npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rest-api/redux

v2.1.0

Published

[![npm version](https://img.shields.io/npm/v/@rest-api/redux)](https://www.npmjs.com/package/@rest-api/redux) [![CircleCI](https://circleci.com/gh/hector7/rest-api-redux.svg?style=shield)](https://circleci.com/gh/hector7/rest-api-redux) [![codecov](https:

Downloads

7

Readme

@rest-api/redux

npm version CircleCI codecov

Core library which handles all ajax calls on redux.

Caution: if you have some random typescript error (pex: ts2589) on creating or editing models, kill the process and restart npm start (on Visual Studio Code restart program).

Major changes

A model on a schema type is the type of model. If you want to has the id in order to populate, you can write with following type:

	{ type: model, idOnly: true }

Declaring models

Declare the models of your application, given a Schema, an id (need to be required field) and a base url (final argument is reserved for opts):

import { Model, Schema, required } from  '@rest-api/redux'

const librarySchema = Schema({
    id: {
	    type: Number,
	    required
    },
    name: String
})
export default new Model(librarySchema, 
    'id', 
    '/api/library')

Or define your model with metadata, passing some arguments in order to build the metadata:

    import { Model, Schema, required } from  '@rest-api/redux'
    
    const librarySchema = Schema({
        id: {
    	    type: Number,
    	    required
        },
        name: String
    })
    export default new Model(librarySchema, 
	    'id', 
	    '/api/library',
		Schema({ count: { type: Number, required: true }, items: [{ type: librarySchema, required: true }] }), //define the data exactly returns your endpoint GET
		data => data.items, //function that returns an array of items as librarySchema
		d => d.items.length //function that returns the metadata from the request
	)

The opts for a model are an object with all properties as optional, which can be:

	{
		headers: A json with a key value string, this headers will be passed to all requests
		trailingSlash: Feature that pass a trailingSlash to each endpoint (solving django trailing slash endpoints)
	}

This schema can be updated or delete some fields, but returns a new Schema:

	const librarySchemaWithFailName = librarySchema.updateSchema({ name: Number })
	const librarySchemaWithoutFields = librarySchemaWithFailName.deleteFields('name', 'id)

You can use complex objects on a Schema simplier creating subschemas:

import { Schema } from  '@rest-api/redux'

const testSchema = Schema({
    subSchema: Schema({
    	id: { type: String },
    	name: String
	})
})

And foreign keys of your model can be representated:

import { ModelType, ModelPopulatedType, Schema, Model } from  '@rest-api/redux'
import libraryModel from './libraryModel'

const bookSchema = Schema({
    id: { type: Number, required: true },
    name: { type: String, required: true },
    description: String,
    library: {
	    type: libraryModel,
	    required: true,
		idOnly: true
    }
})
export type BookType = ModelType<typeof bookSchema>
export type BookPopulatedType = ModelPopulatedType<typeof bookSchema>
export default new Model(bookSchema, 'id', '/api/book')

An option can be passed to model declaration in order to works with django "trailing slash" or pass custom headers:

new Model(bookSchema, 'id', '/api/book', { trailingSlash: true, headers: { Authorization: "Basic xxxx" } })