@geekmidas/cli 0.10.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +525 -0
- package/dist/bundler-B1qy9b-j.cjs +112 -0
- package/dist/bundler-B1qy9b-j.cjs.map +1 -0
- package/dist/bundler-DskIqW2t.mjs +111 -0
- package/dist/bundler-DskIqW2t.mjs.map +1 -0
- package/dist/{config-C9aXOHBe.cjs → config-AmInkU7k.cjs} +8 -8
- package/dist/config-AmInkU7k.cjs.map +1 -0
- package/dist/{config-BrkUalUh.mjs → config-DYULeEv8.mjs} +3 -3
- package/dist/config-DYULeEv8.mjs.map +1 -0
- package/dist/config.cjs +1 -1
- package/dist/config.d.cts +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config.mjs +1 -1
- package/dist/encryption-C8H-38Yy.mjs +42 -0
- package/dist/encryption-C8H-38Yy.mjs.map +1 -0
- package/dist/encryption-Dyf_r1h-.cjs +44 -0
- package/dist/encryption-Dyf_r1h-.cjs.map +1 -0
- package/dist/index.cjs +2123 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2141 -192
- package/dist/index.mjs.map +1 -1
- package/dist/{openapi-CZLI4QTr.mjs → openapi-BfFlOBCG.mjs} +801 -38
- package/dist/openapi-BfFlOBCG.mjs.map +1 -0
- package/dist/{openapi-BeHLKcwP.cjs → openapi-Bt_1FDpT.cjs} +794 -31
- package/dist/openapi-Bt_1FDpT.cjs.map +1 -0
- package/dist/{openapi-react-query-o5iMi8tz.cjs → openapi-react-query-B-sNWHFU.cjs} +5 -5
- package/dist/openapi-react-query-B-sNWHFU.cjs.map +1 -0
- package/dist/{openapi-react-query-CcciaVu5.mjs → openapi-react-query-B6XTeGqS.mjs} +5 -5
- package/dist/openapi-react-query-B6XTeGqS.mjs.map +1 -0
- package/dist/openapi-react-query.cjs +1 -1
- package/dist/openapi-react-query.d.cts.map +1 -1
- package/dist/openapi-react-query.d.mts.map +1 -1
- package/dist/openapi-react-query.mjs +1 -1
- package/dist/openapi.cjs +2 -2
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.cts.map +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +2 -2
- package/dist/storage-BOOpAF8N.cjs +5 -0
- package/dist/storage-Bj1E26lU.cjs +187 -0
- package/dist/storage-Bj1E26lU.cjs.map +1 -0
- package/dist/storage-kSxTjkNb.mjs +133 -0
- package/dist/storage-kSxTjkNb.mjs.map +1 -0
- package/dist/storage-tgZSUnKl.mjs +3 -0
- package/dist/{types-b-vwGpqc.d.cts → types-BR0M2v_c.d.mts} +100 -1
- package/dist/types-BR0M2v_c.d.mts.map +1 -0
- package/dist/{types-DXgiA1sF.d.mts → types-BhkZc-vm.d.cts} +100 -1
- package/dist/types-BhkZc-vm.d.cts.map +1 -0
- package/examples/cron-example.ts +27 -27
- package/examples/env.ts +27 -27
- package/examples/function-example.ts +31 -31
- package/examples/gkm.config.json +20 -20
- package/examples/gkm.config.ts +8 -8
- package/examples/gkm.minimal.config.json +5 -5
- package/examples/gkm.production.config.json +25 -25
- package/examples/logger.ts +2 -2
- package/package.json +6 -6
- package/src/__tests__/EndpointGenerator.hooks.spec.ts +191 -191
- package/src/__tests__/config.spec.ts +55 -55
- package/src/__tests__/loadEnvFiles.spec.ts +93 -93
- package/src/__tests__/normalizeHooksConfig.spec.ts +58 -58
- package/src/__tests__/openapi-react-query.spec.ts +497 -497
- package/src/__tests__/openapi.spec.ts +428 -428
- package/src/__tests__/test-helpers.ts +76 -76
- package/src/auth/__tests__/credentials.spec.ts +204 -0
- package/src/auth/__tests__/index.spec.ts +168 -0
- package/src/auth/credentials.ts +187 -0
- package/src/auth/index.ts +226 -0
- package/src/build/__tests__/bundler.spec.ts +444 -0
- package/src/build/__tests__/index-new.spec.ts +474 -474
- package/src/build/__tests__/manifests.spec.ts +333 -333
- package/src/build/bundler.ts +210 -0
- package/src/build/endpoint-analyzer.ts +236 -0
- package/src/build/handler-templates.ts +1253 -0
- package/src/build/index.ts +260 -179
- package/src/build/manifests.ts +52 -52
- package/src/build/providerResolver.ts +145 -145
- package/src/build/types.ts +64 -43
- package/src/config.ts +39 -39
- package/src/deploy/__tests__/docker.spec.ts +111 -0
- package/src/deploy/__tests__/dokploy.spec.ts +245 -0
- package/src/deploy/__tests__/init.spec.ts +662 -0
- package/src/deploy/docker.ts +128 -0
- package/src/deploy/dokploy.ts +204 -0
- package/src/deploy/index.ts +136 -0
- package/src/deploy/init.ts +484 -0
- package/src/deploy/types.ts +48 -0
- package/src/dev/__tests__/index.spec.ts +266 -266
- package/src/dev/index.ts +647 -601
- package/src/docker/__tests__/compose.spec.ts +531 -0
- package/src/docker/__tests__/templates.spec.ts +280 -0
- package/src/docker/compose.ts +273 -0
- package/src/docker/index.ts +230 -0
- package/src/docker/templates.ts +446 -0
- package/src/generators/CronGenerator.ts +72 -72
- package/src/generators/EndpointGenerator.ts +699 -398
- package/src/generators/FunctionGenerator.ts +84 -84
- package/src/generators/Generator.ts +72 -72
- package/src/generators/OpenApiTsGenerator.ts +577 -577
- package/src/generators/SubscriberGenerator.ts +124 -124
- package/src/generators/__tests__/CronGenerator.spec.ts +433 -433
- package/src/generators/__tests__/EndpointGenerator.spec.ts +532 -382
- package/src/generators/__tests__/FunctionGenerator.spec.ts +244 -244
- package/src/generators/__tests__/SubscriberGenerator.spec.ts +397 -382
- package/src/generators/index.ts +4 -4
- package/src/index.ts +623 -201
- package/src/init/__tests__/generators.spec.ts +334 -334
- package/src/init/__tests__/init.spec.ts +332 -332
- package/src/init/__tests__/utils.spec.ts +89 -89
- package/src/init/generators/config.ts +175 -175
- package/src/init/generators/docker.ts +41 -41
- package/src/init/generators/env.ts +72 -72
- package/src/init/generators/index.ts +1 -1
- package/src/init/generators/models.ts +64 -64
- package/src/init/generators/monorepo.ts +161 -161
- package/src/init/generators/package.ts +71 -71
- package/src/init/generators/source.ts +6 -6
- package/src/init/index.ts +203 -208
- package/src/init/templates/api.ts +115 -115
- package/src/init/templates/index.ts +75 -75
- package/src/init/templates/minimal.ts +98 -98
- package/src/init/templates/serverless.ts +89 -89
- package/src/init/templates/worker.ts +98 -98
- package/src/init/utils.ts +54 -56
- package/src/openapi-react-query.ts +194 -194
- package/src/openapi.ts +63 -63
- package/src/secrets/__tests__/encryption.spec.ts +226 -0
- package/src/secrets/__tests__/generator.spec.ts +319 -0
- package/src/secrets/__tests__/index.spec.ts +91 -0
- package/src/secrets/__tests__/storage.spec.ts +611 -0
- package/src/secrets/encryption.ts +91 -0
- package/src/secrets/generator.ts +164 -0
- package/src/secrets/index.ts +383 -0
- package/src/secrets/storage.ts +192 -0
- package/src/secrets/types.ts +53 -0
- package/src/types.ts +295 -176
- package/tsdown.config.ts +11 -8
- package/dist/config-BrkUalUh.mjs.map +0 -1
- package/dist/config-C9aXOHBe.cjs.map +0 -1
- package/dist/openapi-BeHLKcwP.cjs.map +0 -1
- package/dist/openapi-CZLI4QTr.mjs.map +0 -1
- package/dist/openapi-react-query-CcciaVu5.mjs.map +0 -1
- package/dist/openapi-react-query-o5iMi8tz.cjs.map +0 -1
- package/dist/types-DXgiA1sF.d.mts.map +0 -1
- package/dist/types-b-vwGpqc.d.cts.map +0 -1
|
@@ -1,256 +1,256 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { f } from '@geekmidas/constructs/functions';
|
|
4
3
|
import type { Function } from '@geekmidas/constructs/functions';
|
|
4
|
+
import { f } from '@geekmidas/constructs/functions';
|
|
5
5
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
cleanupDir,
|
|
9
|
+
createMockBuildContext,
|
|
10
|
+
createTempDir,
|
|
11
11
|
} from '../../__tests__/test-helpers';
|
|
12
12
|
import { FunctionGenerator } from '../FunctionGenerator';
|
|
13
13
|
import type { GeneratedConstruct } from '../Generator';
|
|
14
14
|
|
|
15
15
|
describe('FunctionGenerator', () => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
16
|
+
let tempDir: string;
|
|
17
|
+
let outputDir: string;
|
|
18
|
+
let generator: FunctionGenerator;
|
|
19
|
+
let context: ReturnType<typeof createMockBuildContext>;
|
|
20
|
+
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
tempDir = await createTempDir();
|
|
23
|
+
outputDir = join(tempDir, 'output');
|
|
24
|
+
generator = new FunctionGenerator();
|
|
25
|
+
context = createMockBuildContext();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(async () => {
|
|
29
|
+
await cleanupDir(tempDir);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('isConstruct', () => {
|
|
33
|
+
it('should identify valid functions', () => {
|
|
34
|
+
const testFunction = f
|
|
35
|
+
.input(z.object({ name: z.string() }))
|
|
36
|
+
.output(z.object({ greeting: z.string() }))
|
|
37
|
+
.timeout(30)
|
|
38
|
+
.handle(async ({ input }) => ({
|
|
39
|
+
greeting: `Hello, ${input.name}!`,
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
expect(generator.isConstruct(testFunction)).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 createTestFunctionConstruct = (
|
|
54
|
+
key: string,
|
|
55
|
+
timeout: number = 30,
|
|
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
|
+
};
|
|
71
|
+
|
|
72
|
+
describe('aws-lambda provider', () => {
|
|
73
|
+
it('should generate function handlers', async () => {
|
|
74
|
+
const constructs = [
|
|
75
|
+
createTestFunctionConstruct('processData', 60),
|
|
76
|
+
createTestFunctionConstruct('sendEmail', 30),
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
const functionInfos = await generator.build(
|
|
80
|
+
context,
|
|
81
|
+
constructs,
|
|
82
|
+
outputDir,
|
|
83
|
+
{ provider: 'aws-lambda' },
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(functionInfos).toHaveLength(2);
|
|
87
|
+
expect(functionInfos[0]).toMatchObject({
|
|
88
|
+
name: 'processData',
|
|
89
|
+
handler: expect.stringContaining('functions/processData.handler'),
|
|
90
|
+
timeout: 60,
|
|
91
|
+
});
|
|
92
|
+
expect(functionInfos[1]).toMatchObject({
|
|
93
|
+
name: 'sendEmail',
|
|
94
|
+
handler: expect.stringContaining('functions/sendEmail.handler'),
|
|
95
|
+
timeout: 30,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Check that handler files were created
|
|
99
|
+
const processDataHandlerPath = join(
|
|
100
|
+
outputDir,
|
|
101
|
+
'functions',
|
|
102
|
+
'processData.ts',
|
|
103
|
+
);
|
|
104
|
+
const processDataContent = await readFile(
|
|
105
|
+
processDataHandlerPath,
|
|
106
|
+
'utf-8',
|
|
107
|
+
);
|
|
108
|
+
expect(processDataContent).toContain('AWSLambdaFunction');
|
|
109
|
+
expect(processDataContent).toContain('import { processData }');
|
|
110
|
+
expect(processDataContent).toContain('import envParser');
|
|
111
|
+
expect(processDataContent).toContain('import logger');
|
|
112
|
+
|
|
113
|
+
const sendEmailHandlerPath = join(
|
|
114
|
+
outputDir,
|
|
115
|
+
'functions',
|
|
116
|
+
'sendEmail.ts',
|
|
117
|
+
);
|
|
118
|
+
const sendEmailContent = await readFile(sendEmailHandlerPath, 'utf-8');
|
|
119
|
+
expect(sendEmailContent).toContain('AWSLambdaFunction');
|
|
120
|
+
expect(sendEmailContent).toContain('import { sendEmail }');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should generate correct relative import paths', async () => {
|
|
124
|
+
const construct: GeneratedConstruct<Function<any, any, any, any>> = {
|
|
125
|
+
key: 'deepFunction',
|
|
126
|
+
name: 'deep-function',
|
|
127
|
+
construct: createTestFunctionConstruct('deepFunction', 45).construct,
|
|
128
|
+
path: {
|
|
129
|
+
absolute: join(tempDir, 'src/functions/deep/processor.ts'),
|
|
130
|
+
relative: 'src/functions/deep/processor.ts',
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
await generator.build(context, [construct], outputDir, {
|
|
135
|
+
provider: 'aws-lambda',
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const handlerPath = join(outputDir, 'functions', 'deepFunction.ts');
|
|
139
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
140
|
+
|
|
141
|
+
// Check relative imports are correct - the path will be relative from outputDir
|
|
142
|
+
expect(handlerContent).toMatch(
|
|
143
|
+
/from ['"].*src\/functions\/deep\/processor\.js['"]/,
|
|
144
|
+
);
|
|
145
|
+
expect(handlerContent).toMatch(/from ['"].*\/env['"]/);
|
|
146
|
+
expect(handlerContent).toMatch(/from ['"].*\/logger['"]/);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('should log generation progress', async () => {
|
|
150
|
+
const logSpy = vi.spyOn(console, 'log');
|
|
151
|
+
|
|
152
|
+
const constructs = [createTestFunctionConstruct('testFunction', 30)];
|
|
153
|
+
|
|
154
|
+
await generator.build(context, constructs, outputDir, {
|
|
155
|
+
provider: 'aws-lambda',
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
159
|
+
'Generated function handler: testFunction',
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
logSpy.mockRestore();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
describe('non aws-lambda provider', () => {
|
|
167
|
+
it('should return empty array for server provider', async () => {
|
|
168
|
+
const constructs = [createTestFunctionConstruct('testFunction', 30)];
|
|
169
|
+
|
|
170
|
+
const functionInfos = await generator.build(
|
|
171
|
+
context,
|
|
172
|
+
constructs,
|
|
173
|
+
outputDir,
|
|
174
|
+
{ provider: 'server' },
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
expect(functionInfos).toEqual([]);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should return empty array for aws-apigatewayv1 provider', async () => {
|
|
181
|
+
const constructs = [createTestFunctionConstruct('testFunction', 30)];
|
|
182
|
+
|
|
183
|
+
const functionInfos = await generator.build(
|
|
184
|
+
context,
|
|
185
|
+
constructs,
|
|
186
|
+
outputDir,
|
|
187
|
+
{ provider: 'aws-apigatewayv1' },
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
expect(functionInfos).toEqual([]);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should return empty array for empty constructs', async () => {
|
|
195
|
+
const functionInfos = await generator.build(context, [], outputDir, {
|
|
196
|
+
provider: 'aws-lambda',
|
|
197
|
+
});
|
|
198
|
+
expect(functionInfos).toEqual([]);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('should use default provider when none specified', async () => {
|
|
202
|
+
const constructs = [createTestFunctionConstruct('defaultFunction', 30)];
|
|
203
|
+
|
|
204
|
+
const functionInfos = await generator.build(
|
|
205
|
+
context,
|
|
206
|
+
constructs,
|
|
207
|
+
outputDir,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
expect(functionInfos).toHaveLength(1);
|
|
211
|
+
expect(functionInfos[0].name).toBe('defaultFunction');
|
|
212
|
+
|
|
213
|
+
// Check that handler was created (default is aws-lambda)
|
|
214
|
+
const handlerPath = join(outputDir, 'functions', 'defaultFunction.ts');
|
|
215
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
216
|
+
expect(handlerContent).toContain('AWSLambdaFunction');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should handle functions with different timeout values', async () => {
|
|
220
|
+
const constructs = [
|
|
221
|
+
createTestFunctionConstruct('quickFunction', 15),
|
|
222
|
+
createTestFunctionConstruct('slowFunction', 300),
|
|
223
|
+
];
|
|
224
|
+
|
|
225
|
+
const functionInfos = await generator.build(
|
|
226
|
+
context,
|
|
227
|
+
constructs,
|
|
228
|
+
outputDir,
|
|
229
|
+
{ provider: 'aws-lambda' },
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
expect(functionInfos[0].timeout).toBe(15);
|
|
233
|
+
expect(functionInfos[1].timeout).toBe(300);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('should handle functions with custom environment parser patterns', async () => {
|
|
237
|
+
const customContext = {
|
|
238
|
+
...context,
|
|
239
|
+
envParserImportPattern: '{ customParser as envParser }',
|
|
240
|
+
loggerImportPattern: '{ customLogger as logger }',
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const constructs = [createTestFunctionConstruct('customFunction', 30)];
|
|
244
|
+
|
|
245
|
+
await generator.build(customContext, constructs, outputDir, {
|
|
246
|
+
provider: 'aws-lambda',
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
const handlerPath = join(outputDir, 'functions', 'customFunction.ts');
|
|
250
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
251
|
+
|
|
252
|
+
expect(handlerContent).toContain('import { customParser as envParser }');
|
|
253
|
+
expect(handlerContent).toContain('import { customLogger as logger }');
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
256
|
});
|