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/utils.d.ts
CHANGED
|
@@ -1,31 +1 @@
|
|
|
1
|
-
export type BufferLike
|
|
2
|
-
export type NumberFormat = "f64" | "f32" | "i32";
|
|
3
|
-
export type NumberBufferOptions = {
|
|
4
|
-
format?: NumberFormat;
|
|
5
|
-
};
|
|
6
|
-
/** View ArrayBuffer/SharedArrayBuffer/typed-array bytes as Uint8Array. */
|
|
7
|
-
export declare const bufferToBytes: (source: BufferLike) => Uint8Array;
|
|
8
|
-
/** Copy bytes into a SharedArrayBuffer for zero-copy worker inputs. */
|
|
9
|
-
export declare const bytesToBuffer: (source: BufferLike) => SharedArrayBuffer;
|
|
10
|
-
/** Decode UTF-8 bytes from ArrayBuffer/SharedArrayBuffer/typed-array input. */
|
|
11
|
-
export declare const bufferToString: (source: BufferLike) => string;
|
|
12
|
-
/** Encode UTF-8 text into a SharedArrayBuffer. */
|
|
13
|
-
export declare const stringToBuffer: (text: string) => SharedArrayBuffer;
|
|
14
|
-
/** Decode JSON from UTF-8 bytes. */
|
|
15
|
-
export declare const bufferToJson: <T = unknown>(source: BufferLike) => T;
|
|
16
|
-
/** Encode JSON into a SharedArrayBuffer. */
|
|
17
|
-
export declare const jsonToBuffer: (value: unknown) => SharedArrayBuffer;
|
|
18
|
-
/** Encode numbers into a SharedArrayBuffer (`f64` by default). */
|
|
19
|
-
export declare const numbersToBuffer: (numbers: ArrayLike<number>, options?: NumberBufferOptions) => SharedArrayBuffer;
|
|
20
|
-
/** Decode numeric typed-array views from worker-friendly byte buffers. */
|
|
21
|
-
export declare function bufferToNumbers(source: BufferLike, options?: {
|
|
22
|
-
format?: "f64";
|
|
23
|
-
}): Float64Array;
|
|
24
|
-
export declare function bufferToNumbers(source: BufferLike, options: {
|
|
25
|
-
format: "f32";
|
|
26
|
-
}): Float32Array;
|
|
27
|
-
export declare function bufferToNumbers(source: BufferLike, options: {
|
|
28
|
-
format: "i32";
|
|
29
|
-
}): Int32Array;
|
|
30
|
-
|
|
31
|
-
export {};
|
|
1
|
+
export { type BufferLike, bufferToBytes, bufferToJson, bufferToNumbers, bufferToString, bytesToBuffer, jsonToBuffer, type NumberBufferOptions, type NumberFormat, numbersToBuffer, stringToBuffer, } from "./src/utils/http.js";
|
package/utils.js
CHANGED
|
@@ -1,116 +1 @@
|
|
|
1
|
-
|
|
2
|
-
var __returnValue = (v) => v;
|
|
3
|
-
function __exportSetter(name, newValue) {
|
|
4
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
5
|
-
}
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true,
|
|
11
|
-
configurable: true,
|
|
12
|
-
set: __exportSetter.bind(all, name)
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
16
|
-
|
|
17
|
-
// src/utils/http.ts
|
|
18
|
-
var nodeBuffer = globalThis.Buffer;
|
|
19
|
-
var hasNodeBuffer = typeof nodeBuffer?.from === "function" && typeof nodeBuffer?.byteLength === "function";
|
|
20
|
-
var textEncoder = new TextEncoder;
|
|
21
|
-
var textDecoder = new TextDecoder;
|
|
22
|
-
var hasSharedArrayBuffer = typeof SharedArrayBuffer === "function";
|
|
23
|
-
var isSharedArrayBuffer = (value) => hasSharedArrayBuffer && value instanceof SharedArrayBuffer;
|
|
24
|
-
var BYTES_PER_ELEMENT = {
|
|
25
|
-
f64: 8,
|
|
26
|
-
f32: 4,
|
|
27
|
-
i32: 4
|
|
28
|
-
};
|
|
29
|
-
var toBytes = (source) => {
|
|
30
|
-
if (source instanceof Uint8Array)
|
|
31
|
-
return source;
|
|
32
|
-
if (ArrayBuffer.isView(source)) {
|
|
33
|
-
return new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
34
|
-
}
|
|
35
|
-
if (source instanceof ArrayBuffer || isSharedArrayBuffer(source)) {
|
|
36
|
-
return new Uint8Array(source);
|
|
37
|
-
}
|
|
38
|
-
throw new TypeError("Expected an ArrayBuffer, SharedArrayBuffer, or typed-array view.");
|
|
39
|
-
};
|
|
40
|
-
var bufferToBytes = (source) => toBytes(source);
|
|
41
|
-
var bytesToBuffer = (source) => {
|
|
42
|
-
const bytes = toBytes(source);
|
|
43
|
-
const sab = new SharedArrayBuffer(bytes.byteLength);
|
|
44
|
-
new Uint8Array(sab).set(bytes);
|
|
45
|
-
return sab;
|
|
46
|
-
};
|
|
47
|
-
var makeNumberView = (format, buffer, byteOffset, length) => {
|
|
48
|
-
switch (format) {
|
|
49
|
-
case "f64":
|
|
50
|
-
return new Float64Array(buffer, byteOffset, length);
|
|
51
|
-
case "f32":
|
|
52
|
-
return new Float32Array(buffer, byteOffset, length);
|
|
53
|
-
case "i32":
|
|
54
|
-
return new Int32Array(buffer, byteOffset, length);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
var bufferToString = (source) => {
|
|
58
|
-
const bytes = toBytes(source);
|
|
59
|
-
if (hasNodeBuffer) {
|
|
60
|
-
return nodeBuffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString("utf8");
|
|
61
|
-
}
|
|
62
|
-
return textDecoder.decode(bytes);
|
|
63
|
-
};
|
|
64
|
-
var stringToBuffer = (text) => {
|
|
65
|
-
if (typeof text !== "string") {
|
|
66
|
-
throw new TypeError("stringToBuffer expects a string.");
|
|
67
|
-
}
|
|
68
|
-
if (hasNodeBuffer) {
|
|
69
|
-
const byteLength = nodeBuffer.byteLength(text, "utf8");
|
|
70
|
-
const sab2 = new SharedArrayBuffer(byteLength);
|
|
71
|
-
nodeBuffer.from(sab2).write(text, "utf8");
|
|
72
|
-
return sab2;
|
|
73
|
-
}
|
|
74
|
-
const encoded = textEncoder.encode(text);
|
|
75
|
-
const sab = new SharedArrayBuffer(encoded.byteLength);
|
|
76
|
-
new Uint8Array(sab).set(encoded);
|
|
77
|
-
return sab;
|
|
78
|
-
};
|
|
79
|
-
var bufferToJson = (source) => JSON.parse(bufferToString(source));
|
|
80
|
-
var jsonToBuffer = (value) => {
|
|
81
|
-
const text = JSON.stringify(value);
|
|
82
|
-
if (typeof text !== "string") {
|
|
83
|
-
throw new TypeError("jsonToBuffer: value is not JSON-serializable (stringify returned undefined).");
|
|
84
|
-
}
|
|
85
|
-
return stringToBuffer(text);
|
|
86
|
-
};
|
|
87
|
-
var numbersToBuffer = (numbers, options) => {
|
|
88
|
-
const format = options?.format ?? "f64";
|
|
89
|
-
const sab = new SharedArrayBuffer(numbers.length * BYTES_PER_ELEMENT[format]);
|
|
90
|
-
makeNumberView(format, sab, 0, numbers.length).set(numbers);
|
|
91
|
-
return sab;
|
|
92
|
-
};
|
|
93
|
-
function bufferToNumbers(source, options) {
|
|
94
|
-
const format = options?.format ?? "f64";
|
|
95
|
-
const bytesPer = BYTES_PER_ELEMENT[format];
|
|
96
|
-
const bytes = toBytes(source);
|
|
97
|
-
if (bytes.byteLength % bytesPer !== 0) {
|
|
98
|
-
throw new RangeError(`bufferToNumbers: byte length ${bytes.byteLength} is not a multiple of ` + `${bytesPer} for format "${format}".`);
|
|
99
|
-
}
|
|
100
|
-
const length = bytes.byteLength / bytesPer;
|
|
101
|
-
if (bytes.byteOffset % bytesPer === 0) {
|
|
102
|
-
return makeNumberView(format, bytes.buffer, bytes.byteOffset, length);
|
|
103
|
-
}
|
|
104
|
-
const copy = bytes.slice();
|
|
105
|
-
return makeNumberView(format, copy.buffer, 0, length);
|
|
106
|
-
}
|
|
107
|
-
export {
|
|
108
|
-
stringToBuffer,
|
|
109
|
-
numbersToBuffer,
|
|
110
|
-
jsonToBuffer,
|
|
111
|
-
bytesToBuffer,
|
|
112
|
-
bufferToString,
|
|
113
|
-
bufferToNumbers,
|
|
114
|
-
bufferToJson,
|
|
115
|
-
bufferToBytes
|
|
116
|
-
};
|
|
1
|
+
export { bufferToBytes, bufferToJson, bufferToNumbers, bufferToString, bytesToBuffer, jsonToBuffer, numbersToBuffer, stringToBuffer, } from "./src/utils/http.js";
|