@geekmidas/constructs 9.2.0 → 9.3.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/CHANGELOG.md +62 -0
- package/README.md +1 -1
- package/dist/{AWSScheduledFunction-B0thZRJU.d.cts → AWSScheduledFunction-DAGP_vz5.d.cts} +43 -11
- package/dist/AWSScheduledFunction-DAGP_vz5.d.cts.map +1 -0
- package/dist/{AWSScheduledFunction-a6hRp3nk.d.mts → AWSScheduledFunction-Dg6TPIxn.d.mts} +42 -10
- package/dist/AWSScheduledFunction-Dg6TPIxn.d.mts.map +1 -0
- package/dist/{Endpoint-BmnuNbF1.d.cts → Endpoint-CxBdXNZm.d.cts} +2 -2
- package/dist/{Endpoint-BmnuNbF1.d.cts.map → Endpoint-CxBdXNZm.d.cts.map} +1 -1
- package/dist/Endpoint-DEydLuBs.d.mts.map +1 -1
- package/dist/{HonoEndpointAdaptor-Dd-S7gV_.mjs → HonoEndpointAdaptor-CJfFQ5KR.mjs} +2 -2
- package/dist/{HonoEndpointAdaptor-Dd-S7gV_.mjs.map → HonoEndpointAdaptor-CJfFQ5KR.mjs.map} +1 -1
- package/dist/{HonoEndpointAdaptor-INisd3XZ.cjs → HonoEndpointAdaptor-DCD0rhFg.cjs} +2 -2
- package/dist/{HonoEndpointAdaptor-INisd3XZ.cjs.map → HonoEndpointAdaptor-DCD0rhFg.cjs.map} +1 -1
- package/dist/adaptors/aws.cjs +8 -7
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +3 -3
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +1 -1
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +9 -8
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/hono.cjs +2 -2
- package/dist/adaptors/hono.d.cts +2 -2
- package/dist/adaptors/hono.mjs +2 -2
- package/dist/adaptors/testing.cjs +2 -2
- package/dist/adaptors/testing.d.cts +2 -2
- package/dist/adaptors/testing.mjs +2 -2
- package/dist/crons/index.cjs +4 -0
- package/dist/crons/index.cjs.map +1 -1
- package/dist/crons/index.d.cts +8 -4
- package/dist/crons/index.d.cts.map +1 -1
- package/dist/crons/index.d.mts +7 -3
- package/dist/crons/index.d.mts.map +1 -1
- package/dist/crons/index.mjs +4 -0
- package/dist/crons/index.mjs.map +1 -1
- package/dist/endpoints/index.cjs +1 -1
- package/dist/endpoints/index.d.cts +4 -4
- package/dist/endpoints/index.mjs +1 -1
- package/dist/functions/index.d.cts +1 -1
- package/dist/{index-HWHPZv8u.d.cts → index-CeoLMr7c.d.cts} +5 -5
- package/dist/{index-HWHPZv8u.d.cts.map → index-CeoLMr7c.d.cts.map} +1 -1
- package/dist/lazyAccessors-C1n1QfEj.cjs +653 -0
- package/dist/lazyAccessors-C1n1QfEj.cjs.map +1 -0
- package/dist/lazyAccessors-fFIQrblM.mjs +594 -0
- package/dist/lazyAccessors-fFIQrblM.mjs.map +1 -0
- package/dist/monitors/index.cjs +1 -1
- package/dist/monitors/index.cjs.map +1 -1
- package/dist/monitors/index.d.cts +1 -1
- package/dist/monitors/index.d.mts +1 -1
- package/dist/monitors/index.mjs +1 -1
- package/dist/monitors/index.mjs.map +1 -1
- package/package.json +23 -27
- package/src/__tests__/Construct.environment.spec.ts +2 -2
- package/src/__tests__/builder-reuse.spec.ts +2 -2
- package/src/__tests__/monitor.spec.ts +16 -16
- package/src/crons/Cron.ts +187 -60
- package/src/crons/CronBuilder.ts +10 -4
- package/src/crons/__tests__/AWSScheduledFunction.spec.ts +8 -6
- package/src/crons/__tests__/Cron.spec.ts +53 -91
- package/src/crons/__tests__/CronBuilder.state-isolation.spec.ts +28 -28
- package/src/crons/index.ts +2 -1
- package/src/endpoints/AmazonApiGatewayEndpointAdaptor.ts +7 -15
- package/src/endpoints/Endpoint.ts +12 -15
- package/src/monitors/heartbeat.ts +1 -1
- package/tsdown.config.ts +1 -7
- package/dist/AWSScheduledFunction-B0thZRJU.d.cts.map +0 -1
- package/dist/AWSScheduledFunction-a6hRp3nk.d.mts.map +0 -1
- package/dist/lazyAccessors-DzxZVtPR.mjs +0 -1855
- package/dist/lazyAccessors-DzxZVtPR.mjs.map +0 -1
- package/dist/lazyAccessors-iwvg1Pv4.cjs +0 -1920
- package/dist/lazyAccessors-iwvg1Pv4.cjs.map +0 -1
package/src/crons/Cron.ts
CHANGED
|
@@ -73,45 +73,94 @@ export class Cron<
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
// ---- Cron expression types ------------------------------------------------
|
|
77
|
+
//
|
|
78
|
+
// `.schedule()` takes a `cron(…)` in either of two dialects, told apart by the
|
|
79
|
+
// field count, and checks each by its own rules:
|
|
80
|
+
//
|
|
81
|
+
// - Unix, five fields: `min hour day-of-month month day-of-week`, with
|
|
82
|
+
// day-of-week 0–7 (SUN = 0 or 7) and no `?`.
|
|
83
|
+
// - AWS, six fields: `min hour day-of-month month day-of-week year`, with
|
|
84
|
+
// day-of-week 1–7 (SUN = 1), `?` in exactly one day field, and `L`, `W`
|
|
85
|
+
// and `#` where EventBridge allows them.
|
|
86
|
+
//
|
|
87
|
+
// The types are generic because a plain union of every field's forms is too
|
|
88
|
+
// large for TypeScript, so the literal is checked field by field instead.
|
|
89
|
+
// `@geekmidas/manifest`'s `parseCron` applies the same rules at build time.
|
|
77
90
|
|
|
78
|
-
type
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
91
|
+
type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
|
|
92
|
+
|
|
93
|
+
/** `'0'`…`'99'`, with an optional leading zero (`'08'`). */
|
|
94
|
+
type UpTo99 = Digit | `${Digit}${Digit}`;
|
|
95
|
+
|
|
96
|
+
type ToNumber<S extends string> = S extends `0${infer R extends `${number}`}`
|
|
97
|
+
? R extends ''
|
|
98
|
+
? 0
|
|
99
|
+
: ToNumber<R>
|
|
100
|
+
: S extends `${infer N extends number}`
|
|
101
|
+
? N
|
|
102
|
+
: never;
|
|
103
|
+
|
|
104
|
+
type Range<
|
|
105
|
+
N extends number,
|
|
106
|
+
Acc extends number[] = [],
|
|
107
|
+
> = Acc['length'] extends N ? Acc[number] : Range<N, [...Acc, Acc['length']]>;
|
|
108
|
+
|
|
109
|
+
/** Numbers from `Min` to `Max` inclusive. */
|
|
110
|
+
type Between<Min extends number, Max extends number> =
|
|
111
|
+
| Exclude<Range<Max>, Range<Min>>
|
|
112
|
+
| Max;
|
|
113
|
+
|
|
114
|
+
/** A single value: a number in range, or one of the field's names. */
|
|
115
|
+
type IsValue<
|
|
116
|
+
S extends string,
|
|
117
|
+
Min extends number,
|
|
118
|
+
Max extends number,
|
|
119
|
+
Names extends string,
|
|
120
|
+
> = S extends Names
|
|
121
|
+
? true
|
|
122
|
+
: S extends UpTo99
|
|
123
|
+
? ToNumber<S> extends Between<Min, Max>
|
|
124
|
+
? true
|
|
125
|
+
: false
|
|
126
|
+
: false;
|
|
127
|
+
|
|
128
|
+
/** `v`, `a-b` or `*`, with an optional `/step`. */
|
|
129
|
+
type IsAtom<
|
|
130
|
+
S extends string,
|
|
131
|
+
Min extends number,
|
|
132
|
+
Max extends number,
|
|
133
|
+
Names extends string,
|
|
134
|
+
> = S extends `${infer Base}/${infer Step}`
|
|
135
|
+
? Step extends UpTo99
|
|
136
|
+
? Base extends '*'
|
|
137
|
+
? true
|
|
138
|
+
: IsAtom<Base, Min, Max, Names>
|
|
139
|
+
: false
|
|
140
|
+
: S extends '*'
|
|
141
|
+
? true
|
|
142
|
+
: S extends `${infer A}-${infer B}`
|
|
143
|
+
? [IsValue<A, Min, Max, Names>, IsValue<B, Min, Max, Names>] extends [
|
|
144
|
+
true,
|
|
145
|
+
true,
|
|
146
|
+
]
|
|
147
|
+
? true
|
|
148
|
+
: false
|
|
149
|
+
: IsValue<S, Min, Max, Names>;
|
|
150
|
+
|
|
151
|
+
/** A comma-separated list of atoms. */
|
|
152
|
+
type IsField<
|
|
153
|
+
S extends string,
|
|
154
|
+
Min extends number,
|
|
155
|
+
Max extends number,
|
|
156
|
+
Names extends string = never,
|
|
157
|
+
> = S extends `${infer Head},${infer Rest}`
|
|
158
|
+
? IsAtom<Head, Min, Max, Names> extends true
|
|
159
|
+
? IsField<Rest, Min, Max, Names>
|
|
160
|
+
: false
|
|
161
|
+
: IsAtom<S, Min, Max, Names>;
|
|
162
|
+
|
|
163
|
+
type MonthName =
|
|
115
164
|
| 'JAN'
|
|
116
165
|
| 'FEB'
|
|
117
166
|
| 'MAR'
|
|
@@ -123,27 +172,105 @@ type CronMonth =
|
|
|
123
172
|
| 'SEP'
|
|
124
173
|
| 'OCT'
|
|
125
174
|
| 'NOV'
|
|
126
|
-
| 'DEC'
|
|
127
|
-
|
|
175
|
+
| 'DEC';
|
|
176
|
+
type DayName = 'SUN' | 'MON' | 'TUE' | 'WED' | 'THU' | 'FRI' | 'SAT';
|
|
128
177
|
|
|
129
|
-
type
|
|
178
|
+
type AllTrue<T extends boolean[]> = T extends true[] ? true : false;
|
|
179
|
+
|
|
180
|
+
type IsUnix<S extends string> =
|
|
181
|
+
S extends `${infer Mi} ${infer H} ${infer Dom} ${infer Mo} ${infer Dow}`
|
|
182
|
+
? AllTrue<
|
|
183
|
+
[
|
|
184
|
+
IsField<Mi, 0, 59>,
|
|
185
|
+
IsField<H, 0, 23>,
|
|
186
|
+
IsField<Dom, 1, 31>,
|
|
187
|
+
IsField<Mo, 1, 12, MonthName>,
|
|
188
|
+
IsField<Dow, 0, 7, DayName>,
|
|
189
|
+
]
|
|
190
|
+
>
|
|
191
|
+
: false;
|
|
192
|
+
|
|
193
|
+
type IsAwsDayOfMonth<S extends string> = S extends 'L' | `L-${UpTo99}` | 'LW'
|
|
194
|
+
? true
|
|
195
|
+
: S extends `${infer D}W`
|
|
196
|
+
? IsValue<D, 1, 31, never>
|
|
197
|
+
: IsField<S, 1, 31>;
|
|
198
|
+
|
|
199
|
+
type IsAwsDayOfWeek<S extends string> = S extends `${infer D}L`
|
|
200
|
+
? IsValue<D, 1, 7, DayName>
|
|
201
|
+
: S extends `${infer D}#${infer N}`
|
|
202
|
+
? AllTrue<[IsValue<D, 1, 7, DayName>, IsValue<N, 1, 5, never>]>
|
|
203
|
+
: IsField<S, 1, 7, DayName>;
|
|
204
|
+
|
|
205
|
+
/** 1970–2199, EventBridge's range. */
|
|
206
|
+
type Year = `19${'7' | '8' | '9'}${Digit}` | `${'20' | '21'}${Digit}${Digit}`;
|
|
207
|
+
|
|
208
|
+
type IsYearAtom<S extends string> = S extends
|
|
130
209
|
| '*'
|
|
131
|
-
|
|
|
132
|
-
| `${
|
|
133
|
-
| `${
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
210
|
+
| Year
|
|
211
|
+
| `${'*' | Year}/${UpTo99}`
|
|
212
|
+
| `${Year}-${Year}`
|
|
213
|
+
? true
|
|
214
|
+
: false;
|
|
215
|
+
|
|
216
|
+
type IsAwsYear<S extends string> = S extends `${infer Head},${infer Rest}`
|
|
217
|
+
? IsYearAtom<Head> extends true
|
|
218
|
+
? IsAwsYear<Rest>
|
|
219
|
+
: false
|
|
220
|
+
: IsYearAtom<S>;
|
|
221
|
+
|
|
222
|
+
type IsAws<S extends string> =
|
|
223
|
+
S extends `${infer Mi} ${infer H} ${infer Dom} ${infer Mo} ${infer Dow} ${infer Y}`
|
|
224
|
+
? AllTrue<
|
|
225
|
+
[
|
|
226
|
+
IsField<Mi, 0, 59>,
|
|
227
|
+
IsField<H, 0, 23>,
|
|
228
|
+
IsField<Mo, 1, 12, MonthName>,
|
|
229
|
+
IsAwsYear<Y>,
|
|
230
|
+
Dom extends '?'
|
|
231
|
+
? Dow extends '?'
|
|
232
|
+
? false
|
|
233
|
+
: IsAwsDayOfWeek<Dow>
|
|
234
|
+
: Dow extends '?'
|
|
235
|
+
? IsAwsDayOfMonth<Dom>
|
|
236
|
+
: false,
|
|
237
|
+
]
|
|
238
|
+
>
|
|
239
|
+
: false;
|
|
240
|
+
|
|
241
|
+
/** `T` when it is a valid five-field Unix `cron(…)`. */
|
|
242
|
+
export type UnixCronExpression<T extends string> = T extends `cron(${infer S})`
|
|
243
|
+
? IsUnix<S> extends true
|
|
244
|
+
? T
|
|
245
|
+
: never
|
|
246
|
+
: never;
|
|
247
|
+
|
|
248
|
+
/** `T` when it is a valid six-field AWS (EventBridge) `cron(…)`. */
|
|
249
|
+
export type AwsCronExpression<T extends string> = T extends `cron(${infer S})`
|
|
250
|
+
? IsAws<S> extends true
|
|
251
|
+
? T
|
|
252
|
+
: never
|
|
253
|
+
: never;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* `T` when it is a valid cron expression in either dialect, otherwise a
|
|
257
|
+
* message saying what's expected. A schedule built at runtime can be cast to
|
|
258
|
+
* {@link ScheduleExpression}, which `gkm build` then checks.
|
|
259
|
+
*/
|
|
260
|
+
export type CronExpression<T extends string> = [T] extends [ScheduleExpression]
|
|
261
|
+
? [ScheduleExpression] extends [T]
|
|
262
|
+
? T
|
|
263
|
+
: CheckedCronExpression<T>
|
|
264
|
+
: CheckedCronExpression<T>;
|
|
265
|
+
|
|
266
|
+
type CheckedCronExpression<T extends string> = [
|
|
267
|
+
UnixCronExpression<T> | AwsCronExpression<T>,
|
|
268
|
+
] extends [never]
|
|
269
|
+
? 'Expected cron(…) with 5 fields (Unix) or 6 fields (AWS)'
|
|
270
|
+
: T;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* A cron's schedule once set. Literals are checked by {@link CronExpression};
|
|
274
|
+
* every schedule is checked again by `gkm build`.
|
|
275
|
+
*/
|
|
276
|
+
export type ScheduleExpression = `cron(${string})`;
|
package/src/crons/CronBuilder.ts
CHANGED
|
@@ -7,7 +7,7 @@ import uniqBy from 'lodash.uniqby';
|
|
|
7
7
|
import { ConstructType } from '../Construct';
|
|
8
8
|
import { cloneWith } from '../clone';
|
|
9
9
|
import { FunctionBuilder, type FunctionHandler } from '../functions';
|
|
10
|
-
import { Cron, type ScheduleExpression } from './Cron';
|
|
10
|
+
import { Cron, type CronExpression, type ScheduleExpression } from './Cron';
|
|
11
11
|
|
|
12
12
|
export class CronBuilder<
|
|
13
13
|
TInput extends ComposableStandardSchema,
|
|
@@ -40,8 +40,12 @@ export class CronBuilder<
|
|
|
40
40
|
return cloneWith(this, { _memorySize: memorySize });
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
/**
|
|
44
|
+
* When the cron runs: a five-field Unix `cron(…)` or a six-field AWS one.
|
|
45
|
+
* `gkm build` writes it to the manifest in the AWS form.
|
|
46
|
+
*/
|
|
47
|
+
schedule<const T extends string>(
|
|
48
|
+
_expression: CronExpression<T>,
|
|
45
49
|
): CronBuilder<
|
|
46
50
|
TInput,
|
|
47
51
|
TServices,
|
|
@@ -52,7 +56,9 @@ export class CronBuilder<
|
|
|
52
56
|
TDatabase,
|
|
53
57
|
TDatabaseServiceName
|
|
54
58
|
> {
|
|
55
|
-
return cloneWith(this, {
|
|
59
|
+
return cloneWith(this, {
|
|
60
|
+
_schedule: _expression as ScheduleExpression,
|
|
61
|
+
});
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
override input<T extends ComposableStandardSchema>(
|
|
@@ -77,9 +77,11 @@ describe('AWSScheduledFunction', () => {
|
|
|
77
77
|
|
|
78
78
|
it('runs the cron handler on a scheduled event', async () => {
|
|
79
79
|
const ran = vi.fn();
|
|
80
|
-
const cron = new CronBuilder()
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
const cron = new CronBuilder()
|
|
81
|
+
.schedule('cron(0 0 * * *)')
|
|
82
|
+
.handle(async () => {
|
|
83
|
+
ran();
|
|
84
|
+
});
|
|
83
85
|
|
|
84
86
|
const adapter = new AWSScheduledFunction(envParser, cron);
|
|
85
87
|
const result = await adapter.handler(
|
|
@@ -96,7 +98,7 @@ describe('AWSScheduledFunction', () => {
|
|
|
96
98
|
|
|
97
99
|
it('parses and returns output when the cron declares an output schema', async () => {
|
|
98
100
|
const cron = new CronBuilder()
|
|
99
|
-
.schedule('
|
|
101
|
+
.schedule('cron(0 0 * * *)')
|
|
100
102
|
.output(z.object({ cancelled: z.number() }))
|
|
101
103
|
.handle(async () => ({ cancelled: 3 }));
|
|
102
104
|
|
|
@@ -113,7 +115,7 @@ describe('AWSScheduledFunction', () => {
|
|
|
113
115
|
it('exposes services to the cron handler', async () => {
|
|
114
116
|
let observed = 0;
|
|
115
117
|
const cron = new CronBuilder()
|
|
116
|
-
.schedule('
|
|
118
|
+
.schedule('cron(0 * * * *)')
|
|
117
119
|
.services([new CounterService()])
|
|
118
120
|
.handle(async ({ services }) => {
|
|
119
121
|
observed = services.counter.increment();
|
|
@@ -134,7 +136,7 @@ describe('AWSScheduledFunction', () => {
|
|
|
134
136
|
const logger = makeSpyLogger();
|
|
135
137
|
|
|
136
138
|
const cron = new CronBuilder()
|
|
137
|
-
.schedule('
|
|
139
|
+
.schedule('cron(0 0 * * *)')
|
|
138
140
|
.logger(logger)
|
|
139
141
|
.handle(async () => {
|
|
140
142
|
hadContext = serviceContext.hasContext();
|
|
@@ -3,7 +3,7 @@ import type { Service } from '@geekmidas/services';
|
|
|
3
3
|
import { describe, expect, it, vi } from 'vitest';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { ConstructType } from '../../Construct';
|
|
6
|
-
import { Cron, type
|
|
6
|
+
import { Cron, type ScheduleExpression } from '../Cron';
|
|
7
7
|
import { CronBuilder } from '../CronBuilder';
|
|
8
8
|
|
|
9
9
|
// Mock service for testing
|
|
@@ -41,7 +41,7 @@ describe('Cron', () => {
|
|
|
41
41
|
|
|
42
42
|
it('should create a Cron instance with schedule expression', () => {
|
|
43
43
|
const handler = vi.fn();
|
|
44
|
-
const schedule:
|
|
44
|
+
const schedule: ScheduleExpression = 'cron(0 12 * * MON)';
|
|
45
45
|
const cron = new Cron(handler, undefined, schedule);
|
|
46
46
|
|
|
47
47
|
expect(cron).toBeInstanceOf(Cron);
|
|
@@ -134,7 +134,7 @@ describe('Cron', () => {
|
|
|
134
134
|
it('should create a Cron with all parameters', () => {
|
|
135
135
|
const inputSchema = z.object({ name: z.string() });
|
|
136
136
|
const outputSchema = z.object({ greeting: z.string() });
|
|
137
|
-
const schedule:
|
|
137
|
+
const schedule: ScheduleExpression = 'cron(*/5 * * * *)';
|
|
138
138
|
const timeout = 60000;
|
|
139
139
|
const service = new MockService();
|
|
140
140
|
const logger = new ConsoleLogger();
|
|
@@ -207,7 +207,7 @@ describe('Cron', () => {
|
|
|
207
207
|
|
|
208
208
|
it('should set schedule with schedule() method', () => {
|
|
209
209
|
const builder = new CronBuilder();
|
|
210
|
-
const schedule:
|
|
210
|
+
const schedule: ScheduleExpression = 'cron(0 0 * * SUN)';
|
|
211
211
|
|
|
212
212
|
const result = builder.schedule(schedule);
|
|
213
213
|
|
|
@@ -231,7 +231,7 @@ describe('Cron', () => {
|
|
|
231
231
|
it('should build Cron with full builder chain', () => {
|
|
232
232
|
const inputSchema = z.object({ task: z.string() });
|
|
233
233
|
const outputSchema = z.object({ completed: z.boolean() });
|
|
234
|
-
const schedule:
|
|
234
|
+
const schedule: ScheduleExpression = 'cron(0 * * * *)';
|
|
235
235
|
const service = new MockService();
|
|
236
236
|
const logger = new ConsoleLogger();
|
|
237
237
|
|
|
@@ -259,7 +259,7 @@ describe('Cron', () => {
|
|
|
259
259
|
|
|
260
260
|
it('should support method chaining in any order', () => {
|
|
261
261
|
const builder = new CronBuilder();
|
|
262
|
-
const schedule:
|
|
262
|
+
const schedule: ScheduleExpression = 'cron(30 2 * * TUE)';
|
|
263
263
|
|
|
264
264
|
const chained = builder
|
|
265
265
|
.timeout(30000)
|
|
@@ -274,90 +274,52 @@ describe('Cron', () => {
|
|
|
274
274
|
});
|
|
275
275
|
|
|
276
276
|
describe('Schedule Expression Types', () => {
|
|
277
|
-
it('
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
it('should handle all month names', () => {
|
|
325
|
-
const months: CronExpression[] = [
|
|
326
|
-
'cron(0 0 1 JAN *)',
|
|
327
|
-
'cron(0 0 1 FEB *)',
|
|
328
|
-
'cron(0 0 1 MAR *)',
|
|
329
|
-
'cron(0 0 1 APR *)',
|
|
330
|
-
'cron(0 0 1 MAY *)',
|
|
331
|
-
'cron(0 0 1 JUN *)',
|
|
332
|
-
'cron(0 0 1 JUL *)',
|
|
333
|
-
'cron(0 0 1 AUG *)',
|
|
334
|
-
'cron(0 0 1 SEP *)',
|
|
335
|
-
'cron(0 0 1 OCT *)',
|
|
336
|
-
'cron(0 0 1 NOV *)',
|
|
337
|
-
'cron(0 0 1 DEC *)',
|
|
338
|
-
];
|
|
339
|
-
|
|
340
|
-
months.forEach((expression) => {
|
|
341
|
-
const builder = new CronBuilder();
|
|
342
|
-
expect(() => builder.schedule(expression)).not.toThrow();
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
it('should handle all weekday names', () => {
|
|
347
|
-
const weekdays: CronExpression[] = [
|
|
348
|
-
'cron(0 0 * * SUN)',
|
|
349
|
-
'cron(0 0 * * MON)',
|
|
350
|
-
'cron(0 0 * * TUE)',
|
|
351
|
-
'cron(0 0 * * WED)',
|
|
352
|
-
'cron(0 0 * * THU)',
|
|
353
|
-
'cron(0 0 * * FRI)',
|
|
354
|
-
'cron(0 0 * * SAT)',
|
|
355
|
-
];
|
|
356
|
-
|
|
357
|
-
weekdays.forEach((expression) => {
|
|
358
|
-
const builder = new CronBuilder();
|
|
359
|
-
expect(() => builder.schedule(expression)).not.toThrow();
|
|
360
|
-
});
|
|
277
|
+
it('accepts Unix and AWS literals and rejects invalid ones', () => {
|
|
278
|
+
const c = new CronBuilder();
|
|
279
|
+
|
|
280
|
+
c.schedule('cron(0 8 * * *)');
|
|
281
|
+
c.schedule('cron(0 9 * * MON-FRI)');
|
|
282
|
+
c.schedule('cron(0 9 1 * MON)');
|
|
283
|
+
c.schedule('cron(0 0 * * 7)');
|
|
284
|
+
c.schedule('cron(0 8 * * ? *)');
|
|
285
|
+
c.schedule('cron(0 9 ? * MON-FRI *)');
|
|
286
|
+
c.schedule('cron(0 9 L * ? *)');
|
|
287
|
+
c.schedule('cron(0 9 15W * ? *)');
|
|
288
|
+
c.schedule('cron(0 9 ? * 6#3 *)');
|
|
289
|
+
c.schedule('cron(0 9 ? * FRIL 2026-2027)');
|
|
290
|
+
|
|
291
|
+
// @ts-expect-error 4 fields
|
|
292
|
+
c.schedule('cron(0 8 * *)');
|
|
293
|
+
// @ts-expect-error 7 fields
|
|
294
|
+
c.schedule('cron(0 0 8 * * ? *)');
|
|
295
|
+
// @ts-expect-error `?` is AWS, not Unix
|
|
296
|
+
c.schedule('cron(0 8 * * ?)');
|
|
297
|
+
// @ts-expect-error AWS needs `?` in one day field
|
|
298
|
+
c.schedule('cron(0 8 * * * *)');
|
|
299
|
+
// @ts-expect-error AWS with `?` in both day fields
|
|
300
|
+
c.schedule('cron(0 8 ? * ? *)');
|
|
301
|
+
// @ts-expect-error AWS with both day fields restricted
|
|
302
|
+
c.schedule('cron(0 9 1 * MON *)');
|
|
303
|
+
// @ts-expect-error AWS day-of-week is 1-7
|
|
304
|
+
c.schedule('cron(0 9 ? * 0 *)');
|
|
305
|
+
// @ts-expect-error hour 25
|
|
306
|
+
c.schedule('cron(0 25 * * *)');
|
|
307
|
+
// @ts-expect-error minute 60
|
|
308
|
+
c.schedule('cron(60 * * * ? *)');
|
|
309
|
+
// @ts-expect-error `L` is AWS only
|
|
310
|
+
c.schedule('cron(0 9 L * *)');
|
|
311
|
+
// @ts-expect-error rate() is not supported
|
|
312
|
+
c.schedule('rate(1 day)');
|
|
313
|
+
// @ts-expect-error double space
|
|
314
|
+
c.schedule('cron(0 8 * * *)');
|
|
315
|
+
// @ts-expect-error not a month
|
|
316
|
+
c.schedule('cron(0 8 * FOO *)');
|
|
317
|
+
// @ts-expect-error a year before 1970
|
|
318
|
+
c.schedule('cron(0 8 * * ? 1969)');
|
|
319
|
+
// @ts-expect-error a plain string needs a cast
|
|
320
|
+
c.schedule('cron(0 8 * * *)' as string);
|
|
321
|
+
// A runtime schedule cast to ScheduleExpression is checked at build.
|
|
322
|
+
c.schedule('cron(0 8 * * *)' as ScheduleExpression);
|
|
361
323
|
});
|
|
362
324
|
});
|
|
363
325
|
|
|
@@ -454,7 +416,7 @@ describe('Cron', () => {
|
|
|
454
416
|
|
|
455
417
|
const cron1 = new CronBuilder()
|
|
456
418
|
.timeout(1000)
|
|
457
|
-
.schedule('
|
|
419
|
+
.schedule('cron(*/5 * * * *)')
|
|
458
420
|
.handle(handler1);
|
|
459
421
|
|
|
460
422
|
const cron2 = new CronBuilder()
|