@scpxl/nodejs-framework 1.0.50 → 1.0.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +14 -9
- 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 +69 -65
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Processor, WorkerOptions } from 'bullmq';
|
|
2
|
-
import type { RedisInstance } from '../redis/index.js';
|
|
3
2
|
import type { ApplicationConfig } from '../application/base-application.interface.js';
|
|
3
|
+
import type { RedisInstance } from '../redis/index.js';
|
|
4
4
|
import type QueueManager from './manager.js';
|
|
5
5
|
export interface QueueWorkerConstructorParams {
|
|
6
6
|
applicationConfig: ApplicationConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.interface.d.ts","sourceRoot":"","sources":["../../src/queue/worker.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"worker.interface.d.ts","sourceRoot":"","sources":["../../src/queue/worker.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AACtF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,YAAY,MAAM,cAAc,CAAC;AAE7C,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,YAAY,EAAE,YAAY,CAAC;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACzE,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,aAAa,EAAE,aAAa,CAAC;CAC9B"}
|
package/dist/queue/worker.js
CHANGED
|
@@ -39,7 +39,7 @@ class QueueWorker extends Worker {
|
|
|
39
39
|
onWorkerError = /* @__PURE__ */ __name((error) => {
|
|
40
40
|
Logger.error({ error });
|
|
41
41
|
}, "onWorkerError");
|
|
42
|
-
onWorkerFailed = /* @__PURE__ */ __name((
|
|
42
|
+
onWorkerFailed = /* @__PURE__ */ __name((_job, error) => {
|
|
43
43
|
Logger.error({ error });
|
|
44
44
|
}, "onWorkerFailed");
|
|
45
45
|
onWorkerStalled = /* @__PURE__ */ __name((jobId) => {
|
package/dist/queue/worker.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/queue/worker.ts"],
|
|
4
|
-
"sourcesContent": ["import { type Job, type Processor, Worker } from 'bullmq';\nimport type {
|
|
5
|
-
"mappings": ";;AAAA,SAAmC,cAAc;
|
|
4
|
+
"sourcesContent": ["import { type Job, type Processor, Worker } from 'bullmq';\nimport type { ApplicationConfig } from '../application/base-application.interface.js';\nimport { Logger } from '../logger/index.js';\nimport type { RedisInstance } from '../redis/index.js';\nimport { Time } from '../util/index.js';\nimport { WebSocketRedisSubscriberEvent } from '../websocket/websocket.interface.js';\nimport type QueueManager from './manager.js';\nimport type { QueueWorkerConstructorParams } from './worker.interface.js';\n\nexport default class QueueWorker extends Worker {\n private applicationConfig: ApplicationConfig;\n\n private queueManager: QueueManager;\n private redisInstance: RedisInstance;\n\n constructor({\n applicationConfig,\n queueManager,\n name,\n processor,\n options,\n redisInstance,\n }: QueueWorkerConstructorParams) {\n super(name, processor, options);\n\n this.applicationConfig = applicationConfig;\n\n this.queueManager = queueManager;\n this.redisInstance = redisInstance;\n\n this.on('active', this.onWorkerActive);\n this.on('error', this.onWorkerError);\n this.on('failed', this.onWorkerFailed);\n this.on('stalled', this.onWorkerStalled);\n this.on('completed', this.onWorkerCompleted);\n }\n\n private onWorkerActive = (job: Job): void => {\n this.queueManager.log('Worker active', {\n Queue: job.queueName,\n 'Job Name': job.name,\n 'Job ID': job.id,\n });\n };\n\n private onWorkerError = (error: Error): void => {\n Logger.error({ error });\n };\n\n private onWorkerFailed = (_job: Job<any, Processor<any, any, string>, string> | undefined, error: Error): void => {\n // // Send job failed message to client\n // if (job && job.data.webSocketClientId) {\n // const errorMessage = {\n // webSocketClientId: job.data.webSocketClientId,\n // action: job.name,\n // error: error.message,\n // };\n\n // // Send error message to client\n // this.redisInstance.publisherClient.publish('queueJobError', JSON.stringify(errorMessage));\n // }\n\n Logger.error({ error });\n };\n\n private onWorkerStalled = (jobId: string): void => {\n this.queueManager.log('Worker stalled', { Job: jobId });\n };\n\n private onWorkerCompleted = (job: Job): void => {\n const jobData = job.data;\n\n if (job.returnvalue?.webSocketClientId) {\n // Send job completed message to client\n this.redisInstance.publisherClient.publish(\n WebSocketRedisSubscriberEvent.QueueJobCompleted,\n JSON.stringify(job.returnvalue),\n );\n }\n\n const startTime = jobData.startTime;\n\n const executionTimeMs = Time.calculateElapsedTimeMs({ startTime });\n const formattedExecutionTime = executionTimeMs.toFixed(2);\n\n if (this.applicationConfig.queue.log?.jobCompleted) {\n this.queueManager.log('Job completed', {\n Queue: job.queueName,\n 'Job Name': job.name,\n 'Job ID': job.id,\n Time: `${formattedExecutionTime}ms`,\n });\n }\n };\n\n /**\n * Cleanup worker resources before shutdown.\n * Removes all event listeners and closes the worker connection.\n */\n public async cleanup(): Promise<void> {\n this.removeAllListeners();\n await this.close();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,SAAmC,cAAc;AAEjD,SAAS,cAAc;AAEvB,SAAS,YAAY;AACrB,SAAS,qCAAqC;AAI9C,MAAO,oBAAkC,OAAO;AAAA,EAThD,OASgD;AAAA;AAAA;AAAA,EACtC;AAAA,EAEA;AAAA,EACA;AAAA,EAER,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAiC;AAC/B,UAAM,MAAM,WAAW,OAAO;AAE9B,SAAK,oBAAoB;AAEzB,SAAK,eAAe;AACpB,SAAK,gBAAgB;AAErB,SAAK,GAAG,UAAU,KAAK,cAAc;AACrC,SAAK,GAAG,SAAS,KAAK,aAAa;AACnC,SAAK,GAAG,UAAU,KAAK,cAAc;AACrC,SAAK,GAAG,WAAW,KAAK,eAAe;AACvC,SAAK,GAAG,aAAa,KAAK,iBAAiB;AAAA,EAC7C;AAAA,EAEQ,iBAAiB,wBAAC,QAAmB;AAC3C,SAAK,aAAa,IAAI,iBAAiB;AAAA,MACrC,OAAO,IAAI;AAAA,MACX,YAAY,IAAI;AAAA,MAChB,UAAU,IAAI;AAAA,IAChB,CAAC;AAAA,EACH,GANyB;AAAA,EAQjB,gBAAgB,wBAAC,UAAuB;AAC9C,WAAO,MAAM,EAAE,MAAM,CAAC;AAAA,EACxB,GAFwB;AAAA,EAIhB,iBAAiB,wBAAC,MAAiE,UAAuB;AAahH,WAAO,MAAM,EAAE,MAAM,CAAC;AAAA,EACxB,GAdyB;AAAA,EAgBjB,kBAAkB,wBAAC,UAAwB;AACjD,SAAK,aAAa,IAAI,kBAAkB,EAAE,KAAK,MAAM,CAAC;AAAA,EACxD,GAF0B;AAAA,EAIlB,oBAAoB,wBAAC,QAAmB;AAC9C,UAAM,UAAU,IAAI;AAEpB,QAAI,IAAI,aAAa,mBAAmB;AAEtC,WAAK,cAAc,gBAAgB;AAAA,QACjC,8BAA8B;AAAA,QAC9B,KAAK,UAAU,IAAI,WAAW;AAAA,MAChC;AAAA,IACF;AAEA,UAAM,YAAY,QAAQ;AAE1B,UAAM,kBAAkB,KAAK,uBAAuB,EAAE,UAAU,CAAC;AACjE,UAAM,yBAAyB,gBAAgB,QAAQ,CAAC;AAExD,QAAI,KAAK,kBAAkB,MAAM,KAAK,cAAc;AAClD,WAAK,aAAa,IAAI,iBAAiB;AAAA,QACrC,OAAO,IAAI;AAAA,QACX,YAAY,IAAI;AAAA,QAChB,UAAU,IAAI;AAAA,QACd,MAAM,GAAG,sBAAsB;AAAA,MACjC,CAAC;AAAA,IACH;AAAA,EACF,GAxB4B;AAAA;AAAA;AAAA;AAAA;AAAA,EA8B5B,MAAa,UAAyB;AACpC,SAAK,mBAAmB;AACxB,UAAM,KAAK,MAAM;AAAA,EACnB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/redis/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redis/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,6BAA6B,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/redis/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { default as default2
|
|
2
|
-
import { default as default3 } from "./
|
|
1
|
+
import { default as default2 } from "./instance.js";
|
|
2
|
+
import { clearGlobalInMemoryRedisState, default as default3 } from "./manager.js";
|
|
3
3
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
default2 as RedisInstance,
|
|
5
|
+
default3 as RedisManager,
|
|
6
6
|
clearGlobalInMemoryRedisState
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
package/dist/redis/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/redis/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { default as
|
|
5
|
-
"mappings": "AAAA,SAAoB,WAAXA,
|
|
4
|
+
"sourcesContent": ["export { default as RedisInstance } from './instance.js';\nexport { clearGlobalInMemoryRedisState, default as RedisManager } from './manager.js';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAAgC;AACzC,SAAS,+BAA0C,WAAXA,gBAA+B;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
package/dist/redis/manager.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RedisManagerConfig as RedisManagerOptions } from './manager.interface.js';
|
|
2
1
|
import RedisInstance from './instance.js';
|
|
2
|
+
import type { RedisManagerConfig as RedisManagerOptions } from './manager.interface.js';
|
|
3
3
|
/**
|
|
4
4
|
* Clears the global in-memory Redis state including all timers.
|
|
5
5
|
* Useful for test cleanup to prevent timer leaks between tests.
|
|
@@ -16,5 +16,6 @@ export default class RedisManager {
|
|
|
16
16
|
* Log Redis message
|
|
17
17
|
*/
|
|
18
18
|
log(message: string, meta?: Record<string, unknown>): void;
|
|
19
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
19
20
|
}
|
|
20
21
|
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/redis/manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/redis/manager.ts"],"names":[],"mappings":"AAKA,OAAO,aAAa,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,kBAAkB,IAAI,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AA8BxF;;;GAGG;AACH,wBAAgB,6BAA6B,IAAI,IAAI,CAWpD;AAyHD,MAAM,CAAC,OAAO,OAAO,YAAY;IAC/B,OAAO,CAAC,MAAM,CAAyB;IAEvC,OAAO,CAAC,OAAO,CAAsB;IAE9B,SAAS,EAAE,aAAa,EAAE,CAAM;gBAE3B,MAAM,EAAE,mBAAmB;IAI1B,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IA8GjC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAiDxC;;OAEG;IACI,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAI3D,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7C"}
|
package/dist/redis/manager.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { Redis } from "ioredis";
|
|
4
3
|
import { EventEmitter } from "node:events";
|
|
5
|
-
import
|
|
4
|
+
import { Redis } from "ioredis";
|
|
5
|
+
import { safeSerializeError } from "../error/error-reporter.js";
|
|
6
6
|
import { Logger } from "../logger/index.js";
|
|
7
7
|
import { CachePerformanceWrapper } from "../performance/index.js";
|
|
8
|
-
import
|
|
8
|
+
import RedisInstance from "./instance.js";
|
|
9
9
|
const truthyPattern = /^(1|true|yes|on)$/i;
|
|
10
10
|
const scheduleMicrotask = typeof globalThis.queueMicrotask === "function" ? globalThis.queueMicrotask.bind(globalThis) : (callback) => {
|
|
11
11
|
void Promise.resolve().then(callback);
|
|
@@ -159,7 +159,7 @@ class RedisManager {
|
|
|
159
159
|
return new InMemoryRedisClient(getGlobalInMemoryRedisState());
|
|
160
160
|
}
|
|
161
161
|
const client2 = new Redis(redisOptions);
|
|
162
|
-
const errorHandler = /* @__PURE__ */ __name((
|
|
162
|
+
const errorHandler = /* @__PURE__ */ __name((_error) => {
|
|
163
163
|
}, "errorHandler");
|
|
164
164
|
client2.once("error", errorHandler);
|
|
165
165
|
return client2;
|
|
@@ -275,6 +275,9 @@ class RedisManager {
|
|
|
275
275
|
log(message, meta) {
|
|
276
276
|
this.logger.custom({ level: "redis", message, meta });
|
|
277
277
|
}
|
|
278
|
+
async [Symbol.asyncDispose]() {
|
|
279
|
+
await this.disconnect();
|
|
280
|
+
}
|
|
278
281
|
}
|
|
279
282
|
export {
|
|
280
283
|
clearGlobalInMemoryRedisState,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/redis/manager.ts"],
|
|
4
|
-
"sourcesContent": ["import { Redis, type RedisOptions } from 'ioredis';\nimport { EventEmitter } from 'node:events';\nimport type { RedisManagerConfig as RedisManagerOptions } from './manager.interface.js';\nimport RedisInstance from './instance.js';\nimport { Logger } from '../logger/index.js';\nimport { CachePerformanceWrapper } from '../performance/index.js';\nimport { safeSerializeError } from '../error/error-reporter.js';\n\nconst truthyPattern = /^(1|true|yes|on)$/i;\nconst scheduleMicrotask =\n typeof (globalThis as any).queueMicrotask === 'function'\n ? (globalThis as any).queueMicrotask.bind(globalThis)\n : (callback: () => void) => {\n void Promise.resolve().then(callback);\n };\n\ntype RedisCallback = (error: Error | null, result?: string) => void;\n\ninterface InMemoryRedisSharedState {\n store: Map<string, string | Buffer>;\n expirations: Map<string, NodeJS.Timeout>;\n subscriptions: Map<string, Set<InMemoryRedisClient>>;\n}\n\n// Global singleton shared state for in-memory Redis\nlet globalInMemoryRedisState: InMemoryRedisSharedState | null = null;\n\nfunction getGlobalInMemoryRedisState(): InMemoryRedisSharedState {\n globalInMemoryRedisState ??= {\n store: new Map<string, string | Buffer>(),\n expirations: new Map<string, NodeJS.Timeout>(),\n subscriptions: new Map<string, Set<InMemoryRedisClient>>(),\n };\n return globalInMemoryRedisState;\n}\n\n/**\n * Clears the global in-memory Redis state including all timers.\n * Useful for test cleanup to prevent timer leaks between tests.\n */\nexport function clearGlobalInMemoryRedisState(): void {\n if (globalInMemoryRedisState) {\n // Clear all expiration timers to prevent memory leaks\n for (const timer of globalInMemoryRedisState.expirations.values()) {\n clearTimeout(timer);\n }\n globalInMemoryRedisState.expirations.clear();\n globalInMemoryRedisState.store.clear();\n globalInMemoryRedisState.subscriptions.clear();\n }\n globalInMemoryRedisState = null;\n}\n\nclass InMemoryRedisClient extends EventEmitter {\n private shared: InMemoryRedisSharedState;\n\n constructor(shared: InMemoryRedisSharedState) {\n super();\n this.shared = shared;\n\n scheduleMicrotask(() => {\n this.emit('ready');\n });\n }\n\n private cleanupSubscriptions(): void {\n for (const subscribers of this.shared.subscriptions.values()) {\n subscribers.delete(this);\n }\n }\n\n private clearExpirationForKey(key: string): void {\n const timer = this.shared.expirations.get(key);\n if (timer) {\n clearTimeout(timer);\n this.shared.expirations.delete(key);\n }\n }\n\n public ping(callback?: RedisCallback): Promise<string> {\n if (callback) {\n callback(null, 'PONG');\n return Promise.resolve('PONG');\n }\n\n return Promise.resolve('PONG');\n }\n\n public async set(...args: any[]): Promise<'OK'> {\n const [key, value, mode, expiration] = args;\n const serializedValue: string | Buffer = value instanceof Buffer ? value : String(value);\n\n this.shared.store.set(key, serializedValue);\n this.clearExpirationForKey(key);\n\n if (typeof mode === 'string' && mode.toUpperCase() === 'EX' && typeof expiration === 'number') {\n const timer = setTimeout(() => {\n this.shared.store.delete(key);\n this.shared.expirations.delete(key);\n }, expiration * 1000);\n\n if (typeof timer.unref === 'function') {\n timer.unref();\n }\n\n this.shared.expirations.set(key, timer);\n }\n\n return 'OK';\n }\n\n public async get(key: string): Promise<string | null> {\n return (this.shared.store.get(key) as string | undefined) ?? null;\n }\n\n public async del(key: string): Promise<number> {\n const existed = this.shared.store.delete(key);\n this.clearExpirationForKey(key);\n return existed ? 1 : 0;\n }\n\n public async publish(channel: string, message: string): Promise<number> {\n const subscribers = this.shared.subscriptions.get(channel);\n\n if (!subscribers || subscribers.size === 0) {\n return 0;\n }\n\n for (const subscriber of subscribers) {\n scheduleMicrotask(() => {\n subscriber.emit('message', channel, message);\n });\n }\n\n return subscribers.size;\n }\n\n public async subscribe(channel: string): Promise<number> {\n let subscribers = this.shared.subscriptions.get(channel);\n if (!subscribers) {\n subscribers = new Set<InMemoryRedisClient>();\n this.shared.subscriptions.set(channel, subscribers);\n }\n subscribers.add(this);\n return subscribers.size;\n }\n\n public async unsubscribe(channel: string): Promise<number> {\n const subscribers = this.shared.subscriptions.get(channel);\n\n if (!subscribers) {\n return 0;\n }\n\n subscribers.delete(this);\n return subscribers.size;\n }\n\n public async quit(): Promise<'OK'> {\n this.cleanupSubscriptions();\n this.emit('end');\n this.removeAllListeners();\n return 'OK';\n }\n\n public disconnect(): void {\n this.cleanupSubscriptions();\n this.emit('end');\n this.removeAllListeners();\n }\n}\n\nexport default class RedisManager {\n private logger: typeof Logger = Logger;\n\n private options: RedisManagerOptions;\n\n public instances: RedisInstance[] = [];\n\n constructor(config: RedisManagerOptions) {\n this.options = config;\n }\n\n public async connect(): Promise<RedisInstance> {\n return CachePerformanceWrapper.monitorConnection(\n 'connect',\n async () => {\n const startTime = performance.now();\n\n const redisOptions: RedisOptions = {\n host: this.options.host,\n port: this.options.port,\n password: this.options.password,\n maxRetriesPerRequest: null, // Needed for bullmq\n lazyConnect: true, // Prevent automatic connection to avoid unhandled errors\n };\n\n const useInMemoryRedis =\n truthyPattern.test(process.env.PXL_REDIS_IN_MEMORY ?? '') ||\n truthyPattern.test(process.env.REDIS_IN_MEMORY ?? '');\n\n const createClient = (): Redis => {\n if (useInMemoryRedis) {\n return new InMemoryRedisClient(getGlobalInMemoryRedisState()) as unknown as Redis;\n }\n\n const client = new Redis(redisOptions);\n // Attach a temporary error handler to prevent unhandled errors during connection\n const errorHandler = (error: Error) => {\n // Error will be handled by the promise rejection below\n };\n client.once('error', errorHandler);\n return client;\n };\n\n const client = createClient();\n const publisherClient = createClient();\n const subscriberClient = createClient();\n\n try {\n // For non-in-memory clients, explicitly connect since we use lazyConnect\n if (!useInMemoryRedis) {\n await Promise.all([client.connect(), publisherClient.connect(), subscriberClient.connect()]);\n } else {\n // Wait for in-memory clients to be ready\n await Promise.all([\n new Promise<void>((resolve, reject) => {\n client.once('ready', () => resolve());\n client.once('error', (error: Error) => reject(error));\n }),\n new Promise<void>((resolve, reject) => {\n publisherClient.once('ready', () => resolve());\n publisherClient.once('error', (error: Error) => reject(error));\n }),\n new Promise<void>((resolve, reject) => {\n subscriberClient.once('ready', () => resolve());\n subscriberClient.once('error', (error: Error) => reject(error));\n }),\n ]);\n }\n\n const redisInstance = new RedisInstance({\n redisManager: this,\n client,\n publisherClient,\n subscriberClient,\n });\n\n this.instances.push(redisInstance);\n\n const duration = performance.now() - startTime;\n const meta = {\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n Mode: useInMemoryRedis ? 'in-memory' : 'network',\n };\n\n if (this.options.applicationConfig.log?.startUp) {\n this.log('Connected', meta);\n } else {\n this.logger.debug({ message: 'Redis connected', meta });\n }\n\n if (useInMemoryRedis) {\n this.logger.debug({ message: 'Using in-memory Redis stub' });\n }\n\n return redisInstance;\n } catch (error) {\n const duration = performance.now() - startTime;\n\n // Clean up clients on error\n await Promise.allSettled([client.quit(), publisherClient.quit(), subscriberClient.quit()]);\n\n this.logger.error({\n error: error instanceof Error ? error : new Error(safeSerializeError(error)),\n message: 'Redis connection failed',\n meta: {\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n Mode: useInMemoryRedis ? 'in-memory' : 'network',\n },\n });\n\n throw error;\n }\n },\n { host: this.options.host, port: this.options.port },\n );\n }\n\n public async disconnect(): Promise<void> {\n await CachePerformanceWrapper.monitorConnection(\n 'disconnect',\n async () => {\n const startTime = performance.now();\n const instanceCount = this.instances.length;\n\n try {\n await Promise.all(this.instances.map(instance => instance.disconnect()));\n\n const duration = performance.now() - startTime;\n\n if (instanceCount > 0) {\n const meta = {\n Instances: instanceCount,\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n };\n\n if (this.options.applicationConfig.log?.startUp) {\n this.log('Disconnected all Redis instances', meta);\n } else {\n this.logger.debug({ message: 'Redis instances disconnected', meta });\n }\n }\n\n this.instances = [];\n } catch (error) {\n const duration = performance.now() - startTime;\n\n this.logger.error({\n error: error instanceof Error ? error : new Error(safeSerializeError(error)),\n message: 'Redis disconnection failed',\n meta: {\n Host: this.options.host,\n Port: this.options.port,\n Instances: instanceCount,\n Duration: `${duration.toFixed(2)}ms`,\n },\n });\n\n throw error;\n }\n },\n { host: this.options.host, port: this.options.port },\n );\n }\n\n /**\n * Log Redis message\n */\n public log(message: string, meta?: Record<string, unknown>): void {\n this.logger.custom({ level: 'redis', message, meta });\n }\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA,SAAS,
|
|
4
|
+
"sourcesContent": ["import { EventEmitter } from 'node:events';\nimport { Redis, type RedisOptions } from 'ioredis';\nimport { safeSerializeError } from '../error/error-reporter.js';\nimport { Logger } from '../logger/index.js';\nimport { CachePerformanceWrapper } from '../performance/index.js';\nimport RedisInstance from './instance.js';\nimport type { RedisManagerConfig as RedisManagerOptions } from './manager.interface.js';\n\nconst truthyPattern = /^(1|true|yes|on)$/i;\nconst scheduleMicrotask =\n typeof (globalThis as any).queueMicrotask === 'function'\n ? (globalThis as any).queueMicrotask.bind(globalThis)\n : (callback: () => void) => {\n void Promise.resolve().then(callback);\n };\n\ntype RedisCallback = (error: Error | null, result?: string) => void;\n\ninterface InMemoryRedisSharedState {\n store: Map<string, string | Buffer>;\n expirations: Map<string, NodeJS.Timeout>;\n subscriptions: Map<string, Set<InMemoryRedisClient>>;\n}\n\n// Global singleton shared state for in-memory Redis\nlet globalInMemoryRedisState: InMemoryRedisSharedState | null = null;\n\nfunction getGlobalInMemoryRedisState(): InMemoryRedisSharedState {\n globalInMemoryRedisState ??= {\n store: new Map<string, string | Buffer>(),\n expirations: new Map<string, NodeJS.Timeout>(),\n subscriptions: new Map<string, Set<InMemoryRedisClient>>(),\n };\n return globalInMemoryRedisState;\n}\n\n/**\n * Clears the global in-memory Redis state including all timers.\n * Useful for test cleanup to prevent timer leaks between tests.\n */\nexport function clearGlobalInMemoryRedisState(): void {\n if (globalInMemoryRedisState) {\n // Clear all expiration timers to prevent memory leaks\n for (const timer of globalInMemoryRedisState.expirations.values()) {\n clearTimeout(timer);\n }\n globalInMemoryRedisState.expirations.clear();\n globalInMemoryRedisState.store.clear();\n globalInMemoryRedisState.subscriptions.clear();\n }\n globalInMemoryRedisState = null;\n}\n\nclass InMemoryRedisClient extends EventEmitter {\n private shared: InMemoryRedisSharedState;\n\n constructor(shared: InMemoryRedisSharedState) {\n super();\n this.shared = shared;\n\n scheduleMicrotask(() => {\n this.emit('ready');\n });\n }\n\n private cleanupSubscriptions(): void {\n for (const subscribers of this.shared.subscriptions.values()) {\n subscribers.delete(this);\n }\n }\n\n private clearExpirationForKey(key: string): void {\n const timer = this.shared.expirations.get(key);\n if (timer) {\n clearTimeout(timer);\n this.shared.expirations.delete(key);\n }\n }\n\n public ping(callback?: RedisCallback): Promise<string> {\n if (callback) {\n callback(null, 'PONG');\n return Promise.resolve('PONG');\n }\n\n return Promise.resolve('PONG');\n }\n\n public async set(...args: any[]): Promise<'OK'> {\n const [key, value, mode, expiration] = args;\n const serializedValue: string | Buffer = value instanceof Buffer ? value : String(value);\n\n this.shared.store.set(key, serializedValue);\n this.clearExpirationForKey(key);\n\n if (typeof mode === 'string' && mode.toUpperCase() === 'EX' && typeof expiration === 'number') {\n const timer = setTimeout(() => {\n this.shared.store.delete(key);\n this.shared.expirations.delete(key);\n }, expiration * 1000);\n\n if (typeof timer.unref === 'function') {\n timer.unref();\n }\n\n this.shared.expirations.set(key, timer);\n }\n\n return 'OK';\n }\n\n public async get(key: string): Promise<string | null> {\n return (this.shared.store.get(key) as string | undefined) ?? null;\n }\n\n public async del(key: string): Promise<number> {\n const existed = this.shared.store.delete(key);\n this.clearExpirationForKey(key);\n return existed ? 1 : 0;\n }\n\n public async publish(channel: string, message: string): Promise<number> {\n const subscribers = this.shared.subscriptions.get(channel);\n\n if (!subscribers || subscribers.size === 0) {\n return 0;\n }\n\n for (const subscriber of subscribers) {\n scheduleMicrotask(() => {\n subscriber.emit('message', channel, message);\n });\n }\n\n return subscribers.size;\n }\n\n public async subscribe(channel: string): Promise<number> {\n let subscribers = this.shared.subscriptions.get(channel);\n if (!subscribers) {\n subscribers = new Set<InMemoryRedisClient>();\n this.shared.subscriptions.set(channel, subscribers);\n }\n subscribers.add(this);\n return subscribers.size;\n }\n\n public async unsubscribe(channel: string): Promise<number> {\n const subscribers = this.shared.subscriptions.get(channel);\n\n if (!subscribers) {\n return 0;\n }\n\n subscribers.delete(this);\n return subscribers.size;\n }\n\n public async quit(): Promise<'OK'> {\n this.cleanupSubscriptions();\n this.emit('end');\n this.removeAllListeners();\n return 'OK';\n }\n\n public disconnect(): void {\n this.cleanupSubscriptions();\n this.emit('end');\n this.removeAllListeners();\n }\n}\n\nexport default class RedisManager {\n private logger: typeof Logger = Logger;\n\n private options: RedisManagerOptions;\n\n public instances: RedisInstance[] = [];\n\n constructor(config: RedisManagerOptions) {\n this.options = config;\n }\n\n public async connect(): Promise<RedisInstance> {\n return CachePerformanceWrapper.monitorConnection(\n 'connect',\n async () => {\n const startTime = performance.now();\n\n const redisOptions: RedisOptions = {\n host: this.options.host,\n port: this.options.port,\n password: this.options.password,\n maxRetriesPerRequest: null, // Needed for bullmq\n lazyConnect: true, // Prevent automatic connection to avoid unhandled errors\n };\n\n const useInMemoryRedis =\n truthyPattern.test(process.env.PXL_REDIS_IN_MEMORY ?? '') ||\n truthyPattern.test(process.env.REDIS_IN_MEMORY ?? '');\n\n const createClient = (): Redis => {\n if (useInMemoryRedis) {\n return new InMemoryRedisClient(getGlobalInMemoryRedisState()) as unknown as Redis;\n }\n\n const client = new Redis(redisOptions);\n // Attach a temporary error handler to prevent unhandled errors during connection\n const errorHandler = (_error: Error) => {\n // Error will be handled by the promise rejection below\n };\n client.once('error', errorHandler);\n return client;\n };\n\n const client = createClient();\n const publisherClient = createClient();\n const subscriberClient = createClient();\n\n try {\n // For non-in-memory clients, explicitly connect since we use lazyConnect\n if (!useInMemoryRedis) {\n await Promise.all([client.connect(), publisherClient.connect(), subscriberClient.connect()]);\n } else {\n // Wait for in-memory clients to be ready\n await Promise.all([\n new Promise<void>((resolve, reject) => {\n client.once('ready', () => resolve());\n client.once('error', (error: Error) => reject(error));\n }),\n new Promise<void>((resolve, reject) => {\n publisherClient.once('ready', () => resolve());\n publisherClient.once('error', (error: Error) => reject(error));\n }),\n new Promise<void>((resolve, reject) => {\n subscriberClient.once('ready', () => resolve());\n subscriberClient.once('error', (error: Error) => reject(error));\n }),\n ]);\n }\n\n const redisInstance = new RedisInstance({\n redisManager: this,\n client,\n publisherClient,\n subscriberClient,\n });\n\n this.instances.push(redisInstance);\n\n const duration = performance.now() - startTime;\n const meta = {\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n Mode: useInMemoryRedis ? 'in-memory' : 'network',\n };\n\n if (this.options.applicationConfig.log?.startUp) {\n this.log('Connected', meta);\n } else {\n this.logger.debug({ message: 'Redis connected', meta });\n }\n\n if (useInMemoryRedis) {\n this.logger.debug({ message: 'Using in-memory Redis stub' });\n }\n\n return redisInstance;\n } catch (error) {\n const duration = performance.now() - startTime;\n\n // Clean up clients on error\n await Promise.allSettled([client.quit(), publisherClient.quit(), subscriberClient.quit()]);\n\n this.logger.error({\n error: error instanceof Error ? error : new Error(safeSerializeError(error)),\n message: 'Redis connection failed',\n meta: {\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n Mode: useInMemoryRedis ? 'in-memory' : 'network',\n },\n });\n\n throw error;\n }\n },\n { host: this.options.host, port: this.options.port },\n );\n }\n\n public async disconnect(): Promise<void> {\n await CachePerformanceWrapper.monitorConnection(\n 'disconnect',\n async () => {\n const startTime = performance.now();\n const instanceCount = this.instances.length;\n\n try {\n await Promise.all(this.instances.map(instance => instance.disconnect()));\n\n const duration = performance.now() - startTime;\n\n if (instanceCount > 0) {\n const meta = {\n Instances: instanceCount,\n Host: this.options.host,\n Port: this.options.port,\n Duration: `${duration.toFixed(2)}ms`,\n };\n\n if (this.options.applicationConfig.log?.startUp) {\n this.log('Disconnected all Redis instances', meta);\n } else {\n this.logger.debug({ message: 'Redis instances disconnected', meta });\n }\n }\n\n this.instances = [];\n } catch (error) {\n const duration = performance.now() - startTime;\n\n this.logger.error({\n error: error instanceof Error ? error : new Error(safeSerializeError(error)),\n message: 'Redis disconnection failed',\n meta: {\n Host: this.options.host,\n Port: this.options.port,\n Instances: instanceCount,\n Duration: `${duration.toFixed(2)}ms`,\n },\n });\n\n throw error;\n }\n },\n { host: this.options.host, port: this.options.port },\n );\n }\n\n /**\n * Log Redis message\n */\n public log(message: string, meta?: Record<string, unknown>): void {\n this.logger.custom({ level: 'redis', message, meta });\n }\n\n async [Symbol.asyncDispose](): Promise<void> {\n await this.disconnect();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,SAAS,oBAAo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AAgB,GAAG;AACrB,kBAAM,OAAO;AAAA,cACX,WAAW;AAAA,cACX,MAAM,KAAK,QAAQ;AAAA,cACnB,MAAM,KAAK,QAAQ;AAAA,cACnB,UAAU,GAAG,SAAS,QAAQ,CAAC,CAAC;AAAA,YAClC;AAEA,gBAAI,KAAK,QAAQ,kBAAkB,KAAK,SAAS;AAC/C,mBAAK,IAAI,oCAAoC,IAAI;AAAA,YACnD,OAAO;AACL,mBAAK,OAAO,MAAM,EAAE,SAAS,gCAAgC,KAAK,CAAC;AAAA,YACrE;AAAA,UACF;AAEA,eAAK,YAAY,CAAC;AAAA,QACpB,SAAS,OAAO;AACd,gBAAM,WAAW,YAAY,IAAI,IAAI;AAErC,eAAK,OAAO,MAAM;AAAA,YAChB,OAAO,iBAAiB,QAAQ,QAAQ,IAAI,MAAM,mBAAmB,KAAK,CAAC;AAAA,YAC3E,SAAS;AAAA,YACT,MAAM;AAAA,cACJ,MAAM,KAAK,QAAQ;AAAA,cACnB,MAAM,KAAK,QAAQ;AAAA,cACnB,WAAW;AAAA,cACX,UAAU,GAAG,SAAS,QAAQ,CAAC,CAAC;AAAA,YAClC;AAAA,UACF,CAAC;AAED,gBAAM;AAAA,QACR;AAAA,MACF;AAAA,MACA,EAAE,MAAM,KAAK,QAAQ,MAAM,MAAM,KAAK,QAAQ,KAAK;AAAA,IACrD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKO,IAAI,SAAiB,MAAsC;AAChE,SAAK,OAAO,OAAO,EAAE,OAAO,SAAS,SAAS,KAAK,CAAC;AAAA,EACtD;AAAA,EAEA,OAAO,OAAO,YAAY,IAAmB;AAC3C,UAAM,KAAK,WAAW;AAAA,EACxB;AACF;",
|
|
6
6
|
"names": ["client"]
|
|
7
7
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export type { RequestContext, RunWithContextOptions } from './request-context.interface.js';
|
|
2
|
-
export {
|
|
2
|
+
export { enterRequestContext, getContextMetadata, getRequestContext, getRequestId, getUserId, requestContextStorage, runWithContext, runWithContextAsync, setContextMetadata, setUserId, } from './request-context.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/request-context/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EACL,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/request-context/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EACL,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,SAAS,GACV,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
+
enterRequestContext,
|
|
3
|
+
getContextMetadata,
|
|
2
4
|
getRequestContext,
|
|
3
5
|
getRequestId,
|
|
4
6
|
getUserId,
|
|
5
|
-
|
|
6
|
-
getContextMetadata,
|
|
7
|
-
setContextMetadata,
|
|
7
|
+
requestContextStorage,
|
|
8
8
|
runWithContext,
|
|
9
9
|
runWithContextAsync,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
setContextMetadata,
|
|
11
|
+
setUserId
|
|
12
12
|
} from "./request-context.js";
|
|
13
13
|
export {
|
|
14
14
|
enterRequestContext,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/request-context/index.ts"],
|
|
4
|
-
"sourcesContent": ["export type { RequestContext, RunWithContextOptions } from './request-context.interface.js';\nexport {\n
|
|
4
|
+
"sourcesContent": ["export type { RequestContext, RunWithContextOptions } from './request-context.interface.js';\nexport {\n enterRequestContext,\n getContextMetadata,\n getRequestContext,\n getRequestId,\n getUserId,\n requestContextStorage,\n runWithContext,\n runWithContextAsync,\n setContextMetadata,\n setUserId,\n} from './request-context.js';\n"],
|
|
5
5
|
"mappings": "AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,7 +6,7 @@ import { z } from 'zod';
|
|
|
6
6
|
* - readAugment: additional fields present on the persisted/read model (e.g. id, timestamps)
|
|
7
7
|
* - strict: apply .strict() to objects (defaults true)
|
|
8
8
|
*/
|
|
9
|
-
export interface BuildEntitySchemasOptions<Shape extends z.ZodRawShape, Updatable extends keyof Shape = keyof Shape, ReadAugment extends z.ZodRawShape =
|
|
9
|
+
export interface BuildEntitySchemasOptions<Shape extends z.ZodRawShape, Updatable extends keyof Shape = keyof Shape, ReadAugment extends z.ZodRawShape = Record<string, never>> {
|
|
10
10
|
shape: Shape;
|
|
11
11
|
updatableFields?: readonly Updatable[];
|
|
12
12
|
readAugment?: ReadAugment;
|
|
@@ -21,7 +21,7 @@ export interface BuiltEntitySchemas<Shape extends z.ZodRawShape, Updatable exten
|
|
|
21
21
|
keys: (keyof Shape)[];
|
|
22
22
|
updatableKeys: Updatable[];
|
|
23
23
|
}
|
|
24
|
-
export declare function buildEntitySchemas<Shape extends z.ZodRawShape, Updatable extends keyof Shape = keyof Shape, ReadAugment extends z.ZodRawShape =
|
|
24
|
+
export declare function buildEntitySchemas<Shape extends z.ZodRawShape, Updatable extends keyof Shape = keyof Shape, ReadAugment extends z.ZodRawShape = Record<string, never>>(options: BuildEntitySchemasOptions<Shape, Updatable, ReadAugment>): BuiltEntitySchemas<Shape, Updatable, ReadAugment>;
|
|
25
25
|
export declare const HttpMethodSchema: z.ZodEnum<{
|
|
26
26
|
GET: "GET";
|
|
27
27
|
POST: "POST";
|
|
@@ -31,5 +31,5 @@ export declare const HttpMethodSchema: z.ZodEnum<{
|
|
|
31
31
|
PATCH: "PATCH";
|
|
32
32
|
OPTIONS: "OPTIONS";
|
|
33
33
|
}>;
|
|
34
|
-
export declare const HttpStatusCodeSchema: z.core.$ZodBranded<z.ZodNumber, "HttpStatusCode">;
|
|
34
|
+
export declare const HttpStatusCodeSchema: z.core.$ZodBranded<z.ZodNumber, "HttpStatusCode", "out">;
|
|
35
35
|
//# sourceMappingURL=entity-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-builder.d.ts","sourceRoot":"","sources":["../../src/schemas/entity-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB,CACxC,KAAK,SAAS,CAAC,CAAC,WAAW,EAC3B,SAAS,SAAS,MAAM,KAAK,GAAG,MAAM,KAAK,EAC3C,WAAW,SAAS,CAAC,CAAC,WAAW,GAAG,EAAE;
|
|
1
|
+
{"version":3,"file":"entity-builder.d.ts","sourceRoot":"","sources":["../../src/schemas/entity-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,WAAW,yBAAyB,CACxC,KAAK,SAAS,CAAC,CAAC,WAAW,EAC3B,SAAS,SAAS,MAAM,KAAK,GAAG,MAAM,KAAK,EAC3C,WAAW,SAAS,CAAC,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;IAEzD,KAAK,EAAE,KAAK,CAAC;IACb,eAAe,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IACvC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAED,MAAM,WAAW,kBAAkB,CACjC,KAAK,SAAS,CAAC,CAAC,WAAW,EAC3B,SAAS,SAAS,MAAM,KAAK,EAC7B,WAAW,SAAS,CAAC,CAAC,WAAW;IAEjC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC3B,+DAA+D;IAC/D,MAAM,EAAE,CAAC,CAAC,UAAU,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,GAAG,WAAW,CAAC,CAAC;IACvC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IACtB,aAAa,EAAE,SAAS,EAAE,CAAC;CAC5B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,SAAS,CAAC,CAAC,WAAW,EAC3B,SAAS,SAAS,MAAM,KAAK,GAAG,MAAM,KAAK,EAC3C,WAAW,SAAS,CAAC,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAEzD,OAAO,EAAE,yBAAyB,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC,GAChE,kBAAkB,CAAC,KAAK,EAAE,SAAS,EAAE,WAAW,CAAC,CAoCnD;AAGD,eAAO,MAAM,gBAAgB;;;;;;;;EAAuE,CAAC;AACrG,eAAO,MAAM,oBAAoB,0DAA+D,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/schemas/entity-builder.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from 'zod';\n\n/**\n * Options for building standardized entity schemas.\n * - shape: base create shape (required fields for creation)\n * - updatableFields: subset of keys allowed in updates (defaults to all keys of shape)\n * - readAugment: additional fields present on the persisted/read model (e.g. id, timestamps)\n * - strict: apply .strict() to objects (defaults true)\n */\nexport interface BuildEntitySchemasOptions<\n Shape extends z.ZodRawShape,\n Updatable extends keyof Shape = keyof Shape,\n ReadAugment extends z.ZodRawShape =
|
|
4
|
+
"sourcesContent": ["import { z } from 'zod';\n\n/**\n * Options for building standardized entity schemas.\n * - shape: base create shape (required fields for creation)\n * - updatableFields: subset of keys allowed in updates (defaults to all keys of shape)\n * - readAugment: additional fields present on the persisted/read model (e.g. id, timestamps)\n * - strict: apply .strict() to objects (defaults true)\n */\nexport interface BuildEntitySchemasOptions<\n Shape extends z.ZodRawShape,\n Updatable extends keyof Shape = keyof Shape,\n ReadAugment extends z.ZodRawShape = Record<string, never>,\n> {\n shape: Shape;\n updatableFields?: readonly Updatable[];\n readAugment?: ReadAugment; // fields that exist after persistence (e.g. id, createdAt)\n strict?: boolean;\n requireAtLeastOneOnUpdate?: boolean; // default true\n}\n\nexport interface BuiltEntitySchemas<\n Shape extends z.ZodRawShape,\n Updatable extends keyof Shape,\n ReadAugment extends z.ZodRawShape,\n> {\n create: z.ZodObject<Shape>;\n /** Update schema is a partial over selected updatable keys. */\n update: z.ZodTypeAny;\n read: z.ZodObject<Shape & ReadAugment>;\n keys: (keyof Shape)[];\n updatableKeys: Updatable[];\n}\n\nexport function buildEntitySchemas<\n Shape extends z.ZodRawShape,\n Updatable extends keyof Shape = keyof Shape,\n ReadAugment extends z.ZodRawShape = Record<string, never>,\n>(\n options: BuildEntitySchemasOptions<Shape, Updatable, ReadAugment>,\n): BuiltEntitySchemas<Shape, Updatable, ReadAugment> {\n const { shape, updatableFields, readAugment, strict = true, requireAtLeastOneOnUpdate = true } = options;\n\n // Freeze to avoid accidental mutation\n Object.freeze(shape);\n\n const create = strict ? z.object(shape).strict() : z.object(shape);\n\n const updatableKeys = updatableFields ? [...updatableFields] : (Object.keys(shape) as Updatable[]);\n // Build pick mask for updatable keys\n const pickMask = updatableKeys.reduce<Record<string, true>>((acc, key) => {\n acc[String(key)] = true;\n return acc;\n }, {});\n\n const updateBase = updatableFields ? (create as z.ZodObject<any>).pick(pickMask) : (create as z.ZodObject<any>);\n let updateObject: z.ZodTypeAny = updateBase.partial();\n\n if (requireAtLeastOneOnUpdate) {\n updateObject = updateObject.refine(\n (value: unknown) =>\n !!value && typeof value === 'object' && Object.keys(value as Record<string, unknown>).length > 0,\n 'At least one field must be provided for update',\n );\n }\n\n const readShape = { ...shape, ...(readAugment ?? {}) } as Shape & ReadAugment;\n const read = strict ? z.object(readShape).strict() : z.object(readShape);\n\n return {\n create,\n update: updateObject,\n read: read as z.ZodObject<Shape & ReadAugment>,\n keys: Object.keys(shape) as (keyof Shape)[],\n updatableKeys,\n };\n}\n\n// Common atoms for reuse in entity schemas\nexport const HttpMethodSchema = z.enum(['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']);\nexport const HttpStatusCodeSchema = z.number().int().min(100).max(599).brand<'HttpStatusCode'>();\n"],
|
|
5
5
|
"mappings": ";;AAAA,SAAS,SAAS;AAkCX,SAAS,mBAKd,SACmD;AACnD,QAAM,EAAE,OAAO,iBAAiB,aAAa,SAAS,MAAM,4BAA4B,KAAK,IAAI;AAGjG,SAAO,OAAO,KAAK;AAEnB,QAAM,SAAS,SAAS,EAAE,OAAO,KAAK,EAAE,OAAO,IAAI,EAAE,OAAO,KAAK;AAEjE,QAAM,gBAAgB,kBAAkB,CAAC,GAAG,eAAe,IAAK,OAAO,KAAK,KAAK;AAEjF,QAAM,WAAW,cAAc,OAA6B,CAAC,KAAK,QAAQ;AACxE,QAAI,OAAO,GAAG,CAAC,IAAI;AACnB,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AAEL,QAAM,aAAa,kBAAmB,OAA4B,KAAK,QAAQ,IAAK;AACpF,MAAI,eAA6B,WAAW,QAAQ;AAEpD,MAAI,2BAA2B;AAC7B,mBAAe,aAAa;AAAA,MAC1B,CAAC,UACC,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,OAAO,KAAK,KAAgC,EAAE,SAAS;AAAA,MACjG;AAAA,IACF;AAAA,EACF;AAEA,QAAM,YAAY,EAAE,GAAG,OAAO,GAAI,eAAe,CAAC,EAAG;AACrD,QAAM,OAAO,SAAS,EAAE,OAAO,SAAS,EAAE,OAAO,IAAI,EAAE,OAAO,SAAS;AAEvE,SAAO;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,MAAM,OAAO,KAAK,KAAK;AAAA,IACvB;AAAA,EACF;AACF;AA1CgB;AA6CT,MAAM,mBAAmB,EAAE,KAAK,CAAC,OAAO,QAAQ,OAAO,UAAU,SAAS,QAAQ,SAAS,CAAC;AAC5F,MAAM,uBAAuB,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,IAAI,GAAG,EAAE,MAAwB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../src/services/aws/s3.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../../../src/services/aws/s3.ts"],"names":[],"mappings":"AAIA,OAAO,EAML,QAAQ,EAGT,MAAM,oBAAoB,CAAC;AAI5B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAIjE,UAAU,mBAAmB;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,CAAC,OAAO,OAAO,KAAK;IACjB,MAAM,EAAE,QAAQ,CAAC;IAExB,OAAO,CAAC,OAAO,CAA0B;gBAE7B,OAAO,EAAE,OAAO,CAAC,uBAAuB,CAAC;IA4CrD,OAAO,CAAC,YAAY;IAQP,UAAU,CAAC,EACtB,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,WAAW,EACX,aAAa,EACb,UAAU,GACX,EAAE;QACD,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;QAC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E,MAAM,EAAE,GAAG,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;CA2BlG"}
|
package/dist/services/aws/s3.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { createWriteStream } from "node:fs";
|
|
4
|
+
import { dirname } from "node:path";
|
|
5
|
+
import { pipeline, Readable } from "node:stream";
|
|
6
|
+
import { promisify } from "node:util";
|
|
3
7
|
import {
|
|
4
8
|
CompleteMultipartUploadCommand,
|
|
5
9
|
CreateMultipartUploadCommand,
|
|
@@ -9,12 +13,8 @@ import {
|
|
|
9
13
|
UploadPartCommand
|
|
10
14
|
} from "@aws-sdk/client-s3";
|
|
11
15
|
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
12
|
-
import { File, Helper } from "../../util/index.js";
|
|
13
|
-
import { createWriteStream } from "fs";
|
|
14
|
-
import { Readable, pipeline } from "stream";
|
|
15
|
-
import { promisify } from "node:util";
|
|
16
16
|
import { Logger } from "../../logger/index.js";
|
|
17
|
-
import {
|
|
17
|
+
import { File, Helper } from "../../util/index.js";
|
|
18
18
|
const asyncPipeline = promisify(pipeline);
|
|
19
19
|
class AwsS3 {
|
|
20
20
|
static {
|
|
@@ -55,13 +55,10 @@ class AwsS3 {
|
|
|
55
55
|
this.client = new S3Client(s3ClientConfig);
|
|
56
56
|
}
|
|
57
57
|
getBucketUrl({ bucketName, path }) {
|
|
58
|
-
let url;
|
|
59
58
|
if (this.options.localstack.enabled) {
|
|
60
|
-
|
|
61
|
-
} else {
|
|
62
|
-
url = `https://${bucketName}.s3.amazonaws.com/${path}`;
|
|
59
|
+
return `http://localhost:${this.options.localstack.port}/${bucketName}/${path}`;
|
|
63
60
|
}
|
|
64
|
-
return
|
|
61
|
+
return `https://${bucketName}.s3.amazonaws.com/${path}`;
|
|
65
62
|
}
|
|
66
63
|
async uploadFile({
|
|
67
64
|
bucketName,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/services/aws/s3.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n CompleteMultipartUploadCommand,\n CreateMultipartUploadCommand,\n GetObjectCommand,\n PutObjectCommand,\n type PutObjectCommandInput,\n S3Client,\n type S3ClientConfig,\n UploadPartCommand,\n} from '@aws-sdk/client-s3';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport {
|
|
5
|
-
"mappings": ";;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,
|
|
4
|
+
"sourcesContent": ["import { createWriteStream } from 'node:fs';\nimport { dirname } from 'node:path';\nimport { pipeline, Readable } from 'node:stream';\nimport { promisify } from 'node:util';\nimport {\n CompleteMultipartUploadCommand,\n CreateMultipartUploadCommand,\n GetObjectCommand,\n PutObjectCommand,\n type PutObjectCommandInput,\n S3Client,\n type S3ClientConfig,\n UploadPartCommand,\n} from '@aws-sdk/client-s3';\nimport { getSignedUrl } from '@aws-sdk/s3-request-presigner';\nimport { Logger } from '../../logger/index.js';\nimport { File, Helper } from '../../util/index.js';\nimport type { AwsS3ConstructorOptions } from './s3.interface.js';\n\nconst asyncPipeline = promisify(pipeline);\n\ninterface DownloadFileOptions {\n bucketName: string;\n key: string;\n destinationFilePath: string;\n}\n\nexport default class AwsS3 {\n public client: S3Client;\n\n private options: AwsS3ConstructorOptions;\n\n constructor(options: Partial<AwsS3ConstructorOptions>) {\n // Define default options\n const defaultOptions: AwsS3ConstructorOptions = {\n region: 'us-east-1',\n localstack: {\n enabled: false,\n port: 4566,\n },\n };\n\n this.options = Helper.defaultsDeep(options, defaultOptions) as AwsS3ConstructorOptions;\n\n const s3ClientConfig: S3ClientConfig = {\n region: this.options.region,\n };\n\n if (this.options.localstack.enabled) {\n s3ClientConfig.forcePathStyle = true;\n\n if (!this.options.endpoint) {\n throw new Error('Endpoint is required when using LocalStack');\n }\n\n // s3ClientConfig.endpoint = `http://s3.localhost.localstack.cloud:${this.options.localstack.port}`; // Works when the Node.js API is calling from within the Docker container\n // s3ClientConfig.endpoint = `http://localhost:${this.options.localstack.port}`; // works out side of the container (media generator example)\n\n s3ClientConfig.endpoint = this.options.endpoint;\n\n s3ClientConfig.credentials = {\n accessKeyId: 'test',\n secretAccessKey: 'test',\n };\n } else {\n if (this.options.credentials?.accessKeyId && this.options.credentials?.secretAccessKey) {\n s3ClientConfig.credentials = {\n accessKeyId: this.options.credentials.accessKeyId,\n secretAccessKey: this.options.credentials.secretAccessKey,\n };\n }\n }\n\n this.client = new S3Client(s3ClientConfig);\n }\n\n private getBucketUrl({ bucketName, path }: { bucketName: string; path: string }) {\n if (this.options.localstack.enabled) {\n return `http://localhost:${this.options.localstack.port}/${bucketName}/${path}`;\n }\n\n return `https://${bucketName}.s3.amazonaws.com/${path}`;\n }\n\n public async uploadFile({\n bucketName,\n path,\n body,\n contentType,\n forceDownload,\n publicRead,\n }: {\n bucketName: string;\n path: string;\n body: Buffer;\n contentType?: string;\n forceDownload?: boolean;\n publicRead?: boolean;\n }): Promise<string> {\n let contentDisposition = forceDownload ? 'attachment' : 'inline';\n contentDisposition += `; filename=\"${path.split('/').pop()}\"`;\n\n const putObjectOptions: PutObjectCommandInput = {\n Bucket: bucketName,\n Key: path,\n Body: body,\n ContentDisposition: contentDisposition,\n ACL: publicRead ? 'public-read' : 'private',\n };\n\n if (contentType) {\n putObjectOptions.ContentType = contentType;\n }\n\n const command = new PutObjectCommand(putObjectOptions);\n\n await this.client.send(command);\n\n return this.getBucketUrl({ bucketName, path });\n }\n\n public async startMultipartUpload({\n bucketName,\n path,\n publicRead,\n }: {\n bucketName: string;\n path: string;\n publicRead?: boolean;\n }) {\n const command = new CreateMultipartUploadCommand({\n Bucket: bucketName,\n Key: path,\n ACL: publicRead ? 'public-read' : 'private',\n });\n\n const response = await this.client.send(command);\n\n return response.UploadId;\n }\n\n public async uploadPart({\n bucketName,\n path,\n partNumber,\n uploadId,\n body,\n }: {\n bucketName: string;\n path: string;\n partNumber: number;\n uploadId: string;\n body: any;\n }): Promise<string | undefined> {\n const command = new UploadPartCommand({\n Bucket: bucketName,\n Key: path,\n PartNumber: partNumber,\n UploadId: uploadId,\n Body: body,\n });\n\n const response = await this.client.send(command);\n\n return response.ETag;\n }\n\n public async completeMultipartUpload({\n bucketName,\n path,\n uploadId,\n parts,\n }: {\n bucketName: string;\n path: string;\n uploadId: string;\n parts: { PartNumber: number; ETag: string }[];\n }) {\n // Sort parts by PartNumber\n parts.sort((a, b) => a.PartNumber - b.PartNumber);\n\n const command = new CompleteMultipartUploadCommand({\n Bucket: bucketName,\n Key: path,\n UploadId: uploadId,\n MultipartUpload: {\n Parts: parts,\n },\n });\n\n const response = await this.client.send(command);\n\n if (!response.Location) {\n throw new Error('Failed to complete multipart upload');\n }\n\n // return response.Location;\n return this.getBucketUrl({\n bucketName,\n path,\n });\n }\n\n async downloadFile({\n bucketName,\n key,\n destinationFilePath,\n onStart,\n onProgress,\n onComplete,\n onError,\n }: DownloadFileOptions & {\n onStart?: () => void;\n onProgress?: (progress: number) => void;\n onComplete?: () => void;\n onError?: (error: Error) => void;\n }): Promise<void> {\n const decodedKey = decodeURIComponent(key);\n const bucketKey = decodedKey;\n\n Logger.info({\n message: 'Downloading file from S3',\n meta: {\n bucketName,\n Key: bucketKey,\n },\n });\n\n const getObjectParams = {\n Bucket: bucketName,\n Key: bucketKey,\n };\n\n try {\n const command = new GetObjectCommand(getObjectParams);\n\n const response = await this.client.send(command);\n\n if (!response.Body || !(response.Body instanceof Readable)) {\n throw new Error('Expected Body to be a readable stream!');\n }\n\n if (onStart) {\n onStart();\n }\n\n const directoryPath = dirname(destinationFilePath);\n\n // Ensure directory exists\n await File.ensureDir(directoryPath);\n\n const fileStream = createWriteStream(destinationFilePath);\n const totalSize = parseInt(response.ContentLength?.toString() ?? '0', 10);\n\n let bytesRead = 0;\n\n response.Body.on('data', (chunk: Buffer) => {\n bytesRead += chunk.length;\n\n if (onProgress && totalSize > 0) {\n const progress = Math.min((bytesRead / totalSize) * 100, 100);\n const formattedProgress = parseFloat(progress.toFixed(1));\n\n onProgress(formattedProgress);\n }\n });\n\n await asyncPipeline(response.Body, fileStream);\n\n // Verify file was written\n if (!(await File.pathExists(destinationFilePath))) {\n throw new Error(`Could not find downloaded file at ${destinationFilePath}`);\n }\n\n Logger.info({\n message: 'File successfully downloaded',\n meta: {\n Path: destinationFilePath,\n },\n });\n\n if (onComplete) {\n onComplete();\n }\n } catch (error) {\n Logger.error({ error });\n\n if (onError) {\n onError(error as Error);\n }\n\n throw error as Error;\n }\n }\n\n public async generateSignedUrl({ bucket, key }: { bucket: string; key: string }): Promise<string> {\n try {\n const command = new GetObjectCommand({\n Bucket: bucket,\n Key: key,\n });\n\n // Set the expiration for the signed URL to 1 hour\n const signedUrl = await getSignedUrl(this.client, command, {\n expiresIn: 3600,\n });\n\n // Log the signed URL\n Logger.info({\n message: 'Generated signed URL',\n meta: {\n URL: signedUrl,\n },\n });\n\n return signedUrl;\n } catch (error) {\n Logger.error({ error });\n\n throw error;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA,SAAS,yBAAyB;AAClC,SAAS,eAAe;AACxB,SAAS,UAAU,gBAAgB;AACnC,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EAEA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AACvB,SAAS,MAAM,cAAc;AAG7B,MAAM,gBAAgB,UAAU,QAAQ;AAQxC,MAAO,MAAoB;AAAA,EA3B3B,OA2B2B;AAAA;AAAA;AAAA,EAClB;AAAA,EAEC;AAAA,E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D,cAAM,IAAI,MAAM,qCAAqC,mBAAmB,EAAE;AAAA,MAC5E;AAEA,aAAO,KAAK;AAAA,QACV,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,MAAM;AAAA,QACR;AAAA,MACF,CAAC;AAED,UAAI,YAAY;AACd,mBAAW;AAAA,MACb;AAAA,IACF,SAAS,OAAO;AACd,aAAO,MAAM,EAAE,MAAM,CAAC;AAEtB,UAAI,SAAS;AACX,gBAAQ,KAAc;AAAA,MACxB;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,MAAa,kBAAkB,EAAE,QAAQ,IAAI,GAAqD;AAChG,QAAI;AACF,YAAM,UAAU,IAAI,iBAAiB;AAAA,QACnC,QAAQ;AAAA,QACR,KAAK;AAAA,MACP,CAAC;AAGD,YAAM,YAAY,MAAM,aAAa,KAAK,QAAQ,SAAS;AAAA,QACzD,WAAW;AAAA,MACb,CAAC;AAGD,aAAO,KAAK;AAAA,QACV,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,KAAK;AAAA,QACP;AAAA,MACF,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,aAAO,MAAM,EAAE,MAAM,CAAC;AAEtB,YAAM;AAAA,IACR;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/util/file.d.ts
CHANGED
|
@@ -9,11 +9,6 @@ declare function pathExists(pathToCheck: string): Promise<boolean>;
|
|
|
9
9
|
* @param dirPath - Directory path to ensure
|
|
10
10
|
*/
|
|
11
11
|
declare function ensureDir(dirPath: string): Promise<void>;
|
|
12
|
-
declare function convertFile({ inputFilePath, outputFilePath, format, }: {
|
|
13
|
-
inputFilePath: string;
|
|
14
|
-
outputFilePath: string;
|
|
15
|
-
format: string;
|
|
16
|
-
}): Promise<void>;
|
|
17
12
|
/**
|
|
18
13
|
* Copy a file or directory synchronously.
|
|
19
14
|
*
|
|
@@ -57,7 +52,6 @@ declare function formatFileSize({ bytes }: {
|
|
|
57
52
|
*/
|
|
58
53
|
declare function removeSync(target: string): void;
|
|
59
54
|
declare const _default: {
|
|
60
|
-
convertFile: typeof convertFile;
|
|
61
55
|
copySync: typeof copySync;
|
|
62
56
|
downloadFile: typeof downloadFile;
|
|
63
57
|
formatFileSize: typeof formatFileSize;
|
package/dist/util/file.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/util/file.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,iBAAe,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO/D;AAED;;;GAGG;AACH,iBAAe,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvD;AAED;;;;;;;;;;GAUG;AACH,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAmBjD;AAED;;;;;GAKG;AACH,iBAAe,YAAY,CAAC,EAAE,GAAG,EAAE,eAAe,EAAE,EAAE;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA4B7G;AAED;;;;GAIG;AACH,iBAAS,cAAc,CAAC,EAAE,KAAK,EAAE,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAyB5D;AAED;;;;;;;;;;GAUG;AACH,iBAAS,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAoBxC;;;;;;;;;AAED,wBAOE"}
|
package/dist/util/file.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import { access, mkdir } from "fs/promises";
|
|
5
|
-
import * as
|
|
6
|
-
import * as
|
|
7
|
-
import { pipeline } from "stream";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import { access, mkdir } from "node:fs/promises";
|
|
5
|
+
import * as https from "node:https";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { pipeline } from "node:stream";
|
|
8
8
|
import { promisify } from "node:util";
|
|
9
|
-
import ffmpeg from "fluent-ffmpeg";
|
|
10
9
|
const pipelineAsync = promisify(pipeline);
|
|
11
10
|
async function pathExists(pathToCheck) {
|
|
12
11
|
try {
|
|
@@ -25,26 +24,6 @@ async function ensureDir(dirPath) {
|
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
__name(ensureDir, "ensureDir");
|
|
28
|
-
async function convertFile({
|
|
29
|
-
inputFilePath,
|
|
30
|
-
outputFilePath,
|
|
31
|
-
format
|
|
32
|
-
}) {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
console.log(`Starting conversion: ${inputFilePath} -> ${outputFilePath} (format: ${format})`);
|
|
35
|
-
const command = ffmpeg(inputFilePath).output(outputFilePath).outputFormat(format === "jpg" ? "mjpeg" : format).on("progress", (progress) => {
|
|
36
|
-
console.log(`Processing: ${Math.round(progress.percent)}% done`);
|
|
37
|
-
}).on("end", () => {
|
|
38
|
-
console.log("Conversion finished successfully");
|
|
39
|
-
resolve();
|
|
40
|
-
}).on("error", (err) => {
|
|
41
|
-
console.error("Error during conversion:", err);
|
|
42
|
-
reject(err);
|
|
43
|
-
});
|
|
44
|
-
command.run();
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
__name(convertFile, "convertFile");
|
|
48
27
|
function copySync(src, dest) {
|
|
49
28
|
const stats = fs.statSync(src);
|
|
50
29
|
if (stats.isDirectory()) {
|
|
@@ -89,7 +68,7 @@ function formatFileSize({ bytes }) {
|
|
|
89
68
|
let idx = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
90
69
|
if (idx < 0) idx = 0;
|
|
91
70
|
if (idx >= units.length) idx = units.length - 1;
|
|
92
|
-
const fileSize = (bytes /
|
|
71
|
+
const fileSize = (bytes / 1024 ** idx).toFixed(1);
|
|
93
72
|
let unit;
|
|
94
73
|
switch (idx) {
|
|
95
74
|
case 0:
|
|
@@ -128,7 +107,6 @@ function removeSync(target) {
|
|
|
128
107
|
}
|
|
129
108
|
__name(removeSync, "removeSync");
|
|
130
109
|
var file_default = {
|
|
131
|
-
convertFile,
|
|
132
110
|
copySync,
|
|
133
111
|
downloadFile,
|
|
134
112
|
formatFileSize,
|