@catbee/utils 0.0.6 → 0.0.7
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 +51 -1106
- package/build/esm/config.d.ts +5 -13
- package/build/esm/config.js +0 -12
- package/build/esm/config.js.map +1 -1
- package/build/esm/servers/server.builder.d.ts +1 -118
- package/build/esm/servers/server.builder.js +0 -20
- package/build/esm/servers/server.builder.js.map +1 -1
- package/build/esm/servers/server.d.ts +2 -2
- package/build/esm/servers/server.js +3 -13
- package/build/esm/servers/server.js.map +1 -1
- package/build/esm/types/api-response.d.ts +28 -0
- package/build/esm/types/api-response.js +10 -1
- package/build/esm/types/api-response.js.map +1 -1
- package/build/esm/types/server.d.ts +0 -17
- package/build/esm/types/server.js.map +1 -1
- package/build/esm/utils/async.utils.d.ts +91 -0
- package/build/esm/utils/async.utils.js +244 -0
- package/build/esm/utils/async.utils.js.map +1 -1
- package/build/esm/utils/context-store.utils.d.ts +3 -0
- package/build/esm/utils/context-store.utils.js +9 -6
- package/build/esm/utils/context-store.utils.js.map +1 -1
- package/build/esm/utils/date.utils.d.ts +159 -0
- package/build/esm/utils/date.utils.js +389 -0
- package/build/esm/utils/date.utils.js.map +1 -0
- package/build/esm/utils/logger.utils.d.ts +3 -9
- package/build/esm/utils/logger.utils.js +3 -9
- package/build/esm/utils/logger.utils.js.map +1 -1
- package/build/esm/utils/middleware.utils.js +2 -1
- package/build/esm/utils/middleware.utils.js.map +1 -1
- package/build/esm/utils/performance.utils.d.ts +136 -0
- package/build/esm/utils/performance.utils.js +376 -0
- package/build/esm/utils/performance.utils.js.map +1 -0
- package/build/esm/utils/request.utils.d.ts +9 -0
- package/build/esm/utils/request.utils.js +32 -5
- package/build/esm/utils/request.utils.js.map +1 -1
- package/build/esm/utils/stream.utils.d.ts +88 -0
- package/build/esm/utils/stream.utils.js +284 -0
- package/build/esm/utils/stream.utils.js.map +1 -0
- package/build/esm/utils/type.utils.d.ts +90 -0
- package/build/esm/utils/type.utils.js +190 -0
- package/build/esm/utils/type.utils.js.map +1 -0
- package/build/esnext/config.d.ts +5 -13
- package/build/esnext/config.js +0 -12
- package/build/esnext/config.js.map +1 -1
- package/build/esnext/servers/server.builder.d.ts +1 -118
- package/build/esnext/servers/server.builder.js +0 -20
- package/build/esnext/servers/server.builder.js.map +1 -1
- package/build/esnext/servers/server.d.ts +2 -2
- package/build/esnext/servers/server.js +3 -13
- package/build/esnext/servers/server.js.map +1 -1
- package/build/esnext/types/api-response.d.ts +28 -0
- package/build/esnext/types/api-response.js +10 -1
- package/build/esnext/types/api-response.js.map +1 -1
- package/build/esnext/types/server.d.ts +0 -17
- package/build/esnext/types/server.js.map +1 -1
- package/build/esnext/utils/async.utils.d.ts +91 -0
- package/build/esnext/utils/async.utils.js +190 -0
- package/build/esnext/utils/async.utils.js.map +1 -1
- package/build/esnext/utils/context-store.utils.d.ts +3 -0
- package/build/esnext/utils/context-store.utils.js +9 -6
- package/build/esnext/utils/context-store.utils.js.map +1 -1
- package/build/esnext/utils/date.utils.d.ts +159 -0
- package/build/esnext/utils/date.utils.js +384 -0
- package/build/esnext/utils/date.utils.js.map +1 -0
- package/build/esnext/utils/logger.utils.d.ts +3 -9
- package/build/esnext/utils/logger.utils.js +3 -9
- package/build/esnext/utils/logger.utils.js.map +1 -1
- package/build/esnext/utils/middleware.utils.js +2 -1
- package/build/esnext/utils/middleware.utils.js.map +1 -1
- package/build/esnext/utils/performance.utils.d.ts +136 -0
- package/build/esnext/utils/performance.utils.js +271 -0
- package/build/esnext/utils/performance.utils.js.map +1 -0
- package/build/esnext/utils/request.utils.d.ts +9 -0
- package/build/esnext/utils/request.utils.js +23 -5
- package/build/esnext/utils/request.utils.js.map +1 -1
- package/build/esnext/utils/stream.utils.d.ts +88 -0
- package/build/esnext/utils/stream.utils.js +210 -0
- package/build/esnext/utils/stream.utils.js.map +1 -0
- package/build/esnext/utils/type.utils.d.ts +90 -0
- package/build/esnext/utils/type.utils.js +187 -0
- package/build/esnext/utils/type.utils.js.map +1 -0
- package/build/src/config.d.ts +5 -13
- package/build/src/config.js +0 -12
- package/build/src/config.js.map +1 -1
- package/build/src/servers/server.builder.d.ts +1 -118
- package/build/src/servers/server.builder.js +0 -20
- package/build/src/servers/server.builder.js.map +1 -1
- package/build/src/servers/server.d.ts +2 -2
- package/build/src/servers/server.js +2 -12
- package/build/src/servers/server.js.map +1 -1
- package/build/src/types/api-response.d.ts +28 -0
- package/build/src/types/api-response.js +11 -0
- package/build/src/types/api-response.js.map +1 -1
- package/build/src/types/server.d.ts +0 -17
- package/build/src/types/server.js.map +1 -1
- package/build/src/utils/async.utils.d.ts +91 -0
- package/build/src/utils/async.utils.js +194 -0
- package/build/src/utils/async.utils.js.map +1 -1
- package/build/src/utils/context-store.utils.d.ts +3 -0
- package/build/src/utils/context-store.utils.js +9 -6
- package/build/src/utils/context-store.utils.js.map +1 -1
- package/build/src/utils/date.utils.d.ts +159 -0
- package/build/src/utils/date.utils.js +396 -0
- package/build/src/utils/date.utils.js.map +1 -0
- package/build/src/utils/logger.utils.d.ts +3 -9
- package/build/src/utils/logger.utils.js +4 -10
- package/build/src/utils/logger.utils.js.map +1 -1
- package/build/src/utils/middleware.utils.js +2 -1
- package/build/src/utils/middleware.utils.js.map +1 -1
- package/build/src/utils/performance.utils.d.ts +136 -0
- package/build/src/utils/performance.utils.js +278 -0
- package/build/src/utils/performance.utils.js.map +1 -0
- package/build/src/utils/request.utils.d.ts +9 -0
- package/build/src/utils/request.utils.js +25 -5
- package/build/src/utils/request.utils.js.map +1 -1
- package/build/src/utils/stream.utils.d.ts +88 -0
- package/build/src/utils/stream.utils.js +218 -0
- package/build/src/utils/stream.utils.js.map +1 -0
- package/build/src/utils/type.utils.d.ts +90 -0
- package/build/src/utils/type.utils.js +196 -0
- package/build/src/utils/type.utils.js.map +1 -0
- package/package.json +6 -2
package/build/src/config.js
CHANGED
|
@@ -52,12 +52,6 @@ exports.config = {
|
|
|
52
52
|
*/
|
|
53
53
|
singleLine: env_utils_1.Env.getBoolean('LOGGER_PRETTY_SINGLE_LINE', false)
|
|
54
54
|
},
|
|
55
|
-
http: {
|
|
56
|
-
/**
|
|
57
|
-
* Timeout for HTTP requests in milliseconds
|
|
58
|
-
*/
|
|
59
|
-
timeout: env_utils_1.Env.getNumber('HTTP_TIMEOUT', 30000)
|
|
60
|
-
},
|
|
61
55
|
cache: {
|
|
62
56
|
/**
|
|
63
57
|
* Default TTL (time to live) for cache entries in seconds
|
|
@@ -116,12 +110,6 @@ exports.defaultServerConfig = {
|
|
|
116
110
|
exposeHeader: true,
|
|
117
111
|
generator: () => (0, id_utils_1.uuid)()
|
|
118
112
|
},
|
|
119
|
-
logger: {
|
|
120
|
-
name: 'express_app',
|
|
121
|
-
level: 'info',
|
|
122
|
-
prettyPrint: false,
|
|
123
|
-
singleLine: false
|
|
124
|
-
},
|
|
125
113
|
metrics: {
|
|
126
114
|
enable: false,
|
|
127
115
|
path: '/metrics',
|
package/build/src/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AA8HH,8BAEC;AAMD,8BAEC;AArID,iDAAwC;AACxC,+CAAwC;AAExC,iDAAiD;AAmBjD;;GAEG;AACQ,QAAA,MAAM,GAAG;IAClB,MAAM,EAAE;QACN;;WAEG;QACH,KAAK,EAAE,eAAG,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAiB;QAEtD;;WAEG;QACH,IAAI,EAAE,eAAG,CAAC,GAAG,CAAC,aAAa,EAAE,eAAG,CAAC,GAAG,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;QAE1E;;;WAGG;QACH,MAAM,EAAE,eA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MAAM,EAAE,KAAK;QACb,SAAS,EAAE,OAAO;QAClB,OAAO,EAAE,KAAK;QACd,gBAAgB,EAAE,KAAK;KACxB;IACD,WAAW,EAAE;QACX,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,IAAI;KACf;IACD,cAAc,EAAE,KAAK;IACrB,YAAY,EAAE;QACZ,MAAM,EAAE,KAAK;QACb,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,KAAK;KACrB;IACD,SAAS,EAAE;QACT,UAAU,EAAE,cAAc;QAC1B,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,GAAG,EAAE,CAAC,IAAA,eAAI,GAAE;KACxB;IACD,OAAO,EAAE;QACP,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,UAAU;QAChB,gBAAgB,EAAE,KAAK;KACxB;IACD,cAAc,EAAE;QACd,MAAM,EAAE,KAAK;QACb,UAAU,EAAE,mBAAmB;QAC/B,OAAO,EAAE,OAAO;KACjB;CACqB,CAAC;AAEzB;;;GAGG;AACH,SAAgB,SAAS,CAAC,KAA6B;IACrD,IAAA,wBAAY,EAAC,cAAM,EAAE,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS;IACvB,OAAO,cAAM,CAAC;AAChB,CAAC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { ServerConfig } from './types/server';\nimport { Env } from './utils/env.utils';\nimport { uuid } from './utils/id.utils';\nimport { Logger, LoggerLevels } from './utils/logger.utils';\nimport { deepObjMerge } from './utils/obj.utils';\n\n/**\n * Extends Express Request interface to add request ID tracking.\n * Added by requestId middleware during request processing.\n */\ndeclare global {\n namespace Express {\n interface Request {\n /** Unique request identifier (set by middleware) */\n id?: string;\n /** Logger instance for the request (set by middleware) */\n logger?: Logger;\n /** User information (set by authentication middleware) */\n user?: any;\n }\n }\n}\n\n/**\n * Application runtime configuration loaded from environment variables.\n */\nexport let config = {\n logger: {\n /**\n * Logging level (e.g., 'info', 'debug', 'warn', 'error').\n */\n level: Env.get('LOGGER_LEVEL', 'info') as LoggerLevels,\n\n /**\n * Name of the logger instance (defaults to npm package name).\n */\n name: Env.get('LOGGER_NAME', Env.get('npm_package_name', '@catbee/utils')),\n\n /**\n * Enables pretty-print logging in development.\n * Has no effect in production.\n */\n pretty: Env.getBoolean('LOGGER_PRETTY', true),\n /**\n * Single line output for pretty-print (default: false)\n */\n singleLine: Env.getBoolean('LOGGER_PRETTY_SINGLE_LINE', false)\n },\n\n cache: {\n /**\n * Default TTL (time to live) for cache entries in seconds\n */\n defaultTtl: Env.getNumber('CACHE_DEFAULT_TTL_SECONDS', 3600) * 1000\n }\n};\n\nexport const defaultServerConfig = {\n port: 3000,\n host: '0.0.0.0',\n cors: false,\n helmet: false,\n compression: false,\n bodyParser: {\n json: { limit: '1mb' },\n urlencoded: { extended: true, limit: '1mb' }\n },\n cookieParser: false,\n isMicroservice: false,\n appName: 'express_app',\n globalHeaders: {},\n rateLimit: {\n enable: false,\n windowMs: 15 * 60 * 1000,\n max: 100,\n message: 'Too many requests',\n standardHeaders: true,\n legacyHeaders: false\n },\n requestLogging: {\n enable: Env.isDev(),\n ignorePaths: (req, _res) => {\n const skipPaths = ['/healthz', '/favicon.ico', '/metrics', '/docs', '/.well-known'];\n return skipPaths.some(path => req.path.startsWith(path));\n },\n skipNotFoundRoutes: false\n },\n openApi: {\n enable: false,\n mountPath: '/docs',\n verbose: false,\n withGlobalPrefix: false\n },\n healthCheck: {\n path: '/healthz',\n detailed: true\n },\n requestTimeout: 30000,\n responseTime: {\n enable: false,\n addHeader: true,\n logOnComplete: false\n },\n requestId: {\n headerName: 'x-request-id',\n exposeHeader: true,\n generator: () => uuid()\n },\n metrics: {\n enable: false,\n path: '/metrics',\n withGlobalPrefix: false\n },\n serviceVersion: {\n enable: false,\n headerName: 'x-service-version',\n version: '0.0.0'\n }\n} satisfies ServerConfig;\n\n/**\n * Update the @catbee/utils configuration.\n * @param value Partial configuration object.\n */\nexport function setConfig(value: Partial<typeof config>): void {\n deepObjMerge(config, value);\n}\n\n/**\n * Get the current @catbee/utils configuration.\n * @returns The current configuration object.\n */\nexport function getConfig(): typeof config {\n return config;\n}\n"]}
|
|
@@ -408,23 +408,6 @@ export declare class ServerConfigBuilder {
|
|
|
408
408
|
* ```
|
|
409
409
|
*/
|
|
410
410
|
withCookies(opts: ServerConfig['cookieParser']): this;
|
|
411
|
-
/**
|
|
412
|
-
* Configures the logger used by the server.
|
|
413
|
-
*
|
|
414
|
-
* @param opts - Logger configuration options
|
|
415
|
-
* @returns The builder instance for chaining
|
|
416
|
-
* @default { name: 'express_app', level: 'info', prettyPrint: true in dev, singleLine: false }
|
|
417
|
-
*
|
|
418
|
-
* @example
|
|
419
|
-
* ```typescript
|
|
420
|
-
* builder.withLogger({
|
|
421
|
-
* level: 'info',
|
|
422
|
-
* prettyPrint: true,
|
|
423
|
-
* singleLine: false
|
|
424
|
-
* })
|
|
425
|
-
* ```
|
|
426
|
-
*/
|
|
427
|
-
withLogger(opts: Partial<NonNullable<ServerConfig['logger']>>): this;
|
|
428
411
|
/**
|
|
429
412
|
* Adds a static folder to serve files from.
|
|
430
413
|
*
|
|
@@ -518,107 +501,7 @@ export declare class ServerConfigBuilder {
|
|
|
518
501
|
* .build();
|
|
519
502
|
* ```
|
|
520
503
|
*/
|
|
521
|
-
build(): Readonly<
|
|
522
|
-
[BUILD_MARKER]: boolean;
|
|
523
|
-
port: number;
|
|
524
|
-
host?: string;
|
|
525
|
-
cors?: import("..").ToggleConfig<import("cors").CorsOptions>;
|
|
526
|
-
helmet?: import("..").ToggleConfig<import("helmet").HelmetOptions>;
|
|
527
|
-
compression?: import("..").ToggleConfig<import("compression").CompressionOptions>;
|
|
528
|
-
bodyParser?: {
|
|
529
|
-
json? /**
|
|
530
|
-
* Sets the hostname the server will bind to.
|
|
531
|
-
*
|
|
532
|
-
* @param host - The hostname (e.g., 'localhost', '0.0.0.0', '127.0.0.1')
|
|
533
|
-
* @returns The builder instance for chaining
|
|
534
|
-
* @default '0.0.0.0' (can be overridden via HOST env variable)
|
|
535
|
-
*
|
|
536
|
-
* @example
|
|
537
|
-
* ```typescript
|
|
538
|
-
* builder.withHost('0.0.0.0') // Listen on all interfaces
|
|
539
|
-
* ```
|
|
540
|
-
*/: Parameters<typeof import("express").json>[0];
|
|
541
|
-
urlencoded?: Parameters<typeof import("express").urlencoded>[0];
|
|
542
|
-
};
|
|
543
|
-
cookieParser?: import("..").ToggleConfig<import("cookie-parser").CookieParseOptions>;
|
|
544
|
-
trustProxy?: boolean;
|
|
545
|
-
staticFolders?: Array<{
|
|
546
|
-
path?: string;
|
|
547
|
-
directory: string;
|
|
548
|
-
maxAge?: string;
|
|
549
|
-
etag?: boolean;
|
|
550
|
-
immutable?: boolean;
|
|
551
|
-
lastModified?: boolean;
|
|
552
|
-
cacheControl?: boolean;
|
|
553
|
-
}>;
|
|
554
|
-
isMicroservice?: boolean;
|
|
555
|
-
appName?: string;
|
|
556
|
-
globalHeaders?: Record<string, string | (() => string)>;
|
|
557
|
-
rateLimit?: {
|
|
558
|
-
enable: boolean;
|
|
559
|
-
windowMs?: number;
|
|
560
|
-
max?: number;
|
|
561
|
-
message?: string;
|
|
562
|
-
standardHeaders?: boolean;
|
|
563
|
-
legacyHeaders?: boolean;
|
|
564
|
-
};
|
|
565
|
-
requestLogging?: {
|
|
566
|
-
enable: boolean;
|
|
567
|
-
ignorePaths?: string[] | ((req: import("express").Request, res: import("express").Response) => boolean);
|
|
568
|
-
skipNotFoundRoutes?: boolean;
|
|
569
|
-
};
|
|
570
|
-
healthCheck?: {
|
|
571
|
-
path?: string;
|
|
572
|
-
checks?: Array<{
|
|
573
|
-
name: string;
|
|
574
|
-
check: () => Promise<boolean> | boolean;
|
|
575
|
-
}>;
|
|
576
|
-
detailed?: boolean;
|
|
577
|
-
withGlobalPrefix?: boolean;
|
|
578
|
-
};
|
|
579
|
-
requestTimeout?: number;
|
|
580
|
-
responseTime?: {
|
|
581
|
-
enable: boolean;
|
|
582
|
-
addHeader?: boolean;
|
|
583
|
-
logOnComplete?: boolean;
|
|
584
|
-
};
|
|
585
|
-
requestId?: {
|
|
586
|
-
headerName?: string;
|
|
587
|
-
exposeHeader?: boolean;
|
|
588
|
-
generator?: () => string;
|
|
589
|
-
};
|
|
590
|
-
globalPrefix?: string;
|
|
591
|
-
openApi?: {
|
|
592
|
-
enable: boolean;
|
|
593
|
-
mountPath?: string;
|
|
594
|
-
filePath?: string;
|
|
595
|
-
verbose?: boolean;
|
|
596
|
-
withGlobalPrefix?: boolean;
|
|
597
|
-
};
|
|
598
|
-
logger?: {
|
|
599
|
-
name?: string;
|
|
600
|
-
level?: import("..").LoggerLevels;
|
|
601
|
-
prettyPrint?: boolean;
|
|
602
|
-
singleLine?: boolean;
|
|
603
|
-
};
|
|
604
|
-
metrics?: {
|
|
605
|
-
enable: boolean;
|
|
606
|
-
path?: string;
|
|
607
|
-
withGlobalPrefix?: boolean;
|
|
608
|
-
};
|
|
609
|
-
serviceVersion?: {
|
|
610
|
-
enable: boolean;
|
|
611
|
-
headerName?: string;
|
|
612
|
-
version?: string | (() => string);
|
|
613
|
-
};
|
|
614
|
-
https?: {
|
|
615
|
-
key: string;
|
|
616
|
-
cert: string;
|
|
617
|
-
ca?: string;
|
|
618
|
-
passphrase?: string;
|
|
619
|
-
[key: string]: any;
|
|
620
|
-
};
|
|
621
|
-
}>;
|
|
504
|
+
build(): Readonly<ServerConfig>;
|
|
622
505
|
private mergeConfig;
|
|
623
506
|
private setEnabled;
|
|
624
507
|
}
|
|
@@ -525,26 +525,6 @@ class ServerConfigBuilder {
|
|
|
525
525
|
this.config.cookieParser = opts;
|
|
526
526
|
return this;
|
|
527
527
|
}
|
|
528
|
-
/**
|
|
529
|
-
* Configures the logger used by the server.
|
|
530
|
-
*
|
|
531
|
-
* @param opts - Logger configuration options
|
|
532
|
-
* @returns The builder instance for chaining
|
|
533
|
-
* @default { name: 'express_app', level: 'info', prettyPrint: true in dev, singleLine: false }
|
|
534
|
-
*
|
|
535
|
-
* @example
|
|
536
|
-
* ```typescript
|
|
537
|
-
* builder.withLogger({
|
|
538
|
-
* level: 'info',
|
|
539
|
-
* prettyPrint: true,
|
|
540
|
-
* singleLine: false
|
|
541
|
-
* })
|
|
542
|
-
* ```
|
|
543
|
-
*/
|
|
544
|
-
withLogger(opts) {
|
|
545
|
-
this.mergeConfig('logger', opts);
|
|
546
|
-
return this;
|
|
547
|
-
}
|
|
548
528
|
/**
|
|
549
529
|
* Adds a static folder to serve files from.
|
|
550
530
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.builder.js","sourceRoot":"","sources":["../../../src/servers/server.builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,kDAAkD;AAElD,sCAAgD;AAChD,4DAAiD;AAEjD;;;;;;;;;;;;;;;GAeG;AAEU,QAAA,YAAY,GAAG,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AE,IAAI,CAAC,MAAM,CAAiB,CAAC;QAElF,oBAAoB;QACpB,IAAI,CAAA,MAAA,MAAM,CAAC,OAAO,0CAAE,MAAM,KAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,iCACf,MAAM,KACT,CAAC,oBAAY,CAAC,EAAE,IAAI,IACpB,CAAC;IACL,CAAC;IAEO,WAAW,CAA+B,GAAM,EAAE,KAA4C;QACpG,MAAM,OAAO,GACX,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;YAC/D,CAAC,CAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAkC;YACpD,CAAC,CAAC,EAAE,CAAC;QACT,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAA,wBAAY,EAAC,EAAE,EAAE,OAAO,EAAE,KAAK,CAAiC,CAAC;IACtF,CAAC;IAEO,UAAU,CAChB,GAAM,EACN,MAAe,EACf,YAAmD,EAAE;QAErD,IAAI,CAAC,WAAW,CAAC,GAAG,kCAAO,SAAS,KAAE,MAAM,IAAG,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA7qBD,kDA6qBC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { deepObjMerge } from '../utils/obj.utils';\nimport { ServerConfig } from '../types/server';\nimport { defaultServerConfig } from '../config';\nimport { isPort } from '../utils/validate.utils';\n\n/**\n * Builder class for creating and configuring an Express server configuration.\n *\n * This class provides a fluent interface to configure all aspects of the Express server\n * including security settings, middleware, routing, and more.\n *\n * @example\n * ```typescript\n * const serverConfig = new ServerConfigBuilder()\n * .withPort(3000)\n * .withHost('localhost')\n * .enableCors()\n * .enableHelmet()\n * .build();\n * ```\n */\n\nexport const BUILD_MARKER = Symbol.for('catbee.express.server.build');\n\nexport class ServerConfigBuilder {\n private config: Partial<ServerConfig> = {};\n\n /**\n * Validates that a port number is valid and usable.\n *\n * @private\n * @param port - The port number to validate\n * @throws {Error} If port is not an integer or is outside the valid range (1-65535)\n */\n private validatePort(port: number): void {\n if (!isPort(port)) {\n throw new Error(`Port must be a valid number between 1 and 65535, got: ${port}`);\n }\n }\n\n /**\n * Sets the port the server will listen on.\n *\n * @param port - The port number (1-65535)\n * @returns The builder instance for chaining\n * @throws {Error} If port is invalid\n * @default 3000 (can be overridden via PORT env variable)\n *\n * @example\n * ```typescript\n * builder.withPort(3000)\n * ```\n */\n withPort(port: number): this {\n this.validatePort(port);\n this.config.port = port;\n return this;\n }\n\n /**\n * Sets the hostname the server will bind to.\n *\n * @param host - The hostname (e.g., 'localhost', '0.0.0.0', '127.0.0.1')\n * @returns The builder instance for chaining\n * @default '0.0.0.0' (can be overridden via HOST env variable)\n *\n * @example\n * ```typescript\n * builder.withHost('0.0.0.0') // Listen on all interfaces\n * ```\n */\n withHost(host: string): this {\n this.config.host = host;\n return this;\n }\n\n /**\n * Configures Cross-Origin Resource Sharing (CORS) for the server.\n *\n * @param opts - CORS options object or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false (CORS is disabled by default)\n *\n * @example\n * ```typescript\n * // Enable CORS with default options\n * builder.withCors(true)\n *\n * // Configure CORS with specific options\n * builder.withCors({\n * origin: ['https://example.com'],\n * methods: ['GET', 'POST']\n * })\n * ```\n */\n withCors(opts: ServerConfig['cors']): this {\n this.config.cors = opts;\n return this;\n }\n\n /**\n * Enables CORS with default settings\n *\n * @returns The builder instance for chaining\n */\n enableCors(): this {\n return this.withCors(true);\n }\n\n /**\n * Disables CORS\n *\n * @returns The builder instance for chaining\n */\n disableCors(): this {\n return this.withCors(false);\n }\n\n /**\n * Configures the Helmet middleware for setting HTTP security headers.\n *\n * @param opts - Helmet options object or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false (Helmet is disabled by default)\n *\n * @example\n * ```typescript\n * // Enable Helmet with default settings\n * builder.withHelmet(true)\n *\n * // Configure Helmet with specific options\n * builder.withHelmet({\n * contentSecurityPolicy: false,\n * xssFilter: true\n * })\n * ```\n */\n withHelmet(opts: ServerConfig['helmet']): this {\n this.config.helmet = opts;\n return this;\n }\n\n /**\n * Enables Helmet with default settings\n *\n * @returns The builder instance for chaining\n */\n enableHelmet(): this {\n return this.withHelmet(true);\n }\n\n /**\n * Disables Helmet\n *\n * @returns The builder instance for chaining\n */\n disableHelmet(): this {\n return this.withHelmet(false);\n }\n\n /**\n * Configures response compression middleware.\n *\n * @param opts - Compression options object or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false (Compression is disabled by default)\n *\n * @example\n * ```typescript\n * // Enable compression with default settings\n * builder.withCompression(true)\n *\n * // Configure compression with specific options\n * builder.withCompression({\n * level: 6,\n * threshold: 1024\n * })\n * ```\n */\n withCompression(opts: ServerConfig['compression']): this {\n this.config.compression = opts;\n return this;\n }\n\n /**\n * Enables compression with default settings\n *\n * @returns The builder instance for chaining\n */\n enableCompression(): this {\n return this.withCompression(true);\n }\n\n /**\n * Disables compression\n *\n * @returns The builder instance for chaining\n */\n disableCompression(): this {\n return this.withCompression(false);\n }\n\n /**\n * Configures rate limiting to protect against brute-force attacks.\n *\n * @param opts - Rate limit configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, windowMs: 15 * 60 * 1000, max: 100, message: 'Too many requests', standardHeaders: true, legacyHeaders: false }\n *\n * @example\n * ```typescript\n * builder.withRateLimit({\n * enable: true,\n * windowMs: 15 * 60 * 1000, // 15 minutes\n * max: 100 // limit each IP to 100 requests per windowMs\n * })\n * ```\n */\n withRateLimit(opts: Partial<ServerConfig['rateLimit']>): this {\n this.mergeConfig('rateLimit', opts as NonNullable<ServerConfig['rateLimit']>);\n return this;\n }\n\n /**\n * Enables rate limiting with default or custom settings\n *\n * @param opts - Optional rate limit configuration (max requests, window, etc.)\n * @returns The builder instance for chaining\n */\n enableRateLimit(opts: Omit<Partial<NonNullable<ServerConfig['rateLimit']>>, 'enable'> = {}): this {\n return this.setEnabled('rateLimit', true, opts);\n }\n\n /**\n * Disables rate limiting\n *\n * @returns The builder instance for chaining\n */\n disableRateLimit(): this {\n return this.setEnabled('rateLimit', false);\n }\n\n /**\n * Configures HTTP request logging middleware.\n *\n * @param opts - Request logging configuration options\n * @returns The builder instance for chaining\n * @default { enable: true in dev/false in prod, ignorePaths: ['/healthz', '/favicon.ico', '/metrics', '/docs', '/.well-known'], skipNotFoundRoutes: false }\n *\n * @example\n * ```typescript\n * builder.withRequestLogging({\n * enable: true,\n * ignorePaths: ['/health', '/metrics'],\n * skipNotFoundRoutes: true\n * })\n * ```\n */\n withRequestLogging(opts: Partial<NonNullable<ServerConfig['requestLogging']>>): this {\n this.mergeConfig('requestLogging', opts as NonNullable<ServerConfig['requestLogging']>);\n return this;\n }\n\n /**\n * Enables request logging with default or custom settings\n *\n * @param opts - Optional request logging configuration\n * @returns The builder instance for chaining\n */\n enableRequestLogging(opts: Omit<Partial<NonNullable<ServerConfig['requestLogging']>>, 'enable'> = {}): this {\n return this.setEnabled('requestLogging', true, opts);\n }\n\n /**\n * Disables request logging\n *\n * @returns The builder instance for chaining\n */\n disableRequestLogging(): this {\n return this.setEnabled('requestLogging', false);\n }\n\n /**\n * Configures server metrics collection and endpoints.\n *\n * @param opts - Metrics configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, path: '/metrics', withGlobalPrefix: false }\n *\n * @example\n * ```typescript\n * builder.withMetrics({\n * enable: true,\n * path: '/metrics'\n * })\n * ```\n */\n withMetrics(opts: Partial<NonNullable<ServerConfig['metrics']>>): this {\n this.mergeConfig('metrics', opts as NonNullable<ServerConfig['metrics']>);\n return this;\n }\n\n /**\n * Enables Prometheus metrics collection and endpoint\n *\n * @param opts - Optional metrics configuration\n * @returns The builder instance for chaining\n */\n enableMetrics(opts: Omit<Partial<NonNullable<ServerConfig['metrics']>>, 'enable'> = {}): this {\n return this.setEnabled('metrics', true, opts);\n }\n\n /**\n * Disables Prometheus metrics\n *\n * @returns The builder instance for chaining\n */\n disableMetrics(): this {\n return this.setEnabled('metrics', false);\n }\n\n /**\n * Configures server health check endpoint.\n *\n * @param opts - Health check configuration options\n * @returns The builder instance for chaining\n * @default { path: '/healthz', detailed: true, withGlobalPrefix: false }\n *\n * @example\n * ```typescript\n * builder.withHealthCheck({\n * path: '/health',\n * detailed: true\n * })\n * ```\n */\n withHealthCheck(opts: Partial<NonNullable<ServerConfig['healthCheck']>>): this {\n this.mergeConfig('healthCheck', opts as NonNullable<ServerConfig['healthCheck']>);\n return this;\n }\n\n /**\n * Configures OpenAPI/Swagger documentation for the API.\n *\n * @param opts - OpenAPI configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, mountPath: '/docs', verbose: false, withGlobalPrefix: false }\n *\n * @example\n * ```typescript\n * builder.withOpenApi({\n * enable: true,\n * path: '/api-docs',\n * filePath: './openapi.yaml'\n * })\n * ```\n */\n withOpenApi(opts: Partial<NonNullable<ServerConfig['openApi']>>): this {\n this.mergeConfig('openApi', opts as NonNullable<ServerConfig['openApi']>);\n return this;\n }\n\n /**\n * Enables OpenAPI documentation with required file path\n *\n * @param filePath - Path to OpenAPI specification file (required)\n * @param opts - Optional OpenAPI configuration\n * @returns The builder instance for chaining\n */\n enableOpenApi(\n filePath: string,\n opts: Omit<Partial<NonNullable<ServerConfig['openApi']>>, 'enable' | 'filePath'> = {}\n ): this {\n this.setEnabled('openApi', true, { filePath, ...opts });\n return this;\n }\n\n /**\n * Disables OpenAPI documentation\n *\n * @returns The builder instance for chaining\n */\n disableOpenApi(): this {\n return this.setEnabled('openApi', false);\n }\n\n /**\n * Configures the server as a microservice with versioning.\n *\n * @param opts - Microservice configuration options including app name and service version\n * @returns The builder instance for chaining\n * @default { isMicroservice: false, appName: 'express_app' }\n *\n * @example\n * ```typescript\n * builder.withMicroService({\n * appName: 'user-service',\n * serviceVersion: {\n * enable: true,\n * version: '1.2.3'\n * }\n * })\n * ```\n */\n withMicroService(opts: {\n appName: NonNullable<ServerConfig['appName']>;\n serviceVersion: Partial<NonNullable<ServerConfig['serviceVersion']>>;\n }): this {\n this.config.isMicroservice = true;\n this.config.appName = opts.appName;\n\n this.mergeConfig('serviceVersion', opts.serviceVersion as NonNullable<ServerConfig['serviceVersion']>);\n return this;\n }\n\n /**\n * Configures the trust proxy settings to determine if X-Forwarded-* headers should be trusted.\n *\n * @param opts - Trust proxy configuration options\n * @returns The builder instance for chaining\n * @default false\n *\n * @example\n * ```typescript\n * // Trust proxy headers (useful when behind a load balancer)\n * builder.withTrustProxy(true)\n * ```\n */\n withTrustProxy(opts: NonNullable<ServerConfig['trustProxy']>): this {\n this.config.trustProxy = opts;\n return this;\n }\n\n /**\n * Configures the request ID middleware for tracing requests across services.\n *\n * @param opts - Request ID configuration options\n * @returns The builder instance for chaining\n * @default { headerName: 'x-request-id', exposeHeader: true }\n *\n * @example\n * ```typescript\n * builder.withRequestId({\n * headerName: 'X-Request-Id',\n * generator: () => crypto.randomUUID()\n * })\n * ```\n */\n withRequestId(opts: Partial<NonNullable<ServerConfig['requestId']>>): this {\n this.mergeConfig('requestId', opts as NonNullable<ServerConfig['requestId']>);\n return this;\n }\n\n /**\n * Configures the response time middleware for measuring request processing times.\n *\n * @param opts - Response time configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, addHeader: true, logOnComplete: false }\n *\n * @example\n * ```typescript\n * builder.withResponseTime({\n * enable: true,\n * addHeader: true,\n * logOnComplete: true\n * })\n * ```\n */\n withResponseTime(opts: Partial<NonNullable<ServerConfig['responseTime']>>): this {\n this.mergeConfig('responseTime', opts as NonNullable<ServerConfig['responseTime']>);\n return this;\n }\n\n /**\n * Enables response time tracking with default or custom settings\n *\n * @param opts - Optional response time configuration\n * @returns The builder instance for chaining\n */\n enableResponseTime(opts: Omit<Partial<NonNullable<ServerConfig['responseTime']>>, 'enable'> = {}): this {\n this.setEnabled('responseTime', true, opts);\n return this;\n }\n\n /**\n * Disables response time tracking\n *\n * @returns The builder instance for chaining\n */\n disableResponseTime(): this {\n return this.setEnabled('responseTime', false);\n }\n\n /**\n * Configures the body parser middleware options for parsing request bodies.\n *\n * @param opts - Body parser configuration options\n * @returns The builder instance for chaining\n * @default { json: { limit: '1mb' }, urlencoded: { extended: true, limit: '1mb' } }\n *\n * @example\n * ```typescript\n * builder.withBodyParser({\n * json: {\n * limit: '1mb'\n * },\n * urlencoded: {\n * extended: true,\n * limit: '1mb'\n * }\n * })\n * ```\n */\n withBodyParser(opts: NonNullable<ServerConfig['bodyParser']>): this {\n this.config.bodyParser = deepObjMerge({}, this.config.bodyParser ?? {}, opts);\n return this;\n }\n\n /**\n * Configures cookie parsing middleware.\n *\n * @param opts - Cookie parser options or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false\n *\n * @example\n * ```typescript\n * // Enable cookie parsing with default options\n * builder.withCookies(true)\n *\n * // Enable cookie parsing with specific options\n * builder.withCookies({\n * secret: 'your-secret-key',\n * secure: true\n * })\n * ```\n */\n withCookies(opts: ServerConfig['cookieParser']): this {\n this.config.cookieParser = opts;\n return this;\n }\n\n /**\n * Configures the logger used by the server.\n *\n * @param opts - Logger configuration options\n * @returns The builder instance for chaining\n * @default { name: 'express_app', level: 'info', prettyPrint: true in dev, singleLine: false }\n *\n * @example\n * ```typescript\n * builder.withLogger({\n * level: 'info',\n * prettyPrint: true,\n * singleLine: false\n * })\n * ```\n */\n withLogger(opts: Partial<NonNullable<ServerConfig['logger']>>): this {\n this.mergeConfig('logger', opts as NonNullable<ServerConfig['logger']>);\n return this;\n }\n\n /**\n * Adds a static folder to serve files from.\n *\n * @param folder - Static folder configuration\n * @returns The builder instance for chaining\n *\n * @example\n * ```typescript\n * builder.withStaticFolder({\n * path: '/assets',\n * directory: './public',\n * options: { maxAge: '1d' }\n * })\n * ```\n */\n withStaticFolder(folder: NonNullable<ServerConfig['staticFolders']>[number]): this {\n if (!folder.path) throw new Error('Static folder requires a path');\n const folders = [...(this.config.staticFolders ?? []), folder];\n this.config.staticFolders = Array.from(new Map(folders.map(f => [f.path, f])).values());\n return this;\n }\n\n /**\n * Sets global headers to be included in all responses.\n *\n * @param headers - Object containing header name/value pairs or functions that return values\n * @returns The builder instance for chaining\n * @default {}\n *\n * @example\n * ```typescript\n * builder.withGlobalHeaders({\n * 'X-Powered-By': 'Catbee',\n * 'Server-Time': () => new Date().toISOString()\n * })\n * ```\n */\n withGlobalHeaders(headers: NonNullable<ServerConfig['globalHeaders']>): this {\n this.mergeConfig('globalHeaders', headers);\n return this;\n }\n\n /**\n * Sets a global prefix for all routes.\n *\n * @param prefix - The prefix to prepend to all routes (e.g., '/api/v1')\n * @returns The builder instance for chaining\n * @default '/'\n *\n * @example\n * ```typescript\n * builder.withGlobalPrefix('/api/v1')\n * ```\n */\n withGlobalPrefix(prefix: string): this {\n this.config.globalPrefix = prefix;\n return this;\n }\n\n /**\n * Applies custom configuration overrides directly.\n *\n * @param overrides - Custom configuration options to merge\n * @returns The builder instance for chaining\n *\n * @example\n * ```typescript\n * builder.withCustom({\n * port: 8080,\n * customMiddleware: myMiddlewareFunction\n * })\n * ```\n */\n withCustom(overrides: Partial<ServerConfig>): this {\n this.config = deepObjMerge({}, this.config, overrides);\n return this;\n }\n\n /**\n * Configures HTTPS server options.\n *\n * @param opts - HTTPS configuration (key, cert, ca, passphrase, etc.)\n * @returns The builder instance for chaining\n *\n * @example\n * ```typescript\n * builder.withHttps({\n * key: './localhost-key.pem',\n * cert: './localhost-cert.pem'\n * })\n * ```\n */\n withHttps(opts: NonNullable<ServerConfig['https']>): this {\n this.config.https = opts;\n return this;\n }\n\n /**\n * Builds and returns the final server configuration.\n *\n * This method merges the user-specified configuration with default values,\n * ensures all sections with 'enable' flags are properly structured, and\n * produces the final configuration to be used by the server.\n *\n * @returns The complete ServerConfig object\n *\n * @example\n * ```typescript\n * const config = new ServerConfigBuilder()\n * .withPort(3000)\n * .withHost('localhost')\n * .withCors(true)\n * .build();\n * ```\n */\n build() {\n const config = deepObjMerge({}, defaultServerConfig, this.config) as ServerConfig;\n\n // Common validation\n if (config.openApi?.enable && !config.openApi.filePath) {\n throw new Error('OpenAPI is enabled but no filePath is specified');\n }\n\n return Object.freeze({\n ...config,\n [BUILD_MARKER]: true\n });\n }\n\n private mergeConfig<K extends keyof ServerConfig>(key: K, value: Partial<NonNullable<ServerConfig[K]>>): void {\n const current =\n typeof this.config[key] === 'object' && this.config[key] !== null\n ? (this.config[key] as NonNullable<ServerConfig[K]>)\n : {};\n this.config[key] = deepObjMerge({}, current, value) as NonNullable<ServerConfig[K]>;\n }\n\n private setEnabled<K extends keyof ServerConfig>(\n key: K,\n enable: boolean,\n overrides: Partial<NonNullable<ServerConfig[K]>> = {}\n ): this {\n this.mergeConfig(key, { ...overrides, enable });\n return this;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"server.builder.js","sourceRoot":"","sources":["../../../src/servers/server.builder.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH,kDAAkD;AAElD,sCAAgD;AAChD,4DAAiD;AAEjD;;;;;;;;;;;;;;;GAeG;AAEU,QAAA,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAEtE,MAAa,mBAAmB;IAAhC;QACU,WAAM,GAA0B,EAAE,CAAC;IAupB7C,CAAC;IArpBC;;;;;;OAMG;IACK,YAAY,CAAC,IAAY;QAC/B,IAAI,CAAC,IAAA,uBAAM,EAAC,IAAI,CAAC,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,yDAAyD,IAAI,EAAE,CAAC,CAAC;QACnF,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,IAAY;QACnB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,IAAY;QACnB,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,CAAC,IAA0B;QACjC,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAED;;;;OAIG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,UAAU,CAAC,IAA4B;QAC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AAM,MAAM,GAAG,IAAA,wBAAY,EAAC,EAAE,EAAE,4BAAmB,EAAE,IAAI,CAAC,MAAM,CAAiB,CAAC;QAElF,oBAAoB;QACpB,IAAI,CAAA,MAAA,MAAM,CAAC,OAAO,0CAAE,MAAM,KAAI,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,iCACf,MAAM,KACT,CAAC,oBAAY,CAAC,EAAE,IAAI,IACpB,CAAC;IACL,CAAC;IAEO,WAAW,CAA+B,GAAM,EAAE,KAA4C;QACpG,MAAM,OAAO,GACX,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI;YAC/D,CAAC,CAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAkC;YACpD,CAAC,CAAC,EAAE,CAAC;QACT,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAA,wBAAY,EAAC,EAAE,EAAE,OAAO,EAAE,KAAK,CAAiC,CAAC;IACtF,CAAC;IAEO,UAAU,CAChB,GAAM,EACN,MAAe,EACf,YAAmD,EAAE;QAErD,IAAI,CAAC,WAAW,CAAC,GAAG,kCAAO,SAAS,KAAE,MAAM,IAAG,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAxpBD,kDAwpBC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { deepObjMerge } from '../utils/obj.utils';\nimport { ServerConfig } from '../types/server';\nimport { defaultServerConfig } from '../config';\nimport { isPort } from '../utils/validate.utils';\n\n/**\n * Builder class for creating and configuring an Express server configuration.\n *\n * This class provides a fluent interface to configure all aspects of the Express server\n * including security settings, middleware, routing, and more.\n *\n * @example\n * ```typescript\n * const serverConfig = new ServerConfigBuilder()\n * .withPort(3000)\n * .withHost('localhost')\n * .enableCors()\n * .enableHelmet()\n * .build();\n * ```\n */\n\nexport const BUILD_MARKER = Symbol.for('catbee.express.server.build');\n\nexport class ServerConfigBuilder {\n private config: Partial<ServerConfig> = {};\n\n /**\n * Validates that a port number is valid and usable.\n *\n * @private\n * @param port - The port number to validate\n * @throws {Error} If port is not an integer or is outside the valid range (1-65535)\n */\n private validatePort(port: number): void {\n if (!isPort(port)) {\n throw new Error(`Port must be a valid number between 1 and 65535, got: ${port}`);\n }\n }\n\n /**\n * Sets the port the server will listen on.\n *\n * @param port - The port number (1-65535)\n * @returns The builder instance for chaining\n * @throws {Error} If port is invalid\n * @default 3000 (can be overridden via PORT env variable)\n *\n * @example\n * ```typescript\n * builder.withPort(3000)\n * ```\n */\n withPort(port: number): this {\n this.validatePort(port);\n this.config.port = port;\n return this;\n }\n\n /**\n * Sets the hostname the server will bind to.\n *\n * @param host - The hostname (e.g., 'localhost', '0.0.0.0', '127.0.0.1')\n * @returns The builder instance for chaining\n * @default '0.0.0.0' (can be overridden via HOST env variable)\n *\n * @example\n * ```typescript\n * builder.withHost('0.0.0.0') // Listen on all interfaces\n * ```\n */\n withHost(host: string): this {\n this.config.host = host;\n return this;\n }\n\n /**\n * Configures Cross-Origin Resource Sharing (CORS) for the server.\n *\n * @param opts - CORS options object or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false (CORS is disabled by default)\n *\n * @example\n * ```typescript\n * // Enable CORS with default options\n * builder.withCors(true)\n *\n * // Configure CORS with specific options\n * builder.withCors({\n * origin: ['https://example.com'],\n * methods: ['GET', 'POST']\n * })\n * ```\n */\n withCors(opts: ServerConfig['cors']): this {\n this.config.cors = opts;\n return this;\n }\n\n /**\n * Enables CORS with default settings\n *\n * @returns The builder instance for chaining\n */\n enableCors(): this {\n return this.withCors(true);\n }\n\n /**\n * Disables CORS\n *\n * @returns The builder instance for chaining\n */\n disableCors(): this {\n return this.withCors(false);\n }\n\n /**\n * Configures the Helmet middleware for setting HTTP security headers.\n *\n * @param opts - Helmet options object or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false (Helmet is disabled by default)\n *\n * @example\n * ```typescript\n * // Enable Helmet with default settings\n * builder.withHelmet(true)\n *\n * // Configure Helmet with specific options\n * builder.withHelmet({\n * contentSecurityPolicy: false,\n * xssFilter: true\n * })\n * ```\n */\n withHelmet(opts: ServerConfig['helmet']): this {\n this.config.helmet = opts;\n return this;\n }\n\n /**\n * Enables Helmet with default settings\n *\n * @returns The builder instance for chaining\n */\n enableHelmet(): this {\n return this.withHelmet(true);\n }\n\n /**\n * Disables Helmet\n *\n * @returns The builder instance for chaining\n */\n disableHelmet(): this {\n return this.withHelmet(false);\n }\n\n /**\n * Configures response compression middleware.\n *\n * @param opts - Compression options object or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false (Compression is disabled by default)\n *\n * @example\n * ```typescript\n * // Enable compression with default settings\n * builder.withCompression(true)\n *\n * // Configure compression with specific options\n * builder.withCompression({\n * level: 6,\n * threshold: 1024\n * })\n * ```\n */\n withCompression(opts: ServerConfig['compression']): this {\n this.config.compression = opts;\n return this;\n }\n\n /**\n * Enables compression with default settings\n *\n * @returns The builder instance for chaining\n */\n enableCompression(): this {\n return this.withCompression(true);\n }\n\n /**\n * Disables compression\n *\n * @returns The builder instance for chaining\n */\n disableCompression(): this {\n return this.withCompression(false);\n }\n\n /**\n * Configures rate limiting to protect against brute-force attacks.\n *\n * @param opts - Rate limit configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, windowMs: 15 * 60 * 1000, max: 100, message: 'Too many requests', standardHeaders: true, legacyHeaders: false }\n *\n * @example\n * ```typescript\n * builder.withRateLimit({\n * enable: true,\n * windowMs: 15 * 60 * 1000, // 15 minutes\n * max: 100 // limit each IP to 100 requests per windowMs\n * })\n * ```\n */\n withRateLimit(opts: Partial<ServerConfig['rateLimit']>): this {\n this.mergeConfig('rateLimit', opts as NonNullable<ServerConfig['rateLimit']>);\n return this;\n }\n\n /**\n * Enables rate limiting with default or custom settings\n *\n * @param opts - Optional rate limit configuration (max requests, window, etc.)\n * @returns The builder instance for chaining\n */\n enableRateLimit(opts: Omit<Partial<NonNullable<ServerConfig['rateLimit']>>, 'enable'> = {}): this {\n return this.setEnabled('rateLimit', true, opts);\n }\n\n /**\n * Disables rate limiting\n *\n * @returns The builder instance for chaining\n */\n disableRateLimit(): this {\n return this.setEnabled('rateLimit', false);\n }\n\n /**\n * Configures HTTP request logging middleware.\n *\n * @param opts - Request logging configuration options\n * @returns The builder instance for chaining\n * @default { enable: true in dev/false in prod, ignorePaths: ['/healthz', '/favicon.ico', '/metrics', '/docs', '/.well-known'], skipNotFoundRoutes: false }\n *\n * @example\n * ```typescript\n * builder.withRequestLogging({\n * enable: true,\n * ignorePaths: ['/health', '/metrics'],\n * skipNotFoundRoutes: true\n * })\n * ```\n */\n withRequestLogging(opts: Partial<NonNullable<ServerConfig['requestLogging']>>): this {\n this.mergeConfig('requestLogging', opts as NonNullable<ServerConfig['requestLogging']>);\n return this;\n }\n\n /**\n * Enables request logging with default or custom settings\n *\n * @param opts - Optional request logging configuration\n * @returns The builder instance for chaining\n */\n enableRequestLogging(opts: Omit<Partial<NonNullable<ServerConfig['requestLogging']>>, 'enable'> = {}): this {\n return this.setEnabled('requestLogging', true, opts);\n }\n\n /**\n * Disables request logging\n *\n * @returns The builder instance for chaining\n */\n disableRequestLogging(): this {\n return this.setEnabled('requestLogging', false);\n }\n\n /**\n * Configures server metrics collection and endpoints.\n *\n * @param opts - Metrics configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, path: '/metrics', withGlobalPrefix: false }\n *\n * @example\n * ```typescript\n * builder.withMetrics({\n * enable: true,\n * path: '/metrics'\n * })\n * ```\n */\n withMetrics(opts: Partial<NonNullable<ServerConfig['metrics']>>): this {\n this.mergeConfig('metrics', opts as NonNullable<ServerConfig['metrics']>);\n return this;\n }\n\n /**\n * Enables Prometheus metrics collection and endpoint\n *\n * @param opts - Optional metrics configuration\n * @returns The builder instance for chaining\n */\n enableMetrics(opts: Omit<Partial<NonNullable<ServerConfig['metrics']>>, 'enable'> = {}): this {\n return this.setEnabled('metrics', true, opts);\n }\n\n /**\n * Disables Prometheus metrics\n *\n * @returns The builder instance for chaining\n */\n disableMetrics(): this {\n return this.setEnabled('metrics', false);\n }\n\n /**\n * Configures server health check endpoint.\n *\n * @param opts - Health check configuration options\n * @returns The builder instance for chaining\n * @default { path: '/healthz', detailed: true, withGlobalPrefix: false }\n *\n * @example\n * ```typescript\n * builder.withHealthCheck({\n * path: '/health',\n * detailed: true\n * })\n * ```\n */\n withHealthCheck(opts: Partial<NonNullable<ServerConfig['healthCheck']>>): this {\n this.mergeConfig('healthCheck', opts as NonNullable<ServerConfig['healthCheck']>);\n return this;\n }\n\n /**\n * Configures OpenAPI/Swagger documentation for the API.\n *\n * @param opts - OpenAPI configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, mountPath: '/docs', verbose: false, withGlobalPrefix: false }\n *\n * @example\n * ```typescript\n * builder.withOpenApi({\n * enable: true,\n * path: '/api-docs',\n * filePath: './openapi.yaml'\n * })\n * ```\n */\n withOpenApi(opts: Partial<NonNullable<ServerConfig['openApi']>>): this {\n this.mergeConfig('openApi', opts as NonNullable<ServerConfig['openApi']>);\n return this;\n }\n\n /**\n * Enables OpenAPI documentation with required file path\n *\n * @param filePath - Path to OpenAPI specification file (required)\n * @param opts - Optional OpenAPI configuration\n * @returns The builder instance for chaining\n */\n enableOpenApi(\n filePath: string,\n opts: Omit<Partial<NonNullable<ServerConfig['openApi']>>, 'enable' | 'filePath'> = {}\n ): this {\n this.setEnabled('openApi', true, { filePath, ...opts });\n return this;\n }\n\n /**\n * Disables OpenAPI documentation\n *\n * @returns The builder instance for chaining\n */\n disableOpenApi(): this {\n return this.setEnabled('openApi', false);\n }\n\n /**\n * Configures the server as a microservice with versioning.\n *\n * @param opts - Microservice configuration options including app name and service version\n * @returns The builder instance for chaining\n * @default { isMicroservice: false, appName: 'express_app' }\n *\n * @example\n * ```typescript\n * builder.withMicroService({\n * appName: 'user-service',\n * serviceVersion: {\n * enable: true,\n * version: '1.2.3'\n * }\n * })\n * ```\n */\n withMicroService(opts: {\n appName: NonNullable<ServerConfig['appName']>;\n serviceVersion: Partial<NonNullable<ServerConfig['serviceVersion']>>;\n }): this {\n this.config.isMicroservice = true;\n this.config.appName = opts.appName;\n\n this.mergeConfig('serviceVersion', opts.serviceVersion as NonNullable<ServerConfig['serviceVersion']>);\n return this;\n }\n\n /**\n * Configures the trust proxy settings to determine if X-Forwarded-* headers should be trusted.\n *\n * @param opts - Trust proxy configuration options\n * @returns The builder instance for chaining\n * @default false\n *\n * @example\n * ```typescript\n * // Trust proxy headers (useful when behind a load balancer)\n * builder.withTrustProxy(true)\n * ```\n */\n withTrustProxy(opts: NonNullable<ServerConfig['trustProxy']>): this {\n this.config.trustProxy = opts;\n return this;\n }\n\n /**\n * Configures the request ID middleware for tracing requests across services.\n *\n * @param opts - Request ID configuration options\n * @returns The builder instance for chaining\n * @default { headerName: 'x-request-id', exposeHeader: true }\n *\n * @example\n * ```typescript\n * builder.withRequestId({\n * headerName: 'X-Request-Id',\n * generator: () => crypto.randomUUID()\n * })\n * ```\n */\n withRequestId(opts: Partial<NonNullable<ServerConfig['requestId']>>): this {\n this.mergeConfig('requestId', opts as NonNullable<ServerConfig['requestId']>);\n return this;\n }\n\n /**\n * Configures the response time middleware for measuring request processing times.\n *\n * @param opts - Response time configuration options\n * @returns The builder instance for chaining\n * @default { enable: false, addHeader: true, logOnComplete: false }\n *\n * @example\n * ```typescript\n * builder.withResponseTime({\n * enable: true,\n * addHeader: true,\n * logOnComplete: true\n * })\n * ```\n */\n withResponseTime(opts: Partial<NonNullable<ServerConfig['responseTime']>>): this {\n this.mergeConfig('responseTime', opts as NonNullable<ServerConfig['responseTime']>);\n return this;\n }\n\n /**\n * Enables response time tracking with default or custom settings\n *\n * @param opts - Optional response time configuration\n * @returns The builder instance for chaining\n */\n enableResponseTime(opts: Omit<Partial<NonNullable<ServerConfig['responseTime']>>, 'enable'> = {}): this {\n this.setEnabled('responseTime', true, opts);\n return this;\n }\n\n /**\n * Disables response time tracking\n *\n * @returns The builder instance for chaining\n */\n disableResponseTime(): this {\n return this.setEnabled('responseTime', false);\n }\n\n /**\n * Configures the body parser middleware options for parsing request bodies.\n *\n * @param opts - Body parser configuration options\n * @returns The builder instance for chaining\n * @default { json: { limit: '1mb' }, urlencoded: { extended: true, limit: '1mb' } }\n *\n * @example\n * ```typescript\n * builder.withBodyParser({\n * json: {\n * limit: '1mb'\n * },\n * urlencoded: {\n * extended: true,\n * limit: '1mb'\n * }\n * })\n * ```\n */\n withBodyParser(opts: NonNullable<ServerConfig['bodyParser']>): this {\n this.config.bodyParser = deepObjMerge({}, this.config.bodyParser ?? {}, opts);\n return this;\n }\n\n /**\n * Configures cookie parsing middleware.\n *\n * @param opts - Cookie parser options or boolean (true to enable with defaults, false to disable)\n * @returns The builder instance for chaining\n * @default false\n *\n * @example\n * ```typescript\n * // Enable cookie parsing with default options\n * builder.withCookies(true)\n *\n * // Enable cookie parsing with specific options\n * builder.withCookies({\n * secret: 'your-secret-key',\n * secure: true\n * })\n * ```\n */\n withCookies(opts: ServerConfig['cookieParser']): this {\n this.config.cookieParser = opts;\n return this;\n }\n\n /**\n * Adds a static folder to serve files from.\n *\n * @param folder - Static folder configuration\n * @returns The builder instance for chaining\n *\n * @example\n * ```typescript\n * builder.withStaticFolder({\n * path: '/assets',\n * directory: './public',\n * options: { maxAge: '1d' }\n * })\n * ```\n */\n withStaticFolder(folder: NonNullable<ServerConfig['staticFolders']>[number]): this {\n if (!folder.path) throw new Error('Static folder requires a path');\n const folders = [...(this.config.staticFolders ?? []), folder];\n this.config.staticFolders = Array.from(new Map(folders.map(f => [f.path, f])).values());\n return this;\n }\n\n /**\n * Sets global headers to be included in all responses.\n *\n * @param headers - Object containing header name/value pairs or functions that return values\n * @returns The builder instance for chaining\n * @default {}\n *\n * @example\n * ```typescript\n * builder.withGlobalHeaders({\n * 'X-Powered-By': 'Catbee',\n * 'Server-Time': () => new Date().toISOString()\n * })\n * ```\n */\n withGlobalHeaders(headers: NonNullable<ServerConfig['globalHeaders']>): this {\n this.mergeConfig('globalHeaders', headers);\n return this;\n }\n\n /**\n * Sets a global prefix for all routes.\n *\n * @param prefix - The prefix to prepend to all routes (e.g., '/api/v1')\n * @returns The builder instance for chaining\n * @default '/'\n *\n * @example\n * ```typescript\n * builder.withGlobalPrefix('/api/v1')\n * ```\n */\n withGlobalPrefix(prefix: string): this {\n this.config.globalPrefix = prefix;\n return this;\n }\n\n /**\n * Applies custom configuration overrides directly.\n *\n * @param overrides - Custom configuration options to merge\n * @returns The builder instance for chaining\n *\n * @example\n * ```typescript\n * builder.withCustom({\n * port: 8080,\n * customMiddleware: myMiddlewareFunction\n * })\n * ```\n */\n withCustom(overrides: Partial<ServerConfig>): this {\n this.config = deepObjMerge({}, this.config, overrides);\n return this;\n }\n\n /**\n * Configures HTTPS server options.\n *\n * @param opts - HTTPS configuration (key, cert, ca, passphrase, etc.)\n * @returns The builder instance for chaining\n *\n * @example\n * ```typescript\n * builder.withHttps({\n * key: './localhost-key.pem',\n * cert: './localhost-cert.pem'\n * })\n * ```\n */\n withHttps(opts: NonNullable<ServerConfig['https']>): this {\n this.config.https = opts;\n return this;\n }\n\n /**\n * Builds and returns the final server configuration.\n *\n * This method merges the user-specified configuration with default values,\n * ensures all sections with 'enable' flags are properly structured, and\n * produces the final configuration to be used by the server.\n *\n * @returns The complete ServerConfig object\n *\n * @example\n * ```typescript\n * const config = new ServerConfigBuilder()\n * .withPort(3000)\n * .withHost('localhost')\n * .withCors(true)\n * .build();\n * ```\n */\n build(): Readonly<ServerConfig> {\n const config = deepObjMerge({}, defaultServerConfig, this.config) as ServerConfig;\n\n // Common validation\n if (config.openApi?.enable && !config.openApi.filePath) {\n throw new Error('OpenAPI is enabled but no filePath is specified');\n }\n\n return Object.freeze({\n ...config,\n [BUILD_MARKER]: true\n });\n }\n\n private mergeConfig<K extends keyof ServerConfig>(key: K, value: Partial<NonNullable<ServerConfig[K]>>): void {\n const current =\n typeof this.config[key] === 'object' && this.config[key] !== null\n ? (this.config[key] as NonNullable<ServerConfig[K]>)\n : {};\n this.config[key] = deepObjMerge({}, current, value) as NonNullable<ServerConfig[K]>;\n }\n\n private setEnabled<K extends keyof ServerConfig>(\n key: K,\n enable: boolean,\n overrides: Partial<NonNullable<ServerConfig[K]>> = {}\n ): this {\n this.mergeConfig(key, { ...overrides, enable });\n return this;\n }\n}\n"]}
|
|
@@ -183,12 +183,12 @@ export declare class ExpressServer {
|
|
|
183
183
|
*
|
|
184
184
|
* @param signals Array of process signals to listen for (default: SIGINT, SIGTERM)
|
|
185
185
|
*/
|
|
186
|
-
enableGracefulShutdown(signals?: NodeJS.Signals[]):
|
|
186
|
+
enableGracefulShutdown(signals?: NodeJS.Signals[]): this;
|
|
187
187
|
/**
|
|
188
188
|
* Set an externally created base router.
|
|
189
189
|
* This will override the internal rootRouter.
|
|
190
190
|
*/
|
|
191
|
-
setBaseRouter(router: Router):
|
|
191
|
+
setBaseRouter(router: Router): this;
|
|
192
192
|
/**
|
|
193
193
|
* Create and register a new router (only used if not injecting one externally - use `setBaseRouter` instead).
|
|
194
194
|
*/
|
|
@@ -179,18 +179,6 @@ class ExpressServer {
|
|
|
179
179
|
if ((_b = config.healthCheck) === null || _b === void 0 ? void 0 : _b.checks) {
|
|
180
180
|
this.healthChecks.push(...config.healthCheck.checks);
|
|
181
181
|
}
|
|
182
|
-
// Logger
|
|
183
|
-
if (this.config.logger) {
|
|
184
|
-
const { name, level, prettyPrint: pretty, singleLine } = this.config.logger;
|
|
185
|
-
(0, config_1.setConfig)({
|
|
186
|
-
logger: {
|
|
187
|
-
name: name !== null && name !== void 0 ? name : 'express_app',
|
|
188
|
-
level: level !== null && level !== void 0 ? level : 'info',
|
|
189
|
-
pretty: pretty !== null && pretty !== void 0 ? pretty : env_utils_1.Env.isDev(),
|
|
190
|
-
singleLine: singleLine !== null && singleLine !== void 0 ? singleLine : false
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
182
|
// Set global prefix (normalize to empty string or "/prefix" without trailing slash)
|
|
195
183
|
this.globalPrefix = this.normalizePath((_c = this.config.globalPrefix) !== null && _c !== void 0 ? _c : '', false);
|
|
196
184
|
this.hooks = hooks;
|
|
@@ -762,6 +750,7 @@ class ExpressServer {
|
|
|
762
750
|
}
|
|
763
751
|
});
|
|
764
752
|
});
|
|
753
|
+
return this;
|
|
765
754
|
}
|
|
766
755
|
/**
|
|
767
756
|
* Set an externally created base router.
|
|
@@ -769,6 +758,7 @@ class ExpressServer {
|
|
|
769
758
|
*/
|
|
770
759
|
setBaseRouter(router) {
|
|
771
760
|
this.externalRouter = router;
|
|
761
|
+
return this;
|
|
772
762
|
}
|
|
773
763
|
/**
|
|
774
764
|
* Create and register a new router (only used if not injecting one externally - use `setBaseRouter` instead).
|