@20baht/engine 0.0.0-stage → 0.1.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 (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -2
  3. package/dist/approval.d.ts +15 -0
  4. package/dist/approval.js +18 -0
  5. package/dist/dates.d.ts +34 -0
  6. package/dist/dates.js +91 -0
  7. package/dist/defaults.d.ts +6 -0
  8. package/dist/defaults.js +37 -0
  9. package/dist/display.d.ts +33 -0
  10. package/dist/display.js +110 -0
  11. package/dist/engine/conditions.d.ts +27 -0
  12. package/dist/engine/conditions.js +123 -0
  13. package/dist/engine/evaluate.d.ts +8 -0
  14. package/dist/engine/evaluate.js +368 -0
  15. package/dist/engine/expressions.d.ts +3 -0
  16. package/dist/engine/expressions.js +70 -0
  17. package/dist/engine/form-session.d.ts +129 -0
  18. package/dist/engine/form-session.js +310 -0
  19. package/dist/engine/graph.d.ts +40 -0
  20. package/dist/engine/graph.js +59 -0
  21. package/dist/engine/runtime.d.ts +173 -0
  22. package/dist/engine/runtime.js +237 -0
  23. package/dist/engine/scripts.d.ts +34 -0
  24. package/dist/engine/scripts.js +98 -0
  25. package/dist/flags.d.ts +19 -0
  26. package/dist/flags.js +49 -0
  27. package/dist/form-values.d.ts +78 -0
  28. package/dist/form-values.js +6 -0
  29. package/dist/i18n.d.ts +171 -0
  30. package/dist/i18n.js +298 -0
  31. package/dist/index.d.ts +25 -0
  32. package/dist/index.js +23 -0
  33. package/dist/keys.d.ts +14 -0
  34. package/dist/keys.js +4 -0
  35. package/dist/legacy.d.ts +14 -0
  36. package/dist/legacy.js +47 -0
  37. package/dist/pattern-safety.d.ts +34 -0
  38. package/dist/pattern-safety.js +267 -0
  39. package/dist/same-data.d.ts +5 -0
  40. package/dist/same-data.js +23 -0
  41. package/dist/shortcut.d.ts +44 -0
  42. package/dist/shortcut.js +176 -0
  43. package/dist/types.d.ts +541 -0
  44. package/dist/types.js +1 -0
  45. package/dist/urls.d.ts +8 -0
  46. package/dist/urls.js +30 -0
  47. package/dist/validators.d.ts +39 -0
  48. package/dist/validators.js +372 -0
  49. package/dist/views.d.ts +12 -0
  50. package/dist/views.js +11 -0
  51. package/package.json +49 -4
@@ -0,0 +1,368 @@
1
+ import { approvalFields } from '../approval.js';
2
+ import { defaultValue } from '../defaults.js';
3
+ import { UNSAFE_KEYS, rowSubFields } from '../keys.js';
4
+ import { conditionRowRefs, evalCondition, parseRowRef } from './conditions.js';
5
+ import { evalValueExpr } from './expressions.js';
6
+ const MAX_PASSES = 20;
7
+ function ownValue(obj, key) {
8
+ return obj !== null && typeof obj === 'object' && Object.hasOwn(obj, key)
9
+ ? obj[key]
10
+ : undefined;
11
+ }
12
+ function eq(a, b) {
13
+ if (a === b || Object.is(a, b))
14
+ return true;
15
+ if (Array.isArray(a) && Array.isArray(b)) {
16
+ return a.length === b.length && a.every((v, i) => eq(v, b[i]));
17
+ }
18
+ if (a !== null &&
19
+ b !== null &&
20
+ typeof a === 'object' &&
21
+ typeof b === 'object' &&
22
+ Object.getPrototypeOf(a) === Object.prototype &&
23
+ Object.getPrototypeOf(b) === Object.prototype) {
24
+ const ka = Object.keys(a);
25
+ const kb = Object.keys(b);
26
+ return (ka.length === kb.length &&
27
+ ka.every((k) => eq(a[k], b[k])));
28
+ }
29
+ return false;
30
+ }
31
+ function resolve(actions) {
32
+ let winner;
33
+ for (const a of actions) {
34
+ if (!winner ||
35
+ a.priority > winner.priority ||
36
+ (a.priority === winner.priority && a.index >= winner.index)) {
37
+ winner = a;
38
+ }
39
+ }
40
+ return winner?.action;
41
+ }
42
+ export function evaluate(workflow, input) {
43
+ const errors = [];
44
+ const { descriptors, formNames, data: initial } = indexWorkflow(workflow, input, errors);
45
+ let data = initial;
46
+ let fields = {};
47
+ let forms = {};
48
+ let converged = false;
49
+ for (let pass = 0; pass < MAX_PASSES; pass++) {
50
+ ({ fields, forms } = resetState(descriptors, formNames, data));
51
+ const buckets = bucketActions(workflow.rules, data, errors);
52
+ const pendingSetValues = applyBuckets(buckets, fields, forms, errors);
53
+ const next = clearHidden(data, descriptors, formNames, fields, forms);
54
+ runSetValues(pendingSetValues, next, fields, forms, errors);
55
+ const stable = eq(next, data);
56
+ data = next;
57
+ if (stable) {
58
+ converged = true;
59
+ break;
60
+ }
61
+ }
62
+ if (!converged) {
63
+ errors.push({
64
+ ref: workflow.workflow_id,
65
+ message: `rules did not converge within ${MAX_PASSES} passes (cycle?)`,
66
+ kind: 'data',
67
+ });
68
+ }
69
+ return { data: visibleOutput(data, formNames, fields, forms), fields, forms, errors };
70
+ }
71
+ function indexWorkflow(workflow, input, errors) {
72
+ const descriptors = new Map();
73
+ const formNames = [];
74
+ const data = {};
75
+ for (const form of workflow.forms) {
76
+ if (UNSAFE_KEYS.has(form.form_name)) {
77
+ errors.push({ ref: form.form_name, message: 'unsafe form name', kind: 'schema' });
78
+ continue;
79
+ }
80
+ formNames.push(form.form_name);
81
+ const values = {};
82
+ const formInput = ownValue(input, form.form_name);
83
+ for (const field of [...form.fields, ...approvalFields(form)]) {
84
+ if (field.type === 'label' || field.type === 'section')
85
+ continue;
86
+ if (UNSAFE_KEYS.has(field.key)) {
87
+ errors.push({
88
+ ref: `${form.form_name}.${field.key}`,
89
+ message: 'unsafe field key',
90
+ kind: 'schema',
91
+ });
92
+ continue;
93
+ }
94
+ descriptors.set(`${form.form_name}.${field.key}`, field);
95
+ const provided = ownValue(formInput, field.key);
96
+ values[field.key] = provided !== undefined ? provided : defaultValue(field);
97
+ }
98
+ data[form.form_name] = values;
99
+ }
100
+ return { descriptors, formNames, data };
101
+ }
102
+ function baseState(d) {
103
+ return {
104
+ visible: true,
105
+ enabled: !d.disabled,
106
+ readonly: !!d.readonly,
107
+ required: !!d.required,
108
+ computed: false,
109
+ };
110
+ }
111
+ function isRow(row) {
112
+ return typeof row === 'object' && row !== null && !Array.isArray(row);
113
+ }
114
+ function copyRows(rows) {
115
+ return rows.map((r) => (isRow(r) ? { ...r } : r));
116
+ }
117
+ function rowsOf(data, form, repeater) {
118
+ const rows = data[form]?.[repeater];
119
+ return Array.isArray(rows) ? rows : [];
120
+ }
121
+ function resetState(descriptors, formNames, data) {
122
+ const fields = {};
123
+ const forms = {};
124
+ for (const name of formNames)
125
+ forms[name] = { visible: true };
126
+ for (const [ref, d] of descriptors) {
127
+ fields[ref] = baseState(d);
128
+ if (d.type !== 'repeater')
129
+ continue;
130
+ const [form, key] = splitRef(ref);
131
+ rowsOf(data, form, key).forEach((_, i) => {
132
+ for (const sub of rowSubFields(d))
133
+ fields[`${ref}[${i}].${sub.key}`] = baseState(sub);
134
+ });
135
+ }
136
+ return { fields, forms };
137
+ }
138
+ function ruleRepeaters(rule) {
139
+ const refs = conditionRowRefs(rule.when).map((r) => `${r.form}.${r.repeater}`);
140
+ for (const action of [...(rule.then ?? []), ...(rule.else ?? [])]) {
141
+ const target = action.target;
142
+ if (!('field' in target))
143
+ continue;
144
+ const row = parseRowRef(`${target.form}.${target.field}`);
145
+ if (row)
146
+ refs.push(`${row.form}.${row.repeater}`);
147
+ }
148
+ return new Set(refs);
149
+ }
150
+ function bindAction(action, scope) {
151
+ const target = action.target;
152
+ if (!('field' in target))
153
+ return action;
154
+ const row = parseRowRef(`${target.form}.${target.field}`);
155
+ if (row?.form !== scope.form || row.repeater !== scope.repeater)
156
+ return action;
157
+ return {
158
+ ...action,
159
+ target: { form: target.form, field: `${row.repeater}[${scope.index}].${row.sub}` },
160
+ };
161
+ }
162
+ function bucketAction(buckets, action, priority, index) {
163
+ const key = bucketKey(action);
164
+ const list = buckets.get(key) ?? [];
165
+ list.push({ action, priority, index });
166
+ buckets.set(key, list);
167
+ }
168
+ function bucketActions(rules, data, errors) {
169
+ const buckets = new Map();
170
+ rules.forEach((rule, index) => {
171
+ const priority = rule.priority ?? 0;
172
+ const repeaters = ruleRepeaters(rule);
173
+ if (repeaters.size > 1) {
174
+ errors.push({
175
+ ref: rule.id ?? `rule[${index}]`,
176
+ message: 'a rule may be row-scoped to one repeater only',
177
+ kind: 'schema',
178
+ });
179
+ return;
180
+ }
181
+ const [scoped] = repeaters;
182
+ if (scoped === undefined) {
183
+ const active = evalCondition(rule.when, data) ? rule.then : rule.else;
184
+ for (const action of active ?? [])
185
+ bucketAction(buckets, action, priority, index);
186
+ return;
187
+ }
188
+ const [form, repeater] = splitRef(scoped);
189
+ rowsOf(data, form, repeater).forEach((_, i) => {
190
+ const scope = { form, repeater, index: i };
191
+ const active = evalCondition(rule.when, data, scope) ? rule.then : rule.else;
192
+ for (const action of active ?? []) {
193
+ bucketAction(buckets, bindAction(action, scope), priority, index);
194
+ }
195
+ });
196
+ });
197
+ return buckets;
198
+ }
199
+ function applyFormAction(action, key, forms, errors) {
200
+ const f = forms[action.target.form];
201
+ if (!f) {
202
+ errors.push({
203
+ ref: action.target.form,
204
+ message: `rule targets unknown form (${key})`,
205
+ kind: 'schema',
206
+ });
207
+ return;
208
+ }
209
+ f.visible = action.action === 'showForm';
210
+ }
211
+ const FIELD_STATE_MUTATORS = {
212
+ show: (st) => (st.visible = true),
213
+ hide: (st) => (st.visible = false),
214
+ enable: (st) => (st.enabled = true),
215
+ disable: (st) => (st.enabled = false),
216
+ readonly: (st) => (st.readonly = true),
217
+ required: (st) => (st.required = true),
218
+ optional: (st) => (st.required = false),
219
+ };
220
+ function applyFieldState(action, state) {
221
+ FIELD_STATE_MUTATORS[action.action]?.(state);
222
+ }
223
+ function applyBuckets(buckets, fields, forms, errors) {
224
+ const pendingSetValues = [];
225
+ for (const [key, list] of buckets) {
226
+ const action = resolve(list);
227
+ if (!action)
228
+ continue;
229
+ if (action.action === 'setValue') {
230
+ pendingSetValues.push({ ref: `${action.target.form}.${action.target.field}`, action });
231
+ }
232
+ else if (action.action === 'showForm' ||
233
+ action.action === 'hideForm' ||
234
+ action.action === 'skipForm') {
235
+ applyFormAction(action, key, forms, errors);
236
+ }
237
+ else {
238
+ const target = action.target;
239
+ const ref = `${target.form}.${target.field}`;
240
+ const state = fields[ref];
241
+ if (state)
242
+ applyFieldState(action, state);
243
+ else
244
+ errors.push({ ref, message: 'rule targets unknown field', kind: 'schema' });
245
+ }
246
+ }
247
+ return pendingSetValues;
248
+ }
249
+ function clearHidden(data, descriptors, formNames, fields, forms) {
250
+ const next = {};
251
+ for (const name of formNames)
252
+ next[name] = { ...data[name] };
253
+ for (const [ref, d] of descriptors) {
254
+ const [form_name, key] = splitRef(ref);
255
+ const hidden = !forms[form_name].visible || !fields[ref].visible;
256
+ if (hidden)
257
+ next[form_name][key] = defaultValue(d);
258
+ }
259
+ clearHiddenRowFields(next, descriptors, fields, forms);
260
+ return next;
261
+ }
262
+ function clearHiddenRowFields(next, descriptors, fields, forms) {
263
+ const copied = new Set();
264
+ for (const [ref, state] of Object.entries(fields)) {
265
+ const row = parseRowState(ref);
266
+ if (!row || state.visible)
267
+ continue;
268
+ const { repeaterRef, index, sub } = row;
269
+ const [form_name, key] = splitRef(repeaterRef);
270
+ const repeater = descriptors.get(repeaterRef);
271
+ const values = next[form_name];
272
+ if (!repeater || !values || !forms[form_name].visible)
273
+ continue;
274
+ if (!copied.has(repeaterRef)) {
275
+ values[key] = copyRows(rowsOf(next, form_name, key));
276
+ copied.add(repeaterRef);
277
+ }
278
+ const rows = values[key];
279
+ const descriptor = rowSubFields(repeater).find((f) => f.key === sub);
280
+ const target = rows[index];
281
+ if (isRow(target) && descriptor)
282
+ target[sub] = defaultValue(descriptor);
283
+ }
284
+ }
285
+ function parseRowState(ref) {
286
+ const m = /^(.+?)\[(\d+)\]\.([^.[\]]+)$/.exec(ref);
287
+ return m ? { repeaterRef: m[1], index: Number(m[2]), sub: m[3] } : null;
288
+ }
289
+ function runSetValues(pending, next, fields, forms, errors) {
290
+ for (const { ref, action } of pending) {
291
+ const [form_name, key] = splitRef(ref);
292
+ if (parseRowState(ref)) {
293
+ errors.push({
294
+ ref,
295
+ message: 'setValue on a repeater row field is not supported',
296
+ kind: 'schema',
297
+ });
298
+ continue;
299
+ }
300
+ const state = fields[ref];
301
+ if (!state) {
302
+ errors.push({ ref, message: 'setValue targets unknown field', kind: 'schema' });
303
+ continue;
304
+ }
305
+ if (!forms[form_name].visible || !state.visible)
306
+ continue;
307
+ next[form_name][key] = evalValueExpr(action.value, next);
308
+ if (action.lock !== false) {
309
+ state.readonly = true;
310
+ state.computed = true;
311
+ }
312
+ }
313
+ }
314
+ function visibleOutput(data, formNames, fields, forms) {
315
+ const output = {};
316
+ for (const name of formNames) {
317
+ if (!forms[name].visible)
318
+ continue;
319
+ const values = {};
320
+ for (const [key, value] of Object.entries(data[name])) {
321
+ if (fields[`${name}.${key}`].visible)
322
+ values[key] = value;
323
+ }
324
+ output[name] = values;
325
+ }
326
+ dropHiddenRowFields(output, fields);
327
+ return output;
328
+ }
329
+ function dropHiddenRowFields(output, fields) {
330
+ const copied = new Set();
331
+ for (const [ref, state] of Object.entries(fields)) {
332
+ const row = parseRowState(ref);
333
+ if (!row || state.visible)
334
+ continue;
335
+ const [form_name, key] = splitRef(row.repeaterRef);
336
+ const values = output[form_name];
337
+ if (!values || !Array.isArray(values[key]))
338
+ continue;
339
+ if (!copied.has(row.repeaterRef)) {
340
+ values[key] = copyRows(values[key]);
341
+ copied.add(row.repeaterRef);
342
+ }
343
+ const rows = values[key];
344
+ const target = rows[row.index];
345
+ if (isRow(target)) {
346
+ rows[row.index] = Object.fromEntries(Object.entries(target).filter(([k]) => k !== row.sub));
347
+ }
348
+ }
349
+ }
350
+ function bucketKey(action) {
351
+ const prop = action.action === 'show' || action.action === 'hide'
352
+ ? 'visible'
353
+ : action.action === 'enable' || action.action === 'disable'
354
+ ? 'enabled'
355
+ : action.action === 'required' || action.action === 'optional'
356
+ ? 'required'
357
+ : action.action === 'showForm' ||
358
+ action.action === 'hideForm' ||
359
+ action.action === 'skipForm'
360
+ ? 'formVisible'
361
+ : action.action;
362
+ const target = 'field' in action.target ? `${action.target.form}.${action.target.field}` : action.target.form;
363
+ return `${prop}:${target}`;
364
+ }
365
+ function splitRef(ref) {
366
+ const dot = ref.indexOf('.');
367
+ return [ref.slice(0, dot), ref.slice(dot + 1)];
368
+ }
@@ -0,0 +1,3 @@
1
+ import type { NestedData, ValueExpr } from '../types.js';
2
+ /** Wrapper that maps the div-by-zero NaN marker to null. */
3
+ export declare function evalValueExpr(expr: ValueExpr, data: NestedData): unknown;
@@ -0,0 +1,70 @@
1
+ import { evalCondition, readRef } from './conditions.js';
2
+ function toNumber(v) {
3
+ if (v === null || v === undefined || v === '')
4
+ return null;
5
+ const n = Number(v);
6
+ return Number.isNaN(n) ? null : n;
7
+ }
8
+ function toText(v) {
9
+ if (v === null || v === undefined)
10
+ return '';
11
+ if (typeof v === 'string')
12
+ return v;
13
+ if (typeof v === 'number' || typeof v === 'boolean' || typeof v === 'bigint')
14
+ return String(v);
15
+ if (Array.isArray(v))
16
+ return v.map(toText).join(',');
17
+ if (typeof v === 'object')
18
+ return JSON.stringify(v);
19
+ return '';
20
+ }
21
+ function normalizeNaN(v) {
22
+ return typeof v === 'number' && Number.isNaN(v) ? null : v;
23
+ }
24
+ function evalExpr(expr, data) {
25
+ if ('ref' in expr)
26
+ return readRef(data, expr.ref);
27
+ if ('const' in expr)
28
+ return expr.const;
29
+ if ('if' in expr) {
30
+ const [cond, whenTrue, whenFalse] = expr.if;
31
+ return evalCondition(cond, data)
32
+ ? normalizeNaN(evalExpr(whenTrue, data))
33
+ : normalizeNaN(evalExpr(whenFalse, data));
34
+ }
35
+ const args = expr.args.map((a) => normalizeNaN(evalExpr(a, data)));
36
+ switch (expr.op) {
37
+ case 'concat':
38
+ return args.map(toText).join('');
39
+ case 'coalesce':
40
+ return args.find((a) => a !== null && a !== undefined) ?? null;
41
+ case 'add':
42
+ case 'sub':
43
+ case 'mul':
44
+ case 'div': {
45
+ const op = expr.op;
46
+ const nums = args.map(toNumber);
47
+ if (nums.length === 0)
48
+ return null;
49
+ if (nums.some((n) => n === null))
50
+ return null;
51
+ return nums.reduce((acc, n, i) => {
52
+ if (i === 0)
53
+ return n;
54
+ switch (op) {
55
+ case 'add':
56
+ return acc + n;
57
+ case 'sub':
58
+ return acc - n;
59
+ case 'mul':
60
+ return acc * n;
61
+ case 'div':
62
+ return n === 0 ? NaN : acc / n;
63
+ }
64
+ });
65
+ }
66
+ }
67
+ }
68
+ export function evalValueExpr(expr, data) {
69
+ return normalizeNaN(evalExpr(expr, data));
70
+ }
@@ -0,0 +1,129 @@
1
+ import type { DerivedFieldState, FieldDescriptor, FormDefinition, Registry, ScriptContext, ScriptMessage, ValidationError } from '../types.js';
2
+ import { type ScriptFieldState, type ScriptSink } from './scripts.js';
3
+ /** What the host owns and hands to every step. */
4
+ export interface FormInput {
5
+ /** The definition as the form sees it (flags already applied). */
6
+ form: FormDefinition;
7
+ /** The starting data; the session's edits sit over it. */
8
+ value?: Record<string, unknown>;
9
+ registry?: Registry;
10
+ /** Rule-derived state per field key (a workflow's `Derived`), and per repeater row. */
11
+ fieldStates?: Record<string, DerivedFieldState>;
12
+ /** A view of `form.views`: only its fields are validated. Unknown: the whole form. */
13
+ view?: string | undefined;
14
+ /** When errors are checked again: on every edit once some show (default), on blur, or only on validate. */
15
+ validateOn?: 'change' | 'blur' | 'submit' | undefined;
16
+ }
17
+ export interface FormState {
18
+ /** What was entered over `value`, by key. */
19
+ edits: Readonly<Record<string, unknown>>;
20
+ errors: readonly ValidationError[];
21
+ /** Per-field overrides set by scripts; they win over `fieldStates`. */
22
+ scriptStates: Readonly<Record<string, ScriptFieldState>>;
23
+ /** `showFieldMsg()` messages, one per field. */
24
+ fieldMessages: Readonly<Record<string, ScriptMessage>>;
25
+ /** `addErrorMessage()` / `addInfoMessage()`, emptied at the start of every submit pass. */
26
+ formMessages: readonly ScriptMessage[];
27
+ }
28
+ export declare const emptyFormState: FormState;
29
+ export type FormMsg =
30
+ /** The user entered a value (already flushed from any debounce). */
31
+ {
32
+ type: 'input';
33
+ key: string;
34
+ value: unknown;
35
+ }
36
+ /** The host merged values in: change scripts run, no `baht-change`. */
37
+ | {
38
+ type: 'set';
39
+ patch: Record<string, unknown>;
40
+ }
41
+ /** Drop the edits to these keys, so each shows `value` again. */
42
+ | {
43
+ type: 'revert';
44
+ keys: readonly string[];
45
+ }
46
+ /** `value` was replaced; `previous` is the one before. It wins for the keys it changed. */
47
+ | {
48
+ type: 'value';
49
+ previous: Record<string, unknown>;
50
+ }
51
+ /** `form` was replaced; `previous` is the one before. */
52
+ | {
53
+ type: 'form';
54
+ previous: FormDefinition | undefined;
55
+ }
56
+ /** The form came up: change scripts with `isLoading`, then the load scripts. */
57
+ | {
58
+ type: 'load';
59
+ }
60
+ /** Validators over what is shown, then the submit scripts. */
61
+ | {
62
+ type: 'validate';
63
+ }
64
+ /** The user left a field (`validateOn: 'blur'`). */
65
+ | {
66
+ type: 'blur';
67
+ key: string;
68
+ }
69
+ /**
70
+ * A script handler calling back after its step (it kept `g` across an `await`): `write` gets
71
+ * the sink of this step. Not JSON; a `FormHost.context` sends it.
72
+ */
73
+ | {
74
+ type: 'script';
75
+ write: (sink: ScriptSink) => void;
76
+ } | {
77
+ type: 'reset';
78
+ };
79
+ /** What a host may take over from the session. */
80
+ export interface FormHost {
81
+ /**
82
+ * Builds the `g` handed to script handlers, over the sink of the step that runs them. By
83
+ * default a new one per step, which is dead once the step returns. A host whose handlers keep
84
+ * `g` for later returns one of its own here and forwards a late call as a `script` message.
85
+ */
86
+ context?: (form: FormDefinition, sink: ScriptSink) => ScriptContext;
87
+ }
88
+ export interface FormEventMap {
89
+ 'baht-change': {
90
+ form_name: string;
91
+ key: string;
92
+ value: unknown;
93
+ data: Record<string, unknown>;
94
+ };
95
+ 'baht-validity': {
96
+ valid: boolean;
97
+ errors: ValidationError[];
98
+ };
99
+ }
100
+ export type FormEvent = {
101
+ [K in keyof FormEventMap]: {
102
+ name: K;
103
+ detail: FormEventMap[K];
104
+ };
105
+ }[keyof FormEventMap];
106
+ export interface FormUpdate {
107
+ state: FormState;
108
+ /** In the order to dispatch them. */
109
+ events: FormEvent[];
110
+ }
111
+ /** The form's data: every data field, the whole form whatever the view (spec 01 §6). */
112
+ export declare function formData(input: FormInput, state: FormState): Record<string, unknown>;
113
+ /** One field as it stands: the rules' state, the scripts' overrides over it, `hidden` over both. */
114
+ export declare function formFieldState(input: FormInput, state: FormState, field: FieldDescriptor): DerivedFieldState;
115
+ /**
116
+ * The errors of one field as it is shown: none while it is hidden (spec 02 §5), and `required`
117
+ * is the derived one, not the descriptor's. The browser and the server both validate through here.
118
+ */
119
+ export declare function validateShownField(field: FieldDescriptor, shown: Pick<DerivedFieldState, 'visible' | 'required'> | undefined, value: unknown, registry?: Registry, data?: Record<string, unknown>, rowStates?: Record<string, DerivedFieldState>): ValidationError[];
120
+ /**
121
+ * Run the form's `submit` scripts over `sink` and return what blocks, as errors on `$`: every
122
+ * `addErrorMessage()`, or the catalog's `scriptBlocked` when a handler returned `false` in silence.
123
+ */
124
+ export declare function submitScriptErrors(form: FormDefinition, registry: Registry | undefined, sink: ScriptSink): ValidationError[];
125
+ /**
126
+ * One step of a form session. Same input, state and message: same result, as far as the host's
127
+ * script handlers are themselves repeatable.
128
+ */
129
+ export declare function updateForm(input: FormInput, state: FormState, msg: FormMsg, host?: FormHost): FormUpdate;