@getodk/xforms-engine 0.5.0 → 0.7.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 +8 -4
- package/dist/client/BaseValueNode.d.ts +8 -4
- package/dist/client/GroupNode.d.ts +1 -0
- package/dist/client/InputNode.d.ts +32 -3
- package/dist/client/ModelValueNode.d.ts +1 -0
- package/dist/client/NoteNode.d.ts +24 -7
- package/dist/client/RangeNode.d.ts +36 -0
- package/dist/client/RankNode.d.ts +46 -0
- package/dist/client/RootNode.d.ts +21 -14
- 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/constants.d.ts +11 -12
- package/dist/client/form/CreateFormInstance.d.ts +14 -0
- package/dist/client/form/EditFormInstance.d.ts +62 -0
- package/dist/client/form/FormInstance.d.ts +104 -0
- package/dist/client/form/FormInstanceConfig.d.ts +17 -0
- package/dist/client/form/FormResource.d.ts +1 -0
- package/dist/client/form/LoadForm.d.ts +79 -0
- package/dist/client/form/LoadFormResult.d.ts +67 -0
- package/dist/client/form/RestoreFormInstance.d.ts +8 -0
- package/dist/client/hierarchy.d.ts +5 -5
- package/dist/client/index.d.ts +37 -11
- package/dist/client/node-types.d.ts +2 -2
- package/dist/client/repeat/BaseRepeatRangeNode.d.ts +3 -4
- package/dist/client/repeat/RepeatInstanceNode.d.ts +4 -5
- package/dist/client/repeat/RepeatRangeControlledNode.d.ts +2 -2
- package/dist/client/repeat/RepeatRangeUncontrolledNode.d.ts +2 -2
- package/dist/client/resources.d.ts +1 -1
- package/dist/client/serialization/InstanceData.d.ts +12 -0
- package/dist/client/serialization/InstanceFile.d.ts +6 -0
- package/dist/client/serialization/InstancePayload.d.ts +93 -0
- package/dist/client/serialization/InstancePayloadOptions.d.ts +23 -0
- package/dist/client/serialization/InstanceState.d.ts +12 -0
- package/dist/client/submission/{SubmissionDefinition.d.ts → SubmissionMeta.d.ts} +1 -1
- package/dist/client/unsupported/UnsupportedControlNode.d.ts +1 -3
- package/dist/entrypoints/FormInstance.d.ts +20 -0
- package/dist/entrypoints/FormResult/BaseFormResult.d.ts +22 -0
- package/dist/entrypoints/FormResult/BaseInstantiableFormResult.d.ts +25 -0
- package/dist/entrypoints/FormResult/FormFailureResult.d.ts +17 -0
- package/dist/entrypoints/FormResult/FormSuccessResult.d.ts +15 -0
- package/dist/entrypoints/FormResult/FormWarningResult.d.ts +15 -0
- package/dist/entrypoints/createInstance.d.ts +9 -0
- package/dist/entrypoints/editInstance.d.ts +9 -0
- package/dist/entrypoints/index.d.ts +4 -0
- package/dist/entrypoints/loadForm.d.ts +4 -0
- package/dist/entrypoints/restoreInstance.d.ts +9 -0
- package/dist/error/LoadFormFailureError.d.ts +9 -0
- package/dist/error/MalformedInstanceDataError.d.ts +3 -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/TemplatedNodeAttributeSerializationError.d.ts +22 -0
- package/dist/error/XFormsSpecViolationError.d.ts +2 -0
- package/dist/index.d.ts +2 -34
- package/dist/index.js +7274 -5840
- package/dist/index.js.map +1 -1
- package/dist/instance/Group.d.ts +7 -5
- package/dist/instance/InputControl.d.ts +9 -6
- package/dist/instance/ModelValue.d.ts +7 -4
- package/dist/instance/Note.d.ts +14 -25
- package/dist/instance/PrimaryInstance.d.ts +36 -8
- package/dist/instance/RangeControl.d.ts +35 -0
- package/dist/instance/RankControl.d.ts +41 -0
- package/dist/instance/Root.d.ts +8 -9
- package/dist/instance/SelectControl.d.ts +67 -0
- package/dist/instance/Subtree.d.ts +7 -5
- package/dist/instance/TriggerControl.d.ts +10 -22
- package/dist/instance/abstract/DescendantNode.d.ts +11 -3
- package/dist/instance/abstract/InstanceNode.d.ts +10 -5
- package/dist/instance/abstract/ValueNode.d.ts +7 -6
- package/dist/instance/children/DescendantNodeInitOptions.d.ts +32 -0
- package/dist/instance/{children.d.ts → children/buildChildren.d.ts} +1 -1
- package/dist/instance/children/childrenInitOptions.d.ts +9 -0
- package/dist/instance/children/normalizeChildInitOptions.d.ts +2 -0
- package/dist/instance/hierarchy.d.ts +9 -9
- package/dist/instance/input/InitialInstanceState.d.ts +13 -0
- package/dist/instance/input/InstanceAttachmentMap.d.ts +19 -0
- package/dist/instance/internal-api/InstanceConfig.d.ts +2 -9
- package/dist/instance/internal-api/InstanceValueContext.d.ts +10 -1
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableInstance.d.ts +14 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableLeafNode.d.ts +32 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableParentNode.d.ts +18 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.d.ts +13 -0
- package/dist/instance/internal-api/serialization/ClientReactiveSerializableValueNode.d.ts +21 -0
- package/dist/instance/repeat/BaseRepeatRange.d.ts +11 -8
- package/dist/instance/repeat/RepeatInstance.d.ts +11 -7
- package/dist/instance/repeat/RepeatRangeControlled.d.ts +27 -3
- package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +4 -3
- package/dist/instance/resource.d.ts +5 -1
- package/dist/instance/unsupported/UploadControl.d.ts +32 -4
- package/dist/integration/xpath/EngineXPathEvaluator.d.ts +2 -2
- package/dist/integration/xpath/adapter/kind.d.ts +4 -10
- package/dist/integration/xpath/adapter/names.d.ts +1 -11
- package/dist/integration/xpath/adapter/traversal.d.ts +10 -9
- package/dist/integration/xpath/static-dom/StaticAttribute.d.ts +10 -4
- package/dist/integration/xpath/static-dom/StaticDocument.d.ts +13 -11
- package/dist/integration/xpath/static-dom/StaticElement.d.ts +25 -18
- package/dist/integration/xpath/static-dom/StaticNode.d.ts +1 -1
- package/dist/integration/xpath/static-dom/StaticParentNode.d.ts +13 -0
- package/dist/integration/xpath/static-dom/staticNodeName.d.ts +3 -0
- package/dist/lib/client-reactivity/instance-state/createNodeRangeInstanceState.d.ts +4 -0
- package/dist/lib/client-reactivity/instance-state/createParentNodeInstanceState.d.ts +4 -0
- package/dist/lib/client-reactivity/instance-state/createPrimaryInstanceState.d.ts +3 -0
- package/dist/lib/client-reactivity/instance-state/createRootInstanceState.d.ts +3 -0
- package/dist/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.d.ts +6 -0
- package/dist/lib/client-reactivity/instance-state/createValueNodeInstanceState.d.ts +3 -0
- package/dist/lib/client-reactivity/instance-state/prepareInstancePayload.d.ts +8 -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/NoteCodec.d.ts +8 -0
- package/dist/lib/codecs/RangeCodec.d.ts +8 -0
- package/dist/lib/codecs/TempUnsupportedControlCodec.d.ts +7 -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 +2 -2
- 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 +3 -2
- 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 +1 -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/names/UnprefixedXFormsName.d.ts +4 -0
- package/dist/lib/number-parsers.d.ts +2 -0
- package/dist/lib/reactivity/createInstanceValueState.d.ts +2 -27
- package/dist/lib/reactivity/createItemCollection.d.ts +21 -0
- package/dist/lib/xml-serialization.d.ts +11 -2
- package/dist/parse/XFormDOM.d.ts +1 -1
- package/dist/parse/body/BodyDefinition.d.ts +2 -2
- package/dist/parse/body/appearance/rangeAppearanceParser.d.ts +3 -0
- package/dist/parse/body/control/InputControlDefinition.d.ts +3 -0
- 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/model/BindDefinition.d.ts +3 -1
- package/dist/parse/model/BindPreloadDefinition.d.ts +42 -0
- package/dist/parse/model/DescendentNodeDefinition.d.ts +4 -13
- package/dist/parse/model/ItextTranslationsDefinition.d.ts +18 -0
- package/dist/parse/model/LeafNodeDefinition.d.ts +9 -7
- package/dist/parse/model/ModelDefinition.d.ts +9 -2
- package/dist/parse/model/NodeDefinition.d.ts +30 -45
- package/dist/parse/model/NoteNodeDefinition.d.ts +7 -5
- package/dist/parse/model/RangeNodeDefinition.d.ts +42 -0
- package/dist/parse/model/RepeatDefinition.d.ts +62 -0
- package/dist/parse/model/RootAttributeDefinition.d.ts +21 -0
- package/dist/parse/model/RootAttributeMap.d.ts +24 -0
- package/dist/parse/model/RootDefinition.d.ts +15 -14
- package/dist/parse/model/SecondaryInstance/SecondaryInstancesDefinition.d.ts +15 -2
- package/dist/parse/model/SecondaryInstance/assertSecondaryInstanceDefinition.d.ts +5 -0
- package/dist/parse/model/SecondaryInstance/defineSecondaryInstance.d.ts +5 -0
- package/dist/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.d.ts +1 -7
- package/dist/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.d.ts +1 -1
- package/dist/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.d.ts +1 -1
- package/dist/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.d.ts +1 -1
- package/dist/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.d.ts +1 -1
- package/dist/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.d.ts +1 -1
- package/dist/parse/model/{FormSubmissionDefinition.d.ts → SubmissionDefinition.d.ts} +2 -2
- package/dist/parse/model/SubtreeDefinition.d.ts +9 -7
- package/dist/parse/model/nodeDefinitionMap.d.ts +5 -0
- package/dist/parse/shared/parseInstanceXML.d.ts +21 -0
- package/dist/parse/shared/parseStaticDocumentFromDOMSubtree.d.ts +4 -22
- 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/xpath/semantic-analysis.d.ts +1 -3
- package/dist/solid.js +7247 -5813
- package/dist/solid.js.map +1 -1
- package/package.json +15 -12
- package/src/client/BaseNode.ts +9 -4
- package/src/client/BaseValueNode.ts +8 -4
- package/src/client/GroupNode.ts +1 -0
- package/src/client/InputNode.ts +38 -2
- package/src/client/ModelValueNode.ts +1 -0
- package/src/client/NoteNode.ts +43 -7
- package/src/client/RangeNode.ts +51 -0
- package/src/client/RankNode.ts +54 -0
- package/src/client/RootNode.ts +30 -16
- package/src/client/SelectNode.ts +53 -26
- package/src/client/SubtreeNode.ts +1 -0
- package/src/client/TriggerNode.ts +12 -6
- package/src/client/constants.ts +12 -14
- package/src/client/form/CreateFormInstance.ts +19 -0
- package/src/client/form/EditFormInstance.ts +93 -0
- package/src/client/form/FormInstance.ts +114 -0
- package/src/client/form/FormInstanceConfig.ts +18 -0
- package/src/client/form/FormResource.ts +1 -0
- package/src/client/form/LoadForm.ts +92 -0
- package/src/client/form/LoadFormResult.ts +103 -0
- package/src/client/form/RestoreFormInstance.ts +14 -0
- package/src/client/hierarchy.ts +7 -8
- package/src/client/index.ts +47 -29
- package/src/client/node-types.ts +3 -5
- package/src/client/repeat/BaseRepeatRangeNode.ts +3 -4
- package/src/client/repeat/RepeatInstanceNode.ts +4 -8
- package/src/client/repeat/RepeatRangeControlledNode.ts +2 -2
- package/src/client/repeat/RepeatRangeUncontrolledNode.ts +2 -2
- package/src/client/resources.ts +2 -2
- package/src/client/serialization/InstanceData.ts +16 -0
- package/src/client/serialization/InstanceFile.ts +9 -0
- package/src/client/serialization/InstancePayload.ts +126 -0
- package/src/client/serialization/InstancePayloadOptions.ts +28 -0
- package/src/client/serialization/InstanceState.ts +14 -0
- package/src/client/submission/{SubmissionDefinition.ts → SubmissionMeta.ts} +1 -1
- package/src/client/unsupported/UnsupportedControlNode.ts +2 -6
- package/src/entrypoints/FormInstance.ts +55 -0
- package/src/entrypoints/FormResult/BaseFormResult.ts +40 -0
- package/src/entrypoints/FormResult/BaseInstantiableFormResult.ts +109 -0
- package/src/entrypoints/FormResult/FormFailureResult.ts +44 -0
- package/src/entrypoints/FormResult/FormSuccessResult.ts +25 -0
- package/src/entrypoints/FormResult/FormWarningResult.ts +25 -0
- package/src/entrypoints/createInstance.ts +23 -0
- package/src/entrypoints/editInstance.ts +24 -0
- package/src/entrypoints/index.ts +4 -0
- package/src/entrypoints/loadForm.ts +154 -0
- package/src/entrypoints/restoreInstance.ts +27 -0
- package/src/error/LoadFormFailureError.ts +114 -0
- package/src/error/MalformedInstanceDataError.ts +3 -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/TemplatedNodeAttributeSerializationError.ts +24 -0
- package/src/error/XFormsSpecViolationError.ts +1 -0
- package/src/index.ts +2 -56
- package/src/instance/Group.ts +17 -15
- package/src/instance/InputControl.ts +58 -12
- package/src/instance/ModelValue.ts +19 -11
- package/src/instance/Note.ts +40 -64
- package/src/instance/PrimaryInstance.ts +70 -31
- package/src/instance/RangeControl.ts +119 -0
- package/src/instance/RankControl.ts +208 -0
- package/src/instance/Root.ts +21 -31
- package/src/instance/SelectControl.ts +228 -0
- package/src/instance/Subtree.ts +17 -15
- package/src/instance/TriggerControl.ts +50 -80
- package/src/instance/abstract/DescendantNode.ts +13 -8
- package/src/instance/abstract/InstanceNode.ts +19 -7
- package/src/instance/abstract/ValueNode.ts +14 -15
- package/src/instance/children/DescendantNodeInitOptions.ts +35 -0
- package/src/instance/children/buildChildren.ts +206 -0
- package/src/instance/children/childrenInitOptions.ts +117 -0
- package/src/instance/children/normalizeChildInitOptions.ts +332 -0
- package/src/instance/hierarchy.ts +21 -16
- package/src/instance/input/InitialInstanceState.ts +108 -0
- package/src/instance/input/InstanceAttachmentMap.ts +142 -0
- package/src/instance/internal-api/InstanceConfig.ts +3 -10
- package/src/instance/internal-api/InstanceValueContext.ts +11 -1
- package/src/instance/internal-api/serialization/ClientReactiveSerializableInstance.ts +20 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableLeafNode.ts +43 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableParentNode.ts +26 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.ts +24 -0
- package/src/instance/internal-api/serialization/ClientReactiveSerializableValueNode.ts +28 -0
- package/src/instance/repeat/BaseRepeatRange.ts +21 -24
- package/src/instance/repeat/RepeatInstance.ts +27 -19
- package/src/instance/repeat/RepeatRangeControlled.ts +90 -17
- package/src/instance/repeat/RepeatRangeUncontrolled.ts +10 -9
- package/src/instance/resource.ts +18 -2
- package/src/instance/unsupported/UploadControl.ts +116 -5
- package/src/integration/xpath/EngineXPathEvaluator.ts +2 -2
- package/src/integration/xpath/adapter/kind.ts +1 -28
- package/src/integration/xpath/adapter/names.ts +66 -17
- package/src/integration/xpath/adapter/traversal.ts +12 -11
- package/src/integration/xpath/static-dom/StaticAttribute.ts +16 -7
- package/src/integration/xpath/static-dom/StaticDocument.ts +17 -18
- package/src/integration/xpath/static-dom/StaticElement.ts +211 -52
- package/src/integration/xpath/static-dom/StaticNode.ts +1 -1
- package/src/integration/xpath/static-dom/StaticParentNode.ts +22 -0
- package/src/integration/xpath/static-dom/staticNodeName.ts +20 -0
- package/src/lib/client-reactivity/instance-state/createNodeRangeInstanceState.ts +17 -0
- package/src/lib/client-reactivity/instance-state/createParentNodeInstanceState.ts +22 -0
- package/src/lib/client-reactivity/instance-state/createPrimaryInstanceState.ts +12 -0
- package/src/lib/client-reactivity/instance-state/createRootInstanceState.ts +19 -0
- package/src/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.ts +31 -0
- package/src/lib/client-reactivity/instance-state/createValueNodeInstanceState.ts +21 -0
- package/src/lib/client-reactivity/instance-state/prepareInstancePayload.ts +173 -0
- package/src/lib/codecs/Geopoint/Geopoint.ts +150 -0
- package/src/lib/codecs/Geopoint/GeopointValueCodec.ts +20 -0
- package/src/lib/codecs/NoteCodec.ts +32 -0
- package/src/lib/codecs/RangeCodec.ts +65 -0
- package/src/lib/codecs/TempUnsupportedControlCodec.ts +32 -0
- package/src/lib/codecs/TriggerCodec.ts +64 -0
- package/src/lib/codecs/ValueArrayCodec.ts +42 -0
- package/src/lib/codecs/ValueCodec.ts +2 -2
- package/src/lib/codecs/getNoteCodec.ts +27 -0
- package/src/lib/codecs/getSelectCodec.ts +27 -0
- package/src/lib/codecs/getSharedValueCodec.ts +5 -3
- 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 +1 -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/names/UnprefixedXFormsName.ts +12 -0
- package/src/lib/number-parsers.ts +25 -0
- package/src/lib/reactivity/createInstanceValueState.ts +69 -43
- package/src/lib/reactivity/{createSelectItems.ts → createItemCollection.ts} +41 -36
- package/src/lib/xml-serialization.ts +76 -9
- package/src/parse/XFormDOM.ts +141 -21
- package/src/parse/XFormDefinition.ts +1 -4
- package/src/parse/body/BodyDefinition.ts +4 -4
- package/src/parse/body/appearance/rangeAppearanceParser.ts +11 -0
- package/src/parse/body/control/InputControlDefinition.ts +9 -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/model/BindDefinition.ts +4 -0
- package/src/parse/model/BindPreloadDefinition.ts +100 -0
- package/src/parse/model/DescendentNodeDefinition.ts +7 -25
- package/src/parse/model/ItextTranslationsDefinition.ts +79 -0
- package/src/parse/model/LeafNodeDefinition.ts +13 -8
- package/src/parse/model/ModelDefinition.ts +36 -3
- package/src/parse/model/NodeDefinition.ts +38 -85
- package/src/parse/model/NoteNodeDefinition.ts +12 -10
- package/src/parse/model/RangeNodeDefinition.ts +119 -0
- package/src/parse/model/RepeatDefinition.ts +382 -0
- package/src/parse/model/RootAttributeDefinition.ts +44 -0
- package/src/parse/model/RootAttributeMap.ts +49 -0
- package/src/parse/model/RootDefinition.ts +42 -43
- package/src/parse/model/SecondaryInstance/SecondaryInstancesDefinition.ts +23 -2
- package/src/parse/model/SecondaryInstance/assertSecondaryInstanceDefinition.ts +14 -0
- package/src/parse/model/SecondaryInstance/defineSecondaryInstance.ts +32 -0
- package/src/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.ts +3 -24
- package/src/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.ts +33 -86
- package/src/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.ts +64 -136
- package/src/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.ts +9 -7
- package/src/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.ts +1 -1
- package/src/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.ts +7 -7
- package/src/parse/model/{FormSubmissionDefinition.ts → SubmissionDefinition.ts} +2 -2
- package/src/parse/model/SubtreeDefinition.ts +15 -16
- package/src/parse/model/nodeDefinitionMap.ts +34 -0
- package/src/parse/shared/parseInstanceXML.ts +79 -0
- package/src/parse/shared/parseStaticDocumentFromDOMSubtree.ts +46 -131
- 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/xpath/semantic-analysis.ts +4 -3
- package/dist/client/EngineConfig.d.ts +0 -79
- package/dist/client/submission/SubmissionData.d.ts +0 -7
- package/dist/client/submission/SubmissionInstanceFile.d.ts +0 -6
- package/dist/client/submission/SubmissionOptions.d.ts +0 -23
- package/dist/client/submission/SubmissionResult.d.ts +0 -91
- package/dist/client/submission/SubmissionState.d.ts +0 -12
- 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 -58
- package/dist/instance/abstract/UnsupportedControl.d.ts +0 -53
- package/dist/instance/index.d.ts +0 -8
- package/dist/instance/internal-api/ValueContext.d.ts +0 -23
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableInstance.d.ts +0 -14
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.d.ts +0 -31
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableParentNode.d.ts +0 -18
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableValueNode.d.ts +0 -17
- package/dist/instance/unsupported/RangeControl.d.ts +0 -6
- package/dist/instance/unsupported/RankControl.d.ts +0 -6
- package/dist/integration/xpath/static-dom/StaticNamedNode.d.ts +0 -17
- package/dist/lib/client-reactivity/submission/createInstanceSubmissionState.d.ts +0 -3
- package/dist/lib/client-reactivity/submission/createLeafNodeSubmissionState.d.ts +0 -3
- package/dist/lib/client-reactivity/submission/createNodeRangeSubmissionState.d.ts +0 -4
- package/dist/lib/client-reactivity/submission/createParentNodeSubmissionState.d.ts +0 -4
- package/dist/lib/client-reactivity/submission/createValueNodeSubmissionState.d.ts +0 -3
- package/dist/lib/client-reactivity/submission/prepareSubmission.d.ts +0 -8
- package/dist/lib/reactivity/createSelectItems.d.ts +0 -16
- package/dist/lib/reactivity/createValueState.d.ts +0 -40
- 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 -9
- package/dist/parse/model/ItextTranslation/ItextTranslationDefinition.d.ts +0 -4
- package/dist/parse/model/ItextTranslation/ItextTranslationRootDefinition.d.ts +0 -8
- package/dist/parse/model/ItextTranslation/ItextTranslationsDefinition.d.ts +0 -8
- package/dist/parse/model/RepeatInstanceDefinition.d.ts +0 -14
- package/dist/parse/model/RepeatRangeDefinition.d.ts +0 -29
- package/dist/parse/model/RepeatTemplateDefinition.d.ts +0 -28
- package/dist/parse/model/SecondaryInstance/SecondaryInstanceDefinition.d.ts +0 -4
- package/dist/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.d.ts +0 -7
- package/src/client/EngineConfig.ts +0 -84
- package/src/client/submission/SubmissionData.ts +0 -12
- package/src/client/submission/SubmissionInstanceFile.ts +0 -9
- package/src/client/submission/SubmissionOptions.ts +0 -28
- package/src/client/submission/SubmissionResult.ts +0 -124
- package/src/client/submission/SubmissionState.ts +0 -14
- package/src/client/unsupported/RangeNode.ts +0 -14
- package/src/client/unsupported/RankNode.ts +0 -14
- package/src/instance/SelectField.ts +0 -263
- package/src/instance/abstract/UnsupportedControl.ts +0 -174
- package/src/instance/children.ts +0 -158
- package/src/instance/index.ts +0 -55
- package/src/instance/internal-api/ValueContext.ts +0 -28
- package/src/instance/internal-api/submission/ClientReactiveSubmittableInstance.ts +0 -20
- package/src/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.ts +0 -42
- package/src/instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts +0 -25
- package/src/instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts +0 -23
- package/src/instance/unsupported/RangeControl.ts +0 -9
- package/src/instance/unsupported/RankControl.ts +0 -9
- package/src/integration/xpath/static-dom/StaticNamedNode.ts +0 -45
- package/src/lib/client-reactivity/submission/createInstanceSubmissionState.ts +0 -12
- package/src/lib/client-reactivity/submission/createLeafNodeSubmissionState.ts +0 -20
- package/src/lib/client-reactivity/submission/createNodeRangeSubmissionState.ts +0 -17
- package/src/lib/client-reactivity/submission/createParentNodeSubmissionState.ts +0 -22
- package/src/lib/client-reactivity/submission/createValueNodeSubmissionState.ts +0 -21
- package/src/lib/client-reactivity/submission/prepareSubmission.ts +0 -172
- package/src/lib/reactivity/createValueState.ts +0 -200
- package/src/parse/body/control/select/ItemsetNodesetContext.ts +0 -21
- package/src/parse/model/ItextTranslation/ItextTranslationDefinition.ts +0 -4
- package/src/parse/model/ItextTranslation/ItextTranslationRootDefinition.ts +0 -41
- package/src/parse/model/ItextTranslation/ItextTranslationsDefinition.ts +0 -31
- package/src/parse/model/RepeatInstanceDefinition.ts +0 -34
- package/src/parse/model/RepeatRangeDefinition.ts +0 -94
- package/src/parse/model/RepeatTemplateDefinition.ts +0 -145
- package/src/parse/model/SecondaryInstance/SecondaryInstanceDefinition.ts +0 -4
- package/src/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.ts +0 -12
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { QualifiedName, type QualifiedNameSource } from '../../../lib/names/QualifiedName.ts';
|
|
2
|
+
import { UnprefixedXFormsName } from '../../../lib/names/UnprefixedXFormsName.ts';
|
|
3
|
+
|
|
4
|
+
// prettier-ignore
|
|
5
|
+
export type StaticNodeNameSource =
|
|
6
|
+
| QualifiedName
|
|
7
|
+
| QualifiedNameSource
|
|
8
|
+
| string;
|
|
9
|
+
|
|
10
|
+
export const staticNodeName = (source: StaticNodeNameSource): QualifiedName => {
|
|
11
|
+
if (source instanceof QualifiedName) {
|
|
12
|
+
return source;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (typeof source === 'string') {
|
|
16
|
+
return new UnprefixedXFormsName(source);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return new QualifiedName(source);
|
|
20
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { InstanceState } from '../../../client/serialization/InstanceState.ts';
|
|
2
|
+
import type { ClientReactiveSerializableParentNode } from '../../../instance/internal-api/serialization/ClientReactiveSerializableParentNode.ts';
|
|
3
|
+
import type { RepeatInstance } from '../../../instance/repeat/RepeatInstance.ts';
|
|
4
|
+
|
|
5
|
+
export const createNodeRangeInstanceState = (
|
|
6
|
+
node: ClientReactiveSerializableParentNode<RepeatInstance>
|
|
7
|
+
): InstanceState => {
|
|
8
|
+
return {
|
|
9
|
+
get instanceXML() {
|
|
10
|
+
const serializedChildren = node.currentState.children.map((child) => {
|
|
11
|
+
return child.instanceState.instanceXML;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
return serializedChildren.join('');
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { InstanceState } from '../../../client/serialization/InstanceState.ts';
|
|
2
|
+
import type { GeneralChildNode } from '../../../instance/hierarchy.ts';
|
|
3
|
+
import type { ClientReactiveSerializableParentNode } from '../../../instance/internal-api/serialization/ClientReactiveSerializableParentNode.ts';
|
|
4
|
+
import { serializeParentElementXML } from '../../xml-serialization.ts';
|
|
5
|
+
|
|
6
|
+
export const createParentNodeInstanceState = (
|
|
7
|
+
node: ClientReactiveSerializableParentNode<GeneralChildNode>
|
|
8
|
+
): InstanceState => {
|
|
9
|
+
return {
|
|
10
|
+
get instanceXML() {
|
|
11
|
+
if (!node.currentState.relevant) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const serializedChildren = node.currentState.children.map((child) => {
|
|
16
|
+
return child.instanceState.instanceXML;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return serializeParentElementXML(node.definition.qualifiedName, serializedChildren);
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InstanceState } from '../../../client/serialization/InstanceState.ts';
|
|
2
|
+
import type { ClientReactiveSerializableInstance } from '../../../instance/internal-api/serialization/ClientReactiveSerializableInstance.ts';
|
|
3
|
+
|
|
4
|
+
export const createPrimaryInstanceState = (
|
|
5
|
+
node: ClientReactiveSerializableInstance
|
|
6
|
+
): InstanceState => {
|
|
7
|
+
return {
|
|
8
|
+
get instanceXML(): string {
|
|
9
|
+
return node.root.instanceState.instanceXML;
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { InstanceState } from '../../../client/serialization/InstanceState.ts';
|
|
2
|
+
import type { Root } from '../../../instance/Root.ts';
|
|
3
|
+
import { serializeParentElementXML } from '../../xml-serialization.ts';
|
|
4
|
+
|
|
5
|
+
export const createRootInstanceState = (node: Root): InstanceState => {
|
|
6
|
+
return {
|
|
7
|
+
get instanceXML() {
|
|
8
|
+
const { namespaceDeclarations, attributes } = node.definition;
|
|
9
|
+
const serializedChildren = node.currentState.children.map((child) => {
|
|
10
|
+
return child.instanceState.instanceXML;
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return serializeParentElementXML(node.definition.qualifiedName, serializedChildren, {
|
|
14
|
+
namespaceDeclarations,
|
|
15
|
+
attributes: Array.from(attributes.values()),
|
|
16
|
+
});
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { InstanceState } from '../../../client/serialization/InstanceState.ts';
|
|
2
|
+
import { TemplatedNodeAttributeSerializationError } from '../../../error/TemplatedNodeAttributeSerializationError.ts';
|
|
3
|
+
import type { ClientReactiveSerializableTemplatedNode } from '../../../instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.ts';
|
|
4
|
+
import { serializeParentElementXML } from '../../xml-serialization.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @see {@link TemplatedNodeAttributeSerializationError}
|
|
8
|
+
*/
|
|
9
|
+
export const createTemplatedNodeInstanceState = (
|
|
10
|
+
node: ClientReactiveSerializableTemplatedNode
|
|
11
|
+
): InstanceState => {
|
|
12
|
+
return {
|
|
13
|
+
get instanceXML() {
|
|
14
|
+
if (!node.currentState.relevant) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const serializedChildren = node.currentState.children.map((child) => {
|
|
19
|
+
return child.instanceState.instanceXML;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const { attributes } = node.currentState;
|
|
23
|
+
|
|
24
|
+
if (attributes != null) {
|
|
25
|
+
throw new TemplatedNodeAttributeSerializationError();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return serializeParentElementXML(node.definition.qualifiedName, serializedChildren);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { InstanceState } from '../../../client/serialization/InstanceState.ts';
|
|
2
|
+
import type { ClientReactiveSerializableValueNode } from '../../../instance/internal-api/serialization/ClientReactiveSerializableValueNode.ts';
|
|
3
|
+
import { escapeXMLText, serializeLeafElementXML } from '../../xml-serialization.ts';
|
|
4
|
+
|
|
5
|
+
export const createValueNodeInstanceState = (
|
|
6
|
+
node: ClientReactiveSerializableValueNode
|
|
7
|
+
): InstanceState => {
|
|
8
|
+
const { qualifiedName } = node.definition;
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
get instanceXML() {
|
|
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,173 @@
|
|
|
1
|
+
import { UnreachableError } from '@getodk/common/lib/error/UnreachableError.ts';
|
|
2
|
+
import { INSTANCE_FILE_NAME, INSTANCE_FILE_TYPE } from '../../../client/constants.ts';
|
|
3
|
+
import type { InstanceData as ClientInstanceData } from '../../../client/serialization/InstanceData.ts';
|
|
4
|
+
import type { InstanceFile as ClientInstanceFile } from '../../../client/serialization/InstanceFile.ts';
|
|
5
|
+
import type {
|
|
6
|
+
ChunkedInstancePayload,
|
|
7
|
+
InstancePayload,
|
|
8
|
+
MonolithicInstancePayload,
|
|
9
|
+
} from '../../../client/serialization/InstancePayload.ts';
|
|
10
|
+
import type { InstancePayloadType } from '../../../client/serialization/InstancePayloadOptions.ts';
|
|
11
|
+
import type { SubmissionMeta } from '../../../client/submission/SubmissionMeta.ts';
|
|
12
|
+
import type { DescendantNodeViolationReference } from '../../../client/validation.ts';
|
|
13
|
+
import type { ClientReactiveSerializableInstance } from '../../../instance/internal-api/serialization/ClientReactiveSerializableInstance.ts';
|
|
14
|
+
|
|
15
|
+
class InstanceFile extends File implements ClientInstanceFile {
|
|
16
|
+
override readonly name = INSTANCE_FILE_NAME;
|
|
17
|
+
override readonly type = INSTANCE_FILE_TYPE;
|
|
18
|
+
|
|
19
|
+
constructor(instanceRoot: ClientReactiveSerializableInstance) {
|
|
20
|
+
const { instanceXML } = instanceRoot.instanceState;
|
|
21
|
+
|
|
22
|
+
super([instanceXML], INSTANCE_FILE_NAME, {
|
|
23
|
+
type: INSTANCE_FILE_TYPE,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type AssertInstanceData = (data: FormData) => asserts data is ClientInstanceData;
|
|
29
|
+
|
|
30
|
+
const assertInstanceData: AssertInstanceData = (data) => {
|
|
31
|
+
const instanceFile = data.get(INSTANCE_FILE_NAME);
|
|
32
|
+
|
|
33
|
+
if (!(instanceFile instanceof InstanceFile)) {
|
|
34
|
+
throw new Error(`Invalid InstanceData`);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
class InstanceData extends FormData {
|
|
39
|
+
static from(instanceFile: InstanceFile, attachments: readonly File[]): ClientInstanceData {
|
|
40
|
+
const data = new this(instanceFile, attachments);
|
|
41
|
+
|
|
42
|
+
assertInstanceData(data);
|
|
43
|
+
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private constructor(
|
|
48
|
+
readonly instanceFile: InstanceFile,
|
|
49
|
+
readonly attachments: readonly File[]
|
|
50
|
+
) {
|
|
51
|
+
super();
|
|
52
|
+
|
|
53
|
+
this.set(INSTANCE_FILE_NAME, instanceFile);
|
|
54
|
+
|
|
55
|
+
attachments.forEach((attachment) => {
|
|
56
|
+
const { name } = attachment;
|
|
57
|
+
|
|
58
|
+
if (name === INSTANCE_FILE_NAME && attachment !== instanceFile) {
|
|
59
|
+
throw new Error(`Failed to add conflicting attachment with name ${INSTANCE_FILE_NAME}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this.set(name, attachment);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface PendingValidation {
|
|
68
|
+
readonly status: 'pending';
|
|
69
|
+
readonly violations: readonly DescendantNodeViolationReference[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface ReadyValidation {
|
|
73
|
+
readonly status: 'ready';
|
|
74
|
+
readonly violations: null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type InstanceStateValidation = PendingValidation | ReadyValidation;
|
|
78
|
+
|
|
79
|
+
const validateInstance = (
|
|
80
|
+
instanceRoot: ClientReactiveSerializableInstance
|
|
81
|
+
): InstanceStateValidation => {
|
|
82
|
+
const { violations } = instanceRoot.validationState;
|
|
83
|
+
|
|
84
|
+
if (violations.length === 0) {
|
|
85
|
+
return {
|
|
86
|
+
status: 'ready',
|
|
87
|
+
violations: null,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
status: 'pending',
|
|
93
|
+
violations,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const monolithicInstancePayload = (
|
|
98
|
+
validation: InstanceStateValidation,
|
|
99
|
+
submissionMeta: SubmissionMeta,
|
|
100
|
+
instanceFile: InstanceFile,
|
|
101
|
+
attachments: readonly File[]
|
|
102
|
+
): MonolithicInstancePayload => {
|
|
103
|
+
const data = InstanceData.from(instanceFile, attachments);
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
payloadType: 'monolithic',
|
|
107
|
+
...validation,
|
|
108
|
+
submissionMeta,
|
|
109
|
+
data: [data],
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
interface ChunkedInstancePayloadOptions {
|
|
114
|
+
readonly maxSize: number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const chunkedInstancePayload = (
|
|
118
|
+
validation: InstanceStateValidation,
|
|
119
|
+
submissionMeta: SubmissionMeta,
|
|
120
|
+
instanceFile: InstanceFile,
|
|
121
|
+
attachments: readonly File[],
|
|
122
|
+
options: ChunkedInstancePayloadOptions
|
|
123
|
+
): ChunkedInstancePayload => {
|
|
124
|
+
if (attachments.length > 0 || options.maxSize !== Infinity) {
|
|
125
|
+
throw new Error('InstancePayload chunking pending implementation');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const data = InstanceData.from(instanceFile, attachments);
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
payloadType: 'chunked',
|
|
132
|
+
...validation,
|
|
133
|
+
submissionMeta,
|
|
134
|
+
data: [data],
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export interface PrepareInstancePayloadOptions<PayloadType extends InstancePayloadType> {
|
|
139
|
+
readonly payloadType: PayloadType;
|
|
140
|
+
readonly maxSize: number;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const prepareInstancePayload = <PayloadType extends InstancePayloadType>(
|
|
144
|
+
instanceRoot: ClientReactiveSerializableInstance,
|
|
145
|
+
options: PrepareInstancePayloadOptions<PayloadType>
|
|
146
|
+
): InstancePayload<PayloadType> => {
|
|
147
|
+
const validation = validateInstance(instanceRoot);
|
|
148
|
+
const submissionMeta = instanceRoot.definition.submission;
|
|
149
|
+
const instanceFile = new InstanceFile(instanceRoot);
|
|
150
|
+
const attachments: readonly File[] = [];
|
|
151
|
+
|
|
152
|
+
switch (options.payloadType) {
|
|
153
|
+
case 'chunked':
|
|
154
|
+
return chunkedInstancePayload(
|
|
155
|
+
validation,
|
|
156
|
+
submissionMeta,
|
|
157
|
+
instanceFile,
|
|
158
|
+
attachments,
|
|
159
|
+
options
|
|
160
|
+
) satisfies ChunkedInstancePayload as InstancePayload<PayloadType>;
|
|
161
|
+
|
|
162
|
+
case 'monolithic':
|
|
163
|
+
return monolithicInstancePayload(
|
|
164
|
+
validation,
|
|
165
|
+
submissionMeta,
|
|
166
|
+
instanceFile,
|
|
167
|
+
attachments
|
|
168
|
+
) satisfies MonolithicInstancePayload as InstancePayload<PayloadType>;
|
|
169
|
+
|
|
170
|
+
default:
|
|
171
|
+
throw new UnreachableError(options.payloadType);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
@@ -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,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,32 @@
|
|
|
1
|
+
import { identity } from '@getodk/common/lib/identity.ts';
|
|
2
|
+
import type { ValueType } from '../../client/ValueType.ts';
|
|
3
|
+
import { ValueCodec, type CodecDecoder, type CodecEncoder } from './ValueCodec.ts';
|
|
4
|
+
|
|
5
|
+
class TempUnsupportedControlEncodeError extends Error {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(`Cannot encode state: not implemented`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type TempUnsupportedRuntimeValue = unknown;
|
|
12
|
+
export type TempUnsupportedInputValue = unknown;
|
|
13
|
+
|
|
14
|
+
export class TempUnsupportedControlCodec<V extends ValueType> extends ValueCodec<
|
|
15
|
+
V,
|
|
16
|
+
TempUnsupportedRuntimeValue,
|
|
17
|
+
TempUnsupportedInputValue
|
|
18
|
+
> {
|
|
19
|
+
constructor(valueType: V) {
|
|
20
|
+
const encodeValue: CodecEncoder<TempUnsupportedRuntimeValue> = (input): string => {
|
|
21
|
+
if (typeof input === 'string') {
|
|
22
|
+
return input;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
throw new TempUnsupportedControlEncodeError();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const decodeValue: CodecDecoder<TempUnsupportedInputValue> = identity;
|
|
29
|
+
|
|
30
|
+
super(valueType, encodeValue, decodeValue);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -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
|
+
}
|