@geekmidas/cli 0.1.0 → 0.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 (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-CB-NHtZW.cjs +205 -0
  19. package/dist/SubscriberGenerator-CB-NHtZW.cjs.map +1 -0
  20. package/dist/SubscriberGenerator-Cuu4co3-.mjs +199 -0
  21. package/dist/SubscriberGenerator-Cuu4co3-.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-Ajg356_5.cjs +89 -0
  28. package/dist/build-Ajg356_5.cjs.map +1 -0
  29. package/dist/build-zpABVsc0.mjs +83 -0
  30. package/dist/build-zpABVsc0.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 +274 -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 +392 -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,392 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import {
4
+ type Subscriber,
5
+ SubscriberBuilder,
6
+ } from '@geekmidas/constructs/subscribers';
7
+
8
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
9
+ import {
10
+ cleanupDir,
11
+ createMockBuildContext,
12
+ createTempDir,
13
+ } from '../../__tests__/test-helpers';
14
+ import type { GeneratedConstruct } from '../Generator';
15
+ import { SubscriberGenerator } from '../SubscriberGenerator';
16
+
17
+ describe('SubscriberGenerator', () => {
18
+ let tempDir: string;
19
+ let outputDir: string;
20
+ let generator: SubscriberGenerator;
21
+ let context: ReturnType<typeof createMockBuildContext>;
22
+
23
+ beforeEach(async () => {
24
+ tempDir = await createTempDir();
25
+ outputDir = join(tempDir, 'output');
26
+ generator = new SubscriberGenerator();
27
+ context = createMockBuildContext();
28
+ });
29
+
30
+ afterEach(async () => {
31
+ await cleanupDir(tempDir);
32
+ });
33
+
34
+ describe('isConstruct', () => {
35
+ it('should identify valid subscribers', async () => {
36
+ const testSubscriber = new SubscriberBuilder()
37
+ .subscribe(['user.created'] as any)
38
+ .handle(async ({ events, logger }) => {
39
+ logger.info({ eventCount: events.length }, 'Processing events');
40
+ });
41
+
42
+ expect(generator.isConstruct(testSubscriber)).toBe(true);
43
+ });
44
+
45
+ it('should reject invalid constructs', () => {
46
+ expect(generator.isConstruct({})).toBe(false);
47
+ expect(generator.isConstruct('string')).toBe(false);
48
+ expect(generator.isConstruct(null)).toBe(false);
49
+ });
50
+ });
51
+
52
+ describe('build', () => {
53
+ const createSubscriberConstruct = (
54
+ key: string,
55
+ subscribedEvents: string[],
56
+ timeout: number = 30000,
57
+ ): GeneratedConstruct<Subscriber<any, any, any, any, any, any>> => {
58
+ const subscriber = new SubscriberBuilder()
59
+ .subscribe(subscribedEvents as any)
60
+ .timeout(timeout)
61
+ .handle(async ({ events, logger }) => {
62
+ logger.info({ eventCount: events.length }, 'Processing events');
63
+ });
64
+
65
+ return {
66
+ key,
67
+ name: key.toLowerCase(),
68
+ construct: subscriber,
69
+ path: {
70
+ absolute: join(tempDir, `${key}.ts`),
71
+ relative: `${key}.ts`,
72
+ },
73
+ };
74
+ };
75
+
76
+ it('should generate subscriber handlers', async () => {
77
+ const constructs = [
78
+ createSubscriberConstruct('userEventSubscriber', [
79
+ 'user.created',
80
+ 'user.updated',
81
+ ]),
82
+ createSubscriberConstruct('orderEventSubscriber', ['order.placed']),
83
+ ];
84
+
85
+ const subscriberInfos = await generator.build(
86
+ context,
87
+ constructs,
88
+ outputDir,
89
+ { provider: 'aws-lambda' },
90
+ );
91
+
92
+ expect(subscriberInfos).toHaveLength(2);
93
+ expect(subscriberInfos[0]).toMatchObject({
94
+ name: 'userEventSubscriber',
95
+ handler: expect.stringContaining(
96
+ 'subscribers/userEventSubscriber.handler',
97
+ ),
98
+ subscribedEvents: ['user.created', 'user.updated'],
99
+ timeout: 30000,
100
+ });
101
+ expect(subscriberInfos[1]).toMatchObject({
102
+ name: 'orderEventSubscriber',
103
+ handler: expect.stringContaining(
104
+ 'subscribers/orderEventSubscriber.handler',
105
+ ),
106
+ subscribedEvents: ['order.placed'],
107
+ timeout: 30000,
108
+ });
109
+
110
+ // Check that handler files were created
111
+ const userHandlerPath = join(
112
+ outputDir,
113
+ 'subscribers',
114
+ 'userEventSubscriber.ts',
115
+ );
116
+ const userContent = await readFile(userHandlerPath, 'utf-8');
117
+ expect(userContent).toContain('AWSLambdaSubscriber');
118
+ expect(userContent).toContain('import { userEventSubscriber }');
119
+ expect(userContent).toContain('import envParser');
120
+
121
+ const orderHandlerPath = join(
122
+ outputDir,
123
+ 'subscribers',
124
+ 'orderEventSubscriber.ts',
125
+ );
126
+ const orderContent = await readFile(orderHandlerPath, 'utf-8');
127
+ expect(orderContent).toContain('AWSLambdaSubscriber');
128
+ expect(orderContent).toContain('import { orderEventSubscriber }');
129
+ });
130
+
131
+ it('should generate correct relative import paths', async () => {
132
+ const subscriber = new SubscriberBuilder()
133
+ .subscribe(['event.type'] as any)
134
+ .timeout(45000)
135
+ .handle(async ({ events, logger }) => {
136
+ logger.info({ eventCount: events.length }, 'Processing events');
137
+ });
138
+
139
+ const construct: GeneratedConstruct<
140
+ Subscriber<any, any, any, any, any, any>
141
+ > = {
142
+ key: 'deepSubscriber',
143
+ name: 'deep-subscriber',
144
+ construct: subscriber,
145
+ path: {
146
+ absolute: join(tempDir, 'src/subscribers/deep/processor.ts'),
147
+ relative: 'src/subscribers/deep/processor.ts',
148
+ },
149
+ };
150
+
151
+ await generator.build(context, [construct], outputDir);
152
+
153
+ const handlerPath = join(outputDir, 'subscribers', 'deepSubscriber.ts');
154
+ const handlerContent = await readFile(handlerPath, 'utf-8');
155
+
156
+ // Check relative imports are correct
157
+ expect(handlerContent).toMatch(
158
+ /from ['"].*src\/subscribers\/deep\/processor\.js['"]/,
159
+ );
160
+ expect(handlerContent).toMatch(/from ['"].*\/env['"]/);
161
+ });
162
+
163
+ it('should handle subscribers with different timeout values', async () => {
164
+ const constructs = [
165
+ createSubscriberConstruct('quickSubscriber', ['fast.event'], 15000),
166
+ createSubscriberConstruct('slowSubscriber', ['slow.event'], 300000),
167
+ ];
168
+
169
+ const subscriberInfos = await generator.build(
170
+ context,
171
+ constructs,
172
+ outputDir,
173
+ );
174
+
175
+ expect(subscriberInfos[0].timeout).toBe(15000);
176
+ expect(subscriberInfos[1].timeout).toBe(300000);
177
+ });
178
+
179
+ it('should handle subscribers with no subscribed events', async () => {
180
+ const subscriber = new SubscriberBuilder()
181
+ .timeout(30000)
182
+ .handle(async ({ events, logger }) => {
183
+ logger.info({ eventCount: events.length }, 'Processing all events');
184
+ });
185
+
186
+ const construct: GeneratedConstruct<
187
+ Subscriber<any, any, any, any, any, any>
188
+ > = {
189
+ key: 'catchAllSubscriber',
190
+ name: 'catch-all-subscriber',
191
+ construct: subscriber,
192
+ path: {
193
+ absolute: join(tempDir, 'catchAllSubscriber.ts'),
194
+ relative: 'catchAllSubscriber.ts',
195
+ },
196
+ };
197
+
198
+ const subscriberInfos = await generator.build(
199
+ context,
200
+ [construct],
201
+ outputDir,
202
+ );
203
+
204
+ expect(subscriberInfos[0].subscribedEvents).toEqual([]);
205
+ });
206
+
207
+ it('should handle subscribers with multiple event types', async () => {
208
+ const constructs = [
209
+ createSubscriberConstruct('multiEventSubscriber', [
210
+ 'user.created',
211
+ 'user.updated',
212
+ 'user.deleted',
213
+ 'order.placed',
214
+ ]),
215
+ ];
216
+
217
+ const subscriberInfos = await generator.build(
218
+ context,
219
+ constructs,
220
+ outputDir,
221
+ );
222
+
223
+ expect(subscriberInfos[0].subscribedEvents).toEqual([
224
+ 'user.created',
225
+ 'user.updated',
226
+ 'user.deleted',
227
+ 'order.placed',
228
+ ]);
229
+ });
230
+
231
+ it('should log generation progress', async () => {
232
+ const logSpy = vi.spyOn(console, 'log');
233
+
234
+ const constructs = [
235
+ createSubscriberConstruct('testSubscriber', ['test.event']),
236
+ ];
237
+
238
+ await generator.build(context, constructs, outputDir);
239
+
240
+ expect(logSpy).toHaveBeenCalledWith(
241
+ 'Generated subscriber handler: testSubscriber',
242
+ );
243
+
244
+ logSpy.mockRestore();
245
+ });
246
+
247
+ it('should return empty array for empty constructs', async () => {
248
+ const subscriberInfos = await generator.build(context, [], outputDir);
249
+ expect(subscriberInfos).toEqual([]);
250
+ });
251
+
252
+ it('should generate subscribers.ts file for server provider even with no subscribers', async () => {
253
+ const subscriberInfos = await generator.build(
254
+ context,
255
+ [],
256
+ outputDir,
257
+ { provider: 'server' },
258
+ );
259
+
260
+ expect(subscriberInfos).toEqual([]);
261
+
262
+ // Check that subscribers.ts was generated
263
+ const subscribersPath = join(outputDir, 'subscribers.ts');
264
+ const subscribersContent = await readFile(subscribersPath, 'utf-8');
265
+
266
+ expect(subscribersContent).toContain('export async function setupSubscribers');
267
+ expect(subscribersContent).toContain('const subscribers = [');
268
+ expect(subscribersContent).toContain('import type { EnvironmentParser }');
269
+ expect(subscribersContent).toContain('import type { Logger }');
270
+ });
271
+
272
+ it('should generate subscribers.ts file for server provider with subscribers', async () => {
273
+ const constructs = [
274
+ createSubscriberConstruct('userEventSubscriber', [
275
+ 'user.created',
276
+ 'user.updated',
277
+ ]),
278
+ createSubscriberConstruct('orderEventSubscriber', ['order.placed']),
279
+ ];
280
+
281
+ const subscriberInfos = await generator.build(
282
+ context,
283
+ constructs,
284
+ outputDir,
285
+ { provider: 'server' },
286
+ );
287
+
288
+ expect(subscriberInfos).toEqual([]);
289
+
290
+ // Check that subscribers.ts was generated
291
+ const subscribersPath = join(outputDir, 'subscribers.ts');
292
+ const subscribersContent = await readFile(subscribersPath, 'utf-8');
293
+
294
+ expect(subscribersContent).toContain('export async function setupSubscribers');
295
+ expect(subscribersContent).toContain('import { userEventSubscriber }');
296
+ expect(subscribersContent).toContain('import { orderEventSubscriber }');
297
+ expect(subscribersContent).toContain('const subscribers = [');
298
+ expect(subscribersContent).toContain('userEventSubscriber');
299
+ expect(subscribersContent).toContain('orderEventSubscriber');
300
+ expect(subscribersContent).toContain('Setting up subscribers in polling mode');
301
+ });
302
+
303
+ it('should handle subscribers with custom environment parser patterns', async () => {
304
+ const customContext = {
305
+ ...context,
306
+ envParserImportPattern: '{ customParser as envParser }',
307
+ };
308
+
309
+ const constructs = [
310
+ createSubscriberConstruct('customSubscriber', ['custom.event']),
311
+ ];
312
+
313
+ await generator.build(customContext, constructs, outputDir);
314
+
315
+ const handlerPath = join(outputDir, 'subscribers', 'customSubscriber.ts');
316
+ const handlerContent = await readFile(handlerPath, 'utf-8');
317
+
318
+ expect(handlerContent).toContain('import { customParser as envParser }');
319
+ });
320
+
321
+ it('should create subscribers directory if it does not exist', async () => {
322
+ const constructs = [
323
+ createSubscriberConstruct('firstSubscriber', ['first.event']),
324
+ ];
325
+
326
+ // outputDir does not exist yet
327
+ await generator.build(context, constructs, outputDir);
328
+
329
+ const subscribersDir = join(outputDir, 'subscribers');
330
+ const handlerPath = join(subscribersDir, 'firstSubscriber.ts');
331
+
332
+ // Should be able to read the file, meaning the directory was created
333
+ const content = await readFile(handlerPath, 'utf-8');
334
+ expect(content).toContain('AWSLambdaSubscriber');
335
+ });
336
+
337
+ it('should handle exported subscriber with custom name', async () => {
338
+ const subscriber = new SubscriberBuilder()
339
+ .subscribe(['custom.event'] as any)
340
+ .handle(async ({ events, logger }) => {
341
+ logger.info({ eventCount: events.length }, 'Processing events');
342
+ });
343
+
344
+ const construct: GeneratedConstruct<
345
+ Subscriber<any, any, any, any, any, any>
346
+ > = {
347
+ key: 'myCustomSubscriberName',
348
+ name: 'custom-name',
349
+ construct: subscriber,
350
+ path: {
351
+ absolute: join(tempDir, 'subscriber.ts'),
352
+ relative: 'subscriber.ts',
353
+ },
354
+ };
355
+
356
+ await generator.build(context, [construct], outputDir);
357
+
358
+ const handlerPath = join(
359
+ outputDir,
360
+ 'subscribers',
361
+ 'myCustomSubscriberName.ts',
362
+ );
363
+ const handlerContent = await readFile(handlerPath, 'utf-8');
364
+
365
+ expect(handlerContent).toContain(
366
+ 'import { myCustomSubscriberName } from',
367
+ );
368
+ expect(handlerContent).toContain(
369
+ 'new AWSLambdaSubscriber(envParser, myCustomSubscriberName)',
370
+ );
371
+ });
372
+
373
+ it('should generate handler files that can be imported', async () => {
374
+ const constructs = [
375
+ createSubscriberConstruct('validSubscriber', ['valid.event']),
376
+ ];
377
+
378
+ await generator.build(context, constructs, outputDir);
379
+
380
+ const handlerPath = join(outputDir, 'subscribers', 'validSubscriber.ts');
381
+ const handlerContent = await readFile(handlerPath, 'utf-8');
382
+
383
+ // Check that the generated file has proper structure
384
+ expect(handlerContent).toContain(
385
+ "import { AWSLambdaSubscriber } from '@geekmidas/constructs/aws'",
386
+ );
387
+ expect(handlerContent).toContain(
388
+ 'export const handler = adapter.handler',
389
+ );
390
+ });
391
+ });
392
+ });
@@ -1,6 +1,7 @@
1
1
  export { CronGenerator } from './CronGenerator';
2
2
  export { EndpointGenerator } from './EndpointGenerator';
3
3
  export { FunctionGenerator } from './FunctionGenerator';
4
+ export { SubscriberGenerator } from './SubscriberGenerator';
4
5
  export {
5
6
  ConstructGenerator,
6
7
  type GeneratedConstruct,
@@ -63,6 +63,7 @@ export async function generateReactQueryCommand(
63
63
  logger.warn('Run: npm install -D openapi-typescript');
64
64
 
65
65
  // Generate basic types file
66
+ await mkdir(dirname(typesPath), { recursive: true });
66
67
  await writeFile(
67
68
  typesPath,
68
69
  `// Auto-generated placeholder types
@@ -185,7 +186,7 @@ function generateReactQueryCode(
185
186
  operations: OperationInfo[],
186
187
  apiName: string,
187
188
  ): string {
188
- const imports = `import { createTypedQueryClient } from '@geekmidas/api/client';
189
+ const imports = `import { createTypedQueryClient } from '@geekmidas/client';
189
190
  import type { paths } from './openapi-types';
190
191
 
191
192
  // Create typed query client
package/src/openapi.ts CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { mkdir, writeFile } from 'node:fs/promises';
4
4
  import { join } from 'node:path';
5
- import { Endpoint } from '@geekmidas/api/server';
5
+ import { Endpoint } from '@geekmidas/constructs/endpoints';
6
6
  import { loadConfig } from './config.js';
7
7
  import { EndpointGenerator } from './generators/EndpointGenerator.js';
8
8
 
package/src/types.ts CHANGED
@@ -43,6 +43,7 @@ export interface GkmConfig {
43
43
  routes: Routes;
44
44
  functions?: Routes;
45
45
  crons?: Routes;
46
+ subscribers?: Routes;
46
47
  envParser: string;
47
48
  logger: string;
48
49
  providers?: ProvidersConfig;
@@ -59,6 +60,7 @@ export interface RouteInfo {
59
60
  path: string;
60
61
  method: string;
61
62
  handler: string;
63
+ environment?: string[];
62
64
  }
63
65
 
64
66
  export interface FunctionInfo {
@@ -66,6 +68,7 @@ export interface FunctionInfo {
66
68
  handler: string;
67
69
  timeout?: number;
68
70
  memorySize?: number;
71
+ environment?: string[];
69
72
  }
70
73
 
71
74
  export interface CronInfo {
@@ -74,6 +77,16 @@ export interface CronInfo {
74
77
  schedule: string;
75
78
  timeout?: number;
76
79
  memorySize?: number;
80
+ environment?: string[];
81
+ }
82
+
83
+ export interface SubscriberInfo {
84
+ name: string;
85
+ handler: string;
86
+ subscribedEvents: string[];
87
+ timeout?: number;
88
+ memorySize?: number;
89
+ environment?: string[];
77
90
  }
78
91
 
79
92
  export interface RoutesManifest {
@@ -88,8 +101,13 @@ export interface CronsManifest {
88
101
  crons: CronInfo[];
89
102
  }
90
103
 
104
+ export interface SubscribersManifest {
105
+ subscribers: SubscriberInfo[];
106
+ }
107
+
91
108
  export interface BuildManifest {
92
109
  routes: RouteInfo[];
93
110
  functions: FunctionInfo[];
94
111
  crons: CronInfo[];
112
+ subscribers: SubscriberInfo[];
95
113
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"CronGenerator-ClbRcmz_.mjs","names":["context: BuildContext","constructs: GeneratedConstruct<Cron<any, any, any, any>>[]","outputDir: string","options?: GeneratorOptions","cronInfos: CronInfo[]","value: any","sourceFile: string","exportName: string"],"sources":["../src/generators/CronGenerator.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { Cron } from '@geekmidas/api/constructs';\nimport type { BuildContext } from '../build/types';\nimport type { CronInfo } from '../types';\nimport {\n ConstructGenerator,\n type GeneratedConstruct,\n type GeneratorOptions,\n} from './Generator';\n\nexport class CronGenerator extends ConstructGenerator<\n Cron<any, any, any, any>,\n CronInfo[]\n> {\n async build(\n context: BuildContext,\n constructs: GeneratedConstruct<Cron<any, any, any, any>>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<CronInfo[]> {\n const provider = options?.provider || 'aws-lambda';\n const logger = console;\n const cronInfos: CronInfo[] = [];\n\n if (constructs.length === 0 || provider !== 'aws-lambda') {\n return cronInfos;\n }\n\n // Create crons subdirectory\n const cronsDir = join(outputDir, 'crons');\n await mkdir(cronsDir, { recursive: true });\n\n // Generate cron handlers\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateCronHandler(\n cronsDir,\n path.relative,\n key,\n context,\n );\n\n cronInfos.push({\n name: key,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n schedule: construct.schedule || 'rate(1 hour)',\n timeout: construct.timeout,\n });\n\n logger.log(`Generated cron handler: ${key}`);\n }\n\n return cronInfos;\n }\n\n isConstruct(value: any): value is Cron<any, any, any, any> {\n return Cron.isCron(value);\n }\n\n private async generateCronHandler(\n outputDir: string,\n sourceFile: string,\n exportName: string,\n context: BuildContext,\n ): Promise<string> {\n const handlerFileName = `${exportName}.ts`;\n const handlerPath = join(outputDir, handlerFileName);\n\n const relativePath = relative(dirname(handlerPath), sourceFile);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n const relativeEnvParserPath = relative(\n dirname(handlerPath),\n context.envParserPath,\n );\n const relativeLoggerPath = relative(\n dirname(handlerPath),\n context.loggerPath,\n );\n\n const content = `import { AWSScheduledFunction } from '@geekmidas/api/aws-lambda';\nimport { ${exportName} } from '${importPath}';\nimport ${context.envParserImportPattern} from '${relativeEnvParserPath}';\nimport ${context.loggerImportPattern} from '${relativeLoggerPath}';\n\nconst adapter = new AWSScheduledFunction(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n\n await writeFile(handlerPath, content);\n return handlerPath;\n }\n}\n"],"mappings":";;;;;;AAWA,IAAa,gBAAb,cAAmC,mBAGjC;CACA,MAAM,MACJA,SACAC,YACAC,WACAC,SACqB;EACrB,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,SAAS;EACf,MAAMC,YAAwB,CAAE;AAEhC,MAAI,WAAW,WAAW,KAAK,aAAa,aAC1C,QAAO;EAIT,MAAM,WAAW,KAAK,WAAW,QAAQ;AACzC,QAAM,MAAM,UAAU,EAAE,WAAW,KAAM,EAAC;AAG1C,OAAK,MAAM,EAAE,KAAK,WAAW,MAAM,IAAI,YAAY;GACjD,MAAM,cAAc,MAAM,KAAK,oBAC7B,UACA,KAAK,UACL,KACA,QACD;AAED,aAAU,KAAK;IACb,MAAM;IACN,SAAS,SAAS,QAAQ,KAAK,EAAE,YAAY,CAAC,QAC5C,SACA,WACD;IACD,UAAU,UAAU,YAAY;IAChC,SAAS,UAAU;GACpB,EAAC;AAEF,UAAO,KAAK,0BAA0B,IAAI,EAAE;EAC7C;AAED,SAAO;CACR;CAED,YAAYC,OAA+C;AACzD,SAAO,KAAK,OAAO,MAAM;CAC1B;CAED,MAAc,oBACZH,WACAI,YACAC,YACAP,SACiB;EACjB,MAAM,mBAAmB,EAAE,WAAW;EACtC,MAAM,cAAc,KAAK,WAAW,gBAAgB;EAEpD,MAAM,eAAe,SAAS,QAAQ,YAAY,EAAE,WAAW;EAC/D,MAAM,aAAa,aAAa,QAAQ,SAAS,MAAM;EAEvD,MAAM,wBAAwB,SAC5B,QAAQ,YAAY,EACpB,QAAQ,cACT;EACD,MAAM,qBAAqB,SACzB,QAAQ,YAAY,EACpB,QAAQ,WACT;EAED,MAAM,WAAW;WACV,WAAW,WAAW,WAAW;SACnC,QAAQ,uBAAuB,SAAS,sBAAsB;SAC9D,QAAQ,oBAAoB,SAAS,mBAAmB;;sDAEX,WAAW;;;;AAK7D,QAAM,UAAU,aAAa,QAAQ;AACrC,SAAO;CACR;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"CronGenerator-Ctl4USy4.cjs","names":["ConstructGenerator","context: BuildContext","constructs: GeneratedConstruct<Cron<any, any, any, any>>[]","outputDir: string","options?: GeneratorOptions","cronInfos: CronInfo[]","value: any","sourceFile: string","exportName: string"],"sources":["../src/generators/CronGenerator.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { Cron } from '@geekmidas/api/constructs';\nimport type { BuildContext } from '../build/types';\nimport type { CronInfo } from '../types';\nimport {\n ConstructGenerator,\n type GeneratedConstruct,\n type GeneratorOptions,\n} from './Generator';\n\nexport class CronGenerator extends ConstructGenerator<\n Cron<any, any, any, any>,\n CronInfo[]\n> {\n async build(\n context: BuildContext,\n constructs: GeneratedConstruct<Cron<any, any, any, any>>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<CronInfo[]> {\n const provider = options?.provider || 'aws-lambda';\n const logger = console;\n const cronInfos: CronInfo[] = [];\n\n if (constructs.length === 0 || provider !== 'aws-lambda') {\n return cronInfos;\n }\n\n // Create crons subdirectory\n const cronsDir = join(outputDir, 'crons');\n await mkdir(cronsDir, { recursive: true });\n\n // Generate cron handlers\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateCronHandler(\n cronsDir,\n path.relative,\n key,\n context,\n );\n\n cronInfos.push({\n name: key,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n schedule: construct.schedule || 'rate(1 hour)',\n timeout: construct.timeout,\n });\n\n logger.log(`Generated cron handler: ${key}`);\n }\n\n return cronInfos;\n }\n\n isConstruct(value: any): value is Cron<any, any, any, any> {\n return Cron.isCron(value);\n }\n\n private async generateCronHandler(\n outputDir: string,\n sourceFile: string,\n exportName: string,\n context: BuildContext,\n ): Promise<string> {\n const handlerFileName = `${exportName}.ts`;\n const handlerPath = join(outputDir, handlerFileName);\n\n const relativePath = relative(dirname(handlerPath), sourceFile);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n const relativeEnvParserPath = relative(\n dirname(handlerPath),\n context.envParserPath,\n );\n const relativeLoggerPath = relative(\n dirname(handlerPath),\n context.loggerPath,\n );\n\n const content = `import { AWSScheduledFunction } from '@geekmidas/api/aws-lambda';\nimport { ${exportName} } from '${importPath}';\nimport ${context.envParserImportPattern} from '${relativeEnvParserPath}';\nimport ${context.loggerImportPattern} from '${relativeLoggerPath}';\n\nconst adapter = new AWSScheduledFunction(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n\n await writeFile(handlerPath, content);\n return handlerPath;\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAa,gBAAb,cAAmCA,qCAGjC;CACA,MAAM,MACJC,SACAC,YACAC,WACAC,SACqB;EACrB,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,SAAS;EACf,MAAMC,YAAwB,CAAE;AAEhC,MAAI,WAAW,WAAW,KAAK,aAAa,aAC1C,QAAO;EAIT,MAAM,WAAW,oBAAK,WAAW,QAAQ;AACzC,QAAM,4BAAM,UAAU,EAAE,WAAW,KAAM,EAAC;AAG1C,OAAK,MAAM,EAAE,KAAK,WAAW,MAAM,IAAI,YAAY;GACjD,MAAM,cAAc,MAAM,KAAK,oBAC7B,UACA,KAAK,UACL,KACA,QACD;AAED,aAAU,KAAK;IACb,MAAM;IACN,SAAS,wBAAS,QAAQ,KAAK,EAAE,YAAY,CAAC,QAC5C,SACA,WACD;IACD,UAAU,UAAU,YAAY;IAChC,SAAS,UAAU;GACpB,EAAC;AAEF,UAAO,KAAK,0BAA0B,IAAI,EAAE;EAC7C;AAED,SAAO;CACR;CAED,YAAYC,OAA+C;AACzD,SAAO,gCAAK,OAAO,MAAM;CAC1B;CAED,MAAc,oBACZH,WACAI,YACAC,YACAP,SACiB;EACjB,MAAM,mBAAmB,EAAE,WAAW;EACtC,MAAM,cAAc,oBAAK,WAAW,gBAAgB;EAEpD,MAAM,eAAe,wBAAS,uBAAQ,YAAY,EAAE,WAAW;EAC/D,MAAM,aAAa,aAAa,QAAQ,SAAS,MAAM;EAEvD,MAAM,wBAAwB,wBAC5B,uBAAQ,YAAY,EACpB,QAAQ,cACT;EACD,MAAM,qBAAqB,wBACzB,uBAAQ,YAAY,EACpB,QAAQ,WACT;EAED,MAAM,WAAW;WACV,WAAW,WAAW,WAAW;SACnC,QAAQ,uBAAuB,SAAS,sBAAsB;SAC9D,QAAQ,oBAAoB,SAAS,mBAAmB;;sDAEX,WAAW;;;;AAK7D,QAAM,gCAAU,aAAa,QAAQ;AACrC,SAAO;CACR;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"EndpointGenerator-Dj7AumHi.cjs","names":["ConstructGenerator","value: any","context: BuildContext","constructs: GeneratedConstruct<Endpoint<any, any, any, any, any, any>>[]","outputDir: string","options?: GeneratorOptions","routes: RouteInfo[]","routeInfo: RouteInfo","sourceFile: string","exportName: string","provider: LegacyProvider","_endpoint: Endpoint<any, any, any, any, any, any>","content: string","endpoints: GeneratedConstruct<Endpoint<any, any, any, any, any, any>>[]","enableOpenApi: boolean","exports","importPath: string","envParserPath: string","envParserImportPattern: string"],"sources":["../src/generators/EndpointGenerator.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { Endpoint } from '@geekmidas/api/server';\nimport type { BuildContext } from '../build/types';\nimport type { LegacyProvider, RouteInfo } from '../types';\nimport {\n ConstructGenerator,\n type GeneratedConstruct,\n type GeneratorOptions,\n} from './Generator';\n\nexport class EndpointGenerator extends ConstructGenerator<\n Endpoint<any, any, any, any, any, any>,\n RouteInfo[]\n> {\n isConstruct(value: any): value is Endpoint<any, any, any, any, any, any> {\n return Endpoint.isEndpoint(value);\n }\n\n async build(\n context: BuildContext,\n constructs: GeneratedConstruct<Endpoint<any, any, any, any, any, any>>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<RouteInfo[]> {\n const provider = options?.provider || 'aws-apigatewayv2';\n const enableOpenApi = options?.enableOpenApi || false;\n const logger = console;\n const routes: RouteInfo[] = [];\n\n if (constructs.length === 0) {\n return routes;\n }\n\n if (provider === 'server') {\n // Generate single server file with all endpoints\n const serverFile = await this.generateServerFile(\n outputDir,\n constructs,\n context,\n enableOpenApi,\n );\n\n routes.push({\n path: '*',\n method: 'ALL',\n handler: relative(process.cwd(), serverFile),\n });\n\n logger.log(\n `Generated server app with ${constructs.length} endpoints${enableOpenApi ? ' (OpenAPI enabled)' : ''}`,\n );\n } else if (provider === 'aws-lambda') {\n // For aws-lambda, create routes subdirectory\n const routesDir = join(outputDir, 'routes');\n await mkdir(routesDir, { recursive: true });\n\n // Generate individual handlers for API Gateway routes\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateHandlerFile(\n routesDir,\n path.relative,\n key,\n 'aws-apigatewayv2',\n construct,\n context,\n );\n\n const routeInfo: RouteInfo = {\n path: construct._path,\n method: construct.method,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n };\n\n routes.push(routeInfo);\n logger.log(\n `Generated handler for ${routeInfo.method} ${routeInfo.path}`,\n );\n }\n } else {\n // Generate individual handler files for AWS API Gateway providers\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateHandlerFile(\n outputDir,\n path.relative,\n key,\n provider,\n construct,\n context,\n );\n\n const routeInfo: RouteInfo = {\n path: construct._path,\n method: construct.method,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n };\n\n routes.push(routeInfo);\n logger.log(\n `Generated handler for ${routeInfo.method} ${routeInfo.path}`,\n );\n }\n }\n\n return routes;\n }\n\n private async generateHandlerFile(\n outputDir: string,\n sourceFile: string,\n exportName: string,\n provider: LegacyProvider,\n _endpoint: Endpoint<any, any, any, any, any, any>,\n context: BuildContext,\n ): Promise<string> {\n const handlerFileName = `${exportName}.ts`;\n const handlerPath = join(outputDir, handlerFileName);\n\n const relativePath = relative(dirname(handlerPath), sourceFile);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n const relativeEnvParserPath = relative(\n dirname(handlerPath),\n context.envParserPath,\n );\n\n let content: string;\n\n switch (provider) {\n case 'aws-apigatewayv1':\n content = this.generateAWSApiGatewayV1Handler(\n importPath,\n exportName,\n relativeEnvParserPath,\n context.envParserImportPattern,\n );\n break;\n case 'aws-apigatewayv2':\n content = this.generateAWSApiGatewayV2Handler(\n importPath,\n exportName,\n relativeEnvParserPath,\n context.envParserImportPattern,\n );\n break;\n case 'server':\n content = this.generateServerHandler(importPath, exportName);\n break;\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n\n await writeFile(handlerPath, content);\n return handlerPath;\n }\n\n private async generateServerFile(\n outputDir: string,\n endpoints: GeneratedConstruct<Endpoint<any, any, any, any, any, any>>[],\n context: BuildContext,\n enableOpenApi: boolean,\n ): Promise<string> {\n const serverFileName = 'app.ts';\n const serverPath = join(outputDir, serverFileName);\n\n // Group imports by file\n const importsByFile = new Map<string, string[]>();\n\n for (const { path, key } of endpoints) {\n const relativePath = relative(dirname(serverPath), path.relative);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n if (!importsByFile.has(importPath)) {\n importsByFile.set(importPath, []);\n }\n importsByFile.get(importPath)!.push(key);\n }\n\n const relativeEnvParserPath = relative(\n dirname(serverPath),\n context.envParserPath,\n );\n const relativeLoggerPath = relative(\n dirname(serverPath),\n context.loggerPath,\n );\n\n // Generate import statements\n const imports = Array.from(importsByFile.entries())\n .map(\n ([importPath, exports]) =>\n `import { ${exports.join(', ')} } from '${importPath}';`,\n )\n .join('\\n');\n\n const allExportNames = endpoints.map(({ key }) => key);\n\n const content = `import { HonoEndpoint } from '@geekmidas/api/hono';\nimport { Endpoint } from '@geekmidas/api/server';\nimport { ServiceDiscovery } from '@geekmidas/api/services';\nimport { Hono } from 'hono';\nimport ${context.envParserImportPattern} from '${relativeEnvParserPath}';\nimport ${context.loggerImportPattern} from '${relativeLoggerPath}';\n${imports}\n\nexport function createApp(app?: Hono, enableOpenApi: boolean = ${enableOpenApi}): Hono {\n const honoApp = app || new Hono();\n \n const endpoints: Endpoint<any, any, any, any, any, any, any>[] = [\n ${allExportNames.join(',\\n ')}\n ];\n\n const serviceDiscovery = ServiceDiscovery.getInstance(\n logger,\n envParser\n );\n\n // Configure OpenAPI options based on enableOpenApi flag\n const openApiOptions: any = enableOpenApi ? {\n docsPath: '/docs',\n openApiOptions: {\n title: 'API Documentation',\n version: '1.0.0',\n description: 'Generated API documentation'\n }\n } : { docsPath: false };\n\n HonoEndpoint.addRoutes(endpoints, serviceDiscovery, honoApp, openApiOptions);\n\n return honoApp;\n}\n\n// Default export for convenience\nexport default createApp;\n`;\n\n await writeFile(serverPath, content);\n\n return serverPath;\n }\n\n private generateAWSApiGatewayV1Handler(\n importPath: string,\n exportName: string,\n envParserPath: string,\n envParserImportPattern: string,\n ): string {\n return `import { AmazonApiGatewayV1Endpoint } from '@geekmidas/api/aws-apigateway';\nimport { ${exportName} } from '${importPath}';\nimport ${envParserImportPattern} from '${envParserPath}';\n\nconst adapter = new AmazonApiGatewayV1Endpoint(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n }\n\n private generateAWSApiGatewayV2Handler(\n importPath: string,\n exportName: string,\n envParserPath: string,\n envParserImportPattern: string,\n ): string {\n return `import { AmazonApiGatewayV2Endpoint } from '@geekmidas/api/aws-apigateway';\nimport { ${exportName} } from '${importPath}';\nimport ${envParserImportPattern} from '${envParserPath}';\n\nconst adapter = new AmazonApiGatewayV2Endpoint(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n }\n\n private generateServerHandler(\n importPath: string,\n exportName: string,\n ): string {\n return `import { ${exportName} } from '${importPath}';\n\n// Server handler - implement based on your server framework\nexport const handler = ${exportName};\n`;\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAa,oBAAb,cAAuCA,qCAGrC;CACA,YAAYC,OAA6D;AACvE,SAAO,gCAAS,WAAW,MAAM;CAClC;CAED,MAAM,MACJC,SACAC,YACAC,WACAC,SACsB;EACtB,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,gBAAgB,SAAS,iBAAiB;EAChD,MAAM,SAAS;EACf,MAAMC,SAAsB,CAAE;AAE9B,MAAI,WAAW,WAAW,EACxB,QAAO;AAGT,MAAI,aAAa,UAAU;GAEzB,MAAM,aAAa,MAAM,KAAK,mBAC5B,WACA,YACA,SACA,cACD;AAED,UAAO,KAAK;IACV,MAAM;IACN,QAAQ;IACR,SAAS,wBAAS,QAAQ,KAAK,EAAE,WAAW;GAC7C,EAAC;AAEF,UAAO,KACJ,4BAA4B,WAAW,OAAO,YAAY,gBAAgB,uBAAuB,GAAG,EACtG;EACF,WAAU,aAAa,cAAc;GAEpC,MAAM,YAAY,oBAAK,WAAW,SAAS;AAC3C,SAAM,4BAAM,WAAW,EAAE,WAAW,KAAM,EAAC;AAG3C,QAAK,MAAM,EAAE,KAAK,WAAW,MAAM,IAAI,YAAY;IACjD,MAAM,cAAc,MAAM,KAAK,oBAC7B,WACA,KAAK,UACL,KACA,oBACA,WACA,QACD;IAED,MAAMC,YAAuB;KAC3B,MAAM,UAAU;KAChB,QAAQ,UAAU;KAClB,SAAS,wBAAS,QAAQ,KAAK,EAAE,YAAY,CAAC,QAC5C,SACA,W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uBA1ixUw.mjs","names":["value: any","context: BuildContext","constructs: GeneratedConstruct<Endpoint<any, any, any, any, any, any>>[]","outputDir: string","options?: GeneratorOptions","routes: RouteInfo[]","routeInfo: RouteInfo","sourceFile: string","exportName: string","provider: LegacyProvider","_endpoint: Endpoint<any, any, any, any, any, any>","content: string","endpoints: GeneratedConstruct<Endpoint<any, any, any, any, any, any>>[]","enableOpenApi: boolean","importPath: string","envParserPath: string","envParserImportPattern: string"],"sources":["../src/generators/EndpointGenerator.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { Endpoint } from '@geekmidas/api/server';\nimport type { BuildContext } from '../build/types';\nimport type { LegacyProvider, RouteInfo } from '../types';\nimport {\n ConstructGenerator,\n type GeneratedConstruct,\n type GeneratorOptions,\n} from './Generator';\n\nexport class EndpointGenerator extends ConstructGenerator<\n Endpoint<any, any, any, any, any, any>,\n RouteInfo[]\n> {\n isConstruct(value: any): value is Endpoint<any, any, any, any, any, any> {\n return Endpoint.isEndpoint(value);\n }\n\n async build(\n context: BuildContext,\n constructs: GeneratedConstruct<Endpoint<any, any, any, any, any, any>>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<RouteInfo[]> {\n const provider = options?.provider || 'aws-apigatewayv2';\n const enableOpenApi = options?.enableOpenApi || false;\n const logger = console;\n const routes: RouteInfo[] = [];\n\n if (constructs.length === 0) {\n return routes;\n }\n\n if (provider === 'server') {\n // Generate single server file with all endpoints\n const serverFile = await this.generateServerFile(\n outputDir,\n constructs,\n context,\n enableOpenApi,\n );\n\n routes.push({\n path: '*',\n method: 'ALL',\n handler: relative(process.cwd(), serverFile),\n });\n\n logger.log(\n `Generated server app with ${constructs.length} endpoints${enableOpenApi ? ' (OpenAPI enabled)' : ''}`,\n );\n } else if (provider === 'aws-lambda') {\n // For aws-lambda, create routes subdirectory\n const routesDir = join(outputDir, 'routes');\n await mkdir(routesDir, { recursive: true });\n\n // Generate individual handlers for API Gateway routes\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateHandlerFile(\n routesDir,\n path.relative,\n key,\n 'aws-apigatewayv2',\n construct,\n context,\n );\n\n const routeInfo: RouteInfo = {\n path: construct._path,\n method: construct.method,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n };\n\n routes.push(routeInfo);\n logger.log(\n `Generated handler for ${routeInfo.method} ${routeInfo.path}`,\n );\n }\n } else {\n // Generate individual handler files for AWS API Gateway providers\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateHandlerFile(\n outputDir,\n path.relative,\n key,\n provider,\n construct,\n context,\n );\n\n const routeInfo: RouteInfo = {\n path: construct._path,\n method: construct.method,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n };\n\n routes.push(routeInfo);\n logger.log(\n `Generated handler for ${routeInfo.method} ${routeInfo.path}`,\n );\n }\n }\n\n return routes;\n }\n\n private async generateHandlerFile(\n outputDir: string,\n sourceFile: string,\n exportName: string,\n provider: LegacyProvider,\n _endpoint: Endpoint<any, any, any, any, any, any>,\n context: BuildContext,\n ): Promise<string> {\n const handlerFileName = `${exportName}.ts`;\n const handlerPath = join(outputDir, handlerFileName);\n\n const relativePath = relative(dirname(handlerPath), sourceFile);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n const relativeEnvParserPath = relative(\n dirname(handlerPath),\n context.envParserPath,\n );\n\n let content: string;\n\n switch (provider) {\n case 'aws-apigatewayv1':\n content = this.generateAWSApiGatewayV1Handler(\n importPath,\n exportName,\n relativeEnvParserPath,\n context.envParserImportPattern,\n );\n break;\n case 'aws-apigatewayv2':\n content = this.generateAWSApiGatewayV2Handler(\n importPath,\n exportName,\n relativeEnvParserPath,\n context.envParserImportPattern,\n );\n break;\n case 'server':\n content = this.generateServerHandler(importPath, exportName);\n break;\n default:\n throw new Error(`Unsupported provider: ${provider}`);\n }\n\n await writeFile(handlerPath, content);\n return handlerPath;\n }\n\n private async generateServerFile(\n outputDir: string,\n endpoints: GeneratedConstruct<Endpoint<any, any, any, any, any, any>>[],\n context: BuildContext,\n enableOpenApi: boolean,\n ): Promise<string> {\n const serverFileName = 'app.ts';\n const serverPath = join(outputDir, serverFileName);\n\n // Group imports by file\n const importsByFile = new Map<string, string[]>();\n\n for (const { path, key } of endpoints) {\n const relativePath = relative(dirname(serverPath), path.relative);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n if (!importsByFile.has(importPath)) {\n importsByFile.set(importPath, []);\n }\n importsByFile.get(importPath)!.push(key);\n }\n\n const relativeEnvParserPath = relative(\n dirname(serverPath),\n context.envParserPath,\n );\n const relativeLoggerPath = relative(\n dirname(serverPath),\n context.loggerPath,\n );\n\n // Generate import statements\n const imports = Array.from(importsByFile.entries())\n .map(\n ([importPath, exports]) =>\n `import { ${exports.join(', ')} } from '${importPath}';`,\n )\n .join('\\n');\n\n const allExportNames = endpoints.map(({ key }) => key);\n\n const content = `import { HonoEndpoint } from '@geekmidas/api/hono';\nimport { Endpoint } from '@geekmidas/api/server';\nimport { ServiceDiscovery } from '@geekmidas/api/services';\nimport { Hono } from 'hono';\nimport ${context.envParserImportPattern} from '${relativeEnvParserPath}';\nimport ${context.loggerImportPattern} from '${relativeLoggerPath}';\n${imports}\n\nexport function createApp(app?: Hono, enableOpenApi: boolean = ${enableOpenApi}): Hono {\n const honoApp = app || new Hono();\n \n const endpoints: Endpoint<any, any, any, any, any, any, any>[] = [\n ${allExportNames.join(',\\n ')}\n ];\n\n const serviceDiscovery = ServiceDiscovery.getInstance(\n logger,\n envParser\n );\n\n // Configure OpenAPI options based on enableOpenApi flag\n const openApiOptions: any = enableOpenApi ? {\n docsPath: '/docs',\n openApiOptions: {\n title: 'API Documentation',\n version: '1.0.0',\n description: 'Generated API documentation'\n }\n } : { docsPath: false };\n\n HonoEndpoint.addRoutes(endpoints, serviceDiscovery, honoApp, openApiOptions);\n\n return honoApp;\n}\n\n// Default export for convenience\nexport default createApp;\n`;\n\n await writeFile(serverPath, content);\n\n return serverPath;\n }\n\n private generateAWSApiGatewayV1Handler(\n importPath: string,\n exportName: string,\n envParserPath: string,\n envParserImportPattern: string,\n ): string {\n return `import { AmazonApiGatewayV1Endpoint } from '@geekmidas/api/aws-apigateway';\nimport { ${exportName} } from '${importPath}';\nimport ${envParserImportPattern} from '${envParserPath}';\n\nconst adapter = new AmazonApiGatewayV1Endpoint(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n }\n\n private generateAWSApiGatewayV2Handler(\n importPath: string,\n exportName: string,\n envParserPath: string,\n envParserImportPattern: string,\n ): string {\n return `import { AmazonApiGatewayV2Endpoint } from '@geekmidas/api/aws-apigateway';\nimport { ${exportName} } from '${importPath}';\nimport ${envParserImportPattern} from '${envParserPath}';\n\nconst adapter = new AmazonApiGatewayV2Endpoint(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n }\n\n private generateServerHandler(\n importPath: string,\n exportName: string,\n ): string {\n return `import { ${exportName} } from '${importPath}';\n\n// Server handler - implement based on your server framework\nexport const handler = ${exportName};\n`;\n }\n}\n"],"mappings":";;;;;;AAWA,IAAa,oBAAb,cAAuC,mBAGrC;CACA,YAAYA,OAA6D;AACvE,SAAO,SAAS,WAAW,MAAM;CAClC;CAED,MAAM,MACJC,SACAC,YACAC,WACAC,SACsB;EACtB,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,gBAAgB,SAAS,iBAAiB;EAChD,MAAM,SAAS;EACf,MAAMC,SAAsB,CAAE;AAE9B,MAAI,WAAW,WAAW,EACxB,QAAO;AAGT,MAAI,aAAa,UAAU;GAEzB,MAAM,aAAa,MAAM,KAAK,mBAC5B,WACA,YACA,SACA,cACD;AAED,UAAO,KAAK;IACV,MAAM;IACN,QAAQ;IACR,SAAS,SAAS,QAAQ,KAAK,EAAE,WAAW;GAC7C,EAAC;AAEF,UAAO,KACJ,4BAA4B,WAAW,OAAO,YAAY,gBAAgB,uBAAuB,GAAG,EACt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W,WAAW,WAAW;SACnC,uBAAuB,SAAS,cAAc;;4DAEK,WAAW;;;;CAIpE;CAED,AAAQ,+BACNF,YACAN,YACAO,eACAC,wBACQ;AACR,UAAQ;WACD,WAAW,WAAW,WAAW;SACnC,uBAAuB,SAAS,cAAc;;4DAEK,WAAW;;;;CAIpE;CAED,AAAQ,sBACNF,YACAN,YACQ;AACR,UAAQ,WAAW,WAAW,WAAW,WAAW;;;yBAG/B,WAAW;;CAEjC;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"FunctionGenerator-DN681IUn.cjs","names":["ConstructGenerator","value: any","context: BuildContext","constructs: GeneratedConstruct<Function<any, any, any, any>>[]","outputDir: string","options?: GeneratorOptions","functionInfos: FunctionInfo[]","sourceFile: string","exportName: string"],"sources":["../src/generators/FunctionGenerator.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { Function } from '@geekmidas/api/constructs';\nimport type { BuildContext } from '../build/types';\nimport type { FunctionInfo } from '../types';\nimport {\n ConstructGenerator,\n type GeneratedConstruct,\n type GeneratorOptions,\n} from './Generator';\n\nexport class FunctionGenerator extends ConstructGenerator<\n Function<any, any, any, any>,\n FunctionInfo[]\n> {\n isConstruct(value: any): value is Function<any, any, any, any> {\n return Function.isFunction(value);\n }\n\n async build(\n context: BuildContext,\n constructs: GeneratedConstruct<Function<any, any, any, any>>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<FunctionInfo[]> {\n const provider = options?.provider || 'aws-lambda';\n const logger = console;\n const functionInfos: FunctionInfo[] = [];\n\n if (constructs.length === 0 || provider !== 'aws-lambda') {\n return functionInfos;\n }\n\n // Create functions subdirectory\n const functionsDir = join(outputDir, 'functions');\n await mkdir(functionsDir, { recursive: true });\n\n // Generate function handlers\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateFunctionHandler(\n functionsDir,\n path.relative,\n key,\n context,\n );\n\n functionInfos.push({\n name: key,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n timeout: construct.timeout,\n });\n\n logger.log(`Generated function handler: ${key}`);\n }\n\n return functionInfos;\n }\n\n private async generateFunctionHandler(\n outputDir: string,\n sourceFile: string,\n exportName: string,\n context: BuildContext,\n ): Promise<string> {\n const handlerFileName = `${exportName}.ts`;\n const handlerPath = join(outputDir, handlerFileName);\n\n const relativePath = relative(dirname(handlerPath), sourceFile);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n const relativeEnvParserPath = relative(\n dirname(handlerPath),\n context.envParserPath,\n );\n const relativeLoggerPath = relative(\n dirname(handlerPath),\n context.loggerPath,\n );\n\n const content = `import { AWSLambdaFunction } from '@geekmidas/api/aws-lambda';\nimport { ${exportName} } from '${importPath}';\nimport ${context.envParserImportPattern} from '${relativeEnvParserPath}';\nimport ${context.loggerImportPattern} from '${relativeLoggerPath}';\n\nconst adapter = new AWSLambdaFunction(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n\n await writeFile(handlerPath, content);\n return handlerPath;\n }\n}\n"],"mappings":";;;;;;;AAWA,IAAa,oBAAb,cAAuCA,qCAGrC;CACA,YAAYC,OAAmD;AAC7D,SAAO,oCAAS,WAAW,MAAM;CAClC;CAED,MAAM,MACJC,SACAC,YACAC,WACAC,SACyB;EACzB,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,SAAS;EACf,MAAMC,gBAAgC,CAAE;AAExC,MAAI,WAAW,WAAW,KAAK,aAAa,aAC1C,QAAO;EAIT,MAAM,eAAe,oBAAK,WAAW,YAAY;AACjD,QAAM,4BAAM,cAAc,EAAE,WAAW,KAAM,EAAC;AAG9C,OAAK,MAAM,EAAE,KAAK,WAAW,MAAM,IAAI,YAAY;GACjD,MAAM,cAAc,MAAM,KAAK,wBAC7B,cACA,KAAK,UACL,KACA,QACD;AAED,iBAAc,KAAK;IACjB,MAAM;IACN,SAAS,wBAAS,QAAQ,KAAK,EAAE,YAAY,CAAC,QAC5C,SACA,WACD;IACD,SAAS,UAAU;GACpB,EAAC;AAEF,UAAO,KAAK,8BAA8B,IAAI,EAAE;EACjD;AAED,SAAO;CACR;CAED,MAAc,wBACZF,WACAG,YACAC,YACAN,SACiB;EACjB,MAAM,mBAAmB,EAAE,WAAW;EACtC,MAAM,cAAc,oBAAK,WAAW,gBAAgB;EAEpD,MAAM,eAAe,wBAAS,uBAAQ,YAAY,EAAE,WAAW;EAC/D,MAAM,aAAa,aAAa,QAAQ,SAAS,MAAM;EAEvD,MAAM,wBAAwB,wBAC5B,uBAAQ,YAAY,EACpB,QAAQ,cACT;EACD,MAAM,qBAAqB,wBACzB,uBAAQ,YAAY,EACpB,QAAQ,WACT;EAED,MAAM,WAAW;WACV,WAAW,WAAW,WAAW;SACnC,QAAQ,uBAAuB,SAAS,sBAAsB;SAC9D,QAAQ,oBAAoB,SAAS,mBAAmB;;mDAEd,WAAW;;;;AAK1D,QAAM,gCAAU,aAAa,QAAQ;AACrC,SAAO;CACR;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"FunctionGenerator-crAa-JC7.mjs","names":["value: any","context: BuildContext","constructs: GeneratedConstruct<Function<any, any, any, any>>[]","outputDir: string","options?: GeneratorOptions","functionInfos: FunctionInfo[]","sourceFile: string","exportName: string"],"sources":["../src/generators/FunctionGenerator.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises';\nimport { dirname, join, relative } from 'node:path';\nimport { Function } from '@geekmidas/api/constructs';\nimport type { BuildContext } from '../build/types';\nimport type { FunctionInfo } from '../types';\nimport {\n ConstructGenerator,\n type GeneratedConstruct,\n type GeneratorOptions,\n} from './Generator';\n\nexport class FunctionGenerator extends ConstructGenerator<\n Function<any, any, any, any>,\n FunctionInfo[]\n> {\n isConstruct(value: any): value is Function<any, any, any, any> {\n return Function.isFunction(value);\n }\n\n async build(\n context: BuildContext,\n constructs: GeneratedConstruct<Function<any, any, any, any>>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<FunctionInfo[]> {\n const provider = options?.provider || 'aws-lambda';\n const logger = console;\n const functionInfos: FunctionInfo[] = [];\n\n if (constructs.length === 0 || provider !== 'aws-lambda') {\n return functionInfos;\n }\n\n // Create functions subdirectory\n const functionsDir = join(outputDir, 'functions');\n await mkdir(functionsDir, { recursive: true });\n\n // Generate function handlers\n for (const { key, construct, path } of constructs) {\n const handlerFile = await this.generateFunctionHandler(\n functionsDir,\n path.relative,\n key,\n context,\n );\n\n functionInfos.push({\n name: key,\n handler: relative(process.cwd(), handlerFile).replace(\n /\\.ts$/,\n '.handler',\n ),\n timeout: construct.timeout,\n });\n\n logger.log(`Generated function handler: ${key}`);\n }\n\n return functionInfos;\n }\n\n private async generateFunctionHandler(\n outputDir: string,\n sourceFile: string,\n exportName: string,\n context: BuildContext,\n ): Promise<string> {\n const handlerFileName = `${exportName}.ts`;\n const handlerPath = join(outputDir, handlerFileName);\n\n const relativePath = relative(dirname(handlerPath), sourceFile);\n const importPath = relativePath.replace(/\\.ts$/, '.js');\n\n const relativeEnvParserPath = relative(\n dirname(handlerPath),\n context.envParserPath,\n );\n const relativeLoggerPath = relative(\n dirname(handlerPath),\n context.loggerPath,\n );\n\n const content = `import { AWSLambdaFunction } from '@geekmidas/api/aws-lambda';\nimport { ${exportName} } from '${importPath}';\nimport ${context.envParserImportPattern} from '${relativeEnvParserPath}';\nimport ${context.loggerImportPattern} from '${relativeLoggerPath}';\n\nconst adapter = new AWSLambdaFunction(envParser, ${exportName});\n\nexport const handler = adapter.handler;\n`;\n\n await writeFile(handlerPath, content);\n return handlerPath;\n }\n}\n"],"mappings":";;;;;;AAWA,IAAa,oBAAb,cAAuC,mBAGrC;CACA,YAAYA,OAAmD;AAC7D,SAAO,SAAS,WAAW,MAAM;CAClC;CAED,MAAM,MACJC,SACAC,YACAC,WACAC,SACyB;EACzB,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,SAAS;EACf,MAAMC,gBAAgC,CAAE;AAExC,MAAI,WAAW,WAAW,KAAK,aAAa,aAC1C,QAAO;EAIT,MAAM,eAAe,KAAK,WAAW,YAAY;AACjD,QAAM,MAAM,cAAc,EAAE,WAAW,KAAM,EAAC;AAG9C,OAAK,MAAM,EAAE,KAAK,WAAW,MAAM,IAAI,YAAY;GACjD,MAAM,cAAc,MAAM,KAAK,wBAC7B,cACA,KAAK,UACL,KACA,QACD;AAED,iBAAc,KAAK;IACjB,MAAM;IACN,SAAS,SAAS,QAAQ,KAAK,EAAE,YAAY,CAAC,QAC5C,SACA,WACD;IACD,SAAS,UAAU;GACpB,EAAC;AAEF,UAAO,KAAK,8BAA8B,IAAI,EAAE;EACjD;AAED,SAAO;CACR;CAED,MAAc,wBACZF,WACAG,YACAC,YACAN,SACiB;EACjB,MAAM,mBAAmB,EAAE,WAAW;EACtC,MAAM,cAAc,KAAK,WAAW,gBAAgB;EAEpD,MAAM,eAAe,SAAS,QAAQ,YAAY,EAAE,WAAW;EAC/D,MAAM,aAAa,aAAa,QAAQ,SAAS,MAAM;EAEvD,MAAM,wBAAwB,SAC5B,QAAQ,YAAY,EACpB,QAAQ,cACT;EACD,MAAM,qBAAqB,SACzB,QAAQ,YAAY,EACpB,QAAQ,WACT;EAED,MAAM,WAAW;WACV,WAAW,WAAW,WAAW;SACnC,QAAQ,uBAAuB,SAAS,sBAAsB;SAC9D,QAAQ,oBAAoB,SAAS,mBAAmB;;mDAEd,WAAW;;;;AAK1D,QAAM,UAAU,aAAa,QAAQ;AACrC,SAAO;CACR;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Generator-C3tYSTQY.cjs","names":["context: BuildContext","outputDir: string","generator: ConstructGenerator<T, R>","patterns?: Routes","options?: GeneratorOptions","constructs: GeneratedConstruct<T>[]","module"],"sources":["../src/generators/Generator.ts"],"sourcesContent":["import { relative } from 'path';\nimport type { Construct } from '@geekmidas/api/constructs';\nimport fg from 'fast-glob';\nimport kebabCase from 'lodash.kebabcase';\nimport type { BuildContext } from '../build/types';\nimport type { LegacyProvider, Routes } from '../types';\n\nexport interface GeneratorOptions {\n provider?: LegacyProvider;\n [key: string]: any;\n}\n\nexport abstract class ConstructGenerator<T extends Construct, R = void> {\n abstract isConstruct(value: any): value is T;\n\n static async build<T extends Construct, R = void>(\n context: BuildContext,\n outputDir: string,\n generator: ConstructGenerator<T, R>,\n patterns?: Routes,\n options?: GeneratorOptions,\n ): Promise<R> {\n const constructs = await generator.load(patterns);\n return generator.build(context, constructs, outputDir, options);\n }\n\n abstract build(\n context: BuildContext,\n constructs: GeneratedConstruct<T>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<R>;\n\n async load(\n patterns?: Routes,\n cwd = process.cwd(),\n ): Promise<GeneratedConstruct<T>[]> {\n const logger = console;\n\n // Normalize patterns to array\n const globPatterns = Array.isArray(patterns)\n ? patterns\n : patterns\n ? [patterns]\n : [];\n\n // Find all files\n const files = fg.stream(globPatterns, {\n cwd,\n absolute: true,\n });\n\n // Load constructs\n const constructs: GeneratedConstruct<T>[] = [];\n\n for await (const f of files) {\n try {\n const file = f.toString();\n const module = await import(file);\n\n // Check all exports for constructs\n for (const [key, construct] of Object.entries(module)) {\n if (this.isConstruct(construct)) {\n constructs.push({\n key,\n name: kebabCase(key),\n construct,\n path: {\n absolute: file,\n relative: relative(process.cwd(), file),\n },\n });\n }\n }\n } catch (error) {\n logger.warn(`Failed to load ${f}:`, (error as Error).message);\n throw new Error(\n 'Failed to load constructs. Please check the logs for details.',\n );\n }\n }\n\n return constructs;\n }\n}\n\nexport interface GeneratedConstruct<T extends Construct> {\n key: string;\n name: string;\n construct: T;\n path: {\n absolute: string;\n relative: string;\n };\n}\n"],"mappings":";;;;;;AAYA,IAAsB,qBAAtB,MAAwE;CAGtE,aAAa,MACXA,SACAC,WACAC,WACAC,UACAC,SACY;EACZ,MAAM,aAAa,MAAM,UAAU,KAAK,SAAS;AACjD,SAAO,UAAU,MAAM,SAAS,YAAY,WAAW,QAAQ;CAChE;CASD,MAAM,KACJD,UACA,MAAM,QAAQ,KAAK,EACe;EAClC,MAAM,SAAS;EAGf,MAAM,eAAe,MAAM,QAAQ,SAAS,GACxC,WACA,WACE,CAAC,QAAS,IACV,CAAE;EAGR,MAAM,QAAQ,kBAAG,OAAO,cAAc;GACpC;GACA,UAAU;EACX,EAAC;EAGF,MAAME,aAAsC,CAAE;AAE9C,aAAW,MAAM,KAAK,MACpB,KAAI;GACF,MAAM,OAAO,EAAE,UAAU;GACzB,MAAMC,WAAS,MAAM,OAAO;AAG5B,QAAK,MAAM,CAAC,KAAK,UAAU,IAAI,OAAO,QAAQA,SAAO,CACnD,KAAI,KAAK,YAAY,UAAU,CAC7B,YAAW,KAAK;IACd;IACA,MAAM,8BAAU,IAAI;IACpB;IACA,MAAM;KACJ,UAAU;KACV,UAAU,mBAAS,QAAQ,KAAK,EAAE,KAAK;IACxC;GACF,EAAC;EAGP,SAAQ,OAAO;AACd,UAAO,MAAM,iBAAiB,EAAE,IAAK,MAAgB,QAAQ;AAC7D,SAAM,IAAI,MACR;EAEH;AAGH,SAAO;CACR;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Generator-CDt4pB3W.mjs","names":["context: BuildContext","outputDir: string","generator: ConstructGenerator<T, R>","patterns?: Routes","options?: GeneratorOptions","constructs: GeneratedConstruct<T>[]"],"sources":["../src/generators/Generator.ts"],"sourcesContent":["import { relative } from 'path';\nimport type { Construct } from '@geekmidas/api/constructs';\nimport fg from 'fast-glob';\nimport kebabCase from 'lodash.kebabcase';\nimport type { BuildContext } from '../build/types';\nimport type { LegacyProvider, Routes } from '../types';\n\nexport interface GeneratorOptions {\n provider?: LegacyProvider;\n [key: string]: any;\n}\n\nexport abstract class ConstructGenerator<T extends Construct, R = void> {\n abstract isConstruct(value: any): value is T;\n\n static async build<T extends Construct, R = void>(\n context: BuildContext,\n outputDir: string,\n generator: ConstructGenerator<T, R>,\n patterns?: Routes,\n options?: GeneratorOptions,\n ): Promise<R> {\n const constructs = await generator.load(patterns);\n return generator.build(context, constructs, outputDir, options);\n }\n\n abstract build(\n context: BuildContext,\n constructs: GeneratedConstruct<T>[],\n outputDir: string,\n options?: GeneratorOptions,\n ): Promise<R>;\n\n async load(\n patterns?: Routes,\n cwd = process.cwd(),\n ): Promise<GeneratedConstruct<T>[]> {\n const logger = console;\n\n // Normalize patterns to array\n const globPatterns = Array.isArray(patterns)\n ? patterns\n : patterns\n ? [patterns]\n : [];\n\n // Find all files\n const files = fg.stream(globPatterns, {\n cwd,\n absolute: true,\n });\n\n // Load constructs\n const constructs: GeneratedConstruct<T>[] = [];\n\n for await (const f of files) {\n try {\n const file = f.toString();\n const module = await import(file);\n\n // Check all exports for constructs\n for (const [key, construct] of Object.entries(module)) {\n if (this.isConstruct(construct)) {\n constructs.push({\n key,\n name: kebabCase(key),\n construct,\n path: {\n absolute: file,\n relative: relative(process.cwd(), file),\n },\n });\n }\n }\n } catch (error) {\n logger.warn(`Failed to load ${f}:`, (error as Error).message);\n throw new Error(\n 'Failed to load constructs. Please check the logs for details.',\n );\n }\n }\n\n return constructs;\n }\n}\n\nexport interface GeneratedConstruct<T extends Construct> {\n key: string;\n name: string;\n construct: T;\n path: {\n absolute: string;\n relative: string;\n };\n}\n"],"mappings":";;;;;AAYA,IAAsB,qBAAtB,MAAwE;CAGtE,aAAa,MACXA,SACAC,WACAC,WACAC,UACAC,SACY;EACZ,MAAM,aAAa,MAAM,UAAU,KAAK,SAAS;AACjD,SAAO,UAAU,MAAM,SAAS,YAAY,WAAW,QAAQ;CAChE;CASD,MAAM,KACJD,UACA,MAAM,QAAQ,KAAK,EACe;EAClC,MAAM,SAAS;EAGf,MAAM,eAAe,MAAM,QAAQ,SAAS,GACxC,WACA,WACE,CAAC,QAAS,IACV,CAAE;EAGR,MAAM,QAAQ,GAAG,OAAO,cAAc;GACpC;GACA,UAAU;EACX,EAAC;EAGF,MAAME,aAAsC,CAAE;AAE9C,aAAW,MAAM,KAAK,MACpB,KAAI;GACF,MAAM,OAAO,EAAE,UAAU;GACzB,MAAM,SAAS,MAAM,OAAO;AAG5B,QAAK,MAAM,CAAC,KAAK,UAAU,IAAI,OAAO,QAAQ,OAAO,CACnD,KAAI,KAAK,YAAY,UAAU,CAC7B,YAAW,KAAK;IACd;IACA,MAAM,UAAU,IAAI;IACpB;IACA,MAAM;KACJ,UAAU;KACV,UAAU,SAAS,QAAQ,KAAK,EAAE,KAAK;IACxC;GACF,EAAC;EAGP,SAAQ,OAAO;AACd,UAAO,MAAM,iBAAiB,EAAE,IAAK,MAAgB,QAAQ;AAC7D,SAAM,IAAI,MACR;EAEH;AAGH,SAAO;CACR;AACF"}