@schema-engine/forms 0.5.0 → 0.5.2

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 (71) hide show
  1. package/README.md +3 -3
  2. package/dist/actions/index.js +4 -4
  3. package/dist/actions/plugins/index.js +3 -3
  4. package/dist/actions/plugins/registrations.js +3 -3
  5. package/dist/agent-tool/index.js +1 -1
  6. package/dist/{chunk-U2X3IYSD.js → chunk-6EYX257T.js} +1 -1
  7. package/dist/{chunk-HEAKWS27.js → chunk-A5VLMQAK.js} +693 -643
  8. package/dist/chunk-A5VLMQAK.js.map +7 -0
  9. package/dist/{chunk-5QXT7YAJ.js → chunk-CANRZY5A.js} +1 -1
  10. package/dist/{chunk-2VKEOE2L.js → chunk-GQHMU3AR.js} +12 -12
  11. package/dist/{chunk-WS7SLVXL.js → chunk-JA5ET6MC.js} +4 -4
  12. package/dist/{chunk-2PTM54FQ.js → chunk-KH6QWB5Y.js} +2 -2
  13. package/dist/chunk-PCL2KNHC.js.map +7 -0
  14. package/dist/{chunk-56CJ2UZ7.js → chunk-TSKELYW7.js} +2 -2
  15. package/dist/chunk-U3YHTQHR.js +215 -0
  16. package/dist/chunk-U3YHTQHR.js.map +7 -0
  17. package/dist/{chunk-XPQRHO5E.js → chunk-V5H7L5PJ.js} +1 -1
  18. package/dist/engine/build-form-engine.js +7 -7
  19. package/dist/engine/create-form-engine.js +8 -8
  20. package/dist/engine/form-engine.js +7 -7
  21. package/dist/engine/index.js +8 -8
  22. package/dist/engine/step-machine.js +1 -1
  23. package/dist/engine/submission-schema.js +1 -1
  24. package/dist/engine/value-validation.js +1 -1
  25. package/dist/index.js +26 -26
  26. package/dist/lib/validate-form.js +4 -4
  27. package/dist/recipes/index.js +1 -1
  28. package/dist/recipes/view-model.js +1 -1
  29. package/dist/runtime/create-form-runtime.js +7 -7
  30. package/dist/runtime/index.js +7 -7
  31. package/dist/schemas/base-field.js +2 -2
  32. package/dist/schemas/form-config-shape.js +2 -2
  33. package/dist/schemas/form-config.js +2 -2
  34. package/dist/schemas/index.js +5 -5
  35. package/dist/schemas/validation/dependencies.js +1 -1
  36. package/dist/schemas/validation/index.js +5 -5
  37. package/dist/schemas/validation/utils.js +1 -1
  38. package/dist/schemas/validation/validation-registry.js +1 -1
  39. package/dist/server-errors/from-json-api-errors.js +3 -3
  40. package/dist/server-errors/from-problem-details.js +3 -3
  41. package/dist/server-errors/index.js +6 -6
  42. package/dist/server-errors/shared.js +2 -2
  43. package/dist/state-container/create-form-state-container.js +5 -5
  44. package/dist/state-container/index.d.ts +1 -1
  45. package/dist/state-container/index.js +12 -12
  46. package/dist/state-container/selectors.js +1 -1
  47. package/dist/state-container/submission.js +1 -1
  48. package/dist/state-container/types.d.ts +1 -1
  49. package/dist/state-container/types.js +1 -1
  50. package/dist/testing/assert.d.ts +92 -0
  51. package/dist/testing/assert.js +42 -0
  52. package/dist/testing/assert.js.map +7 -0
  53. package/dist/testing/form-state-container-conformance.d.ts +15 -3
  54. package/dist/testing/form-state-container-conformance.js +4 -3
  55. package/dist/testing/index.d.ts +3 -2
  56. package/dist/testing/index.js +4 -3
  57. package/package.json +7 -13
  58. package/skill/SKILL.md +14 -14
  59. package/skill/reference/forms.md +7 -6
  60. package/dist/chunk-HEAKWS27.js.map +0 -7
  61. package/dist/chunk-PXWVKJGF.js.map +0 -7
  62. package/dist/{chunk-U2X3IYSD.js.map → chunk-6EYX257T.js.map} +0 -0
  63. package/dist/{chunk-5QXT7YAJ.js.map → chunk-CANRZY5A.js.map} +0 -0
  64. package/dist/{chunk-GY657L56.js → chunk-DP7SYLLI.js} +5 -5
  65. /package/dist/{chunk-GY657L56.js.map → chunk-DP7SYLLI.js.map} +0 -0
  66. /package/dist/{chunk-2VKEOE2L.js.map → chunk-GQHMU3AR.js.map} +0 -0
  67. /package/dist/{chunk-WS7SLVXL.js.map → chunk-JA5ET6MC.js.map} +0 -0
  68. /package/dist/{chunk-2PTM54FQ.js.map → chunk-KH6QWB5Y.js.map} +0 -0
  69. /package/dist/{chunk-PXWVKJGF.js → chunk-PCL2KNHC.js} +0 -0
  70. /package/dist/{chunk-56CJ2UZ7.js.map → chunk-TSKELYW7.js.map} +0 -0
  71. /package/dist/{chunk-XPQRHO5E.js.map → chunk-V5H7L5PJ.js.map} +0 -0
@@ -0,0 +1,92 @@
1
+ /**
2
+ * The assertions, spy and timing helpers the conformance suite runs on.
3
+ *
4
+ * @remarks
5
+ * Internal to the suite and not exported from the entry. They use no test runner, `node:assert` or any other
6
+ * Node-only module, so a case runs the same under Vitest, Jest, Bun, `node:test` or in a browser: a failed check
7
+ * throws an {@link AssertionError} and the runner reports it as a failed test.
8
+ */
9
+ /** The error a failed check throws; its message shows what was received and what was expected. */
10
+ export declare class AssertionError extends Error {
11
+ readonly name = "AssertionError";
12
+ }
13
+ /** Fails unless the values are deeply equal; a property set to `undefined` equals a missing one. */
14
+ export declare function assertEqual(actual: unknown, expected: unknown, label?: string): void;
15
+ /** Fails unless the values are the same, by `Object.is`. */
16
+ export declare function assertSame(actual: unknown, expected: unknown, label?: string): void;
17
+ /** Fails when the values are the same, by `Object.is`. */
18
+ export declare function assertNotSame(actual: unknown, unexpected: unknown, label?: string): void;
19
+ /** Fails unless `actual` has every key and value `partial` names, however many more it has. */
20
+ export declare function assertMatches(actual: unknown, partial: unknown, label?: string): void;
21
+ /** Fails unless the value is `undefined`. */
22
+ export declare function assertUndefined(actual: unknown, label?: string): void;
23
+ /** Fails when the value is `undefined`. */
24
+ export declare function assertDefined(actual: unknown, label?: string): void;
25
+ /** Fails unless the array has `length` items. */
26
+ export declare function assertLength(actual: ArrayLike<unknown>, length: number, label?: string): void;
27
+ /** Fails when the text matches `pattern`. */
28
+ export declare function assertNotMatches(actual: string, pattern: RegExp, label?: string): void;
29
+ /** Fails when the object has the property, own or inherited. */
30
+ export declare function assertNoProperty(actual: object, key: string, label?: string): void;
31
+ /** Fails when the array holds the item, by `Object.is`. */
32
+ export declare function assertNotIncludes(actual: readonly unknown[], item: unknown, label?: string): void;
33
+ /**
34
+ * Fails unless `run` throws.
35
+ *
36
+ * @remarks
37
+ * `expected` narrows what it throws: an error class, or a pattern its message must match.
38
+ */
39
+ export declare function assertThrows(run: () => unknown, expected?: RegExp | (new (...args: never[]) => Error)): void;
40
+ /** Fails when `run` throws, and shows what it threw. */
41
+ export declare function assertDoesNotThrow(run: () => unknown): void;
42
+ /** A function that records each call it receives; see {@link createSpy}. */
43
+ export interface Spy<Args extends unknown[] = unknown[], Result = unknown> {
44
+ (...args: Args): Result;
45
+ /** The arguments of every call, oldest first. */
46
+ readonly calls: Args[];
47
+ /** Swaps what the spy does from now on; calls already recorded stay. */
48
+ implement(implementation: (...args: Args) => Result): void;
49
+ }
50
+ /**
51
+ * A function that records its calls and runs `implementation`, if given.
52
+ *
53
+ * @remarks
54
+ * Without an implementation the spy returns `undefined`, so give one whenever the caller reads the result.
55
+ */
56
+ export declare function createSpy<Args extends unknown[] = unknown[], Result = unknown>(implementation?: (...args: Args) => Result): Spy<Args, Result>;
57
+ /** Fails unless the spy was called exactly `times` times. */
58
+ export declare function assertCallCount(spy: {
59
+ readonly calls: readonly unknown[];
60
+ }, times: number, label?: string): void;
61
+ /**
62
+ * Puts `value` on `target` under `key` and returns what undoes it.
63
+ *
64
+ * @remarks
65
+ * A property that was inherited or missing before is removed again instead of being left behind as an own one.
66
+ */
67
+ export declare function replaceProperty(target: object, key: PropertyKey, value: unknown): () => void;
68
+ /**
69
+ * Replaces a global, such as `fetch`, and returns what restores it.
70
+ *
71
+ * @remarks
72
+ * Call the restore function in a `finally`, so a failing case cannot leak the stub into the next test.
73
+ */
74
+ export declare function stubGlobal(name: string, value: unknown): () => void;
75
+ /** Replaces `target[key]` with a {@link Spy} that calls `implementation`, and returns the spy with what restores the original. */
76
+ export declare function spyOn<Args extends unknown[], Result>(target: object, key: PropertyKey, implementation?: (...args: Args) => Result): {
77
+ readonly spy: Spy<Args, Result>;
78
+ readonly restore: () => void;
79
+ };
80
+ /** How long {@link waitFor} keeps trying, and how long it waits between tries. */
81
+ export interface WaitForOptions {
82
+ readonly timeout?: number;
83
+ readonly interval?: number;
84
+ }
85
+ /**
86
+ * Calls `check` until it stops throwing and resolves with what it returned.
87
+ *
88
+ * @remarks
89
+ * Defaults to the 1000 ms timeout and 50 ms interval of Vitest's `vi.waitFor`. Rethrows the last error `check`
90
+ * threw once the timeout passes, so the failure names the assertion that never held.
91
+ */
92
+ export declare function waitFor<Result>(check: () => Result | Promise<Result>, { timeout, interval }?: WaitForOptions): Promise<Result>;
@@ -0,0 +1,42 @@
1
+ import {
2
+ AssertionError,
3
+ assertCallCount,
4
+ assertDefined,
5
+ assertDoesNotThrow,
6
+ assertEqual,
7
+ assertLength,
8
+ assertMatches,
9
+ assertNoProperty,
10
+ assertNotIncludes,
11
+ assertNotMatches,
12
+ assertNotSame,
13
+ assertSame,
14
+ assertThrows,
15
+ assertUndefined,
16
+ createSpy,
17
+ replaceProperty,
18
+ spyOn,
19
+ stubGlobal,
20
+ waitFor
21
+ } from "../chunk-U3YHTQHR.js";
22
+ export {
23
+ AssertionError,
24
+ assertCallCount,
25
+ assertDefined,
26
+ assertDoesNotThrow,
27
+ assertEqual,
28
+ assertLength,
29
+ assertMatches,
30
+ assertNoProperty,
31
+ assertNotIncludes,
32
+ assertNotMatches,
33
+ assertNotSame,
34
+ assertSame,
35
+ assertThrows,
36
+ assertUndefined,
37
+ createSpy,
38
+ replaceProperty,
39
+ spyOn,
40
+ stubGlobal,
41
+ waitFor
42
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -43,9 +43,21 @@ export declare function watchValidation(store: FormStateContainer): {
43
43
  /** Every rule of the contract, for a test that checks a deliberately broken store fails the rule it breaks. */
44
44
  export declare const formStateContainerCases: readonly FormStateContainerCase[];
45
45
  /**
46
- * Registers the internal form store contract as vitest tests against the store `createStore` builds.
46
+ * The two functions of a test runner the conformance suite registers its cases with.
47
47
  *
48
48
  * @remarks
49
- * Call it from a test file, like `rendererConformance`. A fresh store is built for each test.
49
+ * Structural, so the `describe` and `test` of Vitest, Jest, Bun test and `node:test` satisfy it as they are:
50
+ * `formStateContainerConformance(createStore, { describe, test })`.
50
51
  */
51
- export declare function formStateContainerConformance(createStore: FormStateContainerFactory): void;
52
+ export interface ConformanceRunner {
53
+ describe(name: string, register: () => void): void;
54
+ test(name: string, run: () => void | Promise<void>): void;
55
+ }
56
+ /**
57
+ * Registers the internal form store contract as tests of `runner` against the store `createStore` builds.
58
+ *
59
+ * @remarks
60
+ * Call it from a test file, like `rendererConformance`. A fresh store is built for each test. The suite uses no
61
+ * test runner itself, so any runner with `describe` and `test` works, in Node or in a browser.
62
+ */
63
+ export declare function formStateContainerConformance(createStore: FormStateContainerFactory, runner: ConformanceRunner): void;
@@ -4,7 +4,7 @@ import {
4
4
  formStateContainerCases,
5
5
  formStateContainerConformance,
6
6
  watchValidation
7
- } from "../chunk-HEAKWS27.js";
7
+ } from "../chunk-A5VLMQAK.js";
8
8
  import "../chunk-CRVXBWSY.js";
9
9
  import "../chunk-KFQEDSYI.js";
10
10
  import "../chunk-6IZYNHZ3.js";
@@ -25,15 +25,16 @@ import "../chunk-YDGH7DTL.js";
25
25
  import "../chunk-S7I76ISM.js";
26
26
  import "../chunk-CRQWKC67.js";
27
27
  import "../chunk-QLGM2AZW.js";
28
- import "../chunk-OR2L7EKO.js";
29
28
  import "../chunk-ZUYSGCEH.js";
29
+ import "../chunk-OR2L7EKO.js";
30
30
  import "../chunk-6BAJHAGL.js";
31
31
  import "../chunk-6NV2JDGI.js";
32
- import "../chunk-PXWVKJGF.js";
32
+ import "../chunk-PCL2KNHC.js";
33
33
  import "../chunk-RB22U6HI.js";
34
34
  import "../chunk-K5TMXCMY.js";
35
35
  import "../chunk-3YLRJVVN.js";
36
36
  import "../chunk-CMPOBBRV.js";
37
+ import "../chunk-U3YHTQHR.js";
37
38
  export {
38
39
  containerOptions,
39
40
  defaultModes,
@@ -2,6 +2,7 @@
2
2
  * The conformance suite of the form state container contract.
3
3
  *
4
4
  * @remarks
5
- * It imports `vitest`, an optional peer dependency of the package: import this entry only from a test file.
5
+ * It depends on no test runner: pass the `describe` and `test` of Vitest, Jest, Bun test, `node:test` or any runner
6
+ * with the same two functions. Import this entry only from a test file.
6
7
  */
7
- export { formStateContainerConformance } from './form-state-container-conformance';
8
+ export { formStateContainerConformance, type ConformanceRunner } from './form-state-container-conformance';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  formStateContainerConformance
3
- } from "../chunk-HEAKWS27.js";
3
+ } from "../chunk-A5VLMQAK.js";
4
4
  import "../chunk-CRVXBWSY.js";
5
5
  import "../chunk-KFQEDSYI.js";
6
6
  import "../chunk-6IZYNHZ3.js";
@@ -21,15 +21,16 @@ import "../chunk-YDGH7DTL.js";
21
21
  import "../chunk-S7I76ISM.js";
22
22
  import "../chunk-CRQWKC67.js";
23
23
  import "../chunk-QLGM2AZW.js";
24
- import "../chunk-OR2L7EKO.js";
25
24
  import "../chunk-ZUYSGCEH.js";
25
+ import "../chunk-OR2L7EKO.js";
26
26
  import "../chunk-6BAJHAGL.js";
27
27
  import "../chunk-6NV2JDGI.js";
28
- import "../chunk-PXWVKJGF.js";
28
+ import "../chunk-PCL2KNHC.js";
29
29
  import "../chunk-RB22U6HI.js";
30
30
  import "../chunk-K5TMXCMY.js";
31
31
  import "../chunk-3YLRJVVN.js";
32
32
  import "../chunk-CMPOBBRV.js";
33
+ import "../chunk-U3YHTQHR.js";
33
34
  export {
34
35
  formStateContainerConformance
35
36
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@schema-engine/forms",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.5.2",
5
5
  "description": "The forms domain of Schema Engine: JSON forms with elements, validation, constraints, steps, form state and submission, with no renderer",
6
6
  "keywords": [
7
7
  "schema-engine",
@@ -46,27 +46,21 @@
46
46
  "effect": "^3.22.1",
47
47
  "esbuild": "^0.27.0",
48
48
  "tsc-alias": "^1.8.16",
49
+ "typescript": "^5.9.3",
49
50
  "valibot": "^1.4.2",
50
- "vitest": "^4.0.13",
51
+ "vitest": "^5.1.1",
51
52
  "yaml": "2.9.1",
52
53
  "@schema-engine/scripts": "0.0.0"
53
54
  },
54
55
  "dependencies": {
55
56
  "@ecopages/logger": "^0.2.3",
56
57
  "@standard-schema/spec": "^1.1.0",
57
- "@schema-engine/actions": "^0.5.0",
58
- "@schema-engine/layout": "^0.5.0",
59
- "@schema-engine/registry": "^0.5.0"
58
+ "@schema-engine/actions": "^0.5.1",
59
+ "@schema-engine/layout": "^0.5.1",
60
+ "@schema-engine/registry": "^0.5.1"
60
61
  },
61
62
  "peerDependencies": {
62
- "typescript": "^5.4",
63
- "zod": "^4.0.17",
64
- "vitest": "^4.0.13"
65
- },
66
- "peerDependenciesMeta": {
67
- "vitest": {
68
- "optional": true
69
- }
63
+ "zod": "^4.0.17"
70
64
  },
71
65
  "exports": {
72
66
  "./package.json": {
package/skill/SKILL.md CHANGED
@@ -27,7 +27,7 @@ This file is the router. It defines the concepts once; the references assume the
27
27
 
28
28
  - **config**: a form is plain data, a `FormConfig` of steps holding elements, each with a `$type`, a `name`, `rules` and `constraints`. `engine.defineForm()` (typed, in TypeScript) or `engine.validateForm(unknown)` (portable JSON) checks it against the engine's registrations and returns a frozen `NormalizedFormConfig` that the engine owns.
29
29
  - **container**: the form's state, a `FormStateContainer` from `@schema-engine/forms/state-container`. It owns the nested values, errors, warnings, touched and dirty marks, field-array row ids and the validation in flight. Paths are dotted (`contacts.1.email`) and `FORM_ROOT` is the form itself. Every change is a command (`setValue`, `blur`, `reportNative`, `validate`, `submit`, `reset`, `fieldArray`), and every read is a pure selector over an immutable snapshot.
30
- - **runtime**: `createFormRuntime` is the lifecycle every renderer shares. It builds the container and owns the submission, the wizard steps and their navigation, `form_mount` and `form_change`, and every action dispatch. A renderer supplies only what an element can do, such as focus.
30
+ - **runtime**: for renderer authors, `createFormRuntime` is the lifecycle every renderer shares, and a renderer creates one for each form it draws. It builds the container and owns the submission, the wizard steps and their navigation, `form_mount` and `form_change`, and every action dispatch. A renderer supplies only what an element can do, such as focus. An app does not create one: it gives the engine and a config to a renderer.
31
31
  - **issues and the formatter**: the engine reports what is wrong as an issue (`type`, `source`, `ruleId`, `params`, `message`) and never makes up text. `formatIssue`, a function of the application, turns an issue into the words shown, and falls back to the issue's own `message`.
32
32
 
33
33
  Outcomes use one vocabulary: a check or a submission ends `passed`, `invalid` or `overtaken`. `overtaken` means an edit or a reset outran the check, so there is no verdict and nothing to show.
@@ -49,19 +49,19 @@ A symbol has one import path. `@schema-engine/forms` has these entries: `.` (the
49
49
 
50
50
  Each package ships this router as its own `skill/SKILL.md` and its references in its `skill/reference/` folder, so a reference is `node_modules/@schema-engine/<package>/skill/reference/<file>`, and any installed package has the router. Read the rows of the packages the project depends on and skip the others: a package that is not installed has no file. The deployed site serves the latest version of the router and of every reference at `/skill/`, with the references flat at `/skill/reference/<file>`.
51
51
 
52
- | To do | Package | Reference |
53
- | ---------------------------------------------------------------------------- | ------------------------------ | ------------------------------------ |
54
- | Register something, build a registry, or read a YAML document | `@schema-engine/registry` | `reference/registry.md` |
55
- | Parse, dispatch or cancel actions outside a form | `@schema-engine/actions` | `reference/actions.md` |
56
- | Build a grid, an appearance axis or a layout theme | `@schema-engine/layout` | `reference/layout.md` |
57
- | Create an engine, author a config, use the container or the runtime directly | `@schema-engine/forms` | `reference/forms.md` |
58
- | Add a rule, explain a validation result, or translate messages | `@schema-engine/forms` | `reference/forms-validation.md` |
59
- | Handle submit, server errors, CSRF or wizard steps | `@schema-engine/forms` | `reference/forms-submission.md` |
60
- | Run code on a form event, or define a form action | `@schema-engine/forms` | `reference/forms-actions.md` |
61
- | Render a form in React, or use its hooks | `@schema-engine/forms-react` | `reference/forms-react.md` |
62
- | Write or change a React field widget, and test it | `@schema-engine/forms-react` | `reference/forms-react-widgets.md` |
63
- | Render a form in Radiant, or reach the container from an element | `@schema-engine/forms-radiant` | `reference/forms-radiant.md` |
64
- | Write or change a Radiant field widget, and test it | `@schema-engine/forms-radiant` | `reference/forms-radiant-widgets.md` |
52
+ | To do | Package | Reference |
53
+ | ---------------------------------------------------------------- | ------------------------------ | ------------------------------------ |
54
+ | Register something, build a registry, or read a YAML document | `@schema-engine/registry` | `reference/registry.md` |
55
+ | Parse, dispatch or cancel actions outside a form | `@schema-engine/actions` | `reference/actions.md` |
56
+ | Build a grid, an appearance axis or a layout theme | `@schema-engine/layout` | `reference/layout.md` |
57
+ | Create an engine, author a config, or use the container directly | `@schema-engine/forms` | `reference/forms.md` |
58
+ | Add a rule, explain a validation result, or translate messages | `@schema-engine/forms` | `reference/forms-validation.md` |
59
+ | Handle submit, server errors, CSRF or wizard steps | `@schema-engine/forms` | `reference/forms-submission.md` |
60
+ | Run code on a form event, or define a form action | `@schema-engine/forms` | `reference/forms-actions.md` |
61
+ | Render a form in React, or use its hooks | `@schema-engine/forms-react` | `reference/forms-react.md` |
62
+ | Write or change a React field widget, and test it | `@schema-engine/forms-react` | `reference/forms-react-widgets.md` |
63
+ | Render a form in Radiant, or reach the container from an element | `@schema-engine/forms-radiant` | `reference/forms-radiant.md` |
64
+ | Write or change a Radiant field widget, and test it | `@schema-engine/forms-radiant` | `reference/forms-radiant-widgets.md` |
65
65
 
66
66
  ## Documentation map
67
67
 
@@ -1,10 +1,10 @@
1
1
  # @schema-engine/forms
2
2
 
3
- The engine, the config, validation timing, constraints, the container and the runtime. The terms are defined in the router (`SKILL.md`).
3
+ The engine, the config, validation timing, constraints, the container and, for renderer authors, the runtime. The terms are defined in the router (`SKILL.md`).
4
4
 
5
5
  ## Engine
6
6
 
7
- `createFormEngine` takes `elements`, `recipes`, `actions`, `validations` (extra rules), `layout`, `formatIssue`, `fetch` and `csrf`. It builds read-only registries (a later `$type` replaces an earlier one) and returns an immutable engine: create it once and reuse it. `engine.extend({ ... })` adds registrations and inherits the layout theme. The package ships no field widgets; an element is registered with `defineInput({ $type, schema, metadata, value, render })` (see Registrations below), and renderer packages bring the widgets.
7
+ `createFormEngine` takes `elements`, `recipes`, `actions`, `validations` (extra rules), `layout`, `formatIssue`, `fetch` and `csrf`. It builds read-only registries (a later `$type` replaces an earlier one) and returns an immutable engine: create it once and reuse it. `engine.extend({ ... })` adds registrations and inherits the layout theme. An app gives the engine and a config to a renderer: `FormRenderer` in `forms-react.md` or `forms-radiant.md`. The package ships no field widgets; an element is registered with `defineInput({ $type, schema, metadata, value, render })` (see Registrations below), and renderer packages bring the widgets.
8
8
 
9
9
  ```ts title="forms/engine.ts"
10
10
  import * as z from 'zod/mini';
@@ -139,9 +139,9 @@ export async function submitContact(name: string, email: string) {
139
139
  - `getSnapshot()` is stable until something changes. Read it with `selectValue` and `selectFieldState` (its `error` is the one of exactly that path), which return the same object while what they read is unchanged, so they are safe for `useSyncExternalStore`.
140
140
  - `toHydration(container.getServerSnapshot())` is the serializable part a server hands to a client, which passes it as `snapshot` so row ids survive.
141
141
 
142
- ## Runtime
142
+ ## Runtime (for renderer authors)
143
143
 
144
- `createFormRuntime({ engine, config, host, onSubmit, ... })` wraps a container with the submission, the wizard and the actions. `host.focus(paths)` is the only required host member; a renderer adds `sync` and `submitNatively` when it needs them.
144
+ An app does not create a runtime: a renderer creates one for each form it draws, and an app reaches it with a hook or a controller (`useFormRuntime`, `FormController`). `createFormRuntime({ engine, config, host, onSubmit, ... })` wraps a container with the submission, the wizard and the actions. `host.focus(paths)` is the only required host member; a renderer adds `sync` and `submitNatively` when it needs them.
145
145
 
146
146
  ```ts title="forms/runtime.ts"
147
147
  import { createFormRuntime, type FormValues } from '@schema-engine/forms';
@@ -163,13 +163,14 @@ Every command resolves one string: `moved`, `submitted`, `failed`, `invalid`, `o
163
163
 
164
164
  ## Testing a container
165
165
 
166
- A container of your own, or a store that must behave like this one, proves it with the conformance suite. It registers its cases with vitest, an optional peer dependency, so import this entry only from a test file.
166
+ A container of your own, or a store that must behave like this one, proves it with the conformance suite. It depends on no test runner: pass the `describe` and `test` of yours (Vitest below; Jest, Bun and `node:test` work the same), and import this entry only from a test file.
167
167
 
168
168
  ```ts title="forms/container-conformance.test.ts"
169
+ import { describe, test } from 'vitest';
169
170
  import { createFormStateContainer } from '@schema-engine/forms/state-container';
170
171
  import { formStateContainerConformance } from '@schema-engine/forms/testing';
171
172
 
172
- formStateContainerConformance(createFormStateContainer);
173
+ formStateContainerConformance(createFormStateContainer, { describe, test });
173
174
  ```
174
175
 
175
176
  Save your copy as `container-conformance.test.ts`.