@igniter-js/jobs 0.1.14 → 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/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { IgniterLogger, IgniterError } from '@igniter-js/common';
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 IgniterJobsScheduleParams, p as IgniterJobsInferSchemaInput, q as IgniterCronDefinition, r as IgniterJobsScopeEntry, s as IgniterJobsSchema, t as IgniterJobsScopeOptions } from './adapter-Cax_40HW.mjs';
3
- export { u as IgniterJobCounts, v as IgniterJobsAdapterDispatchParams, w as IgniterJobsAdapterScheduleParams, x as IgniterJobsBullMQAdapterOptions, y as IgniterJobsBunSQLiteAdapterOptions, z as IgniterJobsEvent, A as IgniterJobsExecutionContext, B as IgniterJobsFailureHook, C as IgniterJobsHookContext, D as IgniterJobsInferSchemaOutput, E as IgniterJobsInvokeOptions, F as IgniterJobsJobLog, G as IgniterJobsProgressHook, H as IgniterJobsQueueManager, J as IgniterJobsScheduleOptions, K as IgniterJobsStartHook, L as IgniterJobsSuccessHook, M as IgniterJobsWorkerMetrics } from './adapter-Cax_40HW.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';
4
4
  import 'ioredis';
5
5
 
6
6
  /**
@@ -13,12 +13,12 @@ interface IgniterJobsConfig<TContext = unknown, TQueues extends Record<string, I
13
13
  contextFactory: () => TContext | Promise<TContext>;
14
14
  queues: TQueues;
15
15
  scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
16
- queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
16
+ queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any, any>>;
17
17
  workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
18
18
  autoStartWorker?: {
19
19
  queues: (keyof TQueues)[];
20
20
  concurrency?: number;
21
- limiter?: IgniterJobsWorkerBuilderConfig['limiter'];
21
+ limiter?: IgniterJobsWorkerBuilderConfig["limiter"];
22
22
  };
23
23
  logger?: IgniterLogger;
24
24
  telemetry?: IgniterJobsTelemetry;
@@ -33,12 +33,12 @@ interface IgniterJobsBuilderState<TContext, TQueues extends Record<string, Ignit
33
33
  contextFactory?: () => TContext | Promise<TContext>;
34
34
  queues: TQueues;
35
35
  scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
36
- queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
36
+ queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any, any>>;
37
37
  workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
38
38
  autoStartWorker?: {
39
39
  queues: (keyof TQueues)[];
40
40
  concurrency?: number;
41
- limiter?: IgniterJobsWorkerBuilderConfig['limiter'];
41
+ limiter?: IgniterJobsWorkerBuilderConfig["limiter"];
42
42
  };
43
43
  }
44
44
 
@@ -49,8 +49,9 @@ interface IgniterJobsBuilderState<TContext, TQueues extends Record<string, Ignit
49
49
 
50
50
  type IgniterJobsInferInput<TInput> = IgniterJobsInferSchemaInput<TInput>;
51
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;
52
53
  type IgniterJobsInferCronResult<TDef> = TDef extends IgniterCronDefinition<any, infer TResult> ? TResult : unknown;
53
- interface IgniterJobsJobInstanceAccessor {
54
+ interface IgniterJobsJobInstanceAccessor<TDef extends IgniterJobDefinition<any, any, any, any> = IgniterJobDefinition<any, any, any, any>> {
54
55
  retrieve(): Promise<IgniterJobSearchResult | null>;
55
56
  retry(): Promise<void>;
56
57
  remove(): Promise<void>;
@@ -63,15 +64,16 @@ interface IgniterJobsJobInstanceAccessor {
63
64
  message: string;
64
65
  level: "info" | "warn" | "error";
65
66
  }[]>;
67
+ stream(): IgniterJobsJobStreamAccessor<TDef>;
66
68
  }
67
69
  interface IgniterJobsJobManyAccessor {
68
70
  retry(): Promise<void>;
69
71
  remove(): Promise<void>;
70
72
  }
71
- interface IgniterJobsJobAccessor<TInput = unknown, TResult = unknown> {
72
- dispatch(params: IgniterJobsDispatchParams<TInput>): Promise<string>;
73
- schedule(params: IgniterJobsScheduleParams<TInput>): Promise<string>;
74
- 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>;
75
77
  many(ids: string[]): IgniterJobsJobManyAccessor;
76
78
  subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
77
79
  }
@@ -86,7 +88,7 @@ interface IgniterJobsQueueManagerAccessor {
86
88
  }): Promise<void>;
87
89
  retryAll(): Promise<number>;
88
90
  }
89
- type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<any, any, any>> = {}> = {
91
+ type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<any, any, any, any>> = {}> = {
90
92
  get(): IgniterJobsQueueManagerAccessor;
91
93
  list(filter?: {
92
94
  status?: IgniterJobStatus[];
@@ -95,10 +97,10 @@ type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<
95
97
  }): Promise<IgniterJobSearchResult[]>;
96
98
  subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
97
99
  readonly jobs: {
98
- [K in keyof TJobs]: IgniterJobsJobAccessor<IgniterJobsInferJobInput<TJobs[K]>, any>;
100
+ [K in keyof TJobs]: IgniterJobsJobAccessor<TJobs[K]>;
99
101
  };
100
102
  } & {
101
- [K in keyof TJobs]: IgniterJobsJobAccessor<IgniterJobsInferJobInput<TJobs[K]>, any>;
103
+ [K in keyof TJobs]: IgniterJobsJobAccessor<TJobs[K]>;
102
104
  };
103
105
  interface IgniterJobsWorkerBuilderAccessor<TQueueNames extends string> {
104
106
  create(): IgniterJobsWorkerFluentBuilder<TQueueNames>;
@@ -125,7 +127,7 @@ interface IgniterJobsBaseRuntime<TConfig extends IgniterJobsConfig<any, any, any
125
127
  }
126
128
  type IgniterJobsRuntime<TConfig extends IgniterJobsConfig<any, any, any> = IgniterJobsConfig<any, any, any>> = IgniterJobsBaseRuntime<TConfig> & {
127
129
  [Q in keyof TConfig["queues"]]: TConfig["queues"][Q] extends {
128
- jobs: infer TJobs extends Record<string, IgniterJobDefinition<any, any, any>>;
130
+ jobs: infer TJobs extends Record<string, IgniterJobDefinition<any, any, any, any>>;
129
131
  } ? IgniterJobsQueueAccessor<TJobs> : IgniterJobsQueueAccessor;
130
132
  };
131
133
 
@@ -383,6 +385,11 @@ declare class IgniterJobsManager<TConfig extends IgniterJobsConfig<any, any, any
383
385
  */
384
386
  private getJobDefinition;
385
387
  private getEffectiveJobDefinition;
388
+ private createExecutionStreamEmitter;
389
+ private createJobStreamAccessor;
390
+ private normalizeStreamEmitPayload;
391
+ private normalizeStreamReadEvent;
392
+ private getJobStreamSchema;
386
393
  /**
387
394
  * Resolves the effective scope for a job operation.
388
395
  * @internal
@@ -435,7 +442,7 @@ declare class IgniterJobsManager<TConfig extends IgniterJobsConfig<any, any, any
435
442
  * .build()
436
443
  * ```
437
444
  */
438
- 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> {
439
446
  private readonly state;
440
447
  private constructor();
441
448
  /**
@@ -449,7 +456,7 @@ declare class IgniterQueueBuilder<TContext, TJobs extends Record<string, Igniter
449
456
  * @param jobName - Unique name of the job inside the queue.
450
457
  * @param definition - Job definition (handler, schemas, options, hooks).
451
458
  */
452
- 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>;
453
460
  /**
454
461
  * Registers a cron task on the queue.
455
462
  *
@@ -605,7 +612,7 @@ declare class IgniterJobsBuilder<TContext, TQueues extends Record<string, Ignite
605
612
  /**
606
613
  * Applies default job options to all queues.
607
614
  */
608
- withQueueDefaults(defaults: Partial<IgniterJobDefinition<TContext, any, any>>): IgniterJobsBuilder<TContext, TQueues, TScope>;
615
+ withQueueDefaults(defaults: Partial<IgniterJobDefinition<TContext, any, any, any>>): IgniterJobsBuilder<TContext, TQueues, TScope>;
609
616
  /**
610
617
  * Applies default worker options.
611
618
  */
@@ -737,4 +744,4 @@ declare class IgniterJobsError extends IgniterError {
737
744
  constructor(options: IgniterJobsErrorOptions);
738
745
  }
739
746
 
740
- 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,6 +1,6 @@
1
1
  import { IgniterLogger, IgniterError } from '@igniter-js/common';
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 IgniterJobsScheduleParams, p as IgniterJobsInferSchemaInput, q as IgniterCronDefinition, r as IgniterJobsScopeEntry, s as IgniterJobsSchema, t as IgniterJobsScopeOptions } from './adapter-Cax_40HW.js';
3
- export { u as IgniterJobCounts, v as IgniterJobsAdapterDispatchParams, w as IgniterJobsAdapterScheduleParams, x as IgniterJobsBullMQAdapterOptions, y as IgniterJobsBunSQLiteAdapterOptions, z as IgniterJobsEvent, A as IgniterJobsExecutionContext, B as IgniterJobsFailureHook, C as IgniterJobsHookContext, D as IgniterJobsInferSchemaOutput, E as IgniterJobsInvokeOptions, F as IgniterJobsJobLog, G as IgniterJobsProgressHook, H as IgniterJobsQueueManager, J as IgniterJobsScheduleOptions, K as IgniterJobsStartHook, L as IgniterJobsSuccessHook, M as IgniterJobsWorkerMetrics } from './adapter-Cax_40HW.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';
4
4
  import 'ioredis';
5
5
 
6
6
  /**
@@ -13,12 +13,12 @@ interface IgniterJobsConfig<TContext = unknown, TQueues extends Record<string, I
13
13
  contextFactory: () => TContext | Promise<TContext>;
14
14
  queues: TQueues;
15
15
  scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
16
- queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
16
+ queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any, any>>;
17
17
  workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
18
18
  autoStartWorker?: {
19
19
  queues: (keyof TQueues)[];
20
20
  concurrency?: number;
21
- limiter?: IgniterJobsWorkerBuilderConfig['limiter'];
21
+ limiter?: IgniterJobsWorkerBuilderConfig["limiter"];
22
22
  };
23
23
  logger?: IgniterLogger;
24
24
  telemetry?: IgniterJobsTelemetry;
@@ -33,12 +33,12 @@ interface IgniterJobsBuilderState<TContext, TQueues extends Record<string, Ignit
33
33
  contextFactory?: () => TContext | Promise<TContext>;
34
34
  queues: TQueues;
35
35
  scopeDefinition?: IgniterJobsScopeDefinition<TScope>;
36
- queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any>>;
36
+ queueDefaults?: Partial<IgniterJobDefinition<TContext, any, any, any>>;
37
37
  workerDefaults?: Partial<IgniterJobsWorkerBuilderConfig>;
38
38
  autoStartWorker?: {
39
39
  queues: (keyof TQueues)[];
40
40
  concurrency?: number;
41
- limiter?: IgniterJobsWorkerBuilderConfig['limiter'];
41
+ limiter?: IgniterJobsWorkerBuilderConfig["limiter"];
42
42
  };
43
43
  }
44
44
 
@@ -49,8 +49,9 @@ interface IgniterJobsBuilderState<TContext, TQueues extends Record<string, Ignit
49
49
 
50
50
  type IgniterJobsInferInput<TInput> = IgniterJobsInferSchemaInput<TInput>;
51
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;
52
53
  type IgniterJobsInferCronResult<TDef> = TDef extends IgniterCronDefinition<any, infer TResult> ? TResult : unknown;
53
- interface IgniterJobsJobInstanceAccessor {
54
+ interface IgniterJobsJobInstanceAccessor<TDef extends IgniterJobDefinition<any, any, any, any> = IgniterJobDefinition<any, any, any, any>> {
54
55
  retrieve(): Promise<IgniterJobSearchResult | null>;
55
56
  retry(): Promise<void>;
56
57
  remove(): Promise<void>;
@@ -63,15 +64,16 @@ interface IgniterJobsJobInstanceAccessor {
63
64
  message: string;
64
65
  level: "info" | "warn" | "error";
65
66
  }[]>;
67
+ stream(): IgniterJobsJobStreamAccessor<TDef>;
66
68
  }
67
69
  interface IgniterJobsJobManyAccessor {
68
70
  retry(): Promise<void>;
69
71
  remove(): Promise<void>;
70
72
  }
71
- interface IgniterJobsJobAccessor<TInput = unknown, TResult = unknown> {
72
- dispatch(params: IgniterJobsDispatchParams<TInput>): Promise<string>;
73
- schedule(params: IgniterJobsScheduleParams<TInput>): Promise<string>;
74
- 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>;
75
77
  many(ids: string[]): IgniterJobsJobManyAccessor;
76
78
  subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
77
79
  }
@@ -86,7 +88,7 @@ interface IgniterJobsQueueManagerAccessor {
86
88
  }): Promise<void>;
87
89
  retryAll(): Promise<number>;
88
90
  }
89
- type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<any, any, any>> = {}> = {
91
+ type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<any, any, any, any>> = {}> = {
90
92
  get(): IgniterJobsQueueManagerAccessor;
91
93
  list(filter?: {
92
94
  status?: IgniterJobStatus[];
@@ -95,10 +97,10 @@ type IgniterJobsQueueAccessor<TJobs extends Record<string, IgniterJobDefinition<
95
97
  }): Promise<IgniterJobSearchResult[]>;
96
98
  subscribe(handler: IgniterJobsEventHandler): Promise<() => Promise<void>>;
97
99
  readonly jobs: {
98
- [K in keyof TJobs]: IgniterJobsJobAccessor<IgniterJobsInferJobInput<TJobs[K]>, any>;
100
+ [K in keyof TJobs]: IgniterJobsJobAccessor<TJobs[K]>;
99
101
  };
100
102
  } & {
101
- [K in keyof TJobs]: IgniterJobsJobAccessor<IgniterJobsInferJobInput<TJobs[K]>, any>;
103
+ [K in keyof TJobs]: IgniterJobsJobAccessor<TJobs[K]>;
102
104
  };
103
105
  interface IgniterJobsWorkerBuilderAccessor<TQueueNames extends string> {
104
106
  create(): IgniterJobsWorkerFluentBuilder<TQueueNames>;
@@ -125,7 +127,7 @@ interface IgniterJobsBaseRuntime<TConfig extends IgniterJobsConfig<any, any, any
125
127
  }
126
128
  type IgniterJobsRuntime<TConfig extends IgniterJobsConfig<any, any, any> = IgniterJobsConfig<any, any, any>> = IgniterJobsBaseRuntime<TConfig> & {
127
129
  [Q in keyof TConfig["queues"]]: TConfig["queues"][Q] extends {
128
- jobs: infer TJobs extends Record<string, IgniterJobDefinition<any, any, any>>;
130
+ jobs: infer TJobs extends Record<string, IgniterJobDefinition<any, any, any, any>>;
129
131
  } ? IgniterJobsQueueAccessor<TJobs> : IgniterJobsQueueAccessor;
130
132
  };
131
133
 
@@ -383,6 +385,11 @@ declare class IgniterJobsManager<TConfig extends IgniterJobsConfig<any, any, any
383
385
  */
384
386
  private getJobDefinition;
385
387
  private getEffectiveJobDefinition;
388
+ private createExecutionStreamEmitter;
389
+ private createJobStreamAccessor;
390
+ private normalizeStreamEmitPayload;
391
+ private normalizeStreamReadEvent;
392
+ private getJobStreamSchema;
386
393
  /**
387
394
  * Resolves the effective scope for a job operation.
388
395
  * @internal
@@ -435,7 +442,7 @@ declare class IgniterJobsManager<TConfig extends IgniterJobsConfig<any, any, any
435
442
  * .build()
436
443
  * ```
437
444
  */
438
- 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> {
439
446
  private readonly state;
440
447
  private constructor();
441
448
  /**
@@ -449,7 +456,7 @@ declare class IgniterQueueBuilder<TContext, TJobs extends Record<string, Igniter
449
456
  * @param jobName - Unique name of the job inside the queue.
450
457
  * @param definition - Job definition (handler, schemas, options, hooks).
451
458
  */
452
- 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>;
453
460
  /**
454
461
  * Registers a cron task on the queue.
455
462
  *
@@ -605,7 +612,7 @@ declare class IgniterJobsBuilder<TContext, TQueues extends Record<string, Ignite
605
612
  /**
606
613
  * Applies default job options to all queues.
607
614
  */
608
- withQueueDefaults(defaults: Partial<IgniterJobDefinition<TContext, any, any>>): IgniterJobsBuilder<TContext, TQueues, TScope>;
615
+ withQueueDefaults(defaults: Partial<IgniterJobDefinition<TContext, any, any, any>>): IgniterJobsBuilder<TContext, TQueues, TScope>;
609
616
  /**
610
617
  * Applies default worker options.
611
618
  */
@@ -737,4 +744,4 @@ declare class IgniterJobsError extends IgniterError {
737
744
  constructor(options: IgniterJobsErrorOptions);
738
745
  }
739
746
 
740
- 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.js CHANGED
@@ -146,6 +146,11 @@ var _IgniterJobsPrefix = class _IgniterJobsPrefix {
146
146
  if (!params.scope) return base;
147
147
  return `${base}:scope:${params.scope.type}:${params.scope.id}`;
148
148
  }
149
+ static buildJobStreamChannel(params) {
150
+ const base = `${_IgniterJobsPrefix.BASE_PREFIX}:stream:${params.environment}:${params.service}:${params.queue}:${params.jobId}`;
151
+ if (!params.scope) return base;
152
+ return `${base}:scope:${params.scope.type}:${params.scope.id}`;
153
+ }
149
154
  };
150
155
  _IgniterJobsPrefix.BASE_PREFIX = "igniter:jobs";
151
156
  var IgniterJobsPrefix = _IgniterJobsPrefix;
@@ -547,7 +552,8 @@ var IgniterJobsManager = class _IgniterJobsManager {
547
552
  },
548
553
  state: () => self.adapter.getJobState(id, queueName),
549
554
  progress: () => self.adapter.getJobProgress(id, queueName),
550
- logs: () => self.adapter.getJobLogs(id, queueName)
555
+ logs: () => self.adapter.getJobLogs(id, queueName),
556
+ stream: () => self.createJobStreamAccessor(queueName, jobName, id)
551
557
  };
552
558
  },
553
559
  many(ids) {
@@ -880,10 +886,18 @@ var IgniterJobsManager = class _IgniterJobsManager {
880
886
  async buildExecutionContext(ctx, queueName, jobName) {
881
887
  const realContext = await this.config.contextFactory();
882
888
  const scope = ctx.scope ?? IgniterJobsScopeUtils.extractScopeFromMetadata(ctx.job.metadata);
889
+ const definition = this.getJobDefinition(queueName, jobName);
890
+ const stream = this.createExecutionStreamEmitter(
891
+ queueName,
892
+ jobName,
893
+ ctx.job.id,
894
+ scope,
895
+ definition
896
+ );
883
897
  return {
884
898
  ...ctx,
885
899
  context: realContext,
886
- job: { ...ctx.job, name: jobName, queue: queueName },
900
+ job: { ...ctx.job, name: jobName, queue: queueName, stream },
887
901
  scope
888
902
  };
889
903
  }
@@ -921,6 +935,115 @@ var IgniterJobsManager = class _IgniterJobsManager {
921
935
  name: jobName
922
936
  };
923
937
  }
938
+ createExecutionStreamEmitter(queueName, jobName, jobId, scope, definition) {
939
+ return {
940
+ emit: async (type, data) => {
941
+ const payload = await this.normalizeStreamEmitPayload(
942
+ queueName,
943
+ jobName,
944
+ type,
945
+ data,
946
+ definition
947
+ );
948
+ return this.adapter.writeJobStreamEvent({
949
+ queue: queueName,
950
+ jobName,
951
+ jobId,
952
+ scope,
953
+ persistence: definition?.stream?.persistence,
954
+ event: {
955
+ type,
956
+ data: payload,
957
+ timestamp: /* @__PURE__ */ new Date(),
958
+ jobId,
959
+ jobName,
960
+ queue: queueName,
961
+ scope
962
+ }
963
+ });
964
+ }
965
+ };
966
+ }
967
+ createJobStreamAccessor(queueName, jobName, jobId) {
968
+ const definition = this.getJobDefinition(queueName, jobName);
969
+ return {
970
+ subscribe: async (handler) => {
971
+ return this.adapter.subscribeJobStream({
972
+ queue: queueName,
973
+ jobId,
974
+ handler: async (event) => {
975
+ const normalized = await this.normalizeStreamReadEvent(
976
+ queueName,
977
+ jobName,
978
+ event,
979
+ definition
980
+ );
981
+ await handler(normalized);
982
+ }
983
+ });
984
+ },
985
+ read: async ({
986
+ after,
987
+ limit
988
+ } = {}) => {
989
+ if (!definition?.stream?.persistence?.enabled) {
990
+ return {
991
+ items: [],
992
+ nextCursor: void 0,
993
+ hasMore: false
994
+ };
995
+ }
996
+ const result = await this.adapter.readJobStream({
997
+ queue: queueName,
998
+ jobId,
999
+ after,
1000
+ limit
1001
+ });
1002
+ return {
1003
+ ...result,
1004
+ items: await Promise.all(
1005
+ result.items.map(
1006
+ (event) => this.normalizeStreamReadEvent(
1007
+ queueName,
1008
+ jobName,
1009
+ event,
1010
+ definition
1011
+ )
1012
+ )
1013
+ )
1014
+ };
1015
+ }
1016
+ };
1017
+ }
1018
+ async normalizeStreamEmitPayload(queueName, jobName, type, data, definition) {
1019
+ const schema = this.getJobStreamSchema(definition, type);
1020
+ if (!schema) return data;
1021
+ return IgniterJobsValidationUtils.validateInput(schema, data);
1022
+ }
1023
+ async normalizeStreamReadEvent(queueName, jobName, event, definition) {
1024
+ const schema = this.getJobStreamSchema(definition, event.type);
1025
+ if (!schema) return event;
1026
+ const normalized = await IgniterJobsValidationUtils.validateInput(
1027
+ schema,
1028
+ event.data
1029
+ );
1030
+ return {
1031
+ ...event,
1032
+ data: normalized
1033
+ };
1034
+ }
1035
+ getJobStreamSchema(definition, type) {
1036
+ const events = definition?.stream?.events;
1037
+ if (!events) return void 0;
1038
+ const schema = events[type];
1039
+ if (!schema) {
1040
+ throw new IgniterJobsError({
1041
+ code: "JOBS_VALIDATION_FAILED",
1042
+ message: `Stream event "${type}" is not registered for this job definition.`
1043
+ });
1044
+ }
1045
+ return schema;
1046
+ }
924
1047
  /**
925
1048
  * Resolves the effective scope for a job operation.
926
1049
  * @internal