@manifest-configuration-language/browser 0.3.6 → 0.3.8
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 +2 -0
- package/dist/mcl.wasm +1 -1
- package/package.json +1 -1
- package/src/index.d.ts +13 -0
- package/src/index.js +58 -4
- package/src/worker.js +5 -0
package/README.md
CHANGED
|
@@ -21,6 +21,8 @@ try {
|
|
|
21
21
|
|
|
22
22
|
Call `runtime.warmUp()` to load the WebAssembly runtime before the first project operation. Pass `signal` and `timeoutMs` to warm-up or an operation to cancel it or set an upper bound for that call. Warm-up's timeout and `initializationTimeoutMs` bound worker startup; an operation's `timeoutMs` bounds execution after startup. Cancelling or timing out worker startup terminates that worker; the next queued operation can create a fresh worker. Cancelling or timing out an operation terminates its worker. Operations and warm-up are serialized because the current Go runtime uses one in-memory project root. Set `priority: "interactive"` for user-triggered work that should move ahead of queued requests, or `priority: "background"` for work that can wait behind default-priority requests. Pending completion, hover, and lint requests supersede older requests of the same project and priority; higher-priority pending requests are retained.
|
|
23
23
|
|
|
24
|
+
`createMclRuntime()` accepts optional `onStatus` and `onOperation` callbacks for local diagnostics and performance measurements. `onStatus` receives `fetching`, `compiling`, `initializing`, `ready`, or `error` for each Worker lifecycle. `onOperation` receives the operation name, total elapsed milliseconds from API call through queue wait and completion, and a `success`, `error`, or `aborted` outcome. Events do not include source text, file paths, or project contents, and callbacks are not sent to a server. Callback exceptions do not affect runtime operations.
|
|
25
|
+
|
|
24
26
|
Project files can be UTF-8 strings or `Uint8Array` values. UTF-8 files remain inline in project updates. The Browser SDK copies each changed `Uint8Array` and transfers its buffer to the Worker; the Worker sends only `{ "encoding": "binary" }` metadata in the update JSON and passes a path-to-`Uint8Array` map to the Go/WASM project session. The Go runtime copies those bytes into its bounded project filesystem. The SDK-owned and caller-owned arrays remain reusable after each update.
|
|
25
27
|
|
|
26
28
|
An open project is a Worker-backed session. Call `project.update(files)` with the complete next snapshot when project files change, then use the returned project handle for subsequent operations. The SDK validates changed files, sends only changed, added, and removed files to the Worker, and applies those deltas to a bounded in-memory Go/WASM filesystem. Each operation sends its entrypoint source and session ID; the project filesystem is not resent or rebuilt. If a canceled or timed-out operation terminates the Worker, the next operation restores the complete snapshot before running. Existing `runtime.parse`, `runtime.render`, and other source-based methods continue to use per-request files.
|
package/dist/mcl.wasm
CHANGED
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -77,9 +77,22 @@ export type MclResult =
|
|
|
77
77
|
export interface RuntimeOptions {
|
|
78
78
|
initializationTimeoutMs?: number;
|
|
79
79
|
operationTimeoutMs?: number;
|
|
80
|
+
/** Receives local WebAssembly initialization state changes without project data. */
|
|
81
|
+
onStatus?: (event: RuntimeStatusEvent) => void;
|
|
82
|
+
/** Receives local operation latency measurements without source or project data. */
|
|
83
|
+
onOperation?: (event: RuntimeOperationEvent) => void;
|
|
80
84
|
workerFactory?: () => Worker;
|
|
81
85
|
}
|
|
82
86
|
|
|
87
|
+
export type RuntimeStatus = "fetching" | "compiling" | "initializing" | "ready" | "error";
|
|
88
|
+
export type RuntimeStatusEvent = { status: RuntimeStatus };
|
|
89
|
+
export type RuntimeOperationOutcome = "success" | "error" | "aborted";
|
|
90
|
+
export type RuntimeOperationEvent = {
|
|
91
|
+
operation: MclOperation;
|
|
92
|
+
durationMs: number;
|
|
93
|
+
outcome: RuntimeOperationOutcome;
|
|
94
|
+
};
|
|
95
|
+
|
|
83
96
|
export interface MclRuntime {
|
|
84
97
|
openProject(files: ProjectFiles): MclProject;
|
|
85
98
|
warmUp(options?: RequestOptions): Promise<void>;
|
package/src/index.js
CHANGED
|
@@ -112,6 +112,26 @@ export function createMclRuntime(options = {}) {
|
|
|
112
112
|
let stopCurrent;
|
|
113
113
|
let stopInitialization;
|
|
114
114
|
|
|
115
|
+
function emitStatus(status) {
|
|
116
|
+
try {
|
|
117
|
+
Promise.resolve(options.onStatus?.({ status })).catch(() => {});
|
|
118
|
+
} catch {
|
|
119
|
+
// Observability callbacks must not affect runtime behavior.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function emitOperation(operation, startedAt, outcome) {
|
|
124
|
+
try {
|
|
125
|
+
Promise.resolve(options.onOperation?.({
|
|
126
|
+
operation,
|
|
127
|
+
durationMs: Math.max(0, performance.now() - startedAt),
|
|
128
|
+
outcome,
|
|
129
|
+
})).catch(() => {});
|
|
130
|
+
} catch {
|
|
131
|
+
// Observability callbacks must not affect runtime behavior.
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
115
135
|
function enqueue(operation, run, signal, scope = "runtime", requestedPriority) {
|
|
116
136
|
if (signal?.aborted) return Promise.reject(signal.reason ?? abortError());
|
|
117
137
|
const priority =
|
|
@@ -144,8 +164,15 @@ export function createMclRuntime(options = {}) {
|
|
|
144
164
|
if (group.size === 0) latestPending.delete(groupKey);
|
|
145
165
|
};
|
|
146
166
|
|
|
147
|
-
if (["render", "evaluate", "check"].includes(operation))
|
|
167
|
+
if (["render", "evaluate", "check"].includes(operation)) {
|
|
148
168
|
supersedePending("lint", priority, "An explicit run replaced this pending lint");
|
|
169
|
+
} else if (priority > requestPriorities.background && operation !== "lint") {
|
|
170
|
+
supersedePending(
|
|
171
|
+
"lint",
|
|
172
|
+
requestPriorities.background,
|
|
173
|
+
"An interactive operation replaced this pending background lint",
|
|
174
|
+
);
|
|
175
|
+
}
|
|
149
176
|
|
|
150
177
|
const queueController = new AbortController();
|
|
151
178
|
const pending = { controller: queueController, started: false };
|
|
@@ -187,6 +214,12 @@ export function createMclRuntime(options = {}) {
|
|
|
187
214
|
worker = currentWorker;
|
|
188
215
|
workerGeneration++;
|
|
189
216
|
workerProject = undefined;
|
|
217
|
+
let lastStatus;
|
|
218
|
+
const reportStatus = (status) => {
|
|
219
|
+
if (lastStatus === status) return;
|
|
220
|
+
lastStatus = status;
|
|
221
|
+
emitStatus(status);
|
|
222
|
+
};
|
|
190
223
|
let resolveReady;
|
|
191
224
|
let rejectReady;
|
|
192
225
|
const initialization = new Promise((resolve, reject) => {
|
|
@@ -199,7 +232,10 @@ export function createMclRuntime(options = {}) {
|
|
|
199
232
|
initializationTimeoutMs,
|
|
200
233
|
);
|
|
201
234
|
const onMessage = (event) => {
|
|
202
|
-
if (event.data?.type === "
|
|
235
|
+
if (event.data?.type === "status") {
|
|
236
|
+
reportStatus(event.data.status);
|
|
237
|
+
} else if (event.data?.type === "ready") {
|
|
238
|
+
reportStatus("ready");
|
|
203
239
|
clearTimeout(timer);
|
|
204
240
|
currentWorker.removeEventListener("message", onMessage);
|
|
205
241
|
currentWorker.removeEventListener("error", onError);
|
|
@@ -209,8 +245,12 @@ export function createMclRuntime(options = {}) {
|
|
|
209
245
|
fail(new Error(event.data.message || "MCL WebAssembly initialization failed"));
|
|
210
246
|
}
|
|
211
247
|
};
|
|
212
|
-
const onError = (event) =>
|
|
248
|
+
const onError = (event) => {
|
|
249
|
+
reportStatus("error");
|
|
250
|
+
fail(new Error(event.message || "MCL worker failed"));
|
|
251
|
+
};
|
|
213
252
|
function fail(error) {
|
|
253
|
+
reportStatus("error");
|
|
214
254
|
clearTimeout(timer);
|
|
215
255
|
currentWorker.removeEventListener("message", onMessage);
|
|
216
256
|
currentWorker.removeEventListener("error", onError);
|
|
@@ -347,6 +387,7 @@ export function createMclRuntime(options = {}) {
|
|
|
347
387
|
) {
|
|
348
388
|
const signal = requestOptions.signal;
|
|
349
389
|
if (signal?.aborted) throw new DOMException("The operation was aborted", "AbortError");
|
|
390
|
+
const startedAt = performance.now();
|
|
350
391
|
const run = async () => {
|
|
351
392
|
if (disposed) throw new Error("MCL runtime has been disposed");
|
|
352
393
|
if (requestOptions.signal?.aborted)
|
|
@@ -442,7 +483,20 @@ export function createMclRuntime(options = {}) {
|
|
|
442
483
|
throw error;
|
|
443
484
|
}
|
|
444
485
|
};
|
|
445
|
-
|
|
486
|
+
try {
|
|
487
|
+
const result = await enqueue(
|
|
488
|
+
operation,
|
|
489
|
+
run,
|
|
490
|
+
signal,
|
|
491
|
+
project?.id ?? "runtime",
|
|
492
|
+
requestOptions.priority,
|
|
493
|
+
);
|
|
494
|
+
emitOperation(operation, startedAt, "success");
|
|
495
|
+
return result;
|
|
496
|
+
} catch (error) {
|
|
497
|
+
emitOperation(operation, startedAt, error?.name === "AbortError" ? "aborted" : "error");
|
|
498
|
+
throw error;
|
|
499
|
+
}
|
|
446
500
|
}
|
|
447
501
|
|
|
448
502
|
function warmUp(requestOptions = {}) {
|
package/src/worker.js
CHANGED
|
@@ -73,6 +73,7 @@ async function initialize() {
|
|
|
73
73
|
initialized = (async () => {
|
|
74
74
|
if (!runtimeAssets?.wasmURL || !runtimeAssets?.wasmExecURL)
|
|
75
75
|
throw new Error("MCL runtime assets were not configured");
|
|
76
|
+
postMessage({ type: "status", status: "fetching" });
|
|
76
77
|
await import(runtimeAssets.wasmExecURL);
|
|
77
78
|
const go = new Go();
|
|
78
79
|
const response = await runtimeFetch(runtimeAssets.wasmURL);
|
|
@@ -80,11 +81,13 @@ async function initialize() {
|
|
|
80
81
|
// Load the runtime before denying network APIs, then lock them before Go starts.
|
|
81
82
|
denyNetworkAccess();
|
|
82
83
|
let instance;
|
|
84
|
+
postMessage({ type: "status", status: "compiling" });
|
|
83
85
|
try {
|
|
84
86
|
({ instance } = await WebAssembly.instantiateStreaming(response.clone(), go.importObject));
|
|
85
87
|
} catch {
|
|
86
88
|
({ instance } = await WebAssembly.instantiate(await response.arrayBuffer(), go.importObject));
|
|
87
89
|
}
|
|
90
|
+
postMessage({ type: "status", status: "initializing" });
|
|
88
91
|
const wasmReady = waitForWasmReady();
|
|
89
92
|
await Promise.race([
|
|
90
93
|
wasmReady,
|
|
@@ -92,8 +95,10 @@ async function initialize() {
|
|
|
92
95
|
throw new Error("MCL WebAssembly exited before initialization completed");
|
|
93
96
|
}),
|
|
94
97
|
]);
|
|
98
|
+
postMessage({ type: "status", status: "ready" });
|
|
95
99
|
postMessage({ type: "ready" });
|
|
96
100
|
})().catch((error) => {
|
|
101
|
+
postMessage({ type: "status", status: "error" });
|
|
97
102
|
postMessage({ type: "fatal", message: error instanceof Error ? error.message : String(error) });
|
|
98
103
|
throw error;
|
|
99
104
|
});
|