@travetto/web-connect 6.0.0-rc.3 → 6.0.0-rc.4
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/package.json +2 -2
- package/src/connect.ts +10 -1
- package/src/util.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/web-connect",
|
|
3
|
-
"version": "6.0.0-rc.
|
|
3
|
+
"version": "6.0.0-rc.4",
|
|
4
4
|
"description": "Web integration for Connect-Like Resources",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"directory": "module/web-connect"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@travetto/web": "^6.0.0-rc.
|
|
27
|
+
"@travetto/web": "^6.0.0-rc.4"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@travetto/cli": "^6.0.0-rc.3",
|
package/src/connect.ts
CHANGED
|
@@ -50,6 +50,7 @@ export class ConnectResponse implements Pick<ServerResponse,
|
|
|
50
50
|
#headersSent = false;
|
|
51
51
|
#finished = false;
|
|
52
52
|
#written: Buffer[] = [];
|
|
53
|
+
#onEndHandlers: (() => void)[] = [];
|
|
53
54
|
|
|
54
55
|
constructor(response?: WebResponse) {
|
|
55
56
|
this.#response = response ?? new WebResponse();
|
|
@@ -143,11 +144,19 @@ export class ConnectResponse implements Pick<ServerResponse,
|
|
|
143
144
|
}
|
|
144
145
|
this.#finished = true;
|
|
145
146
|
cb?.();
|
|
147
|
+
for (const item of this.#onEndHandlers) {
|
|
148
|
+
item();
|
|
149
|
+
}
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
on(type: 'end', handler: () => void): this {
|
|
154
|
+
this.#onEndHandlers.push(handler);
|
|
146
155
|
return this;
|
|
147
156
|
}
|
|
148
157
|
|
|
149
158
|
throwIfSent(): void {
|
|
150
|
-
if (
|
|
159
|
+
if (this.#headersSent) {
|
|
151
160
|
this.#response.body = Buffer.concat(this.#written);
|
|
152
161
|
throw this.#response;
|
|
153
162
|
}
|
package/src/util.ts
CHANGED
|
@@ -27,6 +27,8 @@ export class WebConnectUtil {
|
|
|
27
27
|
const connectRes = ConnectResponse.get();
|
|
28
28
|
|
|
29
29
|
const p = Promise.withResolvers<T | undefined>();
|
|
30
|
+
connectRes.on('end', () => p.resolve(null!));
|
|
31
|
+
|
|
30
32
|
handler(connectReq, connectRes, (err, value) => err ? p.reject(err) : p.resolve(value!));
|
|
31
33
|
const result = await p.promise;
|
|
32
34
|
connectRes.throwIfSent();
|