@geekmidas/cli 0.1.0 → 0.2.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.
Files changed (146) hide show
  1. package/README.md +63 -13
  2. package/dist/{CronGenerator-Ctl4USy4.cjs → CronGenerator-1PflEYe2.cjs} +8 -7
  3. package/dist/CronGenerator-1PflEYe2.cjs.map +1 -0
  4. package/dist/{CronGenerator-ClbRcmz_.mjs → CronGenerator-DXRfHQcV.mjs} +6 -5
  5. package/dist/CronGenerator-DXRfHQcV.mjs.map +1 -0
  6. package/dist/{EndpointGenerator-Dj7AumHi.cjs → EndpointGenerator-BbGrDiCP.cjs} +134 -34
  7. package/dist/EndpointGenerator-BbGrDiCP.cjs.map +1 -0
  8. package/dist/{EndpointGenerator-uBA1ixUw.mjs → EndpointGenerator-BmZ9BxbO.mjs} +132 -32
  9. package/dist/EndpointGenerator-BmZ9BxbO.mjs.map +1 -0
  10. package/dist/{FunctionGenerator-DN681IUn.cjs → FunctionGenerator-Clw64SwQ.cjs} +8 -7
  11. package/dist/FunctionGenerator-Clw64SwQ.cjs.map +1 -0
  12. package/dist/{FunctionGenerator-crAa-JC7.mjs → FunctionGenerator-DOEB_yPh.mjs} +6 -5
  13. package/dist/FunctionGenerator-DOEB_yPh.mjs.map +1 -0
  14. package/dist/{Generator-C3tYSTQY.cjs → Generator-CDoEXCDg.cjs} +2 -2
  15. package/dist/Generator-CDoEXCDg.cjs.map +1 -0
  16. package/dist/{Generator-CDt4pB3W.mjs → Generator-UanJW0_V.mjs} +1 -1
  17. package/dist/Generator-UanJW0_V.mjs.map +1 -0
  18. package/dist/SubscriberGenerator-BfMZCVNy.cjs +204 -0
  19. package/dist/SubscriberGenerator-BfMZCVNy.cjs.map +1 -0
  20. package/dist/SubscriberGenerator-D2u00NI3.mjs +198 -0
  21. package/dist/SubscriberGenerator-D2u00NI3.mjs.map +1 -0
  22. package/dist/build/index.cjs +10 -9
  23. package/dist/build/index.mjs +8 -7
  24. package/dist/build/manifests.cjs +1 -1
  25. package/dist/build/manifests.mjs +1 -1
  26. package/dist/build/providerResolver.cjs +1 -1
  27. package/dist/build-BBhlEjf5.cjs +89 -0
  28. package/dist/build-BBhlEjf5.cjs.map +1 -0
  29. package/dist/build-kY-lG30Q.mjs +83 -0
  30. package/dist/build-kY-lG30Q.mjs.map +1 -0
  31. package/dist/{chunk-CsX-DzYB.cjs → chunk-CUT6urMc.cjs} +0 -12
  32. package/dist/{config-RcNESK0T.cjs → config-D1EpSGk6.cjs} +2 -2
  33. package/dist/{config-RcNESK0T.cjs.map → config-D1EpSGk6.cjs.map} +1 -1
  34. package/dist/{config-CXxYmz_o.mjs → config-U-mdW-7Y.mjs} +1 -1
  35. package/dist/{config-CXxYmz_o.mjs.map → config-U-mdW-7Y.mjs.map} +1 -1
  36. package/dist/config.cjs +1 -1
  37. package/dist/config.mjs +1 -1
  38. package/dist/generators/CronGenerator.cjs +2 -2
  39. package/dist/generators/CronGenerator.mjs +2 -2
  40. package/dist/generators/EndpointGenerator.cjs +2 -2
  41. package/dist/generators/EndpointGenerator.mjs +2 -2
  42. package/dist/generators/FunctionGenerator.cjs +2 -2
  43. package/dist/generators/FunctionGenerator.mjs +2 -2
  44. package/dist/generators/Generator.cjs +1 -1
  45. package/dist/generators/Generator.mjs +1 -1
  46. package/dist/generators/SubscriberGenerator.cjs +4 -0
  47. package/dist/generators/SubscriberGenerator.mjs +4 -0
  48. package/dist/generators/index.cjs +8 -6
  49. package/dist/generators/index.mjs +6 -5
  50. package/dist/index.cjs +18 -14
  51. package/dist/index.cjs.map +1 -1
  52. package/dist/index.mjs +15 -11
  53. package/dist/index.mjs.map +1 -1
  54. package/dist/{manifests-HX4z4kkz.mjs → manifests-BrJXpHrf.mjs} +5 -4
  55. package/dist/manifests-BrJXpHrf.mjs.map +1 -0
  56. package/dist/{manifests-BTtfDMX8.cjs → manifests-D0saShvH.cjs} +6 -5
  57. package/dist/manifests-D0saShvH.cjs.map +1 -0
  58. package/dist/{openapi-BivnatiC.mjs → openapi-BQx3_JbM.mjs} +4 -4
  59. package/dist/openapi-BQx3_JbM.mjs.map +1 -0
  60. package/dist/{openapi-DW-qF3oW.cjs → openapi-CMLr04cz.cjs} +6 -6
  61. package/dist/openapi-CMLr04cz.cjs.map +1 -0
  62. package/dist/{openapi-react-query-lgS7AVEz.mjs → openapi-react-query-DbrWwQzb.mjs} +3 -2
  63. package/dist/openapi-react-query-DbrWwQzb.mjs.map +1 -0
  64. package/dist/{openapi-react-query-J0BzBHhN.cjs → openapi-react-query-Dvjqx_Eo.cjs} +4 -3
  65. package/dist/openapi-react-query-Dvjqx_Eo.cjs.map +1 -0
  66. package/dist/openapi-react-query.cjs +1 -1
  67. package/dist/openapi-react-query.mjs +1 -1
  68. package/dist/openapi.cjs +4 -4
  69. package/dist/openapi.mjs +4 -4
  70. package/dist/{providerResolver-Cs-0YCaP.cjs → providerResolver-DgvzNfP4.cjs} +1 -1
  71. package/dist/{providerResolver-Cs-0YCaP.cjs.map → providerResolver-DgvzNfP4.cjs.map} +1 -1
  72. package/examples/cron-example.ts +1 -1
  73. package/examples/function-example.ts +1 -1
  74. package/examples/logger.ts +1 -1
  75. package/package.json +6 -3
  76. package/src/__tests__/openapi-react-query.spec.ts +506 -0
  77. package/src/__tests__/openapi.spec.ts +362 -0
  78. package/src/__tests__/test-helpers.ts +10 -8
  79. package/src/build/__tests__/index-new.spec.ts +41 -42
  80. package/src/build/index.ts +89 -28
  81. package/src/build/manifests.ts +4 -1
  82. package/src/build/types.ts +2 -2
  83. package/src/generators/CronGenerator.ts +3 -2
  84. package/src/generators/EndpointGenerator.ts +141 -42
  85. package/src/generators/FunctionGenerator.ts +3 -2
  86. package/src/generators/Generator.ts +1 -1
  87. package/src/generators/SubscriberGenerator.ts +271 -0
  88. package/src/generators/__tests__/CronGenerator.spec.ts +1 -1
  89. package/src/generators/__tests__/EndpointGenerator.spec.ts +33 -11
  90. package/src/generators/__tests__/FunctionGenerator.spec.ts +21 -22
  91. package/src/generators/__tests__/SubscriberGenerator.spec.ts +341 -0
  92. package/src/generators/index.ts +1 -0
  93. package/src/openapi-react-query.ts +2 -1
  94. package/src/openapi.ts +1 -1
  95. package/src/types.ts +18 -0
  96. package/dist/CronGenerator-ClbRcmz_.mjs.map +0 -1
  97. package/dist/CronGenerator-Ctl4USy4.cjs.map +0 -1
  98. package/dist/EndpointGenerator-Dj7AumHi.cjs.map +0 -1
  99. package/dist/EndpointGenerator-uBA1ixUw.mjs.map +0 -1
  100. package/dist/FunctionGenerator-DN681IUn.cjs.map +0 -1
  101. package/dist/FunctionGenerator-crAa-JC7.mjs.map +0 -1
  102. package/dist/Generator-C3tYSTQY.cjs.map +0 -1
  103. package/dist/Generator-CDt4pB3W.mjs.map +0 -1
  104. package/dist/__tests__/config.spec.cjs +0 -98
  105. package/dist/__tests__/config.spec.cjs.map +0 -1
  106. package/dist/__tests__/config.spec.mjs +0 -97
  107. package/dist/__tests__/config.spec.mjs.map +0 -1
  108. package/dist/__tests__/test-helpers.cjs +0 -14
  109. package/dist/__tests__/test-helpers.mjs +0 -4
  110. package/dist/build/__tests__/index-new.spec.cjs +0 -286
  111. package/dist/build/__tests__/index-new.spec.cjs.map +0 -1
  112. package/dist/build/__tests__/index-new.spec.mjs +0 -285
  113. package/dist/build/__tests__/index-new.spec.mjs.map +0 -1
  114. package/dist/build-BZdwxCLW.mjs +0 -64
  115. package/dist/build-BZdwxCLW.mjs.map +0 -1
  116. package/dist/build-BfQFnU5-.cjs +0 -70
  117. package/dist/build-BfQFnU5-.cjs.map +0 -1
  118. package/dist/esm-9eeZntth.mjs +0 -3777
  119. package/dist/esm-9eeZntth.mjs.map +0 -1
  120. package/dist/esm-Crmo4h9t.cjs +0 -4392
  121. package/dist/esm-Crmo4h9t.cjs.map +0 -1
  122. package/dist/esm-CsJbr7gi.mjs +0 -3
  123. package/dist/esm-w09tAC4l.cjs +0 -8
  124. package/dist/generators/__tests__/CronGenerator.spec.cjs +0 -216
  125. package/dist/generators/__tests__/CronGenerator.spec.cjs.map +0 -1
  126. package/dist/generators/__tests__/CronGenerator.spec.mjs +0 -215
  127. package/dist/generators/__tests__/CronGenerator.spec.mjs.map +0 -1
  128. package/dist/generators/__tests__/EndpointGenerator.spec.cjs +0 -182
  129. package/dist/generators/__tests__/EndpointGenerator.spec.cjs.map +0 -1
  130. package/dist/generators/__tests__/EndpointGenerator.spec.mjs +0 -181
  131. package/dist/generators/__tests__/EndpointGenerator.spec.mjs.map +0 -1
  132. package/dist/generators/__tests__/FunctionGenerator.spec.cjs +0 -152
  133. package/dist/generators/__tests__/FunctionGenerator.spec.cjs.map +0 -1
  134. package/dist/generators/__tests__/FunctionGenerator.spec.mjs +0 -151
  135. package/dist/generators/__tests__/FunctionGenerator.spec.mjs.map +0 -1
  136. package/dist/manifests-BTtfDMX8.cjs.map +0 -1
  137. package/dist/manifests-HX4z4kkz.mjs.map +0 -1
  138. package/dist/openapi-BivnatiC.mjs.map +0 -1
  139. package/dist/openapi-DW-qF3oW.cjs.map +0 -1
  140. package/dist/openapi-react-query-J0BzBHhN.cjs.map +0 -1
  141. package/dist/openapi-react-query-lgS7AVEz.mjs.map +0 -1
  142. package/dist/test-helpers-ARd8GDgx.cjs +0 -199
  143. package/dist/test-helpers-ARd8GDgx.cjs.map +0 -1
  144. package/dist/test-helpers-DdVBk23F.mjs +0 -133
  145. package/dist/test-helpers-DdVBk23F.mjs.map +0 -1
  146. /package/dist/{generators-_pY7sHy1.cjs → generators-CEKtVh81.cjs} +0 -0
@@ -0,0 +1,271 @@
1
+ import { mkdir, writeFile } from 'node:fs/promises';
2
+ import { dirname, join, relative } from 'node:path';
3
+ import { Subscriber } from '@geekmidas/constructs/subscribers';
4
+ import type { BuildContext } from '../build/types';
5
+ import type { SubscriberInfo } from '../types';
6
+ import {
7
+ ConstructGenerator,
8
+ type GeneratedConstruct,
9
+ type GeneratorOptions,
10
+ } from './Generator';
11
+
12
+ export class SubscriberGenerator extends ConstructGenerator<
13
+ Subscriber<any, any, any, any, any, any>,
14
+ SubscriberInfo[]
15
+ > {
16
+ isConstruct(value: any): value is Subscriber<any, any, any, any, any, any> {
17
+ return Subscriber.isSubscriber(value);
18
+ }
19
+
20
+ async build(
21
+ context: BuildContext,
22
+ constructs: GeneratedConstruct<Subscriber<any, any, any, any, any, any>>[],
23
+ outputDir: string,
24
+ options?: GeneratorOptions,
25
+ ): Promise<SubscriberInfo[]> {
26
+ const provider = options?.provider || 'aws-lambda';
27
+ const logger = console;
28
+ const subscriberInfos: SubscriberInfo[] = [];
29
+
30
+ if (constructs.length === 0) {
31
+ return subscriberInfos;
32
+ }
33
+
34
+ if (provider === 'server') {
35
+ // Generate subscribers.ts for server-based polling
36
+ await this.generateServerSubscribersFile(outputDir, constructs);
37
+
38
+ logger.log(
39
+ `Generated server subscribers file with ${constructs.length} subscribers (polling mode)`,
40
+ );
41
+
42
+ // Return empty array as server subscribers don't have individual handlers
43
+ return subscriberInfos;
44
+ }
45
+
46
+ if (provider !== 'aws-lambda') {
47
+ return subscriberInfos;
48
+ }
49
+
50
+ // Create subscribers subdirectory
51
+ const subscribersDir = join(outputDir, 'subscribers');
52
+ await mkdir(subscribersDir, { recursive: true });
53
+
54
+ // Generate subscriber handlers
55
+ for (const { key, construct, path } of constructs) {
56
+ const handlerFile = await this.generateSubscriberHandler(
57
+ subscribersDir,
58
+ path.relative,
59
+ key,
60
+ construct,
61
+ context,
62
+ );
63
+
64
+ subscriberInfos.push({
65
+ name: key,
66
+ handler: relative(process.cwd(), handlerFile).replace(
67
+ /\.ts$/,
68
+ '.handler',
69
+ ),
70
+ subscribedEvents: construct.subscribedEvents || [],
71
+ timeout: construct.timeout,
72
+ environment: await construct.getEnvironment(),
73
+ });
74
+
75
+ logger.log(`Generated subscriber handler: ${key}`);
76
+ }
77
+
78
+ return subscriberInfos;
79
+ }
80
+
81
+ private async generateSubscriberHandler(
82
+ outputDir: string,
83
+ sourceFile: string,
84
+ exportName: string,
85
+ _subscriber: Subscriber<any, any, any, any, any, any>,
86
+ context: BuildContext,
87
+ ): Promise<string> {
88
+ const handlerFileName = `${exportName}.ts`;
89
+ const handlerPath = join(outputDir, handlerFileName);
90
+
91
+ const relativePath = relative(dirname(handlerPath), sourceFile);
92
+ const importPath = relativePath.replace(/\.ts$/, '.js');
93
+
94
+ const relativeEnvParserPath = relative(
95
+ dirname(handlerPath),
96
+ context.envParserPath,
97
+ );
98
+
99
+ const content = `import { AWSLambdaSubscriber } from '@geekmidas/constructs/aws';
100
+ import { ${exportName} } from '${importPath}';
101
+ import ${context.envParserImportPattern} from '${relativeEnvParserPath}';
102
+
103
+ const adapter = new AWSLambdaSubscriber(envParser, ${exportName});
104
+
105
+ export const handler = adapter.handler;
106
+ `;
107
+
108
+ await writeFile(handlerPath, content);
109
+ return handlerPath;
110
+ }
111
+
112
+ private async generateServerSubscribersFile(
113
+ outputDir: string,
114
+ subscribers: GeneratedConstruct<Subscriber<any, any, any, any, any, any>>[],
115
+ ): Promise<string> {
116
+ const subscribersFileName = 'subscribers.ts';
117
+ const subscribersPath = join(outputDir, subscribersFileName);
118
+
119
+ // Group imports by file
120
+ const importsByFile = new Map<string, string[]>();
121
+
122
+ for (const { path, key } of subscribers) {
123
+ const relativePath = relative(dirname(subscribersPath), path.relative);
124
+ const importPath = relativePath.replace(/\.ts$/, '.js');
125
+
126
+ if (!importsByFile.has(importPath)) {
127
+ importsByFile.set(importPath, []);
128
+ }
129
+ importsByFile.get(importPath)!.push(key);
130
+ }
131
+
132
+ // Generate import statements
133
+ const imports = Array.from(importsByFile.entries())
134
+ .map(
135
+ ([importPath, exports]) =>
136
+ `import { ${exports.join(', ')} } from '${importPath}';`,
137
+ )
138
+ .join('\n');
139
+
140
+ const allExportNames = subscribers.map(({ key }) => key);
141
+
142
+ const content = `/**
143
+ * Generated subscribers setup
144
+ *
145
+ * ⚠️ WARNING: This is for LOCAL DEVELOPMENT ONLY
146
+ * This uses event polling which is not suitable for production.
147
+ *
148
+ * For production, use AWS Lambda with SQS/SNS event source mappings.
149
+ * Lambda automatically:
150
+ * - Scales based on queue depth
151
+ * - Handles batch processing and retries
152
+ * - Manages dead letter queues
153
+ * - Provides better cost optimization
154
+ *
155
+ * This polling implementation is useful for:
156
+ * - Local development and testing
157
+ * - Understanding event flow without Lambda deployment
158
+ *
159
+ * Supported connection strings:
160
+ * - sqs://region/account-id/queue-name (SQS queue)
161
+ * - sns://region/account-id/topic-name (SNS topic)
162
+ * - rabbitmq://host:port/queue-name (RabbitMQ)
163
+ * - basic://in-memory (In-memory for testing)
164
+ */
165
+ import type { EnvironmentParser } from '@geekmidas/envkit';
166
+ import type { Logger } from '@geekmidas/logger';
167
+ import { EventConnectionFactory, Subscriber } from '@geekmidas/events';
168
+ import type { EventConnection, EventSubscriber } from '@geekmidas/events';
169
+ import { ServiceDiscovery } from '@geekmidas/services';
170
+ ${imports}
171
+
172
+ const subscribers = [
173
+ ${allExportNames.join(',\n ')}
174
+ ];
175
+
176
+ const activeSubscribers: EventSubscriber<any>[] = [];
177
+
178
+ export async function setupSubscribers(
179
+ envParser: EnvironmentParser<any>,
180
+ logger: Logger,
181
+ ): Promise<void> {
182
+ logger.info('Setting up subscribers in polling mode (local development)');
183
+
184
+ const config = envParser.create((get) => ({
185
+ connectionString: get('EVENT_SUBSCRIBER_CONNECTION_STRING').string().optional(),
186
+ })).parse();
187
+
188
+ if (!config.connectionString) {
189
+ logger.warn('EVENT_SUBSCRIBER_CONNECTION_STRING not configured, skipping subscriber setup');
190
+ return;
191
+ }
192
+
193
+ const serviceDiscovery = ServiceDiscovery.getInstance(logger, envParser);
194
+
195
+ // Create connection once, outside the loop (more efficient)
196
+ // EventConnectionFactory automatically determines the right connection type
197
+ let connection: EventConnection;
198
+ try {
199
+ connection = await EventConnectionFactory.fromConnectionString(config.connectionString);
200
+
201
+ const connectionType = new URL(config.connectionString).protocol.replace(':', '');
202
+ logger.info({ connectionType }, 'Created shared event connection');
203
+ } catch (error) {
204
+ logger.error({ error }, 'Failed to create event connection');
205
+ return;
206
+ }
207
+
208
+ for (const subscriber of subscribers) {
209
+ try {
210
+ // Create subscriber from shared connection
211
+ const eventSubscriber = await Subscriber.fromConnection(connection);
212
+
213
+ // Register services
214
+ const services = subscriber.services.length > 0
215
+ ? await serviceDiscovery.register(subscriber.services)
216
+ : {};
217
+
218
+ // Subscribe to events
219
+ const subscribedEvents = subscriber.subscribedEvents || [];
220
+
221
+ if (subscribedEvents.length === 0) {
222
+ logger.warn({ subscriber: subscriber.constructor.name }, 'Subscriber has no subscribed events, skipping');
223
+ continue;
224
+ }
225
+
226
+ await eventSubscriber.subscribe(subscribedEvents, async (event) => {
227
+ try {
228
+ // Process single event (batch of 1)
229
+ await subscriber.handler({
230
+ events: [event],
231
+ services: services as any,
232
+ logger: subscriber.logger,
233
+ });
234
+
235
+ logger.debug({ eventType: event.type }, 'Successfully processed event');
236
+ } catch (error) {
237
+ logger.error({ error, event }, 'Failed to process event');
238
+ // Event will become visible again for retry
239
+ }
240
+ });
241
+
242
+ activeSubscribers.push(eventSubscriber);
243
+
244
+ logger.info(
245
+ {
246
+ events: subscribedEvents,
247
+ },
248
+ 'Subscriber started polling'
249
+ );
250
+ } catch (error) {
251
+ logger.error({ error, subscriber: subscriber.constructor.name }, 'Failed to setup subscriber');
252
+ }
253
+ }
254
+
255
+ // Setup graceful shutdown
256
+ const shutdown = () => {
257
+ logger.info('Stopping all subscribers');
258
+ for (const eventSubscriber of activeSubscribers) {
259
+ connection.stop();
260
+ }
261
+ };
262
+
263
+ process.on('SIGTERM', shutdown);
264
+ process.on('SIGINT', shutdown);
265
+ }
266
+ `;
267
+
268
+ await writeFile(subscribersPath, content);
269
+ return subscribersPath;
270
+ }
271
+ }
@@ -1,6 +1,6 @@
1
1
  import { mkdir, readFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
- import type { Cron, ScheduleExpression } from '@geekmidas/api/constructs';
3
+ import type { Cron, ScheduleExpression } from '@geekmidas/constructs/crons';
4
4
  import { itWithDir } from '@geekmidas/testkit/os';
5
5
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
6
  import {
@@ -1,9 +1,10 @@
1
1
  import { mkdir, readFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
- import type { Endpoint } from '@geekmidas/api/server';
3
+ import type { Endpoint } from '@geekmidas/constructs/endpoints';
4
4
  import { itWithDir } from '@geekmidas/testkit/os';
5
5
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
- import type { HttpMethod } from '../../../../api/src/constructs/types';
6
+
7
+ import type { HttpMethod } from '@geekmidas/constructs';
7
8
  import {
8
9
  createMockBuildContext,
9
10
  createMockEndpointFile,
@@ -91,11 +92,26 @@ describe('EndpointGenerator', () => {
91
92
  const appPath = join(outputDir, 'app.ts');
92
93
  const appContent = await readFile(appPath, 'utf-8');
93
94
 
94
- expect(appContent).toContain('import { HonoEndpoint }');
95
- expect(appContent).toContain('import { testEndpoint }');
96
- expect(appContent).toContain('import { anotherEndpoint }');
95
+ expect(appContent).toContain('import { setupEndpoints }');
96
+ expect(appContent).toContain('import { setupSubscribers }');
97
+ expect(appContent).toContain('function createApp');
98
+ expect(appContent).toContain('app?: HonoType');
97
99
  expect(appContent).toContain('enableOpenApi: boolean = true');
98
- expect(appContent).toContain("docsPath: '/docs'");
100
+ expect(appContent).toContain('interface ServerApp');
101
+ expect(appContent).toContain('async start(options');
102
+ expect(appContent).toContain('serve: (app: HonoType, port: number)');
103
+
104
+ // Check that the endpoints.ts file was created with endpoint logic
105
+ const endpointsPath = join(outputDir, 'endpoints.ts');
106
+ const endpointsContent = await readFile(endpointsPath, 'utf-8');
107
+
108
+ expect(endpointsContent).toContain('import { HonoEndpoint }');
109
+ expect(endpointsContent).toContain('import { testEndpoint }');
110
+ expect(endpointsContent).toContain('import { anotherEndpoint }');
111
+ // Function signature always defaults to true
112
+ expect(endpointsContent).toContain('enableOpenApi: boolean = true');
113
+ // OpenAPI options are configured based on the parameter
114
+ expect(endpointsContent).toContain("docsPath: '/docs'");
99
115
  });
100
116
 
101
117
  itWithDir(
@@ -123,8 +139,16 @@ describe('EndpointGenerator', () => {
123
139
  const appPath = join(outputDir, 'app.ts');
124
140
  const appContent = await readFile(appPath, 'utf-8');
125
141
 
126
- expect(appContent).toContain('enableOpenApi: boolean = false');
127
- expect(appContent).toContain('docsPath: false');
142
+ expect(appContent).toContain('function createApp');
143
+
144
+ // Check that the endpoints.ts file defaults to true (but can be overridden)
145
+ const endpointsPath = join(outputDir, 'endpoints.ts');
146
+ const endpointsContent = await readFile(endpointsPath, 'utf-8');
147
+
148
+ // The function signature always defaults to true
149
+ expect(endpointsContent).toContain('enableOpenApi: boolean = true');
150
+ // But the OpenAPI options are configured dynamically based on the parameter
151
+ expect(endpointsContent).toContain('docsPath: false');
128
152
  },
129
153
  );
130
154
 
@@ -363,9 +387,7 @@ describe('EndpointGenerator', () => {
363
387
  provider: 'server',
364
388
  });
365
389
 
366
- expect(logSpy).toHaveBeenCalledWith(
367
- 'Generated server app with 2 endpoints',
368
- );
390
+ expect(logSpy).toHaveBeenCalledWith('Generated server with 2 endpoints');
369
391
 
370
392
  logSpy.mockRestore();
371
393
  });
@@ -1,7 +1,9 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { join } from 'node:path';
3
- import { type Function, FunctionBuilder } from '@geekmidas/api/constructs';
3
+ import { f } from '@geekmidas/constructs/functions';
4
+ import type { Function } from '@geekmidas/constructs/functions';
4
5
  import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6
+ import { z } from 'zod';
5
7
  import {
6
8
  cleanupDir,
7
9
  createMockBuildContext,
@@ -28,16 +30,12 @@ describe('FunctionGenerator', () => {
28
30
  });
29
31
 
30
32
  describe('isConstruct', () => {
31
- it('should identify valid functions', async () => {
32
- // Import the actual FunctionBuilder to create a real Function instance
33
-
34
- const { z } = await import('zod');
35
-
36
- const testFunction = new FunctionBuilder()
33
+ it('should identify valid functions', () => {
34
+ const testFunction = f
37
35
  .input(z.object({ name: z.string() }))
38
36
  .output(z.object({ greeting: z.string() }))
39
37
  .timeout(30)
40
- .handle(async ({ input }: any) => ({
38
+ .handle(async ({ input }) => ({
41
39
  greeting: `Hello, ${input.name}!`,
42
40
  }));
43
41
 
@@ -55,20 +53,21 @@ describe('FunctionGenerator', () => {
55
53
  const createTestFunctionConstruct = (
56
54
  key: string,
57
55
  timeout: number = 30,
58
- ): GeneratedConstruct<Function<any, any, any, any>> => ({
59
- key,
60
- name: key.toLowerCase(),
61
- construct: {
62
- __IS_FUNCTION__: true,
63
- type: 'dev.geekmidas.function.function',
64
- timeout,
65
- handle: async () => ({ greeting: 'Hello!' }),
66
- } as any,
67
- path: {
68
- absolute: join(tempDir, `${key}.ts`),
69
- relative: `${key}.ts`,
70
- },
71
- });
56
+ ): GeneratedConstruct<Function<any, any, any, any>> => {
57
+ const func = f
58
+ .timeout(timeout)
59
+ .handle(async () => ({ greeting: 'Hello!' }));
60
+
61
+ return {
62
+ key,
63
+ name: key.toLowerCase(),
64
+ construct: func,
65
+ path: {
66
+ absolute: join(tempDir, `${key}.ts`),
67
+ relative: `${key}.ts`,
68
+ },
69
+ };
70
+ };
72
71
 
73
72
  describe('aws-lambda provider', () => {
74
73
  it('should generate function handlers', async () => {