@schema-engine/forms 0.0.0-stage → 0.5.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.
- package/LICENSE +21 -0
- package/README.md +69 -2
- package/dist/actions/index.d.ts +3 -0
- package/dist/actions/index.js +50 -0
- package/dist/actions/index.js.map +7 -0
- package/dist/actions/plugins/auto-save.plugin.d.ts +39 -0
- package/dist/actions/plugins/auto-save.plugin.js +10 -0
- package/dist/actions/plugins/auto-save.plugin.js.map +7 -0
- package/dist/actions/plugins/form-reset.plugin.d.ts +23 -0
- package/dist/actions/plugins/form-reset.plugin.js +9 -0
- package/dist/actions/plugins/form-reset.plugin.js.map +7 -0
- package/dist/actions/plugins/form-submit.plugin.d.ts +31 -0
- package/dist/actions/plugins/form-submit.plugin.js +9 -0
- package/dist/actions/plugins/form-submit.plugin.js.map +7 -0
- package/dist/actions/plugins/form-submit.registration.d.ts +22 -0
- package/dist/actions/plugins/form-submit.registration.js +8 -0
- package/dist/actions/plugins/form-submit.registration.js.map +7 -0
- package/dist/actions/plugins/gtm.plugin.d.ts +30 -0
- package/dist/actions/plugins/gtm.plugin.js +8 -0
- package/dist/actions/plugins/gtm.plugin.js.map +7 -0
- package/dist/actions/plugins/index.d.ts +16 -0
- package/dist/actions/plugins/index.js +45 -0
- package/dist/actions/plugins/index.js.map +7 -0
- package/dist/actions/plugins/notification.plugin.d.ts +32 -0
- package/dist/actions/plugins/notification.plugin.js +9 -0
- package/dist/actions/plugins/notification.plugin.js.map +7 -0
- package/dist/actions/plugins/notification.registration.d.ts +22 -0
- package/dist/actions/plugins/notification.registration.js +8 -0
- package/dist/actions/plugins/notification.registration.js.map +7 -0
- package/dist/actions/plugins/registrations.d.ts +17 -0
- package/dist/actions/plugins/registrations.js +14 -0
- package/dist/actions/plugins/registrations.js.map +7 -0
- package/dist/actions/triggers.d.ts +42 -0
- package/dist/actions/triggers.js +6 -0
- package/dist/actions/triggers.js.map +7 -0
- package/dist/actions/types.d.ts +16 -0
- package/dist/actions/types.js +1 -0
- package/dist/actions/types.js.map +7 -0
- package/dist/agent-tool/index.d.ts +54 -0
- package/dist/agent-tool/index.js +128 -0
- package/dist/agent-tool/index.js.map +7 -0
- package/dist/browser/action-registrations.d.ts +46 -0
- package/dist/browser/action-registrations.js +19 -0
- package/dist/browser/action-registrations.js.map +7 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.js +36 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/browser/tools/auto-save-storage.d.ts +20 -0
- package/dist/browser/tools/auto-save-storage.js +12 -0
- package/dist/browser/tools/auto-save-storage.js.map +7 -0
- package/dist/browser/tools/gdpr-consent.d.ts +32 -0
- package/dist/browser/tools/gdpr-consent.js +11 -0
- package/dist/browser/tools/gdpr-consent.js.map +7 -0
- package/dist/browser/tools/gtm-tracker.d.ts +7 -0
- package/dist/browser/tools/gtm-tracker.js +7 -0
- package/dist/browser/tools/gtm-tracker.js.map +7 -0
- package/dist/builder/form-authoring.d.ts +159 -0
- package/dist/builder/form-authoring.js +1 -0
- package/dist/builder/form-authoring.js.map +7 -0
- package/dist/builder/form-values.d.ts +158 -0
- package/dist/builder/form-values.js +0 -0
- package/dist/builder/form-values.js.map +7 -0
- package/dist/builder/index.d.ts +5 -0
- package/dist/builder/index.js +2 -0
- package/dist/builder/index.js.map +7 -0
- package/dist/builder/types.utils.d.ts +137 -0
- package/dist/builder/types.utils.js +1 -0
- package/dist/builder/types.utils.js.map +7 -0
- package/dist/chunk-237BHPDH.js +88 -0
- package/dist/chunk-237BHPDH.js.map +7 -0
- package/dist/chunk-25PLQDKN.js +45 -0
- package/dist/chunk-25PLQDKN.js.map +7 -0
- package/dist/chunk-2PTM54FQ.js +51 -0
- package/dist/chunk-2PTM54FQ.js.map +7 -0
- package/dist/chunk-2VKEOE2L.js +907 -0
- package/dist/chunk-2VKEOE2L.js.map +7 -0
- package/dist/chunk-2XWISGGM.js +8 -0
- package/dist/chunk-2XWISGGM.js.map +7 -0
- package/dist/chunk-2YKQAVI2.js +8 -0
- package/dist/chunk-2YKQAVI2.js.map +7 -0
- package/dist/chunk-3B7CJOF6.js +18 -0
- package/dist/chunk-3B7CJOF6.js.map +7 -0
- package/dist/chunk-3YLRJVVN.js +17 -0
- package/dist/chunk-3YLRJVVN.js.map +7 -0
- package/dist/chunk-4CUGHU36.js +58 -0
- package/dist/chunk-4CUGHU36.js.map +7 -0
- package/dist/chunk-4FELFUCD.js +0 -0
- package/dist/chunk-4FELFUCD.js.map +7 -0
- package/dist/chunk-4XPLSYTK.js +82 -0
- package/dist/chunk-4XPLSYTK.js.map +7 -0
- package/dist/chunk-56CJ2UZ7.js +55 -0
- package/dist/chunk-56CJ2UZ7.js.map +7 -0
- package/dist/chunk-5QXT7YAJ.js +87 -0
- package/dist/chunk-5QXT7YAJ.js.map +7 -0
- package/dist/chunk-5Y6U3MR3.js +54 -0
- package/dist/chunk-5Y6U3MR3.js.map +7 -0
- package/dist/chunk-6BAJHAGL.js +29 -0
- package/dist/chunk-6BAJHAGL.js.map +7 -0
- package/dist/chunk-6FUGK5HQ.js +26 -0
- package/dist/chunk-6FUGK5HQ.js.map +7 -0
- package/dist/chunk-6IZYNHZ3.js +118 -0
- package/dist/chunk-6IZYNHZ3.js.map +7 -0
- package/dist/chunk-6NV2JDGI.js +8 -0
- package/dist/chunk-6NV2JDGI.js.map +7 -0
- package/dist/chunk-6R2MBQPL.js +19 -0
- package/dist/chunk-6R2MBQPL.js.map +7 -0
- package/dist/chunk-7EQJUI5N.js +40 -0
- package/dist/chunk-7EQJUI5N.js.map +7 -0
- package/dist/chunk-AUZ45XPE.js +27 -0
- package/dist/chunk-AUZ45XPE.js.map +7 -0
- package/dist/chunk-BIHEIJG3.js +0 -0
- package/dist/chunk-BIHEIJG3.js.map +7 -0
- package/dist/chunk-BKNWW4PK.js +0 -0
- package/dist/chunk-BKNWW4PK.js.map +7 -0
- package/dist/chunk-BLFLCSG3.js +71 -0
- package/dist/chunk-BLFLCSG3.js.map +7 -0
- package/dist/chunk-BYYGAGNH.js +0 -0
- package/dist/chunk-BYYGAGNH.js.map +7 -0
- package/dist/chunk-CAZPWBQ4.js +18 -0
- package/dist/chunk-CAZPWBQ4.js.map +7 -0
- package/dist/chunk-CMPOBBRV.js +10 -0
- package/dist/chunk-CMPOBBRV.js.map +7 -0
- package/dist/chunk-CRQWKC67.js +118 -0
- package/dist/chunk-CRQWKC67.js.map +7 -0
- package/dist/chunk-CRVXBWSY.js +70 -0
- package/dist/chunk-CRVXBWSY.js.map +7 -0
- package/dist/chunk-D6ZHV6AT.js +0 -0
- package/dist/chunk-D6ZHV6AT.js.map +7 -0
- package/dist/chunk-DVDKPY2A.js +12 -0
- package/dist/chunk-DVDKPY2A.js.map +7 -0
- package/dist/chunk-E4VONSLO.js +15 -0
- package/dist/chunk-E4VONSLO.js.map +7 -0
- package/dist/chunk-EEYGPPLU.js +185 -0
- package/dist/chunk-EEYGPPLU.js.map +7 -0
- package/dist/chunk-EI5TMJDC.js +56 -0
- package/dist/chunk-EI5TMJDC.js.map +7 -0
- package/dist/chunk-EQ5AIF3T.js +117 -0
- package/dist/chunk-EQ5AIF3T.js.map +7 -0
- package/dist/chunk-EZZHO6DQ.js +26 -0
- package/dist/chunk-EZZHO6DQ.js.map +7 -0
- package/dist/chunk-FUHLRG3M.js +130 -0
- package/dist/chunk-FUHLRG3M.js.map +7 -0
- package/dist/chunk-FVOL3ZOJ.js +101 -0
- package/dist/chunk-FVOL3ZOJ.js.map +7 -0
- package/dist/chunk-G33EUV7N.js +288 -0
- package/dist/chunk-G33EUV7N.js.map +7 -0
- package/dist/chunk-GH34XFCC.js +56 -0
- package/dist/chunk-GH34XFCC.js.map +7 -0
- package/dist/chunk-GKWRJ6H4.js +27 -0
- package/dist/chunk-GKWRJ6H4.js.map +7 -0
- package/dist/chunk-GRZU6F7Q.js +80 -0
- package/dist/chunk-GRZU6F7Q.js.map +7 -0
- package/dist/chunk-GT2LARKT.js +107 -0
- package/dist/chunk-GT2LARKT.js.map +7 -0
- package/dist/chunk-GY657L56.js +206 -0
- package/dist/chunk-GY657L56.js.map +7 -0
- package/dist/chunk-H4ABGAAG.js +60 -0
- package/dist/chunk-H4ABGAAG.js.map +7 -0
- package/dist/chunk-H63UHX42.js +93 -0
- package/dist/chunk-H63UHX42.js.map +7 -0
- package/dist/chunk-HEAKWS27.js +2730 -0
- package/dist/chunk-HEAKWS27.js.map +7 -0
- package/dist/chunk-HIS4MGIR.js +8 -0
- package/dist/chunk-HIS4MGIR.js.map +7 -0
- package/dist/chunk-HPPFSWIV.js +213 -0
- package/dist/chunk-HPPFSWIV.js.map +7 -0
- package/dist/chunk-J2FC5K4B.js +87 -0
- package/dist/chunk-J2FC5K4B.js.map +7 -0
- package/dist/chunk-J5BSFDVK.js +123 -0
- package/dist/chunk-J5BSFDVK.js.map +7 -0
- package/dist/chunk-J7GSNWXT.js +151 -0
- package/dist/chunk-J7GSNWXT.js.map +7 -0
- package/dist/chunk-K22S7IZR.js +12 -0
- package/dist/chunk-K22S7IZR.js.map +7 -0
- package/dist/chunk-K5TMXCMY.js +139 -0
- package/dist/chunk-K5TMXCMY.js.map +7 -0
- package/dist/chunk-KE53GN4Q.js +246 -0
- package/dist/chunk-KE53GN4Q.js.map +7 -0
- package/dist/chunk-KFQEDSYI.js +24 -0
- package/dist/chunk-KFQEDSYI.js.map +7 -0
- package/dist/chunk-KLATKWUA.js +116 -0
- package/dist/chunk-KLATKWUA.js.map +7 -0
- package/dist/chunk-KSKWSUOB.js +17 -0
- package/dist/chunk-KSKWSUOB.js.map +7 -0
- package/dist/chunk-LFWEJXWE.js +68 -0
- package/dist/chunk-LFWEJXWE.js.map +7 -0
- package/dist/chunk-LMWJAD3B.js +24 -0
- package/dist/chunk-LMWJAD3B.js.map +7 -0
- package/dist/chunk-MD23VADH.js +92 -0
- package/dist/chunk-MD23VADH.js.map +7 -0
- package/dist/chunk-MKMJT3XR.js +0 -0
- package/dist/chunk-MKMJT3XR.js.map +7 -0
- package/dist/chunk-NJTLBSTR.js +82 -0
- package/dist/chunk-NJTLBSTR.js.map +7 -0
- package/dist/chunk-NJXKMF67.js +182 -0
- package/dist/chunk-NJXKMF67.js.map +7 -0
- package/dist/chunk-OBQBIOGN.js +16 -0
- package/dist/chunk-OBQBIOGN.js.map +7 -0
- package/dist/chunk-OLYHNFKC.js +82 -0
- package/dist/chunk-OLYHNFKC.js.map +7 -0
- package/dist/chunk-OR2L7EKO.js +33 -0
- package/dist/chunk-OR2L7EKO.js.map +7 -0
- package/dist/chunk-OUF57UZ7.js +28 -0
- package/dist/chunk-OUF57UZ7.js.map +7 -0
- package/dist/chunk-PBMM2N77.js +56 -0
- package/dist/chunk-PBMM2N77.js.map +7 -0
- package/dist/chunk-PH3LWLYN.js +49 -0
- package/dist/chunk-PH3LWLYN.js.map +7 -0
- package/dist/chunk-PHNMDWSK.js +9 -0
- package/dist/chunk-PHNMDWSK.js.map +7 -0
- package/dist/chunk-PN5EH6DM.js +36 -0
- package/dist/chunk-PN5EH6DM.js.map +7 -0
- package/dist/chunk-POCAINUE.js +42 -0
- package/dist/chunk-POCAINUE.js.map +7 -0
- package/dist/chunk-PXWVKJGF.js +6 -0
- package/dist/chunk-PXWVKJGF.js.map +7 -0
- package/dist/chunk-Q5LEK7CI.js +64 -0
- package/dist/chunk-Q5LEK7CI.js.map +7 -0
- package/dist/chunk-QH7VW7IY.js +0 -0
- package/dist/chunk-QH7VW7IY.js.map +7 -0
- package/dist/chunk-QLGM2AZW.js +173 -0
- package/dist/chunk-QLGM2AZW.js.map +7 -0
- package/dist/chunk-QT3EYUL5.js +85 -0
- package/dist/chunk-QT3EYUL5.js.map +7 -0
- package/dist/chunk-QYHOFLRX.js +43 -0
- package/dist/chunk-QYHOFLRX.js.map +7 -0
- package/dist/chunk-R3MBVWVI.js +127 -0
- package/dist/chunk-R3MBVWVI.js.map +7 -0
- package/dist/chunk-R6V3LH7F.js +67 -0
- package/dist/chunk-R6V3LH7F.js.map +7 -0
- package/dist/chunk-RB22U6HI.js +64 -0
- package/dist/chunk-RB22U6HI.js.map +7 -0
- package/dist/chunk-RQRQYYTB.js +34 -0
- package/dist/chunk-RQRQYYTB.js.map +7 -0
- package/dist/chunk-S5D2QE4G.js +53 -0
- package/dist/chunk-S5D2QE4G.js.map +7 -0
- package/dist/chunk-S7I76ISM.js +245 -0
- package/dist/chunk-S7I76ISM.js.map +7 -0
- package/dist/chunk-TBDZOQ2C.js +66 -0
- package/dist/chunk-TBDZOQ2C.js.map +7 -0
- package/dist/chunk-U2X3IYSD.js +23 -0
- package/dist/chunk-U2X3IYSD.js.map +7 -0
- package/dist/chunk-UGL3KNOT.js +42 -0
- package/dist/chunk-UGL3KNOT.js.map +7 -0
- package/dist/chunk-UN3DARLG.js +35 -0
- package/dist/chunk-UN3DARLG.js.map +7 -0
- package/dist/chunk-VGGERKV2.js +7 -0
- package/dist/chunk-VGGERKV2.js.map +7 -0
- package/dist/chunk-VVFXYY65.js +0 -0
- package/dist/chunk-VVFXYY65.js.map +7 -0
- package/dist/chunk-WLDCYUN6.js +161 -0
- package/dist/chunk-WLDCYUN6.js.map +7 -0
- package/dist/chunk-WMDTQS36.js +0 -0
- package/dist/chunk-WMDTQS36.js.map +7 -0
- package/dist/chunk-WS7SLVXL.js +550 -0
- package/dist/chunk-WS7SLVXL.js.map +7 -0
- package/dist/chunk-WUTGZYP4.js +290 -0
- package/dist/chunk-WUTGZYP4.js.map +7 -0
- package/dist/chunk-XKN3WWK3.js +0 -0
- package/dist/chunk-XKN3WWK3.js.map +7 -0
- package/dist/chunk-XPQRHO5E.js +587 -0
- package/dist/chunk-XPQRHO5E.js.map +7 -0
- package/dist/chunk-XQ5VJ4QO.js +62 -0
- package/dist/chunk-XQ5VJ4QO.js.map +7 -0
- package/dist/chunk-XQVKX47O.js +174 -0
- package/dist/chunk-XQVKX47O.js.map +7 -0
- package/dist/chunk-Y5CNB57V.js +22 -0
- package/dist/chunk-Y5CNB57V.js.map +7 -0
- package/dist/chunk-YDGH7DTL.js +18 -0
- package/dist/chunk-YDGH7DTL.js.map +7 -0
- package/dist/chunk-YIFUBPJ3.js +0 -0
- package/dist/chunk-YIFUBPJ3.js.map +7 -0
- package/dist/chunk-YUUDXRBW.js +212 -0
- package/dist/chunk-YUUDXRBW.js.map +7 -0
- package/dist/chunk-Z6DQLJS2.js +23 -0
- package/dist/chunk-Z6DQLJS2.js.map +7 -0
- package/dist/chunk-ZDEZ2FOC.js +81 -0
- package/dist/chunk-ZDEZ2FOC.js.map +7 -0
- package/dist/chunk-ZUYSGCEH.js +65 -0
- package/dist/chunk-ZUYSGCEH.js.map +7 -0
- package/dist/chunk-ZYP3MIH3.js +115 -0
- package/dist/chunk-ZYP3MIH3.js.map +7 -0
- package/dist/constraints/constraint-evaluator.d.ts +57 -0
- package/dist/constraints/constraint-evaluator.js +17 -0
- package/dist/constraints/constraint-evaluator.js.map +7 -0
- package/dist/constraints/index.d.ts +1 -0
- package/dist/constraints/index.js +17 -0
- package/dist/constraints/index.js.map +7 -0
- package/dist/csrf/index.d.ts +43 -0
- package/dist/csrf/index.js +43 -0
- package/dist/csrf/index.js.map +7 -0
- package/dist/engine/build-form-engine.d.ts +27 -0
- package/dist/engine/build-form-engine.js +58 -0
- package/dist/engine/build-form-engine.js.map +7 -0
- package/dist/engine/component-type.d.ts +19 -0
- package/dist/engine/component-type.js +6 -0
- package/dist/engine/component-type.js.map +7 -0
- package/dist/engine/create-form-engine.d.ts +100 -0
- package/dist/engine/create-form-engine.js +59 -0
- package/dist/engine/create-form-engine.js.map +7 -0
- package/dist/engine/form-action-context.d.ts +70 -0
- package/dist/engine/form-action-context.js +10 -0
- package/dist/engine/form-action-context.js.map +7 -0
- package/dist/engine/form-engine.d.ts +236 -0
- package/dist/engine/form-engine.js +61 -0
- package/dist/engine/form-engine.js.map +7 -0
- package/dist/engine/index.d.ts +12 -0
- package/dist/engine/index.js +124 -0
- package/dist/engine/index.js.map +7 -0
- package/dist/engine/schema-artifacts.d.ts +87 -0
- package/dist/engine/schema-artifacts.js +14 -0
- package/dist/engine/schema-artifacts.js.map +7 -0
- package/dist/engine/schema-metadata-catalog.d.ts +41 -0
- package/dist/engine/schema-metadata-catalog.js +6 -0
- package/dist/engine/schema-metadata-catalog.js.map +7 -0
- package/dist/engine/step-machine.d.ts +59 -0
- package/dist/engine/step-machine.js +32 -0
- package/dist/engine/step-machine.js.map +7 -0
- package/dist/engine/submission-schema.d.ts +53 -0
- package/dist/engine/submission-schema.js +22 -0
- package/dist/engine/submission-schema.js.map +7 -0
- package/dist/engine/value-validation.d.ts +237 -0
- package/dist/engine/value-validation.js +39 -0
- package/dist/engine/value-validation.js.map +7 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +283 -0
- package/dist/index.js.map +7 -0
- package/dist/lib/authoring-catalog.d.ts +5 -0
- package/dist/lib/authoring-catalog.js +11 -0
- package/dist/lib/authoring-catalog.js.map +7 -0
- package/dist/lib/container-kind-of.d.ts +5 -0
- package/dist/lib/container-kind-of.js +6 -0
- package/dist/lib/container-kind-of.js.map +7 -0
- package/dist/lib/debounce.d.ts +19 -0
- package/dist/lib/debounce.js +6 -0
- package/dist/lib/debounce.js.map +7 -0
- package/dist/lib/deep-readonly.d.ts +12 -0
- package/dist/lib/deep-readonly.js +0 -0
- package/dist/lib/deep-readonly.js.map +7 -0
- package/dist/lib/element-children.d.ts +35 -0
- package/dist/lib/element-children.js +16 -0
- package/dist/lib/element-children.js.map +7 -0
- package/dist/lib/exported-action-envelope.d.ts +11 -0
- package/dist/lib/exported-action-envelope.js +7 -0
- package/dist/lib/exported-action-envelope.js.map +7 -0
- package/dist/lib/exported-rules.d.ts +14 -0
- package/dist/lib/exported-rules.js +6 -0
- package/dist/lib/exported-rules.js.map +7 -0
- package/dist/lib/field-ref.d.ts +13 -0
- package/dist/lib/field-ref.js +6 -0
- package/dist/lib/field-ref.js.map +7 -0
- package/dist/lib/field-scope.d.ts +121 -0
- package/dist/lib/field-scope.js +41 -0
- package/dist/lib/field-scope.js.map +7 -0
- package/dist/lib/form-fetch.d.ts +36 -0
- package/dist/lib/form-fetch.js +10 -0
- package/dist/lib/form-fetch.js.map +7 -0
- package/dist/lib/form-view.d.ts +33 -0
- package/dist/lib/form-view.js +12 -0
- package/dist/lib/form-view.js.map +7 -0
- package/dist/lib/frozen-copy.d.ts +9 -0
- package/dist/lib/frozen-copy.js +7 -0
- package/dist/lib/frozen-copy.js.map +7 -0
- package/dist/lib/is-plain-object.d.ts +2 -0
- package/dist/lib/is-plain-object.js +6 -0
- package/dist/lib/is-plain-object.js.map +7 -0
- package/dist/lib/logger.d.ts +2 -0
- package/dist/lib/logger.js +6 -0
- package/dist/lib/logger.js.map +7 -0
- package/dist/lib/normalized-form-config.d.ts +106 -0
- package/dist/lib/normalized-form-config.js +19 -0
- package/dist/lib/normalized-form-config.js.map +7 -0
- package/dist/lib/omit-paths.d.ts +11 -0
- package/dist/lib/omit-paths.js +7 -0
- package/dist/lib/omit-paths.js.map +7 -0
- package/dist/lib/path-values.d.ts +47 -0
- package/dist/lib/path-values.js +22 -0
- package/dist/lib/path-values.js.map +7 -0
- package/dist/lib/renderer-data-attributes.d.ts +10 -0
- package/dist/lib/renderer-data-attributes.js +6 -0
- package/dist/lib/renderer-data-attributes.js.map +7 -0
- package/dist/lib/reserved-path-keys.d.ts +10 -0
- package/dist/lib/reserved-path-keys.js +10 -0
- package/dist/lib/reserved-path-keys.js.map +7 -0
- package/dist/lib/resolve-appearance.d.ts +48 -0
- package/dist/lib/resolve-appearance.js +10 -0
- package/dist/lib/resolve-appearance.js.map +7 -0
- package/dist/lib/standard-json-schema.d.ts +27 -0
- package/dist/lib/standard-json-schema.js +8 -0
- package/dist/lib/standard-json-schema.js.map +7 -0
- package/dist/lib/standard-schema.d.ts +19 -0
- package/dist/lib/standard-schema.js +8 -0
- package/dist/lib/standard-schema.js.map +7 -0
- package/dist/lib/submission-shape.d.ts +60 -0
- package/dist/lib/submission-shape.js +14 -0
- package/dist/lib/submission-shape.js.map +7 -0
- package/dist/lib/validate-form/grid-checks.d.ts +57 -0
- package/dist/lib/validate-form/grid-checks.js +16 -0
- package/dist/lib/validate-form/grid-checks.js.map +7 -0
- package/dist/lib/validate-form/issues.d.ts +43 -0
- package/dist/lib/validate-form/issues.js +13 -0
- package/dist/lib/validate-form/issues.js.map +7 -0
- package/dist/lib/validate-form/options.d.ts +22 -0
- package/dist/lib/validate-form/options.js +0 -0
- package/dist/lib/validate-form/options.js.map +7 -0
- package/dist/lib/validate-form/parse-elements.d.ts +23 -0
- package/dist/lib/validate-form/parse-elements.js +21 -0
- package/dist/lib/validate-form/parse-elements.js.map +7 -0
- package/dist/lib/validate-form/parse-owner-actions.d.ts +14 -0
- package/dist/lib/validate-form/parse-owner-actions.js +10 -0
- package/dist/lib/validate-form/parse-owner-actions.js.map +7 -0
- package/dist/lib/validate-form/parse-view.d.ts +11 -0
- package/dist/lib/validate-form/parse-view.js +11 -0
- package/dist/lib/validate-form/parse-view.js.map +7 -0
- package/dist/lib/validate-form/schema-issues.d.ts +16 -0
- package/dist/lib/validate-form/schema-issues.js +8 -0
- package/dist/lib/validate-form/schema-issues.js.map +7 -0
- package/dist/lib/validate-form/step-checks.d.ts +18 -0
- package/dist/lib/validate-form/step-checks.js +15 -0
- package/dist/lib/validate-form/step-checks.js.map +7 -0
- package/dist/lib/validate-form/validation-error.d.ts +26 -0
- package/dist/lib/validate-form/validation-error.js +8 -0
- package/dist/lib/validate-form/validation-error.js.map +7 -0
- package/dist/lib/validate-form.d.ts +34 -0
- package/dist/lib/validate-form.js +62 -0
- package/dist/lib/validate-form.js.map +7 -0
- package/dist/lib/zod-json-schema.d.ts +33 -0
- package/dist/lib/zod-json-schema.js +10 -0
- package/dist/lib/zod-json-schema.js.map +7 -0
- package/dist/recipes/built-in-specs.d.ts +1832 -0
- package/dist/recipes/built-in-specs.js +28 -0
- package/dist/recipes/built-in-specs.js.map +7 -0
- package/dist/recipes/built-in.d.ts +2 -0
- package/dist/recipes/built-in.js +49 -0
- package/dist/recipes/built-in.js.map +7 -0
- package/dist/recipes/define-form-recipe.d.ts +10 -0
- package/dist/recipes/define-form-recipe.js +6 -0
- package/dist/recipes/define-form-recipe.js.map +7 -0
- package/dist/recipes/define-recipe-spec.d.ts +13 -0
- package/dist/recipes/define-recipe-spec.js +8 -0
- package/dist/recipes/define-recipe-spec.js.map +7 -0
- package/dist/recipes/index.d.ts +6 -0
- package/dist/recipes/index.js +43 -0
- package/dist/recipes/index.js.map +7 -0
- package/dist/recipes/protocol.d.ts +24 -0
- package/dist/recipes/protocol.js +11 -0
- package/dist/recipes/protocol.js.map +7 -0
- package/dist/recipes/slot-schemas.d.ts +128 -0
- package/dist/recipes/slot-schemas.js +24 -0
- package/dist/recipes/slot-schemas.js.map +7 -0
- package/dist/recipes/types.d.ts +55 -0
- package/dist/recipes/types.js +1 -0
- package/dist/recipes/types.js.map +7 -0
- package/dist/recipes/view-model.d.ts +93 -0
- package/dist/recipes/view-model.js +29 -0
- package/dist/recipes/view-model.js.map +7 -0
- package/dist/registries/index.d.ts +8 -0
- package/dist/registries/index.js +0 -0
- package/dist/registries/index.js.map +7 -0
- package/dist/runtime/create-form-runtime.d.ts +43 -0
- package/dist/runtime/create-form-runtime.js +41 -0
- package/dist/runtime/create-form-runtime.js.map +7 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +44 -0
- package/dist/runtime/index.js.map +7 -0
- package/dist/runtime/submission-lifecycle.d.ts +65 -0
- package/dist/runtime/submission-lifecycle.js +6 -0
- package/dist/runtime/submission-lifecycle.js.map +7 -0
- package/dist/runtime/types.d.ts +172 -0
- package/dist/runtime/types.js +6 -0
- package/dist/runtime/types.js.map +7 -0
- package/dist/schemas/base-field.d.ts +450 -0
- package/dist/schemas/base-field.js +36 -0
- package/dist/schemas/base-field.js.map +7 -0
- package/dist/schemas/field-config.d.ts +36 -0
- package/dist/schemas/field-config.js +1 -0
- package/dist/schemas/field-config.js.map +7 -0
- package/dist/schemas/form-config-shape.d.ts +763 -0
- package/dist/schemas/form-config-shape.js +35 -0
- package/dist/schemas/form-config-shape.js.map +7 -0
- package/dist/schemas/form-config.d.ts +1288 -0
- package/dist/schemas/form-config.js +41 -0
- package/dist/schemas/form-config.js.map +7 -0
- package/dist/schemas/html-attributes.d.ts +12 -0
- package/dist/schemas/html-attributes.js +12 -0
- package/dist/schemas/html-attributes.js.map +7 -0
- package/dist/schemas/index.d.ts +5 -0
- package/dist/schemas/index.js +165 -0
- package/dist/schemas/index.js.map +7 -0
- package/dist/schemas/validation/async/cache.d.ts +39 -0
- package/dist/schemas/validation/async/cache.js +6 -0
- package/dist/schemas/validation/async/cache.js.map +7 -0
- package/dist/schemas/validation/async/handler.d.ts +21 -0
- package/dist/schemas/validation/async/handler.js +11 -0
- package/dist/schemas/validation/async/handler.js.map +7 -0
- package/dist/schemas/validation/async/index.d.ts +8 -0
- package/dist/schemas/validation/async/index.js +14 -0
- package/dist/schemas/validation/async/index.js.map +7 -0
- package/dist/schemas/validation/defaults.d.ts +6 -0
- package/dist/schemas/validation/defaults.js +12 -0
- package/dist/schemas/validation/defaults.js.map +7 -0
- package/dist/schemas/validation/dependencies.d.ts +52 -0
- package/dist/schemas/validation/dependencies.js +17 -0
- package/dist/schemas/validation/dependencies.js.map +7 -0
- package/dist/schemas/validation/empty.d.ts +1 -0
- package/dist/schemas/validation/empty.js +6 -0
- package/dist/schemas/validation/empty.js.map +7 -0
- package/dist/schemas/validation/errors.d.ts +44 -0
- package/dist/schemas/validation/errors.js +12 -0
- package/dist/schemas/validation/errors.js.map +7 -0
- package/dist/schemas/validation/index.d.ts +9 -0
- package/dist/schemas/validation/index.js +130 -0
- package/dist/schemas/validation/index.js.map +7 -0
- package/dist/schemas/validation/presets.d.ts +66 -0
- package/dist/schemas/validation/presets.js +6 -0
- package/dist/schemas/validation/presets.js.map +7 -0
- package/dist/schemas/validation/relations.d.ts +12 -0
- package/dist/schemas/validation/relations.js +8 -0
- package/dist/schemas/validation/relations.js.map +7 -0
- package/dist/schemas/validation/types.d.ts +817 -0
- package/dist/schemas/validation/types.js +64 -0
- package/dist/schemas/validation/types.js.map +7 -0
- package/dist/schemas/validation/utils.d.ts +76 -0
- package/dist/schemas/validation/utils.js +24 -0
- package/dist/schemas/validation/utils.js.map +7 -0
- package/dist/schemas/validation/validation-registry.d.ts +124 -0
- package/dist/schemas/validation/validation-registry.js +27 -0
- package/dist/schemas/validation/validation-registry.js.map +7 -0
- package/dist/server-errors/from-json-api-errors.d.ts +13 -0
- package/dist/server-errors/from-json-api-errors.js +10 -0
- package/dist/server-errors/from-json-api-errors.js.map +7 -0
- package/dist/server-errors/from-problem-details.d.ts +15 -0
- package/dist/server-errors/from-problem-details.js +10 -0
- package/dist/server-errors/from-problem-details.js.map +7 -0
- package/dist/server-errors/index.d.ts +8 -0
- package/dist/server-errors/index.js +17 -0
- package/dist/server-errors/index.js.map +7 -0
- package/dist/server-errors/shared.d.ts +34 -0
- package/dist/server-errors/shared.js +23 -0
- package/dist/server-errors/shared.js.map +7 -0
- package/dist/state-container/create-form-state-container.d.ts +17 -0
- package/dist/state-container/create-form-state-container.js +31 -0
- package/dist/state-container/create-form-state-container.js.map +7 -0
- package/dist/state-container/dirty.d.ts +11 -0
- package/dist/state-container/dirty.js +9 -0
- package/dist/state-container/dirty.js.map +7 -0
- package/dist/state-container/field-array.d.ts +41 -0
- package/dist/state-container/field-array.js +8 -0
- package/dist/state-container/field-array.js.map +7 -0
- package/dist/state-container/hydration.d.ts +21 -0
- package/dist/state-container/hydration.js +11 -0
- package/dist/state-container/hydration.js.map +7 -0
- package/dist/state-container/index.d.ts +16 -0
- package/dist/state-container/index.js +51 -0
- package/dist/state-container/index.js.map +7 -0
- package/dist/state-container/issue-text.d.ts +11 -0
- package/dist/state-container/issue-text.js +6 -0
- package/dist/state-container/issue-text.js.map +7 -0
- package/dist/state-container/row-ids.d.ts +34 -0
- package/dist/state-container/row-ids.js +19 -0
- package/dist/state-container/row-ids.js.map +7 -0
- package/dist/state-container/selectors.d.ts +33 -0
- package/dist/state-container/selectors.js +22 -0
- package/dist/state-container/selectors.js.map +7 -0
- package/dist/state-container/stale-results.d.ts +28 -0
- package/dist/state-container/stale-results.js +9 -0
- package/dist/state-container/stale-results.js.map +7 -0
- package/dist/state-container/state-tree.d.ts +56 -0
- package/dist/state-container/state-tree.js +33 -0
- package/dist/state-container/state-tree.js.map +7 -0
- package/dist/state-container/submission.d.ts +45 -0
- package/dist/state-container/submission.js +26 -0
- package/dist/state-container/submission.js.map +7 -0
- package/dist/state-container/types.d.ts +404 -0
- package/dist/state-container/types.js +6 -0
- package/dist/state-container/types.js.map +7 -0
- package/dist/state-container/value-tree.d.ts +56 -0
- package/dist/state-container/value-tree.js +34 -0
- package/dist/state-container/value-tree.js.map +7 -0
- package/dist/testing/form-state-container-conformance.d.ts +51 -0
- package/dist/testing/form-state-container-conformance.js +43 -0
- package/dist/testing/form-state-container-conformance.js.map +7 -0
- package/dist/testing/index.d.ts +7 -0
- package/dist/testing/index.js +35 -0
- package/dist/testing/index.js.map +7 -0
- package/dist/types/actions.d.ts +75 -0
- package/dist/types/actions.js +1 -0
- package/dist/types/actions.js.map +7 -0
- package/dist/types/categories.d.ts +21 -0
- package/dist/types/categories.js +8 -0
- package/dist/types/categories.js.map +7 -0
- package/dist/types/define-element.d.ts +73 -0
- package/dist/types/define-element.js +8 -0
- package/dist/types/define-element.js.map +7 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.js +17 -0
- package/dist/types/index.js.map +7 -0
- package/dist/types/metadata.d.ts +14 -0
- package/dist/types/metadata.js +1 -0
- package/dist/types/metadata.js.map +7 -0
- package/dist/types/registration.d.ts +142 -0
- package/dist/types/registration.js +1 -0
- package/dist/types/registration.js.map +7 -0
- package/package.json +119 -3
- package/skill/SKILL.md +79 -0
- package/skill/reference/forms-actions.md +51 -0
- package/skill/reference/forms-submission.md +44 -0
- package/skill/reference/forms-validation.md +91 -0
- package/skill/reference/forms.md +179 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isZodType
|
|
3
|
+
} from "./chunk-25PLQDKN.js";
|
|
4
|
+
import {
|
|
5
|
+
buildSubmissionShape
|
|
6
|
+
} from "./chunk-NJTLBSTR.js";
|
|
7
|
+
import {
|
|
8
|
+
frozenCopy
|
|
9
|
+
} from "./chunk-3B7CJOF6.js";
|
|
10
|
+
import {
|
|
11
|
+
getValidationRulesForElement,
|
|
12
|
+
isFieldRequired
|
|
13
|
+
} from "./chunk-KLATKWUA.js";
|
|
14
|
+
import {
|
|
15
|
+
isPlainObject
|
|
16
|
+
} from "./chunk-CMPOBBRV.js";
|
|
17
|
+
|
|
18
|
+
// src/engine/submission-schema.ts
|
|
19
|
+
import * as z from "zod/mini";
|
|
20
|
+
var EMPTY = ["", null];
|
|
21
|
+
var isEmpty = (value) => value === void 0 || value === "" || value === null;
|
|
22
|
+
var isRequired = (node) => node.kind !== "any" && node.required;
|
|
23
|
+
function requiredOf(shape, source, inside = false) {
|
|
24
|
+
const { element } = shape;
|
|
25
|
+
const ruled = element !== void 0 && !shape.conditional && isFieldRequired(
|
|
26
|
+
getValidationRulesForElement(
|
|
27
|
+
element,
|
|
28
|
+
source.validationRegistry
|
|
29
|
+
)
|
|
30
|
+
);
|
|
31
|
+
return ruled || inside;
|
|
32
|
+
}
|
|
33
|
+
function describeElement(element) {
|
|
34
|
+
const { label, description } = element ?? {};
|
|
35
|
+
const parts = [label, description].filter((part) => typeof part === "string" && part !== "");
|
|
36
|
+
return parts.length > 0 ? { description: parts.join(": ") } : {};
|
|
37
|
+
}
|
|
38
|
+
function leafOf(shape, source) {
|
|
39
|
+
const { element } = shape;
|
|
40
|
+
const registration = element.$type ? source.getElement(element.$type) : void 0;
|
|
41
|
+
const schema = registration && "value" in registration ? registration.value?.(element) : void 0;
|
|
42
|
+
if (schema === void 0) return { kind: "any" };
|
|
43
|
+
return {
|
|
44
|
+
kind: "leaf",
|
|
45
|
+
name: element.name ?? "",
|
|
46
|
+
schema,
|
|
47
|
+
required: requiredOf(shape, source),
|
|
48
|
+
...describeElement(element)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function nodeOf(shape, source) {
|
|
52
|
+
if (shape.kind === "field") return leafOf(shape, source);
|
|
53
|
+
if (shape.kind === "array") {
|
|
54
|
+
return {
|
|
55
|
+
kind: "array",
|
|
56
|
+
row: nodeOf(shape.row, source),
|
|
57
|
+
required: requiredOf(shape, source),
|
|
58
|
+
...describeElement(shape.element)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const fields = Object.entries(shape.fields).map(([key, child]) => [key, nodeOf(child, source)]);
|
|
62
|
+
const inside = fields.some(([, child]) => isRequired(child));
|
|
63
|
+
return { kind: "object", fields, required: requiredOf(shape, source, inside), ...describeElement(shape.element) };
|
|
64
|
+
}
|
|
65
|
+
function validateLeaf(schema, value) {
|
|
66
|
+
const result = schema["~standard"].validate(value);
|
|
67
|
+
if (result instanceof Promise) throw new Error("A value schema must validate synchronously.");
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
var joined = (path, key) => [...path, key];
|
|
71
|
+
var DEFAULT_NOT_CHECKED = "The default could not be checked: ";
|
|
72
|
+
function atField(issue) {
|
|
73
|
+
const path = issue.path ?? [];
|
|
74
|
+
const row = path.findIndex((segment) => typeof segment === "number");
|
|
75
|
+
return row === -1 ? issue : { ...issue, path: path.slice(0, row) };
|
|
76
|
+
}
|
|
77
|
+
function parse(node, value, path, partial, issues) {
|
|
78
|
+
switch (node.kind) {
|
|
79
|
+
case "any":
|
|
80
|
+
return value;
|
|
81
|
+
case "leaf": {
|
|
82
|
+
if ((partial || !node.required) && isEmpty(value)) return value;
|
|
83
|
+
let result;
|
|
84
|
+
try {
|
|
85
|
+
result = validateLeaf(node.schema, value);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (!partial) throw error;
|
|
88
|
+
const cause = error instanceof Error ? error.message : String(error);
|
|
89
|
+
issues.push({ message: `${DEFAULT_NOT_CHECKED}${cause}`, path });
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
if (result.issues === void 0) return result.value;
|
|
93
|
+
for (const issue of result.issues) {
|
|
94
|
+
const inside = partial ? [] : (issue.path ?? []).map((segment) => typeof segment === "object" ? segment.key : segment);
|
|
95
|
+
issues.push({ ...issue, path: [...path, ...inside] });
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
}
|
|
99
|
+
case "array": {
|
|
100
|
+
if (value === void 0) return void 0;
|
|
101
|
+
if (!Array.isArray(value)) {
|
|
102
|
+
issues.push({ message: "Expected a list", path });
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
return value.map((row, index) => parse(node.row, row, joined(path, index), partial, issues));
|
|
106
|
+
}
|
|
107
|
+
case "object": {
|
|
108
|
+
if (value === void 0) return void 0;
|
|
109
|
+
if (!isPlainObject(value)) {
|
|
110
|
+
issues.push({ message: "Expected an object", path });
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
const kept = {};
|
|
114
|
+
for (const [key, child] of node.fields) {
|
|
115
|
+
const present = Object.hasOwn(value, key) && value[key] !== void 0;
|
|
116
|
+
if (!present) {
|
|
117
|
+
if (isRequired(child) && !partial) {
|
|
118
|
+
issues.push({ message: "Required", path: joined(path, key) });
|
|
119
|
+
}
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
kept[key] = parse(child, value[key], joined(path, key), partial, issues);
|
|
123
|
+
}
|
|
124
|
+
return kept;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function issuePath(issue) {
|
|
129
|
+
return (issue.path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
130
|
+
}
|
|
131
|
+
function standardOptions(options) {
|
|
132
|
+
switch (options.target) {
|
|
133
|
+
case "draft-2020-12":
|
|
134
|
+
return { target: "draft-2020-12" };
|
|
135
|
+
case "draft-07":
|
|
136
|
+
return { target: "draft-7" };
|
|
137
|
+
case "openapi-3.0":
|
|
138
|
+
return { target: "openapi-3.0" };
|
|
139
|
+
default:
|
|
140
|
+
throw new Error(`The JSON Schema target '${options.target}' is not supported for a submission.`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
var hasJsonSchema = (schema) => "jsonSchema" in schema["~standard"];
|
|
144
|
+
function leafJsonSchema(name, schema, io, options) {
|
|
145
|
+
if (hasJsonSchema(schema)) return schema["~standard"].jsonSchema[io](options);
|
|
146
|
+
if (isZodType(schema)) {
|
|
147
|
+
const { $schema: _dropped, ...rest } = z.toJSONSchema(schema, {
|
|
148
|
+
...standardOptions(options),
|
|
149
|
+
io,
|
|
150
|
+
unrepresentable: "any"
|
|
151
|
+
});
|
|
152
|
+
return rest;
|
|
153
|
+
}
|
|
154
|
+
throw new Error(`The value schema of '${name}' has no JSON Schema.`);
|
|
155
|
+
}
|
|
156
|
+
function toJsonSchema(node, io, options) {
|
|
157
|
+
const schema = nodeJsonSchema(node, io, options);
|
|
158
|
+
return node.kind !== "any" && node.description ? { ...schema, description: node.description } : schema;
|
|
159
|
+
}
|
|
160
|
+
function nodeJsonSchema(node, io, options) {
|
|
161
|
+
switch (node.kind) {
|
|
162
|
+
case "any":
|
|
163
|
+
return {};
|
|
164
|
+
case "leaf": {
|
|
165
|
+
const schema = leafJsonSchema(node.name, node.schema, io, options);
|
|
166
|
+
return node.required ? schema : { anyOf: [schema, ...EMPTY.map((empty) => ({ const: empty }))] };
|
|
167
|
+
}
|
|
168
|
+
case "array":
|
|
169
|
+
return { type: "array", items: toJsonSchema(node.row, io, options) };
|
|
170
|
+
case "object": {
|
|
171
|
+
const required = node.fields.flatMap(([key, child]) => isRequired(child) ? [key] : []);
|
|
172
|
+
return {
|
|
173
|
+
type: "object",
|
|
174
|
+
properties: Object.fromEntries(
|
|
175
|
+
node.fields.map(([key, child]) => [key, toJsonSchema(child, io, options)])
|
|
176
|
+
),
|
|
177
|
+
...required.length ? { required } : {},
|
|
178
|
+
additionalProperties: false
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function createSubmissionSchema(config, source) {
|
|
184
|
+
const shape = buildSubmissionShape(config.steps);
|
|
185
|
+
const root = nodeOf(shape, source);
|
|
186
|
+
const payload = Object.entries(config.payload ?? {}).map(([key]) => [key, { kind: "any" }]);
|
|
187
|
+
const tree = root.kind === "object" ? { ...root, fields: [...root.fields, ...payload] } : root;
|
|
188
|
+
const validator = (partial) => (value) => {
|
|
189
|
+
const issues = [];
|
|
190
|
+
const parsed = parse(tree, value, [], partial, issues);
|
|
191
|
+
if (issues.length) return { issues: partial ? issues.map(atField) : issues };
|
|
192
|
+
return isPlainObject(parsed) ? { value: frozenCopy(parsed) } : { issues: [{ message: "Expected an object" }] };
|
|
193
|
+
};
|
|
194
|
+
const props = (partial) => ({
|
|
195
|
+
version: 1,
|
|
196
|
+
vendor: "schema-engine",
|
|
197
|
+
validate: validator(partial)
|
|
198
|
+
});
|
|
199
|
+
const jsonSchema = {
|
|
200
|
+
input: (options) => ({ ...toJsonSchema(tree, "input", options) }),
|
|
201
|
+
output: (options) => ({ ...toJsonSchema(tree, "output", options) })
|
|
202
|
+
};
|
|
203
|
+
return {
|
|
204
|
+
"~standard": { ...props(false), jsonSchema },
|
|
205
|
+
partial: { "~standard": props(true) }
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export {
|
|
210
|
+
DEFAULT_NOT_CHECKED,
|
|
211
|
+
issuePath,
|
|
212
|
+
createSubmissionSchema
|
|
213
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/engine/submission-schema.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';\nimport * as z from 'zod/mini';\nimport { frozenCopy } from '@/lib/frozen-copy';\nimport { isPlainObject } from '@/lib/is-plain-object';\nimport { buildSubmissionShape, type ShapeElement, type ShapeStep, type SubmissionShape } from '@/lib/submission-shape';\nimport { isZodType } from '@/lib/zod-json-schema';\nimport type { JSONSchemaObject } from '@/lib/standard-json-schema';\nimport type { ValidationRegistry } from '@/schemas/validation/validation-registry';\nimport { getValidationRulesForElement, isFieldRequired } from '@/schemas/validation/utils';\nimport type { BaseValidationRule } from '@/schemas/validation/types';\nimport type { AnyElementRegistration } from '@/types/registration';\n\n/**\n * The submitted values of a form, as a Standard Schema, and as a Standard JSON Schema where its value schemas can say so.\n *\n * @remarks\n * `~standard.validate` checks a submission: the values the container submits, whose keys are the fields' names\n * (dotted names nested), and returns them without any key a field does not declare. A mismatch is a broken\n * element contract, not a user error. `partial` is the same schema with every key optional at every depth and\n * every leaf allowed to be empty, for the `defaultValues` of a form that has not been filled. A value schema that cannot\n * check a default (it throws, or is asynchronous) is reported there as an issue at its field, so one default that cannot\n * be checked never stops the others from being.\n *\n * @remarks\n * An issue of `partial` is at the field, because a default is kept or dropped as a whole: a leaf is a field, a group is\n * not (its fields are), and a list is one field, so an issue inside a row is at the list (`tags`, not `tags.0` or\n * `tags.0.name`). `createFormRuntime` drops the default of each field `partial` reports.\n */\nexport interface SubmissionSchema<TValues = Readonly<Record<string, unknown>>>\n\textends StandardSchemaV1<unknown, TValues>, StandardJSONSchemaV1<unknown, TValues> {\n\treadonly '~standard': StandardSchemaV1.Props<unknown, TValues> & StandardJSONSchemaV1.Props<unknown, TValues>;\n\treadonly partial: {\n\t\treadonly '~standard': Omit<StandardSchemaV1.Props<unknown, unknown>, 'validate'> & {\n\t\t\treadonly validate: (value: unknown) => StandardSchemaV1.Result<unknown>;\n\t\t};\n\t};\n}\n\n/** What the composer needs of an engine: the element registrations and the validation rules. */\nexport interface SubmissionSchemaSource {\n\tgetElement(id: string): AnyElementRegistration | undefined;\n\treadonly validationRegistry: ValidationRegistry;\n}\n\n/** What it reads of the form config: its steps and its payload. */\nexport interface SubmissionSchemaConfig {\n\treadonly steps: readonly ShapeStep[];\n\treadonly payload?: Readonly<Record<string, unknown>>;\n}\n\n/** The empty values of an optional leaf field, which a submission keeps so a PATCH can tell cleared from untouched. */\nconst EMPTY = ['', null] as const;\n\ntype Issues = StandardSchemaV1.Issue[];\ntype Key = PropertyKey;\n\n/** A node of the schema: what the shape's field, object or array checks, with the value schema of each leaf resolved. */\ntype Node =\n\t| {\n\t\t\treadonly kind: 'leaf';\n\t\t\treadonly name: string;\n\t\t\treadonly schema: StandardSchemaV1;\n\t\t\treadonly required: boolean;\n\t\t\treadonly description?: string;\n\t }\n\t| {\n\t\t\treadonly kind: 'object';\n\t\t\treadonly fields: ReadonlyArray<readonly [string, Node]>;\n\t\t\treadonly required: boolean;\n\t\t\treadonly description?: string;\n\t }\n\t| { readonly kind: 'array'; readonly row: Node; readonly required: boolean; readonly description?: string }\n\t| { readonly kind: 'any' };\n\nconst isEmpty = (value: unknown): boolean => value === undefined || value === '' || value === null;\n\nconst isRequired = (node: Node): boolean => node.kind !== 'any' && node.required;\n\n/**\n * Whether a key is required: its field has a `required` rule and nothing can leave it out, or something inside it is required.\n */\nfunction requiredOf(shape: SubmissionShape, source: SubmissionSchemaSource, inside = false): boolean {\n\tconst { element } = shape;\n\tconst ruled =\n\t\telement !== undefined &&\n\t\t!shape.conditional &&\n\t\tisFieldRequired(\n\t\t\tgetValidationRulesForElement(\n\t\t\t\telement as { $type?: string; rules?: readonly BaseValidationRule[] },\n\t\t\t\tsource.validationRegistry,\n\t\t\t),\n\t\t);\n\treturn ruled || inside;\n}\n\n/** What the JSON Schema says about a field: its label, then its help text. */\nfunction describeElement(element: ShapeElement | undefined): { description?: string } {\n\tconst { label, description } = (element ?? {}) as { label?: unknown; description?: unknown };\n\tconst parts = [label, description].filter((part): part is string => typeof part === 'string' && part !== '');\n\treturn parts.length > 0 ? { description: parts.join(': ') } : {};\n}\n\nfunction leafOf(shape: Extract<SubmissionShape, { kind: 'field' }>, source: SubmissionSchemaSource): Node {\n\tconst { element } = shape;\n\tconst registration = element.$type ? source.getElement(element.$type) : undefined;\n\tconst schema = registration && 'value' in registration ? registration.value?.(element as never) : undefined;\n\tif (schema === undefined) return { kind: 'any' };\n\treturn {\n\t\tkind: 'leaf',\n\t\tname: element.name ?? '',\n\t\tschema,\n\t\trequired: requiredOf(shape, source),\n\t\t...describeElement(element),\n\t};\n}\n\nfunction nodeOf(shape: SubmissionShape, source: SubmissionSchemaSource): Node {\n\tif (shape.kind === 'field') return leafOf(shape, source);\n\tif (shape.kind === 'array') {\n\t\treturn {\n\t\t\tkind: 'array',\n\t\t\trow: nodeOf(shape.row, source),\n\t\t\trequired: requiredOf(shape, source),\n\t\t\t...describeElement(shape.element),\n\t\t};\n\t}\n\tconst fields = Object.entries(shape.fields).map(([key, child]) => [key, nodeOf(child, source)] as const);\n\tconst inside = fields.some(([, child]) => isRequired(child));\n\treturn { kind: 'object', fields, required: requiredOf(shape, source, inside), ...describeElement(shape.element) };\n}\n\nfunction validateLeaf(schema: StandardSchemaV1, value: unknown): StandardSchemaV1.Result<unknown> {\n\tconst result = schema['~standard'].validate(value);\n\tif (result instanceof Promise) throw new Error('A value schema must validate synchronously.');\n\treturn result;\n}\n\nconst joined = (path: readonly Key[], key: Key): readonly Key[] => [...path, key];\n\n/** What an issue of a partial parse says when a default could not be checked at all, which the runtime reads to tell it from a mismatch. */\nexport const DEFAULT_NOT_CHECKED = 'The default could not be checked: ';\n\n/** An issue of a partial parse, moved to the field it is about: a list is one field, so a path inside a row is its list's. */\nfunction atField(issue: StandardSchemaV1.Issue): StandardSchemaV1.Issue {\n\tconst path = issue.path ?? [];\n\tconst row = path.findIndex((segment) => typeof segment === 'number');\n\treturn row === -1 ? issue : { ...issue, path: path.slice(0, row) };\n}\n\n/** What parsing a node found: the value it keeps (`undefined` leaves the key out) and every issue, under `path`. */\nfunction parse(node: Node, value: unknown, path: readonly Key[], partial: boolean, issues: Issues): unknown {\n\tswitch (node.kind) {\n\t\tcase 'any':\n\t\t\treturn value;\n\t\tcase 'leaf': {\n\t\t\tif ((partial || !node.required) && isEmpty(value)) return value;\n\t\t\tlet result: StandardSchemaV1.Result<unknown>;\n\t\t\ttry {\n\t\t\t\tresult = validateLeaf(node.schema, value);\n\t\t\t} catch (error) {\n\t\t\t\tif (!partial) throw error;\n\t\t\t\tconst cause = error instanceof Error ? error.message : String(error);\n\t\t\t\tissues.push({ message: `${DEFAULT_NOT_CHECKED}${cause}`, path });\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tif (result.issues === undefined) return result.value;\n\t\t\tfor (const issue of result.issues) {\n\t\t\t\tconst inside = partial\n\t\t\t\t\t? []\n\t\t\t\t\t: (issue.path ?? []).map((segment) => (typeof segment === 'object' ? segment.key : segment));\n\t\t\t\tissues.push({ ...issue, path: [...path, ...inside] });\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcase 'array': {\n\t\t\tif (value === undefined) return undefined;\n\t\t\tif (!Array.isArray(value)) {\n\t\t\t\tissues.push({ message: 'Expected a list', path });\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\treturn value.map((row, index) => parse(node.row, row, joined(path, index), partial, issues));\n\t\t}\n\t\tcase 'object': {\n\t\t\tif (value === undefined) return undefined;\n\t\t\tif (!isPlainObject(value)) {\n\t\t\t\tissues.push({ message: 'Expected an object', path });\n\t\t\t\treturn value;\n\t\t\t}\n\t\t\tconst kept: Record<string, unknown> = {};\n\t\t\tfor (const [key, child] of node.fields) {\n\t\t\t\tconst present = Object.hasOwn(value, key) && value[key] !== undefined;\n\t\t\t\tif (!present) {\n\t\t\t\t\tif (isRequired(child) && !partial) {\n\t\t\t\t\t\tissues.push({ message: 'Required', path: joined(path, key) });\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tkept[key] = parse(child, value[key], joined(path, key), partial, issues);\n\t\t\t}\n\t\t\treturn kept;\n\t\t}\n\t}\n}\n\n/** The path of an issue as the dotted string a field is known by (`contacts.0.email`). */\nexport function issuePath(issue: StandardSchemaV1.Issue): string {\n\treturn (issue.path ?? []).map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.');\n}\n\nfunction standardOptions(options: StandardJSONSchemaV1.Options): {\n\ttarget: 'draft-2020-12' | 'draft-7' | 'openapi-3.0';\n} {\n\tswitch (options.target) {\n\t\tcase 'draft-2020-12':\n\t\t\treturn { target: 'draft-2020-12' };\n\t\tcase 'draft-07':\n\t\t\treturn { target: 'draft-7' };\n\t\tcase 'openapi-3.0':\n\t\t\treturn { target: 'openapi-3.0' };\n\t\tdefault:\n\t\t\tthrow new Error(`The JSON Schema target '${options.target}' is not supported for a submission.`);\n\t}\n}\n\nconst hasJsonSchema = (schema: StandardSchemaV1): schema is StandardSchemaV1 & StandardJSONSchemaV1 =>\n\t'jsonSchema' in schema['~standard'];\n\nfunction leafJsonSchema(\n\tname: string,\n\tschema: StandardSchemaV1,\n\tio: 'input' | 'output',\n\toptions: StandardJSONSchemaV1.Options,\n): JSONSchemaObject {\n\tif (hasJsonSchema(schema)) return schema['~standard'].jsonSchema[io](options);\n\tif (isZodType(schema)) {\n\t\tconst { $schema: _dropped, ...rest } = z.toJSONSchema(schema, {\n\t\t\t...standardOptions(options),\n\t\t\tio,\n\t\t\tunrepresentable: 'any',\n\t\t}) as JSONSchemaObject;\n\t\treturn rest;\n\t}\n\tthrow new Error(`The value schema of '${name}' has no JSON Schema.`);\n}\n\nfunction toJsonSchema(node: Node, io: 'input' | 'output', options: StandardJSONSchemaV1.Options): JSONSchemaObject {\n\tconst schema = nodeJsonSchema(node, io, options);\n\treturn node.kind !== 'any' && node.description ? { ...schema, description: node.description } : schema;\n}\n\nfunction nodeJsonSchema(node: Node, io: 'input' | 'output', options: StandardJSONSchemaV1.Options): JSONSchemaObject {\n\tswitch (node.kind) {\n\t\tcase 'any':\n\t\t\treturn {};\n\t\tcase 'leaf': {\n\t\t\tconst schema = leafJsonSchema(node.name, node.schema, io, options);\n\t\t\treturn node.required ? schema : { anyOf: [schema, ...EMPTY.map((empty) => ({ const: empty }))] };\n\t\t}\n\t\tcase 'array':\n\t\t\treturn { type: 'array', items: toJsonSchema(node.row, io, options) };\n\t\tcase 'object': {\n\t\t\tconst required = node.fields.flatMap(([key, child]) => (isRequired(child) ? [key] : []));\n\t\t\treturn {\n\t\t\t\ttype: 'object',\n\t\t\t\tproperties: Object.fromEntries(\n\t\t\t\t\tnode.fields.map(([key, child]) => [key, toJsonSchema(child, io, options)]),\n\t\t\t\t),\n\t\t\t\t...(required.length ? { required } : {}),\n\t\t\t\tadditionalProperties: false,\n\t\t\t};\n\t\t}\n\t}\n}\n\n/**\n * Composes the submission schema of a form from its elements' value declarations.\n *\n * @remarks\n * The rules are the container's, read from one {@link buildSubmissionShape}: dotted names nest, named containers\n * become objects, `containerKind: 'array'` becomes an array, a one-child row is a list of values (unless its child is a container of its own, which makes the rows objects) and the `payload`\n * keys are added as they are. A named element that declares no value (a static one) is carried as it is, so the keys of the schema are exactly the shape's. An optional\n * leaf field accepts its empty value (`''` or `null`) as well as its declared one, because a submission keeps what the\n * user cleared; a required field is held to its declaration. Its JSON Schema describes each field by its label, then its help text. A value schema is read once, when this is called.\n */\nexport function createSubmissionSchema(\n\tconfig: SubmissionSchemaConfig,\n\tsource: SubmissionSchemaSource,\n): SubmissionSchema {\n\tconst shape = buildSubmissionShape(config.steps);\n\tconst root = nodeOf(shape, source);\n\tconst payload = Object.entries(config.payload ?? {}).map(([key]) => [key, { kind: 'any' } as Node] as const);\n\tconst tree: Node = root.kind === 'object' ? { ...root, fields: [...root.fields, ...payload] } : root;\n\n\tconst validator =\n\t\t(partial: boolean) =>\n\t\t(value: unknown): StandardSchemaV1.Result<Readonly<Record<string, unknown>>> => {\n\t\t\tconst issues: Issues = [];\n\t\t\tconst parsed = parse(tree, value, [], partial, issues);\n\t\t\tif (issues.length) return { issues: partial ? issues.map(atField) : issues };\n\t\t\treturn isPlainObject(parsed)\n\t\t\t\t? { value: frozenCopy(parsed) }\n\t\t\t\t: { issues: [{ message: 'Expected an object' }] };\n\t\t};\n\tconst props = (partial: boolean) => ({\n\t\tversion: 1 as const,\n\t\tvendor: 'schema-engine',\n\t\tvalidate: validator(partial),\n\t});\n\tconst jsonSchema: StandardJSONSchemaV1.Converter = {\n\t\tinput: (options) => ({ ...toJsonSchema(tree, 'input', options) }),\n\t\toutput: (options) => ({ ...toJsonSchema(tree, 'output', options) }),\n\t};\n\treturn {\n\t\t'~standard': { ...props(false), jsonSchema },\n\t\tpartial: { '~standard': props(true) },\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AACA,YAAY,OAAO;AAkDnB,IAAM,QAAQ,CAAC,IAAI,IAAI;AAuBvB,IAAM,UAAU,CAAC,UAA4B,UAAU,UAAa,UAAU,MAAM,UAAU;AAE9F,IAAM,aAAa,CAAC,SAAwB,KAAK,SAAS,SAAS,KAAK;AAKxE,SAAS,WAAW,OAAwB,QAAgC,SAAS,OAAgB;AACpG,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,QACL,YAAY,UACZ,CAAC,MAAM,eACP;AAAA,IACC;AAAA,MACC;AAAA,MACA,OAAO;AAAA,IACR;AAAA,EACD;AACD,SAAO,SAAS;AACjB;AAGA,SAAS,gBAAgB,SAA6D;AACrF,QAAM,EAAE,OAAO,YAAY,IAAK,WAAW,CAAC;AAC5C,QAAM,QAAQ,CAAC,OAAO,WAAW,EAAE,OAAO,CAAC,SAAyB,OAAO,SAAS,YAAY,SAAS,EAAE;AAC3G,SAAO,MAAM,SAAS,IAAI,EAAE,aAAa,MAAM,KAAK,IAAI,EAAE,IAAI,CAAC;AAChE;AAEA,SAAS,OAAO,OAAoD,QAAsC;AACzG,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,eAAe,QAAQ,QAAQ,OAAO,WAAW,QAAQ,KAAK,IAAI;AACxE,QAAM,SAAS,gBAAgB,WAAW,eAAe,aAAa,QAAQ,OAAgB,IAAI;AAClG,MAAI,WAAW,OA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|
|
9
|
+
function getSlotConfig(viewConfig, slot, schema) {
|
|
10
|
+
return readSlotConfig(viewConfig, slot, schema);
|
|
11
|
+
}
|
|
12
|
+
function getViewRecipe(engine, config) {
|
|
13
|
+
if (!config.view) return void 0;
|
|
14
|
+
const recipe = engine.getRecipe(config.view.$type);
|
|
15
|
+
if (!recipe) {
|
|
16
|
+
throw new Error(`Form '${config.id}' uses view '${config.view.$type}' but the engine has no such recipe.`);
|
|
17
|
+
}
|
|
18
|
+
return recipe;
|
|
19
|
+
}
|
|
20
|
+
function projectViewSteps(steps, states, current) {
|
|
21
|
+
const active = steps.flatMap((step) => {
|
|
22
|
+
const state = states.find(({ id }) => id === step.id);
|
|
23
|
+
return state?.skipped ? [] : [{ step, state }];
|
|
24
|
+
});
|
|
25
|
+
return active.map(({ step, state }, index) => ({
|
|
26
|
+
id: step.id,
|
|
27
|
+
title: step.title,
|
|
28
|
+
description: step.description,
|
|
29
|
+
index,
|
|
30
|
+
total: active.length,
|
|
31
|
+
isActive: step.id === current,
|
|
32
|
+
isCompleted: state?.complete ?? false,
|
|
33
|
+
isInvalid: state?.invalid ?? false,
|
|
34
|
+
isVisited: state?.visited ?? false
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
function createViewNavigation(states, current, commands) {
|
|
38
|
+
const canGoNext = stepAfter(states, current) !== void 0;
|
|
39
|
+
const canGoPrevious = stepBefore(states, current) !== void 0;
|
|
40
|
+
return {
|
|
41
|
+
canGoNext,
|
|
42
|
+
canGoPrevious,
|
|
43
|
+
isFirstStep: !canGoPrevious,
|
|
44
|
+
isLastStep: !canGoNext,
|
|
45
|
+
canGoToStep: (stepId) => states.find(({ id }) => id === stepId)?.reachable ?? false,
|
|
46
|
+
goToStep: (stepId) => void commands.goTo(stepId),
|
|
47
|
+
goToNextStep: () => void commands.next(),
|
|
48
|
+
goToPreviousStep: () => void commands.back()
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function buildViewModel({
|
|
52
|
+
config,
|
|
53
|
+
kind,
|
|
54
|
+
states,
|
|
55
|
+
current,
|
|
56
|
+
navigation,
|
|
57
|
+
isSubmitting,
|
|
58
|
+
viewConfig
|
|
59
|
+
}) {
|
|
60
|
+
const steps = projectViewSteps(config.steps, states, current);
|
|
61
|
+
const activeStep = steps.find(({ isActive }) => isActive) ?? steps[0];
|
|
62
|
+
if (!activeStep) {
|
|
63
|
+
throw new Error(`Form '${config.id}' has no steps.`);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
kind,
|
|
67
|
+
form: {
|
|
68
|
+
id: config.id,
|
|
69
|
+
title: config.title,
|
|
70
|
+
description: config.description,
|
|
71
|
+
isSubmitting: isSubmitting ?? false
|
|
72
|
+
},
|
|
73
|
+
steps,
|
|
74
|
+
activeStep,
|
|
75
|
+
currentStepIndex: activeStep.index,
|
|
76
|
+
navigation,
|
|
77
|
+
viewConfig
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
getSlotConfig,
|
|
83
|
+
getViewRecipe,
|
|
84
|
+
projectViewSteps,
|
|
85
|
+
createViewNavigation,
|
|
86
|
+
buildViewModel
|
|
87
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/recipes/view-model.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod/mini';\nimport type { FormConfigView } from '@/lib/normalized-form-config';\nimport { stepAfter, stepBefore, type FormStepState } from '@/engine/step-machine';\nimport type { AnyRecipeRegistration } from '@/types/registration';\nimport { readSlotConfig, type RecipeViewModel } from '@schema-engine/layout';\nimport type { RecipeKind, RecipeSlot } from './types';\n\n/**\n * The commands a stepper or an actions block calls, and whether each is available.\n *\n * @remarks `goToStep` takes a step id, which stays right when steps are skipped; indexes do not.\n */\nexport interface ViewNavigation {\n\tcanGoNext: boolean;\n\tcanGoPrevious: boolean;\n\tisFirstStep: boolean;\n\tisLastStep: boolean;\n\t/** Whether `goToStep(stepId)` can move there, as the runtime's step state says. */\n\tcanGoToStep: (stepId: string) => boolean;\n\tgoToStep: (stepId: string) => void;\n\tgoToNextStep: () => void;\n\tgoToPreviousStep: () => void;\n}\n\n/**\n * One step that is not skipped, as a recipe block reads it.\n *\n * @remarks `index` is the position among the steps that are not skipped and `total` how many there are, so progress reads \"step 2 of 3\" however many are skipped.\n */\nexport interface ViewStep {\n\tid: string;\n\ttitle?: string;\n\tdescription?: string;\n\tindex: number;\n\ttotal: number;\n\tisActive: boolean;\n\tisCompleted: boolean;\n\tisInvalid: boolean;\n\tisVisited: boolean;\n}\n\nexport interface ViewModel extends RecipeViewModel<RecipeKind> {\n\tform: {\n\t\tid: string;\n\t\ttitle?: string;\n\t\tdescription?: string;\n\t\tisSubmitting: boolean;\n\t};\n\t/** The steps that are not skipped, in order: what progress and a stepper count. */\n\tsteps: ViewStep[];\n\tactiveStep: ViewStep;\n\t/** The position of the current step among `steps`. */\n\tcurrentStepIndex: number;\n\tnavigation: ViewNavigation;\n}\n\n/**\n * Reads one slot's complete config from a normalized view; see the layout `readSlotConfig`, which this\n * types by the forms slot names.\n */\nexport function getSlotConfig<TSchema extends z.ZodMiniType>(\n\tviewConfig: Record<string, unknown>,\n\tslot: RecipeSlot,\n\tschema: TSchema,\n): z.output<TSchema> {\n\treturn readSlotConfig(viewConfig, slot, schema);\n}\n\n/**\n * Resolves the recipe a normalized form's `view` selects, or `undefined` when the form has no view.\n *\n * @remarks\n * Throws when `view.$type` is not registered on the engine, so a config normalized elsewhere fails\n * loudly instead of rendering without chrome.\n */\nexport function getViewRecipe(\n\tengine: { getRecipe(id: string): AnyRecipeRegistration | undefined },\n\tconfig: { id: string; view?: { $type: string } },\n): AnyRecipeRegistration | undefined {\n\tif (!config.view) return undefined;\n\tconst recipe = engine.getRecipe(config.view.$type);\n\tif (!recipe) {\n\t\tthrow new Error(`Form '${config.id}' uses view '${config.view.$type}' but the engine has no such recipe.`);\n\t}\n\treturn recipe;\n}\n\n/** Projects the steps that are not skipped, with their live state, onto the {@link ViewStep} list. */\nexport function projectViewSteps(\n\tsteps: ReadonlyArray<{ id: string; title?: string; description?: string }>,\n\tstates: readonly FormStepState[],\n\tcurrent: string,\n): ViewStep[] {\n\tconst active = steps.flatMap((step) => {\n\t\tconst state = states.find(({ id }) => id === step.id);\n\t\treturn state?.skipped ? [] : [{ step, state }];\n\t});\n\treturn active.map(({ step, state }, index) => ({\n\t\tid: step.id,\n\t\ttitle: step.title,\n\t\tdescription: step.description,\n\t\tindex,\n\t\ttotal: active.length,\n\t\tisActive: step.id === current,\n\t\tisCompleted: state?.complete ?? false,\n\t\tisInvalid: state?.invalid ?? false,\n\t\tisVisited: state?.visited ?? false,\n\t}));\n}\n\n/** The navigation a recipe block reads, from the step states and the commands of a runtime. */\nexport function createViewNavigation(\n\tstates: readonly FormStepState[],\n\tcurrent: string,\n\tcommands: { next: () => unknown; back: () => unknown; goTo: (id: string) => unknown },\n): ViewNavigation {\n\tconst canGoNext = stepAfter(states, current) !== undefined;\n\tconst canGoPrevious = stepBefore(states, current) !== undefined;\n\treturn {\n\t\tcanGoNext,\n\t\tcanGoPrevious,\n\t\tisFirstStep: !canGoPrevious,\n\t\tisLastStep: !canGoNext,\n\t\tcanGoToStep: (stepId) => states.find(({ id }) => id === stepId)?.reachable ?? false,\n\t\tgoToStep: (stepId) => void commands.goTo(stepId),\n\t\tgoToNextStep: () => void commands.next(),\n\t\tgoToPreviousStep: () => void commands.back(),\n\t};\n}\n\nexport function buildViewModel({\n\tconfig,\n\tkind,\n\tstates,\n\tcurrent,\n\tnavigation,\n\tisSubmitting,\n\tviewConfig,\n}: {\n\tconfig: FormConfigView;\n\tkind: RecipeKind;\n\tstates: readonly FormStepState[];\n\tcurrent: string;\n\tnavigation: ViewNavigation;\n\tisSubmitting?: boolean;\n\tviewConfig: Record<string, unknown>;\n}): ViewModel {\n\tconst steps = projectViewSteps(config.steps, states, current);\n\tconst activeStep = steps.find(({ isActive }) => isActive) ?? steps[0];\n\tif (!activeStep) {\n\t\tthrow new Error(`Form '${config.id}' has no steps.`);\n\t}\n\n\treturn {\n\t\tkind,\n\t\tform: {\n\t\t\tid: config.id,\n\t\t\ttitle: config.title,\n\t\t\tdescription: config.description,\n\t\t\tisSubmitting: isSubmitting ?? false,\n\t\t},\n\t\tsteps,\n\t\tactiveStep,\n\t\tcurrentStepIndex: activeStep.index,\n\t\tnavigation,\n\t\tviewConfig,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;AAAA,OAAmB;AAInB,SAAS,sBAA4C;AAwD9C,SAAS,cACf,YACA,MACA,QACoB;AACpB,SAAO,eAAe,YAAY,MAAM,MAAM;AAC/C;AASO,SAAS,cACf,QACA,QACoC;AACpC,MAAI,CAAC,OAAO,KAAM,QAAO;AACzB,QAAM,SAAS,OAAO,UAAU,OAAO,KAAK,KAAK;AACjD,MAAI,CAAC,QAAQ;AACZ,UAAM,IAAI,MAAM,SAAS,OAAO,EAAE,gBAAgB,OAAO,KAAK,KAAK,sCAAsC;AAAA,EAC1G;AACA,SAAO;AACR;AAGO,SAAS,iBACf,OACA,QACA,SACa;AACb,QAAM,SAAS,MAAM,QAAQ,CAAC,SAAS;AACtC,UAAM,QAAQ,OAAO,KAAK,CAAC,EAAE,GAAG,MAAM,OAAO,KAAK,EAAE;AACpD,WAAO,OAAO,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,MAAM,CAAC;AAAA,EAC9C,CAAC;AACD,SAAO,OAAO,IAAI,CAAC,EAAE,MAAM,MAAM,GAAG,WAAW;AAAA,IAC9C,IAAI,KAAK;AAAA,IACT,OAAO,KAAK;AAAA,IACZ,aAAa,KAAK;AAAA,IAClB;AAAA,IACA,OAAO,OAAO;AAAA,IACd,UAAU,KAAK,OAAO;AAAA,IACtB,aAAa,OAAO,YAAY;AAAA,IAChC,WAAW,OAAO,WAAW;AAAA,IAC7B,WAAW,OAAO,WAAW;AAAA,EAC9B,EAAE;AACH;AAGO,SAAS,qBACf,QACA,SACA,UACiB;AACjB,QAAM,YAAY,UAAU,QAAQ,OAAO,MAAM;AACjD,QAAM,gBAAgB,WAAW,QAAQ,OAAO,MAAM;AACtD,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,aAAa,CAAC;AAAA,IACd,YAAY,CAAC;AAAA,IACb,aAAa,CAAC,WAAW,OAAO,KAAK,CAAC,EAAE,GAAG,MAAM,OAAO,MAAM,GAAG,aAAa;AAAA,IAC9E,UAAU,CAAC,WAAW,KAAK,SAAS,KAAK,MAAM;AAAA,IAC/C,cAAc,MAAM,KAAK,SAAS,KAAK;AAAA,IACvC,kBAAkB,MAAM,KAAK,SAAS,KAAK;AAAA,EAC5C;AACD;AAEO,SAAS,eAAe;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAQc;AACb,QAAM,QAAQ,iBAAiB,OAAO,OAAO,QAAQ,OAAO;AAC5D,QAAM,aAAa,MAAM,KAAK,CAAC,EAAE,SAAS,MAAM,QAAQ,KAAK,MAAM,CAAC;AACpE,MAAI,CAAC,YAAY;AAChB,UAAM,IAAI,MAAM,SAAS,OAAO,EAAE,iBAAiB;AAAA,EACpD;AAEA,SAAO;AAAA,IACN;AAAA,IACA,MAAM;AAAA,MACL,IAAI,OAAO;AAAA,MACX,OAAO,OAAO;AAAA,MACd,aAAa,OAAO;AAAA,MACpB,cAAc,gBAAgB;AAAA,IAC/B;AAAA,IACA;AAAA,IACA;AAAA,IACA,kBAAkB,WAAW;AAAA,IAC7B;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// src/recipes/slot-schemas.ts
|
|
2
|
+
import * as z from "zod/mini";
|
|
3
|
+
import { AppearanceConfigSchema } from "@schema-engine/layout";
|
|
4
|
+
var SlotAppearance = z.optional(AppearanceConfigSchema);
|
|
5
|
+
var CardShellConfigSchema = z.strictObject({
|
|
6
|
+
appearance: SlotAppearance
|
|
7
|
+
});
|
|
8
|
+
var HeroShellConfigSchema = z.strictObject({
|
|
9
|
+
appearance: SlotAppearance,
|
|
10
|
+
backgroundImage: z.optional(z.string()),
|
|
11
|
+
backgroundVideo: z.optional(z.string()),
|
|
12
|
+
contentWidth: z._default(z.enum(["sm", "md", "lg", "xl"]), "md")
|
|
13
|
+
});
|
|
14
|
+
var SplitScreenShellConfigSchema = z.strictObject({
|
|
15
|
+
appearance: SlotAppearance,
|
|
16
|
+
sideContent: z.optional(z.string()),
|
|
17
|
+
sidePlacement: z._default(z.enum(["left", "right"]), "left"),
|
|
18
|
+
sideWidth: z._default(z.enum(["narrow", "normal", "wide"]), "normal"),
|
|
19
|
+
contentAlignment: z._default(z.enum(["top", "center", "bottom"]), "center")
|
|
20
|
+
});
|
|
21
|
+
var SidebarShellConfigSchema = z.strictObject({
|
|
22
|
+
appearance: SlotAppearance,
|
|
23
|
+
showSeparator: z._default(z.boolean(), true)
|
|
24
|
+
});
|
|
25
|
+
var StepHeaderConfigSchema = z.strictObject({
|
|
26
|
+
showDescription: z._default(z.boolean(), true),
|
|
27
|
+
showStepCounter: z._default(z.boolean(), false),
|
|
28
|
+
labels: z.prefault(
|
|
29
|
+
z.strictObject({
|
|
30
|
+
stepCounter: z._default(
|
|
31
|
+
z.string().check(z.describe("Template with {current} and {total}")),
|
|
32
|
+
"Step {current} of {total}"
|
|
33
|
+
)
|
|
34
|
+
}),
|
|
35
|
+
{}
|
|
36
|
+
),
|
|
37
|
+
size: z._default(z.enum(["sm", "md", "lg"]), "md"),
|
|
38
|
+
align: z._default(z.enum(["start", "center"]), "start"),
|
|
39
|
+
fallbackToFormTitle: z._default(z.boolean(), true),
|
|
40
|
+
titleAs: z._default(z.enum(["h1", "h2"]), "h2"),
|
|
41
|
+
inheritColor: z._default(z.boolean(), false),
|
|
42
|
+
counterPlacement: z._default(z.enum(["before", "after"]), "after")
|
|
43
|
+
});
|
|
44
|
+
var MinimalProgressConfigSchema = z.strictObject({
|
|
45
|
+
showPercentage: z._default(z.boolean(), true),
|
|
46
|
+
labels: z.prefault(
|
|
47
|
+
z.strictObject({
|
|
48
|
+
progress: z._default(z.string(), "Progress"),
|
|
49
|
+
valueText: z._default(
|
|
50
|
+
z.string().check(z.describe("Template with {current} and {total}, read as the bar value")),
|
|
51
|
+
"Step {current} of {total}"
|
|
52
|
+
)
|
|
53
|
+
}),
|
|
54
|
+
{}
|
|
55
|
+
)
|
|
56
|
+
});
|
|
57
|
+
var StepIndicatorsConfigSchema = z.strictObject({
|
|
58
|
+
orientation: z._default(z.enum(["horizontal", "sidebar"]), "horizontal"),
|
|
59
|
+
showStepNumbers: z._default(z.boolean(), true),
|
|
60
|
+
showStepTitles: z._default(z.boolean(), true),
|
|
61
|
+
showStepDescriptions: z._default(z.boolean(), false),
|
|
62
|
+
labels: z.prefault(
|
|
63
|
+
z.strictObject({
|
|
64
|
+
regionAriaLabel: z._default(z.string(), "Form progress"),
|
|
65
|
+
completed: z._default(
|
|
66
|
+
z.string().check(z.describe("Template with {current} and {total}, the status of a finished step")),
|
|
67
|
+
"Step {current}, completed"
|
|
68
|
+
),
|
|
69
|
+
untitledStep: z._default(
|
|
70
|
+
z.string().check(z.describe("Template with {current} and {total}")),
|
|
71
|
+
"Step {current}"
|
|
72
|
+
)
|
|
73
|
+
}),
|
|
74
|
+
{}
|
|
75
|
+
)
|
|
76
|
+
});
|
|
77
|
+
var WizardActionsConfigSchema = z.strictObject({
|
|
78
|
+
labels: z.prefault(
|
|
79
|
+
z.strictObject({
|
|
80
|
+
previous: z._default(z.string(), "Previous"),
|
|
81
|
+
previousAriaLabel: z._default(z.string(), "Go to previous step"),
|
|
82
|
+
next: z._default(z.string(), "Next"),
|
|
83
|
+
nextAriaLabel: z._default(z.string(), "Go to next step"),
|
|
84
|
+
submit: z._default(z.string(), "Submit"),
|
|
85
|
+
submitAriaLabel: z._default(z.string(), "Submit form"),
|
|
86
|
+
submitting: z._default(z.string(), "Submitting..."),
|
|
87
|
+
stepCounter: z._default(
|
|
88
|
+
z.string().check(z.describe("Template with {current} and {total}")),
|
|
89
|
+
"Step {current} of {total}"
|
|
90
|
+
)
|
|
91
|
+
}),
|
|
92
|
+
{}
|
|
93
|
+
),
|
|
94
|
+
showStepCounter: z._default(z.boolean(), true),
|
|
95
|
+
variant: z._default(z.enum(["default", "minimal"]), "default")
|
|
96
|
+
});
|
|
97
|
+
var FormActionsConfigSchema = z.strictObject({
|
|
98
|
+
labels: z.prefault(
|
|
99
|
+
z.strictObject({
|
|
100
|
+
submit: z._default(z.string(), "Submit"),
|
|
101
|
+
submitAriaLabel: z._default(z.string(), "Submit form"),
|
|
102
|
+
submitting: z._default(z.string(), "Submitting...")
|
|
103
|
+
}),
|
|
104
|
+
{}
|
|
105
|
+
),
|
|
106
|
+
align: z._default(z.enum(["start", "center", "end"]), "end")
|
|
107
|
+
});
|
|
108
|
+
function formatStepLabel(template, current, total) {
|
|
109
|
+
return template.replaceAll("{current}", String(current)).replaceAll("{total}", String(total));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export {
|
|
113
|
+
CardShellConfigSchema,
|
|
114
|
+
HeroShellConfigSchema,
|
|
115
|
+
SplitScreenShellConfigSchema,
|
|
116
|
+
SidebarShellConfigSchema,
|
|
117
|
+
StepHeaderConfigSchema,
|
|
118
|
+
MinimalProgressConfigSchema,
|
|
119
|
+
StepIndicatorsConfigSchema,
|
|
120
|
+
WizardActionsConfigSchema,
|
|
121
|
+
FormActionsConfigSchema,
|
|
122
|
+
formatStepLabel
|
|
123
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/recipes/slot-schemas.ts"],
|
|
4
|
+
"sourcesContent": ["import * as z from 'zod/mini';\nimport { AppearanceConfigSchema } from '@schema-engine/layout';\n\n/**\n * Appearance pick for a slot that declares axes in its spec's `appearanceAxes`.\n *\n * @remarks The slot's width, padding and shadow are `size` and `surface` values, not slot config. The hero, split\n * screen and sidebar shells declare `size` alone: it sets their padding and gaps through `--se-space`.\n */\nconst SlotAppearance = z.optional(AppearanceConfigSchema);\n\nexport const CardShellConfigSchema = z.strictObject({\n\tappearance: SlotAppearance,\n});\n\nexport const HeroShellConfigSchema = z.strictObject({\n\tappearance: SlotAppearance,\n\tbackgroundImage: z.optional(z.string()),\n\tbackgroundVideo: z.optional(z.string()),\n\tcontentWidth: z._default(z.enum(['sm', 'md', 'lg', 'xl']), 'md'),\n});\n\nexport const SplitScreenShellConfigSchema = z.strictObject({\n\tappearance: SlotAppearance,\n\tsideContent: z.optional(z.string()),\n\tsidePlacement: z._default(z.enum(['left', 'right']), 'left'),\n\tsideWidth: z._default(z.enum(['narrow', 'normal', 'wide']), 'normal'),\n\tcontentAlignment: z._default(z.enum(['top', 'center', 'bottom']), 'center'),\n});\n\nexport const SidebarShellConfigSchema = z.strictObject({\n\tappearance: SlotAppearance,\n\tshowSeparator: z._default(z.boolean(), true),\n});\n\nexport const StepHeaderConfigSchema = z.strictObject({\n\tshowDescription: z._default(z.boolean(), true),\n\tshowStepCounter: z._default(z.boolean(), false),\n\tlabels: z.prefault(\n\t\tz.strictObject({\n\t\t\tstepCounter: z._default(\n\t\t\t\tz.string().check(z.describe('Template with {current} and {total}')),\n\t\t\t\t'Step {current} of {total}',\n\t\t\t),\n\t\t}),\n\t\t{},\n\t),\n\tsize: z._default(z.enum(['sm', 'md', 'lg']), 'md'),\n\talign: z._default(z.enum(['start', 'center']), 'start'),\n\tfallbackToFormTitle: z._default(z.boolean(), true),\n\ttitleAs: z._default(z.enum(['h1', 'h2']), 'h2'),\n\tinheritColor: z._default(z.boolean(), false),\n\tcounterPlacement: z._default(z.enum(['before', 'after']), 'after'),\n});\n\nexport const MinimalProgressConfigSchema = z.strictObject({\n\tshowPercentage: z._default(z.boolean(), true),\n\tlabels: z.prefault(\n\t\tz.strictObject({\n\t\t\tprogress: z._default(z.string(), 'Progress'),\n\t\t\tvalueText: z._default(\n\t\t\t\tz.string().check(z.describe('Template with {current} and {total}, read as the bar value')),\n\t\t\t\t'Step {current} of {total}',\n\t\t\t),\n\t\t}),\n\t\t{},\n\t),\n});\n\nexport const StepIndicatorsConfigSchema = z.strictObject({\n\torientation: z._default(z.enum(['horizontal', 'sidebar']), 'horizontal'),\n\tshowStepNumbers: z._default(z.boolean(), true),\n\tshowStepTitles: z._default(z.boolean(), true),\n\tshowStepDescriptions: z._default(z.boolean(), false),\n\tlabels: z.prefault(\n\t\tz.strictObject({\n\t\t\tregionAriaLabel: z._default(z.string(), 'Form progress'),\n\t\t\tcompleted: z._default(\n\t\t\t\tz.string().check(z.describe('Template with {current} and {total}, the status of a finished step')),\n\t\t\t\t'Step {current}, completed',\n\t\t\t),\n\t\t\tuntitledStep: z._default(\n\t\t\t\tz.string().check(z.describe('Template with {current} and {total}')),\n\t\t\t\t'Step {current}',\n\t\t\t),\n\t\t}),\n\t\t{},\n\t),\n});\n\nexport const WizardActionsConfigSchema = z.strictObject({\n\tlabels: z.prefault(\n\t\tz.strictObject({\n\t\t\tprevious: z._default(z.string(), 'Previous'),\n\t\t\tpreviousAriaLabel: z._default(z.string(), 'Go to previous step'),\n\t\t\tnext: z._default(z.string(), 'Next'),\n\t\t\tnextAriaLabel: z._default(z.string(), 'Go to next step'),\n\t\t\tsubmit: z._default(z.string(), 'Submit'),\n\t\t\tsubmitAriaLabel: z._default(z.string(), 'Submit form'),\n\t\t\tsubmitting: z._default(z.string(), 'Submitting...'),\n\t\t\tstepCounter: z._default(\n\t\t\t\tz.string().check(z.describe('Template with {current} and {total}')),\n\t\t\t\t'Step {current} of {total}',\n\t\t\t),\n\t\t}),\n\t\t{},\n\t),\n\tshowStepCounter: z._default(z.boolean(), true),\n\tvariant: z._default(z.enum(['default', 'minimal']), 'default'),\n});\n\nexport const FormActionsConfigSchema = z.strictObject({\n\tlabels: z.prefault(\n\t\tz.strictObject({\n\t\t\tsubmit: z._default(z.string(), 'Submit'),\n\t\t\tsubmitAriaLabel: z._default(z.string(), 'Submit form'),\n\t\t\tsubmitting: z._default(z.string(), 'Submitting...'),\n\t\t}),\n\t\t{},\n\t),\n\talign: z._default(z.enum(['start', 'center', 'end']), 'end'),\n});\n\nexport type CardShellConfig = z.infer<typeof CardShellConfigSchema>;\nexport type HeroShellConfig = z.infer<typeof HeroShellConfigSchema>;\nexport type SplitScreenShellConfig = z.infer<typeof SplitScreenShellConfigSchema>;\nexport type SidebarShellConfig = z.infer<typeof SidebarShellConfigSchema>;\nexport type StepHeaderConfig = z.infer<typeof StepHeaderConfigSchema>;\nexport type MinimalProgressConfig = z.infer<typeof MinimalProgressConfigSchema>;\nexport type StepIndicatorsConfig = z.infer<typeof StepIndicatorsConfigSchema>;\nexport type WizardActionsConfig = z.infer<typeof WizardActionsConfigSchema>;\nexport type FormActionsConfig = z.infer<typeof FormActionsConfigSchema>;\n\n/**\n * @remarks\n * Fills every `{current}` and `{total}` in a label template; other text is left as is.\n * Also formats the progress value text, the untitled step title and the completed status.\n */\nexport function formatStepLabel(template: string, current: number, total: number): string {\n\treturn template.replaceAll('{current}', String(current)).replaceAll('{total}', String(total));\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,YAAY,OAAO;AACnB,SAAS,8BAA8B;AAQvC,IAAM,iBAAmB,WAAS,sBAAsB;AAEjD,IAAM,wBAA0B,eAAa;AAAA,EACnD,YAAY;AACb,CAAC;AAEM,IAAM,wBAA0B,eAAa;AAAA,EACnD,YAAY;AAAA,EACZ,iBAAmB,WAAW,SAAO,CAAC;AAAA,EACtC,iBAAmB,WAAW,SAAO,CAAC;AAAA,EACtC,cAAgB,WAAW,OAAK,CAAC,MAAM,MAAM,MAAM,IAAI,CAAC,GAAG,IAAI;AAChE,CAAC;AAEM,IAAM,+BAAiC,eAAa;AAAA,EAC1D,YAAY;AAAA,EACZ,aAAe,WAAW,SAAO,CAAC;AAAA,EAClC,eAAiB,WAAW,OAAK,CA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BAA4B,eAAa;AAAA,EACrD,QAAU;AAAA,IACP,eAAa;AAAA,MACd,QAAU,WAAW,SAAO,GAAG,QAAQ;AAAA,MACvC,iBAAmB,WAAW,SAAO,GAAG,aAAa;AAAA,MACrD,YAAc,WAAW,SAAO,GAAG,eAAe;AAAA,IACnD,CAAC;AAAA,IACD,CAAC;AAAA,EACF;AAAA,EACA,OAAS,WAAW,OAAK,CAAC,SAAS,UAAU,KAAK,CAAC,GAAG,KAAK;AAC5D,CAAC;AAiBM,SAAS,gBAAgB,UAAkB,SAAiB,OAAuB;AACzF,SAAO,SAAS,WAAW,aAAa,OAAO,OAAO,CAAC,EAAE,WAAW,WAAW,OAAO,KAAK,CAAC;AAC7F;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asyncValidationCache
|
|
3
|
+
} from "./chunk-MD23VADH.js";
|
|
4
|
+
import {
|
|
5
|
+
REPORTED_TEXT,
|
|
6
|
+
ValidationSuperseded,
|
|
7
|
+
ValidationUnavailable
|
|
8
|
+
} from "./chunk-6BAJHAGL.js";
|
|
9
|
+
import {
|
|
10
|
+
isEmpty
|
|
11
|
+
} from "./chunk-6NV2JDGI.js";
|
|
12
|
+
|
|
13
|
+
// src/schemas/validation/async/handler.ts
|
|
14
|
+
import * as z from "zod/mini";
|
|
15
|
+
var CACHE_TTL = {
|
|
16
|
+
DEFAULT: 5 * 60 * 1e3
|
|
17
|
+
};
|
|
18
|
+
function resolveDependencies(dependencies, context) {
|
|
19
|
+
if (!dependencies?.length) {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
return Object.fromEntries(
|
|
23
|
+
dependencies.map((dep) => [dep, context.resolve(dep)]).filter(([, value]) => value !== void 0)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function createValidationPayload(value, dependsOn, extraPayload) {
|
|
27
|
+
const payload = {
|
|
28
|
+
value
|
|
29
|
+
};
|
|
30
|
+
if (Object.keys(dependsOn).length > 0) {
|
|
31
|
+
payload.dependsOn = dependsOn;
|
|
32
|
+
}
|
|
33
|
+
if (extraPayload) {
|
|
34
|
+
Object.assign(payload, extraPayload);
|
|
35
|
+
}
|
|
36
|
+
return payload;
|
|
37
|
+
}
|
|
38
|
+
function sameData(a, b) {
|
|
39
|
+
if (Object.is(a, b)) return true;
|
|
40
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
41
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, i) => sameData(item, b[i]));
|
|
42
|
+
}
|
|
43
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
44
|
+
const left = a;
|
|
45
|
+
const right = b;
|
|
46
|
+
const keys = Object.keys(left);
|
|
47
|
+
return keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && sameData(left[key], right[key]));
|
|
48
|
+
}
|
|
49
|
+
function isValidationSuccessful(data, expectedResponse) {
|
|
50
|
+
if (expectedResponse) return sameData(data, expectedResponse);
|
|
51
|
+
if (typeof data === "boolean") return data;
|
|
52
|
+
if (typeof data === "object" && data !== null) {
|
|
53
|
+
const { valid, success } = data;
|
|
54
|
+
if (typeof valid === "boolean") return valid;
|
|
55
|
+
if (typeof success === "boolean") return success;
|
|
56
|
+
}
|
|
57
|
+
throw new ValidationUnavailable();
|
|
58
|
+
}
|
|
59
|
+
function getErrorMessage(data, fallbackMessage) {
|
|
60
|
+
if (typeof data === "object" && data !== null) {
|
|
61
|
+
const obj = data;
|
|
62
|
+
return obj.message || obj.error || fallbackMessage;
|
|
63
|
+
}
|
|
64
|
+
return fallbackMessage;
|
|
65
|
+
}
|
|
66
|
+
function handleValidationFailure(ctx, text) {
|
|
67
|
+
ctx.addIssue({
|
|
68
|
+
code: "custom",
|
|
69
|
+
...text === void 0 ? {} : { params: { [REPORTED_TEXT]: text } }
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function createAsyncValidationHandler(rule, context) {
|
|
73
|
+
return z.unknown().check(
|
|
74
|
+
z.superRefine(async (value, ctx) => {
|
|
75
|
+
if (isEmpty(value)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const dependsOn = resolveDependencies(rule.dependencies, context);
|
|
79
|
+
if (rule.dependencies?.length) {
|
|
80
|
+
const hasEmptyDependencies = rule.dependencies.some((dep) => {
|
|
81
|
+
const depValue = context.resolve(dep);
|
|
82
|
+
return isEmpty(depValue);
|
|
83
|
+
});
|
|
84
|
+
if (hasEmptyDependencies) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const payload = createValidationPayload(value, dependsOn, rule.extraPayload);
|
|
89
|
+
if (!rule.disableCache) {
|
|
90
|
+
const cachedResult = asyncValidationCache.get(rule.url, payload);
|
|
91
|
+
if (cachedResult !== null) {
|
|
92
|
+
if (!cachedResult.valid) {
|
|
93
|
+
handleValidationFailure(ctx, cachedResult.message);
|
|
94
|
+
}
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const stablePayload = { dependsOn, ...rule.extraPayload };
|
|
99
|
+
const debounceKey = `async-validation:${context.fieldPath}:${rule.url}:${JSON.stringify(stablePayload)}`;
|
|
100
|
+
const performValidation = async () => {
|
|
101
|
+
const method = rule.method ?? "POST";
|
|
102
|
+
const hasBody = method !== "GET";
|
|
103
|
+
let data;
|
|
104
|
+
try {
|
|
105
|
+
const response = await context.fetch(rule.url, {
|
|
106
|
+
method,
|
|
107
|
+
headers: {
|
|
108
|
+
...hasBody ? { "Content-Type": "application/json" } : {},
|
|
109
|
+
...rule.headers
|
|
110
|
+
},
|
|
111
|
+
...hasBody ? { body: JSON.stringify(payload) } : {}
|
|
112
|
+
});
|
|
113
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
114
|
+
data = await response.json();
|
|
115
|
+
} catch (cause) {
|
|
116
|
+
throw new ValidationUnavailable({ cause });
|
|
117
|
+
}
|
|
118
|
+
const isValid = isValidationSuccessful(data, rule.expectedResponse);
|
|
119
|
+
const cacheResult = {
|
|
120
|
+
valid: isValid,
|
|
121
|
+
message: isValid ? void 0 : getErrorMessage(data, rule.message)
|
|
122
|
+
};
|
|
123
|
+
if (!rule.disableCache) {
|
|
124
|
+
asyncValidationCache.set(rule.url, payload, cacheResult, rule.cacheTTL);
|
|
125
|
+
}
|
|
126
|
+
return cacheResult;
|
|
127
|
+
};
|
|
128
|
+
let result;
|
|
129
|
+
if (rule.debounce && rule.debounce > 0) {
|
|
130
|
+
const outcome = await context.debounceScope.debounce(
|
|
131
|
+
performValidation,
|
|
132
|
+
rule.debounce,
|
|
133
|
+
debounceKey,
|
|
134
|
+
JSON.stringify(value)
|
|
135
|
+
);
|
|
136
|
+
if (outcome.status !== "completed") throw new ValidationSuperseded();
|
|
137
|
+
result = outcome.value;
|
|
138
|
+
} else {
|
|
139
|
+
result = await performValidation();
|
|
140
|
+
}
|
|
141
|
+
if (!result.valid) {
|
|
142
|
+
handleValidationFailure(ctx, result.message);
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export {
|
|
149
|
+
CACHE_TTL,
|
|
150
|
+
createAsyncValidationHandler
|
|
151
|
+
};
|