diff --git a/.changeset/ten-wolves-reflect.md b/.changeset/ten-wolves-reflect.md new file mode 100644 index 000000000..e8501f45e --- /dev/null +++ b/.changeset/ten-wolves-reflect.md @@ -0,0 +1,13 @@ +--- +'@getodk/xforms-engine': minor +--- + +**BREAKING CHANGE** + +The main engine entrypoint (formerly `initializeForm`) has been split into: + +- `loadForm`, producing an intermediate result from which many instances of the same form can be created (with a `createInstance` method on that result) + +- `createInstance`, a convenience wrapper composing the result from `loadForm` and its `createInstance` method to create a single instance; this entrypoint effectively restores the behavior of `initializeForm` + +Some interfaces related to the former `initializeForm` have also been refined to reflect this change. diff --git a/packages/scenario/src/client/init.ts b/packages/scenario/src/client/init.ts index 95070bf24..214eaebc0 100644 --- a/packages/scenario/src/client/init.ts +++ b/packages/scenario/src/client/init.ts @@ -1,12 +1,12 @@ import type { JRResourceService } from '@getodk/common/jr-resources/JRResourceService.ts'; import type { XFormsElement } from '@getodk/common/test/fixtures/xform-dsl/XFormsElement.ts'; import type { - EngineConfig, FormResource, + LoadFormOptions, OpaqueReactiveObjectFactory, RootNode, } from '@getodk/xforms-engine'; -import { initializeForm } from '@getodk/xforms-engine'; +import { createInstance } from '@getodk/xforms-engine'; import type { Owner } from 'solid-js'; import { createRoot, getOwner, runWithOwner } from 'solid-js'; import type { MissingResourceBehavior } from '../../../xforms-engine/dist/client/constants'; @@ -62,7 +62,7 @@ export interface InitializeTestFormOptions { const defaultConfig = { fetchFormDefinition: fetchFormDefinitionStub, -} as const satisfies Omit; +} as const satisfies LoadFormOptions; interface InitializedTestForm { readonly instanceRoot: RootNode; @@ -82,19 +82,21 @@ export const initializeTestForm = async ( } const formResource = await getFormResource(testForm); - const instanceRoot = await runWithOwner(owner, async () => { - return initializeForm(formResource, { - config: { + const instance = await runWithOwner(owner, async () => { + return createInstance(formResource, { + form: { ...defaultConfig, fetchFormAttachment: options.resourceService.handleRequest, missingResourceBehavior: options.missingResourceBehavior, + }, + instance: { stateFactory: options.stateFactory, }, }); })!; return { - instanceRoot, + instanceRoot: instance.root, owner, dispose, }; diff --git a/packages/scenario/test/serialization.test.ts b/packages/scenario/test/serialization.test.ts index c4e5536d0..5fdefe4cf 100644 --- a/packages/scenario/test/serialization.test.ts +++ b/packages/scenario/test/serialization.test.ts @@ -9,7 +9,7 @@ import { t, title, } from '@getodk/common/test/fixtures/xform-dsl/index.ts'; -import type { EngineConfig, InitializeFormOptions } from '@getodk/xforms-engine'; +import type { LoadFormOptions } from '@getodk/xforms-engine'; import { describe, expect, it } from 'vitest'; import { stringAnswer } from '../src/answer/ExpectedStringAnswer.ts'; import { Scenario } from '../src/jr/Scenario.ts'; @@ -175,8 +175,7 @@ describe('ExternalSecondaryInstanceParseTest.java', () => { * - Insofar as we may find ourselves implementing similar logic (albeit * serving other purposes), how can we establish a clear interface * contract around behaviors like this? Should it be more consistent? Does - * our current {@link EngineConfig.fetchFormDefinition} - * option—configurable in {@link InitializeFormOptions}—provide enough + * our current {@link LoadFormOptions.fetchFormDefinition} provide enough * informational surface area to communicate such intent (and allow both * clients and engine alike to have clarity of that intent at * call/handling sites)? diff --git a/packages/web-forms/src/components/OdkWebForm.vue b/packages/web-forms/src/components/OdkWebForm.vue index feed0376a..59b3d457d 100644 --- a/packages/web-forms/src/components/OdkWebForm.vue +++ b/packages/web-forms/src/components/OdkWebForm.vue @@ -1,10 +1,12 @@