/** * CSP-safe module workers. * * `defineWorker()` / `defineRpcWorker()` describe a pre-bundled worker script by * URL on the main thread; `exposeTask()` / `exposeRpc()` wire that script up to * the bQuery worker protocol inside the worker. Because the worker body is a * real module loaded by URL — never a serialized function revived with * `new Function(...)` — this path runs under a strict Content-Security-Policy * without `'unsafe-eval'` or a `blob:` worker source. * * @module bquery/concurrency */ import type { DefineWorkerOptions, RpcWorkerModule, WorkerHostScope, WorkerModule, WorkerRpcHandlers, WorkerTaskHandler } from './types'; /** * Describes a CSP-safe task worker module addressed by URL. * * @example * ```ts * import { defineWorker, createTaskWorker } from '@bquery/bquery/concurrency'; * * const heavy = defineWorker(new URL('./heavy.worker.ts', import.meta.url)); * const worker = createTaskWorker(heavy); * const result = await worker.run(21); * worker.terminate(); * ``` */ export declare function defineWorker(url: string | URL, options?: DefineWorkerOptions): WorkerModule; /** * Describes a CSP-safe RPC worker module addressed by URL. * * @example * ```ts * import { defineRpcWorker, createRpcWorker } from '@bquery/bquery/concurrency'; * * type Routes = { sum(input: { values: number[] }): number }; * const calc = defineRpcWorker(new URL('./calc.worker.ts', import.meta.url)); * const rpc = createRpcWorker(calc); * const total = await rpc.call('sum', { values: [1, 2, 3] }); * rpc.terminate(); * ``` */ export declare function defineRpcWorker(url: string | URL, options?: DefineWorkerOptions): RpcWorkerModule; /** * Returns `true` when a value is a {@link WorkerModule} / {@link RpcWorkerModule} * produced by `defineWorker()` / `defineRpcWorker()`. */ export declare function isWorkerModule(value: unknown): value is WorkerModule | RpcWorkerModule; /** * Wires a standalone handler into the bQuery worker protocol from inside a * module worker. Pairs with `createTaskWorker(defineWorker(...))` on the main * thread. * * @example * ```ts * // heavy.worker.ts * import { exposeTask } from '@bquery/bquery/concurrency'; * * exposeTask((value: number) => value * value); * ``` * * @param handler - Worker-side task handler * @param scope - Worker global scope; defaults to the ambient worker `self` */ export declare function exposeTask(handler: WorkerTaskHandler, scope?: WorkerHostScope): void; /** * Wires a map of named RPC handlers into the bQuery worker protocol from inside * a module worker. Pairs with `createRpcWorker(defineRpcWorker(...))` on the * main thread. * * @example * ```ts * // calc.worker.ts * import { exposeRpc } from '@bquery/bquery/concurrency'; * * exposeRpc({ * sum: ({ values }: { values: number[] }) => values.reduce((a, b) => a + b, 0), * }); * ``` * * @param handlers - Worker-side RPC handler map * @param scope - Worker global scope; defaults to the ambient worker `self` */ export declare function exposeRpc(handlers: TRoutes, scope?: WorkerHostScope): void; //# sourceMappingURL=module-worker.d.ts.map