json-server 0.17.1 → 0.17.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
@@ -43,6 +43,14 @@ See also:
43
43
 
44
44
  <p>&nbsp;</p>
45
45
 
46
+ <p align="center">
47
+ <a href="http://asocks.com/c/TFw5bz" target="_blank">
48
+ <img src="https://jsonplaceholder.typicode.com/asocks.png" height="70px">
49
+ </a>
50
+ </p>
51
+
52
+ <p>&nbsp;</p>
53
+
46
54
  <p>&nbsp;</p>
47
55
 
48
56
  <h2 align="center">Silver sponsors 🥈</h2>
@@ -348,7 +356,7 @@ module.exports = () => {
348
356
  $ json-server index.js
349
357
  ```
350
358
 
351
- __Tip__ use modules like [Faker](https://github.com/Marak/faker.js), [Casual](https://github.com/boo1ean/casual), [Chance](https://github.com/victorquinn/chancejs) or [JSON Schema Faker](https://github.com/json-schema-faker/json-schema-faker).
359
+ __Tip__ use modules like [Faker](https://github.com/faker-js/faker), [Casual](https://github.com/boo1ean/casual), [Chance](https://github.com/victorquinn/chancejs) or [JSON Schema Faker](https://github.com/json-schema-faker/json-schema-faker).
352
360
 
353
361
  ### HTTPS
354
362
 
package/lib/cli/run.js CHANGED
@@ -26,6 +26,8 @@ function prettyPrint(argv, object, rules) {
26
26
  console.log(chalk.bold(' Resources'));
27
27
 
28
28
  for (const prop in object) {
29
+ // skip printing $schema nodes
30
+ if (prop === '$schema') continue;
29
31
  console.log(` ${root}/${prop}`);
30
32
  }
31
33
 
@@ -11,7 +11,7 @@ function FILE(s) {
11
11
  }
12
12
 
13
13
  function JS(s) {
14
- return !URL(s) && /\.js$/.test(s);
14
+ return !URL(s) && /\.c?js$/.test(s);
15
15
  }
16
16
 
17
17
  function URL(s) {
@@ -65,6 +65,11 @@ module.exports = (db, opts) => {
65
65
  router.use(nested(opts)); // Create routes
66
66
 
67
67
  db.forEach((value, key) => {
68
+ if (key === '$schema') {
69
+ // ignore $schema
70
+ return;
71
+ }
72
+
68
73
  if (_.isPlainObject(value)) {
69
74
  router.use(`/${key}`, singular(db, key, opts));
70
75
  return;
@@ -13,6 +13,7 @@ module.exports = obj => {
13
13
  if (_.isPlainObject(obj)) {
14
14
  Object.keys(obj).forEach(validateKey);
15
15
  } else {
16
- throw new Error(`Data must be an object. Found ${typeof obj}.` + 'See https://github.com/typicode/json-server for example.');
16
+ throw new Error(`Data must be an object. Found ${Array.isArray(obj) ? 'array' : typeof obj}.
17
+ 'See https://github.com/typicode/json-server for example.`);
17
18
  }
18
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-server",
3
- "version": "0.17.1",
3
+ "version": "0.17.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",
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "scripts": {
12
12
  "prepare": "husky install",
13
- "test": "npm run build && cross-env NODE_ENV=test jest && npm run lint",
13
+ "test": "npm run build && cross-env NODE_ENV=test jest",
14
14
  "start": "babel-node -- src/cli/bin db.json -r routes.json",
15
15
  "lint": "eslint . --ignore-path .gitignore",
16
16
  "fix": "npm run lint -- --fix",
@@ -38,6 +38,7 @@
38
38
  "please-upgrade-node": "^3.2.0",
39
39
  "pluralize": "^8.0.0",
40
40
  "server-destroy": "^1.0.1",
41
+ "standard": "^17.0.0",
41
42
  "yargs": "^17.0.1"
42
43
  },
43
44
  "devDependencies": {
package/public/script.js CHANGED
@@ -15,7 +15,7 @@ function ResourceList({ db }) {
15
15
  ResourceItem({
16
16
  name,
17
17
  length: Array.isArray(db[name]) && db[name].length,
18
- })
18
+ }),
19
19
  )
20
20
  .join('')}
21
21
  </ul>
@@ -40,7 +40,7 @@ window
40
40
  .then((response) => response.json())
41
41
  .then(
42
42
  (db) =>
43
- (document.getElementById('resources').innerHTML = ResourcesBlock({ db }))
43
+ (document.getElementById('resources').innerHTML = ResourcesBlock({ db })),
44
44
  )
45
45
 
46
46
  function CustomRoutesBlock({ customRoutes }) {
@@ -56,7 +56,7 @@ function CustomRoutesBlock({ customRoutes }) {
56
56
  `<tr>
57
57
  <td>${rule}</td>
58
58
  <td><code>⇢</code> ${customRoutes[rule]}</td>
59
- </tr>`
59
+ </tr>`,
60
60
  )
61
61
  .join('')}
62
62
  </table>
@@ -72,5 +72,5 @@ window
72
72
  (customRoutes) =>
73
73
  (document.getElementById('custom-routes').innerHTML = CustomRoutesBlock({
74
74
  customRoutes,
75
- }))
75
+ })),
76
76
  )