knitting 0.1.46
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/LICENSE +202 -0
- package/README.md +632 -0
- package/knitting.d.ts +4 -0
- package/knitting.js +5 -0
- package/map.md +264 -0
- package/package.json +77 -0
- package/prebuilds/darwin-arm64-node-127/knitting_shared_memory.node +0 -0
- package/prebuilds/darwin-arm64-node-127/knitting_shm.node +0 -0
- package/prebuilds/darwin-arm64-node-137/knitting_shared_memory.node +0 -0
- package/prebuilds/darwin-arm64-node-137/knitting_shm.node +0 -0
- package/prebuilds/darwin-x64-node-127/knitting_shared_memory.node +0 -0
- package/prebuilds/darwin-x64-node-127/knitting_shm.node +0 -0
- package/prebuilds/darwin-x64-node-137/knitting_shared_memory.node +0 -0
- package/prebuilds/darwin-x64-node-137/knitting_shm.node +0 -0
- package/prebuilds/linux-x64-node-127/knitting_shared_memory.node +0 -0
- package/prebuilds/linux-x64-node-127/knitting_shm.node +0 -0
- package/prebuilds/linux-x64-node-137/knitting_shared_memory.node +0 -0
- package/prebuilds/linux-x64-node-137/knitting_shm.node +0 -0
- package/process-shared-buffer.d.ts +1 -0
- package/process-shared-buffer.js +1 -0
- package/scripts/build-native-addons.ts +295 -0
- package/src/api.d.ts +55 -0
- package/src/api.js +384 -0
- package/src/common/envelope.d.ts +11 -0
- package/src/common/envelope.js +8 -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 +2 -0
- package/src/common/task-source.js +79 -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 +40 -0
- package/src/common/worker-runtime.js +52 -0
- package/src/connections/bun.d.ts +20 -0
- package/src/connections/bun.js +159 -0
- package/src/connections/deno.d.ts +20 -0
- package/src/connections/deno.js +150 -0
- package/src/connections/file-descriptor.d.ts +37 -0
- package/src/connections/file-descriptor.js +139 -0
- package/src/connections/index.d.ts +3 -0
- package/src/connections/index.js +3 -0
- package/src/connections/node-addons.d.ts +5 -0
- package/src/connections/node-addons.js +43 -0
- package/src/connections/node.d.ts +29 -0
- package/src/connections/node.js +59 -0
- package/src/connections/posix.d.ts +31 -0
- package/src/connections/posix.js +71 -0
- package/src/connections/process-shared-buffer.d.ts +67 -0
- package/src/connections/process-shared-buffer.js +267 -0
- package/src/connections/types.d.ts +48 -0
- package/src/connections/types.js +37 -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 +25 -0
- package/src/ipc/transport/shared-memory.js +35 -0
- package/src/knitting_shared_memory.cc +436 -0
- package/src/knitting_shm.cc +476 -0
- package/src/memory/byte-carpet.d.ts +73 -0
- package/src/memory/byte-carpet.js +157 -0
- package/src/memory/lock.d.ts +190 -0
- package/src/memory/lock.js +856 -0
- package/src/memory/payload-config.d.ts +22 -0
- package/src/memory/payload-config.js +67 -0
- package/src/memory/payloadCodec.d.ts +46 -0
- package/src/memory/payloadCodec.js +1157 -0
- package/src/memory/regionRegistry.d.ts +17 -0
- package/src/memory/regionRegistry.js +285 -0
- package/src/memory/shared-buffer-io.d.ts +53 -0
- package/src/memory/shared-buffer-io.js +380 -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 +640 -0
- package/src/runtime/balancer.d.ts +19 -0
- package/src/runtime/balancer.js +149 -0
- package/src/runtime/dispatcher.d.ts +34 -0
- package/src/runtime/dispatcher.js +142 -0
- package/src/runtime/inline-executor.d.ts +10 -0
- package/src/runtime/inline-executor.js +270 -0
- package/src/runtime/pool.d.ts +43 -0
- package/src/runtime/pool.js +922 -0
- package/src/runtime/tx-queue.d.ts +25 -0
- package/src/runtime/tx-queue.js +144 -0
- package/src/shared/abortSignal.d.ts +23 -0
- package/src/shared/abortSignal.js +126 -0
- package/src/types.d.ts +283 -0
- package/src/types.js +2 -0
- package/src/worker/composable-runners.d.ts +12 -0
- package/src/worker/composable-runners.js +105 -0
- package/src/worker/loop.d.ts +2 -0
- package/src/worker/loop.js +453 -0
- package/src/worker/rx-queue.d.ts +22 -0
- package/src/worker/rx-queue.js +124 -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 +26 -0
- package/src/worker/task-loader.js +66 -0
- package/src/worker/timers.d.ts +18 -0
- package/src/worker/timers.js +97 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import RingQueue from "../ipc/tools/ring-queue.js";
|
|
2
|
+
import { type SharedBufferSource } from "../common/shared-buffer-region.js";
|
|
3
|
+
import { type LockBufferTextCompat } from "../common/shared-buffer-text.js";
|
|
4
|
+
import { type PayloadBufferOptions } from "./payload-config.js";
|
|
5
|
+
/**
|
|
6
|
+
* TODO: Compose all the instance where the array is passed as argument
|
|
7
|
+
*/
|
|
8
|
+
export declare enum PayloadSignal {
|
|
9
|
+
UNREACHABLE = 0,
|
|
10
|
+
BigInt = 2,
|
|
11
|
+
True = 3,
|
|
12
|
+
False = 4,
|
|
13
|
+
Undefined = 5,
|
|
14
|
+
NaN = 6,
|
|
15
|
+
Float64 = 9,
|
|
16
|
+
Null = 10
|
|
17
|
+
}
|
|
18
|
+
export declare enum PayloadBuffer {
|
|
19
|
+
BORDER_SIGNAL_BUFFER = 11,
|
|
20
|
+
String = 11,
|
|
21
|
+
Json = 12,
|
|
22
|
+
StaticString = 15,
|
|
23
|
+
StaticJson = 16,
|
|
24
|
+
Binary = 17,
|
|
25
|
+
StaticBinary = 18,
|
|
26
|
+
Int32Array = 19,
|
|
27
|
+
Float64Array = 20,
|
|
28
|
+
BigInt64Array = 21,
|
|
29
|
+
BigUint64Array = 22,
|
|
30
|
+
DataView = 23,
|
|
31
|
+
Error = 24,
|
|
32
|
+
Date = 25,
|
|
33
|
+
Symbol = 26,
|
|
34
|
+
StaticSymbol = 27,
|
|
35
|
+
BigInt = 28,
|
|
36
|
+
StaticBigInt = 29,
|
|
37
|
+
StaticInt32Array = 31,
|
|
38
|
+
StaticFloat64Array = 32,
|
|
39
|
+
StaticBigInt64Array = 33,
|
|
40
|
+
StaticBigUint64Array = 34,
|
|
41
|
+
StaticDataView = 35,
|
|
42
|
+
ArrayBuffer = 36,
|
|
43
|
+
StaticArrayBuffer = 37,
|
|
44
|
+
Buffer = 38,
|
|
45
|
+
StaticBuffer = 39,
|
|
46
|
+
EnvelopeStaticHeader = 40,
|
|
47
|
+
EnvelopeDynamicHeader = 41,
|
|
48
|
+
EnvelopeStaticHeaderString = 42,
|
|
49
|
+
EnvelopeDynamicHeaderString = 43,
|
|
50
|
+
ExternalPayload = 44,
|
|
51
|
+
StaticExternalPayload = 45,
|
|
52
|
+
ProcessSharedBuffer = 46
|
|
53
|
+
}
|
|
54
|
+
export declare enum LockBound {
|
|
55
|
+
paddingLock = 0,
|
|
56
|
+
padding = 0,
|
|
57
|
+
slots = 32,
|
|
58
|
+
header = 0
|
|
59
|
+
}
|
|
60
|
+
export declare const LOCK_CACHE_LINE_BYTES = 64;
|
|
61
|
+
export declare const LOCK_SECTOR_BYTES = 256;
|
|
62
|
+
export type Task = [
|
|
63
|
+
number,
|
|
64
|
+
number,
|
|
65
|
+
PayloadSignal | PayloadBuffer,
|
|
66
|
+
number,
|
|
67
|
+
number,
|
|
68
|
+
number,
|
|
69
|
+
number,
|
|
70
|
+
number
|
|
71
|
+
] & {
|
|
72
|
+
value: unknown;
|
|
73
|
+
resolve: (value?: unknown) => void;
|
|
74
|
+
reject: (reason?: unknown) => void;
|
|
75
|
+
};
|
|
76
|
+
export declare const PromisePayloadMarker: unique symbol;
|
|
77
|
+
export type PromisePayloadHandler = (task: Task, isRejected: boolean, value: unknown) => void;
|
|
78
|
+
export declare const beginPromisePayload: (task: Task) => boolean;
|
|
79
|
+
export declare const finishPromisePayload: (task: Task) => void;
|
|
80
|
+
export declare const isPromisePayloadPending: (task: Task) => boolean;
|
|
81
|
+
export declare const resetTaskLocalFlags: (task: Task) => void;
|
|
82
|
+
export declare enum TaskIndex {
|
|
83
|
+
/**
|
|
84
|
+
* Worker -> host response flags word.
|
|
85
|
+
*/
|
|
86
|
+
FlagsToHost = 0,
|
|
87
|
+
/**
|
|
88
|
+
* Host -> worker request function id (low 16 bits).
|
|
89
|
+
* High 16 bits are reserved for caller metadata on request path.
|
|
90
|
+
* NOTE: shares the same storage word as `FlagsToHost`.
|
|
91
|
+
*/
|
|
92
|
+
FunctionID = 0,
|
|
93
|
+
ID = 1,
|
|
94
|
+
Type = 2,
|
|
95
|
+
Start = 3,
|
|
96
|
+
End = 4,
|
|
97
|
+
PayloadLen = 5,
|
|
98
|
+
/**
|
|
99
|
+
* Low 5 bits: region slot index (0..31).
|
|
100
|
+
* High 27 bits: reserved for caller metadata (e.g. enqueue timing).
|
|
101
|
+
*/
|
|
102
|
+
slotBuffer = 6,
|
|
103
|
+
Size = 8,
|
|
104
|
+
/**
|
|
105
|
+
* Total slot length in Uint32 words, including the task header.
|
|
106
|
+
*/
|
|
107
|
+
TotalBuff = 144
|
|
108
|
+
}
|
|
109
|
+
export declare const TASK_SLOT_INDEX_BITS = 5;
|
|
110
|
+
export declare const TASK_SLOT_INDEX_MASK: number;
|
|
111
|
+
export declare const TASK_SLOT_META_BITS: number;
|
|
112
|
+
export declare const TASK_SLOT_META_VALUE_MASK: number;
|
|
113
|
+
export declare const TASK_FUNCTION_ID_BITS = 16;
|
|
114
|
+
export declare const TASK_FUNCTION_ID_MASK: number;
|
|
115
|
+
export declare const TASK_FUNCTION_META_BITS: number;
|
|
116
|
+
export declare const TASK_FUNCTION_META_VALUE_MASK: number;
|
|
117
|
+
export declare const getTaskFunctionID: (task: ArrayLike<number>) => number;
|
|
118
|
+
export declare const setTaskFunctionID: (task: Task, functionID: number) => void;
|
|
119
|
+
export declare const getTaskFunctionMeta: (task: ArrayLike<number>) => number;
|
|
120
|
+
export declare const setTaskFunctionMeta: (task: Task, value: number) => void;
|
|
121
|
+
export declare const getTaskSlotIndex: (task: ArrayLike<number>) => number;
|
|
122
|
+
export declare const setTaskSlotIndex: (task: Task, slotIndex: number) => void;
|
|
123
|
+
export declare const getTaskSlotMeta: (task: ArrayLike<number>) => number;
|
|
124
|
+
export declare const setTaskSlotMeta: (task: Task, value: number) => void;
|
|
125
|
+
export declare enum TaskFlag {
|
|
126
|
+
Reject = 1
|
|
127
|
+
}
|
|
128
|
+
export declare const LOCK_WORD_BYTES: number;
|
|
129
|
+
export declare const LOCK_HOST_BITS_OFFSET_BYTES = LockBound.paddingLock;
|
|
130
|
+
export declare const LOCK_WORKER_BITS_OFFSET_BYTES = 64;
|
|
131
|
+
export declare const LOCK_SECTOR_BYTE_LENGTH = 256;
|
|
132
|
+
export declare const PAYLOAD_LOCK_HOST_BITS_OFFSET_BYTES: number;
|
|
133
|
+
export declare const PAYLOAD_LOCK_WORKER_BITS_OFFSET_BYTES: number;
|
|
134
|
+
export declare const PAYLOAD_LOCK_SECTOR_BYTE_LENGTH = 256;
|
|
135
|
+
export declare const HEADER_SLOT_STRIDE_U32: number;
|
|
136
|
+
export declare const HEADER_SLOT_STRIDE_BYTES: number;
|
|
137
|
+
export declare const HEADER_TASK_LINE_U32: number;
|
|
138
|
+
export declare const HEADER_STATIC_PAYLOAD_U32: number;
|
|
139
|
+
export declare const HEADER_TASK_OFFSET_IN_SLOT_U32: number;
|
|
140
|
+
export declare const HEADER_U32_LENGTH: number;
|
|
141
|
+
export declare const HEADER_BYTE_LENGTH: number;
|
|
142
|
+
export declare const makeTask: () => Task;
|
|
143
|
+
type ResolveHostOptions = {
|
|
144
|
+
queue: Task[];
|
|
145
|
+
onResolved?: (task: Task) => void;
|
|
146
|
+
shouldSettle?: (task: Task) => boolean;
|
|
147
|
+
activeRejectPlaceholder?: Task["reject"];
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Complexity: 7 / 10
|
|
151
|
+
*
|
|
152
|
+
* SAFETY:
|
|
153
|
+
* - Single producer/consumer; do not call encode/decode concurrently.
|
|
154
|
+
* - Shared buffers must be the same between host/worker.
|
|
155
|
+
* - encode/decode are not re-entrant; payload codec uses a shared scratch buffer.
|
|
156
|
+
*/
|
|
157
|
+
export type Lock2 = ReturnType<typeof lock2>;
|
|
158
|
+
export declare const lock2: ({ headers, headerSlotStrideU32, LockBoundSector, payload, payloadConfig, payloadSector, textCompat, resultList, toSentList, recycleList, }: {
|
|
159
|
+
headers?: SharedBufferSource;
|
|
160
|
+
headerSlotStrideU32?: number;
|
|
161
|
+
LockBoundSector?: SharedBufferSource;
|
|
162
|
+
payload?: SharedBufferSource;
|
|
163
|
+
payloadConfig?: PayloadBufferOptions;
|
|
164
|
+
payloadSector?: SharedBufferSource;
|
|
165
|
+
textCompat?: LockBufferTextCompat;
|
|
166
|
+
toSentList?: RingQueue<Task>;
|
|
167
|
+
resultList?: RingQueue<Task>;
|
|
168
|
+
recycleList?: RingQueue<Task>;
|
|
169
|
+
}) => {
|
|
170
|
+
enlist: (task: Task) => true;
|
|
171
|
+
encode: (task: Task, state?: number) => boolean;
|
|
172
|
+
encodeManyFrom: (list: RingQueue<Task>) => number;
|
|
173
|
+
encodeAll: () => boolean;
|
|
174
|
+
publish: (task: Task) => boolean;
|
|
175
|
+
flushPending: () => boolean;
|
|
176
|
+
decode: () => boolean;
|
|
177
|
+
hasSpace: () => boolean;
|
|
178
|
+
resolved: RingQueue<Task>;
|
|
179
|
+
hostBits: Int32Array<import("../common/shared-buffer-region.js").SharedBuffer>;
|
|
180
|
+
workerBits: Int32Array<import("../common/shared-buffer-region.js").SharedBuffer>;
|
|
181
|
+
recyclecList: RingQueue<Task>;
|
|
182
|
+
resolveHost: ({ queue, onResolved, shouldSettle, activeRejectPlaceholder, }: ResolveHostOptions) => () => number;
|
|
183
|
+
hasPendingFrames: () => boolean;
|
|
184
|
+
getPendingFrameCount: () => number;
|
|
185
|
+
getPendingPromiseCount: () => number;
|
|
186
|
+
resetPendingState: () => void;
|
|
187
|
+
takeDeferredCount: () => number;
|
|
188
|
+
setPromiseHandler: (handler?: PromisePayloadHandler) => void;
|
|
189
|
+
};
|
|
190
|
+
export {};
|