jlens-wasm 0.16.0 → 0.18.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,6 +525,7 @@ 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
530
  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];
492
531
  readonly __wbindgen_malloc: (a: number, b: number) => number;
package/jlens.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /* @ts-self-types="./jlens.d.ts" */
2
- import { jlensCallable } from './snippets/jlens-wasm-916cefd4ec897092/inline0.js';
3
- import { jlensLevel } from './snippets/jlens-wasm-916cefd4ec897092/inline1.js';
2
+ import { jlensCallable } from './snippets/jlens-wasm-b5dd6593a6f87d95/inline0.js';
3
+ import { jlensLevel } from './snippets/jlens-wasm-b5dd6593a6f87d95/inline1.js';
4
4
 
5
5
 
6
6
  /**
@@ -25,14 +25,16 @@ export class Document {
25
25
  wasm.__wbg_document_free(ptr, 0);
26
26
  }
27
27
  /**
28
- * Parses JSON text.
28
+ * Parses JSON text. With `read` (the `input` of a `reads()`, or of a `unionReads()`), the
29
+ * fields it leaves out are skipped: they are checked as JSON syntax only.
29
30
  * @param {string} text
31
+ * @param {any | null} [read]
30
32
  * @returns {Document}
31
33
  */
32
- static fromJson(text) {
34
+ static fromJson(text, read) {
33
35
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
34
36
  const len0 = WASM_VECTOR_LEN;
35
- const ret = wasm.document_fromJson(ptr0, len0);
37
+ const ret = wasm.document_fromJson(ptr0, len0, isLikeNone(read) ? 0 : addToExternrefTable0(read));
36
38
  if (ret[2]) {
37
39
  throw takeFromExternrefTable0(ret[1]);
38
40
  }
@@ -98,7 +100,8 @@ export class Expression {
98
100
  }
99
101
  /**
100
102
  * Like `evaluate`, with the input document and the result as JSON text. This avoids
101
- * converting large documents to and from JavaScript objects.
103
+ * converting large documents to and from JavaScript objects. The fields of the input that
104
+ * the expression does not read (`reads()`, without bindings) are skipped while parsing.
102
105
  * @param {string | null} [input]
103
106
  * @param {any | null} [bindings]
104
107
  * @param {any | null} [options]
@@ -169,6 +172,21 @@ export class Expression {
169
172
  ExpressionFinalization.register(this, this.__wbg_ptr, this);
170
173
  return this;
171
174
  }
175
+ /**
176
+ * The fields of the input and of the bindings the expression reads (ADR 0016). The
177
+ * functions in `bindings`, and those registered on the expression, read only their
178
+ * arguments, since a JavaScript function cannot read the context of its call; a call to a
179
+ * function the analysis does not know reads its context whole.
180
+ * @param {any | null} [bindings]
181
+ * @returns {any}
182
+ */
183
+ reads(bindings) {
184
+ const ret = wasm.expression_reads(this.__wbg_ptr, isLikeNone(bindings) ? 0 : addToExternrefTable0(bindings));
185
+ if (ret[2]) {
186
+ throw takeFromExternrefTable0(ret[1]);
187
+ }
188
+ return takeFromExternrefTable0(ret[0]);
189
+ }
172
190
  /**
173
191
  * Makes `implementation` available to the expression as `$name`, in every evaluation. With
174
192
  * a `signature` (such as `<n-n?:n>`), arguments are checked before each call, as for
@@ -328,6 +346,20 @@ export function parseRecover(source) {
328
346
  return ret;
329
347
  }
330
348
 
349
+ /**
350
+ * What any of several expressions reads: the union of their `reads()`. Throws a `TypeError`
351
+ * when an item is not in the form `reads()` returns.
352
+ * @param {any} reads
353
+ * @returns {any}
354
+ */
355
+ export function unionReads(reads) {
356
+ const ret = wasm.unionReads(reads);
357
+ if (ret[2]) {
358
+ throw takeFromExternrefTable0(ret[1]);
359
+ }
360
+ return takeFromExternrefTable0(ret[0]);
361
+ }
362
+
331
363
  /**
332
364
  * The jlens version.
333
365
  * @returns {string}
@@ -431,11 +463,11 @@ function __wbg_get_imports() {
431
463
  const ret = Array.isArray(arg0);
432
464
  return ret;
433
465
  },
434
- __wbg_jlensCallable_994f4bff15a48977: function(arg0, arg1) {
466
+ __wbg_jlensCallable_7d9ffbb6d82e5c6e: function(arg0, arg1) {
435
467
  const ret = jlensCallable(arg0, arg1 >>> 0);
436
468
  return ret;
437
469
  },
438
- __wbg_jlensLevel_004c4888e371d1a1: function() { return handleError(function (arg0, arg1, arg2) {
470
+ __wbg_jlensLevel_7fc665e0f96eeefc: function() { return handleError(function (arg0, arg1, arg2) {
439
471
  const ret = jlensLevel(arg0, arg1 >>> 0, arg2 >>> 0);
440
472
  return ret;
441
473
  }, arguments); },
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,6 +23,7 @@ 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
28
  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];
27
29
  export const __wbindgen_malloc: (a: number, b: number) => number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jlens-wasm",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "JSONata in WebAssembly, with evaluation audits and schema-driven autocomplete",
5
5
  "license": "MIT",
6
6
  "repository": {