@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,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This abstract class defines the minimal behavior for a default geopoint.
|
|
3
|
+
* It can be expanded later to support units (e.g., degrees or meters),
|
|
4
|
+
* which would also serve as documentation to clarify what each value represents.
|
|
5
|
+
*/
|
|
6
|
+
abstract class SemanticValue<Semantic extends string, Value extends number | null> {
|
|
7
|
+
abstract readonly semantic: Semantic;
|
|
8
|
+
|
|
9
|
+
constructor(readonly value: Value) {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class Latitude extends SemanticValue<'latitude', number> {
|
|
13
|
+
readonly semantic = 'latitude';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
class Longitude extends SemanticValue<'longitude', number> {
|
|
17
|
+
readonly semantic = 'longitude';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
class Altitude<Value extends number | null = number> extends SemanticValue<'altitude', Value> {
|
|
21
|
+
readonly semantic = 'altitude';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class Accuracy<Value extends number | null = number> extends SemanticValue<'accuracy', Value> {
|
|
25
|
+
readonly semantic = 'accuracy';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface GeopointValue {
|
|
29
|
+
readonly latitude: number;
|
|
30
|
+
readonly longitude: number;
|
|
31
|
+
readonly altitude: number | null;
|
|
32
|
+
readonly accuracy: number | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type GeopointRuntimeValue = GeopointValue | null;
|
|
36
|
+
|
|
37
|
+
// TODO: Add support for GeoJSONValue
|
|
38
|
+
export type GeopointInputValue = GeopointRuntimeValue | string;
|
|
39
|
+
|
|
40
|
+
interface GeopointInternalValue {
|
|
41
|
+
readonly latitude: Latitude;
|
|
42
|
+
readonly longitude: Longitude;
|
|
43
|
+
readonly altitude: Altitude<null> | Altitude<number>;
|
|
44
|
+
readonly accuracy: Accuracy<null> | Accuracy<number>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type GeopointTuple =
|
|
48
|
+
| readonly [
|
|
49
|
+
latitude: Latitude,
|
|
50
|
+
longitude: Longitude,
|
|
51
|
+
altitude: Altitude<null> | Altitude<number>,
|
|
52
|
+
accuracy: Accuracy,
|
|
53
|
+
]
|
|
54
|
+
| readonly [latitude: Latitude, longitude: Longitude, altitude: Altitude]
|
|
55
|
+
| readonly [latitude: Latitude, longitude: Longitude];
|
|
56
|
+
|
|
57
|
+
const DEGREES_MAX = {
|
|
58
|
+
latitude: 90,
|
|
59
|
+
longitude: 180,
|
|
60
|
+
} as const;
|
|
61
|
+
|
|
62
|
+
type CoordinateType = keyof typeof DEGREES_MAX;
|
|
63
|
+
|
|
64
|
+
export class Geopoint {
|
|
65
|
+
private readonly internalValue: GeopointInternalValue;
|
|
66
|
+
|
|
67
|
+
constructor(coordinates: GeopointValue) {
|
|
68
|
+
const { latitude, longitude, altitude, accuracy } = coordinates;
|
|
69
|
+
|
|
70
|
+
this.internalValue = {
|
|
71
|
+
latitude: new Latitude(latitude),
|
|
72
|
+
longitude: new Longitude(longitude),
|
|
73
|
+
altitude: this.isValidNumber(altitude) ? new Altitude(altitude) : new Altitude(null),
|
|
74
|
+
accuracy: this.isValidNumber(accuracy) ? new Accuracy(accuracy) : new Accuracy(null),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getTuple(): GeopointTuple {
|
|
79
|
+
const { latitude, longitude, altitude, accuracy } = this.internalValue;
|
|
80
|
+
|
|
81
|
+
if (accuracy.value != null) {
|
|
82
|
+
return [latitude, longitude, altitude, accuracy];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (altitude.value != null) {
|
|
86
|
+
return [latitude, longitude, altitude];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return [latitude, longitude];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
getRuntimeValue(): GeopointRuntimeValue {
|
|
93
|
+
const { latitude, longitude, altitude, accuracy } = this.internalValue;
|
|
94
|
+
const isLatitude = this.isValidDegrees('latitude', latitude.value);
|
|
95
|
+
const isLongitude = this.isValidDegrees('longitude', longitude.value);
|
|
96
|
+
|
|
97
|
+
if (!isLatitude || !isLongitude || Geopoint.isNullLocation(latitude.value, longitude.value)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
latitude: latitude.value,
|
|
103
|
+
longitude: longitude.value,
|
|
104
|
+
altitude: altitude.value,
|
|
105
|
+
accuracy: accuracy.value,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private isValidDegrees(coordinate: CoordinateType, degrees: number): degrees is number {
|
|
110
|
+
return this.isValidNumber(degrees) && Math.abs(degrees) <= DEGREES_MAX[coordinate];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private isValidNumber(value: number | null | undefined) {
|
|
114
|
+
return value != null && !Number.isNaN(value);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
private static isNullLocation(latitude: number, longitude: number) {
|
|
118
|
+
return latitude === 0 && longitude === 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static parseString(value: string): GeopointRuntimeValue {
|
|
122
|
+
if (value.trim() === '') {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const [latitude, longitude, altitude = null, accuracy = null] = value.split(/\s+/).map(Number);
|
|
127
|
+
|
|
128
|
+
if (latitude == null || longitude == null || Number.isNaN(altitude) || Number.isNaN(accuracy)) {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return new this({ latitude, longitude, altitude, accuracy }).getRuntimeValue();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static toCoordinatesString(value: GeopointInputValue): string {
|
|
136
|
+
const decodedValue = typeof value === 'string' ? Geopoint.parseString(value) : value;
|
|
137
|
+
|
|
138
|
+
if (
|
|
139
|
+
decodedValue == null ||
|
|
140
|
+
Geopoint.isNullLocation(decodedValue.latitude, decodedValue.longitude)
|
|
141
|
+
) {
|
|
142
|
+
return '';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return new this(decodedValue)
|
|
146
|
+
.getTuple()
|
|
147
|
+
.map((item) => item.value ?? 0)
|
|
148
|
+
.join(' ');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type CodecDecoder, type CodecEncoder, ValueCodec } from '../ValueCodec.ts';
|
|
2
|
+
import { Geopoint, type GeopointInputValue, type GeopointRuntimeValue } from './Geopoint.ts';
|
|
3
|
+
|
|
4
|
+
export class GeopointValueCodec extends ValueCodec<
|
|
5
|
+
'geopoint',
|
|
6
|
+
GeopointRuntimeValue,
|
|
7
|
+
GeopointInputValue
|
|
8
|
+
> {
|
|
9
|
+
constructor() {
|
|
10
|
+
const encodeValue: CodecEncoder<GeopointInputValue> = (value) => {
|
|
11
|
+
return Geopoint.toCoordinatesString(value);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const decodeValue: CodecDecoder<GeopointRuntimeValue> = (value: string) => {
|
|
15
|
+
return Geopoint.parseString(value);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
super('geopoint', encodeValue, decodeValue);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ValueTypeInvariantError } from '../../error/ValueTypeInvariantError.ts';
|
|
2
|
+
import { ValueCodec } from './ValueCodec.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Per {@link https://getodk.github.io/xforms-spec/#data-type:int}, which
|
|
6
|
+
* specifies "as in {@link https://www.w3.org/TR/xmlschema-2/#int | XML 1.0}":
|
|
7
|
+
*
|
|
8
|
+
* > int is ·derived· from long by setting the value of ·maxInclusive· to be
|
|
9
|
+
* > 2147483647 and ·minInclusive· to be -2147483648.
|
|
10
|
+
*/
|
|
11
|
+
const INT_BOUNDS = {
|
|
12
|
+
MIN: -2_147_483_648n,
|
|
13
|
+
MAX: 2_147_483_647n,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const assertIntBounds = <T extends bigint | null>(value: T): T => {
|
|
17
|
+
if (value == null) {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (value < INT_BOUNDS.MIN || value > INT_BOUNDS.MAX) {
|
|
22
|
+
throw new ValueTypeInvariantError(
|
|
23
|
+
'int',
|
|
24
|
+
`Unable to decode int value from ${String(value)}: expected value to be between ${INT_BOUNDS.MIN} and ${INT_BOUNDS.MAX} (inclusive)`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const boundedInt = (value: bigint | number): bigint => {
|
|
32
|
+
const result = BigInt(value);
|
|
33
|
+
|
|
34
|
+
assertIntBounds(result);
|
|
35
|
+
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type IntInputValue = bigint | number | string | null;
|
|
40
|
+
|
|
41
|
+
const numberToInt = (value: number): bigint | null => {
|
|
42
|
+
if (!Number.isFinite(value)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return boundedInt(Math.trunc(value));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const encodeInt = (value: IntInputValue): string => {
|
|
50
|
+
let intValue: bigint | null;
|
|
51
|
+
|
|
52
|
+
switch (typeof value) {
|
|
53
|
+
case 'object':
|
|
54
|
+
value satisfies null;
|
|
55
|
+
intValue = null;
|
|
56
|
+
break;
|
|
57
|
+
|
|
58
|
+
case 'number':
|
|
59
|
+
intValue = numberToInt(value);
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case 'string':
|
|
63
|
+
intValue = decodeInt(value);
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
default:
|
|
67
|
+
value satisfies bigint;
|
|
68
|
+
|
|
69
|
+
intValue = boundedInt(value);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (intValue == null) {
|
|
73
|
+
return '';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return String(intValue);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type IntRuntimeValue = bigint | null;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Note: Collect/JavaRosa trim decimal values (i.e. round closest to zero). We
|
|
83
|
+
* do the same.
|
|
84
|
+
*
|
|
85
|
+
* @todo Note that we enforce bounds **after** rounding, which may not be quite
|
|
86
|
+
* right! Look at actual Collect/JR implementation to align.
|
|
87
|
+
*/
|
|
88
|
+
const decodeInt = (value: string): IntRuntimeValue => {
|
|
89
|
+
if (value === '') {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return numberToInt(Number(value));
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export class IntValueCodec extends ValueCodec<'int', IntRuntimeValue, IntInputValue> {
|
|
97
|
+
constructor() {
|
|
98
|
+
super('int', encodeInt, decodeInt);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ValueType } from '../../client/ValueType.ts';
|
|
2
|
+
import type { RuntimeInputValue, RuntimeValue, SharedValueCodec } from './getSharedValueCodec.ts';
|
|
3
|
+
import { ValueCodec } from './ValueCodec.ts';
|
|
4
|
+
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
export type NoteRuntimeValue<V extends ValueType> =
|
|
7
|
+
| RuntimeValue<V>
|
|
8
|
+
| null;
|
|
9
|
+
|
|
10
|
+
// prettier-ignore
|
|
11
|
+
export type NoteInputValue<V extends ValueType> =
|
|
12
|
+
| RuntimeInputValue<V>
|
|
13
|
+
| RuntimeValue<V>
|
|
14
|
+
| null;
|
|
15
|
+
|
|
16
|
+
export class NoteCodec<V extends ValueType> extends ValueCodec<
|
|
17
|
+
V,
|
|
18
|
+
NoteRuntimeValue<V>,
|
|
19
|
+
NoteInputValue<V>
|
|
20
|
+
> {
|
|
21
|
+
constructor(baseCodec: SharedValueCodec<V>) {
|
|
22
|
+
const encodeValue = (value: NoteInputValue<V>): string => {
|
|
23
|
+
return baseCodec.encodeValue(value ?? '');
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const decodeValue = (value: string): NoteRuntimeValue<V> => {
|
|
27
|
+
return value === '' ? null : baseCodec.decodeValue(value);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
super(baseCodec.valueType, encodeValue, decodeValue);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { RangeValue } from '../../client/RangeNode.ts';
|
|
2
|
+
import { ValueTypeInvariantError } from '../../error/ValueTypeInvariantError.ts';
|
|
3
|
+
import type { RangeNodeDefinition, RangeValueType } from '../../parse/model/RangeNodeDefinition.ts';
|
|
4
|
+
import type { RuntimeInputValue, RuntimeValue, SharedValueCodec } from './getSharedValueCodec.ts';
|
|
5
|
+
import { ValueCodec } from './ValueCodec.ts';
|
|
6
|
+
|
|
7
|
+
export type RangeRuntimeValue<V extends RangeValueType> = RuntimeValue<V>;
|
|
8
|
+
|
|
9
|
+
export type RangeInputValue<V extends RangeValueType> = RuntimeInputValue<V>;
|
|
10
|
+
|
|
11
|
+
export class RangeCodec<V extends RangeValueType> extends ValueCodec<
|
|
12
|
+
V,
|
|
13
|
+
RangeRuntimeValue<V>,
|
|
14
|
+
RangeInputValue<V>
|
|
15
|
+
> {
|
|
16
|
+
constructor(baseCodec: SharedValueCodec<V>, definition: RangeNodeDefinition<V>) {
|
|
17
|
+
const { valueType, bounds } = definition;
|
|
18
|
+
const { min, max } = bounds;
|
|
19
|
+
|
|
20
|
+
type ComparableRangeValue = bigint | number | null;
|
|
21
|
+
|
|
22
|
+
const toComparableValue = (value: RangeInputValue<V>): ComparableRangeValue => {
|
|
23
|
+
if (value == null) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof value === 'string') {
|
|
28
|
+
return baseCodec.decodeValue(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const assertBounds = (value: RuntimeInputValue<V>) => {
|
|
35
|
+
const comparableValue = toComparableValue(value);
|
|
36
|
+
|
|
37
|
+
if (comparableValue == null) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (comparableValue < min || comparableValue > max) {
|
|
42
|
+
throw new ValueTypeInvariantError(
|
|
43
|
+
valueType,
|
|
44
|
+
`Expected value to be within bounds [${min}, ${max}]. Got: ${value}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const encodeValue = (value: RangeInputValue<V>): string => {
|
|
50
|
+
assertBounds(value);
|
|
51
|
+
|
|
52
|
+
return baseCodec.encodeValue(value);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const decodeValue = (value: string): RangeValue<V> => {
|
|
56
|
+
const decoded = baseCodec.decodeValue(value);
|
|
57
|
+
|
|
58
|
+
assertBounds(value);
|
|
59
|
+
|
|
60
|
+
return decoded;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
super(valueType, encodeValue, decodeValue);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { identity } from '@getodk/common/lib/identity.ts';
|
|
2
|
+
import { ValueCodec } from './ValueCodec.ts';
|
|
3
|
+
|
|
4
|
+
export class StringValueCodec extends ValueCodec<'string', string, string> {
|
|
5
|
+
constructor() {
|
|
6
|
+
super('string', identity, identity, {
|
|
7
|
+
decodeInstanceValueFactory: () => identity,
|
|
8
|
+
runtimeValueStateFactory: () => identity,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { UnreachableError } from '@getodk/common/lib/error/UnreachableError.ts';
|
|
2
|
+
import { ErrorProductionDesignPendingError } from '../../error/ErrorProductionDesignPendingError.ts';
|
|
3
|
+
import { ValueCodec } from './ValueCodec.ts';
|
|
4
|
+
|
|
5
|
+
export type TriggerValueType = 'string';
|
|
6
|
+
|
|
7
|
+
export type TriggerRuntimeValue = boolean;
|
|
8
|
+
|
|
9
|
+
export type TriggerInputValue = boolean | '' | null;
|
|
10
|
+
|
|
11
|
+
type BaseTriggerInstanceValueMapping = Readonly<Record<string, string>>;
|
|
12
|
+
|
|
13
|
+
const TRIGGER_INSTANCE_VALUES = {
|
|
14
|
+
true: 'OK',
|
|
15
|
+
false: '',
|
|
16
|
+
} as const satisfies BaseTriggerInstanceValueMapping;
|
|
17
|
+
|
|
18
|
+
type TriggerInstanceValueMapping = typeof TRIGGER_INSTANCE_VALUES;
|
|
19
|
+
|
|
20
|
+
type TriggerInstanceValue = TriggerInstanceValueMapping[keyof TriggerInstanceValueMapping];
|
|
21
|
+
|
|
22
|
+
const encodeTriggerValue = (value: TriggerInputValue): TriggerInstanceValue => {
|
|
23
|
+
switch (value) {
|
|
24
|
+
case true:
|
|
25
|
+
return TRIGGER_INSTANCE_VALUES.true;
|
|
26
|
+
|
|
27
|
+
case false:
|
|
28
|
+
case '':
|
|
29
|
+
case null:
|
|
30
|
+
return TRIGGER_INSTANCE_VALUES.false;
|
|
31
|
+
|
|
32
|
+
default:
|
|
33
|
+
throw new UnreachableError(value);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const decodeTriggerValue = (value: string): TriggerRuntimeValue => {
|
|
38
|
+
if (value === 'OK') {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (value === '') {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (value.toLowerCase() === 'ok') {
|
|
47
|
+
// eslint-disable-next-line no-console
|
|
48
|
+
console.warn('Treating trigger value as case-insensitive:', value);
|
|
49
|
+
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
throw new ErrorProductionDesignPendingError(`Unexpected trigger value: ${value}`);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export class TriggerCodec extends ValueCodec<
|
|
57
|
+
TriggerValueType,
|
|
58
|
+
TriggerRuntimeValue,
|
|
59
|
+
TriggerInputValue
|
|
60
|
+
> {
|
|
61
|
+
constructor() {
|
|
62
|
+
super('string', encodeTriggerValue, decodeTriggerValue);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ValueType } from '../../client/ValueType.ts';
|
|
2
|
+
import { ErrorProductionDesignPendingError } from '../../error/ErrorProductionDesignPendingError.ts';
|
|
3
|
+
import type { RuntimeValue, SharedValueCodec } from './getSharedValueCodec.ts';
|
|
4
|
+
import type { CodecDecoder, CodecEncoder } from './ValueCodec.ts';
|
|
5
|
+
import { ValueCodec } from './ValueCodec.ts';
|
|
6
|
+
|
|
7
|
+
export type SplitInstanceValues = (value: string) => readonly string[];
|
|
8
|
+
|
|
9
|
+
export type JoinInstnaceValues = (values: readonly string[]) => string;
|
|
10
|
+
|
|
11
|
+
export type RuntimeItemValue<V extends ValueType> = NonNullable<RuntimeValue<V>>;
|
|
12
|
+
|
|
13
|
+
export type RuntimeValues<V extends ValueType> = ReadonlyArray<RuntimeItemValue<V>>;
|
|
14
|
+
|
|
15
|
+
export abstract class ValueArrayCodec<
|
|
16
|
+
V extends ValueType,
|
|
17
|
+
Values extends RuntimeValues<V> = RuntimeValues<V>,
|
|
18
|
+
> extends ValueCodec<V, Values, Values> {
|
|
19
|
+
readonly decodeItemValue: CodecDecoder<RuntimeItemValue<V>>;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
baseCodec: SharedValueCodec<V>,
|
|
23
|
+
encodeValue: CodecEncoder<Values>,
|
|
24
|
+
decodeValue: CodecDecoder<Values>
|
|
25
|
+
) {
|
|
26
|
+
const decodeItemValue: CodecDecoder<RuntimeItemValue<V>> = (value) => {
|
|
27
|
+
const decoded = baseCodec.decodeValue(value);
|
|
28
|
+
|
|
29
|
+
if (decoded == null) {
|
|
30
|
+
throw new ErrorProductionDesignPendingError(
|
|
31
|
+
`Failed to decode item value: ${JSON.stringify(value)}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return decoded;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
super(baseCodec.valueType, encodeValue, decodeValue);
|
|
39
|
+
|
|
40
|
+
this.decodeItemValue = decodeItemValue;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Accessor } from 'solid-js';
|
|
2
|
+
import type { ValueType } from '../../client/ValueType.ts';
|
|
3
|
+
import type { DecodeInstanceValue } from '../../instance/internal-api/InstanceValueContext.ts';
|
|
4
|
+
import type { SimpleAtomicState } from '../reactivity/types.ts';
|
|
5
|
+
|
|
6
|
+
export type CodecEncoder<RuntimeInputValue> = (input: RuntimeInputValue) => string;
|
|
7
|
+
|
|
8
|
+
export type CodecDecoder<RuntimeValue> = (value: string) => RuntimeValue;
|
|
9
|
+
|
|
10
|
+
type RuntimeValueAccessor<RuntimeValue> = Accessor<RuntimeValue>;
|
|
11
|
+
|
|
12
|
+
export type RuntimeValueSetter<
|
|
13
|
+
RuntimeValue extends RuntimeInputValue,
|
|
14
|
+
RuntimeInputValue = RuntimeValue,
|
|
15
|
+
> = (input: RuntimeInputValue) => RuntimeValue;
|
|
16
|
+
|
|
17
|
+
export type RuntimeValueState<
|
|
18
|
+
RuntimeValue extends RuntimeInputValue,
|
|
19
|
+
RuntimeInputValue = RuntimeValue,
|
|
20
|
+
> = readonly [
|
|
21
|
+
get: RuntimeValueAccessor<RuntimeValue>,
|
|
22
|
+
set: RuntimeValueSetter<RuntimeValue, RuntimeInputValue>,
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export type CreateRuntimeValueState<
|
|
26
|
+
RuntimeValue extends RuntimeInputValue,
|
|
27
|
+
RuntimeInputValue = RuntimeValue,
|
|
28
|
+
> = (
|
|
29
|
+
instanceState: SimpleAtomicState<string>
|
|
30
|
+
) => RuntimeValueState<RuntimeValue, RuntimeInputValue>;
|
|
31
|
+
|
|
32
|
+
type RuntimeValueStateFactory<
|
|
33
|
+
RuntimeValue extends RuntimeInputValue,
|
|
34
|
+
RuntimeInputValue = RuntimeValue,
|
|
35
|
+
> = (
|
|
36
|
+
encodeValue: CodecEncoder<RuntimeInputValue>,
|
|
37
|
+
decodeValue: CodecDecoder<RuntimeValue>
|
|
38
|
+
) => CreateRuntimeValueState<RuntimeValue, RuntimeInputValue>;
|
|
39
|
+
|
|
40
|
+
type DecodeInstanceValueFactory<
|
|
41
|
+
RuntimeValue extends RuntimeInputValue,
|
|
42
|
+
RuntimeInputValue = RuntimeValue,
|
|
43
|
+
> = (
|
|
44
|
+
encodeValue: CodecEncoder<RuntimeInputValue>,
|
|
45
|
+
decodeValue: CodecDecoder<RuntimeValue>
|
|
46
|
+
) => DecodeInstanceValue;
|
|
47
|
+
|
|
48
|
+
interface ValueCodecOptions<RuntimeValue extends RuntimeInputValue, RuntimeInputValue> {
|
|
49
|
+
readonly decodeInstanceValueFactory?: DecodeInstanceValueFactory<RuntimeValue, RuntimeInputValue>;
|
|
50
|
+
readonly runtimeValueStateFactory?: RuntimeValueStateFactory<RuntimeValue, RuntimeInputValue>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export abstract class ValueCodec<
|
|
54
|
+
V extends ValueType,
|
|
55
|
+
RuntimeValue extends RuntimeInputValue,
|
|
56
|
+
RuntimeInputValue = RuntimeValue,
|
|
57
|
+
> {
|
|
58
|
+
protected readonly defaultRuntimeValueStateFactory: RuntimeValueStateFactory<
|
|
59
|
+
RuntimeValue,
|
|
60
|
+
RuntimeInputValue
|
|
61
|
+
> = (encodeValue, decodeValue) => {
|
|
62
|
+
return (instanceState) => {
|
|
63
|
+
const [getInstanceValue, setInstanceValue] = instanceState;
|
|
64
|
+
|
|
65
|
+
const getValue = (): RuntimeValue => {
|
|
66
|
+
return decodeValue(getInstanceValue());
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const setValue = (runtimeValue: RuntimeInputValue): RuntimeValue => {
|
|
70
|
+
const encodedValue = encodeValue(runtimeValue);
|
|
71
|
+
const persistedValue = setInstanceValue(encodedValue);
|
|
72
|
+
|
|
73
|
+
return decodeValue(persistedValue);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return [getValue, setValue];
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
protected readonly defaultDecodeInstanceValueFactory: DecodeInstanceValueFactory<
|
|
81
|
+
RuntimeValue,
|
|
82
|
+
RuntimeInputValue
|
|
83
|
+
> = (encodeValue, decodeValue) => {
|
|
84
|
+
return (instanceValue) => {
|
|
85
|
+
return encodeValue(decodeValue(instanceValue));
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
readonly decodeInstanceValue: DecodeInstanceValue;
|
|
90
|
+
readonly createRuntimeValueState: CreateRuntimeValueState<RuntimeValue, RuntimeInputValue>;
|
|
91
|
+
|
|
92
|
+
constructor(
|
|
93
|
+
readonly valueType: V,
|
|
94
|
+
readonly encodeValue: CodecEncoder<RuntimeInputValue>,
|
|
95
|
+
readonly decodeValue: CodecDecoder<RuntimeValue>,
|
|
96
|
+
options: ValueCodecOptions<RuntimeValue, RuntimeInputValue> = {}
|
|
97
|
+
) {
|
|
98
|
+
const {
|
|
99
|
+
decodeInstanceValueFactory = this.defaultDecodeInstanceValueFactory,
|
|
100
|
+
runtimeValueStateFactory = this.defaultRuntimeValueStateFactory,
|
|
101
|
+
} = options;
|
|
102
|
+
|
|
103
|
+
this.decodeInstanceValue = decodeInstanceValueFactory(encodeValue, decodeValue);
|
|
104
|
+
this.createRuntimeValueState = runtimeValueStateFactory(encodeValue, decodeValue);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { identity } from '@getodk/common/lib/identity.ts';
|
|
2
|
+
import type { ValueType } from '../../client/ValueType.ts';
|
|
3
|
+
import { ValueCodec } from './ValueCodec.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provides fallback functionality where a {@link ValueCodec} is expected, for
|
|
7
|
+
* those {@link ValueType | value types} which are still pending implementation.
|
|
8
|
+
* This allows consistent use of the {@link ValueCodec} interface while
|
|
9
|
+
* maintaining the current behavior of treating those unimplemented value types
|
|
10
|
+
* as string values.
|
|
11
|
+
*/
|
|
12
|
+
export class ValueTypePlaceholderCodec<V extends ValueType> extends ValueCodec<V, string, string> {
|
|
13
|
+
constructor(valueType: V) {
|
|
14
|
+
super(valueType, identity, identity, {
|
|
15
|
+
decodeInstanceValueFactory: () => identity,
|
|
16
|
+
runtimeValueStateFactory: () => identity,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ValueType } from '../../client/ValueType.ts';
|
|
2
|
+
import { sharedValueCodecs } from './getSharedValueCodec.ts';
|
|
3
|
+
import { NoteCodec } from './NoteCodec.ts';
|
|
4
|
+
|
|
5
|
+
type NoteCodecs = {
|
|
6
|
+
readonly [V in ValueType]: NoteCodec<V>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const noteCodecs: NoteCodecs = {
|
|
10
|
+
string: new NoteCodec(sharedValueCodecs.string),
|
|
11
|
+
int: new NoteCodec(sharedValueCodecs.int),
|
|
12
|
+
decimal: new NoteCodec(sharedValueCodecs.decimal),
|
|
13
|
+
boolean: new NoteCodec(sharedValueCodecs.boolean),
|
|
14
|
+
date: new NoteCodec(sharedValueCodecs.date),
|
|
15
|
+
time: new NoteCodec(sharedValueCodecs.time),
|
|
16
|
+
dateTime: new NoteCodec(sharedValueCodecs.dateTime),
|
|
17
|
+
geopoint: new NoteCodec(sharedValueCodecs.geopoint),
|
|
18
|
+
geotrace: new NoteCodec(sharedValueCodecs.geotrace),
|
|
19
|
+
geoshape: new NoteCodec(sharedValueCodecs.geoshape),
|
|
20
|
+
binary: new NoteCodec(sharedValueCodecs.binary),
|
|
21
|
+
barcode: new NoteCodec(sharedValueCodecs.barcode),
|
|
22
|
+
intent: new NoteCodec(sharedValueCodecs.intent),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const getNoteCodec = <V extends ValueType>(valueType: V): NoteCodec<V> => {
|
|
26
|
+
return noteCodecs[valueType];
|
|
27
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { UnreachableError } from '@getodk/common/lib/error/UnreachableError.ts';
|
|
2
|
+
import type { SelectDefinition } from '../../client/SelectNode.ts';
|
|
3
|
+
import { sharedValueCodecs } from './getSharedValueCodec.ts';
|
|
4
|
+
import { MultipleValueItemCodec } from './items/MultipleValueItemCodec.ts';
|
|
5
|
+
import { SingleValueItemCodec } from './items/SingleValueItemCodec.ts';
|
|
6
|
+
|
|
7
|
+
const multipleValueSelectCodec = new MultipleValueItemCodec(sharedValueCodecs.string);
|
|
8
|
+
|
|
9
|
+
const singleValueSelectCodec = new SingleValueItemCodec(sharedValueCodecs.string);
|
|
10
|
+
|
|
11
|
+
// prettier-ignore
|
|
12
|
+
export type SelectCodec =
|
|
13
|
+
| MultipleValueItemCodec
|
|
14
|
+
| SingleValueItemCodec;
|
|
15
|
+
|
|
16
|
+
export const getSelectCodec = (definition: SelectDefinition<'string'>): SelectCodec => {
|
|
17
|
+
switch (definition.bodyElement.type) {
|
|
18
|
+
case 'select':
|
|
19
|
+
return multipleValueSelectCodec;
|
|
20
|
+
|
|
21
|
+
case 'select1':
|
|
22
|
+
return singleValueSelectCodec;
|
|
23
|
+
|
|
24
|
+
default:
|
|
25
|
+
throw new UnreachableError(definition.bodyElement.type);
|
|
26
|
+
}
|
|
27
|
+
};
|