@schema-engine/forms 0.5.1 → 0.5.3

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 (265) hide show
  1. package/README.md +6 -5
  2. package/dist/agent-tool/index.js +13 -6
  3. package/dist/agent-tool/index.js.map +2 -2
  4. package/dist/builder/types.utils.d.ts +1 -0
  5. package/dist/chunk-2MKT7OIS.js +40 -0
  6. package/dist/chunk-2MKT7OIS.js.map +7 -0
  7. package/dist/{chunk-HPPFSWIV.js → chunk-2U4WRMPB.js} +26 -22
  8. package/dist/chunk-2U4WRMPB.js.map +7 -0
  9. package/dist/{chunk-YUUDXRBW.js → chunk-3ABPK4QP.js} +62 -2
  10. package/dist/chunk-3ABPK4QP.js.map +7 -0
  11. package/dist/chunk-3BMTC224.js +21 -0
  12. package/dist/chunk-3BMTC224.js.map +7 -0
  13. package/dist/chunk-3GZKJSXI.js +49 -0
  14. package/dist/chunk-3GZKJSXI.js.map +7 -0
  15. package/dist/{chunk-NJXKMF67.js → chunk-4HSGF4WX.js} +33 -52
  16. package/dist/chunk-4HSGF4WX.js.map +7 -0
  17. package/dist/chunk-4SWCTY7K.js +8 -0
  18. package/dist/chunk-4SWCTY7K.js.map +7 -0
  19. package/dist/{chunk-KLATKWUA.js → chunk-4YANBG3M.js} +1 -1
  20. package/dist/chunk-53SXH32V.js +43 -0
  21. package/dist/chunk-53SXH32V.js.map +7 -0
  22. package/dist/{chunk-DP7SYLLI.js → chunk-6OJ46PR2.js} +15 -20
  23. package/dist/chunk-6OJ46PR2.js.map +7 -0
  24. package/dist/chunk-AAOFZ27F.js +39 -0
  25. package/dist/chunk-AAOFZ27F.js.map +7 -0
  26. package/dist/{chunk-NJTLBSTR.js → chunk-AROD3D4R.js} +1 -1
  27. package/dist/{chunk-Q5LEK7CI.js → chunk-AT2NHSY3.js} +1 -1
  28. package/dist/chunk-B2PMISHZ.js +43 -0
  29. package/dist/chunk-B2PMISHZ.js.map +7 -0
  30. package/dist/chunk-BHCSZ4VO.js +27 -0
  31. package/dist/chunk-BHCSZ4VO.js.map +7 -0
  32. package/dist/chunk-BXGE5IXF.js +38 -0
  33. package/dist/chunk-BXGE5IXF.js.map +7 -0
  34. package/dist/chunk-CW7UMF3K.js +48 -0
  35. package/dist/chunk-CW7UMF3K.js.map +7 -0
  36. package/dist/{chunk-BLFLCSG3.js → chunk-DEWI6E3O.js} +2 -2
  37. package/dist/chunk-DSPTVDHL.js +45 -0
  38. package/dist/chunk-DSPTVDHL.js.map +7 -0
  39. package/dist/chunk-DU26WGQA.js +27 -0
  40. package/dist/chunk-DU26WGQA.js.map +7 -0
  41. package/dist/{chunk-GH34XFCC.js → chunk-EO5CW7XD.js} +2 -2
  42. package/dist/{chunk-A5VLMQAK.js → chunk-ERSCXYVE.js} +2 -2
  43. package/dist/chunk-EWNYEO6T.js.map +7 -0
  44. package/dist/{chunk-CRVXBWSY.js → chunk-FGL773EA.js} +1 -1
  45. package/dist/chunk-FVW5Z2CC.js +36 -0
  46. package/dist/chunk-FVW5Z2CC.js.map +7 -0
  47. package/dist/chunk-GDUF2SWI.js +32 -0
  48. package/dist/chunk-GDUF2SWI.js.map +7 -0
  49. package/dist/{chunk-GQHMU3AR.js → chunk-HEWLTCU4.js} +4 -4
  50. package/dist/{chunk-6R2MBQPL.js → chunk-HKLDRUFN.js} +4 -1
  51. package/dist/{chunk-6R2MBQPL.js.map → chunk-HKLDRUFN.js.map} +2 -2
  52. package/dist/{chunk-J2FC5K4B.js → chunk-IHXXPIFD.js} +1 -2
  53. package/dist/chunk-IHXXPIFD.js.map +7 -0
  54. package/dist/{chunk-GRZU6F7Q.js → chunk-KANWAQNI.js} +33 -38
  55. package/dist/chunk-KANWAQNI.js.map +7 -0
  56. package/dist/chunk-KWQJFQII.js +52 -0
  57. package/dist/chunk-KWQJFQII.js.map +7 -0
  58. package/dist/{chunk-PH3LWLYN.js → chunk-MFZYG6DN.js} +3 -2
  59. package/dist/chunk-MFZYG6DN.js.map +7 -0
  60. package/dist/{chunk-WUTGZYP4.js → chunk-MG7VFU6V.js} +2 -2
  61. package/dist/chunk-OG3OLZ5R.js +184 -0
  62. package/dist/chunk-OG3OLZ5R.js.map +7 -0
  63. package/dist/{chunk-WLDCYUN6.js → chunk-OKJLJ3GI.js} +1 -1
  64. package/dist/chunk-QDU55RCZ.js.map +7 -0
  65. package/dist/chunk-QFQB5EBY.js +38 -0
  66. package/dist/chunk-QFQB5EBY.js.map +7 -0
  67. package/dist/{chunk-6IZYNHZ3.js → chunk-RDQFBY6S.js} +45 -31
  68. package/dist/chunk-RDQFBY6S.js.map +7 -0
  69. package/dist/chunk-RMX7C43O.js.map +7 -0
  70. package/dist/chunk-T5JAAPFB.js +40 -0
  71. package/dist/chunk-T5JAAPFB.js.map +7 -0
  72. package/dist/chunk-TDXFT6Q5.js +57 -0
  73. package/dist/chunk-TDXFT6Q5.js.map +7 -0
  74. package/dist/{chunk-JA5ET6MC.js → chunk-TWQU2IGF.js} +6 -6
  75. package/dist/chunk-V3GYAG33.js +12 -0
  76. package/dist/chunk-V3GYAG33.js.map +7 -0
  77. package/dist/{chunk-V5H7L5PJ.js → chunk-WHLID5BN.js} +59 -23
  78. package/dist/{chunk-V5H7L5PJ.js.map → chunk-WHLID5BN.js.map} +2 -2
  79. package/dist/chunk-XKINCUXT.js +51 -0
  80. package/dist/chunk-XKINCUXT.js.map +7 -0
  81. package/dist/chunk-XLEOTW6H.js +50 -0
  82. package/dist/chunk-XLEOTW6H.js.map +7 -0
  83. package/dist/chunk-YHSOS3IH.js +53 -0
  84. package/dist/chunk-YHSOS3IH.js.map +7 -0
  85. package/dist/chunk-YKXOBPSU.js +19 -0
  86. package/dist/chunk-YKXOBPSU.js.map +7 -0
  87. package/dist/{chunk-ZYP3MIH3.js → chunk-YW2KZUAM.js} +5 -3
  88. package/dist/chunk-YW2KZUAM.js.map +7 -0
  89. package/dist/{chunk-E4VONSLO.js.map → chunk-YZFL6JPZ.js.map} +2 -2
  90. package/dist/{chunk-6EYX257T.js → chunk-Z5KZDT7V.js} +1 -1
  91. package/dist/chunk-ZZ4KB6GE.js +47 -0
  92. package/dist/chunk-ZZ4KB6GE.js.map +7 -0
  93. package/dist/default-elements/array-elements.d.ts +793 -0
  94. package/dist/default-elements/array-elements.js +34 -0
  95. package/dist/default-elements/array-elements.js.map +7 -0
  96. package/dist/default-elements/checkbox-group.d.ts +812 -0
  97. package/dist/default-elements/checkbox-group.js +40 -0
  98. package/dist/default-elements/checkbox-group.js.map +7 -0
  99. package/dist/default-elements/checkbox.d.ts +788 -0
  100. package/dist/default-elements/checkbox.js +38 -0
  101. package/dist/default-elements/checkbox.js.map +7 -0
  102. package/dist/default-elements/combobox.d.ts +806 -0
  103. package/dist/default-elements/combobox.js +40 -0
  104. package/dist/default-elements/combobox.js.map +7 -0
  105. package/dist/default-elements/define-contract.d.ts +25 -0
  106. package/dist/default-elements/define-contract.js +8 -0
  107. package/dist/default-elements/define-contract.js.map +7 -0
  108. package/dist/default-elements/drop-zone.d.ts +789 -0
  109. package/dist/default-elements/drop-zone.js +40 -0
  110. package/dist/default-elements/drop-zone.js.map +7 -0
  111. package/dist/default-elements/fieldset.d.ts +783 -0
  112. package/dist/default-elements/fieldset.js +34 -0
  113. package/dist/default-elements/fieldset.js.map +7 -0
  114. package/dist/default-elements/index.d.ts +75 -0
  115. package/dist/default-elements/index.js +240 -0
  116. package/dist/default-elements/index.js.map +7 -0
  117. package/dist/default-elements/input-otp.d.ts +1298 -0
  118. package/dist/default-elements/input-otp.js +38 -0
  119. package/dist/default-elements/input-otp.js.map +7 -0
  120. package/dist/default-elements/input.d.ts +843 -0
  121. package/dist/default-elements/input.js +40 -0
  122. package/dist/default-elements/input.js.map +7 -0
  123. package/dist/default-elements/masked-input.d.ts +835 -0
  124. package/dist/default-elements/masked-input.js +40 -0
  125. package/dist/default-elements/masked-input.js.map +7 -0
  126. package/dist/default-elements/number.d.ts +821 -0
  127. package/dist/default-elements/number.js +38 -0
  128. package/dist/default-elements/number.js.map +7 -0
  129. package/dist/default-elements/phone-input.d.ts +785 -0
  130. package/dist/default-elements/phone-input.js +40 -0
  131. package/dist/default-elements/phone-input.js.map +7 -0
  132. package/dist/default-elements/radio.d.ts +812 -0
  133. package/dist/default-elements/radio.js +40 -0
  134. package/dist/default-elements/radio.js.map +7 -0
  135. package/dist/default-elements/select.d.ts +809 -0
  136. package/dist/default-elements/select.js +40 -0
  137. package/dist/default-elements/select.js.map +7 -0
  138. package/dist/default-elements/slider.d.ts +800 -0
  139. package/dist/default-elements/slider.js +38 -0
  140. package/dist/default-elements/slider.js.map +7 -0
  141. package/dist/default-elements/submission-alert.d.ts +804 -0
  142. package/dist/default-elements/submission-alert.js +36 -0
  143. package/dist/default-elements/submission-alert.js.map +7 -0
  144. package/dist/default-elements/submit-button.d.ts +771 -0
  145. package/dist/default-elements/submit-button.js +34 -0
  146. package/dist/default-elements/submit-button.js.map +7 -0
  147. package/dist/default-elements/switch.d.ts +794 -0
  148. package/dist/default-elements/switch.js +38 -0
  149. package/dist/default-elements/switch.js.map +7 -0
  150. package/dist/default-elements/textarea.d.ts +815 -0
  151. package/dist/default-elements/textarea.js +40 -0
  152. package/dist/default-elements/textarea.js.map +7 -0
  153. package/dist/engine/build-form-engine.js +22 -18
  154. package/dist/engine/create-form-engine.js +23 -19
  155. package/dist/engine/form-engine.js +22 -18
  156. package/dist/engine/index.js +25 -21
  157. package/dist/engine/schema-artifacts.js +6 -2
  158. package/dist/engine/step-machine.d.ts +10 -0
  159. package/dist/engine/step-machine.js +5 -5
  160. package/dist/engine/submission-schema.js +8 -6
  161. package/dist/engine/value-validation.js +4 -4
  162. package/dist/index.d.ts +4 -2
  163. package/dist/index.js +40 -31
  164. package/dist/index.js.map +3 -3
  165. package/dist/lib/export-schema.d.ts +128 -0
  166. package/dist/lib/export-schema.js +15 -0
  167. package/dist/lib/export-schema.js.map +7 -0
  168. package/dist/lib/exported-recipe-view.d.ts +17 -0
  169. package/dist/lib/exported-recipe-view.js +10 -0
  170. package/dist/lib/exported-recipe-view.js.map +7 -0
  171. package/dist/lib/field-scope.js +2 -2
  172. package/dist/lib/grid-track-items.d.ts +26 -0
  173. package/dist/lib/grid-track-items.js +10 -0
  174. package/dist/lib/grid-track-items.js.map +7 -0
  175. package/dist/lib/is-zod-type.d.ts +5 -0
  176. package/dist/lib/is-zod-type.js +6 -0
  177. package/dist/lib/is-zod-type.js.map +7 -0
  178. package/dist/lib/submission-shape.js +3 -3
  179. package/dist/lib/validate-form/grid-checks.d.ts +24 -0
  180. package/dist/lib/validate-form/grid-checks.js +6 -1
  181. package/dist/lib/validate-form/parse-elements.d.ts +9 -7
  182. package/dist/lib/validate-form/parse-elements.js +5 -6
  183. package/dist/lib/validate-form/parse-owner-actions.js +1 -1
  184. package/dist/lib/validate-form/parse-view.js +1 -1
  185. package/dist/lib/validate-form/step-checks.js +3 -3
  186. package/dist/lib/validate-form/validation-error.d.ts +1 -10
  187. package/dist/lib/validate-form/validation-error.js +3 -5
  188. package/dist/lib/validate-form.d.ts +1 -1
  189. package/dist/lib/validate-form.js +14 -15
  190. package/dist/lib/zod-json-schema.d.ts +0 -4
  191. package/dist/lib/zod-json-schema.js +7 -5
  192. package/dist/recipes/built-in-specs.js +2 -2
  193. package/dist/recipes/built-in.js +2 -2
  194. package/dist/recipes/define-form-recipe.d.ts +2 -2
  195. package/dist/recipes/define-form-recipe.js +1 -1
  196. package/dist/recipes/define-recipe-spec.d.ts +3 -2
  197. package/dist/recipes/define-recipe-spec.js +1 -1
  198. package/dist/recipes/index.js +8 -8
  199. package/dist/recipes/types.d.ts +2 -2
  200. package/dist/recipes/view-model.d.ts +2 -2
  201. package/dist/recipes/view-model.js +6 -6
  202. package/dist/runtime/create-form-runtime.js +14 -13
  203. package/dist/runtime/index.d.ts +1 -1
  204. package/dist/runtime/index.js +14 -13
  205. package/dist/runtime/types.d.ts +11 -0
  206. package/dist/runtime/types.js +1 -1
  207. package/dist/schemas/base-field.d.ts +14 -6
  208. package/dist/schemas/base-field.js +5 -5
  209. package/dist/schemas/form-config-shape.d.ts +33 -21
  210. package/dist/schemas/form-config-shape.js +5 -5
  211. package/dist/schemas/form-config.d.ts +55 -35
  212. package/dist/schemas/form-config.js +5 -5
  213. package/dist/schemas/index.js +5 -5
  214. package/dist/schemas/validation/dependencies.js +4 -4
  215. package/dist/schemas/validation/index.js +5 -5
  216. package/dist/schemas/validation/utils.js +3 -3
  217. package/dist/schemas/validation/validation-registry.d.ts +1 -1
  218. package/dist/schemas/validation/validation-registry.js +4 -4
  219. package/dist/state-container/create-form-state-container.js +8 -8
  220. package/dist/state-container/index.js +9 -9
  221. package/dist/state-container/selectors.js +5 -5
  222. package/dist/state-container/submission.js +6 -6
  223. package/dist/testing/form-state-container-conformance.js +7 -7
  224. package/dist/testing/index.js +7 -7
  225. package/dist/types/define-element.d.ts +2 -2
  226. package/dist/types/define-element.js +1 -1
  227. package/dist/types/index.js +1 -1
  228. package/dist/types/registration.d.ts +7 -0
  229. package/package.json +8 -4
  230. package/skill/SKILL.md +26 -25
  231. package/skill/reference/forms.md +7 -7
  232. package/dist/chunk-25PLQDKN.js +0 -45
  233. package/dist/chunk-25PLQDKN.js.map +0 -7
  234. package/dist/chunk-2XWISGGM.js.map +0 -7
  235. package/dist/chunk-6IZYNHZ3.js.map +0 -7
  236. package/dist/chunk-DP7SYLLI.js.map +0 -7
  237. package/dist/chunk-GRZU6F7Q.js.map +0 -7
  238. package/dist/chunk-HPPFSWIV.js.map +0 -7
  239. package/dist/chunk-J2FC5K4B.js.map +0 -7
  240. package/dist/chunk-K22S7IZR.js.map +0 -7
  241. package/dist/chunk-NJXKMF67.js.map +0 -7
  242. package/dist/chunk-PH3LWLYN.js.map +0 -7
  243. package/dist/chunk-PHNMDWSK.js.map +0 -7
  244. package/dist/chunk-PN5EH6DM.js +0 -36
  245. package/dist/chunk-PN5EH6DM.js.map +0 -7
  246. package/dist/chunk-YUUDXRBW.js.map +0 -7
  247. package/dist/chunk-ZYP3MIH3.js.map +0 -7
  248. package/dist/{chunk-KLATKWUA.js.map → chunk-4YANBG3M.js.map} +0 -0
  249. package/dist/{chunk-S7I76ISM.js → chunk-7QLR5WM3.js} +3 -3
  250. /package/dist/{chunk-S7I76ISM.js.map → chunk-7QLR5WM3.js.map} +0 -0
  251. /package/dist/{chunk-NJTLBSTR.js.map → chunk-AROD3D4R.js.map} +0 -0
  252. /package/dist/{chunk-Q5LEK7CI.js.map → chunk-AT2NHSY3.js.map} +0 -0
  253. /package/dist/{chunk-BLFLCSG3.js.map → chunk-DEWI6E3O.js.map} +0 -0
  254. /package/dist/{chunk-GH34XFCC.js.map → chunk-EO5CW7XD.js.map} +0 -0
  255. /package/dist/{chunk-A5VLMQAK.js.map → chunk-ERSCXYVE.js.map} +0 -0
  256. /package/dist/{chunk-K22S7IZR.js → chunk-EWNYEO6T.js} +0 -0
  257. /package/dist/{chunk-CRVXBWSY.js.map → chunk-FGL773EA.js.map} +0 -0
  258. /package/dist/{chunk-GQHMU3AR.js.map → chunk-HEWLTCU4.js.map} +0 -0
  259. /package/dist/{chunk-WUTGZYP4.js.map → chunk-MG7VFU6V.js.map} +0 -0
  260. /package/dist/{chunk-WLDCYUN6.js.map → chunk-OKJLJ3GI.js.map} +0 -0
  261. /package/dist/{chunk-2XWISGGM.js → chunk-QDU55RCZ.js} +0 -0
  262. /package/dist/{chunk-PHNMDWSK.js → chunk-RMX7C43O.js} +0 -0
  263. /package/dist/{chunk-JA5ET6MC.js.map → chunk-TWQU2IGF.js.map} +0 -0
  264. /package/dist/{chunk-E4VONSLO.js → chunk-YZFL6JPZ.js} +0 -0
  265. /package/dist/{chunk-6EYX257T.js.map → chunk-Z5KZDT7V.js.map} +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/engine/step-machine.ts"],
4
+ "sourcesContent": ["import { collectStepFieldPaths, type ValidationStep } from './value-validation';\n\n/**\n * How freely a wizard moves forward.\n *\n * @remarks\n * `'linear'` reaches only steps already visited and validates every step on the way; `'free'` reaches any\n * active step without validating. Going back is always allowed and `next()` validates in both.\n */\nexport type StepNavigationMode = 'linear' | 'free';\n\n/**\n * One step of a form as a renderer reads it.\n *\n * @remarks\n * Only `visited` and `complete` are stored, by step id. `skipped` is derived from the values (the step's\n * constraints hide it) and `invalid` from the errors recorded at its fields, so neither can go stale.\n * `title` is the step config's, so a stepper reused across forms reads it here instead of looking it up by `id`.\n */\nexport interface FormStepState {\n\treadonly id: string;\n\t/**\n\t * The step config's `title`, as authored: the engine does not translate it.\n\t *\n\t * @remarks\n\t * `undefined` when the runtime was given a step with no title. A form config requires one, so every step of a\n\t * validated config has it; only a hand-built runtime config can leave it out, and a stepper may fall back to `id`.\n\t */\n\treadonly title?: string;\n\t/** Its constraints hide it: it is passed over and its fields take no part. */\n\treadonly skipped: boolean;\n\treadonly visited: boolean;\n\t/** `next()` validated it and moved on. */\n\treadonly complete: boolean;\n\t/** An error is recorded at one of its fields. */\n\treadonly invalid: boolean;\n\t/** `goTo` can move there: an active step other than the current one that is before it, or after it when the form's `navigation` is `'free'` or the step was visited. */\n\treadonly reachable: boolean;\n}\n\n/** What the runtime stores of the steps: where the user is, and which steps were visited and completed, by id. */\nexport interface StepProgress {\n\treadonly current: string;\n\treadonly visited: readonly string[];\n\treadonly complete: readonly string[];\n}\n\n/** Progress at the start: the first step is current and visited. */\nexport const startProgress = (first: string): StepProgress => ({ current: first, visited: [first], complete: [] });\n\nconst including = (ids: readonly string[], added: readonly string[]): readonly string[] =>\n\tadded.every((id) => ids.includes(id)) ? ids : [...ids, ...added.filter((id) => !ids.includes(id))];\n\n/** Progress after moving to `to`, which becomes visited, with `completed` marked complete. */\nexport function moveProgress(progress: StepProgress, to: string, completed: readonly string[] = []): StepProgress {\n\tconst visited = including(progress.visited, [to]);\n\tconst complete = including(progress.complete, completed);\n\treturn progress.current === to && visited === progress.visited && complete === progress.complete\n\t\t? progress\n\t\t: { current: to, visited, complete };\n}\n\n/** The steps as renderers read them, from the stored progress and what the values and errors say. */\nexport function deriveStepStates(\n\tsteps: readonly { readonly id: string; readonly title?: string }[],\n\tprogress: StepProgress,\n\tderived: { readonly skipped: readonly string[]; readonly invalid: readonly string[] },\n\tmode: StepNavigationMode,\n): FormStepState[] {\n\tconst at = steps.findIndex(({ id }) => id === progress.current);\n\treturn steps.map(({ id, title }, index) => {\n\t\tconst skipped = derived.skipped.includes(id);\n\t\tconst visited = progress.visited.includes(id);\n\t\treturn {\n\t\t\tid,\n\t\t\ttitle,\n\t\t\tskipped,\n\t\t\tvisited,\n\t\t\tcomplete: progress.complete.includes(id),\n\t\t\tinvalid: derived.invalid.includes(id),\n\t\t\treachable: !skipped && id !== progress.current && (index < at || mode === 'free' || visited),\n\t\t};\n\t});\n}\n\n/** The ids of the steps that are not skipped, in order. */\nexport const activeStepIds = (states: readonly FormStepState[]): string[] =>\n\tstates.filter(({ skipped }) => !skipped).map(({ id }) => id);\n\n/** The nearest active step after `id`, which may itself be skipped, or `undefined` on the last one. */\nexport function stepAfter(states: readonly FormStepState[], id: string): string | undefined {\n\tconst at = states.findIndex((state) => state.id === id);\n\treturn states.slice(at + 1).find(({ skipped }) => !skipped)?.id;\n}\n\n/** The nearest active step before `id`, which may itself be skipped, or `undefined` on the first one. */\nexport function stepBefore(states: readonly FormStepState[], id: string): string | undefined {\n\tconst at = states.findIndex((state) => state.id === id);\n\treturn states.slice(0, Math.max(at, 0)).findLast(({ skipped }) => !skipped)?.id;\n}\n\n/**\n * The ids of the steps that have an error recorded at one of their fields.\n *\n * @remarks Fields are read as `collectStepFieldPaths` expands them over the live rows.\n */\nexport function stepsWithErrors(\n\tsteps: readonly (ValidationStep & { readonly id: string })[],\n\tvalues: Record<string, unknown>,\n\terrors: Readonly<Record<string, unknown>>,\n): string[] {\n\treturn steps\n\t\t.filter((step) => collectStepFieldPaths(step, values).some((path) => Object.hasOwn(errors, path)))\n\t\t.map(({ id }) => id);\n}\n"],
5
+ "mappings": ";;;;;AAgDO,IAAM,g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U,MAAM,OAAO,EAAE;AACtD,SAAO,OAAO,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,QAAQ,MAAM,CAAC,OAAO,GAAG;AAC9D;AAGO,SAAS,WAAW,QAAkC,IAAgC;AAC5F,QAAM,KAAK,OAAO,UAAU,CAAC,UAAU,MAAM,OAAO,EAAE;AACtD,SAAO,OAAO,MAAM,GAAG,KAAK,IAAI,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,QAAQ,MAAM,CAAC,OAAO,GAAG;AAC9E;AAOO,SAAS,gBACf,OACA,QACA,QACW;AACX,SAAO,MACL,OAAO,CAAC,SAAS,sBAAsB,MAAM,MAAM,EAAE,KAAK,CAAC,SAAS,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC,EAChG,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE;AACrB;",
6
+ "names": []
7
+ }
@@ -9,11 +9,11 @@ import {
9
9
  createZodSchemaFromRules,
10
10
  getValidationRulesForElement,
11
11
  isFieldRequired
12
- } from "./chunk-KLATKWUA.js";
12
+ } from "./chunk-4YANBG3M.js";
13
13
  import {
14
14
  getElementName,
15
15
  walkNamedElements
16
- } from "./chunk-S7I76ISM.js";
16
+ } from "./chunk-7QLR5WM3.js";
17
17
  import {
18
18
  expandContainerParentPaths,
19
19
  expandFieldTemplatePaths,
@@ -0,0 +1,184 @@
1
+ import {
2
+ isZodType
3
+ } from "./chunk-4SWCTY7K.js";
4
+ import {
5
+ logger
6
+ } from "./chunk-VGGERKV2.js";
7
+ import {
8
+ isPlainObject
9
+ } from "./chunk-CMPOBBRV.js";
10
+
11
+ // src/lib/export-schema.ts
12
+ import * as z from "zod/mini";
13
+ var STANDARD_TARGETS = { "draft-7": "draft-07", "draft-4": "draft-04" };
14
+ var STANDARD_SOURCES = /* @__PURE__ */ new WeakMap();
15
+ function readStandardJSONSchema(schema) {
16
+ if (typeof schema !== "object" && typeof schema !== "function") return void 0;
17
+ if (schema === null || !("~standard" in schema)) return void 0;
18
+ const standard = schema["~standard"];
19
+ if (typeof standard !== "object" || standard === null || !("jsonSchema" in standard)) return void 0;
20
+ const converter = standard.jsonSchema;
21
+ if (typeof converter !== "object" || converter === null) return void 0;
22
+ if (!("input" in converter) || typeof converter.input !== "function") return void 0;
23
+ if (!("output" in converter) || typeof converter.output !== "function") return void 0;
24
+ return converter;
25
+ }
26
+ function vendorOf(schema) {
27
+ const standard = schema["~standard"];
28
+ return typeof standard === "object" && standard !== null && "vendor" in standard && typeof standard.vendor === "string" ? standard.vendor : "unknown";
29
+ }
30
+ function resolveExportSchema(schema, open) {
31
+ if (isZodType(schema)) return { kind: "zod", schema };
32
+ const converter = readStandardJSONSchema(schema);
33
+ if (!converter) return { kind: "open" };
34
+ const placeholder = z.any();
35
+ STANDARD_SOURCES.set(placeholder, { vendor: vendorOf(schema), converter, open });
36
+ return { kind: "standard", schema: placeholder };
37
+ }
38
+ var DATA_KEYWORDS = /* @__PURE__ */ new Set(["const", "enum", "default", "examples"]);
39
+ var NAMED_SCHEMA_KEYWORDS = /* @__PURE__ */ new Set([
40
+ "properties",
41
+ "patternProperties",
42
+ "$defs",
43
+ "definitions",
44
+ "dependentSchemas",
45
+ "dependencies"
46
+ ]);
47
+ var isLocalPointer = (ref) => ref === "#" || ref.startsWith("#/");
48
+ var startsResource = (schema) => typeof schema.$id === "string" && !schema.$id.startsWith("#");
49
+ function mapResource(node, rewrite, isRoot = true) {
50
+ if (Array.isArray(node)) return node.map((item) => mapResource(item, rewrite, false));
51
+ if (!isPlainObject(node)) return node;
52
+ if (!isRoot && startsResource(node)) return structuredClone(node);
53
+ const copy = {};
54
+ for (const [key, value] of Object.entries(node)) {
55
+ if (typeof value === "string") copy[key] = rewrite(key, value);
56
+ else if (DATA_KEYWORDS.has(key)) copy[key] = structuredClone(value);
57
+ else if (NAMED_SCHEMA_KEYWORDS.has(key) && isPlainObject(value)) {
58
+ copy[key] = Object.fromEntries(
59
+ Object.entries(value).map(([name, schema]) => [name, mapResource(schema, rewrite, false)])
60
+ );
61
+ } else copy[key] = mapResource(value, rewrite, false);
62
+ }
63
+ return copy;
64
+ }
65
+ function declaredAnchors(schema) {
66
+ const names = /* @__PURE__ */ new Set();
67
+ mapResource(schema, (keyword, value) => {
68
+ if (keyword === "$anchor" || keyword === "$dynamicAnchor") names.add(value);
69
+ else if (keyword === "$id" && value.startsWith("#")) names.add(value.slice(1));
70
+ return value;
71
+ });
72
+ return names;
73
+ }
74
+ function rewriteResource(schema, rewrite) {
75
+ const anchors = rewrite.anchor ? declaredAnchors(schema) : /* @__PURE__ */ new Set();
76
+ const renamed = (name) => rewrite.anchor && anchors.has(name) ? rewrite.anchor(name) : name;
77
+ return mapResource(schema, (keyword, value) => {
78
+ if (keyword === "$anchor" || keyword === "$dynamicAnchor") return renamed(value);
79
+ if (keyword === "$id" && value.startsWith("#")) return `#${renamed(value.slice(1))}`;
80
+ if (keyword !== "$ref" && keyword !== "$dynamicRef") return value;
81
+ if (isLocalPointer(value)) return rewrite.pointer ? rewrite.pointer(value) : value;
82
+ return value.startsWith("#") ? `#${renamed(value.slice(1))}` : value;
83
+ });
84
+ }
85
+ function withoutSchemaKeyword(schema) {
86
+ const { $schema: _dropped, ...rest } = schema;
87
+ return structuredClone(rest);
88
+ }
89
+ function hasLocalRef(schema) {
90
+ let found = false;
91
+ mapResource(schema, (keyword, value) => {
92
+ if (keyword === "$ref" && isLocalPointer(value)) found = true;
93
+ return value;
94
+ });
95
+ return found;
96
+ }
97
+ function withoutRootAnchor(schema) {
98
+ if (typeof schema.$id !== "string" || !schema.$id.startsWith("#")) return schema;
99
+ const root = schema.$id;
100
+ const { $id: _anchor, ...rest } = mapResource(
101
+ schema,
102
+ (keyword, value) => (keyword === "$ref" || keyword === "$dynamicRef") && value === root ? "#" : value
103
+ );
104
+ return rest;
105
+ }
106
+ var definitionsKeyword = (target) => target === "draft-2020-12" ? "$defs" : "definitions";
107
+ function createJSONSchemaEmbedder(target, placement) {
108
+ const keyword = definitionsKeyword(target);
109
+ const hoisted = {};
110
+ let count = 0;
111
+ return {
112
+ embed(own) {
113
+ const body = withoutSchemaKeyword(own);
114
+ if (startsResource(body)) return body;
115
+ const pointsIntoItself = hasLocalRef(body);
116
+ if (!pointsIntoItself && declaredAnchors(body).size === 0) return body;
117
+ count += 1;
118
+ const key = `embedded-${count}`;
119
+ if (pointsIntoItself && placement.kind === "collection") {
120
+ const ref2 = placement.uri(key);
121
+ hoisted[key] = {
122
+ ...own.$schema === void 0 ? {} : { $schema: own.$schema },
123
+ ...withoutRootAnchor(body),
124
+ $id: ref2
125
+ };
126
+ return { $ref: ref2 };
127
+ }
128
+ const ref = `#/${keyword}/${key}`;
129
+ const rewritten = rewriteResource(body, {
130
+ pointer: pointsIntoItself ? (pointer) => `${ref}${pointer.slice(1)}` : void 0,
131
+ anchor: (name) => `${key}-${name}`
132
+ });
133
+ if (!pointsIntoItself) return rewritten;
134
+ hoisted[key] = rewritten;
135
+ return { $ref: ref };
136
+ },
137
+ finish(written) {
138
+ if (Object.keys(hoisted).length === 0) return written;
139
+ const field = placement.kind === "collection" ? "schemas" : keyword;
140
+ const existing = isPlainObject(written[field]) ? written[field] : {};
141
+ for (const key of Object.keys(hoisted)) {
142
+ if (key in existing) throw new Error(`The JSON Schema export already defines '${key}'.`);
143
+ }
144
+ written[field] = { ...existing, ...hoisted };
145
+ return written;
146
+ }
147
+ };
148
+ }
149
+ function createExportConversion(options) {
150
+ const { io, target, placement } = options;
151
+ const embedder = createJSONSchemaEmbedder(target, placement);
152
+ const standardTarget = STANDARD_TARGETS[target] ?? target;
153
+ function ownJSONSchema(source) {
154
+ try {
155
+ return source.converter[io]({ target: standardTarget });
156
+ } catch (error) {
157
+ logger.warn(
158
+ `A '${source.vendor}' schema could not write JSON Schema for target '${standardTarget}' (${io}), so the export lists it by its shape.`,
159
+ { error }
160
+ );
161
+ return z.toJSONSchema(source.open(), { target, io, unrepresentable: "any" });
162
+ }
163
+ }
164
+ return {
165
+ override({ zodSchema, jsonSchema }) {
166
+ const source = STANDARD_SOURCES.get(zodSchema);
167
+ if (!source) return;
168
+ const annotations = { ...jsonSchema };
169
+ const own = ownJSONSchema(source);
170
+ const isEntry = placement.kind === "collection" && placement.registry.get(zodSchema)?.id !== void 0;
171
+ const written = isEntry ? withoutSchemaKeyword(own) : embedder.embed(own);
172
+ for (const key of Object.keys(jsonSchema)) delete jsonSchema[key];
173
+ Object.assign(jsonSchema, annotations, written);
174
+ },
175
+ finish: (converted) => embedder.finish(converted)
176
+ };
177
+ }
178
+
179
+ export {
180
+ readStandardJSONSchema,
181
+ resolveExportSchema,
182
+ createJSONSchemaEmbedder,
183
+ createExportConversion
184
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lib/export-schema.ts"],
4
+ "sourcesContent": ["import * as z from 'zod/mini';\nimport type { StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport type { JSONSchemaObject, JSONSchemaTarget } from '@/lib/standard-json-schema';\nimport { isPlainObject } from '@/lib/is-plain-object';\nimport { isZodType } from '@/lib/is-zod-type';\nimport { logger } from '@/lib/logger';\n\n/**\n * How the JSON Schema export reads one registration's schema.\n *\n * - `zod`: a Zod schema (classic or Mini), exported by the Zod converter. The caller may compose it first (closed\n * appearance axes, typed children and rules).\n * - `standard`: a schema that exports itself, held by a Zod placeholder the conversion replaces with what the schema\n * returns. Nothing is composed around it.\n * - `open`: a schema the export cannot read. The caller lists it by an open object of its own kind.\n */\nexport type ExportSchemaSource =\n\t| { readonly kind: 'zod'; readonly schema: z.ZodMiniType }\n\t| { readonly kind: 'standard'; readonly schema: z.ZodMiniType }\n\t| { readonly kind: 'open' };\n\ninterface StandardSource {\n\treadonly vendor: string;\n\treadonly converter: StandardJSONSchemaV1.Converter;\n\treadonly open: () => z.ZodMiniType;\n}\n\n/** The Standard JSON Schema names of the targets Zod also accepts by an older name. */\nconst STANDARD_TARGETS: Readonly<Record<string, string>> = { 'draft-7': 'draft-07', 'draft-4': 'draft-04' };\n\nconst STANDARD_SOURCES = new WeakMap<object, StandardSource>();\n\n/**\n * The Standard JSON Schema converter of a schema (`~standard.jsonSchema`), when it provides one.\n */\nexport function readStandardJSONSchema(schema: unknown): StandardJSONSchemaV1.Converter | undefined {\n\tif (typeof schema !== 'object' && typeof schema !== 'function') return undefined;\n\tif (schema === null || !('~standard' in schema)) return undefined;\n\tconst standard = schema['~standard'];\n\tif (typeof standard !== 'object' || standard === null || !('jsonSchema' in standard)) return undefined;\n\tconst converter = standard.jsonSchema;\n\tif (typeof converter !== 'object' || converter === null) return undefined;\n\tif (!('input' in converter) || typeof converter.input !== 'function') return undefined;\n\tif (!('output' in converter) || typeof converter.output !== 'function') return undefined;\n\treturn converter as StandardJSONSchemaV1.Converter;\n}\n\nfunction vendorOf(schema: unknown): string {\n\tconst standard: unknown = (schema as { '~standard'?: unknown })['~standard'];\n\treturn typeof standard === 'object' &&\n\t\tstandard !== null &&\n\t\t'vendor' in standard &&\n\t\ttypeof standard.vendor === 'string'\n\t\t? standard.vendor\n\t\t: 'unknown';\n}\n\n/**\n * Decide how the JSON Schema export reads a schema, for every kind it lists: an element, an action, a validation\n * rule and a recipe slot.\n *\n * @param schema - The schema a registration declares, from any Standard Schema library\n * @param open - The open object the caller lists the schema by when it cannot be read. A `standard` schema is listed\n * by it too, for a conversion whose `target` the schema's own converter throws on.\n *\n * @remarks\n * One decision, in this order:\n *\n * 1. A Zod schema (classic or Mini) is exported by the Zod converter. This comes first even though classic Zod also\n * implements Standard JSON Schema, because the export composes Zod schemas before it converts them (closed\n * appearance axes, typed children and rules), which a schema that has already exported itself cannot take part\n * in. Read through `~standard.jsonSchema`, a classic Zod element would lose those, and would export differently\n * from the same element in Zod Mini.\n * 2. Any other schema that provides Standard JSON Schema (`~standard.jsonSchema`) is exported as what it returns for\n * the conversion's `io` and `target`; see {@link createExportConversion} for how it is embedded.\n * 3. Anything else is `open`.\n *\n * A `standard` schema is a fresh Zod `any` placeholder on every call, so two registrations that share a schema object\n * keep their own catalog ids.\n */\nexport function resolveExportSchema(schema: unknown, open: () => z.ZodMiniType): ExportSchemaSource {\n\tif (isZodType(schema)) return { kind: 'zod', schema };\n\tconst converter = readStandardJSONSchema(schema);\n\tif (!converter) return { kind: 'open' };\n\tconst placeholder = z.any();\n\tSTANDARD_SOURCES.set(placeholder, { vendor: vendorOf(schema), converter, open });\n\treturn { kind: 'standard', schema: placeholder };\n}\n\n/** Where the JSON Schema being written keeps its definitions. */\nexport type JSONSchemaPlacement =\n\t| { readonly kind: 'document' }\n\t| {\n\t\t\treadonly kind: 'collection';\n\t\t\t/** The URI the collection refers to an entry by. */\n\t\t\treadonly uri: (id: string) => string;\n\t\t\t/** The registry whose ids are the collection's entries. */\n\t\t\treadonly registry: { get(schema: z.core.$ZodType): { id?: string } | undefined };\n\t };\n\n/** Keywords whose value is data rather than a schema, so a `$ref` key inside it is not a reference. */\nconst DATA_KEYWORDS = new Set(['const', 'enum', 'default', 'examples']);\n\n/** Keywords whose value maps names to schemas, so a key there is a name rather than a keyword. */\nconst NAMED_SCHEMA_KEYWORDS = new Set([\n\t'properties',\n\t'patternProperties',\n\t'$defs',\n\t'definitions',\n\t'dependentSchemas',\n\t'dependencies',\n]);\n\nconst isLocalPointer = (ref: string): boolean => ref === '#' || ref.startsWith('#/');\n\n/**\n * Whether a schema is the root of a resource of its own, which resolves its references against itself. A draft-07\n * `$id` that is only a fragment (`#node`) names an anchor instead.\n */\nconst startsResource = (schema: Record<string, unknown>): boolean =>\n\ttypeof schema.$id === 'string' && !schema.$id.startsWith('#');\n\n/**\n * A copy of a schema's root resource with `rewrite` applied to each string keyword of every schema in it. A keyword\n * is replaced where `rewrite` returns another value.\n *\n * @remarks\n * A subschema with its own `$id` is another resource: its references and anchors are relative to it, not to the\n * schema being embedded, so it is copied as it is. The root is walked whatever its `$id`; the embedder embeds a root\n * that starts a resource as it is.\n */\nfunction mapResource(node: unknown, rewrite: (keyword: string, value: string) => string, isRoot = true): unknown {\n\tif (Array.isArray(node)) return node.map((item) => mapResource(item, rewrite, false));\n\tif (!isPlainObject(node)) return node;\n\tif (!isRoot && startsResource(node)) return structuredClone(node);\n\tconst copy: Record<string, unknown> = {};\n\tfor (const [key, value] of Object.entries(node)) {\n\t\tif (typeof value === 'string') copy[key] = rewrite(key, value);\n\t\telse if (DATA_KEYWORDS.has(key)) copy[key] = structuredClone(value);\n\t\telse if (NAMED_SCHEMA_KEYWORDS.has(key) && isPlainObject(value)) {\n\t\t\tcopy[key] = Object.fromEntries(\n\t\t\t\tObject.entries(value).map(([name, schema]) => [name, mapResource(schema, rewrite, false)]),\n\t\t\t);\n\t\t} else copy[key] = mapResource(value, rewrite, false);\n\t}\n\treturn copy;\n}\n\n/** The anchor names a schema's root resource declares: `$anchor`, `$dynamicAnchor` and a draft-07 `$id: '#name'`. */\nfunction declaredAnchors(schema: JSONSchemaObject): Set<string> {\n\tconst names = new Set<string>();\n\tmapResource(schema, (keyword, value) => {\n\t\tif (keyword === '$anchor' || keyword === '$dynamicAnchor') names.add(value);\n\t\telse if (keyword === '$id' && value.startsWith('#')) names.add(value.slice(1));\n\t\treturn value;\n\t});\n\treturn names;\n}\n\n/**\n * A copy of a schema's root resource with its local JSON Pointer references passed through `pointer`, and each\n * anchor it declares, with the `#name` references to it, renamed by `anchor`.\n */\nfunction rewriteResource(\n\tschema: JSONSchemaObject,\n\trewrite: { readonly pointer?: (pointer: string) => string; readonly anchor?: (name: string) => string },\n): JSONSchemaObject {\n\tconst anchors = rewrite.anchor ? declaredAnchors(schema) : new Set<string>();\n\tconst renamed = (name: string) => (rewrite.anchor && anchors.has(name) ? rewrite.anchor(name) : name);\n\treturn mapResource(schema, (keyword, value) => {\n\t\tif (keyword === '$anchor' || keyword === '$dynamicAnchor') return renamed(value);\n\t\tif (keyword === '$id' && value.startsWith('#')) return `#${renamed(value.slice(1))}`;\n\t\tif (keyword !== '$ref' && keyword !== '$dynamicRef') return value;\n\t\tif (isLocalPointer(value)) return rewrite.pointer ? rewrite.pointer(value) : value;\n\t\treturn value.startsWith('#') ? `#${renamed(value.slice(1))}` : value;\n\t}) as JSONSchemaObject;\n}\n\nfunction withoutSchemaKeyword(schema: JSONSchemaObject): JSONSchemaObject {\n\tconst { $schema: _dropped, ...rest } = schema;\n\treturn structuredClone(rest);\n}\n\nfunction hasLocalRef(schema: JSONSchemaObject): boolean {\n\tlet found = false;\n\tmapResource(schema, (keyword, value) => {\n\t\tif (keyword === '$ref' && isLocalPointer(value)) found = true;\n\t\treturn value;\n\t});\n\treturn found;\n}\n\n/**\n * A copy of a schema without its root's draft-07 fragment `$id` (`#node`), with the `#node` references to it pointing\n * at the root as `#`. A schema without one is returned as it is.\n *\n * @remarks\n * A fragment `$id` is an anchor, and a draft-07 root has only one `$id`, which an entry of a collection needs for its\n * URI. The anchor can only name the root, so `#` says the same within the entry, which is a resource of its own by\n * that URI. Anchors below the root are kept, and the root's other keywords are untouched.\n */\nfunction withoutRootAnchor(schema: JSONSchemaObject): JSONSchemaObject {\n\tif (typeof schema.$id !== 'string' || !schema.$id.startsWith('#')) return schema;\n\tconst root = schema.$id;\n\tconst { $id: _anchor, ...rest } = mapResource(schema, (keyword, value) =>\n\t\t(keyword === '$ref' || keyword === '$dynamicRef') && value === root ? '#' : value,\n\t) as JSONSchemaObject;\n\treturn rest;\n}\n\n/** The keyword a document keeps its definitions under, as Zod writes it for the target. */\nconst definitionsKeyword = (target: string): '$defs' | 'definitions' =>\n\ttarget === 'draft-2020-12' ? '$defs' : 'definitions';\n\n/**\n * Embeds JSON Schemas that were written as documents of their own (by a Standard JSON Schema converter or a separate\n * Zod conversion) into one JSON Schema being written.\n */\nexport interface JSONSchemaEmbedder {\n\t/** The schema to write in place of `own`, which is not changed. */\n\tembed(own: JSONSchemaObject): JSONSchemaObject;\n\t/** Adds the definitions `embed` hoisted to the finished document or collection, in place. */\n\tfinish(written: JSONSchemaObject): JSONSchemaObject;\n}\n\n/**\n * Create the embedder for one JSON Schema being written.\n *\n * @param target - The target the schema is written for\n * @param placement - Whether it is one document or a collection of entries\n *\n * @remarks\n * `$schema` is dropped, since the document being written declares the dialect. A schema whose `$ref` points into\n * itself from its root (`#`, `#/$defs/node`, as ArkType writes a recursive type) would point at the wrong root once\n * embedded, so it is hoisted: in a document, into its definitions under a key of its own (`embedded-1`), with each of\n * its local pointers prefixed by that place; in a collection, as an entry of its own, referred to by its URI. The\n * references stay `#/...` pointers and `#name` anchors, which is what AI tool APIs resolve, rather than `$id` URIs.\n *\n * A plain-name anchor (`$anchor`, `$dynamicAnchor`, a draft-07 `$id: '#node'`) resolves anywhere in the document, so\n * two schemas that each declare `node` would declare it twice. Each embedded schema's anchors, and the `#node`\n * references to them, are renamed to carry its key (`embedded-1-node`), whether it is hoisted into a document or\n * embedded where it stands. A schema hoisted into a collection is a resource of its own by its `$id`, which scopes\n * its anchors, so they keep their names. Only a draft-07 root `$id: '#node'` cannot stay: the entry's `$id` is its\n * assigned URI, so the root's anchor is dropped and its `#node` references become `#`, as\n * {@link withoutRootAnchor} explains.\n *\n * Only the schema's root resource is rewritten. A schema with its own `$id`, and any subschema that sets one, resolves\n * its pointers and anchors against that and is left as it is.\n */\nexport function createJSONSchemaEmbedder(target: string, placement: JSONSchemaPlacement): JSONSchemaEmbedder {\n\tconst keyword = definitionsKeyword(target);\n\tconst hoisted: Record<string, JSONSchemaObject> = {};\n\tlet count = 0;\n\treturn {\n\t\tembed(own) {\n\t\t\tconst body = withoutSchemaKeyword(own);\n\t\t\tif (startsResource(body)) return body;\n\t\t\tconst pointsIntoItself = hasLocalRef(body);\n\t\t\tif (!pointsIntoItself && declaredAnchors(body).size === 0) return body;\n\t\t\tcount += 1;\n\t\t\tconst key = `embedded-${count}`;\n\t\t\tif (pointsIntoItself && placement.kind === 'collection') {\n\t\t\t\tconst ref = placement.uri(key);\n\t\t\t\thoisted[key] = {\n\t\t\t\t\t...(own.$schema === undefined ? {} : { $schema: own.$schema }),\n\t\t\t\t\t...withoutRootAnchor(body),\n\t\t\t\t\t$id: ref,\n\t\t\t\t};\n\t\t\t\treturn { $ref: ref };\n\t\t\t}\n\t\t\tconst ref = `#/${keyword}/${key}`;\n\t\t\tconst rewritten = rewriteResource(body, {\n\t\t\t\tpointer: pointsIntoItself ? (pointer) => `${ref}${pointer.slice(1)}` : undefined,\n\t\t\t\tanchor: (name) => `${key}-${name}`,\n\t\t\t});\n\t\t\tif (!pointsIntoItself) return rewritten;\n\t\t\thoisted[key] = rewritten;\n\t\t\treturn { $ref: ref };\n\t\t},\n\t\tfinish(written) {\n\t\t\tif (Object.keys(hoisted).length === 0) return written;\n\t\t\tconst field = placement.kind === 'collection' ? 'schemas' : keyword;\n\t\t\tconst existing: JSONSchemaObject = isPlainObject(written[field]) ? written[field] : {};\n\t\t\tfor (const key of Object.keys(hoisted)) {\n\t\t\t\tif (key in existing) throw new Error(`The JSON Schema export already defines '${key}'.`);\n\t\t\t}\n\t\t\twritten[field] = { ...existing, ...hoisted };\n\t\t\treturn written;\n\t\t},\n\t};\n}\n\n/** One Zod conversion of the export: the `override` that writes each `standard` schema, and the step after it. */\nexport interface ExportConversion {\n\treadonly override: (context: { zodSchema: z.core.$ZodType; jsonSchema: Record<string, unknown> }) => void;\n\t/** Adds what the override hoisted to the converted result. */\n\treadonly finish: (converted: JSONSchemaObject) => JSONSchemaObject;\n}\n\n/**\n * Create the `override` of `z.toJSONSchema` that writes each `standard` placeholder's own JSON Schema in its place.\n *\n * @param options - The `io` and `target` of the conversion, passed to each schema's converter, and where it writes\n *\n * @remarks\n * The schema's keywords are written as it returns them, embedded by {@link createJSONSchemaEmbedder}. The catalog\n * metadata Zod wrote on the placeholder (`title`, `description`, `componentType`, `category`, which a document lists for every\n * registration) is kept beside them where the schema does not set the same key, so an agent reading the document still\n * sees what the entry is. They are annotations, so they change nothing the schema accepts. The entry of a collection\n * is the schema's own document root, so it is written there without hoisting.\n *\n * The engine takes Zod's target names, so `draft-7` reaches a converter as `draft-07`. A converter that throws (a\n * target it does not support, as ArkType does for `openapi-3.0`) does not stop the export: the schema is listed by the\n * `open` object it was resolved with, and a warning names its vendor and the target.\n */\nexport function createExportConversion(options: {\n\tio: 'input' | 'output';\n\ttarget: JSONSchemaTarget;\n\tplacement: JSONSchemaPlacement;\n}): ExportConversion {\n\tconst { io, target, placement } = options;\n\tconst embedder = createJSONSchemaEmbedder(target, placement);\n\tconst standardTarget = STANDARD_TARGETS[target] ?? target;\n\n\tfunction ownJSONSchema(source: StandardSource): JSONSchemaObject {\n\t\ttry {\n\t\t\treturn source.converter[io]({ target: standardTarget });\n\t\t} catch (error) {\n\t\t\tlogger.warn(\n\t\t\t\t`A '${source.vendor}' schema could not write JSON Schema for target '${standardTarget}' (${io}), so the export lists it by its shape.`,\n\t\t\t\t{ error },\n\t\t\t);\n\t\t\treturn z.toJSONSchema(source.open(), { target, io, unrepresentable: 'any' }) as JSONSchemaObject;\n\t\t}\n\t}\n\n\treturn {\n\t\toverride({ zodSchema, jsonSchema }) {\n\t\t\tconst source = STANDARD_SOURCES.get(zodSchema);\n\t\t\tif (!source) return;\n\t\t\tconst annotations = { ...jsonSchema };\n\t\t\tconst own = ownJSONSchema(source);\n\t\t\tconst isEntry = placement.kind === 'collection' && placement.registry.get(zodSchema)?.id !== undefined;\n\t\t\tconst written = isEntry ? withoutSchemaKeyword(own) : embedder.embed(own);\n\t\t\tfor (const key of Object.keys(jsonSchema)) delete jsonSchema[key];\n\t\t\tObject.assign(jsonSchema, annotations, written);\n\t\t},\n\t\tfinish: (converted) => embedder.finish(converted),\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;AAAA,YAAY,OAAO;AA4BnB,IAAM,mBAAqD,EAAE,WAAW,YAAY,WAAW,WAAW;AAE1G,IAAM,mBAAmB,oBAAI,QAAgC;AAKtD,SAAS,uBAAuB,QAA6D;AACnG,MAAI,OAAO,WAAW,YAAY,OAAO,WAAW,WAAY,QAAO;AACvE,MAAI,WAAW,QAAQ,EAAE,eAAe,QAAS,QAAO;AACxD,QAAM,WAAW,OA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AAS;AAC3D,QAAM,iBAAiB,iBAAiB,MAAM,KAAK;AAEnD,WAAS,cAAc,QAA0C;AAChE,QAAI;AACH,aAAO,OAAO,UAAU,EAAE,EAAE,EAAE,QAAQ,eAAe,CAAC;AAAA,IACvD,SAAS,OAAO;AACf,aAAO;AAAA,QACN,MAAM,OAAO,MAAM,oDAAoD,cAAc,MAAM,EAAE;AAAA,QAC7F,EAAE,MAAM;AAAA,MACT;AACA,aAAS,eAAa,OAAO,KAAK,GAAG,EAAE,QAAQ,IAAI,iBAAiB,MAAM,CAAC;AAAA,IAC5E;AAAA,EACD;AAEA,SAAO;AAAA,IACN,SAAS,EAAE,WAAW,WAAW,GAAG;AACnC,YAAM,SAAS,iBAAiB,IAAI,SAAS;AAC7C,UAAI,CAAC,OAAQ;AACb,YAAM,cAAc,EAAE,GAAG,WAAW;AACpC,YAAM,MAAM,cAAc,MAAM;AAChC,YAAM,UAAU,UAAU,SAAS,gBAAgB,UAAU,SAAS,IAAI,SAAS,GAAG,OAAO;AAC7F,YAAM,UAAU,UAAU,qBAAqB,GAAG,IAAI,SAAS,MAAM,GAAG;AACxE,iBAAW,OAAO,OAAO,KAAK,UAAU,EAAG,QAAO,WAAW,GAAG;AAChE,aAAO,OAAO,YAAY,aAAa,OAAO;AAAA,IAC/C;AAAA,IACA,QAAQ,CAAC,cAAc,SAAS,OAAO,SAAS;AAAA,EACjD;AACD;",
6
+ "names": ["ref"]
7
+ }
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-J5BSFDVK.js";
12
12
  import {
13
13
  defineRecipeSpec
14
- } from "./chunk-E4VONSLO.js";
14
+ } from "./chunk-YZFL6JPZ.js";
15
15
 
16
16
  // src/recipes/built-in-specs.ts
17
17
  var MINIMAL_ACTIONS = { variant: "minimal", showStepCounter: false };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/runtime/types.ts"],
4
+ "sourcesContent": ["import type { ParsedActionSequence } from '@schema-engine/actions';\nimport type { FormEngineRuntime } from '@/engine/form-engine';\nimport type { FormActionConfig, SubmissionActionResult } from '@/runtime/submission-lifecycle';\nimport type { FormStepState, StepNavigationMode } from '@/engine/step-machine';\nimport type { ValidationStep } from '@/engine/value-validation';\nimport type { SubmissionSchema } from '@/engine/submission-schema';\nimport type { FormFetch } from '@/lib/form-fetch';\nimport type { FormActionTrigger } from '@/actions';\nimport type { DefaultValuesOf } from '@/builder/form-values';\nimport type { ValuesBrand } from '@/lib/normalized-form-config';\nimport type {\n\tFormStateContainer,\n\tFormStateContainerConfig,\n\tFormStateErrorsInput,\n\tFormIssueFormatter,\n\tFormStateHydration,\n\tFormSubmissionIssue,\n} from '@/state-container/types';\n\n/** The nested values of a form, as the container holds them and a submission hands them over. */\nexport type FormValues = Readonly<Record<string, unknown>>;\n\n/** What `onSubmit` is given besides the values that passed. */\nexport interface FormSubmitHelpers {\n\t/** Shows the server's answer to this submission, by path; `FORM_ROOT` stands for the form. */\n\tsetServerErrors: (errors: FormStateErrorsInput) => void;\n\t/**\n\t * The engine's `fetch`: the request to send the values with.\n\t *\n\t * @remarks It applies the engine's CSRF policy to a same-origin unsafe request, so a submit callback adds no token itself.\n\t */\n\tfetch: FormFetch;\n}\n\n/**\n * How a command ended.\n *\n * @remarks\n * - `moved`: the current step changed.\n * - `submitted` and `failed`: a submission ran and its actions and `onSubmit` succeeded or did not. Why it\n * failed is in `snapshot.submission.failures`, never in the return value.\n * - `invalid`: validation found errors, which are shown and focused.\n * - `overtaken`: an edit or a row move outran the check, so there is no verdict: nothing is shown or focused.\n * - `refused`: there was nowhere to go, or the step is unknown, skipped or not reachable.\n * - `busy`: another command was running.\n * - `cancelled`: a reset or an unmount revoked the command, which then wrote nothing.\n */\nexport type FormRuntimeOutcome =\n\t'moved' | 'submitted' | 'failed' | 'invalid' | 'overtaken' | 'refused' | 'busy' | 'cancelled';\n\n/** How `next()`, `back()` and `goTo()` ended. */\nexport type NavigationOutcome = Extract<\n\tFormRuntimeOutcome,\n\t'moved' | 'failed' | 'invalid' | 'overtaken' | 'refused' | 'busy' | 'cancelled'\n>;\n\n/** How `submit()` ended: before the last active step it acts as `next()`, so it can end `moved`. */\nexport type SubmitOutcome = Extract<\n\tFormRuntimeOutcome,\n\t'moved' | 'submitted' | 'failed' | 'invalid' | 'overtaken' | 'refused' | 'busy' | 'cancelled'\n>;\n\n/**\n * Where a submission is: `idle` until one starts, `validating` while its validation runs, `submitting` once it passed and the actions and `onSubmit` run, then how it ended.\n *\n * @remarks A submission that is `invalid` or `overtaken` goes from `validating` back to `idle` and is never `submitting`: submission starts, for the `form_submit_start` trigger and for a renderer's own start event, once it passed validation.\n */\nexport type SubmissionStatus = 'idle' | 'validating' | 'submitting' | 'success' | 'error';\n\n/**\n * Whether a submission is in progress: its validation or its actions are running.\n *\n * @remarks The one definition of busy, which the runtime's revoke and every renderer's submit button, label and busy state share.\n */\nexport function isSubmissionBusy(status: SubmissionStatus): boolean {\n\treturn status === 'validating' || status === 'submitting';\n}\n\n/**\n * What the form reports about its submissions.\n *\n * @remarks `failures` explain an `error` status and are empty otherwise. They are issues, so the form's one formatter words them.\n */\nexport interface FormSubmissionState {\n\treadonly status: SubmissionStatus;\n\treadonly failures: readonly FormSubmissionIssue[];\n\t/** The submissions that ended, whether they passed or failed validation, since the form was created or reset. */\n\treadonly submitCount: number;\n}\n\n/** What a runtime reports: its submission, and its steps. */\nexport interface FormRuntimeSnapshot {\n\treadonly submission: FormSubmissionState;\n\t/** The id of the current step. */\n\treadonly current: string;\n\t/** A `next`, `back`, `goTo` or a submit that acts as `next` is running. */\n\treadonly navigating: boolean;\n\t/** Every step in config order, skipped ones included. */\n\treadonly steps: readonly FormStepState[];\n}\n\n/**\n * What an application reads of a form's wizard: where it is, and the commands that move it.\n *\n * @remarks\n * The commands are those of the form's runtime and end with an outcome (`'moved'`, `'invalid'`, `'busy'`, ...). `steps` lists every\n * step in order with its `title`, `skipped`, `visited`, `complete` and `invalid`; a skipped step is passed over by `next` and `back` and refused by `goTo`.\n * Each renderer exposes it its own way: `useFormWizard` in React, `FormController.wizard` in Radiant.\n */\nexport type FormWizard = Pick<FormRuntimeSnapshot, 'current' | 'steps' | 'navigating'> &\n\tPick<FormRuntime, 'next' | 'back' | 'goTo'>;\n\n/** What only the renderer can do. */\nexport interface FormRuntimeHost {\n\t/**\n\t * Focuses the first control with an error among `paths`.\n\t *\n\t * @remarks The paths are those of the fields that have an error; the host picks the first in the document. The list may be empty (a rule that could not run records no field error), and the host then focuses nothing.\n\t */\n\tfocus(paths: readonly string[]): void;\n\t/** Writes the controls' values to the container and reports their native validity, as a submit does, before a check. */\n\tsync?(): void;\n\t/**\n\t * Called once a submission succeeded, after its actions and `onSubmit`, with the values the form declares, so a host whose form can post natively may do it with them.\n\t *\n\t * @remarks The values are what the form's elements write, checked by the schema derived from them, and not what the application's schema made of them (a `Date`, a class): a form posts what its fields hold. The host decides whether it posts, because a renderer always passes a stable `onSubmit` wrapper and the runtime cannot tell whether the application gave one: Radiant posts when it did not. The navigation cannot cut off the success and complete triggers, which ran first.\n\t */\n\tsubmitNatively?(values: FormValues): void;\n}\n\n/** A step of the config the runtime reads. */\nexport interface FormRuntimeStep<TAction extends FormActionConfig = FormActionConfig> extends ValidationStep {\n\treadonly id: string;\n\t/** Carried to the step's {@link FormStepState.title}. */\n\treadonly title?: string;\n\t/** Actions dispatched after the form's on every trigger while this step is current. */\n\treadonly actions?: ParsedActionSequence<TAction>;\n}\n\n/** The normalized form config, in the shape the runtime reads. */\nexport interface FormRuntimeConfig<\n\tTAction extends FormActionConfig = FormActionConfig,\n> extends FormStateContainerConfig {\n\treadonly id?: string;\n\treadonly navigation?: StepNavigationMode;\n\treadonly actions?: ParsedActionSequence<TAction>;\n\treadonly steps: readonly FormRuntimeStep<TAction>[];\n}\n\n/**\n * What {@link createFormRuntime} builds a runtime from.\n *\n * @template TValues - The values a submission holds, which the form's config carries ({@link ValuesBrand}); {@link FormValues} when it is not typed. It is inferred from `config`, which the runtime has parsed every submission against before it reaches a callback.\n */\nexport interface CreateFormRuntimeOptions<TAction extends FormActionConfig = FormActionConfig, TValues = FormValues> {\n\t/** The engine, for its validation registry, its actions and its `fetch`. */\n\tengine: FormEngineRuntime;\n\tconfig: FormRuntimeConfig<TAction> & ValuesBrand<TValues>;\n\t/** Values the form starts from, over the defaults of its fields. */\n\tdefaults?: DefaultValuesOf<TValues>;\n\t/** The snapshot of a container that rendered the form on the server, to start from. */\n\tsnapshot?: FormStateHydration;\n\thost: FormRuntimeHost;\n\t/** Called with the values that passed validation and matched the form's value schemas, after the submit actions and before the success trigger. */\n\tonSubmit?: (data: TValues, helpers: FormSubmitHelpers) => void | Promise<void>;\n\t/** Called when the values change, never for an error, a touch or a validation result. */\n\tonChange?: (data: FormValues) => void;\n\t/** Called with each submit action that succeeded, and the values that passed. Typed by the engine's actions. */\n\tonAction?: (action: TAction, data: TValues) => void | Promise<void>;\n\t/**\n\t * Takes the page to the `redirectUrl` a submit action asked for, once the whole submission succeeded.\n\t *\n\t * @remarks\n\t * Called at most once, after every submit action and `onSubmit` succeeded and the success trigger ran, with the\n\t * `redirectUrl` of the last successful submit action that set one. It replaces\n\t * {@link FormRuntimeHost.submitNatively} for that submission, since a native post would load a page of its own.\n\t * Defaults to {@link defaultNavigate}: `location.assign` where `globalThis.location` exists, and nothing on a server.\n\t */\n\tnavigate?: (url: string) => void;\n\t/** Called with the results of every trigger that ran actions, and once with those of the submit actions. */\n\tonActionResults?: (results: readonly SubmissionActionResult[], trigger: FormActionTrigger) => void | Promise<void>;\n}\n\n/** One instance of a form's lifecycle and wizard navigation, shared by every renderer. */\nexport interface FormRuntime {\n\t/** The form state: values, field state, validation and the captured submission. */\n\treadonly container: FormStateContainer;\n\t/** The normalized config the runtime was created from. */\n\treadonly config: FormRuntimeConfig;\n\t/**\n\t * The submitted values of the form as a Standard Schema, composed once from the config's elements.\n\t *\n\t * @remarks The schema every submission is checked against, so a tool that builds values for the form reads it from here and cannot drift from the runtime's.\n\t */\n\treadonly submissionSchema: SubmissionSchema;\n\t/** The engine's `formatIssue`, which a form without one of its own words its issues with. */\n\treadonly formatIssue: FormIssueFormatter | undefined;\n\t/**\n\t * Starts the runtime: dispatches `form_mount` the first time, and watches the values for `form_change` and `onChange`.\n\t *\n\t * @remarks The returned function stops the watch and revokes any command in flight (`next`, `back`, `goTo`, `submit`), which ends `'cancelled'`. Mounting again is allowed and dispatches `form_mount` no more.\n\t */\n\tmount: () => () => void;\n\tgetSnapshot: () => FormRuntimeSnapshot;\n\tgetServerSnapshot: () => FormRuntimeSnapshot;\n\tsubscribe: (listener: () => void) => () => void;\n\t/** Validates the current step and moves to the next active one. */\n\tnext: () => Promise<NavigationOutcome>;\n\t/** Moves to the previous active step, without validating. */\n\tback: () => Promise<NavigationOutcome>;\n\t/** Moves to the step `id`: back always, forward as the form's `navigation` allows. */\n\tgoTo: (id: string) => Promise<NavigationOutcome>;\n\t/** Acts as `next()` before the last active step; on it, validates every active step, runs the actions and `onSubmit`. */\n\tsubmit: () => Promise<SubmitOutcome>;\n\t/** Hides the outcome of the last submission: the status goes back to `idle` and the failures are dropped. */\n\tclearSubmission: () => void;\n}\n"],
5
+ "mappings": ";AA0EO,SAAS,iBAAiB,QAAmC;AACnE,SAAO,WAAW,gBAAgB,WAAW;AAC9C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,38 @@
1
+ import {
2
+ defineInputContract
3
+ } from "./chunk-V3GYAG33.js";
4
+ import {
5
+ BaseFieldSchema
6
+ } from "./chunk-237BHPDH.js";
7
+
8
+ // src/default-elements/checkbox.ts
9
+ import * as z from "zod/mini";
10
+ var CheckboxFieldExtensionSchema = z.object({
11
+ autoFocus: z.optional(z.boolean()),
12
+ checked: z.optional(z.boolean()),
13
+ indeterminate: z.optional(z.boolean()),
14
+ form: z.optional(z.string())
15
+ });
16
+ var CheckboxFieldConfigSchema = z.extend(BaseFieldSchema, {
17
+ $type: z.literal("checkbox"),
18
+ ...CheckboxFieldExtensionSchema.shape
19
+ });
20
+ var checkboxFieldValue = () => z.boolean();
21
+ var CheckboxElementContract = defineInputContract({
22
+ $type: "checkbox",
23
+ appearanceAxes: ["size"],
24
+ schema: CheckboxFieldConfigSchema,
25
+ value: checkboxFieldValue,
26
+ metadata: {
27
+ name: "Checkbox Field",
28
+ description: "Checkbox input field for boolean values",
29
+ category: "input"
30
+ }
31
+ });
32
+
33
+ export {
34
+ CheckboxFieldExtensionSchema,
35
+ CheckboxFieldConfigSchema,
36
+ checkboxFieldValue,
37
+ CheckboxElementContract
38
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/default-elements/checkbox.ts"],
4
+ "sourcesContent": ["import * as z from 'zod/mini';\nimport { BaseFieldSchema } from '@/schemas/base-field';\nimport { defineInputContract } from './define-contract';\n\nexport const CheckboxFieldExtensionSchema = z.object({\n\tautoFocus: z.optional(z.boolean()),\n\tchecked: z.optional(z.boolean()),\n\tindeterminate: z.optional(z.boolean()),\n\tform: z.optional(z.string()),\n});\n\nexport const CheckboxFieldConfigSchema = z.extend(BaseFieldSchema, {\n\t$type: z.literal('checkbox'),\n\t...CheckboxFieldExtensionSchema.shape,\n});\n\nexport type CheckboxFieldExtension = z.infer<typeof CheckboxFieldExtensionSchema>;\nexport type CheckboxFieldConfig = z.infer<typeof CheckboxFieldConfigSchema>;\n\n/** The value a checkbox writes: whether it is checked. */\nexport const checkboxFieldValue = () => z.boolean();\n\n/** The contract of the `checkbox` element: what every renderer of it agrees on. */\nexport const CheckboxElementContract = defineInputContract({\n\t$type: 'checkbox',\n\tappearanceAxes: ['size'],\n\tschema: CheckboxFieldConfigSchema,\n\tvalue: checkboxFieldValue,\n\tmetadata: {\n\t\tname: 'Checkbox Field',\n\t\tdescription: 'Checkbox input field for boolean values',\n\t\tcategory: 'input',\n\t},\n});\n"],
5
+ "mappings": ";;;;;;;;AAAA,YAAY,OAAO;AAIZ,IAAM,+BAAiC,SAAO;AAAA,EACpD,WAAa,WAAW,UAAQ,CAAC;AAAA,EACjC,SAAW,WAAW,UAAQ,CAAC;AAAA,EAC/B,eAAiB,WAAW,UAAQ,CAAC;AAAA,EACrC,MAAQ,WAAW,SAAO,CAAC;AAC5B,CAAC;AAEM,IAAM,4BAA8B,SAAO,iBAAiB;AAAA,EAClE,OAAS,UAAQ,UAAU;AAAA,EAC3B,GAAG,6BAA6B;AACjC,CAAC;AAMM,IAAM,qBAAqB,MAAQ,UAAQ;AAG3C,IAAM,0BAA0B,oBAAoB;AAAA,EAC1D,OAAO;AAAA,EACP,gBAAgB,CAAC,MAAM;AAAA,EACvB,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,UAAU;AAAA,IACT,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACX;AACD,CAAC;",
6
+ "names": []
7
+ }
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  fromSchemaIssues
3
3
  } from "./chunk-FVOL3ZOJ.js";
4
- import {
5
- issueAt
6
- } from "./chunk-LMWJAD3B.js";
7
4
  import {
8
5
  globalFetch
9
6
  } from "./chunk-OUF57UZ7.js";
@@ -15,14 +12,20 @@ import {
15
12
  } from "./chunk-KE53GN4Q.js";
16
13
  import {
17
14
  createValidationContext
18
- } from "./chunk-KLATKWUA.js";
15
+ } from "./chunk-4YANBG3M.js";
19
16
  import {
20
17
  ValidationRuleError
21
18
  } from "./chunk-6BAJHAGL.js";
22
19
 
23
20
  // src/schemas/validation/validation-registry.ts
24
21
  import "zod/mini";
25
- import { createRegistry, safeParseStandardSchema } from "@schema-engine/registry";
22
+ import {
23
+ createRegistry,
24
+ safeParseNode,
25
+ safeParseStandardSchema,
26
+ standardSchema,
27
+ unregisteredTypeMessage
28
+ } from "@schema-engine/registry";
26
29
  function deriveDefaultRules(registrations) {
27
30
  const byFieldType = /* @__PURE__ */ new Map();
28
31
  for (const registration of registrations) {
@@ -45,9 +48,32 @@ function withCommonFields(parsed, common) {
45
48
  );
46
49
  return { ...parsed, ...kept };
47
50
  }
48
- function unknownRuleMessage(type, registrations) {
51
+ function unknownRuleHint(registrations) {
49
52
  const registered = registrations.map((registration) => registration.$type).join(", ");
50
- return `Unknown validation rule '${type}'. Register it with createFormEngine({ validations: [...] }). Registered rules: ${registered}.`;
53
+ return `Register it with createFormEngine({ validations: [...] }). Registered rules: ${registered}.`;
54
+ }
55
+ function ruleSchema(registration, fetch) {
56
+ return standardSchema((rule) => {
57
+ const common = safeParseStandardSchema(BaseValidationRuleSchema, rule);
58
+ if (!common.success) return { issues: common.error.issues };
59
+ const parsed = safeParseStandardSchema(registration.schema, rule);
60
+ if (!parsed.success) return { issues: parsed.error.issues };
61
+ const parsedRule = withCommonFields(parsed.data, common.data);
62
+ try {
63
+ registration.handler(parsedRule, { ...createValidationContext(), fetch });
64
+ } catch (error) {
65
+ const reason = error instanceof Error ? error.message : String(error);
66
+ return {
67
+ issues: [
68
+ {
69
+ message: `Validation rule '${registration.$type}' could not be built: ${reason}`,
70
+ path: ["$type"]
71
+ }
72
+ ]
73
+ };
74
+ }
75
+ return { value: parsedRule };
76
+ });
51
77
  }
52
78
  function createValidationRegistry(registrations, options = {}) {
53
79
  const { fetch = globalFetch } = options;
@@ -56,6 +82,14 @@ function createValidationRegistry(registrations, options = {}) {
56
82
  registrations
57
83
  );
58
84
  const defaultRulesByFieldType = deriveDefaultRules(registry.all());
85
+ const unknownHint = unknownRuleHint(registry.all());
86
+ const rules = {
87
+ get(type) {
88
+ const registration = registry.get(type);
89
+ return registration && { schema: ruleSchema(registration, fetch) };
90
+ },
91
+ hint: unknownHint
92
+ };
59
93
  const api = {
60
94
  ...registry,
61
95
  getDefaultRulesForFieldType: (fieldType) => defaultRulesByFieldType.get(fieldType) ?? NO_DEFAULT_RULES,
@@ -70,7 +104,7 @@ function createValidationRegistry(registrations, options = {}) {
70
104
  createSchema: (rule, context) => {
71
105
  const registration = registry.get(rule.$type);
72
106
  if (!registration) {
73
- throw new ValidationRuleError(rule.$type, unknownRuleMessage(rule.$type, registry.all()));
107
+ throw new ValidationRuleError(rule.$type, unregisteredTypeMessage(rule.$type, unknownHint));
74
108
  }
75
109
  try {
76
110
  return registration.handler(rule, { ...context, fetch });
@@ -81,29 +115,9 @@ function createValidationRegistry(registrations, options = {}) {
81
115
  }
82
116
  },
83
117
  check: (rule) => {
84
- const registration = registry.get(rule.$type);
85
- if (!registration) {
86
- return { ok: false, issues: [issueAt(["$type"], unknownRuleMessage(rule.$type, registry.all()))] };
87
- }
88
- const common = safeParseStandardSchema(BaseValidationRuleSchema, rule);
89
- if (!common.success) {
90
- return { ok: false, issues: fromSchemaIssues(common.error.issues, []) };
91
- }
92
- const parsed = safeParseStandardSchema(registration.schema, rule);
93
- if (!parsed.success) {
94
- return { ok: false, issues: fromSchemaIssues(parsed.error.issues, []) };
95
- }
96
- const parsedRule = withCommonFields(parsed.data, common.data);
97
- try {
98
- registration.handler(parsedRule, { ...createValidationContext(), fetch });
99
- } catch (error) {
100
- const reason = error instanceof Error ? error.message : String(error);
101
- return {
102
- ok: false,
103
- issues: [issueAt(["$type"], `Validation rule '${rule.$type}' could not be built: ${reason}`)]
104
- };
105
- }
106
- return { ok: true, rule: parsedRule };
118
+ const checked = safeParseNode(rules, rule);
119
+ if (!checked.success) return { ok: false, issues: fromSchemaIssues(checked.issues, []) };
120
+ return { ok: true, rule: checked.data };
107
121
  }
108
122
  };
109
123
  return Object.freeze(api);
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/schemas/validation/validation-registry.ts"],
4
+ "sourcesContent": ["import * as z from 'zod/mini';\nimport type { StandardSchemaV1 } from '@standard-schema/spec';\nimport {\n\tcreateRegistry,\n\tsafeParseNode,\n\tsafeParseStandardSchema,\n\tstandardSchema,\n\tunregisteredTypeMessage,\n\ttype NodeLookup,\n\ttype ReadOnlyRegistry,\n} from '@schema-engine/registry';\nimport type {\n\tAnyValidationRegistration,\n\tBaseValidationRule,\n\tValidationScope,\n\tValidationRegistration,\n\tValidationRegistrationConstraint,\n} from './types.js';\nimport { defaultValidations } from './defaults.js';\nimport { BaseValidationRuleSchema } from './types.js';\nimport { ValidationRuleError } from './errors.js';\nimport { globalFetch, type FormFetch } from '@/lib/form-fetch';\nimport type { FormValidationIssue } from '@/lib/validate-form/issues';\nimport { fromSchemaIssues } from '@/lib/validate-form/schema-issues';\nimport { createValidationContext } from './utils.js';\n\n/** @remarks Rule-specific handlers are checked where a registration is defined, then stored together by rule type. */\ntype StoredValidationRegistration = ValidationRegistration<any>;\n\n/**\n * Read-only store of validation registrations, with the lookups the renderers and the engine need.\n *\n * @remarks\n * Built by {@link createValidationRegistry}, so it has no `register`, `unregister` or `clear`: to\n * change the rules, build another registry from a new list. The per-field-type default rules are\n * derived from the registrations once, at build.\n */\nexport interface ValidationRegistry extends ReadOnlyRegistry<AnyValidationRegistration> {\n\t/**\n\t * Default rules injected for a field `$type` when the author omitted them.\n\t *\n\t * @remarks\n\t * Frozen, and shared between calls. When a registration is replaced, its default rules keep the\n\t * position the first registration of that `$type` had among the field type's defaults.\n\t */\n\tgetDefaultRulesForFieldType(fieldType: string): readonly BaseValidationRule[];\n\n\t/**\n\t * Field references a rule reads besides the value under test.\n\t *\n\t * @remarks\n\t * Lives on the registry because the answer comes from the registration, and a\n\t * consumer-registered type is a plain string that `get` would otherwise need\n\t * a cast to reach at every call site.\n\t */\n\tgetRuleDependencies(rule: { $type: string }): readonly string[];\n\n\t/** The options of a rule its registration exposes to messages (`{ minLength: 8 }`), or `undefined` when it exposes none. */\n\tgetRuleParams(rule: { $type: string }): Readonly<Record<string, unknown>> | undefined;\n\n\t/** The fallback text of an issue of a rule: its author's `message`, or what its registration takes from the schema's `reported` text. */\n\tgetRuleMessage(rule: { $type: string; message?: string }, reported: string | undefined): string | undefined;\n\n\t/** Registrations of one category. */\n\tgetByCategory(category: string): AnyValidationRegistration[];\n\n\t/**\n\t * The request function of the rules that make requests: the engine's `fetch`, or the global one for a standalone registry.\n\t *\n\t * @remarks `createSchema` hands it to every handler as `context.fetch`, whatever context the caller built.\n\t */\n\treadonly fetch: FormFetch;\n\n\t/**\n\t * Create a Zod Mini schema from a validation rule.\n\t *\n\t * @param rule - The validation rule\n\t * @param context - Form context for rules that read other fields\n\t * @throws {ValidationRuleError} When the rule type is not registered or its handler throws\n\t *\n\t * @remarks\n\t * A rule that cannot be built is never skipped: a form that silently skipped it would accept values\n\t * the author meant to reject. A config is checked with {@link ValidationRegistry.check} when it is\n\t * validated, so reaching this error at run time means the registry changed after that.\n\t *\n\t * `context` is required rather than optional so a caller cannot silently omit\n\t * it: a renderer that did exactly that is why cross-field rules were inert on\n\t * one of the two renderers. Build it with `createValidationContext`.\n\t *\n\t * The rule type is generic, not `{ $type: string }`, so a rule literal with extra properties such as\n\t * `{ $type: 'min', value: 10 }` is not rejected as an excess-property error.\n\t */\n\tcreateSchema<T extends { $type: string }>(rule: T, context: ValidationScope): z.ZodMiniType;\n\n\t/**\n\t * Whether a rule can be used, and the rule as its registration parses it.\n\t *\n\t * @remarks\n\t * The one check of a rule written in a form config: its `$type` is registered, its options satisfy the\n\t * registration's `schema`, and the handler builds a schema for it, so a rule that throws is found when\n\t * the form config is validated and not when a user first types. The registration owns the shape, so a\n\t * registration that replaces a built-in decides its options. The rule that comes back is the parsed\n\t * one, which is what the handler runs on: the schema's defaults applied, and `$type`, `message`, `id` and\n\t * `severity` kept from the authored rule even when the schema is a plain object that strips them.\n\t *\n\t * Issue paths are relative to the rule: an option the schema refuses is reported at its key, and a\n\t * `$type` nothing registers or a handler that throws at `$type`.\n\t */\n\tcheck(rule: { $type: string }): RuleCheck;\n}\n\n/** What {@link ValidationRegistry.check} found: the rule as its registration parses it, or the issues that make it unusable. */\nexport type RuleCheck =\n\t| { readonly ok: true; readonly rule: BaseValidationRule }\n\t| { readonly ok: false; readonly issues: readonly FormValidationIssue[] };\n\n/** What a validation registry is built with besides its registrations. */\nexport interface ValidationRegistryOptions {\n\t/** The request function of rules that make requests; the global `fetch` by default. */\n\treadonly fetch?: FormFetch;\n}\n\nfunction deriveDefaultRules(\n\tregistrations: readonly AnyValidationRegistration[],\n): ReadonlyMap<string, readonly BaseValidationRule[]> {\n\tconst byFieldType = new Map<string, BaseValidationRule[]>();\n\tfor (const registration of registrations) {\n\t\tfor (const fieldType of registration.defaultFor ?? []) {\n\t\t\tconst rules = byFieldType.get(fieldType) ?? [];\n\t\t\trules.push(Object.freeze({ $type: registration.$type }));\n\t\t\tbyFieldType.set(fieldType, rules);\n\t\t}\n\t}\n\tfor (const rules of byFieldType.values()) {\n\t\tObject.freeze(rules);\n\t}\n\treturn byFieldType;\n}\n\nconst NO_DEFAULT_RULES: readonly BaseValidationRule[] = Object.freeze([]);\n\nconst COMMON_RULE_KEYS = Object.keys(BaseValidationRuleSchema.shape);\n\n/**\n * The rule as its registration parsed it, with the fields every rule has put back from the authored rule.\n *\n * @remarks\n * The engine owns `$type`, `message`, `id` and `severity`: a registration whose schema is a plain object\n * strips them, which would turn a `warning` into a blocking error and lose the author's text and `id`.\n * Options and defaults stay the registration's.\n */\nfunction withCommonFields(parsed: BaseValidationRule, common: BaseValidationRule): BaseValidationRule {\n\tconst kept = Object.fromEntries(\n\t\tCOMMON_RULE_KEYS.flatMap((key) => (key in common && common[key] !== undefined ? [[key, common[key]]] : [])),\n\t);\n\treturn { ...parsed, ...kept };\n}\n\n/** Says where to register a rule `$type` nothing registers, and lists the types that are, so a typo is easy to see. */\nfunction unknownRuleHint(registrations: readonly AnyValidationRegistration[]): string {\n\tconst registered = registrations.map((registration) => registration.$type).join(', ');\n\treturn `Register it with createFormEngine({ validations: [...] }). Registered rules: ${registered}.`;\n}\n\n/**\n * The schema of a whole rule: the keys every rule has, then the registration's own schema, merged into the parsed\n * rule, then the handler, which must build a schema for it.\n *\n * @remarks\n * `safeParseNode` runs it only once it has found the registration, so the rule is an object with a registered\n * `$type`. Its issues are relative to the rule. A handler that throws is an issue at `$type`.\n *\n * The value it returns is a {@link BaseValidationRule}: `check` relies on that when it reads the `unknown` data of\n * `safeParseNode` as one.\n */\nfunction ruleSchema(registration: StoredValidationRegistration, fetch: FormFetch): StandardSchemaV1 {\n\treturn standardSchema((rule) => {\n\t\tconst common = safeParseStandardSchema(BaseValidationRuleSchema, rule);\n\t\tif (!common.success) return { issues: common.error.issues };\n\t\tconst parsed = safeParseStandardSchema(registration.schema, rule);\n\t\tif (!parsed.success) return { issues: parsed.error.issues };\n\t\tconst parsedRule = withCommonFields(parsed.data as BaseValidationRule, common.data);\n\t\ttry {\n\t\t\tregistration.handler(parsedRule, { ...createValidationContext(), fetch });\n\t\t} catch (error) {\n\t\t\tconst reason = error instanceof Error ? error.message : String(error);\n\t\t\treturn {\n\t\t\t\tissues: [\n\t\t\t\t\t{\n\t\t\t\t\t\tmessage: `Validation rule '${registration.$type}' could not be built: ${reason}`,\n\t\t\t\t\t\tpath: ['$type'],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t};\n\t\t}\n\t\treturn { value: parsedRule };\n\t});\n}\n\n/**\n * Build a read-only validation registry from a list of registrations.\n *\n * @param registrations - Validation registrations, keyed by `$type`\n * @throws {Error} Naming the `$type` when a winning registration's schema is not a Standard Schema\n *\n * @remarks\n * Stored by `createRegistry` from `@schema-engine/registry`: a later registration with the same\n * `$type` replaces the earlier one without a warning, so `[...defaults, custom]` overrides a rule.\n * The built-in rules are not added; use {@link createDefaultValidationRegistry} for those.\n *\n * Takes {@link ValidationRegistrationConstraint}, which erases each rule type so a\n * `ValidationRegistration<PostcodeRule>` is accepted; the registrations are stored as\n * {@link AnyValidationRegistration} after that single cast.\n */\nexport function createValidationRegistry(\n\tregistrations: readonly ValidationRegistrationConstraint[],\n\toptions: ValidationRegistryOptions = {},\n): ValidationRegistry {\n\tconst { fetch = globalFetch } = options;\n\tconst registry = createRegistry<AnyValidationRegistration>(\n\t\t'Validation',\n\t\tregistrations as readonly AnyValidationRegistration[],\n\t);\n\tconst defaultRulesByFieldType = deriveDefaultRules(registry.all());\n\tconst unknownHint = unknownRuleHint(registry.all());\n\tconst rules: NodeLookup<{ schema: StandardSchemaV1 }> = {\n\t\tget(type) {\n\t\t\tconst registration = registry.get(type) as StoredValidationRegistration | undefined;\n\t\t\treturn registration && { schema: ruleSchema(registration, fetch) };\n\t\t},\n\t\thint: unknownHint,\n\t};\n\n\tconst api: ValidationRegistry = {\n\t\t...registry,\n\t\tgetDefaultRulesForFieldType: (fieldType) => defaultRulesByFieldType.get(fieldType) ?? NO_DEFAULT_RULES,\n\t\tgetRuleDependencies: (rule) =>\n\t\t\t(registry.get(rule.$type) as StoredValidationRegistration | undefined)?.dependsOn?.(rule) ?? [],\n\t\tgetRuleMessage: (rule, reported) => {\n\t\t\tconst registration = registry.get(rule.$type) as StoredValidationRegistration | undefined;\n\t\t\treturn registration?.message ? registration.message(rule, reported) : rule.message;\n\t\t},\n\t\tgetRuleParams: (rule) => (registry.get(rule.$type) as StoredValidationRegistration | undefined)?.params?.(rule),\n\t\tgetByCategory: (category) => registry.all().filter((registration) => registration.category === category),\n\t\tfetch,\n\t\tcreateSchema: (rule, context) => {\n\t\t\tconst registration = registry.get(rule.$type) as StoredValidationRegistration | undefined;\n\t\t\tif (!registration) {\n\t\t\t\tthrow new ValidationRuleError(rule.$type, unregisteredTypeMessage(rule.$type, unknownHint));\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\treturn registration.handler(rule, { ...context, fetch });\n\t\t\t} catch (cause) {\n\t\t\t\tthrow new ValidationRuleError(rule.$type, `Validation rule '${rule.$type}' could not be built.`, {\n\t\t\t\t\tcause,\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\t\tcheck: (rule) => {\n\t\t\tconst checked = safeParseNode(rules, rule);\n\t\t\tif (!checked.success) return { ok: false, issues: fromSchemaIssues(checked.issues, []) };\n\t\t\treturn { ok: true, rule: checked.data as BaseValidationRule };\n\t\t},\n\t};\n\treturn Object.freeze(api);\n}\n\n/**\n * The built-in rules followed by any extra registrations, so an extra registration with a built-in\n * `$type` overrides it.\n */\nexport function createDefaultValidationRegistry(\n\textra: readonly ValidationRegistrationConstraint[] = [],\n\toptions: ValidationRegistryOptions = {},\n): ValidationRegistry {\n\treturn createValidationRegistry([...defaultValidations, ...extra], options);\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA,OAAmB;AAEnB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGM;AAgHP,SAAS,mBACR,eACqD;AACrD,QAAM,cAAc,oBAAI,IAAkC;AAC1D,aAAW,gBAAgB,eAAe;AACzC,eAAW,aAAa,aAAa,cAAc,CAAC,GAAG;AACtD,YAAM,QAAQ,YAAY,IAAI,SAAS,KAAK,CAAC;AAC7C,YAAM,KAAK,OAAO,OAAO,EAAE,OAAO,aAAa,MAAM,CAAC,CAAC;AACvD,kBAAY,IAAI,WAAW,KAAK;AAAA,IACjC;AAAA,EACD;AACA,aAAW,SAAS,YAAY,OAAO,GAAG;AACzC,WAAO,OAAO,KAAK;AAAA,EACpB;AACA,SAAO;AACR;AAEA,IAAM,mBAAkD,OAAO,OAAO,CAAC,CAAC;AAExE,IAAM,mBAAmB,OAAO,KAAK,yBAAyB,KAAK;AAUnE,SAAS,iBAAiB,QAA4B,QAAgD;AACrG,QAAM,OAAO,OAAO;AAAA,IACnB,iBAAiB,QAAQ,CAAC,QAAS,OAAO,UAAU,OAAO,GAAG,MAAM,SAAY,CAAC,CAAC,KAAK,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,CAAE;AAAA,EAC3G;AACA,SAAO,EAAE,GAAG,QAAQ,GAAG,KAAK;AAC7B;AAGA,SAAS,gBAAgB,eAA6D;AACrF,QAAM,aAAa,cAAc,IAAI,CAAC,iBAAiB,aAAa,KAAK,EAAE,KAAK,IAAI;AACpF,SAAO,gFAAgF,UAAU;AAClG;AAaA,SAAS,WAAW,cAA4C,OAAoC;AACnG,SAAO,eAAe,CAAC,SAAS;AAC/B,UAAM,SAAS,wBAAwB,0BAA0B,IAAI;AACrE,QAAI,CAAC,OAAO,QAAS,QAA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AK,KAAK;AAC5C,aAAO,cAAc,UAAU,aAAa,QAAQ,MAAM,QAAQ,IAAI,KAAK;AAAA,IAC5E;AAAA,IACA,eAAe,CAAC,SAAU,SAAS,IAAI,KAAK,KAAK,GAAgD,SAAS,IAAI;AAAA,IAC9G,eAAe,CAAC,aAAa,SAAS,IAAI,EAAE,OAAO,CAAC,iBAAiB,aAAa,aAAa,QAAQ;AAAA,IACvG;AAAA,IACA,cAAc,CAAC,MAAM,YAAY;AAChC,YAAM,eAAe,SAAS,IAAI,KAAK,KAAK;AAC5C,UAAI,CAAC,cAAc;AAClB,cAAM,IAAI,oBAAoB,KAAK,OAAO,wBAAwB,KAAK,OAAO,WAAW,CAAC;AAAA,MAC3F;AAEA,UAAI;AACH,eAAO,aAAa,QAAQ,MAAM,EAAE,GAAG,SAAS,MAAM,CAAC;AAAA,MACxD,SAAS,OAAO;AACf,cAAM,IAAI,oBAAoB,KAAK,OAAO,oBAAoB,KAAK,KAAK,yBAAyB;AAAA,UAChG;AAAA,QACD,CAAC;AAAA,MACF;AAAA,IACD;AAAA,IACA,OAAO,CAAC,SAAS;AAChB,YAAM,UAAU,cAAc,OAAO,IAAI;AACzC,UAAI,CAAC,QAAQ,QAAS,QAAO,EAAE,IAAI,OAAO,QAAQ,iBAAiB,QAAQ,QAAQ,CAAC,CAAC,EAAE;AACvF,aAAO,EAAE,IAAI,MAAM,MAAM,QAAQ,KAA2B;AAAA,IAC7D;AAAA,EACD;AACA,SAAO,OAAO,OAAO,GAAG;AACzB;AAMO,SAAS,gCACf,QAAqD,CAAC,GACtD,UAAqC,CAAC,GACjB;AACrB,SAAO,yBAAyB,CAAC,GAAG,oBAAoB,GAAG,KAAK,GAAG,OAAO;AAC3E;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/recipes/define-form-recipe.ts"],
4
+ "sourcesContent": ["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport { bindRecipe } from '@schema-engine/layout';\nimport type { RecipeRegistration } from '@/types';\nimport type { RecipeSlotSchemas, RecipeSpec } from './types';\n\n/**\n * Binds a recipe spec to a framework render payload (shell and slot components).\n *\n * Specs are canonical in this package. React implementations typically come\n * from the Schema Engine registry; Radiant binds its own payload in-package.\n */\nexport function defineFormRecipe<\n\tconst TType extends string,\n\tTSlots extends RecipeSlotSchemas,\n\tTSchema extends StandardSchemaV1,\n\tTRender,\n>(spec: RecipeSpec<TType, TSchema, TSlots>, render: TRender): RecipeRegistration<TType, TSchema, TRender> {\n\treturn bindRecipe(spec, render) as RecipeRegistration<TType, TSchema, TRender>;\n}\n"],
5
+ "mappings": ";AACA,SAAS,kBAAkB;AAUpB,SAAS,iBAKd,MAA0C,QAA8D;AACzG,SAAO,WAAW,MAAM,MAAM;AAC/B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,40 @@
1
+ import {
2
+ defineInputContract
3
+ } from "./chunk-V3GYAG33.js";
4
+ import {
5
+ BaseFieldSchema
6
+ } from "./chunk-237BHPDH.js";
7
+
8
+ // src/default-elements/number.ts
9
+ import * as z from "zod/mini";
10
+ var NumberFieldExtensionSchema = z.object({
11
+ min: z.optional(z.number()),
12
+ max: z.optional(z.number()),
13
+ step: z.optional(z.number()),
14
+ autoComplete: z.optional(z.string()),
15
+ autoFocus: z.optional(z.boolean()),
16
+ inputMode: z.optional(z.enum(["none", "text", "decimal", "numeric", "tel", "search", "email", "url"]))
17
+ });
18
+ var NumberFieldConfigSchema = z.extend(BaseFieldSchema, {
19
+ $type: z.literal("number"),
20
+ ...NumberFieldExtensionSchema.shape
21
+ });
22
+ var numberFieldValue = () => z.number();
23
+ var NumberElementContract = defineInputContract({
24
+ $type: "number",
25
+ appearanceAxes: ["size"],
26
+ schema: NumberFieldConfigSchema,
27
+ value: numberFieldValue,
28
+ metadata: {
29
+ name: "Number Field",
30
+ description: "Number input field for numeric values",
31
+ category: "input"
32
+ }
33
+ });
34
+
35
+ export {
36
+ NumberFieldExtensionSchema,
37
+ NumberFieldConfigSchema,
38
+ numberFieldValue,
39
+ NumberElementContract
40
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/default-elements/number.ts"],
4
+ "sourcesContent": ["import * as z from 'zod/mini';\nimport { BaseFieldSchema } from '@/schemas/base-field';\nimport { defineInputContract } from './define-contract';\n\nexport const NumberFieldExtensionSchema = z.object({\n\tmin: z.optional(z.number()),\n\tmax: z.optional(z.number()),\n\tstep: z.optional(z.number()),\n\tautoComplete: z.optional(z.string()),\n\tautoFocus: z.optional(z.boolean()),\n\tinputMode: z.optional(z.enum(['none', 'text', 'decimal', 'numeric', 'tel', 'search', 'email', 'url'])),\n});\n\nexport const NumberFieldConfigSchema = z.extend(BaseFieldSchema, {\n\t$type: z.literal('number'),\n\t...NumberFieldExtensionSchema.shape,\n});\n\nexport type NumberFieldExtension = z.infer<typeof NumberFieldExtensionSchema>;\nexport type NumberFieldConfig = z.infer<typeof NumberFieldConfigSchema>;\n\n/** The value a number field writes: a number. An empty field writes `''`, which only an optional field may hold. */\nexport const numberFieldValue = () => z.number();\n\n/** The contract of the `number` element: what every renderer of it agrees on. */\nexport const NumberElementContract = defineInputContract({\n\t$type: 'number',\n\tappearanceAxes: ['size'],\n\tschema: NumberFieldConfigSchema,\n\tvalue: numberFieldValue,\n\tmetadata: {\n\t\tname: 'Number Field',\n\t\tdescription: 'Number input field for numeric values',\n\t\tcategory: 'input',\n\t},\n});\n"],
5
+ "mappings": ";;;;;;;;AAAA,YAAY,OAAO;AAIZ,IAAM,6BAA+B,SAAO;AAAA,EAClD,KAAO,WAAW,SAAO,CAAC;AAAA,EAC1B,KAAO,WAAW,SAAO,CAAC;AAAA,EAC1B,MAAQ,WAAW,SAAO,CAAC;AAAA,EAC3B,cAAgB,WAAW,SAAO,CAAC;AAAA,EACnC,WAAa,WAAW,UAAQ,CAAC;AAAA,EACjC,WAAa,WAAW,OAAK,CAAC,QAAQ,QAAQ,WAAW,WAAW,OAAO,UAAU,SAAS,KAAK,CAAC,CAAC;AACtG,CAAC;AAEM,IAAM,0BAA4B,SAAO,iBAAiB;AAAA,EAChE,OAAS,UAAQ,QAAQ;AAAA,EACzB,GAAG,2BAA2B;AAC/B,CAAC;AAMM,IAAM,mBAAmB,MAAQ,SAAO;AAGxC,IAAM,wBAAwB,oBAAoB;AAAA,EACxD,OAAO;AAAA,EACP,gBAAgB,CAAC,MAAM;AAAA,EACvB,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,UAAU;AAAA,IACT,MAAM;AAAA,IACN,aAAa;AAAA,IACb,UAAU;AAAA,EACX;AACD,CAAC;",
6
+ "names": []
7
+ }