@inversifyjs/http-uwebsockets 4.1.0

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +5 -0
  4. package/lib/cjs/actions/pipeStreamOverResponse.d.ts +26 -0
  5. package/lib/cjs/actions/pipeStreamOverResponse.d.ts.map +1 -0
  6. package/lib/cjs/actions/pipeStreamOverResponse.js +95 -0
  7. package/lib/cjs/actions/pipeStreamOverResponse.js.map +1 -0
  8. package/lib/cjs/actions/pipeStreamOverResponse.spec.d.ts +2 -0
  9. package/lib/cjs/actions/pipeStreamOverResponse.spec.d.ts.map +1 -0
  10. package/lib/cjs/adapter/InversifyUwebSocketsHttpAdapter.d.ts +22 -0
  11. package/lib/cjs/adapter/InversifyUwebSocketsHttpAdapter.d.ts.map +1 -0
  12. package/lib/cjs/adapter/InversifyUwebSocketsHttpAdapter.js +200 -0
  13. package/lib/cjs/adapter/InversifyUwebSocketsHttpAdapter.js.map +1 -0
  14. package/lib/cjs/calculations/toArrayBuffer.d.ts +13 -0
  15. package/lib/cjs/calculations/toArrayBuffer.d.ts.map +1 -0
  16. package/lib/cjs/calculations/toArrayBuffer.js +32 -0
  17. package/lib/cjs/calculations/toArrayBuffer.js.map +1 -0
  18. package/lib/cjs/calculations/toArrayBuffer.spec.d.ts +2 -0
  19. package/lib/cjs/calculations/toArrayBuffer.spec.d.ts.map +1 -0
  20. package/lib/cjs/data/abortedSymbol.d.ts +2 -0
  21. package/lib/cjs/data/abortedSymbol.d.ts.map +1 -0
  22. package/lib/cjs/data/abortedSymbol.js +5 -0
  23. package/lib/cjs/data/abortedSymbol.js.map +1 -0
  24. package/lib/cjs/index.d.ts +7 -0
  25. package/lib/cjs/index.d.ts.map +1 -0
  26. package/lib/cjs/index.js +6 -0
  27. package/lib/cjs/index.js.map +1 -0
  28. package/lib/cjs/models/CustomHttpResponse.d.ts +6 -0
  29. package/lib/cjs/models/CustomHttpResponse.d.ts.map +1 -0
  30. package/lib/cjs/models/CustomHttpResponse.js +4 -0
  31. package/lib/cjs/models/CustomHttpResponse.js.map +1 -0
  32. package/lib/cjs/models/UwebSocketsErrorFilter.d.ts +4 -0
  33. package/lib/cjs/models/UwebSocketsErrorFilter.d.ts.map +1 -0
  34. package/lib/cjs/models/UwebSocketsErrorFilter.js +3 -0
  35. package/lib/cjs/models/UwebSocketsErrorFilter.js.map +1 -0
  36. package/lib/cjs/models/UwebSocketsGuard.d.ts +4 -0
  37. package/lib/cjs/models/UwebSocketsGuard.d.ts.map +1 -0
  38. package/lib/cjs/models/UwebSocketsGuard.js +3 -0
  39. package/lib/cjs/models/UwebSocketsGuard.js.map +1 -0
  40. package/lib/cjs/models/UwebSocketsHttpAdapterOptions.d.ts +5 -0
  41. package/lib/cjs/models/UwebSocketsHttpAdapterOptions.d.ts.map +1 -0
  42. package/lib/cjs/models/UwebSocketsHttpAdapterOptions.js +3 -0
  43. package/lib/cjs/models/UwebSocketsHttpAdapterOptions.js.map +1 -0
  44. package/lib/cjs/models/UwebSocketsInterceptor.d.ts +4 -0
  45. package/lib/cjs/models/UwebSocketsInterceptor.d.ts.map +1 -0
  46. package/lib/cjs/models/UwebSocketsInterceptor.js +3 -0
  47. package/lib/cjs/models/UwebSocketsInterceptor.js.map +1 -0
  48. package/lib/cjs/models/UwebSocketsMiddleware.d.ts +4 -0
  49. package/lib/cjs/models/UwebSocketsMiddleware.d.ts.map +1 -0
  50. package/lib/cjs/models/UwebSocketsMiddleware.js +3 -0
  51. package/lib/cjs/models/UwebSocketsMiddleware.js.map +1 -0
  52. package/lib/cjs/package.json +3 -0
  53. package/lib/esm/index.d.ts +36 -0
  54. package/lib/esm/index.d.ts.map +1 -0
  55. package/lib/esm/index.js +2 -0
  56. package/lib/esm/index.js.map +1 -0
  57. package/lib/esm/package.json +3 -0
  58. package/package.json +77 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ # @inversifyjs/http-uwebsockets
2
+
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Added `InversifyUwebSocketsHttpAdapter`
8
+ - Added `UwebSocketsHttpAdapterOptions`
9
+ - Added `UwebSocketsErrorFilter`
10
+ - Added `UwebSocketsGuard`
11
+ - Added `UwebSocketsInterceptor`
12
+ - Added `UwebSocketsMiddleware`
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+ - @inversifyjs/http-core@4.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 inversify
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ [![Test coverage](https://codecov.io/gh/inversify/monorepo/branch/main/graph/badge.svg?flag=%40inversifyjs%2Fhttp-uwebsockets)](https://codecov.io/gh/inversify/monorepo/branch/main/graph/badge.svg?flag=%40inversifyjs%2Fhttp-uwebsockets) [![npm version](https://img.shields.io/github/package-json/v/inversify/monorepo?filename=packages%2Fframework%2Fhttp%2Flibraries%2Fuwebsockets%2Fpackage.json&style=plastic)](https://www.npmjs.com/package/@inversifyjs/http-uwebsockets)
2
+
3
+ # @inversifyjs/http-uwebsockets
4
+
5
+ Inversify monorepo http uwebsockets modules.
@@ -0,0 +1,26 @@
1
+ import { Readable } from 'node:stream';
2
+ import { type Logger } from '@inversifyjs/logger';
3
+ import { HttpResponse } from 'uWebSockets.js';
4
+ /**
5
+ * Pipes a Node.js Readable stream over a uWebSockets.js HTTP response with proper
6
+ * backpressure handling and error management.
7
+ *
8
+ * This function handles:
9
+ * - Backpressure: Pauses the stream when the socket buffer is full
10
+ * - Abort handling: Cleans up resources when the client disconnects
11
+ * - Error handling: Catches stream errors and sends appropriate error responses
12
+ * - Object mode detection: Throws an error if the stream is in object mode
13
+ *
14
+ * @param response - The uWebSockets.js HTTP response object
15
+ * @param readableStream - The Node.js Readable stream to pipe (must not be in object mode)
16
+ * @param options - Optional configuration for logging
17
+ * @throws {Error} If the stream is in object mode
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const fileStream = fs.createReadStream('./video.mp4');
22
+ * pipeStreamOverResponse(response, fileStream, { logErrors: true });
23
+ * ```
24
+ */
25
+ export declare function pipeStreamOverResponse(response: HttpResponse, readableStream: Readable, logger: Logger | undefined): void;
26
+ //# sourceMappingURL=pipeStreamOverResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeStreamOverResponse.d.ts","sourceRoot":"","sources":["../../../src/actions/pipeStreamOverResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAM9C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,YAAY,EACtB,cAAc,EAAE,QAAQ,EACxB,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,IAAI,CAwFN"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pipeStreamOverResponse = pipeStreamOverResponse;
4
+ const toArrayBuffer_1 = require("../calculations/toArrayBuffer");
5
+ const abortedSymbol_1 = require("../data/abortedSymbol");
6
+ /**
7
+ * Pipes a Node.js Readable stream over a uWebSockets.js HTTP response with proper
8
+ * backpressure handling and error management.
9
+ *
10
+ * This function handles:
11
+ * - Backpressure: Pauses the stream when the socket buffer is full
12
+ * - Abort handling: Cleans up resources when the client disconnects
13
+ * - Error handling: Catches stream errors and sends appropriate error responses
14
+ * - Object mode detection: Throws an error if the stream is in object mode
15
+ *
16
+ * @param response - The uWebSockets.js HTTP response object
17
+ * @param readableStream - The Node.js Readable stream to pipe (must not be in object mode)
18
+ * @param options - Optional configuration for logging
19
+ * @throws {Error} If the stream is in object mode
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * const fileStream = fs.createReadStream('./video.mp4');
24
+ * pipeStreamOverResponse(response, fileStream, { logErrors: true });
25
+ * ```
26
+ */
27
+ function pipeStreamOverResponse(response, readableStream, logger) {
28
+ let isStreamClosed = false;
29
+ let storedBuffer;
30
+ let storedOffset;
31
+ /**
32
+ * Clean up function called when the stream is aborted or finished
33
+ */
34
+ const cleanup = () => {
35
+ if (!isStreamClosed) {
36
+ isStreamClosed = true;
37
+ readableStream.destroy();
38
+ storedBuffer = undefined;
39
+ storedOffset = undefined;
40
+ }
41
+ };
42
+ // Handle response abortion (client disconnected)
43
+ response.onAborted(() => {
44
+ cleanup();
45
+ });
46
+ // Handle stream data chunks
47
+ readableStream.on('data', (chunk) => {
48
+ if (response[abortedSymbol_1.abortedSymbol] === true) {
49
+ cleanup();
50
+ return;
51
+ }
52
+ const arrayBuffer = (0, toArrayBuffer_1.toArrayBuffer)(chunk);
53
+ const lastOffset = response.getWriteOffset();
54
+ const [ok, done] = response.tryEnd(arrayBuffer, arrayBuffer.byteLength);
55
+ if (done) {
56
+ cleanup();
57
+ }
58
+ else if (!ok) {
59
+ readableStream.pause();
60
+ storedBuffer = arrayBuffer;
61
+ storedOffset = lastOffset;
62
+ response.onWritable((offset) => {
63
+ if (response[abortedSymbol_1.abortedSymbol] === true) {
64
+ cleanup();
65
+ return false;
66
+ }
67
+ if (storedBuffer === undefined || storedOffset === undefined) {
68
+ return false;
69
+ }
70
+ const [retryOk, retryDone] = response.tryEnd(storedBuffer.slice(offset - storedOffset), storedBuffer.byteLength);
71
+ if (retryDone) {
72
+ cleanup();
73
+ }
74
+ else if (retryOk) {
75
+ readableStream.resume();
76
+ }
77
+ return retryOk;
78
+ });
79
+ }
80
+ });
81
+ readableStream.on('error', (error) => {
82
+ logger?.error(error.stack ?? error.message);
83
+ cleanup();
84
+ if (response[abortedSymbol_1.abortedSymbol] !== true) {
85
+ response.cork(() => {
86
+ response.writeStatus('500');
87
+ response.end('Stream error occurred');
88
+ });
89
+ }
90
+ });
91
+ readableStream.on('end', () => {
92
+ cleanup();
93
+ });
94
+ }
95
+ //# sourceMappingURL=pipeStreamOverResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeStreamOverResponse.js","sourceRoot":"","sources":["../../../src/actions/pipeStreamOverResponse.ts"],"names":[],"mappings":";;AA8BA,wDA4FC;AArHD,iEAA8D;AAC9D,yDAAsD;AAGtD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,sBAAsB,CACpC,QAAsB,EACtB,cAAwB,EACxB,MAA0B;IAE1B,IAAI,cAAc,GAAY,KAAK,CAAC;IACpC,IAAI,YAAqC,CAAC;IAC1C,IAAI,YAAgC,CAAC;IAErC;;OAEG;IACH,MAAM,OAAO,GAAe,GAAS,EAAE;QACrC,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,cAAc,GAAG,IAAI,CAAC;YACtB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AK,CAAC,MAAM,GAAG,YAAY,CAAC,EACzC,YAAY,CAAC,UAAU,CACxB,CAAC;gBAEF,IAAI,SAAS,EAAE,CAAC;oBACd,OAAO,EAAE,CAAC;gBACZ,CAAC;qBAAM,IAAI,OAAO,EAAE,CAAC;oBACnB,cAAc,CAAC,MAAM,EAAE,CAAC;gBAC1B,CAAC;gBAED,OAAO,OAAO,CAAC;YACjB,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAQ,EAAE;QAChD,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAE5C,OAAO,EAAE,CAAC;QAEV,IAAK,QAA+B,CAAC,6BAAa,CAAC,KAAK,IAAI,EAAE,CAAC;YAC7D,QAAQ,CAAC,IAAI,CAAC,GAAS,EAAE;gBACvB,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;gBAC5B,QAAQ,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;YACxC,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,GAAS,EAAE;QAClC,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pipeStreamOverResponse.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeStreamOverResponse.spec.d.ts","sourceRoot":"","sources":["../../../src/actions/pipeStreamOverResponse.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
1
+ import { Readable } from 'node:stream';
2
+ import { HttpStatusCode, InversifyHttpAdapter, RouterParams } from '@inversifyjs/http-core';
3
+ import { Container } from 'inversify';
4
+ import { HttpRequest, HttpResponse, TemplatedApp } from 'uWebSockets.js';
5
+ import { UwebSocketsHttpAdapterOptions } from '../models/UwebSocketsHttpAdapterOptions';
6
+ export declare class InversifyUwebSocketsHttpAdapter extends InversifyHttpAdapter<HttpRequest, HttpResponse, () => void, void, UwebSocketsHttpAdapterOptions> {
7
+ #private;
8
+ constructor(container: Container, httpAdapterOptions?: UwebSocketsHttpAdapterOptions, customApp?: TemplatedApp);
9
+ build(): Promise<TemplatedApp>;
10
+ protected _buildRouter(routerParams: RouterParams<HttpRequest, HttpResponse, () => void, void>): void;
11
+ protected _replyJson(_request: HttpRequest, response: HttpResponse, value?: object): void;
12
+ protected _replyText(_request: HttpRequest, response: HttpResponse, value?: string): void;
13
+ protected _replyStream(_request: HttpRequest, response: HttpResponse, stream: Readable): void;
14
+ protected _setStatus(_request: HttpRequest, response: HttpResponse, statusCode: HttpStatusCode): void;
15
+ protected _setHeader(_request: HttpRequest, response: HttpResponse, key: string, value: string): void;
16
+ protected _getBody(_request: HttpRequest, response: HttpResponse, parameterName?: string): Promise<unknown>;
17
+ protected _getParams(request: HttpRequest, parameterName?: string): unknown;
18
+ protected _getQuery(request: HttpRequest, parameterName?: string): unknown;
19
+ protected _getHeaders(request: HttpRequest, parameterName?: string): unknown;
20
+ protected _getCookies(request: HttpRequest, _response: HttpResponse, parameterName?: string): unknown;
21
+ }
22
+ //# sourceMappingURL=InversifyUwebSocketsHttpAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InversifyUwebSocketsHttpAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapter/InversifyUwebSocketsHttpAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAGvC,OAAO,EACL,cAAc,EACd,oBAAoB,EAIpB,YAAY,EACb,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAEL,WAAW,EACX,YAAY,EAEZ,YAAY,EACb,MAAM,gBAAgB,CAAC;AAK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CAAC,SAAS,CAAC,OAAO,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO;IAM1E,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,OAAO;IAM5E,SAAS,CAAC,WAAW,CACnB,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,YAAY,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO;CA6GX"}
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InversifyUwebSocketsHttpAdapter = void 0;
4
+ const http_core_1 = require("@inversifyjs/http-core");
5
+ const uWebSockets_js_1 = require("uWebSockets.js");
6
+ const pipeStreamOverResponse_1 = require("../actions/pipeStreamOverResponse");
7
+ const abortedSymbol_1 = require("../data/abortedSymbol");
8
+ class InversifyUwebSocketsHttpAdapter extends http_core_1.InversifyHttpAdapter {
9
+ #app;
10
+ constructor(container, httpAdapterOptions, customApp) {
11
+ super(container, {
12
+ logger: true,
13
+ useJson: true,
14
+ }, httpAdapterOptions, [http_core_1.RequestMethodParameterType.Body]);
15
+ this.#app = customApp ?? this.#buildDefaultApp();
16
+ }
17
+ async build() {
18
+ await this._buildServer();
19
+ return this.#app;
20
+ }
21
+ _buildRouter(routerParams) {
22
+ for (const routeParams of routerParams.routeParamsList) {
23
+ const orderedHandlers = [
24
+ ...routeParams.preHandlerMiddlewareList,
25
+ ...routeParams.guardList,
26
+ routeParams.handler,
27
+ ...routeParams.postHandlerMiddlewareList,
28
+ ];
29
+ let routePath = `${routerParams.path}${routeParams.path}`;
30
+ if (routePath.endsWith('/') && routePath.length > 1) {
31
+ routePath = routePath.slice(0, -1);
32
+ }
33
+ this.#getAppRouteHandler(routeParams.requestMethodType)(routePath, async (res, req) => {
34
+ res.onAborted(() => {
35
+ res[abortedSymbol_1.abortedSymbol] = true;
36
+ });
37
+ let currentIndex = 0;
38
+ let [currentHandler] = orderedHandlers;
39
+ let nextCalled = false;
40
+ const next = () => {
41
+ nextCalled = true;
42
+ };
43
+ while (currentHandler !== undefined) {
44
+ await currentHandler(req, res, next);
45
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
46
+ if (!nextCalled) {
47
+ break;
48
+ }
49
+ nextCalled = false;
50
+ currentHandler = orderedHandlers[++currentIndex];
51
+ }
52
+ });
53
+ }
54
+ }
55
+ _replyJson(_request, response, value) {
56
+ if (response[abortedSymbol_1.abortedSymbol] !== true) {
57
+ response.cork(() => {
58
+ response.end(JSON.stringify(value));
59
+ });
60
+ }
61
+ }
62
+ _replyText(_request, response, value) {
63
+ if (response[abortedSymbol_1.abortedSymbol] !== true) {
64
+ response.cork(() => {
65
+ response.end(value);
66
+ });
67
+ }
68
+ }
69
+ _replyStream(_request, response, stream) {
70
+ (0, pipeStreamOverResponse_1.pipeStreamOverResponse)(response, stream, this.httpAdapterOptions.logger === false ? undefined : this._logger);
71
+ }
72
+ _setStatus(_request, response, statusCode) {
73
+ response.cork(() => {
74
+ response.writeStatus(statusCode.toString());
75
+ });
76
+ }
77
+ _setHeader(_request, response, key, value) {
78
+ response.cork(() => {
79
+ response.writeHeader(key, value);
80
+ });
81
+ }
82
+ async _getBody(_request, response, parameterName) {
83
+ const body = await this.#parseBody(response);
84
+ if (parameterName === undefined) {
85
+ return body;
86
+ }
87
+ if (!(parameterName in body)) {
88
+ throw new Error(`Body parameter '${parameterName}' not found.`);
89
+ }
90
+ return body[parameterName];
91
+ }
92
+ _getParams(request, parameterName) {
93
+ if (parameterName === undefined) {
94
+ throw new Error('Getting all route parameters is not supported in uWebSockets.js adapter.');
95
+ }
96
+ return request.getParameter(parameterName);
97
+ }
98
+ _getQuery(request, parameterName) {
99
+ return parameterName === undefined
100
+ ? this.#parseQuery(request)
101
+ : request.getQuery(parameterName);
102
+ }
103
+ _getHeaders(request, parameterName) {
104
+ return parameterName === undefined
105
+ ? this.#parseHeaders(request)
106
+ : request.getHeader(parameterName);
107
+ }
108
+ _getCookies(request, _response, parameterName) {
109
+ const cookies = this.#parseCookies(request);
110
+ return parameterName === undefined ? cookies : cookies[parameterName];
111
+ }
112
+ #buildDefaultApp() {
113
+ return (0, uWebSockets_js_1.App)();
114
+ }
115
+ #getAppRouteHandler(requestMethodType) {
116
+ switch (requestMethodType) {
117
+ case http_core_1.RequestMethodType.All:
118
+ return this.#app.any.bind(this.#app);
119
+ case http_core_1.RequestMethodType.Delete:
120
+ return this.#app.del.bind(this.#app);
121
+ case http_core_1.RequestMethodType.Get:
122
+ return this.#app.get.bind(this.#app);
123
+ case http_core_1.RequestMethodType.Head:
124
+ return this.#app.head.bind(this.#app);
125
+ case http_core_1.RequestMethodType.Options:
126
+ return this.#app.options.bind(this.#app);
127
+ case http_core_1.RequestMethodType.Patch:
128
+ return this.#app.patch.bind(this.#app);
129
+ case http_core_1.RequestMethodType.Post:
130
+ return this.#app.post.bind(this.#app);
131
+ case http_core_1.RequestMethodType.Put:
132
+ return this.#app.put.bind(this.#app);
133
+ }
134
+ }
135
+ async #parseBody(res) {
136
+ return new Promise((resolve) => {
137
+ let buffer;
138
+ res.onData((chunk, isLast) => {
139
+ const curBuf = Buffer.from(chunk);
140
+ buffer = buffer
141
+ ? Buffer.concat([buffer, curBuf])
142
+ : isLast
143
+ ? curBuf
144
+ : Buffer.concat([curBuf]);
145
+ if (isLast) {
146
+ const stringifiedBody = buffer.toString();
147
+ if (this.httpAdapterOptions.useJson) {
148
+ resolve(JSON.parse(stringifiedBody));
149
+ }
150
+ else {
151
+ resolve(stringifiedBody);
152
+ }
153
+ }
154
+ });
155
+ });
156
+ }
157
+ #parseCookies(request) {
158
+ const cookieHeader = request.getHeader('cookie');
159
+ if (cookieHeader === '') {
160
+ return {};
161
+ }
162
+ // Parse cookies manually
163
+ const cookies = {};
164
+ for (const cookie of cookieHeader.split(';')) {
165
+ const [name, ...rest] = cookie.split('=');
166
+ const value = rest.join('=').trim();
167
+ if (name !== undefined) {
168
+ cookies[name.trim()] = decodeURIComponent(value);
169
+ }
170
+ }
171
+ return cookies;
172
+ }
173
+ #parseHeaders(request) {
174
+ const headers = {};
175
+ request.forEach((key, value) => {
176
+ headers[key] = value;
177
+ });
178
+ return headers;
179
+ }
180
+ #parseQuery(request) {
181
+ const queryEntries = new URLSearchParams(request.getQuery()).entries();
182
+ const result = {};
183
+ for (const [key, value] of queryEntries) {
184
+ if (result[key] !== undefined) {
185
+ if (Array.isArray(result[key])) {
186
+ result[key].push(value);
187
+ }
188
+ else {
189
+ result[key] = [result[key], value];
190
+ }
191
+ }
192
+ else {
193
+ result[key] = value;
194
+ }
195
+ }
196
+ return result;
197
+ }
198
+ }
199
+ exports.InversifyUwebSocketsHttpAdapter = InversifyUwebSocketsHttpAdapter;
200
+ //# sourceMappingURL=InversifyUwebSocketsHttpAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InversifyUwebSocketsHttpAdapter.js","sourceRoot":"","sources":["../../../src/adapter/InversifyUwebSocketsHttpAdapter.ts"],"names":[],"mappings":";;;AAGA,sDAOgC;AAEhC,mDAMwB;AAExB,8EAA2E;AAC3E,yDAAsD;AAItD,MAAa,+BAAgC,SAAQ,gCAMpD;IACU,IAAI,CAAe;IAE5B,YACE,SAAoB,EACpB,kBAAkD,EAClD,SAAwB;QAExB,KAAK,CACH,SAAS,EACT;YACE,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,IAAI;SACd,EACD,kBAAkB,EAClB,CAAC,sCAA0B,CAAC,IAAI,CAAC,CAClC,CAAC;QAEF,IAAI,CAAC,IAAI,GAAG,SAAS,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACnD,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAE1B,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAES,YAAY,CACpB,YAAuE;QAEvE,KAAK,MAAM,WAAW,IAAI,YAAY,CAAC,eAAe,EAAE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C,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,aAAa,CAAC,OAAoB;QAChC,MAAM,OAAO,GAA2B,EAAE,CAAC;QAC3C,OAAO,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,KAAa,EAAE,EAAE;YAC7C,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,WAAW,CAAC,OAAoB;QAC9B,MAAM,YAAY,GAChB,IAAI,eAAe,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QAEpD,MAAM,MAAM,GAAsC,EAAE,CAAC;QAErD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,YAAY,EAAE,CAAC;YACxC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC9B,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;oBAC/B,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC1B,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;YACtB,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA7SD,0EA6SC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Converts a Node.js Buffer or string to an ArrayBuffer.
3
+ *
4
+ * This function handles both Buffer and string inputs (as Readable streams
5
+ * in non-object mode can emit either type). For Buffers, it extracts the
6
+ * underlying ArrayBuffer and handles the case where the Buffer's underlying
7
+ * storage is a SharedArrayBuffer. For strings, it encodes them as UTF-8.
8
+ *
9
+ * @param chunk - The Node.js Buffer or string to convert. In object mode, this can be any type.
10
+ * @returns An ArrayBuffer containing the chunk's data
11
+ */
12
+ export declare function toArrayBuffer(chunk: unknown): ArrayBuffer;
13
+ //# sourceMappingURL=toArrayBuffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toArrayBuffer.d.ts","sourceRoot":"","sources":["../../../src/calculations/toArrayBuffer.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAyBzD"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toArrayBuffer = toArrayBuffer;
4
+ const node_buffer_1 = require("node:buffer");
5
+ /**
6
+ * Converts a Node.js Buffer or string to an ArrayBuffer.
7
+ *
8
+ * This function handles both Buffer and string inputs (as Readable streams
9
+ * in non-object mode can emit either type). For Buffers, it extracts the
10
+ * underlying ArrayBuffer and handles the case where the Buffer's underlying
11
+ * storage is a SharedArrayBuffer. For strings, it encodes them as UTF-8.
12
+ *
13
+ * @param chunk - The Node.js Buffer or string to convert. In object mode, this can be any type.
14
+ * @returns An ArrayBuffer containing the chunk's data
15
+ */
16
+ function toArrayBuffer(chunk) {
17
+ const buffer = typeof chunk === 'string'
18
+ ? node_buffer_1.Buffer.from(chunk)
19
+ : node_buffer_1.Buffer.isBuffer(chunk)
20
+ ? chunk
21
+ : node_buffer_1.Buffer.from(
22
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string, @typescript-eslint/no-unsafe-function-type
23
+ chunk.toString());
24
+ const arrayBuffer = buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
25
+ if (arrayBuffer instanceof SharedArrayBuffer) {
26
+ const newArrayBuffer = new ArrayBuffer(arrayBuffer.byteLength);
27
+ new Uint8Array(newArrayBuffer).set(new Uint8Array(arrayBuffer));
28
+ return newArrayBuffer;
29
+ }
30
+ return arrayBuffer;
31
+ }
32
+ //# sourceMappingURL=toArrayBuffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toArrayBuffer.js","sourceRoot":"","sources":["../../../src/calculations/toArrayBuffer.ts"],"names":[],"mappings":";;AAaA,sCAyBC;AAtCD,6CAAqC;AAErC;;;;;;;;;;GAUG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,MAAM,MAAM,GACV,OAAO,KAAK,KAAK,QAAQ;QACvB,CAAC,CAAC,oBAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC,CAAC,oBAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YACtB,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,oBAAM,CAAC,IAAI;YACT,4GAA4G;YAC3G,KAAuD,CAAC,QAAQ,EAAE,CACpE,CAAC;IAEV,MAAM,WAAW,GAAoC,MAAM,CAAC,MAAM,CAAC,KAAK,CACtE,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CACtC,CAAC;IAEF,IAAI,WAAW,YAAY,iBAAiB,EAAE,CAAC;QAC7C,MAAM,cAAc,GAAgB,IAAI,WAAW,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAE5E,IAAI,UAAU,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;QAEhE,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=toArrayBuffer.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toArrayBuffer.spec.d.ts","sourceRoot":"","sources":["../../../src/calculations/toArrayBuffer.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export declare const abortedSymbol: unique symbol;
2
+ //# sourceMappingURL=abortedSymbol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abortedSymbol.d.ts","sourceRoot":"","sources":["../../../src/data/abortedSymbol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,EAAE,OAAO,MAA8B,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.abortedSymbol = void 0;
4
+ exports.abortedSymbol = Symbol.for('aborted');
5
+ //# sourceMappingURL=abortedSymbol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abortedSymbol.js","sourceRoot":"","sources":["../../../src/data/abortedSymbol.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAkB,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { InversifyUwebSocketsHttpAdapter } from './adapter/InversifyUwebSocketsHttpAdapter';
2
+ export type { UwebSocketsHttpAdapterOptions } from './models/UwebSocketsHttpAdapterOptions';
3
+ export type { UwebSocketsErrorFilter } from './models/UwebSocketsErrorFilter';
4
+ export type { UwebSocketsGuard } from './models/UwebSocketsGuard';
5
+ export type { UwebSocketsInterceptor } from './models/UwebSocketsInterceptor';
6
+ export type { UwebSocketsMiddleware } from './models/UwebSocketsMiddleware';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,2CAA2C,CAAC;AAC5F,YAAY,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAC5F,YAAY,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,YAAY,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InversifyUwebSocketsHttpAdapter = void 0;
4
+ var InversifyUwebSocketsHttpAdapter_1 = require("./adapter/InversifyUwebSocketsHttpAdapter");
5
+ Object.defineProperty(exports, "InversifyUwebSocketsHttpAdapter", { enumerable: true, get: function () { return InversifyUwebSocketsHttpAdapter_1.InversifyUwebSocketsHttpAdapter; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6FAA4F;AAAnF,kJAAA,+BAA+B,OAAA"}
@@ -0,0 +1,6 @@
1
+ import { HttpResponse } from 'uWebSockets.js';
2
+ import { abortedSymbol } from '../data/abortedSymbol';
3
+ export interface CustomHttpResponse extends HttpResponse {
4
+ [abortedSymbol]?: boolean;
5
+ }
6
+ //# sourceMappingURL=CustomHttpResponse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomHttpResponse.d.ts","sourceRoot":"","sources":["../../../src/models/CustomHttpResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,CAAC,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC;CAC3B"}
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const abortedSymbol_1 = require("../data/abortedSymbol");
4
+ //# sourceMappingURL=CustomHttpResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomHttpResponse.js","sourceRoot":"","sources":["../../../src/models/CustomHttpResponse.ts"],"names":[],"mappings":";;AAEA,yDAAsD"}
@@ -0,0 +1,4 @@
1
+ import { ErrorFilter } from '@inversifyjs/http-core';
2
+ import { HttpRequest, HttpResponse } from 'uWebSockets.js';
3
+ export type UwebSocketsErrorFilter<TError = unknown> = ErrorFilter<TError, HttpRequest, HttpResponse, void>;
4
+ //# sourceMappingURL=UwebSocketsErrorFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsErrorFilter.d.ts","sourceRoot":"","sources":["../../../src/models/UwebSocketsErrorFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3D,MAAM,MAAM,sBAAsB,CAAC,MAAM,GAAG,OAAO,IAAI,WAAW,CAChE,MAAM,EACN,WAAW,EACX,YAAY,EACZ,IAAI,CACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=UwebSocketsErrorFilter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsErrorFilter.js","sourceRoot":"","sources":["../../../src/models/UwebSocketsErrorFilter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Guard } from '@inversifyjs/http-core';
2
+ import { HttpRequest } from 'uWebSockets.js';
3
+ export type UwebSocketsGuard = Guard<HttpRequest>;
4
+ //# sourceMappingURL=UwebSocketsGuard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsGuard.d.ts","sourceRoot":"","sources":["../../../src/models/UwebSocketsGuard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=UwebSocketsGuard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsGuard.js","sourceRoot":"","sources":["../../../src/models/UwebSocketsGuard.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { HttpAdapterOptions } from '@inversifyjs/http-core';
2
+ export interface UwebSocketsHttpAdapterOptions extends HttpAdapterOptions {
3
+ useJson?: boolean;
4
+ }
5
+ //# sourceMappingURL=UwebSocketsHttpAdapterOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsHttpAdapterOptions.d.ts","sourceRoot":"","sources":["../../../src/models/UwebSocketsHttpAdapterOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,WAAW,6BAA8B,SAAQ,kBAAkB;IACvE,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=UwebSocketsHttpAdapterOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsHttpAdapterOptions.js","sourceRoot":"","sources":["../../../src/models/UwebSocketsHttpAdapterOptions.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Interceptor } from '@inversifyjs/http-core';
2
+ import { HttpRequest, HttpResponse } from 'uWebSockets.js';
3
+ export type UwebSocketsInterceptor = Interceptor<HttpRequest, HttpResponse>;
4
+ //# sourceMappingURL=UwebSocketsInterceptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsInterceptor.d.ts","sourceRoot":"","sources":["../../../src/models/UwebSocketsInterceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3D,MAAM,MAAM,sBAAsB,GAAG,WAAW,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=UwebSocketsInterceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsInterceptor.js","sourceRoot":"","sources":["../../../src/models/UwebSocketsInterceptor.ts"],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Middleware } from '@inversifyjs/http-core';
2
+ import { HttpRequest, HttpResponse } from 'uWebSockets.js';
3
+ export type UwebSocketsMiddleware = Middleware<HttpRequest, HttpResponse, () => void, void>;
4
+ //# sourceMappingURL=UwebSocketsMiddleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsMiddleware.d.ts","sourceRoot":"","sources":["../../../src/models/UwebSocketsMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3D,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAC5C,WAAW,EACX,YAAY,EACZ,MAAM,IAAI,EACV,IAAI,CACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=UwebSocketsMiddleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UwebSocketsMiddleware.js","sourceRoot":"","sources":["../../../src/models/UwebSocketsMiddleware.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,36 @@
1
+ import { Readable } from 'node:stream';
2
+ import { HttpAdapterOptions, InversifyHttpAdapter, RouterParams, HttpStatusCode, ErrorFilter, Guard, Interceptor, Middleware } from '@inversifyjs/http-core';
3
+ import { Container } from 'inversify';
4
+ import { HttpRequest, HttpResponse, TemplatedApp } from 'uWebSockets.js';
5
+
6
+ interface UwebSocketsHttpAdapterOptions extends HttpAdapterOptions {
7
+ useJson?: boolean;
8
+ }
9
+
10
+ declare class InversifyUwebSocketsHttpAdapter extends InversifyHttpAdapter<HttpRequest, HttpResponse, () => void, void, UwebSocketsHttpAdapterOptions> {
11
+ #private;
12
+ constructor(container: Container, httpAdapterOptions?: UwebSocketsHttpAdapterOptions, customApp?: TemplatedApp);
13
+ build(): Promise<TemplatedApp>;
14
+ protected _buildRouter(routerParams: RouterParams<HttpRequest, HttpResponse, () => void, void>): void;
15
+ protected _replyJson(_request: HttpRequest, response: HttpResponse, value?: object): void;
16
+ protected _replyText(_request: HttpRequest, response: HttpResponse, value?: string): void;
17
+ protected _replyStream(_request: HttpRequest, response: HttpResponse, stream: Readable): void;
18
+ protected _setStatus(_request: HttpRequest, response: HttpResponse, statusCode: HttpStatusCode): void;
19
+ protected _setHeader(_request: HttpRequest, response: HttpResponse, key: string, value: string): void;
20
+ protected _getBody(_request: HttpRequest, response: HttpResponse, parameterName?: string): Promise<unknown>;
21
+ protected _getParams(request: HttpRequest, parameterName?: string): unknown;
22
+ protected _getQuery(request: HttpRequest, parameterName?: string): unknown;
23
+ protected _getHeaders(request: HttpRequest, parameterName?: string): unknown;
24
+ protected _getCookies(request: HttpRequest, _response: HttpResponse, parameterName?: string): unknown;
25
+ }
26
+
27
+ type UwebSocketsErrorFilter<TError = unknown> = ErrorFilter<TError, HttpRequest, HttpResponse, void>;
28
+
29
+ type UwebSocketsGuard = Guard<HttpRequest>;
30
+
31
+ type UwebSocketsInterceptor = Interceptor<HttpRequest, HttpResponse>;
32
+
33
+ type UwebSocketsMiddleware = Middleware<HttpRequest, HttpResponse, () => void, void>;
34
+
35
+ export { InversifyUwebSocketsHttpAdapter };
36
+ export type { UwebSocketsErrorFilter, UwebSocketsGuard, UwebSocketsHttpAdapterOptions, UwebSocketsInterceptor, UwebSocketsMiddleware };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,2CAA2C,CAAC;AAC5F,YAAY,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AAC5F,YAAY,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC9E,YAAY,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{InversifyHttpAdapter as e,RequestMethodParameterType as t,RequestMethodType as r}from"@inversifyjs/http-core";import{App as s}from"uWebSockets.js";import{Buffer as o}from"node:buffer";const n=Symbol.for("aborted");function i(e,t,r){let s,i,a=!1;const p=()=>{a||(a=!0,t.destroy(),s=void 0,i=void 0)};e.onAborted(()=>{p()}),t.on("data",r=>{if(!0===e[n])return void p();const a=function(e){const t="string"==typeof e?o.from(e):o.isBuffer(e)?e:o.from(e.toString()),r=t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength);if(r instanceof SharedArrayBuffer){const e=new ArrayBuffer(r.byteLength);return new Uint8Array(e).set(new Uint8Array(r)),e}return r}(r),d=e.getWriteOffset(),[u,c]=e.tryEnd(a,a.byteLength);c?p():u||(t.pause(),s=a,i=d,e.onWritable(r=>{if(!0===e[n])return p(),!1;if(void 0===s||void 0===i)return!1;const[o,a]=e.tryEnd(s.slice(r-i),s.byteLength);return a?p():o&&t.resume(),o}))}),t.on("error",t=>{r?.error(t.stack??t.message),p(),!0!==e[n]&&e.cork(()=>{e.writeStatus("500"),e.end("Stream error occurred")})}),t.on("end",()=>{p()})}class a extends e{#e;constructor(e,r,s){super(e,{logger:!0,useJson:!0},r,[t.Body]),this.#e=s??this.#t()}async build(){return await this._buildServer(),this.#e}_buildRouter(e){for(const t of e.routeParamsList){const r=[...t.preHandlerMiddlewareList,...t.guardList,t.handler,...t.postHandlerMiddlewareList];let s=`${e.path}${t.path}`;s.endsWith("/")&&s.length>1&&(s=s.slice(0,-1)),this.#r(t.requestMethodType)(s,async(e,t)=>{e.onAborted(()=>{e[n]=!0});let s=0,[o]=r,i=!1;const a=()=>{i=!0};for(;void 0!==o&&(await o(t,e,a),i);)i=!1,o=r[++s]})}}_replyJson(e,t,r){!0!==t[n]&&t.cork(()=>{t.end(JSON.stringify(r))})}_replyText(e,t,r){!0!==t[n]&&t.cork(()=>{t.end(r)})}_replyStream(e,t,r){i(t,r,!1===this.httpAdapterOptions.logger?void 0:this._logger)}_setStatus(e,t,r){t.cork(()=>{t.writeStatus(r.toString())})}_setHeader(e,t,r,s){t.cork(()=>{t.writeHeader(r,s)})}async _getBody(e,t,r){const s=await this.#s(t);if(void 0===r)return s;if(!(r in s))throw new Error(`Body parameter '${r}' not found.`);return s[r]}_getParams(e,t){if(void 0===t)throw new Error("Getting all route parameters is not supported in uWebSockets.js adapter.");return e.getParameter(t)}_getQuery(e,t){return void 0===t?this.#o(e):e.getQuery(t)}_getHeaders(e,t){return void 0===t?this.#n(e):e.getHeader(t)}_getCookies(e,t,r){const s=this.#i(e);return void 0===r?s:s[r]}#t(){return s()}#r(e){switch(e){case r.All:return this.#e.any.bind(this.#e);case r.Delete:return this.#e.del.bind(this.#e);case r.Get:return this.#e.get.bind(this.#e);case r.Head:return this.#e.head.bind(this.#e);case r.Options:return this.#e.options.bind(this.#e);case r.Patch:return this.#e.patch.bind(this.#e);case r.Post:return this.#e.post.bind(this.#e);case r.Put:return this.#e.put.bind(this.#e)}}async#s(e){return new Promise(t=>{let r;e.onData((e,s)=>{const o=Buffer.from(e);if(r=r?Buffer.concat([r,o]):s?o:Buffer.concat([o]),s){const e=r.toString();this.httpAdapterOptions.useJson?t(JSON.parse(e)):t(e)}})})}#i(e){const t=e.getHeader("cookie");if(""===t)return{};const r={};for(const e of t.split(";")){const[t,...s]=e.split("="),o=s.join("=").trim();void 0!==t&&(r[t.trim()]=decodeURIComponent(o))}return r}#n(e){const t={};return e.forEach((e,r)=>{t[e]=r}),t}#o(e){const t=new URLSearchParams(e.getQuery()).entries(),r={};for(const[e,s]of t)void 0!==r[e]?Array.isArray(r[e])?r[e].push(s):r[e]=[r[e],s]:r[e]=s;return r}}export{a as InversifyUwebSocketsHttpAdapter};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/data/abortedSymbol.ts","../../src/actions/pipeStreamOverResponse.ts","../../src/calculations/toArrayBuffer.ts","../../src/adapter/InversifyUwebSocketsHttpAdapter.ts"],"sourcesContent":[null,null,null,null],"names":["abortedSymbol","Symbol","for","pipeStreamOverResponse","response","readableStream","logger","storedBuffer","storedOffset","isStreamClosed","cleanup","destroy","undefined","onAborted","on","chunk","arrayBuffer","buffer","Buffer","from","isBuffer","toString","slice","byteOffset","byteLength","SharedArrayBuffer","newArrayBuffer","ArrayBuffer","Uint8Array","set","toArrayBuffer","lastOffset","getWriteOffset","ok","done","tryEnd","pause","onWritable","offset","retryOk","retryDone","resume","error","stack","message","cork","writeStatus","end","InversifyUwebSocketsHttpAdapter","InversifyHttpAdapter","app","constructor","container","httpAdapterOptions","customApp","super","useJson","RequestMethodParameterType","Body","this","buildDefaultApp","build","_buildServer","_buildRouter","routerParams","routeParams","routeParamsList","orderedHandlers","preHandlerMiddlewareList","guardList","handler","postHandlerMiddlewareList","routePath","path","endsWith","length","getAppRouteHandler","requestMethodType","async","res","req","currentIndex","currentHandler","nextCalled","next","_replyJson","_request","value","JSON","stringify","_replyText","_replyStream","stream","_logger","_setStatus","statusCode","_setHeader","key","writeHeader","_getBody","parameterName","body","parseBody","Error","_getParams","request","getParameter","_getQuery","parseQuery","getQuery","_getHeaders","parseHeaders","getHeader","_getCookies","_response","cookies","parseCookies","App","RequestMethodType","All","any","bind","Delete","del","Get","get","Head","head","Options","options","Patch","patch","Post","post","Put","put","Promise","resolve","onData","isLast","curBuf","concat","stringifiedBody","parse","cookieHeader","cookie","split","name","rest","join","trim","decodeURIComponent","headers","forEach","queryEntries","URLSearchParams","entries","result","Array","isArray","push"],"mappings":"+LAAO,MAAMA,EAA+BC,OAAOC,IAAI,oBC8BvCC,EACdC,EACAC,EACAC,GAEA,IACIC,EACAC,EAFAC,GAA0B,EAO9B,MAAMC,EAAsB,KACrBD,IACHA,GAAiB,EACjBJ,EAAeM,UACfJ,OAAeK,EACfJ,OAAeI,IAKnBR,EAASS,UAAU,KACjBH,MAIFL,EAAeS,GAAG,OAASC,IACzB,IAAwD,IAAnDX,EAAgCJ,GAEnC,YADAU,IAIF,MAAMM,EClDJ,SAAwBD,GAC5B,MAAME,EACa,iBAAVF,EACHG,EAAOC,KAAKJ,GACZG,EAAOE,SAASL,GACdA,EACAG,EAAOC,KAEJJ,EAAwDM,YAG7DL,EAA+CC,EAAOA,OAAOK,MACjEL,EAAOM,WACPN,EAAOM,WAAaN,EAAOO,YAG7B,GAAIR,aAAuBS,kBAAmB,CAC5C,MAAMC,EAA8B,IAAIC,YAAYX,EAAYQ,YAIhE,OAFA,IAAII,WAAWF,GAAgBG,IAAI,IAAID,WAAWZ,IAE3CU,CACT,CAEA,OAAOV,CACT,CDyBqCc,CAAcf,GAEzCgB,EAAqB3B,EAAS4B,kBAE7BC,EAAIC,GAA4B9B,EAAS+B,OAC9CnB,EACAA,EAAYQ,YAGVU,EACFxB,IACUuB,IACV5B,EAAe+B,QAEf7B,EAAeS,EACfR,EAAeuB,EAEf3B,EAASiC,WAAYC,IACnB,IAAwD,IAAnDlC,EAAgCJ,GAEnC,OADAU,KACO,EAGT,QAAqBE,IAAjBL,QAA+CK,IAAjBJ,EAChC,OAAO,EAGT,MAAO+B,EAASC,GAAiCpC,EAAS+B,OACxD5B,EAAae,MAAMgB,EAAS9B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AEA,EAAAJ,CAAcN,GACZ,MAAM+C,EAAkC,CAAA,EAIxC,OAHA/C,EAAQgD,QAAQ,CAACxD,EAAaV,KAC5BiE,EAAQvD,GAAOV,IAEViE,CACT,CAEA,EAAA5C,CAAYH,GACV,MAAMiD,EACJ,IAAIC,gBAAgBlD,EAAQI,YAAY+C,UAEpCC,EAA4C,CAAA,EAElD,IAAK,MAAO5D,EAAKV,KAAUmE,OACL9I,IAAhBiJ,EAAO5D,GACL6D,MAAMC,QAAQF,EAAO5D,IACvB4D,EAAO5D,GAAK+D,KAAKzE,GAEjBsE,EAAO5D,GAAO,CAAC4D,EAAO5D,GAAMV,GAG9BsE,EAAO5D,GAAOV,EAIlB,OAAOsE,CACT"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "author": "Roberto Pintos López",
3
+ "bugs": {
4
+ "url": "https://github.com/inversify/monorepo/issues"
5
+ },
6
+ "description": "InversifyJs http express package",
7
+ "dependencies": {
8
+ "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.55.0",
9
+ "@inversifyjs/http-core": "4.1.0"
10
+ },
11
+ "devDependencies": {
12
+ "@stryker-mutator/core": "9.3.0",
13
+ "@stryker-mutator/vitest-runner": "9.3.0",
14
+ "@stryker-mutator/typescript-checker": "9.3.0",
15
+ "@types/node": "24.10.0",
16
+ "@vitest/coverage-v8": "4.0.7",
17
+ "eslint": "9.38.0",
18
+ "prettier": "3.6.2",
19
+ "rimraf": "6.1.0",
20
+ "rollup": "4.52.5",
21
+ "ts-loader": "9.5.4",
22
+ "tslib": "2.8.1",
23
+ "typescript": "5.9.3",
24
+ "vitest": "4.0.7"
25
+ },
26
+ "devEngines": {
27
+ "node": "^24.10.0",
28
+ "pnpm": "^10.13.1"
29
+ },
30
+ "homepage": "https://inversify.io",
31
+ "keywords": [
32
+ "dependency injection",
33
+ "dependency inversion",
34
+ "di",
35
+ "inversion of control container",
36
+ "ioc",
37
+ "javascript",
38
+ "node",
39
+ "typescript"
40
+ ],
41
+ "license": "MIT",
42
+ "main": "lib/cjs/index.js",
43
+ "module": "lib/esm/index.js",
44
+ "exports": {
45
+ ".": {
46
+ "import": "./lib/esm/index.js",
47
+ "require": "./lib/cjs/index.js"
48
+ }
49
+ },
50
+ "name": "@inversifyjs/http-uwebsockets",
51
+ "peerDependencies": {
52
+ "@inversifyjs/logger": "^1.1.0",
53
+ "inversify": "^7.10.4"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/inversify/monorepo.git"
61
+ },
62
+ "version": "4.1.0",
63
+ "scripts": {
64
+ "build": "pnpm run build:cjs && pnpm run build:esm",
65
+ "build:cjs": "tsc --build tsconfig.cjs.json && pnpm exec foundation-ts-package-cjs ./lib/cjs",
66
+ "build:esm": "rollup -c ./rollup.config.mjs && pnpm exec foundation-ts-package-esm ./lib/esm",
67
+ "build:clean": "rimraf lib",
68
+ "format": "prettier --write ./src/**/*.ts",
69
+ "lint": "eslint ./src",
70
+ "prebuild": "pnpm run build:clean",
71
+ "test": "vitest run",
72
+ "test:integration": "pnpm run test --project Integration",
73
+ "test:coverage": "pnpm run test:unit --coverage",
74
+ "test:uncommitted": "pnpm run test --changed=HEAD",
75
+ "test:unit": "pnpm run test --project Unit"
76
+ }
77
+ }