@goplasmatic/datalogic 4.0.6 → 4.0.8

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/README.md CHANGED
@@ -19,15 +19,15 @@ import init, { evaluate, CompiledRule } from '@goplasmatic/datalogic';
19
19
  await init();
20
20
 
21
21
  // Simple evaluation
22
- const result = evaluate('{"==": [1, 1]}', '{}');
22
+ const result = evaluate('{"==": [1, 1]}', '{}', false);
23
23
  console.log(result); // "true"
24
24
 
25
25
  // With data
26
- const result2 = evaluate('{"var": "user.age"}', '{"user": {"age": 25}}');
26
+ const result2 = evaluate('{"var": "user.age"}', '{"user": {"age": 25}}', false);
27
27
  console.log(result2); // "25"
28
28
 
29
29
  // Compiled rule for repeated evaluation (better performance)
30
- const rule = new CompiledRule('{"+": [{"var": "a"}, {"var": "b"}]}');
30
+ const rule = new CompiledRule('{"+": [{"var": "a"}, {"var": "b"}]}', false);
31
31
  console.log(rule.evaluate('{"a": 1, "b": 2}')); // "3"
32
32
  console.log(rule.evaluate('{"a": 10, "b": 20}')); // "30"
33
33
  ```
@@ -45,7 +45,7 @@ async function run() {
45
45
  await init();
46
46
 
47
47
  // Now you can use evaluate and CompiledRule
48
- const result = evaluate('{"and": [true, {"var": "active"}]}', '{"active": true}');
48
+ const result = evaluate('{"and": [true, {"var": "active"}]}', '{"active": true}', false);
49
49
  console.log(result); // "true"
50
50
  }
51
51
 
@@ -60,11 +60,11 @@ run();
60
60
  import { evaluate, CompiledRule } from '@goplasmatic/datalogic';
61
61
 
62
62
  // No init() needed for Node.js
63
- const result = evaluate('{"==": [1, 1]}', '{}');
63
+ const result = evaluate('{"==": [1, 1]}', '{}', false);
64
64
  console.log(result); // "true"
65
65
 
66
66
  // Compiled rule
67
- const rule = new CompiledRule('{"if": [{"var": "premium"}, "VIP", "Standard"]}');
67
+ const rule = new CompiledRule('{"if": [{"var": "premium"}, "VIP", "Standard"]}', false);
68
68
  console.log(rule.evaluate('{"premium": true}')); // "\"VIP\""
69
69
  console.log(rule.evaluate('{"premium": false}')); // "\"Standard\""
70
70
  ```
@@ -77,7 +77,7 @@ import init, { evaluate, CompiledRule } from '@goplasmatic/datalogic';
77
77
  // For bundlers, you may need to initialize
78
78
  await init();
79
79
 
80
- const result = evaluate('{">=": [{"var": "score"}, 80]}', '{"score": 85}');
80
+ const result = evaluate('{">=": [{"var": "score"}, 80]}', '{"score": 85}', false);
81
81
  console.log(result); // "true"
82
82
  ```
83
83
 
@@ -98,31 +98,37 @@ import { evaluate } from '@goplasmatic/datalogic/nodejs';
98
98
 
99
99
  ## API Reference
100
100
 
101
- ### `evaluate(logic: string, data: string): string`
101
+ ### `evaluate(logic: string, data: string, preserve_structure: boolean): string`
102
102
 
103
103
  Evaluate a JSONLogic expression against data.
104
104
 
105
105
  **Parameters:**
106
106
  - `logic` - JSON string containing the JSONLogic expression
107
107
  - `data` - JSON string containing the data to evaluate against
108
+ - `preserve_structure` - If `true`, preserves object structure for JSON templates with embedded JSONLogic (templating mode)
108
109
 
109
110
  **Returns:** JSON string result
110
111
 
111
112
  **Throws:** Error string on invalid JSON or evaluation error
112
113
 
113
114
  ```javascript
114
- evaluate('{"==": [{"var": "x"}, 5]}', '{"x": 5}'); // "true"
115
- evaluate('{"+": [1, 2, 3]}', '{}'); // "6"
116
- evaluate('{"map": [[1,2,3], {"+": [{"var": ""}, 1]}]}', '{}'); // "[2,3,4]"
115
+ evaluate('{"==": [{"var": "x"}, 5]}', '{"x": 5}', false); // "true"
116
+ evaluate('{"+": [1, 2, 3]}', '{}', false); // "6"
117
+ evaluate('{"map": [[1,2,3], {"+": [{"var": ""}, 1]}]}', '{}', false); // "[2,3,4]"
118
+
119
+ // With preserve_structure for templating
120
+ evaluate('{"name": {"var": "user"}, "active": true}', '{"user": "Alice"}', true);
121
+ // '{"name":"Alice","active":true}'
117
122
  ```
118
123
 
119
- ### `evaluate_with_trace(logic: string, data: string): string`
124
+ ### `evaluate_with_trace(logic: string, data: string, preserve_structure: boolean): string`
120
125
 
121
126
  Evaluate with execution trace for debugging. Returns detailed step-by-step information about how the expression was evaluated.
122
127
 
123
128
  **Parameters:**
124
129
  - `logic` - JSON string containing the JSONLogic expression
125
130
  - `data` - JSON string containing the data to evaluate against
131
+ - `preserve_structure` - If `true`, preserves object structure for JSON templates with embedded JSONLogic (templating mode)
126
132
 
127
133
  **Returns:** JSON string containing `TracedResult` with:
128
134
  - `result` - The evaluation result
@@ -130,7 +136,7 @@ Evaluate with execution trace for debugging. Returns detailed step-by-step infor
130
136
  - `steps` - Array of execution steps with context and intermediate results
131
137
 
132
138
  ```javascript
133
- const trace = evaluate_with_trace('{"and": [true, {"var": "x"}]}', '{"x": true}');
139
+ const trace = evaluate_with_trace('{"and": [true, {"var": "x"}]}', '{"x": true}', false);
134
140
  console.log(JSON.parse(trace));
135
141
  // {
136
142
  // "result": true,
@@ -143,12 +149,16 @@ console.log(JSON.parse(trace));
143
149
 
144
150
  A compiled JSONLogic rule for repeated evaluation. Pre-compiling rules provides better performance when evaluating the same logic against different data.
145
151
 
146
- #### `new CompiledRule(logic: string)`
152
+ #### `new CompiledRule(logic: string, preserve_structure: boolean)`
147
153
 
148
154
  Create a new compiled rule.
149
155
 
156
+ **Parameters:**
157
+ - `logic` - JSON string containing the JSONLogic expression
158
+ - `preserve_structure` - If `true`, preserves object structure for JSON templates with embedded JSONLogic (templating mode)
159
+
150
160
  ```javascript
151
- const rule = new CompiledRule('{">=": [{"var": "age"}, 18]}');
161
+ const rule = new CompiledRule('{">=": [{"var": "age"}, 18]}', false);
152
162
  ```
153
163
 
154
164
  #### `evaluate(data: string): string`
@@ -206,7 +216,7 @@ rustup target add wasm32-unknown-unknown
206
216
  ### Build
207
217
 
208
218
  ```bash
209
- cd datalogic-wasm
219
+ cd wasm
210
220
  ./build.sh
211
221
  ```
212
222
 
@@ -226,8 +236,13 @@ wasm-pack test --headless --firefox
226
236
 
227
237
  Apache-2.0
228
238
 
239
+ ## Documentation
240
+
241
+ For complete documentation including advanced usage, framework integration, and API details, see the [full documentation](https://goplasmatic.github.io/datalogic-rs/javascript/installation.html).
242
+
229
243
  ## Links
230
244
 
231
245
  - [GitHub Repository](https://github.com/GoPlasmatic/datalogic-rs)
246
+ - [Full Documentation](https://goplasmatic.github.io/datalogic-rs/)
247
+ - [Online Playground](https://goplasmatic.github.io/datalogic-rs/playground/)
232
248
  - [JSONLogic Specification](https://jsonlogic.com/)
233
- - [Documentation](https://goplasmatic.github.io/datalogic-rs/)
@@ -9,8 +9,9 @@ export class CompiledRule {
9
9
  *
10
10
  * # Arguments
11
11
  * * `logic` - JSON string containing the JSONLogic expression
12
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
12
13
  */
13
- constructor(logic: string);
14
+ constructor(logic: string, preserve_structure: boolean);
14
15
  /**
15
16
  * Evaluate the compiled rule against data.
16
17
  *
@@ -29,11 +30,12 @@ export class CompiledRule {
29
30
  * # Arguments
30
31
  * * `logic` - JSON string containing the JSONLogic expression
31
32
  * * `data` - JSON string containing the data to evaluate against
33
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
32
34
  *
33
35
  * # Returns
34
36
  * JSON string result or error message
35
37
  */
36
- export function evaluate(logic: string, data: string): string;
38
+ export function evaluate(logic: string, data: string, preserve_structure: boolean): string;
37
39
 
38
40
  /**
39
41
  * Evaluate a JSONLogic expression with execution trace for debugging.
@@ -44,6 +46,7 @@ export function evaluate(logic: string, data: string): string;
44
46
  * # Arguments
45
47
  * * `logic` - JSON string containing the JSONLogic expression
46
48
  * * `data` - JSON string containing the data to evaluate against
49
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
47
50
  *
48
51
  * # Returns
49
52
  * JSON string containing TracedResult (result, expression_tree, steps) or error message
@@ -64,6 +67,6 @@ export function evaluate(logic: string, data: string): string;
64
67
  * }
65
68
  * ```
66
69
  */
67
- export function evaluate_with_trace(logic: string, data: string): string;
70
+ export function evaluate_with_trace(logic: string, data: string, preserve_structure: boolean): string;
68
71
 
69
72
  export function init(): void;
@@ -3,6 +3,21 @@ export function __wbg_set_wasm(val) {
3
3
  wasm = val;
4
4
  }
5
5
 
6
+ function addHeapObject(obj) {
7
+ if (heap_next === heap.length) heap.push(heap.length + 1);
8
+ const idx = heap_next;
9
+ heap_next = heap[idx];
10
+
11
+ heap[idx] = obj;
12
+ return idx;
13
+ }
14
+
15
+ function dropObject(idx) {
16
+ if (idx < 132) return;
17
+ heap[idx] = heap_next;
18
+ heap_next = idx;
19
+ }
20
+
6
21
  let cachedDataViewMemory0 = null;
7
22
  function getDataViewMemory0() {
8
23
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
@@ -24,6 +39,13 @@ function getUint8ArrayMemory0() {
24
39
  return cachedUint8ArrayMemory0;
25
40
  }
26
41
 
42
+ function getObject(idx) { return heap[idx]; }
43
+
44
+ let heap = new Array(128).fill(undefined);
45
+ heap.push(undefined, null, true, false);
46
+
47
+ let heap_next = heap.length;
48
+
27
49
  function passStringToWasm0(arg, malloc, realloc) {
28
50
  if (realloc === undefined) {
29
51
  const buf = cachedTextEncoder.encode(arg);
@@ -61,10 +83,10 @@ function passStringToWasm0(arg, malloc, realloc) {
61
83
  return ptr;
62
84
  }
63
85
 
64
- function takeFromExternrefTable0(idx) {
65
- const value = wasm.__wbindgen_externrefs.get(idx);
66
- wasm.__externref_table_dealloc(idx);
67
- return value;
86
+ function takeObject(idx) {
87
+ const ret = getObject(idx);
88
+ dropObject(idx);
89
+ return ret;
68
90
  }
69
91
 
70
92
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
@@ -122,18 +144,28 @@ export class CompiledRule {
122
144
  *
123
145
  * # Arguments
124
146
  * * `logic` - JSON string containing the JSONLogic expression
147
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
125
148
  * @param {string} logic
149
+ * @param {boolean} preserve_structure
126
150
  */
127
- constructor(logic) {
128
- const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
129
- const len0 = WASM_VECTOR_LEN;
130
- const ret = wasm.compiledrule_new(ptr0, len0);
131
- if (ret[2]) {
132
- throw takeFromExternrefTable0(ret[1]);
151
+ constructor(logic, preserve_structure) {
152
+ try {
153
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
154
+ const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
155
+ const len0 = WASM_VECTOR_LEN;
156
+ wasm.compiledrule_new(retptr, ptr0, len0, preserve_structure);
157
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
158
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
159
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
160
+ if (r2) {
161
+ throw takeObject(r1);
162
+ }
163
+ this.__wbg_ptr = r0 >>> 0;
164
+ CompiledRuleFinalization.register(this, this.__wbg_ptr, this);
165
+ return this;
166
+ } finally {
167
+ wasm.__wbindgen_add_to_stack_pointer(16);
133
168
  }
134
- this.__wbg_ptr = ret[0] >>> 0;
135
- CompiledRuleFinalization.register(this, this.__wbg_ptr, this);
136
- return this;
137
169
  }
138
170
  /**
139
171
  * Evaluate the compiled rule against data.
@@ -150,20 +182,26 @@ export class CompiledRule {
150
182
  let deferred3_0;
151
183
  let deferred3_1;
152
184
  try {
153
- const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
185
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
186
+ const ptr0 = passStringToWasm0(data, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
154
187
  const len0 = WASM_VECTOR_LEN;
155
- const ret = wasm.compiledrule_evaluate(this.__wbg_ptr, ptr0, len0);
156
- var ptr2 = ret[0];
157
- var len2 = ret[1];
158
- if (ret[3]) {
188
+ wasm.compiledrule_evaluate(retptr, this.__wbg_ptr, ptr0, len0);
189
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
190
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
191
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
192
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
193
+ var ptr2 = r0;
194
+ var len2 = r1;
195
+ if (r3) {
159
196
  ptr2 = 0; len2 = 0;
160
- throw takeFromExternrefTable0(ret[2]);
197
+ throw takeObject(r2);
161
198
  }
162
199
  deferred3_0 = ptr2;
163
200
  deferred3_1 = len2;
164
201
  return getStringFromWasm0(ptr2, len2);
165
202
  } finally {
166
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
203
+ wasm.__wbindgen_add_to_stack_pointer(16);
204
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
167
205
  }
168
206
  }
169
207
  }
@@ -175,33 +213,41 @@ if (Symbol.dispose) CompiledRule.prototype[Symbol.dispose] = CompiledRule.protot
175
213
  * # Arguments
176
214
  * * `logic` - JSON string containing the JSONLogic expression
177
215
  * * `data` - JSON string containing the data to evaluate against
216
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
178
217
  *
179
218
  * # Returns
180
219
  * JSON string result or error message
181
220
  * @param {string} logic
182
221
  * @param {string} data
222
+ * @param {boolean} preserve_structure
183
223
  * @returns {string}
184
224
  */
185
- export function evaluate(logic, data) {
225
+ export function evaluate(logic, data, preserve_structure) {
186
226
  let deferred4_0;
187
227
  let deferred4_1;
188
228
  try {
189
- const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
229
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
230
+ const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
190
231
  const len0 = WASM_VECTOR_LEN;
191
- const ptr1 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
232
+ const ptr1 = passStringToWasm0(data, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
192
233
  const len1 = WASM_VECTOR_LEN;
193
- const ret = wasm.evaluate(ptr0, len0, ptr1, len1);
194
- var ptr3 = ret[0];
195
- var len3 = ret[1];
196
- if (ret[3]) {
234
+ wasm.evaluate(retptr, ptr0, len0, ptr1, len1, preserve_structure);
235
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
236
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
237
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
238
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
239
+ var ptr3 = r0;
240
+ var len3 = r1;
241
+ if (r3) {
197
242
  ptr3 = 0; len3 = 0;
198
- throw takeFromExternrefTable0(ret[2]);
243
+ throw takeObject(r2);
199
244
  }
200
245
  deferred4_0 = ptr3;
201
246
  deferred4_1 = len3;
202
247
  return getStringFromWasm0(ptr3, len3);
203
248
  } finally {
204
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
249
+ wasm.__wbindgen_add_to_stack_pointer(16);
250
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
205
251
  }
206
252
  }
207
253
 
@@ -214,6 +260,7 @@ export function evaluate(logic, data) {
214
260
  * # Arguments
215
261
  * * `logic` - JSON string containing the JSONLogic expression
216
262
  * * `data` - JSON string containing the data to evaluate against
263
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
217
264
  *
218
265
  * # Returns
219
266
  * JSON string containing TracedResult (result, expression_tree, steps) or error message
@@ -235,28 +282,35 @@ export function evaluate(logic, data) {
235
282
  * ```
236
283
  * @param {string} logic
237
284
  * @param {string} data
285
+ * @param {boolean} preserve_structure
238
286
  * @returns {string}
239
287
  */
240
- export function evaluate_with_trace(logic, data) {
288
+ export function evaluate_with_trace(logic, data, preserve_structure) {
241
289
  let deferred4_0;
242
290
  let deferred4_1;
243
291
  try {
244
- const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
292
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
293
+ const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
245
294
  const len0 = WASM_VECTOR_LEN;
246
- const ptr1 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
295
+ const ptr1 = passStringToWasm0(data, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
247
296
  const len1 = WASM_VECTOR_LEN;
248
- const ret = wasm.evaluate_with_trace(ptr0, len0, ptr1, len1);
249
- var ptr3 = ret[0];
250
- var len3 = ret[1];
251
- if (ret[3]) {
297
+ wasm.evaluate_with_trace(retptr, ptr0, len0, ptr1, len1, preserve_structure);
298
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
299
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
300
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
301
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
302
+ var ptr3 = r0;
303
+ var len3 = r1;
304
+ if (r3) {
252
305
  ptr3 = 0; len3 = 0;
253
- throw takeFromExternrefTable0(ret[2]);
306
+ throw takeObject(r2);
254
307
  }
255
308
  deferred4_0 = ptr3;
256
309
  deferred4_1 = len3;
257
310
  return getStringFromWasm0(ptr3, len3);
258
311
  } finally {
259
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
312
+ wasm.__wbindgen_add_to_stack_pointer(16);
313
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
260
314
  }
261
315
  }
262
316
 
@@ -276,18 +330,28 @@ export function __wbg_error_7534b8e9a36f1ab4(arg0, arg1) {
276
330
  deferred0_1 = arg1;
277
331
  console.error(getStringFromWasm0(arg0, arg1));
278
332
  } finally {
279
- wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
333
+ wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
280
334
  }
281
335
  };
282
336
 
337
+ export function __wbg_getTime_ad1e9878a735af08(arg0) {
338
+ const ret = getObject(arg0).getTime();
339
+ return ret;
340
+ };
341
+
342
+ export function __wbg_new_0_23cedd11d9b40c9d() {
343
+ const ret = new Date();
344
+ return addHeapObject(ret);
345
+ };
346
+
283
347
  export function __wbg_new_8a6f238a6ece86ea() {
284
348
  const ret = new Error();
285
- return ret;
349
+ return addHeapObject(ret);
286
350
  };
287
351
 
288
352
  export function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
289
- const ret = arg1.stack;
290
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
353
+ const ret = getObject(arg1).stack;
354
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
291
355
  const len1 = WASM_VECTOR_LEN;
292
356
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
293
357
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
@@ -296,15 +360,9 @@ export function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
296
360
  export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
297
361
  // Cast intrinsic for `Ref(String) -> Externref`.
298
362
  const ret = getStringFromWasm0(arg0, arg1);
299
- return ret;
363
+ return addHeapObject(ret);
300
364
  };
301
365
 
302
- export function __wbindgen_init_externref_table() {
303
- const table = wasm.__wbindgen_externrefs;
304
- const offset = table.grow(4);
305
- table.set(0, undefined);
306
- table.set(offset + 0, undefined);
307
- table.set(offset + 1, null);
308
- table.set(offset + 2, true);
309
- table.set(offset + 3, false);
366
+ export function __wbindgen_object_drop_ref(arg0) {
367
+ takeObject(arg0);
310
368
  };
Binary file
@@ -2,14 +2,13 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_compiledrule_free: (a: number, b: number) => void;
5
- export const compiledrule_evaluate: (a: number, b: number, c: number) => [number, number, number, number];
6
- export const compiledrule_new: (a: number, b: number) => [number, number, number];
7
- export const evaluate: (a: number, b: number, c: number, d: number) => [number, number, number, number];
8
- export const evaluate_with_trace: (a: number, b: number, c: number, d: number) => [number, number, number, number];
5
+ export const compiledrule_evaluate: (a: number, b: number, c: number, d: number) => void;
6
+ export const compiledrule_new: (a: number, b: number, c: number, d: number) => void;
7
+ export const evaluate: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
8
+ export const evaluate_with_trace: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
9
9
  export const init: () => void;
10
- export const __wbindgen_free: (a: number, b: number, c: number) => void;
11
- export const __wbindgen_malloc: (a: number, b: number) => number;
12
- export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
13
- export const __wbindgen_externrefs: WebAssembly.Table;
14
- export const __externref_table_dealloc: (a: number) => void;
10
+ export const __wbindgen_export: (a: number, b: number, c: number) => void;
11
+ export const __wbindgen_export2: (a: number, b: number) => number;
12
+ export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
13
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
15
14
  export const __wbindgen_start: () => void;
@@ -9,8 +9,9 @@ export class CompiledRule {
9
9
  *
10
10
  * # Arguments
11
11
  * * `logic` - JSON string containing the JSONLogic expression
12
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
12
13
  */
13
- constructor(logic: string);
14
+ constructor(logic: string, preserve_structure: boolean);
14
15
  /**
15
16
  * Evaluate the compiled rule against data.
16
17
  *
@@ -29,11 +30,12 @@ export class CompiledRule {
29
30
  * # Arguments
30
31
  * * `logic` - JSON string containing the JSONLogic expression
31
32
  * * `data` - JSON string containing the data to evaluate against
33
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
32
34
  *
33
35
  * # Returns
34
36
  * JSON string result or error message
35
37
  */
36
- export function evaluate(logic: string, data: string): string;
38
+ export function evaluate(logic: string, data: string, preserve_structure: boolean): string;
37
39
 
38
40
  /**
39
41
  * Evaluate a JSONLogic expression with execution trace for debugging.
@@ -44,6 +46,7 @@ export function evaluate(logic: string, data: string): string;
44
46
  * # Arguments
45
47
  * * `logic` - JSON string containing the JSONLogic expression
46
48
  * * `data` - JSON string containing the data to evaluate against
49
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
47
50
  *
48
51
  * # Returns
49
52
  * JSON string containing TracedResult (result, expression_tree, steps) or error message
@@ -64,6 +67,6 @@ export function evaluate(logic: string, data: string): string;
64
67
  * }
65
68
  * ```
66
69
  */
67
- export function evaluate_with_trace(logic: string, data: string): string;
70
+ export function evaluate_with_trace(logic: string, data: string, preserve_structure: boolean): string;
68
71
 
69
72
  export function init(): void;
@@ -2,6 +2,21 @@
2
2
  let imports = {};
3
3
  imports['__wbindgen_placeholder__'] = module.exports;
4
4
 
5
+ function addHeapObject(obj) {
6
+ if (heap_next === heap.length) heap.push(heap.length + 1);
7
+ const idx = heap_next;
8
+ heap_next = heap[idx];
9
+
10
+ heap[idx] = obj;
11
+ return idx;
12
+ }
13
+
14
+ function dropObject(idx) {
15
+ if (idx < 132) return;
16
+ heap[idx] = heap_next;
17
+ heap_next = idx;
18
+ }
19
+
5
20
  let cachedDataViewMemory0 = null;
6
21
  function getDataViewMemory0() {
7
22
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
@@ -23,6 +38,13 @@ function getUint8ArrayMemory0() {
23
38
  return cachedUint8ArrayMemory0;
24
39
  }
25
40
 
41
+ function getObject(idx) { return heap[idx]; }
42
+
43
+ let heap = new Array(128).fill(undefined);
44
+ heap.push(undefined, null, true, false);
45
+
46
+ let heap_next = heap.length;
47
+
26
48
  function passStringToWasm0(arg, malloc, realloc) {
27
49
  if (realloc === undefined) {
28
50
  const buf = cachedTextEncoder.encode(arg);
@@ -60,10 +82,10 @@ function passStringToWasm0(arg, malloc, realloc) {
60
82
  return ptr;
61
83
  }
62
84
 
63
- function takeFromExternrefTable0(idx) {
64
- const value = wasm.__wbindgen_externrefs.get(idx);
65
- wasm.__externref_table_dealloc(idx);
66
- return value;
85
+ function takeObject(idx) {
86
+ const ret = getObject(idx);
87
+ dropObject(idx);
88
+ return ret;
67
89
  }
68
90
 
69
91
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
@@ -113,18 +135,28 @@ class CompiledRule {
113
135
  *
114
136
  * # Arguments
115
137
  * * `logic` - JSON string containing the JSONLogic expression
138
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
116
139
  * @param {string} logic
140
+ * @param {boolean} preserve_structure
117
141
  */
118
- constructor(logic) {
119
- const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
120
- const len0 = WASM_VECTOR_LEN;
121
- const ret = wasm.compiledrule_new(ptr0, len0);
122
- if (ret[2]) {
123
- throw takeFromExternrefTable0(ret[1]);
142
+ constructor(logic, preserve_structure) {
143
+ try {
144
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
145
+ const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
146
+ const len0 = WASM_VECTOR_LEN;
147
+ wasm.compiledrule_new(retptr, ptr0, len0, preserve_structure);
148
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
149
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
150
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
151
+ if (r2) {
152
+ throw takeObject(r1);
153
+ }
154
+ this.__wbg_ptr = r0 >>> 0;
155
+ CompiledRuleFinalization.register(this, this.__wbg_ptr, this);
156
+ return this;
157
+ } finally {
158
+ wasm.__wbindgen_add_to_stack_pointer(16);
124
159
  }
125
- this.__wbg_ptr = ret[0] >>> 0;
126
- CompiledRuleFinalization.register(this, this.__wbg_ptr, this);
127
- return this;
128
160
  }
129
161
  /**
130
162
  * Evaluate the compiled rule against data.
@@ -141,20 +173,26 @@ class CompiledRule {
141
173
  let deferred3_0;
142
174
  let deferred3_1;
143
175
  try {
144
- const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
176
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
177
+ const ptr0 = passStringToWasm0(data, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
145
178
  const len0 = WASM_VECTOR_LEN;
146
- const ret = wasm.compiledrule_evaluate(this.__wbg_ptr, ptr0, len0);
147
- var ptr2 = ret[0];
148
- var len2 = ret[1];
149
- if (ret[3]) {
179
+ wasm.compiledrule_evaluate(retptr, this.__wbg_ptr, ptr0, len0);
180
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
181
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
182
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
183
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
184
+ var ptr2 = r0;
185
+ var len2 = r1;
186
+ if (r3) {
150
187
  ptr2 = 0; len2 = 0;
151
- throw takeFromExternrefTable0(ret[2]);
188
+ throw takeObject(r2);
152
189
  }
153
190
  deferred3_0 = ptr2;
154
191
  deferred3_1 = len2;
155
192
  return getStringFromWasm0(ptr2, len2);
156
193
  } finally {
157
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
194
+ wasm.__wbindgen_add_to_stack_pointer(16);
195
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
158
196
  }
159
197
  }
160
198
  }
@@ -167,33 +205,41 @@ exports.CompiledRule = CompiledRule;
167
205
  * # Arguments
168
206
  * * `logic` - JSON string containing the JSONLogic expression
169
207
  * * `data` - JSON string containing the data to evaluate against
208
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
170
209
  *
171
210
  * # Returns
172
211
  * JSON string result or error message
173
212
  * @param {string} logic
174
213
  * @param {string} data
214
+ * @param {boolean} preserve_structure
175
215
  * @returns {string}
176
216
  */
177
- function evaluate(logic, data) {
217
+ function evaluate(logic, data, preserve_structure) {
178
218
  let deferred4_0;
179
219
  let deferred4_1;
180
220
  try {
181
- const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
221
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
222
+ const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
182
223
  const len0 = WASM_VECTOR_LEN;
183
- const ptr1 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
224
+ const ptr1 = passStringToWasm0(data, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
184
225
  const len1 = WASM_VECTOR_LEN;
185
- const ret = wasm.evaluate(ptr0, len0, ptr1, len1);
186
- var ptr3 = ret[0];
187
- var len3 = ret[1];
188
- if (ret[3]) {
226
+ wasm.evaluate(retptr, ptr0, len0, ptr1, len1, preserve_structure);
227
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
228
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
229
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
230
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
231
+ var ptr3 = r0;
232
+ var len3 = r1;
233
+ if (r3) {
189
234
  ptr3 = 0; len3 = 0;
190
- throw takeFromExternrefTable0(ret[2]);
235
+ throw takeObject(r2);
191
236
  }
192
237
  deferred4_0 = ptr3;
193
238
  deferred4_1 = len3;
194
239
  return getStringFromWasm0(ptr3, len3);
195
240
  } finally {
196
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
241
+ wasm.__wbindgen_add_to_stack_pointer(16);
242
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
197
243
  }
198
244
  }
199
245
  exports.evaluate = evaluate;
@@ -207,6 +253,7 @@ exports.evaluate = evaluate;
207
253
  * # Arguments
208
254
  * * `logic` - JSON string containing the JSONLogic expression
209
255
  * * `data` - JSON string containing the data to evaluate against
256
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
210
257
  *
211
258
  * # Returns
212
259
  * JSON string containing TracedResult (result, expression_tree, steps) or error message
@@ -228,28 +275,35 @@ exports.evaluate = evaluate;
228
275
  * ```
229
276
  * @param {string} logic
230
277
  * @param {string} data
278
+ * @param {boolean} preserve_structure
231
279
  * @returns {string}
232
280
  */
233
- function evaluate_with_trace(logic, data) {
281
+ function evaluate_with_trace(logic, data, preserve_structure) {
234
282
  let deferred4_0;
235
283
  let deferred4_1;
236
284
  try {
237
- const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
285
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
286
+ const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
238
287
  const len0 = WASM_VECTOR_LEN;
239
- const ptr1 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
288
+ const ptr1 = passStringToWasm0(data, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
240
289
  const len1 = WASM_VECTOR_LEN;
241
- const ret = wasm.evaluate_with_trace(ptr0, len0, ptr1, len1);
242
- var ptr3 = ret[0];
243
- var len3 = ret[1];
244
- if (ret[3]) {
290
+ wasm.evaluate_with_trace(retptr, ptr0, len0, ptr1, len1, preserve_structure);
291
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
292
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
293
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
294
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
295
+ var ptr3 = r0;
296
+ var len3 = r1;
297
+ if (r3) {
245
298
  ptr3 = 0; len3 = 0;
246
- throw takeFromExternrefTable0(ret[2]);
299
+ throw takeObject(r2);
247
300
  }
248
301
  deferred4_0 = ptr3;
249
302
  deferred4_1 = len3;
250
303
  return getStringFromWasm0(ptr3, len3);
251
304
  } finally {
252
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
305
+ wasm.__wbindgen_add_to_stack_pointer(16);
306
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
253
307
  }
254
308
  }
255
309
  exports.evaluate_with_trace = evaluate_with_trace;
@@ -271,18 +325,28 @@ exports.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
271
325
  deferred0_1 = arg1;
272
326
  console.error(getStringFromWasm0(arg0, arg1));
273
327
  } finally {
274
- wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
328
+ wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
275
329
  }
276
330
  };
277
331
 
332
+ exports.__wbg_getTime_ad1e9878a735af08 = function(arg0) {
333
+ const ret = getObject(arg0).getTime();
334
+ return ret;
335
+ };
336
+
337
+ exports.__wbg_new_0_23cedd11d9b40c9d = function() {
338
+ const ret = new Date();
339
+ return addHeapObject(ret);
340
+ };
341
+
278
342
  exports.__wbg_new_8a6f238a6ece86ea = function() {
279
343
  const ret = new Error();
280
- return ret;
344
+ return addHeapObject(ret);
281
345
  };
282
346
 
283
347
  exports.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
284
- const ret = arg1.stack;
285
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
348
+ const ret = getObject(arg1).stack;
349
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
286
350
  const len1 = WASM_VECTOR_LEN;
287
351
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
288
352
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
@@ -291,17 +355,11 @@ exports.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
291
355
  exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
292
356
  // Cast intrinsic for `Ref(String) -> Externref`.
293
357
  const ret = getStringFromWasm0(arg0, arg1);
294
- return ret;
358
+ return addHeapObject(ret);
295
359
  };
296
360
 
297
- exports.__wbindgen_init_externref_table = function() {
298
- const table = wasm.__wbindgen_externrefs;
299
- const offset = table.grow(4);
300
- table.set(0, undefined);
301
- table.set(offset + 0, undefined);
302
- table.set(offset + 1, null);
303
- table.set(offset + 2, true);
304
- table.set(offset + 3, false);
361
+ exports.__wbindgen_object_drop_ref = function(arg0) {
362
+ takeObject(arg0);
305
363
  };
306
364
 
307
365
  const wasmPath = `${__dirname}/datalogic_wasm_bg.wasm`;
Binary file
@@ -2,14 +2,13 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_compiledrule_free: (a: number, b: number) => void;
5
- export const compiledrule_evaluate: (a: number, b: number, c: number) => [number, number, number, number];
6
- export const compiledrule_new: (a: number, b: number) => [number, number, number];
7
- export const evaluate: (a: number, b: number, c: number, d: number) => [number, number, number, number];
8
- export const evaluate_with_trace: (a: number, b: number, c: number, d: number) => [number, number, number, number];
5
+ export const compiledrule_evaluate: (a: number, b: number, c: number, d: number) => void;
6
+ export const compiledrule_new: (a: number, b: number, c: number, d: number) => void;
7
+ export const evaluate: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
8
+ export const evaluate_with_trace: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
9
9
  export const init: () => void;
10
- export const __wbindgen_free: (a: number, b: number, c: number) => void;
11
- export const __wbindgen_malloc: (a: number, b: number) => number;
12
- export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
13
- export const __wbindgen_externrefs: WebAssembly.Table;
14
- export const __externref_table_dealloc: (a: number) => void;
10
+ export const __wbindgen_export: (a: number, b: number, c: number) => void;
11
+ export const __wbindgen_export2: (a: number, b: number) => number;
12
+ export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
13
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
15
14
  export const __wbindgen_start: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goplasmatic/datalogic",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "description": "High-performance JSONLogic engine for JavaScript/TypeScript - WebAssembly powered",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -9,8 +9,9 @@ export class CompiledRule {
9
9
  *
10
10
  * # Arguments
11
11
  * * `logic` - JSON string containing the JSONLogic expression
12
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
12
13
  */
13
- constructor(logic: string);
14
+ constructor(logic: string, preserve_structure: boolean);
14
15
  /**
15
16
  * Evaluate the compiled rule against data.
16
17
  *
@@ -29,11 +30,12 @@ export class CompiledRule {
29
30
  * # Arguments
30
31
  * * `logic` - JSON string containing the JSONLogic expression
31
32
  * * `data` - JSON string containing the data to evaluate against
33
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
32
34
  *
33
35
  * # Returns
34
36
  * JSON string result or error message
35
37
  */
36
- export function evaluate(logic: string, data: string): string;
38
+ export function evaluate(logic: string, data: string, preserve_structure: boolean): string;
37
39
 
38
40
  /**
39
41
  * Evaluate a JSONLogic expression with execution trace for debugging.
@@ -44,6 +46,7 @@ export function evaluate(logic: string, data: string): string;
44
46
  * # Arguments
45
47
  * * `logic` - JSON string containing the JSONLogic expression
46
48
  * * `data` - JSON string containing the data to evaluate against
49
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
47
50
  *
48
51
  * # Returns
49
52
  * JSON string containing TracedResult (result, expression_tree, steps) or error message
@@ -64,7 +67,7 @@ export function evaluate(logic: string, data: string): string;
64
67
  * }
65
68
  * ```
66
69
  */
67
- export function evaluate_with_trace(logic: string, data: string): string;
70
+ export function evaluate_with_trace(logic: string, data: string, preserve_structure: boolean): string;
68
71
 
69
72
  export function init(): void;
70
73
 
@@ -73,16 +76,15 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
73
76
  export interface InitOutput {
74
77
  readonly memory: WebAssembly.Memory;
75
78
  readonly __wbg_compiledrule_free: (a: number, b: number) => void;
76
- readonly compiledrule_evaluate: (a: number, b: number, c: number) => [number, number, number, number];
77
- readonly compiledrule_new: (a: number, b: number) => [number, number, number];
78
- readonly evaluate: (a: number, b: number, c: number, d: number) => [number, number, number, number];
79
- readonly evaluate_with_trace: (a: number, b: number, c: number, d: number) => [number, number, number, number];
79
+ readonly compiledrule_evaluate: (a: number, b: number, c: number, d: number) => void;
80
+ readonly compiledrule_new: (a: number, b: number, c: number, d: number) => void;
81
+ readonly evaluate: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
82
+ readonly evaluate_with_trace: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
80
83
  readonly init: () => void;
81
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
82
- readonly __wbindgen_malloc: (a: number, b: number) => number;
83
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
84
- readonly __wbindgen_externrefs: WebAssembly.Table;
85
- readonly __externref_table_dealloc: (a: number) => void;
84
+ readonly __wbindgen_export: (a: number, b: number, c: number) => void;
85
+ readonly __wbindgen_export2: (a: number, b: number) => number;
86
+ readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
87
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
86
88
  readonly __wbindgen_start: () => void;
87
89
  }
88
90
 
@@ -1,5 +1,20 @@
1
1
  let wasm;
2
2
 
3
+ function addHeapObject(obj) {
4
+ if (heap_next === heap.length) heap.push(heap.length + 1);
5
+ const idx = heap_next;
6
+ heap_next = heap[idx];
7
+
8
+ heap[idx] = obj;
9
+ return idx;
10
+ }
11
+
12
+ function dropObject(idx) {
13
+ if (idx < 132) return;
14
+ heap[idx] = heap_next;
15
+ heap_next = idx;
16
+ }
17
+
3
18
  let cachedDataViewMemory0 = null;
4
19
  function getDataViewMemory0() {
5
20
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
@@ -21,6 +36,13 @@ function getUint8ArrayMemory0() {
21
36
  return cachedUint8ArrayMemory0;
22
37
  }
23
38
 
39
+ function getObject(idx) { return heap[idx]; }
40
+
41
+ let heap = new Array(128).fill(undefined);
42
+ heap.push(undefined, null, true, false);
43
+
44
+ let heap_next = heap.length;
45
+
24
46
  function passStringToWasm0(arg, malloc, realloc) {
25
47
  if (realloc === undefined) {
26
48
  const buf = cachedTextEncoder.encode(arg);
@@ -58,10 +80,10 @@ function passStringToWasm0(arg, malloc, realloc) {
58
80
  return ptr;
59
81
  }
60
82
 
61
- function takeFromExternrefTable0(idx) {
62
- const value = wasm.__wbindgen_externrefs.get(idx);
63
- wasm.__externref_table_dealloc(idx);
64
- return value;
83
+ function takeObject(idx) {
84
+ const ret = getObject(idx);
85
+ dropObject(idx);
86
+ return ret;
65
87
  }
66
88
 
67
89
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
@@ -119,18 +141,28 @@ export class CompiledRule {
119
141
  *
120
142
  * # Arguments
121
143
  * * `logic` - JSON string containing the JSONLogic expression
144
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
122
145
  * @param {string} logic
146
+ * @param {boolean} preserve_structure
123
147
  */
124
- constructor(logic) {
125
- const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
126
- const len0 = WASM_VECTOR_LEN;
127
- const ret = wasm.compiledrule_new(ptr0, len0);
128
- if (ret[2]) {
129
- throw takeFromExternrefTable0(ret[1]);
148
+ constructor(logic, preserve_structure) {
149
+ try {
150
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
151
+ const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
152
+ const len0 = WASM_VECTOR_LEN;
153
+ wasm.compiledrule_new(retptr, ptr0, len0, preserve_structure);
154
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
155
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
156
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
157
+ if (r2) {
158
+ throw takeObject(r1);
159
+ }
160
+ this.__wbg_ptr = r0 >>> 0;
161
+ CompiledRuleFinalization.register(this, this.__wbg_ptr, this);
162
+ return this;
163
+ } finally {
164
+ wasm.__wbindgen_add_to_stack_pointer(16);
130
165
  }
131
- this.__wbg_ptr = ret[0] >>> 0;
132
- CompiledRuleFinalization.register(this, this.__wbg_ptr, this);
133
- return this;
134
166
  }
135
167
  /**
136
168
  * Evaluate the compiled rule against data.
@@ -147,20 +179,26 @@ export class CompiledRule {
147
179
  let deferred3_0;
148
180
  let deferred3_1;
149
181
  try {
150
- const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
182
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
183
+ const ptr0 = passStringToWasm0(data, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
151
184
  const len0 = WASM_VECTOR_LEN;
152
- const ret = wasm.compiledrule_evaluate(this.__wbg_ptr, ptr0, len0);
153
- var ptr2 = ret[0];
154
- var len2 = ret[1];
155
- if (ret[3]) {
185
+ wasm.compiledrule_evaluate(retptr, this.__wbg_ptr, ptr0, len0);
186
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
187
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
188
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
189
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
190
+ var ptr2 = r0;
191
+ var len2 = r1;
192
+ if (r3) {
156
193
  ptr2 = 0; len2 = 0;
157
- throw takeFromExternrefTable0(ret[2]);
194
+ throw takeObject(r2);
158
195
  }
159
196
  deferred3_0 = ptr2;
160
197
  deferred3_1 = len2;
161
198
  return getStringFromWasm0(ptr2, len2);
162
199
  } finally {
163
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
200
+ wasm.__wbindgen_add_to_stack_pointer(16);
201
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
164
202
  }
165
203
  }
166
204
  }
@@ -172,33 +210,41 @@ if (Symbol.dispose) CompiledRule.prototype[Symbol.dispose] = CompiledRule.protot
172
210
  * # Arguments
173
211
  * * `logic` - JSON string containing the JSONLogic expression
174
212
  * * `data` - JSON string containing the data to evaluate against
213
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
175
214
  *
176
215
  * # Returns
177
216
  * JSON string result or error message
178
217
  * @param {string} logic
179
218
  * @param {string} data
219
+ * @param {boolean} preserve_structure
180
220
  * @returns {string}
181
221
  */
182
- export function evaluate(logic, data) {
222
+ export function evaluate(logic, data, preserve_structure) {
183
223
  let deferred4_0;
184
224
  let deferred4_1;
185
225
  try {
186
- const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
226
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
227
+ const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
187
228
  const len0 = WASM_VECTOR_LEN;
188
- const ptr1 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
229
+ const ptr1 = passStringToWasm0(data, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
189
230
  const len1 = WASM_VECTOR_LEN;
190
- const ret = wasm.evaluate(ptr0, len0, ptr1, len1);
191
- var ptr3 = ret[0];
192
- var len3 = ret[1];
193
- if (ret[3]) {
231
+ wasm.evaluate(retptr, ptr0, len0, ptr1, len1, preserve_structure);
232
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
233
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
234
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
235
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
236
+ var ptr3 = r0;
237
+ var len3 = r1;
238
+ if (r3) {
194
239
  ptr3 = 0; len3 = 0;
195
- throw takeFromExternrefTable0(ret[2]);
240
+ throw takeObject(r2);
196
241
  }
197
242
  deferred4_0 = ptr3;
198
243
  deferred4_1 = len3;
199
244
  return getStringFromWasm0(ptr3, len3);
200
245
  } finally {
201
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
246
+ wasm.__wbindgen_add_to_stack_pointer(16);
247
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
202
248
  }
203
249
  }
204
250
 
@@ -211,6 +257,7 @@ export function evaluate(logic, data) {
211
257
  * # Arguments
212
258
  * * `logic` - JSON string containing the JSONLogic expression
213
259
  * * `data` - JSON string containing the data to evaluate against
260
+ * * `preserve_structure` - If true, preserves object structure for JSON templates with embedded JSONLogic
214
261
  *
215
262
  * # Returns
216
263
  * JSON string containing TracedResult (result, expression_tree, steps) or error message
@@ -232,28 +279,35 @@ export function evaluate(logic, data) {
232
279
  * ```
233
280
  * @param {string} logic
234
281
  * @param {string} data
282
+ * @param {boolean} preserve_structure
235
283
  * @returns {string}
236
284
  */
237
- export function evaluate_with_trace(logic, data) {
285
+ export function evaluate_with_trace(logic, data, preserve_structure) {
238
286
  let deferred4_0;
239
287
  let deferred4_1;
240
288
  try {
241
- const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
289
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
290
+ const ptr0 = passStringToWasm0(logic, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
242
291
  const len0 = WASM_VECTOR_LEN;
243
- const ptr1 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
292
+ const ptr1 = passStringToWasm0(data, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
244
293
  const len1 = WASM_VECTOR_LEN;
245
- const ret = wasm.evaluate_with_trace(ptr0, len0, ptr1, len1);
246
- var ptr3 = ret[0];
247
- var len3 = ret[1];
248
- if (ret[3]) {
294
+ wasm.evaluate_with_trace(retptr, ptr0, len0, ptr1, len1, preserve_structure);
295
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
296
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
297
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
298
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
299
+ var ptr3 = r0;
300
+ var len3 = r1;
301
+ if (r3) {
249
302
  ptr3 = 0; len3 = 0;
250
- throw takeFromExternrefTable0(ret[2]);
303
+ throw takeObject(r2);
251
304
  }
252
305
  deferred4_0 = ptr3;
253
306
  deferred4_1 = len3;
254
307
  return getStringFromWasm0(ptr3, len3);
255
308
  } finally {
256
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
309
+ wasm.__wbindgen_add_to_stack_pointer(16);
310
+ wasm.__wbindgen_export(deferred4_0, deferred4_1, 1);
257
311
  }
258
312
  }
259
313
 
@@ -307,16 +361,24 @@ function __wbg_get_imports() {
307
361
  deferred0_1 = arg1;
308
362
  console.error(getStringFromWasm0(arg0, arg1));
309
363
  } finally {
310
- wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
364
+ wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
311
365
  }
312
366
  };
367
+ imports.wbg.__wbg_getTime_ad1e9878a735af08 = function(arg0) {
368
+ const ret = getObject(arg0).getTime();
369
+ return ret;
370
+ };
371
+ imports.wbg.__wbg_new_0_23cedd11d9b40c9d = function() {
372
+ const ret = new Date();
373
+ return addHeapObject(ret);
374
+ };
313
375
  imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
314
376
  const ret = new Error();
315
- return ret;
377
+ return addHeapObject(ret);
316
378
  };
317
379
  imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
318
- const ret = arg1.stack;
319
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
380
+ const ret = getObject(arg1).stack;
381
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
320
382
  const len1 = WASM_VECTOR_LEN;
321
383
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
322
384
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
@@ -324,16 +386,10 @@ function __wbg_get_imports() {
324
386
  imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
325
387
  // Cast intrinsic for `Ref(String) -> Externref`.
326
388
  const ret = getStringFromWasm0(arg0, arg1);
327
- return ret;
389
+ return addHeapObject(ret);
328
390
  };
329
- imports.wbg.__wbindgen_init_externref_table = function() {
330
- const table = wasm.__wbindgen_externrefs;
331
- const offset = table.grow(4);
332
- table.set(0, undefined);
333
- table.set(offset + 0, undefined);
334
- table.set(offset + 1, null);
335
- table.set(offset + 2, true);
336
- table.set(offset + 3, false);
391
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
392
+ takeObject(arg0);
337
393
  };
338
394
 
339
395
  return imports;
Binary file
@@ -2,14 +2,13 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_compiledrule_free: (a: number, b: number) => void;
5
- export const compiledrule_evaluate: (a: number, b: number, c: number) => [number, number, number, number];
6
- export const compiledrule_new: (a: number, b: number) => [number, number, number];
7
- export const evaluate: (a: number, b: number, c: number, d: number) => [number, number, number, number];
8
- export const evaluate_with_trace: (a: number, b: number, c: number, d: number) => [number, number, number, number];
5
+ export const compiledrule_evaluate: (a: number, b: number, c: number, d: number) => void;
6
+ export const compiledrule_new: (a: number, b: number, c: number, d: number) => void;
7
+ export const evaluate: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
8
+ export const evaluate_with_trace: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
9
9
  export const init: () => void;
10
- export const __wbindgen_free: (a: number, b: number, c: number) => void;
11
- export const __wbindgen_malloc: (a: number, b: number) => number;
12
- export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
13
- export const __wbindgen_externrefs: WebAssembly.Table;
14
- export const __externref_table_dealloc: (a: number) => void;
10
+ export const __wbindgen_export: (a: number, b: number, c: number) => void;
11
+ export const __wbindgen_export2: (a: number, b: number) => number;
12
+ export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
13
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
15
14
  export const __wbindgen_start: () => void;