@geekmidas/cli 9.2.1 → 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 +31 -0
- package/README.md +1 -1
- package/dist/index.cjs +67 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +67 -21
- package/dist/index.mjs.map +1 -1
- package/docs/manifest-refactor-design.md +1 -1
- package/examples/cron-example.ts +1 -1
- package/package.json +9 -9
- package/src/__tests__/test-helpers.ts +4 -4
- package/src/build/__tests__/index-new.spec.ts +3 -3
- package/src/build/__tests__/manifests.spec.ts +2 -2
- package/src/generators/CronGenerator.ts +72 -1
- package/src/generators/__tests__/CronGenerator.spec.ts +74 -23
- package/src/init/versions.ts +19 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# @geekmidas/cli
|
|
2
2
|
|
|
3
|
+
## 9.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 🔥 [#331](https://github.com/geekmidas/toolbox/pull/331) [`0383ab8`](https://github.com/geekmidas/toolbox/commit/0383ab86dcbe300556d6cda5b20be24cd7e63cdd) Thanks [@geekmidas](https://github.com/geekmidas)! - Crons take Unix or AWS cron expressions, and `rate(…)` is removed
|
|
8
|
+
|
|
9
|
+
**Breaking:** `rate(…)` schedules are no longer accepted. Write the cron they stand for, e.g. `rate(5 minutes)` is `cron(*/5 * * * *)` and `rate(1 day)` is `cron(0 0 * * *)`. `RateExpression` and `@geekmidas/cloud`'s `CronRate` are removed.
|
|
10
|
+
|
|
11
|
+
`.schedule()` takes a five-field Unix `cron(…)` or a six-field AWS one, and checks each by its own rules at compile time:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
c.schedule("cron(0 9 * * MON-FRI)"); // Unix
|
|
15
|
+
c.schedule("cron(0 9 ? * 6#3 *)"); // AWS
|
|
16
|
+
c.schedule("cron(0 25 * * *)"); // type error: hour 25
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`gkm build` and `gkm dev` validate every cron's schedule and fail on an invalid one, listing each cron with the field and token that failed. The manifest always records the AWS form, converting a Unix expression and warning when the conversion is approximate.
|
|
20
|
+
|
|
21
|
+
`@geekmidas/manifest` exports `parseCron`, `toAwsCron` and `toUnixCron`, and `cronPeriod`: the longest gap between runs in seconds, the period a heartbeat should expect.
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`0383ab8`](https://github.com/geekmidas/toolbox/commit/0383ab86dcbe300556d6cda5b20be24cd7e63cdd)]:
|
|
26
|
+
- @geekmidas/manifest@9.3.0
|
|
27
|
+
- @geekmidas/constructs@9.3.0
|
|
28
|
+
- @geekmidas/envkit@9.3.0
|
|
29
|
+
- @geekmidas/errors@9.3.0
|
|
30
|
+
- @geekmidas/logger@9.3.0
|
|
31
|
+
- @geekmidas/schema@9.3.0
|
|
32
|
+
- @geekmidas/telescope@9.3.0
|
|
33
|
+
|
|
3
34
|
## 9.2.1
|
|
4
35
|
|
|
5
36
|
### Patch Changes
|
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -24,6 +24,7 @@ const fast_glob = require_chunk.__toESM(require("fast-glob"));
|
|
|
24
24
|
const yaml = require_chunk.__toESM(require("yaml"));
|
|
25
25
|
const node_crypto = require_chunk.__toESM(require("node:crypto"));
|
|
26
26
|
const __geekmidas_constructs_crons = require_chunk.__toESM(require("@geekmidas/constructs/crons"));
|
|
27
|
+
const __geekmidas_manifest = require_chunk.__toESM(require("@geekmidas/manifest"));
|
|
27
28
|
const __geekmidas_constructs_functions = require_chunk.__toESM(require("@geekmidas/constructs/functions"));
|
|
28
29
|
const __geekmidas_constructs_queue = require_chunk.__toESM(require("@geekmidas/constructs/queue"));
|
|
29
30
|
const __geekmidas_constructs_subscribers = require_chunk.__toESM(require("@geekmidas/constructs/subscribers"));
|
|
@@ -36,7 +37,7 @@ const prompts = require_chunk.__toESM(require("prompts"));
|
|
|
36
37
|
|
|
37
38
|
//#region package.json
|
|
38
39
|
var name = "@geekmidas/cli";
|
|
39
|
-
var version = "9.2.
|
|
40
|
+
var version = "9.2.1";
|
|
40
41
|
var description = "CLI tools for building Lambda handlers, server applications, and generating OpenAPI specs";
|
|
41
42
|
var private$1 = false;
|
|
42
43
|
var type = "module";
|
|
@@ -376,6 +377,7 @@ var CronGenerator = class extends require_openapi.ConstructGenerator {
|
|
|
376
377
|
const provider = options?.provider || "aws-lambda";
|
|
377
378
|
const logger$13 = console;
|
|
378
379
|
const cronInfos = [];
|
|
380
|
+
const schedules = resolveSchedules(constructs, logger$13);
|
|
379
381
|
if (constructs.length === 0 || provider !== "aws-lambda") return cronInfos;
|
|
380
382
|
const cronsDir = (0, node_path.join)(outputDir, "crons");
|
|
381
383
|
await (0, node_fs_promises.mkdir)(cronsDir, { recursive: true });
|
|
@@ -384,7 +386,7 @@ var CronGenerator = class extends require_openapi.ConstructGenerator {
|
|
|
384
386
|
cronInfos.push({
|
|
385
387
|
name: key,
|
|
386
388
|
handler: (0, node_path.relative)(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
|
|
387
|
-
schedule:
|
|
389
|
+
schedule: schedules.get(key),
|
|
388
390
|
timeout: construct.timeout,
|
|
389
391
|
memorySize: construct.memorySize,
|
|
390
392
|
environment: await construct.getEnvironment({ markOptional: context.markOptional }),
|
|
@@ -417,6 +419,50 @@ export const handler = adapter.handler;
|
|
|
417
419
|
return handlerPath;
|
|
418
420
|
}
|
|
419
421
|
};
|
|
422
|
+
/** One or more crons have an invalid schedule; all of them are listed. */
|
|
423
|
+
var InvalidCronSchedulesError = class extends Error {
|
|
424
|
+
constructor(crons) {
|
|
425
|
+
super("Invalid cron schedules", { cause: { crons } });
|
|
426
|
+
this.crons = crons;
|
|
427
|
+
this.name = "InvalidCronSchedulesError";
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
/** Hourly, when a cron sets no schedule. */
|
|
431
|
+
const DEFAULT_SCHEDULE = "cron(0 * * * *)";
|
|
432
|
+
/**
|
|
433
|
+
* Each cron's schedule in the AWS form the manifest records, keyed by cron.
|
|
434
|
+
* Every schedule is validated, since a cast or JavaScript caller gets past
|
|
435
|
+
* the types, and all invalid ones are reported together.
|
|
436
|
+
*
|
|
437
|
+
* @throws {InvalidCronSchedulesError}
|
|
438
|
+
*/
|
|
439
|
+
function resolveSchedules(constructs, logger$13) {
|
|
440
|
+
const schedules = /* @__PURE__ */ new Map();
|
|
441
|
+
const invalid = [];
|
|
442
|
+
for (const { key, construct } of constructs) {
|
|
443
|
+
const schedule = construct.schedule ?? DEFAULT_SCHEDULE;
|
|
444
|
+
try {
|
|
445
|
+
const { expression, warnings } = (0, __geekmidas_manifest.toAwsCron)(schedule);
|
|
446
|
+
for (const warning of warnings) logger$13.warn("Cron schedule converted to AWS approximately", {
|
|
447
|
+
cron: key,
|
|
448
|
+
schedule,
|
|
449
|
+
expression,
|
|
450
|
+
...warning
|
|
451
|
+
});
|
|
452
|
+
schedules.set(key, expression);
|
|
453
|
+
} catch (error) {
|
|
454
|
+
if (!(error instanceof __geekmidas_manifest.InvalidCronExpressionError)) throw error;
|
|
455
|
+
invalid.push({
|
|
456
|
+
cron: key,
|
|
457
|
+
schedule,
|
|
458
|
+
field: error.field,
|
|
459
|
+
token: error.token
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (invalid.length > 0) throw new InvalidCronSchedulesError(invalid);
|
|
464
|
+
return schedules;
|
|
465
|
+
}
|
|
420
466
|
|
|
421
467
|
//#endregion
|
|
422
468
|
//#region src/generators/FunctionGenerator.ts
|
|
@@ -6897,25 +6943,25 @@ const CLI_VERSION = `~${pkg.version}`;
|
|
|
6897
6943
|
* Run: pnpm --filter @geekmidas/cli sync-versions
|
|
6898
6944
|
*/
|
|
6899
6945
|
const GEEKMIDAS_VERSIONS = {
|
|
6900
|
-
"@geekmidas/audit": "~9.2.
|
|
6901
|
-
"@geekmidas/auth": "~9.2.
|
|
6902
|
-
"@geekmidas/cache": "~9.2.
|
|
6903
|
-
"@geekmidas/client": "~9.2.
|
|
6904
|
-
"@geekmidas/cloud": "~9.2.
|
|
6905
|
-
"@geekmidas/constructs": "~9.2.
|
|
6906
|
-
"@geekmidas/db": "~9.2.
|
|
6907
|
-
"@geekmidas/emailkit": "~9.2.
|
|
6908
|
-
"@geekmidas/envkit": "~9.2.
|
|
6909
|
-
"@geekmidas/errors": "~9.2.
|
|
6910
|
-
"@geekmidas/events": "~9.2.
|
|
6911
|
-
"@geekmidas/logger": "~9.2.
|
|
6912
|
-
"@geekmidas/rate-limit": "~9.2.
|
|
6913
|
-
"@geekmidas/schema": "~9.2.
|
|
6914
|
-
"@geekmidas/services": "~9.2.
|
|
6915
|
-
"@geekmidas/storage": "~9.2.
|
|
6916
|
-
"@geekmidas/studio": "~9.2.
|
|
6917
|
-
"@geekmidas/telescope": "~9.2.
|
|
6918
|
-
"@geekmidas/testkit": "~9.2.
|
|
6946
|
+
"@geekmidas/audit": "~9.2.1",
|
|
6947
|
+
"@geekmidas/auth": "~9.2.1",
|
|
6948
|
+
"@geekmidas/cache": "~9.2.1",
|
|
6949
|
+
"@geekmidas/client": "~9.2.1",
|
|
6950
|
+
"@geekmidas/cloud": "~9.2.1",
|
|
6951
|
+
"@geekmidas/constructs": "~9.2.1",
|
|
6952
|
+
"@geekmidas/db": "~9.2.1",
|
|
6953
|
+
"@geekmidas/emailkit": "~9.2.1",
|
|
6954
|
+
"@geekmidas/envkit": "~9.2.1",
|
|
6955
|
+
"@geekmidas/errors": "~9.2.1",
|
|
6956
|
+
"@geekmidas/events": "~9.2.1",
|
|
6957
|
+
"@geekmidas/logger": "~9.2.1",
|
|
6958
|
+
"@geekmidas/rate-limit": "~9.2.1",
|
|
6959
|
+
"@geekmidas/schema": "~9.2.1",
|
|
6960
|
+
"@geekmidas/services": "~9.2.1",
|
|
6961
|
+
"@geekmidas/storage": "~9.2.1",
|
|
6962
|
+
"@geekmidas/studio": "~9.2.1",
|
|
6963
|
+
"@geekmidas/telescope": "~9.2.1",
|
|
6964
|
+
"@geekmidas/testkit": "~9.2.1",
|
|
6919
6965
|
"@geekmidas/cli": CLI_VERSION
|
|
6920
6966
|
};
|
|
6921
6967
|
|