@json-eval-rs/webcore 0.0.53 → 0.0.55
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 +14 -0
- package/dist/index.js +33 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -372,6 +372,16 @@ export declare class JSONEvalCore {
|
|
|
372
372
|
* @returns New instance
|
|
373
373
|
*/
|
|
374
374
|
static fromCache(wasmModule: any, cacheKey: string, context?: any, data?: any): JSONEvalCore;
|
|
375
|
+
/**
|
|
376
|
+
* Evaluate logic expression without creating an instance
|
|
377
|
+
*
|
|
378
|
+
* @param wasmModule - WASM module
|
|
379
|
+
* @param logicStr - JSON Logic expression (string or object)
|
|
380
|
+
* @param data - Optional data (string or object)
|
|
381
|
+
* @param context - Optional context (string or object)
|
|
382
|
+
* @returns Evaluation result
|
|
383
|
+
*/
|
|
384
|
+
static evaluateLogic(wasmModule: any, logicStr: string | object, data?: any, context?: any): any;
|
|
375
385
|
/**
|
|
376
386
|
* Validate data against schema (returns parsed JavaScript object)
|
|
377
387
|
* Uses validateJS for Worker-safe serialization
|
|
@@ -484,6 +494,10 @@ export declare class JSONEvalCore {
|
|
|
484
494
|
* Validate data against schema rules with optional path filtering
|
|
485
495
|
*/
|
|
486
496
|
validatePaths({ data, context, paths }: EvaluateOptions): Promise<ValidationResult>;
|
|
497
|
+
/**
|
|
498
|
+
* Cancel any running evaluation
|
|
499
|
+
*/
|
|
500
|
+
cancel(): Promise<void>;
|
|
487
501
|
/**
|
|
488
502
|
* Evaluate a subform with data
|
|
489
503
|
*/
|
package/dist/index.js
CHANGED
|
@@ -119,6 +119,28 @@ export class JSONEvalCore {
|
|
|
119
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 ? (typeof data === 'string' ? data : JSON.stringify(data)) : null;
|
|
141
|
+
const contextStr = context ? (typeof context === 'string' ? context : JSON.stringify(context)) : null;
|
|
142
|
+
return JSONEvalWasm.evaluateLogic(logic, dataStr, contextStr);
|
|
143
|
+
}
|
|
122
144
|
/**
|
|
123
145
|
* Validate data against schema (returns parsed JavaScript object)
|
|
124
146
|
* Uses validateJS for Worker-safe serialization
|
|
@@ -148,7 +170,7 @@ export class JSONEvalCore {
|
|
|
148
170
|
/**
|
|
149
171
|
* Evaluate dependent fields (returns parsed JavaScript object, processes transitively)
|
|
150
172
|
*/
|
|
151
|
-
async evaluateDependents({ changedPaths, data, context, reEvaluate =
|
|
173
|
+
async evaluateDependents({ changedPaths, data, context, reEvaluate = true }) {
|
|
152
174
|
await this.init();
|
|
153
175
|
try {
|
|
154
176
|
// Ensure paths is an array for WASM
|
|
@@ -379,6 +401,14 @@ export class JSONEvalCore {
|
|
|
379
401
|
throw new Error(`Validation failed: ${error.message || error}`);
|
|
380
402
|
}
|
|
381
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* Cancel any running evaluation
|
|
406
|
+
*/
|
|
407
|
+
async cancel() {
|
|
408
|
+
if (this._ready && this._instance) {
|
|
409
|
+
this._instance.cancel();
|
|
410
|
+
}
|
|
411
|
+
}
|
|
382
412
|
// ============================================================================
|
|
383
413
|
// Subform Methods
|
|
384
414
|
// ============================================================================
|
|
@@ -399,11 +429,11 @@ export class JSONEvalCore {
|
|
|
399
429
|
/**
|
|
400
430
|
* Evaluate dependent fields in subform
|
|
401
431
|
*/
|
|
402
|
-
async evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate =
|
|
432
|
+
async evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate = true }) {
|
|
403
433
|
await this.init();
|
|
404
434
|
// For backward compatibility, accept single changedPath too (though types say array)
|
|
405
435
|
const paths = Array.isArray(changedPaths) ? changedPaths : [changedPaths];
|
|
406
|
-
return this._instance.evaluateDependentsSubformJS(subformPath, JSON.stringify(paths), data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null);
|
|
436
|
+
return this._instance.evaluateDependentsSubformJS(subformPath, JSON.stringify(paths), data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null, reEvaluate);
|
|
407
437
|
}
|
|
408
438
|
/**
|
|
409
439
|
* Resolve layout for subform
|