@getodk/xforms-engine 0.7.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 (69) hide show
  1. package/dist/client/RootNode.d.ts +4 -4
  2. package/dist/client/UploadNode.d.ts +53 -0
  3. package/dist/client/attachments/InstanceAttachmentMeta.d.ts +8 -0
  4. package/dist/client/attachments/InstanceAttachmentsConfig.d.ts +8 -0
  5. package/dist/client/form/FormInstanceConfig.d.ts +2 -0
  6. package/dist/client/hierarchy.d.ts +4 -5
  7. package/dist/client/index.d.ts +5 -2
  8. package/dist/client/node-types.d.ts +2 -3
  9. package/dist/client/serialization/InstanceData.d.ts +7 -5
  10. package/dist/client/serialization/InstancePayloadOptions.d.ts +3 -2
  11. package/dist/error/UploadValueTypeError.d.ts +8 -0
  12. package/dist/index.js +6603 -5598
  13. package/dist/index.js.map +1 -1
  14. package/dist/instance/PrimaryInstance.d.ts +2 -3
  15. package/dist/instance/UploadControl.d.ts +58 -0
  16. package/dist/instance/attachments/InstanceAttachment.d.ts +42 -0
  17. package/dist/instance/attachments/InstanceAttachmentsState.d.ts +9 -0
  18. package/dist/instance/hierarchy.d.ts +6 -7
  19. package/dist/instance/internal-api/InstanceAttachmentContext.d.ts +19 -0
  20. package/dist/instance/internal-api/InstanceConfig.d.ts +2 -0
  21. package/dist/instance/internal-api/serialization/ClientReactiveSerializableInstance.d.ts +2 -0
  22. package/dist/lib/reactivity/createInstanceAttachment.d.ts +8 -0
  23. package/dist/lib/resource-helpers.d.ts +2 -0
  24. package/dist/parse/body/BodyDefinition.d.ts +2 -1
  25. package/dist/parse/body/control/UploadControlDefinition.d.ts +2 -0
  26. package/dist/parse/model/BindTypeDefinition.d.ts +2 -7
  27. package/dist/solid.js +6600 -5596
  28. package/dist/solid.js.map +1 -1
  29. package/package.json +15 -14
  30. package/src/client/RootNode.ts +8 -3
  31. package/src/client/UploadNode.ts +78 -0
  32. package/src/client/attachments/InstanceAttachmentMeta.ts +10 -0
  33. package/src/client/attachments/InstanceAttachmentsConfig.ts +13 -0
  34. package/src/client/form/FormInstanceConfig.ts +3 -0
  35. package/src/client/hierarchy.ts +5 -8
  36. package/src/client/index.ts +4 -2
  37. package/src/client/node-types.ts +2 -5
  38. package/src/client/serialization/InstanceData.ts +14 -6
  39. package/src/client/serialization/InstancePayloadOptions.ts +3 -2
  40. package/src/entrypoints/FormInstance.ts +3 -2
  41. package/src/error/UploadValueTypeError.ts +13 -0
  42. package/src/instance/PrimaryInstance.ts +4 -5
  43. package/src/instance/UploadControl.ts +184 -0
  44. package/src/instance/attachments/InstanceAttachment.ts +69 -0
  45. package/src/instance/attachments/InstanceAttachmentsState.ts +18 -0
  46. package/src/instance/children/buildChildren.ts +5 -8
  47. package/src/instance/hierarchy.ts +6 -9
  48. package/src/instance/input/InstanceAttachmentMap.ts +33 -21
  49. package/src/instance/internal-api/InstanceAttachmentContext.ts +20 -0
  50. package/src/instance/internal-api/InstanceConfig.ts +3 -0
  51. package/src/instance/internal-api/serialization/ClientReactiveSerializableInstance.ts +2 -0
  52. package/src/lib/client-reactivity/instance-state/prepareInstancePayload.ts +72 -8
  53. package/src/lib/reactivity/createInstanceAttachment.ts +212 -0
  54. package/src/lib/resource-helpers.ts +33 -0
  55. package/src/parse/XFormDOM.ts +1 -3
  56. package/src/parse/body/BodyDefinition.ts +4 -0
  57. package/src/parse/body/control/UploadControlDefinition.ts +42 -0
  58. package/src/parse/model/BindDefinition.ts +1 -1
  59. package/src/parse/model/BindTypeDefinition.ts +68 -26
  60. package/src/parse/model/ModelBindMap.ts +0 -5
  61. package/src/parse/model/SecondaryInstance/sources/ExternalSecondaryInstanceResource.ts +1 -30
  62. package/dist/client/unsupported/UnsupportedControlNode.d.ts +0 -30
  63. package/dist/client/unsupported/UploadNode.d.ts +0 -9
  64. package/dist/instance/unsupported/UploadControl.d.ts +0 -34
  65. package/dist/lib/codecs/TempUnsupportedControlCodec.d.ts +0 -7
  66. package/src/client/unsupported/UnsupportedControlNode.ts +0 -36
  67. package/src/client/unsupported/UploadNode.ts +0 -14
  68. package/src/instance/unsupported/UploadControl.ts +0 -120
  69. package/src/lib/codecs/TempUnsupportedControlCodec.ts +0 -32
@@ -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 { ChunkedInstancePayload, MonolithicInstancePayload } from './serialization/InstancePayload.ts';
7
- import { InstancePayloadOptions } from './serialization/InstancePayloadOptions.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
  /**
@@ -80,7 +80,7 @@ export interface RootNode extends BaseNode {
80
80
  * case a {@link ChunkedInstancePayload} will be produced, with form
81
81
  * attachments
82
82
  */
83
- prepareInstancePayload(): Promise<MonolithicInstancePayload>;
84
- prepareInstancePayload(options: InstancePayloadOptions<'monolithic'>): Promise<MonolithicInstancePayload>;
83
+ prepareInstancePayload(options?: InstancePayloadOptions<'monolithic'>): Promise<MonolithicInstancePayload>;
85
84
  prepareInstancePayload(options: InstancePayloadOptions<'chunked'>): Promise<ChunkedInstancePayload>;
85
+ prepareInstancePayload<PayloadType extends InstancePayloadType>(options: InstancePayloadOptions<PayloadType>): Promise<InstancePayload<PayloadType>>;
86
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,3 +1,4 @@
1
+ import { InstanceAttachmentsConfig } from '../attachments/InstanceAttachmentsConfig.ts';
1
2
  import { OpaqueReactiveObjectFactory } from '../OpaqueReactiveObjectFactory.ts';
2
3
  export interface FormInstanceConfig {
3
4
  /**
@@ -14,4 +15,5 @@ export interface FormInstanceConfig {
14
15
  * mechanism to handle state updates conveyed by the engine.
15
16
  */
16
17
  readonly stateFactory?: OpaqueReactiveObjectFactory;
18
+ readonly instanceAttachments?: InstanceAttachmentsConfig;
17
19
  }
@@ -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
@@ -1,3 +1,5 @@
1
+ export type * from './attachments/InstanceAttachmentMeta.ts';
2
+ export type * from './attachments/InstanceAttachmentsConfig.ts';
1
3
  export type * from './constants.ts';
2
4
  export * as constants from './constants.ts';
3
5
  export type * from './form/CreateFormInstance.ts';
@@ -10,7 +12,8 @@ export type * from './form/LoadFormResult.ts';
10
12
  export type * from './form/RestoreFormInstance.ts';
11
13
  export type * from './FormLanguage.ts';
12
14
  export type * from './GroupNode.ts';
13
- export type { AnyChildNode, AnyControlNode, AnyLeafNode, AnyNode, AnyParentNode, AnyUnsupportedControlNode, GeneralChildNode, GeneralParentNode, RepeatRangeNode, } from './hierarchy.ts';
15
+ export type { AnyChildNode, AnyControlNode, AnyLeafNode, AnyNode, AnyParentNode, GeneralChildNode, GeneralParentNode, RepeatRangeNode, } from './hierarchy.ts';
16
+ export type * from './identity.ts';
14
17
  export type * from './InputNode.ts';
15
18
  export type * from './ModelValueNode.ts';
16
19
  export type * from './NoteNode.ts';
@@ -32,6 +35,6 @@ export type * from './submission/SubmissionMeta.ts';
32
35
  export type * from './SubtreeNode.ts';
33
36
  export type * from './TextRange.ts';
34
37
  export type * from './TriggerNode.ts';
35
- export type * from './unsupported/UploadNode.ts';
38
+ export type * from './UploadNode.ts';
36
39
  export type * from './validation.ts';
37
40
  export type * from './ValueType.ts';
@@ -1,4 +1,3 @@
1
- export type UnsupportedControlNodeType = 'upload';
2
1
  export type RepeatRangeNodeType = 'repeat-range:controlled' | 'repeat-range:uncontrolled';
3
- export type LeafNodeType = 'model-value' | 'note' | 'select' | 'input' | 'trigger' | 'range' | 'rank' | UnsupportedControlNodeType;
4
- export type InstanceNodeType = 'root' | RepeatRangeNodeType | 'repeat-instance' | 'group' | 'subtree' | LeafNodeType | UnsupportedControlNodeType;
2
+ export type LeafNodeType = 'model-value' | 'note' | 'select' | 'input' | 'trigger' | 'range' | 'rank' | 'upload';
3
+ export type InstanceNodeType = 'root' | RepeatRangeNodeType | 'repeat-instance' | 'group' | 'subtree' | LeafNodeType;
@@ -1,12 +1,14 @@
1
1
  import { INSTANCE_FILE_NAME, InstanceFile } from './InstanceFile.ts';
2
2
  export type InstanceAttachmentFileName = string;
3
+ export type InstanceDataEntryValue = File;
3
4
  export interface InstanceData extends FormData {
5
+ [Symbol.iterator](): FormDataIterator<[string, InstanceDataEntryValue]>;
6
+ entries(): FormDataIterator<[string, InstanceDataEntryValue]>;
7
+ values(): FormDataIterator<InstanceDataEntryValue>;
8
+ forEach(callbackfn: (value: InstanceDataEntryValue, key: string, parent: InstanceData) => void, thisArg?: any): void;
4
9
  get(name: INSTANCE_FILE_NAME): InstanceFile;
5
- /**
6
- * @todo Can we guarantee (both in static types and at runtime) that
7
- * {@link InstanceData} only contains files?
8
- */
9
- get(name: InstanceAttachmentFileName): FormDataEntryValue | null;
10
+ get(name: InstanceAttachmentFileName): InstanceDataEntryValue | null;
11
+ getAll(name: string): InstanceDataEntryValue[];
10
12
  has(name: INSTANCE_FILE_NAME): true;
11
13
  has(name: InstanceAttachmentFileName): boolean;
12
14
  }
@@ -1,6 +1,6 @@
1
1
  export type InstancePayloadType = 'chunked' | 'monolithic';
2
2
  interface BaseInstancePayloadOptions<PayloadType extends InstancePayloadType> {
3
- readonly payloadType?: PayloadType | undefined;
3
+ readonly payloadType: PayloadType;
4
4
  /**
5
5
  * As described in the
6
6
  * {@link https://docs.getodk.org/openrosa-form-submission/#extended-transmission-considerations | OpenRosa Form Submission API},
@@ -10,10 +10,11 @@ interface BaseInstancePayloadOptions<PayloadType extends InstancePayloadType> {
10
10
  readonly maxSize?: number;
11
11
  }
12
12
  interface ChunkedInstancePayloadOptions extends BaseInstancePayloadOptions<'chunked'> {
13
+ readonly payloadType: 'chunked';
13
14
  readonly maxSize: number;
14
15
  }
15
16
  interface MonolithicInstancePayloadOptions extends BaseInstancePayloadOptions<'monolithic'> {
16
- readonly payloadType?: 'monolithic' | undefined;
17
+ readonly payloadType: 'monolithic';
17
18
  readonly maxSize?: never;
18
19
  }
19
20
  export type InstancePayloadOptions<PayloadType extends InstancePayloadType = 'monolithic'> = {
@@ -0,0 +1,8 @@
1
+ import { UploadDefinition } from '../client/UploadNode.ts';
2
+ import { ValueType } from '../client/ValueType.ts';
3
+ import { XFormsSpecViolationError } from './XFormsSpecViolationError.ts';
4
+ type UnsupportedUploadValueType = Exclude<ValueType, 'binary'>;
5
+ export declare class UploadValueTypeError extends XFormsSpecViolationError {
6
+ constructor(definition: UploadDefinition<UnsupportedUploadValueType>);
7
+ }
8
+ export {};