@getopenpay/openpay-js-react 0.0.2-beta.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js DELETED
@@ -1,3106 +0,0 @@
1
- import { createContext as Nt, useContext as It, useState as B, useRef as it, useEffect as ze, useCallback as et, useMemo as Ce } from "react";
2
- import { jsx as K } from "react/jsx-runtime";
3
- const ot = Nt({
4
- contextId: "",
5
- formHeight: "",
6
- referer: void 0,
7
- checkoutSecureToken: void 0
8
- }), At = () => {
9
- const r = It(ot);
10
- if (!r)
11
- throw new Error("useOpenPayElements must be used within an OpenPayElementsProvider");
12
- return r;
13
- };
14
- var T = [];
15
- for (var Be = 0; Be < 256; ++Be)
16
- T.push((Be + 256).toString(16).slice(1));
17
- function jt(r, e = 0) {
18
- return (T[r[e + 0]] + T[r[e + 1]] + T[r[e + 2]] + T[r[e + 3]] + "-" + T[r[e + 4]] + T[r[e + 5]] + "-" + T[r[e + 6]] + T[r[e + 7]] + "-" + T[r[e + 8]] + T[r[e + 9]] + "-" + T[r[e + 10]] + T[r[e + 11]] + T[r[e + 12]] + T[r[e + 13]] + T[r[e + 14]] + T[r[e + 15]]).toLowerCase();
19
- }
20
- var Oe, $t = new Uint8Array(16);
21
- function Pt() {
22
- if (!Oe && (Oe = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !Oe))
23
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
24
- return Oe($t);
25
- }
26
- var Dt = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto);
27
- const tt = {
28
- randomUUID: Dt
29
- };
30
- function Ut(r, e, t) {
31
- if (tt.randomUUID && !e && !r)
32
- return tt.randomUUID();
33
- r = r || {};
34
- var n = r.random || (r.rng || Pt)();
35
- return n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, jt(n);
36
- }
37
- const Ge = "https://cde.getopenpay.com";
38
- var x;
39
- (function(r) {
40
- r.assertEqual = (s) => s;
41
- function e(s) {
42
- }
43
- r.assertIs = e;
44
- function t(s) {
45
- throw new Error();
46
- }
47
- r.assertNever = t, r.arrayToEnum = (s) => {
48
- const a = {};
49
- for (const i of s)
50
- a[i] = i;
51
- return a;
52
- }, r.getValidEnumValues = (s) => {
53
- const a = r.objectKeys(s).filter((o) => typeof s[s[o]] != "number"), i = {};
54
- for (const o of a)
55
- i[o] = s[o];
56
- return r.objectValues(i);
57
- }, r.objectValues = (s) => r.objectKeys(s).map(function(a) {
58
- return s[a];
59
- }), r.objectKeys = typeof Object.keys == "function" ? (s) => Object.keys(s) : (s) => {
60
- const a = [];
61
- for (const i in s)
62
- Object.prototype.hasOwnProperty.call(s, i) && a.push(i);
63
- return a;
64
- }, r.find = (s, a) => {
65
- for (const i of s)
66
- if (a(i))
67
- return i;
68
- }, r.isInteger = typeof Number.isInteger == "function" ? (s) => Number.isInteger(s) : (s) => typeof s == "number" && isFinite(s) && Math.floor(s) === s;
69
- function n(s, a = " | ") {
70
- return s.map((i) => typeof i == "string" ? `'${i}'` : i).join(a);
71
- }
72
- r.joinValues = n, r.jsonStringifyReplacer = (s, a) => typeof a == "bigint" ? a.toString() : a;
73
- })(x || (x = {}));
74
- var Ke;
75
- (function(r) {
76
- r.mergeShapes = (e, t) => ({
77
- ...e,
78
- ...t
79
- // second overwrites first
80
- });
81
- })(Ke || (Ke = {}));
82
- const f = x.arrayToEnum([
83
- "string",
84
- "nan",
85
- "number",
86
- "integer",
87
- "float",
88
- "boolean",
89
- "date",
90
- "bigint",
91
- "symbol",
92
- "function",
93
- "undefined",
94
- "null",
95
- "array",
96
- "object",
97
- "unknown",
98
- "promise",
99
- "void",
100
- "never",
101
- "map",
102
- "set"
103
- ]), H = (r) => {
104
- switch (typeof r) {
105
- case "undefined":
106
- return f.undefined;
107
- case "string":
108
- return f.string;
109
- case "number":
110
- return isNaN(r) ? f.nan : f.number;
111
- case "boolean":
112
- return f.boolean;
113
- case "function":
114
- return f.function;
115
- case "bigint":
116
- return f.bigint;
117
- case "symbol":
118
- return f.symbol;
119
- case "object":
120
- return Array.isArray(r) ? f.array : r === null ? f.null : r.then && typeof r.then == "function" && r.catch && typeof r.catch == "function" ? f.promise : typeof Map < "u" && r instanceof Map ? f.map : typeof Set < "u" && r instanceof Set ? f.set : typeof Date < "u" && r instanceof Date ? f.date : f.object;
121
- default:
122
- return f.unknown;
123
- }
124
- }, c = x.arrayToEnum([
125
- "invalid_type",
126
- "invalid_literal",
127
- "custom",
128
- "invalid_union",
129
- "invalid_union_discriminator",
130
- "invalid_enum_value",
131
- "unrecognized_keys",
132
- "invalid_arguments",
133
- "invalid_return_type",
134
- "invalid_date",
135
- "invalid_string",
136
- "too_small",
137
- "too_big",
138
- "invalid_intersection_types",
139
- "not_multiple_of",
140
- "not_finite"
141
- ]), Mt = (r) => JSON.stringify(r, null, 2).replace(/"([^"]+)":/g, "$1:");
142
- class O extends Error {
143
- constructor(e) {
144
- super(), this.issues = [], this.addIssue = (n) => {
145
- this.issues = [...this.issues, n];
146
- }, this.addIssues = (n = []) => {
147
- this.issues = [...this.issues, ...n];
148
- };
149
- const t = new.target.prototype;
150
- Object.setPrototypeOf ? Object.setPrototypeOf(this, t) : this.__proto__ = t, this.name = "ZodError", this.issues = e;
151
- }
152
- get errors() {
153
- return this.issues;
154
- }
155
- format(e) {
156
- const t = e || function(a) {
157
- return a.message;
158
- }, n = { _errors: [] }, s = (a) => {
159
- for (const i of a.issues)
160
- if (i.code === "invalid_union")
161
- i.unionErrors.map(s);
162
- else if (i.code === "invalid_return_type")
163
- s(i.returnTypeError);
164
- else if (i.code === "invalid_arguments")
165
- s(i.argumentsError);
166
- else if (i.path.length === 0)
167
- n._errors.push(t(i));
168
- else {
169
- let o = n, u = 0;
170
- for (; u < i.path.length; ) {
171
- const d = i.path[u];
172
- u === i.path.length - 1 ? (o[d] = o[d] || { _errors: [] }, o[d]._errors.push(t(i))) : o[d] = o[d] || { _errors: [] }, o = o[d], u++;
173
- }
174
- }
175
- };
176
- return s(this), n;
177
- }
178
- static assert(e) {
179
- if (!(e instanceof O))
180
- throw new Error(`Not a ZodError: ${e}`);
181
- }
182
- toString() {
183
- return this.message;
184
- }
185
- get message() {
186
- return JSON.stringify(this.issues, x.jsonStringifyReplacer, 2);
187
- }
188
- get isEmpty() {
189
- return this.issues.length === 0;
190
- }
191
- flatten(e = (t) => t.message) {
192
- const t = {}, n = [];
193
- for (const s of this.issues)
194
- s.path.length > 0 ? (t[s.path[0]] = t[s.path[0]] || [], t[s.path[0]].push(e(s))) : n.push(e(s));
195
- return { formErrors: n, fieldErrors: t };
196
- }
197
- get formErrors() {
198
- return this.flatten();
199
- }
200
- }
201
- O.create = (r) => new O(r);
202
- const se = (r, e) => {
203
- let t;
204
- switch (r.code) {
205
- case c.invalid_type:
206
- r.received === f.undefined ? t = "Required" : t = `Expected ${r.expected}, received ${r.received}`;
207
- break;
208
- case c.invalid_literal:
209
- t = `Invalid literal value, expected ${JSON.stringify(r.expected, x.jsonStringifyReplacer)}`;
210
- break;
211
- case c.unrecognized_keys:
212
- t = `Unrecognized key(s) in object: ${x.joinValues(r.keys, ", ")}`;
213
- break;
214
- case c.invalid_union:
215
- t = "Invalid input";
216
- break;
217
- case c.invalid_union_discriminator:
218
- t = `Invalid discriminator value. Expected ${x.joinValues(r.options)}`;
219
- break;
220
- case c.invalid_enum_value:
221
- t = `Invalid enum value. Expected ${x.joinValues(r.options)}, received '${r.received}'`;
222
- break;
223
- case c.invalid_arguments:
224
- t = "Invalid function arguments";
225
- break;
226
- case c.invalid_return_type:
227
- t = "Invalid function return type";
228
- break;
229
- case c.invalid_date:
230
- t = "Invalid date";
231
- break;
232
- case c.invalid_string:
233
- typeof r.validation == "object" ? "includes" in r.validation ? (t = `Invalid input: must include "${r.validation.includes}"`, typeof r.validation.position == "number" && (t = `${t} at one or more positions greater than or equal to ${r.validation.position}`)) : "startsWith" in r.validation ? t = `Invalid input: must start with "${r.validation.startsWith}"` : "endsWith" in r.validation ? t = `Invalid input: must end with "${r.validation.endsWith}"` : x.assertNever(r.validation) : r.validation !== "regex" ? t = `Invalid ${r.validation}` : t = "Invalid";
234
- break;
235
- case c.too_small:
236
- r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "more than"} ${r.minimum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at least" : "over"} ${r.minimum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${r.minimum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly equal to " : r.inclusive ? "greater than or equal to " : "greater than "}${new Date(Number(r.minimum))}` : t = "Invalid input";
237
- break;
238
- case c.too_big:
239
- r.type === "array" ? t = `Array must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "less than"} ${r.maximum} element(s)` : r.type === "string" ? t = `String must contain ${r.exact ? "exactly" : r.inclusive ? "at most" : "under"} ${r.maximum} character(s)` : r.type === "number" ? t = `Number must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "bigint" ? t = `BigInt must be ${r.exact ? "exactly" : r.inclusive ? "less than or equal to" : "less than"} ${r.maximum}` : r.type === "date" ? t = `Date must be ${r.exact ? "exactly" : r.inclusive ? "smaller than or equal to" : "smaller than"} ${new Date(Number(r.maximum))}` : t = "Invalid input";
240
- break;
241
- case c.custom:
242
- t = "Invalid input";
243
- break;
244
- case c.invalid_intersection_types:
245
- t = "Intersection results could not be merged";
246
- break;
247
- case c.not_multiple_of:
248
- t = `Number must be a multiple of ${r.multipleOf}`;
249
- break;
250
- case c.not_finite:
251
- t = "Number must be finite";
252
- break;
253
- default:
254
- t = e.defaultError, x.assertNever(r);
255
- }
256
- return { message: t };
257
- };
258
- let ct = se;
259
- function Lt(r) {
260
- ct = r;
261
- }
262
- function Re() {
263
- return ct;
264
- }
265
- const Ze = (r) => {
266
- const { data: e, path: t, errorMaps: n, issueData: s } = r, a = [...t, ...s.path || []], i = {
267
- ...s,
268
- path: a
269
- };
270
- if (s.message !== void 0)
271
- return {
272
- ...s,
273
- path: a,
274
- message: s.message
275
- };
276
- let o = "";
277
- const u = n.filter((d) => !!d).slice().reverse();
278
- for (const d of u)
279
- o = d(i, { data: e, defaultError: o }).message;
280
- return {
281
- ...s,
282
- path: a,
283
- message: o
284
- };
285
- }, Vt = [];
286
- function l(r, e) {
287
- const t = Re(), n = Ze({
288
- issueData: e,
289
- data: r.data,
290
- path: r.path,
291
- errorMaps: [
292
- r.common.contextualErrorMap,
293
- r.schemaErrorMap,
294
- t,
295
- t === se ? void 0 : se
296
- // then global default map
297
- ].filter((s) => !!s)
298
- });
299
- r.common.issues.push(n);
300
- }
301
- class E {
302
- constructor() {
303
- this.value = "valid";
304
- }
305
- dirty() {
306
- this.value === "valid" && (this.value = "dirty");
307
- }
308
- abort() {
309
- this.value !== "aborted" && (this.value = "aborted");
310
- }
311
- static mergeArray(e, t) {
312
- const n = [];
313
- for (const s of t) {
314
- if (s.status === "aborted")
315
- return g;
316
- s.status === "dirty" && e.dirty(), n.push(s.value);
317
- }
318
- return { status: e.value, value: n };
319
- }
320
- static async mergeObjectAsync(e, t) {
321
- const n = [];
322
- for (const s of t) {
323
- const a = await s.key, i = await s.value;
324
- n.push({
325
- key: a,
326
- value: i
327
- });
328
- }
329
- return E.mergeObjectSync(e, n);
330
- }
331
- static mergeObjectSync(e, t) {
332
- const n = {};
333
- for (const s of t) {
334
- const { key: a, value: i } = s;
335
- if (a.status === "aborted" || i.status === "aborted")
336
- return g;
337
- a.status === "dirty" && e.dirty(), i.status === "dirty" && e.dirty(), a.value !== "__proto__" && (typeof i.value < "u" || s.alwaysSet) && (n[a.value] = i.value);
338
- }
339
- return { status: e.value, value: n };
340
- }
341
- }
342
- const g = Object.freeze({
343
- status: "aborted"
344
- }), re = (r) => ({ status: "dirty", value: r }), S = (r) => ({ status: "valid", value: r }), We = (r) => r.status === "aborted", qe = (r) => r.status === "dirty", ue = (r) => r.status === "valid", le = (r) => typeof Promise < "u" && r instanceof Promise;
345
- function Ne(r, e, t, n) {
346
- if (typeof e == "function" ? r !== e || !n : !e.has(r)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
347
- return e.get(r);
348
- }
349
- function dt(r, e, t, n, s) {
350
- if (typeof e == "function" ? r !== e || !s : !e.has(r)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
351
- return e.set(r, t), t;
352
- }
353
- var h;
354
- (function(r) {
355
- r.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, r.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message;
356
- })(h || (h = {}));
357
- var ce, de;
358
- class P {
359
- constructor(e, t, n, s) {
360
- this._cachedPath = [], this.parent = e, this.data = t, this._path = n, this._key = s;
361
- }
362
- get path() {
363
- return this._cachedPath.length || (this._key instanceof Array ? this._cachedPath.push(...this._path, ...this._key) : this._cachedPath.push(...this._path, this._key)), this._cachedPath;
364
- }
365
- }
366
- const rt = (r, e) => {
367
- if (ue(e))
368
- return { success: !0, data: e.value };
369
- if (!r.common.issues.length)
370
- throw new Error("Validation failed but no issues detected.");
371
- return {
372
- success: !1,
373
- get error() {
374
- if (this._error)
375
- return this._error;
376
- const t = new O(r.common.issues);
377
- return this._error = t, this._error;
378
- }
379
- };
380
- };
381
- function v(r) {
382
- if (!r)
383
- return {};
384
- const { errorMap: e, invalid_type_error: t, required_error: n, description: s } = r;
385
- if (e && (t || n))
386
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
387
- return e ? { errorMap: e, description: s } : { errorMap: (i, o) => {
388
- var u, d;
389
- const { message: p } = r;
390
- return i.code === "invalid_enum_value" ? { message: p ?? o.defaultError } : typeof o.data > "u" ? { message: (u = p ?? n) !== null && u !== void 0 ? u : o.defaultError } : i.code !== "invalid_type" ? { message: o.defaultError } : { message: (d = p ?? t) !== null && d !== void 0 ? d : o.defaultError };
391
- }, description: s };
392
- }
393
- class _ {
394
- constructor(e) {
395
- this.spa = this.safeParseAsync, this._def = e, this.parse = this.parse.bind(this), this.safeParse = this.safeParse.bind(this), this.parseAsync = this.parseAsync.bind(this), this.safeParseAsync = this.safeParseAsync.bind(this), this.spa = this.spa.bind(this), this.refine = this.refine.bind(this), this.refinement = this.refinement.bind(this), this.superRefine = this.superRefine.bind(this), this.optional = this.optional.bind(this), this.nullable = this.nullable.bind(this), this.nullish = this.nullish.bind(this), this.array = this.array.bind(this), this.promise = this.promise.bind(this), this.or = this.or.bind(this), this.and = this.and.bind(this), this.transform = this.transform.bind(this), this.brand = this.brand.bind(this), this.default = this.default.bind(this), this.catch = this.catch.bind(this), this.describe = this.describe.bind(this), this.pipe = this.pipe.bind(this), this.readonly = this.readonly.bind(this), this.isNullable = this.isNullable.bind(this), this.isOptional = this.isOptional.bind(this);
396
- }
397
- get description() {
398
- return this._def.description;
399
- }
400
- _getType(e) {
401
- return H(e.data);
402
- }
403
- _getOrReturnCtx(e, t) {
404
- return t || {
405
- common: e.parent.common,
406
- data: e.data,
407
- parsedType: H(e.data),
408
- schemaErrorMap: this._def.errorMap,
409
- path: e.path,
410
- parent: e.parent
411
- };
412
- }
413
- _processInputParams(e) {
414
- return {
415
- status: new E(),
416
- ctx: {
417
- common: e.parent.common,
418
- data: e.data,
419
- parsedType: H(e.data),
420
- schemaErrorMap: this._def.errorMap,
421
- path: e.path,
422
- parent: e.parent
423
- }
424
- };
425
- }
426
- _parseSync(e) {
427
- const t = this._parse(e);
428
- if (le(t))
429
- throw new Error("Synchronous parse encountered promise.");
430
- return t;
431
- }
432
- _parseAsync(e) {
433
- const t = this._parse(e);
434
- return Promise.resolve(t);
435
- }
436
- parse(e, t) {
437
- const n = this.safeParse(e, t);
438
- if (n.success)
439
- return n.data;
440
- throw n.error;
441
- }
442
- safeParse(e, t) {
443
- var n;
444
- const s = {
445
- common: {
446
- issues: [],
447
- async: (n = t == null ? void 0 : t.async) !== null && n !== void 0 ? n : !1,
448
- contextualErrorMap: t == null ? void 0 : t.errorMap
449
- },
450
- path: (t == null ? void 0 : t.path) || [],
451
- schemaErrorMap: this._def.errorMap,
452
- parent: null,
453
- data: e,
454
- parsedType: H(e)
455
- }, a = this._parseSync({ data: e, path: s.path, parent: s });
456
- return rt(s, a);
457
- }
458
- async parseAsync(e, t) {
459
- const n = await this.safeParseAsync(e, t);
460
- if (n.success)
461
- return n.data;
462
- throw n.error;
463
- }
464
- async safeParseAsync(e, t) {
465
- const n = {
466
- common: {
467
- issues: [],
468
- contextualErrorMap: t == null ? void 0 : t.errorMap,
469
- async: !0
470
- },
471
- path: (t == null ? void 0 : t.path) || [],
472
- schemaErrorMap: this._def.errorMap,
473
- parent: null,
474
- data: e,
475
- parsedType: H(e)
476
- }, s = this._parse({ data: e, path: n.path, parent: n }), a = await (le(s) ? s : Promise.resolve(s));
477
- return rt(n, a);
478
- }
479
- refine(e, t) {
480
- const n = (s) => typeof t == "string" || typeof t > "u" ? { message: t } : typeof t == "function" ? t(s) : t;
481
- return this._refinement((s, a) => {
482
- const i = e(s), o = () => a.addIssue({
483
- code: c.custom,
484
- ...n(s)
485
- });
486
- return typeof Promise < "u" && i instanceof Promise ? i.then((u) => u ? !0 : (o(), !1)) : i ? !0 : (o(), !1);
487
- });
488
- }
489
- refinement(e, t) {
490
- return this._refinement((n, s) => e(n) ? !0 : (s.addIssue(typeof t == "function" ? t(n, s) : t), !1));
491
- }
492
- _refinement(e) {
493
- return new j({
494
- schema: this,
495
- typeName: y.ZodEffects,
496
- effect: { type: "refinement", refinement: e }
497
- });
498
- }
499
- superRefine(e) {
500
- return this._refinement(e);
501
- }
502
- optional() {
503
- return $.create(this, this._def);
504
- }
505
- nullable() {
506
- return G.create(this, this._def);
507
- }
508
- nullish() {
509
- return this.nullable().optional();
510
- }
511
- array() {
512
- return A.create(this, this._def);
513
- }
514
- promise() {
515
- return ie.create(this, this._def);
516
- }
517
- or(e) {
518
- return me.create([this, e], this._def);
519
- }
520
- and(e) {
521
- return ye.create(this, e, this._def);
522
- }
523
- transform(e) {
524
- return new j({
525
- ...v(this._def),
526
- schema: this,
527
- typeName: y.ZodEffects,
528
- effect: { type: "transform", transform: e }
529
- });
530
- }
531
- default(e) {
532
- const t = typeof e == "function" ? e : () => e;
533
- return new ke({
534
- ...v(this._def),
535
- innerType: this,
536
- defaultValue: t,
537
- typeName: y.ZodDefault
538
- });
539
- }
540
- brand() {
541
- return new Je({
542
- typeName: y.ZodBranded,
543
- type: this,
544
- ...v(this._def)
545
- });
546
- }
547
- catch(e) {
548
- const t = typeof e == "function" ? e : () => e;
549
- return new be({
550
- ...v(this._def),
551
- innerType: this,
552
- catchValue: t,
553
- typeName: y.ZodCatch
554
- });
555
- }
556
- describe(e) {
557
- const t = this.constructor;
558
- return new t({
559
- ...this._def,
560
- description: e
561
- });
562
- }
563
- pipe(e) {
564
- return Te.create(this, e);
565
- }
566
- readonly() {
567
- return we.create(this);
568
- }
569
- isOptional() {
570
- return this.safeParse(void 0).success;
571
- }
572
- isNullable() {
573
- return this.safeParse(null).success;
574
- }
575
- }
576
- const zt = /^c[^\s-]{8,}$/i, Bt = /^[0-9a-z]+$/, Ht = /^[0-9A-HJKMNP-TV-Z]{26}$/, Kt = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i, Wt = /^[a-z0-9_-]{21}$/i, qt = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/, Yt = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i, Gt = "^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";
577
- let He;
578
- const Jt = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/, Xt = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/, Qt = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, ut = "((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))", Ft = new RegExp(`^${ut}$`);
579
- function lt(r) {
580
- let e = "([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";
581
- return r.precision ? e = `${e}\\.\\d{${r.precision}}` : r.precision == null && (e = `${e}(\\.\\d+)?`), e;
582
- }
583
- function er(r) {
584
- return new RegExp(`^${lt(r)}$`);
585
- }
586
- function ft(r) {
587
- let e = `${ut}T${lt(r)}`;
588
- const t = [];
589
- return t.push(r.local ? "Z?" : "Z"), r.offset && t.push("([+-]\\d{2}:?\\d{2})"), e = `${e}(${t.join("|")})`, new RegExp(`^${e}$`);
590
- }
591
- function tr(r, e) {
592
- return !!((e === "v4" || !e) && Jt.test(r) || (e === "v6" || !e) && Xt.test(r));
593
- }
594
- class I extends _ {
595
- _parse(e) {
596
- if (this._def.coerce && (e.data = String(e.data)), this._getType(e) !== f.string) {
597
- const a = this._getOrReturnCtx(e);
598
- return l(a, {
599
- code: c.invalid_type,
600
- expected: f.string,
601
- received: a.parsedType
602
- }), g;
603
- }
604
- const n = new E();
605
- let s;
606
- for (const a of this._def.checks)
607
- if (a.kind === "min")
608
- e.data.length < a.value && (s = this._getOrReturnCtx(e, s), l(s, {
609
- code: c.too_small,
610
- minimum: a.value,
611
- type: "string",
612
- inclusive: !0,
613
- exact: !1,
614
- message: a.message
615
- }), n.dirty());
616
- else if (a.kind === "max")
617
- e.data.length > a.value && (s = this._getOrReturnCtx(e, s), l(s, {
618
- code: c.too_big,
619
- maximum: a.value,
620
- type: "string",
621
- inclusive: !0,
622
- exact: !1,
623
- message: a.message
624
- }), n.dirty());
625
- else if (a.kind === "length") {
626
- const i = e.data.length > a.value, o = e.data.length < a.value;
627
- (i || o) && (s = this._getOrReturnCtx(e, s), i ? l(s, {
628
- code: c.too_big,
629
- maximum: a.value,
630
- type: "string",
631
- inclusive: !0,
632
- exact: !0,
633
- message: a.message
634
- }) : o && l(s, {
635
- code: c.too_small,
636
- minimum: a.value,
637
- type: "string",
638
- inclusive: !0,
639
- exact: !0,
640
- message: a.message
641
- }), n.dirty());
642
- } else if (a.kind === "email")
643
- Yt.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
644
- validation: "email",
645
- code: c.invalid_string,
646
- message: a.message
647
- }), n.dirty());
648
- else if (a.kind === "emoji")
649
- He || (He = new RegExp(Gt, "u")), He.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
650
- validation: "emoji",
651
- code: c.invalid_string,
652
- message: a.message
653
- }), n.dirty());
654
- else if (a.kind === "uuid")
655
- Kt.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
656
- validation: "uuid",
657
- code: c.invalid_string,
658
- message: a.message
659
- }), n.dirty());
660
- else if (a.kind === "nanoid")
661
- Wt.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
662
- validation: "nanoid",
663
- code: c.invalid_string,
664
- message: a.message
665
- }), n.dirty());
666
- else if (a.kind === "cuid")
667
- zt.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
668
- validation: "cuid",
669
- code: c.invalid_string,
670
- message: a.message
671
- }), n.dirty());
672
- else if (a.kind === "cuid2")
673
- Bt.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
674
- validation: "cuid2",
675
- code: c.invalid_string,
676
- message: a.message
677
- }), n.dirty());
678
- else if (a.kind === "ulid")
679
- Ht.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
680
- validation: "ulid",
681
- code: c.invalid_string,
682
- message: a.message
683
- }), n.dirty());
684
- else if (a.kind === "url")
685
- try {
686
- new URL(e.data);
687
- } catch {
688
- s = this._getOrReturnCtx(e, s), l(s, {
689
- validation: "url",
690
- code: c.invalid_string,
691
- message: a.message
692
- }), n.dirty();
693
- }
694
- else a.kind === "regex" ? (a.regex.lastIndex = 0, a.regex.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
695
- validation: "regex",
696
- code: c.invalid_string,
697
- message: a.message
698
- }), n.dirty())) : a.kind === "trim" ? e.data = e.data.trim() : a.kind === "includes" ? e.data.includes(a.value, a.position) || (s = this._getOrReturnCtx(e, s), l(s, {
699
- code: c.invalid_string,
700
- validation: { includes: a.value, position: a.position },
701
- message: a.message
702
- }), n.dirty()) : a.kind === "toLowerCase" ? e.data = e.data.toLowerCase() : a.kind === "toUpperCase" ? e.data = e.data.toUpperCase() : a.kind === "startsWith" ? e.data.startsWith(a.value) || (s = this._getOrReturnCtx(e, s), l(s, {
703
- code: c.invalid_string,
704
- validation: { startsWith: a.value },
705
- message: a.message
706
- }), n.dirty()) : a.kind === "endsWith" ? e.data.endsWith(a.value) || (s = this._getOrReturnCtx(e, s), l(s, {
707
- code: c.invalid_string,
708
- validation: { endsWith: a.value },
709
- message: a.message
710
- }), n.dirty()) : a.kind === "datetime" ? ft(a).test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
711
- code: c.invalid_string,
712
- validation: "datetime",
713
- message: a.message
714
- }), n.dirty()) : a.kind === "date" ? Ft.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
715
- code: c.invalid_string,
716
- validation: "date",
717
- message: a.message
718
- }), n.dirty()) : a.kind === "time" ? er(a).test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
719
- code: c.invalid_string,
720
- validation: "time",
721
- message: a.message
722
- }), n.dirty()) : a.kind === "duration" ? qt.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
723
- validation: "duration",
724
- code: c.invalid_string,
725
- message: a.message
726
- }), n.dirty()) : a.kind === "ip" ? tr(e.data, a.version) || (s = this._getOrReturnCtx(e, s), l(s, {
727
- validation: "ip",
728
- code: c.invalid_string,
729
- message: a.message
730
- }), n.dirty()) : a.kind === "base64" ? Qt.test(e.data) || (s = this._getOrReturnCtx(e, s), l(s, {
731
- validation: "base64",
732
- code: c.invalid_string,
733
- message: a.message
734
- }), n.dirty()) : x.assertNever(a);
735
- return { status: n.value, value: e.data };
736
- }
737
- _regex(e, t, n) {
738
- return this.refinement((s) => e.test(s), {
739
- validation: t,
740
- code: c.invalid_string,
741
- ...h.errToObj(n)
742
- });
743
- }
744
- _addCheck(e) {
745
- return new I({
746
- ...this._def,
747
- checks: [...this._def.checks, e]
748
- });
749
- }
750
- email(e) {
751
- return this._addCheck({ kind: "email", ...h.errToObj(e) });
752
- }
753
- url(e) {
754
- return this._addCheck({ kind: "url", ...h.errToObj(e) });
755
- }
756
- emoji(e) {
757
- return this._addCheck({ kind: "emoji", ...h.errToObj(e) });
758
- }
759
- uuid(e) {
760
- return this._addCheck({ kind: "uuid", ...h.errToObj(e) });
761
- }
762
- nanoid(e) {
763
- return this._addCheck({ kind: "nanoid", ...h.errToObj(e) });
764
- }
765
- cuid(e) {
766
- return this._addCheck({ kind: "cuid", ...h.errToObj(e) });
767
- }
768
- cuid2(e) {
769
- return this._addCheck({ kind: "cuid2", ...h.errToObj(e) });
770
- }
771
- ulid(e) {
772
- return this._addCheck({ kind: "ulid", ...h.errToObj(e) });
773
- }
774
- base64(e) {
775
- return this._addCheck({ kind: "base64", ...h.errToObj(e) });
776
- }
777
- ip(e) {
778
- return this._addCheck({ kind: "ip", ...h.errToObj(e) });
779
- }
780
- datetime(e) {
781
- var t, n;
782
- return typeof e == "string" ? this._addCheck({
783
- kind: "datetime",
784
- precision: null,
785
- offset: !1,
786
- local: !1,
787
- message: e
788
- }) : this._addCheck({
789
- kind: "datetime",
790
- precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
791
- offset: (t = e == null ? void 0 : e.offset) !== null && t !== void 0 ? t : !1,
792
- local: (n = e == null ? void 0 : e.local) !== null && n !== void 0 ? n : !1,
793
- ...h.errToObj(e == null ? void 0 : e.message)
794
- });
795
- }
796
- date(e) {
797
- return this._addCheck({ kind: "date", message: e });
798
- }
799
- time(e) {
800
- return typeof e == "string" ? this._addCheck({
801
- kind: "time",
802
- precision: null,
803
- message: e
804
- }) : this._addCheck({
805
- kind: "time",
806
- precision: typeof (e == null ? void 0 : e.precision) > "u" ? null : e == null ? void 0 : e.precision,
807
- ...h.errToObj(e == null ? void 0 : e.message)
808
- });
809
- }
810
- duration(e) {
811
- return this._addCheck({ kind: "duration", ...h.errToObj(e) });
812
- }
813
- regex(e, t) {
814
- return this._addCheck({
815
- kind: "regex",
816
- regex: e,
817
- ...h.errToObj(t)
818
- });
819
- }
820
- includes(e, t) {
821
- return this._addCheck({
822
- kind: "includes",
823
- value: e,
824
- position: t == null ? void 0 : t.position,
825
- ...h.errToObj(t == null ? void 0 : t.message)
826
- });
827
- }
828
- startsWith(e, t) {
829
- return this._addCheck({
830
- kind: "startsWith",
831
- value: e,
832
- ...h.errToObj(t)
833
- });
834
- }
835
- endsWith(e, t) {
836
- return this._addCheck({
837
- kind: "endsWith",
838
- value: e,
839
- ...h.errToObj(t)
840
- });
841
- }
842
- min(e, t) {
843
- return this._addCheck({
844
- kind: "min",
845
- value: e,
846
- ...h.errToObj(t)
847
- });
848
- }
849
- max(e, t) {
850
- return this._addCheck({
851
- kind: "max",
852
- value: e,
853
- ...h.errToObj(t)
854
- });
855
- }
856
- length(e, t) {
857
- return this._addCheck({
858
- kind: "length",
859
- value: e,
860
- ...h.errToObj(t)
861
- });
862
- }
863
- /**
864
- * @deprecated Use z.string().min(1) instead.
865
- * @see {@link ZodString.min}
866
- */
867
- nonempty(e) {
868
- return this.min(1, h.errToObj(e));
869
- }
870
- trim() {
871
- return new I({
872
- ...this._def,
873
- checks: [...this._def.checks, { kind: "trim" }]
874
- });
875
- }
876
- toLowerCase() {
877
- return new I({
878
- ...this._def,
879
- checks: [...this._def.checks, { kind: "toLowerCase" }]
880
- });
881
- }
882
- toUpperCase() {
883
- return new I({
884
- ...this._def,
885
- checks: [...this._def.checks, { kind: "toUpperCase" }]
886
- });
887
- }
888
- get isDatetime() {
889
- return !!this._def.checks.find((e) => e.kind === "datetime");
890
- }
891
- get isDate() {
892
- return !!this._def.checks.find((e) => e.kind === "date");
893
- }
894
- get isTime() {
895
- return !!this._def.checks.find((e) => e.kind === "time");
896
- }
897
- get isDuration() {
898
- return !!this._def.checks.find((e) => e.kind === "duration");
899
- }
900
- get isEmail() {
901
- return !!this._def.checks.find((e) => e.kind === "email");
902
- }
903
- get isURL() {
904
- return !!this._def.checks.find((e) => e.kind === "url");
905
- }
906
- get isEmoji() {
907
- return !!this._def.checks.find((e) => e.kind === "emoji");
908
- }
909
- get isUUID() {
910
- return !!this._def.checks.find((e) => e.kind === "uuid");
911
- }
912
- get isNANOID() {
913
- return !!this._def.checks.find((e) => e.kind === "nanoid");
914
- }
915
- get isCUID() {
916
- return !!this._def.checks.find((e) => e.kind === "cuid");
917
- }
918
- get isCUID2() {
919
- return !!this._def.checks.find((e) => e.kind === "cuid2");
920
- }
921
- get isULID() {
922
- return !!this._def.checks.find((e) => e.kind === "ulid");
923
- }
924
- get isIP() {
925
- return !!this._def.checks.find((e) => e.kind === "ip");
926
- }
927
- get isBase64() {
928
- return !!this._def.checks.find((e) => e.kind === "base64");
929
- }
930
- get minLength() {
931
- let e = null;
932
- for (const t of this._def.checks)
933
- t.kind === "min" && (e === null || t.value > e) && (e = t.value);
934
- return e;
935
- }
936
- get maxLength() {
937
- let e = null;
938
- for (const t of this._def.checks)
939
- t.kind === "max" && (e === null || t.value < e) && (e = t.value);
940
- return e;
941
- }
942
- }
943
- I.create = (r) => {
944
- var e;
945
- return new I({
946
- checks: [],
947
- typeName: y.ZodString,
948
- coerce: (e = r == null ? void 0 : r.coerce) !== null && e !== void 0 ? e : !1,
949
- ...v(r)
950
- });
951
- };
952
- function rr(r, e) {
953
- const t = (r.toString().split(".")[1] || "").length, n = (e.toString().split(".")[1] || "").length, s = t > n ? t : n, a = parseInt(r.toFixed(s).replace(".", "")), i = parseInt(e.toFixed(s).replace(".", ""));
954
- return a % i / Math.pow(10, s);
955
- }
956
- class W extends _ {
957
- constructor() {
958
- super(...arguments), this.min = this.gte, this.max = this.lte, this.step = this.multipleOf;
959
- }
960
- _parse(e) {
961
- if (this._def.coerce && (e.data = Number(e.data)), this._getType(e) !== f.number) {
962
- const a = this._getOrReturnCtx(e);
963
- return l(a, {
964
- code: c.invalid_type,
965
- expected: f.number,
966
- received: a.parsedType
967
- }), g;
968
- }
969
- let n;
970
- const s = new E();
971
- for (const a of this._def.checks)
972
- a.kind === "int" ? x.isInteger(e.data) || (n = this._getOrReturnCtx(e, n), l(n, {
973
- code: c.invalid_type,
974
- expected: "integer",
975
- received: "float",
976
- message: a.message
977
- }), s.dirty()) : a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (n = this._getOrReturnCtx(e, n), l(n, {
978
- code: c.too_small,
979
- minimum: a.value,
980
- type: "number",
981
- inclusive: a.inclusive,
982
- exact: !1,
983
- message: a.message
984
- }), s.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (n = this._getOrReturnCtx(e, n), l(n, {
985
- code: c.too_big,
986
- maximum: a.value,
987
- type: "number",
988
- inclusive: a.inclusive,
989
- exact: !1,
990
- message: a.message
991
- }), s.dirty()) : a.kind === "multipleOf" ? rr(e.data, a.value) !== 0 && (n = this._getOrReturnCtx(e, n), l(n, {
992
- code: c.not_multiple_of,
993
- multipleOf: a.value,
994
- message: a.message
995
- }), s.dirty()) : a.kind === "finite" ? Number.isFinite(e.data) || (n = this._getOrReturnCtx(e, n), l(n, {
996
- code: c.not_finite,
997
- message: a.message
998
- }), s.dirty()) : x.assertNever(a);
999
- return { status: s.value, value: e.data };
1000
- }
1001
- gte(e, t) {
1002
- return this.setLimit("min", e, !0, h.toString(t));
1003
- }
1004
- gt(e, t) {
1005
- return this.setLimit("min", e, !1, h.toString(t));
1006
- }
1007
- lte(e, t) {
1008
- return this.setLimit("max", e, !0, h.toString(t));
1009
- }
1010
- lt(e, t) {
1011
- return this.setLimit("max", e, !1, h.toString(t));
1012
- }
1013
- setLimit(e, t, n, s) {
1014
- return new W({
1015
- ...this._def,
1016
- checks: [
1017
- ...this._def.checks,
1018
- {
1019
- kind: e,
1020
- value: t,
1021
- inclusive: n,
1022
- message: h.toString(s)
1023
- }
1024
- ]
1025
- });
1026
- }
1027
- _addCheck(e) {
1028
- return new W({
1029
- ...this._def,
1030
- checks: [...this._def.checks, e]
1031
- });
1032
- }
1033
- int(e) {
1034
- return this._addCheck({
1035
- kind: "int",
1036
- message: h.toString(e)
1037
- });
1038
- }
1039
- positive(e) {
1040
- return this._addCheck({
1041
- kind: "min",
1042
- value: 0,
1043
- inclusive: !1,
1044
- message: h.toString(e)
1045
- });
1046
- }
1047
- negative(e) {
1048
- return this._addCheck({
1049
- kind: "max",
1050
- value: 0,
1051
- inclusive: !1,
1052
- message: h.toString(e)
1053
- });
1054
- }
1055
- nonpositive(e) {
1056
- return this._addCheck({
1057
- kind: "max",
1058
- value: 0,
1059
- inclusive: !0,
1060
- message: h.toString(e)
1061
- });
1062
- }
1063
- nonnegative(e) {
1064
- return this._addCheck({
1065
- kind: "min",
1066
- value: 0,
1067
- inclusive: !0,
1068
- message: h.toString(e)
1069
- });
1070
- }
1071
- multipleOf(e, t) {
1072
- return this._addCheck({
1073
- kind: "multipleOf",
1074
- value: e,
1075
- message: h.toString(t)
1076
- });
1077
- }
1078
- finite(e) {
1079
- return this._addCheck({
1080
- kind: "finite",
1081
- message: h.toString(e)
1082
- });
1083
- }
1084
- safe(e) {
1085
- return this._addCheck({
1086
- kind: "min",
1087
- inclusive: !0,
1088
- value: Number.MIN_SAFE_INTEGER,
1089
- message: h.toString(e)
1090
- })._addCheck({
1091
- kind: "max",
1092
- inclusive: !0,
1093
- value: Number.MAX_SAFE_INTEGER,
1094
- message: h.toString(e)
1095
- });
1096
- }
1097
- get minValue() {
1098
- let e = null;
1099
- for (const t of this._def.checks)
1100
- t.kind === "min" && (e === null || t.value > e) && (e = t.value);
1101
- return e;
1102
- }
1103
- get maxValue() {
1104
- let e = null;
1105
- for (const t of this._def.checks)
1106
- t.kind === "max" && (e === null || t.value < e) && (e = t.value);
1107
- return e;
1108
- }
1109
- get isInt() {
1110
- return !!this._def.checks.find((e) => e.kind === "int" || e.kind === "multipleOf" && x.isInteger(e.value));
1111
- }
1112
- get isFinite() {
1113
- let e = null, t = null;
1114
- for (const n of this._def.checks) {
1115
- if (n.kind === "finite" || n.kind === "int" || n.kind === "multipleOf")
1116
- return !0;
1117
- n.kind === "min" ? (t === null || n.value > t) && (t = n.value) : n.kind === "max" && (e === null || n.value < e) && (e = n.value);
1118
- }
1119
- return Number.isFinite(t) && Number.isFinite(e);
1120
- }
1121
- }
1122
- W.create = (r) => new W({
1123
- checks: [],
1124
- typeName: y.ZodNumber,
1125
- coerce: (r == null ? void 0 : r.coerce) || !1,
1126
- ...v(r)
1127
- });
1128
- class q extends _ {
1129
- constructor() {
1130
- super(...arguments), this.min = this.gte, this.max = this.lte;
1131
- }
1132
- _parse(e) {
1133
- if (this._def.coerce && (e.data = BigInt(e.data)), this._getType(e) !== f.bigint) {
1134
- const a = this._getOrReturnCtx(e);
1135
- return l(a, {
1136
- code: c.invalid_type,
1137
- expected: f.bigint,
1138
- received: a.parsedType
1139
- }), g;
1140
- }
1141
- let n;
1142
- const s = new E();
1143
- for (const a of this._def.checks)
1144
- a.kind === "min" ? (a.inclusive ? e.data < a.value : e.data <= a.value) && (n = this._getOrReturnCtx(e, n), l(n, {
1145
- code: c.too_small,
1146
- type: "bigint",
1147
- minimum: a.value,
1148
- inclusive: a.inclusive,
1149
- message: a.message
1150
- }), s.dirty()) : a.kind === "max" ? (a.inclusive ? e.data > a.value : e.data >= a.value) && (n = this._getOrReturnCtx(e, n), l(n, {
1151
- code: c.too_big,
1152
- type: "bigint",
1153
- maximum: a.value,
1154
- inclusive: a.inclusive,
1155
- message: a.message
1156
- }), s.dirty()) : a.kind === "multipleOf" ? e.data % a.value !== BigInt(0) && (n = this._getOrReturnCtx(e, n), l(n, {
1157
- code: c.not_multiple_of,
1158
- multipleOf: a.value,
1159
- message: a.message
1160
- }), s.dirty()) : x.assertNever(a);
1161
- return { status: s.value, value: e.data };
1162
- }
1163
- gte(e, t) {
1164
- return this.setLimit("min", e, !0, h.toString(t));
1165
- }
1166
- gt(e, t) {
1167
- return this.setLimit("min", e, !1, h.toString(t));
1168
- }
1169
- lte(e, t) {
1170
- return this.setLimit("max", e, !0, h.toString(t));
1171
- }
1172
- lt(e, t) {
1173
- return this.setLimit("max", e, !1, h.toString(t));
1174
- }
1175
- setLimit(e, t, n, s) {
1176
- return new q({
1177
- ...this._def,
1178
- checks: [
1179
- ...this._def.checks,
1180
- {
1181
- kind: e,
1182
- value: t,
1183
- inclusive: n,
1184
- message: h.toString(s)
1185
- }
1186
- ]
1187
- });
1188
- }
1189
- _addCheck(e) {
1190
- return new q({
1191
- ...this._def,
1192
- checks: [...this._def.checks, e]
1193
- });
1194
- }
1195
- positive(e) {
1196
- return this._addCheck({
1197
- kind: "min",
1198
- value: BigInt(0),
1199
- inclusive: !1,
1200
- message: h.toString(e)
1201
- });
1202
- }
1203
- negative(e) {
1204
- return this._addCheck({
1205
- kind: "max",
1206
- value: BigInt(0),
1207
- inclusive: !1,
1208
- message: h.toString(e)
1209
- });
1210
- }
1211
- nonpositive(e) {
1212
- return this._addCheck({
1213
- kind: "max",
1214
- value: BigInt(0),
1215
- inclusive: !0,
1216
- message: h.toString(e)
1217
- });
1218
- }
1219
- nonnegative(e) {
1220
- return this._addCheck({
1221
- kind: "min",
1222
- value: BigInt(0),
1223
- inclusive: !0,
1224
- message: h.toString(e)
1225
- });
1226
- }
1227
- multipleOf(e, t) {
1228
- return this._addCheck({
1229
- kind: "multipleOf",
1230
- value: e,
1231
- message: h.toString(t)
1232
- });
1233
- }
1234
- get minValue() {
1235
- let e = null;
1236
- for (const t of this._def.checks)
1237
- t.kind === "min" && (e === null || t.value > e) && (e = t.value);
1238
- return e;
1239
- }
1240
- get maxValue() {
1241
- let e = null;
1242
- for (const t of this._def.checks)
1243
- t.kind === "max" && (e === null || t.value < e) && (e = t.value);
1244
- return e;
1245
- }
1246
- }
1247
- q.create = (r) => {
1248
- var e;
1249
- return new q({
1250
- checks: [],
1251
- typeName: y.ZodBigInt,
1252
- coerce: (e = r == null ? void 0 : r.coerce) !== null && e !== void 0 ? e : !1,
1253
- ...v(r)
1254
- });
1255
- };
1256
- class fe extends _ {
1257
- _parse(e) {
1258
- if (this._def.coerce && (e.data = !!e.data), this._getType(e) !== f.boolean) {
1259
- const n = this._getOrReturnCtx(e);
1260
- return l(n, {
1261
- code: c.invalid_type,
1262
- expected: f.boolean,
1263
- received: n.parsedType
1264
- }), g;
1265
- }
1266
- return S(e.data);
1267
- }
1268
- }
1269
- fe.create = (r) => new fe({
1270
- typeName: y.ZodBoolean,
1271
- coerce: (r == null ? void 0 : r.coerce) || !1,
1272
- ...v(r)
1273
- });
1274
- class X extends _ {
1275
- _parse(e) {
1276
- if (this._def.coerce && (e.data = new Date(e.data)), this._getType(e) !== f.date) {
1277
- const a = this._getOrReturnCtx(e);
1278
- return l(a, {
1279
- code: c.invalid_type,
1280
- expected: f.date,
1281
- received: a.parsedType
1282
- }), g;
1283
- }
1284
- if (isNaN(e.data.getTime())) {
1285
- const a = this._getOrReturnCtx(e);
1286
- return l(a, {
1287
- code: c.invalid_date
1288
- }), g;
1289
- }
1290
- const n = new E();
1291
- let s;
1292
- for (const a of this._def.checks)
1293
- a.kind === "min" ? e.data.getTime() < a.value && (s = this._getOrReturnCtx(e, s), l(s, {
1294
- code: c.too_small,
1295
- message: a.message,
1296
- inclusive: !0,
1297
- exact: !1,
1298
- minimum: a.value,
1299
- type: "date"
1300
- }), n.dirty()) : a.kind === "max" ? e.data.getTime() > a.value && (s = this._getOrReturnCtx(e, s), l(s, {
1301
- code: c.too_big,
1302
- message: a.message,
1303
- inclusive: !0,
1304
- exact: !1,
1305
- maximum: a.value,
1306
- type: "date"
1307
- }), n.dirty()) : x.assertNever(a);
1308
- return {
1309
- status: n.value,
1310
- value: new Date(e.data.getTime())
1311
- };
1312
- }
1313
- _addCheck(e) {
1314
- return new X({
1315
- ...this._def,
1316
- checks: [...this._def.checks, e]
1317
- });
1318
- }
1319
- min(e, t) {
1320
- return this._addCheck({
1321
- kind: "min",
1322
- value: e.getTime(),
1323
- message: h.toString(t)
1324
- });
1325
- }
1326
- max(e, t) {
1327
- return this._addCheck({
1328
- kind: "max",
1329
- value: e.getTime(),
1330
- message: h.toString(t)
1331
- });
1332
- }
1333
- get minDate() {
1334
- let e = null;
1335
- for (const t of this._def.checks)
1336
- t.kind === "min" && (e === null || t.value > e) && (e = t.value);
1337
- return e != null ? new Date(e) : null;
1338
- }
1339
- get maxDate() {
1340
- let e = null;
1341
- for (const t of this._def.checks)
1342
- t.kind === "max" && (e === null || t.value < e) && (e = t.value);
1343
- return e != null ? new Date(e) : null;
1344
- }
1345
- }
1346
- X.create = (r) => new X({
1347
- checks: [],
1348
- coerce: (r == null ? void 0 : r.coerce) || !1,
1349
- typeName: y.ZodDate,
1350
- ...v(r)
1351
- });
1352
- class Ie extends _ {
1353
- _parse(e) {
1354
- if (this._getType(e) !== f.symbol) {
1355
- const n = this._getOrReturnCtx(e);
1356
- return l(n, {
1357
- code: c.invalid_type,
1358
- expected: f.symbol,
1359
- received: n.parsedType
1360
- }), g;
1361
- }
1362
- return S(e.data);
1363
- }
1364
- }
1365
- Ie.create = (r) => new Ie({
1366
- typeName: y.ZodSymbol,
1367
- ...v(r)
1368
- });
1369
- class he extends _ {
1370
- _parse(e) {
1371
- if (this._getType(e) !== f.undefined) {
1372
- const n = this._getOrReturnCtx(e);
1373
- return l(n, {
1374
- code: c.invalid_type,
1375
- expected: f.undefined,
1376
- received: n.parsedType
1377
- }), g;
1378
- }
1379
- return S(e.data);
1380
- }
1381
- }
1382
- he.create = (r) => new he({
1383
- typeName: y.ZodUndefined,
1384
- ...v(r)
1385
- });
1386
- class pe extends _ {
1387
- _parse(e) {
1388
- if (this._getType(e) !== f.null) {
1389
- const n = this._getOrReturnCtx(e);
1390
- return l(n, {
1391
- code: c.invalid_type,
1392
- expected: f.null,
1393
- received: n.parsedType
1394
- }), g;
1395
- }
1396
- return S(e.data);
1397
- }
1398
- }
1399
- pe.create = (r) => new pe({
1400
- typeName: y.ZodNull,
1401
- ...v(r)
1402
- });
1403
- class ae extends _ {
1404
- constructor() {
1405
- super(...arguments), this._any = !0;
1406
- }
1407
- _parse(e) {
1408
- return S(e.data);
1409
- }
1410
- }
1411
- ae.create = (r) => new ae({
1412
- typeName: y.ZodAny,
1413
- ...v(r)
1414
- });
1415
- class J extends _ {
1416
- constructor() {
1417
- super(...arguments), this._unknown = !0;
1418
- }
1419
- _parse(e) {
1420
- return S(e.data);
1421
- }
1422
- }
1423
- J.create = (r) => new J({
1424
- typeName: y.ZodUnknown,
1425
- ...v(r)
1426
- });
1427
- class M extends _ {
1428
- _parse(e) {
1429
- const t = this._getOrReturnCtx(e);
1430
- return l(t, {
1431
- code: c.invalid_type,
1432
- expected: f.never,
1433
- received: t.parsedType
1434
- }), g;
1435
- }
1436
- }
1437
- M.create = (r) => new M({
1438
- typeName: y.ZodNever,
1439
- ...v(r)
1440
- });
1441
- class Ae extends _ {
1442
- _parse(e) {
1443
- if (this._getType(e) !== f.undefined) {
1444
- const n = this._getOrReturnCtx(e);
1445
- return l(n, {
1446
- code: c.invalid_type,
1447
- expected: f.void,
1448
- received: n.parsedType
1449
- }), g;
1450
- }
1451
- return S(e.data);
1452
- }
1453
- }
1454
- Ae.create = (r) => new Ae({
1455
- typeName: y.ZodVoid,
1456
- ...v(r)
1457
- });
1458
- class A extends _ {
1459
- _parse(e) {
1460
- const { ctx: t, status: n } = this._processInputParams(e), s = this._def;
1461
- if (t.parsedType !== f.array)
1462
- return l(t, {
1463
- code: c.invalid_type,
1464
- expected: f.array,
1465
- received: t.parsedType
1466
- }), g;
1467
- if (s.exactLength !== null) {
1468
- const i = t.data.length > s.exactLength.value, o = t.data.length < s.exactLength.value;
1469
- (i || o) && (l(t, {
1470
- code: i ? c.too_big : c.too_small,
1471
- minimum: o ? s.exactLength.value : void 0,
1472
- maximum: i ? s.exactLength.value : void 0,
1473
- type: "array",
1474
- inclusive: !0,
1475
- exact: !0,
1476
- message: s.exactLength.message
1477
- }), n.dirty());
1478
- }
1479
- if (s.minLength !== null && t.data.length < s.minLength.value && (l(t, {
1480
- code: c.too_small,
1481
- minimum: s.minLength.value,
1482
- type: "array",
1483
- inclusive: !0,
1484
- exact: !1,
1485
- message: s.minLength.message
1486
- }), n.dirty()), s.maxLength !== null && t.data.length > s.maxLength.value && (l(t, {
1487
- code: c.too_big,
1488
- maximum: s.maxLength.value,
1489
- type: "array",
1490
- inclusive: !0,
1491
- exact: !1,
1492
- message: s.maxLength.message
1493
- }), n.dirty()), t.common.async)
1494
- return Promise.all([...t.data].map((i, o) => s.type._parseAsync(new P(t, i, t.path, o)))).then((i) => E.mergeArray(n, i));
1495
- const a = [...t.data].map((i, o) => s.type._parseSync(new P(t, i, t.path, o)));
1496
- return E.mergeArray(n, a);
1497
- }
1498
- get element() {
1499
- return this._def.type;
1500
- }
1501
- min(e, t) {
1502
- return new A({
1503
- ...this._def,
1504
- minLength: { value: e, message: h.toString(t) }
1505
- });
1506
- }
1507
- max(e, t) {
1508
- return new A({
1509
- ...this._def,
1510
- maxLength: { value: e, message: h.toString(t) }
1511
- });
1512
- }
1513
- length(e, t) {
1514
- return new A({
1515
- ...this._def,
1516
- exactLength: { value: e, message: h.toString(t) }
1517
- });
1518
- }
1519
- nonempty(e) {
1520
- return this.min(1, e);
1521
- }
1522
- }
1523
- A.create = (r, e) => new A({
1524
- type: r,
1525
- minLength: null,
1526
- maxLength: null,
1527
- exactLength: null,
1528
- typeName: y.ZodArray,
1529
- ...v(e)
1530
- });
1531
- function te(r) {
1532
- if (r instanceof b) {
1533
- const e = {};
1534
- for (const t in r.shape) {
1535
- const n = r.shape[t];
1536
- e[t] = $.create(te(n));
1537
- }
1538
- return new b({
1539
- ...r._def,
1540
- shape: () => e
1541
- });
1542
- } else return r instanceof A ? new A({
1543
- ...r._def,
1544
- type: te(r.element)
1545
- }) : r instanceof $ ? $.create(te(r.unwrap())) : r instanceof G ? G.create(te(r.unwrap())) : r instanceof D ? D.create(r.items.map((e) => te(e))) : r;
1546
- }
1547
- class b extends _ {
1548
- constructor() {
1549
- super(...arguments), this._cached = null, this.nonstrict = this.passthrough, this.augment = this.extend;
1550
- }
1551
- _getCached() {
1552
- if (this._cached !== null)
1553
- return this._cached;
1554
- const e = this._def.shape(), t = x.objectKeys(e);
1555
- return this._cached = { shape: e, keys: t };
1556
- }
1557
- _parse(e) {
1558
- if (this._getType(e) !== f.object) {
1559
- const d = this._getOrReturnCtx(e);
1560
- return l(d, {
1561
- code: c.invalid_type,
1562
- expected: f.object,
1563
- received: d.parsedType
1564
- }), g;
1565
- }
1566
- const { status: n, ctx: s } = this._processInputParams(e), { shape: a, keys: i } = this._getCached(), o = [];
1567
- if (!(this._def.catchall instanceof M && this._def.unknownKeys === "strip"))
1568
- for (const d in s.data)
1569
- i.includes(d) || o.push(d);
1570
- const u = [];
1571
- for (const d of i) {
1572
- const p = a[d], w = s.data[d];
1573
- u.push({
1574
- key: { status: "valid", value: d },
1575
- value: p._parse(new P(s, w, s.path, d)),
1576
- alwaysSet: d in s.data
1577
- });
1578
- }
1579
- if (this._def.catchall instanceof M) {
1580
- const d = this._def.unknownKeys;
1581
- if (d === "passthrough")
1582
- for (const p of o)
1583
- u.push({
1584
- key: { status: "valid", value: p },
1585
- value: { status: "valid", value: s.data[p] }
1586
- });
1587
- else if (d === "strict")
1588
- o.length > 0 && (l(s, {
1589
- code: c.unrecognized_keys,
1590
- keys: o
1591
- }), n.dirty());
1592
- else if (d !== "strip") throw new Error("Internal ZodObject error: invalid unknownKeys value.");
1593
- } else {
1594
- const d = this._def.catchall;
1595
- for (const p of o) {
1596
- const w = s.data[p];
1597
- u.push({
1598
- key: { status: "valid", value: p },
1599
- value: d._parse(
1600
- new P(s, w, s.path, p)
1601
- //, ctx.child(key), value, getParsedType(value)
1602
- ),
1603
- alwaysSet: p in s.data
1604
- });
1605
- }
1606
- }
1607
- return s.common.async ? Promise.resolve().then(async () => {
1608
- const d = [];
1609
- for (const p of u) {
1610
- const w = await p.key, L = await p.value;
1611
- d.push({
1612
- key: w,
1613
- value: L,
1614
- alwaysSet: p.alwaysSet
1615
- });
1616
- }
1617
- return d;
1618
- }).then((d) => E.mergeObjectSync(n, d)) : E.mergeObjectSync(n, u);
1619
- }
1620
- get shape() {
1621
- return this._def.shape();
1622
- }
1623
- strict(e) {
1624
- return h.errToObj, new b({
1625
- ...this._def,
1626
- unknownKeys: "strict",
1627
- ...e !== void 0 ? {
1628
- errorMap: (t, n) => {
1629
- var s, a, i, o;
1630
- const u = (i = (a = (s = this._def).errorMap) === null || a === void 0 ? void 0 : a.call(s, t, n).message) !== null && i !== void 0 ? i : n.defaultError;
1631
- return t.code === "unrecognized_keys" ? {
1632
- message: (o = h.errToObj(e).message) !== null && o !== void 0 ? o : u
1633
- } : {
1634
- message: u
1635
- };
1636
- }
1637
- } : {}
1638
- });
1639
- }
1640
- strip() {
1641
- return new b({
1642
- ...this._def,
1643
- unknownKeys: "strip"
1644
- });
1645
- }
1646
- passthrough() {
1647
- return new b({
1648
- ...this._def,
1649
- unknownKeys: "passthrough"
1650
- });
1651
- }
1652
- // const AugmentFactory =
1653
- // <Def extends ZodObjectDef>(def: Def) =>
1654
- // <Augmentation extends ZodRawShape>(
1655
- // augmentation: Augmentation
1656
- // ): ZodObject<
1657
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
1658
- // Def["unknownKeys"],
1659
- // Def["catchall"]
1660
- // > => {
1661
- // return new ZodObject({
1662
- // ...def,
1663
- // shape: () => ({
1664
- // ...def.shape(),
1665
- // ...augmentation,
1666
- // }),
1667
- // }) as any;
1668
- // };
1669
- extend(e) {
1670
- return new b({
1671
- ...this._def,
1672
- shape: () => ({
1673
- ...this._def.shape(),
1674
- ...e
1675
- })
1676
- });
1677
- }
1678
- /**
1679
- * Prior to zod@1.0.12 there was a bug in the
1680
- * inferred type of merged objects. Please
1681
- * upgrade if you are experiencing issues.
1682
- */
1683
- merge(e) {
1684
- return new b({
1685
- unknownKeys: e._def.unknownKeys,
1686
- catchall: e._def.catchall,
1687
- shape: () => ({
1688
- ...this._def.shape(),
1689
- ...e._def.shape()
1690
- }),
1691
- typeName: y.ZodObject
1692
- });
1693
- }
1694
- // merge<
1695
- // Incoming extends AnyZodObject,
1696
- // Augmentation extends Incoming["shape"],
1697
- // NewOutput extends {
1698
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
1699
- // ? Augmentation[k]["_output"]
1700
- // : k extends keyof Output
1701
- // ? Output[k]
1702
- // : never;
1703
- // },
1704
- // NewInput extends {
1705
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
1706
- // ? Augmentation[k]["_input"]
1707
- // : k extends keyof Input
1708
- // ? Input[k]
1709
- // : never;
1710
- // }
1711
- // >(
1712
- // merging: Incoming
1713
- // ): ZodObject<
1714
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1715
- // Incoming["_def"]["unknownKeys"],
1716
- // Incoming["_def"]["catchall"],
1717
- // NewOutput,
1718
- // NewInput
1719
- // > {
1720
- // const merged: any = new ZodObject({
1721
- // unknownKeys: merging._def.unknownKeys,
1722
- // catchall: merging._def.catchall,
1723
- // shape: () =>
1724
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1725
- // typeName: ZodFirstPartyTypeKind.ZodObject,
1726
- // }) as any;
1727
- // return merged;
1728
- // }
1729
- setKey(e, t) {
1730
- return this.augment({ [e]: t });
1731
- }
1732
- // merge<Incoming extends AnyZodObject>(
1733
- // merging: Incoming
1734
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
1735
- // ZodObject<
1736
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
1737
- // Incoming["_def"]["unknownKeys"],
1738
- // Incoming["_def"]["catchall"]
1739
- // > {
1740
- // // const mergedShape = objectUtil.mergeShapes(
1741
- // // this._def.shape(),
1742
- // // merging._def.shape()
1743
- // // );
1744
- // const merged: any = new ZodObject({
1745
- // unknownKeys: merging._def.unknownKeys,
1746
- // catchall: merging._def.catchall,
1747
- // shape: () =>
1748
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
1749
- // typeName: ZodFirstPartyTypeKind.ZodObject,
1750
- // }) as any;
1751
- // return merged;
1752
- // }
1753
- catchall(e) {
1754
- return new b({
1755
- ...this._def,
1756
- catchall: e
1757
- });
1758
- }
1759
- pick(e) {
1760
- const t = {};
1761
- return x.objectKeys(e).forEach((n) => {
1762
- e[n] && this.shape[n] && (t[n] = this.shape[n]);
1763
- }), new b({
1764
- ...this._def,
1765
- shape: () => t
1766
- });
1767
- }
1768
- omit(e) {
1769
- const t = {};
1770
- return x.objectKeys(this.shape).forEach((n) => {
1771
- e[n] || (t[n] = this.shape[n]);
1772
- }), new b({
1773
- ...this._def,
1774
- shape: () => t
1775
- });
1776
- }
1777
- /**
1778
- * @deprecated
1779
- */
1780
- deepPartial() {
1781
- return te(this);
1782
- }
1783
- partial(e) {
1784
- const t = {};
1785
- return x.objectKeys(this.shape).forEach((n) => {
1786
- const s = this.shape[n];
1787
- e && !e[n] ? t[n] = s : t[n] = s.optional();
1788
- }), new b({
1789
- ...this._def,
1790
- shape: () => t
1791
- });
1792
- }
1793
- required(e) {
1794
- const t = {};
1795
- return x.objectKeys(this.shape).forEach((n) => {
1796
- if (e && !e[n])
1797
- t[n] = this.shape[n];
1798
- else {
1799
- let a = this.shape[n];
1800
- for (; a instanceof $; )
1801
- a = a._def.innerType;
1802
- t[n] = a;
1803
- }
1804
- }), new b({
1805
- ...this._def,
1806
- shape: () => t
1807
- });
1808
- }
1809
- keyof() {
1810
- return ht(x.objectKeys(this.shape));
1811
- }
1812
- }
1813
- b.create = (r, e) => new b({
1814
- shape: () => r,
1815
- unknownKeys: "strip",
1816
- catchall: M.create(),
1817
- typeName: y.ZodObject,
1818
- ...v(e)
1819
- });
1820
- b.strictCreate = (r, e) => new b({
1821
- shape: () => r,
1822
- unknownKeys: "strict",
1823
- catchall: M.create(),
1824
- typeName: y.ZodObject,
1825
- ...v(e)
1826
- });
1827
- b.lazycreate = (r, e) => new b({
1828
- shape: r,
1829
- unknownKeys: "strip",
1830
- catchall: M.create(),
1831
- typeName: y.ZodObject,
1832
- ...v(e)
1833
- });
1834
- class me extends _ {
1835
- _parse(e) {
1836
- const { ctx: t } = this._processInputParams(e), n = this._def.options;
1837
- function s(a) {
1838
- for (const o of a)
1839
- if (o.result.status === "valid")
1840
- return o.result;
1841
- for (const o of a)
1842
- if (o.result.status === "dirty")
1843
- return t.common.issues.push(...o.ctx.common.issues), o.result;
1844
- const i = a.map((o) => new O(o.ctx.common.issues));
1845
- return l(t, {
1846
- code: c.invalid_union,
1847
- unionErrors: i
1848
- }), g;
1849
- }
1850
- if (t.common.async)
1851
- return Promise.all(n.map(async (a) => {
1852
- const i = {
1853
- ...t,
1854
- common: {
1855
- ...t.common,
1856
- issues: []
1857
- },
1858
- parent: null
1859
- };
1860
- return {
1861
- result: await a._parseAsync({
1862
- data: t.data,
1863
- path: t.path,
1864
- parent: i
1865
- }),
1866
- ctx: i
1867
- };
1868
- })).then(s);
1869
- {
1870
- let a;
1871
- const i = [];
1872
- for (const u of n) {
1873
- const d = {
1874
- ...t,
1875
- common: {
1876
- ...t.common,
1877
- issues: []
1878
- },
1879
- parent: null
1880
- }, p = u._parseSync({
1881
- data: t.data,
1882
- path: t.path,
1883
- parent: d
1884
- });
1885
- if (p.status === "valid")
1886
- return p;
1887
- p.status === "dirty" && !a && (a = { result: p, ctx: d }), d.common.issues.length && i.push(d.common.issues);
1888
- }
1889
- if (a)
1890
- return t.common.issues.push(...a.ctx.common.issues), a.result;
1891
- const o = i.map((u) => new O(u));
1892
- return l(t, {
1893
- code: c.invalid_union,
1894
- unionErrors: o
1895
- }), g;
1896
- }
1897
- }
1898
- get options() {
1899
- return this._def.options;
1900
- }
1901
- }
1902
- me.create = (r, e) => new me({
1903
- options: r,
1904
- typeName: y.ZodUnion,
1905
- ...v(e)
1906
- });
1907
- const U = (r) => r instanceof ve ? U(r.schema) : r instanceof j ? U(r.innerType()) : r instanceof _e ? [r.value] : r instanceof Y ? r.options : r instanceof xe ? x.objectValues(r.enum) : r instanceof ke ? U(r._def.innerType) : r instanceof he ? [void 0] : r instanceof pe ? [null] : r instanceof $ ? [void 0, ...U(r.unwrap())] : r instanceof G ? [null, ...U(r.unwrap())] : r instanceof Je || r instanceof we ? U(r.unwrap()) : r instanceof be ? U(r._def.innerType) : [];
1908
- class Pe extends _ {
1909
- _parse(e) {
1910
- const { ctx: t } = this._processInputParams(e);
1911
- if (t.parsedType !== f.object)
1912
- return l(t, {
1913
- code: c.invalid_type,
1914
- expected: f.object,
1915
- received: t.parsedType
1916
- }), g;
1917
- const n = this.discriminator, s = t.data[n], a = this.optionsMap.get(s);
1918
- return a ? t.common.async ? a._parseAsync({
1919
- data: t.data,
1920
- path: t.path,
1921
- parent: t
1922
- }) : a._parseSync({
1923
- data: t.data,
1924
- path: t.path,
1925
- parent: t
1926
- }) : (l(t, {
1927
- code: c.invalid_union_discriminator,
1928
- options: Array.from(this.optionsMap.keys()),
1929
- path: [n]
1930
- }), g);
1931
- }
1932
- get discriminator() {
1933
- return this._def.discriminator;
1934
- }
1935
- get options() {
1936
- return this._def.options;
1937
- }
1938
- get optionsMap() {
1939
- return this._def.optionsMap;
1940
- }
1941
- /**
1942
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
1943
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
1944
- * have a different value for each object in the union.
1945
- * @param discriminator the name of the discriminator property
1946
- * @param types an array of object schemas
1947
- * @param params
1948
- */
1949
- static create(e, t, n) {
1950
- const s = /* @__PURE__ */ new Map();
1951
- for (const a of t) {
1952
- const i = U(a.shape[e]);
1953
- if (!i.length)
1954
- throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);
1955
- for (const o of i) {
1956
- if (s.has(o))
1957
- throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(o)}`);
1958
- s.set(o, a);
1959
- }
1960
- }
1961
- return new Pe({
1962
- typeName: y.ZodDiscriminatedUnion,
1963
- discriminator: e,
1964
- options: t,
1965
- optionsMap: s,
1966
- ...v(n)
1967
- });
1968
- }
1969
- }
1970
- function Ye(r, e) {
1971
- const t = H(r), n = H(e);
1972
- if (r === e)
1973
- return { valid: !0, data: r };
1974
- if (t === f.object && n === f.object) {
1975
- const s = x.objectKeys(e), a = x.objectKeys(r).filter((o) => s.indexOf(o) !== -1), i = { ...r, ...e };
1976
- for (const o of a) {
1977
- const u = Ye(r[o], e[o]);
1978
- if (!u.valid)
1979
- return { valid: !1 };
1980
- i[o] = u.data;
1981
- }
1982
- return { valid: !0, data: i };
1983
- } else if (t === f.array && n === f.array) {
1984
- if (r.length !== e.length)
1985
- return { valid: !1 };
1986
- const s = [];
1987
- for (let a = 0; a < r.length; a++) {
1988
- const i = r[a], o = e[a], u = Ye(i, o);
1989
- if (!u.valid)
1990
- return { valid: !1 };
1991
- s.push(u.data);
1992
- }
1993
- return { valid: !0, data: s };
1994
- } else return t === f.date && n === f.date && +r == +e ? { valid: !0, data: r } : { valid: !1 };
1995
- }
1996
- class ye extends _ {
1997
- _parse(e) {
1998
- const { status: t, ctx: n } = this._processInputParams(e), s = (a, i) => {
1999
- if (We(a) || We(i))
2000
- return g;
2001
- const o = Ye(a.value, i.value);
2002
- return o.valid ? ((qe(a) || qe(i)) && t.dirty(), { status: t.value, value: o.data }) : (l(n, {
2003
- code: c.invalid_intersection_types
2004
- }), g);
2005
- };
2006
- return n.common.async ? Promise.all([
2007
- this._def.left._parseAsync({
2008
- data: n.data,
2009
- path: n.path,
2010
- parent: n
2011
- }),
2012
- this._def.right._parseAsync({
2013
- data: n.data,
2014
- path: n.path,
2015
- parent: n
2016
- })
2017
- ]).then(([a, i]) => s(a, i)) : s(this._def.left._parseSync({
2018
- data: n.data,
2019
- path: n.path,
2020
- parent: n
2021
- }), this._def.right._parseSync({
2022
- data: n.data,
2023
- path: n.path,
2024
- parent: n
2025
- }));
2026
- }
2027
- }
2028
- ye.create = (r, e, t) => new ye({
2029
- left: r,
2030
- right: e,
2031
- typeName: y.ZodIntersection,
2032
- ...v(t)
2033
- });
2034
- class D extends _ {
2035
- _parse(e) {
2036
- const { status: t, ctx: n } = this._processInputParams(e);
2037
- if (n.parsedType !== f.array)
2038
- return l(n, {
2039
- code: c.invalid_type,
2040
- expected: f.array,
2041
- received: n.parsedType
2042
- }), g;
2043
- if (n.data.length < this._def.items.length)
2044
- return l(n, {
2045
- code: c.too_small,
2046
- minimum: this._def.items.length,
2047
- inclusive: !0,
2048
- exact: !1,
2049
- type: "array"
2050
- }), g;
2051
- !this._def.rest && n.data.length > this._def.items.length && (l(n, {
2052
- code: c.too_big,
2053
- maximum: this._def.items.length,
2054
- inclusive: !0,
2055
- exact: !1,
2056
- type: "array"
2057
- }), t.dirty());
2058
- const a = [...n.data].map((i, o) => {
2059
- const u = this._def.items[o] || this._def.rest;
2060
- return u ? u._parse(new P(n, i, n.path, o)) : null;
2061
- }).filter((i) => !!i);
2062
- return n.common.async ? Promise.all(a).then((i) => E.mergeArray(t, i)) : E.mergeArray(t, a);
2063
- }
2064
- get items() {
2065
- return this._def.items;
2066
- }
2067
- rest(e) {
2068
- return new D({
2069
- ...this._def,
2070
- rest: e
2071
- });
2072
- }
2073
- }
2074
- D.create = (r, e) => {
2075
- if (!Array.isArray(r))
2076
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2077
- return new D({
2078
- items: r,
2079
- typeName: y.ZodTuple,
2080
- rest: null,
2081
- ...v(e)
2082
- });
2083
- };
2084
- class ge extends _ {
2085
- get keySchema() {
2086
- return this._def.keyType;
2087
- }
2088
- get valueSchema() {
2089
- return this._def.valueType;
2090
- }
2091
- _parse(e) {
2092
- const { status: t, ctx: n } = this._processInputParams(e);
2093
- if (n.parsedType !== f.object)
2094
- return l(n, {
2095
- code: c.invalid_type,
2096
- expected: f.object,
2097
- received: n.parsedType
2098
- }), g;
2099
- const s = [], a = this._def.keyType, i = this._def.valueType;
2100
- for (const o in n.data)
2101
- s.push({
2102
- key: a._parse(new P(n, o, n.path, o)),
2103
- value: i._parse(new P(n, n.data[o], n.path, o)),
2104
- alwaysSet: o in n.data
2105
- });
2106
- return n.common.async ? E.mergeObjectAsync(t, s) : E.mergeObjectSync(t, s);
2107
- }
2108
- get element() {
2109
- return this._def.valueType;
2110
- }
2111
- static create(e, t, n) {
2112
- return t instanceof _ ? new ge({
2113
- keyType: e,
2114
- valueType: t,
2115
- typeName: y.ZodRecord,
2116
- ...v(n)
2117
- }) : new ge({
2118
- keyType: I.create(),
2119
- valueType: e,
2120
- typeName: y.ZodRecord,
2121
- ...v(t)
2122
- });
2123
- }
2124
- }
2125
- class je extends _ {
2126
- get keySchema() {
2127
- return this._def.keyType;
2128
- }
2129
- get valueSchema() {
2130
- return this._def.valueType;
2131
- }
2132
- _parse(e) {
2133
- const { status: t, ctx: n } = this._processInputParams(e);
2134
- if (n.parsedType !== f.map)
2135
- return l(n, {
2136
- code: c.invalid_type,
2137
- expected: f.map,
2138
- received: n.parsedType
2139
- }), g;
2140
- const s = this._def.keyType, a = this._def.valueType, i = [...n.data.entries()].map(([o, u], d) => ({
2141
- key: s._parse(new P(n, o, n.path, [d, "key"])),
2142
- value: a._parse(new P(n, u, n.path, [d, "value"]))
2143
- }));
2144
- if (n.common.async) {
2145
- const o = /* @__PURE__ */ new Map();
2146
- return Promise.resolve().then(async () => {
2147
- for (const u of i) {
2148
- const d = await u.key, p = await u.value;
2149
- if (d.status === "aborted" || p.status === "aborted")
2150
- return g;
2151
- (d.status === "dirty" || p.status === "dirty") && t.dirty(), o.set(d.value, p.value);
2152
- }
2153
- return { status: t.value, value: o };
2154
- });
2155
- } else {
2156
- const o = /* @__PURE__ */ new Map();
2157
- for (const u of i) {
2158
- const d = u.key, p = u.value;
2159
- if (d.status === "aborted" || p.status === "aborted")
2160
- return g;
2161
- (d.status === "dirty" || p.status === "dirty") && t.dirty(), o.set(d.value, p.value);
2162
- }
2163
- return { status: t.value, value: o };
2164
- }
2165
- }
2166
- }
2167
- je.create = (r, e, t) => new je({
2168
- valueType: e,
2169
- keyType: r,
2170
- typeName: y.ZodMap,
2171
- ...v(t)
2172
- });
2173
- class Q extends _ {
2174
- _parse(e) {
2175
- const { status: t, ctx: n } = this._processInputParams(e);
2176
- if (n.parsedType !== f.set)
2177
- return l(n, {
2178
- code: c.invalid_type,
2179
- expected: f.set,
2180
- received: n.parsedType
2181
- }), g;
2182
- const s = this._def;
2183
- s.minSize !== null && n.data.size < s.minSize.value && (l(n, {
2184
- code: c.too_small,
2185
- minimum: s.minSize.value,
2186
- type: "set",
2187
- inclusive: !0,
2188
- exact: !1,
2189
- message: s.minSize.message
2190
- }), t.dirty()), s.maxSize !== null && n.data.size > s.maxSize.value && (l(n, {
2191
- code: c.too_big,
2192
- maximum: s.maxSize.value,
2193
- type: "set",
2194
- inclusive: !0,
2195
- exact: !1,
2196
- message: s.maxSize.message
2197
- }), t.dirty());
2198
- const a = this._def.valueType;
2199
- function i(u) {
2200
- const d = /* @__PURE__ */ new Set();
2201
- for (const p of u) {
2202
- if (p.status === "aborted")
2203
- return g;
2204
- p.status === "dirty" && t.dirty(), d.add(p.value);
2205
- }
2206
- return { status: t.value, value: d };
2207
- }
2208
- const o = [...n.data.values()].map((u, d) => a._parse(new P(n, u, n.path, d)));
2209
- return n.common.async ? Promise.all(o).then((u) => i(u)) : i(o);
2210
- }
2211
- min(e, t) {
2212
- return new Q({
2213
- ...this._def,
2214
- minSize: { value: e, message: h.toString(t) }
2215
- });
2216
- }
2217
- max(e, t) {
2218
- return new Q({
2219
- ...this._def,
2220
- maxSize: { value: e, message: h.toString(t) }
2221
- });
2222
- }
2223
- size(e, t) {
2224
- return this.min(e, t).max(e, t);
2225
- }
2226
- nonempty(e) {
2227
- return this.min(1, e);
2228
- }
2229
- }
2230
- Q.create = (r, e) => new Q({
2231
- valueType: r,
2232
- minSize: null,
2233
- maxSize: null,
2234
- typeName: y.ZodSet,
2235
- ...v(e)
2236
- });
2237
- class ne extends _ {
2238
- constructor() {
2239
- super(...arguments), this.validate = this.implement;
2240
- }
2241
- _parse(e) {
2242
- const { ctx: t } = this._processInputParams(e);
2243
- if (t.parsedType !== f.function)
2244
- return l(t, {
2245
- code: c.invalid_type,
2246
- expected: f.function,
2247
- received: t.parsedType
2248
- }), g;
2249
- function n(o, u) {
2250
- return Ze({
2251
- data: o,
2252
- path: t.path,
2253
- errorMaps: [
2254
- t.common.contextualErrorMap,
2255
- t.schemaErrorMap,
2256
- Re(),
2257
- se
2258
- ].filter((d) => !!d),
2259
- issueData: {
2260
- code: c.invalid_arguments,
2261
- argumentsError: u
2262
- }
2263
- });
2264
- }
2265
- function s(o, u) {
2266
- return Ze({
2267
- data: o,
2268
- path: t.path,
2269
- errorMaps: [
2270
- t.common.contextualErrorMap,
2271
- t.schemaErrorMap,
2272
- Re(),
2273
- se
2274
- ].filter((d) => !!d),
2275
- issueData: {
2276
- code: c.invalid_return_type,
2277
- returnTypeError: u
2278
- }
2279
- });
2280
- }
2281
- const a = { errorMap: t.common.contextualErrorMap }, i = t.data;
2282
- if (this._def.returns instanceof ie) {
2283
- const o = this;
2284
- return S(async function(...u) {
2285
- const d = new O([]), p = await o._def.args.parseAsync(u, a).catch((R) => {
2286
- throw d.addIssue(n(u, R)), d;
2287
- }), w = await Reflect.apply(i, this, p);
2288
- return await o._def.returns._def.type.parseAsync(w, a).catch((R) => {
2289
- throw d.addIssue(s(w, R)), d;
2290
- });
2291
- });
2292
- } else {
2293
- const o = this;
2294
- return S(function(...u) {
2295
- const d = o._def.args.safeParse(u, a);
2296
- if (!d.success)
2297
- throw new O([n(u, d.error)]);
2298
- const p = Reflect.apply(i, this, d.data), w = o._def.returns.safeParse(p, a);
2299
- if (!w.success)
2300
- throw new O([s(p, w.error)]);
2301
- return w.data;
2302
- });
2303
- }
2304
- }
2305
- parameters() {
2306
- return this._def.args;
2307
- }
2308
- returnType() {
2309
- return this._def.returns;
2310
- }
2311
- args(...e) {
2312
- return new ne({
2313
- ...this._def,
2314
- args: D.create(e).rest(J.create())
2315
- });
2316
- }
2317
- returns(e) {
2318
- return new ne({
2319
- ...this._def,
2320
- returns: e
2321
- });
2322
- }
2323
- implement(e) {
2324
- return this.parse(e);
2325
- }
2326
- strictImplement(e) {
2327
- return this.parse(e);
2328
- }
2329
- static create(e, t, n) {
2330
- return new ne({
2331
- args: e || D.create([]).rest(J.create()),
2332
- returns: t || J.create(),
2333
- typeName: y.ZodFunction,
2334
- ...v(n)
2335
- });
2336
- }
2337
- }
2338
- class ve extends _ {
2339
- get schema() {
2340
- return this._def.getter();
2341
- }
2342
- _parse(e) {
2343
- const { ctx: t } = this._processInputParams(e);
2344
- return this._def.getter()._parse({ data: t.data, path: t.path, parent: t });
2345
- }
2346
- }
2347
- ve.create = (r, e) => new ve({
2348
- getter: r,
2349
- typeName: y.ZodLazy,
2350
- ...v(e)
2351
- });
2352
- class _e extends _ {
2353
- _parse(e) {
2354
- if (e.data !== this._def.value) {
2355
- const t = this._getOrReturnCtx(e);
2356
- return l(t, {
2357
- received: t.data,
2358
- code: c.invalid_literal,
2359
- expected: this._def.value
2360
- }), g;
2361
- }
2362
- return { status: "valid", value: e.data };
2363
- }
2364
- get value() {
2365
- return this._def.value;
2366
- }
2367
- }
2368
- _e.create = (r, e) => new _e({
2369
- value: r,
2370
- typeName: y.ZodLiteral,
2371
- ...v(e)
2372
- });
2373
- function ht(r, e) {
2374
- return new Y({
2375
- values: r,
2376
- typeName: y.ZodEnum,
2377
- ...v(e)
2378
- });
2379
- }
2380
- class Y extends _ {
2381
- constructor() {
2382
- super(...arguments), ce.set(this, void 0);
2383
- }
2384
- _parse(e) {
2385
- if (typeof e.data != "string") {
2386
- const t = this._getOrReturnCtx(e), n = this._def.values;
2387
- return l(t, {
2388
- expected: x.joinValues(n),
2389
- received: t.parsedType,
2390
- code: c.invalid_type
2391
- }), g;
2392
- }
2393
- if (Ne(this, ce) || dt(this, ce, new Set(this._def.values)), !Ne(this, ce).has(e.data)) {
2394
- const t = this._getOrReturnCtx(e), n = this._def.values;
2395
- return l(t, {
2396
- received: t.data,
2397
- code: c.invalid_enum_value,
2398
- options: n
2399
- }), g;
2400
- }
2401
- return S(e.data);
2402
- }
2403
- get options() {
2404
- return this._def.values;
2405
- }
2406
- get enum() {
2407
- const e = {};
2408
- for (const t of this._def.values)
2409
- e[t] = t;
2410
- return e;
2411
- }
2412
- get Values() {
2413
- const e = {};
2414
- for (const t of this._def.values)
2415
- e[t] = t;
2416
- return e;
2417
- }
2418
- get Enum() {
2419
- const e = {};
2420
- for (const t of this._def.values)
2421
- e[t] = t;
2422
- return e;
2423
- }
2424
- extract(e, t = this._def) {
2425
- return Y.create(e, {
2426
- ...this._def,
2427
- ...t
2428
- });
2429
- }
2430
- exclude(e, t = this._def) {
2431
- return Y.create(this.options.filter((n) => !e.includes(n)), {
2432
- ...this._def,
2433
- ...t
2434
- });
2435
- }
2436
- }
2437
- ce = /* @__PURE__ */ new WeakMap();
2438
- Y.create = ht;
2439
- class xe extends _ {
2440
- constructor() {
2441
- super(...arguments), de.set(this, void 0);
2442
- }
2443
- _parse(e) {
2444
- const t = x.getValidEnumValues(this._def.values), n = this._getOrReturnCtx(e);
2445
- if (n.parsedType !== f.string && n.parsedType !== f.number) {
2446
- const s = x.objectValues(t);
2447
- return l(n, {
2448
- expected: x.joinValues(s),
2449
- received: n.parsedType,
2450
- code: c.invalid_type
2451
- }), g;
2452
- }
2453
- if (Ne(this, de) || dt(this, de, new Set(x.getValidEnumValues(this._def.values))), !Ne(this, de).has(e.data)) {
2454
- const s = x.objectValues(t);
2455
- return l(n, {
2456
- received: n.data,
2457
- code: c.invalid_enum_value,
2458
- options: s
2459
- }), g;
2460
- }
2461
- return S(e.data);
2462
- }
2463
- get enum() {
2464
- return this._def.values;
2465
- }
2466
- }
2467
- de = /* @__PURE__ */ new WeakMap();
2468
- xe.create = (r, e) => new xe({
2469
- values: r,
2470
- typeName: y.ZodNativeEnum,
2471
- ...v(e)
2472
- });
2473
- class ie extends _ {
2474
- unwrap() {
2475
- return this._def.type;
2476
- }
2477
- _parse(e) {
2478
- const { ctx: t } = this._processInputParams(e);
2479
- if (t.parsedType !== f.promise && t.common.async === !1)
2480
- return l(t, {
2481
- code: c.invalid_type,
2482
- expected: f.promise,
2483
- received: t.parsedType
2484
- }), g;
2485
- const n = t.parsedType === f.promise ? t.data : Promise.resolve(t.data);
2486
- return S(n.then((s) => this._def.type.parseAsync(s, {
2487
- path: t.path,
2488
- errorMap: t.common.contextualErrorMap
2489
- })));
2490
- }
2491
- }
2492
- ie.create = (r, e) => new ie({
2493
- type: r,
2494
- typeName: y.ZodPromise,
2495
- ...v(e)
2496
- });
2497
- class j extends _ {
2498
- innerType() {
2499
- return this._def.schema;
2500
- }
2501
- sourceType() {
2502
- return this._def.schema._def.typeName === y.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
2503
- }
2504
- _parse(e) {
2505
- const { status: t, ctx: n } = this._processInputParams(e), s = this._def.effect || null, a = {
2506
- addIssue: (i) => {
2507
- l(n, i), i.fatal ? t.abort() : t.dirty();
2508
- },
2509
- get path() {
2510
- return n.path;
2511
- }
2512
- };
2513
- if (a.addIssue = a.addIssue.bind(a), s.type === "preprocess") {
2514
- const i = s.transform(n.data, a);
2515
- if (n.common.async)
2516
- return Promise.resolve(i).then(async (o) => {
2517
- if (t.value === "aborted")
2518
- return g;
2519
- const u = await this._def.schema._parseAsync({
2520
- data: o,
2521
- path: n.path,
2522
- parent: n
2523
- });
2524
- return u.status === "aborted" ? g : u.status === "dirty" || t.value === "dirty" ? re(u.value) : u;
2525
- });
2526
- {
2527
- if (t.value === "aborted")
2528
- return g;
2529
- const o = this._def.schema._parseSync({
2530
- data: i,
2531
- path: n.path,
2532
- parent: n
2533
- });
2534
- return o.status === "aborted" ? g : o.status === "dirty" || t.value === "dirty" ? re(o.value) : o;
2535
- }
2536
- }
2537
- if (s.type === "refinement") {
2538
- const i = (o) => {
2539
- const u = s.refinement(o, a);
2540
- if (n.common.async)
2541
- return Promise.resolve(u);
2542
- if (u instanceof Promise)
2543
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
2544
- return o;
2545
- };
2546
- if (n.common.async === !1) {
2547
- const o = this._def.schema._parseSync({
2548
- data: n.data,
2549
- path: n.path,
2550
- parent: n
2551
- });
2552
- return o.status === "aborted" ? g : (o.status === "dirty" && t.dirty(), i(o.value), { status: t.value, value: o.value });
2553
- } else
2554
- return this._def.schema._parseAsync({ data: n.data, path: n.path, parent: n }).then((o) => o.status === "aborted" ? g : (o.status === "dirty" && t.dirty(), i(o.value).then(() => ({ status: t.value, value: o.value }))));
2555
- }
2556
- if (s.type === "transform")
2557
- if (n.common.async === !1) {
2558
- const i = this._def.schema._parseSync({
2559
- data: n.data,
2560
- path: n.path,
2561
- parent: n
2562
- });
2563
- if (!ue(i))
2564
- return i;
2565
- const o = s.transform(i.value, a);
2566
- if (o instanceof Promise)
2567
- throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");
2568
- return { status: t.value, value: o };
2569
- } else
2570
- return this._def.schema._parseAsync({ data: n.data, path: n.path, parent: n }).then((i) => ue(i) ? Promise.resolve(s.transform(i.value, a)).then((o) => ({ status: t.value, value: o })) : i);
2571
- x.assertNever(s);
2572
- }
2573
- }
2574
- j.create = (r, e, t) => new j({
2575
- schema: r,
2576
- typeName: y.ZodEffects,
2577
- effect: e,
2578
- ...v(t)
2579
- });
2580
- j.createWithPreprocess = (r, e, t) => new j({
2581
- schema: e,
2582
- effect: { type: "preprocess", transform: r },
2583
- typeName: y.ZodEffects,
2584
- ...v(t)
2585
- });
2586
- class $ extends _ {
2587
- _parse(e) {
2588
- return this._getType(e) === f.undefined ? S(void 0) : this._def.innerType._parse(e);
2589
- }
2590
- unwrap() {
2591
- return this._def.innerType;
2592
- }
2593
- }
2594
- $.create = (r, e) => new $({
2595
- innerType: r,
2596
- typeName: y.ZodOptional,
2597
- ...v(e)
2598
- });
2599
- class G extends _ {
2600
- _parse(e) {
2601
- return this._getType(e) === f.null ? S(null) : this._def.innerType._parse(e);
2602
- }
2603
- unwrap() {
2604
- return this._def.innerType;
2605
- }
2606
- }
2607
- G.create = (r, e) => new G({
2608
- innerType: r,
2609
- typeName: y.ZodNullable,
2610
- ...v(e)
2611
- });
2612
- class ke extends _ {
2613
- _parse(e) {
2614
- const { ctx: t } = this._processInputParams(e);
2615
- let n = t.data;
2616
- return t.parsedType === f.undefined && (n = this._def.defaultValue()), this._def.innerType._parse({
2617
- data: n,
2618
- path: t.path,
2619
- parent: t
2620
- });
2621
- }
2622
- removeDefault() {
2623
- return this._def.innerType;
2624
- }
2625
- }
2626
- ke.create = (r, e) => new ke({
2627
- innerType: r,
2628
- typeName: y.ZodDefault,
2629
- defaultValue: typeof e.default == "function" ? e.default : () => e.default,
2630
- ...v(e)
2631
- });
2632
- class be extends _ {
2633
- _parse(e) {
2634
- const { ctx: t } = this._processInputParams(e), n = {
2635
- ...t,
2636
- common: {
2637
- ...t.common,
2638
- issues: []
2639
- }
2640
- }, s = this._def.innerType._parse({
2641
- data: n.data,
2642
- path: n.path,
2643
- parent: {
2644
- ...n
2645
- }
2646
- });
2647
- return le(s) ? s.then((a) => ({
2648
- status: "valid",
2649
- value: a.status === "valid" ? a.value : this._def.catchValue({
2650
- get error() {
2651
- return new O(n.common.issues);
2652
- },
2653
- input: n.data
2654
- })
2655
- })) : {
2656
- status: "valid",
2657
- value: s.status === "valid" ? s.value : this._def.catchValue({
2658
- get error() {
2659
- return new O(n.common.issues);
2660
- },
2661
- input: n.data
2662
- })
2663
- };
2664
- }
2665
- removeCatch() {
2666
- return this._def.innerType;
2667
- }
2668
- }
2669
- be.create = (r, e) => new be({
2670
- innerType: r,
2671
- typeName: y.ZodCatch,
2672
- catchValue: typeof e.catch == "function" ? e.catch : () => e.catch,
2673
- ...v(e)
2674
- });
2675
- class $e extends _ {
2676
- _parse(e) {
2677
- if (this._getType(e) !== f.nan) {
2678
- const n = this._getOrReturnCtx(e);
2679
- return l(n, {
2680
- code: c.invalid_type,
2681
- expected: f.nan,
2682
- received: n.parsedType
2683
- }), g;
2684
- }
2685
- return { status: "valid", value: e.data };
2686
- }
2687
- }
2688
- $e.create = (r) => new $e({
2689
- typeName: y.ZodNaN,
2690
- ...v(r)
2691
- });
2692
- const nr = Symbol("zod_brand");
2693
- class Je extends _ {
2694
- _parse(e) {
2695
- const { ctx: t } = this._processInputParams(e), n = t.data;
2696
- return this._def.type._parse({
2697
- data: n,
2698
- path: t.path,
2699
- parent: t
2700
- });
2701
- }
2702
- unwrap() {
2703
- return this._def.type;
2704
- }
2705
- }
2706
- class Te extends _ {
2707
- _parse(e) {
2708
- const { status: t, ctx: n } = this._processInputParams(e);
2709
- if (n.common.async)
2710
- return (async () => {
2711
- const a = await this._def.in._parseAsync({
2712
- data: n.data,
2713
- path: n.path,
2714
- parent: n
2715
- });
2716
- return a.status === "aborted" ? g : a.status === "dirty" ? (t.dirty(), re(a.value)) : this._def.out._parseAsync({
2717
- data: a.value,
2718
- path: n.path,
2719
- parent: n
2720
- });
2721
- })();
2722
- {
2723
- const s = this._def.in._parseSync({
2724
- data: n.data,
2725
- path: n.path,
2726
- parent: n
2727
- });
2728
- return s.status === "aborted" ? g : s.status === "dirty" ? (t.dirty(), {
2729
- status: "dirty",
2730
- value: s.value
2731
- }) : this._def.out._parseSync({
2732
- data: s.value,
2733
- path: n.path,
2734
- parent: n
2735
- });
2736
- }
2737
- }
2738
- static create(e, t) {
2739
- return new Te({
2740
- in: e,
2741
- out: t,
2742
- typeName: y.ZodPipeline
2743
- });
2744
- }
2745
- }
2746
- class we extends _ {
2747
- _parse(e) {
2748
- const t = this._def.innerType._parse(e), n = (s) => (ue(s) && (s.value = Object.freeze(s.value)), s);
2749
- return le(t) ? t.then((s) => n(s)) : n(t);
2750
- }
2751
- unwrap() {
2752
- return this._def.innerType;
2753
- }
2754
- }
2755
- we.create = (r, e) => new we({
2756
- innerType: r,
2757
- typeName: y.ZodReadonly,
2758
- ...v(e)
2759
- });
2760
- function pt(r, e = {}, t) {
2761
- return r ? ae.create().superRefine((n, s) => {
2762
- var a, i;
2763
- if (!r(n)) {
2764
- const o = typeof e == "function" ? e(n) : typeof e == "string" ? { message: e } : e, u = (i = (a = o.fatal) !== null && a !== void 0 ? a : t) !== null && i !== void 0 ? i : !0, d = typeof o == "string" ? { message: o } : o;
2765
- s.addIssue({ code: "custom", ...d, fatal: u });
2766
- }
2767
- }) : ae.create();
2768
- }
2769
- const sr = {
2770
- object: b.lazycreate
2771
- };
2772
- var y;
2773
- (function(r) {
2774
- r.ZodString = "ZodString", r.ZodNumber = "ZodNumber", r.ZodNaN = "ZodNaN", r.ZodBigInt = "ZodBigInt", r.ZodBoolean = "ZodBoolean", r.ZodDate = "ZodDate", r.ZodSymbol = "ZodSymbol", r.ZodUndefined = "ZodUndefined", r.ZodNull = "ZodNull", r.ZodAny = "ZodAny", r.ZodUnknown = "ZodUnknown", r.ZodNever = "ZodNever", r.ZodVoid = "ZodVoid", r.ZodArray = "ZodArray", r.ZodObject = "ZodObject", r.ZodUnion = "ZodUnion", r.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", r.ZodIntersection = "ZodIntersection", r.ZodTuple = "ZodTuple", r.ZodRecord = "ZodRecord", r.ZodMap = "ZodMap", r.ZodSet = "ZodSet", r.ZodFunction = "ZodFunction", r.ZodLazy = "ZodLazy", r.ZodLiteral = "ZodLiteral", r.ZodEnum = "ZodEnum", r.ZodEffects = "ZodEffects", r.ZodNativeEnum = "ZodNativeEnum", r.ZodOptional = "ZodOptional", r.ZodNullable = "ZodNullable", r.ZodDefault = "ZodDefault", r.ZodCatch = "ZodCatch", r.ZodPromise = "ZodPromise", r.ZodBranded = "ZodBranded", r.ZodPipeline = "ZodPipeline", r.ZodReadonly = "ZodReadonly";
2775
- })(y || (y = {}));
2776
- const ar = (r, e = {
2777
- message: `Input not instance of ${r.name}`
2778
- }) => pt((t) => t instanceof r, e), mt = I.create, yt = W.create, ir = $e.create, or = q.create, gt = fe.create, cr = X.create, dr = Ie.create, ur = he.create, lr = pe.create, fr = ae.create, hr = J.create, pr = M.create, mr = Ae.create, yr = A.create, gr = b.create, vr = b.strictCreate, _r = me.create, xr = Pe.create, kr = ye.create, br = D.create, wr = ge.create, Tr = je.create, Er = Q.create, Sr = ne.create, Cr = ve.create, Or = _e.create, Rr = Y.create, Zr = xe.create, Nr = ie.create, nt = j.create, Ir = $.create, Ar = G.create, jr = j.createWithPreprocess, $r = Te.create, Pr = () => mt().optional(), Dr = () => yt().optional(), Ur = () => gt().optional(), Mr = {
2779
- string: (r) => I.create({ ...r, coerce: !0 }),
2780
- number: (r) => W.create({ ...r, coerce: !0 }),
2781
- boolean: (r) => fe.create({
2782
- ...r,
2783
- coerce: !0
2784
- }),
2785
- bigint: (r) => q.create({ ...r, coerce: !0 }),
2786
- date: (r) => X.create({ ...r, coerce: !0 })
2787
- }, Lr = g;
2788
- var m = /* @__PURE__ */ Object.freeze({
2789
- __proto__: null,
2790
- defaultErrorMap: se,
2791
- setErrorMap: Lt,
2792
- getErrorMap: Re,
2793
- makeIssue: Ze,
2794
- EMPTY_PATH: Vt,
2795
- addIssueToContext: l,
2796
- ParseStatus: E,
2797
- INVALID: g,
2798
- DIRTY: re,
2799
- OK: S,
2800
- isAborted: We,
2801
- isDirty: qe,
2802
- isValid: ue,
2803
- isAsync: le,
2804
- get util() {
2805
- return x;
2806
- },
2807
- get objectUtil() {
2808
- return Ke;
2809
- },
2810
- ZodParsedType: f,
2811
- getParsedType: H,
2812
- ZodType: _,
2813
- datetimeRegex: ft,
2814
- ZodString: I,
2815
- ZodNumber: W,
2816
- ZodBigInt: q,
2817
- ZodBoolean: fe,
2818
- ZodDate: X,
2819
- ZodSymbol: Ie,
2820
- ZodUndefined: he,
2821
- ZodNull: pe,
2822
- ZodAny: ae,
2823
- ZodUnknown: J,
2824
- ZodNever: M,
2825
- ZodVoid: Ae,
2826
- ZodArray: A,
2827
- ZodObject: b,
2828
- ZodUnion: me,
2829
- ZodDiscriminatedUnion: Pe,
2830
- ZodIntersection: ye,
2831
- ZodTuple: D,
2832
- ZodRecord: ge,
2833
- ZodMap: je,
2834
- ZodSet: Q,
2835
- ZodFunction: ne,
2836
- ZodLazy: ve,
2837
- ZodLiteral: _e,
2838
- ZodEnum: Y,
2839
- ZodNativeEnum: xe,
2840
- ZodPromise: ie,
2841
- ZodEffects: j,
2842
- ZodTransformer: j,
2843
- ZodOptional: $,
2844
- ZodNullable: G,
2845
- ZodDefault: ke,
2846
- ZodCatch: be,
2847
- ZodNaN: $e,
2848
- BRAND: nr,
2849
- ZodBranded: Je,
2850
- ZodPipeline: Te,
2851
- ZodReadonly: we,
2852
- custom: pt,
2853
- Schema: _,
2854
- ZodSchema: _,
2855
- late: sr,
2856
- get ZodFirstPartyTypeKind() {
2857
- return y;
2858
- },
2859
- coerce: Mr,
2860
- any: fr,
2861
- array: yr,
2862
- bigint: or,
2863
- boolean: gt,
2864
- date: cr,
2865
- discriminatedUnion: xr,
2866
- effect: nt,
2867
- enum: Rr,
2868
- function: Sr,
2869
- instanceof: ar,
2870
- intersection: kr,
2871
- lazy: Cr,
2872
- literal: Or,
2873
- map: Tr,
2874
- nan: ir,
2875
- nativeEnum: Zr,
2876
- never: pr,
2877
- null: lr,
2878
- nullable: Ar,
2879
- number: yt,
2880
- object: gr,
2881
- oboolean: Ur,
2882
- onumber: Dr,
2883
- optional: Ir,
2884
- ostring: Pr,
2885
- pipeline: $r,
2886
- preprocess: jr,
2887
- promise: Nr,
2888
- record: wr,
2889
- set: Er,
2890
- strictObject: vr,
2891
- string: mt,
2892
- symbol: dr,
2893
- transformer: nt,
2894
- tuple: br,
2895
- undefined: ur,
2896
- union: _r,
2897
- unknown: hr,
2898
- void: mr,
2899
- NEVER: Lr,
2900
- ZodIssueCode: c,
2901
- quotelessJson: Mt,
2902
- ZodError: O
2903
- }), Vr = /* @__PURE__ */ ((r) => (r.UNSTYLED = "unstyled", r.LIGHT = "light", r.DARK = "dark", r))(Vr || {});
2904
- const zr = m.object({
2905
- colorPrimary: m.string().optional(),
2906
- colorBackground: m.string().optional(),
2907
- colorForeground: m.string().optional(),
2908
- colorText: m.string().optional(),
2909
- colorDanger: m.string().optional(),
2910
- fontFamily: m.string().optional(),
2911
- fontSize: m.string().optional(),
2912
- spacing: m.string().optional(),
2913
- borderRadius: m.string().optional(),
2914
- borderColor: m.string().optional(),
2915
- borderWidth: m.string().optional(),
2916
- focusRingColor: m.string().optional(),
2917
- padding: m.string().optional()
2918
- }), an = m.object({
2919
- theme: m.enum([
2920
- "unstyled",
2921
- "light",
2922
- "dark"
2923
- /* DARK */
2924
- ]),
2925
- variables: zr.optional()
2926
- });
2927
- m.object({
2928
- backgroundColor: m.string().optional(),
2929
- color: m.string().optional(),
2930
- fontFamily: m.string().optional(),
2931
- fontSize: m.string().optional(),
2932
- fontWeight: m.string().optional(),
2933
- margin: m.string().optional(),
2934
- padding: m.string().optional()
2935
- });
2936
- var Br = /* @__PURE__ */ ((r) => (r.FIRST_NAME = "firstName", r.LAST_NAME = "lastName", r.EMAIL = "email", r.ZIP_CODE = "zipCode", r.CITY = "city", r.STATE = "state", r.COUNTRY = "country", r.ADDRESS = "address", r.PHONE = "phone", r))(Br || {});
2937
- const C = "op-elements";
2938
- var k = ((r) => (r.LOADED = `${C}-loaded`, r.BLUR = `${C}-blur`, r.FOCUS = `${C}-focus`, r.CHANGE = `${C}-change`, r.TOKENIZE_STARTED = `${C}-tokenize-started`, r.CHECKOUT_STARTED = `${C}-checkout-started`, r.TOKENIZE_SUCCESS = `${C}-tokenize-success`, r.CHECKOUT_SUCCESS = `${C}-checkout-success`, r.LOAD_ERROR = `${C}-load-error`, r.VALIDATION_ERROR = `${C}-validation-error`, r.TOKENIZE_ERROR = `${C}-tokenize-error`, r.CHECKOUT_ERROR = `${C}-checkout-error`, r.TOKENIZE = `${C}-tokenize`, r.CHECKOUT = `${C}-checkout`, r))(k || {});
2939
- const Hr = m.enum([
2940
- k.BLUR,
2941
- k.FOCUS,
2942
- k.CHANGE,
2943
- k.TOKENIZE_STARTED,
2944
- k.CHECKOUT_STARTED
2945
- ]), Kr = m.object({ type: Hr }), Wr = m.enum([
2946
- k.LOAD_ERROR,
2947
- k.VALIDATION_ERROR,
2948
- k.TOKENIZE_ERROR,
2949
- k.CHECKOUT_ERROR
2950
- ]), qr = m.object({
2951
- type: Wr,
2952
- message: m.string()
2953
- }), Yr = m.object({
2954
- type: m.literal(k.LOADED),
2955
- height: m.string(),
2956
- totalAmountAtoms: m.number()
2957
- }), Gr = m.enum([k.TOKENIZE, k.CHECKOUT]), vt = m.object({
2958
- type: Gr,
2959
- firstName: m.string(),
2960
- lastName: m.string(),
2961
- email: m.string(),
2962
- zipCode: m.string(),
2963
- country: m.string()
2964
- }), Jr = m.object({
2965
- type: m.literal(k.TOKENIZE_SUCCESS),
2966
- paymentToken: m.string()
2967
- }), Xr = m.object({
2968
- type: m.literal(k.CHECKOUT_SUCCESS),
2969
- invoiceUrls: m.array(m.string())
2970
- }), Qr = m.discriminatedUnion("type", [
2971
- Kr,
2972
- qr,
2973
- Yr,
2974
- vt,
2975
- Jr,
2976
- Xr
2977
- ]), Fr = m.object({
2978
- payload: Qr,
2979
- nonce: m.string(),
2980
- formId: m.string(),
2981
- elementId: m.string()
2982
- }), en = (r) => {
2983
- const t = Array.from(r.querySelectorAll("input[data-opid]") ?? []).reduce(
2984
- (n, s) => {
2985
- const a = s.getAttribute("data-opid");
2986
- return a ? { ...n, [a]: s.value } : n;
2987
- },
2988
- { type: k.TOKENIZE }
2989
- );
2990
- return vt.parse(t);
2991
- }, tn = (r) => {
2992
- try {
2993
- return Fr.parse(r);
2994
- } catch (e) {
2995
- throw e;
2996
- }
2997
- }, st = (r, e, t, n) => {
2998
- const s = {
2999
- payload: n,
3000
- nonce: Ut(),
3001
- formId: e,
3002
- elementId: t
3003
- };
3004
- r.postMessage(JSON.stringify(s), Ge);
3005
- }, on = (r) => {
3006
- const {
3007
- children: e,
3008
- checkoutSecureToken: t,
3009
- className: n,
3010
- onFocus: s,
3011
- onBlur: a,
3012
- onChange: i,
3013
- onLoad: o,
3014
- onLoadError: u,
3015
- onValidationError: d,
3016
- onCheckoutStarted: p,
3017
- onCheckoutSuccess: w,
3018
- onCheckoutError: L,
3019
- appearance: R
3020
- } = r, [_t, xt] = B(void 0), [F, kt] = B(""), [Xe, bt] = B([]), [Ee, wt] = B({}), [Tt, Et] = B("1px"), [Qe, St] = B(!1), [Ue, Fe] = B(void 0), [Me, Ct] = B(void 0), ee = it(null);
3021
- ze(() => kt(`opjs-form-${window.crypto.randomUUID()}`), []);
3022
- const Le = et(
3023
- (V) => {
3024
- const oe = V.source;
3025
- if (V.origin !== Ge || !oe) return;
3026
- const Z = tn(JSON.parse(V.data)), Se = Z.elementId;
3027
- if (Z.formId !== F || !Se || Z.nonce in Xe)
3028
- return;
3029
- bt((Ve) => [...Ve, Z.nonce]);
3030
- const z = Z.payload, N = z.type;
3031
- if (N === k.FOCUS && s)
3032
- s(Z.elementId);
3033
- else if (N === k.BLUR && a)
3034
- a(Z.elementId);
3035
- else if (N === k.CHANGE && i)
3036
- i(Z.elementId);
3037
- else if (N === k.LOADED) {
3038
- wt((Zt) => ({ ...Zt, [Se]: oe })), Ct(z.totalAmountAtoms);
3039
- const Ve = z.height ? `${z.height}px` : "100%";
3040
- Et(Ve);
3041
- } else N === k.TOKENIZE_STARTED ? p && p() : N === k.TOKENIZE_SUCCESS && Ue ? (st(oe, F, Se, Ue), Fe(void 0)) : N === k.CHECKOUT_SUCCESS ? w && w(z.invoiceUrls) : N === k.LOAD_ERROR ? u && u(z.message) : N === k.VALIDATION_ERROR ? d && d(z.message, Se) : (N === k.TOKENIZE_ERROR || N === k.CHECKOUT_ERROR) && L && L(z.message);
3042
- },
3043
- [
3044
- F,
3045
- Xe,
3046
- Ue,
3047
- a,
3048
- i,
3049
- s,
3050
- u,
3051
- p,
3052
- w,
3053
- L,
3054
- d
3055
- ]
3056
- ), Ot = et(() => {
3057
- if (!ee.current) return;
3058
- const V = en(ee.current);
3059
- for (const [oe, Z] of Object.entries(Ee))
3060
- Z && st(Z, F, oe, V);
3061
- V.type = k.CHECKOUT, Fe(V);
3062
- }, [ee, Ee, F]);
3063
- ze(() => {
3064
- if (Qe || !ee.current || !Me) return;
3065
- ee.current.querySelectorAll("iframe").length === Object.keys(Ee).length && (St(!0), o && o(Me));
3066
- }, [Ee, Qe, o, Me]), ze(() => (window.addEventListener("message", Le), xt(window.location.origin), () => window.removeEventListener("message", Le)), [Le]);
3067
- const Rt = {
3068
- contextId: F,
3069
- formHeight: Tt,
3070
- referer: _t,
3071
- checkoutSecureToken: t,
3072
- appearance: R
3073
- };
3074
- return /* @__PURE__ */ K(ot.Provider, { value: Rt, children: /* @__PURE__ */ K("div", { className: n, ref: ee, children: e({ submit: Ot }) }) });
3075
- }, at = (r) => encodeURIComponent(JSON.stringify(r)), De = (r) => {
3076
- const { subPath: e, styles: t } = r, { contextId: n, referer: s, formHeight: a, checkoutSecureToken: i, appearance: o } = At(), u = it(null), d = Ce(() => t ? at(t) : "", [t]), p = Ce(() => o ? at(o) : "", [o]), w = Ce(() => ({
3077
- border: "none",
3078
- width: "100%",
3079
- height: a
3080
- }), [a]), L = Ce(() => {
3081
- if (!i || !s) return "";
3082
- const R = new URLSearchParams();
3083
- return R.append("referer", s), R.append("styles", d), R.append("appearance", p), R.append("contextId", n), R.append("secureToken", i), R.toString();
3084
- }, [d, p, n, s, i]);
3085
- return i ? /* @__PURE__ */ K(
3086
- "iframe",
3087
- {
3088
- name: `${e}-element`,
3089
- src: `${Ge}/app/v1/${e}-element?${L}`,
3090
- style: w,
3091
- ref: u
3092
- }
3093
- ) : /* @__PURE__ */ K("div", {});
3094
- }, cn = (r) => /* @__PURE__ */ K(De, { subPath: "card-cvc", ...r }), dn = (r) => /* @__PURE__ */ K(De, { subPath: "card", ...r }), un = (r) => /* @__PURE__ */ K(De, { subPath: "card-expiry", ...r }), ln = (r) => /* @__PURE__ */ K(De, { subPath: "card-number", ...r });
3095
- export {
3096
- an as Appearance,
3097
- Vr as AppearanceTheme,
3098
- zr as AppearanceVariables,
3099
- cn as CardCvcElement,
3100
- dn as CardElement,
3101
- un as CardExpiryElement,
3102
- ln as CardNumberElement,
3103
- on as ElementsForm,
3104
- Br as FieldName,
3105
- At as useOpenPayElements
3106
- };