@cloudhal/schedules 0.0.0-stage → 0.1.1
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/LICENSE +202 -0
- package/README.md +103 -2
- package/dist/src/automation.d.ts +82 -0
- package/dist/src/automation.js +199 -0
- package/dist/src/budget-meter.d.ts +58 -0
- package/dist/src/budget-meter.js +130 -0
- package/dist/src/budget.d.ts +41 -0
- package/dist/src/budget.js +76 -0
- package/dist/src/builtins.d.ts +132 -0
- package/dist/src/builtins.js +473 -0
- package/dist/src/engine.d.ts +16 -0
- package/dist/src/engine.js +30 -0
- package/dist/src/errors.d.ts +22 -0
- package/dist/src/errors.js +56 -0
- package/dist/src/feed-check.d.ts +56 -0
- package/dist/src/feed-check.js +365 -0
- package/dist/src/findings.d.ts +185 -0
- package/dist/src/findings.js +287 -0
- package/dist/src/ids.d.ts +24 -0
- package/dist/src/ids.js +96 -0
- package/dist/src/index.d.ts +24 -0
- package/dist/src/index.js +24 -0
- package/dist/src/instant.d.ts +19 -0
- package/dist/src/instant.js +50 -0
- package/dist/src/notify.d.ts +50 -0
- package/dist/src/notify.js +60 -0
- package/dist/src/recurrence.d.ts +155 -0
- package/dist/src/recurrence.js +939 -0
- package/dist/src/release-when.d.ts +23 -0
- package/dist/src/release-when.js +55 -0
- package/dist/src/release.d.ts +198 -0
- package/dist/src/release.js +552 -0
- package/dist/src/scheduler.d.ts +490 -0
- package/dist/src/scheduler.js +1343 -0
- package/dist/src/sql/finish.d.ts +32 -0
- package/dist/src/sql/finish.js +103 -0
- package/dist/src/sql/index.d.ts +6 -0
- package/dist/src/sql/index.js +15 -0
- package/dist/src/sql/rows.d.ts +125 -0
- package/dist/src/sql/rows.js +297 -0
- package/dist/src/sql/store.d.ts +467 -0
- package/dist/src/sql/store.js +2166 -0
- package/dist/src/taint.d.ts +65 -0
- package/dist/src/taint.js +138 -0
- package/dist/src/text.d.ts +6 -0
- package/dist/src/text.js +25 -0
- package/dist/src/time-entry.d.ts +6 -0
- package/dist/src/time-entry.js +6 -0
- package/dist/src/time.d.ts +61 -0
- package/dist/src/time.js +140 -0
- package/package.json +69 -3
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
export type Weekday = "MO" | "TU" | "WE" | "TH" | "FR" | "SA" | "SU";
|
|
2
|
+
/** ISO order (Monday = 1). */
|
|
3
|
+
export declare const WEEKDAYS: readonly Weekday[];
|
|
4
|
+
export type RuleFrequency = "DAILY" | "WEEKLY" | "MONTHLY";
|
|
5
|
+
export interface ByDay {
|
|
6
|
+
day: Weekday;
|
|
7
|
+
/** 1…5 or -5…-1 (MONTHLY only): the nth (from the end) such weekday of the month. */
|
|
8
|
+
ordinal?: number;
|
|
9
|
+
}
|
|
10
|
+
/** A parsed rule; `formatRule` turns it back into its canonical text. */
|
|
11
|
+
export interface ParsedRule {
|
|
12
|
+
freq: RuleFrequency;
|
|
13
|
+
interval: number;
|
|
14
|
+
byDay?: ByDay[];
|
|
15
|
+
byMonthDay?: number[];
|
|
16
|
+
byHour?: number[];
|
|
17
|
+
byMinute?: number[];
|
|
18
|
+
count?: number;
|
|
19
|
+
/** Canonical instant (inclusive). */
|
|
20
|
+
until?: string;
|
|
21
|
+
}
|
|
22
|
+
/** What `occurrences` needs: the contract's `AutomationRecurrence` without `preset`. */
|
|
23
|
+
export interface RecurrenceInput {
|
|
24
|
+
start: string;
|
|
25
|
+
timeZone: string;
|
|
26
|
+
rule?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface Occurrence {
|
|
29
|
+
/** The instant, canonical (`Date#toISOString()`). */
|
|
30
|
+
at: string;
|
|
31
|
+
/** The wall-clock time the rule produced (before any DST move), to the minute. */
|
|
32
|
+
local: string;
|
|
33
|
+
adjusted?: "dst-gap";
|
|
34
|
+
}
|
|
35
|
+
export declare const RULE_MAX_LENGTH = 300;
|
|
36
|
+
export declare const MAX_BYMINUTE = 4;
|
|
37
|
+
/** Built-in jobs and agent tasks (§9.3). */
|
|
38
|
+
export declare const DEFAULT_MIN_INTERVAL_MINUTES = 60;
|
|
39
|
+
export declare const MAX_OCCURRENCES_PER_DAY = 24;
|
|
40
|
+
/** Parses a rule of the subset (without `RRULE:`); throws `ScheduleError` naming the problem. */
|
|
41
|
+
export declare function parseRule(rule: string): ParsedRule;
|
|
42
|
+
/** The canonical text of a parsed rule (parts in a fixed order). */
|
|
43
|
+
export declare function formatRule(rule: ParsedRule): string;
|
|
44
|
+
export interface ValidateOptions {
|
|
45
|
+
/** Minimum minutes between two runs (default 60, §9.3). */
|
|
46
|
+
minIntervalMinutes?: number;
|
|
47
|
+
/** Most runs on one day (default 24). */
|
|
48
|
+
maxPerDay?: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Validates a recurrence for storage: the zone, the start, the rule and the job's minimum interval.
|
|
52
|
+
* Returns the parsed rule (undefined for a one-off).
|
|
53
|
+
*/
|
|
54
|
+
export declare function validateRecurrence(input: RecurrenceInput, options?: ValidateOptions): ParsedRule | undefined;
|
|
55
|
+
export interface OccurrenceQuery {
|
|
56
|
+
/** Only occurrences strictly after this instant. */
|
|
57
|
+
after?: string | Date | number;
|
|
58
|
+
/** Only occurrences strictly before this instant. */
|
|
59
|
+
before?: string | Date | number;
|
|
60
|
+
/** At most this many (required: a rule without COUNT or UNTIL never ends). */
|
|
61
|
+
limit: number;
|
|
62
|
+
/** Stop after this many periods without reaching `limit` (default: 100 years' worth). */
|
|
63
|
+
maxPeriods?: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Expands a recurrence (a one-off when `rule` is absent) into instants, in order. Pure: pass the
|
|
67
|
+
* clock as `after`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function occurrences(input: RecurrenceInput, query: OccurrenceQuery): Occurrence[];
|
|
70
|
+
/** The first occurrence strictly after `after`, or undefined when the recurrence has ended. */
|
|
71
|
+
export declare function nextOccurrence(input: RecurrenceInput, after: string | Date | number): Occurrence | undefined;
|
|
72
|
+
export interface OccurrencesBetween {
|
|
73
|
+
/** The first occurrences in the range, at most `limit`. */
|
|
74
|
+
occurrences: Occurrence[];
|
|
75
|
+
/** The latest occurrence in the range (the one that runs after downtime, §8.6). */
|
|
76
|
+
latest?: Occurrence;
|
|
77
|
+
/** How many there are, saturating at `limit + 1`. */
|
|
78
|
+
count: number;
|
|
79
|
+
truncated: boolean;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Occurrences in `(after, upTo]` — what a tick that last ran at `after` has to account for. Only
|
|
83
|
+
* the first `limit` are listed, but `latest` is always the true latest (only it runs, §8.6).
|
|
84
|
+
*/
|
|
85
|
+
export declare function occurrencesBetween(input: RecurrenceInput, after: string | Date | number, upTo: string | Date | number, limit?: number): OccurrencesBetween;
|
|
86
|
+
export type RecurrencePreset = "once" | "hourly" | "daily" | "weekdays" | "weekly" | "monthly" | "custom";
|
|
87
|
+
/**
|
|
88
|
+
* The rule a Studio/MCP preset stands for, given the wall-clock `start` (§9.3), with every part
|
|
89
|
+
* spelled out so the rule reads the same whatever `start` later becomes: `hourly` is
|
|
90
|
+
* `FREQ=DAILY;BYHOUR=0,…,23;BYMINUTE=m` (HOURLY stays out of the vocabulary), `daily` adds
|
|
91
|
+
* `BYHOUR`/`BYMINUTE`, `weekly` the start's weekday, `monthly` its day of the month. `once` has no
|
|
92
|
+
* rule; `custom` has none of its own (the caller supplies it).
|
|
93
|
+
*/
|
|
94
|
+
export declare function presetRule(preset: "once", start: string): undefined;
|
|
95
|
+
export declare function presetRule(preset: Exclude<RecurrencePreset, "custom" | "once">, start: string): string;
|
|
96
|
+
export declare function presetRule(preset: Exclude<RecurrencePreset, "custom">, start: string): string | undefined;
|
|
97
|
+
/** The preset a rule matches for `start`, or `custom`. */
|
|
98
|
+
export declare function presetOf(rule: string | undefined, start: string): RecurrencePreset;
|
|
99
|
+
/**
|
|
100
|
+
* The deterministic minute offset (0–9) a built-in job created from a preset gets, so many sites do
|
|
101
|
+
* not all wake at :00 (§9.5): FNV-1a 32 of the automation id, modulo 10.
|
|
102
|
+
*/
|
|
103
|
+
export declare function presetMinuteOffset(automationId: string): number;
|
|
104
|
+
export type RecurrenceSentenceKey = "once" | "hourly" | "daily" | "everyNDays" | "weekdays" | "weekly" | "everyNWeeks" | "monthlyOnDays" | "everyNMonthsOnDays" | "monthlyOnWeekdays" | "everyNMonthsOnWeekdays" | "custom";
|
|
105
|
+
/**
|
|
106
|
+
* A recurrence in words, as data: Studio and the API render it with `renderRecurrence` (or their
|
|
107
|
+
* own templates from the same keys); nothing here is an English string.
|
|
108
|
+
*/
|
|
109
|
+
export interface RecurrenceSentence {
|
|
110
|
+
key: RecurrenceSentenceKey;
|
|
111
|
+
/** Wall-clock times, `HH:mm`, in the recurrence's zone. */
|
|
112
|
+
times: string[];
|
|
113
|
+
timeZone: string;
|
|
114
|
+
n?: number;
|
|
115
|
+
/** The start's date (`YYYY-MM-DD`), for `once`. */
|
|
116
|
+
date?: string;
|
|
117
|
+
/** `hourly`: the minute (`07`). */
|
|
118
|
+
minute?: string;
|
|
119
|
+
days?: Weekday[];
|
|
120
|
+
/** Days of the month; -1 is the last day. */
|
|
121
|
+
monthDays?: number[];
|
|
122
|
+
/** `monthlyOnWeekdays`: plain weekdays carry no ordinal. */
|
|
123
|
+
weekdays?: ByDay[];
|
|
124
|
+
count?: number;
|
|
125
|
+
/** The last date (`YYYY-MM-DD`, in the zone) for UNTIL. */
|
|
126
|
+
until?: string;
|
|
127
|
+
/** `custom`: the canonical rule. */
|
|
128
|
+
rule?: string;
|
|
129
|
+
}
|
|
130
|
+
/** Describes a recurrence as a `RecurrenceSentence`. */
|
|
131
|
+
export declare function describeRecurrence(input: RecurrenceInput): RecurrenceSentence;
|
|
132
|
+
export type RecurrenceLocale = "en" | "tr";
|
|
133
|
+
/** Templates and words for `renderRecurrence`, per locale. `{name}` is a placeholder. */
|
|
134
|
+
export interface RecurrenceMessages {
|
|
135
|
+
templates: Record<RecurrenceSentenceKey, string>;
|
|
136
|
+
count: string;
|
|
137
|
+
until: string;
|
|
138
|
+
and: string;
|
|
139
|
+
listSeparator: string;
|
|
140
|
+
dayNames: Record<Weekday, string>;
|
|
141
|
+
/** The weekday as the head of "the second Tuesday of the month" (Turkish possessive). */
|
|
142
|
+
dayNamesOrdinal: Record<Weekday, string>;
|
|
143
|
+
/** 1…5, -1…-5 → "first", "last", "second to last". */
|
|
144
|
+
ordinals: Record<string, string>;
|
|
145
|
+
/** A day of the month: `{n}` → "1st" / "1."; `last` for -1. */
|
|
146
|
+
monthDay: (n: number) => string;
|
|
147
|
+
lastMonthDay: string;
|
|
148
|
+
monthNames: readonly string[];
|
|
149
|
+
/** `{d} {month} {y}` order. */
|
|
150
|
+
date: string;
|
|
151
|
+
}
|
|
152
|
+
/** The recurrence words in English and Turkish (§15.8: our own templates, not a cron-to-text library). */
|
|
153
|
+
export declare const RECURRENCE_MESSAGES: Record<RecurrenceLocale, RecurrenceMessages>;
|
|
154
|
+
/** Renders a sentence with the locale's templates ("Her ayın ikinci salısı 09:07"). */
|
|
155
|
+
export declare function renderRecurrence(sentence: RecurrenceSentence, locale: RecurrenceLocale): string;
|