jlens-wasm 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 jlens contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,47 @@
1
- # Temporary Holding Version
1
+ # jlens-wasm
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [JSONata](https://jsonata.org/) for the browser, compiled from Rust to WebAssembly. It
4
+ evaluates expressions, **explains** how a result was reached, and gives editors completion,
5
+ diagnostics and hover driven by a JSON Schema inferred from sample documents.
6
+
7
+ This is an ES module for browsers (`--target web`). It also runs in Node.js 20+ and Deno if you
8
+ pass the `.wasm` bytes to `init`.
9
+
10
+ ```js
11
+ import init, { Expression } from "jlens-wasm";
12
+
13
+ await init(); // fetches jlens_bg.wasm next to jlens.js
14
+
15
+ const expr = new Expression("$sum(items[type = $kind].(price * qty))");
16
+ expr.evaluate({ items: [{ type: "a", price: 2.5, qty: 4 }] }, { kind: "a" }); // 10
17
+ ```
18
+
19
+ ## API
20
+
21
+ | Export | Purpose |
22
+ |---|---|
23
+ | `init(options?)` | Loads the WebAssembly module; call (and await) it once before anything else |
24
+ | `new Expression(source)` | Compiles an expression; throws a `JlensError` on syntax errors |
25
+ | `expr.evaluate(input?, bindings?, options?)` | Evaluates against a JSON-compatible value; `undefined` when the result is undefined |
26
+ | `expr.evaluateJson(json?, bindings?, options?)` | The same with JSON text in and out (faster for large documents) |
27
+ | `new Document(input)`, `Document.fromJson(text)` | A document converted once, for `expr.evaluateDocument(doc, bindings?, options?)` |
28
+ | `expr.evaluateWithAudit(input?, bindings?, options?)` | Result, audit tree and explanation; errors are reported, not thrown |
29
+ | `expr.ast()` | The processed syntax tree |
30
+ | `parseRecover(source)` | Partial syntax tree and every diagnostic, without throwing |
31
+ | `inferSchema(samples, overrides?)` | A JSON Schema (2020-12) inferred from sample documents |
32
+ | `new LanguageService(schema?, variables?)` | `complete`, `diagnostics`, `hover` and `signatureHelp` for an editor |
33
+ | `functions()` | The built-in function catalog |
34
+ | `version()` | The jlens version |
35
+
36
+ `options` takes `timeout` (milliseconds) and `maxDepth`; for `evaluateWithAudit` also `level`
37
+ (`"off"`, `"decisions"`, `"full"`) and `limits`. Errors are `Error` objects named `JlensError`
38
+ with the JSONata error `code`, plus `position`, `start`, `end` and `token` when known.
39
+
40
+ All offsets, in both directions, are UTF-16 code units, like JavaScript string indexes.
41
+
42
+ The full guide is the "WebAssembly (browser)" chapter of the jlens book (`docs/src/guides/wasm.md`).
43
+
44
+ ## License
45
+
46
+ MIT. The JSONata test suite and the documentation adapted from JSONata are © IBM Corp. and
47
+ JSONata contributors, also under the MIT license.
package/jlens.d.ts ADDED
@@ -0,0 +1,455 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /** Variables an expression is evaluated with: `{limit: 10}` defines `$limit`. */
4
+ export type Bindings = Record<string, unknown>;
5
+
6
+ /** Evaluation guardrails. */
7
+ export interface EvaluateOptions {
8
+ /** Maximum duration of one evaluation, in milliseconds (error `D1012`). */
9
+ timeout?: number;
10
+ /** Maximum evaluation depth (error `D1011`). */
11
+ maxDepth?: number;
12
+ }
13
+
14
+ /** A range of the expression source, in UTF-16 code units (`end` is exclusive). */
15
+ export interface Span {
16
+ start: number;
17
+ end: number;
18
+ }
19
+
20
+ /**
21
+ * The error thrown by `new Expression()`, `evaluate()` and `evaluateJson()`. Check it with
22
+ * `err.name === "JlensError"`.
23
+ */
24
+ export interface JlensError extends Error {
25
+ name: "JlensError";
26
+ /** The JSONata error code, such as `S0202` or `T2001`. */
27
+ code: string;
28
+ /** Where the error was detected, like jsonata-js: usually just after the offending token. */
29
+ position?: number;
30
+ /** The offending source range, when known. */
31
+ start?: number;
32
+ end?: number;
33
+ /** The token involved, when there is one. */
34
+ token?: string;
35
+ /** The value involved, when there is one. */
36
+ value?: unknown;
37
+ }
38
+
39
+ /** The fields of a `JlensError`, as reported in an `AuditResult`. */
40
+ export interface ErrorInfo {
41
+ code: string;
42
+ message: string;
43
+ position?: number;
44
+ start?: number;
45
+ end?: number;
46
+ token?: string;
47
+ value?: unknown;
48
+ }
49
+
50
+ // ---------------------------------------------------------------------------------------------
51
+ // Auditing
52
+
53
+ /** What an audit records. */
54
+ export type AuditLevel = "off" | "decisions" | "full";
55
+
56
+ /** Bounds on what an audit captures. */
57
+ export interface CaptureLimits {
58
+ /** Items kept from an array (and fields from an object) in captured values. Default 10. */
59
+ maxItems: number;
60
+ /** Characters kept from a string in captured values. Default 200. */
61
+ maxString: number;
62
+ /** Nesting depth kept in captured values. Default 4. */
63
+ maxDepth: number;
64
+ /** Rejected items kept as samples per filter. Default 5. */
65
+ maxRejected: number;
66
+ /** Nodes recorded in the tree. Default 10000. */
67
+ maxNodes: number;
68
+ /** Characters of source text kept per node. Default 200. */
69
+ maxSource: number;
70
+ }
71
+
72
+ /** Options of `evaluateWithAudit`. */
73
+ export interface AuditOptions extends EvaluateOptions {
74
+ /** Default `"decisions"`. */
75
+ level?: AuditLevel;
76
+ limits?: Partial<CaptureLimits>;
77
+ }
78
+
79
+ /** The result of `evaluateWithAudit`. */
80
+ export interface AuditResult {
81
+ /** The result; absent when undefined or when the evaluation failed. */
82
+ result?: unknown;
83
+ /** The error, when the evaluation failed. */
84
+ error?: ErrorInfo;
85
+ /** The audit tree. */
86
+ audit: AuditTree;
87
+ /** Why the result was reached. */
88
+ explanation: Explanation;
89
+ /** `explanation` rendered as text, as printed by `jlens eval --explain`. */
90
+ explanationText: string;
91
+ }
92
+
93
+ export interface AuditTree {
94
+ header: AuditHeader;
95
+ /** Absent with level `"off"`. */
96
+ root?: AuditNode;
97
+ nodeCount: number;
98
+ /** Whether nodes were dropped because of `maxNodes`. */
99
+ truncated: boolean;
100
+ }
101
+
102
+ export interface AuditHeader {
103
+ /** `jlens-core` and its version. */
104
+ engine: string;
105
+ /** FNV-1a 64-bit hash of the expression source, in hexadecimal. */
106
+ expressionHash: string;
107
+ /** FNV-1a 64-bit hash of the input document's JSON text, in hexadecimal. */
108
+ inputHash: string;
109
+ /** The evaluation timestamp (`$now()`), in ISO 8601. */
110
+ timestamp: string;
111
+ durationMs: number;
112
+ level: AuditLevel;
113
+ result?: unknown;
114
+ error?: { code: string; message: string };
115
+ }
116
+
117
+ export type OutcomeKind = "true" | "false" | "value" | "undefined" | "error";
118
+
119
+ /** One evaluation of one node. */
120
+ export interface AuditNode {
121
+ /** The syntax-tree node id. */
122
+ node: number;
123
+ /** The node type (`binary`, `path`, `function`, ...). */
124
+ kind: string;
125
+ /** The operator, function or variable name. */
126
+ op?: string;
127
+ span: Span;
128
+ /** The node's source text (possibly shortened). */
129
+ source: string;
130
+ /** Annotation `@label`, `@message` and `@id`. */
131
+ label?: string;
132
+ message?: string;
133
+ checkId?: string;
134
+ /** The context value (level `"full"` only). */
135
+ input?: unknown;
136
+ output?: unknown;
137
+ outcome: OutcomeKind;
138
+ error?: { code: string; message: string };
139
+ /** The compared values, for comparisons (`null` stands for undefined). */
140
+ operands?: [unknown, unknown];
141
+ /** For `and`/`or`: the right side was not evaluated. */
142
+ shortCircuited?: boolean;
143
+ /** For conditionals: the branch taken. */
144
+ branch?: "then" | "else" | "none";
145
+ /** For `$name := value`: the variable bound. */
146
+ binding?: string;
147
+ filters?: FilterAudit[];
148
+ children?: AuditNode[];
149
+ }
150
+
151
+ /** Statistics of a predicate filter. */
152
+ export interface FilterAudit {
153
+ node: number;
154
+ source: string;
155
+ label?: string;
156
+ tested: number;
157
+ passed: number;
158
+ /** A sample of the items that did not pass. */
159
+ rejected?: unknown[];
160
+ }
161
+
162
+ export interface Explanation {
163
+ /** The result, or the error, as text. */
164
+ result: string;
165
+ lines: ExplanationLine[];
166
+ }
167
+
168
+ export interface ExplanationLine {
169
+ depth: number;
170
+ /** `true` for a check that held, `false` for one that failed, `null` otherwise. */
171
+ passed: boolean | null;
172
+ text: string;
173
+ /** The annotation `@message`, shown for failed checks. */
174
+ message?: string;
175
+ /** The syntax-tree node the line is about. */
176
+ node: number;
177
+ }
178
+
179
+ // ---------------------------------------------------------------------------------------------
180
+ // Parsing
181
+
182
+ /** A node of the processed syntax tree. The `type` field tells the kind of node. */
183
+ export interface AstNode {
184
+ id: number;
185
+ type: string;
186
+ span: Span;
187
+ annotation?: Annotation;
188
+ [field: string]: unknown;
189
+ }
190
+
191
+ /** An audit annotation, read from a `/** ... *\/` comment. */
192
+ export interface Annotation {
193
+ label?: string;
194
+ message?: string;
195
+ id?: string;
196
+ description?: string;
197
+ span: Span;
198
+ }
199
+
200
+ export interface Diagnostic {
201
+ severity: "error" | "warning";
202
+ /** A JSONata error code (`S0xxx`) or a jlens warning code (`W0xxx`). */
203
+ code: string;
204
+ message: string;
205
+ span: Span;
206
+ }
207
+
208
+ /** The result of `parseRecover`. */
209
+ export interface ParseResult {
210
+ ast: AstNode;
211
+ diagnostics: Diagnostic[];
212
+ }
213
+
214
+ // ---------------------------------------------------------------------------------------------
215
+ // Schemas and the language service
216
+
217
+ /** A JSON Schema document (2020-12). */
218
+ export type JsonSchema = boolean | { [keyword: string]: unknown };
219
+
220
+ export type JsonType = "null" | "boolean" | "integer" | "number" | "string" | "array" | "object";
221
+
222
+ /** Settings applied to the value at one path of an inferred schema. */
223
+ export interface SchemaOverride {
224
+ description?: string;
225
+ label?: string;
226
+ /** Hide from completion. */
227
+ hidden?: boolean;
228
+ enum?: unknown[];
229
+ format?: string;
230
+ type?: JsonType[];
231
+ examples?: unknown[];
232
+ }
233
+
234
+ export type CompletionKind = "field" | "variable" | "function" | "keyword" | "operator";
235
+
236
+ export interface CompletionItem {
237
+ label: string;
238
+ kind: CompletionKind;
239
+ /** The type of a field or variable, the signature of a function. */
240
+ detail?: string;
241
+ /** Markdown. */
242
+ documentation?: string;
243
+ /** The text to insert in place of `Completions.range`. */
244
+ insertText: string;
245
+ }
246
+
247
+ export interface Completions {
248
+ /** The range the chosen item replaces (the word under the cursor). */
249
+ range: Span;
250
+ /** Best first. */
251
+ items: CompletionItem[];
252
+ }
253
+
254
+ export interface Hover {
255
+ range: Span;
256
+ /** Markdown. */
257
+ contents: string;
258
+ }
259
+
260
+ export interface SignatureHelp {
261
+ /** The function name, with `$`. */
262
+ name: string;
263
+ signature: string;
264
+ params: string[];
265
+ /** The parameter being edited (0-based). */
266
+ activeParam: number;
267
+ summary: string;
268
+ }
269
+
270
+ export type FunctionCategory =
271
+ | "string"
272
+ | "numeric"
273
+ | "aggregation"
274
+ | "boolean"
275
+ | "array"
276
+ | "object"
277
+ | "higher-order"
278
+ | "date-time"
279
+ | "encoding"
280
+ | "misc";
281
+
282
+ export interface FunctionInfo {
283
+ /** The name, without `$`. */
284
+ name: string;
285
+ signature: string;
286
+ params: string[];
287
+ category: FunctionCategory;
288
+ summary: string;
289
+ }
290
+
291
+ // ---------------------------------------------------------------------------------------------
292
+ // Classes and functions with optional arguments (declared here so that the arguments are optional)
293
+
294
+ /**
295
+ * A compiled JSONata expression. Compile once, then evaluate against any number of documents.
296
+ * Call `free()` when it is no longer needed, or rely on the garbage collector.
297
+ */
298
+ export class Expression {
299
+ /** Compiles a JSONata expression. Throws a `JlensError` on syntax errors. */
300
+ constructor(source: string);
301
+ /** The source text of the expression. */
302
+ readonly source: string;
303
+ /**
304
+ * Evaluates the expression against `input`, a JSON-compatible value (`undefined` means no
305
+ * input document). Returns `undefined` when the result is undefined; throws a `JlensError`
306
+ * when the evaluation fails.
307
+ */
308
+ evaluate(input?: unknown, bindings?: Bindings | null, options?: EvaluateOptions): unknown;
309
+ /**
310
+ * Like `evaluate`, with the input document and the result as JSON text. This avoids
311
+ * converting large documents to and from JavaScript objects.
312
+ */
313
+ evaluateJson(
314
+ input?: string | null,
315
+ bindings?: Bindings | null,
316
+ options?: EvaluateOptions,
317
+ ): string | undefined;
318
+ /**
319
+ * Evaluates the expression and records how the result was reached. Evaluation errors are
320
+ * reported in the returned `error`, not thrown.
321
+ */
322
+ /**
323
+ * Evaluates the expression against a `Document` converted beforehand, which avoids converting
324
+ * the input on every call. Use it to evaluate several expressions against one document.
325
+ */
326
+ evaluateDocument(document: Document, bindings?: Bindings | null, options?: EvaluateOptions): unknown;
327
+ evaluateWithAudit(input?: unknown, bindings?: Bindings | null, options?: AuditOptions): AuditResult;
328
+ /** The processed syntax tree, as plain objects. */
329
+ ast(): AstNode;
330
+ /** Releases the compiled expression. */
331
+ free(): void;
332
+ [Symbol.dispose](): void;
333
+ }
334
+
335
+ /**
336
+ * A JSON document converted once into jlens's internal representation. Evaluating against a
337
+ * `Document` (`expr.evaluateDocument(doc)`) skips converting the input on every call.
338
+ */
339
+ export class Document {
340
+ /** Converts a JSON-compatible value. */
341
+ constructor(input: unknown);
342
+ /** Parses JSON text. Throws a `TypeError` when it is not valid JSON. */
343
+ static fromJson(text: string): Document;
344
+ free(): void;
345
+ [Symbol.dispose](): void;
346
+ }
347
+
348
+ /**
349
+ * Completion, diagnostics, hover and signature help for expressions over documents described by
350
+ * a JSON Schema.
351
+ */
352
+ export class LanguageService {
353
+ /**
354
+ * `schema` describes the input documents; without it, functions and variables are still
355
+ * completed. `variables` declares the bindings the expressions are evaluated with (names with
356
+ * or without `$`), optionally with a schema for their values.
357
+ */
358
+ constructor(schema?: JsonSchema | null, variables?: Record<string, JsonSchema | null>);
359
+ /** Suggestions for the word at `offset`, and the range they replace. */
360
+ complete(text: string, offset: number): Completions;
361
+ /** Syntax errors, and references to fields the schema does not have. */
362
+ diagnostics(text: string): Diagnostic[];
363
+ /** The type and description of what is under `offset`, if anything. */
364
+ hover(text: string, offset: number): Hover | undefined;
365
+ /** The parameters of the function call around `offset`, if any. */
366
+ signatureHelp(text: string, offset: number): SignatureHelp | undefined;
367
+ free(): void;
368
+ [Symbol.dispose](): void;
369
+ }
370
+
371
+ /**
372
+ * Infers a JSON Schema (2020-12, with `x-jlens-*` annotations) from sample documents.
373
+ * `overrides` adds descriptions, labels, allowed values and hidden fields by path, such as
374
+ * `"items[].type"`.
375
+ * Paths missing from the samples are declared; a malformed path or override throws a `TypeError`.
376
+ */
377
+ export function inferSchema(
378
+ samples: unknown[],
379
+ overrides?: Record<string, SchemaOverride>,
380
+ ): JsonSchema;
381
+
382
+
383
+
384
+ /**
385
+ * The built-in functions: name, signature, parameters, category and summary.
386
+ */
387
+ export function functions(): FunctionInfo[];
388
+
389
+ /**
390
+ * Parses an expression, recovering from syntax errors: returns the (partial) syntax tree and
391
+ * every problem found. This never throws.
392
+ */
393
+ export function parseRecover(source: string): ParseResult;
394
+
395
+ /**
396
+ * The jlens version.
397
+ */
398
+ export function version(): string;
399
+
400
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
401
+
402
+ export interface InitOutput {
403
+ readonly memory: WebAssembly.Memory;
404
+ readonly __wbg_document_free: (a: number, b: number) => void;
405
+ readonly __wbg_expression_free: (a: number, b: number) => void;
406
+ readonly __wbg_languageservice_free: (a: number, b: number) => void;
407
+ readonly document_fromJson: (a: number, b: number) => [number, number, number];
408
+ readonly document_new: (a: any) => [number, number, number];
409
+ readonly expression_ast: (a: number) => any;
410
+ readonly expression_evaluate: (a: number, b: number, c: number, d: number) => [number, number, number];
411
+ readonly expression_evaluateDocument: (a: number, b: number, c: number, d: number) => [number, number, number];
412
+ readonly expression_evaluateJson: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
413
+ readonly expression_evaluateWithAudit: (a: number, b: number, c: number, d: number) => [number, number, number];
414
+ readonly expression_new: (a: number, b: number) => [number, number, number];
415
+ readonly expression_source: (a: number) => [number, number];
416
+ readonly functions: () => any;
417
+ readonly inferSchema: (a: any, b: number) => [number, number, number];
418
+ readonly languageservice_complete: (a: number, b: number, c: number, d: number) => any;
419
+ readonly languageservice_diagnostics: (a: number, b: number, c: number) => any;
420
+ readonly languageservice_hover: (a: number, b: number, c: number, d: number) => any;
421
+ readonly languageservice_new: (a: number, b: number) => [number, number, number];
422
+ readonly languageservice_signatureHelp: (a: number, b: number, c: number, d: number) => any;
423
+ readonly parseRecover: (a: number, b: number) => any;
424
+ readonly version: () => [number, number];
425
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
426
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
427
+ readonly __wbindgen_exn_store: (a: number) => void;
428
+ readonly __externref_table_alloc: () => number;
429
+ readonly __wbindgen_externrefs: WebAssembly.Table;
430
+ readonly __externref_table_dealloc: (a: number) => void;
431
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
432
+ readonly __wbindgen_start: () => void;
433
+ }
434
+
435
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
436
+
437
+ /**
438
+ * Instantiates the given `module`, which can either be bytes or
439
+ * a precompiled `WebAssembly.Module`.
440
+ *
441
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
442
+ *
443
+ * @returns {InitOutput}
444
+ */
445
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
446
+
447
+ /**
448
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
449
+ * for everything else, calls `WebAssembly.instantiate` directly.
450
+ *
451
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
452
+ *
453
+ * @returns {Promise<InitOutput>}
454
+ */
455
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/jlens.js ADDED
@@ -0,0 +1,709 @@
1
+ /* @ts-self-types="./jlens.d.ts" */
2
+
3
+ /**
4
+ * A JSON document converted once into jlens's internal representation, for evaluating
5
+ * several expressions (or one several times) against it.
6
+ */
7
+ export class Document {
8
+ static __wrap(ptr) {
9
+ const obj = Object.create(Document.prototype);
10
+ obj.__wbg_ptr = ptr;
11
+ DocumentFinalization.register(obj, obj.__wbg_ptr, obj);
12
+ return obj;
13
+ }
14
+ __destroy_into_raw() {
15
+ const ptr = this.__wbg_ptr;
16
+ this.__wbg_ptr = 0;
17
+ DocumentFinalization.unregister(this);
18
+ return ptr;
19
+ }
20
+ free() {
21
+ const ptr = this.__destroy_into_raw();
22
+ wasm.__wbg_document_free(ptr, 0);
23
+ }
24
+ /**
25
+ * Parses JSON text.
26
+ * @param {string} text
27
+ * @returns {Document}
28
+ */
29
+ static fromJson(text) {
30
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
31
+ const len0 = WASM_VECTOR_LEN;
32
+ const ret = wasm.document_fromJson(ptr0, len0);
33
+ if (ret[2]) {
34
+ throw takeFromExternrefTable0(ret[1]);
35
+ }
36
+ return Document.__wrap(ret[0]);
37
+ }
38
+ /**
39
+ * Converts a JSON-compatible value.
40
+ * @param {any} input
41
+ */
42
+ constructor(input) {
43
+ const ret = wasm.document_new(input);
44
+ if (ret[2]) {
45
+ throw takeFromExternrefTable0(ret[1]);
46
+ }
47
+ this.__wbg_ptr = ret[0];
48
+ DocumentFinalization.register(this, this.__wbg_ptr, this);
49
+ return this;
50
+ }
51
+ }
52
+ if (Symbol.dispose) Document.prototype[Symbol.dispose] = Document.prototype.free;
53
+
54
+ /**
55
+ * A compiled JSONata expression.
56
+ *
57
+ * Compile once, then evaluate against any number of documents. Call `free()` when the
58
+ * expression is no longer needed (or rely on the garbage collector, where `FinalizationRegistry`
59
+ * is available).
60
+ */
61
+ export class Expression {
62
+ __destroy_into_raw() {
63
+ const ptr = this.__wbg_ptr;
64
+ this.__wbg_ptr = 0;
65
+ ExpressionFinalization.unregister(this);
66
+ return ptr;
67
+ }
68
+ free() {
69
+ const ptr = this.__destroy_into_raw();
70
+ wasm.__wbg_expression_free(ptr, 0);
71
+ }
72
+ /**
73
+ * The processed syntax tree, as plain objects (spans in UTF-16 code units).
74
+ * @returns {any}
75
+ */
76
+ ast() {
77
+ const ret = wasm.expression_ast(this.__wbg_ptr);
78
+ return ret;
79
+ }
80
+ /**
81
+ * Evaluates the expression against a `Document` converted beforehand, which avoids
82
+ * converting the input on every call.
83
+ * @param {Document} document
84
+ * @param {any | null} [bindings]
85
+ * @param {any | null} [options]
86
+ * @returns {any}
87
+ */
88
+ evaluateDocument(document, bindings, options) {
89
+ _assertClass(document, Document);
90
+ const ret = wasm.expression_evaluateDocument(this.__wbg_ptr, document.__wbg_ptr, isLikeNone(bindings) ? 0 : addToExternrefTable0(bindings), isLikeNone(options) ? 0 : addToExternrefTable0(options));
91
+ if (ret[2]) {
92
+ throw takeFromExternrefTable0(ret[1]);
93
+ }
94
+ return takeFromExternrefTable0(ret[0]);
95
+ }
96
+ /**
97
+ * Like `evaluate`, with the input document and the result as JSON text. This avoids
98
+ * converting large documents to and from JavaScript objects.
99
+ * @param {string | null} [input]
100
+ * @param {any | null} [bindings]
101
+ * @param {any | null} [options]
102
+ * @returns {string | undefined}
103
+ */
104
+ evaluateJson(input, bindings, options) {
105
+ var ptr0 = isLikeNone(input) ? 0 : passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
106
+ var len0 = WASM_VECTOR_LEN;
107
+ const ret = wasm.expression_evaluateJson(this.__wbg_ptr, ptr0, len0, isLikeNone(bindings) ? 0 : addToExternrefTable0(bindings), isLikeNone(options) ? 0 : addToExternrefTable0(options));
108
+ if (ret[3]) {
109
+ throw takeFromExternrefTable0(ret[2]);
110
+ }
111
+ let v2;
112
+ if (ret[0] !== 0) {
113
+ v2 = getStringFromWasm0(ret[0], ret[1]);
114
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
115
+ }
116
+ return v2;
117
+ }
118
+ /**
119
+ * Evaluates the expression and records how the result was reached. Never throws for
120
+ * evaluation errors: they are reported in the returned `error`.
121
+ * @param {any | null} [input]
122
+ * @param {any | null} [bindings]
123
+ * @param {any | null} [options]
124
+ * @returns {any}
125
+ */
126
+ evaluateWithAudit(input, bindings, options) {
127
+ const ret = wasm.expression_evaluateWithAudit(this.__wbg_ptr, isLikeNone(input) ? 0 : addToExternrefTable0(input), isLikeNone(bindings) ? 0 : addToExternrefTable0(bindings), isLikeNone(options) ? 0 : addToExternrefTable0(options));
128
+ if (ret[2]) {
129
+ throw takeFromExternrefTable0(ret[1]);
130
+ }
131
+ return takeFromExternrefTable0(ret[0]);
132
+ }
133
+ /**
134
+ * Evaluates the expression against `input`, a JSON-compatible value (`undefined` means no
135
+ * input document). `bindings` provides variables: `{limit: 10}` defines `$limit`.
136
+ * Returns `undefined` when the result is undefined; throws a `JlensError` when the
137
+ * evaluation fails.
138
+ * @param {any | null} [input]
139
+ * @param {any | null} [bindings]
140
+ * @param {any | null} [options]
141
+ * @returns {any}
142
+ */
143
+ evaluate(input, bindings, options) {
144
+ const ret = wasm.expression_evaluate(this.__wbg_ptr, isLikeNone(input) ? 0 : addToExternrefTable0(input), isLikeNone(bindings) ? 0 : addToExternrefTable0(bindings), isLikeNone(options) ? 0 : addToExternrefTable0(options));
145
+ if (ret[2]) {
146
+ throw takeFromExternrefTable0(ret[1]);
147
+ }
148
+ return takeFromExternrefTable0(ret[0]);
149
+ }
150
+ /**
151
+ * Compiles a JSONata expression. Throws a `JlensError` on syntax errors.
152
+ * @param {string} source
153
+ */
154
+ constructor(source) {
155
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
156
+ const len0 = WASM_VECTOR_LEN;
157
+ const ret = wasm.expression_new(ptr0, len0);
158
+ if (ret[2]) {
159
+ throw takeFromExternrefTable0(ret[1]);
160
+ }
161
+ this.__wbg_ptr = ret[0];
162
+ ExpressionFinalization.register(this, this.__wbg_ptr, this);
163
+ return this;
164
+ }
165
+ /**
166
+ * The source text of the expression.
167
+ * @returns {string}
168
+ */
169
+ get source() {
170
+ let deferred1_0;
171
+ let deferred1_1;
172
+ try {
173
+ const ret = wasm.expression_source(this.__wbg_ptr);
174
+ deferred1_0 = ret[0];
175
+ deferred1_1 = ret[1];
176
+ return getStringFromWasm0(ret[0], ret[1]);
177
+ } finally {
178
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
179
+ }
180
+ }
181
+ }
182
+ if (Symbol.dispose) Expression.prototype[Symbol.dispose] = Expression.prototype.free;
183
+
184
+ /**
185
+ * Completion, diagnostics, hover and signature help for expressions over documents described
186
+ * by a JSON Schema. Offsets are in UTF-16 code units.
187
+ */
188
+ export class LanguageService {
189
+ __destroy_into_raw() {
190
+ const ptr = this.__wbg_ptr;
191
+ this.__wbg_ptr = 0;
192
+ LanguageServiceFinalization.unregister(this);
193
+ return ptr;
194
+ }
195
+ free() {
196
+ const ptr = this.__destroy_into_raw();
197
+ wasm.__wbg_languageservice_free(ptr, 0);
198
+ }
199
+ /**
200
+ * Suggestions for the word at `offset`, and the range they replace.
201
+ * @param {string} text
202
+ * @param {number} offset
203
+ * @returns {any}
204
+ */
205
+ complete(text, offset) {
206
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
207
+ const len0 = WASM_VECTOR_LEN;
208
+ const ret = wasm.languageservice_complete(this.__wbg_ptr, ptr0, len0, offset);
209
+ return ret;
210
+ }
211
+ /**
212
+ * Syntax errors, and references to fields the schema does not have.
213
+ * @param {string} text
214
+ * @returns {any}
215
+ */
216
+ diagnostics(text) {
217
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
218
+ const len0 = WASM_VECTOR_LEN;
219
+ const ret = wasm.languageservice_diagnostics(this.__wbg_ptr, ptr0, len0);
220
+ return ret;
221
+ }
222
+ /**
223
+ * The type and description of what is under `offset`, if anything.
224
+ * @param {string} text
225
+ * @param {number} offset
226
+ * @returns {any}
227
+ */
228
+ hover(text, offset) {
229
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
230
+ const len0 = WASM_VECTOR_LEN;
231
+ const ret = wasm.languageservice_hover(this.__wbg_ptr, ptr0, len0, offset);
232
+ return ret;
233
+ }
234
+ /**
235
+ * Creates a service. `schema` describes the input documents (without it, functions and
236
+ * variables are still completed); `variables` declares the bindings the expressions are
237
+ * evaluated with, optionally with a schema for their values.
238
+ * @param {any | null} [schema]
239
+ * @param {any | null} [variables]
240
+ */
241
+ constructor(schema, variables) {
242
+ const ret = wasm.languageservice_new(isLikeNone(schema) ? 0 : addToExternrefTable0(schema), isLikeNone(variables) ? 0 : addToExternrefTable0(variables));
243
+ if (ret[2]) {
244
+ throw takeFromExternrefTable0(ret[1]);
245
+ }
246
+ this.__wbg_ptr = ret[0];
247
+ LanguageServiceFinalization.register(this, this.__wbg_ptr, this);
248
+ return this;
249
+ }
250
+ /**
251
+ * The parameters of the function call around `offset`, if any.
252
+ * @param {string} text
253
+ * @param {number} offset
254
+ * @returns {any}
255
+ */
256
+ signatureHelp(text, offset) {
257
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
258
+ const len0 = WASM_VECTOR_LEN;
259
+ const ret = wasm.languageservice_signatureHelp(this.__wbg_ptr, ptr0, len0, offset);
260
+ return ret;
261
+ }
262
+ }
263
+ if (Symbol.dispose) LanguageService.prototype[Symbol.dispose] = LanguageService.prototype.free;
264
+
265
+ /**
266
+ * The built-in functions: name, signature, parameters, category and summary.
267
+ * @returns {FunctionInfo[]}
268
+ */
269
+ export function functions() {
270
+ const ret = wasm.functions();
271
+ return ret;
272
+ }
273
+
274
+ /**
275
+ * Infers a JSON Schema (2020-12, with `x-jlens-*` annotations) from sample documents.
276
+ * `overrides` adds descriptions, labels, allowed values and hidden fields by path, such as
277
+ * `"items[].type"`.
278
+ * Paths missing from the samples are declared; a malformed path or override throws a `TypeError`.
279
+ * @param {any} samples
280
+ * @param {any | null} [overrides]
281
+ * @returns {any}
282
+ */
283
+ export function inferSchema(samples, overrides) {
284
+ const ret = wasm.inferSchema(samples, isLikeNone(overrides) ? 0 : addToExternrefTable0(overrides));
285
+ if (ret[2]) {
286
+ throw takeFromExternrefTable0(ret[1]);
287
+ }
288
+ return takeFromExternrefTable0(ret[0]);
289
+ }
290
+
291
+ /**
292
+ * Parses an expression, recovering from syntax errors: returns the (partial) syntax tree and
293
+ * every problem found. This never throws.
294
+ * @param {string} source
295
+ * @returns {ParseResult}
296
+ */
297
+ export function parseRecover(source) {
298
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
299
+ const len0 = WASM_VECTOR_LEN;
300
+ const ret = wasm.parseRecover(ptr0, len0);
301
+ return ret;
302
+ }
303
+
304
+ /**
305
+ * The jlens version.
306
+ * @returns {string}
307
+ */
308
+ export function version() {
309
+ let deferred1_0;
310
+ let deferred1_1;
311
+ try {
312
+ const ret = wasm.version();
313
+ deferred1_0 = ret[0];
314
+ deferred1_1 = ret[1];
315
+ return getStringFromWasm0(ret[0], ret[1]);
316
+ } finally {
317
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
318
+ }
319
+ }
320
+ function __wbg_get_imports() {
321
+ const import0 = {
322
+ __proto__: null,
323
+ __wbg___wbindgen_debug_string_4687d8d8c2017d52: function(arg0, arg1) {
324
+ const ret = debugString(arg1);
325
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
326
+ const len1 = WASM_VECTOR_LEN;
327
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
328
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
329
+ },
330
+ __wbg___wbindgen_is_null_e343b7d08827ba72: function(arg0) {
331
+ const ret = arg0 === null;
332
+ return ret;
333
+ },
334
+ __wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
335
+ const ret = arg0 === undefined;
336
+ return ret;
337
+ },
338
+ __wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
339
+ const obj = arg1;
340
+ const ret = typeof(obj) === 'string' ? obj : undefined;
341
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
342
+ var len1 = WASM_VECTOR_LEN;
343
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
344
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
345
+ },
346
+ __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
347
+ throw new Error(getStringFromWasm0(arg0, arg1));
348
+ },
349
+ __wbg_new_2bdcdfcebdfc34d2: function(arg0, arg1) {
350
+ const ret = new TypeError(getStringFromWasm0(arg0, arg1));
351
+ return ret;
352
+ },
353
+ __wbg_new_343a093a3c2ffb4e: function(arg0, arg1) {
354
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
355
+ return ret;
356
+ },
357
+ __wbg_now_aa4ccb83129e9e55: function() {
358
+ const ret = Date.now();
359
+ return ret;
360
+ },
361
+ __wbg_now_e7c6795a7f81e10f: function(arg0) {
362
+ const ret = arg0.now();
363
+ return ret;
364
+ },
365
+ __wbg_parse_0fc53dead14b3b42: function() { return handleError(function (arg0, arg1) {
366
+ const ret = JSON.parse(getStringFromWasm0(arg0, arg1));
367
+ return ret;
368
+ }, arguments); },
369
+ __wbg_performance_3fcf6e32a7e1ed0a: function(arg0) {
370
+ const ret = arg0.performance;
371
+ return ret;
372
+ },
373
+ __wbg_set_145a351398b48c65: function() { return handleError(function (arg0, arg1, arg2) {
374
+ const ret = Reflect.set(arg0, arg1, arg2);
375
+ return ret;
376
+ }, arguments); },
377
+ __wbg_set_name_2c630595dc90a7aa: function(arg0, arg1, arg2) {
378
+ arg0.name = getStringFromWasm0(arg1, arg2);
379
+ },
380
+ __wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
381
+ const ret = typeof global === 'undefined' ? null : global;
382
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
383
+ },
384
+ __wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
385
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
386
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
387
+ },
388
+ __wbg_static_accessor_SELF_0b583911f537483a: function() {
389
+ const ret = typeof self === 'undefined' ? null : self;
390
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
391
+ },
392
+ __wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
393
+ const ret = typeof window === 'undefined' ? null : window;
394
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
395
+ },
396
+ __wbg_stringify_52ff602c1cc4fbb6: function() { return handleError(function (arg0) {
397
+ const ret = JSON.stringify(arg0);
398
+ return ret;
399
+ }, arguments); },
400
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
401
+ // Cast intrinsic for `Ref(String) -> Externref`.
402
+ const ret = getStringFromWasm0(arg0, arg1);
403
+ return ret;
404
+ },
405
+ __wbindgen_init_externref_table: function() {
406
+ const table = wasm.__wbindgen_externrefs;
407
+ const offset = table.grow(4);
408
+ table.set(0, undefined);
409
+ table.set(offset + 0, undefined);
410
+ table.set(offset + 1, null);
411
+ table.set(offset + 2, true);
412
+ table.set(offset + 3, false);
413
+ },
414
+ };
415
+ return {
416
+ __proto__: null,
417
+ "./jlens_bg.js": import0,
418
+ };
419
+ }
420
+
421
+ const DocumentFinalization = (typeof FinalizationRegistry === 'undefined')
422
+ ? { register: () => {}, unregister: () => {} }
423
+ : new FinalizationRegistry(ptr => wasm.__wbg_document_free(ptr, 1));
424
+ const ExpressionFinalization = (typeof FinalizationRegistry === 'undefined')
425
+ ? { register: () => {}, unregister: () => {} }
426
+ : new FinalizationRegistry(ptr => wasm.__wbg_expression_free(ptr, 1));
427
+ const LanguageServiceFinalization = (typeof FinalizationRegistry === 'undefined')
428
+ ? { register: () => {}, unregister: () => {} }
429
+ : new FinalizationRegistry(ptr => wasm.__wbg_languageservice_free(ptr, 1));
430
+
431
+ function addToExternrefTable0(obj) {
432
+ const idx = wasm.__externref_table_alloc();
433
+ wasm.__wbindgen_externrefs.set(idx, obj);
434
+ return idx;
435
+ }
436
+
437
+ function _assertClass(instance, klass) {
438
+ if (!(instance instanceof klass)) {
439
+ throw new Error(`expected instance of ${klass.name}`);
440
+ }
441
+ }
442
+
443
+ function debugString(val) {
444
+ // primitive types
445
+ const type = typeof val;
446
+ if (type == 'number' || type == 'boolean' || val == null) {
447
+ return `${val}`;
448
+ }
449
+ if (type == 'string') {
450
+ return `"${val}"`;
451
+ }
452
+ if (type == 'symbol') {
453
+ const description = val.description;
454
+ if (description == null) {
455
+ return 'Symbol';
456
+ } else {
457
+ return `Symbol(${description})`;
458
+ }
459
+ }
460
+ if (type == 'function') {
461
+ const name = val.name;
462
+ if (typeof name == 'string' && name.length > 0) {
463
+ return `Function(${name})`;
464
+ } else {
465
+ return 'Function';
466
+ }
467
+ }
468
+ // objects
469
+ if (Array.isArray(val)) {
470
+ const length = val.length;
471
+ let debug = '[';
472
+ if (length > 0) {
473
+ debug += debugString(val[0]);
474
+ }
475
+ for(let i = 1; i < length; i++) {
476
+ debug += ', ' + debugString(val[i]);
477
+ }
478
+ debug += ']';
479
+ return debug;
480
+ }
481
+ // Test for built-in
482
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
483
+ let className;
484
+ if (builtInMatches && builtInMatches.length > 1) {
485
+ className = builtInMatches[1];
486
+ } else {
487
+ // Failed to match the standard '[object ClassName]'
488
+ return toString.call(val);
489
+ }
490
+ if (className == 'Object') {
491
+ // we're a user defined class or Object
492
+ // JSON.stringify avoids problems with cycles, and is generally much
493
+ // easier than looping through ownProperties of `val`.
494
+ try {
495
+ return 'Object(' + JSON.stringify(val) + ')';
496
+ } catch (_) {
497
+ return 'Object';
498
+ }
499
+ }
500
+ // errors
501
+ if (val instanceof Error) {
502
+ return `${val.name}: ${val.message}\n${val.stack}`;
503
+ }
504
+ // TODO we could test for more things here, like `Set`s and `Map`s.
505
+ return className;
506
+ }
507
+
508
+ let cachedDataViewMemory0 = null;
509
+ function getDataViewMemory0() {
510
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
511
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
512
+ }
513
+ return cachedDataViewMemory0;
514
+ }
515
+
516
+ function getStringFromWasm0(ptr, len) {
517
+ return decodeText(ptr >>> 0, len);
518
+ }
519
+
520
+ let cachedUint8ArrayMemory0 = null;
521
+ function getUint8ArrayMemory0() {
522
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
523
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
524
+ }
525
+ return cachedUint8ArrayMemory0;
526
+ }
527
+
528
+ function handleError(f, args) {
529
+ try {
530
+ return f.apply(this, args);
531
+ } catch (e) {
532
+ const idx = addToExternrefTable0(e);
533
+ wasm.__wbindgen_exn_store(idx);
534
+ }
535
+ }
536
+
537
+ function isLikeNone(x) {
538
+ return x === undefined || x === null;
539
+ }
540
+
541
+ function passStringToWasm0(arg, malloc, realloc) {
542
+ if (realloc === undefined) {
543
+ const buf = cachedTextEncoder.encode(arg);
544
+ const ptr = malloc(buf.length, 1) >>> 0;
545
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
546
+ WASM_VECTOR_LEN = buf.length;
547
+ return ptr;
548
+ }
549
+
550
+ let len = arg.length;
551
+ let ptr = malloc(len, 1) >>> 0;
552
+
553
+ const mem = getUint8ArrayMemory0();
554
+
555
+ let offset = 0;
556
+
557
+ for (; offset < len; offset++) {
558
+ const code = arg.charCodeAt(offset);
559
+ if (code > 0x7F) break;
560
+ mem[ptr + offset] = code;
561
+ }
562
+ if (offset !== len) {
563
+ if (offset !== 0) {
564
+ arg = arg.slice(offset);
565
+ }
566
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
567
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
568
+ const ret = cachedTextEncoder.encodeInto(arg, view);
569
+
570
+ offset += ret.written;
571
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
572
+ }
573
+
574
+ WASM_VECTOR_LEN = offset;
575
+ return ptr;
576
+ }
577
+
578
+ function takeFromExternrefTable0(idx) {
579
+ const value = wasm.__wbindgen_externrefs.get(idx);
580
+ wasm.__externref_table_dealloc(idx);
581
+ return value;
582
+ }
583
+
584
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
585
+ cachedTextDecoder.decode();
586
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
587
+ let numBytesDecoded = 0;
588
+ function decodeText(ptr, len) {
589
+ numBytesDecoded += len;
590
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
591
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
592
+ cachedTextDecoder.decode();
593
+ numBytesDecoded = len;
594
+ }
595
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
596
+ }
597
+
598
+ const cachedTextEncoder = new TextEncoder();
599
+
600
+ if (!('encodeInto' in cachedTextEncoder)) {
601
+ cachedTextEncoder.encodeInto = function (arg, view) {
602
+ const buf = cachedTextEncoder.encode(arg);
603
+ view.set(buf);
604
+ return {
605
+ read: arg.length,
606
+ written: buf.length
607
+ };
608
+ };
609
+ }
610
+
611
+ let WASM_VECTOR_LEN = 0;
612
+
613
+ let wasmModule, wasmInstance, wasm;
614
+ function __wbg_finalize_init(instance, module) {
615
+ wasmInstance = instance;
616
+ wasm = instance.exports;
617
+ wasmModule = module;
618
+ cachedDataViewMemory0 = null;
619
+ cachedUint8ArrayMemory0 = null;
620
+ wasm.__wbindgen_start();
621
+ return wasm;
622
+ }
623
+
624
+ async function __wbg_load(module, imports) {
625
+ if (typeof Response === 'function' && module instanceof Response) {
626
+ if (!module.ok) {
627
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
628
+ }
629
+
630
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
631
+ try {
632
+ return await WebAssembly.instantiateStreaming(module, imports);
633
+ } catch (e) {
634
+ const validResponse = expectedResponseType(module.type);
635
+
636
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
637
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
638
+
639
+ } else { throw e; }
640
+ }
641
+ }
642
+
643
+ const bytes = await module.arrayBuffer();
644
+ return await WebAssembly.instantiate(bytes, imports);
645
+ } else {
646
+ const instance = await WebAssembly.instantiate(module, imports);
647
+
648
+ if (instance instanceof WebAssembly.Instance) {
649
+ return { instance, module };
650
+ } else {
651
+ return instance;
652
+ }
653
+ }
654
+
655
+ function expectedResponseType(type) {
656
+ switch (type) {
657
+ case 'basic': case 'cors': case 'default': return true;
658
+ }
659
+ return false;
660
+ }
661
+ }
662
+
663
+ function initSync(module) {
664
+ if (wasm !== undefined) return wasm;
665
+
666
+
667
+ if (module !== undefined) {
668
+ if (Object.getPrototypeOf(module) === Object.prototype) {
669
+ ({module} = module)
670
+ } else {
671
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
672
+ }
673
+ }
674
+
675
+ const imports = __wbg_get_imports();
676
+ if (!(module instanceof WebAssembly.Module)) {
677
+ module = new WebAssembly.Module(module);
678
+ }
679
+ const instance = new WebAssembly.Instance(module, imports);
680
+ return __wbg_finalize_init(instance, module);
681
+ }
682
+
683
+ async function __wbg_init(module_or_path) {
684
+ if (wasm !== undefined) return wasm;
685
+
686
+
687
+ if (module_or_path !== undefined) {
688
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
689
+ ({module_or_path} = module_or_path)
690
+ } else {
691
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
692
+ }
693
+ }
694
+
695
+ if (module_or_path === undefined) {
696
+ module_or_path = new URL('jlens_bg.wasm', import.meta.url);
697
+ }
698
+ const imports = __wbg_get_imports();
699
+
700
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
701
+ module_or_path = fetch(module_or_path);
702
+ }
703
+
704
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
705
+
706
+ return __wbg_finalize_init(instance, module);
707
+ }
708
+
709
+ export { initSync, __wbg_init as default };
package/jlens_bg.wasm ADDED
Binary file
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_document_free: (a: number, b: number) => void;
5
+ export const __wbg_expression_free: (a: number, b: number) => void;
6
+ export const __wbg_languageservice_free: (a: number, b: number) => void;
7
+ export const document_fromJson: (a: number, b: number) => [number, number, number];
8
+ export const document_new: (a: any) => [number, number, number];
9
+ export const expression_ast: (a: number) => any;
10
+ export const expression_evaluate: (a: number, b: number, c: number, d: number) => [number, number, number];
11
+ export const expression_evaluateDocument: (a: number, b: number, c: number, d: number) => [number, number, number];
12
+ export const expression_evaluateJson: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
13
+ export const expression_evaluateWithAudit: (a: number, b: number, c: number, d: number) => [number, number, number];
14
+ export const expression_new: (a: number, b: number) => [number, number, number];
15
+ export const expression_source: (a: number) => [number, number];
16
+ export const functions: () => any;
17
+ export const inferSchema: (a: any, b: number) => [number, number, number];
18
+ export const languageservice_complete: (a: number, b: number, c: number, d: number) => any;
19
+ export const languageservice_diagnostics: (a: number, b: number, c: number) => any;
20
+ export const languageservice_hover: (a: number, b: number, c: number, d: number) => any;
21
+ export const languageservice_new: (a: number, b: number) => [number, number, number];
22
+ export const languageservice_signatureHelp: (a: number, b: number, c: number, d: number) => any;
23
+ export const parseRecover: (a: number, b: number) => any;
24
+ export const version: () => [number, number];
25
+ export const __wbindgen_malloc: (a: number, b: number) => number;
26
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
27
+ export const __wbindgen_exn_store: (a: number) => void;
28
+ export const __externref_table_alloc: () => number;
29
+ export const __wbindgen_externrefs: WebAssembly.Table;
30
+ export const __externref_table_dealloc: (a: number) => void;
31
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
32
+ export const __wbindgen_start: () => void;
package/package.json CHANGED
@@ -1,6 +1,33 @@
1
1
  {
2
2
  "name": "jlens-wasm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "JSONata in WebAssembly, with evaluation audits and schema-driven autocomplete",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/thkprado/jlens.git",
9
+ "directory": "crates/jlens-wasm"
10
+ },
11
+ "homepage": "https://github.com/thkprado/jlens",
12
+ "bugs": "https://github.com/thkprado/jlens/issues",
13
+ "type": "module",
14
+ "main": "./jlens.js",
15
+ "types": "./jlens.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./jlens.d.ts",
19
+ "default": "./jlens.js"
20
+ },
21
+ "./jlens_bg.wasm": "./jlens_bg.wasm"
22
+ },
23
+ "files": [
24
+ "jlens.js",
25
+ "jlens.d.ts",
26
+ "jlens_bg.wasm",
27
+ "jlens_bg.wasm.d.ts",
28
+ "README.md",
29
+ "LICENSE"
30
+ ],
31
+ "sideEffects": false,
32
+ "keywords": ["jsonata", "json", "query", "transform", "wasm"]
33
+ }