@getodk/xforms-engine 0.6.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/dist/client/BaseNode.d.ts +4 -4
- package/dist/client/BaseValueNode.d.ts +7 -3
- package/dist/client/RootNode.d.ts +20 -16
- 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/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/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/TemplatedNodeAttributeSerializationError.d.ts +22 -0
- package/dist/index.d.ts +2 -33
- package/dist/index.js +1915 -1419
- package/dist/index.js.map +1 -1
- package/dist/instance/Group.d.ts +6 -5
- package/dist/instance/InputControl.d.ts +5 -4
- package/dist/instance/ModelValue.d.ts +5 -4
- package/dist/instance/Note.d.ts +4 -3
- package/dist/instance/PrimaryInstance.d.ts +35 -8
- package/dist/instance/RangeControl.d.ts +5 -4
- package/dist/instance/RankControl.d.ts +6 -5
- package/dist/instance/Root.d.ts +7 -9
- package/dist/instance/SelectControl.d.ts +4 -3
- package/dist/instance/Subtree.d.ts +6 -5
- package/dist/instance/TriggerControl.d.ts +4 -3
- package/dist/instance/abstract/DescendantNode.d.ts +10 -1
- package/dist/instance/abstract/InstanceNode.d.ts +7 -4
- package/dist/instance/abstract/ValueNode.d.ts +7 -5
- 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/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 +8 -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 +10 -8
- package/dist/instance/repeat/RepeatInstance.d.ts +10 -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/static-dom/StaticAttribute.d.ts +4 -5
- package/dist/integration/xpath/static-dom/StaticDocument.d.ts +13 -10
- package/dist/integration/xpath/static-dom/StaticElement.d.ts +21 -22
- 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/TempUnsupportedControlCodec.d.ts +7 -0
- package/dist/lib/names/UnprefixedXFormsName.d.ts +4 -0
- package/dist/lib/reactivity/createInstanceValueState.d.ts +2 -27
- package/dist/parse/XFormDOM.d.ts +1 -1
- package/dist/parse/model/BindDefinition.d.ts +1 -1
- package/dist/parse/model/ItextTranslationsDefinition.d.ts +18 -0
- package/dist/parse/model/LeafNodeDefinition.d.ts +4 -5
- package/dist/parse/model/ModelBindMap.d.ts +1 -1
- package/dist/parse/model/ModelDefinition.d.ts +9 -2
- package/dist/parse/model/NodeDefinition.d.ts +18 -30
- package/dist/parse/model/NoteNodeDefinition.d.ts +3 -2
- package/dist/parse/model/RangeNodeDefinition.d.ts +2 -1
- package/dist/parse/model/RepeatDefinition.d.ts +62 -0
- package/dist/parse/model/RootAttributeDefinition.d.ts +1 -4
- package/dist/parse/model/RootAttributeMap.d.ts +2 -1
- package/dist/parse/model/RootDefinition.d.ts +7 -8
- 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 +4 -5
- 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 -21
- package/dist/solid.js +1709 -1213
- package/dist/solid.js.map +1 -1
- package/package.json +1 -1
- package/src/client/BaseNode.ts +4 -4
- package/src/client/BaseValueNode.ts +7 -3
- package/src/client/RootNode.ts +27 -19
- 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/index.ts +47 -29
- package/src/client/node-types.ts +2 -4
- 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/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/TemplatedNodeAttributeSerializationError.ts +24 -0
- package/src/index.ts +2 -46
- package/src/instance/Group.ts +16 -15
- package/src/instance/InputControl.ts +17 -11
- package/src/instance/ModelValue.ts +17 -11
- package/src/instance/Note.ts +10 -9
- package/src/instance/PrimaryInstance.ts +69 -31
- package/src/instance/RangeControl.ts +17 -11
- package/src/instance/RankControl.ts +28 -19
- package/src/instance/Root.ts +20 -31
- package/src/instance/SelectControl.ts +21 -12
- package/src/instance/Subtree.ts +16 -15
- package/src/instance/TriggerControl.ts +21 -12
- package/src/instance/abstract/DescendantNode.ts +12 -2
- package/src/instance/abstract/InstanceNode.ts +9 -5
- package/src/instance/abstract/ValueNode.ts +11 -13
- package/src/instance/children/DescendantNodeInitOptions.ts +35 -0
- package/src/instance/{children.ts → children/buildChildren.ts} +55 -48
- package/src/instance/children/childrenInitOptions.ts +117 -0
- package/src/instance/children/normalizeChildInitOptions.ts +332 -0
- 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 +9 -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 +19 -24
- package/src/instance/repeat/RepeatInstance.ts +26 -19
- package/src/instance/repeat/RepeatRangeControlled.ts +90 -17
- package/src/instance/repeat/RepeatRangeUncontrolled.ts +10 -9
- package/src/instance/resource.ts +14 -1
- 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/traversal.ts +2 -2
- package/src/integration/xpath/static-dom/StaticAttribute.ts +6 -5
- package/src/integration/xpath/static-dom/StaticDocument.ts +17 -16
- package/src/integration/xpath/static-dom/StaticElement.ts +196 -50
- 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/{submission/createRootSubmissionState.ts → instance-state/createRootInstanceState.ts} +4 -4
- 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/TempUnsupportedControlCodec.ts +32 -0
- package/src/lib/names/UnprefixedXFormsName.ts +12 -0
- package/src/lib/reactivity/createInstanceValueState.ts +27 -51
- package/src/parse/model/ItextTranslationsDefinition.ts +79 -0
- package/src/parse/model/LeafNodeDefinition.ts +3 -5
- package/src/parse/model/ModelDefinition.ts +36 -3
- package/src/parse/model/NodeDefinition.ts +19 -45
- package/src/parse/model/NoteNodeDefinition.ts +4 -3
- package/src/parse/model/RangeNodeDefinition.ts +3 -2
- package/src/parse/model/RepeatDefinition.ts +382 -0
- package/src/parse/model/RootAttributeDefinition.ts +6 -7
- package/src/parse/model/RootAttributeMap.ts +15 -10
- package/src/parse/model/RootDefinition.ts +17 -19
- 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 -137
- 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 +4 -5
- package/src/parse/model/nodeDefinitionMap.ts +34 -0
- package/src/parse/shared/parseInstanceXML.ts +79 -0
- package/src/parse/shared/parseStaticDocumentFromDOMSubtree.ts +45 -130
- 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/instance/abstract/UnsupportedControl.d.ts +0 -54
- 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 -32
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableParentNode.d.ts +0 -19
- package/dist/instance/internal-api/submission/ClientReactiveSubmittableValueNode.d.ts +0 -18
- 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/createRootSubmissionState.d.ts +0 -3
- 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/createValueState.d.ts +0 -40
- package/dist/parse/model/ItextTranslation/ItextTranslationDefinition.d.ts +0 -4
- package/dist/parse/model/ItextTranslation/ItextTranslationRootDefinition.d.ts +0 -9
- package/dist/parse/model/ItextTranslation/ItextTranslationsDefinition.d.ts +0 -8
- package/dist/parse/model/RepeatInstanceDefinition.d.ts +0 -17
- package/dist/parse/model/RepeatRangeDefinition.d.ts +0 -32
- package/dist/parse/model/RepeatTemplateDefinition.d.ts +0 -31
- 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/instance/abstract/UnsupportedControl.ts +0 -175
- 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 -43
- package/src/instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts +0 -26
- package/src/instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts +0 -24
- 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/model/ItextTranslation/ItextTranslationDefinition.ts +0 -4
- package/src/parse/model/ItextTranslation/ItextTranslationRootDefinition.ts +0 -42
- package/src/parse/model/ItextTranslation/ItextTranslationsDefinition.ts +0 -31
- package/src/parse/model/RepeatInstanceDefinition.ts +0 -38
- package/src/parse/model/RepeatRangeDefinition.ts +0 -98
- package/src/parse/model/RepeatTemplateDefinition.ts +0 -149
- package/src/parse/model/SecondaryInstance/SecondaryInstanceDefinition.ts +0 -4
- package/src/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.ts +0 -12
package/package.json
CHANGED
package/src/client/BaseNode.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { OpaqueReactiveObjectFactory } from './OpaqueReactiveObjectFactory.
|
|
|
5
5
|
import type { TextRange } from './TextRange.ts';
|
|
6
6
|
import type { FormNodeID } from './identity.ts';
|
|
7
7
|
import type { InstanceNodeType } from './node-types.ts';
|
|
8
|
-
import type {
|
|
8
|
+
import type { InstanceState } from './serialization/InstanceState.ts';
|
|
9
9
|
import type {
|
|
10
10
|
AncestorNodeValidationState,
|
|
11
11
|
LeafNodeValidationState,
|
|
@@ -256,14 +256,14 @@ export interface BaseNode {
|
|
|
256
256
|
readonly validationState: NodeValidationState;
|
|
257
257
|
|
|
258
258
|
/**
|
|
259
|
-
* Represents the current
|
|
259
|
+
* Represents the current instance state of the node.
|
|
260
260
|
*
|
|
261
|
-
* @see {@link
|
|
261
|
+
* @see {@link InstanceState.instanceXML} for additional detail.
|
|
262
262
|
*
|
|
263
263
|
* @todo Consider whether this can (should) be merged with
|
|
264
264
|
* {@link currentState}, while providing the same client-reactivity
|
|
265
265
|
* guarantees. (The challenge there is in defining client-reactive state which
|
|
266
266
|
* self-referentially derives state from its own definition.)
|
|
267
267
|
*/
|
|
268
|
-
readonly
|
|
268
|
+
readonly instanceState: InstanceState;
|
|
269
269
|
}
|
|
@@ -2,6 +2,7 @@ import type { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
|
|
|
2
2
|
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
3
3
|
import type { GeneralParentNode } from './hierarchy.ts';
|
|
4
4
|
import type { LeafNodeType } from './node-types.ts';
|
|
5
|
+
import type { InstanceState } from './serialization/InstanceState.ts';
|
|
5
6
|
import type { LeafNodeValidationState } from './validation.ts';
|
|
6
7
|
import type { ValueType } from './ValueType.ts';
|
|
7
8
|
|
|
@@ -15,12 +16,14 @@ export interface BaseValueNodeState<Value> extends BaseNodeState {
|
|
|
15
16
|
* {@link value} state. This representation allows access to the node's value
|
|
16
17
|
* _as primary instance state_. In other words, this is the value which:
|
|
17
18
|
*
|
|
18
|
-
* - would be serialized as a text node in
|
|
19
|
-
*
|
|
20
|
-
*
|
|
19
|
+
* - would be serialized as a text node in {@link InstanceState.instanceXML}
|
|
20
|
+
* (note: this value is **NOT** escaped for XML serialization, as it is
|
|
21
|
+
* there)
|
|
21
22
|
*
|
|
22
23
|
* - is used when the node's value is referenced in any of a form's XPath
|
|
23
24
|
* expressions
|
|
25
|
+
*
|
|
26
|
+
* @todo Consider moving into {@link InstanceState}
|
|
24
27
|
*/
|
|
25
28
|
get instanceValue(): string;
|
|
26
29
|
}
|
|
@@ -32,4 +35,5 @@ export interface BaseValueNode<V extends ValueType = ValueType, Value = string>
|
|
|
32
35
|
readonly parent: GeneralParentNode;
|
|
33
36
|
readonly currentState: BaseValueNodeState<Value>;
|
|
34
37
|
readonly validationState: LeafNodeValidationState;
|
|
38
|
+
readonly instanceState: InstanceState;
|
|
35
39
|
}
|
package/src/client/RootNode.ts
CHANGED
|
@@ -3,12 +3,12 @@ import type { RootDefinition } from '../parse/model/RootDefinition.ts';
|
|
|
3
3
|
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
|
|
4
4
|
import type { ActiveLanguage, FormLanguage, FormLanguages } from './FormLanguage.ts';
|
|
5
5
|
import type { GeneralChildNode } from './hierarchy.ts';
|
|
6
|
-
import type { SubmissionOptions } from './submission/SubmissionOptions.ts';
|
|
7
6
|
import type {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} from './
|
|
7
|
+
ChunkedInstancePayload,
|
|
8
|
+
InstancePayload,
|
|
9
|
+
MonolithicInstancePayload,
|
|
10
|
+
} from './serialization/InstancePayload.ts';
|
|
11
|
+
import type { InstancePayloadOptions } from './serialization/InstancePayloadOptions.ts';
|
|
12
12
|
import type { AncestorNodeValidationState } from './validation.ts';
|
|
13
13
|
|
|
14
14
|
export interface RootNodeState extends BaseNodeState {
|
|
@@ -64,33 +64,41 @@ export interface RootNode extends BaseNode {
|
|
|
64
64
|
setLanguage(language: FormLanguage): RootNode;
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* Prepares the current form instance state
|
|
67
|
+
* Prepares the current form instance state as an {@link InstancePayload}.
|
|
68
68
|
*
|
|
69
|
-
* A
|
|
70
|
-
*
|
|
71
|
-
* two purposes:
|
|
69
|
+
* A payload will be prepared even if the current form state includes
|
|
70
|
+
* `constraint` or `required` violations. This supports serveral purposes:
|
|
72
71
|
*
|
|
73
|
-
* - A client may effectively use this method as a part of its
|
|
74
|
-
*
|
|
72
|
+
* - A client may effectively use this method as a part of its "submit"
|
|
73
|
+
* workflow, and use any violations included in the {@link InstancePayload}
|
|
75
74
|
* to prompt users to address those violations.
|
|
76
75
|
*
|
|
77
|
-
* - A client may inspect the
|
|
76
|
+
* - A client may inspect the serialized instance state of a form at any time.
|
|
78
77
|
* Depending on the client and use case, this may be a convenience (e.g. for
|
|
79
78
|
* developers to inspect that form state at a current point in time); or it
|
|
80
79
|
* may provide necessary functionality (e.g. for test or tooling clients).
|
|
81
80
|
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
81
|
+
* - A client may capture _incomplete_ instance state (e.g. for storage in
|
|
82
|
+
* client-side storage or similar persistance layer), to resume filling the
|
|
83
|
+
* instance at a later time.
|
|
84
|
+
*
|
|
85
|
+
* Note on asynchrony: preparing a {@link InstancePayload} is expected to be a
|
|
86
|
+
* fast operation. It may even be nearly instantaneous, or roughly
|
|
84
87
|
* proportionate to the size of the form itself. However, this method is
|
|
85
88
|
* designed to be asynchronous out of an abundance of caution, anticipating
|
|
86
89
|
* that some as-yet undeveloped operations on binary data (e.g. form
|
|
87
90
|
* attachments) may themselves impose asynchrony (i.e. by interfaces provided
|
|
88
91
|
* by the platform and/or external dependencies).
|
|
89
92
|
*
|
|
90
|
-
* A client may specify {@link
|
|
91
|
-
* {@link
|
|
93
|
+
* A client may specify {@link InstancePayloadOptions<'chunked'>}, in which
|
|
94
|
+
* case a {@link ChunkedInstancePayload} will be produced, with form
|
|
95
|
+
* attachments
|
|
92
96
|
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
prepareInstancePayload(): Promise<MonolithicInstancePayload>;
|
|
98
|
+
prepareInstancePayload(
|
|
99
|
+
options: InstancePayloadOptions<'monolithic'>
|
|
100
|
+
): Promise<MonolithicInstancePayload>;
|
|
101
|
+
prepareInstancePayload(
|
|
102
|
+
options: InstancePayloadOptions<'chunked'>
|
|
103
|
+
): Promise<ChunkedInstancePayload>;
|
|
96
104
|
}
|
package/src/client/constants.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { InitializeForm } from './index.ts';
|
|
1
|
+
import type { LoadForm } from './form/LoadForm.ts';
|
|
3
2
|
import type { ValidationTextRole } from './TextRange.ts';
|
|
4
3
|
|
|
5
4
|
export const MISSING_RESOURCE_BEHAVIOR = {
|
|
6
5
|
/**
|
|
7
|
-
* When this behavior is configured, {@link
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* When this behavior is configured, {@link LoadForm | loading a form} which
|
|
7
|
+
* references any **missing** resources will fail, producing an error to the
|
|
8
|
+
* calling client.
|
|
10
9
|
*
|
|
11
10
|
* @see {@link MissingResourceBehavior}
|
|
12
11
|
*/
|
|
13
12
|
ERROR: 'ERROR',
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
|
-
* When this behavior is configured, {@link
|
|
17
|
-
*
|
|
18
|
-
* resources will succeed (producing a warning).
|
|
15
|
+
* When this behavior is configured, {@link LoadForm | loading a form} which
|
|
16
|
+
* references any **missing** resources will succeed (producing a warning).
|
|
19
17
|
*
|
|
20
18
|
* Such missing resources will be parsed as if they are blank, as appropriate
|
|
21
19
|
* for the resource's XForm semantic usage and/or format.
|
|
@@ -39,8 +37,8 @@ export type MissingResourceBehaviorBlank = typeof MISSING_RESOURCE_BEHAVIOR.BLAN
|
|
|
39
37
|
export type MissingResourceBehaviorDefault = typeof MISSING_RESOURCE_BEHAVIOR.DEFAULT;
|
|
40
38
|
|
|
41
39
|
/**
|
|
42
|
-
* Specifies behavior for {@link
|
|
43
|
-
*
|
|
40
|
+
* Specifies behavior for {@link LoadForm | loading a form} which references any
|
|
41
|
+
* **missing** resources.
|
|
44
42
|
*
|
|
45
43
|
* Here the term "missing" is consistent with
|
|
46
44
|
* {@link https://www.rfc-editor.org/rfc/rfc9110#status.404 | HTTP 404 status}
|
|
@@ -70,8 +68,8 @@ type ValidationTextDefaults = typeof VALIDATION_TEXT;
|
|
|
70
68
|
|
|
71
69
|
export type ValidationTextDefault<Role extends ValidationTextRole> = ValidationTextDefaults[Role];
|
|
72
70
|
|
|
73
|
-
export const
|
|
74
|
-
export type
|
|
71
|
+
export const INSTANCE_FILE_NAME = 'xml_submission_file';
|
|
72
|
+
export type INSTANCE_FILE_NAME = typeof INSTANCE_FILE_NAME;
|
|
75
73
|
|
|
76
|
-
export const
|
|
77
|
-
export type
|
|
74
|
+
export const INSTANCE_FILE_TYPE = 'text/xml';
|
|
75
|
+
export type INSTANCE_FILE_TYPE = typeof INSTANCE_FILE_TYPE;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RootNode } from '../RootNode.ts';
|
|
2
|
+
import type { FormInstance, FormInstanceCreateMode } from './FormInstance.ts';
|
|
3
|
+
import type { FormInstanceConfig } from './FormInstanceConfig.ts';
|
|
4
|
+
import type { LoadForm } from './LoadForm.ts';
|
|
5
|
+
import type { LoadFormResult } from './LoadFormResult.ts';
|
|
6
|
+
|
|
7
|
+
export type CreatedFormInstance = FormInstance<FormInstanceCreateMode>;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @todo This is fallible! Client-facing interfaces will need to account for
|
|
11
|
+
* this. We've begun addressing fallibility _at the interface level_ in
|
|
12
|
+
* {@link LoadForm} (with {@link LoadFormResult}). We'll eventually have a more
|
|
13
|
+
* general interface pattern for this, and we'll apply it here as well. The baby
|
|
14
|
+
* step approach in {@link LoadFormResult} is impractical here due to
|
|
15
|
+
* engine-internal designs, and revising that is currently out of scope. As
|
|
16
|
+
* such, explicit interface-level documentation of fallibility is deferred here,
|
|
17
|
+
* on {@link RootNode} itself, and into any of its sub-interfaces.
|
|
18
|
+
*/
|
|
19
|
+
export type CreateFormInstance = (config?: FormInstanceConfig) => CreatedFormInstance;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Awaitable, Thunk } from '@getodk/common/types/helpers.d.ts';
|
|
2
|
+
import type { FetchResourceResponse } from '../resources.ts';
|
|
3
|
+
import type { InstanceAttachmentFileName, InstanceData } from '../serialization/InstanceData.ts';
|
|
4
|
+
import type { FormInstance, FormInstanceEditMode } from './FormInstance.ts';
|
|
5
|
+
import type { FormInstanceConfig } from './FormInstanceConfig.ts';
|
|
6
|
+
import type { LoadForm } from './LoadForm.ts';
|
|
7
|
+
import type { RestoreFormInstance, RestoreFormInstanceInput } from './RestoreFormInstance.ts';
|
|
8
|
+
|
|
9
|
+
export type ResolvableFormInstanceInputType = 'FORM_INSTANCE_INPUT_RESOLVABLE';
|
|
10
|
+
export type ResolvedFormInstanceInputType = 'FORM_INSTANCE_INPUT_RESOLVED';
|
|
11
|
+
|
|
12
|
+
// prettier-ignore
|
|
13
|
+
export type EditFormInstanceInputType =
|
|
14
|
+
| ResolvableFormInstanceInputType
|
|
15
|
+
| ResolvedFormInstanceInputType;
|
|
16
|
+
|
|
17
|
+
// prettier-ignore
|
|
18
|
+
export type ResolvedFormInstance =
|
|
19
|
+
| Blob
|
|
20
|
+
| FetchResourceResponse
|
|
21
|
+
| File
|
|
22
|
+
| string;
|
|
23
|
+
|
|
24
|
+
export type ResolvableFormInstance = Thunk<Awaitable<ResolvedFormInstance>>;
|
|
25
|
+
|
|
26
|
+
export type ResolveFormInstanceResource = Thunk<Promise<FetchResourceResponse>>;
|
|
27
|
+
|
|
28
|
+
export type ResolvableInstanceAttachmentsMap = ReadonlyMap<
|
|
29
|
+
InstanceAttachmentFileName,
|
|
30
|
+
ResolveFormInstanceResource
|
|
31
|
+
>;
|
|
32
|
+
|
|
33
|
+
interface BaseEditFormInstanceInput {
|
|
34
|
+
readonly inputType: EditFormInstanceInputType;
|
|
35
|
+
readonly data?: readonly [InstanceData, ...InstanceData[]];
|
|
36
|
+
readonly resolveInstance?: ResolvableFormInstance;
|
|
37
|
+
readonly attachments?: ResolvableInstanceAttachmentsMap;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ResolvableFormInstanceInput extends BaseEditFormInstanceInput {
|
|
41
|
+
readonly inputType: ResolvableFormInstanceInputType;
|
|
42
|
+
readonly resolveInstance: ResolvableFormInstance;
|
|
43
|
+
readonly attachments: ResolvableInstanceAttachmentsMap;
|
|
44
|
+
readonly data?: never;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @todo This is included as a strawman for discussiong: "should we accept input
|
|
49
|
+
* to {@link EditFormInstance} in the same shape as input to
|
|
50
|
+
* {@link RestoreFormInstance}?".
|
|
51
|
+
*
|
|
52
|
+
* Pros:
|
|
53
|
+
*
|
|
54
|
+
* - More consistency between the two entrypoint APIs, which are pretty similar
|
|
55
|
+
* _conceptually_.
|
|
56
|
+
* - ?
|
|
57
|
+
*
|
|
58
|
+
* Cons:
|
|
59
|
+
*
|
|
60
|
+
* - Less consistency between this entrypoint API and {@link LoadForm}, which is
|
|
61
|
+
* also responsible for loading arbitrary attachments (presumably over a
|
|
62
|
+
* network), which...
|
|
63
|
+
* - ... all but rules out flexibility to optimize loading large resources (i.e.
|
|
64
|
+
* streaming video/audio)
|
|
65
|
+
*
|
|
66
|
+
* Alternative:
|
|
67
|
+
*
|
|
68
|
+
* - Increase consistency across the board by inverting the relationship between
|
|
69
|
+
* edit/restore: {@link RestoreFormInstanceInput} could be the place where we
|
|
70
|
+
* accept a union of resolved | resolvable input, and clients which might
|
|
71
|
+
* benefit from this consistency could consolidate on the resolvable case
|
|
72
|
+
* without sacrificing resource loading optimizations)
|
|
73
|
+
*/
|
|
74
|
+
export interface ResolvedFormInstanceInput
|
|
75
|
+
extends BaseEditFormInstanceInput,
|
|
76
|
+
RestoreFormInstanceInput {
|
|
77
|
+
readonly inputType: ResolvedFormInstanceInputType;
|
|
78
|
+
readonly data: readonly [InstanceData, ...InstanceData[]];
|
|
79
|
+
readonly resolveInstance?: never;
|
|
80
|
+
readonly attachments?: never;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// prettier-ignore
|
|
84
|
+
export type EditFormInstanceInput =
|
|
85
|
+
| ResolvableFormInstanceInput
|
|
86
|
+
| ResolvedFormInstanceInput;
|
|
87
|
+
|
|
88
|
+
export type EditedFormInstance = FormInstance<FormInstanceEditMode>;
|
|
89
|
+
|
|
90
|
+
export type EditFormInstance = (
|
|
91
|
+
input: EditFormInstanceInput,
|
|
92
|
+
config?: FormInstanceConfig
|
|
93
|
+
) => Promise<EditedFormInstance>;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { RootNode } from '../RootNode.ts';
|
|
2
|
+
import type { InstantiableLoadFormResult, LoadFormResult } from './LoadFormResult.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents an instance which is newly created from a form definition.
|
|
6
|
+
*
|
|
7
|
+
* A newly created instance is populated with default values and state defined
|
|
8
|
+
* by the form.
|
|
9
|
+
*
|
|
10
|
+
* Computations are performed on initialization as specified by
|
|
11
|
+
* {@link https://getodk.github.io/xforms-spec/ | ODK XForms}, as the instance's
|
|
12
|
+
* {@link https://getodk.github.io/xforms-spec/#event:odk-instance-first-load | first load}.
|
|
13
|
+
*/
|
|
14
|
+
export type FormInstanceCreateMode = 'create';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents an instance restored from previously filled state, as represented
|
|
18
|
+
* in an {@link InstancePayload}. Clients may serialize and persist an instance
|
|
19
|
+
* payload as appropriate for their use cases, and can restore the instance with
|
|
20
|
+
* a partial instance payload structure, defined by the
|
|
21
|
+
* {@link RestoreFormInstanceInput} interface.
|
|
22
|
+
*
|
|
23
|
+
* A restored instance is populated by the engine with the answers as they had
|
|
24
|
+
* been filled at the time the {@link InstancePayload}
|
|
25
|
+
* ({@link RestoreFormInstanceInput}) was created.
|
|
26
|
+
*
|
|
27
|
+
* Computations are performed on initialization as specified by
|
|
28
|
+
* {@link https://getodk.github.io/xforms-spec/#event:odk-instance-load | ODK XForms},
|
|
29
|
+
* as a
|
|
30
|
+
* {@link https://getodk.github.io/xforms-spec/#event:odk-instance-load | subsequent load}
|
|
31
|
+
* (i.e. **NOT** "first load", as is the case with newly
|
|
32
|
+
* {@link FormInstanceCreateMode | created} instances}) of the instance.
|
|
33
|
+
*/
|
|
34
|
+
export type FormInstanceRestoreMode = 'restore';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Represents an instance which:
|
|
38
|
+
*
|
|
39
|
+
* - was previously serialized
|
|
40
|
+
* - was **submitted**, often referred to as a "submission" (noun)
|
|
41
|
+
* - is being initialized to produce an edited instance of that "submission"
|
|
42
|
+
*
|
|
43
|
+
* An edited instance may be populated from one or more network-accessible
|
|
44
|
+
* resources—its serialized instance XML, and any _instance attachments_—which
|
|
45
|
+
* are resolved in a manner similar to that of a form definition and its _form
|
|
46
|
+
* attachments_.
|
|
47
|
+
*
|
|
48
|
+
* Once resolved, an edited instance is restored from its previously filled
|
|
49
|
+
* state _as it was submitted_, consistent with
|
|
50
|
+
* {@link FormInstanceRestoreMode | restoring an instance}, with the following
|
|
51
|
+
* exceptions:
|
|
52
|
+
*
|
|
53
|
+
* - If the form or instance does not define an explicit
|
|
54
|
+
* {@link https://getodk.github.io/xforms-spec/#metadata | `deprecatedID` metadata element},
|
|
55
|
+
* one will be created.
|
|
56
|
+
*
|
|
57
|
+
* - If the instance has an `instanceID` metadata element, that element's value
|
|
58
|
+
* will be assigned to the instance's `deprecatedID`.
|
|
59
|
+
*
|
|
60
|
+
* - If applicable, a new instance id will be assigned:
|
|
61
|
+
*
|
|
62
|
+
* - If the instance has an `instanceID` metadata element, and the form
|
|
63
|
+
* explicitly defines a
|
|
64
|
+
* {@link https://getodk.github.io/xforms-spec/#preload-attributes | `uid` preload attribute}
|
|
65
|
+
* for its model binding, a new instance id value will be assigned to that
|
|
66
|
+
* element _as if it were the
|
|
67
|
+
* {@link https://getodk.github.io/xforms-spec/#event:odk-instance-first-load | instance's first load}_.
|
|
68
|
+
*
|
|
69
|
+
* - **Consistent with {@link FormInstanceCreateMode | instance creation}:**
|
|
70
|
+
* if the form **DOES NOT** define an `instanceID` element or model
|
|
71
|
+
* binding, the `uid` preload behavior described above is **implied** as
|
|
72
|
+
* the form's default behavior for that metadata; in which case whether
|
|
73
|
+
* the instance defines an `instanceID` element explicitly or not, it will
|
|
74
|
+
* be treated as if it had, behaving as described in the point above.
|
|
75
|
+
*
|
|
76
|
+
* **NOTE:** the behavior for an instance's `instanceID` metadata element and a
|
|
77
|
+
* form's `uid` preload attribute describe a special case, applying only to that
|
|
78
|
+
* specific preload attribute. In other words, when initializing instance state
|
|
79
|
+
* for editing:
|
|
80
|
+
*
|
|
81
|
+
* - The `odk-instance-first-load` event itself will **NOT** be triggered
|
|
82
|
+
* - Preload attributes _other than `uid`_ will **NOT** be recomputed
|
|
83
|
+
*
|
|
84
|
+
* **NOTE:** while the `uid` preload attribute is discussed above in terms of
|
|
85
|
+
* the `instanceID` meta element, its behavior is not applied specially to any
|
|
86
|
+
* particular node, regardless of
|
|
87
|
+
* {@link FormInstanceInitializationMode | initialization mode}.
|
|
88
|
+
*/
|
|
89
|
+
export type FormInstanceEditMode = 'edit';
|
|
90
|
+
|
|
91
|
+
// prettier-ignore
|
|
92
|
+
export type FormInstanceInitializationMode =
|
|
93
|
+
| FormInstanceCreateMode
|
|
94
|
+
| FormInstanceEditMode
|
|
95
|
+
| FormInstanceRestoreMode;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @todo this could hypothetically convey warnings and/or errors, just as
|
|
99
|
+
* {@link LoadFormResult} does. This has been deferred because:
|
|
100
|
+
*
|
|
101
|
+
* - We really want a more thoughtful design for Result types
|
|
102
|
+
* - The `try`/`catch` approach to capturing all errors takes a huge performance
|
|
103
|
+
* hit, which we should not incur if we have a more thoughtful design coming
|
|
104
|
+
* eventually. It would be too easy to forget about, indefinitely!
|
|
105
|
+
*/
|
|
106
|
+
export interface FormInstance<Mode extends FormInstanceInitializationMode> {
|
|
107
|
+
readonly formResult: InstantiableLoadFormResult;
|
|
108
|
+
readonly mode: Mode;
|
|
109
|
+
readonly root: RootNode;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export type AnyFormInstance = {
|
|
113
|
+
[Mode in FormInstanceInitializationMode]: FormInstance<Mode>;
|
|
114
|
+
}[FormInstanceInitializationMode];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { OpaqueReactiveObjectFactory } from '../OpaqueReactiveObjectFactory.ts';
|
|
2
|
+
|
|
3
|
+
export interface FormInstanceConfig {
|
|
4
|
+
/**
|
|
5
|
+
* A client may specify a generic function for constructing stateful objects.
|
|
6
|
+
* The only hard requirement of this function is that it accepts an **object**
|
|
7
|
+
* and returns an object of the same shape. The engine will use this function
|
|
8
|
+
* to initialize client-facing state, and will mutate properties of the object
|
|
9
|
+
* when their corresponding state is changed.
|
|
10
|
+
*
|
|
11
|
+
* A client may use this function to provide its own implementation of
|
|
12
|
+
* reactivity with semantics like those described above. The mechanism of
|
|
13
|
+
* reactivity, if any, is at the discretion of the client. It is expected that
|
|
14
|
+
* clients providing this function will use a reactive subscribe-on-read
|
|
15
|
+
* mechanism to handle state updates conveyed by the engine.
|
|
16
|
+
*/
|
|
17
|
+
readonly stateFactory?: OpaqueReactiveObjectFactory;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type FormResource = Blob | File | URL | string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { loadForm } from '../../entrypoints/loadForm.ts';
|
|
2
|
+
import type { MissingResourceBehavior } from '../constants.ts';
|
|
3
|
+
import type { FetchFormAttachment, FetchResource } from '../resources.ts';
|
|
4
|
+
import type { FormResource } from './FormResource.ts';
|
|
5
|
+
import type { LoadFormFailureResult, LoadFormResult } from './LoadFormResult.ts';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @see {@link LoadForm}
|
|
9
|
+
*/
|
|
10
|
+
export interface FormLoadPromise<T> extends PromiseLike<T> {}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Any fetch-like {@link LoadFormOptions | form loading options} which are not
|
|
14
|
+
* provided will default to the global {@link fetch} function, if one is
|
|
15
|
+
* available in the calling environment. If a global {@link fetch} function is
|
|
16
|
+
* _is not available_, and if the associated form loading option is required for
|
|
17
|
+
* the provided {@link FormResource} to be loaded, a
|
|
18
|
+
* {@link LoadFormFailureResult} will be produced.
|
|
19
|
+
*/
|
|
20
|
+
export type GlobalFetchDefault = typeof fetch;
|
|
21
|
+
|
|
22
|
+
export interface LoadFormOptions {
|
|
23
|
+
/**
|
|
24
|
+
* A client may specify an arbitrary {@link fetch}-like function for
|
|
25
|
+
* retrieving an XML XForm form definition.
|
|
26
|
+
*
|
|
27
|
+
* Calls to {@link loadForm | load a form} from a form definition provided as
|
|
28
|
+
* either a raw XML string or {@link Blob} data containing an XML string, this
|
|
29
|
+
* option will be ignored.
|
|
30
|
+
*
|
|
31
|
+
* Calls to load a form by {@link URL} will consult this option, if defined.
|
|
32
|
+
*
|
|
33
|
+
* If this option is omitted, loading a form by URL will use the
|
|
34
|
+
* {@link GlobalFetchDefault | global fetch function} by default.
|
|
35
|
+
*/
|
|
36
|
+
readonly fetchFormDefinition?: FetchResource;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A client may specify an arbitrary {@link fetch}-like function to retrieve a
|
|
40
|
+
* form's attachments, i.e. any `jr:` URL referenced by the form (as specified
|
|
41
|
+
* by {@link https://getodk.github.io/xforms-spec/ | ODK XForms}).
|
|
42
|
+
*
|
|
43
|
+
* As part of {@link loadForm | loading a form}, once the form definition
|
|
44
|
+
* itself is resolved, this option (if provided) will be consulted to load any
|
|
45
|
+
* form attachments referenced by the form definition.
|
|
46
|
+
*
|
|
47
|
+
* If this option is omitted, the engine will attempt to load form attachments
|
|
48
|
+
* by calling the {@link GlobalFetchDefault | global fetch function} with each
|
|
49
|
+
* attachment's `jr:` URL. This default behavior will typically result in
|
|
50
|
+
* failure to load form attachments—and in most cases this will in most cases
|
|
51
|
+
* cause {@link loadForm | loading a form} to produce a
|
|
52
|
+
* {@link LoadFormFailureResult}, with the following exception:
|
|
53
|
+
*
|
|
54
|
+
* Clients implementing a
|
|
55
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API | Service Worker}
|
|
56
|
+
* (e.g. supporting offline functionality, or any other use case for
|
|
57
|
+
* intercepting network requests) may opt for the convenience of handling
|
|
58
|
+
* network requests _for form attachments' `jr:` URLs_ along with any other
|
|
59
|
+
* network interception logic. Client implementors should be warned, however,
|
|
60
|
+
* that such `jr:` URLs are not namespaced or otherwise scoped to a particular
|
|
61
|
+
* form definition! Such a client would therefore inherently need to
|
|
62
|
+
* coordinate state between the Service Worker and the main thread (or
|
|
63
|
+
* whatever other realm calls {@link loadForm}).
|
|
64
|
+
*
|
|
65
|
+
* @todo We can almost certainly address the scoping caveat! We'll probably
|
|
66
|
+
* want to design for that as part of offline support.
|
|
67
|
+
*/
|
|
68
|
+
// TODO (internal): Also note that the current round of revisions to
|
|
69
|
+
// engine/client entrypoints are not directly designed to address the above
|
|
70
|
+
// `@todo`, but the offline use case in particular is very much in mind for
|
|
71
|
+
// these interface changes!
|
|
72
|
+
readonly fetchFormAttachment?: FetchFormAttachment;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @see {@link MissingResourceBehavior}
|
|
76
|
+
* @see {@link MissingResourceBehaviorDefault}
|
|
77
|
+
*
|
|
78
|
+
* @default MissingResourceBehaviorDefault
|
|
79
|
+
*/
|
|
80
|
+
readonly missingResourceBehavior?: MissingResourceBehavior;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Note: loading a form produce a {@link Promise} which **will never reject**.
|
|
85
|
+
* Rather than rejecting, any errors encountered in the process of loading a
|
|
86
|
+
* form will be **resolved**, in a
|
|
87
|
+
* {@link LoadFormFailureResult.error | FormLoadFailureResult error}.
|
|
88
|
+
*/
|
|
89
|
+
export type LoadForm = (
|
|
90
|
+
formResource: FormResource,
|
|
91
|
+
options?: LoadFormOptions
|
|
92
|
+
) => FormLoadPromise<LoadFormResult>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { UnknownObject } from '@getodk/common/lib/type-assertions/assertUnknownObject.ts';
|
|
2
|
+
import type { AnyFunction } from '@getodk/common/types/helpers.js';
|
|
3
|
+
import type { LoadFormFailureError } from '../../error/LoadFormFailureError.ts';
|
|
4
|
+
import type { CreateFormInstance } from './CreateFormInstance.ts';
|
|
5
|
+
import type { EditFormInstance } from './EditFormInstance.ts';
|
|
6
|
+
import type { RestoreFormInstance } from './RestoreFormInstance.ts';
|
|
7
|
+
|
|
8
|
+
// Re-export for client access
|
|
9
|
+
export type { LoadFormFailureError };
|
|
10
|
+
|
|
11
|
+
// prettier-ignore
|
|
12
|
+
export type FormResultStatus =
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
14
|
+
| 'success'
|
|
15
|
+
| 'warning'
|
|
16
|
+
| 'failure';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @todo Pending design and modeling of warning cases.
|
|
20
|
+
*/
|
|
21
|
+
export type LoadFormWarnings = UnknownObject;
|
|
22
|
+
|
|
23
|
+
// prettier-ignore
|
|
24
|
+
type FailedLoadFormResultMethodParameters<T extends AnyFunction> =
|
|
25
|
+
& readonly never[]
|
|
26
|
+
& (
|
|
27
|
+
Parameters<T> extends { readonly length: infer Length extends number }
|
|
28
|
+
? { readonly length: Length }
|
|
29
|
+
: never
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
export type FailedLoadFormResultMethod<T extends AnyFunction> = (
|
|
33
|
+
...args: FailedLoadFormResultMethodParameters<T>
|
|
34
|
+
) => never;
|
|
35
|
+
|
|
36
|
+
// prettier-ignore
|
|
37
|
+
export type FallibleLoadFormResultMethod<T extends AnyFunction> =
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
|
|
39
|
+
| T
|
|
40
|
+
| FailedLoadFormResultMethod<T>;
|
|
41
|
+
|
|
42
|
+
interface BaseLoadFormResult {
|
|
43
|
+
readonly status: FormResultStatus;
|
|
44
|
+
readonly warnings: LoadFormWarnings | null;
|
|
45
|
+
readonly error: LoadFormFailureError | null;
|
|
46
|
+
readonly createInstance: FallibleLoadFormResultMethod<CreateFormInstance>;
|
|
47
|
+
readonly editInstance: FallibleLoadFormResultMethod<EditFormInstance>;
|
|
48
|
+
readonly restoreInstance: FallibleLoadFormResultMethod<RestoreFormInstance>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface LoadFormSuccessResult extends BaseLoadFormResult {
|
|
52
|
+
readonly status: 'success';
|
|
53
|
+
readonly warnings: null;
|
|
54
|
+
readonly error: null;
|
|
55
|
+
readonly createInstance: CreateFormInstance;
|
|
56
|
+
readonly editInstance: EditFormInstance;
|
|
57
|
+
readonly restoreInstance: RestoreFormInstance;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface LoadFormWarningResult extends BaseLoadFormResult {
|
|
61
|
+
readonly status: 'warning';
|
|
62
|
+
readonly warnings: LoadFormWarnings;
|
|
63
|
+
readonly error: null;
|
|
64
|
+
readonly createInstance: CreateFormInstance;
|
|
65
|
+
readonly editInstance: EditFormInstance;
|
|
66
|
+
readonly restoreInstance: RestoreFormInstance;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface LoadFormFailureResult extends BaseLoadFormResult {
|
|
70
|
+
readonly status: 'failure';
|
|
71
|
+
readonly warnings: LoadFormWarnings | null;
|
|
72
|
+
readonly error: LoadFormFailureError;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @example A temporary demo integration was built during development of this
|
|
76
|
+
* interface.
|
|
77
|
+
*
|
|
78
|
+
* @see
|
|
79
|
+
* {@link https://github.com/getodk/web-forms/pull/345/commits/9ef36355d89dd1450d3a87c3a55506bb9b0fc414}
|
|
80
|
+
*/
|
|
81
|
+
readonly createInstance: FailedLoadFormResultMethod<CreateFormInstance>;
|
|
82
|
+
|
|
83
|
+
readonly editInstance: FailedLoadFormResultMethod<EditFormInstance>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @example A temporary demo integration was built during development of this
|
|
87
|
+
* interface.
|
|
88
|
+
*
|
|
89
|
+
* @see
|
|
90
|
+
* {@link https://github.com/getodk/web-forms/pull/345/commits/9ef36355d89dd1450d3a87c3a55506bb9b0fc414}
|
|
91
|
+
*/
|
|
92
|
+
readonly restoreInstance: FailedLoadFormResultMethod<RestoreFormInstance>;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// prettier-ignore
|
|
96
|
+
export type InstantiableLoadFormResult =
|
|
97
|
+
| LoadFormSuccessResult
|
|
98
|
+
| LoadFormWarningResult
|
|
99
|
+
|
|
100
|
+
// prettier-ignore
|
|
101
|
+
export type LoadFormResult =
|
|
102
|
+
| InstantiableLoadFormResult
|
|
103
|
+
| LoadFormFailureResult;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InstanceData } from '../serialization/InstanceData.ts';
|
|
2
|
+
import type { FormInstance, FormInstanceRestoreMode } from './FormInstance.ts';
|
|
3
|
+
import type { FormInstanceConfig } from './FormInstanceConfig.ts';
|
|
4
|
+
|
|
5
|
+
export interface RestoreFormInstanceInput {
|
|
6
|
+
readonly data: readonly [InstanceData, ...InstanceData[]];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type RestoredFormInstance = FormInstance<FormInstanceRestoreMode>;
|
|
10
|
+
|
|
11
|
+
export type RestoreFormInstance = (
|
|
12
|
+
input: RestoreFormInstanceInput,
|
|
13
|
+
config?: FormInstanceConfig
|
|
14
|
+
) => Promise<RestoredFormInstance>;
|