json-server 0.16.2 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,15 +24,9 @@ See also:
24
24
  </a>
25
25
  </p>
26
26
 
27
- <p>&nbsp;</p>
28
-
29
- <h2 align="center">Bronze sponsors 🥉</h2>
30
-
31
- <p>&nbsp;</p>
32
-
33
27
  <p align="center">
34
- <a href="https://www.zinggrid.com/hello/json-server?utm_source=jsonserver&utm_medium=github&utm_campaign=sponsorship" target="_blank">
35
- <img src="https://i.imgur.com/3mJGTAQ.png" height="30px">
28
+ <a href="https://mockend.com/" target="_blank">
29
+ <img src="https://i.imgur.com/Gwaqv3q.png" height="70px">
36
30
  </a>
37
31
  </p>
38
32
 
package/lib/cli/run.js CHANGED
@@ -33,7 +33,7 @@ function prettyPrint(argv, object, rules) {
33
33
  console.log();
34
34
  console.log(chalk.bold(' Other routes'));
35
35
 
36
- for (var rule in rules) {
36
+ for (const rule in rules) {
37
37
  console.log(` ${rule} -> ${rules[rule]}`);
38
38
  }
39
39
  }
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
- const nanoid = require('nanoid');
3
+ const {
4
+ nanoid
5
+ } = require('nanoid');
4
6
 
5
7
  const pluralize = require('pluralize');
6
8
 
@@ -75,7 +75,7 @@ module.exports = (db, opts) => {
75
75
  return;
76
76
  }
77
77
 
78
- var sourceMessage = ''; // if (!_.isObject(source)) {
78
+ const sourceMessage = ''; // if (!_.isObject(source)) {
79
79
  // sourceMessage = `in ${source}`
80
80
  // }
81
81
 
@@ -103,6 +103,8 @@ module.exports = (db, name, opts) => {
103
103
  return true;
104
104
  }
105
105
  }
106
+
107
+ return false;
106
108
  });
107
109
  }
108
110
 
@@ -124,7 +126,7 @@ module.exports = (db, name, opts) => {
124
126
 
125
127
 
126
128
  if (elementValue === undefined || elementValue === null) {
127
- return;
129
+ return undefined;
128
130
  }
129
131
 
130
132
  if (isRange) {
@@ -230,7 +232,7 @@ module.exports = (db, name, opts) => {
230
232
 
231
233
  if (opts._isFake) {
232
234
  const id = db.get(name).createId().value();
233
- resource = _objectSpread({}, req.body, {
235
+ resource = _objectSpread(_objectSpread({}, req.body), {}, {
234
236
  id
235
237
  });
236
238
  } else {
@@ -254,9 +256,9 @@ module.exports = (db, name, opts) => {
254
256
  resource = db.get(name).getById(id).value();
255
257
 
256
258
  if (req.method === 'PATCH') {
257
- resource = _objectSpread({}, resource, {}, req.body);
259
+ resource = _objectSpread(_objectSpread({}, resource), req.body);
258
260
  } else {
259
- resource = _objectSpread({}, req.body, {
261
+ resource = _objectSpread(_objectSpread({}, req.body), {}, {
260
262
  id: resource.id
261
263
  });
262
264
  }
@@ -43,7 +43,7 @@ module.exports = (db, name, opts) => {
43
43
  res.locals.data = req.body;
44
44
  } else {
45
45
  const resource = db.get(name).value();
46
- res.locals.data = _objectSpread({}, resource, {}, req.body);
46
+ res.locals.data = _objectSpread(_objectSpread({}, resource), req.body);
47
47
  }
48
48
  } else {
49
49
  if (req.method === 'PUT') {
@@ -5,9 +5,9 @@ module.exports = {
5
5
  };
6
6
 
7
7
  function getPage(array, page, perPage) {
8
- var obj = {};
9
- var start = (page - 1) * perPage;
10
- var end = page * perPage;
8
+ const obj = {};
9
+ const start = (page - 1) * perPage;
10
+ const end = page * perPage;
11
11
  obj.items = array.slice(start, end);
12
12
 
13
13
  if (obj.items.length === 0) {
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "json-server",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "description": "Get a full fake REST API with zero coding in less than 30 seconds",
5
5
  "main": "./lib/server/index.js",
6
6
  "bin": "./lib/cli/bin.js",
7
+ "files": [
8
+ "lib",
9
+ "public"
10
+ ],
7
11
  "scripts": {
12
+ "_postinstall": "husky install",
8
13
  "test": "npm run build && cross-env NODE_ENV=test jest && npm run lint",
9
14
  "start": "babel-node -- src/cli/bin db.json -r routes.json",
10
15
  "lint": "eslint . --ignore-path .gitignore",
@@ -12,55 +17,57 @@
12
17
  "build": "babel src -d lib",
13
18
  "toc": "markdown-toc -i README.md",
14
19
  "postversion": "git push && git push --tags",
15
- "prepublishOnly": "npm test && npm run build && pkg-ok"
20
+ "prepublish": "npm test && npm run build && pkg-ok && pinst --disable",
21
+ "postpublish": "pinst --enable"
16
22
  },
17
23
  "dependencies": {
18
24
  "body-parser": "^1.19.0",
19
- "chalk": "^3.0.0",
25
+ "chalk": "^4.1.0",
20
26
  "compression": "^1.7.4",
21
27
  "connect-pause": "^0.1.1",
22
28
  "cors": "^2.8.5",
23
29
  "errorhandler": "^1.5.1",
24
30
  "express": "^4.17.1",
25
- "express-urlrewrite": "^1.2.0",
31
+ "express-urlrewrite": "^1.3.0",
26
32
  "json-parse-helpfulerror": "^1.0.3",
27
- "lodash": "^4.17.15",
33
+ "lodash": "^4.17.20",
28
34
  "lodash-id": "^0.14.0",
29
35
  "lowdb": "^1.0.0",
30
36
  "method-override": "^3.0.0",
31
- "morgan": "^1.9.1",
32
- "nanoid": "^2.1.11",
37
+ "morgan": "^1.10.0",
38
+ "nanoid": "^3.1.16",
33
39
  "please-upgrade-node": "^3.2.0",
34
40
  "pluralize": "^8.0.0",
35
41
  "server-destroy": "^1.0.1",
36
- "update-notifier": "^4.0.0",
37
- "yargs": "^15.1.0"
42
+ "update-notifier": "^5.0.1",
43
+ "yargs": "^16.1.1"
38
44
  },
39
45
  "devDependencies": {
40
- "@babel/cli": "^7.8.4",
41
- "@babel/core": "^7.8.4",
42
- "@babel/node": "^7.8.4",
43
- "@babel/preset-env": "^7.8.4",
44
- "cross-env": "^7.0.0",
45
- "eslint": "^6.8.0",
46
- "eslint-config-prettier": "^6.10.0",
47
- "eslint-config-standard": "^14.1.0",
48
- "eslint-plugin-import": "^2.20.1",
49
- "eslint-plugin-node": "^11.0.0",
50
- "eslint-plugin-prettier": "^3.1.2",
46
+ "@babel/cli": "^7.12.1",
47
+ "@babel/core": "^7.12.3",
48
+ "@babel/node": "^7.12.6",
49
+ "@babel/preset-env": "^7.12.1",
50
+ "cross-env": "^7.0.2",
51
+ "eslint": "^7.13.0",
52
+ "eslint-config-prettier": "^6.15.0",
53
+ "eslint-config-standard": "^16.0.1",
54
+ "eslint-plugin-import": "^2.22.1",
55
+ "eslint-plugin-node": "^11.1.0",
56
+ "eslint-plugin-prettier": "^3.1.4",
51
57
  "eslint-plugin-promise": "^4.2.1",
52
- "eslint-plugin-standard": "^4.0.1",
53
- "husky": "^4.2.1",
54
- "jest": "^25.1.0",
58
+ "eslint-plugin-standard": "^4.1.0",
59
+ "husky": "^5.0.0-beta.0",
60
+ "jest": "^26.6.3",
55
61
  "markdown-toc": "^1.2.0",
56
- "mkdirp": "^1.0.3",
62
+ "mkdirp": "^1.0.4",
57
63
  "npm-run-all": "^4.1.5",
58
64
  "os-tmpdir": "^2.0.0",
65
+ "pinst": "^2.1.1",
59
66
  "pkg-ok": "^2.3.1",
60
- "prettier": "^1.19.1",
67
+ "prettier": "^2.1.2",
61
68
  "rimraf": "^3.0.2",
62
69
  "server-ready": "^0.3.1",
63
- "supertest": "^4.0.2",
70
+ "supertest": "^6.0.1",
64
71
  "temp-write": "^4.0.0"
65
72
  },
66
73
  "repository": {
@@ -92,11 +99,6 @@
92
99
  "engines": {
93
100
  "node": ">=10"
94
101
  },
95
- "husky": {
96
- "hooks": {
97
- "pre-commit": "npm test"
98
- }
99
- },
100
102
  "jest": {
101
103
  "testURL": "http://localhost/"
102
104
  }
package/public/script.js CHANGED
@@ -11,10 +11,10 @@ function ResourceList({ db }) {
11
11
  return `
12
12
  <ul>
13
13
  ${Object.keys(db)
14
- .map(name =>
14
+ .map((name) =>
15
15
  ResourceItem({
16
16
  name,
17
- length: Array.isArray(db[name]) && db[name].length
17
+ length: Array.isArray(db[name]) && db[name].length,
18
18
  })
19
19
  )
20
20
  .join('')}
@@ -37,9 +37,9 @@ function ResourcesBlock({ db }) {
37
37
 
38
38
  window
39
39
  .fetch('db')
40
- .then(response => response.json())
40
+ .then((response) => response.json())
41
41
  .then(
42
- db =>
42
+ (db) =>
43
43
  (document.getElementById('resources').innerHTML = ResourcesBlock({ db }))
44
44
  )
45
45
 
@@ -52,7 +52,7 @@ function CustomRoutesBlock({ customRoutes }) {
52
52
  <table>
53
53
  ${rules
54
54
  .map(
55
- rule =>
55
+ (rule) =>
56
56
  `<tr>
57
57
  <td>${rule}</td>
58
58
  <td><code>⇢</code> ${customRoutes[rule]}</td>
@@ -67,10 +67,10 @@ function CustomRoutesBlock({ customRoutes }) {
67
67
 
68
68
  window
69
69
  .fetch('__rules')
70
- .then(response => response.json())
70
+ .then((response) => response.json())
71
71
  .then(
72
- customRoutes =>
72
+ (customRoutes) =>
73
73
  (document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
74
- customRoutes
74
+ customRoutes,
75
75
  }))
76
76
  )
package/.babelrc DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@babel/preset-env",
5
- {
6
- "targets": {
7
- "node": "8"
8
- }
9
- }
10
- ]
11
- ]
12
- }
package/.eslintignore DELETED
@@ -1,2 +0,0 @@
1
- src/server/public
2
- lib
package/.eslintrc.js DELETED
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- extends: ['standard', 'prettier'],
3
- plugins: ['prettier'],
4
- rules: {
5
- 'prettier/prettier': [
6
- 'error',
7
- {
8
- singleQuote: true,
9
- semi: false,
10
- },
11
- ]
12
- },
13
- env: { jest: true }
14
- }
@@ -1 +0,0 @@
1
- github: typicode
@@ -1,31 +0,0 @@
1
- name: CI
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- test:
7
- strategy:
8
- matrix:
9
- platform: [ubuntu-latest]
10
- node: [ '10', '12' ]
11
- name: Node ${{ matrix.node }} (${{ matrix.platform }})
12
- runs-on: ${{ matrix.platform }}
13
- steps:
14
- - uses: actions/checkout@v1
15
- - uses: actions/setup-node@v1
16
- with:
17
- node-version: ${{ matrix.node }}
18
- - name: install dependencies
19
- run: npm i
20
- - name: run tests
21
- run: npm test
22
- test_latest:
23
- runs-on: ubuntu-latest
24
- container: node:latest
25
- name: Node latest (ubuntu-latest)
26
- steps:
27
- - uses: actions/checkout@v1
28
- - name: install dependencies
29
- run: npm i
30
- - name: run tests
31
- run: npm test
package/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "node"
4
- - "12"
5
- - "10"
6
- install: npm i
package/appveyor.yml DELETED
@@ -1,21 +0,0 @@
1
- # Test against this version of Node.js
2
- environment:
3
- nodejs_version: "8"
4
-
5
- # Install scripts. (runs after repo cloning)
6
- install:
7
- # Get the latest stable version of Node.js
8
- - ps: Install-Product node $env:nodejs_version
9
- # install modules
10
- - npm install
11
-
12
- # Post-install test scripts.
13
- test_script:
14
- # Output useful info for debugging.
15
- - node --version
16
- - npm --version
17
- # run tests
18
- - npm test
19
-
20
- # Don't actually build.
21
- build: off
package/db.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "posts": [
3
- { "id": 1, "title": "json-server", "author": "typicode" }
4
- ],
5
- "comments": [
6
- { "id": 1, "body": "some comment", "postId": 1 }
7
- ],
8
- "profile": { "name": "typicode" }
9
- }
package/postinstall.js DELETED
@@ -1,10 +0,0 @@
1
- const chalk = require('chalk')
2
-
3
- console.log(
4
- 'Like JSON Server? You can support the project on',
5
- chalk.bold('GitHub Sponsors')
6
- )
7
- console.log(
8
- chalk.underline('https://github.com/users/typicode/sponsorship'),
9
- chalk.red('❤')
10
- )
package/routes.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "/api/": "/",
3
- "/blog/:resource/:id/show": "/:resource/:id",
4
- "/blog/:category": "/posts?category=:category"
5
- }