@instockng/storefront-ui 1.0.37 → 1.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/RecommendedProducts.d.ts +8 -0
- package/dist/components/RecommendedProducts.d.ts.map +1 -0
- package/dist/components/ShoppingCart.d.ts.map +1 -1
- package/dist/contexts/CartContext.d.ts.map +1 -1
- package/dist/index.mjs +72 -70
- package/dist/index100.mjs +26 -16
- package/dist/index101.mjs +13 -210
- package/dist/index102.mjs +194 -159
- package/dist/index103.mjs +175 -17
- package/dist/index104.mjs +14 -15
- package/dist/index105.mjs +15 -25
- package/dist/index106.mjs +27 -150
- package/dist/index107.mjs +151 -15
- package/dist/index108.mjs +13 -24
- package/dist/index109.mjs +22 -75
- package/dist/index11.mjs +29 -27
- package/dist/index110.mjs +76 -30
- package/dist/index111.mjs +32 -139
- package/dist/index112.mjs +135 -45
- package/dist/index113.mjs +51 -19
- package/dist/index114.mjs +15 -19
- package/dist/index115.mjs +21 -17
- package/dist/index116.mjs +16 -18
- package/dist/index117.mjs +17 -13
- package/dist/index118.mjs +13 -14
- package/dist/index119.mjs +13 -12
- package/dist/index120.mjs +14 -58
- package/dist/index121.mjs +57 -10
- package/dist/index122.mjs +11 -32
- package/dist/index123.mjs +32 -17
- package/dist/index124.mjs +17 -27
- package/dist/index125.mjs +26 -19
- package/dist/index126.mjs +20 -12
- package/dist/index127.mjs +12 -14
- package/dist/index128.mjs +14 -40
- package/dist/index129.mjs +40 -16
- package/dist/index13.mjs +3 -3
- package/dist/index130.mjs +15 -260
- package/dist/index131.mjs +262 -64
- package/dist/index132.mjs +69 -7
- package/dist/index133.mjs +8 -2
- package/dist/index134.mjs +2 -2
- package/dist/index135.mjs +2 -33
- package/dist/index136.mjs +33 -2
- package/dist/index137.mjs +2 -21
- package/dist/index138.mjs +19 -54
- package/dist/index139.mjs +55 -28
- package/dist/index14.mjs +2 -2
- package/dist/index140.mjs +28 -6
- package/dist/index141.mjs +6 -51
- package/dist/index142.mjs +51 -5
- package/dist/index143.mjs +6 -12
- package/dist/index144.mjs +12 -7
- package/dist/index145.mjs +6 -27
- package/dist/index146.mjs +28 -2
- package/dist/index147.mjs +2 -70
- package/dist/index148.mjs +67 -164
- package/dist/index149.mjs +167 -2
- package/dist/index151.mjs +2 -2
- package/dist/index152.mjs +2 -18
- package/dist/index153.mjs +11 -25
- package/dist/index154.mjs +26 -32
- package/dist/index155.mjs +32 -12
- package/dist/index156.mjs +9 -9
- package/dist/index157.mjs +18 -2
- package/dist/index158.mjs +2 -20
- package/dist/index159.mjs +13 -39
- package/dist/index16.mjs +1 -1
- package/dist/index160.mjs +46 -2
- package/dist/index161.mjs +2 -30
- package/dist/index162.mjs +24 -12
- package/dist/index163.mjs +18 -2
- package/dist/index164.mjs +2 -2
- package/dist/index165.mjs +2 -2
- package/dist/index166.mjs +2 -2
- package/dist/index167.mjs +2 -72
- package/dist/index168.mjs +72 -2
- package/dist/index169.mjs +2 -53
- package/dist/index17.mjs +1 -1
- package/dist/index170.mjs +53 -2
- package/dist/index171.mjs +2 -36
- package/dist/index172.mjs +30 -146
- package/dist/index173.mjs +152 -2
- package/dist/index174.mjs +2 -2
- package/dist/index175.mjs +2 -19
- package/dist/index176.mjs +19 -2
- package/dist/index177.mjs +2 -2
- package/dist/index178.mjs +2 -26
- package/dist/index179.mjs +26 -2
- package/dist/index180.mjs +2 -2
- package/dist/index181.mjs +2 -24
- package/dist/index182.mjs +17 -16
- package/dist/index183.mjs +23 -2
- package/dist/index185.mjs +2 -2
- package/dist/index186.mjs +2 -23
- package/dist/index187.mjs +23 -2
- package/dist/index188.mjs +2 -23
- package/dist/index189.mjs +23 -2
- package/dist/index190.mjs +2 -2
- package/dist/index192.mjs +2 -23
- package/dist/index193.mjs +23 -2
- package/dist/index194.mjs +2 -23
- package/dist/index195.mjs +23 -2
- package/dist/index196.mjs +2 -2
- package/dist/index197.mjs +2 -2
- package/dist/index199.mjs +2 -2
- package/dist/index20.mjs +2 -2
- package/dist/index200.mjs +2 -2
- package/dist/index201.mjs +2 -2
- package/dist/index202.mjs +2 -2
- package/dist/index203.mjs +2 -127
- package/dist/index204.mjs +127 -2
- package/dist/index205.mjs +2 -74
- package/dist/index206.mjs +60 -60
- package/dist/index207.mjs +74 -2
- package/dist/index208.mjs +2 -31
- package/dist/index209.mjs +2 -11
- package/dist/index210.mjs +2 -4
- package/dist/index211.mjs +2 -4
- package/dist/index212.mjs +2 -13
- package/dist/index213.mjs +2 -7
- package/dist/index214.mjs +2 -12
- package/dist/index215.mjs +2 -5
- package/dist/index216.mjs +2 -33
- package/dist/index217.mjs +106 -29
- package/dist/index218.mjs +2 -28
- package/dist/index219.mjs +2 -61
- package/dist/index220.mjs +37 -2
- package/dist/index221.mjs +2 -2
- package/dist/index222.mjs +244 -2
- package/dist/index224.mjs +33 -2
- package/dist/index225.mjs +65 -2
- package/dist/index226.mjs +25 -2
- package/dist/index228.mjs +2 -108
- package/dist/index23.mjs +2 -2
- package/dist/index231.mjs +2 -37
- package/dist/index232.mjs +2 -2
- package/dist/index233.mjs +2 -244
- package/dist/index235.mjs +2 -33
- package/dist/index236.mjs +2 -65
- package/dist/index237.mjs +4 -25
- package/dist/index238.mjs +31 -2
- package/dist/index239.mjs +11 -2
- package/dist/index24.mjs +1 -1
- package/dist/index240.mjs +4 -2
- package/dist/index241.mjs +4 -2
- package/dist/index242.mjs +13 -2
- package/dist/index243.mjs +7 -2
- package/dist/index244.mjs +2 -2
- package/dist/index246.mjs +12 -2
- package/dist/index247.mjs +5 -2
- package/dist/index248.mjs +33 -4
- package/dist/index249.mjs +31 -2
- package/dist/index250.mjs +28 -2
- package/dist/index251.mjs +61 -2
- package/dist/index252.mjs +2 -2
- package/dist/index253.mjs +2 -18
- package/dist/index254.mjs +13 -42
- package/dist/index255.mjs +47 -2
- package/dist/index256.mjs +2 -2
- package/dist/index257.mjs +2 -2
- package/dist/index258.mjs +2 -2
- package/dist/index259.mjs +2 -91
- package/dist/index26.mjs +50 -39
- package/dist/index260.mjs +91 -2
- package/dist/index261.mjs +1 -2
- package/dist/index262.mjs +3 -2
- package/dist/index263.mjs +2 -2
- package/dist/index264.mjs +2 -17
- package/dist/index265.mjs +15 -11
- package/dist/index266.mjs +13 -6
- package/dist/index267.mjs +6 -30
- package/dist/index268.mjs +30 -2
- package/dist/index270.mjs +2 -2
- package/dist/index271.mjs +5 -0
- package/dist/index3.mjs +36 -28
- package/dist/index30.mjs +6 -5
- package/dist/index31.mjs +16 -15
- package/dist/index32.mjs +11 -11
- package/dist/index33.mjs +54 -45
- package/dist/index34.mjs +1 -1
- package/dist/index35.mjs +1 -1
- package/dist/index36.mjs +1 -1
- package/dist/index37.mjs +1 -1
- package/dist/index38.mjs +2 -2
- package/dist/index40.mjs +2 -2
- package/dist/index41.mjs +96 -6
- package/dist/index42.mjs +6 -1432
- package/dist/index43.mjs +1433 -2
- package/dist/index44.mjs +2 -60
- package/dist/index45.mjs +57 -48
- package/dist/index46.mjs +51 -33
- package/dist/index47.mjs +33 -15
- package/dist/index48.mjs +12 -2260
- package/dist/index49.mjs +2263 -36
- package/dist/index50.mjs +36 -44
- package/dist/index51.mjs +44 -99
- package/dist/index52.mjs +99 -113
- package/dist/index53.mjs +82 -50
- package/dist/index54.mjs +55 -51
- package/dist/index55.mjs +46 -64
- package/dist/index56.mjs +71 -57
- package/dist/index57.mjs +57 -55
- package/dist/index58.mjs +75 -15
- package/dist/index59.mjs +13 -12
- package/dist/index60.mjs +16 -59
- package/dist/index61.mjs +43 -105
- package/dist/index62.mjs +89 -93
- package/dist/index63.mjs +128 -23
- package/dist/index64.mjs +24 -2
- package/dist/index65.mjs +2 -153
- package/dist/index66.mjs +149 -19
- package/dist/index67.mjs +21 -73
- package/dist/index68.mjs +5 -15
- package/dist/index69.mjs +68 -56
- package/dist/index70.mjs +15 -5
- package/dist/index71.mjs +63 -2
- package/dist/index72.mjs +2 -6
- package/dist/index73.mjs +5 -1133
- package/dist/index74.mjs +1130 -16
- package/dist/index75.mjs +16 -51
- package/dist/index76.mjs +49 -27
- package/dist/index77.mjs +33 -2
- package/dist/index78.mjs +2 -235
- package/dist/index79.mjs +233 -4
- package/dist/index80.mjs +5 -133
- package/dist/index81.mjs +129 -63
- package/dist/index82.mjs +67 -86
- package/dist/index83.mjs +85 -27
- package/dist/index84.mjs +28 -8
- package/dist/index85.mjs +8 -74
- package/dist/index86.mjs +74 -3
- package/dist/index87.mjs +4 -2
- package/dist/index88.mjs +2 -83
- package/dist/index89.mjs +81 -52
- package/dist/index90.mjs +53 -5
- package/dist/index91.mjs +5 -4
- package/dist/index92.mjs +4 -178
- package/dist/index93.mjs +174 -48
- package/dist/index94.mjs +51 -67
- package/dist/index95.mjs +69 -34
- package/dist/index96.mjs +31 -40
- package/dist/index97.mjs +43 -2
- package/dist/index98.mjs +2 -2
- package/dist/index99.mjs +2 -28
- package/dist/styles.css +1 -1
- package/package.json +2 -2
- package/src/components/RecommendedProducts.stories.tsx +115 -0
- package/src/components/RecommendedProducts.tsx +184 -0
- package/src/components/ShoppingCart.tsx +9 -7
- package/src/contexts/CartContext.tsx +11 -2
package/dist/index43.mjs
CHANGED
|
@@ -1,5 +1,1436 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
2
|
+
import { p as S } from "./index69.mjs";
|
|
3
|
+
import { t as U } from "./index70.mjs";
|
|
4
|
+
import he from "./index71.mjs";
|
|
5
|
+
const fe = Object.prototype.toString, de = Error.prototype.toString, pe = RegExp.prototype.toString, me = typeof Symbol < "u" ? Symbol.prototype.toString : () => "", ye = /^Symbol\((.*)\)(.*)$/;
|
|
6
|
+
function ge(n) {
|
|
7
|
+
return n != +n ? "NaN" : n === 0 && 1 / n < 0 ? "-0" : "" + n;
|
|
8
|
+
}
|
|
9
|
+
function H(n, t = !1) {
|
|
10
|
+
if (n == null || n === !0 || n === !1) return "" + n;
|
|
11
|
+
const e = typeof n;
|
|
12
|
+
if (e === "number") return ge(n);
|
|
13
|
+
if (e === "string") return t ? `"${n}"` : n;
|
|
14
|
+
if (e === "function") return "[Function " + (n.name || "anonymous") + "]";
|
|
15
|
+
if (e === "symbol") return me.call(n).replace(ye, "Symbol($1)");
|
|
16
|
+
const r = fe.call(n).slice(8, -1);
|
|
17
|
+
return r === "Date" ? isNaN(n.getTime()) ? "" + n : n.toISOString(n) : r === "Error" || n instanceof Error ? "[" + de.call(n) + "]" : r === "RegExp" ? pe.call(n) : null;
|
|
18
|
+
}
|
|
19
|
+
function x(n, t) {
|
|
20
|
+
let e = H(n, t);
|
|
21
|
+
return e !== null ? e : JSON.stringify(n, function(r, s) {
|
|
22
|
+
let i = H(this[r], t);
|
|
23
|
+
return i !== null ? i : s;
|
|
24
|
+
}, 2);
|
|
25
|
+
}
|
|
26
|
+
function te(n) {
|
|
27
|
+
return n == null ? [] : [].concat(n);
|
|
28
|
+
}
|
|
29
|
+
let re, se, ne, be = /\$\{\s*(\w+)\s*\}/g;
|
|
30
|
+
re = Symbol.toStringTag;
|
|
31
|
+
class Q {
|
|
32
|
+
constructor(t, e, r, s) {
|
|
33
|
+
this.name = void 0, this.message = void 0, this.value = void 0, this.path = void 0, this.type = void 0, this.params = void 0, this.errors = void 0, this.inner = void 0, this[re] = "Error", this.name = "ValidationError", this.value = e, this.path = r, this.type = s, this.errors = [], this.inner = [], te(t).forEach((i) => {
|
|
34
|
+
if (p.isError(i)) {
|
|
35
|
+
this.errors.push(...i.errors);
|
|
36
|
+
const a = i.inner.length ? i.inner : [i];
|
|
37
|
+
this.inner.push(...a);
|
|
38
|
+
} else
|
|
39
|
+
this.errors.push(i);
|
|
40
|
+
}), this.message = this.errors.length > 1 ? `${this.errors.length} errors occurred` : this.errors[0];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
se = Symbol.hasInstance;
|
|
44
|
+
ne = Symbol.toStringTag;
|
|
45
|
+
class p extends Error {
|
|
46
|
+
static formatError(t, e) {
|
|
47
|
+
const r = e.label || e.path || "this";
|
|
48
|
+
return e = Object.assign({}, e, {
|
|
49
|
+
path: r,
|
|
50
|
+
originalPath: e.path
|
|
51
|
+
}), typeof t == "string" ? t.replace(be, (s, i) => x(e[i])) : typeof t == "function" ? t(e) : t;
|
|
52
|
+
}
|
|
53
|
+
static isError(t) {
|
|
54
|
+
return t && t.name === "ValidationError";
|
|
55
|
+
}
|
|
56
|
+
constructor(t, e, r, s, i) {
|
|
57
|
+
const a = new Q(t, e, r, s);
|
|
58
|
+
if (i)
|
|
59
|
+
return a;
|
|
60
|
+
super(), this.value = void 0, this.path = void 0, this.type = void 0, this.params = void 0, this.errors = [], this.inner = [], this[ne] = "Error", this.name = a.name, this.message = a.message, this.type = a.type, this.value = a.value, this.path = a.path, this.errors = a.errors, this.inner = a.inner, Error.captureStackTrace && Error.captureStackTrace(this, p);
|
|
61
|
+
}
|
|
62
|
+
static [se](t) {
|
|
63
|
+
return Q[Symbol.hasInstance](t) || super[Symbol.hasInstance](t);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let F = {
|
|
67
|
+
default: "${path} is invalid",
|
|
68
|
+
required: "${path} is a required field",
|
|
69
|
+
defined: "${path} must be defined",
|
|
70
|
+
notNull: "${path} cannot be null",
|
|
71
|
+
oneOf: "${path} must be one of the following values: ${values}",
|
|
72
|
+
notOneOf: "${path} must not be one of the following values: ${values}",
|
|
73
|
+
notType: ({
|
|
74
|
+
path: n,
|
|
75
|
+
type: t,
|
|
76
|
+
value: e,
|
|
77
|
+
originalValue: r
|
|
78
|
+
}) => {
|
|
79
|
+
const s = r != null && r !== e ? ` (cast from the value \`${x(r, !0)}\`).` : ".";
|
|
80
|
+
return t !== "mixed" ? `${n} must be a \`${t}\` type, but the final value was: \`${x(e, !0)}\`` + s : `${n} must match the configured type. The validated value was: \`${x(e, !0)}\`` + s;
|
|
81
|
+
}
|
|
82
|
+
}, m = {
|
|
83
|
+
length: "${path} must be exactly ${length} characters",
|
|
84
|
+
min: "${path} must be at least ${min} characters",
|
|
85
|
+
max: "${path} must be at most ${max} characters",
|
|
86
|
+
matches: '${path} must match the following: "${regex}"',
|
|
87
|
+
email: "${path} must be a valid email",
|
|
88
|
+
url: "${path} must be a valid URL",
|
|
89
|
+
uuid: "${path} must be a valid UUID",
|
|
90
|
+
datetime: "${path} must be a valid ISO date-time",
|
|
91
|
+
datetime_precision: "${path} must be a valid ISO date-time with a sub-second precision of exactly ${precision} digits",
|
|
92
|
+
datetime_offset: '${path} must be a valid ISO date-time with UTC "Z" timezone',
|
|
93
|
+
trim: "${path} must be a trimmed string",
|
|
94
|
+
lowercase: "${path} must be a lowercase string",
|
|
95
|
+
uppercase: "${path} must be a upper case string"
|
|
96
|
+
}, Fe = {
|
|
97
|
+
min: "${path} must be greater than or equal to ${min}",
|
|
98
|
+
max: "${path} must be less than or equal to ${max}",
|
|
99
|
+
lessThan: "${path} must be less than ${less}",
|
|
100
|
+
moreThan: "${path} must be greater than ${more}",
|
|
101
|
+
positive: "${path} must be a positive number",
|
|
102
|
+
negative: "${path} must be a negative number",
|
|
103
|
+
integer: "${path} must be an integer"
|
|
104
|
+
}, q = {
|
|
105
|
+
min: "${path} field must be later than ${min}",
|
|
106
|
+
max: "${path} field must be at earlier than ${max}"
|
|
107
|
+
}, $e = {
|
|
108
|
+
isValue: "${path} field must be ${value}"
|
|
109
|
+
}, C = {
|
|
110
|
+
noUnknown: "${path} field has unspecified keys: ${unknown}",
|
|
111
|
+
exact: "${path} object contains unknown properties: ${properties}"
|
|
112
|
+
}, Oe = {
|
|
113
|
+
min: "${path} field must have at least ${min} items",
|
|
114
|
+
max: "${path} field must have less than or equal to ${max} items",
|
|
115
|
+
length: "${path} must have ${length} items"
|
|
116
|
+
}, we = {
|
|
117
|
+
notType: (n) => {
|
|
118
|
+
const {
|
|
119
|
+
path: t,
|
|
120
|
+
value: e,
|
|
121
|
+
spec: r
|
|
122
|
+
} = n, s = r.types.length;
|
|
123
|
+
if (Array.isArray(e)) {
|
|
124
|
+
if (e.length < s) return `${t} tuple value has too few items, expected a length of ${s} but got ${e.length} for value: \`${x(e, !0)}\``;
|
|
125
|
+
if (e.length > s) return `${t} tuple value has too many items, expected a length of ${s} but got ${e.length} for value: \`${x(e, !0)}\``;
|
|
126
|
+
}
|
|
127
|
+
return p.formatError(F.notType, n);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
131
|
+
mixed: F,
|
|
132
|
+
string: m,
|
|
133
|
+
number: Fe,
|
|
134
|
+
date: q,
|
|
135
|
+
object: C,
|
|
136
|
+
array: Oe,
|
|
137
|
+
boolean: $e,
|
|
138
|
+
tuple: we
|
|
139
|
+
});
|
|
140
|
+
const L = (n) => n && n.__isYupSchema__;
|
|
141
|
+
class R {
|
|
142
|
+
static fromOptions(t, e) {
|
|
143
|
+
if (!e.then && !e.otherwise) throw new TypeError("either `then:` or `otherwise:` is required for `when()` conditions");
|
|
144
|
+
let {
|
|
145
|
+
is: r,
|
|
146
|
+
then: s,
|
|
147
|
+
otherwise: i
|
|
148
|
+
} = e, a = typeof r == "function" ? r : (...l) => l.every((u) => u === r);
|
|
149
|
+
return new R(t, (l, u) => {
|
|
150
|
+
var o;
|
|
151
|
+
let c = a(...l) ? s : i;
|
|
152
|
+
return (o = c == null ? void 0 : c(u)) != null ? o : u;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
constructor(t, e) {
|
|
156
|
+
this.fn = void 0, this.refs = t, this.refs = t, this.fn = e;
|
|
157
|
+
}
|
|
158
|
+
resolve(t, e) {
|
|
159
|
+
let r = this.refs.map((i) => (
|
|
160
|
+
// TODO: ? operator here?
|
|
161
|
+
i.getValue(e == null ? void 0 : e.value, e == null ? void 0 : e.parent, e == null ? void 0 : e.context)
|
|
162
|
+
)), s = this.fn(r, t, e);
|
|
163
|
+
if (s === void 0 || // @ts-ignore this can be base
|
|
164
|
+
s === t)
|
|
165
|
+
return t;
|
|
166
|
+
if (!L(s)) throw new TypeError("conditions must return a schema object");
|
|
167
|
+
return s.resolve(e);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const N = {
|
|
171
|
+
context: "$",
|
|
172
|
+
value: "."
|
|
173
|
+
};
|
|
174
|
+
class E {
|
|
175
|
+
constructor(t, e = {}) {
|
|
176
|
+
if (this.key = void 0, this.isContext = void 0, this.isValue = void 0, this.isSibling = void 0, this.path = void 0, this.getter = void 0, this.map = void 0, typeof t != "string") throw new TypeError("ref must be a string, got: " + t);
|
|
177
|
+
if (this.key = t.trim(), t === "") throw new TypeError("ref must be a non-empty string");
|
|
178
|
+
this.isContext = this.key[0] === N.context, this.isValue = this.key[0] === N.value, this.isSibling = !this.isContext && !this.isValue;
|
|
179
|
+
let r = this.isContext ? N.context : this.isValue ? N.value : "";
|
|
180
|
+
this.path = this.key.slice(r.length), this.getter = this.path && S.getter(this.path, !0), this.map = e.map;
|
|
181
|
+
}
|
|
182
|
+
getValue(t, e, r) {
|
|
183
|
+
let s = this.isContext ? r : this.isValue ? t : e;
|
|
184
|
+
return this.getter && (s = this.getter(s || {})), this.map && (s = this.map(s)), s;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
* @param {*} value
|
|
189
|
+
* @param {Object} options
|
|
190
|
+
* @param {Object=} options.context
|
|
191
|
+
* @param {Object=} options.parent
|
|
192
|
+
*/
|
|
193
|
+
cast(t, e) {
|
|
194
|
+
return this.getValue(t, e == null ? void 0 : e.parent, e == null ? void 0 : e.context);
|
|
195
|
+
}
|
|
196
|
+
resolve() {
|
|
197
|
+
return this;
|
|
198
|
+
}
|
|
199
|
+
describe() {
|
|
200
|
+
return {
|
|
201
|
+
type: "ref",
|
|
202
|
+
key: this.key
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
toString() {
|
|
206
|
+
return `Ref(${this.key})`;
|
|
207
|
+
}
|
|
208
|
+
static isRef(t) {
|
|
209
|
+
return t && t.__isYupRef;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
E.prototype.__isYupRef = !0;
|
|
213
|
+
const v = (n) => n == null;
|
|
214
|
+
function k(n) {
|
|
215
|
+
function t({
|
|
216
|
+
value: e,
|
|
217
|
+
path: r = "",
|
|
218
|
+
options: s,
|
|
219
|
+
originalValue: i,
|
|
220
|
+
schema: a
|
|
221
|
+
}, l, u) {
|
|
222
|
+
const {
|
|
223
|
+
name: o,
|
|
224
|
+
test: c,
|
|
225
|
+
params: h,
|
|
226
|
+
message: f,
|
|
227
|
+
skipAbsent: g
|
|
228
|
+
} = n;
|
|
229
|
+
let {
|
|
230
|
+
parent: b,
|
|
231
|
+
context: y,
|
|
232
|
+
abortEarly: w = a.spec.abortEarly,
|
|
233
|
+
disableStackTrace: D = a.spec.disableStackTrace
|
|
234
|
+
} = s;
|
|
235
|
+
const _ = {
|
|
236
|
+
value: e,
|
|
237
|
+
parent: b,
|
|
238
|
+
context: y
|
|
239
|
+
};
|
|
240
|
+
function K(d = {}) {
|
|
241
|
+
const A = ie(Object.assign({
|
|
242
|
+
value: e,
|
|
243
|
+
originalValue: i,
|
|
244
|
+
label: a.spec.label,
|
|
245
|
+
path: d.path || r,
|
|
246
|
+
spec: a.spec,
|
|
247
|
+
disableStackTrace: d.disableStackTrace || D
|
|
248
|
+
}, h, d.params), _), G = new p(p.formatError(d.message || f, A), e, A.path, d.type || o, A.disableStackTrace);
|
|
249
|
+
return G.params = A, G;
|
|
250
|
+
}
|
|
251
|
+
const M = w ? l : u;
|
|
252
|
+
let z = {
|
|
253
|
+
path: r,
|
|
254
|
+
parent: b,
|
|
255
|
+
type: o,
|
|
256
|
+
from: s.from,
|
|
257
|
+
createError: K,
|
|
258
|
+
resolve(d) {
|
|
259
|
+
return ae(d, _);
|
|
260
|
+
},
|
|
261
|
+
options: s,
|
|
262
|
+
originalValue: i,
|
|
263
|
+
schema: a
|
|
264
|
+
};
|
|
265
|
+
const V = (d) => {
|
|
266
|
+
p.isError(d) ? M(d) : d ? u(null) : M(K());
|
|
267
|
+
}, B = (d) => {
|
|
268
|
+
p.isError(d) ? M(d) : l(d);
|
|
269
|
+
};
|
|
270
|
+
if (g && v(e))
|
|
271
|
+
return V(!0);
|
|
272
|
+
let j;
|
|
273
|
+
try {
|
|
274
|
+
var J;
|
|
275
|
+
if (j = c.call(z, e, z), typeof ((J = j) == null ? void 0 : J.then) == "function") {
|
|
276
|
+
if (s.sync)
|
|
277
|
+
throw new Error(`Validation test of type: "${z.type}" returned a Promise during a synchronous validate. This test will finish after the validate call has returned`);
|
|
278
|
+
return Promise.resolve(j).then(V, B);
|
|
279
|
+
}
|
|
280
|
+
} catch (d) {
|
|
281
|
+
B(d);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
V(j);
|
|
285
|
+
}
|
|
286
|
+
return t.OPTIONS = n, t;
|
|
287
|
+
}
|
|
288
|
+
function ie(n, t) {
|
|
289
|
+
if (!n) return n;
|
|
290
|
+
for (const e of Object.keys(n))
|
|
291
|
+
n[e] = ae(n[e], t);
|
|
292
|
+
return n;
|
|
293
|
+
}
|
|
294
|
+
function ae(n, t) {
|
|
295
|
+
return E.isRef(n) ? n.getValue(t.value, t.parent, t.context) : n;
|
|
296
|
+
}
|
|
297
|
+
function xe(n, t, e, r = e) {
|
|
298
|
+
let s, i, a;
|
|
299
|
+
return t ? (S.forEach(t, (l, u, o) => {
|
|
300
|
+
let c = u ? l.slice(1, l.length - 1) : l;
|
|
301
|
+
n = n.resolve({
|
|
302
|
+
context: r,
|
|
303
|
+
parent: s,
|
|
304
|
+
value: e
|
|
305
|
+
});
|
|
306
|
+
let h = n.type === "tuple", f = o ? parseInt(c, 10) : 0;
|
|
307
|
+
if (n.innerType || h) {
|
|
308
|
+
if (h && !o) throw new Error(`Yup.reach cannot implicitly index into a tuple type. the path part "${a}" must contain an index to the tuple element, e.g. "${a}[0]"`);
|
|
309
|
+
if (e && f >= e.length)
|
|
310
|
+
throw new Error(`Yup.reach cannot resolve an array item at index: ${l}, in the path: ${t}. because there is no value at that index. `);
|
|
311
|
+
s = e, e = e && e[f], n = h ? n.spec.types[f] : n.innerType;
|
|
312
|
+
}
|
|
313
|
+
if (!o) {
|
|
314
|
+
if (!n.fields || !n.fields[c]) throw new Error(`The schema does not contain the path: ${t}. (failed at: ${a} which is a type: "${n.type}")`);
|
|
315
|
+
s = e, e = e && e[c], n = n.fields[c];
|
|
316
|
+
}
|
|
317
|
+
i = c, a = u ? "[" + l + "]" : "." + l;
|
|
318
|
+
}), {
|
|
319
|
+
schema: n,
|
|
320
|
+
parent: s,
|
|
321
|
+
parentPath: i
|
|
322
|
+
}) : {
|
|
323
|
+
parent: s,
|
|
324
|
+
parentPath: t,
|
|
325
|
+
schema: n
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
class P extends Set {
|
|
329
|
+
describe() {
|
|
330
|
+
const t = [];
|
|
331
|
+
for (const e of this.values())
|
|
332
|
+
t.push(E.isRef(e) ? e.describe() : e);
|
|
333
|
+
return t;
|
|
334
|
+
}
|
|
335
|
+
resolveAll(t) {
|
|
336
|
+
let e = [];
|
|
337
|
+
for (const r of this.values())
|
|
338
|
+
e.push(t(r));
|
|
339
|
+
return e;
|
|
340
|
+
}
|
|
341
|
+
clone() {
|
|
342
|
+
return new P(this.values());
|
|
343
|
+
}
|
|
344
|
+
merge(t, e) {
|
|
345
|
+
const r = this.clone();
|
|
346
|
+
return t.forEach((s) => r.add(s)), e.forEach((s) => r.delete(s)), r;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function T(n, t = /* @__PURE__ */ new Map()) {
|
|
350
|
+
if (L(n) || !n || typeof n != "object") return n;
|
|
351
|
+
if (t.has(n)) return t.get(n);
|
|
352
|
+
let e;
|
|
353
|
+
if (n instanceof Date)
|
|
354
|
+
e = new Date(n.getTime()), t.set(n, e);
|
|
355
|
+
else if (n instanceof RegExp)
|
|
356
|
+
e = new RegExp(n), t.set(n, e);
|
|
357
|
+
else if (Array.isArray(n)) {
|
|
358
|
+
e = new Array(n.length), t.set(n, e);
|
|
359
|
+
for (let r = 0; r < n.length; r++) e[r] = T(n[r], t);
|
|
360
|
+
} else if (n instanceof Map) {
|
|
361
|
+
e = /* @__PURE__ */ new Map(), t.set(n, e);
|
|
362
|
+
for (const [r, s] of n.entries()) e.set(r, T(s, t));
|
|
363
|
+
} else if (n instanceof Set) {
|
|
364
|
+
e = /* @__PURE__ */ new Set(), t.set(n, e);
|
|
365
|
+
for (const r of n) e.add(T(r, t));
|
|
366
|
+
} else if (n instanceof Object) {
|
|
367
|
+
e = {}, t.set(n, e);
|
|
368
|
+
for (const [r, s] of Object.entries(n)) e[r] = T(s, t);
|
|
369
|
+
} else
|
|
370
|
+
throw Error(`Unable to clone ${n}`);
|
|
371
|
+
return e;
|
|
372
|
+
}
|
|
373
|
+
function _e(n) {
|
|
374
|
+
if (!(n != null && n.length))
|
|
375
|
+
return;
|
|
376
|
+
const t = [];
|
|
377
|
+
let e = "", r = !1, s = !1;
|
|
378
|
+
for (let i = 0; i < n.length; i++) {
|
|
379
|
+
const a = n[i];
|
|
380
|
+
if (a === "[" && !s) {
|
|
381
|
+
e && (t.push(...e.split(".").filter(Boolean)), e = ""), r = !0;
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (a === "]" && !s) {
|
|
385
|
+
e && (/^\d+$/.test(e) ? t.push(e) : t.push(e.replace(/^"|"$/g, "")), e = ""), r = !1;
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
if (a === '"') {
|
|
389
|
+
s = !s;
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
if (a === "." && !r && !s) {
|
|
393
|
+
e && (t.push(e), e = "");
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
e += a;
|
|
397
|
+
}
|
|
398
|
+
return e && t.push(...e.split(".").filter(Boolean)), t;
|
|
399
|
+
}
|
|
400
|
+
function ve(n, t) {
|
|
401
|
+
const e = t ? `${t}.${n.path}` : n.path;
|
|
402
|
+
return n.errors.map((r) => ({
|
|
403
|
+
message: r,
|
|
404
|
+
path: _e(e)
|
|
405
|
+
}));
|
|
406
|
+
}
|
|
407
|
+
function le(n, t) {
|
|
408
|
+
var e;
|
|
409
|
+
if (!((e = n.inner) != null && e.length) && n.errors.length)
|
|
410
|
+
return ve(n, t);
|
|
411
|
+
const r = t ? `${t}.${n.path}` : n.path;
|
|
412
|
+
return n.inner.flatMap((s) => le(s, r));
|
|
413
|
+
}
|
|
414
|
+
class $ {
|
|
415
|
+
constructor(t) {
|
|
416
|
+
this.type = void 0, this.deps = [], this.tests = void 0, this.transforms = void 0, this.conditions = [], this._mutate = void 0, this.internalTests = {}, this._whitelist = new P(), this._blacklist = new P(), this.exclusiveTests = /* @__PURE__ */ Object.create(null), this._typeCheck = void 0, this.spec = void 0, this.tests = [], this.transforms = [], this.withMutation(() => {
|
|
417
|
+
this.typeError(F.notType);
|
|
418
|
+
}), this.type = t.type, this._typeCheck = t.check, this.spec = Object.assign({
|
|
419
|
+
strip: !1,
|
|
420
|
+
strict: !1,
|
|
421
|
+
abortEarly: !0,
|
|
422
|
+
recursive: !0,
|
|
423
|
+
disableStackTrace: !1,
|
|
424
|
+
nullable: !1,
|
|
425
|
+
optional: !0,
|
|
426
|
+
coerce: !0
|
|
427
|
+
}, t == null ? void 0 : t.spec), this.withMutation((e) => {
|
|
428
|
+
e.nonNullable();
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
// TODO: remove
|
|
432
|
+
get _type() {
|
|
433
|
+
return this.type;
|
|
434
|
+
}
|
|
435
|
+
clone(t) {
|
|
436
|
+
if (this._mutate)
|
|
437
|
+
return t && Object.assign(this.spec, t), this;
|
|
438
|
+
const e = Object.create(Object.getPrototypeOf(this));
|
|
439
|
+
return e.type = this.type, e._typeCheck = this._typeCheck, e._whitelist = this._whitelist.clone(), e._blacklist = this._blacklist.clone(), e.internalTests = Object.assign({}, this.internalTests), e.exclusiveTests = Object.assign({}, this.exclusiveTests), e.deps = [...this.deps], e.conditions = [...this.conditions], e.tests = [...this.tests], e.transforms = [...this.transforms], e.spec = T(Object.assign({}, this.spec, t)), e;
|
|
440
|
+
}
|
|
441
|
+
label(t) {
|
|
442
|
+
let e = this.clone();
|
|
443
|
+
return e.spec.label = t, e;
|
|
444
|
+
}
|
|
445
|
+
meta(...t) {
|
|
446
|
+
if (t.length === 0) return this.spec.meta;
|
|
447
|
+
let e = this.clone();
|
|
448
|
+
return e.spec.meta = Object.assign(e.spec.meta || {}, t[0]), e;
|
|
449
|
+
}
|
|
450
|
+
withMutation(t) {
|
|
451
|
+
let e = this._mutate;
|
|
452
|
+
this._mutate = !0;
|
|
453
|
+
let r = t(this);
|
|
454
|
+
return this._mutate = e, r;
|
|
455
|
+
}
|
|
456
|
+
concat(t) {
|
|
457
|
+
if (!t || t === this) return this;
|
|
458
|
+
if (t.type !== this.type && this.type !== "mixed") throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${t.type}`);
|
|
459
|
+
let e = this, r = t.clone();
|
|
460
|
+
const s = Object.assign({}, e.spec, r.spec);
|
|
461
|
+
return r.spec = s, r.internalTests = Object.assign({}, e.internalTests, r.internalTests), r._whitelist = e._whitelist.merge(t._whitelist, t._blacklist), r._blacklist = e._blacklist.merge(t._blacklist, t._whitelist), r.tests = e.tests, r.exclusiveTests = e.exclusiveTests, r.withMutation((i) => {
|
|
462
|
+
t.tests.forEach((a) => {
|
|
463
|
+
i.test(a.OPTIONS);
|
|
464
|
+
});
|
|
465
|
+
}), r.transforms = [...e.transforms, ...r.transforms], r;
|
|
466
|
+
}
|
|
467
|
+
isType(t) {
|
|
468
|
+
return t == null ? !!(this.spec.nullable && t === null || this.spec.optional && t === void 0) : this._typeCheck(t);
|
|
469
|
+
}
|
|
470
|
+
resolve(t) {
|
|
471
|
+
let e = this;
|
|
472
|
+
if (e.conditions.length) {
|
|
473
|
+
let r = e.conditions;
|
|
474
|
+
e = e.clone(), e.conditions = [], e = r.reduce((s, i) => i.resolve(s, t), e), e = e.resolve(t);
|
|
475
|
+
}
|
|
476
|
+
return e;
|
|
477
|
+
}
|
|
478
|
+
resolveOptions(t) {
|
|
479
|
+
var e, r, s, i;
|
|
480
|
+
return Object.assign({}, t, {
|
|
481
|
+
from: t.from || [],
|
|
482
|
+
strict: (e = t.strict) != null ? e : this.spec.strict,
|
|
483
|
+
abortEarly: (r = t.abortEarly) != null ? r : this.spec.abortEarly,
|
|
484
|
+
recursive: (s = t.recursive) != null ? s : this.spec.recursive,
|
|
485
|
+
disableStackTrace: (i = t.disableStackTrace) != null ? i : this.spec.disableStackTrace
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* Run the configured transform pipeline over an input value.
|
|
490
|
+
*/
|
|
491
|
+
cast(t, e = {}) {
|
|
492
|
+
let r = this.resolve(Object.assign({}, e, {
|
|
493
|
+
value: t
|
|
494
|
+
// parent: options.parent,
|
|
495
|
+
// context: options.context,
|
|
496
|
+
})), s = e.assert === "ignore-optionality", i = r._cast(t, e);
|
|
497
|
+
if (e.assert !== !1 && !r.isType(i)) {
|
|
498
|
+
if (s && v(i))
|
|
499
|
+
return i;
|
|
500
|
+
let a = x(t), l = x(i);
|
|
501
|
+
throw new TypeError(`The value of ${e.path || "field"} could not be cast to a value that satisfies the schema type: "${r.type}".
|
|
502
|
+
|
|
503
|
+
attempted value: ${a}
|
|
504
|
+
` + (l !== a ? `result of cast: ${l}` : ""));
|
|
505
|
+
}
|
|
506
|
+
return i;
|
|
507
|
+
}
|
|
508
|
+
_cast(t, e) {
|
|
509
|
+
let r = t === void 0 ? t : this.transforms.reduce((s, i) => i.call(this, s, t, this, e), t);
|
|
510
|
+
return r === void 0 && (r = this.getDefault(e)), r;
|
|
511
|
+
}
|
|
512
|
+
_validate(t, e = {}, r, s) {
|
|
513
|
+
let {
|
|
514
|
+
path: i,
|
|
515
|
+
originalValue: a = t,
|
|
516
|
+
strict: l = this.spec.strict
|
|
517
|
+
} = e, u = t;
|
|
518
|
+
l || (u = this._cast(u, Object.assign({
|
|
519
|
+
assert: !1
|
|
520
|
+
}, e)));
|
|
521
|
+
let o = [];
|
|
522
|
+
for (let c of Object.values(this.internalTests))
|
|
523
|
+
c && o.push(c);
|
|
524
|
+
this.runTests({
|
|
525
|
+
path: i,
|
|
526
|
+
value: u,
|
|
527
|
+
originalValue: a,
|
|
528
|
+
options: e,
|
|
529
|
+
tests: o
|
|
530
|
+
}, r, (c) => {
|
|
531
|
+
if (c.length)
|
|
532
|
+
return s(c, u);
|
|
533
|
+
this.runTests({
|
|
534
|
+
path: i,
|
|
535
|
+
value: u,
|
|
536
|
+
originalValue: a,
|
|
537
|
+
options: e,
|
|
538
|
+
tests: this.tests
|
|
539
|
+
}, r, s);
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Executes a set of validations, either schema, produced Tests or a nested
|
|
544
|
+
* schema validate result.
|
|
545
|
+
*/
|
|
546
|
+
runTests(t, e, r) {
|
|
547
|
+
let s = !1, {
|
|
548
|
+
tests: i,
|
|
549
|
+
value: a,
|
|
550
|
+
originalValue: l,
|
|
551
|
+
path: u,
|
|
552
|
+
options: o
|
|
553
|
+
} = t, c = (y) => {
|
|
554
|
+
s || (s = !0, e(y, a));
|
|
555
|
+
}, h = (y) => {
|
|
556
|
+
s || (s = !0, r(y, a));
|
|
557
|
+
}, f = i.length, g = [];
|
|
558
|
+
if (!f) return h([]);
|
|
559
|
+
let b = {
|
|
560
|
+
value: a,
|
|
561
|
+
originalValue: l,
|
|
562
|
+
path: u,
|
|
563
|
+
options: o,
|
|
564
|
+
schema: this
|
|
565
|
+
};
|
|
566
|
+
for (let y = 0; y < i.length; y++) {
|
|
567
|
+
const w = i[y];
|
|
568
|
+
w(b, c, function(_) {
|
|
569
|
+
_ && (Array.isArray(_) ? g.push(..._) : g.push(_)), --f <= 0 && h(g);
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
asNestedTest({
|
|
574
|
+
key: t,
|
|
575
|
+
index: e,
|
|
576
|
+
parent: r,
|
|
577
|
+
parentPath: s,
|
|
578
|
+
originalParent: i,
|
|
579
|
+
options: a
|
|
580
|
+
}) {
|
|
581
|
+
const l = t ?? e;
|
|
582
|
+
if (l == null)
|
|
583
|
+
throw TypeError("Must include `key` or `index` for nested validations");
|
|
584
|
+
const u = typeof l == "number";
|
|
585
|
+
let o = r[l];
|
|
586
|
+
const c = Object.assign({}, a, {
|
|
587
|
+
// Nested validations fields are always strict:
|
|
588
|
+
// 1. parent isn't strict so the casting will also have cast inner values
|
|
589
|
+
// 2. parent is strict in which case the nested values weren't cast either
|
|
590
|
+
strict: !0,
|
|
591
|
+
parent: r,
|
|
592
|
+
value: o,
|
|
593
|
+
originalValue: i[l],
|
|
594
|
+
// FIXME: tests depend on `index` being passed around deeply,
|
|
595
|
+
// we should not let the options.key/index bleed through
|
|
596
|
+
key: void 0,
|
|
597
|
+
// index: undefined,
|
|
598
|
+
[u ? "index" : "key"]: l,
|
|
599
|
+
path: u || l.includes(".") ? `${s || ""}[${u ? l : `"${l}"`}]` : (s ? `${s}.` : "") + t
|
|
600
|
+
});
|
|
601
|
+
return (h, f, g) => this.resolve(c)._validate(o, c, f, g);
|
|
602
|
+
}
|
|
603
|
+
validate(t, e) {
|
|
604
|
+
var r;
|
|
605
|
+
let s = this.resolve(Object.assign({}, e, {
|
|
606
|
+
value: t
|
|
607
|
+
})), i = (r = e == null ? void 0 : e.disableStackTrace) != null ? r : s.spec.disableStackTrace;
|
|
608
|
+
return new Promise((a, l) => s._validate(t, e, (u, o) => {
|
|
609
|
+
p.isError(u) && (u.value = o), l(u);
|
|
610
|
+
}, (u, o) => {
|
|
611
|
+
u.length ? l(new p(u, o, void 0, void 0, i)) : a(o);
|
|
612
|
+
}));
|
|
613
|
+
}
|
|
614
|
+
validateSync(t, e) {
|
|
615
|
+
var r;
|
|
616
|
+
let s = this.resolve(Object.assign({}, e, {
|
|
617
|
+
value: t
|
|
618
|
+
})), i, a = (r = e == null ? void 0 : e.disableStackTrace) != null ? r : s.spec.disableStackTrace;
|
|
619
|
+
return s._validate(t, Object.assign({}, e, {
|
|
620
|
+
sync: !0
|
|
621
|
+
}), (l, u) => {
|
|
622
|
+
throw p.isError(l) && (l.value = u), l;
|
|
623
|
+
}, (l, u) => {
|
|
624
|
+
if (l.length) throw new p(l, t, void 0, void 0, a);
|
|
625
|
+
i = u;
|
|
626
|
+
}), i;
|
|
627
|
+
}
|
|
628
|
+
isValid(t, e) {
|
|
629
|
+
return this.validate(t, e).then(() => !0, (r) => {
|
|
630
|
+
if (p.isError(r)) return !1;
|
|
631
|
+
throw r;
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
isValidSync(t, e) {
|
|
635
|
+
try {
|
|
636
|
+
return this.validateSync(t, e), !0;
|
|
637
|
+
} catch (r) {
|
|
638
|
+
if (p.isError(r)) return !1;
|
|
639
|
+
throw r;
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
_getDefault(t) {
|
|
643
|
+
let e = this.spec.default;
|
|
644
|
+
return e == null ? e : typeof e == "function" ? e.call(this, t) : T(e);
|
|
645
|
+
}
|
|
646
|
+
getDefault(t) {
|
|
647
|
+
return this.resolve(t || {})._getDefault(t);
|
|
648
|
+
}
|
|
649
|
+
default(t) {
|
|
650
|
+
return arguments.length === 0 ? this._getDefault() : this.clone({
|
|
651
|
+
default: t
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
strict(t = !0) {
|
|
655
|
+
return this.clone({
|
|
656
|
+
strict: t
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
nullability(t, e) {
|
|
660
|
+
const r = this.clone({
|
|
661
|
+
nullable: t
|
|
662
|
+
});
|
|
663
|
+
return r.internalTests.nullable = k({
|
|
664
|
+
message: e,
|
|
665
|
+
name: "nullable",
|
|
666
|
+
test(s) {
|
|
667
|
+
return s === null ? this.schema.spec.nullable : !0;
|
|
668
|
+
}
|
|
669
|
+
}), r;
|
|
670
|
+
}
|
|
671
|
+
optionality(t, e) {
|
|
672
|
+
const r = this.clone({
|
|
673
|
+
optional: t
|
|
674
|
+
});
|
|
675
|
+
return r.internalTests.optionality = k({
|
|
676
|
+
message: e,
|
|
677
|
+
name: "optionality",
|
|
678
|
+
test(s) {
|
|
679
|
+
return s === void 0 ? this.schema.spec.optional : !0;
|
|
680
|
+
}
|
|
681
|
+
}), r;
|
|
682
|
+
}
|
|
683
|
+
optional() {
|
|
684
|
+
return this.optionality(!0);
|
|
685
|
+
}
|
|
686
|
+
defined(t = F.defined) {
|
|
687
|
+
return this.optionality(!1, t);
|
|
688
|
+
}
|
|
689
|
+
nullable() {
|
|
690
|
+
return this.nullability(!0);
|
|
691
|
+
}
|
|
692
|
+
nonNullable(t = F.notNull) {
|
|
693
|
+
return this.nullability(!1, t);
|
|
694
|
+
}
|
|
695
|
+
required(t = F.required) {
|
|
696
|
+
return this.clone().withMutation((e) => e.nonNullable(t).defined(t));
|
|
697
|
+
}
|
|
698
|
+
notRequired() {
|
|
699
|
+
return this.clone().withMutation((t) => t.nullable().optional());
|
|
700
|
+
}
|
|
701
|
+
transform(t) {
|
|
702
|
+
let e = this.clone();
|
|
703
|
+
return e.transforms.push(t), e;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Adds a test function to the schema's queue of tests.
|
|
707
|
+
* tests can be exclusive or non-exclusive.
|
|
708
|
+
*
|
|
709
|
+
* - exclusive tests, will replace any existing tests of the same name.
|
|
710
|
+
* - non-exclusive: can be stacked
|
|
711
|
+
*
|
|
712
|
+
* If a non-exclusive test is added to a schema with an exclusive test of the same name
|
|
713
|
+
* the exclusive test is removed and further tests of the same name will be stacked.
|
|
714
|
+
*
|
|
715
|
+
* If an exclusive test is added to a schema with non-exclusive tests of the same name
|
|
716
|
+
* the previous tests are removed and further tests of the same name will replace each other.
|
|
717
|
+
*/
|
|
718
|
+
test(...t) {
|
|
719
|
+
let e;
|
|
720
|
+
if (t.length === 1 ? typeof t[0] == "function" ? e = {
|
|
721
|
+
test: t[0]
|
|
722
|
+
} : e = t[0] : t.length === 2 ? e = {
|
|
723
|
+
name: t[0],
|
|
724
|
+
test: t[1]
|
|
725
|
+
} : e = {
|
|
726
|
+
name: t[0],
|
|
727
|
+
message: t[1],
|
|
728
|
+
test: t[2]
|
|
729
|
+
}, e.message === void 0 && (e.message = F.default), typeof e.test != "function") throw new TypeError("`test` is a required parameters");
|
|
730
|
+
let r = this.clone(), s = k(e), i = e.exclusive || e.name && r.exclusiveTests[e.name] === !0;
|
|
731
|
+
if (e.exclusive && !e.name)
|
|
732
|
+
throw new TypeError("Exclusive tests must provide a unique `name` identifying the test");
|
|
733
|
+
return e.name && (r.exclusiveTests[e.name] = !!e.exclusive), r.tests = r.tests.filter((a) => !(a.OPTIONS.name === e.name && (i || a.OPTIONS.test === s.OPTIONS.test))), r.tests.push(s), r;
|
|
734
|
+
}
|
|
735
|
+
when(t, e) {
|
|
736
|
+
!Array.isArray(t) && typeof t != "string" && (e = t, t = ".");
|
|
737
|
+
let r = this.clone(), s = te(t).map((i) => new E(i));
|
|
738
|
+
return s.forEach((i) => {
|
|
739
|
+
i.isSibling && r.deps.push(i.key);
|
|
740
|
+
}), r.conditions.push(typeof e == "function" ? new R(s, e) : R.fromOptions(s, e)), r;
|
|
741
|
+
}
|
|
742
|
+
typeError(t) {
|
|
743
|
+
let e = this.clone();
|
|
744
|
+
return e.internalTests.typeError = k({
|
|
745
|
+
message: t,
|
|
746
|
+
name: "typeError",
|
|
747
|
+
skipAbsent: !0,
|
|
748
|
+
test(r) {
|
|
749
|
+
return this.schema._typeCheck(r) ? !0 : this.createError({
|
|
750
|
+
params: {
|
|
751
|
+
type: this.schema.type
|
|
752
|
+
}
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
}), e;
|
|
756
|
+
}
|
|
757
|
+
oneOf(t, e = F.oneOf) {
|
|
758
|
+
let r = this.clone();
|
|
759
|
+
return t.forEach((s) => {
|
|
760
|
+
r._whitelist.add(s), r._blacklist.delete(s);
|
|
761
|
+
}), r.internalTests.whiteList = k({
|
|
762
|
+
message: e,
|
|
763
|
+
name: "oneOf",
|
|
764
|
+
skipAbsent: !0,
|
|
765
|
+
test(s) {
|
|
766
|
+
let i = this.schema._whitelist, a = i.resolveAll(this.resolve);
|
|
767
|
+
return a.includes(s) ? !0 : this.createError({
|
|
768
|
+
params: {
|
|
769
|
+
values: Array.from(i).join(", "),
|
|
770
|
+
resolved: a
|
|
771
|
+
}
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}), r;
|
|
775
|
+
}
|
|
776
|
+
notOneOf(t, e = F.notOneOf) {
|
|
777
|
+
let r = this.clone();
|
|
778
|
+
return t.forEach((s) => {
|
|
779
|
+
r._blacklist.add(s), r._whitelist.delete(s);
|
|
780
|
+
}), r.internalTests.blacklist = k({
|
|
781
|
+
message: e,
|
|
782
|
+
name: "notOneOf",
|
|
783
|
+
test(s) {
|
|
784
|
+
let i = this.schema._blacklist, a = i.resolveAll(this.resolve);
|
|
785
|
+
return a.includes(s) ? this.createError({
|
|
786
|
+
params: {
|
|
787
|
+
values: Array.from(i).join(", "),
|
|
788
|
+
resolved: a
|
|
789
|
+
}
|
|
790
|
+
}) : !0;
|
|
791
|
+
}
|
|
792
|
+
}), r;
|
|
793
|
+
}
|
|
794
|
+
strip(t = !0) {
|
|
795
|
+
let e = this.clone();
|
|
796
|
+
return e.spec.strip = t, e;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Return a serialized description of the schema including validations, flags, types etc.
|
|
800
|
+
*
|
|
801
|
+
* @param options Provide any needed context for resolving runtime schema alterations (lazy, when conditions, etc).
|
|
802
|
+
*/
|
|
803
|
+
describe(t) {
|
|
804
|
+
const e = (t ? this.resolve(t) : this).clone(), {
|
|
805
|
+
label: r,
|
|
806
|
+
meta: s,
|
|
807
|
+
optional: i,
|
|
808
|
+
nullable: a
|
|
809
|
+
} = e.spec;
|
|
810
|
+
return {
|
|
811
|
+
meta: s,
|
|
812
|
+
label: r,
|
|
813
|
+
optional: i,
|
|
814
|
+
nullable: a,
|
|
815
|
+
default: e.getDefault(t),
|
|
816
|
+
type: e.type,
|
|
817
|
+
oneOf: e._whitelist.describe(),
|
|
818
|
+
notOneOf: e._blacklist.describe(),
|
|
819
|
+
tests: e.tests.filter((u, o, c) => c.findIndex((h) => h.OPTIONS.name === u.OPTIONS.name) === o).map((u) => {
|
|
820
|
+
const o = u.OPTIONS.params && t ? ie(Object.assign({}, u.OPTIONS.params), t) : u.OPTIONS.params;
|
|
821
|
+
return {
|
|
822
|
+
name: u.OPTIONS.name,
|
|
823
|
+
params: o
|
|
824
|
+
};
|
|
825
|
+
})
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
get "~standard"() {
|
|
829
|
+
const t = this;
|
|
830
|
+
return {
|
|
831
|
+
version: 1,
|
|
832
|
+
vendor: "yup",
|
|
833
|
+
async validate(r) {
|
|
834
|
+
try {
|
|
835
|
+
return {
|
|
836
|
+
value: await t.validate(r, {
|
|
837
|
+
abortEarly: !1
|
|
838
|
+
})
|
|
839
|
+
};
|
|
840
|
+
} catch (s) {
|
|
841
|
+
if (s instanceof p)
|
|
842
|
+
return {
|
|
843
|
+
issues: le(s)
|
|
844
|
+
};
|
|
845
|
+
throw s;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
$.prototype.__isYupSchema__ = !0;
|
|
852
|
+
for (const n of ["validate", "validateSync"]) $.prototype[`${n}At`] = function(t, e, r = {}) {
|
|
853
|
+
const {
|
|
854
|
+
parent: s,
|
|
855
|
+
parentPath: i,
|
|
856
|
+
schema: a
|
|
857
|
+
} = xe(this, t, e, r.context);
|
|
858
|
+
return a[n](s && s[i], Object.assign({}, r, {
|
|
859
|
+
parent: s,
|
|
860
|
+
path: t
|
|
861
|
+
}));
|
|
862
|
+
};
|
|
863
|
+
for (const n of ["equals", "is"]) $.prototype[n] = $.prototype.oneOf;
|
|
864
|
+
for (const n of ["not", "nope"]) $.prototype[n] = $.prototype.notOneOf;
|
|
865
|
+
const Se = /^(\d{4}|[+-]\d{6})(?:-?(\d{2})(?:-?(\d{2}))?)?(?:[ T]?(\d{2}):?(\d{2})(?::?(\d{2})(?:[,.](\d{1,}))?)?(?:(Z)|([+-])(\d{2})(?::?(\d{2}))?)?)?$/;
|
|
866
|
+
function Ee(n) {
|
|
867
|
+
const t = Z(n);
|
|
868
|
+
if (!t) return Date.parse ? Date.parse(n) : Number.NaN;
|
|
869
|
+
if (t.z === void 0 && t.plusMinus === void 0)
|
|
870
|
+
return new Date(t.year, t.month, t.day, t.hour, t.minute, t.second, t.millisecond).valueOf();
|
|
871
|
+
let e = 0;
|
|
872
|
+
return t.z !== "Z" && t.plusMinus !== void 0 && (e = t.hourOffset * 60 + t.minuteOffset, t.plusMinus === "+" && (e = 0 - e)), Date.UTC(t.year, t.month, t.day, t.hour, t.minute + e, t.second, t.millisecond);
|
|
873
|
+
}
|
|
874
|
+
function Z(n) {
|
|
875
|
+
var t, e;
|
|
876
|
+
const r = Se.exec(n);
|
|
877
|
+
return r ? {
|
|
878
|
+
year: O(r[1]),
|
|
879
|
+
month: O(r[2], 1) - 1,
|
|
880
|
+
day: O(r[3], 1),
|
|
881
|
+
hour: O(r[4]),
|
|
882
|
+
minute: O(r[5]),
|
|
883
|
+
second: O(r[6]),
|
|
884
|
+
millisecond: r[7] ? (
|
|
885
|
+
// allow arbitrary sub-second precision beyond milliseconds
|
|
886
|
+
O(r[7].substring(0, 3))
|
|
887
|
+
) : 0,
|
|
888
|
+
precision: (t = (e = r[7]) == null ? void 0 : e.length) != null ? t : void 0,
|
|
889
|
+
z: r[8] || void 0,
|
|
890
|
+
plusMinus: r[9] || void 0,
|
|
891
|
+
hourOffset: O(r[10]),
|
|
892
|
+
minuteOffset: O(r[11])
|
|
893
|
+
} : null;
|
|
894
|
+
}
|
|
895
|
+
function O(n, t = 0) {
|
|
896
|
+
return Number(n) || t;
|
|
897
|
+
}
|
|
898
|
+
let ke = (
|
|
899
|
+
// eslint-disable-next-line
|
|
900
|
+
/^[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])?)*$/
|
|
901
|
+
), Te = (
|
|
902
|
+
// eslint-disable-next-line
|
|
903
|
+
/^((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
|
|
904
|
+
), De = /^(?:[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, je = "^\\d{4}-\\d{2}-\\d{2}", Ae = "\\d{2}:\\d{2}:\\d{2}", Ne = "(([+-]\\d{2}(:?\\d{2})?)|Z)", Ce = new RegExp(`${je}T${Ae}(\\.\\d+)?${Ne}$`), Ie = (n) => v(n) || n === n.trim(), Re = {}.toString();
|
|
905
|
+
function Pe() {
|
|
906
|
+
return new ue();
|
|
907
|
+
}
|
|
908
|
+
class ue extends $ {
|
|
909
|
+
constructor() {
|
|
910
|
+
super({
|
|
911
|
+
type: "string",
|
|
912
|
+
check(t) {
|
|
913
|
+
return t instanceof String && (t = t.valueOf()), typeof t == "string";
|
|
914
|
+
}
|
|
915
|
+
}), this.withMutation(() => {
|
|
916
|
+
this.transform((t, e) => {
|
|
917
|
+
if (!this.spec.coerce || this.isType(t) || Array.isArray(t)) return t;
|
|
918
|
+
const r = t != null && t.toString ? t.toString() : t;
|
|
919
|
+
return r === Re ? t : r;
|
|
920
|
+
});
|
|
921
|
+
});
|
|
922
|
+
}
|
|
923
|
+
required(t) {
|
|
924
|
+
return super.required(t).withMutation((e) => e.test({
|
|
925
|
+
message: t || F.required,
|
|
926
|
+
name: "required",
|
|
927
|
+
skipAbsent: !0,
|
|
928
|
+
test: (r) => !!r.length
|
|
929
|
+
}));
|
|
930
|
+
}
|
|
931
|
+
notRequired() {
|
|
932
|
+
return super.notRequired().withMutation((t) => (t.tests = t.tests.filter((e) => e.OPTIONS.name !== "required"), t));
|
|
933
|
+
}
|
|
934
|
+
length(t, e = m.length) {
|
|
935
|
+
return this.test({
|
|
936
|
+
message: e,
|
|
937
|
+
name: "length",
|
|
938
|
+
exclusive: !0,
|
|
939
|
+
params: {
|
|
940
|
+
length: t
|
|
941
|
+
},
|
|
942
|
+
skipAbsent: !0,
|
|
943
|
+
test(r) {
|
|
944
|
+
return r.length === this.resolve(t);
|
|
945
|
+
}
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
min(t, e = m.min) {
|
|
949
|
+
return this.test({
|
|
950
|
+
message: e,
|
|
951
|
+
name: "min",
|
|
952
|
+
exclusive: !0,
|
|
953
|
+
params: {
|
|
954
|
+
min: t
|
|
955
|
+
},
|
|
956
|
+
skipAbsent: !0,
|
|
957
|
+
test(r) {
|
|
958
|
+
return r.length >= this.resolve(t);
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
max(t, e = m.max) {
|
|
963
|
+
return this.test({
|
|
964
|
+
name: "max",
|
|
965
|
+
exclusive: !0,
|
|
966
|
+
message: e,
|
|
967
|
+
params: {
|
|
968
|
+
max: t
|
|
969
|
+
},
|
|
970
|
+
skipAbsent: !0,
|
|
971
|
+
test(r) {
|
|
972
|
+
return r.length <= this.resolve(t);
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
matches(t, e) {
|
|
977
|
+
let r = !1, s, i;
|
|
978
|
+
return e && (typeof e == "object" ? {
|
|
979
|
+
excludeEmptyString: r = !1,
|
|
980
|
+
message: s,
|
|
981
|
+
name: i
|
|
982
|
+
} = e : s = e), this.test({
|
|
983
|
+
name: i || "matches",
|
|
984
|
+
message: s || m.matches,
|
|
985
|
+
params: {
|
|
986
|
+
regex: t
|
|
987
|
+
},
|
|
988
|
+
skipAbsent: !0,
|
|
989
|
+
test: (a) => a === "" && r || a.search(t) !== -1
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
email(t = m.email) {
|
|
993
|
+
return this.matches(ke, {
|
|
994
|
+
name: "email",
|
|
995
|
+
message: t,
|
|
996
|
+
excludeEmptyString: !0
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
url(t = m.url) {
|
|
1000
|
+
return this.matches(Te, {
|
|
1001
|
+
name: "url",
|
|
1002
|
+
message: t,
|
|
1003
|
+
excludeEmptyString: !0
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
uuid(t = m.uuid) {
|
|
1007
|
+
return this.matches(De, {
|
|
1008
|
+
name: "uuid",
|
|
1009
|
+
message: t,
|
|
1010
|
+
excludeEmptyString: !1
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
datetime(t) {
|
|
1014
|
+
let e = "", r, s;
|
|
1015
|
+
return t && (typeof t == "object" ? {
|
|
1016
|
+
message: e = "",
|
|
1017
|
+
allowOffset: r = !1,
|
|
1018
|
+
precision: s = void 0
|
|
1019
|
+
} = t : e = t), this.matches(Ce, {
|
|
1020
|
+
name: "datetime",
|
|
1021
|
+
message: e || m.datetime,
|
|
1022
|
+
excludeEmptyString: !0
|
|
1023
|
+
}).test({
|
|
1024
|
+
name: "datetime_offset",
|
|
1025
|
+
message: e || m.datetime_offset,
|
|
1026
|
+
params: {
|
|
1027
|
+
allowOffset: r
|
|
1028
|
+
},
|
|
1029
|
+
skipAbsent: !0,
|
|
1030
|
+
test: (i) => {
|
|
1031
|
+
if (!i || r) return !0;
|
|
1032
|
+
const a = Z(i);
|
|
1033
|
+
return a ? !!a.z : !1;
|
|
1034
|
+
}
|
|
1035
|
+
}).test({
|
|
1036
|
+
name: "datetime_precision",
|
|
1037
|
+
message: e || m.datetime_precision,
|
|
1038
|
+
params: {
|
|
1039
|
+
precision: s
|
|
1040
|
+
},
|
|
1041
|
+
skipAbsent: !0,
|
|
1042
|
+
test: (i) => {
|
|
1043
|
+
if (!i || s == null) return !0;
|
|
1044
|
+
const a = Z(i);
|
|
1045
|
+
return a ? a.precision === s : !1;
|
|
1046
|
+
}
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
//-- transforms --
|
|
1050
|
+
ensure() {
|
|
1051
|
+
return this.default("").transform((t) => t === null ? "" : t);
|
|
1052
|
+
}
|
|
1053
|
+
trim(t = m.trim) {
|
|
1054
|
+
return this.transform((e) => e != null ? e.trim() : e).test({
|
|
1055
|
+
message: t,
|
|
1056
|
+
name: "trim",
|
|
1057
|
+
test: Ie
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
lowercase(t = m.lowercase) {
|
|
1061
|
+
return this.transform((e) => v(e) ? e : e.toLowerCase()).test({
|
|
1062
|
+
message: t,
|
|
1063
|
+
name: "string_case",
|
|
1064
|
+
exclusive: !0,
|
|
1065
|
+
skipAbsent: !0,
|
|
1066
|
+
test: (e) => v(e) || e === e.toLowerCase()
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
uppercase(t = m.uppercase) {
|
|
1070
|
+
return this.transform((e) => v(e) ? e : e.toUpperCase()).test({
|
|
1071
|
+
message: t,
|
|
1072
|
+
name: "string_case",
|
|
1073
|
+
exclusive: !0,
|
|
1074
|
+
skipAbsent: !0,
|
|
1075
|
+
test: (e) => v(e) || e === e.toUpperCase()
|
|
1076
|
+
});
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
Pe.prototype = ue.prototype;
|
|
1080
|
+
let Me = /* @__PURE__ */ new Date(""), ze = (n) => Object.prototype.toString.call(n) === "[object Date]";
|
|
1081
|
+
class Y extends $ {
|
|
1082
|
+
constructor() {
|
|
1083
|
+
super({
|
|
1084
|
+
type: "date",
|
|
1085
|
+
check(t) {
|
|
1086
|
+
return ze(t) && !isNaN(t.getTime());
|
|
1087
|
+
}
|
|
1088
|
+
}), this.withMutation(() => {
|
|
1089
|
+
this.transform((t, e) => !this.spec.coerce || this.isType(t) || t === null ? t : (t = Ee(t), isNaN(t) ? Y.INVALID_DATE : new Date(t)));
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
prepareParam(t, e) {
|
|
1093
|
+
let r;
|
|
1094
|
+
if (E.isRef(t))
|
|
1095
|
+
r = t;
|
|
1096
|
+
else {
|
|
1097
|
+
let s = this.cast(t);
|
|
1098
|
+
if (!this._typeCheck(s)) throw new TypeError(`\`${e}\` must be a Date or a value that can be \`cast()\` to a Date`);
|
|
1099
|
+
r = s;
|
|
1100
|
+
}
|
|
1101
|
+
return r;
|
|
1102
|
+
}
|
|
1103
|
+
min(t, e = q.min) {
|
|
1104
|
+
let r = this.prepareParam(t, "min");
|
|
1105
|
+
return this.test({
|
|
1106
|
+
message: e,
|
|
1107
|
+
name: "min",
|
|
1108
|
+
exclusive: !0,
|
|
1109
|
+
params: {
|
|
1110
|
+
min: t
|
|
1111
|
+
},
|
|
1112
|
+
skipAbsent: !0,
|
|
1113
|
+
test(s) {
|
|
1114
|
+
return s >= this.resolve(r);
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
}
|
|
1118
|
+
max(t, e = q.max) {
|
|
1119
|
+
let r = this.prepareParam(t, "max");
|
|
1120
|
+
return this.test({
|
|
1121
|
+
message: e,
|
|
1122
|
+
name: "max",
|
|
1123
|
+
exclusive: !0,
|
|
1124
|
+
params: {
|
|
1125
|
+
max: t
|
|
1126
|
+
},
|
|
1127
|
+
skipAbsent: !0,
|
|
1128
|
+
test(s) {
|
|
1129
|
+
return s <= this.resolve(r);
|
|
1130
|
+
}
|
|
1131
|
+
});
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
Y.INVALID_DATE = Me;
|
|
1135
|
+
function Ve(n, t = []) {
|
|
1136
|
+
let e = [], r = /* @__PURE__ */ new Set(), s = new Set(t.map(([a, l]) => `${a}-${l}`));
|
|
1137
|
+
function i(a, l) {
|
|
1138
|
+
let u = S.split(a)[0];
|
|
1139
|
+
r.add(u), s.has(`${l}-${u}`) || e.push([l, u]);
|
|
1140
|
+
}
|
|
1141
|
+
for (const a of Object.keys(n)) {
|
|
1142
|
+
let l = n[a];
|
|
1143
|
+
r.add(a), E.isRef(l) && l.isSibling ? i(l.path, a) : L(l) && "deps" in l && l.deps.forEach((u) => i(u, a));
|
|
1144
|
+
}
|
|
1145
|
+
return he.array(Array.from(r), e).reverse();
|
|
1146
|
+
}
|
|
1147
|
+
function X(n, t) {
|
|
1148
|
+
let e = 1 / 0;
|
|
1149
|
+
return n.some((r, s) => {
|
|
1150
|
+
var i;
|
|
1151
|
+
if ((i = t.path) != null && i.includes(r))
|
|
1152
|
+
return e = s, !0;
|
|
1153
|
+
}), e;
|
|
1154
|
+
}
|
|
1155
|
+
function oe(n) {
|
|
1156
|
+
return (t, e) => X(n, t) - X(n, e);
|
|
1157
|
+
}
|
|
1158
|
+
const Ue = (n, t, e) => {
|
|
1159
|
+
if (typeof n != "string")
|
|
1160
|
+
return n;
|
|
1161
|
+
let r = n;
|
|
1162
|
+
try {
|
|
1163
|
+
r = JSON.parse(n);
|
|
1164
|
+
} catch {
|
|
1165
|
+
}
|
|
1166
|
+
return e.isType(r) ? r : n;
|
|
1167
|
+
};
|
|
1168
|
+
function I(n) {
|
|
1169
|
+
if ("fields" in n) {
|
|
1170
|
+
const t = {};
|
|
1171
|
+
for (const [e, r] of Object.entries(n.fields))
|
|
1172
|
+
t[e] = I(r);
|
|
1173
|
+
return n.setFields(t);
|
|
1174
|
+
}
|
|
1175
|
+
if (n.type === "array") {
|
|
1176
|
+
const t = n.optional();
|
|
1177
|
+
return t.innerType && (t.innerType = I(t.innerType)), t;
|
|
1178
|
+
}
|
|
1179
|
+
return n.type === "tuple" ? n.optional().clone({
|
|
1180
|
+
types: n.spec.types.map(I)
|
|
1181
|
+
}) : "optional" in n ? n.optional() : n;
|
|
1182
|
+
}
|
|
1183
|
+
const qe = (n, t) => {
|
|
1184
|
+
const e = [...S.normalizePath(t)];
|
|
1185
|
+
if (e.length === 1) return e[0] in n;
|
|
1186
|
+
let r = e.pop(), s = S.getter(S.join(e), !0)(n);
|
|
1187
|
+
return !!(s && r in s);
|
|
1188
|
+
};
|
|
1189
|
+
let W = (n) => Object.prototype.toString.call(n) === "[object Object]";
|
|
1190
|
+
function ee(n, t) {
|
|
1191
|
+
let e = Object.keys(n.fields);
|
|
1192
|
+
return Object.keys(t).filter((r) => e.indexOf(r) === -1);
|
|
1193
|
+
}
|
|
1194
|
+
const Ze = oe([]);
|
|
1195
|
+
function Le(n) {
|
|
1196
|
+
return new ce(n);
|
|
1197
|
+
}
|
|
1198
|
+
class ce extends $ {
|
|
1199
|
+
constructor(t) {
|
|
1200
|
+
super({
|
|
1201
|
+
type: "object",
|
|
1202
|
+
check(e) {
|
|
1203
|
+
return W(e) || typeof e == "function";
|
|
1204
|
+
}
|
|
1205
|
+
}), this.fields = /* @__PURE__ */ Object.create(null), this._sortErrors = Ze, this._nodes = [], this._excludedEdges = [], this.withMutation(() => {
|
|
1206
|
+
t && this.shape(t);
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
_cast(t, e = {}) {
|
|
1210
|
+
var r;
|
|
1211
|
+
let s = super._cast(t, e);
|
|
1212
|
+
if (s === void 0) return this.getDefault(e);
|
|
1213
|
+
if (!this._typeCheck(s)) return s;
|
|
1214
|
+
let i = this.fields, a = (r = e.stripUnknown) != null ? r : this.spec.noUnknown, l = [].concat(this._nodes, Object.keys(s).filter((h) => !this._nodes.includes(h))), u = {}, o = Object.assign({}, e, {
|
|
1215
|
+
parent: u,
|
|
1216
|
+
__validating: e.__validating || !1
|
|
1217
|
+
}), c = !1;
|
|
1218
|
+
for (const h of l) {
|
|
1219
|
+
let f = i[h], g = h in s, b = s[h];
|
|
1220
|
+
if (f) {
|
|
1221
|
+
let y;
|
|
1222
|
+
o.path = (e.path ? `${e.path}.` : "") + h, f = f.resolve({
|
|
1223
|
+
value: b,
|
|
1224
|
+
context: e.context,
|
|
1225
|
+
parent: u
|
|
1226
|
+
});
|
|
1227
|
+
let w = f instanceof $ ? f.spec : void 0, D = w == null ? void 0 : w.strict;
|
|
1228
|
+
if (w != null && w.strip) {
|
|
1229
|
+
c = c || h in s;
|
|
1230
|
+
continue;
|
|
1231
|
+
}
|
|
1232
|
+
y = !e.__validating || !D ? f.cast(b, o) : b, y !== void 0 && (u[h] = y);
|
|
1233
|
+
} else g && !a && (u[h] = b);
|
|
1234
|
+
(g !== h in u || u[h] !== b) && (c = !0);
|
|
1235
|
+
}
|
|
1236
|
+
return c ? u : s;
|
|
1237
|
+
}
|
|
1238
|
+
_validate(t, e = {}, r, s) {
|
|
1239
|
+
let {
|
|
1240
|
+
from: i = [],
|
|
1241
|
+
originalValue: a = t,
|
|
1242
|
+
recursive: l = this.spec.recursive
|
|
1243
|
+
} = e;
|
|
1244
|
+
e.from = [{
|
|
1245
|
+
schema: this,
|
|
1246
|
+
value: a
|
|
1247
|
+
}, ...i], e.__validating = !0, e.originalValue = a, super._validate(t, e, r, (u, o) => {
|
|
1248
|
+
if (!l || !W(o)) {
|
|
1249
|
+
s(u, o);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
a = a || o;
|
|
1253
|
+
let c = [];
|
|
1254
|
+
for (let h of this._nodes) {
|
|
1255
|
+
let f = this.fields[h];
|
|
1256
|
+
!f || E.isRef(f) || c.push(f.asNestedTest({
|
|
1257
|
+
options: e,
|
|
1258
|
+
key: h,
|
|
1259
|
+
parent: o,
|
|
1260
|
+
parentPath: e.path,
|
|
1261
|
+
originalParent: a
|
|
1262
|
+
}));
|
|
1263
|
+
}
|
|
1264
|
+
this.runTests({
|
|
1265
|
+
tests: c,
|
|
1266
|
+
value: o,
|
|
1267
|
+
originalValue: a,
|
|
1268
|
+
options: e
|
|
1269
|
+
}, r, (h) => {
|
|
1270
|
+
s(h.sort(this._sortErrors).concat(u), o);
|
|
1271
|
+
});
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
clone(t) {
|
|
1275
|
+
const e = super.clone(t);
|
|
1276
|
+
return e.fields = Object.assign({}, this.fields), e._nodes = this._nodes, e._excludedEdges = this._excludedEdges, e._sortErrors = this._sortErrors, e;
|
|
1277
|
+
}
|
|
1278
|
+
concat(t) {
|
|
1279
|
+
let e = super.concat(t), r = e.fields;
|
|
1280
|
+
for (let [s, i] of Object.entries(this.fields)) {
|
|
1281
|
+
const a = r[s];
|
|
1282
|
+
r[s] = a === void 0 ? i : a;
|
|
1283
|
+
}
|
|
1284
|
+
return e.withMutation((s) => (
|
|
1285
|
+
// XXX: excludes here is wrong
|
|
1286
|
+
s.setFields(r, [...this._excludedEdges, ...t._excludedEdges])
|
|
1287
|
+
));
|
|
1288
|
+
}
|
|
1289
|
+
_getDefault(t) {
|
|
1290
|
+
if ("default" in this.spec)
|
|
1291
|
+
return super._getDefault(t);
|
|
1292
|
+
if (!this._nodes.length)
|
|
1293
|
+
return;
|
|
1294
|
+
let e = {};
|
|
1295
|
+
return this._nodes.forEach((r) => {
|
|
1296
|
+
var s;
|
|
1297
|
+
const i = this.fields[r];
|
|
1298
|
+
let a = t;
|
|
1299
|
+
(s = a) != null && s.value && (a = Object.assign({}, a, {
|
|
1300
|
+
parent: a.value,
|
|
1301
|
+
value: a.value[r]
|
|
1302
|
+
})), e[r] = i && "getDefault" in i ? i.getDefault(a) : void 0;
|
|
1303
|
+
}), e;
|
|
1304
|
+
}
|
|
1305
|
+
setFields(t, e) {
|
|
1306
|
+
let r = this.clone();
|
|
1307
|
+
return r.fields = t, r._nodes = Ve(t, e), r._sortErrors = oe(Object.keys(t)), e && (r._excludedEdges = e), r;
|
|
1308
|
+
}
|
|
1309
|
+
shape(t, e = []) {
|
|
1310
|
+
return this.clone().withMutation((r) => {
|
|
1311
|
+
let s = r._excludedEdges;
|
|
1312
|
+
return e.length && (Array.isArray(e[0]) || (e = [e]), s = [...r._excludedEdges, ...e]), r.setFields(Object.assign(r.fields, t), s);
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
partial() {
|
|
1316
|
+
const t = {};
|
|
1317
|
+
for (const [e, r] of Object.entries(this.fields))
|
|
1318
|
+
t[e] = "optional" in r && r.optional instanceof Function ? r.optional() : r;
|
|
1319
|
+
return this.setFields(t);
|
|
1320
|
+
}
|
|
1321
|
+
deepPartial() {
|
|
1322
|
+
return I(this);
|
|
1323
|
+
}
|
|
1324
|
+
pick(t) {
|
|
1325
|
+
const e = {};
|
|
1326
|
+
for (const r of t)
|
|
1327
|
+
this.fields[r] && (e[r] = this.fields[r]);
|
|
1328
|
+
return this.setFields(e, this._excludedEdges.filter(([r, s]) => t.includes(r) && t.includes(s)));
|
|
1329
|
+
}
|
|
1330
|
+
omit(t) {
|
|
1331
|
+
const e = [];
|
|
1332
|
+
for (const r of Object.keys(this.fields))
|
|
1333
|
+
t.includes(r) || e.push(r);
|
|
1334
|
+
return this.pick(e);
|
|
1335
|
+
}
|
|
1336
|
+
from(t, e, r) {
|
|
1337
|
+
let s = S.getter(t, !0);
|
|
1338
|
+
return this.transform((i) => {
|
|
1339
|
+
if (!i) return i;
|
|
1340
|
+
let a = i;
|
|
1341
|
+
return qe(i, t) && (a = Object.assign({}, i), r || delete a[t], a[e] = s(i)), a;
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
/** Parse an input JSON string to an object */
|
|
1345
|
+
json() {
|
|
1346
|
+
return this.transform(Ue);
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Similar to `noUnknown` but only validates that an object is the right shape without stripping the unknown keys
|
|
1350
|
+
*/
|
|
1351
|
+
exact(t) {
|
|
1352
|
+
return this.test({
|
|
1353
|
+
name: "exact",
|
|
1354
|
+
exclusive: !0,
|
|
1355
|
+
message: t || C.exact,
|
|
1356
|
+
test(e) {
|
|
1357
|
+
if (e == null) return !0;
|
|
1358
|
+
const r = ee(this.schema, e);
|
|
1359
|
+
return r.length === 0 || this.createError({
|
|
1360
|
+
params: {
|
|
1361
|
+
properties: r.join(", ")
|
|
1362
|
+
}
|
|
1363
|
+
});
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
stripUnknown() {
|
|
1368
|
+
return this.clone({
|
|
1369
|
+
noUnknown: !0
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
noUnknown(t = !0, e = C.noUnknown) {
|
|
1373
|
+
typeof t != "boolean" && (e = t, t = !0);
|
|
1374
|
+
let r = this.test({
|
|
1375
|
+
name: "noUnknown",
|
|
1376
|
+
exclusive: !0,
|
|
1377
|
+
message: e,
|
|
1378
|
+
test(s) {
|
|
1379
|
+
if (s == null) return !0;
|
|
1380
|
+
const i = ee(this.schema, s);
|
|
1381
|
+
return !t || i.length === 0 || this.createError({
|
|
1382
|
+
params: {
|
|
1383
|
+
unknown: i.join(", ")
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
});
|
|
1388
|
+
return r.spec.noUnknown = t, r;
|
|
1389
|
+
}
|
|
1390
|
+
unknown(t = !0, e = C.noUnknown) {
|
|
1391
|
+
return this.noUnknown(!t, e);
|
|
1392
|
+
}
|
|
1393
|
+
transformKeys(t) {
|
|
1394
|
+
return this.transform((e) => {
|
|
1395
|
+
if (!e) return e;
|
|
1396
|
+
const r = {};
|
|
1397
|
+
for (const s of Object.keys(e)) r[t(s)] = e[s];
|
|
1398
|
+
return r;
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
camelCase() {
|
|
1402
|
+
return this.transformKeys(U.camelCase);
|
|
1403
|
+
}
|
|
1404
|
+
snakeCase() {
|
|
1405
|
+
return this.transformKeys(U.snakeCase);
|
|
1406
|
+
}
|
|
1407
|
+
constantCase() {
|
|
1408
|
+
return this.transformKeys((t) => U.snakeCase(t).toUpperCase());
|
|
1409
|
+
}
|
|
1410
|
+
describe(t) {
|
|
1411
|
+
const e = (t ? this.resolve(t) : this).clone(), r = super.describe(t);
|
|
1412
|
+
r.fields = {};
|
|
1413
|
+
for (const [i, a] of Object.entries(e.fields)) {
|
|
1414
|
+
var s;
|
|
1415
|
+
let l = t;
|
|
1416
|
+
(s = l) != null && s.value && (l = Object.assign({}, l, {
|
|
1417
|
+
parent: l.value,
|
|
1418
|
+
value: l.value[i]
|
|
1419
|
+
})), r.fields[i] = a.describe(l);
|
|
1420
|
+
}
|
|
1421
|
+
return r;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
Le.prototype = ce.prototype;
|
|
3
1425
|
export {
|
|
4
|
-
|
|
1426
|
+
Y as DateSchema,
|
|
1427
|
+
ce as ObjectSchema,
|
|
1428
|
+
$ as Schema,
|
|
1429
|
+
ue as StringSchema,
|
|
1430
|
+
p as ValidationError,
|
|
1431
|
+
xe as getIn,
|
|
1432
|
+
L as isSchema,
|
|
1433
|
+
Le as object,
|
|
1434
|
+
x as printValue,
|
|
1435
|
+
Pe as string
|
|
5
1436
|
};
|