@bedrockio/yada 1.0.3 → 1.0.4

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) {
@@ -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;
@@ -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
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@bedrockio/yada",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Validation library inspired by Joi.",
5
5
  "scripts": {
6
6
  "test": "NODE_OPTIONS=--experimental-vm-modules 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",
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/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
  }