json-server 0.14.2 → 0.16.1
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/.babelrc +1 -1
- package/.eslintrc.js +1 -1
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/main.yaml +31 -0
- package/.travis.yml +3 -1
- package/CHANGELOG.md +8 -0
- package/README.md +29 -10
- package/appveyor.yml +1 -1
- package/lib/cli/run.js +5 -3
- package/lib/front/index.js +54 -50
- package/lib/front/script.js +71 -0
- package/lib/server/defaults.js +2 -4
- package/lib/server/mixins.js +4 -5
- package/lib/server/router/index.js +6 -4
- package/lib/server/router/plural.js +16 -14
- package/lib/server/router/singular.js +4 -2
- package/package.json +38 -64
- package/postinstall.js +10 -0
- package/{dist → public}/favicon.ico +0 -0
- package/public/index.html +85 -0
- package/public/script.js +76 -0
- package/public/style.css +113 -0
- package/dist/index.html +0 -53
- package/dist/main.css +0 -675
- package/dist/main.js +0 -1
- package/webpack.config.js +0 -21
package/.babelrc
CHANGED
package/.eslintrc.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
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
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
Changes for 0.15.1+ can now be found in https://github.com/typicode/json-server/releases
|
|
4
|
+
|
|
5
|
+
## 0.15.0 - 2019-05-21
|
|
6
|
+
|
|
7
|
+
* __Breaking__ Require Node 8
|
|
8
|
+
* Upgrade dependencies
|
|
9
|
+
* Reduce package size
|
|
10
|
+
|
|
3
11
|
## 0.14.2 - 2018-12-26
|
|
4
12
|
|
|
5
13
|
* Fix `db.getState is not a function`
|
package/README.md
CHANGED
|
@@ -5,26 +5,45 @@ Get a full fake REST API with __zero coding__ in __less than 30 seconds__ (serio
|
|
|
5
5
|
Created with <3 for front-end developers who need a quick back-end for prototyping and mocking.
|
|
6
6
|
|
|
7
7
|
* [Egghead.io free video tutorial - Creating demo APIs with json-server](https://egghead.io/lessons/nodejs-creating-demo-apis-with-json-server)
|
|
8
|
-
* [JSONPlaceholder - Live running version](
|
|
8
|
+
* [JSONPlaceholder - Live running version](https://jsonplaceholder.typicode.com)
|
|
9
|
+
* [__My JSON Server__ - no installation required, use your own data](https://my-json-server.typicode.com)
|
|
9
10
|
|
|
10
11
|
See also:
|
|
11
12
|
* :dog: [husky - Git hooks made easy](https://github.com/typicode/husky)
|
|
12
13
|
* :hotel: [hotel - developer tool with local .localhost domain and https out of the box](https://github.com/typicode/hotel)
|
|
13
|
-
* ⚛️ 🔧 [react-lodash - lodash as React components](https://github.com/typicode/react-lodash)
|
|
14
14
|
|
|
15
|
-
<
|
|
16
|
-
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
|
|
17
|
-
</a>
|
|
15
|
+
<p> </p>
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
<h2 align="center">Gold sponsors 🥇</h2>
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
<p> </p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="https://tryretool.com/?utm_source=sponsor&utm_campaign=typicode" target="_blank">
|
|
23
|
+
<img src="https://i.imgur.com/IBItATn.png" height="70px">
|
|
24
|
+
</a>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
<p> </p>
|
|
28
|
+
|
|
29
|
+
<h2 align="center">Bronze sponsors 🥉</h2>
|
|
30
|
+
|
|
31
|
+
<p> </p>
|
|
32
|
+
|
|
33
|
+
<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">
|
|
36
|
+
</a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
<p> </p>
|
|
40
|
+
|
|
41
|
+
[Become a sponsor and have your company logo here](https://github.com/users/typicode/sponsorship)
|
|
22
42
|
|
|
23
43
|
## Table of contents
|
|
24
44
|
|
|
25
45
|
<!-- toc -->
|
|
26
46
|
|
|
27
|
-
- [Sponsorship](#sponsorship)
|
|
28
47
|
- [Getting started](#getting-started)
|
|
29
48
|
- [Routes](#routes)
|
|
30
49
|
* [Plural routes](#plural-routes)
|
|
@@ -574,7 +593,7 @@ You can deploy JSON Server. For example, [JSONPlaceholder](http://jsonplaceholde
|
|
|
574
593
|
* [Node Module Of The Week - json-server](http://nmotw.in/json-server/)
|
|
575
594
|
* [Mock up your REST API with JSON Server](http://www.betterpixels.co.uk/projects/2015/05/09/mock-up-your-rest-api-with-json-server/)
|
|
576
595
|
* [ng-admin: Add an AngularJS admin GUI to any RESTful API](http://marmelab.com/blog/2014/09/15/easy-backend-for-your-restful-api.html)
|
|
577
|
-
* [Fast prototyping using Restangular and Json-server](
|
|
596
|
+
* [Fast prototyping using Restangular and Json-server](https://glebbahmutov.com/blog/fast-prototyping-restangular-and-json-server/)
|
|
578
597
|
* [Create a Mock REST API in Seconds for Prototyping your Frontend](https://coligo.io/create-mock-rest-api-with-json-server/)
|
|
579
598
|
* [No API? No Problem! Rapid Development via Mock APIs](https://medium.com/@housecor/rapid-development-via-mock-apis-e559087be066#.93d7w8oro)
|
|
580
599
|
* [Zero Code REST With json-server](https://dzone.com/articles/zero-code-rest-with-json-server)
|
|
@@ -591,4 +610,4 @@ You can deploy JSON Server. For example, [JSONPlaceholder](http://jsonplaceholde
|
|
|
591
610
|
|
|
592
611
|
MIT
|
|
593
612
|
|
|
594
|
-
[
|
|
613
|
+
[Supporters](https://thanks.typicode.com) ✨
|
package/appveyor.yml
CHANGED
package/lib/cli/run.js
CHANGED
|
@@ -25,7 +25,7 @@ function prettyPrint(argv, object, rules) {
|
|
|
25
25
|
console.log();
|
|
26
26
|
console.log(chalk.bold(' Resources'));
|
|
27
27
|
|
|
28
|
-
for (
|
|
28
|
+
for (const prop in object) {
|
|
29
29
|
console.log(` ${root}/${prop}`);
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -46,8 +46,10 @@ function prettyPrint(argv, object, rules) {
|
|
|
46
46
|
|
|
47
47
|
function createApp(db, routes, middlewares, argv) {
|
|
48
48
|
const app = jsonServer.create();
|
|
49
|
-
const
|
|
50
|
-
|
|
49
|
+
const {
|
|
50
|
+
foreignKeySuffix
|
|
51
|
+
} = argv;
|
|
52
|
+
const router = jsonServer.router(db, foreignKeySuffix ? {
|
|
51
53
|
foreignKeySuffix
|
|
52
54
|
} : undefined);
|
|
53
55
|
const defaultsOpts = {
|
package/lib/front/index.js
CHANGED
|
@@ -1,67 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function ResourceItem(_ref) {
|
|
14
|
-
var name = _ref.name,
|
|
15
|
-
length = _ref.length;
|
|
16
|
-
return (0, _preact.h)("li", null, (0, _preact.h)("a", {
|
|
17
|
-
href: name
|
|
18
|
-
}, "/", name), " ", (0, _preact.h)("sup", null, length ? "".concat(length, "x") : 'object'));
|
|
3
|
+
function ResourceItem({
|
|
4
|
+
name,
|
|
5
|
+
length
|
|
6
|
+
}) {
|
|
7
|
+
return `
|
|
8
|
+
<li>
|
|
9
|
+
<a href="${name}">/${name}</a>
|
|
10
|
+
<sup>${length ? `${length}x` : 'object'}</sup>
|
|
11
|
+
</li>
|
|
12
|
+
`;
|
|
19
13
|
}
|
|
20
14
|
|
|
21
|
-
function ResourceList(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
function ResourceList({
|
|
16
|
+
db
|
|
17
|
+
}) {
|
|
18
|
+
return `
|
|
19
|
+
<ul>
|
|
20
|
+
${Object.keys(db).map(name => ResourceItem({
|
|
21
|
+
name,
|
|
22
|
+
length: Array.isArray(db[name]) && db[name].length
|
|
23
|
+
})).join('')}
|
|
24
|
+
</ul>
|
|
25
|
+
`;
|
|
29
26
|
}
|
|
30
27
|
|
|
31
28
|
function NoResources() {
|
|
32
|
-
return
|
|
29
|
+
return `<p>No resources found</p>`;
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
function ResourcesBlock(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
function ResourcesBlock({
|
|
33
|
+
db
|
|
34
|
+
}) {
|
|
35
|
+
return `
|
|
36
|
+
<div>
|
|
37
|
+
<h1>Resources</h1>
|
|
38
|
+
${Object.keys(db).length ? ResourceList({
|
|
39
|
+
db
|
|
40
|
+
}) : NoResources()}
|
|
41
|
+
</div>
|
|
42
|
+
`;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
window.fetch('db').then(
|
|
43
|
-
|
|
44
|
-
})
|
|
45
|
-
return (0, _preact.render)((0, _preact.h)(ResourcesBlock, {
|
|
46
|
-
db: db
|
|
47
|
-
}), document.getElementById('resources'));
|
|
48
|
-
});
|
|
45
|
+
window.fetch('db').then(response => response.json()).then(db => document.getElementById('resources').innerHTML = ResourcesBlock({
|
|
46
|
+
db
|
|
47
|
+
}));
|
|
49
48
|
|
|
50
|
-
function CustomRoutesBlock(
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
function CustomRoutesBlock({
|
|
50
|
+
customRoutes
|
|
51
|
+
}) {
|
|
52
|
+
const rules = Object.keys(customRoutes);
|
|
53
53
|
|
|
54
54
|
if (rules.length) {
|
|
55
|
-
return
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
return `
|
|
56
|
+
<div>
|
|
57
|
+
<h1>Custom Routes</h1>
|
|
58
|
+
<table>
|
|
59
|
+
${rules.map(rule => `<tr>
|
|
60
|
+
<td>${rule}</td>
|
|
61
|
+
<td><code>⇢</code> ${customRoutes[rule]}</td>
|
|
62
|
+
</tr>`).join('')}
|
|
63
|
+
</table>
|
|
64
|
+
</div>
|
|
65
|
+
`;
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
68
|
|
|
61
|
-
window.fetch('__rules').then(
|
|
62
|
-
|
|
63
|
-
})
|
|
64
|
-
(0, _preact.render)((0, _preact.h)(CustomRoutesBlock, {
|
|
65
|
-
customRoutes: customRoutes
|
|
66
|
-
}), document.getElementById('custom-routes'));
|
|
67
|
-
});
|
|
69
|
+
window.fetch('__rules').then(response => response.json()).then(customRoutes => document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
|
|
70
|
+
customRoutes
|
|
71
|
+
}));
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function ResourceItem({
|
|
4
|
+
name,
|
|
5
|
+
length
|
|
6
|
+
}) {
|
|
7
|
+
return `
|
|
8
|
+
<li>
|
|
9
|
+
<a href="${name}">/${name}</a>
|
|
10
|
+
<sup>${length ? `${length}x` : 'object'}</sup>
|
|
11
|
+
</li>
|
|
12
|
+
`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function ResourceList({
|
|
16
|
+
db
|
|
17
|
+
}) {
|
|
18
|
+
return `
|
|
19
|
+
<ul>
|
|
20
|
+
${Object.keys(db).map(name => ResourceItem({
|
|
21
|
+
name,
|
|
22
|
+
length: Array.isArray(db[name]) && db[name].length
|
|
23
|
+
})).join('')}
|
|
24
|
+
</ul>
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function NoResources() {
|
|
29
|
+
return `<p>No resources found</p>`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function ResourcesBlock({
|
|
33
|
+
db
|
|
34
|
+
}) {
|
|
35
|
+
return `
|
|
36
|
+
<div>
|
|
37
|
+
<h1>Resources</h1>
|
|
38
|
+
${Object.keys(db).length ? ResourceList({
|
|
39
|
+
db
|
|
40
|
+
}) : NoResources()}
|
|
41
|
+
</div>
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
window.fetch('db').then(response => response.json()).then(db => document.getElementById('resources').innerHTML = ResourcesBlock({
|
|
46
|
+
db
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
function CustomRoutesBlock({
|
|
50
|
+
customRoutes
|
|
51
|
+
}) {
|
|
52
|
+
const rules = Object.keys(customRoutes);
|
|
53
|
+
|
|
54
|
+
if (rules.length) {
|
|
55
|
+
return `
|
|
56
|
+
<div>
|
|
57
|
+
<h1>Custom Routes</h1>
|
|
58
|
+
<table>
|
|
59
|
+
${rules.map(rule => `<tr>
|
|
60
|
+
<td>${rule}</td>
|
|
61
|
+
<td><code>⇢</code> ${customRoutes[rule]}</td>
|
|
62
|
+
</tr>`).join('')}
|
|
63
|
+
</table>
|
|
64
|
+
</div>
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
window.fetch('__rules').then(response => response.json()).then(customRoutes => document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
|
|
70
|
+
customRoutes
|
|
71
|
+
}));
|
package/lib/server/defaults.js
CHANGED
|
@@ -14,15 +14,13 @@ const compression = require('compression');
|
|
|
14
14
|
|
|
15
15
|
const errorhandler = require('errorhandler');
|
|
16
16
|
|
|
17
|
-
const objectAssign = require('object-assign');
|
|
18
|
-
|
|
19
17
|
const bodyParser = require('./body-parser');
|
|
20
18
|
|
|
21
19
|
module.exports = function (opts) {
|
|
22
20
|
const userDir = path.join(process.cwd(), 'public');
|
|
23
|
-
const defaultDir = path.join(__dirname, '../../
|
|
21
|
+
const defaultDir = path.join(__dirname, '../../public');
|
|
24
22
|
const staticDir = fs.existsSync(userDir) ? userDir : defaultDir;
|
|
25
|
-
opts =
|
|
23
|
+
opts = Object.assign({
|
|
26
24
|
logger: true,
|
|
27
25
|
static: staticDir
|
|
28
26
|
}, opts);
|
package/lib/server/mixins.js
CHANGED
|
@@ -7,10 +7,9 @@ const pluralize = require('pluralize');
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
getRemovable,
|
|
9
9
|
createId,
|
|
10
|
-
deepQuery
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
10
|
+
deepQuery
|
|
11
|
+
}; // Returns document ids that have unsatisfied relations
|
|
12
|
+
// Example: a comment that references a post that doesn't exist
|
|
14
13
|
|
|
15
14
|
function getRemovable(db, opts) {
|
|
16
15
|
const _ = this;
|
|
@@ -72,7 +71,7 @@ function deepQuery(value, q) {
|
|
|
72
71
|
}
|
|
73
72
|
}
|
|
74
73
|
} else if (_.isObject(value) && !_.isArray(value)) {
|
|
75
|
-
for (
|
|
74
|
+
for (const k in value) {
|
|
76
75
|
if (_.deepQuery(value[k], q)) {
|
|
77
76
|
return true;
|
|
78
77
|
}
|
|
@@ -26,10 +26,12 @@ const singular = require('./singular');
|
|
|
26
26
|
|
|
27
27
|
const mixins = require('../mixins');
|
|
28
28
|
|
|
29
|
-
module.exports = (db, opts
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
module.exports = (db, opts) => {
|
|
30
|
+
opts = Object.assign({
|
|
31
|
+
foreignKeySuffix: 'Id',
|
|
32
|
+
_isFake: false
|
|
33
|
+
}, opts);
|
|
34
|
+
|
|
33
35
|
if (typeof db === 'string') {
|
|
34
36
|
db = low(new FileSync(db));
|
|
35
37
|
} else if (!_.has(db, '__chain__') || !_.has(db, '__wrapped__')) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
4
6
|
|
|
5
7
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
8
|
|
|
@@ -61,11 +63,11 @@ module.exports = (db, name, opts) => {
|
|
|
61
63
|
let _start = req.query._start;
|
|
62
64
|
let _end = req.query._end;
|
|
63
65
|
let _page = req.query._page;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
const _sort = req.query._sort;
|
|
67
|
+
const _order = req.query._order;
|
|
66
68
|
let _limit = req.query._limit;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
const _embed = req.query._embed;
|
|
70
|
+
const _expand = req.query._expand;
|
|
69
71
|
delete req.query.q;
|
|
70
72
|
delete req.query._start;
|
|
71
73
|
delete req.query._end;
|
|
@@ -79,7 +81,7 @@ module.exports = (db, name, opts) => {
|
|
|
79
81
|
Object.keys(req.query).forEach(query => {
|
|
80
82
|
const arr = db.get(name).value();
|
|
81
83
|
|
|
82
|
-
for (
|
|
84
|
+
for (const i in arr) {
|
|
83
85
|
if (_.has(arr[i], query) || query === 'callback' || query === '_' || /_lte$/.test(query) || /_gte$/.test(query) || /_ne$/.test(query) || /_like$/.test(query)) return;
|
|
84
86
|
}
|
|
85
87
|
|
|
@@ -94,7 +96,7 @@ module.exports = (db, name, opts) => {
|
|
|
94
96
|
|
|
95
97
|
q = q.toLowerCase();
|
|
96
98
|
chain = chain.filter(obj => {
|
|
97
|
-
for (
|
|
99
|
+
for (const key in obj) {
|
|
98
100
|
const value = obj[key];
|
|
99
101
|
|
|
100
102
|
if (db._.deepQuery(value, q)) {
|
|
@@ -110,14 +112,14 @@ module.exports = (db, name, opts) => {
|
|
|
110
112
|
if (key !== 'callback' && key !== '_') {
|
|
111
113
|
// Always use an array, in case req.query is an array
|
|
112
114
|
const arr = [].concat(req.query[key]);
|
|
115
|
+
const isDifferent = /_ne$/.test(key);
|
|
116
|
+
const isRange = /_lte$/.test(key) || /_gte$/.test(key);
|
|
117
|
+
const isLike = /_like$/.test(key);
|
|
118
|
+
const path = key.replace(/(_lte|_gte|_ne|_like)$/, '');
|
|
113
119
|
chain = chain.filter(element => {
|
|
114
120
|
return arr.map(function (value) {
|
|
115
|
-
|
|
116
|
-
const isRange = /_lte$/.test(key) || /_gte$/.test(key);
|
|
117
|
-
const isLike = /_like$/.test(key);
|
|
118
|
-
const path = key.replace(/(_lte|_gte|_ne|_like)$/, ''); // get item value based on path
|
|
121
|
+
// get item value based on path
|
|
119
122
|
// i.e post.title -> 'foo'
|
|
120
|
-
|
|
121
123
|
const elementValue = _.get(element, path); // Prevent toString() failing on undefined or null values
|
|
122
124
|
|
|
123
125
|
|
|
@@ -135,7 +137,7 @@ module.exports = (db, name, opts) => {
|
|
|
135
137
|
} else {
|
|
136
138
|
return value === elementValue.toString();
|
|
137
139
|
}
|
|
138
|
-
}).reduce((a, b) => a || b);
|
|
140
|
+
}).reduce((a, b) => isDifferent ? a && b : a || b);
|
|
139
141
|
});
|
|
140
142
|
}
|
|
141
143
|
}); // Sort
|
|
@@ -252,7 +254,7 @@ module.exports = (db, name, opts) => {
|
|
|
252
254
|
resource = db.get(name).getById(id).value();
|
|
253
255
|
|
|
254
256
|
if (req.method === 'PATCH') {
|
|
255
|
-
resource = _objectSpread({}, resource, req.body);
|
|
257
|
+
resource = _objectSpread({}, resource, {}, req.body);
|
|
256
258
|
} else {
|
|
257
259
|
resource = _objectSpread({}, req.body, {
|
|
258
260
|
id: resource.id
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
4
6
|
|
|
5
7
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
8
|
|
|
@@ -41,7 +43,7 @@ module.exports = (db, name, opts) => {
|
|
|
41
43
|
res.locals.data = req.body;
|
|
42
44
|
} else {
|
|
43
45
|
const resource = db.get(name).value();
|
|
44
|
-
res.locals.data = _objectSpread({}, resource, req.body);
|
|
46
|
+
res.locals.data = _objectSpread({}, resource, {}, req.body);
|
|
45
47
|
}
|
|
46
48
|
} else {
|
|
47
49
|
if (req.method === 'PUT') {
|