@liquidmetal-ai/raindrop 0.9.0 → 0.9.1

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