cron-toolkit 0.0.0 → 1.0.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.
Files changed (57) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +245 -0
  3. package/dist/constants.d.ts +15 -0
  4. package/dist/constants.js +28 -0
  5. package/dist/core/ast.d.ts +10 -0
  6. package/dist/core/ast.js +27 -0
  7. package/dist/core/dialects.d.ts +33 -0
  8. package/dist/core/dialects.js +50 -0
  9. package/dist/core/errors.d.ts +19 -0
  10. package/dist/core/errors.js +74 -0
  11. package/dist/core/fields.d.ts +15 -0
  12. package/dist/core/fields.js +167 -0
  13. package/dist/core/format.d.ts +17 -0
  14. package/dist/core/format.js +110 -0
  15. package/dist/core/parse.d.ts +10 -0
  16. package/dist/core/parse.js +102 -0
  17. package/dist/core/types.d.ts +88 -0
  18. package/dist/core/types.js +1 -0
  19. package/dist/describe/describer.d.ts +4 -0
  20. package/dist/describe/describer.js +224 -0
  21. package/dist/describe/intl.d.ts +11 -0
  22. package/dist/describe/intl.js +32 -0
  23. package/dist/describe/locale.d.ts +64 -0
  24. package/dist/describe/locale.js +1 -0
  25. package/dist/describe.d.ts +19 -0
  26. package/dist/describe.js +14 -0
  27. package/dist/index.d.ts +6 -0
  28. package/dist/index.js +4 -0
  29. package/dist/locales/en.d.ts +2 -0
  30. package/dist/locales/en.js +40 -0
  31. package/dist/locales/es.d.ts +2 -0
  32. package/dist/locales/es.js +101 -0
  33. package/dist/locales/fr.d.ts +2 -0
  34. package/dist/locales/fr.js +101 -0
  35. package/dist/recurrence/recurrence.d.ts +15 -0
  36. package/dist/recurrence/recurrence.js +222 -0
  37. package/dist/recurrence/types.d.ts +56 -0
  38. package/dist/recurrence/types.js +5 -0
  39. package/dist/schedule/civil.d.ts +26 -0
  40. package/dist/schedule/civil.js +53 -0
  41. package/dist/schedule/compile.d.ts +18 -0
  42. package/dist/schedule/compile.js +122 -0
  43. package/dist/schedule/engine.d.ts +32 -0
  44. package/dist/schedule/engine.js +97 -0
  45. package/dist/schedule/search.d.ts +9 -0
  46. package/dist/schedule/search.js +137 -0
  47. package/dist/schedule/temporal.d.ts +7 -0
  48. package/dist/schedule/temporal.js +14 -0
  49. package/dist/schedule/zone.d.ts +29 -0
  50. package/dist/schedule/zone.js +66 -0
  51. package/dist/schedule.d.ts +36 -0
  52. package/dist/schedule.js +84 -0
  53. package/dist/utils/operator-grammar.d.ts +49 -0
  54. package/dist/utils/operator-grammar.js +79 -0
  55. package/dist/utils/parse-cron-int.d.ts +1 -0
  56. package/dist/utils/parse-cron-int.js +3 -0
  57. package/package.json +69 -7
@@ -0,0 +1,167 @@
1
+ import { parseOperatorExpression } from "../utils/operator-grammar.js";
2
+ import { parseCronInt } from "../utils/parse-cron-int.js";
3
+ import { toCanonicalWeekday } from "./dialects.js";
4
+ const DOM_SPECIAL = /^(L|L-\d*|LW|\d+W)$/i;
5
+ const DOW_SPECIAL = /^(L|[a-z0-9]+L|.*#.*)$/i;
6
+ const MAX_LAST_DAY_OFFSET = 30;
7
+ /** Parses one field's text into canonical form for the given dialect. */
8
+ export function parseField(dialect, field, text) {
9
+ const spec = dialect.fields[field];
10
+ if (!spec)
11
+ throw new Error(`${dialect.dialect} has no ${field} field`);
12
+ const isDayField = field === "dayOfMonth" || field === "dayOfWeek";
13
+ if (text === "?") {
14
+ if (isDayField && dialect.daySpecials)
15
+ return { ok: true, expr: { kind: "none" } };
16
+ return unsupported(dialect, text);
17
+ }
18
+ if (isDayField) {
19
+ const special = field === "dayOfMonth" ? DOM_SPECIAL : DOW_SPECIAL;
20
+ const items = text.split(",");
21
+ const specialItem = items.find((item) => special.test(item));
22
+ if (specialItem !== undefined) {
23
+ if (!dialect.daySpecials)
24
+ return unsupported(dialect, specialItem);
25
+ if (items.length > 1)
26
+ return failure("SPECIAL_NOT_COMBINABLE", { token: specialItem });
27
+ return field === "dayOfMonth"
28
+ ? parseDayOfMonthSpecial(spec, text)
29
+ : parseDayOfWeekSpecial(dialect, spec, text);
30
+ }
31
+ }
32
+ const result = parseOperatorExpression(text, grammarFor(dialect, spec));
33
+ if (!result.ok) {
34
+ const { code, token } = result.issue;
35
+ if (code === "INVALID_VALUE")
36
+ return invalidValue(spec, token);
37
+ if (code === "INVALID_STEP") {
38
+ return failure(code, spec.maxStep === undefined ? { token } : { token, max: spec.maxStep });
39
+ }
40
+ return failure(code, { token });
41
+ }
42
+ if (result.expr.kind === "any")
43
+ return result;
44
+ const items = field === "dayOfWeek" ? toCanonicalWeekdayItems(dialect, result.expr.items) : result.expr.items;
45
+ return { ok: true, expr: { kind: "list", items } };
46
+ }
47
+ function grammarFor(dialect, spec) {
48
+ return {
49
+ bounds: spec.bounds,
50
+ parseAtom: (token) => parseAtom(spec, token),
51
+ maxStep: spec.maxStep,
52
+ allowNamedStepStart: dialect.allowNamedStepStart,
53
+ };
54
+ }
55
+ /** Native value of a number or (case-insensitive) name, or NaN. */
56
+ function parseAtom(spec, token) {
57
+ const numeric = parseCronInt(token);
58
+ if (!Number.isNaN(numeric) || !spec.names)
59
+ return numeric;
60
+ const index = spec.names.indexOf(token.toLowerCase());
61
+ return index === -1 ? NaN : index + (spec.nameBase ?? 0);
62
+ }
63
+ function parseBoundedAtom(spec, token) {
64
+ const value = parseAtom(spec, token);
65
+ const [min, max] = spec.bounds;
66
+ return value >= min && value <= max ? value : NaN;
67
+ }
68
+ function parseDayOfMonthSpecial(spec, text) {
69
+ const upper = text.toUpperCase();
70
+ if (upper === "L")
71
+ return list({ kind: "lastDay", offset: 0 });
72
+ if (upper === "LW")
73
+ return list({ kind: "lastWeekday" });
74
+ if (upper.startsWith("L-")) {
75
+ const offset = parseCronInt(upper.slice(2));
76
+ if (!(offset >= 0 && offset <= MAX_LAST_DAY_OFFSET))
77
+ return invalidValue(spec, text);
78
+ return list({ kind: "lastDay", offset });
79
+ }
80
+ const day = parseBoundedAtom(spec, upper.slice(0, -1));
81
+ if (Number.isNaN(day))
82
+ return invalidValue(spec, text);
83
+ return list({ kind: "nearestWeekday", day });
84
+ }
85
+ function parseDayOfWeekSpecial(dialect, spec, text) {
86
+ if (text.toUpperCase() === "L")
87
+ return list({ kind: "value", value: 6 });
88
+ if (text.includes("#")) {
89
+ const [weekdayToken, nthToken, ...rest] = text.split("#");
90
+ const native = parseBoundedAtom(spec, weekdayToken);
91
+ if (Number.isNaN(native))
92
+ return invalidValue(spec, weekdayToken);
93
+ const nth = parseCronInt(nthToken);
94
+ if (rest.length > 0 || !(nth >= 1 && nth <= 5))
95
+ return failure("INVALID_NTH", { token: text });
96
+ return list({
97
+ kind: "nthDayOfWeek",
98
+ weekday: toCanonicalWeekday(dialect.dialect, native),
99
+ nth: nth,
100
+ });
101
+ }
102
+ const native = parseBoundedAtom(spec, text.slice(0, -1));
103
+ if (Number.isNaN(native))
104
+ return invalidValue(spec, text);
105
+ return list({ kind: "lastDayOfWeek", weekday: toCanonicalWeekday(dialect.dialect, native) });
106
+ }
107
+ /**
108
+ * Maps native weekday items to canonical ones. Quartz is a plain shift (1-7 →
109
+ * 0-6). Unix 7 also means Sunday, so items reaching 7 are split or expanded
110
+ * instead of producing a wrap-around range.
111
+ */
112
+ function toCanonicalWeekdayItems(dialect, items) {
113
+ if (dialect.dialect === "quartz") {
114
+ return items.map((item) => {
115
+ if (item.kind === "value")
116
+ return { kind: "value", value: item.value - 1 };
117
+ if (item.kind === "range")
118
+ return { ...item, start: item.start - 1, end: item.end - 1 };
119
+ return item.start === "any" ? item : { ...item, start: item.start - 1 };
120
+ });
121
+ }
122
+ return items.flatMap((item) => {
123
+ if (item.kind === "value")
124
+ return [{ kind: "value", value: item.value % 7 }];
125
+ if (item.kind === "step" && item.start === "any")
126
+ return [item];
127
+ const start = item.start;
128
+ const end = item.kind === "range" ? item.end : 7;
129
+ const step = item.step ?? 1;
130
+ const reachesSeven = end === 7 && (7 - start) % step === 0;
131
+ if (!reachesSeven)
132
+ return [item.kind === "range" ? item : { ...item, start }];
133
+ if (step === 1) {
134
+ if (start === 0)
135
+ return [{ kind: "range", start: 0, end: 6 }];
136
+ if (start === 7)
137
+ return [{ kind: "value", value: 0 }];
138
+ return [
139
+ { kind: "range", start, end: 6 },
140
+ { kind: "value", value: 0 },
141
+ ];
142
+ }
143
+ const expanded = [];
144
+ for (let value = start; value <= end; value += step) {
145
+ const canonical = value % 7;
146
+ if (!expanded.includes(canonical))
147
+ expanded.push(canonical);
148
+ }
149
+ return expanded.map((value) => ({ kind: "value", value }));
150
+ });
151
+ }
152
+ function list(item) {
153
+ return { ok: true, expr: { kind: "list", items: [item] } };
154
+ }
155
+ function invalidValue(spec, token) {
156
+ const [min, max] = spec.bounds;
157
+ const params = { token, min, max };
158
+ if (spec.namesHint)
159
+ params.names = spec.namesHint;
160
+ return failure("INVALID_VALUE", params);
161
+ }
162
+ function unsupported(dialect, token) {
163
+ return failure("UNSUPPORTED_SYNTAX", { token, dialect: dialect.dialect });
164
+ }
165
+ function failure(code, params) {
166
+ return { ok: false, issue: { code, params } };
167
+ }
@@ -0,0 +1,17 @@
1
+ import type { Cron, Dialect, DialectOption } from "./types.js";
2
+ export interface FormatOptions {
3
+ /** Target dialect; defaults to the expression's own. A different one converts (and may throw). */
4
+ dialect?: Dialect;
5
+ }
6
+ export interface ConvertOptions {
7
+ to: Dialect;
8
+ /** Source dialect when the input is a string; defaults to `auto`. */
9
+ from?: DialectOption;
10
+ }
11
+ /**
12
+ * Canonical string for an expression: single spaces, day-of-week as names
13
+ * (so Quartz 1-7 vs Unix 0-7 numbering can't be confused), numbers elsewhere.
14
+ */
15
+ export declare function format(input: string | Cron, options?: FormatOptions): string;
16
+ /** Converts between dialects; throws `CronConvertError` when the target can't express it. */
17
+ export declare function convert(input: string | Cron, options: ConvertOptions): string;
@@ -0,0 +1,110 @@
1
+ import { DAY_NAMES } from "../constants.js";
2
+ import { isSingleValue, isSpecialItem, startsWithWildcard } from "./ast.js";
3
+ import { DIALECTS, fromCanonicalWeekday } from "./dialects.js";
4
+ import { CronConvertError, FIELD_LABELS } from "./errors.js";
5
+ import { parse, resolveCron } from "./parse.js";
6
+ /**
7
+ * Canonical string for an expression: single spaces, day-of-week as names
8
+ * (so Quartz 1-7 vs Unix 0-7 numbering can't be confused), numbers elsewhere.
9
+ */
10
+ export function format(input, options = {}) {
11
+ const cron = resolveCron(input);
12
+ const target = options.dialect ?? cron.dialect;
13
+ const fields = target === cron.dialect ? cron.fields : convertFields(cron, target);
14
+ return formatFields(fields, target);
15
+ }
16
+ /** Converts between dialects; throws `CronConvertError` when the target can't express it. */
17
+ export function convert(input, options) {
18
+ const cron = resolveCron(input, { dialect: options.from ?? "auto" });
19
+ return format(cron, { dialect: options.to });
20
+ }
21
+ function convertFields(cron, target) {
22
+ const reasons = [];
23
+ const fields = { ...cron.fields };
24
+ const { dayOfMonth, dayOfWeek } = cron.fields;
25
+ if (target === "unix") {
26
+ if (!isSingleValue(fields.second, 0))
27
+ reasons.push("Unix cron has no seconds field; seconds must be 0");
28
+ if (fields.year.kind !== "any")
29
+ reasons.push("Unix cron has no year field");
30
+ for (const field of ["dayOfMonth", "dayOfWeek"]) {
31
+ const expr = fields[field];
32
+ if (expr.kind === "none")
33
+ fields[field] = { kind: "any" };
34
+ if (expr.kind === "list") {
35
+ for (const item of expr.items.filter(isSpecialItem)) {
36
+ const token = formatItem(item, field, cron.dialect);
37
+ reasons.push(`Unix cron does not support '${token}' in ${FIELD_LABELS[field].toLowerCase()}`);
38
+ }
39
+ }
40
+ }
41
+ }
42
+ else {
43
+ const domAny = dayOfMonth.kind === "any";
44
+ const dowAny = dayOfWeek.kind === "any";
45
+ if (domAny) {
46
+ fields.dayOfMonth = dowAny ? { kind: "any" } : { kind: "none" };
47
+ fields.dayOfWeek = dowAny ? { kind: "none" } : dayOfWeek;
48
+ }
49
+ else if (dowAny) {
50
+ fields.dayOfWeek = { kind: "none" };
51
+ }
52
+ else if (startsWithWildcard(dayOfMonth) || startsWithWildcard(dayOfWeek)) {
53
+ reasons.push("Unix matches day-of-month AND day-of-week here (leading '*'); Quartz can't restrict both day fields");
54
+ }
55
+ else {
56
+ reasons.push("Unix matches day-of-month OR day-of-week here; Quartz can't restrict both day fields");
57
+ }
58
+ }
59
+ if (reasons.length > 0)
60
+ throw new CronConvertError(reasons);
61
+ // Safety net: the target dialect must accept the result (e.g. Quartz caps step sizes).
62
+ const reparsed = parse(formatFields(fields, target), { dialect: target });
63
+ if (!reparsed.success)
64
+ throw new CronConvertError(reparsed.errors.map((error) => error.message));
65
+ return fields;
66
+ }
67
+ function formatFields(fields, dialect) {
68
+ const spec = DIALECTS[dialect];
69
+ const names = [...spec.fieldOrder];
70
+ if (spec.optionalField && fields[spec.optionalField].kind !== "any")
71
+ names.push(spec.optionalField);
72
+ return names.map((field) => formatField(fields[field], field, dialect)).join(" ");
73
+ }
74
+ function formatField(expr, field, dialect) {
75
+ if (expr.kind === "any")
76
+ return "*";
77
+ if (expr.kind === "none")
78
+ return dialect === "quartz" ? "?" : "*";
79
+ return expr.items.map((item) => formatItem(item, field, dialect)).join(",");
80
+ }
81
+ function formatItem(item, field, dialect) {
82
+ const isDayOfWeek = field === "dayOfWeek";
83
+ const native = (value) => (isDayOfWeek ? fromCanonicalWeekday(dialect, value) : value);
84
+ const label = (value) => (isDayOfWeek ? DAY_NAMES[value].toUpperCase() : String(value));
85
+ switch (item.kind) {
86
+ case "value":
87
+ return label(item.value);
88
+ case "range":
89
+ return item.step === undefined
90
+ ? `${label(item.start)}-${label(item.end)}`
91
+ : `${native(item.start)}-${native(item.end)}/${item.step}`;
92
+ case "step":
93
+ if (item.start === "any")
94
+ return `*/${item.step}`;
95
+ // Unix day-of-week runs to 7 (= Sunday again), so `1/2` would add Sunday; bound it at Saturday.
96
+ if (isDayOfWeek && dialect === "unix")
97
+ return `${item.start}-6/${item.step}`;
98
+ return `${native(item.start)}/${item.step}`;
99
+ case "lastDay":
100
+ return item.offset === 0 ? "L" : `L-${item.offset}`;
101
+ case "nearestWeekday":
102
+ return `${item.day}W`;
103
+ case "lastWeekday":
104
+ return "LW";
105
+ case "lastDayOfWeek":
106
+ return `${native(item.weekday)}L`;
107
+ case "nthDayOfWeek":
108
+ return `${native(item.weekday)}#${item.nth}`;
109
+ }
110
+ }
@@ -0,0 +1,10 @@
1
+ import type { Cron, ParseOptions, ParseResult, ValidationResult } from "./types.js";
2
+ /**
3
+ * Parses a cron expression into its canonical form. Never throws: invalid
4
+ * input returns every field's error (no short-circuiting).
5
+ */
6
+ export declare function parse(expression: string, options?: ParseOptions): ParseResult;
7
+ export declare function validate(expression: string, options?: ParseOptions): ValidationResult;
8
+ export declare function isValid(expression: string, options?: ParseOptions): boolean;
9
+ /** Accepts a parsed `Cron` as-is, or parses a string and throws `CronParseError` if invalid. */
10
+ export declare function resolveCron(input: string | Cron, options?: ParseOptions): Cron;
@@ -0,0 +1,102 @@
1
+ import { DIALECTS, UNIX_MACROS } from "./dialects.js";
2
+ import { createError, CronParseError } from "./errors.js";
3
+ import { parseField } from "./fields.js";
4
+ const ANY = { kind: "any" };
5
+ const ZERO = { kind: "list", items: [{ kind: "value", value: 0 }] };
6
+ /**
7
+ * Parses a cron expression into its canonical form. Never throws: invalid
8
+ * input returns every field's error (no short-circuiting).
9
+ */
10
+ export function parse(expression, options = {}) {
11
+ const source = expression.trim().split(/\s+/).join(" ");
12
+ const requested = options.dialect ?? "auto";
13
+ if (source === "")
14
+ return failure([createError("EMPTY_EXPRESSION")]);
15
+ if (source.startsWith("@"))
16
+ return parseMacro(source, requested);
17
+ const tokens = source.split(" ");
18
+ const dialect = resolveDialect(requested, tokens.length);
19
+ if (!dialect) {
20
+ return failure([createError("WRONG_FIELD_COUNT", undefined, { dialect: requested, count: tokens.length })]);
21
+ }
22
+ const spec = DIALECTS[dialect];
23
+ const fieldNames = [...spec.fieldOrder];
24
+ if (spec.optionalField && tokens.length > fieldNames.length)
25
+ fieldNames.push(spec.optionalField);
26
+ const fields = {
27
+ second: ZERO,
28
+ minute: ANY,
29
+ hour: ANY,
30
+ dayOfMonth: ANY,
31
+ month: ANY,
32
+ dayOfWeek: ANY,
33
+ year: ANY,
34
+ };
35
+ const errors = [];
36
+ fieldNames.forEach((field, index) => {
37
+ const result = parseField(spec, field, tokens[index]);
38
+ if (result.ok)
39
+ fields[field] = result.expr;
40
+ else
41
+ errors.push(createError(result.issue.code, field, result.issue.params));
42
+ });
43
+ const dayFieldsParsed = !errors.some((error) => error.field === "dayOfMonth" || error.field === "dayOfWeek");
44
+ if (dialect === "quartz" && dayFieldsParsed) {
45
+ const domNone = fields.dayOfMonth.kind === "none";
46
+ const dowNone = fields.dayOfWeek.kind === "none";
47
+ if (domNone && dowNone)
48
+ errors.push(createError("DAY_FIELDS_BOTH_UNSET"));
49
+ if (!domNone && !dowNone)
50
+ errors.push(createError("DAY_FIELDS_BOTH_SET"));
51
+ }
52
+ if (errors.length > 0)
53
+ return failure(errors);
54
+ return { success: true, cron: { dialect, source, fields } };
55
+ }
56
+ export function validate(expression, options = {}) {
57
+ const result = parse(expression, options);
58
+ return result.success ? { valid: true, errors: [] } : { valid: false, errors: result.errors };
59
+ }
60
+ export function isValid(expression, options = {}) {
61
+ return parse(expression, options).success;
62
+ }
63
+ /** Accepts a parsed `Cron` as-is, or parses a string and throws `CronParseError` if invalid. */
64
+ export function resolveCron(input, options = {}) {
65
+ if (typeof input !== "string")
66
+ return input;
67
+ const result = parse(input, options);
68
+ if (!result.success)
69
+ throw new CronParseError(result.errors);
70
+ return result.cron;
71
+ }
72
+ function parseMacro(source, requested) {
73
+ if (requested === "quartz") {
74
+ return failure([createError("WRONG_FIELD_COUNT", undefined, { dialect: "quartz", count: 1 })]);
75
+ }
76
+ const macro = source.toLowerCase();
77
+ if (macro === "@reboot")
78
+ return failure([createError("UNSUPPORTED_MACRO", undefined, { macro: source })]);
79
+ const expansion = UNIX_MACROS[macro];
80
+ if (!expansion)
81
+ return failure([createError("UNKNOWN_MACRO", undefined, { macro: source })]);
82
+ const result = parse(expansion, { dialect: "unix" });
83
+ if (!result.success)
84
+ return result;
85
+ return { success: true, cron: { ...result.cron, source } };
86
+ }
87
+ function resolveDialect(requested, fieldCount) {
88
+ const isUnixCount = fieldCount === 5;
89
+ const isQuartzCount = fieldCount === 6 || fieldCount === 7;
90
+ if (requested === "unix")
91
+ return isUnixCount ? "unix" : null;
92
+ if (requested === "quartz")
93
+ return isQuartzCount ? "quartz" : null;
94
+ if (isUnixCount)
95
+ return "unix";
96
+ if (isQuartzCount)
97
+ return "quartz";
98
+ return null;
99
+ }
100
+ function failure(errors) {
101
+ return { success: false, errors };
102
+ }
@@ -0,0 +1,88 @@
1
+ export type Dialect = "quartz" | "unix";
2
+ export type FieldName = "second" | "minute" | "hour" | "dayOfMonth" | "month" | "dayOfWeek" | "year";
3
+ /**
4
+ * One comma-separated item of a field, in canonical numbering:
5
+ * day-of-week is always 0 = Sunday … 6 = Saturday, whatever the dialect.
6
+ */
7
+ export type FieldItem = {
8
+ kind: "value";
9
+ value: number;
10
+ } | {
11
+ kind: "range";
12
+ start: number;
13
+ end: number;
14
+ step?: number;
15
+ }
16
+ /** `*\/5` (start "any" = field minimum) or `10/5` (start to field maximum). */
17
+ | {
18
+ kind: "step";
19
+ start: number | "any";
20
+ step: number;
21
+ }
22
+ /** Day-of-month `L` (offset 0) or `L-3`. */
23
+ | {
24
+ kind: "lastDay";
25
+ offset: number;
26
+ }
27
+ /** Day-of-month `15W`: weekday nearest the given day, within the same month. */
28
+ | {
29
+ kind: "nearestWeekday";
30
+ day: number;
31
+ }
32
+ /** Day-of-month `LW`: last weekday (Mon-Fri) of the month. */
33
+ | {
34
+ kind: "lastWeekday";
35
+ }
36
+ /** Day-of-week `5L` / `FRIL`: last given weekday of the month. */
37
+ | {
38
+ kind: "lastDayOfWeek";
39
+ weekday: number;
40
+ }
41
+ /** Day-of-week `6#3` / `FRI#3`: nth given weekday of the month. */
42
+ | {
43
+ kind: "nthDayOfWeek";
44
+ weekday: number;
45
+ nth: 1 | 2 | 3 | 4 | 5;
46
+ };
47
+ export type FieldExpr = {
48
+ kind: "any";
49
+ }
50
+ /** Quartz `?`: no specific value (day-of-month / day-of-week only). */
51
+ | {
52
+ kind: "none";
53
+ } | {
54
+ kind: "list";
55
+ items: FieldItem[];
56
+ };
57
+ export interface Cron {
58
+ dialect: Dialect;
59
+ /** The expression as given (trimmed), e.g. `@daily` or `0 0 12 * * ?`. */
60
+ source: string;
61
+ fields: Record<FieldName, FieldExpr>;
62
+ }
63
+ export type DialectOption = Dialect | "auto";
64
+ export interface ParseOptions {
65
+ /** `auto` (default): `@macro` or 5 fields → unix; 6-7 fields → quartz. */
66
+ dialect?: DialectOption;
67
+ }
68
+ export type CronErrorCode = "EMPTY_EXPRESSION" | "WRONG_FIELD_COUNT" | "UNKNOWN_MACRO" | "UNSUPPORTED_MACRO" | "INVALID_VALUE" | "INVALID_RANGE" | "INVALID_STEP" | "UNSUPPORTED_SYNTAX" | "INVALID_NTH" | "SPECIAL_NOT_COMBINABLE" | "DAY_FIELDS_BOTH_SET" | "DAY_FIELDS_BOTH_UNSET";
69
+ export interface CronError {
70
+ code: CronErrorCode;
71
+ /** The field the error belongs to; absent for whole-expression errors. */
72
+ field?: FieldName;
73
+ /** Values interpolated into the message (token, bounds, …). */
74
+ params: Record<string, string | number>;
75
+ /** English message. Use `formatError` from `cron-toolkit/describe` for other locales. */
76
+ message: string;
77
+ }
78
+ export type ParseResult = {
79
+ success: true;
80
+ cron: Cron;
81
+ } | {
82
+ success: false;
83
+ errors: CronError[];
84
+ };
85
+ export interface ValidationResult {
86
+ valid: boolean;
87
+ errors: CronError[];
88
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { Cron } from "../core/types.js";
2
+ import { type HourCycle } from "./intl.js";
3
+ import type { Locale } from "./locale.js";
4
+ export declare function describeCron(cron: Cron, locale: Locale, hourCycle: HourCycle): string;