@json-eval-rs/webcore 0.0.55 → 0.0.57
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/index.d.ts +55 -25
- package/dist/index.js +84 -43
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,15 @@
|
|
|
10
10
|
* @returns Version string
|
|
11
11
|
*/
|
|
12
12
|
export declare function getVersion(wasmModule: any): string;
|
|
13
|
+
/**
|
|
14
|
+
* Item for get schema value array results
|
|
15
|
+
*/
|
|
16
|
+
export interface SchemaValueItem {
|
|
17
|
+
/** Dotted path (e.g., "field1.field2") */
|
|
18
|
+
path: string;
|
|
19
|
+
/** Value at this path */
|
|
20
|
+
value: any;
|
|
21
|
+
}
|
|
13
22
|
/**
|
|
14
23
|
* Return format for path-based methods
|
|
15
24
|
*/
|
|
@@ -46,8 +55,8 @@ export interface ValidationError {
|
|
|
46
55
|
export interface ValidationResult {
|
|
47
56
|
/** Whether any validation errors occurred */
|
|
48
57
|
has_error: boolean;
|
|
49
|
-
/**
|
|
50
|
-
|
|
58
|
+
/** Map of validation errors keyed by field path */
|
|
59
|
+
error: Record<string, ValidationError>;
|
|
51
60
|
}
|
|
52
61
|
/**
|
|
53
62
|
* Dependent field change from evaluateDependents
|
|
@@ -386,7 +395,7 @@ export declare class JSONEvalCore {
|
|
|
386
395
|
* Validate data against schema (returns parsed JavaScript object)
|
|
387
396
|
* Uses validateJS for Worker-safe serialization
|
|
388
397
|
*/
|
|
389
|
-
validate({ data, context }: ValidateOptions): Promise<ValidationResult>;
|
|
398
|
+
validate({ data, context, }: ValidateOptions): Promise<ValidationResult>;
|
|
390
399
|
/**
|
|
391
400
|
* Evaluate schema with data (returns parsed JavaScript object)
|
|
392
401
|
*/
|
|
@@ -394,32 +403,42 @@ export declare class JSONEvalCore {
|
|
|
394
403
|
/**
|
|
395
404
|
* Evaluate dependent fields (returns parsed JavaScript object, processes transitively)
|
|
396
405
|
*/
|
|
397
|
-
evaluateDependents({ changedPaths, data, context, reEvaluate }: EvaluateDependentsOptions): Promise<DependentChange[]>;
|
|
406
|
+
evaluateDependents({ changedPaths, data, context, reEvaluate, }: EvaluateDependentsOptions): Promise<DependentChange[]>;
|
|
398
407
|
/**
|
|
399
408
|
* Get evaluated schema
|
|
400
409
|
*/
|
|
401
|
-
getEvaluatedSchema({ skipLayout }?: GetEvaluatedSchemaOptions): Promise<any>;
|
|
410
|
+
getEvaluatedSchema({ skipLayout, }?: GetEvaluatedSchemaOptions): Promise<any>;
|
|
402
411
|
/**
|
|
403
412
|
* Get evaluated schema as MessagePack binary data
|
|
404
413
|
*/
|
|
405
|
-
getEvaluatedSchemaMsgpack({ skipLayout }?: GetEvaluatedSchemaOptions): Promise<Uint8Array>;
|
|
414
|
+
getEvaluatedSchemaMsgpack({ skipLayout, }?: GetEvaluatedSchemaOptions): Promise<Uint8Array>;
|
|
406
415
|
/**
|
|
407
416
|
* Get schema values (evaluations ending with .value)
|
|
408
417
|
*/
|
|
409
418
|
getSchemaValue(): Promise<any>;
|
|
419
|
+
/**
|
|
420
|
+
* Get all schema values as array of path-value pairs
|
|
421
|
+
* Returns [{path: "", value: ""}, ...]
|
|
422
|
+
*/
|
|
423
|
+
getSchemaValueArray(): Promise<SchemaValueItem[]>;
|
|
424
|
+
/**
|
|
425
|
+
* Get all schema values as object with dotted path keys
|
|
426
|
+
* Returns {path: value, ...}
|
|
427
|
+
*/
|
|
428
|
+
getSchemaValueObject(): Promise<Record<string, any>>;
|
|
410
429
|
/**
|
|
411
430
|
* Get evaluated schema without $params field
|
|
412
431
|
*/
|
|
413
|
-
getEvaluatedSchemaWithoutParams({ skipLayout }?: GetEvaluatedSchemaOptions): Promise<any>;
|
|
432
|
+
getEvaluatedSchemaWithoutParams({ skipLayout, }?: GetEvaluatedSchemaOptions): Promise<any>;
|
|
414
433
|
/**
|
|
415
434
|
* Get a value from the evaluated schema using dotted path notation
|
|
416
435
|
*/
|
|
417
|
-
getEvaluatedSchemaByPath({ path, skipLayout }: GetValueByPathOptions): Promise<any | null>;
|
|
436
|
+
getEvaluatedSchemaByPath({ path, skipLayout, }: GetValueByPathOptions): Promise<any | null>;
|
|
418
437
|
/**
|
|
419
438
|
* Get values from the evaluated schema using multiple dotted path notations
|
|
420
439
|
* Returns data in the specified format (skips paths that are not found)
|
|
421
440
|
*/
|
|
422
|
-
getEvaluatedSchemaByPaths({ paths, skipLayout, format }: GetValueByPathsOptions): Promise<any>;
|
|
441
|
+
getEvaluatedSchemaByPaths({ paths, skipLayout, format, }: GetValueByPathsOptions): Promise<any>;
|
|
423
442
|
/**
|
|
424
443
|
* Get a value from the schema using dotted path notation
|
|
425
444
|
*/
|
|
@@ -428,11 +447,11 @@ export declare class JSONEvalCore {
|
|
|
428
447
|
* Get values from the schema using multiple dotted path notations
|
|
429
448
|
* Returns data in the specified format (skips paths that are not found)
|
|
430
449
|
*/
|
|
431
|
-
getSchemaByPaths({ paths, format }: GetSchemaByPathsOptions): Promise<any>;
|
|
450
|
+
getSchemaByPaths({ paths, format, }: GetSchemaByPathsOptions): Promise<any>;
|
|
432
451
|
/**
|
|
433
452
|
* Reload schema with new data
|
|
434
453
|
*/
|
|
435
|
-
reloadSchema({ schema, context, data }: ReloadSchemaOptions): Promise<void>;
|
|
454
|
+
reloadSchema({ schema, context, data, }: ReloadSchemaOptions): Promise<void>;
|
|
436
455
|
/**
|
|
437
456
|
* Reload schema from MessagePack bytes
|
|
438
457
|
*/
|
|
@@ -481,7 +500,7 @@ export declare class JSONEvalCore {
|
|
|
481
500
|
/**
|
|
482
501
|
* Compile and run JSON logic from a JSON logic string
|
|
483
502
|
*/
|
|
484
|
-
compileAndRunLogic({ logicStr, data, context }: CompileAndRunLogicOptions): Promise<any>;
|
|
503
|
+
compileAndRunLogic({ logicStr, data, context, }: CompileAndRunLogicOptions): Promise<any>;
|
|
485
504
|
/**
|
|
486
505
|
* Compile JSON logic and return a global ID
|
|
487
506
|
*/
|
|
@@ -493,7 +512,7 @@ export declare class JSONEvalCore {
|
|
|
493
512
|
/**
|
|
494
513
|
* Validate data against schema rules with optional path filtering
|
|
495
514
|
*/
|
|
496
|
-
validatePaths({ data, context, paths }: EvaluateOptions): Promise<ValidationResult>;
|
|
515
|
+
validatePaths({ data, context, paths, }: EvaluateOptions): Promise<ValidationResult>;
|
|
497
516
|
/**
|
|
498
517
|
* Cancel any running evaluation
|
|
499
518
|
*/
|
|
@@ -501,40 +520,51 @@ export declare class JSONEvalCore {
|
|
|
501
520
|
/**
|
|
502
521
|
* Evaluate a subform with data
|
|
503
522
|
*/
|
|
504
|
-
evaluateSubform({ subformPath, data, context, paths }: EvaluateSubformOptions): Promise<void>;
|
|
523
|
+
evaluateSubform({ subformPath, data, context, paths, }: EvaluateSubformOptions): Promise<void>;
|
|
505
524
|
/**
|
|
506
525
|
* Validate subform data against its schema rules
|
|
507
526
|
*/
|
|
508
|
-
validateSubform({ subformPath, data, context }: ValidateSubformOptions): Promise<ValidationResult>;
|
|
527
|
+
validateSubform({ subformPath, data, context, }: ValidateSubformOptions): Promise<ValidationResult>;
|
|
509
528
|
/**
|
|
510
529
|
* Evaluate dependent fields in subform
|
|
511
530
|
*/
|
|
512
|
-
evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate }: EvaluateDependentsSubformOptions): Promise<DependentChange[]>;
|
|
531
|
+
evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate, }: EvaluateDependentsSubformOptions): Promise<DependentChange[]>;
|
|
513
532
|
/**
|
|
514
533
|
* Resolve layout for subform
|
|
515
534
|
*/
|
|
516
|
-
resolveLayoutSubform({ subformPath, evaluate }: ResolveLayoutSubformOptions): Promise<void>;
|
|
535
|
+
resolveLayoutSubform({ subformPath, evaluate, }: ResolveLayoutSubformOptions): Promise<void>;
|
|
517
536
|
/**
|
|
518
537
|
* Get evaluated schema from subform
|
|
519
538
|
*/
|
|
520
|
-
getEvaluatedSchemaSubform({ subformPath, resolveLayout }: GetEvaluatedSchemaSubformOptions): Promise<any>;
|
|
539
|
+
getEvaluatedSchemaSubform({ subformPath, resolveLayout, }: GetEvaluatedSchemaSubformOptions): Promise<any>;
|
|
540
|
+
/**
|
|
541
|
+
* Get schema value from subform in nested object format (all .value fields).
|
|
542
|
+
* Returns a hierarchical object structure mimicking the schema.
|
|
543
|
+
*/
|
|
544
|
+
getSchemaValueSubform({ subformPath, }: GetSchemaValueSubformOptions): Promise<any>;
|
|
545
|
+
/**
|
|
546
|
+
* Get schema values from subform as a flat array of path-value pairs.
|
|
547
|
+
* Returns an array like `[{path: "field.sub", value: 123}, ...]`.
|
|
548
|
+
*/
|
|
549
|
+
getSchemaValueArraySubform({ subformPath, }: GetSchemaValueSubformOptions): Promise<SchemaValueItem[]>;
|
|
521
550
|
/**
|
|
522
|
-
* Get schema
|
|
551
|
+
* Get schema values from subform as a flat object with dotted path keys.
|
|
552
|
+
* Returns an object like `{"field.sub": 123, ...}`.
|
|
523
553
|
*/
|
|
524
|
-
|
|
554
|
+
getSchemaValueObjectSubform({ subformPath, }: GetSchemaValueSubformOptions): Promise<Record<string, any>>;
|
|
525
555
|
/**
|
|
526
556
|
* Get evaluated schema without $params from subform
|
|
527
557
|
*/
|
|
528
|
-
getEvaluatedSchemaWithoutParamsSubform({ subformPath, resolveLayout }: GetEvaluatedSchemaSubformOptions): Promise<any>;
|
|
558
|
+
getEvaluatedSchemaWithoutParamsSubform({ subformPath, resolveLayout, }: GetEvaluatedSchemaSubformOptions): Promise<any>;
|
|
529
559
|
/**
|
|
530
560
|
* Get evaluated schema by specific path from subform
|
|
531
561
|
*/
|
|
532
|
-
getEvaluatedSchemaByPathSubform({ subformPath, schemaPath, skipLayout }: GetEvaluatedSchemaByPathSubformOptions): Promise<any | null>;
|
|
562
|
+
getEvaluatedSchemaByPathSubform({ subformPath, schemaPath, skipLayout, }: GetEvaluatedSchemaByPathSubformOptions): Promise<any | null>;
|
|
533
563
|
/**
|
|
534
564
|
* Get evaluated schema by multiple paths from subform
|
|
535
565
|
* Returns data in the specified format (skips paths that are not found)
|
|
536
566
|
*/
|
|
537
|
-
getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout, format }: GetEvaluatedSchemaByPathsSubformOptions): Promise<any>;
|
|
567
|
+
getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout, format, }: GetEvaluatedSchemaByPathsSubformOptions): Promise<any>;
|
|
538
568
|
/**
|
|
539
569
|
* Get list of available subform paths
|
|
540
570
|
*/
|
|
@@ -542,12 +572,12 @@ export declare class JSONEvalCore {
|
|
|
542
572
|
/**
|
|
543
573
|
* Get schema by specific path from subform
|
|
544
574
|
*/
|
|
545
|
-
getSchemaByPathSubform({ subformPath, schemaPath }: GetSchemaByPathSubformOptions): Promise<any | null>;
|
|
575
|
+
getSchemaByPathSubform({ subformPath, schemaPath, }: GetSchemaByPathSubformOptions): Promise<any | null>;
|
|
546
576
|
/**
|
|
547
577
|
* Get schema by multiple paths from subform
|
|
548
578
|
* Returns data in the specified format (skips paths that are not found)
|
|
549
579
|
*/
|
|
550
|
-
getSchemaByPathsSubform({ subformPath, schemaPaths, format }: GetSchemaByPathsSubformOptions): Promise<any>;
|
|
580
|
+
getSchemaByPathsSubform({ subformPath, schemaPaths, format, }: GetSchemaByPathsSubformOptions): Promise<any>;
|
|
551
581
|
/**
|
|
552
582
|
* Check if a subform exists at the given path
|
|
553
583
|
*/
|
package/dist/index.js
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
* @returns Version string
|
|
11
11
|
*/
|
|
12
12
|
export function getVersion(wasmModule) {
|
|
13
|
-
if (wasmModule && typeof wasmModule.getVersion ===
|
|
13
|
+
if (wasmModule && typeof wasmModule.getVersion === "function") {
|
|
14
14
|
return wasmModule.getVersion();
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return "unknown";
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Return format for path-based methods
|
|
@@ -78,9 +78,9 @@ export class JSONEvalCore {
|
|
|
78
78
|
return;
|
|
79
79
|
// If WASM module not provided, throw error - user must provide it or install peer dependency
|
|
80
80
|
if (!this._wasmModule) {
|
|
81
|
-
throw new Error(
|
|
81
|
+
throw new Error("No WASM module provided. Please either:\n" +
|
|
82
82
|
'1. Pass wasmModule in constructor: new JSONEval({ schema, wasmModule: await import("@json-eval-rs/bundler") })\n' +
|
|
83
|
-
|
|
83
|
+
"2. Or install a peer dependency: yarn install @json-eval-rs/bundler (or @json-eval-rs/vanilla or @json-eval-rs/node)");
|
|
84
84
|
}
|
|
85
85
|
try {
|
|
86
86
|
const { JSONEvalWasm } = this._wasmModule;
|
|
@@ -116,7 +116,7 @@ export class JSONEvalCore {
|
|
|
116
116
|
schema: cacheKey,
|
|
117
117
|
context,
|
|
118
118
|
data,
|
|
119
|
-
fromCache: true
|
|
119
|
+
fromCache: true,
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
@@ -130,22 +130,30 @@ export class JSONEvalCore {
|
|
|
130
130
|
*/
|
|
131
131
|
static evaluateLogic(wasmModule, logicStr, data, context) {
|
|
132
132
|
if (!wasmModule) {
|
|
133
|
-
throw new Error(
|
|
133
|
+
throw new Error("No WASM module provided.");
|
|
134
134
|
}
|
|
135
135
|
const { JSONEvalWasm } = wasmModule;
|
|
136
|
-
if (!JSONEvalWasm || typeof JSONEvalWasm.evaluateLogic !==
|
|
137
|
-
throw new Error(
|
|
136
|
+
if (!JSONEvalWasm || typeof JSONEvalWasm.evaluateLogic !== "function") {
|
|
137
|
+
throw new Error("WASM module does not support evaluateLogic.");
|
|
138
138
|
}
|
|
139
|
-
const logic = typeof logicStr ===
|
|
140
|
-
const dataStr = data
|
|
141
|
-
|
|
139
|
+
const logic = typeof logicStr === "string" ? logicStr : JSON.stringify(logicStr);
|
|
140
|
+
const dataStr = data
|
|
141
|
+
? typeof data === "string"
|
|
142
|
+
? data
|
|
143
|
+
: JSON.stringify(data)
|
|
144
|
+
: null;
|
|
145
|
+
const contextStr = context
|
|
146
|
+
? typeof context === "string"
|
|
147
|
+
? context
|
|
148
|
+
: JSON.stringify(context)
|
|
149
|
+
: null;
|
|
142
150
|
return JSONEvalWasm.evaluateLogic(logic, dataStr, contextStr);
|
|
143
151
|
}
|
|
144
152
|
/**
|
|
145
153
|
* Validate data against schema (returns parsed JavaScript object)
|
|
146
154
|
* Uses validateJS for Worker-safe serialization
|
|
147
155
|
*/
|
|
148
|
-
async validate({ data, context }) {
|
|
156
|
+
async validate({ data, context, }) {
|
|
149
157
|
await this.init();
|
|
150
158
|
try {
|
|
151
159
|
// Use validateJS for proper serialization (Worker-safe)
|
|
@@ -170,7 +178,7 @@ export class JSONEvalCore {
|
|
|
170
178
|
/**
|
|
171
179
|
* Evaluate dependent fields (returns parsed JavaScript object, processes transitively)
|
|
172
180
|
*/
|
|
173
|
-
async evaluateDependents({ changedPaths, data, context, reEvaluate = true }) {
|
|
181
|
+
async evaluateDependents({ changedPaths, data, context, reEvaluate = true, }) {
|
|
174
182
|
await this.init();
|
|
175
183
|
try {
|
|
176
184
|
// Ensure paths is an array for WASM
|
|
@@ -184,14 +192,14 @@ export class JSONEvalCore {
|
|
|
184
192
|
/**
|
|
185
193
|
* Get evaluated schema
|
|
186
194
|
*/
|
|
187
|
-
async getEvaluatedSchema({ skipLayout = false } = {}) {
|
|
195
|
+
async getEvaluatedSchema({ skipLayout = false, } = {}) {
|
|
188
196
|
await this.init();
|
|
189
197
|
return this._instance.getEvaluatedSchemaJS(skipLayout);
|
|
190
198
|
}
|
|
191
199
|
/**
|
|
192
200
|
* Get evaluated schema as MessagePack binary data
|
|
193
201
|
*/
|
|
194
|
-
async getEvaluatedSchemaMsgpack({ skipLayout = false } = {}) {
|
|
202
|
+
async getEvaluatedSchemaMsgpack({ skipLayout = false, } = {}) {
|
|
195
203
|
await this.init();
|
|
196
204
|
return this._instance.getEvaluatedSchemaMsgpack(skipLayout);
|
|
197
205
|
}
|
|
@@ -202,17 +210,33 @@ export class JSONEvalCore {
|
|
|
202
210
|
await this.init();
|
|
203
211
|
return this._instance.getSchemaValue();
|
|
204
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Get all schema values as array of path-value pairs
|
|
215
|
+
* Returns [{path: "", value: ""}, ...]
|
|
216
|
+
*/
|
|
217
|
+
async getSchemaValueArray() {
|
|
218
|
+
await this.init();
|
|
219
|
+
return this._instance.getSchemaValueArray();
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get all schema values as object with dotted path keys
|
|
223
|
+
* Returns {path: value, ...}
|
|
224
|
+
*/
|
|
225
|
+
async getSchemaValueObject() {
|
|
226
|
+
await this.init();
|
|
227
|
+
return this._instance.getSchemaValueObject();
|
|
228
|
+
}
|
|
205
229
|
/**
|
|
206
230
|
* Get evaluated schema without $params field
|
|
207
231
|
*/
|
|
208
|
-
async getEvaluatedSchemaWithoutParams({ skipLayout = false } = {}) {
|
|
232
|
+
async getEvaluatedSchemaWithoutParams({ skipLayout = false, } = {}) {
|
|
209
233
|
await this.init();
|
|
210
234
|
return this._instance.getEvaluatedSchemaWithoutParamsJS(skipLayout);
|
|
211
235
|
}
|
|
212
236
|
/**
|
|
213
237
|
* Get a value from the evaluated schema using dotted path notation
|
|
214
238
|
*/
|
|
215
|
-
async getEvaluatedSchemaByPath({ path, skipLayout = false }) {
|
|
239
|
+
async getEvaluatedSchemaByPath({ path, skipLayout = false, }) {
|
|
216
240
|
await this.init();
|
|
217
241
|
return this._instance.getEvaluatedSchemaByPathJS(path, skipLayout);
|
|
218
242
|
}
|
|
@@ -220,7 +244,7 @@ export class JSONEvalCore {
|
|
|
220
244
|
* Get values from the evaluated schema using multiple dotted path notations
|
|
221
245
|
* Returns data in the specified format (skips paths that are not found)
|
|
222
246
|
*/
|
|
223
|
-
async getEvaluatedSchemaByPaths({ paths, skipLayout = false, format = 0 }) {
|
|
247
|
+
async getEvaluatedSchemaByPaths({ paths, skipLayout = false, format = 0, }) {
|
|
224
248
|
await this.init();
|
|
225
249
|
return this._instance.getEvaluatedSchemaByPathsJS(JSON.stringify(paths), skipLayout, format);
|
|
226
250
|
}
|
|
@@ -235,16 +259,16 @@ export class JSONEvalCore {
|
|
|
235
259
|
* Get values from the schema using multiple dotted path notations
|
|
236
260
|
* Returns data in the specified format (skips paths that are not found)
|
|
237
261
|
*/
|
|
238
|
-
async getSchemaByPaths({ paths, format = 0 }) {
|
|
262
|
+
async getSchemaByPaths({ paths, format = 0, }) {
|
|
239
263
|
await this.init();
|
|
240
264
|
return this._instance.getSchemaByPathsJS(JSON.stringify(paths), format);
|
|
241
265
|
}
|
|
242
266
|
/**
|
|
243
267
|
* Reload schema with new data
|
|
244
268
|
*/
|
|
245
|
-
async reloadSchema({ schema, context, data }) {
|
|
269
|
+
async reloadSchema({ schema, context, data, }) {
|
|
246
270
|
if (!this._instance) {
|
|
247
|
-
throw new Error(
|
|
271
|
+
throw new Error("Instance not initialized. Call init() first.");
|
|
248
272
|
}
|
|
249
273
|
try {
|
|
250
274
|
await this._instance.reloadSchema(JSON.stringify(schema), context ? JSON.stringify(context) : null, data ? JSON.stringify(data) : null);
|
|
@@ -262,10 +286,10 @@ export class JSONEvalCore {
|
|
|
262
286
|
*/
|
|
263
287
|
async reloadSchemaMsgpack(schemaMsgpack, context, data) {
|
|
264
288
|
if (!this._instance) {
|
|
265
|
-
throw new Error(
|
|
289
|
+
throw new Error("Instance not initialized. Call init() first.");
|
|
266
290
|
}
|
|
267
291
|
if (!(schemaMsgpack instanceof Uint8Array)) {
|
|
268
|
-
throw new Error(
|
|
292
|
+
throw new Error("schemaMsgpack must be a Uint8Array");
|
|
269
293
|
}
|
|
270
294
|
try {
|
|
271
295
|
await this._instance.reloadSchemaMsgpack(schemaMsgpack, context ? JSON.stringify(context) : null, data ? JSON.stringify(data) : null);
|
|
@@ -284,10 +308,10 @@ export class JSONEvalCore {
|
|
|
284
308
|
*/
|
|
285
309
|
async reloadSchemaFromCache(cacheKey, context, data) {
|
|
286
310
|
if (!this._instance) {
|
|
287
|
-
throw new Error(
|
|
311
|
+
throw new Error("Instance not initialized. Call init() first.");
|
|
288
312
|
}
|
|
289
|
-
if (typeof cacheKey !==
|
|
290
|
-
throw new Error(
|
|
313
|
+
if (typeof cacheKey !== "string" || !cacheKey) {
|
|
314
|
+
throw new Error("cacheKey must be a non-empty string");
|
|
291
315
|
}
|
|
292
316
|
try {
|
|
293
317
|
await this._instance.reloadSchemaFromCache(cacheKey, context ? JSON.stringify(context) : null, data ? JSON.stringify(data) : null);
|
|
@@ -359,16 +383,16 @@ export class JSONEvalCore {
|
|
|
359
383
|
*/
|
|
360
384
|
setTimezoneOffset(offsetMinutes) {
|
|
361
385
|
if (!this._instance) {
|
|
362
|
-
throw new Error(
|
|
386
|
+
throw new Error("Instance not initialized. Call init() first.");
|
|
363
387
|
}
|
|
364
388
|
this._instance.setTimezoneOffset(offsetMinutes);
|
|
365
389
|
}
|
|
366
390
|
/**
|
|
367
391
|
* Compile and run JSON logic from a JSON logic string
|
|
368
392
|
*/
|
|
369
|
-
async compileAndRunLogic({ logicStr, data, context }) {
|
|
393
|
+
async compileAndRunLogic({ logicStr, data, context, }) {
|
|
370
394
|
await this.init();
|
|
371
|
-
const logic = typeof logicStr ===
|
|
395
|
+
const logic = typeof logicStr === "string" ? logicStr : JSON.stringify(logicStr);
|
|
372
396
|
const result = await this._instance.compileAndRunLogic(logic, data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null);
|
|
373
397
|
return result;
|
|
374
398
|
}
|
|
@@ -377,7 +401,7 @@ export class JSONEvalCore {
|
|
|
377
401
|
*/
|
|
378
402
|
async compileLogic(logicStr) {
|
|
379
403
|
await this.init();
|
|
380
|
-
const logic = typeof logicStr ===
|
|
404
|
+
const logic = typeof logicStr === "string" ? logicStr : JSON.stringify(logicStr);
|
|
381
405
|
return this._instance.compileLogic(logic);
|
|
382
406
|
}
|
|
383
407
|
/**
|
|
@@ -391,7 +415,7 @@ export class JSONEvalCore {
|
|
|
391
415
|
/**
|
|
392
416
|
* Validate data against schema rules with optional path filtering
|
|
393
417
|
*/
|
|
394
|
-
async validatePaths({ data, context, paths }) {
|
|
418
|
+
async validatePaths({ data, context, paths, }) {
|
|
395
419
|
await this.init();
|
|
396
420
|
try {
|
|
397
421
|
// Use validatePathsJS for proper serialization (Worker-safe)
|
|
@@ -415,21 +439,21 @@ export class JSONEvalCore {
|
|
|
415
439
|
/**
|
|
416
440
|
* Evaluate a subform with data
|
|
417
441
|
*/
|
|
418
|
-
async evaluateSubform({ subformPath, data, context, paths }) {
|
|
442
|
+
async evaluateSubform({ subformPath, data, context, paths, }) {
|
|
419
443
|
await this.init();
|
|
420
444
|
return this._instance.evaluateSubform(subformPath, JSON.stringify(data), context ? JSON.stringify(context) : null, paths || null);
|
|
421
445
|
}
|
|
422
446
|
/**
|
|
423
447
|
* Validate subform data against its schema rules
|
|
424
448
|
*/
|
|
425
|
-
async validateSubform({ subformPath, data, context }) {
|
|
449
|
+
async validateSubform({ subformPath, data, context, }) {
|
|
426
450
|
await this.init();
|
|
427
451
|
return this._instance.validateSubform(subformPath, JSON.stringify(data), context ? JSON.stringify(context) : null);
|
|
428
452
|
}
|
|
429
453
|
/**
|
|
430
454
|
* Evaluate dependent fields in subform
|
|
431
455
|
*/
|
|
432
|
-
async evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate = true }) {
|
|
456
|
+
async evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate = true, }) {
|
|
433
457
|
await this.init();
|
|
434
458
|
// For backward compatibility, accept single changedPath too (though types say array)
|
|
435
459
|
const paths = Array.isArray(changedPaths) ? changedPaths : [changedPaths];
|
|
@@ -438,35 +462,52 @@ export class JSONEvalCore {
|
|
|
438
462
|
/**
|
|
439
463
|
* Resolve layout for subform
|
|
440
464
|
*/
|
|
441
|
-
async resolveLayoutSubform({ subformPath, evaluate = false }) {
|
|
465
|
+
async resolveLayoutSubform({ subformPath, evaluate = false, }) {
|
|
442
466
|
await this.init();
|
|
443
467
|
return this._instance.resolveLayoutSubform(subformPath, evaluate);
|
|
444
468
|
}
|
|
445
469
|
/**
|
|
446
470
|
* Get evaluated schema from subform
|
|
447
471
|
*/
|
|
448
|
-
async getEvaluatedSchemaSubform({ subformPath, resolveLayout = false }) {
|
|
472
|
+
async getEvaluatedSchemaSubform({ subformPath, resolveLayout = false, }) {
|
|
449
473
|
await this.init();
|
|
450
474
|
return this._instance.getEvaluatedSchemaSubformJS(subformPath, resolveLayout);
|
|
451
475
|
}
|
|
452
476
|
/**
|
|
453
|
-
* Get schema value from subform (all .value fields)
|
|
477
|
+
* Get schema value from subform in nested object format (all .value fields).
|
|
478
|
+
* Returns a hierarchical object structure mimicking the schema.
|
|
454
479
|
*/
|
|
455
|
-
async getSchemaValueSubform({ subformPath }) {
|
|
480
|
+
async getSchemaValueSubform({ subformPath, }) {
|
|
456
481
|
await this.init();
|
|
457
482
|
return this._instance.getSchemaValueSubform(subformPath);
|
|
458
483
|
}
|
|
484
|
+
/**
|
|
485
|
+
* Get schema values from subform as a flat array of path-value pairs.
|
|
486
|
+
* Returns an array like `[{path: "field.sub", value: 123}, ...]`.
|
|
487
|
+
*/
|
|
488
|
+
async getSchemaValueArraySubform({ subformPath, }) {
|
|
489
|
+
await this.init();
|
|
490
|
+
return this._instance.getSchemaValueArraySubform(subformPath);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Get schema values from subform as a flat object with dotted path keys.
|
|
494
|
+
* Returns an object like `{"field.sub": 123, ...}`.
|
|
495
|
+
*/
|
|
496
|
+
async getSchemaValueObjectSubform({ subformPath, }) {
|
|
497
|
+
await this.init();
|
|
498
|
+
return this._instance.getSchemaValueObjectSubform(subformPath);
|
|
499
|
+
}
|
|
459
500
|
/**
|
|
460
501
|
* Get evaluated schema without $params from subform
|
|
461
502
|
*/
|
|
462
|
-
async getEvaluatedSchemaWithoutParamsSubform({ subformPath, resolveLayout = false }) {
|
|
503
|
+
async getEvaluatedSchemaWithoutParamsSubform({ subformPath, resolveLayout = false, }) {
|
|
463
504
|
await this.init();
|
|
464
505
|
return this._instance.getEvaluatedSchemaWithoutParamsSubformJS(subformPath, resolveLayout);
|
|
465
506
|
}
|
|
466
507
|
/**
|
|
467
508
|
* Get evaluated schema by specific path from subform
|
|
468
509
|
*/
|
|
469
|
-
async getEvaluatedSchemaByPathSubform({ subformPath, schemaPath, skipLayout = false }) {
|
|
510
|
+
async getEvaluatedSchemaByPathSubform({ subformPath, schemaPath, skipLayout = false, }) {
|
|
470
511
|
await this.init();
|
|
471
512
|
return this._instance.getEvaluatedSchemaByPathSubformJS(subformPath, schemaPath, skipLayout);
|
|
472
513
|
}
|
|
@@ -474,7 +515,7 @@ export class JSONEvalCore {
|
|
|
474
515
|
* Get evaluated schema by multiple paths from subform
|
|
475
516
|
* Returns data in the specified format (skips paths that are not found)
|
|
476
517
|
*/
|
|
477
|
-
async getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout = false, format = 0 }) {
|
|
518
|
+
async getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout = false, format = 0, }) {
|
|
478
519
|
await this.init();
|
|
479
520
|
return this._instance.getEvaluatedSchemaByPathsSubformJS(subformPath, JSON.stringify(schemaPaths), skipLayout, format);
|
|
480
521
|
}
|
|
@@ -488,7 +529,7 @@ export class JSONEvalCore {
|
|
|
488
529
|
/**
|
|
489
530
|
* Get schema by specific path from subform
|
|
490
531
|
*/
|
|
491
|
-
async getSchemaByPathSubform({ subformPath, schemaPath }) {
|
|
532
|
+
async getSchemaByPathSubform({ subformPath, schemaPath, }) {
|
|
492
533
|
await this.init();
|
|
493
534
|
return this._instance.getSchemaByPathSubformJS(subformPath, schemaPath);
|
|
494
535
|
}
|
|
@@ -496,7 +537,7 @@ export class JSONEvalCore {
|
|
|
496
537
|
* Get schema by multiple paths from subform
|
|
497
538
|
* Returns data in the specified format (skips paths that are not found)
|
|
498
539
|
*/
|
|
499
|
-
async getSchemaByPathsSubform({ subformPath, schemaPaths, format = 0 }) {
|
|
540
|
+
async getSchemaByPathsSubform({ subformPath, schemaPaths, format = 0, }) {
|
|
500
541
|
await this.init();
|
|
501
542
|
return this._instance.getSchemaByPathsSubformJS(subformPath, JSON.stringify(schemaPaths), format);
|
|
502
543
|
}
|