@json-eval-rs/webcore 0.0.44 → 0.0.45

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.
@@ -0,0 +1,520 @@
1
+ /**
2
+ * @json-eval-rs/webcore
3
+ * High-level JavaScript API for JSON Eval RS WASM bindings
4
+ *
5
+ * This package provides a clean, ergonomic API that works with any WASM target:
6
+ */
7
+ /**
8
+ * Get the library version from the WASM module
9
+ * @param wasmModule - WASM module
10
+ * @returns Version string
11
+ */
12
+ export declare function getVersion(wasmModule: any): string;
13
+ /**
14
+ * Return format for path-based methods
15
+ */
16
+ export declare enum ReturnFormat {
17
+ /** Nested object preserving the path hierarchy (default) */
18
+ Nested = 0,
19
+ /** Flat object with dotted keys */
20
+ Flat = 1,
21
+ /** Array of values in the order of requested paths */
22
+ Array = 2
23
+ }
24
+ /**
25
+ * Validation error for a specific field
26
+ */
27
+ export interface ValidationError {
28
+ /** Field path with the error */
29
+ path: string;
30
+ /** Type of validation rule that failed (e.g., 'required', 'min', 'max', 'pattern') */
31
+ rule_type: string;
32
+ /** Error message */
33
+ message: string;
34
+ /** Optional error code */
35
+ code?: string;
36
+ /** Optional regex pattern (for pattern validation errors) */
37
+ pattern?: string;
38
+ /** Optional field value that failed validation (as string) */
39
+ field_value?: string;
40
+ /** Optional additional data context for the error */
41
+ data?: any;
42
+ }
43
+ /**
44
+ * Result of validation operation
45
+ */
46
+ export interface ValidationResult {
47
+ /** Whether any validation errors occurred */
48
+ has_error: boolean;
49
+ /** Array of validation errors */
50
+ errors: ValidationError[];
51
+ }
52
+ /**
53
+ * Dependent field change from evaluateDependents
54
+ */
55
+ export interface DependentChange {
56
+ /** Path of the dependent field (in dot notation) */
57
+ $ref: string;
58
+ /** Schema definition of the changed field */
59
+ $field?: any;
60
+ /** Schema definition of the parent field */
61
+ $parentField: any;
62
+ /** Whether this is a transitive dependency */
63
+ transitive: boolean;
64
+ /** If true, the field was cleared */
65
+ clear?: boolean;
66
+ /** New value of the field (if changed) */
67
+ value?: any;
68
+ }
69
+ /**
70
+ * Options for creating a JSONEval instance
71
+ */
72
+ export interface JSONEvalOptions {
73
+ /** JSON schema object */
74
+ schema: any;
75
+ /** Optional context data */
76
+ context?: any;
77
+ /** Optional initial data */
78
+ data?: any;
79
+ /** If true, schema is treated as a cache key */
80
+ fromCache?: boolean;
81
+ }
82
+ /**
83
+ * Options for validation
84
+ */
85
+ export interface ValidateOptions {
86
+ /** JSON data to validate */
87
+ data: any;
88
+ /** Optional context data */
89
+ context?: any;
90
+ }
91
+ /**
92
+ * Options for evaluation
93
+ */
94
+ export interface EvaluateOptions {
95
+ /** JSON data to evaluate */
96
+ data: any;
97
+ /** Optional context data */
98
+ context?: any;
99
+ /** Optional array of paths for selective evaluation */
100
+ paths?: string[];
101
+ }
102
+ /**
103
+ * Options for evaluating dependents
104
+ */
105
+ export interface EvaluateDependentsOptions {
106
+ /** Array of field paths that changed */
107
+ changedPaths: string[];
108
+ /** Updated JSON data */
109
+ data?: any;
110
+ /** Optional context data */
111
+ context?: any;
112
+ /** If true, performs full evaluation after processing dependents */
113
+ reEvaluate?: boolean;
114
+ }
115
+ /**
116
+ * Options for getting evaluated schema
117
+ */
118
+ export interface GetEvaluatedSchemaOptions {
119
+ /** Whether to skip layout resolution */
120
+ skipLayout?: boolean;
121
+ }
122
+ /**
123
+ * Options for getting a value by path from evaluated schema
124
+ */
125
+ export interface GetValueByPathOptions {
126
+ /** Dotted path to the value */
127
+ path: string;
128
+ /** Whether to skip layout resolution */
129
+ skipLayout?: boolean;
130
+ }
131
+ /**
132
+ * Options for getting values by multiple paths from evaluated schema
133
+ */
134
+ export interface GetValueByPathsOptions {
135
+ /** Array of dotted paths to retrieve */
136
+ paths: string[];
137
+ /** Whether to skip layout resolution */
138
+ skipLayout?: boolean;
139
+ /** Return format (Nested, Flat, or Array) */
140
+ format?: ReturnFormat;
141
+ }
142
+ /**
143
+ * Options for getting a value by path from schema
144
+ */
145
+ export interface GetSchemaByPathOptions {
146
+ /** Dotted path to the value */
147
+ path: string;
148
+ }
149
+ /**
150
+ * Options for getting values by multiple paths from schema
151
+ */
152
+ export interface GetSchemaByPathsOptions {
153
+ /** Array of dotted paths to retrieve */
154
+ paths: string[];
155
+ /** Return format (Nested, Flat, or Array) */
156
+ format?: ReturnFormat;
157
+ }
158
+ /**
159
+ * Options for reloading schema
160
+ */
161
+ export interface ReloadSchemaOptions {
162
+ /** New JSON schema */
163
+ schema: any;
164
+ /** Optional new context */
165
+ context?: any;
166
+ /** Optional new data */
167
+ data?: any;
168
+ }
169
+ /**
170
+ * Cache statistics
171
+ */
172
+ export interface CacheStats {
173
+ /** Number of cache hits */
174
+ hits: number;
175
+ /** Number of cache misses */
176
+ misses: number;
177
+ /** Number of cached entries */
178
+ entries: number;
179
+ }
180
+ /**
181
+ * Options for evaluating a subform
182
+ */
183
+ export interface EvaluateSubformOptions {
184
+ /** Path to the subform */
185
+ subformPath: string;
186
+ /** JSON data to evaluate */
187
+ data: any;
188
+ /** Optional context data */
189
+ context?: any;
190
+ /** Optional array of paths to evaluate */
191
+ paths?: string[];
192
+ }
193
+ /**
194
+ * Options for validating a subform
195
+ */
196
+ export interface ValidateSubformOptions {
197
+ /** Path to the subform */
198
+ subformPath: string;
199
+ /** JSON data to validate */
200
+ data: any;
201
+ /** Optional context data */
202
+ context?: any;
203
+ }
204
+ /**
205
+ * Options for evaluating dependents in a subform
206
+ */
207
+ export interface EvaluateDependentsSubformOptions {
208
+ /** Path to the subform */
209
+ subformPath: string;
210
+ /** Array of field paths that changed */
211
+ changedPaths: string[];
212
+ /** Updated JSON data */
213
+ data?: any;
214
+ /** Optional context data */
215
+ context?: any;
216
+ /** If true, performs full evaluation after processing dependents */
217
+ reEvaluate?: boolean;
218
+ }
219
+ /**
220
+ * Options for resolving layout in a subform
221
+ */
222
+ export interface ResolveLayoutSubformOptions {
223
+ /** Path to the subform */
224
+ subformPath: string;
225
+ /** Whether to evaluate after resolving layout */
226
+ evaluate?: boolean;
227
+ }
228
+ /**
229
+ * Options for getting evaluated schema from a subform
230
+ */
231
+ export interface GetEvaluatedSchemaSubformOptions {
232
+ /** Path to the subform */
233
+ subformPath: string;
234
+ /** Whether to resolve layout */
235
+ resolveLayout?: boolean;
236
+ }
237
+ /**
238
+ * Options for getting schema value from a subform
239
+ */
240
+ export interface GetSchemaValueSubformOptions {
241
+ /** Path to the subform */
242
+ subformPath: string;
243
+ }
244
+ /**
245
+ * Options for getting evaluated schema by path from a subform
246
+ */
247
+ export interface GetEvaluatedSchemaByPathSubformOptions {
248
+ /** Path to the subform */
249
+ subformPath: string;
250
+ /** Dotted path to the value within the subform */
251
+ schemaPath: string;
252
+ /** Whether to skip layout resolution */
253
+ skipLayout?: boolean;
254
+ }
255
+ /**
256
+ * Options for getting evaluated schema by multiple paths from a subform
257
+ */
258
+ export interface GetEvaluatedSchemaByPathsSubformOptions {
259
+ /** Path to the subform */
260
+ subformPath: string;
261
+ /** Array of dotted paths to retrieve within the subform */
262
+ schemaPaths: string[];
263
+ /** Whether to skip layout resolution */
264
+ skipLayout?: boolean;
265
+ /** Return format (Nested, Flat, or Array) */
266
+ format?: ReturnFormat;
267
+ }
268
+ /**
269
+ * Options for getting schema by path from a subform
270
+ */
271
+ export interface GetSchemaByPathSubformOptions {
272
+ /** Path to the subform */
273
+ subformPath: string;
274
+ /** Dotted path to the value within the subform */
275
+ schemaPath: string;
276
+ }
277
+ /**
278
+ * Options for getting schema by multiple paths from a subform
279
+ */
280
+ export interface GetSchemaByPathsSubformOptions {
281
+ /** Path to the subform */
282
+ subformPath: string;
283
+ /** Array of dotted paths to retrieve within the subform */
284
+ schemaPaths: string[];
285
+ /** Return format (Nested, Flat, or Array) */
286
+ format?: ReturnFormat;
287
+ }
288
+ /**
289
+ * Options for compiling and running logic
290
+ */
291
+ export interface CompileAndRunLogicOptions {
292
+ /** Logic expression as string or object */
293
+ logicStr: string | object;
294
+ /** Optional data context */
295
+ data?: any;
296
+ /** Optional context data */
297
+ context?: any;
298
+ }
299
+ /**
300
+ * JSONEval - High-level JavaScript API for JSON Eval RS
301
+ *
302
+ * This is an internal abstraction layer. Use specific packages instead:
303
+ * - @json-eval-rs/bundler (for bundlers like Webpack, Vite, Next.js)
304
+ * - @json-eval-rs/vanilla (for direct browser usage)
305
+ * - @json-eval-rs/node (for Node.js/SSR)
306
+ *
307
+ * @example
308
+ * ```js
309
+ * import { JSONEval } from '@json-eval-rs/webcore';
310
+ *
311
+ * const evaluator = new JSONEval({
312
+ * schema: { type: 'object', properties: { ... } }
313
+ * });
314
+ *
315
+ * await evaluator.init();
316
+ * const result = await evaluator.validate({ data: { name: 'John' } });
317
+ * ```
318
+ */
319
+ export declare class JSONEvalCore {
320
+ private _schema;
321
+ private _wasmModule;
322
+ private _context;
323
+ private _data;
324
+ private _instance;
325
+ private _ready;
326
+ private _isMsgpackSchema;
327
+ private _isFromCache;
328
+ /**
329
+ * @param wasmModule - WASM module (injected by wrapper package)
330
+ * @param options
331
+ */
332
+ constructor(wasmModule: any, { schema, context, data, fromCache }: JSONEvalOptions);
333
+ /**
334
+ * Initialize the WASM instance
335
+ * Call this before using other methods, or use the async methods which call it automatically
336
+ */
337
+ init(): Promise<void>;
338
+ /**
339
+ * Create a new JSONEval instance from a cached ParsedSchema
340
+ * Static factory method for convenience
341
+ *
342
+ * @param wasmModule - WASM module
343
+ * @param cacheKey - Cache key to lookup in ParsedSchemaCache
344
+ * @param context - Optional context data
345
+ * @param data - Optional initial data
346
+ * @returns New instance
347
+ */
348
+ static fromCache(wasmModule: any, cacheKey: string, context?: any, data?: any): JSONEvalCore;
349
+ /**
350
+ * Validate data against schema (returns parsed JavaScript object)
351
+ * Uses validateJS for Worker-safe serialization
352
+ */
353
+ validate({ data, context }: ValidateOptions): Promise<ValidationResult>;
354
+ /**
355
+ * Evaluate schema with data (returns parsed JavaScript object)
356
+ */
357
+ evaluate({ data, context, paths }: EvaluateOptions): Promise<any>;
358
+ /**
359
+ * Evaluate dependent fields (returns parsed JavaScript object, processes transitively)
360
+ */
361
+ evaluateDependents({ changedPaths, data, context, reEvaluate }: EvaluateDependentsOptions): Promise<DependentChange[]>;
362
+ /**
363
+ * Get evaluated schema
364
+ */
365
+ getEvaluatedSchema({ skipLayout }?: GetEvaluatedSchemaOptions): Promise<any>;
366
+ /**
367
+ * Get evaluated schema as MessagePack binary data
368
+ */
369
+ getEvaluatedSchemaMsgpack({ skipLayout }?: GetEvaluatedSchemaOptions): Promise<Uint8Array>;
370
+ /**
371
+ * Get schema values (evaluations ending with .value)
372
+ */
373
+ getSchemaValue(): Promise<any>;
374
+ /**
375
+ * Get evaluated schema without $params field
376
+ */
377
+ getEvaluatedSchemaWithoutParams({ skipLayout }?: GetEvaluatedSchemaOptions): Promise<any>;
378
+ /**
379
+ * Get a value from the evaluated schema using dotted path notation
380
+ */
381
+ getEvaluatedSchemaByPath({ path, skipLayout }: GetValueByPathOptions): Promise<any | null>;
382
+ /**
383
+ * Get values from the evaluated schema using multiple dotted path notations
384
+ * Returns data in the specified format (skips paths that are not found)
385
+ */
386
+ getEvaluatedSchemaByPaths({ paths, skipLayout, format }: GetValueByPathsOptions): Promise<any>;
387
+ /**
388
+ * Get a value from the schema using dotted path notation
389
+ */
390
+ getSchemaByPath({ path }: GetSchemaByPathOptions): Promise<any | null>;
391
+ /**
392
+ * Get values from the schema using multiple dotted path notations
393
+ * Returns data in the specified format (skips paths that are not found)
394
+ */
395
+ getSchemaByPaths({ paths, format }: GetSchemaByPathsOptions): Promise<any>;
396
+ /**
397
+ * Reload schema with new data
398
+ */
399
+ reloadSchema({ schema, context, data }: ReloadSchemaOptions): Promise<void>;
400
+ /**
401
+ * Reload schema from MessagePack bytes
402
+ */
403
+ reloadSchemaMsgpack(schemaMsgpack: Uint8Array, context?: any, data?: any): Promise<void>;
404
+ /**
405
+ * Reload schema from ParsedSchemaCache using a cache key
406
+ */
407
+ reloadSchemaFromCache(cacheKey: string, context?: any, data?: any): Promise<void>;
408
+ /**
409
+ * Get cache statistics
410
+ */
411
+ cacheStats(): Promise<CacheStats>;
412
+ /**
413
+ * Clear the evaluation cache
414
+ */
415
+ clearCache(): Promise<void>;
416
+ /**
417
+ * Get the number of cached entries
418
+ */
419
+ cacheLen(): Promise<number>;
420
+ /**
421
+ * Enable evaluation caching
422
+ */
423
+ enableCache(): Promise<void>;
424
+ /**
425
+ * Disable evaluation caching
426
+ */
427
+ disableCache(): Promise<void>;
428
+ /**
429
+ * Check if evaluation caching is enabled
430
+ */
431
+ isCacheEnabled(): boolean;
432
+ /**
433
+ * Resolve layout with optional evaluation
434
+ */
435
+ resolveLayout(options?: {
436
+ evaluate?: boolean;
437
+ }): Promise<void>;
438
+ /**
439
+ * Set timezone offset for datetime operations (TODAY, NOW)
440
+ * @param offsetMinutes - Timezone offset in minutes from UTC
441
+ * (e.g., 420 for UTC+7, -300 for UTC-5)
442
+ * Pass null or undefined to reset to UTC
443
+ */
444
+ setTimezoneOffset(offsetMinutes: number | null | undefined): void;
445
+ /**
446
+ * Compile and run JSON logic from a JSON logic string
447
+ */
448
+ compileAndRunLogic({ logicStr, data, context }: CompileAndRunLogicOptions): Promise<any>;
449
+ /**
450
+ * Compile JSON logic and return a global ID
451
+ */
452
+ compileLogic(logicStr: string | object): Promise<number>;
453
+ /**
454
+ * Run pre-compiled logic by ID
455
+ */
456
+ runLogic(logicId: number, data?: any, context?: any): Promise<any>;
457
+ /**
458
+ * Validate data against schema rules with optional path filtering
459
+ */
460
+ validatePaths({ data, context, paths }: EvaluateOptions): Promise<ValidationResult>;
461
+ /**
462
+ * Evaluate a subform with data
463
+ */
464
+ evaluateSubform({ subformPath, data, context, paths }: EvaluateSubformOptions): Promise<void>;
465
+ /**
466
+ * Validate subform data against its schema rules
467
+ */
468
+ validateSubform({ subformPath, data, context }: ValidateSubformOptions): Promise<ValidationResult>;
469
+ /**
470
+ * Evaluate dependent fields in subform
471
+ */
472
+ evaluateDependentsSubform({ subformPath, changedPaths, data, context, reEvaluate }: EvaluateDependentsSubformOptions): Promise<DependentChange[]>;
473
+ /**
474
+ * Resolve layout for subform
475
+ */
476
+ resolveLayoutSubform({ subformPath, evaluate }: ResolveLayoutSubformOptions): Promise<void>;
477
+ /**
478
+ * Get evaluated schema from subform
479
+ */
480
+ getEvaluatedSchemaSubform({ subformPath, resolveLayout }: GetEvaluatedSchemaSubformOptions): Promise<any>;
481
+ /**
482
+ * Get schema value from subform (all .value fields)
483
+ */
484
+ getSchemaValueSubform({ subformPath }: GetSchemaValueSubformOptions): Promise<any>;
485
+ /**
486
+ * Get evaluated schema without $params from subform
487
+ */
488
+ getEvaluatedSchemaWithoutParamsSubform({ subformPath, resolveLayout }: GetEvaluatedSchemaSubformOptions): Promise<any>;
489
+ /**
490
+ * Get evaluated schema by specific path from subform
491
+ */
492
+ getEvaluatedSchemaByPathSubform({ subformPath, schemaPath, skipLayout }: GetEvaluatedSchemaByPathSubformOptions): Promise<any | null>;
493
+ /**
494
+ * Get evaluated schema by multiple paths from subform
495
+ * Returns data in the specified format (skips paths that are not found)
496
+ */
497
+ getEvaluatedSchemaByPathsSubform({ subformPath, schemaPaths, skipLayout, format }: GetEvaluatedSchemaByPathsSubformOptions): Promise<any>;
498
+ /**
499
+ * Get list of available subform paths
500
+ */
501
+ getSubformPaths(): Promise<string[]>;
502
+ /**
503
+ * Get schema by specific path from subform
504
+ */
505
+ getSchemaByPathSubform({ subformPath, schemaPath }: GetSchemaByPathSubformOptions): Promise<any | null>;
506
+ /**
507
+ * Get schema by multiple paths from subform
508
+ * Returns data in the specified format (skips paths that are not found)
509
+ */
510
+ getSchemaByPathsSubform({ subformPath, schemaPaths, format }: GetSchemaByPathsSubformOptions): Promise<any>;
511
+ /**
512
+ * Check if a subform exists at the given path
513
+ */
514
+ hasSubform(subformPath: string): Promise<boolean>;
515
+ /**
516
+ * Free WASM resources
517
+ */
518
+ free(): void;
519
+ }
520
+ export default JSONEvalCore;