@edgerules/web 0.0.0-alpha.202607061957 → 0.0.0-alpha.202607071338
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/dist/_core/completions.d.ts +32 -0
- package/dist/_core/completions.js +13 -0
- package/dist/_core/diagnostics.d.ts +25 -0
- package/dist/_core/diagnostics.js +15 -0
- package/dist/_core/mutable-service.d.ts +17 -2
- package/dist/_core/mutable-service.js +20 -0
- package/dist/_core/offsets.d.ts +21 -0
- package/dist/_core/offsets.js +73 -0
- package/dist/_core/wasm-types.d.ts +9 -0
- package/dist/mutable.d.ts +4 -0
- package/dist/wasm/dev/edgerules_wasm.d.ts +34 -0
- package/dist/wasm/dev/edgerules_wasm.js +87 -0
- package/dist/wasm/dev/edgerules_wasm_bg.wasm +0 -0
- package/dist/wasm/dev/edgerules_wasm_bg.wasm.d.ts +2 -0
- package/dist/wasm/prod/edgerules_wasm_bg.wasm +0 -0
- package/package.json +2 -2
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One completion option from the dev WASM build's `completions()` export.
|
|
3
|
+
*
|
|
4
|
+
* A structural superset of `@codemirror/autocomplete`'s `Completion`: `label` is the text to
|
|
5
|
+
* insert, `type` the icon category CodeMirror renders, and `detail` an optional short hint shown
|
|
6
|
+
* after the label (a built-in's signature, a member's declared type).
|
|
7
|
+
*/
|
|
8
|
+
export interface EditorCompletion {
|
|
9
|
+
label: string;
|
|
10
|
+
type: 'variable' | 'function' | 'type' | 'keyword' | 'property' | 'constant';
|
|
11
|
+
detail?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A completion query result, directly usable as a CodeMirror `CompletionResult`.
|
|
15
|
+
*
|
|
16
|
+
* `from`/`to` delimit the identifier prefix being typed (UTF-16 code units into the document,
|
|
17
|
+
* already converted from the engine's UTF-8 byte offsets), so CodeMirror replaces the right range;
|
|
18
|
+
* an empty range at the cursor means no prefix. `options` are rank-ordered — user-scope names,
|
|
19
|
+
* then built-ins, then keywords — and unfiltered: CodeMirror's own fuzzy matcher filters by the
|
|
20
|
+
* typed prefix.
|
|
21
|
+
*/
|
|
22
|
+
export interface EditorCompletionResult {
|
|
23
|
+
from: number;
|
|
24
|
+
to: number;
|
|
25
|
+
options: EditorCompletion[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parses the raw JSON emitted by the WASM `completions()` export and converts the replace range
|
|
29
|
+
* from UTF-8 byte offsets to UTF-16 code-unit offsets against the same `code` string, keeping
|
|
30
|
+
* `from <= to` and both within the document.
|
|
31
|
+
*/
|
|
32
|
+
export declare function toEditorCompletions(rawJson: string, code: string): EditorCompletionResult;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { byteToUtf16Mapper } from './offsets.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses the raw JSON emitted by the WASM `completions()` export and converts the replace range
|
|
4
|
+
* from UTF-8 byte offsets to UTF-16 code-unit offsets against the same `code` string, keeping
|
|
5
|
+
* `from <= to` and both within the document.
|
|
6
|
+
*/
|
|
7
|
+
export function toEditorCompletions(rawJson, code) {
|
|
8
|
+
const raw = JSON.parse(rawJson);
|
|
9
|
+
const toUtf16 = byteToUtf16Mapper(code);
|
|
10
|
+
const from = toUtf16(raw.from);
|
|
11
|
+
const to = Math.max(from, toUtf16(raw.to));
|
|
12
|
+
return { from, to, options: raw.options };
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A structured diagnostic from the dev WASM build's `diagnostics()` export.
|
|
3
|
+
*
|
|
4
|
+
* The shape is a structural superset of `@codemirror/lint`'s `Diagnostic`, so an editor can pass
|
|
5
|
+
* these straight to a CodeMirror linter callback: `from`/`to` are document positions in UTF-16
|
|
6
|
+
* code units (already converted from the engine's UTF-8 byte offsets and clamped to the document),
|
|
7
|
+
* `severity` matches CodeMirror's union, and `source`/`code` fill the optional fields of the same
|
|
8
|
+
* names. A diagnostic whose location could not be resolved (a linker error with no span) arrives
|
|
9
|
+
* as `from = to = 0` — render it document-wide or as a gutter marker.
|
|
10
|
+
*/
|
|
11
|
+
export interface EditorDiagnostic {
|
|
12
|
+
from: number;
|
|
13
|
+
to: number;
|
|
14
|
+
severity: 'error';
|
|
15
|
+
source: 'parser' | 'linker';
|
|
16
|
+
/** Stable machine code: a `ParseErrorKind` name (`"UnexpectedToken"`) or a linker `Exxx` code. */
|
|
17
|
+
code?: string;
|
|
18
|
+
message: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Parses the raw JSON emitted by the WASM `diagnostics()` export and converts every span from
|
|
22
|
+
* UTF-8 byte offsets to UTF-16 code-unit offsets against the same `code` string, keeping
|
|
23
|
+
* `from <= to` and both within the document.
|
|
24
|
+
*/
|
|
25
|
+
export declare function toEditorDiagnostics(rawJson: string, code: string): EditorDiagnostic[];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { byteToUtf16Mapper } from './offsets.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses the raw JSON emitted by the WASM `diagnostics()` export and converts every span from
|
|
4
|
+
* UTF-8 byte offsets to UTF-16 code-unit offsets against the same `code` string, keeping
|
|
5
|
+
* `from <= to` and both within the document.
|
|
6
|
+
*/
|
|
7
|
+
export function toEditorDiagnostics(rawJson, code) {
|
|
8
|
+
const raw = JSON.parse(rawJson);
|
|
9
|
+
const toUtf16 = byteToUtf16Mapper(code);
|
|
10
|
+
return raw.map((diagnostic) => {
|
|
11
|
+
const from = toUtf16(diagnostic.from);
|
|
12
|
+
const to = Math.max(from, toUtf16(diagnostic.to));
|
|
13
|
+
return { ...diagnostic, from, to };
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { PortableError, PortableNode, PortableRootContext } from '@edgerules/portable';
|
|
2
|
-
import type {
|
|
2
|
+
import type { MutableDecisionServiceWasmCtor, MutableDecisionServiceWasmInstance } from './wasm-types.js';
|
|
3
|
+
import { type EditorDiagnostic } from './diagnostics.js';
|
|
4
|
+
import { type EditorCompletionResult } from './completions.js';
|
|
3
5
|
/**
|
|
4
6
|
* Binds `MutableDecisionService` to a specific platform's dev wasm-pack class. Mirrors
|
|
5
7
|
* `createDecisionService` (Clarification 8) but for the CRUD-enabled dev WASM build.
|
|
@@ -8,7 +10,7 @@ import type { DecisionServiceWasmCtor, MutableDecisionServiceWasmInstance } from
|
|
|
8
10
|
* deliberately non-generic (see Clarification 14) — inheriting them unmodified would construct a base
|
|
9
11
|
* `DecisionService`, not a `MutableDecisionService`, losing `set`/`remove`/`rename` at runtime.
|
|
10
12
|
*/
|
|
11
|
-
export declare function createMutableDecisionService<TInstance extends MutableDecisionServiceWasmInstance>(WasmClass:
|
|
13
|
+
export declare function createMutableDecisionService<TInstance extends MutableDecisionServiceWasmInstance>(WasmClass: MutableDecisionServiceWasmCtor<TInstance>): {
|
|
12
14
|
new (wasm: TInstance): {
|
|
13
15
|
set(path: string, node: PortableNode): PortableNode | PortableError;
|
|
14
16
|
remove(path: string): void | PortableError;
|
|
@@ -29,6 +31,19 @@ export declare function createMutableDecisionService<TInstance extends MutableDe
|
|
|
29
31
|
toPortable(): PortableRootContext;
|
|
30
32
|
[Symbol.dispose](): void;
|
|
31
33
|
};
|
|
34
|
+
/**
|
|
35
|
+
* Parses and links `code` without constructing a service, returning structured,
|
|
36
|
+
* CodeMirror-compatible diagnostics (empty when the source is valid). Positions are
|
|
37
|
+
* UTF-16 code units into `code`, ready to use as editor document offsets.
|
|
38
|
+
*/
|
|
39
|
+
diagnostics(code: string): EditorDiagnostic[];
|
|
40
|
+
/**
|
|
41
|
+
* Computes completion options for the cursor at UTF-16 document position `pos` in `code`,
|
|
42
|
+
* in the shape of `@codemirror/autocomplete`'s `CompletionResult`. Works on syntactically
|
|
43
|
+
* broken source (the engine parses leniently) and never throws for arbitrary input; the
|
|
44
|
+
* worst case is an empty `options` list.
|
|
45
|
+
*/
|
|
46
|
+
completions(code: string, pos: number): EditorCompletionResult;
|
|
32
47
|
fromPortable(model: PortableRootContext): {
|
|
33
48
|
set(path: string, node: PortableNode): PortableNode | PortableError;
|
|
34
49
|
remove(path: string): void | PortableError;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createDecisionService } from './decision-service.js';
|
|
2
2
|
import { toPortableError } from './errors.js';
|
|
3
|
+
import { toEditorDiagnostics } from './diagnostics.js';
|
|
4
|
+
import { toEditorCompletions } from './completions.js';
|
|
5
|
+
import { utf16ToByteOffset } from './offsets.js';
|
|
3
6
|
/**
|
|
4
7
|
* Binds `MutableDecisionService` to a specific platform's dev wasm-pack class. Mirrors
|
|
5
8
|
* `createDecisionService` (Clarification 8) but for the CRUD-enabled dev WASM build.
|
|
@@ -14,6 +17,23 @@ export function createMutableDecisionService(WasmClass) {
|
|
|
14
17
|
static fromCode(code) {
|
|
15
18
|
return new MutableDecisionService(WasmClass.from_code(code));
|
|
16
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Parses and links `code` without constructing a service, returning structured,
|
|
22
|
+
* CodeMirror-compatible diagnostics (empty when the source is valid). Positions are
|
|
23
|
+
* UTF-16 code units into `code`, ready to use as editor document offsets.
|
|
24
|
+
*/
|
|
25
|
+
static diagnostics(code) {
|
|
26
|
+
return toEditorDiagnostics(WasmClass.diagnostics(code), code);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Computes completion options for the cursor at UTF-16 document position `pos` in `code`,
|
|
30
|
+
* in the shape of `@codemirror/autocomplete`'s `CompletionResult`. Works on syntactically
|
|
31
|
+
* broken source (the engine parses leniently) and never throws for arbitrary input; the
|
|
32
|
+
* worst case is an empty `options` list.
|
|
33
|
+
*/
|
|
34
|
+
static completions(code, pos) {
|
|
35
|
+
return toEditorCompletions(WasmClass.completions(code, utf16ToByteOffset(code, pos)), code);
|
|
36
|
+
}
|
|
17
37
|
static fromPortable(model) {
|
|
18
38
|
return new MutableDecisionService(WasmClass.from_portable(JSON.stringify(model)));
|
|
19
39
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UTF-8 byte offset ↔ UTF-16 code unit conversion for editor positions.
|
|
3
|
+
*
|
|
4
|
+
* The engine reports source ranges as byte offsets into the UTF-8 source; CodeMirror document
|
|
5
|
+
* positions are UTF-16 code units. For ASCII sources the two coincide and conversion is a clamp.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Builds a UTF-8-byte-offset → UTF-16-code-unit-offset mapper for `code`.
|
|
9
|
+
*
|
|
10
|
+
* For non-ASCII sources a per-code-point offset table is built once and each lookup binary-searches
|
|
11
|
+
* it. Offsets that fall inside a multi-byte sequence (impossible for well-formed engine spans) or
|
|
12
|
+
* past the end resolve to the nearest boundary.
|
|
13
|
+
*/
|
|
14
|
+
export declare function byteToUtf16Mapper(code: string): (byteOffset: number) => number;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a single UTF-16 code-unit position in `code` to a UTF-8 byte offset — the reverse
|
|
17
|
+
* direction of {@link byteToUtf16Mapper}, as a one-shot walk (completion sends one position per
|
|
18
|
+
* request, so no table is needed). Positions inside a surrogate pair or past the end resolve to
|
|
19
|
+
* the nearest code-point boundary.
|
|
20
|
+
*/
|
|
21
|
+
export declare function utf16ToByteOffset(code: string, position: number): number;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UTF-8 byte offset ↔ UTF-16 code unit conversion for editor positions.
|
|
3
|
+
*
|
|
4
|
+
* The engine reports source ranges as byte offsets into the UTF-8 source; CodeMirror document
|
|
5
|
+
* positions are UTF-16 code units. For ASCII sources the two coincide and conversion is a clamp.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Builds a UTF-8-byte-offset → UTF-16-code-unit-offset mapper for `code`.
|
|
9
|
+
*
|
|
10
|
+
* For non-ASCII sources a per-code-point offset table is built once and each lookup binary-searches
|
|
11
|
+
* it. Offsets that fall inside a multi-byte sequence (impossible for well-formed engine spans) or
|
|
12
|
+
* past the end resolve to the nearest boundary.
|
|
13
|
+
*/
|
|
14
|
+
export function byteToUtf16Mapper(code) {
|
|
15
|
+
// eslint-disable-next-line no-control-regex
|
|
16
|
+
if (!/[^\x00-\x7f]/.test(code)) {
|
|
17
|
+
return (byteOffset) => Math.max(0, Math.min(byteOffset, code.length));
|
|
18
|
+
}
|
|
19
|
+
const byteStarts = [];
|
|
20
|
+
const utf16Starts = [];
|
|
21
|
+
let byteOffset = 0;
|
|
22
|
+
let utf16Offset = 0;
|
|
23
|
+
for (const char of code) {
|
|
24
|
+
byteStarts.push(byteOffset);
|
|
25
|
+
utf16Starts.push(utf16Offset);
|
|
26
|
+
const codePoint = char.codePointAt(0) ?? 0;
|
|
27
|
+
byteOffset += codePoint < 0x80 ? 1 : codePoint < 0x800 ? 2 : codePoint < 0x10000 ? 3 : 4;
|
|
28
|
+
utf16Offset += char.length;
|
|
29
|
+
}
|
|
30
|
+
byteStarts.push(byteOffset);
|
|
31
|
+
utf16Starts.push(utf16Offset);
|
|
32
|
+
return (target) => {
|
|
33
|
+
let low = 0;
|
|
34
|
+
let high = byteStarts.length - 1;
|
|
35
|
+
while (low < high) {
|
|
36
|
+
const mid = (low + high + 1) >> 1;
|
|
37
|
+
if (byteStarts[mid] <= target) {
|
|
38
|
+
low = mid;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
high = mid - 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return utf16Starts[low];
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Converts a single UTF-16 code-unit position in `code` to a UTF-8 byte offset — the reverse
|
|
49
|
+
* direction of {@link byteToUtf16Mapper}, as a one-shot walk (completion sends one position per
|
|
50
|
+
* request, so no table is needed). Positions inside a surrogate pair or past the end resolve to
|
|
51
|
+
* the nearest code-point boundary.
|
|
52
|
+
*/
|
|
53
|
+
export function utf16ToByteOffset(code, position) {
|
|
54
|
+
// eslint-disable-next-line no-control-regex
|
|
55
|
+
if (!/[^\x00-\x7f]/.test(code)) {
|
|
56
|
+
return Math.max(0, Math.min(position, code.length));
|
|
57
|
+
}
|
|
58
|
+
const clamped = Math.max(0, Math.min(position, code.length));
|
|
59
|
+
let byteOffset = 0;
|
|
60
|
+
let utf16Offset = 0;
|
|
61
|
+
for (const char of code) {
|
|
62
|
+
if (utf16Offset + char.length > clamped) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
const codePoint = char.codePointAt(0) ?? 0;
|
|
66
|
+
byteOffset += codePoint < 0x80 ? 1 : codePoint < 0x800 ? 2 : codePoint < 0x10000 ? 3 : 4;
|
|
67
|
+
utf16Offset += char.length;
|
|
68
|
+
if (utf16Offset === clamped) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return byteOffset;
|
|
73
|
+
}
|
|
@@ -18,3 +18,12 @@ export interface DecisionServiceWasmCtor<TInstance extends DecisionServiceWasmIn
|
|
|
18
18
|
from_code(code: string): TInstance;
|
|
19
19
|
from_portable(json: string): TInstance;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Ctor surface of the dev (`mutable_ds` + `analyzer`) WASM builds, which additionally export the
|
|
23
|
+
* static `diagnostics` and `completions` language-tooling entry points. Production builds
|
|
24
|
+
* deliberately lack both.
|
|
25
|
+
*/
|
|
26
|
+
export interface MutableDecisionServiceWasmCtor<TInstance extends MutableDecisionServiceWasmInstance> extends DecisionServiceWasmCtor<TInstance> {
|
|
27
|
+
diagnostics(code: string): string;
|
|
28
|
+
completions(code: string, offset: number): string;
|
|
29
|
+
}
|
package/dist/mutable.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ export declare const MutableDecisionService: {
|
|
|
22
22
|
toPortable(): import("@edgerules/portable").PortableRootContext;
|
|
23
23
|
[Symbol.dispose](): void;
|
|
24
24
|
};
|
|
25
|
+
diagnostics(code: string): import("./mutable.js").EditorDiagnostic[];
|
|
26
|
+
completions(code: string, pos: number): import("./mutable.js").EditorCompletionResult;
|
|
25
27
|
fromPortable(model: import("@edgerules/portable").PortableRootContext): {
|
|
26
28
|
set(path: string, node: import("@edgerules/portable").PortableNode): import("@edgerules/portable").PortableNode | import("@edgerules/portable").PortableError;
|
|
27
29
|
remove(path: string): void | import("@edgerules/portable").PortableError;
|
|
@@ -35,4 +37,6 @@ export declare const MutableDecisionService: {
|
|
|
35
37
|
};
|
|
36
38
|
export type MutableDecisionService = InstanceType<typeof MutableDecisionService>;
|
|
37
39
|
export type { GetFilter } from './_core/decision-service.js';
|
|
40
|
+
export type { EditorDiagnostic } from './_core/diagnostics.js';
|
|
41
|
+
export type { EditorCompletion, EditorCompletionResult } from './_core/completions.js';
|
|
38
42
|
export type { PortableError, PortableNode, PortableRootContext } from '@edgerules/portable';
|
|
@@ -8,6 +8,38 @@ export class DecisionServiceWASM {
|
|
|
8
8
|
private constructor();
|
|
9
9
|
free(): void;
|
|
10
10
|
[Symbol.dispose](): void;
|
|
11
|
+
/**
|
|
12
|
+
* Computes code-completion options for the cursor at UTF-8 byte `offset`
|
|
13
|
+
* into `code`, returning JSON `{from, to, options: [{label, type,
|
|
14
|
+
* detail?}]}` — the shape of `@codemirror/autocomplete`'s
|
|
15
|
+
* `CompletionResult`. `from`/`to` delimit the identifier prefix being
|
|
16
|
+
* typed (byte offsets; the JS wrapper converts to UTF-16) and `options`
|
|
17
|
+
* are rank-ordered: user-scope names, then built-ins, then keywords.
|
|
18
|
+
*
|
|
19
|
+
* Works on syntactically broken source (lenient parse) and never throws
|
|
20
|
+
* for arbitrary input; the worst case is an empty options list.
|
|
21
|
+
*
|
|
22
|
+
* Dev/IDE builds only (`analyzer`): production packages stay
|
|
23
|
+
* execution-only and never link this code in.
|
|
24
|
+
*/
|
|
25
|
+
static completions(code: string, offset: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Parses and links `code`, returning a JSON array of structured
|
|
28
|
+
* diagnostics — empty when the source is valid.
|
|
29
|
+
*
|
|
30
|
+
* Each diagnostic is `{severity, source, code?, message, from, to}` with
|
|
31
|
+
* `from`/`to` as UTF-8 byte offsets into `code` (start/end exclusive).
|
|
32
|
+
* Parse failures report every collected `ParseError` with its own span;
|
|
33
|
+
* a link failure reports the single `LinkerError`, resolved to the
|
|
34
|
+
* offending definition's span via `EdgeRulesModel::span_of(node_id)`.
|
|
35
|
+
* Errors that carry no `node_id` (or an id allocated outside the parser)
|
|
36
|
+
* degrade to `from = to = 0` — the editor maps that to a whole-document
|
|
37
|
+
* diagnostic.
|
|
38
|
+
*
|
|
39
|
+
* Dev/IDE builds only (`analyzer`): production packages stay
|
|
40
|
+
* execution-only and never link this code in.
|
|
41
|
+
*/
|
|
42
|
+
static diagnostics(code: string): string;
|
|
11
43
|
/**
|
|
12
44
|
* Executes a function defined in the model, or evaluates a field by path.
|
|
13
45
|
*
|
|
@@ -79,6 +111,8 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
79
111
|
export interface InitOutput {
|
|
80
112
|
readonly memory: WebAssembly.Memory;
|
|
81
113
|
readonly __wbg_decisionservicewasm_free: (a: number, b: number) => void;
|
|
114
|
+
readonly decisionservicewasm_completions: (a: number, b: number, c: number, d: number) => void;
|
|
115
|
+
readonly decisionservicewasm_diagnostics: (a: number, b: number, c: number) => void;
|
|
82
116
|
readonly decisionservicewasm_execute: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
83
117
|
readonly decisionservicewasm_from_code: (a: number, b: number, c: number) => void;
|
|
84
118
|
readonly decisionservicewasm_from_portable: (a: number, b: number, c: number) => void;
|
|
@@ -22,6 +22,93 @@ export class DecisionServiceWASM {
|
|
|
22
22
|
const ptr = this.__destroy_into_raw();
|
|
23
23
|
wasm.__wbg_decisionservicewasm_free(ptr, 0);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Computes code-completion options for the cursor at UTF-8 byte `offset`
|
|
27
|
+
* into `code`, returning JSON `{from, to, options: [{label, type,
|
|
28
|
+
* detail?}]}` — the shape of `@codemirror/autocomplete`'s
|
|
29
|
+
* `CompletionResult`. `from`/`to` delimit the identifier prefix being
|
|
30
|
+
* typed (byte offsets; the JS wrapper converts to UTF-16) and `options`
|
|
31
|
+
* are rank-ordered: user-scope names, then built-ins, then keywords.
|
|
32
|
+
*
|
|
33
|
+
* Works on syntactically broken source (lenient parse) and never throws
|
|
34
|
+
* for arbitrary input; the worst case is an empty options list.
|
|
35
|
+
*
|
|
36
|
+
* Dev/IDE builds only (`analyzer`): production packages stay
|
|
37
|
+
* execution-only and never link this code in.
|
|
38
|
+
* @param {string} code
|
|
39
|
+
* @param {number} offset
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
static completions(code, offset) {
|
|
43
|
+
let deferred3_0;
|
|
44
|
+
let deferred3_1;
|
|
45
|
+
try {
|
|
46
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
47
|
+
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
48
|
+
const len0 = WASM_VECTOR_LEN;
|
|
49
|
+
wasm.decisionservicewasm_completions(retptr, ptr0, len0, offset);
|
|
50
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
51
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
52
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
53
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
54
|
+
var ptr2 = r0;
|
|
55
|
+
var len2 = r1;
|
|
56
|
+
if (r3) {
|
|
57
|
+
ptr2 = 0; len2 = 0;
|
|
58
|
+
throw takeObject(r2);
|
|
59
|
+
}
|
|
60
|
+
deferred3_0 = ptr2;
|
|
61
|
+
deferred3_1 = len2;
|
|
62
|
+
return getStringFromWasm0(ptr2, len2);
|
|
63
|
+
} finally {
|
|
64
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
65
|
+
wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parses and links `code`, returning a JSON array of structured
|
|
70
|
+
* diagnostics — empty when the source is valid.
|
|
71
|
+
*
|
|
72
|
+
* Each diagnostic is `{severity, source, code?, message, from, to}` with
|
|
73
|
+
* `from`/`to` as UTF-8 byte offsets into `code` (start/end exclusive).
|
|
74
|
+
* Parse failures report every collected `ParseError` with its own span;
|
|
75
|
+
* a link failure reports the single `LinkerError`, resolved to the
|
|
76
|
+
* offending definition's span via `EdgeRulesModel::span_of(node_id)`.
|
|
77
|
+
* Errors that carry no `node_id` (or an id allocated outside the parser)
|
|
78
|
+
* degrade to `from = to = 0` — the editor maps that to a whole-document
|
|
79
|
+
* diagnostic.
|
|
80
|
+
*
|
|
81
|
+
* Dev/IDE builds only (`analyzer`): production packages stay
|
|
82
|
+
* execution-only and never link this code in.
|
|
83
|
+
* @param {string} code
|
|
84
|
+
* @returns {string}
|
|
85
|
+
*/
|
|
86
|
+
static diagnostics(code) {
|
|
87
|
+
let deferred3_0;
|
|
88
|
+
let deferred3_1;
|
|
89
|
+
try {
|
|
90
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
91
|
+
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
92
|
+
const len0 = WASM_VECTOR_LEN;
|
|
93
|
+
wasm.decisionservicewasm_diagnostics(retptr, ptr0, len0);
|
|
94
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
95
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
96
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
97
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
98
|
+
var ptr2 = r0;
|
|
99
|
+
var len2 = r1;
|
|
100
|
+
if (r3) {
|
|
101
|
+
ptr2 = 0; len2 = 0;
|
|
102
|
+
throw takeObject(r2);
|
|
103
|
+
}
|
|
104
|
+
deferred3_0 = ptr2;
|
|
105
|
+
deferred3_1 = len2;
|
|
106
|
+
return getStringFromWasm0(ptr2, len2);
|
|
107
|
+
} finally {
|
|
108
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
109
|
+
wasm.__wbindgen_export4(deferred3_0, deferred3_1, 1);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
25
112
|
/**
|
|
26
113
|
* Executes a function defined in the model, or evaluates a field by path.
|
|
27
114
|
*
|
|
Binary file
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
export const memory: WebAssembly.Memory;
|
|
4
4
|
export const __wbg_decisionservicewasm_free: (a: number, b: number) => void;
|
|
5
|
+
export const decisionservicewasm_completions: (a: number, b: number, c: number, d: number) => void;
|
|
6
|
+
export const decisionservicewasm_diagnostics: (a: number, b: number, c: number) => void;
|
|
5
7
|
export const decisionservicewasm_execute: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
6
8
|
export const decisionservicewasm_from_code: (a: number, b: number, c: number) => void;
|
|
7
9
|
export const decisionservicewasm_from_portable: (a: number, b: number, c: number) => void;
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edgerules/web",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.202607071338",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "EdgeRules decision service for the browser.",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@edgerules/portable": "0.0.0-alpha.
|
|
7
|
+
"@edgerules/portable": "0.0.0-alpha.202607071338"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
10
|
"@edgerules/core": "*",
|