@geekmidas/cli 9.2.1 → 9.4.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 CHANGED
@@ -1,5 +1,72 @@
1
1
  # @geekmidas/cli
2
2
 
3
+ ## 9.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#334](https://github.com/geekmidas/toolbox/pull/334) [`b03c43d`](https://github.com/geekmidas/toolbox/commit/b03c43dfd2c86b1daa7f0a47f43e5fb2e518518b) Thanks [@geekmidas](https://github.com/geekmidas)! - Crons report to an uptime monitor with `.uptime()`, which replaces `.monitor()`
8
+
9
+ **Breaking:** `.monitor()` is removed from functions, crons, endpoints and `EndpointFactory`, along with the monitor hooks in the endpoint adaptors. The manifest's `monitoring` field is removed from routes, functions and crons.
10
+
11
+ A monitor only adds something a cron can't report itself: that it didn't run. A function or endpoint runs when it's called, so no ping is ever due, and its failures are already logged where they happen. So uptime is now set on crons alone:
12
+
13
+ ```ts
14
+ export const nightlyReport = c
15
+ .schedule("cron(0 8 * * MON-FRI)")
16
+ .uptime(heartbeat.betterStack("MONITORING_URL"))
17
+ .handle(async () => {});
18
+ ```
19
+
20
+ Calling `.uptime()` again replaces the monitor. `gkm build` records it on the cron's manifest entry as `uptime`, with the period the heartbeat should expect, derived from the schedule by `cronPeriod`:
21
+
22
+ ```ts
23
+ uptime: { type: 'heartbeat', provider: 'betterStack', env: 'MONITORING_URL', period: 259200 }
24
+ ```
25
+
26
+ `MonitorInfo` in `@geekmidas/manifest` is replaced by `UptimeInfo`.
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [[`b03c43d`](https://github.com/geekmidas/toolbox/commit/b03c43dfd2c86b1daa7f0a47f43e5fb2e518518b)]:
31
+ - @geekmidas/manifest@9.4.0
32
+ - @geekmidas/constructs@9.4.0
33
+ - @geekmidas/envkit@9.4.0
34
+ - @geekmidas/errors@9.4.0
35
+ - @geekmidas/logger@9.4.0
36
+ - @geekmidas/schema@9.4.0
37
+ - @geekmidas/telescope@9.4.0
38
+
39
+ ## 9.3.0
40
+
41
+ ### Minor Changes
42
+
43
+ - 🔥 [#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
44
+
45
+ **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.
46
+
47
+ `.schedule()` takes a five-field Unix `cron(…)` or a six-field AWS one, and checks each by its own rules at compile time:
48
+
49
+ ```ts
50
+ c.schedule("cron(0 9 * * MON-FRI)"); // Unix
51
+ c.schedule("cron(0 9 ? * 6#3 *)"); // AWS
52
+ c.schedule("cron(0 25 * * *)"); // type error: hour 25
53
+ ```
54
+
55
+ `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.
56
+
57
+ `@geekmidas/manifest` exports `parseCron`, `toAwsCron` and `toUnixCron`, and `cronPeriod`: the longest gap between runs in seconds, the period a heartbeat should expect.
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies [[`0383ab8`](https://github.com/geekmidas/toolbox/commit/0383ab86dcbe300556d6cda5b20be24cd7e63cdd)]:
62
+ - @geekmidas/manifest@9.3.0
63
+ - @geekmidas/constructs@9.3.0
64
+ - @geekmidas/envkit@9.3.0
65
+ - @geekmidas/errors@9.3.0
66
+ - @geekmidas/logger@9.3.0
67
+ - @geekmidas/schema@9.3.0
68
+ - @geekmidas/telescope@9.3.0
69
+
3
70
  ## 9.2.1
4
71
 
5
72
  ### Patch Changes
package/README.md CHANGED
@@ -1554,7 +1554,7 @@ export const manifest = {
1554
1554
  {
1555
1555
  name: 'dailyCleanup',
1556
1556
  handler: '.gkm/aws-lambda/crons/dailyCleanup.handler',
1557
- schedule: 'rate(1 day)',
1557
+ schedule: 'cron(0 0 * * ? *)',
1558
1558
  timeout: 300,
1559
1559
  memorySize: 512,
1560
1560
  },
package/dist/index.cjs CHANGED
@@ -6,7 +6,7 @@ const require_credentials = require('./credentials-C8DWtnMY.cjs');
6
6
  const require_fullstack_secrets = require('./fullstack-secrets-BYzi6Hwl.cjs');
7
7
  const require_storage = require('./storage-B1wvztiJ.cjs');
8
8
  const require_setup = require('./setup-C2UhXWhN.cjs');
9
- const require_openapi = require('./openapi-C-YgZHyd.cjs');
9
+ const require_openapi = require('./openapi-ayEknaaM.cjs');
10
10
  const require_dokploy_api = require('./dokploy-api-CqOIKHme.cjs');
11
11
  const require_encryption = require('./encryption-MfXAiFTm.cjs');
12
12
  const require_CachedStateProvider = require('./CachedStateProvider-klLWZXWF.cjs');
@@ -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.0";
40
+ var version = "9.3.0";
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,19 +377,25 @@ 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 });
382
384
  for (const { key, construct, path } of constructs) {
383
385
  const handlerFile = await this.generateCronHandler(cronsDir, path.relative, key, context);
386
+ const schedule = schedules.get(key);
387
+ const uptime = construct.getUptime();
384
388
  cronInfos.push({
385
389
  name: key,
386
390
  handler: (0, node_path.relative)(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
387
- schedule: construct.schedule || "rate(1 hour)",
391
+ schedule,
388
392
  timeout: construct.timeout,
389
393
  memorySize: construct.memorySize,
390
394
  environment: await construct.getEnvironment({ markOptional: context.markOptional }),
391
- monitoring: construct.getMonitoring()
395
+ ...uptime && { uptime: {
396
+ ...uptime,
397
+ period: (0, __geekmidas_manifest.cronPeriod)(schedule)
398
+ } }
392
399
  });
393
400
  logger$13.log(`Generated cron handler: ${key}`);
394
401
  }
@@ -417,6 +424,50 @@ export const handler = adapter.handler;
417
424
  return handlerPath;
418
425
  }
419
426
  };
427
+ /** One or more crons have an invalid schedule; all of them are listed. */
428
+ var InvalidCronSchedulesError = class extends Error {
429
+ constructor(crons) {
430
+ super("Invalid cron schedules", { cause: { crons } });
431
+ this.crons = crons;
432
+ this.name = "InvalidCronSchedulesError";
433
+ }
434
+ };
435
+ /** Hourly, when a cron sets no schedule. */
436
+ const DEFAULT_SCHEDULE = "cron(0 * * * *)";
437
+ /**
438
+ * Each cron's schedule in the AWS form the manifest records, keyed by cron.
439
+ * Every schedule is validated, since a cast or JavaScript caller gets past
440
+ * the types, and all invalid ones are reported together.
441
+ *
442
+ * @throws {InvalidCronSchedulesError}
443
+ */
444
+ function resolveSchedules(constructs, logger$13) {
445
+ const schedules = /* @__PURE__ */ new Map();
446
+ const invalid = [];
447
+ for (const { key, construct } of constructs) {
448
+ const schedule = construct.schedule ?? DEFAULT_SCHEDULE;
449
+ try {
450
+ const { expression, warnings } = (0, __geekmidas_manifest.toAwsCron)(schedule);
451
+ for (const warning of warnings) logger$13.warn("Cron schedule converted to AWS approximately", {
452
+ cron: key,
453
+ schedule,
454
+ expression,
455
+ ...warning
456
+ });
457
+ schedules.set(key, expression);
458
+ } catch (error) {
459
+ if (!(error instanceof __geekmidas_manifest.InvalidCronExpressionError)) throw error;
460
+ invalid.push({
461
+ cron: key,
462
+ schedule,
463
+ field: error.field,
464
+ token: error.token
465
+ });
466
+ }
467
+ }
468
+ if (invalid.length > 0) throw new InvalidCronSchedulesError(invalid);
469
+ return schedules;
470
+ }
420
471
 
421
472
  //#endregion
422
473
  //#region src/generators/FunctionGenerator.ts
@@ -438,8 +489,7 @@ var FunctionGenerator = class extends require_openapi.ConstructGenerator {
438
489
  handler: (0, node_path.relative)(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
439
490
  timeout: construct.timeout,
440
491
  memorySize: construct.memorySize,
441
- environment: await construct.getEnvironment({ markOptional: context.markOptional }),
442
- monitoring: construct.getMonitoring()
492
+ environment: await construct.getEnvironment({ markOptional: context.markOptional })
443
493
  });
444
494
  logger$13.log(`Generated function handler: ${key}`);
445
495
  }
@@ -6897,25 +6947,25 @@ const CLI_VERSION = `~${pkg.version}`;
6897
6947
  * Run: pnpm --filter @geekmidas/cli sync-versions
6898
6948
  */
6899
6949
  const GEEKMIDAS_VERSIONS = {
6900
- "@geekmidas/audit": "~9.2.0",
6901
- "@geekmidas/auth": "~9.2.0",
6902
- "@geekmidas/cache": "~9.2.0",
6903
- "@geekmidas/client": "~9.2.0",
6904
- "@geekmidas/cloud": "~9.2.0",
6905
- "@geekmidas/constructs": "~9.2.0",
6906
- "@geekmidas/db": "~9.2.0",
6907
- "@geekmidas/emailkit": "~9.2.0",
6908
- "@geekmidas/envkit": "~9.2.0",
6909
- "@geekmidas/errors": "~9.2.0",
6910
- "@geekmidas/events": "~9.2.0",
6911
- "@geekmidas/logger": "~9.2.0",
6912
- "@geekmidas/rate-limit": "~9.2.0",
6913
- "@geekmidas/schema": "~9.2.0",
6914
- "@geekmidas/services": "~9.2.0",
6915
- "@geekmidas/storage": "~9.2.0",
6916
- "@geekmidas/studio": "~9.2.0",
6917
- "@geekmidas/telescope": "~9.2.0",
6918
- "@geekmidas/testkit": "~9.2.0",
6950
+ "@geekmidas/audit": "~9.3.0",
6951
+ "@geekmidas/auth": "~9.3.0",
6952
+ "@geekmidas/cache": "~9.3.0",
6953
+ "@geekmidas/client": "~9.3.0",
6954
+ "@geekmidas/cloud": "~9.3.0",
6955
+ "@geekmidas/constructs": "~9.3.0",
6956
+ "@geekmidas/db": "~9.3.0",
6957
+ "@geekmidas/emailkit": "~9.3.0",
6958
+ "@geekmidas/envkit": "~9.3.0",
6959
+ "@geekmidas/errors": "~9.3.0",
6960
+ "@geekmidas/events": "~9.3.0",
6961
+ "@geekmidas/logger": "~9.3.0",
6962
+ "@geekmidas/rate-limit": "~9.3.0",
6963
+ "@geekmidas/schema": "~9.3.0",
6964
+ "@geekmidas/services": "~9.3.0",
6965
+ "@geekmidas/storage": "~9.3.0",
6966
+ "@geekmidas/studio": "~9.3.0",
6967
+ "@geekmidas/telescope": "~9.3.0",
6968
+ "@geekmidas/testkit": "~9.3.0",
6919
6969
  "@geekmidas/cli": CLI_VERSION
6920
6970
  };
6921
6971