cvx-kit 0.2.0 → 2.0.0-beta.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 (372) hide show
  1. package/README.md +556 -99
  2. package/dist/agent-tools.d.mts +39 -26
  3. package/dist/agent-tools.mjs +1 -1
  4. package/dist/agent-tools.mjs.map +1 -1
  5. package/dist/auth.d.mts +120 -308
  6. package/dist/auth.mjs +1 -1
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/components/approvals/_generated/api.d.mts +7 -9
  9. package/dist/components/approvals/_generated/api.mjs.map +1 -1
  10. package/dist/components/approvals/_generated/component.d.mts +1 -4
  11. package/dist/components/approvals/_generated/dataModel.d.mts +5 -8
  12. package/dist/components/approvals/_generated/server.d.mts +12 -15
  13. package/dist/components/approvals/_generated/server.mjs.map +1 -1
  14. package/dist/components/approvals/audit.d.mts +8 -9
  15. package/dist/components/approvals/audit.mjs +1 -1
  16. package/dist/components/approvals/audit.mjs.map +1 -1
  17. package/dist/components/approvals/client.d.mts +11 -12
  18. package/dist/components/approvals/client.mjs +1 -1
  19. package/dist/components/approvals/client.mjs.map +1 -1
  20. package/dist/components/approvals/constants.d.mts +30 -31
  21. package/dist/components/approvals/constants.mjs.map +1 -1
  22. package/dist/components/approvals/convex.config.d.mts +0 -2
  23. package/dist/components/approvals/convex.config.mjs.map +1 -1
  24. package/dist/components/approvals/decisions.d.mts +13 -17
  25. package/dist/components/approvals/decisions.mjs +1 -1
  26. package/dist/components/approvals/decisions.mjs.map +1 -1
  27. package/dist/components/approvals/functions.d.mts +3 -4
  28. package/dist/components/approvals/functions.mjs +1 -1
  29. package/dist/components/approvals/functions.mjs.map +1 -1
  30. package/dist/components/approvals/health.d.mts +2 -3
  31. package/dist/components/approvals/health.mjs.map +1 -1
  32. package/dist/components/approvals/requests.d.mts +114 -131
  33. package/dist/components/approvals/requests.mjs +1 -1
  34. package/dist/components/approvals/requests.mjs.map +1 -1
  35. package/dist/components/approvals/schema.d.ts +106 -315
  36. package/dist/components/approvals/schema.js +1 -1
  37. package/dist/components/approvals/validators.d.mts +323 -395
  38. package/dist/components/approvals/validators.mjs +1 -1
  39. package/dist/components/approvals/validators.mjs.map +1 -1
  40. package/dist/components/approvals/workflow.d.mts +4 -5
  41. package/dist/components/approvals/workflow.mjs +1 -1
  42. package/dist/components/approvals/workflow.mjs.map +1 -1
  43. package/dist/components/approvals/workflow_steps.d.mts +16 -17
  44. package/dist/components/approvals/workflow_steps.mjs +1 -1
  45. package/dist/components/approvals/workflow_steps.mjs.map +1 -1
  46. package/dist/components/foundation/_generated/api.d.mts +6 -8
  47. package/dist/components/foundation/_generated/api.mjs.map +1 -1
  48. package/dist/components/foundation/_generated/component.d.mts +1 -4
  49. package/dist/components/foundation/_generated/dataModel.d.mts +5 -8
  50. package/dist/components/foundation/_generated/server.d.mts +12 -15
  51. package/dist/components/foundation/_generated/server.mjs.map +1 -1
  52. package/dist/components/foundation/client.d.mts +45 -38
  53. package/dist/components/foundation/client.mjs +1 -1
  54. package/dist/components/foundation/client.mjs.map +1 -1
  55. package/dist/components/foundation/convex.config.d.mts +0 -2
  56. package/dist/components/foundation/convex.config.mjs.map +1 -1
  57. package/dist/components/foundation/functions.d.mts +2 -3
  58. package/dist/components/foundation/functions.mjs.map +1 -1
  59. package/dist/components/foundation/modules/command/command.d.mts +65 -17
  60. package/dist/components/foundation/modules/command/command.mjs +1 -1
  61. package/dist/components/foundation/modules/command/command.mjs.map +1 -1
  62. package/dist/components/foundation/modules/command/lifecycle.d.mts +78 -0
  63. package/dist/components/foundation/modules/command/lifecycle.mjs +2 -0
  64. package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -0
  65. package/dist/components/foundation/modules/observability/observability.d.mts +13 -6
  66. package/dist/components/foundation/modules/observability/observability.mjs +1 -1
  67. package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
  68. package/dist/components/foundation/modules/query/query.d.mts +11 -12
  69. package/dist/components/foundation/modules/query/query.mjs +1 -1
  70. package/dist/components/foundation/modules/query/query.mjs.map +1 -1
  71. package/dist/components/foundation/operation.d.mts +72 -0
  72. package/dist/components/foundation/operation.mjs +2 -0
  73. package/dist/components/foundation/operation.mjs.map +1 -0
  74. package/dist/components/foundation/result.d.mts +7 -8
  75. package/dist/components/foundation/result.mjs.map +1 -1
  76. package/dist/components/foundation/schema.d.ts +0 -2
  77. package/dist/components/foundation/telemetry.d.mts +2 -3
  78. package/dist/components/foundation/telemetry.mjs +1 -1
  79. package/dist/components/foundation/telemetry.mjs.map +1 -1
  80. package/dist/contracts.d.mts +5 -0
  81. package/dist/contracts.mjs +1 -0
  82. package/dist/crud.d.mts +185 -27
  83. package/dist/crud.mjs +1 -1
  84. package/dist/crud.mjs.map +1 -1
  85. package/dist/effect.d.mts +16 -0
  86. package/dist/effect.mjs +1 -0
  87. package/dist/errors.d.mts +6 -6
  88. package/dist/errors.mjs +1 -1
  89. package/dist/errors.mjs.map +1 -1
  90. package/dist/filters.d.mts +4 -0
  91. package/dist/filters.mjs +1 -0
  92. package/dist/idempotency.d.mts +2 -0
  93. package/dist/idempotency.mjs +1 -0
  94. package/dist/index.d.mts +14 -7
  95. package/dist/index.mjs +1 -1
  96. package/dist/json-schema.d.mts +40 -0
  97. package/dist/json-schema.mjs +2 -0
  98. package/dist/json-schema.mjs.map +1 -0
  99. package/dist/k/compile.d.mts +17 -0
  100. package/dist/k/compile.mjs +2 -0
  101. package/dist/k/compile.mjs.map +1 -0
  102. package/dist/k/dates.d.mts +23 -0
  103. package/dist/k/dates.mjs +2 -0
  104. package/dist/k/dates.mjs.map +1 -0
  105. package/dist/k/formats.d.mts +24 -0
  106. package/dist/k/formats.mjs +2 -0
  107. package/dist/k/formats.mjs.map +1 -0
  108. package/dist/k/index.d.mts +32 -0
  109. package/dist/k/index.mjs +2 -0
  110. package/dist/k/index.mjs.map +1 -0
  111. package/dist/k/issues.d.mts +31 -0
  112. package/dist/k/issues.mjs +2 -0
  113. package/dist/k/issues.mjs.map +1 -0
  114. package/dist/k/kinds.d.mts +81 -0
  115. package/dist/k/kinds.mjs +2 -0
  116. package/dist/k/kinds.mjs.map +1 -0
  117. package/dist/k/object.d.mts +43 -0
  118. package/dist/k/object.mjs +2 -0
  119. package/dist/k/object.mjs.map +1 -0
  120. package/dist/k/parse.d.mts +29 -0
  121. package/dist/k/parse.mjs +2 -0
  122. package/dist/k/parse.mjs.map +1 -0
  123. package/dist/k/schema.d.mts +100 -0
  124. package/dist/k/schema.mjs +2 -0
  125. package/dist/k/schema.mjs.map +1 -0
  126. package/dist/k/standard.d.mts +8 -0
  127. package/dist/k/standard.mjs +2 -0
  128. package/dist/k/standard.mjs.map +1 -0
  129. package/dist/k/types.d.mts +64 -0
  130. package/dist/k/types.mjs +1 -0
  131. package/dist/k.d.mts +8 -0
  132. package/dist/k.mjs +1 -0
  133. package/dist/middleware.d.mts +8 -11
  134. package/dist/middleware.mjs +1 -1
  135. package/dist/middleware.mjs.map +1 -1
  136. package/dist/modules/contracts/binding.d.mts +23 -0
  137. package/dist/modules/contracts/binding.mjs +2 -0
  138. package/dist/modules/contracts/binding.mjs.map +1 -0
  139. package/dist/modules/contracts/contract.d.mts +67 -0
  140. package/dist/modules/contracts/contract.mjs +2 -0
  141. package/dist/modules/contracts/contract.mjs.map +1 -0
  142. package/dist/modules/contracts/convex.d.mts +18 -0
  143. package/dist/modules/contracts/convex.mjs +2 -0
  144. package/dist/modules/contracts/convex.mjs.map +1 -0
  145. package/dist/modules/contracts/domain.d.mts +62 -0
  146. package/dist/modules/contracts/domain.mjs +2 -0
  147. package/dist/modules/contracts/domain.mjs.map +1 -0
  148. package/dist/modules/contracts/errors.d.mts +737 -0
  149. package/dist/modules/contracts/errors.mjs +2 -0
  150. package/dist/modules/contracts/errors.mjs.map +1 -0
  151. package/dist/modules/contracts/exposure.d.mts +103 -0
  152. package/dist/modules/contracts/exposure.mjs +2 -0
  153. package/dist/modules/contracts/exposure.mjs.map +1 -0
  154. package/dist/modules/contracts/idempotency.d.mts +85 -0
  155. package/dist/modules/contracts/idempotency.mjs +2 -0
  156. package/dist/modules/contracts/idempotency.mjs.map +1 -0
  157. package/dist/modules/contracts/lazy.d.mts +6 -0
  158. package/dist/modules/contracts/lazy.mjs +2 -0
  159. package/dist/modules/contracts/lazy.mjs.map +1 -0
  160. package/dist/modules/contracts/standard.d.mts +17 -0
  161. package/dist/modules/contracts/standard.mjs +2 -0
  162. package/dist/modules/contracts/standard.mjs.map +1 -0
  163. package/dist/modules/contracts/workflow.d.mts +165 -0
  164. package/dist/modules/contracts/workflow.mjs +2 -0
  165. package/dist/modules/contracts/workflow.mjs.map +1 -0
  166. package/dist/modules/effect/action.d.mts +63 -0
  167. package/dist/modules/effect/action.mjs +2 -0
  168. package/dist/modules/effect/action.mjs.map +1 -0
  169. package/dist/modules/effect/agent-tools.d.mts +2 -0
  170. package/dist/modules/effect/agent-tools.mjs +1 -0
  171. package/dist/modules/effect/api-runtime.d.mts +36 -0
  172. package/dist/modules/effect/api-runtime.mjs +2 -0
  173. package/dist/modules/effect/api-runtime.mjs.map +1 -0
  174. package/dist/modules/effect/api.d.mts +46 -0
  175. package/dist/modules/effect/api.mjs +2 -0
  176. package/dist/modules/effect/api.mjs.map +1 -0
  177. package/dist/modules/effect/auth.d.mts +46 -0
  178. package/dist/modules/effect/auth.mjs +2 -0
  179. package/dist/modules/effect/auth.mjs.map +1 -0
  180. package/dist/modules/effect/client.d.mts +15 -0
  181. package/dist/modules/effect/client.mjs +1 -0
  182. package/dist/modules/effect/command.d.mts +108 -0
  183. package/dist/modules/effect/command.mjs +2 -0
  184. package/dist/modules/effect/command.mjs.map +1 -0
  185. package/dist/modules/effect/crud.d.mts +885 -0
  186. package/dist/modules/effect/crud.mjs +2 -0
  187. package/dist/modules/effect/crud.mjs.map +1 -0
  188. package/dist/modules/effect/domain.d.mts +82 -0
  189. package/dist/modules/effect/domain.mjs +2 -0
  190. package/dist/modules/effect/domain.mjs.map +1 -0
  191. package/dist/modules/effect/errors.d.mts +13 -0
  192. package/dist/modules/effect/errors.mjs +2 -0
  193. package/dist/modules/effect/errors.mjs.map +1 -0
  194. package/dist/modules/effect/failure-audit.d.mts +48 -0
  195. package/dist/modules/effect/failure-audit.mjs +2 -0
  196. package/dist/modules/effect/failure-audit.mjs.map +1 -0
  197. package/dist/modules/effect/failures.d.mts +21 -0
  198. package/dist/modules/effect/failures.mjs +2 -0
  199. package/dist/modules/effect/failures.mjs.map +1 -0
  200. package/dist/modules/effect/foundation.d.mts +23 -0
  201. package/dist/modules/effect/foundation.mjs +2 -0
  202. package/dist/modules/effect/foundation.mjs.map +1 -0
  203. package/dist/modules/effect/idempotency.d.mts +29 -0
  204. package/dist/modules/effect/idempotency.mjs +2 -0
  205. package/dist/modules/effect/idempotency.mjs.map +1 -0
  206. package/dist/modules/effect/input.d.mts +10 -0
  207. package/dist/modules/effect/input.mjs +2 -0
  208. package/dist/modules/effect/input.mjs.map +1 -0
  209. package/dist/modules/effect/normalize.d.mts +7 -0
  210. package/dist/modules/effect/normalize.mjs +2 -0
  211. package/dist/modules/effect/normalize.mjs.map +1 -0
  212. package/dist/modules/effect/operation.d.mts +148 -0
  213. package/dist/modules/effect/operation.mjs +2 -0
  214. package/dist/modules/effect/operation.mjs.map +1 -0
  215. package/dist/modules/effect/query.d.mts +90 -0
  216. package/dist/modules/effect/query.mjs +2 -0
  217. package/dist/modules/effect/query.mjs.map +1 -0
  218. package/dist/modules/effect/schema.d.mts +30 -0
  219. package/dist/modules/effect/schema.mjs +2 -0
  220. package/dist/modules/effect/schema.mjs.map +1 -0
  221. package/dist/modules/effect/scope.d.mts +25 -0
  222. package/dist/modules/effect/scope.mjs +2 -0
  223. package/dist/modules/effect/scope.mjs.map +1 -0
  224. package/dist/modules/effect/workflow.d.mts +75 -0
  225. package/dist/modules/effect/workflow.mjs +2 -0
  226. package/dist/modules/effect/workflow.mjs.map +1 -0
  227. package/dist/modules/foundation/foundation.d.mts +108 -0
  228. package/dist/modules/foundation/foundation.mjs +2 -0
  229. package/dist/modules/foundation/foundation.mjs.map +1 -0
  230. package/dist/modules/foundation/operation.d.mts +139 -0
  231. package/dist/modules/foundation/operation.mjs +2 -0
  232. package/dist/modules/foundation/operation.mjs.map +1 -0
  233. package/dist/namespace.d.mts +104 -0
  234. package/dist/namespace.mjs +2 -0
  235. package/dist/namespace.mjs.map +1 -0
  236. package/dist/oxlint/architecture.d.mts +23 -0
  237. package/dist/oxlint/architecture.mjs +2 -0
  238. package/dist/oxlint/architecture.mjs.map +1 -0
  239. package/dist/oxlint/ast.d.mts +51 -0
  240. package/dist/oxlint/ast.mjs +2 -0
  241. package/dist/oxlint/ast.mjs.map +1 -0
  242. package/dist/oxlint/components.d.mts +4 -0
  243. package/dist/oxlint/components.mjs +2 -0
  244. package/dist/oxlint/components.mjs.map +1 -0
  245. package/dist/oxlint/ownership.d.mts +59 -0
  246. package/dist/oxlint/ownership.mjs +2 -0
  247. package/dist/oxlint/ownership.mjs.map +1 -0
  248. package/dist/oxlint/reserved-files.d.mts +4 -0
  249. package/dist/oxlint/reserved-files.mjs +2 -0
  250. package/dist/oxlint/reserved-files.mjs.map +1 -0
  251. package/dist/oxlint.d.mts +9 -0
  252. package/dist/oxlint.mjs +2 -0
  253. package/dist/oxlint.mjs.map +1 -0
  254. package/dist/querying/cursors.d.mts +94 -0
  255. package/dist/querying/cursors.mjs +2 -0
  256. package/dist/querying/cursors.mjs.map +1 -0
  257. package/dist/querying/execution.d.mts +40 -0
  258. package/dist/querying/execution.mjs +2 -0
  259. package/dist/querying/execution.mjs.map +1 -0
  260. package/dist/querying/failures.d.mts +11 -0
  261. package/dist/querying/failures.mjs +2 -0
  262. package/dist/querying/failures.mjs.map +1 -0
  263. package/dist/querying/filter-boundary.d.mts +25 -0
  264. package/dist/querying/filter-boundary.mjs +2 -0
  265. package/dist/querying/filter-boundary.mjs.map +1 -0
  266. package/dist/querying/filters.d.mts +180 -0
  267. package/dist/querying/filters.mjs +2 -0
  268. package/dist/querying/filters.mjs.map +1 -0
  269. package/dist/querying/planner.d.mts +61 -0
  270. package/dist/querying/planner.mjs +2 -0
  271. package/dist/querying/planner.mjs.map +1 -0
  272. package/dist/querying/relationships.d.mts +58 -0
  273. package/dist/querying/relationships.mjs +2 -0
  274. package/dist/querying/relationships.mjs.map +1 -0
  275. package/dist/querying/search.d.mts +69 -0
  276. package/dist/querying/search.mjs +2 -0
  277. package/dist/querying/search.mjs.map +1 -0
  278. package/dist/querying/security.d.mts +123 -0
  279. package/dist/querying/security.mjs +2 -0
  280. package/dist/querying/security.mjs.map +1 -0
  281. package/dist/querying/shared/ast.d.mts +26 -0
  282. package/dist/querying/shared/ast.mjs +2 -0
  283. package/dist/querying/shared/ast.mjs.map +1 -0
  284. package/dist/querying/shared/contract.d.mts +98 -0
  285. package/dist/querying/shared/contract.mjs +2 -0
  286. package/dist/querying/shared/contract.mjs.map +1 -0
  287. package/dist/querying/shared/evaluate.d.mts +5 -0
  288. package/dist/querying/shared/evaluate.mjs +2 -0
  289. package/dist/querying/shared/evaluate.mjs.map +1 -0
  290. package/dist/querying/shared/filters.d.mts +65 -0
  291. package/dist/querying/shared/filters.mjs +2 -0
  292. package/dist/querying/shared/filters.mjs.map +1 -0
  293. package/dist/querying/shared/native-json.d.mts +7 -0
  294. package/dist/querying/shared/native-json.mjs +2 -0
  295. package/dist/querying/shared/native-json.mjs.map +1 -0
  296. package/dist/querying/shared/page.d.mts +20 -0
  297. package/dist/querying/shared/page.mjs +2 -0
  298. package/dist/querying/shared/page.mjs.map +1 -0
  299. package/dist/querying.d.mts +82 -0
  300. package/dist/querying.mjs +2 -0
  301. package/dist/querying.mjs.map +1 -0
  302. package/dist/react/failures.d.mts +24 -0
  303. package/dist/react/failures.mjs +2 -0
  304. package/dist/react/failures.mjs.map +1 -0
  305. package/dist/react/optimistic.d.mts +46 -0
  306. package/dist/react/optimistic.mjs +2 -0
  307. package/dist/react/optimistic.mjs.map +1 -0
  308. package/dist/react/pagination-state.d.mts +39 -0
  309. package/dist/react/pagination-state.mjs +2 -0
  310. package/dist/react/pagination-state.mjs.map +1 -0
  311. package/dist/react/use-command.d.mts +22 -0
  312. package/dist/react/use-command.mjs +2 -0
  313. package/dist/react/use-command.mjs.map +1 -0
  314. package/dist/react/use-paginated-list.d.mts +34 -0
  315. package/dist/react/use-paginated-list.mjs +2 -0
  316. package/dist/react/use-paginated-list.mjs.map +1 -0
  317. package/dist/react.d.mts +6 -0
  318. package/dist/react.mjs +1 -0
  319. package/dist/registration.d.mts +65 -0
  320. package/dist/registration.mjs +2 -0
  321. package/dist/registration.mjs.map +1 -0
  322. package/dist/relations-public.d.mts +2 -0
  323. package/dist/relations-public.mjs +1 -0
  324. package/dist/relations.d.mts +274 -0
  325. package/dist/relations.mjs +2 -0
  326. package/dist/relations.mjs.map +1 -0
  327. package/dist/state-machine.d.mts +1 -4
  328. package/dist/state-machine.mjs.map +1 -1
  329. package/dist/table.d.mts +222 -0
  330. package/dist/table.mjs +2 -0
  331. package/dist/table.mjs.map +1 -0
  332. package/dist/tenancy.d.mts +6 -8
  333. package/dist/tenancy.mjs +1 -1
  334. package/dist/tenancy.mjs.map +1 -1
  335. package/dist/triggers.d.mts +12 -10
  336. package/dist/triggers.mjs +1 -1
  337. package/dist/triggers.mjs.map +1 -1
  338. package/dist/webhooks.d.mts +22 -112
  339. package/dist/webhooks.mjs +1 -1
  340. package/dist/webhooks.mjs.map +1 -1
  341. package/dist/workflow.d.mts +2 -0
  342. package/dist/workflow.mjs +1 -0
  343. package/dist/zod.d.mts +30 -0
  344. package/dist/zod.mjs +2 -0
  345. package/dist/zod.mjs.map +1 -0
  346. package/package.json +145 -33
  347. package/src/test.ts +9 -17
  348. package/CHANGELOG.md +0 -145
  349. package/ROADMAP.md +0 -126
  350. package/dist/zod-table.d.mts +0 -175
  351. package/dist/zod-table.mjs +0 -2
  352. package/dist/zod-table.mjs.map +0 -1
  353. package/docs/agent-tools.md +0 -41
  354. package/docs/approvals.md +0 -200
  355. package/docs/architecture.md +0 -124
  356. package/docs/auth.md +0 -218
  357. package/docs/commands.md +0 -278
  358. package/docs/conventions.md +0 -291
  359. package/docs/crud.md +0 -62
  360. package/docs/llms.md +0 -220
  361. package/docs/maintainability.md +0 -124
  362. package/docs/migration.md +0 -351
  363. package/docs/plans/2026-08-14-001-feat-v0.1.0-feature-set-plan.md +0 -461
  364. package/docs/plans/2026-08-21-0930-feat-resolve-organization-hook-plan.md +0 -178
  365. package/docs/tenancy.md +0 -179
  366. package/docs/triggers.md +0 -75
  367. package/docs/upgrading.md +0 -175
  368. package/docs/webhooks.md +0 -58
  369. package/docs/zod-table.md +0 -173
  370. package/scripts/convex-config-bridge.mjs +0 -55
  371. package/scripts/extract-changelog.mjs +0 -29
  372. package/scripts/smoke-packed-components.mjs +0 -374
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.mjs","names":["nullNative","v","anyNative","compileNative","optional","nullable","root","node","native","compileRoot","compileOutput","outputOf","membersOf","compileRootOutput","differs","base","current","outputOfNode","requiredOutput","required","fields","out","key","field","output","element","requiredOf","value","members","outputs","member","compileEnum","compileFields","requiredCopy","values"],"sources":["../../src/k/compile.ts"],"sourcesContent":["import { v } from 'convex/values'\nimport type { GenericValidator, PropertyValidators } from 'convex/values'\nimport type {\n\tKDiscriminated,\n\tKFields,\n\tKLiteralValue,\n\tKNode,\n\tKRequiredValidator,\n\tKType,\n} from './types'\n\n/** Native validators are immutable, so every nullable shares one null member and every transform one any. */\nconst nullNative = v.null()\nconst anyNative = v.any()\n\n/**\n * Build the input-side native validator for a chain record in one walk to its root. The root's validator\n * is memoised on the root, so check records reuse it; `nullable` wraps it and `optional`/`default` make it\n * optional. Transform and pipe records keep their input schema's validator.\n */\nexport function compileNative(node: KNode): GenericValidator {\n\tlet optional = false\n\tlet nullable = false\n\tlet root = node\n\twhile (root.prev !== null) {\n\t\tif (root.op === 'optional' || root.op === 'partial' || root.op === 'default') optional = true\n\t\telse if (root.op === 'nullable') nullable = true\n\t\troot = root.prev\n\t}\n\t// SAFETY: root validators are never optional; only optional/default records make a chain optional.\n\tlet native = (root.native ??= compileRoot(root)) as KRequiredValidator\n\tif (nullable) native = v.union(native, nullNative)\n\treturn optional ? v.optional(native) : native\n}\n\n/**\n * Build the output-side native validator: a defaulted chain is required, a transform is `v.any()` and a\n * pipe is its target's output side. A chain whose output side equals its input side returns the very\n * same validator instance.\n */\nexport function compileOutput(node: KNode): GenericValidator {\n\treturn outputOf(node, false)\n}\n\n/** The members of a union or discriminated union root. */\nexport function membersOf(root: KNode): readonly KNode[] {\n\tif (root.op === 'union') {\n\t\t// SAFETY: k.union stores its member schemas as the root argument.\n\t\treturn root.arg as readonly KType[]\n\t}\n\t// SAFETY: k.discriminatedUnion stores its key and object options as the root argument.\n\tconst arg = root.arg as KDiscriminated\n\treturn arg.options\n}\n\nfunction outputOf(node: KNode, required: boolean): GenericValidator {\n\tif (node.prev === null) return compileRootOutput(node)\n\tlet optional: boolean | undefined\n\tlet nullable = false\n\tlet differs = false\n\tlet base: KRequiredValidator | undefined\n\tlet current: KNode = node\n\twhile (base === undefined) {\n\t\tif (current.prev === null) {\n\t\t\t// SAFETY: a root's output validator is never optional.\n\t\t\tbase = outputOfNode(current) as KRequiredValidator\n\t\t\tif (base !== current.validator) differs = true\n\t\t\tbreak\n\t\t}\n\t\tif (current.op === 'optional' || current.op === 'partial') optional ??= true\n\t\telse if (current.op === 'default') {\n\t\t\toptional ??= false\n\t\t\tdiffers = true\n\t\t} else if (current.op === 'nullable') nullable = true\n\t\telse if (current.op === 'transform') {\n\t\t\tbase = anyNative\n\t\t\tdiffers = true\n\t\t} else if (current.op === 'pipe') {\n\t\t\t// SAFETY: a pipe record stores its target schema as its argument.\n\t\t\tbase = requiredOutput(current.arg as KNode)\n\t\t\tdiffers = true\n\t\t}\n\t\tcurrent = current.prev\n\t}\n\tif (!differs && !required) return node.validator\n\tif (nullable) base = v.union(base, nullNative)\n\treturn optional === true && !required ? v.optional(base) : base\n}\n\nfunction outputOfNode(node: KNode): GenericValidator {\n\treturn (node.outputNative ??= compileOutput(node))\n}\n\nfunction compileRootOutput(root: KNode): GenericValidator {\n\tswitch (root.op) {\n\t\tcase 'object': {\n\t\t\t// SAFETY: k.object stores its field schemas as the root argument.\n\t\t\tconst fields = root.arg as KFields\n\t\t\tconst out: Record<string, GenericValidator> = {}\n\t\t\tlet differs = false\n\t\t\tfor (const key in fields) {\n\t\t\t\tconst field = fields[key]\n\t\t\t\tconst output = outputOfNode(field)\n\t\t\t\tif (output !== field.validator) differs = true\n\t\t\t\tout[key] = output\n\t\t\t}\n\t\t\treturn differs ? v.object(out) : root.validator\n\t\t}\n\t\tcase 'array': {\n\t\t\t// SAFETY: k.array stores its element schema as the root argument.\n\t\t\tconst element = root.arg as KNode\n\t\t\tconst output = requiredOutput(element)\n\t\t\treturn output === requiredOf(element) ? root.validator : v.array(output)\n\t\t}\n\t\tcase 'record': {\n\t\t\t// SAFETY: k.record stores its key and value schemas as the root argument.\n\t\t\tconst [key, value] = root.arg as readonly KType[]\n\t\t\tconst output = requiredOutput(value)\n\t\t\treturn output === requiredOf(value) ? root.validator : v.record(requiredOf(key), output)\n\t\t}\n\t\tcase 'union':\n\t\tcase 'discriminatedUnion': {\n\t\t\tconst members = membersOf(root)\n\t\t\tconst outputs: KRequiredValidator[] = []\n\t\t\tlet differs = false\n\t\t\tfor (const member of members) {\n\t\t\t\tconst output = requiredOutput(member)\n\t\t\t\tif (output !== requiredOf(member)) differs = true\n\t\t\t\toutputs.push(output)\n\t\t\t}\n\t\t\treturn differs ? v.union(...outputs) : root.validator\n\t\t}\n\t\tdefault:\n\t\t\treturn root.validator\n\t}\n}\n\nfunction compileRoot(node: KNode): KRequiredValidator {\n\tswitch (node.op) {\n\t\tcase 'string':\n\t\tcase 'isoDate':\n\t\tcase 'isoDateTime':\n\t\t\treturn v.string()\n\t\tcase 'number':\n\t\tcase 'int':\n\t\tcase 'timestamp':\n\t\t\treturn v.number()\n\t\tcase 'int64':\n\t\t\treturn v.int64()\n\t\tcase 'boolean':\n\t\t\treturn v.boolean()\n\t\tcase 'null':\n\t\t\treturn v.null()\n\t\tcase 'bytes':\n\t\t\treturn v.bytes()\n\t\tcase 'any':\n\t\t\treturn v.any()\n\t\tcase 'json':\n\t\t\treturn v.union(\n\t\t\t\tv.string(),\n\t\t\t\tv.number(),\n\t\t\t\tv.boolean(),\n\t\t\t\tv.null(),\n\t\t\t\tv.array(v.any()),\n\t\t\t\tv.record(v.string(), v.any()),\n\t\t\t)\n\t\tcase 'literal':\n\t\t\t// SAFETY: k.literal stores its literal value as the root argument.\n\t\t\treturn v.literal(node.arg as KLiteralValue)\n\t\tcase 'id':\n\t\t\t// SAFETY: k.id stores its table name as the root argument.\n\t\t\treturn v.id(node.arg as string)\n\t\tcase 'enum':\n\t\t\t// SAFETY: k.enum stores its non-empty value list as the root argument.\n\t\t\treturn compileEnum(node.arg as readonly string[])\n\t\tcase 'array':\n\t\t\t// SAFETY: k.array stores its element schema as the root argument.\n\t\t\treturn v.array(requiredOf(node.arg as KNode))\n\t\tcase 'object':\n\t\t\t// SAFETY: k.object stores its field schemas as the root argument.\n\t\t\treturn v.object(compileFields(node.arg as KFields))\n\t\tcase 'record': {\n\t\t\t// SAFETY: k.record stores its key and value schemas as the root argument.\n\t\t\tconst [key, value] = node.arg as readonly KType[]\n\t\t\treturn v.record(requiredOf(key), requiredOf(value))\n\t\t}\n\t\tcase 'union':\n\t\tcase 'discriminatedUnion':\n\t\t\treturn v.union(...membersOf(node).map(requiredOf))\n\t\tdefault:\n\t\t\tthrow new Error(`k: '${node.op}' is not a root operation`)\n\t}\n}\n\nfunction requiredOf(node: KNode): KRequiredValidator {\n\tconst native = node.validator\n\t// SAFETY: an optional validator's required form is rebuilt only for the rare optional array element or union member.\n\treturn native.isOptional === 'optional' ? requiredCopy(node) : (native as KRequiredValidator)\n}\n\nfunction requiredOutput(node: KNode): KRequiredValidator {\n\tconst output = outputOfNode(node)\n\tif (output.isOptional === 'optional') {\n\t\t// SAFETY: outputOf with `required` never makes the validator optional.\n\t\treturn outputOf(node, true) as KRequiredValidator\n\t}\n\t// SAFETY: the validator is not optional, checked above.\n\treturn output as KRequiredValidator\n}\n\nfunction requiredCopy(node: KNode): KRequiredValidator {\n\tlet nullable = false\n\tlet root = node\n\twhile (root.prev !== null) {\n\t\tif (root.op === 'nullable') nullable = true\n\t\troot = root.prev\n\t}\n\t// SAFETY: root validators are never optional.\n\tconst native = root.validator as KRequiredValidator\n\treturn nullable ? v.union(native, nullNative) : native\n}\n\nfunction compileEnum(values: readonly string[]): KRequiredValidator {\n\tconst members: KRequiredValidator[] = []\n\tfor (const value of values) members.push(v.literal(value))\n\treturn v.union(...members)\n}\n\nfunction compileFields(fields: KFields): PropertyValidators {\n\tconst out: Record<string, GenericValidator> = {}\n\tfor (const key in fields) out[key] = fields[key].validator\n\treturn out\n}\n"],"mappings":"A,kCAYA,MAAMA,EAAaC,EAAE,KAAK,EACpBC,EAAYD,EAAE,IAAI,EAOxB,SAAgBE,EAAc,EAA+B,CAC5D,IAAIC,EAAW,GACXC,EAAW,GACXC,EAAOC,EACX,KAAOD,EAAK,OAAS,MAChBA,EAAK,KAAO,YAAcA,EAAK,KAAO,WAAaA,EAAK,KAAO,UAAW,EAAW,GAChFA,EAAK,KAAO,aAAY,EAAW,IAC5C,EAAOA,EAAK,KAGb,IAAIE,EAAU,EAAK,SAAWC,EAAYH,CAAI,EAE9C,OADID,IAAU,EAASJ,EAAE,MAAMO,EAAQR,CAAU,GAC1CI,EAAWH,EAAE,SAASO,CAAM,EAAIA,CACxC,CAOA,SAAgBE,EAAc,EAA+B,CAC5D,OAAOC,EAASJ,EAAM,EAAK,CAC5B,CAGA,SAAgBK,EAAU,EAA+B,CAOxD,OANIN,EAAK,KAAO,QAERA,EAAK,IAGDA,EAAK,IACN,OACZ,CAEA,SAASK,EAAS,EAAa,EAAqC,CACnE,GAAIJ,EAAK,OAAS,KAAM,OAAOM,EAAkBN,CAAI,EACrD,IAAIH,EACAC,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strict `YYYY-MM-DD` calendar date; natively `v.string()`. */
4
+ export declare class KIsoDate extends KString {
5
+ /** Input-position conversion to UTC midnight in milliseconds. A transform: table fields reject it. */
6
+ toTimestamp(): KTransform<this, number>;
7
+ }
8
+ /** An ISO 8601 date-time with a `Z` or numeric offset; natively `v.string()`. */
9
+ export declare class KIsoDateTime extends KString {
10
+ /** Input-position conversion to milliseconds. A transform: table fields reject it. */
11
+ toTimestamp(): KTransform<this, number>;
12
+ }
13
+ /** Finite integer milliseconds since the epoch, not negative; natively `v.number()`. */
14
+ export declare class KTimestamp extends KNumber {
15
+ /** Input-position conversion to an ISO date-time in UTC. A transform: table fields reject it. */
16
+ toIsoDateTime(): KTransform<this, string>;
17
+ /** Input-position conversion to the UTC `YYYY-MM-DD`. A transform: table fields reject it. */
18
+ toIsoDate(): KTransform<this, string>;
19
+ }
20
+ export declare function isoDate(): KIsoDate;
21
+ export declare function isoDateTime(): KIsoDateTime;
22
+ export declare function timestamp(): KTimestamp;
23
+ //# sourceMappingURL=dates.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{isoDateTimeToTimestamp as e,isoDateToTimestamp as t,timestampToIsoDate as n,timestampToIsoDateTime as r}from"./formats.mjs";import{KNumber as i,KString as a}from"./kinds.mjs";var o=class extends a{toTimestamp(){return this.transform(h(t))}},s=class extends a{toTimestamp(){return this.transform(h(e))}},c=class extends i{toIsoDateTime(){return this.transform(h(r))}toIsoDate(){return this.transform(h(n))}};const l=new o(null,`isoDate`,void 0,void 0),u=new s(null,`isoDateTime`,void 0,void 0),d=new c(null,`timestamp`,void 0,void 0);function f(){return l}function p(){return u}function m(){return d}function h(e){return e}export{o as KIsoDate,s as KIsoDateTime,c as KTimestamp,f as isoDate,p as isoDateTime,m as timestamp};
2
+ //# sourceMappingURL=dates.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dates.mjs","names":["KIsoDate","KString","conversion","isoDateToTimestamp","KIsoDateTime","isoDateTimeToTimestamp","KTimestamp","KNumber","timestampToIsoDateTime","timestampToIsoDate","isoDateRoot","isoDateTimeRoot","timestampRoot","isoDate","isoDateTime","timestamp","convert"],"sources":["../../src/k/dates.ts"],"sourcesContent":["import {\n\ttype KConversionFailure,\n\tisoDateTimeToTimestamp,\n\tisoDateToTimestamp,\n\ttimestampToIsoDate,\n\ttimestampToIsoDateTime,\n} from './formats'\nimport { KNumber, KString } from './kinds'\nimport type { KTransform } from './schema'\n\n/** A strict `YYYY-MM-DD` calendar date; natively `v.string()`. */\nexport class KIsoDate extends KString {\n\t/** Input-position conversion to UTC midnight in milliseconds. A transform: table fields reject it. */\n\ttoTimestamp(): KTransform<this, number> {\n\t\treturn this.transform(conversion(isoDateToTimestamp))\n\t}\n}\n\n/** An ISO 8601 date-time with a `Z` or numeric offset; natively `v.string()`. */\nexport class KIsoDateTime extends KString {\n\t/** Input-position conversion to milliseconds. A transform: table fields reject it. */\n\ttoTimestamp(): KTransform<this, number> {\n\t\treturn this.transform(conversion(isoDateTimeToTimestamp))\n\t}\n}\n\n/** Finite integer milliseconds since the epoch, not negative; natively `v.number()`. */\nexport class KTimestamp extends KNumber {\n\t/** Input-position conversion to an ISO date-time in UTC. A transform: table fields reject it. */\n\ttoIsoDateTime(): KTransform<this, string> {\n\t\treturn this.transform(conversion(timestampToIsoDateTime))\n\t}\n\n\t/** Input-position conversion to the UTC `YYYY-MM-DD`. A transform: table fields reject it. */\n\ttoIsoDate(): KTransform<this, string> {\n\t\treturn this.transform(conversion(timestampToIsoDate))\n\t}\n}\n\nconst isoDateRoot = new KIsoDate(null, 'isoDate', undefined, undefined)\nconst isoDateTimeRoot = new KIsoDateTime(null, 'isoDateTime', undefined, undefined)\nconst timestampRoot = new KTimestamp(null, 'timestamp', undefined, undefined)\n\nexport function isoDate(): KIsoDate {\n\treturn isoDateRoot\n}\n\nexport function isoDateTime(): KIsoDateTime {\n\treturn isoDateTimeRoot\n}\n\nexport function timestamp(): KTimestamp {\n\treturn timestampRoot\n}\n\n/** A conversion's failure value is reported by the walker as an issue, so callers see only the success type. */\nfunction conversion<I, O>(convert: (value: I) => O | KConversionFailure): (value: I) => O {\n\t// SAFETY: the walker turns a KConversionFailure result into an issue before any caller sees it.\n\treturn convert as (value: I) => O\n}\n"],"mappings":"A,sLAWA,IAAaA,EAAb,cAA8BC,CAAQ,CAErC,aAAwC,CACvC,OAAO,KAAK,UAAUC,EAAWC,CAAkB,CAAC,CACrD,CACD,EAGaC,EAAb,cAAkCH,CAAQ,CAEzC,aAAwC,CACvC,OAAO,KAAK,UAAUC,EAAWG,CAAsB,CAAC,CACzD,CACD,EAGaC,EAAb,cAAgCC,CAAQ,CAEvC,eAA0C,CACzC,OAAO,KAAK,UAAUL,EAAWM,CAAsB,CAAC,CACzD,CAGA,WAAsC,CACrC,OAAO,KAAK,UAAUN,EAAWO,CAAkB,CAAC,CACrD,CACD,EAEA,MAAMC,EAAc,IAAIV,EAAS,KAAM,UAAW,IAAA,GAAW,IAAA,EAAS,EAChEW,EAAkB,IAAIP,EAAa,KAAM,cAAe,IAAA,GAAW,IAAA,EAAS,EAC5EQ,EAAgB,IAAIN,EAAW,KAAM,YAAa,IAAA,GAAW,IAAA,EAAS,EAE5E,SAAgBO,GAAoB,CACnC,OAAOH,CACR,CAEA,SAAgBI,GAA4B,CAC3C,OAAOH,CACR,CAEA,SAAgBI,GAAwB,CACvC,OAAOH,CACR,CAGA,SAASV,EAAiB,EAAgE,CAEzF,OAAOc,CACR,C"}
@@ -0,0 +1,24 @@
1
+ /** Strict ISO 8601 checks and conversions, with no date dependency and no `Date` parsing leniency. */
2
+ /** `YYYY-MM-DD` naming a real calendar day, leap years included. */
3
+ export declare function isIsoDate(value: string): boolean;
4
+ /** An ISO 8601 date-time with seconds, optional fractional seconds and a `Z` or `±HH:MM` offset. */
5
+ export declare function isIsoDateTime(value: string): boolean;
6
+ /**
7
+ * The supported timestamp range: 1970-01-01T00:00:00.000Z through 9999-12-31T23:59:59.999Z, so every
8
+ * timestamp has a four-digit ISO year and every conversion is total.
9
+ */
10
+ export declare const maxTimestamp = 253402300799999;
11
+ /** A conversion's failure, reported by the walker as an `invalid_value` issue instead of a throw. */
12
+ export declare class KConversionFailure {
13
+ readonly message: string;
14
+ constructor(message: string);
15
+ }
16
+ /** Integer milliseconds within the supported range. */
17
+ export declare function isTimestamp(value: number): boolean;
18
+ /** UTC midnight of an already validated `YYYY-MM-DD`, or a failure before 1970. */
19
+ export declare function isoDateToTimestamp(value: string): number | KConversionFailure;
20
+ /** Milliseconds of an already validated ISO date-time, or a failure outside the supported range. */
21
+ export declare function isoDateTimeToTimestamp(value: string): number | KConversionFailure;
22
+ export declare function timestampToIsoDateTime(value: number): string | KConversionFailure;
23
+ export declare function timestampToIsoDate(value: number): string | KConversionFailure;
24
+ //# sourceMappingURL=formats.d.mts.map
@@ -0,0 +1,2 @@
1
+ const e=/^(\d{4})-(\d{2})-(\d{2})$/,t=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(?:Z|([+-])(\d{2}):(\d{2}))$/;function n(t){let n=e.exec(t);return n!==null&&p(n[1],n[2],n[3])}function r(e){let n=t.exec(e);return n===null||!p(n[1],n[2],n[3])||Number(n[4])>23||Number(n[5])>59||Number(n[6])>59?!1:n[7]===void 0||Number(n[8])<=23&&Number(n[9])<=59}const i=0xe677d21fdbff;var a=class{message;constructor(e){this.message=e}};const o=new a(`Out of range: a timestamp must be from 1970-01-01T00:00:00.000Z to 9999-12-31T23:59:59.999Z`);function s(e){return Number.isInteger(e)&&e>=0&&e<=0xe677d21fdbff}function c(e){return f(Date.parse(`${e}T00:00:00Z`))}function l(e){return f(Date.parse(e))}function u(e){return s(e)?new Date(e).toISOString():o}function d(e){return s(e)?new Date(e).toISOString().slice(0,10):o}function f(e){return s(e)?e:o}function p(e,t,n){let r=Number(e),i=Number(t),a=Number(n);return i>=1&&i<=12&&a>=1&&a<=m(r,i)}function m(e,t){return t===2?e%4==0&&e%100!=0||e%400==0?29:28:t===4||t===6||t===9||t===11?30:31}export{a as KConversionFailure,n as isIsoDate,r as isIsoDateTime,s as isTimestamp,l as isoDateTimeToTimestamp,c as isoDateToTimestamp,i as maxTimestamp,d as timestampToIsoDate,u as timestampToIsoDateTime};
2
+ //# sourceMappingURL=formats.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"formats.mjs","names":["isoDatePattern","isoDateTimePattern","isIsoDate","match","value","isCalendarDay","isIsoDateTime","maxTimestamp","KConversionFailure","message","outOfRange","isTimestamp","isoDateToTimestamp","inRange","isoDateTimeToTimestamp","timestampToIsoDateTime","timestampToIsoDate","time","y","year","m","month","d","day","daysIn"],"sources":["../../src/k/formats.ts"],"sourcesContent":["/** Strict ISO 8601 checks and conversions, with no date dependency and no `Date` parsing leniency. */\n\nconst isoDatePattern = /^(\\d{4})-(\\d{2})-(\\d{2})$/\nconst isoDateTimePattern =\n\t/^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})(?:\\.\\d+)?(?:Z|([+-])(\\d{2}):(\\d{2}))$/\n\n/** `YYYY-MM-DD` naming a real calendar day, leap years included. */\nexport function isIsoDate(value: string): boolean {\n\tconst match = isoDatePattern.exec(value)\n\treturn match !== null && isCalendarDay(match[1], match[2], match[3])\n}\n\n/** An ISO 8601 date-time with seconds, optional fractional seconds and a `Z` or `±HH:MM` offset. */\nexport function isIsoDateTime(value: string): boolean {\n\tconst match = isoDateTimePattern.exec(value)\n\tif (match === null || !isCalendarDay(match[1], match[2], match[3])) return false\n\tif (Number(match[4]) > 23 || Number(match[5]) > 59 || Number(match[6]) > 59) return false\n\treturn match[7] === undefined || (Number(match[8]) <= 23 && Number(match[9]) <= 59)\n}\n\n/**\n * The supported timestamp range: 1970-01-01T00:00:00.000Z through 9999-12-31T23:59:59.999Z, so every\n * timestamp has a four-digit ISO year and every conversion is total.\n */\nexport const maxTimestamp = 253_402_300_799_999\n\n/** A conversion's failure, reported by the walker as an `invalid_value` issue instead of a throw. */\nexport class KConversionFailure {\n\treadonly message: string\n\n\tconstructor(message: string) {\n\t\tthis.message = message\n\t}\n}\n\nconst outOfRange = new KConversionFailure(\n\t'Out of range: a timestamp must be from 1970-01-01T00:00:00.000Z to 9999-12-31T23:59:59.999Z',\n)\n\n/** Integer milliseconds within the supported range. */\nexport function isTimestamp(value: number): boolean {\n\treturn Number.isInteger(value) && value >= 0 && value <= maxTimestamp\n}\n\n/** UTC midnight of an already validated `YYYY-MM-DD`, or a failure before 1970. */\nexport function isoDateToTimestamp(value: string): number | KConversionFailure {\n\treturn inRange(Date.parse(`${value}T00:00:00Z`))\n}\n\n/** Milliseconds of an already validated ISO date-time, or a failure outside the supported range. */\nexport function isoDateTimeToTimestamp(value: string): number | KConversionFailure {\n\treturn inRange(Date.parse(value))\n}\n\nexport function timestampToIsoDateTime(value: number): string | KConversionFailure {\n\treturn isTimestamp(value) ? new Date(value).toISOString() : outOfRange\n}\n\nexport function timestampToIsoDate(value: number): string | KConversionFailure {\n\treturn isTimestamp(value) ? new Date(value).toISOString().slice(0, 10) : outOfRange\n}\n\nfunction inRange(time: number): number | KConversionFailure {\n\treturn isTimestamp(time) ? time : outOfRange\n}\n\nfunction isCalendarDay(year: string, month: string, day: string): boolean {\n\tconst y = Number(year)\n\tconst m = Number(month)\n\tconst d = Number(day)\n\treturn m >= 1 && m <= 12 && d >= 1 && d <= daysIn(y, m)\n}\n\nfunction daysIn(year: number, month: number): number {\n\tif (month === 2) return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0 ? 29 : 28\n\treturn month === 4 || month === 6 || month === 9 || month === 11 ? 30 : 31\n}\n"],"mappings":"AAEA,MAAMA,EAAiB,4BACjBC,EACL,yFAGD,SAAgBC,EAAU,EAAwB,CACjD,IAAMC,EAAQH,EAAe,KAAKI,CAAK,EACvC,OAAOD,IAAU,MAAQE,EAAcF,EAAM,GAAIA,EAAM,GAAIA,EAAM,EAAE,CACpE,CAGA,SAAgBG,EAAc,EAAwB,CACrD,IAAMH,EA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AGE,CAAC,CACvD,CAEA,SAASI,EAAO,EAAc,EAAuB,CAEpD,OADIH,IAAU,EAAWF,EAAO,GAAM,GAAKA,EAAO,KAAQ,GAAMA,EAAO,KAAQ,EAAI,GAAK,GACjFE,IAAU,GAAKA,IAAU,GAAKA,IAAU,GAAKA,IAAU,GAAK,GAAK,EACzE,C"}
@@ -0,0 +1,32 @@
1
+ import { any, array, boolean, bytes, discriminatedUnion, enumOf, id, int, int64, json, literal, nullValue, number, record, string, union } from "./kinds.mjs";
2
+ import { isoDate, isoDateTime, timestamp } from "./dates.mjs";
3
+ import { object } from "./object.mjs";
4
+ import { KType } from "./types.mjs";
5
+ export declare const k: {
6
+ string: typeof string;
7
+ number: typeof number;
8
+ int: typeof int;
9
+ int64: typeof int64;
10
+ boolean: typeof boolean;
11
+ null: typeof nullValue;
12
+ bytes: typeof bytes;
13
+ any: typeof any;
14
+ json: typeof json;
15
+ literal: typeof literal;
16
+ enum: typeof enumOf;
17
+ id: typeof id;
18
+ array: typeof array;
19
+ object: typeof object;
20
+ record: typeof record;
21
+ union: typeof union;
22
+ discriminatedUnion: typeof discriminatedUnion;
23
+ isoDate: typeof isoDate;
24
+ isoDateTime: typeof isoDateTime;
25
+ timestamp: typeof timestamp;
26
+ };
27
+ export declare namespace k {
28
+ type infer<T extends KType> = T['_output'];
29
+ type output<T extends KType> = T['_output'];
30
+ type input<T extends KType> = T['validator']['type'];
31
+ }
32
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{any as e,array as t,boolean as n,bytes as r,discriminatedUnion as i,enumOf as a,id as o,int as s,int64 as c,json as l,literal as u,nullValue as d,number as f,record as p,string as m,union as h}from"./kinds.mjs";import{isoDate as g,isoDateTime as _,timestamp as v}from"./dates.mjs";import{object as y}from"./object.mjs";const b={string:m,number:f,int:s,int64:c,boolean:n,null:d,bytes:r,any:e,json:l,literal:u,enum:a,id:o,array:t,object:y,record:p,union:h,discriminatedUnion:i,isoDate:g,isoDateTime:_,timestamp:v};export{b as k};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["k","nullValue","enumOf"],"sources":["../../src/k/index.ts"],"sourcesContent":["import {\n\tany,\n\tarray,\n\tboolean,\n\tbytes,\n\tdiscriminatedUnion,\n\tenumOf,\n\tid,\n\tint,\n\tint64,\n\tjson,\n\tliteral,\n\tnullValue,\n\tnumber,\n\trecord,\n\tstring,\n\tunion,\n} from './kinds'\nimport { isoDate, isoDateTime, timestamp } from './dates'\nimport { object } from './object'\nimport type { KType } from './types'\n\nexport const k = {\n\tstring,\n\tnumber,\n\tint,\n\tint64,\n\tboolean,\n\tnull: nullValue,\n\tbytes,\n\tany,\n\tjson,\n\tliteral,\n\tenum: enumOf,\n\tid,\n\tarray,\n\tobject,\n\trecord,\n\tunion,\n\tdiscriminatedUnion,\n\tisoDate,\n\tisoDateTime,\n\ttimestamp,\n}\n\nexport declare namespace k {\n\ttype infer<T extends KType> = T['_output']\n\ttype output<T extends KType> = T['_output']\n\ttype input<T extends KType> = T['validator']['type']\n}\n"],"mappings":"A,sUAsBA,MAAaA,EAAI,CAChB,SACA,SACA,MACA,QACA,UACA,KAAMC,EACN,QACA,MACA,OACA,UACA,KAAMC,EACN,KACA,QACA,SACA,SACA,QACA,qBACA,UACA,cACA,WACD,E"}
@@ -0,0 +1,31 @@
1
+ import { KPath } from "./types.mjs";
2
+ import { ConvexError } from "convex/values";
3
+ export type KIssueCode = 'invalid_type' | 'too_small' | 'too_big' | 'invalid_format' | 'not_integer' | 'invalid_value' | 'unrecognized_key' | 'invalid_union' | 'custom';
4
+ /** One validation failure. A type alias, not an interface, so it is a Convex `Value` and crosses the wire. */
5
+ export type KIssue = {
6
+ path: KPath;
7
+ code: KIssueCode;
8
+ message: string;
9
+ };
10
+ /** An issue added from `.check()`; its path is relative to the checked value. */
11
+ export type KIssueInput = {
12
+ readonly path?: KPath;
13
+ readonly message: string;
14
+ readonly code?: KIssueCode;
15
+ };
16
+ export type KValidationData = {
17
+ code: 'VALIDATION';
18
+ issues: KIssue[];
19
+ };
20
+ export type KSafeParseResult<T> = {
21
+ readonly success: true;
22
+ readonly data: T;
23
+ } | {
24
+ readonly success: false;
25
+ readonly issues: KIssue[];
26
+ };
27
+ /** Thrown by `parse` and the function boundary: a `ConvexError` whose data is `{ code: 'VALIDATION', issues }`. */
28
+ export declare class KValidationError extends ConvexError<KValidationData> {
29
+ constructor(issues: KIssue[]);
30
+ }
31
+ //# sourceMappingURL=issues.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{ConvexError as e}from"convex/values";var t=class extends e{constructor(e){super({code:`VALIDATION`,issues:e})}};export{t as KValidationError};
2
+ //# sourceMappingURL=issues.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"issues.mjs","names":["KValidationError","ConvexError"],"sources":["../../src/k/issues.ts"],"sourcesContent":["import { ConvexError } from 'convex/values'\nimport type { KPath } from './types'\n\nexport type KIssueCode =\n\t| 'invalid_type'\n\t| 'too_small'\n\t| 'too_big'\n\t| 'invalid_format'\n\t| 'not_integer'\n\t| 'invalid_value'\n\t| 'unrecognized_key'\n\t| 'invalid_union'\n\t| 'custom'\n\n/** One validation failure. A type alias, not an interface, so it is a Convex `Value` and crosses the wire. */\nexport type KIssue = { path: KPath; code: KIssueCode; message: string }\n\n/** An issue added from `.check()`; its path is relative to the checked value. */\nexport type KIssueInput = {\n\treadonly path?: KPath\n\treadonly message: string\n\treadonly code?: KIssueCode\n}\n\nexport type KValidationData = { code: 'VALIDATION'; issues: KIssue[] }\n\nexport type KSafeParseResult<T> =\n\t| { readonly success: true; readonly data: T }\n\t| { readonly success: false; readonly issues: KIssue[] }\n\n/** Thrown by `parse` and the function boundary: a `ConvexError` whose data is `{ code: 'VALIDATION', issues }`. */\nexport class KValidationError extends ConvexError<KValidationData> {\n\tconstructor(issues: KIssue[]) {\n\t\tsuper({ code: 'VALIDATION', issues })\n\t}\n}\n"],"mappings":"A,4CA+BA,IAAaA,EAAb,cAAsCC,CAA6B,CAClE,YAAY,EAAkB,CAC7B,MAAM,CAAE,KAAM,aAAc,QAAO,CAAC,CACrC,CACD,E"}
@@ -0,0 +1,81 @@
1
+ import { KSchema } from "./schema.mjs";
2
+ import { KLiteralValue, KOutputRequired, KType } from "./types.mjs";
3
+ import { GenericId, JSONValue, VAny, VArray, VBoolean, VBytes, VFloat64, VId, VInt64, VLiteral, VNull, VRecord, VString, VUnion, Validator } from "convex/values";
4
+ export declare class KString extends KSchema<string, VString<string>> {
5
+ min(length: number, message?: string): this;
6
+ max(length: number, message?: string): this;
7
+ length(length: number, message?: string): this;
8
+ regex(pattern: RegExp, message?: string): this;
9
+ trim(): this;
10
+ toLowerCase(): this;
11
+ toUpperCase(): this;
12
+ }
13
+ export declare class KNumber extends KSchema<number, VFloat64<number>> {
14
+ min(value: number, message?: string): this;
15
+ max(value: number, message?: string): this;
16
+ int(message?: string): this;
17
+ }
18
+ export declare class KInt64 extends KSchema<bigint, VInt64<bigint>> {}
19
+ export declare class KBoolean extends KSchema<boolean, VBoolean<boolean>> {}
20
+ export declare class KNull extends KSchema<null, VNull<null>> {}
21
+ export declare class KBytes extends KSchema<ArrayBuffer, VBytes<ArrayBuffer>> {}
22
+ export declare class KAny extends KSchema<any, VAny> {}
23
+ /**
24
+ * Any JSON-compatible value. Natively the six-member union v1's `z.json()` stored (string, number,
25
+ * boolean, null, array of any, record of any); parse also checks the value is JSON-compatible throughout.
26
+ */
27
+ export declare class KJson extends KSchema<JSONValue, VUnion<JSONValue, [VString<string>, VFloat64<number>, VBoolean<boolean>, VNull<null>, VArray<JSONValue[], VAny<JSONValue>>, VRecord<Record<string, JSONValue>, VString<string>, VAny<JSONValue>>]>> {}
28
+ export declare class KLiteral<V extends KLiteralValue> extends KSchema<V, VLiteral<V>> {}
29
+ export declare class KEnum<V extends readonly [string, ...string[]]> extends KSchema<V[number], VUnion<V[number], { -readonly [I in keyof V]: VLiteral<V[I]>; }>> {
30
+ get options(): V;
31
+ }
32
+ export declare class KId<T extends string> extends KSchema<GenericId<T>, VId<GenericId<T>>> {}
33
+ export declare class KArray<E extends KType> extends KSchema<E['_output'][], VArray<E['_req']['type'][], E['_req']>, E['_d'], VArray<E['_req']['type'][], E['_req']>, E['_t']> {
34
+ readonly _or: VArray<E['_output'][], KOutputRequired<E>>;
35
+ readonly _oo: VArray<E['_output'][], KOutputRequired<E>>;
36
+ min(length: number, message?: string): this;
37
+ max(length: number, message?: string): this;
38
+ length(length: number, message?: string): this;
39
+ }
40
+ export type KRecordKey = KType & {
41
+ readonly _req: Validator<string, 'required', any>;
42
+ };
43
+ export declare class KRecord<K extends KRecordKey, V extends KType> extends KSchema<Record<K['_output'], V['_output']>, VRecord<Record<K['_req']['type'], V['_req']['type']>, K['_req'], V['_req']>, V['_d'], VRecord<Record<K['_req']['type'], V['_req']['type']>, K['_req'], V['_req']>, V['_t']> {
44
+ readonly _or: VRecord<Record<K['_output'], V['_output']>, K['_req'], KOutputRequired<V>>;
45
+ readonly _oo: VRecord<Record<K['_output'], V['_output']>, K['_req'], KOutputRequired<V>>;
46
+ }
47
+ export declare class KUnion<M extends readonly KType[]> extends KSchema<M[number]['_output'], VUnion<M[number]['_req']['type'], { -readonly [I in keyof M]: M[I]['_req']; }>, M[number]['_d'], VUnion<M[number]['_req']['type'], { -readonly [I in keyof M]: M[I]['_req']; }>, M[number]['_t']> {
48
+ readonly _or: VUnion<M[number]['_output'], { -readonly [I in keyof M]: KOutputRequired<M[I]>; }>;
49
+ readonly _oo: VUnion<M[number]['_output'], { -readonly [I in keyof M]: KOutputRequired<M[I]>; }>;
50
+ }
51
+ /** A union of objects dispatched on one literal or enum field when parsed; natively a plain union. */
52
+ /** An object option of a discriminated union: its output carries the key with a literal value. */
53
+ export type KDiscriminatedOption<Key extends string> = KType & {
54
+ readonly _output: { readonly [P in Key]: KLiteralValue; };
55
+ };
56
+ export declare class KDiscriminatedUnion<Key extends string, M extends readonly KType[]> extends KUnion<M> {
57
+ get discriminator(): Key;
58
+ get options(): M;
59
+ }
60
+ /**
61
+ * Argument-less factories return one shared root: records are immutable, so sharing is safe. Factories
62
+ * that take an array or map freeze it in place, so what a schema holds cannot change after declaration.
63
+ */
64
+ export declare function string(): KString;
65
+ export declare function number(): KNumber;
66
+ /** A number that must be an integer; one root record whose op carries the integer check. */
67
+ export declare function int(): KNumber;
68
+ export declare function int64(): KInt64;
69
+ export declare function boolean(): KBoolean;
70
+ export declare function nullValue(): KNull;
71
+ export declare function bytes(): KBytes;
72
+ export declare function any(): KAny;
73
+ export declare function json(): KJson;
74
+ export declare function literal<const V extends KLiteralValue>(value: V): KLiteral<V>;
75
+ export declare function enumOf<const V extends readonly [string, ...string[]]>(values: V): KEnum<V>;
76
+ export declare function id<T extends string>(table: T): KId<T>;
77
+ export declare function array<E extends KType>(element: E): KArray<E>;
78
+ export declare function record<K extends KRecordKey, V extends KType>(key: K, value: V): KRecord<K, V>;
79
+ export declare function union<const M extends readonly [KType, KType, ...KType[]]>(members: M): KUnion<M>;
80
+ export declare function discriminatedUnion<Key extends string, const M extends readonly [KDiscriminatedOption<Key>, ...KDiscriminatedOption<Key>[]]>(key: Key, options: M): KDiscriminatedUnion<Key, M>;
81
+ //# sourceMappingURL=kinds.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{KSchema as e}from"./schema.mjs";import{v as t}from"convex/values";var n=class extends e{min(e,t){return this.link(`min`,e,t)}max(e,t){return this.link(`max`,e,t)}length(e,t){return this.link(`length`,e,t)}regex(e,t){return this.link(`regex`,e,t)}trim(){return this.link(`trim`,void 0,void 0)}toLowerCase(){return this.link(`lower`,void 0,void 0)}toUpperCase(){return this.link(`upper`,void 0,void 0)}},r=class extends e{min(e,t){return this.link(`min`,e,t)}max(e,t){return this.link(`max`,e,t)}int(e){return this.link(`int`,void 0,e)}},i=class extends e{},a=class extends e{},o=class extends e{},s=class extends e{},c=class extends e{},l=class extends e{},u=class extends e{},d=class extends e{get options(){return H(this).arg}},f=class extends e{},p=class extends e{min(e,t){return this.link(`min`,e,t)}max(e,t){return this.link(`max`,e,t)}length(e,t){return this.link(`length`,e,t)}},m=class extends e{},h=class extends e{},g=class extends h{get discriminator(){return H(this).arg.key}get options(){return H(this).arg.options}};const _=new n(null,`string`,void 0,void 0),v=new r(null,`number`,void 0,void 0),y=new r(null,`int`,void 0,void 0),b=new i(null,`int64`,void 0,void 0),x=new a(null,`boolean`,void 0,void 0),S=new o(null,`null`,void 0,void 0),C=new s(null,`bytes`,void 0,void 0),w=new c(null,`any`,void 0,void 0),T=new l(null,`json`,void 0,void 0);_.native=t.string(),v.native=t.number(),y.native=v.native,b.native=t.int64(),x.native=t.boolean(),S.native=t.null(),C.native=t.bytes(),w.native=t.any();function E(){return _}function D(){return v}function O(){return y}function k(){return b}function A(){return x}function j(){return S}function M(){return C}function N(){return w}function P(){return T}function F(e){return new u(null,`literal`,e,void 0)}function I(e){if(e.length===0)throw Error(`k.enum() needs at least one value`);return new d(null,`enum`,Object.freeze(e),void 0)}function L(e){return new f(null,`id`,e,void 0)}function R(e){return new p(null,`array`,e,void 0)}function z(e,t){return new m(null,`record`,Object.freeze([e,t]),void 0)}function B(e){return new h(null,`union`,Object.freeze(e),void 0)}function V(e,t){return new g(null,`discriminatedUnion`,Object.freeze({key:e,options:Object.freeze(t)}),void 0)}function H(e){let t=e;for(;t.prev!==null;)t=t.prev;return t}export{c as KAny,p as KArray,a as KBoolean,s as KBytes,g as KDiscriminatedUnion,d as KEnum,f as KId,i as KInt64,l as KJson,u as KLiteral,o as KNull,r as KNumber,m as KRecord,n as KString,h as KUnion,N as any,R as array,A as boolean,M as bytes,V as discriminatedUnion,I as enumOf,L as id,O as int,k as int64,P as json,F as literal,j as nullValue,D as number,z as record,E as string,B as union};
2
+ //# sourceMappingURL=kinds.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kinds.mjs","names":["KString","KSchema","length","message","pattern","KNumber","value","KInt64","KBoolean","KNull","KBytes","KAny","KJson","KLiteral","KEnum","rootOf","KId","KArray","KRecord","KUnion","KDiscriminatedUnion","stringRoot","numberRoot","intRoot","int64Root","booleanRoot","nullRoot","bytesRoot","anyRoot","jsonRoot","v","string","number","int","int64","boolean","nullValue","bytes","any","json","literal","enumOf","values","id","table","array","element","record","key","union","members","discriminatedUnion","options","root","node"],"sources":["../../src/k/kinds.ts"],"sourcesContent":["import { v } from 'convex/values'\nimport type {\n\tGenericId,\n\tJSONValue,\n\tValidator,\n\tVAny,\n\tVArray,\n\tVBoolean,\n\tVBytes,\n\tVFloat64,\n\tVId,\n\tVInt64,\n\tVLiteral,\n\tVNull,\n\tVRecord,\n\tVString,\n\tVUnion,\n} from 'convex/values'\nimport { KSchema } from './schema'\nimport type { KDiscriminated, KLiteralValue, KNode, KOutputRequired, KType } from './types'\n\nexport class KString extends KSchema<string, VString<string>> {\n\tmin(length: number, message?: string): this {\n\t\treturn this.link('min', length, message)\n\t}\n\n\tmax(length: number, message?: string): this {\n\t\treturn this.link('max', length, message)\n\t}\n\n\tlength(length: number, message?: string): this {\n\t\treturn this.link('length', length, message)\n\t}\n\n\tregex(pattern: RegExp, message?: string): this {\n\t\treturn this.link('regex', pattern, message)\n\t}\n\n\ttrim(): this {\n\t\treturn this.link('trim', undefined, undefined)\n\t}\n\n\ttoLowerCase(): this {\n\t\treturn this.link('lower', undefined, undefined)\n\t}\n\n\ttoUpperCase(): this {\n\t\treturn this.link('upper', undefined, undefined)\n\t}\n}\n\nexport class KNumber extends KSchema<number, VFloat64<number>> {\n\tmin(value: number, message?: string): this {\n\t\treturn this.link('min', value, message)\n\t}\n\n\tmax(value: number, message?: string): this {\n\t\treturn this.link('max', value, message)\n\t}\n\n\tint(message?: string): this {\n\t\treturn this.link('int', undefined, message)\n\t}\n}\n\nexport class KInt64 extends KSchema<bigint, VInt64<bigint>> {}\n\nexport class KBoolean extends KSchema<boolean, VBoolean<boolean>> {}\n\nexport class KNull extends KSchema<null, VNull<null>> {}\n\nexport class KBytes extends KSchema<ArrayBuffer, VBytes<ArrayBuffer>> {}\n\nexport class KAny extends KSchema<any, VAny> {}\n\n/**\n * Any JSON-compatible value. Natively the six-member union v1's `z.json()` stored (string, number,\n * boolean, null, array of any, record of any); parse also checks the value is JSON-compatible throughout.\n */\nexport class KJson extends KSchema<\n\tJSONValue,\n\tVUnion<\n\t\tJSONValue,\n\t\t[\n\t\t\tVString<string>,\n\t\t\tVFloat64<number>,\n\t\t\tVBoolean<boolean>,\n\t\t\tVNull<null>,\n\t\t\tVArray<JSONValue[], VAny<JSONValue>>,\n\t\t\tVRecord<Record<string, JSONValue>, VString<string>, VAny<JSONValue>>,\n\t\t]\n\t>\n> {}\n\nexport class KLiteral<V extends KLiteralValue> extends KSchema<V, VLiteral<V>> {}\n\nexport class KEnum<V extends readonly [string, ...string[]]> extends KSchema<\n\tV[number],\n\tVUnion<V[number], { -readonly [I in keyof V]: VLiteral<V[I]> }>\n> {\n\tget options(): V {\n\t\t// SAFETY: k.enum stores its value tuple as the root argument.\n\t\treturn rootOf(this).arg as V\n\t}\n}\n\nexport class KId<T extends string> extends KSchema<GenericId<T>, VId<GenericId<T>>> {}\n\nexport class KArray<E extends KType> extends KSchema<\n\tE['_output'][],\n\tVArray<E['_req']['type'][], E['_req']>,\n\tE['_d'],\n\tVArray<E['_req']['type'][], E['_req']>,\n\tE['_t']\n> {\n\tdeclare readonly _or: VArray<E['_output'][], KOutputRequired<E>>\n\tdeclare readonly _oo: VArray<E['_output'][], KOutputRequired<E>>\n\n\tmin(length: number, message?: string): this {\n\t\treturn this.link('min', length, message)\n\t}\n\n\tmax(length: number, message?: string): this {\n\t\treturn this.link('max', length, message)\n\t}\n\n\tlength(length: number, message?: string): this {\n\t\treturn this.link('length', length, message)\n\t}\n}\n\nexport type KRecordKey = KType & { readonly _req: Validator<string, 'required', any> }\n\nexport class KRecord<K extends KRecordKey, V extends KType> extends KSchema<\n\tRecord<K['_output'], V['_output']>,\n\tVRecord<Record<K['_req']['type'], V['_req']['type']>, K['_req'], V['_req']>,\n\tV['_d'],\n\tVRecord<Record<K['_req']['type'], V['_req']['type']>, K['_req'], V['_req']>,\n\tV['_t']\n> {\n\tdeclare readonly _or: VRecord<Record<K['_output'], V['_output']>, K['_req'], KOutputRequired<V>>\n\tdeclare readonly _oo: VRecord<Record<K['_output'], V['_output']>, K['_req'], KOutputRequired<V>>\n}\n\nexport class KUnion<M extends readonly KType[]> extends KSchema<\n\tM[number]['_output'],\n\tVUnion<M[number]['_req']['type'], { -readonly [I in keyof M]: M[I]['_req'] }>,\n\tM[number]['_d'],\n\tVUnion<M[number]['_req']['type'], { -readonly [I in keyof M]: M[I]['_req'] }>,\n\tM[number]['_t']\n> {\n\tdeclare readonly _or: VUnion<\n\t\tM[number]['_output'],\n\t\t{ -readonly [I in keyof M]: KOutputRequired<M[I]> }\n\t>\n\tdeclare readonly _oo: VUnion<\n\t\tM[number]['_output'],\n\t\t{ -readonly [I in keyof M]: KOutputRequired<M[I]> }\n\t>\n}\n\n/** A union of objects dispatched on one literal or enum field when parsed; natively a plain union. */\n/** An object option of a discriminated union: its output carries the key with a literal value. */\nexport type KDiscriminatedOption<Key extends string> = KType & {\n\treadonly _output: { readonly [P in Key]: KLiteralValue }\n}\n\nexport class KDiscriminatedUnion<Key extends string, M extends readonly KType[]> extends KUnion<M> {\n\tget discriminator(): Key {\n\t\t// SAFETY: k.discriminatedUnion stores its key with the options as the root argument.\n\t\treturn (rootOf(this).arg as { readonly key: Key }).key\n\t}\n\n\tget options(): M {\n\t\t// SAFETY: k.discriminatedUnion stores its key and options as the root argument.\n\t\tconst arg = rootOf(this).arg as KDiscriminated\n\t\t// SAFETY: the stored options are the tuple this class was created with.\n\t\treturn arg.options as M\n\t}\n}\n\nconst stringRoot = new KString(null, 'string', undefined, undefined)\nconst numberRoot = new KNumber(null, 'number', undefined, undefined)\nconst intRoot = new KNumber(null, 'int', undefined, undefined)\nconst int64Root = new KInt64(null, 'int64', undefined, undefined)\nconst booleanRoot = new KBoolean(null, 'boolean', undefined, undefined)\nconst nullRoot = new KNull(null, 'null', undefined, undefined)\nconst bytesRoot = new KBytes(null, 'bytes', undefined, undefined)\nconst anyRoot = new KAny(null, 'any', undefined, undefined)\nconst jsonRoot = new KJson(null, 'json', undefined, undefined)\n\n// Scalar roots wrap one native value. Containers and parameterised leaves stay lazy.\nstringRoot.native = v.string()\nnumberRoot.native = v.number()\nintRoot.native = numberRoot.native\nint64Root.native = v.int64()\nbooleanRoot.native = v.boolean()\nnullRoot.native = v.null()\nbytesRoot.native = v.bytes()\nanyRoot.native = v.any()\n\n/**\n * Argument-less factories return one shared root: records are immutable, so sharing is safe. Factories\n * that take an array or map freeze it in place, so what a schema holds cannot change after declaration.\n */\nexport function string(): KString {\n\treturn stringRoot\n}\n\nexport function number(): KNumber {\n\treturn numberRoot\n}\n\n/** A number that must be an integer; one root record whose op carries the integer check. */\nexport function int(): KNumber {\n\treturn intRoot\n}\n\nexport function int64(): KInt64 {\n\treturn int64Root\n}\n\nexport function boolean(): KBoolean {\n\treturn booleanRoot\n}\n\nexport function nullValue(): KNull {\n\treturn nullRoot\n}\n\nexport function bytes(): KBytes {\n\treturn bytesRoot\n}\n\nexport function any(): KAny {\n\treturn anyRoot\n}\n\nexport function json(): KJson {\n\treturn jsonRoot\n}\n\nexport function literal<const V extends KLiteralValue>(value: V): KLiteral<V> {\n\treturn new KLiteral<V>(null, 'literal', value, undefined)\n}\n\nexport function enumOf<const V extends readonly [string, ...string[]]>(values: V): KEnum<V> {\n\tif (values.length === 0) throw new Error('k.enum() needs at least one value')\n\treturn new KEnum<V>(null, 'enum', Object.freeze(values), undefined)\n}\n\nexport function id<T extends string>(table: T): KId<T> {\n\treturn new KId<T>(null, 'id', table, undefined)\n}\n\nexport function array<E extends KType>(element: E): KArray<E> {\n\treturn new KArray<E>(null, 'array', element, undefined)\n}\n\nexport function record<K extends KRecordKey, V extends KType>(key: K, value: V): KRecord<K, V> {\n\treturn new KRecord<K, V>(null, 'record', Object.freeze([key, value]), undefined)\n}\n\nexport function union<const M extends readonly [KType, KType, ...KType[]]>(members: M): KUnion<M> {\n\treturn new KUnion<M>(null, 'union', Object.freeze(members), undefined)\n}\n\nexport function discriminatedUnion<\n\tKey extends string,\n\tconst M extends readonly [KDiscriminatedOption<Key>, ...KDiscriminatedOption<Key>[]],\n>(key: Key, options: M): KDiscriminatedUnion<Key, M> {\n\treturn new KDiscriminatedUnion<Key, M>(\n\t\tnull,\n\t\t'discriminatedUnion',\n\t\tObject.freeze({ key, options: Object.freeze(options) }),\n\t\tundefined,\n\t)\n}\n\nfunction rootOf(node: KNode): KNode {\n\tlet root = node\n\twhile (root.prev !== null) root = root.prev\n\treturn root\n}\n"],"mappings":"A,yEAqBA,IAAaA,EAAb,cAA6BC,CAAiC,CAC7D,IAAI,EAAgB,EAAwB,CAC3C,OAAO,KAAK,KAAK,MAAOC,EAAQC,CAAO,CACxC,CAEA,IAAI,EAAgB,EAAwB,CAC3C,OAAO,KAAK,KAAK,MAAOD,EAAQC,CAAO,CACxC,CAEA,OAAO,EAAgB,EAAwB,CAC9C,OAAO,KAAK,KAAK,SAAUD,EAAQC,CAAO,CAC3C,CAEA,MAAM,EAAiB,EAAwB,CAC9C,OAAO,KAAK,KAAK,QAASC,EAASD,CAAO,CAC3C,CAEA,MAAa,CACZ,OAAO,KAAK,KAAK,OAAQ,IAAA,GAAW,IAAA,EAAS,CAC9C,CAEA,aAAoB,CACnB,OAAO,KAAK,KAAK,QAAS,IAAA,GAAW,IAAA,EAAS,CAC/C,CAEA,aAAoB,CACnB,OAAO,KAAK,KAAK,QAAS,IAAA,GAAW,IAAA,EAAS,CAC/C,CACD,EAEaE,EAAb,cAA6BJ,CAAkC,CAC9D,IAAI,EAAe,EAAwB,CAC1C,OAAO,KAAK,KAAK,MAAOK,EAAOH,CAAO,CACvC,CAEA,IAAI,EAAe,EAAwB,CAC1C,OAAO,KAAK,KAAK,MAAOG,EAAOH,CAAO,CACvC,CAEA,IAAI,EAAwB,CAC3B,OAAO,KAAK,K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O,KAAM,KAAM4B,EAAO,IAAA,EAAS,CAC/C,CAEA,SAAgBC,EAAuB,EAAuB,CAC7D,OAAO,IAAI5B,EAAU,KAAM,QAAS6B,EAAS,IAAA,EAAS,CACvD,CAEA,SAAgBC,EAA8C,EAAQ,EAAyB,CAC9F,OAAO,IAAI7B,EAAc,KAAM,SAAU,OAAO,OAAO,CAAC8B,EAAK1C,CAAK,CAAC,EAAG,IAAA,EAAS,CAChF,CAEA,SAAgB2C,EAA2D,EAAuB,CACjG,OAAO,IAAI9B,EAAU,KAAM,QAAS,OAAO,OAAO+B,CAAO,EAAG,IAAA,EAAS,CACtE,CAEA,SAAgBC,EAGd,EAAU,EAAyC,CACpD,OAAO,IAAI/B,EACV,KACA,qBACA,OAAO,OAAO,CAAE,MAAK,QAAS,OAAO,OAAOgC,CAAO,CAAE,CAAC,EACtD,IAAA,EACD,CACD,CAEA,SAASrC,EAAO,EAAoB,CACnC,IAAIsC,EAAOC,EACX,KAAOD,EAAK,OAAS,MAAM,EAAOA,EAAK,KACvC,OAAOA,CACR,C"}
@@ -0,0 +1,43 @@
1
+ import { KOptional, KSchema } from "./schema.mjs";
2
+ import { Flat, KAnyDiffers, KAnyTransform, KFields, KNativeFields, KObjectOutput, KOutputFields } from "./types.mjs";
3
+ import { ObjectType, VObject } from "convex/values";
4
+ /**
5
+ * A strict object. `pick`, `omit`, `extend` and `partial` build a new object root over the same field
6
+ * schema instances, so retained fields keep their checks, defaults and normalisers; refinements declared
7
+ * on the object itself are not carried over, because they may read fields the new object lacks.
8
+ */
9
+ export declare class KObject<F extends KFields> extends KSchema<KAnyDiffers<F> extends true ? KObjectOutput<F> : ObjectType<KNativeFields<F>>, VObject<KObjectInput<F>, KNativeFields<F>>, KAnyDiffers<F>, VObject<KObjectInput<F>, KNativeFields<F>>, KAnyTransform<F>> {
10
+ readonly _or: VObject<this['_output'], KOutputFields<F>>;
11
+ readonly _oo: VObject<this['_output'], KOutputFields<F>>;
12
+ /**
13
+ * The field map, frozen when first read: it is the only handle through which code other than the
14
+ * declaring caller can reach it. Reusing a field keeps every behaviour declared on it.
15
+ */
16
+ get shape(): F;
17
+ pick<K extends keyof F & string>(...keys: K[]): KObject<Pick<F, K>>;
18
+ omit<K extends keyof F & string>(...keys: K[]): KObject<Omit<F, K>>;
19
+ /** Add or replace fields; a key present in both takes the new schema. */
20
+ extend<E extends KFields>(fields: E): KObject<Flat<Omit<F, keyof E> & E>>;
21
+ /**
22
+ * Every field optional, for patches: a field that had a default becomes plain optional, so an omitted
23
+ * field stays omitted instead of overwriting a stored value. Other field behaviour is kept.
24
+ */
25
+ partial(): KObject<{ [K in keyof F]: KOptional<F[K]>; }>;
26
+ /** Parse removes unknown keys instead of reporting them. The native validator stays strict. */
27
+ strip(): this;
28
+ }
29
+ /**
30
+ * The input type of a strict object. With no fields, `{}` would admit any object literal, so it is a
31
+ * record of `never` instead: an object with no fields accepts no keys, as v1's strict Zod object did.
32
+ */
33
+ export type KObjectInput<F extends KFields> = keyof F extends never ? {
34
+ readonly [key: string]: never;
35
+ } : ObjectType<KNativeFields<F>>;
36
+ /**
37
+ * The field map is kept by reference, not copied, and frozen in place when `.shape` is first read.
38
+ * Freezing every map at declaration costs a hidden-class transition per object shape (measured
39
+ * +0.28 MB on the 400-schema bench), so the caller's literal stays writable until then; do not mutate
40
+ * it after declaring.
41
+ */
42
+ export declare function object<F extends KFields>(fields: F): KObject<F>;
43
+ //# sourceMappingURL=object.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{KOptional as e,KSchema as t}from"./schema.mjs";var n=class extends t{get shape(){return Object.freeze(o(this))}pick(...e){let t=o(this),n={};for(let r of e)n[r]=t[r];return r(i(n))}omit(...e){let t=o(this),n={},a=new Set(e);for(let e in t)a.has(e)||(n[e]=t[e]);return r(i(n))}extend(e){return r(i({...o(this),...e}))}partial(){let e=o(this),t={};for(let n in e)t[n]=a(e[n]);return r(i(t))}strip(){return this.link(`strip`,void 0,void 0)}};function r(e){return new n(null,`object`,e,void 0)}function i(e){return e}function a(t){return new e(t,`partial`,void 0,void 0)}function o(e){let t=e;for(;t.prev!==null;)t=t.prev;return t.arg}export{n as KObject,r as object};
2
+ //# sourceMappingURL=object.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.mjs","names":["KObject","KSchema","fieldsOf","keys","fields","out","key","object","retyped","dropped","optionalOf","KOptional","field","root","node"],"sources":["../../src/k/object.ts"],"sourcesContent":["import type { ObjectType, VObject } from 'convex/values'\nimport { KOptional, KSchema } from './schema'\nimport type {\n\tFlat,\n\tKAnyDiffers,\n\tKAnyTransform,\n\tKFields,\n\tKNativeFields,\n\tKObjectOutput,\n\tKOutputFields,\n\tKNode,\n\tKType,\n} from './types'\n\n/**\n * A strict object. `pick`, `omit`, `extend` and `partial` build a new object root over the same field\n * schema instances, so retained fields keep their checks, defaults and normalisers; refinements declared\n * on the object itself are not carried over, because they may read fields the new object lacks.\n */\nexport class KObject<F extends KFields> extends KSchema<\n\tKAnyDiffers<F> extends true ? KObjectOutput<F> : ObjectType<KNativeFields<F>>,\n\tVObject<KObjectInput<F>, KNativeFields<F>>,\n\tKAnyDiffers<F>,\n\tVObject<KObjectInput<F>, KNativeFields<F>>,\n\tKAnyTransform<F>\n> {\n\tdeclare readonly _or: VObject<this['_output'], KOutputFields<F>>\n\tdeclare readonly _oo: VObject<this['_output'], KOutputFields<F>>\n\n\t/**\n\t * The field map, frozen when first read: it is the only handle through which code other than the\n\t * declaring caller can reach it. Reusing a field keeps every behaviour declared on it.\n\t */\n\t// oxlint-disable-next-line anti-slop/no-shape-in-symbol-names -- `.shape` is the field-map name apps already use (R6).\n\tget shape(): F {\n\t\treturn Object.freeze(fieldsOf(this))\n\t}\n\n\tpick<K extends keyof F & string>(...keys: K[]): KObject<Pick<F, K>> {\n\t\tconst fields = fieldsOf(this)\n\t\tconst out: Record<string, KType> = {}\n\t\tfor (const key of keys) out[key] = fields[key]\n\t\treturn object(retyped<Pick<F, K>>(out))\n\t}\n\n\tomit<K extends keyof F & string>(...keys: K[]): KObject<Omit<F, K>> {\n\t\tconst fields = fieldsOf(this)\n\t\tconst out: Record<string, KType> = {}\n\t\tconst dropped = new Set<string>(keys)\n\t\tfor (const key in fields) if (!dropped.has(key)) out[key] = fields[key]\n\t\treturn object(retyped<Omit<F, K>>(out))\n\t}\n\n\t/** Add or replace fields; a key present in both takes the new schema. */\n\textend<E extends KFields>(fields: E): KObject<Flat<Omit<F, keyof E> & E>> {\n\t\treturn object(retyped<Flat<Omit<F, keyof E> & E>>({ ...fieldsOf(this), ...fields }))\n\t}\n\n\t/**\n\t * Every field optional, for patches: a field that had a default becomes plain optional, so an omitted\n\t * field stays omitted instead of overwriting a stored value. Other field behaviour is kept.\n\t */\n\tpartial(): KObject<{ [K in keyof F]: KOptional<F[K]> }> {\n\t\tconst fields = fieldsOf(this)\n\t\tconst out: Record<string, KType> = {}\n\t\tfor (const key in fields) out[key] = optionalOf(fields[key])\n\t\treturn object(retyped<{ [K in keyof F]: KOptional<F[K]> }>(out))\n\t}\n\n\t/** Parse removes unknown keys instead of reporting them. The native validator stays strict. */\n\tstrip(): this {\n\t\treturn this.link('strip', undefined, undefined)\n\t}\n}\n\n/**\n * The input type of a strict object. With no fields, `{}` would admit any object literal, so it is a\n * record of `never` instead: an object with no fields accepts no keys, as v1's strict Zod object did.\n */\nexport type KObjectInput<F extends KFields> = keyof F extends never\n\t? { readonly [key: string]: never }\n\t: ObjectType<KNativeFields<F>>\n\n/**\n * The field map is kept by reference, not copied, and frozen in place when `.shape` is first read.\n * Freezing every map at declaration costs a hidden-class transition per object shape (measured\n * +0.28 MB on the 400-schema bench), so the caller's literal stays writable until then; do not mutate\n * it after declaring.\n */\nexport function object<F extends KFields>(fields: F): KObject<F> {\n\treturn new KObject<F>(null, 'object', fields, undefined)\n}\n\n/** The field map built by pick, omit, extend or partial, under the type its method states. */\nfunction retyped<T extends KFields>(fields: KFields): T {\n\t// SAFETY: each caller builds exactly the keys and field schemas its declared result type names.\n\treturn fields as T\n}\n\nfunction optionalOf(field: KType): KType {\n\t// SAFETY: every field value at runtime is a KSchema record created by a k factory.\n\treturn new KOptional(field as KSchema, 'partial', undefined, undefined)\n}\n\nfunction fieldsOf<F extends KFields>(node: KObject<F>): F {\n\tlet root: KNode = node\n\twhile (root.prev !== null) root = root.prev\n\t// SAFETY: k.object stores its field map as the root argument.\n\treturn root.arg as F\n}\n"],"mappings":"A,sDAmBA,IAAaA,EAAb,cAAgDC,CAM9C,CASD,IAAI,OAAW,CACd,OAAO,OAAO,OAAOC,EAAS,IAAI,CAAC,CACpC,CAEA,KAAiC,GAAGC,EAAgC,CACnE,IAAMC,EAASF,EAAS,IAAI,EACtBG,EAA6B,CAAC,EACpC,IAAK,IAAMC,KAAOH,EAAM,EAAIG,GAAOF,EAAOE,GAC1C,OAAOC,EAAOC,EAAoBH,CAAG,CAAC,CACvC,CAEA,KAAiC,GAAGF,EAAgC,CACnE,IAAMC,EAASF,EAAS,IAAI,EACtBG,EAA6B,CAAC,EAC9BI,EAAU,IAAI,IAAYN,CAAI,EACpC,IAAK,IAAMG,KAAOF,EAAaK,EAAQ,IAAIH,CAAG,IAAG,EAAIA,GAAOF,EAAOE,IACnE,OAAOC,EAAOC,EAAoBH,CAAG,CAAC,CACvC,CAGA,OAA0B,EAAgD,CACzE,OAAOE,EAAOC,EAAoC,CAAE,GAAGN,EAAS,IAAI,EAAG,GAAGE,CAAO,CAAC,CAAC,CACpF,CAMA,SAAwD,CACvD,IAAMA,EAASF,EAAS,IAAI,EACtBG,EAA6B,CAAC,EACpC,IAAK,IAAMC,KAAOF,EAAQ,EAAIE,GAAOI,EAAWN,EAAOE,EAAI,EAC3D,OAAOC,EAAOC,EAA6CH,CAAG,CAAC,CAChE,CAGA,OAAc,CACb,OAAO,KAAK,KAAK,QAAS,IAAA,GAAW,IAAA,EAAS,CAC/C,CACD,EAgBA,SAAgBE,EAA0B,EAAuB,CAChE,OAAO,IAAIP,EAAW,KAAM,SAAUI,EAAQ,IAAA,EAAS,CACxD,CAGA,SAASI,EAA2B,EAAoB,CAEvD,OAAOJ,CACR,CAEA,SAASM,EAAW,EAAqB,CAExC,OAAO,IAAIC,EAAUC,EAAkB,UAAW,IAAA,GAAW,IAAA,EAAS,CACvE,CAEA,SAASV,EAA4B,EAAqB,CACzD,IAAIW,EAAcC,EAClB,KAAOD,EAAK,OAAS,MAAM,EAAOA,EAAK,KAEvC,OAAOA,EAAK,GACb,C"}
@@ -0,0 +1,29 @@
1
+ import { KSafeParseResult } from "./issues.mjs";
2
+ import { KLiteralValue, KNode } from "./types.mjs";
3
+ /**
4
+ * The memoised parse plan of one chain record. `declared` says whether the subtree declares any
5
+ * behaviour a structurally valid value still needs (default, normaliser, check, transform, integer or
6
+ * JSON check); `transform` whether it holds a transform or pipe. A record at the tip of a run of checks
7
+ * and normalisers also records the run: the record below it and the run's normalisers and checks in
8
+ * declared order. A discriminated union root records its dispatch table.
9
+ */
10
+ export declare class KPlan {
11
+ readonly declared: boolean;
12
+ readonly transform: boolean;
13
+ readonly base: KNode | null;
14
+ readonly normalisers: readonly KNode[];
15
+ readonly checks: readonly KNode[];
16
+ readonly dispatch: ReadonlyMap<KLiteralValue, KNode> | null;
17
+ constructor(declared: boolean, transform: boolean, base: KNode | null, normalisers: readonly KNode[], checks: readonly KNode[], dispatch: ReadonlyMap<KLiteralValue, KNode> | null);
18
+ }
19
+ export declare function parseSchema(schema: KNode, input: unknown): unknown;
20
+ export declare function safeParseSchema(schema: KNode, input: unknown): KSafeParseResult<unknown>;
21
+ /**
22
+ * The function-boundary entry (KTD3): `value` has already passed the schema's native validator, so only
23
+ * planned paths are visited. With an empty plan the very same value is returned without a walk.
24
+ */
25
+ export declare function runDeclared(schema: KNode, value: unknown): unknown;
26
+ export declare function hasDeclaredBehaviour(schema: KNode): boolean;
27
+ /** Whether a transform or pipe sits anywhere in the schema's tree; table fields and return shapes reject it. */
28
+ export declare function containsTransform(schema: KNode): boolean;
29
+ //# sourceMappingURL=parse.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{membersOf as e}from"./compile.mjs";import{KConversionFailure as t,isIsoDate as n,isIsoDateTime as r,isTimestamp as i,maxTimestamp as a}from"./formats.mjs";import{KValidationError as o}from"./issues.mjs";var s=class{declared;transform;base;normalisers;checks;dispatch;constructor(e,t,n,r,i,a){this.declared=e,this.transform=t,this.base=n,this.normalisers=r,this.checks=i,this.dispatch=a}};function c(e,t){let n=new v,r=E(e,t,n,!0,!1);if(n.issues.length>0)throw new o(n.issues);return r}function l(e,t){let n=new v,r=E(e,t,n,!0,!1);return n.issues.length>0?{success:!1,issues:n.issues}:{success:!0,data:r}}function u(e,t){if(!b(e).declared)return t;let n=new v,r=E(e,t,n,!1,!1);if(n.issues.length>0)throw new o(n.issues);return r}function d(e){return b(e).declared}function f(e){return b(e).transform}const p=Symbol(`k.fail`),m=[],h=new s(!1,!1,null,m,m,null),g=new s(!0,!1,null,m,m,null),_=new s(!0,!0,null,m,m,null);var v=class{issues=[];path=[];add(e,t,n){let r=n===void 0?[...this.path]:[...this.path,...n];this.issues.push({path:r,code:e,message:t})}},y=class{context;constructor(e){this.context=e}addIssue(e){this.context.add(e.code??`custom`,e.message,e.path)}};function b(e){return e.plan??=x(e)}function x(e){if(e.prev===null)return C(e);switch(e.op){case`optional`:case`partial`:case`nullable`:case`strip`:case`describe`:return b(e.prev);case`default`:return b(e.prev).transform?_:g;case`transform`:case`pipe`:return _;default:return S(e)}}function S(e){let t=[],n=e;for(;n.prev!==null&&(de(n)||n.op===`describe`);)n.op!==`describe`&&t.push(n),n=n.prev;let r=[],i=[];for(let e=t.length-1;e>=0;e--){let n=t[e];fe(n)?r.push(n):i.push(n)}return new s(!0,b(n).transform,n,r,i,null)}function C(t){switch(t.op){case`int`:case`json`:case`isoDate`:case`isoDateTime`:case`timestamp`:return g;case`array`:return b(K(t));case`object`:{let e=q(t),n=!1,r=!1;for(let t in e){let i=b(G(e[t]));n||=i.declared,r||=i.transform}return w(n,r)}case`record`:{let[e,n]=J(t),r=b(e),i=b(n);return w(r.declared||i.declared,r.transform||i.transform)}case`union`:case`discriminatedUnion`:{let n=!1,r=!1;for(let i of e(t)){let e=b(i);n||=e.declared,r||=e.transform}return t.op===`union`?w(n,r):new s(n,r,null,m,m,ee(t))}default:return h}}function w(e,t){return t?_:e?g:h}function ee(e){let{key:t,options:n}=e.arg,r=/* @__PURE__ */ new Map;for(let e of n){let n=G(e),i=q(W(n))[t];if(i===void 0)throw Error(`k.discriminatedUnion: an option has no '${t}' field`);let a=W(G(i));if(a.op===`literal`)T(r,t,Y(a),n);else if(a.op===`enum`)for(let e of X(a))T(r,t,e,n);else throw Error(`k.discriminatedUnion: '${t}' must be a literal or enum on every option`)}return r}function T(e,t,n,r){if(e.has(n))throw Error(`k.discriminatedUnion: more than one option has '${t}' value ${JSON.stringify(String(n))}`);e.set(n,r)}function E(e,t,n,r,i){if(!r&&!b(e).declared)return t;if(e.prev===null)return ie(e,t,n,r,i);switch(e.op){case`optional`:return t===void 0&&!pe(e.prev)?void 0:E(e.prev,t,n,r,i);case`partial`:return t===void 0?void 0:E(e.prev,t,n,r,i);case`describe`:return E(e.prev,t,n,r,i);case`nullable`:return t===null?null:E(e.prev,t,n,r,i);case`default`:return t===void 0?b(e.prev).transform?e.arg:E(e.prev,e.arg,n,r,i):E(e.prev,t,n,r,i);case`strip`:return E(e.prev,t,n,r,!0);case`transform`:{let a=E(e.prev,t,n,r,i);return a===p?p:j($(e)(a),n,`transform`)}case`pipe`:{let a=E(e.prev,t,n,r,i);return a===p?p:E(K(e),a,n,!0,!1)}default:return te(e,t,n,r,i)}}function te(e,t,n,r,i){let a=b(e),o=E(a.base,t,n,r,i);if(o===p)return p;for(let e of a.normalisers)if(o=j(ne(e,o),n,`overwrite`),o===p)return p;let s=n.issues.length;for(let e of a.checks)re(e,o,n);return n.issues.length===s?o:p}function ne(e,t){switch(e.op){case`trim`:return Q(t).trim();case`lower`:return Q(t).toLowerCase();case`upper`:return Q(t).toUpperCase();default:return $(e)(t)}}function re(e,t,n){switch(e.op){case`min`:{let r=Z(e);V(t)>=r||n.add(`too_small`,U(e,`Too small: expected ${H(t,r,`>=`)}`),void 0);return}case`max`:{let r=Z(e);V(t)<=r||n.add(`too_big`,U(e,`Too big: expected ${H(t,r,`<=`)}`),void 0);return}case`length`:{let r=Z(e),i=V(t);if(i===r)return;i>r?n.add(`too_big`,U(e,`Too big: expected ${H(t,r,`==`)}`),void 0):n.add(`too_small`,U(e,`Too small: expected ${H(t,r,`==`)}`),void 0);return}case`regex`:{let r=e.arg;r.lastIndex=0,r.test(Q(t))||n.add(`invalid_format`,U(e,`Invalid string: must match ${r}`),void 0);return}case`int`:Number.isInteger(t)||n.add(`not_integer`,U(e,`Expected an integer`),void 0);return;case`refine`:if(M($(e)(t))!==!0){let t=le(e);n.add(`custom`,t?.message??`Invalid input`,t?.path)}return;case`check`:N(M($(e)(t,new y(n))))&&n.add(`custom`,`A check must be synchronous`,void 0);return;default:throw Error(`k: '${e.op}' is not a check`)}}function ie(e,t,i,a,o){switch(e.op){case`array`:return a&&!Array.isArray(t)?L(i,`array`,t):se(e,t,i,a);case`object`:return a&&!z(t)?L(i,`object`,t):ce(e,t,i,a,o);case`record`:return a&&!z(t)?L(i,`record`,t):O(e,t,i,a);case`union`:return k(e,t,i);case`discriminatedUnion`:return a&&!z(t)?L(i,`object`,t):A(e,t,i,a);case`int`:return a&&typeof t!=`number`?L(i,`number`,t):Number.isInteger(t)?t:(i.add(`not_integer`,`Expected an integer`,void 0),p);case`isoDate`:return a&&typeof t!=`string`?L(i,`string`,t):n(Q(t))?t:(i.add(`invalid_format`,`Invalid ISO date: expected YYYY-MM-DD`,void 0),p);case`isoDateTime`:return a&&typeof t!=`string`?L(i,`string`,t):r(Q(t))?t:(i.add(`invalid_format`,`Invalid ISO date-time`,void 0),p);case`timestamp`:return ae(t,i,a);case`json`:return B(t)?t:(i.add(`invalid_type`,`Expected a JSON value`,void 0),p);default:return a?oe(e,t,i):t}}function ae(e,t,n){if(n&&typeof e!=`number`)return L(t,`number`,e);let r=e;return i(r)?e:(Number.isFinite(r)?Number.isInteger(r)?r<0?t.add(`too_small`,`Expected a timestamp >= 0`,void 0):t.add(`too_big`,`Expected a timestamp <= ${a} (9999-12-31T23:59:59.999Z)`,void 0):t.add(`not_integer`,`Expected integer milliseconds`,void 0):t.add(`invalid_type`,`Expected a finite timestamp`,void 0),p)}function oe(e,t,n){switch(e.op){case`string`:case`id`:return typeof t==`string`?t:L(n,`string`,t);case`number`:return typeof t==`number`?t:L(n,`number`,t);case`int64`:return typeof t==`bigint`?t:L(n,`bigint`,t);case`boolean`:return typeof t==`boolean`?t:L(n,`boolean`,t);case`null`:return t===null?t:L(n,`null`,t);case`bytes`:return t instanceof ArrayBuffer?t:L(n,`ArrayBuffer`,t);case`any`:return t===void 0?L(n,`a value`,t):t;case`literal`:{let r=Y(e);return t===r?t:(n.add(`invalid_value`,`Invalid input: expected ${JSON.stringify(String(r))}`,void 0),p)}case`enum`:{let r=X(e);return typeof t==`string`&&r.includes(t)?t:(n.add(`invalid_value`,`Invalid option: expected one of ${r.map(ue).join(`|`)}`,void 0),p)}default:throw Error(`k: '${e.op}' is not a root operation`)}}function se(e,t,n,r){let i=K(e),a,o=!1;for(let e=0;e<t.length;e++){let s=t[e];n.path.push(e);let c=E(i,s,n,r,!1);n.path.pop(),c===p?o=!0:(a===void 0&&c!==s&&(a=t.slice(0,e)),a?.push(c))}return o?p:a??t}function ce(e,t,n,r,i){let a=q(e),o,s=!1;for(let e in a){let i=Object.hasOwn(t,e)?t[e]:void 0;n.path.push(e);let c=E(G(a[e]),i,n,r,!1);n.path.pop(),c===p?s=!0:(o===void 0&&c!==i&&(o={},D(o,t,a,e)),o!==void 0&&c!==void 0&&I(o,e,c))}let c=!1;if(r)for(let e of Object.keys(t))Object.hasOwn(a,e)||(i?c=!0:(s=!0,n.add(`unrecognized_key`,`Unrecognized key: ${JSON.stringify(e)}`,[e])));return s?p:(c&&o===void 0&&(o={},D(o,t,a,null)),o??t)}function D(e,t,n,r){for(let i in n){if(i===r)break;Object.hasOwn(t,i)&&t[i]!==void 0&&I(e,i,t[i])}}function O(e,t,n,r){let[i,a]=J(e),o=Object.keys(t),s,c=!1;for(let e=0;e<o.length;e++){let l=o[e],u=t[l];n.path.push(l);let d=E(i,l,n,r,!1);d!==p&&(r||d!==l)&&!F(Q(d))&&(n.add(`invalid_format`,P,void 0),d=p);let f=E(a,u,n,r,!1);if(n.path.pop(),d===p||f===p)c=!0;else{if(s===void 0&&(d!==l||f!==u)){s={};for(let n=0;n<e;n++)I(s,o[n],t[o[n]])}s!==void 0&&I(s,Q(d),f)}}return c?p:s??t}function k(t,n,r){let i=r.issues;for(let a of e(t)){r.issues=[];let e=E(a,n,r,!0,!1);if(e!==p)return r.issues=i,e}return r.issues=i,r.add(`invalid_union`,`Invalid input: no union member matched`,void 0),p}function A(e,t,n,r){let i=b(e),{key:a}=e.arg,o=t[a],s=i.dispatch.get(o);return s===void 0?(n.add(`invalid_union`,`Invalid discriminator value at ${JSON.stringify(a)}`,[a]),p):E(s,t,n,r,!1)}function j(e,n,r){return e instanceof t?(n.add(`invalid_value`,e.message,void 0),p):N(M(e))?(n.add(`custom`,`Async ${r} is not supported: ${r} callbacks must be synchronous`,void 0),p):e}function M(e){return N(e)&&e.then(void 0,()=>{}),e}function N(e){return e!==null&&(typeof e==`object`||typeof e==`function`)&&`then`in e&&typeof e.then==`function`}const P=`Invalid record key: Convex record keys are non-empty ASCII, at most 1024 characters, and do not start with '$' or '_'`;function F(e){if(e.length===0||e.length>1024||e[0]===`$`||e[0]===`_`)return!1;for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n>=127)return!1}return!0}function I(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})}function L(e,t,n){return e.add(`invalid_type`,`Invalid input: expected ${t}, received ${R(n)}`,void 0),p}function R(e){return e===null?`null`:Array.isArray(e)?`array`:e instanceof ArrayBuffer?`ArrayBuffer`:typeof e}function z(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function B(e){if(e===null||typeof e==`string`||typeof e==`boolean`)return!0;if(typeof e==`number`)return Number.isFinite(e);if(Array.isArray(e))return e.every(B);if(!z(e))return!1;for(let t in e)if(!B(e[t]))return!1;return!0}function V(e){return typeof e==`string`||Array.isArray(e)?e.length:Number(e)}function H(e,t,n){return typeof e==`string`?`string to have ${n}${t} characters`:Array.isArray(e)?`array to have ${n}${t} items`:`number to be ${n}${t}`}function U(e,t){let n=e.message;return typeof n==`string`?n:n?.message??t}function le(e){let t=e.message;return typeof t==`string`?{message:t}:t}function ue(e){return JSON.stringify(e)}function de(e){switch(e.op){case`min`:case`max`:case`length`:case`regex`:case`int`:case`refine`:case`check`:case`trim`:case`lower`:case`upper`:case`overwrite`:return!0;default:return!1}}function fe(e){return e.op===`trim`||e.op===`lower`||e.op===`upper`||e.op===`overwrite`}function pe(e){for(let t=e;t!==null;t=t.prev){if(t.op==="default")return!0;if(t.op===`transform`||t.op===`pipe`)return!1}return!1}function W(e){let t=e;for(;t.prev!==null;)t=t.prev;return t}function G(e){return e}function K(e){return G(e.arg)}function q(e){return e.arg}function J(e){return e.arg}function Y(e){return e.arg}function X(e){return e.arg}function Z(e){return e.arg}function Q(e){return e}function $(e){return e.arg}export{s as KPlan,f as containsTransform,d as hasDeclaredBehaviour,c as parseSchema,u as runDeclared,l as safeParseSchema};
2
+ //# sourceMappingURL=parse.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.mjs","names":["KPlan","declared","transform","base","normalisers","checks","dispatch","parseSchema","context","WalkContext","output","walk","schema","input","KValidationError","safeParseSchema","runDeclared","planOf","value","hasDeclaredBehaviour","containsTransform","FAIL","noRecords","emptyPlan","checkedPlan","transformPlan","path","below","CheckContext","issue","compilePlan","node","rootPlan","runPlan","run","isRunOp","index","record","isNormaliser","root","argSchema","fields","fieldsOf","key","plan","asSchema","combined","recordOf","keyPlan","valuePlan","member","membersOf","dispatchOf","option","options","field","rootOf","fieldRoot","dispatchTo","literalOf","enumOf","full","walkRoot","strip","defaultsBelow","callbackResult","callbackOf","walkRun","normaliser","normalise","before","check","runCheck","stringOf","limit","numberArg","sizeOf","messageOf","unitOf","size","pattern","settled","optionsOf","isThenable","invalidType","walkArray","isPlainObject","walkObject","walkRecord","walkUnion","walkDiscriminated","isIsoDate","isIsoDateTime","walkTimestamp","isJson","walkLeaf","time","isTimestamp","maxTimestamp","expected","values","quoted","element","out","failed","copyKnown","setOwn","stripped","stop","keySchema","valueSchema","keys","outputKey","isRecordKey","recordKeyMessage","issues","discriminator","KConversionFailure","kind","result","code","target","receivedOf","prototype","relation","message","fallback","current"],"sources":["../../src/k/parse.ts"],"sourcesContent":["/* oxlint-disable anti-slop/no-runtime-typeof, anti-slop/no-unknown-parameters, anti-slop/no-unknown-returns, anti-slop/no-unsafe-dictionary-type -- This module is the decoding boundary: it receives undecoded values, narrows them by representation and hands them back as the schema's output, which the typed callers in schema.ts name. */\nimport { membersOf } from './compile'\nimport { KConversionFailure, isIsoDate, isIsoDateTime, isTimestamp, maxTimestamp } from './formats'\nimport {\n\tKValidationError,\n\ttype KIssue,\n\ttype KIssueCode,\n\ttype KIssueInput,\n\ttype KSafeParseResult,\n} from './issues'\nimport type { KCheckContext } from './schema'\nimport type {\n\tKDiscriminated,\n\tKFields,\n\tKLiteralValue,\n\tKNode,\n\tKPath,\n\tKRefineOptions,\n\tKType,\n} from './types'\n\n/**\n * The memoised parse plan of one chain record. `declared` says whether the subtree declares any\n * behaviour a structurally valid value still needs (default, normaliser, check, transform, integer or\n * JSON check); `transform` whether it holds a transform or pipe. A record at the tip of a run of checks\n * and normalisers also records the run: the record below it and the run's normalisers and checks in\n * declared order. A discriminated union root records its dispatch table.\n */\nexport class KPlan {\n\treadonly declared: boolean\n\treadonly transform: boolean\n\treadonly base: KNode | null\n\treadonly normalisers: readonly KNode[]\n\treadonly checks: readonly KNode[]\n\treadonly dispatch: ReadonlyMap<KLiteralValue, KNode> | null\n\n\tconstructor(\n\t\tdeclared: boolean,\n\t\ttransform: boolean,\n\t\tbase: KNode | null,\n\t\tnormalisers: readonly KNode[],\n\t\tchecks: readonly KNode[],\n\t\tdispatch: ReadonlyMap<KLiteralValue, KNode> | null,\n\t) {\n\t\tthis.declared = declared\n\t\tthis.transform = transform\n\t\tthis.base = base\n\t\tthis.normalisers = normalisers\n\t\tthis.checks = checks\n\t\tthis.dispatch = dispatch\n\t}\n}\n\nexport function parseSchema(schema: KNode, input: unknown): unknown {\n\tconst context = new WalkContext()\n\tconst output = walk(schema, input, context, true, false)\n\tif (context.issues.length > 0) throw new KValidationError(context.issues)\n\treturn output\n}\n\nexport function safeParseSchema(schema: KNode, input: unknown): KSafeParseResult<unknown> {\n\tconst context = new WalkContext()\n\tconst output = walk(schema, input, context, true, false)\n\tif (context.issues.length > 0) return { success: false, issues: context.issues }\n\treturn { success: true, data: output }\n}\n\n/**\n * The function-boundary entry (KTD3): `value` has already passed the schema's native validator, so only\n * planned paths are visited. With an empty plan the very same value is returned without a walk.\n */\nexport function runDeclared(schema: KNode, value: unknown): unknown {\n\tif (!planOf(schema).declared) return value\n\tconst context = new WalkContext()\n\tconst output = walk(schema, value, context, false, false)\n\tif (context.issues.length > 0) throw new KValidationError(context.issues)\n\treturn output\n}\n\nexport function hasDeclaredBehaviour(schema: KNode): boolean {\n\treturn planOf(schema).declared\n}\n\n/** Whether a transform or pipe sits anywhere in the schema's tree; table fields and return shapes reject it. */\nexport function containsTransform(schema: KNode): boolean {\n\treturn planOf(schema).transform\n}\n\nconst FAIL: unique symbol = Symbol('k.fail')\nconst noRecords: readonly KNode[] = []\nconst emptyPlan = new KPlan(false, false, null, noRecords, noRecords, null)\nconst checkedPlan = new KPlan(true, false, null, noRecords, noRecords, null)\nconst transformPlan = new KPlan(true, true, null, noRecords, noRecords, null)\n\nclass WalkContext {\n\tissues: KIssue[] = []\n\treadonly path: KPath = []\n\n\tadd(code: KIssueCode, message: string, below: KPath | undefined): void {\n\t\tconst path = below === undefined ? [...this.path] : [...this.path, ...below]\n\t\tthis.issues.push({ path, code, message })\n\t}\n}\n\nclass CheckContext implements KCheckContext {\n\treadonly context: WalkContext\n\n\tconstructor(context: WalkContext) {\n\t\tthis.context = context\n\t}\n\n\taddIssue(issue: KIssueInput): void {\n\t\tthis.context.add(issue.code ?? 'custom', issue.message, issue.path)\n\t}\n}\n\nfunction planOf(node: KNode): KPlan {\n\treturn (node.plan ??= compilePlan(node))\n}\n\nfunction compilePlan(node: KNode): KPlan {\n\tif (node.prev === null) return rootPlan(node)\n\tswitch (node.op) {\n\t\tcase 'optional':\n\t\tcase 'partial':\n\t\tcase 'nullable':\n\t\tcase 'strip':\n\t\tcase 'describe':\n\t\t\treturn planOf(node.prev)\n\t\tcase 'default':\n\t\t\treturn planOf(node.prev).transform ? transformPlan : checkedPlan\n\t\tcase 'transform':\n\t\tcase 'pipe':\n\t\t\treturn transformPlan\n\t\tdefault:\n\t\t\treturn runPlan(node)\n\t}\n}\n\nfunction runPlan(node: KNode): KPlan {\n\tconst run: KNode[] = []\n\tlet base = node\n\twhile (base.prev !== null && (isRunOp(base) || base.op === 'describe')) {\n\t\tif (base.op !== 'describe') run.push(base)\n\t\tbase = base.prev\n\t}\n\tconst normalisers: KNode[] = []\n\tconst checks: KNode[] = []\n\tfor (let index = run.length - 1; index >= 0; index--) {\n\t\tconst record = run[index]\n\t\tif (isNormaliser(record)) normalisers.push(record)\n\t\telse checks.push(record)\n\t}\n\treturn new KPlan(true, planOf(base).transform, base, normalisers, checks, null)\n}\n\nfunction rootPlan(root: KNode): KPlan {\n\tswitch (root.op) {\n\t\tcase 'int':\n\t\tcase 'json':\n\t\tcase 'isoDate':\n\t\tcase 'isoDateTime':\n\t\tcase 'timestamp':\n\t\t\treturn checkedPlan\n\t\tcase 'array':\n\t\t\treturn planOf(argSchema(root))\n\t\tcase 'object': {\n\t\t\tconst fields = fieldsOf(root)\n\t\t\tlet declared = false\n\t\t\tlet transform = false\n\t\t\tfor (const key in fields) {\n\t\t\t\tconst plan = planOf(asSchema(fields[key]))\n\t\t\t\tdeclared ||= plan.declared\n\t\t\t\ttransform ||= plan.transform\n\t\t\t}\n\t\t\treturn combined(declared, transform)\n\t\t}\n\t\tcase 'record': {\n\t\t\tconst [key, value] = recordOf(root)\n\t\t\tconst keyPlan = planOf(key)\n\t\t\tconst valuePlan = planOf(value)\n\t\t\treturn combined(\n\t\t\t\tkeyPlan.declared || valuePlan.declared,\n\t\t\t\tkeyPlan.transform || valuePlan.transform,\n\t\t\t)\n\t\t}\n\t\tcase 'union':\n\t\tcase 'discriminatedUnion': {\n\t\t\tlet declared = false\n\t\t\tlet transform = false\n\t\t\tfor (const member of membersOf(root)) {\n\t\t\t\tconst plan = planOf(member)\n\t\t\t\tdeclared ||= plan.declared\n\t\t\t\ttransform ||= plan.transform\n\t\t\t}\n\t\t\tif (root.op === 'union') return combined(declared, transform)\n\t\t\treturn new KPlan(declared, transform, null, noRecords, noRecords, dispatchOf(root))\n\t\t}\n\t\tdefault:\n\t\t\treturn emptyPlan\n\t}\n}\n\nfunction combined(declared: boolean, transform: boolean): KPlan {\n\tif (transform) return transformPlan\n\treturn declared ? checkedPlan : emptyPlan\n}\n\nfunction dispatchOf(root: KNode): Map<KLiteralValue, KNode> {\n\t// SAFETY: k.discriminatedUnion stores its key and object options as the root argument.\n\tconst { key, options } = root.arg as KDiscriminated\n\tconst dispatch = new Map<KLiteralValue, KNode>()\n\tfor (const option of options) {\n\t\tconst member = asSchema(option)\n\t\tconst field = fieldsOf(rootOf(member))[key]\n\t\tif (field === undefined)\n\t\t\tthrow new Error(`k.discriminatedUnion: an option has no '${key}' field`)\n\t\tconst fieldRoot = rootOf(asSchema(field))\n\t\tif (fieldRoot.op === 'literal') dispatchTo(dispatch, key, literalOf(fieldRoot), member)\n\t\telse if (fieldRoot.op === 'enum')\n\t\t\tfor (const value of enumOf(fieldRoot)) dispatchTo(dispatch, key, value, member)\n\t\telse throw new Error(`k.discriminatedUnion: '${key}' must be a literal or enum on every option`)\n\t}\n\treturn dispatch\n}\n\n/** Two options sharing a discriminator value would make dispatch pick a branch the native union may not. */\nfunction dispatchTo(\n\tdispatch: Map<KLiteralValue, KNode>,\n\tkey: string,\n\tvalue: KLiteralValue,\n\tmember: KNode,\n): void {\n\tif (dispatch.has(value))\n\t\tthrow new Error(\n\t\t\t`k.discriminatedUnion: more than one option has '${key}' value ${JSON.stringify(String(value))}`,\n\t\t)\n\tdispatch.set(value, member)\n}\n\nfunction walk(\n\tnode: KNode,\n\tvalue: unknown,\n\tcontext: WalkContext,\n\tfull: boolean,\n\tstrip: boolean,\n): unknown {\n\tif (!full && !planOf(node).declared) return value\n\tif (node.prev === null) return walkRoot(node, value, context, full, strip)\n\tswitch (node.op) {\n\t\tcase 'optional':\n\t\t\tif (value === undefined && !defaultsBelow(node.prev)) return undefined\n\t\t\treturn walk(node.prev, value, context, full, strip)\n\t\tcase 'partial':\n\t\t\treturn value === undefined ? undefined : walk(node.prev, value, context, full, strip)\n\t\tcase 'describe':\n\t\t\treturn walk(node.prev, value, context, full, strip)\n\t\tcase 'nullable':\n\t\t\treturn value === null ? null : walk(node.prev, value, context, full, strip)\n\t\tcase 'default':\n\t\t\tif (value !== undefined) return walk(node.prev, value, context, full, strip)\n\t\t\tif (planOf(node.prev).transform) return node.arg\n\t\t\treturn walk(node.prev, node.arg, context, full, strip)\n\t\tcase 'strip':\n\t\t\treturn walk(node.prev, value, context, full, true)\n\t\tcase 'transform': {\n\t\t\tconst input = walk(node.prev, value, context, full, strip)\n\t\t\treturn input === FAIL ? FAIL : callbackResult(callbackOf(node)(input), context, 'transform')\n\t\t}\n\t\tcase 'pipe': {\n\t\t\tconst input = walk(node.prev, value, context, full, strip)\n\t\t\treturn input === FAIL ? FAIL : walk(argSchema(node), input, context, true, false)\n\t\t}\n\t\tdefault:\n\t\t\treturn walkRun(node, value, context, full, strip)\n\t}\n}\n\nfunction walkRun(\n\tnode: KNode,\n\tvalue: unknown,\n\tcontext: WalkContext,\n\tfull: boolean,\n\tstrip: boolean,\n): unknown {\n\tconst plan = planOf(node)\n\t// SAFETY: runPlan always records the base below a run.\n\tlet output = walk(plan.base as KNode, value, context, full, strip)\n\tif (output === FAIL) return FAIL\n\tfor (const normaliser of plan.normalisers) {\n\t\toutput = callbackResult(normalise(normaliser, output), context, 'overwrite')\n\t\tif (output === FAIL) return FAIL\n\t}\n\tconst before = context.issues.length\n\tfor (const check of plan.checks) runCheck(check, output, context)\n\treturn context.issues.length === before ? output : FAIL\n}\n\nfunction normalise(record: KNode, value: unknown): unknown {\n\tswitch (record.op) {\n\t\tcase 'trim':\n\t\t\treturn stringOf(value).trim()\n\t\tcase 'lower':\n\t\t\treturn stringOf(value).toLowerCase()\n\t\tcase 'upper':\n\t\t\treturn stringOf(value).toUpperCase()\n\t\tdefault:\n\t\t\treturn callbackOf(record)(value)\n\t}\n}\n\nfunction runCheck(record: KNode, value: unknown, context: WalkContext): void {\n\tswitch (record.op) {\n\t\tcase 'min': {\n\t\t\tconst limit = numberArg(record)\n\t\t\tif (!(sizeOf(value) >= limit))\n\t\t\t\tcontext.add(\n\t\t\t\t\t'too_small',\n\t\t\t\t\tmessageOf(record, `Too small: expected ${unitOf(value, limit, '>=')}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tcase 'max': {\n\t\t\tconst limit = numberArg(record)\n\t\t\tif (!(sizeOf(value) <= limit))\n\t\t\t\tcontext.add(\n\t\t\t\t\t'too_big',\n\t\t\t\t\tmessageOf(record, `Too big: expected ${unitOf(value, limit, '<=')}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tcase 'length': {\n\t\t\tconst limit = numberArg(record)\n\t\t\tconst size = sizeOf(value)\n\t\t\tif (size === limit) return\n\t\t\tif (!(size > limit))\n\t\t\t\tcontext.add(\n\t\t\t\t\t'too_small',\n\t\t\t\t\tmessageOf(record, `Too small: expected ${unitOf(value, limit, '==')}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\telse\n\t\t\t\tcontext.add(\n\t\t\t\t\t'too_big',\n\t\t\t\t\tmessageOf(record, `Too big: expected ${unitOf(value, limit, '==')}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tcase 'regex': {\n\t\t\t// SAFETY: .regex stores its pattern as the record argument.\n\t\t\tconst pattern = record.arg as RegExp\n\t\t\tpattern.lastIndex = 0\n\t\t\tif (!pattern.test(stringOf(value)))\n\t\t\t\tcontext.add(\n\t\t\t\t\t'invalid_format',\n\t\t\t\t\tmessageOf(record, `Invalid string: must match ${pattern}`),\n\t\t\t\t\tundefined,\n\t\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tcase 'int':\n\t\t\tif (!Number.isInteger(value))\n\t\t\t\tcontext.add('not_integer', messageOf(record, 'Expected an integer'), undefined)\n\t\t\treturn\n\t\tcase 'refine':\n\t\t\tif (settled(callbackOf(record)(value)) !== true) {\n\t\t\t\tconst options = optionsOf(record)\n\t\t\t\tcontext.add('custom', options?.message ?? 'Invalid input', options?.path)\n\t\t\t}\n\t\t\treturn\n\t\tcase 'check': {\n\t\t\tconst result = callbackOf(record)(value, new CheckContext(context))\n\t\t\tif (isThenable(settled(result)))\n\t\t\t\tcontext.add('custom', 'A check must be synchronous', undefined)\n\t\t\treturn\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`k: '${record.op}' is not a check`)\n\t}\n}\n\nfunction walkRoot(\n\troot: KNode,\n\tvalue: unknown,\n\tcontext: WalkContext,\n\tfull: boolean,\n\tstrip: boolean,\n): unknown {\n\tswitch (root.op) {\n\t\tcase 'array':\n\t\t\tif (full && !Array.isArray(value)) return invalidType(context, 'array', value)\n\t\t\t// SAFETY: checked above, or already validated natively at a function boundary.\n\t\t\treturn walkArray(root, value as unknown[], context, full)\n\t\tcase 'object':\n\t\t\tif (full && !isPlainObject(value)) return invalidType(context, 'object', value)\n\t\t\t// SAFETY: checked above, or already validated natively at a function boundary.\n\t\t\treturn walkObject(root, value as Record<string, unknown>, context, full, strip)\n\t\tcase 'record':\n\t\t\tif (full && !isPlainObject(value)) return invalidType(context, 'record', value)\n\t\t\t// SAFETY: checked above, or already validated natively at a function boundary.\n\t\t\treturn walkRecord(root, value as Record<string, unknown>, context, full)\n\t\tcase 'union':\n\t\t\treturn walkUnion(root, value, context)\n\t\tcase 'discriminatedUnion':\n\t\t\tif (full && !isPlainObject(value)) return invalidType(context, 'object', value)\n\t\t\t// SAFETY: checked above, or already validated natively at a function boundary.\n\t\t\treturn walkDiscriminated(root, value as Record<string, unknown>, context, full)\n\t\tcase 'int':\n\t\t\tif (full && typeof value !== 'number') return invalidType(context, 'number', value)\n\t\t\tif (Number.isInteger(value)) return value\n\t\t\tcontext.add('not_integer', 'Expected an integer', undefined)\n\t\t\treturn FAIL\n\t\tcase 'isoDate':\n\t\t\tif (full && typeof value !== 'string') return invalidType(context, 'string', value)\n\t\t\tif (isIsoDate(stringOf(value))) return value\n\t\t\tcontext.add('invalid_format', 'Invalid ISO date: expected YYYY-MM-DD', undefined)\n\t\t\treturn FAIL\n\t\tcase 'isoDateTime':\n\t\t\tif (full && typeof value !== 'string') return invalidType(context, 'string', value)\n\t\t\tif (isIsoDateTime(stringOf(value))) return value\n\t\t\tcontext.add('invalid_format', 'Invalid ISO date-time', undefined)\n\t\t\treturn FAIL\n\t\tcase 'timestamp':\n\t\t\treturn walkTimestamp(value, context, full)\n\t\tcase 'json':\n\t\t\tif (isJson(value)) return value\n\t\t\tcontext.add('invalid_type', 'Expected a JSON value', undefined)\n\t\t\treturn FAIL\n\t\tdefault:\n\t\t\treturn full ? walkLeaf(root, value, context) : value\n\t}\n}\n\nfunction walkTimestamp(value: unknown, context: WalkContext, full: boolean): unknown {\n\tif (full && typeof value !== 'number') return invalidType(context, 'number', value)\n\t// SAFETY: checked above, or already validated natively at a function boundary.\n\tconst time = value as number\n\tif (isTimestamp(time)) return value\n\tif (!Number.isFinite(time)) context.add('invalid_type', 'Expected a finite timestamp', undefined)\n\telse if (!Number.isInteger(time))\n\t\tcontext.add('not_integer', 'Expected integer milliseconds', undefined)\n\telse if (time < 0) context.add('too_small', 'Expected a timestamp >= 0', undefined)\n\telse\n\t\tcontext.add(\n\t\t\t'too_big',\n\t\t\t`Expected a timestamp <= ${maxTimestamp} (9999-12-31T23:59:59.999Z)`,\n\t\t\tundefined,\n\t\t)\n\treturn FAIL\n}\n\nfunction walkLeaf(root: KNode, value: unknown, context: WalkContext): unknown {\n\tswitch (root.op) {\n\t\tcase 'string':\n\t\tcase 'id':\n\t\t\treturn typeof value === 'string' ? value : invalidType(context, 'string', value)\n\t\tcase 'number':\n\t\t\treturn typeof value === 'number' ? value : invalidType(context, 'number', value)\n\t\tcase 'int64':\n\t\t\treturn typeof value === 'bigint' ? value : invalidType(context, 'bigint', value)\n\t\tcase 'boolean':\n\t\t\treturn typeof value === 'boolean' ? value : invalidType(context, 'boolean', value)\n\t\tcase 'null':\n\t\t\treturn value === null ? value : invalidType(context, 'null', value)\n\t\tcase 'bytes':\n\t\t\treturn value instanceof ArrayBuffer ? value : invalidType(context, 'ArrayBuffer', value)\n\t\tcase 'any':\n\t\t\treturn value === undefined ? invalidType(context, 'a value', value) : value\n\t\tcase 'literal': {\n\t\t\tconst expected = literalOf(root)\n\t\t\tif (value === expected) return value\n\t\t\tcontext.add(\n\t\t\t\t'invalid_value',\n\t\t\t\t`Invalid input: expected ${JSON.stringify(String(expected))}`,\n\t\t\t\tundefined,\n\t\t\t)\n\t\t\treturn FAIL\n\t\t}\n\t\tcase 'enum': {\n\t\t\tconst values = enumOf(root)\n\t\t\tif (typeof value === 'string' && values.includes(value)) return value\n\t\t\tcontext.add(\n\t\t\t\t'invalid_value',\n\t\t\t\t`Invalid option: expected one of ${values.map(quoted).join('|')}`,\n\t\t\t\tundefined,\n\t\t\t)\n\t\t\treturn FAIL\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`k: '${root.op}' is not a root operation`)\n\t}\n}\n\nfunction walkArray(root: KNode, value: unknown[], context: WalkContext, full: boolean): unknown {\n\tconst element = argSchema(root)\n\tlet out: unknown[] | undefined\n\tlet failed = false\n\tfor (let index = 0; index < value.length; index++) {\n\t\tconst input = value[index]\n\t\tcontext.path.push(index)\n\t\tconst output = walk(element, input, context, full, false)\n\t\tcontext.path.pop()\n\t\tif (output === FAIL) failed = true\n\t\telse {\n\t\t\tif (out === undefined && output !== input) out = value.slice(0, index)\n\t\t\tout?.push(output)\n\t\t}\n\t}\n\tif (failed) return FAIL\n\treturn out ?? value\n}\n\nfunction walkObject(\n\troot: KNode,\n\tvalue: Record<string, unknown>,\n\tcontext: WalkContext,\n\tfull: boolean,\n\tstrip: boolean,\n): unknown {\n\tconst fields = fieldsOf(root)\n\tlet out: Record<string, unknown> | undefined\n\tlet failed = false\n\tfor (const key in fields) {\n\t\tconst input = Object.hasOwn(value, key) ? value[key] : undefined\n\t\tcontext.path.push(key)\n\t\tconst output = walk(asSchema(fields[key]), input, context, full, false)\n\t\tcontext.path.pop()\n\t\tif (output === FAIL) {\n\t\t\tfailed = true\n\t\t\tcontinue\n\t\t}\n\t\tif (out === undefined && output !== input) {\n\t\t\tout = {}\n\t\t\tcopyKnown(out, value, fields, key)\n\t\t}\n\t\tif (out !== undefined && output !== undefined) setOwn(out, key, output)\n\t}\n\tlet stripped = false\n\tif (full) {\n\t\tfor (const key of Object.keys(value)) {\n\t\t\tif (Object.hasOwn(fields, key)) continue\n\t\t\tif (strip) stripped = true\n\t\t\telse {\n\t\t\t\tfailed = true\n\t\t\t\tcontext.add('unrecognized_key', `Unrecognized key: ${JSON.stringify(key)}`, [key])\n\t\t\t}\n\t\t}\n\t}\n\tif (failed) return FAIL\n\tif (stripped && out === undefined) {\n\t\tout = {}\n\t\tcopyKnown(out, value, fields, null)\n\t}\n\treturn out ?? value\n}\n\n/** Copy into `out` the known fields of `value` before `stop` in declaration order (all of them for `null`). */\nfunction copyKnown(\n\tout: Record<string, unknown>,\n\tvalue: Record<string, unknown>,\n\tfields: KFields,\n\tstop: string | null,\n): void {\n\tfor (const key in fields) {\n\t\tif (key === stop) break\n\t\tif (Object.hasOwn(value, key) && value[key] !== undefined) setOwn(out, key, value[key])\n\t}\n}\n\nfunction walkRecord(\n\troot: KNode,\n\tvalue: Record<string, unknown>,\n\tcontext: WalkContext,\n\tfull: boolean,\n): unknown {\n\tconst [keySchema, valueSchema] = recordOf(root)\n\tconst keys = Object.keys(value)\n\tlet out: Record<string, unknown> | undefined\n\tlet failed = false\n\tfor (let index = 0; index < keys.length; index++) {\n\t\tconst key = keys[index]\n\t\tconst input = value[key]\n\t\tcontext.path.push(key)\n\t\tlet outputKey = walk(keySchema, key, context, full, false)\n\t\tif (outputKey !== FAIL && (full || outputKey !== key) && !isRecordKey(stringOf(outputKey))) {\n\t\t\tcontext.add('invalid_format', recordKeyMessage, undefined)\n\t\t\toutputKey = FAIL\n\t\t}\n\t\tconst output = walk(valueSchema, input, context, full, false)\n\t\tcontext.path.pop()\n\t\tif (outputKey === FAIL || output === FAIL) {\n\t\t\tfailed = true\n\t\t\tcontinue\n\t\t}\n\t\tif (out === undefined && (outputKey !== key || output !== input)) {\n\t\t\tout = {}\n\t\t\tfor (let before = 0; before < index; before++) setOwn(out, keys[before], value[keys[before]])\n\t\t}\n\t\tif (out !== undefined) setOwn(out, stringOf(outputKey), output)\n\t}\n\tif (failed) return FAIL\n\treturn out ?? value\n}\n\nfunction walkUnion(root: KNode, value: unknown, context: WalkContext): unknown {\n\tconst issues = context.issues\n\tfor (const member of membersOf(root)) {\n\t\tcontext.issues = []\n\t\tconst output = walk(member, value, context, true, false)\n\t\tif (output !== FAIL) {\n\t\t\tcontext.issues = issues\n\t\t\treturn output\n\t\t}\n\t}\n\tcontext.issues = issues\n\tcontext.add('invalid_union', 'Invalid input: no union member matched', undefined)\n\treturn FAIL\n}\n\nfunction walkDiscriminated(\n\troot: KNode,\n\tvalue: Record<string, unknown>,\n\tcontext: WalkContext,\n\tfull: boolean,\n): unknown {\n\tconst plan = planOf(root)\n\t// SAFETY: k.discriminatedUnion stores its key with the options as the root argument.\n\tconst { key } = root.arg as KDiscriminated\n\tconst discriminator = value[key]\n\t// SAFETY: rootPlan records a dispatch table for every discriminated union root.\n\tconst option = (plan.dispatch as ReadonlyMap<unknown, KNode>).get(discriminator)\n\tif (option === undefined) {\n\t\tcontext.add('invalid_union', `Invalid discriminator value at ${JSON.stringify(key)}`, [key])\n\t\treturn FAIL\n\t}\n\treturn walk(option, value, context, full, false)\n}\n\n/** A transform or overwrite is synchronous; a promise or a conversion failure becomes an issue. */\nfunction callbackResult(output: unknown, context: WalkContext, kind: string): unknown {\n\tif (output instanceof KConversionFailure) {\n\t\tcontext.add('invalid_value', output.message, undefined)\n\t\treturn FAIL\n\t}\n\tif (!isThenable(settled(output))) return output\n\tcontext.add(\n\t\t'custom',\n\t\t`Async ${kind} is not supported: ${kind} callbacks must be synchronous`,\n\t\tundefined,\n\t)\n\treturn FAIL\n}\n\n/**\n * A check is synchronous. One that returns a promise (an untyped caller's async callback) fails, and\n * its rejection is contained so no detail escapes as an unhandled rejection.\n */\nfunction settled(result: unknown): unknown {\n\tif (isThenable(result)) result.then(undefined, () => {})\n\treturn result\n}\n\nfunction isThenable(value: unknown): value is PromiseLike<unknown> {\n\treturn (\n\t\tvalue !== null &&\n\t\t(typeof value === 'object' || typeof value === 'function') &&\n\t\t'then' in value &&\n\t\ttypeof value.then === 'function'\n\t)\n}\n\nconst recordKeyMessage =\n\t\"Invalid record key: Convex record keys are non-empty ASCII, at most 1024 characters, and do not start with '$' or '_'\"\n\n/** The Convex record key rule (`v.record`), applied to the key after normalisation. */\nfunction isRecordKey(key: string): boolean {\n\tif (key.length === 0 || key.length > 1024 || key[0] === '$' || key[0] === '_') return false\n\tfor (let index = 0; index < key.length; index++) {\n\t\tconst code = key.charCodeAt(index)\n\t\tif (code < 32 || code >= 127) return false\n\t}\n\treturn true\n}\n\n/** Write an own data property: a key taken from input (`__proto__`) never reaches a setter. */\nfunction setOwn(target: Record<string, unknown>, key: string, value: unknown): void {\n\tObject.defineProperty(target, key, {\n\t\tvalue,\n\t\tenumerable: true,\n\t\twritable: true,\n\t\tconfigurable: true,\n\t})\n}\n\nfunction invalidType(context: WalkContext, expected: string, value: unknown): typeof FAIL {\n\tcontext.add(\n\t\t'invalid_type',\n\t\t`Invalid input: expected ${expected}, received ${receivedOf(value)}`,\n\t\tundefined,\n\t)\n\treturn FAIL\n}\n\nfunction receivedOf(value: unknown): string {\n\tif (value === null) return 'null'\n\tif (Array.isArray(value)) return 'array'\n\tif (value instanceof ArrayBuffer) return 'ArrayBuffer'\n\treturn typeof value\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (value === null || typeof value !== 'object') return false\n\tconst prototype = Object.getPrototypeOf(value)\n\treturn prototype === Object.prototype || prototype === null\n}\n\nfunction isJson(value: unknown): boolean {\n\tif (value === null || typeof value === 'string' || typeof value === 'boolean') return true\n\tif (typeof value === 'number') return Number.isFinite(value)\n\tif (Array.isArray(value)) return value.every(isJson)\n\tif (!isPlainObject(value)) return false\n\tfor (const key in value) if (!isJson(value[key])) return false\n\treturn true\n}\n\nfunction sizeOf(value: unknown): number {\n\tif (typeof value === 'string' || Array.isArray(value)) return value.length\n\treturn Number(value)\n}\n\nfunction unitOf(value: unknown, limit: number, relation: string): string {\n\tif (typeof value === 'string') return `string to have ${relation}${limit} characters`\n\tif (Array.isArray(value)) return `array to have ${relation}${limit} items`\n\treturn `number to be ${relation}${limit}`\n}\n\nfunction messageOf(record: KNode, fallback: string): string {\n\tconst message = record.message\n\tif (typeof message === 'string') return message\n\treturn message?.message ?? fallback\n}\n\nfunction optionsOf(record: KNode): KRefineOptions | undefined {\n\tconst message = record.message\n\treturn typeof message === 'string' ? { message } : message\n}\n\nfunction quoted(value: string): string {\n\treturn JSON.stringify(value)\n}\n\nfunction isRunOp(record: KNode): boolean {\n\tswitch (record.op) {\n\t\tcase 'min':\n\t\tcase 'max':\n\t\tcase 'length':\n\t\tcase 'regex':\n\t\tcase 'int':\n\t\tcase 'refine':\n\t\tcase 'check':\n\t\tcase 'trim':\n\t\tcase 'lower':\n\t\tcase 'upper':\n\t\tcase 'overwrite':\n\t\t\treturn true\n\t\tdefault:\n\t\t\treturn false\n\t}\n}\n\nfunction isNormaliser(record: KNode): boolean {\n\treturn (\n\t\trecord.op === 'trim' ||\n\t\trecord.op === 'lower' ||\n\t\trecord.op === 'upper' ||\n\t\trecord.op === 'overwrite'\n\t)\n}\n\n/** Whether a default sits inside an optional wrapper, so `undefined` still receives it (as in Zod 4). */\nfunction defaultsBelow(node: KNode): boolean {\n\tfor (let current: KNode | null = node; current !== null; current = current.prev) {\n\t\tif (current.op === 'default') return true\n\t\tif (current.op === 'transform' || current.op === 'pipe') return false\n\t}\n\treturn false\n}\n\nfunction rootOf(node: KNode): KNode {\n\tlet root = node\n\twhile (root.prev !== null) root = root.prev\n\treturn root\n}\n\nfunction asSchema(value: unknown): KNode {\n\t// SAFETY: every schema reachable from a k root was created by a k factory.\n\treturn value as KNode\n}\n\nfunction argSchema(record: KNode): KNode {\n\treturn asSchema(record.arg)\n}\n\nfunction fieldsOf(root: KNode): KFields {\n\t// SAFETY: k.object stores its field map as the root argument.\n\treturn root.arg as KFields\n}\n\nfunction recordOf(root: KNode): readonly KNode[] {\n\t// SAFETY: k.record stores its key and value schemas as the root argument.\n\treturn root.arg as readonly KType[]\n}\n\nfunction literalOf(root: KNode): KLiteralValue {\n\t// SAFETY: k.literal stores its literal value as the root argument.\n\treturn root.arg as KLiteralValue\n}\n\nfunction enumOf(root: KNode): readonly string[] {\n\t// SAFETY: k.enum stores its value list as the root argument.\n\treturn root.arg as readonly string[]\n}\n\nfunction numberArg(record: KNode): number {\n\t// SAFETY: min, max and length store their numeric limit as the record argument.\n\treturn record.arg as number\n}\n\nfunction stringOf(value: unknown): string {\n\t// SAFETY: string normalisers and record keys run only after the string structure check passed.\n\treturn value as string\n}\n\nfunction callbackOf(record: KNode): (value: unknown, context?: CheckContext) => unknown {\n\t// SAFETY: refine, check, overwrite and transform store their callback as the record argument.\n\treturn record.arg as (value: unknown, context?: CheckContext) => unknown\n}\n"],"mappings":"A,kNA4BA,IAAaA,EAAb,KAAmB,CAClB,SACA,UACA,KACA,YACA,OACA,SAEA,YACC,EACA,EACA,EACA,EACA,EACA,EACC,CACD,KAAK,SAAWC,EAChB,KAAK,UAAYC,EACjB,KAAK,KAAOC,EACZ,KAAK,YAAcC,EACnB,KAAK,OAASC,EACd,KAAK,SAAWC,CACjB,CACD,EAEA,SAAgBC,EAAY,EAAe,EAAyB,CACnE,IAAMC,EAAU,IAAIC,EACdC,EAASC,EAAKC,EAAQC,EAAOL,EAAS,GAAM,EAAK,EACvD,GAAIA,EAAQ,OAAO,OAAS,EAAG,MAAM,IAAIM,EAAiBN,EAAQ,MAAM,EACxE,OAAOE,CACR,CAEA,SAAgBK,EAAgB,EAAe,EAA2C,CACzF,IAAMP,EAAU,IAAIC,EACdC,EAASC,EAAKC,EAAQC,EAAOL,EAAS,GAAM,EAAK,EAEvD,OADIA,EAAQ,OAAO,OAAS,EAAU,CAAE,QAAS,GAAO,OAAQA,EAAQ,MAAO,EACxE,CAAE,QAAS,GAAM,KAAME,CAAO,CACtC,CAMA,SAAgBM,EAAY,EAAe,EAAyB,CACnE,GAAI,CAACC,EAAOL,CAAM,CAAC,CAAC,SAAU,OAAOM,EACrC,IAAMV,EAAU,IAAIC,EACdC,EAASC,EAAKC,EAAQM,EAAOV,EAAS,GAAO,EAAK,EACxD,GAAIA,EAAQ,OAAO,OAAS,EAAG,MAAM,IAAIM,EAAiBN,EAAQ,MAAM,EACxE,OAAOE,CACR,CAEA,SAAgBS,EAAqB,EAAwB,CAC5D,OAAOF,EAAOL,CAAM,CAAC,CAAC,QACvB,CAGA,SAAgBQ,EAAkB,EAAwB,CACzD,OAAOH,EAAOL,CAAM,CAAC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