@catbee/utils 0.0.8-rc.3 → 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/README.md +3 -2
- package/build/index.cjs +6912 -0
- package/build/index.d.ts +5284 -0
- package/build/index.mjs +6635 -0
- package/package.json +13 -292
- package/build/cjs/config.d.ts +0 -121
- package/build/cjs/config.js +0 -137
- package/build/cjs/index.d.ts +0 -26
- package/build/cjs/index.js +0 -68
- package/build/cjs/servers/server.builder.d.ts +0 -507
- package/build/cjs/servers/server.builder.js +0 -658
- package/build/cjs/servers/server.d.ts +0 -255
- package/build/cjs/servers/server.js +0 -970
- package/build/cjs/types/api-response.d.ts +0 -151
- package/build/cjs/types/api-response.js +0 -36
- package/build/cjs/types/index.d.ts +0 -124
- package/build/cjs/types/index.js +0 -25
- package/build/cjs/types/server.d.ts +0 -267
- package/build/cjs/types/server.js +0 -25
- package/build/cjs/utils/array.utils.d.ts +0 -167
- package/build/cjs/utils/array.utils.js +0 -363
- package/build/cjs/utils/async.utils.d.ts +0 -264
- package/build/cjs/utils/async.utils.js +0 -640
- package/build/cjs/utils/cache.utils.d.ts +0 -152
- package/build/cjs/utils/cache.utils.js +0 -298
- package/build/cjs/utils/context-store.utils.d.ts +0 -188
- package/build/cjs/utils/context-store.utils.js +0 -297
- package/build/cjs/utils/crypto.utils.d.ts +0 -159
- package/build/cjs/utils/crypto.utils.js +0 -295
- package/build/cjs/utils/date.utils.d.ts +0 -158
- package/build/cjs/utils/date.utils.js +0 -395
- package/build/cjs/utils/decorators.utils.d.ts +0 -511
- package/build/cjs/utils/decorators.utils.js +0 -1035
- package/build/cjs/utils/dir.utils.d.ts +0 -195
- package/build/cjs/utils/dir.utils.js +0 -500
- package/build/cjs/utils/env.utils.d.ts +0 -376
- package/build/cjs/utils/env.utils.js +0 -786
- package/build/cjs/utils/exception.utils.d.ts +0 -229
- package/build/cjs/utils/exception.utils.js +0 -408
- package/build/cjs/utils/fs.utils.d.ts +0 -163
- package/build/cjs/utils/fs.utils.js +0 -371
- package/build/cjs/utils/http-status-codes.d.ts +0 -265
- package/build/cjs/utils/http-status-codes.js +0 -297
- package/build/cjs/utils/id.utils.d.ts +0 -35
- package/build/cjs/utils/id.utils.js +0 -90
- package/build/cjs/utils/logger.utils.d.ts +0 -159
- package/build/cjs/utils/logger.utils.js +0 -350
- package/build/cjs/utils/middleware.utils.d.ts +0 -99
- package/build/cjs/utils/middleware.utils.js +0 -243
- package/build/cjs/utils/obj.utils.d.ts +0 -123
- package/build/cjs/utils/obj.utils.js +0 -428
- package/build/cjs/utils/performance.utils.d.ts +0 -135
- package/build/cjs/utils/performance.utils.js +0 -280
- package/build/cjs/utils/request.utils.d.ts +0 -85
- package/build/cjs/utils/request.utils.js +0 -199
- package/build/cjs/utils/response.utils.d.ts +0 -162
- package/build/cjs/utils/response.utils.js +0 -274
- package/build/cjs/utils/stream.utils.d.ts +0 -87
- package/build/cjs/utils/stream.utils.js +0 -217
- package/build/cjs/utils/string.utils.d.ts +0 -92
- package/build/cjs/utils/string.utils.js +0 -178
- package/build/cjs/utils/type.utils.d.ts +0 -89
- package/build/cjs/utils/type.utils.js +0 -195
- package/build/cjs/utils/url.utils.d.ts +0 -140
- package/build/cjs/utils/url.utils.js +0 -316
- package/build/cjs/utils/validate.utils.d.ts +0 -176
- package/build/cjs/utils/validate.utils.js +0 -344
- package/build/esm/config.d.ts +0 -121
- package/build/esm/config.js +0 -132
- package/build/esm/index.d.ts +0 -26
- package/build/esm/index.js +0 -49
- package/build/esm/servers/server.builder.d.ts +0 -507
- package/build/esm/servers/server.builder.js +0 -654
- package/build/esm/servers/server.d.ts +0 -255
- package/build/esm/servers/server.js +0 -963
- package/build/esm/types/api-response.d.ts +0 -151
- package/build/esm/types/api-response.js +0 -33
- package/build/esm/types/index.d.ts +0 -124
- package/build/esm/types/index.js +0 -24
- package/build/esm/types/server.d.ts +0 -267
- package/build/esm/types/server.js +0 -24
- package/build/esm/utils/array.utils.d.ts +0 -167
- package/build/esm/utils/array.utils.js +0 -344
- package/build/esm/utils/async.utils.d.ts +0 -264
- package/build/esm/utils/async.utils.js +0 -619
- package/build/esm/utils/cache.utils.d.ts +0 -152
- package/build/esm/utils/cache.utils.js +0 -294
- package/build/esm/utils/context-store.utils.d.ts +0 -188
- package/build/esm/utils/context-store.utils.js +0 -290
- package/build/esm/utils/crypto.utils.d.ts +0 -159
- package/build/esm/utils/crypto.utils.js +0 -278
- package/build/esm/utils/date.utils.d.ts +0 -158
- package/build/esm/utils/date.utils.js +0 -383
- package/build/esm/utils/decorators.utils.d.ts +0 -511
- package/build/esm/utils/decorators.utils.js +0 -1013
- package/build/esm/utils/dir.utils.d.ts +0 -195
- package/build/esm/utils/dir.utils.js +0 -476
- package/build/esm/utils/env.utils.d.ts +0 -376
- package/build/esm/utils/env.utils.js +0 -782
- package/build/esm/utils/exception.utils.d.ts +0 -229
- package/build/esm/utils/exception.utils.js +0 -382
- package/build/esm/utils/fs.utils.d.ts +0 -163
- package/build/esm/utils/fs.utils.js +0 -348
- package/build/esm/utils/http-status-codes.d.ts +0 -265
- package/build/esm/utils/http-status-codes.js +0 -294
- package/build/esm/utils/id.utils.d.ts +0 -35
- package/build/esm/utils/id.utils.js +0 -83
- package/build/esm/utils/logger.utils.d.ts +0 -159
- package/build/esm/utils/logger.utils.js +0 -304
- package/build/esm/utils/middleware.utils.d.ts +0 -99
- package/build/esm/utils/middleware.utils.js +0 -235
- package/build/esm/utils/obj.utils.d.ts +0 -123
- package/build/esm/utils/obj.utils.js +0 -412
- package/build/esm/utils/performance.utils.d.ts +0 -135
- package/build/esm/utils/performance.utils.js +0 -273
- package/build/esm/utils/request.utils.d.ts +0 -85
- package/build/esm/utils/request.utils.js +0 -190
- package/build/esm/utils/response.utils.d.ts +0 -162
- package/build/esm/utils/response.utils.js +0 -261
- package/build/esm/utils/stream.utils.d.ts +0 -87
- package/build/esm/utils/stream.utils.js +0 -209
- package/build/esm/utils/string.utils.d.ts +0 -92
- package/build/esm/utils/string.utils.js +0 -164
- package/build/esm/utils/type.utils.d.ts +0 -89
- package/build/esm/utils/type.utils.js +0 -186
- package/build/esm/utils/url.utils.d.ts +0 -140
- package/build/esm/utils/url.utils.js +0 -303
- package/build/esm/utils/validate.utils.d.ts +0 -176
- package/build/esm/utils/validate.utils.js +0 -319
|
@@ -1,507 +0,0 @@
|
|
|
1
|
-
import { ServerConfig } from '../types/server';
|
|
2
|
-
/**
|
|
3
|
-
* Builder class for creating and configuring an Express server configuration.
|
|
4
|
-
*
|
|
5
|
-
* This class provides a fluent interface to configure all aspects of the Express server
|
|
6
|
-
* including security settings, middleware, routing, and more.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* const serverConfig = new ServerConfigBuilder()
|
|
11
|
-
* .withPort(3000)
|
|
12
|
-
* .withHost('localhost')
|
|
13
|
-
* .enableCors()
|
|
14
|
-
* .enableHelmet()
|
|
15
|
-
* .build();
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
export declare const BUILD_MARKER: unique symbol;
|
|
19
|
-
export declare class ServerConfigBuilder {
|
|
20
|
-
private config;
|
|
21
|
-
/**
|
|
22
|
-
* Validates that a port number is valid and usable.
|
|
23
|
-
*
|
|
24
|
-
* @private
|
|
25
|
-
* @param port - The port number to validate
|
|
26
|
-
* @throws {Error} If port is not an integer or is outside the valid range (1-65535)
|
|
27
|
-
*/
|
|
28
|
-
private validatePort;
|
|
29
|
-
/**
|
|
30
|
-
* Sets the port the server will listen on.
|
|
31
|
-
*
|
|
32
|
-
* @param port - The port number (1-65535)
|
|
33
|
-
* @returns The builder instance for chaining
|
|
34
|
-
* @throws {Error} If port is invalid
|
|
35
|
-
* @default 3000 (can be overridden via PORT env variable)
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* builder.withPort(3000)
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
withPort(port: number): this;
|
|
43
|
-
/**
|
|
44
|
-
* Sets the hostname the server will bind to.
|
|
45
|
-
*
|
|
46
|
-
* @param host - The hostname (e.g., 'localhost', '0.0.0.0', '127.0.0.1')
|
|
47
|
-
* @returns The builder instance for chaining
|
|
48
|
-
* @default '0.0.0.0' (can be overridden via HOST env variable)
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* builder.withHost('0.0.0.0') // Listen on all interfaces
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
withHost(host: string): this;
|
|
56
|
-
/**
|
|
57
|
-
* Configures Cross-Origin Resource Sharing (CORS) for the server.
|
|
58
|
-
*
|
|
59
|
-
* @param opts - CORS options object or boolean (true to enable with defaults, false to disable)
|
|
60
|
-
* @returns The builder instance for chaining
|
|
61
|
-
* @default false (CORS is disabled by default)
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* // Enable CORS with default options
|
|
66
|
-
* builder.withCors(true)
|
|
67
|
-
*
|
|
68
|
-
* // Configure CORS with specific options
|
|
69
|
-
* builder.withCors({
|
|
70
|
-
* origin: ['https://example.com'],
|
|
71
|
-
* methods: ['GET', 'POST']
|
|
72
|
-
* })
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
withCors(opts: ServerConfig['cors']): this;
|
|
76
|
-
/**
|
|
77
|
-
* Enables CORS with default settings
|
|
78
|
-
*
|
|
79
|
-
* @returns The builder instance for chaining
|
|
80
|
-
*/
|
|
81
|
-
enableCors(): this;
|
|
82
|
-
/**
|
|
83
|
-
* Disables CORS
|
|
84
|
-
*
|
|
85
|
-
* @returns The builder instance for chaining
|
|
86
|
-
*/
|
|
87
|
-
disableCors(): this;
|
|
88
|
-
/**
|
|
89
|
-
* Configures the Helmet middleware for setting HTTP security headers.
|
|
90
|
-
*
|
|
91
|
-
* @param opts - Helmet options object or boolean (true to enable with defaults, false to disable)
|
|
92
|
-
* @returns The builder instance for chaining
|
|
93
|
-
* @default false (Helmet is disabled by default)
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* // Enable Helmet with default settings
|
|
98
|
-
* builder.withHelmet(true)
|
|
99
|
-
*
|
|
100
|
-
* // Configure Helmet with specific options
|
|
101
|
-
* builder.withHelmet({
|
|
102
|
-
* contentSecurityPolicy: false,
|
|
103
|
-
* xssFilter: true
|
|
104
|
-
* })
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
withHelmet(opts: ServerConfig['helmet']): this;
|
|
108
|
-
/**
|
|
109
|
-
* Enables Helmet with default settings
|
|
110
|
-
*
|
|
111
|
-
* @returns The builder instance for chaining
|
|
112
|
-
*/
|
|
113
|
-
enableHelmet(): this;
|
|
114
|
-
/**
|
|
115
|
-
* Disables Helmet
|
|
116
|
-
*
|
|
117
|
-
* @returns The builder instance for chaining
|
|
118
|
-
*/
|
|
119
|
-
disableHelmet(): this;
|
|
120
|
-
/**
|
|
121
|
-
* Configures response compression middleware.
|
|
122
|
-
*
|
|
123
|
-
* @param opts - Compression options object or boolean (true to enable with defaults, false to disable)
|
|
124
|
-
* @returns The builder instance for chaining
|
|
125
|
-
* @default false (Compression is disabled by default)
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```typescript
|
|
129
|
-
* // Enable compression with default settings
|
|
130
|
-
* builder.withCompression(true)
|
|
131
|
-
*
|
|
132
|
-
* // Configure compression with specific options
|
|
133
|
-
* builder.withCompression({
|
|
134
|
-
* level: 6,
|
|
135
|
-
* threshold: 1024
|
|
136
|
-
* })
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
withCompression(opts: ServerConfig['compression']): this;
|
|
140
|
-
/**
|
|
141
|
-
* Enables compression with default settings
|
|
142
|
-
*
|
|
143
|
-
* @returns The builder instance for chaining
|
|
144
|
-
*/
|
|
145
|
-
enableCompression(): this;
|
|
146
|
-
/**
|
|
147
|
-
* Disables compression
|
|
148
|
-
*
|
|
149
|
-
* @returns The builder instance for chaining
|
|
150
|
-
*/
|
|
151
|
-
disableCompression(): this;
|
|
152
|
-
/**
|
|
153
|
-
* Configures rate limiting to protect against brute-force attacks.
|
|
154
|
-
*
|
|
155
|
-
* @param opts - Rate limit configuration options
|
|
156
|
-
* @returns The builder instance for chaining
|
|
157
|
-
* @default { enable: false, windowMs: 15 * 60 * 1000, max: 100, message: 'Too many requests', standardHeaders: true, legacyHeaders: false }
|
|
158
|
-
*
|
|
159
|
-
* @example
|
|
160
|
-
* ```typescript
|
|
161
|
-
* builder.withRateLimit({
|
|
162
|
-
* enable: true,
|
|
163
|
-
* windowMs: 15 * 60 * 1000, // 15 minutes
|
|
164
|
-
* max: 100 // limit each IP to 100 requests per windowMs
|
|
165
|
-
* })
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
withRateLimit(opts: Partial<ServerConfig['rateLimit']>): this;
|
|
169
|
-
/**
|
|
170
|
-
* Enables rate limiting with default or custom settings
|
|
171
|
-
*
|
|
172
|
-
* @param opts - Optional rate limit configuration (max requests, window, etc.)
|
|
173
|
-
* @returns The builder instance for chaining
|
|
174
|
-
*/
|
|
175
|
-
enableRateLimit(opts?: Omit<Partial<NonNullable<ServerConfig['rateLimit']>>, 'enable'>): this;
|
|
176
|
-
/**
|
|
177
|
-
* Disables rate limiting
|
|
178
|
-
*
|
|
179
|
-
* @returns The builder instance for chaining
|
|
180
|
-
*/
|
|
181
|
-
disableRateLimit(): this;
|
|
182
|
-
/**
|
|
183
|
-
* Configures HTTP request logging middleware.
|
|
184
|
-
*
|
|
185
|
-
* @param opts - Request logging configuration options
|
|
186
|
-
* @returns The builder instance for chaining
|
|
187
|
-
* @default { enable: true in dev/false in prod, ignorePaths: ['/healthz', '/favicon.ico', '/metrics', '/docs', '/.well-known'], skipNotFoundRoutes: false }
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```typescript
|
|
191
|
-
* builder.withRequestLogging({
|
|
192
|
-
* enable: true,
|
|
193
|
-
* ignorePaths: ['/health', '/metrics'],
|
|
194
|
-
* skipNotFoundRoutes: true
|
|
195
|
-
* })
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
withRequestLogging(opts: Partial<NonNullable<ServerConfig['requestLogging']>>): this;
|
|
199
|
-
/**
|
|
200
|
-
* Enables request logging with default or custom settings
|
|
201
|
-
*
|
|
202
|
-
* @param opts - Optional request logging configuration
|
|
203
|
-
* @returns The builder instance for chaining
|
|
204
|
-
*/
|
|
205
|
-
enableRequestLogging(opts?: Omit<Partial<NonNullable<ServerConfig['requestLogging']>>, 'enable'>): this;
|
|
206
|
-
/**
|
|
207
|
-
* Disables request logging
|
|
208
|
-
*
|
|
209
|
-
* @returns The builder instance for chaining
|
|
210
|
-
*/
|
|
211
|
-
disableRequestLogging(): this;
|
|
212
|
-
/**
|
|
213
|
-
* Configures server metrics collection and endpoints.
|
|
214
|
-
*
|
|
215
|
-
* @param opts - Metrics configuration options
|
|
216
|
-
* @returns The builder instance for chaining
|
|
217
|
-
* @default { enable: false, path: '/metrics', withGlobalPrefix: false }
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```typescript
|
|
221
|
-
* builder.withMetrics({
|
|
222
|
-
* enable: true,
|
|
223
|
-
* path: '/metrics'
|
|
224
|
-
* })
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
withMetrics(opts: Partial<NonNullable<ServerConfig['metrics']>>): this;
|
|
228
|
-
/**
|
|
229
|
-
* Enables Prometheus metrics collection and endpoint
|
|
230
|
-
*
|
|
231
|
-
* @param opts - Optional metrics configuration
|
|
232
|
-
* @returns The builder instance for chaining
|
|
233
|
-
*/
|
|
234
|
-
enableMetrics(opts?: Omit<Partial<NonNullable<ServerConfig['metrics']>>, 'enable'>): this;
|
|
235
|
-
/**
|
|
236
|
-
* Disables Prometheus metrics
|
|
237
|
-
*
|
|
238
|
-
* @returns The builder instance for chaining
|
|
239
|
-
*/
|
|
240
|
-
disableMetrics(): this;
|
|
241
|
-
/**
|
|
242
|
-
* Configures server health check endpoint.
|
|
243
|
-
*
|
|
244
|
-
* @param opts - Health check configuration options
|
|
245
|
-
* @returns The builder instance for chaining
|
|
246
|
-
* @default { path: '/healthz', detailed: true, withGlobalPrefix: false }
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* ```typescript
|
|
250
|
-
* builder.withHealthCheck({
|
|
251
|
-
* path: '/health',
|
|
252
|
-
* detailed: true
|
|
253
|
-
* })
|
|
254
|
-
* ```
|
|
255
|
-
*/
|
|
256
|
-
withHealthCheck(opts: Partial<NonNullable<ServerConfig['healthCheck']>>): this;
|
|
257
|
-
/**
|
|
258
|
-
* Configures OpenAPI/Swagger documentation for the API.
|
|
259
|
-
*
|
|
260
|
-
* @param opts - OpenAPI configuration options
|
|
261
|
-
* @returns The builder instance for chaining
|
|
262
|
-
* @default { enable: false, mountPath: '/docs', verbose: false, withGlobalPrefix: false }
|
|
263
|
-
*
|
|
264
|
-
* @example
|
|
265
|
-
* ```typescript
|
|
266
|
-
* builder.withOpenApi({
|
|
267
|
-
* enable: true,
|
|
268
|
-
* path: '/api-docs',
|
|
269
|
-
* filePath: './openapi.yaml'
|
|
270
|
-
* })
|
|
271
|
-
* ```
|
|
272
|
-
*/
|
|
273
|
-
withOpenApi(opts: Partial<NonNullable<ServerConfig['openApi']>>): this;
|
|
274
|
-
/**
|
|
275
|
-
* Enables OpenAPI documentation with required file path
|
|
276
|
-
*
|
|
277
|
-
* @param filePath - Path to OpenAPI specification file (required)
|
|
278
|
-
* @param opts - Optional OpenAPI configuration
|
|
279
|
-
* @returns The builder instance for chaining
|
|
280
|
-
*/
|
|
281
|
-
enableOpenApi(filePath: string, opts?: Omit<Partial<NonNullable<ServerConfig['openApi']>>, 'enable' | 'filePath'>): this;
|
|
282
|
-
/**
|
|
283
|
-
* Disables OpenAPI documentation
|
|
284
|
-
*
|
|
285
|
-
* @returns The builder instance for chaining
|
|
286
|
-
*/
|
|
287
|
-
disableOpenApi(): this;
|
|
288
|
-
/**
|
|
289
|
-
* Configures the server as a microservice with versioning.
|
|
290
|
-
*
|
|
291
|
-
* @param opts - Microservice configuration options including app name and service version
|
|
292
|
-
* @returns The builder instance for chaining
|
|
293
|
-
* @default { isMicroservice: false, appName: 'express_app' }
|
|
294
|
-
*
|
|
295
|
-
* @example
|
|
296
|
-
* ```typescript
|
|
297
|
-
* builder.withMicroService({
|
|
298
|
-
* appName: 'user-service',
|
|
299
|
-
* serviceVersion: {
|
|
300
|
-
* enable: true,
|
|
301
|
-
* version: '1.2.3'
|
|
302
|
-
* }
|
|
303
|
-
* })
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
withMicroService(opts: {
|
|
307
|
-
appName: NonNullable<ServerConfig['appName']>;
|
|
308
|
-
serviceVersion: Partial<NonNullable<ServerConfig['serviceVersion']>>;
|
|
309
|
-
}): this;
|
|
310
|
-
/**
|
|
311
|
-
* Configures the trust proxy settings to determine if X-Forwarded-* headers should be trusted.
|
|
312
|
-
*
|
|
313
|
-
* @param opts - Trust proxy configuration options
|
|
314
|
-
* @returns The builder instance for chaining
|
|
315
|
-
* @default false
|
|
316
|
-
*
|
|
317
|
-
* @example
|
|
318
|
-
* ```typescript
|
|
319
|
-
* // Trust proxy headers (useful when behind a load balancer)
|
|
320
|
-
* builder.withTrustProxy(true)
|
|
321
|
-
* ```
|
|
322
|
-
*/
|
|
323
|
-
withTrustProxy(opts: NonNullable<ServerConfig['trustProxy']>): this;
|
|
324
|
-
/**
|
|
325
|
-
* Configures the request ID middleware for tracing requests across services.
|
|
326
|
-
*
|
|
327
|
-
* @param opts - Request ID configuration options
|
|
328
|
-
* @returns The builder instance for chaining
|
|
329
|
-
* @default { headerName: 'x-request-id', exposeHeader: true }
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* ```typescript
|
|
333
|
-
* builder.withRequestId({
|
|
334
|
-
* headerName: 'X-Request-Id',
|
|
335
|
-
* generator: () => crypto.randomUUID()
|
|
336
|
-
* })
|
|
337
|
-
* ```
|
|
338
|
-
*/
|
|
339
|
-
withRequestId(opts: Partial<NonNullable<ServerConfig['requestId']>>): this;
|
|
340
|
-
/**
|
|
341
|
-
* Configures the response time middleware for measuring request processing times.
|
|
342
|
-
*
|
|
343
|
-
* @param opts - Response time configuration options
|
|
344
|
-
* @returns The builder instance for chaining
|
|
345
|
-
* @default { enable: false, addHeader: true, logOnComplete: false }
|
|
346
|
-
*
|
|
347
|
-
* @example
|
|
348
|
-
* ```typescript
|
|
349
|
-
* builder.withResponseTime({
|
|
350
|
-
* enable: true,
|
|
351
|
-
* addHeader: true,
|
|
352
|
-
* logOnComplete: true
|
|
353
|
-
* })
|
|
354
|
-
* ```
|
|
355
|
-
*/
|
|
356
|
-
withResponseTime(opts: Partial<NonNullable<ServerConfig['responseTime']>>): this;
|
|
357
|
-
/**
|
|
358
|
-
* Enables response time tracking with default or custom settings
|
|
359
|
-
*
|
|
360
|
-
* @param opts - Optional response time configuration
|
|
361
|
-
* @returns The builder instance for chaining
|
|
362
|
-
*/
|
|
363
|
-
enableResponseTime(opts?: Omit<Partial<NonNullable<ServerConfig['responseTime']>>, 'enable'>): this;
|
|
364
|
-
/**
|
|
365
|
-
* Disables response time tracking
|
|
366
|
-
*
|
|
367
|
-
* @returns The builder instance for chaining
|
|
368
|
-
*/
|
|
369
|
-
disableResponseTime(): this;
|
|
370
|
-
/**
|
|
371
|
-
* Configures the body parser middleware options for parsing request bodies.
|
|
372
|
-
*
|
|
373
|
-
* @param opts - Body parser configuration options
|
|
374
|
-
* @returns The builder instance for chaining
|
|
375
|
-
* @default { json: { limit: '1mb' }, urlencoded: { extended: true, limit: '1mb' } }
|
|
376
|
-
*
|
|
377
|
-
* @example
|
|
378
|
-
* ```typescript
|
|
379
|
-
* builder.withBodyParser({
|
|
380
|
-
* json: {
|
|
381
|
-
* limit: '1mb'
|
|
382
|
-
* },
|
|
383
|
-
* urlencoded: {
|
|
384
|
-
* extended: true,
|
|
385
|
-
* limit: '1mb'
|
|
386
|
-
* }
|
|
387
|
-
* })
|
|
388
|
-
* ```
|
|
389
|
-
*/
|
|
390
|
-
withBodyParser(opts: NonNullable<ServerConfig['bodyParser']>): this;
|
|
391
|
-
/**
|
|
392
|
-
* Configures cookie parsing middleware.
|
|
393
|
-
*
|
|
394
|
-
* @param opts - Cookie parser options or boolean (true to enable with defaults, false to disable)
|
|
395
|
-
* @returns The builder instance for chaining
|
|
396
|
-
* @default false
|
|
397
|
-
*
|
|
398
|
-
* @example
|
|
399
|
-
* ```typescript
|
|
400
|
-
* // Enable cookie parsing with default options
|
|
401
|
-
* builder.withCookies(true)
|
|
402
|
-
*
|
|
403
|
-
* // Enable cookie parsing with specific options
|
|
404
|
-
* builder.withCookies({
|
|
405
|
-
* secret: 'your-secret-key',
|
|
406
|
-
* secure: true
|
|
407
|
-
* })
|
|
408
|
-
* ```
|
|
409
|
-
*/
|
|
410
|
-
withCookies(opts: ServerConfig['cookieParser']): this;
|
|
411
|
-
/**
|
|
412
|
-
* Adds a static folder to serve files from.
|
|
413
|
-
*
|
|
414
|
-
* @param folder - Static folder configuration
|
|
415
|
-
* @returns The builder instance for chaining
|
|
416
|
-
*
|
|
417
|
-
* @example
|
|
418
|
-
* ```typescript
|
|
419
|
-
* builder.withStaticFolder({
|
|
420
|
-
* path: '/assets',
|
|
421
|
-
* directory: './public',
|
|
422
|
-
* options: { maxAge: '1d' }
|
|
423
|
-
* })
|
|
424
|
-
* ```
|
|
425
|
-
*/
|
|
426
|
-
withStaticFolder(folder: NonNullable<ServerConfig['staticFolders']>[number]): this;
|
|
427
|
-
/**
|
|
428
|
-
* Sets global headers to be included in all responses.
|
|
429
|
-
*
|
|
430
|
-
* @param headers - Object containing header name/value pairs or functions that return values
|
|
431
|
-
* @returns The builder instance for chaining
|
|
432
|
-
* @default {}
|
|
433
|
-
*
|
|
434
|
-
* @example
|
|
435
|
-
* ```typescript
|
|
436
|
-
* builder.withGlobalHeaders({
|
|
437
|
-
* 'X-Powered-By': 'Catbee',
|
|
438
|
-
* 'Server-Time': () => new Date().toISOString()
|
|
439
|
-
* })
|
|
440
|
-
* ```
|
|
441
|
-
*/
|
|
442
|
-
withGlobalHeaders(headers: NonNullable<ServerConfig['globalHeaders']>): this;
|
|
443
|
-
/**
|
|
444
|
-
* Sets a global prefix for all routes.
|
|
445
|
-
*
|
|
446
|
-
* @param prefix - The prefix to prepend to all routes (e.g., '/api/v1')
|
|
447
|
-
* @returns The builder instance for chaining
|
|
448
|
-
* @default '/'
|
|
449
|
-
*
|
|
450
|
-
* @example
|
|
451
|
-
* ```typescript
|
|
452
|
-
* builder.withGlobalPrefix('/api/v1')
|
|
453
|
-
* ```
|
|
454
|
-
*/
|
|
455
|
-
withGlobalPrefix(prefix: string): this;
|
|
456
|
-
/**
|
|
457
|
-
* Applies custom configuration overrides directly.
|
|
458
|
-
*
|
|
459
|
-
* @param overrides - Custom configuration options to merge
|
|
460
|
-
* @returns The builder instance for chaining
|
|
461
|
-
*
|
|
462
|
-
* @example
|
|
463
|
-
* ```typescript
|
|
464
|
-
* builder.withCustom({
|
|
465
|
-
* port: 8080,
|
|
466
|
-
* customMiddleware: myMiddlewareFunction
|
|
467
|
-
* })
|
|
468
|
-
* ```
|
|
469
|
-
*/
|
|
470
|
-
withCustom(overrides: Partial<ServerConfig>): this;
|
|
471
|
-
/**
|
|
472
|
-
* Configures HTTPS server options.
|
|
473
|
-
*
|
|
474
|
-
* @param opts - HTTPS configuration (key, cert, ca, passphrase, etc.)
|
|
475
|
-
* @returns The builder instance for chaining
|
|
476
|
-
*
|
|
477
|
-
* @example
|
|
478
|
-
* ```typescript
|
|
479
|
-
* builder.withHttps({
|
|
480
|
-
* key: './localhost-key.pem',
|
|
481
|
-
* cert: './localhost-cert.pem'
|
|
482
|
-
* })
|
|
483
|
-
* ```
|
|
484
|
-
*/
|
|
485
|
-
withHttps(opts: NonNullable<ServerConfig['https']>): this;
|
|
486
|
-
/**
|
|
487
|
-
* Builds and returns the final server configuration.
|
|
488
|
-
*
|
|
489
|
-
* This method merges the user-specified configuration with default values,
|
|
490
|
-
* ensures all sections with 'enable' flags are properly structured, and
|
|
491
|
-
* produces the final configuration to be used by the server.
|
|
492
|
-
*
|
|
493
|
-
* @returns The complete ServerConfig object
|
|
494
|
-
*
|
|
495
|
-
* @example
|
|
496
|
-
* ```typescript
|
|
497
|
-
* const config = new ServerConfigBuilder()
|
|
498
|
-
* .withPort(3000)
|
|
499
|
-
* .withHost('localhost')
|
|
500
|
-
* .withCors(true)
|
|
501
|
-
* .build();
|
|
502
|
-
* ```
|
|
503
|
-
*/
|
|
504
|
-
build(): Readonly<ServerConfig>;
|
|
505
|
-
private mergeConfig;
|
|
506
|
-
private setEnabled;
|
|
507
|
-
}
|