@lemmabase/lemma-engine 0.8.11 → 0.8.13
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/README.md +98 -28
- package/lemma.bindings.d.ts +39 -23
- package/lemma.bindings.js +234 -169
- package/lemma.d.ts +127 -12
- package/lemma.iife.js +1 -1
- package/lemma_bg.wasm +0 -0
- package/lemma_bg.wasm.d.ts +9 -6
- package/lsp-client.js +9 -0
- package/monaco.js +97 -11
- package/package.json +2 -2
package/lemma.d.ts
CHANGED
|
@@ -3,6 +3,59 @@ export { Engine, initSync } from './lemma.bindings.js';
|
|
|
3
3
|
export declare function init(): Promise<void>;
|
|
4
4
|
export declare function Lemma(): Promise<Engine>;
|
|
5
5
|
|
|
6
|
+
/** Resolved shape of {@link Engine.fetch}. */
|
|
7
|
+
export interface RegistryFetchResult {
|
|
8
|
+
source: string;
|
|
9
|
+
id: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare module './lemma.bindings.js' {
|
|
13
|
+
interface Engine {
|
|
14
|
+
/**
|
|
15
|
+
* Load multiple Lemma sources in one planning pass. Object keys become error-reporting
|
|
16
|
+
* paths (`SourceType::Path`); use `""` for volatile/inline. Non-empty `dependency` tags
|
|
17
|
+
* the batch as that dependency id. Throws `EngineError[]` on failure.
|
|
18
|
+
*/
|
|
19
|
+
load_batch(
|
|
20
|
+
sources: Record<string, string>,
|
|
21
|
+
dependency?: string | null,
|
|
22
|
+
): void;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Download Lemma source from the registry for `name` (e.g. `@org/pkg`). Resolves with
|
|
26
|
+
* `{ source, id }`; does not load the engine. Rejects with `EngineError[]` like `load`.
|
|
27
|
+
*/
|
|
28
|
+
fetch(name: string): Promise<RegistryFetchResult>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* JSON serialization of `Vec<ResolvedRepository>` from [`Engine::list`]:
|
|
32
|
+
* each item has `repository` ([`LemmaRepository`]) and `specs` (`LemmaSpecSet[]`),
|
|
33
|
+
* each set has `repository`, `name`, and `specs` (`LemmaSpec[]`).
|
|
34
|
+
*/
|
|
35
|
+
list(): ResolvedRepositoryJson[];
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `repository`: qualifier or `null`/omit for workspace — same as `Engine::schema` `repo`.
|
|
39
|
+
*/
|
|
40
|
+
schema(
|
|
41
|
+
repository: string | null | undefined,
|
|
42
|
+
spec: string,
|
|
43
|
+
effective?: string | null,
|
|
44
|
+
): SpecSchema;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `repository`: qualifier or `null`/omit for workspace — same as `Engine::run` `repo`.
|
|
48
|
+
*/
|
|
49
|
+
run(
|
|
50
|
+
repository: string | null | undefined,
|
|
51
|
+
spec: string,
|
|
52
|
+
rule_names: string[] | string,
|
|
53
|
+
data_values: Record<string, unknown>,
|
|
54
|
+
effective?: string | null,
|
|
55
|
+
): any;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
6
59
|
/**
|
|
7
60
|
* Source location attached to an {@link EngineError}. Line and column are
|
|
8
61
|
* 1-based; `length` is the UTF-8 byte length of the offending span.
|
|
@@ -16,11 +69,12 @@ export interface EngineErrorSource {
|
|
|
16
69
|
|
|
17
70
|
/**
|
|
18
71
|
* Structured error thrown by {@link Engine.run}, {@link Engine.schema},
|
|
19
|
-
* {@link Engine.format},
|
|
72
|
+
* {@link Engine.format}, {@link Engine.load}, and {@link Engine.load_batch}
|
|
73
|
+
* (as an array), and rejected from {@link Engine.fetch} (as an array).
|
|
20
74
|
*
|
|
21
75
|
* - `kind` classifies the failure ("parsing" for syntax, "validation" for
|
|
22
|
-
* semantic/planning including bad data values, "
|
|
23
|
-
* etc.).
|
|
76
|
+
* semantic/planning including bad data values, "missing_repository" when a
|
|
77
|
+
* referenced repo is not loaded, "request" for bad API input, etc.).
|
|
24
78
|
* - `message` is the inner reason only. Callers that previously parsed
|
|
25
79
|
* `"Failed to parse data 'X' as Y: ..."` strings should now use `related_data`
|
|
26
80
|
* for attribution and `message` for the reason.
|
|
@@ -29,17 +83,26 @@ export interface EngineErrorSource {
|
|
|
29
83
|
* - `source` points at the offending range in the original Lemma source.
|
|
30
84
|
*/
|
|
31
85
|
export interface EngineError {
|
|
32
|
-
kind:
|
|
86
|
+
kind:
|
|
87
|
+
| "parsing"
|
|
88
|
+
| "validation"
|
|
89
|
+
| "inversion"
|
|
90
|
+
| "registry"
|
|
91
|
+
| "missing_repository"
|
|
92
|
+
| "request"
|
|
93
|
+
| "resource_limit";
|
|
33
94
|
message: string;
|
|
34
95
|
related_data: string | null;
|
|
35
96
|
spec: string | null;
|
|
36
97
|
related_spec: string | null;
|
|
37
98
|
source: EngineErrorSource | null;
|
|
38
99
|
suggestion: string | null;
|
|
100
|
+
/** Present for `missing_repository` and `registry` errors (`@…` id). */
|
|
101
|
+
repository: string | null;
|
|
39
102
|
}
|
|
40
103
|
|
|
41
104
|
// ---------------------------------------------------------------------------
|
|
42
|
-
// Schema envelope (return shape of Engine.schema
|
|
105
|
+
// Schema envelope (return shape of Engine.schema)
|
|
43
106
|
// ---------------------------------------------------------------------------
|
|
44
107
|
|
|
45
108
|
/** Literal value produced by `JSON.stringify` on a Lemma `LiteralValue`. */
|
|
@@ -103,9 +166,12 @@ export type LemmaType =
|
|
|
103
166
|
| { kind: "veto"; message: string | null }
|
|
104
167
|
);
|
|
105
168
|
|
|
106
|
-
/** One input
|
|
169
|
+
/** One input declared in a spec. Omitted fields are absent (not `null`). */
|
|
107
170
|
export interface DataEntry {
|
|
108
171
|
type: LemmaType;
|
|
172
|
+
/** Literal bound in the source (`data x: literal`). */
|
|
173
|
+
bound_value?: LiteralValue;
|
|
174
|
+
/** `-> default ...` suggestion; omitted from `bound_value` until evaluation applies it. */
|
|
109
175
|
default?: LiteralValue;
|
|
110
176
|
}
|
|
111
177
|
|
|
@@ -117,11 +183,60 @@ export interface SpecSchema {
|
|
|
117
183
|
meta: Record<string, unknown>;
|
|
118
184
|
}
|
|
119
185
|
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
|
|
186
|
+
/** JSON mirror of Rust `ResolvedRepository` (engine `list`). */
|
|
187
|
+
export interface ResolvedRepositoryJson {
|
|
188
|
+
repository: LemmaRepositoryJson;
|
|
189
|
+
/** [`LemmaSpecSet`] list for this resolved repository. */
|
|
190
|
+
specs: LemmaSpecSetJson[];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** JSON mirror of Rust `LemmaSpecSet` as serialized by the engine. */
|
|
194
|
+
export interface LemmaSpecSetJson {
|
|
195
|
+
repository: LemmaRepositoryJson;
|
|
123
196
|
name: string;
|
|
124
|
-
effective_from
|
|
125
|
-
|
|
126
|
-
|
|
197
|
+
/** Temporal versions, ascending `effective_from` (same order as `iter_specs`). */
|
|
198
|
+
specs: LemmaSpecJson[];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** JSON mirror of Rust `LemmaRepository`. */
|
|
202
|
+
export interface LemmaRepositoryJson {
|
|
203
|
+
name: string | null;
|
|
204
|
+
dependency: string | null;
|
|
205
|
+
start_line: number;
|
|
206
|
+
source_type: unknown;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** JSON mirror of Rust `EffectiveDate` (externally tagged). */
|
|
210
|
+
export type EffectiveDateJson =
|
|
211
|
+
| { Origin: null }
|
|
212
|
+
| { DateTimeValue: DateTimeValueJson };
|
|
213
|
+
|
|
214
|
+
/** JSON mirror of Rust `DateTimeValue`. */
|
|
215
|
+
export interface DateTimeValueJson {
|
|
216
|
+
year: number;
|
|
217
|
+
month: number;
|
|
218
|
+
day: number;
|
|
219
|
+
hour: number;
|
|
220
|
+
minute: number;
|
|
221
|
+
second: number;
|
|
222
|
+
microsecond: number;
|
|
223
|
+
timezone: unknown;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** JSON mirror of Rust `LemmaSpec` (full AST; deep nodes are engine-shaped). */
|
|
227
|
+
export interface LemmaSpecJson {
|
|
228
|
+
name: string;
|
|
229
|
+
effective_from: EffectiveDateJson;
|
|
230
|
+
source_type: unknown;
|
|
231
|
+
start_line: number;
|
|
232
|
+
commentary: string | null;
|
|
233
|
+
data: unknown[];
|
|
234
|
+
rules: unknown[];
|
|
235
|
+
meta_fields: unknown[];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** One entry of {@link Engine.repositories}. */
|
|
239
|
+
export interface RepositoryEntry {
|
|
240
|
+
name: string | null;
|
|
241
|
+
dependency: string | null;
|
|
127
242
|
}
|