@veloxts/queue 0.6.56 → 0.6.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,34 +1,8 @@
1
1
  # @veloxts/queue
2
2
 
3
- > **Early Preview** - APIs may change before v1.0.
3
+ > **Early Preview (v0.6.x)** - APIs are stabilizing but may still change. Use with caution in production.
4
4
 
5
- Background job processing with type-safe job definitions and multiple drivers.
6
-
7
- ## Installation
8
-
9
- ```bash
10
- npm install @veloxts/queue
11
- ```
12
-
13
- ## Quick Start
14
-
15
- ```typescript
16
- import { queuePlugin, defineJob } from '@veloxts/queue';
17
-
18
- app.use(queuePlugin({ driver: 'sync' }));
19
-
20
- const sendEmail = defineJob({
21
- name: 'email.send',
22
- handler: async ({ data }) => {
23
- await mailer.send(data.to, data.subject, data.body);
24
- },
25
- });
26
-
27
- // Dispatch a job
28
- await ctx.queue.dispatch(sendEmail, { to: 'user@example.com', subject: 'Hello' });
29
- ```
30
-
31
- See [GUIDE.md](./GUIDE.md) for detailed documentation.
5
+ Background job processing for VeloxTS Framework - provides sync and BullMQ drivers with type-safe job definitions and reliable execution. Learn more at [@veloxts/velox](https://www.npmjs.com/package/@veloxts/velox).
32
6
 
33
7
  ## License
34
8
 
package/dist/index.d.ts CHANGED
@@ -53,3 +53,30 @@ export { createQueueManager, createWorkerManager, type QueueManager, queue, type
53
53
  export { closeQueue, getQueue, getQueueFromInstance, initQueue, queuePlugin, } from './plugin.js';
54
54
  export type { BackoffOptions, BullMQConfig, Delay, DispatchOptions, DurationString, FailedJob, JobContext, JobDefinition, JobDefinitionConfig, JobHandler, JobOptions, QueueConfig, QueueDriver, QueuePluginOptions, QueueStats, QueueStore, SyncConfig, WorkerStore, } from './types.js';
55
55
  export { formatDuration, isDurationString, parseDelay, validateJobName } from './utils.js';
56
+ /**
57
+ * DI tokens and providers for @veloxts/queue
58
+ *
59
+ * Use these to integrate queue services with the @veloxts/core DI container.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * import { Container } from '@veloxts/core';
64
+ * import { registerQueueProviders, QUEUE_MANAGER, WORKER_MANAGER } from '@veloxts/queue';
65
+ *
66
+ * const container = new Container();
67
+ * await registerQueueProviders(container, {
68
+ * driver: 'sync',
69
+ * includeWorker: true,
70
+ * });
71
+ *
72
+ * const queue = container.resolve(QUEUE_MANAGER);
73
+ * await queue.dispatch(myJob, { data: 'value' });
74
+ *
75
+ * const worker = container.resolve(WORKER_MANAGER);
76
+ * worker.register(myJob);
77
+ * await worker.start();
78
+ * ```
79
+ */
80
+ export type { RegisterQueueProvidersOptions } from './providers.js';
81
+ export { registerQueueProviders } from './providers.js';
82
+ export { QUEUE_CONFIG, QUEUE_MANAGER, QUEUE_STORE, WORKER_MANAGER, WORKER_STORE, } from './tokens.js';
package/dist/index.js CHANGED
@@ -57,3 +57,6 @@ export { createQueueManager, createWorkerManager, queue, } from './manager.js';
57
57
  export { closeQueue, getQueue, getQueueFromInstance, initQueue, queuePlugin, } from './plugin.js';
58
58
  // Utilities
59
59
  export { formatDuration, isDurationString, parseDelay, validateJobName } from './utils.js';
60
+ export { registerQueueProviders } from './providers.js';
61
+ // Token exports - unique identifiers for DI resolution
62
+ export { QUEUE_CONFIG, QUEUE_MANAGER, QUEUE_STORE, WORKER_MANAGER, WORKER_STORE, } from './tokens.js';
@@ -0,0 +1,69 @@
1
+ /**
2
+ * DI Providers for @veloxts/queue
3
+ *
4
+ * Factory provider functions for registering queue services with the DI container.
5
+ * These providers allow services to be managed by the container for testability and flexibility.
6
+ *
7
+ * @module queue/providers
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { registerQueueProviders, QUEUE_MANAGER } from '@veloxts/queue';
13
+ *
14
+ * const container = new Container();
15
+ * await registerQueueProviders(container, { driver: 'sync' });
16
+ *
17
+ * const queue = container.resolve(QUEUE_MANAGER);
18
+ * await queue.dispatch(myJob, { data: 'value' });
19
+ * ```
20
+ */
21
+ import type { Container } from '@veloxts/core';
22
+ import type { QueuePluginOptions } from './types.js';
23
+ /**
24
+ * Options for registering queue providers
25
+ */
26
+ export type RegisterQueueProvidersOptions = QueuePluginOptions & {
27
+ /**
28
+ * Whether to also register a worker manager.
29
+ * @default false
30
+ */
31
+ includeWorker?: boolean;
32
+ };
33
+ /**
34
+ * Registers queue providers with a container
35
+ *
36
+ * This handles async initialization of the queue manager and optionally
37
+ * the worker manager, registering the resolved instances directly for
38
+ * synchronous resolution.
39
+ *
40
+ * @param container - The DI container to register providers with
41
+ * @param config - Queue plugin options (driver, prefix, etc.)
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * import { Container } from '@veloxts/core';
46
+ * import { registerQueueProviders, QUEUE_MANAGER, WORKER_MANAGER } from '@veloxts/queue';
47
+ *
48
+ * const container = new Container();
49
+ *
50
+ * // Sync driver (development/testing)
51
+ * await registerQueueProviders(container, { driver: 'sync' });
52
+ *
53
+ * // BullMQ driver (production) with worker
54
+ * await registerQueueProviders(container, {
55
+ * driver: 'bullmq',
56
+ * config: { url: process.env.REDIS_URL },
57
+ * includeWorker: true,
58
+ * });
59
+ *
60
+ * const queue = container.resolve(QUEUE_MANAGER);
61
+ * await queue.dispatch(myJob, { userId: '123' });
62
+ *
63
+ * // If includeWorker was true:
64
+ * const worker = container.resolve(WORKER_MANAGER);
65
+ * worker.register(myJob);
66
+ * await worker.start();
67
+ * ```
68
+ */
69
+ export declare function registerQueueProviders(container: Container, config?: RegisterQueueProvidersOptions): Promise<void>;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * DI Providers for @veloxts/queue
3
+ *
4
+ * Factory provider functions for registering queue services with the DI container.
5
+ * These providers allow services to be managed by the container for testability and flexibility.
6
+ *
7
+ * @module queue/providers
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { registerQueueProviders, QUEUE_MANAGER } from '@veloxts/queue';
13
+ *
14
+ * const container = new Container();
15
+ * await registerQueueProviders(container, { driver: 'sync' });
16
+ *
17
+ * const queue = container.resolve(QUEUE_MANAGER);
18
+ * await queue.dispatch(myJob, { data: 'value' });
19
+ * ```
20
+ */
21
+ import { createQueueManager, createWorkerManager } from './manager.js';
22
+ import { QUEUE_CONFIG, QUEUE_MANAGER, WORKER_MANAGER } from './tokens.js';
23
+ /**
24
+ * Registers queue providers with a container
25
+ *
26
+ * This handles async initialization of the queue manager and optionally
27
+ * the worker manager, registering the resolved instances directly for
28
+ * synchronous resolution.
29
+ *
30
+ * @param container - The DI container to register providers with
31
+ * @param config - Queue plugin options (driver, prefix, etc.)
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { Container } from '@veloxts/core';
36
+ * import { registerQueueProviders, QUEUE_MANAGER, WORKER_MANAGER } from '@veloxts/queue';
37
+ *
38
+ * const container = new Container();
39
+ *
40
+ * // Sync driver (development/testing)
41
+ * await registerQueueProviders(container, { driver: 'sync' });
42
+ *
43
+ * // BullMQ driver (production) with worker
44
+ * await registerQueueProviders(container, {
45
+ * driver: 'bullmq',
46
+ * config: { url: process.env.REDIS_URL },
47
+ * includeWorker: true,
48
+ * });
49
+ *
50
+ * const queue = container.resolve(QUEUE_MANAGER);
51
+ * await queue.dispatch(myJob, { userId: '123' });
52
+ *
53
+ * // If includeWorker was true:
54
+ * const worker = container.resolve(WORKER_MANAGER);
55
+ * worker.register(myJob);
56
+ * await worker.start();
57
+ * ```
58
+ */
59
+ export async function registerQueueProviders(container, config = {}) {
60
+ const { includeWorker, ...queueConfig } = config;
61
+ // Register config
62
+ container.register({
63
+ provide: QUEUE_CONFIG,
64
+ useValue: queueConfig,
65
+ });
66
+ // Create queue manager (async operation)
67
+ const queueManager = await createQueueManager(queueConfig);
68
+ // Register the resolved queue manager instance directly
69
+ // This allows synchronous resolution from the container
70
+ container.register({
71
+ provide: QUEUE_MANAGER,
72
+ useValue: queueManager,
73
+ });
74
+ // Optionally create and register worker manager
75
+ if (includeWorker) {
76
+ const workerManager = await createWorkerManager(queueConfig);
77
+ container.register({
78
+ provide: WORKER_MANAGER,
79
+ useValue: workerManager,
80
+ });
81
+ }
82
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * DI Tokens for @veloxts/queue
3
+ *
4
+ * Symbol-based tokens for type-safe dependency injection.
5
+ * These tokens allow queue services to be registered, resolved, and mocked via the DI container.
6
+ *
7
+ * @module queue/tokens
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { QUEUE_MANAGER, registerQueueProviders } from '@veloxts/queue';
13
+ *
14
+ * const container = new Container();
15
+ * await registerQueueProviders(container, { driver: 'sync' });
16
+ *
17
+ * const queue = container.resolve(QUEUE_MANAGER);
18
+ * await queue.dispatch(myJob, { data: 'value' });
19
+ * ```
20
+ */
21
+ import type { QueueManager, WorkerManager } from './manager.js';
22
+ import type { QueuePluginOptions, QueueStore, WorkerStore } from './types.js';
23
+ /**
24
+ * Queue manager token
25
+ *
26
+ * The main queue manager instance for dispatching and managing jobs.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const queue = container.resolve(QUEUE_MANAGER);
31
+ * await queue.dispatch(sendWelcomeEmail, { userId: '123' });
32
+ * await queue.getStats();
33
+ * ```
34
+ */
35
+ export declare const QUEUE_MANAGER: import("@veloxts/core").SymbolToken<QueueManager>;
36
+ /**
37
+ * Worker manager token
38
+ *
39
+ * The worker manager for processing jobs.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const worker = container.resolve(WORKER_MANAGER);
44
+ * worker.register(sendWelcomeEmail);
45
+ * await worker.start();
46
+ * ```
47
+ */
48
+ export declare const WORKER_MANAGER: import("@veloxts/core").SymbolToken<WorkerManager>;
49
+ /**
50
+ * Queue store token
51
+ *
52
+ * The underlying queue store driver (BullMQ or Sync).
53
+ * Use QUEUE_MANAGER for high-level operations; use this for direct store access.
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const store = container.resolve(QUEUE_STORE);
58
+ * await store.add('job-name', data, { queue: 'default' });
59
+ * ```
60
+ */
61
+ export declare const QUEUE_STORE: import("@veloxts/core").SymbolToken<QueueStore>;
62
+ /**
63
+ * Worker store token
64
+ *
65
+ * The underlying worker store driver for job processing.
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const store = container.resolve(WORKER_STORE);
70
+ * store.registerHandler('job-name', handler, { queue: 'default' });
71
+ * ```
72
+ */
73
+ export declare const WORKER_STORE: import("@veloxts/core").SymbolToken<WorkerStore>;
74
+ /**
75
+ * Queue configuration token
76
+ *
77
+ * Contains queue plugin options including driver and driver-specific config.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const config = container.resolve(QUEUE_CONFIG);
82
+ * console.log(config.driver); // 'bullmq' or 'sync'
83
+ * ```
84
+ */
85
+ export declare const QUEUE_CONFIG: import("@veloxts/core").SymbolToken<QueuePluginOptions>;
package/dist/tokens.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * DI Tokens for @veloxts/queue
3
+ *
4
+ * Symbol-based tokens for type-safe dependency injection.
5
+ * These tokens allow queue services to be registered, resolved, and mocked via the DI container.
6
+ *
7
+ * @module queue/tokens
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Container } from '@veloxts/core';
12
+ * import { QUEUE_MANAGER, registerQueueProviders } from '@veloxts/queue';
13
+ *
14
+ * const container = new Container();
15
+ * await registerQueueProviders(container, { driver: 'sync' });
16
+ *
17
+ * const queue = container.resolve(QUEUE_MANAGER);
18
+ * await queue.dispatch(myJob, { data: 'value' });
19
+ * ```
20
+ */
21
+ import { token } from '@veloxts/core';
22
+ // ============================================================================
23
+ // Core Queue Tokens
24
+ // ============================================================================
25
+ /**
26
+ * Queue manager token
27
+ *
28
+ * The main queue manager instance for dispatching and managing jobs.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const queue = container.resolve(QUEUE_MANAGER);
33
+ * await queue.dispatch(sendWelcomeEmail, { userId: '123' });
34
+ * await queue.getStats();
35
+ * ```
36
+ */
37
+ export const QUEUE_MANAGER = token.symbol('QUEUE_MANAGER');
38
+ /**
39
+ * Worker manager token
40
+ *
41
+ * The worker manager for processing jobs.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const worker = container.resolve(WORKER_MANAGER);
46
+ * worker.register(sendWelcomeEmail);
47
+ * await worker.start();
48
+ * ```
49
+ */
50
+ export const WORKER_MANAGER = token.symbol('WORKER_MANAGER');
51
+ /**
52
+ * Queue store token
53
+ *
54
+ * The underlying queue store driver (BullMQ or Sync).
55
+ * Use QUEUE_MANAGER for high-level operations; use this for direct store access.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const store = container.resolve(QUEUE_STORE);
60
+ * await store.add('job-name', data, { queue: 'default' });
61
+ * ```
62
+ */
63
+ export const QUEUE_STORE = token.symbol('QUEUE_STORE');
64
+ /**
65
+ * Worker store token
66
+ *
67
+ * The underlying worker store driver for job processing.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const store = container.resolve(WORKER_STORE);
72
+ * store.registerHandler('job-name', handler, { queue: 'default' });
73
+ * ```
74
+ */
75
+ export const WORKER_STORE = token.symbol('WORKER_STORE');
76
+ // ============================================================================
77
+ // Configuration Tokens
78
+ // ============================================================================
79
+ /**
80
+ * Queue configuration token
81
+ *
82
+ * Contains queue plugin options including driver and driver-specific config.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const config = container.resolve(QUEUE_CONFIG);
87
+ * console.log(config.driver); // 'bullmq' or 'sync'
88
+ * ```
89
+ */
90
+ export const QUEUE_CONFIG = token.symbol('QUEUE_CONFIG');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@veloxts/queue",
3
- "version": "0.6.56",
3
+ "version": "0.6.58",
4
4
  "description": "Background job processing for VeloxTS framework",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "ioredis": "5.6.1",
24
24
  "superjson": "2.2.2",
25
25
  "zod": "3.24.4",
26
- "@veloxts/core": "0.6.56"
26
+ "@veloxts/core": "0.6.58"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@biomejs/biome": "2.0.0",
@@ -32,7 +32,7 @@
32
32
  "fastify": "5.6.2",
33
33
  "typescript": "5.8.3",
34
34
  "vitest": "4.0.16",
35
- "@veloxts/testing": "0.6.56"
35
+ "@veloxts/testing": "0.6.58"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "fastify": "^5.0.0"