@boo-labs/server 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +287 -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
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for @boo/server
|
|
3
|
+
*
|
|
4
|
+
* Generated to support TypeScript consumers while keeping the core JS-based.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import * as http from 'node:http';
|
|
8
|
+
import * as https from 'node:https';
|
|
9
|
+
import * as http2 from 'node:http2';
|
|
10
|
+
import * as stream from 'node:stream';
|
|
11
|
+
|
|
12
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
13
|
+
// PRIMITIVE TYPES
|
|
14
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents an HTTP method supported by the routing layer.
|
|
18
|
+
*/
|
|
19
|
+
export type HTTPMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS' | 'QUERY' | 'TRACE';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Identifies an application-layer communication protocol.
|
|
23
|
+
*/
|
|
24
|
+
export type Protocol = 'http' | 'https';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Identifies the transport implementation used by the server.
|
|
28
|
+
*/
|
|
29
|
+
export type Transport = 'h1' | 'h1s' | 'h2c' | 'h2';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Represents the connection options accepted by supported transports.
|
|
33
|
+
*/
|
|
34
|
+
export type ServerConnectionOptions = http.ServerOptions | https.ServerOptions | http2.ServerOptions | http2.SecureServerOptions;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Represents the lifecycle states of the server.
|
|
38
|
+
*/
|
|
39
|
+
export type ServerState = 'idle' | 'starting' | 'listening' | 'stopping' | 'closed' | 'error';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents the current state of a response body.
|
|
43
|
+
*/
|
|
44
|
+
export type BodyKind = 'none' | 'buffer' | 'stream';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Represents a function that delegates execution to the next middleware layer.
|
|
48
|
+
*/
|
|
49
|
+
export type NextFunction = () => void | Promise<void>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Represents an exchange middleware function.
|
|
53
|
+
*/
|
|
54
|
+
export type MiddlewareFunction = (
|
|
55
|
+
exchange: Exchange,
|
|
56
|
+
next: NextFunction,
|
|
57
|
+
) => void | Promise<void>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Represents a handler invoked when no route matches.
|
|
61
|
+
*/
|
|
62
|
+
export type NotFoundHandler = (exchange: Exchange) => void | Promise<void>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Represents a handler invoked when an error propagates during processing.
|
|
66
|
+
*/
|
|
67
|
+
export type SystemErrorHandler = (
|
|
68
|
+
error: Error,
|
|
69
|
+
exchange: Exchange,
|
|
70
|
+
) => void | Promise<void>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Represents an event name supported by the server.
|
|
74
|
+
*/
|
|
75
|
+
export type EventName = 'listen' | 'close' | 'error' | 'exchange:start' | 'exchange:end' | 'exchange:error';
|
|
76
|
+
|
|
77
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
78
|
+
// VALUE OBJECTS
|
|
79
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
80
|
+
|
|
81
|
+
export interface AddressInfo {
|
|
82
|
+
address: string;
|
|
83
|
+
port: number;
|
|
84
|
+
family: string;
|
|
85
|
+
displayHost: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Represents the network address of an HTTP server.
|
|
90
|
+
*
|
|
91
|
+
* Instances are produced by the runtime and exposed on the `listen` event.
|
|
92
|
+
* They are not meant to be constructed by consumers.
|
|
93
|
+
*/
|
|
94
|
+
export interface Address {
|
|
95
|
+
readonly address: string;
|
|
96
|
+
readonly port: number;
|
|
97
|
+
readonly family: string;
|
|
98
|
+
readonly displayHost: string;
|
|
99
|
+
toObject(): AddressInfo;
|
|
100
|
+
toJSON(): AddressInfo;
|
|
101
|
+
toString(): string;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface EndpointData {
|
|
105
|
+
protocol: Protocol;
|
|
106
|
+
address: string;
|
|
107
|
+
port: number;
|
|
108
|
+
family: string;
|
|
109
|
+
displayHost: string;
|
|
110
|
+
displayUrl: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Represents a complete network endpoint.
|
|
115
|
+
*
|
|
116
|
+
* Instances are produced by the runtime and exposed on the `listen` event.
|
|
117
|
+
* They are not meant to be constructed by consumers.
|
|
118
|
+
*/
|
|
119
|
+
export interface Endpoint {
|
|
120
|
+
readonly protocol: Protocol;
|
|
121
|
+
readonly address: string;
|
|
122
|
+
readonly port: number;
|
|
123
|
+
readonly family: string;
|
|
124
|
+
readonly displayHost: string;
|
|
125
|
+
readonly displayUrl: string;
|
|
126
|
+
toObject(): EndpointData;
|
|
127
|
+
toJSON(): EndpointData;
|
|
128
|
+
toString(): string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
132
|
+
// REQUEST
|
|
133
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Immutable, case-insensitive view of incoming HTTP request headers.
|
|
137
|
+
*/
|
|
138
|
+
export interface RequestHeaders {
|
|
139
|
+
get(name: string): string | string[] | undefined;
|
|
140
|
+
has(name: string): boolean;
|
|
141
|
+
getNames(): string[];
|
|
142
|
+
entries(): IterableIterator<[string, string | string[] | undefined]>;
|
|
143
|
+
[Symbol.iterator](): IterableIterator<[string, string | string[] | undefined]>;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Represents an incoming HTTP request.
|
|
148
|
+
*
|
|
149
|
+
* Instances are produced by the runtime and exposed as `exchange.request`.
|
|
150
|
+
*/
|
|
151
|
+
export interface Request {
|
|
152
|
+
readonly pathname: string;
|
|
153
|
+
readonly method: string;
|
|
154
|
+
readonly url: string | undefined;
|
|
155
|
+
readonly headers: RequestHeaders;
|
|
156
|
+
readonly ip: string | undefined;
|
|
157
|
+
readonly hostname: string;
|
|
158
|
+
readonly query: URLSearchParams;
|
|
159
|
+
readonly contentType: string | null;
|
|
160
|
+
readonly mediaType: string | null;
|
|
161
|
+
readonly protocol: Protocol;
|
|
162
|
+
readonly isSecure: boolean;
|
|
163
|
+
readonly httpVersion: string | undefined;
|
|
164
|
+
getHeader(name: string): string | string[] | undefined;
|
|
165
|
+
body(): Promise<unknown>;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
169
|
+
// RESPONSE
|
|
170
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Represents an outgoing HTTP response.
|
|
174
|
+
*
|
|
175
|
+
* Instances are produced by the runtime and exposed as `exchange.response`.
|
|
176
|
+
*/
|
|
177
|
+
export interface Response {
|
|
178
|
+
readonly statusCode: number;
|
|
179
|
+
readonly statusText: string;
|
|
180
|
+
readonly isCommitted: boolean;
|
|
181
|
+
readonly bodyKind: BodyKind;
|
|
182
|
+
readonly bodyLength: number | undefined;
|
|
183
|
+
|
|
184
|
+
status(code: number): this;
|
|
185
|
+
setHeader(name: string, value: string | number | (string | number)[]): this;
|
|
186
|
+
setHeaders(
|
|
187
|
+
headers: Record<string, string | number | (string | number)[]>,
|
|
188
|
+
): this;
|
|
189
|
+
appendHeader(name: string, value: string | number): this;
|
|
190
|
+
getHeader(name: string): string | number | (string | number)[] | undefined;
|
|
191
|
+
hasHeader(name: string): boolean;
|
|
192
|
+
removeHeader(name: string): this;
|
|
193
|
+
getHeaders(): Readonly<Record<string, string | number | (string | number)[]>>;
|
|
194
|
+
|
|
195
|
+
json(data: unknown): this;
|
|
196
|
+
html(content: string): this;
|
|
197
|
+
text(content: string): this;
|
|
198
|
+
send(body?: string | Uint8Array): this;
|
|
199
|
+
stream(stream: stream.Readable, contentType?: string): this;
|
|
200
|
+
redirect(url: string, statusCode?: number): this;
|
|
201
|
+
|
|
202
|
+
vary(...fields: string[]): this;
|
|
203
|
+
cache(seconds: number): this;
|
|
204
|
+
noCache(): this;
|
|
205
|
+
|
|
206
|
+
end(): this;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
210
|
+
// EXCHANGE
|
|
211
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
212
|
+
|
|
213
|
+
export interface ExchangeTiming {
|
|
214
|
+
startedAt: number;
|
|
215
|
+
endedAt?: number;
|
|
216
|
+
duration?: number;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface ExchangeStartInfo {
|
|
220
|
+
id: string;
|
|
221
|
+
traceId: string;
|
|
222
|
+
request: { method: string; pathname: string };
|
|
223
|
+
timing: { startedAt: number };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export interface ExchangeEndInfo {
|
|
227
|
+
id: string;
|
|
228
|
+
traceId: string;
|
|
229
|
+
request: { method: string; pathname: string };
|
|
230
|
+
outcome: 'success' | 'error';
|
|
231
|
+
timing: ExchangeTiming;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface ExchangeErrorInfo {
|
|
235
|
+
id: string;
|
|
236
|
+
traceId: string;
|
|
237
|
+
error: Error;
|
|
238
|
+
request: { method: string; pathname: string };
|
|
239
|
+
timing: ExchangeTiming;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Represents a single HTTP transaction.
|
|
244
|
+
*
|
|
245
|
+
* Instances are passed to middleware functions and to `notFound` /
|
|
246
|
+
* `systemError` handlers. They are not meant to be constructed by consumers.
|
|
247
|
+
*/
|
|
248
|
+
export interface Exchange {
|
|
249
|
+
readonly request: Request;
|
|
250
|
+
readonly response: Response;
|
|
251
|
+
readonly state: Record<string, unknown>;
|
|
252
|
+
readonly id: string;
|
|
253
|
+
readonly traceId: string;
|
|
254
|
+
readonly spanId: string;
|
|
255
|
+
readonly signal: AbortSignal;
|
|
256
|
+
readonly startedAt: number;
|
|
257
|
+
abort(): void;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
261
|
+
// IPC
|
|
262
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
263
|
+
|
|
264
|
+
export type IPCHandler<T = unknown, R = unknown> = (
|
|
265
|
+
data: T,
|
|
266
|
+
) => R | Promise<R>;
|
|
267
|
+
|
|
268
|
+
export type IPCEventListener<T = unknown> = (data: T) => void;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Owns the IPC subsystem and its application-facing API.
|
|
272
|
+
*
|
|
273
|
+
* Accessible through `server.ipc` while the server is listening.
|
|
274
|
+
*/
|
|
275
|
+
export interface IPCMain {
|
|
276
|
+
handle<T = unknown, R = unknown>(
|
|
277
|
+
channel: string,
|
|
278
|
+
handler: IPCHandler<T, R>,
|
|
279
|
+
): this;
|
|
280
|
+
removeHandler(channel: string): this;
|
|
281
|
+
on<T = unknown>(channel: string, listener: IPCEventListener<T>): this;
|
|
282
|
+
off<T = unknown>(channel: string, listener: IPCEventListener<T>): this;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
286
|
+
// CONFIGURATION INPUTS
|
|
287
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
288
|
+
|
|
289
|
+
export interface ListenOptionsInput {
|
|
290
|
+
port?: number;
|
|
291
|
+
host?: string;
|
|
292
|
+
backlog?: number;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export interface RequestOptionsInput {
|
|
296
|
+
bodyLimit?: number;
|
|
297
|
+
trustProxy?: boolean | number;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface ResponseOptionsInput {
|
|
301
|
+
etag?: boolean;
|
|
302
|
+
defaultCharset?: string;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export interface StaticOptionsInput {
|
|
306
|
+
root: string;
|
|
307
|
+
index?: readonly string[];
|
|
308
|
+
maxAge?: number;
|
|
309
|
+
etag?: boolean;
|
|
310
|
+
lastModified?: boolean;
|
|
311
|
+
fallthrough?: boolean;
|
|
312
|
+
extensions?: readonly string[];
|
|
313
|
+
dotfiles?: boolean;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export interface CORSOptionsInput {
|
|
317
|
+
origin?: true | string | readonly string[];
|
|
318
|
+
methods?: readonly string[];
|
|
319
|
+
allowedHeaders?: readonly string[];
|
|
320
|
+
exposedHeaders?: readonly string[];
|
|
321
|
+
credentials?: boolean;
|
|
322
|
+
maxAge?: number;
|
|
323
|
+
preflightContinue?: boolean;
|
|
324
|
+
optionsSuccessStatus?: number;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export interface SecurityHeadersOptionsInput {
|
|
328
|
+
contentSecurityPolicy?: string | false;
|
|
329
|
+
crossOriginEmbedderPolicy?: string | false;
|
|
330
|
+
crossOriginOpenerPolicy?: string | false;
|
|
331
|
+
crossOriginResourcePolicy?: string | false;
|
|
332
|
+
originAgentCluster?: string | false;
|
|
333
|
+
permissionsPolicy?: string | false;
|
|
334
|
+
referrerPolicy?: string | false;
|
|
335
|
+
strictTransportSecurity?: string | false;
|
|
336
|
+
xContentTypeOptions?: string | false;
|
|
337
|
+
xDnsPrefetchControl?: string | false;
|
|
338
|
+
xDownloadOptions?: string | false;
|
|
339
|
+
xFrameOptions?: string | false;
|
|
340
|
+
xPermittedCrossDomainPolicies?: string | false;
|
|
341
|
+
xXssProtection?: string | false;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export interface RateLimitOptionsInput {
|
|
345
|
+
windowMs?: number;
|
|
346
|
+
max?: number;
|
|
347
|
+
statusCode?: number;
|
|
348
|
+
message?: Record<string, unknown>;
|
|
349
|
+
standardHeaders?: boolean;
|
|
350
|
+
legacyHeaders?: boolean;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export interface CookieParserOptionsInput {
|
|
354
|
+
decode?: boolean;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
export interface CookieSessionOptionsInput {
|
|
358
|
+
name?: string;
|
|
359
|
+
keys: readonly string[];
|
|
360
|
+
maxAge?: number;
|
|
361
|
+
path?: string;
|
|
362
|
+
domain?: string;
|
|
363
|
+
secure?: boolean;
|
|
364
|
+
httpOnly?: boolean;
|
|
365
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
366
|
+
overwrite?: boolean;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export interface CookieOptionsInput {
|
|
370
|
+
parser?: CookieParserOptionsInput;
|
|
371
|
+
session?: CookieSessionOptionsInput;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export interface CSRFOptionsInput {
|
|
375
|
+
cookieName?: string;
|
|
376
|
+
headerName?: string;
|
|
377
|
+
safeMethods?: readonly string[];
|
|
378
|
+
tokenBytes?: number;
|
|
379
|
+
path?: string;
|
|
380
|
+
domain?: string;
|
|
381
|
+
secure?: boolean;
|
|
382
|
+
sameSite?: 'Strict' | 'Lax' | 'None';
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export interface CompressOptionsInput {
|
|
386
|
+
threshold?: number;
|
|
387
|
+
level?: number;
|
|
388
|
+
types?: readonly string[];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
export interface ServerConfigurationOptionsInputBase {
|
|
392
|
+
listen?: ListenOptionsInput;
|
|
393
|
+
request?: RequestOptionsInput;
|
|
394
|
+
response?: ResponseOptionsInput;
|
|
395
|
+
static?: StaticOptionsInput;
|
|
396
|
+
cors?: CORSOptionsInput;
|
|
397
|
+
securityHeaders?: SecurityHeadersOptionsInput;
|
|
398
|
+
rateLimit?: RateLimitOptionsInput;
|
|
399
|
+
cookie?: CookieOptionsInput;
|
|
400
|
+
csrf?: CSRFOptionsInput;
|
|
401
|
+
compress?: CompressOptionsInput;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
405
|
+
// SERVER CONFIGURATIONS
|
|
406
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
407
|
+
export interface ListenOptions {
|
|
408
|
+
port: number | undefined;
|
|
409
|
+
host: string | undefined;
|
|
410
|
+
backlog: number | undefined;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
export interface RequestOptions {
|
|
414
|
+
bodyLimit: number | undefined;
|
|
415
|
+
trustProxy: boolean | number | undefined;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export interface ResponseOptions {
|
|
419
|
+
etag: boolean | undefined;
|
|
420
|
+
defaultCharset: string | undefined;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface StaticOptions {
|
|
424
|
+
root: string;
|
|
425
|
+
index: readonly string[];
|
|
426
|
+
maxAge: number;
|
|
427
|
+
etag: boolean;
|
|
428
|
+
lastModified: boolean;
|
|
429
|
+
fallthrough: boolean;
|
|
430
|
+
extensions: readonly string[] | undefined;
|
|
431
|
+
dotfiles: boolean;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export interface CORSOptions {
|
|
435
|
+
origin: true | string | readonly string[];
|
|
436
|
+
methods: readonly string[];
|
|
437
|
+
allowedHeaders: readonly string[] | undefined;
|
|
438
|
+
exposedHeaders: readonly string[] | undefined;
|
|
439
|
+
credentials: boolean;
|
|
440
|
+
maxAge: number | undefined;
|
|
441
|
+
preflightContinue: boolean;
|
|
442
|
+
optionsSuccessStatus: number;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export interface SecurityHeadersOptions {
|
|
446
|
+
contentSecurityPolicy: string | false;
|
|
447
|
+
crossOriginEmbedderPolicy: string | false;
|
|
448
|
+
crossOriginOpenerPolicy: string | false;
|
|
449
|
+
crossOriginResourcePolicy: string | false;
|
|
450
|
+
originAgentCluster: string | false;
|
|
451
|
+
permissionsPolicy: string | false;
|
|
452
|
+
referrerPolicy: string | false;
|
|
453
|
+
strictTransportSecurity: string | false;
|
|
454
|
+
xContentTypeOptions: string | false;
|
|
455
|
+
xDnsPrefetchControl: string | false;
|
|
456
|
+
xDownloadOptions: string | false;
|
|
457
|
+
xFrameOptions: string | false;
|
|
458
|
+
xPermittedCrossDomainPolicies: string | false;
|
|
459
|
+
xXssProtection: string | false;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
export interface RateLimitOptions {
|
|
463
|
+
windowMs: number;
|
|
464
|
+
max: number;
|
|
465
|
+
statusCode: number;
|
|
466
|
+
message: Readonly<Record<string, unknown>>;
|
|
467
|
+
standardHeaders: boolean;
|
|
468
|
+
legacyHeaders: boolean;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
export interface CookieParserOptions {
|
|
472
|
+
decode: boolean;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export interface CookieSessionOptions {
|
|
476
|
+
name: string;
|
|
477
|
+
keys: readonly string[];
|
|
478
|
+
maxAge: number | undefined;
|
|
479
|
+
path: string;
|
|
480
|
+
domain: string | undefined;
|
|
481
|
+
secure: boolean;
|
|
482
|
+
httpOnly: boolean;
|
|
483
|
+
sameSite: 'Strict' | 'Lax' | 'None';
|
|
484
|
+
overwrite: boolean;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export interface CookieOptions {
|
|
488
|
+
parser: CookieParserOptions;
|
|
489
|
+
session?: CookieSessionOptions;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export interface CSRFOptions {
|
|
493
|
+
cookieName: string;
|
|
494
|
+
headerName: string;
|
|
495
|
+
safeMethods: readonly string[];
|
|
496
|
+
tokenBytes: number;
|
|
497
|
+
path: string;
|
|
498
|
+
domain: string | undefined;
|
|
499
|
+
secure: boolean;
|
|
500
|
+
sameSite: 'Strict' | 'Lax' | 'None';
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
export interface CompressOptions {
|
|
504
|
+
threshold: number;
|
|
505
|
+
level: number;
|
|
506
|
+
types: readonly string[] | undefined;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
// ── ServerConfigurationObject ─────────────────────────────────────────────
|
|
510
|
+
export interface ServerConfigurationObject {
|
|
511
|
+
connection?: ServerConnectionOptions;
|
|
512
|
+
listen?: ListenOptions;
|
|
513
|
+
request?: RequestOptions;
|
|
514
|
+
response?: ResponseOptions;
|
|
515
|
+
static?: StaticOptions;
|
|
516
|
+
cors?: CORSOptions;
|
|
517
|
+
securityHeaders?: SecurityHeadersOptions;
|
|
518
|
+
rateLimit?: RateLimitOptions;
|
|
519
|
+
cookie?: CookieOptions;
|
|
520
|
+
csrf?: CSRFOptions;
|
|
521
|
+
compress?: CompressOptions;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Base contract shared by all server configurations.
|
|
526
|
+
*/
|
|
527
|
+
export interface ServerConfiguration {
|
|
528
|
+
readonly transport: Transport;
|
|
529
|
+
readonly protocol: Protocol;
|
|
530
|
+
readonly connection: ServerConnectionOptions | undefined;
|
|
531
|
+
toObject(): ServerConfigurationObject;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export interface HttpServerConfigurationOptions
|
|
535
|
+
extends ServerConfigurationOptionsInputBase {
|
|
536
|
+
connection?: http.ServerOptions;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
export interface HttpsServerConfigurationOptions
|
|
540
|
+
extends ServerConfigurationOptionsInputBase {
|
|
541
|
+
connection?: https.ServerOptions;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export interface Http2CleartextServerConfigurationOptions
|
|
545
|
+
extends ServerConfigurationOptionsInputBase {
|
|
546
|
+
connection?: http2.ServerOptions;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
export interface Http2SecureServerConfigurationOptions
|
|
550
|
+
extends ServerConfigurationOptionsInputBase {
|
|
551
|
+
connection?: http2.SecureServerOptions;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
export declare class HttpServerConfiguration implements ServerConfiguration {
|
|
555
|
+
constructor(options?: HttpServerConfigurationOptions);
|
|
556
|
+
readonly transport: 'h1';
|
|
557
|
+
readonly protocol: 'http';
|
|
558
|
+
readonly connection: http.ServerOptions | undefined;
|
|
559
|
+
toObject(): ServerConfigurationObject;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
export declare class HttpsServerConfiguration implements ServerConfiguration {
|
|
563
|
+
constructor(options?: HttpsServerConfigurationOptions);
|
|
564
|
+
readonly transport: 'h1s';
|
|
565
|
+
readonly protocol: 'https';
|
|
566
|
+
readonly connection: https.ServerOptions | undefined;
|
|
567
|
+
toObject(): ServerConfigurationObject;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
export declare class Http2CleartextServerConfiguration
|
|
571
|
+
implements ServerConfiguration
|
|
572
|
+
{
|
|
573
|
+
constructor(options?: Http2CleartextServerConfigurationOptions);
|
|
574
|
+
readonly transport: 'h2c';
|
|
575
|
+
readonly protocol: 'http';
|
|
576
|
+
readonly connection: http2.ServerOptions | undefined;
|
|
577
|
+
toObject(): ServerConfigurationObject;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export declare class Http2SecureServerConfiguration
|
|
581
|
+
implements ServerConfiguration
|
|
582
|
+
{
|
|
583
|
+
constructor(options?: Http2SecureServerConfigurationOptions);
|
|
584
|
+
readonly transport: 'h2';
|
|
585
|
+
readonly protocol: 'https';
|
|
586
|
+
readonly connection: http2.SecureServerOptions | undefined;
|
|
587
|
+
toObject(): ServerConfigurationObject;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
591
|
+
// ROUTER
|
|
592
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
593
|
+
|
|
594
|
+
export declare class Router {
|
|
595
|
+
constructor();
|
|
596
|
+
|
|
597
|
+
use(...middlewares: MiddlewareFunction[]): this;
|
|
598
|
+
all(pathnamePattern: string, ...middlewares: MiddlewareFunction[]): this;
|
|
599
|
+
get(pathnamePattern: string, ...middlewares: MiddlewareFunction[]): this;
|
|
600
|
+
post(pathnamePattern: string, ...middlewares: MiddlewareFunction[]): this;
|
|
601
|
+
put(pathnamePattern: string, ...middlewares: MiddlewareFunction[]): this;
|
|
602
|
+
patch(pathnamePattern: string, ...middlewares: MiddlewareFunction[]): this;
|
|
603
|
+
delete(pathnamePattern: string, ...middlewares: MiddlewareFunction[]): this;
|
|
604
|
+
head(pathnamePattern: string, ...middlewares: MiddlewareFunction[]): this;
|
|
605
|
+
trace(pathnamePattern: string, ...middlewares: MiddlewareFunction[]): this;
|
|
606
|
+
query(pathnamePattern: string, ...middlewares: MiddlewareFunction[]): this;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
610
|
+
// EVENTS
|
|
611
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
612
|
+
|
|
613
|
+
export interface ListenEventData {
|
|
614
|
+
endpoint: Endpoint;
|
|
615
|
+
address: Address;
|
|
616
|
+
elapsed: number;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
export interface CloseEventData {
|
|
620
|
+
elapsed: number;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
624
|
+
// SERVER
|
|
625
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
626
|
+
|
|
627
|
+
export declare class Server {
|
|
628
|
+
constructor(configuration: ServerConfiguration);
|
|
629
|
+
|
|
630
|
+
readonly state: ServerState;
|
|
631
|
+
readonly listening: boolean;
|
|
632
|
+
readonly ipc: IPCMain;
|
|
633
|
+
|
|
634
|
+
// ── Registration ─────────────────────────────────────────────────────────
|
|
635
|
+
use(
|
|
636
|
+
pathnamePattern: string | MiddlewareFunction,
|
|
637
|
+
...middlewares: MiddlewareFunction[]
|
|
638
|
+
): this;
|
|
639
|
+
get(
|
|
640
|
+
pathnamePattern: string | MiddlewareFunction,
|
|
641
|
+
...middlewares: MiddlewareFunction[]
|
|
642
|
+
): this;
|
|
643
|
+
post(
|
|
644
|
+
pathnamePattern: string | MiddlewareFunction,
|
|
645
|
+
...middlewares: MiddlewareFunction[]
|
|
646
|
+
): this;
|
|
647
|
+
put(
|
|
648
|
+
pathnamePattern: string | MiddlewareFunction,
|
|
649
|
+
...middlewares: MiddlewareFunction[]
|
|
650
|
+
): this;
|
|
651
|
+
patch(
|
|
652
|
+
pathnamePattern: string | MiddlewareFunction,
|
|
653
|
+
...middlewares: MiddlewareFunction[]
|
|
654
|
+
): this;
|
|
655
|
+
delete(
|
|
656
|
+
pathnamePattern: string | MiddlewareFunction,
|
|
657
|
+
...middlewares: MiddlewareFunction[]
|
|
658
|
+
): this;
|
|
659
|
+
head(
|
|
660
|
+
pathnamePattern: string | MiddlewareFunction,
|
|
661
|
+
...middlewares: MiddlewareFunction[]
|
|
662
|
+
): this;
|
|
663
|
+
trace(
|
|
664
|
+
pathnamePattern: string | MiddlewareFunction,
|
|
665
|
+
...middlewares: MiddlewareFunction[]
|
|
666
|
+
): this;
|
|
667
|
+
query(
|
|
668
|
+
pathnamePattern: string | MiddlewareFunction,
|
|
669
|
+
...middlewares: MiddlewareFunction[]
|
|
670
|
+
): this;
|
|
671
|
+
|
|
672
|
+
mount(pathnamePattern: string, router: Router): this;
|
|
673
|
+
notFound(handler: NotFoundHandler): this;
|
|
674
|
+
systemError(handler: SystemErrorHandler): this;
|
|
675
|
+
|
|
676
|
+
// ── Lifecycle ────────────────────────────────────────────────────────────
|
|
677
|
+
listen(): Promise<void>;
|
|
678
|
+
close(): Promise<void>;
|
|
679
|
+
|
|
680
|
+
// ── Events (typed overloads) ─────────────────────────────────────────────
|
|
681
|
+
on(event: 'listen', listener: (data: ListenEventData) => void): this;
|
|
682
|
+
on(event: 'close', listener: (data: CloseEventData) => void): this;
|
|
683
|
+
on(event: 'error', listener: (error: Error) => void): this;
|
|
684
|
+
on(event: 'exchange:start', listener: (data: ExchangeStartInfo) => void): this;
|
|
685
|
+
on(event: 'exchange:end', listener: (data: ExchangeEndInfo) => void): this;
|
|
686
|
+
on(event: 'exchange:error', listener: (data: ExchangeErrorInfo) => void): this;
|
|
687
|
+
on(event: EventName, listener: (data?: unknown) => void): this;
|
|
688
|
+
|
|
689
|
+
once(event: 'listen', listener: (data: ListenEventData) => void): this;
|
|
690
|
+
once(event: 'close', listener: (data: CloseEventData) => void): this;
|
|
691
|
+
once(event: 'error', listener: (error: Error) => void): this;
|
|
692
|
+
once(event: 'exchange:start', listener: (data: ExchangeStartInfo) => void): this;
|
|
693
|
+
once(event: 'exchange:end', listener: (data: ExchangeEndInfo) => void): this;
|
|
694
|
+
once(event: 'exchange:error', listener: (data: ExchangeErrorInfo) => void): this;
|
|
695
|
+
once(event: EventName, listener: (data?: unknown) => void): this;
|
|
696
|
+
|
|
697
|
+
off(event: 'listen', listener: (data: ListenEventData) => void): this;
|
|
698
|
+
off(event: 'close', listener: (data: CloseEventData) => void): this;
|
|
699
|
+
off(event: 'error', listener: (error: Error) => void): this;
|
|
700
|
+
off(event: 'exchange:start', listener: (data: ExchangeStartInfo) => void): this;
|
|
701
|
+
off(event: 'exchange:end', listener: (data: ExchangeEndInfo) => void): this;
|
|
702
|
+
off(event: 'exchange:error', listener: (data: ExchangeErrorInfo) => void): this;
|
|
703
|
+
off(event: EventName, listener: (data?: unknown) => void): this;
|
|
704
|
+
|
|
705
|
+
onListen(listener: (data: ListenEventData) => void): this;
|
|
706
|
+
onClose(listener: (data: CloseEventData) => void): this;
|
|
707
|
+
onError(listener: (error: Error) => void): this;
|
|
708
|
+
onExchangeStart(listener: (data: ExchangeStartInfo) => void): this;
|
|
709
|
+
onExchangeEnd(listener: (data: ExchangeEndInfo) => void): this;
|
|
710
|
+
onExchangeError(listener: (data: ExchangeErrorInfo) => void): this;
|
|
711
|
+
|
|
712
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
716
|
+
// DEFAULT EXPORT
|
|
717
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
718
|
+
|
|
719
|
+
export default Server;
|