wizzard-stepper-react 1.0.0 → 1.0.1

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/dist/index.cjs CHANGED
@@ -1,14 +1,9 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __commonJS = (cb, mod) => function __require() {
10
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
- };
12
7
  var __export = (target, all) => {
13
8
  for (var name in all)
14
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -21,232 +16,9 @@ var __copyProps = (to, from, except, desc) => {
21
16
  }
22
17
  return to;
23
18
  };
24
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
- // If the importer is in node compatibility mode or this is not an ESM
26
- // file that has been converted to a CommonJS file using a Babel-
27
- // compatible transform (i.e. "__esModule" has not been set), then set
28
- // "default" to the CommonJS "module.exports" for node compatibility.
29
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
- mod
31
- ));
32
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
20
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
34
21
 
35
- // node_modules/property-expr/index.js
36
- var require_property_expr = __commonJS({
37
- "node_modules/property-expr/index.js"(exports2, module2) {
38
- "use strict";
39
- function Cache(maxSize) {
40
- this._maxSize = maxSize;
41
- this.clear();
42
- }
43
- Cache.prototype.clear = function() {
44
- this._size = 0;
45
- this._values = /* @__PURE__ */ Object.create(null);
46
- };
47
- Cache.prototype.get = function(key) {
48
- return this._values[key];
49
- };
50
- Cache.prototype.set = function(key, value) {
51
- this._size >= this._maxSize && this.clear();
52
- if (!(key in this._values)) this._size++;
53
- return this._values[key] = value;
54
- };
55
- var SPLIT_REGEX = /[^.^\]^[]+|(?=\[\]|\.\.)/g;
56
- var DIGIT_REGEX = /^\d+$/;
57
- var LEAD_DIGIT_REGEX = /^\d/;
58
- var SPEC_CHAR_REGEX = /[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g;
59
- var CLEAN_QUOTES_REGEX = /^\s*(['"]?)(.*?)(\1)\s*$/;
60
- var MAX_CACHE_SIZE = 512;
61
- var pathCache = new Cache(MAX_CACHE_SIZE);
62
- var setCache = new Cache(MAX_CACHE_SIZE);
63
- var getCache = new Cache(MAX_CACHE_SIZE);
64
- module2.exports = {
65
- Cache,
66
- split: split2,
67
- normalizePath: normalizePath2,
68
- setter: function(path) {
69
- var parts = normalizePath2(path);
70
- return setCache.get(path) || setCache.set(path, function setter(obj, value) {
71
- var index = 0;
72
- var len = parts.length;
73
- var data = obj;
74
- while (index < len - 1) {
75
- var part = parts[index];
76
- if (part === "__proto__" || part === "constructor" || part === "prototype") {
77
- return obj;
78
- }
79
- data = data[parts[index++]];
80
- }
81
- data[parts[index]] = value;
82
- });
83
- },
84
- getter: function(path, safe) {
85
- var parts = normalizePath2(path);
86
- return getCache.get(path) || getCache.set(path, function getter2(data) {
87
- var index = 0, len = parts.length;
88
- while (index < len) {
89
- if (data != null || !safe) data = data[parts[index++]];
90
- else return;
91
- }
92
- return data;
93
- });
94
- },
95
- join: function(segments) {
96
- return segments.reduce(function(path, part) {
97
- return path + (isQuoted(part) || DIGIT_REGEX.test(part) ? "[" + part + "]" : (path ? "." : "") + part);
98
- }, "");
99
- },
100
- forEach: function(path, cb, thisArg) {
101
- forEach2(Array.isArray(path) ? path : split2(path), cb, thisArg);
102
- }
103
- };
104
- function normalizePath2(path) {
105
- return pathCache.get(path) || pathCache.set(
106
- path,
107
- split2(path).map(function(part) {
108
- return part.replace(CLEAN_QUOTES_REGEX, "$2");
109
- })
110
- );
111
- }
112
- function split2(path) {
113
- return path.match(SPLIT_REGEX) || [""];
114
- }
115
- function forEach2(parts, iter, thisArg) {
116
- var len = parts.length, part, idx, isArray, isBracket;
117
- for (idx = 0; idx < len; idx++) {
118
- part = parts[idx];
119
- if (part) {
120
- if (shouldBeQuoted(part)) {
121
- part = '"' + part + '"';
122
- }
123
- isBracket = isQuoted(part);
124
- isArray = !isBracket && /^\d+$/.test(part);
125
- iter.call(thisArg, part, isBracket, isArray, idx, parts);
126
- }
127
- }
128
- }
129
- function isQuoted(str) {
130
- return typeof str === "string" && str && ["'", '"'].indexOf(str.charAt(0)) !== -1;
131
- }
132
- function hasLeadingNumber(part) {
133
- return part.match(LEAD_DIGIT_REGEX) && !part.match(DIGIT_REGEX);
134
- }
135
- function hasSpecialChars(part) {
136
- return SPEC_CHAR_REGEX.test(part);
137
- }
138
- function shouldBeQuoted(part) {
139
- return !isQuoted(part) && (hasLeadingNumber(part) || hasSpecialChars(part));
140
- }
141
- }
142
- });
143
-
144
- // node_modules/tiny-case/index.js
145
- var require_tiny_case = __commonJS({
146
- "node_modules/tiny-case/index.js"(exports2, module2) {
147
- "use strict";
148
- var reWords = /[A-Z\xc0-\xd6\xd8-\xde]?[a-z\xdf-\xf6\xf8-\xff]+(?:['’](?:d|ll|m|re|s|t|ve))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde]|$)|(?:[A-Z\xc0-\xd6\xd8-\xde]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:D|LL|M|RE|S|T|VE))?(?=[\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000]|[A-Z\xc0-\xd6\xd8-\xde](?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])|$)|[A-Z\xc0-\xd6\xd8-\xde]?(?:[a-z\xdf-\xf6\xf8-\xff]|[^\ud800-\udfff\xac\xb1\xd7\xf7\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\xbf\u2000-\u206f \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\d+\u2700-\u27bfa-z\xdf-\xf6\xf8-\xffA-Z\xc0-\xd6\xd8-\xde])+(?:['’](?:d|ll|m|re|s|t|ve))?|[A-Z\xc0-\xd6\xd8-\xde]+(?:['’](?:D|LL|M|RE|S|T|VE))?|\d*(?:1ST|2ND|3RD|(?![123])\dTH)(?=\b|[a-z_])|\d*(?:1st|2nd|3rd|(?![123])\dth)(?=\b|[A-Z_])|\d+|(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?(?:\u200d(?:[^\ud800-\udfff]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff])[\ufe0e\ufe0f]?(?:[\u0300-\u036f\ufe20-\ufe2f\u20d0-\u20ff]|\ud83c[\udffb-\udfff])?)*/g;
149
- var words = (str) => str.match(reWords) || [];
150
- var upperFirst = (str) => str[0].toUpperCase() + str.slice(1);
151
- var join2 = (str, d) => words(str).join(d).toLowerCase();
152
- var camelCase2 = (str) => words(str).reduce(
153
- (acc, next) => `${acc}${!acc ? next.toLowerCase() : next[0].toUpperCase() + next.slice(1).toLowerCase()}`,
154
- ""
155
- );
156
- var pascalCase = (str) => upperFirst(camelCase2(str));
157
- var snakeCase2 = (str) => join2(str, "_");
158
- var kebabCase = (str) => join2(str, "-");
159
- var sentenceCase = (str) => upperFirst(join2(str, " "));
160
- var titleCase = (str) => words(str).map(upperFirst).join(" ");
161
- module2.exports = {
162
- words,
163
- upperFirst,
164
- camelCase: camelCase2,
165
- pascalCase,
166
- snakeCase: snakeCase2,
167
- kebabCase,
168
- sentenceCase,
169
- titleCase
170
- };
171
- }
172
- });
173
-
174
- // node_modules/toposort/index.js
175
- var require_toposort = __commonJS({
176
- "node_modules/toposort/index.js"(exports2, module2) {
177
- "use strict";
178
- module2.exports = function(edges) {
179
- return toposort2(uniqueNodes(edges), edges);
180
- };
181
- module2.exports.array = toposort2;
182
- function toposort2(nodes, edges) {
183
- var cursor = nodes.length, sorted = new Array(cursor), visited = {}, i = cursor, outgoingEdges = makeOutgoingEdges(edges), nodesHash = makeNodesHash(nodes);
184
- edges.forEach(function(edge) {
185
- if (!nodesHash.has(edge[0]) || !nodesHash.has(edge[1])) {
186
- throw new Error("Unknown node. There is an unknown node in the supplied edges.");
187
- }
188
- });
189
- while (i--) {
190
- if (!visited[i]) visit(nodes[i], i, /* @__PURE__ */ new Set());
191
- }
192
- return sorted;
193
- function visit(node, i2, predecessors) {
194
- if (predecessors.has(node)) {
195
- var nodeRep;
196
- try {
197
- nodeRep = ", node was:" + JSON.stringify(node);
198
- } catch (e) {
199
- nodeRep = "";
200
- }
201
- throw new Error("Cyclic dependency" + nodeRep);
202
- }
203
- if (!nodesHash.has(node)) {
204
- throw new Error("Found unknown node. Make sure to provided all involved nodes. Unknown node: " + JSON.stringify(node));
205
- }
206
- if (visited[i2]) return;
207
- visited[i2] = true;
208
- var outgoing = outgoingEdges.get(node) || /* @__PURE__ */ new Set();
209
- outgoing = Array.from(outgoing);
210
- if (i2 = outgoing.length) {
211
- predecessors.add(node);
212
- do {
213
- var child = outgoing[--i2];
214
- visit(child, nodesHash.get(child), predecessors);
215
- } while (i2);
216
- predecessors.delete(node);
217
- }
218
- sorted[--cursor] = node;
219
- }
220
- }
221
- function uniqueNodes(arr) {
222
- var res = /* @__PURE__ */ new Set();
223
- for (var i = 0, len = arr.length; i < len; i++) {
224
- var edge = arr[i];
225
- res.add(edge[0]);
226
- res.add(edge[1]);
227
- }
228
- return Array.from(res);
229
- }
230
- function makeOutgoingEdges(arr) {
231
- var edges = /* @__PURE__ */ new Map();
232
- for (var i = 0, len = arr.length; i < len; i++) {
233
- var edge = arr[i];
234
- if (!edges.has(edge[0])) edges.set(edge[0], /* @__PURE__ */ new Set());
235
- if (!edges.has(edge[1])) edges.set(edge[1], /* @__PURE__ */ new Set());
236
- edges.get(edge[0]).add(edge[1]);
237
- }
238
- return edges;
239
- }
240
- function makeNodesHash(arr) {
241
- var res = /* @__PURE__ */ new Map();
242
- for (var i = 0, len = arr.length; i < len; i++) {
243
- res.set(arr[i], i);
244
- }
245
- return res;
246
- }
247
- }
248
- });
249
-
250
22
  // src/index.ts
251
23
  var index_exports = {};
252
24
  __export(index_exports, {
@@ -517,6 +289,7 @@ var LocalStorageAdapter = class {
517
289
  // src/adapters/validation/ZodAdapter.ts
518
290
  var ZodAdapter = class {
519
291
  constructor(schema) {
292
+ __publicField(this, "schema");
520
293
  this.schema = schema;
521
294
  }
522
295
  async validate(data) {
@@ -533,2305 +306,11 @@ var ZodAdapter = class {
533
306
  }
534
307
  };
535
308
 
536
- // node_modules/yup/index.esm.js
537
- var import_property_expr = __toESM(require_property_expr());
538
- var import_tiny_case = __toESM(require_tiny_case());
539
- var import_toposort = __toESM(require_toposort());
540
- var toString = Object.prototype.toString;
541
- var errorToString = Error.prototype.toString;
542
- var regExpToString = RegExp.prototype.toString;
543
- var symbolToString = typeof Symbol !== "undefined" ? Symbol.prototype.toString : () => "";
544
- var SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
545
- function printNumber(val) {
546
- if (val != +val) return "NaN";
547
- const isNegativeZero = val === 0 && 1 / val < 0;
548
- return isNegativeZero ? "-0" : "" + val;
549
- }
550
- function printSimpleValue(val, quoteStrings = false) {
551
- if (val == null || val === true || val === false) return "" + val;
552
- const typeOf = typeof val;
553
- if (typeOf === "number") return printNumber(val);
554
- if (typeOf === "string") return quoteStrings ? `"${val}"` : val;
555
- if (typeOf === "function") return "[Function " + (val.name || "anonymous") + "]";
556
- if (typeOf === "symbol") return symbolToString.call(val).replace(SYMBOL_REGEXP, "Symbol($1)");
557
- const tag = toString.call(val).slice(8, -1);
558
- if (tag === "Date") return isNaN(val.getTime()) ? "" + val : val.toISOString(val);
559
- if (tag === "Error" || val instanceof Error) return "[" + errorToString.call(val) + "]";
560
- if (tag === "RegExp") return regExpToString.call(val);
561
- return null;
562
- }
563
- function printValue(value, quoteStrings) {
564
- let result = printSimpleValue(value, quoteStrings);
565
- if (result !== null) return result;
566
- return JSON.stringify(value, function(key, value2) {
567
- let result2 = printSimpleValue(this[key], quoteStrings);
568
- if (result2 !== null) return result2;
569
- return value2;
570
- }, 2);
571
- }
572
- function toArray(value) {
573
- return value == null ? [] : [].concat(value);
574
- }
575
- var _Symbol$toStringTag;
576
- var _Symbol$hasInstance;
577
- var _Symbol$toStringTag2;
578
- var strReg = /\$\{\s*(\w+)\s*\}/g;
579
- _Symbol$toStringTag = Symbol.toStringTag;
580
- var ValidationErrorNoStack = class {
581
- constructor(errorOrErrors, value, field, type) {
582
- this.name = void 0;
583
- this.message = void 0;
584
- this.value = void 0;
585
- this.path = void 0;
586
- this.type = void 0;
587
- this.params = void 0;
588
- this.errors = void 0;
589
- this.inner = void 0;
590
- this[_Symbol$toStringTag] = "Error";
591
- this.name = "ValidationError";
592
- this.value = value;
593
- this.path = field;
594
- this.type = type;
595
- this.errors = [];
596
- this.inner = [];
597
- toArray(errorOrErrors).forEach((err) => {
598
- if (ValidationError.isError(err)) {
599
- this.errors.push(...err.errors);
600
- const innerErrors = err.inner.length ? err.inner : [err];
601
- this.inner.push(...innerErrors);
602
- } else {
603
- this.errors.push(err);
604
- }
605
- });
606
- this.message = this.errors.length > 1 ? `${this.errors.length} errors occurred` : this.errors[0];
607
- }
608
- };
609
- _Symbol$hasInstance = Symbol.hasInstance;
610
- _Symbol$toStringTag2 = Symbol.toStringTag;
611
- var ValidationError = class _ValidationError extends Error {
612
- static formatError(message, params) {
613
- const path = params.label || params.path || "this";
614
- params = Object.assign({}, params, {
615
- path,
616
- originalPath: params.path
617
- });
618
- if (typeof message === "string") return message.replace(strReg, (_, key) => printValue(params[key]));
619
- if (typeof message === "function") return message(params);
620
- return message;
621
- }
622
- static isError(err) {
623
- return err && err.name === "ValidationError";
624
- }
625
- constructor(errorOrErrors, value, field, type, disableStack) {
626
- const errorNoStack = new ValidationErrorNoStack(errorOrErrors, value, field, type);
627
- if (disableStack) {
628
- return errorNoStack;
629
- }
630
- super();
631
- this.value = void 0;
632
- this.path = void 0;
633
- this.type = void 0;
634
- this.params = void 0;
635
- this.errors = [];
636
- this.inner = [];
637
- this[_Symbol$toStringTag2] = "Error";
638
- this.name = errorNoStack.name;
639
- this.message = errorNoStack.message;
640
- this.type = errorNoStack.type;
641
- this.value = errorNoStack.value;
642
- this.path = errorNoStack.path;
643
- this.errors = errorNoStack.errors;
644
- this.inner = errorNoStack.inner;
645
- if (Error.captureStackTrace) {
646
- Error.captureStackTrace(this, _ValidationError);
647
- }
648
- }
649
- static [_Symbol$hasInstance](inst) {
650
- return ValidationErrorNoStack[Symbol.hasInstance](inst) || super[Symbol.hasInstance](inst);
651
- }
652
- };
653
- var mixed = {
654
- default: "${path} is invalid",
655
- required: "${path} is a required field",
656
- defined: "${path} must be defined",
657
- notNull: "${path} cannot be null",
658
- oneOf: "${path} must be one of the following values: ${values}",
659
- notOneOf: "${path} must not be one of the following values: ${values}",
660
- notType: ({
661
- path,
662
- type,
663
- value,
664
- originalValue
665
- }) => {
666
- const castMsg = originalValue != null && originalValue !== value ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : ".";
667
- return type !== "mixed" ? `${path} must be a \`${type}\` type, but the final value was: \`${printValue(value, true)}\`` + castMsg : `${path} must match the configured type. The validated value was: \`${printValue(value, true)}\`` + castMsg;
668
- }
669
- };
670
- var string = {
671
- length: "${path} must be exactly ${length} characters",
672
- min: "${path} must be at least ${min} characters",
673
- max: "${path} must be at most ${max} characters",
674
- matches: '${path} must match the following: "${regex}"',
675
- email: "${path} must be a valid email",
676
- url: "${path} must be a valid URL",
677
- uuid: "${path} must be a valid UUID",
678
- datetime: "${path} must be a valid ISO date-time",
679
- datetime_precision: "${path} must be a valid ISO date-time with a sub-second precision of exactly ${precision} digits",
680
- datetime_offset: '${path} must be a valid ISO date-time with UTC "Z" timezone',
681
- trim: "${path} must be a trimmed string",
682
- lowercase: "${path} must be a lowercase string",
683
- uppercase: "${path} must be a upper case string"
684
- };
685
- var number = {
686
- min: "${path} must be greater than or equal to ${min}",
687
- max: "${path} must be less than or equal to ${max}",
688
- lessThan: "${path} must be less than ${less}",
689
- moreThan: "${path} must be greater than ${more}",
690
- positive: "${path} must be a positive number",
691
- negative: "${path} must be a negative number",
692
- integer: "${path} must be an integer"
693
- };
694
- var date = {
695
- min: "${path} field must be later than ${min}",
696
- max: "${path} field must be at earlier than ${max}"
697
- };
698
- var boolean = {
699
- isValue: "${path} field must be ${value}"
700
- };
701
- var object = {
702
- noUnknown: "${path} field has unspecified keys: ${unknown}",
703
- exact: "${path} object contains unknown properties: ${properties}"
704
- };
705
- var array = {
706
- min: "${path} field must have at least ${min} items",
707
- max: "${path} field must have less than or equal to ${max} items",
708
- length: "${path} must have ${length} items"
709
- };
710
- var tuple = {
711
- notType: (params) => {
712
- const {
713
- path,
714
- value,
715
- spec
716
- } = params;
717
- const typeLen = spec.types.length;
718
- if (Array.isArray(value)) {
719
- if (value.length < typeLen) return `${path} tuple value has too few items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
720
- if (value.length > typeLen) return `${path} tuple value has too many items, expected a length of ${typeLen} but got ${value.length} for value: \`${printValue(value, true)}\``;
721
- }
722
- return ValidationError.formatError(mixed.notType, params);
723
- }
724
- };
725
- var locale = Object.assign(/* @__PURE__ */ Object.create(null), {
726
- mixed,
727
- string,
728
- number,
729
- date,
730
- object,
731
- array,
732
- boolean,
733
- tuple
734
- });
735
- var isSchema = (obj) => obj && obj.__isYupSchema__;
736
- var Condition = class _Condition {
737
- static fromOptions(refs, config) {
738
- if (!config.then && !config.otherwise) throw new TypeError("either `then:` or `otherwise:` is required for `when()` conditions");
739
- let {
740
- is,
741
- then,
742
- otherwise
743
- } = config;
744
- let check = typeof is === "function" ? is : (...values) => values.every((value) => value === is);
745
- return new _Condition(refs, (values, schema) => {
746
- var _branch;
747
- let branch = check(...values) ? then : otherwise;
748
- return (_branch = branch == null ? void 0 : branch(schema)) != null ? _branch : schema;
749
- });
750
- }
751
- constructor(refs, builder) {
752
- this.fn = void 0;
753
- this.refs = refs;
754
- this.refs = refs;
755
- this.fn = builder;
756
- }
757
- resolve(base, options) {
758
- let values = this.refs.map((ref) => (
759
- // TODO: ? operator here?
760
- ref.getValue(options == null ? void 0 : options.value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context)
761
- ));
762
- let schema = this.fn(values, base, options);
763
- if (schema === void 0 || // @ts-ignore this can be base
764
- schema === base) {
765
- return base;
766
- }
767
- if (!isSchema(schema)) throw new TypeError("conditions must return a schema object");
768
- return schema.resolve(options);
769
- }
770
- };
771
- var prefixes = {
772
- context: "$",
773
- value: "."
774
- };
775
- var Reference = class {
776
- constructor(key, options = {}) {
777
- this.key = void 0;
778
- this.isContext = void 0;
779
- this.isValue = void 0;
780
- this.isSibling = void 0;
781
- this.path = void 0;
782
- this.getter = void 0;
783
- this.map = void 0;
784
- if (typeof key !== "string") throw new TypeError("ref must be a string, got: " + key);
785
- this.key = key.trim();
786
- if (key === "") throw new TypeError("ref must be a non-empty string");
787
- this.isContext = this.key[0] === prefixes.context;
788
- this.isValue = this.key[0] === prefixes.value;
789
- this.isSibling = !this.isContext && !this.isValue;
790
- let prefix = this.isContext ? prefixes.context : this.isValue ? prefixes.value : "";
791
- this.path = this.key.slice(prefix.length);
792
- this.getter = this.path && (0, import_property_expr.getter)(this.path, true);
793
- this.map = options.map;
794
- }
795
- getValue(value, parent, context) {
796
- let result = this.isContext ? context : this.isValue ? value : parent;
797
- if (this.getter) result = this.getter(result || {});
798
- if (this.map) result = this.map(result);
799
- return result;
800
- }
801
- /**
802
- *
803
- * @param {*} value
804
- * @param {Object} options
805
- * @param {Object=} options.context
806
- * @param {Object=} options.parent
807
- */
808
- cast(value, options) {
809
- return this.getValue(value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context);
810
- }
811
- resolve() {
812
- return this;
813
- }
814
- describe() {
815
- return {
816
- type: "ref",
817
- key: this.key
818
- };
819
- }
820
- toString() {
821
- return `Ref(${this.key})`;
822
- }
823
- static isRef(value) {
824
- return value && value.__isYupRef;
825
- }
826
- };
827
- Reference.prototype.__isYupRef = true;
828
- var isAbsent = (value) => value == null;
829
- function createValidation(config) {
830
- function validate({
831
- value,
832
- path = "",
833
- options,
834
- originalValue,
835
- schema
836
- }, panic, next) {
837
- const {
838
- name,
839
- test,
840
- params,
841
- message,
842
- skipAbsent
843
- } = config;
844
- let {
845
- parent,
846
- context,
847
- abortEarly = schema.spec.abortEarly,
848
- disableStackTrace = schema.spec.disableStackTrace
849
- } = options;
850
- const resolveOptions = {
851
- value,
852
- parent,
853
- context
854
- };
855
- function createError(overrides = {}) {
856
- const nextParams = resolveParams(Object.assign({
857
- value,
858
- originalValue,
859
- label: schema.spec.label,
860
- path: overrides.path || path,
861
- spec: schema.spec,
862
- disableStackTrace: overrides.disableStackTrace || disableStackTrace
863
- }, params, overrides.params), resolveOptions);
864
- const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
865
- error.params = nextParams;
866
- return error;
867
- }
868
- const invalid = abortEarly ? panic : next;
869
- let ctx = {
870
- path,
871
- parent,
872
- type: name,
873
- from: options.from,
874
- createError,
875
- resolve(item) {
876
- return resolveMaybeRef(item, resolveOptions);
877
- },
878
- options,
879
- originalValue,
880
- schema
881
- };
882
- const handleResult = (validOrError) => {
883
- if (ValidationError.isError(validOrError)) invalid(validOrError);
884
- else if (!validOrError) invalid(createError());
885
- else next(null);
886
- };
887
- const handleError = (err) => {
888
- if (ValidationError.isError(err)) invalid(err);
889
- else panic(err);
890
- };
891
- const shouldSkip = skipAbsent && isAbsent(value);
892
- if (shouldSkip) {
893
- return handleResult(true);
894
- }
895
- let result;
896
- try {
897
- var _result;
898
- result = test.call(ctx, value, ctx);
899
- if (typeof ((_result = result) == null ? void 0 : _result.then) === "function") {
900
- if (options.sync) {
901
- throw new Error(`Validation test of type: "${ctx.type}" returned a Promise during a synchronous validate. This test will finish after the validate call has returned`);
902
- }
903
- return Promise.resolve(result).then(handleResult, handleError);
904
- }
905
- } catch (err) {
906
- handleError(err);
907
- return;
908
- }
909
- handleResult(result);
910
- }
911
- validate.OPTIONS = config;
912
- return validate;
913
- }
914
- function resolveParams(params, options) {
915
- if (!params) return params;
916
- for (const key of Object.keys(params)) {
917
- params[key] = resolveMaybeRef(params[key], options);
918
- }
919
- return params;
920
- }
921
- function resolveMaybeRef(item, options) {
922
- return Reference.isRef(item) ? item.getValue(options.value, options.parent, options.context) : item;
923
- }
924
- function getIn(schema, path, value, context = value) {
925
- let parent, lastPart, lastPartDebug;
926
- if (!path) return {
927
- parent,
928
- parentPath: path,
929
- schema
930
- };
931
- (0, import_property_expr.forEach)(path, (_part, isBracket, isArray) => {
932
- let part = isBracket ? _part.slice(1, _part.length - 1) : _part;
933
- schema = schema.resolve({
934
- context,
935
- parent,
936
- value
937
- });
938
- let isTuple = schema.type === "tuple";
939
- let idx = isArray ? parseInt(part, 10) : 0;
940
- if (schema.innerType || isTuple) {
941
- if (isTuple && !isArray) throw new Error(`Yup.reach cannot implicitly index into a tuple type. the path part "${lastPartDebug}" must contain an index to the tuple element, e.g. "${lastPartDebug}[0]"`);
942
- if (value && idx >= value.length) {
943
- throw new Error(`Yup.reach cannot resolve an array item at index: ${_part}, in the path: ${path}. because there is no value at that index. `);
944
- }
945
- parent = value;
946
- value = value && value[idx];
947
- schema = isTuple ? schema.spec.types[idx] : schema.innerType;
948
- }
949
- if (!isArray) {
950
- if (!schema.fields || !schema.fields[part]) throw new Error(`The schema does not contain the path: ${path}. (failed at: ${lastPartDebug} which is a type: "${schema.type}")`);
951
- parent = value;
952
- value = value && value[part];
953
- schema = schema.fields[part];
954
- }
955
- lastPart = part;
956
- lastPartDebug = isBracket ? "[" + _part + "]" : "." + _part;
957
- });
958
- return {
959
- schema,
960
- parent,
961
- parentPath: lastPart
962
- };
963
- }
964
- var ReferenceSet = class _ReferenceSet extends Set {
965
- describe() {
966
- const description = [];
967
- for (const item of this.values()) {
968
- description.push(Reference.isRef(item) ? item.describe() : item);
969
- }
970
- return description;
971
- }
972
- resolveAll(resolve) {
973
- let result = [];
974
- for (const item of this.values()) {
975
- result.push(resolve(item));
976
- }
977
- return result;
978
- }
979
- clone() {
980
- return new _ReferenceSet(this.values());
981
- }
982
- merge(newItems, removeItems) {
983
- const next = this.clone();
984
- newItems.forEach((value) => next.add(value));
985
- removeItems.forEach((value) => next.delete(value));
986
- return next;
987
- }
988
- };
989
- function clone(src, seen = /* @__PURE__ */ new Map()) {
990
- if (isSchema(src) || !src || typeof src !== "object") return src;
991
- if (seen.has(src)) return seen.get(src);
992
- let copy;
993
- if (src instanceof Date) {
994
- copy = new Date(src.getTime());
995
- seen.set(src, copy);
996
- } else if (src instanceof RegExp) {
997
- copy = new RegExp(src);
998
- seen.set(src, copy);
999
- } else if (Array.isArray(src)) {
1000
- copy = new Array(src.length);
1001
- seen.set(src, copy);
1002
- for (let i = 0; i < src.length; i++) copy[i] = clone(src[i], seen);
1003
- } else if (src instanceof Map) {
1004
- copy = /* @__PURE__ */ new Map();
1005
- seen.set(src, copy);
1006
- for (const [k, v] of src.entries()) copy.set(k, clone(v, seen));
1007
- } else if (src instanceof Set) {
1008
- copy = /* @__PURE__ */ new Set();
1009
- seen.set(src, copy);
1010
- for (const v of src) copy.add(clone(v, seen));
1011
- } else if (src instanceof Object) {
1012
- copy = {};
1013
- seen.set(src, copy);
1014
- for (const [k, v] of Object.entries(src)) copy[k] = clone(v, seen);
1015
- } else {
1016
- throw Error(`Unable to clone ${src}`);
1017
- }
1018
- return copy;
1019
- }
1020
- function createStandardPath(path) {
1021
- if (!(path != null && path.length)) {
1022
- return void 0;
1023
- }
1024
- const segments = [];
1025
- let currentSegment = "";
1026
- let inBrackets = false;
1027
- let inQuotes = false;
1028
- for (let i = 0; i < path.length; i++) {
1029
- const char = path[i];
1030
- if (char === "[" && !inQuotes) {
1031
- if (currentSegment) {
1032
- segments.push(...currentSegment.split(".").filter(Boolean));
1033
- currentSegment = "";
1034
- }
1035
- inBrackets = true;
1036
- continue;
1037
- }
1038
- if (char === "]" && !inQuotes) {
1039
- if (currentSegment) {
1040
- if (/^\d+$/.test(currentSegment)) {
1041
- segments.push(currentSegment);
1042
- } else {
1043
- segments.push(currentSegment.replace(/^"|"$/g, ""));
1044
- }
1045
- currentSegment = "";
1046
- }
1047
- inBrackets = false;
1048
- continue;
1049
- }
1050
- if (char === '"') {
1051
- inQuotes = !inQuotes;
1052
- continue;
1053
- }
1054
- if (char === "." && !inBrackets && !inQuotes) {
1055
- if (currentSegment) {
1056
- segments.push(currentSegment);
1057
- currentSegment = "";
1058
- }
1059
- continue;
1060
- }
1061
- currentSegment += char;
1062
- }
1063
- if (currentSegment) {
1064
- segments.push(...currentSegment.split(".").filter(Boolean));
1065
- }
1066
- return segments;
1067
- }
1068
- function createStandardIssues(error, parentPath) {
1069
- const path = parentPath ? `${parentPath}.${error.path}` : error.path;
1070
- return error.errors.map((err) => ({
1071
- message: err,
1072
- path: createStandardPath(path)
1073
- }));
1074
- }
1075
- function issuesFromValidationError(error, parentPath) {
1076
- var _error$inner;
1077
- if (!((_error$inner = error.inner) != null && _error$inner.length) && error.errors.length) {
1078
- return createStandardIssues(error, parentPath);
1079
- }
1080
- const path = parentPath ? `${parentPath}.${error.path}` : error.path;
1081
- return error.inner.flatMap((err) => issuesFromValidationError(err, path));
1082
- }
1083
- var Schema = class {
1084
- constructor(options) {
1085
- this.type = void 0;
1086
- this.deps = [];
1087
- this.tests = void 0;
1088
- this.transforms = void 0;
1089
- this.conditions = [];
1090
- this._mutate = void 0;
1091
- this.internalTests = {};
1092
- this._whitelist = new ReferenceSet();
1093
- this._blacklist = new ReferenceSet();
1094
- this.exclusiveTests = /* @__PURE__ */ Object.create(null);
1095
- this._typeCheck = void 0;
1096
- this.spec = void 0;
1097
- this.tests = [];
1098
- this.transforms = [];
1099
- this.withMutation(() => {
1100
- this.typeError(mixed.notType);
1101
- });
1102
- this.type = options.type;
1103
- this._typeCheck = options.check;
1104
- this.spec = Object.assign({
1105
- strip: false,
1106
- strict: false,
1107
- abortEarly: true,
1108
- recursive: true,
1109
- disableStackTrace: false,
1110
- nullable: false,
1111
- optional: true,
1112
- coerce: true
1113
- }, options == null ? void 0 : options.spec);
1114
- this.withMutation((s) => {
1115
- s.nonNullable();
1116
- });
1117
- }
1118
- // TODO: remove
1119
- get _type() {
1120
- return this.type;
1121
- }
1122
- clone(spec) {
1123
- if (this._mutate) {
1124
- if (spec) Object.assign(this.spec, spec);
1125
- return this;
1126
- }
1127
- const next = Object.create(Object.getPrototypeOf(this));
1128
- next.type = this.type;
1129
- next._typeCheck = this._typeCheck;
1130
- next._whitelist = this._whitelist.clone();
1131
- next._blacklist = this._blacklist.clone();
1132
- next.internalTests = Object.assign({}, this.internalTests);
1133
- next.exclusiveTests = Object.assign({}, this.exclusiveTests);
1134
- next.deps = [...this.deps];
1135
- next.conditions = [...this.conditions];
1136
- next.tests = [...this.tests];
1137
- next.transforms = [...this.transforms];
1138
- next.spec = clone(Object.assign({}, this.spec, spec));
1139
- return next;
1140
- }
1141
- label(label) {
1142
- let next = this.clone();
1143
- next.spec.label = label;
1144
- return next;
1145
- }
1146
- meta(...args) {
1147
- if (args.length === 0) return this.spec.meta;
1148
- let next = this.clone();
1149
- next.spec.meta = Object.assign(next.spec.meta || {}, args[0]);
1150
- return next;
1151
- }
1152
- withMutation(fn) {
1153
- let before = this._mutate;
1154
- this._mutate = true;
1155
- let result = fn(this);
1156
- this._mutate = before;
1157
- return result;
1158
- }
1159
- concat(schema) {
1160
- if (!schema || schema === this) return this;
1161
- if (schema.type !== this.type && this.type !== "mixed") throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${schema.type}`);
1162
- let base = this;
1163
- let combined = schema.clone();
1164
- const mergedSpec = Object.assign({}, base.spec, combined.spec);
1165
- combined.spec = mergedSpec;
1166
- combined.internalTests = Object.assign({}, base.internalTests, combined.internalTests);
1167
- combined._whitelist = base._whitelist.merge(schema._whitelist, schema._blacklist);
1168
- combined._blacklist = base._blacklist.merge(schema._blacklist, schema._whitelist);
1169
- combined.tests = base.tests;
1170
- combined.exclusiveTests = base.exclusiveTests;
1171
- combined.withMutation((next) => {
1172
- schema.tests.forEach((fn) => {
1173
- next.test(fn.OPTIONS);
1174
- });
1175
- });
1176
- combined.transforms = [...base.transforms, ...combined.transforms];
1177
- return combined;
1178
- }
1179
- isType(v) {
1180
- if (v == null) {
1181
- if (this.spec.nullable && v === null) return true;
1182
- if (this.spec.optional && v === void 0) return true;
1183
- return false;
1184
- }
1185
- return this._typeCheck(v);
1186
- }
1187
- resolve(options) {
1188
- let schema = this;
1189
- if (schema.conditions.length) {
1190
- let conditions = schema.conditions;
1191
- schema = schema.clone();
1192
- schema.conditions = [];
1193
- schema = conditions.reduce((prevSchema, condition) => condition.resolve(prevSchema, options), schema);
1194
- schema = schema.resolve(options);
1195
- }
1196
- return schema;
1197
- }
1198
- resolveOptions(options) {
1199
- var _options$strict, _options$abortEarly, _options$recursive, _options$disableStack;
1200
- return Object.assign({}, options, {
1201
- from: options.from || [],
1202
- strict: (_options$strict = options.strict) != null ? _options$strict : this.spec.strict,
1203
- abortEarly: (_options$abortEarly = options.abortEarly) != null ? _options$abortEarly : this.spec.abortEarly,
1204
- recursive: (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive,
1205
- disableStackTrace: (_options$disableStack = options.disableStackTrace) != null ? _options$disableStack : this.spec.disableStackTrace
1206
- });
1207
- }
1208
- /**
1209
- * Run the configured transform pipeline over an input value.
1210
- */
1211
- cast(value, options = {}) {
1212
- let resolvedSchema = this.resolve(Object.assign({}, options, {
1213
- value
1214
- // parent: options.parent,
1215
- // context: options.context,
1216
- }));
1217
- let allowOptionality = options.assert === "ignore-optionality";
1218
- let result = resolvedSchema._cast(value, options);
1219
- if (options.assert !== false && !resolvedSchema.isType(result)) {
1220
- if (allowOptionality && isAbsent(result)) {
1221
- return result;
1222
- }
1223
- let formattedValue = printValue(value);
1224
- let formattedResult = printValue(result);
1225
- throw new TypeError(`The value of ${options.path || "field"} could not be cast to a value that satisfies the schema type: "${resolvedSchema.type}".
1226
-
1227
- attempted value: ${formattedValue}
1228
- ` + (formattedResult !== formattedValue ? `result of cast: ${formattedResult}` : ""));
1229
- }
1230
- return result;
1231
- }
1232
- _cast(rawValue, options) {
1233
- let value = rawValue === void 0 ? rawValue : this.transforms.reduce((prevValue, fn) => fn.call(this, prevValue, rawValue, this, options), rawValue);
1234
- if (value === void 0) {
1235
- value = this.getDefault(options);
1236
- }
1237
- return value;
1238
- }
1239
- _validate(_value, options = {}, panic, next) {
1240
- let {
1241
- path,
1242
- originalValue = _value,
1243
- strict = this.spec.strict
1244
- } = options;
1245
- let value = _value;
1246
- if (!strict) {
1247
- value = this._cast(value, Object.assign({
1248
- assert: false
1249
- }, options));
1250
- }
1251
- let initialTests = [];
1252
- for (let test of Object.values(this.internalTests)) {
1253
- if (test) initialTests.push(test);
1254
- }
1255
- this.runTests({
1256
- path,
1257
- value,
1258
- originalValue,
1259
- options,
1260
- tests: initialTests
1261
- }, panic, (initialErrors) => {
1262
- if (initialErrors.length) {
1263
- return next(initialErrors, value);
1264
- }
1265
- this.runTests({
1266
- path,
1267
- value,
1268
- originalValue,
1269
- options,
1270
- tests: this.tests
1271
- }, panic, next);
1272
- });
1273
- }
1274
- /**
1275
- * Executes a set of validations, either schema, produced Tests or a nested
1276
- * schema validate result.
1277
- */
1278
- runTests(runOptions, panic, next) {
1279
- let fired = false;
1280
- let {
1281
- tests,
1282
- value,
1283
- originalValue,
1284
- path,
1285
- options
1286
- } = runOptions;
1287
- let panicOnce = (arg) => {
1288
- if (fired) return;
1289
- fired = true;
1290
- panic(arg, value);
1291
- };
1292
- let nextOnce = (arg) => {
1293
- if (fired) return;
1294
- fired = true;
1295
- next(arg, value);
1296
- };
1297
- let count = tests.length;
1298
- let nestedErrors = [];
1299
- if (!count) return nextOnce([]);
1300
- let args = {
1301
- value,
1302
- originalValue,
1303
- path,
1304
- options,
1305
- schema: this
1306
- };
1307
- for (let i = 0; i < tests.length; i++) {
1308
- const test = tests[i];
1309
- test(args, panicOnce, function finishTestRun(err) {
1310
- if (err) {
1311
- Array.isArray(err) ? nestedErrors.push(...err) : nestedErrors.push(err);
1312
- }
1313
- if (--count <= 0) {
1314
- nextOnce(nestedErrors);
1315
- }
1316
- });
1317
- }
1318
- }
1319
- asNestedTest({
1320
- key,
1321
- index,
1322
- parent,
1323
- parentPath,
1324
- originalParent,
1325
- options
1326
- }) {
1327
- const k = key != null ? key : index;
1328
- if (k == null) {
1329
- throw TypeError("Must include `key` or `index` for nested validations");
1330
- }
1331
- const isIndex = typeof k === "number";
1332
- let value = parent[k];
1333
- const testOptions = Object.assign({}, options, {
1334
- // Nested validations fields are always strict:
1335
- // 1. parent isn't strict so the casting will also have cast inner values
1336
- // 2. parent is strict in which case the nested values weren't cast either
1337
- strict: true,
1338
- parent,
1339
- value,
1340
- originalValue: originalParent[k],
1341
- // FIXME: tests depend on `index` being passed around deeply,
1342
- // we should not let the options.key/index bleed through
1343
- key: void 0,
1344
- // index: undefined,
1345
- [isIndex ? "index" : "key"]: k,
1346
- path: isIndex || k.includes(".") ? `${parentPath || ""}[${isIndex ? k : `"${k}"`}]` : (parentPath ? `${parentPath}.` : "") + key
1347
- });
1348
- return (_, panic, next) => this.resolve(testOptions)._validate(value, testOptions, panic, next);
1349
- }
1350
- validate(value, options) {
1351
- var _options$disableStack2;
1352
- let schema = this.resolve(Object.assign({}, options, {
1353
- value
1354
- }));
1355
- let disableStackTrace = (_options$disableStack2 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack2 : schema.spec.disableStackTrace;
1356
- return new Promise((resolve, reject) => schema._validate(value, options, (error, parsed) => {
1357
- if (ValidationError.isError(error)) error.value = parsed;
1358
- reject(error);
1359
- }, (errors, validated) => {
1360
- if (errors.length) reject(new ValidationError(errors, validated, void 0, void 0, disableStackTrace));
1361
- else resolve(validated);
1362
- }));
1363
- }
1364
- validateSync(value, options) {
1365
- var _options$disableStack3;
1366
- let schema = this.resolve(Object.assign({}, options, {
1367
- value
1368
- }));
1369
- let result;
1370
- let disableStackTrace = (_options$disableStack3 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack3 : schema.spec.disableStackTrace;
1371
- schema._validate(value, Object.assign({}, options, {
1372
- sync: true
1373
- }), (error, parsed) => {
1374
- if (ValidationError.isError(error)) error.value = parsed;
1375
- throw error;
1376
- }, (errors, validated) => {
1377
- if (errors.length) throw new ValidationError(errors, value, void 0, void 0, disableStackTrace);
1378
- result = validated;
1379
- });
1380
- return result;
1381
- }
1382
- isValid(value, options) {
1383
- return this.validate(value, options).then(() => true, (err) => {
1384
- if (ValidationError.isError(err)) return false;
1385
- throw err;
1386
- });
1387
- }
1388
- isValidSync(value, options) {
1389
- try {
1390
- this.validateSync(value, options);
1391
- return true;
1392
- } catch (err) {
1393
- if (ValidationError.isError(err)) return false;
1394
- throw err;
1395
- }
1396
- }
1397
- _getDefault(options) {
1398
- let defaultValue = this.spec.default;
1399
- if (defaultValue == null) {
1400
- return defaultValue;
1401
- }
1402
- return typeof defaultValue === "function" ? defaultValue.call(this, options) : clone(defaultValue);
1403
- }
1404
- getDefault(options) {
1405
- let schema = this.resolve(options || {});
1406
- return schema._getDefault(options);
1407
- }
1408
- default(def) {
1409
- if (arguments.length === 0) {
1410
- return this._getDefault();
1411
- }
1412
- let next = this.clone({
1413
- default: def
1414
- });
1415
- return next;
1416
- }
1417
- strict(isStrict = true) {
1418
- return this.clone({
1419
- strict: isStrict
1420
- });
1421
- }
1422
- nullability(nullable, message) {
1423
- const next = this.clone({
1424
- nullable
1425
- });
1426
- next.internalTests.nullable = createValidation({
1427
- message,
1428
- name: "nullable",
1429
- test(value) {
1430
- return value === null ? this.schema.spec.nullable : true;
1431
- }
1432
- });
1433
- return next;
1434
- }
1435
- optionality(optional, message) {
1436
- const next = this.clone({
1437
- optional
1438
- });
1439
- next.internalTests.optionality = createValidation({
1440
- message,
1441
- name: "optionality",
1442
- test(value) {
1443
- return value === void 0 ? this.schema.spec.optional : true;
1444
- }
1445
- });
1446
- return next;
1447
- }
1448
- optional() {
1449
- return this.optionality(true);
1450
- }
1451
- defined(message = mixed.defined) {
1452
- return this.optionality(false, message);
1453
- }
1454
- nullable() {
1455
- return this.nullability(true);
1456
- }
1457
- nonNullable(message = mixed.notNull) {
1458
- return this.nullability(false, message);
1459
- }
1460
- required(message = mixed.required) {
1461
- return this.clone().withMutation((next) => next.nonNullable(message).defined(message));
1462
- }
1463
- notRequired() {
1464
- return this.clone().withMutation((next) => next.nullable().optional());
1465
- }
1466
- transform(fn) {
1467
- let next = this.clone();
1468
- next.transforms.push(fn);
1469
- return next;
1470
- }
1471
- /**
1472
- * Adds a test function to the schema's queue of tests.
1473
- * tests can be exclusive or non-exclusive.
1474
- *
1475
- * - exclusive tests, will replace any existing tests of the same name.
1476
- * - non-exclusive: can be stacked
1477
- *
1478
- * If a non-exclusive test is added to a schema with an exclusive test of the same name
1479
- * the exclusive test is removed and further tests of the same name will be stacked.
1480
- *
1481
- * If an exclusive test is added to a schema with non-exclusive tests of the same name
1482
- * the previous tests are removed and further tests of the same name will replace each other.
1483
- */
1484
- test(...args) {
1485
- let opts;
1486
- if (args.length === 1) {
1487
- if (typeof args[0] === "function") {
1488
- opts = {
1489
- test: args[0]
1490
- };
1491
- } else {
1492
- opts = args[0];
1493
- }
1494
- } else if (args.length === 2) {
1495
- opts = {
1496
- name: args[0],
1497
- test: args[1]
1498
- };
1499
- } else {
1500
- opts = {
1501
- name: args[0],
1502
- message: args[1],
1503
- test: args[2]
1504
- };
1505
- }
1506
- if (opts.message === void 0) opts.message = mixed.default;
1507
- if (typeof opts.test !== "function") throw new TypeError("`test` is a required parameters");
1508
- let next = this.clone();
1509
- let validate = createValidation(opts);
1510
- let isExclusive = opts.exclusive || opts.name && next.exclusiveTests[opts.name] === true;
1511
- if (opts.exclusive) {
1512
- if (!opts.name) throw new TypeError("Exclusive tests must provide a unique `name` identifying the test");
1513
- }
1514
- if (opts.name) next.exclusiveTests[opts.name] = !!opts.exclusive;
1515
- next.tests = next.tests.filter((fn) => {
1516
- if (fn.OPTIONS.name === opts.name) {
1517
- if (isExclusive) return false;
1518
- if (fn.OPTIONS.test === validate.OPTIONS.test) return false;
1519
- }
1520
- return true;
1521
- });
1522
- next.tests.push(validate);
1523
- return next;
1524
- }
1525
- when(keys, options) {
1526
- if (!Array.isArray(keys) && typeof keys !== "string") {
1527
- options = keys;
1528
- keys = ".";
1529
- }
1530
- let next = this.clone();
1531
- let deps = toArray(keys).map((key) => new Reference(key));
1532
- deps.forEach((dep) => {
1533
- if (dep.isSibling) next.deps.push(dep.key);
1534
- });
1535
- next.conditions.push(typeof options === "function" ? new Condition(deps, options) : Condition.fromOptions(deps, options));
1536
- return next;
1537
- }
1538
- typeError(message) {
1539
- let next = this.clone();
1540
- next.internalTests.typeError = createValidation({
1541
- message,
1542
- name: "typeError",
1543
- skipAbsent: true,
1544
- test(value) {
1545
- if (!this.schema._typeCheck(value)) return this.createError({
1546
- params: {
1547
- type: this.schema.type
1548
- }
1549
- });
1550
- return true;
1551
- }
1552
- });
1553
- return next;
1554
- }
1555
- oneOf(enums, message = mixed.oneOf) {
1556
- let next = this.clone();
1557
- enums.forEach((val) => {
1558
- next._whitelist.add(val);
1559
- next._blacklist.delete(val);
1560
- });
1561
- next.internalTests.whiteList = createValidation({
1562
- message,
1563
- name: "oneOf",
1564
- skipAbsent: true,
1565
- test(value) {
1566
- let valids = this.schema._whitelist;
1567
- let resolved = valids.resolveAll(this.resolve);
1568
- return resolved.includes(value) ? true : this.createError({
1569
- params: {
1570
- values: Array.from(valids).join(", "),
1571
- resolved
1572
- }
1573
- });
1574
- }
1575
- });
1576
- return next;
1577
- }
1578
- notOneOf(enums, message = mixed.notOneOf) {
1579
- let next = this.clone();
1580
- enums.forEach((val) => {
1581
- next._blacklist.add(val);
1582
- next._whitelist.delete(val);
1583
- });
1584
- next.internalTests.blacklist = createValidation({
1585
- message,
1586
- name: "notOneOf",
1587
- test(value) {
1588
- let invalids = this.schema._blacklist;
1589
- let resolved = invalids.resolveAll(this.resolve);
1590
- if (resolved.includes(value)) return this.createError({
1591
- params: {
1592
- values: Array.from(invalids).join(", "),
1593
- resolved
1594
- }
1595
- });
1596
- return true;
1597
- }
1598
- });
1599
- return next;
1600
- }
1601
- strip(strip = true) {
1602
- let next = this.clone();
1603
- next.spec.strip = strip;
1604
- return next;
1605
- }
1606
- /**
1607
- * Return a serialized description of the schema including validations, flags, types etc.
1608
- *
1609
- * @param options Provide any needed context for resolving runtime schema alterations (lazy, when conditions, etc).
1610
- */
1611
- describe(options) {
1612
- const next = (options ? this.resolve(options) : this).clone();
1613
- const {
1614
- label,
1615
- meta,
1616
- optional,
1617
- nullable
1618
- } = next.spec;
1619
- const description = {
1620
- meta,
1621
- label,
1622
- optional,
1623
- nullable,
1624
- default: next.getDefault(options),
1625
- type: next.type,
1626
- oneOf: next._whitelist.describe(),
1627
- notOneOf: next._blacklist.describe(),
1628
- tests: next.tests.filter((n, idx, list) => list.findIndex((c) => c.OPTIONS.name === n.OPTIONS.name) === idx).map((fn) => {
1629
- const params = fn.OPTIONS.params && options ? resolveParams(Object.assign({}, fn.OPTIONS.params), options) : fn.OPTIONS.params;
1630
- return {
1631
- name: fn.OPTIONS.name,
1632
- params
1633
- };
1634
- })
1635
- };
1636
- return description;
1637
- }
1638
- get ["~standard"]() {
1639
- const schema = this;
1640
- const standard = {
1641
- version: 1,
1642
- vendor: "yup",
1643
- async validate(value) {
1644
- try {
1645
- const result = await schema.validate(value, {
1646
- abortEarly: false
1647
- });
1648
- return {
1649
- value: result
1650
- };
1651
- } catch (err) {
1652
- if (err instanceof ValidationError) {
1653
- return {
1654
- issues: issuesFromValidationError(err)
1655
- };
1656
- }
1657
- throw err;
1658
- }
1659
- }
1660
- };
1661
- return standard;
1662
- }
1663
- };
1664
- Schema.prototype.__isYupSchema__ = true;
1665
- for (const method of ["validate", "validateSync"]) Schema.prototype[`${method}At`] = function(path, value, options = {}) {
1666
- const {
1667
- parent,
1668
- parentPath,
1669
- schema
1670
- } = getIn(this, path, value, options.context);
1671
- return schema[method](parent && parent[parentPath], Object.assign({}, options, {
1672
- parent,
1673
- path
1674
- }));
1675
- };
1676
- for (const alias of ["equals", "is"]) Schema.prototype[alias] = Schema.prototype.oneOf;
1677
- for (const alias of ["not", "nope"]) Schema.prototype[alias] = Schema.prototype.notOneOf;
1678
- var returnsTrue = () => true;
1679
- function create$8(spec) {
1680
- return new MixedSchema(spec);
1681
- }
1682
- var MixedSchema = class extends Schema {
1683
- constructor(spec) {
1684
- super(typeof spec === "function" ? {
1685
- type: "mixed",
1686
- check: spec
1687
- } : Object.assign({
1688
- type: "mixed",
1689
- check: returnsTrue
1690
- }, spec));
1691
- }
1692
- };
1693
- create$8.prototype = MixedSchema.prototype;
1694
- function create$7() {
1695
- return new BooleanSchema();
1696
- }
1697
- var BooleanSchema = class extends Schema {
1698
- constructor() {
1699
- super({
1700
- type: "boolean",
1701
- check(v) {
1702
- if (v instanceof Boolean) v = v.valueOf();
1703
- return typeof v === "boolean";
1704
- }
1705
- });
1706
- this.withMutation(() => {
1707
- this.transform((value, _raw) => {
1708
- if (this.spec.coerce && !this.isType(value)) {
1709
- if (/^(true|1)$/i.test(String(value))) return true;
1710
- if (/^(false|0)$/i.test(String(value))) return false;
1711
- }
1712
- return value;
1713
- });
1714
- });
1715
- }
1716
- isTrue(message = boolean.isValue) {
1717
- return this.test({
1718
- message,
1719
- name: "is-value",
1720
- exclusive: true,
1721
- params: {
1722
- value: "true"
1723
- },
1724
- test(value) {
1725
- return isAbsent(value) || value === true;
1726
- }
1727
- });
1728
- }
1729
- isFalse(message = boolean.isValue) {
1730
- return this.test({
1731
- message,
1732
- name: "is-value",
1733
- exclusive: true,
1734
- params: {
1735
- value: "false"
1736
- },
1737
- test(value) {
1738
- return isAbsent(value) || value === false;
1739
- }
1740
- });
1741
- }
1742
- default(def) {
1743
- return super.default(def);
1744
- }
1745
- defined(msg) {
1746
- return super.defined(msg);
1747
- }
1748
- optional() {
1749
- return super.optional();
1750
- }
1751
- required(msg) {
1752
- return super.required(msg);
1753
- }
1754
- notRequired() {
1755
- return super.notRequired();
1756
- }
1757
- nullable() {
1758
- return super.nullable();
1759
- }
1760
- nonNullable(msg) {
1761
- return super.nonNullable(msg);
1762
- }
1763
- strip(v) {
1764
- return super.strip(v);
1765
- }
1766
- };
1767
- create$7.prototype = BooleanSchema.prototype;
1768
- var isoReg = /^(\d{4}|[+-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,.](\d{1,}))?)?(?:(Z)|([+-])(\d{2})(?::?(\d{2}))?)?)?$/;
1769
- function parseIsoDate(date2) {
1770
- const struct = parseDateStruct(date2);
1771
- if (!struct) return Date.parse ? Date.parse(date2) : Number.NaN;
1772
- if (struct.z === void 0 && struct.plusMinus === void 0) {
1773
- return new Date(struct.year, struct.month, struct.day, struct.hour, struct.minute, struct.second, struct.millisecond).valueOf();
1774
- }
1775
- let totalMinutesOffset = 0;
1776
- if (struct.z !== "Z" && struct.plusMinus !== void 0) {
1777
- totalMinutesOffset = struct.hourOffset * 60 + struct.minuteOffset;
1778
- if (struct.plusMinus === "+") totalMinutesOffset = 0 - totalMinutesOffset;
1779
- }
1780
- return Date.UTC(struct.year, struct.month, struct.day, struct.hour, struct.minute + totalMinutesOffset, struct.second, struct.millisecond);
1781
- }
1782
- function parseDateStruct(date2) {
1783
- var _regexResult$7$length, _regexResult$;
1784
- const regexResult = isoReg.exec(date2);
1785
- if (!regexResult) return null;
1786
- return {
1787
- year: toNumber(regexResult[1]),
1788
- month: toNumber(regexResult[2], 1) - 1,
1789
- day: toNumber(regexResult[3], 1),
1790
- hour: toNumber(regexResult[4]),
1791
- minute: toNumber(regexResult[5]),
1792
- second: toNumber(regexResult[6]),
1793
- millisecond: regexResult[7] ? (
1794
- // allow arbitrary sub-second precision beyond milliseconds
1795
- toNumber(regexResult[7].substring(0, 3))
1796
- ) : 0,
1797
- precision: (_regexResult$7$length = (_regexResult$ = regexResult[7]) == null ? void 0 : _regexResult$.length) != null ? _regexResult$7$length : void 0,
1798
- z: regexResult[8] || void 0,
1799
- plusMinus: regexResult[9] || void 0,
1800
- hourOffset: toNumber(regexResult[10]),
1801
- minuteOffset: toNumber(regexResult[11])
1802
- };
1803
- }
1804
- function toNumber(str, defaultValue = 0) {
1805
- return Number(str) || defaultValue;
1806
- }
1807
- var rEmail = (
1808
- // eslint-disable-next-line
1809
- /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
1810
- );
1811
- var rUrl = (
1812
- // eslint-disable-next-line
1813
- /^((https?|ftp):)?\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
1814
- );
1815
- var rUUID = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
1816
- var yearMonthDay = "^\\d{4}-\\d{2}-\\d{2}";
1817
- var hourMinuteSecond = "\\d{2}:\\d{2}:\\d{2}";
1818
- var zOrOffset = "(([+-]\\d{2}(:?\\d{2})?)|Z)";
1819
- var rIsoDateTime = new RegExp(`${yearMonthDay}T${hourMinuteSecond}(\\.\\d+)?${zOrOffset}$`);
1820
- var isTrimmed = (value) => isAbsent(value) || value === value.trim();
1821
- var objStringTag = {}.toString();
1822
- function create$6() {
1823
- return new StringSchema();
1824
- }
1825
- var StringSchema = class extends Schema {
1826
- constructor() {
1827
- super({
1828
- type: "string",
1829
- check(value) {
1830
- if (value instanceof String) value = value.valueOf();
1831
- return typeof value === "string";
1832
- }
1833
- });
1834
- this.withMutation(() => {
1835
- this.transform((value, _raw) => {
1836
- if (!this.spec.coerce || this.isType(value)) return value;
1837
- if (Array.isArray(value)) return value;
1838
- const strValue = value != null && value.toString ? value.toString() : value;
1839
- if (strValue === objStringTag) return value;
1840
- return strValue;
1841
- });
1842
- });
1843
- }
1844
- required(message) {
1845
- return super.required(message).withMutation((schema) => schema.test({
1846
- message: message || mixed.required,
1847
- name: "required",
1848
- skipAbsent: true,
1849
- test: (value) => !!value.length
1850
- }));
1851
- }
1852
- notRequired() {
1853
- return super.notRequired().withMutation((schema) => {
1854
- schema.tests = schema.tests.filter((t) => t.OPTIONS.name !== "required");
1855
- return schema;
1856
- });
1857
- }
1858
- length(length, message = string.length) {
1859
- return this.test({
1860
- message,
1861
- name: "length",
1862
- exclusive: true,
1863
- params: {
1864
- length
1865
- },
1866
- skipAbsent: true,
1867
- test(value) {
1868
- return value.length === this.resolve(length);
1869
- }
1870
- });
1871
- }
1872
- min(min, message = string.min) {
1873
- return this.test({
1874
- message,
1875
- name: "min",
1876
- exclusive: true,
1877
- params: {
1878
- min
1879
- },
1880
- skipAbsent: true,
1881
- test(value) {
1882
- return value.length >= this.resolve(min);
1883
- }
1884
- });
1885
- }
1886
- max(max, message = string.max) {
1887
- return this.test({
1888
- name: "max",
1889
- exclusive: true,
1890
- message,
1891
- params: {
1892
- max
1893
- },
1894
- skipAbsent: true,
1895
- test(value) {
1896
- return value.length <= this.resolve(max);
1897
- }
1898
- });
1899
- }
1900
- matches(regex, options) {
1901
- let excludeEmptyString = false;
1902
- let message;
1903
- let name;
1904
- if (options) {
1905
- if (typeof options === "object") {
1906
- ({
1907
- excludeEmptyString = false,
1908
- message,
1909
- name
1910
- } = options);
1911
- } else {
1912
- message = options;
1913
- }
1914
- }
1915
- return this.test({
1916
- name: name || "matches",
1917
- message: message || string.matches,
1918
- params: {
1919
- regex
1920
- },
1921
- skipAbsent: true,
1922
- test: (value) => value === "" && excludeEmptyString || value.search(regex) !== -1
1923
- });
1924
- }
1925
- email(message = string.email) {
1926
- return this.matches(rEmail, {
1927
- name: "email",
1928
- message,
1929
- excludeEmptyString: true
1930
- });
1931
- }
1932
- url(message = string.url) {
1933
- return this.matches(rUrl, {
1934
- name: "url",
1935
- message,
1936
- excludeEmptyString: true
1937
- });
1938
- }
1939
- uuid(message = string.uuid) {
1940
- return this.matches(rUUID, {
1941
- name: "uuid",
1942
- message,
1943
- excludeEmptyString: false
1944
- });
1945
- }
1946
- datetime(options) {
1947
- let message = "";
1948
- let allowOffset;
1949
- let precision;
1950
- if (options) {
1951
- if (typeof options === "object") {
1952
- ({
1953
- message = "",
1954
- allowOffset = false,
1955
- precision = void 0
1956
- } = options);
1957
- } else {
1958
- message = options;
1959
- }
1960
- }
1961
- return this.matches(rIsoDateTime, {
1962
- name: "datetime",
1963
- message: message || string.datetime,
1964
- excludeEmptyString: true
1965
- }).test({
1966
- name: "datetime_offset",
1967
- message: message || string.datetime_offset,
1968
- params: {
1969
- allowOffset
1970
- },
1971
- skipAbsent: true,
1972
- test: (value) => {
1973
- if (!value || allowOffset) return true;
1974
- const struct = parseDateStruct(value);
1975
- if (!struct) return false;
1976
- return !!struct.z;
1977
- }
1978
- }).test({
1979
- name: "datetime_precision",
1980
- message: message || string.datetime_precision,
1981
- params: {
1982
- precision
1983
- },
1984
- skipAbsent: true,
1985
- test: (value) => {
1986
- if (!value || precision == void 0) return true;
1987
- const struct = parseDateStruct(value);
1988
- if (!struct) return false;
1989
- return struct.precision === precision;
1990
- }
1991
- });
1992
- }
1993
- //-- transforms --
1994
- ensure() {
1995
- return this.default("").transform((val) => val === null ? "" : val);
1996
- }
1997
- trim(message = string.trim) {
1998
- return this.transform((val) => val != null ? val.trim() : val).test({
1999
- message,
2000
- name: "trim",
2001
- test: isTrimmed
2002
- });
2003
- }
2004
- lowercase(message = string.lowercase) {
2005
- return this.transform((value) => !isAbsent(value) ? value.toLowerCase() : value).test({
2006
- message,
2007
- name: "string_case",
2008
- exclusive: true,
2009
- skipAbsent: true,
2010
- test: (value) => isAbsent(value) || value === value.toLowerCase()
2011
- });
2012
- }
2013
- uppercase(message = string.uppercase) {
2014
- return this.transform((value) => !isAbsent(value) ? value.toUpperCase() : value).test({
2015
- message,
2016
- name: "string_case",
2017
- exclusive: true,
2018
- skipAbsent: true,
2019
- test: (value) => isAbsent(value) || value === value.toUpperCase()
2020
- });
2021
- }
2022
- };
2023
- create$6.prototype = StringSchema.prototype;
2024
- var isNaN$1 = (value) => value != +value;
2025
- function create$5() {
2026
- return new NumberSchema();
2027
- }
2028
- var NumberSchema = class extends Schema {
2029
- constructor() {
2030
- super({
2031
- type: "number",
2032
- check(value) {
2033
- if (value instanceof Number) value = value.valueOf();
2034
- return typeof value === "number" && !isNaN$1(value);
2035
- }
2036
- });
2037
- this.withMutation(() => {
2038
- this.transform((value, _raw) => {
2039
- if (!this.spec.coerce) return value;
2040
- let parsed = value;
2041
- if (typeof parsed === "string") {
2042
- parsed = parsed.replace(/\s/g, "");
2043
- if (parsed === "") return NaN;
2044
- parsed = +parsed;
2045
- }
2046
- if (this.isType(parsed) || parsed === null) return parsed;
2047
- return parseFloat(parsed);
2048
- });
2049
- });
2050
- }
2051
- min(min, message = number.min) {
2052
- return this.test({
2053
- message,
2054
- name: "min",
2055
- exclusive: true,
2056
- params: {
2057
- min
2058
- },
2059
- skipAbsent: true,
2060
- test(value) {
2061
- return value >= this.resolve(min);
2062
- }
2063
- });
2064
- }
2065
- max(max, message = number.max) {
2066
- return this.test({
2067
- message,
2068
- name: "max",
2069
- exclusive: true,
2070
- params: {
2071
- max
2072
- },
2073
- skipAbsent: true,
2074
- test(value) {
2075
- return value <= this.resolve(max);
2076
- }
2077
- });
2078
- }
2079
- lessThan(less, message = number.lessThan) {
2080
- return this.test({
2081
- message,
2082
- name: "max",
2083
- exclusive: true,
2084
- params: {
2085
- less
2086
- },
2087
- skipAbsent: true,
2088
- test(value) {
2089
- return value < this.resolve(less);
2090
- }
2091
- });
2092
- }
2093
- moreThan(more, message = number.moreThan) {
2094
- return this.test({
2095
- message,
2096
- name: "min",
2097
- exclusive: true,
2098
- params: {
2099
- more
2100
- },
2101
- skipAbsent: true,
2102
- test(value) {
2103
- return value > this.resolve(more);
2104
- }
2105
- });
2106
- }
2107
- positive(msg = number.positive) {
2108
- return this.moreThan(0, msg);
2109
- }
2110
- negative(msg = number.negative) {
2111
- return this.lessThan(0, msg);
2112
- }
2113
- integer(message = number.integer) {
2114
- return this.test({
2115
- name: "integer",
2116
- message,
2117
- skipAbsent: true,
2118
- test: (val) => Number.isInteger(val)
2119
- });
2120
- }
2121
- truncate() {
2122
- return this.transform((value) => !isAbsent(value) ? value | 0 : value);
2123
- }
2124
- round(method) {
2125
- var _method;
2126
- let avail = ["ceil", "floor", "round", "trunc"];
2127
- method = ((_method = method) == null ? void 0 : _method.toLowerCase()) || "round";
2128
- if (method === "trunc") return this.truncate();
2129
- if (avail.indexOf(method.toLowerCase()) === -1) throw new TypeError("Only valid options for round() are: " + avail.join(", "));
2130
- return this.transform((value) => !isAbsent(value) ? Math[method](value) : value);
2131
- }
2132
- };
2133
- create$5.prototype = NumberSchema.prototype;
2134
- var invalidDate = /* @__PURE__ */ new Date("");
2135
- var isDate = (obj) => Object.prototype.toString.call(obj) === "[object Date]";
2136
- function create$4() {
2137
- return new DateSchema();
2138
- }
2139
- var DateSchema = class _DateSchema extends Schema {
2140
- constructor() {
2141
- super({
2142
- type: "date",
2143
- check(v) {
2144
- return isDate(v) && !isNaN(v.getTime());
2145
- }
2146
- });
2147
- this.withMutation(() => {
2148
- this.transform((value, _raw) => {
2149
- if (!this.spec.coerce || this.isType(value) || value === null) return value;
2150
- value = parseIsoDate(value);
2151
- return !isNaN(value) ? new Date(value) : _DateSchema.INVALID_DATE;
2152
- });
2153
- });
2154
- }
2155
- prepareParam(ref, name) {
2156
- let param;
2157
- if (!Reference.isRef(ref)) {
2158
- let cast = this.cast(ref);
2159
- if (!this._typeCheck(cast)) throw new TypeError(`\`${name}\` must be a Date or a value that can be \`cast()\` to a Date`);
2160
- param = cast;
2161
- } else {
2162
- param = ref;
2163
- }
2164
- return param;
2165
- }
2166
- min(min, message = date.min) {
2167
- let limit = this.prepareParam(min, "min");
2168
- return this.test({
2169
- message,
2170
- name: "min",
2171
- exclusive: true,
2172
- params: {
2173
- min
2174
- },
2175
- skipAbsent: true,
2176
- test(value) {
2177
- return value >= this.resolve(limit);
2178
- }
2179
- });
2180
- }
2181
- max(max, message = date.max) {
2182
- let limit = this.prepareParam(max, "max");
2183
- return this.test({
2184
- message,
2185
- name: "max",
2186
- exclusive: true,
2187
- params: {
2188
- max
2189
- },
2190
- skipAbsent: true,
2191
- test(value) {
2192
- return value <= this.resolve(limit);
2193
- }
2194
- });
2195
- }
2196
- };
2197
- DateSchema.INVALID_DATE = invalidDate;
2198
- create$4.prototype = DateSchema.prototype;
2199
- create$4.INVALID_DATE = invalidDate;
2200
- function sortFields(fields, excludedEdges = []) {
2201
- let edges = [];
2202
- let nodes = /* @__PURE__ */ new Set();
2203
- let excludes = new Set(excludedEdges.map(([a, b]) => `${a}-${b}`));
2204
- function addNode(depPath, key) {
2205
- let node = (0, import_property_expr.split)(depPath)[0];
2206
- nodes.add(node);
2207
- if (!excludes.has(`${key}-${node}`)) edges.push([key, node]);
2208
- }
2209
- for (const key of Object.keys(fields)) {
2210
- let value = fields[key];
2211
- nodes.add(key);
2212
- if (Reference.isRef(value) && value.isSibling) addNode(value.path, key);
2213
- else if (isSchema(value) && "deps" in value) value.deps.forEach((path) => addNode(path, key));
2214
- }
2215
- return import_toposort.default.array(Array.from(nodes), edges).reverse();
2216
- }
2217
- function findIndex(arr, err) {
2218
- let idx = Infinity;
2219
- arr.some((key, ii) => {
2220
- var _err$path;
2221
- if ((_err$path = err.path) != null && _err$path.includes(key)) {
2222
- idx = ii;
2223
- return true;
2224
- }
2225
- });
2226
- return idx;
2227
- }
2228
- function sortByKeyOrder(keys) {
2229
- return (a, b) => {
2230
- return findIndex(keys, a) - findIndex(keys, b);
2231
- };
2232
- }
2233
- var parseJson = (value, _, schema) => {
2234
- if (typeof value !== "string") {
2235
- return value;
2236
- }
2237
- let parsed = value;
2238
- try {
2239
- parsed = JSON.parse(value);
2240
- } catch (err) {
2241
- }
2242
- return schema.isType(parsed) ? parsed : value;
2243
- };
2244
- function deepPartial(schema) {
2245
- if ("fields" in schema) {
2246
- const partial = {};
2247
- for (const [key, fieldSchema] of Object.entries(schema.fields)) {
2248
- partial[key] = deepPartial(fieldSchema);
2249
- }
2250
- return schema.setFields(partial);
2251
- }
2252
- if (schema.type === "array") {
2253
- const nextArray = schema.optional();
2254
- if (nextArray.innerType) nextArray.innerType = deepPartial(nextArray.innerType);
2255
- return nextArray;
2256
- }
2257
- if (schema.type === "tuple") {
2258
- return schema.optional().clone({
2259
- types: schema.spec.types.map(deepPartial)
2260
- });
2261
- }
2262
- if ("optional" in schema) {
2263
- return schema.optional();
2264
- }
2265
- return schema;
2266
- }
2267
- var deepHas = (obj, p) => {
2268
- const path = [...(0, import_property_expr.normalizePath)(p)];
2269
- if (path.length === 1) return path[0] in obj;
2270
- let last = path.pop();
2271
- let parent = (0, import_property_expr.getter)((0, import_property_expr.join)(path), true)(obj);
2272
- return !!(parent && last in parent);
2273
- };
2274
- var isObject = (obj) => Object.prototype.toString.call(obj) === "[object Object]";
2275
- function unknown(ctx, value) {
2276
- let known = Object.keys(ctx.fields);
2277
- return Object.keys(value).filter((key) => known.indexOf(key) === -1);
2278
- }
2279
- var defaultSort = sortByKeyOrder([]);
2280
- function create$3(spec) {
2281
- return new ObjectSchema(spec);
2282
- }
2283
- var ObjectSchema = class extends Schema {
2284
- constructor(spec) {
2285
- super({
2286
- type: "object",
2287
- check(value) {
2288
- return isObject(value) || typeof value === "function";
2289
- }
2290
- });
2291
- this.fields = /* @__PURE__ */ Object.create(null);
2292
- this._sortErrors = defaultSort;
2293
- this._nodes = [];
2294
- this._excludedEdges = [];
2295
- this.withMutation(() => {
2296
- if (spec) {
2297
- this.shape(spec);
2298
- }
2299
- });
2300
- }
2301
- _cast(_value, options = {}) {
2302
- var _options$stripUnknown;
2303
- let value = super._cast(_value, options);
2304
- if (value === void 0) return this.getDefault(options);
2305
- if (!this._typeCheck(value)) return value;
2306
- let fields = this.fields;
2307
- let strip = (_options$stripUnknown = options.stripUnknown) != null ? _options$stripUnknown : this.spec.noUnknown;
2308
- let props = [].concat(this._nodes, Object.keys(value).filter((v) => !this._nodes.includes(v)));
2309
- let intermediateValue = {};
2310
- let innerOptions = Object.assign({}, options, {
2311
- parent: intermediateValue,
2312
- __validating: options.__validating || false
2313
- });
2314
- let isChanged = false;
2315
- for (const prop of props) {
2316
- let field = fields[prop];
2317
- let exists = prop in value;
2318
- let inputValue = value[prop];
2319
- if (field) {
2320
- let fieldValue;
2321
- innerOptions.path = (options.path ? `${options.path}.` : "") + prop;
2322
- field = field.resolve({
2323
- value: inputValue,
2324
- context: options.context,
2325
- parent: intermediateValue
2326
- });
2327
- let fieldSpec = field instanceof Schema ? field.spec : void 0;
2328
- let strict = fieldSpec == null ? void 0 : fieldSpec.strict;
2329
- if (fieldSpec != null && fieldSpec.strip) {
2330
- isChanged = isChanged || prop in value;
2331
- continue;
2332
- }
2333
- fieldValue = !options.__validating || !strict ? field.cast(inputValue, innerOptions) : inputValue;
2334
- if (fieldValue !== void 0) {
2335
- intermediateValue[prop] = fieldValue;
2336
- }
2337
- } else if (exists && !strip) {
2338
- intermediateValue[prop] = inputValue;
2339
- }
2340
- if (exists !== prop in intermediateValue || intermediateValue[prop] !== inputValue) {
2341
- isChanged = true;
2342
- }
2343
- }
2344
- return isChanged ? intermediateValue : value;
2345
- }
2346
- _validate(_value, options = {}, panic, next) {
2347
- let {
2348
- from = [],
2349
- originalValue = _value,
2350
- recursive = this.spec.recursive
2351
- } = options;
2352
- options.from = [{
2353
- schema: this,
2354
- value: originalValue
2355
- }, ...from];
2356
- options.__validating = true;
2357
- options.originalValue = originalValue;
2358
- super._validate(_value, options, panic, (objectErrors, value) => {
2359
- if (!recursive || !isObject(value)) {
2360
- next(objectErrors, value);
2361
- return;
2362
- }
2363
- originalValue = originalValue || value;
2364
- let tests = [];
2365
- for (let key of this._nodes) {
2366
- let field = this.fields[key];
2367
- if (!field || Reference.isRef(field)) {
2368
- continue;
2369
- }
2370
- tests.push(field.asNestedTest({
2371
- options,
2372
- key,
2373
- parent: value,
2374
- parentPath: options.path,
2375
- originalParent: originalValue
2376
- }));
2377
- }
2378
- this.runTests({
2379
- tests,
2380
- value,
2381
- originalValue,
2382
- options
2383
- }, panic, (fieldErrors) => {
2384
- next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value);
2385
- });
2386
- });
2387
- }
2388
- clone(spec) {
2389
- const next = super.clone(spec);
2390
- next.fields = Object.assign({}, this.fields);
2391
- next._nodes = this._nodes;
2392
- next._excludedEdges = this._excludedEdges;
2393
- next._sortErrors = this._sortErrors;
2394
- return next;
2395
- }
2396
- concat(schema) {
2397
- let next = super.concat(schema);
2398
- let nextFields = next.fields;
2399
- for (let [field, schemaOrRef] of Object.entries(this.fields)) {
2400
- const target = nextFields[field];
2401
- nextFields[field] = target === void 0 ? schemaOrRef : target;
2402
- }
2403
- return next.withMutation((s) => (
2404
- // XXX: excludes here is wrong
2405
- s.setFields(nextFields, [...this._excludedEdges, ...schema._excludedEdges])
2406
- ));
2407
- }
2408
- _getDefault(options) {
2409
- if ("default" in this.spec) {
2410
- return super._getDefault(options);
2411
- }
2412
- if (!this._nodes.length) {
2413
- return void 0;
2414
- }
2415
- let dft = {};
2416
- this._nodes.forEach((key) => {
2417
- var _innerOptions;
2418
- const field = this.fields[key];
2419
- let innerOptions = options;
2420
- if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
2421
- innerOptions = Object.assign({}, innerOptions, {
2422
- parent: innerOptions.value,
2423
- value: innerOptions.value[key]
2424
- });
2425
- }
2426
- dft[key] = field && "getDefault" in field ? field.getDefault(innerOptions) : void 0;
2427
- });
2428
- return dft;
2429
- }
2430
- setFields(shape, excludedEdges) {
2431
- let next = this.clone();
2432
- next.fields = shape;
2433
- next._nodes = sortFields(shape, excludedEdges);
2434
- next._sortErrors = sortByKeyOrder(Object.keys(shape));
2435
- if (excludedEdges) next._excludedEdges = excludedEdges;
2436
- return next;
2437
- }
2438
- shape(additions, excludes = []) {
2439
- return this.clone().withMutation((next) => {
2440
- let edges = next._excludedEdges;
2441
- if (excludes.length) {
2442
- if (!Array.isArray(excludes[0])) excludes = [excludes];
2443
- edges = [...next._excludedEdges, ...excludes];
2444
- }
2445
- return next.setFields(Object.assign(next.fields, additions), edges);
2446
- });
2447
- }
2448
- partial() {
2449
- const partial = {};
2450
- for (const [key, schema] of Object.entries(this.fields)) {
2451
- partial[key] = "optional" in schema && schema.optional instanceof Function ? schema.optional() : schema;
2452
- }
2453
- return this.setFields(partial);
2454
- }
2455
- deepPartial() {
2456
- const next = deepPartial(this);
2457
- return next;
2458
- }
2459
- pick(keys) {
2460
- const picked = {};
2461
- for (const key of keys) {
2462
- if (this.fields[key]) picked[key] = this.fields[key];
2463
- }
2464
- return this.setFields(picked, this._excludedEdges.filter(([a, b]) => keys.includes(a) && keys.includes(b)));
2465
- }
2466
- omit(keys) {
2467
- const remaining = [];
2468
- for (const key of Object.keys(this.fields)) {
2469
- if (keys.includes(key)) continue;
2470
- remaining.push(key);
2471
- }
2472
- return this.pick(remaining);
2473
- }
2474
- from(from, to, alias) {
2475
- let fromGetter = (0, import_property_expr.getter)(from, true);
2476
- return this.transform((obj) => {
2477
- if (!obj) return obj;
2478
- let newObj = obj;
2479
- if (deepHas(obj, from)) {
2480
- newObj = Object.assign({}, obj);
2481
- if (!alias) delete newObj[from];
2482
- newObj[to] = fromGetter(obj);
2483
- }
2484
- return newObj;
2485
- });
2486
- }
2487
- /** Parse an input JSON string to an object */
2488
- json() {
2489
- return this.transform(parseJson);
2490
- }
2491
- /**
2492
- * Similar to `noUnknown` but only validates that an object is the right shape without stripping the unknown keys
2493
- */
2494
- exact(message) {
2495
- return this.test({
2496
- name: "exact",
2497
- exclusive: true,
2498
- message: message || object.exact,
2499
- test(value) {
2500
- if (value == null) return true;
2501
- const unknownKeys = unknown(this.schema, value);
2502
- return unknownKeys.length === 0 || this.createError({
2503
- params: {
2504
- properties: unknownKeys.join(", ")
2505
- }
2506
- });
2507
- }
2508
- });
2509
- }
2510
- stripUnknown() {
2511
- return this.clone({
2512
- noUnknown: true
2513
- });
2514
- }
2515
- noUnknown(noAllow = true, message = object.noUnknown) {
2516
- if (typeof noAllow !== "boolean") {
2517
- message = noAllow;
2518
- noAllow = true;
2519
- }
2520
- let next = this.test({
2521
- name: "noUnknown",
2522
- exclusive: true,
2523
- message,
2524
- test(value) {
2525
- if (value == null) return true;
2526
- const unknownKeys = unknown(this.schema, value);
2527
- return !noAllow || unknownKeys.length === 0 || this.createError({
2528
- params: {
2529
- unknown: unknownKeys.join(", ")
2530
- }
2531
- });
2532
- }
2533
- });
2534
- next.spec.noUnknown = noAllow;
2535
- return next;
2536
- }
2537
- unknown(allow = true, message = object.noUnknown) {
2538
- return this.noUnknown(!allow, message);
2539
- }
2540
- transformKeys(fn) {
2541
- return this.transform((obj) => {
2542
- if (!obj) return obj;
2543
- const result = {};
2544
- for (const key of Object.keys(obj)) result[fn(key)] = obj[key];
2545
- return result;
2546
- });
2547
- }
2548
- camelCase() {
2549
- return this.transformKeys(import_tiny_case.camelCase);
2550
- }
2551
- snakeCase() {
2552
- return this.transformKeys(import_tiny_case.snakeCase);
2553
- }
2554
- constantCase() {
2555
- return this.transformKeys((key) => (0, import_tiny_case.snakeCase)(key).toUpperCase());
2556
- }
2557
- describe(options) {
2558
- const next = (options ? this.resolve(options) : this).clone();
2559
- const base = super.describe(options);
2560
- base.fields = {};
2561
- for (const [key, value] of Object.entries(next.fields)) {
2562
- var _innerOptions2;
2563
- let innerOptions = options;
2564
- if ((_innerOptions2 = innerOptions) != null && _innerOptions2.value) {
2565
- innerOptions = Object.assign({}, innerOptions, {
2566
- parent: innerOptions.value,
2567
- value: innerOptions.value[key]
2568
- });
2569
- }
2570
- base.fields[key] = value.describe(innerOptions);
2571
- }
2572
- return base;
2573
- }
2574
- };
2575
- create$3.prototype = ObjectSchema.prototype;
2576
- function create$2(type) {
2577
- return new ArraySchema(type);
2578
- }
2579
- var ArraySchema = class extends Schema {
2580
- constructor(type) {
2581
- super({
2582
- type: "array",
2583
- spec: {
2584
- types: type
2585
- },
2586
- check(v) {
2587
- return Array.isArray(v);
2588
- }
2589
- });
2590
- this.innerType = void 0;
2591
- this.innerType = type;
2592
- }
2593
- _cast(_value, _opts) {
2594
- const value = super._cast(_value, _opts);
2595
- if (!this._typeCheck(value) || !this.innerType) {
2596
- return value;
2597
- }
2598
- let isChanged = false;
2599
- const castArray = value.map((v, idx) => {
2600
- const castElement = this.innerType.cast(v, Object.assign({}, _opts, {
2601
- path: `${_opts.path || ""}[${idx}]`,
2602
- parent: value,
2603
- originalValue: v,
2604
- value: v,
2605
- index: idx
2606
- }));
2607
- if (castElement !== v) {
2608
- isChanged = true;
2609
- }
2610
- return castElement;
2611
- });
2612
- return isChanged ? castArray : value;
2613
- }
2614
- _validate(_value, options = {}, panic, next) {
2615
- var _options$recursive;
2616
- let innerType = this.innerType;
2617
- let recursive = (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive;
2618
- options.originalValue != null ? options.originalValue : _value;
2619
- super._validate(_value, options, panic, (arrayErrors, value) => {
2620
- var _options$originalValu2;
2621
- if (!recursive || !innerType || !this._typeCheck(value)) {
2622
- next(arrayErrors, value);
2623
- return;
2624
- }
2625
- let tests = new Array(value.length);
2626
- for (let index = 0; index < value.length; index++) {
2627
- var _options$originalValu;
2628
- tests[index] = innerType.asNestedTest({
2629
- options,
2630
- index,
2631
- parent: value,
2632
- parentPath: options.path,
2633
- originalParent: (_options$originalValu = options.originalValue) != null ? _options$originalValu : _value
2634
- });
2635
- }
2636
- this.runTests({
2637
- value,
2638
- tests,
2639
- originalValue: (_options$originalValu2 = options.originalValue) != null ? _options$originalValu2 : _value,
2640
- options
2641
- }, panic, (innerTypeErrors) => next(innerTypeErrors.concat(arrayErrors), value));
2642
- });
2643
- }
2644
- clone(spec) {
2645
- const next = super.clone(spec);
2646
- next.innerType = this.innerType;
2647
- return next;
2648
- }
2649
- /** Parse an input JSON string to an object */
2650
- json() {
2651
- return this.transform(parseJson);
2652
- }
2653
- concat(schema) {
2654
- let next = super.concat(schema);
2655
- next.innerType = this.innerType;
2656
- if (schema.innerType)
2657
- next.innerType = next.innerType ? (
2658
- // @ts-expect-error Lazy doesn't have concat and will break
2659
- next.innerType.concat(schema.innerType)
2660
- ) : schema.innerType;
2661
- return next;
2662
- }
2663
- of(schema) {
2664
- let next = this.clone();
2665
- if (!isSchema(schema)) throw new TypeError("`array.of()` sub-schema must be a valid yup schema not: " + printValue(schema));
2666
- next.innerType = schema;
2667
- next.spec = Object.assign({}, next.spec, {
2668
- types: schema
2669
- });
2670
- return next;
2671
- }
2672
- length(length, message = array.length) {
2673
- return this.test({
2674
- message,
2675
- name: "length",
2676
- exclusive: true,
2677
- params: {
2678
- length
2679
- },
2680
- skipAbsent: true,
2681
- test(value) {
2682
- return value.length === this.resolve(length);
2683
- }
2684
- });
2685
- }
2686
- min(min, message) {
2687
- message = message || array.min;
2688
- return this.test({
2689
- message,
2690
- name: "min",
2691
- exclusive: true,
2692
- params: {
2693
- min
2694
- },
2695
- skipAbsent: true,
2696
- // FIXME(ts): Array<typeof T>
2697
- test(value) {
2698
- return value.length >= this.resolve(min);
2699
- }
2700
- });
2701
- }
2702
- max(max, message) {
2703
- message = message || array.max;
2704
- return this.test({
2705
- message,
2706
- name: "max",
2707
- exclusive: true,
2708
- params: {
2709
- max
2710
- },
2711
- skipAbsent: true,
2712
- test(value) {
2713
- return value.length <= this.resolve(max);
2714
- }
2715
- });
2716
- }
2717
- ensure() {
2718
- return this.default(() => []).transform((val, original) => {
2719
- if (this._typeCheck(val)) return val;
2720
- return original == null ? [] : [].concat(original);
2721
- });
2722
- }
2723
- compact(rejector) {
2724
- let reject = !rejector ? (v) => !!v : (v, i, a) => !rejector(v, i, a);
2725
- return this.transform((values) => values != null ? values.filter(reject) : values);
2726
- }
2727
- describe(options) {
2728
- const next = (options ? this.resolve(options) : this).clone();
2729
- const base = super.describe(options);
2730
- if (next.innerType) {
2731
- var _innerOptions;
2732
- let innerOptions = options;
2733
- if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
2734
- innerOptions = Object.assign({}, innerOptions, {
2735
- parent: innerOptions.value,
2736
- value: innerOptions.value[0]
2737
- });
2738
- }
2739
- base.innerType = next.innerType.describe(innerOptions);
2740
- }
2741
- return base;
2742
- }
2743
- };
2744
- create$2.prototype = ArraySchema.prototype;
2745
- function create$1(schemas) {
2746
- return new TupleSchema(schemas);
2747
- }
2748
- var TupleSchema = class extends Schema {
2749
- constructor(schemas) {
2750
- super({
2751
- type: "tuple",
2752
- spec: {
2753
- types: schemas
2754
- },
2755
- check(v) {
2756
- const types = this.spec.types;
2757
- return Array.isArray(v) && v.length === types.length;
2758
- }
2759
- });
2760
- this.withMutation(() => {
2761
- this.typeError(tuple.notType);
2762
- });
2763
- }
2764
- _cast(inputValue, options) {
2765
- const {
2766
- types
2767
- } = this.spec;
2768
- const value = super._cast(inputValue, options);
2769
- if (!this._typeCheck(value)) {
2770
- return value;
2771
- }
2772
- let isChanged = false;
2773
- const castArray = types.map((type, idx) => {
2774
- const castElement = type.cast(value[idx], Object.assign({}, options, {
2775
- path: `${options.path || ""}[${idx}]`,
2776
- parent: value,
2777
- originalValue: value[idx],
2778
- value: value[idx],
2779
- index: idx
2780
- }));
2781
- if (castElement !== value[idx]) isChanged = true;
2782
- return castElement;
2783
- });
2784
- return isChanged ? castArray : value;
2785
- }
2786
- _validate(_value, options = {}, panic, next) {
2787
- let itemTypes = this.spec.types;
2788
- super._validate(_value, options, panic, (tupleErrors, value) => {
2789
- var _options$originalValu2;
2790
- if (!this._typeCheck(value)) {
2791
- next(tupleErrors, value);
2792
- return;
2793
- }
2794
- let tests = [];
2795
- for (let [index, itemSchema] of itemTypes.entries()) {
2796
- var _options$originalValu;
2797
- tests[index] = itemSchema.asNestedTest({
2798
- options,
2799
- index,
2800
- parent: value,
2801
- parentPath: options.path,
2802
- originalParent: (_options$originalValu = options.originalValue) != null ? _options$originalValu : _value
2803
- });
2804
- }
2805
- this.runTests({
2806
- value,
2807
- tests,
2808
- originalValue: (_options$originalValu2 = options.originalValue) != null ? _options$originalValu2 : _value,
2809
- options
2810
- }, panic, (innerTypeErrors) => next(innerTypeErrors.concat(tupleErrors), value));
2811
- });
2812
- }
2813
- describe(options) {
2814
- const next = (options ? this.resolve(options) : this).clone();
2815
- const base = super.describe(options);
2816
- base.innerType = next.spec.types.map((schema, index) => {
2817
- var _innerOptions;
2818
- let innerOptions = options;
2819
- if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
2820
- innerOptions = Object.assign({}, innerOptions, {
2821
- parent: innerOptions.value,
2822
- value: innerOptions.value[index]
2823
- });
2824
- }
2825
- return schema.describe(innerOptions);
2826
- });
2827
- return base;
2828
- }
2829
- };
2830
- create$1.prototype = TupleSchema.prototype;
2831
-
2832
309
  // src/adapters/validation/YupAdapter.ts
310
+ var import_yup = require("yup");
2833
311
  var YupAdapter = class {
2834
312
  constructor(schema) {
313
+ __publicField(this, "schema");
2835
314
  this.schema = schema;
2836
315
  }
2837
316
  async validate(data) {
@@ -2839,7 +318,7 @@ var YupAdapter = class {
2839
318
  await this.schema.validate(data, { abortEarly: false });
2840
319
  return { isValid: true };
2841
320
  } catch (err) {
2842
- if (err instanceof ValidationError) {
321
+ if (err instanceof import_yup.ValidationError) {
2843
322
  const errors = {};
2844
323
  err.inner.forEach((error) => {
2845
324
  if (error.path) {