@json-eval-rs/webcore 0.0.63 → 0.0.65
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.js +25 -24
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JSONStringify } from "json-with-bigint";
|
|
1
2
|
/**
|
|
2
3
|
* @json-eval-rs/webcore
|
|
3
4
|
* High-level JavaScript API for JSON Eval RS WASM bindings
|
|
@@ -87,13 +88,13 @@ export class JSONEvalCore {
|
|
|
87
88
|
// Create instance from cache, MessagePack, or JSON
|
|
88
89
|
if (this._isFromCache) {
|
|
89
90
|
this._instance = JSONEvalWasm.newFromCache(this._schema, // cache key
|
|
90
|
-
this._context ?
|
|
91
|
+
this._context ? typeof this._context === "string" ? this._context : JSONStringify(this._context) : null, this._data ? typeof this._data === "string" ? this._data : JSONStringify(this._data) : null);
|
|
91
92
|
}
|
|
92
93
|
else if (this._isMsgpackSchema) {
|
|
93
|
-
this._instance = JSONEvalWasm.newFromMsgpack(this._schema, this._context ?
|
|
94
|
+
this._instance = JSONEvalWasm.newFromMsgpack(this._schema, this._context ? typeof this._context === "string" ? this._context : JSONStringify(this._context) : null, this._data ? typeof this._data === "string" ? this._data : JSONStringify(this._data) : null);
|
|
94
95
|
}
|
|
95
96
|
else {
|
|
96
|
-
this._instance = new JSONEvalWasm(
|
|
97
|
+
this._instance = new JSONEvalWasm(typeof this._schema === "string" ? this._schema : JSONStringify(this._schema), this._context ? typeof this._context === "string" ? this._context : JSONStringify(this._context) : null, this._data ? typeof this._data === "string" ? this._data : JSONStringify(this._data) : null);
|
|
97
98
|
}
|
|
98
99
|
this._ready = true;
|
|
99
100
|
}
|
|
@@ -136,16 +137,16 @@ export class JSONEvalCore {
|
|
|
136
137
|
if (!JSONEvalWasm || typeof JSONEvalWasm.evaluateLogic !== "function") {
|
|
137
138
|
throw new Error("WASM module does not support evaluateLogic.");
|
|
138
139
|
}
|
|
139
|
-
const logic = typeof logicStr === "string" ? logicStr :
|
|
140
|
+
const logic = typeof logicStr === "string" ? logicStr : JSONStringify(logicStr);
|
|
140
141
|
const dataStr = data
|
|
141
142
|
? typeof data === "string"
|
|
142
143
|
? data
|
|
143
|
-
:
|
|
144
|
+
: JSONStringify(data)
|
|
144
145
|
: null;
|
|
145
146
|
const contextStr = context
|
|
146
147
|
? typeof context === "string"
|
|
147
148
|
? context
|
|
148
|
-
:
|
|
149
|
+
: JSONStringify(context)
|
|
149
150
|
: null;
|
|
150
151
|
return JSONEvalWasm.evaluateLogic(logic, dataStr, contextStr);
|
|
151
152
|
}
|
|
@@ -157,7 +158,7 @@ export class JSONEvalCore {
|
|
|
157
158
|
await this.init();
|
|
158
159
|
try {
|
|
159
160
|
// Use validateJS for proper serialization (Worker-safe)
|
|
160
|
-
return this._instance.validateJS(
|
|
161
|
+
return this._instance.validateJS(typeof data === "string" ? data : JSONStringify(data), context ? typeof context === "string" ? context : JSONStringify(context) : null);
|
|
161
162
|
}
|
|
162
163
|
catch (error) {
|
|
163
164
|
throw new Error(`Validation failed: ${error.message || error}`);
|
|
@@ -169,7 +170,7 @@ export class JSONEvalCore {
|
|
|
169
170
|
async evaluate({ data, context, paths }) {
|
|
170
171
|
await this.init();
|
|
171
172
|
try {
|
|
172
|
-
return this._instance.evaluateJS(
|
|
173
|
+
return this._instance.evaluateJS(typeof data === "string" ? data : JSONStringify(data), context ? typeof context === "string" ? context : JSONStringify(context) : null, paths || null);
|
|
173
174
|
}
|
|
174
175
|
catch (error) {
|
|
175
176
|
throw new Error(`Evaluation failed: ${error.message || error}`);
|
|
@@ -183,7 +184,7 @@ export class JSONEvalCore {
|
|
|
183
184
|
try {
|
|
184
185
|
// Ensure paths is an array for WASM
|
|
185
186
|
const paths = Array.isArray(changedPaths) ? changedPaths : [changedPaths];
|
|
186
|
-
return this._instance.evaluateDependentsJS(
|
|
187
|
+
return this._instance.evaluateDependentsJS(typeof paths === "string" ? paths : JSONStringify(paths), data ? typeof data === "string" ? data : JSONStringify(data) : null, context ? typeof context === "string" ? context : JSONStringify(context) : null, reEvaluate);
|
|
187
188
|
}
|
|
188
189
|
catch (error) {
|
|
189
190
|
throw new Error(`Dependent evaluation failed: ${error.message || error}`);
|
|
@@ -246,7 +247,7 @@ export class JSONEvalCore {
|
|
|
246
247
|
*/
|
|
247
248
|
async getEvaluatedSchemaByPaths({ paths, skipLayout = false, format = 0, }) {
|
|
248
249
|
await this.init();
|
|
249
|
-
return this._instance.getEvaluatedSchemaByPathsJS(
|
|
250
|
+
return this._instance.getEvaluatedSchemaByPathsJS(typeof paths === "string" ? paths : JSONStringify(paths), skipLayout, format);
|
|
250
251
|
}
|
|
251
252
|
/**
|
|
252
253
|
* Get a value from the schema using dotted path notation
|
|
@@ -261,7 +262,7 @@ export class JSONEvalCore {
|
|
|
261
262
|
*/
|
|
262
263
|
async getSchemaByPaths({ paths, format = 0, }) {
|
|
263
264
|
await this.init();
|
|
264
|
-
return this._instance.getSchemaByPathsJS(
|
|
265
|
+
return this._instance.getSchemaByPathsJS(typeof paths === "string" ? paths : JSONStringify(paths), format);
|
|
265
266
|
}
|
|
266
267
|
/**
|
|
267
268
|
* Reload schema with new data
|
|
@@ -271,7 +272,7 @@ export class JSONEvalCore {
|
|
|
271
272
|
throw new Error("Instance not initialized. Call init() first.");
|
|
272
273
|
}
|
|
273
274
|
try {
|
|
274
|
-
await this._instance.reloadSchema(
|
|
275
|
+
await this._instance.reloadSchema(typeof schema === "string" ? schema : JSONStringify(schema), context ? typeof context === "string" ? context : JSONStringify(context) : null, data ? typeof data === "string" ? data : JSONStringify(data) : null);
|
|
275
276
|
// Update internal state
|
|
276
277
|
this._schema = schema;
|
|
277
278
|
this._context = context;
|
|
@@ -292,7 +293,7 @@ export class JSONEvalCore {
|
|
|
292
293
|
throw new Error("schemaMsgpack must be a Uint8Array");
|
|
293
294
|
}
|
|
294
295
|
try {
|
|
295
|
-
await this._instance.reloadSchemaMsgpack(schemaMsgpack, context ?
|
|
296
|
+
await this._instance.reloadSchemaMsgpack(schemaMsgpack, context ? typeof context === "string" ? context : JSONStringify(context) : null, data ? typeof data === "string" ? data : JSONStringify(data) : null);
|
|
296
297
|
// Update internal state
|
|
297
298
|
this._schema = schemaMsgpack;
|
|
298
299
|
this._context = context;
|
|
@@ -314,7 +315,7 @@ export class JSONEvalCore {
|
|
|
314
315
|
throw new Error("cacheKey must be a non-empty string");
|
|
315
316
|
}
|
|
316
317
|
try {
|
|
317
|
-
await this._instance.reloadSchemaFromCache(cacheKey, context ?
|
|
318
|
+
await this._instance.reloadSchemaFromCache(cacheKey, context ? typeof context === "string" ? context : JSONStringify(context) : null, data ? typeof data === "string" ? data : JSONStringify(data) : null);
|
|
318
319
|
// Update internal state
|
|
319
320
|
this._context = context;
|
|
320
321
|
this._data = data;
|
|
@@ -392,8 +393,8 @@ export class JSONEvalCore {
|
|
|
392
393
|
*/
|
|
393
394
|
async compileAndRunLogic({ logicStr, data, context, }) {
|
|
394
395
|
await this.init();
|
|
395
|
-
const logic = typeof logicStr === "string" ? logicStr :
|
|
396
|
-
const result = await this._instance.compileAndRunLogic(logic, data ?
|
|
396
|
+
const logic = typeof logicStr === "string" ? logicStr : JSONStringify(logicStr);
|
|
397
|
+
const result = await this._instance.compileAndRunLogic(logic, data ? typeof data === "string" ? data : JSONStringify(data) : null, context ? typeof context === "string" ? context : JSONStringify(context) : null);
|
|
397
398
|
return result;
|
|
398
399
|
}
|
|
399
400
|
/**
|
|
@@ -401,7 +402,7 @@ export class JSONEvalCore {
|
|
|
401
402
|
*/
|
|
402
403
|
async compileLogic(logicStr) {
|
|
403
404
|
await this.init();
|
|
404
|
-
const logic = typeof logicStr === "string" ? logicStr :
|
|
405
|
+
const logic = typeof logicStr === "string" ? logicStr : JSONStringify(logicStr);
|
|
405
406
|
return this._instance.compileLogic(logic);
|
|
406
407
|
}
|
|
407
408
|
/**
|
|
@@ -409,7 +410,7 @@ export class JSONEvalCore {
|
|
|
409
410
|
*/
|
|
410
411
|
async runLogic(logicId, data, context) {
|
|
411
412
|
await this.init();
|
|
412
|
-
const result = await this._instance.runLogic(logicId, data ?
|
|
413
|
+
const result = await this._instance.runLogic(logicId, data ? typeof data === "string" ? data : JSONStringify(data) : null, context ? typeof context === "string" ? context : JSONStringify(context) : null);
|
|
413
414
|
return result;
|
|
414
415
|
}
|
|
415
416
|
/**
|
|
@@ -419,7 +420,7 @@ export class JSONEvalCore {
|
|
|
419
420
|
await this.init();
|
|
420
421
|
try {
|
|
421
422
|
// Use validatePathsJS for proper serialization (Worker-safe)
|
|
422
|
-
return this._instance.validatePathsJS(
|
|
423
|
+
return this._instance.validatePathsJS(typeof data === "string" ? data : JSONStringify(data), context ? typeof context === "string" ? context : JSONStringify(context) : null, paths || null);
|
|
423
424
|
}
|
|
424
425
|
catch (error) {
|
|
425
426
|
throw new Error(`Validation failed: ${error.message || error}`);
|
|
@@ -441,14 +442,14 @@ export class JSONEvalCore {
|
|
|
441
442
|
*/
|
|
442
443
|
async evaluateSubform({ subformPath, data, context, paths, }) {
|
|
443
444
|
await this.init();
|
|
444
|
-
return this._instance.evaluateSubform(subformPath,
|
|
445
|
+
return this._instance.evaluateSubform(subformPath, typeof data === "string" ? data : JSONStringify(data), context ? typeof context === "string" ? context : JSONStringify(context) : null, paths || null);
|
|
445
446
|
}
|
|
446
447
|
/**
|
|
447
448
|
* Validate subform data against its schema rules
|
|
448
449
|
*/
|
|
449
450
|
async validateSubform({ subformPath, data, context, }) {
|
|
450
451
|
await this.init();
|
|
451
|
-
return this._instance.validateSubform(subformPath,
|
|
452
|
+
return this._instance.validateSubform(subformPath, typeof data === "string" ? data : JSONStringify(data), context ? typeof context === "string" ? context : JSONStringify(context) : null);
|
|
452
453
|
}
|
|
453
454
|
/**
|
|
454
455
|
* Evaluate dependent fields in subform
|
|
@@ -457,7 +458,7 @@ export class JSONEvalCore {
|
|
|
457
458
|
await this.init();
|
|
458
459
|
// For backward compatibility, accept single changedPath too (though types say array)
|
|
459
460
|
const paths = Array.isArray(changedPaths) ? changedPaths : [changedPaths];
|
|
460
|
-
return this._instance.evaluateDependentsSubformJS(subformPath,
|
|
461
|
+
return this._instance.evaluateDependentsSubformJS(subformPath, typeof paths === "string" ? paths : JSONStringify(paths), data ? typeof data === "string" ? data : JSONStringify(data) : null, context ? typeof context === "string" ? context : JSONStringify(context) : null, reEvaluate);
|
|
461
462
|
}
|
|
462
463
|
/**
|
|
463
464
|
* Resolve layout for subform
|
|
@@ -517,7 +518,7 @@ export class JSONEvalCore {
|
|
|
517
518
|
*/
|
|
518
519
|
async getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout = false, format = 0, }) {
|
|
519
520
|
await this.init();
|
|
520
|
-
return this._instance.getEvaluatedSchemaByPathsSubformJS(subformPath,
|
|
521
|
+
return this._instance.getEvaluatedSchemaByPathsSubformJS(subformPath, typeof schemaPaths === "string" ? schemaPaths : JSONStringify(schemaPaths), skipLayout, format);
|
|
521
522
|
}
|
|
522
523
|
/**
|
|
523
524
|
* Get list of available subform paths
|
|
@@ -539,7 +540,7 @@ export class JSONEvalCore {
|
|
|
539
540
|
*/
|
|
540
541
|
async getSchemaByPathsSubform({ subformPath, schemaPaths, format = 0, }) {
|
|
541
542
|
await this.init();
|
|
542
|
-
return this._instance.getSchemaByPathsSubformJS(subformPath,
|
|
543
|
+
return this._instance.getSchemaByPathsSubformJS(subformPath, typeof schemaPaths === "string" ? schemaPaths : JSONStringify(schemaPaths), format);
|
|
543
544
|
}
|
|
544
545
|
/**
|
|
545
546
|
* Check if a subform exists at the given path
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@json-eval-rs/webcore",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.65",
|
|
4
4
|
"description": "JSON Eval RS core JavaScript wrapper (internal package - not published)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,5 +26,8 @@
|
|
|
26
26
|
"url": "https://github.com/byrizki/jsoneval-rs.git",
|
|
27
27
|
"directory": "bindings/web/packages/core"
|
|
28
28
|
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"json-with-bigint": "^3.5.3"
|
|
31
|
+
},
|
|
29
32
|
"sideEffects": false
|
|
30
33
|
}
|