@bluprynt/forms-core 3.0.0 → 4.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.
- package/README.md +12 -1
- package/dist/form-definition.schema.json +388 -2
- package/dist/index.cjs +1677 -51
- package/dist/index.d.cts +652 -47
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +652 -47
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1673 -52
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -31,6 +31,34 @@ type CompoundCondition = {
|
|
|
31
31
|
*/
|
|
32
32
|
type Condition = SimpleCondition | CompoundCondition;
|
|
33
33
|
//#endregion
|
|
34
|
+
//#region src/types/field-types.d.ts
|
|
35
|
+
/**
|
|
36
|
+
* Union of all supported form field types.
|
|
37
|
+
*
|
|
38
|
+
* - `string` -- free-text input
|
|
39
|
+
* - `number` -- numeric input
|
|
40
|
+
* - `boolean` -- true/false toggle
|
|
41
|
+
* - `date` -- date picker (ISO-8601 string value)
|
|
42
|
+
* - `select` -- single selection from a predefined list
|
|
43
|
+
* - `multiselect` -- any number of selections from a predefined list; the
|
|
44
|
+
* value is an array of the chosen options' `value`s
|
|
45
|
+
* - `array` -- ordered list of values whose item type is any non-array field type
|
|
46
|
+
* - `array_obj` -- ordered list of rows; each row is an object holding one value
|
|
47
|
+
* per sub-field defined in the field's `items` list
|
|
48
|
+
* - `file` -- file upload (stores name, MIME type, size, URL)
|
|
49
|
+
* - `static` -- display-only text; holds no value and is never validated
|
|
50
|
+
* - `blockchain` -- a CAIP address identifying an on-chain asset. The value is
|
|
51
|
+
* an opaque string: the engine never checks its format
|
|
52
|
+
* - `sustainability` -- sustainability data for an on-chain asset; the value is
|
|
53
|
+
* a {@link SustainabilityValue} object (`address`, `ccri`, `cmc`)
|
|
54
|
+
*/
|
|
55
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'select' | 'multiselect' | 'array' | 'array_obj' | 'file' | 'static' | 'blockchain' | 'sustainability';
|
|
56
|
+
/**
|
|
57
|
+
* Discriminator for every content node in a form definition.
|
|
58
|
+
* Includes all {@link FieldType} values plus `'section'` for grouping containers.
|
|
59
|
+
*/
|
|
60
|
+
type ContentItemType = FieldType | 'section';
|
|
61
|
+
//#endregion
|
|
34
62
|
//#region src/condition-evaluator.d.ts
|
|
35
63
|
/**
|
|
36
64
|
* Context passed to condition evaluation methods.
|
|
@@ -41,11 +69,15 @@ type Condition = SimpleCondition | CompoundCondition;
|
|
|
41
69
|
* actual value.
|
|
42
70
|
* @property now - Reference date for resolving relative date expressions in
|
|
43
71
|
* condition values.
|
|
72
|
+
* @property fieldTypes - Type of each item by id. Optional: when omitted every
|
|
73
|
+
* field is compared with the default scalar semantics. Supplying it enables
|
|
74
|
+
* the set-oriented semantics used for `multiselect` fields.
|
|
44
75
|
*/
|
|
45
76
|
type EvaluationContext = {
|
|
46
77
|
values: Record<string, unknown>;
|
|
47
78
|
visibilityMap?: Map<number, boolean>;
|
|
48
79
|
now: Date;
|
|
80
|
+
fieldTypes?: Map<number, ContentItemType>;
|
|
49
81
|
};
|
|
50
82
|
/**
|
|
51
83
|
* Evaluates condition trees against form state.
|
|
@@ -64,6 +96,18 @@ type EvaluationContext = {
|
|
|
64
96
|
*
|
|
65
97
|
* **Date handling**: condition values that are relative date expressions
|
|
66
98
|
* (e.g. `"+7d"`) are resolved against `ctx.now` before comparison.
|
|
99
|
+
*
|
|
100
|
+
* **Multiselect handling**: when `ctx.fieldTypes` reports the referenced field
|
|
101
|
+
* as `multiselect`, its array value is compared as a set instead of a scalar:
|
|
102
|
+
* `set` means "at least one option chosen", `eq`/`ne` compare set membership
|
|
103
|
+
* ignoring order and duplicates, `in`/`notin` test whether *any* chosen option
|
|
104
|
+
* appears in the condition's list, and the ordering operators are always
|
|
105
|
+
* `false`. Fields of every other type -- including `array` -- keep the original
|
|
106
|
+
* scalar semantics.
|
|
107
|
+
*
|
|
108
|
+
* **Object-valued fields** (`file`, `sustainability`) go through the scalar path
|
|
109
|
+
* too, so only `set`/`notset` are meaningful: any object present counts as
|
|
110
|
+
* `set`, and `eq`/`ne`/`in`/`notin` compare by reference and so never match.
|
|
67
111
|
*/
|
|
68
112
|
declare class ConditionEvaluator {
|
|
69
113
|
/**
|
|
@@ -76,29 +120,17 @@ declare class ConditionEvaluator {
|
|
|
76
120
|
*/
|
|
77
121
|
evalCondition(condition: Condition, ctx: EvaluationContext): boolean;
|
|
78
122
|
private evalSimple;
|
|
123
|
+
private evalMultiselect;
|
|
124
|
+
/**
|
|
125
|
+
* Compares the chosen options against a condition value as sets, ignoring
|
|
126
|
+
* order and duplicates. A scalar condition value is read as a one-element
|
|
127
|
+
* set, so `{ op: 'eq', value: 'a' }` means "`a` is the only option chosen".
|
|
128
|
+
*/
|
|
129
|
+
private sameSet;
|
|
79
130
|
private resolveIfDate;
|
|
80
131
|
private compareTo;
|
|
81
132
|
}
|
|
82
133
|
//#endregion
|
|
83
|
-
//#region src/types/field-types.d.ts
|
|
84
|
-
/**
|
|
85
|
-
* Union of all supported form field types.
|
|
86
|
-
*
|
|
87
|
-
* - `string` -- free-text input
|
|
88
|
-
* - `number` -- numeric input
|
|
89
|
-
* - `boolean` -- true/false toggle
|
|
90
|
-
* - `date` -- date picker (ISO-8601 string value)
|
|
91
|
-
* - `select` -- single selection from a predefined list
|
|
92
|
-
* - `array` -- ordered list of values whose item type is any non-array field type
|
|
93
|
-
* - `file` -- file upload (stores name, MIME type, size, URL)
|
|
94
|
-
*/
|
|
95
|
-
type FieldType = 'string' | 'number' | 'boolean' | 'date' | 'select' | 'array' | 'file';
|
|
96
|
-
/**
|
|
97
|
-
* Discriminator for every content node in a form definition.
|
|
98
|
-
* Includes all {@link FieldType} values plus `'section'` for grouping containers.
|
|
99
|
-
*/
|
|
100
|
-
type ContentItemType = FieldType | 'section';
|
|
101
|
-
//#endregion
|
|
102
134
|
//#region src/types/select-option.d.ts
|
|
103
135
|
/**
|
|
104
136
|
* A single option within a `select` field's predefined list.
|
|
@@ -113,26 +145,140 @@ type SelectOption = {
|
|
|
113
145
|
//#endregion
|
|
114
146
|
//#region src/types/array-item-def.d.ts
|
|
115
147
|
/**
|
|
116
|
-
* Schema for
|
|
148
|
+
* Schema for a value-producing item inside an `array` field.
|
|
117
149
|
*
|
|
118
|
-
*
|
|
150
|
+
* Neither list type may nest, so `type` excludes `'array'` and `'array_obj'`.
|
|
119
151
|
* Items do not have their own id or condition -- they inherit the parent
|
|
120
152
|
* array field's identity and visibility.
|
|
121
153
|
*
|
|
122
|
-
* @property type - The
|
|
154
|
+
* @property type - The field type for each item in the array.
|
|
123
155
|
* @property label - Display label for the item.
|
|
124
156
|
* @property description - Optional description shown to the user.
|
|
157
|
+
* @property placeholder - Optional placeholder text for the item's input control.
|
|
158
|
+
* @property answer_guidelines - Optional guidance describing how the item should be answered.
|
|
159
|
+
* @property reference_id - Optional external reference (e.g. a regulation or questionnaire item id).
|
|
125
160
|
* @property validation - Validation rules applied to each individual item.
|
|
126
|
-
* @property options - Required when {@link type} is `'select'
|
|
127
|
-
* allowed values.
|
|
161
|
+
* @property options - Required when {@link type} is `'select'` or `'multiselect'`;
|
|
162
|
+
* the list of allowed values.
|
|
128
163
|
*/
|
|
129
|
-
type
|
|
130
|
-
type: Exclude<FieldType, 'array'>;
|
|
164
|
+
type ValueArrayItemDef = {
|
|
165
|
+
type: Exclude<FieldType, 'array' | 'array_obj' | 'static'>;
|
|
131
166
|
label: string;
|
|
132
167
|
description?: string;
|
|
168
|
+
placeholder?: string;
|
|
169
|
+
answer_guidelines?: string;
|
|
170
|
+
reference_id?: string;
|
|
133
171
|
validation?: Record<string, unknown>;
|
|
134
172
|
options?: SelectOption[];
|
|
135
173
|
};
|
|
174
|
+
/**
|
|
175
|
+
* Schema for a display-only item inside an `array` field.
|
|
176
|
+
*
|
|
177
|
+
* A static item holds no value and is never validated, so an array using one
|
|
178
|
+
* renders as many blocks as the stored array is long and contributes nothing
|
|
179
|
+
* to the document's values. Accepted for symmetry with `array_obj`, where a
|
|
180
|
+
* static sub-field is genuinely useful as a per-row caption.
|
|
181
|
+
*
|
|
182
|
+
* @property type - Always `'static'`.
|
|
183
|
+
* @property text - The text to display.
|
|
184
|
+
* @property label - Optional heading shown above {@link text}.
|
|
185
|
+
*/
|
|
186
|
+
type StaticArrayItemDef = {
|
|
187
|
+
type: 'static';
|
|
188
|
+
text: string;
|
|
189
|
+
label?: string;
|
|
190
|
+
description?: string;
|
|
191
|
+
placeholder?: string;
|
|
192
|
+
answer_guidelines?: string;
|
|
193
|
+
reference_id?: string;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Schema for individual items inside an `array` field.
|
|
197
|
+
*
|
|
198
|
+
* Narrow with `item.type === 'static'` to reach {@link StaticArrayItemDef}'s
|
|
199
|
+
* `text`, or with `item.type !== 'static'` to reach the value-item properties
|
|
200
|
+
* (`label`, `validation`, `options`).
|
|
201
|
+
*/
|
|
202
|
+
type ArrayItemDef = ValueArrayItemDef | StaticArrayItemDef;
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/types/array-obj-item-def.d.ts
|
|
205
|
+
/**
|
|
206
|
+
* Schema for a value-producing sub-field inside an `array_obj` field.
|
|
207
|
+
*
|
|
208
|
+
* Unlike an `array` item, a sub-field carries its own `id`: it is drawn from
|
|
209
|
+
* the same globally unique id space as top-level fields and is the key under
|
|
210
|
+
* which the sub-field's value is stored inside each row object.
|
|
211
|
+
*
|
|
212
|
+
* Neither list type may nest, so `type` excludes `'array'` and `'array_obj'`.
|
|
213
|
+
* Sub-fields have no `condition` -- they inherit the parent field's visibility.
|
|
214
|
+
*
|
|
215
|
+
* @property id - Unique numeric identifier, also the row-object key.
|
|
216
|
+
* @property type - The field type for this sub-field.
|
|
217
|
+
* @property label - Display label for the sub-field.
|
|
218
|
+
* @property description - Optional description shown to the user.
|
|
219
|
+
* @property placeholder - Optional placeholder text for the sub-field's input control.
|
|
220
|
+
* @property answer_guidelines - Optional guidance describing how the sub-field should be answered.
|
|
221
|
+
* @property reference_id - Optional external reference (e.g. a regulation or questionnaire item id).
|
|
222
|
+
* @property validation - Validation rules applied to this sub-field in every row.
|
|
223
|
+
* @property options - Required when {@link type} is `'select'` or `'multiselect'`;
|
|
224
|
+
* the list of allowed values.
|
|
225
|
+
*/
|
|
226
|
+
type ValueArrayObjItemDef = {
|
|
227
|
+
id: number;
|
|
228
|
+
type: Exclude<FieldType, 'array' | 'array_obj' | 'static'>;
|
|
229
|
+
label: string;
|
|
230
|
+
description?: string;
|
|
231
|
+
placeholder?: string;
|
|
232
|
+
answer_guidelines?: string;
|
|
233
|
+
reference_id?: string;
|
|
234
|
+
validation?: Record<string, unknown>;
|
|
235
|
+
options?: SelectOption[];
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Schema for a display-only sub-field inside an `array_obj` field.
|
|
239
|
+
*
|
|
240
|
+
* Holds no value and is never validated, but still occupies a position in
|
|
241
|
+
* every row -- useful as a per-row caption or separator.
|
|
242
|
+
*
|
|
243
|
+
* @property id - Unique numeric identifier. No value is ever stored under it.
|
|
244
|
+
* @property type - Always `'static'`.
|
|
245
|
+
* @property text - The text to display.
|
|
246
|
+
* @property label - Optional heading shown above {@link text}.
|
|
247
|
+
*/
|
|
248
|
+
type StaticArrayObjItemDef = {
|
|
249
|
+
id: number;
|
|
250
|
+
type: 'static';
|
|
251
|
+
text: string;
|
|
252
|
+
label?: string;
|
|
253
|
+
description?: string;
|
|
254
|
+
placeholder?: string;
|
|
255
|
+
answer_guidelines?: string;
|
|
256
|
+
reference_id?: string;
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Schema for a single sub-field inside an `array_obj` field.
|
|
260
|
+
*
|
|
261
|
+
* Narrow with `item.type === 'static'` to reach {@link StaticArrayObjItemDef}'s
|
|
262
|
+
* `text`, or with `item.type !== 'static'` to reach the value-field properties
|
|
263
|
+
* (`label`, `validation`, `options`).
|
|
264
|
+
*/
|
|
265
|
+
type ArrayObjItemDef = ValueArrayObjItemDef | StaticArrayObjItemDef;
|
|
266
|
+
/**
|
|
267
|
+
* How an `array_obj` field asks to be laid out.
|
|
268
|
+
*
|
|
269
|
+
* Purely presentation metadata: the engine never reads it, and it affects
|
|
270
|
+
* neither values, validation nor visibility. `'list'` when absent, so
|
|
271
|
+
* definitions written before it existed keep their original rendering.
|
|
272
|
+
*
|
|
273
|
+
* - `list` -- each row is a stacked block of labelled controls.
|
|
274
|
+
* - `table` -- rows share one header, one column per sub-field.
|
|
275
|
+
*/
|
|
276
|
+
type ArrayObjKind = 'list' | 'table';
|
|
277
|
+
/**
|
|
278
|
+
* A single row of an `array_obj` field's value: a map from stringified
|
|
279
|
+
* sub-field id to that sub-field's value.
|
|
280
|
+
*/
|
|
281
|
+
type ArrayObjRow = Record<string, unknown>;
|
|
136
282
|
//#endregion
|
|
137
283
|
//#region src/types/validation/array.d.ts
|
|
138
284
|
/**
|
|
@@ -146,6 +292,34 @@ type ArrayValidation = {
|
|
|
146
292
|
maxItems?: number;
|
|
147
293
|
};
|
|
148
294
|
//#endregion
|
|
295
|
+
//#region src/types/validation/array-obj.d.ts
|
|
296
|
+
/**
|
|
297
|
+
* Validation rules for `array_obj` fields.
|
|
298
|
+
*
|
|
299
|
+
* Covers the row list itself. Per-sub-field rules live inside each entry of
|
|
300
|
+
* the field's `items` list.
|
|
301
|
+
*
|
|
302
|
+
* @property minItems - Minimum number of rows the field must contain (inclusive).
|
|
303
|
+
* @property maxItems - Maximum number of rows the field may contain (inclusive).
|
|
304
|
+
*/
|
|
305
|
+
type ArrayObjValidation = {
|
|
306
|
+
minItems?: number;
|
|
307
|
+
maxItems?: number;
|
|
308
|
+
};
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/types/validation/blockchain.d.ts
|
|
311
|
+
/**
|
|
312
|
+
* Validation rules for `blockchain` fields.
|
|
313
|
+
*
|
|
314
|
+
* The value is an opaque CAIP address string -- there is deliberately no format
|
|
315
|
+
* rule, so a malformed address is the consumer's concern, not the engine's.
|
|
316
|
+
*
|
|
317
|
+
* @property required - Whether an address must be provided.
|
|
318
|
+
*/
|
|
319
|
+
type BlockchainValidation = {
|
|
320
|
+
required?: boolean;
|
|
321
|
+
};
|
|
322
|
+
//#endregion
|
|
149
323
|
//#region src/types/validation/boolean.d.ts
|
|
150
324
|
/**
|
|
151
325
|
* Validation rules for `boolean` fields.
|
|
@@ -184,6 +358,17 @@ type FileValidation = {
|
|
|
184
358
|
required?: boolean;
|
|
185
359
|
};
|
|
186
360
|
//#endregion
|
|
361
|
+
//#region src/types/validation/multiselect.d.ts
|
|
362
|
+
/**
|
|
363
|
+
* Validation rules for `multiselect` fields.
|
|
364
|
+
*
|
|
365
|
+
* @property required - When `true`, at least one option must be selected.
|
|
366
|
+
* An absent value and an empty array both fail this rule.
|
|
367
|
+
*/
|
|
368
|
+
type MultiselectValidation = {
|
|
369
|
+
required?: boolean;
|
|
370
|
+
};
|
|
371
|
+
//#endregion
|
|
187
372
|
//#region src/types/validation/number.d.ts
|
|
188
373
|
/**
|
|
189
374
|
* Validation rules for `number` fields.
|
|
@@ -226,12 +411,23 @@ type StringValidation = {
|
|
|
226
411
|
patternMessage?: string;
|
|
227
412
|
};
|
|
228
413
|
//#endregion
|
|
414
|
+
//#region src/types/validation/sustainability.d.ts
|
|
415
|
+
/**
|
|
416
|
+
* Validation rules for `sustainability` fields.
|
|
417
|
+
*
|
|
418
|
+
* @property required - Whether the value's `address` must be a non-empty
|
|
419
|
+
* string. `ccri` and `cmc` are always optional.
|
|
420
|
+
*/
|
|
421
|
+
type SustainabilityValidation = {
|
|
422
|
+
required?: boolean;
|
|
423
|
+
};
|
|
424
|
+
//#endregion
|
|
229
425
|
//#region src/types/validation/type-specific.d.ts
|
|
230
426
|
/**
|
|
231
427
|
* Union of all type-specific validation rule shapes.
|
|
232
428
|
* The applicable shape depends on the field's {@link FieldType}.
|
|
233
429
|
*/
|
|
234
|
-
type TypeSpecificValidation = StringValidation | NumberValidation | BooleanValidation | DateValidation | SelectValidation | ArrayValidation | FileValidation;
|
|
430
|
+
type TypeSpecificValidation = StringValidation | NumberValidation | BooleanValidation | DateValidation | SelectValidation | MultiselectValidation | ArrayValidation | ArrayObjValidation | FileValidation | BlockchainValidation | SustainabilityValidation;
|
|
235
431
|
//#endregion
|
|
236
432
|
//#region src/types/field-entry.d.ts
|
|
237
433
|
/**
|
|
@@ -248,6 +444,7 @@ type TypeSpecificValidation = StringValidation | NumberValidation | BooleanValid
|
|
|
248
444
|
* @property parentId - Id of the containing section, or `undefined` for top-level items.
|
|
249
445
|
* @property options - Select options (only for `select` fields).
|
|
250
446
|
* @property item - Array item definition (only for `array` fields).
|
|
447
|
+
* @property items - Sub-field definitions (only for `array_obj` fields).
|
|
251
448
|
* @property label - Display label (only for fields, `undefined` for sections).
|
|
252
449
|
* @property title - Display title (only for sections, `undefined` for fields).
|
|
253
450
|
*/
|
|
@@ -259,6 +456,7 @@ type FieldEntry = {
|
|
|
259
456
|
parentId: number | undefined;
|
|
260
457
|
options: SelectOption[] | undefined;
|
|
261
458
|
item: ArrayItemDef | undefined;
|
|
459
|
+
items: ArrayObjItemDef[] | undefined;
|
|
262
460
|
label: string | undefined;
|
|
263
461
|
title: string | undefined;
|
|
264
462
|
};
|
|
@@ -345,6 +543,32 @@ declare class DependencyGraph {
|
|
|
345
543
|
private expandTransitiveDependencies;
|
|
346
544
|
}
|
|
347
545
|
//#endregion
|
|
546
|
+
//#region src/types/suggestion.d.ts
|
|
547
|
+
/**
|
|
548
|
+
* A machine-proposed answer for a single field.
|
|
549
|
+
*
|
|
550
|
+
* Suggestions live alongside user-entered values in a {@link FormDocument} and
|
|
551
|
+
* never participate in validation or visibility. A suggestion is only ever
|
|
552
|
+
* copied into `values` when it is explicitly accepted.
|
|
553
|
+
*
|
|
554
|
+
* @property value - The proposed value, shaped like the field's own value.
|
|
555
|
+
* @property confidence - How confident the producer is, as a `0..1` fraction
|
|
556
|
+
* (`0.3` means 30%). Range-checked on write, not on read.
|
|
557
|
+
* @property source - Human-readable explanation of why the value was proposed.
|
|
558
|
+
*/
|
|
559
|
+
type FieldSuggestion = {
|
|
560
|
+
value: unknown;
|
|
561
|
+
confidence: number;
|
|
562
|
+
source: string;
|
|
563
|
+
};
|
|
564
|
+
/**
|
|
565
|
+
* A sparse map of suggestions keyed by stringified field id (e.g. `"1"`, `"42"`),
|
|
566
|
+
* using the same key space as {@link FormValues}.
|
|
567
|
+
*
|
|
568
|
+
* Most fields have no suggestion, so keys are expected to be missing.
|
|
569
|
+
*/
|
|
570
|
+
type FormSuggestions = Record<string, FieldSuggestion>;
|
|
571
|
+
//#endregion
|
|
348
572
|
//#region src/types/form-values.d.ts
|
|
349
573
|
/**
|
|
350
574
|
* A flat key-value map of user-submitted form data.
|
|
@@ -364,6 +588,9 @@ type FormValues = Record<string, unknown>;
|
|
|
364
588
|
* @property form.id - The form schema's unique identifier (from {@link FormDefinition.id}).
|
|
365
589
|
* @property form.version - The form schema's version (from {@link FormDefinition.version}).
|
|
366
590
|
* @property values - Flat key-value map of user-submitted data.
|
|
591
|
+
* @property suggestions - Optional sparse map of machine-proposed answers, keyed
|
|
592
|
+
* like {@link values}. Omitted entirely on documents that have none, so
|
|
593
|
+
* documents produced before suggestions existed remain valid unchanged.
|
|
367
594
|
*/
|
|
368
595
|
type FormDocument = {
|
|
369
596
|
form: {
|
|
@@ -372,6 +599,7 @@ type FormDocument = {
|
|
|
372
599
|
submittedAt: string;
|
|
373
600
|
};
|
|
374
601
|
values: FormValues;
|
|
602
|
+
suggestions?: FormSuggestions;
|
|
375
603
|
};
|
|
376
604
|
//#endregion
|
|
377
605
|
//#region src/types/validation-results.d.ts
|
|
@@ -391,8 +619,11 @@ type FormDocument = {
|
|
|
391
619
|
* | `MAX_DATE` | `date` |
|
|
392
620
|
* | `INVALID_DATE` | `date` (unparseable value) |
|
|
393
621
|
* | `INVALID_OPTION` | `select` (value not in options list) |
|
|
394
|
-
* | `MIN_ITEMS` | `array` |
|
|
395
|
-
* | `MAX_ITEMS` | `array` |
|
|
622
|
+
* | `MIN_ITEMS` | `array`, `array_obj` |
|
|
623
|
+
* | `MAX_ITEMS` | `array`, `array_obj` |
|
|
624
|
+
*
|
|
625
|
+
* On a `sustainability` field `REQUIRED` means the value's `address` is missing
|
|
626
|
+
* or empty -- `ccri` and `cmc` never trigger it.
|
|
396
627
|
*/
|
|
397
628
|
type FieldValidationRule = 'REQUIRED' | 'TYPE' | 'MIN_LENGTH' | 'MAX_LENGTH' | 'PATTERN' | 'MIN' | 'MAX' | 'MIN_DATE' | 'MAX_DATE' | 'INVALID_DATE' | 'INVALID_OPTION' | 'MIN_ITEMS' | 'MAX_ITEMS';
|
|
398
629
|
/**
|
|
@@ -402,8 +633,13 @@ type FieldValidationRule = 'REQUIRED' | 'TYPE' | 'MIN_LENGTH' | 'MAX_LENGTH' | '
|
|
|
402
633
|
* @property rule - Machine-readable rule code from {@link FieldValidationRule}.
|
|
403
634
|
* @property message - Human-readable error description.
|
|
404
635
|
* @property params - Optional parameters providing context (e.g. `{ minLength: 5, actual: 3 }`).
|
|
405
|
-
* @property itemIndex - For array fields, the zero-based index
|
|
406
|
-
* that failed validation. `undefined` for
|
|
636
|
+
* @property itemIndex - For `array` and `array_obj` fields, the zero-based index
|
|
637
|
+
* of the item or row that failed validation. `undefined` for other fields.
|
|
638
|
+
* @property itemFieldId - For `array_obj` fields, the id of the sub-field within
|
|
639
|
+
* the row identified by {@link itemIndex}. `undefined` everywhere else,
|
|
640
|
+
* including on a row-level `TYPE` error. Note that `fieldId` stays the
|
|
641
|
+
* `array_obj` container's id, so it always matches the key this error is
|
|
642
|
+
* stored under in {@link FormValidationResult.fieldErrors}.
|
|
407
643
|
*/
|
|
408
644
|
type FieldValidationError = {
|
|
409
645
|
fieldId: number;
|
|
@@ -411,6 +647,7 @@ type FieldValidationError = {
|
|
|
411
647
|
message: string;
|
|
412
648
|
params?: Record<string, unknown>;
|
|
413
649
|
itemIndex?: number;
|
|
650
|
+
itemFieldId?: number;
|
|
414
651
|
};
|
|
415
652
|
/**
|
|
416
653
|
* Machine-readable codes for all document-level validation errors.
|
|
@@ -422,6 +659,8 @@ type FieldValidationError = {
|
|
|
422
659
|
* | `NESTING_DEPTH` | A section is nested deeper than the allowed 3 levels. |
|
|
423
660
|
* | `UNKNOWN_FIELD_REF` | A condition references a field id that does not exist in the form. |
|
|
424
661
|
* | `CONDITION_REFS_SECTION` | A condition references a section id; sections have no value to compare. |
|
|
662
|
+
* | `CONDITION_REFS_STATIC` | A condition references a static field id; static blocks have no value to compare. |
|
|
663
|
+
* | `CONDITION_REFS_ARRAY_OBJ_ITEM` | A condition references an `array_obj` sub-field id; its value is per-row and not addressable. |
|
|
425
664
|
* | `INVALID_MIN_MAX` | A field's minimum constraint exceeds its maximum constraint. |
|
|
426
665
|
* | `INVALID_REGEX` | String field `pattern` is not a valid regular expression. |
|
|
427
666
|
* | `CIRCULAR_DEPENDENCY` | Condition dependencies form a cycle (A depends on B depends on A). |
|
|
@@ -430,7 +669,7 @@ type FieldValidationError = {
|
|
|
430
669
|
* | `FORM_SUBMITTED_AT_MISSING` | The document's submittedAt field is missing. |
|
|
431
670
|
* | `FORM_SUBMITTED_AT_INVALID` | The document's submittedAt field is not a valid date. |
|
|
432
671
|
*/
|
|
433
|
-
type DocumentValidationErrorCode = 'SCHEMA_INVALID' | 'DUPLICATE_ID' | 'NESTING_DEPTH' | 'UNKNOWN_FIELD_REF' | 'CONDITION_REFS_SECTION' | 'INVALID_MIN_MAX' | 'INVALID_REGEX' | 'CIRCULAR_DEPENDENCY' | 'FORM_ID_MISMATCH' | 'FORM_VERSION_MISMATCH' | 'FORM_SUBMITTED_AT_MISSING' | 'FORM_SUBMITTED_AT_INVALID';
|
|
672
|
+
type DocumentValidationErrorCode = 'SCHEMA_INVALID' | 'DUPLICATE_ID' | 'NESTING_DEPTH' | 'UNKNOWN_FIELD_REF' | 'CONDITION_REFS_SECTION' | 'CONDITION_REFS_STATIC' | 'CONDITION_REFS_ARRAY_OBJ_ITEM' | 'INVALID_MIN_MAX' | 'INVALID_REGEX' | 'CIRCULAR_DEPENDENCY' | 'FORM_ID_MISMATCH' | 'FORM_VERSION_MISMATCH' | 'FORM_SUBMITTED_AT_MISSING' | 'FORM_SUBMITTED_AT_INVALID';
|
|
434
673
|
/**
|
|
435
674
|
* A single validation error found during form definition or document validation.
|
|
436
675
|
*
|
|
@@ -475,9 +714,19 @@ type FormValidationResult = {
|
|
|
475
714
|
* - `date` -- `required`, `minDate`, `maxDate`. Relative date boundaries
|
|
476
715
|
* are resolved against `now`.
|
|
477
716
|
* - `select` -- `required`, plus the value must be one of the defined options.
|
|
717
|
+
* - `multiselect` -- `required` (an absent value and an empty array both fail),
|
|
718
|
+
* plus every selected value must be one of the defined options.
|
|
719
|
+
* - `static` -- never validated; static blocks hold no value.
|
|
720
|
+
* - `blockchain` -- `required` only. The CAIP address format is never checked.
|
|
721
|
+
* - `sustainability` -- `required` (the value's `address` must be a non-empty
|
|
722
|
+
* string) plus a shape check; `ccri` and `cmc` are optional text.
|
|
478
723
|
* - `array` -- `minItems`, `maxItems`, plus each item is validated
|
|
479
724
|
* individually according to the array's {@link ArrayItemDef}. Item-level
|
|
480
725
|
* errors carry an `itemIndex`.
|
|
726
|
+
* - `array_obj` -- `minItems`, `maxItems`, plus every sub-field of every row is
|
|
727
|
+
* validated according to the field's {@link ArrayObjItemDef} list. Sub-field
|
|
728
|
+
* errors carry an `itemIndex` (the row) and an `itemFieldId` (the sub-field),
|
|
729
|
+
* while `fieldId` stays the container's id.
|
|
481
730
|
*
|
|
482
731
|
* For all types, if `required` fails, no further rules are checked for that
|
|
483
732
|
* field (early return). If the value is empty/absent and `required` is not
|
|
@@ -525,30 +774,83 @@ type FormDefinition = {
|
|
|
525
774
|
content: ContentItem[];
|
|
526
775
|
};
|
|
527
776
|
/**
|
|
528
|
-
* A single node in the form definition tree --
|
|
777
|
+
* A single node in the form definition tree -- a value field, a static block
|
|
778
|
+
* or a section.
|
|
779
|
+
*/
|
|
780
|
+
type ContentItem = AnyFieldContentItem | SectionContentItem;
|
|
781
|
+
/**
|
|
782
|
+
* Any non-section node: either a value-producing field or a static block.
|
|
783
|
+
*
|
|
784
|
+
* Narrow with `item.type === 'static'` to reach {@link StaticFieldContentItem}'s
|
|
785
|
+
* `text`, or with `item.type !== 'static'` to reach the value-field properties
|
|
786
|
+
* (`label`, `validation`, `options`, `item`, `items`).
|
|
529
787
|
*/
|
|
530
|
-
type
|
|
788
|
+
type AnyFieldContentItem = FieldContentItem | StaticFieldContentItem;
|
|
531
789
|
/**
|
|
532
|
-
* A field node within the form definition tree.
|
|
790
|
+
* A value-producing field node within the form definition tree.
|
|
791
|
+
*
|
|
792
|
+
* Excludes `static`, which holds no value and has its own shape --
|
|
793
|
+
* see {@link StaticFieldContentItem}.
|
|
533
794
|
*
|
|
534
795
|
* @property id - Unique numeric identifier.
|
|
535
796
|
* @property type - The field's data type.
|
|
536
797
|
* @property label - Display label shown to the user.
|
|
537
798
|
* @property description - Optional help text.
|
|
799
|
+
* @property placeholder - Optional placeholder text for the field's input control.
|
|
800
|
+
* @property answer_guidelines - Optional guidance describing how the field should be answered.
|
|
801
|
+
* @property reference_id - Optional external reference (e.g. a regulation or questionnaire item id).
|
|
538
802
|
* @property condition - Visibility condition that controls whether this field is shown.
|
|
539
803
|
* @property validation - Type-specific validation rules.
|
|
540
|
-
* @property options - Allowed values (required for `select` fields).
|
|
804
|
+
* @property options - Allowed values (required for `select` and `multiselect` fields).
|
|
541
805
|
* @property item - Item schema (required for `array` fields).
|
|
806
|
+
* @property items - Sub-field schemas (required for `array_obj` fields).
|
|
807
|
+
* @property kind - Layout hint for `array_obj` fields (`'list'` when absent).
|
|
808
|
+
* Presentation metadata only -- the engine never reads it.
|
|
542
809
|
*/
|
|
543
810
|
type FieldContentItem = {
|
|
544
811
|
id: number;
|
|
545
|
-
type: FieldType
|
|
812
|
+
type: Exclude<FieldType, 'static'>;
|
|
546
813
|
label: string;
|
|
547
814
|
description?: string;
|
|
815
|
+
placeholder?: string;
|
|
816
|
+
answer_guidelines?: string;
|
|
817
|
+
reference_id?: string;
|
|
548
818
|
condition?: Condition;
|
|
549
819
|
validation?: TypeSpecificValidation;
|
|
550
820
|
options?: SelectOption[];
|
|
551
821
|
item?: ArrayItemDef;
|
|
822
|
+
items?: ArrayObjItemDef[];
|
|
823
|
+
kind?: ArrayObjKind;
|
|
824
|
+
};
|
|
825
|
+
/**
|
|
826
|
+
* A display-only text block within the form definition tree.
|
|
827
|
+
*
|
|
828
|
+
* Static blocks render alongside fields and honour their own `condition`, but
|
|
829
|
+
* they hold no value: they never appear in form values, never carry
|
|
830
|
+
* validation rules, never produce validation errors, and cannot be referenced
|
|
831
|
+
* by another item's condition.
|
|
832
|
+
*
|
|
833
|
+
* @property id - Unique numeric identifier.
|
|
834
|
+
* @property type - Always `'static'`.
|
|
835
|
+
* @property text - The text to display. This is the block's content, and the
|
|
836
|
+
* only required property beyond `id` and `type`.
|
|
837
|
+
* @property label - Optional heading shown above {@link text}.
|
|
838
|
+
* @property description - Optional secondary text.
|
|
839
|
+
* @property placeholder - Optional presentation metadata. Opaque to the engine.
|
|
840
|
+
* @property answer_guidelines - Optional presentation metadata. Opaque to the engine.
|
|
841
|
+
* @property reference_id - Optional external reference (e.g. a regulation or questionnaire item id).
|
|
842
|
+
* @property condition - Visibility condition that controls whether this block is shown.
|
|
843
|
+
*/
|
|
844
|
+
type StaticFieldContentItem = {
|
|
845
|
+
id: number;
|
|
846
|
+
type: 'static';
|
|
847
|
+
text: string;
|
|
848
|
+
label?: string;
|
|
849
|
+
description?: string;
|
|
850
|
+
placeholder?: string;
|
|
851
|
+
answer_guidelines?: string;
|
|
852
|
+
reference_id?: string;
|
|
853
|
+
condition?: Condition;
|
|
552
854
|
};
|
|
553
855
|
/**
|
|
554
856
|
* A section node that groups fields and/or child sections.
|
|
@@ -559,6 +861,9 @@ type FieldContentItem = {
|
|
|
559
861
|
* @property type - Always `'section'`.
|
|
560
862
|
* @property title - Display title for the section.
|
|
561
863
|
* @property description - Optional description.
|
|
864
|
+
* @property placeholder - Optional placeholder text.
|
|
865
|
+
* @property answer_guidelines - Optional guidance describing how the section should be completed.
|
|
866
|
+
* @property reference_id - Optional external reference (e.g. a regulation or questionnaire item id).
|
|
562
867
|
* @property condition - Visibility condition. When hidden, all descendant
|
|
563
868
|
* fields and sections are also hidden.
|
|
564
869
|
* @property content - Ordered list of child content items.
|
|
@@ -568,6 +873,9 @@ type SectionContentItem = {
|
|
|
568
873
|
type: 'section';
|
|
569
874
|
title: string;
|
|
570
875
|
description?: string;
|
|
876
|
+
placeholder?: string;
|
|
877
|
+
answer_guidelines?: string;
|
|
878
|
+
reference_id?: string;
|
|
571
879
|
condition?: Condition;
|
|
572
880
|
content: ContentItem[];
|
|
573
881
|
};
|
|
@@ -576,10 +884,16 @@ type SectionContentItem = {
|
|
|
576
884
|
/**
|
|
577
885
|
* Descriptor for a field to be added via the editor.
|
|
578
886
|
* `id` is optional -- when omitted the editor auto-assigns the next available id.
|
|
887
|
+
*
|
|
888
|
+
* Written as an explicit union rather than `Omit<AnyFieldContentItem, 'id'>`
|
|
889
|
+
* because `Omit` does not distribute over a union -- it would collapse to the
|
|
890
|
+
* properties the two members share, dropping `label` and `text`.
|
|
579
891
|
*/
|
|
580
|
-
type FieldDescriptor = Omit<FieldContentItem, 'id'> & {
|
|
892
|
+
type FieldDescriptor = (Omit<FieldContentItem, 'id'> & {
|
|
581
893
|
id?: number;
|
|
582
|
-
}
|
|
894
|
+
}) | (Omit<StaticFieldContentItem, 'id'> & {
|
|
895
|
+
id?: number;
|
|
896
|
+
});
|
|
583
897
|
/**
|
|
584
898
|
* Descriptor for a section to be added via the editor.
|
|
585
899
|
* `id` is optional -- when omitted the editor auto-assigns the next available id.
|
|
@@ -627,6 +941,9 @@ declare class FormDefinitionEditor {
|
|
|
627
941
|
setId(id: string): this;
|
|
628
942
|
/**
|
|
629
943
|
* Returns the next available numeric id (max existing + 1).
|
|
944
|
+
*
|
|
945
|
+
* `array_obj` sub-field ids share the form-wide id space, so they count
|
|
946
|
+
* here too -- otherwise a new top-level field could collide with one.
|
|
630
947
|
*/
|
|
631
948
|
nextId(): number;
|
|
632
949
|
/**
|
|
@@ -655,7 +972,9 @@ declare class FormDefinitionEditor {
|
|
|
655
972
|
* Cannot change `id` or `type`. Use {@link removeItem} + {@link addField}
|
|
656
973
|
* to change the type.
|
|
657
974
|
*/
|
|
658
|
-
updateField(id: number, updates: Partial<Omit<FieldContentItem, 'id' | 'type'
|
|
975
|
+
updateField(id: number, updates: Partial<Omit<FieldContentItem, 'id' | 'type'> & {
|
|
976
|
+
text: string;
|
|
977
|
+
}>): this;
|
|
659
978
|
/**
|
|
660
979
|
* Updates properties of an existing section.
|
|
661
980
|
*
|
|
@@ -703,27 +1022,114 @@ declare class FormDefinitionEditor {
|
|
|
703
1022
|
*/
|
|
704
1023
|
setCondition(id: number, condition: Condition | undefined): this;
|
|
705
1024
|
/**
|
|
706
|
-
* Sets the
|
|
1025
|
+
* Sets the options for a `select` or `multiselect` field.
|
|
707
1026
|
*/
|
|
708
1027
|
setOptions(id: number, options: SelectOption[]): this;
|
|
709
1028
|
/**
|
|
710
1029
|
* Sets the item definition for an `array` field.
|
|
711
1030
|
*/
|
|
712
1031
|
setArrayItem(id: number, itemDef: ArrayItemDef): this;
|
|
1032
|
+
/**
|
|
1033
|
+
* Replaces the whole sub-field list of an `array_obj` field.
|
|
1034
|
+
*
|
|
1035
|
+
* @throws If the id is not found or does not refer to an `array_obj` field.
|
|
1036
|
+
*/
|
|
1037
|
+
setArrayItems(id: number, itemDefs: ArrayObjItemDef[]): this;
|
|
1038
|
+
/**
|
|
1039
|
+
* Returns the sub-field list of an `array_obj` field.
|
|
1040
|
+
*
|
|
1041
|
+
* @throws If the id is not found or does not refer to an `array_obj` field.
|
|
1042
|
+
*/
|
|
1043
|
+
getArrayItems(id: number): ArrayObjItemDef[];
|
|
1044
|
+
/**
|
|
1045
|
+
* Sets or clears the layout hint of an `array_obj` field.
|
|
1046
|
+
*
|
|
1047
|
+
* Presentation metadata only -- the engine never reads it. Passing
|
|
1048
|
+
* `undefined` removes the key, which reads as `'list'`.
|
|
1049
|
+
*
|
|
1050
|
+
* @throws If the id is not found or does not refer to an `array_obj` field.
|
|
1051
|
+
*/
|
|
1052
|
+
setArrayKind(id: number, kind: ArrayObjKind | undefined): this;
|
|
1053
|
+
/**
|
|
1054
|
+
* Appends a sub-field to an `array_obj` field. The sub-field's `id` is
|
|
1055
|
+
* auto-assigned when omitted.
|
|
1056
|
+
*
|
|
1057
|
+
* @returns The id of the sub-field that was added.
|
|
1058
|
+
* @throws If the id is not found, does not refer to an `array_obj` field,
|
|
1059
|
+
* or the requested sub-field id is already taken.
|
|
1060
|
+
*/
|
|
1061
|
+
addArrayItemField(id: number, subField: Omit<ArrayObjItemDef, 'id'> & {
|
|
1062
|
+
id?: number;
|
|
1063
|
+
}): number;
|
|
1064
|
+
/**
|
|
1065
|
+
* Merges properties into an existing `array_obj` sub-field.
|
|
1066
|
+
*
|
|
1067
|
+
* Like {@link updateField}, omitted properties are kept rather than
|
|
1068
|
+
* removed -- pass a property explicitly as `undefined` to clear it.
|
|
1069
|
+
*
|
|
1070
|
+
* @throws If the field or the sub-field is not found.
|
|
1071
|
+
*/
|
|
1072
|
+
updateArrayItemField(id: number, subFieldId: number, patch: Partial<ArrayObjItemDef>): this;
|
|
1073
|
+
/**
|
|
1074
|
+
* Removes a sub-field from an `array_obj` field.
|
|
1075
|
+
*
|
|
1076
|
+
* @throws If the field or the sub-field is not found.
|
|
1077
|
+
*/
|
|
1078
|
+
removeArrayItemField(id: number, subFieldId: number): this;
|
|
1079
|
+
/**
|
|
1080
|
+
* Moves a sub-field of an `array_obj` field to another position.
|
|
1081
|
+
*
|
|
1082
|
+
* @throws If the field is not found or either index is out of range.
|
|
1083
|
+
*/
|
|
1084
|
+
moveArrayItemField(id: number, fromIndex: number, toIndex: number): this;
|
|
713
1085
|
/**
|
|
714
1086
|
* Sets the label for a field.
|
|
715
1087
|
*/
|
|
716
1088
|
setLabel(id: number, label: string): this;
|
|
1089
|
+
/**
|
|
1090
|
+
* Sets the displayed text of a `static` field.
|
|
1091
|
+
*
|
|
1092
|
+
* @throws If the id is not found or does not refer to a static field.
|
|
1093
|
+
*/
|
|
1094
|
+
setText(id: number, text: string): this;
|
|
717
1095
|
/**
|
|
718
1096
|
* Sets the description for a field or section.
|
|
719
1097
|
*/
|
|
720
1098
|
setFieldDescription(id: number, description: string | undefined): this;
|
|
1099
|
+
/**
|
|
1100
|
+
* Sets the placeholder for a field or section.
|
|
1101
|
+
*
|
|
1102
|
+
* Passing `undefined` removes the property. Unlike {@link updateField},
|
|
1103
|
+
* which merges and therefore cannot clear, this genuinely deletes the key.
|
|
1104
|
+
*/
|
|
1105
|
+
setPlaceholder(id: number, placeholder: string | undefined): this;
|
|
1106
|
+
/**
|
|
1107
|
+
* Sets the answer guidelines for a field or section.
|
|
1108
|
+
*
|
|
1109
|
+
* Passing `undefined` removes the property.
|
|
1110
|
+
*/
|
|
1111
|
+
setAnswerGuidelines(id: number, answerGuidelines: string | undefined): this;
|
|
1112
|
+
/**
|
|
1113
|
+
* Sets the external reference id for a field or section.
|
|
1114
|
+
*
|
|
1115
|
+
* Passing `undefined` removes the property.
|
|
1116
|
+
*/
|
|
1117
|
+
setReferenceId(id: number, referenceId: string | undefined): this;
|
|
1118
|
+
/**
|
|
1119
|
+
* Assigns or deletes one optional string property on a field or section.
|
|
1120
|
+
*/
|
|
1121
|
+
private setMetadata;
|
|
721
1122
|
/**
|
|
722
1123
|
* Returns a deep clone of the current form definition.
|
|
723
1124
|
*/
|
|
724
1125
|
toJSON(): FormDefinition;
|
|
725
1126
|
private findItem;
|
|
726
1127
|
private assertIdAvailable;
|
|
1128
|
+
/**
|
|
1129
|
+
* Finds an `array_obj` sub-field anywhere in the definition by its id.
|
|
1130
|
+
*/
|
|
1131
|
+
private findArrayObjItem;
|
|
1132
|
+
private assertArrayObjField;
|
|
727
1133
|
private insertItem;
|
|
728
1134
|
private getTargetContent;
|
|
729
1135
|
private removeFromContent;
|
|
@@ -746,12 +1152,17 @@ declare class FormDefinitionEditor {
|
|
|
746
1152
|
* ### Semantic validation (`validate`)
|
|
747
1153
|
* Checks for logical issues that go beyond JSON schema validity:
|
|
748
1154
|
* 1. **Duplicate IDs** (`DUPLICATE_ID`) -- every content item id must be unique.
|
|
1155
|
+
* `array_obj` sub-field ids share that id space and are checked with it.
|
|
749
1156
|
* 2. **Nesting depth** (`NESTING_DEPTH`) -- sections may not be nested more
|
|
750
1157
|
* than 3 levels deep.
|
|
751
1158
|
* 3. **Unknown field references** (`UNKNOWN_FIELD_REF`) -- conditions must
|
|
752
1159
|
* only reference field ids that exist in the registry.
|
|
753
|
-
* 4. **Condition references
|
|
754
|
-
* must not reference section
|
|
1160
|
+
* 4. **Condition references a valueless item** (`CONDITION_REFS_SECTION`,
|
|
1161
|
+
* `CONDITION_REFS_STATIC`) -- conditions must not reference section or
|
|
1162
|
+
* static ids, because neither holds a value.
|
|
1163
|
+
* 4b. **Condition references an `array_obj` sub-field** (`CONDITION_REFS_ARRAY_OBJ_ITEM`)
|
|
1164
|
+
* -- a sub-field holds one value per row, so a form-level condition cannot
|
|
1165
|
+
* say which row it means.
|
|
755
1166
|
* 5. **Constraint contradictions** (`INVALID_MIN_MAX`) -- e.g. `minLength > maxLength`,
|
|
756
1167
|
* `min > max`, `minDate > maxDate` (absolute dates only), `minItems > maxItems`.
|
|
757
1168
|
* 6. **Invalid regex** (`INVALID_REGEX`) -- string field `pattern` values must
|
|
@@ -765,6 +1176,21 @@ declare class FormDefinitionValidator {
|
|
|
765
1176
|
* @returns Array of `SCHEMA_INVALID` issues. Empty when the input conforms to the schema.
|
|
766
1177
|
*/
|
|
767
1178
|
validateSchema(input: unknown): DocumentValidationError[];
|
|
1179
|
+
private formatSchemaErrors;
|
|
1180
|
+
private collectSchemaIssues;
|
|
1181
|
+
private shouldKeepSchemaError;
|
|
1182
|
+
private shouldKeepAdditionalPropertyError;
|
|
1183
|
+
private formatSchemaIssue;
|
|
1184
|
+
private formatAdditionalPropertiesIssue;
|
|
1185
|
+
private deduplicateSchemaIssues;
|
|
1186
|
+
private isRedundantOneOfIssue;
|
|
1187
|
+
private formatPath;
|
|
1188
|
+
private getValueAtPath;
|
|
1189
|
+
private getParentPath;
|
|
1190
|
+
private getLastPathSegment;
|
|
1191
|
+
private isContentItemPath;
|
|
1192
|
+
private formatArticle;
|
|
1193
|
+
private isRecord;
|
|
768
1194
|
/**
|
|
769
1195
|
* Validates a form definition semantically.
|
|
770
1196
|
*
|
|
@@ -774,9 +1200,11 @@ declare class FormDefinitionValidator {
|
|
|
774
1200
|
*/
|
|
775
1201
|
validate(definition: FormDefinition, registry: Map<number, FieldEntry>): DocumentValidationError[];
|
|
776
1202
|
private checkDuplicateIds;
|
|
1203
|
+
private collectArrayObjItemIds;
|
|
1204
|
+
private checkConditionRefsArrayObjItem;
|
|
777
1205
|
private checkNestingDepth;
|
|
778
1206
|
private checkConditionRefs;
|
|
779
|
-
private
|
|
1207
|
+
private checkConditionRefsValueless;
|
|
780
1208
|
private checkConstraintContradictions;
|
|
781
1209
|
private checkInvalidRegex;
|
|
782
1210
|
private walkItems;
|
|
@@ -1000,8 +1428,9 @@ declare class FormValuesEditor {
|
|
|
1000
1428
|
* If the field currently has no value, it is initialized to an empty array
|
|
1001
1429
|
* before appending.
|
|
1002
1430
|
*
|
|
1003
|
-
* @param fieldId - Numeric id of the array field.
|
|
1004
|
-
* @param value - The value to append. Defaults to `undefined
|
|
1431
|
+
* @param fieldId - Numeric id of the `array` or `array_obj` field.
|
|
1432
|
+
* @param value - The value to append. Defaults to `undefined` for an
|
|
1433
|
+
* `array` field and to an empty row (`{}`) for an `array_obj` field.
|
|
1005
1434
|
* @returns `this` for chaining.
|
|
1006
1435
|
* @throws If `fieldId` is not an array field.
|
|
1007
1436
|
*/
|
|
@@ -1035,6 +1464,88 @@ declare class FormValuesEditor {
|
|
|
1035
1464
|
* @throws If `fieldId` is not an array field or the index is out of bounds.
|
|
1036
1465
|
*/
|
|
1037
1466
|
setArrayItem(fieldId: number, index: number, value: unknown): this;
|
|
1467
|
+
/**
|
|
1468
|
+
* Returns the value of one sub-field within one row of an `array_obj` field.
|
|
1469
|
+
*
|
|
1470
|
+
* @param fieldId - Numeric id of the `array_obj` field.
|
|
1471
|
+
* @param index - Zero-based row index.
|
|
1472
|
+
* @param subFieldId - Numeric id of the sub-field.
|
|
1473
|
+
* @returns The sub-field value, or `undefined` if not set.
|
|
1474
|
+
* @throws If the field is not an `array_obj`, the row index is out of
|
|
1475
|
+
* bounds, or the sub-field does not belong to the field.
|
|
1476
|
+
*/
|
|
1477
|
+
getArrayObjValue(fieldId: number, index: number, subFieldId: number): unknown;
|
|
1478
|
+
/**
|
|
1479
|
+
* Sets the value of one sub-field within one row of an `array_obj` field.
|
|
1480
|
+
*
|
|
1481
|
+
* @param fieldId - Numeric id of the `array_obj` field.
|
|
1482
|
+
* @param index - Zero-based row index.
|
|
1483
|
+
* @param subFieldId - Numeric id of the sub-field.
|
|
1484
|
+
* @param value - The value to set.
|
|
1485
|
+
* @returns `this` for chaining.
|
|
1486
|
+
* @throws If the field is not an `array_obj`, the row index is out of
|
|
1487
|
+
* bounds, or the sub-field does not belong to the field or is static.
|
|
1488
|
+
*/
|
|
1489
|
+
setArrayObjValue(fieldId: number, index: number, subFieldId: number, value: unknown): this;
|
|
1490
|
+
/**
|
|
1491
|
+
* Removes one sub-field's value from one row of an `array_obj` field.
|
|
1492
|
+
*
|
|
1493
|
+
* @returns `this` for chaining.
|
|
1494
|
+
* @throws Under the same conditions as {@link setArrayObjValue}.
|
|
1495
|
+
*/
|
|
1496
|
+
clearArrayObjValue(fieldId: number, index: number, subFieldId: number): this;
|
|
1497
|
+
/**
|
|
1498
|
+
* Returns the suggestion recorded for a field.
|
|
1499
|
+
*
|
|
1500
|
+
* @param fieldId - Numeric id of the field.
|
|
1501
|
+
* @returns The suggestion, or `undefined` if the field has none.
|
|
1502
|
+
*/
|
|
1503
|
+
getSuggestion(fieldId: number): FieldSuggestion | undefined;
|
|
1504
|
+
/**
|
|
1505
|
+
* Returns every suggestion on the document, keyed by stringified field id.
|
|
1506
|
+
*
|
|
1507
|
+
* @returns A copy of the suggestions map. Empty when there are none.
|
|
1508
|
+
*/
|
|
1509
|
+
getSuggestions(): FormSuggestions;
|
|
1510
|
+
/**
|
|
1511
|
+
* Records a suggestion for a field, replacing any existing one. The field's
|
|
1512
|
+
* value is left untouched.
|
|
1513
|
+
*
|
|
1514
|
+
* @param fieldId - Numeric id of the field.
|
|
1515
|
+
* @param suggestion - The suggestion to store.
|
|
1516
|
+
* @returns `this` for chaining.
|
|
1517
|
+
* @throws If `fieldId` is unknown, references a section, or `confidence`
|
|
1518
|
+
* falls outside `0..1`.
|
|
1519
|
+
*/
|
|
1520
|
+
setSuggestion(fieldId: number, suggestion: FieldSuggestion): this;
|
|
1521
|
+
/**
|
|
1522
|
+
* Removes the suggestion recorded for a field, leaving its value untouched.
|
|
1523
|
+
*
|
|
1524
|
+
* @param fieldId - Numeric id of the field.
|
|
1525
|
+
* @returns `this` for chaining.
|
|
1526
|
+
*/
|
|
1527
|
+
clearSuggestion(fieldId: number): this;
|
|
1528
|
+
/**
|
|
1529
|
+
* Accepts a field's suggestion: copies the suggested value into the field's
|
|
1530
|
+
* value and **keeps** the suggestion, so its source stays visible.
|
|
1531
|
+
*
|
|
1532
|
+
* No-op when the field has no suggestion.
|
|
1533
|
+
*
|
|
1534
|
+
* @param fieldId - Numeric id of the field.
|
|
1535
|
+
* @returns `this` for chaining.
|
|
1536
|
+
* @throws If `fieldId` is unknown or references a section.
|
|
1537
|
+
*/
|
|
1538
|
+
acceptSuggestion(fieldId: number): this;
|
|
1539
|
+
/**
|
|
1540
|
+
* Rejects a field's suggestion: removes it entirely, leaving the field's
|
|
1541
|
+
* value untouched.
|
|
1542
|
+
*
|
|
1543
|
+
* No-op when the field has no suggestion.
|
|
1544
|
+
*
|
|
1545
|
+
* @param fieldId - Numeric id of the field.
|
|
1546
|
+
* @returns `this` for chaining.
|
|
1547
|
+
*/
|
|
1548
|
+
rejectSuggestion(fieldId: number): this;
|
|
1038
1549
|
/**
|
|
1039
1550
|
* Sets the `submittedAt` timestamp on the document.
|
|
1040
1551
|
*
|
|
@@ -1086,8 +1597,83 @@ declare class FormValuesEditor {
|
|
|
1086
1597
|
* Returns the array value for `fieldId`, initializing to `[]` if not yet set.
|
|
1087
1598
|
*/
|
|
1088
1599
|
private getOrInitArray;
|
|
1600
|
+
/**
|
|
1601
|
+
* Asserts that `fieldId` is an `array_obj` field holding a row at `index`
|
|
1602
|
+
* with a writable sub-field `subFieldId`, and returns that row.
|
|
1603
|
+
* The row is created in place when it is absent or not an object.
|
|
1604
|
+
*/
|
|
1605
|
+
private assertArrayObjRow;
|
|
1089
1606
|
}
|
|
1090
1607
|
//#endregion
|
|
1608
|
+
//#region src/suggestions.d.ts
|
|
1609
|
+
/**
|
|
1610
|
+
* Pure helpers for reading and writing the `suggestions` block of a
|
|
1611
|
+
* {@link FormDocument}.
|
|
1612
|
+
*
|
|
1613
|
+
* Every function is total over legacy documents: `doc.suggestions` may be
|
|
1614
|
+
* `undefined` (documents written before suggestions existed) and each helper
|
|
1615
|
+
* treats that as "no suggestions". Writers never mutate their input -- they
|
|
1616
|
+
* return a new document -- and they drop the `suggestions` key entirely once it
|
|
1617
|
+
* would be empty, so a document that never had suggestions round-trips
|
|
1618
|
+
* unchanged.
|
|
1619
|
+
*
|
|
1620
|
+
* These helpers deliberately do **not** check that `fieldId` refers to an
|
|
1621
|
+
* existing, non-section field. That check belongs to the general-purpose
|
|
1622
|
+
* authoring API ({@link FormValuesEditor}); callers that already resolved a
|
|
1623
|
+
* field -- such as the viewer's render loop -- would only pay for it twice.
|
|
1624
|
+
*/
|
|
1625
|
+
/**
|
|
1626
|
+
* Returns the suggestion recorded for a field.
|
|
1627
|
+
*
|
|
1628
|
+
* @param doc - The form document to read from.
|
|
1629
|
+
* @param fieldId - Numeric id of the field.
|
|
1630
|
+
* @returns The suggestion, or `undefined` when the field has none.
|
|
1631
|
+
*/
|
|
1632
|
+
declare const getSuggestion: (doc: FormDocument, fieldId: number) => FieldSuggestion | undefined;
|
|
1633
|
+
/**
|
|
1634
|
+
* Records a suggestion for a field, replacing any existing one.
|
|
1635
|
+
*
|
|
1636
|
+
* @param doc - The form document to update.
|
|
1637
|
+
* @param fieldId - Numeric id of the field.
|
|
1638
|
+
* @param suggestion - The suggestion to store. Deep-copied before storing.
|
|
1639
|
+
* @returns A new document carrying the suggestion.
|
|
1640
|
+
* @throws If `confidence` is not a finite number within `0..1`.
|
|
1641
|
+
*/
|
|
1642
|
+
declare const setSuggestion: (doc: FormDocument, fieldId: number, suggestion: FieldSuggestion) => FormDocument;
|
|
1643
|
+
/**
|
|
1644
|
+
* Removes the suggestion recorded for a field, leaving the field's value alone.
|
|
1645
|
+
*
|
|
1646
|
+
* When the removed entry was the last one, the `suggestions` key is dropped
|
|
1647
|
+
* from the document rather than left as an empty object.
|
|
1648
|
+
*
|
|
1649
|
+
* @param doc - The form document to update.
|
|
1650
|
+
* @param fieldId - Numeric id of the field.
|
|
1651
|
+
* @returns A new document without that suggestion, or `doc` itself when there
|
|
1652
|
+
* was nothing to remove.
|
|
1653
|
+
*/
|
|
1654
|
+
declare const removeSuggestion: (doc: FormDocument, fieldId: number) => FormDocument;
|
|
1655
|
+
/**
|
|
1656
|
+
* Copies a field's suggested value into the document's values, keeping the
|
|
1657
|
+
* suggestion in place so the origin of the answer stays visible.
|
|
1658
|
+
*
|
|
1659
|
+
* The value is deep-copied: array and object suggestions must not become
|
|
1660
|
+
* aliases of the stored value, or later in-place edits (e.g. appending an array
|
|
1661
|
+
* item) would silently rewrite the suggestion too.
|
|
1662
|
+
*
|
|
1663
|
+
* @param doc - The form document to update.
|
|
1664
|
+
* @param fieldId - Numeric id of the field.
|
|
1665
|
+
* @returns A new document with the value applied, or `doc` itself when the
|
|
1666
|
+
* field has no suggestion.
|
|
1667
|
+
*/
|
|
1668
|
+
declare const applySuggestion: (doc: FormDocument, fieldId: number) => FormDocument;
|
|
1669
|
+
/**
|
|
1670
|
+
* Returns all suggestions on a document as a plain object, never `undefined`.
|
|
1671
|
+
*
|
|
1672
|
+
* @param doc - The form document to read from.
|
|
1673
|
+
* @returns A copy of the suggestions map. Empty when the document has none.
|
|
1674
|
+
*/
|
|
1675
|
+
declare const getSuggestions: (doc: FormDocument) => FormSuggestions;
|
|
1676
|
+
//#endregion
|
|
1091
1677
|
//#region src/types/errors.d.ts
|
|
1092
1678
|
/**
|
|
1093
1679
|
* Error thrown when form definition or document validation fails.
|
|
@@ -1136,6 +1722,24 @@ type FileValue = {
|
|
|
1136
1722
|
url: string;
|
|
1137
1723
|
};
|
|
1138
1724
|
//#endregion
|
|
1725
|
+
//#region src/types/sustainability-value.d.ts
|
|
1726
|
+
/**
|
|
1727
|
+
* Sustainability data for an on-chain asset.
|
|
1728
|
+
*
|
|
1729
|
+
* The engine does not resolve or verify any of these -- the consumer produces
|
|
1730
|
+
* the object and the engine stores it verbatim.
|
|
1731
|
+
*
|
|
1732
|
+
* @property address - CAIP address of the asset the data describes. Opaque to
|
|
1733
|
+
* the engine: its format is never checked.
|
|
1734
|
+
* @property ccri - CCRI (Crypto Carbon Ratings Institute) reference.
|
|
1735
|
+
* @property cmc - CoinMarketCap reference.
|
|
1736
|
+
*/
|
|
1737
|
+
type SustainabilityValue = {
|
|
1738
|
+
address: string;
|
|
1739
|
+
ccri?: string;
|
|
1740
|
+
cmc?: string;
|
|
1741
|
+
};
|
|
1742
|
+
//#endregion
|
|
1139
1743
|
//#region src/visibility-resolver.d.ts
|
|
1140
1744
|
/**
|
|
1141
1745
|
* Computes field and section visibility for a form.
|
|
@@ -1151,6 +1755,7 @@ declare class VisibilityResolver {
|
|
|
1151
1755
|
private readonly registry;
|
|
1152
1756
|
private readonly conditionEvaluator;
|
|
1153
1757
|
private readonly topologicalOrder;
|
|
1758
|
+
private readonly fieldTypes;
|
|
1154
1759
|
/**
|
|
1155
1760
|
* @param registry - The engine's field registry.
|
|
1156
1761
|
* @param conditionEvaluator - Evaluator for condition trees.
|
|
@@ -1196,5 +1801,5 @@ declare class VisibilityResolver {
|
|
|
1196
1801
|
getVisibilityMap(values: FormValues, now: Date): Map<number, boolean>;
|
|
1197
1802
|
}
|
|
1198
1803
|
//#endregion
|
|
1199
|
-
export { type ArrayItemDef, type ArrayValidation, type BooleanValidation, type CompoundCondition, type Condition, ConditionEvaluator, type ContentItem, type ContentItemInfo, type ContentItemType, type DateValidation, DependencyGraph, DocumentError, type DocumentValidationError, type DocumentValidationErrorCode, type EvaluationContext, type FieldContentItem, type FieldDescriptor, type FieldEntry, type FieldType, type FieldValidationError, type FieldValidationRule, FieldValidator, type FileValidation, type FileValue, type FormDefinition, FormDefinitionEditor, FormDefinitionValidator, type FormDocument, FormEngine, type FormSnapshot, type FormValidationResult, type FormValues, FormValuesEditor, type NumberValidation, type SectionContentItem, type SectionDescriptor, type SelectOption, type SelectValidation, type SimpleCondition, type StringValidation, type TypeSpecificValidation, VisibilityResolver };
|
|
1804
|
+
export { type AnyFieldContentItem, type ArrayItemDef, type ArrayObjItemDef, type ArrayObjKind, type ArrayObjRow, type ArrayObjValidation, type ArrayValidation, type BlockchainValidation, type BooleanValidation, type CompoundCondition, type Condition, ConditionEvaluator, type ContentItem, type ContentItemInfo, type ContentItemType, type DateValidation, DependencyGraph, DocumentError, type DocumentValidationError, type DocumentValidationErrorCode, type EvaluationContext, type FieldContentItem, type FieldDescriptor, type FieldEntry, type FieldSuggestion, type FieldType, type FieldValidationError, type FieldValidationRule, FieldValidator, type FileValidation, type FileValue, type FormDefinition, FormDefinitionEditor, FormDefinitionValidator, type FormDocument, FormEngine, type FormSnapshot, type FormSuggestions, type FormValidationResult, type FormValues, FormValuesEditor, type MultiselectValidation, type NumberValidation, type SectionContentItem, type SectionDescriptor, type SelectOption, type SelectValidation, type SimpleCondition, type StaticArrayItemDef, type StaticArrayObjItemDef, type StaticFieldContentItem, type StringValidation, type SustainabilityValidation, type SustainabilityValue, type TypeSpecificValidation, type ValueArrayItemDef, type ValueArrayObjItemDef, VisibilityResolver, applySuggestion, getSuggestion, getSuggestions, removeSuggestion, setSuggestion };
|
|
1200
1805
|
//# sourceMappingURL=index.d.mts.map
|