1 | import { SpawnOptions } from 'child_process';
|
2 | import { DateTime } from 'luxon';
|
3 | import { CONSTRAINTS, TIME_UNITS_MAP } from '../constants';
|
4 | import { CronJob } from '../job';
|
5 | import { IntRange } from './utils';
|
6 | interface BaseCronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> {
|
7 | cronTime: string | Date | DateTime;
|
8 | onTick: CronCommand<C, WithOnComplete<OC>>;
|
9 | onComplete?: OC;
|
10 | start?: boolean | null;
|
11 | context?: C;
|
12 | runOnInit?: boolean | null;
|
13 | unrefTimeout?: boolean | null;
|
14 | waitForCompletion?: boolean | null;
|
15 | }
|
16 | export type CronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> = BaseCronJobParams<OC, C> & ({
|
17 | timeZone?: string | null;
|
18 | utcOffset?: never;
|
19 | } | {
|
20 | timeZone?: never;
|
21 | utcOffset?: number | null;
|
22 | });
|
23 | export type CronContext<C> = C extends null ? CronJob : NonNullable<C>;
|
24 | export type CronCallback<C, WithOnCompleteBool extends boolean = false> = (this: CronContext<C>, onComplete: WithOnCompleteBool extends true ? CronOnCompleteCallback : never) => void | Promise<void>;
|
25 | export type CronOnCompleteCallback = () => void | Promise<void>;
|
26 | export type CronSystemCommand = string | {
|
27 | command: string;
|
28 | args?: readonly string[] | null;
|
29 | options?: SpawnOptions | null;
|
30 | };
|
31 | export type CronCommand<C, WithOnCompleteBool extends boolean = false> = CronCallback<C, WithOnCompleteBool> | CronSystemCommand;
|
32 | export type CronOnCompleteCommand = CronOnCompleteCallback | CronSystemCommand;
|
33 | export type WithOnComplete<OC> = OC extends null ? false : true;
|
34 | export type TimeUnit = (typeof TIME_UNITS_MAP)[keyof typeof TIME_UNITS_MAP];
|
35 | export type TimeUnitField<T extends TimeUnit> = Partial<Record<Ranges[T], boolean>>;
|
36 | export interface Ranges {
|
37 | second: SecondRange;
|
38 | minute: MinuteRange;
|
39 | hour: HourRange;
|
40 | dayOfMonth: DayOfMonthRange;
|
41 | month: MonthRange;
|
42 | dayOfWeek: DayOfWeekRange;
|
43 | }
|
44 | export type SecondRange = IntRange<(typeof CONSTRAINTS)['second'][0], (typeof CONSTRAINTS)['second'][1]>;
|
45 | export type MinuteRange = IntRange<(typeof CONSTRAINTS)['minute'][0], (typeof CONSTRAINTS)['minute'][1]>;
|
46 | export type HourRange = IntRange<(typeof CONSTRAINTS)['hour'][0], (typeof CONSTRAINTS)['hour'][1]>;
|
47 | export type DayOfMonthRange = IntRange<(typeof CONSTRAINTS)['dayOfMonth'][0], (typeof CONSTRAINTS)['dayOfMonth'][1]>;
|
48 | export type MonthRange = IntRange<(typeof CONSTRAINTS)['month'][0], (typeof CONSTRAINTS)['month'][1]>;
|
49 | export type DayOfWeekRange = IntRange<(typeof CONSTRAINTS)['dayOfWeek'][0], (typeof CONSTRAINTS)['dayOfWeek'][1]>;
|
50 | export {};
|