@openaddresses/batch-schema 3.1.2 → 4.1.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/.github/workflows/release.yml +29 -0
- package/.github/workflows/test.yml +1 -1
- package/CHANGELOG.md +14 -0
- package/docs/assets/anchor.js +350 -0
- package/docs/assets/bass-addons.css +12 -0
- package/docs/assets/bass.css +544 -0
- package/docs/assets/fonts/EOT/SourceCodePro-Bold.eot +0 -0
- package/docs/assets/fonts/EOT/SourceCodePro-Regular.eot +0 -0
- package/docs/assets/fonts/LICENSE.txt +93 -0
- package/docs/assets/fonts/OTF/SourceCodePro-Bold.otf +0 -0
- package/docs/assets/fonts/OTF/SourceCodePro-Regular.otf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Bold.ttf +0 -0
- package/docs/assets/fonts/TTF/SourceCodePro-Regular.ttf +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Bold.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/OTF/SourceCodePro-Regular.otf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Bold.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF/TTF/SourceCodePro-Regular.ttf.woff +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Bold.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/OTF/SourceCodePro-Regular.otf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Bold.ttf.woff2 +0 -0
- package/docs/assets/fonts/WOFF2/TTF/SourceCodePro-Regular.ttf.woff2 +0 -0
- package/docs/assets/fonts/source-code-pro.css +23 -0
- package/docs/assets/github.css +123 -0
- package/docs/assets/site.js +168 -0
- package/docs/assets/split.css +15 -0
- package/docs/assets/split.js +782 -0
- package/docs/assets/style.css +147 -0
- package/docs/index.html +792 -0
- package/lib/schema.js +10 -11
- package/package.json +9 -6
- package/test/schema.srv.test.js +25 -22
package/lib/schema.js
CHANGED
|
@@ -35,15 +35,12 @@ class Param {
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* @class
|
|
38
|
+
*
|
|
39
|
+
* @param {Object} router Express Router Object
|
|
40
|
+
* @param {Object} opts Options Object
|
|
41
|
+
* @param {String} opts.schemas Schemas Path
|
|
38
42
|
*/
|
|
39
43
|
export default class Schemas {
|
|
40
|
-
/**
|
|
41
|
-
* @constructor
|
|
42
|
-
*
|
|
43
|
-
* @param {Object} router Express Router Object
|
|
44
|
-
* @param {Object} opts Options Object
|
|
45
|
-
* @param {String} opts.schemas Schemas Path
|
|
46
|
-
*/
|
|
47
44
|
constructor(router, opts = {}) {
|
|
48
45
|
if (!router) throw new Error('Router Param Required');
|
|
49
46
|
|
|
@@ -180,11 +177,13 @@ export default class Schemas {
|
|
|
180
177
|
*/
|
|
181
178
|
static query(schema) {
|
|
182
179
|
return function (req, res, next) {
|
|
183
|
-
for (const key
|
|
180
|
+
for (const key in req.query) {
|
|
184
181
|
if (!schema.properties[key] || !schema.properties[key].type) continue;
|
|
185
182
|
|
|
186
183
|
// For easier processing use consistent array format IE: `type: ["integer", "boolean"]` vs type: "integer"
|
|
187
|
-
if (!Array.isArray(schema.properties[key].type))
|
|
184
|
+
if (!Array.isArray(schema.properties[key].type)) {
|
|
185
|
+
schema.properties[key].type = [schema.properties[key].type];
|
|
186
|
+
}
|
|
188
187
|
|
|
189
188
|
for (const type of schema.properties[key].type) {
|
|
190
189
|
if (type === 'integer' && !isNaN(parseInt(req.query[key]))) {
|
|
@@ -203,8 +202,8 @@ export default class Schemas {
|
|
|
203
202
|
}
|
|
204
203
|
}
|
|
205
204
|
|
|
206
|
-
for (const key
|
|
207
|
-
if (req.query[key] === undefined && schema.properties[key].default) {
|
|
205
|
+
for (const key in schema.properties) {
|
|
206
|
+
if (req.query[key] === undefined && schema.properties[key].default !== undefined) {
|
|
208
207
|
req.query[key] = schema.properties[key].default;
|
|
209
208
|
}
|
|
210
209
|
}
|
package/package.json
CHANGED
|
@@ -3,27 +3,30 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"root": true,
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "4.1.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>",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"private": false,
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">= 18"
|
|
14
|
+
},
|
|
12
15
|
"scripts": {
|
|
13
16
|
"test": "tape test/**.test.js",
|
|
14
|
-
"lint": "eslint index.js lib/**.js routes/**.js test/**.js"
|
|
17
|
+
"lint": "eslint index.js lib/**.js routes/**.js test/**.js",
|
|
18
|
+
"doc": "documentation build index.js -f html -o docs && documentation lint index.js"
|
|
15
19
|
},
|
|
16
20
|
"dependencies": {
|
|
17
21
|
"ajv": "^8.6.3",
|
|
18
22
|
"express": "^4.17.1",
|
|
19
|
-
"express-json-validator-middleware": "^
|
|
20
|
-
"glob": "^
|
|
21
|
-
"got": "^11.8.2",
|
|
23
|
+
"express-json-validator-middleware": "^3.0.0",
|
|
24
|
+
"glob": "^8.0.0",
|
|
22
25
|
"json-schema-ref-parser": "^9.0.9",
|
|
23
|
-
"request": "^2.88.2",
|
|
24
26
|
"tape": "^5.3.1"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
29
|
+
"documentation": "^13.2.5",
|
|
27
30
|
"eslint": "^8.0.1",
|
|
28
31
|
"eslint-plugin-node": "^11.0.0"
|
|
29
32
|
}
|
package/test/schema.srv.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import test from 'tape';
|
|
2
2
|
import express from 'express';
|
|
3
3
|
import { Schema } from '../index.js';
|
|
4
|
-
import got from 'got';
|
|
5
4
|
|
|
6
5
|
const app = express();
|
|
7
6
|
const schema = new Schema(express.Router(), {
|
|
@@ -24,11 +23,10 @@ test('start', (t) => {
|
|
|
24
23
|
|
|
25
24
|
test('GET: api/schema', async (t) => {
|
|
26
25
|
try {
|
|
27
|
-
const res = await
|
|
28
|
-
|
|
29
|
-
}).json();
|
|
26
|
+
const res = await fetch('http://localhost:2000/api/schema');
|
|
27
|
+
const body = await res.json();
|
|
30
28
|
|
|
31
|
-
t.deepEquals(
|
|
29
|
+
t.deepEquals(body, {
|
|
32
30
|
'GET /schema':{
|
|
33
31
|
body: false,
|
|
34
32
|
query: true,
|
|
@@ -44,22 +42,25 @@ test('GET: api/schema', async (t) => {
|
|
|
44
42
|
|
|
45
43
|
test('GET: api/schema?method=FAKE', async (t) => {
|
|
46
44
|
try {
|
|
47
|
-
await
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
const res = await fetch('http://localhost:2000/api/schema?method=fake');
|
|
46
|
+
|
|
47
|
+
t.notOk(res.ok);
|
|
48
|
+
|
|
49
|
+
t.deepEquals(await res.json(), {
|
|
51
50
|
status: 400,
|
|
52
51
|
message: 'validation error',
|
|
53
52
|
messages: [{
|
|
54
53
|
keyword: 'enum',
|
|
55
|
-
|
|
54
|
+
instancePath: '/method',
|
|
56
55
|
schemaPath: '#/properties/method/enum',
|
|
57
56
|
params: {
|
|
58
57
|
allowedValues: ['GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH']
|
|
59
58
|
},
|
|
60
|
-
message: '
|
|
59
|
+
message: 'must be equal to one of the allowed values'
|
|
61
60
|
}]
|
|
62
61
|
});
|
|
62
|
+
} catch (err) {
|
|
63
|
+
t.error(err);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
t.end();
|
|
@@ -67,28 +68,30 @@ test('GET: api/schema?method=FAKE', async (t) => {
|
|
|
67
68
|
|
|
68
69
|
test('GET: api/schema?method=GET', async (t) => {
|
|
69
70
|
try {
|
|
70
|
-
await
|
|
71
|
-
t.
|
|
72
|
-
|
|
73
|
-
t.deepEquals(JSON.parse(err.response.body), {
|
|
71
|
+
const res = await fetch('http://localhost:2000/api/schema?method=GET');
|
|
72
|
+
t.notOk(res.ok);
|
|
73
|
+
t.deepEquals(await res.json(), {
|
|
74
74
|
status: 400,
|
|
75
75
|
message: 'url & method params must be used together',
|
|
76
76
|
messages: []
|
|
77
77
|
});
|
|
78
|
+
} catch (err) {
|
|
79
|
+
t.error(err);
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
t.end();
|
|
81
83
|
});
|
|
82
84
|
test('GET: api/schema?url=123', async (t) => {
|
|
83
85
|
try {
|
|
84
|
-
await
|
|
85
|
-
t.
|
|
86
|
-
|
|
87
|
-
t.deepEquals(JSON.parse(err.response.body), {
|
|
86
|
+
const res = await fetch('http://localhost:2000/api/schema?url=123');
|
|
87
|
+
t.notOk(res.ok);
|
|
88
|
+
t.deepEquals(await res.json(), {
|
|
88
89
|
status: 400,
|
|
89
90
|
message: 'url & method params must be used together',
|
|
90
91
|
messages: []
|
|
91
92
|
});
|
|
93
|
+
} catch (err) {
|
|
94
|
+
t.error(err);
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
t.end();
|
|
@@ -96,10 +99,10 @@ test('GET: api/schema?url=123', async (t) => {
|
|
|
96
99
|
|
|
97
100
|
test('GET: api/schema?method=GET&url=/schema', async (t) => {
|
|
98
101
|
try {
|
|
99
|
-
const res = await
|
|
102
|
+
const res = await fetch('http://localhost:2000/api/schema?method=GET&url=/schema');
|
|
100
103
|
|
|
101
|
-
t.equals(res.
|
|
102
|
-
t.deepEquals(Object.keys(
|
|
104
|
+
t.equals(res.status, 200, 'http: 200');
|
|
105
|
+
t.deepEquals(Object.keys(await res.json()).sort(), ['query', 'body', 'res'].sort());
|
|
103
106
|
|
|
104
107
|
} catch (err) {
|
|
105
108
|
t.error(err, 'no error');
|