@travetto/web-connect 6.0.0-rc.2 → 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/README.md +1 -0
- package/package.json +3 -3
- package/src/connect.ts +10 -1
- package/src/util.ts +2 -0
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ This module is already most likely compatible with quite a bit of middleware, bu
|
|
|
19
19
|
* The calling code expects the request or response to be a proper [EventEmitter](https://nodejs.org/api/events.html#class-eventemitter)
|
|
20
20
|
* The calling code expects the request/response sockets to be live.
|
|
21
21
|
* The calling code modifies the shape of the objects (e.g. rewrites the close method on response).
|
|
22
|
+
|
|
22
23
|
Barring these exceptions, gaps will be filled in as more use cases arise. The above exceptions are non-negotiable as they are are enforced by the invocation method defined by [Web API](https://github.com/travetto/travetto/tree/main/module/web#readme "Declarative api for Web Applications with support for the dependency injection.").
|
|
23
24
|
|
|
24
25
|
**Code: Example of using the Connect Adaptor with Passport**
|
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,10 +24,10 @@
|
|
|
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
|
-
"@travetto/cli": "^6.0.0-rc.
|
|
30
|
+
"@travetto/cli": "^6.0.0-rc.3",
|
|
31
31
|
"@travetto/test": "^6.0.0-rc.2"
|
|
32
32
|
},
|
|
33
33
|
"peerDependenciesMeta": {
|
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();
|