timed-silky
Version:
Timed-Silky 是基于一款基于 TypeScript 的定时任务调度器。得益于 TypeScript,Timed-Silky 可以用符合特定句式的自然语言描述任务的调度规则,提供丝滑的链式调用接口。
78 lines (77 loc) • 2.83 kB
TypeScript
import { RuleChain } from "./rule";
import { DayOfWeek, TimePointTemplate } from "./time-type";
interface Start {
at(timePoint: TimePointTemplate, ...timePoints: TimePointTemplate[]): TimePointAnd & DayRangeIn;
every(x: number): XUnit;
every_second(): HourRangeIn & DayRangeIn;
every_minute(): HourRangeIn & DayRangeIn;
every_hour(): HourRangeIn & DayRangeIn;
every_day(): DayRangeIn;
}
interface TimePointAnd {
and(timePoint: string): DayRangeIn;
}
interface DayRangeIn {
on(day: DayOfWeek): DayRangeAnd & DayRangeTo;
on(day: DayOfWeek, day2: DayOfWeek, ...days: DayOfWeek[]): DayRangeAnd;
from(day: DayOfWeek): DayRangeTo;
except(day: DayOfWeek): DayRangeAnd & DayRangeTo;
except(day: DayOfWeek, day2: DayOfWeek, ...days: DayOfWeek[]): DayRangeAnd;
}
interface DayRangeTo {
to(day: DayOfWeek): DayRangeAnd;
}
interface DayRangeAnd {
and(day: DayOfWeek): DayRangeTo;
}
interface XUnit {
seconds(): HourRangeIn & DayRangeIn;
minutes(): HourRangeIn & DayRangeIn;
hours(): HourRangeIn & DayRangeIn;
days(): DayRangeIn;
}
interface HourRangeIn {
from(timePont: TimePointTemplate): HourRangeTo;
except(timePont: TimePointTemplate): HourRangeTo;
}
interface HourRangeTo {
to(timePoint: TimePointTemplate): HourRangeAnd & DayRangeIn;
}
interface HourRangeAnd {
and(timePoint: TimePointTemplate): HourRangeTo;
}
interface TimedRuleWordsWrapper {
get timeRuleWords(): string[];
}
interface Timed {
timed(rule: string): void;
}
declare class RuleBuilder implements Start, Timed {
private _timeRuleWords;
constructor();
get timeRuleWords(): string[];
timed(rule: string): void;
at(timePoint: string, ...timePoints: string[]): this;
every(x: number): this;
seconds(): this;
minutes(): this;
hours(): this;
days(): this;
every_second(): this;
every_minute(): this;
every_hour(): this;
every_day(): this;
and(dayOrPoint: string | DayOfWeek): this;
on(day: DayOfWeek, day2?: DayOfWeek, ...days: DayOfWeek[]): this;
from(timePoint: string): this;
except(dayOrPoint: DayOfWeek | TimePointTemplate, day2?: DayOfWeek, ...days: DayOfWeek[]): this;
to(dayOrPoint: DayOfWeek | string): this;
}
declare function createRuleBuilder(): Start & Timed;
/**
* 解析自然语言描述的时间规则,并返回 RuleChain 对象描述的时间规则链
* @param ruleWords 自然语言字符串或单词列表描述的时间规则
* @returns RuleChain 对象表示的时间规则链,RuleChain 当前可能包括一个规则,以后可能会包括多个
*/
declare function parseFrom(ruleWords: string[]): RuleChain;
export { createRuleBuilder, TimedRuleWordsWrapper, parseFrom, RuleBuilder, Start, Timed, };