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