adp-web-components 0.0.27 → 0.0.28

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.
Files changed (79) hide show
  1. package/dist/cjs/{Loading-14fca13b.js → Loading-df2a9144.js} +1 -1
  2. package/dist/cjs/dead-stock-lookup.cjs.entry.js +2 -2
  3. package/dist/cjs/distributor-lookup.cjs.entry.js +2 -2
  4. package/dist/cjs/dynamic-claim_6.cjs.entry.js +38 -5
  5. package/dist/cjs/dynamic-redeem.cjs.entry.js +1 -1
  6. package/dist/cjs/form-input.cjs.entry.js +1 -1
  7. package/dist/cjs/general-inquiry-form.cjs.entry.js +5 -2131
  8. package/dist/cjs/{index-97b8da6d.js → index-d2dc29e0.js} +13 -1
  9. package/dist/cjs/index.esm-c628daeb.js +2135 -0
  10. package/dist/cjs/loader.cjs.js +2 -2
  11. package/dist/cjs/manufacturer-lookup.cjs.entry.js +2 -2
  12. package/dist/cjs/shift-components.cjs.js +2 -2
  13. package/dist/cjs/vehicle-lookup.cjs.entry.js +1 -1
  14. package/dist/collection/components/vehicle-lookup/warranty-details.js +68 -30
  15. package/dist/collection/global/types/locale-schema.js +30 -0
  16. package/dist/components/dead-stock-lookup.js +1 -1
  17. package/dist/components/distributor-lookup.js +1 -1
  18. package/dist/components/dynamic-claim.js +1 -1
  19. package/dist/components/dynamic-redeem.js +1 -1
  20. package/dist/components/form-input.js +1 -1
  21. package/dist/components/general-inquiry-form.js +1 -1
  22. package/dist/components/index.js +1 -1
  23. package/dist/components/manufacturer-lookup.js +1 -1
  24. package/dist/components/p-0be9e62f.js +5 -0
  25. package/dist/components/p-0e4c747d.js +5 -0
  26. package/dist/components/{p-9245caae.js → p-5f03cbe9.js} +1 -1
  27. package/dist/components/p-719499ff.js +5 -0
  28. package/dist/components/{p-2741b156.js → p-7aec104e.js} +1 -1
  29. package/dist/components/{p-6ffb4e5d.js → p-a3d447f9.js} +1 -1
  30. package/dist/components/{p-be0a5ab5.js → p-b2051f01.js} +1 -1
  31. package/dist/components/{p-4bf4435e.js → p-c2815a66.js} +1 -1
  32. package/dist/components/{p-d999f3c4.js → p-d07331eb.js} +1 -1
  33. package/dist/components/p-e446fb9d.js +5 -0
  34. package/dist/components/{p-2ea90585.js → p-ec05b4cd.js} +1 -1
  35. package/dist/components/{p-b90fd51c.js → p-f001d15b.js} +1 -1
  36. package/dist/components/paint-thickness.js +1 -1
  37. package/dist/components/service-history.js +1 -1
  38. package/dist/components/vehicle-accessories.js +1 -1
  39. package/dist/components/vehicle-lookup.js +1 -1
  40. package/dist/components/vehicle-specification.js +1 -1
  41. package/dist/components/warranty-details.js +1 -1
  42. package/dist/esm/{Loading-2b8a745c.js → Loading-3a10eb05.js} +1 -1
  43. package/dist/esm/dead-stock-lookup.entry.js +2 -2
  44. package/dist/esm/distributor-lookup.entry.js +2 -2
  45. package/dist/esm/dynamic-claim_6.entry.js +38 -5
  46. package/dist/esm/dynamic-redeem.entry.js +1 -1
  47. package/dist/esm/form-input.entry.js +1 -1
  48. package/dist/esm/general-inquiry-form.entry.js +2 -2128
  49. package/dist/esm/{index-ff1dab22.js → index-c3d67367.js} +13 -2
  50. package/dist/esm/index.esm-46e0cdad.js +2132 -0
  51. package/dist/esm/loader.js +3 -3
  52. package/dist/esm/manufacturer-lookup.entry.js +2 -2
  53. package/dist/esm/shift-components.js +3 -3
  54. package/dist/esm/vehicle-lookup.entry.js +1 -1
  55. package/dist/locales/ar.json +5 -0
  56. package/dist/locales/en.json +5 -0
  57. package/dist/locales/ku.json +5 -0
  58. package/dist/shift-components/{p-fad254c9.entry.js → p-02ec4905.entry.js} +1 -1
  59. package/dist/shift-components/p-0394e29f.entry.js +5 -0
  60. package/dist/shift-components/{p-33e4c335.entry.js → p-1265a8ec.entry.js} +1 -1
  61. package/dist/shift-components/{p-f6764fb5.entry.js → p-1f46b4d0.entry.js} +1 -1
  62. package/dist/shift-components/p-7a17c535.entry.js +5 -0
  63. package/dist/shift-components/{p-e35e44a4.js → p-89d232e9.js} +1 -1
  64. package/dist/shift-components/{p-26b9d31a.entry.js → p-9d6b2cfb.entry.js} +1 -1
  65. package/dist/shift-components/{p-d03dade1.entry.js → p-bf83fa95.entry.js} +1 -1
  66. package/dist/shift-components/{p-1719e164.entry.js → p-d0683e92.entry.js} +1 -1
  67. package/dist/shift-components/p-dbaab71c.js +6 -0
  68. package/dist/shift-components/p-e446fb9d.js +5 -0
  69. package/dist/shift-components/shift-components.esm.js +1 -1
  70. package/dist/types/components/vehicle-lookup/warranty-details.d.ts +7 -2
  71. package/dist/types/components.d.ts +4 -0
  72. package/dist/types/global/types/locale-schema.d.ts +21 -0
  73. package/package.json +9 -4
  74. package/dist/components/p-514c4736.js +0 -5
  75. package/dist/components/p-c62be897.js +0 -5
  76. package/dist/components/p-d4718f3b.js +0 -5
  77. package/dist/shift-components/p-9f58a33b.entry.js +0 -5
  78. package/dist/shift-components/p-d1ffe0eb.entry.js +0 -5
  79. package/dist/shift-components/p-f37b60d5.js +0 -6
@@ -6,2134 +6,8 @@
6
6
 
7
7
  Object.defineProperty(exports, '__esModule', { value: true });
8
8
 
9
- const index = require('./index-97b8da6d.js');
10
-
11
- /**
12
- * Based on Kendo UI Core expression code <https://github.com/telerik/kendo-ui-core#license-information>
13
- */
14
-
15
- function Cache(maxSize) {
16
- this._maxSize = maxSize;
17
- this.clear();
18
- }
19
- Cache.prototype.clear = function () {
20
- this._size = 0;
21
- this._values = Object.create(null);
22
- };
23
- Cache.prototype.get = function (key) {
24
- return this._values[key]
25
- };
26
- Cache.prototype.set = function (key, value) {
27
- this._size >= this._maxSize && this.clear();
28
- if (!(key in this._values)) this._size++;
29
-
30
- return (this._values[key] = value)
31
- };
32
-
33
- var SPLIT_REGEX = /[^.^\]^[]+|(?=\[\]|\.\.)/g,
34
- DIGIT_REGEX = /^\d+$/,
35
- LEAD_DIGIT_REGEX = /^\d/,
36
- SPEC_CHAR_REGEX = /[~`!#$%\^&*+=\-\[\]\\';,/{}|\\":<>\?]/g,
37
- CLEAN_QUOTES_REGEX = /^\s*(['"]?)(.*?)(\1)\s*$/,
38
- MAX_CACHE_SIZE = 512;
39
-
40
- var pathCache = new Cache(MAX_CACHE_SIZE),
41
- setCache = new Cache(MAX_CACHE_SIZE),
42
- getCache = new Cache(MAX_CACHE_SIZE);
43
-
44
- var propertyExpr = {
45
- Cache: Cache,
46
-
47
- split: split,
48
-
49
- normalizePath: normalizePath,
50
-
51
- setter: function (path) {
52
- var parts = normalizePath(path);
53
-
54
- return (
55
- setCache.get(path) ||
56
- setCache.set(path, function setter(obj, value) {
57
- var index = 0;
58
- var len = parts.length;
59
- var data = obj;
60
-
61
- while (index < len - 1) {
62
- var part = parts[index];
63
- if (
64
- part === '__proto__' ||
65
- part === 'constructor' ||
66
- part === 'prototype'
67
- ) {
68
- return obj
69
- }
70
-
71
- data = data[parts[index++]];
72
- }
73
- data[parts[index]] = value;
74
- })
75
- )
76
- },
77
-
78
- getter: function (path, safe) {
79
- var parts = normalizePath(path);
80
- return (
81
- getCache.get(path) ||
82
- getCache.set(path, function getter(data) {
83
- var index = 0,
84
- len = parts.length;
85
- while (index < len) {
86
- if (data != null || !safe) data = data[parts[index++]];
87
- else return
88
- }
89
- return data
90
- })
91
- )
92
- },
93
-
94
- join: function (segments) {
95
- return segments.reduce(function (path, part) {
96
- return (
97
- path +
98
- (isQuoted(part) || DIGIT_REGEX.test(part)
99
- ? '[' + part + ']'
100
- : (path ? '.' : '') + part)
101
- )
102
- }, '')
103
- },
104
-
105
- forEach: function (path, cb, thisArg) {
106
- forEach(Array.isArray(path) ? path : split(path), cb, thisArg);
107
- },
108
- };
109
-
110
- function normalizePath(path) {
111
- return (
112
- pathCache.get(path) ||
113
- pathCache.set(
114
- path,
115
- split(path).map(function (part) {
116
- return part.replace(CLEAN_QUOTES_REGEX, '$2')
117
- })
118
- )
119
- )
120
- }
121
-
122
- function split(path) {
123
- return path.match(SPLIT_REGEX) || ['']
124
- }
125
-
126
- function forEach(parts, iter, thisArg) {
127
- var len = parts.length,
128
- part,
129
- idx,
130
- isArray,
131
- isBracket;
132
-
133
- for (idx = 0; idx < len; idx++) {
134
- part = parts[idx];
135
-
136
- if (part) {
137
- if (shouldBeQuoted(part)) {
138
- part = '"' + part + '"';
139
- }
140
-
141
- isBracket = isQuoted(part);
142
- isArray = !isBracket && /^\d+$/.test(part);
143
-
144
- iter.call(thisArg, part, isBracket, isArray, idx, parts);
145
- }
146
- }
147
- }
148
-
149
- function isQuoted(str) {
150
- return (
151
- typeof str === 'string' && str && ["'", '"'].indexOf(str.charAt(0)) !== -1
152
- )
153
- }
154
-
155
- function hasLeadingNumber(part) {
156
- return part.match(LEAD_DIGIT_REGEX) && !part.match(DIGIT_REGEX)
157
- }
158
-
159
- function hasSpecialChars(part) {
160
- return SPEC_CHAR_REGEX.test(part)
161
- }
162
-
163
- function shouldBeQuoted(part) {
164
- return !isQuoted(part) && (hasLeadingNumber(part) || hasSpecialChars(part))
165
- }
166
-
167
- const 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;
168
-
169
- const words = (str) => str.match(reWords) || [];
170
-
171
- const upperFirst = (str) => str[0].toUpperCase() + str.slice(1);
172
-
173
- const join = (str, d) => words(str).join(d).toLowerCase();
174
-
175
- const camelCase = (str) =>
176
- words(str).reduce(
177
- (acc, next) =>
178
- `${acc}${
179
- !acc
180
- ? next.toLowerCase()
181
- : next[0].toUpperCase() + next.slice(1).toLowerCase()
182
- }`,
183
- '',
184
- );
185
-
186
- const pascalCase = (str) => upperFirst(camelCase(str));
187
-
188
- const snakeCase = (str) => join(str, '_');
189
-
190
- const kebabCase = (str) => join(str, '-');
191
-
192
- const sentenceCase = (str) => upperFirst(join(str, ' '));
193
-
194
- const titleCase = (str) => words(str).map(upperFirst).join(' ');
195
-
196
- var tinyCase = {
197
- words,
198
- upperFirst,
199
- camelCase,
200
- pascalCase,
201
- snakeCase,
202
- kebabCase,
203
- sentenceCase,
204
- titleCase,
205
- };
206
-
207
- var toposort$2 = {exports: {}};
208
-
209
- /**
210
- * Topological sorting function
211
- *
212
- * @param {Array} edges
213
- * @returns {Array}
214
- */
215
-
216
- toposort$2.exports = function(edges) {
217
- return toposort(uniqueNodes(edges), edges)
218
- };
219
-
220
- toposort$2.exports.array = toposort;
221
-
222
- function toposort(nodes, edges) {
223
- var cursor = nodes.length
224
- , sorted = new Array(cursor)
225
- , visited = {}
226
- , i = cursor
227
- // Better data structures make algorithm much faster.
228
- , outgoingEdges = makeOutgoingEdges(edges)
229
- , nodesHash = makeNodesHash(nodes);
230
-
231
- // check for unknown nodes
232
- edges.forEach(function(edge) {
233
- if (!nodesHash.has(edge[0]) || !nodesHash.has(edge[1])) {
234
- throw new Error('Unknown node. There is an unknown node in the supplied edges.')
235
- }
236
- });
237
-
238
- while (i--) {
239
- if (!visited[i]) visit(nodes[i], i, new Set());
240
- }
241
-
242
- return sorted
243
-
244
- function visit(node, i, predecessors) {
245
- if(predecessors.has(node)) {
246
- var nodeRep;
247
- try {
248
- nodeRep = ", node was:" + JSON.stringify(node);
249
- } catch(e) {
250
- nodeRep = "";
251
- }
252
- throw new Error('Cyclic dependency' + nodeRep)
253
- }
254
-
255
- if (!nodesHash.has(node)) {
256
- throw new Error('Found unknown node. Make sure to provided all involved nodes. Unknown node: '+JSON.stringify(node))
257
- }
258
-
259
- if (visited[i]) return;
260
- visited[i] = true;
261
-
262
- var outgoing = outgoingEdges.get(node) || new Set();
263
- outgoing = Array.from(outgoing);
264
-
265
- if (i = outgoing.length) {
266
- predecessors.add(node);
267
- do {
268
- var child = outgoing[--i];
269
- visit(child, nodesHash.get(child), predecessors);
270
- } while (i)
271
- predecessors.delete(node);
272
- }
273
-
274
- sorted[--cursor] = node;
275
- }
276
- }
277
-
278
- function uniqueNodes(arr){
279
- var res = new Set();
280
- for (var i = 0, len = arr.length; i < len; i++) {
281
- var edge = arr[i];
282
- res.add(edge[0]);
283
- res.add(edge[1]);
284
- }
285
- return Array.from(res)
286
- }
287
-
288
- function makeOutgoingEdges(arr){
289
- var edges = new Map();
290
- for (var i = 0, len = arr.length; i < len; i++) {
291
- var edge = arr[i];
292
- if (!edges.has(edge[0])) edges.set(edge[0], new Set());
293
- if (!edges.has(edge[1])) edges.set(edge[1], new Set());
294
- edges.get(edge[0]).add(edge[1]);
295
- }
296
- return edges
297
- }
298
-
299
- function makeNodesHash(arr){
300
- var res = new Map();
301
- for (var i = 0, len = arr.length; i < len; i++) {
302
- res.set(arr[i], i);
303
- }
304
- return res
305
- }
306
-
307
- const toposort$1 = toposort$2.exports;
308
-
309
- const toString = Object.prototype.toString;
310
- const errorToString = Error.prototype.toString;
311
- const regExpToString = RegExp.prototype.toString;
312
- const symbolToString = typeof Symbol !== 'undefined' ? Symbol.prototype.toString : () => '';
313
- const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;
314
- function printNumber(val) {
315
- if (val != +val) return 'NaN';
316
- const isNegativeZero = val === 0 && 1 / val < 0;
317
- return isNegativeZero ? '-0' : '' + val;
318
- }
319
- function printSimpleValue(val, quoteStrings = false) {
320
- if (val == null || val === true || val === false) return '' + val;
321
- const typeOf = typeof val;
322
- if (typeOf === 'number') return printNumber(val);
323
- if (typeOf === 'string') return quoteStrings ? `"${val}"` : val;
324
- if (typeOf === 'function') return '[Function ' + (val.name || 'anonymous') + ']';
325
- if (typeOf === 'symbol') return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)');
326
- const tag = toString.call(val).slice(8, -1);
327
- if (tag === 'Date') return isNaN(val.getTime()) ? '' + val : val.toISOString(val);
328
- if (tag === 'Error' || val instanceof Error) return '[' + errorToString.call(val) + ']';
329
- if (tag === 'RegExp') return regExpToString.call(val);
330
- return null;
331
- }
332
- function printValue(value, quoteStrings) {
333
- let result = printSimpleValue(value, quoteStrings);
334
- if (result !== null) return result;
335
- return JSON.stringify(value, function (key, value) {
336
- let result = printSimpleValue(this[key], quoteStrings);
337
- if (result !== null) return result;
338
- return value;
339
- }, 2);
340
- }
341
-
342
- function toArray(value) {
343
- return value == null ? [] : [].concat(value);
344
- }
345
-
346
- let _Symbol$toStringTag, _Symbol$hasInstance, _Symbol$toStringTag2;
347
- let strReg = /\$\{\s*(\w+)\s*\}/g;
348
- _Symbol$toStringTag = Symbol.toStringTag;
349
- class ValidationErrorNoStack {
350
- constructor(errorOrErrors, value, field, type) {
351
- this.name = void 0;
352
- this.message = void 0;
353
- this.value = void 0;
354
- this.path = void 0;
355
- this.type = void 0;
356
- this.params = void 0;
357
- this.errors = void 0;
358
- this.inner = void 0;
359
- this[_Symbol$toStringTag] = 'Error';
360
- this.name = 'ValidationError';
361
- this.value = value;
362
- this.path = field;
363
- this.type = type;
364
- this.errors = [];
365
- this.inner = [];
366
- toArray(errorOrErrors).forEach(err => {
367
- if (ValidationError.isError(err)) {
368
- this.errors.push(...err.errors);
369
- const innerErrors = err.inner.length ? err.inner : [err];
370
- this.inner.push(...innerErrors);
371
- } else {
372
- this.errors.push(err);
373
- }
374
- });
375
- this.message = this.errors.length > 1 ? `${this.errors.length} errors occurred` : this.errors[0];
376
- }
377
- }
378
- _Symbol$hasInstance = Symbol.hasInstance;
379
- _Symbol$toStringTag2 = Symbol.toStringTag;
380
- class ValidationError extends Error {
381
- static formatError(message, params) {
382
- // Attempt to make the path more friendly for error message interpolation.
383
- const path = params.label || params.path || 'this';
384
- // Store the original path under `originalPath` so it isn't lost to custom
385
- // message functions; e.g., ones provided in `setLocale()` calls.
386
- params = Object.assign({}, params, {
387
- path,
388
- originalPath: params.path
389
- });
390
- if (typeof message === 'string') return message.replace(strReg, (_, key) => printValue(params[key]));
391
- if (typeof message === 'function') return message(params);
392
- return message;
393
- }
394
- static isError(err) {
395
- return err && err.name === 'ValidationError';
396
- }
397
- constructor(errorOrErrors, value, field, type, disableStack) {
398
- const errorNoStack = new ValidationErrorNoStack(errorOrErrors, value, field, type);
399
- if (disableStack) {
400
- return errorNoStack;
401
- }
402
- super();
403
- this.value = void 0;
404
- this.path = void 0;
405
- this.type = void 0;
406
- this.params = void 0;
407
- this.errors = [];
408
- this.inner = [];
409
- this[_Symbol$toStringTag2] = 'Error';
410
- this.name = errorNoStack.name;
411
- this.message = errorNoStack.message;
412
- this.type = errorNoStack.type;
413
- this.value = errorNoStack.value;
414
- this.path = errorNoStack.path;
415
- this.errors = errorNoStack.errors;
416
- this.inner = errorNoStack.inner;
417
- if (Error.captureStackTrace) {
418
- Error.captureStackTrace(this, ValidationError);
419
- }
420
- }
421
- static [_Symbol$hasInstance](inst) {
422
- return ValidationErrorNoStack[Symbol.hasInstance](inst) || super[Symbol.hasInstance](inst);
423
- }
424
- }
425
-
426
- let mixed = {
427
- default: '${path} is invalid',
428
- required: '${path} is a required field',
429
- defined: '${path} must be defined',
430
- notNull: '${path} cannot be null',
431
- oneOf: '${path} must be one of the following values: ${values}',
432
- notOneOf: '${path} must not be one of the following values: ${values}',
433
- notType: ({
434
- path,
435
- type,
436
- value,
437
- originalValue
438
- }) => {
439
- const castMsg = originalValue != null && originalValue !== value ? ` (cast from the value \`${printValue(originalValue, true)}\`).` : '.';
440
- 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;
441
- }
442
- };
443
- let string = {
444
- length: '${path} must be exactly ${length} characters',
445
- min: '${path} must be at least ${min} characters',
446
- max: '${path} must be at most ${max} characters',
447
- matches: '${path} must match the following: "${regex}"',
448
- email: '${path} must be a valid email',
449
- url: '${path} must be a valid URL',
450
- uuid: '${path} must be a valid UUID',
451
- datetime: '${path} must be a valid ISO date-time',
452
- datetime_precision: '${path} must be a valid ISO date-time with a sub-second precision of exactly ${precision} digits',
453
- datetime_offset: '${path} must be a valid ISO date-time with UTC "Z" timezone',
454
- trim: '${path} must be a trimmed string',
455
- lowercase: '${path} must be a lowercase string',
456
- uppercase: '${path} must be a upper case string'
457
- };
458
- let number = {
459
- min: '${path} must be greater than or equal to ${min}',
460
- max: '${path} must be less than or equal to ${max}',
461
- lessThan: '${path} must be less than ${less}',
462
- moreThan: '${path} must be greater than ${more}',
463
- positive: '${path} must be a positive number',
464
- negative: '${path} must be a negative number',
465
- integer: '${path} must be an integer'
466
- };
467
- let date = {
468
- min: '${path} field must be later than ${min}',
469
- max: '${path} field must be at earlier than ${max}'
470
- };
471
- let boolean = {
472
- isValue: '${path} field must be ${value}'
473
- };
474
- let object = {
475
- noUnknown: '${path} field has unspecified keys: ${unknown}',
476
- exact: '${path} object contains unknown properties: ${properties}'
477
- };
478
- let array = {
479
- min: '${path} field must have at least ${min} items',
480
- max: '${path} field must have less than or equal to ${max} items',
481
- length: '${path} must have ${length} items'
482
- };
483
- let tuple = {
484
- notType: params => {
485
- const {
486
- path,
487
- value,
488
- spec
489
- } = params;
490
- const typeLen = spec.types.length;
491
- if (Array.isArray(value)) {
492
- 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)}\``;
493
- 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)}\``;
494
- }
495
- return ValidationError.formatError(mixed.notType, params);
496
- }
497
- };
498
- Object.assign(Object.create(null), {
499
- mixed,
500
- string,
501
- number,
502
- date,
503
- object,
504
- array,
505
- boolean,
506
- tuple
507
- });
508
-
509
- const isSchema = obj => obj && obj.__isYupSchema__;
510
-
511
- class Condition {
512
- static fromOptions(refs, config) {
513
- if (!config.then && !config.otherwise) throw new TypeError('either `then:` or `otherwise:` is required for `when()` conditions');
514
- let {
515
- is,
516
- then,
517
- otherwise
518
- } = config;
519
- let check = typeof is === 'function' ? is : (...values) => values.every(value => value === is);
520
- return new Condition(refs, (values, schema) => {
521
- var _branch;
522
- let branch = check(...values) ? then : otherwise;
523
- return (_branch = branch == null ? void 0 : branch(schema)) != null ? _branch : schema;
524
- });
525
- }
526
- constructor(refs, builder) {
527
- this.fn = void 0;
528
- this.refs = refs;
529
- this.refs = refs;
530
- this.fn = builder;
531
- }
532
- resolve(base, options) {
533
- let values = this.refs.map(ref =>
534
- // TODO: ? operator here?
535
- ref.getValue(options == null ? void 0 : options.value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context));
536
- let schema = this.fn(values, base, options);
537
- if (schema === undefined ||
538
- // @ts-ignore this can be base
539
- schema === base) {
540
- return base;
541
- }
542
- if (!isSchema(schema)) throw new TypeError('conditions must return a schema object');
543
- return schema.resolve(options);
544
- }
545
- }
546
-
547
- const prefixes = {
548
- context: '$',
549
- value: '.'
550
- };
551
- class Reference {
552
- constructor(key, options = {}) {
553
- this.key = void 0;
554
- this.isContext = void 0;
555
- this.isValue = void 0;
556
- this.isSibling = void 0;
557
- this.path = void 0;
558
- this.getter = void 0;
559
- this.map = void 0;
560
- if (typeof key !== 'string') throw new TypeError('ref must be a string, got: ' + key);
561
- this.key = key.trim();
562
- if (key === '') throw new TypeError('ref must be a non-empty string');
563
- this.isContext = this.key[0] === prefixes.context;
564
- this.isValue = this.key[0] === prefixes.value;
565
- this.isSibling = !this.isContext && !this.isValue;
566
- let prefix = this.isContext ? prefixes.context : this.isValue ? prefixes.value : '';
567
- this.path = this.key.slice(prefix.length);
568
- this.getter = this.path && propertyExpr.getter(this.path, true);
569
- this.map = options.map;
570
- }
571
- getValue(value, parent, context) {
572
- let result = this.isContext ? context : this.isValue ? value : parent;
573
- if (this.getter) result = this.getter(result || {});
574
- if (this.map) result = this.map(result);
575
- return result;
576
- }
577
-
578
- /**
579
- *
580
- * @param {*} value
581
- * @param {Object} options
582
- * @param {Object=} options.context
583
- * @param {Object=} options.parent
584
- */
585
- cast(value, options) {
586
- return this.getValue(value, options == null ? void 0 : options.parent, options == null ? void 0 : options.context);
587
- }
588
- resolve() {
589
- return this;
590
- }
591
- describe() {
592
- return {
593
- type: 'ref',
594
- key: this.key
595
- };
596
- }
597
- toString() {
598
- return `Ref(${this.key})`;
599
- }
600
- static isRef(value) {
601
- return value && value.__isYupRef;
602
- }
603
- }
604
-
605
- // @ts-ignore
606
- Reference.prototype.__isYupRef = true;
607
-
608
- const isAbsent = value => value == null;
609
-
610
- function createValidation(config) {
611
- function validate({
612
- value,
613
- path = '',
614
- options,
615
- originalValue,
616
- schema
617
- }, panic, next) {
618
- const {
619
- name,
620
- test,
621
- params,
622
- message,
623
- skipAbsent
624
- } = config;
625
- let {
626
- parent,
627
- context,
628
- abortEarly = schema.spec.abortEarly,
629
- disableStackTrace = schema.spec.disableStackTrace
630
- } = options;
631
- function resolve(item) {
632
- return Reference.isRef(item) ? item.getValue(value, parent, context) : item;
633
- }
634
- function createError(overrides = {}) {
635
- const nextParams = Object.assign({
636
- value,
637
- originalValue,
638
- label: schema.spec.label,
639
- path: overrides.path || path,
640
- spec: schema.spec,
641
- disableStackTrace: overrides.disableStackTrace || disableStackTrace
642
- }, params, overrides.params);
643
- for (const key of Object.keys(nextParams)) nextParams[key] = resolve(nextParams[key]);
644
- const error = new ValidationError(ValidationError.formatError(overrides.message || message, nextParams), value, nextParams.path, overrides.type || name, nextParams.disableStackTrace);
645
- error.params = nextParams;
646
- return error;
647
- }
648
- const invalid = abortEarly ? panic : next;
649
- let ctx = {
650
- path,
651
- parent,
652
- type: name,
653
- from: options.from,
654
- createError,
655
- resolve,
656
- options,
657
- originalValue,
658
- schema
659
- };
660
- const handleResult = validOrError => {
661
- if (ValidationError.isError(validOrError)) invalid(validOrError);else if (!validOrError) invalid(createError());else next(null);
662
- };
663
- const handleError = err => {
664
- if (ValidationError.isError(err)) invalid(err);else panic(err);
665
- };
666
- const shouldSkip = skipAbsent && isAbsent(value);
667
- if (shouldSkip) {
668
- return handleResult(true);
669
- }
670
- let result;
671
- try {
672
- var _result;
673
- result = test.call(ctx, value, ctx);
674
- if (typeof ((_result = result) == null ? void 0 : _result.then) === 'function') {
675
- if (options.sync) {
676
- 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`);
677
- }
678
- return Promise.resolve(result).then(handleResult, handleError);
679
- }
680
- } catch (err) {
681
- handleError(err);
682
- return;
683
- }
684
- handleResult(result);
685
- }
686
- validate.OPTIONS = config;
687
- return validate;
688
- }
689
-
690
- function getIn(schema, path, value, context = value) {
691
- let parent, lastPart, lastPartDebug;
692
-
693
- // root path: ''
694
- if (!path) return {
695
- parent,
696
- parentPath: path,
697
- schema
698
- };
699
- propertyExpr.forEach(path, (_part, isBracket, isArray) => {
700
- let part = isBracket ? _part.slice(1, _part.length - 1) : _part;
701
- schema = schema.resolve({
702
- context,
703
- parent,
704
- value
705
- });
706
- let isTuple = schema.type === 'tuple';
707
- let idx = isArray ? parseInt(part, 10) : 0;
708
- if (schema.innerType || isTuple) {
709
- 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]"`);
710
- if (value && idx >= value.length) {
711
- 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. `);
712
- }
713
- parent = value;
714
- value = value && value[idx];
715
- schema = isTuple ? schema.spec.types[idx] : schema.innerType;
716
- }
717
-
718
- // sometimes the array index part of a path doesn't exist: "nested.arr.child"
719
- // in these cases the current part is the next schema and should be processed
720
- // in this iteration. For cases where the index signature is included this
721
- // check will fail and we'll handle the `child` part on the next iteration like normal
722
- if (!isArray) {
723
- 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}")`);
724
- parent = value;
725
- value = value && value[part];
726
- schema = schema.fields[part];
727
- }
728
- lastPart = part;
729
- lastPartDebug = isBracket ? '[' + _part + ']' : '.' + _part;
730
- });
731
- return {
732
- schema,
733
- parent,
734
- parentPath: lastPart
735
- };
736
- }
737
-
738
- class ReferenceSet extends Set {
739
- describe() {
740
- const description = [];
741
- for (const item of this.values()) {
742
- description.push(Reference.isRef(item) ? item.describe() : item);
743
- }
744
- return description;
745
- }
746
- resolveAll(resolve) {
747
- let result = [];
748
- for (const item of this.values()) {
749
- result.push(resolve(item));
750
- }
751
- return result;
752
- }
753
- clone() {
754
- return new ReferenceSet(this.values());
755
- }
756
- merge(newItems, removeItems) {
757
- const next = this.clone();
758
- newItems.forEach(value => next.add(value));
759
- removeItems.forEach(value => next.delete(value));
760
- return next;
761
- }
762
- }
763
-
764
- // tweaked from https://github.com/Kelin2025/nanoclone/blob/0abeb7635bda9b68ef2277093f76dbe3bf3948e1/src/index.js
765
- function clone(src, seen = new Map()) {
766
- if (isSchema(src) || !src || typeof src !== 'object') return src;
767
- if (seen.has(src)) return seen.get(src);
768
- let copy;
769
- if (src instanceof Date) {
770
- // Date
771
- copy = new Date(src.getTime());
772
- seen.set(src, copy);
773
- } else if (src instanceof RegExp) {
774
- // RegExp
775
- copy = new RegExp(src);
776
- seen.set(src, copy);
777
- } else if (Array.isArray(src)) {
778
- // Array
779
- copy = new Array(src.length);
780
- seen.set(src, copy);
781
- for (let i = 0; i < src.length; i++) copy[i] = clone(src[i], seen);
782
- } else if (src instanceof Map) {
783
- // Map
784
- copy = new Map();
785
- seen.set(src, copy);
786
- for (const [k, v] of src.entries()) copy.set(k, clone(v, seen));
787
- } else if (src instanceof Set) {
788
- // Set
789
- copy = new Set();
790
- seen.set(src, copy);
791
- for (const v of src) copy.add(clone(v, seen));
792
- } else if (src instanceof Object) {
793
- // Object
794
- copy = {};
795
- seen.set(src, copy);
796
- for (const [k, v] of Object.entries(src)) copy[k] = clone(v, seen);
797
- } else {
798
- throw Error(`Unable to clone ${src}`);
799
- }
800
- return copy;
801
- }
802
-
803
- // If `CustomSchemaMeta` isn't extended with any keys, we'll fall back to a
804
- // loose Record definition allowing free form usage.
805
- class Schema {
806
- constructor(options) {
807
- this.type = void 0;
808
- this.deps = [];
809
- this.tests = void 0;
810
- this.transforms = void 0;
811
- this.conditions = [];
812
- this._mutate = void 0;
813
- this.internalTests = {};
814
- this._whitelist = new ReferenceSet();
815
- this._blacklist = new ReferenceSet();
816
- this.exclusiveTests = Object.create(null);
817
- this._typeCheck = void 0;
818
- this.spec = void 0;
819
- this.tests = [];
820
- this.transforms = [];
821
- this.withMutation(() => {
822
- this.typeError(mixed.notType);
823
- });
824
- this.type = options.type;
825
- this._typeCheck = options.check;
826
- this.spec = Object.assign({
827
- strip: false,
828
- strict: false,
829
- abortEarly: true,
830
- recursive: true,
831
- disableStackTrace: false,
832
- nullable: false,
833
- optional: true,
834
- coerce: true
835
- }, options == null ? void 0 : options.spec);
836
- this.withMutation(s => {
837
- s.nonNullable();
838
- });
839
- }
840
-
841
- // TODO: remove
842
- get _type() {
843
- return this.type;
844
- }
845
- clone(spec) {
846
- if (this._mutate) {
847
- if (spec) Object.assign(this.spec, spec);
848
- return this;
849
- }
850
-
851
- // if the nested value is a schema we can skip cloning, since
852
- // they are already immutable
853
- const next = Object.create(Object.getPrototypeOf(this));
854
-
855
- // @ts-expect-error this is readonly
856
- next.type = this.type;
857
- next._typeCheck = this._typeCheck;
858
- next._whitelist = this._whitelist.clone();
859
- next._blacklist = this._blacklist.clone();
860
- next.internalTests = Object.assign({}, this.internalTests);
861
- next.exclusiveTests = Object.assign({}, this.exclusiveTests);
862
-
863
- // @ts-expect-error this is readonly
864
- next.deps = [...this.deps];
865
- next.conditions = [...this.conditions];
866
- next.tests = [...this.tests];
867
- next.transforms = [...this.transforms];
868
- next.spec = clone(Object.assign({}, this.spec, spec));
869
- return next;
870
- }
871
- label(label) {
872
- let next = this.clone();
873
- next.spec.label = label;
874
- return next;
875
- }
876
- meta(...args) {
877
- if (args.length === 0) return this.spec.meta;
878
- let next = this.clone();
879
- next.spec.meta = Object.assign(next.spec.meta || {}, args[0]);
880
- return next;
881
- }
882
- withMutation(fn) {
883
- let before = this._mutate;
884
- this._mutate = true;
885
- let result = fn(this);
886
- this._mutate = before;
887
- return result;
888
- }
889
- concat(schema) {
890
- if (!schema || schema === this) return this;
891
- if (schema.type !== this.type && this.type !== 'mixed') throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${schema.type}`);
892
- let base = this;
893
- let combined = schema.clone();
894
- const mergedSpec = Object.assign({}, base.spec, combined.spec);
895
- combined.spec = mergedSpec;
896
- combined.internalTests = Object.assign({}, base.internalTests, combined.internalTests);
897
-
898
- // manually merge the blacklist/whitelist (the other `schema` takes
899
- // precedence in case of conflicts)
900
- combined._whitelist = base._whitelist.merge(schema._whitelist, schema._blacklist);
901
- combined._blacklist = base._blacklist.merge(schema._blacklist, schema._whitelist);
902
-
903
- // start with the current tests
904
- combined.tests = base.tests;
905
- combined.exclusiveTests = base.exclusiveTests;
906
-
907
- // manually add the new tests to ensure
908
- // the deduping logic is consistent
909
- combined.withMutation(next => {
910
- schema.tests.forEach(fn => {
911
- next.test(fn.OPTIONS);
912
- });
913
- });
914
- combined.transforms = [...base.transforms, ...combined.transforms];
915
- return combined;
916
- }
917
- isType(v) {
918
- if (v == null) {
919
- if (this.spec.nullable && v === null) return true;
920
- if (this.spec.optional && v === undefined) return true;
921
- return false;
922
- }
923
- return this._typeCheck(v);
924
- }
925
- resolve(options) {
926
- let schema = this;
927
- if (schema.conditions.length) {
928
- let conditions = schema.conditions;
929
- schema = schema.clone();
930
- schema.conditions = [];
931
- schema = conditions.reduce((prevSchema, condition) => condition.resolve(prevSchema, options), schema);
932
- schema = schema.resolve(options);
933
- }
934
- return schema;
935
- }
936
- resolveOptions(options) {
937
- var _options$strict, _options$abortEarly, _options$recursive, _options$disableStack;
938
- return Object.assign({}, options, {
939
- from: options.from || [],
940
- strict: (_options$strict = options.strict) != null ? _options$strict : this.spec.strict,
941
- abortEarly: (_options$abortEarly = options.abortEarly) != null ? _options$abortEarly : this.spec.abortEarly,
942
- recursive: (_options$recursive = options.recursive) != null ? _options$recursive : this.spec.recursive,
943
- disableStackTrace: (_options$disableStack = options.disableStackTrace) != null ? _options$disableStack : this.spec.disableStackTrace
944
- });
945
- }
946
-
947
- /**
948
- * Run the configured transform pipeline over an input value.
949
- */
950
-
951
- cast(value, options = {}) {
952
- let resolvedSchema = this.resolve(Object.assign({
953
- value
954
- }, options));
955
- let allowOptionality = options.assert === 'ignore-optionality';
956
- let result = resolvedSchema._cast(value, options);
957
- if (options.assert !== false && !resolvedSchema.isType(result)) {
958
- if (allowOptionality && isAbsent(result)) {
959
- return result;
960
- }
961
- let formattedValue = printValue(value);
962
- let formattedResult = printValue(result);
963
- throw new TypeError(`The value of ${options.path || 'field'} could not be cast to a value ` + `that satisfies the schema type: "${resolvedSchema.type}". \n\n` + `attempted value: ${formattedValue} \n` + (formattedResult !== formattedValue ? `result of cast: ${formattedResult}` : ''));
964
- }
965
- return result;
966
- }
967
- _cast(rawValue, options) {
968
- let value = rawValue === undefined ? rawValue : this.transforms.reduce((prevValue, fn) => fn.call(this, prevValue, rawValue, this), rawValue);
969
- if (value === undefined) {
970
- value = this.getDefault(options);
971
- }
972
- return value;
973
- }
974
- _validate(_value, options = {}, panic, next) {
975
- let {
976
- path,
977
- originalValue = _value,
978
- strict = this.spec.strict
979
- } = options;
980
- let value = _value;
981
- if (!strict) {
982
- value = this._cast(value, Object.assign({
983
- assert: false
984
- }, options));
985
- }
986
- let initialTests = [];
987
- for (let test of Object.values(this.internalTests)) {
988
- if (test) initialTests.push(test);
989
- }
990
- this.runTests({
991
- path,
992
- value,
993
- originalValue,
994
- options,
995
- tests: initialTests
996
- }, panic, initialErrors => {
997
- // even if we aren't ending early we can't proceed further if the types aren't correct
998
- if (initialErrors.length) {
999
- return next(initialErrors, value);
1000
- }
1001
- this.runTests({
1002
- path,
1003
- value,
1004
- originalValue,
1005
- options,
1006
- tests: this.tests
1007
- }, panic, next);
1008
- });
1009
- }
1010
-
1011
- /**
1012
- * Executes a set of validations, either schema, produced Tests or a nested
1013
- * schema validate result.
1014
- */
1015
- runTests(runOptions, panic, next) {
1016
- let fired = false;
1017
- let {
1018
- tests,
1019
- value,
1020
- originalValue,
1021
- path,
1022
- options
1023
- } = runOptions;
1024
- let panicOnce = arg => {
1025
- if (fired) return;
1026
- fired = true;
1027
- panic(arg, value);
1028
- };
1029
- let nextOnce = arg => {
1030
- if (fired) return;
1031
- fired = true;
1032
- next(arg, value);
1033
- };
1034
- let count = tests.length;
1035
- let nestedErrors = [];
1036
- if (!count) return nextOnce([]);
1037
- let args = {
1038
- value,
1039
- originalValue,
1040
- path,
1041
- options,
1042
- schema: this
1043
- };
1044
- for (let i = 0; i < tests.length; i++) {
1045
- const test = tests[i];
1046
- test(args, panicOnce, function finishTestRun(err) {
1047
- if (err) {
1048
- Array.isArray(err) ? nestedErrors.push(...err) : nestedErrors.push(err);
1049
- }
1050
- if (--count <= 0) {
1051
- nextOnce(nestedErrors);
1052
- }
1053
- });
1054
- }
1055
- }
1056
- asNestedTest({
1057
- key,
1058
- index,
1059
- parent,
1060
- parentPath,
1061
- originalParent,
1062
- options
1063
- }) {
1064
- const k = key != null ? key : index;
1065
- if (k == null) {
1066
- throw TypeError('Must include `key` or `index` for nested validations');
1067
- }
1068
- const isIndex = typeof k === 'number';
1069
- let value = parent[k];
1070
- const testOptions = Object.assign({}, options, {
1071
- // Nested validations fields are always strict:
1072
- // 1. parent isn't strict so the casting will also have cast inner values
1073
- // 2. parent is strict in which case the nested values weren't cast either
1074
- strict: true,
1075
- parent,
1076
- value,
1077
- originalValue: originalParent[k],
1078
- // FIXME: tests depend on `index` being passed around deeply,
1079
- // we should not let the options.key/index bleed through
1080
- key: undefined,
1081
- // index: undefined,
1082
- [isIndex ? 'index' : 'key']: k,
1083
- path: isIndex || k.includes('.') ? `${parentPath || ''}[${isIndex ? k : `"${k}"`}]` : (parentPath ? `${parentPath}.` : '') + key
1084
- });
1085
- return (_, panic, next) => this.resolve(testOptions)._validate(value, testOptions, panic, next);
1086
- }
1087
- validate(value, options) {
1088
- var _options$disableStack2;
1089
- let schema = this.resolve(Object.assign({}, options, {
1090
- value
1091
- }));
1092
- let disableStackTrace = (_options$disableStack2 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack2 : schema.spec.disableStackTrace;
1093
- return new Promise((resolve, reject) => schema._validate(value, options, (error, parsed) => {
1094
- if (ValidationError.isError(error)) error.value = parsed;
1095
- reject(error);
1096
- }, (errors, validated) => {
1097
- if (errors.length) reject(new ValidationError(errors, validated, undefined, undefined, disableStackTrace));else resolve(validated);
1098
- }));
1099
- }
1100
- validateSync(value, options) {
1101
- var _options$disableStack3;
1102
- let schema = this.resolve(Object.assign({}, options, {
1103
- value
1104
- }));
1105
- let result;
1106
- let disableStackTrace = (_options$disableStack3 = options == null ? void 0 : options.disableStackTrace) != null ? _options$disableStack3 : schema.spec.disableStackTrace;
1107
- schema._validate(value, Object.assign({}, options, {
1108
- sync: true
1109
- }), (error, parsed) => {
1110
- if (ValidationError.isError(error)) error.value = parsed;
1111
- throw error;
1112
- }, (errors, validated) => {
1113
- if (errors.length) throw new ValidationError(errors, value, undefined, undefined, disableStackTrace);
1114
- result = validated;
1115
- });
1116
- return result;
1117
- }
1118
- isValid(value, options) {
1119
- return this.validate(value, options).then(() => true, err => {
1120
- if (ValidationError.isError(err)) return false;
1121
- throw err;
1122
- });
1123
- }
1124
- isValidSync(value, options) {
1125
- try {
1126
- this.validateSync(value, options);
1127
- return true;
1128
- } catch (err) {
1129
- if (ValidationError.isError(err)) return false;
1130
- throw err;
1131
- }
1132
- }
1133
- _getDefault(options) {
1134
- let defaultValue = this.spec.default;
1135
- if (defaultValue == null) {
1136
- return defaultValue;
1137
- }
1138
- return typeof defaultValue === 'function' ? defaultValue.call(this, options) : clone(defaultValue);
1139
- }
1140
- getDefault(options
1141
- // If schema is defaulted we know it's at least not undefined
1142
- ) {
1143
- let schema = this.resolve(options || {});
1144
- return schema._getDefault(options);
1145
- }
1146
- default(def) {
1147
- if (arguments.length === 0) {
1148
- return this._getDefault();
1149
- }
1150
- let next = this.clone({
1151
- default: def
1152
- });
1153
- return next;
1154
- }
1155
- strict(isStrict = true) {
1156
- return this.clone({
1157
- strict: isStrict
1158
- });
1159
- }
1160
- nullability(nullable, message) {
1161
- const next = this.clone({
1162
- nullable
1163
- });
1164
- next.internalTests.nullable = createValidation({
1165
- message,
1166
- name: 'nullable',
1167
- test(value) {
1168
- return value === null ? this.schema.spec.nullable : true;
1169
- }
1170
- });
1171
- return next;
1172
- }
1173
- optionality(optional, message) {
1174
- const next = this.clone({
1175
- optional
1176
- });
1177
- next.internalTests.optionality = createValidation({
1178
- message,
1179
- name: 'optionality',
1180
- test(value) {
1181
- return value === undefined ? this.schema.spec.optional : true;
1182
- }
1183
- });
1184
- return next;
1185
- }
1186
- optional() {
1187
- return this.optionality(true);
1188
- }
1189
- defined(message = mixed.defined) {
1190
- return this.optionality(false, message);
1191
- }
1192
- nullable() {
1193
- return this.nullability(true);
1194
- }
1195
- nonNullable(message = mixed.notNull) {
1196
- return this.nullability(false, message);
1197
- }
1198
- required(message = mixed.required) {
1199
- return this.clone().withMutation(next => next.nonNullable(message).defined(message));
1200
- }
1201
- notRequired() {
1202
- return this.clone().withMutation(next => next.nullable().optional());
1203
- }
1204
- transform(fn) {
1205
- let next = this.clone();
1206
- next.transforms.push(fn);
1207
- return next;
1208
- }
1209
-
1210
- /**
1211
- * Adds a test function to the schema's queue of tests.
1212
- * tests can be exclusive or non-exclusive.
1213
- *
1214
- * - exclusive tests, will replace any existing tests of the same name.
1215
- * - non-exclusive: can be stacked
1216
- *
1217
- * If a non-exclusive test is added to a schema with an exclusive test of the same name
1218
- * the exclusive test is removed and further tests of the same name will be stacked.
1219
- *
1220
- * If an exclusive test is added to a schema with non-exclusive tests of the same name
1221
- * the previous tests are removed and further tests of the same name will replace each other.
1222
- */
1223
-
1224
- test(...args) {
1225
- let opts;
1226
- if (args.length === 1) {
1227
- if (typeof args[0] === 'function') {
1228
- opts = {
1229
- test: args[0]
1230
- };
1231
- } else {
1232
- opts = args[0];
1233
- }
1234
- } else if (args.length === 2) {
1235
- opts = {
1236
- name: args[0],
1237
- test: args[1]
1238
- };
1239
- } else {
1240
- opts = {
1241
- name: args[0],
1242
- message: args[1],
1243
- test: args[2]
1244
- };
1245
- }
1246
- if (opts.message === undefined) opts.message = mixed.default;
1247
- if (typeof opts.test !== 'function') throw new TypeError('`test` is a required parameters');
1248
- let next = this.clone();
1249
- let validate = createValidation(opts);
1250
- let isExclusive = opts.exclusive || opts.name && next.exclusiveTests[opts.name] === true;
1251
- if (opts.exclusive) {
1252
- if (!opts.name) throw new TypeError('Exclusive tests must provide a unique `name` identifying the test');
1253
- }
1254
- if (opts.name) next.exclusiveTests[opts.name] = !!opts.exclusive;
1255
- next.tests = next.tests.filter(fn => {
1256
- if (fn.OPTIONS.name === opts.name) {
1257
- if (isExclusive) return false;
1258
- if (fn.OPTIONS.test === validate.OPTIONS.test) return false;
1259
- }
1260
- return true;
1261
- });
1262
- next.tests.push(validate);
1263
- return next;
1264
- }
1265
- when(keys, options) {
1266
- if (!Array.isArray(keys) && typeof keys !== 'string') {
1267
- options = keys;
1268
- keys = '.';
1269
- }
1270
- let next = this.clone();
1271
- let deps = toArray(keys).map(key => new Reference(key));
1272
- deps.forEach(dep => {
1273
- // @ts-ignore readonly array
1274
- if (dep.isSibling) next.deps.push(dep.key);
1275
- });
1276
- next.conditions.push(typeof options === 'function' ? new Condition(deps, options) : Condition.fromOptions(deps, options));
1277
- return next;
1278
- }
1279
- typeError(message) {
1280
- let next = this.clone();
1281
- next.internalTests.typeError = createValidation({
1282
- message,
1283
- name: 'typeError',
1284
- skipAbsent: true,
1285
- test(value) {
1286
- if (!this.schema._typeCheck(value)) return this.createError({
1287
- params: {
1288
- type: this.schema.type
1289
- }
1290
- });
1291
- return true;
1292
- }
1293
- });
1294
- return next;
1295
- }
1296
- oneOf(enums, message = mixed.oneOf) {
1297
- let next = this.clone();
1298
- enums.forEach(val => {
1299
- next._whitelist.add(val);
1300
- next._blacklist.delete(val);
1301
- });
1302
- next.internalTests.whiteList = createValidation({
1303
- message,
1304
- name: 'oneOf',
1305
- skipAbsent: true,
1306
- test(value) {
1307
- let valids = this.schema._whitelist;
1308
- let resolved = valids.resolveAll(this.resolve);
1309
- return resolved.includes(value) ? true : this.createError({
1310
- params: {
1311
- values: Array.from(valids).join(', '),
1312
- resolved
1313
- }
1314
- });
1315
- }
1316
- });
1317
- return next;
1318
- }
1319
- notOneOf(enums, message = mixed.notOneOf) {
1320
- let next = this.clone();
1321
- enums.forEach(val => {
1322
- next._blacklist.add(val);
1323
- next._whitelist.delete(val);
1324
- });
1325
- next.internalTests.blacklist = createValidation({
1326
- message,
1327
- name: 'notOneOf',
1328
- test(value) {
1329
- let invalids = this.schema._blacklist;
1330
- let resolved = invalids.resolveAll(this.resolve);
1331
- if (resolved.includes(value)) return this.createError({
1332
- params: {
1333
- values: Array.from(invalids).join(', '),
1334
- resolved
1335
- }
1336
- });
1337
- return true;
1338
- }
1339
- });
1340
- return next;
1341
- }
1342
- strip(strip = true) {
1343
- let next = this.clone();
1344
- next.spec.strip = strip;
1345
- return next;
1346
- }
1347
-
1348
- /**
1349
- * Return a serialized description of the schema including validations, flags, types etc.
1350
- *
1351
- * @param options Provide any needed context for resolving runtime schema alterations (lazy, when conditions, etc).
1352
- */
1353
- describe(options) {
1354
- const next = (options ? this.resolve(options) : this).clone();
1355
- const {
1356
- label,
1357
- meta,
1358
- optional,
1359
- nullable
1360
- } = next.spec;
1361
- const description = {
1362
- meta,
1363
- label,
1364
- optional,
1365
- nullable,
1366
- default: next.getDefault(options),
1367
- type: next.type,
1368
- oneOf: next._whitelist.describe(),
1369
- notOneOf: next._blacklist.describe(),
1370
- tests: next.tests.map(fn => ({
1371
- name: fn.OPTIONS.name,
1372
- params: fn.OPTIONS.params
1373
- })).filter((n, idx, list) => list.findIndex(c => c.name === n.name) === idx)
1374
- };
1375
- return description;
1376
- }
1377
- }
1378
- // @ts-expect-error
1379
- Schema.prototype.__isYupSchema__ = true;
1380
- for (const method of ['validate', 'validateSync']) Schema.prototype[`${method}At`] = function (path, value, options = {}) {
1381
- const {
1382
- parent,
1383
- parentPath,
1384
- schema
1385
- } = getIn(this, path, value, options.context);
1386
- return schema[method](parent && parent[parentPath], Object.assign({}, options, {
1387
- parent,
1388
- path
1389
- }));
1390
- };
1391
- for (const alias of ['equals', 'is']) Schema.prototype[alias] = Schema.prototype.oneOf;
1392
- for (const alias of ['not', 'nope']) Schema.prototype[alias] = Schema.prototype.notOneOf;
1393
-
1394
- /**
1395
- * This file is a modified version of the file from the following repository:
1396
- * Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
1397
- * NON-CONFORMANT EDITION.
1398
- * © 2011 Colin Snover <http://zetafleet.com>
1399
- * Released under MIT license.
1400
- */
1401
-
1402
- // prettier-ignore
1403
- // 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
1404
- const isoReg = /^(\d{4}|[+-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,.](\d{1,}))?)?(?:(Z)|([+-])(\d{2})(?::?(\d{2}))?)?)?$/;
1405
- function parseIsoDate(date) {
1406
- const struct = parseDateStruct(date);
1407
- if (!struct) return Date.parse ? Date.parse(date) : Number.NaN;
1408
-
1409
- // timestamps without timezone identifiers should be considered local time
1410
- if (struct.z === undefined && struct.plusMinus === undefined) {
1411
- return new Date(struct.year, struct.month, struct.day, struct.hour, struct.minute, struct.second, struct.millisecond).valueOf();
1412
- }
1413
- let totalMinutesOffset = 0;
1414
- if (struct.z !== 'Z' && struct.plusMinus !== undefined) {
1415
- totalMinutesOffset = struct.hourOffset * 60 + struct.minuteOffset;
1416
- if (struct.plusMinus === '+') totalMinutesOffset = 0 - totalMinutesOffset;
1417
- }
1418
- return Date.UTC(struct.year, struct.month, struct.day, struct.hour, struct.minute + totalMinutesOffset, struct.second, struct.millisecond);
1419
- }
1420
- function parseDateStruct(date) {
1421
- var _regexResult$7$length, _regexResult$;
1422
- const regexResult = isoReg.exec(date);
1423
- if (!regexResult) return null;
1424
-
1425
- // use of toNumber() avoids NaN timestamps caused by “undefined”
1426
- // values being passed to Date constructor
1427
- return {
1428
- year: toNumber(regexResult[1]),
1429
- month: toNumber(regexResult[2], 1) - 1,
1430
- day: toNumber(regexResult[3], 1),
1431
- hour: toNumber(regexResult[4]),
1432
- minute: toNumber(regexResult[5]),
1433
- second: toNumber(regexResult[6]),
1434
- millisecond: regexResult[7] ?
1435
- // allow arbitrary sub-second precision beyond milliseconds
1436
- toNumber(regexResult[7].substring(0, 3)) : 0,
1437
- precision: (_regexResult$7$length = (_regexResult$ = regexResult[7]) == null ? void 0 : _regexResult$.length) != null ? _regexResult$7$length : undefined,
1438
- z: regexResult[8] || undefined,
1439
- plusMinus: regexResult[9] || undefined,
1440
- hourOffset: toNumber(regexResult[10]),
1441
- minuteOffset: toNumber(regexResult[11])
1442
- };
1443
- }
1444
- function toNumber(str, defaultValue = 0) {
1445
- return Number(str) || defaultValue;
1446
- }
1447
-
1448
- // Taken from HTML spec: https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address
1449
- let rEmail =
1450
- // eslint-disable-next-line
1451
- /^[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])?)*$/;
1452
- let rUrl =
1453
- // eslint-disable-next-line
1454
- /^((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;
1455
-
1456
- // eslint-disable-next-line
1457
- let 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;
1458
- let yearMonthDay = '^\\d{4}-\\d{2}-\\d{2}';
1459
- let hourMinuteSecond = '\\d{2}:\\d{2}:\\d{2}';
1460
- let zOrOffset = '(([+-]\\d{2}(:?\\d{2})?)|Z)';
1461
- let rIsoDateTime = new RegExp(`${yearMonthDay}T${hourMinuteSecond}(\\.\\d+)?${zOrOffset}$`);
1462
- let isTrimmed = value => isAbsent(value) || value === value.trim();
1463
- let objStringTag = {}.toString();
1464
- function create$6() {
1465
- return new StringSchema();
1466
- }
1467
- class StringSchema extends Schema {
1468
- constructor() {
1469
- super({
1470
- type: 'string',
1471
- check(value) {
1472
- if (value instanceof String) value = value.valueOf();
1473
- return typeof value === 'string';
1474
- }
1475
- });
1476
- this.withMutation(() => {
1477
- this.transform((value, _raw, ctx) => {
1478
- if (!ctx.spec.coerce || ctx.isType(value)) return value;
1479
-
1480
- // don't ever convert arrays
1481
- if (Array.isArray(value)) return value;
1482
- const strValue = value != null && value.toString ? value.toString() : value;
1483
-
1484
- // no one wants plain objects converted to [Object object]
1485
- if (strValue === objStringTag) return value;
1486
- return strValue;
1487
- });
1488
- });
1489
- }
1490
- required(message) {
1491
- return super.required(message).withMutation(schema => schema.test({
1492
- message: message || mixed.required,
1493
- name: 'required',
1494
- skipAbsent: true,
1495
- test: value => !!value.length
1496
- }));
1497
- }
1498
- notRequired() {
1499
- return super.notRequired().withMutation(schema => {
1500
- schema.tests = schema.tests.filter(t => t.OPTIONS.name !== 'required');
1501
- return schema;
1502
- });
1503
- }
1504
- length(length, message = string.length) {
1505
- return this.test({
1506
- message,
1507
- name: 'length',
1508
- exclusive: true,
1509
- params: {
1510
- length
1511
- },
1512
- skipAbsent: true,
1513
- test(value) {
1514
- return value.length === this.resolve(length);
1515
- }
1516
- });
1517
- }
1518
- min(min, message = string.min) {
1519
- return this.test({
1520
- message,
1521
- name: 'min',
1522
- exclusive: true,
1523
- params: {
1524
- min
1525
- },
1526
- skipAbsent: true,
1527
- test(value) {
1528
- return value.length >= this.resolve(min);
1529
- }
1530
- });
1531
- }
1532
- max(max, message = string.max) {
1533
- return this.test({
1534
- name: 'max',
1535
- exclusive: true,
1536
- message,
1537
- params: {
1538
- max
1539
- },
1540
- skipAbsent: true,
1541
- test(value) {
1542
- return value.length <= this.resolve(max);
1543
- }
1544
- });
1545
- }
1546
- matches(regex, options) {
1547
- let excludeEmptyString = false;
1548
- let message;
1549
- let name;
1550
- if (options) {
1551
- if (typeof options === 'object') {
1552
- ({
1553
- excludeEmptyString = false,
1554
- message,
1555
- name
1556
- } = options);
1557
- } else {
1558
- message = options;
1559
- }
1560
- }
1561
- return this.test({
1562
- name: name || 'matches',
1563
- message: message || string.matches,
1564
- params: {
1565
- regex
1566
- },
1567
- skipAbsent: true,
1568
- test: value => value === '' && excludeEmptyString || value.search(regex) !== -1
1569
- });
1570
- }
1571
- email(message = string.email) {
1572
- return this.matches(rEmail, {
1573
- name: 'email',
1574
- message,
1575
- excludeEmptyString: true
1576
- });
1577
- }
1578
- url(message = string.url) {
1579
- return this.matches(rUrl, {
1580
- name: 'url',
1581
- message,
1582
- excludeEmptyString: true
1583
- });
1584
- }
1585
- uuid(message = string.uuid) {
1586
- return this.matches(rUUID, {
1587
- name: 'uuid',
1588
- message,
1589
- excludeEmptyString: false
1590
- });
1591
- }
1592
- datetime(options) {
1593
- let message = '';
1594
- let allowOffset;
1595
- let precision;
1596
- if (options) {
1597
- if (typeof options === 'object') {
1598
- ({
1599
- message = '',
1600
- allowOffset = false,
1601
- precision = undefined
1602
- } = options);
1603
- } else {
1604
- message = options;
1605
- }
1606
- }
1607
- return this.matches(rIsoDateTime, {
1608
- name: 'datetime',
1609
- message: message || string.datetime,
1610
- excludeEmptyString: true
1611
- }).test({
1612
- name: 'datetime_offset',
1613
- message: message || string.datetime_offset,
1614
- params: {
1615
- allowOffset
1616
- },
1617
- skipAbsent: true,
1618
- test: value => {
1619
- if (!value || allowOffset) return true;
1620
- const struct = parseDateStruct(value);
1621
- if (!struct) return false;
1622
- return !!struct.z;
1623
- }
1624
- }).test({
1625
- name: 'datetime_precision',
1626
- message: message || string.datetime_precision,
1627
- params: {
1628
- precision
1629
- },
1630
- skipAbsent: true,
1631
- test: value => {
1632
- if (!value || precision == undefined) return true;
1633
- const struct = parseDateStruct(value);
1634
- if (!struct) return false;
1635
- return struct.precision === precision;
1636
- }
1637
- });
1638
- }
1639
-
1640
- //-- transforms --
1641
- ensure() {
1642
- return this.default('').transform(val => val === null ? '' : val);
1643
- }
1644
- trim(message = string.trim) {
1645
- return this.transform(val => val != null ? val.trim() : val).test({
1646
- message,
1647
- name: 'trim',
1648
- test: isTrimmed
1649
- });
1650
- }
1651
- lowercase(message = string.lowercase) {
1652
- return this.transform(value => !isAbsent(value) ? value.toLowerCase() : value).test({
1653
- message,
1654
- name: 'string_case',
1655
- exclusive: true,
1656
- skipAbsent: true,
1657
- test: value => isAbsent(value) || value === value.toLowerCase()
1658
- });
1659
- }
1660
- uppercase(message = string.uppercase) {
1661
- return this.transform(value => !isAbsent(value) ? value.toUpperCase() : value).test({
1662
- message,
1663
- name: 'string_case',
1664
- exclusive: true,
1665
- skipAbsent: true,
1666
- test: value => isAbsent(value) || value === value.toUpperCase()
1667
- });
1668
- }
1669
- }
1670
- create$6.prototype = StringSchema.prototype;
1671
-
1672
- //
1673
- // Number Interfaces
1674
- //
1675
-
1676
- let invalidDate = new Date('');
1677
- let isDate = obj => Object.prototype.toString.call(obj) === '[object Date]';
1678
- class DateSchema extends Schema {
1679
- constructor() {
1680
- super({
1681
- type: 'date',
1682
- check(v) {
1683
- return isDate(v) && !isNaN(v.getTime());
1684
- }
1685
- });
1686
- this.withMutation(() => {
1687
- this.transform((value, _raw, ctx) => {
1688
- // null -> InvalidDate isn't useful; treat all nulls as null and let it fail on
1689
- // nullability check vs TypeErrors
1690
- if (!ctx.spec.coerce || ctx.isType(value) || value === null) return value;
1691
- value = parseIsoDate(value);
1692
-
1693
- // 0 is a valid timestamp equivalent to 1970-01-01T00:00:00Z(unix epoch) or before.
1694
- return !isNaN(value) ? new Date(value) : DateSchema.INVALID_DATE;
1695
- });
1696
- });
1697
- }
1698
- prepareParam(ref, name) {
1699
- let param;
1700
- if (!Reference.isRef(ref)) {
1701
- let cast = this.cast(ref);
1702
- if (!this._typeCheck(cast)) throw new TypeError(`\`${name}\` must be a Date or a value that can be \`cast()\` to a Date`);
1703
- param = cast;
1704
- } else {
1705
- param = ref;
1706
- }
1707
- return param;
1708
- }
1709
- min(min, message = date.min) {
1710
- let limit = this.prepareParam(min, 'min');
1711
- return this.test({
1712
- message,
1713
- name: 'min',
1714
- exclusive: true,
1715
- params: {
1716
- min
1717
- },
1718
- skipAbsent: true,
1719
- test(value) {
1720
- return value >= this.resolve(limit);
1721
- }
1722
- });
1723
- }
1724
- max(max, message = date.max) {
1725
- let limit = this.prepareParam(max, 'max');
1726
- return this.test({
1727
- message,
1728
- name: 'max',
1729
- exclusive: true,
1730
- params: {
1731
- max
1732
- },
1733
- skipAbsent: true,
1734
- test(value) {
1735
- return value <= this.resolve(limit);
1736
- }
1737
- });
1738
- }
1739
- }
1740
- DateSchema.INVALID_DATE = invalidDate;
1741
-
1742
- // @ts-expect-error
1743
- function sortFields(fields, excludedEdges = []) {
1744
- let edges = [];
1745
- let nodes = new Set();
1746
- let excludes = new Set(excludedEdges.map(([a, b]) => `${a}-${b}`));
1747
- function addNode(depPath, key) {
1748
- let node = propertyExpr.split(depPath)[0];
1749
- nodes.add(node);
1750
- if (!excludes.has(`${key}-${node}`)) edges.push([key, node]);
1751
- }
1752
- for (const key of Object.keys(fields)) {
1753
- let value = fields[key];
1754
- nodes.add(key);
1755
- if (Reference.isRef(value) && value.isSibling) addNode(value.path, key);else if (isSchema(value) && 'deps' in value) value.deps.forEach(path => addNode(path, key));
1756
- }
1757
- return toposort$1.array(Array.from(nodes), edges).reverse();
1758
- }
1759
-
1760
- function findIndex(arr, err) {
1761
- let idx = Infinity;
1762
- arr.some((key, ii) => {
1763
- var _err$path;
1764
- if ((_err$path = err.path) != null && _err$path.includes(key)) {
1765
- idx = ii;
1766
- return true;
1767
- }
1768
- });
1769
- return idx;
1770
- }
1771
- function sortByKeyOrder(keys) {
1772
- return (a, b) => {
1773
- return findIndex(keys, a) - findIndex(keys, b);
1774
- };
1775
- }
1776
-
1777
- const parseJson = (value, _, ctx) => {
1778
- if (typeof value !== 'string') {
1779
- return value;
1780
- }
1781
- let parsed = value;
1782
- try {
1783
- parsed = JSON.parse(value);
1784
- } catch (err) {
1785
- /* */
1786
- }
1787
- return ctx.isType(parsed) ? parsed : value;
1788
- };
1789
-
1790
- // @ts-ignore
1791
- function deepPartial(schema) {
1792
- if ('fields' in schema) {
1793
- const partial = {};
1794
- for (const [key, fieldSchema] of Object.entries(schema.fields)) {
1795
- partial[key] = deepPartial(fieldSchema);
1796
- }
1797
- return schema.setFields(partial);
1798
- }
1799
- if (schema.type === 'array') {
1800
- const nextArray = schema.optional();
1801
- if (nextArray.innerType) nextArray.innerType = deepPartial(nextArray.innerType);
1802
- return nextArray;
1803
- }
1804
- if (schema.type === 'tuple') {
1805
- return schema.optional().clone({
1806
- types: schema.spec.types.map(deepPartial)
1807
- });
1808
- }
1809
- if ('optional' in schema) {
1810
- return schema.optional();
1811
- }
1812
- return schema;
1813
- }
1814
- const deepHas = (obj, p) => {
1815
- const path = [...propertyExpr.normalizePath(p)];
1816
- if (path.length === 1) return path[0] in obj;
1817
- let last = path.pop();
1818
- let parent = propertyExpr.getter(propertyExpr.join(path), true)(obj);
1819
- return !!(parent && last in parent);
1820
- };
1821
- let isObject = obj => Object.prototype.toString.call(obj) === '[object Object]';
1822
- function unknown(ctx, value) {
1823
- let known = Object.keys(ctx.fields);
1824
- return Object.keys(value).filter(key => known.indexOf(key) === -1);
1825
- }
1826
- const defaultSort = sortByKeyOrder([]);
1827
- function create$3(spec) {
1828
- return new ObjectSchema(spec);
1829
- }
1830
- class ObjectSchema extends Schema {
1831
- constructor(spec) {
1832
- super({
1833
- type: 'object',
1834
- check(value) {
1835
- return isObject(value) || typeof value === 'function';
1836
- }
1837
- });
1838
- this.fields = Object.create(null);
1839
- this._sortErrors = defaultSort;
1840
- this._nodes = [];
1841
- this._excludedEdges = [];
1842
- this.withMutation(() => {
1843
- if (spec) {
1844
- this.shape(spec);
1845
- }
1846
- });
1847
- }
1848
- _cast(_value, options = {}) {
1849
- var _options$stripUnknown;
1850
- let value = super._cast(_value, options);
1851
-
1852
- //should ignore nulls here
1853
- if (value === undefined) return this.getDefault(options);
1854
- if (!this._typeCheck(value)) return value;
1855
- let fields = this.fields;
1856
- let strip = (_options$stripUnknown = options.stripUnknown) != null ? _options$stripUnknown : this.spec.noUnknown;
1857
- let props = [].concat(this._nodes, Object.keys(value).filter(v => !this._nodes.includes(v)));
1858
- let intermediateValue = {}; // is filled during the transform below
1859
- let innerOptions = Object.assign({}, options, {
1860
- parent: intermediateValue,
1861
- __validating: options.__validating || false
1862
- });
1863
- let isChanged = false;
1864
- for (const prop of props) {
1865
- let field = fields[prop];
1866
- let exists = (prop in value);
1867
- if (field) {
1868
- let fieldValue;
1869
- let inputValue = value[prop];
1870
-
1871
- // safe to mutate since this is fired in sequence
1872
- innerOptions.path = (options.path ? `${options.path}.` : '') + prop;
1873
- field = field.resolve({
1874
- value: inputValue,
1875
- context: options.context,
1876
- parent: intermediateValue
1877
- });
1878
- let fieldSpec = field instanceof Schema ? field.spec : undefined;
1879
- let strict = fieldSpec == null ? void 0 : fieldSpec.strict;
1880
- if (fieldSpec != null && fieldSpec.strip) {
1881
- isChanged = isChanged || prop in value;
1882
- continue;
1883
- }
1884
- fieldValue = !options.__validating || !strict ?
1885
- // TODO: use _cast, this is double resolving
1886
- field.cast(value[prop], innerOptions) : value[prop];
1887
- if (fieldValue !== undefined) {
1888
- intermediateValue[prop] = fieldValue;
1889
- }
1890
- } else if (exists && !strip) {
1891
- intermediateValue[prop] = value[prop];
1892
- }
1893
- if (exists !== prop in intermediateValue || intermediateValue[prop] !== value[prop]) {
1894
- isChanged = true;
1895
- }
1896
- }
1897
- return isChanged ? intermediateValue : value;
1898
- }
1899
- _validate(_value, options = {}, panic, next) {
1900
- let {
1901
- from = [],
1902
- originalValue = _value,
1903
- recursive = this.spec.recursive
1904
- } = options;
1905
- options.from = [{
1906
- schema: this,
1907
- value: originalValue
1908
- }, ...from];
1909
- // this flag is needed for handling `strict` correctly in the context of
1910
- // validation vs just casting. e.g strict() on a field is only used when validating
1911
- options.__validating = true;
1912
- options.originalValue = originalValue;
1913
- super._validate(_value, options, panic, (objectErrors, value) => {
1914
- if (!recursive || !isObject(value)) {
1915
- next(objectErrors, value);
1916
- return;
1917
- }
1918
- originalValue = originalValue || value;
1919
- let tests = [];
1920
- for (let key of this._nodes) {
1921
- let field = this.fields[key];
1922
- if (!field || Reference.isRef(field)) {
1923
- continue;
1924
- }
1925
- tests.push(field.asNestedTest({
1926
- options,
1927
- key,
1928
- parent: value,
1929
- parentPath: options.path,
1930
- originalParent: originalValue
1931
- }));
1932
- }
1933
- this.runTests({
1934
- tests,
1935
- value,
1936
- originalValue,
1937
- options
1938
- }, panic, fieldErrors => {
1939
- next(fieldErrors.sort(this._sortErrors).concat(objectErrors), value);
1940
- });
1941
- });
1942
- }
1943
- clone(spec) {
1944
- const next = super.clone(spec);
1945
- next.fields = Object.assign({}, this.fields);
1946
- next._nodes = this._nodes;
1947
- next._excludedEdges = this._excludedEdges;
1948
- next._sortErrors = this._sortErrors;
1949
- return next;
1950
- }
1951
- concat(schema) {
1952
- let next = super.concat(schema);
1953
- let nextFields = next.fields;
1954
- for (let [field, schemaOrRef] of Object.entries(this.fields)) {
1955
- const target = nextFields[field];
1956
- nextFields[field] = target === undefined ? schemaOrRef : target;
1957
- }
1958
- return next.withMutation(s =>
1959
- // XXX: excludes here is wrong
1960
- s.setFields(nextFields, [...this._excludedEdges, ...schema._excludedEdges]));
1961
- }
1962
- _getDefault(options) {
1963
- if ('default' in this.spec) {
1964
- return super._getDefault(options);
1965
- }
1966
-
1967
- // if there is no default set invent one
1968
- if (!this._nodes.length) {
1969
- return undefined;
1970
- }
1971
- let dft = {};
1972
- this._nodes.forEach(key => {
1973
- var _innerOptions;
1974
- const field = this.fields[key];
1975
- let innerOptions = options;
1976
- if ((_innerOptions = innerOptions) != null && _innerOptions.value) {
1977
- innerOptions = Object.assign({}, innerOptions, {
1978
- parent: innerOptions.value,
1979
- value: innerOptions.value[key]
1980
- });
1981
- }
1982
- dft[key] = field && 'getDefault' in field ? field.getDefault(innerOptions) : undefined;
1983
- });
1984
- return dft;
1985
- }
1986
- setFields(shape, excludedEdges) {
1987
- let next = this.clone();
1988
- next.fields = shape;
1989
- next._nodes = sortFields(shape, excludedEdges);
1990
- next._sortErrors = sortByKeyOrder(Object.keys(shape));
1991
- // XXX: this carries over edges which may not be what you want
1992
- if (excludedEdges) next._excludedEdges = excludedEdges;
1993
- return next;
1994
- }
1995
- shape(additions, excludes = []) {
1996
- return this.clone().withMutation(next => {
1997
- let edges = next._excludedEdges;
1998
- if (excludes.length) {
1999
- if (!Array.isArray(excludes[0])) excludes = [excludes];
2000
- edges = [...next._excludedEdges, ...excludes];
2001
- }
2002
-
2003
- // XXX: excludes here is wrong
2004
- return next.setFields(Object.assign(next.fields, additions), edges);
2005
- });
2006
- }
2007
- partial() {
2008
- const partial = {};
2009
- for (const [key, schema] of Object.entries(this.fields)) {
2010
- partial[key] = 'optional' in schema && schema.optional instanceof Function ? schema.optional() : schema;
2011
- }
2012
- return this.setFields(partial);
2013
- }
2014
- deepPartial() {
2015
- const next = deepPartial(this);
2016
- return next;
2017
- }
2018
- pick(keys) {
2019
- const picked = {};
2020
- for (const key of keys) {
2021
- if (this.fields[key]) picked[key] = this.fields[key];
2022
- }
2023
- return this.setFields(picked, this._excludedEdges.filter(([a, b]) => keys.includes(a) && keys.includes(b)));
2024
- }
2025
- omit(keys) {
2026
- const remaining = [];
2027
- for (const key of Object.keys(this.fields)) {
2028
- if (keys.includes(key)) continue;
2029
- remaining.push(key);
2030
- }
2031
- return this.pick(remaining);
2032
- }
2033
- from(from, to, alias) {
2034
- let fromGetter = propertyExpr.getter(from, true);
2035
- return this.transform(obj => {
2036
- if (!obj) return obj;
2037
- let newObj = obj;
2038
- if (deepHas(obj, from)) {
2039
- newObj = Object.assign({}, obj);
2040
- if (!alias) delete newObj[from];
2041
- newObj[to] = fromGetter(obj);
2042
- }
2043
- return newObj;
2044
- });
2045
- }
2046
-
2047
- /** Parse an input JSON string to an object */
2048
- json() {
2049
- return this.transform(parseJson);
2050
- }
2051
-
2052
- /**
2053
- * Similar to `noUnknown` but only validates that an object is the right shape without stripping the unknown keys
2054
- */
2055
- exact(message) {
2056
- return this.test({
2057
- name: 'exact',
2058
- exclusive: true,
2059
- message: message || object.exact,
2060
- test(value) {
2061
- if (value == null) return true;
2062
- const unknownKeys = unknown(this.schema, value);
2063
- return unknownKeys.length === 0 || this.createError({
2064
- params: {
2065
- properties: unknownKeys.join(', ')
2066
- }
2067
- });
2068
- }
2069
- });
2070
- }
2071
- stripUnknown() {
2072
- return this.clone({
2073
- noUnknown: true
2074
- });
2075
- }
2076
- noUnknown(noAllow = true, message = object.noUnknown) {
2077
- if (typeof noAllow !== 'boolean') {
2078
- message = noAllow;
2079
- noAllow = true;
2080
- }
2081
- let next = this.test({
2082
- name: 'noUnknown',
2083
- exclusive: true,
2084
- message: message,
2085
- test(value) {
2086
- if (value == null) return true;
2087
- const unknownKeys = unknown(this.schema, value);
2088
- return !noAllow || unknownKeys.length === 0 || this.createError({
2089
- params: {
2090
- unknown: unknownKeys.join(', ')
2091
- }
2092
- });
2093
- }
2094
- });
2095
- next.spec.noUnknown = noAllow;
2096
- return next;
2097
- }
2098
- unknown(allow = true, message = object.noUnknown) {
2099
- return this.noUnknown(!allow, message);
2100
- }
2101
- transformKeys(fn) {
2102
- return this.transform(obj => {
2103
- if (!obj) return obj;
2104
- const result = {};
2105
- for (const key of Object.keys(obj)) result[fn(key)] = obj[key];
2106
- return result;
2107
- });
2108
- }
2109
- camelCase() {
2110
- return this.transformKeys(tinyCase.camelCase);
2111
- }
2112
- snakeCase() {
2113
- return this.transformKeys(tinyCase.snakeCase);
2114
- }
2115
- constantCase() {
2116
- return this.transformKeys(key => tinyCase.snakeCase(key).toUpperCase());
2117
- }
2118
- describe(options) {
2119
- const next = (options ? this.resolve(options) : this).clone();
2120
- const base = super.describe(options);
2121
- base.fields = {};
2122
- for (const [key, value] of Object.entries(next.fields)) {
2123
- var _innerOptions2;
2124
- let innerOptions = options;
2125
- if ((_innerOptions2 = innerOptions) != null && _innerOptions2.value) {
2126
- innerOptions = Object.assign({}, innerOptions, {
2127
- parent: innerOptions.value,
2128
- value: innerOptions.value[key]
2129
- });
2130
- }
2131
- base.fields[key] = value.describe(innerOptions);
2132
- }
2133
- return base;
2134
- }
2135
- }
2136
- create$3.prototype = ObjectSchema.prototype;
9
+ const index = require('./index-d2dc29e0.js');
10
+ const index_esm = require('./index.esm-c628daeb.js');
2137
11
 
2138
12
  class FormHook {
2139
13
  constructor(context, schemaObject, formStateOptions) {
@@ -2253,9 +127,9 @@ class FormHook {
2253
127
  const generalInquiryFormCss = "*,:after,:before{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scroll-snap-strictness:proximity;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;border:0 solid #e5e7eb;box-sizing:border-box}::backdrop{--tw-border-spacing-x:0;--tw-border-spacing-y:0;--tw-translate-x:0;--tw-translate-y:0;--tw-rotate:0;--tw-skew-x:0;--tw-skew-y:0;--tw-scale-x:1;--tw-scale-y:1;--tw-scroll-snap-strictness:proximity;--tw-ring-offset-width:0px;--tw-ring-offset-color:#fff;--tw-ring-color:rgba(59,130,246,.5);--tw-ring-offset-shadow:0 0 #0000;--tw-ring-shadow:0 0 #0000;--tw-shadow:0 0 #0000;--tw-shadow-colored:0 0 #0000;}/*! tailwindcss v3.4.15 | MIT License | https://tailwindcss.com*/:after,:before{--tw-content:\"\"}:host,html{-webkit-text-size-adjust:100%;font-feature-settings:normal;-webkit-tap-highlight-color:transparent;font-family:ui-sans-serif,system-ui,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;font-variation-settings:normal;line-height:1.5;-moz-tab-size:4;tab-size:4}body{line-height:inherit;margin:0}hr{border-top-width:1px;color:inherit;height:0}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,pre,samp{font-feature-settings:normal;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em;font-variation-settings:normal}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-collapse:collapse;border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-feature-settings:inherit;color:inherit;font-family:inherit;font-size:100%;font-variation-settings:inherit;font-weight:inherit;letter-spacing:inherit;line-height:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dd,dl,fieldset,figure,h1,h2,h3,h4,h5,h6,hr,p,pre{margin:0}fieldset,legend{padding:0}menu,ol,ul{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::placeholder,textarea::placeholder{color:#9ca3af;opacity:1}[role=button],button{cursor:pointer}:disabled{cursor:default}audio,canvas,embed,iframe,img,object,svg,video{display:block;vertical-align:middle}img,video{height:auto;max-width:100%}[hidden]:where(:not([hidden=until-found])){display:none}.block{display:block}:host{all:initial!important;display:block}*{font-family:Arial}.static{position:static}.shadow{--tw-shadow:0 1px 3px 0 rgba(0,0,0,.1),0 1px 2px -1px rgba(0,0,0,.1);--tw-shadow-colored:0 1px 3px 0 var(--tw-shadow-color),0 1px 2px -1px var(--tw-shadow-color);box-shadow:var(--tw-ring-offset-shadow,0 0 #0000),var(--tw-ring-shadow,0 0 #0000),var(--tw-shadow)}";
2254
128
  const GeneralInquiryFormStyle0 = generalInquiryFormCss;
2255
129
 
2256
- const inquirySchema = create$3({
2257
- name: create$6().required('r').min(4, 'kd').max(7, 'kk'),
2258
- name2: create$6().required(),
130
+ const inquirySchema = index_esm.create$3({
131
+ name: index_esm.create$6().required('r').min(4, 'kd').max(7, 'kk'),
132
+ name2: index_esm.create$6().required(),
2259
133
  });
2260
134
  const GeneralInquiryForm = class {
2261
135
  constructor(hostRef) {