knitting 0.1.55 → 0.1.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +254 -40
- package/knitting.d.ts +7 -797
- package/knitting.js +6 -9780
- package/map.md +31 -15
- package/package.json +20 -6
- package/process-shared-buffer.d.ts +1 -0
- package/process-shared-buffer.js +1 -0
- package/scripts/build-compiled-worker.ts +276 -0
- package/scripts/compiled-worker/porffor.d.ts +5 -0
- package/scripts/compiled-worker/runtime.ts +529 -0
- package/scripts/compiled-worker/task-shim.ts +32 -0
- package/shared-memory.d.ts +1 -155
- package/shared-memory.js +1 -1342
- package/src/api.d.ts +92 -0
- package/src/api.js +798 -0
- package/src/common/envelope.d.ts +17 -0
- package/src/common/envelope.js +22 -0
- package/src/common/module-url.d.ts +2 -0
- package/src/common/module-url.js +52 -0
- package/src/common/node-compat.d.ts +22 -0
- package/src/common/node-compat.js +24 -0
- package/src/common/path-canonical.d.ts +6 -0
- package/src/common/path-canonical.js +55 -0
- package/src/common/runtime.d.ts +16 -0
- package/src/common/runtime.js +105 -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 +5 -0
- package/src/common/task-source.js +100 -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 +70 -0
- package/src/connections/buffer-reference-native.d.ts +56 -0
- package/src/connections/buffer-reference-native.js +241 -0
- package/src/connections/buffer-reference.d.ts +99 -0
- package/src/connections/buffer-reference.js +575 -0
- package/src/connections/bun.d.ts +22 -0
- package/src/connections/bun.js +225 -0
- package/src/connections/deno.d.ts +24 -0
- package/src/connections/deno.js +226 -0
- package/src/connections/external-array-buffer.d.ts +2 -0
- package/src/connections/external-array-buffer.js +33 -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 +16 -0
- package/src/connections/node-addons.js +92 -0
- package/src/connections/node-buffer-pointer.d.ts +20 -0
- package/src/connections/node-buffer-pointer.js +16 -0
- package/src/connections/node-ffi-api.d.ts +19 -0
- package/src/connections/node-ffi-api.js +28 -0
- package/src/connections/node-ffi.d.ts +27 -0
- package/src/connections/node-ffi.js +262 -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 +55 -0
- package/src/connections/posix.d.ts +74 -0
- package/src/connections/posix.js +178 -0
- package/src/connections/process-shared-buffer.d.ts +76 -0
- package/src/connections/process-shared-buffer.js +245 -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 +54 -0
- package/src/connections/types.js +37 -0
- package/src/connections/windows.d.ts +37 -0
- package/src/connections/windows.js +245 -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 +14 -0
- package/src/error.js +50 -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 +213 -0
- package/src/memory/lock.js +760 -0
- package/src/memory/payload-config.d.ts +31 -0
- package/src/memory/payload-config.js +67 -0
- package/src/memory/payloadCodec.d.ts +55 -0
- package/src/memory/payloadCodec.js +1473 -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/compatibility.d.ts +28 -0
- package/src/permission/compatibility.js +239 -0
- package/src/permission/index.d.ts +4 -0
- package/src/permission/index.js +3 -0
- package/src/permission/protocol.d.ts +167 -0
- package/src/permission/protocol.js +690 -0
- package/src/runtime/balancer.d.ts +19 -0
- package/src/runtime/balancer.js +149 -0
- package/src/runtime/compiled-artifact.d.ts +21 -0
- package/src/runtime/compiled-artifact.js +260 -0
- package/src/runtime/compiled-builder.d.ts +8 -0
- package/src/runtime/compiled-builder.js +42 -0
- package/src/runtime/compiled-worker.d.ts +27 -0
- package/src/runtime/compiled-worker.js +562 -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 +294 -0
- package/src/runtime/pool.d.ts +44 -0
- package/src/runtime/pool.js +472 -0
- package/src/runtime/process-worker.d.ts +92 -0
- package/src/runtime/process-worker.js +713 -0
- package/src/runtime/tx-queue.d.ts +28 -0
- package/src/runtime/tx-queue.js +158 -0
- package/src/shared/abortSignal.d.ts +23 -0
- package/src/shared/abortSignal.js +134 -0
- package/src/types.d.ts +399 -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 +98 -0
- package/src/worker/loop.d.ts +3 -0
- package/src/worker/loop.js +395 -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 +28 -0
- package/src/worker/task-loader.js +76 -0
- package/src/worker/timers.d.ts +18 -0
- package/src/worker/timers.js +118 -0
- package/unsafe.d.ts +1 -71
- package/unsafe.js +1 -878
- package/utils.d.ts +1 -31
- package/utils.js +1 -116
package/src/api.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { setModuleUrl } from "./common/task-source.js";
|
|
2
|
+
import { endpointSymbol } from "./common/task-symbol.js";
|
|
3
|
+
import type { AbortSignalConfig, AbortSignalOption, AbortSignalToolkit, Args, CompiledWorkerCheck, CompiledWorkerOptions, CompiledWorkerSource, ComposedWithKey, CreatePool, FixPoint, ImportTaskOptions, MaybePromise, Pool, ReturnFixed, TaskInput, tasks, TaskTimeout } from "./types.js";
|
|
4
|
+
type ToListAndIds = {
|
|
5
|
+
list: string[];
|
|
6
|
+
ids: number[];
|
|
7
|
+
names: string[];
|
|
8
|
+
at: number[];
|
|
9
|
+
};
|
|
10
|
+
type ToListAndIdsFn = (args: ComposedWithKey[]) => ToListAndIds;
|
|
11
|
+
type CreatePoolFactory = (options: CreatePool) => <T extends tasks>(tasks: T) => Pool<T>;
|
|
12
|
+
type InferredTaskFunction = (...args: any[]) => MaybePromise<Args>;
|
|
13
|
+
type InferredTaskInput<F extends InferredTaskFunction, AS extends AbortSignalOption> = Parameters<F> extends [] ? void : AS extends undefined ? Parameters<F> extends [infer A] ? A extends TaskInput ? A : never : never : Parameters<F> extends [infer A] ? A extends TaskInput ? A : never : Parameters<F> extends [infer A, AbortSignalToolkit<AS>] ? A extends TaskInput ? A : never : never;
|
|
14
|
+
type InferredTaskOutput<F extends InferredTaskFunction> = Awaited<ReturnType<F>> extends infer R ? R extends Blob ? never : R extends Args ? R : never : never;
|
|
15
|
+
type InferredTaskShape<F extends InferredTaskFunction, AS extends AbortSignalOption> = [InferredTaskInput<F, AS>] extends [never] ? never : [InferredTaskOutput<F>] extends [never] ? never : {
|
|
16
|
+
readonly f: F;
|
|
17
|
+
readonly timeout?: TaskTimeout;
|
|
18
|
+
} & (AS extends undefined ? {
|
|
19
|
+
readonly abortSignal?: undefined;
|
|
20
|
+
} : {
|
|
21
|
+
readonly abortSignal: AS;
|
|
22
|
+
});
|
|
23
|
+
export declare const isMain: boolean;
|
|
24
|
+
export { endpointSymbol as endpointSymbol };
|
|
25
|
+
/**
|
|
26
|
+
* Declare the task module's URL for runtimes without stack traces (e.g.
|
|
27
|
+
* Andromeda) that can't auto-discover the caller. Call once at module top
|
|
28
|
+
* level, before defining tasks:
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { setModuleUrl, task } from "knitting";
|
|
32
|
+
* setModuleUrl(import.meta.url);
|
|
33
|
+
* export const add = task({ f: ([a, b]: [number, number]) => a + b });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* Runs in both host and worker (same module re-imported), so both agree on the
|
|
37
|
+
* path. No-op-safe on Node/Deno/Bun, where stack discovery already works.
|
|
38
|
+
*/
|
|
39
|
+
export { setModuleUrl as setModuleUrl };
|
|
40
|
+
/**
|
|
41
|
+
* Reconstructs stable task order from top-level exports before names are bound.
|
|
42
|
+
*/
|
|
43
|
+
export declare const toListAndIds: ToListAndIdsFn;
|
|
44
|
+
/**
|
|
45
|
+
* Check whether a task module has a compatible prebuilt native worker.
|
|
46
|
+
*
|
|
47
|
+
* By default tasks.ts resolves to tasks.knt plus tasks.knt.json.
|
|
48
|
+
* This only inspects the artifact; it never executes it.
|
|
49
|
+
*/
|
|
50
|
+
export declare const checkCompiledWorker: (source: CompiledWorkerSource, options?: CompiledWorkerOptions) => CompiledWorkerCheck;
|
|
51
|
+
/**
|
|
52
|
+
* Create a typed worker pool from module-scope exported tasks/functions.
|
|
53
|
+
*
|
|
54
|
+
* Install/import as `knitting` on npm or `@vixeny/knitting` on JSR. Requires
|
|
55
|
+
* Node 22+, Deno 2+, or Bun 1+.
|
|
56
|
+
*
|
|
57
|
+
* Use `createPool(options)({ taskA })`, call `await pool.call.taskA(arg)`, and
|
|
58
|
+
* clean up with `using pool = ...` or `await pool.shutdown()`.
|
|
59
|
+
*
|
|
60
|
+
* Guard host-only pool setup with `isMain`: workers re-import task modules, and
|
|
61
|
+
* top-level imports in those modules run in every worker. Keep task modules
|
|
62
|
+
* lean and separate from server/framework setup. Each task receives one
|
|
63
|
+
* argument; use an object or tuple for multiple values.
|
|
64
|
+
*/
|
|
65
|
+
export declare const createPool: CreatePoolFactory;
|
|
66
|
+
/**
|
|
67
|
+
* Define a worker task with options.
|
|
68
|
+
*
|
|
69
|
+
* Pass raw module-scope exported functions to `createPool` directly when you do
|
|
70
|
+
* not need options. Use `task({ f })` for timeouts, abort signals, or the
|
|
71
|
+
* single-task `.createPool()` shorthand.
|
|
72
|
+
*
|
|
73
|
+
* The function receives one argument; use a tuple/object for multiple values.
|
|
74
|
+
* Inputs may be direct values or native Promises, so `request.arrayBuffer()` can
|
|
75
|
+
* be forwarded without awaiting on the host.
|
|
76
|
+
*/
|
|
77
|
+
export declare function task<F extends InferredTaskFunction>(I: InferredTaskShape<F, undefined>): ReturnFixed<InferredTaskInput<F, undefined>, InferredTaskOutput<F>, undefined>;
|
|
78
|
+
export declare function task<F extends InferredTaskFunction>(I: InferredTaskShape<F, true>): ReturnFixed<InferredTaskInput<F, true>, InferredTaskOutput<F>, true>;
|
|
79
|
+
export declare function task<AS extends AbortSignalConfig, F extends InferredTaskFunction>(I: InferredTaskShape<F, AS>): ReturnFixed<InferredTaskInput<F, AS>, InferredTaskOutput<F>, AS>;
|
|
80
|
+
export declare function task<A extends TaskInput = void, B extends Args = void>(I: FixPoint<A, B, true>): ReturnFixed<A, B, true>;
|
|
81
|
+
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>;
|
|
82
|
+
export declare function task<A extends TaskInput = void, B extends Args = void>(I: FixPoint<A, B, undefined>): ReturnFixed<A, B, undefined>;
|
|
83
|
+
/**
|
|
84
|
+
* Define a task whose worker-side code is imported only by workers.
|
|
85
|
+
*
|
|
86
|
+
* Use this for untrusted or security-sensitive code: the host keeps a typed
|
|
87
|
+
* wrapper and does not import/evaluate `href`. The target export must be a
|
|
88
|
+
* plain function, not a `task()` wrapper.
|
|
89
|
+
*/
|
|
90
|
+
export declare function importTask<A extends TaskInput = void, B extends Args = void>(options: ImportTaskOptions<A, B, true>): ReturnFixed<A, B, true>;
|
|
91
|
+
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>;
|
|
92
|
+
export declare function importTask<A extends TaskInput = void, B extends Args = void>(options: ImportTaskOptions<A, B, undefined>): ReturnFixed<A, B, undefined>;
|