obi-sdk 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4364 @@
1
+ var util;
2
+ (function(util2) {
3
+ util2.assertEqual = (val) => val;
4
+ function assertIs(_arg) {
5
+ }
6
+ util2.assertIs = assertIs;
7
+ function assertNever(_x) {
8
+ throw new Error();
9
+ }
10
+ util2.assertNever = assertNever;
11
+ util2.arrayToEnum = (items) => {
12
+ const obj = {};
13
+ for (const item of items) {
14
+ obj[item] = item;
15
+ }
16
+ return obj;
17
+ };
18
+ util2.getValidEnumValues = (obj) => {
19
+ const validKeys = util2.objectKeys(obj).filter((k2) => typeof obj[obj[k2]] !== "number");
20
+ const filtered = {};
21
+ for (const k2 of validKeys) {
22
+ filtered[k2] = obj[k2];
23
+ }
24
+ return util2.objectValues(filtered);
25
+ };
26
+ util2.objectValues = (obj) => {
27
+ return util2.objectKeys(obj).map(function(e2) {
28
+ return obj[e2];
29
+ });
30
+ };
31
+ util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
32
+ const keys = [];
33
+ for (const key in object) {
34
+ if (Object.prototype.hasOwnProperty.call(object, key)) {
35
+ keys.push(key);
36
+ }
37
+ }
38
+ return keys;
39
+ };
40
+ util2.find = (arr, checker) => {
41
+ for (const item of arr) {
42
+ if (checker(item))
43
+ return item;
44
+ }
45
+ return void 0;
46
+ };
47
+ util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
48
+ function joinValues(array, separator = " | ") {
49
+ return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
50
+ }
51
+ util2.joinValues = joinValues;
52
+ util2.jsonStringifyReplacer = (_2, value) => {
53
+ if (typeof value === "bigint") {
54
+ return value.toString();
55
+ }
56
+ return value;
57
+ };
58
+ })(util || (util = {}));
59
+ var objectUtil;
60
+ (function(objectUtil2) {
61
+ objectUtil2.mergeShapes = (first, second) => {
62
+ return {
63
+ ...first,
64
+ ...second
65
+ // second overwrites first
66
+ };
67
+ };
68
+ })(objectUtil || (objectUtil = {}));
69
+ const ZodParsedType = util.arrayToEnum([
70
+ "string",
71
+ "nan",
72
+ "number",
73
+ "integer",
74
+ "float",
75
+ "boolean",
76
+ "date",
77
+ "bigint",
78
+ "symbol",
79
+ "function",
80
+ "undefined",
81
+ "null",
82
+ "array",
83
+ "object",
84
+ "unknown",
85
+ "promise",
86
+ "void",
87
+ "never",
88
+ "map",
89
+ "set"
90
+ ]);
91
+ const getParsedType = (data) => {
92
+ const t2 = typeof data;
93
+ switch (t2) {
94
+ case "undefined":
95
+ return ZodParsedType.undefined;
96
+ case "string":
97
+ return ZodParsedType.string;
98
+ case "number":
99
+ return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
100
+ case "boolean":
101
+ return ZodParsedType.boolean;
102
+ case "function":
103
+ return ZodParsedType.function;
104
+ case "bigint":
105
+ return ZodParsedType.bigint;
106
+ case "symbol":
107
+ return ZodParsedType.symbol;
108
+ case "object":
109
+ if (Array.isArray(data)) {
110
+ return ZodParsedType.array;
111
+ }
112
+ if (data === null) {
113
+ return ZodParsedType.null;
114
+ }
115
+ if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
116
+ return ZodParsedType.promise;
117
+ }
118
+ if (typeof Map !== "undefined" && data instanceof Map) {
119
+ return ZodParsedType.map;
120
+ }
121
+ if (typeof Set !== "undefined" && data instanceof Set) {
122
+ return ZodParsedType.set;
123
+ }
124
+ if (typeof Date !== "undefined" && data instanceof Date) {
125
+ return ZodParsedType.date;
126
+ }
127
+ return ZodParsedType.object;
128
+ default:
129
+ return ZodParsedType.unknown;
130
+ }
131
+ };
132
+ const ZodIssueCode = util.arrayToEnum([
133
+ "invalid_type",
134
+ "invalid_literal",
135
+ "custom",
136
+ "invalid_union",
137
+ "invalid_union_discriminator",
138
+ "invalid_enum_value",
139
+ "unrecognized_keys",
140
+ "invalid_arguments",
141
+ "invalid_return_type",
142
+ "invalid_date",
143
+ "invalid_string",
144
+ "too_small",
145
+ "too_big",
146
+ "invalid_intersection_types",
147
+ "not_multiple_of",
148
+ "not_finite"
149
+ ]);
150
+ const quotelessJson = (obj) => {
151
+ const json = JSON.stringify(obj, null, 2);
152
+ return json.replace(/"([^"]+)":/g, "$1:");
153
+ };
154
+ class ZodError extends Error {
155
+ get errors() {
156
+ return this.issues;
157
+ }
158
+ constructor(issues) {
159
+ super();
160
+ this.issues = [];
161
+ this.addIssue = (sub) => {
162
+ this.issues = [...this.issues, sub];
163
+ };
164
+ this.addIssues = (subs = []) => {
165
+ this.issues = [...this.issues, ...subs];
166
+ };
167
+ const actualProto = new.target.prototype;
168
+ if (Object.setPrototypeOf) {
169
+ Object.setPrototypeOf(this, actualProto);
170
+ } else {
171
+ this.__proto__ = actualProto;
172
+ }
173
+ this.name = "ZodError";
174
+ this.issues = issues;
175
+ }
176
+ format(_mapper) {
177
+ const mapper = _mapper || function(issue) {
178
+ return issue.message;
179
+ };
180
+ const fieldErrors = { _errors: [] };
181
+ const processError = (error) => {
182
+ for (const issue of error.issues) {
183
+ if (issue.code === "invalid_union") {
184
+ issue.unionErrors.map(processError);
185
+ } else if (issue.code === "invalid_return_type") {
186
+ processError(issue.returnTypeError);
187
+ } else if (issue.code === "invalid_arguments") {
188
+ processError(issue.argumentsError);
189
+ } else if (issue.path.length === 0) {
190
+ fieldErrors._errors.push(mapper(issue));
191
+ } else {
192
+ let curr = fieldErrors;
193
+ let i2 = 0;
194
+ while (i2 < issue.path.length) {
195
+ const el = issue.path[i2];
196
+ const terminal = i2 === issue.path.length - 1;
197
+ if (!terminal) {
198
+ curr[el] = curr[el] || { _errors: [] };
199
+ } else {
200
+ curr[el] = curr[el] || { _errors: [] };
201
+ curr[el]._errors.push(mapper(issue));
202
+ }
203
+ curr = curr[el];
204
+ i2++;
205
+ }
206
+ }
207
+ }
208
+ };
209
+ processError(this);
210
+ return fieldErrors;
211
+ }
212
+ static assert(value) {
213
+ if (!(value instanceof ZodError)) {
214
+ throw new Error(`Not a ZodError: ${value}`);
215
+ }
216
+ }
217
+ toString() {
218
+ return this.message;
219
+ }
220
+ get message() {
221
+ return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
222
+ }
223
+ get isEmpty() {
224
+ return this.issues.length === 0;
225
+ }
226
+ flatten(mapper = (issue) => issue.message) {
227
+ const fieldErrors = {};
228
+ const formErrors = [];
229
+ for (const sub of this.issues) {
230
+ if (sub.path.length > 0) {
231
+ fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
232
+ fieldErrors[sub.path[0]].push(mapper(sub));
233
+ } else {
234
+ formErrors.push(mapper(sub));
235
+ }
236
+ }
237
+ return { formErrors, fieldErrors };
238
+ }
239
+ get formErrors() {
240
+ return this.flatten();
241
+ }
242
+ }
243
+ ZodError.create = (issues) => {
244
+ const error = new ZodError(issues);
245
+ return error;
246
+ };
247
+ const errorMap = (issue, _ctx) => {
248
+ let message;
249
+ switch (issue.code) {
250
+ case ZodIssueCode.invalid_type:
251
+ if (issue.received === ZodParsedType.undefined) {
252
+ message = "Required";
253
+ } else {
254
+ message = `Expected ${issue.expected}, received ${issue.received}`;
255
+ }
256
+ break;
257
+ case ZodIssueCode.invalid_literal:
258
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
259
+ break;
260
+ case ZodIssueCode.unrecognized_keys:
261
+ message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
262
+ break;
263
+ case ZodIssueCode.invalid_union:
264
+ message = `Invalid input`;
265
+ break;
266
+ case ZodIssueCode.invalid_union_discriminator:
267
+ message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
268
+ break;
269
+ case ZodIssueCode.invalid_enum_value:
270
+ message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
271
+ break;
272
+ case ZodIssueCode.invalid_arguments:
273
+ message = `Invalid function arguments`;
274
+ break;
275
+ case ZodIssueCode.invalid_return_type:
276
+ message = `Invalid function return type`;
277
+ break;
278
+ case ZodIssueCode.invalid_date:
279
+ message = `Invalid date`;
280
+ break;
281
+ case ZodIssueCode.invalid_string:
282
+ if (typeof issue.validation === "object") {
283
+ if ("includes" in issue.validation) {
284
+ message = `Invalid input: must include "${issue.validation.includes}"`;
285
+ if (typeof issue.validation.position === "number") {
286
+ message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
287
+ }
288
+ } else if ("startsWith" in issue.validation) {
289
+ message = `Invalid input: must start with "${issue.validation.startsWith}"`;
290
+ } else if ("endsWith" in issue.validation) {
291
+ message = `Invalid input: must end with "${issue.validation.endsWith}"`;
292
+ } else {
293
+ util.assertNever(issue.validation);
294
+ }
295
+ } else if (issue.validation !== "regex") {
296
+ message = `Invalid ${issue.validation}`;
297
+ } else {
298
+ message = "Invalid";
299
+ }
300
+ break;
301
+ case ZodIssueCode.too_small:
302
+ if (issue.type === "array")
303
+ message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
304
+ else if (issue.type === "string")
305
+ message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
306
+ else if (issue.type === "number")
307
+ message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
308
+ else if (issue.type === "date")
309
+ message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
310
+ else
311
+ message = "Invalid input";
312
+ break;
313
+ case ZodIssueCode.too_big:
314
+ if (issue.type === "array")
315
+ message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
316
+ else if (issue.type === "string")
317
+ message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
318
+ else if (issue.type === "number")
319
+ message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
320
+ else if (issue.type === "bigint")
321
+ message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
322
+ else if (issue.type === "date")
323
+ message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
324
+ else
325
+ message = "Invalid input";
326
+ break;
327
+ case ZodIssueCode.custom:
328
+ message = `Invalid input`;
329
+ break;
330
+ case ZodIssueCode.invalid_intersection_types:
331
+ message = `Intersection results could not be merged`;
332
+ break;
333
+ case ZodIssueCode.not_multiple_of:
334
+ message = `Number must be a multiple of ${issue.multipleOf}`;
335
+ break;
336
+ case ZodIssueCode.not_finite:
337
+ message = "Number must be finite";
338
+ break;
339
+ default:
340
+ message = _ctx.defaultError;
341
+ util.assertNever(issue);
342
+ }
343
+ return { message };
344
+ };
345
+ let overrideErrorMap = errorMap;
346
+ function setErrorMap(map) {
347
+ overrideErrorMap = map;
348
+ }
349
+ function getErrorMap() {
350
+ return overrideErrorMap;
351
+ }
352
+ const makeIssue = (params) => {
353
+ const { data, path, errorMaps, issueData } = params;
354
+ const fullPath = [...path, ...issueData.path || []];
355
+ const fullIssue = {
356
+ ...issueData,
357
+ path: fullPath
358
+ };
359
+ if (issueData.message !== void 0) {
360
+ return {
361
+ ...issueData,
362
+ path: fullPath,
363
+ message: issueData.message
364
+ };
365
+ }
366
+ let errorMessage = "";
367
+ const maps = errorMaps.filter((m2) => !!m2).slice().reverse();
368
+ for (const map of maps) {
369
+ errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
370
+ }
371
+ return {
372
+ ...issueData,
373
+ path: fullPath,
374
+ message: errorMessage
375
+ };
376
+ };
377
+ const EMPTY_PATH = [];
378
+ function addIssueToContext(ctx, issueData) {
379
+ const overrideMap = getErrorMap();
380
+ const issue = makeIssue({
381
+ issueData,
382
+ data: ctx.data,
383
+ path: ctx.path,
384
+ errorMaps: [
385
+ ctx.common.contextualErrorMap,
386
+ // contextual error map is first priority
387
+ ctx.schemaErrorMap,
388
+ // then schema-bound map if available
389
+ overrideMap,
390
+ // then global override map
391
+ overrideMap === errorMap ? void 0 : errorMap
392
+ // then global default map
393
+ ].filter((x2) => !!x2)
394
+ });
395
+ ctx.common.issues.push(issue);
396
+ }
397
+ class ParseStatus {
398
+ constructor() {
399
+ this.value = "valid";
400
+ }
401
+ dirty() {
402
+ if (this.value === "valid")
403
+ this.value = "dirty";
404
+ }
405
+ abort() {
406
+ if (this.value !== "aborted")
407
+ this.value = "aborted";
408
+ }
409
+ static mergeArray(status, results) {
410
+ const arrayValue = [];
411
+ for (const s2 of results) {
412
+ if (s2.status === "aborted")
413
+ return INVALID;
414
+ if (s2.status === "dirty")
415
+ status.dirty();
416
+ arrayValue.push(s2.value);
417
+ }
418
+ return { status: status.value, value: arrayValue };
419
+ }
420
+ static async mergeObjectAsync(status, pairs) {
421
+ const syncPairs = [];
422
+ for (const pair of pairs) {
423
+ const key = await pair.key;
424
+ const value = await pair.value;
425
+ syncPairs.push({
426
+ key,
427
+ value
428
+ });
429
+ }
430
+ return ParseStatus.mergeObjectSync(status, syncPairs);
431
+ }
432
+ static mergeObjectSync(status, pairs) {
433
+ const finalObject = {};
434
+ for (const pair of pairs) {
435
+ const { key, value } = pair;
436
+ if (key.status === "aborted")
437
+ return INVALID;
438
+ if (value.status === "aborted")
439
+ return INVALID;
440
+ if (key.status === "dirty")
441
+ status.dirty();
442
+ if (value.status === "dirty")
443
+ status.dirty();
444
+ if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
445
+ finalObject[key.value] = value.value;
446
+ }
447
+ }
448
+ return { status: status.value, value: finalObject };
449
+ }
450
+ }
451
+ const INVALID = Object.freeze({
452
+ status: "aborted"
453
+ });
454
+ const DIRTY = (value) => ({ status: "dirty", value });
455
+ const OK = (value) => ({ status: "valid", value });
456
+ const isAborted = (x2) => x2.status === "aborted";
457
+ const isDirty = (x2) => x2.status === "dirty";
458
+ const isValid = (x2) => x2.status === "valid";
459
+ const isAsync = (x2) => typeof Promise !== "undefined" && x2 instanceof Promise;
460
+ function __classPrivateFieldGet(receiver, state, kind, f2) {
461
+ if (kind === "a" && !f2)
462
+ throw new TypeError("Private accessor was defined without a getter");
463
+ if (typeof state === "function" ? receiver !== state || !f2 : !state.has(receiver))
464
+ throw new TypeError("Cannot read private member from an object whose class did not declare it");
465
+ return kind === "m" ? f2 : kind === "a" ? f2.call(receiver) : f2 ? f2.value : state.get(receiver);
466
+ }
467
+ function __classPrivateFieldSet(receiver, state, value, kind, f2) {
468
+ if (kind === "m")
469
+ throw new TypeError("Private method is not writable");
470
+ if (kind === "a" && !f2)
471
+ throw new TypeError("Private accessor was defined without a setter");
472
+ if (typeof state === "function" ? receiver !== state || !f2 : !state.has(receiver))
473
+ throw new TypeError("Cannot write private member to an object whose class did not declare it");
474
+ return kind === "a" ? f2.call(receiver, value) : f2 ? f2.value = value : state.set(receiver, value), value;
475
+ }
476
+ typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
477
+ var e2 = new Error(message);
478
+ return e2.name = "SuppressedError", e2.error = error, e2.suppressed = suppressed, e2;
479
+ };
480
+ var errorUtil;
481
+ (function(errorUtil2) {
482
+ errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
483
+ errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
484
+ })(errorUtil || (errorUtil = {}));
485
+ var _ZodEnum_cache, _ZodNativeEnum_cache;
486
+ class ParseInputLazyPath {
487
+ constructor(parent, value, path, key) {
488
+ this._cachedPath = [];
489
+ this.parent = parent;
490
+ this.data = value;
491
+ this._path = path;
492
+ this._key = key;
493
+ }
494
+ get path() {
495
+ if (!this._cachedPath.length) {
496
+ if (this._key instanceof Array) {
497
+ this._cachedPath.push(...this._path, ...this._key);
498
+ } else {
499
+ this._cachedPath.push(...this._path, this._key);
500
+ }
501
+ }
502
+ return this._cachedPath;
503
+ }
504
+ }
505
+ const handleResult = (ctx, result) => {
506
+ if (isValid(result)) {
507
+ return { success: true, data: result.value };
508
+ } else {
509
+ if (!ctx.common.issues.length) {
510
+ throw new Error("Validation failed but no issues detected.");
511
+ }
512
+ return {
513
+ success: false,
514
+ get error() {
515
+ if (this._error)
516
+ return this._error;
517
+ const error = new ZodError(ctx.common.issues);
518
+ this._error = error;
519
+ return this._error;
520
+ }
521
+ };
522
+ }
523
+ };
524
+ function processCreateParams(params) {
525
+ if (!params)
526
+ return {};
527
+ const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
528
+ if (errorMap2 && (invalid_type_error || required_error)) {
529
+ throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
530
+ }
531
+ if (errorMap2)
532
+ return { errorMap: errorMap2, description };
533
+ const customMap = (iss, ctx) => {
534
+ var _a, _b;
535
+ const { message } = params;
536
+ if (iss.code === "invalid_enum_value") {
537
+ return { message: message !== null && message !== void 0 ? message : ctx.defaultError };
538
+ }
539
+ if (typeof ctx.data === "undefined") {
540
+ return { message: (_a = message !== null && message !== void 0 ? message : required_error) !== null && _a !== void 0 ? _a : ctx.defaultError };
541
+ }
542
+ if (iss.code !== "invalid_type")
543
+ return { message: ctx.defaultError };
544
+ return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
545
+ };
546
+ return { errorMap: customMap, description };
547
+ }
548
+ class ZodType {
549
+ get description() {
550
+ return this._def.description;
551
+ }
552
+ _getType(input) {
553
+ return getParsedType(input.data);
554
+ }
555
+ _getOrReturnCtx(input, ctx) {
556
+ return ctx || {
557
+ common: input.parent.common,
558
+ data: input.data,
559
+ parsedType: getParsedType(input.data),
560
+ schemaErrorMap: this._def.errorMap,
561
+ path: input.path,
562
+ parent: input.parent
563
+ };
564
+ }
565
+ _processInputParams(input) {
566
+ return {
567
+ status: new ParseStatus(),
568
+ ctx: {
569
+ common: input.parent.common,
570
+ data: input.data,
571
+ parsedType: getParsedType(input.data),
572
+ schemaErrorMap: this._def.errorMap,
573
+ path: input.path,
574
+ parent: input.parent
575
+ }
576
+ };
577
+ }
578
+ _parseSync(input) {
579
+ const result = this._parse(input);
580
+ if (isAsync(result)) {
581
+ throw new Error("Synchronous parse encountered promise.");
582
+ }
583
+ return result;
584
+ }
585
+ _parseAsync(input) {
586
+ const result = this._parse(input);
587
+ return Promise.resolve(result);
588
+ }
589
+ parse(data, params) {
590
+ const result = this.safeParse(data, params);
591
+ if (result.success)
592
+ return result.data;
593
+ throw result.error;
594
+ }
595
+ safeParse(data, params) {
596
+ var _a;
597
+ const ctx = {
598
+ common: {
599
+ issues: [],
600
+ async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
601
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
602
+ },
603
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
604
+ schemaErrorMap: this._def.errorMap,
605
+ parent: null,
606
+ data,
607
+ parsedType: getParsedType(data)
608
+ };
609
+ const result = this._parseSync({ data, path: ctx.path, parent: ctx });
610
+ return handleResult(ctx, result);
611
+ }
612
+ "~validate"(data) {
613
+ var _a, _b;
614
+ const ctx = {
615
+ common: {
616
+ issues: [],
617
+ async: !!this["~standard"].async
618
+ },
619
+ path: [],
620
+ schemaErrorMap: this._def.errorMap,
621
+ parent: null,
622
+ data,
623
+ parsedType: getParsedType(data)
624
+ };
625
+ if (!this["~standard"].async) {
626
+ try {
627
+ const result = this._parseSync({ data, path: [], parent: ctx });
628
+ return isValid(result) ? {
629
+ value: result.value
630
+ } : {
631
+ issues: ctx.common.issues
632
+ };
633
+ } catch (err) {
634
+ if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
635
+ this["~standard"].async = true;
636
+ }
637
+ ctx.common = {
638
+ issues: [],
639
+ async: true
640
+ };
641
+ }
642
+ }
643
+ return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
644
+ value: result.value
645
+ } : {
646
+ issues: ctx.common.issues
647
+ });
648
+ }
649
+ async parseAsync(data, params) {
650
+ const result = await this.safeParseAsync(data, params);
651
+ if (result.success)
652
+ return result.data;
653
+ throw result.error;
654
+ }
655
+ async safeParseAsync(data, params) {
656
+ const ctx = {
657
+ common: {
658
+ issues: [],
659
+ contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
660
+ async: true
661
+ },
662
+ path: (params === null || params === void 0 ? void 0 : params.path) || [],
663
+ schemaErrorMap: this._def.errorMap,
664
+ parent: null,
665
+ data,
666
+ parsedType: getParsedType(data)
667
+ };
668
+ const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
669
+ const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
670
+ return handleResult(ctx, result);
671
+ }
672
+ refine(check, message) {
673
+ const getIssueProperties = (val) => {
674
+ if (typeof message === "string" || typeof message === "undefined") {
675
+ return { message };
676
+ } else if (typeof message === "function") {
677
+ return message(val);
678
+ } else {
679
+ return message;
680
+ }
681
+ };
682
+ return this._refinement((val, ctx) => {
683
+ const result = check(val);
684
+ const setError = () => ctx.addIssue({
685
+ code: ZodIssueCode.custom,
686
+ ...getIssueProperties(val)
687
+ });
688
+ if (typeof Promise !== "undefined" && result instanceof Promise) {
689
+ return result.then((data) => {
690
+ if (!data) {
691
+ setError();
692
+ return false;
693
+ } else {
694
+ return true;
695
+ }
696
+ });
697
+ }
698
+ if (!result) {
699
+ setError();
700
+ return false;
701
+ } else {
702
+ return true;
703
+ }
704
+ });
705
+ }
706
+ refinement(check, refinementData) {
707
+ return this._refinement((val, ctx) => {
708
+ if (!check(val)) {
709
+ ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
710
+ return false;
711
+ } else {
712
+ return true;
713
+ }
714
+ });
715
+ }
716
+ _refinement(refinement) {
717
+ return new ZodEffects({
718
+ schema: this,
719
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
720
+ effect: { type: "refinement", refinement }
721
+ });
722
+ }
723
+ superRefine(refinement) {
724
+ return this._refinement(refinement);
725
+ }
726
+ constructor(def) {
727
+ this.spa = this.safeParseAsync;
728
+ this._def = def;
729
+ this.parse = this.parse.bind(this);
730
+ this.safeParse = this.safeParse.bind(this);
731
+ this.parseAsync = this.parseAsync.bind(this);
732
+ this.safeParseAsync = this.safeParseAsync.bind(this);
733
+ this.spa = this.spa.bind(this);
734
+ this.refine = this.refine.bind(this);
735
+ this.refinement = this.refinement.bind(this);
736
+ this.superRefine = this.superRefine.bind(this);
737
+ this.optional = this.optional.bind(this);
738
+ this.nullable = this.nullable.bind(this);
739
+ this.nullish = this.nullish.bind(this);
740
+ this.array = this.array.bind(this);
741
+ this.promise = this.promise.bind(this);
742
+ this.or = this.or.bind(this);
743
+ this.and = this.and.bind(this);
744
+ this.transform = this.transform.bind(this);
745
+ this.brand = this.brand.bind(this);
746
+ this.default = this.default.bind(this);
747
+ this.catch = this.catch.bind(this);
748
+ this.describe = this.describe.bind(this);
749
+ this.pipe = this.pipe.bind(this);
750
+ this.readonly = this.readonly.bind(this);
751
+ this.isNullable = this.isNullable.bind(this);
752
+ this.isOptional = this.isOptional.bind(this);
753
+ this["~standard"] = {
754
+ version: 1,
755
+ vendor: "zod",
756
+ validate: (data) => this["~validate"](data)
757
+ };
758
+ }
759
+ optional() {
760
+ return ZodOptional.create(this, this._def);
761
+ }
762
+ nullable() {
763
+ return ZodNullable.create(this, this._def);
764
+ }
765
+ nullish() {
766
+ return this.nullable().optional();
767
+ }
768
+ array() {
769
+ return ZodArray.create(this);
770
+ }
771
+ promise() {
772
+ return ZodPromise.create(this, this._def);
773
+ }
774
+ or(option) {
775
+ return ZodUnion.create([this, option], this._def);
776
+ }
777
+ and(incoming) {
778
+ return ZodIntersection.create(this, incoming, this._def);
779
+ }
780
+ transform(transform) {
781
+ return new ZodEffects({
782
+ ...processCreateParams(this._def),
783
+ schema: this,
784
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
785
+ effect: { type: "transform", transform }
786
+ });
787
+ }
788
+ default(def) {
789
+ const defaultValueFunc = typeof def === "function" ? def : () => def;
790
+ return new ZodDefault({
791
+ ...processCreateParams(this._def),
792
+ innerType: this,
793
+ defaultValue: defaultValueFunc,
794
+ typeName: ZodFirstPartyTypeKind.ZodDefault
795
+ });
796
+ }
797
+ brand() {
798
+ return new ZodBranded({
799
+ typeName: ZodFirstPartyTypeKind.ZodBranded,
800
+ type: this,
801
+ ...processCreateParams(this._def)
802
+ });
803
+ }
804
+ catch(def) {
805
+ const catchValueFunc = typeof def === "function" ? def : () => def;
806
+ return new ZodCatch({
807
+ ...processCreateParams(this._def),
808
+ innerType: this,
809
+ catchValue: catchValueFunc,
810
+ typeName: ZodFirstPartyTypeKind.ZodCatch
811
+ });
812
+ }
813
+ describe(description) {
814
+ const This = this.constructor;
815
+ return new This({
816
+ ...this._def,
817
+ description
818
+ });
819
+ }
820
+ pipe(target) {
821
+ return ZodPipeline.create(this, target);
822
+ }
823
+ readonly() {
824
+ return ZodReadonly.create(this);
825
+ }
826
+ isOptional() {
827
+ return this.safeParse(void 0).success;
828
+ }
829
+ isNullable() {
830
+ return this.safeParse(null).success;
831
+ }
832
+ }
833
+ const cuidRegex = /^c[^\s-]{8,}$/i;
834
+ const cuid2Regex = /^[0-9a-z]+$/;
835
+ const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
836
+ const uuidRegex = /^[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;
837
+ const nanoidRegex = /^[a-z0-9_-]{21}$/i;
838
+ const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
839
+ const durationRegex = /^[-+]?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)?)??$/;
840
+ const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
841
+ const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
842
+ let emojiRegex;
843
+ const ipv4Regex = /^(?:(?: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])$/;
844
+ const ipv4CidrRegex = /^(?:(?: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])$/;
845
+ const ipv6Regex = /^(([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]))$/;
846
+ const ipv6CidrRegex = /^(([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])$/;
847
+ const base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
848
+ const base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
849
+ const dateRegexSource = `((\\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])))`;
850
+ const dateRegex = new RegExp(`^${dateRegexSource}$`);
851
+ function timeRegexSource(args) {
852
+ let regex = `([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d`;
853
+ if (args.precision) {
854
+ regex = `${regex}\\.\\d{${args.precision}}`;
855
+ } else if (args.precision == null) {
856
+ regex = `${regex}(\\.\\d+)?`;
857
+ }
858
+ return regex;
859
+ }
860
+ function timeRegex(args) {
861
+ return new RegExp(`^${timeRegexSource(args)}$`);
862
+ }
863
+ function datetimeRegex(args) {
864
+ let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
865
+ const opts = [];
866
+ opts.push(args.local ? `Z?` : `Z`);
867
+ if (args.offset)
868
+ opts.push(`([+-]\\d{2}:?\\d{2})`);
869
+ regex = `${regex}(${opts.join("|")})`;
870
+ return new RegExp(`^${regex}$`);
871
+ }
872
+ function isValidIP(ip, version) {
873
+ if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
874
+ return true;
875
+ }
876
+ if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
877
+ return true;
878
+ }
879
+ return false;
880
+ }
881
+ function isValidJWT(jwt, alg) {
882
+ if (!jwtRegex.test(jwt))
883
+ return false;
884
+ try {
885
+ const [header] = jwt.split(".");
886
+ const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
887
+ const decoded = JSON.parse(atob(base64));
888
+ if (typeof decoded !== "object" || decoded === null)
889
+ return false;
890
+ if (!decoded.typ || !decoded.alg)
891
+ return false;
892
+ if (alg && decoded.alg !== alg)
893
+ return false;
894
+ return true;
895
+ } catch (_a) {
896
+ return false;
897
+ }
898
+ }
899
+ function isValidCidr(ip, version) {
900
+ if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
901
+ return true;
902
+ }
903
+ if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
904
+ return true;
905
+ }
906
+ return false;
907
+ }
908
+ class ZodString extends ZodType {
909
+ _parse(input) {
910
+ if (this._def.coerce) {
911
+ input.data = String(input.data);
912
+ }
913
+ const parsedType = this._getType(input);
914
+ if (parsedType !== ZodParsedType.string) {
915
+ const ctx2 = this._getOrReturnCtx(input);
916
+ addIssueToContext(ctx2, {
917
+ code: ZodIssueCode.invalid_type,
918
+ expected: ZodParsedType.string,
919
+ received: ctx2.parsedType
920
+ });
921
+ return INVALID;
922
+ }
923
+ const status = new ParseStatus();
924
+ let ctx = void 0;
925
+ for (const check of this._def.checks) {
926
+ if (check.kind === "min") {
927
+ if (input.data.length < check.value) {
928
+ ctx = this._getOrReturnCtx(input, ctx);
929
+ addIssueToContext(ctx, {
930
+ code: ZodIssueCode.too_small,
931
+ minimum: check.value,
932
+ type: "string",
933
+ inclusive: true,
934
+ exact: false,
935
+ message: check.message
936
+ });
937
+ status.dirty();
938
+ }
939
+ } else if (check.kind === "max") {
940
+ if (input.data.length > check.value) {
941
+ ctx = this._getOrReturnCtx(input, ctx);
942
+ addIssueToContext(ctx, {
943
+ code: ZodIssueCode.too_big,
944
+ maximum: check.value,
945
+ type: "string",
946
+ inclusive: true,
947
+ exact: false,
948
+ message: check.message
949
+ });
950
+ status.dirty();
951
+ }
952
+ } else if (check.kind === "length") {
953
+ const tooBig = input.data.length > check.value;
954
+ const tooSmall = input.data.length < check.value;
955
+ if (tooBig || tooSmall) {
956
+ ctx = this._getOrReturnCtx(input, ctx);
957
+ if (tooBig) {
958
+ addIssueToContext(ctx, {
959
+ code: ZodIssueCode.too_big,
960
+ maximum: check.value,
961
+ type: "string",
962
+ inclusive: true,
963
+ exact: true,
964
+ message: check.message
965
+ });
966
+ } else if (tooSmall) {
967
+ addIssueToContext(ctx, {
968
+ code: ZodIssueCode.too_small,
969
+ minimum: check.value,
970
+ type: "string",
971
+ inclusive: true,
972
+ exact: true,
973
+ message: check.message
974
+ });
975
+ }
976
+ status.dirty();
977
+ }
978
+ } else if (check.kind === "email") {
979
+ if (!emailRegex.test(input.data)) {
980
+ ctx = this._getOrReturnCtx(input, ctx);
981
+ addIssueToContext(ctx, {
982
+ validation: "email",
983
+ code: ZodIssueCode.invalid_string,
984
+ message: check.message
985
+ });
986
+ status.dirty();
987
+ }
988
+ } else if (check.kind === "emoji") {
989
+ if (!emojiRegex) {
990
+ emojiRegex = new RegExp(_emojiRegex, "u");
991
+ }
992
+ if (!emojiRegex.test(input.data)) {
993
+ ctx = this._getOrReturnCtx(input, ctx);
994
+ addIssueToContext(ctx, {
995
+ validation: "emoji",
996
+ code: ZodIssueCode.invalid_string,
997
+ message: check.message
998
+ });
999
+ status.dirty();
1000
+ }
1001
+ } else if (check.kind === "uuid") {
1002
+ if (!uuidRegex.test(input.data)) {
1003
+ ctx = this._getOrReturnCtx(input, ctx);
1004
+ addIssueToContext(ctx, {
1005
+ validation: "uuid",
1006
+ code: ZodIssueCode.invalid_string,
1007
+ message: check.message
1008
+ });
1009
+ status.dirty();
1010
+ }
1011
+ } else if (check.kind === "nanoid") {
1012
+ if (!nanoidRegex.test(input.data)) {
1013
+ ctx = this._getOrReturnCtx(input, ctx);
1014
+ addIssueToContext(ctx, {
1015
+ validation: "nanoid",
1016
+ code: ZodIssueCode.invalid_string,
1017
+ message: check.message
1018
+ });
1019
+ status.dirty();
1020
+ }
1021
+ } else if (check.kind === "cuid") {
1022
+ if (!cuidRegex.test(input.data)) {
1023
+ ctx = this._getOrReturnCtx(input, ctx);
1024
+ addIssueToContext(ctx, {
1025
+ validation: "cuid",
1026
+ code: ZodIssueCode.invalid_string,
1027
+ message: check.message
1028
+ });
1029
+ status.dirty();
1030
+ }
1031
+ } else if (check.kind === "cuid2") {
1032
+ if (!cuid2Regex.test(input.data)) {
1033
+ ctx = this._getOrReturnCtx(input, ctx);
1034
+ addIssueToContext(ctx, {
1035
+ validation: "cuid2",
1036
+ code: ZodIssueCode.invalid_string,
1037
+ message: check.message
1038
+ });
1039
+ status.dirty();
1040
+ }
1041
+ } else if (check.kind === "ulid") {
1042
+ if (!ulidRegex.test(input.data)) {
1043
+ ctx = this._getOrReturnCtx(input, ctx);
1044
+ addIssueToContext(ctx, {
1045
+ validation: "ulid",
1046
+ code: ZodIssueCode.invalid_string,
1047
+ message: check.message
1048
+ });
1049
+ status.dirty();
1050
+ }
1051
+ } else if (check.kind === "url") {
1052
+ try {
1053
+ new URL(input.data);
1054
+ } catch (_a) {
1055
+ ctx = this._getOrReturnCtx(input, ctx);
1056
+ addIssueToContext(ctx, {
1057
+ validation: "url",
1058
+ code: ZodIssueCode.invalid_string,
1059
+ message: check.message
1060
+ });
1061
+ status.dirty();
1062
+ }
1063
+ } else if (check.kind === "regex") {
1064
+ check.regex.lastIndex = 0;
1065
+ const testResult = check.regex.test(input.data);
1066
+ if (!testResult) {
1067
+ ctx = this._getOrReturnCtx(input, ctx);
1068
+ addIssueToContext(ctx, {
1069
+ validation: "regex",
1070
+ code: ZodIssueCode.invalid_string,
1071
+ message: check.message
1072
+ });
1073
+ status.dirty();
1074
+ }
1075
+ } else if (check.kind === "trim") {
1076
+ input.data = input.data.trim();
1077
+ } else if (check.kind === "includes") {
1078
+ if (!input.data.includes(check.value, check.position)) {
1079
+ ctx = this._getOrReturnCtx(input, ctx);
1080
+ addIssueToContext(ctx, {
1081
+ code: ZodIssueCode.invalid_string,
1082
+ validation: { includes: check.value, position: check.position },
1083
+ message: check.message
1084
+ });
1085
+ status.dirty();
1086
+ }
1087
+ } else if (check.kind === "toLowerCase") {
1088
+ input.data = input.data.toLowerCase();
1089
+ } else if (check.kind === "toUpperCase") {
1090
+ input.data = input.data.toUpperCase();
1091
+ } else if (check.kind === "startsWith") {
1092
+ if (!input.data.startsWith(check.value)) {
1093
+ ctx = this._getOrReturnCtx(input, ctx);
1094
+ addIssueToContext(ctx, {
1095
+ code: ZodIssueCode.invalid_string,
1096
+ validation: { startsWith: check.value },
1097
+ message: check.message
1098
+ });
1099
+ status.dirty();
1100
+ }
1101
+ } else if (check.kind === "endsWith") {
1102
+ if (!input.data.endsWith(check.value)) {
1103
+ ctx = this._getOrReturnCtx(input, ctx);
1104
+ addIssueToContext(ctx, {
1105
+ code: ZodIssueCode.invalid_string,
1106
+ validation: { endsWith: check.value },
1107
+ message: check.message
1108
+ });
1109
+ status.dirty();
1110
+ }
1111
+ } else if (check.kind === "datetime") {
1112
+ const regex = datetimeRegex(check);
1113
+ if (!regex.test(input.data)) {
1114
+ ctx = this._getOrReturnCtx(input, ctx);
1115
+ addIssueToContext(ctx, {
1116
+ code: ZodIssueCode.invalid_string,
1117
+ validation: "datetime",
1118
+ message: check.message
1119
+ });
1120
+ status.dirty();
1121
+ }
1122
+ } else if (check.kind === "date") {
1123
+ const regex = dateRegex;
1124
+ if (!regex.test(input.data)) {
1125
+ ctx = this._getOrReturnCtx(input, ctx);
1126
+ addIssueToContext(ctx, {
1127
+ code: ZodIssueCode.invalid_string,
1128
+ validation: "date",
1129
+ message: check.message
1130
+ });
1131
+ status.dirty();
1132
+ }
1133
+ } else if (check.kind === "time") {
1134
+ const regex = timeRegex(check);
1135
+ if (!regex.test(input.data)) {
1136
+ ctx = this._getOrReturnCtx(input, ctx);
1137
+ addIssueToContext(ctx, {
1138
+ code: ZodIssueCode.invalid_string,
1139
+ validation: "time",
1140
+ message: check.message
1141
+ });
1142
+ status.dirty();
1143
+ }
1144
+ } else if (check.kind === "duration") {
1145
+ if (!durationRegex.test(input.data)) {
1146
+ ctx = this._getOrReturnCtx(input, ctx);
1147
+ addIssueToContext(ctx, {
1148
+ validation: "duration",
1149
+ code: ZodIssueCode.invalid_string,
1150
+ message: check.message
1151
+ });
1152
+ status.dirty();
1153
+ }
1154
+ } else if (check.kind === "ip") {
1155
+ if (!isValidIP(input.data, check.version)) {
1156
+ ctx = this._getOrReturnCtx(input, ctx);
1157
+ addIssueToContext(ctx, {
1158
+ validation: "ip",
1159
+ code: ZodIssueCode.invalid_string,
1160
+ message: check.message
1161
+ });
1162
+ status.dirty();
1163
+ }
1164
+ } else if (check.kind === "jwt") {
1165
+ if (!isValidJWT(input.data, check.alg)) {
1166
+ ctx = this._getOrReturnCtx(input, ctx);
1167
+ addIssueToContext(ctx, {
1168
+ validation: "jwt",
1169
+ code: ZodIssueCode.invalid_string,
1170
+ message: check.message
1171
+ });
1172
+ status.dirty();
1173
+ }
1174
+ } else if (check.kind === "cidr") {
1175
+ if (!isValidCidr(input.data, check.version)) {
1176
+ ctx = this._getOrReturnCtx(input, ctx);
1177
+ addIssueToContext(ctx, {
1178
+ validation: "cidr",
1179
+ code: ZodIssueCode.invalid_string,
1180
+ message: check.message
1181
+ });
1182
+ status.dirty();
1183
+ }
1184
+ } else if (check.kind === "base64") {
1185
+ if (!base64Regex.test(input.data)) {
1186
+ ctx = this._getOrReturnCtx(input, ctx);
1187
+ addIssueToContext(ctx, {
1188
+ validation: "base64",
1189
+ code: ZodIssueCode.invalid_string,
1190
+ message: check.message
1191
+ });
1192
+ status.dirty();
1193
+ }
1194
+ } else if (check.kind === "base64url") {
1195
+ if (!base64urlRegex.test(input.data)) {
1196
+ ctx = this._getOrReturnCtx(input, ctx);
1197
+ addIssueToContext(ctx, {
1198
+ validation: "base64url",
1199
+ code: ZodIssueCode.invalid_string,
1200
+ message: check.message
1201
+ });
1202
+ status.dirty();
1203
+ }
1204
+ } else {
1205
+ util.assertNever(check);
1206
+ }
1207
+ }
1208
+ return { status: status.value, value: input.data };
1209
+ }
1210
+ _regex(regex, validation, message) {
1211
+ return this.refinement((data) => regex.test(data), {
1212
+ validation,
1213
+ code: ZodIssueCode.invalid_string,
1214
+ ...errorUtil.errToObj(message)
1215
+ });
1216
+ }
1217
+ _addCheck(check) {
1218
+ return new ZodString({
1219
+ ...this._def,
1220
+ checks: [...this._def.checks, check]
1221
+ });
1222
+ }
1223
+ email(message) {
1224
+ return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) });
1225
+ }
1226
+ url(message) {
1227
+ return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) });
1228
+ }
1229
+ emoji(message) {
1230
+ return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) });
1231
+ }
1232
+ uuid(message) {
1233
+ return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) });
1234
+ }
1235
+ nanoid(message) {
1236
+ return this._addCheck({ kind: "nanoid", ...errorUtil.errToObj(message) });
1237
+ }
1238
+ cuid(message) {
1239
+ return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) });
1240
+ }
1241
+ cuid2(message) {
1242
+ return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) });
1243
+ }
1244
+ ulid(message) {
1245
+ return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) });
1246
+ }
1247
+ base64(message) {
1248
+ return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
1249
+ }
1250
+ base64url(message) {
1251
+ return this._addCheck({
1252
+ kind: "base64url",
1253
+ ...errorUtil.errToObj(message)
1254
+ });
1255
+ }
1256
+ jwt(options) {
1257
+ return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
1258
+ }
1259
+ ip(options) {
1260
+ return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
1261
+ }
1262
+ cidr(options) {
1263
+ return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
1264
+ }
1265
+ datetime(options) {
1266
+ var _a, _b;
1267
+ if (typeof options === "string") {
1268
+ return this._addCheck({
1269
+ kind: "datetime",
1270
+ precision: null,
1271
+ offset: false,
1272
+ local: false,
1273
+ message: options
1274
+ });
1275
+ }
1276
+ return this._addCheck({
1277
+ kind: "datetime",
1278
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1279
+ offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
1280
+ local: (_b = options === null || options === void 0 ? void 0 : options.local) !== null && _b !== void 0 ? _b : false,
1281
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
1282
+ });
1283
+ }
1284
+ date(message) {
1285
+ return this._addCheck({ kind: "date", message });
1286
+ }
1287
+ time(options) {
1288
+ if (typeof options === "string") {
1289
+ return this._addCheck({
1290
+ kind: "time",
1291
+ precision: null,
1292
+ message: options
1293
+ });
1294
+ }
1295
+ return this._addCheck({
1296
+ kind: "time",
1297
+ precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
1298
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
1299
+ });
1300
+ }
1301
+ duration(message) {
1302
+ return this._addCheck({ kind: "duration", ...errorUtil.errToObj(message) });
1303
+ }
1304
+ regex(regex, message) {
1305
+ return this._addCheck({
1306
+ kind: "regex",
1307
+ regex,
1308
+ ...errorUtil.errToObj(message)
1309
+ });
1310
+ }
1311
+ includes(value, options) {
1312
+ return this._addCheck({
1313
+ kind: "includes",
1314
+ value,
1315
+ position: options === null || options === void 0 ? void 0 : options.position,
1316
+ ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
1317
+ });
1318
+ }
1319
+ startsWith(value, message) {
1320
+ return this._addCheck({
1321
+ kind: "startsWith",
1322
+ value,
1323
+ ...errorUtil.errToObj(message)
1324
+ });
1325
+ }
1326
+ endsWith(value, message) {
1327
+ return this._addCheck({
1328
+ kind: "endsWith",
1329
+ value,
1330
+ ...errorUtil.errToObj(message)
1331
+ });
1332
+ }
1333
+ min(minLength, message) {
1334
+ return this._addCheck({
1335
+ kind: "min",
1336
+ value: minLength,
1337
+ ...errorUtil.errToObj(message)
1338
+ });
1339
+ }
1340
+ max(maxLength, message) {
1341
+ return this._addCheck({
1342
+ kind: "max",
1343
+ value: maxLength,
1344
+ ...errorUtil.errToObj(message)
1345
+ });
1346
+ }
1347
+ length(len, message) {
1348
+ return this._addCheck({
1349
+ kind: "length",
1350
+ value: len,
1351
+ ...errorUtil.errToObj(message)
1352
+ });
1353
+ }
1354
+ /**
1355
+ * Equivalent to `.min(1)`
1356
+ */
1357
+ nonempty(message) {
1358
+ return this.min(1, errorUtil.errToObj(message));
1359
+ }
1360
+ trim() {
1361
+ return new ZodString({
1362
+ ...this._def,
1363
+ checks: [...this._def.checks, { kind: "trim" }]
1364
+ });
1365
+ }
1366
+ toLowerCase() {
1367
+ return new ZodString({
1368
+ ...this._def,
1369
+ checks: [...this._def.checks, { kind: "toLowerCase" }]
1370
+ });
1371
+ }
1372
+ toUpperCase() {
1373
+ return new ZodString({
1374
+ ...this._def,
1375
+ checks: [...this._def.checks, { kind: "toUpperCase" }]
1376
+ });
1377
+ }
1378
+ get isDatetime() {
1379
+ return !!this._def.checks.find((ch) => ch.kind === "datetime");
1380
+ }
1381
+ get isDate() {
1382
+ return !!this._def.checks.find((ch) => ch.kind === "date");
1383
+ }
1384
+ get isTime() {
1385
+ return !!this._def.checks.find((ch) => ch.kind === "time");
1386
+ }
1387
+ get isDuration() {
1388
+ return !!this._def.checks.find((ch) => ch.kind === "duration");
1389
+ }
1390
+ get isEmail() {
1391
+ return !!this._def.checks.find((ch) => ch.kind === "email");
1392
+ }
1393
+ get isURL() {
1394
+ return !!this._def.checks.find((ch) => ch.kind === "url");
1395
+ }
1396
+ get isEmoji() {
1397
+ return !!this._def.checks.find((ch) => ch.kind === "emoji");
1398
+ }
1399
+ get isUUID() {
1400
+ return !!this._def.checks.find((ch) => ch.kind === "uuid");
1401
+ }
1402
+ get isNANOID() {
1403
+ return !!this._def.checks.find((ch) => ch.kind === "nanoid");
1404
+ }
1405
+ get isCUID() {
1406
+ return !!this._def.checks.find((ch) => ch.kind === "cuid");
1407
+ }
1408
+ get isCUID2() {
1409
+ return !!this._def.checks.find((ch) => ch.kind === "cuid2");
1410
+ }
1411
+ get isULID() {
1412
+ return !!this._def.checks.find((ch) => ch.kind === "ulid");
1413
+ }
1414
+ get isIP() {
1415
+ return !!this._def.checks.find((ch) => ch.kind === "ip");
1416
+ }
1417
+ get isCIDR() {
1418
+ return !!this._def.checks.find((ch) => ch.kind === "cidr");
1419
+ }
1420
+ get isBase64() {
1421
+ return !!this._def.checks.find((ch) => ch.kind === "base64");
1422
+ }
1423
+ get isBase64url() {
1424
+ return !!this._def.checks.find((ch) => ch.kind === "base64url");
1425
+ }
1426
+ get minLength() {
1427
+ let min = null;
1428
+ for (const ch of this._def.checks) {
1429
+ if (ch.kind === "min") {
1430
+ if (min === null || ch.value > min)
1431
+ min = ch.value;
1432
+ }
1433
+ }
1434
+ return min;
1435
+ }
1436
+ get maxLength() {
1437
+ let max = null;
1438
+ for (const ch of this._def.checks) {
1439
+ if (ch.kind === "max") {
1440
+ if (max === null || ch.value < max)
1441
+ max = ch.value;
1442
+ }
1443
+ }
1444
+ return max;
1445
+ }
1446
+ }
1447
+ ZodString.create = (params) => {
1448
+ var _a;
1449
+ return new ZodString({
1450
+ checks: [],
1451
+ typeName: ZodFirstPartyTypeKind.ZodString,
1452
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1453
+ ...processCreateParams(params)
1454
+ });
1455
+ };
1456
+ function floatSafeRemainder(val, step) {
1457
+ const valDecCount = (val.toString().split(".")[1] || "").length;
1458
+ const stepDecCount = (step.toString().split(".")[1] || "").length;
1459
+ const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
1460
+ const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
1461
+ const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
1462
+ return valInt % stepInt / Math.pow(10, decCount);
1463
+ }
1464
+ class ZodNumber extends ZodType {
1465
+ constructor() {
1466
+ super(...arguments);
1467
+ this.min = this.gte;
1468
+ this.max = this.lte;
1469
+ this.step = this.multipleOf;
1470
+ }
1471
+ _parse(input) {
1472
+ if (this._def.coerce) {
1473
+ input.data = Number(input.data);
1474
+ }
1475
+ const parsedType = this._getType(input);
1476
+ if (parsedType !== ZodParsedType.number) {
1477
+ const ctx2 = this._getOrReturnCtx(input);
1478
+ addIssueToContext(ctx2, {
1479
+ code: ZodIssueCode.invalid_type,
1480
+ expected: ZodParsedType.number,
1481
+ received: ctx2.parsedType
1482
+ });
1483
+ return INVALID;
1484
+ }
1485
+ let ctx = void 0;
1486
+ const status = new ParseStatus();
1487
+ for (const check of this._def.checks) {
1488
+ if (check.kind === "int") {
1489
+ if (!util.isInteger(input.data)) {
1490
+ ctx = this._getOrReturnCtx(input, ctx);
1491
+ addIssueToContext(ctx, {
1492
+ code: ZodIssueCode.invalid_type,
1493
+ expected: "integer",
1494
+ received: "float",
1495
+ message: check.message
1496
+ });
1497
+ status.dirty();
1498
+ }
1499
+ } else if (check.kind === "min") {
1500
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1501
+ if (tooSmall) {
1502
+ ctx = this._getOrReturnCtx(input, ctx);
1503
+ addIssueToContext(ctx, {
1504
+ code: ZodIssueCode.too_small,
1505
+ minimum: check.value,
1506
+ type: "number",
1507
+ inclusive: check.inclusive,
1508
+ exact: false,
1509
+ message: check.message
1510
+ });
1511
+ status.dirty();
1512
+ }
1513
+ } else if (check.kind === "max") {
1514
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1515
+ if (tooBig) {
1516
+ ctx = this._getOrReturnCtx(input, ctx);
1517
+ addIssueToContext(ctx, {
1518
+ code: ZodIssueCode.too_big,
1519
+ maximum: check.value,
1520
+ type: "number",
1521
+ inclusive: check.inclusive,
1522
+ exact: false,
1523
+ message: check.message
1524
+ });
1525
+ status.dirty();
1526
+ }
1527
+ } else if (check.kind === "multipleOf") {
1528
+ if (floatSafeRemainder(input.data, check.value) !== 0) {
1529
+ ctx = this._getOrReturnCtx(input, ctx);
1530
+ addIssueToContext(ctx, {
1531
+ code: ZodIssueCode.not_multiple_of,
1532
+ multipleOf: check.value,
1533
+ message: check.message
1534
+ });
1535
+ status.dirty();
1536
+ }
1537
+ } else if (check.kind === "finite") {
1538
+ if (!Number.isFinite(input.data)) {
1539
+ ctx = this._getOrReturnCtx(input, ctx);
1540
+ addIssueToContext(ctx, {
1541
+ code: ZodIssueCode.not_finite,
1542
+ message: check.message
1543
+ });
1544
+ status.dirty();
1545
+ }
1546
+ } else {
1547
+ util.assertNever(check);
1548
+ }
1549
+ }
1550
+ return { status: status.value, value: input.data };
1551
+ }
1552
+ gte(value, message) {
1553
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1554
+ }
1555
+ gt(value, message) {
1556
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1557
+ }
1558
+ lte(value, message) {
1559
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1560
+ }
1561
+ lt(value, message) {
1562
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1563
+ }
1564
+ setLimit(kind, value, inclusive, message) {
1565
+ return new ZodNumber({
1566
+ ...this._def,
1567
+ checks: [
1568
+ ...this._def.checks,
1569
+ {
1570
+ kind,
1571
+ value,
1572
+ inclusive,
1573
+ message: errorUtil.toString(message)
1574
+ }
1575
+ ]
1576
+ });
1577
+ }
1578
+ _addCheck(check) {
1579
+ return new ZodNumber({
1580
+ ...this._def,
1581
+ checks: [...this._def.checks, check]
1582
+ });
1583
+ }
1584
+ int(message) {
1585
+ return this._addCheck({
1586
+ kind: "int",
1587
+ message: errorUtil.toString(message)
1588
+ });
1589
+ }
1590
+ positive(message) {
1591
+ return this._addCheck({
1592
+ kind: "min",
1593
+ value: 0,
1594
+ inclusive: false,
1595
+ message: errorUtil.toString(message)
1596
+ });
1597
+ }
1598
+ negative(message) {
1599
+ return this._addCheck({
1600
+ kind: "max",
1601
+ value: 0,
1602
+ inclusive: false,
1603
+ message: errorUtil.toString(message)
1604
+ });
1605
+ }
1606
+ nonpositive(message) {
1607
+ return this._addCheck({
1608
+ kind: "max",
1609
+ value: 0,
1610
+ inclusive: true,
1611
+ message: errorUtil.toString(message)
1612
+ });
1613
+ }
1614
+ nonnegative(message) {
1615
+ return this._addCheck({
1616
+ kind: "min",
1617
+ value: 0,
1618
+ inclusive: true,
1619
+ message: errorUtil.toString(message)
1620
+ });
1621
+ }
1622
+ multipleOf(value, message) {
1623
+ return this._addCheck({
1624
+ kind: "multipleOf",
1625
+ value,
1626
+ message: errorUtil.toString(message)
1627
+ });
1628
+ }
1629
+ finite(message) {
1630
+ return this._addCheck({
1631
+ kind: "finite",
1632
+ message: errorUtil.toString(message)
1633
+ });
1634
+ }
1635
+ safe(message) {
1636
+ return this._addCheck({
1637
+ kind: "min",
1638
+ inclusive: true,
1639
+ value: Number.MIN_SAFE_INTEGER,
1640
+ message: errorUtil.toString(message)
1641
+ })._addCheck({
1642
+ kind: "max",
1643
+ inclusive: true,
1644
+ value: Number.MAX_SAFE_INTEGER,
1645
+ message: errorUtil.toString(message)
1646
+ });
1647
+ }
1648
+ get minValue() {
1649
+ let min = null;
1650
+ for (const ch of this._def.checks) {
1651
+ if (ch.kind === "min") {
1652
+ if (min === null || ch.value > min)
1653
+ min = ch.value;
1654
+ }
1655
+ }
1656
+ return min;
1657
+ }
1658
+ get maxValue() {
1659
+ let max = null;
1660
+ for (const ch of this._def.checks) {
1661
+ if (ch.kind === "max") {
1662
+ if (max === null || ch.value < max)
1663
+ max = ch.value;
1664
+ }
1665
+ }
1666
+ return max;
1667
+ }
1668
+ get isInt() {
1669
+ return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
1670
+ }
1671
+ get isFinite() {
1672
+ let max = null, min = null;
1673
+ for (const ch of this._def.checks) {
1674
+ if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
1675
+ return true;
1676
+ } else if (ch.kind === "min") {
1677
+ if (min === null || ch.value > min)
1678
+ min = ch.value;
1679
+ } else if (ch.kind === "max") {
1680
+ if (max === null || ch.value < max)
1681
+ max = ch.value;
1682
+ }
1683
+ }
1684
+ return Number.isFinite(min) && Number.isFinite(max);
1685
+ }
1686
+ }
1687
+ ZodNumber.create = (params) => {
1688
+ return new ZodNumber({
1689
+ checks: [],
1690
+ typeName: ZodFirstPartyTypeKind.ZodNumber,
1691
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1692
+ ...processCreateParams(params)
1693
+ });
1694
+ };
1695
+ class ZodBigInt extends ZodType {
1696
+ constructor() {
1697
+ super(...arguments);
1698
+ this.min = this.gte;
1699
+ this.max = this.lte;
1700
+ }
1701
+ _parse(input) {
1702
+ if (this._def.coerce) {
1703
+ try {
1704
+ input.data = BigInt(input.data);
1705
+ } catch (_a) {
1706
+ return this._getInvalidInput(input);
1707
+ }
1708
+ }
1709
+ const parsedType = this._getType(input);
1710
+ if (parsedType !== ZodParsedType.bigint) {
1711
+ return this._getInvalidInput(input);
1712
+ }
1713
+ let ctx = void 0;
1714
+ const status = new ParseStatus();
1715
+ for (const check of this._def.checks) {
1716
+ if (check.kind === "min") {
1717
+ const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
1718
+ if (tooSmall) {
1719
+ ctx = this._getOrReturnCtx(input, ctx);
1720
+ addIssueToContext(ctx, {
1721
+ code: ZodIssueCode.too_small,
1722
+ type: "bigint",
1723
+ minimum: check.value,
1724
+ inclusive: check.inclusive,
1725
+ message: check.message
1726
+ });
1727
+ status.dirty();
1728
+ }
1729
+ } else if (check.kind === "max") {
1730
+ const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
1731
+ if (tooBig) {
1732
+ ctx = this._getOrReturnCtx(input, ctx);
1733
+ addIssueToContext(ctx, {
1734
+ code: ZodIssueCode.too_big,
1735
+ type: "bigint",
1736
+ maximum: check.value,
1737
+ inclusive: check.inclusive,
1738
+ message: check.message
1739
+ });
1740
+ status.dirty();
1741
+ }
1742
+ } else if (check.kind === "multipleOf") {
1743
+ if (input.data % check.value !== BigInt(0)) {
1744
+ ctx = this._getOrReturnCtx(input, ctx);
1745
+ addIssueToContext(ctx, {
1746
+ code: ZodIssueCode.not_multiple_of,
1747
+ multipleOf: check.value,
1748
+ message: check.message
1749
+ });
1750
+ status.dirty();
1751
+ }
1752
+ } else {
1753
+ util.assertNever(check);
1754
+ }
1755
+ }
1756
+ return { status: status.value, value: input.data };
1757
+ }
1758
+ _getInvalidInput(input) {
1759
+ const ctx = this._getOrReturnCtx(input);
1760
+ addIssueToContext(ctx, {
1761
+ code: ZodIssueCode.invalid_type,
1762
+ expected: ZodParsedType.bigint,
1763
+ received: ctx.parsedType
1764
+ });
1765
+ return INVALID;
1766
+ }
1767
+ gte(value, message) {
1768
+ return this.setLimit("min", value, true, errorUtil.toString(message));
1769
+ }
1770
+ gt(value, message) {
1771
+ return this.setLimit("min", value, false, errorUtil.toString(message));
1772
+ }
1773
+ lte(value, message) {
1774
+ return this.setLimit("max", value, true, errorUtil.toString(message));
1775
+ }
1776
+ lt(value, message) {
1777
+ return this.setLimit("max", value, false, errorUtil.toString(message));
1778
+ }
1779
+ setLimit(kind, value, inclusive, message) {
1780
+ return new ZodBigInt({
1781
+ ...this._def,
1782
+ checks: [
1783
+ ...this._def.checks,
1784
+ {
1785
+ kind,
1786
+ value,
1787
+ inclusive,
1788
+ message: errorUtil.toString(message)
1789
+ }
1790
+ ]
1791
+ });
1792
+ }
1793
+ _addCheck(check) {
1794
+ return new ZodBigInt({
1795
+ ...this._def,
1796
+ checks: [...this._def.checks, check]
1797
+ });
1798
+ }
1799
+ positive(message) {
1800
+ return this._addCheck({
1801
+ kind: "min",
1802
+ value: BigInt(0),
1803
+ inclusive: false,
1804
+ message: errorUtil.toString(message)
1805
+ });
1806
+ }
1807
+ negative(message) {
1808
+ return this._addCheck({
1809
+ kind: "max",
1810
+ value: BigInt(0),
1811
+ inclusive: false,
1812
+ message: errorUtil.toString(message)
1813
+ });
1814
+ }
1815
+ nonpositive(message) {
1816
+ return this._addCheck({
1817
+ kind: "max",
1818
+ value: BigInt(0),
1819
+ inclusive: true,
1820
+ message: errorUtil.toString(message)
1821
+ });
1822
+ }
1823
+ nonnegative(message) {
1824
+ return this._addCheck({
1825
+ kind: "min",
1826
+ value: BigInt(0),
1827
+ inclusive: true,
1828
+ message: errorUtil.toString(message)
1829
+ });
1830
+ }
1831
+ multipleOf(value, message) {
1832
+ return this._addCheck({
1833
+ kind: "multipleOf",
1834
+ value,
1835
+ message: errorUtil.toString(message)
1836
+ });
1837
+ }
1838
+ get minValue() {
1839
+ let min = null;
1840
+ for (const ch of this._def.checks) {
1841
+ if (ch.kind === "min") {
1842
+ if (min === null || ch.value > min)
1843
+ min = ch.value;
1844
+ }
1845
+ }
1846
+ return min;
1847
+ }
1848
+ get maxValue() {
1849
+ let max = null;
1850
+ for (const ch of this._def.checks) {
1851
+ if (ch.kind === "max") {
1852
+ if (max === null || ch.value < max)
1853
+ max = ch.value;
1854
+ }
1855
+ }
1856
+ return max;
1857
+ }
1858
+ }
1859
+ ZodBigInt.create = (params) => {
1860
+ var _a;
1861
+ return new ZodBigInt({
1862
+ checks: [],
1863
+ typeName: ZodFirstPartyTypeKind.ZodBigInt,
1864
+ coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
1865
+ ...processCreateParams(params)
1866
+ });
1867
+ };
1868
+ class ZodBoolean extends ZodType {
1869
+ _parse(input) {
1870
+ if (this._def.coerce) {
1871
+ input.data = Boolean(input.data);
1872
+ }
1873
+ const parsedType = this._getType(input);
1874
+ if (parsedType !== ZodParsedType.boolean) {
1875
+ const ctx = this._getOrReturnCtx(input);
1876
+ addIssueToContext(ctx, {
1877
+ code: ZodIssueCode.invalid_type,
1878
+ expected: ZodParsedType.boolean,
1879
+ received: ctx.parsedType
1880
+ });
1881
+ return INVALID;
1882
+ }
1883
+ return OK(input.data);
1884
+ }
1885
+ }
1886
+ ZodBoolean.create = (params) => {
1887
+ return new ZodBoolean({
1888
+ typeName: ZodFirstPartyTypeKind.ZodBoolean,
1889
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1890
+ ...processCreateParams(params)
1891
+ });
1892
+ };
1893
+ class ZodDate extends ZodType {
1894
+ _parse(input) {
1895
+ if (this._def.coerce) {
1896
+ input.data = new Date(input.data);
1897
+ }
1898
+ const parsedType = this._getType(input);
1899
+ if (parsedType !== ZodParsedType.date) {
1900
+ const ctx2 = this._getOrReturnCtx(input);
1901
+ addIssueToContext(ctx2, {
1902
+ code: ZodIssueCode.invalid_type,
1903
+ expected: ZodParsedType.date,
1904
+ received: ctx2.parsedType
1905
+ });
1906
+ return INVALID;
1907
+ }
1908
+ if (isNaN(input.data.getTime())) {
1909
+ const ctx2 = this._getOrReturnCtx(input);
1910
+ addIssueToContext(ctx2, {
1911
+ code: ZodIssueCode.invalid_date
1912
+ });
1913
+ return INVALID;
1914
+ }
1915
+ const status = new ParseStatus();
1916
+ let ctx = void 0;
1917
+ for (const check of this._def.checks) {
1918
+ if (check.kind === "min") {
1919
+ if (input.data.getTime() < check.value) {
1920
+ ctx = this._getOrReturnCtx(input, ctx);
1921
+ addIssueToContext(ctx, {
1922
+ code: ZodIssueCode.too_small,
1923
+ message: check.message,
1924
+ inclusive: true,
1925
+ exact: false,
1926
+ minimum: check.value,
1927
+ type: "date"
1928
+ });
1929
+ status.dirty();
1930
+ }
1931
+ } else if (check.kind === "max") {
1932
+ if (input.data.getTime() > check.value) {
1933
+ ctx = this._getOrReturnCtx(input, ctx);
1934
+ addIssueToContext(ctx, {
1935
+ code: ZodIssueCode.too_big,
1936
+ message: check.message,
1937
+ inclusive: true,
1938
+ exact: false,
1939
+ maximum: check.value,
1940
+ type: "date"
1941
+ });
1942
+ status.dirty();
1943
+ }
1944
+ } else {
1945
+ util.assertNever(check);
1946
+ }
1947
+ }
1948
+ return {
1949
+ status: status.value,
1950
+ value: new Date(input.data.getTime())
1951
+ };
1952
+ }
1953
+ _addCheck(check) {
1954
+ return new ZodDate({
1955
+ ...this._def,
1956
+ checks: [...this._def.checks, check]
1957
+ });
1958
+ }
1959
+ min(minDate, message) {
1960
+ return this._addCheck({
1961
+ kind: "min",
1962
+ value: minDate.getTime(),
1963
+ message: errorUtil.toString(message)
1964
+ });
1965
+ }
1966
+ max(maxDate, message) {
1967
+ return this._addCheck({
1968
+ kind: "max",
1969
+ value: maxDate.getTime(),
1970
+ message: errorUtil.toString(message)
1971
+ });
1972
+ }
1973
+ get minDate() {
1974
+ let min = null;
1975
+ for (const ch of this._def.checks) {
1976
+ if (ch.kind === "min") {
1977
+ if (min === null || ch.value > min)
1978
+ min = ch.value;
1979
+ }
1980
+ }
1981
+ return min != null ? new Date(min) : null;
1982
+ }
1983
+ get maxDate() {
1984
+ let max = null;
1985
+ for (const ch of this._def.checks) {
1986
+ if (ch.kind === "max") {
1987
+ if (max === null || ch.value < max)
1988
+ max = ch.value;
1989
+ }
1990
+ }
1991
+ return max != null ? new Date(max) : null;
1992
+ }
1993
+ }
1994
+ ZodDate.create = (params) => {
1995
+ return new ZodDate({
1996
+ checks: [],
1997
+ coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
1998
+ typeName: ZodFirstPartyTypeKind.ZodDate,
1999
+ ...processCreateParams(params)
2000
+ });
2001
+ };
2002
+ class ZodSymbol extends ZodType {
2003
+ _parse(input) {
2004
+ const parsedType = this._getType(input);
2005
+ if (parsedType !== ZodParsedType.symbol) {
2006
+ const ctx = this._getOrReturnCtx(input);
2007
+ addIssueToContext(ctx, {
2008
+ code: ZodIssueCode.invalid_type,
2009
+ expected: ZodParsedType.symbol,
2010
+ received: ctx.parsedType
2011
+ });
2012
+ return INVALID;
2013
+ }
2014
+ return OK(input.data);
2015
+ }
2016
+ }
2017
+ ZodSymbol.create = (params) => {
2018
+ return new ZodSymbol({
2019
+ typeName: ZodFirstPartyTypeKind.ZodSymbol,
2020
+ ...processCreateParams(params)
2021
+ });
2022
+ };
2023
+ class ZodUndefined extends ZodType {
2024
+ _parse(input) {
2025
+ const parsedType = this._getType(input);
2026
+ if (parsedType !== ZodParsedType.undefined) {
2027
+ const ctx = this._getOrReturnCtx(input);
2028
+ addIssueToContext(ctx, {
2029
+ code: ZodIssueCode.invalid_type,
2030
+ expected: ZodParsedType.undefined,
2031
+ received: ctx.parsedType
2032
+ });
2033
+ return INVALID;
2034
+ }
2035
+ return OK(input.data);
2036
+ }
2037
+ }
2038
+ ZodUndefined.create = (params) => {
2039
+ return new ZodUndefined({
2040
+ typeName: ZodFirstPartyTypeKind.ZodUndefined,
2041
+ ...processCreateParams(params)
2042
+ });
2043
+ };
2044
+ class ZodNull extends ZodType {
2045
+ _parse(input) {
2046
+ const parsedType = this._getType(input);
2047
+ if (parsedType !== ZodParsedType.null) {
2048
+ const ctx = this._getOrReturnCtx(input);
2049
+ addIssueToContext(ctx, {
2050
+ code: ZodIssueCode.invalid_type,
2051
+ expected: ZodParsedType.null,
2052
+ received: ctx.parsedType
2053
+ });
2054
+ return INVALID;
2055
+ }
2056
+ return OK(input.data);
2057
+ }
2058
+ }
2059
+ ZodNull.create = (params) => {
2060
+ return new ZodNull({
2061
+ typeName: ZodFirstPartyTypeKind.ZodNull,
2062
+ ...processCreateParams(params)
2063
+ });
2064
+ };
2065
+ class ZodAny extends ZodType {
2066
+ constructor() {
2067
+ super(...arguments);
2068
+ this._any = true;
2069
+ }
2070
+ _parse(input) {
2071
+ return OK(input.data);
2072
+ }
2073
+ }
2074
+ ZodAny.create = (params) => {
2075
+ return new ZodAny({
2076
+ typeName: ZodFirstPartyTypeKind.ZodAny,
2077
+ ...processCreateParams(params)
2078
+ });
2079
+ };
2080
+ class ZodUnknown extends ZodType {
2081
+ constructor() {
2082
+ super(...arguments);
2083
+ this._unknown = true;
2084
+ }
2085
+ _parse(input) {
2086
+ return OK(input.data);
2087
+ }
2088
+ }
2089
+ ZodUnknown.create = (params) => {
2090
+ return new ZodUnknown({
2091
+ typeName: ZodFirstPartyTypeKind.ZodUnknown,
2092
+ ...processCreateParams(params)
2093
+ });
2094
+ };
2095
+ class ZodNever extends ZodType {
2096
+ _parse(input) {
2097
+ const ctx = this._getOrReturnCtx(input);
2098
+ addIssueToContext(ctx, {
2099
+ code: ZodIssueCode.invalid_type,
2100
+ expected: ZodParsedType.never,
2101
+ received: ctx.parsedType
2102
+ });
2103
+ return INVALID;
2104
+ }
2105
+ }
2106
+ ZodNever.create = (params) => {
2107
+ return new ZodNever({
2108
+ typeName: ZodFirstPartyTypeKind.ZodNever,
2109
+ ...processCreateParams(params)
2110
+ });
2111
+ };
2112
+ class ZodVoid extends ZodType {
2113
+ _parse(input) {
2114
+ const parsedType = this._getType(input);
2115
+ if (parsedType !== ZodParsedType.undefined) {
2116
+ const ctx = this._getOrReturnCtx(input);
2117
+ addIssueToContext(ctx, {
2118
+ code: ZodIssueCode.invalid_type,
2119
+ expected: ZodParsedType.void,
2120
+ received: ctx.parsedType
2121
+ });
2122
+ return INVALID;
2123
+ }
2124
+ return OK(input.data);
2125
+ }
2126
+ }
2127
+ ZodVoid.create = (params) => {
2128
+ return new ZodVoid({
2129
+ typeName: ZodFirstPartyTypeKind.ZodVoid,
2130
+ ...processCreateParams(params)
2131
+ });
2132
+ };
2133
+ class ZodArray extends ZodType {
2134
+ _parse(input) {
2135
+ const { ctx, status } = this._processInputParams(input);
2136
+ const def = this._def;
2137
+ if (ctx.parsedType !== ZodParsedType.array) {
2138
+ addIssueToContext(ctx, {
2139
+ code: ZodIssueCode.invalid_type,
2140
+ expected: ZodParsedType.array,
2141
+ received: ctx.parsedType
2142
+ });
2143
+ return INVALID;
2144
+ }
2145
+ if (def.exactLength !== null) {
2146
+ const tooBig = ctx.data.length > def.exactLength.value;
2147
+ const tooSmall = ctx.data.length < def.exactLength.value;
2148
+ if (tooBig || tooSmall) {
2149
+ addIssueToContext(ctx, {
2150
+ code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
2151
+ minimum: tooSmall ? def.exactLength.value : void 0,
2152
+ maximum: tooBig ? def.exactLength.value : void 0,
2153
+ type: "array",
2154
+ inclusive: true,
2155
+ exact: true,
2156
+ message: def.exactLength.message
2157
+ });
2158
+ status.dirty();
2159
+ }
2160
+ }
2161
+ if (def.minLength !== null) {
2162
+ if (ctx.data.length < def.minLength.value) {
2163
+ addIssueToContext(ctx, {
2164
+ code: ZodIssueCode.too_small,
2165
+ minimum: def.minLength.value,
2166
+ type: "array",
2167
+ inclusive: true,
2168
+ exact: false,
2169
+ message: def.minLength.message
2170
+ });
2171
+ status.dirty();
2172
+ }
2173
+ }
2174
+ if (def.maxLength !== null) {
2175
+ if (ctx.data.length > def.maxLength.value) {
2176
+ addIssueToContext(ctx, {
2177
+ code: ZodIssueCode.too_big,
2178
+ maximum: def.maxLength.value,
2179
+ type: "array",
2180
+ inclusive: true,
2181
+ exact: false,
2182
+ message: def.maxLength.message
2183
+ });
2184
+ status.dirty();
2185
+ }
2186
+ }
2187
+ if (ctx.common.async) {
2188
+ return Promise.all([...ctx.data].map((item, i2) => {
2189
+ return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i2));
2190
+ })).then((result2) => {
2191
+ return ParseStatus.mergeArray(status, result2);
2192
+ });
2193
+ }
2194
+ const result = [...ctx.data].map((item, i2) => {
2195
+ return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i2));
2196
+ });
2197
+ return ParseStatus.mergeArray(status, result);
2198
+ }
2199
+ get element() {
2200
+ return this._def.type;
2201
+ }
2202
+ min(minLength, message) {
2203
+ return new ZodArray({
2204
+ ...this._def,
2205
+ minLength: { value: minLength, message: errorUtil.toString(message) }
2206
+ });
2207
+ }
2208
+ max(maxLength, message) {
2209
+ return new ZodArray({
2210
+ ...this._def,
2211
+ maxLength: { value: maxLength, message: errorUtil.toString(message) }
2212
+ });
2213
+ }
2214
+ length(len, message) {
2215
+ return new ZodArray({
2216
+ ...this._def,
2217
+ exactLength: { value: len, message: errorUtil.toString(message) }
2218
+ });
2219
+ }
2220
+ nonempty(message) {
2221
+ return this.min(1, message);
2222
+ }
2223
+ }
2224
+ ZodArray.create = (schema, params) => {
2225
+ return new ZodArray({
2226
+ type: schema,
2227
+ minLength: null,
2228
+ maxLength: null,
2229
+ exactLength: null,
2230
+ typeName: ZodFirstPartyTypeKind.ZodArray,
2231
+ ...processCreateParams(params)
2232
+ });
2233
+ };
2234
+ function deepPartialify(schema) {
2235
+ if (schema instanceof ZodObject) {
2236
+ const newShape = {};
2237
+ for (const key in schema.shape) {
2238
+ const fieldSchema = schema.shape[key];
2239
+ newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
2240
+ }
2241
+ return new ZodObject({
2242
+ ...schema._def,
2243
+ shape: () => newShape
2244
+ });
2245
+ } else if (schema instanceof ZodArray) {
2246
+ return new ZodArray({
2247
+ ...schema._def,
2248
+ type: deepPartialify(schema.element)
2249
+ });
2250
+ } else if (schema instanceof ZodOptional) {
2251
+ return ZodOptional.create(deepPartialify(schema.unwrap()));
2252
+ } else if (schema instanceof ZodNullable) {
2253
+ return ZodNullable.create(deepPartialify(schema.unwrap()));
2254
+ } else if (schema instanceof ZodTuple) {
2255
+ return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
2256
+ } else {
2257
+ return schema;
2258
+ }
2259
+ }
2260
+ class ZodObject extends ZodType {
2261
+ constructor() {
2262
+ super(...arguments);
2263
+ this._cached = null;
2264
+ this.nonstrict = this.passthrough;
2265
+ this.augment = this.extend;
2266
+ }
2267
+ _getCached() {
2268
+ if (this._cached !== null)
2269
+ return this._cached;
2270
+ const shape = this._def.shape();
2271
+ const keys = util.objectKeys(shape);
2272
+ return this._cached = { shape, keys };
2273
+ }
2274
+ _parse(input) {
2275
+ const parsedType = this._getType(input);
2276
+ if (parsedType !== ZodParsedType.object) {
2277
+ const ctx2 = this._getOrReturnCtx(input);
2278
+ addIssueToContext(ctx2, {
2279
+ code: ZodIssueCode.invalid_type,
2280
+ expected: ZodParsedType.object,
2281
+ received: ctx2.parsedType
2282
+ });
2283
+ return INVALID;
2284
+ }
2285
+ const { status, ctx } = this._processInputParams(input);
2286
+ const { shape, keys: shapeKeys } = this._getCached();
2287
+ const extraKeys = [];
2288
+ if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
2289
+ for (const key in ctx.data) {
2290
+ if (!shapeKeys.includes(key)) {
2291
+ extraKeys.push(key);
2292
+ }
2293
+ }
2294
+ }
2295
+ const pairs = [];
2296
+ for (const key of shapeKeys) {
2297
+ const keyValidator = shape[key];
2298
+ const value = ctx.data[key];
2299
+ pairs.push({
2300
+ key: { status: "valid", value: key },
2301
+ value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
2302
+ alwaysSet: key in ctx.data
2303
+ });
2304
+ }
2305
+ if (this._def.catchall instanceof ZodNever) {
2306
+ const unknownKeys = this._def.unknownKeys;
2307
+ if (unknownKeys === "passthrough") {
2308
+ for (const key of extraKeys) {
2309
+ pairs.push({
2310
+ key: { status: "valid", value: key },
2311
+ value: { status: "valid", value: ctx.data[key] }
2312
+ });
2313
+ }
2314
+ } else if (unknownKeys === "strict") {
2315
+ if (extraKeys.length > 0) {
2316
+ addIssueToContext(ctx, {
2317
+ code: ZodIssueCode.unrecognized_keys,
2318
+ keys: extraKeys
2319
+ });
2320
+ status.dirty();
2321
+ }
2322
+ } else if (unknownKeys === "strip")
2323
+ ;
2324
+ else {
2325
+ throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
2326
+ }
2327
+ } else {
2328
+ const catchall = this._def.catchall;
2329
+ for (const key of extraKeys) {
2330
+ const value = ctx.data[key];
2331
+ pairs.push({
2332
+ key: { status: "valid", value: key },
2333
+ value: catchall._parse(
2334
+ new ParseInputLazyPath(ctx, value, ctx.path, key)
2335
+ //, ctx.child(key), value, getParsedType(value)
2336
+ ),
2337
+ alwaysSet: key in ctx.data
2338
+ });
2339
+ }
2340
+ }
2341
+ if (ctx.common.async) {
2342
+ return Promise.resolve().then(async () => {
2343
+ const syncPairs = [];
2344
+ for (const pair of pairs) {
2345
+ const key = await pair.key;
2346
+ const value = await pair.value;
2347
+ syncPairs.push({
2348
+ key,
2349
+ value,
2350
+ alwaysSet: pair.alwaysSet
2351
+ });
2352
+ }
2353
+ return syncPairs;
2354
+ }).then((syncPairs) => {
2355
+ return ParseStatus.mergeObjectSync(status, syncPairs);
2356
+ });
2357
+ } else {
2358
+ return ParseStatus.mergeObjectSync(status, pairs);
2359
+ }
2360
+ }
2361
+ get shape() {
2362
+ return this._def.shape();
2363
+ }
2364
+ strict(message) {
2365
+ errorUtil.errToObj;
2366
+ return new ZodObject({
2367
+ ...this._def,
2368
+ unknownKeys: "strict",
2369
+ ...message !== void 0 ? {
2370
+ errorMap: (issue, ctx) => {
2371
+ var _a, _b, _c, _d;
2372
+ const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
2373
+ if (issue.code === "unrecognized_keys")
2374
+ return {
2375
+ message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
2376
+ };
2377
+ return {
2378
+ message: defaultError
2379
+ };
2380
+ }
2381
+ } : {}
2382
+ });
2383
+ }
2384
+ strip() {
2385
+ return new ZodObject({
2386
+ ...this._def,
2387
+ unknownKeys: "strip"
2388
+ });
2389
+ }
2390
+ passthrough() {
2391
+ return new ZodObject({
2392
+ ...this._def,
2393
+ unknownKeys: "passthrough"
2394
+ });
2395
+ }
2396
+ // const AugmentFactory =
2397
+ // <Def extends ZodObjectDef>(def: Def) =>
2398
+ // <Augmentation extends ZodRawShape>(
2399
+ // augmentation: Augmentation
2400
+ // ): ZodObject<
2401
+ // extendShape<ReturnType<Def["shape"]>, Augmentation>,
2402
+ // Def["unknownKeys"],
2403
+ // Def["catchall"]
2404
+ // > => {
2405
+ // return new ZodObject({
2406
+ // ...def,
2407
+ // shape: () => ({
2408
+ // ...def.shape(),
2409
+ // ...augmentation,
2410
+ // }),
2411
+ // }) as any;
2412
+ // };
2413
+ extend(augmentation) {
2414
+ return new ZodObject({
2415
+ ...this._def,
2416
+ shape: () => ({
2417
+ ...this._def.shape(),
2418
+ ...augmentation
2419
+ })
2420
+ });
2421
+ }
2422
+ /**
2423
+ * Prior to zod@1.0.12 there was a bug in the
2424
+ * inferred type of merged objects. Please
2425
+ * upgrade if you are experiencing issues.
2426
+ */
2427
+ merge(merging) {
2428
+ const merged = new ZodObject({
2429
+ unknownKeys: merging._def.unknownKeys,
2430
+ catchall: merging._def.catchall,
2431
+ shape: () => ({
2432
+ ...this._def.shape(),
2433
+ ...merging._def.shape()
2434
+ }),
2435
+ typeName: ZodFirstPartyTypeKind.ZodObject
2436
+ });
2437
+ return merged;
2438
+ }
2439
+ // merge<
2440
+ // Incoming extends AnyZodObject,
2441
+ // Augmentation extends Incoming["shape"],
2442
+ // NewOutput extends {
2443
+ // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
2444
+ // ? Augmentation[k]["_output"]
2445
+ // : k extends keyof Output
2446
+ // ? Output[k]
2447
+ // : never;
2448
+ // },
2449
+ // NewInput extends {
2450
+ // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
2451
+ // ? Augmentation[k]["_input"]
2452
+ // : k extends keyof Input
2453
+ // ? Input[k]
2454
+ // : never;
2455
+ // }
2456
+ // >(
2457
+ // merging: Incoming
2458
+ // ): ZodObject<
2459
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2460
+ // Incoming["_def"]["unknownKeys"],
2461
+ // Incoming["_def"]["catchall"],
2462
+ // NewOutput,
2463
+ // NewInput
2464
+ // > {
2465
+ // const merged: any = new ZodObject({
2466
+ // unknownKeys: merging._def.unknownKeys,
2467
+ // catchall: merging._def.catchall,
2468
+ // shape: () =>
2469
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2470
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2471
+ // }) as any;
2472
+ // return merged;
2473
+ // }
2474
+ setKey(key, schema) {
2475
+ return this.augment({ [key]: schema });
2476
+ }
2477
+ // merge<Incoming extends AnyZodObject>(
2478
+ // merging: Incoming
2479
+ // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
2480
+ // ZodObject<
2481
+ // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
2482
+ // Incoming["_def"]["unknownKeys"],
2483
+ // Incoming["_def"]["catchall"]
2484
+ // > {
2485
+ // // const mergedShape = objectUtil.mergeShapes(
2486
+ // // this._def.shape(),
2487
+ // // merging._def.shape()
2488
+ // // );
2489
+ // const merged: any = new ZodObject({
2490
+ // unknownKeys: merging._def.unknownKeys,
2491
+ // catchall: merging._def.catchall,
2492
+ // shape: () =>
2493
+ // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
2494
+ // typeName: ZodFirstPartyTypeKind.ZodObject,
2495
+ // }) as any;
2496
+ // return merged;
2497
+ // }
2498
+ catchall(index) {
2499
+ return new ZodObject({
2500
+ ...this._def,
2501
+ catchall: index
2502
+ });
2503
+ }
2504
+ pick(mask) {
2505
+ const shape = {};
2506
+ util.objectKeys(mask).forEach((key) => {
2507
+ if (mask[key] && this.shape[key]) {
2508
+ shape[key] = this.shape[key];
2509
+ }
2510
+ });
2511
+ return new ZodObject({
2512
+ ...this._def,
2513
+ shape: () => shape
2514
+ });
2515
+ }
2516
+ omit(mask) {
2517
+ const shape = {};
2518
+ util.objectKeys(this.shape).forEach((key) => {
2519
+ if (!mask[key]) {
2520
+ shape[key] = this.shape[key];
2521
+ }
2522
+ });
2523
+ return new ZodObject({
2524
+ ...this._def,
2525
+ shape: () => shape
2526
+ });
2527
+ }
2528
+ /**
2529
+ * @deprecated
2530
+ */
2531
+ deepPartial() {
2532
+ return deepPartialify(this);
2533
+ }
2534
+ partial(mask) {
2535
+ const newShape = {};
2536
+ util.objectKeys(this.shape).forEach((key) => {
2537
+ const fieldSchema = this.shape[key];
2538
+ if (mask && !mask[key]) {
2539
+ newShape[key] = fieldSchema;
2540
+ } else {
2541
+ newShape[key] = fieldSchema.optional();
2542
+ }
2543
+ });
2544
+ return new ZodObject({
2545
+ ...this._def,
2546
+ shape: () => newShape
2547
+ });
2548
+ }
2549
+ required(mask) {
2550
+ const newShape = {};
2551
+ util.objectKeys(this.shape).forEach((key) => {
2552
+ if (mask && !mask[key]) {
2553
+ newShape[key] = this.shape[key];
2554
+ } else {
2555
+ const fieldSchema = this.shape[key];
2556
+ let newField = fieldSchema;
2557
+ while (newField instanceof ZodOptional) {
2558
+ newField = newField._def.innerType;
2559
+ }
2560
+ newShape[key] = newField;
2561
+ }
2562
+ });
2563
+ return new ZodObject({
2564
+ ...this._def,
2565
+ shape: () => newShape
2566
+ });
2567
+ }
2568
+ keyof() {
2569
+ return createZodEnum(util.objectKeys(this.shape));
2570
+ }
2571
+ }
2572
+ ZodObject.create = (shape, params) => {
2573
+ return new ZodObject({
2574
+ shape: () => shape,
2575
+ unknownKeys: "strip",
2576
+ catchall: ZodNever.create(),
2577
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2578
+ ...processCreateParams(params)
2579
+ });
2580
+ };
2581
+ ZodObject.strictCreate = (shape, params) => {
2582
+ return new ZodObject({
2583
+ shape: () => shape,
2584
+ unknownKeys: "strict",
2585
+ catchall: ZodNever.create(),
2586
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2587
+ ...processCreateParams(params)
2588
+ });
2589
+ };
2590
+ ZodObject.lazycreate = (shape, params) => {
2591
+ return new ZodObject({
2592
+ shape,
2593
+ unknownKeys: "strip",
2594
+ catchall: ZodNever.create(),
2595
+ typeName: ZodFirstPartyTypeKind.ZodObject,
2596
+ ...processCreateParams(params)
2597
+ });
2598
+ };
2599
+ class ZodUnion extends ZodType {
2600
+ _parse(input) {
2601
+ const { ctx } = this._processInputParams(input);
2602
+ const options = this._def.options;
2603
+ function handleResults(results) {
2604
+ for (const result of results) {
2605
+ if (result.result.status === "valid") {
2606
+ return result.result;
2607
+ }
2608
+ }
2609
+ for (const result of results) {
2610
+ if (result.result.status === "dirty") {
2611
+ ctx.common.issues.push(...result.ctx.common.issues);
2612
+ return result.result;
2613
+ }
2614
+ }
2615
+ const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
2616
+ addIssueToContext(ctx, {
2617
+ code: ZodIssueCode.invalid_union,
2618
+ unionErrors
2619
+ });
2620
+ return INVALID;
2621
+ }
2622
+ if (ctx.common.async) {
2623
+ return Promise.all(options.map(async (option) => {
2624
+ const childCtx = {
2625
+ ...ctx,
2626
+ common: {
2627
+ ...ctx.common,
2628
+ issues: []
2629
+ },
2630
+ parent: null
2631
+ };
2632
+ return {
2633
+ result: await option._parseAsync({
2634
+ data: ctx.data,
2635
+ path: ctx.path,
2636
+ parent: childCtx
2637
+ }),
2638
+ ctx: childCtx
2639
+ };
2640
+ })).then(handleResults);
2641
+ } else {
2642
+ let dirty = void 0;
2643
+ const issues = [];
2644
+ for (const option of options) {
2645
+ const childCtx = {
2646
+ ...ctx,
2647
+ common: {
2648
+ ...ctx.common,
2649
+ issues: []
2650
+ },
2651
+ parent: null
2652
+ };
2653
+ const result = option._parseSync({
2654
+ data: ctx.data,
2655
+ path: ctx.path,
2656
+ parent: childCtx
2657
+ });
2658
+ if (result.status === "valid") {
2659
+ return result;
2660
+ } else if (result.status === "dirty" && !dirty) {
2661
+ dirty = { result, ctx: childCtx };
2662
+ }
2663
+ if (childCtx.common.issues.length) {
2664
+ issues.push(childCtx.common.issues);
2665
+ }
2666
+ }
2667
+ if (dirty) {
2668
+ ctx.common.issues.push(...dirty.ctx.common.issues);
2669
+ return dirty.result;
2670
+ }
2671
+ const unionErrors = issues.map((issues2) => new ZodError(issues2));
2672
+ addIssueToContext(ctx, {
2673
+ code: ZodIssueCode.invalid_union,
2674
+ unionErrors
2675
+ });
2676
+ return INVALID;
2677
+ }
2678
+ }
2679
+ get options() {
2680
+ return this._def.options;
2681
+ }
2682
+ }
2683
+ ZodUnion.create = (types, params) => {
2684
+ return new ZodUnion({
2685
+ options: types,
2686
+ typeName: ZodFirstPartyTypeKind.ZodUnion,
2687
+ ...processCreateParams(params)
2688
+ });
2689
+ };
2690
+ const getDiscriminator = (type) => {
2691
+ if (type instanceof ZodLazy) {
2692
+ return getDiscriminator(type.schema);
2693
+ } else if (type instanceof ZodEffects) {
2694
+ return getDiscriminator(type.innerType());
2695
+ } else if (type instanceof ZodLiteral) {
2696
+ return [type.value];
2697
+ } else if (type instanceof ZodEnum) {
2698
+ return type.options;
2699
+ } else if (type instanceof ZodNativeEnum) {
2700
+ return util.objectValues(type.enum);
2701
+ } else if (type instanceof ZodDefault) {
2702
+ return getDiscriminator(type._def.innerType);
2703
+ } else if (type instanceof ZodUndefined) {
2704
+ return [void 0];
2705
+ } else if (type instanceof ZodNull) {
2706
+ return [null];
2707
+ } else if (type instanceof ZodOptional) {
2708
+ return [void 0, ...getDiscriminator(type.unwrap())];
2709
+ } else if (type instanceof ZodNullable) {
2710
+ return [null, ...getDiscriminator(type.unwrap())];
2711
+ } else if (type instanceof ZodBranded) {
2712
+ return getDiscriminator(type.unwrap());
2713
+ } else if (type instanceof ZodReadonly) {
2714
+ return getDiscriminator(type.unwrap());
2715
+ } else if (type instanceof ZodCatch) {
2716
+ return getDiscriminator(type._def.innerType);
2717
+ } else {
2718
+ return [];
2719
+ }
2720
+ };
2721
+ class ZodDiscriminatedUnion extends ZodType {
2722
+ _parse(input) {
2723
+ const { ctx } = this._processInputParams(input);
2724
+ if (ctx.parsedType !== ZodParsedType.object) {
2725
+ addIssueToContext(ctx, {
2726
+ code: ZodIssueCode.invalid_type,
2727
+ expected: ZodParsedType.object,
2728
+ received: ctx.parsedType
2729
+ });
2730
+ return INVALID;
2731
+ }
2732
+ const discriminator = this.discriminator;
2733
+ const discriminatorValue = ctx.data[discriminator];
2734
+ const option = this.optionsMap.get(discriminatorValue);
2735
+ if (!option) {
2736
+ addIssueToContext(ctx, {
2737
+ code: ZodIssueCode.invalid_union_discriminator,
2738
+ options: Array.from(this.optionsMap.keys()),
2739
+ path: [discriminator]
2740
+ });
2741
+ return INVALID;
2742
+ }
2743
+ if (ctx.common.async) {
2744
+ return option._parseAsync({
2745
+ data: ctx.data,
2746
+ path: ctx.path,
2747
+ parent: ctx
2748
+ });
2749
+ } else {
2750
+ return option._parseSync({
2751
+ data: ctx.data,
2752
+ path: ctx.path,
2753
+ parent: ctx
2754
+ });
2755
+ }
2756
+ }
2757
+ get discriminator() {
2758
+ return this._def.discriminator;
2759
+ }
2760
+ get options() {
2761
+ return this._def.options;
2762
+ }
2763
+ get optionsMap() {
2764
+ return this._def.optionsMap;
2765
+ }
2766
+ /**
2767
+ * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
2768
+ * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
2769
+ * have a different value for each object in the union.
2770
+ * @param discriminator the name of the discriminator property
2771
+ * @param types an array of object schemas
2772
+ * @param params
2773
+ */
2774
+ static create(discriminator, options, params) {
2775
+ const optionsMap = /* @__PURE__ */ new Map();
2776
+ for (const type of options) {
2777
+ const discriminatorValues = getDiscriminator(type.shape[discriminator]);
2778
+ if (!discriminatorValues.length) {
2779
+ throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
2780
+ }
2781
+ for (const value of discriminatorValues) {
2782
+ if (optionsMap.has(value)) {
2783
+ throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
2784
+ }
2785
+ optionsMap.set(value, type);
2786
+ }
2787
+ }
2788
+ return new ZodDiscriminatedUnion({
2789
+ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
2790
+ discriminator,
2791
+ options,
2792
+ optionsMap,
2793
+ ...processCreateParams(params)
2794
+ });
2795
+ }
2796
+ }
2797
+ function mergeValues(a2, b2) {
2798
+ const aType = getParsedType(a2);
2799
+ const bType = getParsedType(b2);
2800
+ if (a2 === b2) {
2801
+ return { valid: true, data: a2 };
2802
+ } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
2803
+ const bKeys = util.objectKeys(b2);
2804
+ const sharedKeys = util.objectKeys(a2).filter((key) => bKeys.indexOf(key) !== -1);
2805
+ const newObj = { ...a2, ...b2 };
2806
+ for (const key of sharedKeys) {
2807
+ const sharedValue = mergeValues(a2[key], b2[key]);
2808
+ if (!sharedValue.valid) {
2809
+ return { valid: false };
2810
+ }
2811
+ newObj[key] = sharedValue.data;
2812
+ }
2813
+ return { valid: true, data: newObj };
2814
+ } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
2815
+ if (a2.length !== b2.length) {
2816
+ return { valid: false };
2817
+ }
2818
+ const newArray = [];
2819
+ for (let index = 0; index < a2.length; index++) {
2820
+ const itemA = a2[index];
2821
+ const itemB = b2[index];
2822
+ const sharedValue = mergeValues(itemA, itemB);
2823
+ if (!sharedValue.valid) {
2824
+ return { valid: false };
2825
+ }
2826
+ newArray.push(sharedValue.data);
2827
+ }
2828
+ return { valid: true, data: newArray };
2829
+ } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a2 === +b2) {
2830
+ return { valid: true, data: a2 };
2831
+ } else {
2832
+ return { valid: false };
2833
+ }
2834
+ }
2835
+ class ZodIntersection extends ZodType {
2836
+ _parse(input) {
2837
+ const { status, ctx } = this._processInputParams(input);
2838
+ const handleParsed = (parsedLeft, parsedRight) => {
2839
+ if (isAborted(parsedLeft) || isAborted(parsedRight)) {
2840
+ return INVALID;
2841
+ }
2842
+ const merged = mergeValues(parsedLeft.value, parsedRight.value);
2843
+ if (!merged.valid) {
2844
+ addIssueToContext(ctx, {
2845
+ code: ZodIssueCode.invalid_intersection_types
2846
+ });
2847
+ return INVALID;
2848
+ }
2849
+ if (isDirty(parsedLeft) || isDirty(parsedRight)) {
2850
+ status.dirty();
2851
+ }
2852
+ return { status: status.value, value: merged.data };
2853
+ };
2854
+ if (ctx.common.async) {
2855
+ return Promise.all([
2856
+ this._def.left._parseAsync({
2857
+ data: ctx.data,
2858
+ path: ctx.path,
2859
+ parent: ctx
2860
+ }),
2861
+ this._def.right._parseAsync({
2862
+ data: ctx.data,
2863
+ path: ctx.path,
2864
+ parent: ctx
2865
+ })
2866
+ ]).then(([left, right]) => handleParsed(left, right));
2867
+ } else {
2868
+ return handleParsed(this._def.left._parseSync({
2869
+ data: ctx.data,
2870
+ path: ctx.path,
2871
+ parent: ctx
2872
+ }), this._def.right._parseSync({
2873
+ data: ctx.data,
2874
+ path: ctx.path,
2875
+ parent: ctx
2876
+ }));
2877
+ }
2878
+ }
2879
+ }
2880
+ ZodIntersection.create = (left, right, params) => {
2881
+ return new ZodIntersection({
2882
+ left,
2883
+ right,
2884
+ typeName: ZodFirstPartyTypeKind.ZodIntersection,
2885
+ ...processCreateParams(params)
2886
+ });
2887
+ };
2888
+ class ZodTuple extends ZodType {
2889
+ _parse(input) {
2890
+ const { status, ctx } = this._processInputParams(input);
2891
+ if (ctx.parsedType !== ZodParsedType.array) {
2892
+ addIssueToContext(ctx, {
2893
+ code: ZodIssueCode.invalid_type,
2894
+ expected: ZodParsedType.array,
2895
+ received: ctx.parsedType
2896
+ });
2897
+ return INVALID;
2898
+ }
2899
+ if (ctx.data.length < this._def.items.length) {
2900
+ addIssueToContext(ctx, {
2901
+ code: ZodIssueCode.too_small,
2902
+ minimum: this._def.items.length,
2903
+ inclusive: true,
2904
+ exact: false,
2905
+ type: "array"
2906
+ });
2907
+ return INVALID;
2908
+ }
2909
+ const rest = this._def.rest;
2910
+ if (!rest && ctx.data.length > this._def.items.length) {
2911
+ addIssueToContext(ctx, {
2912
+ code: ZodIssueCode.too_big,
2913
+ maximum: this._def.items.length,
2914
+ inclusive: true,
2915
+ exact: false,
2916
+ type: "array"
2917
+ });
2918
+ status.dirty();
2919
+ }
2920
+ const items = [...ctx.data].map((item, itemIndex) => {
2921
+ const schema = this._def.items[itemIndex] || this._def.rest;
2922
+ if (!schema)
2923
+ return null;
2924
+ return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
2925
+ }).filter((x2) => !!x2);
2926
+ if (ctx.common.async) {
2927
+ return Promise.all(items).then((results) => {
2928
+ return ParseStatus.mergeArray(status, results);
2929
+ });
2930
+ } else {
2931
+ return ParseStatus.mergeArray(status, items);
2932
+ }
2933
+ }
2934
+ get items() {
2935
+ return this._def.items;
2936
+ }
2937
+ rest(rest) {
2938
+ return new ZodTuple({
2939
+ ...this._def,
2940
+ rest
2941
+ });
2942
+ }
2943
+ }
2944
+ ZodTuple.create = (schemas, params) => {
2945
+ if (!Array.isArray(schemas)) {
2946
+ throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2947
+ }
2948
+ return new ZodTuple({
2949
+ items: schemas,
2950
+ typeName: ZodFirstPartyTypeKind.ZodTuple,
2951
+ rest: null,
2952
+ ...processCreateParams(params)
2953
+ });
2954
+ };
2955
+ class ZodRecord extends ZodType {
2956
+ get keySchema() {
2957
+ return this._def.keyType;
2958
+ }
2959
+ get valueSchema() {
2960
+ return this._def.valueType;
2961
+ }
2962
+ _parse(input) {
2963
+ const { status, ctx } = this._processInputParams(input);
2964
+ if (ctx.parsedType !== ZodParsedType.object) {
2965
+ addIssueToContext(ctx, {
2966
+ code: ZodIssueCode.invalid_type,
2967
+ expected: ZodParsedType.object,
2968
+ received: ctx.parsedType
2969
+ });
2970
+ return INVALID;
2971
+ }
2972
+ const pairs = [];
2973
+ const keyType = this._def.keyType;
2974
+ const valueType = this._def.valueType;
2975
+ for (const key in ctx.data) {
2976
+ pairs.push({
2977
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
2978
+ value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
2979
+ alwaysSet: key in ctx.data
2980
+ });
2981
+ }
2982
+ if (ctx.common.async) {
2983
+ return ParseStatus.mergeObjectAsync(status, pairs);
2984
+ } else {
2985
+ return ParseStatus.mergeObjectSync(status, pairs);
2986
+ }
2987
+ }
2988
+ get element() {
2989
+ return this._def.valueType;
2990
+ }
2991
+ static create(first, second, third) {
2992
+ if (second instanceof ZodType) {
2993
+ return new ZodRecord({
2994
+ keyType: first,
2995
+ valueType: second,
2996
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
2997
+ ...processCreateParams(third)
2998
+ });
2999
+ }
3000
+ return new ZodRecord({
3001
+ keyType: ZodString.create(),
3002
+ valueType: first,
3003
+ typeName: ZodFirstPartyTypeKind.ZodRecord,
3004
+ ...processCreateParams(second)
3005
+ });
3006
+ }
3007
+ }
3008
+ class ZodMap extends ZodType {
3009
+ get keySchema() {
3010
+ return this._def.keyType;
3011
+ }
3012
+ get valueSchema() {
3013
+ return this._def.valueType;
3014
+ }
3015
+ _parse(input) {
3016
+ const { status, ctx } = this._processInputParams(input);
3017
+ if (ctx.parsedType !== ZodParsedType.map) {
3018
+ addIssueToContext(ctx, {
3019
+ code: ZodIssueCode.invalid_type,
3020
+ expected: ZodParsedType.map,
3021
+ received: ctx.parsedType
3022
+ });
3023
+ return INVALID;
3024
+ }
3025
+ const keyType = this._def.keyType;
3026
+ const valueType = this._def.valueType;
3027
+ const pairs = [...ctx.data.entries()].map(([key, value], index) => {
3028
+ return {
3029
+ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
3030
+ value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
3031
+ };
3032
+ });
3033
+ if (ctx.common.async) {
3034
+ const finalMap = /* @__PURE__ */ new Map();
3035
+ return Promise.resolve().then(async () => {
3036
+ for (const pair of pairs) {
3037
+ const key = await pair.key;
3038
+ const value = await pair.value;
3039
+ if (key.status === "aborted" || value.status === "aborted") {
3040
+ return INVALID;
3041
+ }
3042
+ if (key.status === "dirty" || value.status === "dirty") {
3043
+ status.dirty();
3044
+ }
3045
+ finalMap.set(key.value, value.value);
3046
+ }
3047
+ return { status: status.value, value: finalMap };
3048
+ });
3049
+ } else {
3050
+ const finalMap = /* @__PURE__ */ new Map();
3051
+ for (const pair of pairs) {
3052
+ const key = pair.key;
3053
+ const value = pair.value;
3054
+ if (key.status === "aborted" || value.status === "aborted") {
3055
+ return INVALID;
3056
+ }
3057
+ if (key.status === "dirty" || value.status === "dirty") {
3058
+ status.dirty();
3059
+ }
3060
+ finalMap.set(key.value, value.value);
3061
+ }
3062
+ return { status: status.value, value: finalMap };
3063
+ }
3064
+ }
3065
+ }
3066
+ ZodMap.create = (keyType, valueType, params) => {
3067
+ return new ZodMap({
3068
+ valueType,
3069
+ keyType,
3070
+ typeName: ZodFirstPartyTypeKind.ZodMap,
3071
+ ...processCreateParams(params)
3072
+ });
3073
+ };
3074
+ class ZodSet extends ZodType {
3075
+ _parse(input) {
3076
+ const { status, ctx } = this._processInputParams(input);
3077
+ if (ctx.parsedType !== ZodParsedType.set) {
3078
+ addIssueToContext(ctx, {
3079
+ code: ZodIssueCode.invalid_type,
3080
+ expected: ZodParsedType.set,
3081
+ received: ctx.parsedType
3082
+ });
3083
+ return INVALID;
3084
+ }
3085
+ const def = this._def;
3086
+ if (def.minSize !== null) {
3087
+ if (ctx.data.size < def.minSize.value) {
3088
+ addIssueToContext(ctx, {
3089
+ code: ZodIssueCode.too_small,
3090
+ minimum: def.minSize.value,
3091
+ type: "set",
3092
+ inclusive: true,
3093
+ exact: false,
3094
+ message: def.minSize.message
3095
+ });
3096
+ status.dirty();
3097
+ }
3098
+ }
3099
+ if (def.maxSize !== null) {
3100
+ if (ctx.data.size > def.maxSize.value) {
3101
+ addIssueToContext(ctx, {
3102
+ code: ZodIssueCode.too_big,
3103
+ maximum: def.maxSize.value,
3104
+ type: "set",
3105
+ inclusive: true,
3106
+ exact: false,
3107
+ message: def.maxSize.message
3108
+ });
3109
+ status.dirty();
3110
+ }
3111
+ }
3112
+ const valueType = this._def.valueType;
3113
+ function finalizeSet(elements2) {
3114
+ const parsedSet = /* @__PURE__ */ new Set();
3115
+ for (const element of elements2) {
3116
+ if (element.status === "aborted")
3117
+ return INVALID;
3118
+ if (element.status === "dirty")
3119
+ status.dirty();
3120
+ parsedSet.add(element.value);
3121
+ }
3122
+ return { status: status.value, value: parsedSet };
3123
+ }
3124
+ const elements = [...ctx.data.values()].map((item, i2) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i2)));
3125
+ if (ctx.common.async) {
3126
+ return Promise.all(elements).then((elements2) => finalizeSet(elements2));
3127
+ } else {
3128
+ return finalizeSet(elements);
3129
+ }
3130
+ }
3131
+ min(minSize, message) {
3132
+ return new ZodSet({
3133
+ ...this._def,
3134
+ minSize: { value: minSize, message: errorUtil.toString(message) }
3135
+ });
3136
+ }
3137
+ max(maxSize, message) {
3138
+ return new ZodSet({
3139
+ ...this._def,
3140
+ maxSize: { value: maxSize, message: errorUtil.toString(message) }
3141
+ });
3142
+ }
3143
+ size(size, message) {
3144
+ return this.min(size, message).max(size, message);
3145
+ }
3146
+ nonempty(message) {
3147
+ return this.min(1, message);
3148
+ }
3149
+ }
3150
+ ZodSet.create = (valueType, params) => {
3151
+ return new ZodSet({
3152
+ valueType,
3153
+ minSize: null,
3154
+ maxSize: null,
3155
+ typeName: ZodFirstPartyTypeKind.ZodSet,
3156
+ ...processCreateParams(params)
3157
+ });
3158
+ };
3159
+ class ZodFunction extends ZodType {
3160
+ constructor() {
3161
+ super(...arguments);
3162
+ this.validate = this.implement;
3163
+ }
3164
+ _parse(input) {
3165
+ const { ctx } = this._processInputParams(input);
3166
+ if (ctx.parsedType !== ZodParsedType.function) {
3167
+ addIssueToContext(ctx, {
3168
+ code: ZodIssueCode.invalid_type,
3169
+ expected: ZodParsedType.function,
3170
+ received: ctx.parsedType
3171
+ });
3172
+ return INVALID;
3173
+ }
3174
+ function makeArgsIssue(args, error) {
3175
+ return makeIssue({
3176
+ data: args,
3177
+ path: ctx.path,
3178
+ errorMaps: [
3179
+ ctx.common.contextualErrorMap,
3180
+ ctx.schemaErrorMap,
3181
+ getErrorMap(),
3182
+ errorMap
3183
+ ].filter((x2) => !!x2),
3184
+ issueData: {
3185
+ code: ZodIssueCode.invalid_arguments,
3186
+ argumentsError: error
3187
+ }
3188
+ });
3189
+ }
3190
+ function makeReturnsIssue(returns, error) {
3191
+ return makeIssue({
3192
+ data: returns,
3193
+ path: ctx.path,
3194
+ errorMaps: [
3195
+ ctx.common.contextualErrorMap,
3196
+ ctx.schemaErrorMap,
3197
+ getErrorMap(),
3198
+ errorMap
3199
+ ].filter((x2) => !!x2),
3200
+ issueData: {
3201
+ code: ZodIssueCode.invalid_return_type,
3202
+ returnTypeError: error
3203
+ }
3204
+ });
3205
+ }
3206
+ const params = { errorMap: ctx.common.contextualErrorMap };
3207
+ const fn = ctx.data;
3208
+ if (this._def.returns instanceof ZodPromise) {
3209
+ const me = this;
3210
+ return OK(async function(...args) {
3211
+ const error = new ZodError([]);
3212
+ const parsedArgs = await me._def.args.parseAsync(args, params).catch((e2) => {
3213
+ error.addIssue(makeArgsIssue(args, e2));
3214
+ throw error;
3215
+ });
3216
+ const result = await Reflect.apply(fn, this, parsedArgs);
3217
+ const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e2) => {
3218
+ error.addIssue(makeReturnsIssue(result, e2));
3219
+ throw error;
3220
+ });
3221
+ return parsedReturns;
3222
+ });
3223
+ } else {
3224
+ const me = this;
3225
+ return OK(function(...args) {
3226
+ const parsedArgs = me._def.args.safeParse(args, params);
3227
+ if (!parsedArgs.success) {
3228
+ throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
3229
+ }
3230
+ const result = Reflect.apply(fn, this, parsedArgs.data);
3231
+ const parsedReturns = me._def.returns.safeParse(result, params);
3232
+ if (!parsedReturns.success) {
3233
+ throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
3234
+ }
3235
+ return parsedReturns.data;
3236
+ });
3237
+ }
3238
+ }
3239
+ parameters() {
3240
+ return this._def.args;
3241
+ }
3242
+ returnType() {
3243
+ return this._def.returns;
3244
+ }
3245
+ args(...items) {
3246
+ return new ZodFunction({
3247
+ ...this._def,
3248
+ args: ZodTuple.create(items).rest(ZodUnknown.create())
3249
+ });
3250
+ }
3251
+ returns(returnType) {
3252
+ return new ZodFunction({
3253
+ ...this._def,
3254
+ returns: returnType
3255
+ });
3256
+ }
3257
+ implement(func) {
3258
+ const validatedFunc = this.parse(func);
3259
+ return validatedFunc;
3260
+ }
3261
+ strictImplement(func) {
3262
+ const validatedFunc = this.parse(func);
3263
+ return validatedFunc;
3264
+ }
3265
+ static create(args, returns, params) {
3266
+ return new ZodFunction({
3267
+ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
3268
+ returns: returns || ZodUnknown.create(),
3269
+ typeName: ZodFirstPartyTypeKind.ZodFunction,
3270
+ ...processCreateParams(params)
3271
+ });
3272
+ }
3273
+ }
3274
+ class ZodLazy extends ZodType {
3275
+ get schema() {
3276
+ return this._def.getter();
3277
+ }
3278
+ _parse(input) {
3279
+ const { ctx } = this._processInputParams(input);
3280
+ const lazySchema = this._def.getter();
3281
+ return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
3282
+ }
3283
+ }
3284
+ ZodLazy.create = (getter, params) => {
3285
+ return new ZodLazy({
3286
+ getter,
3287
+ typeName: ZodFirstPartyTypeKind.ZodLazy,
3288
+ ...processCreateParams(params)
3289
+ });
3290
+ };
3291
+ class ZodLiteral extends ZodType {
3292
+ _parse(input) {
3293
+ if (input.data !== this._def.value) {
3294
+ const ctx = this._getOrReturnCtx(input);
3295
+ addIssueToContext(ctx, {
3296
+ received: ctx.data,
3297
+ code: ZodIssueCode.invalid_literal,
3298
+ expected: this._def.value
3299
+ });
3300
+ return INVALID;
3301
+ }
3302
+ return { status: "valid", value: input.data };
3303
+ }
3304
+ get value() {
3305
+ return this._def.value;
3306
+ }
3307
+ }
3308
+ ZodLiteral.create = (value, params) => {
3309
+ return new ZodLiteral({
3310
+ value,
3311
+ typeName: ZodFirstPartyTypeKind.ZodLiteral,
3312
+ ...processCreateParams(params)
3313
+ });
3314
+ };
3315
+ function createZodEnum(values, params) {
3316
+ return new ZodEnum({
3317
+ values,
3318
+ typeName: ZodFirstPartyTypeKind.ZodEnum,
3319
+ ...processCreateParams(params)
3320
+ });
3321
+ }
3322
+ class ZodEnum extends ZodType {
3323
+ constructor() {
3324
+ super(...arguments);
3325
+ _ZodEnum_cache.set(this, void 0);
3326
+ }
3327
+ _parse(input) {
3328
+ if (typeof input.data !== "string") {
3329
+ const ctx = this._getOrReturnCtx(input);
3330
+ const expectedValues = this._def.values;
3331
+ addIssueToContext(ctx, {
3332
+ expected: util.joinValues(expectedValues),
3333
+ received: ctx.parsedType,
3334
+ code: ZodIssueCode.invalid_type
3335
+ });
3336
+ return INVALID;
3337
+ }
3338
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f")) {
3339
+ __classPrivateFieldSet(this, _ZodEnum_cache, new Set(this._def.values), "f");
3340
+ }
3341
+ if (!__classPrivateFieldGet(this, _ZodEnum_cache, "f").has(input.data)) {
3342
+ const ctx = this._getOrReturnCtx(input);
3343
+ const expectedValues = this._def.values;
3344
+ addIssueToContext(ctx, {
3345
+ received: ctx.data,
3346
+ code: ZodIssueCode.invalid_enum_value,
3347
+ options: expectedValues
3348
+ });
3349
+ return INVALID;
3350
+ }
3351
+ return OK(input.data);
3352
+ }
3353
+ get options() {
3354
+ return this._def.values;
3355
+ }
3356
+ get enum() {
3357
+ const enumValues = {};
3358
+ for (const val of this._def.values) {
3359
+ enumValues[val] = val;
3360
+ }
3361
+ return enumValues;
3362
+ }
3363
+ get Values() {
3364
+ const enumValues = {};
3365
+ for (const val of this._def.values) {
3366
+ enumValues[val] = val;
3367
+ }
3368
+ return enumValues;
3369
+ }
3370
+ get Enum() {
3371
+ const enumValues = {};
3372
+ for (const val of this._def.values) {
3373
+ enumValues[val] = val;
3374
+ }
3375
+ return enumValues;
3376
+ }
3377
+ extract(values, newDef = this._def) {
3378
+ return ZodEnum.create(values, {
3379
+ ...this._def,
3380
+ ...newDef
3381
+ });
3382
+ }
3383
+ exclude(values, newDef = this._def) {
3384
+ return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
3385
+ ...this._def,
3386
+ ...newDef
3387
+ });
3388
+ }
3389
+ }
3390
+ _ZodEnum_cache = /* @__PURE__ */ new WeakMap();
3391
+ ZodEnum.create = createZodEnum;
3392
+ class ZodNativeEnum extends ZodType {
3393
+ constructor() {
3394
+ super(...arguments);
3395
+ _ZodNativeEnum_cache.set(this, void 0);
3396
+ }
3397
+ _parse(input) {
3398
+ const nativeEnumValues = util.getValidEnumValues(this._def.values);
3399
+ const ctx = this._getOrReturnCtx(input);
3400
+ if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
3401
+ const expectedValues = util.objectValues(nativeEnumValues);
3402
+ addIssueToContext(ctx, {
3403
+ expected: util.joinValues(expectedValues),
3404
+ received: ctx.parsedType,
3405
+ code: ZodIssueCode.invalid_type
3406
+ });
3407
+ return INVALID;
3408
+ }
3409
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f")) {
3410
+ __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)), "f");
3411
+ }
3412
+ if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache, "f").has(input.data)) {
3413
+ const expectedValues = util.objectValues(nativeEnumValues);
3414
+ addIssueToContext(ctx, {
3415
+ received: ctx.data,
3416
+ code: ZodIssueCode.invalid_enum_value,
3417
+ options: expectedValues
3418
+ });
3419
+ return INVALID;
3420
+ }
3421
+ return OK(input.data);
3422
+ }
3423
+ get enum() {
3424
+ return this._def.values;
3425
+ }
3426
+ }
3427
+ _ZodNativeEnum_cache = /* @__PURE__ */ new WeakMap();
3428
+ ZodNativeEnum.create = (values, params) => {
3429
+ return new ZodNativeEnum({
3430
+ values,
3431
+ typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
3432
+ ...processCreateParams(params)
3433
+ });
3434
+ };
3435
+ class ZodPromise extends ZodType {
3436
+ unwrap() {
3437
+ return this._def.type;
3438
+ }
3439
+ _parse(input) {
3440
+ const { ctx } = this._processInputParams(input);
3441
+ if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
3442
+ addIssueToContext(ctx, {
3443
+ code: ZodIssueCode.invalid_type,
3444
+ expected: ZodParsedType.promise,
3445
+ received: ctx.parsedType
3446
+ });
3447
+ return INVALID;
3448
+ }
3449
+ const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
3450
+ return OK(promisified.then((data) => {
3451
+ return this._def.type.parseAsync(data, {
3452
+ path: ctx.path,
3453
+ errorMap: ctx.common.contextualErrorMap
3454
+ });
3455
+ }));
3456
+ }
3457
+ }
3458
+ ZodPromise.create = (schema, params) => {
3459
+ return new ZodPromise({
3460
+ type: schema,
3461
+ typeName: ZodFirstPartyTypeKind.ZodPromise,
3462
+ ...processCreateParams(params)
3463
+ });
3464
+ };
3465
+ class ZodEffects extends ZodType {
3466
+ innerType() {
3467
+ return this._def.schema;
3468
+ }
3469
+ sourceType() {
3470
+ return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
3471
+ }
3472
+ _parse(input) {
3473
+ const { status, ctx } = this._processInputParams(input);
3474
+ const effect = this._def.effect || null;
3475
+ const checkCtx = {
3476
+ addIssue: (arg) => {
3477
+ addIssueToContext(ctx, arg);
3478
+ if (arg.fatal) {
3479
+ status.abort();
3480
+ } else {
3481
+ status.dirty();
3482
+ }
3483
+ },
3484
+ get path() {
3485
+ return ctx.path;
3486
+ }
3487
+ };
3488
+ checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
3489
+ if (effect.type === "preprocess") {
3490
+ const processed = effect.transform(ctx.data, checkCtx);
3491
+ if (ctx.common.async) {
3492
+ return Promise.resolve(processed).then(async (processed2) => {
3493
+ if (status.value === "aborted")
3494
+ return INVALID;
3495
+ const result = await this._def.schema._parseAsync({
3496
+ data: processed2,
3497
+ path: ctx.path,
3498
+ parent: ctx
3499
+ });
3500
+ if (result.status === "aborted")
3501
+ return INVALID;
3502
+ if (result.status === "dirty")
3503
+ return DIRTY(result.value);
3504
+ if (status.value === "dirty")
3505
+ return DIRTY(result.value);
3506
+ return result;
3507
+ });
3508
+ } else {
3509
+ if (status.value === "aborted")
3510
+ return INVALID;
3511
+ const result = this._def.schema._parseSync({
3512
+ data: processed,
3513
+ path: ctx.path,
3514
+ parent: ctx
3515
+ });
3516
+ if (result.status === "aborted")
3517
+ return INVALID;
3518
+ if (result.status === "dirty")
3519
+ return DIRTY(result.value);
3520
+ if (status.value === "dirty")
3521
+ return DIRTY(result.value);
3522
+ return result;
3523
+ }
3524
+ }
3525
+ if (effect.type === "refinement") {
3526
+ const executeRefinement = (acc) => {
3527
+ const result = effect.refinement(acc, checkCtx);
3528
+ if (ctx.common.async) {
3529
+ return Promise.resolve(result);
3530
+ }
3531
+ if (result instanceof Promise) {
3532
+ throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
3533
+ }
3534
+ return acc;
3535
+ };
3536
+ if (ctx.common.async === false) {
3537
+ const inner = this._def.schema._parseSync({
3538
+ data: ctx.data,
3539
+ path: ctx.path,
3540
+ parent: ctx
3541
+ });
3542
+ if (inner.status === "aborted")
3543
+ return INVALID;
3544
+ if (inner.status === "dirty")
3545
+ status.dirty();
3546
+ executeRefinement(inner.value);
3547
+ return { status: status.value, value: inner.value };
3548
+ } else {
3549
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => {
3550
+ if (inner.status === "aborted")
3551
+ return INVALID;
3552
+ if (inner.status === "dirty")
3553
+ status.dirty();
3554
+ return executeRefinement(inner.value).then(() => {
3555
+ return { status: status.value, value: inner.value };
3556
+ });
3557
+ });
3558
+ }
3559
+ }
3560
+ if (effect.type === "transform") {
3561
+ if (ctx.common.async === false) {
3562
+ const base = this._def.schema._parseSync({
3563
+ data: ctx.data,
3564
+ path: ctx.path,
3565
+ parent: ctx
3566
+ });
3567
+ if (!isValid(base))
3568
+ return base;
3569
+ const result = effect.transform(base.value, checkCtx);
3570
+ if (result instanceof Promise) {
3571
+ throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
3572
+ }
3573
+ return { status: status.value, value: result };
3574
+ } else {
3575
+ return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => {
3576
+ if (!isValid(base))
3577
+ return base;
3578
+ return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
3579
+ });
3580
+ }
3581
+ }
3582
+ util.assertNever(effect);
3583
+ }
3584
+ }
3585
+ ZodEffects.create = (schema, effect, params) => {
3586
+ return new ZodEffects({
3587
+ schema,
3588
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3589
+ effect,
3590
+ ...processCreateParams(params)
3591
+ });
3592
+ };
3593
+ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
3594
+ return new ZodEffects({
3595
+ schema,
3596
+ effect: { type: "preprocess", transform: preprocess },
3597
+ typeName: ZodFirstPartyTypeKind.ZodEffects,
3598
+ ...processCreateParams(params)
3599
+ });
3600
+ };
3601
+ class ZodOptional extends ZodType {
3602
+ _parse(input) {
3603
+ const parsedType = this._getType(input);
3604
+ if (parsedType === ZodParsedType.undefined) {
3605
+ return OK(void 0);
3606
+ }
3607
+ return this._def.innerType._parse(input);
3608
+ }
3609
+ unwrap() {
3610
+ return this._def.innerType;
3611
+ }
3612
+ }
3613
+ ZodOptional.create = (type, params) => {
3614
+ return new ZodOptional({
3615
+ innerType: type,
3616
+ typeName: ZodFirstPartyTypeKind.ZodOptional,
3617
+ ...processCreateParams(params)
3618
+ });
3619
+ };
3620
+ class ZodNullable extends ZodType {
3621
+ _parse(input) {
3622
+ const parsedType = this._getType(input);
3623
+ if (parsedType === ZodParsedType.null) {
3624
+ return OK(null);
3625
+ }
3626
+ return this._def.innerType._parse(input);
3627
+ }
3628
+ unwrap() {
3629
+ return this._def.innerType;
3630
+ }
3631
+ }
3632
+ ZodNullable.create = (type, params) => {
3633
+ return new ZodNullable({
3634
+ innerType: type,
3635
+ typeName: ZodFirstPartyTypeKind.ZodNullable,
3636
+ ...processCreateParams(params)
3637
+ });
3638
+ };
3639
+ class ZodDefault extends ZodType {
3640
+ _parse(input) {
3641
+ const { ctx } = this._processInputParams(input);
3642
+ let data = ctx.data;
3643
+ if (ctx.parsedType === ZodParsedType.undefined) {
3644
+ data = this._def.defaultValue();
3645
+ }
3646
+ return this._def.innerType._parse({
3647
+ data,
3648
+ path: ctx.path,
3649
+ parent: ctx
3650
+ });
3651
+ }
3652
+ removeDefault() {
3653
+ return this._def.innerType;
3654
+ }
3655
+ }
3656
+ ZodDefault.create = (type, params) => {
3657
+ return new ZodDefault({
3658
+ innerType: type,
3659
+ typeName: ZodFirstPartyTypeKind.ZodDefault,
3660
+ defaultValue: typeof params.default === "function" ? params.default : () => params.default,
3661
+ ...processCreateParams(params)
3662
+ });
3663
+ };
3664
+ class ZodCatch extends ZodType {
3665
+ _parse(input) {
3666
+ const { ctx } = this._processInputParams(input);
3667
+ const newCtx = {
3668
+ ...ctx,
3669
+ common: {
3670
+ ...ctx.common,
3671
+ issues: []
3672
+ }
3673
+ };
3674
+ const result = this._def.innerType._parse({
3675
+ data: newCtx.data,
3676
+ path: newCtx.path,
3677
+ parent: {
3678
+ ...newCtx
3679
+ }
3680
+ });
3681
+ if (isAsync(result)) {
3682
+ return result.then((result2) => {
3683
+ return {
3684
+ status: "valid",
3685
+ value: result2.status === "valid" ? result2.value : this._def.catchValue({
3686
+ get error() {
3687
+ return new ZodError(newCtx.common.issues);
3688
+ },
3689
+ input: newCtx.data
3690
+ })
3691
+ };
3692
+ });
3693
+ } else {
3694
+ return {
3695
+ status: "valid",
3696
+ value: result.status === "valid" ? result.value : this._def.catchValue({
3697
+ get error() {
3698
+ return new ZodError(newCtx.common.issues);
3699
+ },
3700
+ input: newCtx.data
3701
+ })
3702
+ };
3703
+ }
3704
+ }
3705
+ removeCatch() {
3706
+ return this._def.innerType;
3707
+ }
3708
+ }
3709
+ ZodCatch.create = (type, params) => {
3710
+ return new ZodCatch({
3711
+ innerType: type,
3712
+ typeName: ZodFirstPartyTypeKind.ZodCatch,
3713
+ catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
3714
+ ...processCreateParams(params)
3715
+ });
3716
+ };
3717
+ class ZodNaN extends ZodType {
3718
+ _parse(input) {
3719
+ const parsedType = this._getType(input);
3720
+ if (parsedType !== ZodParsedType.nan) {
3721
+ const ctx = this._getOrReturnCtx(input);
3722
+ addIssueToContext(ctx, {
3723
+ code: ZodIssueCode.invalid_type,
3724
+ expected: ZodParsedType.nan,
3725
+ received: ctx.parsedType
3726
+ });
3727
+ return INVALID;
3728
+ }
3729
+ return { status: "valid", value: input.data };
3730
+ }
3731
+ }
3732
+ ZodNaN.create = (params) => {
3733
+ return new ZodNaN({
3734
+ typeName: ZodFirstPartyTypeKind.ZodNaN,
3735
+ ...processCreateParams(params)
3736
+ });
3737
+ };
3738
+ const BRAND = Symbol("zod_brand");
3739
+ class ZodBranded extends ZodType {
3740
+ _parse(input) {
3741
+ const { ctx } = this._processInputParams(input);
3742
+ const data = ctx.data;
3743
+ return this._def.type._parse({
3744
+ data,
3745
+ path: ctx.path,
3746
+ parent: ctx
3747
+ });
3748
+ }
3749
+ unwrap() {
3750
+ return this._def.type;
3751
+ }
3752
+ }
3753
+ class ZodPipeline extends ZodType {
3754
+ _parse(input) {
3755
+ const { status, ctx } = this._processInputParams(input);
3756
+ if (ctx.common.async) {
3757
+ const handleAsync = async () => {
3758
+ const inResult = await this._def.in._parseAsync({
3759
+ data: ctx.data,
3760
+ path: ctx.path,
3761
+ parent: ctx
3762
+ });
3763
+ if (inResult.status === "aborted")
3764
+ return INVALID;
3765
+ if (inResult.status === "dirty") {
3766
+ status.dirty();
3767
+ return DIRTY(inResult.value);
3768
+ } else {
3769
+ return this._def.out._parseAsync({
3770
+ data: inResult.value,
3771
+ path: ctx.path,
3772
+ parent: ctx
3773
+ });
3774
+ }
3775
+ };
3776
+ return handleAsync();
3777
+ } else {
3778
+ const inResult = this._def.in._parseSync({
3779
+ data: ctx.data,
3780
+ path: ctx.path,
3781
+ parent: ctx
3782
+ });
3783
+ if (inResult.status === "aborted")
3784
+ return INVALID;
3785
+ if (inResult.status === "dirty") {
3786
+ status.dirty();
3787
+ return {
3788
+ status: "dirty",
3789
+ value: inResult.value
3790
+ };
3791
+ } else {
3792
+ return this._def.out._parseSync({
3793
+ data: inResult.value,
3794
+ path: ctx.path,
3795
+ parent: ctx
3796
+ });
3797
+ }
3798
+ }
3799
+ }
3800
+ static create(a2, b2) {
3801
+ return new ZodPipeline({
3802
+ in: a2,
3803
+ out: b2,
3804
+ typeName: ZodFirstPartyTypeKind.ZodPipeline
3805
+ });
3806
+ }
3807
+ }
3808
+ class ZodReadonly extends ZodType {
3809
+ _parse(input) {
3810
+ const result = this._def.innerType._parse(input);
3811
+ const freeze = (data) => {
3812
+ if (isValid(data)) {
3813
+ data.value = Object.freeze(data.value);
3814
+ }
3815
+ return data;
3816
+ };
3817
+ return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
3818
+ }
3819
+ unwrap() {
3820
+ return this._def.innerType;
3821
+ }
3822
+ }
3823
+ ZodReadonly.create = (type, params) => {
3824
+ return new ZodReadonly({
3825
+ innerType: type,
3826
+ typeName: ZodFirstPartyTypeKind.ZodReadonly,
3827
+ ...processCreateParams(params)
3828
+ });
3829
+ };
3830
+ function cleanParams(params, data) {
3831
+ const p2 = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params;
3832
+ const p22 = typeof p2 === "string" ? { message: p2 } : p2;
3833
+ return p22;
3834
+ }
3835
+ function custom(check, _params = {}, fatal) {
3836
+ if (check)
3837
+ return ZodAny.create().superRefine((data, ctx) => {
3838
+ var _a, _b;
3839
+ const r2 = check(data);
3840
+ if (r2 instanceof Promise) {
3841
+ return r2.then((r3) => {
3842
+ var _a2, _b2;
3843
+ if (!r3) {
3844
+ const params = cleanParams(_params, data);
3845
+ const _fatal = (_b2 = (_a2 = params.fatal) !== null && _a2 !== void 0 ? _a2 : fatal) !== null && _b2 !== void 0 ? _b2 : true;
3846
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3847
+ }
3848
+ });
3849
+ }
3850
+ if (!r2) {
3851
+ const params = cleanParams(_params, data);
3852
+ const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
3853
+ ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
3854
+ }
3855
+ return;
3856
+ });
3857
+ return ZodAny.create();
3858
+ }
3859
+ const late = {
3860
+ object: ZodObject.lazycreate
3861
+ };
3862
+ var ZodFirstPartyTypeKind;
3863
+ (function(ZodFirstPartyTypeKind2) {
3864
+ ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
3865
+ ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
3866
+ ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
3867
+ ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
3868
+ ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
3869
+ ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
3870
+ ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
3871
+ ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
3872
+ ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
3873
+ ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
3874
+ ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
3875
+ ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
3876
+ ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
3877
+ ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
3878
+ ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
3879
+ ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
3880
+ ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
3881
+ ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
3882
+ ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
3883
+ ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
3884
+ ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
3885
+ ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
3886
+ ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
3887
+ ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
3888
+ ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
3889
+ ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
3890
+ ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
3891
+ ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
3892
+ ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
3893
+ ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
3894
+ ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
3895
+ ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
3896
+ ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
3897
+ ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
3898
+ ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
3899
+ ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
3900
+ })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
3901
+ const instanceOfType = (cls, params = {
3902
+ message: `Input not instance of ${cls.name}`
3903
+ }) => custom((data) => data instanceof cls, params);
3904
+ const stringType = ZodString.create;
3905
+ const numberType = ZodNumber.create;
3906
+ const nanType = ZodNaN.create;
3907
+ const bigIntType = ZodBigInt.create;
3908
+ const booleanType = ZodBoolean.create;
3909
+ const dateType = ZodDate.create;
3910
+ const symbolType = ZodSymbol.create;
3911
+ const undefinedType = ZodUndefined.create;
3912
+ const nullType = ZodNull.create;
3913
+ const anyType = ZodAny.create;
3914
+ const unknownType = ZodUnknown.create;
3915
+ const neverType = ZodNever.create;
3916
+ const voidType = ZodVoid.create;
3917
+ const arrayType = ZodArray.create;
3918
+ const objectType = ZodObject.create;
3919
+ const strictObjectType = ZodObject.strictCreate;
3920
+ const unionType = ZodUnion.create;
3921
+ const discriminatedUnionType = ZodDiscriminatedUnion.create;
3922
+ const intersectionType = ZodIntersection.create;
3923
+ const tupleType = ZodTuple.create;
3924
+ const recordType = ZodRecord.create;
3925
+ const mapType = ZodMap.create;
3926
+ const setType = ZodSet.create;
3927
+ const functionType = ZodFunction.create;
3928
+ const lazyType = ZodLazy.create;
3929
+ const literalType = ZodLiteral.create;
3930
+ const enumType = ZodEnum.create;
3931
+ const nativeEnumType = ZodNativeEnum.create;
3932
+ const promiseType = ZodPromise.create;
3933
+ const effectsType = ZodEffects.create;
3934
+ const optionalType = ZodOptional.create;
3935
+ const nullableType = ZodNullable.create;
3936
+ const preprocessType = ZodEffects.createWithPreprocess;
3937
+ const pipelineType = ZodPipeline.create;
3938
+ const ostring = () => stringType().optional();
3939
+ const onumber = () => numberType().optional();
3940
+ const oboolean = () => booleanType().optional();
3941
+ const coerce = {
3942
+ string: (arg) => ZodString.create({ ...arg, coerce: true }),
3943
+ number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
3944
+ boolean: (arg) => ZodBoolean.create({
3945
+ ...arg,
3946
+ coerce: true
3947
+ }),
3948
+ bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
3949
+ date: (arg) => ZodDate.create({ ...arg, coerce: true })
3950
+ };
3951
+ const NEVER = INVALID;
3952
+ var z$1 = /* @__PURE__ */ Object.freeze({
3953
+ __proto__: null,
3954
+ defaultErrorMap: errorMap,
3955
+ setErrorMap,
3956
+ getErrorMap,
3957
+ makeIssue,
3958
+ EMPTY_PATH,
3959
+ addIssueToContext,
3960
+ ParseStatus,
3961
+ INVALID,
3962
+ DIRTY,
3963
+ OK,
3964
+ isAborted,
3965
+ isDirty,
3966
+ isValid,
3967
+ isAsync,
3968
+ get util() {
3969
+ return util;
3970
+ },
3971
+ get objectUtil() {
3972
+ return objectUtil;
3973
+ },
3974
+ ZodParsedType,
3975
+ getParsedType,
3976
+ ZodType,
3977
+ datetimeRegex,
3978
+ ZodString,
3979
+ ZodNumber,
3980
+ ZodBigInt,
3981
+ ZodBoolean,
3982
+ ZodDate,
3983
+ ZodSymbol,
3984
+ ZodUndefined,
3985
+ ZodNull,
3986
+ ZodAny,
3987
+ ZodUnknown,
3988
+ ZodNever,
3989
+ ZodVoid,
3990
+ ZodArray,
3991
+ ZodObject,
3992
+ ZodUnion,
3993
+ ZodDiscriminatedUnion,
3994
+ ZodIntersection,
3995
+ ZodTuple,
3996
+ ZodRecord,
3997
+ ZodMap,
3998
+ ZodSet,
3999
+ ZodFunction,
4000
+ ZodLazy,
4001
+ ZodLiteral,
4002
+ ZodEnum,
4003
+ ZodNativeEnum,
4004
+ ZodPromise,
4005
+ ZodEffects,
4006
+ ZodTransformer: ZodEffects,
4007
+ ZodOptional,
4008
+ ZodNullable,
4009
+ ZodDefault,
4010
+ ZodCatch,
4011
+ ZodNaN,
4012
+ BRAND,
4013
+ ZodBranded,
4014
+ ZodPipeline,
4015
+ ZodReadonly,
4016
+ custom,
4017
+ Schema: ZodType,
4018
+ ZodSchema: ZodType,
4019
+ late,
4020
+ get ZodFirstPartyTypeKind() {
4021
+ return ZodFirstPartyTypeKind;
4022
+ },
4023
+ coerce,
4024
+ any: anyType,
4025
+ array: arrayType,
4026
+ bigint: bigIntType,
4027
+ boolean: booleanType,
4028
+ date: dateType,
4029
+ discriminatedUnion: discriminatedUnionType,
4030
+ effect: effectsType,
4031
+ "enum": enumType,
4032
+ "function": functionType,
4033
+ "instanceof": instanceOfType,
4034
+ intersection: intersectionType,
4035
+ lazy: lazyType,
4036
+ literal: literalType,
4037
+ map: mapType,
4038
+ nan: nanType,
4039
+ nativeEnum: nativeEnumType,
4040
+ never: neverType,
4041
+ "null": nullType,
4042
+ nullable: nullableType,
4043
+ number: numberType,
4044
+ object: objectType,
4045
+ oboolean,
4046
+ onumber,
4047
+ optional: optionalType,
4048
+ ostring,
4049
+ pipeline: pipelineType,
4050
+ preprocess: preprocessType,
4051
+ promise: promiseType,
4052
+ record: recordType,
4053
+ set: setType,
4054
+ strictObject: strictObjectType,
4055
+ string: stringType,
4056
+ symbol: symbolType,
4057
+ transformer: effectsType,
4058
+ tuple: tupleType,
4059
+ "undefined": undefinedType,
4060
+ union: unionType,
4061
+ unknown: unknownType,
4062
+ "void": voidType,
4063
+ NEVER,
4064
+ ZodIssueCode,
4065
+ quotelessJson,
4066
+ ZodError
4067
+ });
4068
+ const ObiSDKConfigSchema = z$1.object({
4069
+ apiKey: z$1.string().optional(),
4070
+ baseUrl: z$1.string().default("https://iamobi.ai/api"),
4071
+ enableVoice: z$1.boolean().default(true),
4072
+ enableScreenCapture: z$1.boolean().default(true),
4073
+ debug: z$1.boolean().default(false)
4074
+ });
4075
+ var EventType = /* @__PURE__ */ ((EventType2) => {
4076
+ EventType2["READY"] = "ready";
4077
+ EventType2["ERROR"] = "error";
4078
+ EventType2["VOICE_START"] = "voice:start";
4079
+ EventType2["VOICE_STOP"] = "voice:stop";
4080
+ EventType2["SCREEN_CAPTURE_START"] = "screen:start";
4081
+ EventType2["SCREEN_CAPTURE_STOP"] = "screen:stop";
4082
+ EventType2["STATE_CHANGE"] = "state:change";
4083
+ return EventType2;
4084
+ })(EventType || {});
4085
+ var SDKState = /* @__PURE__ */ ((SDKState2) => {
4086
+ SDKState2["READY"] = "ready";
4087
+ SDKState2["ERROR"] = "error";
4088
+ SDKState2["PAUSED"] = "paused";
4089
+ SDKState2["LOADING"] = "loading";
4090
+ SDKState2["THINKING"] = "thinking";
4091
+ SDKState2["RESEARCHING"] = "researching";
4092
+ SDKState2["AGENT_SPEAKING"] = "agent_speaking";
4093
+ SDKState2["USER_SPEAKING"] = "user_speaking";
4094
+ SDKState2["AWAITING_USER_INPUT"] = "awaiting_user_input";
4095
+ return SDKState2;
4096
+ })(SDKState || {});
4097
+ const t = Symbol.for("@ts-pattern/matcher"), e = Symbol.for("@ts-pattern/isVariadic"), n = "@ts-pattern/anonymous-select-key", r = (t2) => Boolean(t2 && "object" == typeof t2), i = (e2) => e2 && !!e2[t], o = (n2, s2, c2) => {
4098
+ if (i(n2)) {
4099
+ const e2 = n2[t](), { matched: r2, selections: i2 } = e2.match(s2);
4100
+ return r2 && i2 && Object.keys(i2).forEach((t2) => c2(t2, i2[t2])), r2;
4101
+ }
4102
+ if (r(n2)) {
4103
+ if (!r(s2))
4104
+ return false;
4105
+ if (Array.isArray(n2)) {
4106
+ if (!Array.isArray(s2))
4107
+ return false;
4108
+ let t2 = [], r2 = [], a2 = [];
4109
+ for (const o2 of n2.keys()) {
4110
+ const s3 = n2[o2];
4111
+ i(s3) && s3[e] ? a2.push(s3) : a2.length ? r2.push(s3) : t2.push(s3);
4112
+ }
4113
+ if (a2.length) {
4114
+ if (a2.length > 1)
4115
+ throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
4116
+ if (s2.length < t2.length + r2.length)
4117
+ return false;
4118
+ const e2 = s2.slice(0, t2.length), n3 = 0 === r2.length ? [] : s2.slice(-r2.length), i2 = s2.slice(t2.length, 0 === r2.length ? Infinity : -r2.length);
4119
+ return t2.every((t3, n4) => o(t3, e2[n4], c2)) && r2.every((t3, e3) => o(t3, n3[e3], c2)) && (0 === a2.length || o(a2[0], i2, c2));
4120
+ }
4121
+ return n2.length === s2.length && n2.every((t3, e2) => o(t3, s2[e2], c2));
4122
+ }
4123
+ return Reflect.ownKeys(n2).every((e2) => {
4124
+ const r2 = n2[e2];
4125
+ return (e2 in s2 || i(a2 = r2) && "optional" === a2[t]().matcherType) && o(r2, s2[e2], c2);
4126
+ var a2;
4127
+ });
4128
+ }
4129
+ return Object.is(s2, n2);
4130
+ }, s = (e2) => {
4131
+ var n2, o2, a2;
4132
+ return r(e2) ? i(e2) ? null != (n2 = null == (o2 = (a2 = e2[t]()).getSelectionKeys) ? void 0 : o2.call(a2)) ? n2 : [] : Array.isArray(e2) ? c(e2, s) : c(Object.values(e2), s) : [];
4133
+ }, c = (t2, e2) => t2.reduce((t3, n2) => t3.concat(e2(n2)), []);
4134
+ function a(...t2) {
4135
+ if (1 === t2.length) {
4136
+ const [e2] = t2;
4137
+ return (t3) => o(e2, t3, () => {
4138
+ });
4139
+ }
4140
+ if (2 === t2.length) {
4141
+ const [e2, n2] = t2;
4142
+ return o(e2, n2, () => {
4143
+ });
4144
+ }
4145
+ throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t2.length}.`);
4146
+ }
4147
+ function u(t2) {
4148
+ return Object.assign(t2, { optional: () => h(t2), and: (e2) => m(t2, e2), or: (e2) => d(t2, e2), select: (e2) => void 0 === e2 ? y(t2) : y(e2, t2) });
4149
+ }
4150
+ function l(t2) {
4151
+ return Object.assign(((t3) => Object.assign(t3, { [Symbol.iterator]() {
4152
+ let n2 = 0;
4153
+ const r2 = [{ value: Object.assign(t3, { [e]: true }), done: false }, { done: true, value: void 0 }];
4154
+ return { next: () => {
4155
+ var t4;
4156
+ return null != (t4 = r2[n2++]) ? t4 : r2.at(-1);
4157
+ } };
4158
+ } }))(t2), { optional: () => l(h(t2)), select: (e2) => l(void 0 === e2 ? y(t2) : y(e2, t2)) });
4159
+ }
4160
+ function h(e2) {
4161
+ return u({ [t]: () => ({ match: (t2) => {
4162
+ let n2 = {};
4163
+ const r2 = (t3, e3) => {
4164
+ n2[t3] = e3;
4165
+ };
4166
+ return void 0 === t2 ? (s(e2).forEach((t3) => r2(t3, void 0)), { matched: true, selections: n2 }) : { matched: o(e2, t2, r2), selections: n2 };
4167
+ }, getSelectionKeys: () => s(e2), matcherType: "optional" }) });
4168
+ }
4169
+ const f = (t2, e2) => {
4170
+ for (const n2 of t2)
4171
+ if (!e2(n2))
4172
+ return false;
4173
+ return true;
4174
+ }, g = (t2, e2) => {
4175
+ for (const [n2, r2] of t2.entries())
4176
+ if (!e2(r2, n2))
4177
+ return false;
4178
+ return true;
4179
+ };
4180
+ function m(...e2) {
4181
+ return u({ [t]: () => ({ match: (t2) => {
4182
+ let n2 = {};
4183
+ const r2 = (t3, e3) => {
4184
+ n2[t3] = e3;
4185
+ };
4186
+ return { matched: e2.every((e3) => o(e3, t2, r2)), selections: n2 };
4187
+ }, getSelectionKeys: () => c(e2, s), matcherType: "and" }) });
4188
+ }
4189
+ function d(...e2) {
4190
+ return u({ [t]: () => ({ match: (t2) => {
4191
+ let n2 = {};
4192
+ const r2 = (t3, e3) => {
4193
+ n2[t3] = e3;
4194
+ };
4195
+ return c(e2, s).forEach((t3) => r2(t3, void 0)), { matched: e2.some((e3) => o(e3, t2, r2)), selections: n2 };
4196
+ }, getSelectionKeys: () => c(e2, s), matcherType: "or" }) });
4197
+ }
4198
+ function p(e2) {
4199
+ return { [t]: () => ({ match: (t2) => ({ matched: Boolean(e2(t2)) }) }) };
4200
+ }
4201
+ function y(...e2) {
4202
+ const r2 = "string" == typeof e2[0] ? e2[0] : void 0, i2 = 2 === e2.length ? e2[1] : "string" == typeof e2[0] ? void 0 : e2[0];
4203
+ return u({ [t]: () => ({ match: (t2) => {
4204
+ let e3 = { [null != r2 ? r2 : n]: t2 };
4205
+ return { matched: void 0 === i2 || o(i2, t2, (t3, n2) => {
4206
+ e3[t3] = n2;
4207
+ }), selections: e3 };
4208
+ }, getSelectionKeys: () => [null != r2 ? r2 : n].concat(void 0 === i2 ? [] : s(i2)) }) });
4209
+ }
4210
+ function v(t2) {
4211
+ return "number" == typeof t2;
4212
+ }
4213
+ function b(t2) {
4214
+ return "string" == typeof t2;
4215
+ }
4216
+ function w(t2) {
4217
+ return "bigint" == typeof t2;
4218
+ }
4219
+ const S = u(p(function(t2) {
4220
+ return true;
4221
+ })), O = S, j = (t2) => Object.assign(u(t2), { startsWith: (e2) => {
4222
+ return j(m(t2, (n2 = e2, p((t3) => b(t3) && t3.startsWith(n2)))));
4223
+ var n2;
4224
+ }, endsWith: (e2) => {
4225
+ return j(m(t2, (n2 = e2, p((t3) => b(t3) && t3.endsWith(n2)))));
4226
+ var n2;
4227
+ }, minLength: (e2) => j(m(t2, ((t3) => p((e3) => b(e3) && e3.length >= t3))(e2))), length: (e2) => j(m(t2, ((t3) => p((e3) => b(e3) && e3.length === t3))(e2))), maxLength: (e2) => j(m(t2, ((t3) => p((e3) => b(e3) && e3.length <= t3))(e2))), includes: (e2) => {
4228
+ return j(m(t2, (n2 = e2, p((t3) => b(t3) && t3.includes(n2)))));
4229
+ var n2;
4230
+ }, regex: (e2) => {
4231
+ return j(m(t2, (n2 = e2, p((t3) => b(t3) && Boolean(t3.match(n2))))));
4232
+ var n2;
4233
+ } }), K = j(p(b)), x = (t2) => Object.assign(u(t2), { between: (e2, n2) => x(m(t2, ((t3, e3) => p((n3) => v(n3) && t3 <= n3 && e3 >= n3))(e2, n2))), lt: (e2) => x(m(t2, ((t3) => p((e3) => v(e3) && e3 < t3))(e2))), gt: (e2) => x(m(t2, ((t3) => p((e3) => v(e3) && e3 > t3))(e2))), lte: (e2) => x(m(t2, ((t3) => p((e3) => v(e3) && e3 <= t3))(e2))), gte: (e2) => x(m(t2, ((t3) => p((e3) => v(e3) && e3 >= t3))(e2))), int: () => x(m(t2, p((t3) => v(t3) && Number.isInteger(t3)))), finite: () => x(m(t2, p((t3) => v(t3) && Number.isFinite(t3)))), positive: () => x(m(t2, p((t3) => v(t3) && t3 > 0))), negative: () => x(m(t2, p((t3) => v(t3) && t3 < 0))) }), E = x(p(v)), A = (t2) => Object.assign(u(t2), { between: (e2, n2) => A(m(t2, ((t3, e3) => p((n3) => w(n3) && t3 <= n3 && e3 >= n3))(e2, n2))), lt: (e2) => A(m(t2, ((t3) => p((e3) => w(e3) && e3 < t3))(e2))), gt: (e2) => A(m(t2, ((t3) => p((e3) => w(e3) && e3 > t3))(e2))), lte: (e2) => A(m(t2, ((t3) => p((e3) => w(e3) && e3 <= t3))(e2))), gte: (e2) => A(m(t2, ((t3) => p((e3) => w(e3) && e3 >= t3))(e2))), positive: () => A(m(t2, p((t3) => w(t3) && t3 > 0))), negative: () => A(m(t2, p((t3) => w(t3) && t3 < 0))) }), P = A(p(w)), T = u(p(function(t2) {
4234
+ return "boolean" == typeof t2;
4235
+ })), B = u(p(function(t2) {
4236
+ return "symbol" == typeof t2;
4237
+ })), _ = u(p(function(t2) {
4238
+ return null == t2;
4239
+ })), k = u(p(function(t2) {
4240
+ return null != t2;
4241
+ }));
4242
+ var N = { __proto__: null, matcher: t, optional: h, array: function(...e2) {
4243
+ return l({ [t]: () => ({ match: (t2) => {
4244
+ if (!Array.isArray(t2))
4245
+ return { matched: false };
4246
+ if (0 === e2.length)
4247
+ return { matched: true };
4248
+ const n2 = e2[0];
4249
+ let r2 = {};
4250
+ if (0 === t2.length)
4251
+ return s(n2).forEach((t3) => {
4252
+ r2[t3] = [];
4253
+ }), { matched: true, selections: r2 };
4254
+ const i2 = (t3, e3) => {
4255
+ r2[t3] = (r2[t3] || []).concat([e3]);
4256
+ };
4257
+ return { matched: t2.every((t3) => o(n2, t3, i2)), selections: r2 };
4258
+ }, getSelectionKeys: () => 0 === e2.length ? [] : s(e2[0]) }) });
4259
+ }, set: function(...e2) {
4260
+ return u({ [t]: () => ({ match: (t2) => {
4261
+ if (!(t2 instanceof Set))
4262
+ return { matched: false };
4263
+ let n2 = {};
4264
+ if (0 === t2.size)
4265
+ return { matched: true, selections: n2 };
4266
+ if (0 === e2.length)
4267
+ return { matched: true };
4268
+ const r2 = (t3, e3) => {
4269
+ n2[t3] = (n2[t3] || []).concat([e3]);
4270
+ }, i2 = e2[0];
4271
+ return { matched: f(t2, (t3) => o(i2, t3, r2)), selections: n2 };
4272
+ }, getSelectionKeys: () => 0 === e2.length ? [] : s(e2[0]) }) });
4273
+ }, map: function(...e2) {
4274
+ return u({ [t]: () => ({ match: (t2) => {
4275
+ if (!(t2 instanceof Map))
4276
+ return { matched: false };
4277
+ let n2 = {};
4278
+ if (0 === t2.size)
4279
+ return { matched: true, selections: n2 };
4280
+ const r2 = (t3, e3) => {
4281
+ n2[t3] = (n2[t3] || []).concat([e3]);
4282
+ };
4283
+ if (0 === e2.length)
4284
+ return { matched: true };
4285
+ var i2;
4286
+ if (1 === e2.length)
4287
+ throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${null == (i2 = e2[0]) ? void 0 : i2.toString()}`);
4288
+ const [s2, c2] = e2;
4289
+ return { matched: g(t2, (t3, e3) => {
4290
+ const n3 = o(s2, e3, r2), i3 = o(c2, t3, r2);
4291
+ return n3 && i3;
4292
+ }), selections: n2 };
4293
+ }, getSelectionKeys: () => 0 === e2.length ? [] : [...s(e2[0]), ...s(e2[1])] }) });
4294
+ }, intersection: m, union: d, not: function(e2) {
4295
+ return u({ [t]: () => ({ match: (t2) => ({ matched: !o(e2, t2, () => {
4296
+ }) }), getSelectionKeys: () => [], matcherType: "not" }) });
4297
+ }, when: p, select: y, any: S, _: O, string: K, number: E, bigint: P, boolean: T, symbol: B, nullish: _, nonNullable: k, instanceOf: function(t2) {
4298
+ return u(p(function(t3) {
4299
+ return (e2) => e2 instanceof t3;
4300
+ }(t2)));
4301
+ }, shape: function(t2) {
4302
+ return u(p(a(t2)));
4303
+ } };
4304
+ class W extends Error {
4305
+ constructor(t2) {
4306
+ let e2;
4307
+ try {
4308
+ e2 = JSON.stringify(t2);
4309
+ } catch (n2) {
4310
+ e2 = t2;
4311
+ }
4312
+ super(`Pattern matching error: no pattern matches value ${e2}`), this.input = void 0, this.input = t2;
4313
+ }
4314
+ }
4315
+ const $ = { matched: false, value: void 0 };
4316
+ function z(t2) {
4317
+ return new I(t2, $);
4318
+ }
4319
+ class I {
4320
+ constructor(t2, e2) {
4321
+ this.input = void 0, this.state = void 0, this.input = t2, this.state = e2;
4322
+ }
4323
+ with(...t2) {
4324
+ if (this.state.matched)
4325
+ return this;
4326
+ const e2 = t2[t2.length - 1], r2 = [t2[0]];
4327
+ let i2;
4328
+ 3 === t2.length && "function" == typeof t2[1] ? i2 = t2[1] : t2.length > 2 && r2.push(...t2.slice(1, t2.length - 1));
4329
+ let s2 = false, c2 = {};
4330
+ const a2 = (t3, e3) => {
4331
+ s2 = true, c2[t3] = e3;
4332
+ }, u2 = !r2.some((t3) => o(t3, this.input, a2)) || i2 && !Boolean(i2(this.input)) ? $ : { matched: true, value: e2(s2 ? n in c2 ? c2[n] : c2 : this.input, this.input) };
4333
+ return new I(this.input, u2);
4334
+ }
4335
+ when(t2, e2) {
4336
+ if (this.state.matched)
4337
+ return this;
4338
+ const n2 = Boolean(t2(this.input));
4339
+ return new I(this.input, n2 ? { matched: true, value: e2(this.input, this.input) } : $);
4340
+ }
4341
+ otherwise(t2) {
4342
+ return this.state.matched ? this.state.value : t2(this.input);
4343
+ }
4344
+ exhaustive(t2 = L) {
4345
+ return this.state.matched ? this.state.value : t2(this.input);
4346
+ }
4347
+ run() {
4348
+ return this.exhaustive();
4349
+ }
4350
+ returnType() {
4351
+ return this;
4352
+ }
4353
+ }
4354
+ function L(t2) {
4355
+ throw new W(t2);
4356
+ }
4357
+ export {
4358
+ EventType as E,
4359
+ N,
4360
+ ObiSDKConfigSchema as O,
4361
+ SDKState as S,
4362
+ z
4363
+ };
4364
+ //# sourceMappingURL=index-634e0df5.js.map