@liquidmetal-ai/raindrop 0.13.0 → 0.15.0

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