@openaddresses/batch-schema 4.3.0 → 5.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/CHANGELOG.md CHANGED
@@ -10,6 +10,18 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v5.1.0
14
+
15
+ - :rocket: Support `URL` in `Schema.load`
16
+
17
+ ### v5.0.0
18
+
19
+ - :tada: Logging and body parsing enabled by default
20
+
21
+ ### v4.4.0
22
+
23
+ - :rocket: Add ability to take a `URL` as a schemas directory
24
+
13
25
  ### v4.3.0
14
26
 
15
27
  - :arrow_up: Update base deps
package/lib/schema.js CHANGED
@@ -3,6 +3,8 @@ import { ValidationError } from 'express-json-validator-middleware';
3
3
  import $RefParser from 'json-schema-ref-parser';
4
4
  import fs from 'fs';
5
5
  import path from 'path';
6
+ import morgan from 'morgan';
7
+ import bodyparser from 'body-parser';
6
8
 
7
9
  import Err from './error.js';
8
10
  import SchemaRoute from '../routes/schema.js';
@@ -41,14 +43,19 @@ class Param {
41
43
  * @param {Object} router Express Router Object
42
44
  * @param {Object} opts Options Object
43
45
  * @param {String} opts.schemas Schemas Path
46
+ * @param {boolean|string} [opts.logging=true] disable logging with false
47
+ * @param {number} [opts.limit=50] body size limit in mb
44
48
  */
45
49
  export default class Schemas {
46
50
  constructor(router, opts = {}) {
47
51
  if (!router) throw new Error('Router Param Required');
48
52
 
49
53
  if (!opts.schemas) {
50
- this.schemas_path = String(new URL('../schema/', import.meta.url)).replace('file://', '');
54
+ this.schemas_path = new URL('../schema/', import.meta.url).pathname;
51
55
  } else {
56
+ if (opts.schemas instanceof URL) opts.schemas = opts.schemas.pathname;
57
+ else opts.schemas = String(opts.schemas);
58
+
52
59
  this.schemas_path = opts.schemas;
53
60
  }
54
61
 
@@ -59,6 +66,11 @@ export default class Schemas {
59
66
  });
60
67
 
61
68
  this.router = router;
69
+
70
+ if (opts.morgan !== false) this.router.use(morgan('combined'));
71
+ this.router.use(bodyparser.urlencoded({ extended: true }));
72
+ this.router.use(bodyparser.json({ limit: `${opts.limit}mb` }));
73
+
62
74
  this.schemas = new Map();
63
75
  this.validate = this.validator.validate;
64
76
  }
@@ -77,6 +89,9 @@ export default class Schemas {
77
89
  * @param {boolean} opts.silent Squelch StdOut
78
90
  */
79
91
  async load(dirpath, config, opts = {}) {
92
+ if (dirpath instanceof URL) dirpath = dirpath.pathname;
93
+ else dirpath = String(dirpath);
94
+
80
95
  // Load dynamic routes directory
81
96
  for (const r of fs.readdirSync(dirpath)) {
82
97
  if (!opts.silent) console.error(`ok - loaded routes/${r}`);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "root": true,
5
5
  "main": "index.js",
6
- "version": "4.3.0",
6
+ "version": "5.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>",
@@ -19,10 +19,12 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "ajv": "^8.6.3",
22
+ "body-parser": "^1.20.0",
22
23
  "express": "^4.17.1",
23
24
  "express-json-validator-middleware": "^3.0.0",
24
25
  "glob": "^8.0.0",
25
26
  "json-schema-ref-parser": "^9.0.9",
27
+ "morgan": "^1.10.0",
26
28
  "tape": "^5.3.1"
27
29
  },
28
30
  "devDependencies": {