@ricsam/isolate-client 0.1.22 → 0.1.23
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/connection.cjs
CHANGED
|
@@ -90,6 +90,8 @@ async function connect(options = {}) {
|
|
|
90
90
|
uploadStreams: new Map,
|
|
91
91
|
moduleSourceCache: new Map,
|
|
92
92
|
callbackStreamReaders: new Map,
|
|
93
|
+
activeCallbackInvocations: new Map,
|
|
94
|
+
callbackAbortControllers: new Map,
|
|
93
95
|
closing: false,
|
|
94
96
|
namespacedRuntimes: new Map
|
|
95
97
|
};
|
|
@@ -126,6 +128,11 @@ async function connect(options = {}) {
|
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
state.uploadStreams.clear();
|
|
131
|
+
for (const [, controller] of state.callbackAbortControllers) {
|
|
132
|
+
controller.abort();
|
|
133
|
+
}
|
|
134
|
+
state.callbackAbortControllers.clear();
|
|
135
|
+
state.activeCallbackInvocations.clear();
|
|
129
136
|
if (!state.closing && state.namespacedRuntimes.size > 0) {
|
|
130
137
|
state.reconnecting = reconnect(state, options).catch(() => {
|
|
131
138
|
state.namespacedRuntimes.clear();
|
|
@@ -311,6 +318,18 @@ function handleMessage(message, state) {
|
|
|
311
318
|
}
|
|
312
319
|
break;
|
|
313
320
|
}
|
|
321
|
+
case import_isolate_protocol.MessageType.CALLBACK_ABORT: {
|
|
322
|
+
const msg = message;
|
|
323
|
+
const invocation = state.activeCallbackInvocations.get(msg.targetRequestId);
|
|
324
|
+
if (invocation) {
|
|
325
|
+
invocation.aborted = true;
|
|
326
|
+
}
|
|
327
|
+
const controller = state.callbackAbortControllers.get(msg.targetRequestId);
|
|
328
|
+
if (controller && !controller.signal.aborted) {
|
|
329
|
+
controller.abort();
|
|
330
|
+
}
|
|
331
|
+
break;
|
|
332
|
+
}
|
|
314
333
|
case import_isolate_protocol.MessageType.ISOLATE_EVENT: {
|
|
315
334
|
const msg = message;
|
|
316
335
|
handleIsolateEvent(msg, state);
|
|
@@ -473,6 +492,8 @@ function handleMessage(message, state) {
|
|
|
473
492
|
}
|
|
474
493
|
async function handleCallbackInvoke(invoke, state) {
|
|
475
494
|
const callback = state.callbacks.get(invoke.callbackId);
|
|
495
|
+
const invocationState = { aborted: false };
|
|
496
|
+
state.activeCallbackInvocations.set(invoke.requestId, invocationState);
|
|
476
497
|
const response = {
|
|
477
498
|
type: import_isolate_protocol.MessageType.CALLBACK_RESPONSE,
|
|
478
499
|
requestId: invoke.requestId
|
|
@@ -482,7 +503,10 @@ async function handleCallbackInvoke(invoke, state) {
|
|
|
482
503
|
name: "Error",
|
|
483
504
|
message: `Unknown callback: ${invoke.callbackId}`
|
|
484
505
|
};
|
|
485
|
-
|
|
506
|
+
if (!invocationState.aborted) {
|
|
507
|
+
sendMessage(state.socket, response);
|
|
508
|
+
}
|
|
509
|
+
state.activeCallbackInvocations.delete(invoke.requestId);
|
|
486
510
|
} else {
|
|
487
511
|
try {
|
|
488
512
|
const needsRequestId = state.callbacksNeedingRequestId.has(invoke.callbackId);
|
|
@@ -490,9 +514,15 @@ async function handleCallbackInvoke(invoke, state) {
|
|
|
490
514
|
if (result && typeof result === "object" && result.__callbackStreaming) {
|
|
491
515
|
return;
|
|
492
516
|
}
|
|
517
|
+
if (invocationState.aborted) {
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
493
520
|
response.result = result;
|
|
494
521
|
sendMessage(state.socket, response);
|
|
495
522
|
} catch (err) {
|
|
523
|
+
if (invocationState.aborted) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
496
526
|
const error = err;
|
|
497
527
|
response.error = {
|
|
498
528
|
name: error.name,
|
|
@@ -500,6 +530,8 @@ async function handleCallbackInvoke(invoke, state) {
|
|
|
500
530
|
stack: error.stack
|
|
501
531
|
};
|
|
502
532
|
sendMessage(state.socket, response);
|
|
533
|
+
} finally {
|
|
534
|
+
state.activeCallbackInvocations.delete(invoke.requestId);
|
|
503
535
|
}
|
|
504
536
|
}
|
|
505
537
|
}
|
|
@@ -1105,42 +1137,52 @@ function registerFetchCallback(state, callback) {
|
|
|
1105
1137
|
state.callbacks.set(callbackId, async (serialized, requestId) => {
|
|
1106
1138
|
const data = serialized;
|
|
1107
1139
|
const signalController = new AbortController;
|
|
1140
|
+
const callbackRequestId = typeof requestId === "number" ? requestId : undefined;
|
|
1141
|
+
if (callbackRequestId !== undefined) {
|
|
1142
|
+
state.callbackAbortControllers.set(callbackRequestId, signalController);
|
|
1143
|
+
}
|
|
1108
1144
|
if (data.signalAborted) {
|
|
1109
1145
|
signalController.abort();
|
|
1110
1146
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
headers.
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1147
|
+
try {
|
|
1148
|
+
const init = {
|
|
1149
|
+
method: data.method,
|
|
1150
|
+
headers: data.headers,
|
|
1151
|
+
rawBody: data.body ?? null,
|
|
1152
|
+
body: data.body ?? null,
|
|
1153
|
+
signal: signalController.signal
|
|
1154
|
+
};
|
|
1155
|
+
const response = await callback(data.url, init);
|
|
1156
|
+
const contentLength = response.headers.get("content-length");
|
|
1157
|
+
const knownSize = contentLength ? parseInt(contentLength, 10) : null;
|
|
1158
|
+
const isNetworkResponse = response.url && (response.url.startsWith("http://") || response.url.startsWith("https://"));
|
|
1159
|
+
const shouldStream = isNetworkResponse && !NULL_BODY_STATUSES.has(response.status) && !!response.body && (knownSize === null || knownSize > CALLBACK_STREAM_THRESHOLD);
|
|
1160
|
+
if (shouldStream && response.body) {
|
|
1161
|
+
const streamId = state.nextStreamId++;
|
|
1162
|
+
const headers = [];
|
|
1163
|
+
response.headers.forEach((value, key) => {
|
|
1164
|
+
headers.push([key, value]);
|
|
1165
|
+
});
|
|
1166
|
+
sendMessage(state.socket, {
|
|
1167
|
+
type: import_isolate_protocol.MessageType.CALLBACK_STREAM_START,
|
|
1168
|
+
requestId,
|
|
1169
|
+
streamId,
|
|
1170
|
+
metadata: {
|
|
1171
|
+
status: response.status,
|
|
1172
|
+
statusText: response.statusText,
|
|
1173
|
+
headers,
|
|
1174
|
+
url: response.url || undefined
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
streamCallbackResponseBody(state, streamId, requestId, response.body);
|
|
1178
|
+
return { __callbackStreaming: true, streamId };
|
|
1179
|
+
}
|
|
1180
|
+
return import_isolate_protocol.serializeResponse(response);
|
|
1181
|
+
} finally {
|
|
1182
|
+
if (callbackRequestId !== undefined) {
|
|
1183
|
+
state.callbackAbortControllers.delete(callbackRequestId);
|
|
1184
|
+
}
|
|
1142
1185
|
}
|
|
1143
|
-
return import_isolate_protocol.serializeResponse(response);
|
|
1144
1186
|
});
|
|
1145
1187
|
return { callbackId, name: "fetch", type: "async" };
|
|
1146
1188
|
}
|
|
@@ -1742,4 +1784,4 @@ function handleClientWsClose(isolateId, payload, state) {
|
|
|
1742
1784
|
}
|
|
1743
1785
|
}
|
|
1744
1786
|
|
|
1745
|
-
//# debugId=
|
|
1787
|
+
//# debugId=FBC99A585051CDE264756E2164756E21
|