@kitschpatrol/create-project 1.0.0

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