@riktajs/queue 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +16251 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +946 -0
- package/dist/index.d.ts +945 -21
- package/dist/index.js +16177 -29
- package/dist/index.js.map +1 -1
- package/package.json +13 -6
- package/dist/config/queue.config.d.ts +0 -43
- package/dist/config/queue.config.d.ts.map +0 -1
- package/dist/config/queue.config.js +0 -82
- package/dist/config/queue.config.js.map +0 -1
- package/dist/constants.d.ts +0 -33
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -37
- package/dist/constants.js.map +0 -1
- package/dist/decorators/events.decorator.d.ts +0 -85
- package/dist/decorators/events.decorator.d.ts.map +0 -1
- package/dist/decorators/events.decorator.js +0 -120
- package/dist/decorators/events.decorator.js.map +0 -1
- package/dist/decorators/index.d.ts +0 -8
- package/dist/decorators/index.d.ts.map +0 -1
- package/dist/decorators/index.js +0 -8
- package/dist/decorators/index.js.map +0 -1
- package/dist/decorators/process.decorator.d.ts +0 -41
- package/dist/decorators/process.decorator.d.ts.map +0 -1
- package/dist/decorators/process.decorator.js +0 -61
- package/dist/decorators/process.decorator.js.map +0 -1
- package/dist/decorators/processor.decorator.d.ts +0 -41
- package/dist/decorators/processor.decorator.d.ts.map +0 -1
- package/dist/decorators/processor.decorator.js +0 -59
- package/dist/decorators/processor.decorator.js.map +0 -1
- package/dist/decorators/queue.decorator.d.ts +0 -35
- package/dist/decorators/queue.decorator.d.ts.map +0 -1
- package/dist/decorators/queue.decorator.js +0 -49
- package/dist/decorators/queue.decorator.js.map +0 -1
- package/dist/events/queue-events.d.ts +0 -32
- package/dist/events/queue-events.d.ts.map +0 -1
- package/dist/events/queue-events.js +0 -103
- package/dist/events/queue-events.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/monitoring/bull-board.d.ts +0 -77
- package/dist/monitoring/bull-board.d.ts.map +0 -1
- package/dist/monitoring/bull-board.js +0 -112
- package/dist/monitoring/bull-board.js.map +0 -1
- package/dist/providers/queue.provider.d.ts +0 -113
- package/dist/providers/queue.provider.d.ts.map +0 -1
- package/dist/providers/queue.provider.js +0 -383
- package/dist/providers/queue.provider.js.map +0 -1
- package/dist/services/queue.service.d.ts +0 -133
- package/dist/services/queue.service.d.ts.map +0 -1
- package/dist/services/queue.service.js +0 -192
- package/dist/services/queue.service.js.map +0 -1
- package/dist/types.d.ts +0 -133
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/utils/connection.d.ts +0 -47
- package/dist/utils/connection.d.ts.map +0 -1
- package/dist/utils/connection.js +0 -102
- package/dist/utils/connection.js.map +0 -1
- package/dist/utils/validation.d.ts +0 -137
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js +0 -156
- package/dist/utils/validation.js.map +0 -1
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* QueueService - Injectable service for adding jobs to queues
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Service for adding jobs to queues from anywhere in the application.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* @Injectable()
|
|
10
|
-
* class NotificationService {
|
|
11
|
-
* @Autowired()
|
|
12
|
-
* private queueService!: QueueService;
|
|
13
|
-
*
|
|
14
|
-
* async sendNotification(userId: string, message: string) {
|
|
15
|
-
* await this.queueService.addJob('notifications', 'send', {
|
|
16
|
-
* userId,
|
|
17
|
-
* message,
|
|
18
|
-
* });
|
|
19
|
-
* }
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export class QueueService {
|
|
24
|
-
provider;
|
|
25
|
-
constructor(provider) {
|
|
26
|
-
this.provider = provider;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Add a job to a queue
|
|
30
|
-
*
|
|
31
|
-
* @param queueName - Name of the queue
|
|
32
|
-
* @param jobName - Name of the job (matches @Process decorator)
|
|
33
|
-
* @param data - Job payload data
|
|
34
|
-
* @param options - Optional job options
|
|
35
|
-
* @returns The created job
|
|
36
|
-
*/
|
|
37
|
-
async addJob(queueName, jobName, data, options) {
|
|
38
|
-
const queue = this.getQueueOrThrow(queueName);
|
|
39
|
-
// Handle deduplication
|
|
40
|
-
const jobOptions = { ...options };
|
|
41
|
-
if (options?.deduplicationKey) {
|
|
42
|
-
jobOptions.jobId = options.deduplicationKey;
|
|
43
|
-
}
|
|
44
|
-
return queue.add(jobName, data, jobOptions);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Add multiple jobs to a queue in bulk
|
|
48
|
-
*
|
|
49
|
-
* @param queueName - Name of the queue
|
|
50
|
-
* @param jobs - Array of jobs to add
|
|
51
|
-
* @returns Array of created jobs
|
|
52
|
-
*/
|
|
53
|
-
async addJobs(queueName, jobs) {
|
|
54
|
-
const queue = this.getQueueOrThrow(queueName);
|
|
55
|
-
const bulkJobs = jobs.map(j => ({
|
|
56
|
-
name: j.name,
|
|
57
|
-
data: j.data,
|
|
58
|
-
opts: j.options,
|
|
59
|
-
}));
|
|
60
|
-
return queue.addBulk(bulkJobs);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Add a delayed job
|
|
64
|
-
*
|
|
65
|
-
* @param queueName - Name of the queue
|
|
66
|
-
* @param jobName - Name of the job
|
|
67
|
-
* @param data - Job payload data
|
|
68
|
-
* @param delay - Delay in milliseconds
|
|
69
|
-
* @param options - Optional job options
|
|
70
|
-
*/
|
|
71
|
-
async addDelayedJob(queueName, jobName, data, delay, options) {
|
|
72
|
-
return this.addJob(queueName, jobName, data, { ...options, delay });
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Add a repeatable job (scheduled)
|
|
76
|
-
*
|
|
77
|
-
* @param queueName - Name of the queue
|
|
78
|
-
* @param jobName - Name of the job
|
|
79
|
-
* @param data - Job payload data
|
|
80
|
-
* @param repeat - Repeat options (cron pattern, interval, etc.)
|
|
81
|
-
* @param options - Optional schedule options
|
|
82
|
-
*/
|
|
83
|
-
async addRepeatableJob(queueName, jobName, data, repeat, options) {
|
|
84
|
-
const queue = this.getQueueOrThrow(queueName);
|
|
85
|
-
return queue.add(jobName, data, {
|
|
86
|
-
...options,
|
|
87
|
-
repeat,
|
|
88
|
-
jobId: options?.jobId,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Remove a repeatable job
|
|
93
|
-
*
|
|
94
|
-
* @param queueName - Name of the queue
|
|
95
|
-
* @param jobName - Name of the job
|
|
96
|
-
* @param repeat - The repeat options used when creating the job
|
|
97
|
-
*/
|
|
98
|
-
async removeRepeatableJob(queueName, jobName, repeat) {
|
|
99
|
-
const queue = this.getQueueOrThrow(queueName);
|
|
100
|
-
return queue.removeRepeatableByKey(`${jobName}:${JSON.stringify(repeat)}`);
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Get a job by ID
|
|
104
|
-
*
|
|
105
|
-
* @param queueName - Name of the queue
|
|
106
|
-
* @param jobId - Job ID
|
|
107
|
-
*/
|
|
108
|
-
async getJob(queueName, jobId) {
|
|
109
|
-
const queue = this.getQueueOrThrow(queueName);
|
|
110
|
-
return queue.getJob(jobId);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get queue statistics
|
|
114
|
-
*
|
|
115
|
-
* @param queueName - Name of the queue
|
|
116
|
-
*/
|
|
117
|
-
async getQueueStats(queueName) {
|
|
118
|
-
const queue = this.getQueueOrThrow(queueName);
|
|
119
|
-
const [waiting, active, completed, failed, delayed, paused] = await Promise.all([
|
|
120
|
-
queue.getWaitingCount(),
|
|
121
|
-
queue.getActiveCount(),
|
|
122
|
-
queue.getCompletedCount(),
|
|
123
|
-
queue.getFailedCount(),
|
|
124
|
-
queue.getDelayedCount(),
|
|
125
|
-
queue.isPaused().then(p => (p ? 1 : 0)),
|
|
126
|
-
]);
|
|
127
|
-
return { waiting, active, completed, failed, delayed, paused };
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Pause a queue
|
|
131
|
-
*/
|
|
132
|
-
async pauseQueue(queueName) {
|
|
133
|
-
const queue = this.getQueueOrThrow(queueName);
|
|
134
|
-
await queue.pause();
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Resume a queue
|
|
138
|
-
*/
|
|
139
|
-
async resumeQueue(queueName) {
|
|
140
|
-
const queue = this.getQueueOrThrow(queueName);
|
|
141
|
-
await queue.resume();
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Clear all jobs from a queue
|
|
145
|
-
*
|
|
146
|
-
* @param queueName - Name of the queue
|
|
147
|
-
* @param status - Which jobs to clear (default: all)
|
|
148
|
-
*/
|
|
149
|
-
async clearQueue(queueName, status) {
|
|
150
|
-
const queue = this.getQueueOrThrow(queueName);
|
|
151
|
-
if (status) {
|
|
152
|
-
await queue.clean(0, 0, status);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
await queue.obliterate({ force: true });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Get all queue names
|
|
160
|
-
*/
|
|
161
|
-
getQueueNames() {
|
|
162
|
-
return this.provider.getAllQueues().map(q => q.name);
|
|
163
|
-
}
|
|
164
|
-
getQueueOrThrow(queueName) {
|
|
165
|
-
const queue = this.provider.getQueue(queueName);
|
|
166
|
-
if (!queue) {
|
|
167
|
-
throw new QueueNotFoundError(queueName);
|
|
168
|
-
}
|
|
169
|
-
return queue;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Error thrown when a queue is not found
|
|
174
|
-
*/
|
|
175
|
-
export class QueueNotFoundError extends Error {
|
|
176
|
-
constructor(queueName) {
|
|
177
|
-
super(`Queue not found: ${queueName}`);
|
|
178
|
-
this.name = 'QueueNotFoundError';
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Error thrown when job validation fails
|
|
183
|
-
*/
|
|
184
|
-
export class JobValidationError extends Error {
|
|
185
|
-
errors;
|
|
186
|
-
constructor(message, errors) {
|
|
187
|
-
super(message);
|
|
188
|
-
this.errors = errors;
|
|
189
|
-
this.name = 'JobValidationError';
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
//# sourceMappingURL=queue.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"queue.service.js","sourceRoot":"","sources":["../../src/services/queue.service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,YAAY;IACM;IAA7B,YAA6B,QAAuB;QAAvB,aAAQ,GAAR,QAAQ,CAAe;IAAG,CAAC;IAExD;;;;;;;;OAQG;IACH,KAAK,CAAC,MAAM,CACV,SAAiB,EACjB,OAAe,EACf,IAAW,EACX,OAAuB;QAEvB,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAE9C,uBAAuB;QACvB,MAAM,UAAU,GAAgB,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,IAAI,OAAO,EAAE,gBAAgB,EAAE,CAAC;YAC9B,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC;QAC9C,CAAC;QAED,OAAO,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,UAAU,CAAiC,CAAC;IAC9E,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,CACX,SAAiB,EACjB,IAAiE;QAEjE,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;QAE9C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC9B,IAAI,EAAE,CAAC,CAA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AAC;aAAM,CAAC;YACN,MAAM,KAAK,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAEO,eAAe,CAAC,SAAiB;QACvC,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QAChD,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,SAAiB;QAC3B,KAAK,CAAC,oBAAoB,SAAS,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACE;IAA7C,YAAY,OAAe,EAAkB,MAAiB;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,WAAM,GAAN,MAAM,CAAW;QAE5D,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type definitions for @riktajs/queue
|
|
3
|
-
*/
|
|
4
|
-
import type { QueueOptions as BullMQQueueOptions, WorkerOptions as BullMQWorkerOptions, JobsOptions, RepeatOptions } from 'bullmq';
|
|
5
|
-
/** Redis connection configuration */
|
|
6
|
-
export interface RedisConnectionOptions {
|
|
7
|
-
/** Redis host */
|
|
8
|
-
host?: string;
|
|
9
|
-
/** Redis port */
|
|
10
|
-
port?: number;
|
|
11
|
-
/** Redis password */
|
|
12
|
-
password?: string;
|
|
13
|
-
/** Redis username */
|
|
14
|
-
username?: string;
|
|
15
|
-
/** Redis database number */
|
|
16
|
-
db?: number;
|
|
17
|
-
/** Enable TLS */
|
|
18
|
-
tls?: boolean;
|
|
19
|
-
/** Cluster mode configuration */
|
|
20
|
-
cluster?: {
|
|
21
|
-
nodes: Array<{
|
|
22
|
-
host: string;
|
|
23
|
-
port: number;
|
|
24
|
-
}>;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
/** Options for @Queue decorator */
|
|
28
|
-
export interface QueueDecoratorOptions {
|
|
29
|
-
/** Queue name (required) */
|
|
30
|
-
name: string;
|
|
31
|
-
/** BullMQ queue options */
|
|
32
|
-
options?: Omit<BullMQQueueOptions, 'connection'>;
|
|
33
|
-
/** Default job options */
|
|
34
|
-
defaultJobOptions?: JobsOptions;
|
|
35
|
-
}
|
|
36
|
-
/** Options for @Processor decorator */
|
|
37
|
-
export interface ProcessorOptions {
|
|
38
|
-
/** The queue name to process */
|
|
39
|
-
queueName: string;
|
|
40
|
-
/** Worker concurrency */
|
|
41
|
-
concurrency?: number;
|
|
42
|
-
/** Rate limiter configuration */
|
|
43
|
-
rateLimiter?: {
|
|
44
|
-
/** Maximum jobs per duration */
|
|
45
|
-
max: number;
|
|
46
|
-
/** Duration in milliseconds */
|
|
47
|
-
duration: number;
|
|
48
|
-
};
|
|
49
|
-
/** Additional BullMQ worker options */
|
|
50
|
-
workerOptions?: Omit<BullMQWorkerOptions, 'connection' | 'concurrency' | 'limiter'>;
|
|
51
|
-
}
|
|
52
|
-
/** Metadata for a job handler method */
|
|
53
|
-
export interface JobHandlerMeta {
|
|
54
|
-
/** Job name */
|
|
55
|
-
name: string;
|
|
56
|
-
/** Method name on the processor class */
|
|
57
|
-
methodName: string;
|
|
58
|
-
/** Validation schema (Zod) */
|
|
59
|
-
schema?: unknown;
|
|
60
|
-
}
|
|
61
|
-
/** Queue event names */
|
|
62
|
-
export type QueueEventName = 'job:added' | 'job:completed' | 'job:failed' | 'job:progress' | 'job:stalled' | 'job:delayed' | 'job:removed' | 'worker:ready' | 'worker:closed' | 'worker:error';
|
|
63
|
-
/** Metadata for an event handler method */
|
|
64
|
-
export interface EventHandlerMeta {
|
|
65
|
-
/** Event name */
|
|
66
|
-
event: QueueEventName;
|
|
67
|
-
/** Method name on the processor class */
|
|
68
|
-
methodName: string;
|
|
69
|
-
}
|
|
70
|
-
/** Event payload for queue events */
|
|
71
|
-
export interface QueueEventPayload<TData = unknown, TResult = unknown> {
|
|
72
|
-
/** Queue name */
|
|
73
|
-
queueName: string;
|
|
74
|
-
/** Job ID */
|
|
75
|
-
jobId: string;
|
|
76
|
-
/** Job name */
|
|
77
|
-
jobName: string;
|
|
78
|
-
/** Job data */
|
|
79
|
-
data: TData;
|
|
80
|
-
/** Job return value (for completed events) */
|
|
81
|
-
returnValue?: TResult;
|
|
82
|
-
/** Number of attempts made */
|
|
83
|
-
attemptsMade?: number;
|
|
84
|
-
/** Error message (for failed events) */
|
|
85
|
-
error?: string;
|
|
86
|
-
/** Progress value (for progress events) */
|
|
87
|
-
progress?: number | object;
|
|
88
|
-
/** Timestamp */
|
|
89
|
-
timestamp: number;
|
|
90
|
-
}
|
|
91
|
-
/** Options for adding a job */
|
|
92
|
-
export interface AddJobOptions extends JobsOptions {
|
|
93
|
-
/** Deduplicate by this key */
|
|
94
|
-
deduplicationKey?: string;
|
|
95
|
-
}
|
|
96
|
-
/** Repeat options for scheduled jobs */
|
|
97
|
-
export interface ScheduleOptions extends RepeatOptions {
|
|
98
|
-
/** Job ID for the repeatable job */
|
|
99
|
-
jobId?: string;
|
|
100
|
-
}
|
|
101
|
-
/** Queue configuration from environment/config */
|
|
102
|
-
export interface QueueConfig {
|
|
103
|
-
/** Redis connection options */
|
|
104
|
-
redis: RedisConnectionOptions;
|
|
105
|
-
/** Default worker concurrency */
|
|
106
|
-
defaultConcurrency?: number;
|
|
107
|
-
/** Default rate limiter */
|
|
108
|
-
defaultRateLimiter?: {
|
|
109
|
-
max: number;
|
|
110
|
-
duration: number;
|
|
111
|
-
};
|
|
112
|
-
/** Bull Board dashboard path */
|
|
113
|
-
dashboardPath?: string;
|
|
114
|
-
/** Enable dashboard (default: false in production) */
|
|
115
|
-
dashboardEnabled?: boolean;
|
|
116
|
-
/** Graceful shutdown timeout in ms */
|
|
117
|
-
shutdownTimeout?: number;
|
|
118
|
-
}
|
|
119
|
-
/** Provider options for creating QueueProvider */
|
|
120
|
-
export interface QueueProviderOptions {
|
|
121
|
-
/** Queue configuration */
|
|
122
|
-
config?: Partial<QueueConfig>;
|
|
123
|
-
/** Auto-initialize on provider init */
|
|
124
|
-
autoInitialize?: boolean;
|
|
125
|
-
/** Retry connection attempts */
|
|
126
|
-
retryAttempts?: number;
|
|
127
|
-
/** Delay between retries in ms */
|
|
128
|
-
retryDelay?: number;
|
|
129
|
-
}
|
|
130
|
-
/** Re-export useful BullMQ types */
|
|
131
|
-
export type { Job, Queue as BullQueue, Worker, QueueEvents } from 'bullmq';
|
|
132
|
-
export type { Redis } from 'ioredis';
|
|
133
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,YAAY,IAAI,kBAAkB,EAClC,aAAa,IAAI,mBAAmB,EACpC,WAAW,EACX,aAAa,EACd,MAAM,QAAQ,CAAC;AAEhB,qCAAqC;AACrC,MAAM,WAAW,sBAAsB;IACrC,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAA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CAAC;IAC3B,sCAAsC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,kDAAkD;AAClD,MAAM,WAAW,oBAAoB;IACnC,0BAA0B;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9B,uCAAuC;IACvC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gCAAgC;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kCAAkC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,oCAAoC;AACpC,YAAY,EAAE,GAAG,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC3E,YAAY,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Redis connection utilities
|
|
3
|
-
*/
|
|
4
|
-
import type { RedisConnectionOptions } from '../types.js';
|
|
5
|
-
import type { Redis, Cluster } from 'ioredis';
|
|
6
|
-
/**
|
|
7
|
-
* Create a Redis client based on configuration
|
|
8
|
-
* @param config - Redis connection options
|
|
9
|
-
*/
|
|
10
|
-
export declare function createRedisClient(config: RedisConnectionOptions): Redis | Cluster;
|
|
11
|
-
/**
|
|
12
|
-
* Error thrown when Redis connection fails
|
|
13
|
-
*/
|
|
14
|
-
export declare class QueueConnectionError extends Error {
|
|
15
|
-
readonly host?: string | undefined;
|
|
16
|
-
readonly port?: number | undefined;
|
|
17
|
-
readonly cause?: Error | undefined;
|
|
18
|
-
constructor(message: string, host?: string | undefined, port?: number | undefined, cause?: Error | undefined);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Manages a shared Redis connection for all queues
|
|
22
|
-
*/
|
|
23
|
-
export declare class RedisConnectionManager {
|
|
24
|
-
private client;
|
|
25
|
-
private config;
|
|
26
|
-
/**
|
|
27
|
-
* Initialize the connection manager with configuration
|
|
28
|
-
*/
|
|
29
|
-
configure(config: RedisConnectionOptions): this;
|
|
30
|
-
/**
|
|
31
|
-
* Get or create the Redis client
|
|
32
|
-
*/
|
|
33
|
-
getClient(): Redis | Cluster;
|
|
34
|
-
/**
|
|
35
|
-
* Check if client is connected
|
|
36
|
-
*/
|
|
37
|
-
isConnected(): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Close the Redis connection
|
|
40
|
-
*/
|
|
41
|
-
close(): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Disconnect immediately (force)
|
|
44
|
-
*/
|
|
45
|
-
disconnect(): void;
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAG9C;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,sBAAsB,GAAG,KAAK,GAAG,OAAO,CAqBjF;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;aAG3B,IAAI,CAAC,EAAE,MAAM;aACb,IAAI,CAAC,EAAE,MAAM;aACb,KAAK,CAAC,EAAE,KAAK;gBAH7B,OAAO,EAAE,MAAM,EACC,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,IAAI,CAAC,EAAE,MAAM,YAAA,EACb,KAAK,CAAC,EAAE,KAAK,YAAA;CAKhC;AAED;;GAEG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,MAAM,CAAgC;IAC9C,OAAO,CAAC,MAAM,CAAuC;IAErD;;OAEG;IACH,SAAS,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI;IAK/C;;OAEG;IACH,SAAS,IAAI,KAAK,GAAG,OAAO;IAqB5B;;OAEG;IACH,WAAW,IAAI,OAAO;IAKtB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAO5B;;OAEG;IACH,UAAU,IAAI,IAAI;CAMnB"}
|
package/dist/utils/connection.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Redis connection utilities
|
|
3
|
-
*/
|
|
4
|
-
import IORedis from 'ioredis';
|
|
5
|
-
/**
|
|
6
|
-
* Create a Redis client based on configuration
|
|
7
|
-
* @param config - Redis connection options
|
|
8
|
-
*/
|
|
9
|
-
export function createRedisClient(config) {
|
|
10
|
-
if (config.cluster?.nodes) {
|
|
11
|
-
// Cluster mode
|
|
12
|
-
return new IORedis.Cluster(config.cluster.nodes, {
|
|
13
|
-
redisOptions: {
|
|
14
|
-
password: config.password,
|
|
15
|
-
username: config.username,
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
// Single node mode
|
|
20
|
-
return new IORedis({
|
|
21
|
-
host: config.host || 'localhost',
|
|
22
|
-
port: config.port || 6379,
|
|
23
|
-
password: config.password,
|
|
24
|
-
username: config.username,
|
|
25
|
-
db: config.db || 0,
|
|
26
|
-
maxRetriesPerRequest: null, // Required for BullMQ
|
|
27
|
-
enableReadyCheck: false,
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Error thrown when Redis connection fails
|
|
32
|
-
*/
|
|
33
|
-
export class QueueConnectionError extends Error {
|
|
34
|
-
host;
|
|
35
|
-
port;
|
|
36
|
-
cause;
|
|
37
|
-
constructor(message, host, port, cause) {
|
|
38
|
-
super(message);
|
|
39
|
-
this.host = host;
|
|
40
|
-
this.port = port;
|
|
41
|
-
this.cause = cause;
|
|
42
|
-
this.name = 'QueueConnectionError';
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Manages a shared Redis connection for all queues
|
|
47
|
-
*/
|
|
48
|
-
export class RedisConnectionManager {
|
|
49
|
-
client = null;
|
|
50
|
-
config = null;
|
|
51
|
-
/**
|
|
52
|
-
* Initialize the connection manager with configuration
|
|
53
|
-
*/
|
|
54
|
-
configure(config) {
|
|
55
|
-
this.config = config;
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Get or create the Redis client
|
|
60
|
-
*/
|
|
61
|
-
getClient() {
|
|
62
|
-
if (!this.client) {
|
|
63
|
-
if (!this.config) {
|
|
64
|
-
throw new QueueConnectionError('Redis connection not configured');
|
|
65
|
-
}
|
|
66
|
-
try {
|
|
67
|
-
this.client = createRedisClient(this.config);
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
throw new QueueConnectionError(`Failed to create Redis connection: ${error.message}`, this.config.host, this.config.port, error);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return this.client;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Check if client is connected
|
|
77
|
-
*/
|
|
78
|
-
isConnected() {
|
|
79
|
-
if (!this.client)
|
|
80
|
-
return false;
|
|
81
|
-
return this.client.status === 'ready';
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Close the Redis connection
|
|
85
|
-
*/
|
|
86
|
-
async close() {
|
|
87
|
-
if (this.client) {
|
|
88
|
-
await this.client.quit();
|
|
89
|
-
this.client = null;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Disconnect immediately (force)
|
|
94
|
-
*/
|
|
95
|
-
disconnect() {
|
|
96
|
-
if (this.client) {
|
|
97
|
-
this.client.disconnect();
|
|
98
|
-
this.client = null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
//# sourceMappingURL=connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAA8B;IAC9D,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;QAC1B,eAAe;QACf,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE;YAC/C,YAAY,EAAE;gBACZ,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;aAC1B;SACF,CAAY,CAAC;IAChB,CAAC;IAED,mBAAmB;IACnB,OAAO,IAAK,OAAqD,CAAC;QAChE,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,WAAW;QAChC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,IAAI;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC;QAClB,oBAAoB,EAAE,IAAI,EAAE,sBAAsB;QAClD,gBAAgB,EAAE,KAAK;KACxB,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAG3B;IACA;IACA;IAJlB,YACE,OAAe,EACC,IAAa,EACb,IAAa,EACb,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAS;QACb,SAAI,GAAJ,IAAI,CAAS;QACb,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,sBAAsB;IACzB,M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AC;IACH,CAAC;CACF"}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zod validation utilities for job payloads
|
|
3
|
-
*/
|
|
4
|
-
import { z, type ZodSchema, type ZodError } from 'zod';
|
|
5
|
-
/**
|
|
6
|
-
* Creates a wrapper around a Zod schema for job validation
|
|
7
|
-
*
|
|
8
|
-
* @param schema - The Zod schema to use for validation
|
|
9
|
-
* @returns A wrapped schema with job-specific utilities
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const EmailJobSchema = createJobSchema(z.object({
|
|
14
|
-
* to: z.string().email(),
|
|
15
|
-
* subject: z.string().min(1),
|
|
16
|
-
* body: z.string(),
|
|
17
|
-
* }));
|
|
18
|
-
*
|
|
19
|
-
* // Validate job data
|
|
20
|
-
* const result = EmailJobSchema.validate({ to: 'test@example.com', subject: 'Hello', body: 'World' });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function createJobSchema<T>(schema: ZodSchema<T>): JobSchema<T>;
|
|
24
|
-
/**
|
|
25
|
-
* Wrapper class for Zod schemas with job-specific utilities
|
|
26
|
-
*/
|
|
27
|
-
export declare class JobSchema<T> {
|
|
28
|
-
private readonly schema;
|
|
29
|
-
constructor(schema: ZodSchema<T>);
|
|
30
|
-
/**
|
|
31
|
-
* Get the underlying Zod schema
|
|
32
|
-
*/
|
|
33
|
-
getSchema(): ZodSchema<T>;
|
|
34
|
-
/**
|
|
35
|
-
* Validate job data
|
|
36
|
-
* @throws JobValidationError if validation fails
|
|
37
|
-
*/
|
|
38
|
-
validate(data: unknown): T;
|
|
39
|
-
/**
|
|
40
|
-
* Validate job data, returning undefined on failure
|
|
41
|
-
*/
|
|
42
|
-
validateSafe(data: unknown): T | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Check if data is valid without throwing
|
|
45
|
-
*/
|
|
46
|
-
isValid(data: unknown): data is T;
|
|
47
|
-
/**
|
|
48
|
-
* Get validation errors for data
|
|
49
|
-
*/
|
|
50
|
-
getErrors(data: unknown): string[];
|
|
51
|
-
/**
|
|
52
|
-
* Parse and transform data with defaults
|
|
53
|
-
*/
|
|
54
|
-
parse(data: unknown): T;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Error thrown when job schema validation fails
|
|
58
|
-
*/
|
|
59
|
-
export declare class JobSchemaValidationError extends Error {
|
|
60
|
-
readonly zodError: ZodError;
|
|
61
|
-
constructor(message: string, zodError: ZodError);
|
|
62
|
-
/**
|
|
63
|
-
* Get formatted validation errors
|
|
64
|
-
*/
|
|
65
|
-
getErrors(): Array<{
|
|
66
|
-
path: string;
|
|
67
|
-
message: string;
|
|
68
|
-
}>;
|
|
69
|
-
}
|
|
70
|
-
export { z };
|
|
71
|
-
/**
|
|
72
|
-
* Common job schemas for typical use cases
|
|
73
|
-
*/
|
|
74
|
-
export declare const CommonJobSchemas: {
|
|
75
|
-
/**
|
|
76
|
-
* Email job schema
|
|
77
|
-
*/
|
|
78
|
-
email: z.ZodObject<{
|
|
79
|
-
to: z.ZodString;
|
|
80
|
-
cc: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
81
|
-
bcc: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
82
|
-
subject: z.ZodString;
|
|
83
|
-
body: z.ZodString;
|
|
84
|
-
html: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
85
|
-
attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
86
|
-
filename: z.ZodString;
|
|
87
|
-
content: z.ZodString;
|
|
88
|
-
contentType: z.ZodOptional<z.ZodString>;
|
|
89
|
-
}, z.core.$strip>>>;
|
|
90
|
-
}, z.core.$strip>;
|
|
91
|
-
/**
|
|
92
|
-
* Notification job schema
|
|
93
|
-
*/
|
|
94
|
-
notification: z.ZodObject<{
|
|
95
|
-
userId: z.ZodString;
|
|
96
|
-
title: z.ZodString;
|
|
97
|
-
message: z.ZodString;
|
|
98
|
-
type: z.ZodDefault<z.ZodEnum<{
|
|
99
|
-
error: "error";
|
|
100
|
-
success: "success";
|
|
101
|
-
info: "info";
|
|
102
|
-
warning: "warning";
|
|
103
|
-
}>>;
|
|
104
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
105
|
-
}, z.core.$strip>;
|
|
106
|
-
/**
|
|
107
|
-
* File processing job schema
|
|
108
|
-
*/
|
|
109
|
-
fileProcessing: z.ZodObject<{
|
|
110
|
-
fileId: z.ZodString;
|
|
111
|
-
filePath: z.ZodString;
|
|
112
|
-
operation: z.ZodEnum<{
|
|
113
|
-
resize: "resize";
|
|
114
|
-
compress: "compress";
|
|
115
|
-
convert: "convert";
|
|
116
|
-
thumbnail: "thumbnail";
|
|
117
|
-
}>;
|
|
118
|
-
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
119
|
-
}, z.core.$strip>;
|
|
120
|
-
/**
|
|
121
|
-
* Webhook job schema
|
|
122
|
-
*/
|
|
123
|
-
webhook: z.ZodObject<{
|
|
124
|
-
url: z.ZodString;
|
|
125
|
-
method: z.ZodDefault<z.ZodEnum<{
|
|
126
|
-
DELETE: "DELETE";
|
|
127
|
-
GET: "GET";
|
|
128
|
-
PATCH: "PATCH";
|
|
129
|
-
POST: "POST";
|
|
130
|
-
PUT: "PUT";
|
|
131
|
-
}>>;
|
|
132
|
-
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
133
|
-
body: z.ZodOptional<z.ZodUnknown>;
|
|
134
|
-
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
135
|
-
}, z.core.$strip>;
|
|
136
|
-
};
|
|
137
|
-
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAA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