jlens-wasm 0.17.0 → 0.19.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 CHANGED
@@ -217,6 +217,26 @@ export interface ExplanationLine {
217
217
  node: number;
218
218
  }
219
219
 
220
+ // ---------------------------------------------------------------------------------------------
221
+ // The fields an expression reads
222
+
223
+ /**
224
+ * What an expression reads of a value: `true` for the whole value; an object for only the fields
225
+ * it lists, each with its own `Read` (of an array, its items, each read the same way; of a
226
+ * scalar, the scalar). An empty object needs the value but none of its fields, as `$count` does.
227
+ */
228
+ export type Read = true | { [field: string]: Read };
229
+
230
+ /** What an expression reads of its input and of its bindings, given by `Expression.reads()`. */
231
+ export interface Reads {
232
+ /** Absent when the expression does not read its input. */
233
+ input?: Read;
234
+ /** The bindings the expression reads, by name (without the `$`). */
235
+ bindings: Record<string, Read>;
236
+ /** Set when the expression may read any binding whole, as `$eval` can: keep all bindings. */
237
+ everyBinding?: true;
238
+ }
239
+
220
240
  // ---------------------------------------------------------------------------------------------
221
241
  // Parsing
222
242
 
@@ -360,7 +380,8 @@ export class Expression {
360
380
  evaluate(input?: unknown, bindings?: Bindings | null, options?: EvaluateOptions): unknown;
361
381
  /**
362
382
  * Like `evaluate`, with the input document and the result as JSON text. This avoids
363
- * converting large documents to and from JavaScript objects.
383
+ * converting large documents to and from JavaScript objects. The fields of the input that the
384
+ * expression does not read (`reads()`) are skipped while parsing, checked as JSON syntax only.
364
385
  */
365
386
  evaluateJson(
366
387
  input?: string | null,
@@ -385,6 +406,12 @@ export class Expression {
385
406
  * `JlensError` when the signature is invalid.
386
407
  */
387
408
  registerFunction(name: string, implementation: HostFunction, signature?: string): void;
409
+ /**
410
+ * The fields of the input and of the bindings the expression reads: an input cut down to them
411
+ * gives the same result. The functions in `bindings`, and those registered on the expression,
412
+ * read only their arguments; a call to a function it does not know reads its context whole.
413
+ */
414
+ reads(bindings?: Bindings | null): Reads;
388
415
  /** The processed syntax tree, as plain objects. */
389
416
  ast(): AstNode;
390
417
  /** Releases the compiled expression. */
@@ -399,8 +426,12 @@ export class Expression {
399
426
  export class Document {
400
427
  /** Converts a JSON-compatible value. */
401
428
  constructor(input: unknown);
402
- /** Parses JSON text. Throws a `TypeError` when it is not valid JSON. */
403
- static fromJson(text: string): Document;
429
+ /**
430
+ * Parses JSON text. Throws a `TypeError` when it is not valid JSON. With `read` (the `input`
431
+ * of `reads()` or of `unionReads()`), the fields it leaves out are skipped, checked as JSON
432
+ * syntax only, and the document serves the expressions it comes from as the whole one would.
433
+ */
434
+ static fromJson(text: string, read?: Read | null): Document;
404
435
  free(): void;
405
436
  [Symbol.dispose](): void;
406
437
  }
@@ -433,6 +464,12 @@ export class LanguageService {
433
464
  [Symbol.dispose](): void;
434
465
  }
435
466
 
467
+ /**
468
+ * What any of several expressions reads: an input cut down to the union gives each of them its
469
+ * result. Throws a `TypeError` when an item is not in the form `reads()` returns.
470
+ */
471
+ export function unionReads(reads: Reads[]): Reads;
472
+
436
473
  /**
437
474
  * Infers a JSON Schema (2020-12, with `x-jlens-*` annotations) from sample documents.
438
475
  * `overrides` adds descriptions, labels, allowed values and hidden fields by path, such as
@@ -469,7 +506,7 @@ export interface InitOutput {
469
506
  readonly __wbg_document_free: (a: number, b: number) => void;
470
507
  readonly __wbg_expression_free: (a: number, b: number) => void;
471
508
  readonly __wbg_languageservice_free: (a: number, b: number) => void;
472
- readonly document_fromJson: (a: number, b: number) => [number, number, number];
509
+ readonly document_fromJson: (a: number, b: number, c: number) => [number, number, number];
473
510
  readonly document_new: (a: any) => [number, number, number];
474
511
  readonly expression_ast: (a: number) => any;
475
512
  readonly expression_evaluate: (a: number, b: number, c: number, d: number) => [number, number, number];
@@ -477,6 +514,7 @@ export interface InitOutput {
477
514
  readonly expression_evaluateJson: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
478
515
  readonly expression_evaluateWithAudit: (a: number, b: number, c: number, d: number) => [number, number, number];
479
516
  readonly expression_new: (a: number, b: number) => [number, number, number];
517
+ readonly expression_reads: (a: number, b: number) => [number, number, number];
480
518
  readonly expression_registerFunction: (a: number, b: number, c: number, d: any, e: number, f: number) => [number, number];
481
519
  readonly expression_source: (a: number) => [number, number];
482
520
  readonly functions: () => any;
@@ -487,8 +525,9 @@ export interface InitOutput {
487
525
  readonly languageservice_new: (a: number, b: number, c: number) => [number, number, number];
488
526
  readonly languageservice_signatureHelp: (a: number, b: number, c: number, d: number) => any;
489
527
  readonly parseRecover: (a: number, b: number) => any;
528
+ readonly unionReads: (a: any) => [number, number, number];
490
529
  readonly version: () => [number, number];
491
- readonly wasm_bindgen_dfd3dc8039a2d669___convert__closures_____invoke___js_sys_94575574b531b35c___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_dfd3dc8039a2d669___JsValue__wasm_bindgen_dfd3dc8039a2d669___JsValue___false_: (a: number, b: number, c: any) => [number, number, number];
530
+ readonly wasm_bindgen_83299752791f6fbb___convert__closures_____invoke___js_sys_f067e63b4fcf480b___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_83299752791f6fbb___JsValue__wasm_bindgen_83299752791f6fbb___JsValue___false_: (a: number, b: number, c: any) => [number, number, number];
492
531
  readonly __wbindgen_malloc: (a: number, b: number) => number;
493
532
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
494
533
  readonly __wbindgen_exn_store: (a: number) => void;
package/jlens.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /* @ts-self-types="./jlens.d.ts" */
2
- import { jlensCallable } from './snippets/jlens-wasm-669ebf4a414f63a3/inline0.js';
3
- import { jlensLevel } from './snippets/jlens-wasm-669ebf4a414f63a3/inline1.js';
2
+ import { jlensCallable } from './snippets/jlens-wasm-14c70486967a4dac/inline0.js';
3
+ import { jlensBuild } from './snippets/jlens-wasm-14c70486967a4dac/inline1.js';
4
+ import { jlensLevel } from './snippets/jlens-wasm-14c70486967a4dac/inline2.js';
4
5
 
5
6
 
6
7
  /**
@@ -25,14 +26,16 @@ export class Document {
25
26
  wasm.__wbg_document_free(ptr, 0);
26
27
  }
27
28
  /**
28
- * Parses JSON text.
29
+ * Parses JSON text. With `read` (the `input` of a `reads()`, or of a `unionReads()`), the
30
+ * fields it leaves out are skipped: they are checked as JSON syntax only.
29
31
  * @param {string} text
32
+ * @param {any | null} [read]
30
33
  * @returns {Document}
31
34
  */
32
- static fromJson(text) {
35
+ static fromJson(text, read) {
33
36
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
34
37
  const len0 = WASM_VECTOR_LEN;
35
- const ret = wasm.document_fromJson(ptr0, len0);
38
+ const ret = wasm.document_fromJson(ptr0, len0, isLikeNone(read) ? 0 : addToExternrefTable0(read));
36
39
  if (ret[2]) {
37
40
  throw takeFromExternrefTable0(ret[1]);
38
41
  }
@@ -98,7 +101,8 @@ export class Expression {
98
101
  }
99
102
  /**
100
103
  * Like `evaluate`, with the input document and the result as JSON text. This avoids
101
- * converting large documents to and from JavaScript objects.
104
+ * converting large documents to and from JavaScript objects. The fields of the input that
105
+ * the expression does not read (`reads()`, without bindings) are skipped while parsing.
102
106
  * @param {string | null} [input]
103
107
  * @param {any | null} [bindings]
104
108
  * @param {any | null} [options]
@@ -169,6 +173,21 @@ export class Expression {
169
173
  ExpressionFinalization.register(this, this.__wbg_ptr, this);
170
174
  return this;
171
175
  }
176
+ /**
177
+ * The fields of the input and of the bindings the expression reads (ADR 0016). The
178
+ * functions in `bindings`, and those registered on the expression, read only their
179
+ * arguments, since a JavaScript function cannot read the context of its call; a call to a
180
+ * function the analysis does not know reads its context whole.
181
+ * @param {any | null} [bindings]
182
+ * @returns {any}
183
+ */
184
+ reads(bindings) {
185
+ const ret = wasm.expression_reads(this.__wbg_ptr, isLikeNone(bindings) ? 0 : addToExternrefTable0(bindings));
186
+ if (ret[2]) {
187
+ throw takeFromExternrefTable0(ret[1]);
188
+ }
189
+ return takeFromExternrefTable0(ret[0]);
190
+ }
172
191
  /**
173
192
  * Makes `implementation` available to the expression as `$name`, in every evaluation. With
174
193
  * a `signature` (such as `<n-n?:n>`), arguments are checked before each call, as for
@@ -328,6 +347,20 @@ export function parseRecover(source) {
328
347
  return ret;
329
348
  }
330
349
 
350
+ /**
351
+ * What any of several expressions reads: the union of their `reads()`. Throws a `TypeError`
352
+ * when an item is not in the form `reads()` returns.
353
+ * @param {any} reads
354
+ * @returns {any}
355
+ */
356
+ export function unionReads(reads) {
357
+ const ret = wasm.unionReads(reads);
358
+ if (ret[2]) {
359
+ throw takeFromExternrefTable0(ret[1]);
360
+ }
361
+ return takeFromExternrefTable0(ret[0]);
362
+ }
363
+
331
364
  /**
332
365
  * The jlens version.
333
366
  * @returns {string}
@@ -431,11 +464,15 @@ function __wbg_get_imports() {
431
464
  const ret = Array.isArray(arg0);
432
465
  return ret;
433
466
  },
434
- __wbg_jlensCallable_bc242b920bd3b7cb: function(arg0, arg1) {
467
+ __wbg_jlensBuild_de18e2fe951ffbb5: function(arg0, arg1, arg2, arg3, arg4, arg5) {
468
+ const ret = jlensBuild(getArrayU32FromWasm0(arg0, arg1), getArrayF64FromWasm0(arg2, arg3), getStringFromWasm0(arg4, arg5));
469
+ return ret;
470
+ },
471
+ __wbg_jlensCallable_089c61626da1df71: function(arg0, arg1) {
435
472
  const ret = jlensCallable(arg0, arg1 >>> 0);
436
473
  return ret;
437
474
  },
438
- __wbg_jlensLevel_4984dcab128c4444: function() { return handleError(function (arg0, arg1, arg2) {
475
+ __wbg_jlensLevel_7fa2a312bee944b5: function() { return handleError(function (arg0, arg1, arg2) {
439
476
  const ret = jlensLevel(arg0, arg1 >>> 0, arg2 >>> 0);
440
477
  return ret;
441
478
  }, arguments); },
@@ -522,7 +559,7 @@ function __wbg_get_imports() {
522
559
  }, arguments); },
523
560
  __wbindgen_generic_0000000000000001: function(arg0, arg1) {
524
561
  var state0 = {a: arg0, b: arg1};
525
- var cb0 = (arg0) => wasm_bindgen_dfd3dc8039a2d669___convert__closures_____invoke___js_sys_94575574b531b35c___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_dfd3dc8039a2d669___JsValue__wasm_bindgen_dfd3dc8039a2d669___JsValue___false_(state0.a, state0.b, arg0);
562
+ var cb0 = (arg0) => wasm_bindgen_83299752791f6fbb___convert__closures_____invoke___js_sys_f067e63b4fcf480b___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_83299752791f6fbb___JsValue__wasm_bindgen_83299752791f6fbb___JsValue___false_(state0.a, state0.b, arg0);
526
563
  cb0._wbg_cb_unref = () => state0.a = 0;
527
564
  // Cast intrinsic for `Closure(Closure { owned: false, function: Function { arguments: [NamedExternref("Array<any>")], shim_idx: 10, ret: Result(Externref), inner_ret: Some(Result(Externref)) }, mutable: false }) -> Externref`.
528
565
  const ret = cb0;
@@ -554,8 +591,8 @@ function __wbg_get_imports() {
554
591
  };
555
592
  }
556
593
 
557
- function wasm_bindgen_dfd3dc8039a2d669___convert__closures_____invoke___js_sys_94575574b531b35c___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_dfd3dc8039a2d669___JsValue__wasm_bindgen_dfd3dc8039a2d669___JsValue___false_(arg0, arg1, arg2) {
558
- const ret = wasm.wasm_bindgen_dfd3dc8039a2d669___convert__closures_____invoke___js_sys_94575574b531b35c___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_dfd3dc8039a2d669___JsValue__wasm_bindgen_dfd3dc8039a2d669___JsValue___false_(arg0, arg1, arg2);
594
+ function wasm_bindgen_83299752791f6fbb___convert__closures_____invoke___js_sys_f067e63b4fcf480b___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_83299752791f6fbb___JsValue__wasm_bindgen_83299752791f6fbb___JsValue___false_(arg0, arg1, arg2) {
595
+ const ret = wasm.wasm_bindgen_83299752791f6fbb___convert__closures_____invoke___js_sys_f067e63b4fcf480b___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_83299752791f6fbb___JsValue__wasm_bindgen_83299752791f6fbb___JsValue___false_(arg0, arg1, arg2);
559
596
  if (ret[2]) {
560
597
  throw takeFromExternrefTable0(ret[1]);
561
598
  }
@@ -654,6 +691,11 @@ function getArrayF64FromWasm0(ptr, len) {
654
691
  return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
655
692
  }
656
693
 
694
+ function getArrayU32FromWasm0(ptr, len) {
695
+ ptr = ptr >>> 0;
696
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
697
+ }
698
+
657
699
  let cachedDataViewMemory0 = null;
658
700
  function getDataViewMemory0() {
659
701
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
@@ -674,6 +716,14 @@ function getStringFromWasm0(ptr, len) {
674
716
  return decodeText(ptr >>> 0, len);
675
717
  }
676
718
 
719
+ let cachedUint32ArrayMemory0 = null;
720
+ function getUint32ArrayMemory0() {
721
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
722
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
723
+ }
724
+ return cachedUint32ArrayMemory0;
725
+ }
726
+
677
727
  let cachedUint8ArrayMemory0 = null;
678
728
  function getUint8ArrayMemory0() {
679
729
  if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
@@ -774,6 +824,7 @@ function __wbg_finalize_init(instance, module) {
774
824
  wasmModule = module;
775
825
  cachedDataViewMemory0 = null;
776
826
  cachedFloat64ArrayMemory0 = null;
827
+ cachedUint32ArrayMemory0 = null;
777
828
  cachedUint8ArrayMemory0 = null;
778
829
  wasm.__wbindgen_start();
779
830
  return wasm;
package/jlens_bg.wasm CHANGED
Binary file
@@ -4,7 +4,7 @@ export const memory: WebAssembly.Memory;
4
4
  export const __wbg_document_free: (a: number, b: number) => void;
5
5
  export const __wbg_expression_free: (a: number, b: number) => void;
6
6
  export const __wbg_languageservice_free: (a: number, b: number) => void;
7
- export const document_fromJson: (a: number, b: number) => [number, number, number];
7
+ export const document_fromJson: (a: number, b: number, c: number) => [number, number, number];
8
8
  export const document_new: (a: any) => [number, number, number];
9
9
  export const expression_ast: (a: number) => any;
10
10
  export const expression_evaluate: (a: number, b: number, c: number, d: number) => [number, number, number];
@@ -12,6 +12,7 @@ export const expression_evaluateDocument: (a: number, b: number, c: number, d: n
12
12
  export const expression_evaluateJson: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
13
13
  export const expression_evaluateWithAudit: (a: number, b: number, c: number, d: number) => [number, number, number];
14
14
  export const expression_new: (a: number, b: number) => [number, number, number];
15
+ export const expression_reads: (a: number, b: number) => [number, number, number];
15
16
  export const expression_registerFunction: (a: number, b: number, c: number, d: any, e: number, f: number) => [number, number];
16
17
  export const expression_source: (a: number) => [number, number];
17
18
  export const functions: () => any;
@@ -22,8 +23,9 @@ export const languageservice_hover: (a: number, b: number, c: number, d: number)
22
23
  export const languageservice_new: (a: number, b: number, c: number) => [number, number, number];
23
24
  export const languageservice_signatureHelp: (a: number, b: number, c: number, d: number) => any;
24
25
  export const parseRecover: (a: number, b: number) => any;
26
+ export const unionReads: (a: any) => [number, number, number];
25
27
  export const version: () => [number, number];
26
- export const wasm_bindgen_dfd3dc8039a2d669___convert__closures_____invoke___js_sys_94575574b531b35c___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_dfd3dc8039a2d669___JsValue__wasm_bindgen_dfd3dc8039a2d669___JsValue___false_: (a: number, b: number, c: any) => [number, number, number];
28
+ export const wasm_bindgen_83299752791f6fbb___convert__closures_____invoke___js_sys_f067e63b4fcf480b___Array__core_37ee0ce0c4cd57d5___result__Result_wasm_bindgen_83299752791f6fbb___JsValue__wasm_bindgen_83299752791f6fbb___JsValue___false_: (a: number, b: number, c: any) => [number, number, number];
27
29
  export const __wbindgen_malloc: (a: number, b: number) => number;
28
30
  export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
29
31
  export const __wbindgen_exn_store: (a: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jlens-wasm",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "description": "JSONata in WebAssembly, with evaluation audits and schema-driven autocomplete",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -0,0 +1,48 @@
1
+
2
+ // Builds the values that `ops` describes, in order: a stack holds the values built, and the
3
+ // arrays and objects being filled. `text` holds the strings and the new keys, one after the
4
+ // other (lengths in UTF-16 code units). Returns the last value built: the result.
5
+ export function jlensBuild(ops, nums, text) {
6
+ const stack = [];
7
+ const keys = [];
8
+ // The index of the key `__proto__`, which an assignment would take for the prototype.
9
+ let proto = -1;
10
+ let num = 0, pos = 0;
11
+ for (let i = 0; i < ops.length; i++) {
12
+ switch (ops[i]) {
13
+ case 0: stack.push(null); break;
14
+ case 1: stack.push(false); break;
15
+ case 2: stack.push(true); break;
16
+ case 3: stack.push(nums[num++]); break;
17
+ case 4: { const end = pos + ops[++i]; stack.push(text.slice(pos, end)); pos = end; break; }
18
+ case 5: stack.push([]); break;
19
+ case 6: { const item = stack.pop(); stack[stack.length - 1].push(item); break; }
20
+ case 7: stack.push({}); break;
21
+ case 8: {
22
+ const key = ops[++i];
23
+ const value = stack.pop();
24
+ if (key === proto) own(stack[stack.length - 1], keys[key], value);
25
+ else stack[stack.length - 1][keys[key]] = value;
26
+ break;
27
+ }
28
+ case 9: {
29
+ const end = pos + ops[++i];
30
+ const key = text.slice(pos, end);
31
+ pos = end;
32
+ const value = stack.pop();
33
+ if (key === "__proto__") {
34
+ proto = keys.length;
35
+ own(stack[stack.length - 1], key, value);
36
+ } else stack[stack.length - 1][key] = value;
37
+ keys.push(key);
38
+ break;
39
+ }
40
+ }
41
+ }
42
+ return stack.pop();
43
+ }
44
+
45
+ // Defines an own property, as JSON.parse does.
46
+ function own(object, key, value) {
47
+ Object.defineProperty(object, key, { value, writable: true, enumerable: true, configurable: true });
48
+ }