jlens-wasm 0.1.1 → 0.2.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 +47 -8
- package/jlens.js +84 -5
- package/jlens_bg.wasm +0 -0
- package/jlens_bg.wasm.d.ts +2 -1
- package/package.json +1 -1
package/jlens.d.ts
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Variables and functions an expression is evaluated with: `{limit: 10}` defines `$limit`, and
|
|
5
|
+
* `{rate: (region) => 0.2}` defines `$rate(region)`. Values are converted to JSON; functions are
|
|
6
|
+
* called as host functions (see `HostFunction`).
|
|
7
|
+
*/
|
|
4
8
|
export type Bindings = Record<string, unknown>;
|
|
5
9
|
|
|
10
|
+
/**
|
|
11
|
+
* A JavaScript function called from an expression. Arguments and the result are converted
|
|
12
|
+
* through JSON: `undefined` stands for undefined, and a function argument arrives as
|
|
13
|
+
* `undefined`. `this` is `undefined`; use a signature with `-` to receive the context value.
|
|
14
|
+
* Without a signature, `length` tells higher-order functions how many arguments to pass. An
|
|
15
|
+
* exception it throws is rethrown by the evaluation, with the `position` and `token` of the call
|
|
16
|
+
* when it has none. Returning a promise fails with `U1002`.
|
|
17
|
+
*/
|
|
18
|
+
export type HostFunction = (...args: any[]) => unknown;
|
|
19
|
+
|
|
6
20
|
/** Evaluation guardrails. */
|
|
7
21
|
export interface EvaluateOptions {
|
|
8
22
|
/** Maximum duration of one evaluation, in milliseconds (error `D1012`). */
|
|
@@ -279,6 +293,17 @@ export type FunctionCategory =
|
|
|
279
293
|
| "encoding"
|
|
280
294
|
| "misc";
|
|
281
295
|
|
|
296
|
+
/** A host function declared to the language service, completed like a built-in function. */
|
|
297
|
+
export interface FunctionDeclaration {
|
|
298
|
+
/** The name, with or without `$`. */
|
|
299
|
+
name: string;
|
|
300
|
+
/** The signature, such as `<n-n?:n>`. */
|
|
301
|
+
signature?: string;
|
|
302
|
+
/** Parameter names, without `$`, shown by signature help. */
|
|
303
|
+
params?: string[];
|
|
304
|
+
summary?: string;
|
|
305
|
+
}
|
|
306
|
+
|
|
282
307
|
export interface FunctionInfo {
|
|
283
308
|
/** The name, without `$`. */
|
|
284
309
|
name: string;
|
|
@@ -315,16 +340,24 @@ export class Expression {
|
|
|
315
340
|
bindings?: Bindings | null,
|
|
316
341
|
options?: EvaluateOptions,
|
|
317
342
|
): 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
343
|
/**
|
|
323
344
|
* Evaluates the expression against a `Document` converted beforehand, which avoids converting
|
|
324
345
|
* the input on every call. Use it to evaluate several expressions against one document.
|
|
325
346
|
*/
|
|
326
347
|
evaluateDocument(document: Document, bindings?: Bindings | null, options?: EvaluateOptions): unknown;
|
|
348
|
+
/**
|
|
349
|
+
* Evaluates the expression and records how the result was reached. Evaluation errors are
|
|
350
|
+
* reported in the returned `error`, not thrown; an exception of a host function is reported
|
|
351
|
+
* with its `code` (or its `name`) and its `message`.
|
|
352
|
+
*/
|
|
327
353
|
evaluateWithAudit(input?: unknown, bindings?: Bindings | null, options?: AuditOptions): AuditResult;
|
|
354
|
+
/**
|
|
355
|
+
* Makes `implementation` available as `$name` in every evaluation, as jsonata-js does. With a
|
|
356
|
+
* `signature` (such as `<n-n?:n>`), arguments are checked before each call, as for built-in
|
|
357
|
+
* functions. A function of the same name in the bindings takes precedence. Throws a
|
|
358
|
+
* `JlensError` when the signature is invalid.
|
|
359
|
+
*/
|
|
360
|
+
registerFunction(name: string, implementation: HostFunction, signature?: string): void;
|
|
328
361
|
/** The processed syntax tree, as plain objects. */
|
|
329
362
|
ast(): AstNode;
|
|
330
363
|
/** Releases the compiled expression. */
|
|
@@ -353,9 +386,14 @@ export class LanguageService {
|
|
|
353
386
|
/**
|
|
354
387
|
* `schema` describes the input documents; without it, functions and variables are still
|
|
355
388
|
* completed. `variables` declares the bindings the expressions are evaluated with (names with
|
|
356
|
-
* or without `$`), optionally with a schema for their values.
|
|
389
|
+
* or without `$`), optionally with a schema for their values. `functions` declares the host
|
|
390
|
+
* functions they are evaluated with.
|
|
357
391
|
*/
|
|
358
|
-
constructor(
|
|
392
|
+
constructor(
|
|
393
|
+
schema?: JsonSchema | null,
|
|
394
|
+
variables?: Record<string, JsonSchema | null> | null,
|
|
395
|
+
functions?: FunctionDeclaration[] | null,
|
|
396
|
+
);
|
|
359
397
|
/** Suggestions for the word at `offset`, and the range they replace. */
|
|
360
398
|
complete(text: string, offset: number): Completions;
|
|
361
399
|
/** Syntax errors, and references to fields the schema does not have. */
|
|
@@ -412,13 +450,14 @@ export interface InitOutput {
|
|
|
412
450
|
readonly expression_evaluateJson: (a: number, b: number, c: number, d: number, e: number) => [number, number, number, number];
|
|
413
451
|
readonly expression_evaluateWithAudit: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
414
452
|
readonly expression_new: (a: number, b: number) => [number, number, number];
|
|
453
|
+
readonly expression_registerFunction: (a: number, b: number, c: number, d: any, e: number, f: number) => [number, number];
|
|
415
454
|
readonly expression_source: (a: number) => [number, number];
|
|
416
455
|
readonly functions: () => any;
|
|
417
456
|
readonly inferSchema: (a: any, b: number) => [number, number, number];
|
|
418
457
|
readonly languageservice_complete: (a: number, b: number, c: number, d: number) => any;
|
|
419
458
|
readonly languageservice_diagnostics: (a: number, b: number, c: number) => any;
|
|
420
459
|
readonly languageservice_hover: (a: number, b: number, c: number, d: number) => any;
|
|
421
|
-
readonly languageservice_new: (a: number, b: number) => [number, number, number];
|
|
460
|
+
readonly languageservice_new: (a: number, b: number, c: number) => [number, number, number];
|
|
422
461
|
readonly languageservice_signatureHelp: (a: number, b: number, c: number, d: number) => any;
|
|
423
462
|
readonly parseRecover: (a: number, b: number) => any;
|
|
424
463
|
readonly version: () => [number, number];
|
package/jlens.js
CHANGED
|
@@ -132,7 +132,8 @@ export class Expression {
|
|
|
132
132
|
}
|
|
133
133
|
/**
|
|
134
134
|
* Evaluates the expression against `input`, a JSON-compatible value (`undefined` means no
|
|
135
|
-
* input document). `bindings` provides variables: `{limit: 10}` defines
|
|
135
|
+
* input document). `bindings` provides variables and functions: `{limit: 10}` defines
|
|
136
|
+
* `$limit`, and `{rate: (region) => ...}` defines `$rate(region)`.
|
|
136
137
|
* Returns `undefined` when the result is undefined; throws a `JlensError` when the
|
|
137
138
|
* evaluation fails.
|
|
138
139
|
* @param {any | null} [input]
|
|
@@ -162,6 +163,24 @@ export class Expression {
|
|
|
162
163
|
ExpressionFinalization.register(this, this.__wbg_ptr, this);
|
|
163
164
|
return this;
|
|
164
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Makes `implementation` available to the expression as `$name`, in every evaluation. With
|
|
168
|
+
* a `signature` (such as `<n-n?:n>`), arguments are checked before each call, as for
|
|
169
|
+
* built-in functions. Throws a `JlensError` when the signature is invalid.
|
|
170
|
+
* @param {string} name
|
|
171
|
+
* @param {Function} implementation
|
|
172
|
+
* @param {string | null} [signature]
|
|
173
|
+
*/
|
|
174
|
+
registerFunction(name, implementation, signature) {
|
|
175
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
176
|
+
const len0 = WASM_VECTOR_LEN;
|
|
177
|
+
var ptr1 = isLikeNone(signature) ? 0 : passStringToWasm0(signature, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
178
|
+
var len1 = WASM_VECTOR_LEN;
|
|
179
|
+
const ret = wasm.expression_registerFunction(this.__wbg_ptr, ptr0, len0, implementation, ptr1, len1);
|
|
180
|
+
if (ret[1]) {
|
|
181
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
165
184
|
/**
|
|
166
185
|
* The source text of the expression.
|
|
167
186
|
* @returns {string}
|
|
@@ -234,12 +253,14 @@ export class LanguageService {
|
|
|
234
253
|
/**
|
|
235
254
|
* Creates a service. `schema` describes the input documents (without it, functions and
|
|
236
255
|
* variables are still completed); `variables` declares the bindings the expressions are
|
|
237
|
-
* evaluated with, optionally with a schema for their values
|
|
256
|
+
* evaluated with, optionally with a schema for their values; `functions` declares the host
|
|
257
|
+
* functions they are evaluated with.
|
|
238
258
|
* @param {any | null} [schema]
|
|
239
259
|
* @param {any | null} [variables]
|
|
260
|
+
* @param {any | null} [functions]
|
|
240
261
|
*/
|
|
241
|
-
constructor(schema, variables) {
|
|
242
|
-
const ret = wasm.languageservice_new(isLikeNone(schema) ? 0 : addToExternrefTable0(schema), isLikeNone(variables) ? 0 : addToExternrefTable0(variables));
|
|
262
|
+
constructor(schema, variables, functions) {
|
|
263
|
+
const ret = wasm.languageservice_new(isLikeNone(schema) ? 0 : addToExternrefTable0(schema), isLikeNone(variables) ? 0 : addToExternrefTable0(variables), isLikeNone(functions) ? 0 : addToExternrefTable0(functions));
|
|
243
264
|
if (ret[2]) {
|
|
244
265
|
throw takeFromExternrefTable0(ret[1]);
|
|
245
266
|
}
|
|
@@ -327,10 +348,19 @@ function __wbg_get_imports() {
|
|
|
327
348
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
328
349
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
329
350
|
},
|
|
351
|
+
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
|
|
352
|
+
const ret = typeof(arg0) === 'function';
|
|
353
|
+
return ret;
|
|
354
|
+
},
|
|
330
355
|
__wbg___wbindgen_is_null_e343b7d08827ba72: function(arg0) {
|
|
331
356
|
const ret = arg0 === null;
|
|
332
357
|
return ret;
|
|
333
358
|
},
|
|
359
|
+
__wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
|
|
360
|
+
const val = arg0;
|
|
361
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
362
|
+
return ret;
|
|
363
|
+
},
|
|
334
364
|
__wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
|
|
335
365
|
const ret = arg0 === undefined;
|
|
336
366
|
return ret;
|
|
@@ -346,6 +376,42 @@ function __wbg_get_imports() {
|
|
|
346
376
|
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
347
377
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
348
378
|
},
|
|
379
|
+
__wbg_apply_a910804df6e1e433: function() { return handleError(function (arg0, arg1, arg2) {
|
|
380
|
+
const ret = arg0.apply(arg1, arg2);
|
|
381
|
+
return ret;
|
|
382
|
+
}, arguments); },
|
|
383
|
+
__wbg_entries_fb6397112b1de25f: function(arg0) {
|
|
384
|
+
const ret = Object.entries(arg0);
|
|
385
|
+
return ret;
|
|
386
|
+
},
|
|
387
|
+
__wbg_get_31af05bd4842a84f: function() { return handleError(function (arg0, arg1) {
|
|
388
|
+
const ret = Reflect.get(arg0, arg1);
|
|
389
|
+
return ret;
|
|
390
|
+
}, arguments); },
|
|
391
|
+
__wbg_get_6c896e0571ddae51: function(arg0, arg1) {
|
|
392
|
+
const ret = arg0[arg1 >>> 0];
|
|
393
|
+
return ret;
|
|
394
|
+
},
|
|
395
|
+
__wbg_get_unchecked_288889d017702237: function(arg0, arg1) {
|
|
396
|
+
const ret = arg0[arg1 >>> 0];
|
|
397
|
+
return ret;
|
|
398
|
+
},
|
|
399
|
+
__wbg_has_5d6706e5209576c1: function() { return handleError(function (arg0, arg1) {
|
|
400
|
+
const ret = Reflect.has(arg0, arg1);
|
|
401
|
+
return ret;
|
|
402
|
+
}, arguments); },
|
|
403
|
+
__wbg_isArray_e15a2ff68ffdbef2: function(arg0) {
|
|
404
|
+
const ret = Array.isArray(arg0);
|
|
405
|
+
return ret;
|
|
406
|
+
},
|
|
407
|
+
__wbg_length_3121141f8e1c8c58: function(arg0) {
|
|
408
|
+
const ret = arg0.length;
|
|
409
|
+
return ret;
|
|
410
|
+
},
|
|
411
|
+
__wbg_length_d4bdea10311bd9cf: function(arg0) {
|
|
412
|
+
const ret = arg0.length;
|
|
413
|
+
return ret;
|
|
414
|
+
},
|
|
349
415
|
__wbg_new_2bdcdfcebdfc34d2: function(arg0, arg1) {
|
|
350
416
|
const ret = new TypeError(getStringFromWasm0(arg0, arg1));
|
|
351
417
|
return ret;
|
|
@@ -354,6 +420,10 @@ function __wbg_get_imports() {
|
|
|
354
420
|
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
355
421
|
return ret;
|
|
356
422
|
},
|
|
423
|
+
__wbg_new_ee2291f50781bf1d: function() {
|
|
424
|
+
const ret = new Array();
|
|
425
|
+
return ret;
|
|
426
|
+
},
|
|
357
427
|
__wbg_now_aa4ccb83129e9e55: function() {
|
|
358
428
|
const ret = Date.now();
|
|
359
429
|
return ret;
|
|
@@ -370,6 +440,10 @@ function __wbg_get_imports() {
|
|
|
370
440
|
const ret = arg0.performance;
|
|
371
441
|
return ret;
|
|
372
442
|
},
|
|
443
|
+
__wbg_push_2baf45db356cf468: function(arg0, arg1) {
|
|
444
|
+
const ret = arg0.push(arg1);
|
|
445
|
+
return ret;
|
|
446
|
+
},
|
|
373
447
|
__wbg_set_145a351398b48c65: function() { return handleError(function (arg0, arg1, arg2) {
|
|
374
448
|
const ret = Reflect.set(arg0, arg1, arg2);
|
|
375
449
|
return ret;
|
|
@@ -397,7 +471,12 @@ function __wbg_get_imports() {
|
|
|
397
471
|
const ret = JSON.stringify(arg0);
|
|
398
472
|
return ret;
|
|
399
473
|
}, arguments); },
|
|
400
|
-
__wbindgen_generic_0000000000000001: function(arg0
|
|
474
|
+
__wbindgen_generic_0000000000000001: function(arg0) {
|
|
475
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
476
|
+
const ret = arg0;
|
|
477
|
+
return ret;
|
|
478
|
+
},
|
|
479
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
401
480
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
402
481
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
403
482
|
return ret;
|
package/jlens_bg.wasm
CHANGED
|
Binary file
|
package/jlens_bg.wasm.d.ts
CHANGED
|
@@ -12,13 +12,14 @@ 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_registerFunction: (a: number, b: number, c: number, d: any, e: number, f: number) => [number, number];
|
|
15
16
|
export const expression_source: (a: number) => [number, number];
|
|
16
17
|
export const functions: () => any;
|
|
17
18
|
export const inferSchema: (a: any, b: number) => [number, number, number];
|
|
18
19
|
export const languageservice_complete: (a: number, b: number, c: number, d: number) => any;
|
|
19
20
|
export const languageservice_diagnostics: (a: number, b: number, c: number) => any;
|
|
20
21
|
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_new: (a: number, b: number, c: number) => [number, number, number];
|
|
22
23
|
export const languageservice_signatureHelp: (a: number, b: number, c: number, d: number) => any;
|
|
23
24
|
export const parseRecover: (a: number, b: number) => any;
|
|
24
25
|
export const version: () => [number, number];
|