@quintal/environment 0.2.0 → 1.0.1

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