@bedrockio/yada 1.0.40 → 1.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/README.md CHANGED
@@ -19,12 +19,13 @@ Concepts
19
19
  - [Object](#object)
20
20
  - [Date](#date)
21
21
  - [Common Methods](#common-methods)
22
- - [Allow](#allow)
23
- - [Reject](#reject)
24
- - [Append](#append)
25
- - [Custom](#custom)
26
- - [Default](#default)
27
- - [Strip](#strip)
22
+ - [allow](#allow)
23
+ - [reject](#reject)
24
+ - [append](#append)
25
+ - [custom](#custom)
26
+ - [default](#default)
27
+ - [strip](#strip)
28
+ - [message](#message)
28
29
  - [Validation Options](#validation-options)
29
30
  - [Error Messages](#error-messages)
30
31
  - [Localization](#localization)
@@ -552,6 +553,65 @@ const schema = yd.object({
552
553
  Arguments are identical to those passed to [custom](#custom). The field will be
553
554
  stripped out if the function returns a truthy value.
554
555
 
556
+ ### Message
557
+
558
+ The `message` method allows adding a custom message to schema or field. Note
559
+ that when using with [`getFullMessage`](#error-messages) the custom message will
560
+ not include the nested field name by default:
561
+
562
+ ```js
563
+ const schema = yd.object({
564
+ name: yd.string().required().message('Please provide your full name.'),
565
+ });
566
+ try {
567
+ await schema.validate({});
568
+ } catch (error) {
569
+ console.log(error.getFullMessage());
570
+ // -> Please provide your full name.
571
+ }
572
+ ```
573
+
574
+ To include the field name, the `{field}` token may be used in the message:
575
+
576
+ ```js
577
+ const schema = yd.object({
578
+ name: yd
579
+ .string()
580
+ .match(/^[A-Z]/)
581
+ .message('{field} must start with an uppercase letter.'),
582
+ });
583
+ try {
584
+ await schema.validate({
585
+ name: 'frank',
586
+ });
587
+ } catch (error) {
588
+ console.log(error.getFullMessage());
589
+ // -> "name" must start with an uppercase letter.
590
+ }
591
+ ```
592
+
593
+ The `{field}` token may also be used when throwing custom errors:
594
+
595
+ ```js
596
+ const schema = yd.object({
597
+ profile: yd.object({
598
+ name: yd.custom((value) => {
599
+ if (value !== 'Frank') {
600
+ throw new Error('{field} must be "Frank".');
601
+ }
602
+ }),
603
+ }),
604
+ });
605
+ try {
606
+ await schema.validate({
607
+ name: 'Bob',
608
+ });
609
+ } catch (error) {
610
+ console.log(error.getFullMessage());
611
+ // -> "name" must be "Frank".
612
+ }
613
+ ```
614
+
555
615
  ## Validation Options
556
616
 
557
617
  Validation options in Yada can be passed at runtime on validation or baked into
@@ -634,7 +694,6 @@ which returns that map:
634
694
  ```js
635
695
  yd.useLocalizer({
636
696
  'Must be at least {length} character{s}.': '{length}文字以上入力して下さい。',
637
- 'Object failed validation.': '不正な入力がありました。',
638
697
  });
639
698
  ```
640
699
 
@@ -657,13 +716,11 @@ allow quick discovery of strings that have not yet been localized:
657
716
  ```js
658
717
  yd.useLocalizer({
659
718
  'Must be at least {length} character{s}.': '{length}文字以上入力して下さい。',
660
- 'Object failed validation.': '不正な入力がありました。',
661
719
  });
662
720
  // Error validation occuring here
663
721
  yd.getLocalizedMessages();
664
722
  // {
665
723
  // 'Must be at least {length} character{s}.': '{length}文字以上入力して下さい。',
666
- // 'Object failed validation.': '不正な入力がありました。',
667
724
  // 'Value must be a string.': 'Value must be a string.',
668
725
  // ...etc
669
726
  // }
@@ -13,7 +13,6 @@ const REQUIRED_TYPES = ['default', 'required'];
13
13
  /**
14
14
  * @typedef {[fn: Function] | [type: string, fn: Function]} CustomSignature
15
15
  */
16
-
17
16
  class Schema {
18
17
  constructor(meta = {}) {
19
18
  this.assertions = [];
@@ -157,8 +156,15 @@ class Schema {
157
156
  value = result;
158
157
  }
159
158
  } catch (error) {
160
- if (error instanceof _errors.ArrayError) {
161
- details = [...details, ...error.details];
159
+ const {
160
+ type
161
+ } = assertion;
162
+ if (type === 'type') {
163
+ details.push(new _errors.TypeError(error, this.meta.type));
164
+ } else if (type === 'format') {
165
+ details.push(new _errors.FormatError(error, this.meta.format));
166
+ } else if (!error.type) {
167
+ details.push(new _errors.AssertionError(error, type));
162
168
  } else {
163
169
  details.push(error);
164
170
  }
@@ -168,10 +174,7 @@ class Schema {
168
174
  }
169
175
  }
170
176
  if (details.length) {
171
- const {
172
- message = 'Input failed validation.'
173
- } = this.meta;
174
- throw new _errors.ValidationError(message, details);
177
+ throw new _errors.ValidationError(this.meta.message, details);
175
178
  }
176
179
  return value;
177
180
  }
@@ -266,12 +269,11 @@ class Schema {
266
269
  }
267
270
  return el;
268
271
  });
269
- const msg = `${allow ? 'Must' : 'Must not'} be one of [{types}].`;
272
+ const message = `${allow ? 'Must' : 'Must not'} be one of [{types}].`;
270
273
  return this.clone({
271
274
  enum: set
272
275
  }).assert('enum', async (val, options) => {
273
276
  if (val !== undefined) {
274
- let error;
275
277
  for (let el of set) {
276
278
  if (isSchema(el)) {
277
279
  try {
@@ -282,28 +284,23 @@ class Schema {
282
284
  return await el.validate(val, options);
283
285
  } catch (err) {
284
286
  const [first] = err.details;
285
- const isTypeError = first?.type === 'type';
286
- if (!isTypeError) {
287
- // Capture the first error object only if it is not
288
- // a simple type error to surface error messages on
289
- // more complex schemas. Otherwise allow this to fall
290
- // through to show more meaningful messages for simple
291
- // enums.
292
- error ||= err;
287
+ if (first instanceof _errors.TypeError) {
288
+ // If the error is a simple type error then continue
289
+ // to show more meaningful messages for simple enums.
290
+ continue;
291
+ } else {
292
+ // Otherwise throw the error to surface messages on
293
+ // more complex schemas.
294
+ throw err;
293
295
  }
294
- continue;
295
296
  }
296
297
  } else if (el === val === allow) {
297
298
  return;
298
299
  }
299
300
  }
300
- if (error) {
301
- throw new _errors.ValidationError(options.message || error.message, error.details);
302
- } else {
303
- throw new _errors.LocalizedError(options.message || msg, {
304
- types: types.join(', ')
305
- });
306
- }
301
+ throw new _errors.LocalizedError(message, {
302
+ types: types.join(', ')
303
+ });
307
304
  }
308
305
  });
309
306
  }
@@ -344,17 +341,9 @@ class Schema {
344
341
  }
345
342
  async runAssertion(assertion, value, options = {}) {
346
343
  const {
347
- type,
348
344
  fn
349
345
  } = assertion;
350
- try {
351
- return await fn(value, options);
352
- } catch (error) {
353
- if ((0, _errors.isSchemaError)(error)) {
354
- throw error;
355
- }
356
- throw new _errors.AssertionError(error.message, error.type || type, error);
357
- }
346
+ return await fn(value, options);
358
347
  }
359
348
  enumToOpenApi() {
360
349
  const {
@@ -10,8 +10,8 @@ class TypeSchema extends _Schema.default {
10
10
  constructor(Class, meta) {
11
11
  const type = Class.name.toLowerCase();
12
12
  super({
13
- type,
14
- ...meta
13
+ ...meta,
14
+ type
15
15
  });
16
16
  }
17
17
  format(name, fn) {
package/dist/cjs/array.js CHANGED
@@ -5,13 +5,13 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = _default;
7
7
  var _Schema = _interopRequireDefault(require("./Schema"));
8
+ var _TypeSchema = _interopRequireDefault(require("./TypeSchema"));
8
9
  var _errors = require("./errors");
9
10
  var _utils = require("./utils");
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- class ArraySchema extends _Schema.default {
12
+ class ArraySchema extends _TypeSchema.default {
12
13
  constructor(schemas) {
13
- super({
14
- message: 'Array failed validation.',
14
+ super(Array, {
15
15
  schemas
16
16
  });
17
17
  this.setup();
@@ -22,8 +22,7 @@ class ArraySchema extends _Schema.default {
22
22
  */
23
23
  setup() {
24
24
  const {
25
- schemas,
26
- message
25
+ schemas
27
26
  } = this.meta;
28
27
  const schema = schemas.length > 1 ? new _Schema.default().allow(schemas) : schemas[0];
29
28
  this.assert('type', (val, options) => {
@@ -36,6 +35,9 @@ class ArraySchema extends _Schema.default {
36
35
  return val;
37
36
  });
38
37
  if (schema) {
38
+ const {
39
+ message
40
+ } = schema.meta;
39
41
  this.assert('elements', async (arr, options) => {
40
42
  const errors = [];
41
43
  const result = [];
@@ -47,7 +49,7 @@ class ArraySchema extends _Schema.default {
47
49
  options = (0, _utils.omit)(options, 'message');
48
50
  result.push(await schema.validate(el, options));
49
51
  } catch (error) {
50
- errors.push(new _errors.ElementError('Element failed validation.', i, error.original, error.details));
52
+ errors.push(new _errors.ElementError(message, i, error.details));
51
53
  }
52
54
  }
53
55
  if (errors.length) {
@@ -3,58 +3,38 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.ValidationError = exports.LocalizedError = exports.FieldError = exports.ElementError = exports.AssertionError = exports.ArrayError = void 0;
6
+ exports.ValidationError = exports.TypeError = exports.LocalizedError = exports.FormatError = exports.FieldError = exports.ElementError = exports.AssertionError = exports.ArrayError = void 0;
7
7
  exports.isSchemaError = isSchemaError;
8
8
  var _messages = require("./messages");
9
9
  var _localization = require("./localization");
10
10
  class LocalizedError extends Error {
11
- constructor(message, values) {
11
+ constructor(message, values = {}) {
12
12
  super((0, _localization.localize)(message, values));
13
- this.values = values;
14
- }
15
- get type() {
16
- return this.values?.type;
17
13
  }
18
14
  }
19
15
  exports.LocalizedError = LocalizedError;
20
16
  class ValidationError extends Error {
21
- constructor(message, details = [], type = 'validation') {
22
- super((0, _localization.localize)(message));
17
+ constructor(arg, details = []) {
18
+ super(getLocalizedMessage(arg));
19
+ this.type = 'validation';
23
20
  this.details = details;
24
- this.type = type;
25
21
  }
26
22
  toJSON() {
27
- if (this.canRollup()) {
28
- const [first] = this.details;
29
- return {
30
- ...first.toJSON(),
31
- type: this.type
32
- };
33
- } else {
34
- return {
35
- type: this.type,
36
- message: this.message,
37
- details: this.details.map(error => {
38
- return error.toJSON();
39
- })
40
- };
41
- }
42
- }
43
- canRollup() {
44
23
  const {
24
+ message,
45
25
  details
46
26
  } = this;
47
- if (details.length !== 1) {
48
- return false;
49
- }
50
- const [first] = details;
51
-
52
- // Roll up field types as long as they are not
53
- // referencing nested fields.
54
- return this.isFieldType() && !first.isFieldType?.();
55
- }
56
- isFieldType() {
57
- return this.type === 'field' || this.type === 'element';
27
+ return {
28
+ type: this.type,
29
+ ...(message && {
30
+ message
31
+ }),
32
+ ...(details.length && {
33
+ details: details.map(error => {
34
+ return error.toJSON();
35
+ })
36
+ })
37
+ };
58
38
  }
59
39
  getFullMessage(options) {
60
40
  return (0, _messages.getFullMessage)(this, {
@@ -64,12 +44,46 @@ class ValidationError extends Error {
64
44
  }
65
45
  }
66
46
  exports.ValidationError = ValidationError;
47
+ class AssertionError extends ValidationError {
48
+ constructor(message, type = 'assertion') {
49
+ super(message);
50
+ this.type = type;
51
+ }
52
+ }
53
+ exports.AssertionError = AssertionError;
54
+ class TypeError extends ValidationError {
55
+ constructor(message, kind) {
56
+ super(message);
57
+ this.type = 'type';
58
+ this.kind = kind;
59
+ }
60
+ toJSON() {
61
+ return {
62
+ ...super.toJSON(),
63
+ kind: this.kind
64
+ };
65
+ }
66
+ }
67
+ exports.TypeError = TypeError;
68
+ class FormatError extends ValidationError {
69
+ constructor(message, format) {
70
+ super(message);
71
+ this.type = 'format';
72
+ this.format = format;
73
+ }
74
+ toJSON() {
75
+ return {
76
+ ...super.toJSON(),
77
+ format: this.format
78
+ };
79
+ }
80
+ }
81
+ exports.FormatError = FormatError;
67
82
  class FieldError extends ValidationError {
68
- constructor(message, field, original, details) {
69
- super(message, details, 'field');
83
+ constructor(message, field, details) {
84
+ super(message, details);
85
+ this.type = 'field';
70
86
  this.field = field;
71
- this.original = original;
72
- this.details = details;
73
87
  }
74
88
  toJSON() {
75
89
  return {
@@ -80,11 +94,10 @@ class FieldError extends ValidationError {
80
94
  }
81
95
  exports.FieldError = FieldError;
82
96
  class ElementError extends ValidationError {
83
- constructor(message, index, original, details) {
84
- super(message, details, 'element');
97
+ constructor(message, index, details) {
98
+ super(message, details);
99
+ this.type = 'element';
85
100
  this.index = index;
86
- this.original = original;
87
- this.details = details;
88
101
  }
89
102
  toJSON() {
90
103
  return {
@@ -94,27 +107,23 @@ class ElementError extends ValidationError {
94
107
  }
95
108
  }
96
109
  exports.ElementError = ElementError;
97
- class AssertionError extends Error {
98
- constructor(message, type, original) {
99
- super(message);
100
- this.type = type;
101
- this.original = original;
102
- }
103
- toJSON() {
104
- return {
105
- type: this.type,
106
- message: this.message
107
- };
108
- }
109
- }
110
- exports.AssertionError = AssertionError;
111
- class ArrayError extends Error {
110
+ class ArrayError extends ValidationError {
112
111
  constructor(message, details) {
113
112
  super(message);
113
+ this.type = 'array';
114
114
  this.details = details;
115
115
  }
116
116
  }
117
117
  exports.ArrayError = ArrayError;
118
118
  function isSchemaError(arg) {
119
- return arg instanceof ValidationError || arg instanceof AssertionError || arg instanceof ArrayError;
119
+ return arg instanceof ValidationError;
120
+ }
121
+ function getLocalizedMessage(arg) {
122
+ if (arg instanceof LocalizedError) {
123
+ return arg.message;
124
+ } else if (arg instanceof Error) {
125
+ return (0, _localization.localize)(arg.message);
126
+ } else {
127
+ return (0, _localization.localize)(arg);
128
+ }
120
129
  }
@@ -32,6 +32,9 @@ function getLocalized(message) {
32
32
  }
33
33
  }
34
34
  function localize(message, values = {}) {
35
+ if (!message) {
36
+ return;
37
+ }
35
38
  let str = message;
36
39
  if (str) {
37
40
  let localized = getLocalized(message);
@@ -4,37 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getFullMessage = getFullMessage;
7
- var _errors = require("./errors");
8
7
  var _localization = require("./localization");
9
8
  function getFullMessage(error, options) {
10
9
  const {
11
10
  delimiter = '\n'
12
11
  } = options;
13
- if (error.details) {
12
+ if (error.message) {
13
+ return getLabeledMessage(error, options);
14
+ } else if (error.details?.length) {
14
15
  return error.details.map(error => {
15
- if ((0, _errors.isSchemaError)(error)) {
16
- return getFullMessage(error, {
17
- ...options,
18
- path: getInnerPath(error, options)
19
- });
20
- } else {
21
- return error.message;
22
- }
16
+ return getFullMessage(error, {
17
+ ...options,
18
+ path: getInnerPath(error, options)
19
+ });
23
20
  }).join(delimiter);
24
- } else {
25
- return getLabeledMessage(error, options);
26
21
  }
27
22
  }
28
23
  function getInnerPath(error, options) {
29
- const {
30
- type
31
- } = error;
32
24
  const {
33
25
  path = []
34
26
  } = options;
35
- if (type === 'field' && error.field) {
27
+ if (error.field) {
36
28
  return [...path, error.field];
37
- } else if (type === 'element') {
29
+ } else if (error.index != null) {
38
30
  return [...path, error.index];
39
31
  } else {
40
32
  return path;
@@ -48,15 +40,28 @@ function getLabeledMessage(error, options) {
48
40
  path = []
49
41
  } = options;
50
42
  const base = getBase(error.message);
51
- if (type !== 'custom' && path.length) {
52
- const msg = `{field} ${downcase(base)}`;
53
- return (0, _localization.localize)(msg, {
43
+ let template;
44
+ if (base.includes('{field}')) {
45
+ template = base;
46
+ } else if (canAutoAddField(type, path)) {
47
+ template = `{field} ${downcase(base)}`;
48
+ }
49
+ if (template) {
50
+ return (0, _localization.localize)(template, {
54
51
  field: getFieldLabel(options)
55
52
  });
56
53
  } else {
57
54
  return (0, _localization.localize)(base);
58
55
  }
59
56
  }
57
+ const DISALLOWED_TYPES = ['field', 'element', 'array', 'custom'];
58
+
59
+ // Error types that have custom messages should not add the field
60
+ // names automatically. Instead the custom messages can include
61
+ // the {field} token to allow it to be interpolated if required.
62
+ function canAutoAddField(type, path) {
63
+ return path.length && !DISALLOWED_TYPES.includes(type);
64
+ }
60
65
  function getFieldLabel(options) {
61
66
  const {
62
67
  path = [],
@@ -21,8 +21,7 @@ class ObjectSchema extends _TypeSchema.default {
21
21
  constructor(fields, meta) {
22
22
  super(Object, {
23
23
  ...meta,
24
- fields,
25
- message: 'Object failed validation.'
24
+ fields
26
25
  });
27
26
  this.setup();
28
27
  }
@@ -93,7 +92,10 @@ class ObjectSchema extends _TypeSchema.default {
93
92
  };
94
93
  }
95
94
  } catch (error) {
96
- throw new _errors.FieldError('Field failed validation.', key, error.original, error.details);
95
+ const {
96
+ message
97
+ } = schema.meta;
98
+ throw new _errors.FieldError(message, key, error.details);
97
99
  }
98
100
  }
99
101
  });
package/dist/cjs/tuple.js CHANGED
@@ -10,7 +10,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
10
10
  class TupleSchema extends _Schema.default {
11
11
  constructor(schemas) {
12
12
  super({
13
- message: 'Tuple failed validation.',
14
13
  schemas
15
14
  });
16
15
  this.setup();
@@ -21,7 +20,8 @@ class TupleSchema extends _Schema.default {
21
20
  */
22
21
  setup() {
23
22
  const {
24
- schemas
23
+ schemas,
24
+ message
25
25
  } = this.meta;
26
26
  this.assert('type', (val, options) => {
27
27
  if (typeof val === 'string' && options.cast) {
@@ -63,11 +63,10 @@ class TupleSchema extends _Schema.default {
63
63
  }
64
64
  result.push(await schema.validate(el, options));
65
65
  } catch (error) {
66
- if (error.details?.length === 1) {
67
- errors.push(new _errors.ElementError(error.details[0].message, i));
68
- } else {
69
- errors.push(new _errors.ElementError('Element failed validation.', i, error.details));
70
- }
66
+ const {
67
+ message
68
+ } = schema.meta;
69
+ errors.push(new _errors.ElementError(message, i, error.details));
71
70
  }
72
71
  }
73
72
  if (errors.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bedrockio/yada",
3
- "version": "1.0.40",
3
+ "version": "1.1.0",
4
4
  "description": "Validation library inspired by Joi.",
5
5
  "scripts": {
6
6
  "test": "jest",
package/src/Schema.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
- isSchemaError,
3
- ValidationError,
2
+ TypeError,
3
+ FormatError,
4
4
  AssertionError,
5
5
  LocalizedError,
6
- ArrayError,
6
+ ValidationError,
7
7
  } from './errors';
8
8
  import { omit } from './utils';
9
9
 
@@ -13,7 +13,6 @@ const REQUIRED_TYPES = ['default', 'required'];
13
13
  /**
14
14
  * @typedef {[fn: Function] | [type: string, fn: Function]} CustomSignature
15
15
  */
16
-
17
16
  export default class Schema {
18
17
  constructor(meta = {}) {
19
18
  this.assertions = [];
@@ -150,8 +149,14 @@ export default class Schema {
150
149
  value = result;
151
150
  }
152
151
  } catch (error) {
153
- if (error instanceof ArrayError) {
154
- details = [...details, ...error.details];
152
+ const { type } = assertion;
153
+
154
+ if (type === 'type') {
155
+ details.push(new TypeError(error, this.meta.type));
156
+ } else if (type === 'format') {
157
+ details.push(new FormatError(error, this.meta.format));
158
+ } else if (!error.type) {
159
+ details.push(new AssertionError(error, type));
155
160
  } else {
156
161
  details.push(error);
157
162
  }
@@ -162,8 +167,7 @@ export default class Schema {
162
167
  }
163
168
 
164
169
  if (details.length) {
165
- const { message = 'Input failed validation.' } = this.meta;
166
- throw new ValidationError(message, details);
170
+ throw new ValidationError(this.meta.message, details);
167
171
  }
168
172
 
169
173
  return value;
@@ -249,10 +253,9 @@ export default class Schema {
249
253
  }
250
254
  return el;
251
255
  });
252
- const msg = `${allow ? 'Must' : 'Must not'} be one of [{types}].`;
256
+ const message = `${allow ? 'Must' : 'Must not'} be one of [{types}].`;
253
257
  return this.clone({ enum: set }).assert('enum', async (val, options) => {
254
258
  if (val !== undefined) {
255
- let error;
256
259
  for (let el of set) {
257
260
  if (isSchema(el)) {
258
261
  try {
@@ -263,31 +266,23 @@ export default class Schema {
263
266
  return await el.validate(val, options);
264
267
  } catch (err) {
265
268
  const [first] = err.details;
266
- const isTypeError = first?.type === 'type';
267
- if (!isTypeError) {
268
- // Capture the first error object only if it is not
269
- // a simple type error to surface error messages on
270
- // more complex schemas. Otherwise allow this to fall
271
- // through to show more meaningful messages for simple
272
- // enums.
273
- error ||= err;
269
+ if (first instanceof TypeError) {
270
+ // If the error is a simple type error then continue
271
+ // to show more meaningful messages for simple enums.
272
+ continue;
273
+ } else {
274
+ // Otherwise throw the error to surface messages on
275
+ // more complex schemas.
276
+ throw err;
274
277
  }
275
- continue;
276
278
  }
277
279
  } else if ((el === val) === allow) {
278
280
  return;
279
281
  }
280
282
  }
281
- if (error) {
282
- throw new ValidationError(
283
- options.message || error.message,
284
- error.details
285
- );
286
- } else {
287
- throw new LocalizedError(options.message || msg, {
288
- types: types.join(', '),
289
- });
290
- }
283
+ throw new LocalizedError(message, {
284
+ types: types.join(', '),
285
+ });
291
286
  }
292
287
  });
293
288
  }
@@ -330,15 +325,8 @@ export default class Schema {
330
325
  }
331
326
 
332
327
  async runAssertion(assertion, value, options = {}) {
333
- const { type, fn } = assertion;
334
- try {
335
- return await fn(value, options);
336
- } catch (error) {
337
- if (isSchemaError(error)) {
338
- throw error;
339
- }
340
- throw new AssertionError(error.message, error.type || type, error);
341
- }
328
+ const { fn } = assertion;
329
+ return await fn(value, options);
342
330
  }
343
331
 
344
332
  enumToOpenApi() {
package/src/TypeSchema.js CHANGED
@@ -3,7 +3,7 @@ import Schema from './Schema';
3
3
  export default class TypeSchema extends Schema {
4
4
  constructor(Class, meta) {
5
5
  const type = Class.name.toLowerCase();
6
- super({ type, ...meta });
6
+ super({ ...meta, type });
7
7
  }
8
8
 
9
9
  format(name, fn) {
package/src/array.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import Schema from './Schema';
2
+ import TypeSchema from './TypeSchema';
2
3
  import { ArrayError, ElementError, LocalizedError } from './errors';
3
4
  import { omit } from './utils';
4
5
 
5
- class ArraySchema extends Schema {
6
+ class ArraySchema extends TypeSchema {
6
7
  constructor(schemas) {
7
- super({ message: 'Array failed validation.', schemas });
8
+ super(Array, { schemas });
8
9
  this.setup();
9
10
  }
10
11
 
@@ -12,7 +13,7 @@ class ArraySchema extends Schema {
12
13
  * @private
13
14
  */
14
15
  setup() {
15
- const { schemas, message } = this.meta;
16
+ const { schemas } = this.meta;
16
17
  const schema =
17
18
  schemas.length > 1 ? new Schema().allow(schemas) : schemas[0];
18
19
 
@@ -27,6 +28,7 @@ class ArraySchema extends Schema {
27
28
  });
28
29
 
29
30
  if (schema) {
31
+ const { message } = schema.meta;
30
32
  this.assert('elements', async (arr, options) => {
31
33
  const errors = [];
32
34
  const result = [];
@@ -38,14 +40,7 @@ class ArraySchema extends Schema {
38
40
  options = omit(options, 'message');
39
41
  result.push(await schema.validate(el, options));
40
42
  } catch (error) {
41
- errors.push(
42
- new ElementError(
43
- 'Element failed validation.',
44
- i,
45
- error.original,
46
- error.details
47
- )
48
- );
43
+ errors.push(new ElementError(message, i, error.details));
49
44
  }
50
45
  }
51
46
  if (errors.length) {
package/src/errors.js CHANGED
@@ -2,55 +2,31 @@ import { getFullMessage } from './messages';
2
2
  import { localize } from './localization';
3
3
 
4
4
  export class LocalizedError extends Error {
5
- constructor(message, values) {
5
+ constructor(message, values = {}) {
6
6
  super(localize(message, values));
7
- this.values = values;
8
- }
9
-
10
- get type() {
11
- return this.values?.type;
12
7
  }
13
8
  }
14
9
 
15
10
  export class ValidationError extends Error {
16
- constructor(message, details = [], type = 'validation') {
17
- super(localize(message));
11
+ constructor(arg, details = []) {
12
+ super(getLocalizedMessage(arg));
13
+ this.type = 'validation';
18
14
  this.details = details;
19
- this.type = type;
20
15
  }
21
16
 
22
17
  toJSON() {
23
- if (this.canRollup()) {
24
- const [first] = this.details;
25
- return {
26
- ...first.toJSON(),
27
- type: this.type,
28
- };
29
- } else {
30
- return {
31
- type: this.type,
32
- message: this.message,
33
- details: this.details.map((error) => {
18
+ const { message, details } = this;
19
+ return {
20
+ type: this.type,
21
+ ...(message && {
22
+ message,
23
+ }),
24
+ ...(details.length && {
25
+ details: details.map((error) => {
34
26
  return error.toJSON();
35
27
  }),
36
- };
37
- }
38
- }
39
-
40
- canRollup() {
41
- const { details } = this;
42
- if (details.length !== 1) {
43
- return false;
44
- }
45
- const [first] = details;
46
-
47
- // Roll up field types as long as they are not
48
- // referencing nested fields.
49
- return this.isFieldType() && !first.isFieldType?.();
50
- }
51
-
52
- isFieldType() {
53
- return this.type === 'field' || this.type === 'element';
28
+ }),
29
+ };
54
30
  }
55
31
 
56
32
  getFullMessage(options) {
@@ -61,64 +37,91 @@ export class ValidationError extends Error {
61
37
  }
62
38
  }
63
39
 
64
- export class FieldError extends ValidationError {
65
- constructor(message, field, original, details) {
66
- super(message, details, 'field');
67
- this.field = field;
68
- this.original = original;
69
- this.details = details;
40
+ export class AssertionError extends ValidationError {
41
+ constructor(message, type = 'assertion') {
42
+ super(message);
43
+ this.type = type;
44
+ }
45
+ }
46
+
47
+ export class TypeError extends ValidationError {
48
+ constructor(message, kind) {
49
+ super(message);
50
+ this.type = 'type';
51
+ this.kind = kind;
70
52
  }
71
53
 
72
54
  toJSON() {
73
55
  return {
74
56
  ...super.toJSON(),
75
- field: this.field,
57
+ kind: this.kind,
76
58
  };
77
59
  }
78
60
  }
79
61
 
80
- export class ElementError extends ValidationError {
81
- constructor(message, index, original, details) {
82
- super(message, details, 'element');
83
- this.index = index;
84
- this.original = original;
85
- this.details = details;
62
+ export class FormatError extends ValidationError {
63
+ constructor(message, format) {
64
+ super(message);
65
+ this.type = 'format';
66
+ this.format = format;
86
67
  }
87
68
 
88
69
  toJSON() {
89
70
  return {
90
71
  ...super.toJSON(),
91
- index: this.index,
72
+ format: this.format,
92
73
  };
93
74
  }
94
75
  }
95
76
 
96
- export class AssertionError extends Error {
97
- constructor(message, type, original) {
98
- super(message);
99
- this.type = type;
100
- this.original = original;
77
+ export class FieldError extends ValidationError {
78
+ constructor(message, field, details) {
79
+ super(message, details);
80
+ this.type = 'field';
81
+ this.field = field;
101
82
  }
102
83
 
103
84
  toJSON() {
104
85
  return {
105
- type: this.type,
106
- message: this.message,
86
+ ...super.toJSON(),
87
+ field: this.field,
88
+ };
89
+ }
90
+ }
91
+
92
+ export class ElementError extends ValidationError {
93
+ constructor(message, index, details) {
94
+ super(message, details);
95
+ this.type = 'element';
96
+ this.index = index;
97
+ }
98
+
99
+ toJSON() {
100
+ return {
101
+ ...super.toJSON(),
102
+ index: this.index,
107
103
  };
108
104
  }
109
105
  }
110
106
 
111
- export class ArrayError extends Error {
107
+ export class ArrayError extends ValidationError {
112
108
  constructor(message, details) {
113
109
  super(message);
110
+ this.type = 'array';
114
111
  this.details = details;
115
112
  }
116
113
  }
117
114
 
118
115
  export function isSchemaError(arg) {
119
- return (
120
- arg instanceof ValidationError ||
121
- arg instanceof AssertionError ||
122
- arg instanceof ArrayError
123
- );
116
+ return arg instanceof ValidationError;
117
+ }
118
+
119
+ function getLocalizedMessage(arg) {
120
+ if (arg instanceof LocalizedError) {
121
+ return arg.message;
122
+ } else if (arg instanceof Error) {
123
+ return localize(arg.message);
124
+ } else {
125
+ return localize(arg);
126
+ }
124
127
  }
@@ -26,6 +26,9 @@ export function getLocalized(message) {
26
26
  }
27
27
 
28
28
  export function localize(message, values = {}) {
29
+ if (!message) {
30
+ return;
31
+ }
29
32
  let str = message;
30
33
  if (str) {
31
34
  let localized = getLocalized(message);
package/src/messages.js CHANGED
@@ -1,32 +1,26 @@
1
- import { isSchemaError } from './errors';
2
1
  import { localize } from './localization';
3
2
 
4
3
  export function getFullMessage(error, options) {
5
4
  const { delimiter = '\n' } = options;
6
- if (error.details) {
5
+ if (error.message) {
6
+ return getLabeledMessage(error, options);
7
+ } else if (error.details?.length) {
7
8
  return error.details
8
9
  .map((error) => {
9
- if (isSchemaError(error)) {
10
- return getFullMessage(error, {
11
- ...options,
12
- path: getInnerPath(error, options),
13
- });
14
- } else {
15
- return error.message;
16
- }
10
+ return getFullMessage(error, {
11
+ ...options,
12
+ path: getInnerPath(error, options),
13
+ });
17
14
  })
18
15
  .join(delimiter);
19
- } else {
20
- return getLabeledMessage(error, options);
21
16
  }
22
17
  }
23
18
 
24
19
  function getInnerPath(error, options) {
25
- const { type } = error;
26
20
  const { path = [] } = options;
27
- if (type === 'field' && error.field) {
21
+ if (error.field) {
28
22
  return [...path, error.field];
29
- } else if (type === 'element') {
23
+ } else if (error.index != null) {
30
24
  return [...path, error.index];
31
25
  } else {
32
26
  return path;
@@ -37,9 +31,16 @@ function getLabeledMessage(error, options) {
37
31
  const { type } = error;
38
32
  const { path = [] } = options;
39
33
  const base = getBase(error.message);
40
- if (type !== 'custom' && path.length) {
41
- const msg = `{field} ${downcase(base)}`;
42
- return localize(msg, {
34
+
35
+ let template;
36
+ if (base.includes('{field}')) {
37
+ template = base;
38
+ } else if (canAutoAddField(type, path)) {
39
+ template = `{field} ${downcase(base)}`;
40
+ }
41
+
42
+ if (template) {
43
+ return localize(template, {
43
44
  field: getFieldLabel(options),
44
45
  });
45
46
  } else {
@@ -47,6 +48,15 @@ function getLabeledMessage(error, options) {
47
48
  }
48
49
  }
49
50
 
51
+ const DISALLOWED_TYPES = ['field', 'element', 'array', 'custom'];
52
+
53
+ // Error types that have custom messages should not add the field
54
+ // names automatically. Instead the custom messages can include
55
+ // the {field} token to allow it to be interpolated if required.
56
+ function canAutoAddField(type, path) {
57
+ return path.length && !DISALLOWED_TYPES.includes(type);
58
+ }
59
+
50
60
  function getFieldLabel(options) {
51
61
  const { path = [], natural } = options;
52
62
  if (natural) {
package/src/object.js CHANGED
@@ -11,11 +11,7 @@ const BASE_ASSERTIONS = ['type', 'transform', 'field'];
11
11
 
12
12
  class ObjectSchema extends TypeSchema {
13
13
  constructor(fields, meta) {
14
- super(Object, {
15
- ...meta,
16
- fields,
17
- message: 'Object failed validation.',
18
- });
14
+ super(Object, { ...meta, fields });
19
15
  this.setup();
20
16
  }
21
17
 
@@ -79,12 +75,8 @@ class ObjectSchema extends TypeSchema {
79
75
  };
80
76
  }
81
77
  } catch (error) {
82
- throw new FieldError(
83
- 'Field failed validation.',
84
- key,
85
- error.original,
86
- error.details
87
- );
78
+ const { message } = schema.meta;
79
+ throw new FieldError(message, key, error.details);
88
80
  }
89
81
  }
90
82
  });
package/src/tuple.js CHANGED
@@ -3,7 +3,7 @@ import { ArrayError, ElementError, LocalizedError } from './errors';
3
3
 
4
4
  class TupleSchema extends Schema {
5
5
  constructor(schemas) {
6
- super({ message: 'Tuple failed validation.', schemas });
6
+ super({ schemas });
7
7
  this.setup();
8
8
  }
9
9
 
@@ -11,7 +11,7 @@ class TupleSchema extends Schema {
11
11
  * @private
12
12
  */
13
13
  setup() {
14
- const { schemas } = this.meta;
14
+ const { schemas, message } = this.meta;
15
15
 
16
16
  this.assert('type', (val, options) => {
17
17
  if (typeof val === 'string' && options.cast) {
@@ -52,13 +52,8 @@ class TupleSchema extends Schema {
52
52
  }
53
53
  result.push(await schema.validate(el, options));
54
54
  } catch (error) {
55
- if (error.details?.length === 1) {
56
- errors.push(new ElementError(error.details[0].message, i));
57
- } else {
58
- errors.push(
59
- new ElementError('Element failed validation.', i, error.details)
60
- );
61
- }
55
+ const { message } = schema.meta;
56
+ errors.push(new ElementError(message, i, error.details));
62
57
  }
63
58
  }
64
59
  if (errors.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"AA8XA,4CAEC;AApXD;;GAEG;AAEH;IACE,uBAGC;IAFC,kBAAoB;IACpB,SAAgB;IAKlB;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,mBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,gBAHW,eAAe,GACb,IAAI,CAmBhB;IAED;;;;OAIG;IACH,mBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,gBAFa,IAAI,CAShB;IAED;;OAEG;IACH,+BAFa,IAAI,CAMhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED,iDAqCC;IAED;;OAEG;IACH,kBAFa,IAAI,CAOhB;IAED;;;OAGG;IACH,qBAFa,IAAI,CAMhB;IAED,2BAWC;IAED;;MAOC;IAED;;;;MASC;IAED,kBAEC;IAED,4BAMC;IAID;;OAEG;IACH,kCAFa,IAAI,CAqDhB;IAED;;OAEG;IACH,4BAFa,IAAI,CAUhB;IAED,oCAKC;IAED;;OAEG;IACH,oBAFa,IAAI,CAShB;IAED,gCAGC;IAED,qEAUC;IAED;;;;;;;;MAoCC;CACF;8BA/WY,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAAU,CAAC"}
1
+ {"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.js"],"names":[],"mappings":"AAkXA,4CAEC;AAxWD;;GAEG;AACH;IACE,uBAGC;IAFC,kBAAoB;IACpB,SAAgB;IAKlB;;OAEG;IACH,YAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,mBAFa,IAAI,CAShB;IAED;;;;OAIG;IACH,gBAHW,eAAe,GACb,IAAI,CAmBhB;IAED;;;;OAIG;IACH,mBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,sBAFa,IAAI,CAIhB;IAED;;;OAGG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED;;OAEG;IACH,gBAFa,IAAI,CAShB;IAED;;OAEG;IACH,+BAFa,IAAI,CAMhB;IAED;;OAEG;IACH,uBAFa,IAAI,CAIhB;IAED,iDA0CC;IAED;;OAEG;IACH,kBAFa,IAAI,CAOhB;IAED;;;OAGG;IACH,qBAFa,IAAI,CAMhB;IAED,2BAWC;IAED;;MAOC;IAED;;;;MASC;IAED,kBAEC;IAED,4BAMC;IAID;;OAEG;IACH,kCAFa,IAAI,CA4ChB;IAED;;OAEG;IACH,4BAFa,IAAI,CAUhB;IAED,oCAKC;IAED;;OAEG;IACH,oBAFa,IAAI,CAShB;IAED,gCAGC;IAED,qEAGC;IAED;;;;;;;;MAoCC;CACF;8BAnWY,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,UAAU,CAAC"}
package/types/array.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  */
9
9
  export default function _default(...schemas?: Schema[]): ArraySchema;
10
10
  import Schema from "./Schema";
11
- declare class ArraySchema extends Schema {
11
+ declare class ArraySchema extends TypeSchema {
12
12
  constructor(schemas: any);
13
13
  /**
14
14
  * @private
@@ -18,6 +18,8 @@ declare class ArraySchema extends Schema {
18
18
  min(length: any): ArraySchema;
19
19
  max(length: any): ArraySchema;
20
20
  latlng(): ArraySchema;
21
+ toString(): string;
21
22
  }
23
+ import TypeSchema from "./TypeSchema";
22
24
  export {};
23
25
  //# sourceMappingURL=array.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.js"],"names":[],"mappings":"AA4IA;;;;;;;GAOG;AACH,8CALc,MAAM,iBAUnB;;AArJD;IACE,0BAGC;IAED;;OAEG;IACH,cA4CC;IAED,iCAUC;IAED,8BAUC;IAED,8BAaC;IAED,sBAaC;CA2BF"}
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../src/array.js"],"names":[],"mappings":"AAuIA;;;;;;;GAOG;AACH,8CALc,MAAM,iBAUnB;;AA/ID;IACE,0BAGC;IAED;;OAEG;IACH,cAsCC;IAED,iCAUC;IAED,8BAUC;IAED,8BAaC;IAED,sBAaC;IAED,mBAEC;CAuBF"}
package/types/errors.d.ts CHANGED
@@ -1,40 +1,62 @@
1
1
  export function isSchemaError(arg: any): boolean;
2
2
  export class LocalizedError extends Error {
3
- constructor(message: any, values: any);
4
- values: any;
5
- get type(): any;
3
+ constructor(message: any, values?: {});
6
4
  }
7
5
  export class ValidationError extends Error {
8
- constructor(message: any, details?: any[], type?: string);
9
- details: any[];
6
+ constructor(arg: any, details?: any[]);
10
7
  type: string;
11
- toJSON(): any;
12
- canRollup(): boolean;
13
- isFieldType(): boolean;
8
+ details: any[];
9
+ toJSON(): {
10
+ details: any[];
11
+ message: string;
12
+ type: string;
13
+ };
14
14
  getFullMessage(options: any): any;
15
15
  }
16
+ export class AssertionError extends ValidationError {
17
+ constructor(message: any, type?: string);
18
+ }
19
+ export class TypeError extends ValidationError {
20
+ constructor(message: any, kind: any);
21
+ kind: any;
22
+ toJSON(): {
23
+ kind: any;
24
+ details: any[];
25
+ message: string;
26
+ type: string;
27
+ };
28
+ }
29
+ export class FormatError extends ValidationError {
30
+ constructor(message: any, format: any);
31
+ format: any;
32
+ toJSON(): {
33
+ format: any;
34
+ details: any[];
35
+ message: string;
36
+ type: string;
37
+ };
38
+ }
16
39
  export class FieldError extends ValidationError {
17
- constructor(message: any, field: any, original: any, details: any);
40
+ constructor(message: any, field: any, details: any);
18
41
  field: any;
19
- original: any;
20
- details: any;
42
+ toJSON(): {
43
+ field: any;
44
+ details: any[];
45
+ message: string;
46
+ type: string;
47
+ };
21
48
  }
22
49
  export class ElementError extends ValidationError {
23
- constructor(message: any, index: any, original: any, details: any);
50
+ constructor(message: any, index: any, details: any);
24
51
  index: any;
25
- original: any;
26
- details: any;
27
- }
28
- export class AssertionError extends Error {
29
- constructor(message: any, type: any, original: any);
30
- type: any;
31
- original: any;
32
52
  toJSON(): {
33
- type: any;
53
+ index: any;
54
+ details: any[];
34
55
  message: string;
56
+ type: string;
35
57
  };
36
58
  }
37
- export class ArrayError extends Error {
59
+ export class ArrayError extends ValidationError {
38
60
  constructor(message: any, details: any);
39
61
  details: any;
40
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.js"],"names":[],"mappings":"AAqHA,iDAMC;AAxHD;IACE,uCAGC;IADC,YAAoB;IAGtB,gBAEC;CACF;AAED;IACE,0DAIC;IAFC,eAAsB;IACtB,aAAgB;IAGlB,cAgBC;IAED,qBAUC;IAED,uBAEC;IAED,kCAKC;CACF;AAED;IACE,mEAKC;IAHC,WAAkB;IAClB,cAAwB;IACxB,aAAsB;CASzB;AAED;IACE,mEAKC;IAHC,WAAkB;IAClB,cAAwB;IACxB,aAAsB;CASzB;AAED;IACE,oDAIC;IAFC,UAAgB;IAChB,cAAwB;IAG1B;;;MAKC;CACF;AAED;IACE,wCAGC;IADC,aAAsB;CAEzB"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.js"],"names":[],"mappings":"AAkHA,iDAEC;AAjHD;IACE,uCAEC;CACF;AAED;IACE,uCAIC;IAFC,aAAwB;IACxB,eAAsB;IAGxB;;;;MAaC;IAED,kCAKC;CACF;AAED;IACE,yCAGC;CACF;AAED;IACE,qCAIC;IADC,UAAgB;IAGlB;;;;;MAKC;CACF;AAED;IACE,uCAIC;IADC,YAAoB;IAGtB;;;;;MAKC;CACF;AAED;IACE,oDAIC;IADC,WAAkB;IAGpB;;;;;MAKC;CACF;AAED;IACE,oDAIC;IADC,WAAkB;IAGpB;;;;;MAKC;CACF;AAED;IACE,wCAIC;IADC,aAAsB;CAEzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../src/localization.js"],"names":[],"mappings":"AASA;;;;;GAKG;AACH;;WAL8C,MAAM,KAAK,MAAM,SAS9D;AAED,gDAIC;AAED,yDAgBC;AAED;;;GAGG;AACH;;EAEC"}
1
+ {"version":3,"file":"localization.d.ts","sourceRoot":"","sources":["../src/localization.js"],"names":[],"mappings":"AASA;;;;;GAKG;AACH;;WAL8C,MAAM,KAAK,MAAM,SAS9D;AAED,gDAIC;AAED,yDAmBC;AAED;;;GAGG;AACH;;EAEC"}
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.js"],"names":[],"mappings":"AAGA,8DAkBC"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.js"],"names":[],"mappings":"AAEA,8DAcC"}
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.js"],"names":[],"mappings":"AAyMA;;;;;;GAMG;AACH,uCAJW,SAAS,gBAMnB;;;;AA3MD;;GAEG;AAEH;IAUE;;OAEG;IACH,cAmEC;IAED;;OAEG;IACH,kBAEC;IAED;;OAEG;IAEH,YAHW,SAAS,GAAC,MAAM,gBAkC1B;IAED;;OAEG;IACH,gBAFc,MAAM,kBAWnB;IAED;;OAEG;IACH,gBAFc,MAAM,kBAWnB;CAcF"}
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.js"],"names":[],"mappings":"AAiMA;;;;;;GAMG;AACH,uCAJW,SAAS,gBAMnB;;;;AAnMD;;GAEG;AAEH;IAME;;OAEG;IACH,cA+DC;IAED;;OAEG;IACH,kBAEC;IAED;;OAEG;IAEH,YAHW,SAAS,GAAC,MAAM,gBAkC1B;IAED;;OAEG;IACH,gBAFc,MAAM,kBAWnB;IAED;;OAEG;IACH,gBAFc,MAAM,kBAWnB;CAcF"}
@@ -1 +1 @@
1
- {"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../src/tuple.js"],"names":[],"mappings":"AA2FA;;;;;;GAMG;AACH,8CAJc,MAAM,iBASnB;;AApGD;IACE,0BAGC;IAED;;OAEG;IACH,cAyDC;IAED,qBAEC;CAgBF"}
1
+ {"version":3,"file":"tuple.d.ts","sourceRoot":"","sources":["../src/tuple.js"],"names":[],"mappings":"AAsFA;;;;;;GAMG;AACH,8CAJc,MAAM,iBASnB;;AA/FD;IACE,0BAGC;IAED;;OAEG;IACH,cAoDC;IAED,qBAEC;CAgBF"}