@boo-labs/server 0.0.0-stage → 1.0.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/README.md +229 -2
- package/index.mjs +23 -0
- package/package.json +71 -4
- package/source/application/Kernel/index.mjs +1137 -0
- package/source/application/Server/index.mjs +1201 -0
- package/source/application/configurations/Http2CleartextServerConfiguration/index.mjs +168 -0
- package/source/application/configurations/Http2SecureServerConfiguration/index.mjs +172 -0
- package/source/application/configurations/HttpServerConfiguration/index.mjs +169 -0
- package/source/application/configurations/HttpsServerConfiguration/index.mjs +172 -0
- package/source/application/configurations/ServerConfiguration/Options/CORSOptions/CORSOptionsValue.mjs +158 -0
- package/source/application/configurations/ServerConfiguration/Options/CORSOptions/index.mjs +87 -0
- package/source/application/configurations/ServerConfiguration/Options/CSRFOptions/CSRFOptionsValue.mjs +178 -0
- package/source/application/configurations/ServerConfiguration/Options/CSRFOptions/index.mjs +80 -0
- package/source/application/configurations/ServerConfiguration/Options/CompressOptions/CompressOptionsValue.mjs +126 -0
- package/source/application/configurations/ServerConfiguration/Options/CompressOptions/index.mjs +81 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieParserOptions/CookieParserOptionsValue.mjs +107 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieParserOptions/index.mjs +82 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieSessionOptions/CookieSessionOptionsValue.mjs +182 -0
- package/source/application/configurations/ServerConfiguration/Options/CookieSessionOptions/index.mjs +86 -0
- package/source/application/configurations/ServerConfiguration/Options/ListenOptions/ListenOptionsValue.mjs +95 -0
- package/source/application/configurations/ServerConfiguration/Options/ListenOptions/index.mjs +47 -0
- package/source/application/configurations/ServerConfiguration/Options/MiddlewareOption.mjs +102 -0
- package/source/application/configurations/ServerConfiguration/Options/Options.mjs +105 -0
- package/source/application/configurations/ServerConfiguration/Options/RateLimitOptions/RateLimitOptionsValue.mjs +164 -0
- package/source/application/configurations/ServerConfiguration/Options/RateLimitOptions/index.mjs +84 -0
- package/source/application/configurations/ServerConfiguration/Options/RequestOptions/RequestOptionsValue.mjs +108 -0
- package/source/application/configurations/ServerConfiguration/Options/RequestOptions/index.mjs +47 -0
- package/source/application/configurations/ServerConfiguration/Options/ResponseOptions/ResponseOptionsValue.mjs +101 -0
- package/source/application/configurations/ServerConfiguration/Options/ResponseOptions/index.mjs +47 -0
- package/source/application/configurations/ServerConfiguration/Options/SecurityHeadersOptions/SecurityHeadersOptionsValue.mjs +272 -0
- package/source/application/configurations/ServerConfiguration/Options/SecurityHeadersOptions/index.mjs +85 -0
- package/source/application/configurations/ServerConfiguration/Options/ServerOption.mjs +50 -0
- package/source/application/configurations/ServerConfiguration/Options/StaticOptions/StaticOptionsValue.mjs +164 -0
- package/source/application/configurations/ServerConfiguration/Options/StaticOptions/index.mjs +89 -0
- package/source/application/configurations/ServerConfiguration/index.mjs +781 -0
- package/source/application/resolvers/TransportResolver/index.mjs +119 -0
- package/source/application/use-cases/CloseServer/index.mjs +85 -0
- package/source/application/use-cases/ListenServer/index.mjs +98 -0
- package/source/core/EventSystem/index.mjs +110 -0
- package/source/core/Exchange/ExchangeContext.mjs +291 -0
- package/source/core/Exchange/Telemetry.mjs +193 -0
- package/source/core/Exchange/index.mjs +604 -0
- package/source/core/ExchangeLayerBuilder/index.mjs +133 -0
- package/source/core/IPCMain/IPCMain.mjs +507 -0
- package/source/core/IPCMain/IPCProtocol.mjs +441 -0
- package/source/core/IPCMain/IPCServerChannel.mjs +331 -0
- package/source/core/IPCMain/WebSocketAdapter.mjs +189 -0
- package/source/core/Request/BodyParser/BodyParser.mjs +197 -0
- package/source/core/Request/BodyParser/JSONParser.mjs +70 -0
- package/source/core/Request/BodyParser/MultipartParser.mjs +612 -0
- package/source/core/Request/BodyParser/URLEncodedParser.mjs +71 -0
- package/source/core/Request/RequestHeaders.mjs +177 -0
- package/source/core/Request/index.mjs +805 -0
- package/source/core/Response/ResponseHeaders.mjs +402 -0
- package/source/core/Response/index.mjs +1370 -0
- package/source/core/middlewares/CORSMiddleware/index.mjs +289 -0
- package/source/core/middlewares/CSRFMiddleware/index.mjs +284 -0
- package/source/core/middlewares/CompressMiddleware/index.mjs +460 -0
- package/source/core/middlewares/CookieParserMiddleware/index.mjs +194 -0
- package/source/core/middlewares/CookieSessionMiddleware/index.mjs +460 -0
- package/source/core/middlewares/RateLimitMiddleware/index.mjs +245 -0
- package/source/core/middlewares/SecurityHeadersMiddleware/index.mjs +151 -0
- package/source/core/middlewares/StaticMiddleware/index.mjs +628 -0
- package/source/core/routing/ExchangeLayer/ExchangeMatcher.mjs +127 -0
- package/source/core/routing/ExchangeLayer/index.mjs +254 -0
- package/source/core/routing/Pipeline/index.mjs +157 -0
- package/source/core/routing/Router/Route.mjs +184 -0
- package/source/core/routing/Router/index.mjs +523 -0
- package/source/core/routing/RouterRegister/OptionsMiddleware.mjs +147 -0
- package/source/core/routing/RouterRegister/index.mjs +150 -0
- package/source/core/routing/RouterSystem/index.mjs +225 -0
- package/source/core/value-objects/Address/index.mjs +281 -0
- package/source/core/value-objects/Endpoint/index.mjs +293 -0
- package/source/index.mjs +62 -0
- package/source/infrastructure/adapters/Http2Adapter/index.mjs +144 -0
- package/source/infrastructure/adapters/Http2CleartextAdapter/index.mjs +147 -0
- package/source/infrastructure/adapters/HttpAdapter/index.mjs +124 -0
- package/source/infrastructure/adapters/HttpsAdapter/index.mjs +124 -0
- package/source/infrastructure/adapters/TransportAdapter/createWebSocketOpenRequest.mjs +843 -0
- package/source/infrastructure/adapters/TransportAdapter/index.mjs +555 -0
- package/source/shared/Identifier/index.mjs +671 -0
- package/source/shared/constants/symbols/brands/index.mjs +45 -0
- package/source/shared/domain/UUIDV7/index.mjs +346 -0
- package/source/shared/errors/BaseError/index.mjs +157 -0
- package/source/shared/errors/IPCError/index.mjs +97 -0
- package/source/shared/errors/MiddlewareError/index.mjs +106 -0
- package/source/shared/errors/PathnamePatternError/index.mjs +103 -0
- package/source/shared/errors/RequestError/index.mjs +116 -0
- package/source/shared/errors/ResponseError/index.mjs +140 -0
- package/source/shared/errors/RouterError/index.mjs +90 -0
- package/source/shared/errors/ServerConfigurationError/index.mjs +551 -0
- package/source/shared/errors/ServerError/index.mjs +127 -0
- package/source/shared/errors/WebSocketError/index.mjs +58 -0
- package/source/shared/outcome/ErrorSchema.mjs +361 -0
- package/source/shared/outcome/Result/index.mjs +239 -0
- package/source/shared/outcome/Validation/index.mjs +208 -0
- package/source/shared/validations/Middleware/index.mjs +160 -0
- package/source/shared/validations/PathnamePattern/index.mjs +256 -0
- package/source/shared/validations/Server/NotFoundHandler/index.mjs +94 -0
- package/source/shared/validations/Server/Router/index.mjs +68 -0
- package/source/shared/validations/Server/ServerConfiguration/index.mjs +68 -0
- package/source/shared/validations/Server/SystemErrorHandler/index.mjs +94 -0
- package/source/shared/validations/ServerConfiguration/CORSOptions/index.mjs +310 -0
- package/source/shared/validations/ServerConfiguration/CSRFOptions/index.mjs +299 -0
- package/source/shared/validations/ServerConfiguration/CompressOptions/index.mjs +204 -0
- package/source/shared/validations/ServerConfiguration/CookieParserOptions/index.mjs +102 -0
- package/source/shared/validations/ServerConfiguration/CookieSessionOptions/index.mjs +332 -0
- package/source/shared/validations/ServerConfiguration/ListenOptions/index.mjs +178 -0
- package/source/shared/validations/ServerConfiguration/RateLimitOptions/index.mjs +229 -0
- package/source/shared/validations/ServerConfiguration/RequestOptions/index.mjs +132 -0
- package/source/shared/validations/ServerConfiguration/ResponseOptions/index.mjs +122 -0
- package/source/shared/validations/ServerConfiguration/SecurityHeadersOptions/index.mjs +137 -0
- package/source/shared/validations/ServerConfiguration/StaticOptions/index.mjs +248 -0
- package/types/index.d.ts +719 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file Defines the Node.js `HTTP/2` secure transport adapter.
|
|
4
|
+
*
|
|
5
|
+
* @description Provides the concrete `HTTP/2` secure transport adapter for Node.js.
|
|
6
|
+
*
|
|
7
|
+
* `Http2Adapter` implements the `TransportAdapter` contract using Node.js'
|
|
8
|
+
* built-in `node:http2` module. It creates and manages the native
|
|
9
|
+
* `Http2SecureServer` instance and translates the transport operations defined
|
|
10
|
+
* by the application into operations provided by the Node.js HTTP/2 server.
|
|
11
|
+
*
|
|
12
|
+
* This adapter belongs to the infrastructure layer and isolates the rest
|
|
13
|
+
* of the application from the Node.js HTTP/2 server implementation.
|
|
14
|
+
*
|
|
15
|
+
* @module Http2Adapter
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// ━━ IMPORT MODULES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
19
|
+
// » IMPORT NATIVE NODEJS MODULES
|
|
20
|
+
import http2 from 'node:http2';
|
|
21
|
+
|
|
22
|
+
// » IMPORT LOCAL MODULES
|
|
23
|
+
import TransportAdapter from '../TransportAdapter/index.mjs';
|
|
24
|
+
|
|
25
|
+
// ━━ TYPE DEFINITIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
26
|
+
/**
|
|
27
|
+
* Represents the underlying Node.js secure HTTP/2 server.
|
|
28
|
+
*
|
|
29
|
+
* @typedef {import('node:http2').Http2SecureServer} Http2SecureServer
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options passed to the underlying Node.js HTTP/2 server.
|
|
34
|
+
*
|
|
35
|
+
* This type is provided by the native `node:http2` module and is used to
|
|
36
|
+
* configure the server created by {@link Http2Adapter}.
|
|
37
|
+
*
|
|
38
|
+
* @typedef {import('node:http2').SecureServerOptions} ServerOptions
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents an incoming HTTP/1.1 request message from Node.js.
|
|
43
|
+
*
|
|
44
|
+
* @typedef {import('node:http').IncomingMessage} IncomingMessage
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Represents a Node.js HTTP/1.1 response.
|
|
49
|
+
*
|
|
50
|
+
* @typedef {import('node:http').ServerResponse} ServerResponse
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Represents an incoming HTTP/2 request.
|
|
55
|
+
*
|
|
56
|
+
* @typedef {import('node:http2').Http2ServerRequest} Http2ServerRequest
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Represents an HTTP/2 server response.
|
|
61
|
+
*
|
|
62
|
+
* @typedef {import('node:http2').Http2ServerResponse} Http2ServerResponse
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Callback that handles an incoming HTTP/1.1 request.
|
|
67
|
+
*
|
|
68
|
+
* @callback Http1Handler
|
|
69
|
+
* @param {IncomingMessage} request - The incoming HTTP/1.1 request message.
|
|
70
|
+
* @param {ServerResponse} response - The HTTP/1.1 server response.
|
|
71
|
+
* @returns {void}
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Callback that handles an incoming HTTP/2 request.
|
|
76
|
+
*
|
|
77
|
+
* @callback Http2Handler
|
|
78
|
+
* @param {Http2ServerRequest} request - The incoming HTTP/2 request message.
|
|
79
|
+
* @param {Http2ServerResponse} response - The HTTP/2 server response.
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Identity for a secure HTTP/2 server (h2).
|
|
85
|
+
*
|
|
86
|
+
* Represents a permitted transport identity for a Node.js HTTP/2 server
|
|
87
|
+
* operating over TLS.
|
|
88
|
+
*
|
|
89
|
+
* @typedef {object} TransportIdentityH2
|
|
90
|
+
* @property {Http2SecureServer} server - The underlying Node.js secure HTTP/2 server instance.
|
|
91
|
+
* @property {'https'} protocol - The application-level protocol (`https`).
|
|
92
|
+
* @property {'h2'} transport - The transport identifier for HTTP/2 over TLS (`h2`).
|
|
93
|
+
* @property {Http2Handler | Http1Handler} requestHandler - Callback invoked for each incoming request.
|
|
94
|
+
*/
|
|
95
|
+
// ━━ MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
96
|
+
/**
|
|
97
|
+
* Node.js implementation of the {@link TransportAdapter} contract.
|
|
98
|
+
*
|
|
99
|
+
* @classdesc `Http2Adapter` adapts the native Node.js secure HTTP/2 server to
|
|
100
|
+
* the transport contract expected by the application. It owns the underlying
|
|
101
|
+
* `Http2SecureServer` instance and exposes transport-independent operations
|
|
102
|
+
* through the inherited `TransportAdapter` API.
|
|
103
|
+
*
|
|
104
|
+
* The adapter uses the `https` protocol and `h2` transport, while delegating
|
|
105
|
+
* server lifecycle operations to Node.js.
|
|
106
|
+
*
|
|
107
|
+
* @augments {TransportAdapter<TransportIdentityH2>}
|
|
108
|
+
*/
|
|
109
|
+
class Http2Adapter extends TransportAdapter {
|
|
110
|
+
/**
|
|
111
|
+
* Creates a Node.js secure HTTP/2 transport adapter.
|
|
112
|
+
*
|
|
113
|
+
* The constructor creates the underlying Node.js secure HTTP/2 server
|
|
114
|
+
* using the supplied server configuration.
|
|
115
|
+
*
|
|
116
|
+
* @param {ServerOptions} [options] - Configuration for the HTTP/2 server.
|
|
117
|
+
* @example
|
|
118
|
+
* ```js
|
|
119
|
+
* const adapter = new Http2Adapter({
|
|
120
|
+
* key: privateKey,
|
|
121
|
+
* cert: certificate
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
constructor(options) {
|
|
126
|
+
const server = Http2Adapter.#createServer(options);
|
|
127
|
+
super(server, 'https', 'h2');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Creates the underlying Node.js secure HTTP/2 server.
|
|
132
|
+
*
|
|
133
|
+
* @param {ServerOptions} [options] - Configuration for the HTTP/2 server.
|
|
134
|
+
* @returns {Http2SecureServer} The created Node.js secure HTTP/2 server.
|
|
135
|
+
*/
|
|
136
|
+
static #createServer(options) {
|
|
137
|
+
if (options === undefined) {
|
|
138
|
+
return http2.createSecureServer();
|
|
139
|
+
}
|
|
140
|
+
return http2.createSecureServer(options);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
144
|
+
export default Http2Adapter;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file Defines the Node.js `HTTP/2` cleartext transport adapter.
|
|
4
|
+
*
|
|
5
|
+
* @description Provides the concrete `HTTP/2` cleartext transport adapter for Node.js.
|
|
6
|
+
*
|
|
7
|
+
* `Http2CleartextAdapter` implements the `TransportAdapter` contract using Node.js'
|
|
8
|
+
* built-in `node:http2` module. It creates and manages the native
|
|
9
|
+
* `Http2Server` instance and translates the transport operations defined
|
|
10
|
+
* by the application into operations provided by the Node.js HTTP/2 server.
|
|
11
|
+
*
|
|
12
|
+
* This adapter belongs to the infrastructure layer and isolates the rest
|
|
13
|
+
* of the application from the Node.js HTTP/2 server implementation.
|
|
14
|
+
*
|
|
15
|
+
* @module Http2CleartextAdapter
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// ━━ IMPORT MODULES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
19
|
+
// » IMPORT NATIVE NODEJS MODULES
|
|
20
|
+
import http2 from 'node:http2';
|
|
21
|
+
|
|
22
|
+
// » IMPORT LOCAL MODULES
|
|
23
|
+
import TransportAdapter from '../TransportAdapter/index.mjs';
|
|
24
|
+
|
|
25
|
+
// ━━ TYPE DEFINITIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
26
|
+
/**
|
|
27
|
+
* Represents the underlying Node.js cleartext HTTP/2 server.
|
|
28
|
+
*
|
|
29
|
+
* @typedef {import('node:http2').Http2Server} Http2Server
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options passed to the underlying Node.js HTTP/2 server.
|
|
34
|
+
*
|
|
35
|
+
* This type is provided by the native `node:http2` module and is used to
|
|
36
|
+
* configure the server created by {@link Http2CleartextAdapter}.
|
|
37
|
+
*
|
|
38
|
+
* @typedef {import('node:http2').ServerOptions} ServerOptions
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents an incoming HTTP/1.1 request message from Node.js.
|
|
43
|
+
*
|
|
44
|
+
* @typedef {import('node:http').IncomingMessage} IncomingMessage
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Represents a Node.js HTTP/1.1 response.
|
|
49
|
+
*
|
|
50
|
+
* @typedef {import('node:http').ServerResponse} ServerResponse
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Represents an incoming HTTP/2 request.
|
|
55
|
+
*
|
|
56
|
+
* @typedef {import('node:http2').Http2ServerRequest} Http2ServerRequest
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Represents an HTTP/2 server response.
|
|
61
|
+
*
|
|
62
|
+
* @typedef {import('node:http2').Http2ServerResponse} Http2ServerResponse
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Callback that handles an incoming HTTP/1.1 request.
|
|
67
|
+
*
|
|
68
|
+
* @callback Http1Handler
|
|
69
|
+
* @param {IncomingMessage} request - The incoming HTTP/1.1 request message.
|
|
70
|
+
* @param {ServerResponse} response - The HTTP/1.1 server response.
|
|
71
|
+
* @returns {void}
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Callback that handles an incoming HTTP/2 request.
|
|
76
|
+
*
|
|
77
|
+
* @callback Http2Handler
|
|
78
|
+
* @param {Http2ServerRequest} request - The incoming HTTP/2 request message.
|
|
79
|
+
* @param {Http2ServerResponse} response - The HTTP/2 server response.
|
|
80
|
+
* @returns {void}
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Identity for a cleartext HTTP/2 server (h2c).
|
|
85
|
+
*
|
|
86
|
+
* Represents a permitted transport identity for a Node.js HTTP/2 server
|
|
87
|
+
* operating over cleartext.
|
|
88
|
+
*
|
|
89
|
+
* @typedef {object} TransportIdentityH2C
|
|
90
|
+
* @property {Http2Server} server - The underlying Node.js HTTP/2 cleartext server instance.
|
|
91
|
+
* @property {'http'} protocol - The application-level protocol (`http`).
|
|
92
|
+
* @property {'h2c'} transport - The transport identifier for HTTP/2 cleartext (`h2c`).
|
|
93
|
+
* @property {Http2Handler | Http1Handler} requestHandler - Callback invoked for each incoming request.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
// ━━ MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
97
|
+
/**
|
|
98
|
+
* Node.js implementation of the {@link TransportAdapter} contract.
|
|
99
|
+
*
|
|
100
|
+
* @classdesc `Http2CleartextAdapter` adapts the native Node.js cleartext HTTP/2
|
|
101
|
+
* server to the transport contract expected by the application. It owns the
|
|
102
|
+
* underlying `Http2Server` instance and exposes transport-independent
|
|
103
|
+
* operations through the inherited `TransportAdapter` API.
|
|
104
|
+
*
|
|
105
|
+
* The adapter uses the `http` protocol and `h2c` transport, while delegating
|
|
106
|
+
* server lifecycle operations to Node.js.
|
|
107
|
+
*
|
|
108
|
+
* @augments {TransportAdapter<TransportIdentityH2C>}
|
|
109
|
+
*/
|
|
110
|
+
class Http2CleartextAdapter extends TransportAdapter {
|
|
111
|
+
/**
|
|
112
|
+
* Creates a Node.js cleartext HTTP/2 transport adapter.
|
|
113
|
+
*
|
|
114
|
+
* The constructor creates the underlying Node.js cleartext HTTP/2 server
|
|
115
|
+
* using the supplied server configuration.
|
|
116
|
+
*
|
|
117
|
+
* @param {ServerOptions} [options] - Configuration for the HTTP/2 server.
|
|
118
|
+
* @example
|
|
119
|
+
* ```js
|
|
120
|
+
* const adapter = new Http2CleartextAdapter({
|
|
121
|
+
* settings: {
|
|
122
|
+
* enablePush: false
|
|
123
|
+
* }
|
|
124
|
+
* });
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
constructor(options) {
|
|
128
|
+
const server = Http2CleartextAdapter.#createServer(options);
|
|
129
|
+
super(server, 'http', 'h2c');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Creates the underlying Node.js cleartext HTTP/2 server.
|
|
134
|
+
*
|
|
135
|
+
* @param {ServerOptions} [options] - Configuration for the HTTP/2 server.
|
|
136
|
+
* @returns {Http2Server} The created Node.js cleartext HTTP/2 server.
|
|
137
|
+
*/
|
|
138
|
+
static #createServer(options) {
|
|
139
|
+
if (options === undefined) {
|
|
140
|
+
return http2.createServer();
|
|
141
|
+
}
|
|
142
|
+
return http2.createServer(options);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
147
|
+
export default Http2CleartextAdapter;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file Defines the Node.js `HTTP` transport adapter.
|
|
4
|
+
*
|
|
5
|
+
* @description Provides the concrete `HTTP` transport adapter for Node.js.
|
|
6
|
+
*
|
|
7
|
+
* `HttpAdapter` implements the `TransportAdapter` contract using Node.js'
|
|
8
|
+
* built-in `node:http` module. It creates and manages the native
|
|
9
|
+
* `http.Server` instance and translates the transport operations defined
|
|
10
|
+
* by the application into operations provided by the Node.js HTTP server.
|
|
11
|
+
*
|
|
12
|
+
* This adapter belongs to the infrastructure layer and isolates the rest
|
|
13
|
+
* of the application from the Node.js HTTP server implementation.
|
|
14
|
+
*
|
|
15
|
+
* @module HttpAdapter
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// ━━ IMPORT MODULES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
19
|
+
// » IMPORT NATIVE NODEJS MODULES
|
|
20
|
+
import http from 'node:http';
|
|
21
|
+
|
|
22
|
+
// » IMPORT LOCAL MODULES
|
|
23
|
+
import TransportAdapter from '../TransportAdapter/index.mjs';
|
|
24
|
+
|
|
25
|
+
// ━━ TYPE DEFINITIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
26
|
+
/**
|
|
27
|
+
* Represents the underlying Node.js HTTP server.
|
|
28
|
+
*
|
|
29
|
+
* @typedef {import('node:http').Server} HttpServer
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options passed to the underlying Node.js HTTP server.
|
|
34
|
+
*
|
|
35
|
+
* This type is provided by the native `node:http` module and is used to
|
|
36
|
+
* configure the server created by {@link HttpAdapter}.
|
|
37
|
+
*
|
|
38
|
+
* @typedef {import('node:http').ServerOptions} ServerOptions
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents an incoming HTTP/1.1 request message from Node.js.
|
|
43
|
+
*
|
|
44
|
+
* @typedef {import('node:http').IncomingMessage} IncomingMessage
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Represents a Node.js HTTP/1.1 response.
|
|
49
|
+
*
|
|
50
|
+
* @typedef {import('node:http').ServerResponse} ServerResponse
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Callback that handles an incoming HTTP/1.1 request.
|
|
55
|
+
*
|
|
56
|
+
* @callback Http1Handler
|
|
57
|
+
* @param {IncomingMessage} request - The incoming HTTP/1.1 request message.
|
|
58
|
+
* @param {ServerResponse} response - The HTTP/1.1 server response.
|
|
59
|
+
* @returns {void}
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Identity for a plain HTTP/1.1 server.
|
|
64
|
+
*
|
|
65
|
+
* Represents a permitted transport identity for a Node.js HTTP server
|
|
66
|
+
* operating over HTTP/1.1 cleartext.
|
|
67
|
+
*
|
|
68
|
+
* @typedef {object} TransportIdentityH1
|
|
69
|
+
* @property {HttpServer} server - The underlying Node.js HTTP server instance.
|
|
70
|
+
* @property {'http'} protocol - The application-level protocol (`http`).
|
|
71
|
+
* @property {'h1'} transport - The transport identifier for HTTP/1.1 cleartext (`h1`).
|
|
72
|
+
* @property {Http1Handler} requestHandler - Callback invoked for each incoming HTTP request.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
// ━━ MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
76
|
+
/**
|
|
77
|
+
* Node.js implementation of the {@link TransportAdapter} contract.
|
|
78
|
+
*
|
|
79
|
+
* @classdesc `HttpAdapter` adapts the native Node.js HTTP server to the
|
|
80
|
+
* transport contract expected by the application. It owns the underlying
|
|
81
|
+
* `http.Server` instance and exposes transport-independent operations
|
|
82
|
+
* through the inherited `TransportAdapter` API.
|
|
83
|
+
*
|
|
84
|
+
* The adapter uses the `http` protocol and `h1` transport, while delegating
|
|
85
|
+
* server lifecycle operations to Node.js.
|
|
86
|
+
*
|
|
87
|
+
* @augments {TransportAdapter<TransportIdentityH1>}
|
|
88
|
+
*/
|
|
89
|
+
class HttpAdapter extends TransportAdapter {
|
|
90
|
+
/**
|
|
91
|
+
* Creates a Node.js HTTP transport adapter.
|
|
92
|
+
*
|
|
93
|
+
* The constructor creates the underlying Node.js HTTP server using the
|
|
94
|
+
* supplied server configuration.
|
|
95
|
+
*
|
|
96
|
+
* @param {ServerOptions} [options] - Configuration for the HTTP server.
|
|
97
|
+
* @example
|
|
98
|
+
* ```js
|
|
99
|
+
* const adapter = new HttpAdapter({
|
|
100
|
+
* keepAliveTimeout: 65000
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
constructor(options) {
|
|
105
|
+
const server = HttpAdapter.#createServer(options);
|
|
106
|
+
super(server, 'http', 'h1');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Creates the underlying Node.js HTTP server.
|
|
111
|
+
*
|
|
112
|
+
* @param {ServerOptions} [options] - Configuration for the HTTP server.
|
|
113
|
+
* @returns {HttpServer} The created Node.js HTTP server.
|
|
114
|
+
*/
|
|
115
|
+
static #createServer(options) {
|
|
116
|
+
if (options === undefined) {
|
|
117
|
+
return http.createServer();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return http.createServer(options);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
124
|
+
export default HttpAdapter;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file Defines the Node.js `HTTPS` transport adapter.
|
|
4
|
+
*
|
|
5
|
+
* @description Provides the concrete `HTTPS` transport adapter for Node.js.
|
|
6
|
+
*
|
|
7
|
+
* `HttpsAdapter` implements the `TransportAdapter` contract using Node.js'
|
|
8
|
+
* built-in `node:https` module. It creates and manages the native
|
|
9
|
+
* `https.Server` instance and translates the transport operations defined
|
|
10
|
+
* by the application into operations provided by the Node.js HTTP server.
|
|
11
|
+
*
|
|
12
|
+
* This adapter belongs to the infrastructure layer and isolates the rest
|
|
13
|
+
* of the application from the Node.js HTTP server implementation.
|
|
14
|
+
*
|
|
15
|
+
* @module HttpsAdapter
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// ━━ IMPORT MODULES ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
19
|
+
// » IMPORT NATIVE NODEJS MODULES
|
|
20
|
+
import https from 'node:https';
|
|
21
|
+
|
|
22
|
+
// » IMPORT LOCAL MODULES
|
|
23
|
+
import TransportAdapter from '../TransportAdapter/index.mjs';
|
|
24
|
+
|
|
25
|
+
// ━━ TYPE DEFINITIONS ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
26
|
+
/**
|
|
27
|
+
* Represents the underlying Node.js HTTPS server.
|
|
28
|
+
*
|
|
29
|
+
* @typedef {import('node:https').Server} HttpsServer
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Configuration options passed to the underlying Node.js HTTPS server.
|
|
34
|
+
*
|
|
35
|
+
* This type is provided by the native `node:https` module and is used to
|
|
36
|
+
* configure the server created by {@link HttpsAdapter}.
|
|
37
|
+
*
|
|
38
|
+
* @typedef {import('node:https').ServerOptions} ServerOptions
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents an incoming HTTP/1.1 request message from Node.js.
|
|
43
|
+
*
|
|
44
|
+
* @typedef {import('node:http').IncomingMessage} IncomingMessage
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Represents a Node.js HTTP/1.1 response.
|
|
49
|
+
*
|
|
50
|
+
* @typedef {import('node:http').ServerResponse} ServerResponse
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Callback that handles an incoming HTTP/1.1 request.
|
|
55
|
+
*
|
|
56
|
+
* @callback Http1Handler
|
|
57
|
+
* @param {IncomingMessage} request - The incoming HTTP/1.1 request message.
|
|
58
|
+
* @param {ServerResponse} response - The HTTP/1.1 server response.
|
|
59
|
+
* @returns {void}
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Identity for a secure HTTPS/1.1 server.
|
|
64
|
+
*
|
|
65
|
+
* Represents a valid combination of a Node.js HTTPS server instance
|
|
66
|
+
* with the corresponding protocol and transport identifiers.
|
|
67
|
+
*
|
|
68
|
+
* @typedef {object} TransportIdentityH1S
|
|
69
|
+
* @property {HttpsServer} server - The underlying Node.js HTTPS server instance.
|
|
70
|
+
* @property {'https'} protocol - The application-level protocol (`https`).
|
|
71
|
+
* @property {'h1s'} transport - The transport identifier for HTTP/1.1 over TLS (`h1s`).
|
|
72
|
+
* @property {Http1Handler} requestHandler - Callback invoked for each incoming HTTP request.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
// ━━ MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
76
|
+
/**
|
|
77
|
+
* Node.js implementation of the {@link TransportAdapter} contract.
|
|
78
|
+
*
|
|
79
|
+
* @classdesc `HttpsAdapter` adapts the native Node.js HTTPS server to the
|
|
80
|
+
* transport contract expected by the application. It owns the underlying
|
|
81
|
+
* `https.Server` instance and exposes transport-independent operations
|
|
82
|
+
* through the inherited `TransportAdapter` API.
|
|
83
|
+
*
|
|
84
|
+
* The adapter uses the `https` protocol and `h1s` transport, while delegating
|
|
85
|
+
* server lifecycle operations to Node.js.
|
|
86
|
+
*
|
|
87
|
+
* @augments {TransportAdapter<TransportIdentityH1S>}
|
|
88
|
+
*/
|
|
89
|
+
class HttpsAdapter extends TransportAdapter {
|
|
90
|
+
/**
|
|
91
|
+
* Creates a Node.js HTTPS transport adapter.
|
|
92
|
+
*
|
|
93
|
+
* The constructor creates the underlying Node.js HTTPS server using the
|
|
94
|
+
* supplied server configuration.
|
|
95
|
+
*
|
|
96
|
+
* @param {ServerOptions} [options] - Configuration for the HTTPS server.
|
|
97
|
+
* @example
|
|
98
|
+
* ```js
|
|
99
|
+
* const adapter = new HttpsAdapter({
|
|
100
|
+
* keepAliveTimeout: 65000
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
constructor(options) {
|
|
105
|
+
const server = HttpsAdapter.#createServer(options);
|
|
106
|
+
super(server, 'https', 'h1s');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Creates the underlying Node.js secure HTTP server.
|
|
111
|
+
*
|
|
112
|
+
* @param {ServerOptions} [options] - Configuration for the HTTPS server.
|
|
113
|
+
* @returns {HttpsServer} The created Node.js secure HTTP server.
|
|
114
|
+
*/
|
|
115
|
+
static #createServer(options) {
|
|
116
|
+
if (options === undefined) {
|
|
117
|
+
return https.createServer();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return https.createServer(options);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// ━━ EXPORT MODULE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
|
124
|
+
export default HttpsAdapter;
|