@ricsam/isolate-client 0.1.17 → 0.1.19

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.
@@ -4,38 +4,59 @@ var __defProp = Object.defineProperty;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
- var __moduleCache = /* @__PURE__ */ new WeakMap;
19
32
  var __toCommonJS = (from) => {
20
- var entry = __moduleCache.get(from), desc;
33
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
21
34
  if (entry)
22
35
  return entry;
23
36
  entry = __defProp({}, "__esModule", { value: true });
24
- if (from && typeof from === "object" || typeof from === "function")
25
- __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
26
- get: () => from[key],
27
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
28
- }));
37
+ if (from && typeof from === "object" || typeof from === "function") {
38
+ for (var key of __getOwnPropNames(from))
39
+ if (!__hasOwnProp.call(entry, key))
40
+ __defProp(entry, key, {
41
+ get: __accessProp.bind(from, key),
42
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
43
+ });
44
+ }
29
45
  __moduleCache.set(from, entry);
30
46
  return entry;
31
47
  };
48
+ var __moduleCache;
49
+ var __returnValue = (v) => v;
50
+ function __exportSetter(name, newValue) {
51
+ this[name] = __returnValue.bind(null, newValue);
52
+ }
32
53
  var __export = (target, all) => {
33
54
  for (var name in all)
34
55
  __defProp(target, name, {
35
56
  get: all[name],
36
57
  enumerable: true,
37
58
  configurable: true,
38
- set: (newValue) => all[name] = () => newValue
59
+ set: __exportSetter.bind(all, name)
39
60
  });
40
61
  };
41
62
 
@@ -660,6 +681,8 @@ async function createRuntime(state, options = {}, namespaceId) {
660
681
  if (signal?.aborted) {
661
682
  throw new DOMException("The operation was aborted", "AbortError");
662
683
  }
684
+ const requestSignal = req.signal;
685
+ const requestSignalInitiallyAborted = requestSignal?.aborted ?? false;
663
686
  const reqId = state.nextRequestId++;
664
687
  const serialized = await serializeRequestWithStreaming(state, req);
665
688
  const { bodyStream, ...serializableRequest } = serialized;
@@ -686,6 +709,23 @@ async function createRuntime(state, options = {}, namespaceId) {
686
709
  };
687
710
  signal.addEventListener("abort", onAbort, { once: true });
688
711
  }
712
+ let onRequestAbort;
713
+ if (requestSignal && !requestSignalInitiallyAborted) {
714
+ onRequestAbort = () => {
715
+ const abortMessage = {
716
+ type: import_isolate_protocol.MessageType.DISPATCH_REQUEST_ABORT,
717
+ isolateId,
718
+ targetRequestId: reqId
719
+ };
720
+ if (state.connected) {
721
+ sendMessage(state.socket, abortMessage);
722
+ }
723
+ };
724
+ requestSignal.addEventListener("abort", onRequestAbort, { once: true });
725
+ if (requestSignal.aborted) {
726
+ onRequestAbort();
727
+ }
728
+ }
689
729
  try {
690
730
  if (serialized.bodyStreamId !== undefined && bodyStream) {
691
731
  const streamId = serialized.bodyStreamId;
@@ -701,6 +741,9 @@ async function createRuntime(state, options = {}, namespaceId) {
701
741
  if (signal && onAbort) {
702
742
  signal.removeEventListener("abort", onAbort);
703
743
  }
744
+ if (requestSignal && onRequestAbort) {
745
+ requestSignal.removeEventListener("abort", onRequestAbort);
746
+ }
704
747
  }
705
748
  },
706
749
  async getUpgradeRequest() {
@@ -1031,12 +1074,16 @@ function registerFetchCallback(state, callback) {
1031
1074
  state.callbacksNeedingRequestId.add(callbackId);
1032
1075
  state.callbacks.set(callbackId, async (serialized, requestId) => {
1033
1076
  const data = serialized;
1077
+ const signalController = new AbortController;
1078
+ if (data.signalAborted) {
1079
+ signalController.abort();
1080
+ }
1034
1081
  const init = {
1035
1082
  method: data.method,
1036
1083
  headers: data.headers,
1037
1084
  rawBody: data.body ?? null,
1038
1085
  body: data.body ?? null,
1039
- signal: new AbortController().signal
1086
+ signal: signalController.signal
1040
1087
  };
1041
1088
  const response = await callback(data.url, init);
1042
1089
  const contentLength = response.headers.get("content-length");
@@ -1407,7 +1454,8 @@ async function serializeRequestWithStreaming(state, request) {
1407
1454
  method: request.method,
1408
1455
  url: request.url,
1409
1456
  headers,
1410
- body
1457
+ body,
1458
+ signalAborted: request.signal?.aborted ?? false
1411
1459
  };
1412
1460
  if (bodyStreamId !== undefined) {
1413
1461
  result.bodyStreamId = bodyStreamId;
@@ -1664,4 +1712,4 @@ function handleClientWsClose(isolateId, payload, state) {
1664
1712
  }
1665
1713
  }
1666
1714
 
1667
- //# debugId=BB5A27475A32C8E264756E2164756E21
1715
+ //# debugId=C08D5EB489DD9C9D64756E2164756E21