Skip to content

Commit 600d978

Browse files
committed
allow for already resolved files
1 parent ddb9abd commit 600d978

5 files changed

Lines changed: 18 additions & 57 deletions

File tree

packages/web-forms/src/lib/locale/useLocale.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createIntl, type IntlShape } from '@formatjs/intl';
22
import type { FormLanguage, RootNode } from '@getodk/xforms-engine';
3-
import { all as primeLocales } from 'primelocale';
43
import type { Ref } from 'vue';
54
import { computed, onUnmounted, shallowRef, watch } from 'vue';
65
// English strings always available as language fallback
@@ -185,9 +184,9 @@ export const useLocale = (formRef: Ref<RootNode | null>) => {
185184
const newContentLocale = formBaseLocale ?? FALLBACK;
186185
document.documentElement.lang = newContentLocale;
187186
latestRequestedLocale.locale = newContentLocale;
188-
const primeLocaleKey = findBestLocale(candidates, (lang) => {
189-
return Object.hasOwn(primeLocales, lang);
190-
});
187+
// const primeLocaleKey = findBestLocale(candidates, (lang) => {
188+
// return Object.hasOwn(primeLocales, lang);
189+
// });
191190
// const primeLocale = primeLocales[primeLocaleKey as keyof typeof primeLocales];
192191
// if (primeLocale) {
193192
// primevue.config.locale = { ...primevue.config.locale, ...primeLocale };

packages/xforms-engine/src/instance/attachments/InstanceAttachmentsState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class InstanceAttachmentsState extends Map<InstanceAttachmentContext, Ins
88
super();
99
}
1010

11-
getInitialFileValue(instanceNode: StaticLeafElement | null): Promise<File> | null {
11+
getInitialFileValue(instanceNode: StaticLeafElement | null): File | Promise<File> | null {
1212
if (instanceNode == null) {
1313
return null;
1414
}

packages/xforms-engine/src/instance/input/InitialInstanceState.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getBlobText } from '@getodk/common/lib/web-compat/blob.ts';
2+
import { INSTANCE_FILE_NAME } from '../../client/constants.ts';
23
import type {
34
EditFormInstanceInput,
45
ResolvableFormInstanceInput,
@@ -74,17 +75,16 @@ export class InitialInstanceState {
7475
input: EditFormInstanceInput
7576
): Promise<InitialInstanceState> {
7677
if (input.inputType === 'FORM_INSTANCE_INPUT_RESOLVED') {
77-
throw new Error('not yet implemented');
78-
// const { data } = input;
79-
// const [instanceData] = data;
80-
// const instanceFile = instanceData.get(INSTANCE_FILE_NAME);
81-
// const instanceXML = await getBlobText(instanceFile);
82-
// const attachments = InstanceAttachmentMap.from(data); // TODO wtaf
83-
84-
// return new this(model, {
85-
// instanceXML,
86-
// attachments,
87-
// });
78+
const { data } = input;
79+
const [instanceData] = data;
80+
const instanceFile = instanceData.get(INSTANCE_FILE_NAME);
81+
const instanceXML = await getBlobText(instanceFile);
82+
const attachments = InstanceAttachmentMap.from(data);
83+
84+
return new this(model, {
85+
instanceXML,
86+
attachments,
87+
});
8888
}
8989

9090
const instanceXML = await resolveInstanceXML(input);

packages/xforms-engine/src/instance/input/InstanceAttachmentMap.ts

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { MalformedInstanceDataError } from '../../error/MalformedInstanceDataErr
55
import { getResponseContentType } from '../../lib/resource-helpers.ts';
66
import type { FetchResourceResponse } from '../resource.ts';
77

8-
type InstanceAttachmentMapSourceEntry = readonly [key: string, value: Promise<File>];
8+
type InstanceAttachmentMapSourceEntry = readonly [key: string, value: File | Promise<File>];
99

1010
interface InstanceAttachmentMapSource {
1111
entries(): Iterable<InstanceAttachmentMapSourceEntry>;
@@ -52,44 +52,7 @@ const resolveInstanceAttachmentMapSource = (
5252
return { entries: () => entries };
5353
};
5454

55-
interface KeyedInstanceDataFile<Key extends string> extends File {
56-
readonly name: Key;
57-
}
58-
59-
type AssertKeyedInstanceDataFile = <Key extends string>(
60-
key: Key,
61-
file: File
62-
) => asserts file is KeyedInstanceDataFile<Key>;
63-
64-
const assertKeyedInstanceDataFile: AssertKeyedInstanceDataFile = (key, file) => {
65-
if (file.name !== key) {
66-
throw new MalformedInstanceDataError(
67-
`Unexpected InstanceData file. Expected file name to match key, got key: ${JSON.stringify(key)} and file name: ${JSON.stringify(file.name)}`
68-
);
69-
}
70-
};
71-
72-
type UnknownInstanceDataEntry = readonly [key: string, value: FormDataEntryValue];
73-
74-
type KeyedInstanceDataEntry<Key extends string> = readonly [key: Key, KeyedInstanceDataFile<Key>];
75-
76-
type AssertInstanceDataEntry = <Key extends string>(
77-
entry: UnknownInstanceDataEntry
78-
) => asserts entry is KeyedInstanceDataEntry<Key>;
79-
80-
const assertInstanceDataEntry: AssertInstanceDataEntry = (entry) => {
81-
const [key, value] = entry;
82-
83-
if (!(value instanceof File)) {
84-
throw new MalformedInstanceDataError(
85-
`Unexpected non-file attachment in InstanceData for key: ${key}`
86-
);
87-
}
88-
89-
assertKeyedInstanceDataFile(key, value);
90-
};
91-
92-
export class InstanceAttachmentMap extends Map<string, Promise<File>> {
55+
export class InstanceAttachmentMap extends Map<string, File | Promise<File>> {
9356
static from(sources: readonly InstanceAttachmentMapSource[]): InstanceAttachmentMap {
9457
return new this(sources);
9558
}

packages/xforms-engine/src/lib/reactivity/createInstanceAttachment.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ export const createInstanceAttachment = (
138138
const { rootDocument, nodeId } = context;
139139
const { attachments } = rootDocument;
140140

141-
// TODO THIS IS IT
142141
const filePromise = attachments.getInitialFileValue(context.instanceNode);
143142
const initialState = instanceAttachmentState(context, {
144143
nodeId,
@@ -149,7 +148,7 @@ export const createInstanceAttachment = (
149148
const [getState, setState] = createSignal<InstanceAttachmentState>(initialState);
150149

151150
if (filePromise) {
152-
void filePromise.then((file: File) => {
151+
void Promise.resolve(filePromise).then((file: File) => {
153152
const resolvedState = instanceAttachmentState(context, {
154153
nodeId,
155154
file,

0 commit comments

Comments
 (0)