@maligator/cli 0.1.0-alpha.3 → 0.1.0-alpha.30

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/test-api.d.ts ADDED
@@ -0,0 +1,230 @@
1
+ // Generated from src/platform/catalog.ts; edit the catalog and regenerate.
2
+ /**
3
+ * Test authoring and assertions. Importing this module does not register tests or
4
+ * install runner globals. Registration and assertions are ordinary effectful calls;
5
+ * the test command initializes its internal runner explicitly. Unused imports can be
6
+ * eliminated.
7
+ */
8
+ declare module "maligator:test" {
9
+ /**
10
+ * A test or hook body. Maligator waits for a returned promise or thenable before
11
+ * advancing the lifecycle.
12
+ *
13
+ * @see https://maligator.ddv.tools/api/test#TestCallback
14
+ */
15
+ export type TestCallback = () => unknown;
16
+
17
+ /**
18
+ * A lifecycle hook body, with the same async completion contract as a test.
19
+ *
20
+ * @see https://maligator.ddv.tools/api/test#HookCallback
21
+ */
22
+ export type HookCallback = TestCallback;
23
+
24
+ /**
25
+ * A constructable value accepted by {@link expect.any}.
26
+ *
27
+ * @see https://maligator.ddv.tools/api/test#Constructor
28
+ */
29
+ export type Constructor = abstract new (...args: Array<never>) => unknown;
30
+
31
+ /**
32
+ * Opaque partial-match value produced by helpers such as {@link
33
+ * expect.objectContaining}. It may be nested inside `toEqual`, `toStrictEqual`, and
34
+ * `toMatchObject` expectations.
35
+ *
36
+ * @see https://maligator.ddv.tools/api/test#AsymmetricMatcher
37
+ */
38
+ export type AsymmetricMatcher = {
39
+ readonly __maligator_asymmetric__: string;
40
+ };
41
+
42
+ /**
43
+ * Matchers for a synchronously received value.
44
+ *
45
+ * @see https://maligator.ddv.tools/api/test#Matchers
46
+ */
47
+ export type Matchers = {
48
+ /** Negate the following matcher. */
49
+ readonly not: Matchers;
50
+ /** Wait for the received promise to fulfill, then match its value. */
51
+ readonly resolves: AsyncMatchers;
52
+ /** Wait for the received promise to reject, then match its reason. */
53
+ readonly rejects: AsyncMatchers;
54
+ /** Require ECMAScript `Object.is` identity. */
55
+ toBe(expected: unknown): void;
56
+ /** Recursively compare enumerable object properties and array elements. */
57
+ toEqual(expected: unknown): void;
58
+ /**
59
+ * Recursively compare values while also requiring matching prototypes and
60
+ * matching sparse-array holes.
61
+ */
62
+ toStrictEqual(expected: unknown): void;
63
+ /** Require a value other than `undefined`. */
64
+ toBeDefined(): void;
65
+ /** Require `undefined`. */
66
+ toBeUndefined(): void;
67
+ /** Require `null`. */
68
+ toBeNull(): void;
69
+ /** Require a truthy value. */
70
+ toBeTruthy(): void;
71
+ /** Require a falsy value. */
72
+ toBeFalsy(): void;
73
+ /** Require a string substring or an array element matched by identity. */
74
+ toContain(expected: unknown): void;
75
+ /** Require a numeric `.length` equal to `expected`. */
76
+ toHaveLength(expected: number): void;
77
+ /** Match a string against a substring or regular expression. */
78
+ toMatch(expected: string | RegExp): void;
79
+ /** Recursively require the enumerable properties present in `expected`. */
80
+ toMatchObject(expected: object): void;
81
+ /**
82
+ * Invoke the received function and require it to throw. The optional
83
+ * expectation may be a message substring, regular expression, error
84
+ * constructor, or error instance.
85
+ */
86
+ toThrow(
87
+ expected?:
88
+ | string
89
+ | RegExp
90
+ | Error
91
+ | (abstract new (...args: Array<never>) => Error),
92
+ ): void;
93
+ };
94
+
95
+ /**
96
+ * Promise-returning matcher surface exposed by {@link Matchers.resolves} and {@link
97
+ * Matchers.rejects}. Await these calls so the test cannot finish before the
98
+ * assertion.
99
+ *
100
+ * @see https://maligator.ddv.tools/api/test#AsyncMatchers
101
+ */
102
+ export type AsyncMatchers = {
103
+ /** Negate the following asynchronous matcher. */
104
+ readonly not: AsyncMatchers;
105
+ toBe(expected: unknown): Promise<void>;
106
+ toEqual(expected: unknown): Promise<void>;
107
+ toStrictEqual(expected: unknown): Promise<void>;
108
+ toBeDefined(): Promise<void>;
109
+ toBeUndefined(): Promise<void>;
110
+ toBeNull(): Promise<void>;
111
+ toBeTruthy(): Promise<void>;
112
+ toBeFalsy(): Promise<void>;
113
+ toContain(expected: unknown): Promise<void>;
114
+ toHaveLength(expected: number): Promise<void>;
115
+ toMatch(expected: string | RegExp): Promise<void>;
116
+ toMatchObject(expected: object): Promise<void>;
117
+ toThrow(
118
+ expected?:
119
+ | string
120
+ | RegExp
121
+ | Error
122
+ | (abstract new (...args: Array<never>) => Error),
123
+ ): Promise<void>;
124
+ };
125
+
126
+ /**
127
+ * Assertion entrypoint and Maligator-owned asymmetric matcher factories.
128
+ *
129
+ * @see https://maligator.ddv.tools/api/test#ExpectFunction
130
+ */
131
+ export type ExpectFunction = {
132
+ /** Create matchers for `received`. The assertion position is captured here. */
133
+ (received: unknown): Matchers;
134
+ /** Match a primitive of the corresponding built-in kind or an instance. */
135
+ any(constructorValue: Constructor): AsymmetricMatcher;
136
+ /** Match any value except `null` and `undefined`. */
137
+ anything(): AsymmetricMatcher;
138
+ /** Match a string containing `pattern` or satisfying the regular expression. */
139
+ stringMatching(pattern: string | RegExp): AsymmetricMatcher;
140
+ /** Match an object containing all recursively matched properties in `value`. */
141
+ objectContaining(value: object): AsymmetricMatcher;
142
+ /** Match an array containing a match for every element in `value`. */
143
+ arrayContaining(value: Array<unknown>): AsymmetricMatcher;
144
+ };
145
+
146
+ /**
147
+ * Register tests in the current suite during module evaluation.
148
+ *
149
+ * @see https://maligator.ddv.tools/api/test#TestFunction
150
+ */
151
+ export type TestFunction = {
152
+ /** Register a test. Returned promises are awaited by the runner. */
153
+ (name: string, callback: TestCallback): void;
154
+ /** Register a skipped test without invoking its callback. */
155
+ skip(name: string, callback: TestCallback): void;
156
+ /** Register a named placeholder with no callback. */
157
+ todo(name: string): void;
158
+ /**
159
+ * Register a focused test. When any `.only` exists, non-focused tests are
160
+ * skipped and the runner emits a warning.
161
+ */
162
+ only(name: string, callback: TestCallback): void;
163
+ /**
164
+ * Register one test for each row. Use `%#` in `name` for the zero-based row
165
+ * index. Array rows are spread into callback parameters.
166
+ */
167
+ each<const Row extends ReadonlyArray<unknown>>(
168
+ rows: ReadonlyArray<Row>,
169
+ ): (name: string, callback: (...values: [...Row]) => unknown) => void;
170
+ };
171
+
172
+ /**
173
+ * Register nested suites synchronously during module evaluation.
174
+ *
175
+ * @see https://maligator.ddv.tools/api/test#DescribeFunction
176
+ */
177
+ export type DescribeFunction = {
178
+ /** Register a suite. Suite callbacks must not return a promise. */
179
+ (name: string, callback: () => void): void;
180
+ /** Register a suite whose descendants are skipped. */
181
+ skip(name: string, callback: () => void): void;
182
+ /** Register a focused suite and emit the runner's focused-test warning. */
183
+ only(name: string, callback: () => void): void;
184
+ };
185
+
186
+ /**
187
+ * Register a test in the current suite.
188
+ *
189
+ * @see https://maligator.ddv.tools/api/test#test
190
+ */
191
+ export const test: TestFunction;
192
+ /**
193
+ * Register a nested suite in the current suite.
194
+ *
195
+ * @see https://maligator.ddv.tools/api/test#describe
196
+ */
197
+ export const describe: DescribeFunction;
198
+ /**
199
+ * Create fluent matchers for a received value.
200
+ *
201
+ * @see https://maligator.ddv.tools/api/test#expect
202
+ */
203
+ export const expect: ExpectFunction;
204
+ /**
205
+ * Run once before tests in the current suite.
206
+ *
207
+ * @see https://maligator.ddv.tools/api/test#beforeAll
208
+ */
209
+ export const beforeAll: (callback: HookCallback) => void;
210
+ /**
211
+ * Run once after tests in the current suite, including after test failures.
212
+ *
213
+ * @see https://maligator.ddv.tools/api/test#afterAll
214
+ */
215
+ export const afterAll: (callback: HookCallback) => void;
216
+ /**
217
+ * Run before every selected descendant test. Ancestor hooks run before hooks
218
+ * declared by a nested suite.
219
+ *
220
+ * @see https://maligator.ddv.tools/api/test#beforeEach
221
+ */
222
+ export const beforeEach: (callback: HookCallback) => void;
223
+ /**
224
+ * Run after every selected descendant test. Nested-suite hooks run before ancestor
225
+ * hooks.
226
+ *
227
+ * @see https://maligator.ddv.tools/api/test#afterEach
228
+ */
229
+ export const afterEach: (callback: HookCallback) => void;
230
+ }
@@ -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
+ }