@openaddresses/batch-schema 7.3.0 → 7.5.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 CHANGED
@@ -10,6 +10,14 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v7.5.0
14
+
15
+ - :tada: Add support for inline JSON Schemas
16
+
17
+ ### v7.4.0
18
+
19
+ - :tada: Add experimental `blueprint()` function
20
+
13
21
  ### v7.3.0
14
22
 
15
23
  - :arrow_up: `res.json` will automatically serialize Generic objects
package/lib/schema.js CHANGED
@@ -71,11 +71,24 @@ export default class Schemas {
71
71
 
72
72
  // Load dynamic routes directory
73
73
  for (const r of fs.readdirSync(dirpath)) {
74
- if (!opts.silent) console.error(`ok - loaded routes/${r}`);
74
+ if (!opts.silent) console.log(`ok - loaded routes/${r}`);
75
75
  await (await import(path.resolve(dirpath, r))).default(this, config);
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.log(`ok - loaded ${bp_class.name}`);
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
 
@@ -127,11 +140,17 @@ export default class Schemas {
127
140
  if (!schemas[type]) continue;
128
141
 
129
142
  // TODO: Write schemas to a tmp directory so blueprints & main schemas are in the same place
130
- schemas[`${type}_url`] = '../schema/' + schemas[type];
131
- try {
132
- schemas[type] = await $RefParser.dereference((new URL(`../schema/${schemas[type]}`, import.meta.url)).pathname);
133
- } catch (err) {
134
- schemas[type] = await $RefParser.dereference(`${this.schemas_path}/${schemas[type]}`);
143
+ if (typeof schemas[type] === 'object') {
144
+ schemas[`${type}_url`] = null;
145
+ } else if (typeof schemas[type] === 'string') {
146
+ schemas[`${type}_url`] = '../schema/' + schemas[type];
147
+ try {
148
+ schemas[type] = await $RefParser.dereference((new URL(`../schema/${schemas[type]}`, import.meta.url)).pathname);
149
+ } catch (err) {
150
+ schemas[type] = await $RefParser.dereference(`${this.schemas_path}/${schemas[type]}`);
151
+ }
152
+ } else {
153
+ throw new Error(`Unsupported Value in ${type} value for ${url}`);
135
154
  }
136
155
  }
137
156
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "root": true,
5
5
  "main": "index.js",
6
- "version": "7.3.0",
6
+ "version": "7.5.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>",