@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/dist/index.mjs CHANGED
@@ -6,7 +6,7 @@ import { getCredentialsPath, getDokployCredentials, getDokployRegistryId, getDok
6
6
  import { createStageSecrets, generateDbPassword, generateDbUrl, generateFullstackCustomSecrets, rotateServicePassword } from "./fullstack-secrets-l8s3II_H.mjs";
7
7
  import { getKeyPath, maskPassword, readStageSecrets, secretsExist, setCustomSecret, toEmbeddableSecrets, writeStageSecrets } from "./storage-dbb9RyBl.mjs";
8
8
  import { createCredentialsPreload, createEntryWrapper, findAvailablePort, isPortAvailable, loadEnvFiles, loadSecretsForApp, prepareEntryCredentials, resolveServicePorts, rewriteUrlsWithPorts, setupCommand, startWorkspaceServices } from "./setup-A-BX8JUm.mjs";
9
- import { ConstructGenerator, EndpointGenerator, OPENAPI_OUTPUT_PATH, generateOpenApi, isPartitionedRoutes, normalizeRoutes, openapiCommand, resolveOpenApiConfig } from "./openapi-BlIiUahn.mjs";
9
+ import { ConstructGenerator, EndpointGenerator, OPENAPI_OUTPUT_PATH, generateOpenApi, isPartitionedRoutes, normalizeRoutes, openapiCommand, resolveOpenApiConfig } from "./openapi-Dm1_sCxe.mjs";
10
10
  import { DokployApi } from "./dokploy-api-sfZFlWuE.mjs";
11
11
  import { encryptSecrets } from "./encryption-CO5Q4Bhf.mjs";
12
12
  import { CachedStateProvider } from "./CachedStateProvider-CzyFct42.mjs";
@@ -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, cronPeriod, 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.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 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 });
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: 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: 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 } = 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 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 ConstructGenerator {
438
489
  handler: 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