knitting 0.1.55 → 0.1.56
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/knitting.d.ts +6 -797
- package/knitting.js +6 -9780
- package/map.md +12 -8
- package/package.json +14 -6
- package/process-shared-buffer.d.ts +1 -0
- package/process-shared-buffer.js +1 -0
- package/shared-memory.d.ts +1 -155
- package/shared-memory.js +1 -1342
- package/src/api.d.ts +69 -0
- package/src/api.js +619 -0
- package/src/common/envelope.d.ts +17 -0
- package/src/common/envelope.js +22 -0
- package/src/common/module-url.d.ts +1 -0
- package/src/common/module-url.js +24 -0
- package/src/common/node-compat.d.ts +20 -0
- package/src/common/node-compat.js +24 -0
- package/src/common/path-canonical.d.ts +6 -0
- package/src/common/path-canonical.js +41 -0
- package/src/common/runtime.d.ts +15 -0
- package/src/common/runtime.js +91 -0
- package/src/common/shared-buffer-region.d.ts +11 -0
- package/src/common/shared-buffer-region.js +21 -0
- package/src/common/shared-buffer-text.d.ts +16 -0
- package/src/common/shared-buffer-text.js +65 -0
- package/src/common/task-source.d.ts +3 -0
- package/src/common/task-source.js +84 -0
- package/src/common/task-symbol.d.ts +1 -0
- package/src/common/task-symbol.js +1 -0
- package/src/common/with-resolvers.d.ts +9 -0
- package/src/common/with-resolvers.js +23 -0
- package/src/common/worker-runtime.d.ts +42 -0
- package/src/common/worker-runtime.js +61 -0
- package/src/connections/buffer-reference-native.d.ts +56 -0
- package/src/connections/buffer-reference-native.js +217 -0
- package/src/connections/buffer-reference.d.ts +78 -0
- package/src/connections/buffer-reference.js +461 -0
- package/src/connections/bun.d.ts +22 -0
- package/src/connections/bun.js +214 -0
- package/src/connections/deno.d.ts +22 -0
- package/src/connections/deno.js +205 -0
- package/src/connections/file-descriptor.d.ts +39 -0
- package/src/connections/file-descriptor.js +161 -0
- package/src/connections/index.d.ts +4 -0
- package/src/connections/index.js +4 -0
- package/src/connections/node-addons.d.ts +5 -0
- package/src/connections/node-addons.js +44 -0
- package/src/connections/node-buffer-pointer.d.ts +20 -0
- package/src/connections/node-buffer-pointer.js +16 -0
- package/src/connections/node.d.ts +30 -0
- package/src/connections/node.js +62 -0
- package/src/connections/numeric-array.d.ts +5 -0
- package/src/connections/numeric-array.js +17 -0
- package/src/connections/package-assets.d.ts +2 -0
- package/src/connections/package-assets.js +45 -0
- package/src/connections/posix.d.ts +32 -0
- package/src/connections/posix.js +77 -0
- package/src/connections/process-shared-buffer.d.ts +75 -0
- package/src/connections/process-shared-buffer.js +279 -0
- package/src/connections/shared-array-buffer-payload.d.ts +36 -0
- package/src/connections/shared-array-buffer-payload.js +235 -0
- package/src/connections/types.d.ts +50 -0
- package/src/connections/types.js +37 -0
- package/src/connections/windows.d.ts +28 -0
- package/src/connections/windows.js +224 -0
- package/src/debug/env-diff.d.ts +26 -0
- package/src/debug/env-diff.js +49 -0
- package/src/debug/gate.d.ts +18 -0
- package/src/debug/gate.js +69 -0
- package/src/debug/handle.d.ts +23 -0
- package/src/debug/handle.js +48 -0
- package/src/error.d.ts +13 -0
- package/src/error.js +49 -0
- package/src/ipc/tools/ring-queue.d.ts +33 -0
- package/src/ipc/tools/ring-queue.js +159 -0
- package/src/ipc/transport/shared-memory.d.ts +23 -0
- package/src/ipc/transport/shared-memory.js +35 -0
- package/src/memory/byte-carpet.d.ts +73 -0
- package/src/memory/byte-carpet.js +157 -0
- package/src/memory/lock.d.ts +203 -0
- package/src/memory/lock.js +741 -0
- package/src/memory/payload-config.d.ts +31 -0
- package/src/memory/payload-config.js +67 -0
- package/src/memory/payloadCodec.d.ts +46 -0
- package/src/memory/payloadCodec.js +1377 -0
- package/src/memory/regionRegistry.d.ts +17 -0
- package/src/memory/regionRegistry.js +285 -0
- package/src/memory/shared-buffer-io.d.ts +55 -0
- package/src/memory/shared-buffer-io.js +403 -0
- package/src/permission/index.d.ts +2 -0
- package/src/permission/index.js +2 -0
- package/src/permission/protocol.d.ts +166 -0
- package/src/permission/protocol.js +650 -0
- package/src/runtime/balancer.d.ts +19 -0
- package/src/runtime/balancer.js +149 -0
- package/src/runtime/dispatcher.d.ts +40 -0
- package/src/runtime/dispatcher.js +142 -0
- package/src/runtime/inline-executor.d.ts +10 -0
- package/src/runtime/inline-executor.js +282 -0
- package/src/runtime/pool.d.ts +39 -0
- package/src/runtime/pool.js +404 -0
- package/src/runtime/process-worker.d.ts +92 -0
- package/src/runtime/process-worker.js +673 -0
- package/src/runtime/tx-queue.d.ts +26 -0
- package/src/runtime/tx-queue.js +155 -0
- package/src/shared/abortSignal.d.ts +23 -0
- package/src/shared/abortSignal.js +134 -0
- package/src/types.d.ts +357 -0
- package/src/types.js +2 -0
- package/src/utils/http.d.ts +29 -0
- package/src/utils/http.js +100 -0
- package/src/worker/bootstrap.d.ts +5 -0
- package/src/worker/bootstrap.js +78 -0
- package/src/worker/composable-runners.d.ts +12 -0
- package/src/worker/composable-runners.js +97 -0
- package/src/worker/loop.d.ts +2 -0
- package/src/worker/loop.js +382 -0
- package/src/worker/process-worker-bootstrap.d.ts +8 -0
- package/src/worker/process-worker-bootstrap.js +160 -0
- package/src/worker/rx-queue.d.ts +25 -0
- package/src/worker/rx-queue.js +173 -0
- package/src/worker/safety/index.d.ts +4 -0
- package/src/worker/safety/index.js +4 -0
- package/src/worker/safety/performance.d.ts +1 -0
- package/src/worker/safety/performance.js +17 -0
- package/src/worker/safety/process.d.ts +2 -0
- package/src/worker/safety/process.js +79 -0
- package/src/worker/safety/startup.d.ts +16 -0
- package/src/worker/safety/startup.js +30 -0
- package/src/worker/safety/worker-data.d.ts +2 -0
- package/src/worker/safety/worker-data.js +36 -0
- package/src/worker/task-loader.d.ts +27 -0
- package/src/worker/task-loader.js +70 -0
- package/src/worker/timers.d.ts +18 -0
- package/src/worker/timers.js +116 -0
- package/unsafe.d.ts +1 -71
- package/unsafe.js +1 -878
- package/utils.d.ts +1 -31
- package/utils.js +1 -116
package/knitting.d.ts
CHANGED
|
@@ -1,797 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type
|
|
7
|
-
pointerLow: number,
|
|
8
|
-
pointerHigh: number,
|
|
9
|
-
tokenLow: number,
|
|
10
|
-
tokenHigh: number,
|
|
11
|
-
byteOffset: number,
|
|
12
|
-
byteLength: number,
|
|
13
|
-
runtime: number,
|
|
14
|
-
originPid: number
|
|
15
|
-
];
|
|
16
|
-
type BufferReferenceMetadata = {
|
|
17
|
-
readonly kind: typeof BUFFER_REFERENCE_KIND;
|
|
18
|
-
readonly origin: string;
|
|
19
|
-
readonly runtime: BufferReferenceRuntime;
|
|
20
|
-
readonly pointer: string;
|
|
21
|
-
/** Producer-side release handle (process-local). */
|
|
22
|
-
readonly token: string;
|
|
23
|
-
readonly byteOffset: number;
|
|
24
|
-
readonly byteLength: number;
|
|
25
|
-
};
|
|
26
|
-
type BufferReferenceReturnReleaser = (token: bigint) => void;
|
|
27
|
-
type BufferSource$1 = ArrayBufferView | ArrayBuffer;
|
|
28
|
-
declare const PAYLOAD_TRANSPORT_FINALIZER: unique symbol;
|
|
29
|
-
declare class BufferReference {
|
|
30
|
-
#private;
|
|
31
|
-
readonly [EXTERNAL_PAYLOAD_BRAND]: "knitting.bufferReference";
|
|
32
|
-
readonly runtime: BufferReferenceRuntime;
|
|
33
|
-
readonly origin: string;
|
|
34
|
-
readonly pointer: bigint;
|
|
35
|
-
readonly byteOffset: number;
|
|
36
|
-
readonly byteLength: number;
|
|
37
|
-
constructor(source: BufferSource$1);
|
|
38
|
-
constructor(source: BufferSource$1 | undefined, meta: BufferReferenceMetadata);
|
|
39
|
-
static fromMetadata(meta: BufferReferenceMetadata): BufferReference;
|
|
40
|
-
toMetadata(): BufferReferenceMetadata;
|
|
41
|
-
[BUFFER_REFERENCE_NUMERIC_TRANSFER](): BufferReferenceNumericMetadata | undefined;
|
|
42
|
-
get isLocal(): boolean;
|
|
43
|
-
/** Prepare a returned reference before the worker-side producer hold drains. */
|
|
44
|
-
claimOwnership(releaser?: BufferReferenceReturnReleaser): this;
|
|
45
|
-
toArrayBuffer(): ArrayBuffer;
|
|
46
|
-
toUint8Array(): Uint8Array;
|
|
47
|
-
/** The source is moved on construction, so it is never retained here. */
|
|
48
|
-
get source(): undefined;
|
|
49
|
-
release(): void;
|
|
50
|
-
[Symbol.dispose](): void;
|
|
51
|
-
[PAYLOAD_TRANSPORT_FINALIZER](): (() => void) | undefined;
|
|
52
|
-
}
|
|
53
|
-
type SharedBuffer = SharedArrayBuffer | ArrayBuffer;
|
|
54
|
-
type SharedBufferRegion = {
|
|
55
|
-
sab: SharedBuffer;
|
|
56
|
-
byteOffset: number;
|
|
57
|
-
byteLength: number;
|
|
58
|
-
};
|
|
59
|
-
type SharedBufferSource = SharedBuffer | SharedBufferRegion;
|
|
60
|
-
type ConnectionRuntime = "node" | "deno" | "bun";
|
|
61
|
-
type SharedMemoryBuffer = ArrayBuffer | SharedArrayBuffer;
|
|
62
|
-
type SharedMemoryBufferKind = "shared-array-buffer" | "external-array-buffer";
|
|
63
|
-
type SharedMemoryCreateMode = "anonymous" | "create" | "open";
|
|
64
|
-
type SharedMemoryMapping<Buffer extends SharedMemoryBuffer = SharedMemoryBuffer> = {
|
|
65
|
-
runtime: ConnectionRuntime;
|
|
66
|
-
fd: number;
|
|
67
|
-
name?: string;
|
|
68
|
-
size: number;
|
|
69
|
-
byteLength: number;
|
|
70
|
-
buffer: Buffer;
|
|
71
|
-
kind: SharedMemoryBufferKind;
|
|
72
|
-
sab?: SharedArrayBuffer;
|
|
73
|
-
arrayBuffer?: ArrayBuffer;
|
|
74
|
-
baseAddressMod64?: number;
|
|
75
|
-
unsafePointer?: unknown;
|
|
76
|
-
close?: () => void;
|
|
77
|
-
};
|
|
78
|
-
type CreateSharedMemoryOptions = {
|
|
79
|
-
size: number;
|
|
80
|
-
/**
|
|
81
|
-
* `anonymous` keeps the current fd-backed private mapping behavior.
|
|
82
|
-
* `create` and `open` use a named shared-memory object so independent
|
|
83
|
-
* processes can rendezvous by name.
|
|
84
|
-
*/
|
|
85
|
-
mode?: SharedMemoryCreateMode;
|
|
86
|
-
name?: string;
|
|
87
|
-
};
|
|
88
|
-
type MapSharedMemoryOptions = {
|
|
89
|
-
fd: number;
|
|
90
|
-
name?: string;
|
|
91
|
-
size: number;
|
|
92
|
-
duplicateFd?: boolean;
|
|
93
|
-
};
|
|
94
|
-
type SharedMemoryConnectionPrimitives<Mapping extends SharedMemoryMapping = SharedMemoryMapping> = {
|
|
95
|
-
runtime: ConnectionRuntime;
|
|
96
|
-
createSharedMemory: (options: number | CreateSharedMemoryOptions) => Mapping;
|
|
97
|
-
mapSharedMemory: (options: MapSharedMemoryOptions) => Mapping;
|
|
98
|
-
unlinkSharedMemory?: (name: string) => boolean;
|
|
99
|
-
};
|
|
100
|
-
type FileDescriptorMetadata = {
|
|
101
|
-
version: 1;
|
|
102
|
-
fd: number;
|
|
103
|
-
name?: string;
|
|
104
|
-
size: number;
|
|
105
|
-
byteLength: number;
|
|
106
|
-
runtime?: ConnectionRuntime;
|
|
107
|
-
kind?: SharedMemoryMapping["kind"];
|
|
108
|
-
baseAddressMod64?: number;
|
|
109
|
-
};
|
|
110
|
-
type FileDescriptorMapper = Pick<SharedMemoryConnectionPrimitives, "mapSharedMemory">;
|
|
111
|
-
declare class FileDescriptor {
|
|
112
|
-
#private;
|
|
113
|
-
readonly fd: number;
|
|
114
|
-
readonly name?: string;
|
|
115
|
-
readonly size: number;
|
|
116
|
-
readonly byteLength: number;
|
|
117
|
-
readonly runtime?: ConnectionRuntime;
|
|
118
|
-
readonly kind?: SharedMemoryMapping["kind"];
|
|
119
|
-
readonly baseAddressMod64?: number;
|
|
120
|
-
constructor(metadata: FileDescriptorMetadata, mapping?: SharedMemoryMapping);
|
|
121
|
-
static fromMapping(mapping: SharedMemoryMapping): FileDescriptor;
|
|
122
|
-
static fromMetadata(metadata: unknown): FileDescriptor;
|
|
123
|
-
static parse(serialized: string): FileDescriptor;
|
|
124
|
-
toMetadata(): FileDescriptorMetadata;
|
|
125
|
-
toJSON(): FileDescriptorMetadata;
|
|
126
|
-
stringify(): string;
|
|
127
|
-
stringifyMetadata(): string;
|
|
128
|
-
toString(): string;
|
|
129
|
-
attach(mapping: SharedMemoryMapping): this;
|
|
130
|
-
get mapping(): SharedMemoryMapping | undefined;
|
|
131
|
-
map(mapper: FileDescriptorMapper): SharedMemoryMapping;
|
|
132
|
-
getBuffer(mapper?: FileDescriptorMapper): SharedMemoryBuffer;
|
|
133
|
-
getSharedArrayBuffer(mapper?: FileDescriptorMapper): SharedArrayBuffer;
|
|
134
|
-
getSAB(mapper?: FileDescriptorMapper): SharedArrayBuffer;
|
|
135
|
-
}
|
|
136
|
-
type ProcessSharedBufferMetadata = {
|
|
137
|
-
version: 1;
|
|
138
|
-
descriptor: FileDescriptorMetadata;
|
|
139
|
-
byteOffset: number;
|
|
140
|
-
byteLength: number;
|
|
141
|
-
};
|
|
142
|
-
declare const PROCESS_SHARED_BUFFER_BRAND: unique symbol;
|
|
143
|
-
declare const PROCESS_SHARED_BUFFER_NUMERIC_TRANSFER: unique symbol;
|
|
144
|
-
declare const EXTERNAL_PAYLOAD_BRAND$1: unique symbol;
|
|
145
|
-
type ProcessSharedBufferNumericMetadata = readonly [
|
|
146
|
-
fd: number,
|
|
147
|
-
size: number,
|
|
148
|
-
descriptorByteLength: number,
|
|
149
|
-
byteOffset: number,
|
|
150
|
-
byteLength: number,
|
|
151
|
-
runtime: number,
|
|
152
|
-
kind: number,
|
|
153
|
-
baseAddressMod64: number
|
|
154
|
-
];
|
|
155
|
-
type ProcessSharedBufferRange = {
|
|
156
|
-
byteOffset?: number;
|
|
157
|
-
byteLength?: number;
|
|
158
|
-
};
|
|
159
|
-
type ProcessSharedBufferCreator = Pick<SharedMemoryConnectionPrimitives, "createSharedMemory">;
|
|
160
|
-
type ProcessSharedBufferMapper = Pick<SharedMemoryConnectionPrimitives, "mapSharedMemory">;
|
|
161
|
-
type ProcessSharedBufferView = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | BigInt64Array | BigUint64Array | Float32Array | Float64Array;
|
|
162
|
-
type ProcessSharedBufferViewConstructor<View extends ProcessSharedBufferView = ProcessSharedBufferView> = {
|
|
163
|
-
readonly BYTES_PER_ELEMENT: number;
|
|
164
|
-
new (buffer: SharedBuffer, byteOffset: number, length: number): View;
|
|
165
|
-
};
|
|
166
|
-
declare class ProcessSharedBuffer {
|
|
167
|
-
readonly [PROCESS_SHARED_BUFFER_BRAND] = true;
|
|
168
|
-
readonly [EXTERNAL_PAYLOAD_BRAND$1] = "knitting.processSharedBuffer";
|
|
169
|
-
readonly descriptor: FileDescriptor;
|
|
170
|
-
readonly byteOffset: number;
|
|
171
|
-
readonly byteLength: number;
|
|
172
|
-
constructor(descriptor: FileDescriptor, range?: ProcessSharedBufferRange);
|
|
173
|
-
static create(options: number | CreateSharedMemoryOptions, creator?: ProcessSharedBufferCreator): ProcessSharedBuffer;
|
|
174
|
-
static fromMapping(mapping: SharedMemoryMapping): ProcessSharedBuffer;
|
|
175
|
-
static fromDescriptor(descriptor: FileDescriptor, range?: ProcessSharedBufferRange): ProcessSharedBuffer;
|
|
176
|
-
static fromMetadata(metadata: unknown): ProcessSharedBuffer;
|
|
177
|
-
static parse(serialized: string): ProcessSharedBuffer;
|
|
178
|
-
static [PROCESS_SHARED_BUFFER_NUMERIC_TRANSFER](metadata: ProcessSharedBufferNumericMetadata): ProcessSharedBuffer;
|
|
179
|
-
get fd(): number;
|
|
180
|
-
get size(): number;
|
|
181
|
-
subbuffer(byteOffset: number, byteLength?: number): ProcessSharedBuffer;
|
|
182
|
-
getSharedArrayBuffer(mapper?: ProcessSharedBufferMapper): SharedArrayBuffer;
|
|
183
|
-
getSAB(mapper?: ProcessSharedBufferMapper): SharedArrayBuffer;
|
|
184
|
-
getBuffer(mapper?: ProcessSharedBufferMapper): SharedBuffer;
|
|
185
|
-
getRegion(mapper?: ProcessSharedBufferMapper): SharedBufferRegion;
|
|
186
|
-
view<View extends ProcessSharedBufferView>(constructor: ProcessSharedBufferViewConstructor<View>, mapper?: ProcessSharedBufferMapper): View;
|
|
187
|
-
bytes(mapper?: ProcessSharedBufferMapper): Uint8Array;
|
|
188
|
-
dataView(mapper?: ProcessSharedBufferMapper): DataView;
|
|
189
|
-
toMetadata(): ProcessSharedBufferMetadata;
|
|
190
|
-
toJSON(): ProcessSharedBufferMetadata;
|
|
191
|
-
stringify(): string;
|
|
192
|
-
stringifyMetadata(): string;
|
|
193
|
-
toString(): string;
|
|
194
|
-
}
|
|
195
|
-
type EnvelopeHeaderPrimitive = string | number | boolean | null;
|
|
196
|
-
type EnvelopeHeaderValue = EnvelopeHeaderPrimitive | EnvelopeHeaderValue[] | {
|
|
197
|
-
[key: string]: EnvelopeHeaderValue;
|
|
198
|
-
};
|
|
199
|
-
export type EnvelopeHeader = EnvelopeHeaderValue;
|
|
200
|
-
export type EnvelopeBody = ArrayBuffer | SharedArrayBuffer | BufferReference | ProcessSharedBuffer;
|
|
201
|
-
declare const PayloadTransportFinalizer: unique symbol;
|
|
202
|
-
export declare class Envelope<H extends EnvelopeHeader = EnvelopeHeader, B extends EnvelopeBody = ArrayBuffer> {
|
|
203
|
-
readonly header: H;
|
|
204
|
-
readonly payload: B;
|
|
205
|
-
constructor(header: H, payload: B);
|
|
206
|
-
[Symbol.dispose](): void;
|
|
207
|
-
[PayloadTransportFinalizer](): (() => void) | undefined;
|
|
208
|
-
}
|
|
209
|
-
type SharedBufferTextCompat = {
|
|
210
|
-
encodeInto: boolean;
|
|
211
|
-
decode: boolean;
|
|
212
|
-
};
|
|
213
|
-
type LockBufferTextCompat = {
|
|
214
|
-
headers: SharedBufferTextCompat;
|
|
215
|
-
payload: SharedBufferTextCompat;
|
|
216
|
-
};
|
|
217
|
-
type PayloadBufferMode = "growable" | "fixed";
|
|
218
|
-
type PayloadBufferOptions = {
|
|
219
|
-
/** Shared payload buffer mode. Defaults to growable when available. */
|
|
220
|
-
mode?: PayloadBufferMode;
|
|
221
|
-
/** Initial shared payload bytes per direction. Defaults to 4 MiB when growable. */
|
|
222
|
-
payloadInitialBytes?: number;
|
|
223
|
-
/** Shared payload growth cap. Defaults to 64 MiB. */
|
|
224
|
-
payloadMaxByteLength?: number;
|
|
225
|
-
/**
|
|
226
|
-
* Max dynamic payload bytes for one call. Defaults to `payloadMaxByteLength >> 3`
|
|
227
|
-
* (about 8 MiB by default) and must stay `<= payloadMaxByteLength >> 3`.
|
|
228
|
-
* Over-cap payloads reject with `KNT_ERROR_3`.
|
|
229
|
-
*/
|
|
230
|
-
maxPayloadBytes?: number;
|
|
231
|
-
};
|
|
232
|
-
type PermissionPath = string | URL;
|
|
233
|
-
type NodePermissionSettings = {
|
|
234
|
-
allowWorker?: boolean;
|
|
235
|
-
allowChildProcess?: boolean;
|
|
236
|
-
allowAddons?: boolean;
|
|
237
|
-
allowWasi?: boolean;
|
|
238
|
-
};
|
|
239
|
-
type DenoPermissionSettings = {
|
|
240
|
-
lock?: boolean | PermissionPath;
|
|
241
|
-
frozen?: boolean;
|
|
242
|
-
/**
|
|
243
|
-
* Legacy compatibility: superseded by top-level `run`.
|
|
244
|
-
*/
|
|
245
|
-
allowRun?: boolean;
|
|
246
|
-
};
|
|
247
|
-
type SysApiName = "hostname" | "osRelease" | "osUptime" | "loadavg" | "networkInterfaces" | "systemMemoryInfo" | "uid" | "gid";
|
|
248
|
-
type PermissionEnvironment = {
|
|
249
|
-
allow?: string[] | true;
|
|
250
|
-
deny?: string[];
|
|
251
|
-
files?: PermissionPath | PermissionPath[];
|
|
252
|
-
};
|
|
253
|
-
type PermissionMode = "strict" | "unsafe" | "custom";
|
|
254
|
-
type PermissionLegacyMode = "off";
|
|
255
|
-
type PermissionProtocol = {
|
|
256
|
-
/**
|
|
257
|
-
* `strict` = hardened defaults, `unsafe` = full access,
|
|
258
|
-
* `custom` = strict baseline with user overrides.
|
|
259
|
-
*/
|
|
260
|
-
mode?: PermissionMode;
|
|
261
|
-
/**
|
|
262
|
-
* Console access for worker task code.
|
|
263
|
-
* Defaults to `false` in strict/custom mode, `true` in unsafe mode.
|
|
264
|
-
*/
|
|
265
|
-
console?: boolean;
|
|
266
|
-
/**
|
|
267
|
-
* Base directory used to resolve relative paths.
|
|
268
|
-
* Defaults to the current shell working directory.
|
|
269
|
-
*/
|
|
270
|
-
cwd?: string;
|
|
271
|
-
/**
|
|
272
|
-
* Read allow-list. `true` means unrestricted access.
|
|
273
|
-
*/
|
|
274
|
-
read?: PermissionPath[] | true;
|
|
275
|
-
/**
|
|
276
|
-
* Write allow-list. `true` means unrestricted access.
|
|
277
|
-
*/
|
|
278
|
-
write?: PermissionPath[] | true;
|
|
279
|
-
/**
|
|
280
|
-
* Explicit deny-read entries.
|
|
281
|
-
*/
|
|
282
|
-
denyRead?: PermissionPath[];
|
|
283
|
-
/**
|
|
284
|
-
* Explicit deny-write entries.
|
|
285
|
-
*/
|
|
286
|
-
denyWrite?: PermissionPath[];
|
|
287
|
-
/**
|
|
288
|
-
* Network allow-list. `true` means unrestricted access.
|
|
289
|
-
*/
|
|
290
|
-
net?: string[] | true;
|
|
291
|
-
/**
|
|
292
|
-
* Explicit network deny-list.
|
|
293
|
-
*/
|
|
294
|
-
denyNet?: string[];
|
|
295
|
-
/**
|
|
296
|
-
* Allowed import hostnames. `true` means unrestricted import hosts.
|
|
297
|
-
*/
|
|
298
|
-
allowImport?: string[] | true;
|
|
299
|
-
/**
|
|
300
|
-
* Environment permission settings.
|
|
301
|
-
*/
|
|
302
|
-
env?: PermissionEnvironment;
|
|
303
|
-
/**
|
|
304
|
-
* Subprocess allow-list. `true` means unrestricted access.
|
|
305
|
-
*/
|
|
306
|
-
run?: string[] | true;
|
|
307
|
-
/**
|
|
308
|
-
* Explicit subprocess deny-list.
|
|
309
|
-
*/
|
|
310
|
-
denyRun?: string[];
|
|
311
|
-
/**
|
|
312
|
-
* Whether worker spawning is allowed.
|
|
313
|
-
*/
|
|
314
|
-
workers?: boolean;
|
|
315
|
-
/**
|
|
316
|
-
* FFI allow-list or toggle.
|
|
317
|
-
*/
|
|
318
|
-
ffi?: PermissionPath[] | boolean;
|
|
319
|
-
/**
|
|
320
|
-
* Explicit FFI deny-list.
|
|
321
|
-
*/
|
|
322
|
-
denyFfi?: PermissionPath[];
|
|
323
|
-
/**
|
|
324
|
-
* System API allow-list. `true` means unrestricted access.
|
|
325
|
-
*/
|
|
326
|
-
sys?: SysApiName[] | true;
|
|
327
|
-
/**
|
|
328
|
-
* Explicit system API deny-list.
|
|
329
|
-
*/
|
|
330
|
-
denySys?: SysApiName[];
|
|
331
|
-
/**
|
|
332
|
-
* Whether WASI is allowed.
|
|
333
|
-
*/
|
|
334
|
-
wasi?: boolean;
|
|
335
|
-
/**
|
|
336
|
-
* Backward-compat runtime overrides.
|
|
337
|
-
*/
|
|
338
|
-
node?: NodePermissionSettings;
|
|
339
|
-
deno?: DenoPermissionSettings;
|
|
340
|
-
};
|
|
341
|
-
type PermissionProtocolInput = PermissionMode | PermissionLegacyMode | PermissionProtocol;
|
|
342
|
-
type L3RuntimeKeys = {
|
|
343
|
-
deno: string[];
|
|
344
|
-
node: string[];
|
|
345
|
-
};
|
|
346
|
-
type ResolvedPermissionProtocol = {
|
|
347
|
-
enabled: boolean;
|
|
348
|
-
mode: PermissionMode;
|
|
349
|
-
unsafe: boolean;
|
|
350
|
-
allowConsole: boolean;
|
|
351
|
-
cwd: string;
|
|
352
|
-
read: string[];
|
|
353
|
-
readAll: boolean;
|
|
354
|
-
write: string[];
|
|
355
|
-
writeAll: boolean;
|
|
356
|
-
denyRead: string[];
|
|
357
|
-
denyWrite: string[];
|
|
358
|
-
net: string[];
|
|
359
|
-
netAll: boolean;
|
|
360
|
-
denyNet: string[];
|
|
361
|
-
allowImport: string[];
|
|
362
|
-
allowImportAll: boolean;
|
|
363
|
-
env: {
|
|
364
|
-
allow: string[];
|
|
365
|
-
allowAll: boolean;
|
|
366
|
-
deny: string[];
|
|
367
|
-
files: string[];
|
|
368
|
-
};
|
|
369
|
-
envFiles: string[];
|
|
370
|
-
run: string[];
|
|
371
|
-
runAll: boolean;
|
|
372
|
-
denyRun: string[];
|
|
373
|
-
workers: boolean;
|
|
374
|
-
ffi: string[];
|
|
375
|
-
ffiAll: boolean;
|
|
376
|
-
denyFfi: string[];
|
|
377
|
-
sys: SysApiName[];
|
|
378
|
-
sysAll: boolean;
|
|
379
|
-
denySys: SysApiName[];
|
|
380
|
-
wasi: boolean;
|
|
381
|
-
lockFiles: {
|
|
382
|
-
deno?: string;
|
|
383
|
-
};
|
|
384
|
-
node: Required<NodePermissionSettings> & {
|
|
385
|
-
flags: string[];
|
|
386
|
-
};
|
|
387
|
-
deno: Required<Omit<DenoPermissionSettings, "lock">> & {
|
|
388
|
-
flags: string[];
|
|
389
|
-
};
|
|
390
|
-
l3: L3RuntimeKeys;
|
|
391
|
-
};
|
|
392
|
-
type WorkerData = {
|
|
393
|
-
sab: SharedBufferSource;
|
|
394
|
-
abortSignalSAB?: SharedBufferSource;
|
|
395
|
-
abortSignalMax?: number;
|
|
396
|
-
list: string[];
|
|
397
|
-
ids: number[];
|
|
398
|
-
names: string[];
|
|
399
|
-
thread: number;
|
|
400
|
-
totalNumberOfThread: number;
|
|
401
|
-
debug?: DebugOptions;
|
|
402
|
-
startAt: number;
|
|
403
|
-
workerOptions?: WorkerSettings;
|
|
404
|
-
at: number[];
|
|
405
|
-
lock: LockBuffers;
|
|
406
|
-
returnLock: LockBuffers;
|
|
407
|
-
payloadConfig?: PayloadBufferOptions;
|
|
408
|
-
bufferReferenceReturn?: "copy" | "borrow";
|
|
409
|
-
permission?: ResolvedPermissionProtocol;
|
|
410
|
-
};
|
|
411
|
-
type UnsafeOptions = {
|
|
412
|
-
/**
|
|
413
|
-
* Experimental `BufferReference` return lifetime.
|
|
414
|
-
*
|
|
415
|
-
* `"copy"` is safe after worker release. `"borrow"` skips the Deno/Bun copy,
|
|
416
|
-
* but must be released before producer shutdown and must not outlive its ref.
|
|
417
|
-
*/
|
|
418
|
-
BufferReferenceReturn?: "copy" | "borrow";
|
|
419
|
-
};
|
|
420
|
-
type LockBuffers = {
|
|
421
|
-
headers: SharedBufferSource;
|
|
422
|
-
headerSlotStrideU32?: number;
|
|
423
|
-
lockSector: SharedBufferSource;
|
|
424
|
-
payload: SharedBufferSource;
|
|
425
|
-
payloadSector: SharedBufferSource;
|
|
426
|
-
textCompat?: LockBufferTextCompat;
|
|
427
|
-
};
|
|
428
|
-
type JSONValue = string | number | boolean | null | JSONArray | JSONObject;
|
|
429
|
-
interface JSONObject {
|
|
430
|
-
[key: string]: JSONValue;
|
|
431
|
-
}
|
|
432
|
-
interface JSONArray extends Array<JSONValue> {
|
|
433
|
-
}
|
|
434
|
-
type Serializable = string | object | number | boolean | bigint;
|
|
435
|
-
type ValidInput = bigint | void | JSONValue | symbol | ArrayBuffer | Uint8Array | Int32Array | Float64Array | BigInt64Array | BigUint64Array | DataView | Error | Date | Envelope<EnvelopeHeader, EnvelopeBody>;
|
|
436
|
-
type Args = ValidInput | Serializable;
|
|
437
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
438
|
-
type NoBlob<T> = T extends Blob ? never : T;
|
|
439
|
-
type TaskInput = NoBlob<Args> | Promise<NoBlob<Args>>;
|
|
440
|
-
type TaskTimeout = number | {
|
|
441
|
-
time: number;
|
|
442
|
-
maybe?: true;
|
|
443
|
-
default?: unknown;
|
|
444
|
-
error?: unknown;
|
|
445
|
-
};
|
|
446
|
-
type BivariantCallback<Args extends unknown[], R> = {
|
|
447
|
-
bivarianceHack(...args: Args): R;
|
|
448
|
-
}["bivarianceHack"];
|
|
449
|
-
type AbortSignalConfig = {
|
|
450
|
-
readonly hasAborted: true;
|
|
451
|
-
};
|
|
452
|
-
type AbortSignalOption = true | AbortSignalConfig | undefined;
|
|
453
|
-
type AbortSignalMethods<AS extends AbortSignalOption> = AS extends undefined ? never : {
|
|
454
|
-
hasAborted: () => boolean;
|
|
455
|
-
};
|
|
456
|
-
type AbortSignalToolkit<AS extends AbortSignalOption> = AbortSignalMethods<AS>;
|
|
457
|
-
type TaskFn<A extends TaskInput, B extends Args, AS extends AbortSignalOption = undefined> = BivariantCallback<AS extends undefined ? [
|
|
458
|
-
NoBlob<Awaited<A>>
|
|
459
|
-
] : [
|
|
460
|
-
NoBlob<Awaited<A>>,
|
|
461
|
-
AbortSignalToolkit<AS>
|
|
462
|
-
], MaybePromise<NoBlob<B>>>;
|
|
463
|
-
type PromiseWithMaybeReject<T> = Promise<T> & {
|
|
464
|
-
reject: (reason?: unknown) => void;
|
|
465
|
-
};
|
|
466
|
-
type TaskLike<AS extends AbortSignalOption = AbortSignalOption> = {
|
|
467
|
-
readonly f: (...args: any[]) => any;
|
|
468
|
-
} & (AS extends undefined ? {
|
|
469
|
-
readonly abortSignal?: undefined;
|
|
470
|
-
} : {
|
|
471
|
-
readonly abortSignal: AS;
|
|
472
|
-
});
|
|
473
|
-
type TaskFunctionLike = (...args: any[]) => any;
|
|
474
|
-
type Composed<A extends TaskInput = Args, B extends Args = Args, AS extends AbortSignalOption = undefined> = FixPoint<A, B, AS> & SecondPart;
|
|
475
|
-
type tasks = Record<string, Composed<any, any, any> | TaskFunctionLike>;
|
|
476
|
-
type PromiseWrapped<F extends (...args: any[]) => any, AS extends AbortSignalOption = undefined> = (...args: PromisifyCallArgs<F, AS>) => AS extends undefined ? Promise<Awaited<ReturnType<F>>> : PromiseWithMaybeReject<Awaited<ReturnType<F>>>;
|
|
477
|
-
type PromiseInput<T> = T | Promise<T>;
|
|
478
|
-
type PromisifyArgs<T extends unknown[]> = {
|
|
479
|
-
[K in keyof T]: PromiseInput<T[K]>;
|
|
480
|
-
};
|
|
481
|
-
type NormalizeUndefinedSingleArg<T extends unknown[]> = T extends [
|
|
482
|
-
undefined
|
|
483
|
-
] ? [
|
|
484
|
-
] | [
|
|
485
|
-
undefined
|
|
486
|
-
] : T;
|
|
487
|
-
type AbortAwareCallArgs<T extends unknown[]> = T extends [
|
|
488
|
-
...infer Head,
|
|
489
|
-
AbortSignalToolkit<any>
|
|
490
|
-
] ? NormalizeUndefinedSingleArg<Head> : NormalizeUndefinedSingleArg<T>;
|
|
491
|
-
type HostCallArgs<F extends (...args: any[]) => any, AS extends AbortSignalOption> = AS extends undefined ? Parameters<F> : AbortAwareCallArgs<Parameters<F>>;
|
|
492
|
-
type PromisifyCallArgs<F extends (...args: any[]) => any, AS extends AbortSignalOption> = HostCallArgs<F, AS> extends infer T ? T extends unknown[] ? PromisifyArgs<T> : never : never;
|
|
493
|
-
type TaskCallable<T> = T extends TaskLike<any> ? T["f"] : T extends TaskFunctionLike ? T : never;
|
|
494
|
-
type AbortSignalOfTask<T> = T extends {
|
|
495
|
-
readonly abortSignal: infer AS;
|
|
496
|
-
} ? Extract<AS, AbortSignalOption> : undefined;
|
|
497
|
-
type FunctionMapType<T extends Record<string, TaskLike<any> | TaskFunctionLike>> = {
|
|
498
|
-
[K in keyof T]: PromiseWrapped<TaskCallable<T[K]>, AbortSignalOfTask<T[K]>>;
|
|
499
|
-
};
|
|
500
|
-
interface FixPointBase<A extends TaskInput, B extends Args, AS extends AbortSignalOption = undefined> {
|
|
501
|
-
/** Worker function. It receives one value; use a tuple/object for many inputs. */
|
|
502
|
-
readonly f: TaskFn<A, B, AS>;
|
|
503
|
-
/** Soft call timeout. Use `worker.hardTimeoutMs` for runaway CPU walls. */
|
|
504
|
-
readonly timeout?: TaskTimeout;
|
|
505
|
-
}
|
|
506
|
-
type FixPoint<A extends TaskInput, B extends Args, AS extends AbortSignalOption = undefined> = FixPointBase<A, B, AS> & (AS extends undefined ? {
|
|
507
|
-
readonly abortSignal?: undefined;
|
|
508
|
-
} : {
|
|
509
|
-
readonly abortSignal: AS;
|
|
510
|
-
});
|
|
511
|
-
type ImportTaskOptions<A extends TaskInput = void, B extends Args = void, AS extends AbortSignalOption = undefined> = Omit<FixPoint<A, B, AS>, "f"> & {
|
|
512
|
-
/** Module imported by the worker only. Relative paths resolve from caller. */
|
|
513
|
-
readonly href: string;
|
|
514
|
-
/** Plain function export name. Defaults to `"default"`; do not target `task()`. */
|
|
515
|
-
readonly name?: string;
|
|
516
|
-
};
|
|
517
|
-
type SecondPart = {
|
|
518
|
-
readonly [endpointSymbol]: true;
|
|
519
|
-
readonly id: number;
|
|
520
|
-
/** Logical export order used to match worker tasks before names are known. */
|
|
521
|
-
readonly at: number;
|
|
522
|
-
readonly importedFrom: string;
|
|
523
|
-
/**
|
|
524
|
-
* Imported tasks stay on worker lanes so imports run under worker permissions.
|
|
525
|
-
*/
|
|
526
|
-
readonly imported?: boolean;
|
|
527
|
-
};
|
|
528
|
-
type SingleTaskPool<A extends TaskInput = Args, B extends Args = Args, AS extends AbortSignalOption = undefined> = {
|
|
529
|
-
/** Invoke the single task. Arguments may be native Promises. */
|
|
530
|
-
call: PromiseWrapped<TaskFn<A, B, AS>, AS>;
|
|
531
|
-
/** Await worker teardown now. `using` disposes at scope exit without awaiting. */
|
|
532
|
-
shutdown: (delayMs?: number) => Promise<void>;
|
|
533
|
-
/** Starts shutdown at scope exit. Use `shutdown()` when you must await it. */
|
|
534
|
-
[Symbol.dispose]: () => void;
|
|
535
|
-
};
|
|
536
|
-
type Pool<T extends Record<string, TaskLike<any> | TaskFunctionLike>> = {
|
|
537
|
-
/** Await worker teardown now. `using` disposes at scope exit without awaiting. */
|
|
538
|
-
shutdown: (delayMs?: number) => Promise<void>;
|
|
539
|
-
/** Starts shutdown at scope exit. Use `shutdown()` when you must await it. */
|
|
540
|
-
[Symbol.dispose]: () => void;
|
|
541
|
-
/**
|
|
542
|
-
* Typed task callers. Each call accepts the task input or a native Promise.
|
|
543
|
-
* Thrown errors/rejections reject here as Error objects with cause chains.
|
|
544
|
-
*/
|
|
545
|
-
call: FunctionMapType<T>;
|
|
546
|
-
};
|
|
547
|
-
type ReturnFixed<A extends TaskInput = undefined, B extends Args = undefined, AS extends AbortSignalOption = undefined> = FixPoint<A, B, AS> & SecondPart & {
|
|
548
|
-
createPool: (options?: CreatePool) => SingleTaskPool<A, B, AS>;
|
|
549
|
-
};
|
|
550
|
-
type Inliner = {
|
|
551
|
-
position?: "first" | "last";
|
|
552
|
-
/**
|
|
553
|
-
* Inline tasks per event loop tick.
|
|
554
|
-
* Defaults to 1 when inliner is enabled.
|
|
555
|
-
*/
|
|
556
|
-
batchSize?: number;
|
|
557
|
-
/**
|
|
558
|
-
* Minimum in-flight calls before routing can use the inline host lane.
|
|
559
|
-
* Defaults to 1 (inline lane available immediately).
|
|
560
|
-
*/
|
|
561
|
-
dispatchThreshold?: number;
|
|
562
|
-
};
|
|
563
|
-
type BalancerStrategy = "roundRobin" | "robinRound" | "firstIdle" | "randomLane" | "firstIdleOrRandom";
|
|
564
|
-
type Balancer = BalancerStrategy | {
|
|
565
|
-
/**
|
|
566
|
-
* Optional. Defaults to "roundRobin".
|
|
567
|
-
*/
|
|
568
|
-
strategy?: BalancerStrategy;
|
|
569
|
-
};
|
|
570
|
-
type DebugNamespace = "host" | "globals" | "signals" | "imports" | "lifecycle";
|
|
571
|
-
type DebugFlags = {
|
|
572
|
-
[Namespace in DebugNamespace]?: boolean;
|
|
573
|
-
};
|
|
574
|
-
type DebugOptions = boolean | DebugFlags;
|
|
575
|
-
type WorkerBootstrapOptions<Data = unknown> = {
|
|
576
|
-
/**
|
|
577
|
-
* Module imported inside the worker before task modules are imported.
|
|
578
|
-
* Relative paths are resolved from the `createPool(...)` caller.
|
|
579
|
-
*/
|
|
580
|
-
href: string;
|
|
581
|
-
/**
|
|
582
|
-
* Exported bootstrap function name. Defaults to `"default"`.
|
|
583
|
-
*/
|
|
584
|
-
name?: string;
|
|
585
|
-
/**
|
|
586
|
-
* Structured data passed to the bootstrap function.
|
|
587
|
-
*/
|
|
588
|
-
data?: Data;
|
|
589
|
-
};
|
|
590
|
-
type WorkerSettings = {
|
|
591
|
-
resolveAfterFinishingAll?: true;
|
|
592
|
-
/**
|
|
593
|
-
* Privileged async worker hook that runs once before task modules import.
|
|
594
|
-
* Use it to shape the worker environment before user task code loads.
|
|
595
|
-
*/
|
|
596
|
-
bootstrap?: WorkerBootstrapOptions;
|
|
597
|
-
/**
|
|
598
|
-
* Experimental worker runtime.
|
|
599
|
-
* "thread" uses Worker/worker_threads. "process" spawns another JavaScript
|
|
600
|
-
* runtime, useful for process isolation, bwrap, and containers.
|
|
601
|
-
*/
|
|
602
|
-
runtime?: "thread" | "process";
|
|
603
|
-
/**
|
|
604
|
-
* Runtime executable to use when runtime is "process". Defaults to "deno".
|
|
605
|
-
*/
|
|
606
|
-
processRuntime?: "bun" | "deno" | "node";
|
|
607
|
-
/**
|
|
608
|
-
* Command argv to prepend before the process worker runtime command.
|
|
609
|
-
* Useful for wrappers such as systemd-run, cgexec, nice, taskset, or
|
|
610
|
-
* docker. Knitting appends the runtime command after this prefix.
|
|
611
|
-
*
|
|
612
|
-
* Example:
|
|
613
|
-
* ["systemd-run", "--scope", "-p", "MemoryMax=500M", "-p", "CPUQuota=25%"]
|
|
614
|
-
*
|
|
615
|
-
* With containers, use processSharedMemory: "named", share the IPC
|
|
616
|
-
* namespace, mount the worker files at the same path, and forward
|
|
617
|
-
* KNITTING_PROCESS_WORKER plus KNITTING_PROCESS_WORKER_BOOT.
|
|
618
|
-
*/
|
|
619
|
-
processCommandPrefix?: string[];
|
|
620
|
-
/**
|
|
621
|
-
* How process workers discover their shared-memory control channel.
|
|
622
|
-
*
|
|
623
|
-
* "inherit" keeps the POSIX fd-inheritance path and is the default outside
|
|
624
|
-
* Windows. "named" creates an OS-named shared-memory object that wrappers
|
|
625
|
-
* such as containers can reopen by name when they share the same IPC
|
|
626
|
-
* namespace.
|
|
627
|
-
*/
|
|
628
|
-
processSharedMemory?: ProcessSharedMemoryMode | ProcessSharedMemorySettings;
|
|
629
|
-
timers?: WorkerTimers;
|
|
630
|
-
/**
|
|
631
|
-
* Hard task execution timeout in milliseconds.
|
|
632
|
-
* When exceeded, the pool is force-shutdown to stop runaway CPU tasks.
|
|
633
|
-
*/
|
|
634
|
-
hardTimeoutMs?: number;
|
|
635
|
-
};
|
|
636
|
-
type ProcessSharedMemoryMode = "inherit" | "named";
|
|
637
|
-
type ProcessSharedMemorySettings = {
|
|
638
|
-
mode?: ProcessSharedMemoryMode;
|
|
639
|
-
namePrefix?: string;
|
|
640
|
-
unlinkOnShutdown?: boolean;
|
|
641
|
-
};
|
|
642
|
-
type WorkerTimers = {
|
|
643
|
-
/**
|
|
644
|
-
* Busy-spin budget before parking (microseconds).
|
|
645
|
-
*/
|
|
646
|
-
spinMicroseconds?: number;
|
|
647
|
-
/**
|
|
648
|
-
* Atomics.wait timeout when parked (milliseconds).
|
|
649
|
-
*/
|
|
650
|
-
parkMs?: number;
|
|
651
|
-
/**
|
|
652
|
-
* Atomics.pause duration during spin (nanoseconds).
|
|
653
|
-
* Set to 0 (or less) to disable pause calls.
|
|
654
|
-
*/
|
|
655
|
-
pauseNanoseconds?: number;
|
|
656
|
-
};
|
|
657
|
-
type DispatcherSettings = {
|
|
658
|
-
/**
|
|
659
|
-
* How many immediate notify loops before backoff kicks in.
|
|
660
|
-
*/
|
|
661
|
-
stallFreeLoops?: number;
|
|
662
|
-
/**
|
|
663
|
-
* Max backoff delay (milliseconds).
|
|
664
|
-
*/
|
|
665
|
-
maxBackoffMs?: number;
|
|
666
|
-
/**
|
|
667
|
-
* Host dispatcher topology.
|
|
668
|
-
* - `"per-thread"`: each worker owns its dispatcher and macro channel.
|
|
669
|
-
* - `"serial-channel"`: each worker keeps its own dispatcher check state, but
|
|
670
|
-
* one shared channel runs all lane checks from first to last.
|
|
671
|
-
*
|
|
672
|
-
* Experimental default: `"per-thread"` on Bun or with one worker, otherwise
|
|
673
|
-
* `"serial-channel"` for multi-worker Node/Deno pools. Can also be forced
|
|
674
|
-
* with the `KNITTING_DISPATCHER` env var (`serial-channel` or `per-thread`).
|
|
675
|
-
*/
|
|
676
|
-
dispatcher?: "per-thread" | "serial-channel";
|
|
677
|
-
};
|
|
678
|
-
type CreatePool = {
|
|
679
|
-
/** Number of workers. Default: 1. */
|
|
680
|
-
threads?: number;
|
|
681
|
-
/** Add a host inline lane for regular tasks. Imported tasks still use workers. */
|
|
682
|
-
inliner?: Inliner;
|
|
683
|
-
balancer?: Balancer;
|
|
684
|
-
worker?: WorkerSettings;
|
|
685
|
-
/**
|
|
686
|
-
* Payload transport settings. Default dynamic payload cap is about 8 MiB
|
|
687
|
-
* (`payloadMaxByteLength >> 3`, with a 64 MiB growth cap).
|
|
688
|
-
*/
|
|
689
|
-
payload?: PayloadBufferOptions;
|
|
690
|
-
/**
|
|
691
|
-
* Experimental unsafe options.
|
|
692
|
-
*/
|
|
693
|
-
unsafe?: UnsafeOptions;
|
|
694
|
-
/**
|
|
695
|
-
* Abort-aware signal pool capacity.
|
|
696
|
-
* Defaults to `258`.
|
|
697
|
-
*/
|
|
698
|
-
abortSignalCapacity?: number;
|
|
699
|
-
/**
|
|
700
|
-
* Host dispatcher backoff and scheduling options.
|
|
701
|
-
*/
|
|
702
|
-
host?: DispatcherSettings;
|
|
703
|
-
/**
|
|
704
|
-
* Extra Node.js execArgv flags for worker threads (e.g. ["--expose-gc"]).
|
|
705
|
-
* Defaults to process.execArgv plus "--expose-gc" when allowed.
|
|
706
|
-
*/
|
|
707
|
-
workerExecArgv?: string[];
|
|
708
|
-
/**
|
|
709
|
-
* Runtime permission protocol.
|
|
710
|
-
* Omit to use strict defaults with `allowImport: true`; worker console is
|
|
711
|
-
* quiet unless `permission: { console: true }`.
|
|
712
|
-
*
|
|
713
|
-
* Task code cannot terminate the host: process/Deno exit APIs are blocked.
|
|
714
|
-
* Use `"strict"` (default for object mode) or `"unsafe"`.
|
|
715
|
-
* Accepts object form for fine-grained permission controls.
|
|
716
|
-
*/
|
|
717
|
-
permission?: PermissionProtocolInput;
|
|
718
|
-
debug?: DebugOptions;
|
|
719
|
-
source?: string;
|
|
720
|
-
};
|
|
721
|
-
export declare const workerMainLoop: (startupData: WorkerData) => Promise<void>;
|
|
722
|
-
type CreatePoolFactory = (options: CreatePool) => <T extends tasks>(tasks: T) => Pool<T>;
|
|
723
|
-
type InferredTaskFunction = (...args: any[]) => MaybePromise<Args>;
|
|
724
|
-
type InferredTaskInput<F extends InferredTaskFunction, AS extends AbortSignalOption> = Parameters<F> extends [
|
|
725
|
-
] ? void : AS extends undefined ? Parameters<F> extends [
|
|
726
|
-
infer A
|
|
727
|
-
] ? A extends TaskInput ? A : never : never : Parameters<F> extends [
|
|
728
|
-
infer A
|
|
729
|
-
] ? A extends TaskInput ? A : never : Parameters<F> extends [
|
|
730
|
-
infer A,
|
|
731
|
-
AbortSignalToolkit<AS>
|
|
732
|
-
] ? A extends TaskInput ? A : never : never;
|
|
733
|
-
type InferredTaskOutput<F extends InferredTaskFunction> = Awaited<ReturnType<F>> extends infer R ? R extends Blob ? never : R extends Args ? R : never : never;
|
|
734
|
-
type InferredTaskShape<F extends InferredTaskFunction, AS extends AbortSignalOption> = [
|
|
735
|
-
InferredTaskInput<F, AS>
|
|
736
|
-
] extends [
|
|
737
|
-
never
|
|
738
|
-
] ? never : [
|
|
739
|
-
InferredTaskOutput<F>
|
|
740
|
-
] extends [
|
|
741
|
-
never
|
|
742
|
-
] ? never : {
|
|
743
|
-
readonly f: F;
|
|
744
|
-
readonly timeout?: TaskTimeout;
|
|
745
|
-
} & (AS extends undefined ? {
|
|
746
|
-
readonly abortSignal?: undefined;
|
|
747
|
-
} : {
|
|
748
|
-
readonly abortSignal: AS;
|
|
749
|
-
});
|
|
750
|
-
export declare const isMain: boolean;
|
|
751
|
-
/**
|
|
752
|
-
* Create a typed worker pool from module-scope exported tasks/functions.
|
|
753
|
-
*
|
|
754
|
-
* Install/import as `knitting` on npm or `@vixeny/knitting` on JSR. Requires
|
|
755
|
-
* Node 22+, Deno 2+, or Bun 1+.
|
|
756
|
-
*
|
|
757
|
-
* Use `createPool(options)({ taskA })`, call `await pool.call.taskA(arg)`, and
|
|
758
|
-
* clean up with `using pool = ...` or `await pool.shutdown()`.
|
|
759
|
-
*
|
|
760
|
-
* Guard host-only pool setup with `isMain`: workers re-import task modules, and
|
|
761
|
-
* top-level imports in those modules run in every worker. Keep task modules
|
|
762
|
-
* lean and separate from server/framework setup. Each task receives one
|
|
763
|
-
* argument; use an object or tuple for multiple values.
|
|
764
|
-
*/
|
|
765
|
-
export declare const createPool: CreatePoolFactory;
|
|
766
|
-
/**
|
|
767
|
-
* Define a worker task with options.
|
|
768
|
-
*
|
|
769
|
-
* Pass raw module-scope exported functions to `createPool` directly when you do
|
|
770
|
-
* not need options. Use `task({ f })` for timeouts, abort signals, or the
|
|
771
|
-
* single-task `.createPool()` shorthand.
|
|
772
|
-
*
|
|
773
|
-
* The function receives one argument; use a tuple/object for multiple values.
|
|
774
|
-
* Inputs may be direct values or native Promises, so `request.arrayBuffer()` can
|
|
775
|
-
* be forwarded without awaiting on the host.
|
|
776
|
-
*/
|
|
777
|
-
export declare function task<F extends InferredTaskFunction>(I: InferredTaskShape<F, undefined>): ReturnFixed<InferredTaskInput<F, undefined>, InferredTaskOutput<F>, undefined>;
|
|
778
|
-
export declare function task<F extends InferredTaskFunction>(I: InferredTaskShape<F, true>): ReturnFixed<InferredTaskInput<F, true>, InferredTaskOutput<F>, true>;
|
|
779
|
-
export declare function task<AS extends AbortSignalConfig, F extends InferredTaskFunction>(I: InferredTaskShape<F, AS>): ReturnFixed<InferredTaskInput<F, AS>, InferredTaskOutput<F>, AS>;
|
|
780
|
-
export declare function task<A extends TaskInput = void, B extends Args = void>(I: FixPoint<A, B, true>): ReturnFixed<A, B, true>;
|
|
781
|
-
export declare function task<A extends TaskInput = void, B extends Args = void, AS extends AbortSignalConfig = AbortSignalConfig>(I: FixPoint<A, B, AS>): ReturnFixed<A, B, AS>;
|
|
782
|
-
export declare function task<A extends TaskInput = void, B extends Args = void>(I: FixPoint<A, B, undefined>): ReturnFixed<A, B, undefined>;
|
|
783
|
-
/**
|
|
784
|
-
* Define a task whose worker-side code is imported only by workers.
|
|
785
|
-
*
|
|
786
|
-
* Use this for untrusted or security-sensitive code: the host keeps a typed
|
|
787
|
-
* wrapper and does not import/evaluate `href`. The target export must be a
|
|
788
|
-
* plain function, not a `task()` wrapper.
|
|
789
|
-
*/
|
|
790
|
-
export declare function importTask<A extends TaskInput = void, B extends Args = void>(options: ImportTaskOptions<A, B, true>): ReturnFixed<A, B, true>;
|
|
791
|
-
export declare function importTask<A extends TaskInput = void, B extends Args = void, AS extends AbortSignalConfig = AbortSignalConfig>(options: ImportTaskOptions<A, B, AS>): ReturnFixed<A, B, AS>;
|
|
792
|
-
export declare function importTask<A extends TaskInput = void, B extends Args = void>(options: ImportTaskOptions<A, B, undefined>): ReturnFixed<A, B, undefined>;
|
|
793
|
-
export declare class NumericArray extends Array<number> {
|
|
794
|
-
}
|
|
795
|
-
export declare const isNumericArray: (value: object) => value is NumericArray;
|
|
796
|
-
|
|
797
|
-
export {};
|
|
1
|
+
import { workerMainLoop } from "./src/worker/loop.js";
|
|
2
|
+
import { createPool, importTask, isMain, task } from "./src/api.js";
|
|
3
|
+
import { Envelope } from "./src/common/envelope.js";
|
|
4
|
+
import { isNumericArray, NumericArray } from "./src/connections/numeric-array.js";
|
|
5
|
+
export { createPool as createPool, Envelope as Envelope, importTask as importTask, isMain as isMain, isNumericArray as isNumericArray, NumericArray as NumericArray, task as task, workerMainLoop as workerMainLoop, };
|
|
6
|
+
export type { EnvelopeBody as EnvelopeBody, EnvelopeHeader as EnvelopeHeader, } from "./src/common/envelope.js";
|