@getodk/xforms-engine 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/client/BaseNode.d.ts +18 -3
- package/dist/client/BaseValueNode.d.ts +32 -0
- package/dist/client/EngineConfig.d.ts +49 -48
- package/dist/client/GroupNode.d.ts +1 -0
- package/dist/client/InputNode.d.ts +82 -0
- package/dist/client/ModelValueNode.d.ts +13 -7
- package/dist/client/NoteNode.d.ts +26 -9
- package/dist/client/RangeNode.d.ts +36 -0
- package/dist/client/RankNode.d.ts +46 -0
- package/dist/client/RootNode.d.ts +37 -7
- package/dist/client/SelectNode.d.ts +47 -25
- package/dist/client/SubtreeNode.d.ts +1 -0
- package/dist/client/TriggerNode.d.ts +10 -6
- package/dist/client/ValueType.d.ts +3 -0
- package/dist/client/constants.d.ts +50 -0
- package/dist/client/hierarchy.d.ts +8 -8
- package/dist/client/identity.d.ts +14 -0
- package/dist/client/node-types.d.ts +3 -2
- package/dist/client/resources.d.ts +93 -0
- package/dist/client/submission/SubmissionData.d.ts +7 -0
- package/dist/client/submission/SubmissionDefinition.d.ts +14 -0
- package/dist/client/submission/SubmissionInstanceFile.d.ts +6 -0
- package/dist/client/submission/SubmissionOptions.d.ts +23 -0
- package/dist/client/submission/SubmissionResult.d.ts +91 -0
- package/dist/client/submission/SubmissionState.d.ts +12 -0
- package/dist/client/unsupported/UnsupportedControlNode.d.ts +1 -3
- package/dist/client/validation.d.ts +2 -2
- package/dist/error/ErrorProductionDesignPendingError.d.ts +7 -0
- package/dist/error/RankMissingValueError.d.ts +3 -0
- package/dist/error/RankValueTypeError.d.ts +6 -0
- package/dist/error/SelectValueTypeError.d.ts +15 -0
- package/dist/error/ValueTypeInvariantError.d.ts +17 -0
- package/dist/error/XFormsSpecViolationError.d.ts +2 -0
- package/dist/error/XPathFunctionalityError.d.ts +14 -0
- package/dist/error/XPathFunctionalityNotSupportedError.d.ts +7 -0
- package/dist/error/XPathFunctionalityPendingError.d.ts +7 -0
- package/dist/index.d.ts +12 -4
- package/dist/index.js +17864 -14655
- package/dist/index.js.map +1 -1
- package/dist/instance/Group.d.ts +10 -4
- package/dist/instance/InputControl.d.ts +38 -0
- package/dist/instance/ModelValue.d.ts +17 -25
- package/dist/instance/Note.d.ts +16 -21
- package/dist/instance/PrimaryInstance.d.ts +85 -0
- package/dist/instance/RangeControl.d.ts +34 -0
- package/dist/instance/RankControl.d.ts +40 -0
- package/dist/instance/Root.d.ts +30 -25
- package/dist/instance/SelectControl.d.ts +66 -0
- package/dist/instance/Subtree.d.ts +11 -5
- package/dist/instance/TriggerControl.d.ts +13 -19
- package/dist/instance/abstract/DescendantNode.d.ts +32 -25
- package/dist/instance/abstract/InstanceNode.d.ts +52 -30
- package/dist/instance/abstract/UnsupportedControl.d.ts +11 -3
- package/dist/instance/abstract/ValueNode.d.ts +47 -0
- package/dist/instance/hierarchy.d.ts +13 -12
- package/dist/instance/identity.d.ts +2 -7
- package/dist/instance/internal-api/EvaluationContext.d.ts +53 -12
- package/dist/instance/internal-api/InstanceConfig.d.ts +8 -2
- package/dist/instance/internal-api/InstanceValueContext.d.ts +22 -0
- package/dist/instance/internal-api/PrimaryInstanceDocument.d.ts +36 -0
- package/dist/instance/internal-api/TranslationContext.d.ts +3 -2
- package/dist/instance/internal-api/ValidationContext.d.ts +3 -4
- package/dist/instance/internal-api/ValueContext.d.ts +2 -1
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableInstance.d.ts +14 -0
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.d.ts +32 -0
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableParentNode.d.ts +19 -0
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableValueNode.d.ts +18 -0
- package/dist/instance/repeat/BaseRepeatRange.d.ts +40 -83
- package/dist/instance/repeat/RepeatInstance.d.ts +12 -29
- package/dist/instance/repeat/RepeatRangeControlled.d.ts +2 -2
- package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +2 -2
- package/dist/instance/resource.d.ts +1 -1
- package/dist/instance/text/TextRange.d.ts +1 -1
- package/dist/instance/unsupported/UploadControl.d.ts +3 -1
- package/dist/integration/xpath/EngineXPathEvaluator.d.ts +14 -0
- package/dist/integration/xpath/adapter/XFormsXPathNode.d.ts +71 -0
- package/dist/integration/xpath/adapter/engineDOMAdapter.d.ts +5 -0
- package/dist/integration/xpath/adapter/kind.d.ts +32 -0
- package/dist/integration/xpath/adapter/names.d.ts +6 -0
- package/dist/integration/xpath/adapter/traversal.d.ts +26 -0
- package/dist/integration/xpath/adapter/values.d.ts +2 -0
- package/dist/integration/xpath/static-dom/StaticAttribute.d.ts +26 -0
- package/dist/integration/xpath/static-dom/StaticDocument.d.ts +15 -0
- package/dist/integration/xpath/static-dom/StaticElement.d.ts +48 -0
- package/dist/integration/xpath/static-dom/StaticNode.d.ts +33 -0
- package/dist/integration/xpath/static-dom/StaticText.d.ts +16 -0
- package/dist/lib/client-reactivity/submission/createInstanceSubmissionState.d.ts +3 -0
- package/dist/lib/client-reactivity/submission/createLeafNodeSubmissionState.d.ts +3 -0
- package/dist/lib/client-reactivity/submission/createNodeRangeSubmissionState.d.ts +4 -0
- package/dist/lib/client-reactivity/submission/createParentNodeSubmissionState.d.ts +4 -0
- package/dist/lib/client-reactivity/submission/createRootSubmissionState.d.ts +3 -0
- package/dist/lib/client-reactivity/submission/createValueNodeSubmissionState.d.ts +3 -0
- package/dist/lib/client-reactivity/submission/prepareSubmission.d.ts +8 -0
- package/dist/lib/codecs/DecimalValueCodec.d.ts +6 -0
- package/dist/lib/codecs/Geopoint/Geopoint.d.ts +48 -0
- package/dist/lib/codecs/Geopoint/GeopointValueCodec.d.ts +5 -0
- package/dist/lib/codecs/IntValueCodec.d.ts +6 -0
- package/dist/lib/codecs/NoteCodec.d.ts +8 -0
- package/dist/lib/codecs/RangeCodec.d.ts +8 -0
- package/dist/lib/codecs/StringValueCodec.d.ts +4 -0
- package/dist/lib/codecs/TriggerCodec.d.ts +7 -0
- package/dist/lib/codecs/ValueArrayCodec.d.ts +11 -0
- package/dist/lib/codecs/ValueCodec.d.ts +30 -0
- package/dist/lib/codecs/ValueTypePlaceholderCodec.d.ts +12 -0
- package/dist/lib/codecs/getNoteCodec.d.ts +3 -0
- package/dist/lib/codecs/getSelectCodec.d.ts +5 -0
- package/dist/lib/codecs/getSharedValueCodec.d.ts +48 -0
- package/dist/lib/codecs/items/BaseItemCodec.d.ts +9 -0
- package/dist/lib/codecs/items/MultipleValueItemCodec.d.ts +14 -0
- package/dist/lib/codecs/items/SingleValueItemCodec.d.ts +24 -0
- package/dist/lib/dom/query.d.ts +4 -2
- package/dist/lib/names/NamespaceDeclaration.d.ts +45 -0
- package/dist/lib/names/NamespaceDeclarationMap.d.ts +137 -0
- package/dist/lib/names/NamespaceURL.d.ts +30 -0
- package/dist/lib/names/QualifiedName.d.ts +113 -0
- package/dist/lib/number-parsers.d.ts +2 -0
- package/dist/lib/reactivity/createChildrenState.d.ts +7 -5
- package/dist/lib/reactivity/createComputedExpression.d.ts +18 -5
- package/dist/lib/reactivity/createInstanceValueState.d.ts +40 -0
- package/dist/lib/reactivity/createItemCollection.d.ts +21 -0
- package/dist/lib/reactivity/createNoteReadonlyThunk.d.ts +2 -2
- package/dist/lib/reactivity/createTranslationState.d.ts +19 -0
- package/dist/lib/reactivity/createValueState.d.ts +6 -10
- package/dist/lib/reactivity/materializeCurrentStateChildren.d.ts +4 -4
- package/dist/lib/xml-serialization.d.ts +50 -0
- package/dist/parse/XFormDOM.d.ts +18 -7
- package/dist/parse/XFormDefinition.d.ts +1 -2
- package/dist/parse/attachments/FormAttachmentResource.d.ts +27 -0
- package/dist/parse/body/BodyDefinition.d.ts +4 -4
- package/dist/parse/body/RepeatElementDefinition.d.ts +1 -1
- package/dist/parse/body/appearance/inputAppearanceParser.d.ts +1 -1
- package/dist/parse/body/appearance/rangeAppearanceParser.d.ts +3 -0
- package/dist/parse/body/control/{InputDefinition.d.ts → InputControlDefinition.d.ts} +4 -1
- package/dist/parse/body/control/ItemDefinition.d.ts +14 -0
- package/dist/parse/body/control/ItemsetDefinition.d.ts +18 -0
- package/dist/parse/body/control/RangeControlDefinition.d.ts +31 -2
- package/dist/parse/body/control/RankControlDefinition.d.ts +7 -3
- package/dist/parse/body/control/{select/SelectDefinition.d.ts → SelectControlDefinition.d.ts} +9 -9
- package/dist/parse/expression/ItemsetNodesetExpression.d.ts +1 -1
- package/dist/parse/expression/ItemsetValueExpression.d.ts +1 -1
- package/dist/parse/expression/abstract/DependencyContext.d.ts +0 -5
- package/dist/parse/expression/abstract/DependentExpression.d.ts +2 -3
- package/dist/parse/model/BindDefinition.d.ts +6 -5
- package/dist/parse/model/BindPreloadDefinition.d.ts +42 -0
- package/dist/parse/model/BindTypeDefinition.d.ts +20 -0
- package/dist/parse/model/DescendentNodeDefinition.d.ts +4 -14
- package/dist/parse/model/FormSubmissionDefinition.d.ts +8 -0
- package/dist/parse/model/ItextTranslation/ItextTranslationDefinition.d.ts +4 -0
- package/dist/parse/model/ItextTranslation/ItextTranslationRootDefinition.d.ts +9 -0
- package/dist/parse/model/ItextTranslation/ItextTranslationsDefinition.d.ts +8 -0
- package/dist/parse/model/LeafNodeDefinition.d.ts +9 -4
- package/dist/parse/model/ModelBindMap.d.ts +1 -1
- package/dist/parse/model/ModelDefinition.d.ts +2 -0
- package/dist/parse/model/NodeDefinition.d.ts +16 -20
- package/dist/parse/model/NoteNodeDefinition.d.ts +9 -8
- package/dist/parse/model/RangeNodeDefinition.d.ts +41 -0
- package/dist/parse/model/RepeatInstanceDefinition.d.ts +7 -4
- package/dist/parse/model/RepeatRangeDefinition.d.ts +7 -4
- package/dist/parse/model/RepeatTemplateDefinition.d.ts +7 -4
- package/dist/parse/model/RootAttributeDefinition.d.ts +24 -0
- package/dist/parse/model/RootAttributeMap.d.ts +23 -0
- package/dist/parse/model/RootDefinition.d.ts +12 -9
- package/dist/parse/model/SecondaryInstance/SecondaryInstanceDefinition.d.ts +4 -0
- package/dist/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.d.ts +7 -0
- package/dist/parse/model/SecondaryInstance/SecondaryInstancesDefinition.d.ts +13 -0
- package/dist/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.d.ts +14 -0
- package/dist/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.d.ts +22 -0
- package/dist/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceResource.d.ts +23 -0
- package/dist/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceSource.d.ts +9 -0
- package/dist/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.d.ts +5 -0
- package/dist/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.d.ts +7 -0
- package/dist/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.d.ts +13 -0
- package/dist/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.d.ts +12 -0
- package/dist/parse/model/SubtreeDefinition.d.ts +7 -4
- package/dist/parse/shared/parseStaticDocumentFromDOMSubtree.d.ts +23 -0
- package/dist/parse/text/ItemLabelDefinition.d.ts +1 -1
- package/dist/parse/text/ItemsetLabelDefinition.d.ts +2 -2
- package/dist/parse/text/abstract/TextElementDefinition.d.ts +1 -1
- package/dist/parse/text/abstract/TextRangeDefinition.d.ts +0 -2
- package/dist/parse/xpath/semantic-analysis.d.ts +6 -3
- package/dist/solid.js +15437 -12246
- package/dist/solid.js.map +1 -1
- package/package.json +18 -13
- package/src/client/BaseNode.ts +21 -6
- package/src/client/BaseValueNode.ts +35 -0
- package/src/client/EngineConfig.ts +52 -51
- package/src/client/GroupNode.ts +1 -0
- package/src/client/InputNode.ts +113 -0
- package/src/client/ModelValueNode.ts +31 -7
- package/src/client/NoteNode.ts +45 -9
- package/src/client/RangeNode.ts +51 -0
- package/src/client/RankNode.ts +54 -0
- package/src/client/RootNode.ts +43 -7
- package/src/client/SelectNode.ts +53 -26
- package/src/client/SubtreeNode.ts +1 -0
- package/src/client/TriggerNode.ts +12 -6
- package/src/client/ValueType.ts +4 -0
- package/src/client/constants.ts +67 -0
- package/src/client/hierarchy.ts +12 -13
- package/src/client/identity.ts +16 -0
- package/src/client/node-types.ts +13 -7
- package/src/client/resources.ts +118 -0
- package/src/client/submission/SubmissionData.ts +12 -0
- package/src/client/submission/SubmissionDefinition.ts +16 -0
- package/src/client/submission/SubmissionInstanceFile.ts +9 -0
- package/src/client/submission/SubmissionOptions.ts +28 -0
- package/src/client/submission/SubmissionResult.ts +124 -0
- package/src/client/submission/SubmissionState.ts +14 -0
- package/src/client/unsupported/UnsupportedControlNode.ts +2 -6
- package/src/client/validation.ts +2 -2
- package/src/error/ErrorProductionDesignPendingError.ts +6 -0
- package/src/error/RankMissingValueError.ts +5 -0
- package/src/error/RankValueTypeError.ts +13 -0
- package/src/error/SelectValueTypeError.ts +22 -0
- package/src/error/ValueTypeInvariantError.ts +22 -0
- package/src/error/XFormsSpecViolationError.ts +1 -0
- package/src/error/XPathFunctionalityError.ts +26 -0
- package/src/error/XPathFunctionalityNotSupportedError.ts +18 -0
- package/src/error/XPathFunctionalityPendingError.ts +18 -0
- package/src/index.ts +12 -13
- package/src/instance/Group.ts +18 -5
- package/src/instance/InputControl.ts +159 -0
- package/src/instance/ModelValue.ts +48 -53
- package/src/instance/Note.ts +40 -49
- package/src/instance/PrimaryInstance.ts +245 -0
- package/src/instance/RangeControl.ts +113 -0
- package/src/instance/RankControl.ts +199 -0
- package/src/instance/Root.ts +63 -134
- package/src/instance/SelectControl.ts +219 -0
- package/src/instance/Subtree.ts +20 -7
- package/src/instance/TriggerControl.ts +44 -66
- package/src/instance/abstract/DescendantNode.ts +91 -51
- package/src/instance/abstract/InstanceNode.ts +113 -107
- package/src/instance/abstract/UnsupportedControl.ts +29 -5
- package/src/instance/abstract/ValueNode.ts +128 -0
- package/src/instance/children.ts +80 -40
- package/src/instance/hierarchy.ts +39 -30
- package/src/instance/identity.ts +3 -9
- package/src/instance/index.ts +25 -7
- package/src/instance/internal-api/EvaluationContext.ts +60 -13
- package/src/instance/internal-api/InstanceConfig.ts +9 -2
- package/src/instance/internal-api/InstanceValueContext.ts +26 -0
- package/src/instance/internal-api/PrimaryInstanceDocument.ts +53 -0
- package/src/instance/internal-api/TranslationContext.ts +3 -2
- package/src/instance/internal-api/ValidationContext.ts +3 -4
- package/src/instance/internal-api/ValueContext.ts +2 -1
- package/src/instance/internal-api/submission/ClientReactiveSubmittableInstance.ts +20 -0
- package/src/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.ts +43 -0
- package/src/instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts +26 -0
- package/src/instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts +24 -0
- package/src/instance/repeat/BaseRepeatRange.ts +52 -131
- package/src/instance/repeat/RepeatInstance.ts +21 -46
- package/src/instance/repeat/RepeatRangeControlled.ts +5 -5
- package/src/instance/repeat/RepeatRangeUncontrolled.ts +2 -4
- package/src/instance/resource.ts +5 -2
- package/src/instance/text/TextChunk.ts +1 -1
- package/src/instance/unsupported/UploadControl.ts +5 -1
- package/src/integration/xpath/EngineXPathEvaluator.ts +22 -0
- package/src/integration/xpath/adapter/XFormsXPathNode.ts +126 -0
- package/src/integration/xpath/adapter/engineDOMAdapter.ts +57 -0
- package/src/integration/xpath/adapter/kind.ts +114 -0
- package/src/integration/xpath/adapter/names.ts +148 -0
- package/src/integration/xpath/adapter/traversal.ts +229 -0
- package/src/integration/xpath/adapter/values.ts +5 -0
- package/src/integration/xpath/static-dom/StaticAttribute.ts +41 -0
- package/src/integration/xpath/static-dom/StaticDocument.ts +36 -0
- package/src/integration/xpath/static-dom/StaticElement.ts +119 -0
- package/src/integration/xpath/static-dom/StaticNode.ts +68 -0
- package/src/integration/xpath/static-dom/StaticText.ts +28 -0
- package/src/lib/client-reactivity/README.md +0 -0
- package/src/lib/client-reactivity/submission/createInstanceSubmissionState.ts +12 -0
- package/src/lib/client-reactivity/submission/createLeafNodeSubmissionState.ts +20 -0
- package/src/lib/client-reactivity/submission/createNodeRangeSubmissionState.ts +17 -0
- package/src/lib/client-reactivity/submission/createParentNodeSubmissionState.ts +22 -0
- package/src/lib/client-reactivity/submission/createRootSubmissionState.ts +19 -0
- package/src/lib/client-reactivity/submission/createValueNodeSubmissionState.ts +21 -0
- package/src/lib/client-reactivity/submission/prepareSubmission.ts +172 -0
- package/src/lib/codecs/DecimalValueCodec.ts +46 -0
- package/src/lib/codecs/Geopoint/Geopoint.ts +150 -0
- package/src/lib/codecs/Geopoint/GeopointValueCodec.ts +20 -0
- package/src/lib/codecs/IntValueCodec.ts +100 -0
- package/src/lib/codecs/NoteCodec.ts +32 -0
- package/src/lib/codecs/RangeCodec.ts +65 -0
- package/src/lib/codecs/StringValueCodec.ts +11 -0
- package/src/lib/codecs/TriggerCodec.ts +64 -0
- package/src/lib/codecs/ValueArrayCodec.ts +42 -0
- package/src/lib/codecs/ValueCodec.ts +106 -0
- package/src/lib/codecs/ValueTypePlaceholderCodec.ts +19 -0
- package/src/lib/codecs/getNoteCodec.ts +27 -0
- package/src/lib/codecs/getSelectCodec.ts +27 -0
- package/src/lib/codecs/getSharedValueCodec.ts +79 -0
- package/src/lib/codecs/items/BaseItemCodec.ts +20 -0
- package/src/lib/codecs/items/MultipleValueItemCodec.ts +28 -0
- package/src/lib/codecs/items/SingleValueItemCodec.ts +67 -0
- package/src/lib/dom/query.ts +8 -2
- package/src/lib/names/NamespaceDeclaration.ts +106 -0
- package/src/lib/names/NamespaceDeclarationMap.ts +228 -0
- package/src/lib/names/NamespaceURL.ts +44 -0
- package/src/lib/names/QualifiedName.ts +170 -0
- package/src/lib/number-parsers.ts +25 -0
- package/src/lib/reactivity/createChildrenState.ts +8 -6
- package/src/lib/reactivity/createComputedExpression.ts +57 -34
- package/src/lib/reactivity/createInstanceValueState.ts +216 -0
- package/src/lib/reactivity/createItemCollection.ts +173 -0
- package/src/lib/reactivity/createNoteReadonlyThunk.ts +12 -7
- package/src/lib/reactivity/createTranslationState.ts +61 -0
- package/src/lib/reactivity/createValueState.ts +62 -120
- package/src/lib/reactivity/materializeCurrentStateChildren.ts +7 -7
- package/src/lib/reactivity/text/createTextRange.ts +4 -3
- package/src/lib/reactivity/validation/createAggregatedViolations.ts +1 -1
- package/src/lib/reactivity/validation/createValidation.ts +2 -3
- package/src/lib/xml-serialization.ts +163 -0
- package/src/parse/XFormDOM.ts +231 -76
- package/src/parse/XFormDefinition.ts +2 -10
- package/src/parse/attachments/FormAttachmentResource.ts +40 -0
- package/src/parse/body/BodyDefinition.ts +7 -7
- package/src/parse/body/appearance/inputAppearanceParser.ts +1 -1
- package/src/parse/body/appearance/rangeAppearanceParser.ts +11 -0
- package/src/parse/body/control/InputControlDefinition.ts +29 -0
- package/src/parse/body/control/{select/ItemDefinition.ts → ItemDefinition.ts} +8 -6
- package/src/parse/body/control/{select/ItemsetDefinition.ts → ItemsetDefinition.ts} +11 -9
- package/src/parse/body/control/RangeControlDefinition.ts +91 -6
- package/src/parse/body/control/RankControlDefinition.ts +25 -7
- package/src/parse/body/control/{select/SelectDefinition.ts → SelectControlDefinition.ts} +9 -9
- package/src/parse/expression/ItemsetNodesetExpression.ts +1 -1
- package/src/parse/expression/ItemsetValueExpression.ts +1 -1
- package/src/parse/expression/abstract/DependencyContext.ts +0 -26
- package/src/parse/expression/abstract/DependentExpression.ts +2 -13
- package/src/parse/model/BindDefinition.ts +9 -8
- package/src/parse/model/BindPreloadDefinition.ts +100 -0
- package/src/parse/model/BindTypeDefinition.ts +175 -0
- package/src/parse/model/DescendentNodeDefinition.ts +7 -31
- package/src/parse/model/FormSubmissionDefinition.ts +44 -0
- package/src/parse/model/ItextTranslation/ItextTranslationDefinition.ts +4 -0
- package/src/parse/model/ItextTranslation/ItextTranslationRootDefinition.ts +42 -0
- package/src/parse/model/ItextTranslation/ItextTranslationsDefinition.ts +31 -0
- package/src/parse/model/LeafNodeDefinition.ts +15 -5
- package/src/parse/model/ModelBindMap.ts +6 -8
- package/src/parse/model/ModelDefinition.ts +6 -1
- package/src/parse/model/NodeDefinition.ts +24 -48
- package/src/parse/model/NoteNodeDefinition.ts +11 -10
- package/src/parse/model/RangeNodeDefinition.ts +118 -0
- package/src/parse/model/RepeatInstanceDefinition.ts +11 -7
- package/src/parse/model/RepeatRangeDefinition.ts +11 -7
- package/src/parse/model/RepeatTemplateDefinition.ts +11 -7
- package/src/parse/model/RootAttributeDefinition.ts +45 -0
- package/src/parse/model/RootAttributeMap.ts +44 -0
- package/src/parse/model/RootDefinition.ts +31 -29
- package/src/parse/model/SecondaryInstance/SecondaryInstanceDefinition.ts +4 -0
- package/src/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.ts +12 -0
- package/src/parse/model/SecondaryInstance/SecondaryInstancesDefinition.ts +102 -0
- package/src/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.ts +40 -0
- package/src/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.ts +288 -0
- package/src/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceResource.ts +222 -0
- package/src/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceSource.ts +22 -0
- package/src/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.ts +415 -0
- package/src/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.ts +19 -0
- package/src/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.ts +29 -0
- package/src/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.ts +32 -0
- package/src/parse/model/SubtreeDefinition.ts +12 -12
- package/src/parse/shared/parseStaticDocumentFromDOMSubtree.ts +149 -0
- package/src/parse/text/ItemLabelDefinition.ts +1 -1
- package/src/parse/text/ItemsetLabelDefinition.ts +2 -2
- package/src/parse/text/abstract/TextElementDefinition.ts +1 -1
- package/src/parse/text/abstract/TextRangeDefinition.ts +0 -6
- package/src/parse/xpath/semantic-analysis.ts +33 -3
- package/dist/client/StringNode.d.ts +0 -46
- package/dist/client/unsupported/RangeNode.d.ts +0 -9
- package/dist/client/unsupported/RankNode.d.ts +0 -9
- package/dist/instance/SelectField.d.ts +0 -50
- package/dist/instance/StringField.d.ts +0 -44
- package/dist/instance/internal-api/SubscribableDependency.d.ts +0 -59
- package/dist/instance/unsupported/RangeControl.d.ts +0 -4
- package/dist/instance/unsupported/RankControl.d.ts +0 -4
- package/dist/lib/reactivity/createSelectItems.d.ts +0 -16
- package/dist/parse/XFormDataType.d.ts +0 -25
- package/dist/parse/body/control/select/ItemDefinition.d.ts +0 -13
- package/dist/parse/body/control/select/ItemsetDefinition.d.ts +0 -17
- package/dist/parse/body/control/select/ItemsetNodesetContext.d.ts +0 -11
- package/src/client/StringNode.ts +0 -52
- package/src/client/unsupported/RangeNode.ts +0 -14
- package/src/client/unsupported/RankNode.ts +0 -14
- package/src/instance/SelectField.ts +0 -226
- package/src/instance/StringField.ts +0 -120
- package/src/instance/internal-api/SubscribableDependency.ts +0 -61
- package/src/instance/unsupported/RangeControl.ts +0 -5
- package/src/instance/unsupported/RankControl.ts +0 -5
- package/src/lib/reactivity/createSelectItems.ts +0 -168
- package/src/parse/XFormDataType.ts +0 -62
- package/src/parse/body/control/InputDefinition.ts +0 -22
- package/src/parse/body/control/select/ItemsetNodesetContext.ts +0 -26
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { XPathNodeKindKey } from '@getodk/xpath';
|
|
2
|
+
import { QualifiedName } from '../../../lib/names/QualifiedName.ts';
|
|
3
|
+
import type { XFormsXPathAttribute } from '../adapter/XFormsXPathNode.ts';
|
|
4
|
+
import type { StaticDocument } from './StaticDocument.ts';
|
|
5
|
+
import type { StaticElement } from './StaticElement.ts';
|
|
6
|
+
import { StaticNode } from './StaticNode.ts';
|
|
7
|
+
|
|
8
|
+
interface StaticAttributeOptions {
|
|
9
|
+
readonly namespaceURI: string | null;
|
|
10
|
+
readonly prefix?: string | null;
|
|
11
|
+
readonly localName: string;
|
|
12
|
+
readonly value: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class StaticAttribute extends StaticNode<'attribute'> implements XFormsXPathAttribute {
|
|
16
|
+
readonly [XPathNodeKindKey] = 'attribute';
|
|
17
|
+
readonly nodeType = 'static-attribute';
|
|
18
|
+
readonly rootDocument: StaticDocument;
|
|
19
|
+
readonly root: StaticElement;
|
|
20
|
+
readonly qualifiedName: QualifiedName;
|
|
21
|
+
readonly attributes = [] as const;
|
|
22
|
+
readonly children = null;
|
|
23
|
+
readonly value: string;
|
|
24
|
+
|
|
25
|
+
constructor(
|
|
26
|
+
readonly parent: StaticElement,
|
|
27
|
+
options: StaticAttributeOptions
|
|
28
|
+
) {
|
|
29
|
+
super();
|
|
30
|
+
|
|
31
|
+
this.rootDocument = parent.rootDocument;
|
|
32
|
+
this.root = parent.root;
|
|
33
|
+
this.qualifiedName = new QualifiedName(options);
|
|
34
|
+
this.value = options.value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// XFormsXPathAttribute
|
|
38
|
+
getXPathValue(): string {
|
|
39
|
+
return this.value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { XPathNodeKindKey } from '@getodk/xpath';
|
|
2
|
+
import type { XFormsXPathDocument } from '../adapter/XFormsXPathNode.ts';
|
|
3
|
+
import { StaticElement } from './StaticElement.ts';
|
|
4
|
+
import { StaticNode } from './StaticNode.ts';
|
|
5
|
+
|
|
6
|
+
export type StaticDocumentRootFactory<T extends StaticDocument, Root extends StaticElement> = (
|
|
7
|
+
staticDocument: T
|
|
8
|
+
) => Root;
|
|
9
|
+
|
|
10
|
+
export abstract class StaticDocument<DocumentRoot extends StaticElement = StaticElement>
|
|
11
|
+
extends StaticNode<'document'>
|
|
12
|
+
implements XFormsXPathDocument
|
|
13
|
+
{
|
|
14
|
+
readonly [XPathNodeKindKey] = 'document';
|
|
15
|
+
readonly nodeType = 'static-document';
|
|
16
|
+
readonly rootDocument: StaticDocument;
|
|
17
|
+
readonly root: DocumentRoot;
|
|
18
|
+
readonly parent = null;
|
|
19
|
+
readonly children: readonly [root: DocumentRoot];
|
|
20
|
+
|
|
21
|
+
constructor(rootFactory: StaticDocumentRootFactory<StaticDocument<DocumentRoot>, DocumentRoot>) {
|
|
22
|
+
super();
|
|
23
|
+
|
|
24
|
+
this.rootDocument = this;
|
|
25
|
+
|
|
26
|
+
const root = rootFactory(this);
|
|
27
|
+
|
|
28
|
+
this.root = root;
|
|
29
|
+
this.children = [root];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// XFormsXPathDocument
|
|
33
|
+
getXPathValue(): string {
|
|
34
|
+
return this.root.getXPathValue();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { XFORMS_KNOWN_ATTRIBUTE, XFORMS_LOCAL_NAME, XPathNodeKindKey } from '@getodk/xpath';
|
|
2
|
+
import { QualifiedName } from '../../../lib/names/QualifiedName.ts';
|
|
3
|
+
import type { EngineDOMAdapter } from '../adapter/engineDOMAdapter.ts';
|
|
4
|
+
import type { XFormsXPathElement } from '../adapter/XFormsXPathNode.ts';
|
|
5
|
+
import { StaticAttribute } from './StaticAttribute.ts';
|
|
6
|
+
import type { StaticDocument } from './StaticDocument.ts';
|
|
7
|
+
import type { StaticChildNode, StaticParentNode } from './StaticNode.ts';
|
|
8
|
+
import { StaticNode } from './StaticNode.ts';
|
|
9
|
+
|
|
10
|
+
export type StaticElementAttributesFactory = (element: StaticElement) => readonly StaticAttribute[];
|
|
11
|
+
|
|
12
|
+
export type StaticElementChildNodesFactory = (element: StaticElement) => readonly StaticChildNode[];
|
|
13
|
+
|
|
14
|
+
export interface StaticElementOptions {
|
|
15
|
+
readonly namespaceURI: string | null;
|
|
16
|
+
readonly prefix?: string | null;
|
|
17
|
+
readonly localName: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type StaticElementKnownAttributeValue<
|
|
21
|
+
T extends StaticElement,
|
|
22
|
+
LocalName extends string,
|
|
23
|
+
> = T extends { readonly [XFORMS_KNOWN_ATTRIBUTE]: LocalName } ? string : string | null;
|
|
24
|
+
|
|
25
|
+
type AssertStaticElementKnownAttributeValue = <T extends StaticElement, LocalName extends string>(
|
|
26
|
+
element: T,
|
|
27
|
+
localName: LocalName,
|
|
28
|
+
value: string | null
|
|
29
|
+
) => asserts value is StaticElementKnownAttributeValue<T, LocalName>;
|
|
30
|
+
|
|
31
|
+
const assertStaticElementKnownAttributeValue: AssertStaticElementKnownAttributeValue = (
|
|
32
|
+
element,
|
|
33
|
+
localName,
|
|
34
|
+
value
|
|
35
|
+
) => {
|
|
36
|
+
if (localName === element[XFORMS_KNOWN_ATTRIBUTE] && value == null) {
|
|
37
|
+
throw new Error(`Expected attribute: ${element[XFORMS_KNOWN_ATTRIBUTE]}`);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export class StaticElement<Parent extends StaticParentNode = StaticParentNode>
|
|
42
|
+
extends StaticNode<'element'>
|
|
43
|
+
implements XFormsXPathElement
|
|
44
|
+
{
|
|
45
|
+
readonly [XFORMS_LOCAL_NAME]?: string;
|
|
46
|
+
readonly [XFORMS_KNOWN_ATTRIBUTE]?: string;
|
|
47
|
+
|
|
48
|
+
readonly [XPathNodeKindKey] = 'element';
|
|
49
|
+
readonly nodeType = 'static-element';
|
|
50
|
+
readonly rootDocument: StaticDocument;
|
|
51
|
+
readonly root: StaticElement;
|
|
52
|
+
readonly qualifiedName: QualifiedName;
|
|
53
|
+
readonly attributes: readonly StaticAttribute[];
|
|
54
|
+
readonly children: readonly StaticChildNode[];
|
|
55
|
+
readonly value = null;
|
|
56
|
+
|
|
57
|
+
constructor(
|
|
58
|
+
readonly parent: Parent,
|
|
59
|
+
attributesFactory: StaticElementAttributesFactory,
|
|
60
|
+
childNodesFactory: StaticElementChildNodesFactory,
|
|
61
|
+
options: StaticElementOptions
|
|
62
|
+
) {
|
|
63
|
+
super();
|
|
64
|
+
|
|
65
|
+
const { rootDocument } = parent;
|
|
66
|
+
|
|
67
|
+
this.rootDocument = rootDocument;
|
|
68
|
+
|
|
69
|
+
// Account for the fact that we may be constructing the document root!
|
|
70
|
+
if (parent === rootDocument) {
|
|
71
|
+
this.root = this;
|
|
72
|
+
} else {
|
|
73
|
+
this.root = parent.root;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.qualifiedName = new QualifiedName(options);
|
|
77
|
+
this.attributes = attributesFactory(this);
|
|
78
|
+
this.children = childNodesFactory(this);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @todo Generalize this, incorporate into {@link EngineDOMAdapter}
|
|
83
|
+
* @todo Namespaced lookup
|
|
84
|
+
* @todo Optimize: lookup from map and/or caching
|
|
85
|
+
*/
|
|
86
|
+
protected getAttributeNode(localName: string): StaticAttribute | null {
|
|
87
|
+
return (
|
|
88
|
+
this.attributes.find((attribute) => {
|
|
89
|
+
return attribute.qualifiedName.localName === localName;
|
|
90
|
+
}) ?? null
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @todo Generalize this, incorporate into {@link EngineDOMAdapter}
|
|
96
|
+
* @todo Namespaced lookup
|
|
97
|
+
* @todo Optimize: lookup from map and/or caching (especially asserting known
|
|
98
|
+
* attributes!)
|
|
99
|
+
* @todo As long as this depends on {@link getAttributeNode}, push assertion
|
|
100
|
+
* up. (This was put off because the types are already plenty complex as it
|
|
101
|
+
* is.)
|
|
102
|
+
*/
|
|
103
|
+
getAttributeValue<This extends StaticElement, LocalName extends string>(
|
|
104
|
+
this: This,
|
|
105
|
+
localName: LocalName
|
|
106
|
+
): StaticElementKnownAttributeValue<This, LocalName> {
|
|
107
|
+
const attribute = this.getAttributeNode(localName);
|
|
108
|
+
const value = attribute?.value ?? null;
|
|
109
|
+
|
|
110
|
+
assertStaticElementKnownAttributeValue(this, localName, value);
|
|
111
|
+
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// XFormsXPathElement
|
|
116
|
+
getXPathValue(): string {
|
|
117
|
+
return this.children.map((child) => child.getXPathValue()).join('');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// import type { StaticNodeBrand } from '@getodk/xpath';
|
|
2
|
+
import { XPathNodeKindKey } from '@getodk/xpath';
|
|
3
|
+
import type { XFormsXPathNode } from '../adapter/XFormsXPathNode.ts';
|
|
4
|
+
import type { StaticAttribute } from './StaticAttribute.ts';
|
|
5
|
+
import type { StaticDocument } from './StaticDocument.ts';
|
|
6
|
+
import type { StaticElement } from './StaticElement.ts';
|
|
7
|
+
import type { StaticText } from './StaticText.ts';
|
|
8
|
+
|
|
9
|
+
// prettier-ignore
|
|
10
|
+
export type StaticNodeKind =
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
12
|
+
| 'document'
|
|
13
|
+
| 'element'
|
|
14
|
+
| 'attribute'
|
|
15
|
+
| 'text';
|
|
16
|
+
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
export type StaticNodeType<Kind extends StaticNodeKind> = `static-${Kind}`;
|
|
19
|
+
|
|
20
|
+
export abstract class StaticNode<Kind extends StaticNodeKind> implements XFormsXPathNode {
|
|
21
|
+
abstract readonly [XPathNodeKindKey]: Kind;
|
|
22
|
+
|
|
23
|
+
abstract readonly nodeType: StaticNodeType<Kind>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A concrete {@link StaticDocument} instance, representing the topmost node
|
|
27
|
+
* of a static document tree, containing all of:
|
|
28
|
+
*
|
|
29
|
+
* - {@link root}
|
|
30
|
+
* - {@link children}
|
|
31
|
+
* - any {@link StaticChildNode} descendants of either of the above
|
|
32
|
+
*/
|
|
33
|
+
abstract readonly rootDocument: StaticDocument;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A concrete {@link StaticElement} instance, representing the single,
|
|
37
|
+
* immediate child of {@link rootDocument}, containing all other descendants
|
|
38
|
+
* of its document tree.
|
|
39
|
+
*/
|
|
40
|
+
abstract readonly root: StaticElement;
|
|
41
|
+
|
|
42
|
+
abstract readonly children: readonly StaticChildNode[] | null;
|
|
43
|
+
|
|
44
|
+
// XFormsXPathNode
|
|
45
|
+
getXPathChildNodes(): readonly StaticChildNode[] {
|
|
46
|
+
return this.children ?? [];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
abstract getXPathValue(): string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// prettier-ignore
|
|
53
|
+
export type AnyStaticNode =
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
55
|
+
| StaticDocument
|
|
56
|
+
| StaticElement
|
|
57
|
+
| StaticAttribute
|
|
58
|
+
| StaticText;
|
|
59
|
+
|
|
60
|
+
// prettier-ignore
|
|
61
|
+
export type StaticParentNode =
|
|
62
|
+
| StaticDocument
|
|
63
|
+
| StaticElement;
|
|
64
|
+
|
|
65
|
+
// prettier-ignore
|
|
66
|
+
export type StaticChildNode =
|
|
67
|
+
| StaticElement
|
|
68
|
+
| StaticText;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { XPathNodeKindKey } from '@getodk/xpath';
|
|
2
|
+
import type { XFormsXPathText } from '../adapter/XFormsXPathNode.ts';
|
|
3
|
+
import type { StaticDocument } from './StaticDocument.ts';
|
|
4
|
+
import type { StaticElement } from './StaticElement.ts';
|
|
5
|
+
import { StaticNode } from './StaticNode.ts';
|
|
6
|
+
|
|
7
|
+
export class StaticText extends StaticNode<'text'> implements XFormsXPathText {
|
|
8
|
+
readonly [XPathNodeKindKey] = 'text';
|
|
9
|
+
readonly nodeType = 'static-text';
|
|
10
|
+
readonly rootDocument: StaticDocument;
|
|
11
|
+
readonly root: StaticElement;
|
|
12
|
+
readonly children = null;
|
|
13
|
+
|
|
14
|
+
constructor(
|
|
15
|
+
readonly parent: StaticElement,
|
|
16
|
+
readonly value: string
|
|
17
|
+
) {
|
|
18
|
+
super();
|
|
19
|
+
|
|
20
|
+
this.rootDocument = parent.rootDocument;
|
|
21
|
+
this.root = parent.root;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// XFormsXPathText
|
|
25
|
+
getXPathValue(): string {
|
|
26
|
+
return this.value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
|
|
2
|
+
import type { ClientReactiveSubmittableInstance } from '../../../instance/internal-api/submission/ClientReactiveSubmittableInstance.ts';
|
|
3
|
+
|
|
4
|
+
export const createInstanceSubmissionState = (
|
|
5
|
+
node: ClientReactiveSubmittableInstance
|
|
6
|
+
): SubmissionState => {
|
|
7
|
+
return {
|
|
8
|
+
get submissionXML(): string {
|
|
9
|
+
return node.root.submissionState.submissionXML;
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
|
|
2
|
+
import type { ClientReactiveSubmittableLeafNode } from '../../../instance/internal-api/submission/ClientReactiveSubmittableLeafNode.ts';
|
|
3
|
+
import { escapeXMLText, serializeLeafElementXML } from '../../xml-serialization.ts';
|
|
4
|
+
|
|
5
|
+
export const createLeafNodeSubmissionState = <Value>(
|
|
6
|
+
node: ClientReactiveSubmittableLeafNode<Value>
|
|
7
|
+
): SubmissionState => {
|
|
8
|
+
return {
|
|
9
|
+
get submissionXML() {
|
|
10
|
+
if (!node.currentState.relevant) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const value = node.encodeValue(node.currentState.value);
|
|
15
|
+
const xmlValue = escapeXMLText(value);
|
|
16
|
+
|
|
17
|
+
return serializeLeafElementXML(node.definition.qualifiedName, xmlValue);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
|
|
2
|
+
import type { ClientReactiveSubmittableParentNode } from '../../../instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts';
|
|
3
|
+
import type { RepeatInstance } from '../../../instance/repeat/RepeatInstance.ts';
|
|
4
|
+
|
|
5
|
+
export const createNodeRangeSubmissionState = (
|
|
6
|
+
node: ClientReactiveSubmittableParentNode<RepeatInstance>
|
|
7
|
+
): SubmissionState => {
|
|
8
|
+
return {
|
|
9
|
+
get submissionXML() {
|
|
10
|
+
const serializedChildren = node.currentState.children.map((child) => {
|
|
11
|
+
return child.submissionState.submissionXML;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return serializedChildren.join('');
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
|
|
2
|
+
import type { GeneralChildNode } from '../../../instance/hierarchy.ts';
|
|
3
|
+
import type { ClientReactiveSubmittableParentNode } from '../../../instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts';
|
|
4
|
+
import { serializeParentElementXML } from '../../xml-serialization.ts';
|
|
5
|
+
|
|
6
|
+
export const createParentNodeSubmissionState = (
|
|
7
|
+
node: ClientReactiveSubmittableParentNode<GeneralChildNode>
|
|
8
|
+
): SubmissionState => {
|
|
9
|
+
return {
|
|
10
|
+
get submissionXML() {
|
|
11
|
+
if (!node.currentState.relevant) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const serializedChildren = node.currentState.children.map((child) => {
|
|
16
|
+
return child.submissionState.submissionXML;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return serializeParentElementXML(node.definition.qualifiedName, serializedChildren);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
|
|
2
|
+
import type { Root } from '../../../instance/Root.ts';
|
|
3
|
+
import { serializeParentElementXML } from '../../xml-serialization.ts';
|
|
4
|
+
|
|
5
|
+
export const createRootSubmissionState = (node: Root): SubmissionState => {
|
|
6
|
+
return {
|
|
7
|
+
get submissionXML() {
|
|
8
|
+
const { namespaceDeclarations, attributes } = node.definition;
|
|
9
|
+
const serializedChildren = node.currentState.children.map((child) => {
|
|
10
|
+
return child.submissionState.submissionXML;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return serializeParentElementXML(node.definition.qualifiedName, serializedChildren, {
|
|
14
|
+
namespaceDeclarations,
|
|
15
|
+
attributes: Array.from(attributes.values()),
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SubmissionState } from '../../../client/submission/SubmissionState.ts';
|
|
2
|
+
import type { ClientReactiveSubmittableValueNode } from '../../../instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts';
|
|
3
|
+
import { escapeXMLText, serializeLeafElementXML } from '../../xml-serialization.ts';
|
|
4
|
+
|
|
5
|
+
export const createValueNodeSubmissionState = (
|
|
6
|
+
node: ClientReactiveSubmittableValueNode
|
|
7
|
+
): SubmissionState => {
|
|
8
|
+
const { qualifiedName } = node.definition;
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
get submissionXML() {
|
|
12
|
+
if (!node.currentState.relevant) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const xmlValue = escapeXMLText(node.currentState.instanceValue);
|
|
17
|
+
|
|
18
|
+
return serializeLeafElementXML(qualifiedName, xmlValue);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { UnreachableError } from '@getodk/common/lib/error/UnreachableError.ts';
|
|
2
|
+
import {
|
|
3
|
+
SUBMISSION_INSTANCE_FILE_NAME,
|
|
4
|
+
SUBMISSION_INSTANCE_FILE_TYPE,
|
|
5
|
+
} from '../../../client/constants.ts';
|
|
6
|
+
import type { SubmissionData } from '../../../client/submission/SubmissionData.ts';
|
|
7
|
+
import type { SubmissionDefinition } from '../../../client/submission/SubmissionDefinition.ts';
|
|
8
|
+
import type { SubmissionInstanceFile } from '../../../client/submission/SubmissionInstanceFile.ts';
|
|
9
|
+
import type { SubmissionChunkedType } from '../../../client/submission/SubmissionOptions.ts';
|
|
10
|
+
import type { SubmissionResult } from '../../../client/submission/SubmissionResult.ts';
|
|
11
|
+
import type { DescendantNodeViolationReference } from '../../../client/validation.ts';
|
|
12
|
+
import type { ClientReactiveSubmittableInstance } from '../../../instance/internal-api/submission/ClientReactiveSubmittableInstance.ts';
|
|
13
|
+
|
|
14
|
+
class InstanceFile extends File implements SubmissionInstanceFile {
|
|
15
|
+
override readonly name = SUBMISSION_INSTANCE_FILE_NAME;
|
|
16
|
+
override readonly type = SUBMISSION_INSTANCE_FILE_TYPE;
|
|
17
|
+
|
|
18
|
+
constructor(instanceRoot: ClientReactiveSubmittableInstance) {
|
|
19
|
+
const { submissionXML } = instanceRoot.submissionState;
|
|
20
|
+
|
|
21
|
+
super([submissionXML], SUBMISSION_INSTANCE_FILE_NAME, {
|
|
22
|
+
type: SUBMISSION_INSTANCE_FILE_TYPE,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type AssertSubmissionData = (data: FormData) => asserts data is SubmissionData;
|
|
28
|
+
|
|
29
|
+
const assertSubmissionData: AssertSubmissionData = (data) => {
|
|
30
|
+
const instanceFile = data.get(SUBMISSION_INSTANCE_FILE_NAME);
|
|
31
|
+
|
|
32
|
+
if (!(instanceFile instanceof InstanceFile)) {
|
|
33
|
+
throw new Error(`Invalid SubmissionData`);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
class InstanceSubmissionData extends FormData {
|
|
38
|
+
static from(instanceFile: InstanceFile, attachments: readonly File[]): SubmissionData {
|
|
39
|
+
const data = new this(instanceFile, attachments);
|
|
40
|
+
|
|
41
|
+
assertSubmissionData(data);
|
|
42
|
+
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private constructor(
|
|
47
|
+
readonly instanceFile: InstanceFile,
|
|
48
|
+
readonly attachments: readonly File[]
|
|
49
|
+
) {
|
|
50
|
+
super();
|
|
51
|
+
|
|
52
|
+
this.set(SUBMISSION_INSTANCE_FILE_NAME, instanceFile);
|
|
53
|
+
|
|
54
|
+
attachments.forEach((attachment) => {
|
|
55
|
+
const { name } = attachment;
|
|
56
|
+
|
|
57
|
+
if (name === SUBMISSION_INSTANCE_FILE_NAME && attachment !== instanceFile) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Failed to add conflicting attachment with name ${SUBMISSION_INSTANCE_FILE_NAME}`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.set(name, attachment);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface PendingValidation {
|
|
69
|
+
readonly status: 'pending';
|
|
70
|
+
readonly violations: readonly DescendantNodeViolationReference[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
interface ReadyValidation {
|
|
74
|
+
readonly status: 'ready';
|
|
75
|
+
readonly violations: null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
type SubmissionInstanceStateValidation = PendingValidation | ReadyValidation;
|
|
79
|
+
|
|
80
|
+
const validateSubmission = (
|
|
81
|
+
instanceRoot: ClientReactiveSubmittableInstance
|
|
82
|
+
): SubmissionInstanceStateValidation => {
|
|
83
|
+
const { violations } = instanceRoot.validationState;
|
|
84
|
+
|
|
85
|
+
if (violations.length === 0) {
|
|
86
|
+
return {
|
|
87
|
+
status: 'ready',
|
|
88
|
+
violations: null,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
status: 'pending',
|
|
94
|
+
violations,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const monolithicSubmissionResult = (
|
|
99
|
+
validation: SubmissionInstanceStateValidation,
|
|
100
|
+
definition: SubmissionDefinition,
|
|
101
|
+
instanceFile: InstanceFile,
|
|
102
|
+
attachments: readonly File[]
|
|
103
|
+
): SubmissionResult<'monolithic'> => {
|
|
104
|
+
const data = InstanceSubmissionData.from(instanceFile, attachments);
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
...validation,
|
|
108
|
+
definition,
|
|
109
|
+
data,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
interface ChunkedSubmissionResultOptions {
|
|
114
|
+
readonly maxSize: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const chunkedSubmissionResult = (
|
|
118
|
+
validation: SubmissionInstanceStateValidation,
|
|
119
|
+
definition: SubmissionDefinition,
|
|
120
|
+
instanceFile: InstanceFile,
|
|
121
|
+
attachments: readonly File[],
|
|
122
|
+
options: ChunkedSubmissionResultOptions
|
|
123
|
+
): SubmissionResult<'chunked'> => {
|
|
124
|
+
if (attachments.length > 0 || options.maxSize !== Infinity) {
|
|
125
|
+
throw new Error('Submission chunking pending implementation');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const data = InstanceSubmissionData.from(instanceFile, attachments);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
...validation,
|
|
132
|
+
definition,
|
|
133
|
+
data: [data],
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export interface PrepeareSubmissionOptions<ChunkedType extends SubmissionChunkedType> {
|
|
138
|
+
readonly chunked: ChunkedType;
|
|
139
|
+
readonly maxSize: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const prepareSubmission = <ChunkedType extends SubmissionChunkedType>(
|
|
143
|
+
instanceRoot: ClientReactiveSubmittableInstance,
|
|
144
|
+
options: PrepeareSubmissionOptions<ChunkedType>
|
|
145
|
+
): SubmissionResult<ChunkedType> => {
|
|
146
|
+
const validation = validateSubmission(instanceRoot);
|
|
147
|
+
const definition = instanceRoot.definition.submission;
|
|
148
|
+
const instanceFile = new InstanceFile(instanceRoot);
|
|
149
|
+
const attachments: readonly File[] = [];
|
|
150
|
+
|
|
151
|
+
switch (options.chunked) {
|
|
152
|
+
case 'chunked':
|
|
153
|
+
return chunkedSubmissionResult(
|
|
154
|
+
validation,
|
|
155
|
+
definition,
|
|
156
|
+
instanceFile,
|
|
157
|
+
attachments,
|
|
158
|
+
options
|
|
159
|
+
) satisfies SubmissionResult<'chunked'> as SubmissionResult<ChunkedType>;
|
|
160
|
+
|
|
161
|
+
case 'monolithic':
|
|
162
|
+
return monolithicSubmissionResult(
|
|
163
|
+
validation,
|
|
164
|
+
definition,
|
|
165
|
+
instanceFile,
|
|
166
|
+
attachments
|
|
167
|
+
) satisfies SubmissionResult<'monolithic'> as SubmissionResult<ChunkedType>;
|
|
168
|
+
|
|
169
|
+
default:
|
|
170
|
+
throw new UnreachableError(options.chunked);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ValueCodec } from './ValueCodec.ts';
|
|
2
|
+
|
|
3
|
+
export type DecimalInputValue = bigint | number | string | null;
|
|
4
|
+
|
|
5
|
+
const encodeDecimal = (value: DecimalInputValue): string => {
|
|
6
|
+
if (value == null) {
|
|
7
|
+
return '';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (typeof value === 'string') {
|
|
11
|
+
decodeDecimal(value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return String(value);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type DecimalRuntimeValue = number | null;
|
|
18
|
+
|
|
19
|
+
const decodeDecimal = (value: string): DecimalRuntimeValue => {
|
|
20
|
+
if (value === '') {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const decoded = Number(value);
|
|
25
|
+
|
|
26
|
+
if (
|
|
27
|
+
// NaN is not a decimal value!
|
|
28
|
+
Number.isNaN(decoded) ||
|
|
29
|
+
// Infinity is not a decimal value!
|
|
30
|
+
!Number.isFinite(decoded)
|
|
31
|
+
) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return decoded;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export class DecimalValueCodec extends ValueCodec<
|
|
39
|
+
'decimal',
|
|
40
|
+
DecimalRuntimeValue,
|
|
41
|
+
DecimalInputValue
|
|
42
|
+
> {
|
|
43
|
+
constructor() {
|
|
44
|
+
super('decimal', encodeDecimal, decodeDecimal);
|
|
45
|
+
}
|
|
46
|
+
}
|