@maligator/cli 0.1.0-alpha.27 → 0.1.0-alpha.29

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.
@@ -0,0 +1,445 @@
1
+ // Generated from src/platform/catalog.ts; edit the catalog and regenerate.
2
+ /**
3
+ * Parallel computation and isolated event loops. Declared entries are bundled into
4
+ * the application image; workers do not compile or load source files at runtime.
5
+ * Native executors and GC helpers are shared across JavaScript isolates.
6
+ */
7
+ declare module "maligator:workers" {
8
+ /**
9
+ * An immutable image-local worker entry declaration. The compiler resolves the
10
+ * declaration independently of how libraries pass the descriptor or its href onward.
11
+ * Erased module types express the caller's assertion; runtime entry identity is
12
+ * validated.
13
+ *
14
+ * @see https://maligator.ddv.tools/api/workers#WorkerUrl
15
+ */
16
+ export type WorkerUrl<Module = unknown> = {
17
+ readonly href: string;
18
+ readonly __workerModule?: Module;
19
+ };
20
+
21
+ /**
22
+ * ArrayBuffer stores move at admission. MessagePort endpoints transfer ownership.
23
+ * SharedArrayBuffer is cloned by sharing its backing and cannot be transferred.
24
+ *
25
+ * @see https://maligator.ddv.tools/api/workers#Transferable
26
+ */
27
+ export type Transferable = ArrayBuffer | MessagePort;
28
+
29
+ /**
30
+ * Cancellation is cooperative while a pool task runs. The worker remains occupied
31
+ * until the task's returned promise settles.
32
+ *
33
+ * @see https://maligator.ddv.tools/api/workers#TaskContext
34
+ */
35
+ export type TaskContext = {
36
+ /** Worker-local cancellation signal. Cancellation does not preempt JavaScript. */
37
+ readonly signal: AbortSignal;
38
+ /** Throws if cancelled. Check between bounded pieces of work. */
39
+ throwIfCancelled(): void;
40
+ };
41
+
42
+ /**
43
+ * An opaque result envelope. Constructing it does not detach buffers; publication
44
+ * commits transfers.
45
+ *
46
+ * @see https://maligator.ddv.tools/api/workers#TransferResult
47
+ */
48
+ export type TransferResult<Value> = {
49
+ readonly value: Value;
50
+ readonly __transferResult: unique symbol;
51
+ };
52
+
53
+ /**
54
+ * Names of context-first exported task functions.
55
+ *
56
+ * @see https://maligator.ddv.tools/api/workers#TaskNames
57
+ */
58
+ export type TaskNames<Module> = {
59
+ [Key in keyof Module]-?: Module[Key] extends (
60
+ context: TaskContext,
61
+ ...args: infer Args
62
+ ) => unknown
63
+ ? Key
64
+ : never;
65
+ }[keyof Module] &
66
+ string;
67
+
68
+ /**
69
+ * The task's argument tuple, excluding its local cancellation context.
70
+ *
71
+ * @see https://maligator.ddv.tools/api/workers#TaskArgs
72
+ */
73
+ export type TaskArgs<Function> = Function extends (
74
+ context: TaskContext,
75
+ ...args: infer Args
76
+ ) => unknown
77
+ ? Args
78
+ : never;
79
+
80
+ /**
81
+ * The settled task result after unwrapping an explicit transfer envelope.
82
+ *
83
+ * @see https://maligator.ddv.tools/api/workers#TaskValue
84
+ */
85
+ export type TaskValue<Function> = Function extends (
86
+ ...args: Array<never>
87
+ ) => infer Result
88
+ ? Awaited<Result> extends TransferResult<infer Value>
89
+ ? Value
90
+ : Awaited<Result>
91
+ : never;
92
+
93
+ /**
94
+ * Fixed persistent worker count and admission bounds. Every worker has independent
95
+ * module state. A size-one pool dispatches admitted tasks serially.
96
+ *
97
+ * @see https://maligator.ddv.tools/api/workers#PoolOptions
98
+ */
99
+ export type PoolOptions = {
100
+ /** Positive safe integer; defaults to host parallelism, falling back to 1. */
101
+ size?: number;
102
+ /** Nonnegative safe integer; defaults to four times size. Zero disables the waiting queue. */
103
+ maxQueuedTasks?: number;
104
+ /** Positive safe integer in bytes; defaults to 67108864 (64 MiB). */
105
+ maxQueuedBytes?: number;
106
+ /** Positive safe integer in bytes; defaults to maxQueuedBytes. */
107
+ maxMessageBytes?: number;
108
+ /** Worker name prefix; each worker receives a one-based suffix. */
109
+ name?: string;
110
+ };
111
+
112
+ /**
113
+ * The transfer list commits synchronously when run returns normally. Validation,
114
+ * saturation, closed pools and already-aborted signals throw before admission.
115
+ *
116
+ * @see https://maligator.ddv.tools/api/workers#RunOptions
117
+ */
118
+ export type RunOptions = {
119
+ /** Already-aborted signals throw before admission. Running cancellation is cooperative. */
120
+ signal?: AbortSignal;
121
+ /** Ownership moves synchronously on successful admission; rejection leaves values unchanged. */
122
+ transfer?: ReadonlyArray<Transferable>;
123
+ };
124
+
125
+ /**
126
+ * The window bounds pulled inputs and buffered results together. Results are yielded
127
+ * in input order; iterator return cancels this map's work and closes its input.
128
+ *
129
+ * @see https://maligator.ddv.tools/api/workers#MapOptions
130
+ */
131
+ export type MapOptions<Args> = {
132
+ /** Cancels only work owned by this map; running tasks must cooperate. */
133
+ signal?: AbortSignal;
134
+ /** Positive safe integer; defaults to pool size. Bounds pulled inputs and buffered results together. */
135
+ window?: number;
136
+ /** Called for each input before admission to choose values whose ownership moves. */
137
+ transfer?: (args: Args, index: number) => ReadonlyArray<Transferable>;
138
+ };
139
+
140
+ /**
141
+ * A snapshot of this pool's scheduling and settled operations.
142
+ *
143
+ * @see https://maligator.ddv.tools/api/workers#PoolStats
144
+ */
145
+ export type PoolStats = {
146
+ readonly size: number;
147
+ readonly active: number;
148
+ readonly queued: number;
149
+ readonly completed: number;
150
+ readonly failed: number;
151
+ readonly cancelled: number;
152
+ };
153
+
154
+ /**
155
+ * A bounded task scheduler over isolated persistent workers. Each worker executes
156
+ * one task through asynchronous settlement. No accepted task is replayed after
157
+ * worker failure.
158
+ *
159
+ * @see https://maligator.ddv.tools/api/workers#WorkerPool
160
+ */
161
+ export type WorkerPool<Module> = {
162
+ /** Resolves after every worker evaluates the entry; rejects on startup failure. */
163
+ readonly ready: Promise<void>;
164
+ /** Throws on failed admission; returns a promise for the accepted task's result or failure. */
165
+ run<Key extends TaskNames<Module>>(
166
+ name: Key,
167
+ args: TaskArgs<Module[Key]>,
168
+ options?: RunOptions,
169
+ ): Promise<TaskValue<Module[Key]>>;
170
+ /** Yields in input order. Returning from the iterator cancels its work and closes its input. */
171
+ map<Key extends TaskNames<Module>>(
172
+ name: Key,
173
+ args: Iterable<TaskArgs<Module[Key]>> | AsyncIterable<TaskArgs<Module[Key]>>,
174
+ options?: MapOptions<TaskArgs<Module[Key]>>,
175
+ ): AsyncIterable<TaskValue<Module[Key]>>;
176
+ /** Stops admission, drains accepted tasks, then joins every worker. Idempotent. */
177
+ close(): Promise<void>;
178
+ /** Rejects outstanding tasks with AbortError; joins workers after running tasks cooperate and settle. */
179
+ terminate(): Promise<void>;
180
+ /** Returns a scheduling snapshot; counts are not a subscription. */
181
+ stats(): PoolStats;
182
+ /** Keeps the process alive while pool workers exist; returns this pool. */
183
+ ref(): WorkerPool<Module>;
184
+ /** Allows the process to exit without waiting for this pool; returns this pool. */
185
+ unref(): WorkerPool<Module>;
186
+ /** Reports whether this pool currently keeps the process alive. */
187
+ hasRef(): boolean;
188
+ };
189
+
190
+ /**
191
+ * A terminal record published only after the native worker is joined and its slot is
192
+ * released.
193
+ *
194
+ * @see https://maligator.ddv.tools/api/workers#WorkerExit
195
+ */
196
+ export type WorkerExit = {
197
+ readonly id: number;
198
+ readonly code: number;
199
+ readonly reason: "completed" | "terminated" | "error";
200
+ readonly error?: unknown;
201
+ };
202
+
203
+ /**
204
+ * Worker data is snapshotted before startup. The native host bounds live workers and
205
+ * message admission process-wide.
206
+ *
207
+ * @see https://maligator.ddv.tools/api/workers#WorkerOptions
208
+ */
209
+ export type WorkerOptions = {
210
+ name?: string;
211
+ /** Cloned into workerData before startup; later caller mutations are not shared. */
212
+ data?: unknown;
213
+ /** Values moved as part of startup-data admission. */
214
+ transfer?: ReadonlyArray<Transferable>;
215
+ /** Positive safe integer, at most 4294967295; defaults to 4096 messages per endpoint. */
216
+ maxQueuedMessages?: number;
217
+ /** Positive safe integer in bytes; defaults to 67108864 (64 MiB) per endpoint. */
218
+ maxQueuedBytes?: number;
219
+ /** Positive safe integer in bytes; defaults to 16777216 (16 MiB) per message. */
220
+ maxMessageBytes?: number;
221
+ };
222
+
223
+ /**
224
+ * Each endpoint bounds its pending message count and bytes. Rejection leaves the
225
+ * sender's transferables unchanged.
226
+ *
227
+ * @see https://maligator.ddv.tools/api/workers#MessageChannelOptions
228
+ */
229
+ export type MessageChannelOptions = {
230
+ /** Positive safe integer, at most 4294967295; defaults to 4096 messages per endpoint. */
231
+ maxQueuedMessages?: number;
232
+ /** Positive safe integer in bytes; defaults to 67108864 (64 MiB) per endpoint. */
233
+ maxQueuedBytes?: number;
234
+ /** Positive safe integer in bytes; defaults to 16777216 (16 MiB) per message. */
235
+ maxMessageBytes?: number;
236
+ };
237
+
238
+ /**
239
+ * An ordered bidirectional endpoint with transactional transfer and bounded queues.
240
+ * Message listeners and values are owned by the receiving isolate.
241
+ *
242
+ * @see https://maligator.ddv.tools/api/workers#MessagePort.type
243
+ */
244
+ export interface MessagePort<Send = unknown, Receive = unknown> extends EventTarget {
245
+ /** Clones and admits a message synchronously. Transfer commits only after successful validation/admission. */
246
+ postMessage(value: Send, transfer?: ReadonlyArray<Transferable>): void;
247
+ /** Setting this handler starts delivery. addEventListener listeners need start(). */
248
+ onmessage: ((event: MessageEvent<Receive>) => void) | null;
249
+ /** Receives message decoding failures in the receiving isolate. */
250
+ onmessageerror: ((event: MessageEvent<unknown>) => void) | null;
251
+ /** Enables delivery to event listeners; repeated calls are harmless. */
252
+ start(): void;
253
+ /** Discards queued messages and closes this endpoint. */
254
+ close(): void;
255
+ /** Keeps the receiving isolate alive; returns this port. */
256
+ ref(): MessagePort<Send, Receive>;
257
+ /** Allows the receiving isolate to exit; returns this port. */
258
+ unref(): MessagePort<Send, Receive>;
259
+ hasRef(): boolean;
260
+ }
261
+
262
+ /**
263
+ * A standalone channel whose endpoints may be transferred to workers.
264
+ *
265
+ * @see https://maligator.ddv.tools/api/workers#MessageChannel.type
266
+ */
267
+ export type MessageChannel = {
268
+ readonly port1: MessagePort;
269
+ readonly port2: MessagePort;
270
+ };
271
+
272
+ /**
273
+ * A long-lived isolated module and its parent communication port. Startup completes
274
+ * after module evaluation; shutdown completes after native thread reaping.
275
+ *
276
+ * @see https://maligator.ddv.tools/api/workers#Worker.type
277
+ */
278
+ export type Worker<Send = unknown, Receive = unknown> = EventTarget & {
279
+ readonly id: number;
280
+ /** Resolves after entry evaluation; rejects on startup failure. */
281
+ readonly ready: Promise<void>;
282
+ /** Resolves with a terminal record after the native thread is joined and its slot released. */
283
+ readonly closed: Promise<WorkerExit>;
284
+ readonly port: MessagePort<Send, Receive>;
285
+ /** Requests shutdown and resolves after thread reaping. */
286
+ terminate(): Promise<WorkerExit>;
287
+ ref(): Worker<Send, Receive>;
288
+ unref(): Worker<Send, Receive>;
289
+ hasRef(): boolean;
290
+ };
291
+
292
+ /**
293
+ * Declare an entry using a static string literal and explicit import.meta.url base.
294
+ * The immutable href projection can be passed to existing worker libraries.
295
+ *
296
+ * @example
297
+ * // declaration.ts
298
+ * import { createWorkerUrl } from "maligator:workers";
299
+ *
300
+ * export const tasks = createWorkerUrl<typeof import("./sum.ts")>(
301
+ * "./sum.ts",
302
+ * import.meta.url,
303
+ * );
304
+ *
305
+ * console.log(Object.isFrozen(tasks), tasks.href.startsWith("file:"));
306
+ *
307
+ * @see https://maligator.ddv.tools/api/workers#createWorkerUrl
308
+ */
309
+ export const createWorkerUrl: <Module = unknown>(
310
+ specifier: string,
311
+ base: string,
312
+ ) => WorkerUrl<Module>;
313
+ /**
314
+ * Create a bounded pool of persistent workers for a declared entry. Submission
315
+ * failures throw synchronously; admitted tasks settle asynchronously. Await ready
316
+ * before submitting startup-dependent work and close the pool when finished. Throws
317
+ * NotSupportedError without threads and RangeError for invalid bounds.
318
+ *
319
+ * @see https://maligator.ddv.tools/api/workers#createPool
320
+ */
321
+ export const createPool: <Module>(
322
+ entry: WorkerUrl<Module>,
323
+ options?: PoolOptions,
324
+ ) => WorkerPool<Module>;
325
+ /**
326
+ * Wrap a result for transfer when the worker publishes it.
327
+ *
328
+ * @example
329
+ * // transfer-task.ts
330
+ * import { transfer } from "maligator:workers";
331
+ * import type { TaskContext } from "maligator:workers";
332
+ *
333
+ * export function reverse(context: TaskContext, buffer: ArrayBuffer) {
334
+ * context.throwIfCancelled();
335
+ * new Uint8Array(buffer).reverse();
336
+ * return transfer(buffer, [buffer]);
337
+ * }
338
+ *
339
+ * @see https://maligator.ddv.tools/api/workers#transfer
340
+ */
341
+ export const transfer: <Value>(
342
+ value: Value,
343
+ transfer: ReadonlyArray<Transferable>,
344
+ ) => TransferResult<Value>;
345
+ /**
346
+ * Start a declared isolated module and expose its ordered port and complete
347
+ * lifecycle.
348
+ *
349
+ * @example
350
+ * // echo.ts
351
+ * import { parentPort } from "maligator:workers";
352
+ *
353
+ * if (parentPort === null) throw new Error("Run this module as a worker");
354
+ * const port = parentPort;
355
+ * port.onmessage = (event) => {
356
+ * port.postMessage(String(event.data));
357
+ * };
358
+ * port.start();
359
+ *
360
+ * @see https://maligator.ddv.tools/api/workers#Worker
361
+ */
362
+ export const Worker: {
363
+ new <Send = unknown, Receive = unknown>(
364
+ entry: WorkerUrl,
365
+ options?: WorkerOptions,
366
+ ): Worker<Send, Receive>;
367
+ };
368
+ /**
369
+ * Create two transferable endpoints independently of worker startup.
370
+ *
371
+ * @see https://maligator.ddv.tools/api/workers#MessageChannel
372
+ */
373
+ export const MessageChannel: { new (options?: MessageChannelOptions): MessageChannel };
374
+ /**
375
+ * The port prototype for type and identity checks. Ports are created by channels and
376
+ * workers.
377
+ *
378
+ * @see https://maligator.ddv.tools/api/workers#MessagePort
379
+ */
380
+ export const MessagePort: { readonly prototype: MessagePort };
381
+ /**
382
+ * Synchronously dequeue one pending message without running unrelated callbacks.
383
+ *
384
+ * @see https://maligator.ddv.tools/api/workers#receiveMessageOnPort
385
+ */
386
+ export const receiveMessageOnPort: <Receive>(
387
+ port: MessagePort<unknown, Receive>,
388
+ ) => { message: Receive } | undefined;
389
+ /**
390
+ * Report the running host's worker facilities and capacity.
391
+ *
392
+ * @example
393
+ * // capabilities.ts
394
+ * import { capabilities } from "maligator:workers";
395
+ *
396
+ * const host = capabilities();
397
+ * console.log(host.threads, host.sharedMemory);
398
+ * console.log(host.parallelism >= 1, host.maxWorkers >= 1);
399
+ *
400
+ * @see https://maligator.ddv.tools/api/workers#capabilities
401
+ */
402
+ export const capabilities: () => {
403
+ readonly threads: boolean;
404
+ readonly sharedMemory: boolean;
405
+ readonly parallelism: number;
406
+ readonly maxWorkers: number;
407
+ };
408
+ /**
409
+ * The worker's parent endpoint; null in the main isolate.
410
+ *
411
+ * @example
412
+ * // echo.ts
413
+ * import { parentPort } from "maligator:workers";
414
+ *
415
+ * if (parentPort === null) throw new Error("Run this module as a worker");
416
+ * const port = parentPort;
417
+ * port.onmessage = (event) => {
418
+ * port.postMessage(String(event.data));
419
+ * };
420
+ * port.start();
421
+ *
422
+ * @see https://maligator.ddv.tools/api/workers#parentPort
423
+ */
424
+ export const parentPort: MessagePort | null;
425
+ /**
426
+ * The worker-owned clone of startup data.
427
+ *
428
+ * @example
429
+ * // configuration.ts
430
+ * import { createWorkerUrl, Worker } from "maligator:workers";
431
+ *
432
+ * const entry = createWorkerUrl("./worker-data.ts", import.meta.url);
433
+ * const worker = new Worker(entry, { data: { label: "thumbnail" } });
434
+ * try {
435
+ * await worker.ready;
436
+ * const exit = await worker.closed;
437
+ * if (exit.code !== 0) throw new Error("Worker failed");
438
+ * } finally {
439
+ * await worker.terminate();
440
+ * }
441
+ *
442
+ * @see https://maligator.ddv.tools/api/workers#workerData
443
+ */
444
+ export const workerData: unknown;
445
+ }
@@ -0,0 +1,135 @@
1
+ // Generated from src/platform/catalog.ts; edit the catalog and regenerate.
2
+ /**
3
+ * Toolchain-owned worker substrate used by the public source API and Node
4
+ * compatibility personality.
5
+ */
6
+ declare module "maligator:internal/workers" {
7
+ import type * as Workers from "maligator:workers";
8
+ /**
9
+ * Values whose ownership moves when a message is admitted.
10
+ */
11
+ export type Transferable = Workers.Transferable;
12
+
13
+ /**
14
+ * A terminal record. The error is the uncaught value as thrown.
15
+ */
16
+ export type WorkerExit = {
17
+ readonly id: number;
18
+ readonly code: number;
19
+ readonly reason: "completed" | "terminated" | "error";
20
+ readonly error?: unknown;
21
+ };
22
+
23
+ /**
24
+ * A worker's uncaught value as thrown and its own string message, or the empty
25
+ * string.
26
+ */
27
+ export type WorkerErrorEvent = Event & {
28
+ readonly error: unknown;
29
+ readonly message: string;
30
+ };
31
+
32
+ /**
33
+ * A transactional endpoint. postMessage returns the admission ticket, or undefined
34
+ * when nothing was queued; _discard drops a posted message the peer has not
35
+ * received.
36
+ */
37
+ export type MessagePort<Send = unknown, Receive = unknown> = {
38
+ postMessage(value: Send, transfer?: ReadonlyArray<Transferable>): number | undefined;
39
+ _discard(ticket: number): boolean;
40
+ addEventListener(
41
+ type: "message",
42
+ listener: (event: MessageEvent<Receive>) => void | Promise<void>,
43
+ options?: AddEventListenerOptions | boolean,
44
+ ): void;
45
+ onmessage: ((event: MessageEvent<Receive>) => void) | null;
46
+ onmessageerror: ((event: MessageEvent<unknown>) => void) | null;
47
+ start(): void;
48
+ close(): void;
49
+ ref(): MessagePort<Send, Receive>;
50
+ unref(): MessagePort<Send, Receive>;
51
+ hasRef(): boolean;
52
+ } & EventTarget;
53
+
54
+ /**
55
+ * A channel whose first port sends Forward messages and receives Backward messages.
56
+ */
57
+ export type MessageChannel<Forward = unknown, Backward = unknown> = {
58
+ readonly port1: MessagePort<Forward, Backward>;
59
+ readonly port2: MessagePort<Backward, Forward>;
60
+ };
61
+
62
+ /**
63
+ * A source-API worker handle over a transactional parent port.
64
+ */
65
+ export type Worker<Send = unknown, Receive = unknown> = {
66
+ readonly id: number;
67
+ readonly ready: Promise<void>;
68
+ readonly closed: Promise<WorkerExit>;
69
+ readonly port: MessagePort<Send, Receive>;
70
+ addEventListener(
71
+ type: "error",
72
+ listener: (event: WorkerErrorEvent) => void,
73
+ options?: AddEventListenerOptions | boolean,
74
+ ): void;
75
+ terminate(): Promise<WorkerExit>;
76
+ ref(): Worker<Send, Receive>;
77
+ unref(): Worker<Send, Receive>;
78
+ hasRef(): boolean;
79
+ } & EventTarget;
80
+
81
+ /**
82
+ * Start a declared isolated module with a transactional parent port.
83
+ */
84
+ export const Worker: {
85
+ new <Send = unknown, Receive = unknown>(
86
+ entry: { readonly href: string },
87
+ options?: Workers.WorkerOptions,
88
+ ): Worker<Send, Receive>;
89
+ };
90
+ /**
91
+ * Create two transactional endpoints.
92
+ */
93
+ export const MessageChannel: {
94
+ new <Forward = unknown, Backward = unknown>(
95
+ options?: Workers.MessageChannelOptions,
96
+ ): MessageChannel<Forward, Backward>;
97
+ };
98
+ /**
99
+ * The transactional port prototype.
100
+ */
101
+ export const MessagePort: { readonly prototype: MessagePort };
102
+ /**
103
+ * Synchronously dequeue one pending message without running unrelated callbacks.
104
+ */
105
+ export const receiveMessageOnPort: <Receive>(
106
+ port: MessagePort<unknown, Receive>,
107
+ ) => { readonly message: Receive } | undefined;
108
+ /**
109
+ * Report the running host's worker facilities and capacity.
110
+ */
111
+ export const capabilities: typeof Workers.capabilities;
112
+ /**
113
+ * Fail the current worker after its outcome cannot be published.
114
+ */
115
+ export const failCurrent: () => void;
116
+ /**
117
+ * Internal static entry declaration.
118
+ */
119
+ export const createWorkerUrl: (
120
+ specifier: string,
121
+ base: string,
122
+ ) => { readonly href: string };
123
+ /**
124
+ * Isolate-owned worker state.
125
+ */
126
+ export const parentPort: MessagePort | null;
127
+ /**
128
+ * Isolate-owned worker state.
129
+ */
130
+ export const workerData: unknown;
131
+ /**
132
+ * The task-pool bootstrap entry.
133
+ */
134
+ export const poolEntry: { readonly href: string };
135
+ }