@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/dist/index.mjs CHANGED
@@ -25,6 +25,7 @@ import fg from "fast-glob";
25
25
  import { parse as parse$1 } from "yaml";
26
26
  import { randomBytes } from "node:crypto";
27
27
  import { Cron } from "@geekmidas/constructs/crons";
28
+ import { InvalidCronExpressionError, toAwsCron } from "@geekmidas/manifest";
28
29
  import { Function } from "@geekmidas/constructs/functions";
29
30
  import { Queue } from "@geekmidas/constructs/queue";
30
31
  import { Subscriber } from "@geekmidas/constructs/subscribers";
@@ -36,7 +37,7 @@ import prompts from "prompts";
36
37
 
37
38
  //#region package.json
38
39
  var name = "@geekmidas/cli";
39
- var version = "9.2.0";
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 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 = join(outputDir, "crons");
381
383
  await mkdir(cronsDir, { recursive: true });
@@ -384,7 +386,7 @@ var CronGenerator = class extends ConstructGenerator {
384
386
  cronInfos.push({
385
387
  name: key,
386
388
  handler: relative(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
387
- schedule: construct.schedule || "rate(1 hour)",
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 } = 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 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.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",
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