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