@geekmidas/cli 9.1.0 → 9.2.1

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/{config-Bbu1JKvf.mjs → config-D7AVl-qm.mjs} +2 -2
  3. package/dist/{config-Bbu1JKvf.mjs.map → config-D7AVl-qm.mjs.map} +1 -1
  4. package/dist/{config-DujV8DbR.cjs → config-DcxHEHPB.cjs} +2 -2
  5. package/dist/{config-DujV8DbR.cjs.map → config-DcxHEHPB.cjs.map} +1 -1
  6. package/dist/config.cjs +2 -2
  7. package/dist/config.mjs +2 -2
  8. package/dist/index.cjs +30 -28
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.mjs +30 -28
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/{openapi-Cfwi0fqF.mjs → openapi-BlIiUahn.mjs} +14 -5
  13. package/dist/openapi-BlIiUahn.mjs.map +1 -0
  14. package/dist/{openapi-BzNOC7_i.cjs → openapi-C-YgZHyd.cjs} +14 -5
  15. package/dist/openapi-C-YgZHyd.cjs.map +1 -0
  16. package/dist/openapi.cjs +3 -3
  17. package/dist/openapi.mjs +3 -3
  18. package/dist/{setup-DDXUXzzl.mjs → setup-A-BX8JUm.mjs} +3 -3
  19. package/dist/{setup-DDXUXzzl.mjs.map → setup-A-BX8JUm.mjs.map} +1 -1
  20. package/dist/setup-BDB9lvEI.cjs +8 -0
  21. package/dist/{setup-Dh-B7YTX.mjs → setup-BzftAUve.mjs} +3 -3
  22. package/dist/{setup-WZ-xqAQO.cjs → setup-C2UhXWhN.cjs} +3 -3
  23. package/dist/{setup-WZ-xqAQO.cjs.map → setup-C2UhXWhN.cjs.map} +1 -1
  24. package/dist/workspace/index.cjs +1 -1
  25. package/dist/workspace/index.mjs +1 -1
  26. package/dist/workspace-CqXfzYyp.cjs +6704 -0
  27. package/dist/workspace-CqXfzYyp.cjs.map +1 -0
  28. package/dist/workspace-DrBWGtI7.mjs +6579 -0
  29. package/dist/workspace-DrBWGtI7.mjs.map +1 -0
  30. package/package.json +10 -10
  31. package/src/generators/CronGenerator.ts +1 -0
  32. package/src/generators/EndpointGenerator.ts +13 -0
  33. package/src/generators/FunctionGenerator.ts +1 -0
  34. package/src/generators/OpenApiTsGenerator.ts +21 -0
  35. package/src/generators/__tests__/CronGenerator.spec.ts +45 -1
  36. package/src/generators/__tests__/EndpointGenerator.spec.ts +80 -2
  37. package/src/generators/__tests__/FunctionGenerator.spec.ts +20 -0
  38. package/src/generators/__tests__/Generator.bustCache.spec.ts +16 -8
  39. package/src/init/versions.ts +19 -19
  40. package/dist/openapi-BzNOC7_i.cjs.map +0 -1
  41. package/dist/openapi-Cfwi0fqF.mjs.map +0 -1
  42. package/dist/setup-DLwhfyt-.cjs +0 -8
  43. package/dist/workspace-CQTT7HJQ.cjs +0 -4361
  44. package/dist/workspace-CQTT7HJQ.cjs.map +0 -1
  45. package/dist/workspace-D-37Ylqo.mjs +0 -4236
  46. package/dist/workspace-D-37Ylqo.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geekmidas/cli",
3
- "version": "9.1.0",
3
+ "version": "9.2.1",
4
4
  "description": "CLI tools for building Lambda handlers, server applications, and generating OpenAPI specs",
5
5
  "private": false,
6
6
  "type": "module",
@@ -81,12 +81,12 @@
81
81
  "prompts": "~2.4.2",
82
82
  "tsx": "~4.20.3",
83
83
  "yaml": "~2.8.2",
84
- "@geekmidas/constructs": "~9.1.0",
85
- "@geekmidas/envkit": "~9.1.0",
86
- "@geekmidas/errors": "~9.1.0",
87
- "@geekmidas/logger": "~9.1.0",
88
- "@geekmidas/manifest": "9.1.0",
89
- "@geekmidas/schema": "~9.1.0"
84
+ "@geekmidas/constructs": "~9.2.1",
85
+ "@geekmidas/errors": "~9.2.1",
86
+ "@geekmidas/logger": "~9.2.1",
87
+ "@geekmidas/manifest": "9.2.1",
88
+ "@geekmidas/envkit": "~9.2.1",
89
+ "@geekmidas/schema": "~9.2.1"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@types/lodash.kebabcase": "^4.1.9",
@@ -95,11 +95,11 @@
95
95
  "@types/prompts": "~2.4.9",
96
96
  "typescript": "^5.8.2",
97
97
  "vitest": "^3.2.4",
98
- "zod": "~4.1.13",
99
- "@geekmidas/testkit": "9.1.0"
98
+ "zod": "~4.6.6",
99
+ "@geekmidas/testkit": "9.2.1"
100
100
  },
101
101
  "peerDependencies": {
102
- "@geekmidas/telescope": "^9.1.0"
102
+ "@geekmidas/telescope": "^9.2.1"
103
103
  },
104
104
  "peerDependenciesMeta": {
105
105
  "@geekmidas/telescope": {
@@ -54,6 +54,7 @@ export class CronGenerator extends ConstructGenerator<
54
54
  environment: await construct.getEnvironment({
55
55
  markOptional: context.markOptional,
56
56
  }),
57
+ monitoring: construct.getMonitoring(),
57
58
  });
58
59
 
59
60
  logger.log(`Generated cron handler: ${key}`);
@@ -95,11 +95,22 @@ export class EndpointGenerator extends ConstructGenerator<
95
95
  await this.generateEndpointsFile(outputDir, constructs, context);
96
96
  const appFile = await this.generateAppFile(outputDir, context);
97
97
 
98
+ // One process serves every endpoint, so its monitors are the distinct
99
+ // ones across them: endpoints reading the same variable share its URL.
100
+ const monitoring = [
101
+ ...new Map(
102
+ constructs
103
+ .flatMap(({ construct }) => construct.getMonitoring() ?? [])
104
+ .map((monitor) => [JSON.stringify(monitor), monitor]),
105
+ ).values(),
106
+ ];
107
+
98
108
  routes.push({
99
109
  path: '*',
100
110
  method: 'ALL',
101
111
  handler: relative(process.cwd(), appFile),
102
112
  authorizer: 'none',
113
+ ...(monitoring.length ? { monitoring } : {}),
103
114
  });
104
115
 
105
116
  logger.log(
@@ -134,6 +145,7 @@ export class EndpointGenerator extends ConstructGenerator<
134
145
  markOptional: context.markOptional,
135
146
  }),
136
147
  authorizer: construct.authorizer?.name ?? 'none',
148
+ monitoring: construct.getMonitoring(),
137
149
  };
138
150
 
139
151
  routes.push(routeInfo);
@@ -166,6 +178,7 @@ export class EndpointGenerator extends ConstructGenerator<
166
178
  markOptional: context.markOptional,
167
179
  }),
168
180
  authorizer: construct.authorizer?.name ?? 'none',
181
+ monitoring: construct.getMonitoring(),
169
182
  };
170
183
 
171
184
  routes.push(routeInfo);
@@ -72,6 +72,7 @@ export class FunctionGenerator extends ConstructGenerator<
72
72
  environment: await construct.getEnvironment({
73
73
  markOptional: context.markOptional,
74
74
  }),
75
+ monitoring: construct.getMonitoring(),
75
76
  });
76
77
 
77
78
  logger.log(`Generated function handler: ${key}`);
@@ -426,6 +426,27 @@ export class OpenApiTsGenerator {
426
426
 
427
427
  // Remove $defs from the schema before converting to interface
428
428
  const { $defs, ...schemaWithoutDefs } = jsonSchema;
429
+
430
+ // A schema that *is* a registered schema converts to nothing but a
431
+ // `$ref` at it, and the def it points at has already been collected
432
+ // above — so emitting a declaration here as well produces
433
+ // `export type User = User`, a circular alias that is not a type.
434
+ //
435
+ // Zod used to inline this case and only started emitting the `$ref` in
436
+ // 4.6, which is how the bug arrived without the generator changing.
437
+ const ref = (schemaWithoutDefs as { $ref?: string }).$ref;
438
+ if (
439
+ ref &&
440
+ Object.keys(schemaWithoutDefs).every(
441
+ (k) => k === '$ref' || k === '$schema',
442
+ )
443
+ ) {
444
+ const target = ref.split('/').pop();
445
+ // The def's own interface is the declaration. Only alias it when the
446
+ // names actually differ, which is when the alias says something.
447
+ return target === name ? null : `export type ${name} = ${target};`;
448
+ }
449
+
429
450
  return this.jsonSchemaToInterface(schemaWithoutDefs, name);
430
451
  } catch {
431
452
  return null;
@@ -1,6 +1,11 @@
1
1
  import { mkdir, readFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
- import type { Cron, ScheduleExpression } from '@geekmidas/constructs/crons';
3
+ import {
4
+ type Cron,
5
+ CronBuilder,
6
+ type ScheduleExpression,
7
+ } from '@geekmidas/constructs/crons';
8
+ import { heartbeat } from '@geekmidas/constructs/monitors';
4
9
  import { itWithDir } from '@geekmidas/testkit/os';
5
10
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
11
  import {
@@ -145,6 +150,45 @@ describe('CronGenerator', () => {
145
150
  expect(hourlyCleanupContent).toContain('import { hourlyCleanup }');
146
151
  });
147
152
 
153
+ it('records the cron’s monitors in its manifest entry', async () => {
154
+ const monitored = new CronBuilder()
155
+ .schedule('cron(0 8 * * ? *)')
156
+ .monitor(heartbeat.betterStack('MONITORING_URL'))
157
+ .handle(async () => ({}));
158
+ const plain = createTestCron();
159
+
160
+ const cronInfos = await generator.build(
161
+ context,
162
+ [
163
+ {
164
+ key: 'monitored',
165
+ name: 'monitored',
166
+ construct: monitored,
167
+ path: {
168
+ absolute: join(tempDir, 'monitored.ts'),
169
+ relative: 'monitored.ts',
170
+ },
171
+ },
172
+ {
173
+ key: 'plain',
174
+ name: 'plain',
175
+ construct: plain,
176
+ path: {
177
+ absolute: join(tempDir, 'plain.ts'),
178
+ relative: 'plain.ts',
179
+ },
180
+ },
181
+ ],
182
+ outputDir,
183
+ { provider: 'aws-lambda' },
184
+ );
185
+
186
+ expect(cronInfos[0].monitoring).toEqual([
187
+ { type: 'heartbeat', provider: 'betterStack', env: 'MONITORING_URL' },
188
+ ]);
189
+ expect(cronInfos[1].monitoring).toBeUndefined();
190
+ });
191
+
148
192
  it('should use default schedule when none provided', async () => {
149
193
  // Create a cron with empty schedule that will use default
150
194
  const cronWithDefaultSchedule = createTestCron(undefined, 30);
@@ -1,7 +1,9 @@
1
- import { mkdir, readFile } from 'node:fs/promises';
1
+ import { mkdir, mkdtemp, readFile, rm } from 'node:fs/promises';
2
+ import { tmpdir } from 'node:os';
2
3
  import { join } from 'node:path';
3
4
  import type { HttpMethod } from '@geekmidas/constructs';
4
- import type { Endpoint } from '@geekmidas/constructs/endpoints';
5
+ import { type Endpoint, e } from '@geekmidas/constructs/endpoints';
6
+ import { heartbeat } from '@geekmidas/constructs/monitors';
5
7
  import { itWithDir } from '@geekmidas/testkit/os';
6
8
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
7
9
  import {
@@ -51,6 +53,82 @@ describe('EndpointGenerator', () => {
51
53
  },
52
54
  });
53
55
 
56
+ describe('monitoring', () => {
57
+ const MONITOR = {
58
+ type: 'heartbeat',
59
+ provider: 'betterStack',
60
+ env: 'MONITORING_URL',
61
+ };
62
+ let dir: string;
63
+
64
+ beforeEach(async () => {
65
+ dir = await mkdtemp(join(tmpdir(), 'endpoint-monitoring-'));
66
+ await mkdir(join(dir, 'output'), { recursive: true });
67
+ });
68
+
69
+ afterEach(async () => {
70
+ await rm(dir, { recursive: true, force: true });
71
+ });
72
+
73
+ const monitoredAt = (key: string, path: string) => {
74
+ const construct = createTestEndpointConstruct(key, path, 'GET', dir);
75
+ construct.construct = e
76
+ .monitor(heartbeat.betterStack('MONITORING_URL'))
77
+ .get(path)
78
+ .handle(async () => ({}));
79
+ return construct;
80
+ };
81
+
82
+ it.each([
83
+ 'aws-lambda',
84
+ 'aws-apigatewayv2',
85
+ ] as const)('records each route’s monitors (%s)', async (provider) => {
86
+ const routes = await generator.build(
87
+ context,
88
+ [
89
+ monitoredAt('monitored', '/monitored'),
90
+ createTestEndpointConstruct('plain', '/plain', 'GET', dir),
91
+ ],
92
+ join(dir, 'output'),
93
+ { provider },
94
+ );
95
+
96
+ expect(routes.find((r) => r.path === '/monitored')?.monitoring).toEqual([
97
+ MONITOR,
98
+ ]);
99
+ expect(
100
+ routes.find((r) => r.path === '/plain')?.monitoring,
101
+ ).toBeUndefined();
102
+ });
103
+
104
+ it('records the distinct monitors across endpoints on the server route', async () => {
105
+ const routes = await generator.build(
106
+ context,
107
+ [
108
+ monitoredAt('first', '/first'),
109
+ monitoredAt('second', '/second'),
110
+ createTestEndpointConstruct('plain', '/plain', 'GET', dir),
111
+ ],
112
+ join(dir, 'output'),
113
+ { provider: 'server' },
114
+ );
115
+
116
+ expect(routes).toHaveLength(1);
117
+ expect(routes[0].monitoring).toEqual([MONITOR]);
118
+ });
119
+
120
+ it('records no monitoring on a server whose endpoints have none', async () => {
121
+ const routes = await generator.build(
122
+ context,
123
+ [createTestEndpointConstruct('plain', '/plain', 'GET', dir)],
124
+ join(dir, 'output'),
125
+ { provider: 'server' },
126
+ );
127
+
128
+ expect(routes[0].monitoring).toBeUndefined();
129
+ });
130
+ });
131
+
54
132
  itWithDir('should generate a single server app file', async ({ dir }) => {
55
133
  const outputDir = join(dir, 'output');
56
134
  const routesDir = join(dir, 'routes');
@@ -2,6 +2,7 @@ import { readFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
3
  import type { Function } from '@geekmidas/constructs/functions';
4
4
  import { f } from '@geekmidas/constructs/functions';
5
+ import { heartbeat } from '@geekmidas/constructs/monitors';
5
6
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
7
  import { z } from 'zod';
7
8
  import {
@@ -120,6 +121,25 @@ describe('FunctionGenerator', () => {
120
121
  expect(sendEmailContent).toContain('import { sendEmail }');
121
122
  });
122
123
 
124
+ it('records the function’s monitors in its manifest entry', async () => {
125
+ const monitored = createTestFunctionConstruct('monitored');
126
+ monitored.construct = f
127
+ .monitor(heartbeat.betterStack('MONITORING_URL'))
128
+ .handle(async () => ({}));
129
+
130
+ const functionInfos = await generator.build(
131
+ context,
132
+ [monitored, createTestFunctionConstruct('plain')],
133
+ outputDir,
134
+ { provider: 'aws-lambda' },
135
+ );
136
+
137
+ expect(functionInfos[0].monitoring).toEqual([
138
+ { type: 'heartbeat', provider: 'betterStack', env: 'MONITORING_URL' },
139
+ ]);
140
+ expect(functionInfos[1].monitoring).toBeUndefined();
141
+ });
142
+
123
143
  it('should generate correct relative import paths', async () => {
124
144
  const construct: GeneratedConstruct<Function<any, any, any, any>> = {
125
145
  key: 'deepFunction',
@@ -7,17 +7,25 @@ import { EndpointGenerator } from '../EndpointGenerator';
7
7
  import { clearZodGlobalRegistry } from '../Generator';
8
8
 
9
9
  describe('clearZodGlobalRegistry', () => {
10
- it('removes an id from the global registry so the same id can be re-registered', () => {
11
- // Register once — succeeds
12
- z.object({ x: z.string() }).meta({ id: 'BustCacheSchema_A' });
10
+ it('removes a registered id from the global registry', () => {
11
+ const registry = (
12
+ globalThis as {
13
+ __zod_globalRegistry?: { _idmap?: Map<string, unknown> };
14
+ }
15
+ ).__zod_globalRegistry;
13
16
 
14
- // Re-registering without clearing throws
15
- expect(() =>
16
- z.object({ y: z.string() }).meta({ id: 'BustCacheSchema_A' }),
17
- ).toThrow(/already exists in the registry/);
17
+ z.object({ x: z.string() }).meta({ id: 'BustCacheSchema_A' });
18
+ expect(registry?._idmap?.has('BustCacheSchema_A')).toBe(true);
18
19
 
19
- // After clearing, the id can be registered again
20
+ // The contract is that the id is gone, asserted on the registry itself.
21
+ // This used to be asserted by re-registering and expecting a throw, which
22
+ // stopped meaning anything in Zod 4.6: a duplicate id is accepted now
23
+ // rather than rejected. That made the test pass for the wrong reason
24
+ // first, and then fail for the wrong reason — neither of which was ever
25
+ // about `clearZodGlobalRegistry`.
20
26
  clearZodGlobalRegistry();
27
+ expect(registry?._idmap?.has('BustCacheSchema_A')).toBe(false);
28
+
21
29
  expect(() =>
22
30
  z.object({ z: z.string() }).meta({ id: 'BustCacheSchema_A' }),
23
31
  ).not.toThrow();
@@ -27,25 +27,25 @@ export const CLI_VERSION = `~${pkg.version}`;
27
27
  * Run: pnpm --filter @geekmidas/cli sync-versions
28
28
  */
29
29
  export const GEEKMIDAS_VERSIONS = {
30
- '@geekmidas/audit': '~9.0.2',
31
- '@geekmidas/auth': '~9.0.2',
32
- '@geekmidas/cache': '~9.0.2',
33
- '@geekmidas/client': '~9.0.2',
34
- '@geekmidas/cloud': '~9.0.2',
35
- '@geekmidas/constructs': '~9.0.2',
36
- '@geekmidas/db': '~9.0.2',
37
- '@geekmidas/emailkit': '~9.0.2',
38
- '@geekmidas/envkit': '~9.0.2',
39
- '@geekmidas/errors': '~9.0.2',
40
- '@geekmidas/events': '~9.0.2',
41
- '@geekmidas/logger': '~9.0.2',
42
- '@geekmidas/rate-limit': '~9.0.2',
43
- '@geekmidas/schema': '~9.0.2',
44
- '@geekmidas/services': '~9.0.2',
45
- '@geekmidas/storage': '~9.0.2',
46
- '@geekmidas/studio': '~9.0.2',
47
- '@geekmidas/telescope': '~9.0.2',
48
- '@geekmidas/testkit': '~9.0.2',
30
+ '@geekmidas/audit': '~9.2.0',
31
+ '@geekmidas/auth': '~9.2.0',
32
+ '@geekmidas/cache': '~9.2.0',
33
+ '@geekmidas/client': '~9.2.0',
34
+ '@geekmidas/cloud': '~9.2.0',
35
+ '@geekmidas/constructs': '~9.2.0',
36
+ '@geekmidas/db': '~9.2.0',
37
+ '@geekmidas/emailkit': '~9.2.0',
38
+ '@geekmidas/envkit': '~9.2.0',
39
+ '@geekmidas/errors': '~9.2.0',
40
+ '@geekmidas/events': '~9.2.0',
41
+ '@geekmidas/logger': '~9.2.0',
42
+ '@geekmidas/rate-limit': '~9.2.0',
43
+ '@geekmidas/schema': '~9.2.0',
44
+ '@geekmidas/services': '~9.2.0',
45
+ '@geekmidas/storage': '~9.2.0',
46
+ '@geekmidas/studio': '~9.2.0',
47
+ '@geekmidas/telescope': '~9.2.0',
48
+ '@geekmidas/testkit': '~9.2.0',
49
49
  '@geekmidas/cli': CLI_VERSION,
50
50
  } as const;
51
51