@scpxl/nodejs-framework 1.0.50 → 1.0.56
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 +12 -7
- package/dist/api-requester/api-requester.js +1 -1
- package/dist/api-requester/api-requester.js.map +2 -2
- package/dist/api-requester/index.d.ts +1 -1
- package/dist/api-requester/index.d.ts.map +1 -1
- package/dist/api-requester/index.js.map +2 -2
- package/dist/application/base-application.d.ts +6 -5
- package/dist/application/base-application.d.ts.map +1 -1
- package/dist/application/base-application.interface.d.ts +2 -4
- package/dist/application/base-application.interface.d.ts.map +1 -1
- package/dist/application/base-application.js +17 -14
- package/dist/application/base-application.js.map +2 -2
- package/dist/application/command-application.d.ts.map +1 -1
- package/dist/application/command-application.js +2 -2
- package/dist/application/command-application.js.map +2 -2
- package/dist/application/index.d.ts +3 -3
- package/dist/application/index.d.ts.map +1 -1
- package/dist/application/index.js +4 -4
- package/dist/application/index.js.map +2 -2
- package/dist/application/web-application.d.ts +5 -5
- package/dist/application/web-application.d.ts.map +1 -1
- package/dist/application/web-application.js +6 -7
- package/dist/application/web-application.js.map +2 -2
- package/dist/application/worker-application.d.ts +2 -2
- package/dist/application/worker-application.d.ts.map +1 -1
- package/dist/application/worker-application.js +2 -2
- package/dist/application/worker-application.js.map +2 -2
- package/dist/auth/jwt.d.ts.map +1 -1
- package/dist/auth/jwt.js +2 -2
- package/dist/auth/jwt.js.map +2 -2
- package/dist/cache/manager.d.ts.map +1 -1
- package/dist/cache/manager.js.map +2 -2
- package/dist/cli/index.js +192 -7029
- package/dist/cli/index.js.map +4 -4
- package/dist/cluster/cluster-manager.d.ts.map +1 -1
- package/dist/cluster/cluster-manager.js +1 -1
- package/dist/cluster/cluster-manager.js.map +2 -2
- package/dist/command/command.d.ts +1 -1
- package/dist/command/command.d.ts.map +1 -1
- package/dist/command/command.js.map +2 -2
- package/dist/config/env.d.ts +1 -1
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/config/index.js.map +1 -1
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +1 -1
- package/dist/config/schema.js.map +2 -2
- package/dist/database/dynamic-entity.js +9 -9
- package/dist/database/dynamic-entity.js.map +2 -2
- package/dist/database/index.d.ts +3 -3
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +5 -5
- package/dist/database/index.js.map +2 -2
- package/dist/database/instance.d.ts +3 -3
- package/dist/database/instance.js +3 -3
- package/dist/database/instance.js.map +1 -1
- package/dist/database/manager.d.ts +1 -0
- package/dist/database/manager.d.ts.map +1 -1
- package/dist/database/manager.js +16 -3
- package/dist/database/manager.js.map +2 -2
- package/dist/error/error-reporter.js +1 -1
- package/dist/error/error-reporter.js.map +2 -2
- package/dist/error/index.d.ts +2 -3
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +8 -9
- package/dist/error/index.js.map +2 -2
- package/dist/event/controller/base.d.ts +2 -2
- package/dist/event/controller/base.d.ts.map +1 -1
- package/dist/event/controller/base.js +2 -2
- package/dist/event/controller/base.js.map +2 -2
- package/dist/event/index.d.ts +3 -3
- package/dist/event/index.d.ts.map +1 -1
- package/dist/event/index.js +5 -5
- package/dist/event/index.js.map +2 -2
- package/dist/event/manager.d.ts.map +1 -1
- package/dist/event/manager.interface.d.ts +2 -3
- package/dist/event/manager.interface.d.ts.map +1 -1
- package/dist/event/manager.js.map +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +2 -2
- package/dist/lifecycle/index.d.ts +3 -3
- package/dist/lifecycle/index.d.ts.map +1 -1
- package/dist/lifecycle/index.js +1 -1
- package/dist/lifecycle/index.js.map +2 -2
- package/dist/logger/logger.d.ts +20 -1
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +68 -96
- package/dist/logger/logger.js.map +2 -2
- package/dist/performance/cache-performance.d.ts.map +1 -1
- package/dist/performance/cache-performance.js +1 -1
- package/dist/performance/cache-performance.js.map +2 -2
- package/dist/performance/database-performance.d.ts.map +1 -1
- package/dist/performance/database-performance.js +1 -1
- package/dist/performance/database-performance.js.map +2 -2
- package/dist/performance/index.d.ts +3 -3
- package/dist/performance/index.d.ts.map +1 -1
- package/dist/performance/index.js +3 -3
- package/dist/performance/index.js.map +1 -1
- package/dist/performance/performance-monitor.js +2 -2
- package/dist/performance/performance-monitor.js.map +2 -2
- package/dist/performance/performance-monitor.plugin.d.ts.map +1 -1
- package/dist/performance/performance-monitor.plugin.js +1 -1
- package/dist/performance/performance-monitor.plugin.js.map +2 -2
- package/dist/performance/queue-performance.d.ts.map +1 -1
- package/dist/performance/queue-performance.js +1 -1
- package/dist/performance/queue-performance.js.map +2 -2
- package/dist/performance/webserver-performance.d.ts.map +1 -1
- package/dist/performance/webserver-performance.js +1 -1
- package/dist/performance/webserver-performance.js.map +2 -2
- package/dist/performance/websocket-performance.d.ts.map +1 -1
- package/dist/performance/websocket-performance.js +1 -1
- package/dist/performance/websocket-performance.js.map +2 -2
- package/dist/queue/index.d.ts +2 -2
- package/dist/queue/index.d.ts.map +1 -1
- package/dist/queue/index.interface.d.ts +1 -1
- package/dist/queue/index.interface.d.ts.map +1 -1
- package/dist/queue/index.js.map +2 -2
- package/dist/queue/manager.d.ts +3 -2
- package/dist/queue/manager.d.ts.map +1 -1
- package/dist/queue/manager.js +5 -2
- package/dist/queue/manager.js.map +2 -2
- package/dist/queue/processor/base.d.ts +5 -5
- package/dist/queue/processor/base.d.ts.map +1 -1
- package/dist/queue/processor/base.js +2 -2
- package/dist/queue/processor/base.js.map +2 -2
- package/dist/queue/processor/processor.interface.d.ts +3 -3
- package/dist/queue/processor/processor.interface.d.ts.map +1 -1
- package/dist/queue/worker.d.ts.map +1 -1
- package/dist/queue/worker.interface.d.ts +1 -1
- package/dist/queue/worker.interface.d.ts.map +1 -1
- package/dist/queue/worker.js +1 -1
- package/dist/queue/worker.js.map +2 -2
- package/dist/redis/index.d.ts +1 -1
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js +4 -4
- package/dist/redis/index.js.map +2 -2
- package/dist/redis/manager.d.ts +2 -1
- package/dist/redis/manager.d.ts.map +1 -1
- package/dist/redis/manager.js +7 -4
- package/dist/redis/manager.js.map +2 -2
- package/dist/request-context/index.d.ts +1 -1
- package/dist/request-context/index.d.ts.map +1 -1
- package/dist/request-context/index.js +5 -5
- package/dist/request-context/index.js.map +1 -1
- package/dist/schemas/entity-builder.d.ts +3 -3
- package/dist/schemas/entity-builder.d.ts.map +1 -1
- package/dist/schemas/entity-builder.js.map +1 -1
- package/dist/services/aws/s3.d.ts.map +1 -1
- package/dist/services/aws/s3.js +7 -10
- package/dist/services/aws/s3.js.map +2 -2
- package/dist/util/file.d.ts +0 -6
- package/dist/util/file.d.ts.map +1 -1
- package/dist/util/file.js +6 -28
- package/dist/util/file.js.map +2 -2
- package/dist/util/helper.js +2 -2
- package/dist/util/helper.js.map +2 -2
- package/dist/util/index.d.ts +2 -2
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +18 -18
- package/dist/util/index.js.map +2 -2
- package/dist/util/loader.js +3 -3
- package/dist/util/loader.js.map +2 -2
- package/dist/util/os.js +2 -2
- package/dist/util/os.js.map +2 -2
- package/dist/webserver/controller/auth-middleware.d.ts +1 -1
- package/dist/webserver/controller/auth-middleware.d.ts.map +1 -1
- package/dist/webserver/controller/auth-middleware.js +1 -1
- package/dist/webserver/controller/auth-middleware.js.map +2 -2
- package/dist/webserver/controller/base.d.ts +6 -6
- package/dist/webserver/controller/base.d.ts.map +1 -1
- package/dist/webserver/controller/base.interface.d.ts +1 -1
- package/dist/webserver/controller/base.interface.d.ts.map +1 -1
- package/dist/webserver/controller/base.js +4 -4
- package/dist/webserver/controller/base.js.map +2 -2
- package/dist/webserver/controller/entity.d.ts +3 -3
- package/dist/webserver/controller/entity.d.ts.map +1 -1
- package/dist/webserver/controller/entity.js +19 -17
- package/dist/webserver/controller/entity.js.map +2 -2
- package/dist/webserver/controller/example-auth.d.ts.map +1 -1
- package/dist/webserver/controller/example-auth.js +1 -1
- package/dist/webserver/controller/example-auth.js.map +2 -2
- package/dist/webserver/controller/health.d.ts.map +1 -1
- package/dist/webserver/controller/health.js +1 -1
- package/dist/webserver/controller/health.js.map +2 -2
- package/dist/webserver/define-action.d.ts +1 -1
- package/dist/webserver/define-action.d.ts.map +1 -1
- package/dist/webserver/define-action.js.map +1 -1
- package/dist/webserver/define-route.d.ts +1 -1
- package/dist/webserver/define-route.d.ts.map +1 -1
- package/dist/webserver/define-route.js.map +2 -2
- package/dist/webserver/index.d.ts +9 -9
- package/dist/webserver/index.d.ts.map +1 -1
- package/dist/webserver/index.js +14 -14
- package/dist/webserver/index.js.map +2 -2
- package/dist/webserver/webserver.d.ts +3 -3
- package/dist/webserver/webserver.d.ts.map +1 -1
- package/dist/webserver/webserver.interface.d.ts +5 -5
- package/dist/webserver/webserver.interface.d.ts.map +1 -1
- package/dist/webserver/webserver.interface.js.map +1 -1
- package/dist/webserver/webserver.js +9 -9
- package/dist/webserver/webserver.js.map +2 -2
- package/dist/websocket/controller/server/base.d.ts +2 -2
- package/dist/websocket/controller/server/base.js.map +1 -1
- package/dist/websocket/controllers/server/system.d.ts.map +1 -1
- package/dist/websocket/controllers/server/system.js +1 -1
- package/dist/websocket/controllers/server/system.js.map +2 -2
- package/dist/websocket/index.d.ts +9 -11
- package/dist/websocket/index.d.ts.map +1 -1
- package/dist/websocket/index.js +22 -22
- package/dist/websocket/index.js.map +2 -2
- package/dist/websocket/subscriber-middleware.d.ts.map +1 -1
- package/dist/websocket/subscriber-middleware.js.map +2 -2
- package/dist/websocket/subscriber-utils.d.ts.map +1 -1
- package/dist/websocket/subscriber-utils.js.map +2 -2
- package/dist/websocket/utils.d.ts.map +1 -1
- package/dist/websocket/utils.js +4 -2
- package/dist/websocket/utils.js.map +2 -2
- package/dist/websocket/websocket-auth.d.ts.map +1 -1
- package/dist/websocket/websocket-auth.js +3 -3
- package/dist/websocket/websocket-auth.js.map +2 -2
- package/dist/websocket/websocket-base.d.ts +2 -2
- package/dist/websocket/websocket-base.d.ts.map +1 -1
- package/dist/websocket/websocket-base.js +1 -1
- package/dist/websocket/websocket-base.js.map +2 -2
- package/dist/websocket/websocket-client-manager.d.ts.map +1 -1
- package/dist/websocket/websocket-client-manager.js +3 -3
- package/dist/websocket/websocket-client-manager.js.map +2 -2
- package/dist/websocket/websocket-client.d.ts +5 -5
- package/dist/websocket/websocket-client.d.ts.map +1 -1
- package/dist/websocket/websocket-client.js +5 -5
- package/dist/websocket/websocket-client.js.map +2 -2
- package/dist/websocket/websocket-room-manager.js +1 -1
- package/dist/websocket/websocket-room-manager.js.map +1 -1
- package/dist/websocket/websocket-server.d.ts +7 -7
- package/dist/websocket/websocket-server.d.ts.map +1 -1
- package/dist/websocket/websocket-server.js +25 -20
- package/dist/websocket/websocket-server.js.map +2 -2
- package/dist/websocket/websocket-service.d.ts +2 -2
- package/dist/websocket/websocket-service.d.ts.map +1 -1
- package/dist/websocket/websocket-service.js +1 -1
- package/dist/websocket/websocket-service.js.map +2 -2
- package/dist/websocket/websocket.interface.d.ts +3 -5
- package/dist/websocket/websocket.interface.d.ts.map +1 -1
- package/dist/websocket/websocket.interface.js.map +2 -2
- package/package.json +68 -64
package/dist/util/file.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/file.ts"],
|
|
4
|
-
"sourcesContent": ["import * as fs from 'fs';\nimport { access, mkdir } from 'fs/promises';\nimport * as
|
|
5
|
-
"mappings": ";;AAAA,YAAY,QAAQ;AACpB,SAAS,QAAQ,aAAa;AAC9B,YAAY,
|
|
4
|
+
"sourcesContent": ["import * as fs from 'node:fs';\nimport { access, mkdir } from 'node:fs/promises';\nimport * as https from 'node:https';\nimport * as path from 'node:path';\nimport { pipeline } from 'node:stream';\nimport { promisify } from 'node:util';\n\nconst pipelineAsync = promisify(pipeline);\n\n/**\n * Check if a file or directory exists asynchronously\n * @param pathToCheck - Path to check\n * @returns Promise<boolean> - true if exists, false otherwise\n */\nasync function pathExists(pathToCheck: string): Promise<boolean> {\n try {\n await access(pathToCheck);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Ensure directory exists, create if it doesn't\n * @param dirPath - Directory path to ensure\n */\nasync function ensureDir(dirPath: string): Promise<void> {\n try {\n await access(dirPath);\n } catch {\n await mkdir(dirPath, { recursive: true });\n }\n}\n\n/**\n * Copy a file or directory synchronously.\n *\n * **Note**: This function uses synchronous file system operations which block\n * the event loop. It is intended for use during application initialization,\n * build scripts, or CLI tools where blocking is acceptable.\n * For production runtime code with high concurrency, consider using async alternatives.\n *\n * @param src The source path\n * @param dest The destination path\n */\nfunction copySync(src: string, dest: string): void {\n const stats = fs.statSync(src);\n\n if (stats.isDirectory()) {\n // Create destination directory if it doesn't exist\n if (!fs.existsSync(dest)) {\n fs.mkdirSync(dest);\n }\n\n // Read directory contents\n for (const entry of fs.readdirSync(src)) {\n const srcPath = path.join(src, entry);\n const destPath = path.join(dest, entry);\n copySync(srcPath, destPath);\n }\n } else {\n // Copy file\n fs.copyFileSync(src, dest);\n }\n}\n\n/**\n * Download file from URL\n *\n * @param url The URL to download the file from\n * @param destinationPath The path to save the downloaded file\n */\nasync function downloadFile({ url, destinationPath }: { url: string; destinationPath: string }): Promise<void> {\n return new Promise((resolve, reject) => {\n const file = fs.createWriteStream(destinationPath);\n\n https\n .get(url, response => {\n // Check if response status is OK (200\u2013299)\n if (response.statusCode && response.statusCode >= 200 && response.statusCode < 300) {\n pipelineAsync(response, file)\n .then(() => resolve())\n .catch(err => {\n fs.unlink(destinationPath, () => reject(err)); // Clean up partially written file on error\n });\n } else {\n fs.unlink(destinationPath, () => {\n reject(new Error(`Failed to download file, status code: ${response.statusCode}`));\n });\n }\n })\n .on('error', err => {\n fs.unlink(destinationPath, () => reject(err)); // Handle request errors\n });\n\n // Handle file stream errors\n file.on('error', err => {\n fs.unlink(destinationPath, () => reject(err));\n });\n });\n}\n\n/**\n * Format file size.\n *\n * @param bytes The file size in bytes\n */\nfunction formatFileSize({ bytes }: { bytes: number }): string {\n if (bytes === 0) return '0 bytes';\n const units = ['bytes', 'kB', 'MB', 'GB', 'TB'] as const;\n let idx = Math.floor(Math.log(bytes) / Math.log(1024));\n if (idx < 0) idx = 0;\n if (idx >= units.length) idx = units.length - 1;\n const fileSize = (bytes / 1024 ** idx).toFixed(1);\n let unit: string;\n switch (idx) {\n case 0:\n unit = 'bytes';\n break;\n case 1:\n unit = 'kB';\n break;\n case 2:\n unit = 'MB';\n break;\n case 3:\n unit = 'GB';\n break;\n default:\n unit = 'TB';\n }\n return `${fileSize} ${unit}`;\n}\n\n/**\n * Remove a file or directory synchronously.\n *\n * **Note**: This function uses synchronous file system operations which block\n * the event loop. It is intended for use during application cleanup, build scripts,\n * or CLI tools where blocking is acceptable.\n * For production runtime code with high concurrency, consider using async alternatives\n * like `fs.promises.rm(target, { recursive: true, force: true })`.\n *\n * @param target The path to the file or directory to remove\n */\nfunction removeSync(target: string): void {\n if (fs.existsSync(target)) {\n const stats = fs.statSync(target);\n\n if (stats.isDirectory()) {\n // Read the directory contents\n for (const entry of fs.readdirSync(target)) {\n const entryPath = path.join(target, entry);\n removeSync(entryPath);\n }\n\n // Remove the directory itself\n fs.rmdirSync(target);\n } else {\n // Remove the file\n fs.unlinkSync(target);\n }\n } else {\n console.warn(`Path ${target} does not exist.`);\n }\n}\n\nexport default {\n copySync,\n downloadFile,\n formatFileSize,\n removeSync,\n pathExists,\n ensureDir,\n};\n"],
|
|
5
|
+
"mappings": ";;AAAA,YAAY,QAAQ;AACpB,SAAS,QAAQ,aAAa;AAC9B,YAAY,WAAW;AACvB,YAAY,UAAU;AACtB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;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,IAAO,eAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/util/helper.js
CHANGED
|
@@ -45,7 +45,7 @@ function mergeObjects(target, source) {
|
|
|
45
45
|
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
46
46
|
continue;
|
|
47
47
|
}
|
|
48
|
-
if (!Object.
|
|
48
|
+
if (!Object.hasOwn(source, key)) {
|
|
49
49
|
continue;
|
|
50
50
|
}
|
|
51
51
|
const sourceValue = source[key];
|
|
@@ -84,7 +84,7 @@ function getValueFromObject(obj, path) {
|
|
|
84
84
|
let current = obj;
|
|
85
85
|
for (const part of parts) {
|
|
86
86
|
if (part === "__proto__" || part === "constructor" || part === "prototype") return void 0;
|
|
87
|
-
if (!current || !Object.
|
|
87
|
+
if (!current || !Object.hasOwn(current, part)) return void 0;
|
|
88
88
|
current = current[part];
|
|
89
89
|
}
|
|
90
90
|
return current;
|
package/dist/util/helper.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/helper.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Deep merge objects with defaults, preventing prototype pollution.\n *\n * This function:\n * - Recursively merges source objects into the target\n * - Preserves existing values in target (acts like defaults)\n * - Sanitizes sources to remove dangerous keys (__proto__, constructor, prototype)\n * - Prevents prototype pollution attacks\n *\n * @param target - The target object to merge into\n * @param sources - Source objects providing default values\n * @returns The merged target object (mutated)\n *\n * @example\n * const userConfig = { host: 'localhost' };\n * const defaults = { host: '0.0.0.0', port: 3001 };\n * const merged = defaultsDeep(userConfig, defaults);\n * // merged = { host: 'localhost', port: 3001 }\n */\nfunction defaultsDeep<T extends object>(target: T, ...sources: Array<Partial<T>>): T {\n // Handle null/undefined target by converting to empty object\n let result = target;\n if (target === null || target === undefined) {\n result = {} as T;\n }\n\n // Process each source\n for (const source of sources) {\n if (!isObject(source) && !Array.isArray(source)) continue;\n\n // Recursively merge source into target\n mergeObjects(result, source);\n }\n\n return result;\n}\n\n/**\n * Recursively merge source into target, preserving target values.\n * This acts like defaultsDeep - only fills in missing values from source.\n */\nfunction mergeObjects(target: any, source: any): void {\n // Handle arrays specially - merge by index\n if (Array.isArray(source)) {\n // If target is not an array but source is, treat target as object with numeric keys\n if (!Array.isArray(target)) {\n // Merge array into object-like target\n for (let i = 0; i < source.length; i++) {\n const key = String(i);\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue;\n\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[i];\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[key];\n\n // Check if key exists in target\n const keyExists = key in target;\n\n if (keyExists && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n } else if (!keyExists || targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[key] = isObject(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n }\n return;\n }\n\n // Both are arrays - merge by index\n for (let i = 0; i < source.length; i++) {\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[i];\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[i];\n\n // Check if index exists in target (not just if value is undefined)\n const indexExists = i in target;\n\n // If index exists and both values are objects, merge them\n if (indexExists && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If index doesn't exist or value is undefined, fill from source\n else if (!indexExists || targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[i] = isObject(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n // Otherwise, keep target's existing value\n }\n return;\n }\n\n // Regular object merging\n for (const key of Object.keys(source)) {\n // Block dangerous keys to prevent prototype pollution\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // Only use hasOwnProperty for safer property access\n if (!Object.
|
|
5
|
-
"mappings": ";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AK,MAAM,GAAG;AAErC,QAAI,QAAQ,eAAe,QAAQ,iBAAiB,QAAQ,aAAa;AACvE;AAAA,IACF;AAGA,QAAI,CAAC,OAAO,
|
|
4
|
+
"sourcesContent": ["/**\n * Deep merge objects with defaults, preventing prototype pollution.\n *\n * This function:\n * - Recursively merges source objects into the target\n * - Preserves existing values in target (acts like defaults)\n * - Sanitizes sources to remove dangerous keys (__proto__, constructor, prototype)\n * - Prevents prototype pollution attacks\n *\n * @param target - The target object to merge into\n * @param sources - Source objects providing default values\n * @returns The merged target object (mutated)\n *\n * @example\n * const userConfig = { host: 'localhost' };\n * const defaults = { host: '0.0.0.0', port: 3001 };\n * const merged = defaultsDeep(userConfig, defaults);\n * // merged = { host: 'localhost', port: 3001 }\n */\nfunction defaultsDeep<T extends object>(target: T, ...sources: Array<Partial<T>>): T {\n // Handle null/undefined target by converting to empty object\n let result = target;\n if (target === null || target === undefined) {\n result = {} as T;\n }\n\n // Process each source\n for (const source of sources) {\n if (!isObject(source) && !Array.isArray(source)) continue;\n\n // Recursively merge source into target\n mergeObjects(result, source);\n }\n\n return result;\n}\n\n/**\n * Recursively merge source into target, preserving target values.\n * This acts like defaultsDeep - only fills in missing values from source.\n */\nfunction mergeObjects(target: any, source: any): void {\n // Handle arrays specially - merge by index\n if (Array.isArray(source)) {\n // If target is not an array but source is, treat target as object with numeric keys\n if (!Array.isArray(target)) {\n // Merge array into object-like target\n for (let i = 0; i < source.length; i++) {\n const key = String(i);\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') continue;\n\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[i];\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[key];\n\n // Check if key exists in target\n const keyExists = key in target;\n\n if (keyExists && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n } else if (!keyExists || targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[key] = isObject(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n }\n return;\n }\n\n // Both are arrays - merge by index\n for (let i = 0; i < source.length; i++) {\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[i];\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[i];\n\n // Check if index exists in target (not just if value is undefined)\n const indexExists = i in target;\n\n // If index exists and both values are objects, merge them\n if (indexExists && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If index doesn't exist or value is undefined, fill from source\n else if (!indexExists || targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[i] = isObject(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n // Otherwise, keep target's existing value\n }\n return;\n }\n\n // Regular object merging\n for (const key of Object.keys(source)) {\n // Block dangerous keys to prevent prototype pollution\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // Only use hasOwnProperty for safer property access\n if (!Object.hasOwn(source, key)) {\n continue;\n }\n\n // Access guarded by ownProperty check and blocked prototype keys\n // eslint-disable-next-line security/detect-object-injection\n const sourceValue = source[key];\n\n // eslint-disable-next-line security/detect-object-injection\n const targetValue = target[key];\n\n // If both are arrays, merge them by index\n if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If target is object and source is array, merge array into object by numeric keys\n else if (isObject(targetValue) && Array.isArray(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If target value exists and both are objects (not arrays), recurse\n else if (targetValue !== undefined && isObject(targetValue) && isObject(sourceValue)) {\n mergeObjects(targetValue, sourceValue);\n }\n // If target doesn't have this key, set it from source\n else if (targetValue === undefined) {\n // eslint-disable-next-line security/detect-object-injection\n target[key] = isObject(sourceValue) || Array.isArray(sourceValue) ? deepClone(sourceValue) : sourceValue;\n }\n // Otherwise, keep target's existing value (defaultsDeep behavior)\n }\n}\n\n/**\n * Deep clone an object to avoid reference sharing.\n */\nfunction deepClone<T>(obj: T): T {\n if (!isObject(obj)) return obj;\n\n const cloned: any = Array.isArray(obj) ? [] : {};\n\n for (const key of Object.keys(obj)) {\n // Block dangerous keys\n if (key === '__proto__' || key === 'constructor' || key === 'prototype') {\n continue;\n }\n\n // eslint-disable-next-line security/detect-object-injection\n const value = (obj as any)[key];\n\n // eslint-disable-next-line security/detect-object-injection\n cloned[key] = isObject(value) ? deepClone(value) : value;\n }\n\n return cloned;\n}\n\n/**\n * Check if a value is an object.\n */\nfunction isObject(item: unknown): item is Record<string, unknown> {\n return item !== null && typeof item === 'object' && !Array.isArray(item);\n}\n\ntype AnyObject = Record<string, unknown>;\n\n/**\n * Retrieves the value from an object using a dotted key path safely.\n *\n * @param obj - The object to retrieve the value from.\n * @param path - The dotted key path (e.g., 'user.email').\n * @returns The value at the specified key path or undefined if not found.\n */\nfunction getValueFromObject(obj: AnyObject, path: string): unknown {\n const parts = path.split('.');\n let current: any = obj;\n for (const part of parts) {\n if (part === '__proto__' || part === 'constructor' || part === 'prototype') return undefined;\n if (!current || !Object.hasOwn(current, part)) return undefined;\n // Access guarded by ownProperty check and blocked prototype keys\n // eslint-disable-next-line security/detect-object-injection\n current = (current as Record<string, any>)[part];\n }\n return current;\n}\n\n/**\n * Retrieves the value from an array of objects using a dotted key path.\n *\n * @param arr - The array of objects.\n * @param path - The dotted key path (e.g., 'user.email').\n * @returns An array of values at the specified key path from each object.\n */\nfunction getValueFromArray(arr: AnyObject[], path: string): unknown[] {\n return arr.map(obj => getValueFromObject(obj, path));\n}\n\nfunction getScriptFileExtension(): string {\n return process.env.NODE_ENV === 'development' ? 'ts' : 'js';\n}\n\nexport default {\n defaultsDeep,\n isObject,\n getValueFromArray,\n getValueFromObject,\n getScriptFileExtension,\n};\n"],
|
|
5
|
+
"mappings": ";;AAmBA,SAAS,aAA+B,WAAc,SAA+B;AAEnF,MAAI,SAAS;AACb,MAAI,WAAW,QAAQ,WAAW,QAAW;AAC3C,aAAS,CAAC;AAAA,EACZ;AAGA,aAAW,UAAU,SAAS;AAC5B,QAA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A,EACjD;AACA,SAAO;AACT;AAXS;AAoBT,SAAS,kBAAkB,KAAkB,MAAyB;AACpE,SAAO,IAAI,IAAI,SAAO,mBAAmB,KAAK,IAAI,CAAC;AACrD;AAFS;AAIT,SAAS,yBAAiC;AACxC,SAAO,QAAQ,IAAI,aAAa,gBAAgB,OAAO;AACzD;AAFS;AAIT,IAAO,iBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
export { default as Time } from './time.js';
|
|
2
|
-
export { default as Timing } from './timing.js';
|
|
3
1
|
export { default as File } from './file.js';
|
|
4
2
|
export { default as Helper } from './helper.js';
|
|
5
3
|
export { default as Image } from './image.js';
|
|
@@ -7,5 +5,7 @@ export { default as Loader } from './loader.js';
|
|
|
7
5
|
export { default as Num } from './num.js';
|
|
8
6
|
export { default as OS } from './os.js';
|
|
9
7
|
export { default as Str } from './str.js';
|
|
8
|
+
export { default as Time } from './time.js';
|
|
9
|
+
export { default as Timing } from './timing.js';
|
|
10
10
|
export { default as URL } from './url.js';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/util/index.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { default as default2 } from "./
|
|
2
|
-
import { default as default3 } from "./
|
|
3
|
-
import { default as default4 } from "./
|
|
4
|
-
import { default as default5 } from "./
|
|
5
|
-
import { default as default6 } from "./
|
|
6
|
-
import { default as default7 } from "./
|
|
7
|
-
import { default as default8 } from "./
|
|
8
|
-
import { default as default9 } from "./
|
|
9
|
-
import { default as default10 } from "./
|
|
1
|
+
import { default as default2 } from "./file.js";
|
|
2
|
+
import { default as default3 } from "./helper.js";
|
|
3
|
+
import { default as default4 } from "./image.js";
|
|
4
|
+
import { default as default5 } from "./loader.js";
|
|
5
|
+
import { default as default6 } from "./num.js";
|
|
6
|
+
import { default as default7 } from "./os.js";
|
|
7
|
+
import { default as default8 } from "./str.js";
|
|
8
|
+
import { default as default9 } from "./time.js";
|
|
9
|
+
import { default as default10 } from "./timing.js";
|
|
10
10
|
import { default as default11 } from "./url.js";
|
|
11
11
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
default2 as File,
|
|
13
|
+
default3 as Helper,
|
|
14
|
+
default4 as Image,
|
|
15
|
+
default5 as Loader,
|
|
16
|
+
default6 as Num,
|
|
17
|
+
default7 as OS,
|
|
18
|
+
default8 as Str,
|
|
19
|
+
default9 as Time,
|
|
20
|
+
default10 as Timing,
|
|
21
21
|
default11 as URL
|
|
22
22
|
};
|
|
23
23
|
//# sourceMappingURL=index.js.map
|
package/dist/util/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { default as
|
|
5
|
-
"mappings": "AAAA,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,
|
|
4
|
+
"sourcesContent": ["export { default as File } from './file.js';\nexport { default as Helper } from './helper.js';\nexport { default as Image } from './image.js';\nexport { default as Loader } from './loader.js';\nexport { default as Num } from './num.js';\nexport { default as OS } from './os.js';\nexport { default as Str } from './str.js';\nexport { default as Time } from './time.js';\nexport { default as Timing } from './timing.js';\nexport { default as URL } from './url.js';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,gBAAwB;AACjC,SAAoB,WAAXA,gBAAyB;AAClC,SAAoB,WAAXA,gBAAsB;AAC/B,SAAoB,WAAXA,gBAAqB;AAC9B,SAAoB,WAAXA,gBAAsB;AAC/B,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,iBAAyB;AAClC,SAAoB,WAAXA,iBAAsB;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
package/dist/util/loader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
5
|
import { LRUCache } from "lru-cache";
|
|
6
6
|
import { Helper } from "./index.js";
|
|
7
7
|
const moduleCache = new LRUCache({
|
|
@@ -69,7 +69,7 @@ const loadEntityModule = /* @__PURE__ */ __name(async ({
|
|
|
69
69
|
if (entityName === "__proto__" || entityName === "constructor" || entityName === "prototype") {
|
|
70
70
|
throw new Error(`Invalid entity name (Entity: ${entityName})`);
|
|
71
71
|
}
|
|
72
|
-
if (!entityModule || !Object.
|
|
72
|
+
if (!entityModule || !Object.hasOwn(entityModule, entityName)) {
|
|
73
73
|
throw new Error(`Entity not found (Entity: ${entityName})`);
|
|
74
74
|
}
|
|
75
75
|
const EntityClass = Reflect.get(entityModule, entityName);
|
package/dist/util/loader.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/loader.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'fs';\nimport path from 'path';\nimport { LRUCache } from 'lru-cache';\nimport { Helper } from './index.js';\n\n// Type for a map of loaded modules\nexport interface ModuleMap<T = unknown> {\n [key: string]: T;\n}\n\n// Cache for loaded modules to avoid repeated imports\n// Using LRU cache to prevent unbounded memory growth in long-running processes\nconst moduleCache = new LRUCache<string, ModuleMap>({\n max: 100, // Max 100 directories cached\n ttl: 1000 * 60 * 10, // 10 minutes\n});\n\nconst entityCache = new LRUCache<string, EntityClass>({\n max: 500, // Max 500 entities cached (accessed more frequently than modules)\n ttl: 1000 * 60 * 10, // 10 minutes\n});\n\nconst loadModulesInDirectory = async <T = unknown>({\n directory,\n extensions,\n}: {\n directory: string;\n extensions?: string[];\n}): Promise<ModuleMap<T>> => {\n // Create cache key based on directory and extensions\n const cacheKey = `${directory}:${extensions?.join(',') ?? 'all'}`;\n\n // Check cache first\n if (moduleCache.has(cacheKey)) {\n const cachedModule = moduleCache.get(cacheKey);\n if (cachedModule) {\n return cachedModule as ModuleMap<T>;\n }\n }\n\n const loadedModules: ModuleMap<T> = {};\n\n // Use readdir with withFileTypes option to avoid separate stat calls\n const dirents = await fs.promises.readdir(directory, { withFileTypes: true });\n\n for (const dirent of dirents) {\n // Skip directories without needing stat call\n if (dirent.isDirectory()) {\n continue;\n }\n\n const file = dirent.name;\n const ext = path.extname(file);\n const isDeclarationFile = file.endsWith('.d.ts');\n\n // Skip files that are not in the specified extensions or are .d.ts files\n if ((extensions && extensions.length > 0 && !extensions.includes(ext)) || isDeclarationFile) {\n continue;\n }\n\n const moduleName = path.basename(file, ext);\n const filePath = path.join(directory, file);\n // Convert to absolute path for ESM import\n const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(filePath);\n // Use file:// URL for Windows compatibility\n const fileUrl = `file://${absolutePath.replace(/\\\\/g, '/')}`;\n\n try {\n const importedModule = await import(fileUrl);\n\n // Use safe property assignment to prevent prototype pollution\n if (moduleName !== '__proto__' && moduleName !== 'constructor' && moduleName !== 'prototype') {\n // Prefer default export, but fall back to the entire module if no default\n const moduleExport = importedModule.default ?? importedModule;\n Reflect.set(loadedModules, moduleName, moduleExport);\n }\n } catch (error) {\n // Note: console.error used here as Logger may not be initialized during early bootstrap\n console.error(`Failed to import module ${filePath}:`, error);\n }\n }\n\n // Cache the results for future use\n moduleCache.set(cacheKey, loadedModules);\n\n return loadedModules;\n};\n\n// Type constraint for entity classes (must be constructable)\nexport type EntityClass<T = unknown> = new (...args: unknown[]) => T;\n\nconst loadEntityModule = async <T = unknown>({\n entitiesDirectory,\n entityName,\n}: {\n entitiesDirectory: string;\n entityName: string;\n}): Promise<EntityClass<T>> => {\n // Create cache key based on directory and entity name\n const cacheKey = `${entitiesDirectory}:${entityName}`;\n\n // Check cache first\n if (entityCache.has(cacheKey)) {\n return entityCache.get(cacheKey) as EntityClass<T>;\n }\n\n // Define entity module path\n const entityModulePath = path.join(entitiesDirectory, `${entityName}.${Helper.getScriptFileExtension()}`);\n\n // Import entity module\n const entityModule = await import(entityModulePath);\n\n // Safe property access to prevent prototype pollution\n if (entityName === '__proto__' || entityName === 'constructor' || entityName === 'prototype') {\n throw new Error(`Invalid entity name (Entity: ${entityName})`);\n }\n\n if (!entityModule || !Object.
|
|
5
|
-
"mappings": ";;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AASvB,MAAM,cAAc,IAAI,SAA4B;AAAA,EAClD,KAAK;AAAA;AAAA,EACL,KAAK,MAAO,KAAK;AAAA;AACnB,CAAC;AAED,MAAM,cAAc,IAAI,SAA8B;AAAA,EACpD,KAAK;AAAA;AAAA,EACL,KAAK,MAAO,KAAK;AAAA;AACnB,CAAC;AAED,MAAM,yBAAyB,8BAAoB;AAAA,EACjD;AAAA,EACA;AACF,MAG6B;AAE3B,QAAM,WAAW,GAAG,SAAS,IAAI,YAAY,KAAK,GAAG,KAAK,KAAK;AAG/D,MAAI,YAAY,IAAI,QAAQ,GAAG;AAC7B,UAAM,eAAe,YAAY,IAAI,QAAQ;AAC7C,QAAI,cAAc;AAChB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,QAAM,gBAA8B,CAAC;AAGrC,QAAM,UAAU,MAAM,GAAG,SAAS,QAAQ,WAAW,EAAE,eAAe,KAAK,CAAC;AAE5E,aAAW,UAAU,SAAS;AAE5B,QAAI,OAAO,YAAY,GAAG;AACxB;AAAA,IACF;AAEA,UAAM,OAAO,OAAO;AACpB,UAAM,MAAM,KAAK,QAAQ,IAAI;AAC7B,UAAM,oBAAoB,KAAK,SAAS,OAAO;AAG/C,QAAK,cAAc,WAAW,SAAS,KAAK,CAAC,WAAW,SAAS,GAAG,KAAM,mBAAmB;AAC3F;AAAA,IACF;AAEA,UAAM,aAAa,KAAK,SAAS,MAAM,GAAG;AAC1C,UAAM,WAAW,KAAK,KAAK,WAAW,IAAI;AAE1C,UAAM,eAAe,KAAK,WAAW,QAAQ,IAAI,WAAW,KAAK,QAAQ,QAAQ;AAEjF,UAAM,UAAU,UAAU,aAAa,QAAQ,OAAO,GAAG,CAAC;AAE1D,QAAI;AACF,YAAM,iBAAiB,MAAM,OAAO;AAGpC,UAAI,eAAe,eAAe,eAAe,iBAAiB,eAAe,aAAa;AAE5F,cAAM,eAAe,eAAe,WAAW;AAC/C,gBAAQ,IAAI,eAAe,YAAY,YAAY;AAAA,MACrD;AAAA,IACF,SAAS,OAAO;AAEd,cAAQ,MAAM,2BAA2B,QAAQ,KAAK,KAAK;AAAA,IAC7D;AAAA,EACF;AAGA,cAAY,IAAI,UAAU,aAAa;AAEvC,SAAO;AACT,GAhE+B;AAqE/B,MAAM,mBAAmB,8BAAoB;AAAA,EAC3C;AAAA,EACA;AACF,MAG+B;AAE7B,QAAM,WAAW,GAAG,iBAAiB,IAAI,UAAU;AAGnD,MAAI,YAAY,IAAI,QAAQ,GAAG;AAC7B,WAAO,YAAY,IAAI,QAAQ;AAAA,EACjC;AAGA,QAAM,mBAAmB,KAAK,KAAK,mBAAmB,GAAG,UAAU,IAAI,OAAO,uBAAuB,CAAC,EAAE;AAGxG,QAAM,eAAe,MAAM,OAAO;AAGlC,MAAI,eAAe,eAAe,eAAe,iBAAiB,eAAe,aAAa;AAC5F,UAAM,IAAI,MAAM,gCAAgC,UAAU,GAAG;AAAA,EAC/D;AAEA,MAAI,CAAC,gBAAgB,CAAC,OAAO,
|
|
4
|
+
"sourcesContent": ["import fs from 'node:fs';\nimport path from 'node:path';\nimport { LRUCache } from 'lru-cache';\nimport { Helper } from './index.js';\n\n// Type for a map of loaded modules\nexport interface ModuleMap<T = unknown> {\n [key: string]: T;\n}\n\n// Cache for loaded modules to avoid repeated imports\n// Using LRU cache to prevent unbounded memory growth in long-running processes\nconst moduleCache = new LRUCache<string, ModuleMap>({\n max: 100, // Max 100 directories cached\n ttl: 1000 * 60 * 10, // 10 minutes\n});\n\nconst entityCache = new LRUCache<string, EntityClass>({\n max: 500, // Max 500 entities cached (accessed more frequently than modules)\n ttl: 1000 * 60 * 10, // 10 minutes\n});\n\nconst loadModulesInDirectory = async <T = unknown>({\n directory,\n extensions,\n}: {\n directory: string;\n extensions?: string[];\n}): Promise<ModuleMap<T>> => {\n // Create cache key based on directory and extensions\n const cacheKey = `${directory}:${extensions?.join(',') ?? 'all'}`;\n\n // Check cache first\n if (moduleCache.has(cacheKey)) {\n const cachedModule = moduleCache.get(cacheKey);\n if (cachedModule) {\n return cachedModule as ModuleMap<T>;\n }\n }\n\n const loadedModules: ModuleMap<T> = {};\n\n // Use readdir with withFileTypes option to avoid separate stat calls\n const dirents = await fs.promises.readdir(directory, { withFileTypes: true });\n\n for (const dirent of dirents) {\n // Skip directories without needing stat call\n if (dirent.isDirectory()) {\n continue;\n }\n\n const file = dirent.name;\n const ext = path.extname(file);\n const isDeclarationFile = file.endsWith('.d.ts');\n\n // Skip files that are not in the specified extensions or are .d.ts files\n if ((extensions && extensions.length > 0 && !extensions.includes(ext)) || isDeclarationFile) {\n continue;\n }\n\n const moduleName = path.basename(file, ext);\n const filePath = path.join(directory, file);\n // Convert to absolute path for ESM import\n const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(filePath);\n // Use file:// URL for Windows compatibility\n const fileUrl = `file://${absolutePath.replace(/\\\\/g, '/')}`;\n\n try {\n const importedModule = await import(fileUrl);\n\n // Use safe property assignment to prevent prototype pollution\n if (moduleName !== '__proto__' && moduleName !== 'constructor' && moduleName !== 'prototype') {\n // Prefer default export, but fall back to the entire module if no default\n const moduleExport = importedModule.default ?? importedModule;\n Reflect.set(loadedModules, moduleName, moduleExport);\n }\n } catch (error) {\n // Note: console.error used here as Logger may not be initialized during early bootstrap\n console.error(`Failed to import module ${filePath}:`, error);\n }\n }\n\n // Cache the results for future use\n moduleCache.set(cacheKey, loadedModules);\n\n return loadedModules;\n};\n\n// Type constraint for entity classes (must be constructable)\nexport type EntityClass<T = unknown> = new (...args: unknown[]) => T;\n\nconst loadEntityModule = async <T = unknown>({\n entitiesDirectory,\n entityName,\n}: {\n entitiesDirectory: string;\n entityName: string;\n}): Promise<EntityClass<T>> => {\n // Create cache key based on directory and entity name\n const cacheKey = `${entitiesDirectory}:${entityName}`;\n\n // Check cache first\n if (entityCache.has(cacheKey)) {\n return entityCache.get(cacheKey) as EntityClass<T>;\n }\n\n // Define entity module path\n const entityModulePath = path.join(entitiesDirectory, `${entityName}.${Helper.getScriptFileExtension()}`);\n\n // Import entity module\n const entityModule = await import(entityModulePath);\n\n // Safe property access to prevent prototype pollution\n if (entityName === '__proto__' || entityName === 'constructor' || entityName === 'prototype') {\n throw new Error(`Invalid entity name (Entity: ${entityName})`);\n }\n\n if (!entityModule || !Object.hasOwn(entityModule, entityName)) {\n throw new Error(`Entity not found (Entity: ${entityName})`);\n }\n\n // Get entity class\n const EntityClass = Reflect.get(entityModule, entityName);\n\n // Cache the entity for future use\n entityCache.set(cacheKey, EntityClass);\n\n return EntityClass;\n};\n\n// Cache management functions for development/testing\nconst clearModuleCache = (): void => {\n moduleCache.clear();\n entityCache.clear();\n};\n\nconst getCacheStats = (): { modulesCached: number; entitiesCached: number } => {\n return {\n modulesCached: moduleCache.size,\n entitiesCached: entityCache.size,\n };\n};\n\nexport default {\n loadModulesInDirectory,\n loadEntityModule,\n clearModuleCache,\n getCacheStats,\n};\n"],
|
|
5
|
+
"mappings": ";;AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,gBAAgB;AACzB,SAAS,cAAc;AASvB,MAAM,cAAc,IAAI,SAA4B;AAAA,EAClD,KAAK;AAAA;AAAA,EACL,KAAK,MAAO,KAAK;AAAA;AACnB,CAAC;AAED,MAAM,cAAc,IAAI,SAA8B;AAAA,EACpD,KAAK;AAAA;AAAA,EACL,KAAK,MAAO,KAAK;AAAA;AACnB,CAAC;AAED,MAAM,yBAAyB,8BAAoB;AAAA,EACjD;AAAA,EACA;AACF,MAG6B;AAE3B,QAAM,WAAW,GAAG,SAAS,IAAI,YAAY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YAAY,IAAI,QAAQ;AAAA,EACjC;AAGA,QAAM,mBAAmB,KAAK,KAAK,mBAAmB,GAAG,UAAU,IAAI,OAAO,uBAAuB,CAAC,EAAE;AAGxG,QAAM,eAAe,MAAM,OAAO;AAGlC,MAAI,eAAe,eAAe,eAAe,iBAAiB,eAAe,aAAa;AAC5F,UAAM,IAAI,MAAM,gCAAgC,UAAU,GAAG;AAAA,EAC/D;AAEA,MAAI,CAAC,gBAAgB,CAAC,OAAO,OAAO,cAAc,UAAU,GAAG;AAC7D,UAAM,IAAI,MAAM,6BAA6B,UAAU,GAAG;AAAA,EAC5D;AAGA,QAAM,cAAc,QAAQ,IAAI,cAAc,UAAU;AAGxD,cAAY,IAAI,UAAU,WAAW;AAErC,SAAO;AACT,GArCyB;AAwCzB,MAAM,mBAAmB,6BAAY;AACnC,cAAY,MAAM;AAClB,cAAY,MAAM;AACpB,GAHyB;AAKzB,MAAM,gBAAgB,6BAAyD;AAC7E,SAAO;AAAA,IACL,eAAe,YAAY;AAAA,IAC3B,gBAAgB,YAAY;AAAA,EAC9B;AACF,GALsB;AAOtB,IAAO,iBAAQ;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/util/os.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import crypto from "node:crypto";
|
|
4
|
+
import os from "node:os";
|
|
5
5
|
function getUniqueComputerId() {
|
|
6
6
|
const interfaces = Object.values(os.networkInterfaces()).filter(Boolean);
|
|
7
7
|
let macAddress = "";
|
package/dist/util/os.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/util/os.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";;AAAA,OAAO,
|
|
4
|
+
"sourcesContent": ["import crypto from 'node:crypto';\nimport os from 'node:os';\n\nfunction getUniqueComputerId(): string {\n const interfaces = Object.values(os.networkInterfaces()).filter(Boolean) as os.NetworkInterfaceInfo[][];\n let macAddress = '';\n for (const ifaceList of interfaces) {\n for (const details of ifaceList) {\n if (details.mac) {\n macAddress = details.mac;\n break;\n }\n }\n if (macAddress) break;\n }\n return crypto.createHash('sha256').update(macAddress).digest('hex');\n}\n\nexport default {\n getUniqueComputerId,\n};\n"],
|
|
5
|
+
"mappings": ";;AAAA,OAAO,YAAY;AACnB,OAAO,QAAQ;AAEf,SAAS,sBAA8B;AACrC,QAAM,aAAa,OAAO,OAAO,GAAG,kBAAkB,CAAC,EAAE,OAAO,OAAO;AACvE,MAAI,aAAa;AACjB,aAAW,aAAa,YAAY;AAClC,eAAW,WAAW,WAAW;AAC/B,UAAI,QAAQ,KAAK;AACf,qBAAa,QAAQ;AACrB;AAAA,MACF;AAAA,IACF;AACA,QAAI,WAAY;AAAA,EAClB;AACA,SAAO,OAAO,WAAW,QAAQ,EAAE,OAAO,UAAU,EAAE,OAAO,KAAK;AACpE;AAbS;AAeT,IAAO,aAAQ;AAAA,EACb;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -17,5 +17,5 @@ export declare function withAuth(handler: AuthenticatedRouteHandler, authenticat
|
|
|
17
17
|
* Method decorator for class-based controllers
|
|
18
18
|
* Usage: @requiresAuth()
|
|
19
19
|
*/
|
|
20
|
-
export declare function requiresAuth(): (
|
|
20
|
+
export declare function requiresAuth(): (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
21
21
|
//# sourceMappingURL=auth-middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/auth-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3F;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,yBAAyB,EAClC,mBAAmB,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,GACvG,YAAY,CAed;AAED;;;GAGG;AACH,wBAAgB,YAAY,KAClB,SAAS,GAAG,EAAE,cAAc,MAAM,EAAE,YAAY,kBAAkB,wBAoB3E"}
|
|
@@ -12,7 +12,7 @@ function withAuth(handler, authenticateRequest) {
|
|
|
12
12
|
}
|
|
13
13
|
__name(withAuth, "withAuth");
|
|
14
14
|
function requiresAuth() {
|
|
15
|
-
return
|
|
15
|
+
return (_target, _propertyKey, descriptor) => {
|
|
16
16
|
const originalMethod = descriptor.value;
|
|
17
17
|
descriptor.value = async function(request, reply) {
|
|
18
18
|
const user = await this.authenticateRequest(request, reply);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/webserver/controller/auth-middleware.ts"],
|
|
4
|
-
"sourcesContent": ["import type { FastifyReply, FastifyRequest } from 'fastify';\nimport type { AuthenticatedUser } from './base.js';\n\nexport type { AuthenticatedUser } from './base.js';\n\nexport interface AuthenticatedRequest extends FastifyRequest {\n user: AuthenticatedUser;\n}\n\nexport type AuthenticatedRouteHandler = (request: AuthenticatedRequest, reply: FastifyReply) => Promise<void>;\nexport type RouteHandler = (request: FastifyRequest, reply: FastifyReply) => Promise<void>;\n\n/**\n * Higher-order function that wraps a route handler with authentication\n * @param handler The route handler that requires authentication\n * @param authenticateRequest The authentication method from the controller\n * @returns A new route handler with authentication built-in\n */\nexport function withAuth(\n handler: AuthenticatedRouteHandler,\n authenticateRequest: (request: FastifyRequest, reply: FastifyReply) => Promise<AuthenticatedUser | null>,\n): RouteHandler {\n return async (request: FastifyRequest, reply: FastifyReply): Promise<void> => {\n const user = await authenticateRequest(request, reply);\n\n if (!user) {\n // Authentication failed, response already sent by authenticateRequest\n return;\n }\n\n // Add user to request object\n (request as AuthenticatedRequest).user = user;\n\n // Call the original handler with the authenticated request\n return handler(request as AuthenticatedRequest, reply);\n };\n}\n\n/**\n * Method decorator for class-based controllers\n * Usage: @requiresAuth()\n */\nexport function requiresAuth() {\n return
|
|
5
|
-
"mappings": ";;AAkBO,SAAS,SACd,SACA,qBACc;AACd,SAAO,OAAO,SAAyB,UAAuC;AAC5E,UAAM,OAAO,MAAM,oBAAoB,SAAS,KAAK;AAErD,QAAI,CAAC,MAAM;AAET;AAAA,IACF;AAGA,IAAC,QAAiC,OAAO;AAGzC,WAAO,QAAQ,SAAiC,KAAK;AAAA,EACvD;AACF;AAlBgB;AAwBT,SAAS,eAAe;AAC7B,SAAO,
|
|
4
|
+
"sourcesContent": ["import type { FastifyReply, FastifyRequest } from 'fastify';\nimport type { AuthenticatedUser } from './base.js';\n\nexport type { AuthenticatedUser } from './base.js';\n\nexport interface AuthenticatedRequest extends FastifyRequest {\n user: AuthenticatedUser;\n}\n\nexport type AuthenticatedRouteHandler = (request: AuthenticatedRequest, reply: FastifyReply) => Promise<void>;\nexport type RouteHandler = (request: FastifyRequest, reply: FastifyReply) => Promise<void>;\n\n/**\n * Higher-order function that wraps a route handler with authentication\n * @param handler The route handler that requires authentication\n * @param authenticateRequest The authentication method from the controller\n * @returns A new route handler with authentication built-in\n */\nexport function withAuth(\n handler: AuthenticatedRouteHandler,\n authenticateRequest: (request: FastifyRequest, reply: FastifyReply) => Promise<AuthenticatedUser | null>,\n): RouteHandler {\n return async (request: FastifyRequest, reply: FastifyReply): Promise<void> => {\n const user = await authenticateRequest(request, reply);\n\n if (!user) {\n // Authentication failed, response already sent by authenticateRequest\n return;\n }\n\n // Add user to request object\n (request as AuthenticatedRequest).user = user;\n\n // Call the original handler with the authenticated request\n return handler(request as AuthenticatedRequest, reply);\n };\n}\n\n/**\n * Method decorator for class-based controllers\n * Usage: @requiresAuth()\n */\nexport function requiresAuth() {\n return (_target: any, _propertyKey: string, descriptor: PropertyDescriptor) => {\n const originalMethod = descriptor.value;\n\n descriptor.value = async function (this: any, request: FastifyRequest, reply: FastifyReply) {\n const user = await this.authenticateRequest(request, reply);\n\n if (!user) {\n // Authentication failed, response already sent by authenticateRequest\n return;\n }\n\n // Add user to request object\n (request as AuthenticatedRequest).user = user;\n\n // Call the original method with the authenticated request\n return originalMethod.call(this, request, reply);\n };\n\n return descriptor;\n };\n}\n"],
|
|
5
|
+
"mappings": ";;AAkBO,SAAS,SACd,SACA,qBACc;AACd,SAAO,OAAO,SAAyB,UAAuC;AAC5E,UAAM,OAAO,MAAM,oBAAoB,SAAS,KAAK;AAErD,QAAI,CAAC,MAAM;AAET;AAAA,IACF;AAGA,IAAC,QAAiC,OAAO;AAGzC,WAAO,QAAQ,SAAiC,KAAK;AAAA,EACvD;AACF;AAlBgB;AAwBT,SAAS,eAAe;AAC7B,SAAO,CAAC,SAAc,cAAsB,eAAmC;AAC7E,UAAM,iBAAiB,WAAW;AAElC,eAAW,QAAQ,eAA2B,SAAyB,OAAqB;AAC1F,YAAM,OAAO,MAAM,KAAK,oBAAoB,SAAS,KAAK;AAE1D,UAAI,CAAC,MAAM;AAET;AAAA,MACF;AAGA,MAAC,QAAiC,OAAO;AAGzC,aAAO,eAAe,KAAK,MAAM,SAAS,KAAK;AAAA,IACjD;AAEA,WAAO;AAAA,EACT;AACF;AArBgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { StatusCodes } from 'http-status-codes';
|
|
2
1
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
3
|
-
import
|
|
4
|
-
import type { RedisInstance } from '../../redis/index.js';
|
|
5
|
-
import type { QueueManager } from '../../queue/index.js';
|
|
6
|
-
import type { ApiError, ApiResponse, WebServerBaseControllerConstructorParams } from './base.interface.js';
|
|
2
|
+
import { StatusCodes } from 'http-status-codes';
|
|
7
3
|
import type { ApplicationConfig } from '../../application/base-application.interface.js';
|
|
4
|
+
import type { DatabaseInstance } from '../../database/index.js';
|
|
8
5
|
import type EventManager from '../../event/manager.js';
|
|
9
|
-
import type { WebServerOptions } from '../webserver.interface.js';
|
|
10
6
|
import type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';
|
|
7
|
+
import type { QueueManager } from '../../queue/index.js';
|
|
8
|
+
import type { RedisInstance } from '../../redis/index.js';
|
|
9
|
+
import type { WebServerOptions } from '../webserver.interface.js';
|
|
10
|
+
import type { ApiError, ApiResponse, WebServerBaseControllerConstructorParams } from './base.interface.js';
|
|
11
11
|
export interface AuthenticatedUser<TPayload = Record<string, unknown>> {
|
|
12
12
|
userId: number;
|
|
13
13
|
payload: TPayload;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AAEzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAE7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,E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,MAAM,CAAC,CAAC;KAC/B;IAYD,SAAS,CAAC,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,GAAE,MAA6B;IAW1F,SAAS,CAAC,iBAAiB,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,UAAoC,EACpC,SAAS,GACV,EAAE;QACD,KAAK,EAAE,YAAY,CAAC;QACpB,KAAK,EAAE,OAAO,CAAC;QACf,UAAU,CAAC,EAAE,WAAW,CAAC;QACzB,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;KAC9B;IA4CD,OAAO,CAAC,YAAY;cAoBJ,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;CAwErH"}
|
|
@@ -2,11 +2,11 @@ import type { FastifyRequest } from 'fastify';
|
|
|
2
2
|
import type { ApplicationConfig } from '../../application/base-application.interface.js';
|
|
3
3
|
import type { DatabaseInstance } from '../../database/index.js';
|
|
4
4
|
import type EventManager from '../../event/manager.js';
|
|
5
|
+
import type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';
|
|
5
6
|
import type { QueueManager } from '../../queue/index.js';
|
|
6
7
|
import type { RedisInstance } from '../../redis/index.js';
|
|
7
8
|
import type { RouteHandler, RouteHandlerContext, RouteSchemaDefinition, WebServerOptions } from '../webserver.interface.js';
|
|
8
9
|
import type WebServerBaseController from './base.js';
|
|
9
|
-
import type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';
|
|
10
10
|
export interface WebServerBaseControllerConstructorParams<TQueueManager extends QueueManager = QueueManager, TRedisInstance extends RedisInstance = RedisInstance, TEventManager extends EventManager = EventManager, TDatabaseInstance extends DatabaseInstance = DatabaseInstance> {
|
|
11
11
|
applicationConfig: ApplicationConfig;
|
|
12
12
|
webServerOptions: WebServerOptions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.interface.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,uBAAuB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"base.interface.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/base.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iDAAiD,CAAC;AACzF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,YAAY,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,uBAAuB,MAAM,WAAW,CAAC;AAErD,MAAM,WAAW,wCAAwC,CACvD,aAAa,SAAS,YAAY,GAAG,YAAY,EACjD,cAAc,SAAS,aAAa,GA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AM,CAAC;KACnB,CAAC;IACF,KAAK,CAAC,EAAE,QAAQ,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,eAAe,GAAG,WAAW,GAAG,cAAc,GAAG,cAAc,CAAC;IACxG,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CAC5B"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import cluster from "node:cluster";
|
|
3
4
|
import { StatusCodes } from "http-status-codes";
|
|
4
|
-
import { Logger } from "../../logger/index.js";
|
|
5
|
-
import cluster from "cluster";
|
|
6
5
|
import Jwt from "../../auth/jwt.js";
|
|
7
6
|
import { safeSerializeError } from "../../error/error-reporter.js";
|
|
7
|
+
import { Logger } from "../../logger/index.js";
|
|
8
8
|
class BaseController {
|
|
9
9
|
static {
|
|
10
10
|
__name(this, "BaseController");
|
|
@@ -68,7 +68,7 @@ class BaseController {
|
|
|
68
68
|
errorType
|
|
69
69
|
}) {
|
|
70
70
|
let publicErrorMessage;
|
|
71
|
-
let errorDetails
|
|
71
|
+
let errorDetails;
|
|
72
72
|
if (this.webServerOptions.errors?.verbose === true) {
|
|
73
73
|
if (error instanceof Error) {
|
|
74
74
|
publicErrorMessage = error.stack ?? error.message;
|
|
@@ -169,7 +169,7 @@ class BaseController {
|
|
|
169
169
|
});
|
|
170
170
|
return null;
|
|
171
171
|
}
|
|
172
|
-
const userId = parseInt(payload.sub);
|
|
172
|
+
const userId = parseInt(payload.sub, 10);
|
|
173
173
|
return {
|
|
174
174
|
userId,
|
|
175
175
|
payload
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/webserver/controller/base.ts"],
|
|
4
|
-
"sourcesContent": ["import
|
|
5
|
-
"mappings": ";;AAAA,
|
|
4
|
+
"sourcesContent": ["import cluster from 'node:cluster';\nimport type { FastifyReply, FastifyRequest } from 'fastify';\nimport { StatusCodes } from 'http-status-codes';\nimport type { ApplicationConfig } from '../../application/base-application.interface.js';\nimport Jwt from '../../auth/jwt.js';\nimport type { DatabaseInstance } from '../../database/index.js';\nimport { safeSerializeError } from '../../error/error-reporter.js';\nimport type EventManager from '../../event/manager.js';\nimport type { LifecycleManager } from '../../lifecycle/lifecycle-manager.js';\nimport { Logger } from '../../logger/index.js';\nimport type { QueueManager } from '../../queue/index.js';\nimport type { RedisInstance } from '../../redis/index.js';\nimport type { WebServerOptions } from '../webserver.interface.js';\nimport type { ApiError, ApiResponse, WebServerBaseControllerConstructorParams } from './base.interface.js';\n\nexport interface AuthenticatedUser<TPayload = Record<string, unknown>> {\n userId: number;\n payload: TPayload;\n}\n\nexport default abstract class BaseController<\n TQueueManager extends QueueManager = QueueManager,\n TRedisInstance extends RedisInstance = RedisInstance,\n TEventManager extends EventManager = EventManager,\n TDatabaseInstance extends DatabaseInstance = DatabaseInstance,\n> {\n protected workerId: number | undefined;\n\n protected applicationConfig: ApplicationConfig;\n protected webServerOptions: WebServerOptions;\n\n protected redisInstance: TRedisInstance;\n protected queueManager: TQueueManager;\n protected eventManager: TEventManager;\n protected databaseInstance: TDatabaseInstance;\n protected lifecycleManager: LifecycleManager;\n\n constructor({\n applicationConfig,\n webServerOptions,\n redisInstance,\n queueManager,\n eventManager,\n databaseInstance,\n lifecycleManager,\n }: WebServerBaseControllerConstructorParams<TQueueManager, TRedisInstance, TEventManager, TDatabaseInstance>) {\n this.workerId = cluster.worker?.id;\n\n this.applicationConfig = applicationConfig;\n this.webServerOptions = webServerOptions;\n\n this.redisInstance = redisInstance;\n this.queueManager = queueManager;\n this.eventManager = eventManager;\n this.databaseInstance = databaseInstance;\n this.lifecycleManager = lifecycleManager;\n }\n\n protected sendSuccessResponse<T = unknown>({\n reply,\n data,\n statusCode = StatusCodes.OK,\n meta,\n }: {\n reply: FastifyReply;\n data: T;\n statusCode?: StatusCodes;\n meta?: ApiResponse<T>['meta'];\n }) {\n const response: ApiResponse<T> = {\n data,\n meta: {\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n ...meta,\n },\n };\n reply.status(statusCode).send(response);\n }\n\n protected sendNotFoundResponse(reply: FastifyReply, message: string = 'Resource not found') {\n const error: ApiError = {\n message,\n type: 'not_found',\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n };\n const response: ApiResponse = { error };\n reply.status(StatusCodes.NOT_FOUND).send(response);\n }\n\n protected sendErrorResponse({\n reply,\n error,\n statusCode = StatusCodes.BAD_REQUEST,\n errorType,\n }: {\n reply: FastifyReply;\n error: unknown;\n statusCode?: StatusCodes;\n errorType?: ApiError['type'];\n }) {\n let publicErrorMessage: string;\n let errorDetails: Record<string, unknown> | undefined;\n\n if (this.webServerOptions.errors?.verbose === true) {\n if (error instanceof Error) {\n publicErrorMessage = error.stack ?? error.message;\n errorDetails = { stack: error.stack, name: error.name };\n } else {\n publicErrorMessage = safeSerializeError(error);\n }\n } else {\n if (process.env.NODE_ENV === 'production') {\n if (error instanceof Error) {\n publicErrorMessage = 'Something went wrong';\n } else if (typeof error === 'string') {\n publicErrorMessage = error;\n } else {\n publicErrorMessage = 'An unknown error occurred';\n }\n } else {\n if (error instanceof Error) {\n publicErrorMessage = error.stack ?? error.message;\n errorDetails = { stack: error.stack, name: error.name };\n } else {\n publicErrorMessage = safeSerializeError(error);\n }\n }\n }\n\n Logger.error({ error });\n\n const apiError: ApiError = {\n message: publicErrorMessage,\n type: errorType ?? this.getErrorType(statusCode),\n timestamp: new Date().toISOString(),\n requestId: reply.request.id || 'unknown',\n ...(errorDetails && { details: errorDetails }),\n };\n\n const response: ApiResponse = { error: apiError };\n reply.status(statusCode).send(response);\n }\n\n private getErrorType(statusCode: StatusCodes): ApiError['type'] {\n switch (statusCode) {\n case StatusCodes.UNAUTHORIZED:\n return 'authentication';\n case StatusCodes.FORBIDDEN:\n return 'authorization';\n case StatusCodes.NOT_FOUND:\n return 'not_found';\n case StatusCodes.BAD_REQUEST:\n case StatusCodes.UNPROCESSABLE_ENTITY:\n return 'validation';\n case StatusCodes.INTERNAL_SERVER_ERROR:\n case StatusCodes.BAD_GATEWAY:\n case StatusCodes.SERVICE_UNAVAILABLE:\n return 'server_error';\n default:\n return 'client_error';\n }\n }\n\n protected async authenticateRequest(request: FastifyRequest, reply: FastifyReply): Promise<AuthenticatedUser | null> {\n // Get JWT secret key from application config\n const jwtSecretKey = this.applicationConfig.auth?.jwtSecretKey;\n\n if (!jwtSecretKey) {\n this.sendErrorResponse({\n reply,\n error: 'Authentication not configured.',\n statusCode: StatusCodes.INTERNAL_SERVER_ERROR,\n errorType: 'server_error',\n });\n return null;\n }\n\n const authHeader = request.headers.authorization;\n\n if (!authHeader) {\n this.sendErrorResponse({\n reply,\n error: 'No token provided.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n\n if (!authHeader.startsWith('Bearer ')) {\n this.sendErrorResponse({\n reply,\n error: 'Invalid token.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n\n try {\n const importedJwtSecretKey = await Jwt.importJwtSecretKey({\n jwtSecretKey,\n });\n\n // Remove \"Bearer \" from token\n const jwtAccessToken = authHeader.substring(7);\n\n const { payload } = await Jwt.jwtVerify(jwtAccessToken, importedJwtSecretKey);\n\n if (!payload.sub) {\n this.sendErrorResponse({\n reply,\n error: 'Invalid token payload.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n\n const userId = parseInt(payload.sub, 10);\n\n return {\n userId,\n payload,\n };\n } catch {\n this.sendErrorResponse({\n reply,\n error: 'Invalid or expired token.',\n statusCode: StatusCodes.UNAUTHORIZED,\n errorType: 'authentication',\n });\n return null;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,OAAO,aAAa;AAEpB,SAAS,mBAAmB;AAE5B,OAAO,SAAS;AAEhB,SAAS,0BAA0B;AAGnC,SAAS,cAAc;AAWvB,MAAO,eAKL;AAAA,EAzBF,OAyBE;AAAA;AAAA;AAAA,EACU;AAAA,EAEA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEV,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAA8G;AAC5G,SAAK,WAAW,QAAQ,QAAQ;AAEhC,SAAK,oBAAoB;AACzB,SAAK,mBAAmB;AAExB,SAAK,gBAAgB;AACrB,SAAK,eAAe;AACpB,SAAK,eAAe;AACpB,SAAK,mBAAmB;AACxB,SAAK,mBAAmB;AAAA,EAC1B;AAAA,EAEU,oBAAiC;AAAA,IACzC;AAAA,IACA;AAAA,IACA,aAAa,YAAY;AAAA,IACzB;AAAA,EACF,GAKG;AACD,UAAM,WAA2B;AAAA,MAC/B;AAAA,MACA,MAAM;AAAA,QACJ,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,QAClC,WAAW,MAAM,QAAQ,MAAM;AAAA,QAC/B,GAAG;AAAA,MACL;AAAA,IACF;AACA,UAAM,OAAO,UAAU,EAAE,KAAK,QAAQ;AAAA,EACxC;AAAA,EAEU,qBAAqB,OAAqB,UAAkB,sBAAsB;AAC1F,UAAM,QAAkB;AA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AAAA,UACrB;AAAA,UACA,OAAO;AAAA,UACP,YAAY,YAAY;AAAA,UACxB,WAAW;AAAA,QACb,CAAC;AACD,eAAO;AAAA,MACT;AAEA,YAAM,SAAS,SAAS,QAAQ,KAAK,EAAE;AAEvC,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF,QAAQ;AACN,WAAK,kBAAkB;AAAA,QACrB;AAAA,QACA,OAAO;AAAA,QACP,YAAY,YAAY;AAAA,QACxB,WAAW;AAAA,MACb,CAAC;AACD,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import type { EntityManager } from '@mikro-orm/core';
|
|
3
3
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
|
4
|
-
import BaseController from './base.js';
|
|
5
4
|
import type { DynamicEntity } from '../../database/dynamic-entity.js';
|
|
5
|
+
import BaseController from './base.js';
|
|
6
6
|
export default abstract class EntityController extends BaseController {
|
|
7
7
|
protected abstract entityName: string;
|
|
8
8
|
private static entityCache;
|
|
@@ -16,8 +16,8 @@ export default abstract class EntityController extends BaseController {
|
|
|
16
16
|
private getRequestEntityManager;
|
|
17
17
|
protected getEntity: () => Promise<typeof DynamicEntity | undefined>;
|
|
18
18
|
private getEntityProperties;
|
|
19
|
-
options: (
|
|
20
|
-
metadata: (
|
|
19
|
+
options: (_request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
20
|
+
metadata: (_request: FastifyRequest, reply: FastifyReply) => Promise<void>;
|
|
21
21
|
protected preGetMany(_: {
|
|
22
22
|
entityManager: EntityManager;
|
|
23
23
|
request: FastifyRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../../../src/webserver/controller/entity.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAA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