@openaddresses/batch-schema 7.2.0 → 7.4.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/CHANGELOG.md +8 -0
- package/lib/middleware.js +6 -0
- package/lib/schema.js +13 -0
- package/package.json +4 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
|
|
11
11
|
## Version History
|
|
12
12
|
|
|
13
|
+
### v7.4.0
|
|
14
|
+
|
|
15
|
+
- :tada: Add experimental `blueprint()` function
|
|
16
|
+
|
|
17
|
+
### v7.3.0
|
|
18
|
+
|
|
19
|
+
- :arrow_up: `res.json` will automatically serialize Generic objects
|
|
20
|
+
|
|
13
21
|
### v7.2.0
|
|
14
22
|
|
|
15
23
|
- :tada: Preliminary support for automatically generated an APIDoc definitions file
|
package/lib/middleware.js
CHANGED
|
@@ -3,6 +3,7 @@ import Param from './param.js';
|
|
|
3
3
|
import Ajv from 'ajv';
|
|
4
4
|
import addFormats from 'ajv-formats';
|
|
5
5
|
import { ValidationError } from 'express-json-validator-middleware';
|
|
6
|
+
import Generic from '@openaddresses/batch-generic';
|
|
6
7
|
|
|
7
8
|
const ajv = addFormats(new Ajv({
|
|
8
9
|
allErrors: true,
|
|
@@ -99,6 +100,7 @@ export default class Middleware {
|
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
102
|
* Express middleware to validate the response body
|
|
103
|
+
* and optionally serialize Generic object to JSON
|
|
102
104
|
*
|
|
103
105
|
* @param {Object} schema JSON Schema
|
|
104
106
|
*
|
|
@@ -110,6 +112,10 @@ export default class Middleware {
|
|
|
110
112
|
return function (req, res, next) {
|
|
111
113
|
const json = res.json;
|
|
112
114
|
res.json = function(obj) {
|
|
115
|
+
if (obj instanceof Generic && typeof obj.serialize === 'function') {
|
|
116
|
+
obj = obj.serialize();
|
|
117
|
+
}
|
|
118
|
+
|
|
113
119
|
if (res.statusCode === null || res.statusCode === 200) {
|
|
114
120
|
validate(obj);
|
|
115
121
|
}
|
package/lib/schema.js
CHANGED
|
@@ -76,6 +76,19 @@ export default class Schemas {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Load a blueprint into the router
|
|
81
|
+
*
|
|
82
|
+
* @param {Object} bp_class Blueprint Class with blueprint() fn
|
|
83
|
+
* @param {object} config Config Object
|
|
84
|
+
* @param {Object} opts Options Object
|
|
85
|
+
* @param {boolean} opts.silent Squelch StdOut
|
|
86
|
+
*/
|
|
87
|
+
async blueprint(bp_class, config, opts = {}) {
|
|
88
|
+
if (!opts.silent) console.error(`ok - loaded ${bp_class}`);
|
|
89
|
+
await bp_class.blueprint(this, config);
|
|
90
|
+
}
|
|
91
|
+
|
|
79
92
|
check(url, schemas, fns) {
|
|
80
93
|
if (typeof url !== 'string') throw new Error('URL should be string');
|
|
81
94
|
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"root": true,
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"version": "7.
|
|
6
|
+
"version": "7.4.0",
|
|
7
7
|
"description": "Strongly Validated JSON Schema support for address",
|
|
8
8
|
"repository": "git@github.com:openaddresses/batch-schema",
|
|
9
9
|
"author": "ingalls <nick@ingalls.ca>",
|
|
@@ -29,6 +29,9 @@
|
|
|
29
29
|
"morgan": "^1.10.0",
|
|
30
30
|
"tape": "^5.3.1"
|
|
31
31
|
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@openaddresses/batch-generic": "x.x.x"
|
|
34
|
+
},
|
|
32
35
|
"devDependencies": {
|
|
33
36
|
"documentation": "^13.2.5",
|
|
34
37
|
"eslint": "^8.0.1",
|