@catbee/utils 0.0.8-rc.2 → 0.0.8-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/build/cjs/config.d.ts +121 -0
  2. package/build/cjs/config.js +137 -0
  3. package/build/cjs/index.d.ts +26 -0
  4. package/build/cjs/index.js +68 -0
  5. package/build/cjs/servers/server.builder.d.ts +507 -0
  6. package/build/cjs/servers/server.builder.js +658 -0
  7. package/build/cjs/servers/server.d.ts +255 -0
  8. package/build/cjs/servers/server.js +970 -0
  9. package/build/cjs/types/api-response.d.ts +151 -0
  10. package/build/cjs/types/api-response.js +36 -0
  11. package/build/cjs/types/index.d.ts +124 -0
  12. package/build/cjs/types/index.js +25 -0
  13. package/build/cjs/types/server.d.ts +267 -0
  14. package/build/cjs/types/server.js +25 -0
  15. package/build/cjs/utils/array.utils.d.ts +167 -0
  16. package/build/cjs/utils/array.utils.js +363 -0
  17. package/build/cjs/utils/async.utils.d.ts +264 -0
  18. package/build/cjs/utils/async.utils.js +640 -0
  19. package/build/cjs/utils/cache.utils.d.ts +152 -0
  20. package/build/cjs/utils/cache.utils.js +298 -0
  21. package/build/cjs/utils/context-store.utils.d.ts +188 -0
  22. package/build/cjs/utils/context-store.utils.js +297 -0
  23. package/build/cjs/utils/crypto.utils.d.ts +159 -0
  24. package/build/cjs/utils/crypto.utils.js +295 -0
  25. package/build/cjs/utils/date.utils.d.ts +158 -0
  26. package/build/cjs/utils/date.utils.js +395 -0
  27. package/build/cjs/utils/decorators.utils.d.ts +511 -0
  28. package/build/cjs/utils/decorators.utils.js +1035 -0
  29. package/build/cjs/utils/dir.utils.d.ts +195 -0
  30. package/build/cjs/utils/dir.utils.js +500 -0
  31. package/build/cjs/utils/env.utils.d.ts +376 -0
  32. package/build/cjs/utils/env.utils.js +786 -0
  33. package/build/cjs/utils/exception.utils.d.ts +229 -0
  34. package/build/cjs/utils/exception.utils.js +408 -0
  35. package/build/cjs/utils/fs.utils.d.ts +163 -0
  36. package/build/cjs/utils/fs.utils.js +371 -0
  37. package/build/cjs/utils/http-status-codes.d.ts +265 -0
  38. package/build/cjs/utils/http-status-codes.js +297 -0
  39. package/build/cjs/utils/id.utils.d.ts +35 -0
  40. package/build/cjs/utils/id.utils.js +90 -0
  41. package/build/cjs/utils/logger.utils.d.ts +159 -0
  42. package/build/cjs/utils/logger.utils.js +350 -0
  43. package/build/cjs/utils/middleware.utils.d.ts +99 -0
  44. package/build/cjs/utils/middleware.utils.js +243 -0
  45. package/build/cjs/utils/obj.utils.d.ts +123 -0
  46. package/build/cjs/utils/obj.utils.js +428 -0
  47. package/build/cjs/utils/performance.utils.d.ts +135 -0
  48. package/build/cjs/utils/performance.utils.js +280 -0
  49. package/build/cjs/utils/request.utils.d.ts +85 -0
  50. package/build/cjs/utils/request.utils.js +199 -0
  51. package/build/cjs/utils/response.utils.d.ts +162 -0
  52. package/build/cjs/utils/response.utils.js +274 -0
  53. package/build/cjs/utils/stream.utils.d.ts +87 -0
  54. package/build/cjs/utils/stream.utils.js +217 -0
  55. package/build/cjs/utils/string.utils.d.ts +92 -0
  56. package/build/cjs/utils/string.utils.js +178 -0
  57. package/build/cjs/utils/type.utils.d.ts +89 -0
  58. package/build/cjs/utils/type.utils.js +195 -0
  59. package/build/cjs/utils/url.utils.d.ts +140 -0
  60. package/build/cjs/utils/url.utils.js +316 -0
  61. package/build/cjs/utils/validate.utils.d.ts +176 -0
  62. package/build/cjs/utils/validate.utils.js +344 -0
  63. package/build/esm/utils/context-store.utils.d.ts +1 -1
  64. package/build/esm/utils/context-store.utils.js +1 -1
  65. package/build/esm/utils/decorators.utils.js +1 -1
  66. package/package.json +287 -32
@@ -0,0 +1,121 @@
1
+ import { Logger, LoggerLevels } from './utils/logger.utils';
2
+ /**
3
+ * Extends Express Request interface to add request ID tracking.
4
+ * Added by requestId middleware during request processing.
5
+ */
6
+ declare global {
7
+ namespace Express {
8
+ interface Request {
9
+ /** Unique request identifier (set by middleware) */
10
+ id?: string;
11
+ /** Logger instance for the request (set by middleware) */
12
+ logger?: Logger;
13
+ /** User information (set by authentication middleware) */
14
+ user?: any;
15
+ }
16
+ }
17
+ }
18
+ /**
19
+ * Application runtime configuration loaded from environment variables.
20
+ */
21
+ export declare let config: {
22
+ logger: {
23
+ /**
24
+ * Logging level (e.g., 'info', 'debug', 'warn', 'error').
25
+ */
26
+ level: LoggerLevels;
27
+ /**
28
+ * Name of the logger instance (defaults to npm package name).
29
+ */
30
+ name: string;
31
+ /**
32
+ * Enables pretty-print logging in development.
33
+ * Has no effect in production.
34
+ */
35
+ pretty: boolean;
36
+ /**
37
+ * Single line output for pretty-print (default: false)
38
+ */
39
+ singleLine: boolean;
40
+ };
41
+ cache: {
42
+ /**
43
+ * Default TTL (time to live) for cache entries in seconds
44
+ */
45
+ defaultTtl: number;
46
+ };
47
+ };
48
+ export declare const defaultServerConfig: {
49
+ port: number;
50
+ host: string;
51
+ cors: false;
52
+ helmet: false;
53
+ compression: false;
54
+ bodyParser: {
55
+ json: {
56
+ limit: string;
57
+ };
58
+ urlencoded: {
59
+ extended: true;
60
+ limit: string;
61
+ };
62
+ };
63
+ cookieParser: false;
64
+ isMicroservice: false;
65
+ appName: string;
66
+ globalHeaders: {};
67
+ rateLimit: {
68
+ enable: false;
69
+ windowMs: number;
70
+ max: number;
71
+ message: string;
72
+ standardHeaders: true;
73
+ legacyHeaders: false;
74
+ };
75
+ requestLogging: {
76
+ enable: boolean;
77
+ ignorePaths: (req: import("express").Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>, _res: import("express").Response<any, Record<string, any>>) => boolean;
78
+ skipNotFoundRoutes: false;
79
+ };
80
+ openApi: {
81
+ enable: false;
82
+ mountPath: string;
83
+ verbose: false;
84
+ withGlobalPrefix: false;
85
+ };
86
+ healthCheck: {
87
+ path: string;
88
+ detailed: true;
89
+ };
90
+ requestTimeout: number;
91
+ responseTime: {
92
+ enable: false;
93
+ addHeader: true;
94
+ logOnComplete: false;
95
+ };
96
+ requestId: {
97
+ headerName: string;
98
+ exposeHeader: true;
99
+ generator: () => string;
100
+ };
101
+ metrics: {
102
+ enable: false;
103
+ path: string;
104
+ withGlobalPrefix: false;
105
+ };
106
+ serviceVersion: {
107
+ enable: false;
108
+ headerName: string;
109
+ version: string;
110
+ };
111
+ };
112
+ /**
113
+ * Update the @catbee/utils configuration.
114
+ * @param value Partial configuration object.
115
+ */
116
+ export declare function setConfig(value: Partial<typeof config>): void;
117
+ /**
118
+ * Get the current @catbee/utils configuration.
119
+ * @returns The current configuration object.
120
+ */
121
+ export declare function getConfig(): typeof config;
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ /*
3
+ * The MIT License
4
+ *
5
+ * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.defaultServerConfig = exports.config = void 0;
27
+ exports.setConfig = setConfig;
28
+ exports.getConfig = getConfig;
29
+ const env_utils_1 = require("./utils/env.utils");
30
+ const id_utils_1 = require("./utils/id.utils");
31
+ const obj_utils_1 = require("./utils/obj.utils");
32
+ /**
33
+ * Application runtime configuration loaded from environment variables.
34
+ */
35
+ exports.config = {
36
+ logger: {
37
+ /**
38
+ * Logging level (e.g., 'info', 'debug', 'warn', 'error').
39
+ */
40
+ level: env_utils_1.Env.get('LOGGER_LEVEL', 'info'),
41
+ /**
42
+ * Name of the logger instance (defaults to npm package name).
43
+ */
44
+ name: env_utils_1.Env.get('LOGGER_NAME', env_utils_1.Env.get('npm_package_name', '@catbee/utils')),
45
+ /**
46
+ * Enables pretty-print logging in development.
47
+ * Has no effect in production.
48
+ */
49
+ pretty: env_utils_1.Env.getBoolean('LOGGER_PRETTY', true),
50
+ /**
51
+ * Single line output for pretty-print (default: false)
52
+ */
53
+ singleLine: env_utils_1.Env.getBoolean('LOGGER_PRETTY_SINGLE_LINE', false)
54
+ },
55
+ cache: {
56
+ /**
57
+ * Default TTL (time to live) for cache entries in seconds
58
+ */
59
+ defaultTtl: env_utils_1.Env.getNumber('CACHE_DEFAULT_TTL_SECONDS', 3600) * 1000
60
+ }
61
+ };
62
+ exports.defaultServerConfig = {
63
+ port: 3000,
64
+ host: '0.0.0.0',
65
+ cors: false,
66
+ helmet: false,
67
+ compression: false,
68
+ bodyParser: {
69
+ json: { limit: '1mb' },
70
+ urlencoded: { extended: true, limit: '1mb' }
71
+ },
72
+ cookieParser: false,
73
+ isMicroservice: false,
74
+ appName: 'express_app',
75
+ globalHeaders: {},
76
+ rateLimit: {
77
+ enable: false,
78
+ windowMs: 15 * 60 * 1000,
79
+ max: 100,
80
+ message: 'Too many requests',
81
+ standardHeaders: true,
82
+ legacyHeaders: false
83
+ },
84
+ requestLogging: {
85
+ enable: env_utils_1.Env.isDev(),
86
+ ignorePaths: (req, _res) => {
87
+ const skipPaths = ['/healthz', '/favicon.ico', '/metrics', '/docs', '/.well-known'];
88
+ return skipPaths.some(path => req.path.startsWith(path));
89
+ },
90
+ skipNotFoundRoutes: false
91
+ },
92
+ openApi: {
93
+ enable: false,
94
+ mountPath: '/docs',
95
+ verbose: false,
96
+ withGlobalPrefix: false
97
+ },
98
+ healthCheck: {
99
+ path: '/healthz',
100
+ detailed: true
101
+ },
102
+ requestTimeout: 30000,
103
+ responseTime: {
104
+ enable: false,
105
+ addHeader: true,
106
+ logOnComplete: false
107
+ },
108
+ requestId: {
109
+ headerName: 'x-request-id',
110
+ exposeHeader: true,
111
+ generator: () => (0, id_utils_1.uuid)()
112
+ },
113
+ metrics: {
114
+ enable: false,
115
+ path: '/metrics',
116
+ withGlobalPrefix: false
117
+ },
118
+ serviceVersion: {
119
+ enable: false,
120
+ headerName: 'x-service-version',
121
+ version: '0.0.0'
122
+ }
123
+ };
124
+ /**
125
+ * Update the @catbee/utils configuration.
126
+ * @param value Partial configuration object.
127
+ */
128
+ function setConfig(value) {
129
+ (0, obj_utils_1.deepObjMerge)(exports.config, value);
130
+ }
131
+ /**
132
+ * Get the current @catbee/utils configuration.
133
+ * @returns The current configuration object.
134
+ */
135
+ function getConfig() {
136
+ return exports.config;
137
+ }
@@ -0,0 +1,26 @@
1
+ export { setConfig, getConfig } from './config';
2
+ export * from './utils/array.utils';
3
+ export * from './utils/async.utils';
4
+ export * from './utils/cache.utils';
5
+ export * from './utils/context-store.utils';
6
+ export * from './utils/crypto.utils';
7
+ export * from './utils/decorators.utils';
8
+ export * from './utils/dir.utils';
9
+ export * from './utils/env.utils';
10
+ export * from './utils/exception.utils';
11
+ export * from './utils/fs.utils';
12
+ export * from './utils/http-status-codes';
13
+ export * from './utils/id.utils';
14
+ export * from './utils/logger.utils';
15
+ export * from './utils/middleware.utils';
16
+ export * from './utils/obj.utils';
17
+ export * from './utils/request.utils';
18
+ export * from './utils/response.utils';
19
+ export * from './utils/string.utils';
20
+ export * from './utils/url.utils';
21
+ export * from './utils/validate.utils';
22
+ export * from './types/index';
23
+ export * from './types/server';
24
+ export * from './types/api-response';
25
+ export * from './servers/server';
26
+ export * from './servers/server.builder';
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /*
3
+ * The MIT License
4
+ *
5
+ * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ var desc = Object.getOwnPropertyDescriptor(m, k);
28
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
29
+ desc = { enumerable: true, get: function() { return m[k]; } };
30
+ }
31
+ Object.defineProperty(o, k2, desc);
32
+ }) : (function(o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ o[k2] = m[k];
35
+ }));
36
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
37
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.getConfig = exports.setConfig = void 0;
41
+ var config_1 = require("./config");
42
+ Object.defineProperty(exports, "setConfig", { enumerable: true, get: function () { return config_1.setConfig; } });
43
+ Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return config_1.getConfig; } });
44
+ __exportStar(require("./utils/array.utils"), exports);
45
+ __exportStar(require("./utils/async.utils"), exports);
46
+ __exportStar(require("./utils/cache.utils"), exports);
47
+ __exportStar(require("./utils/context-store.utils"), exports);
48
+ __exportStar(require("./utils/crypto.utils"), exports);
49
+ __exportStar(require("./utils/decorators.utils"), exports);
50
+ __exportStar(require("./utils/dir.utils"), exports);
51
+ __exportStar(require("./utils/env.utils"), exports);
52
+ __exportStar(require("./utils/exception.utils"), exports);
53
+ __exportStar(require("./utils/fs.utils"), exports);
54
+ __exportStar(require("./utils/http-status-codes"), exports);
55
+ __exportStar(require("./utils/id.utils"), exports);
56
+ __exportStar(require("./utils/logger.utils"), exports);
57
+ __exportStar(require("./utils/middleware.utils"), exports);
58
+ __exportStar(require("./utils/obj.utils"), exports);
59
+ __exportStar(require("./utils/request.utils"), exports);
60
+ __exportStar(require("./utils/response.utils"), exports);
61
+ __exportStar(require("./utils/string.utils"), exports);
62
+ __exportStar(require("./utils/url.utils"), exports);
63
+ __exportStar(require("./utils/validate.utils"), exports);
64
+ __exportStar(require("./types/index"), exports);
65
+ __exportStar(require("./types/server"), exports);
66
+ __exportStar(require("./types/api-response"), exports);
67
+ __exportStar(require("./servers/server"), exports);
68
+ __exportStar(require("./servers/server.builder"), exports);