@json-eval-rs/webcore 0.0.47 → 0.0.49

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 CHANGED
@@ -70,13 +70,28 @@ export interface DependentChange {
70
70
  * Options for creating a JSONEval instance
71
71
  */
72
72
  export interface JSONEvalOptions {
73
- /** JSON schema object */
73
+ /**
74
+ * JSON schema object or MessagePack binary or cache key string.
75
+ * - If object: Standard JSON Schema
76
+ * - If Uint8Array: MessagePack encoded schema
77
+ * - If string (and fromCache=true): Cache key for pre-parsed schema
78
+ */
74
79
  schema: any;
75
- /** Optional context data */
80
+ /**
81
+ * Optional context data accessible via $context in logic.
82
+ * Useful for user sessions, environment variables, etc.
83
+ */
76
84
  context?: any;
77
- /** Optional initial data */
85
+ /**
86
+ * Optional initial data object to evaluate against.
87
+ * Can be updated later with reloadSchema.
88
+ */
78
89
  data?: any;
79
- /** If true, schema is treated as a cache key */
90
+ /**
91
+ * If true, the `schema` parameter is treated as a string cache key
92
+ * to lookup a pre-parsed schema from the global cache.
93
+ * Default: false
94
+ */
80
95
  fromCache?: boolean;
81
96
  }
82
97
  /**
@@ -317,17 +332,28 @@ export interface CompileAndRunLogicOptions {
317
332
  * ```
318
333
  */
319
334
  export declare class JSONEvalCore {
335
+ /** Internal storage for the schema (JSON, MsgPack, or Cache Key) */
320
336
  private _schema;
337
+ /** Reference to the loaded WASM module */
321
338
  private _wasmModule;
339
+ /** Current context data */
322
340
  private _context;
341
+ /** Current evaluation data */
323
342
  private _data;
343
+ /** The underlying WASM JSONEval instance */
324
344
  private _instance;
345
+ /** Initialization state flag */
325
346
  private _ready;
347
+ /** Flag indicating if schema provided is binary MessagePack */
326
348
  private _isMsgpackSchema;
349
+ /** Flag indicating if schema is a cache key reference */
327
350
  private _isFromCache;
328
351
  /**
329
- * @param wasmModule - WASM module (injected by wrapper package)
330
- * @param options
352
+ * Create a new JSONEval Core instance.
353
+ * Does not initialize WASM immediately; wait for `init()` or call async methods.
354
+ *
355
+ * @param wasmModule - The loaded WASM module (provided by wrapper packages like @json-eval-rs/node or /vanilla)
356
+ * @param options - Configuration options containing schema, data, and context
331
357
  */
332
358
  constructor(wasmModule: any, { schema, context, data, fromCache }: JSONEvalOptions);
333
359
  /**
package/dist/index.js CHANGED
@@ -49,11 +49,16 @@ export var ReturnFormat;
49
49
  */
50
50
  export class JSONEvalCore {
51
51
  /**
52
- * @param wasmModule - WASM module (injected by wrapper package)
53
- * @param options
52
+ * Create a new JSONEval Core instance.
53
+ * Does not initialize WASM immediately; wait for `init()` or call async methods.
54
+ *
55
+ * @param wasmModule - The loaded WASM module (provided by wrapper packages like @json-eval-rs/node or /vanilla)
56
+ * @param options - Configuration options containing schema, data, and context
54
57
  */
55
58
  constructor(wasmModule, { schema, context, data, fromCache = false }) {
59
+ /** The underlying WASM JSONEval instance */
56
60
  this._instance = null;
61
+ /** Initialization state flag */
57
62
  this._ready = false;
58
63
  this._schema = schema;
59
64
  this._wasmModule = wasmModule;
@@ -146,8 +151,9 @@ export class JSONEvalCore {
146
151
  async evaluateDependents({ changedPaths, data, context, reEvaluate = false }) {
147
152
  await this.init();
148
153
  try {
149
- return this._instance.evaluateDependentsJS(changedPaths, // Pass array directly
150
- data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null, reEvaluate);
154
+ // Ensure paths is an array for WASM
155
+ const paths = Array.isArray(changedPaths) ? changedPaths : [changedPaths];
156
+ return this._instance.evaluateDependentsJS(JSON.stringify(paths), data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null, reEvaluate);
151
157
  }
152
158
  catch (error) {
153
159
  throw new Error(`Dependent evaluation failed: ${error.message || error}`);
@@ -194,7 +200,7 @@ export class JSONEvalCore {
194
200
  */
195
201
  async getEvaluatedSchemaByPaths({ paths, skipLayout = false, format = 0 }) {
196
202
  await this.init();
197
- return this._instance.getEvaluatedSchemaByPathsJS(paths, skipLayout, format);
203
+ return this._instance.getEvaluatedSchemaByPathsJS(JSON.stringify(paths), skipLayout, format);
198
204
  }
199
205
  /**
200
206
  * Get a value from the schema using dotted path notation
@@ -209,7 +215,7 @@ export class JSONEvalCore {
209
215
  */
210
216
  async getSchemaByPaths({ paths, format = 0 }) {
211
217
  await this.init();
212
- return this._instance.getSchemaByPathsJS(paths, format);
218
+ return this._instance.getSchemaByPathsJS(JSON.stringify(paths), format);
213
219
  }
214
220
  /**
215
221
  * Reload schema with new data
@@ -342,8 +348,7 @@ export class JSONEvalCore {
342
348
  await this.init();
343
349
  const logic = typeof logicStr === 'string' ? logicStr : JSON.stringify(logicStr);
344
350
  const result = await this._instance.compileAndRunLogic(logic, data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null);
345
- // Parse result if it's a string
346
- return typeof result === 'string' ? JSON.parse(result) : result;
351
+ return result;
347
352
  }
348
353
  /**
349
354
  * Compile JSON logic and return a global ID
@@ -359,8 +364,7 @@ export class JSONEvalCore {
359
364
  async runLogic(logicId, data, context) {
360
365
  await this.init();
361
366
  const result = await this._instance.runLogic(logicId, data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null);
362
- // Parse result if it's a string
363
- return typeof result === 'string' ? JSON.parse(result) : result;
367
+ return result;
364
368
  }
365
369
  /**
366
370
  * Validate data against schema rules with optional path filtering
@@ -399,8 +403,7 @@ export class JSONEvalCore {
399
403
  await this.init();
400
404
  // For backward compatibility, accept single changedPath too (though types say array)
401
405
  const paths = Array.isArray(changedPaths) ? changedPaths : [changedPaths];
402
- return this._instance.evaluateDependentsSubformJS(subformPath, paths, // Pass array directly (WASM now accepts array)
403
- data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null);
406
+ return this._instance.evaluateDependentsSubformJS(subformPath, JSON.stringify(paths), data ? JSON.stringify(data) : null, context ? JSON.stringify(context) : null);
404
407
  }
405
408
  /**
406
409
  * Resolve layout for subform
@@ -443,7 +446,7 @@ export class JSONEvalCore {
443
446
  */
444
447
  async getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout = false, format = 0 }) {
445
448
  await this.init();
446
- return this._instance.getEvaluatedSchemaByPathsSubformJS(subformPath, schemaPaths, skipLayout, format);
449
+ return this._instance.getEvaluatedSchemaByPathsSubformJS(subformPath, JSON.stringify(schemaPaths), skipLayout, format);
447
450
  }
448
451
  /**
449
452
  * Get list of available subform paths
@@ -465,7 +468,7 @@ export class JSONEvalCore {
465
468
  */
466
469
  async getSchemaByPathsSubform({ subformPath, schemaPaths, format = 0 }) {
467
470
  await this.init();
468
- return this._instance.getSchemaByPathsSubformJS(subformPath, schemaPaths, format);
471
+ return this._instance.getSchemaByPathsSubformJS(subformPath, JSON.stringify(schemaPaths), format);
469
472
  }
470
473
  /**
471
474
  * 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.47",
3
+ "version": "0.0.49",
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",