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 +2 -8
- package/lib/cli/run.js +1 -1
- package/lib/server/mixins.js +3 -1
- package/lib/server/router/index.js +1 -1
- package/lib/server/router/plural.js +6 -4
- package/lib/server/router/singular.js +1 -1
- package/lib/server/utils.js +3 -3
- package/package.json +33 -31
- package/public/script.js +8 -8
- package/.babelrc +0 -12
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -14
- package/.github/FUNDING.yml +0 -1
- package/.github/workflows/main.yaml +0 -31
- package/.travis.yml +0 -6
- package/appveyor.yml +0 -21
- package/db.json +0 -9
- package/postinstall.js +0 -10
- package/routes.json +0 -5
package/README.md
CHANGED
|
@@ -24,15 +24,9 @@ See also:
|
|
|
24
24
|
</a>
|
|
25
25
|
</p>
|
|
26
26
|
|
|
27
|
-
<p> </p>
|
|
28
|
-
|
|
29
|
-
<h2 align="center">Bronze sponsors 🥉</h2>
|
|
30
|
-
|
|
31
|
-
<p> </p>
|
|
32
|
-
|
|
33
27
|
<p align="center">
|
|
34
|
-
<a href="https://
|
|
35
|
-
<img src="https://i.imgur.com/
|
|
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
package/lib/server/mixins.js
CHANGED
|
@@ -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,
|
|
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,
|
|
46
|
+
res.locals.data = _objectSpread(_objectSpread({}, resource), req.body);
|
|
47
47
|
}
|
|
48
48
|
} else {
|
|
49
49
|
if (req.method === 'PUT') {
|
package/lib/server/utils.js
CHANGED
|
@@ -5,9 +5,9 @@ module.exports = {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
function getPage(array, page, perPage) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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.
|
|
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
|
-
"
|
|
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": "^
|
|
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.
|
|
31
|
+
"express-urlrewrite": "^1.3.0",
|
|
26
32
|
"json-parse-helpfulerror": "^1.0.3",
|
|
27
|
-
"lodash": "^4.17.
|
|
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.
|
|
32
|
-
"nanoid": "^
|
|
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": "^
|
|
37
|
-
"yargs": "^
|
|
42
|
+
"update-notifier": "^5.0.1",
|
|
43
|
+
"yargs": "^16.1.1"
|
|
38
44
|
},
|
|
39
45
|
"devDependencies": {
|
|
40
|
-
"@babel/cli": "^7.
|
|
41
|
-
"@babel/core": "^7.
|
|
42
|
-
"@babel/node": "^7.
|
|
43
|
-
"@babel/preset-env": "^7.
|
|
44
|
-
"cross-env": "^7.0.
|
|
45
|
-
"eslint": "^
|
|
46
|
-
"eslint-config-prettier": "^6.
|
|
47
|
-
"eslint-config-standard": "^
|
|
48
|
-
"eslint-plugin-import": "^2.
|
|
49
|
-
"eslint-plugin-node": "^11.
|
|
50
|
-
"eslint-plugin-prettier": "^3.1.
|
|
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
|
|
53
|
-
"husky": "^
|
|
54
|
-
"jest": "^
|
|
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.
|
|
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.
|
|
67
|
+
"prettier": "^2.1.2",
|
|
61
68
|
"rimraf": "^3.0.2",
|
|
62
69
|
"server-ready": "^0.3.1",
|
|
63
|
-
"supertest": "^
|
|
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
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
package/.github/FUNDING.yml
DELETED
|
@@ -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
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
package/postinstall.js
DELETED