jlens-wasm 0.7.0 → 0.9.0
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/jlens.d.ts +1 -1
- package/jlens.js +44 -0
- package/jlens_bg.wasm +0 -0
- package/package.json +2 -1
- package/snippets/jlens-wasm-3e775bec4e0b65c4/inline0.js +79 -0
package/jlens.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type HostFunction = (...args: any[]) => unknown;
|
|
|
21
21
|
export interface EvaluateOptions {
|
|
22
22
|
/** Maximum duration of one evaluation, in milliseconds (error `D1012`). */
|
|
23
23
|
timeout?: number;
|
|
24
|
-
/** Maximum evaluation depth (default
|
|
24
|
+
/** Maximum evaluation depth (default 800; error `D1011`). */
|
|
25
25
|
maxDepth?: number;
|
|
26
26
|
/** Maximum length, in bytes of UTF-8, of a string the evaluation builds (default 256 MiB; error `U1001`). */
|
|
27
27
|
maxStringLength?: number;
|
package/jlens.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/* @ts-self-types="./jlens.d.ts" */
|
|
2
|
+
import { jlensLevel } from './snippets/jlens-wasm-3e775bec4e0b65c4/inline0.js';
|
|
3
|
+
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* A JSON document converted once into jlens's internal representation, for evaluating
|
|
@@ -136,6 +138,9 @@ export class Expression {
|
|
|
136
138
|
* `$limit`, and `{rate: (region) => ...}` defines `$rate(region)`.
|
|
137
139
|
* Returns `undefined` when the result is undefined; throws a `JlensError` when the
|
|
138
140
|
* evaluation fails.
|
|
141
|
+
*
|
|
142
|
+
* The input is read during the evaluation, one level at a time, as the expression reaches
|
|
143
|
+
* it (ADR 0010).
|
|
139
144
|
* @param {any | null} [input]
|
|
140
145
|
* @param {any | null} [bindings]
|
|
141
146
|
* @param {any | null} [options]
|
|
@@ -400,18 +405,40 @@ function __wbg_get_imports() {
|
|
|
400
405
|
const ret = Reflect.has(arg0, arg1);
|
|
401
406
|
return ret;
|
|
402
407
|
}, arguments); },
|
|
408
|
+
__wbg_instanceof_Error_80a725f81f2e102d: function(arg0) {
|
|
409
|
+
let result;
|
|
410
|
+
try {
|
|
411
|
+
result = arg0 instanceof Error;
|
|
412
|
+
} catch (_) {
|
|
413
|
+
result = false;
|
|
414
|
+
}
|
|
415
|
+
const ret = result;
|
|
416
|
+
return ret;
|
|
417
|
+
},
|
|
403
418
|
__wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
|
|
404
419
|
const ret = Array.isArray(arg0);
|
|
405
420
|
return ret;
|
|
406
421
|
},
|
|
422
|
+
__wbg_jlensLevel_c9d434c9c1cbe278: function() { return handleError(function (arg0, arg1, arg2) {
|
|
423
|
+
const ret = jlensLevel(arg0, arg1 >>> 0, arg2 >>> 0);
|
|
424
|
+
return ret;
|
|
425
|
+
}, arguments); },
|
|
407
426
|
__wbg_length_3121141f8e1c8c58: function(arg0) {
|
|
408
427
|
const ret = arg0.length;
|
|
409
428
|
return ret;
|
|
410
429
|
},
|
|
430
|
+
__wbg_length_b5f0008bbf60cf59: function(arg0) {
|
|
431
|
+
const ret = arg0.length;
|
|
432
|
+
return ret;
|
|
433
|
+
},
|
|
411
434
|
__wbg_length_d4bdea10311bd9cf: function(arg0) {
|
|
412
435
|
const ret = arg0.length;
|
|
413
436
|
return ret;
|
|
414
437
|
},
|
|
438
|
+
__wbg_message_5f8387f0c32b90a7: function(arg0) {
|
|
439
|
+
const ret = arg0.message;
|
|
440
|
+
return ret;
|
|
441
|
+
},
|
|
415
442
|
__wbg_new_2bdcdfcebdfc34d2: function(arg0, arg1) {
|
|
416
443
|
const ret = new TypeError(getStringFromWasm0(arg0, arg1));
|
|
417
444
|
return ret;
|
|
@@ -440,6 +467,9 @@ function __wbg_get_imports() {
|
|
|
440
467
|
const ret = arg0.performance;
|
|
441
468
|
return ret;
|
|
442
469
|
},
|
|
470
|
+
__wbg_prototypesetcall_d49a4fab5ca427bc: function(arg0, arg1, arg2) {
|
|
471
|
+
Float64Array.prototype.set.call(getArrayF64FromWasm0(arg0, arg1), arg2);
|
|
472
|
+
},
|
|
443
473
|
__wbg_push_2baf45db356cf468: function(arg0, arg1) {
|
|
444
474
|
const ret = arg0.push(arg1);
|
|
445
475
|
return ret;
|
|
@@ -584,6 +614,11 @@ function debugString(val) {
|
|
|
584
614
|
return className;
|
|
585
615
|
}
|
|
586
616
|
|
|
617
|
+
function getArrayF64FromWasm0(ptr, len) {
|
|
618
|
+
ptr = ptr >>> 0;
|
|
619
|
+
return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
|
|
620
|
+
}
|
|
621
|
+
|
|
587
622
|
let cachedDataViewMemory0 = null;
|
|
588
623
|
function getDataViewMemory0() {
|
|
589
624
|
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
@@ -592,6 +627,14 @@ function getDataViewMemory0() {
|
|
|
592
627
|
return cachedDataViewMemory0;
|
|
593
628
|
}
|
|
594
629
|
|
|
630
|
+
let cachedFloat64ArrayMemory0 = null;
|
|
631
|
+
function getFloat64ArrayMemory0() {
|
|
632
|
+
if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
|
|
633
|
+
cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
|
|
634
|
+
}
|
|
635
|
+
return cachedFloat64ArrayMemory0;
|
|
636
|
+
}
|
|
637
|
+
|
|
595
638
|
function getStringFromWasm0(ptr, len) {
|
|
596
639
|
return decodeText(ptr >>> 0, len);
|
|
597
640
|
}
|
|
@@ -695,6 +738,7 @@ function __wbg_finalize_init(instance, module) {
|
|
|
695
738
|
wasm = instance.exports;
|
|
696
739
|
wasmModule = module;
|
|
697
740
|
cachedDataViewMemory0 = null;
|
|
741
|
+
cachedFloat64ArrayMemory0 = null;
|
|
698
742
|
cachedUint8ArrayMemory0 = null;
|
|
699
743
|
wasm.__wbindgen_start();
|
|
700
744
|
return wasm;
|
package/jlens_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jlens-wasm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "JSONata in WebAssembly, with evaluation audits and schema-driven autocomplete",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"jlens.d.ts",
|
|
26
26
|
"jlens_bg.wasm",
|
|
27
27
|
"jlens_bg.wasm.d.ts",
|
|
28
|
+
"snippets/",
|
|
28
29
|
"README.md",
|
|
29
30
|
"LICENSE"
|
|
30
31
|
],
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
|
|
2
|
+
const CIRCULAR = "Converting circular structure to JSON";
|
|
3
|
+
const BIGINT = "Do not know how to serialize a BigInt";
|
|
4
|
+
|
|
5
|
+
// Reads one level: `kind` 0 is the input itself (`node` is the value), 1 an array and 2 an
|
|
6
|
+
// object (`node` is {v, up}: the value and its parent's node, to detect cycles). Returns the
|
|
7
|
+
// number of values then their tags and numbers, their strings and keys as one text (lengths
|
|
8
|
+
// in UTF-16 code units), and the nodes of the nested arrays and objects. In an object,
|
|
9
|
+
// each value is followed by the length of its key. An array or object of more than `whole`
|
|
10
|
+
// values is returned as its JSON text instead (a cycle back to an ancestor passes through it
|
|
11
|
+
// again, so JSON.stringify sees it).
|
|
12
|
+
export function jlensLevel(node, kind, whole) {
|
|
13
|
+
const nums = [0];
|
|
14
|
+
let text = "";
|
|
15
|
+
const nested = [];
|
|
16
|
+
const up = kind === 0 ? null : node;
|
|
17
|
+
const put = (v, key) => {
|
|
18
|
+
if ((typeof v === "object" && v !== null) || typeof v === "bigint") {
|
|
19
|
+
const toJSON = v.toJSON;
|
|
20
|
+
if (typeof toJSON === "function") v = toJSON.call(v, key);
|
|
21
|
+
}
|
|
22
|
+
if (typeof v === "object" && v !== null) {
|
|
23
|
+
if (v instanceof Number) v = Number(v);
|
|
24
|
+
else if (v instanceof String) v = String(v);
|
|
25
|
+
else if (v instanceof Boolean) v = v.valueOf();
|
|
26
|
+
else if (v instanceof BigInt) throw new TypeError(BIGINT);
|
|
27
|
+
}
|
|
28
|
+
switch (typeof v) {
|
|
29
|
+
case "string":
|
|
30
|
+
nums.push(5, v.length);
|
|
31
|
+
text += v;
|
|
32
|
+
return true;
|
|
33
|
+
case "number":
|
|
34
|
+
if (isFinite(v)) nums.push(4, v);
|
|
35
|
+
else nums.push(1);
|
|
36
|
+
return true;
|
|
37
|
+
case "boolean":
|
|
38
|
+
nums.push(v ? 3 : 2);
|
|
39
|
+
return true;
|
|
40
|
+
case "bigint":
|
|
41
|
+
throw new TypeError(BIGINT);
|
|
42
|
+
case "object":
|
|
43
|
+
if (v === null) {
|
|
44
|
+
nums.push(1);
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
for (let n = up; n !== null; n = n.up) {
|
|
48
|
+
if (n.v === v) throw new TypeError(CIRCULAR);
|
|
49
|
+
}
|
|
50
|
+
nums.push(Array.isArray(v) ? 6 : 7);
|
|
51
|
+
nested.push({ v, up });
|
|
52
|
+
return true;
|
|
53
|
+
default:
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
if (kind === 0) {
|
|
58
|
+
put(node, "");
|
|
59
|
+
} else if (kind === 1) {
|
|
60
|
+
const items = node.v;
|
|
61
|
+
if (items.length > whole) return JSON.stringify(items);
|
|
62
|
+
nums[0] = items.length;
|
|
63
|
+
for (let i = 0; i < items.length; i++) {
|
|
64
|
+
if (!put(items[i], String(i))) nums.push(1);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
const fields = node.v;
|
|
68
|
+
const keys = Object.keys(fields);
|
|
69
|
+
if (keys.length > whole) return JSON.stringify(fields);
|
|
70
|
+
nums[0] = keys.length;
|
|
71
|
+
for (const key of keys) {
|
|
72
|
+
if (put(fields[key], key)) {
|
|
73
|
+
nums.push(key.length);
|
|
74
|
+
text += key;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [new Float64Array(nums), text, nested];
|
|
79
|
+
}
|