@bedrockio/yada 1.0.3 → 1.0.5

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.
@@ -192,7 +192,7 @@ class Schema {
192
192
  if ((0, _errors.isSchemaError)(error)) {
193
193
  throw error;
194
194
  }
195
- throw new _errors.AssertionError(error.message, type, error);
195
+ throw new _errors.AssertionError(error.message, error.type || type, error);
196
196
  }
197
197
  }
198
198
  toOpenApi(extra) {
@@ -27,4 +27,5 @@ class TypeSchema extends _Schema.default {
27
27
  };
28
28
  }
29
29
  }
30
- exports.default = TypeSchema;
30
+ exports.default = TypeSchema;
31
+ module.exports = exports.default;
package/dist/cjs/array.js CHANGED
@@ -125,4 +125,5 @@ class ArraySchema extends _Schema.default {
125
125
  }
126
126
  }
127
127
  var _default = (0, _utils.wrapSchema)(ArraySchema);
128
- exports.default = _default;
128
+ exports.default = _default;
129
+ module.exports = exports.default;
@@ -26,4 +26,5 @@ class BooleanSchema extends _TypeSchema.default {
26
26
  }
27
27
  }
28
28
  var _default = (0, _utils.wrapSchema)(BooleanSchema);
29
- exports.default = _default;
29
+ exports.default = _default;
30
+ module.exports = exports.default;
package/dist/cjs/date.js CHANGED
@@ -127,4 +127,5 @@ class DateSchema extends _Schema.default {
127
127
  }
128
128
  }
129
129
  var _default = (0, _utils.wrapSchema)(DateSchema);
130
- exports.default = _default;
130
+ exports.default = _default;
131
+ module.exports = exports.default;
@@ -8,6 +8,10 @@ var _localization = require("./localization");
8
8
  class LocalizedError extends Error {
9
9
  constructor(message, values) {
10
10
  super((0, _localization.localize)(message, values));
11
+ this.values = values;
12
+ }
13
+ get type() {
14
+ return this.values?.type;
11
15
  }
12
16
  }
13
17
  exports.LocalizedError = LocalizedError;
package/dist/cjs/index.js CHANGED
@@ -9,13 +9,8 @@ var _number = _interopRequireDefault(require("./number"));
9
9
  var _object = _interopRequireDefault(require("./object"));
10
10
  var _string = _interopRequireDefault(require("./string"));
11
11
  var _utils = require("./utils");
12
- exports.isSchema = _utils.isSchema;
13
- exports.isSchemaError = _utils.isSchemaError;
14
12
  var _localization = require("./localization");
15
- exports.useLocalizer = _localization.useLocalizer;
16
- exports.getLocalizerTemplates = _localization.getLocalizerTemplates;
17
13
  var _errors = require("./errors");
18
- exports.LocalizedError = _errors.LocalizedError;
19
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
15
  const allow = (0, _utils.wrapArgs)('allow');
21
16
  const reject = (0, _utils.wrapArgs)('reject');
@@ -31,6 +26,12 @@ var _default = {
31
26
  any,
32
27
  allow,
33
28
  reject,
34
- custom
29
+ custom,
30
+ isSchema: _utils.isSchema,
31
+ isSchemaError: _utils.isSchemaError,
32
+ useLocalizer: _localization.useLocalizer,
33
+ getLocalizerTemplates: _localization.getLocalizerTemplates,
34
+ LocalizedError: _errors.LocalizedError
35
35
  };
36
- exports.default = _default;
36
+ exports.default = _default;
37
+ module.exports = exports.default;
@@ -88,4 +88,5 @@ class NumberSchema extends _TypeSchema.default {
88
88
  }
89
89
  }
90
90
  var _default = (0, _utils.wrapSchema)(NumberSchema);
91
- exports.default = _default;
91
+ exports.default = _default;
92
+ module.exports = exports.default;
@@ -35,7 +35,8 @@ class ObjectSchema extends _TypeSchema.default {
35
35
  result[key] = obj[key];
36
36
  } else if (!stripUnknown) {
37
37
  throw new _errors.LocalizedError('Unknown field "{key}".', {
38
- key
38
+ key,
39
+ type: 'field'
39
40
  });
40
41
  }
41
42
  }
@@ -101,4 +102,5 @@ class ObjectSchema extends _TypeSchema.default {
101
102
  }
102
103
  }
103
104
  var _default = (0, _utils.wrapSchema)(ObjectSchema);
104
- exports.default = _default;
105
+ exports.default = _default;
106
+ module.exports = exports.default;
@@ -277,4 +277,5 @@ class StringSchema extends _TypeSchema.default {
277
277
  }
278
278
  }
279
279
  var _default = (0, _utils.wrapSchema)(StringSchema);
280
- exports.default = _default;
280
+ exports.default = _default;
281
+ module.exports = exports.default;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bedrockio/yada",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Validation library inspired by Joi.",
5
5
  "scripts": {
6
- "test": "NODE_OPTIONS=--experimental-vm-modules jest",
6
+ "test": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest",
7
7
  "lint": "eslint",
8
8
  "build": "scripts/build",
9
- "prepublish": "scripts/build"
9
+ "prepublishOnly": "npm run build"
10
10
  },
11
11
  "type": "module",
12
12
  "main": "dist/cjs/index.js",
@@ -15,13 +15,14 @@
15
15
  "author": "Andrew Plummer <plummer.andrew@gmail.com>",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "validator": "^13.7.0"
18
+ "validator": "^13.9.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@babel/cli": "^7.19.3",
22
22
  "@babel/core": "^7.19.6",
23
23
  "@babel/preset-env": "^7.19.4",
24
24
  "@bedrockio/prettier-config": "^1.0.2",
25
+ "babel-plugin-add-module-exports": "^1.0.4",
25
26
  "eslint": "^8.26.0",
26
27
  "eslint-plugin-bedrock": "^1.0.17",
27
28
  "jest": "^29.2.2",
package/src/Schema.js CHANGED
@@ -196,7 +196,7 @@ export default class Schema {
196
196
  if (isSchemaError(error)) {
197
197
  throw error;
198
198
  }
199
- throw new AssertionError(error.message, type, error);
199
+ throw new AssertionError(error.message, error.type || type, error);
200
200
  }
201
201
  }
202
202
 
package/src/errors.js CHANGED
@@ -4,6 +4,11 @@ import { localize } from './localization';
4
4
  export class LocalizedError extends Error {
5
5
  constructor(message, values) {
6
6
  super(localize(message, values));
7
+ this.values = values;
8
+ }
9
+
10
+ get type() {
11
+ return this.values?.type;
7
12
  }
8
13
  }
9
14
 
package/src/index.js CHANGED
@@ -25,9 +25,6 @@ export default {
25
25
  allow,
26
26
  reject,
27
27
  custom,
28
- };
29
-
30
- export {
31
28
  isSchema,
32
29
  isSchemaError,
33
30
  useLocalizer,
package/src/object.js CHANGED
@@ -28,6 +28,7 @@ class ObjectSchema extends TypeSchema {
28
28
  } else if (!stripUnknown) {
29
29
  throw new LocalizedError('Unknown field "{key}".', {
30
30
  key,
31
+ type: 'field',
31
32
  });
32
33
  }
33
34
  }