fakeStoreJs 🚧 



fakeStoreJs make mocking easy, quickly create a CRUD access to any object
- Create multiple store in less than a heartbeat ! ♥️
- Come with a unique id attribution ! 💥
- Extends CRUD method using resolvers ! 🔓
- Persistent data ! 🆕
- Easy to use ! 🔥
If something doesn’t work, please file an issue 🐛.
QuickStart 🚀
Install
$ npm install fakestorejs or yarn install fakestorejsUse it Now !
Start importing createStore from fakeStoreJs.
const createStore = ;Create a store from any object.
const store = ;🎉 Start using it 🎉
storebook;// { sucess: true, data: [ { uid: "000000" author: "Speaking JavaScript", title: "Dr. Axel Raushmayer" }, ...] }Usage
Requirements
fakeStoreJs need an object with at least on key. Each key represent a collection name (or table name) and they must provide an array of data or a schema, look at the example below.
const store = ;Or
const store = ;Let's now have a deeper look at what are schema.
Schema
A schema is the 'constructor' used by fakestorejs to create new object.
Example : You want to create a store of users, each user should have a username build from its lastname and firstname, you need to specified it :
const store = ;Schemaless strategy
Most of the time when mocking data you don't need complexity properties like in the schema model, this is the schemaless fakeStoreJs strategy.
const store = ;Methods
fakeStoreJs comes with embedded crud like method : However you can override them and or create new one using resolvers !
| Method | Parameters | sucess | error |
|---|---|---|---|
| post() | obj: Object | { sucess: Boolean, data: Object } | { sucess: Boolean, error: String } |
| get() | None | { sucess: Boolean, data: Object } | { sucess: Boolean, error: String } |
| put() | uid: String, obj: Object | { sucess: Boolean, data: Object } | { sucess: Boolean, error: String } |
| delete() | uid: String | { sucess: Boolean} | { sucess: Boolean, error: String } |
FakeStoreJs will add a unique identifier(uid) for each item.
Resolvers
Resolvers allow custom methods by adding a key inside your object call resolvers :
const store = ;fakeStoreJs bind the resolvers with a neat context : { collection: Array, schema: Function } where :
collectionis the table from your store(database).schemais your schema from thecreateStore().
Nb: schema will always be your collection name capitalized.
example: book schema will be Book
Options
It is possible to add options to fakeStoreJs using the key : options :
const store = ;| Method | Type | informations | Default |
|---|---|---|---|
| idLabel | String | Use as 'key name' for the generate identifier | 'uid' |
| useSchema | Boolean | Switch beetween embedded schema constructor or your own schema | false |
| isPersistent | Boolean | Keep the data even after a restart | false |
| isDataDeletable | Boolean | Delete the initial data from the data field | false |
Contributing
This project welcome any new contribution.