cvx-kit 0.1.35 → 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 (327) hide show
  1. package/README.md +92 -49
  2. package/dist/agent-tools.d.mts +21 -25
  3. package/dist/agent-tools.mjs +1 -1
  4. package/dist/agent-tools.mjs.map +1 -1
  5. package/dist/auth.d.mts +20 -14
  6. package/dist/auth.mjs +1 -1
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/components/approvals/_generated/api.d.mts +4 -5
  9. package/dist/components/approvals/_generated/api.mjs.map +1 -1
  10. package/dist/components/approvals/_generated/component.d.mts +0 -2
  11. package/dist/components/approvals/_generated/dataModel.d.mts +1 -3
  12. package/dist/components/approvals/_generated/server.d.mts +0 -2
  13. package/dist/components/approvals/_generated/server.mjs.map +1 -1
  14. package/dist/components/approvals/audit.d.mts +0 -1
  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 +0 -1
  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 +0 -1
  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 +1 -4
  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 +0 -1
  28. package/dist/components/approvals/functions.mjs.map +1 -1
  29. package/dist/components/approvals/health.d.mts +0 -1
  30. package/dist/components/approvals/health.mjs.map +1 -1
  31. package/dist/components/approvals/requests.d.mts +106 -123
  32. package/dist/components/approvals/requests.mjs +1 -1
  33. package/dist/components/approvals/requests.mjs.map +1 -1
  34. package/dist/components/approvals/schema.d.ts +106 -315
  35. package/dist/components/approvals/schema.js +1 -1
  36. package/dist/components/approvals/validators.d.mts +321 -393
  37. package/dist/components/approvals/validators.mjs +1 -1
  38. package/dist/components/approvals/validators.mjs.map +1 -1
  39. package/dist/components/approvals/workflow.d.mts +0 -1
  40. package/dist/components/approvals/workflow.mjs +1 -1
  41. package/dist/components/approvals/workflow.mjs.map +1 -1
  42. package/dist/components/approvals/workflow_steps.d.mts +1 -2
  43. package/dist/components/approvals/workflow_steps.mjs.map +1 -1
  44. package/dist/components/foundation/_generated/api.d.mts +3 -4
  45. package/dist/components/foundation/_generated/api.mjs.map +1 -1
  46. package/dist/components/foundation/_generated/component.d.mts +0 -2
  47. package/dist/components/foundation/_generated/dataModel.d.mts +1 -3
  48. package/dist/components/foundation/_generated/server.d.mts +0 -2
  49. package/dist/components/foundation/_generated/server.mjs.map +1 -1
  50. package/dist/components/foundation/client.d.mts +0 -1
  51. package/dist/components/foundation/client.mjs +1 -1
  52. package/dist/components/foundation/client.mjs.map +1 -1
  53. package/dist/components/foundation/convex.config.d.mts +0 -2
  54. package/dist/components/foundation/convex.config.mjs.map +1 -1
  55. package/dist/components/foundation/functions.d.mts +0 -1
  56. package/dist/components/foundation/functions.mjs.map +1 -1
  57. package/dist/components/foundation/modules/command/command.d.mts +0 -1
  58. package/dist/components/foundation/modules/command/command.mjs.map +1 -1
  59. package/dist/components/foundation/modules/command/lifecycle.d.mts +0 -2
  60. package/dist/components/foundation/modules/command/lifecycle.mjs.map +1 -1
  61. package/dist/components/foundation/modules/observability/observability.d.mts +0 -1
  62. package/dist/components/foundation/modules/observability/observability.mjs.map +1 -1
  63. package/dist/components/foundation/modules/query/query.d.mts +0 -1
  64. package/dist/components/foundation/modules/query/query.mjs.map +1 -1
  65. package/dist/components/foundation/operation.d.mts +2 -3
  66. package/dist/components/foundation/operation.mjs.map +1 -1
  67. package/dist/components/foundation/result.d.mts +0 -1
  68. package/dist/components/foundation/result.mjs.map +1 -1
  69. package/dist/components/foundation/schema.d.ts +0 -2
  70. package/dist/components/foundation/telemetry.d.mts +0 -1
  71. package/dist/components/foundation/telemetry.mjs +1 -1
  72. package/dist/components/foundation/telemetry.mjs.map +1 -1
  73. package/dist/contracts.d.mts +2 -2
  74. package/dist/contracts.mjs +1 -1
  75. package/dist/crud.d.mts +93 -97
  76. package/dist/crud.mjs +1 -1
  77. package/dist/crud.mjs.map +1 -1
  78. package/dist/effect.d.mts +2 -3
  79. package/dist/effect.mjs +1 -1
  80. package/dist/errors.d.mts +2 -4
  81. package/dist/errors.mjs +1 -1
  82. package/dist/errors.mjs.map +1 -1
  83. package/dist/filters.d.mts +1 -1
  84. package/dist/filters.mjs +1 -1
  85. package/dist/idempotency.mjs +1 -1
  86. package/dist/index.d.mts +10 -7
  87. package/dist/index.mjs +1 -1
  88. package/dist/json-schema.d.mts +40 -0
  89. package/dist/json-schema.mjs +2 -0
  90. package/dist/json-schema.mjs.map +1 -0
  91. package/dist/k/compile.d.mts +17 -0
  92. package/dist/k/compile.mjs +2 -0
  93. package/dist/k/compile.mjs.map +1 -0
  94. package/dist/k/dates.d.mts +23 -0
  95. package/dist/k/dates.mjs +2 -0
  96. package/dist/k/dates.mjs.map +1 -0
  97. package/dist/k/formats.d.mts +24 -0
  98. package/dist/k/formats.mjs +2 -0
  99. package/dist/k/formats.mjs.map +1 -0
  100. package/dist/k/index.d.mts +32 -0
  101. package/dist/k/index.mjs +2 -0
  102. package/dist/k/index.mjs.map +1 -0
  103. package/dist/k/issues.d.mts +31 -0
  104. package/dist/k/issues.mjs +2 -0
  105. package/dist/k/issues.mjs.map +1 -0
  106. package/dist/k/kinds.d.mts +81 -0
  107. package/dist/k/kinds.mjs +2 -0
  108. package/dist/k/kinds.mjs.map +1 -0
  109. package/dist/k/object.d.mts +43 -0
  110. package/dist/k/object.mjs +2 -0
  111. package/dist/k/object.mjs.map +1 -0
  112. package/dist/k/parse.d.mts +29 -0
  113. package/dist/k/parse.mjs +2 -0
  114. package/dist/k/parse.mjs.map +1 -0
  115. package/dist/k/schema.d.mts +100 -0
  116. package/dist/k/schema.mjs +2 -0
  117. package/dist/k/schema.mjs.map +1 -0
  118. package/dist/k/standard.d.mts +8 -0
  119. package/dist/k/standard.mjs +2 -0
  120. package/dist/k/standard.mjs.map +1 -0
  121. package/dist/k/types.d.mts +64 -0
  122. package/dist/k/types.mjs +1 -0
  123. package/dist/k.d.mts +8 -0
  124. package/dist/k.mjs +1 -0
  125. package/dist/middleware.d.mts +0 -2
  126. package/dist/middleware.mjs +1 -1
  127. package/dist/middleware.mjs.map +1 -1
  128. package/dist/modules/contracts/binding.d.mts +1 -2
  129. package/dist/modules/contracts/binding.mjs.map +1 -1
  130. package/dist/modules/contracts/contract.d.mts +0 -2
  131. package/dist/modules/contracts/contract.mjs.map +1 -1
  132. package/dist/modules/contracts/convex.d.mts +1 -3
  133. package/dist/modules/contracts/convex.mjs.map +1 -1
  134. package/dist/modules/contracts/domain.d.mts +1 -2
  135. package/dist/modules/contracts/domain.mjs.map +1 -1
  136. package/dist/modules/contracts/errors.d.mts +161 -2
  137. package/dist/modules/contracts/errors.mjs +1 -1
  138. package/dist/modules/contracts/errors.mjs.map +1 -1
  139. package/dist/modules/contracts/exposure.d.mts +1 -2
  140. package/dist/modules/contracts/exposure.mjs.map +1 -1
  141. package/dist/modules/contracts/idempotency.d.mts +1 -2
  142. package/dist/modules/contracts/idempotency.mjs +1 -1
  143. package/dist/modules/contracts/idempotency.mjs.map +1 -1
  144. package/dist/modules/contracts/lazy.d.mts +0 -2
  145. package/dist/modules/contracts/lazy.mjs.map +1 -1
  146. package/dist/modules/contracts/standard.d.mts +7 -5
  147. package/dist/modules/contracts/standard.mjs +1 -1
  148. package/dist/modules/contracts/standard.mjs.map +1 -1
  149. package/dist/modules/contracts/workflow.d.mts +1 -2
  150. package/dist/modules/contracts/workflow.mjs.map +1 -1
  151. package/dist/modules/effect/action.d.mts +6 -7
  152. package/dist/modules/effect/action.mjs +1 -1
  153. package/dist/modules/effect/action.mjs.map +1 -1
  154. package/dist/modules/effect/agent-tools.mjs +1 -1
  155. package/dist/modules/effect/api-runtime.d.mts +1 -2
  156. package/dist/modules/effect/api-runtime.mjs +1 -1
  157. package/dist/modules/effect/api-runtime.mjs.map +1 -1
  158. package/dist/modules/effect/api.d.mts +41 -15
  159. package/dist/modules/effect/api.mjs +1 -1
  160. package/dist/modules/effect/api.mjs.map +1 -1
  161. package/dist/modules/effect/auth.d.mts +5 -6
  162. package/dist/modules/effect/auth.mjs +1 -1
  163. package/dist/modules/effect/auth.mjs.map +1 -1
  164. package/dist/modules/effect/client.d.mts +7 -8
  165. package/dist/modules/effect/client.mjs +1 -1
  166. package/dist/modules/effect/command.d.mts +7 -5
  167. package/dist/modules/effect/command.mjs +1 -1
  168. package/dist/modules/effect/command.mjs.map +1 -1
  169. package/dist/modules/effect/crud.d.mts +272 -206
  170. package/dist/modules/effect/crud.mjs +1 -1
  171. package/dist/modules/effect/crud.mjs.map +1 -1
  172. package/dist/modules/effect/domain.d.mts +5 -6
  173. package/dist/modules/effect/domain.mjs.map +1 -1
  174. package/dist/modules/effect/errors.d.mts +4 -2
  175. package/dist/modules/effect/errors.mjs +1 -1
  176. package/dist/modules/effect/errors.mjs.map +1 -1
  177. package/dist/modules/effect/failure-audit.d.mts +2 -2
  178. package/dist/modules/effect/failure-audit.mjs +1 -1
  179. package/dist/modules/effect/failure-audit.mjs.map +1 -1
  180. package/dist/modules/effect/failures.d.mts +1 -2
  181. package/dist/modules/effect/failures.mjs.map +1 -1
  182. package/dist/modules/effect/foundation.d.mts +0 -2
  183. package/dist/modules/effect/foundation.mjs.map +1 -1
  184. package/dist/modules/effect/idempotency.d.mts +2 -3
  185. package/dist/modules/effect/idempotency.mjs +1 -1
  186. package/dist/modules/effect/idempotency.mjs.map +1 -1
  187. package/dist/modules/effect/input.d.mts +10 -0
  188. package/dist/modules/effect/input.mjs +2 -0
  189. package/dist/modules/effect/input.mjs.map +1 -0
  190. package/dist/modules/effect/normalize.d.mts +0 -2
  191. package/dist/modules/effect/normalize.mjs.map +1 -1
  192. package/dist/modules/effect/operation.d.mts +2 -3
  193. package/dist/modules/effect/operation.mjs.map +1 -1
  194. package/dist/modules/effect/query.d.mts +6 -4
  195. package/dist/modules/effect/query.mjs +1 -1
  196. package/dist/modules/effect/query.mjs.map +1 -1
  197. package/dist/modules/effect/schema.d.mts +0 -2
  198. package/dist/modules/effect/schema.mjs.map +1 -1
  199. package/dist/modules/effect/scope.d.mts +0 -2
  200. package/dist/modules/effect/scope.mjs.map +1 -1
  201. package/dist/modules/effect/workflow.d.mts +4 -5
  202. package/dist/modules/effect/workflow.mjs +1 -1
  203. package/dist/modules/effect/workflow.mjs.map +1 -1
  204. package/dist/modules/foundation/foundation.d.mts +4 -5
  205. package/dist/modules/foundation/foundation.mjs +1 -1
  206. package/dist/modules/foundation/foundation.mjs.map +1 -1
  207. package/dist/modules/foundation/operation.d.mts +2 -3
  208. package/dist/modules/foundation/operation.mjs.map +1 -1
  209. package/dist/namespace.d.mts +104 -0
  210. package/dist/namespace.mjs +2 -0
  211. package/dist/namespace.mjs.map +1 -0
  212. package/dist/oxlint/architecture.d.mts +0 -2
  213. package/dist/oxlint/architecture.mjs +1 -1
  214. package/dist/oxlint/architecture.mjs.map +1 -1
  215. package/dist/oxlint/ast.d.mts +16 -8
  216. package/dist/oxlint/ast.mjs +1 -1
  217. package/dist/oxlint/ast.mjs.map +1 -1
  218. package/dist/oxlint/components.d.mts +0 -2
  219. package/dist/oxlint/components.mjs.map +1 -1
  220. package/dist/oxlint/ownership.d.mts +0 -2
  221. package/dist/oxlint/ownership.mjs +1 -1
  222. package/dist/oxlint/ownership.mjs.map +1 -1
  223. package/dist/oxlint/reserved-files.d.mts +0 -2
  224. package/dist/oxlint/reserved-files.mjs +1 -1
  225. package/dist/oxlint/reserved-files.mjs.map +1 -1
  226. package/dist/oxlint.d.mts +0 -2
  227. package/dist/oxlint.mjs +1 -1
  228. package/dist/oxlint.mjs.map +1 -1
  229. package/dist/querying/cursors.d.mts +27 -9
  230. package/dist/querying/cursors.mjs +1 -1
  231. package/dist/querying/cursors.mjs.map +1 -1
  232. package/dist/querying/execution.d.mts +6 -7
  233. package/dist/querying/execution.mjs +1 -1
  234. package/dist/querying/execution.mjs.map +1 -1
  235. package/dist/querying/failures.d.mts +0 -2
  236. package/dist/querying/failures.mjs +1 -1
  237. package/dist/querying/failures.mjs.map +1 -1
  238. package/dist/querying/filter-boundary.d.mts +18 -9
  239. package/dist/querying/filter-boundary.mjs +1 -1
  240. package/dist/querying/filter-boundary.mjs.map +1 -1
  241. package/dist/querying/filters.d.mts +71 -35
  242. package/dist/querying/filters.mjs +1 -1
  243. package/dist/querying/filters.mjs.map +1 -1
  244. package/dist/querying/planner.d.mts +16 -20
  245. package/dist/querying/planner.mjs +1 -1
  246. package/dist/querying/planner.mjs.map +1 -1
  247. package/dist/querying/relationships.d.mts +6 -6
  248. package/dist/querying/relationships.mjs +1 -1
  249. package/dist/querying/relationships.mjs.map +1 -1
  250. package/dist/querying/search.d.mts +12 -12
  251. package/dist/querying/search.mjs +1 -1
  252. package/dist/querying/search.mjs.map +1 -1
  253. package/dist/querying/security.d.mts +2 -3
  254. package/dist/querying/security.mjs.map +1 -1
  255. package/dist/querying/shared/ast.d.mts +0 -2
  256. package/dist/querying/shared/ast.mjs.map +1 -1
  257. package/dist/querying/shared/contract.d.mts +17 -23
  258. package/dist/querying/shared/contract.mjs +1 -1
  259. package/dist/querying/shared/contract.mjs.map +1 -1
  260. package/dist/querying/shared/evaluate.d.mts +0 -2
  261. package/dist/querying/shared/evaluate.mjs.map +1 -1
  262. package/dist/querying/shared/filters.d.mts +47 -29
  263. package/dist/querying/shared/filters.mjs +1 -1
  264. package/dist/querying/shared/filters.mjs.map +1 -1
  265. package/dist/querying/shared/native-json.d.mts +7 -0
  266. package/dist/querying/shared/native-json.mjs +2 -0
  267. package/dist/querying/shared/native-json.mjs.map +1 -0
  268. package/dist/querying/shared/page.d.mts +19 -22
  269. package/dist/querying/shared/page.mjs +1 -1
  270. package/dist/querying/shared/page.mjs.map +1 -1
  271. package/dist/querying.d.mts +6 -9
  272. package/dist/querying.mjs +1 -1
  273. package/dist/querying.mjs.map +1 -1
  274. package/dist/react/failures.d.mts +0 -2
  275. package/dist/react/failures.mjs.map +1 -1
  276. package/dist/react/optimistic.d.mts +2 -3
  277. package/dist/react/optimistic.mjs.map +1 -1
  278. package/dist/react/pagination-state.d.mts +1 -2
  279. package/dist/react/pagination-state.mjs.map +1 -1
  280. package/dist/react/use-command.d.mts +0 -2
  281. package/dist/react/use-command.mjs.map +1 -1
  282. package/dist/react/use-paginated-list.d.mts +1 -3
  283. package/dist/react/use-paginated-list.mjs +1 -1
  284. package/dist/react/use-paginated-list.mjs.map +1 -1
  285. package/dist/react.d.mts +1 -1
  286. package/dist/react.mjs +1 -1
  287. package/dist/registration.d.mts +65 -0
  288. package/dist/registration.mjs +2 -0
  289. package/dist/registration.mjs.map +1 -0
  290. package/dist/relations-public.d.mts +2 -2
  291. package/dist/relations-public.mjs +1 -1
  292. package/dist/relations.d.mts +55 -46
  293. package/dist/relations.mjs +1 -1
  294. package/dist/relations.mjs.map +1 -1
  295. package/dist/state-machine.d.mts +0 -2
  296. package/dist/state-machine.mjs.map +1 -1
  297. package/dist/table.d.mts +222 -0
  298. package/dist/table.mjs +2 -0
  299. package/dist/table.mjs.map +1 -0
  300. package/dist/tenancy.d.mts +0 -2
  301. package/dist/tenancy.mjs.map +1 -1
  302. package/dist/triggers.d.mts +2 -4
  303. package/dist/triggers.mjs +1 -1
  304. package/dist/triggers.mjs.map +1 -1
  305. package/dist/webhooks.d.mts +9 -9
  306. package/dist/webhooks.mjs +1 -1
  307. package/dist/webhooks.mjs.map +1 -1
  308. package/dist/workflow.mjs +1 -1
  309. package/dist/zod.d.mts +30 -0
  310. package/dist/zod.mjs +2 -0
  311. package/dist/zod.mjs.map +1 -0
  312. package/package.json +51 -29
  313. package/dist/modules/effect/api-zod.d.mts +0 -34
  314. package/dist/modules/effect/api-zod.mjs +0 -2
  315. package/dist/modules/effect/api-zod.mjs.map +0 -1
  316. package/dist/querying/schema-snapshot.d.mts +0 -49
  317. package/dist/querying/schema-snapshot.mjs +0 -2
  318. package/dist/querying/schema-snapshot.mjs.map +0 -1
  319. package/dist/zod-convex.d.mts +0 -10
  320. package/dist/zod-convex.mjs +0 -2
  321. package/dist/zod-convex.mjs.map +0 -1
  322. package/dist/zod-registration.d.mts +0 -15
  323. package/dist/zod-registration.mjs +0 -2
  324. package/dist/zod-registration.mjs.map +0 -1
  325. package/dist/zod-table.d.mts +0 -351
  326. package/dist/zod-table.mjs +0 -2
  327. package/dist/zod-table.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-schema.mjs","names":["toJsonSchema","out","convert","schema","options","records","current","node","rootSchema","transformed","nullable","description","fallback","index","record","textOf","jsonOf","defaultOf","applyCheck","wrapped","root","maxTimestamp","literalSchema","literalOf","argNode","objectSchema","fieldsOf","key","value","membersOf","properties","required","fields","isRequired","pattern","limit","low","high","strongest","pick","items","item","json","arg"],"sources":["../src/json-schema.ts"],"sourcesContent":["/** JSON Schema for `k` schemas (KTD8): a separate entry, so core function bundles never load it. */\nimport type { JSONValue, Value } from 'convex/values'\nimport { membersOf } from './k/compile'\nimport { maxTimestamp } from './k/formats'\nimport type { KDiscriminated, KFields, KLiteralValue, KNode, KType } from './k/types'\n\n/** The JSON Schema (draft 2020-12) subset `toJsonSchema` emits. */\nexport interface JsonSchema {\n\t$schema?: string\n\ttype?: 'string' | 'number' | 'integer' | 'boolean' | 'null' | 'array' | 'object'\n\tformat?: 'date' | 'date-time'\n\tcontentEncoding?: 'base64'\n\tdescription?: string\n\tconst?: JSONValue\n\tenum?: string[]\n\tdefault?: JSONValue\n\tminLength?: number\n\tmaxLength?: number\n\tpattern?: string\n\tminimum?: number\n\tmaximum?: number\n\tminItems?: number\n\tmaxItems?: number\n\titems?: JsonSchema\n\tproperties?: Record<string, JsonSchema>\n\trequired?: string[]\n\tadditionalProperties?: boolean | JsonSchema\n\tpropertyNames?: JsonSchema\n\tanyOf?: JsonSchema[]\n\toneOf?: JsonSchema[]\n\tallOf?: JsonSchema[]\n}\n\nexport type JsonSchemaOptions = {\n\t/** Add `$schema: \"https://json-schema.org/draft/2020-12/schema\"` to the root. */\n\treadonly $schema?: boolean\n}\n\n/**\n * The input-side JSON Schema of a `k` schema, for agent tool inputs and forms: optional and defaulted\n * fields are not required (a JSON-compatible default is emitted), ids are strings, transforms and pipes\n * emit their input schema, and descriptions come from `.describe()`. Custom refinements are not\n * expressible and are omitted.\n */\nexport function toJsonSchema(schema: KType, options?: JsonSchemaOptions): JsonSchema {\n\tconst out = convert(schema)\n\tif (options?.$schema === true)\n\t\treturn { $schema: 'https://json-schema.org/draft/2020-12/schema', ...out }\n\treturn out\n}\n\nfunction convert(node: KNode): JsonSchema {\n\tconst records: KNode[] = []\n\tfor (let current: KNode | null = node; current !== null; current = current.prev)\n\t\trecords.push(current)\n\t// SAFETY: a chain always ends at a root record.\n\tconst out = rootSchema(records.pop() as KNode)\n\tlet transformed = false\n\tlet nullable = false\n\tlet description: string | undefined\n\tlet fallback: JSONValue | undefined\n\tfor (let index = records.length - 1; index >= 0; index--) {\n\t\tconst record = records[index]\n\t\tswitch (record.op) {\n\t\t\tcase 'transform':\n\t\t\tcase 'pipe':\n\t\t\t\ttransformed = true\n\t\t\t\tbreak\n\t\t\tcase 'describe':\n\t\t\t\tdescription = textOf(record)\n\t\t\t\tbreak\n\t\t\tcase 'nullable':\n\t\t\t\tnullable = true\n\t\t\t\tbreak\n\t\t\tcase 'default':\n\t\t\t\tif (!transformed) fallback = jsonOf(defaultOf(record))\n\t\t\t\tbreak\n\t\t\tcase 'min':\n\t\t\tcase 'max':\n\t\t\tcase 'length':\n\t\t\tcase 'regex':\n\t\t\tcase 'int':\n\t\t\t\tif (!transformed) applyCheck(out, record)\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\tbreak\n\t\t}\n\t}\n\tconst wrapped: JsonSchema = nullable ? { anyOf: [out, { type: 'null' }] } : out\n\tif (description !== undefined) wrapped.description = description\n\tif (fallback !== undefined) wrapped.default = fallback\n\treturn wrapped\n}\n\nfunction rootSchema(root: KNode): JsonSchema {\n\tswitch (root.op) {\n\t\tcase 'string':\n\t\tcase 'id':\n\t\t\treturn { type: 'string' }\n\t\tcase 'isoDate':\n\t\t\treturn { type: 'string', format: 'date' }\n\t\tcase 'isoDateTime':\n\t\t\treturn { type: 'string', format: 'date-time' }\n\t\tcase 'number':\n\t\t\treturn { type: 'number' }\n\t\tcase 'int':\n\t\tcase 'int64':\n\t\t\treturn { type: 'integer' }\n\t\tcase 'timestamp':\n\t\t\treturn { type: 'integer', minimum: 0, maximum: maxTimestamp }\n\t\tcase 'boolean':\n\t\t\treturn { type: 'boolean' }\n\t\tcase 'null':\n\t\t\treturn { type: 'null' }\n\t\tcase 'bytes':\n\t\t\treturn { type: 'string', contentEncoding: 'base64' }\n\t\tcase 'any':\n\t\tcase 'json':\n\t\t\treturn {}\n\t\tcase 'literal':\n\t\t\treturn literalSchema(literalOf(root))\n\t\tcase 'enum':\n\t\t\t// SAFETY: k.enum stores its value list as the root argument.\n\t\t\treturn { type: 'string', enum: [...(root.arg as readonly string[])] }\n\t\tcase 'array':\n\t\t\treturn { type: 'array', items: convert(argNode(root.arg)) }\n\t\tcase 'object':\n\t\t\treturn objectSchema(fieldsOf(root))\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\treturn { type: 'object', propertyNames: convert(key), additionalProperties: convert(value) }\n\t\t}\n\t\tcase 'union':\n\t\t\treturn { anyOf: membersOf(root).map(convert) }\n\t\tcase 'discriminatedUnion': {\n\t\t\t// SAFETY: k.discriminatedUnion stores its key and options as the root argument.\n\t\t\tconst { options } = root.arg as KDiscriminated\n\t\t\treturn { oneOf: options.map(convert) }\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`toJsonSchema: '${root.op}' is not a root operation`)\n\t}\n}\n\nfunction objectSchema(fields: KFields): JsonSchema {\n\tconst properties: Record<string, JsonSchema> = {}\n\tconst required: string[] = []\n\tfor (const key in fields) {\n\t\tproperties[key] = convert(fields[key])\n\t\tif (isRequired(fields[key])) required.push(key)\n\t}\n\tconst out: JsonSchema = { type: 'object', properties, additionalProperties: false }\n\tif (required.length > 0) out.required = required\n\treturn out\n}\n\nfunction isRequired(node: KNode): boolean {\n\tfor (let current: KNode | null = node; current !== null; current = current.prev) {\n\t\tif (current.op === 'optional' || current.op === 'partial' || current.op === 'default')\n\t\t\treturn false\n\t}\n\treturn true\n}\n\nfunction applyCheck(out: JsonSchema, record: KNode): void {\n\tif (record.op === 'int') {\n\t\tout.type = 'integer'\n\t\treturn\n\t}\n\tif (record.op === 'regex') {\n\t\t// SAFETY: .regex stores its pattern as the record argument.\n\t\tconst pattern = (record.arg as RegExp).source\n\t\tif (out.pattern === undefined) out.pattern = pattern\n\t\telse (out.allOf ??= []).push({ pattern })\n\t\treturn\n\t}\n\t// SAFETY: min, max and length store their numeric limit as the record argument.\n\tconst limit = record.arg as number\n\tconst low = record.op === 'min' || record.op === 'length'\n\tconst high = record.op === 'max' || record.op === 'length'\n\tif (out.type === 'string') {\n\t\tif (low) out.minLength = strongest(out.minLength, limit, Math.max)\n\t\tif (high) out.maxLength = strongest(out.maxLength, limit, Math.min)\n\t} else if (out.type === 'array') {\n\t\tif (low) out.minItems = strongest(out.minItems, limit, Math.max)\n\t\tif (high) out.maxItems = strongest(out.maxItems, limit, Math.min)\n\t} else {\n\t\tif (low) out.minimum = strongest(out.minimum, limit, Math.max)\n\t\tif (high) out.maximum = strongest(out.maximum, limit, Math.min)\n\t}\n}\n\n/** Repeated bounds all apply when parsing, so the schema keeps the strongest one. */\nfunction strongest(\n\tcurrent: number | undefined,\n\tlimit: number,\n\tpick: (a: number, b: number) => number,\n): number {\n\treturn current === undefined ? limit : pick(current, limit)\n}\n\nfunction literalSchema(value: KLiteralValue): JsonSchema {\n\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- A declared literal's JSON type follows its representation.\n\tswitch (typeof value) {\n\t\tcase 'string':\n\t\t\treturn { type: 'string', const: value }\n\t\tcase 'boolean':\n\t\t\treturn { type: 'boolean', const: value }\n\t\tcase 'bigint':\n\t\t\treturn { type: 'integer', const: Number(value) }\n\t\tdefault:\n\t\t\treturn { type: 'number', const: value }\n\t}\n}\n\n/** The JSON form of a declared default, or undefined when it has none (bigint, bytes). */\nfunction jsonOf(value: Value): JSONValue | undefined {\n\tif (value === null) return null\n\t// oxlint-disable-next-line anti-slop/no-runtime-typeof -- A declared default is a Convex value whose JSON form follows its representation.\n\tswitch (typeof value) {\n\t\tcase 'string':\n\t\tcase 'boolean':\n\t\t\treturn value\n\t\tcase 'number':\n\t\t\treturn Number.isFinite(value) ? value : undefined\n\t\tcase 'bigint':\n\t\t\treturn undefined\n\t\tdefault:\n\t\t\tbreak\n\t}\n\tif (value instanceof ArrayBuffer) return undefined\n\tif (Array.isArray(value)) {\n\t\tconst items: JSONValue[] = []\n\t\tfor (const item of value) {\n\t\t\tconst json = jsonOf(item)\n\t\t\tif (json === undefined) return undefined\n\t\t\titems.push(json)\n\t\t}\n\t\treturn items\n\t}\n\tconst out: { [key: string]: JSONValue } = {}\n\tfor (const [key, item] of Object.entries(value)) {\n\t\tif (item === undefined) continue\n\t\tconst json = jsonOf(item)\n\t\tif (json === undefined) return undefined\n\t\tout[key] = json\n\t}\n\treturn out\n}\n\nfunction argNode(arg: KNode['arg']): KNode {\n\t// SAFETY: k.array stores its element schema as the root argument.\n\treturn arg as KType\n}\n\nfunction defaultOf(record: KNode): Value {\n\t// SAFETY: a default record stores a Convex value as its argument.\n\treturn record.arg as Value\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 literalOf(root: KNode): KLiteralValue {\n\t// SAFETY: k.literal stores its value as the root argument.\n\treturn root.arg as KLiteralValue\n}\n\nfunction textOf(record: KNode): string {\n\t// SAFETY: a describe record stores its text as the record argument.\n\treturn record.arg as string\n}\n"],"mappings":"A,2FA4CA,SAAgBA,EAAa,EAAe,EAAyC,CACpF,IAAMC,EAAMC,EAAQC,CAAM,EAG1B,OAFIC,GAAS,UAAY,GACjB,CAAE,QAAS,+CAAgD,GAAGH,CAAI,EACnEA,CACR,CAEA,SAASC,EAAQ,EAAyB,CACzC,IAAMG,EAAmB,CAAC,EAC1B,IAAK,IAAIC,EAAwBC,EAAMD,IAAY,KAAM,EAAUA,EAAQ,KAC1ED,EAAQ,KAAKC,CAAO,EAErB,IAAML,EAAMO,EAAWH,EAAQ,IAAI,CAAU,EACzCI,EAAc,GACdC,EAAW,GACXC,EACAC,EACJ,IAAK,IAAIC,EAAQR,EAAQ,OAAS,EAAGQ,GAAS,EAAG,IAAS,CACzD,IAAMC,EAAST,EAAQQ,GACvB,OAAQC,EAAO,GAAf,CACC,IAAK,YACL,IAAK,OACJ,EAAc,GACd,MACD,IAAK,WACJ,EAAcC,EAAOD,CAAM,EAC3B,MACD,IAAK,WACJ,EAAW,GACX,MACD,IAAK,UACCL,IAAa,EAAWO,EAAOC,EAAUH,CAAM,CAAC,GACrD,MACD,IAAK,MACL,IAAK,MACL,IAAK,SACL,IAAK,QACL,IAAK,MACCL,GAAaS,EAAWjB,EAAKa,CAAM,CAI1C,CACD,CACA,IAAMK,EAAsBT,EAAW,CAAE,MAAO,CAACT,EAAK,CAAE,KAAM,MAAO,CAAC,CAAE,EAAIA,EAG5E,OAFIU,IAAgB,IAAA,KAAW,EAAQ,YAAcA,GACjDC,IAAa,IAAA,KAAW,EAAQ,QAAUA,GACvCO,CACR,CAEA,SAASX,EAAW,EAAyB,CAC5C,OAAQY,EAAK,GAAb,CACC,IAAK,SACL,IAAK,KACJ,MAAO,CAAE,KAAM,QAAS,EACzB,IAAK,UACJ,MAAO,CAAE,KAAM,SAAU,OAAQ,MAAO,EACzC,IAAK,c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AOH,EAAK,GACb,CAEA,SAASL,EAAO,EAAuB,CAEtC,OAAOD,EAAO,GACf,C"}
@@ -0,0 +1,17 @@
1
+ import { KNode } from "./types.mjs";
2
+ import { GenericValidator } from "convex/values";
3
+ /**
4
+ * Build the input-side native validator for a chain record in one walk to its root. The root's validator
5
+ * is memoised on the root, so check records reuse it; `nullable` wraps it and `optional`/`default` make it
6
+ * optional. Transform and pipe records keep their input schema's validator.
7
+ */
8
+ export declare function compileNative(node: KNode): GenericValidator;
9
+ /**
10
+ * Build the output-side native validator: a defaulted chain is required, a transform is `v.any()` and a
11
+ * pipe is its target's output side. A chain whose output side equals its input side returns the very
12
+ * same validator instance.
13
+ */
14
+ export declare function compileOutput(node: KNode): GenericValidator;
15
+ /** The members of a union or discriminated union root. */
16
+ export declare function membersOf(root: KNode): readonly KNode[];
17
+ //# sourceMappingURL=compile.d.mts.map
@@ -0,0 +1,2 @@
1
+ import{v as e}from"convex/values";const t=e.null(),n=e.any();function r(n){let r=!1,i=!1,a=n;for(;a.prev!==null;)a.op===`optional`||a.op===`partial`||a.op==="default"?r=!0:a.op===`nullable`&&(i=!0),a=a.prev;let o=a.native??=l(a);return i&&(o=e.union(o,t)),r?e.optional(o):o}function i(e){return o(e,!1)}function a(e){return e.op===`union`?e.arg:e.arg.options}function o(r,i){if(r.prev===null)return c(r);let a,o=!1,l=!1,u,f=r;for(;u===void 0;){if(f.prev===null){u=s(f),u!==f.validator&&(l=!0);break}f.op===`optional`||f.op===`partial`?a??=!0:f.op==="default"?(a??=!1,l=!0):f.op===`nullable`?o=!0:f.op===`transform`?(u=n,l=!0):f.op===`pipe`&&(u=d(f.arg),l=!0),f=f.prev}return!l&&!i?r.validator:(o&&(u=e.union(u,t)),a===!0&&!i?e.optional(u):u)}function s(e){return e.outputNative??=i(e)}function c(t){switch(t.op){case`object`:{let n=t.arg,r={},i=!1;for(let e in n){let t=n[e],a=s(t);a!==t.validator&&(i=!0),r[e]=a}return i?e.object(r):t.validator}case`array`:{let n=t.arg,r=d(n);return r===u(n)?t.validator:e.array(r)}case`record`:{let[n,r]=t.arg,i=d(r);return i===u(r)?t.validator:e.record(u(n),i)}case`union`:case`discriminatedUnion`:{let n=a(t),r=[],i=!1;for(let e of n){let t=d(e);t!==u(e)&&(i=!0),r.push(t)}return i?e.union(...r):t.validator}default:return t.validator}}function l(t){switch(t.op){case`string`:case`isoDate`:case`isoDateTime`:return e.string();case`number`:case`int`:case`timestamp`:return e.number();case`int64`:return e.int64();case`boolean`:return e.boolean();case`null`:return e.null();case`bytes`:return e.bytes();case`any`:return e.any();case`json`:return e.union(e.string(),e.number(),e.boolean(),e.null(),e.array(e.any()),e.record(e.string(),e.any()));case`literal`:return e.literal(t.arg);case`id`:return e.id(t.arg);case`enum`:return p(t.arg);case`array`:return e.array(u(t.arg));case`object`:return e.object(m(t.arg));case`record`:{let[n,r]=t.arg;return e.record(u(n),u(r))}case`union`:case`discriminatedUnion`:return e.union(...a(t).map(u));default:throw Error(`k: '${t.op}' is not a root operation`)}}function u(e){let t=e.validator;return t.isOptional===`optional`?f(e):t}function d(e){let t=s(e);return t.isOptional===`optional`?o(e,!0):t}function f(n){let r=!1,i=n;for(;i.prev!==null;)i.op===`nullable`&&(r=!0),i=i.prev;let a=i.validator;return r?e.union(a,t):a}function p(t){let n=[];for(let r of t)n.push(e.literal(r));return e.union(...n)}function m(e){let t={};for(let n in e)t[n]=e[n].validator;return t}export{r as compileNative,i as compileOutput,a as membersOf};
2
+ //# sourceMappingURL=compile.mjs.map
@@ -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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WJ,EAAE,MAAMO,EAAQR,CAAU,EAAIQ,CACjD,CAEA,SAASuB,EAAY,EAA+C,CACnE,IAAMH,EAAgC,CAAC,EACvC,IAAK,IAAMD,KAASO,EAAQN,EAAQ,KAAK3B,EAAE,QAAQ0B,CAAK,CAAC,EACzD,OAAO1B,EAAE,MAAM,GAAG2B,CAAO,CAC1B,CAEA,SAASI,EAAc,EAAqC,CAC3D,IAAMX,EAAwC,CAAC,EAC/C,IAAK,IAAMC,KAAOF,EAAQ,EAAIE,GAAOF,EAAOE,EAAI,CAAC,UACjD,OAAOD,CACR,C"}
@@ -0,0 +1,23 @@
1
+ import { KNumber, KString } from "./kinds.mjs";
2
+ import { KTransform } from "./schema.mjs";
3
+ /** A 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,EAAQF,EAAmB,KAAKG,CAAK,EAG3C,OAFID,IAAU,MAAQ,CAACE,EAAcF,EAAM,GAAIA,EAAM,GAAIA,EAAM,EAAE,GAC7D,OAAOA,EAAM,EAAE,EAAI,IAAM,OAAOA,EAAM,EAAE,EAAI,IAAM,OAAOA,EAAM,EAAE,EAAI,GAAW,GAC7EA,EAAM,KAAO,IAAA,IAAc,OAAOA,EAAM,EAAE,GAAK,IAAM,OAAOA,EAAM,EAAE,GAAK,EACjF,CAMA,MAAaI,EAAe,eAG5B,IAAaC,EAAb,KAAgC,CAC/B,QAEA,YAAY,EAAiB,CAC5B,KAAK,QAAUC,CAChB,CACD,EAEA,MAAMC,EAAa,IAAIF,EACtB,6FACD,EAGA,SAAgBG,EAAY,EAAwB,CACnD,OAAO,OAAO,UAAUP,CAAK,GAAKA,GAAS,GAAKA,GAAA,cACjD,CAGA,SAAgBQ,EAAmB,EAA4C,CAC9E,OAAOC,EAAQ,KAAK,MAAM,GAAGT,EAAM,WAAW,CAAC,CAChD,CAGA,SAAgBU,EAAuB,EAA4C,CAClF,OAAOD,EAAQ,KAAK,MAAMT,CAAK,CAAC,CACjC,CAEA,SAAgBW,EAAuB,EAA4C,CAClF,OAAOJ,EAAYP,CAAK,EAAI,IAAI,KAAKA,CAAK,CAAC,CAAC,YAAY,EAAIM,CAC7D,CAEA,SAAgBM,EAAmB,EAA4C,CAC9E,OAAOL,EAAYP,CAAK,EAAI,IAAI,KAAKA,CAAK,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,EAAG,EAAE,EAAIM,CAC1E,CAEA,SAASG,EAAQ,EAA2C,CAC3D,OAAOF,EAAYM,CAAI,EAAIA,EAAOP,CACnC,CAEA,SAASL,EAAc,EAAc,EAAe,EAAsB,CACzE,IAAMa,EAAI,OAAOC,CAAI,EACfC,EAAI,OAAOC,CAAK,EAChBC,EAAI,OAAOC,CAAG,EACpB,OAAOH,GAAK,GAAKA,GAAK,IAAME,GAAK,GAAKA,GAAKE,EAAON,EAAGE,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,C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AClC,OAAOV,CACR,CAEA,SAAgBW,GAAgB,CAC/B,OAAOV,CACR,CAEA,SAAgBW,GAAY,CAC3B,OAAOV,CACR,CAEA,SAAgBW,GAAc,CAC7B,OAAOV,CACR,CAEA,SAAgBW,EAAuC,EAAuB,CAC7E,OAAO,IAAI3B,EAAY,KAAM,UAAWP,EAAO,IAAA,EAAS,CACzD,CAEA,SAAgBmC,EAAuD,EAAqB,CAC3F,GAAIC,EAAO,SAAW,EAAG,MAAU,MAAM,mCAAmC,EAC5E,OAAO,IAAI5B,EAAS,KAAM,OAAQ,OAAO,OAAO4B,CAAM,EAAG,IAAA,EAAS,CACnE,CAEA,SAAgBC,EAAqB,EAAkB,CACtD,OAAO,IAAI3B,EAAO,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