@justifi/webcomponents 4.0.0 → 4.0.2

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