@byteplus-iga-pages/agent 0.0.0-stage → 1.0.4

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