semola 0.5.2 → 0.5.4
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/README.md +88 -13
- package/dist/index-BhGNDjPq.d.mts +13 -0
- package/dist/index-DxSbeGP-.d.cts +13 -0
- package/dist/lib/api/index.cjs +522 -4
- package/dist/lib/api/index.d.cts +270 -4
- package/dist/lib/api/index.d.mts +270 -4
- package/dist/lib/api/index.mjs +520 -2
- package/dist/lib/cache/index.d.cts +19 -7
- package/dist/lib/cache/index.d.mts +19 -7
- package/dist/lib/cache/index.mjs +0 -2
- package/dist/lib/cron/index.cjs +470 -11
- package/dist/lib/cron/index.d.cts +112 -5
- package/dist/lib/cron/index.d.mts +112 -5
- package/dist/lib/cron/index.mjs +461 -12
- package/dist/lib/errors/index.d.cts +2 -13
- package/dist/lib/errors/index.d.mts +2 -13
- package/dist/lib/errors/index.mjs +0 -2
- package/dist/lib/i18n/index.cjs +6 -1
- package/dist/lib/i18n/index.d.cts +12 -4
- package/dist/lib/i18n/index.d.mts +12 -4
- package/dist/lib/i18n/index.mjs +6 -3
- package/dist/lib/logging/index.cjs +387 -0
- package/dist/lib/logging/index.d.cts +108 -0
- package/dist/lib/logging/index.d.mts +108 -0
- package/dist/lib/logging/index.mjs +374 -0
- package/dist/lib/policy/index.cjs +206 -20
- package/dist/lib/policy/index.d.cts +61 -5
- package/dist/lib/policy/index.d.mts +61 -5
- package/dist/lib/policy/index.mjs +187 -3
- package/dist/lib/prompts/index.cjs +374 -14
- package/dist/lib/prompts/index.d.cts +77 -12
- package/dist/lib/prompts/index.d.mts +77 -12
- package/dist/lib/prompts/index.mjs +362 -4
- package/dist/lib/pubsub/index.cjs +82 -13
- package/dist/lib/pubsub/index.d.cts +23 -9
- package/dist/lib/pubsub/index.d.mts +23 -9
- package/dist/lib/pubsub/index.mjs +82 -15
- package/dist/lib/queue/index.d.cts +46 -4
- package/dist/lib/queue/index.d.mts +46 -4
- package/dist/lib/queue/index.mjs +0 -2
- package/dist/lib/workflow/index.cjs +534 -0
- package/dist/lib/workflow/index.d.cts +85 -0
- package/dist/lib/workflow/index.d.mts +85 -0
- package/dist/lib/workflow/index.mjs +533 -0
- package/package.json +29 -3
- package/dist/api/core/index.cjs +0 -206
- package/dist/api/core/index.d.cts +0 -21
- package/dist/api/core/index.d.cts.map +0 -1
- package/dist/api/core/index.d.mts +0 -21
- package/dist/api/core/index.d.mts.map +0 -1
- package/dist/api/core/index.mjs +0 -208
- package/dist/api/core/index.mjs.map +0 -1
- package/dist/api/core/types.d.cts +0 -107
- package/dist/api/core/types.d.cts.map +0 -1
- package/dist/api/core/types.d.mts +0 -107
- package/dist/api/core/types.d.mts.map +0 -1
- package/dist/api/middleware/index.cjs +0 -8
- package/dist/api/middleware/index.d.cts +0 -11
- package/dist/api/middleware/index.d.cts.map +0 -1
- package/dist/api/middleware/index.d.mts +0 -11
- package/dist/api/middleware/index.d.mts.map +0 -1
- package/dist/api/middleware/index.mjs +0 -10
- package/dist/api/middleware/index.mjs.map +0 -1
- package/dist/api/middleware/types.d.cts +0 -16
- package/dist/api/middleware/types.d.cts.map +0 -1
- package/dist/api/middleware/types.d.mts +0 -16
- package/dist/api/middleware/types.d.mts.map +0 -1
- package/dist/api/openapi/index.cjs +0 -254
- package/dist/api/openapi/index.mjs +0 -256
- package/dist/api/openapi/index.mjs.map +0 -1
- package/dist/api/openapi/types.d.cts +0 -60
- package/dist/api/openapi/types.d.cts.map +0 -1
- package/dist/api/openapi/types.d.mts +0 -60
- package/dist/api/openapi/types.d.mts.map +0 -1
- package/dist/api/validation/index.cjs +0 -64
- package/dist/api/validation/index.mjs +0 -61
- package/dist/api/validation/index.mjs.map +0 -1
- package/dist/cache/types.d.cts +0 -17
- package/dist/cache/types.d.cts.map +0 -1
- package/dist/cache/types.d.mts +0 -17
- package/dist/cache/types.d.mts.map +0 -1
- package/dist/cron/scanner.cjs +0 -237
- package/dist/cron/scanner.mjs +0 -238
- package/dist/cron/scanner.mjs.map +0 -1
- package/dist/cron/types.d.cts +0 -11
- package/dist/cron/types.d.cts.map +0 -1
- package/dist/cron/types.d.mts +0 -11
- package/dist/cron/types.d.mts.map +0 -1
- package/dist/errors/types.d.cts +0 -5
- package/dist/errors/types.d.cts.map +0 -1
- package/dist/errors/types.d.mts +0 -5
- package/dist/errors/types.d.mts.map +0 -1
- package/dist/i18n/types.d.cts +0 -13
- package/dist/i18n/types.d.cts.map +0 -1
- package/dist/i18n/types.d.mts +0 -13
- package/dist/i18n/types.d.mts.map +0 -1
- package/dist/lib/cache/index.d.cts.map +0 -1
- package/dist/lib/cache/index.d.mts.map +0 -1
- package/dist/lib/cache/index.mjs.map +0 -1
- package/dist/lib/cron/index.d.cts.map +0 -1
- package/dist/lib/cron/index.d.mts.map +0 -1
- package/dist/lib/cron/index.mjs.map +0 -1
- package/dist/lib/errors/index.d.cts.map +0 -1
- package/dist/lib/errors/index.d.mts.map +0 -1
- package/dist/lib/errors/index.mjs.map +0 -1
- package/dist/lib/i18n/index.d.cts.map +0 -1
- package/dist/lib/i18n/index.d.mts.map +0 -1
- package/dist/lib/i18n/index.mjs.map +0 -1
- package/dist/lib/policy/index.d.cts.map +0 -1
- package/dist/lib/policy/index.d.mts.map +0 -1
- package/dist/lib/policy/index.mjs.map +0 -1
- package/dist/lib/prompts/index.d.cts.map +0 -1
- package/dist/lib/prompts/index.d.mts.map +0 -1
- package/dist/lib/prompts/index.mjs.map +0 -1
- package/dist/lib/pubsub/index.d.cts.map +0 -1
- package/dist/lib/pubsub/index.d.mts.map +0 -1
- package/dist/lib/pubsub/index.mjs.map +0 -1
- package/dist/lib/queue/index.d.cts.map +0 -1
- package/dist/lib/queue/index.d.mts.map +0 -1
- package/dist/lib/queue/index.mjs.map +0 -1
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts +0 -80
- package/dist/node_modules/@standard-schema/spec/dist/index.d.cts.map +0 -1
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts +0 -80
- package/dist/node_modules/@standard-schema/spec/dist/index.d.mts.map +0 -1
- package/dist/policy/helpers.cjs +0 -206
- package/dist/policy/helpers.d.cts +0 -50
- package/dist/policy/helpers.d.cts.map +0 -1
- package/dist/policy/helpers.d.mts +0 -50
- package/dist/policy/helpers.d.mts.map +0 -1
- package/dist/policy/helpers.mjs +0 -190
- package/dist/policy/helpers.mjs.map +0 -1
- package/dist/policy/types.d.cts +0 -16
- package/dist/policy/types.d.cts.map +0 -1
- package/dist/policy/types.d.mts +0 -16
- package/dist/policy/types.d.mts.map +0 -1
- package/dist/prompts/core/keys.cjs +0 -165
- package/dist/prompts/core/keys.mjs +0 -167
- package/dist/prompts/core/keys.mjs.map +0 -1
- package/dist/prompts/core/runtime.cjs +0 -104
- package/dist/prompts/core/runtime.mjs +0 -106
- package/dist/prompts/core/runtime.mjs.map +0 -1
- package/dist/prompts/core/session.cjs +0 -98
- package/dist/prompts/core/session.mjs +0 -100
- package/dist/prompts/core/session.mjs.map +0 -1
- package/dist/prompts/core/types.d.cts +0 -21
- package/dist/prompts/core/types.d.cts.map +0 -1
- package/dist/prompts/core/types.d.mts +0 -21
- package/dist/prompts/core/types.d.mts.map +0 -1
- package/dist/prompts/types.d.cts +0 -52
- package/dist/prompts/types.d.cts.map +0 -1
- package/dist/prompts/types.d.mts +0 -52
- package/dist/prompts/types.d.mts.map +0 -1
- package/dist/pubsub/types.d.cts +0 -10
- package/dist/pubsub/types.d.cts.map +0 -1
- package/dist/pubsub/types.d.mts +0 -10
- package/dist/pubsub/types.d.mts.map +0 -1
- package/dist/queue/types.d.cts +0 -47
- package/dist/queue/types.d.cts.map +0 -1
- package/dist/queue/types.d.mts +0 -47
- package/dist/queue/types.d.mts.map +0 -1
|
@@ -1,6 +1,114 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/lib/cron/builder/types.d.ts
|
|
2
|
+
declare const WeekDay: {
|
|
3
|
+
readonly sun: 0;
|
|
4
|
+
readonly mon: 1;
|
|
5
|
+
readonly tue: 2;
|
|
6
|
+
readonly wed: 3;
|
|
7
|
+
readonly thu: 4;
|
|
8
|
+
readonly fri: 5;
|
|
9
|
+
readonly sat: 6;
|
|
10
|
+
};
|
|
11
|
+
declare const Month: {
|
|
12
|
+
readonly jan: 1;
|
|
13
|
+
readonly feb: 2;
|
|
14
|
+
readonly mar: 3;
|
|
15
|
+
readonly apr: 4;
|
|
16
|
+
readonly may: 5;
|
|
17
|
+
readonly jun: 6;
|
|
18
|
+
readonly jul: 7;
|
|
19
|
+
readonly aug: 8;
|
|
20
|
+
readonly sep: 9;
|
|
21
|
+
readonly oct: 10;
|
|
22
|
+
readonly nov: 11;
|
|
23
|
+
readonly dec: 12;
|
|
24
|
+
};
|
|
25
|
+
type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number] : Enumerate<N, [...Acc, Acc["length"]]>;
|
|
26
|
+
type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
|
|
27
|
+
type TimeType = IntRange<0, 60>;
|
|
28
|
+
type HourType = IntRange<0, 24>;
|
|
29
|
+
type DayType = IntRange<1, 32>;
|
|
30
|
+
type MonthType = IntRange<1, 13>;
|
|
31
|
+
type WeekDayType = IntRange<0, 7>;
|
|
32
|
+
type CronRange<T> = {
|
|
33
|
+
min: NoInfer<T>;
|
|
34
|
+
max: NoInfer<T>;
|
|
35
|
+
};
|
|
36
|
+
type CronStep<T> = {
|
|
37
|
+
step: NoInfer<T>;
|
|
38
|
+
range?: {
|
|
39
|
+
min: NoInfer<T>;
|
|
40
|
+
max?: NoInfer<T>;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
type CronField = "second" | "minute" | "hour" | "day" | "month" | "weekday";
|
|
44
|
+
type CronListExpr<T> = Exclude<CronExpr<T>, {
|
|
45
|
+
type: "list";
|
|
46
|
+
}>;
|
|
47
|
+
type CronExpr<T> = {
|
|
48
|
+
type: "any";
|
|
49
|
+
} | {
|
|
50
|
+
type: "value";
|
|
51
|
+
value: T;
|
|
52
|
+
} | {
|
|
53
|
+
type: "range";
|
|
54
|
+
min: T;
|
|
55
|
+
max: T;
|
|
56
|
+
} | {
|
|
57
|
+
type: "step";
|
|
58
|
+
step: T;
|
|
59
|
+
range?: {
|
|
60
|
+
min: T;
|
|
61
|
+
max?: T;
|
|
62
|
+
};
|
|
63
|
+
} | {
|
|
64
|
+
type: "list";
|
|
65
|
+
values: CronListExpr<T>[];
|
|
66
|
+
};
|
|
67
|
+
interface IBuilder<Used extends CronField> {
|
|
68
|
+
second(expr: CronExpr<TimeType>): CronBuilderType<Used | "second">;
|
|
69
|
+
minute(expr: CronExpr<TimeType>): CronBuilderType<Used | "minute">;
|
|
70
|
+
hour(expr: CronExpr<HourType>): CronBuilderType<Used | "hour">;
|
|
71
|
+
day(expr: CronExpr<DayType>): CronBuilderType<Used | "day">;
|
|
72
|
+
month(expr: CronExpr<MonthType>): CronBuilderType<Used | "month">;
|
|
73
|
+
weekday(expr: CronExpr<WeekDayType>): CronBuilderType<Used | "weekday">;
|
|
74
|
+
}
|
|
75
|
+
type CronBuilderType<Used extends CronField = never> = Omit<IBuilder<Used>, Used>;
|
|
76
|
+
type BuilderFn = (builder: CronBuilderType) => void;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/lib/cron/builder/index.d.ts
|
|
79
|
+
declare class FieldWrapper<T> {
|
|
80
|
+
private fields;
|
|
81
|
+
add(expr: CronListExpr<T>): void;
|
|
82
|
+
read(): CronListExpr<T>[];
|
|
83
|
+
}
|
|
84
|
+
declare class CronListBuilder<T> {
|
|
85
|
+
private wrapper;
|
|
86
|
+
constructor(wrapper: FieldWrapper<T>);
|
|
87
|
+
any(): CronListBuilder<T>;
|
|
88
|
+
range(options: CronRange<T>): CronListBuilder<T>;
|
|
89
|
+
step(options: CronStep<T>): CronListBuilder<T>;
|
|
90
|
+
number(value: T): CronListBuilder<T>;
|
|
91
|
+
}
|
|
92
|
+
declare function range<T>(options: CronRange<T>): CronExpr<T>;
|
|
93
|
+
declare function any<T>(): CronExpr<T>;
|
|
94
|
+
declare function step<T>(options: CronStep<T>): CronExpr<T>;
|
|
95
|
+
declare function list<T>(builderFn: (builder: CronListBuilder<T>) => CronListBuilder<T>): CronExpr<T>;
|
|
96
|
+
declare function number<T>(value: T): {
|
|
97
|
+
type: "value";
|
|
98
|
+
value: T;
|
|
99
|
+
};
|
|
100
|
+
declare function cronJobBuilder(buildFn: BuilderFn): string;
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/lib/cron/core/types.d.ts
|
|
103
|
+
type CronAlias = "@yearly" | "@monthly" | "@weekly" | "@daily" | "@hourly" | "@minutely";
|
|
104
|
+
type CronStatus = "idle" | "running" | "paused";
|
|
105
|
+
type CronOptions = {
|
|
106
|
+
name: string;
|
|
107
|
+
schedule: CronAlias | (string & {});
|
|
108
|
+
handler: () => void | Promise<void>;
|
|
109
|
+
};
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/lib/cron/core/index.d.ts
|
|
4
112
|
declare class Cron {
|
|
5
113
|
private options;
|
|
6
114
|
private status;
|
|
@@ -35,5 +143,4 @@ declare class Cron {
|
|
|
35
143
|
private run;
|
|
36
144
|
}
|
|
37
145
|
//#endregion
|
|
38
|
-
export { Cron };
|
|
39
|
-
//# sourceMappingURL=index.d.mts.map
|
|
146
|
+
export { Cron, Month, WeekDay, any, cronJobBuilder, list, number, range, step };
|
package/dist/lib/cron/index.mjs
CHANGED
|
@@ -1,7 +1,426 @@
|
|
|
1
1
|
import { err, mightThrow, ok } from "../errors/index.mjs";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
//#region src/lib/cron/builder/index.ts
|
|
3
|
+
const CRON_FIELD_ORDER = [
|
|
4
|
+
"second",
|
|
5
|
+
"minute",
|
|
6
|
+
"hour",
|
|
7
|
+
"day",
|
|
8
|
+
"month",
|
|
9
|
+
"weekday"
|
|
10
|
+
];
|
|
11
|
+
var FieldWrapper = class {
|
|
12
|
+
fields = [];
|
|
13
|
+
add(expr) {
|
|
14
|
+
this.fields.push(expr);
|
|
15
|
+
}
|
|
16
|
+
read() {
|
|
17
|
+
return this.fields;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var CronListBuilder = class {
|
|
21
|
+
wrapper;
|
|
22
|
+
constructor(wrapper) {
|
|
23
|
+
this.wrapper = wrapper;
|
|
24
|
+
}
|
|
25
|
+
any() {
|
|
26
|
+
this.wrapper.add({ type: "any" });
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
range(options) {
|
|
30
|
+
this.wrapper.add({
|
|
31
|
+
type: "range",
|
|
32
|
+
...options
|
|
33
|
+
});
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
step(options) {
|
|
37
|
+
this.wrapper.add({
|
|
38
|
+
type: "step",
|
|
39
|
+
...options
|
|
40
|
+
});
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
number(value) {
|
|
44
|
+
this.wrapper.add({
|
|
45
|
+
type: "value",
|
|
46
|
+
value
|
|
47
|
+
});
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
function range(options) {
|
|
52
|
+
return {
|
|
53
|
+
type: "range",
|
|
54
|
+
...options
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function any() {
|
|
58
|
+
return { type: "any" };
|
|
59
|
+
}
|
|
60
|
+
function step(options) {
|
|
61
|
+
return {
|
|
62
|
+
type: "step",
|
|
63
|
+
...options
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function list(builderFn) {
|
|
67
|
+
const wrapper = new FieldWrapper();
|
|
68
|
+
builderFn(new CronListBuilder(wrapper));
|
|
69
|
+
return {
|
|
70
|
+
type: "list",
|
|
71
|
+
values: wrapper.read()
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function number(value) {
|
|
75
|
+
return {
|
|
76
|
+
type: "value",
|
|
77
|
+
value
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function cronJobBuilder(buildFn) {
|
|
81
|
+
const fields = {
|
|
82
|
+
second: void 0,
|
|
83
|
+
minute: void 0,
|
|
84
|
+
hour: void 0,
|
|
85
|
+
day: void 0,
|
|
86
|
+
month: void 0,
|
|
87
|
+
weekday: void 0
|
|
88
|
+
};
|
|
89
|
+
const obj = {
|
|
90
|
+
second(expr) {
|
|
91
|
+
fields.second = checkExpr(expr);
|
|
92
|
+
return obj;
|
|
93
|
+
},
|
|
94
|
+
minute(expr) {
|
|
95
|
+
fields.minute = checkExpr(expr);
|
|
96
|
+
return obj;
|
|
97
|
+
},
|
|
98
|
+
hour(expr) {
|
|
99
|
+
fields.hour = checkExpr(expr);
|
|
100
|
+
return obj;
|
|
101
|
+
},
|
|
102
|
+
day(expr) {
|
|
103
|
+
fields.day = checkExpr(expr);
|
|
104
|
+
return obj;
|
|
105
|
+
},
|
|
106
|
+
month(expr) {
|
|
107
|
+
fields.month = checkExpr(expr);
|
|
108
|
+
return obj;
|
|
109
|
+
},
|
|
110
|
+
weekday(expr) {
|
|
111
|
+
fields.weekday = checkExpr(expr);
|
|
112
|
+
return obj;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
buildFn(obj);
|
|
116
|
+
return generate(fields);
|
|
117
|
+
}
|
|
118
|
+
function checkExpr(expr) {
|
|
119
|
+
if (expr.type === "list") {
|
|
120
|
+
const { values } = expr;
|
|
121
|
+
if (values.length === 0) throw new Error("EmptyListError: List expression cannot be empty");
|
|
122
|
+
return values.map((e) => handleSimpleExpression(e)).join(",");
|
|
123
|
+
}
|
|
124
|
+
return handleSimpleExpression(expr);
|
|
125
|
+
}
|
|
126
|
+
function handleSimpleExpression(expr) {
|
|
127
|
+
switch (expr.type) {
|
|
128
|
+
case "any": return "*";
|
|
129
|
+
case "value": return `${expr.value}`;
|
|
130
|
+
case "range": {
|
|
131
|
+
const { min, max } = expr;
|
|
132
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);
|
|
133
|
+
return `${min}-${max}`;
|
|
134
|
+
}
|
|
135
|
+
case "step": {
|
|
136
|
+
const { step, range } = expr;
|
|
137
|
+
if (step === 0) throw new Error(`OutOfBoundError: Expected step value greater than zero`);
|
|
138
|
+
if (!range) return `*/${step}`;
|
|
139
|
+
const { min, max } = range;
|
|
140
|
+
if (max === 0) {
|
|
141
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected max value greater than zero`);
|
|
142
|
+
return `${min}-${max}/${step}`;
|
|
143
|
+
}
|
|
144
|
+
if (!max) return `${min}/${step}`;
|
|
145
|
+
if (min > max) throw new Error(`OutOfBoundError: Expected ${min} <= ${max}`);
|
|
146
|
+
return `${min}-${max}/${step}`;
|
|
147
|
+
}
|
|
148
|
+
default: return "*";
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function generate(fields) {
|
|
152
|
+
const parts = [];
|
|
153
|
+
for (let index = 0; index < CRON_FIELD_ORDER.length; index++) {
|
|
154
|
+
const key = CRON_FIELD_ORDER[index];
|
|
155
|
+
if (!key) return "";
|
|
156
|
+
if (key === "second" && !fields[key]) continue;
|
|
157
|
+
parts.push(fields[key] ?? "*");
|
|
158
|
+
}
|
|
159
|
+
return parts.join(" ");
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/lib/cron/builder/types.ts
|
|
163
|
+
const WeekDay = {
|
|
164
|
+
sun: 0,
|
|
165
|
+
mon: 1,
|
|
166
|
+
tue: 2,
|
|
167
|
+
wed: 3,
|
|
168
|
+
thu: 4,
|
|
169
|
+
fri: 5,
|
|
170
|
+
sat: 6
|
|
171
|
+
};
|
|
172
|
+
const Month = {
|
|
173
|
+
jan: 1,
|
|
174
|
+
feb: 2,
|
|
175
|
+
mar: 3,
|
|
176
|
+
apr: 4,
|
|
177
|
+
may: 5,
|
|
178
|
+
jun: 6,
|
|
179
|
+
jul: 7,
|
|
180
|
+
aug: 8,
|
|
181
|
+
sep: 9,
|
|
182
|
+
oct: 10,
|
|
183
|
+
nov: 11,
|
|
184
|
+
dec: 12
|
|
185
|
+
};
|
|
186
|
+
//#endregion
|
|
187
|
+
//#region src/lib/cron/core/scanner.ts
|
|
188
|
+
const FieldAmount = {
|
|
189
|
+
min: 5,
|
|
190
|
+
max: 6
|
|
191
|
+
};
|
|
192
|
+
var Token = class {
|
|
193
|
+
type;
|
|
194
|
+
component;
|
|
195
|
+
value;
|
|
196
|
+
field;
|
|
197
|
+
constructor(component, type, value, field) {
|
|
198
|
+
this.component = component;
|
|
199
|
+
this.type = type;
|
|
200
|
+
this.value = value;
|
|
201
|
+
this.field = field;
|
|
202
|
+
}
|
|
203
|
+
getComponent() {
|
|
204
|
+
return this.component;
|
|
205
|
+
}
|
|
206
|
+
getTokenType() {
|
|
207
|
+
return this.type;
|
|
208
|
+
}
|
|
209
|
+
getTokenValue() {
|
|
210
|
+
return this.value;
|
|
211
|
+
}
|
|
212
|
+
getField() {
|
|
213
|
+
return this.field;
|
|
214
|
+
}
|
|
215
|
+
toString() {
|
|
216
|
+
return `Token{${`component="${this.component}", type=${this.type}`}, ${`field="${this.field}", value=${this.value}`}}`;
|
|
217
|
+
}
|
|
218
|
+
equals(other) {
|
|
219
|
+
if (!other) return false;
|
|
220
|
+
const isComponentEqual = this.component === other.getComponent();
|
|
221
|
+
const isTokenTypeEqual = this.type === other.getTokenType();
|
|
222
|
+
const isTokenValueEqual = this.value === other.getTokenValue();
|
|
223
|
+
const isFieldEqual = this.field === other.getField();
|
|
224
|
+
return isComponentEqual && isTokenTypeEqual && isTokenValueEqual && isFieldEqual;
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
var Scanner = class {
|
|
228
|
+
expression;
|
|
229
|
+
current;
|
|
230
|
+
start;
|
|
231
|
+
tokens;
|
|
232
|
+
constructor(expression) {
|
|
233
|
+
this.expression = expression;
|
|
234
|
+
this.current = 0;
|
|
235
|
+
this.start = 0;
|
|
236
|
+
this.tokens = [];
|
|
237
|
+
}
|
|
238
|
+
scan() {
|
|
239
|
+
if (this.expression.length === 0) return err("EmptyCronExpressionError", "Cron expression have zero length");
|
|
240
|
+
const fields = this.expression.trim().split(/\s+/);
|
|
241
|
+
const hasMinLen = fields.length === FieldAmount.min;
|
|
242
|
+
const hasMaxLen = fields.length === FieldAmount.max;
|
|
243
|
+
if (!hasMinLen && !hasMaxLen) return err("CronLengthError", `Invalid number of fields for '${this.expression}'. Expected 5 or 6 fields but got ${fields.length} field(s)`);
|
|
244
|
+
const components = this.createComponent(fields);
|
|
245
|
+
for (let idx = 0; idx < components.length; idx++) {
|
|
246
|
+
const component = components[idx];
|
|
247
|
+
if (!component) return err("CronExpressionError", `Invalid cron expression: ${this.expression}`);
|
|
248
|
+
this.current = 0;
|
|
249
|
+
this.start = 0;
|
|
250
|
+
const [error, _] = this.scanComponent(component);
|
|
251
|
+
if (error) return err(error.type, error.message);
|
|
252
|
+
}
|
|
253
|
+
return ok(this.tokens);
|
|
254
|
+
}
|
|
255
|
+
scanComponent(component) {
|
|
256
|
+
const { field, content } = component;
|
|
257
|
+
while (this.current < content.length) {
|
|
258
|
+
let currentCh = this.advance(content);
|
|
259
|
+
switch (currentCh) {
|
|
260
|
+
case "*": {
|
|
261
|
+
const ch = this.peek(content);
|
|
262
|
+
if (this.match(content, "/")) {
|
|
263
|
+
const [error, _] = this.handleStep(component);
|
|
264
|
+
if (error) return err(error.type, error.message);
|
|
265
|
+
} else if (!ch || ch === ",") this.addToken("*", "any", "*", field);
|
|
266
|
+
else return err("CronExpressionError", `Invalid any expression '${content}' for field '${field}'`);
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
case "-":
|
|
270
|
+
currentCh = this.advance(content);
|
|
271
|
+
if (this.isDigit(currentCh)) {
|
|
272
|
+
const [error, _] = this.handleRangeWithStep(component);
|
|
273
|
+
if (error) return err(error.type, error.message);
|
|
274
|
+
} else return err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
275
|
+
break;
|
|
276
|
+
case ",": {
|
|
277
|
+
if (this.current === 1 && this.start === 0) return err("CronExpressionError", `Invalid list expression '${content}' for field '${field}'`);
|
|
278
|
+
const next = this.peek(content);
|
|
279
|
+
if (!next || next === ",") return err("CronExpressionError", `Invalid list expression '${content}' for field '${field}'`);
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
default:
|
|
283
|
+
if (this.isDigit(currentCh)) {
|
|
284
|
+
const [error, _] = this.handleNumber(component);
|
|
285
|
+
if (error) return err(error.type, error.message);
|
|
286
|
+
} else return err("CronExpressionError", `Invalid cron expression '${this.expression}' in field '${field}'`);
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
this.start = this.current;
|
|
290
|
+
}
|
|
291
|
+
return ok(true);
|
|
292
|
+
}
|
|
293
|
+
addToken(component, type, value, field) {
|
|
294
|
+
const token = new Token(component, type, value, field);
|
|
295
|
+
this.tokens.push(token);
|
|
296
|
+
}
|
|
297
|
+
advance(content) {
|
|
298
|
+
const currentCh = content.charAt(this.current);
|
|
299
|
+
this.current += 1;
|
|
300
|
+
return currentCh;
|
|
301
|
+
}
|
|
302
|
+
match(content, expected) {
|
|
303
|
+
if (this.current >= content.length) return false;
|
|
304
|
+
if (content.charAt(this.current) !== expected) return false;
|
|
305
|
+
this.current += 1;
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
peek(content) {
|
|
309
|
+
if (this.current >= content.length) return void 0;
|
|
310
|
+
return content.charAt(this.current);
|
|
311
|
+
}
|
|
312
|
+
handleStep(component) {
|
|
313
|
+
const { field, content } = component;
|
|
314
|
+
let ch = this.peek(content);
|
|
315
|
+
const slashIdx = this.current - 1;
|
|
316
|
+
while (ch && this.isDigit(ch)) {
|
|
317
|
+
this.advance(content);
|
|
318
|
+
ch = this.peek(content);
|
|
319
|
+
}
|
|
320
|
+
if (ch && ch !== ",") return err("CronExpressionError", `Invalid step expression '${content}' for field '${field}'`);
|
|
321
|
+
const tokenContent = content.substring(this.start, this.current);
|
|
322
|
+
const value = content.slice(slashIdx + 1, this.current);
|
|
323
|
+
if (value.length === 0) return err("CronExpressionError", `Invalid step expression '${content}' for field '${field}'`);
|
|
324
|
+
this.addToken(tokenContent, "step", Number(value), field);
|
|
325
|
+
return ok(true);
|
|
326
|
+
}
|
|
327
|
+
handleRangeWithStep(component) {
|
|
328
|
+
const { field, content } = component;
|
|
329
|
+
let ch = this.peek(content);
|
|
330
|
+
while (ch && this.isDigit(ch)) {
|
|
331
|
+
this.advance(content);
|
|
332
|
+
ch = this.peek(content);
|
|
333
|
+
}
|
|
334
|
+
if (!ch) return err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
335
|
+
if (this.match(content, "/")) {
|
|
336
|
+
const [error, _] = this.handleStep(component);
|
|
337
|
+
if (error) return err(error.type, error.message);
|
|
338
|
+
return ok(true);
|
|
339
|
+
}
|
|
340
|
+
return err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
341
|
+
}
|
|
342
|
+
handleNumber(component) {
|
|
343
|
+
const { field, content } = component;
|
|
344
|
+
let ch = this.peek(content);
|
|
345
|
+
this.start = this.current - 1;
|
|
346
|
+
while (ch && this.isDigit(ch)) {
|
|
347
|
+
this.advance(content);
|
|
348
|
+
ch = this.peek(content);
|
|
349
|
+
}
|
|
350
|
+
if (!ch) {
|
|
351
|
+
const item = content.substring(this.start);
|
|
352
|
+
this.addToken(item, "number", Number(item), field);
|
|
353
|
+
return ok(true);
|
|
354
|
+
}
|
|
355
|
+
if (this.match(content, "-")) {
|
|
356
|
+
const [error, _] = this.handleRange(component);
|
|
357
|
+
if (error) return err(error.type, error.message);
|
|
358
|
+
return ok(true);
|
|
359
|
+
}
|
|
360
|
+
if (this.match(content, "/")) {
|
|
361
|
+
const [error, _] = this.handleStep(component);
|
|
362
|
+
if (error) return err(error.type, error.message);
|
|
363
|
+
return ok(true);
|
|
364
|
+
}
|
|
365
|
+
if (!this.isDigit(ch) && ch !== ",") return err("CronExpressionError", `Invalid number '${content}' for field '${field}'`);
|
|
366
|
+
const item = content.substring(this.start, this.current);
|
|
367
|
+
this.addToken(item, "number", Number(item), field);
|
|
368
|
+
return ok(true);
|
|
369
|
+
}
|
|
370
|
+
handleRange(component) {
|
|
371
|
+
const { field, content } = component;
|
|
372
|
+
let ch = this.peek(content);
|
|
373
|
+
if (!ch) return err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
374
|
+
while (ch && this.isDigit(ch)) {
|
|
375
|
+
this.advance(content);
|
|
376
|
+
ch = this.peek(content);
|
|
377
|
+
}
|
|
378
|
+
if (!ch) {
|
|
379
|
+
const tokenContent = content.substring(this.start);
|
|
380
|
+
this.addToken(tokenContent, "range", tokenContent, field);
|
|
381
|
+
return ok(true);
|
|
382
|
+
}
|
|
383
|
+
if (this.match(content, "/")) {
|
|
384
|
+
const [error, _] = this.handleStep(component);
|
|
385
|
+
if (error) return err(error.type, error.message);
|
|
386
|
+
return ok(true);
|
|
387
|
+
}
|
|
388
|
+
if (ch && ch !== ",") return err("CronExpressionError", `Invalid range expression '${content}' for field '${field}'`);
|
|
389
|
+
const tokenContent = content.substring(this.start, this.current);
|
|
390
|
+
this.addToken(tokenContent, "range", tokenContent, field);
|
|
391
|
+
return ok(true);
|
|
392
|
+
}
|
|
393
|
+
isDigit(ch) {
|
|
394
|
+
return ch >= "0" && ch <= "9";
|
|
395
|
+
}
|
|
396
|
+
createComponent(fields) {
|
|
397
|
+
const fieldNames = [
|
|
398
|
+
"second",
|
|
399
|
+
"minute",
|
|
400
|
+
"hour",
|
|
401
|
+
"day",
|
|
402
|
+
"month",
|
|
403
|
+
"weekday"
|
|
404
|
+
];
|
|
405
|
+
const components = [];
|
|
406
|
+
let offset = 1;
|
|
407
|
+
if (fields.length === FieldAmount.max) offset = 0;
|
|
408
|
+
for (let idx = 0; idx < fields.length; idx++) {
|
|
409
|
+
const fieldName = fieldNames[idx + offset];
|
|
410
|
+
const content = fields[idx];
|
|
411
|
+
if (!fieldName || !content) break;
|
|
412
|
+
components.push({
|
|
413
|
+
content,
|
|
414
|
+
field: fieldName
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
return components;
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/lib/cron/core/index.ts
|
|
4
422
|
const RETRY_DELAY_MS = 3600 * 1e3;
|
|
423
|
+
const MAX_YEARS = 4;
|
|
5
424
|
const ALIASES = {
|
|
6
425
|
"@yearly": "0 0 1 1 *",
|
|
7
426
|
"@monthly": "0 0 1 * *",
|
|
@@ -206,7 +625,7 @@ var Cron = class {
|
|
|
206
625
|
return isSecondMatch && isMinuteMatch && isHourMatch && isDayOrDowMatch && isMonthMatch;
|
|
207
626
|
}
|
|
208
627
|
getNextRun() {
|
|
209
|
-
const date = /* @__PURE__ */ new Date(
|
|
628
|
+
const date = /* @__PURE__ */ new Date();
|
|
210
629
|
if (this.hasSeconds) {
|
|
211
630
|
date.setMilliseconds(0);
|
|
212
631
|
date.setSeconds(date.getSeconds() + 1);
|
|
@@ -214,13 +633,45 @@ var Cron = class {
|
|
|
214
633
|
date.setSeconds(0, 0);
|
|
215
634
|
date.setMinutes(date.getMinutes() + 1);
|
|
216
635
|
}
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
636
|
+
const deadline = new Date(date);
|
|
637
|
+
deadline.setFullYear(deadline.getFullYear() + MAX_YEARS);
|
|
638
|
+
while (date < deadline) {
|
|
639
|
+
const s = date.getSeconds();
|
|
640
|
+
const m = date.getMinutes();
|
|
641
|
+
const h = date.getHours();
|
|
642
|
+
const d = date.getDate();
|
|
643
|
+
const mon = date.getMonth();
|
|
644
|
+
const dow = date.getDay();
|
|
645
|
+
if (this.month[mon + 1] === 0) {
|
|
646
|
+
date.setDate(1);
|
|
647
|
+
date.setMonth(mon + 1);
|
|
648
|
+
date.setHours(0, 0, 0, 0);
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
let isDayOrDowMatch;
|
|
652
|
+
if (!this._dayWildcard && !this._dowWildcard) isDayOrDowMatch = this.day[d] === 0 && this.dayOfWeek[dow] === 0;
|
|
653
|
+
else isDayOrDowMatch = this.day[d] === 0 || this.dayOfWeek[dow] === 0;
|
|
654
|
+
if (isDayOrDowMatch) {
|
|
655
|
+
date.setDate(d + 1);
|
|
656
|
+
date.setHours(0, 0, 0, 0);
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
if (this.hour[h] === 0) {
|
|
660
|
+
date.setHours(h + 1);
|
|
661
|
+
date.setMinutes(0, 0, 0);
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
if (this.minute[m] === 0) {
|
|
665
|
+
date.setMinutes(m + 1);
|
|
666
|
+
date.setSeconds(0, 0);
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (this.hasSeconds && this.second[s] === 0) {
|
|
670
|
+
date.setSeconds(s + 1);
|
|
671
|
+
date.setMilliseconds(0);
|
|
672
|
+
continue;
|
|
221
673
|
}
|
|
222
|
-
|
|
223
|
-
else date.setMinutes(date.getMinutes() + 1);
|
|
674
|
+
return new Date(date);
|
|
224
675
|
}
|
|
225
676
|
return null;
|
|
226
677
|
}
|
|
@@ -272,6 +723,4 @@ var Cron = class {
|
|
|
272
723
|
}
|
|
273
724
|
};
|
|
274
725
|
//#endregion
|
|
275
|
-
export { Cron };
|
|
276
|
-
|
|
277
|
-
//# sourceMappingURL=index.mjs.map
|
|
726
|
+
export { Cron, Month, WeekDay, any, cronJobBuilder, list, number, range, step };
|
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/lib/errors/index.d.ts
|
|
4
|
-
declare const ok: <T>(data: T) => readonly [null, T];
|
|
5
|
-
declare const err: <T extends CommonError>(type: T, message: string) => readonly [{
|
|
6
|
-
readonly type: T;
|
|
7
|
-
readonly message: string;
|
|
8
|
-
}, null];
|
|
9
|
-
declare const mightThrowSync: <T>(fn: () => T) => readonly [unknown, null] | readonly [null, T];
|
|
10
|
-
declare const mightThrow: <T>(promise: Promise<T>) => Promise<readonly [null, Awaited<T>] | readonly [unknown, null]>;
|
|
11
|
-
//#endregion
|
|
12
|
-
export { err, mightThrow, mightThrowSync, ok };
|
|
13
|
-
//# sourceMappingURL=index.d.cts.map
|
|
1
|
+
import { i as ok, n as mightThrow, r as mightThrowSync, t as err } from "../../index-DxSbeGP-.cjs";
|
|
2
|
+
export { err, mightThrow, mightThrowSync, ok };
|
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/lib/errors/index.d.ts
|
|
4
|
-
declare const ok: <T>(data: T) => readonly [null, T];
|
|
5
|
-
declare const err: <T extends CommonError>(type: T, message: string) => readonly [{
|
|
6
|
-
readonly type: T;
|
|
7
|
-
readonly message: string;
|
|
8
|
-
}, null];
|
|
9
|
-
declare const mightThrowSync: <T>(fn: () => T) => readonly [unknown, null] | readonly [null, T];
|
|
10
|
-
declare const mightThrow: <T>(promise: Promise<T>) => Promise<readonly [null, Awaited<T>] | readonly [unknown, null]>;
|
|
11
|
-
//#endregion
|
|
12
|
-
export { err, mightThrow, mightThrowSync, ok };
|
|
13
|
-
//# sourceMappingURL=index.d.mts.map
|
|
1
|
+
import { i as ok, n as mightThrow, r as mightThrowSync, t as err } from "../../index-BhGNDjPq.mjs";
|
|
2
|
+
export { err, mightThrow, mightThrowSync, ok };
|
package/dist/lib/i18n/index.cjs
CHANGED
|
@@ -19,12 +19,17 @@ var I18n = class {
|
|
|
19
19
|
const currentTranslations = this.locales[this.currentLocale];
|
|
20
20
|
const defaultTranslations = this.locales[this.defaultLocale];
|
|
21
21
|
const translation = this.getNestedValue(currentTranslations, key) ?? this.getNestedValue(defaultTranslations, key);
|
|
22
|
+
if (typeof translation !== "string") return key;
|
|
22
23
|
if (!translation) return key;
|
|
23
24
|
const paramObj = params[0];
|
|
24
25
|
return this.substituteParams(translation, paramObj);
|
|
25
26
|
}
|
|
26
27
|
getNestedValue(obj, path) {
|
|
27
|
-
return path.split(".").reduce((current, key) =>
|
|
28
|
+
return path.split(".").reduce((current, key) => {
|
|
29
|
+
if (typeof current !== "object") return;
|
|
30
|
+
if (current === null) return;
|
|
31
|
+
return current[key];
|
|
32
|
+
}, obj);
|
|
28
33
|
}
|
|
29
34
|
substituteParams(template, params) {
|
|
30
35
|
if (!params) return template;
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/lib/i18n/types.d.ts
|
|
2
|
+
type ExtractParamType<T extends string> = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : never;
|
|
3
|
+
type BuildParamObject<T extends string, Acc = {}> = T extends `${infer _Start}{${infer Name}:${infer Type}}${infer Rest}` ? BuildParamObject<Rest, Acc & Record<Name, ExtractParamType<Type>>> : Acc;
|
|
4
|
+
type IsString<T> = T extends string ? true : false;
|
|
5
|
+
type IsArray<T> = T extends readonly unknown[] ? true : false;
|
|
6
|
+
type IsObject<T> = T extends object ? T extends readonly unknown[] ? false : true : false;
|
|
7
|
+
type ArrayKeys<T extends readonly unknown[]> = { [K in keyof T & `${number}`]: `${K}` }[keyof T & `${number}`];
|
|
8
|
+
type ObjectPropertyKeys<K extends string, V> = IsString<V> extends true ? K : IsArray<V> extends true ? V extends readonly unknown[] ? `${K}.${NestedKeyOf<V>}` : never : IsObject<V> extends true ? `${K}.${NestedKeyOf<V>}` : never;
|
|
9
|
+
type NestedKeyOf<T> = IsArray<T> extends true ? T extends readonly unknown[] ? ArrayKeys<T> : never : IsObject<T> extends true ? { [K in keyof T & string]: ObjectPropertyKeys<K, T[K]> }[keyof T & string] : never;
|
|
10
|
+
type GetNestedValue<T, K extends string> = K extends `${infer First}.${infer Rest}` ? First extends keyof T ? GetNestedValue<T[First], Rest> : never : K extends keyof T ? T[K] : never;
|
|
11
|
+
//#endregion
|
|
3
12
|
//#region src/lib/i18n/index.d.ts
|
|
4
13
|
declare class I18n<const TLocales extends Record<string, Record<string, unknown>>, TDefaultLocale extends keyof TLocales> {
|
|
5
14
|
private locales;
|
|
@@ -16,5 +25,4 @@ declare class I18n<const TLocales extends Record<string, Record<string, unknown>
|
|
|
16
25
|
private substituteParams;
|
|
17
26
|
}
|
|
18
27
|
//#endregion
|
|
19
|
-
export { I18n };
|
|
20
|
-
//# sourceMappingURL=index.d.cts.map
|
|
28
|
+
export { I18n };
|