@igniter-js/jobs 0.1.13 → 0.1.15
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/AGENTS.md +119 -243
- package/README.md +352 -158
- package/dist/{adapter-CXZxomI9.d.mts → adapter-DDyMVche.d.mts} +125 -20
- package/dist/{adapter-CXZxomI9.d.ts → adapter-DDyMVche.d.ts} +125 -20
- package/dist/adapters/bun.d.mts +101 -0
- package/dist/adapters/bun.d.ts +101 -0
- package/dist/adapters/bun.js +1048 -0
- package/dist/adapters/bun.js.map +1 -0
- package/dist/adapters/bun.mjs +1046 -0
- package/dist/adapters/bun.mjs.map +1 -0
- package/dist/adapters/{memory.adapter.d.ts → mock.d.mts} +7 -3
- package/dist/adapters/{memory.adapter.d.mts → mock.d.ts} +7 -3
- package/dist/adapters/{memory.adapter.js → mock.js} +122 -25
- package/dist/adapters/mock.js.map +1 -0
- package/dist/adapters/{memory.adapter.mjs → mock.mjs} +122 -25
- package/dist/adapters/mock.mjs.map +1 -0
- package/dist/adapters/{bullmq.adapter.d.mts → node.d.mts} +8 -3
- package/dist/adapters/{bullmq.adapter.d.ts → node.d.ts} +8 -3
- package/dist/adapters/{bullmq.adapter.js → node.js} +194 -40
- package/dist/adapters/node.js.map +1 -0
- package/dist/adapters/{bullmq.adapter.mjs → node.mjs} +194 -40
- package/dist/adapters/node.mjs.map +1 -0
- package/dist/index.d.mts +41 -38
- package/dist/index.d.ts +41 -38
- package/dist/index.js +145 -1856
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +146 -1854
- package/dist/index.mjs.map +1 -1
- package/package.json +29 -41
- package/CHANGELOG.md +0 -13
- package/dist/adapters/bullmq.adapter.js.map +0 -1
- package/dist/adapters/bullmq.adapter.mjs.map +0 -1
- package/dist/adapters/index.d.mts +0 -143
- package/dist/adapters/index.d.ts +0 -143
- package/dist/adapters/index.js +0 -1891
- package/dist/adapters/index.js.map +0 -1
- package/dist/adapters/index.mjs +0 -1887
- package/dist/adapters/index.mjs.map +0 -1
- package/dist/adapters/memory.adapter.js.map +0 -1
- package/dist/adapters/memory.adapter.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { IgniterLogger, IgniterError } from '@igniter-js/common';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
export { IgniterJobsBullMQAdapter } from './adapters/bullmq.adapter.mjs';
|
|
5
|
-
export { IgniterJobsMemoryAdapter } from './adapters/memory.adapter.mjs';
|
|
6
|
-
export { IgniterJobsSQLiteAdapter, IgniterJobsSQLiteAdapterOptions } from './adapters/index.mjs';
|
|
2
|
+
import { I as IgniterJobsQueue, a as IgniterJobsAdapter, b as IgniterJobsScopeDefinition, c as IgniterJobDefinition, d as IgniterJobsWorkerBuilderConfig, e as IgniterJobsTelemetry, f as IgniterJobsEventHandler, g as IgniterJobSearchResult, h as IgniterJobsQueueInfo, i as IgniterJobsWorkerHandle, j as IgniterJobsLimiter, k as IgniterJobsWorkerHandlers, l as IgniterJobsQueueCleanOptions, m as IgniterJobStatus, n as IgniterJobsDispatchParams, o as IgniterJobsInferSchemaInput, p as IgniterJobsScheduleParams, q as IgniterJobsJobStreamAccessor, r as IgniterCronDefinition, s as IgniterJobsScopeEntry, t as IgniterJobsSchema, u as IgniterJobsJobStreamSchemaMap, v as IgniterJobsScopeOptions } from './adapter-DDyMVche.mjs';
|
|
3
|
+
export { w as IgniterJobCounts, x as IgniterJobsAdapterDispatchParams, y as IgniterJobsAdapterJobStreamReadParams, z as IgniterJobsAdapterJobStreamSubscribeParams, A as IgniterJobsAdapterJobStreamWriteParams, B as IgniterJobsAdapterScheduleParams, C as IgniterJobsBullMQAdapterOptions, D as IgniterJobsBunSQLiteAdapterOptions, E as IgniterJobsEvent, F as IgniterJobsExecutionContext, G as IgniterJobsExecutionStreamEmitter, H as IgniterJobsFailureHook, J as IgniterJobsHookContext, K as IgniterJobsInferJobStreamEvent, L as IgniterJobsInferSchemaOutput, M as IgniterJobsInferStreamEmitData, N as IgniterJobsInferStreamReadData, O as IgniterJobsInferStreamType, P as IgniterJobsInvokeOptions, Q as IgniterJobsJobLog, R as IgniterJobsJobStreamDefinition, S as IgniterJobsJobStreamEvent, T as IgniterJobsJobStreamPersistenceConfig, U as IgniterJobsJobStreamReadParams, V as IgniterJobsJobStreamReadResult, W as IgniterJobsProgressHook, X as IgniterJobsQueueManager, Y as IgniterJobsScheduleOptions, Z as IgniterJobsStartHook, _ as IgniterJobsStreamEventsFromDefinition, $ as IgniterJobsSuccessHook, a0 as IgniterJobsWorkerMetrics } from './adapter-DDyMVche.mjs';
|
|
7
4
|
import 'ioredis';
|
|
8
5
|
|
|
9
6
|
/**
|
|
@@ -16,12 +13,12 @@ interface IgniterJobsConfig<TContext = unknown, TQueues extends Record<string, I
|
|
|
16
13
|
contextFactory: () => TContext | Promise<TContext>;
|
|
17
14
|
queues: TQueues;
|
|
18
15
|
scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
|
|
19
|
-
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
|
|
16
|
+
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any, any>>;
|
|
20
17
|
workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
|
|
21
18
|
autoStartWorker?: {
|
|
22
19
|
queues: (keyof TQueues)[];
|
|
23
20
|
concurrency?: number;
|
|
24
|
-
limiter?: IgniterJobsWorkerBuilderConfig[
|
|
21
|
+
limiter?: IgniterJobsWorkerBuilderConfig["limiter"];
|
|
25
22
|
};
|
|
26
23
|
logger?: IgniterLogger;
|
|
27
24
|
telemetry?: IgniterJobsTelemetry;
|
|
@@ -36,12 +33,12 @@ interface IgniterJobsBuilderState<TContext, TQueues extends Record<string, Ignit
|
|
|
36
33
|
contextFactory?: () => TContext | Promise<TContext>;
|
|
37
34
|
queues: TQueues;
|
|
38
35
|
scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
|
|
39
|
-
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
|
|
36
|
+
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any, any>>;
|
|
40
37
|
workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
|
|
41
38
|
autoStartWorker?: {
|
|
42
39
|
queues: (keyof TQueues)[];
|
|
43
40
|
concurrency?: number;
|
|
44
|
-
limiter?: IgniterJobsWorkerBuilderConfig[
|
|
41
|
+
limiter?: IgniterJobsWorkerBuilderConfig["limiter"];
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
|
|
@@ -52,32 +49,32 @@ interface IgniterJobsBuilderState<TContext, TQueues extends Record<string, Ignit
|
|
|
52
49
|
|
|
53
50
|
type IgniterJobsInferInput<TInput> = IgniterJobsInferSchemaInput<TInput>;
|
|
54
51
|
type IgniterJobsInferJobInput<TDef> = TDef extends IgniterJobDefinition<any, infer TInput, any> ? IgniterJobsInferInput<TInput> : unknown;
|
|
52
|
+
type IgniterJobsInferJobResult<TDef> = TDef extends IgniterJobDefinition<any, any, infer TResult, any> ? TResult : unknown;
|
|
55
53
|
type IgniterJobsInferCronResult<TDef> = TDef extends IgniterCronDefinition<any, infer TResult> ? TResult : unknown;
|
|
56
|
-
interface IgniterJobsJobInstanceAccessor {
|
|
54
|
+
interface IgniterJobsJobInstanceAccessor<TDef extends IgniterJobDefinition<any, any, any, any> = IgniterJobDefinition<any, any, any, any>> {
|
|
57
55
|
retrieve(): Promise<IgniterJobSearchResult | null>;
|
|
58
56
|
retry(): Promise<void>;
|
|
59
57
|
remove(): Promise<void>;
|
|
60
58
|
promote(): Promise<void>;
|
|
61
|
-
move(state:
|
|
59
|
+
move(state: "failed", reason: string): Promise<void>;
|
|
62
60
|
state(): Promise<IgniterJobStatus | null>;
|
|
63
61
|
progress(): Promise<number>;
|
|
64
62
|
logs(): Promise<{
|
|
65
63
|
timestamp: Date;
|
|
66
64
|
message: string;
|
|
67
|
-
level:
|
|
65
|
+
level: "info" | "warn" | "error";
|
|
68
66
|
}[]>;
|
|
67
|
+
stream(): IgniterJobsJobStreamAccessor<TDef>;
|
|
69
68
|
}
|
|
70
69
|
interface IgniterJobsJobManyAccessor {
|
|
71
70
|
retry(): Promise<void>;
|
|
72
71
|
remove(): Promise<void>;
|
|
73
72
|
}
|
|
74
|
-
interface IgniterJobsJobAccessor<
|
|
75
|
-
dispatch(params: IgniterJobsDispatchParams<
|
|
76
|
-
schedule(params: IgniterJobsScheduleParams<
|
|
77
|
-
get(id: string): IgniterJobsJobInstanceAccessor
|
|
73
|
+
interface IgniterJobsJobAccessor<TDef extends IgniterJobDefinition<any, any, any, any> = IgniterJobDefinition<any, any, any, any>> {
|
|
74
|
+
dispatch(params: IgniterJobsDispatchParams<IgniterJobsInferJobInput<TDef>>): Promise<string>;
|
|
75
|
+
schedule(params: IgniterJobsScheduleParams<IgniterJobsInferJobInput<TDef>>): Promise<string>;
|
|
76
|
+
get(id: string): IgniterJobsJobInstanceAccessor<TDef>;
|
|
78
77
|
many(ids: string[]): IgniterJobsJobManyAccessor;
|
|
79
|
-
pause(): Promise<void>;
|
|
80
|
-
resume(): Promise<void>;
|
|
81
78
|
subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
82
79
|
}
|
|
83
80
|
interface IgniterJobsQueueManagerAccessor {
|
|
@@ -91,7 +88,7 @@ interface IgniterJobsQueueManagerAccessor {
|
|
|
91
88
|
}): Promise<void>;
|
|
92
89
|
retryAll(): Promise<number>;
|
|
93
90
|
}
|
|
94
|
-
type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<any, any, any>> = {}> = {
|
|
91
|
+
type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<any, any, any, any>> = {}> = {
|
|
95
92
|
get(): IgniterJobsQueueManagerAccessor;
|
|
96
93
|
list(filter?: {
|
|
97
94
|
status?: IgniterJobStatus[];
|
|
@@ -100,10 +97,10 @@ type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<
|
|
|
100
97
|
}): Promise<IgniterJobSearchResult[]>;
|
|
101
98
|
subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
102
99
|
readonly jobs: {
|
|
103
|
-
[K in keyof TJobs]: IgniterJobsJobAccessor<
|
|
100
|
+
[K in keyof TJobs]: IgniterJobsJobAccessor<TJobs[K]>;
|
|
104
101
|
};
|
|
105
102
|
} & {
|
|
106
|
-
[K in keyof TJobs]: IgniterJobsJobAccessor<
|
|
103
|
+
[K in keyof TJobs]: IgniterJobsJobAccessor<TJobs[K]>;
|
|
107
104
|
};
|
|
108
105
|
interface IgniterJobsWorkerBuilderAccessor<TQueueNames extends string> {
|
|
109
106
|
create(): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
@@ -112,25 +109,25 @@ interface IgniterJobsWorkerFluentBuilder<TQueueNames extends string> {
|
|
|
112
109
|
addQueue(queue: TQueueNames): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
113
110
|
withConcurrency(concurrency: number): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
114
111
|
withLimiter(limiter: IgniterJobsLimiter): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
115
|
-
onActive(handler: NonNullable<IgniterJobsWorkerHandlers[
|
|
116
|
-
onSuccess(handler: NonNullable<IgniterJobsWorkerHandlers[
|
|
117
|
-
onFailure(handler: NonNullable<IgniterJobsWorkerHandlers[
|
|
118
|
-
onIdle(handler: NonNullable<IgniterJobsWorkerHandlers[
|
|
112
|
+
onActive(handler: NonNullable<IgniterJobsWorkerHandlers["onActive"]>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
113
|
+
onSuccess(handler: NonNullable<IgniterJobsWorkerHandlers["onSuccess"]>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
114
|
+
onFailure(handler: NonNullable<IgniterJobsWorkerHandlers["onFailure"]>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
115
|
+
onIdle(handler: NonNullable<IgniterJobsWorkerHandlers["onIdle"]>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
119
116
|
start(): Promise<IgniterJobsWorkerHandle>;
|
|
120
117
|
}
|
|
121
118
|
interface IgniterJobsBaseRuntime<TConfig extends IgniterJobsConfig<any, any, any> = IgniterJobsConfig<any, any, any>> {
|
|
122
119
|
readonly config: TConfig;
|
|
123
120
|
subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
124
|
-
search(target:
|
|
125
|
-
search(target:
|
|
126
|
-
search(target:
|
|
121
|
+
search(target: "jobs", filter: Record<string, unknown>): Promise<IgniterJobSearchResult[]>;
|
|
122
|
+
search(target: "queues", filter: Record<string, unknown>): Promise<IgniterJobsQueueInfo[]>;
|
|
123
|
+
search(target: "workers", filter: Record<string, unknown>): Promise<IgniterJobsWorkerHandle[]>;
|
|
127
124
|
shutdown(): Promise<void>;
|
|
128
|
-
readonly worker: IgniterJobsWorkerBuilderAccessor<keyof TConfig[
|
|
129
|
-
scope: TConfig extends IgniterJobsConfig<any, any, infer TScope> ?
|
|
125
|
+
readonly worker: IgniterJobsWorkerBuilderAccessor<keyof TConfig["queues"] & string>;
|
|
126
|
+
scope: TConfig extends IgniterJobsConfig<any, any, infer TScope> ? TScope extends string ? (type: TScope, id: string | number, tags?: Record<string, unknown>) => IgniterJobsRuntime<TConfig> : never : never;
|
|
130
127
|
}
|
|
131
128
|
type IgniterJobsRuntime<TConfig extends IgniterJobsConfig<any, any, any> = IgniterJobsConfig<any, any, any>> = IgniterJobsBaseRuntime<TConfig> & {
|
|
132
|
-
[Q in keyof TConfig[
|
|
133
|
-
jobs: infer TJobs extends Record<string, IgniterJobDefinition<any, any, any>>;
|
|
129
|
+
[Q in keyof TConfig["queues"]]: TConfig["queues"][Q] extends {
|
|
130
|
+
jobs: infer TJobs extends Record<string, IgniterJobDefinition<any, any, any, any>>;
|
|
134
131
|
} ? IgniterJobsQueueAccessor<TJobs> : IgniterJobsQueueAccessor;
|
|
135
132
|
};
|
|
136
133
|
|
|
@@ -387,6 +384,12 @@ declare class IgniterJobsManager<TConfig extends IgniterJobsConfig<any, any, any
|
|
|
387
384
|
* @internal
|
|
388
385
|
*/
|
|
389
386
|
private getJobDefinition;
|
|
387
|
+
private getEffectiveJobDefinition;
|
|
388
|
+
private createExecutionStreamEmitter;
|
|
389
|
+
private createJobStreamAccessor;
|
|
390
|
+
private normalizeStreamEmitPayload;
|
|
391
|
+
private normalizeStreamReadEvent;
|
|
392
|
+
private getJobStreamSchema;
|
|
390
393
|
/**
|
|
391
394
|
* Resolves the effective scope for a job operation.
|
|
392
395
|
* @internal
|
|
@@ -439,7 +442,7 @@ declare class IgniterJobsManager<TConfig extends IgniterJobsConfig<any, any, any
|
|
|
439
442
|
* .build()
|
|
440
443
|
* ```
|
|
441
444
|
*/
|
|
442
|
-
declare class IgniterQueueBuilder<TContext, TJobs extends Record<string, IgniterJobDefinition<TContext, any, any>> = {}, TCron extends Record<string, IgniterCronDefinition<TContext, any>> = {}, TName extends string = string> {
|
|
445
|
+
declare class IgniterQueueBuilder<TContext, TJobs extends Record<string, IgniterJobDefinition<TContext, any, any, any>> = {}, TCron extends Record<string, IgniterCronDefinition<TContext, any>> = {}, TName extends string = string> {
|
|
443
446
|
private readonly state;
|
|
444
447
|
private constructor();
|
|
445
448
|
/**
|
|
@@ -453,7 +456,7 @@ declare class IgniterQueueBuilder<TContext, TJobs extends Record<string, Igniter
|
|
|
453
456
|
* @param jobName - Unique name of the job inside the queue.
|
|
454
457
|
* @param definition - Job definition (handler, schemas, options, hooks).
|
|
455
458
|
*/
|
|
456
|
-
addJob<TJobName extends string, TInput extends IgniterJobsSchema | unknown, TResult = unknown>(jobName: TJobName, definition: IgniterJobDefinition<TContext, TInput, TResult>): IgniterQueueBuilder<TContext, TJobs & Record<TJobName, IgniterJobDefinition<TContext, TInput, TResult>>, TCron, TName>;
|
|
459
|
+
addJob<TJobName extends string, TInput extends IgniterJobsSchema | unknown, TResult = unknown, TStreamEvents extends IgniterJobsJobStreamSchemaMap | undefined = undefined>(jobName: TJobName, definition: IgniterJobDefinition<TContext, TInput, TResult, TStreamEvents>): IgniterQueueBuilder<TContext, TJobs & Record<TJobName, IgniterJobDefinition<TContext, TInput, TResult, TStreamEvents>>, TCron, TName>;
|
|
457
460
|
/**
|
|
458
461
|
* Registers a cron task on the queue.
|
|
459
462
|
*
|
|
@@ -504,7 +507,7 @@ declare class IgniterQueue {
|
|
|
504
507
|
* @example
|
|
505
508
|
* ```typescript
|
|
506
509
|
* import { IgniterJobs, IgniterQueue } from '@igniter-js/jobs'
|
|
507
|
-
* import { IgniterJobsMemoryAdapter } from '@igniter-js/jobs/adapters'
|
|
510
|
+
* import { IgniterJobsMemoryAdapter } from '@igniter-js/jobs/adapters/mock'
|
|
508
511
|
* import { z } from 'zod'
|
|
509
512
|
*
|
|
510
513
|
* const emailQueue = IgniterQueue.create('email')
|
|
@@ -609,7 +612,7 @@ declare class IgniterJobsBuilder<TContext, TQueues extends Record<string, Ignite
|
|
|
609
612
|
/**
|
|
610
613
|
* Applies default job options to all queues.
|
|
611
614
|
*/
|
|
612
|
-
withQueueDefaults(defaults: Partial<IgniterJobDefinition<TContext, any, any>>): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
615
|
+
withQueueDefaults(defaults: Partial<IgniterJobDefinition<TContext, any, any, any>>): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
613
616
|
/**
|
|
614
617
|
* Applies default worker options.
|
|
615
618
|
*/
|
|
@@ -644,7 +647,7 @@ declare class IgniterJobsBuilder<TContext, TQueues extends Record<string, Ignite
|
|
|
644
647
|
* @example
|
|
645
648
|
* ```typescript
|
|
646
649
|
* import { IgniterJobs, IgniterQueue } from '@igniter-js/jobs'
|
|
647
|
-
* import { IgniterJobsMemoryAdapter } from '@igniter-js/jobs/adapters'
|
|
650
|
+
* import { IgniterJobsMemoryAdapter } from '@igniter-js/jobs/adapters/mock'
|
|
648
651
|
* import { z } from 'zod'
|
|
649
652
|
*
|
|
650
653
|
* const emailQueue = IgniterQueue.create('email')
|
|
@@ -741,4 +744,4 @@ declare class IgniterJobsError extends IgniterError {
|
|
|
741
744
|
constructor(options: IgniterJobsErrorOptions);
|
|
742
745
|
}
|
|
743
746
|
|
|
744
|
-
export { IGNITER_JOBS_ERROR_CODES, IgniterCronDefinition, IgniterJobDefinition, IgniterJobSearchResult, IgniterJobStatus, IgniterJobs, IgniterJobsAdapter, type IgniterJobsBaseRuntime, IgniterJobsBuilder, type IgniterJobsBuilderState, type IgniterJobsConfig, IgniterJobsDispatchParams, IgniterJobsError, type IgniterJobsErrorCode, type IgniterJobsErrorOptions, IgniterJobsEventHandler, type IgniterJobsInferCronResult, type IgniterJobsInferInput, type IgniterJobsInferJobInput, IgniterJobsInferSchemaInput, type IgniterJobsJobAccessor, type IgniterJobsJobInstanceAccessor, type IgniterJobsJobManyAccessor, IgniterJobsLimiter, IgniterJobsManager, IgniterJobsQueue, type IgniterJobsQueueAccessor, IgniterJobsQueueCleanOptions, IgniterJobsQueueInfo, type IgniterJobsQueueManagerAccessor, type IgniterJobsRuntime, IgniterJobsScheduleParams, IgniterJobsSchema, IgniterJobsScopeDefinition, IgniterJobsScopeEntry, IgniterJobsScopeOptions, IgniterJobsTelemetry, type IgniterJobsWorkerBuilderAccessor, IgniterJobsWorkerBuilderConfig, type IgniterJobsWorkerFluentBuilder, IgniterJobsWorkerHandle, IgniterJobsWorkerHandlers, IgniterQueue, IgniterQueueBuilder, IgniterWorkerBuilder };
|
|
747
|
+
export { IGNITER_JOBS_ERROR_CODES, IgniterCronDefinition, IgniterJobDefinition, IgniterJobSearchResult, IgniterJobStatus, IgniterJobs, IgniterJobsAdapter, type IgniterJobsBaseRuntime, IgniterJobsBuilder, type IgniterJobsBuilderState, type IgniterJobsConfig, IgniterJobsDispatchParams, IgniterJobsError, type IgniterJobsErrorCode, type IgniterJobsErrorOptions, IgniterJobsEventHandler, type IgniterJobsInferCronResult, type IgniterJobsInferInput, type IgniterJobsInferJobInput, type IgniterJobsInferJobResult, IgniterJobsInferSchemaInput, type IgniterJobsJobAccessor, type IgniterJobsJobInstanceAccessor, type IgniterJobsJobManyAccessor, IgniterJobsJobStreamAccessor, IgniterJobsJobStreamSchemaMap, IgniterJobsLimiter, IgniterJobsManager, IgniterJobsQueue, type IgniterJobsQueueAccessor, IgniterJobsQueueCleanOptions, IgniterJobsQueueInfo, type IgniterJobsQueueManagerAccessor, type IgniterJobsRuntime, IgniterJobsScheduleParams, IgniterJobsSchema, IgniterJobsScopeDefinition, IgniterJobsScopeEntry, IgniterJobsScopeOptions, IgniterJobsTelemetry, type IgniterJobsWorkerBuilderAccessor, IgniterJobsWorkerBuilderConfig, type IgniterJobsWorkerFluentBuilder, IgniterJobsWorkerHandle, IgniterJobsWorkerHandlers, IgniterQueue, IgniterQueueBuilder, IgniterWorkerBuilder };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { IgniterLogger, IgniterError } from '@igniter-js/common';
|
|
2
|
-
import {
|
|
3
|
-
export {
|
|
4
|
-
export { IgniterJobsBullMQAdapter } from './adapters/bullmq.adapter.js';
|
|
5
|
-
export { IgniterJobsMemoryAdapter } from './adapters/memory.adapter.js';
|
|
6
|
-
export { IgniterJobsSQLiteAdapter, IgniterJobsSQLiteAdapterOptions } from './adapters/index.js';
|
|
2
|
+
import { I as IgniterJobsQueue, a as IgniterJobsAdapter, b as IgniterJobsScopeDefinition, c as IgniterJobDefinition, d as IgniterJobsWorkerBuilderConfig, e as IgniterJobsTelemetry, f as IgniterJobsEventHandler, g as IgniterJobSearchResult, h as IgniterJobsQueueInfo, i as IgniterJobsWorkerHandle, j as IgniterJobsLimiter, k as IgniterJobsWorkerHandlers, l as IgniterJobsQueueCleanOptions, m as IgniterJobStatus, n as IgniterJobsDispatchParams, o as IgniterJobsInferSchemaInput, p as IgniterJobsScheduleParams, q as IgniterJobsJobStreamAccessor, r as IgniterCronDefinition, s as IgniterJobsScopeEntry, t as IgniterJobsSchema, u as IgniterJobsJobStreamSchemaMap, v as IgniterJobsScopeOptions } from './adapter-DDyMVche.js';
|
|
3
|
+
export { w as IgniterJobCounts, x as IgniterJobsAdapterDispatchParams, y as IgniterJobsAdapterJobStreamReadParams, z as IgniterJobsAdapterJobStreamSubscribeParams, A as IgniterJobsAdapterJobStreamWriteParams, B as IgniterJobsAdapterScheduleParams, C as IgniterJobsBullMQAdapterOptions, D as IgniterJobsBunSQLiteAdapterOptions, E as IgniterJobsEvent, F as IgniterJobsExecutionContext, G as IgniterJobsExecutionStreamEmitter, H as IgniterJobsFailureHook, J as IgniterJobsHookContext, K as IgniterJobsInferJobStreamEvent, L as IgniterJobsInferSchemaOutput, M as IgniterJobsInferStreamEmitData, N as IgniterJobsInferStreamReadData, O as IgniterJobsInferStreamType, P as IgniterJobsInvokeOptions, Q as IgniterJobsJobLog, R as IgniterJobsJobStreamDefinition, S as IgniterJobsJobStreamEvent, T as IgniterJobsJobStreamPersistenceConfig, U as IgniterJobsJobStreamReadParams, V as IgniterJobsJobStreamReadResult, W as IgniterJobsProgressHook, X as IgniterJobsQueueManager, Y as IgniterJobsScheduleOptions, Z as IgniterJobsStartHook, _ as IgniterJobsStreamEventsFromDefinition, $ as IgniterJobsSuccessHook, a0 as IgniterJobsWorkerMetrics } from './adapter-DDyMVche.js';
|
|
7
4
|
import 'ioredis';
|
|
8
5
|
|
|
9
6
|
/**
|
|
@@ -16,12 +13,12 @@ interface IgniterJobsConfig<TContext = unknown, TQueues extends Record<string, I
|
|
|
16
13
|
contextFactory: () => TContext | Promise<TContext>;
|
|
17
14
|
queues: TQueues;
|
|
18
15
|
scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
|
|
19
|
-
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
|
|
16
|
+
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any, any>>;
|
|
20
17
|
workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
|
|
21
18
|
autoStartWorker?: {
|
|
22
19
|
queues: (keyof TQueues)[];
|
|
23
20
|
concurrency?: number;
|
|
24
|
-
limiter?: IgniterJobsWorkerBuilderConfig[
|
|
21
|
+
limiter?: IgniterJobsWorkerBuilderConfig["limiter"];
|
|
25
22
|
};
|
|
26
23
|
logger?: IgniterLogger;
|
|
27
24
|
telemetry?: IgniterJobsTelemetry;
|
|
@@ -36,12 +33,12 @@ interface IgniterJobsBuilderState<TContext, TQueues extends Record<string, Ignit
|
|
|
36
33
|
contextFactory?: () => TContext | Promise<TContext>;
|
|
37
34
|
queues: TQueues;
|
|
38
35
|
scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
|
|
39
|
-
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
|
|
36
|
+
queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any, any>>;
|
|
40
37
|
workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
|
|
41
38
|
autoStartWorker?: {
|
|
42
39
|
queues: (keyof TQueues)[];
|
|
43
40
|
concurrency?: number;
|
|
44
|
-
limiter?: IgniterJobsWorkerBuilderConfig[
|
|
41
|
+
limiter?: IgniterJobsWorkerBuilderConfig["limiter"];
|
|
45
42
|
};
|
|
46
43
|
}
|
|
47
44
|
|
|
@@ -52,32 +49,32 @@ interface IgniterJobsBuilderState<TContext, TQueues extends Record<string, Ignit
|
|
|
52
49
|
|
|
53
50
|
type IgniterJobsInferInput<TInput> = IgniterJobsInferSchemaInput<TInput>;
|
|
54
51
|
type IgniterJobsInferJobInput<TDef> = TDef extends IgniterJobDefinition<any, infer TInput, any> ? IgniterJobsInferInput<TInput> : unknown;
|
|
52
|
+
type IgniterJobsInferJobResult<TDef> = TDef extends IgniterJobDefinition<any, any, infer TResult, any> ? TResult : unknown;
|
|
55
53
|
type IgniterJobsInferCronResult<TDef> = TDef extends IgniterCronDefinition<any, infer TResult> ? TResult : unknown;
|
|
56
|
-
interface IgniterJobsJobInstanceAccessor {
|
|
54
|
+
interface IgniterJobsJobInstanceAccessor<TDef extends IgniterJobDefinition<any, any, any, any> = IgniterJobDefinition<any, any, any, any>> {
|
|
57
55
|
retrieve(): Promise<IgniterJobSearchResult | null>;
|
|
58
56
|
retry(): Promise<void>;
|
|
59
57
|
remove(): Promise<void>;
|
|
60
58
|
promote(): Promise<void>;
|
|
61
|
-
move(state:
|
|
59
|
+
move(state: "failed", reason: string): Promise<void>;
|
|
62
60
|
state(): Promise<IgniterJobStatus | null>;
|
|
63
61
|
progress(): Promise<number>;
|
|
64
62
|
logs(): Promise<{
|
|
65
63
|
timestamp: Date;
|
|
66
64
|
message: string;
|
|
67
|
-
level:
|
|
65
|
+
level: "info" | "warn" | "error";
|
|
68
66
|
}[]>;
|
|
67
|
+
stream(): IgniterJobsJobStreamAccessor<TDef>;
|
|
69
68
|
}
|
|
70
69
|
interface IgniterJobsJobManyAccessor {
|
|
71
70
|
retry(): Promise<void>;
|
|
72
71
|
remove(): Promise<void>;
|
|
73
72
|
}
|
|
74
|
-
interface IgniterJobsJobAccessor<
|
|
75
|
-
dispatch(params: IgniterJobsDispatchParams<
|
|
76
|
-
schedule(params: IgniterJobsScheduleParams<
|
|
77
|
-
get(id: string): IgniterJobsJobInstanceAccessor
|
|
73
|
+
interface IgniterJobsJobAccessor<TDef extends IgniterJobDefinition<any, any, any, any> = IgniterJobDefinition<any, any, any, any>> {
|
|
74
|
+
dispatch(params: IgniterJobsDispatchParams<IgniterJobsInferJobInput<TDef>>): Promise<string>;
|
|
75
|
+
schedule(params: IgniterJobsScheduleParams<IgniterJobsInferJobInput<TDef>>): Promise<string>;
|
|
76
|
+
get(id: string): IgniterJobsJobInstanceAccessor<TDef>;
|
|
78
77
|
many(ids: string[]): IgniterJobsJobManyAccessor;
|
|
79
|
-
pause(): Promise<void>;
|
|
80
|
-
resume(): Promise<void>;
|
|
81
78
|
subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
82
79
|
}
|
|
83
80
|
interface IgniterJobsQueueManagerAccessor {
|
|
@@ -91,7 +88,7 @@ interface IgniterJobsQueueManagerAccessor {
|
|
|
91
88
|
}): Promise<void>;
|
|
92
89
|
retryAll(): Promise<number>;
|
|
93
90
|
}
|
|
94
|
-
type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<any, any, any>> = {}> = {
|
|
91
|
+
type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<any, any, any, any>> = {}> = {
|
|
95
92
|
get(): IgniterJobsQueueManagerAccessor;
|
|
96
93
|
list(filter?: {
|
|
97
94
|
status?: IgniterJobStatus[];
|
|
@@ -100,10 +97,10 @@ type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<
|
|
|
100
97
|
}): Promise<IgniterJobSearchResult[]>;
|
|
101
98
|
subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
102
99
|
readonly jobs: {
|
|
103
|
-
[K in keyof TJobs]: IgniterJobsJobAccessor<
|
|
100
|
+
[K in keyof TJobs]: IgniterJobsJobAccessor<TJobs[K]>;
|
|
104
101
|
};
|
|
105
102
|
} & {
|
|
106
|
-
[K in keyof TJobs]: IgniterJobsJobAccessor<
|
|
103
|
+
[K in keyof TJobs]: IgniterJobsJobAccessor<TJobs[K]>;
|
|
107
104
|
};
|
|
108
105
|
interface IgniterJobsWorkerBuilderAccessor<TQueueNames extends string> {
|
|
109
106
|
create(): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
@@ -112,25 +109,25 @@ interface IgniterJobsWorkerFluentBuilder<TQueueNames extends string> {
|
|
|
112
109
|
addQueue(queue: TQueueNames): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
113
110
|
withConcurrency(concurrency: number): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
114
111
|
withLimiter(limiter: IgniterJobsLimiter): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
115
|
-
onActive(handler: NonNullable<IgniterJobsWorkerHandlers[
|
|
116
|
-
onSuccess(handler: NonNullable<IgniterJobsWorkerHandlers[
|
|
117
|
-
onFailure(handler: NonNullable<IgniterJobsWorkerHandlers[
|
|
118
|
-
onIdle(handler: NonNullable<IgniterJobsWorkerHandlers[
|
|
112
|
+
onActive(handler: NonNullable<IgniterJobsWorkerHandlers["onActive"]>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
113
|
+
onSuccess(handler: NonNullable<IgniterJobsWorkerHandlers["onSuccess"]>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
114
|
+
onFailure(handler: NonNullable<IgniterJobsWorkerHandlers["onFailure"]>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
115
|
+
onIdle(handler: NonNullable<IgniterJobsWorkerHandlers["onIdle"]>): IgniterJobsWorkerFluentBuilder<TQueueNames>;
|
|
119
116
|
start(): Promise<IgniterJobsWorkerHandle>;
|
|
120
117
|
}
|
|
121
118
|
interface IgniterJobsBaseRuntime<TConfig extends IgniterJobsConfig<any, any, any> = IgniterJobsConfig<any, any, any>> {
|
|
122
119
|
readonly config: TConfig;
|
|
123
120
|
subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
|
|
124
|
-
search(target:
|
|
125
|
-
search(target:
|
|
126
|
-
search(target:
|
|
121
|
+
search(target: "jobs", filter: Record<string, unknown>): Promise<IgniterJobSearchResult[]>;
|
|
122
|
+
search(target: "queues", filter: Record<string, unknown>): Promise<IgniterJobsQueueInfo[]>;
|
|
123
|
+
search(target: "workers", filter: Record<string, unknown>): Promise<IgniterJobsWorkerHandle[]>;
|
|
127
124
|
shutdown(): Promise<void>;
|
|
128
|
-
readonly worker: IgniterJobsWorkerBuilderAccessor<keyof TConfig[
|
|
129
|
-
scope: TConfig extends IgniterJobsConfig<any, any, infer TScope> ?
|
|
125
|
+
readonly worker: IgniterJobsWorkerBuilderAccessor<keyof TConfig["queues"] & string>;
|
|
126
|
+
scope: TConfig extends IgniterJobsConfig<any, any, infer TScope> ? TScope extends string ? (type: TScope, id: string | number, tags?: Record<string, unknown>) => IgniterJobsRuntime<TConfig> : never : never;
|
|
130
127
|
}
|
|
131
128
|
type IgniterJobsRuntime<TConfig extends IgniterJobsConfig<any, any, any> = IgniterJobsConfig<any, any, any>> = IgniterJobsBaseRuntime<TConfig> & {
|
|
132
|
-
[Q in keyof TConfig[
|
|
133
|
-
jobs: infer TJobs extends Record<string, IgniterJobDefinition<any, any, any>>;
|
|
129
|
+
[Q in keyof TConfig["queues"]]: TConfig["queues"][Q] extends {
|
|
130
|
+
jobs: infer TJobs extends Record<string, IgniterJobDefinition<any, any, any, any>>;
|
|
134
131
|
} ? IgniterJobsQueueAccessor<TJobs> : IgniterJobsQueueAccessor;
|
|
135
132
|
};
|
|
136
133
|
|
|
@@ -387,6 +384,12 @@ declare class IgniterJobsManager<TConfig extends IgniterJobsConfig<any, any, any
|
|
|
387
384
|
* @internal
|
|
388
385
|
*/
|
|
389
386
|
private getJobDefinition;
|
|
387
|
+
private getEffectiveJobDefinition;
|
|
388
|
+
private createExecutionStreamEmitter;
|
|
389
|
+
private createJobStreamAccessor;
|
|
390
|
+
private normalizeStreamEmitPayload;
|
|
391
|
+
private normalizeStreamReadEvent;
|
|
392
|
+
private getJobStreamSchema;
|
|
390
393
|
/**
|
|
391
394
|
* Resolves the effective scope for a job operation.
|
|
392
395
|
* @internal
|
|
@@ -439,7 +442,7 @@ declare class IgniterJobsManager<TConfig extends IgniterJobsConfig<any, any, any
|
|
|
439
442
|
* .build()
|
|
440
443
|
* ```
|
|
441
444
|
*/
|
|
442
|
-
declare class IgniterQueueBuilder<TContext, TJobs extends Record<string, IgniterJobDefinition<TContext, any, any>> = {}, TCron extends Record<string, IgniterCronDefinition<TContext, any>> = {}, TName extends string = string> {
|
|
445
|
+
declare class IgniterQueueBuilder<TContext, TJobs extends Record<string, IgniterJobDefinition<TContext, any, any, any>> = {}, TCron extends Record<string, IgniterCronDefinition<TContext, any>> = {}, TName extends string = string> {
|
|
443
446
|
private readonly state;
|
|
444
447
|
private constructor();
|
|
445
448
|
/**
|
|
@@ -453,7 +456,7 @@ declare class IgniterQueueBuilder<TContext, TJobs extends Record<string, Igniter
|
|
|
453
456
|
* @param jobName - Unique name of the job inside the queue.
|
|
454
457
|
* @param definition - Job definition (handler, schemas, options, hooks).
|
|
455
458
|
*/
|
|
456
|
-
addJob<TJobName extends string, TInput extends IgniterJobsSchema | unknown, TResult = unknown>(jobName: TJobName, definition: IgniterJobDefinition<TContext, TInput, TResult>): IgniterQueueBuilder<TContext, TJobs & Record<TJobName, IgniterJobDefinition<TContext, TInput, TResult>>, TCron, TName>;
|
|
459
|
+
addJob<TJobName extends string, TInput extends IgniterJobsSchema | unknown, TResult = unknown, TStreamEvents extends IgniterJobsJobStreamSchemaMap | undefined = undefined>(jobName: TJobName, definition: IgniterJobDefinition<TContext, TInput, TResult, TStreamEvents>): IgniterQueueBuilder<TContext, TJobs & Record<TJobName, IgniterJobDefinition<TContext, TInput, TResult, TStreamEvents>>, TCron, TName>;
|
|
457
460
|
/**
|
|
458
461
|
* Registers a cron task on the queue.
|
|
459
462
|
*
|
|
@@ -504,7 +507,7 @@ declare class IgniterQueue {
|
|
|
504
507
|
* @example
|
|
505
508
|
* ```typescript
|
|
506
509
|
* import { IgniterJobs, IgniterQueue } from '@igniter-js/jobs'
|
|
507
|
-
* import { IgniterJobsMemoryAdapter } from '@igniter-js/jobs/adapters'
|
|
510
|
+
* import { IgniterJobsMemoryAdapter } from '@igniter-js/jobs/adapters/mock'
|
|
508
511
|
* import { z } from 'zod'
|
|
509
512
|
*
|
|
510
513
|
* const emailQueue = IgniterQueue.create('email')
|
|
@@ -609,7 +612,7 @@ declare class IgniterJobsBuilder<TContext, TQueues extends Record<string, Ignite
|
|
|
609
612
|
/**
|
|
610
613
|
* Applies default job options to all queues.
|
|
611
614
|
*/
|
|
612
|
-
withQueueDefaults(defaults: Partial<IgniterJobDefinition<TContext, any, any>>): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
615
|
+
withQueueDefaults(defaults: Partial<IgniterJobDefinition<TContext, any, any, any>>): IgniterJobsBuilder<TContext, TQueues, TScope>;
|
|
613
616
|
/**
|
|
614
617
|
* Applies default worker options.
|
|
615
618
|
*/
|
|
@@ -644,7 +647,7 @@ declare class IgniterJobsBuilder<TContext, TQueues extends Record<string, Ignite
|
|
|
644
647
|
* @example
|
|
645
648
|
* ```typescript
|
|
646
649
|
* import { IgniterJobs, IgniterQueue } from '@igniter-js/jobs'
|
|
647
|
-
* import { IgniterJobsMemoryAdapter } from '@igniter-js/jobs/adapters'
|
|
650
|
+
* import { IgniterJobsMemoryAdapter } from '@igniter-js/jobs/adapters/mock'
|
|
648
651
|
* import { z } from 'zod'
|
|
649
652
|
*
|
|
650
653
|
* const emailQueue = IgniterQueue.create('email')
|
|
@@ -741,4 +744,4 @@ declare class IgniterJobsError extends IgniterError {
|
|
|
741
744
|
constructor(options: IgniterJobsErrorOptions);
|
|
742
745
|
}
|
|
743
746
|
|
|
744
|
-
export { IGNITER_JOBS_ERROR_CODES, IgniterCronDefinition, IgniterJobDefinition, IgniterJobSearchResult, IgniterJobStatus, IgniterJobs, IgniterJobsAdapter, type IgniterJobsBaseRuntime, IgniterJobsBuilder, type IgniterJobsBuilderState, type IgniterJobsConfig, IgniterJobsDispatchParams, IgniterJobsError, type IgniterJobsErrorCode, type IgniterJobsErrorOptions, IgniterJobsEventHandler, type IgniterJobsInferCronResult, type IgniterJobsInferInput, type IgniterJobsInferJobInput, IgniterJobsInferSchemaInput, type IgniterJobsJobAccessor, type IgniterJobsJobInstanceAccessor, type IgniterJobsJobManyAccessor, IgniterJobsLimiter, IgniterJobsManager, IgniterJobsQueue, type IgniterJobsQueueAccessor, IgniterJobsQueueCleanOptions, IgniterJobsQueueInfo, type IgniterJobsQueueManagerAccessor, type IgniterJobsRuntime, IgniterJobsScheduleParams, IgniterJobsSchema, IgniterJobsScopeDefinition, IgniterJobsScopeEntry, IgniterJobsScopeOptions, IgniterJobsTelemetry, type IgniterJobsWorkerBuilderAccessor, IgniterJobsWorkerBuilderConfig, type IgniterJobsWorkerFluentBuilder, IgniterJobsWorkerHandle, IgniterJobsWorkerHandlers, IgniterQueue, IgniterQueueBuilder, IgniterWorkerBuilder };
|
|
747
|
+
export { IGNITER_JOBS_ERROR_CODES, IgniterCronDefinition, IgniterJobDefinition, IgniterJobSearchResult, IgniterJobStatus, IgniterJobs, IgniterJobsAdapter, type IgniterJobsBaseRuntime, IgniterJobsBuilder, type IgniterJobsBuilderState, type IgniterJobsConfig, IgniterJobsDispatchParams, IgniterJobsError, type IgniterJobsErrorCode, type IgniterJobsErrorOptions, IgniterJobsEventHandler, type IgniterJobsInferCronResult, type IgniterJobsInferInput, type IgniterJobsInferJobInput, type IgniterJobsInferJobResult, IgniterJobsInferSchemaInput, type IgniterJobsJobAccessor, type IgniterJobsJobInstanceAccessor, type IgniterJobsJobManyAccessor, IgniterJobsJobStreamAccessor, IgniterJobsJobStreamSchemaMap, IgniterJobsLimiter, IgniterJobsManager, IgniterJobsQueue, type IgniterJobsQueueAccessor, IgniterJobsQueueCleanOptions, IgniterJobsQueueInfo, type IgniterJobsQueueManagerAccessor, type IgniterJobsRuntime, IgniterJobsScheduleParams, IgniterJobsSchema, IgniterJobsScopeDefinition, IgniterJobsScopeEntry, IgniterJobsScopeOptions, IgniterJobsTelemetry, type IgniterJobsWorkerBuilderAccessor, IgniterJobsWorkerBuilderConfig, type IgniterJobsWorkerFluentBuilder, IgniterJobsWorkerHandle, IgniterJobsWorkerHandlers, IgniterQueue, IgniterQueueBuilder, IgniterWorkerBuilder };
|