@queuebase/core 1.4.0 → 1.5.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/dist/index.d.cts CHANGED
@@ -23,6 +23,39 @@ interface EnqueueOptions {
23
23
  /** Maximum concurrent jobs of this type (per worker) */
24
24
  concurrency?: number;
25
25
  }
26
+ /**
27
+ * Overlap policy for scheduled jobs
28
+ */
29
+ type OverlapPolicy = 'skip' | 'allow';
30
+ /**
31
+ * Full schedule configuration object
32
+ */
33
+ interface ScheduleConfig {
34
+ /** Cron expression or plain english shorthand */
35
+ cron: string;
36
+ /** IANA timezone (default: 'UTC') */
37
+ timezone?: string;
38
+ /** Whether this schedule is active in code (default: true) */
39
+ enabled?: boolean;
40
+ /** Overlap policy when previous run is still running (default: 'skip') */
41
+ overlap?: OverlapPolicy;
42
+ /** Timeout for scheduled runs (e.g., '5m', '30s', or milliseconds) */
43
+ timeout?: string | number;
44
+ }
45
+ /**
46
+ * Schedule can be a plain english/cron string shorthand or a full config object
47
+ */
48
+ type ScheduleInput = string | ScheduleConfig;
49
+ /**
50
+ * Resolved schedule metadata after parsing — always has a standard cron expression
51
+ */
52
+ interface ResolvedSchedule {
53
+ cronExpression: string;
54
+ timezone: string;
55
+ enabled: boolean;
56
+ overlap: OverlapPolicy;
57
+ timeoutMs: number | null;
58
+ }
26
59
  /**
27
60
  * A job definition with typed input/output
28
61
  */
@@ -33,6 +66,8 @@ interface JobDefinition<TInput = unknown, TOutput = unknown> {
33
66
  handler: (ctx: JobContext<TInput>) => Promise<TOutput>;
34
67
  /** Default options for this job */
35
68
  defaults?: EnqueueOptions;
69
+ /** Cron schedule — only valid when input accepts empty object */
70
+ schedule?: ScheduleInput;
36
71
  }
37
72
  /**
38
73
  * Context passed to job handlers
@@ -121,6 +156,7 @@ interface AnyJobDefinition {
121
156
  input: z.ZodTypeAny;
122
157
  handler: (ctx: JobContext<unknown>) => Promise<unknown>;
123
158
  defaults?: EnqueueOptions;
159
+ schedule?: ScheduleInput;
124
160
  }
125
161
  /**
126
162
  * A collection of job definitions
@@ -161,13 +197,28 @@ type JobClient<T extends Record<string, AnyJobDefinition>> = CallableJobRouter<T
161
197
  };
162
198
 
163
199
  /**
164
- * Creates a job definition with typed input and handler
200
+ * A job definition that accepts empty input schedule is allowed.
165
201
  */
166
- declare function job<TInput, TOutput>(definition: {
202
+ interface SchedulableJobConfig<TInput extends Record<string, never>, TOutput> {
167
203
  input: z.ZodType<TInput>;
168
204
  handler: (ctx: JobContext<TInput>) => Promise<TOutput>;
169
205
  defaults?: EnqueueOptions;
170
- }): AnyJobDefinition;
206
+ schedule?: ScheduleInput;
207
+ }
208
+ /**
209
+ * A job definition with non-empty input — schedule is not allowed.
210
+ */
211
+ interface NonSchedulableJobConfig<TInput, TOutput> {
212
+ input: z.ZodType<TInput>;
213
+ handler: (ctx: JobContext<TInput>) => Promise<TOutput>;
214
+ defaults?: EnqueueOptions;
215
+ }
216
+ /**
217
+ * Creates a job definition with typed input and handler.
218
+ * The `schedule` property is only available when the input schema accepts `{}`.
219
+ */
220
+ declare function job<TInput extends Record<string, never>, TOutput>(definition: SchedulableJobConfig<TInput, TOutput>): AnyJobDefinition;
221
+ declare function job<TInput, TOutput>(definition: NonSchedulableJobConfig<TInput, TOutput>): AnyJobDefinition;
171
222
  /**
172
223
  * Infer the input type from a job definition's Zod schema
173
224
  */
@@ -177,6 +228,44 @@ type InferJobInput<T extends AnyJobDefinition> = T['input'] extends z.ZodType<in
177
228
  */
178
229
  type InferJobOutput<T extends AnyJobDefinition> = T['handler'] extends (ctx: JobContext<unknown>) => Promise<infer O> ? O : never;
179
230
 
231
+ /**
232
+ * Parse a plain english expression to a cron string.
233
+ * Returns the input unchanged if no pattern matches (assumed to be raw cron).
234
+ */
235
+ declare function parsePlainEnglish(expression: string): string;
236
+ /**
237
+ * Validate a cron expression using croner.
238
+ * Throws if the expression is invalid.
239
+ */
240
+ declare function validateCron(expression: string): void;
241
+ /**
242
+ * Compute the next run time for a cron expression with optional timezone.
243
+ */
244
+ declare function nextRun(expression: string, timezone?: string): Date | null;
245
+ /**
246
+ * Compute multiple next run times for a cron expression.
247
+ */
248
+ declare function nextRuns(expression: string, count: number, timezone?: string): Date[];
249
+ /**
250
+ * Resolve a schedule input into a fully resolved schedule.
251
+ * Parses plain english, validates the cron expression, and resolves defaults.
252
+ */
253
+ declare function resolveSchedule(input: ScheduleInput): ResolvedSchedule;
254
+ /**
255
+ * Metadata for a single schedule extracted from a job router.
256
+ */
257
+ interface ScheduleMetadata {
258
+ jobName: string;
259
+ schedule: ResolvedSchedule;
260
+ }
261
+ /**
262
+ * Extract all schedule metadata from a job router.
263
+ * Only includes jobs that have a schedule defined.
264
+ */
265
+ declare function extractSchedules(router: Record<string, {
266
+ schedule?: ScheduleInput;
267
+ }>): ScheduleMetadata[];
268
+
180
269
  /**
181
270
  * Parse a delay string into milliseconds
182
271
  * Supports: '5s', '5m', '5h', '5d' or raw milliseconds
@@ -230,4 +319,4 @@ declare function processJobCallback(router: Record<string, AnyJobDefinition>, re
230
319
  webhookSecret?: string;
231
320
  }): Promise<HandlerResponse>;
232
321
 
233
- export { type AnyJobDefinition, type BackoffStrategy, type CallableJob, type CallableJobRouter, type EnqueueOptions, type EnqueueResult, type HandlerRequest, type HandlerResponse, type InferJobInput, type InferJobOutput, type JobClient, type JobContext, type JobDefinition, JobFailureError, type JobResult, type JobRouter, type JobStatus, type JobStatusResponse, type QueuebaseConfig, type QueuedJob, WEBHOOK_HEADERS, calculateBackoff, createJobRouter, generateJobId, generatePublicId, job, parseDelay, processJobCallback, signPayload, verifySignature };
322
+ export { type AnyJobDefinition, type BackoffStrategy, type CallableJob, type CallableJobRouter, type EnqueueOptions, type EnqueueResult, type HandlerRequest, type HandlerResponse, type InferJobInput, type InferJobOutput, type JobClient, type JobContext, type JobDefinition, JobFailureError, type JobResult, type JobRouter, type JobStatus, type JobStatusResponse, type OverlapPolicy, type QueuebaseConfig, type QueuedJob, type ResolvedSchedule, type ScheduleConfig, type ScheduleInput, type ScheduleMetadata, WEBHOOK_HEADERS, calculateBackoff, createJobRouter, extractSchedules, generateJobId, generatePublicId, job, nextRun, nextRuns, parseDelay, parsePlainEnglish, processJobCallback, resolveSchedule, signPayload, validateCron, verifySignature };
package/dist/index.d.ts CHANGED
@@ -23,6 +23,39 @@ interface EnqueueOptions {
23
23
  /** Maximum concurrent jobs of this type (per worker) */
24
24
  concurrency?: number;
25
25
  }
26
+ /**
27
+ * Overlap policy for scheduled jobs
28
+ */
29
+ type OverlapPolicy = 'skip' | 'allow';
30
+ /**
31
+ * Full schedule configuration object
32
+ */
33
+ interface ScheduleConfig {
34
+ /** Cron expression or plain english shorthand */
35
+ cron: string;
36
+ /** IANA timezone (default: 'UTC') */
37
+ timezone?: string;
38
+ /** Whether this schedule is active in code (default: true) */
39
+ enabled?: boolean;
40
+ /** Overlap policy when previous run is still running (default: 'skip') */
41
+ overlap?: OverlapPolicy;
42
+ /** Timeout for scheduled runs (e.g., '5m', '30s', or milliseconds) */
43
+ timeout?: string | number;
44
+ }
45
+ /**
46
+ * Schedule can be a plain english/cron string shorthand or a full config object
47
+ */
48
+ type ScheduleInput = string | ScheduleConfig;
49
+ /**
50
+ * Resolved schedule metadata after parsing — always has a standard cron expression
51
+ */
52
+ interface ResolvedSchedule {
53
+ cronExpression: string;
54
+ timezone: string;
55
+ enabled: boolean;
56
+ overlap: OverlapPolicy;
57
+ timeoutMs: number | null;
58
+ }
26
59
  /**
27
60
  * A job definition with typed input/output
28
61
  */
@@ -33,6 +66,8 @@ interface JobDefinition<TInput = unknown, TOutput = unknown> {
33
66
  handler: (ctx: JobContext<TInput>) => Promise<TOutput>;
34
67
  /** Default options for this job */
35
68
  defaults?: EnqueueOptions;
69
+ /** Cron schedule — only valid when input accepts empty object */
70
+ schedule?: ScheduleInput;
36
71
  }
37
72
  /**
38
73
  * Context passed to job handlers
@@ -121,6 +156,7 @@ interface AnyJobDefinition {
121
156
  input: z.ZodTypeAny;
122
157
  handler: (ctx: JobContext<unknown>) => Promise<unknown>;
123
158
  defaults?: EnqueueOptions;
159
+ schedule?: ScheduleInput;
124
160
  }
125
161
  /**
126
162
  * A collection of job definitions
@@ -161,13 +197,28 @@ type JobClient<T extends Record<string, AnyJobDefinition>> = CallableJobRouter<T
161
197
  };
162
198
 
163
199
  /**
164
- * Creates a job definition with typed input and handler
200
+ * A job definition that accepts empty input schedule is allowed.
165
201
  */
166
- declare function job<TInput, TOutput>(definition: {
202
+ interface SchedulableJobConfig<TInput extends Record<string, never>, TOutput> {
167
203
  input: z.ZodType<TInput>;
168
204
  handler: (ctx: JobContext<TInput>) => Promise<TOutput>;
169
205
  defaults?: EnqueueOptions;
170
- }): AnyJobDefinition;
206
+ schedule?: ScheduleInput;
207
+ }
208
+ /**
209
+ * A job definition with non-empty input — schedule is not allowed.
210
+ */
211
+ interface NonSchedulableJobConfig<TInput, TOutput> {
212
+ input: z.ZodType<TInput>;
213
+ handler: (ctx: JobContext<TInput>) => Promise<TOutput>;
214
+ defaults?: EnqueueOptions;
215
+ }
216
+ /**
217
+ * Creates a job definition with typed input and handler.
218
+ * The `schedule` property is only available when the input schema accepts `{}`.
219
+ */
220
+ declare function job<TInput extends Record<string, never>, TOutput>(definition: SchedulableJobConfig<TInput, TOutput>): AnyJobDefinition;
221
+ declare function job<TInput, TOutput>(definition: NonSchedulableJobConfig<TInput, TOutput>): AnyJobDefinition;
171
222
  /**
172
223
  * Infer the input type from a job definition's Zod schema
173
224
  */
@@ -177,6 +228,44 @@ type InferJobInput<T extends AnyJobDefinition> = T['input'] extends z.ZodType<in
177
228
  */
178
229
  type InferJobOutput<T extends AnyJobDefinition> = T['handler'] extends (ctx: JobContext<unknown>) => Promise<infer O> ? O : never;
179
230
 
231
+ /**
232
+ * Parse a plain english expression to a cron string.
233
+ * Returns the input unchanged if no pattern matches (assumed to be raw cron).
234
+ */
235
+ declare function parsePlainEnglish(expression: string): string;
236
+ /**
237
+ * Validate a cron expression using croner.
238
+ * Throws if the expression is invalid.
239
+ */
240
+ declare function validateCron(expression: string): void;
241
+ /**
242
+ * Compute the next run time for a cron expression with optional timezone.
243
+ */
244
+ declare function nextRun(expression: string, timezone?: string): Date | null;
245
+ /**
246
+ * Compute multiple next run times for a cron expression.
247
+ */
248
+ declare function nextRuns(expression: string, count: number, timezone?: string): Date[];
249
+ /**
250
+ * Resolve a schedule input into a fully resolved schedule.
251
+ * Parses plain english, validates the cron expression, and resolves defaults.
252
+ */
253
+ declare function resolveSchedule(input: ScheduleInput): ResolvedSchedule;
254
+ /**
255
+ * Metadata for a single schedule extracted from a job router.
256
+ */
257
+ interface ScheduleMetadata {
258
+ jobName: string;
259
+ schedule: ResolvedSchedule;
260
+ }
261
+ /**
262
+ * Extract all schedule metadata from a job router.
263
+ * Only includes jobs that have a schedule defined.
264
+ */
265
+ declare function extractSchedules(router: Record<string, {
266
+ schedule?: ScheduleInput;
267
+ }>): ScheduleMetadata[];
268
+
180
269
  /**
181
270
  * Parse a delay string into milliseconds
182
271
  * Supports: '5s', '5m', '5h', '5d' or raw milliseconds
@@ -230,4 +319,4 @@ declare function processJobCallback(router: Record<string, AnyJobDefinition>, re
230
319
  webhookSecret?: string;
231
320
  }): Promise<HandlerResponse>;
232
321
 
233
- export { type AnyJobDefinition, type BackoffStrategy, type CallableJob, type CallableJobRouter, type EnqueueOptions, type EnqueueResult, type HandlerRequest, type HandlerResponse, type InferJobInput, type InferJobOutput, type JobClient, type JobContext, type JobDefinition, JobFailureError, type JobResult, type JobRouter, type JobStatus, type JobStatusResponse, type QueuebaseConfig, type QueuedJob, WEBHOOK_HEADERS, calculateBackoff, createJobRouter, generateJobId, generatePublicId, job, parseDelay, processJobCallback, signPayload, verifySignature };
322
+ export { type AnyJobDefinition, type BackoffStrategy, type CallableJob, type CallableJobRouter, type EnqueueOptions, type EnqueueResult, type HandlerRequest, type HandlerResponse, type InferJobInput, type InferJobOutput, type JobClient, type JobContext, type JobDefinition, JobFailureError, type JobResult, type JobRouter, type JobStatus, type JobStatusResponse, type OverlapPolicy, type QueuebaseConfig, type QueuedJob, type ResolvedSchedule, type ScheduleConfig, type ScheduleInput, type ScheduleMetadata, WEBHOOK_HEADERS, calculateBackoff, createJobRouter, extractSchedules, generateJobId, generatePublicId, job, nextRun, nextRuns, parseDelay, parsePlainEnglish, processJobCallback, resolveSchedule, signPayload, validateCron, verifySignature };