@fogpipe/forma-core 0.6.0 → 0.8.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.
@@ -1,105 +0,0 @@
1
- import { F as FEELExpression, E as EvaluationContext } from '../types-Bs3CG9JZ.cjs';
2
-
3
- /**
4
- * FEEL Expression Evaluator
5
- *
6
- * Wraps the feelin library to provide FEEL expression evaluation
7
- * with Forma context conventions.
8
- *
9
- * Context variable conventions:
10
- * - `fieldName` - Direct field value access
11
- * - `computed.name` - Computed value access
12
- * - `ref.path` - Reference data lookup (external lookup tables)
13
- * - `item.fieldName` - Array item field access (within array context)
14
- * - `itemIndex` - Current array item index (0-based)
15
- * - `value` - Current field value (in validation expressions)
16
- */
17
-
18
- interface EvaluateResult<T = unknown> {
19
- success: true;
20
- value: T;
21
- }
22
- interface EvaluateError {
23
- success: false;
24
- error: string;
25
- expression: string;
26
- }
27
- type EvaluationOutcome<T = unknown> = EvaluateResult<T> | EvaluateError;
28
- /**
29
- * Evaluate a FEEL expression and return the result
30
- *
31
- * @param expression - FEEL expression string
32
- * @param context - Evaluation context with form data, computed values, etc.
33
- * @returns Evaluation outcome with success/value or error
34
- *
35
- * @example
36
- * // Simple field comparison
37
- * evaluate("age >= 18", { data: { age: 21 } })
38
- * // => { success: true, value: true }
39
- *
40
- * @example
41
- * // Computed value reference
42
- * evaluate("computed.bmi > 30", { data: {}, computed: { bmi: 32.5 } })
43
- * // => { success: true, value: true }
44
- *
45
- * @example
46
- * // Array item context
47
- * evaluate("item.frequency = \"daily\"", { data: {}, item: { frequency: "daily" } })
48
- * // => { success: true, value: true }
49
- */
50
- declare function evaluate<T = unknown>(expression: FEELExpression, context: EvaluationContext): EvaluationOutcome<T>;
51
- /**
52
- * Evaluate a FEEL expression expecting a boolean result
53
- *
54
- * Used for visibility, required, and enabled conditions.
55
- * Returns false on error or non-boolean result for safety.
56
- *
57
- * @param expression - FEEL expression that should return boolean
58
- * @param context - Evaluation context
59
- * @returns Boolean result (false on error)
60
- */
61
- declare function evaluateBoolean(expression: FEELExpression, context: EvaluationContext): boolean;
62
- /**
63
- * Evaluate a FEEL expression expecting a numeric result
64
- *
65
- * Used for computed values that return numbers.
66
- *
67
- * @param expression - FEEL expression that should return number
68
- * @param context - Evaluation context
69
- * @returns Numeric result or null on error
70
- */
71
- declare function evaluateNumber(expression: FEELExpression, context: EvaluationContext): number | null;
72
- /**
73
- * Evaluate a FEEL expression expecting a string result
74
- *
75
- * @param expression - FEEL expression that should return string
76
- * @param context - Evaluation context
77
- * @returns String result or null on error
78
- */
79
- declare function evaluateString(expression: FEELExpression, context: EvaluationContext): string | null;
80
- /**
81
- * Evaluate multiple FEEL expressions at once
82
- *
83
- * Useful for evaluating all visibility conditions in a form.
84
- *
85
- * @param expressions - Map of field names to FEEL expressions
86
- * @param context - Evaluation context
87
- * @returns Map of field names to boolean results
88
- */
89
- declare function evaluateBooleanBatch(expressions: Record<string, FEELExpression>, context: EvaluationContext): Record<string, boolean>;
90
- /**
91
- * Check if a FEEL expression is syntactically valid
92
- *
93
- * @param expression - FEEL expression to validate
94
- * @returns True if the expression can be parsed
95
- */
96
- declare function isValidExpression(expression: FEELExpression): boolean;
97
- /**
98
- * Validate a FEEL expression and return any parsing errors
99
- *
100
- * @param expression - FEEL expression to validate
101
- * @returns Null if valid, error message if invalid
102
- */
103
- declare function validateExpression(expression: FEELExpression): string | null;
104
-
105
- export { type EvaluateError, type EvaluateResult, type EvaluationOutcome, evaluate, evaluateBoolean, evaluateBooleanBatch, evaluateNumber, evaluateString, isValidExpression, validateExpression };
package/dist/index.d.cts DELETED
@@ -1,3 +0,0 @@
1
- export { s as CalculationError, t as CalculationResult, C as ComputedField, p as EnabledResult, E as EvaluationContext, F as FEELExpression, k as FieldDefinition, q as FieldError, j as FieldType, l as FormMeta, m as Forma, J as JSONSchema, g as JSONSchemaArray, b as JSONSchemaBase, f as JSONSchemaBoolean, i as JSONSchemaEnum, e as JSONSchemaInteger, d as JSONSchemaNumber, h as JSONSchemaObject, a as JSONSchemaProperty, c as JSONSchemaString, P as PageDefinition, o as RequiredFieldsResult, R as RequiredResult, S as SelectOption, r as ValidationResult, V as ValidationRule, n as VisibilityResult } from './types-Bs3CG9JZ.cjs';
2
- export { EvaluateError, EvaluateResult, EvaluationOutcome, evaluate, evaluateBoolean, evaluateBooleanBatch, evaluateNumber, evaluateString, isValidExpression, validateExpression } from './feel/index.cjs';
3
- export { EnabledOptions, RequiredOptions, ValidateOptions, VisibilityOptions, calculate, calculateField, calculateWithErrors, getEnabled, getFormattedValue, getPageVisibility, getRequired, getVisibility, isEnabled, isFieldVisible, isRequired, validate, validateSingleField } from './engine/index.cjs';
@@ -1,283 +0,0 @@
1
- /**
2
- * Core Forma Type Definitions
3
- *
4
- * This module defines the complete type system for Forma specifications.
5
- * All conditional logic uses FEEL (Friendly Enough Expression Language).
6
- */
7
- /**
8
- * FEEL expression - a string that will be evaluated at runtime.
9
- *
10
- * Available context variables:
11
- * - `fieldName` - Any field value by name
12
- * - `computed.name` - Computed value by name
13
- * - `ref.path` - Reference data lookup (external lookup tables)
14
- * - `item.fieldName` - Field within current array item
15
- * - `itemIndex` - Current item index (0-based)
16
- * - `value` - Current field value (in validation expressions)
17
- *
18
- * @example
19
- * "age >= 18"
20
- * "claimType = \"Auto\" and wasDriver = true"
21
- * "computed.bmi > 30"
22
- * "item.frequency = \"daily\""
23
- */
24
- type FEELExpression = string;
25
- /**
26
- * Standard JSON Schema (subset we support)
27
- */
28
- interface JSONSchema {
29
- type: "object";
30
- properties: Record<string, JSONSchemaProperty>;
31
- required?: string[];
32
- $defs?: Record<string, JSONSchemaProperty>;
33
- }
34
- type JSONSchemaProperty = JSONSchemaString | JSONSchemaNumber | JSONSchemaInteger | JSONSchemaBoolean | JSONSchemaArray | JSONSchemaObject | JSONSchemaEnum;
35
- interface JSONSchemaBase {
36
- description?: string;
37
- title?: string;
38
- }
39
- interface JSONSchemaString extends JSONSchemaBase {
40
- type: "string";
41
- minLength?: number;
42
- maxLength?: number;
43
- pattern?: string;
44
- format?: "date" | "date-time" | "email" | "uri" | "uuid";
45
- enum?: string[];
46
- }
47
- interface JSONSchemaNumber extends JSONSchemaBase {
48
- type: "number";
49
- minimum?: number;
50
- maximum?: number;
51
- exclusiveMinimum?: number;
52
- exclusiveMaximum?: number;
53
- }
54
- interface JSONSchemaInteger extends JSONSchemaBase {
55
- type: "integer";
56
- minimum?: number;
57
- maximum?: number;
58
- }
59
- interface JSONSchemaBoolean extends JSONSchemaBase {
60
- type: "boolean";
61
- }
62
- interface JSONSchemaArray extends JSONSchemaBase {
63
- type: "array";
64
- items: JSONSchemaProperty;
65
- minItems?: number;
66
- maxItems?: number;
67
- }
68
- interface JSONSchemaObject extends JSONSchemaBase {
69
- type: "object";
70
- properties: Record<string, JSONSchemaProperty>;
71
- required?: string[];
72
- }
73
- interface JSONSchemaEnum extends JSONSchemaBase {
74
- type: "string";
75
- enum: string[];
76
- }
77
- /**
78
- * Field type enumeration - maps to UI component types
79
- */
80
- type FieldType = "text" | "password" | "number" | "integer" | "boolean" | "select" | "multiselect" | "date" | "datetime" | "email" | "url" | "textarea" | "array" | "object" | "computed";
81
- /**
82
- * Validation rule with FEEL expression
83
- */
84
- interface ValidationRule {
85
- /** FEEL expression that should evaluate to true for valid data */
86
- rule: FEELExpression;
87
- /** Error message shown when validation fails */
88
- message: string;
89
- /** Severity level - errors block submission, warnings are informational */
90
- severity?: "error" | "warning";
91
- }
92
- /**
93
- * Option for select/multiselect fields
94
- */
95
- interface SelectOption {
96
- /** Option value - can be string or number to match schema types */
97
- value: string | number;
98
- label: string;
99
- /** When to show this option */
100
- visibleWhen?: FEELExpression;
101
- }
102
- /**
103
- * Field definition with all conditional logic
104
- */
105
- interface FieldDefinition {
106
- /** Display label for the field */
107
- label?: string;
108
- /** Help text or description */
109
- description?: string;
110
- /** Placeholder text for input fields */
111
- placeholder?: string;
112
- /** Field type override (inferred from schema if not provided) */
113
- type?: FieldType;
114
- /** When to show this field. If omitted, always visible. */
115
- visibleWhen?: FEELExpression;
116
- /** When this field is required. If omitted, uses schema required. */
117
- requiredWhen?: FEELExpression;
118
- /** When this field is editable. If omitted, always enabled. */
119
- enabledWhen?: FEELExpression;
120
- /** Custom validation rules using FEEL expressions */
121
- validations?: ValidationRule[];
122
- /** For array fields: field definitions for each item. Requires type: "array" */
123
- itemFields?: Record<string, FieldDefinition>;
124
- /** Minimum number of items (overrides schema) */
125
- minItems?: number;
126
- /** Maximum number of items (overrides schema) */
127
- maxItems?: number;
128
- /** For select fields: available options */
129
- options?: SelectOption[];
130
- }
131
- /**
132
- * Computed field definition - derived values from form data
133
- */
134
- interface ComputedField {
135
- /** FEEL expression to calculate the value */
136
- expression: FEELExpression;
137
- /** Display label */
138
- label?: string;
139
- /** Display format (e.g., "decimal(1)", "currency", "percent") */
140
- format?: string;
141
- /** Whether to display this value in the form */
142
- display?: boolean;
143
- }
144
- /**
145
- * Page definition for multi-step wizard forms
146
- */
147
- interface PageDefinition {
148
- /** Unique page identifier */
149
- id: string;
150
- /** Page title */
151
- title: string;
152
- /** Page description/instructions */
153
- description?: string;
154
- /** When to show this page */
155
- visibleWhen?: FEELExpression;
156
- /** Field paths to include on this page */
157
- fields: string[];
158
- }
159
- /**
160
- * Form metadata
161
- */
162
- interface FormMeta {
163
- /** Unique form identifier */
164
- id: string;
165
- /** Form title */
166
- title: string;
167
- /** Form description */
168
- description?: string;
169
- /** Form version */
170
- version?: string;
171
- }
172
- /**
173
- * Complete Form Specification
174
- *
175
- * This is the root type that defines an entire form including:
176
- * - Data schema (JSON Schema)
177
- * - Computed values
178
- * - Reference data (lookup tables for calculations)
179
- * - Field-level configuration and conditional logic
180
- * - Field ordering
181
- * - Optional wizard/page structure
182
- */
183
- interface Forma {
184
- /** Schema version identifier */
185
- $schema?: string;
186
- /** Spec version */
187
- version: "1.0";
188
- /** Form metadata */
189
- meta: FormMeta;
190
- /** JSON Schema defining the data structure */
191
- schema: JSONSchema;
192
- /** Computed/calculated values */
193
- computed?: Record<string, ComputedField>;
194
- /** Reference data for lookups (external data sources, lookup tables) */
195
- referenceData?: Record<string, unknown>;
196
- /** Field-level definitions and rules */
197
- fields: Record<string, FieldDefinition>;
198
- /** Order in which fields should be displayed */
199
- fieldOrder: string[];
200
- /** Optional multi-page wizard structure */
201
- pages?: PageDefinition[];
202
- }
203
- /**
204
- * Context provided when evaluating FEEL expressions
205
- */
206
- interface EvaluationContext {
207
- /** Current form data */
208
- data: Record<string, unknown>;
209
- /** Computed values (calculated before field evaluation) */
210
- computed?: Record<string, unknown>;
211
- /** Reference data for lookups (external data sources, lookup tables) */
212
- referenceData?: Record<string, unknown>;
213
- /** Current array item (when evaluating within array context) */
214
- item?: Record<string, unknown>;
215
- /** Current array item index (0-based) */
216
- itemIndex?: number;
217
- /** Current field value (for validation expressions) */
218
- value?: unknown;
219
- }
220
- /**
221
- * Field visibility result - map of field path to visibility state
222
- */
223
- interface VisibilityResult {
224
- [fieldPath: string]: boolean;
225
- }
226
- /**
227
- * Required fields result - map of field path to required state
228
- */
229
- interface RequiredResult {
230
- [fieldPath: string]: boolean;
231
- }
232
- /**
233
- * Alias for RequiredResult (backwards compatibility)
234
- */
235
- type RequiredFieldsResult = RequiredResult;
236
- /**
237
- * Enabled fields result - map of field path to enabled state
238
- */
239
- interface EnabledResult {
240
- [fieldPath: string]: boolean;
241
- }
242
- /**
243
- * Field validation error
244
- */
245
- interface FieldError {
246
- /** Field path that has the error */
247
- field: string;
248
- /** Error message */
249
- message: string;
250
- /** Error severity */
251
- severity: "error" | "warning";
252
- }
253
- /**
254
- * Validation result
255
- */
256
- interface ValidationResult {
257
- /** Whether the form data is valid */
258
- valid: boolean;
259
- /** List of validation errors */
260
- errors: FieldError[];
261
- }
262
- /**
263
- * Calculation error
264
- */
265
- interface CalculationError {
266
- /** Computed field name */
267
- field: string;
268
- /** Error message */
269
- message: string;
270
- /** The expression that failed */
271
- expression: string;
272
- }
273
- /**
274
- * Calculation result with potential errors
275
- */
276
- interface CalculationResult {
277
- /** Computed values */
278
- values: Record<string, unknown>;
279
- /** Errors encountered during calculation */
280
- errors: CalculationError[];
281
- }
282
-
283
- export type { ComputedField as C, EvaluationContext as E, FEELExpression as F, JSONSchema as J, PageDefinition as P, RequiredResult as R, SelectOption as S, ValidationRule as V, JSONSchemaProperty as a, JSONSchemaBase as b, JSONSchemaString as c, JSONSchemaNumber as d, JSONSchemaInteger as e, JSONSchemaBoolean as f, JSONSchemaArray as g, JSONSchemaObject as h, JSONSchemaEnum as i, FieldType as j, FieldDefinition as k, FormMeta as l, Forma as m, VisibilityResult as n, RequiredFieldsResult as o, EnabledResult as p, FieldError as q, ValidationResult as r, CalculationError as s, CalculationResult as t };