import { SpawnOptions } from 'child_process'; import { DateTime } from 'luxon'; import { CONSTRAINTS, TIME_UNITS_MAP } from '../constants'; import { CronJob } from '../job'; import { IntRange } from './utils'; interface BaseCronJobParams { cronTime: string | Date | DateTime; onTick: CronCommand>; onComplete?: OC; start?: boolean | null; context?: C; runOnInit?: boolean | null; unrefTimeout?: boolean | null; waitForCompletion?: boolean | null; } export type CronJobParams = BaseCronJobParams & ({ timeZone?: string | null; utcOffset?: never; } | { timeZone?: never; utcOffset?: number | null; }); export type CronContext = C extends null ? CronJob : NonNullable; export type CronCallback = (this: CronContext, onComplete: WithOnCompleteBool extends true ? CronOnCompleteCallback : never) => void | Promise; export type CronOnCompleteCallback = () => void | Promise; export type CronSystemCommand = string | { command: string; args?: readonly string[] | null; options?: SpawnOptions | null; }; export type CronCommand = CronCallback | CronSystemCommand; export type CronOnCompleteCommand = CronOnCompleteCallback | CronSystemCommand; export type WithOnComplete = OC extends null ? false : true; export type TimeUnit = (typeof TIME_UNITS_MAP)[keyof typeof TIME_UNITS_MAP]; export type TimeUnitField = Partial>; export interface Ranges { second: SecondRange; minute: MinuteRange; hour: HourRange; dayOfMonth: DayOfMonthRange; month: MonthRange; dayOfWeek: DayOfWeekRange; } export type SecondRange = IntRange<(typeof CONSTRAINTS)['second'][0], (typeof CONSTRAINTS)['second'][1]>; export type MinuteRange = IntRange<(typeof CONSTRAINTS)['minute'][0], (typeof CONSTRAINTS)['minute'][1]>; export type HourRange = IntRange<(typeof CONSTRAINTS)['hour'][0], (typeof CONSTRAINTS)['hour'][1]>; export type DayOfMonthRange = IntRange<(typeof CONSTRAINTS)['dayOfMonth'][0], (typeof CONSTRAINTS)['dayOfMonth'][1]>; export type MonthRange = IntRange<(typeof CONSTRAINTS)['month'][0], (typeof CONSTRAINTS)['month'][1]>; export type DayOfWeekRange = IntRange<(typeof CONSTRAINTS)['dayOfWeek'][0], (typeof CONSTRAINTS)['dayOfWeek'][1]>; export {};