@geekmidas/cli 9.3.0 → 9.5.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,81 @@
1
1
  # @geekmidas/cli
2
2
 
3
+ ## 9.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#462](https://github.com/geekmidas/toolbox/pull/462) [`9a4cef0`](https://github.com/geekmidas/toolbox/commit/9a4cef04d59cf001b597c697cdf1a0e096109347) Thanks [@geekmidas](https://github.com/geekmidas)! - Queue handlers can retry only the messages that failed
8
+
9
+ A handler now receives `records` beside `messages`: the same batch, each message with the id its transport gave it (the SQS message id deployed, a generated id under `gkm dev`). Returning `{ failed: [...ids] }` retries only those records; the rest of the batch is acknowledged.
10
+
11
+ ```ts
12
+ export const ordersQueue = q
13
+ .queue("orders")
14
+ .message(OrderSchema)
15
+ .handle(async ({ records, services }) => {
16
+ const failed: string[] = [];
17
+ for (const { id, message } of records) {
18
+ try {
19
+ await services.orders.fulfil(message);
20
+ } catch {
21
+ failed.push(id);
22
+ }
23
+ }
24
+ return { failed };
25
+ });
26
+ ```
27
+
28
+ Before, a handler could only retry the whole batch by throwing, so one bad message redelivered every message that had already succeeded. Throwing still does that, and a handler that returns nothing still acknowledges the batch, so existing queues behave as before.
29
+
30
+ `TestQueueAdaptor.invoke` takes `records` as well as `messages`, to drive a handler with chosen ids. `QueueRecord`, `QueueResult` and `isQueueResult` are exported from `@geekmidas/constructs/queue`.
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [[`9a4cef0`](https://github.com/geekmidas/toolbox/commit/9a4cef04d59cf001b597c697cdf1a0e096109347)]:
35
+ - @geekmidas/constructs@9.5.0
36
+ - @geekmidas/envkit@9.5.0
37
+ - @geekmidas/errors@9.5.0
38
+ - @geekmidas/logger@9.5.0
39
+ - @geekmidas/manifest@9.5.0
40
+ - @geekmidas/schema@9.5.0
41
+ - @geekmidas/telescope@9.5.0
42
+
43
+ ## 9.4.0
44
+
45
+ ### Minor Changes
46
+
47
+ - [#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()`
48
+
49
+ **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.
50
+
51
+ 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:
52
+
53
+ ```ts
54
+ export const nightlyReport = c
55
+ .schedule("cron(0 8 * * MON-FRI)")
56
+ .uptime(heartbeat.betterStack("MONITORING_URL"))
57
+ .handle(async () => {});
58
+ ```
59
+
60
+ 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`:
61
+
62
+ ```ts
63
+ uptime: { type: 'heartbeat', provider: 'betterStack', env: 'MONITORING_URL', period: 259200 }
64
+ ```
65
+
66
+ `MonitorInfo` in `@geekmidas/manifest` is replaced by `UptimeInfo`.
67
+
68
+ ### Patch Changes
69
+
70
+ - Updated dependencies [[`b03c43d`](https://github.com/geekmidas/toolbox/commit/b03c43dfd2c86b1daa7f0a47f43e5fb2e518518b)]:
71
+ - @geekmidas/manifest@9.4.0
72
+ - @geekmidas/constructs@9.4.0
73
+ - @geekmidas/envkit@9.4.0
74
+ - @geekmidas/errors@9.4.0
75
+ - @geekmidas/logger@9.4.0
76
+ - @geekmidas/schema@9.4.0
77
+ - @geekmidas/telescope@9.4.0
78
+
3
79
  ## 9.3.0
4
80
 
5
81
  ### Minor Changes
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');
@@ -37,7 +37,7 @@ const prompts = require_chunk.__toESM(require("prompts"));
37
37
 
38
38
  //#region package.json
39
39
  var name = "@geekmidas/cli";
40
- var version = "9.2.1";
40
+ var version = "9.4.0";
41
41
  var description = "CLI tools for building Lambda handlers, server applications, and generating OpenAPI specs";
42
42
  var private$1 = false;
43
43
  var type = "module";
@@ -383,14 +383,19 @@ var CronGenerator = class extends require_openapi.ConstructGenerator {
383
383
  await (0, node_fs_promises.mkdir)(cronsDir, { recursive: true });
384
384
  for (const { key, construct, path } of constructs) {
385
385
  const handlerFile = await this.generateCronHandler(cronsDir, path.relative, key, context);
386
+ const schedule = schedules.get(key);
387
+ const uptime = construct.getUptime();
386
388
  cronInfos.push({
387
389
  name: key,
388
390
  handler: (0, node_path.relative)(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
389
- schedule: schedules.get(key),
391
+ schedule,
390
392
  timeout: construct.timeout,
391
393
  memorySize: construct.memorySize,
392
394
  environment: await construct.getEnvironment({ markOptional: context.markOptional }),
393
- monitoring: construct.getMonitoring()
395
+ ...uptime && { uptime: {
396
+ ...uptime,
397
+ period: (0, __geekmidas_manifest.cronPeriod)(schedule)
398
+ } }
394
399
  });
395
400
  logger$13.log(`Generated cron handler: ${key}`);
396
401
  }
@@ -484,8 +489,7 @@ var FunctionGenerator = class extends require_openapi.ConstructGenerator {
484
489
  handler: (0, node_path.relative)(process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
485
490
  timeout: construct.timeout,
486
491
  memorySize: construct.memorySize,
487
- environment: await construct.getEnvironment({ markOptional: context.markOptional }),
488
- monitoring: construct.getMonitoring()
492
+ environment: await construct.getEnvironment({ markOptional: context.markOptional })
489
493
  });
490
494
  logger$13.log(`Generated function handler: ${key}`);
491
495
  }
@@ -594,6 +598,8 @@ import type { EnvironmentParser } from '@geekmidas/envkit';
594
598
  import type { Logger } from '@geekmidas/logger';
595
599
  import { EventConnectionFactory, Subscriber } from '@geekmidas/events';
596
600
  import type { EventConnection, EventSubscriber } from '@geekmidas/events';
601
+ import { randomUUID } from 'node:crypto';
602
+ import { isQueueResult } from '@geekmidas/constructs/queue';
597
603
  import { ServiceDiscovery } from '@geekmidas/services';
598
604
  ${imports}
599
605
 
@@ -646,12 +652,21 @@ export async function setupQueues(
646
652
  return;
647
653
  }
648
654
 
649
- await queue.handler({
655
+ // One message per delivery locally, so it gets an id of its own for
656
+ // the handler to report it by, as SQS's message id is deployed.
657
+ const id = randomUUID();
658
+ const result = await queue.handler({
650
659
  messages: [validation.value],
660
+ records: [{ id, message: validation.value }],
651
661
  services: services,
652
662
  logger: queue.logger,
653
663
  });
654
664
 
665
+ if (isQueueResult(result) && result.failed.includes(id)) {
666
+ logger.error({ queue: queue.name }, 'Queue handler reported the message as failed');
667
+ return;
668
+ }
669
+
655
670
  logger.debug({ queue: queue.name }, 'Successfully processed queue message');
656
671
  } catch (error) {
657
672
  logger.error({ error, queue: queue.name }, 'Failed to process queue message');
@@ -6943,25 +6958,25 @@ const CLI_VERSION = `~${pkg.version}`;
6943
6958
  * Run: pnpm --filter @geekmidas/cli sync-versions
6944
6959
  */
6945
6960
  const GEEKMIDAS_VERSIONS = {
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",
6961
+ "@geekmidas/audit": "~9.4.0",
6962
+ "@geekmidas/auth": "~9.4.0",
6963
+ "@geekmidas/cache": "~9.4.0",
6964
+ "@geekmidas/client": "~9.4.0",
6965
+ "@geekmidas/cloud": "~9.4.0",
6966
+ "@geekmidas/constructs": "~9.4.0",
6967
+ "@geekmidas/db": "~9.4.0",
6968
+ "@geekmidas/emailkit": "~9.4.0",
6969
+ "@geekmidas/envkit": "~9.4.0",
6970
+ "@geekmidas/errors": "~9.4.0",
6971
+ "@geekmidas/events": "~9.4.0",
6972
+ "@geekmidas/logger": "~9.4.0",
6973
+ "@geekmidas/rate-limit": "~9.4.0",
6974
+ "@geekmidas/schema": "~9.4.0",
6975
+ "@geekmidas/services": "~9.4.0",
6976
+ "@geekmidas/storage": "~9.4.0",
6977
+ "@geekmidas/studio": "~9.4.0",
6978
+ "@geekmidas/telescope": "~9.4.0",
6979
+ "@geekmidas/testkit": "~9.4.0",
6965
6980
  "@geekmidas/cli": CLI_VERSION
6966
6981
  };
6967
6982