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