@ricsam/isolate-client 0.1.22 → 0.1.24
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();
|
|
@@ -211,6 +218,7 @@ async function connect(options = {}) {
|
|
|
211
218
|
requestId,
|
|
212
219
|
options: {
|
|
213
220
|
memoryLimitMB: runtimeOptions.memoryLimitMB,
|
|
221
|
+
executionTimeout: runtimeOptions.executionTimeout,
|
|
214
222
|
cwd: runtimeOptions.cwd,
|
|
215
223
|
callbacks,
|
|
216
224
|
testEnvironment: testEnvironmentOption,
|
|
@@ -311,6 +319,18 @@ function handleMessage(message, state) {
|
|
|
311
319
|
}
|
|
312
320
|
break;
|
|
313
321
|
}
|
|
322
|
+
case import_isolate_protocol.MessageType.CALLBACK_ABORT: {
|
|
323
|
+
const msg = message;
|
|
324
|
+
const invocation = state.activeCallbackInvocations.get(msg.targetRequestId);
|
|
325
|
+
if (invocation) {
|
|
326
|
+
invocation.aborted = true;
|
|
327
|
+
}
|
|
328
|
+
const controller = state.callbackAbortControllers.get(msg.targetRequestId);
|
|
329
|
+
if (controller && !controller.signal.aborted) {
|
|
330
|
+
controller.abort();
|
|
331
|
+
}
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
314
334
|
case import_isolate_protocol.MessageType.ISOLATE_EVENT: {
|
|
315
335
|
const msg = message;
|
|
316
336
|
handleIsolateEvent(msg, state);
|
|
@@ -473,6 +493,8 @@ function handleMessage(message, state) {
|
|
|
473
493
|
}
|
|
474
494
|
async function handleCallbackInvoke(invoke, state) {
|
|
475
495
|
const callback = state.callbacks.get(invoke.callbackId);
|
|
496
|
+
const invocationState = { aborted: false };
|
|
497
|
+
state.activeCallbackInvocations.set(invoke.requestId, invocationState);
|
|
476
498
|
const response = {
|
|
477
499
|
type: import_isolate_protocol.MessageType.CALLBACK_RESPONSE,
|
|
478
500
|
requestId: invoke.requestId
|
|
@@ -482,7 +504,10 @@ async function handleCallbackInvoke(invoke, state) {
|
|
|
482
504
|
name: "Error",
|
|
483
505
|
message: `Unknown callback: ${invoke.callbackId}`
|
|
484
506
|
};
|
|
485
|
-
|
|
507
|
+
if (!invocationState.aborted) {
|
|
508
|
+
sendMessage(state.socket, response);
|
|
509
|
+
}
|
|
510
|
+
state.activeCallbackInvocations.delete(invoke.requestId);
|
|
486
511
|
} else {
|
|
487
512
|
try {
|
|
488
513
|
const needsRequestId = state.callbacksNeedingRequestId.has(invoke.callbackId);
|
|
@@ -490,9 +515,15 @@ async function handleCallbackInvoke(invoke, state) {
|
|
|
490
515
|
if (result && typeof result === "object" && result.__callbackStreaming) {
|
|
491
516
|
return;
|
|
492
517
|
}
|
|
518
|
+
if (invocationState.aborted) {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
493
521
|
response.result = result;
|
|
494
522
|
sendMessage(state.socket, response);
|
|
495
523
|
} catch (err) {
|
|
524
|
+
if (invocationState.aborted) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
496
527
|
const error = err;
|
|
497
528
|
response.error = {
|
|
498
529
|
name: error.name,
|
|
@@ -500,6 +531,8 @@ async function handleCallbackInvoke(invoke, state) {
|
|
|
500
531
|
stack: error.stack
|
|
501
532
|
};
|
|
502
533
|
sendMessage(state.socket, response);
|
|
534
|
+
} finally {
|
|
535
|
+
state.activeCallbackInvocations.delete(invoke.requestId);
|
|
503
536
|
}
|
|
504
537
|
}
|
|
505
538
|
}
|
|
@@ -680,6 +713,7 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
680
713
|
requestId,
|
|
681
714
|
options: {
|
|
682
715
|
memoryLimitMB: options.memoryLimitMB,
|
|
716
|
+
executionTimeout: options.executionTimeout,
|
|
683
717
|
cwd: options.cwd,
|
|
684
718
|
callbacks,
|
|
685
719
|
testEnvironment: testEnvironmentOption,
|
|
@@ -1009,7 +1043,8 @@ async function createRuntime(state, options = {}, namespaceId) {
|
|
|
1009
1043
|
requestId: reqId,
|
|
1010
1044
|
isolateId,
|
|
1011
1045
|
code,
|
|
1012
|
-
filename: options2?.filename
|
|
1046
|
+
filename: options2?.filename,
|
|
1047
|
+
executionTimeout: options2?.executionTimeout
|
|
1013
1048
|
};
|
|
1014
1049
|
await sendRequest(state, req);
|
|
1015
1050
|
},
|
|
@@ -1105,42 +1140,52 @@ function registerFetchCallback(state, callback) {
|
|
|
1105
1140
|
state.callbacks.set(callbackId, async (serialized, requestId) => {
|
|
1106
1141
|
const data = serialized;
|
|
1107
1142
|
const signalController = new AbortController;
|
|
1143
|
+
const callbackRequestId = typeof requestId === "number" ? requestId : undefined;
|
|
1144
|
+
if (callbackRequestId !== undefined) {
|
|
1145
|
+
state.callbackAbortControllers.set(callbackRequestId, signalController);
|
|
1146
|
+
}
|
|
1108
1147
|
if (data.signalAborted) {
|
|
1109
1148
|
signalController.abort();
|
|
1110
1149
|
}
|
|
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
|
-
|
|
1150
|
+
try {
|
|
1151
|
+
const init = {
|
|
1152
|
+
method: data.method,
|
|
1153
|
+
headers: data.headers,
|
|
1154
|
+
rawBody: data.body ?? null,
|
|
1155
|
+
body: data.body ?? null,
|
|
1156
|
+
signal: signalController.signal
|
|
1157
|
+
};
|
|
1158
|
+
const response = await callback(data.url, init);
|
|
1159
|
+
const contentLength = response.headers.get("content-length");
|
|
1160
|
+
const knownSize = contentLength ? parseInt(contentLength, 10) : null;
|
|
1161
|
+
const isNetworkResponse = response.url && (response.url.startsWith("http://") || response.url.startsWith("https://"));
|
|
1162
|
+
const shouldStream = isNetworkResponse && !NULL_BODY_STATUSES.has(response.status) && !!response.body && (knownSize === null || knownSize > CALLBACK_STREAM_THRESHOLD);
|
|
1163
|
+
if (shouldStream && response.body) {
|
|
1164
|
+
const streamId = state.nextStreamId++;
|
|
1165
|
+
const headers = [];
|
|
1166
|
+
response.headers.forEach((value, key) => {
|
|
1167
|
+
headers.push([key, value]);
|
|
1168
|
+
});
|
|
1169
|
+
sendMessage(state.socket, {
|
|
1170
|
+
type: import_isolate_protocol.MessageType.CALLBACK_STREAM_START,
|
|
1171
|
+
requestId,
|
|
1172
|
+
streamId,
|
|
1173
|
+
metadata: {
|
|
1174
|
+
status: response.status,
|
|
1175
|
+
statusText: response.statusText,
|
|
1176
|
+
headers,
|
|
1177
|
+
url: response.url || undefined
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
streamCallbackResponseBody(state, streamId, requestId, response.body);
|
|
1181
|
+
return { __callbackStreaming: true, streamId };
|
|
1182
|
+
}
|
|
1183
|
+
return import_isolate_protocol.serializeResponse(response);
|
|
1184
|
+
} finally {
|
|
1185
|
+
if (callbackRequestId !== undefined) {
|
|
1186
|
+
state.callbackAbortControllers.delete(callbackRequestId);
|
|
1187
|
+
}
|
|
1142
1188
|
}
|
|
1143
|
-
return import_isolate_protocol.serializeResponse(response);
|
|
1144
1189
|
});
|
|
1145
1190
|
return { callbackId, name: "fetch", type: "async" };
|
|
1146
1191
|
}
|
|
@@ -1742,4 +1787,4 @@ function handleClientWsClose(isolateId, payload, state) {
|
|
|
1742
1787
|
}
|
|
1743
1788
|
}
|
|
1744
1789
|
|
|
1745
|
-
//# debugId=
|
|
1790
|
+
//# debugId=D533D4D673D0E39164756E2164756E21
|