@stacksjs/scheduler 0.64.5 → 0.65.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/src/types/cron.ts DELETED
@@ -1,72 +0,0 @@
1
- import type { SpawnOptions } from 'node:child_process'
2
- import type { DateTime } from 'luxon'
3
- import type { CONSTRAINTS, TIME_UNITS_MAP } from '../constants'
4
- import type { CronJob } from '../job'
5
- import type { IntRange } from './utils'
6
-
7
- interface BaseCronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> {
8
- cronTime: string | Date | DateTime
9
- onTick: CronCommand<C, WithOnComplete<OC>>
10
- onComplete?: OC
11
- start?: boolean | null
12
- context?: C
13
- runOnInit?: boolean | null
14
- unrefTimeout?: boolean | null
15
- }
16
-
17
- export type CronJobParams<OC extends CronOnCompleteCommand | null = null, C = null> = BaseCronJobParams<OC, C> &
18
- (
19
- | {
20
- timeZone?: string | null
21
- utcOffset?: never
22
- }
23
- | {
24
- timeZone?: never
25
- utcOffset?: number | null
26
- }
27
- )
28
-
29
- export type CronContext<C> = C extends null ? CronJob : NonNullable<C>
30
-
31
- export type CronCallback<C, WithOnCompleteBool extends boolean = false> = (
32
- this: CronContext<C>,
33
- onComplete: WithOnCompleteBool extends true ? CronOnCompleteCallback : never,
34
- ) => void | Promise<void>
35
-
36
- export type CronOnCompleteCallback = () => void | Promise<void>
37
-
38
- export type CronSystemCommand =
39
- | string
40
- | {
41
- command: string
42
- args?: readonly string[] | null
43
- options?: SpawnOptions | null
44
- }
45
-
46
- export type CronCommand<C, WithOnCompleteBool extends boolean = false> =
47
- | CronCallback<C, WithOnCompleteBool>
48
- | CronSystemCommand
49
-
50
- export type CronOnCompleteCommand = CronOnCompleteCallback | CronSystemCommand
51
-
52
- export type WithOnComplete<OC> = OC extends null ? false : true
53
-
54
- export type TimeUnit = (typeof TIME_UNITS_MAP)[keyof typeof TIME_UNITS_MAP]
55
-
56
- export type TimeUnitField<T extends TimeUnit> = Partial<Record<Ranges[T], boolean>>
57
-
58
- export interface Ranges {
59
- second: SecondRange
60
- minute: MinuteRange
61
- hour: HourRange
62
- dayOfMonth: DayOfMonthRange
63
- month: MonthRange
64
- dayOfWeek: DayOfWeekRange
65
- }
66
-
67
- export type SecondRange = IntRange<(typeof CONSTRAINTS)['second'][0], (typeof CONSTRAINTS)['second'][1]>
68
- export type MinuteRange = IntRange<(typeof CONSTRAINTS)['minute'][0], (typeof CONSTRAINTS)['minute'][1]>
69
- export type HourRange = IntRange<(typeof CONSTRAINTS)['hour'][0], (typeof CONSTRAINTS)['hour'][1]>
70
- export type DayOfMonthRange = IntRange<(typeof CONSTRAINTS)['dayOfMonth'][0], (typeof CONSTRAINTS)['dayOfMonth'][1]>
71
- export type MonthRange = IntRange<(typeof CONSTRAINTS)['month'][0], (typeof CONSTRAINTS)['month'][1]>
72
- export type DayOfWeekRange = IntRange<(typeof CONSTRAINTS)['dayOfWeek'][0], (typeof CONSTRAINTS)['dayOfWeek'][1]>
@@ -1,7 +0,0 @@
1
- export type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F, false>>
2
-
3
- type Enumerate<N extends number, WithTail extends boolean = true, Acc extends number[] = []> = Acc['length'] extends N
4
- ? WithTail extends true
5
- ? [...Acc, Acc['length']][number]
6
- : Acc[number]
7
- : Enumerate<N, WithTail, [...Acc, Acc['length']]>
package/src/utils.ts DELETED
@@ -1,16 +0,0 @@
1
- import { ExclusiveParametersError } from './errors'
2
- import type { Ranges } from './types/cron'
3
-
4
- export function getRecordKeys<K extends Ranges[keyof Ranges]>(record: Partial<Record<K, boolean>>) {
5
- return Object.keys(record) as unknown as (keyof typeof record)[]
6
- }
7
-
8
- export function getTimeZoneAndOffset(timeZone?: string | null, utcOffset?: number | null) {
9
- if (timeZone != null && utcOffset != null) throw new ExclusiveParametersError('timeZone', 'utcOffset')
10
-
11
- if (timeZone != null) return { timeZone, utcOffset: null }
12
-
13
- if (utcOffset != null) return { timeZone: null, utcOffset }
14
-
15
- return { timeZone: null, utcOffset: null }
16
- }