@getodk/xforms-engine 0.3.0 → 0.5.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 (429) hide show
  1. package/dist/client/BaseNode.d.ts +15 -5
  2. package/dist/client/BaseValueNode.d.ts +32 -0
  3. package/dist/client/EngineConfig.d.ts +49 -49
  4. package/dist/client/GroupNode.d.ts +2 -3
  5. package/dist/client/InputNode.d.ts +53 -0
  6. package/dist/client/ModelValueNode.d.ts +13 -9
  7. package/dist/client/NodeAppearances.d.ts +1 -2
  8. package/dist/client/NoteNode.d.ts +3 -4
  9. package/dist/client/RootNode.d.ts +36 -10
  10. package/dist/client/SelectNode.d.ts +4 -5
  11. package/dist/client/SubtreeNode.d.ts +1 -2
  12. package/dist/client/TextRange.d.ts +3 -4
  13. package/dist/client/TriggerNode.d.ts +25 -0
  14. package/dist/client/ValueType.d.ts +3 -0
  15. package/dist/client/constants.d.ts +50 -1
  16. package/dist/client/hierarchy.d.ts +9 -5
  17. package/dist/client/identity.d.ts +14 -0
  18. package/dist/client/index.d.ts +0 -1
  19. package/dist/client/node-types.d.ts +3 -1
  20. package/dist/client/repeat/BaseRepeatRangeNode.d.ts +1 -2
  21. package/dist/client/repeat/RepeatInstanceNode.d.ts +2 -3
  22. package/dist/client/repeat/RepeatRangeControlledNode.d.ts +1 -2
  23. package/dist/client/repeat/RepeatRangeUncontrolledNode.d.ts +1 -2
  24. package/dist/client/resources.d.ts +93 -0
  25. package/dist/client/submission/SubmissionData.d.ts +7 -0
  26. package/dist/client/submission/SubmissionDefinition.d.ts +14 -0
  27. package/dist/client/submission/SubmissionInstanceFile.d.ts +6 -0
  28. package/dist/client/submission/SubmissionOptions.d.ts +23 -0
  29. package/dist/client/submission/SubmissionResult.d.ts +91 -0
  30. package/dist/client/submission/SubmissionState.d.ts +12 -0
  31. package/dist/client/unsupported/RangeNode.d.ts +9 -0
  32. package/dist/client/unsupported/RankNode.d.ts +9 -0
  33. package/dist/client/unsupported/UnsupportedControlNode.d.ts +32 -0
  34. package/dist/client/unsupported/UploadNode.d.ts +9 -0
  35. package/dist/client/validation.d.ts +2 -3
  36. package/dist/error/ErrorProductionDesignPendingError.d.ts +7 -0
  37. package/dist/error/ValueTypeInvariantError.d.ts +17 -0
  38. package/dist/error/XPathFunctionalityError.d.ts +14 -0
  39. package/dist/error/XPathFunctionalityNotSupportedError.d.ts +7 -0
  40. package/dist/error/XPathFunctionalityPendingError.d.ts +7 -0
  41. package/dist/index.d.ts +16 -4
  42. package/dist/index.js +8559 -4700
  43. package/dist/index.js.map +1 -1
  44. package/dist/instance/Group.d.ts +9 -5
  45. package/dist/instance/InputControl.d.ts +36 -0
  46. package/dist/instance/ModelValue.d.ts +16 -27
  47. package/dist/instance/Note.d.ts +11 -5
  48. package/dist/instance/PrimaryInstance.d.ts +84 -0
  49. package/dist/instance/Root.d.ts +31 -28
  50. package/dist/instance/SelectField.d.ts +13 -6
  51. package/dist/instance/Subtree.d.ts +10 -6
  52. package/dist/instance/TriggerControl.d.ts +47 -0
  53. package/dist/instance/abstract/DescendantNode.d.ts +33 -26
  54. package/dist/instance/abstract/InstanceNode.d.ts +50 -31
  55. package/dist/instance/abstract/UnsupportedControl.d.ts +53 -0
  56. package/dist/instance/abstract/ValueNode.d.ts +48 -0
  57. package/dist/instance/children.d.ts +0 -1
  58. package/dist/instance/hierarchy.d.ts +13 -8
  59. package/dist/instance/identity.d.ts +2 -7
  60. package/dist/instance/index.d.ts +0 -1
  61. package/dist/instance/internal-api/EvaluationContext.d.ts +53 -13
  62. package/dist/instance/internal-api/InstanceConfig.d.ts +8 -3
  63. package/dist/instance/internal-api/InstanceValueContext.d.ts +20 -0
  64. package/dist/instance/internal-api/PrimaryInstanceDocument.d.ts +36 -0
  65. package/dist/instance/internal-api/TranslationContext.d.ts +3 -3
  66. package/dist/instance/internal-api/ValidationContext.d.ts +12 -6
  67. package/dist/instance/internal-api/ValueContext.d.ts +5 -5
  68. package/dist/instance/internal-api/submission/ClientReactiveSubmittableInstance.d.ts +14 -0
  69. package/dist/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.d.ts +31 -0
  70. package/dist/instance/internal-api/submission/ClientReactiveSubmittableParentNode.d.ts +18 -0
  71. package/dist/instance/internal-api/submission/ClientReactiveSubmittableValueNode.d.ts +17 -0
  72. package/dist/instance/repeat/BaseRepeatRange.d.ts +40 -85
  73. package/dist/instance/repeat/RepeatInstance.d.ts +11 -30
  74. package/dist/instance/repeat/RepeatRangeControlled.d.ts +3 -4
  75. package/dist/instance/repeat/RepeatRangeUncontrolled.d.ts +3 -4
  76. package/dist/instance/resource.d.ts +1 -2
  77. package/dist/instance/text/TextChunk.d.ts +0 -1
  78. package/dist/instance/text/TextRange.d.ts +1 -2
  79. package/dist/instance/unsupported/RangeControl.d.ts +6 -0
  80. package/dist/instance/unsupported/RankControl.d.ts +6 -0
  81. package/dist/instance/unsupported/UploadControl.d.ts +6 -0
  82. package/dist/integration/xpath/EngineXPathEvaluator.d.ts +14 -0
  83. package/dist/integration/xpath/adapter/XFormsXPathNode.d.ts +71 -0
  84. package/dist/integration/xpath/adapter/engineDOMAdapter.d.ts +5 -0
  85. package/dist/integration/xpath/adapter/kind.d.ts +32 -0
  86. package/dist/integration/xpath/adapter/names.d.ts +16 -0
  87. package/dist/integration/xpath/adapter/traversal.d.ts +25 -0
  88. package/dist/integration/xpath/adapter/values.d.ts +2 -0
  89. package/dist/integration/xpath/static-dom/StaticAttribute.d.ts +19 -0
  90. package/dist/integration/xpath/static-dom/StaticDocument.d.ts +16 -0
  91. package/dist/integration/xpath/static-dom/StaticElement.d.ts +40 -0
  92. package/dist/integration/xpath/static-dom/StaticNamedNode.d.ts +17 -0
  93. package/dist/integration/xpath/static-dom/StaticNode.d.ts +33 -0
  94. package/dist/integration/xpath/static-dom/StaticText.d.ts +16 -0
  95. package/dist/lib/TokenListParser.d.ts +3 -3
  96. package/dist/lib/client-reactivity/submission/createInstanceSubmissionState.d.ts +3 -0
  97. package/dist/lib/client-reactivity/submission/createLeafNodeSubmissionState.d.ts +3 -0
  98. package/dist/lib/client-reactivity/submission/createNodeRangeSubmissionState.d.ts +4 -0
  99. package/dist/lib/client-reactivity/submission/createParentNodeSubmissionState.d.ts +4 -0
  100. package/dist/lib/client-reactivity/submission/createValueNodeSubmissionState.d.ts +3 -0
  101. package/dist/lib/client-reactivity/submission/prepareSubmission.d.ts +8 -0
  102. package/dist/lib/codecs/DecimalValueCodec.d.ts +6 -0
  103. package/dist/lib/codecs/IntValueCodec.d.ts +6 -0
  104. package/dist/lib/codecs/StringValueCodec.d.ts +4 -0
  105. package/dist/lib/codecs/ValueCodec.d.ts +30 -0
  106. package/dist/lib/codecs/ValueTypePlaceholderCodec.d.ts +12 -0
  107. package/dist/lib/codecs/getSharedValueCodec.d.ts +47 -0
  108. package/dist/lib/dom/query.d.ts +4 -2
  109. package/dist/lib/reactivity/createChildrenState.d.ts +7 -6
  110. package/dist/lib/reactivity/createComputedExpression.d.ts +19 -7
  111. package/dist/lib/reactivity/createInstanceValueState.d.ts +40 -0
  112. package/dist/lib/reactivity/createNoteReadonlyThunk.d.ts +2 -3
  113. package/dist/lib/reactivity/createSelectItems.d.ts +0 -1
  114. package/dist/lib/reactivity/createTranslationState.d.ts +19 -0
  115. package/dist/lib/reactivity/createValueState.d.ts +6 -11
  116. package/dist/lib/reactivity/materializeCurrentStateChildren.d.ts +4 -5
  117. package/dist/lib/reactivity/node-state/createClientState.d.ts +0 -1
  118. package/dist/lib/reactivity/node-state/createCurrentState.d.ts +0 -1
  119. package/dist/lib/reactivity/node-state/createEngineState.d.ts +0 -1
  120. package/dist/lib/reactivity/node-state/createSharedNodeState.d.ts +0 -1
  121. package/dist/lib/reactivity/node-state/createSpecifiedPropertyDescriptor.d.ts +0 -1
  122. package/dist/lib/reactivity/node-state/createSpecifiedState.d.ts +0 -1
  123. package/dist/lib/reactivity/node-state/representations.d.ts +0 -1
  124. package/dist/lib/reactivity/scope.d.ts +0 -1
  125. package/dist/lib/reactivity/text/createFieldHint.d.ts +1 -2
  126. package/dist/lib/reactivity/text/createNodeLabel.d.ts +1 -2
  127. package/dist/lib/reactivity/text/createNoteText.d.ts +1 -2
  128. package/dist/lib/reactivity/text/createTextRange.d.ts +0 -1
  129. package/dist/lib/reactivity/types.d.ts +0 -1
  130. package/dist/lib/reactivity/validation/createAggregatedViolations.d.ts +0 -1
  131. package/dist/lib/reactivity/validation/createValidation.d.ts +0 -1
  132. package/dist/lib/xml-serialization.d.ts +41 -0
  133. package/dist/parse/XFormDOM.d.ts +42 -0
  134. package/dist/{XFormDefinition.d.ts → parse/XFormDefinition.d.ts} +3 -5
  135. package/dist/parse/attachments/FormAttachmentResource.d.ts +27 -0
  136. package/dist/{body → parse/body}/BodyDefinition.d.ts +16 -11
  137. package/dist/{body → parse/body}/BodyElementDefinition.d.ts +7 -7
  138. package/dist/{body → parse/body}/RepeatElementDefinition.d.ts +3 -4
  139. package/dist/{body → parse/body}/UnsupportedBodyElementDefinition.d.ts +0 -1
  140. package/dist/parse/body/appearance/inputAppearanceParser.d.ts +3 -0
  141. package/dist/{body → parse/body}/appearance/selectAppearanceParser.d.ts +1 -2
  142. package/dist/{body → parse/body}/appearance/structureElementAppearanceParser.d.ts +1 -2
  143. package/dist/parse/body/appearance/unknownAppearanceParser.d.ts +3 -0
  144. package/dist/{body → parse/body}/control/ControlDefinition.d.ts +3 -4
  145. package/dist/{body/control/InputDefinition.d.ts → parse/body/control/InputControlDefinition.d.ts} +2 -3
  146. package/dist/parse/body/control/RangeControlDefinition.d.ts +11 -0
  147. package/dist/parse/body/control/RankControlDefinition.d.ts +11 -0
  148. package/dist/parse/body/control/TriggerControlDefinition.d.ts +11 -0
  149. package/dist/parse/body/control/UploadControlDefinition.d.ts +11 -0
  150. package/dist/{body → parse/body}/control/select/ItemDefinition.d.ts +2 -3
  151. package/dist/{body → parse/body}/control/select/ItemsetDefinition.d.ts +4 -5
  152. package/dist/{body → parse/body}/control/select/ItemsetNodesetContext.d.ts +1 -4
  153. package/dist/{body → parse/body}/control/select/SelectDefinition.d.ts +3 -12
  154. package/dist/{body → parse/body}/group/BaseGroupDefinition.d.ts +3 -5
  155. package/dist/{body → parse/body}/group/LogicalGroupDefinition.d.ts +0 -1
  156. package/dist/{body → parse/body}/group/PresentationGroupDefinition.d.ts +1 -2
  157. package/dist/{body → parse/body}/group/StructuralGroupDefinition.d.ts +0 -1
  158. package/dist/{model/BindComputation.d.ts → parse/expression/BindComputationExpression.d.ts} +5 -6
  159. package/dist/{body/control/select → parse/expression}/ItemsetNodesetExpression.d.ts +2 -3
  160. package/dist/{body/control/select → parse/expression}/ItemsetValueExpression.d.ts +2 -3
  161. package/dist/parse/expression/RepeatCountControlExpression.d.ts +2 -3
  162. package/dist/parse/expression/TextLiteralExpression.d.ts +9 -0
  163. package/dist/parse/expression/TextOutputExpression.d.ts +7 -0
  164. package/dist/parse/expression/TextReferenceExpression.d.ts +7 -0
  165. package/dist/parse/expression/TextTranslationExpression.d.ts +8 -0
  166. package/dist/parse/expression/abstract/DependencyContext.d.ts +7 -0
  167. package/dist/{expression → parse/expression/abstract}/DependentExpression.d.ts +4 -6
  168. package/dist/parse/expression/abstract/TextChunkExpression.d.ts +17 -0
  169. package/dist/parse/model/BindDefinition.d.ts +38 -0
  170. package/dist/parse/model/BindTypeDefinition.d.ts +20 -0
  171. package/dist/{model → parse/model}/DescendentNodeDefinition.d.ts +0 -2
  172. package/dist/parse/model/FormSubmissionDefinition.d.ts +8 -0
  173. package/dist/parse/model/ItextTranslation/ItextTranslationDefinition.d.ts +4 -0
  174. package/dist/parse/model/ItextTranslation/ItextTranslationRootDefinition.d.ts +8 -0
  175. package/dist/parse/model/ItextTranslation/ItextTranslationsDefinition.d.ts +8 -0
  176. package/dist/{model → parse/model}/LeafNodeDefinition.d.ts +4 -3
  177. package/dist/{model → parse/model}/ModelBindMap.d.ts +1 -2
  178. package/dist/{model → parse/model}/ModelDefinition.d.ts +3 -2
  179. package/dist/{model → parse/model}/NodeDefinition.d.ts +0 -2
  180. package/dist/parse/{NoteNodeDefinition.d.ts → model/NoteNodeDefinition.d.ts} +12 -13
  181. package/dist/{model → parse/model}/RepeatInstanceDefinition.d.ts +1 -2
  182. package/dist/{model → parse/model}/RepeatRangeDefinition.d.ts +2 -3
  183. package/dist/{model → parse/model}/RepeatTemplateDefinition.d.ts +2 -3
  184. package/dist/{model → parse/model}/RootDefinition.d.ts +5 -5
  185. package/dist/parse/model/SecondaryInstance/SecondaryInstanceDefinition.d.ts +4 -0
  186. package/dist/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.d.ts +7 -0
  187. package/dist/parse/model/SecondaryInstance/SecondaryInstancesDefinition.d.ts +13 -0
  188. package/dist/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.d.ts +14 -0
  189. package/dist/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.d.ts +22 -0
  190. package/dist/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceResource.d.ts +23 -0
  191. package/dist/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceSource.d.ts +9 -0
  192. package/dist/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.d.ts +5 -0
  193. package/dist/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.d.ts +7 -0
  194. package/dist/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.d.ts +13 -0
  195. package/dist/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.d.ts +12 -0
  196. package/dist/{model → parse/model}/SubtreeDefinition.d.ts +1 -2
  197. package/dist/parse/shared/parseStaticDocumentFromDOMSubtree.d.ts +24 -0
  198. package/dist/parse/text/HintDefinition.d.ts +2 -3
  199. package/dist/parse/text/ItemLabelDefinition.d.ts +2 -3
  200. package/dist/parse/text/ItemsetLabelDefinition.d.ts +3 -4
  201. package/dist/parse/text/LabelDefinition.d.ts +5 -6
  202. package/dist/parse/text/MessageDefinition.d.ts +4 -5
  203. package/dist/parse/text/abstract/TextElementDefinition.d.ts +8 -9
  204. package/dist/parse/text/abstract/TextRangeDefinition.d.ts +4 -7
  205. package/dist/parse/xpath/path-resolution.d.ts +0 -1
  206. package/dist/parse/xpath/predicate-analysis.d.ts +0 -1
  207. package/dist/parse/xpath/reference-parsing.d.ts +0 -1
  208. package/dist/parse/xpath/semantic-analysis.d.ts +5 -1
  209. package/dist/parse/xpath/syntax-traversal.d.ts +0 -1
  210. package/dist/solid.js +8398 -4543
  211. package/dist/solid.js.map +1 -1
  212. package/package.json +14 -12
  213. package/src/client/BaseNode.ts +17 -7
  214. package/src/client/BaseValueNode.ts +35 -0
  215. package/src/client/EngineConfig.ts +52 -51
  216. package/src/client/GroupNode.ts +2 -2
  217. package/src/client/InputNode.ts +77 -0
  218. package/src/client/ModelValueNode.ts +31 -8
  219. package/src/client/NodeAppearances.ts +1 -1
  220. package/src/client/NoteNode.ts +3 -3
  221. package/src/client/RootNode.ts +39 -9
  222. package/src/client/SelectNode.ts +5 -5
  223. package/src/client/SubtreeNode.ts +1 -1
  224. package/src/client/TextRange.ts +4 -5
  225. package/src/client/TriggerNode.ts +29 -0
  226. package/src/client/ValueType.ts +4 -0
  227. package/src/client/constants.ts +67 -0
  228. package/src/client/hierarchy.ts +16 -4
  229. package/src/client/identity.ts +16 -0
  230. package/src/client/node-types.ts +19 -5
  231. package/src/client/repeat/BaseRepeatRangeNode.ts +1 -1
  232. package/src/client/repeat/RepeatInstanceNode.ts +2 -2
  233. package/src/client/repeat/RepeatRangeControlledNode.ts +1 -1
  234. package/src/client/repeat/RepeatRangeUncontrolledNode.ts +1 -1
  235. package/src/client/resources.ts +118 -0
  236. package/src/client/submission/SubmissionData.ts +12 -0
  237. package/src/client/submission/SubmissionDefinition.ts +16 -0
  238. package/src/client/submission/SubmissionInstanceFile.ts +9 -0
  239. package/src/client/submission/SubmissionOptions.ts +28 -0
  240. package/src/client/submission/SubmissionResult.ts +124 -0
  241. package/src/client/submission/SubmissionState.ts +14 -0
  242. package/src/client/unsupported/RangeNode.ts +14 -0
  243. package/src/client/unsupported/RankNode.ts +14 -0
  244. package/src/client/unsupported/UnsupportedControlNode.ts +40 -0
  245. package/src/client/unsupported/UploadNode.ts +14 -0
  246. package/src/client/validation.ts +2 -2
  247. package/src/error/ErrorProductionDesignPendingError.ts +6 -0
  248. package/src/error/ValueTypeInvariantError.ts +22 -0
  249. package/src/error/XPathFunctionalityError.ts +26 -0
  250. package/src/error/XPathFunctionalityNotSupportedError.ts +18 -0
  251. package/src/error/XPathFunctionalityPendingError.ts +18 -0
  252. package/src/index.ts +16 -2
  253. package/src/instance/Group.ts +17 -5
  254. package/src/instance/InputControl.ts +119 -0
  255. package/src/instance/ModelValue.ts +47 -54
  256. package/src/instance/Note.ts +26 -10
  257. package/src/instance/PrimaryInstance.ts +244 -0
  258. package/src/instance/Root.ts +64 -132
  259. package/src/instance/SelectField.ts +62 -25
  260. package/src/instance/Subtree.ts +19 -7
  261. package/src/instance/{StringField.ts → TriggerControl.ts} +61 -30
  262. package/src/instance/abstract/DescendantNode.ts +92 -47
  263. package/src/instance/abstract/InstanceNode.ts +104 -98
  264. package/src/instance/abstract/UnsupportedControl.ts +174 -0
  265. package/src/instance/abstract/ValueNode.ts +127 -0
  266. package/src/instance/children.ts +83 -14
  267. package/src/instance/hierarchy.ts +36 -14
  268. package/src/instance/identity.ts +3 -9
  269. package/src/instance/index.ts +26 -8
  270. package/src/instance/internal-api/EvaluationContext.ts +61 -14
  271. package/src/instance/internal-api/InstanceConfig.ts +9 -2
  272. package/src/instance/internal-api/InstanceValueContext.ts +24 -0
  273. package/src/instance/internal-api/PrimaryInstanceDocument.ts +53 -0
  274. package/src/instance/internal-api/TranslationContext.ts +3 -2
  275. package/src/instance/internal-api/ValidationContext.ts +13 -5
  276. package/src/instance/internal-api/ValueContext.ts +5 -4
  277. package/src/instance/internal-api/submission/ClientReactiveSubmittableInstance.ts +20 -0
  278. package/src/instance/internal-api/submission/ClientReactiveSubmittableLeafNode.ts +42 -0
  279. package/src/instance/internal-api/submission/ClientReactiveSubmittableParentNode.ts +25 -0
  280. package/src/instance/internal-api/submission/ClientReactiveSubmittableValueNode.ts +23 -0
  281. package/src/instance/repeat/BaseRepeatRange.ts +51 -132
  282. package/src/instance/repeat/RepeatInstance.ts +20 -46
  283. package/src/instance/repeat/RepeatRangeControlled.ts +6 -6
  284. package/src/instance/repeat/RepeatRangeUncontrolled.ts +3 -5
  285. package/src/instance/resource.ts +1 -1
  286. package/src/instance/text/TextChunk.ts +1 -1
  287. package/src/instance/unsupported/RangeControl.ts +9 -0
  288. package/src/instance/unsupported/RankControl.ts +9 -0
  289. package/src/instance/unsupported/UploadControl.ts +9 -0
  290. package/src/integration/xpath/EngineXPathEvaluator.ts +22 -0
  291. package/src/integration/xpath/adapter/XFormsXPathNode.ts +126 -0
  292. package/src/integration/xpath/adapter/engineDOMAdapter.ts +57 -0
  293. package/src/integration/xpath/adapter/kind.ts +114 -0
  294. package/src/integration/xpath/adapter/names.ts +99 -0
  295. package/src/integration/xpath/adapter/traversal.ts +228 -0
  296. package/src/integration/xpath/adapter/values.ts +5 -0
  297. package/src/integration/xpath/static-dom/StaticAttribute.ts +33 -0
  298. package/src/integration/xpath/static-dom/StaticDocument.ts +38 -0
  299. package/src/integration/xpath/static-dom/StaticElement.ts +106 -0
  300. package/src/integration/xpath/static-dom/StaticNamedNode.ts +45 -0
  301. package/src/integration/xpath/static-dom/StaticNode.ts +68 -0
  302. package/src/integration/xpath/static-dom/StaticText.ts +28 -0
  303. package/src/lib/TokenListParser.ts +11 -7
  304. package/src/lib/client-reactivity/README.md +0 -0
  305. package/src/lib/client-reactivity/submission/createInstanceSubmissionState.ts +12 -0
  306. package/src/lib/client-reactivity/submission/createLeafNodeSubmissionState.ts +20 -0
  307. package/src/lib/client-reactivity/submission/createNodeRangeSubmissionState.ts +17 -0
  308. package/src/lib/client-reactivity/submission/createParentNodeSubmissionState.ts +22 -0
  309. package/src/lib/client-reactivity/submission/createValueNodeSubmissionState.ts +21 -0
  310. package/src/lib/client-reactivity/submission/prepareSubmission.ts +172 -0
  311. package/src/lib/codecs/DecimalValueCodec.ts +46 -0
  312. package/src/lib/codecs/IntValueCodec.ts +100 -0
  313. package/src/lib/codecs/StringValueCodec.ts +11 -0
  314. package/src/lib/codecs/ValueCodec.ts +106 -0
  315. package/src/lib/codecs/ValueTypePlaceholderCodec.ts +19 -0
  316. package/src/lib/codecs/getSharedValueCodec.ts +77 -0
  317. package/src/lib/dom/query.ts +8 -1
  318. package/src/lib/reactivity/createChildrenState.ts +8 -6
  319. package/src/lib/reactivity/createComputedExpression.ts +59 -36
  320. package/src/lib/reactivity/createInstanceValueState.ts +166 -0
  321. package/src/lib/reactivity/createNoteReadonlyThunk.ts +12 -7
  322. package/src/lib/reactivity/createSelectItems.ts +23 -23
  323. package/src/lib/reactivity/createTranslationState.ts +61 -0
  324. package/src/lib/reactivity/createValueState.ts +64 -122
  325. package/src/lib/reactivity/materializeCurrentStateChildren.ts +7 -7
  326. package/src/lib/reactivity/node-state/createSpecifiedState.ts +1 -1
  327. package/src/lib/reactivity/text/createFieldHint.ts +1 -1
  328. package/src/lib/reactivity/text/createNodeLabel.ts +1 -1
  329. package/src/lib/reactivity/text/createNoteText.ts +1 -1
  330. package/src/lib/reactivity/text/createTextRange.ts +8 -7
  331. package/src/lib/reactivity/validation/createAggregatedViolations.ts +9 -4
  332. package/src/lib/reactivity/validation/createValidation.ts +2 -3
  333. package/src/lib/xml-serialization.ts +96 -0
  334. package/src/{XFormDOM.ts → parse/XFormDOM.ts} +110 -75
  335. package/src/{XFormDefinition.ts → parse/XFormDefinition.ts} +3 -8
  336. package/src/parse/attachments/FormAttachmentResource.ts +40 -0
  337. package/src/{body → parse/body}/BodyDefinition.ts +46 -29
  338. package/src/{body → parse/body}/BodyElementDefinition.ts +12 -6
  339. package/src/{body → parse/body}/RepeatElementDefinition.ts +7 -5
  340. package/src/{body → parse/body}/appearance/inputAppearanceParser.ts +2 -2
  341. package/src/{body → parse/body}/appearance/selectAppearanceParser.ts +1 -1
  342. package/src/{body → parse/body}/appearance/structureElementAppearanceParser.ts +1 -1
  343. package/src/parse/body/appearance/unknownAppearanceParser.ts +5 -0
  344. package/src/{body → parse/body}/control/ControlDefinition.ts +4 -4
  345. package/src/{body/control/InputDefinition.ts → parse/body/control/InputControlDefinition.ts} +3 -5
  346. package/src/parse/body/control/RangeControlDefinition.ts +26 -0
  347. package/src/parse/body/control/RankControlDefinition.ts +27 -0
  348. package/src/parse/body/control/TriggerControlDefinition.ts +26 -0
  349. package/src/parse/body/control/UploadControlDefinition.ts +26 -0
  350. package/src/{body → parse/body}/control/select/ItemDefinition.ts +2 -2
  351. package/src/{body → parse/body}/control/select/ItemsetDefinition.ts +5 -5
  352. package/src/{body → parse/body}/control/select/ItemsetNodesetContext.ts +1 -6
  353. package/src/{body → parse/body}/control/select/SelectDefinition.ts +3 -11
  354. package/src/{body → parse/body}/group/BaseGroupDefinition.ts +11 -22
  355. package/src/{body → parse/body}/group/PresentationGroupDefinition.ts +1 -1
  356. package/src/{model/BindComputation.ts → parse/expression/BindComputationExpression.ts} +8 -8
  357. package/src/{body/control/select → parse/expression}/ItemsetNodesetExpression.ts +2 -2
  358. package/src/{body/control/select → parse/expression}/ItemsetValueExpression.ts +2 -2
  359. package/src/parse/expression/RepeatCountControlExpression.ts +2 -2
  360. package/src/parse/expression/TextLiteralExpression.ts +19 -0
  361. package/src/parse/{text/OutputChunkDefinition.ts → expression/TextOutputExpression.ts} +4 -4
  362. package/src/parse/{text/ReferenceChunkDefinition.ts → expression/TextReferenceExpression.ts} +4 -4
  363. package/src/parse/{text/TranslationChunkDefinition.ts → expression/TextTranslationExpression.ts} +4 -4
  364. package/src/{expression → parse/expression/abstract}/DependencyContext.ts +0 -26
  365. package/src/{expression → parse/expression/abstract}/DependentExpression.ts +5 -16
  366. package/src/parse/expression/abstract/TextChunkExpression.ts +38 -0
  367. package/src/parse/model/BindDefinition.ts +104 -0
  368. package/src/parse/model/BindTypeDefinition.ts +175 -0
  369. package/src/{model → parse/model}/DescendentNodeDefinition.ts +0 -6
  370. package/src/parse/model/FormSubmissionDefinition.ts +44 -0
  371. package/src/parse/model/ItextTranslation/ItextTranslationDefinition.ts +4 -0
  372. package/src/parse/model/ItextTranslation/ItextTranslationRootDefinition.ts +41 -0
  373. package/src/parse/model/ItextTranslation/ItextTranslationsDefinition.ts +31 -0
  374. package/src/{model → parse/model}/LeafNodeDefinition.ts +4 -1
  375. package/src/{model → parse/model}/ModelBindMap.ts +6 -8
  376. package/src/parse/model/ModelDefinition.ts +24 -0
  377. package/src/{model → parse/model}/NodeDefinition.ts +0 -3
  378. package/src/parse/{NoteNodeDefinition.ts → model/NoteNodeDefinition.ts} +12 -12
  379. package/src/{model → parse/model}/RepeatRangeDefinition.ts +1 -1
  380. package/src/{model → parse/model}/RootDefinition.ts +4 -3
  381. package/src/parse/model/SecondaryInstance/SecondaryInstanceDefinition.ts +4 -0
  382. package/src/parse/model/SecondaryInstance/SecondaryInstanceRootDefinition.ts +12 -0
  383. package/src/parse/model/SecondaryInstance/SecondaryInstancesDefinition.ts +102 -0
  384. package/src/parse/model/SecondaryInstance/sources/BlankSecondaryInstanceSource.ts +40 -0
  385. package/src/parse/model/SecondaryInstance/sources/CSVExternalSecondaryInstance.ts +288 -0
  386. package/src/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceResource.ts +222 -0
  387. package/src/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceSource.ts +22 -0
  388. package/src/parse/model/SecondaryInstance/sources/GeoJSONExternalSecondaryInstance.ts +414 -0
  389. package/src/parse/model/SecondaryInstance/sources/InternalSecondaryInstanceSource.ts +19 -0
  390. package/src/parse/model/SecondaryInstance/sources/SecondaryInstanceSource.ts +29 -0
  391. package/src/parse/model/SecondaryInstance/sources/XMLExternalSecondaryInstanceSource.ts +32 -0
  392. package/src/parse/shared/parseStaticDocumentFromDOMSubtree.ts +149 -0
  393. package/src/parse/text/HintDefinition.ts +2 -2
  394. package/src/parse/text/ItemLabelDefinition.ts +2 -2
  395. package/src/parse/text/ItemsetLabelDefinition.ts +7 -7
  396. package/src/parse/text/LabelDefinition.ts +5 -5
  397. package/src/parse/text/MessageDefinition.ts +7 -7
  398. package/src/parse/text/abstract/TextElementDefinition.ts +14 -14
  399. package/src/parse/text/abstract/TextRangeDefinition.ts +4 -10
  400. package/src/parse/xpath/semantic-analysis.ts +29 -0
  401. package/dist/XFormDOM.d.ts +0 -32
  402. package/dist/XFormDataType.d.ts +0 -27
  403. package/dist/body/appearance/inputAppearanceParser.d.ts +0 -4
  404. package/dist/client/StringNode.d.ts +0 -47
  405. package/dist/expression/DependencyContext.d.ts +0 -13
  406. package/dist/instance/StringField.d.ts +0 -45
  407. package/dist/instance/internal-api/SubscribableDependency.d.ts +0 -60
  408. package/dist/model/BindDefinition.d.ts +0 -34
  409. package/dist/parse/text/OutputChunkDefinition.d.ts +0 -8
  410. package/dist/parse/text/ReferenceChunkDefinition.d.ts +0 -8
  411. package/dist/parse/text/StaticTextChunkDefinition.d.ts +0 -10
  412. package/dist/parse/text/TranslationChunkDefinition.d.ts +0 -9
  413. package/dist/parse/text/abstract/TextChunkDefinition.d.ts +0 -18
  414. package/src/XFormDataType.ts +0 -64
  415. package/src/client/StringNode.ts +0 -52
  416. package/src/instance/internal-api/SubscribableDependency.ts +0 -61
  417. package/src/model/BindDefinition.ts +0 -106
  418. package/src/model/ModelDefinition.ts +0 -19
  419. package/src/parse/TODO.md +0 -3
  420. package/src/parse/text/StaticTextChunkDefinition.ts +0 -19
  421. package/src/parse/text/abstract/TextChunkDefinition.ts +0 -38
  422. /package/dist/{model → parse/model}/BindElement.d.ts +0 -0
  423. /package/src/{body → parse/body}/UnsupportedBodyElementDefinition.ts +0 -0
  424. /package/src/{body → parse/body}/group/LogicalGroupDefinition.ts +0 -0
  425. /package/src/{body → parse/body}/group/StructuralGroupDefinition.ts +0 -0
  426. /package/src/{model → parse/model}/BindElement.ts +0 -0
  427. /package/src/{model → parse/model}/RepeatInstanceDefinition.ts +0 -0
  428. /package/src/{model → parse/model}/RepeatTemplateDefinition.ts +0 -0
  429. /package/src/{model → parse/model}/SubtreeDefinition.ts +0 -0
@@ -0,0 +1,100 @@
1
+ import { ValueTypeInvariantError } from '../../error/ValueTypeInvariantError.ts';
2
+ import { ValueCodec } from './ValueCodec.ts';
3
+
4
+ /**
5
+ * Per {@link https://getodk.github.io/xforms-spec/#data-type:int}, which
6
+ * specifies "as in {@link https://www.w3.org/TR/xmlschema-2/#int | XML 1.0}":
7
+ *
8
+ * > int is ·derived· from long by setting the value of ·maxInclusive· to be
9
+ * > 2147483647 and ·minInclusive· to be -2147483648.
10
+ */
11
+ const INT_BOUNDS = {
12
+ MIN: -2_147_483_648n,
13
+ MAX: 2_147_483_647n,
14
+ };
15
+
16
+ const assertIntBounds = <T extends bigint | null>(value: T): T => {
17
+ if (value == null) {
18
+ return value;
19
+ }
20
+
21
+ if (value < INT_BOUNDS.MIN || value > INT_BOUNDS.MAX) {
22
+ throw new ValueTypeInvariantError(
23
+ 'int',
24
+ `Unable to decode int value from ${String(value)}: expected value to be between ${INT_BOUNDS.MIN} and ${INT_BOUNDS.MAX} (inclusive)`
25
+ );
26
+ }
27
+
28
+ return value;
29
+ };
30
+
31
+ const boundedInt = (value: bigint | number): bigint => {
32
+ const result = BigInt(value);
33
+
34
+ assertIntBounds(result);
35
+
36
+ return result;
37
+ };
38
+
39
+ export type IntInputValue = bigint | number | string | null;
40
+
41
+ const numberToInt = (value: number): bigint | null => {
42
+ if (!Number.isFinite(value)) {
43
+ return null;
44
+ }
45
+
46
+ return boundedInt(Math.trunc(value));
47
+ };
48
+
49
+ const encodeInt = (value: IntInputValue): string => {
50
+ let intValue: bigint | null;
51
+
52
+ switch (typeof value) {
53
+ case 'object':
54
+ value satisfies null;
55
+ intValue = null;
56
+ break;
57
+
58
+ case 'number':
59
+ intValue = numberToInt(value);
60
+ break;
61
+
62
+ case 'string':
63
+ intValue = decodeInt(value);
64
+ break;
65
+
66
+ default:
67
+ value satisfies bigint;
68
+
69
+ intValue = boundedInt(value);
70
+ }
71
+
72
+ if (intValue == null) {
73
+ return '';
74
+ }
75
+
76
+ return String(intValue);
77
+ };
78
+
79
+ export type IntRuntimeValue = bigint | null;
80
+
81
+ /**
82
+ * Note: Collect/JavaRosa trim decimal values (i.e. round closest to zero). We
83
+ * do the same.
84
+ *
85
+ * @todo Note that we enforce bounds **after** rounding, which may not be quite
86
+ * right! Look at actual Collect/JR implementation to align.
87
+ */
88
+ const decodeInt = (value: string): IntRuntimeValue => {
89
+ if (value === '') {
90
+ return null;
91
+ }
92
+
93
+ return numberToInt(Number(value));
94
+ };
95
+
96
+ export class IntValueCodec extends ValueCodec<'int', IntRuntimeValue, IntInputValue> {
97
+ constructor() {
98
+ super('int', encodeInt, decodeInt);
99
+ }
100
+ }
@@ -0,0 +1,11 @@
1
+ import { identity } from '@getodk/common/lib/identity.ts';
2
+ import { ValueCodec } from './ValueCodec.ts';
3
+
4
+ export class StringValueCodec extends ValueCodec<'string', string, string> {
5
+ constructor() {
6
+ super('string', identity, identity, {
7
+ decodeInstanceValueFactory: () => identity,
8
+ runtimeValueStateFactory: () => identity,
9
+ });
10
+ }
11
+ }
@@ -0,0 +1,106 @@
1
+ import type { Accessor } from 'solid-js';
2
+ import type { ValueType } from '../../client/ValueType.ts';
3
+ import type { DecodeInstanceValue } from '../../instance/internal-api/InstanceValueContext.ts';
4
+ import type { SimpleAtomicState } from '../reactivity/types.ts';
5
+
6
+ type CodecEncoder<RuntimeInputValue> = (input: RuntimeInputValue) => string;
7
+
8
+ type CodecDecoder<RuntimeValue> = (value: string) => RuntimeValue;
9
+
10
+ type RuntimeValueAccessor<RuntimeValue> = Accessor<RuntimeValue>;
11
+
12
+ export type RuntimeValueSetter<
13
+ RuntimeValue extends RuntimeInputValue,
14
+ RuntimeInputValue = RuntimeValue,
15
+ > = (input: RuntimeInputValue) => RuntimeValue;
16
+
17
+ export type RuntimeValueState<
18
+ RuntimeValue extends RuntimeInputValue,
19
+ RuntimeInputValue = RuntimeValue,
20
+ > = readonly [
21
+ get: RuntimeValueAccessor<RuntimeValue>,
22
+ set: RuntimeValueSetter<RuntimeValue, RuntimeInputValue>,
23
+ ];
24
+
25
+ export type CreateRuntimeValueState<
26
+ RuntimeValue extends RuntimeInputValue,
27
+ RuntimeInputValue = RuntimeValue,
28
+ > = (
29
+ instanceState: SimpleAtomicState<string>
30
+ ) => RuntimeValueState<RuntimeValue, RuntimeInputValue>;
31
+
32
+ type RuntimeValueStateFactory<
33
+ RuntimeValue extends RuntimeInputValue,
34
+ RuntimeInputValue = RuntimeValue,
35
+ > = (
36
+ encodeValue: CodecEncoder<RuntimeInputValue>,
37
+ decodeValue: CodecDecoder<RuntimeValue>
38
+ ) => CreateRuntimeValueState<RuntimeValue, RuntimeInputValue>;
39
+
40
+ type DecodeInstanceValueFactory<
41
+ RuntimeValue extends RuntimeInputValue,
42
+ RuntimeInputValue = RuntimeValue,
43
+ > = (
44
+ encodeValue: CodecEncoder<RuntimeInputValue>,
45
+ decodeValue: CodecDecoder<RuntimeValue>
46
+ ) => DecodeInstanceValue;
47
+
48
+ interface ValueCodecOptions<RuntimeValue extends RuntimeInputValue, RuntimeInputValue> {
49
+ readonly decodeInstanceValueFactory?: DecodeInstanceValueFactory<RuntimeValue, RuntimeInputValue>;
50
+ readonly runtimeValueStateFactory?: RuntimeValueStateFactory<RuntimeValue, RuntimeInputValue>;
51
+ }
52
+
53
+ export abstract class ValueCodec<
54
+ V extends ValueType,
55
+ RuntimeValue extends RuntimeInputValue,
56
+ RuntimeInputValue = RuntimeValue,
57
+ > {
58
+ protected readonly defaultRuntimeValueStateFactory: RuntimeValueStateFactory<
59
+ RuntimeValue,
60
+ RuntimeInputValue
61
+ > = (encodeValue, decodeValue) => {
62
+ return (instanceState) => {
63
+ const [getInstanceValue, setInstanceValue] = instanceState;
64
+
65
+ const getValue = (): RuntimeValue => {
66
+ return decodeValue(getInstanceValue());
67
+ };
68
+
69
+ const setValue = (runtimeValue: RuntimeInputValue): RuntimeValue => {
70
+ const encodedValue = encodeValue(runtimeValue);
71
+ const persistedValue = setInstanceValue(encodedValue);
72
+
73
+ return decodeValue(persistedValue);
74
+ };
75
+
76
+ return [getValue, setValue];
77
+ };
78
+ };
79
+
80
+ protected readonly defaultDecodeInstanceValueFactory: DecodeInstanceValueFactory<
81
+ RuntimeValue,
82
+ RuntimeInputValue
83
+ > = (encodeValue, decodeValue) => {
84
+ return (instanceValue) => {
85
+ return encodeValue(decodeValue(instanceValue));
86
+ };
87
+ };
88
+
89
+ readonly decodeInstanceValue: DecodeInstanceValue;
90
+ readonly createRuntimeValueState: CreateRuntimeValueState<RuntimeValue, RuntimeInputValue>;
91
+
92
+ constructor(
93
+ readonly valueType: V,
94
+ readonly encodeValue: CodecEncoder<RuntimeInputValue>,
95
+ readonly decodeValue: CodecDecoder<RuntimeValue>,
96
+ options: ValueCodecOptions<RuntimeValue, RuntimeInputValue> = {}
97
+ ) {
98
+ const {
99
+ decodeInstanceValueFactory = this.defaultDecodeInstanceValueFactory,
100
+ runtimeValueStateFactory = this.defaultRuntimeValueStateFactory,
101
+ } = options;
102
+
103
+ this.decodeInstanceValue = decodeInstanceValueFactory(encodeValue, decodeValue);
104
+ this.createRuntimeValueState = runtimeValueStateFactory(encodeValue, decodeValue);
105
+ }
106
+ }
@@ -0,0 +1,19 @@
1
+ import { identity } from '@getodk/common/lib/identity.ts';
2
+ import type { ValueType } from '../../client/ValueType.ts';
3
+ import { ValueCodec } from './ValueCodec.ts';
4
+
5
+ /**
6
+ * Provides fallback functionality where a {@link ValueCodec} is expected, for
7
+ * those {@link ValueType | value types} which are still pending implementation.
8
+ * This allows consistent use of the {@link ValueCodec} interface while
9
+ * maintaining the current behavior of treating those unimplemented value types
10
+ * as string values.
11
+ */
12
+ export class ValueTypePlaceholderCodec<V extends ValueType> extends ValueCodec<V, string, string> {
13
+ constructor(valueType: V) {
14
+ super(valueType, identity, identity, {
15
+ decodeInstanceValueFactory: () => identity,
16
+ runtimeValueStateFactory: () => identity,
17
+ });
18
+ }
19
+ }
@@ -0,0 +1,77 @@
1
+ import type { ValueType } from '../../client/ValueType.ts';
2
+ import {
3
+ DecimalValueCodec,
4
+ type DecimalInputValue,
5
+ type DecimalRuntimeValue,
6
+ } from './DecimalValueCodec.ts';
7
+ import { IntValueCodec, type IntInputValue, type IntRuntimeValue } from './IntValueCodec.ts';
8
+ import { StringValueCodec } from './StringValueCodec.ts';
9
+ import type { ValueCodec } from './ValueCodec.ts';
10
+ import { ValueTypePlaceholderCodec } from './ValueTypePlaceholderCodec.ts';
11
+
12
+ interface RuntimeValuesByType {
13
+ readonly string: string;
14
+ readonly int: IntRuntimeValue;
15
+ readonly decimal: DecimalRuntimeValue;
16
+ readonly boolean: string;
17
+ readonly date: string;
18
+ readonly time: string;
19
+ readonly dateTime: string;
20
+ readonly geopoint: string;
21
+ readonly geotrace: string;
22
+ readonly geoshape: string;
23
+ readonly binary: string;
24
+ readonly barcode: string;
25
+ readonly intent: string;
26
+ }
27
+
28
+ export type RuntimeValue<V extends ValueType> = RuntimeValuesByType[V];
29
+
30
+ interface RuntimeInputValuesByType {
31
+ readonly string: string;
32
+ readonly int: IntInputValue;
33
+ readonly decimal: DecimalInputValue;
34
+ readonly boolean: string;
35
+ readonly date: string;
36
+ readonly time: string;
37
+ readonly dateTime: string;
38
+ readonly geopoint: string;
39
+ readonly geotrace: string;
40
+ readonly geoshape: string;
41
+ readonly binary: string;
42
+ readonly barcode: string;
43
+ readonly intent: string;
44
+ }
45
+
46
+ export type RuntimeInputValue<V extends ValueType> = RuntimeInputValuesByType[V];
47
+
48
+ type SharedValueCodecs = {
49
+ readonly [V in ValueType]: ValueCodec<V, RuntimeValue<V>, RuntimeInputValue<V>>;
50
+ };
51
+
52
+ export type SharedValueCodec<V extends ValueType> = SharedValueCodecs[V];
53
+
54
+ /**
55
+ * Provides codecs for each {@link ValueType | value type}, for nodes with a
56
+ * common representation of those value types.
57
+ */
58
+ export const sharedValueCodecs: SharedValueCodecs = {
59
+ string: new StringValueCodec(),
60
+
61
+ int: new IntValueCodec(),
62
+ decimal: new DecimalValueCodec(),
63
+ boolean: new ValueTypePlaceholderCodec('boolean'),
64
+ date: new ValueTypePlaceholderCodec('date'),
65
+ time: new ValueTypePlaceholderCodec('time'),
66
+ dateTime: new ValueTypePlaceholderCodec('dateTime'),
67
+ geopoint: new ValueTypePlaceholderCodec('geopoint'),
68
+ geotrace: new ValueTypePlaceholderCodec('geotrace'),
69
+ geoshape: new ValueTypePlaceholderCodec('geoshape'),
70
+ binary: new ValueTypePlaceholderCodec('binary'),
71
+ barcode: new ValueTypePlaceholderCodec('barcode'),
72
+ intent: new ValueTypePlaceholderCodec('intent'),
73
+ };
74
+
75
+ export const getSharedValueCodec = <V extends ValueType>(valueType: V): SharedValueCodec<V> => {
76
+ return sharedValueCodecs[valueType];
77
+ };
@@ -3,7 +3,7 @@ import type {
3
3
  KnownAttributeLocalNamedElement,
4
4
  LocalNamedElement,
5
5
  } from '@getodk/common/types/dom.ts';
6
- import type { SelectElement } from '../../body/control/select/SelectDefinition';
6
+ import type { SelectElement } from '../../parse/body/control/select/SelectDefinition';
7
7
 
8
8
  const hintLookup = new ScopedElementLookup(':scope > hint', 'hint');
9
9
  const itemLookup = new ScopedElementLookup(':scope > item', 'item');
@@ -15,6 +15,7 @@ const repeatGroupLabelLookup = new ScopedElementLookup(
15
15
  );
16
16
  const repeatLookup = new ScopedElementLookup(':scope > repeat[nodeset]', 'repeat[nodeset]');
17
17
  const valueLookup = new ScopedElementLookup(':scope > value', 'value');
18
+ const submissionLookup = new ScopedElementLookup(':scope > submission', 'submission');
18
19
 
19
20
  export interface HintElement extends LocalNamedElement<'hint'> {}
20
21
 
@@ -60,3 +61,9 @@ export const getRepeatElement = (parent: Element): RepeatElement | null => {
60
61
  export const getValueElement = (parent: ItemElement | ItemsetElement): ValueElement | null => {
61
62
  return valueLookup.getElement<ValueElement>(parent);
62
63
  };
64
+
65
+ export interface SubmissionElement extends LocalNamedElement<'submission'> {}
66
+
67
+ export const getSubmissionElement = (parent: Element): SubmissionElement | null => {
68
+ return submissionLookup.getElement<SubmissionElement>(parent);
69
+ };
@@ -1,8 +1,8 @@
1
1
  import type { Accessor, Setter, Signal } from 'solid-js';
2
2
  import { createSignal } from 'solid-js';
3
+ import type { FormNodeID } from '../../client/identity.ts';
3
4
  import type { OpaqueReactiveObjectFactory } from '../../index.ts';
4
5
  import type { AnyChildNode, AnyParentNode } from '../../instance/hierarchy.ts';
5
- import type { NodeID } from '../../instance/identity.ts';
6
6
  import type { materializeCurrentStateChildren } from './materializeCurrentStateChildren.ts';
7
7
  import type { ClientState } from './node-state/createClientState.ts';
8
8
  import type { CurrentState } from './node-state/createCurrentState.ts';
@@ -12,14 +12,15 @@ export interface ChildrenState<Child extends AnyChildNode> {
12
12
  readonly children: Signal<readonly Child[]>;
13
13
  readonly getChildren: Accessor<readonly Child[]>;
14
14
  readonly setChildren: Setter<readonly Child[]>;
15
- readonly childIds: Accessor<readonly NodeID[]>;
15
+ readonly childIds: Accessor<readonly FormNodeID[]>;
16
16
  }
17
17
 
18
18
  /**
19
19
  * Creates a synchronized pair of:
20
20
  *
21
21
  * - Internal children state suitable for all parent node types
22
- * - The same children state computed as an array of each child's {@link NodeID}
22
+ * - The same children state computed as an array of each child's
23
+ * {@link FormNodeID}
23
24
  *
24
25
  * This state is used, in tandem with {@link materializeCurrentStateChildren},
25
26
  * to ensure children in **client-facing** state are not written into nested
@@ -34,11 +35,12 @@ export interface ChildrenState<Child extends AnyChildNode> {
34
35
  * The produced {@link ChildrenState.childIds} memo is intended to be used to
35
36
  * specify each parent node's `children` in an instance of {@link EngineState}.
36
37
  * In so doing, the node's corresponding (internal, synchronized)
37
- * {@link ClientState} will likewise store only the children's {@link NodeID}s.
38
+ * {@link ClientState} will likewise store only the children's
39
+ * {@link FormNodeID}s.
38
40
  *
39
41
  * As a client reacts to changes in a given parent node's `children` state, that
40
42
  * node's {@link CurrentState} should produce the child nodes corresponding to
41
- * those {@link NodeID}s with the aforementioned
43
+ * those {@link FormNodeID}s with the aforementioned
42
44
  * {@link materializeCurrentStateChildren}.
43
45
  */
44
46
  export const createChildrenState = <Parent extends AnyParentNode, Child extends AnyChildNode>(
@@ -65,7 +67,7 @@ export const createChildrenState = <Parent extends AnyParentNode, Child extends
65
67
  * likely also slightly more efficient. We can revisit the tradeoff if/when
66
68
  * those hypothetical generalizations become a priority.
67
69
  */
68
- const ids = createSignal<readonly NodeID[]>([]);
70
+ const ids = createSignal<readonly FormNodeID[]>([]);
69
71
  const [childIds, setChildIds] = ids;
70
72
 
71
73
  type ChildrenSetterCallback = (prev: readonly Child[]) => readonly Child[];
@@ -1,18 +1,18 @@
1
1
  import { UnreachableError } from '@getodk/common/lib/error/UnreachableError.ts';
2
- import type { XFormsXPathEvaluator } from '@getodk/xpath';
3
2
  import type { Accessor } from 'solid-js';
4
3
  import { createMemo } from 'solid-js';
4
+ import type { EvaluationContext } from '../../instance/internal-api/EvaluationContext.ts';
5
+ import type { EngineXPathNode } from '../../integration/xpath/adapter/kind.ts';
6
+ import type { EngineXPathEvaluator } from '../../integration/xpath/EngineXPathEvaluator.ts';
5
7
  import type {
6
8
  DependentExpression,
7
9
  DependentExpressionResultType,
8
- } from '../../expression/DependentExpression.ts';
9
- import type { EvaluationContext } from '../../instance/internal-api/EvaluationContext.ts';
10
- import type { SubscribableDependency } from '../../instance/internal-api/SubscribableDependency.ts';
10
+ } from '../../parse/expression/abstract/DependentExpression.ts';
11
11
  import { isConstantExpression } from '../../parse/xpath/semantic-analysis.ts';
12
12
 
13
13
  interface ComputedExpressionResults {
14
14
  readonly boolean: boolean;
15
- readonly nodes: Node[];
15
+ readonly nodes: EngineXPathNode[];
16
16
  readonly number: number;
17
17
  readonly string: string;
18
18
  }
@@ -25,16 +25,18 @@ type EvaluatedExpression<
25
25
  // prettier-ignore
26
26
  type ExpressionEvaluator<
27
27
  Type extends DependentExpressionResultType
28
- > = () => EvaluatedExpression<Type>
28
+ > = () => EvaluatedExpression<Type>;
29
+
30
+ interface ExpressionEvaluatorOptions {
31
+ get contextNode(): EngineXPathNode;
32
+ }
29
33
 
30
34
  const expressionEvaluator = <Type extends DependentExpressionResultType>(
31
- evaluator: XFormsXPathEvaluator,
32
- contextNode: Node,
35
+ evaluator: EngineXPathEvaluator,
33
36
  type: Type,
34
- expression: string
37
+ expression: string,
38
+ options: ExpressionEvaluatorOptions
35
39
  ): ExpressionEvaluator<Type> => {
36
- const options = { contextNode };
37
-
38
40
  switch (type) {
39
41
  case 'boolean':
40
42
  return (() => {
@@ -61,50 +63,71 @@ const expressionEvaluator = <Type extends DependentExpressionResultType>(
61
63
  }
62
64
  };
63
65
 
66
+ type DefaultEvaluationsByType = {
67
+ readonly [Type in DependentExpressionResultType]: EvaluatedExpression<Type>;
68
+ };
69
+
70
+ const DEFAULT_BOOLEAN_EVALUATION = false;
71
+ const DEFAULT_NODES_EVALUATION: [] = [];
72
+ const DEFAULT_NUMBER_EVALUATION = NaN;
73
+ const DEFAULT_STRING_EVALUATION = '';
74
+
75
+ const defaultEvaluationsByType: DefaultEvaluationsByType = {
76
+ boolean: DEFAULT_BOOLEAN_EVALUATION,
77
+ nodes: DEFAULT_NODES_EVALUATION,
78
+ number: DEFAULT_NUMBER_EVALUATION,
79
+ string: DEFAULT_STRING_EVALUATION,
80
+ };
81
+
64
82
  // prettier-ignore
65
83
  type ComputedExpression<Type extends DependentExpressionResultType> = Accessor<
66
84
  EvaluatedExpression<Type>
67
85
  >;
68
86
 
69
- interface CreateComputedExpressionOptions {
70
- readonly arbitraryDependencies?: readonly SubscribableDependency[];
87
+ interface CreateComputedExpressionOptions<Type extends DependentExpressionResultType> {
88
+ /**
89
+ * If a default value is provided, {@link createComputedExpression} will
90
+ * produce this value for computations in a non-attached evaluation context,
91
+ * i.e. when evaluating an expression against a node which has not yet been
92
+ * appended to its parents children state (or which has since been removed
93
+ * from that state). A non-attached state is detected when
94
+ * {@link EvaluationContext.isAttached} returns false.
95
+ *
96
+ * If no default value is provided, an implicit default value is produced as
97
+ * appropriate for the expression's intrinsic result type.
98
+ *
99
+ * @see {@link defaultEvaluationsByType} for these implicit defaults.
100
+ */
101
+ readonly defaultValue?: EvaluatedExpression<Type>;
71
102
  }
72
103
 
73
104
  export const createComputedExpression = <Type extends DependentExpressionResultType>(
74
105
  context: EvaluationContext,
75
106
  dependentExpression: DependentExpression<Type>,
76
- options: CreateComputedExpressionOptions = {}
107
+ options: CreateComputedExpressionOptions<Type> = {}
77
108
  ): ComputedExpression<Type> => {
78
- const { contextNode, evaluator, root, scope } = context;
79
- const { expression, isTranslated, resultType } = dependentExpression;
80
- const dependencyReferences = Array.from(dependentExpression.dependencyReferences);
81
- const evaluateExpression = expressionEvaluator(evaluator, contextNode, resultType, expression);
109
+ return context.scope.runTask(() => {
110
+ const { contextNode, evaluator } = context;
111
+ const { expression, isTranslated, resultType } = dependentExpression;
112
+ const evaluatePreInitializationDefaultValue = () => {
113
+ return options?.defaultValue ?? defaultEvaluationsByType[resultType];
114
+ };
115
+ const evaluateExpression = expressionEvaluator(evaluator, resultType, expression, {
116
+ contextNode,
117
+ });
82
118
 
83
- return scope.runTask(() => {
84
119
  if (isConstantExpression(expression)) {
85
120
  return createMemo(evaluateExpression);
86
121
  }
87
122
 
88
- const { arbitraryDependencies = [] } = options;
89
-
90
- const getReferencedDependencies = createMemo(() => {
91
- return dependencyReferences.flatMap((reference) => {
92
- return context.getSubscribableDependenciesByReference(reference) ?? [];
93
- });
94
- });
95
-
96
123
  return createMemo(() => {
97
- if (isTranslated) {
98
- root.subscribe();
124
+ if (!context.isAttached()) {
125
+ return evaluatePreInitializationDefaultValue();
99
126
  }
100
127
 
101
- arbitraryDependencies.forEach((dependency) => {
102
- dependency.subscribe();
103
- });
104
-
105
- getReferencedDependencies().forEach((dependency) => {
106
- dependency.subscribe();
107
- });
128
+ if (isTranslated) {
129
+ context.getActiveLanguage();
130
+ }
108
131
 
109
132
  return evaluateExpression();
110
133
  });