@spscommerce/asst-api 0.0.1-beta.9 → 0.0.1

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