@json-eval-rs/webcore 0.0.54 → 0.0.56
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 +63 -23
- package/dist/index.js +100 -37
- 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
|
*/
|
|
@@ -372,11 +381,21 @@ export declare class JSONEvalCore {
|
|
|
372
381
|
* @returns New instance
|
|
373
382
|
*/
|
|
374
383
|
static fromCache(wasmModule: any, cacheKey: string, context?: any, data?: any): JSONEvalCore;
|
|
384
|
+
/**
|
|
385
|
+
* Evaluate logic expression without creating an instance
|
|
386
|
+
*
|
|
387
|
+
* @param wasmModule - WASM module
|
|
388
|
+
* @param logicStr - JSON Logic expression (string or object)
|
|
389
|
+
* @param data - Optional data (string or object)
|
|
390
|
+
* @param context - Optional context (string or object)
|
|
391
|
+
* @returns Evaluation result
|
|
392
|
+
*/
|
|
393
|
+
static evaluateLogic(wasmModule: any, logicStr: string | object, data?: any, context?: any): any;
|
|
375
394
|
/**
|
|
376
395
|
* Validate data against schema (returns parsed JavaScript object)
|
|
377
396
|
* Uses validateJS for Worker-safe serialization
|
|
378
397
|
*/
|
|
379
|
-
validate({ data, context }: ValidateOptions): Promise<ValidationResult>;
|
|
398
|
+
validate({ data, context, }: ValidateOptions): Promise<ValidationResult>;
|
|
380
399
|
/**
|
|
381
400
|
* Evaluate schema with data (returns parsed JavaScript object)
|
|
382
401
|
*/
|
|
@@ -384,32 +403,42 @@ export declare class JSONEvalCore {
|
|
|
384
403
|
/**
|
|
385
404
|
* Evaluate dependent fields (returns parsed JavaScript object, processes transitively)
|
|
386
405
|
*/
|
|
387
|
-
evaluateDependents({ changedPaths, data, context, reEvaluate }: EvaluateDependentsOptions): Promise<DependentChange[]>;
|
|
406
|
+
evaluateDependents({ changedPaths, data, context, reEvaluate, }: EvaluateDependentsOptions): Promise<DependentChange[]>;
|
|
388
407
|
/**
|
|
389
408
|
* Get evaluated schema
|
|
390
409
|
*/
|
|
391
|
-
getEvaluatedSchema({ skipLayout }?: GetEvaluatedSchemaOptions): Promise<any>;
|
|
410
|
+
getEvaluatedSchema({ skipLayout, }?: GetEvaluatedSchemaOptions): Promise<any>;
|
|
392
411
|
/**
|
|
393
412
|
* Get evaluated schema as MessagePack binary data
|
|
394
413
|
*/
|
|
395
|
-
getEvaluatedSchemaMsgpack({ skipLayout }?: GetEvaluatedSchemaOptions): Promise<Uint8Array>;
|
|
414
|
+
getEvaluatedSchemaMsgpack({ skipLayout, }?: GetEvaluatedSchemaOptions): Promise<Uint8Array>;
|
|
396
415
|
/**
|
|
397
416
|
* Get schema values (evaluations ending with .value)
|
|
398
417
|
*/
|
|
399
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>>;
|
|
400
429
|
/**
|
|
401
430
|
* Get evaluated schema without $params field
|
|
402
431
|
*/
|
|
403
|
-
getEvaluatedSchemaWithoutParams({ skipLayout }?: GetEvaluatedSchemaOptions): Promise<any>;
|
|
432
|
+
getEvaluatedSchemaWithoutParams({ skipLayout, }?: GetEvaluatedSchemaOptions): Promise<any>;
|
|
404
433
|
/**
|
|
405
434
|
* Get a value from the evaluated schema using dotted path notation
|
|
406
435
|
*/
|
|
407
|
-
getEvaluatedSchemaByPath({ path, skipLayout }: GetValueByPathOptions): Promise<any | null>;
|
|
436
|
+
getEvaluatedSchemaByPath({ path, skipLayout, }: GetValueByPathOptions): Promise<any | null>;
|
|
408
437
|
/**
|
|
409
438
|
* Get values from the evaluated schema using multiple dotted path notations
|
|
410
439
|
* Returns data in the specified format (skips paths that are not found)
|
|
411
440
|
*/
|
|
412
|
-
getEvaluatedSchemaByPaths({ paths, skipLayout, format }: GetValueByPathsOptions): Promise<any>;
|
|
441
|
+
getEvaluatedSchemaByPaths({ paths, skipLayout, format, }: GetValueByPathsOptions): Promise<any>;
|
|
413
442
|
/**
|
|
414
443
|
* Get a value from the schema using dotted path notation
|
|
415
444
|
*/
|
|
@@ -418,11 +447,11 @@ export declare class JSONEvalCore {
|
|
|
418
447
|
* Get values from the schema using multiple dotted path notations
|
|
419
448
|
* Returns data in the specified format (skips paths that are not found)
|
|
420
449
|
*/
|
|
421
|
-
getSchemaByPaths({ paths, format }: GetSchemaByPathsOptions): Promise<any>;
|
|
450
|
+
getSchemaByPaths({ paths, format, }: GetSchemaByPathsOptions): Promise<any>;
|
|
422
451
|
/**
|
|
423
452
|
* Reload schema with new data
|
|
424
453
|
*/
|
|
425
|
-
reloadSchema({ schema, context, data }: ReloadSchemaOptions): Promise<void>;
|
|
454
|
+
reloadSchema({ schema, context, data, }: ReloadSchemaOptions): Promise<void>;
|
|
426
455
|
/**
|
|
427
456
|
* Reload schema from MessagePack bytes
|
|
428
457
|
*/
|
|
@@ -471,7 +500,7 @@ export declare class JSONEvalCore {
|
|
|
471
500
|
/**
|
|
472
501
|
* Compile and run JSON logic from a JSON logic string
|
|
473
502
|
*/
|
|
474
|
-
compileAndRunLogic({ logicStr, data, context }: CompileAndRunLogicOptions): Promise<any>;
|
|
503
|
+
compileAndRunLogic({ logicStr, data, context, }: CompileAndRunLogicOptions): Promise<any>;
|
|
475
504
|
/**
|
|
476
505
|
* Compile JSON logic and return a global ID
|
|
477
506
|
*/
|
|
@@ -483,7 +512,7 @@ export declare class JSONEvalCore {
|
|
|
483
512
|
/**
|
|
484
513
|
* Validate data against schema rules with optional path filtering
|
|
485
514
|
*/
|
|
486
|
-
validatePaths({ data, context, paths }: EvaluateOptions): Promise<ValidationResult>;
|
|
515
|
+
validatePaths({ data, context, paths, }: EvaluateOptions): Promise<ValidationResult>;
|
|
487
516
|
/**
|
|
488
517
|
* Cancel any running evaluation
|
|
489
518
|
*/
|
|
@@ -491,40 +520,51 @@ export declare class JSONEvalCore {
|
|
|
491
520
|
/**
|
|
492
521
|
* Evaluate a subform with data
|
|
493
522
|
*/
|
|
494
|
-
evaluateSubform({ subformPath, data, context, paths }: EvaluateSubformOptions): Promise<void>;
|
|
523
|
+
evaluateSubform({ subformPath, data, context, paths, }: EvaluateSubformOptions): Promise<void>;
|
|
495
524
|
/**
|
|
496
525
|
* Validate subform data against its schema rules
|
|
497
526
|
*/
|
|
498
|
-
validateSubform({ subformPath, data, context }: ValidateSubformOptions): Promise<ValidationResult>;
|
|
527
|
+
validateSubform({ subformPath, data, context, }: ValidateSubformOptions): Promise<ValidationResult>;
|
|
499
528
|
/**
|
|
500
529
|
* Evaluate dependent fields in subform
|
|
501
530
|
*/
|
|
502
|
-
evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate }: EvaluateDependentsSubformOptions): Promise<DependentChange[]>;
|
|
531
|
+
evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate, }: EvaluateDependentsSubformOptions): Promise<DependentChange[]>;
|
|
503
532
|
/**
|
|
504
533
|
* Resolve layout for subform
|
|
505
534
|
*/
|
|
506
|
-
resolveLayoutSubform({ subformPath, evaluate }: ResolveLayoutSubformOptions): Promise<void>;
|
|
535
|
+
resolveLayoutSubform({ subformPath, evaluate, }: ResolveLayoutSubformOptions): Promise<void>;
|
|
507
536
|
/**
|
|
508
537
|
* Get evaluated schema from subform
|
|
509
538
|
*/
|
|
510
|
-
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[]>;
|
|
511
550
|
/**
|
|
512
|
-
* Get schema
|
|
551
|
+
* Get schema values from subform as a flat object with dotted path keys.
|
|
552
|
+
* Returns an object like `{"field.sub": 123, ...}`.
|
|
513
553
|
*/
|
|
514
|
-
|
|
554
|
+
getSchemaValueObjectSubform({ subformPath, }: GetSchemaValueSubformOptions): Promise<Record<string, any>>;
|
|
515
555
|
/**
|
|
516
556
|
* Get evaluated schema without $params from subform
|
|
517
557
|
*/
|
|
518
|
-
getEvaluatedSchemaWithoutParamsSubform({ subformPath, resolveLayout }: GetEvaluatedSchemaSubformOptions): Promise<any>;
|
|
558
|
+
getEvaluatedSchemaWithoutParamsSubform({ subformPath, resolveLayout, }: GetEvaluatedSchemaSubformOptions): Promise<any>;
|
|
519
559
|
/**
|
|
520
560
|
* Get evaluated schema by specific path from subform
|
|
521
561
|
*/
|
|
522
|
-
getEvaluatedSchemaByPathSubform({ subformPath, schemaPath, skipLayout }: GetEvaluatedSchemaByPathSubformOptions): Promise<any | null>;
|
|
562
|
+
getEvaluatedSchemaByPathSubform({ subformPath, schemaPath, skipLayout, }: GetEvaluatedSchemaByPathSubformOptions): Promise<any | null>;
|
|
523
563
|
/**
|
|
524
564
|
* Get evaluated schema by multiple paths from subform
|
|
525
565
|
* Returns data in the specified format (skips paths that are not found)
|
|
526
566
|
*/
|
|
527
|
-
getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout, format }: GetEvaluatedSchemaByPathsSubformOptions): Promise<any>;
|
|
567
|
+
getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout, format, }: GetEvaluatedSchemaByPathsSubformOptions): Promise<any>;
|
|
528
568
|
/**
|
|
529
569
|
* Get list of available subform paths
|
|
530
570
|
*/
|
|
@@ -532,12 +572,12 @@ export declare class JSONEvalCore {
|
|
|
532
572
|
/**
|
|
533
573
|
* Get schema by specific path from subform
|
|
534
574
|
*/
|
|
535
|
-
getSchemaByPathSubform({ subformPath, schemaPath }: GetSchemaByPathSubformOptions): Promise<any | null>;
|
|
575
|
+
getSchemaByPathSubform({ subformPath, schemaPath, }: GetSchemaByPathSubformOptions): Promise<any | null>;
|
|
536
576
|
/**
|
|
537
577
|
* Get schema by multiple paths from subform
|
|
538
578
|
* Returns data in the specified format (skips paths that are not found)
|
|
539
579
|
*/
|
|
540
|
-
getSchemaByPathsSubform({ subformPath, schemaPaths, format }: GetSchemaByPathsSubformOptions): Promise<any>;
|
|
580
|
+
getSchemaByPathsSubform({ subformPath, schemaPaths, format, }: GetSchemaByPathsSubformOptions): Promise<any>;
|
|
541
581
|
/**
|
|
542
582
|
* Check if a subform exists at the given path
|
|
543
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,14 +116,44 @@ export class JSONEvalCore {
|
|
|
116
116
|
schema: cacheKey,
|
|
117
117
|
context,
|
|
118
118
|
data,
|
|
119
|
-
fromCache: true
|
|
119
|
+
fromCache: true,
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Evaluate logic expression without creating an instance
|
|
124
|
+
*
|
|
125
|
+
* @param wasmModule - WASM module
|
|
126
|
+
* @param logicStr - JSON Logic expression (string or object)
|
|
127
|
+
* @param data - Optional data (string or object)
|
|
128
|
+
* @param context - Optional context (string or object)
|
|
129
|
+
* @returns Evaluation result
|
|
130
|
+
*/
|
|
131
|
+
static evaluateLogic(wasmModule, logicStr, data, context) {
|
|
132
|
+
if (!wasmModule) {
|
|
133
|
+
throw new Error("No WASM module provided.");
|
|
134
|
+
}
|
|
135
|
+
const { JSONEvalWasm } = wasmModule;
|
|
136
|
+
if (!JSONEvalWasm || typeof JSONEvalWasm.evaluateLogic !== "function") {
|
|
137
|
+
throw new Error("WASM module does not support evaluateLogic.");
|
|
138
|
+
}
|
|
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;
|
|
150
|
+
return JSONEvalWasm.evaluateLogic(logic, dataStr, contextStr);
|
|
151
|
+
}
|
|
122
152
|
/**
|
|
123
153
|
* Validate data against schema (returns parsed JavaScript object)
|
|
124
154
|
* Uses validateJS for Worker-safe serialization
|
|
125
155
|
*/
|
|
126
|
-
async validate({ data, context }) {
|
|
156
|
+
async validate({ data, context, }) {
|
|
127
157
|
await this.init();
|
|
128
158
|
try {
|
|
129
159
|
// Use validateJS for proper serialization (Worker-safe)
|
|
@@ -148,7 +178,7 @@ export class JSONEvalCore {
|
|
|
148
178
|
/**
|
|
149
179
|
* Evaluate dependent fields (returns parsed JavaScript object, processes transitively)
|
|
150
180
|
*/
|
|
151
|
-
async evaluateDependents({ changedPaths, data, context, reEvaluate = true }) {
|
|
181
|
+
async evaluateDependents({ changedPaths, data, context, reEvaluate = true, }) {
|
|
152
182
|
await this.init();
|
|
153
183
|
try {
|
|
154
184
|
// Ensure paths is an array for WASM
|
|
@@ -162,14 +192,14 @@ export class JSONEvalCore {
|
|
|
162
192
|
/**
|
|
163
193
|
* Get evaluated schema
|
|
164
194
|
*/
|
|
165
|
-
async getEvaluatedSchema({ skipLayout = false } = {}) {
|
|
195
|
+
async getEvaluatedSchema({ skipLayout = false, } = {}) {
|
|
166
196
|
await this.init();
|
|
167
197
|
return this._instance.getEvaluatedSchemaJS(skipLayout);
|
|
168
198
|
}
|
|
169
199
|
/**
|
|
170
200
|
* Get evaluated schema as MessagePack binary data
|
|
171
201
|
*/
|
|
172
|
-
async getEvaluatedSchemaMsgpack({ skipLayout = false } = {}) {
|
|
202
|
+
async getEvaluatedSchemaMsgpack({ skipLayout = false, } = {}) {
|
|
173
203
|
await this.init();
|
|
174
204
|
return this._instance.getEvaluatedSchemaMsgpack(skipLayout);
|
|
175
205
|
}
|
|
@@ -180,17 +210,33 @@ export class JSONEvalCore {
|
|
|
180
210
|
await this.init();
|
|
181
211
|
return this._instance.getSchemaValue();
|
|
182
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
|
+
}
|
|
183
229
|
/**
|
|
184
230
|
* Get evaluated schema without $params field
|
|
185
231
|
*/
|
|
186
|
-
async getEvaluatedSchemaWithoutParams({ skipLayout = false } = {}) {
|
|
232
|
+
async getEvaluatedSchemaWithoutParams({ skipLayout = false, } = {}) {
|
|
187
233
|
await this.init();
|
|
188
234
|
return this._instance.getEvaluatedSchemaWithoutParamsJS(skipLayout);
|
|
189
235
|
}
|
|
190
236
|
/**
|
|
191
237
|
* Get a value from the evaluated schema using dotted path notation
|
|
192
238
|
*/
|
|
193
|
-
async getEvaluatedSchemaByPath({ path, skipLayout = false }) {
|
|
239
|
+
async getEvaluatedSchemaByPath({ path, skipLayout = false, }) {
|
|
194
240
|
await this.init();
|
|
195
241
|
return this._instance.getEvaluatedSchemaByPathJS(path, skipLayout);
|
|
196
242
|
}
|
|
@@ -198,7 +244,7 @@ export class JSONEvalCore {
|
|
|
198
244
|
* Get values from the evaluated schema using multiple dotted path notations
|
|
199
245
|
* Returns data in the specified format (skips paths that are not found)
|
|
200
246
|
*/
|
|
201
|
-
async getEvaluatedSchemaByPaths({ paths, skipLayout = false, format = 0 }) {
|
|
247
|
+
async getEvaluatedSchemaByPaths({ paths, skipLayout = false, format = 0, }) {
|
|
202
248
|
await this.init();
|
|
203
249
|
return this._instance.getEvaluatedSchemaByPathsJS(JSON.stringify(paths), skipLayout, format);
|
|
204
250
|
}
|
|
@@ -213,16 +259,16 @@ export class JSONEvalCore {
|
|
|
213
259
|
* Get values from the schema using multiple dotted path notations
|
|
214
260
|
* Returns data in the specified format (skips paths that are not found)
|
|
215
261
|
*/
|
|
216
|
-
async getSchemaByPaths({ paths, format = 0 }) {
|
|
262
|
+
async getSchemaByPaths({ paths, format = 0, }) {
|
|
217
263
|
await this.init();
|
|
218
264
|
return this._instance.getSchemaByPathsJS(JSON.stringify(paths), format);
|
|
219
265
|
}
|
|
220
266
|
/**
|
|
221
267
|
* Reload schema with new data
|
|
222
268
|
*/
|
|
223
|
-
async reloadSchema({ schema, context, data }) {
|
|
269
|
+
async reloadSchema({ schema, context, data, }) {
|
|
224
270
|
if (!this._instance) {
|
|
225
|
-
throw new Error(
|
|
271
|
+
throw new Error("Instance not initialized. Call init() first.");
|
|
226
272
|
}
|
|
227
273
|
try {
|
|
228
274
|
await this._instance.reloadSchema(JSON.stringify(schema), context ? JSON.stringify(context) : null, data ? JSON.stringify(data) : null);
|
|
@@ -240,10 +286,10 @@ export class JSONEvalCore {
|
|
|
240
286
|
*/
|
|
241
287
|
async reloadSchemaMsgpack(schemaMsgpack, context, data) {
|
|
242
288
|
if (!this._instance) {
|
|
243
|
-
throw new Error(
|
|
289
|
+
throw new Error("Instance not initialized. Call init() first.");
|
|
244
290
|
}
|
|
245
291
|
if (!(schemaMsgpack instanceof Uint8Array)) {
|
|
246
|
-
throw new Error(
|
|
292
|
+
throw new Error("schemaMsgpack must be a Uint8Array");
|
|
247
293
|
}
|
|
248
294
|
try {
|
|
249
295
|
await this._instance.reloadSchemaMsgpack(schemaMsgpack, context ? JSON.stringify(context) : null, data ? JSON.stringify(data) : null);
|
|
@@ -262,10 +308,10 @@ export class JSONEvalCore {
|
|
|
262
308
|
*/
|
|
263
309
|
async reloadSchemaFromCache(cacheKey, context, data) {
|
|
264
310
|
if (!this._instance) {
|
|
265
|
-
throw new Error(
|
|
311
|
+
throw new Error("Instance not initialized. Call init() first.");
|
|
266
312
|
}
|
|
267
|
-
if (typeof cacheKey !==
|
|
268
|
-
throw new Error(
|
|
313
|
+
if (typeof cacheKey !== "string" || !cacheKey) {
|
|
314
|
+
throw new Error("cacheKey must be a non-empty string");
|
|
269
315
|
}
|
|
270
316
|
try {
|
|
271
317
|
await this._instance.reloadSchemaFromCache(cacheKey, context ? JSON.stringify(context) : null, data ? JSON.stringify(data) : null);
|
|
@@ -337,16 +383,16 @@ export class JSONEvalCore {
|
|
|
337
383
|
*/
|
|
338
384
|
setTimezoneOffset(offsetMinutes) {
|
|
339
385
|
if (!this._instance) {
|
|
340
|
-
throw new Error(
|
|
386
|
+
throw new Error("Instance not initialized. Call init() first.");
|
|
341
387
|
}
|
|
342
388
|
this._instance.setTimezoneOffset(offsetMinutes);
|
|
343
389
|
}
|
|
344
390
|
/**
|
|
345
391
|
* Compile and run JSON logic from a JSON logic string
|
|
346
392
|
*/
|
|
347
|
-
async compileAndRunLogic({ logicStr, data, context }) {
|
|
393
|
+
async compileAndRunLogic({ logicStr, data, context, }) {
|
|
348
394
|
await this.init();
|
|
349
|
-
const logic = typeof logicStr ===
|
|
395
|
+
const logic = typeof logicStr === "string" ? logicStr : JSON.stringify(logicStr);
|
|
350
396
|
const result = await this._instance.compileAndRunLogic(logic, data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null);
|
|
351
397
|
return result;
|
|
352
398
|
}
|
|
@@ -355,7 +401,7 @@ export class JSONEvalCore {
|
|
|
355
401
|
*/
|
|
356
402
|
async compileLogic(logicStr) {
|
|
357
403
|
await this.init();
|
|
358
|
-
const logic = typeof logicStr ===
|
|
404
|
+
const logic = typeof logicStr === "string" ? logicStr : JSON.stringify(logicStr);
|
|
359
405
|
return this._instance.compileLogic(logic);
|
|
360
406
|
}
|
|
361
407
|
/**
|
|
@@ -369,7 +415,7 @@ export class JSONEvalCore {
|
|
|
369
415
|
/**
|
|
370
416
|
* Validate data against schema rules with optional path filtering
|
|
371
417
|
*/
|
|
372
|
-
async validatePaths({ data, context, paths }) {
|
|
418
|
+
async validatePaths({ data, context, paths, }) {
|
|
373
419
|
await this.init();
|
|
374
420
|
try {
|
|
375
421
|
// Use validatePathsJS for proper serialization (Worker-safe)
|
|
@@ -393,21 +439,21 @@ export class JSONEvalCore {
|
|
|
393
439
|
/**
|
|
394
440
|
* Evaluate a subform with data
|
|
395
441
|
*/
|
|
396
|
-
async evaluateSubform({ subformPath, data, context, paths }) {
|
|
442
|
+
async evaluateSubform({ subformPath, data, context, paths, }) {
|
|
397
443
|
await this.init();
|
|
398
444
|
return this._instance.evaluateSubform(subformPath, JSON.stringify(data), context ? JSON.stringify(context) : null, paths || null);
|
|
399
445
|
}
|
|
400
446
|
/**
|
|
401
447
|
* Validate subform data against its schema rules
|
|
402
448
|
*/
|
|
403
|
-
async validateSubform({ subformPath, data, context }) {
|
|
449
|
+
async validateSubform({ subformPath, data, context, }) {
|
|
404
450
|
await this.init();
|
|
405
451
|
return this._instance.validateSubform(subformPath, JSON.stringify(data), context ? JSON.stringify(context) : null);
|
|
406
452
|
}
|
|
407
453
|
/**
|
|
408
454
|
* Evaluate dependent fields in subform
|
|
409
455
|
*/
|
|
410
|
-
async evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate = true }) {
|
|
456
|
+
async evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate = true, }) {
|
|
411
457
|
await this.init();
|
|
412
458
|
// For backward compatibility, accept single changedPath too (though types say array)
|
|
413
459
|
const paths = Array.isArray(changedPaths) ? changedPaths : [changedPaths];
|
|
@@ -416,35 +462,52 @@ export class JSONEvalCore {
|
|
|
416
462
|
/**
|
|
417
463
|
* Resolve layout for subform
|
|
418
464
|
*/
|
|
419
|
-
async resolveLayoutSubform({ subformPath, evaluate = false }) {
|
|
465
|
+
async resolveLayoutSubform({ subformPath, evaluate = false, }) {
|
|
420
466
|
await this.init();
|
|
421
467
|
return this._instance.resolveLayoutSubform(subformPath, evaluate);
|
|
422
468
|
}
|
|
423
469
|
/**
|
|
424
470
|
* Get evaluated schema from subform
|
|
425
471
|
*/
|
|
426
|
-
async getEvaluatedSchemaSubform({ subformPath, resolveLayout = false }) {
|
|
472
|
+
async getEvaluatedSchemaSubform({ subformPath, resolveLayout = false, }) {
|
|
427
473
|
await this.init();
|
|
428
474
|
return this._instance.getEvaluatedSchemaSubformJS(subformPath, resolveLayout);
|
|
429
475
|
}
|
|
430
476
|
/**
|
|
431
|
-
* 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.
|
|
432
479
|
*/
|
|
433
|
-
async getSchemaValueSubform({ subformPath }) {
|
|
480
|
+
async getSchemaValueSubform({ subformPath, }) {
|
|
434
481
|
await this.init();
|
|
435
482
|
return this._instance.getSchemaValueSubform(subformPath);
|
|
436
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
|
+
}
|
|
437
500
|
/**
|
|
438
501
|
* Get evaluated schema without $params from subform
|
|
439
502
|
*/
|
|
440
|
-
async getEvaluatedSchemaWithoutParamsSubform({ subformPath, resolveLayout = false }) {
|
|
503
|
+
async getEvaluatedSchemaWithoutParamsSubform({ subformPath, resolveLayout = false, }) {
|
|
441
504
|
await this.init();
|
|
442
505
|
return this._instance.getEvaluatedSchemaWithoutParamsSubformJS(subformPath, resolveLayout);
|
|
443
506
|
}
|
|
444
507
|
/**
|
|
445
508
|
* Get evaluated schema by specific path from subform
|
|
446
509
|
*/
|
|
447
|
-
async getEvaluatedSchemaByPathSubform({ subformPath, schemaPath, skipLayout = false }) {
|
|
510
|
+
async getEvaluatedSchemaByPathSubform({ subformPath, schemaPath, skipLayout = false, }) {
|
|
448
511
|
await this.init();
|
|
449
512
|
return this._instance.getEvaluatedSchemaByPathSubformJS(subformPath, schemaPath, skipLayout);
|
|
450
513
|
}
|
|
@@ -452,7 +515,7 @@ export class JSONEvalCore {
|
|
|
452
515
|
* Get evaluated schema by multiple paths from subform
|
|
453
516
|
* Returns data in the specified format (skips paths that are not found)
|
|
454
517
|
*/
|
|
455
|
-
async getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout = false, format = 0 }) {
|
|
518
|
+
async getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout = false, format = 0, }) {
|
|
456
519
|
await this.init();
|
|
457
520
|
return this._instance.getEvaluatedSchemaByPathsSubformJS(subformPath, JSON.stringify(schemaPaths), skipLayout, format);
|
|
458
521
|
}
|
|
@@ -466,7 +529,7 @@ export class JSONEvalCore {
|
|
|
466
529
|
/**
|
|
467
530
|
* Get schema by specific path from subform
|
|
468
531
|
*/
|
|
469
|
-
async getSchemaByPathSubform({ subformPath, schemaPath }) {
|
|
532
|
+
async getSchemaByPathSubform({ subformPath, schemaPath, }) {
|
|
470
533
|
await this.init();
|
|
471
534
|
return this._instance.getSchemaByPathSubformJS(subformPath, schemaPath);
|
|
472
535
|
}
|
|
@@ -474,7 +537,7 @@ export class JSONEvalCore {
|
|
|
474
537
|
* Get schema by multiple paths from subform
|
|
475
538
|
* Returns data in the specified format (skips paths that are not found)
|
|
476
539
|
*/
|
|
477
|
-
async getSchemaByPathsSubform({ subformPath, schemaPaths, format = 0 }) {
|
|
540
|
+
async getSchemaByPathsSubform({ subformPath, schemaPaths, format = 0, }) {
|
|
478
541
|
await this.init();
|
|
479
542
|
return this._instance.getSchemaByPathsSubformJS(subformPath, JSON.stringify(schemaPaths), format);
|
|
480
543
|
}
|