@chaos-maker/core 0.1.0

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