@nmtjs/http-transport 0.15.0-beta.1 → 0.15.0-beta.3
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/constants.d.ts +80 -0
- package/dist/constants.js +147 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/injectables.d.ts +4 -0
- package/dist/injectables.js +5 -0
- package/dist/injectables.js.map +1 -0
- package/dist/runtimes/bun.d.ts +6 -0
- package/dist/runtimes/bun.js +68 -0
- package/dist/runtimes/bun.js.map +1 -0
- package/dist/runtimes/deno.d.ts +6 -0
- package/dist/runtimes/deno.js +95 -0
- package/dist/runtimes/deno.js.map +1 -0
- package/dist/runtimes/node.d.ts +6 -0
- package/dist/runtimes/node.js +137 -0
- package/dist/runtimes/node.js.map +1 -0
- package/dist/server.d.ts +16 -0
- package/dist/server.js +344 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +72 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +16 -0
- package/dist/utils.js.map +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export declare enum HttpStatus {
|
|
2
|
+
Continue = 100,
|
|
3
|
+
SwitchingProtocols = 101,
|
|
4
|
+
Processing = 102,
|
|
5
|
+
EarlyHints = 103,
|
|
6
|
+
OK = 200,
|
|
7
|
+
Created = 201,
|
|
8
|
+
Accepted = 202,
|
|
9
|
+
NonAuthoritativeInformation = 203,
|
|
10
|
+
NoContent = 204,
|
|
11
|
+
ResetContent = 205,
|
|
12
|
+
PartialContent = 206,
|
|
13
|
+
MultiStatus = 207,
|
|
14
|
+
AlreadyReported = 208,
|
|
15
|
+
IMUsed = 226,
|
|
16
|
+
MultipleChoices = 300,
|
|
17
|
+
MovedPermanently = 301,
|
|
18
|
+
Found = 302,
|
|
19
|
+
SeeOther = 303,
|
|
20
|
+
NotModified = 304,
|
|
21
|
+
UseProxy = 305,
|
|
22
|
+
TemporaryRedirect = 307,
|
|
23
|
+
PermanentRedirect = 308,
|
|
24
|
+
BadRequest = 400,
|
|
25
|
+
Unauthorized = 401,
|
|
26
|
+
PaymentRequired = 402,
|
|
27
|
+
Forbidden = 403,
|
|
28
|
+
NotFound = 404,
|
|
29
|
+
MethodNotAllowed = 405,
|
|
30
|
+
NotAcceptable = 406,
|
|
31
|
+
ProxyAuthenticationRequired = 407,
|
|
32
|
+
RequestTimeout = 408,
|
|
33
|
+
Conflict = 409,
|
|
34
|
+
Gone = 410,
|
|
35
|
+
LengthRequired = 411,
|
|
36
|
+
PreconditionFailed = 412,
|
|
37
|
+
PayloadTooLarge = 413,
|
|
38
|
+
URITooLong = 414,
|
|
39
|
+
UnsupportedMediaType = 415,
|
|
40
|
+
RangeNotSatisfiable = 416,
|
|
41
|
+
ExpectationFailed = 417,
|
|
42
|
+
ImATeapot = 418,
|
|
43
|
+
MisdirectedRequest = 421,
|
|
44
|
+
UnprocessableEntity = 422,
|
|
45
|
+
Locked = 423,
|
|
46
|
+
FailedDependency = 424,
|
|
47
|
+
TooEarly = 425,
|
|
48
|
+
UpgradeRequired = 426,
|
|
49
|
+
PreconditionRequired = 428,
|
|
50
|
+
TooManyRequests = 429,
|
|
51
|
+
RequestHeaderFieldsTooLarge = 431,
|
|
52
|
+
UnavailableForLegalReasons = 451,
|
|
53
|
+
InternalServerError = 500,
|
|
54
|
+
NotImplemented = 501,
|
|
55
|
+
BadGateway = 502,
|
|
56
|
+
ServiceUnavailable = 503,
|
|
57
|
+
GatewayTimeout = 504,
|
|
58
|
+
HTTPVersionNotSupported = 505,
|
|
59
|
+
VariantAlsoNegotiates = 506,
|
|
60
|
+
InsufficientStorage = 507,
|
|
61
|
+
LoopDetected = 508,
|
|
62
|
+
NotExtended = 510,
|
|
63
|
+
NetworkAuthenticationRequired = 511
|
|
64
|
+
}
|
|
65
|
+
export declare const HttpStatusText: Record<HttpStatus, string>;
|
|
66
|
+
export declare const HttpCodeMap: {
|
|
67
|
+
ValidationError: HttpStatus;
|
|
68
|
+
BadRequest: HttpStatus;
|
|
69
|
+
NotFound: HttpStatus;
|
|
70
|
+
Forbidden: HttpStatus;
|
|
71
|
+
Unauthorized: HttpStatus;
|
|
72
|
+
InternalServerError: HttpStatus;
|
|
73
|
+
NotAcceptable: HttpStatus;
|
|
74
|
+
RequestTimeout: HttpStatus;
|
|
75
|
+
GatewayTimeout: HttpStatus;
|
|
76
|
+
ServiceUnavailable: HttpStatus;
|
|
77
|
+
ClientRequestError: HttpStatus;
|
|
78
|
+
ConnectionError: HttpStatus;
|
|
79
|
+
};
|
|
80
|
+
export declare const AllowedHttpMethod: import("@nmtjs/core").MetadataKey<("get" | "post" | "put" | "delete" | "patch")[]>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { createMetadataKey } from '@nmtjs/core';
|
|
2
|
+
import { ErrorCode } from '@nmtjs/protocol';
|
|
3
|
+
export var HttpStatus;
|
|
4
|
+
(function (HttpStatus) {
|
|
5
|
+
HttpStatus[HttpStatus["Continue"] = 100] = "Continue";
|
|
6
|
+
HttpStatus[HttpStatus["SwitchingProtocols"] = 101] = "SwitchingProtocols";
|
|
7
|
+
HttpStatus[HttpStatus["Processing"] = 102] = "Processing";
|
|
8
|
+
HttpStatus[HttpStatus["EarlyHints"] = 103] = "EarlyHints";
|
|
9
|
+
HttpStatus[HttpStatus["OK"] = 200] = "OK";
|
|
10
|
+
HttpStatus[HttpStatus["Created"] = 201] = "Created";
|
|
11
|
+
HttpStatus[HttpStatus["Accepted"] = 202] = "Accepted";
|
|
12
|
+
HttpStatus[HttpStatus["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
|
|
13
|
+
HttpStatus[HttpStatus["NoContent"] = 204] = "NoContent";
|
|
14
|
+
HttpStatus[HttpStatus["ResetContent"] = 205] = "ResetContent";
|
|
15
|
+
HttpStatus[HttpStatus["PartialContent"] = 206] = "PartialContent";
|
|
16
|
+
HttpStatus[HttpStatus["MultiStatus"] = 207] = "MultiStatus";
|
|
17
|
+
HttpStatus[HttpStatus["AlreadyReported"] = 208] = "AlreadyReported";
|
|
18
|
+
HttpStatus[HttpStatus["IMUsed"] = 226] = "IMUsed";
|
|
19
|
+
HttpStatus[HttpStatus["MultipleChoices"] = 300] = "MultipleChoices";
|
|
20
|
+
HttpStatus[HttpStatus["MovedPermanently"] = 301] = "MovedPermanently";
|
|
21
|
+
HttpStatus[HttpStatus["Found"] = 302] = "Found";
|
|
22
|
+
HttpStatus[HttpStatus["SeeOther"] = 303] = "SeeOther";
|
|
23
|
+
HttpStatus[HttpStatus["NotModified"] = 304] = "NotModified";
|
|
24
|
+
HttpStatus[HttpStatus["UseProxy"] = 305] = "UseProxy";
|
|
25
|
+
HttpStatus[HttpStatus["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
26
|
+
HttpStatus[HttpStatus["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
27
|
+
HttpStatus[HttpStatus["BadRequest"] = 400] = "BadRequest";
|
|
28
|
+
HttpStatus[HttpStatus["Unauthorized"] = 401] = "Unauthorized";
|
|
29
|
+
HttpStatus[HttpStatus["PaymentRequired"] = 402] = "PaymentRequired";
|
|
30
|
+
HttpStatus[HttpStatus["Forbidden"] = 403] = "Forbidden";
|
|
31
|
+
HttpStatus[HttpStatus["NotFound"] = 404] = "NotFound";
|
|
32
|
+
HttpStatus[HttpStatus["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
33
|
+
HttpStatus[HttpStatus["NotAcceptable"] = 406] = "NotAcceptable";
|
|
34
|
+
HttpStatus[HttpStatus["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
35
|
+
HttpStatus[HttpStatus["RequestTimeout"] = 408] = "RequestTimeout";
|
|
36
|
+
HttpStatus[HttpStatus["Conflict"] = 409] = "Conflict";
|
|
37
|
+
HttpStatus[HttpStatus["Gone"] = 410] = "Gone";
|
|
38
|
+
HttpStatus[HttpStatus["LengthRequired"] = 411] = "LengthRequired";
|
|
39
|
+
HttpStatus[HttpStatus["PreconditionFailed"] = 412] = "PreconditionFailed";
|
|
40
|
+
HttpStatus[HttpStatus["PayloadTooLarge"] = 413] = "PayloadTooLarge";
|
|
41
|
+
HttpStatus[HttpStatus["URITooLong"] = 414] = "URITooLong";
|
|
42
|
+
HttpStatus[HttpStatus["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
|
|
43
|
+
HttpStatus[HttpStatus["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
|
|
44
|
+
HttpStatus[HttpStatus["ExpectationFailed"] = 417] = "ExpectationFailed";
|
|
45
|
+
HttpStatus[HttpStatus["ImATeapot"] = 418] = "ImATeapot";
|
|
46
|
+
HttpStatus[HttpStatus["MisdirectedRequest"] = 421] = "MisdirectedRequest";
|
|
47
|
+
HttpStatus[HttpStatus["UnprocessableEntity"] = 422] = "UnprocessableEntity";
|
|
48
|
+
HttpStatus[HttpStatus["Locked"] = 423] = "Locked";
|
|
49
|
+
HttpStatus[HttpStatus["FailedDependency"] = 424] = "FailedDependency";
|
|
50
|
+
HttpStatus[HttpStatus["TooEarly"] = 425] = "TooEarly";
|
|
51
|
+
HttpStatus[HttpStatus["UpgradeRequired"] = 426] = "UpgradeRequired";
|
|
52
|
+
HttpStatus[HttpStatus["PreconditionRequired"] = 428] = "PreconditionRequired";
|
|
53
|
+
HttpStatus[HttpStatus["TooManyRequests"] = 429] = "TooManyRequests";
|
|
54
|
+
HttpStatus[HttpStatus["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
|
|
55
|
+
HttpStatus[HttpStatus["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
|
|
56
|
+
HttpStatus[HttpStatus["InternalServerError"] = 500] = "InternalServerError";
|
|
57
|
+
HttpStatus[HttpStatus["NotImplemented"] = 501] = "NotImplemented";
|
|
58
|
+
HttpStatus[HttpStatus["BadGateway"] = 502] = "BadGateway";
|
|
59
|
+
HttpStatus[HttpStatus["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
60
|
+
HttpStatus[HttpStatus["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
61
|
+
HttpStatus[HttpStatus["HTTPVersionNotSupported"] = 505] = "HTTPVersionNotSupported";
|
|
62
|
+
HttpStatus[HttpStatus["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
|
|
63
|
+
HttpStatus[HttpStatus["InsufficientStorage"] = 507] = "InsufficientStorage";
|
|
64
|
+
HttpStatus[HttpStatus["LoopDetected"] = 508] = "LoopDetected";
|
|
65
|
+
HttpStatus[HttpStatus["NotExtended"] = 510] = "NotExtended";
|
|
66
|
+
HttpStatus[HttpStatus["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
|
|
67
|
+
})(HttpStatus || (HttpStatus = {}));
|
|
68
|
+
export const HttpStatusText = {
|
|
69
|
+
[HttpStatus.Continue]: 'Continue',
|
|
70
|
+
[HttpStatus.SwitchingProtocols]: 'Switching Protocols',
|
|
71
|
+
[HttpStatus.Processing]: 'Processing',
|
|
72
|
+
[HttpStatus.EarlyHints]: 'Early Hints',
|
|
73
|
+
[HttpStatus.OK]: 'OK',
|
|
74
|
+
[HttpStatus.Created]: 'Created',
|
|
75
|
+
[HttpStatus.Accepted]: 'Accepted',
|
|
76
|
+
[HttpStatus.NonAuthoritativeInformation]: 'Non-Authoritative Information',
|
|
77
|
+
[HttpStatus.NoContent]: 'No Content',
|
|
78
|
+
[HttpStatus.ResetContent]: 'Reset Content',
|
|
79
|
+
[HttpStatus.PartialContent]: 'Partial Content',
|
|
80
|
+
[HttpStatus.MultiStatus]: 'Multi-Status',
|
|
81
|
+
[HttpStatus.AlreadyReported]: 'Already Reported',
|
|
82
|
+
[HttpStatus.IMUsed]: 'IM Used',
|
|
83
|
+
[HttpStatus.MultipleChoices]: 'Multiple Choices',
|
|
84
|
+
[HttpStatus.MovedPermanently]: 'Moved Permanently',
|
|
85
|
+
[HttpStatus.Found]: 'Found',
|
|
86
|
+
[HttpStatus.SeeOther]: 'See Other',
|
|
87
|
+
[HttpStatus.NotModified]: 'Not Modified',
|
|
88
|
+
[HttpStatus.UseProxy]: 'Use Proxy',
|
|
89
|
+
[HttpStatus.TemporaryRedirect]: 'Temporary Redirect',
|
|
90
|
+
[HttpStatus.PermanentRedirect]: 'Permanent Redirect',
|
|
91
|
+
[HttpStatus.BadRequest]: 'Bad Request',
|
|
92
|
+
[HttpStatus.Unauthorized]: 'Unauthorized',
|
|
93
|
+
[HttpStatus.PaymentRequired]: 'Payment Required',
|
|
94
|
+
[HttpStatus.Forbidden]: 'Forbidden',
|
|
95
|
+
[HttpStatus.NotFound]: 'Not Found',
|
|
96
|
+
[HttpStatus.MethodNotAllowed]: 'Method Not Allowed',
|
|
97
|
+
[HttpStatus.NotAcceptable]: 'Not Acceptable',
|
|
98
|
+
[HttpStatus.ProxyAuthenticationRequired]: 'Proxy Authentication Required',
|
|
99
|
+
[HttpStatus.RequestTimeout]: 'Request Timeout',
|
|
100
|
+
[HttpStatus.Conflict]: 'Conflict',
|
|
101
|
+
[HttpStatus.Gone]: 'Gone',
|
|
102
|
+
[HttpStatus.LengthRequired]: 'Length Required',
|
|
103
|
+
[HttpStatus.PreconditionFailed]: 'Precondition Failed',
|
|
104
|
+
[HttpStatus.PayloadTooLarge]: 'Payload Too Large',
|
|
105
|
+
[HttpStatus.URITooLong]: 'URI Too Long',
|
|
106
|
+
[HttpStatus.UnsupportedMediaType]: 'Unsupported Media Type',
|
|
107
|
+
[HttpStatus.RangeNotSatisfiable]: 'Range Not Satisfiable',
|
|
108
|
+
[HttpStatus.ExpectationFailed]: 'Expectation Failed',
|
|
109
|
+
[HttpStatus.ImATeapot]: "I'm a Teapot",
|
|
110
|
+
[HttpStatus.MisdirectedRequest]: 'Misdirected Request',
|
|
111
|
+
[HttpStatus.UnprocessableEntity]: 'Unprocessable Entity',
|
|
112
|
+
[HttpStatus.Locked]: 'Locked',
|
|
113
|
+
[HttpStatus.FailedDependency]: 'Failed Dependency',
|
|
114
|
+
[HttpStatus.TooEarly]: 'Too Early',
|
|
115
|
+
[HttpStatus.UpgradeRequired]: 'Upgrade Required',
|
|
116
|
+
[HttpStatus.PreconditionRequired]: 'Precondition Required',
|
|
117
|
+
[HttpStatus.TooManyRequests]: 'Too Many Requests',
|
|
118
|
+
[HttpStatus.RequestHeaderFieldsTooLarge]: 'Request Header Fields Too Large',
|
|
119
|
+
[HttpStatus.UnavailableForLegalReasons]: 'Unavailable For Legal Reasons',
|
|
120
|
+
[HttpStatus.InternalServerError]: 'Internal Server Error',
|
|
121
|
+
[HttpStatus.NotImplemented]: 'Not Implemented',
|
|
122
|
+
[HttpStatus.BadGateway]: 'Bad Gateway',
|
|
123
|
+
[HttpStatus.ServiceUnavailable]: 'Service Unavailable',
|
|
124
|
+
[HttpStatus.GatewayTimeout]: 'Gateway Timeout',
|
|
125
|
+
[HttpStatus.HTTPVersionNotSupported]: 'HTTP Version Not Supported',
|
|
126
|
+
[HttpStatus.VariantAlsoNegotiates]: 'Variant Also Negotiates',
|
|
127
|
+
[HttpStatus.InsufficientStorage]: 'Insufficient Storage',
|
|
128
|
+
[HttpStatus.LoopDetected]: 'Loop Detected',
|
|
129
|
+
[HttpStatus.NotExtended]: 'Not Extended',
|
|
130
|
+
[HttpStatus.NetworkAuthenticationRequired]: 'Network Authentication Required',
|
|
131
|
+
};
|
|
132
|
+
export const HttpCodeMap = {
|
|
133
|
+
[ErrorCode.ValidationError]: HttpStatus.BadRequest,
|
|
134
|
+
[ErrorCode.BadRequest]: HttpStatus.BadRequest,
|
|
135
|
+
[ErrorCode.NotFound]: HttpStatus.NotFound,
|
|
136
|
+
[ErrorCode.Forbidden]: HttpStatus.Forbidden,
|
|
137
|
+
[ErrorCode.Unauthorized]: HttpStatus.Unauthorized,
|
|
138
|
+
[ErrorCode.InternalServerError]: HttpStatus.InternalServerError,
|
|
139
|
+
[ErrorCode.NotAcceptable]: HttpStatus.NotAcceptable,
|
|
140
|
+
[ErrorCode.RequestTimeout]: HttpStatus.RequestTimeout,
|
|
141
|
+
[ErrorCode.GatewayTimeout]: HttpStatus.GatewayTimeout,
|
|
142
|
+
[ErrorCode.ServiceUnavailable]: HttpStatus.ServiceUnavailable,
|
|
143
|
+
[ErrorCode.ClientRequestError]: HttpStatus.BadRequest,
|
|
144
|
+
[ErrorCode.ConnectionError]: HttpStatus.NotAcceptable,
|
|
145
|
+
};
|
|
146
|
+
export const AllowedHttpMethod = createMetadataKey('http:method');
|
|
147
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,MAAM,CAAN,IAAY,UA+DX;AA/DD,WAAY,UAAU;IACpB,qDAAc,CAAA;IACd,yEAAwB,CAAA;IACxB,yDAAgB,CAAA;IAChB,yDAAgB,CAAA;IAChB,yCAAQ,CAAA;IACR,mDAAa,CAAA;IACb,qDAAc,CAAA;IACd,2FAAiC,CAAA;IACjC,uDAAe,CAAA;IACf,6DAAkB,CAAA;IAClB,iEAAoB,CAAA;IACpB,2DAAiB,CAAA;IACjB,mEAAqB,CAAA;IACrB,iDAAY,CAAA;IACZ,mEAAqB,CAAA;IACrB,qEAAsB,CAAA;IACtB,+CAAW,CAAA;IACX,qDAAc,CAAA;IACd,2DAAiB,CAAA;IACjB,qDAAc,CAAA;IACd,uEAAuB,CAAA;IACvB,uEAAuB,CAAA;IACvB,yDAAgB,CAAA;IAChB,6DAAkB,CAAA;IAClB,mEAAqB,CAAA;IACrB,uDAAe,CAAA;IACf,qDAAc,CAAA;IACd,qEAAsB,CAAA;IACtB,+DAAmB,CAAA;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AA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Scope } from '@nmtjs/core';
|
|
2
|
+
import type { HttpTransportServerRequest } from './types.ts';
|
|
3
|
+
export declare const connectionData: import("@nmtjs/core").LazyInjectable<HttpTransportServerRequest, Scope.Connection>;
|
|
4
|
+
export declare const httpResponseHeaders: import("@nmtjs/core").LazyInjectable<Headers, Scope.Call>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createLazyInjectable, Scope } from '@nmtjs/core';
|
|
2
|
+
import { connectionData as connectionDataInjectable } from '@nmtjs/gateway';
|
|
3
|
+
export const connectionData = connectionDataInjectable.$withType();
|
|
4
|
+
export const httpResponseHeaders = createLazyInjectable(Scope.Call);
|
|
5
|
+
//# sourceMappingURL=injectables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectables.js","sourceRoot":"","sources":["../src/injectables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EAAE,cAAc,IAAI,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AAI3E,MAAM,CAAC,MAAM,cAAc,GACzB,wBAAwB,CAAC,SAAS,EAA8B,CAAA;AAElE,MAAM,CAAC,MAAM,mBAAmB,GAAG,oBAAoB,CACrD,KAAK,CAAC,IAAI,CACX,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transport } from '@nmtjs/gateway';
|
|
2
|
+
import type { ConnectionType } from '@nmtjs/protocol';
|
|
3
|
+
import { ProxyableTransportType } from '@nmtjs/gateway';
|
|
4
|
+
import type { HttpTransportOptions } from '../types.ts';
|
|
5
|
+
import * as injectables from '../injectables.ts';
|
|
6
|
+
export declare const HttpTransport: Transport<ConnectionType.Unidirectional, HttpTransportOptions<'deno'>, typeof injectables, ProxyableTransportType.HTTP>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ProxyableTransportType } from '@nmtjs/gateway';
|
|
2
|
+
import * as injectables from "../injectables.js";
|
|
3
|
+
import { createHTTPTransportWorker } from "../server.js";
|
|
4
|
+
import { InternalServerErrorHttpResponse, NotFoundHttpResponse, StatusResponse, } from "../utils.js";
|
|
5
|
+
function adapterFactory(params) {
|
|
6
|
+
let server = null;
|
|
7
|
+
function createServer() {
|
|
8
|
+
return globalThis.Bun.serve({
|
|
9
|
+
...params.runtime,
|
|
10
|
+
unix: params.listen.unix,
|
|
11
|
+
port: params.listen.port ?? 0,
|
|
12
|
+
hostname: params.listen.hostname,
|
|
13
|
+
reusePort: params.listen.reusePort,
|
|
14
|
+
tls: params.tls
|
|
15
|
+
? {
|
|
16
|
+
cert: params.tls.cert,
|
|
17
|
+
key: params.tls.key,
|
|
18
|
+
passphrase: params.tls.passphrase,
|
|
19
|
+
}
|
|
20
|
+
: undefined,
|
|
21
|
+
// @ts-expect-error
|
|
22
|
+
routes: {
|
|
23
|
+
...params.runtime?.routes,
|
|
24
|
+
'/healthy': { GET: StatusResponse },
|
|
25
|
+
},
|
|
26
|
+
async fetch(request, server) {
|
|
27
|
+
const url = new URL(request.url);
|
|
28
|
+
try {
|
|
29
|
+
if (request.headers.get('upgrade') === 'websocket')
|
|
30
|
+
return NotFoundHttpResponse();
|
|
31
|
+
const { body, headers, method } = request;
|
|
32
|
+
return await params.fetchHandler({ url, method, headers }, body, request.signal);
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
// TODO: proper logging
|
|
36
|
+
console.error(err);
|
|
37
|
+
// params.logger.error({ err }, 'Error in fetch handler')
|
|
38
|
+
return InternalServerErrorHttpResponse();
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
runtime: {
|
|
45
|
+
get bun() {
|
|
46
|
+
return server;
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
start: async () => {
|
|
50
|
+
server = createServer();
|
|
51
|
+
return server.url.href;
|
|
52
|
+
},
|
|
53
|
+
stop: async () => {
|
|
54
|
+
if (server) {
|
|
55
|
+
await server.stop();
|
|
56
|
+
server = null;
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export const HttpTransport = {
|
|
62
|
+
proxyable: ProxyableTransportType.HTTP,
|
|
63
|
+
injectables,
|
|
64
|
+
factory(options) {
|
|
65
|
+
return createHTTPTransportWorker(adapterFactory, options);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
//# sourceMappingURL=bun.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bun.js","sourceRoot":"","sources":["../../src/runtimes/bun.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAOvD,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EACpB,cAAc,GACf,MAAM,aAAa,CAAA;AAEpB,SAAS,cAAc,CAAC,MAAgC;IACtD,IAAI,MAAM,GAAiC,IAAI,CAAA;IAE/C,SAAS,YAAY;QACnB,OAAO,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC;YAC1B,GAAG,MAAM,CAAC,OAAO;YACjB,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAc;YAClC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC;YAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;YAChC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS;YAClC,GAAG,EAAE,MAAM,CAAC,GAAG;gBACb,CAAC,CAAC;oBACE,IAAI,EAAE,MAAM,CAAC,GAAG,C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CAAC,IAAI,EAAE,CAAA;gBACnB,MAAM,GAAG,IAAI,CAAA;YACf,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAKtB;IACF,SAAS,EAAE,sBAAsB,CAAC,IAAI;IACtC,WAAW;IACX,OAAO,CAAC,OAAO;QACb,OAAO,yBAAyB,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;IAC3D,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transport } from '@nmtjs/gateway';
|
|
2
|
+
import type { ConnectionType } from '@nmtjs/protocol';
|
|
3
|
+
import { ProxyableTransportType } from '@nmtjs/gateway';
|
|
4
|
+
import type { HttpTransportOptions } from '../types.ts';
|
|
5
|
+
import * as injectables from '../injectables.ts';
|
|
6
|
+
export declare const HttpTransport: Transport<ConnectionType.Unidirectional, HttpTransportOptions<'deno'>, typeof injectables, ProxyableTransportType.HTTP>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ProxyableTransportType } from '@nmtjs/gateway';
|
|
2
|
+
import * as injectables from "../injectables.js";
|
|
3
|
+
import { createHTTPTransportWorker } from "../server.js";
|
|
4
|
+
import { InternalServerErrorHttpResponse, NotFoundHttpResponse, StatusResponse, } from "../utils.js";
|
|
5
|
+
function adapterFactory(params) {
|
|
6
|
+
let server = null;
|
|
7
|
+
function createServer() {
|
|
8
|
+
const listenOptions = params.listen.unix
|
|
9
|
+
? { path: params.listen.unix }
|
|
10
|
+
: {
|
|
11
|
+
port: params.listen.port,
|
|
12
|
+
hostname: params.listen.hostname,
|
|
13
|
+
reusePort: params.listen.reusePort,
|
|
14
|
+
};
|
|
15
|
+
const options = {
|
|
16
|
+
...listenOptions,
|
|
17
|
+
tls: params.tls
|
|
18
|
+
? {
|
|
19
|
+
cert: params.tls.cert,
|
|
20
|
+
key: params.tls.key,
|
|
21
|
+
passphrase: params.tls.passphrase,
|
|
22
|
+
}
|
|
23
|
+
: undefined,
|
|
24
|
+
};
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
const server = globalThis.Deno.serve({
|
|
27
|
+
...params.runtime,
|
|
28
|
+
...options,
|
|
29
|
+
handler: async (request, info) => {
|
|
30
|
+
const url = new URL(request.url);
|
|
31
|
+
if (url.pathname === '/healthy') {
|
|
32
|
+
return StatusResponse();
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
if (request.headers.get('upgrade') === 'websocket') {
|
|
36
|
+
return NotFoundHttpResponse();
|
|
37
|
+
}
|
|
38
|
+
const { headers, method, body } = request;
|
|
39
|
+
return await params.fetchHandler({ url, method, headers }, body, request.signal);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
// TODO: proper logging
|
|
43
|
+
console.error(err);
|
|
44
|
+
// params.logger.error({ err }, 'Error in fetch handler')
|
|
45
|
+
return InternalServerErrorHttpResponse();
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
onListen(addr) {
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
resolve({ server, addr });
|
|
51
|
+
}, 1);
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
runtime: {
|
|
58
|
+
get deno() {
|
|
59
|
+
return server;
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
start: async () => {
|
|
63
|
+
const { server: _server, addr } = await createServer();
|
|
64
|
+
server = _server;
|
|
65
|
+
switch (addr.transport) {
|
|
66
|
+
case 'unix':
|
|
67
|
+
case 'unixpacket':
|
|
68
|
+
return `unix://${addr.path}`;
|
|
69
|
+
case 'tcp':
|
|
70
|
+
case 'udp': {
|
|
71
|
+
const proto = params.tls ? 'https' : 'http';
|
|
72
|
+
return `${proto}://${addr.hostname}:${addr.port}`;
|
|
73
|
+
}
|
|
74
|
+
case 'vsock':
|
|
75
|
+
return `vsock://${addr.cid}:${addr.port}`;
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unsupported address transport`);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
stop: async () => {
|
|
81
|
+
if (server) {
|
|
82
|
+
await server.shutdown();
|
|
83
|
+
server = null;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export const HttpTransport = {
|
|
89
|
+
proxyable: ProxyableTransportType.HTTP,
|
|
90
|
+
injectables,
|
|
91
|
+
factory(options) {
|
|
92
|
+
return createHTTPTransportWorker(adapterFactory, options);
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=deno.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deno.js","sourceRoot":"","sources":["../../src/runtimes/deno.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAQvD,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EACpB,cAAc,GACf,MAAM,aAAa,CAAA;AAqBpB,SAAS,cAAc,CAAC,MAAiC;IACvD,IAAI,MAAM,GAAsB,IAAI,CAAA;IAEpC,SAAS,YAAY;QACnB,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI;YACtC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;YAC9B,CAAC,CAAC;gBACE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI;gBACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ;gBAChC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS;aACnC,CAAA;QACL,MAAM,OAAO,GAAG;YACd,GAAG,aAAa;YAChB,GAAG,EAAE,MAAM,CAAC,GAAG;gBACb,CAAC,CAAC;oBACE,IAAI,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AE,OAAO,CAAC,CAAA;IAC3D,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Transport } from '@nmtjs/gateway';
|
|
2
|
+
import type { ConnectionType } from '@nmtjs/protocol';
|
|
3
|
+
import { ProxyableTransportType } from '@nmtjs/gateway';
|
|
4
|
+
import type { HttpTransportOptions } from '../types.ts';
|
|
5
|
+
import * as injectables from '../injectables.ts';
|
|
6
|
+
export declare const HttpTransport: Transport<ConnectionType.Unidirectional, HttpTransportOptions<'node'>, typeof injectables, ProxyableTransportType.HTTP>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {} from 'node:dns';
|
|
2
|
+
import { setTimeout } from 'node:timers/promises';
|
|
3
|
+
import { ProxyableTransportType } from '@nmtjs/gateway';
|
|
4
|
+
import * as injectables from "../injectables.js";
|
|
5
|
+
import { createHTTPTransportWorker } from "../server.js";
|
|
6
|
+
import { InternalServerErrorHttpResponse, NotFoundHttpResponse, StatusResponse, } from "../utils.js";
|
|
7
|
+
import { App, SSLApp, us_socket_local_port } from 'uWebSockets.js';
|
|
8
|
+
function adapterFactory(params) {
|
|
9
|
+
const server = params.tls
|
|
10
|
+
? SSLApp({
|
|
11
|
+
passphrase: params.tls.passphrase,
|
|
12
|
+
key_file_name: params.tls.key,
|
|
13
|
+
cert_file_name: params.tls.cert,
|
|
14
|
+
})
|
|
15
|
+
: App();
|
|
16
|
+
server
|
|
17
|
+
.get('/healthy', async (res) => {
|
|
18
|
+
res.onAborted(() => { });
|
|
19
|
+
const response = StatusResponse();
|
|
20
|
+
res.cork(async () => {
|
|
21
|
+
res
|
|
22
|
+
.writeStatus(`${response.status} ${response.statusText}`)
|
|
23
|
+
.end(await response.arrayBuffer());
|
|
24
|
+
});
|
|
25
|
+
})
|
|
26
|
+
.any('/*', async (res, req) => {
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
res.onAborted(() => {
|
|
29
|
+
res.aborted = true;
|
|
30
|
+
controller.abort();
|
|
31
|
+
});
|
|
32
|
+
let response = NotFoundHttpResponse();
|
|
33
|
+
const headers = new Headers();
|
|
34
|
+
const method = req.getMethod();
|
|
35
|
+
req.forEach((k, v) => headers.append(k, v));
|
|
36
|
+
const host = headers.get('host') || 'localhost';
|
|
37
|
+
const proto = headers.get('x-forwarded-proto') || params.tls ? 'https' : 'http';
|
|
38
|
+
const url = new URL(req.getUrl(), `${proto}://${host}`);
|
|
39
|
+
try {
|
|
40
|
+
const body = new ReadableStream({
|
|
41
|
+
start(controller) {
|
|
42
|
+
res.onData((chunk, isLast) => {
|
|
43
|
+
if (chunk) {
|
|
44
|
+
const copy = Buffer.allocUnsafe(chunk.byteLength);
|
|
45
|
+
copy.set(new Uint8Array(chunk));
|
|
46
|
+
controller.enqueue(copy);
|
|
47
|
+
}
|
|
48
|
+
if (isLast)
|
|
49
|
+
controller.close();
|
|
50
|
+
});
|
|
51
|
+
res.onAborted(() => controller.error());
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
response = await params.fetchHandler({ url, method, headers }, body, controller.signal);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
// TODO: proper logging
|
|
58
|
+
console.error(err);
|
|
59
|
+
// params.logger.error({ err }, 'Error in fetch handler')
|
|
60
|
+
response = InternalServerErrorHttpResponse();
|
|
61
|
+
}
|
|
62
|
+
if (res.aborted)
|
|
63
|
+
return undefined;
|
|
64
|
+
else {
|
|
65
|
+
res.cork(() => {
|
|
66
|
+
if (res.aborted)
|
|
67
|
+
return undefined;
|
|
68
|
+
res.writeStatus(`${response.status.toString()} ${response.statusText}`);
|
|
69
|
+
response.headers.forEach((v, k) => res.writeHeader(k, v));
|
|
70
|
+
});
|
|
71
|
+
if (response.body) {
|
|
72
|
+
try {
|
|
73
|
+
const reader = response.body.getReader();
|
|
74
|
+
let chunk = await reader.read();
|
|
75
|
+
do {
|
|
76
|
+
if (res.aborted)
|
|
77
|
+
break;
|
|
78
|
+
if (chunk.value)
|
|
79
|
+
res.cork(() => res.write(chunk.value));
|
|
80
|
+
chunk = await reader.read();
|
|
81
|
+
} while (!chunk.done);
|
|
82
|
+
if (!res.aborted)
|
|
83
|
+
res.cork(() => res.end());
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
if (!res.aborted)
|
|
87
|
+
res.cork(() => res.close());
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
if (!res.aborted)
|
|
92
|
+
res.cork(() => res.end());
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
runtime: { node: server },
|
|
98
|
+
start: () => new Promise((resolve, reject) => {
|
|
99
|
+
if (params.listen.unix) {
|
|
100
|
+
server.listen_unix((socket) => {
|
|
101
|
+
if (socket) {
|
|
102
|
+
resolve('unix://' + params.listen.unix);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
reject(new Error('Failed to start WebSockets server'));
|
|
106
|
+
}
|
|
107
|
+
}, params.listen.unix);
|
|
108
|
+
}
|
|
109
|
+
else if (typeof params.listen.port === 'number') {
|
|
110
|
+
const proto = params.tls ? 'https' : 'http';
|
|
111
|
+
const hostname = params.listen.hostname || '127.0.0.1';
|
|
112
|
+
server.listen(hostname, params.listen.port, (socket) => {
|
|
113
|
+
if (socket) {
|
|
114
|
+
resolve(`${proto}://${hostname}:${us_socket_local_port(socket)}`);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
reject(new Error('Failed to start WebSockets server'));
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
reject(new Error('Invalid listen parameters'));
|
|
123
|
+
}
|
|
124
|
+
}),
|
|
125
|
+
stop: () => {
|
|
126
|
+
server.close();
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export const HttpTransport = {
|
|
131
|
+
proxyable: ProxyableTransportType.HTTP,
|
|
132
|
+
injectables,
|
|
133
|
+
factory(options) {
|
|
134
|
+
return createHTTPTransportWorker(adapterFactory, options);
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/runtimes/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAIjD,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAOvD,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EACpB,cAAc,GACf,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAElE,SAAS,cAAc,CAAC,MAAiC;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG;QACvB,CAAC,CAAC,MAAM,CAAC;YACL,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU;YACjC,aAAa,EAAE,MAAM,CAAC,GAAG,CAAC,GAAG;YAC7B,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,IAAI;SAChC,CAAC;QACJ,CAAC,CAAC,GAAG,EAAE,CAAA;IAET,MAAM;SACH,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QAC7B,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;QACvB,MAAM,QAAQ,GAAG,cAAc,EAAE,CAAA;QACjC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;YAClB,GAAG;iBACA,WAAW,CAAC,GAAG,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;i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
|
1
|
+
import type { TransportWorker, TransportWorkerParams } from '@nmtjs/gateway';
|
|
2
|
+
import { ConnectionType } from '@nmtjs/protocol';
|
|
3
|
+
import type { HttpAdapterServerFactory, HttpTransportOptions, HttpTransportServerRequest } from './types.ts';
|
|
4
|
+
export declare function createHTTPTransportWorker(adapterFactory: HttpAdapterServerFactory<any>, options: HttpTransportOptions): TransportWorker<ConnectionType.Unidirectional>;
|
|
5
|
+
export declare class HttpTransportServer implements TransportWorker<ConnectionType.Unidirectional> {
|
|
6
|
+
#private;
|
|
7
|
+
protected readonly adapterFactory: HttpAdapterServerFactory<any>;
|
|
8
|
+
protected readonly options: HttpTransportOptions;
|
|
9
|
+
params: TransportWorkerParams<ConnectionType.Unidirectional>;
|
|
10
|
+
constructor(adapterFactory: HttpAdapterServerFactory<any>, options: HttpTransportOptions);
|
|
11
|
+
start(hooks: TransportWorkerParams<ConnectionType.Unidirectional>): Promise<string>;
|
|
12
|
+
stop(): Promise<void>;
|
|
13
|
+
httpHandler(request: HttpTransportServerRequest, body: ReadableStream | null, requestSignal: AbortSignal): Promise<Response>;
|
|
14
|
+
private applyCors;
|
|
15
|
+
private createServer;
|
|
16
|
+
}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
import { Buffer } from 'node:buffer';
|
|
54
|
+
import { Duplex, Readable } from 'node:stream';
|
|
55
|
+
import { anyAbortSignal, isAbortError, isAsyncIterable } from '@nmtjs/common';
|
|
56
|
+
import { provide } from '@nmtjs/core';
|
|
57
|
+
import { ConnectionType, ErrorCode, ProtocolBlob, ProtocolVersion, } from '@nmtjs/protocol';
|
|
58
|
+
import { ProtocolClientStream, ProtocolError, UnsupportedContentTypeError, UnsupportedFormatError, } from '@nmtjs/protocol/server';
|
|
59
|
+
import { AllowedHttpMethod, HttpCodeMap, HttpStatus, HttpStatusText, } from "./constants.js";
|
|
60
|
+
import * as injections from "./injectables.js";
|
|
61
|
+
const NEEMATA_BLOB_HEADER = 'X-Neemata-Blob';
|
|
62
|
+
const DEFAULT_ALLOWED_METHODS = Object.freeze(['post']);
|
|
63
|
+
const DEFAULT_CORS_PARAMS = Object.freeze({
|
|
64
|
+
allowCredentials: 'true',
|
|
65
|
+
allowMethods: ['GET', 'POST'],
|
|
66
|
+
allowHeaders: [
|
|
67
|
+
'Content-Type',
|
|
68
|
+
'Content-Disposition',
|
|
69
|
+
'Content-Length',
|
|
70
|
+
'Accept',
|
|
71
|
+
'Transfer-Encoding',
|
|
72
|
+
],
|
|
73
|
+
maxAge: undefined,
|
|
74
|
+
requestMethod: undefined,
|
|
75
|
+
exposeHeaders: [],
|
|
76
|
+
requestHeaders: [],
|
|
77
|
+
});
|
|
78
|
+
const CORS_HEADERS_MAP = {
|
|
79
|
+
origin: 'Access-Control-Allow-Origin',
|
|
80
|
+
allowMethods: 'Access-Control-Allow-Methods',
|
|
81
|
+
allowHeaders: 'Access-Control-Allow-Headers',
|
|
82
|
+
allowCredentials: 'Access-Control-Allow-Credentials',
|
|
83
|
+
maxAge: 'Access-Control-Max-Age',
|
|
84
|
+
exposeHeaders: 'Access-Control-Expose-Headers',
|
|
85
|
+
requestHeaders: 'Access-Control-Request-Headers',
|
|
86
|
+
requestMethod: 'Access-Control-Request-Method',
|
|
87
|
+
};
|
|
88
|
+
export function createHTTPTransportWorker(adapterFactory, options) {
|
|
89
|
+
return new HttpTransportServer(adapterFactory, options);
|
|
90
|
+
}
|
|
91
|
+
export class HttpTransportServer {
|
|
92
|
+
adapterFactory;
|
|
93
|
+
options;
|
|
94
|
+
#server;
|
|
95
|
+
#corsOptions;
|
|
96
|
+
params;
|
|
97
|
+
constructor(adapterFactory, options) {
|
|
98
|
+
this.adapterFactory = adapterFactory;
|
|
99
|
+
this.options = options;
|
|
100
|
+
this.#server = this.createServer();
|
|
101
|
+
this.#corsOptions = this.options.cors;
|
|
102
|
+
}
|
|
103
|
+
async start(hooks) {
|
|
104
|
+
this.params = hooks;
|
|
105
|
+
return await this.#server.start();
|
|
106
|
+
}
|
|
107
|
+
async stop() {
|
|
108
|
+
await this.#server.stop();
|
|
109
|
+
}
|
|
110
|
+
async httpHandler(request, body, requestSignal) {
|
|
111
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
112
|
+
try {
|
|
113
|
+
const url = new URL(request.url);
|
|
114
|
+
const procedure = url.pathname.slice(1); // remove leading '/'
|
|
115
|
+
const method = request.method.toLowerCase();
|
|
116
|
+
const origin = request.headers.get('origin');
|
|
117
|
+
const responseHeaders = new Headers();
|
|
118
|
+
if (origin)
|
|
119
|
+
this.applyCors(origin, request, responseHeaders);
|
|
120
|
+
// Handle preflight requests
|
|
121
|
+
if (method === 'options') {
|
|
122
|
+
return new Response(null, {
|
|
123
|
+
status: HttpStatus.OK,
|
|
124
|
+
headers: responseHeaders,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
const signal = anyAbortSignal(requestSignal, controller.signal);
|
|
129
|
+
const canHaveBody = method !== 'get';
|
|
130
|
+
const isBlob = request.headers.get(NEEMATA_BLOB_HEADER) === 'true';
|
|
131
|
+
const contentType = request.headers.get('content-type');
|
|
132
|
+
const accept = request.headers.get('accept') || '*/*';
|
|
133
|
+
const connection = __addDisposableResource(env_1, await this.params.onConnect({
|
|
134
|
+
accept,
|
|
135
|
+
contentType: isBlob ? '*/*' : contentType,
|
|
136
|
+
data: request,
|
|
137
|
+
protocolVersion: ProtocolVersion.v1,
|
|
138
|
+
type: ConnectionType.Unidirectional,
|
|
139
|
+
}), true);
|
|
140
|
+
try {
|
|
141
|
+
// Parse request body if present
|
|
142
|
+
let payload;
|
|
143
|
+
if (canHaveBody && body) {
|
|
144
|
+
const bodyStream = Readable.fromWeb(body);
|
|
145
|
+
const cannotDecode = !contentType || !this.params.formats.supportsDecoder(contentType);
|
|
146
|
+
if (isBlob || cannotDecode) {
|
|
147
|
+
const type = contentType || 'application/octet-stream';
|
|
148
|
+
const contentLength = request.headers.get('content-length');
|
|
149
|
+
const size = contentLength
|
|
150
|
+
? Number.parseInt(contentLength)
|
|
151
|
+
: undefined;
|
|
152
|
+
payload = new ProtocolClientStream(-1, { size, type });
|
|
153
|
+
bodyStream.pipe(payload);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
const buffer = Buffer.concat(await bodyStream.toArray());
|
|
157
|
+
if (buffer.byteLength > 0) {
|
|
158
|
+
payload = connection.decoder.decode(buffer);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const querystring = url.searchParams.get('payload');
|
|
164
|
+
if (querystring) {
|
|
165
|
+
payload = JSON.parse(querystring);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const metadata = (metadata) => {
|
|
169
|
+
const allowHttpMethod = metadata.get(AllowedHttpMethod) ?? DEFAULT_ALLOWED_METHODS;
|
|
170
|
+
if (!allowHttpMethod.includes(method)) {
|
|
171
|
+
throw new ProtocolError(ErrorCode.NotFound);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const result = await this.params.onRpc(connection, {
|
|
175
|
+
callId: 0, // since the connection is closed after the call, only one call exists per connection
|
|
176
|
+
payload,
|
|
177
|
+
procedure,
|
|
178
|
+
metadata,
|
|
179
|
+
}, signal, provide(injections.httpResponseHeaders, responseHeaders));
|
|
180
|
+
// Handle blob responses
|
|
181
|
+
if (result instanceof ProtocolBlob) {
|
|
182
|
+
const { source, metadata } = result;
|
|
183
|
+
const { type } = metadata;
|
|
184
|
+
responseHeaders.set(NEEMATA_BLOB_HEADER, 'true');
|
|
185
|
+
responseHeaders.set('Content-Type', type);
|
|
186
|
+
if (metadata.size) {
|
|
187
|
+
responseHeaders.set('Content-Length', metadata.size.toString());
|
|
188
|
+
}
|
|
189
|
+
// Convert source to ReadableStream
|
|
190
|
+
let stream;
|
|
191
|
+
if (source instanceof ReadableStream) {
|
|
192
|
+
stream = source;
|
|
193
|
+
}
|
|
194
|
+
else if (source instanceof Readable || source instanceof Duplex) {
|
|
195
|
+
stream = Readable.toWeb(source);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
throw new Error('Invalid stream source');
|
|
199
|
+
}
|
|
200
|
+
return new Response(stream, {
|
|
201
|
+
status: HttpStatus.OK,
|
|
202
|
+
statusText: HttpStatusText[HttpStatus.OK],
|
|
203
|
+
headers: responseHeaders,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
else if (isAsyncIterable(result)) {
|
|
207
|
+
responseHeaders.set('Content-Type', connection.encoder.contentType);
|
|
208
|
+
responseHeaders.set('Transfer-Encoding', 'chunked');
|
|
209
|
+
const stream = new ReadableStream({
|
|
210
|
+
async start(controller) {
|
|
211
|
+
try {
|
|
212
|
+
for await (const chunk of result) {
|
|
213
|
+
const encoded = connection.encoder.encode(chunk);
|
|
214
|
+
const base64 = Buffer.from(encoded.buffer, encoded.byteOffset, encoded.byteLength).toString('base64');
|
|
215
|
+
controller.enqueue(`data: ${base64}\n\n`);
|
|
216
|
+
}
|
|
217
|
+
controller.close();
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
if (isAbortError(error))
|
|
221
|
+
controller.close();
|
|
222
|
+
else
|
|
223
|
+
controller.error(error);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
return new Response(stream, {
|
|
228
|
+
status: HttpStatus.OK,
|
|
229
|
+
statusText: HttpStatusText[HttpStatus.OK],
|
|
230
|
+
headers: responseHeaders,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
// Handle regular responses
|
|
235
|
+
const buffer = connection.encoder.encode(result);
|
|
236
|
+
responseHeaders.set('Content-Type', connection.encoder.contentType);
|
|
237
|
+
// @ts-expect-error
|
|
238
|
+
return new Response(buffer, {
|
|
239
|
+
status: HttpStatus.OK,
|
|
240
|
+
statusText: HttpStatusText[HttpStatus.OK],
|
|
241
|
+
headers: responseHeaders,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
console.error(error);
|
|
247
|
+
if (error instanceof UnsupportedFormatError) {
|
|
248
|
+
const status = error instanceof UnsupportedContentTypeError
|
|
249
|
+
? HttpStatus.UnsupportedMediaType
|
|
250
|
+
: HttpStatus.NotAcceptable;
|
|
251
|
+
const text = HttpStatusText[status];
|
|
252
|
+
return new Response(text, {
|
|
253
|
+
status,
|
|
254
|
+
statusText: text,
|
|
255
|
+
headers: responseHeaders,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
if (error instanceof ProtocolError) {
|
|
259
|
+
const status = error.code in HttpCodeMap
|
|
260
|
+
? HttpCodeMap[error.code]
|
|
261
|
+
: HttpStatus.InternalServerError;
|
|
262
|
+
const text = HttpStatusText[status];
|
|
263
|
+
const payload = connection.encoder.encode(error);
|
|
264
|
+
responseHeaders.set('Content-Type', connection.encoder.contentType);
|
|
265
|
+
// @ts-expect-error
|
|
266
|
+
return new Response(payload, {
|
|
267
|
+
status,
|
|
268
|
+
statusText: text,
|
|
269
|
+
headers: responseHeaders,
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
// Unknown error
|
|
273
|
+
// this.logError(error, 'Unknown error while processing HTTP request')
|
|
274
|
+
console.error(error);
|
|
275
|
+
const payload = connection.encoder.encode(new ProtocolError(ErrorCode.InternalServerError, 'Internal Server Error'));
|
|
276
|
+
responseHeaders.set('Content-Type', connection.encoder.contentType);
|
|
277
|
+
// @ts-expect-error
|
|
278
|
+
return new Response(payload, {
|
|
279
|
+
status: HttpStatus.InternalServerError,
|
|
280
|
+
statusText: HttpStatusText[HttpStatus.InternalServerError],
|
|
281
|
+
headers: responseHeaders,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch (e_1) {
|
|
286
|
+
env_1.error = e_1;
|
|
287
|
+
env_1.hasError = true;
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
const result_1 = __disposeResources(env_1);
|
|
291
|
+
if (result_1)
|
|
292
|
+
await result_1;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
applyCors(origin, request, headers) {
|
|
296
|
+
if (!this.#corsOptions)
|
|
297
|
+
return;
|
|
298
|
+
let params = null;
|
|
299
|
+
if (this.options.cors === true) {
|
|
300
|
+
params = { ...DEFAULT_CORS_PARAMS };
|
|
301
|
+
}
|
|
302
|
+
else if (Array.isArray(this.options.cors) &&
|
|
303
|
+
this.options.cors.includes(origin)) {
|
|
304
|
+
params = { ...DEFAULT_CORS_PARAMS };
|
|
305
|
+
}
|
|
306
|
+
else if (typeof this.options.cors === 'function') {
|
|
307
|
+
const result = this.options.cors(origin, request);
|
|
308
|
+
if (typeof result === 'boolean') {
|
|
309
|
+
if (result) {
|
|
310
|
+
params = { ...DEFAULT_CORS_PARAMS };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
else if (typeof result === 'object') {
|
|
314
|
+
params = { ...DEFAULT_CORS_PARAMS };
|
|
315
|
+
for (const key in DEFAULT_CORS_PARAMS) {
|
|
316
|
+
params[key] = result[key];
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (params === null)
|
|
321
|
+
return;
|
|
322
|
+
headers.set(CORS_HEADERS_MAP.origin, origin);
|
|
323
|
+
for (const key in params) {
|
|
324
|
+
const header = CORS_HEADERS_MAP[key];
|
|
325
|
+
if (header) {
|
|
326
|
+
let value = params[key];
|
|
327
|
+
if (Array.isArray(value))
|
|
328
|
+
value = value.filter(Boolean).join(', ');
|
|
329
|
+
if (value)
|
|
330
|
+
headers.set(header, value);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
createServer() {
|
|
335
|
+
// const hooks = this.createWsHooks()
|
|
336
|
+
const opts = {
|
|
337
|
+
...this.options,
|
|
338
|
+
// logger: this.logger.child({ $lable: 'WsServer' }),
|
|
339
|
+
fetchHandler: this.httpHandler.bind(this),
|
|
340
|
+
};
|
|
341
|
+
return this.adapterFactory(opts);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAO9C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EACL,cAAc,EACd,SAAS,EACT,YAAY,EACZ,eAAe,GAChB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,wBAAwB,CAAA;AAW/B,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,UAAU,EACV,cAAc,GACf,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAE9C,MAAM,mBAAmB,GAAG,gBAAgB,CAAA;AAC5C,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC,C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GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;YACpC,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;gBACvB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;oBAAE,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBAClE,IAAI,KAAK;oBAAE,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IAEO,YAAY;QAClB,qCAAqC;QACrC,MAAM,IAAI,GAAsB;YAC9B,GAAG,IAAI,CAAC,OAAO;YACf,qDAAqD;YACrD,YAAY,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;SAC1C,CAAA;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Async, OneOf } from '@nmtjs/common';
|
|
2
|
+
export type HttpTransportServerRequest = {
|
|
3
|
+
url: URL;
|
|
4
|
+
method: string;
|
|
5
|
+
headers: Headers;
|
|
6
|
+
};
|
|
7
|
+
export type HttpTransportOptions<R extends keyof HttpTransportRuntimes = keyof HttpTransportRuntimes> = {
|
|
8
|
+
listen: HttpTransportListenOptions;
|
|
9
|
+
cors?: HttpTransportCorsOptions;
|
|
10
|
+
tls?: HttpTransportTlsOptions;
|
|
11
|
+
runtime?: HttpTransportRuntimes[R];
|
|
12
|
+
};
|
|
13
|
+
export type HttpTransportCorsCustomParams = {
|
|
14
|
+
allowMethods?: string[];
|
|
15
|
+
allowHeaders?: string[];
|
|
16
|
+
allowCredentials?: string;
|
|
17
|
+
maxAge?: string;
|
|
18
|
+
exposeHeaders?: string[];
|
|
19
|
+
requestHeaders?: string[];
|
|
20
|
+
requestMethod?: string;
|
|
21
|
+
};
|
|
22
|
+
export type HttpTransportCorsOptions = true | string[] | HttpTransportCorsCustomParams | ((origin: string, request: HttpTransportServerRequest) => boolean | HttpTransportCorsCustomParams);
|
|
23
|
+
export type HttpTransportListenOptions = OneOf<[
|
|
24
|
+
{
|
|
25
|
+
port: number;
|
|
26
|
+
hostname?: string;
|
|
27
|
+
reusePort?: boolean;
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
unix: string;
|
|
31
|
+
}
|
|
32
|
+
]>;
|
|
33
|
+
export type HttpTransportRuntimeBun = Partial<Pick<import('bun').Serve.Options<undefined>, 'development' | 'id' | 'maxRequestBodySize' | 'idleTimeout' | 'ipv6Only'> & import('bun').Serve.Routes<any, any>>;
|
|
34
|
+
export type HttpTransportRuntimeNode = {};
|
|
35
|
+
export type HttpTransportRuntimeDeno = {};
|
|
36
|
+
export type HttpTransportRuntimes = {
|
|
37
|
+
bun: HttpTransportRuntimeBun;
|
|
38
|
+
node: HttpTransportRuntimeNode;
|
|
39
|
+
deno: HttpTransportRuntimeDeno;
|
|
40
|
+
};
|
|
41
|
+
export type HttpTransportTlsOptions = {
|
|
42
|
+
/**
|
|
43
|
+
* File path or inlined TLS certificate in PEM format (required).
|
|
44
|
+
*/
|
|
45
|
+
cert?: string;
|
|
46
|
+
/**
|
|
47
|
+
* File path or inlined TLS private key in PEM format (required).
|
|
48
|
+
*/
|
|
49
|
+
key?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Passphrase for the private key (optional).
|
|
52
|
+
*/
|
|
53
|
+
passphrase?: string;
|
|
54
|
+
};
|
|
55
|
+
export type HttpAdapterParams<R extends keyof HttpTransportRuntimes = keyof HttpTransportRuntimes> = {
|
|
56
|
+
listen: HttpTransportListenOptions;
|
|
57
|
+
fetchHandler: (request: HttpTransportServerRequest, body: ReadableStream | null, signal: AbortSignal) => Async<Response>;
|
|
58
|
+
cors?: HttpTransportCorsOptions;
|
|
59
|
+
tls?: HttpTransportTlsOptions;
|
|
60
|
+
runtime?: HttpTransportRuntimes[R];
|
|
61
|
+
};
|
|
62
|
+
export type DenoServer = ReturnType<typeof globalThis.Deno.serve>;
|
|
63
|
+
export interface HttpAdapterServer {
|
|
64
|
+
runtime: {
|
|
65
|
+
bun?: import('bun').Server<undefined>;
|
|
66
|
+
node?: import('uWebSockets.js').TemplatedApp;
|
|
67
|
+
deno?: DenoServer;
|
|
68
|
+
};
|
|
69
|
+
stop: () => Async<any>;
|
|
70
|
+
start: () => Async<string>;
|
|
71
|
+
}
|
|
72
|
+
export type HttpAdapterServerFactory<R extends keyof HttpTransportRuntimes = keyof HttpTransportRuntimes> = (params: HttpAdapterParams<R>) => HttpAdapterServer;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ProtocolError } from '@nmtjs/protocol/server';
|
|
2
|
+
export declare const InternalError: (message?: string) => ProtocolError;
|
|
3
|
+
export declare const NotFoundError: (message?: string) => ProtocolError;
|
|
4
|
+
export declare const ForbiddenError: (message?: string) => ProtocolError;
|
|
5
|
+
export declare const RequestTimeoutError: (message?: string) => ProtocolError;
|
|
6
|
+
export declare const NotFoundHttpResponse: () => Response;
|
|
7
|
+
export declare const InternalServerErrorHttpResponse: () => Response;
|
|
8
|
+
export declare const StatusResponse: () => Response;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ErrorCode } from '@nmtjs/protocol';
|
|
2
|
+
import { ProtocolError } from '@nmtjs/protocol/server';
|
|
3
|
+
export const InternalError = (message = 'Internal Server Error') => new ProtocolError(ErrorCode.InternalServerError, message);
|
|
4
|
+
export const NotFoundError = (message = 'Not Found') => new ProtocolError(ErrorCode.NotFound, message);
|
|
5
|
+
export const ForbiddenError = (message = 'Forbidden') => new ProtocolError(ErrorCode.Forbidden, message);
|
|
6
|
+
export const RequestTimeoutError = (message = 'Request Timeout') => new ProtocolError(ErrorCode.RequestTimeout, message);
|
|
7
|
+
export const NotFoundHttpResponse = () => new Response('Not Found', {
|
|
8
|
+
status: 404,
|
|
9
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
10
|
+
});
|
|
11
|
+
export const InternalServerErrorHttpResponse = () => new Response('Internal Server Error', {
|
|
12
|
+
status: 500,
|
|
13
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
14
|
+
});
|
|
15
|
+
export const StatusResponse = () => new Response('OK', { status: 200 });
|
|
16
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AAEtD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,GAAG,uBAAuB,EAAE,EAAE,CACjE,IAAI,aAAa,CAAC,SAAS,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAA;AAE3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,GAAG,WAAW,EAAE,EAAE,CACrD,IAAI,aAAa,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AAEhD,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAO,GAAG,WAAW,EAAE,EAAE,CACtD,IAAI,aAAa,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;AAEjD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAO,GAAG,iBAAiB,EAAE,EAAE,CACjE,IAAI,aAAa,CAAC,SAAS,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AAEtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE,CACvC,IAAI,QAAQ,CAAC,WAAW,EAAE;IACxB,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE;CAC1C,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,EAAE,CAClD,IAAI,QAAQ,CAAC,uBAAuB,EAAE;IACpC,MAAM,EAAE,GAAG;IACX,OAAO,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE;CAC1C,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,EAAE,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
},
|
|
10
10
|
"devDependencies": {
|
|
11
11
|
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.56.0",
|
|
12
|
-
"@nmtjs/
|
|
13
|
-
"@nmtjs/
|
|
14
|
-
"@nmtjs/
|
|
15
|
-
"@nmtjs/
|
|
12
|
+
"@nmtjs/client": "0.15.0-beta.3",
|
|
13
|
+
"@nmtjs/common": "0.15.0-beta.3",
|
|
14
|
+
"@nmtjs/gateway": "0.15.0-beta.3",
|
|
15
|
+
"@nmtjs/protocol": "0.15.0-beta.3"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"@types/bun": "^1.3.0",
|
|
19
19
|
"@types/deno": "^2.3.0",
|
|
20
20
|
"@types/node": "^24",
|
|
21
21
|
"uWebSockets.js": "^20.56.0",
|
|
22
|
-
"@nmtjs/common": "0.15.0-beta.
|
|
23
|
-
"@nmtjs/core": "0.15.0-beta.
|
|
24
|
-
"@nmtjs/gateway": "0.15.0-beta.
|
|
25
|
-
"@nmtjs/protocol": "0.15.0-beta.
|
|
22
|
+
"@nmtjs/common": "0.15.0-beta.3",
|
|
23
|
+
"@nmtjs/core": "0.15.0-beta.3",
|
|
24
|
+
"@nmtjs/gateway": "0.15.0-beta.3",
|
|
25
|
+
"@nmtjs/protocol": "0.15.0-beta.3"
|
|
26
26
|
},
|
|
27
27
|
"peerDependenciesMeta": {
|
|
28
28
|
"@types/bun": {
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
"LICENSE.md",
|
|
49
49
|
"README.md"
|
|
50
50
|
],
|
|
51
|
-
"version": "0.15.0-beta.
|
|
51
|
+
"version": "0.15.0-beta.3",
|
|
52
52
|
"scripts": {
|
|
53
53
|
"clean-build": "rm -rf ./dist",
|
|
54
|
-
"build": "tsc",
|
|
54
|
+
"build": "tsc --declaration --sourcemap",
|
|
55
55
|
"dev": "tsc --watch",
|
|
56
56
|
"type-check": "tsc --noEmit"
|
|
57
57
|
}
|