-
Notifications
You must be signed in to change notification settings - Fork 6
/
params.json
6 lines (6 loc) · 4.55 KB
/
params.json
1
2
3
4
5
6
{
"name": "Json-server-extension",
"tagline": "nice additions for json-server in order to support large scale applications",
"body": "# json-server-extension\r\n\r\njson-server is great for stub server usage\r\nbut in my opinion there where some caveat that i tried to solve in this package\r\n\r\n### so what this package gives you\r\n- [x] **splitting to static files -** json-server can serve only single file but in medium/large applications it not ideal, by using this package you can split your json object to files\r\n- [x] **dynamic generation -** with json server you can generate the whole file\r\n now you can create multiple generated objects decoupled each other and even combine\r\n static and generated files\r\n\r\n## Example\r\nfull example can be found here https://github.com/maty21/json-server-extension-example\r\n### init example\r\n```js\r\nconst jsonServer = require('json-server');\r\nconst _jsonExtender = require('./jsonExtender');\r\n\r\n//options:\r\n//fullPath:fullpath for the combined object\r\n//generatedPath:the path where the generated files will be found\r\n//staticPath:the path where the static files will be found\r\nconst jsonExtender = new _jsonExtender({filePath:'./db_extends.json',\r\n generatedPath:'./generated',\r\n staticPath:'./static'})\r\n\r\n//register accept array of generators or path to the generator scripts\r\n//const funcs = Object.keys(generators).map(key => generators[key])\r\njsonExtender.register('../../../generators');\r\njsonExtender.generate().then((data)=>{\r\n console.log(`wow ${data}`);\r\n var server = jsonServer.create()\r\n var router = jsonServer.router('./db_extends.json')\r\n var middlewares = jsonServer.defaults()\r\n\r\n server.use(middlewares)\r\n server.use(router)\r\n server.listen(4000, function () {\r\n console.log('JSON Server is running')\r\n }).catch((err) => {console.log(err)})\r\n\r\n});\r\n```\r\n### generator Example\r\n\r\n```js\r\nconst amount = 100;\r\n const func =next =>create => {\r\n const path = `feed/feedList.json`;\r\n const data = (amount)=> {\r\n let temp = [];\r\n for (let i = 0; i < amount; i++) {\r\n temp.push({\r\n id: `${i}N12134`,\r\n newNotificationCount: i * 3,\r\n isRead: (i % 2 == 0),\r\n isStarMark: (i % 4 == 0),\r\n iconType: \"SocialNotifications\",\r\n description: i + \": this is a new feed \",\r\n date: new Date(Date.now()).toLocaleString()\r\n }\r\n )\r\n }\r\n return temp;\r\n }\r\n create({data: {feed: data(amount)}, path: path})\r\n next(create);\r\n\r\n}\r\nmodule.exports = func;\r\n```\r\n\r\n\r\n## api\r\n\r\n#### constructor\r\n``constructor({filePath:'string',generatedPath:'string, staticPath:'string'}) ``\r\n- ``fullPath``- fullpath for the combined object\r\n- ``generatedPath``- the path where the generated files will be found ``default\r\n: './generated'``\r\n- ``staticPath``- the path where the static files will be found ``default\r\n: './static'``\r\n\r\n#### register\r\n``register('path name') / register([...generator scripts]) ``\r\n- ``register('path name')`` - a path where the generators scripts will be found the package will insatiate the scripts automatically\r\n- ``register([...generator scripts])`` -array of your generators after requiring them manually\r\n\r\n#### generate\r\n``generate(isRun[default:true]) return promise``\r\n- ``isRun`` - there is ability to not generate the db.json each time good when you want to save the state after you close the process the promise will recive the same data so you will not have to change the code\r\n- ``promise``\r\n - ``resolve`` -{files:array of combined files, filePath:the combined file path }\r\n - ``reject``- error\r\n\r\n### generator\r\n\r\n``` const func= next =>create => {}``` - the generator should be initiated as follows first you will have to call for create this is sync function and the for next\r\n- ``create({data: {feed: generatedObject}, path: path})``\r\n - ``data`` - the generated data where the name of the property will be the routing name in this case ``feed``\r\n - ``path`` - a relative path under the generated path that you set in the constructor where you wish to put the output\r\n- ``next(create)`` - just pass the create function there so it's reference will be passed in the pipeline\r\n",
"note": "Don't delete this file! It's used internally to help with page regeneration."
}