form0-core 0.5.1 → 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/README.md +33 -0
- package/package.json +5 -3
- package/src/authoring/form-authoring.js +16 -26
- package/src/builtins/builtin-definitions.js +22 -0
- package/src/builtins/control/eval.js +11 -2
- package/src/builtins/registry.js +4 -0
- package/src/builtins/repeatable/repeatablesum.js +12 -0
- package/src/builtins/repeatable/repeatablevalues.js +12 -0
- package/src/engine/calculation.js +100 -37
- package/src/engine/condition-context.js +90 -0
- package/src/engine/conditions.js +59 -50
- package/src/engine/context-resolver.js +26 -10
- package/src/engine/evaluator.js +13 -5
- package/src/engine/event-source.js +37 -29
- package/src/engine/events.js +6 -2
- package/src/engine/form-engine.js +9 -7
- package/src/engine/managed-events.js +27 -9
- package/src/engine/record-context.js +126 -0
- package/src/engine/record-evaluator.js +657 -0
- package/src/engine/record-freshness.js +19 -0
- package/src/engine/submission-validation.js +125 -0
- package/src/engine/warning-system.js +4 -0
- package/src/index.js +3 -0
- package/src/schema/operators.js +2 -24
- package/src/schema/schema-validator.js +25 -20
- package/src/utilities/calculation-dependencies.js +2 -1
- package/src/utilities/calculation-editor.js +94 -1
- package/src/utilities/record-data.js +23 -0
- package/src/utilities/repeatable-collections.js +170 -0
- package/src/utilities/schema-revision.js +30 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function stableValue(value) {
|
|
2
|
+
if (Array.isArray(value)) return value.map(stableValue);
|
|
3
|
+
if (!value || typeof value !== 'object') return value;
|
|
4
|
+
return Object.fromEntries(
|
|
5
|
+
Object.keys(value)
|
|
6
|
+
.sort()
|
|
7
|
+
.map((key) => [key, stableValue(value[key])])
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function fnv1a64(input) {
|
|
12
|
+
let hash = 0xcbf29ce484222325n;
|
|
13
|
+
for (let index = 0; index < input.length; index += 1) {
|
|
14
|
+
hash ^= BigInt(input.charCodeAt(index));
|
|
15
|
+
hash = BigInt.asUintN(64, hash * 0x100000001b3n);
|
|
16
|
+
}
|
|
17
|
+
return hash.toString(16).padStart(16, '0');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Return a deterministic schema revision without importing authoring/editor modules. */
|
|
21
|
+
export function getFormSchemaRevision(schema) {
|
|
22
|
+
const root =
|
|
23
|
+
schema?.form && Array.isArray(schema.form.elements)
|
|
24
|
+
? schema
|
|
25
|
+
: schema && Array.isArray(schema.elements)
|
|
26
|
+
? { form: schema }
|
|
27
|
+
: null;
|
|
28
|
+
if (!root) throw new Error('Expected a root schema containing form.elements or a form schema');
|
|
29
|
+
return `form0-${fnv1a64(JSON.stringify(stableValue(root)))}`;
|
|
30
|
+
}
|