@seanhogg/builderforce-webcontainers 2026.10.6 → 2026.10.8
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/assets.js +3 -3
- package/dist/check/worker.js +8 -8
- package/dist/host.d.ts +25 -9
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +39 -25
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/node/index.d.ts +5 -9
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +1 -25
- package/dist/node/index.js.map +1 -1
- package/dist/node/portResponder.d.ts +45 -0
- package/dist/node/portResponder.d.ts.map +1 -0
- package/dist/node/portResponder.js +136 -0
- package/dist/node/portResponder.js.map +1 -0
- package/dist/node/processHost.d.ts +26 -2
- package/dist/node/processHost.d.ts.map +1 -1
- package/dist/node/processHost.js +67 -16
- package/dist/node/processHost.js.map +1 -1
- package/dist/node/protocol.d.ts +42 -9
- package/dist/node/protocol.d.ts.map +1 -1
- package/dist/node/protocol.js.map +1 -1
- package/dist/node/responseWire.d.ts +27 -0
- package/dist/node/responseWire.d.ts.map +1 -0
- package/dist/node/responseWire.js +99 -0
- package/dist/node/responseWire.js.map +1 -0
- package/dist/node/worker.js +143 -127
- package/dist/node/workerProcess.d.ts +3 -1
- package/dist/node/workerProcess.d.ts.map +1 -1
- package/dist/node/workerProcess.js +49 -19
- package/dist/node/workerProcess.js.map +1 -1
- package/dist/previewBridge.d.ts +37 -0
- package/dist/previewBridge.d.ts.map +1 -0
- package/dist/previewBridge.js +116 -0
- package/dist/previewBridge.js.map +1 -0
- package/dist/previewMessages.d.ts +24 -0
- package/dist/previewMessages.d.ts.map +1 -0
- package/dist/previewMessages.js +59 -0
- package/dist/previewMessages.js.map +1 -0
- package/dist/process-worker.js +143 -127
- package/dist/protocol.d.ts +23 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +8 -0
- package/dist/protocol.js.map +1 -1
- package/dist/relay.html +1 -1
- package/dist/snapshotStore.d.ts +30 -0
- package/dist/snapshotStore.d.ts.map +1 -0
- package/dist/snapshotStore.js +115 -0
- package/dist/snapshotStore.js.map +1 -0
- package/dist/sw.js +1 -1
- package/dist/swRouter.d.ts +8 -1
- package/dist/swRouter.d.ts.map +1 -1
- package/dist/swRouter.js +40 -5
- package/dist/swRouter.js.map +1 -1
- package/package.json +3 -2
- package/src/host.ts +62 -31
- package/src/index.ts +8 -3
- package/src/node/index.ts +5 -24
- package/src/node/portResponder.ts +175 -0
- package/src/node/processHost.ts +92 -15
- package/src/node/protocol.ts +25 -4
- package/src/node/responseWire.ts +97 -0
- package/src/node/workerProcess.ts +52 -21
- package/src/previewBridge.ts +148 -0
- package/src/previewMessages.ts +79 -0
- package/src/protocol.ts +35 -1
- package/src/snapshotStore.ts +135 -0
- package/src/sw.ts +2 -0
- package/src/swRouter.ts +35 -6
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streamed HTTP responses over postMessage, used on both sides of the
|
|
3
|
+
* page ↔ process-worker boundary: the side that holds a response sends it as
|
|
4
|
+
* head / chunk / end messages as the server writes it, and the side that asked
|
|
5
|
+
* rebuilds an `HttpStreamResponse` whose body stream is fed by them. A reader
|
|
6
|
+
* that cancels the body sends `request-cancel` back, so the server hears the
|
|
7
|
+
* client hang up.
|
|
8
|
+
*/
|
|
9
|
+
import { drainBody, headOf, pushStream } from '@seanhogg/builderforce-webcontainers-core';
|
|
10
|
+
const encoder = new TextEncoder();
|
|
11
|
+
/**
|
|
12
|
+
* Send `response` as messages once it resolves (`undefined`: nothing listens).
|
|
13
|
+
* A rejected handler becomes a 500 carrying the error. Returns a cancel for
|
|
14
|
+
* when the requester hangs up; `onDone` runs once, when the exchange is over.
|
|
15
|
+
*/
|
|
16
|
+
export function sendResponse(post, reqId, response, onDone) {
|
|
17
|
+
let finished = false;
|
|
18
|
+
let stop;
|
|
19
|
+
const done = () => {
|
|
20
|
+
if (finished)
|
|
21
|
+
return;
|
|
22
|
+
finished = true;
|
|
23
|
+
onDone?.();
|
|
24
|
+
};
|
|
25
|
+
response.then((res) => {
|
|
26
|
+
if (finished)
|
|
27
|
+
return void res?.body.cancel().catch(() => undefined);
|
|
28
|
+
if (!res) {
|
|
29
|
+
post({ type: 'response-head', reqId, head: null });
|
|
30
|
+
return done();
|
|
31
|
+
}
|
|
32
|
+
post({ type: 'response-head', reqId, head: headOf(res) });
|
|
33
|
+
stop = drainBody(res.body, {
|
|
34
|
+
chunk: (data) => post({ type: 'response-chunk', reqId, data }),
|
|
35
|
+
end: (error) => {
|
|
36
|
+
post(error ? { type: 'response-end', reqId, error } : { type: 'response-end', reqId });
|
|
37
|
+
done();
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
}, (error) => {
|
|
41
|
+
if (finished)
|
|
42
|
+
return;
|
|
43
|
+
post({ type: 'response-head', reqId, head: { status: 500, headers: { 'content-type': 'text/plain' } } });
|
|
44
|
+
post({ type: 'response-chunk', reqId, data: encoder.encode(String(error instanceof Error ? error.stack : error)) });
|
|
45
|
+
post({ type: 'response-end', reqId });
|
|
46
|
+
done();
|
|
47
|
+
});
|
|
48
|
+
return () => {
|
|
49
|
+
stop?.();
|
|
50
|
+
done();
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Rebuilds streamed responses from the messages answering requests this side sent. */
|
|
54
|
+
export class ResponseReceiver {
|
|
55
|
+
heads = new Map();
|
|
56
|
+
bodies = new Map();
|
|
57
|
+
/** The response to request `reqId`; `cancel` runs if its reader hangs up before the end. */
|
|
58
|
+
expect(reqId, cancel) {
|
|
59
|
+
return new Promise((resolve) => this.heads.set(reqId, { resolve, cancel }));
|
|
60
|
+
}
|
|
61
|
+
receive(message) {
|
|
62
|
+
const { reqId } = message;
|
|
63
|
+
if (message.type === 'response-head') {
|
|
64
|
+
const waiting = this.heads.get(reqId);
|
|
65
|
+
this.heads.delete(reqId);
|
|
66
|
+
if (!waiting)
|
|
67
|
+
return;
|
|
68
|
+
if (!message.head)
|
|
69
|
+
return waiting.resolve(undefined);
|
|
70
|
+
const body = pushStream(() => {
|
|
71
|
+
this.bodies.delete(reqId);
|
|
72
|
+
waiting.cancel();
|
|
73
|
+
});
|
|
74
|
+
this.bodies.set(reqId, body);
|
|
75
|
+
waiting.resolve({ ...message.head, body: body.stream });
|
|
76
|
+
}
|
|
77
|
+
else if (message.type === 'response-chunk') {
|
|
78
|
+
this.bodies.get(reqId)?.push(message.data);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const body = this.bodies.get(reqId);
|
|
82
|
+
this.bodies.delete(reqId);
|
|
83
|
+
if (message.error)
|
|
84
|
+
body?.fail(new Error(message.error));
|
|
85
|
+
else
|
|
86
|
+
body?.end();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** The other side is gone: waiting requests get `fallback`, bodies in flight break off with `reason`. */
|
|
90
|
+
abort(fallback, reason) {
|
|
91
|
+
for (const { resolve } of this.heads.values())
|
|
92
|
+
resolve(fallback());
|
|
93
|
+
this.heads.clear();
|
|
94
|
+
for (const body of this.bodies.values())
|
|
95
|
+
body.fail(new Error(reason));
|
|
96
|
+
this.bodies.clear();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=responseWire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responseWire.js","sourceRoot":"","sources":["../../src/node/responseWire.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAA4C,MAAM,2CAA2C,CAAC;AAGpI,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAwC,EAAE,KAAa,EAAE,QAAiD,EAAE,MAAmB;IAC1J,IAAI,QAAQ,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