@nmtjs/ws-transport 0.8.0 → 0.9.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.
- package/dist/http.js +148 -0
- package/dist/http.js.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/injectables.js +8 -1
- package/dist/injectables.js.map +1 -1
- package/dist/server.js +232 -47
- package/dist/server.js.map +1 -1
- package/dist/transport.js +2 -0
- package/dist/transport.js.map +1 -1
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -1
- package/dist/utils.js +53 -9
- package/dist/utils.js.map +1 -1
- package/package.json +7 -7
- package/src/http.ts +150 -0
- package/src/injectables.ts +6 -1
- package/src/server.ts +308 -68
- package/src/transport.ts +2 -2
- package/src/types.ts +7 -9
- package/src/utils.ts +63 -13
package/dist/transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AAAA,SAAS,uBAAuB,wBAAwB;AACxD,
|
|
1
|
+
{"mappings":"AAAA,SAAS,uBAAuB,wBAAwB;AACxD,SAAS,yBAAyB,aAAa;AAG/C,OAAO,MAAM,cAAc,gBAGzB,eAAe,CAAC,SAAS,YAAY;AACrC,QAAO,IAAI,kBAAkB,SAAS;AACvC,EAAC","names":[],"sources":["../src/transport.ts"],"sourcesContent":["import { createTransport } from '@nmtjs/protocol/server'\nimport { WsTransportServer } from './server.ts'\nimport type { WsConnectionData, WsTransportOptions } from './types.ts'\n\nexport const WsTransport = createTransport<\n WsConnectionData,\n WsTransportOptions\n>('WsTransport', (context, options) => {\n return new WsTransportServer(context, options)\n})\n"],"version":3,"file":"transport.js"}
|
package/dist/types.js
CHANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"","names":[],"sources":["src/types.ts"],"sourcesContent":["import type { AppOptions, WebSocket } from 'uWebSockets.js'\nimport type { Connection, ConnectionContext } from '@nmtjs/protocol/server'\nimport type { InteractivePromise } from '../../common/src/index.ts'\n\nexport type WsUserData = {\n id: Connection['id']\n
|
|
1
|
+
{"mappings":"","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { AppOptions, WebSocket } from 'uWebSockets.js'\nimport type { Connection, ConnectionContext } from '@nmtjs/protocol/server'\nimport type { InteractivePromise } from '../../common/src/index.ts'\nimport type { RequestData } from './utils.ts'\n\nexport type WsConnectionData = { type: 'ws' | 'http' }\n\nexport type WsUserData = {\n id: Connection['id']\n backpressure: InteractivePromise<void> | null\n request: RequestData\n acceptType: string | null\n contentType: string | null\n context: ConnectionContext\n}\n\nexport type WsTransportSocket = WebSocket<WsUserData>\n\nexport type WsTransportOptions = {\n port?: number\n hostname?: string\n unix?: string\n tls?: AppOptions\n cors?: boolean | string[] | ((origin: string) => boolean)\n maxPayloadLength?: number\n maxStreamChunkLength?: number\n}\n"],"version":3,"file":"types.js"}
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PassThrough } from "node:stream";
|
|
1
2
|
import { createPromise } from "@nmtjs/common";
|
|
2
3
|
import { concat, ErrorCode, encodeNumber } from "@nmtjs/protocol/common";
|
|
3
4
|
import { ProtocolError } from "@nmtjs/protocol/server";
|
|
@@ -25,22 +26,65 @@ export const toRecord = (input) => {
|
|
|
25
26
|
});
|
|
26
27
|
return obj;
|
|
27
28
|
};
|
|
28
|
-
export const getRequestData = (req) => {
|
|
29
|
+
export const getRequestData = (req, res) => {
|
|
29
30
|
const url = req.getUrl();
|
|
30
31
|
const method = req.getMethod();
|
|
31
|
-
const headers = new
|
|
32
|
-
|
|
33
|
-
const query = new URLSearchParams(
|
|
34
|
-
const origin = headers.
|
|
35
|
-
|
|
32
|
+
const headers = new Headers();
|
|
33
|
+
const querystring = req.getQuery();
|
|
34
|
+
const query = new URLSearchParams(querystring);
|
|
35
|
+
const origin = headers.get("origin");
|
|
36
|
+
const proxiedRemoteAddress = res.getProxiedRemoteAddressAsText();
|
|
37
|
+
const remoteAddress = res.getRemoteAddressAsText();
|
|
38
|
+
req.forEach((key, value) => headers.append(key, value));
|
|
39
|
+
return Object.freeze({
|
|
36
40
|
url,
|
|
37
|
-
origin,
|
|
41
|
+
origin: origin ? new URL(url, origin) : null,
|
|
38
42
|
method,
|
|
39
43
|
headers,
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
querystring,
|
|
45
|
+
query,
|
|
46
|
+
remoteAddress: Buffer.from(remoteAddress).toString(),
|
|
47
|
+
proxiedRemoteAddress: Buffer.from(proxiedRemoteAddress).toString()
|
|
48
|
+
});
|
|
42
49
|
};
|
|
50
|
+
export function getRequestBody(res) {
|
|
51
|
+
const stream = new PassThrough();
|
|
52
|
+
res.onData((chunk, isLast) => {
|
|
53
|
+
stream.write(Buffer.from(chunk));
|
|
54
|
+
if (isLast) stream.end();
|
|
55
|
+
});
|
|
56
|
+
res.onAborted(() => stream.destroy());
|
|
57
|
+
return stream;
|
|
58
|
+
}
|
|
59
|
+
export function setHeaders(res, headers) {
|
|
60
|
+
headers.forEach((value, key) => {
|
|
61
|
+
if (key === "set-cookie") return;
|
|
62
|
+
res.writeHeader(key, value);
|
|
63
|
+
});
|
|
64
|
+
const cookies = headers.getSetCookie();
|
|
65
|
+
if (cookies) {
|
|
66
|
+
for (const cookie of cookies) {
|
|
67
|
+
res.writeHeader("set-cookie", cookie);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function readableToArrayBuffer(stream) {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
const chunks = [];
|
|
74
|
+
stream.on("data", (chunk) => {
|
|
75
|
+
chunks.push(chunk);
|
|
76
|
+
});
|
|
77
|
+
stream.on("end", () => {
|
|
78
|
+
resolve(Buffer.concat(chunks).buffer);
|
|
79
|
+
});
|
|
80
|
+
stream.on("error", (error) => {
|
|
81
|
+
reject(error);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
43
85
|
export const InternalError = (message = "Internal Server Error") => new ProtocolError(ErrorCode.InternalServerError, message);
|
|
44
86
|
export const NotFoundError = (message = "Not Found") => new ProtocolError(ErrorCode.NotFound, message);
|
|
45
87
|
export const ForbiddenError = (message = "Forbidden") => new ProtocolError(ErrorCode.Forbidden, message);
|
|
46
88
|
export const RequestTimeoutError = (message = "Request Timeout") => new ProtocolError(ErrorCode.RequestTimeout, message);
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"AACA,SAAS,qBAAqB,eAAe;AAC7C,SAAS,QAAQ,WAAW,oBAAoB,wBAAwB;AACxE,SAAS,qBAAqB,wBAAwB;AAGtD,OAAO,MAAM,OAAO,CAClBA,IACAC,MACA,GAAG,YACgB;CACnB,MAAM,OAAO,GAAG,aAAa;AAC7B,KAAI;EACF,MAAM,SAAS,OAAO,aAAa,MAAM,QAAQ,EAAE,GAAG,QAAQ;EAC9D,MAAM,SAAS,GAAG,KAAK,QAAQ,KAAK;AACpC,MAAI,WAAW,GAAG;AAChB,QAAK,eAAe,eAAe;AACnC,UAAO;EACR;AACD,MAAI,WAAW,GAAG;AAChB,UAAO;EACR;AACD,SAAO;CACR,SAAQ,OAAO;AACd,SAAO;CACR;AACF;AAED,OAAO,MAAM,WAAW,CAACC,UAEnB;CACJ,MAAMC,MAA8B,CAAE;AACtC,OAAM,QAAQ,CAAC,OAAO,QAAQ;AAC5B,MAAI,OAAO;CACZ,EAAC;AACF,QAAO;AACR;
|
|
1
|
+
{"mappings":"AACA,SAAS,mBAAkC,aAAa;AACxD,SAAS,qBAAqB,eAAe;AAC7C,SAAS,QAAQ,WAAW,oBAAoB,wBAAwB;AACxE,SAAS,qBAAqB,wBAAwB;AAGtD,OAAO,MAAM,OAAO,CAClBA,IACAC,MACA,GAAG,YACgB;CACnB,MAAM,OAAO,GAAG,aAAa;AAC7B,KAAI;EACF,MAAM,SAAS,OAAO,aAAa,MAAM,QAAQ,EAAE,GAAG,QAAQ;EAC9D,MAAM,SAAS,GAAG,KAAK,QAAQ,KAAK;AACpC,MAAI,WAAW,GAAG;AAChB,QAAK,eAAe,eAAe;AACnC,UAAO;EACR;AACD,MAAI,WAAW,GAAG;AAChB,UAAO;EACR;AACD,SAAO;CACR,SAAQ,OAAO;AACd,SAAO;CACR;AACF;AAED,OAAO,MAAM,WAAW,CAACC,UAEnB;CACJ,MAAMC,MAA8B,CAAE;AACtC,OAAM,QAAQ,CAAC,OAAO,QAAQ;AAC5B,MAAI,OAAO;CACZ,EAAC;AACF,QAAO;AACR;AAaD,OAAO,MAAM,iBAAiB,CAC5BC,KACAC,QACgB;CAChB,MAAM,MAAM,IAAI,QAAQ;CACxB,MAAM,SAAS,IAAI,WAAW;CAC9B,MAAM,UAAU,IAAI;CACpB,MAAM,cAAc,IAAI,UAAU;CAClC,MAAM,QAAQ,IAAI,gBAAgB;CAClC,MAAM,SAAS,QAAQ,IAAI,SAAS;CACpC,MAAM,uBAAuB,IAAI,+BAA+B;CAChE,MAAM,gBAAgB,IAAI,wBAAwB;AAElD,KAAI,QAAQ,CAAC,KAAK,UAAU,QAAQ,OAAO,KAAK,MAAM,CAAC;AAEvD,QAAO,OAAO,OAAO;EACnB;EACA,QAAQ,SAAS,IAAI,IAAI,KAAK,UAAU;EACxC;EACA;EACA;EACA;EACA,eAAe,OAAO,KAAK,cAAc,CAAC,UAAU;EACpD,sBAAsB,OAAO,KAAK,qBAAqB,CAAC,UAAU;CACnE,EAAC;AACH;AAED,OAAO,SAAS,eAAeA,KAAmB;CAChD,MAAM,SAAS,IAAI;AACnB,KAAI,OAAO,CAAC,OAAO,WAAW;AAC5B,SAAO,MAAM,OAAO,KAAK,MAAM,CAAC;AAChC,MAAI,OAAQ,QAAO,KAAK;CACzB,EAAC;AACF,KAAI,UAAU,MAAM,OAAO,SAAS,CAAC;AACrC,QAAO;AACR;AAED,OAAO,SAAS,WAAWA,KAAmBC,SAAkB;AAC9D,SAAQ,QAAQ,CAAC,OAAO,QAAQ;AAC9B,MAAI,QAAQ,aAAc;AAC1B,MAAI,YAAY,KAAK,MAAM;CAC5B,EAAC;CACF,MAAM,UAAU,QAAQ,cAAc;AACtC,KAAI,SAAS;AACX,OAAK,MAAM,UAAU,SAAS;AAC5B,OAAI,YAAY,cAAc,OAAO;EACtC;CACF;AACF;AAED,OAAO,SAAS,sBAAsBC,QAAwC;AAC5E,QAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;EACtC,MAAMC,SAAmB,CAAE;AAC3B,SAAO,GAAG,QAAQ,CAAC,UAAU;AAC3B,UAAO,KAAK,MAAM;EACnB,EAAC;AACF,SAAO,GAAG,OAAO,MAAM;AACrB,WAAQ,OAAO,OAAO,OAAO,CAAC,OAAO;EACtC,EAAC;AACF,SAAO,GAAG,SAAS,CAAC,UAAU;AAC5B,UAAO,MAAM;EACd,EAAC;CACH;AACF;AAED,OAAO,MAAM,gBAAgB,CAAC,UAAU,4BACtC,IAAI,cAAc,UAAU,qBAAqB;AAEnD,OAAO,MAAM,gBAAgB,CAAC,UAAU,gBACtC,IAAI,cAAc,UAAU,UAAU;AAExC,OAAO,MAAM,iBAAiB,CAAC,UAAU,gBACvC,IAAI,cAAc,UAAU,WAAW;AAEzC,OAAO,MAAM,sBAAsB,CAAC,UAAU,sBAC5C,IAAI,cAAc,UAAU,gBAAgB","names":["ws: WsTransportSocket","type: number","input: {\n forEach: (cb: (value, key) => void) => void\n}","obj: Record<string, string>","req: HttpRequest","res: HttpResponse","headers: Headers","stream: Readable","chunks: Buffer[]"],"sources":["../src/utils.ts"],"sourcesContent":["import type { HttpRequest, HttpResponse } from 'uWebSockets.js'\nimport { PassThrough, type Readable } from 'node:stream'\nimport { createPromise } from '@nmtjs/common'\nimport { concat, ErrorCode, encodeNumber } from '@nmtjs/protocol/common'\nimport { ProtocolError } from '@nmtjs/protocol/server'\nimport type { WsTransportSocket } from './types.ts'\n\nexport const send = (\n ws: WsTransportSocket,\n type: number,\n ...buffers: ArrayBuffer[]\n): boolean | null => {\n const data = ws.getUserData()\n try {\n const buffer = concat(encodeNumber(type, 'Uint8'), ...buffers)\n const result = ws.send(buffer, true)\n if (result === 0) {\n data.backpressure = createPromise()\n return false\n }\n if (result === 2) {\n return null\n }\n return true\n } catch (error) {\n return null\n }\n}\n\nexport const toRecord = (input: {\n forEach: (cb: (value, key) => void) => void\n}) => {\n const obj: Record<string, string> = {}\n input.forEach((value, key) => {\n obj[key] = value\n })\n return obj\n}\n\nexport type RequestData = Readonly<{\n url: string\n origin: URL | null\n method: string\n headers: Headers\n querystring: string\n query: URLSearchParams\n remoteAddress: string\n proxiedRemoteAddress: string\n}>\n\nexport const getRequestData = (\n req: HttpRequest,\n res: HttpResponse,\n): RequestData => {\n const url = req.getUrl()\n const method = req.getMethod()\n const headers = new Headers()\n const querystring = req.getQuery()\n const query = new URLSearchParams(querystring)\n const origin = headers.get('origin')\n const proxiedRemoteAddress = res.getProxiedRemoteAddressAsText()\n const remoteAddress = res.getRemoteAddressAsText()\n\n req.forEach((key, value) => headers.append(key, value))\n\n return Object.freeze({\n url,\n origin: origin ? new URL(url, origin) : null,\n method,\n headers,\n querystring,\n query,\n remoteAddress: Buffer.from(remoteAddress).toString(),\n proxiedRemoteAddress: Buffer.from(proxiedRemoteAddress).toString(),\n })\n}\n\nexport function getRequestBody(res: HttpResponse) {\n const stream = new PassThrough()\n res.onData((chunk, isLast) => {\n stream.write(Buffer.from(chunk))\n if (isLast) stream.end()\n })\n res.onAborted(() => stream.destroy())\n return stream\n}\n\nexport function setHeaders(res: HttpResponse, headers: Headers) {\n headers.forEach((value, key) => {\n if (key === 'set-cookie') return\n res.writeHeader(key, value)\n })\n const cookies = headers.getSetCookie()\n if (cookies) {\n for (const cookie of cookies) {\n res.writeHeader('set-cookie', cookie)\n }\n }\n}\n\nexport function readableToArrayBuffer(stream: Readable): Promise<ArrayBuffer> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = []\n stream.on('data', (chunk) => {\n chunks.push(chunk)\n })\n stream.on('end', () => {\n resolve(Buffer.concat(chunks).buffer)\n })\n stream.on('error', (error) => {\n reject(error)\n })\n })\n}\n\nexport const InternalError = (message = 'Internal Server Error') =>\n new ProtocolError(ErrorCode.InternalServerError, message)\n\nexport const NotFoundError = (message = 'Not Found') =>\n new ProtocolError(ErrorCode.NotFound, message)\n\nexport const ForbiddenError = (message = 'Forbidden') =>\n new ProtocolError(ErrorCode.Forbidden, message)\n\nexport const RequestTimeoutError = (message = 'Request Timeout') =>\n new ProtocolError(ErrorCode.RequestTimeout, message)\n"],"version":3,"file":"utils.js"}
|
package/package.json
CHANGED
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.51.0"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@nmtjs/
|
|
15
|
-
"@nmtjs/
|
|
16
|
-
"@nmtjs/
|
|
14
|
+
"@nmtjs/protocol": "0.9.0",
|
|
15
|
+
"@nmtjs/common": "0.9.0",
|
|
16
|
+
"@nmtjs/core": "0.9.0"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/node": "^18",
|
|
20
|
-
"@nmtjs/
|
|
21
|
-
"@nmtjs/
|
|
22
|
-
"@nmtjs/
|
|
20
|
+
"@nmtjs/common": "0.9.0",
|
|
21
|
+
"@nmtjs/protocol": "0.9.0",
|
|
22
|
+
"@nmtjs/client": "0.9.0"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=18"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"LICENSE.md",
|
|
31
31
|
"README.md"
|
|
32
32
|
],
|
|
33
|
-
"version": "0.
|
|
33
|
+
"version": "0.9.0",
|
|
34
34
|
"scripts": {
|
|
35
35
|
"build": "neemata-build --root ./src './**/*.ts'",
|
|
36
36
|
"type-check": "tsc --noEmit"
|
package/src/http.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { createMetadataKey } from '@nmtjs/core'
|
|
2
|
+
import { ErrorCode } from '@nmtjs/protocol/common'
|
|
3
|
+
|
|
4
|
+
export enum HttpCode {
|
|
5
|
+
Continue = 100,
|
|
6
|
+
SwitchingProtocols = 101,
|
|
7
|
+
Processing = 102,
|
|
8
|
+
EarlyHints = 103,
|
|
9
|
+
OK = 200,
|
|
10
|
+
Created = 201,
|
|
11
|
+
Accepted = 202,
|
|
12
|
+
NonAuthoritativeInformation = 203,
|
|
13
|
+
NoContent = 204,
|
|
14
|
+
ResetContent = 205,
|
|
15
|
+
PartialContent = 206,
|
|
16
|
+
MultiStatus = 207,
|
|
17
|
+
AlreadyReported = 208,
|
|
18
|
+
IMUsed = 226,
|
|
19
|
+
MultipleChoices = 300,
|
|
20
|
+
MovedPermanently = 301,
|
|
21
|
+
Found = 302,
|
|
22
|
+
SeeOther = 303,
|
|
23
|
+
NotModified = 304,
|
|
24
|
+
UseProxy = 305,
|
|
25
|
+
TemporaryRedirect = 307,
|
|
26
|
+
PermanentRedirect = 308,
|
|
27
|
+
BadRequest = 400,
|
|
28
|
+
Unauthorized = 401,
|
|
29
|
+
PaymentRequired = 402,
|
|
30
|
+
Forbidden = 403,
|
|
31
|
+
NotFound = 404,
|
|
32
|
+
MethodNotAllowed = 405,
|
|
33
|
+
NotAcceptable = 406,
|
|
34
|
+
ProxyAuthenticationRequired = 407,
|
|
35
|
+
RequestTimeout = 408,
|
|
36
|
+
Conflict = 409,
|
|
37
|
+
Gone = 410,
|
|
38
|
+
LengthRequired = 411,
|
|
39
|
+
PreconditionFailed = 412,
|
|
40
|
+
PayloadTooLarge = 413,
|
|
41
|
+
URITooLong = 414,
|
|
42
|
+
UnsupportedMediaType = 415,
|
|
43
|
+
RangeNotSatisfiable = 416,
|
|
44
|
+
ExpectationFailed = 417,
|
|
45
|
+
ImATeapot = 418,
|
|
46
|
+
MisdirectedRequest = 421,
|
|
47
|
+
UnprocessableEntity = 422,
|
|
48
|
+
Locked = 423,
|
|
49
|
+
FailedDependency = 424,
|
|
50
|
+
TooEarly = 425,
|
|
51
|
+
UpgradeRequired = 426,
|
|
52
|
+
PreconditionRequired = 428,
|
|
53
|
+
TooManyRequests = 429,
|
|
54
|
+
RequestHeaderFieldsTooLarge = 431,
|
|
55
|
+
UnavailableForLegalReasons = 451,
|
|
56
|
+
InternalServerError = 500,
|
|
57
|
+
NotImplemented = 501,
|
|
58
|
+
BadGateway = 502,
|
|
59
|
+
ServiceUnavailable = 503,
|
|
60
|
+
GatewayTimeout = 504,
|
|
61
|
+
HTTPVersionNotSupported = 505,
|
|
62
|
+
VariantAlsoNegotiates = 506,
|
|
63
|
+
InsufficientStorage = 507,
|
|
64
|
+
LoopDetected = 508,
|
|
65
|
+
NotExtended = 510,
|
|
66
|
+
NetworkAuthenticationRequired = 511,
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const HttpStatusText: Record<HttpCode, string> = {
|
|
70
|
+
[HttpCode.Continue]: 'Continue',
|
|
71
|
+
[HttpCode.SwitchingProtocols]: 'Switching Protocols',
|
|
72
|
+
[HttpCode.Processing]: 'Processing',
|
|
73
|
+
[HttpCode.EarlyHints]: 'Early Hints',
|
|
74
|
+
[HttpCode.OK]: 'OK',
|
|
75
|
+
[HttpCode.Created]: 'Created',
|
|
76
|
+
[HttpCode.Accepted]: 'Accepted',
|
|
77
|
+
[HttpCode.NonAuthoritativeInformation]: 'Non-Authoritative Information',
|
|
78
|
+
[HttpCode.NoContent]: 'No Content',
|
|
79
|
+
[HttpCode.ResetContent]: 'Reset Content',
|
|
80
|
+
[HttpCode.PartialContent]: 'Partial Content',
|
|
81
|
+
[HttpCode.MultiStatus]: 'Multi-Status',
|
|
82
|
+
[HttpCode.AlreadyReported]: 'Already Reported',
|
|
83
|
+
[HttpCode.IMUsed]: 'IM Used',
|
|
84
|
+
[HttpCode.MultipleChoices]: 'Multiple Choices',
|
|
85
|
+
[HttpCode.MovedPermanently]: 'Moved Permanently',
|
|
86
|
+
[HttpCode.Found]: 'Found',
|
|
87
|
+
[HttpCode.SeeOther]: 'See Other',
|
|
88
|
+
[HttpCode.NotModified]: 'Not Modified',
|
|
89
|
+
[HttpCode.UseProxy]: 'Use Proxy',
|
|
90
|
+
[HttpCode.TemporaryRedirect]: 'Temporary Redirect',
|
|
91
|
+
[HttpCode.PermanentRedirect]: 'Permanent Redirect',
|
|
92
|
+
[HttpCode.BadRequest]: 'Bad Request',
|
|
93
|
+
[HttpCode.Unauthorized]: 'Unauthorized',
|
|
94
|
+
[HttpCode.PaymentRequired]: 'Payment Required',
|
|
95
|
+
[HttpCode.Forbidden]: 'Forbidden',
|
|
96
|
+
[HttpCode.NotFound]: 'Not Found',
|
|
97
|
+
[HttpCode.MethodNotAllowed]: 'Method Not Allowed',
|
|
98
|
+
[HttpCode.NotAcceptable]: 'Not Acceptable',
|
|
99
|
+
[HttpCode.ProxyAuthenticationRequired]: 'Proxy Authentication Required',
|
|
100
|
+
[HttpCode.RequestTimeout]: 'Request Timeout',
|
|
101
|
+
[HttpCode.Conflict]: 'Conflict',
|
|
102
|
+
[HttpCode.Gone]: 'Gone',
|
|
103
|
+
[HttpCode.LengthRequired]: 'Length Required',
|
|
104
|
+
[HttpCode.PreconditionFailed]: 'Precondition Failed',
|
|
105
|
+
[HttpCode.PayloadTooLarge]: 'Payload Too Large',
|
|
106
|
+
[HttpCode.URITooLong]: 'URI Too Long',
|
|
107
|
+
[HttpCode.UnsupportedMediaType]: 'Unsupported Media Type',
|
|
108
|
+
[HttpCode.RangeNotSatisfiable]: 'Range Not Satisfiable',
|
|
109
|
+
[HttpCode.ExpectationFailed]: 'Expectation Failed',
|
|
110
|
+
[HttpCode.ImATeapot]: "I'm a Teapot",
|
|
111
|
+
[HttpCode.MisdirectedRequest]: 'Misdirected Request',
|
|
112
|
+
[HttpCode.UnprocessableEntity]: 'Unprocessable Entity',
|
|
113
|
+
[HttpCode.Locked]: 'Locked',
|
|
114
|
+
[HttpCode.FailedDependency]: 'Failed Dependency',
|
|
115
|
+
[HttpCode.TooEarly]: 'Too Early',
|
|
116
|
+
[HttpCode.UpgradeRequired]: 'Upgrade Required',
|
|
117
|
+
[HttpCode.PreconditionRequired]: 'Precondition Required',
|
|
118
|
+
[HttpCode.TooManyRequests]: 'Too Many Requests',
|
|
119
|
+
[HttpCode.RequestHeaderFieldsTooLarge]: 'Request Header Fields Too Large',
|
|
120
|
+
[HttpCode.UnavailableForLegalReasons]: 'Unavailable For Legal Reasons',
|
|
121
|
+
[HttpCode.InternalServerError]: 'Internal Server Error',
|
|
122
|
+
[HttpCode.NotImplemented]: 'Not Implemented',
|
|
123
|
+
[HttpCode.BadGateway]: 'Bad Gateway',
|
|
124
|
+
[HttpCode.ServiceUnavailable]: 'Service Unavailable',
|
|
125
|
+
[HttpCode.GatewayTimeout]: 'Gateway Timeout',
|
|
126
|
+
[HttpCode.HTTPVersionNotSupported]: 'HTTP Version Not Supported',
|
|
127
|
+
[HttpCode.VariantAlsoNegotiates]: 'Variant Also Negotiates',
|
|
128
|
+
[HttpCode.InsufficientStorage]: 'Insufficient Storage',
|
|
129
|
+
[HttpCode.LoopDetected]: 'Loop Detected',
|
|
130
|
+
[HttpCode.NotExtended]: 'Not Extended',
|
|
131
|
+
[HttpCode.NetworkAuthenticationRequired]: 'Network Authentication Required',
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const HttpCodeMap = {
|
|
135
|
+
[ErrorCode.ValidationError]: HttpCode.BadRequest,
|
|
136
|
+
[ErrorCode.BadRequest]: HttpCode.BadRequest,
|
|
137
|
+
[ErrorCode.NotFound]: HttpCode.NotFound,
|
|
138
|
+
[ErrorCode.Forbidden]: HttpCode.Forbidden,
|
|
139
|
+
[ErrorCode.Unauthorized]: HttpCode.Unauthorized,
|
|
140
|
+
[ErrorCode.InternalServerError]: HttpCode.InternalServerError,
|
|
141
|
+
[ErrorCode.NotAcceptable]: HttpCode.NotAcceptable,
|
|
142
|
+
[ErrorCode.RequestTimeout]: HttpCode.RequestTimeout,
|
|
143
|
+
[ErrorCode.GatewayTimeout]: HttpCode.GatewayTimeout,
|
|
144
|
+
[ErrorCode.ServiceUnavailable]: HttpCode.ServiceUnavailable,
|
|
145
|
+
[ErrorCode.ClientRequestError]: HttpCode.BadRequest,
|
|
146
|
+
[ErrorCode.ConnectionError]: HttpCode.NotAcceptable,
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export const AllowedHttpMethod =
|
|
150
|
+
createMetadataKey<Array<'get' | 'post'>>('http:method')
|
package/src/injectables.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { createLazyInjectable, type LazyInjectable, Scope } from '@nmtjs/core'
|
|
2
2
|
import { ProtocolInjectables } from '@nmtjs/protocol/server'
|
|
3
3
|
import type { WsUserData } from './types.ts'
|
|
4
4
|
|
|
@@ -7,6 +7,11 @@ const connectionData = ProtocolInjectables.connectionData as LazyInjectable<
|
|
|
7
7
|
Scope.Connection
|
|
8
8
|
>
|
|
9
9
|
|
|
10
|
+
const httpResponseHeaders = createLazyInjectable<Headers, Scope.Call>(
|
|
11
|
+
Scope.Call,
|
|
12
|
+
)
|
|
13
|
+
|
|
10
14
|
export const WsTransportInjectables = {
|
|
11
15
|
connectionData,
|
|
16
|
+
httpResponseHeaders,
|
|
12
17
|
} as const
|