@monque/tsed 0.1.0
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 +15 -0
- package/README.md +222 -0
- package/dist/CHANGELOG.md +19 -0
- package/dist/LICENSE +15 -0
- package/dist/README.md +222 -0
- package/dist/index.cjs +712 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +582 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +582 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +691 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +98 -0
- package/src/config/config.ts +60 -0
- package/src/config/index.ts +2 -0
- package/src/config/types.ts +114 -0
- package/src/constants/constants.ts +12 -0
- package/src/constants/index.ts +2 -0
- package/src/constants/types.ts +21 -0
- package/src/decorators/cron.ts +58 -0
- package/src/decorators/index.ts +10 -0
- package/src/decorators/types.ts +131 -0
- package/src/decorators/worker-controller.ts +55 -0
- package/src/decorators/worker.ts +66 -0
- package/src/index.ts +20 -0
- package/src/monque-module.ts +199 -0
- package/src/services/index.ts +1 -0
- package/src/services/monque-service.ts +267 -0
- package/src/utils/build-job-name.ts +17 -0
- package/src/utils/collect-worker-metadata.ts +95 -0
- package/src/utils/get-worker-token.ts +27 -0
- package/src/utils/guards.ts +62 -0
- package/src/utils/index.ts +13 -0
- package/src/utils/resolve-database.ts +119 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/config/types.ts","../src/config/config.ts","../src/constants/constants.ts","../src/constants/types.ts","../src/decorators/types.ts","../src/decorators/cron.ts","../src/decorators/worker.ts","../src/decorators/worker-controller.ts","../src/services/monque-service.ts","../src/monque-module.ts","../src/utils/build-job-name.ts","../src/utils/collect-worker-metadata.ts","../src/utils/get-worker-token.ts","../src/utils/resolve-database.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;UA0BiB,gBAAA,SAAyB,IAAA,CA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AAA,CAAc,CAAA,MAAO,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;AZVN;;;;;;;;;iBY6C7B,eAAA,CACrB,MAAA,EAAQ,gBAAA,EACR,UAAA,GAAa,UAAA,GACX,OAAA,CAAQ,EAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import { Configuration, InjectorService, LOGGER, OnDestroy, OnInit, TokenProvider } from "@tsed/di";
|
|
2
|
+
import { BulkOperationResult, CursorOptions, CursorPage, EnqueueOptions, GetJobsFilter, JobSelector, Monque, MonqueOptions, PersistedJob, QueueStats, ScheduleOptions, WorkerOptions } from "@monque/core";
|
|
3
|
+
import { Db, ObjectId } from "mongodb";
|
|
4
|
+
|
|
5
|
+
//#region src/config/types.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Configuration options for @monque/tsed.
|
|
8
|
+
*
|
|
9
|
+
* Extends MonqueOptions with Ts.ED-specific settings for database resolution
|
|
10
|
+
* and module behavior.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* @Configuration({
|
|
15
|
+
* monque: {
|
|
16
|
+
* db: mongoClient.db("myapp"),
|
|
17
|
+
* collectionName: "jobs",
|
|
18
|
+
* defaultConcurrency: 5
|
|
19
|
+
* }
|
|
20
|
+
* })
|
|
21
|
+
* export class Server {}
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
interface MonqueTsedConfig extends Omit<MonqueOptions, 'db'> {
|
|
25
|
+
/**
|
|
26
|
+
* Enable or disable the Monque module.
|
|
27
|
+
*
|
|
28
|
+
* When disabled:
|
|
29
|
+
* - Workers are not registered
|
|
30
|
+
* - Lifecycle hooks are no-ops
|
|
31
|
+
* - MonqueService throws on access
|
|
32
|
+
*
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
enabled?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Direct MongoDB database instance.
|
|
38
|
+
*
|
|
39
|
+
* Use when you have a pre-connected Db object available synchronously.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* @Configuration({
|
|
44
|
+
* monque: {
|
|
45
|
+
* db: mongoClient.db("myapp"),
|
|
46
|
+
* collectionName: "jobs"
|
|
47
|
+
* }
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
db?: Db;
|
|
52
|
+
/**
|
|
53
|
+
* Factory function to create the database connection.
|
|
54
|
+
*
|
|
55
|
+
* Called once during module initialization. Supports async factories
|
|
56
|
+
* for connection pooling or lazy initialization.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* @Configuration({
|
|
61
|
+
* monque: {
|
|
62
|
+
* dbFactory: async () => {
|
|
63
|
+
* const client = await MongoClient.connect(process.env.MONGO_URI!);
|
|
64
|
+
* return client.db("myapp");
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
dbFactory?: () => Promise<Db> | Db;
|
|
71
|
+
/**
|
|
72
|
+
* DI token to inject the Db instance from the container.
|
|
73
|
+
*
|
|
74
|
+
* Use when your application already has a MongoDB provider registered
|
|
75
|
+
* in the DI container.
|
|
76
|
+
*
|
|
77
|
+
* Can also be used to inject a MongooseService or Connection.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // First, register a MongoDB provider
|
|
82
|
+
* registerProvider({
|
|
83
|
+
* provide: "MONGODB_DATABASE",
|
|
84
|
+
* useFactory: async () => {
|
|
85
|
+
* const client = await MongoClient.connect(uri);
|
|
86
|
+
* return client.db("myapp");
|
|
87
|
+
* }
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* // Then reference it in config
|
|
91
|
+
* @Configuration({
|
|
92
|
+
* monque: {
|
|
93
|
+
* dbToken: "MONGODB_DATABASE"
|
|
94
|
+
* }
|
|
95
|
+
* })
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
dbToken?: TokenProvider<Db> | string;
|
|
99
|
+
/**
|
|
100
|
+
* Connection ID of the Mongoose connection to use.
|
|
101
|
+
*
|
|
102
|
+
* Requires the use of `dbToken` pointing to `MongooseService`.
|
|
103
|
+
*
|
|
104
|
+
* @default "default"
|
|
105
|
+
*/
|
|
106
|
+
mongooseConnectionId?: string;
|
|
107
|
+
}
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/config/config.d.ts
|
|
110
|
+
/**
|
|
111
|
+
* Augment TsED's Configuration interface to include monque settings.
|
|
112
|
+
*
|
|
113
|
+
* This allows type-safe configuration via @Configuration decorator.
|
|
114
|
+
*/
|
|
115
|
+
declare global {
|
|
116
|
+
namespace TsED {
|
|
117
|
+
interface Configuration {
|
|
118
|
+
/**
|
|
119
|
+
* Monque job queue configuration.
|
|
120
|
+
*/
|
|
121
|
+
monque?: MonqueTsedConfig;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Validate that exactly one database resolution strategy is provided.
|
|
127
|
+
*
|
|
128
|
+
* @param config - The configuration to validate.
|
|
129
|
+
* @throws Error if zero or multiple strategies are provided.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* validateDatabaseConfig({ db: mongoDb }); // OK
|
|
134
|
+
* validateDatabaseConfig({}); // throws
|
|
135
|
+
* validateDatabaseConfig({ db: mongoDb, dbFactory: fn }); // throws
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
declare function validateDatabaseConfig(config: MonqueTsedConfig): void;
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/constants/constants.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* Symbol used to store decorator metadata on class constructors.
|
|
143
|
+
*
|
|
144
|
+
* Used by @WorkerController, @Worker, and @Cron decorators to attach
|
|
145
|
+
* metadata that is later collected by MonqueModule during initialization.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* Store.from(Class).set(MONQUE, metadata);
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
declare const MONQUE: unique symbol;
|
|
153
|
+
//#endregion
|
|
154
|
+
//#region src/constants/types.d.ts
|
|
155
|
+
/**
|
|
156
|
+
* Provider type constants for DI scanning.
|
|
157
|
+
*
|
|
158
|
+
* These constants are used to categorize providers registered with Ts.ED's
|
|
159
|
+
* dependency injection container, enabling MonqueModule to discover and
|
|
160
|
+
* register workers automatically.
|
|
161
|
+
*
|
|
162
|
+
* Note: Using string constants with `as const` instead of enums per
|
|
163
|
+
* Constitution guidelines.
|
|
164
|
+
*/
|
|
165
|
+
declare const ProviderTypes: {
|
|
166
|
+
/** Provider type for @WorkerController decorated classes */readonly WORKER_CONTROLLER: "monque:worker-controller"; /** Provider type for cron job handlers */
|
|
167
|
+
readonly CRON: "monque:cron";
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* Union type of all provider type values.
|
|
171
|
+
*/
|
|
172
|
+
type ProviderType = (typeof ProviderTypes)[keyof typeof ProviderTypes];
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/decorators/types.d.ts
|
|
175
|
+
/**
|
|
176
|
+
* Options for the @Worker method decorator.
|
|
177
|
+
*
|
|
178
|
+
* Maps to @monque/core WorkerOptions. All standard Monque worker options
|
|
179
|
+
* are exposed here for decorator-based configuration.
|
|
180
|
+
*/
|
|
181
|
+
interface WorkerDecoratorOptions extends WorkerOptions {}
|
|
182
|
+
/**
|
|
183
|
+
* Metadata for a single @Worker decorated method.
|
|
184
|
+
*
|
|
185
|
+
* Stored in the WorkerStore and used by MonqueModule to register workers.
|
|
186
|
+
*/
|
|
187
|
+
interface WorkerMetadata {
|
|
188
|
+
/**
|
|
189
|
+
* Job name (without namespace prefix).
|
|
190
|
+
* Combined with controller namespace to form full job name.
|
|
191
|
+
*/
|
|
192
|
+
name: string;
|
|
193
|
+
/**
|
|
194
|
+
* Method name on the controller class.
|
|
195
|
+
*/
|
|
196
|
+
method: string;
|
|
197
|
+
/**
|
|
198
|
+
* Worker options forwarded to Monque.register().
|
|
199
|
+
*/
|
|
200
|
+
opts: WorkerDecoratorOptions;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Options for the @Cron method decorator.
|
|
204
|
+
*
|
|
205
|
+
* Maps to @monque/core ScheduleOptions with additional metadata overrides.
|
|
206
|
+
*/
|
|
207
|
+
interface CronDecoratorOptions extends ScheduleOptions {
|
|
208
|
+
/**
|
|
209
|
+
* Override job name (defaults to method name).
|
|
210
|
+
*/
|
|
211
|
+
name?: string;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Metadata for a single @Cron decorated method.
|
|
215
|
+
*
|
|
216
|
+
* Stored in the WorkerStore and used by MonqueModule to schedule cron jobs.
|
|
217
|
+
*/
|
|
218
|
+
interface CronMetadata {
|
|
219
|
+
/**
|
|
220
|
+
* Cron expression (5-field standard or predefined like @daily).
|
|
221
|
+
*/
|
|
222
|
+
pattern: string;
|
|
223
|
+
/**
|
|
224
|
+
* Job name (defaults to method name if not specified in options).
|
|
225
|
+
*/
|
|
226
|
+
name: string;
|
|
227
|
+
/**
|
|
228
|
+
* Method name on the controller class.
|
|
229
|
+
*/
|
|
230
|
+
method: string;
|
|
231
|
+
/**
|
|
232
|
+
* Schedule options forwarded to Monque.schedule().
|
|
233
|
+
*/
|
|
234
|
+
opts: CronDecoratorOptions;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Complete metadata structure stored on @WorkerController classes.
|
|
238
|
+
*
|
|
239
|
+
* Accessed via `Store.from(Class).get(MONQUE)`.
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* const store = Store.from(EmailWorkers).get<WorkerStore>(MONQUE);
|
|
244
|
+
* console.log(store.namespace); // "email"
|
|
245
|
+
* console.log(store.workers); // [{ name: "send", method: "sendEmail", opts: {} }]
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
interface WorkerStore {
|
|
249
|
+
/**
|
|
250
|
+
* Type identifier for the store.
|
|
251
|
+
* Always "controller" for WorkerController.
|
|
252
|
+
*/
|
|
253
|
+
type: 'controller';
|
|
254
|
+
/**
|
|
255
|
+
* Optional namespace prefix for all jobs in this controller.
|
|
256
|
+
* When set, job names become "{namespace}.{name}".
|
|
257
|
+
*/
|
|
258
|
+
namespace?: string;
|
|
259
|
+
/**
|
|
260
|
+
* Worker method registrations from @Worker decorators.
|
|
261
|
+
*/
|
|
262
|
+
workers: WorkerMetadata[];
|
|
263
|
+
/**
|
|
264
|
+
* Cron job registrations from @Cron decorators.
|
|
265
|
+
*/
|
|
266
|
+
cronJobs: CronMetadata[];
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/decorators/cron.d.ts
|
|
270
|
+
/**
|
|
271
|
+
* Method decorator that registers a method as a scheduled cron job.
|
|
272
|
+
*
|
|
273
|
+
* @param pattern - Cron expression (e.g., "* * * * *", "@daily")
|
|
274
|
+
* @param options - Optional cron configuration (name, timezone, etc.)
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```typescript
|
|
278
|
+
* @WorkerController()
|
|
279
|
+
* class ReportWorkers {
|
|
280
|
+
* @Cron("@daily", { timezone: "UTC" })
|
|
281
|
+
* async generateDailyReport() {
|
|
282
|
+
* // ...
|
|
283
|
+
* }
|
|
284
|
+
* }
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
declare function Cron(pattern: string, options?: CronDecoratorOptions): MethodDecorator;
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/decorators/worker.d.ts
|
|
290
|
+
/**
|
|
291
|
+
* Method decorator that registers a method as a job handler.
|
|
292
|
+
*
|
|
293
|
+
* @param name - The job name (will be prefixed with controller namespace if present)
|
|
294
|
+
* @param options - Optional worker configuration (concurrency, replace, etc.)
|
|
295
|
+
*/
|
|
296
|
+
declare function Worker(name: string, options?: WorkerDecoratorOptions): MethodDecorator;
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/decorators/worker-controller.d.ts
|
|
299
|
+
/**
|
|
300
|
+
* Class decorator that registers a class as a worker controller.
|
|
301
|
+
*
|
|
302
|
+
* @param namespace - Optional namespace prefix for job names
|
|
303
|
+
*/
|
|
304
|
+
declare function WorkerController(namespace?: string): ClassDecorator;
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region src/services/monque-service.d.ts
|
|
307
|
+
/**
|
|
308
|
+
* Injectable service that wraps the Monque instance.
|
|
309
|
+
*
|
|
310
|
+
* Exposes the full Monque public API through dependency injection.
|
|
311
|
+
*/
|
|
312
|
+
declare class MonqueService {
|
|
313
|
+
/**
|
|
314
|
+
* Internal Monque instance (set by MonqueModule)
|
|
315
|
+
* @internal
|
|
316
|
+
*/
|
|
317
|
+
private _monque;
|
|
318
|
+
/**
|
|
319
|
+
* Set the internal Monque instance.
|
|
320
|
+
* Called by MonqueModule during initialization.
|
|
321
|
+
* @internal
|
|
322
|
+
*/
|
|
323
|
+
_setMonque(monque: Monque): void;
|
|
324
|
+
/**
|
|
325
|
+
* Access the underlying Monque instance.
|
|
326
|
+
* @throws Error if MonqueModule is not initialized
|
|
327
|
+
*/
|
|
328
|
+
get monque(): Monque;
|
|
329
|
+
/**
|
|
330
|
+
* Enqueue a job for processing.
|
|
331
|
+
*
|
|
332
|
+
* @param name - Job type identifier (use full namespaced name, e.g., "email.send")
|
|
333
|
+
* @param data - Job payload
|
|
334
|
+
* @param options - Scheduling and deduplication options
|
|
335
|
+
* @returns The created or existing job document
|
|
336
|
+
*/
|
|
337
|
+
enqueue<T>(name: string, data: T, options?: EnqueueOptions): Promise<PersistedJob<T>>;
|
|
338
|
+
/**
|
|
339
|
+
* Enqueue a job for immediate processing.
|
|
340
|
+
*
|
|
341
|
+
* @param name - Job type identifier
|
|
342
|
+
* @param data - Job payload
|
|
343
|
+
* @returns The created job document
|
|
344
|
+
*/
|
|
345
|
+
now<T>(name: string, data: T): Promise<PersistedJob<T>>;
|
|
346
|
+
/**
|
|
347
|
+
* Schedule a recurring job with a cron expression.
|
|
348
|
+
*
|
|
349
|
+
* @param cron - Cron expression (5-field standard or predefined like @daily)
|
|
350
|
+
* @param name - Job type identifier
|
|
351
|
+
* @param data - Job payload
|
|
352
|
+
* @param options - Scheduling options
|
|
353
|
+
* @returns The created job document
|
|
354
|
+
*/
|
|
355
|
+
schedule<T>(cron: string, name: string, data: T, options?: ScheduleOptions): Promise<PersistedJob<T>>;
|
|
356
|
+
/**
|
|
357
|
+
* Cancel a pending or scheduled job.
|
|
358
|
+
*
|
|
359
|
+
* @param jobId - The ID of the job to cancel
|
|
360
|
+
* @returns The cancelled job, or null if not found
|
|
361
|
+
*/
|
|
362
|
+
cancelJob(jobId: string): Promise<PersistedJob<unknown> | null>;
|
|
363
|
+
/**
|
|
364
|
+
* Retry a failed or cancelled job.
|
|
365
|
+
*
|
|
366
|
+
* @param jobId - The ID of the job to retry
|
|
367
|
+
* @returns The updated job, or null if not found
|
|
368
|
+
*/
|
|
369
|
+
retryJob(jobId: string): Promise<PersistedJob<unknown> | null>;
|
|
370
|
+
/**
|
|
371
|
+
* Reschedule a pending job to run at a different time.
|
|
372
|
+
*
|
|
373
|
+
* @param jobId - The ID of the job to reschedule
|
|
374
|
+
* @param runAt - The new Date when the job should run
|
|
375
|
+
* @returns The updated job, or null if not found
|
|
376
|
+
*/
|
|
377
|
+
rescheduleJob(jobId: string, runAt: Date): Promise<PersistedJob<unknown> | null>;
|
|
378
|
+
/**
|
|
379
|
+
* Permanently delete a job.
|
|
380
|
+
*
|
|
381
|
+
* @param jobId - The ID of the job to delete
|
|
382
|
+
* @returns true if deleted, false if job not found
|
|
383
|
+
*/
|
|
384
|
+
deleteJob(jobId: string): Promise<boolean>;
|
|
385
|
+
/**
|
|
386
|
+
* Cancel multiple jobs matching the given filter.
|
|
387
|
+
*
|
|
388
|
+
* @param filter - Selector for which jobs to cancel
|
|
389
|
+
* @returns Result with count of cancelled jobs
|
|
390
|
+
*/
|
|
391
|
+
cancelJobs(filter: JobSelector): Promise<BulkOperationResult>;
|
|
392
|
+
/**
|
|
393
|
+
* Retry multiple jobs matching the given filter.
|
|
394
|
+
*
|
|
395
|
+
* @param filter - Selector for which jobs to retry
|
|
396
|
+
* @returns Result with count of retried jobs
|
|
397
|
+
*/
|
|
398
|
+
retryJobs(filter: JobSelector): Promise<BulkOperationResult>;
|
|
399
|
+
/**
|
|
400
|
+
* Delete multiple jobs matching the given filter.
|
|
401
|
+
*
|
|
402
|
+
* @param filter - Selector for which jobs to delete
|
|
403
|
+
* @returns Result with count of deleted jobs
|
|
404
|
+
*/
|
|
405
|
+
deleteJobs(filter: JobSelector): Promise<BulkOperationResult>;
|
|
406
|
+
/**
|
|
407
|
+
* Get a job by its ID.
|
|
408
|
+
*
|
|
409
|
+
* @param jobId - The job's ObjectId (as string or ObjectId)
|
|
410
|
+
* @returns The job document, or null if not found
|
|
411
|
+
* @throws MonqueError if jobId is an invalid hex string
|
|
412
|
+
*/
|
|
413
|
+
getJob<T>(jobId: string | ObjectId): Promise<PersistedJob<T> | null>;
|
|
414
|
+
/**
|
|
415
|
+
* Query jobs from the queue with optional filters.
|
|
416
|
+
*
|
|
417
|
+
* @param filter - Optional filter criteria (name, status, limit, skip)
|
|
418
|
+
* @returns Array of matching jobs
|
|
419
|
+
*/
|
|
420
|
+
getJobs<T>(filter?: GetJobsFilter): Promise<PersistedJob<T>[]>;
|
|
421
|
+
/**
|
|
422
|
+
* Get a paginated list of jobs using opaque cursors.
|
|
423
|
+
*
|
|
424
|
+
* @param options - Pagination options (cursor, limit, direction, filter)
|
|
425
|
+
* @returns Page of jobs with next/prev cursors
|
|
426
|
+
*/
|
|
427
|
+
getJobsWithCursor<T>(options?: CursorOptions): Promise<CursorPage<T>>;
|
|
428
|
+
/**
|
|
429
|
+
* Get aggregate statistics for the job queue.
|
|
430
|
+
*
|
|
431
|
+
* @param filter - Optional filter to scope statistics by job name
|
|
432
|
+
* @returns Queue statistics
|
|
433
|
+
*/
|
|
434
|
+
getQueueStats(filter?: Pick<JobSelector, 'name'>): Promise<QueueStats>;
|
|
435
|
+
/**
|
|
436
|
+
* Check if the scheduler is healthy and running.
|
|
437
|
+
*
|
|
438
|
+
* @returns true if running and connected
|
|
439
|
+
*/
|
|
440
|
+
isHealthy(): boolean;
|
|
441
|
+
}
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/monque-module.d.ts
|
|
444
|
+
declare class MonqueModule implements OnInit, OnDestroy {
|
|
445
|
+
protected injector: InjectorService;
|
|
446
|
+
protected monqueService: MonqueService;
|
|
447
|
+
protected logger: LOGGER;
|
|
448
|
+
protected monqueConfig: MonqueTsedConfig;
|
|
449
|
+
protected monque: Monque | null;
|
|
450
|
+
constructor(injector: InjectorService, monqueService: MonqueService, logger: LOGGER, configuration: Configuration);
|
|
451
|
+
$onInit(): Promise<void>;
|
|
452
|
+
$onDestroy(): Promise<void>;
|
|
453
|
+
/**
|
|
454
|
+
* Discover and register all workers from @WorkerController providers
|
|
455
|
+
*/
|
|
456
|
+
protected registerWorkers(): Promise<void>;
|
|
457
|
+
}
|
|
458
|
+
//#endregion
|
|
459
|
+
//#region src/utils/build-job-name.d.ts
|
|
460
|
+
/**
|
|
461
|
+
* Build the full job name by combining namespace and name.
|
|
462
|
+
*
|
|
463
|
+
* @param namespace - Optional namespace from @WorkerController
|
|
464
|
+
* @param name - Job name from @Worker or @Cron
|
|
465
|
+
* @returns Full job name (e.g., "email.send" or just "send")
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```typescript
|
|
469
|
+
* buildJobName("email", "send"); // "email.send"
|
|
470
|
+
* buildJobName(undefined, "send"); // "send"
|
|
471
|
+
* buildJobName("", "send"); // "send"
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
declare function buildJobName(namespace: string | undefined, name: string): string;
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/utils/collect-worker-metadata.d.ts
|
|
477
|
+
/**
|
|
478
|
+
* Collected worker registration info ready for Monque.register()
|
|
479
|
+
*/
|
|
480
|
+
interface CollectedWorkerMetadata {
|
|
481
|
+
/**
|
|
482
|
+
* Full job name (with namespace prefix if applicable)
|
|
483
|
+
*/
|
|
484
|
+
fullName: string;
|
|
485
|
+
/**
|
|
486
|
+
* Method name on the controller class
|
|
487
|
+
*/
|
|
488
|
+
method: string;
|
|
489
|
+
/**
|
|
490
|
+
* Worker options to pass to Monque.register()
|
|
491
|
+
*/
|
|
492
|
+
opts: WorkerDecoratorOptions | CronDecoratorOptions;
|
|
493
|
+
/**
|
|
494
|
+
* Whether this is a cron job
|
|
495
|
+
*/
|
|
496
|
+
isCron: boolean;
|
|
497
|
+
/**
|
|
498
|
+
* Cron pattern (only for cron jobs)
|
|
499
|
+
*/
|
|
500
|
+
cronPattern?: string;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Collect all worker metadata from a class.
|
|
504
|
+
*
|
|
505
|
+
* @param target - The class constructor (decorated with @WorkerController)
|
|
506
|
+
* @returns Array of collected worker metadata ready for registration
|
|
507
|
+
*
|
|
508
|
+
* @example
|
|
509
|
+
* ```typescript
|
|
510
|
+
* const metadata = collectWorkerMetadata(EmailWorkers);
|
|
511
|
+
* // Returns:
|
|
512
|
+
* // [
|
|
513
|
+
* // { fullName: "email.send", method: "sendEmail", opts: {}, isCron: false },
|
|
514
|
+
* // { fullName: "email.daily-digest", method: "sendDailyDigest", opts: {}, isCron: true, cronPattern: "0 9 * * *" }
|
|
515
|
+
* // ]
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
declare function collectWorkerMetadata(target: new (...args: unknown[]) => unknown): CollectedWorkerMetadata[];
|
|
519
|
+
//#endregion
|
|
520
|
+
//#region src/utils/get-worker-token.d.ts
|
|
521
|
+
/**
|
|
522
|
+
* Generate a unique token for a worker controller.
|
|
523
|
+
*
|
|
524
|
+
* Used internally by Ts.ED DI to identify worker controller providers.
|
|
525
|
+
* The token is based on the class name for debugging purposes.
|
|
526
|
+
*
|
|
527
|
+
* @param target - The class constructor
|
|
528
|
+
* @returns A Symbol token unique to this worker controller
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* @WorkerController("email")
|
|
533
|
+
* class EmailWorkers {}
|
|
534
|
+
*
|
|
535
|
+
* const token = getWorkerToken(EmailWorkers);
|
|
536
|
+
* // Symbol("monque:worker:EmailWorkers")
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
declare function getWorkerToken(target: new (...args: unknown[]) => unknown): symbol;
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region src/utils/resolve-database.d.ts
|
|
542
|
+
/**
|
|
543
|
+
* Type for the injector function used to resolve DI tokens.
|
|
544
|
+
*/
|
|
545
|
+
type InjectorFn = <T>(token: TokenProvider<T>) => T | undefined;
|
|
546
|
+
/**
|
|
547
|
+
* Resolve the MongoDB database instance from the configuration.
|
|
548
|
+
*
|
|
549
|
+
* Supports three resolution strategies:
|
|
550
|
+
* 1. **Direct `db`**: Returns the provided Db instance directly
|
|
551
|
+
* 2. **Factory `dbFactory`**: Calls the factory function (supports async)
|
|
552
|
+
* 3. **DI Token `dbToken`**: Resolves the Db from the DI container
|
|
553
|
+
*
|
|
554
|
+
* @param config - The Monque configuration containing database settings
|
|
555
|
+
* @param injectorFn - Optional function to resolve DI tokens (required for dbToken strategy)
|
|
556
|
+
* @returns The resolved MongoDB Db instance
|
|
557
|
+
* @throws Error if no database strategy is provided or if DI resolution fails
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```typescript
|
|
561
|
+
* // Direct Db instance
|
|
562
|
+
* const db = await resolveDatabase({ db: mongoDb });
|
|
563
|
+
*
|
|
564
|
+
* // Factory function
|
|
565
|
+
* const db = await resolveDatabase({
|
|
566
|
+
* dbFactory: async () => {
|
|
567
|
+
* const client = await MongoClient.connect(uri);
|
|
568
|
+
* return client.db("myapp");
|
|
569
|
+
* }
|
|
570
|
+
* });
|
|
571
|
+
*
|
|
572
|
+
* // DI token
|
|
573
|
+
* const db = await resolveDatabase(
|
|
574
|
+
* { dbToken: "MONGODB_DATABASE" },
|
|
575
|
+
* (token) => injector.get(token)
|
|
576
|
+
* );
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
declare function resolveDatabase(config: MonqueTsedConfig, injectorFn?: InjectorFn): Promise<Db>;
|
|
580
|
+
//#endregion
|
|
581
|
+
export { type CollectedWorkerMetadata, Cron, type CronDecoratorOptions, type CronMetadata, type InjectorFn, MONQUE, MonqueModule, MonqueService, type MonqueTsedConfig, type ProviderType, ProviderTypes, Worker, WorkerController, type WorkerDecoratorOptions, type WorkerMetadata, type WorkerStore, buildJobName, collectWorkerMetadata, getWorkerToken, resolveDatabase, validateDatabaseConfig };
|
|
582
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/config/types.ts","../src/config/config.ts","../src/constants/constants.ts","../src/constants/types.ts","../src/decorators/types.ts","../src/decorators/cron.ts","../src/decorators/worker.ts","../src/decorators/worker-controller.ts","../src/services/monque-service.ts","../src/monque-module.ts","../src/utils/build-job-name.ts","../src/utils/collect-worker-metadata.ts","../src/utils/get-worker-token.ts","../src/utils/resolve-database.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;UA0BiB,gBAAA,SAAyB,IAAA,CAAK,aAAA;EAgDpB;;;;;;;;;;EArC1B,OAAA;EC/BkD;;;;;;;;;;;;AAuCnD;;;EDSC,EAAA,GAAK,EAAA;ECTyD;;;;AClC/D;;;;;;;;ACDA;;;;;AAUA;EHsDC,SAAA,SAAkB,OAAA,CAAQ,EAAA,IAAM,EAAA;;;;;;;AI1DjC;;;;;AA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