@openaddresses/batch-schema 2.3.3 → 3.0.0
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/.eslintrc.json +2 -2
- package/CHANGELOG.md +12 -0
- package/README.md +19 -1
- package/index.js +6 -3
- package/lib/error.js +1 -5
- package/lib/schema.js +22 -13
- package/package-lock.json +5491 -0
- package/package.json +3 -2
- package/routes/schema.js +2 -5
- package/test/schema.srv.test.js +4 -5
- package/test/schema.test.js +8 -9
package/.eslintrc.json
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"Map": true
|
|
9
9
|
},
|
|
10
10
|
"parserOptions": {
|
|
11
|
-
"ecmaVersion": 13
|
|
11
|
+
"ecmaVersion": 13,
|
|
12
|
+
"sourceType": "module"
|
|
12
13
|
},
|
|
13
14
|
"plugins": [ "node" ],
|
|
14
15
|
"rules": {
|
|
@@ -39,7 +40,6 @@
|
|
|
39
40
|
"template-curly-spacing": [ "error", "never" ],
|
|
40
41
|
"semi-spacing": "error",
|
|
41
42
|
"strict": "error",
|
|
42
|
-
"node/no-unsupported-features": [ "error", { "version": 8 } ],
|
|
43
43
|
"node/no-missing-require": "error",
|
|
44
44
|
"valid-jsdoc": ["error", {
|
|
45
45
|
"requireParamDescription": false,
|
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
|
|
11
11
|
## Version History
|
|
12
12
|
|
|
13
|
+
### v3.0.0
|
|
14
|
+
|
|
15
|
+
- :rocket: Update to ES Module System
|
|
16
|
+
|
|
17
|
+
### v2.4.0
|
|
18
|
+
|
|
19
|
+
- :tada: Add `schema.not_found()`
|
|
20
|
+
|
|
21
|
+
### v2.3.4
|
|
22
|
+
|
|
23
|
+
- :arrow_up: Update base deps
|
|
24
|
+
|
|
13
25
|
### v2.3.3
|
|
14
26
|
|
|
15
27
|
- :rocket: Name exports explicitly instead of returning object for ES module compat.
|
package/README.md
CHANGED
|
@@ -5,7 +5,13 @@
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
|
|
8
|
+
yarn add @openaddresses/batch-schema
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
or
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm i @openaddresses/batch-schema
|
|
9
15
|
```
|
|
10
16
|
|
|
11
17
|
## Example Usage
|
|
@@ -37,6 +43,9 @@ async function server() {
|
|
|
37
43
|
});
|
|
38
44
|
});
|
|
39
45
|
|
|
46
|
+
// Handle Unmatched Routes
|
|
47
|
+
schema.not_found();
|
|
48
|
+
|
|
40
49
|
// Handle Validation Errors => JSON Middleware
|
|
41
50
|
schema.error();
|
|
42
51
|
}
|
|
@@ -66,6 +75,15 @@ Adds a route called `GET /schema` which allows the caller to get a list of endpo
|
|
|
66
75
|
as well as full schema details for every route. If your API is public we recommend enabling this feature, however
|
|
67
76
|
if you do not wish for API routes to be published, this feature is disabled unless called.
|
|
68
77
|
|
|
78
|
+
### schema.not_found
|
|
79
|
+
|
|
80
|
+
Adds a middlware which will catch all routes that have not been defined and return
|
|
81
|
+
a standard error object.
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
schema.not_found()
|
|
85
|
+
```
|
|
86
|
+
|
|
69
87
|
### schema.error
|
|
70
88
|
|
|
71
89
|
Adds a middlware which will convert validation errors into a standard JSON error format.
|
package/index.js
CHANGED
package/lib/error.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* @class
|
|
5
3
|
*/
|
|
6
|
-
class PublicError {
|
|
4
|
+
export default class PublicError {
|
|
7
5
|
constructor(status, err, safe, print = true) {
|
|
8
6
|
// Wrap postgres errors to ensure stack trace (line nums) are returned
|
|
9
7
|
if (err && err.severity) err = new Error(err);
|
|
@@ -43,5 +41,3 @@ class PublicError {
|
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
module.exports = PublicError;
|
package/lib/schema.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { Validator } from 'express-json-validator-middleware';
|
|
2
|
+
import { ValidationError } from 'express-json-validator-middleware';
|
|
3
|
+
import $RefParser from 'json-schema-ref-parser';
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const Err = require('./error');
|
|
7
|
-
const SchemaRoute = require('../routes/schema');
|
|
8
|
-
const { ValidationError } = require('express-json-validator-middleware');
|
|
5
|
+
import Err from './error.js';
|
|
6
|
+
import SchemaRoute from '../routes/schema.js';
|
|
9
7
|
|
|
10
8
|
/**
|
|
11
9
|
* @class
|
|
@@ -38,7 +36,7 @@ class Param {
|
|
|
38
36
|
/**
|
|
39
37
|
* @class
|
|
40
38
|
*/
|
|
41
|
-
class Schemas {
|
|
39
|
+
export default class Schemas {
|
|
42
40
|
/**
|
|
43
41
|
* @constructor
|
|
44
42
|
*
|
|
@@ -50,7 +48,7 @@ class Schemas {
|
|
|
50
48
|
if (!router) throw new Error('Router Param Required');
|
|
51
49
|
|
|
52
50
|
if (!opts.schemas) {
|
|
53
|
-
this.schemas_path =
|
|
51
|
+
this.schemas_path = String(new URL('../schema/', import.meta.url)).replace('file://', '');
|
|
54
52
|
} else {
|
|
55
53
|
this.schemas_path = opts.schemas;
|
|
56
54
|
}
|
|
@@ -121,9 +119,9 @@ class Schemas {
|
|
|
121
119
|
if (!schemas[type]) continue;
|
|
122
120
|
|
|
123
121
|
try {
|
|
124
|
-
schemas[type] = await $RefParser.dereference(
|
|
122
|
+
schemas[type] = await $RefParser.dereference(`../schema/${schemas[type]}`);
|
|
125
123
|
} catch (err) {
|
|
126
|
-
schemas[type] = await $RefParser.dereference(
|
|
124
|
+
schemas[type] = await $RefParser.dereference(`${this.schemas_path}/${schemas[type]}`);
|
|
127
125
|
}
|
|
128
126
|
}
|
|
129
127
|
|
|
@@ -236,6 +234,19 @@ class Schemas {
|
|
|
236
234
|
return schema;
|
|
237
235
|
}
|
|
238
236
|
|
|
237
|
+
/**
|
|
238
|
+
* Catch all for unmatched routes
|
|
239
|
+
*/
|
|
240
|
+
not_found() {
|
|
241
|
+
this.router.all('*', (req, res) => {
|
|
242
|
+
return res.status(404).json({
|
|
243
|
+
status: 404,
|
|
244
|
+
message: 'API endpoint does not exist!',
|
|
245
|
+
messages: []
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
239
250
|
/**
|
|
240
251
|
* Convert validation errors into standardized JSON Error Messages
|
|
241
252
|
*/
|
|
@@ -281,5 +292,3 @@ class Schemas {
|
|
|
281
292
|
return lite;
|
|
282
293
|
}
|
|
283
294
|
}
|
|
284
|
-
|
|
285
|
-
module.exports = Schemas;
|