@geekmidas/cli 0.10.0 → 0.12.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/README.md +525 -0
- package/dist/bundler-DRXCw_YR.mjs +70 -0
- package/dist/bundler-DRXCw_YR.mjs.map +1 -0
- package/dist/bundler-WsEvH_b2.cjs +71 -0
- package/dist/bundler-WsEvH_b2.cjs.map +1 -0
- package/dist/{config-C9aXOHBe.cjs → config-AmInkU7k.cjs} +8 -8
- package/dist/config-AmInkU7k.cjs.map +1 -0
- package/dist/{config-BrkUalUh.mjs → config-DYULeEv8.mjs} +3 -3
- package/dist/config-DYULeEv8.mjs.map +1 -0
- package/dist/config.cjs +1 -1
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/encryption-C8H-38Yy.mjs +42 -0
- package/dist/encryption-C8H-38Yy.mjs.map +1 -0
- package/dist/encryption-Dyf_r1h-.cjs +44 -0
- package/dist/encryption-Dyf_r1h-.cjs.map +1 -0
- package/dist/index.cjs +2116 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2134 -192
- package/dist/index.mjs.map +1 -1
- package/dist/{openapi-CZLI4QTr.mjs → openapi-BfFlOBCG.mjs} +801 -38
- package/dist/openapi-BfFlOBCG.mjs.map +1 -0
- package/dist/{openapi-BeHLKcwP.cjs → openapi-Bt_1FDpT.cjs} +794 -31
- package/dist/openapi-Bt_1FDpT.cjs.map +1 -0
- package/dist/{openapi-react-query-o5iMi8tz.cjs → openapi-react-query-B-sNWHFU.cjs} +5 -5
- package/dist/openapi-react-query-B-sNWHFU.cjs.map +1 -0
- package/dist/{openapi-react-query-CcciaVu5.mjs → openapi-react-query-B6XTeGqS.mjs} +5 -5
- package/dist/openapi-react-query-B6XTeGqS.mjs.map +1 -0
- package/dist/openapi-react-query.cjs +1 -1
- package/dist/openapi-react-query.d.cts.map +1 -1
- package/dist/openapi-react-query.d.mts.map +1 -1
- package/dist/openapi-react-query.mjs +1 -1
- package/dist/openapi.cjs +2 -2
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.cts.map +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +2 -2
- package/dist/storage-BUYQJgz7.cjs +4 -0
- package/dist/storage-BXoJvmv2.cjs +149 -0
- package/dist/storage-BXoJvmv2.cjs.map +1 -0
- package/dist/storage-C9PU_30f.mjs +101 -0
- package/dist/storage-C9PU_30f.mjs.map +1 -0
- package/dist/storage-DLJAYxzJ.mjs +3 -0
- package/dist/{types-b-vwGpqc.d.cts → types-BR0M2v_c.d.mts} +100 -1
- package/dist/types-BR0M2v_c.d.mts.map +1 -0
- package/dist/{types-DXgiA1sF.d.mts → types-BhkZc-vm.d.cts} +100 -1
- package/dist/types-BhkZc-vm.d.cts.map +1 -0
- package/examples/cron-example.ts +27 -27
- package/examples/env.ts +27 -27
- package/examples/function-example.ts +31 -31
- package/examples/gkm.config.json +20 -20
- package/examples/gkm.config.ts +8 -8
- package/examples/gkm.minimal.config.json +5 -5
- package/examples/gkm.production.config.json +25 -25
- package/examples/logger.ts +2 -2
- package/package.json +6 -6
- package/src/__tests__/EndpointGenerator.hooks.spec.ts +191 -191
- package/src/__tests__/config.spec.ts +55 -55
- package/src/__tests__/loadEnvFiles.spec.ts +93 -93
- package/src/__tests__/normalizeHooksConfig.spec.ts +58 -58
- package/src/__tests__/openapi-react-query.spec.ts +497 -497
- package/src/__tests__/openapi.spec.ts +428 -428
- package/src/__tests__/test-helpers.ts +76 -76
- package/src/auth/__tests__/credentials.spec.ts +204 -0
- package/src/auth/__tests__/index.spec.ts +168 -0
- package/src/auth/credentials.ts +187 -0
- package/src/auth/index.ts +226 -0
- package/src/build/__tests__/index-new.spec.ts +474 -474
- package/src/build/__tests__/manifests.spec.ts +333 -333
- package/src/build/bundler.ts +141 -0
- package/src/build/endpoint-analyzer.ts +236 -0
- package/src/build/handler-templates.ts +1253 -0
- package/src/build/index.ts +250 -179
- package/src/build/manifests.ts +52 -52
- package/src/build/providerResolver.ts +145 -145
- package/src/build/types.ts +64 -43
- package/src/config.ts +39 -39
- package/src/deploy/__tests__/docker.spec.ts +111 -0
- package/src/deploy/__tests__/dokploy.spec.ts +245 -0
- package/src/deploy/__tests__/init.spec.ts +662 -0
- package/src/deploy/docker.ts +128 -0
- package/src/deploy/dokploy.ts +204 -0
- package/src/deploy/index.ts +136 -0
- package/src/deploy/init.ts +484 -0
- package/src/deploy/types.ts +48 -0
- package/src/dev/__tests__/index.spec.ts +266 -266
- package/src/dev/index.ts +647 -601
- package/src/docker/__tests__/compose.spec.ts +531 -0
- package/src/docker/__tests__/templates.spec.ts +280 -0
- package/src/docker/compose.ts +273 -0
- package/src/docker/index.ts +230 -0
- package/src/docker/templates.ts +446 -0
- package/src/generators/CronGenerator.ts +72 -72
- package/src/generators/EndpointGenerator.ts +699 -398
- package/src/generators/FunctionGenerator.ts +84 -84
- package/src/generators/Generator.ts +72 -72
- package/src/generators/OpenApiTsGenerator.ts +577 -577
- package/src/generators/SubscriberGenerator.ts +124 -124
- package/src/generators/__tests__/CronGenerator.spec.ts +433 -433
- package/src/generators/__tests__/EndpointGenerator.spec.ts +532 -382
- package/src/generators/__tests__/FunctionGenerator.spec.ts +244 -244
- package/src/generators/__tests__/SubscriberGenerator.spec.ts +397 -382
- package/src/generators/index.ts +4 -4
- package/src/index.ts +623 -201
- package/src/init/__tests__/generators.spec.ts +334 -334
- package/src/init/__tests__/init.spec.ts +332 -332
- package/src/init/__tests__/utils.spec.ts +89 -89
- package/src/init/generators/config.ts +175 -175
- package/src/init/generators/docker.ts +41 -41
- package/src/init/generators/env.ts +72 -72
- package/src/init/generators/index.ts +1 -1
- package/src/init/generators/models.ts +64 -64
- package/src/init/generators/monorepo.ts +161 -161
- package/src/init/generators/package.ts +71 -71
- package/src/init/generators/source.ts +6 -6
- package/src/init/index.ts +203 -208
- package/src/init/templates/api.ts +115 -115
- package/src/init/templates/index.ts +75 -75
- package/src/init/templates/minimal.ts +98 -98
- package/src/init/templates/serverless.ts +89 -89
- package/src/init/templates/worker.ts +98 -98
- package/src/init/utils.ts +54 -56
- package/src/openapi-react-query.ts +194 -194
- package/src/openapi.ts +63 -63
- package/src/secrets/__tests__/encryption.spec.ts +226 -0
- package/src/secrets/__tests__/generator.spec.ts +319 -0
- package/src/secrets/__tests__/index.spec.ts +91 -0
- package/src/secrets/__tests__/storage.spec.ts +403 -0
- package/src/secrets/encryption.ts +91 -0
- package/src/secrets/generator.ts +164 -0
- package/src/secrets/index.ts +383 -0
- package/src/secrets/storage.ts +134 -0
- package/src/secrets/types.ts +53 -0
- package/src/types.ts +295 -176
- package/tsdown.config.ts +11 -8
- package/dist/config-BrkUalUh.mjs.map +0 -1
- package/dist/config-C9aXOHBe.cjs.map +0 -1
- package/dist/openapi-BeHLKcwP.cjs.map +0 -1
- package/dist/openapi-CZLI4QTr.mjs.map +0 -1
- package/dist/openapi-react-query-CcciaVu5.mjs.map +0 -1
- package/dist/openapi-react-query-o5iMi8tz.cjs.map +0 -1
- package/dist/types-DXgiA1sF.d.mts.map +0 -1
- package/dist/types-b-vwGpqc.d.cts.map +0 -1
|
@@ -4,442 +4,442 @@ import type { Cron, ScheduleExpression } from '@geekmidas/constructs/crons';
|
|
|
4
4
|
import { itWithDir } from '@geekmidas/testkit/os';
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
cleanupDir,
|
|
8
|
+
createMockBuildContext,
|
|
9
|
+
createMockCronFile,
|
|
10
|
+
createTempDir,
|
|
11
|
+
createTestCron,
|
|
12
12
|
} from '../../__tests__/test-helpers';
|
|
13
13
|
import { CronGenerator } from '../CronGenerator';
|
|
14
14
|
import type { GeneratedConstruct } from '../Generator';
|
|
15
15
|
|
|
16
16
|
describe('CronGenerator', () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
17
|
+
let tempDir: string;
|
|
18
|
+
let outputDir: string;
|
|
19
|
+
let generator: CronGenerator;
|
|
20
|
+
let context: ReturnType<typeof createMockBuildContext>;
|
|
21
|
+
|
|
22
|
+
beforeEach(async () => {
|
|
23
|
+
tempDir = await createTempDir();
|
|
24
|
+
outputDir = join(tempDir, 'output');
|
|
25
|
+
generator = new CronGenerator();
|
|
26
|
+
context = createMockBuildContext();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(async () => {
|
|
30
|
+
await cleanupDir(tempDir);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe('isConstruct', () => {
|
|
34
|
+
it('should identify valid crons', () => {
|
|
35
|
+
const testCron = createTestCron('rate(1 hour)', 30);
|
|
36
|
+
expect(generator.isConstruct(testCron)).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should reject invalid constructs', () => {
|
|
40
|
+
expect(generator.isConstruct({})).toBe(false);
|
|
41
|
+
expect(generator.isConstruct('string')).toBe(false);
|
|
42
|
+
expect(generator.isConstruct(null)).toBe(false);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('build', () => {
|
|
47
|
+
const _createMockCronConstruct = (
|
|
48
|
+
key: string,
|
|
49
|
+
schedule: ScheduleExpression = 'rate(1 hour)',
|
|
50
|
+
timeout: number = 30,
|
|
51
|
+
): GeneratedConstruct<Cron<any, any, any, any>> => ({
|
|
52
|
+
key,
|
|
53
|
+
name: key.toLowerCase(),
|
|
54
|
+
construct: createTestCron(schedule, timeout),
|
|
55
|
+
path: {
|
|
56
|
+
absolute: join(tempDir, `${key}.ts`),
|
|
57
|
+
relative: `${key}.ts`,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe('aws-lambda provider', () => {
|
|
62
|
+
itWithDir('should generate cron handlers', async ({ dir }) => {
|
|
63
|
+
const outputDir = join(dir, 'output');
|
|
64
|
+
const cronsDir = join(dir, 'crons');
|
|
65
|
+
await mkdir(outputDir, { recursive: true });
|
|
66
|
+
|
|
67
|
+
await Promise.all([
|
|
68
|
+
createMockCronFile(
|
|
69
|
+
cronsDir,
|
|
70
|
+
'dailyReport.ts',
|
|
71
|
+
'dailyReport',
|
|
72
|
+
'rate(1 day)',
|
|
73
|
+
),
|
|
74
|
+
createMockCronFile(
|
|
75
|
+
cronsDir,
|
|
76
|
+
'hourlyCleanup.ts',
|
|
77
|
+
'hourlyCleanup',
|
|
78
|
+
'rate(1 hour)',
|
|
79
|
+
),
|
|
80
|
+
createMockCronFile(
|
|
81
|
+
cronsDir,
|
|
82
|
+
'weeklyBackup.ts',
|
|
83
|
+
'weeklyBackup',
|
|
84
|
+
'cron(0 0 ? * SUN *)',
|
|
85
|
+
),
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
const constructs = await generator.load('**/crons/*.ts', dir);
|
|
89
|
+
|
|
90
|
+
const cronInfos = await generator.build(
|
|
91
|
+
context,
|
|
92
|
+
constructs,
|
|
93
|
+
outputDir,
|
|
94
|
+
{ provider: 'aws-lambda' },
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
expect(cronInfos).toHaveLength(3);
|
|
98
|
+
|
|
99
|
+
// Find crons by name since order may vary
|
|
100
|
+
const dailyReport = cronInfos.find((c) => c.name === 'dailyReport');
|
|
101
|
+
const hourlyCleanup = cronInfos.find((c) => c.name === 'hourlyCleanup');
|
|
102
|
+
const weeklyBackup = cronInfos.find((c) => c.name === 'weeklyBackup');
|
|
103
|
+
|
|
104
|
+
expect(dailyReport).toMatchObject({
|
|
105
|
+
name: 'dailyReport',
|
|
106
|
+
handler: expect.stringContaining('crons/dailyReport.handler'),
|
|
107
|
+
schedule: 'rate(1 day)',
|
|
108
|
+
});
|
|
109
|
+
expect(hourlyCleanup).toMatchObject({
|
|
110
|
+
name: 'hourlyCleanup',
|
|
111
|
+
handler: expect.stringContaining('crons/hourlyCleanup.handler'),
|
|
112
|
+
schedule: 'rate(1 hour)',
|
|
113
|
+
});
|
|
114
|
+
expect(weeklyBackup).toMatchObject({
|
|
115
|
+
name: 'weeklyBackup',
|
|
116
|
+
handler: expect.stringContaining('crons/weeklyBackup.handler'),
|
|
117
|
+
schedule: 'cron(0 0 ? * SUN *)',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Check that handler files were created
|
|
121
|
+
const dailyReportHandlerPath = join(
|
|
122
|
+
outputDir,
|
|
123
|
+
'crons',
|
|
124
|
+
'dailyReport.ts',
|
|
125
|
+
);
|
|
126
|
+
const dailyReportContent = await readFile(
|
|
127
|
+
dailyReportHandlerPath,
|
|
128
|
+
'utf-8',
|
|
129
|
+
);
|
|
130
|
+
expect(dailyReportContent).toContain('AWSScheduledFunction');
|
|
131
|
+
expect(dailyReportContent).toContain('import { dailyReport }');
|
|
132
|
+
expect(dailyReportContent).toContain('import envParser');
|
|
133
|
+
expect(dailyReportContent).toContain('import logger');
|
|
134
|
+
|
|
135
|
+
const hourlyCleanupHandlerPath = join(
|
|
136
|
+
outputDir,
|
|
137
|
+
'crons',
|
|
138
|
+
'hourlyCleanup.ts',
|
|
139
|
+
);
|
|
140
|
+
const hourlyCleanupContent = await readFile(
|
|
141
|
+
hourlyCleanupHandlerPath,
|
|
142
|
+
'utf-8',
|
|
143
|
+
);
|
|
144
|
+
expect(hourlyCleanupContent).toContain('AWSScheduledFunction');
|
|
145
|
+
expect(hourlyCleanupContent).toContain('import { hourlyCleanup }');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should use default schedule when none provided', async () => {
|
|
149
|
+
// Create a cron with empty schedule that will use default
|
|
150
|
+
const cronWithDefaultSchedule = createTestCron(undefined, 30);
|
|
151
|
+
|
|
152
|
+
const construct: GeneratedConstruct<Cron<any, any, any, any>> = {
|
|
153
|
+
key: 'defaultScheduleCron',
|
|
154
|
+
name: 'default-schedule-cron',
|
|
155
|
+
construct: cronWithDefaultSchedule,
|
|
156
|
+
path: {
|
|
157
|
+
absolute: join(tempDir, 'defaultScheduleCron.ts'),
|
|
158
|
+
relative: 'defaultScheduleCron.ts',
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const cronInfos = await generator.build(
|
|
163
|
+
context,
|
|
164
|
+
[construct],
|
|
165
|
+
outputDir,
|
|
166
|
+
{ provider: 'aws-lambda' },
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
// Since the construct has a schedule, it should use that or default logic
|
|
170
|
+
expect(cronInfos[0].schedule).toBeDefined();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
itWithDir(
|
|
174
|
+
'should generate correct relative import paths',
|
|
175
|
+
async ({ dir }) => {
|
|
176
|
+
const outputDir = join(dir, 'output');
|
|
177
|
+
const nestedDir = join(dir, 'src', 'crons', 'deep');
|
|
178
|
+
await mkdir(outputDir, { recursive: true });
|
|
179
|
+
|
|
180
|
+
await createMockCronFile(
|
|
181
|
+
nestedDir,
|
|
182
|
+
'deepCron.ts',
|
|
183
|
+
'deepCron',
|
|
184
|
+
'rate(1 day)',
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const constructs = await generator.load(
|
|
188
|
+
'**/src/crons/deep/*.ts',
|
|
189
|
+
dir,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
await generator.build(context, constructs, outputDir, {
|
|
193
|
+
provider: 'aws-lambda',
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const handlerPath = join(outputDir, 'crons', 'deepCron.ts');
|
|
197
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
198
|
+
|
|
199
|
+
// Check relative imports are correct - the path will be relative from outputDir
|
|
200
|
+
expect(handlerContent).toMatch(
|
|
201
|
+
/from ['"]+.*src\/crons\/deep\/deepCron\.js['"]+/,
|
|
202
|
+
);
|
|
203
|
+
expect(handlerContent).toMatch(/from ['"]+.*\/env['"]+/);
|
|
204
|
+
expect(handlerContent).toMatch(/from ['"]+.*\/logger['"]+/);
|
|
205
|
+
},
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
itWithDir('should log generation progress', async ({ dir }) => {
|
|
209
|
+
const logSpy = vi.spyOn(console, 'log');
|
|
210
|
+
const outputDir = join(dir, 'output');
|
|
211
|
+
const cronsDir = join(dir, 'crons');
|
|
212
|
+
await mkdir(outputDir, { recursive: true });
|
|
213
|
+
|
|
214
|
+
await createMockCronFile(
|
|
215
|
+
cronsDir,
|
|
216
|
+
'testCron.ts',
|
|
217
|
+
'testCron',
|
|
218
|
+
'rate(1 hour)',
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
const constructs = await generator.load('**/crons/*.ts', dir);
|
|
222
|
+
|
|
223
|
+
await generator.build(context, constructs, outputDir, {
|
|
224
|
+
provider: 'aws-lambda',
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
expect(logSpy).toHaveBeenCalledWith('Generated cron handler: testCron');
|
|
228
|
+
|
|
229
|
+
logSpy.mockRestore();
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe('non aws-lambda provider', () => {
|
|
234
|
+
itWithDir(
|
|
235
|
+
'should return empty array for server provider',
|
|
236
|
+
async ({ dir }) => {
|
|
237
|
+
const outputDir = join(dir, 'output');
|
|
238
|
+
const cronsDir = join(dir, 'crons');
|
|
239
|
+
await mkdir(outputDir, { recursive: true });
|
|
240
|
+
|
|
241
|
+
await createMockCronFile(
|
|
242
|
+
cronsDir,
|
|
243
|
+
'testCron.ts',
|
|
244
|
+
'testCron',
|
|
245
|
+
'rate(1 hour)',
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const constructs = await generator.load('**/crons/*.ts', dir);
|
|
249
|
+
|
|
250
|
+
const cronInfos = await generator.build(
|
|
251
|
+
context,
|
|
252
|
+
constructs,
|
|
253
|
+
outputDir,
|
|
254
|
+
{ provider: 'server' },
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
expect(cronInfos).toEqual([]);
|
|
258
|
+
},
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
itWithDir(
|
|
262
|
+
'should return empty array for aws-apigatewayv1 provider',
|
|
263
|
+
async ({ dir }) => {
|
|
264
|
+
const outputDir = join(dir, 'output');
|
|
265
|
+
const cronsDir = join(dir, 'crons');
|
|
266
|
+
await mkdir(outputDir, { recursive: true });
|
|
267
|
+
|
|
268
|
+
await createMockCronFile(
|
|
269
|
+
cronsDir,
|
|
270
|
+
'testCron.ts',
|
|
271
|
+
'testCron',
|
|
272
|
+
'rate(1 hour)',
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
const constructs = await generator.load('**/crons/*.ts', dir);
|
|
276
|
+
|
|
277
|
+
const cronInfos = await generator.build(
|
|
278
|
+
context,
|
|
279
|
+
constructs,
|
|
280
|
+
outputDir,
|
|
281
|
+
{ provider: 'aws-apigatewayv1' },
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
expect(cronInfos).toEqual([]);
|
|
285
|
+
},
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('should return empty array for empty constructs', async () => {
|
|
290
|
+
const cronInfos = await generator.build(context, [], outputDir, {
|
|
291
|
+
provider: 'aws-lambda',
|
|
292
|
+
});
|
|
293
|
+
expect(cronInfos).toEqual([]);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
itWithDir(
|
|
297
|
+
'should use default provider when none specified',
|
|
298
|
+
async ({ dir }) => {
|
|
299
|
+
const outputDir = join(dir, 'output');
|
|
300
|
+
const cronsDir = join(dir, 'crons');
|
|
301
|
+
await mkdir(outputDir, { recursive: true });
|
|
302
|
+
|
|
303
|
+
await createMockCronFile(
|
|
304
|
+
cronsDir,
|
|
305
|
+
'defaultCron.ts',
|
|
306
|
+
'defaultCron',
|
|
307
|
+
'rate(1 hour)',
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
const constructs = await generator.load('**/crons/*.ts', dir);
|
|
311
|
+
|
|
312
|
+
const cronInfos = await generator.build(context, constructs, outputDir);
|
|
313
|
+
|
|
314
|
+
expect(cronInfos).toHaveLength(1);
|
|
315
|
+
expect(cronInfos[0].name).toBe('defaultCron');
|
|
316
|
+
|
|
317
|
+
// Check that handler was created (default is aws-lambda)
|
|
318
|
+
const handlerPath = join(outputDir, 'crons', 'defaultCron.ts');
|
|
319
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
320
|
+
expect(handlerContent).toContain('AWSScheduledFunction');
|
|
321
|
+
},
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
itWithDir('should handle various schedule expressions', async ({ dir }) => {
|
|
325
|
+
const outputDir = join(dir, 'output');
|
|
326
|
+
const cronsDir = join(dir, 'crons');
|
|
327
|
+
await mkdir(outputDir, { recursive: true });
|
|
328
|
+
|
|
329
|
+
await Promise.all([
|
|
330
|
+
createMockCronFile(
|
|
331
|
+
cronsDir,
|
|
332
|
+
'rateCron.ts',
|
|
333
|
+
'rateCron',
|
|
334
|
+
'rate(5 minutes)',
|
|
335
|
+
),
|
|
336
|
+
createMockCronFile(
|
|
337
|
+
cronsDir,
|
|
338
|
+
'cronExpression.ts',
|
|
339
|
+
'cronExpression',
|
|
340
|
+
'cron(0 12 * * ? *)',
|
|
341
|
+
),
|
|
342
|
+
createMockCronFile(
|
|
343
|
+
cronsDir,
|
|
344
|
+
'dailyRate.ts',
|
|
345
|
+
'dailyRate',
|
|
346
|
+
'rate(1 day)',
|
|
347
|
+
),
|
|
348
|
+
]);
|
|
349
|
+
|
|
350
|
+
const constructs = await generator.load('**/crons/*.ts', dir);
|
|
351
|
+
|
|
352
|
+
const cronInfos = await generator.build(context, constructs, outputDir, {
|
|
353
|
+
provider: 'aws-lambda',
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// Find crons by name since order may vary
|
|
357
|
+
const rateCron = cronInfos.find((c) => c.name === 'rateCron');
|
|
358
|
+
const cronExpression = cronInfos.find((c) => c.name === 'cronExpression');
|
|
359
|
+
const dailyRate = cronInfos.find((c) => c.name === 'dailyRate');
|
|
360
|
+
|
|
361
|
+
expect(rateCron?.schedule).toBe('rate(5 minutes)');
|
|
362
|
+
expect(cronExpression?.schedule).toBe('cron(0 12 * * ? *)');
|
|
363
|
+
expect(dailyRate?.schedule).toBe('rate(1 day)');
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
itWithDir(
|
|
367
|
+
'should handle crons with different timeout values',
|
|
368
|
+
async ({ dir }) => {
|
|
369
|
+
const outputDir = join(dir, 'output');
|
|
370
|
+
const cronsDir = join(dir, 'crons');
|
|
371
|
+
await mkdir(outputDir, { recursive: true });
|
|
372
|
+
|
|
373
|
+
await Promise.all([
|
|
374
|
+
createMockCronFile(
|
|
375
|
+
cronsDir,
|
|
376
|
+
'quickCron.ts',
|
|
377
|
+
'quickCron',
|
|
378
|
+
'rate(1 minute)',
|
|
379
|
+
),
|
|
380
|
+
createMockCronFile(
|
|
381
|
+
cronsDir,
|
|
382
|
+
'slowCron.ts',
|
|
383
|
+
'slowCron',
|
|
384
|
+
'rate(1 hour)',
|
|
385
|
+
),
|
|
386
|
+
]);
|
|
387
|
+
|
|
388
|
+
const constructs = await generator.load('**/crons/*.ts', dir);
|
|
389
|
+
|
|
390
|
+
const cronInfos = await generator.build(
|
|
391
|
+
context,
|
|
392
|
+
constructs,
|
|
393
|
+
outputDir,
|
|
394
|
+
{
|
|
395
|
+
provider: 'aws-lambda',
|
|
396
|
+
},
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
// Find crons by name since order may vary
|
|
400
|
+
const quickCron = cronInfos.find((c) => c.name === 'quickCron');
|
|
401
|
+
const slowCron = cronInfos.find((c) => c.name === 'slowCron');
|
|
402
|
+
|
|
403
|
+
// Note: timeout comes from the cron construct, not the file creation
|
|
404
|
+
expect(quickCron).toBeDefined();
|
|
405
|
+
expect(slowCron).toBeDefined();
|
|
406
|
+
},
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
itWithDir(
|
|
410
|
+
'should handle crons with custom environment parser patterns',
|
|
411
|
+
async ({ dir }) => {
|
|
412
|
+
const outputDir = join(dir, 'output');
|
|
413
|
+
const cronsDir = join(dir, 'crons');
|
|
414
|
+
await mkdir(outputDir, { recursive: true });
|
|
415
|
+
|
|
416
|
+
const customContext = {
|
|
417
|
+
...context,
|
|
418
|
+
envParserImportPattern: '{ customParser as envParser }',
|
|
419
|
+
loggerImportPattern: '{ customLogger as logger }',
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
await createMockCronFile(
|
|
423
|
+
cronsDir,
|
|
424
|
+
'customCron.ts',
|
|
425
|
+
'customCron',
|
|
426
|
+
'rate(1 hour)',
|
|
427
|
+
);
|
|
428
|
+
|
|
429
|
+
const constructs = await generator.load('**/crons/*.ts', dir);
|
|
430
|
+
|
|
431
|
+
await generator.build(customContext, constructs, outputDir, {
|
|
432
|
+
provider: 'aws-lambda',
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
const handlerPath = join(outputDir, 'crons', 'customCron.ts');
|
|
436
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
437
|
+
|
|
438
|
+
expect(handlerContent).toContain(
|
|
439
|
+
'import { customParser as envParser }',
|
|
440
|
+
);
|
|
441
|
+
expect(handlerContent).toContain('import { customLogger as logger }');
|
|
442
|
+
},
|
|
443
|
+
);
|
|
444
|
+
});
|
|
445
445
|
});
|