@ricsam/isolate-daemon 0.1.16 → 0.1.18
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/dist/cjs/callback-fs-handler.cjs +19 -9
- package/dist/cjs/callback-fs-handler.cjs.map +2 -2
- package/dist/cjs/connection.cjs +135 -45
- package/dist/cjs/connection.cjs.map +3 -3
- package/dist/cjs/daemon.cjs +1 -5
- package/dist/cjs/daemon.cjs.map +3 -3
- package/dist/cjs/index.cjs +19 -9
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/types.cjs +14 -8
- package/dist/cjs/types.cjs.map +1 -1
- package/dist/mjs/connection.mjs +117 -37
- package/dist/mjs/connection.mjs.map +3 -3
- package/dist/mjs/daemon.mjs +1 -5
- package/dist/mjs/daemon.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -331,4 +341,4 @@ function createCallbackFileSystemHandler(options) {
|
|
|
331
341
|
};
|
|
332
342
|
}
|
|
333
343
|
|
|
334
|
-
//# debugId=
|
|
344
|
+
//# debugId=A4B3B878B0F2F2C464756E2164756E21
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"/**\n * Callback-based FileSystemHandler adapter.\n *\n * Adapts simple client callbacks (readFile, writeFile, etc.) to the\n * FileSystemHandler interface used by @ricsam/isolate-fs.\n */\n\nimport type { FileSystemHandler } from \"@ricsam/isolate-fs\";\nimport type { ConnectionState, CallbackContext } from \"./types.cjs\";\n\n/** Common MIME type mappings by file extension. */\nconst MIME_TYPES: Record<string, string> = {\n txt: \"text/plain\",\n html: \"text/html\",\n htm: \"text/html\",\n css: \"text/css\",\n js: \"text/javascript\",\n json: \"application/json\",\n xml: \"application/xml\",\n png: \"image/png\",\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n gif: \"image/gif\",\n svg: \"image/svg+xml\",\n pdf: \"application/pdf\",\n};\n\ninterface InvokeClientCallback {\n (connection: ConnectionState, callbackId: number, args: unknown[]): Promise<unknown>;\n}\n\ninterface CallbackFsHandlerOptions {\n connection: ConnectionState;\n callbackContext: CallbackContext;\n invokeClientCallback: InvokeClientCallback;\n basePath?: string;\n}\n\n/**\n * Create a FileSystemHandler that invokes client callbacks.\n *\n * Maps WHATWG FileSystem API operations to simple POSIX-like callbacks.\n * Uses callbackContext for dynamic callback ID lookup to support runtime reuse.\n */\nexport function createCallbackFileSystemHandler(\n options: CallbackFsHandlerOptions\n): FileSystemHandler {\n const { connection, callbackContext, invokeClientCallback, basePath = \"\" } = options;\n\n const resolvePath = (path: string): string => {\n // Remove leading slash from the path\n const cleanPath = path.startsWith(\"/\") ? path.slice(1) : path;\n // Handle root case\n if (!basePath || basePath === \"/\") {\n return `/${cleanPath}`;\n }\n // Remove trailing slash from basePath\n const cleanBase = basePath.endsWith(\"/\") ? basePath.slice(0, -1) : basePath;\n return `${cleanBase}/${cleanPath}`;\n };\n\n // Helper to get current callback ID (supports runtime reuse)\n const getCallbackId = (name: keyof CallbackContext[\"fs\"]): number | undefined => {\n return callbackContext.fs[name];\n };\n\n // Helper to get current connection (supports runtime reuse and reconnection)\n const getConnection = async (): Promise<ConnectionState> => {\n if (callbackContext.connection) {\n return callbackContext.connection;\n }\n if (callbackContext.reconnectionPromise) {\n return callbackContext.reconnectionPromise.promise;\n }\n // Fall back to the originally captured connection\n return connection;\n };\n\n return {\n async getFileHandle(path: string, opts?: { create?: boolean }): Promise<void> {\n const fullPath = resolvePath(path);\n const conn = await getConnection();\n\n if (opts?.create) {\n // Ensure file exists by writing empty content if it doesn't exist\n const writeFileId = getCallbackId(\"writeFile\");\n if (writeFileId !== undefined) {\n try {\n // Check if file exists first\n const statId = getCallbackId(\"stat\");\n if (statId !== undefined) {\n try {\n await invokeClientCallback(conn, statId, [fullPath]);\n // File exists, nothing to do\n return;\n } catch {\n // File doesn't exist, create it\n }\n }\n // Create empty file\n await invokeClientCallback(conn, writeFileId, [\n fullPath,\n new Uint8Array(0),\n ]);\n } catch (err) {\n const error = err as Error;\n throw new Error(`[NotFoundError]${error.message}`);\n }\n }\n return;\n }\n\n // Check file exists\n const statId = getCallbackId(\"stat\");\n if (statId !== undefined) {\n try {\n const result = (await invokeClientCallback(conn, statId, [\n fullPath,\n ])) as { isFile: boolean };\n if (!result.isFile) {\n throw new Error(`[TypeMismatchError]Not a file: ${fullPath}`);\n }\n } catch (err) {\n const error = err as Error;\n if (error.message.includes(\"TypeMismatchError\")) throw error;\n throw new Error(`[NotFoundError]File not found: ${fullPath}`);\n }\n }\n },\n\n async getDirectoryHandle(path: string, opts?: { create?: boolean }): Promise<void> {\n const fullPath = resolvePath(path);\n const conn = await getConnection();\n\n if (opts?.create) {\n const mkdirId = getCallbackId(\"mkdir\");\n if (mkdirId !== undefined) {\n try {\n await invokeClientCallback(conn, mkdirId, [\n fullPath,\n { recursive: true },\n ]);\n } catch {\n // Ignore error if directory already exists\n }\n }\n return;\n }\n\n // Check directory exists\n const statId = getCallbackId(\"stat\");\n if (statId !== undefined) {\n try {\n const result = (await invokeClientCallback(conn, statId, [\n fullPath,\n ])) as { isDirectory: boolean };\n if (!result.isDirectory) {\n throw new Error(`[TypeMismatchError]Not a directory: ${fullPath}`);\n }\n } catch (err) {\n const error = err as Error;\n if (error.message.includes(\"TypeMismatchError\")) throw error;\n throw new Error(`[NotFoundError]Directory not found: ${fullPath}`);\n }\n }\n },\n\n async removeEntry(path: string, opts?: { recursive?: boolean }): Promise<void> {\n const fullPath = resolvePath(path);\n const conn = await getConnection();\n\n // Check if it's a file or directory\n let isFile = true;\n const statId = getCallbackId(\"stat\");\n if (statId !== undefined) {\n try {\n const result = (await invokeClientCallback(conn, statId, [\n fullPath,\n ])) as { isFile: boolean; isDirectory: boolean };\n isFile = result.isFile;\n } catch {\n throw new Error(`[NotFoundError]Entry not found: ${fullPath}`);\n }\n }\n\n if (isFile) {\n const unlinkId = getCallbackId(\"unlink\");\n if (unlinkId === undefined) {\n throw new Error(`[NotAllowedError]File deletion not supported`);\n }\n await invokeClientCallback(conn, unlinkId, [fullPath]);\n } else {\n const rmdirId = getCallbackId(\"rmdir\");\n if (rmdirId === undefined) {\n throw new Error(`[NotAllowedError]Directory deletion not supported`);\n }\n // Note: recursive option may need special handling\n await invokeClientCallback(conn, rmdirId, [fullPath]);\n }\n },\n\n async readDirectory(\n path: string\n ): Promise<Array<{ name: string; kind: \"file\" | \"directory\" }>> {\n const fullPath = resolvePath(path);\n const conn = await getConnection();\n\n const readdirId = getCallbackId(\"readdir\");\n if (readdirId === undefined) {\n throw new Error(`[NotAllowedError]Directory reading not supported`);\n }\n\n const entries = (await invokeClientCallback(conn, readdirId, [\n fullPath,\n ])) as string[];\n\n // We need to stat each entry to determine if it's a file or directory\n const result: Array<{ name: string; kind: \"file\" | \"directory\" }> = [];\n\n const statId = getCallbackId(\"stat\");\n for (const name of entries) {\n const entryPath = fullPath ? `${fullPath}/${name}` : name;\n let kind: \"file\" | \"directory\" = \"file\";\n\n if (statId !== undefined) {\n try {\n const stat = (await invokeClientCallback(conn, statId, [\n entryPath,\n ])) as { isFile: boolean; isDirectory: boolean };\n kind = stat.isDirectory ? \"directory\" : \"file\";\n } catch {\n // Default to file if stat fails\n }\n }\n\n result.push({ name, kind });\n }\n\n return result;\n },\n\n async readFile(\n path: string\n ): Promise<{ data: Uint8Array; size: number; lastModified: number; type: string }> {\n const fullPath = resolvePath(path);\n const conn = await getConnection();\n\n const readFileId = getCallbackId(\"readFile\");\n if (readFileId === undefined) {\n throw new Error(`[NotAllowedError]File reading not supported`);\n }\n\n const data = (await invokeClientCallback(conn, readFileId, [\n fullPath,\n ])) as Uint8Array | ArrayBuffer | number[];\n\n // Convert to Uint8Array if needed\n let bytes: Uint8Array;\n if (data instanceof Uint8Array) {\n bytes = data;\n } else if (Array.isArray(data)) {\n bytes = new Uint8Array(data);\n } else if (data instanceof ArrayBuffer) {\n bytes = new Uint8Array(data);\n } else {\n bytes = new Uint8Array(0);\n }\n\n // Get metadata if stat is available\n let size = bytes.length;\n let lastModified = Date.now();\n\n const statId = getCallbackId(\"stat\");\n if (statId !== undefined) {\n try {\n const stat = (await invokeClientCallback(conn, statId, [\n fullPath,\n ])) as { size: number; lastModified?: number };\n size = stat.size;\n if (stat.lastModified) {\n lastModified = stat.lastModified;\n }\n } catch {\n // Use byte length as fallback\n }\n }\n\n // Determine MIME type from extension\n const ext = path.split(\".\").pop()?.toLowerCase() || \"\";\n const type = MIME_TYPES[ext] || \"application/octet-stream\";\n\n return { data: bytes, size, lastModified, type };\n },\n\n async writeFile(path: string, data: Uint8Array, position?: number): Promise<void> {\n const fullPath = resolvePath(path);\n const conn = await getConnection();\n\n const writeFileId = getCallbackId(\"writeFile\");\n if (writeFileId === undefined) {\n throw new Error(`[NotAllowedError]File writing not supported`);\n }\n\n // Note: position parameter for partial writes may need special handling\n // Simple implementation overwrites entire file\n if (position !== undefined && position > 0) {\n // For positional writes, we need to read existing content and merge\n const readFileId = getCallbackId(\"readFile\");\n if (readFileId !== undefined) {\n try {\n const existing = (await invokeClientCallback(\n conn,\n readFileId,\n [fullPath]\n )) as Uint8Array | ArrayBuffer | number[];\n\n let existingBytes: Uint8Array;\n if (existing instanceof Uint8Array) {\n existingBytes = existing;\n } else if (Array.isArray(existing)) {\n existingBytes = new Uint8Array(existing);\n } else if (existing instanceof ArrayBuffer) {\n existingBytes = new Uint8Array(existing);\n } else {\n existingBytes = new Uint8Array(0);\n }\n\n // Create merged buffer\n const newSize = Math.max(existingBytes.length, position + data.length);\n const merged = new Uint8Array(newSize);\n merged.set(existingBytes);\n merged.set(data, position);\n\n await invokeClientCallback(conn, writeFileId, [\n fullPath,\n merged,\n ]);\n return;\n } catch {\n // File doesn't exist, create new one at position\n const newData = new Uint8Array(position + data.length);\n newData.set(data, position);\n await invokeClientCallback(conn, writeFileId, [\n fullPath,\n newData,\n ]);\n return;\n }\n }\n }\n\n await invokeClientCallback(conn, writeFileId, [fullPath, data]);\n },\n\n async truncateFile(path: string, size: number): Promise<void> {\n const fullPath = resolvePath(path);\n const conn = await getConnection();\n\n const readFileId = getCallbackId(\"readFile\");\n const writeFileId = getCallbackId(\"writeFile\");\n if (readFileId === undefined || writeFileId === undefined) {\n throw new Error(`[NotAllowedError]File truncation not supported`);\n }\n\n // Read existing content\n const existing = (await invokeClientCallback(conn, readFileId, [\n fullPath,\n ])) as Uint8Array | ArrayBuffer | number[];\n\n let existingBytes: Uint8Array;\n if (existing instanceof Uint8Array) {\n existingBytes = existing;\n } else if (Array.isArray(existing)) {\n existingBytes = new Uint8Array(existing);\n } else if (existing instanceof ArrayBuffer) {\n existingBytes = new Uint8Array(existing);\n } else {\n existingBytes = new Uint8Array(0);\n }\n\n // Create truncated buffer\n const truncated = new Uint8Array(size);\n truncated.set(existingBytes.slice(0, size));\n\n await invokeClientCallback(conn, writeFileId, [fullPath, truncated]);\n },\n\n async getFileMetadata(\n path: string\n ): Promise<{ size: number; lastModified: number; type: string }> {\n const fullPath = resolvePath(path);\n const conn = await getConnection();\n\n const statId = getCallbackId(\"stat\");\n if (statId === undefined) {\n throw new Error(`[NotAllowedError]File stat not supported`);\n }\n\n const stat = (await invokeClientCallback(conn, statId, [\n fullPath,\n ])) as { size: number; lastModified?: number; isFile: boolean };\n\n if (!stat.isFile) {\n throw new Error(`[TypeMismatchError]Not a file: ${fullPath}`);\n }\n\n // Determine MIME type from extension\n const ext = path.split(\".\").pop()?.toLowerCase() || \"\";\n const type = MIME_TYPES[ext] || \"application/octet-stream\";\n\n return {\n size: stat.size,\n lastModified: stat.lastModified ?? Date.now(),\n type,\n };\n },\n };\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,IAAM,aAAqC;AAAA,EACzC,KAAK;AAAA,EACL,MAAM;AAAA,EACN,KAAK;AAAA,EACL,KAAK;AA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BAAgB,IAAI,WAAW,CAAC;AAAA;AAAA,MAIlC,MAAM,YAAY,IAAI,WAAW,IAAI;AAAA,MACrC,UAAU,IAAI,cAAc,MAAM,GAAG,IAAI,CAAC;AAAA,MAE1C,MAAM,qBAAqB,MAAM,aAAa,CAAC,UAAU,SAAS,CAAC;AAAA;AAAA,SAG/D,gBAAe,CACnB,MAC+D;AAAA,MAC/D,MAAM,WAAW,YAAY,IAAI;AAAA,MACjC,MAAM,OAAO,MAAM,cAAc;AAAA,MAEjC,MAAM,SAAS,cAAc,MAAM;AAAA,MACnC,IAAI,WAAW,WAAW;AAAA,QACxB,MAAM,IAAI,MAAM,0CAA0C;AAAA,MAC5D;AAAA,MAEA,MAAM,OAAQ,MAAM,qBAAqB,MAAM,QAAQ;AAAA,QACrD;AAAA,MACF,CAAC;AAAA,MAED,IAAI,CAAC,KAAK,QAAQ;AAAA,QAChB,MAAM,IAAI,MAAM,kCAAkC,UAAU;AAAA,MAC9D;AAAA,MAGA,MAAM,MAAM,KAAK,MAAM,GAAG,EAAE,IAAI,GAAG,YAAY,KAAK;AAAA,MACpD,MAAM,OAAO,WAAW,QAAQ;AAAA,MAEhC,OAAO;AAAA,QACL,MAAM,KAAK;AAAA,QACX,cAAc,KAAK,gBAAgB,KAAK,IAAI;AAAA,QAC5C;AAAA,MACF;AAAA;AAAA,EAEJ;AAAA;",
|
|
8
|
+
"debugId": "A4B3B878B0F2F2C464756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/cjs/connection.cjs
CHANGED
|
@@ -2,27 +2,37 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
|
|
5
|
+
function __accessProp(key) {
|
|
6
|
+
return this[key];
|
|
7
|
+
}
|
|
6
8
|
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
9
|
+
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
8
10
|
if (entry)
|
|
9
11
|
return entry;
|
|
10
12
|
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(entry, key))
|
|
16
|
+
__defProp(entry, key, {
|
|
17
|
+
get: __accessProp.bind(from, key),
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
16
21
|
__moduleCache.set(from, entry);
|
|
17
22
|
return entry;
|
|
18
23
|
};
|
|
24
|
+
var __moduleCache;
|
|
25
|
+
var __returnValue = (v) => v;
|
|
26
|
+
function __exportSetter(name, newValue) {
|
|
27
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
+
}
|
|
19
29
|
var __export = (target, all) => {
|
|
20
30
|
for (var name in all)
|
|
21
31
|
__defProp(target, name, {
|
|
22
32
|
get: all[name],
|
|
23
33
|
enumerable: true,
|
|
24
34
|
configurable: true,
|
|
25
|
-
set: (
|
|
35
|
+
set: __exportSetter.bind(all, name)
|
|
26
36
|
});
|
|
27
37
|
};
|
|
28
38
|
|
|
@@ -69,7 +79,9 @@ function handleConnection(socket, state) {
|
|
|
69
79
|
nextStreamId: 1,
|
|
70
80
|
activeStreams: new Map,
|
|
71
81
|
streamReceivers: new Map,
|
|
72
|
-
callbackStreamReceivers: new Map
|
|
82
|
+
callbackStreamReceivers: new Map,
|
|
83
|
+
dispatchAbortControllers: new Map,
|
|
84
|
+
earlyAbortedDispatches: new Set
|
|
73
85
|
};
|
|
74
86
|
state.connections.set(socket, connection);
|
|
75
87
|
const parser = import_isolate_protocol.createFrameParser();
|
|
@@ -86,6 +98,14 @@ function handleConnection(socket, state) {
|
|
|
86
98
|
}
|
|
87
99
|
});
|
|
88
100
|
socket.on("close", () => {
|
|
101
|
+
for (const streamId of Array.from(connection.activeStreams.keys())) {
|
|
102
|
+
closeActiveDownloadSession(connection, streamId);
|
|
103
|
+
}
|
|
104
|
+
for (const [, controller] of connection.dispatchAbortControllers) {
|
|
105
|
+
controller.abort();
|
|
106
|
+
}
|
|
107
|
+
connection.dispatchAbortControllers.clear();
|
|
108
|
+
connection.earlyAbortedDispatches.clear();
|
|
89
109
|
for (const isolateId of connection.isolates) {
|
|
90
110
|
const instance = state.isolates.get(isolateId);
|
|
91
111
|
if (instance) {
|
|
@@ -114,6 +134,22 @@ function sendMessage(socket, message) {
|
|
|
114
134
|
const frame = import_isolate_protocol.buildFrame(message);
|
|
115
135
|
socket.write(frame);
|
|
116
136
|
}
|
|
137
|
+
function closeActiveDownloadSession(connection, streamId) {
|
|
138
|
+
const session = connection.activeStreams.get(streamId);
|
|
139
|
+
if (!session) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
session.state = "closed";
|
|
143
|
+
if (session.creditResolver) {
|
|
144
|
+
session.creditResolver();
|
|
145
|
+
session.creditResolver = undefined;
|
|
146
|
+
}
|
|
147
|
+
if (session.cancelReader) {
|
|
148
|
+
session.cancelReader();
|
|
149
|
+
session.cancelReader = undefined;
|
|
150
|
+
}
|
|
151
|
+
connection.activeStreams.delete(streamId);
|
|
152
|
+
}
|
|
117
153
|
function sendError(socket, requestId, code, message, details) {
|
|
118
154
|
const response = {
|
|
119
155
|
type: import_isolate_protocol.MessageType.RESPONSE_ERROR,
|
|
@@ -147,6 +183,9 @@ async function handleMessage(message, connection, state) {
|
|
|
147
183
|
case import_isolate_protocol.MessageType.DISPATCH_REQUEST:
|
|
148
184
|
await handleDispatchRequest(message, connection, state);
|
|
149
185
|
break;
|
|
186
|
+
case import_isolate_protocol.MessageType.DISPATCH_REQUEST_ABORT:
|
|
187
|
+
handleDispatchRequestAbort(message, connection);
|
|
188
|
+
break;
|
|
150
189
|
case import_isolate_protocol.MessageType.CALLBACK_RESPONSE:
|
|
151
190
|
handleCallbackResponse(message, connection);
|
|
152
191
|
break;
|
|
@@ -756,7 +795,8 @@ async function handleCreateRuntime(message, connection, state) {
|
|
|
756
795
|
url,
|
|
757
796
|
method: init.method,
|
|
758
797
|
headers: init.headers,
|
|
759
|
-
body: init.rawBody
|
|
798
|
+
body: init.rawBody,
|
|
799
|
+
signalAborted: init.signal.aborted
|
|
760
800
|
};
|
|
761
801
|
const result = await invokeCallbackWithReconnect(callbackContext, () => callbackContext.fetch, [serialized], "Fetch", invokeClientCallback);
|
|
762
802
|
if (result && typeof result === "object" && result.__streamingResponse) {
|
|
@@ -996,6 +1036,12 @@ async function handleDispatchRequest(message, connection, state) {
|
|
|
996
1036
|
return;
|
|
997
1037
|
}
|
|
998
1038
|
instance.lastActivity = Date.now();
|
|
1039
|
+
const dispatchAbortController = new AbortController;
|
|
1040
|
+
connection.dispatchAbortControllers.set(message.requestId, dispatchAbortController);
|
|
1041
|
+
if (connection.earlyAbortedDispatches.has(message.requestId) || message.request.signalAborted) {
|
|
1042
|
+
dispatchAbortController.abort();
|
|
1043
|
+
connection.earlyAbortedDispatches.delete(message.requestId);
|
|
1044
|
+
}
|
|
999
1045
|
try {
|
|
1000
1046
|
let requestBody = null;
|
|
1001
1047
|
if (message.request.bodyStreamId !== undefined) {
|
|
@@ -1006,9 +1052,12 @@ async function handleDispatchRequest(message, connection, state) {
|
|
|
1006
1052
|
const request = new Request(message.request.url, {
|
|
1007
1053
|
method: message.request.method,
|
|
1008
1054
|
headers: message.request.headers,
|
|
1009
|
-
body: requestBody
|
|
1055
|
+
body: requestBody,
|
|
1056
|
+
signal: dispatchAbortController.signal
|
|
1057
|
+
});
|
|
1058
|
+
const response = await instance.runtime.fetch.dispatchRequest(request, {
|
|
1059
|
+
signal: dispatchAbortController.signal
|
|
1010
1060
|
});
|
|
1011
|
-
const response = await instance.runtime.fetch.dispatchRequest(request);
|
|
1012
1061
|
if (response.body) {
|
|
1013
1062
|
await sendStreamedResponse(connection, message.requestId, response);
|
|
1014
1063
|
} else {
|
|
@@ -1028,7 +1077,18 @@ async function handleDispatchRequest(message, connection, state) {
|
|
|
1028
1077
|
} catch (err) {
|
|
1029
1078
|
const error = err;
|
|
1030
1079
|
sendError(connection.socket, message.requestId, import_isolate_protocol.ErrorCode.SCRIPT_ERROR, error.message, { name: error.name, stack: error.stack });
|
|
1080
|
+
} finally {
|
|
1081
|
+
connection.dispatchAbortControllers.delete(message.requestId);
|
|
1082
|
+
connection.earlyAbortedDispatches.delete(message.requestId);
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
function handleDispatchRequestAbort(message, connection) {
|
|
1086
|
+
const controller = connection.dispatchAbortControllers.get(message.targetRequestId);
|
|
1087
|
+
if (controller) {
|
|
1088
|
+
controller.abort();
|
|
1089
|
+
return;
|
|
1031
1090
|
}
|
|
1091
|
+
connection.earlyAbortedDispatches.add(message.targetRequestId);
|
|
1032
1092
|
}
|
|
1033
1093
|
function receiveStreamedBody(connection, streamId) {
|
|
1034
1094
|
return new Promise((resolve, reject) => {
|
|
@@ -1349,8 +1409,7 @@ function handleStreamError(message, connection) {
|
|
|
1349
1409
|
}
|
|
1350
1410
|
const session = connection.activeStreams.get(message.streamId);
|
|
1351
1411
|
if (session) {
|
|
1352
|
-
|
|
1353
|
-
connection.activeStreams.delete(message.streamId);
|
|
1412
|
+
closeActiveDownloadSession(connection, message.streamId);
|
|
1354
1413
|
}
|
|
1355
1414
|
const callbackReceiver = connection.callbackStreamReceivers.get(message.streamId);
|
|
1356
1415
|
if (callbackReceiver && callbackReceiver.state === "active") {
|
|
@@ -1469,6 +1528,7 @@ function waitForCredit(session) {
|
|
|
1469
1528
|
});
|
|
1470
1529
|
}
|
|
1471
1530
|
async function sendStreamedResponse(connection, requestId, response) {
|
|
1531
|
+
const SEND_LOOP_YIELD_BYTES = 64 * 1024;
|
|
1472
1532
|
const streamId = connection.nextStreamId++;
|
|
1473
1533
|
const headers = [];
|
|
1474
1534
|
response.headers.forEach((value, key) => {
|
|
@@ -1504,38 +1564,61 @@ async function sendStreamedResponse(connection, requestId, response) {
|
|
|
1504
1564
|
};
|
|
1505
1565
|
connection.activeStreams.set(streamId, session);
|
|
1506
1566
|
const reader = response.body.getReader();
|
|
1567
|
+
session.cancelReader = () => {
|
|
1568
|
+
reader.cancel("Stream cancelled by client").catch(() => {});
|
|
1569
|
+
};
|
|
1570
|
+
let cancelledByClient = false;
|
|
1571
|
+
let bytesSinceYield = 0;
|
|
1572
|
+
let chunksSinceYield = 0;
|
|
1507
1573
|
try {
|
|
1508
|
-
|
|
1509
|
-
while (
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
const
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1574
|
+
streamLoop:
|
|
1575
|
+
while (true) {
|
|
1576
|
+
while (session.credit < import_isolate_protocol.STREAM_CHUNK_SIZE && session.state === "active") {
|
|
1577
|
+
await waitForCredit(session);
|
|
1578
|
+
}
|
|
1579
|
+
if (session.state !== "active") {
|
|
1580
|
+
cancelledByClient = true;
|
|
1581
|
+
break;
|
|
1582
|
+
}
|
|
1583
|
+
const { done, value } = await reader.read();
|
|
1584
|
+
if (done) {
|
|
1585
|
+
const endMsg = {
|
|
1586
|
+
type: import_isolate_protocol.MessageType.RESPONSE_STREAM_END,
|
|
1587
|
+
requestId,
|
|
1588
|
+
streamId
|
|
1589
|
+
};
|
|
1590
|
+
sendMessage(connection.socket, endMsg);
|
|
1591
|
+
break;
|
|
1592
|
+
}
|
|
1593
|
+
for (let offset = 0;offset < value.length; offset += import_isolate_protocol.STREAM_CHUNK_SIZE) {
|
|
1594
|
+
const chunk = value.slice(offset, offset + import_isolate_protocol.STREAM_CHUNK_SIZE);
|
|
1595
|
+
const chunkMsg = {
|
|
1596
|
+
type: import_isolate_protocol.MessageType.RESPONSE_STREAM_CHUNK,
|
|
1597
|
+
requestId,
|
|
1598
|
+
streamId,
|
|
1599
|
+
chunk
|
|
1600
|
+
};
|
|
1601
|
+
sendMessage(connection.socket, chunkMsg);
|
|
1602
|
+
const creditCost = Math.max(chunk.length, import_isolate_protocol.STREAM_CHUNK_SIZE);
|
|
1603
|
+
session.credit -= creditCost;
|
|
1604
|
+
session.bytesTransferred += chunk.length;
|
|
1605
|
+
bytesSinceYield += chunk.length;
|
|
1606
|
+
chunksSinceYield += 1;
|
|
1607
|
+
if (chunk.length < 1024 || bytesSinceYield >= SEND_LOOP_YIELD_BYTES || chunksSinceYield >= 256) {
|
|
1608
|
+
bytesSinceYield = 0;
|
|
1609
|
+
chunksSinceYield = 0;
|
|
1610
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
1611
|
+
if (session.state !== "active") {
|
|
1612
|
+
cancelledByClient = true;
|
|
1613
|
+
break streamLoop;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1536
1617
|
}
|
|
1537
|
-
}
|
|
1538
1618
|
} catch (err) {
|
|
1619
|
+
if (cancelledByClient || session.state !== "active") {
|
|
1620
|
+
return;
|
|
1621
|
+
}
|
|
1539
1622
|
const errorMsg = {
|
|
1540
1623
|
type: import_isolate_protocol.MessageType.STREAM_ERROR,
|
|
1541
1624
|
streamId,
|
|
@@ -1543,8 +1626,15 @@ async function sendStreamedResponse(connection, requestId, response) {
|
|
|
1543
1626
|
};
|
|
1544
1627
|
sendMessage(connection.socket, errorMsg);
|
|
1545
1628
|
} finally {
|
|
1629
|
+
if (cancelledByClient) {
|
|
1630
|
+
await Promise.race([
|
|
1631
|
+
reader.cancel("Stream cancelled by client").catch(() => {}),
|
|
1632
|
+
new Promise((resolve) => setTimeout(resolve, 50))
|
|
1633
|
+
]);
|
|
1634
|
+
}
|
|
1635
|
+
session.cancelReader = undefined;
|
|
1546
1636
|
reader.releaseLock();
|
|
1547
|
-
connection
|
|
1637
|
+
closeActiveDownloadSession(connection, streamId);
|
|
1548
1638
|
}
|
|
1549
1639
|
}
|
|
1550
1640
|
async function handleRunTests(message, connection, state) {
|
|
@@ -1661,4 +1751,4 @@ async function handleClearCollectedData(message, connection, state) {
|
|
|
1661
1751
|
}
|
|
1662
1752
|
}
|
|
1663
1753
|
|
|
1664
|
-
//# debugId=
|
|
1754
|
+
//# debugId=E73567439C8E8F2D64756E2164756E21
|