@schema-engine/forms 0.5.2 → 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.
- package/README.md +4 -3
- package/dist/agent-tool/index.js +13 -6
- package/dist/agent-tool/index.js.map +2 -2
- package/dist/builder/types.utils.d.ts +1 -0
- package/dist/chunk-2MKT7OIS.js +40 -0
- package/dist/chunk-2MKT7OIS.js.map +7 -0
- package/dist/{chunk-HPPFSWIV.js → chunk-2U4WRMPB.js} +26 -22
- package/dist/chunk-2U4WRMPB.js.map +7 -0
- package/dist/{chunk-YUUDXRBW.js → chunk-3ABPK4QP.js} +62 -2
- package/dist/chunk-3ABPK4QP.js.map +7 -0
- package/dist/chunk-3BMTC224.js +21 -0
- package/dist/chunk-3BMTC224.js.map +7 -0
- package/dist/chunk-3GZKJSXI.js +49 -0
- package/dist/chunk-3GZKJSXI.js.map +7 -0
- package/dist/{chunk-NJXKMF67.js → chunk-4HSGF4WX.js} +33 -52
- package/dist/chunk-4HSGF4WX.js.map +7 -0
- package/dist/chunk-4SWCTY7K.js +8 -0
- package/dist/chunk-4SWCTY7K.js.map +7 -0
- package/dist/{chunk-KLATKWUA.js → chunk-4YANBG3M.js} +1 -1
- package/dist/chunk-53SXH32V.js +43 -0
- package/dist/chunk-53SXH32V.js.map +7 -0
- package/dist/{chunk-DP7SYLLI.js → chunk-6OJ46PR2.js} +15 -20
- package/dist/chunk-6OJ46PR2.js.map +7 -0
- package/dist/chunk-AAOFZ27F.js +39 -0
- package/dist/chunk-AAOFZ27F.js.map +7 -0
- package/dist/{chunk-NJTLBSTR.js → chunk-AROD3D4R.js} +1 -1
- package/dist/{chunk-Q5LEK7CI.js → chunk-AT2NHSY3.js} +1 -1
- package/dist/chunk-B2PMISHZ.js +43 -0
- package/dist/chunk-B2PMISHZ.js.map +7 -0
- package/dist/chunk-BHCSZ4VO.js +27 -0
- package/dist/chunk-BHCSZ4VO.js.map +7 -0
- package/dist/chunk-BXGE5IXF.js +38 -0
- package/dist/chunk-BXGE5IXF.js.map +7 -0
- package/dist/chunk-CW7UMF3K.js +48 -0
- package/dist/chunk-CW7UMF3K.js.map +7 -0
- package/dist/{chunk-BLFLCSG3.js → chunk-DEWI6E3O.js} +2 -2
- package/dist/chunk-DSPTVDHL.js +45 -0
- package/dist/chunk-DSPTVDHL.js.map +7 -0
- package/dist/chunk-DU26WGQA.js +27 -0
- package/dist/chunk-DU26WGQA.js.map +7 -0
- package/dist/{chunk-GH34XFCC.js → chunk-EO5CW7XD.js} +2 -2
- package/dist/{chunk-A5VLMQAK.js → chunk-ERSCXYVE.js} +2 -2
- package/dist/chunk-EWNYEO6T.js.map +7 -0
- package/dist/{chunk-CRVXBWSY.js → chunk-FGL773EA.js} +1 -1
- package/dist/chunk-FVW5Z2CC.js +36 -0
- package/dist/chunk-FVW5Z2CC.js.map +7 -0
- package/dist/chunk-GDUF2SWI.js +32 -0
- package/dist/chunk-GDUF2SWI.js.map +7 -0
- package/dist/{chunk-GQHMU3AR.js → chunk-HEWLTCU4.js} +4 -4
- package/dist/{chunk-6R2MBQPL.js → chunk-HKLDRUFN.js} +4 -1
- package/dist/{chunk-6R2MBQPL.js.map → chunk-HKLDRUFN.js.map} +2 -2
- package/dist/{chunk-J2FC5K4B.js → chunk-IHXXPIFD.js} +1 -2
- package/dist/chunk-IHXXPIFD.js.map +7 -0
- package/dist/{chunk-GRZU6F7Q.js → chunk-KANWAQNI.js} +33 -38
- package/dist/chunk-KANWAQNI.js.map +7 -0
- package/dist/chunk-KWQJFQII.js +52 -0
- package/dist/chunk-KWQJFQII.js.map +7 -0
- package/dist/{chunk-PH3LWLYN.js → chunk-MFZYG6DN.js} +3 -2
- package/dist/chunk-MFZYG6DN.js.map +7 -0
- package/dist/{chunk-WUTGZYP4.js → chunk-MG7VFU6V.js} +2 -2
- package/dist/chunk-OG3OLZ5R.js +184 -0
- package/dist/chunk-OG3OLZ5R.js.map +7 -0
- package/dist/{chunk-WLDCYUN6.js → chunk-OKJLJ3GI.js} +1 -1
- package/dist/chunk-QDU55RCZ.js.map +7 -0
- package/dist/chunk-QFQB5EBY.js +38 -0
- package/dist/chunk-QFQB5EBY.js.map +7 -0
- package/dist/{chunk-6IZYNHZ3.js → chunk-RDQFBY6S.js} +45 -31
- package/dist/chunk-RDQFBY6S.js.map +7 -0
- package/dist/chunk-RMX7C43O.js.map +7 -0
- package/dist/chunk-T5JAAPFB.js +40 -0
- package/dist/chunk-T5JAAPFB.js.map +7 -0
- package/dist/chunk-TDXFT6Q5.js +57 -0
- package/dist/chunk-TDXFT6Q5.js.map +7 -0
- package/dist/{chunk-JA5ET6MC.js → chunk-TWQU2IGF.js} +6 -6
- package/dist/chunk-V3GYAG33.js +12 -0
- package/dist/chunk-V3GYAG33.js.map +7 -0
- package/dist/{chunk-V5H7L5PJ.js → chunk-WHLID5BN.js} +59 -23
- package/dist/{chunk-V5H7L5PJ.js.map → chunk-WHLID5BN.js.map} +2 -2
- package/dist/chunk-XKINCUXT.js +51 -0
- package/dist/chunk-XKINCUXT.js.map +7 -0
- package/dist/chunk-XLEOTW6H.js +50 -0
- package/dist/chunk-XLEOTW6H.js.map +7 -0
- package/dist/chunk-YHSOS3IH.js +53 -0
- package/dist/chunk-YHSOS3IH.js.map +7 -0
- package/dist/chunk-YKXOBPSU.js +19 -0
- package/dist/chunk-YKXOBPSU.js.map +7 -0
- package/dist/{chunk-ZYP3MIH3.js → chunk-YW2KZUAM.js} +5 -3
- package/dist/chunk-YW2KZUAM.js.map +7 -0
- package/dist/{chunk-E4VONSLO.js.map → chunk-YZFL6JPZ.js.map} +2 -2
- package/dist/{chunk-6EYX257T.js → chunk-Z5KZDT7V.js} +1 -1
- package/dist/chunk-ZZ4KB6GE.js +47 -0
- package/dist/chunk-ZZ4KB6GE.js.map +7 -0
- package/dist/default-elements/array-elements.d.ts +793 -0
- package/dist/default-elements/array-elements.js +34 -0
- package/dist/default-elements/array-elements.js.map +7 -0
- package/dist/default-elements/checkbox-group.d.ts +812 -0
- package/dist/default-elements/checkbox-group.js +40 -0
- package/dist/default-elements/checkbox-group.js.map +7 -0
- package/dist/default-elements/checkbox.d.ts +788 -0
- package/dist/default-elements/checkbox.js +38 -0
- package/dist/default-elements/checkbox.js.map +7 -0
- package/dist/default-elements/combobox.d.ts +806 -0
- package/dist/default-elements/combobox.js +40 -0
- package/dist/default-elements/combobox.js.map +7 -0
- package/dist/default-elements/define-contract.d.ts +25 -0
- package/dist/default-elements/define-contract.js +8 -0
- package/dist/default-elements/define-contract.js.map +7 -0
- package/dist/default-elements/drop-zone.d.ts +789 -0
- package/dist/default-elements/drop-zone.js +40 -0
- package/dist/default-elements/drop-zone.js.map +7 -0
- package/dist/default-elements/fieldset.d.ts +783 -0
- package/dist/default-elements/fieldset.js +34 -0
- package/dist/default-elements/fieldset.js.map +7 -0
- package/dist/default-elements/index.d.ts +75 -0
- package/dist/default-elements/index.js +240 -0
- package/dist/default-elements/index.js.map +7 -0
- package/dist/default-elements/input-otp.d.ts +1298 -0
- package/dist/default-elements/input-otp.js +38 -0
- package/dist/default-elements/input-otp.js.map +7 -0
- package/dist/default-elements/input.d.ts +843 -0
- package/dist/default-elements/input.js +40 -0
- package/dist/default-elements/input.js.map +7 -0
- package/dist/default-elements/masked-input.d.ts +835 -0
- package/dist/default-elements/masked-input.js +40 -0
- package/dist/default-elements/masked-input.js.map +7 -0
- package/dist/default-elements/number.d.ts +821 -0
- package/dist/default-elements/number.js +38 -0
- package/dist/default-elements/number.js.map +7 -0
- package/dist/default-elements/phone-input.d.ts +785 -0
- package/dist/default-elements/phone-input.js +40 -0
- package/dist/default-elements/phone-input.js.map +7 -0
- package/dist/default-elements/radio.d.ts +812 -0
- package/dist/default-elements/radio.js +40 -0
- package/dist/default-elements/radio.js.map +7 -0
- package/dist/default-elements/select.d.ts +809 -0
- package/dist/default-elements/select.js +40 -0
- package/dist/default-elements/select.js.map +7 -0
- package/dist/default-elements/slider.d.ts +800 -0
- package/dist/default-elements/slider.js +38 -0
- package/dist/default-elements/slider.js.map +7 -0
- package/dist/default-elements/submission-alert.d.ts +804 -0
- package/dist/default-elements/submission-alert.js +36 -0
- package/dist/default-elements/submission-alert.js.map +7 -0
- package/dist/default-elements/submit-button.d.ts +771 -0
- package/dist/default-elements/submit-button.js +34 -0
- package/dist/default-elements/submit-button.js.map +7 -0
- package/dist/default-elements/switch.d.ts +794 -0
- package/dist/default-elements/switch.js +38 -0
- package/dist/default-elements/switch.js.map +7 -0
- package/dist/default-elements/textarea.d.ts +815 -0
- package/dist/default-elements/textarea.js +40 -0
- package/dist/default-elements/textarea.js.map +7 -0
- package/dist/engine/build-form-engine.js +22 -18
- package/dist/engine/create-form-engine.js +23 -19
- package/dist/engine/form-engine.js +22 -18
- package/dist/engine/index.js +25 -21
- package/dist/engine/schema-artifacts.js +6 -2
- package/dist/engine/step-machine.d.ts +10 -0
- package/dist/engine/step-machine.js +5 -5
- package/dist/engine/submission-schema.js +8 -6
- package/dist/engine/value-validation.js +4 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.js +40 -31
- package/dist/index.js.map +3 -3
- package/dist/lib/export-schema.d.ts +128 -0
- package/dist/lib/export-schema.js +15 -0
- package/dist/lib/export-schema.js.map +7 -0
- package/dist/lib/exported-recipe-view.d.ts +17 -0
- package/dist/lib/exported-recipe-view.js +10 -0
- package/dist/lib/exported-recipe-view.js.map +7 -0
- package/dist/lib/field-scope.js +2 -2
- package/dist/lib/grid-track-items.d.ts +26 -0
- package/dist/lib/grid-track-items.js +10 -0
- package/dist/lib/grid-track-items.js.map +7 -0
- package/dist/lib/is-zod-type.d.ts +5 -0
- package/dist/lib/is-zod-type.js +6 -0
- package/dist/lib/is-zod-type.js.map +7 -0
- package/dist/lib/submission-shape.js +3 -3
- package/dist/lib/validate-form/grid-checks.d.ts +24 -0
- package/dist/lib/validate-form/grid-checks.js +6 -1
- package/dist/lib/validate-form/parse-elements.d.ts +9 -7
- package/dist/lib/validate-form/parse-elements.js +5 -6
- package/dist/lib/validate-form/parse-owner-actions.js +1 -1
- package/dist/lib/validate-form/parse-view.js +1 -1
- package/dist/lib/validate-form/step-checks.js +3 -3
- package/dist/lib/validate-form/validation-error.d.ts +1 -10
- package/dist/lib/validate-form/validation-error.js +3 -5
- package/dist/lib/validate-form.d.ts +1 -1
- package/dist/lib/validate-form.js +14 -15
- package/dist/lib/zod-json-schema.d.ts +0 -4
- package/dist/lib/zod-json-schema.js +7 -5
- package/dist/recipes/built-in-specs.js +2 -2
- package/dist/recipes/built-in.js +2 -2
- package/dist/recipes/define-form-recipe.d.ts +2 -2
- package/dist/recipes/define-form-recipe.js +1 -1
- package/dist/recipes/define-recipe-spec.d.ts +3 -2
- package/dist/recipes/define-recipe-spec.js +1 -1
- package/dist/recipes/index.js +8 -8
- package/dist/recipes/types.d.ts +2 -2
- package/dist/recipes/view-model.d.ts +2 -2
- package/dist/recipes/view-model.js +6 -6
- package/dist/runtime/create-form-runtime.js +14 -13
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +14 -13
- package/dist/runtime/types.d.ts +11 -0
- package/dist/runtime/types.js +1 -1
- package/dist/schemas/base-field.d.ts +14 -6
- package/dist/schemas/base-field.js +5 -5
- package/dist/schemas/form-config-shape.d.ts +33 -21
- package/dist/schemas/form-config-shape.js +5 -5
- package/dist/schemas/form-config.d.ts +55 -35
- package/dist/schemas/form-config.js +5 -5
- package/dist/schemas/index.js +5 -5
- package/dist/schemas/validation/dependencies.js +4 -4
- package/dist/schemas/validation/index.js +5 -5
- package/dist/schemas/validation/utils.js +3 -3
- package/dist/schemas/validation/validation-registry.d.ts +1 -1
- package/dist/schemas/validation/validation-registry.js +4 -4
- package/dist/state-container/create-form-state-container.js +8 -8
- package/dist/state-container/index.js +9 -9
- package/dist/state-container/selectors.js +5 -5
- package/dist/state-container/submission.js +6 -6
- package/dist/testing/form-state-container-conformance.js +7 -7
- package/dist/testing/index.js +7 -7
- package/dist/types/define-element.d.ts +2 -2
- package/dist/types/define-element.js +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/registration.d.ts +7 -0
- package/package.json +8 -4
- package/skill/SKILL.md +12 -11
- package/skill/reference/forms.md +4 -4
- package/dist/chunk-25PLQDKN.js +0 -45
- package/dist/chunk-25PLQDKN.js.map +0 -7
- package/dist/chunk-2XWISGGM.js.map +0 -7
- package/dist/chunk-6IZYNHZ3.js.map +0 -7
- package/dist/chunk-DP7SYLLI.js.map +0 -7
- package/dist/chunk-GRZU6F7Q.js.map +0 -7
- package/dist/chunk-HPPFSWIV.js.map +0 -7
- package/dist/chunk-J2FC5K4B.js.map +0 -7
- package/dist/chunk-K22S7IZR.js.map +0 -7
- package/dist/chunk-NJXKMF67.js.map +0 -7
- package/dist/chunk-PH3LWLYN.js.map +0 -7
- package/dist/chunk-PHNMDWSK.js.map +0 -7
- package/dist/chunk-PN5EH6DM.js +0 -36
- package/dist/chunk-PN5EH6DM.js.map +0 -7
- package/dist/chunk-YUUDXRBW.js.map +0 -7
- package/dist/chunk-ZYP3MIH3.js.map +0 -7
- package/dist/{chunk-KLATKWUA.js.map → chunk-4YANBG3M.js.map} +0 -0
- package/dist/{chunk-S7I76ISM.js → chunk-7QLR5WM3.js} +3 -3
- /package/dist/{chunk-S7I76ISM.js.map → chunk-7QLR5WM3.js.map} +0 -0
- /package/dist/{chunk-NJTLBSTR.js.map → chunk-AROD3D4R.js.map} +0 -0
- /package/dist/{chunk-Q5LEK7CI.js.map → chunk-AT2NHSY3.js.map} +0 -0
- /package/dist/{chunk-BLFLCSG3.js.map → chunk-DEWI6E3O.js.map} +0 -0
- /package/dist/{chunk-GH34XFCC.js.map → chunk-EO5CW7XD.js.map} +0 -0
- /package/dist/{chunk-A5VLMQAK.js.map → chunk-ERSCXYVE.js.map} +0 -0
- /package/dist/{chunk-K22S7IZR.js → chunk-EWNYEO6T.js} +0 -0
- /package/dist/{chunk-CRVXBWSY.js.map → chunk-FGL773EA.js.map} +0 -0
- /package/dist/{chunk-GQHMU3AR.js.map → chunk-HEWLTCU4.js.map} +0 -0
- /package/dist/{chunk-WUTGZYP4.js.map → chunk-MG7VFU6V.js.map} +0 -0
- /package/dist/{chunk-WLDCYUN6.js.map → chunk-OKJLJ3GI.js.map} +0 -0
- /package/dist/{chunk-2XWISGGM.js → chunk-QDU55RCZ.js} +0 -0
- /package/dist/{chunk-PHNMDWSK.js → chunk-RMX7C43O.js} +0 -0
- /package/dist/{chunk-JA5ET6MC.js.map → chunk-TWQU2IGF.js.map} +0 -0
- /package/dist/{chunk-E4VONSLO.js → chunk-YZFL6JPZ.js} +0 -0
- /package/dist/{chunk-6EYX257T.js.map → chunk-Z5KZDT7V.js.map} +0 -0
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/lib/validate-form.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FormConfig, FormConfigEnvelope, FormTaggedConfig } from '@/schemas/form-config';\nimport { formConfigEnvelopeSchema } from '@/schemas/form-config';\nimport { safeParseStandardSchema } from '@schema-engine/registry';\nimport {\n\tmarkNormalizedFormConfig,\n\tgetNormalizedFormOwner,\n\ttype NormalizedElementConfig,\n\ttype NormalizedFormConfig,\n} from '@/lib/normalized-form-config';\nimport { stepGrid } from '@/lib/form-view';\nimport { walkNamedElements } from '@/lib/field-scope';\nimport { ENGINE_KEY_PREFIX, isReservedPathKey } from '@/lib/reserved-path-keys';\nimport { getDefaultLayoutTheme } from '@schema-engine/layout';\nimport { resolveAppearance, withAppearance, type AppearanceScope } from '@/lib/resolve-appearance';\nimport { fieldPlacementIssues, templateIssues, type PlacedElement } from './validate-form/grid-checks';\nimport {\n\tchildPath,\n\tissueAt,\n\ttype FormValidationIssue,\n\ttype FormValidationResult,\n\ttype ParseResult,\n\ttype Path,\n} from './validate-form/issues';\nimport type { ValidateFormOptions } from './validate-form/options';\nimport { brandElementTree, parseElementList, parseElementNode } from './validate-form/parse-elements';\nimport { parseOwnerActions } from './validate-form/parse-owner-actions';\nimport { parseView } from './validate-form/parse-view';\nimport { stepStructureIssues } from './validate-form/step-checks';\nimport { fromSchemaIssues } from './validate-form/schema-issues';\nimport { FormValidationError } from './validate-form/validation-error';\n\nexport type { FormConfigView, NormalizedElementConfig, NormalizedFormConfig } from '@/lib/normalized-form-config';\nexport { DEFAULT_WIZARD_RECIPE, assertFormEngine, getRenderableSteps, stepGrid } from '@/lib/form-view';\nexport type { FormValidationIssue, FormValidationResult } from './validate-form/issues';\nexport type { ValidateFormOptions } from './validate-form/options';\nexport { FormValidationError, formatIssuePath } from './validate-form/validation-error';\n\n/**\n * Validate a single element against its registration schema, including nested child elements.\n * Use this before rendering a field that is not already part of a {@link NormalizedFormConfig}.\n * The normalized marker is applied only after this element and its children succeed.\n *\n * @throws {FormValidationError} Issue paths are relative to the element, for example `['grid', 'width']`\n * or `['elements', 0, 'rules', 1, '$type']`.\n */\nexport function validateElementConfig(\n\tconfig: unknown,\n\toptions: Pick<ValidateFormOptions, 'getElement' | 'checkRule' | 'axes'>,\n): NormalizedElementConfig {\n\tconst parsed = parseElementNode(config, options.getElement, options.checkRule, [], {\n\t\taxes: options.axes ?? getDefaultLayoutTheme().axes,\n\t\tinherited: {},\n\t});\n\tif (parsed.issues.length > 0 || !parsed.item) {\n\t\tthrow new FormValidationError(\n\t\t\tparsed.issues.length > 0\n\t\t\t\t? parsed.issues\n\t\t\t\t: [issueAt(['$type'], 'Invalid element configuration: missing $type.')],\n\t\t\tconfig,\n\t\t);\n\t}\n\treturn brandElementTree(parsed.item, options.getElement);\n}\n\n/**\n * Strict validation for a form configuration against the engine's registered recipes and schema.\n * Returns a frozen {@link NormalizedFormConfig}: schema defaults and transforms are kept, the input object is not mutated.\n *\n * @throws {FormValidationError} With the issues found. {@link safeValidateFormConfig} returns them instead.\n */\nexport function validateFormConfig(config: unknown, options: ValidateFormOptions): NormalizedFormConfig {\n\tconst result = safeValidateFormConfig(config, options);\n\tif (!result.success) throw new FormValidationError(result.issues, config);\n\treturn result.data;\n}\n\n/**\n * Same validation as {@link validateFormConfig}, reported as a result: the normalized form, or the\n * issues found, each with the config path it is about.\n *\n * @remarks\n * A malformed envelope (the form's own shape) stops the deeper checks, so it comes back on its own;\n * once the envelope parses, the issues of every element, action, grid and view are reported together.\n * Still throws for a misuse of the API, such as a registration whose Standard Schema is async.\n */\nexport function safeValidateFormConfig(\n\tconfig: unknown,\n\toptions: ValidateFormOptions,\n): FormValidationResult<NormalizedFormConfig> {\n\tconst existingOwner = getNormalizedFormOwner(config);\n\tif (existingOwner) {\n\t\tif (existingOwner === options.owner) {\n\t\t\treturn {\n\t\t\t\tsuccess: true,\n\t\t\t\tdata: markNormalizedFormConfig(config as FormConfig, options.owner, options.values),\n\t\t\t};\n\t\t}\n\t\tconst formId = typeof config === 'object' && config !== null && 'id' in config ? String(config.id) : 'unknown';\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\tissues: [\n\t\t\t\tissueAt(\n\t\t\t\t\t[],\n\t\t\t\t\t`Form '${formId}' was already normalized by a different engine. Pass the original authoring input or JSON to this engine instead.`,\n\t\t\t\t),\n\t\t\t],\n\t\t};\n\t}\n\n\tconst parsedEnvelope = parseEnvelope(config);\n\tif (!parsedEnvelope.ok) return { success: false, issues: parsedEnvelope.issues };\n\tconst envelope = parsedEnvelope.data;\n\n\tconst issues: FormValidationIssue[] = [];\n\tconst axes = options.axes ?? getDefaultLayoutTheme().axes;\n\tconst formScope: AppearanceScope = { axes, inherited: {} };\n\tconst formAppearance = resolveAppearance(envelope.appearance, formScope, { subject: 'The form', path: [] });\n\tissues.push(...formAppearance.issues);\n\n\tconst placed: PlacedElement[][] = [];\n\tconst steps = envelope.steps.map((step, stepIndex) => {\n\t\tconst stepPath: Path = ['steps', stepIndex];\n\t\tconst stepAppearance = resolveAppearance(step.appearance, formAppearance.childScope, {\n\t\t\tsubject: 'The step',\n\t\t\tpath: stepPath,\n\t\t});\n\t\tissues.push(...stepAppearance.issues);\n\t\tconst elements = parseElementList(\n\t\t\tstep.elements,\n\t\t\toptions.getElement,\n\t\t\toptions.checkRule,\n\t\t\tstepPath,\n\t\t\tstepAppearance.childScope,\n\t\t);\n\t\tconst actions = parseOwnerActions(step.actions, options, stepPath);\n\t\tissues.push(...elements.issues, ...actions.issues);\n\t\tplaced.push(\n\t\t\telements.byIndex.flatMap((element, index) =>\n\t\t\t\telement ? [{ element, path: childPath(stepPath, index) }] : [],\n\t\t\t),\n\t\t);\n\t\treturn {\n\t\t\t...withAppearance(step, stepAppearance.selection),\n\t\t\telements: elements.items ?? step.elements,\n\t\t\tactions: actions.items ?? step.actions,\n\t\t};\n\t});\n\n\tissues.push(...stepStructureIssues(steps, options.getElement));\n\tissues.push(\n\t\t...payloadIssues(\n\t\t\tenvelope.payload,\n\t\t\tsteps.flatMap((step) => step.elements),\n\t\t),\n\t);\n\n\tconst formShape = templateIssues('Form grid', envelope.grid, ['grid']);\n\tissues.push(...formShape);\n\tsteps.forEach((step, index) => {\n\t\tconst own = step.grid !== undefined;\n\t\tconst label = own ? 'Step grid' : 'Form grid';\n\t\tconst gridPath: Path = own ? ['steps', index, 'grid'] : ['grid'];\n\t\tconst shape = own ? templateIssues(label, step.grid, gridPath) : formShape;\n\t\tif (own) issues.push(...shape);\n\t\tconst scope = { gridPath, elements: placed[index] ?? [] };\n\t\tissues.push(...fieldPlacementIssues(label, stepGrid(envelope, step), scope, shape.length === 0, !own));\n\t});\n\n\tconst view = parseView(\n\t\tenvelope.view && typeof envelope.view.$type === 'string' ? envelope.view : undefined,\n\t\t{ id: envelope.id, stepCount: envelope.steps.length },\n\t\toptions,\n\t\tformAppearance.childScope,\n\t);\n\tconst formActions = parseOwnerActions(envelope.actions, options, []);\n\tissues.push(...view.issues, ...formActions.issues);\n\n\tif (issues.length > 0) {\n\t\treturn { success: false, issues };\n\t}\n\n\treturn {\n\t\tsuccess: true,\n\t\tdata: markNormalizedFormConfig(\n\t\t\t{\n\t\t\t\t...withAppearance(envelope, formAppearance.selection),\n\t\t\t\tsteps: steps.map((step) => ({\n\t\t\t\t\t...step,\n\t\t\t\t\telements: step.elements.map((element) =>\n\t\t\t\t\t\tbrandElementTree(element as FormTaggedConfig, options.getElement),\n\t\t\t\t\t),\n\t\t\t\t})),\n\t\t\t\tview: view.view ?? envelope.view,\n\t\t\t\tactions: formActions.items ?? envelope.actions,\n\t\t\t} as unknown as FormConfig,\n\t\t\toptions.owner,\n\t\t\toptions.values,\n\t\t),\n\t};\n}\n\n/**\n * The payload keys that cannot travel: a reserved segment, or the name of a field.\n *\n * @remarks\n * The payload is data that travels with a submission and is never a value of the form, so a key that is\n * also a field would make one name mean two things in `submission.values`.\n */\nfunction payloadIssues(\n\tpayload: Readonly<Record<string, unknown>> | undefined,\n\telements: readonly object[],\n): FormValidationIssue[] {\n\tif (!payload) return [];\n\tconst fieldNames = new Set(walkNamedElements(elements).map(({ path }) => path.split('.')[0]));\n\treturn Object.keys(payload).flatMap((key) => {\n\t\tif (isReservedPathKey(key)) {\n\t\t\treturn [\n\t\t\t\tissueAt(\n\t\t\t\t\t['payload', key],\n\t\t\t\t\t`Payload key '${key}' is reserved: a key cannot start with '${ENGINE_KEY_PREFIX}' or be one of __proto__, constructor and prototype.`,\n\t\t\t\t),\n\t\t\t];\n\t\t}\n\t\treturn fieldNames.has(key)\n\t\t\t? [\n\t\t\t\t\tissueAt(\n\t\t\t\t\t\t['payload', key],\n\t\t\t\t\t\t`Payload key '${key}' names a field of the form; a payload key cannot be a field.`,\n\t\t\t\t\t),\n\t\t\t\t]\n\t\t\t: [];\n\t});\n}\n\n/**\n * Parses the form's own shape (its id, steps, view and the like). Nothing deeper is checked when this\n * fails, so a malformed envelope is reported on its own.\n */\nfunction parseEnvelope(config: unknown): ParseResult<FormConfigEnvelope> {\n\tconst result = safeParseStandardSchema(formConfigEnvelopeSchema, config);\n\tif (!result.success) return { ok: false, issues: fromSchemaIssues(result.error.issues, []) };\n\treturn { ok: true, data: result.data as FormConfigEnvelope };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;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,UACjE;AAAA,QACD,EAAE;AAAA,QACF,MAAM,KAAK,QAAQ,SAAS;AAAA,QAC5B,SAAS,YAAY,SAAS,SAAS;AAAA,MACxC;AAAA,MACA,QAAQ;AAAA,MACR,QAAQ;AAAA,IACT;AAAA,EACD;AACD;AASA,SAAS,cACR,SACA,UACwB;AACxB,MAAI,CAAC,QAAS,QAAO,CAAC;AACtB,QAAM,aAAa,IAAI,IAAI,kBAAkB,QAAQ,EAAE,IAAI,CAAC,EAAE,KAAK,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;AAC5F,SAAO,OAAO,KAAK,OAAO,EAAE,QAAQ,CAAC,QAAQ;AAC5C,QAAI,kBAAkB,GAAG,GAAG;AAC3B,aAAO;AAAA,QACN;AAAA,UACC,CAAC,WAAW,GAAG;AAAA,UACf,gBAAgB,GAAG,2CAA2C,iBAAiB;AAAA,QAChF;AAAA,MACD;AAAA,IACD;AACA,WAAO,WAAW,IAAI,GAAG,IACtB;AAAA,MACA;AAAA,QACC,CAAC,WAAW,GAAG;AAAA,QACf,gBAAgB,GAAG;AAAA,MACpB;AAAA,IACD,IACC,CAAC;AAAA,EACL,CAAC;AACF;AAMA,SAAS,cAAc,QAAkD;AACxE,QAAM,SAAS,wBAAwB,0BAA0B,MAAM;AACvE,MAAI,CAAC,OAAO,QAAS,QAAO,EAAE,IAAI,OAAO,QAAQ,iBAAiB,OAAO,MAAM,QAAQ,CAAC,CAAC,EAAE;AAC3F,SAAO,EAAE,IAAI,MAAM,MAAM,OAAO,KAA2B;AAC5D;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/lib/validate-form/parse-view.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FormTaggedConfig } from '@/schemas/form-config';\nimport { DEFAULT_WIZARD_RECIPE } from '@/lib/form-view';\nimport { resolveRecipeView } from '@schema-engine/layout';\nimport { logger } from '@/lib/logger';\nimport type { AppearanceScope } from '@/lib/resolve-appearance';\nimport { issueAt, isTaggedConfig, type FormValidationIssue } from './issues';\nimport type { ValidateFormOptions } from './options';\nimport { fromSchemaIssues } from './schema-issues';\n\n/**\n * Form ids already warned about, per owner.\n *\n * @remarks\n * A renderer re-validates an inline raw config on every render, so the missing-recipe warning\n * would otherwise repeat for the same form.\n */\nconst warnedMissingWizardRecipe = new WeakMap<object, Set<string>>();\n\nexport function parseView(\n\tauthored: FormTaggedConfig | undefined,\n\tform: { id: string; stepCount: number },\n\toptions: Pick<ValidateFormOptions, 'getRecipe' | 'defaultWizardRecipe' | 'owner'>,\n\tappearance: AppearanceScope,\n): { issues: FormValidationIssue[]; view?: FormTaggedConfig } {\n\tconst { getRecipe } = options;\n\tconst stepCount = form.stepCount;\n\tlet view = authored;\n\tif (!view) {\n\t\tif (stepCount === 0) return { issues: [issueAt(['steps'], 'Form must have at least one step.')] };\n\t\tif (stepCount < 2) return { issues: [] };\n\t\tconst defaultRecipe = options.defaultWizardRecipe ?? DEFAULT_WIZARD_RECIPE;\n\t\tif (!getRecipe(defaultRecipe)) {\n\t\t\tconst warned = warnedMissingWizardRecipe.get(options.owner) ?? new Set<string>();\n\t\t\twarnedMissingWizardRecipe.set(options.owner, warned);\n\t\t\tif (warned.has(form.id)) return { issues: [] };\n\t\t\twarned.add(form.id);\n\t\t\tlogger.warn(\n\t\t\t\t`Form '${form.id}' has ${stepCount} steps but no '${defaultRecipe}' recipe is registered. The form renders every step on a single page without a view layout. Register a wizard recipe with createFormEngine({ recipes: [...] }) or set an explicit view.$type.`,\n\t\t\t);\n\t\t\treturn { issues: [] };\n\t\t}\n\t\tview = { $type: defaultRecipe };\n\t}\n\n\tconst recipeType = view.$type;\n\tif (!recipeType) {\n\t\treturn { issues: [issueAt(['view', '$type'], 'Must be a non-empty string.')] };\n\t}\n\n\tconst recipe = getRecipe(recipeType);\n\tif (!recipe) {\n\t\treturn {\n\t\t\tissues: [\n\t\t\t\tissueAt(\n\t\t\t\t\t['view', '$type'],\n\t\t\t\t\t`Unknown view recipe '${recipeType}'. Register it with createFormEngine({ recipes: [...] }).`,\n\t\t\t\t),\n\t\t\t],\n\t\t};\n\t}\n\n\tconst issues: FormValidationIssue[] = [];\n\tif (recipe.kind === 'single-step' && stepCount !== 1) {\n\t\tissues.push(\n\t\t\tissueAt(\n\t\t\t\t['view', '$type'],\n\t\t\t\t`Recipe '${recipeType}' is single-step only (kind: 'single-step') but the form has ${stepCount} steps.`,\n\t\t\t),\n\t\t);\n\t}\n\tif (recipe.kind === 'wizard' && stepCount < 2) {\n\t\tissues.push(\n\t\t\tissueAt(\n\t\t\t\t['view', '$type'],\n\t\t\t\t`Recipe '${recipeType}' requires at least 2 steps (kind: 'wizard') but the form has ${stepCount} step(s).`,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst resolved = resolveRecipeView(recipe, view, appearance);\n\tissues.push(...resolved.issues.map((issue) => issueAt(['view', ...issue.path], issue.message)));\n\tif (resolved.schemaIssues) {\n\t\tissues.push(...fromSchemaIssues(resolved.schemaIssues, ['view']));\n\t}\n\treturn { issues, view: isTaggedConfig(resolved.view) ? resolved.view : view };\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;AAEA,SAAS,yBAAyB;AAclC,IAAM,4BAA4B,oBAAI,QAA6B;AAE5D,SAAS,UACf,UACA,MACA,SACA,YAC6D;AAC7D,QAAM,EAAE,UAAU,IAAI;AACtB,QAAM,YAAY,KAAK;AACvB,MAAI,OAAO;AACX,MAAI,CAAC,MAAM;AACV,QAAI,cAAc,EAAG,QAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,OAAO,GAAG,mCAAmC,CAAC,EAAE;AAChG,QAAI,YAAY,EAAG,QAAO,EAAE,QAAQ,CAAC,EAAE;AACvC,UAAM,gBAAgB,QAAQ,uBAAuB;AACrD,QAAI,CAAC,UAAU,aAAa,GAAG;AAC9B,YAAM,SAAS,0BAA0B,IAAI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MAAI,SAAS,cAAc;AAC1B,WAAO,KAAK,GAAG,iBAAiB,SAAS,cAAc,CAAC,MAAM,CAAC,CAAC;AAAA,EACjE;AACA,SAAO,EAAE,QAAQ,MAAM,eAAe,SAAS,IAAI,IAAI,SAAS,OAAO,KAAK;AAC7E;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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,gBAA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AAC,aAAa,EAAE,GAAG,aAAa,MAAM,UAAU,OAAO,EAAE;AAAA,EAClE;AACA,SAAO;AAAA,IACN,aAAa,EAAE,GAAG,MAAM,KAAK,GAAG,WAAW;AAAA,IAC3C,SAAS,EAAE,aAAa,MAAM,IAAI,EAAE;AAAA,EACrC;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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;AACz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ACA;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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/types/define-element.ts"],
|
|
4
|
-
"sourcesContent": ["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { ElementMetadata } from './metadata';\nimport type { ContainerKind, InputRegistration, StaticRegistration, ValueDeclaration } from './registration';\nimport type { NormalizedElementConfig } from '@/lib/normalized-form-config';\nimport type { ValidationRegistrationConstraint } from '@/schemas/validation/types';\nimport type { AppearanceAxisList } from '@schema-engine/layout';\n\ntype InferOutput<TSchema> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : never;\n\n/**\n * Rewrite container `elements` to the normalized children the renderer receives.\n * Parent schemas only require `$type`; the engine supplies frozen, validated children.\n */\nexport type WithNormalizedChildren<T> = T extends { elements: unknown[] }\n\t? Omit<T, 'elements'> & { readonly elements: ReadonlyArray<NormalizedElementConfig> }\n\t: T;\n\nexport type ElementRenderProps<TSchema extends StandardSchemaV1, THandlers = unknown> = WithNormalizedChildren<\n\tInferOutput<TSchema>\n> & {\n\t/** Stable array-item identity overlaid at render time. Not part of authoring. */\n\tinstanceId?: string;\n} & THandlers;\n\ntype DefineElementRegistration<\n\tTType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps,\n\tTKind extends ContainerKind | undefined = ContainerKind | undefined,\n> = {\n\t$type: TType;\n\tschema: TSchema;\n\tmetadata: ElementMetadata;\n\tcontainerKind?: TKind;\n\tappearanceAxes?: AppearanceAxisList;\n\trender: (props: TProps) => unknown;\n};\n\n/**\n * What an input declares about its value, by one rule: `value` is required exactly when its schema output has no `elements`.\n *\n * @remarks\n * A schema that declares `elements` makes the element a container, whose value the engine composes from its children,\n * so it declares no `value` and may set `containerKind` (`'object'` when it does not). Any other input must declare\n * `value`, which is how a registration whose control writes a value the engine cannot check is a type error. A schema\n * that merely allows any key (an index signature) does not declare `elements`.\n */\ntype InputValueDeclaration<TSchema extends StandardSchemaV1, TValue extends StandardSchemaV1> =\n\tDeclaresChildren<InferOutput<TSchema>> extends true\n\t\t? { containerKind?: ContainerKind; value?: never }\n\t\t: { containerKind?: undefined; value: ValueDeclaration<WithNormalizedChildren<InferOutput<TSchema>>, TValue> };\n\n/** Whether a schema output declares `elements`: a key of its own, or an array typed beside an index signature. */\ntype DeclaresChildren<TOutput> = 'elements' extends keyof TOutput\n\t? string extends keyof TOutput\n\t\t? TOutput extends { elements?: readonly unknown[] }\n\t\t\t? true\n\t\t\t: false\n\t\t: true\n\t: false;\n\ntype DefineInputRegistration<\n\tTType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps,\n\tTValue extends StandardSchemaV1,\n\tTKind extends ContainerKind | undefined,\n> = DefineElementRegistration<TType, TSchema, TProps, TKind> & {\n\tvalidations?: readonly ValidationRegistrationConstraint[];\n} & InputValueDeclaration<TSchema, TValue>;\n\ntype DefineElementArg<TType extends string, TSchema extends StandardSchemaV1, TProps> =\n\tWithNormalizedChildren<InferOutput<TSchema>> extends TProps\n\t\t? DefineElementRegistration<TType, TSchema, TProps>\n\t\t: never;\n\ntype DefineInputArg<\n\tTType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps,\n\tTValue extends StandardSchemaV1,\n\tTKind extends ContainerKind | undefined,\n> =\n\tWithNormalizedChildren<InferOutput<TSchema>> extends TProps\n\t\t? DefineInputRegistration<TType, TSchema, TProps, TValue, TKind>\n\t\t: never;\n\n/**\n * Register an input element while preserving schema input/output inference.\n *\n * Form authors supply schema input (defaults stay optional). The render function\n * must accept schema output, with container `elements` already normalized.\n * `validations` are registered when the element is added to a form engine.\n *\n * `value` declares the value the control writes, as a function of the configured element\n * (see {@link ValueDeclaration}); it is required unless the schema has `elements`.\n *\n * It sets the registration's `kind` to `'input'`, which is what the engine reads to require `value`, not the metadata category.\n */\nexport function defineInput<\n\tconst TType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps = WithNormalizedChildren<InferOutput<TSchema>>,\n\tTValue extends StandardSchemaV1 = never,\n\tconst TKind extends ContainerKind | undefined = undefined,\n>(\n\tregistration: DefineInputArg<TType, TSchema, TProps, TValue, TKind>,\n): InputRegistration<TType, TSchema, TProps, TValue, TKind> {\n\treturn { ...registration, kind: 'input' } as unknown as InputRegistration<TType, TSchema, TProps, TValue, TKind>;\n}\n\n/**\n * Register a display-only element while preserving schema input/output inference.\n *\n * It sets the registration's `kind` to `'static'`, so the engine asks it for no `value`, whatever its metadata category.\n */\nexport function defineStatic<\n\tconst TType extends string,\n\tTSchema extends StandardSchemaV1,\n\tTProps = WithNormalizedChildren<InferOutput<TSchema>>,\n>(registration: DefineElementArg<TType, TSchema, TProps>): StaticRegistration<TType, TSchema, TProps> {\n\treturn { ...registration, kind: 'static' } as StaticRegistration<TType, TSchema, TProps>;\n}\n"],
|
|
5
|
-
"mappings": ";AAmGO,SAAS,YAOf,cAC2D;AAC3D,SAAO,EAAE,GAAG,cAAc,MAAM,QAAQ;AACzC;AAOO,SAAS,aAId,cAAoG;AACrG,SAAO,EAAE,GAAG,cAAc,MAAM,SAAS;AAC1C;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/lib/validate-form/parse-elements.ts"],
|
|
4
|
-
"sourcesContent": ["import type { StandardSchemaV1 } from '@standard-schema/spec';\nimport type { FormTaggedConfig } from '@/schemas/form-config';\nimport type { ElementConfig } from '@/schemas/field-config';\nimport { safeParseStandardSchema } from '@schema-engine/registry';\nimport { markNormalizedElementConfig, type NormalizedElementConfig } from '@/lib/normalized-form-config';\nimport { getElementChildren, withElementChildren } from '@/lib/element-children';\nimport { resolveAppearance, withAppearance, type AppearanceScope } from '@/lib/resolve-appearance';\nimport { areaPlacementIssue, namedPlacementIssue } from './grid-checks';\nimport { childPath, isTaggedConfig, issueAt, type FormValidationIssue, type ParseResult, type Path } from './issues';\nimport type { ValidateFormOptions } from './options';\nimport { fromSchemaIssues } from './schema-issues';\nimport { containerKindOf } from '@/lib/container-kind-of';\nimport { ENGINE_KEY_PREFIX, isReservedPathKey } from '@/lib/reserved-path-keys';\n\nfunction parseRegistration(schema: StandardSchemaV1, config: object, path: Path): ParseResult<unknown> {\n\tconst result = safeParseStandardSchema(schema, config);\n\tif (!result.success) {\n\t\treturn { ok: false, issues: fromSchemaIssues(result.error.issues, path) };\n\t}\n\treturn { ok: true, data: result.data };\n}\n\nexport function parseTypedConfig(\n\titem: FormTaggedConfig,\n\tgetRegistration: (id: string) => { schema: StandardSchemaV1 } | undefined,\n\tregisterHint: string,\n\tpath: Path,\n): ParseResult<FormTaggedConfig> {\n\tconst registration = getRegistration(item.$type);\n\tif (!registration) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tissues: [\n\t\t\t\tissueAt([...path, '$type'], `Unknown element type '${item.$type}'. Register it with ${registerHint}.`),\n\t\t\t],\n\t\t};\n\t}\n\n\tconst parsed = parseRegistration(registration.schema, item, path);\n\tif (!parsed.ok) return parsed;\n\tif (!isTaggedConfig(parsed.data)) {\n\t\treturn {\n\t\t\tok: false,\n\t\t\tissues: [\n\t\t\t\tissueAt(\n\t\t\t\t\t[...path, '$type'],\n\t\t\t\t\t`Invalid element configuration for '${item.$type}': parsed output is missing $type.`,\n\t\t\t\t),\n\t\t\t],\n\t\t};\n\t}\n\treturn { ok: true, data: parsed.data };\n}\n\n/**\n * Holds each rule of an element to its registration, and replaces it with the rule as the registration parses it.\n *\n * @remarks\n * The element's own schema accepts a rule of any `$type`, so this is where a rule is held to the\n * registry. Every rule is checked, so a form with two bad rules reports both. An issue keeps the path\n * the registry gave it, laid under the rule: a refused option is at its key, a type nothing registers or\n * a handler that throws is at the rule's `$type`.\n */\nfunction checkElementRules(\n\titem: FormTaggedConfig,\n\tcheckRule: ValidateFormOptions['checkRule'],\n\tpath: Path,\n): { issues: FormValidationIssue[]; item: FormTaggedConfig } {\n\tif (!Array.isArray(item.rules)) return { issues: [], item };\n\n\tconst issues: FormValidationIssue[] = [];\n\tconst rules: unknown[] = [];\n\tfor (const [index, rule] of item.rules.entries()) {\n\t\tif (typeof rule !== 'object' || rule === null || !('$type' in rule) || typeof rule.$type !== 'string') {\n\t\t\trules.push(rule);\n\t\t\tcontinue;\n\t\t}\n\t\tconst checked = checkRule(rule as { $type: string });\n\t\tif (checked.ok) {\n\t\t\trules.push(checked.rule);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const issue of checked.issues) {\n\t\t\tissues.push({ ...issue, path: [...path, 'rules', index, ...issue.path] });\n\t\t}\n\t}\n\treturn { issues, item: { ...item, rules } };\n}\n\n/** The first segment of an element's name that the engine reserves. */\nfunction reservedNameSegment(item: FormTaggedConfig): string | undefined {\n\treturn typeof item.name === 'string' ? item.name.split('.').find(isReservedPathKey) : undefined;\n}\n\nexport function parseElementNode(\n\titem: unknown,\n\tgetElement: ValidateFormOptions['getElement'],\n\tcheckRule: ValidateFormOptions['checkRule'],\n\tpath: Path,\n\tappearance: AppearanceScope,\n\tnested = false,\n): { issues: FormValidationIssue[]; item?: FormTaggedConfig } {\n\tconst fail = (message: string, relative: Path = []) => ({ issues: [issueAt([...path, ...relative], message)] });\n\n\tif (!isTaggedConfig(item)) {\n\t\treturn fail('Invalid element configuration: missing $type.', ['$type']);\n\t}\n\tconst reserved = reservedNameSegment(item);\n\tif (reserved) {\n\t\treturn fail(\n\t\t\t`Field name '${String(item.name)}' uses the reserved segment '${reserved}': a name cannot start with '${ENGINE_KEY_PREFIX}' or be one of __proto__, constructor and prototype.`,\n\t\t\t['name'],\n\t\t);\n\t}\n\tconst { appearance: authoredAppearance, ...authored } = item;\n\tconst parsed = parseTypedConfig(\n\t\tauthored as FormTaggedConfig,\n\t\tgetElement,\n\t\t'createFormEngine({ elements: [...] })',\n\t\tpath,\n\t);\n\tif (!parsed.ok) {\n\t\treturn { issues: parsed.issues };\n\t}\n\tconst checkedRules = checkElementRules(parsed.data, checkRule, path);\n\tif (checkedRules.issues.length > 0) return { issues: checkedRules.issues };\n\tconst config = checkedRules.item;\n\tconst parsedReserved = reservedNameSegment(config);\n\tif (parsedReserved) {\n\t\treturn fail(\n\t\t\t`Field name '${String(config.name)}' uses the reserved segment '${parsedReserved}': a name cannot start with '${ENGINE_KEY_PREFIX}' or be one of __proto__, constructor and prototype.`,\n\t\t\t['name'],\n\t\t);\n\t}\n\tconst placementIssue = namedPlacementIssue(config);\n\tif (placementIssue) return fail(placementIssue.message, placementIssue.path);\n\tconst areaIssue = areaPlacementIssue(config, nested);\n\tif (areaIssue) return fail(areaIssue.message, areaIssue.path);\n\n\tconst elementAppearance = resolveAppearance(authoredAppearance, appearance, {\n\t\tsubject: `Element '${item.$type}'`,\n\t\tpath,\n\t\tsupported: getElement(item.$type)?.appearanceAxes ?? [],\n\t});\n\tconst issues = elementAppearance.issues;\n\tconst resolved = withAppearance(config, elementAppearance.selection);\n\n\tconst children = getElementChildren(config);\n\tif (!children) {\n\t\treturn issues.length > 0 ? { issues } : { issues: [], item: resolved };\n\t}\n\n\tconst nextChildren: FormTaggedConfig[] = [];\n\tconst childScope = elementAppearance.childScope;\n\tfor (let index = 0; index < children.length; index += 1) {\n\t\tconst parsedChild = parseElementNode(\n\t\t\tchildren[index],\n\t\t\tgetElement,\n\t\t\tcheckRule,\n\t\t\tchildPath(path, index),\n\t\t\tchildScope,\n\t\t\ttrue,\n\t\t);\n\t\tissues.push(...parsedChild.issues);\n\t\tif (parsedChild.item) nextChildren.push(parsedChild.item);\n\t}\n\n\tif (issues.length > 0) {\n\t\treturn { issues };\n\t}\n\n\treturn { issues: [], item: withElementChildren(resolved, nextChildren) };\n}\n\n/**\n * Validates the elements of a step. `byIndex` keeps each element at the index it was authored at\n * (`undefined` where it failed), so later checks name the right path.\n */\nexport function parseElementList(\n\titems: unknown[] | undefined,\n\tgetElement: ValidateFormOptions['getElement'],\n\tcheckRule: ValidateFormOptions['checkRule'],\n\tparentPath: Path,\n\tappearance: AppearanceScope,\n): { issues: FormValidationIssue[]; items?: FormTaggedConfig[]; byIndex: Array<FormTaggedConfig | undefined> } {\n\tif (!items) return { issues: [], byIndex: [] };\n\n\tconst next: FormTaggedConfig[] = [];\n\tconst byIndex: Array<FormTaggedConfig | undefined> = [];\n\tconst issues: FormValidationIssue[] = [];\n\tfor (let index = 0; index < items.length; index += 1) {\n\t\tconst parsed = parseElementNode(items[index], getElement, checkRule, childPath(parentPath, index), appearance);\n\t\tissues.push(...parsed.issues);\n\t\tbyIndex.push(parsed.item);\n\t\tif (parsed.item) next.push(parsed.item);\n\t}\n\treturn { issues, items: next, byIndex };\n}\n\nexport function brandElementTree(\n\tconfig: FormTaggedConfig,\n\tgetElement: ValidateFormOptions['getElement'],\n): NormalizedElementConfig {\n\tconst children = getElementChildren(config);\n\tconst next = children\n\t\t? withElementChildren(\n\t\t\t\tconfig,\n\t\t\t\tchildren.map((child) => brandElementTree(child as FormTaggedConfig, getElement)),\n\t\t\t)\n\t\t: config;\n\treturn markNormalizedElementConfig(next as unknown as ElementConfig, containerKindOf(getElement(config.$type)));\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;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B;AAEA,SAAO,EAAE,QAAQ,CAAC,GAAG,MAAM,oBAAoB,UAAU,YAAY,EAAE;AACxE;AAMO,SAAS,iBACf,OACA,YACA,WACA,YACA,YAC8G;AAC9G,MAAI,CAAC,MAAO,QAAO,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC,EAAE;AAE7C,QAAM,OAA2B,CAAC;AAClC,QAAM,UAA+C,CAAC;AACtD,QAAM,SAAgC,CAAC;AACvC,WAAS,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;AACrD,UAAM,SAAS,iBAAiB,MAAM,KAAK,GAAG,YAAY,WAAW,UAAU,YAAY,KAAK,GAAG,UAAU;AAC7G,WAAO,KAAK,GAAG,OAAO,MAAM;AAC5B,YAAQ,KAAK,OAAO,IAAI;AACxB,QAAI,OAAO,KAAM,MAAK,KAAK,OAAO,IAAI;AAAA,EACvC;AACA,SAAO,EAAE,QAAQ,OAAO,MAAM,QAAQ;AACvC;AAEO,SAAS,iBACf,QACA,YAC0B;AAC1B,QAAM,WAAW,mBAAmB,MAAM;AAC1C,QAAM,OAAO,WACV;AAAA,IACA;AAAA,IACA,SAAS,IAAI,CAAC,UAAU,iBAAiB,OAA2B,UAAU,CAAC;AAAA,EAChF,IACC;AACH,SAAO,4BAA4B,MAAkC,gBAAgB,WAAW,OAAO,KAAK,CAAC,CAAC;AAC/G;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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 */\nexport interface FormStepState {\n\treadonly id: 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 }[],\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 }, 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\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": ";;;;;AAuCO,IAAM,gBAAgB,CAAC,WAAiC,EAAE,SAAS,OAAO,SAAS,CAAC,KAAK,GAAG,UAAU,CAAC,EAAE;AAEhH,IAAM,YAAY,CAAC,KAAwB,UAC1C,MAAM,MAAM,CAAC,OAAO,IAAI,SAAS,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC;AAG3F,SAAS,aAAa,UAAwB,IAAY,YAA+B,CAAC,GAAiB;AACjH,QAAM,UAAU,UAAU,SAAS,SAAS,CAAC,EAAE,CAAC;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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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/recipes/define-form-recipe.ts"],
|
|
4
|
-
"sourcesContent": ["import type { z } from 'zod/mini';\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 z.ZodMiniType,\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
|
-
}
|
package/dist/chunk-PN5EH6DM.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
// src/lib/validate-form/validation-error.ts
|
|
2
|
-
function childOf(node, key) {
|
|
3
|
-
return typeof node === "object" && node !== null ? Reflect.get(node, key) : void 0;
|
|
4
|
-
}
|
|
5
|
-
function formatIssuePath(path, source) {
|
|
6
|
-
let node = source;
|
|
7
|
-
let text = "";
|
|
8
|
-
for (const key of path) {
|
|
9
|
-
node = childOf(node, key);
|
|
10
|
-
if (typeof key === "number") {
|
|
11
|
-
const id = childOf(node, "id");
|
|
12
|
-
text += typeof id === "string" && id ? `[${key}] (${id})` : `[${key}]`;
|
|
13
|
-
} else {
|
|
14
|
-
text += text ? `.${String(key)}` : String(key);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return text;
|
|
18
|
-
}
|
|
19
|
-
var FormValidationError = class extends Error {
|
|
20
|
-
issues;
|
|
21
|
-
constructor(issues, source) {
|
|
22
|
-
super(
|
|
23
|
-
issues.length > 0 ? issues.map((issue) => {
|
|
24
|
-
const path = formatIssuePath(issue.path, source);
|
|
25
|
-
return path ? `${path}: ${issue.message}` : issue.message;
|
|
26
|
-
}).join("\n") : "Invalid form configuration"
|
|
27
|
-
);
|
|
28
|
-
this.name = "FormValidationError";
|
|
29
|
-
this.issues = issues;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
formatIssuePath,
|
|
35
|
-
FormValidationError
|
|
36
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/lib/validate-form/validation-error.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FormValidationIssue, Path } from './issues';\n\nfunction childOf(node: unknown, key: PropertyKey): unknown {\n\treturn typeof node === 'object' && node !== null ? Reflect.get(node, key) : undefined;\n}\n\n/**\n * A path as it reads in an error message: object keys joined by dots, array indexes in brackets,\n * for example `steps[0].elements[2].grid.width`. The empty path is the empty string.\n *\n * @param source The config the path points into. With it, an array item that has a string `id` is\n * followed by the id in parentheses, `steps[0] (main).elements[2] (email).grid.width`, so a log of a\n * config with many fields names the one it means.\n */\nexport function formatIssuePath(path: Path, source?: unknown): string {\n\tlet node = source;\n\tlet text = '';\n\tfor (const key of path) {\n\t\tnode = childOf(node, key);\n\t\tif (typeof key === 'number') {\n\t\t\tconst id = childOf(node, 'id');\n\t\t\ttext += typeof id === 'string' && id ? `[${key}] (${id})` : `[${key}]`;\n\t\t} else {\n\t\t\ttext += text ? `.${String(key)}` : String(key);\n\t\t}\n\t}\n\treturn text;\n}\n\n/**\n * Thrown by {@link validateFormConfig} when a form does not validate.\n *\n * @param issues Every problem the checks found, each with the config path it is about.\n * @param source The authored config the paths point into. It only decorates `message` with the ids\n * of the elements and actions a path passes; `issues` stay as they are.\n *\n * @remarks\n * `message` lists the issues one per line as `<path>: <message>`, so a log reads without parsing\n * `issues`. Use `safeValidateForm` on the engine to get the same issues as a result instead of an\n * exception.\n */\nexport class FormValidationError extends Error {\n\treadonly issues: readonly FormValidationIssue[];\n\n\tconstructor(issues: readonly FormValidationIssue[], source?: unknown) {\n\t\tsuper(\n\t\t\tissues.length > 0\n\t\t\t\t? issues\n\t\t\t\t\t\t.map((issue) => {\n\t\t\t\t\t\t\tconst path = formatIssuePath(issue.path, source);\n\t\t\t\t\t\t\treturn path ? `${path}: ${issue.message}` : issue.message;\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.join('\\n')\n\t\t\t\t: 'Invalid form configuration',\n\t\t);\n\t\tthis.name = 'FormValidationError';\n\t\tthis.issues = issues;\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";AAEA,SAAS,QAAQ,MAAe,KAA2B;AAC1D,SAAO,OAAO,SAAS,YAAY,SAAS,OAAO,QAAQ,IAAI,MAAM,GAAG,IAAI;AAC7E;AAUO,SAAS,gBAAgB,MAAY,QAA0B;AACrE,MAAI,OAAO;AACX,MAAI,OAAO;AACX,aAAW,OAAO,MAAM;AACvB,WAAO,QAAQ,MAAM,GAAG;AACxB,QAAI,OAAO,QAAQ,UAAU;AAC5B,YAAM,KAAK,QAAQ,MAAM,IAAI;AAC7B,cAAQ,OAAO,OAAO,YAAY,KAAK,IAAI,GAAG,MAAM,EAAE,MAAM,IAAI,GAAG;AAAA,IACpE,OAAO;AACN,cAAQ,OAAO,IAAI,OAAO,GAAG,CAAC,KAAK,OAAO,GAAG;AAAA,IAC9C;AAAA,EACD;AACA,SAAO;AACR;AAcO,IAAM,sBAAN,cAAkC,MAAM;AAAA,EACrC;AAAA,EAET,YAAY,QAAwC,QAAkB;AACrE;AAAA,MACC,OAAO,SAAS,IACb,OACC,IAAI,CAAC,UAAU;AACf,cAAM,OAAO,gBAAgB,MAAM,MAAM,MAAM;AAC/C,eAAO,OAAO,GAAG,IAAI,KAAK,MAAM,OAAO,KAAK,MAAM;AAAA,MACnD,CAAC,EACA,KAAK,IAAI,IACV;AAAA,IACJ;AACA,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EACf;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/lib/validate-form/grid-checks.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FormTaggedConfig } from '@/schemas/form-config';\nimport {\n\tareaNames,\n\tareaTemplateIssues,\n\tcascadeValues,\n\telementAreaSlots,\n\telementHiddenSlots,\n\telementGridKeys,\n\telementUsesGridWidths,\n\tGRID_TEMPLATE_KEYS,\n\tgridAreaTemplates,\n\tgridUsesAreas,\n\tnamedPlacementOverflow,\n\tWIDTH_TRACKS,\n\ttype CascadeSlot,\n\ttype GridLayoutConfig,\n} from '@schema-engine/layout';\nimport { issueAt, isRecord, type FormValidationIssue, type Path } from './issues';\n\n/**\n * Where a grid sets the first of `keys`, relative to the grid: `['columns']` or\n * `['responsive', 'md', 'columns']`. With `slot`, only that slot's entry is read.\n *\n * @remarks\n * A path always names a key the author wrote, never a viewport the cascade resolved to, so an editor\n * or a YAML file lands on real text.\n */\nfunction gridKeyPath(grid: unknown, keys: readonly string[], slot?: CascadeSlot): Path | undefined {\n\tif (!isRecord(grid)) return undefined;\n\tconst entries: Array<{ slot: string; prefix: Path; entry: unknown }> = [\n\t\t{ slot: 'default', prefix: [], entry: grid },\n\t];\n\tif (isRecord(grid.responsive)) {\n\t\tfor (const [name, entry] of Object.entries(grid.responsive)) {\n\t\t\tentries.push({ slot: name, prefix: ['responsive', name], entry });\n\t\t}\n\t}\n\tfor (const { slot: entrySlot, prefix, entry } of entries) {\n\t\tif ((slot !== undefined && entrySlot !== slot) || !isRecord(entry)) continue;\n\t\tconst key = keys.find((name) => entry[name] !== undefined);\n\t\tif (key !== undefined) return [...prefix, key];\n\t}\n\treturn undefined;\n}\n\n/** Where an element sets the first of `keys` in its `grid`, relative to the element; `['grid']` when none is set. */\nexport function elementGridKeyPath(item: FormTaggedConfig, keys: readonly string[], slot?: CascadeSlot): Path {\n\tconst path = gridKeyPath(item.grid, keys, slot);\n\treturn path ? ['grid', ...path] : ['grid'];\n}\n\n/** Where a grid's `areas` template for a slot sits, below the grid. An array is the `default` template itself. */\nfunction areasPath(grid: GridLayoutConfig | undefined, slot: CascadeSlot): Path {\n\treturn Array.isArray(grid?.areas) ? ['areas'] : ['areas', slot];\n}\n\nfunction elementLabel(item: Record<string, unknown>): string {\n\tif (typeof item.name === 'string') return `Field '${item.name}'`;\n\treturn typeof item.id === 'string' ? `Element '${item.id}'` : 'Element';\n}\n\n/** Placement keys that cannot sit beside a field's `area`, which is a placement of its own. */\nconst AREA_EXCLUSIVE_KEYS = ['width', 'offset', 'column', 'row'] as const;\n\nfunction quotedKeys(keys: readonly string[]): string {\n\treturn keys.map((key) => `'${key}'`).join(' and ');\n}\n\n/**\n * Why a field's named placement is invalid, or `undefined` when it is fine.\n *\n * @remarks\n * Applies at every depth: a container lays its children out in a grid of its\n * own, so a nested field's tracks add up the same way a top-level field's do.\n * The path is relative to the element and names the key that conflicts, or the one that overflows.\n */\nexport function namedPlacementIssue(item: FormTaggedConfig): FormValidationIssue | undefined {\n\tconst keys = elementGridKeys(item);\n\tconst named = ['width', 'offset'].filter((key) => keys.has(key));\n\tif (named.length === 0) return undefined;\n\tconst label = elementLabel(item);\n\tif (keys.has('column')) {\n\t\treturn issueAt(\n\t\t\telementGridKeyPath(item, ['column']),\n\t\t\t`${label} sets grid ${quotedKeys(named)} and 'column'; use named widths or a raw column, not both.`,\n\t\t);\n\t}\n\tconst overflow = namedPlacementOverflow(item);\n\tif (overflow) {\n\t\treturn issueAt(\n\t\t\telementGridKeyPath(item, ['width', 'offset'], overflow.slot),\n\t\t\t`${label} sets grid 'width' and 'offset' that span ${overflow.tracks} of ${WIDTH_TRACKS} tracks at ${overflow.slot === 'default' ? 'default' : `'${overflow.slot}'`}; together they must fit in ${WIDTH_TRACKS} tracks.`,\n\t\t);\n\t}\n\treturn undefined;\n}\n\n/** The slot as it reads in a message: nothing for the default width, else ` at 'md'`. */\nfunction atSlot(slot: string): string {\n\treturn slot === 'default' ? '' : ` at '${slot}'`;\n}\n\n/**\n * Why a field's `area` cannot sit beside its other placement, or inside a container.\n *\n * @remarks\n * An area is a placement of its own: it resolves to the field's column and row,\n * so a width, offset or raw line set next to it would fight it. A container lays\n * its children out in a grid that takes no `areas`, so a child has no template\n * to name. The path is relative to the element.\n */\nexport function areaPlacementIssue(item: FormTaggedConfig, nested: boolean): FormValidationIssue | undefined {\n\tconst keys = elementGridKeys(item);\n\tif (!keys.has('area')) return undefined;\n\tconst label = elementLabel(item);\n\tif (nested) {\n\t\treturn issueAt(\n\t\t\telementGridKeyPath(item, ['area']),\n\t\t\t`${label} sets grid 'area' inside a container; a container lays its children out without areas.`,\n\t\t);\n\t}\n\tconst others = AREA_EXCLUSIVE_KEYS.filter((key) => keys.has(key));\n\tif (others.length === 0) return undefined;\n\treturn issueAt(\n\t\telementGridKeyPath(item, others),\n\t\t`${label} sets grid ${quotedKeys(['area', ...others])}; use an area or a width, offset or raw line, not both.`,\n\t);\n}\n\n/** An element of a step that validated, with where it sits in the form. */\nexport interface PlacedElement {\n\telement: FormTaggedConfig;\n\tpath: Path;\n}\n\ninterface GridScope {\n\t/** Where the grid that lays the step out sits: the step's own, else the form's. */\n\tgridPath: Path;\n\telements: readonly PlacedElement[];\n}\n\n/** The grid keys that set its own tracks (`columns`, `minColumnWidth`), at any breakpoint. */\nfunction templateTrackKeys(grid: GridLayoutConfig | undefined): string[] {\n\tconst entries = [grid, ...Object.values(grid?.responsive ?? {})];\n\treturn GRID_TEMPLATE_KEYS.filter((key) => entries.some((entry) => entry?.[key] !== undefined));\n}\n\n/**\n * Why a grid's `areas` cannot be a template: it sets `columns` or\n * `minColumnWidth` beside them, a responsive record has no `default`, or a\n * template has rows of unequal length or a non-rectangular area.\n *\n * @param gridPath Where the grid sits in the form, prefixed to each issue.\n *\n * @remarks\n * Nothing here depends on the fields, so a grid shared by several steps is\n * checked once rather than once per step.\n */\nexport function templateIssues(\n\tlabel: string,\n\tgrid: GridLayoutConfig | undefined,\n\tgridPath: Path,\n): FormValidationIssue[] {\n\tif (!gridUsesAreas(grid)) return [];\n\tconst templates = gridAreaTemplates(grid);\n\tconst issues: FormValidationIssue[] = [];\n\tconst tracks = templateTrackKeys(grid);\n\tif (tracks.length > 0) {\n\t\tissues.push(\n\t\t\tissueAt(\n\t\t\t\t[...gridPath, 'areas'],\n\t\t\t\t`${label} sets ${quotedKeys(['areas', ...tracks])}; a grid uses areas, widths or columns.`,\n\t\t\t),\n\t\t);\n\t}\n\tif (templates.default === undefined) {\n\t\tissues.push(\n\t\t\tissueAt(\n\t\t\t\t[...gridPath, 'areas'],\n\t\t\t\t`${label} 'areas' per breakpoint must include 'default', the layout below the narrowest breakpoint.`,\n\t\t\t),\n\t\t);\n\t}\n\tfor (const { path, message } of areaTemplateIssues(grid)) {\n\t\tconst slot = String(path[1] ?? 'default');\n\t\tissues.push(issueAt([...gridPath, ...path], `${label} areas${atSlot(slot)}: ${message}`));\n\t}\n\treturn issues;\n}\n\n/**\n * Why a step's fields do not fit the grid that lays them out.\n *\n * @remarks\n * Fields are checked against the cascade the stylesheet applies: a field's area\n * at a breakpoint is the last one set at or below it, and so is the template.\n * That is what a viewport gets, and it catches a template that changes at `md`\n * under a field that kept its `default` area.\n */\nexport function fieldPlacementIssues(\n\tlabel: string,\n\tgrid: GridLayoutConfig | undefined,\n\tscope: GridScope,\n\ttemplatesValid: boolean,\n\tsharedBySteps: boolean,\n): FormValidationIssue[] {\n\tconst usesAreas = gridUsesAreas(grid);\n\tconst issues: FormValidationIssue[] = [];\n\n\tconst widths = scope.elements.find(({ element }) => elementUsesGridWidths(element));\n\tconst exclusive = usesAreas ? ['areas'] : templateTrackKeys(grid);\n\tif (widths && exclusive.length > 0) {\n\t\tconst tracksPath = gridKeyPath(grid, GRID_TEMPLATE_KEYS) ?? [];\n\t\tissues.push(\n\t\t\tissueAt(\n\t\t\t\t[...scope.gridPath, ...(usesAreas ? ['areas'] : tracksPath)],\n\t\t\t\t`${label} sets ${quotedKeys(exclusive)} but ${elementLabel(widths.element)} uses 'width' or 'offset'; a grid uses areas, widths or columns.`,\n\t\t\t),\n\t\t);\n\t}\n\n\tconst claimants = scope.elements.filter(({ element }) => Object.keys(elementAreaSlots(element)).length > 0);\n\tif (!usesAreas) {\n\t\tfor (const { element, path } of claimants) {\n\t\t\tissues.push(\n\t\t\t\tissueAt(\n\t\t\t\t\t[...path, ...elementGridKeyPath(element, ['area'])],\n\t\t\t\t\t`${elementLabel(element)} sets grid 'area' but the ${label.toLowerCase()} has no 'areas'.`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t} else if (templatesValid) {\n\t\tissues.push(...areaClaimIssues(label, grid, scope.gridPath, claimants, sharedBySteps));\n\t}\n\treturn issues;\n}\n\nfunction areaClaimIssues(\n\tlabel: string,\n\tgrid: GridLayoutConfig | undefined,\n\tgridPath: Path,\n\tclaimants: readonly PlacedElement[],\n\tsharedBySteps: boolean,\n): FormValidationIssue[] {\n\tconst issues: FormValidationIssue[] = [];\n\tconst templates = gridAreaTemplates(grid);\n\tconst templateBySlot = cascadeValues(templates);\n\tconst claims = claimants.map(({ element, path }) => ({\n\t\telement,\n\t\tpath,\n\t\tauthored: elementAreaSlots(element),\n\t\tbySlot: cascadeValues(elementAreaSlots(element)),\n\t\thiddenBySlot: cascadeValues(elementHiddenSlots(element)),\n\t}));\n\n\tfor (const { element, path, authored, bySlot, hiddenBySlot } of claims) {\n\t\tfor (const [index, { slot, value: area }] of bySlot.entries()) {\n\t\t\tconst rows = templateBySlot[index]?.value;\n\t\t\tif (area === undefined || rows === undefined || hiddenBySlot[index]?.value) continue;\n\t\t\tconst names = areaNames(rows);\n\t\t\tif (names.includes(area)) continue;\n\t\t\tissues.push(\n\t\t\t\tissueAt(\n\t\t\t\t\t[...path, ...elementGridKeyPath(element, ['area'], authoredSlot(authored, slot))],\n\t\t\t\t\t`${elementLabel(element)} claims area '${area}'${atSlot(slot)}, which is not in the grid areas (${names.join(', ')}).`,\n\t\t\t\t),\n\t\t\t);\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tconst hint = sharedBySteps ? '; a form template applies to every step without a grid of its own' : '';\n\tconst reported = new Set<string>();\n\tfor (const [index, { slot, value: rows }] of templateBySlot.entries()) {\n\t\tif (rows === undefined) continue;\n\t\tfor (const name of areaNames(rows)) {\n\t\t\tconst claimed = claims.some(({ bySlot }) => bySlot[index]?.value === name);\n\t\t\tif (claimed || reported.has(name)) continue;\n\t\t\treported.add(name);\n\t\t\tissues.push(\n\t\t\t\tissueAt(\n\t\t\t\t\t[...gridPath, ...areasPath(grid, authoredSlot(templates, slot))],\n\t\t\t\t\t`${label} area '${name}'${atSlot(slot)} is not claimed by any field${hint}.`,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\treturn issues;\n}\n\n/**\n * The slot whose authored entry a cascaded slot resolves to: itself when it sets one, else the last\n * narrower slot that did. A message says where a viewport lands; a path says what the author wrote.\n */\nfunction authoredSlot<T>(authored: Partial<Record<CascadeSlot, T>>, slot: CascadeSlot): CascadeSlot {\n\tlet found: CascadeSlot = 'default';\n\tfor (const { slot: candidate } of cascadeValues(authored)) {\n\t\tif (authored[candidate] !== undefined) found = candidate;\n\t\tif (candidate === slot) break;\n\t}\n\treturn found;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;AACA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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MAAgC;AACnG,MAAI,QAAqB;AACzB,aAAW,EAAE,MAAM,UAAU,KAAK,cAAc,QAAQ,GAAG;AAC1D,QAAI,SAAS,SAAS,MAAM,OAAW,SAAQ;AAC/C,QAAI,cAAc,KAAM;AAAA,EACzB;AACA,SAAO;AACR;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/engine/schema-artifacts.ts"],
|
|
4
|
-
"sourcesContent": ["import * as z from 'zod/mini';\nimport type { StandardJSONSchemaV1 } from '@standard-schema/spec';\nimport { ComponentType } from './component-type';\nimport { SchemaMetadataCatalog } from './schema-metadata-catalog';\nimport { generateZodJSONSchemaCollection, generateZodJSONSchemaDocument, isZodType } from '@/lib/zod-json-schema';\nimport {\n\tcreateStandardJSONSchema,\n\tcreateStandardJSONSchemaRecord,\n\ttype JSONSchemaObject,\n\ttype JSONSchemaTarget,\n} from '@/lib/standard-json-schema';\n\n/**\n * Metadata for form engine JSON Schema generation.\n * Used across all component types (elements, recipes, and actions).\n */\nexport interface FormEngineSchemaMetadata {\n\tid?: string;\n\ttitle?: string;\n\tdescription?: string;\n\tcomponentType: ComponentType;\n\tcategory?: string;\n\texamples?: unknown[];\n}\n\n/**\n * Metadata registry used by the schema artifact layer.\n */\nexport type FormEngineSchemaMetadataRegistry = ReturnType<typeof z.registry<FormEngineSchemaMetadata>>;\n\n/**\n * Bundles the validator and metadata registry used for schema generation.\n * The engine depends on this abstraction instead of hard-coding JSON Schema\n * conversion details into runtime methods.\n */\nexport interface FormEngineSchemaArtifacts {\n\tmetadataCatalog: SchemaMetadataCatalog;\n\tmetadataRegistry: FormEngineSchemaMetadataRegistry;\n\tformConfigValidator: z.ZodMiniType;\n\t/**\n\t * The schemas the JSON Schema export lists in place of a registration's own, by catalog id.\n\t *\n\t * @remarks\n\t * An element's or recipe's export schema is closed over the appearance axes it declares. The\n\t * catalog keeps the registration's validator schema, so this holds the export's alone.\n\t */\n\texportSchemas: ReadonlyMap<string, z.ZodMiniType>;\n\tjsonSchema: FormEngineJSONSchemaSerializer;\n}\n\ntype ZodSchemaWithRegister = z.ZodMiniType & {\n\tregister: (registry: FormEngineSchemaMetadataRegistry, metadata: FormEngineSchemaMetadata) => void;\n};\n\n/**\n * A schema the JSON Schema export defines once and refers to by its id, though it is no registration of the catalog.\n *\n * @remarks Without an id a schema is written out at every place that uses it.\n */\nexport interface SharedExportSchema {\n\treadonly schema: z.ZodMiniType;\n\treadonly metadata: FormEngineSchemaMetadata;\n}\n\n/**\n * Bridge catalog metadata into a Zod registry for JSON Schema generation.\n *\n * @remarks\n * An entry with an export schema is registered by that schema rather than the catalog's, so the\n * export refers to it by the entry's id.\n */\nexport function createZodRegistryFromCatalog(\n\tcatalog: SchemaMetadataCatalog,\n\texportSchemas: ReadonlyMap<string, z.ZodMiniType> = new Map(),\n): FormEngineSchemaMetadataRegistry {\n\tconst registry = z.registry<FormEngineSchemaMetadata>();\n\n\tfor (const { schema: catalogSchema, entry } of catalog.getRegisteredSchemas()) {\n\t\tconst schema = exportSchemas.get(entry.id) ?? catalogSchema;\n\t\tconst meta: FormEngineSchemaMetadata = {\n\t\t\tid: entry.id,\n\t\t\ttitle: entry.title,\n\t\t\tdescription: entry.description,\n\t\t\tcomponentType: entry.componentType,\n\t\t\tcategory: entry.category,\n\t\t};\n\n\t\tif (!isZodType(schema)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst zodSchema = schema as ZodSchemaWithRegister;\n\t\tif (typeof zodSchema.register === 'function') {\n\t\t\tzodSchema.register(registry, meta);\n\t\t} else {\n\t\t\tregistry.add(zodSchema, meta);\n\t\t}\n\t}\n\n\treturn registry;\n}\n\n/**\n * Serializer contract used by the engine for emitted JSON Schema artifacts.\n * Exposes collections and per-configuration input/output converters.\n */\nexport interface FormEngineJSONSchemaSerializer {\n\tgenerateCollection: (options?: {\n\t\ttarget?: JSONSchemaTarget;\n\t\turi?: (id: string) => string;\n\t\tio?: 'input' | 'output';\n\t}) => JSONSchemaObject;\n\tgenerateFormConfig: (options?: { target?: JSONSchemaTarget; io?: 'input' | 'output' }) => JSONSchemaObject;\n\tgenerateActionConfig: (\n\t\tactionType: string,\n\t\toptions?: { target?: JSONSchemaTarget; io?: 'input' | 'output' },\n\t) => JSONSchemaObject | undefined;\n\tformConfigStandardSchema: StandardJSONSchemaV1;\n\tactionConfigStandardSchemas: Record<string, StandardJSONSchemaV1>;\n}\n\nconst VENDOR = '@schema-engine/forms';\nconst FORM_CONFIG_SCHEMA_ID = 'form-config-schema';\n\n/** The Zod schemas the JSON Schema export lists the actions by, keyed by `$type`. */\nexport function createActionConfigValidatorMap(\n\texportedActions: Iterable<{ $type: string; exportSchema: unknown }>,\n): Map<string, z.ZodMiniType> {\n\treturn new Map(\n\t\tArray.from(exportedActions)\n\t\t\t.filter((action) => isZodType(action.exportSchema))\n\t\t\t.map((action) => [action.$type, action.exportSchema as z.ZodMiniType] as const),\n\t);\n}\n\nfunction generateFormConfigJSONSchemaForIO(\n\tmetadataRegistry: FormEngineSchemaMetadataRegistry,\n\tformConfigValidator: z.ZodMiniType,\n\tio: 'input' | 'output',\n\toptions?: { target?: JSONSchemaTarget },\n): JSONSchemaObject {\n\treturn generateZodJSONSchemaDocument(formConfigValidator, metadataRegistry, {\n\t\ttarget: options?.target,\n\t\tio,\n\t\tschemaId: FORM_CONFIG_SCHEMA_ID,\n\t});\n}\n\n/**\n * Create the JSON Schema serializer used by FormEngine schema artifacts.\n */\nfunction createFormEngineJSONSchemaSerializer(\n\tmetadataRegistry: FormEngineSchemaMetadataRegistry,\n\tformConfigValidator: z.ZodMiniType,\n\tactionConfigValidators?: Map<string, z.ZodMiniType>,\n): FormEngineJSONSchemaSerializer {\n\tconst generateCollection: FormEngineJSONSchemaSerializer['generateCollection'] = (options) => {\n\t\treturn generateZodJSONSchemaCollection(metadataRegistry, options);\n\t};\n\n\tconst generateFormConfig: FormEngineJSONSchemaSerializer['generateFormConfig'] = (options) => {\n\t\treturn generateFormConfigJSONSchemaForIO(\n\t\t\tmetadataRegistry,\n\t\t\tformConfigValidator,\n\t\t\toptions?.io ?? 'input',\n\t\t\toptions,\n\t\t);\n\t};\n\n\tconst generateActionSchema = (\n\t\tactionType: string,\n\t\toptions?: { target?: JSONSchemaTarget; io?: 'input' | 'output' },\n\t): JSONSchemaObject | undefined => {\n\t\tconst validator = actionConfigValidators?.get(actionType);\n\t\treturn validator\n\t\t\t? generateZodJSONSchemaDocument(validator, metadataRegistry, {\n\t\t\t\t\ttarget: options?.target,\n\t\t\t\t\tio: options?.io,\n\t\t\t\t\tschemaId: SchemaMetadataCatalog.entryId(ComponentType.Action, actionType),\n\t\t\t\t})\n\t\t\t: undefined;\n\t};\n\n\tconst formConfigStandardSchema = createStandardJSONSchema(\n\t\tVENDOR,\n\t\t(options) =>\n\t\t\tgenerateFormConfigJSONSchemaForIO(metadataRegistry, formConfigValidator, 'input', {\n\t\t\t\ttarget: options.target,\n\t\t\t}),\n\t\t(options) =>\n\t\t\tgenerateFormConfigJSONSchemaForIO(metadataRegistry, formConfigValidator, 'output', {\n\t\t\t\ttarget: options.target,\n\t\t\t}),\n\t);\n\n\tconst actionConfigStandardSchemas = createStandardJSONSchemaRecord(\n\t\tArray.from(actionConfigValidators?.keys() || []),\n\t\tVENDOR,\n\t\t(actionType, options) => generateActionSchema(actionType, { target: options.target, io: 'input' }),\n\t\t(actionType, options) => generateActionSchema(actionType, { target: options.target, io: 'output' }),\n\t);\n\n\treturn {\n\t\tgenerateCollection,\n\t\tgenerateFormConfig,\n\t\tgenerateActionConfig: generateActionSchema,\n\t\tformConfigStandardSchema,\n\t\tactionConfigStandardSchemas,\n\t};\n}\n\n/**\n * Create a schema artifact bundle from the current validator implementation.\n */\nexport function createFormEngineSchemaArtifacts(\n\tmetadataCatalog: SchemaMetadataCatalog,\n\tformConfigValidator: z.ZodMiniType,\n\tactionConfigValidators?: Map<string, z.ZodMiniType>,\n\texportSchemas: ReadonlyMap<string, z.ZodMiniType> = new Map(),\n\tsharedSchemas: readonly SharedExportSchema[] = [],\n): FormEngineSchemaArtifacts {\n\tconst metadataRegistry = createZodRegistryFromCatalog(metadataCatalog, exportSchemas);\n\tfor (const { schema, metadata } of sharedSchemas) metadataRegistry.add(schema, metadata);\n\treturn {\n\t\tmetadataCatalog,\n\t\tmetadataRegistry,\n\t\tformConfigValidator,\n\t\texportSchemas,\n\t\tjsonSchema: createFormEngineJSONSchemaSerializer(metadataRegistry, formConfigValidator, actionConfigValidators),\n\t};\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA,YAAY,OAAO;AAuEZ,SAAS,6BACf,SACA,gBAAoD,oBAAI,IAAI,GACzB;AACnC,QAAMA,YAAa,WAAmC;AAEtD,aAAW,EAAE,QAAQ,eAAe,MAAM,KAAK,QAAQ,qBAAqB,GAAG;AAC9E,UAAM,SAAS,cAAc,IAAI,MAAM,EAAE,KAAK;AAC9C,UAAM,OAAiC;AAAA,MACtC,IAAI,MAAM;AAAA,MACV,OAAO,MAAM;AAAA,MACb,aAAa,MAAM;AAAA,MACnB,eAAe,MAAM;AAAA,MACrB,UAAU,MAAM;AAAA,IACjB;AAEA,QAAI,CAAC,UAAU,MAAM,GAAG;AACvB;AAAA,IACD;AAEA,UAAM,YAAY;AAClB,QAAI,OAAO,UAAU,aAAa,YAAY;AAC7C,gBAAU,SAASA,WAAU,IAAI;AAAA,IAClC,OAAO;AACN,MAAAA,UAAS,IAAI,WAAW,IAAI;AAAA,IAC7B;AAAA,EACD;AAEA,SAAOA;AACR;AAqBA,IAAM,SAAS;AACf,IAAM,wBAAwB;AAGvB,SAAS,+BACf,iBAC6B;AAC7B,SAAO,IAAI;AAAA,IACV,MAAM,KAAK,eAAe,EACxB,OAAO,CAAC,WAAW,UAAU,OAAO,YAAY,CAAC,EACjD,IAAI,CAAC,WAAW,CAAC,OAAO,OAAO,OAAO,YAA6B,CAAU;AAAA,E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B;AAAA,IACtB;AAAA,IACA;AAAA,EACD;AACD;AAKO,SAAS,gCACf,iBACA,qBACA,wBACA,gBAAoD,oBAAI,IAAI,GAC5D,gBAA+C,CAAC,GACpB;AAC5B,QAAM,mBAAmB,6BAA6B,iBAAiB,aAAa;AACpF,aAAW,EAAE,QAAQ,SAAS,KAAK,cAAe,kBAAiB,IAAI,QAAQ,QAAQ;AACvF,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY,qCAAqC,kBAAkB,qBAAqB,sBAAsB;AAAA,EAC/G;AACD;",
|
|
6
|
-
"names": ["registry"]
|
|
7
|
-
}
|
|
File without changes
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getElementContainerKind
|
|
3
|
-
} from "./chunk-CRQWKC67.js";
|
|
4
1
|
import {
|
|
5
2
|
clonePlainValue,
|
|
6
3
|
getValueAtPath,
|
|
7
4
|
mergePathValues,
|
|
8
5
|
setValueAtPath
|
|
9
6
|
} from "./chunk-QLGM2AZW.js";
|
|
7
|
+
import {
|
|
8
|
+
getElementContainerKind
|
|
9
|
+
} from "./chunk-CRQWKC67.js";
|
|
10
10
|
import {
|
|
11
11
|
getElementChildren
|
|
12
12
|
} from "./chunk-ZUYSGCEH.js";
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|