@fogpipe/forma-core 0.6.0 → 0.7.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/dist/engine/calculate.d.ts +64 -0
- package/dist/engine/calculate.d.ts.map +1 -0
- package/dist/engine/enabled.d.ts +40 -0
- package/dist/engine/enabled.d.ts.map +1 -0
- package/dist/engine/index.d.ts +12 -255
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/required.d.ts +45 -0
- package/dist/engine/required.d.ts.map +1 -0
- package/dist/engine/validate.d.ts +59 -0
- package/dist/engine/validate.d.ts.map +1 -0
- package/dist/engine/visibility.d.ts +52 -0
- package/dist/engine/visibility.d.ts.map +1 -0
- package/dist/feel/index.d.ts +12 -15
- package/dist/feel/index.d.ts.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/{types-Bs3CG9JZ.d.ts → types.d.ts} +29 -30
- package/dist/types.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +36 -2
- package/dist/engine/index.d.cts +0 -258
- package/dist/feel/index.d.cts +0 -105
- package/dist/index.d.cts +0 -3
- package/dist/types-Bs3CG9JZ.d.cts +0 -283
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculation Engine
|
|
3
|
+
*
|
|
4
|
+
* Evaluates computed fields based on form data.
|
|
5
|
+
* Computed values are derived from form data using FEEL expressions.
|
|
6
|
+
*/
|
|
7
|
+
import type { Forma, CalculationResult } from "../types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Calculate all computed values from form data
|
|
10
|
+
*
|
|
11
|
+
* Evaluates each computed field's FEEL expression and returns the results.
|
|
12
|
+
* Errors are collected rather than thrown, allowing partial results.
|
|
13
|
+
*
|
|
14
|
+
* @param data - Current form data
|
|
15
|
+
* @param spec - Form specification with computed fields
|
|
16
|
+
* @returns Computed values and any calculation errors
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const spec = {
|
|
20
|
+
* computed: {
|
|
21
|
+
* bmi: {
|
|
22
|
+
* expression: "weight / (height / 100) ** 2",
|
|
23
|
+
* label: "BMI",
|
|
24
|
+
* format: "decimal(1)"
|
|
25
|
+
* },
|
|
26
|
+
* isObese: {
|
|
27
|
+
* expression: "$computed.bmi >= 30"
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* };
|
|
31
|
+
*
|
|
32
|
+
* const result = calculate({ weight: 85, height: 175 }, spec);
|
|
33
|
+
* // => { values: { bmi: 27.76, isObese: false }, errors: [] }
|
|
34
|
+
*/
|
|
35
|
+
export declare function calculate(data: Record<string, unknown>, spec: Forma): Record<string, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Calculate computed values with error reporting
|
|
38
|
+
*
|
|
39
|
+
* Same as calculate() but also returns any errors that occurred.
|
|
40
|
+
*
|
|
41
|
+
* @param data - Current form data
|
|
42
|
+
* @param spec - Form specification
|
|
43
|
+
* @returns Values and errors
|
|
44
|
+
*/
|
|
45
|
+
export declare function calculateWithErrors(data: Record<string, unknown>, spec: Forma): CalculationResult;
|
|
46
|
+
/**
|
|
47
|
+
* Get a computed value formatted according to its format specification
|
|
48
|
+
*
|
|
49
|
+
* @param fieldName - Name of the computed field
|
|
50
|
+
* @param data - Current form data
|
|
51
|
+
* @param spec - Form specification
|
|
52
|
+
* @returns Formatted string or null if not displayable
|
|
53
|
+
*/
|
|
54
|
+
export declare function getFormattedValue(fieldName: string, data: Record<string, unknown>, spec: Forma): string | null;
|
|
55
|
+
/**
|
|
56
|
+
* Calculate a single computed field
|
|
57
|
+
*
|
|
58
|
+
* @param fieldName - Name of the computed field
|
|
59
|
+
* @param data - Current form data
|
|
60
|
+
* @param spec - Form specification
|
|
61
|
+
* @returns Computed value or null if calculation failed
|
|
62
|
+
*/
|
|
63
|
+
export declare function calculateField(fieldName: string, data: Record<string, unknown>, spec: Forma): unknown;
|
|
64
|
+
//# sourceMappingURL=calculate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculate.d.ts","sourceRoot":"","sources":["../../src/engine/calculate.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,KAAK,EAGL,iBAAiB,EAElB,MAAM,aAAa,CAAC;AAMrB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,GACV,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,GACV,iBAAiB,CAsCnB;AAsKD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,GACV,MAAM,GAAG,IAAI,CAcf;AAkDD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,GACV,OAAO,CAGT"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enabled Fields Engine
|
|
3
|
+
*
|
|
4
|
+
* Determines which fields are currently enabled (editable) based on
|
|
5
|
+
* conditional enabledWhen expressions.
|
|
6
|
+
*/
|
|
7
|
+
import type { Forma, EnabledResult } from "../types.js";
|
|
8
|
+
export interface EnabledOptions {
|
|
9
|
+
/** Pre-calculated computed values */
|
|
10
|
+
computed?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Determine which fields are currently enabled (editable)
|
|
14
|
+
*
|
|
15
|
+
* Returns a map of field paths to boolean enabled states.
|
|
16
|
+
* Fields without enabledWhen expressions are always enabled.
|
|
17
|
+
*
|
|
18
|
+
* @param data - Current form data
|
|
19
|
+
* @param spec - Form specification
|
|
20
|
+
* @param options - Optional pre-calculated computed values
|
|
21
|
+
* @returns Map of field paths to enabled states
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const enabled = getEnabled(
|
|
25
|
+
* { isLocked: true },
|
|
26
|
+
* forma
|
|
27
|
+
* );
|
|
28
|
+
* // => { isLocked: true, lockedField: false, ... }
|
|
29
|
+
*/
|
|
30
|
+
export declare function getEnabled(data: Record<string, unknown>, spec: Forma, options?: EnabledOptions): EnabledResult;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a single field is currently enabled
|
|
33
|
+
*
|
|
34
|
+
* @param fieldPath - Path to the field
|
|
35
|
+
* @param data - Current form data
|
|
36
|
+
* @param spec - Form specification
|
|
37
|
+
* @returns True if the field is enabled
|
|
38
|
+
*/
|
|
39
|
+
export declare function isEnabled(fieldPath: string, data: Record<string, unknown>, spec: Forma): boolean;
|
|
40
|
+
//# sourceMappingURL=enabled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enabled.d.ts","sourceRoot":"","sources":["../../src/engine/enabled.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,KAAK,EAGL,aAAa,EACd,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,cAAmB,GAC3B,aAAa,CA2Cf;AAsBD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,GACV,OAAO,CAkBT"}
|
package/dist/engine/index.d.ts
CHANGED
|
@@ -1,258 +1,15 @@
|
|
|
1
|
-
import { m as Forma, t as CalculationResult, n as VisibilityResult, o as RequiredFieldsResult, p as EnabledResult, r as ValidationResult, q as FieldError } from '../types-Bs3CG9JZ.js';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* Engine module exports
|
|
5
3
|
*
|
|
6
|
-
*
|
|
7
|
-
* Computed values are derived from form data using FEEL expressions.
|
|
4
|
+
* Core form logic engines for visibility, validation, calculation, etc.
|
|
8
5
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const spec = {
|
|
22
|
-
* computed: {
|
|
23
|
-
* bmi: {
|
|
24
|
-
* expression: "weight / (height / 100) ** 2",
|
|
25
|
-
* label: "BMI",
|
|
26
|
-
* format: "decimal(1)"
|
|
27
|
-
* },
|
|
28
|
-
* isObese: {
|
|
29
|
-
* expression: "$computed.bmi >= 30"
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* };
|
|
33
|
-
*
|
|
34
|
-
* const result = calculate({ weight: 85, height: 175 }, spec);
|
|
35
|
-
* // => { values: { bmi: 27.76, isObese: false }, errors: [] }
|
|
36
|
-
*/
|
|
37
|
-
declare function calculate(data: Record<string, unknown>, spec: Forma): Record<string, unknown>;
|
|
38
|
-
/**
|
|
39
|
-
* Calculate computed values with error reporting
|
|
40
|
-
*
|
|
41
|
-
* Same as calculate() but also returns any errors that occurred.
|
|
42
|
-
*
|
|
43
|
-
* @param data - Current form data
|
|
44
|
-
* @param spec - Form specification
|
|
45
|
-
* @returns Values and errors
|
|
46
|
-
*/
|
|
47
|
-
declare function calculateWithErrors(data: Record<string, unknown>, spec: Forma): CalculationResult;
|
|
48
|
-
/**
|
|
49
|
-
* Get a computed value formatted according to its format specification
|
|
50
|
-
*
|
|
51
|
-
* @param fieldName - Name of the computed field
|
|
52
|
-
* @param data - Current form data
|
|
53
|
-
* @param spec - Form specification
|
|
54
|
-
* @returns Formatted string or null if not displayable
|
|
55
|
-
*/
|
|
56
|
-
declare function getFormattedValue(fieldName: string, data: Record<string, unknown>, spec: Forma): string | null;
|
|
57
|
-
/**
|
|
58
|
-
* Calculate a single computed field
|
|
59
|
-
*
|
|
60
|
-
* @param fieldName - Name of the computed field
|
|
61
|
-
* @param data - Current form data
|
|
62
|
-
* @param spec - Form specification
|
|
63
|
-
* @returns Computed value or null if calculation failed
|
|
64
|
-
*/
|
|
65
|
-
declare function calculateField(fieldName: string, data: Record<string, unknown>, spec: Forma): unknown;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Visibility Engine
|
|
69
|
-
*
|
|
70
|
-
* Determines which fields should be visible based on form data
|
|
71
|
-
* and Forma visibility rules.
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
interface VisibilityOptions {
|
|
75
|
-
/** Pre-calculated computed values (avoids recalculation) */
|
|
76
|
-
computed?: Record<string, unknown>;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Determine visibility for all fields in a form
|
|
80
|
-
*
|
|
81
|
-
* Returns a map of field paths to boolean visibility states.
|
|
82
|
-
* Fields without visibleWhen expressions are always visible.
|
|
83
|
-
*
|
|
84
|
-
* @param data - Current form data
|
|
85
|
-
* @param spec - Form specification
|
|
86
|
-
* @param options - Optional pre-calculated computed values
|
|
87
|
-
* @returns Map of field paths to visibility states
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* const visibility = getVisibility(
|
|
91
|
-
* { age: 21, hasLicense: true },
|
|
92
|
-
* forma
|
|
93
|
-
* );
|
|
94
|
-
* // => { age: true, hasLicense: true, vehicleType: true, ... }
|
|
95
|
-
*/
|
|
96
|
-
declare function getVisibility(data: Record<string, unknown>, spec: Forma, options?: VisibilityOptions): VisibilityResult;
|
|
97
|
-
/**
|
|
98
|
-
* Check if a single field is visible
|
|
99
|
-
*
|
|
100
|
-
* Useful for checking visibility of one field without computing all.
|
|
101
|
-
*
|
|
102
|
-
* @param fieldPath - Field path to check
|
|
103
|
-
* @param data - Current form data
|
|
104
|
-
* @param spec - Form specification
|
|
105
|
-
* @param options - Optional pre-calculated computed values
|
|
106
|
-
* @returns True if the field is visible
|
|
107
|
-
*/
|
|
108
|
-
declare function isFieldVisible(fieldPath: string, data: Record<string, unknown>, spec: Forma, options?: VisibilityOptions): boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Determine which pages are visible in a wizard form
|
|
111
|
-
*
|
|
112
|
-
* @param data - Current form data
|
|
113
|
-
* @param spec - Form specification with pages
|
|
114
|
-
* @param options - Optional pre-calculated computed values
|
|
115
|
-
* @returns Map of page IDs to visibility states
|
|
116
|
-
*/
|
|
117
|
-
declare function getPageVisibility(data: Record<string, unknown>, spec: Forma, options?: VisibilityOptions): Record<string, boolean>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Required Fields Engine
|
|
121
|
-
*
|
|
122
|
-
* Determines which fields are currently required based on
|
|
123
|
-
* conditional requiredWhen expressions and schema required array.
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
interface RequiredOptions {
|
|
127
|
-
/** Pre-calculated computed values */
|
|
128
|
-
computed?: Record<string, unknown>;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Determine which fields are currently required
|
|
132
|
-
*
|
|
133
|
-
* Returns a map of field paths to boolean required states.
|
|
134
|
-
* Evaluates requiredWhen expressions for conditional requirements.
|
|
135
|
-
*
|
|
136
|
-
* @param data - Current form data
|
|
137
|
-
* @param spec - Form specification
|
|
138
|
-
* @param options - Optional pre-calculated computed values
|
|
139
|
-
* @returns Map of field paths to required states
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* const required = getRequired(
|
|
143
|
-
* { hasInsurance: true },
|
|
144
|
-
* forma
|
|
145
|
-
* );
|
|
146
|
-
* // => { hasInsurance: true, insuranceProvider: true, policyNumber: true }
|
|
147
|
-
*/
|
|
148
|
-
declare function getRequired(data: Record<string, unknown>, spec: Forma, options?: RequiredOptions): RequiredFieldsResult;
|
|
149
|
-
/**
|
|
150
|
-
* Check if a single field is currently required
|
|
151
|
-
*
|
|
152
|
-
* @param fieldPath - Path to the field
|
|
153
|
-
* @param data - Current form data
|
|
154
|
-
* @param spec - Form specification
|
|
155
|
-
* @returns True if the field is required
|
|
156
|
-
*/
|
|
157
|
-
declare function isRequired(fieldPath: string, data: Record<string, unknown>, spec: Forma): boolean;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Enabled Fields Engine
|
|
161
|
-
*
|
|
162
|
-
* Determines which fields are currently enabled (editable) based on
|
|
163
|
-
* conditional enabledWhen expressions.
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
interface EnabledOptions {
|
|
167
|
-
/** Pre-calculated computed values */
|
|
168
|
-
computed?: Record<string, unknown>;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Determine which fields are currently enabled (editable)
|
|
172
|
-
*
|
|
173
|
-
* Returns a map of field paths to boolean enabled states.
|
|
174
|
-
* Fields without enabledWhen expressions are always enabled.
|
|
175
|
-
*
|
|
176
|
-
* @param data - Current form data
|
|
177
|
-
* @param spec - Form specification
|
|
178
|
-
* @param options - Optional pre-calculated computed values
|
|
179
|
-
* @returns Map of field paths to enabled states
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* const enabled = getEnabled(
|
|
183
|
-
* { isLocked: true },
|
|
184
|
-
* forma
|
|
185
|
-
* );
|
|
186
|
-
* // => { isLocked: true, lockedField: false, ... }
|
|
187
|
-
*/
|
|
188
|
-
declare function getEnabled(data: Record<string, unknown>, spec: Forma, options?: EnabledOptions): EnabledResult;
|
|
189
|
-
/**
|
|
190
|
-
* Check if a single field is currently enabled
|
|
191
|
-
*
|
|
192
|
-
* @param fieldPath - Path to the field
|
|
193
|
-
* @param data - Current form data
|
|
194
|
-
* @param spec - Form specification
|
|
195
|
-
* @returns True if the field is enabled
|
|
196
|
-
*/
|
|
197
|
-
declare function isEnabled(fieldPath: string, data: Record<string, unknown>, spec: Forma): boolean;
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Validation Engine
|
|
201
|
-
*
|
|
202
|
-
* Validates form data against Forma rules including:
|
|
203
|
-
* - JSON Schema type validation
|
|
204
|
-
* - Required field validation (with conditional requiredWhen)
|
|
205
|
-
* - Custom FEEL validation rules
|
|
206
|
-
* - Array item validation
|
|
207
|
-
*/
|
|
208
|
-
|
|
209
|
-
interface ValidateOptions {
|
|
210
|
-
/** Pre-calculated computed values */
|
|
211
|
-
computed?: Record<string, unknown>;
|
|
212
|
-
/** Pre-calculated visibility */
|
|
213
|
-
visibility?: Record<string, boolean>;
|
|
214
|
-
/** Only validate visible fields (default: true) */
|
|
215
|
-
onlyVisible?: boolean;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Validate form data against a Forma
|
|
219
|
-
*
|
|
220
|
-
* Performs comprehensive validation including:
|
|
221
|
-
* - Required field checks (respecting conditional requiredWhen)
|
|
222
|
-
* - JSON Schema type validation
|
|
223
|
-
* - Custom FEEL validation rules
|
|
224
|
-
* - Array min/max items validation
|
|
225
|
-
* - Array item field validation
|
|
226
|
-
*
|
|
227
|
-
* By default, only visible fields are validated.
|
|
228
|
-
*
|
|
229
|
-
* @param data - Current form data
|
|
230
|
-
* @param spec - Form specification
|
|
231
|
-
* @param options - Validation options
|
|
232
|
-
* @returns Validation result with valid flag and errors array
|
|
233
|
-
*
|
|
234
|
-
* @example
|
|
235
|
-
* const result = validate(
|
|
236
|
-
* { name: "", age: 15 },
|
|
237
|
-
* forma
|
|
238
|
-
* );
|
|
239
|
-
* // => {
|
|
240
|
-
* // valid: false,
|
|
241
|
-
* // errors: [
|
|
242
|
-
* // { field: "name", message: "Name is required", severity: "error" },
|
|
243
|
-
* // { field: "age", message: "Must be 18 or older", severity: "error" }
|
|
244
|
-
* // ]
|
|
245
|
-
* // }
|
|
246
|
-
*/
|
|
247
|
-
declare function validate(data: Record<string, unknown>, spec: Forma, options?: ValidateOptions): ValidationResult;
|
|
248
|
-
/**
|
|
249
|
-
* Validate a single field
|
|
250
|
-
*
|
|
251
|
-
* @param fieldPath - Path to the field
|
|
252
|
-
* @param data - Current form data
|
|
253
|
-
* @param spec - Form specification
|
|
254
|
-
* @returns Array of errors for this field
|
|
255
|
-
*/
|
|
256
|
-
declare function validateSingleField(fieldPath: string, data: Record<string, unknown>, spec: Forma): FieldError[];
|
|
257
|
-
|
|
258
|
-
export { type EnabledOptions, type RequiredOptions, type ValidateOptions, type VisibilityOptions, calculate, calculateField, calculateWithErrors, getEnabled, getFormattedValue, getPageVisibility, getRequired, getVisibility, isEnabled, isFieldVisible, isRequired, validate, validateSingleField };
|
|
6
|
+
export { calculate, calculateWithErrors, calculateField, getFormattedValue, } from "./calculate.js";
|
|
7
|
+
export { getVisibility, isFieldVisible, getPageVisibility, } from "./visibility.js";
|
|
8
|
+
export type { VisibilityOptions, } from "./visibility.js";
|
|
9
|
+
export { getRequired, isRequired, } from "./required.js";
|
|
10
|
+
export type { RequiredOptions, } from "./required.js";
|
|
11
|
+
export { getEnabled, isEnabled, } from "./enabled.js";
|
|
12
|
+
export type { EnabledOptions, } from "./enabled.js";
|
|
13
|
+
export { validate, validateSingleField, } from "./validate.js";
|
|
14
|
+
export type { ValidateOptions, } from "./validate.js";
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EACL,SAAS,EACT,mBAAmB,EACnB,cAAc,EACd,iBAAiB,GAClB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,aAAa,EACb,cAAc,EACd,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,WAAW,EACX,UAAU,GACX,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,eAAe,GAChB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,UAAU,EACV,SAAS,GACV,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,cAAc,GACf,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,QAAQ,EACR,mBAAmB,GACpB,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,eAAe,GAChB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Required Fields Engine
|
|
3
|
+
*
|
|
4
|
+
* Determines which fields are currently required based on
|
|
5
|
+
* conditional requiredWhen expressions and schema required array.
|
|
6
|
+
*/
|
|
7
|
+
import type { Forma, FieldDefinition, EvaluationContext, RequiredFieldsResult } from "../types.js";
|
|
8
|
+
export interface RequiredOptions {
|
|
9
|
+
/** Pre-calculated computed values */
|
|
10
|
+
computed?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Determine which fields are currently required
|
|
14
|
+
*
|
|
15
|
+
* Returns a map of field paths to boolean required states.
|
|
16
|
+
* Evaluates requiredWhen expressions for conditional requirements.
|
|
17
|
+
*
|
|
18
|
+
* @param data - Current form data
|
|
19
|
+
* @param spec - Form specification
|
|
20
|
+
* @param options - Optional pre-calculated computed values
|
|
21
|
+
* @returns Map of field paths to required states
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const required = getRequired(
|
|
25
|
+
* { hasInsurance: true },
|
|
26
|
+
* forma
|
|
27
|
+
* );
|
|
28
|
+
* // => { hasInsurance: true, insuranceProvider: true, policyNumber: true }
|
|
29
|
+
*/
|
|
30
|
+
export declare function getRequired(data: Record<string, unknown>, spec: Forma, options?: RequiredOptions): RequiredFieldsResult;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a single field is required based on requiredWhen or schema
|
|
33
|
+
* @internal Exported for use by validate.ts
|
|
34
|
+
*/
|
|
35
|
+
export declare function isFieldRequired(fieldPath: string, fieldDef: FieldDefinition, spec: Forma, context: EvaluationContext): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Check if a single field is currently required
|
|
38
|
+
*
|
|
39
|
+
* @param fieldPath - Path to the field
|
|
40
|
+
* @param data - Current form data
|
|
41
|
+
* @param spec - Form specification
|
|
42
|
+
* @returns True if the field is required
|
|
43
|
+
*/
|
|
44
|
+
export declare function isRequired(fieldPath: string, data: Record<string, unknown>, spec: Forma): boolean;
|
|
45
|
+
//# sourceMappingURL=required.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"required.d.ts","sourceRoot":"","sources":["../../src/engine/required.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,KAAK,EACL,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,eAAoB,GAC5B,oBAAoB,CAgDtB;AAMD;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAQT;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,GACV,OAAO,CAcT"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation Engine
|
|
3
|
+
*
|
|
4
|
+
* Validates form data against Forma rules including:
|
|
5
|
+
* - JSON Schema type validation
|
|
6
|
+
* - Required field validation (with conditional requiredWhen)
|
|
7
|
+
* - Custom FEEL validation rules
|
|
8
|
+
* - Array item validation
|
|
9
|
+
*/
|
|
10
|
+
import type { Forma, ValidationResult, FieldError } from "../types.js";
|
|
11
|
+
export interface ValidateOptions {
|
|
12
|
+
/** Pre-calculated computed values */
|
|
13
|
+
computed?: Record<string, unknown>;
|
|
14
|
+
/** Pre-calculated visibility */
|
|
15
|
+
visibility?: Record<string, boolean>;
|
|
16
|
+
/** Only validate visible fields (default: true) */
|
|
17
|
+
onlyVisible?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Validate form data against a Forma
|
|
21
|
+
*
|
|
22
|
+
* Performs comprehensive validation including:
|
|
23
|
+
* - Required field checks (respecting conditional requiredWhen)
|
|
24
|
+
* - JSON Schema type validation
|
|
25
|
+
* - Custom FEEL validation rules
|
|
26
|
+
* - Array min/max items validation
|
|
27
|
+
* - Array item field validation
|
|
28
|
+
*
|
|
29
|
+
* By default, only visible fields are validated.
|
|
30
|
+
*
|
|
31
|
+
* @param data - Current form data
|
|
32
|
+
* @param spec - Form specification
|
|
33
|
+
* @param options - Validation options
|
|
34
|
+
* @returns Validation result with valid flag and errors array
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* const result = validate(
|
|
38
|
+
* { name: "", age: 15 },
|
|
39
|
+
* forma
|
|
40
|
+
* );
|
|
41
|
+
* // => {
|
|
42
|
+
* // valid: false,
|
|
43
|
+
* // errors: [
|
|
44
|
+
* // { field: "name", message: "Name is required", severity: "error" },
|
|
45
|
+
* // { field: "age", message: "Must be 18 or older", severity: "error" }
|
|
46
|
+
* // ]
|
|
47
|
+
* // }
|
|
48
|
+
*/
|
|
49
|
+
export declare function validate(data: Record<string, unknown>, spec: Forma, options?: ValidateOptions): ValidationResult;
|
|
50
|
+
/**
|
|
51
|
+
* Validate a single field
|
|
52
|
+
*
|
|
53
|
+
* @param fieldPath - Path to the field
|
|
54
|
+
* @param data - Current form data
|
|
55
|
+
* @param spec - Form specification
|
|
56
|
+
* @returns Array of errors for this field
|
|
57
|
+
*/
|
|
58
|
+
export declare function validateSingleField(fieldPath: string, data: Record<string, unknown>, spec: Forma): FieldError[];
|
|
59
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/engine/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EACV,KAAK,EAIL,gBAAgB,EAChB,UAAU,EAEX,MAAM,aAAa,CAAC;AASrB,MAAM,WAAW,eAAe;IAC9B,qCAAqC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,gCAAgC;IAChC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,mDAAmD;IACnD,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,eAAoB,GAC5B,gBAAgB,CA6ClB;AA6eD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,GACV,UAAU,EAAE,CAqBd"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visibility Engine
|
|
3
|
+
*
|
|
4
|
+
* Determines which fields should be visible based on form data
|
|
5
|
+
* and Forma visibility rules.
|
|
6
|
+
*/
|
|
7
|
+
import type { Forma, VisibilityResult } from "../types.js";
|
|
8
|
+
export interface VisibilityOptions {
|
|
9
|
+
/** Pre-calculated computed values (avoids recalculation) */
|
|
10
|
+
computed?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Determine visibility for all fields in a form
|
|
14
|
+
*
|
|
15
|
+
* Returns a map of field paths to boolean visibility states.
|
|
16
|
+
* Fields without visibleWhen expressions are always visible.
|
|
17
|
+
*
|
|
18
|
+
* @param data - Current form data
|
|
19
|
+
* @param spec - Form specification
|
|
20
|
+
* @param options - Optional pre-calculated computed values
|
|
21
|
+
* @returns Map of field paths to visibility states
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const visibility = getVisibility(
|
|
25
|
+
* { age: 21, hasLicense: true },
|
|
26
|
+
* forma
|
|
27
|
+
* );
|
|
28
|
+
* // => { age: true, hasLicense: true, vehicleType: true, ... }
|
|
29
|
+
*/
|
|
30
|
+
export declare function getVisibility(data: Record<string, unknown>, spec: Forma, options?: VisibilityOptions): VisibilityResult;
|
|
31
|
+
/**
|
|
32
|
+
* Check if a single field is visible
|
|
33
|
+
*
|
|
34
|
+
* Useful for checking visibility of one field without computing all.
|
|
35
|
+
*
|
|
36
|
+
* @param fieldPath - Field path to check
|
|
37
|
+
* @param data - Current form data
|
|
38
|
+
* @param spec - Form specification
|
|
39
|
+
* @param options - Optional pre-calculated computed values
|
|
40
|
+
* @returns True if the field is visible
|
|
41
|
+
*/
|
|
42
|
+
export declare function isFieldVisible(fieldPath: string, data: Record<string, unknown>, spec: Forma, options?: VisibilityOptions): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Determine which pages are visible in a wizard form
|
|
45
|
+
*
|
|
46
|
+
* @param data - Current form data
|
|
47
|
+
* @param spec - Form specification with pages
|
|
48
|
+
* @param options - Optional pre-calculated computed values
|
|
49
|
+
* @returns Map of page IDs to visibility states
|
|
50
|
+
*/
|
|
51
|
+
export declare function getPageVisibility(data: Record<string, unknown>, spec: Forma, options?: VisibilityOptions): Record<string, boolean>;
|
|
52
|
+
//# sourceMappingURL=visibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.d.ts","sourceRoot":"","sources":["../../src/engine/visibility.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,KAAK,EAGL,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAOrB,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,iBAAsB,GAC9B,gBAAgB,CAsBlB;AA+ED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAkBT;AAMD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,IAAI,EAAE,KAAK,EACX,OAAO,GAAE,iBAAsB,GAC9B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAuBzB"}
|
package/dist/feel/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { F as FEELExpression, E as EvaluationContext } from '../types-Bs3CG9JZ.js';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* FEEL Expression Evaluator
|
|
5
3
|
*
|
|
@@ -14,17 +12,17 @@ import { F as FEELExpression, E as EvaluationContext } from '../types-Bs3CG9JZ.j
|
|
|
14
12
|
* - `itemIndex` - Current array item index (0-based)
|
|
15
13
|
* - `value` - Current field value (in validation expressions)
|
|
16
14
|
*/
|
|
17
|
-
|
|
18
|
-
interface EvaluateResult<T = unknown> {
|
|
15
|
+
import type { EvaluationContext, FEELExpression } from "../types.js";
|
|
16
|
+
export interface EvaluateResult<T = unknown> {
|
|
19
17
|
success: true;
|
|
20
18
|
value: T;
|
|
21
19
|
}
|
|
22
|
-
interface EvaluateError {
|
|
20
|
+
export interface EvaluateError {
|
|
23
21
|
success: false;
|
|
24
22
|
error: string;
|
|
25
23
|
expression: string;
|
|
26
24
|
}
|
|
27
|
-
type EvaluationOutcome<T = unknown> = EvaluateResult<T> | EvaluateError;
|
|
25
|
+
export type EvaluationOutcome<T = unknown> = EvaluateResult<T> | EvaluateError;
|
|
28
26
|
/**
|
|
29
27
|
* Evaluate a FEEL expression and return the result
|
|
30
28
|
*
|
|
@@ -47,7 +45,7 @@ type EvaluationOutcome<T = unknown> = EvaluateResult<T> | EvaluateError;
|
|
|
47
45
|
* evaluate("item.frequency = \"daily\"", { data: {}, item: { frequency: "daily" } })
|
|
48
46
|
* // => { success: true, value: true }
|
|
49
47
|
*/
|
|
50
|
-
declare function evaluate<T = unknown>(expression: FEELExpression, context: EvaluationContext): EvaluationOutcome<T>;
|
|
48
|
+
export declare function evaluate<T = unknown>(expression: FEELExpression, context: EvaluationContext): EvaluationOutcome<T>;
|
|
51
49
|
/**
|
|
52
50
|
* Evaluate a FEEL expression expecting a boolean result
|
|
53
51
|
*
|
|
@@ -58,7 +56,7 @@ declare function evaluate<T = unknown>(expression: FEELExpression, context: Eval
|
|
|
58
56
|
* @param context - Evaluation context
|
|
59
57
|
* @returns Boolean result (false on error)
|
|
60
58
|
*/
|
|
61
|
-
declare function evaluateBoolean(expression: FEELExpression, context: EvaluationContext): boolean;
|
|
59
|
+
export declare function evaluateBoolean(expression: FEELExpression, context: EvaluationContext): boolean;
|
|
62
60
|
/**
|
|
63
61
|
* Evaluate a FEEL expression expecting a numeric result
|
|
64
62
|
*
|
|
@@ -68,7 +66,7 @@ declare function evaluateBoolean(expression: FEELExpression, context: Evaluation
|
|
|
68
66
|
* @param context - Evaluation context
|
|
69
67
|
* @returns Numeric result or null on error
|
|
70
68
|
*/
|
|
71
|
-
declare function evaluateNumber(expression: FEELExpression, context: EvaluationContext): number | null;
|
|
69
|
+
export declare function evaluateNumber(expression: FEELExpression, context: EvaluationContext): number | null;
|
|
72
70
|
/**
|
|
73
71
|
* Evaluate a FEEL expression expecting a string result
|
|
74
72
|
*
|
|
@@ -76,7 +74,7 @@ declare function evaluateNumber(expression: FEELExpression, context: EvaluationC
|
|
|
76
74
|
* @param context - Evaluation context
|
|
77
75
|
* @returns String result or null on error
|
|
78
76
|
*/
|
|
79
|
-
declare function evaluateString(expression: FEELExpression, context: EvaluationContext): string | null;
|
|
77
|
+
export declare function evaluateString(expression: FEELExpression, context: EvaluationContext): string | null;
|
|
80
78
|
/**
|
|
81
79
|
* Evaluate multiple FEEL expressions at once
|
|
82
80
|
*
|
|
@@ -86,20 +84,19 @@ declare function evaluateString(expression: FEELExpression, context: EvaluationC
|
|
|
86
84
|
* @param context - Evaluation context
|
|
87
85
|
* @returns Map of field names to boolean results
|
|
88
86
|
*/
|
|
89
|
-
declare function evaluateBooleanBatch(expressions: Record<string, FEELExpression>, context: EvaluationContext): Record<string, boolean>;
|
|
87
|
+
export declare function evaluateBooleanBatch(expressions: Record<string, FEELExpression>, context: EvaluationContext): Record<string, boolean>;
|
|
90
88
|
/**
|
|
91
89
|
* Check if a FEEL expression is syntactically valid
|
|
92
90
|
*
|
|
93
91
|
* @param expression - FEEL expression to validate
|
|
94
92
|
* @returns True if the expression can be parsed
|
|
95
93
|
*/
|
|
96
|
-
declare function isValidExpression(expression: FEELExpression): boolean;
|
|
94
|
+
export declare function isValidExpression(expression: FEELExpression): boolean;
|
|
97
95
|
/**
|
|
98
96
|
* Validate a FEEL expression and return any parsing errors
|
|
99
97
|
*
|
|
100
98
|
* @param expression - FEEL expression to validate
|
|
101
99
|
* @returns Null if valid, error message if invalid
|
|
102
100
|
*/
|
|
103
|
-
declare function validateExpression(expression: FEELExpression): string | null;
|
|
104
|
-
|
|
105
|
-
export { type EvaluateError, type EvaluateResult, type EvaluationOutcome, evaluate, evaluateBoolean, evaluateBooleanBatch, evaluateNumber, evaluateString, isValidExpression, validateExpression };
|
|
101
|
+
export declare function validateExpression(expression: FEELExpression): string | null;
|
|
102
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/feel/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAMrE,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,OAAO,EAAE,IAAI,CAAC;IACd,KAAK,EAAE,CAAC,CAAC;CACV;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,KAAK,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,iBAAiB,CAAC,CAAC,GAAG,OAAO,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC;AAuD/E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,GAAG,OAAO,EAClC,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,iBAAiB,GACzB,iBAAiB,CAAC,CAAC,CAAC,CAetB;AAED;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAwBT;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,iBAAiB,GACzB,MAAM,GAAG,IAAI,CAkBf;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,cAAc,EAC1B,OAAO,EAAE,iBAAiB,GACzB,MAAM,GAAG,IAAI,CAkBf;AAMD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,EAC3C,OAAO,EAAE,iBAAiB,GACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQzB;AAMD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO,CASrE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,cAAc,GAAG,MAAM,GAAG,IAAI,CAc5E"}
|