@manifest-configuration-language/browser 0.3.21 → 0.3.23

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/src/protocol.d.ts DELETED
@@ -1,206 +0,0 @@
1
- /* Generated from cmd/mcl-wasm/protocol.schema.json. Do not edit. */
2
-
3
- export type MCLWebAssemblyRequestAndResponseProtocol = Request | Response;
4
- export type Request = {
5
- requestId?: number;
6
- revision?: number;
7
- operation:
8
- | "parse"
9
- | "lint"
10
- | "format"
11
- | "check"
12
- | "evaluate"
13
- | "render"
14
- | "completion"
15
- | "definition"
16
- | "hover"
17
- | "references"
18
- | "rename"
19
- | "renameFileImports";
20
- position?: CompletionPosition;
21
- newName?: string;
22
- oldPath?: ProjectPath;
23
- newPath?: ProjectPath;
24
- entrypoint?: ProjectPath2;
25
- /**
26
- * UTF-8 entrypoint source, limited by the runtime.
27
- */
28
- source: string;
29
- /**
30
- * Project files are limited by the runtime; this count excludes the entrypoint.
31
- */
32
- files?: {
33
- [k: string]: FileInput;
34
- };
35
- };
36
- export type ProjectPath = ProjectPath1;
37
- export type ProjectPath1 = string;
38
- /**
39
- * Project-relative MCL source path. Defaults to main.mcl.
40
- */
41
- export type ProjectPath2 = string;
42
- /**
43
- * Binary files omit content and are supplied in the optional second run argument under the same path.
44
- */
45
- export type FileInput = {
46
- encoding: "utf8" | "binary";
47
- content?: string;
48
- };
49
- export type LintResult = LintDiagnostic[];
50
-
51
- export interface CompletionPosition {
52
- line: number;
53
- character: number;
54
- }
55
- export interface Response {
56
- requestId: number;
57
- revision?: number;
58
- ok: boolean;
59
- result?:
60
- | ParseResult
61
- | LintResult
62
- | FormatResult
63
- | CheckResult
64
- | EvaluateResult
65
- | RenderResult
66
- | CompletionResult
67
- | DefinitionResult
68
- | HoverResult
69
- | ReferencesResult
70
- | RenameResult
71
- | RenameFileImportsResult;
72
- error?: Error;
73
- }
74
- export interface ParseResult {
75
- declarations: number;
76
- }
77
- export interface LintDiagnostic {
78
- code: string;
79
- message: string;
80
- severity: string;
81
- path: string;
82
- line: number;
83
- column: number;
84
- endLine: number;
85
- endColumn: number;
86
- actions?: LintCodeAction[];
87
- }
88
- export interface LintCodeAction {
89
- kind: "removeUnreachableDefinition";
90
- /**
91
- * @minItems 1
92
- */
93
- edits: [RenameEdit, ...RenameEdit[]];
94
- }
95
- export interface RenameEdit {
96
- path: ProjectPath;
97
- range: SourceRange;
98
- newText: string;
99
- }
100
- export interface SourceRange {
101
- start: CompletionPosition;
102
- end: CompletionPosition;
103
- }
104
- export interface FormatResult {
105
- source: string;
106
- }
107
- export interface CheckResult {
108
- valid: true;
109
- artifacts: number;
110
- }
111
- export interface EvaluateResult {
112
- artifacts: number;
113
- renderedBytes: number;
114
- }
115
- export interface RenderResult {
116
- yaml: string;
117
- artifacts: number;
118
- sourceMap: SourceMap;
119
- }
120
- /**
121
- * Source map entries are limited by maxSourceMapBytes. Ranges use zero-based UTF-16 line and character positions with an exclusive end.
122
- */
123
- export interface SourceMap {
124
- complete: boolean;
125
- entries: SourceMapEntry[];
126
- }
127
- export interface SourceMapEntry {
128
- document: number;
129
- /**
130
- * JSON Pointer into the rendered YAML document.
131
- */
132
- path: string;
133
- kind: "key" | "value";
134
- output: SourceRange;
135
- sources: SourceMapOrigin[];
136
- }
137
- export interface SourceMapOrigin {
138
- path: ProjectPath;
139
- range: SourceRange;
140
- kind: "mcl" | "mcl-overlay-base" | "mcl-overlay-patch";
141
- multiplicity: "unique" | "repeated" | "ambiguous";
142
- occurrences: number;
143
- }
144
- export interface CompletionResult {
145
- isIncomplete: boolean;
146
- items: CompletionItem[];
147
- }
148
- export interface CompletionItem {
149
- label: string;
150
- kind: number;
151
- insertText?: string;
152
- detail?: string;
153
- documentation?: string;
154
- }
155
- export interface DefinitionResult {
156
- location: DefinitionLocation | null;
157
- }
158
- export interface DefinitionLocation {
159
- path: string;
160
- range: SourceRange;
161
- }
162
- export interface HoverResult {
163
- hover: HoverInfo | null;
164
- }
165
- export interface HoverInfo {
166
- contents: string;
167
- range: SourceRange;
168
- standardLibrary?: StandardLibraryFunction;
169
- }
170
- export interface StandardLibraryFunction {
171
- module: string;
172
- name: string;
173
- }
174
- export interface ReferencesResult {
175
- references: ReferenceLocation[];
176
- }
177
- export interface ReferenceLocation {
178
- path: ProjectPath;
179
- range: SourceRange;
180
- }
181
- export interface RenameResult {
182
- edits: RenameEdit[];
183
- }
184
- export interface RenameFileImportsResult {
185
- oldPath: ProjectPath;
186
- newPath: ProjectPath;
187
- edits: RenameEdit[];
188
- }
189
- export interface Error {
190
- code: string;
191
- message: string;
192
- path?: string;
193
- line?: number;
194
- column?: number;
195
- endLine?: number;
196
- endColumn?: number;
197
- related?: RelatedLocation[];
198
- }
199
- export interface RelatedLocation {
200
- path: string;
201
- message: string;
202
- line: number;
203
- column: number;
204
- endLine: number;
205
- endColumn: number;
206
- }
package/src/worker.js DELETED
@@ -1,204 +0,0 @@
1
- let initialized;
2
- let runtimeAssets;
3
- let networkAccessDenied = false;
4
- const runtimeFetch = globalThis.fetch.bind(globalThis);
5
- const networkAPINames = [
6
- "Worker",
7
- "SharedWorker",
8
- "XMLHttpRequest",
9
- "WebSocket",
10
- "EventSource",
11
- "WebTransport",
12
- "WebSocketStream",
13
- "RTCPeerConnection",
14
- "importScripts",
15
- ];
16
- const originalFetch = globalThis.fetch;
17
- const originalNetworkAPIs = new Map(
18
- networkAPINames
19
- .filter((name) => typeof globalThis[name] === "function")
20
- .map((name) => [name, globalThis[name]]),
21
- );
22
-
23
- function denyNetworkAccess() {
24
- globalThis.fetch = () =>
25
- Promise.reject(new TypeError("Network access is disabled in the MCL runtime"));
26
- for (const [name] of originalNetworkAPIs) {
27
- Object.defineProperty(globalThis, name, {
28
- configurable: true,
29
- writable: true,
30
- value: function MclNetworkAccessDenied() {
31
- throw new TypeError("Network access is disabled in the MCL runtime");
32
- },
33
- });
34
- }
35
- networkAccessDenied = true;
36
- }
37
-
38
- async function probeNetworkAccess(url) {
39
- let fetchBlocked = false;
40
- try {
41
- await globalThis.fetch(url);
42
- } catch {
43
- fetchBlocked = true;
44
- }
45
-
46
- const availableAPIs = ["fetch", ...originalNetworkAPIs.keys()];
47
- const blockedAPIs = availableAPIs.filter((name) =>
48
- name === "fetch"
49
- ? globalThis.fetch !== originalFetch
50
- : globalThis[name] !== originalNetworkAPIs.get(name),
51
- );
52
- return { fetchBlocked, availableAPIs, blockedAPIs };
53
- }
54
-
55
- function waitForWasmReady() {
56
- return new Promise((resolve) => {
57
- Object.defineProperty(globalThis, "mclWasmReady", {
58
- configurable: true,
59
- set(value) {
60
- Object.defineProperty(globalThis, "mclWasmReady", {
61
- configurable: true,
62
- writable: true,
63
- value,
64
- });
65
- if (value === true) resolve();
66
- },
67
- });
68
- });
69
- }
70
-
71
- async function initialize() {
72
- if (initialized) return initialized;
73
- initialized = (async () => {
74
- if (!runtimeAssets?.wasmURL || !runtimeAssets?.wasmExecURL)
75
- throw new Error("MCL runtime assets were not configured");
76
- postMessage({ type: "status", status: "fetching" });
77
- await import(runtimeAssets.wasmExecURL);
78
- const go = new Go();
79
- const response = await runtimeFetch(runtimeAssets.wasmURL);
80
- if (!response.ok) throw new Error(`Unable to load MCL WebAssembly: ${response.status}`);
81
- // Load the runtime before denying network APIs, then lock them before Go starts.
82
- denyNetworkAccess();
83
- let instance;
84
- postMessage({ type: "status", status: "compiling" });
85
- try {
86
- ({ instance } = await WebAssembly.instantiateStreaming(response.clone(), go.importObject));
87
- } catch {
88
- ({ instance } = await WebAssembly.instantiate(await response.arrayBuffer(), go.importObject));
89
- }
90
- postMessage({ type: "status", status: "initializing" });
91
- const wasmReady = waitForWasmReady();
92
- await Promise.race([
93
- wasmReady,
94
- go.run(instance).then(() => {
95
- throw new Error("MCL WebAssembly exited before initialization completed");
96
- }),
97
- ]);
98
- postMessage({ type: "status", status: "ready" });
99
- postMessage({ type: "ready" });
100
- })().catch((error) => {
101
- postMessage({ type: "status", status: "error" });
102
- postMessage({ type: "fatal", message: error instanceof Error ? error.message : String(error) });
103
- throw error;
104
- });
105
- return initialized;
106
- }
107
-
108
- function encodeFiles(files) {
109
- // Paths come from project input and may legally contain object property
110
- // names such as `__proto__`; keep them as data when serializing the request.
111
- const encoded = Object.create(null);
112
- const binaryFiles = Object.create(null);
113
- for (const [filePath, content] of Object.entries(files ?? {})) {
114
- if (typeof content === "string") {
115
- encoded[filePath] = { encoding: "utf8", content };
116
- } else if (content instanceof Uint8Array) {
117
- encoded[filePath] = { encoding: "binary" };
118
- binaryFiles[filePath] = content;
119
- } else {
120
- throw new TypeError(`Project file ${filePath} must be a string or Uint8Array`);
121
- }
122
- }
123
- return { files: encoded, binaryFiles };
124
- }
125
-
126
- self.addEventListener("message", async (event) => {
127
- const message = event.data;
128
- if (message?.type === "network-probe" && networkAccessDenied) {
129
- const result = await probeNetworkAccess(message.url);
130
- postMessage({ type: "network-probe-result", requestId: message.requestId, ...result });
131
- return;
132
- }
133
- if (message?.type === "configure") {
134
- runtimeAssets = message;
135
- initialize().catch(() => {});
136
- return;
137
- }
138
- if (message?.type === "project-update") {
139
- try {
140
- await initialize();
141
- const binaryFiles = message.binaryFiles ?? Object.create(null);
142
- const result = JSON.parse(
143
- globalThis.mclWasm.updateProject(message.projectId, message.update, binaryFiles),
144
- );
145
- postMessage({ type: "project-updated", requestId: message.requestId, value: result });
146
- } catch (error) {
147
- postMessage({
148
- type: "project-updated",
149
- requestId: message.requestId,
150
- value: {
151
- ok: false,
152
- error: {
153
- code: "MCL-WASM-PROJECT",
154
- message: error instanceof Error ? error.message : String(error),
155
- },
156
- },
157
- });
158
- }
159
- return;
160
- }
161
- if (message?.type !== "run") return;
162
- try {
163
- await initialize();
164
- const encodedFiles = encodeFiles(message.files);
165
- const request = {
166
- requestId: message.requestId,
167
- revision: message.requestId,
168
- operation: message.operation,
169
- entrypoint: message.entrypoint,
170
- newName: message.newName,
171
- oldPath: message.oldPath,
172
- newPath: message.newPath,
173
- position: message.position,
174
- source: message.source,
175
- files: encodedFiles.files,
176
- };
177
- const value = JSON.parse(
178
- message.projectId === undefined
179
- ? globalThis.mclWasm.run(JSON.stringify(request), encodedFiles.binaryFiles)
180
- : globalThis.mclWasm.run(
181
- JSON.stringify(request),
182
- encodedFiles.binaryFiles,
183
- message.projectId,
184
- ),
185
- );
186
- postMessage({
187
- type: "response",
188
- requestId: message.requestId,
189
- value,
190
- });
191
- } catch (error) {
192
- postMessage({
193
- type: "response",
194
- requestId: message.requestId,
195
- value: {
196
- ok: false,
197
- error: {
198
- code: "MCL-WASM-INPUT",
199
- message: error instanceof Error ? error.message : String(error),
200
- },
201
- },
202
- });
203
- }
204
- });
File without changes