@justifi/webcomponents 4.0.2 → 4.0.6

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