@getodk/xforms-engine 0.6.0 → 0.8.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.
Files changed (332) hide show
  1. package/dist/client/BaseNode.d.ts +4 -4
  2. package/dist/client/BaseValueNode.d.ts +7 -3
  3. package/dist/client/RootNode.d.ts +20 -16
  4. package/dist/client/UploadNode.d.ts +53 -0
  5. package/dist/client/attachments/InstanceAttachmentMeta.d.ts +8 -0
  6. package/dist/client/attachments/InstanceAttachmentsConfig.d.ts +8 -0
  7. package/dist/client/constants.d.ts +11 -12
  8. package/dist/client/form/CreateFormInstance.d.ts +14 -0
  9. package/dist/client/form/EditFormInstance.d.ts +62 -0
  10. package/dist/client/form/FormInstance.d.ts +104 -0
  11. package/dist/client/form/FormInstanceConfig.d.ts +19 -0
  12. package/dist/client/form/FormResource.d.ts +1 -0
  13. package/dist/client/form/LoadForm.d.ts +79 -0
  14. package/dist/client/form/LoadFormResult.d.ts +67 -0
  15. package/dist/client/form/RestoreFormInstance.d.ts +8 -0
  16. package/dist/client/hierarchy.d.ts +4 -5
  17. package/dist/client/index.d.ts +40 -11
  18. package/dist/client/node-types.d.ts +2 -3
  19. package/dist/client/repeat/BaseRepeatRangeNode.d.ts +3 -4
  20. package/dist/client/repeat/RepeatInstanceNode.d.ts +4 -5
  21. package/dist/client/repeat/RepeatRangeControlledNode.d.ts +2 -2
  22. package/dist/client/repeat/RepeatRangeUncontrolledNode.d.ts +2 -2
  23. package/dist/client/resources.d.ts +1 -1
  24. package/dist/client/serialization/InstanceData.d.ts +14 -0
  25. package/dist/client/serialization/InstanceFile.d.ts +6 -0
  26. package/dist/client/serialization/InstancePayload.d.ts +93 -0
  27. package/dist/client/serialization/InstancePayloadOptions.d.ts +24 -0
  28. package/dist/client/serialization/InstanceState.d.ts +12 -0
  29. package/dist/client/submission/{SubmissionDefinition.d.ts → SubmissionMeta.d.ts} +1 -1
  30. package/dist/entrypoints/FormInstance.d.ts +20 -0
  31. package/dist/entrypoints/FormResult/BaseFormResult.d.ts +22 -0
  32. package/dist/entrypoints/FormResult/BaseInstantiableFormResult.d.ts +25 -0
  33. package/dist/entrypoints/FormResult/FormFailureResult.d.ts +17 -0
  34. package/dist/entrypoints/FormResult/FormSuccessResult.d.ts +15 -0
  35. package/dist/entrypoints/FormResult/FormWarningResult.d.ts +15 -0
  36. package/dist/entrypoints/createInstance.d.ts +9 -0
  37. package/dist/entrypoints/editInstance.d.ts +9 -0
  38. package/dist/entrypoints/index.d.ts +4 -0
  39. package/dist/entrypoints/loadForm.d.ts +4 -0
  40. package/dist/entrypoints/restoreInstance.d.ts +9 -0
  41. package/dist/error/LoadFormFailureError.d.ts +9 -0
  42. package/dist/error/MalformedInstanceDataError.d.ts +3 -0
  43. package/dist/error/TemplatedNodeAttributeSerializationError.d.ts +22 -0
  44. package/dist/error/UploadValueTypeError.d.ts +8 -0
  45. package/dist/index.d.ts +2 -33
  46. package/dist/index.js +8280 -6779
  47. package/dist/index.js.map +1 -1
  48. package/dist/instance/Group.d.ts +6 -5
  49. package/dist/instance/InputControl.d.ts +5 -4
  50. package/dist/instance/ModelValue.d.ts +5 -4
  51. package/dist/instance/Note.d.ts +4 -3
  52. package/dist/instance/PrimaryInstance.d.ts +34 -8
  53. package/dist/instance/RangeControl.d.ts +5 -4
  54. package/dist/instance/RankControl.d.ts +6 -5
  55. package/dist/instance/Root.d.ts +7 -9
  56. package/dist/instance/SelectControl.d.ts +4 -3
  57. package/dist/instance/Subtree.d.ts +6 -5
  58. package/dist/instance/TriggerControl.d.ts +4 -3
  59. package/dist/instance/UploadControl.d.ts +58 -0
  60. package/dist/instance/abstract/DescendantNode.d.ts +10 -1
  61. package/dist/instance/abstract/InstanceNode.d.ts +7 -4
  62. package/dist/instance/abstract/ValueNode.d.ts +7 -5
  63. package/dist/instance/attachments/InstanceAttachment.d.ts +42 -0
  64. package/dist/instance/attachments/InstanceAttachmentsState.d.ts +9 -0
  65. package/dist/instance/children/DescendantNodeInitOptions.d.ts +32 -0
  66. package/dist/instance/{children.d.ts → children/buildChildren.d.ts} +1 -1
  67. package/dist/instance/children/childrenInitOptions.d.ts +9 -0
  68. package/dist/instance/children/normalizeChildInitOptions.d.ts +2 -0
  69. package/dist/instance/hierarchy.d.ts +6 -7
  70. package/dist/instance/input/InitialInstanceState.d.ts +13 -0
  71. package/dist/instance/input/InstanceAttachmentMap.d.ts +19 -0
  72. package/dist/instance/internal-api/InstanceAttachmentContext.d.ts +19 -0
  73. package/dist/instance/internal-api/InstanceConfig.d.ts +4 -9
  74. package/dist/instance/internal-api/InstanceValueContext.d.ts +8 -1
  75. package/dist/instance/internal-api/serialization/ClientReactiveSerializableInstance.d.ts +16 -0
  76. package/dist/instance/internal-api/serialization/ClientReactiveSerializableLeafNode.d.ts +32 -0
  77. package/dist/instance/internal-api/serialization/ClientReactiveSerializableParentNode.d.ts +18 -0
  78. package/dist/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.d.ts +13 -0
  79. package/dist/instance/internal-api/serialization/ClientReactiveSerializableValueNode.d.ts +21 -0
  80. package/dist/instance/repeat/BaseRepeatRange.d.ts +10 -8
  81. package/dist/instance/repeat/RepeatInstance.d.ts +10 -7
  82. package/dist/instance/repeat/RepeatRangeControlled.d.ts +27 -3
  83. package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +4 -3
  84. package/dist/instance/resource.d.ts +5 -1
  85. package/dist/integration/xpath/EngineXPathEvaluator.d.ts +2 -2
  86. package/dist/integration/xpath/adapter/kind.d.ts +4 -10
  87. package/dist/integration/xpath/static-dom/StaticAttribute.d.ts +4 -5
  88. package/dist/integration/xpath/static-dom/StaticDocument.d.ts +13 -10
  89. package/dist/integration/xpath/static-dom/StaticElement.d.ts +21 -22
  90. package/dist/integration/xpath/static-dom/StaticNode.d.ts +1 -1
  91. package/dist/integration/xpath/static-dom/StaticParentNode.d.ts +13 -0
  92. package/dist/integration/xpath/static-dom/staticNodeName.d.ts +3 -0
  93. package/dist/lib/client-reactivity/instance-state/createNodeRangeInstanceState.d.ts +4 -0
  94. package/dist/lib/client-reactivity/instance-state/createParentNodeInstanceState.d.ts +4 -0
  95. package/dist/lib/client-reactivity/instance-state/createPrimaryInstanceState.d.ts +3 -0
  96. package/dist/lib/client-reactivity/instance-state/createRootInstanceState.d.ts +3 -0
  97. package/dist/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.d.ts +6 -0
  98. package/dist/lib/client-reactivity/instance-state/createValueNodeInstanceState.d.ts +3 -0
  99. package/dist/lib/client-reactivity/instance-state/prepareInstancePayload.d.ts +8 -0
  100. package/dist/lib/names/UnprefixedXFormsName.d.ts +4 -0
  101. package/dist/lib/reactivity/createInstanceAttachment.d.ts +8 -0
  102. package/dist/lib/reactivity/createInstanceValueState.d.ts +2 -27
  103. package/dist/lib/resource-helpers.d.ts +2 -0
  104. package/dist/parse/XFormDOM.d.ts +1 -1
  105. package/dist/parse/body/BodyDefinition.d.ts +2 -1
  106. package/dist/parse/body/control/UploadControlDefinition.d.ts +2 -0
  107. package/dist/parse/model/BindDefinition.d.ts +1 -1
  108. package/dist/parse/model/BindTypeDefinition.d.ts +2 -7
  109. package/dist/parse/model/ItextTranslationsDefinition.d.ts +18 -0
  110. package/dist/parse/model/LeafNodeDefinition.d.ts +4 -5
  111. package/dist/parse/model/ModelBindMap.d.ts +1 -1
  112. package/dist/parse/model/ModelDefinition.d.ts +9 -2
  113. package/dist/parse/model/NodeDefinition.d.ts +18 -30
  114. package/dist/parse/model/NoteNodeDefinition.d.ts +3 -2
  115. package/dist/parse/model/RangeNodeDefinition.d.ts +2 -1
  116. package/dist/parse/model/RepeatDefinition.d.ts +62 -0
  117. package/dist/parse/model/RootAttributeDefinition.d.ts +1 -4
  118. package/dist/parse/model/RootAttributeMap.d.ts +2 -1
  119. package/dist/parse/model/RootDefinition.d.ts +7 -8
  120. package/dist/parse/model/SecondaryInstance/SecondaryInstancesDefinition.d.ts +15 -2
  121. package/dist/parse/model/SecondaryInstance/assertSecondaryInstanceDefinition.d.ts +5 -0
  122. package/dist/parse/model/SecondaryInstance/defineSecondaryInstance.d.ts +5 -0
  123. package/dist/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.d.ts +1 -7
  124. package/dist/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.d.ts +1 -1
  125. package/dist/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.d.ts +1 -1
  126. package/dist/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.d.ts +1 -1
  127. package/dist/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.d.ts +1 -1
  128. package/dist/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.d.ts +1 -1
  129. package/dist/parse/model/{FormSubmissionDefinition.d.ts → SubmissionDefinition.d.ts} +2 -2
  130. package/dist/parse/model/SubtreeDefinition.d.ts +4 -5
  131. package/dist/parse/model/nodeDefinitionMap.d.ts +5 -0
  132. package/dist/parse/shared/parseInstanceXML.d.ts +21 -0
  133. package/dist/parse/shared/parseStaticDocumentFromDOMSubtree.d.ts +4 -21
  134. package/dist/solid.js +8251 -6751
  135. package/dist/solid.js.map +1 -1
  136. package/package.json +15 -14
  137. package/src/client/BaseNode.ts +4 -4
  138. package/src/client/BaseValueNode.ts +7 -3
  139. package/src/client/RootNode.ts +32 -19
  140. package/src/client/UploadNode.ts +78 -0
  141. package/src/client/attachments/InstanceAttachmentMeta.ts +10 -0
  142. package/src/client/attachments/InstanceAttachmentsConfig.ts +13 -0
  143. package/src/client/constants.ts +12 -14
  144. package/src/client/form/CreateFormInstance.ts +19 -0
  145. package/src/client/form/EditFormInstance.ts +93 -0
  146. package/src/client/form/FormInstance.ts +114 -0
  147. package/src/client/form/FormInstanceConfig.ts +21 -0
  148. package/src/client/form/FormResource.ts +1 -0
  149. package/src/client/form/LoadForm.ts +92 -0
  150. package/src/client/form/LoadFormResult.ts +103 -0
  151. package/src/client/form/RestoreFormInstance.ts +14 -0
  152. package/src/client/hierarchy.ts +5 -8
  153. package/src/client/index.ts +49 -29
  154. package/src/client/node-types.ts +3 -8
  155. package/src/client/repeat/BaseRepeatRangeNode.ts +3 -4
  156. package/src/client/repeat/RepeatInstanceNode.ts +4 -8
  157. package/src/client/repeat/RepeatRangeControlledNode.ts +2 -2
  158. package/src/client/repeat/RepeatRangeUncontrolledNode.ts +2 -2
  159. package/src/client/resources.ts +2 -2
  160. package/src/client/serialization/InstanceData.ts +24 -0
  161. package/src/client/serialization/InstanceFile.ts +9 -0
  162. package/src/client/serialization/InstancePayload.ts +126 -0
  163. package/src/client/serialization/InstancePayloadOptions.ts +29 -0
  164. package/src/client/serialization/InstanceState.ts +14 -0
  165. package/src/client/submission/{SubmissionDefinition.ts → SubmissionMeta.ts} +1 -1
  166. package/src/entrypoints/FormInstance.ts +56 -0
  167. package/src/entrypoints/FormResult/BaseFormResult.ts +40 -0
  168. package/src/entrypoints/FormResult/BaseInstantiableFormResult.ts +109 -0
  169. package/src/entrypoints/FormResult/FormFailureResult.ts +44 -0
  170. package/src/entrypoints/FormResult/FormSuccessResult.ts +25 -0
  171. package/src/entrypoints/FormResult/FormWarningResult.ts +25 -0
  172. package/src/entrypoints/createInstance.ts +23 -0
  173. package/src/entrypoints/editInstance.ts +24 -0
  174. package/src/entrypoints/index.ts +4 -0
  175. package/src/entrypoints/loadForm.ts +154 -0
  176. package/src/entrypoints/restoreInstance.ts +27 -0
  177. package/src/error/LoadFormFailureError.ts +114 -0
  178. package/src/error/MalformedInstanceDataError.ts +3 -0
  179. package/src/error/TemplatedNodeAttributeSerializationError.ts +24 -0
  180. package/src/error/UploadValueTypeError.ts +13 -0
  181. package/src/index.ts +2 -46
  182. package/src/instance/Group.ts +16 -15
  183. package/src/instance/InputControl.ts +17 -11
  184. package/src/instance/ModelValue.ts +17 -11
  185. package/src/instance/Note.ts +10 -9
  186. package/src/instance/PrimaryInstance.ts +68 -31
  187. package/src/instance/RangeControl.ts +17 -11
  188. package/src/instance/RankControl.ts +28 -19
  189. package/src/instance/Root.ts +20 -31
  190. package/src/instance/SelectControl.ts +21 -12
  191. package/src/instance/Subtree.ts +16 -15
  192. package/src/instance/TriggerControl.ts +21 -12
  193. package/src/instance/UploadControl.ts +184 -0
  194. package/src/instance/abstract/DescendantNode.ts +12 -2
  195. package/src/instance/abstract/InstanceNode.ts +9 -5
  196. package/src/instance/abstract/ValueNode.ts +11 -13
  197. package/src/instance/attachments/InstanceAttachment.ts +69 -0
  198. package/src/instance/attachments/InstanceAttachmentsState.ts +18 -0
  199. package/src/instance/children/DescendantNodeInitOptions.ts +35 -0
  200. package/src/instance/{children.ts → children/buildChildren.ts} +57 -53
  201. package/src/instance/children/childrenInitOptions.ts +117 -0
  202. package/src/instance/children/normalizeChildInitOptions.ts +332 -0
  203. package/src/instance/hierarchy.ts +6 -9
  204. package/src/instance/input/InitialInstanceState.ts +108 -0
  205. package/src/instance/input/InstanceAttachmentMap.ts +154 -0
  206. package/src/instance/internal-api/InstanceAttachmentContext.ts +20 -0
  207. package/src/instance/internal-api/InstanceConfig.ts +6 -10
  208. package/src/instance/internal-api/InstanceValueContext.ts +9 -1
  209. package/src/instance/internal-api/serialization/ClientReactiveSerializableInstance.ts +22 -0
  210. package/src/instance/internal-api/serialization/ClientReactiveSerializableLeafNode.ts +43 -0
  211. package/src/instance/internal-api/serialization/ClientReactiveSerializableParentNode.ts +26 -0
  212. package/src/instance/internal-api/serialization/ClientReactiveSerializableTemplatedNode.ts +24 -0
  213. package/src/instance/internal-api/serialization/ClientReactiveSerializableValueNode.ts +28 -0
  214. package/src/instance/repeat/BaseRepeatRange.ts +19 -24
  215. package/src/instance/repeat/RepeatInstance.ts +26 -19
  216. package/src/instance/repeat/RepeatRangeControlled.ts +90 -17
  217. package/src/instance/repeat/RepeatRangeUncontrolled.ts +10 -9
  218. package/src/instance/resource.ts +14 -1
  219. package/src/integration/xpath/EngineXPathEvaluator.ts +2 -2
  220. package/src/integration/xpath/adapter/kind.ts +1 -28
  221. package/src/integration/xpath/adapter/traversal.ts +2 -2
  222. package/src/integration/xpath/static-dom/StaticAttribute.ts +6 -5
  223. package/src/integration/xpath/static-dom/StaticDocument.ts +17 -16
  224. package/src/integration/xpath/static-dom/StaticElement.ts +196 -50
  225. package/src/integration/xpath/static-dom/StaticNode.ts +1 -1
  226. package/src/integration/xpath/static-dom/StaticParentNode.ts +22 -0
  227. package/src/integration/xpath/static-dom/staticNodeName.ts +20 -0
  228. package/src/lib/client-reactivity/instance-state/createNodeRangeInstanceState.ts +17 -0
  229. package/src/lib/client-reactivity/instance-state/createParentNodeInstanceState.ts +22 -0
  230. package/src/lib/client-reactivity/instance-state/createPrimaryInstanceState.ts +12 -0
  231. package/src/lib/client-reactivity/{submission/createRootSubmissionState.ts → instance-state/createRootInstanceState.ts} +4 -4
  232. package/src/lib/client-reactivity/instance-state/createTemplatedNodeInstanceState.ts +31 -0
  233. package/src/lib/client-reactivity/instance-state/createValueNodeInstanceState.ts +21 -0
  234. package/src/lib/client-reactivity/instance-state/prepareInstancePayload.ts +237 -0
  235. package/src/lib/names/UnprefixedXFormsName.ts +12 -0
  236. package/src/lib/reactivity/createInstanceAttachment.ts +212 -0
  237. package/src/lib/reactivity/createInstanceValueState.ts +27 -51
  238. package/src/lib/resource-helpers.ts +33 -0
  239. package/src/parse/XFormDOM.ts +1 -3
  240. package/src/parse/body/BodyDefinition.ts +4 -0
  241. package/src/parse/body/control/UploadControlDefinition.ts +42 -0
  242. package/src/parse/model/BindDefinition.ts +1 -1
  243. package/src/parse/model/BindTypeDefinition.ts +68 -26
  244. package/src/parse/model/ItextTranslationsDefinition.ts +79 -0
  245. package/src/parse/model/LeafNodeDefinition.ts +3 -5
  246. package/src/parse/model/ModelBindMap.ts +0 -5
  247. package/src/parse/model/ModelDefinition.ts +36 -3
  248. package/src/parse/model/NodeDefinition.ts +19 -45
  249. package/src/parse/model/NoteNodeDefinition.ts +4 -3
  250. package/src/parse/model/RangeNodeDefinition.ts +3 -2
  251. package/src/parse/model/RepeatDefinition.ts +382 -0
  252. package/src/parse/model/RootAttributeDefinition.ts +6 -7
  253. package/src/parse/model/RootAttributeMap.ts +15 -10
  254. package/src/parse/model/RootDefinition.ts +17 -19
  255. package/src/parse/model/SecondaryInstance/SecondaryInstancesDefinition.ts +23 -2
  256. package/src/parse/model/SecondaryInstance/assertSecondaryInstanceDefinition.ts +14 -0
  257. package/src/parse/model/SecondaryInstance/defineSecondaryInstance.ts +32 -0
  258. package/src/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.ts +3 -24
  259. package/src/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.ts +33 -86
  260. package/src/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceResource.ts +1 -30
  261. package/src/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.ts +64 -137
  262. package/src/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.ts +9 -7
  263. package/src/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.ts +1 -1
  264. package/src/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.ts +7 -7
  265. package/src/parse/model/{FormSubmissionDefinition.ts → SubmissionDefinition.ts} +2 -2
  266. package/src/parse/model/SubtreeDefinition.ts +4 -5
  267. package/src/parse/model/nodeDefinitionMap.ts +34 -0
  268. package/src/parse/shared/parseInstanceXML.ts +79 -0
  269. package/src/parse/shared/parseStaticDocumentFromDOMSubtree.ts +45 -130
  270. package/dist/client/EngineConfig.d.ts +0 -79
  271. package/dist/client/submission/SubmissionData.d.ts +0 -7
  272. package/dist/client/submission/SubmissionInstanceFile.d.ts +0 -6
  273. package/dist/client/submission/SubmissionOptions.d.ts +0 -23
  274. package/dist/client/submission/SubmissionResult.d.ts +0 -91
  275. package/dist/client/submission/SubmissionState.d.ts +0 -12
  276. package/dist/client/unsupported/UnsupportedControlNode.d.ts +0 -30
  277. package/dist/client/unsupported/UploadNode.d.ts +0 -9
  278. package/dist/instance/abstract/UnsupportedControl.d.ts +0 -54
  279. package/dist/instance/index.d.ts +0 -8
  280. package/dist/instance/internal-api/ValueContext.d.ts +0 -23
  281. package/dist/instance/internal-api/submission/ClientReactiveSubmittableInstance.d.ts +0 -14
  282. package/dist/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.d.ts +0 -32
  283. package/dist/instance/internal-api/submission/ClientReactiveSubmittableParentNode.d.ts +0 -19
  284. package/dist/instance/internal-api/submission/ClientReactiveSubmittableValueNode.d.ts +0 -18
  285. package/dist/instance/unsupported/UploadControl.d.ts +0 -6
  286. package/dist/lib/client-reactivity/submission/createInstanceSubmissionState.d.ts +0 -3
  287. package/dist/lib/client-reactivity/submission/createLeafNodeSubmissionState.d.ts +0 -3
  288. package/dist/lib/client-reactivity/submission/createNodeRangeSubmissionState.d.ts +0 -4
  289. package/dist/lib/client-reactivity/submission/createParentNodeSubmissionState.d.ts +0 -4
  290. package/dist/lib/client-reactivity/submission/createRootSubmissionState.d.ts +0 -3
  291. package/dist/lib/client-reactivity/submission/createValueNodeSubmissionState.d.ts +0 -3
  292. package/dist/lib/client-reactivity/submission/prepareSubmission.d.ts +0 -8
  293. package/dist/lib/reactivity/createValueState.d.ts +0 -40
  294. package/dist/parse/model/ItextTranslation/ItextTranslationDefinition.d.ts +0 -4
  295. package/dist/parse/model/ItextTranslation/ItextTranslationRootDefinition.d.ts +0 -9
  296. package/dist/parse/model/ItextTranslation/ItextTranslationsDefinition.d.ts +0 -8
  297. package/dist/parse/model/RepeatInstanceDefinition.d.ts +0 -17
  298. package/dist/parse/model/RepeatRangeDefinition.d.ts +0 -32
  299. package/dist/parse/model/RepeatTemplateDefinition.d.ts +0 -31
  300. package/dist/parse/model/SecondaryInstance/SecondaryInstanceDefinition.d.ts +0 -4
  301. package/dist/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.d.ts +0 -7
  302. package/src/client/EngineConfig.ts +0 -84
  303. package/src/client/submission/SubmissionData.ts +0 -12
  304. package/src/client/submission/SubmissionInstanceFile.ts +0 -9
  305. package/src/client/submission/SubmissionOptions.ts +0 -28
  306. package/src/client/submission/SubmissionResult.ts +0 -124
  307. package/src/client/submission/SubmissionState.ts +0 -14
  308. package/src/client/unsupported/UnsupportedControlNode.ts +0 -36
  309. package/src/client/unsupported/UploadNode.ts +0 -14
  310. package/src/instance/abstract/UnsupportedControl.ts +0 -175
  311. package/src/instance/index.ts +0 -55
  312. package/src/instance/internal-api/ValueContext.ts +0 -28
  313. package/src/instance/internal-api/submission/ClientReactiveSubmittableInstance.ts +0 -20
  314. package/src/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.ts +0 -43
  315. package/src/instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts +0 -26
  316. package/src/instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts +0 -24
  317. package/src/instance/unsupported/UploadControl.ts +0 -9
  318. package/src/lib/client-reactivity/submission/createInstanceSubmissionState.ts +0 -12
  319. package/src/lib/client-reactivity/submission/createLeafNodeSubmissionState.ts +0 -20
  320. package/src/lib/client-reactivity/submission/createNodeRangeSubmissionState.ts +0 -17
  321. package/src/lib/client-reactivity/submission/createParentNodeSubmissionState.ts +0 -22
  322. package/src/lib/client-reactivity/submission/createValueNodeSubmissionState.ts +0 -21
  323. package/src/lib/client-reactivity/submission/prepareSubmission.ts +0 -172
  324. package/src/lib/reactivity/createValueState.ts +0 -200
  325. package/src/parse/model/ItextTranslation/ItextTranslationDefinition.ts +0 -4
  326. package/src/parse/model/ItextTranslation/ItextTranslationRootDefinition.ts +0 -42
  327. package/src/parse/model/ItextTranslation/ItextTranslationsDefinition.ts +0 -31
  328. package/src/parse/model/RepeatInstanceDefinition.ts +0 -38
  329. package/src/parse/model/RepeatRangeDefinition.ts +0 -98
  330. package/src/parse/model/RepeatTemplateDefinition.ts +0 -149
  331. package/src/parse/model/SecondaryInstance/SecondaryInstanceDefinition.ts +0 -4
  332. package/src/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.ts +0 -12
@@ -3,7 +3,7 @@ import { NodeAppearances } from './NodeAppearances.ts';
3
3
  import { TextRange } from './TextRange.ts';
4
4
  import { FormNodeID } from './identity.ts';
5
5
  import { InstanceNodeType } from './node-types.ts';
6
- import { SubmissionState } from './submission/SubmissionState.ts';
6
+ import { InstanceState } from './serialization/InstanceState.ts';
7
7
  import { NodeValidationState } from './validation.ts';
8
8
  export interface BaseNodeState {
9
9
  /**
@@ -211,14 +211,14 @@ export interface BaseNode {
211
211
  */
212
212
  readonly validationState: NodeValidationState;
213
213
  /**
214
- * Represents the current submission state of the node.
214
+ * Represents the current instance state of the node.
215
215
  *
216
- * @see {@link SubmissionState.submissionXML} for additional detail.
216
+ * @see {@link InstanceState.instanceXML} for additional detail.
217
217
  *
218
218
  * @todo Consider whether this can (should) be merged with
219
219
  * {@link currentState}, while providing the same client-reactivity
220
220
  * guarantees. (The challenge there is in defining client-reactive state which
221
221
  * self-referentially derives state from its own definition.)
222
222
  */
223
- readonly submissionState: SubmissionState;
223
+ readonly instanceState: InstanceState;
224
224
  }
@@ -2,6 +2,7 @@ import { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
2
2
  import { BaseNode, BaseNodeState } from './BaseNode.ts';
3
3
  import { GeneralParentNode } from './hierarchy.ts';
4
4
  import { LeafNodeType } from './node-types.ts';
5
+ import { InstanceState } from './serialization/InstanceState.ts';
5
6
  import { LeafNodeValidationState } from './validation.ts';
6
7
  import { ValueType } from './ValueType.ts';
7
8
  export interface BaseValueNodeState<Value> extends BaseNodeState {
@@ -13,12 +14,14 @@ export interface BaseValueNodeState<Value> extends BaseNodeState {
13
14
  * {@link value} state. This representation allows access to the node's value
14
15
  * _as primary instance state_. In other words, this is the value which:
15
16
  *
16
- * - would be serialized as a text node in
17
- * {@link SubmissionState.submissionXML} (note: this value is **NOT**
18
- * escaped for XML serialization, as it is there)
17
+ * - would be serialized as a text node in {@link InstanceState.instanceXML}
18
+ * (note: this value is **NOT** escaped for XML serialization, as it is
19
+ * there)
19
20
  *
20
21
  * - is used when the node's value is referenced in any of a form's XPath
21
22
  * expressions
23
+ *
24
+ * @todo Consider moving into {@link InstanceState}
22
25
  */
23
26
  get instanceValue(): string;
24
27
  }
@@ -29,4 +32,5 @@ export interface BaseValueNode<V extends ValueType = ValueType, Value = string>
29
32
  readonly parent: GeneralParentNode;
30
33
  readonly currentState: BaseValueNodeState<Value>;
31
34
  readonly validationState: LeafNodeValidationState;
35
+ readonly instanceState: InstanceState;
32
36
  }
@@ -3,8 +3,8 @@ import { RootDefinition } from '../parse/model/RootDefinition.ts';
3
3
  import { BaseNode, BaseNodeState } from './BaseNode.ts';
4
4
  import { ActiveLanguage, FormLanguage, FormLanguages } from './FormLanguage.ts';
5
5
  import { GeneralChildNode } from './hierarchy.ts';
6
- import { SubmissionOptions } from './submission/SubmissionOptions.ts';
7
- import { ChunkedSubmissionResult, MonolithicSubmissionResult } from './submission/SubmissionResult.ts';
6
+ import { ChunkedInstancePayload, InstancePayload, MonolithicInstancePayload } from './serialization/InstancePayload.ts';
7
+ import { InstancePayloadOptions, InstancePayloadType } from './serialization/InstancePayloadOptions.ts';
8
8
  import { AncestorNodeValidationState } from './validation.ts';
9
9
  export interface RootNodeState extends BaseNodeState {
10
10
  /**
@@ -50,33 +50,37 @@ export interface RootNode extends BaseNode {
50
50
  readonly languages: FormLanguages;
51
51
  setLanguage(language: FormLanguage): RootNode;
52
52
  /**
53
- * Prepares the current form instance state for submission.
53
+ * Prepares the current form instance state as an {@link InstancePayload}.
54
54
  *
55
- * A {@link SubmissionResult} will be prepared even if the current form state
56
- * includes `constraint` or `required` violations. This is intended to serve
57
- * two purposes:
55
+ * A payload will be prepared even if the current form state includes
56
+ * `constraint` or `required` violations. This supports serveral purposes:
58
57
  *
59
- * - A client may effectively use this method as a part of its own "submit"
60
- * routine, and use any violations included in the {@link SubmissionResult}
58
+ * - A client may effectively use this method as a part of its "submit"
59
+ * workflow, and use any violations included in the {@link InstancePayload}
61
60
  * to prompt users to address those violations.
62
61
  *
63
- * - A client may inspect the submission state of a form at any time.
62
+ * - A client may inspect the serialized instance state of a form at any time.
64
63
  * Depending on the client and use case, this may be a convenience (e.g. for
65
64
  * developers to inspect that form state at a current point in time); or it
66
65
  * may provide necessary functionality (e.g. for test or tooling clients).
67
66
  *
68
- * Note on asynchrony: preparing a {@link SubmissionResult} is expected to be
69
- * a fast operation. It may even be nearly instantaneous, or roughly
67
+ * - A client may capture _incomplete_ instance state (e.g. for storage in
68
+ * client-side storage or similar persistance layer), to resume filling the
69
+ * instance at a later time.
70
+ *
71
+ * Note on asynchrony: preparing a {@link InstancePayload} is expected to be a
72
+ * fast operation. It may even be nearly instantaneous, or roughly
70
73
  * proportionate to the size of the form itself. However, this method is
71
74
  * designed to be asynchronous out of an abundance of caution, anticipating
72
75
  * that some as-yet undeveloped operations on binary data (e.g. form
73
76
  * attachments) may themselves impose asynchrony (i.e. by interfaces provided
74
77
  * by the platform and/or external dependencies).
75
78
  *
76
- * A client may specify {@link SubmissionOptions<'chunked'>}, in which case a
77
- * {@link SubmissionResult<'chunked'>} will be produced, with form attachments
79
+ * A client may specify {@link InstancePayloadOptions<'chunked'>}, in which
80
+ * case a {@link ChunkedInstancePayload} will be produced, with form
81
+ * attachments
78
82
  */
79
- prepareSubmission(): Promise<MonolithicSubmissionResult>;
80
- prepareSubmission(options: SubmissionOptions<'monolithic'>): Promise<MonolithicSubmissionResult>;
81
- prepareSubmission(options: SubmissionOptions<'chunked'>): Promise<ChunkedSubmissionResult>;
83
+ prepareInstancePayload(options?: InstancePayloadOptions<'monolithic'>): Promise<MonolithicInstancePayload>;
84
+ prepareInstancePayload(options: InstancePayloadOptions<'chunked'>): Promise<ChunkedInstancePayload>;
85
+ prepareInstancePayload<PayloadType extends InstancePayloadType>(options: InstancePayloadOptions<PayloadType>): Promise<InstancePayload<PayloadType>>;
82
86
  }
@@ -0,0 +1,53 @@
1
+ import { PartiallyKnownString } from '../../../common/types/string/PartiallyKnownString.ts';
2
+ import { UnknownAppearanceDefinition } from '../parse/body/appearance/unknownAppearanceParser.ts';
3
+ import { UploadControlDefinition } from '../parse/body/control/UploadControlDefinition.ts';
4
+ import { LeafNodeDefinition } from '../parse/model/LeafNodeDefinition.ts';
5
+ import { BaseValueNode, BaseValueNodeState } from './BaseValueNode.ts';
6
+ import { GeneralParentNode } from './hierarchy.ts';
7
+ import { RootNode } from './RootNode.ts';
8
+ import { InstanceAttachmentFileName } from './serialization/InstanceData.ts';
9
+ import { LeafNodeValidationState } from './validation.ts';
10
+ import { ValueType } from './ValueType.ts';
11
+ export type UploadValue = File | null;
12
+ export interface UploadNodeState extends BaseValueNodeState<UploadValue> {
13
+ get valueOptions(): null;
14
+ get value(): UploadValue;
15
+ get instanceValue(): InstanceAttachmentFileName;
16
+ }
17
+ export interface UploadDefinition<V extends ValueType = ValueType> extends LeafNodeDefinition<V> {
18
+ readonly bodyElement: UploadControlDefinition;
19
+ }
20
+ export type UploadMediaType = PartiallyKnownString<'*' | 'audio' | 'image' | 'video'>;
21
+ export type UploadMediaSubtype = PartiallyKnownString<'*'>;
22
+ export type UploadMediaAccept = PartiallyKnownString<'*' | `${UploadMediaType}/${UploadMediaSubtype}`>;
23
+ interface BaseUploadMediaOptions {
24
+ readonly accept: UploadMediaAccept;
25
+ readonly type: UploadMediaType | null;
26
+ readonly subtype: UploadMediaSubtype | null;
27
+ }
28
+ export interface ExplicitUploadMediaOptions extends BaseUploadMediaOptions {
29
+ readonly type: UploadMediaType;
30
+ readonly subtype: UploadMediaSubtype;
31
+ }
32
+ export interface UnspecifiedUploadMediaOptions extends BaseUploadMediaOptions {
33
+ readonly type: null;
34
+ readonly subtype: null;
35
+ }
36
+ export type UploadMediaOptions = ExplicitUploadMediaOptions | UnspecifiedUploadMediaOptions;
37
+ export interface UploadNodeOptions {
38
+ readonly media: UploadMediaOptions;
39
+ }
40
+ export interface UploadNode extends BaseValueNode<'binary', UploadValue> {
41
+ readonly nodeType: 'upload';
42
+ /** @todo */
43
+ readonly appearances: UnknownAppearanceDefinition;
44
+ readonly nodeOptions: UploadNodeOptions;
45
+ readonly valueType: 'binary';
46
+ readonly definition: UploadDefinition<'binary'>;
47
+ readonly root: RootNode;
48
+ readonly parent: GeneralParentNode;
49
+ readonly currentState: UploadNodeState;
50
+ readonly validationState: LeafNodeValidationState;
51
+ setValue(value: UploadValue): RootNode;
52
+ }
53
+ export {};
@@ -0,0 +1,8 @@
1
+ import { FormNodeID } from '../identity.ts';
2
+ export type InstanceAttachmentExtension = `.${string}`;
3
+ export interface InstanceAttachmentMeta {
4
+ readonly nodeId: FormNodeID;
5
+ readonly writtenAt: Date | null;
6
+ readonly basename: string;
7
+ readonly extension: InstanceAttachmentExtension | null;
8
+ }
@@ -0,0 +1,8 @@
1
+ import { InstanceAttachmentMeta } from './InstanceAttachmentMeta.ts';
2
+ export interface UpdatedInstanceAttachmentMeta extends InstanceAttachmentMeta {
3
+ readonly writtenAt: Date;
4
+ }
5
+ export type InstanceAttachmentFileNameFactory = (meta: UpdatedInstanceAttachmentMeta) => string | null;
6
+ export interface InstanceAttachmentsConfig {
7
+ readonly fileNameFactory?: InstanceAttachmentFileNameFactory;
8
+ }
@@ -1,17 +1,16 @@
1
1
  import { ValidationTextRole } from './TextRange.ts';
2
2
  export declare const MISSING_RESOURCE_BEHAVIOR: {
3
3
  /**
4
- * When this behavior is configured, {@link InitializeForm | initializing} a
5
- * {@link PrimaryInstance} for a form which references any **missing**
6
- * resources will fail, producing an error to the calling client.
4
+ * When this behavior is configured, {@link LoadForm | loading a form} which
5
+ * references any **missing** resources will fail, producing an error to the
6
+ * calling client.
7
7
  *
8
8
  * @see {@link MissingResourceBehavior}
9
9
  */
10
10
  readonly ERROR: "ERROR";
11
11
  /**
12
- * When this behavior is configured, {@link InitializeForm | initializing} a
13
- * {@link PrimaryInstance} for a form which references any **missing**
14
- * resources will succeed (producing a warning).
12
+ * When this behavior is configured, {@link LoadForm | loading a form} which
13
+ * references any **missing** resources will succeed (producing a warning).
15
14
  *
16
15
  * Such missing resources will be parsed as if they are blank, as appropriate
17
16
  * for the resource's XForm semantic usage and/or format.
@@ -28,8 +27,8 @@ export type MissingResourceBehaviorError = typeof MISSING_RESOURCE_BEHAVIOR.ERRO
28
27
  export type MissingResourceBehaviorBlank = typeof MISSING_RESOURCE_BEHAVIOR.BLANK;
29
28
  export type MissingResourceBehaviorDefault = typeof MISSING_RESOURCE_BEHAVIOR.DEFAULT;
30
29
  /**
31
- * Specifies behavior for {@link InitializeForm | initializing} a form's
32
- * {@link PrimaryInstance} which references any **missing** resources.
30
+ * Specifies behavior for {@link LoadForm | loading a form} which references any
31
+ * **missing** resources.
33
32
  *
34
33
  * Here the term "missing" is consistent with
35
34
  * {@link https://www.rfc-editor.org/rfc/rfc9110#status.404 | HTTP 404 status}
@@ -51,8 +50,8 @@ export declare const VALIDATION_TEXT: {
51
50
  };
52
51
  type ValidationTextDefaults = typeof VALIDATION_TEXT;
53
52
  export type ValidationTextDefault<Role extends ValidationTextRole> = ValidationTextDefaults[Role];
54
- export declare const SUBMISSION_INSTANCE_FILE_NAME = "xml_submission_file";
55
- export type SubmissionInstanceFileName = typeof SUBMISSION_INSTANCE_FILE_NAME;
56
- export declare const SUBMISSION_INSTANCE_FILE_TYPE = "text/xml";
57
- export type SubmissionInstanceFileType = typeof SUBMISSION_INSTANCE_FILE_TYPE;
53
+ export declare const INSTANCE_FILE_NAME = "xml_submission_file";
54
+ export type INSTANCE_FILE_NAME = typeof INSTANCE_FILE_NAME;
55
+ export declare const INSTANCE_FILE_TYPE = "text/xml";
56
+ export type INSTANCE_FILE_TYPE = typeof INSTANCE_FILE_TYPE;
58
57
  export {};
@@ -0,0 +1,14 @@
1
+ import { FormInstance, FormInstanceCreateMode } from './FormInstance.ts';
2
+ import { FormInstanceConfig } from './FormInstanceConfig.ts';
3
+ export type CreatedFormInstance = FormInstance<FormInstanceCreateMode>;
4
+ /**
5
+ * @todo This is fallible! Client-facing interfaces will need to account for
6
+ * this. We've begun addressing fallibility _at the interface level_ in
7
+ * {@link LoadForm} (with {@link LoadFormResult}). We'll eventually have a more
8
+ * general interface pattern for this, and we'll apply it here as well. The baby
9
+ * step approach in {@link LoadFormResult} is impractical here due to
10
+ * engine-internal designs, and revising that is currently out of scope. As
11
+ * such, explicit interface-level documentation of fallibility is deferred here,
12
+ * on {@link RootNode} itself, and into any of its sub-interfaces.
13
+ */
14
+ export type CreateFormInstance = (config?: FormInstanceConfig) => CreatedFormInstance;
@@ -0,0 +1,62 @@
1
+ import { Awaitable, Thunk } from '../../../../common/types/helpers.d.ts';
2
+ import { FetchResourceResponse } from '../resources.ts';
3
+ import { InstanceAttachmentFileName, InstanceData } from '../serialization/InstanceData.ts';
4
+ import { FormInstance, FormInstanceEditMode } from './FormInstance.ts';
5
+ import { FormInstanceConfig } from './FormInstanceConfig.ts';
6
+ import { RestoreFormInstanceInput } from './RestoreFormInstance.ts';
7
+ export type ResolvableFormInstanceInputType = 'FORM_INSTANCE_INPUT_RESOLVABLE';
8
+ export type ResolvedFormInstanceInputType = 'FORM_INSTANCE_INPUT_RESOLVED';
9
+ export type EditFormInstanceInputType = ResolvableFormInstanceInputType | ResolvedFormInstanceInputType;
10
+ export type ResolvedFormInstance = Blob | FetchResourceResponse | File | string;
11
+ export type ResolvableFormInstance = Thunk<Awaitable<ResolvedFormInstance>>;
12
+ export type ResolveFormInstanceResource = Thunk<Promise<FetchResourceResponse>>;
13
+ export type ResolvableInstanceAttachmentsMap = ReadonlyMap<InstanceAttachmentFileName, ResolveFormInstanceResource>;
14
+ interface BaseEditFormInstanceInput {
15
+ readonly inputType: EditFormInstanceInputType;
16
+ readonly data?: readonly [InstanceData, ...InstanceData[]];
17
+ readonly resolveInstance?: ResolvableFormInstance;
18
+ readonly attachments?: ResolvableInstanceAttachmentsMap;
19
+ }
20
+ export interface ResolvableFormInstanceInput extends BaseEditFormInstanceInput {
21
+ readonly inputType: ResolvableFormInstanceInputType;
22
+ readonly resolveInstance: ResolvableFormInstance;
23
+ readonly attachments: ResolvableInstanceAttachmentsMap;
24
+ readonly data?: never;
25
+ }
26
+ /**
27
+ * @todo This is included as a strawman for discussiong: "should we accept input
28
+ * to {@link EditFormInstance} in the same shape as input to
29
+ * {@link RestoreFormInstance}?".
30
+ *
31
+ * Pros:
32
+ *
33
+ * - More consistency between the two entrypoint APIs, which are pretty similar
34
+ * _conceptually_.
35
+ * - ?
36
+ *
37
+ * Cons:
38
+ *
39
+ * - Less consistency between this entrypoint API and {@link LoadForm}, which is
40
+ * also responsible for loading arbitrary attachments (presumably over a
41
+ * network), which...
42
+ * - ... all but rules out flexibility to optimize loading large resources (i.e.
43
+ * streaming video/audio)
44
+ *
45
+ * Alternative:
46
+ *
47
+ * - Increase consistency across the board by inverting the relationship between
48
+ * edit/restore: {@link RestoreFormInstanceInput} could be the place where we
49
+ * accept a union of resolved | resolvable input, and clients which might
50
+ * benefit from this consistency could consolidate on the resolvable case
51
+ * without sacrificing resource loading optimizations)
52
+ */
53
+ export interface ResolvedFormInstanceInput extends BaseEditFormInstanceInput, RestoreFormInstanceInput {
54
+ readonly inputType: ResolvedFormInstanceInputType;
55
+ readonly data: readonly [InstanceData, ...InstanceData[]];
56
+ readonly resolveInstance?: never;
57
+ readonly attachments?: never;
58
+ }
59
+ export type EditFormInstanceInput = ResolvableFormInstanceInput | ResolvedFormInstanceInput;
60
+ export type EditedFormInstance = FormInstance<FormInstanceEditMode>;
61
+ export type EditFormInstance = (input: EditFormInstanceInput, config?: FormInstanceConfig) => Promise<EditedFormInstance>;
62
+ export {};
@@ -0,0 +1,104 @@
1
+ import { RootNode } from '../RootNode.ts';
2
+ import { InstantiableLoadFormResult } from './LoadFormResult.ts';
3
+ /**
4
+ * Represents an instance which is newly created from a form definition.
5
+ *
6
+ * A newly created instance is populated with default values and state defined
7
+ * by the form.
8
+ *
9
+ * Computations are performed on initialization as specified by
10
+ * {@link https://getodk.github.io/xforms-spec/ | ODK XForms}, as the instance's
11
+ * {@link https://getodk.github.io/xforms-spec/#event:odk-instance-first-load | first load}.
12
+ */
13
+ export type FormInstanceCreateMode = 'create';
14
+ /**
15
+ * Represents an instance restored from previously filled state, as represented
16
+ * in an {@link InstancePayload}. Clients may serialize and persist an instance
17
+ * payload as appropriate for their use cases, and can restore the instance with
18
+ * a partial instance payload structure, defined by the
19
+ * {@link RestoreFormInstanceInput} interface.
20
+ *
21
+ * A restored instance is populated by the engine with the answers as they had
22
+ * been filled at the time the {@link InstancePayload}
23
+ * ({@link RestoreFormInstanceInput}) was created.
24
+ *
25
+ * Computations are performed on initialization as specified by
26
+ * {@link https://getodk.github.io/xforms-spec/#event:odk-instance-load | ODK XForms},
27
+ * as a
28
+ * {@link https://getodk.github.io/xforms-spec/#event:odk-instance-load | subsequent load}
29
+ * (i.e. **NOT** "first load", as is the case with newly
30
+ * {@link FormInstanceCreateMode | created} instances}) of the instance.
31
+ */
32
+ export type FormInstanceRestoreMode = 'restore';
33
+ /**
34
+ * Represents an instance which:
35
+ *
36
+ * - was previously serialized
37
+ * - was **submitted**, often referred to as a "submission" (noun)
38
+ * - is being initialized to produce an edited instance of that "submission"
39
+ *
40
+ * An edited instance may be populated from one or more network-accessible
41
+ * resources—its serialized instance XML, and any _instance attachments_—which
42
+ * are resolved in a manner similar to that of a form definition and its _form
43
+ * attachments_.
44
+ *
45
+ * Once resolved, an edited instance is restored from its previously filled
46
+ * state _as it was submitted_, consistent with
47
+ * {@link FormInstanceRestoreMode | restoring an instance}, with the following
48
+ * exceptions:
49
+ *
50
+ * - If the form or instance does not define an explicit
51
+ * {@link https://getodk.github.io/xforms-spec/#metadata | `deprecatedID` metadata element},
52
+ * one will be created.
53
+ *
54
+ * - If the instance has an `instanceID` metadata element, that element's value
55
+ * will be assigned to the instance's `deprecatedID`.
56
+ *
57
+ * - If applicable, a new instance id will be assigned:
58
+ *
59
+ * - If the instance has an `instanceID` metadata element, and the form
60
+ * explicitly defines a
61
+ * {@link https://getodk.github.io/xforms-spec/#preload-attributes | `uid` preload attribute}
62
+ * for its model binding, a new instance id value will be assigned to that
63
+ * element _as if it were the
64
+ * {@link https://getodk.github.io/xforms-spec/#event:odk-instance-first-load | instance's first load}_.
65
+ *
66
+ * - **Consistent with {@link FormInstanceCreateMode | instance creation}:**
67
+ * if the form **DOES NOT** define an `instanceID` element or model
68
+ * binding, the `uid` preload behavior described above is **implied** as
69
+ * the form's default behavior for that metadata; in which case whether
70
+ * the instance defines an `instanceID` element explicitly or not, it will
71
+ * be treated as if it had, behaving as described in the point above.
72
+ *
73
+ * **NOTE:** the behavior for an instance's `instanceID` metadata element and a
74
+ * form's `uid` preload attribute describe a special case, applying only to that
75
+ * specific preload attribute. In other words, when initializing instance state
76
+ * for editing:
77
+ *
78
+ * - The `odk-instance-first-load` event itself will **NOT** be triggered
79
+ * - Preload attributes _other than `uid`_ will **NOT** be recomputed
80
+ *
81
+ * **NOTE:** while the `uid` preload attribute is discussed above in terms of
82
+ * the `instanceID` meta element, its behavior is not applied specially to any
83
+ * particular node, regardless of
84
+ * {@link FormInstanceInitializationMode | initialization mode}.
85
+ */
86
+ export type FormInstanceEditMode = 'edit';
87
+ export type FormInstanceInitializationMode = FormInstanceCreateMode | FormInstanceEditMode | FormInstanceRestoreMode;
88
+ /**
89
+ * @todo this could hypothetically convey warnings and/or errors, just as
90
+ * {@link LoadFormResult} does. This has been deferred because:
91
+ *
92
+ * - We really want a more thoughtful design for Result types
93
+ * - The `try`/`catch` approach to capturing all errors takes a huge performance
94
+ * hit, which we should not incur if we have a more thoughtful design coming
95
+ * eventually. It would be too easy to forget about, indefinitely!
96
+ */
97
+ export interface FormInstance<Mode extends FormInstanceInitializationMode> {
98
+ readonly formResult: InstantiableLoadFormResult;
99
+ readonly mode: Mode;
100
+ readonly root: RootNode;
101
+ }
102
+ export type AnyFormInstance = {
103
+ [Mode in FormInstanceInitializationMode]: FormInstance<Mode>;
104
+ }[FormInstanceInitializationMode];
@@ -0,0 +1,19 @@
1
+ import { InstanceAttachmentsConfig } from '../attachments/InstanceAttachmentsConfig.ts';
2
+ import { OpaqueReactiveObjectFactory } from '../OpaqueReactiveObjectFactory.ts';
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
+ readonly instanceAttachments?: InstanceAttachmentsConfig;
19
+ }
@@ -0,0 +1 @@
1
+ export type FormResource = Blob | File | URL | string;
@@ -0,0 +1,79 @@
1
+ import { MissingResourceBehavior } from '../constants.ts';
2
+ import { FetchFormAttachment, FetchResource } from '../resources.ts';
3
+ import { FormResource } from './FormResource.ts';
4
+ import { LoadFormResult } from './LoadFormResult.ts';
5
+ /**
6
+ * @see {@link LoadForm}
7
+ */
8
+ export interface FormLoadPromise<T> extends PromiseLike<T> {
9
+ }
10
+ /**
11
+ * Any fetch-like {@link LoadFormOptions | form loading options} which are not
12
+ * provided will default to the global {@link fetch} function, if one is
13
+ * available in the calling environment. If a global {@link fetch} function is
14
+ * _is not available_, and if the associated form loading option is required for
15
+ * the provided {@link FormResource} to be loaded, a
16
+ * {@link LoadFormFailureResult} will be produced.
17
+ */
18
+ export type GlobalFetchDefault = typeof fetch;
19
+ export interface LoadFormOptions {
20
+ /**
21
+ * A client may specify an arbitrary {@link fetch}-like function for
22
+ * retrieving an XML XForm form definition.
23
+ *
24
+ * Calls to {@link loadForm | load a form} from a form definition provided as
25
+ * either a raw XML string or {@link Blob} data containing an XML string, this
26
+ * option will be ignored.
27
+ *
28
+ * Calls to load a form by {@link URL} will consult this option, if defined.
29
+ *
30
+ * If this option is omitted, loading a form by URL will use the
31
+ * {@link GlobalFetchDefault | global fetch function} by default.
32
+ */
33
+ readonly fetchFormDefinition?: FetchResource;
34
+ /**
35
+ * A client may specify an arbitrary {@link fetch}-like function to retrieve a
36
+ * form's attachments, i.e. any `jr:` URL referenced by the form (as specified
37
+ * by {@link https://getodk.github.io/xforms-spec/ | ODK XForms}).
38
+ *
39
+ * As part of {@link loadForm | loading a form}, once the form definition
40
+ * itself is resolved, this option (if provided) will be consulted to load any
41
+ * form attachments referenced by the form definition.
42
+ *
43
+ * If this option is omitted, the engine will attempt to load form attachments
44
+ * by calling the {@link GlobalFetchDefault | global fetch function} with each
45
+ * attachment's `jr:` URL. This default behavior will typically result in
46
+ * failure to load form attachments—and in most cases this will in most cases
47
+ * cause {@link loadForm | loading a form} to produce a
48
+ * {@link LoadFormFailureResult}, with the following exception:
49
+ *
50
+ * Clients implementing a
51
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API | Service Worker}
52
+ * (e.g. supporting offline functionality, or any other use case for
53
+ * intercepting network requests) may opt for the convenience of handling
54
+ * network requests _for form attachments' `jr:` URLs_ along with any other
55
+ * network interception logic. Client implementors should be warned, however,
56
+ * that such `jr:` URLs are not namespaced or otherwise scoped to a particular
57
+ * form definition! Such a client would therefore inherently need to
58
+ * coordinate state between the Service Worker and the main thread (or
59
+ * whatever other realm calls {@link loadForm}).
60
+ *
61
+ * @todo We can almost certainly address the scoping caveat! We'll probably
62
+ * want to design for that as part of offline support.
63
+ */
64
+ readonly fetchFormAttachment?: FetchFormAttachment;
65
+ /**
66
+ * @see {@link MissingResourceBehavior}
67
+ * @see {@link MissingResourceBehaviorDefault}
68
+ *
69
+ * @default MissingResourceBehaviorDefault
70
+ */
71
+ readonly missingResourceBehavior?: MissingResourceBehavior;
72
+ }
73
+ /**
74
+ * Note: loading a form produce a {@link Promise} which **will never reject**.
75
+ * Rather than rejecting, any errors encountered in the process of loading a
76
+ * form will be **resolved**, in a
77
+ * {@link LoadFormFailureResult.error | FormLoadFailureResult error}.
78
+ */
79
+ export type LoadForm = (formResource: FormResource, options?: LoadFormOptions) => FormLoadPromise<LoadFormResult>;
@@ -0,0 +1,67 @@
1
+ import { UnknownObject } from '../../../../common/src/lib/type-assertions/assertUnknownObject.ts';
2
+ import { AnyFunction } from '../../../../common/types/helpers.js';
3
+ import { LoadFormFailureError } from '../../error/LoadFormFailureError.ts';
4
+ import { CreateFormInstance } from './CreateFormInstance.ts';
5
+ import { EditFormInstance } from './EditFormInstance.ts';
6
+ import { RestoreFormInstance } from './RestoreFormInstance.ts';
7
+ export type { LoadFormFailureError };
8
+ export type FormResultStatus = 'success' | 'warning' | 'failure';
9
+ /**
10
+ * @todo Pending design and modeling of warning cases.
11
+ */
12
+ export type LoadFormWarnings = UnknownObject;
13
+ type FailedLoadFormResultMethodParameters<T extends AnyFunction> = readonly never[] & (Parameters<T> extends {
14
+ readonly length: infer Length extends number;
15
+ } ? {
16
+ readonly length: Length;
17
+ } : never);
18
+ export type FailedLoadFormResultMethod<T extends AnyFunction> = (...args: FailedLoadFormResultMethodParameters<T>) => never;
19
+ export type FallibleLoadFormResultMethod<T extends AnyFunction> = T | FailedLoadFormResultMethod<T>;
20
+ interface BaseLoadFormResult {
21
+ readonly status: FormResultStatus;
22
+ readonly warnings: LoadFormWarnings | null;
23
+ readonly error: LoadFormFailureError | null;
24
+ readonly createInstance: FallibleLoadFormResultMethod<CreateFormInstance>;
25
+ readonly editInstance: FallibleLoadFormResultMethod<EditFormInstance>;
26
+ readonly restoreInstance: FallibleLoadFormResultMethod<RestoreFormInstance>;
27
+ }
28
+ export interface LoadFormSuccessResult extends BaseLoadFormResult {
29
+ readonly status: 'success';
30
+ readonly warnings: null;
31
+ readonly error: null;
32
+ readonly createInstance: CreateFormInstance;
33
+ readonly editInstance: EditFormInstance;
34
+ readonly restoreInstance: RestoreFormInstance;
35
+ }
36
+ export interface LoadFormWarningResult extends BaseLoadFormResult {
37
+ readonly status: 'warning';
38
+ readonly warnings: LoadFormWarnings;
39
+ readonly error: null;
40
+ readonly createInstance: CreateFormInstance;
41
+ readonly editInstance: EditFormInstance;
42
+ readonly restoreInstance: RestoreFormInstance;
43
+ }
44
+ export interface LoadFormFailureResult extends BaseLoadFormResult {
45
+ readonly status: 'failure';
46
+ readonly warnings: LoadFormWarnings | null;
47
+ readonly error: LoadFormFailureError;
48
+ /**
49
+ * @example A temporary demo integration was built during development of this
50
+ * interface.
51
+ *
52
+ * @see
53
+ * {@link https://github.com/getodk/web-forms/pull/345/commits/9ef36355d89dd1450d3a87c3a55506bb9b0fc414}
54
+ */
55
+ readonly createInstance: FailedLoadFormResultMethod<CreateFormInstance>;
56
+ readonly editInstance: FailedLoadFormResultMethod<EditFormInstance>;
57
+ /**
58
+ * @example A temporary demo integration was built during development of this
59
+ * interface.
60
+ *
61
+ * @see
62
+ * {@link https://github.com/getodk/web-forms/pull/345/commits/9ef36355d89dd1450d3a87c3a55506bb9b0fc414}
63
+ */
64
+ readonly restoreInstance: FailedLoadFormResultMethod<RestoreFormInstance>;
65
+ }
66
+ export type InstantiableLoadFormResult = LoadFormSuccessResult | LoadFormWarningResult;
67
+ export type LoadFormResult = InstantiableLoadFormResult | LoadFormFailureResult;
@@ -0,0 +1,8 @@
1
+ import { InstanceData } from '../serialization/InstanceData.ts';
2
+ import { FormInstance, FormInstanceRestoreMode } from './FormInstance.ts';
3
+ import { FormInstanceConfig } from './FormInstanceConfig.ts';
4
+ export interface RestoreFormInstanceInput {
5
+ readonly data: readonly [InstanceData, ...InstanceData[]];
6
+ }
7
+ export type RestoredFormInstance = FormInstance<FormInstanceRestoreMode>;
8
+ export type RestoreFormInstance = (input: RestoreFormInstanceInput, config?: FormInstanceConfig) => Promise<RestoredFormInstance>;
@@ -4,6 +4,7 @@ import { AnyInputNode } from './InputNode.ts';
4
4
  import { AnyModelValueNode } from './ModelValueNode.ts';
5
5
  import { AnyNoteNode } from './NoteNode.ts';
6
6
  import { AnyRangeNode } from './RangeNode.ts';
7
+ import { RankNode } from './RankNode.ts';
7
8
  import { RepeatInstanceNode } from './repeat/RepeatInstanceNode.ts';
8
9
  import { RepeatRangeControlledNode } from './repeat/RepeatRangeControlledNode.ts';
9
10
  import { RepeatRangeUncontrolledNode } from './repeat/RepeatRangeUncontrolledNode.ts';
@@ -11,11 +12,9 @@ import { RootNode } from './RootNode.ts';
11
12
  import { SelectNode } from './SelectNode.ts';
12
13
  import { SubtreeNode } from './SubtreeNode.ts';
13
14
  import { TriggerNode } from './TriggerNode.ts';
14
- import { RankNode } from './RankNode.ts';
15
- import { UploadNode } from './unsupported/UploadNode.ts';
16
- export type AnyUnsupportedControlNode = UploadNode;
17
- export type AnyControlNode = AnyInputNode | AnyNoteNode | AnyRangeNode | RankNode | SelectNode | TriggerNode;
18
- export type AnyLeafNode = AnyControlNode | AnyModelValueNode | AnyUnsupportedControlNode;
15
+ import { UploadNode } from './UploadNode.ts';
16
+ export type AnyControlNode = AnyInputNode | AnyNoteNode | AnyRangeNode | RankNode | SelectNode | TriggerNode | UploadNode;
17
+ export type AnyLeafNode = AnyControlNode | AnyModelValueNode;
19
18
  export type RepeatRangeNode = RepeatRangeControlledNode | RepeatRangeUncontrolledNode;
20
19
  /**
21
20
  * Any of the concrete node types which may be a parent of non-repeat instance