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