@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,394 +1,544 @@
|
|
|
1
1
|
import { mkdir, readFile } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
+
import type { HttpMethod } from '@geekmidas/constructs';
|
|
3
4
|
import type { Endpoint } from '@geekmidas/constructs/endpoints';
|
|
4
5
|
import { itWithDir } from '@geekmidas/testkit/os';
|
|
5
6
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import type { HttpMethod } from '@geekmidas/constructs';
|
|
8
7
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
createMockBuildContext,
|
|
9
|
+
createMockEndpointFile,
|
|
10
|
+
createTestEndpoint,
|
|
12
11
|
} from '../../__tests__/test-helpers';
|
|
13
12
|
import { EndpointGenerator } from '../EndpointGenerator';
|
|
14
13
|
import type { GeneratedConstruct } from '../Generator';
|
|
15
14
|
|
|
16
15
|
describe('EndpointGenerator', () => {
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
16
|
+
let _tempDir: string;
|
|
17
|
+
let _outputDir: string;
|
|
18
|
+
let generator: EndpointGenerator;
|
|
19
|
+
let context: ReturnType<typeof createMockBuildContext>;
|
|
20
|
+
|
|
21
|
+
beforeEach(async () => {
|
|
22
|
+
generator = new EndpointGenerator();
|
|
23
|
+
context = createMockBuildContext();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(async () => {});
|
|
27
|
+
|
|
28
|
+
it('should identify valid endpoints', () => {
|
|
29
|
+
const testEndpoint = createTestEndpoint('/test', 'GET');
|
|
30
|
+
expect(generator.isConstruct(testEndpoint)).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should reject invalid constructs', () => {
|
|
34
|
+
expect(generator.isConstruct({})).toBe(false);
|
|
35
|
+
expect(generator.isConstruct('string')).toBe(false);
|
|
36
|
+
expect(generator.isConstruct(null)).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const createTestEndpointConstruct = (
|
|
40
|
+
key: string,
|
|
41
|
+
path: string,
|
|
42
|
+
method: HttpMethod,
|
|
43
|
+
dir: string,
|
|
44
|
+
): GeneratedConstruct<Endpoint<any, any, any, any, any, any>> => ({
|
|
45
|
+
key,
|
|
46
|
+
name: key.toLowerCase(),
|
|
47
|
+
construct: createTestEndpoint(path, method),
|
|
48
|
+
path: {
|
|
49
|
+
absolute: join(dir, `${key}.ts`),
|
|
50
|
+
relative: `./${key}.ts`,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
itWithDir('should generate a single server app file', async ({ dir }) => {
|
|
55
|
+
const outputDir = join(dir, 'output');
|
|
56
|
+
const routesDir = join(dir, 'routes');
|
|
57
|
+
await mkdir(outputDir, { recursive: true });
|
|
58
|
+
|
|
59
|
+
await Promise.all([
|
|
60
|
+
createMockEndpointFile(
|
|
61
|
+
routesDir,
|
|
62
|
+
'testEndpoint.ts',
|
|
63
|
+
'testEndpoint',
|
|
64
|
+
'/test',
|
|
65
|
+
'GET',
|
|
66
|
+
),
|
|
67
|
+
createMockEndpointFile(
|
|
68
|
+
routesDir,
|
|
69
|
+
'anotherEndpoint.ts',
|
|
70
|
+
'anotherEndpoint',
|
|
71
|
+
'/another',
|
|
72
|
+
'POST',
|
|
73
|
+
),
|
|
74
|
+
]);
|
|
75
|
+
|
|
76
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
77
|
+
|
|
78
|
+
const routes = await generator.build(context, constructs, outputDir, {
|
|
79
|
+
provider: 'server',
|
|
80
|
+
enableOpenApi: true,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
expect(routes).toHaveLength(1);
|
|
84
|
+
expect(routes[0]).toMatchObject({
|
|
85
|
+
path: '*',
|
|
86
|
+
method: 'ALL',
|
|
87
|
+
handler: expect.stringContaining('app.ts'),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Check that the app.ts file was created
|
|
91
|
+
const appPath = join(outputDir, 'app.ts');
|
|
92
|
+
const appContent = await readFile(appPath, 'utf-8');
|
|
93
|
+
|
|
94
|
+
expect(appContent).toContain('import { setupEndpoints }');
|
|
95
|
+
expect(appContent).toContain('import { setupSubscribers }');
|
|
96
|
+
expect(appContent).toContain('function createApp');
|
|
97
|
+
expect(appContent).toContain('app?: HonoType');
|
|
98
|
+
expect(appContent).toContain('enableOpenApi: boolean = true');
|
|
99
|
+
expect(appContent).toContain('interface ServerApp');
|
|
100
|
+
expect(appContent).toContain('async start(options');
|
|
101
|
+
expect(appContent).toContain('serve: (app: HonoType, port: number)');
|
|
102
|
+
|
|
103
|
+
// Check that the endpoints.ts file was created with endpoint logic
|
|
104
|
+
const endpointsPath = join(outputDir, 'endpoints.ts');
|
|
105
|
+
const endpointsContent = await readFile(endpointsPath, 'utf-8');
|
|
106
|
+
|
|
107
|
+
expect(endpointsContent).toContain('import { HonoEndpoint }');
|
|
108
|
+
expect(endpointsContent).toContain('import { testEndpoint }');
|
|
109
|
+
expect(endpointsContent).toContain('import { anotherEndpoint }');
|
|
110
|
+
// Function signature always defaults to true
|
|
111
|
+
expect(endpointsContent).toContain('enableOpenApi: boolean = true');
|
|
112
|
+
// OpenAPI options are configured based on the parameter
|
|
113
|
+
expect(endpointsContent).toContain("docsPath: '/__docs'");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
itWithDir(
|
|
117
|
+
'should generate server app without OpenAPI when disabled',
|
|
118
|
+
async ({ dir }) => {
|
|
119
|
+
const outputDir = join(dir, 'output');
|
|
120
|
+
const routesDir = join(dir, 'routes');
|
|
121
|
+
await mkdir(outputDir, { recursive: true });
|
|
122
|
+
|
|
123
|
+
await createMockEndpointFile(
|
|
124
|
+
routesDir,
|
|
125
|
+
'testEndpoint.ts',
|
|
126
|
+
'testEndpoint',
|
|
127
|
+
'/test',
|
|
128
|
+
'GET',
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
132
|
+
|
|
133
|
+
await generator.build(context, constructs, outputDir, {
|
|
134
|
+
provider: 'server',
|
|
135
|
+
enableOpenApi: false,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const appPath = join(outputDir, 'app.ts');
|
|
139
|
+
const appContent = await readFile(appPath, 'utf-8');
|
|
140
|
+
|
|
141
|
+
expect(appContent).toContain('function createApp');
|
|
142
|
+
|
|
143
|
+
// Check that the endpoints.ts file defaults to true (but can be overridden)
|
|
144
|
+
const endpointsPath = join(outputDir, 'endpoints.ts');
|
|
145
|
+
const endpointsContent = await readFile(endpointsPath, 'utf-8');
|
|
146
|
+
|
|
147
|
+
// The function signature always defaults to true
|
|
148
|
+
expect(endpointsContent).toContain('enableOpenApi: boolean = true');
|
|
149
|
+
// But the OpenAPI options are configured dynamically based on the parameter
|
|
150
|
+
expect(endpointsContent).toContain('docsPath: false');
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
itWithDir(
|
|
155
|
+
'should generate individual handlers in routes subdirectory',
|
|
156
|
+
async ({ dir }) => {
|
|
157
|
+
const outputDir = join(dir, 'output');
|
|
158
|
+
const routesDir = join(dir, 'routes');
|
|
159
|
+
await mkdir(outputDir, { recursive: true });
|
|
160
|
+
|
|
161
|
+
await Promise.all([
|
|
162
|
+
createMockEndpointFile(
|
|
163
|
+
routesDir,
|
|
164
|
+
'testEndpoint.ts',
|
|
165
|
+
'testEndpoint',
|
|
166
|
+
'/test',
|
|
167
|
+
'GET',
|
|
168
|
+
),
|
|
169
|
+
createMockEndpointFile(
|
|
170
|
+
routesDir,
|
|
171
|
+
'anotherEndpoint.ts',
|
|
172
|
+
'anotherEndpoint',
|
|
173
|
+
'/another',
|
|
174
|
+
'POST',
|
|
175
|
+
),
|
|
176
|
+
]);
|
|
177
|
+
|
|
178
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
179
|
+
|
|
180
|
+
const routes = await generator.build(context, constructs, outputDir, {
|
|
181
|
+
provider: 'aws-lambda',
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
expect(routes).toHaveLength(2);
|
|
185
|
+
|
|
186
|
+
// Find routes by their path since order may vary
|
|
187
|
+
const testRoute = routes.find((r) => r.path === '/test');
|
|
188
|
+
const anotherRoute = routes.find((r) => r.path === '/another');
|
|
189
|
+
|
|
190
|
+
expect(testRoute).toMatchObject({
|
|
191
|
+
path: '/test',
|
|
192
|
+
method: 'GET',
|
|
193
|
+
handler: expect.stringContaining('routes/testEndpoint.handler'),
|
|
194
|
+
});
|
|
195
|
+
expect(anotherRoute).toMatchObject({
|
|
196
|
+
path: '/another',
|
|
197
|
+
method: 'POST',
|
|
198
|
+
handler: expect.stringContaining('routes/anotherEndpoint.handler'),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Check that handler files were created
|
|
202
|
+
const testHandlerPath = join(outputDir, 'routes', 'testEndpoint.ts');
|
|
203
|
+
const testHandlerContent = await readFile(testHandlerPath, 'utf-8');
|
|
204
|
+
expect(testHandlerContent).toContain('AmazonApiGatewayV2Endpoint');
|
|
205
|
+
expect(testHandlerContent).toContain('import { testEndpoint }');
|
|
206
|
+
|
|
207
|
+
const anotherHandlerPath = join(
|
|
208
|
+
outputDir,
|
|
209
|
+
'routes',
|
|
210
|
+
'anotherEndpoint.ts',
|
|
211
|
+
);
|
|
212
|
+
const anotherHandlerContent = await readFile(anotherHandlerPath, 'utf-8');
|
|
213
|
+
expect(anotherHandlerContent).toContain('AmazonApiGatewayV2Endpoint');
|
|
214
|
+
expect(anotherHandlerContent).toContain('import { anotherEndpoint }');
|
|
215
|
+
},
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
itWithDir(
|
|
219
|
+
'should generate individual handlers with v1 adapter',
|
|
220
|
+
async ({ dir }) => {
|
|
221
|
+
const outputDir = join(dir, 'output');
|
|
222
|
+
const routesDir = join(dir, 'routes');
|
|
223
|
+
await mkdir(outputDir, { recursive: true });
|
|
224
|
+
|
|
225
|
+
await createMockEndpointFile(
|
|
226
|
+
routesDir,
|
|
227
|
+
'testEndpoint.ts',
|
|
228
|
+
'testEndpoint',
|
|
229
|
+
'/test',
|
|
230
|
+
'GET',
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
234
|
+
|
|
235
|
+
const routes = await generator.build(context, constructs, outputDir, {
|
|
236
|
+
provider: 'aws-apigatewayv1',
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
expect(routes).toHaveLength(1);
|
|
240
|
+
|
|
241
|
+
const handlerPath = join(outputDir, 'testEndpoint.ts');
|
|
242
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
243
|
+
expect(handlerContent).toContain('AmazonApiGatewayV1Endpoint');
|
|
244
|
+
expect(handlerContent).toContain('import { testEndpoint }');
|
|
245
|
+
},
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
itWithDir(
|
|
249
|
+
'should generate individual handlers with v2 adapter',
|
|
250
|
+
async ({ dir }) => {
|
|
251
|
+
const outputDir = join(dir, 'output');
|
|
252
|
+
const routesDir = join(dir, 'routes');
|
|
253
|
+
await mkdir(outputDir, { recursive: true });
|
|
254
|
+
|
|
255
|
+
await createMockEndpointFile(
|
|
256
|
+
routesDir,
|
|
257
|
+
'testEndpoint.ts',
|
|
258
|
+
'testEndpoint',
|
|
259
|
+
'/test',
|
|
260
|
+
'GET',
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
264
|
+
|
|
265
|
+
const routes = await generator.build(context, constructs, outputDir, {
|
|
266
|
+
provider: 'aws-apigatewayv2',
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
expect(routes).toHaveLength(1);
|
|
270
|
+
|
|
271
|
+
const handlerPath = join(outputDir, 'testEndpoint.ts');
|
|
272
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
273
|
+
expect(handlerContent).toContain('AmazonApiGatewayV2Endpoint');
|
|
274
|
+
expect(handlerContent).toContain('import { testEndpoint }');
|
|
275
|
+
},
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
itWithDir(
|
|
279
|
+
'should return empty array for empty constructs',
|
|
280
|
+
async ({ dir }) => {
|
|
281
|
+
const outputDir = join(dir, 'output');
|
|
282
|
+
const routes = await generator.build(context, [], outputDir);
|
|
283
|
+
expect(routes).toEqual([]);
|
|
284
|
+
},
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
itWithDir(
|
|
288
|
+
'should use default provider when none specified',
|
|
289
|
+
async ({ dir }) => {
|
|
290
|
+
const outputDir = join(dir, 'output');
|
|
291
|
+
const routesDir = join(dir, 'routes');
|
|
292
|
+
await mkdir(outputDir, { recursive: true });
|
|
293
|
+
|
|
294
|
+
await createMockEndpointFile(
|
|
295
|
+
routesDir,
|
|
296
|
+
'testEndpoint.ts',
|
|
297
|
+
'testEndpoint',
|
|
298
|
+
'/test',
|
|
299
|
+
'GET',
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
303
|
+
|
|
304
|
+
const routes = await generator.build(context, constructs, outputDir);
|
|
305
|
+
|
|
306
|
+
expect(routes).toHaveLength(1);
|
|
307
|
+
|
|
308
|
+
// Should use default aws-apigatewayv2
|
|
309
|
+
const handlerPath = join(outputDir, 'testEndpoint.ts');
|
|
310
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
311
|
+
expect(handlerContent).toContain('AmazonApiGatewayV2Endpoint');
|
|
312
|
+
},
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
itWithDir('should throw error for unsupported provider', async ({ dir }) => {
|
|
316
|
+
const outputDir = join(dir, 'output');
|
|
317
|
+
const constructs = [
|
|
318
|
+
createTestEndpointConstruct('testEndpoint', '/test', 'GET', dir),
|
|
319
|
+
];
|
|
320
|
+
|
|
321
|
+
await expect(
|
|
322
|
+
generator.build(context, constructs, outputDir, {
|
|
323
|
+
provider: 'unsupported' as any,
|
|
324
|
+
}),
|
|
325
|
+
).rejects.toThrow('Unsupported provider: unsupported');
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
itWithDir(
|
|
329
|
+
'should generate correct import paths for nested files',
|
|
330
|
+
async ({ dir }) => {
|
|
331
|
+
const outputDir = join(dir, 'output');
|
|
332
|
+
const nestedDir = join(dir, 'src', 'api', 'endpoints');
|
|
333
|
+
await mkdir(outputDir, { recursive: true });
|
|
334
|
+
|
|
335
|
+
await createMockEndpointFile(
|
|
336
|
+
nestedDir,
|
|
337
|
+
'deepEndpoint.ts',
|
|
338
|
+
'deepEndpoint',
|
|
339
|
+
'/deep',
|
|
340
|
+
'GET',
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
const constructs = await generator.load('**/src/api/endpoints/*.ts', dir);
|
|
344
|
+
|
|
345
|
+
await generator.build(context, constructs, outputDir, {
|
|
346
|
+
provider: 'aws-apigatewayv2',
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const handlerPath = join(outputDir, 'deepEndpoint.ts');
|
|
350
|
+
const handlerContent = await readFile(handlerPath, 'utf-8');
|
|
351
|
+
|
|
352
|
+
// Check that relative imports are correct
|
|
353
|
+
expect(handlerContent).toContain(
|
|
354
|
+
"from '../src/api/endpoints/deepEndpoint.js'",
|
|
355
|
+
);
|
|
356
|
+
expect(handlerContent).toMatch(/from ['"]\.\.\/\.\.\/\.\.\/.*\/env['"]/);
|
|
357
|
+
},
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
itWithDir('should log generation progress', async ({ dir }) => {
|
|
361
|
+
const logSpy = vi.spyOn(console, 'log');
|
|
362
|
+
const outputDir = join(dir, 'output');
|
|
363
|
+
const routesDir = join(dir, 'routes');
|
|
364
|
+
await mkdir(outputDir, { recursive: true });
|
|
365
|
+
|
|
366
|
+
await Promise.all([
|
|
367
|
+
createMockEndpointFile(
|
|
368
|
+
routesDir,
|
|
369
|
+
'endpoint1.ts',
|
|
370
|
+
'endpoint1',
|
|
371
|
+
'/test1',
|
|
372
|
+
'GET',
|
|
373
|
+
),
|
|
374
|
+
createMockEndpointFile(
|
|
375
|
+
routesDir,
|
|
376
|
+
'endpoint2.ts',
|
|
377
|
+
'endpoint2',
|
|
378
|
+
'/test2',
|
|
379
|
+
'POST',
|
|
380
|
+
),
|
|
381
|
+
]);
|
|
382
|
+
|
|
383
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
384
|
+
|
|
385
|
+
await generator.build(context, constructs, outputDir, {
|
|
386
|
+
provider: 'server',
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
expect(logSpy).toHaveBeenCalledWith('Generated server with 2 endpoints');
|
|
390
|
+
|
|
391
|
+
logSpy.mockRestore();
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
itWithDir(
|
|
395
|
+
'should generate production app file when production mode is enabled',
|
|
396
|
+
async ({ dir }) => {
|
|
397
|
+
const outputDir = join(dir, 'output');
|
|
398
|
+
const routesDir = join(dir, 'routes');
|
|
399
|
+
await mkdir(outputDir, { recursive: true });
|
|
400
|
+
|
|
401
|
+
await createMockEndpointFile(
|
|
402
|
+
routesDir,
|
|
403
|
+
'testEndpoint.ts',
|
|
404
|
+
'testEndpoint',
|
|
405
|
+
'/test',
|
|
406
|
+
'GET',
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
410
|
+
|
|
411
|
+
const productionContext = {
|
|
412
|
+
...context,
|
|
413
|
+
production: {
|
|
414
|
+
enabled: true,
|
|
415
|
+
healthCheck: '/health',
|
|
416
|
+
gracefulShutdown: true,
|
|
417
|
+
openapi: false,
|
|
418
|
+
subscribers: 'exclude' as const,
|
|
419
|
+
optimizedHandlers: false,
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
await generator.build(productionContext, constructs, outputDir, {
|
|
424
|
+
provider: 'server',
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
const appPath = join(outputDir, 'app.ts');
|
|
428
|
+
const appContent = await readFile(appPath, 'utf-8');
|
|
429
|
+
|
|
430
|
+
expect(appContent).toContain('Generated production server application');
|
|
431
|
+
expect(appContent).toContain("honoApp.get('/health'");
|
|
432
|
+
expect(appContent).toContain("honoApp.get('/ready'");
|
|
433
|
+
expect(appContent).toContain('Graceful shutdown initiated');
|
|
434
|
+
|
|
435
|
+
// Check server.ts entry point was generated
|
|
436
|
+
const serverPath = join(outputDir, 'server.ts');
|
|
437
|
+
const serverContent = await readFile(serverPath, 'utf-8');
|
|
438
|
+
expect(serverContent).toContain('Production server entry point');
|
|
439
|
+
expect(serverContent).toContain(
|
|
440
|
+
"import { serve } from '@hono/node-server'",
|
|
441
|
+
);
|
|
442
|
+
},
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
itWithDir(
|
|
446
|
+
'should generate production app with subscribers when include option is set',
|
|
447
|
+
async ({ dir }) => {
|
|
448
|
+
const outputDir = join(dir, 'output');
|
|
449
|
+
const routesDir = join(dir, 'routes');
|
|
450
|
+
await mkdir(outputDir, { recursive: true });
|
|
451
|
+
|
|
452
|
+
await createMockEndpointFile(
|
|
453
|
+
routesDir,
|
|
454
|
+
'testEndpoint.ts',
|
|
455
|
+
'testEndpoint',
|
|
456
|
+
'/test',
|
|
457
|
+
'GET',
|
|
458
|
+
);
|
|
459
|
+
|
|
460
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
461
|
+
|
|
462
|
+
const productionContext = {
|
|
463
|
+
...context,
|
|
464
|
+
production: {
|
|
465
|
+
enabled: true,
|
|
466
|
+
healthCheck: '/health',
|
|
467
|
+
gracefulShutdown: false,
|
|
468
|
+
openapi: true,
|
|
469
|
+
subscribers: 'include' as const,
|
|
470
|
+
optimizedHandlers: false,
|
|
471
|
+
},
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
await generator.build(productionContext, constructs, outputDir, {
|
|
475
|
+
provider: 'server',
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
const appPath = join(outputDir, 'app.ts');
|
|
479
|
+
const appContent = await readFile(appPath, 'utf-8');
|
|
480
|
+
|
|
481
|
+
expect(appContent).toContain('import { setupSubscribers }');
|
|
482
|
+
expect(appContent).toContain('Start subscribers in background');
|
|
483
|
+
expect(appContent).toContain(
|
|
484
|
+
'setupEndpoints(honoApp, envParser, logger, true)',
|
|
485
|
+
);
|
|
486
|
+
},
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
itWithDir(
|
|
490
|
+
'should log aws-lambda handler generation for each route',
|
|
491
|
+
async ({ dir }) => {
|
|
492
|
+
const logSpy = vi.spyOn(console, 'log');
|
|
493
|
+
const outputDir = join(dir, 'output');
|
|
494
|
+
const routesDir = join(dir, 'routes');
|
|
495
|
+
await mkdir(outputDir, { recursive: true });
|
|
496
|
+
|
|
497
|
+
await createMockEndpointFile(
|
|
498
|
+
routesDir,
|
|
499
|
+
'testEndpoint.ts',
|
|
500
|
+
'testEndpoint',
|
|
501
|
+
'/test',
|
|
502
|
+
'GET',
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
506
|
+
|
|
507
|
+
await generator.build(context, constructs, outputDir, {
|
|
508
|
+
provider: 'aws-lambda',
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
expect(logSpy).toHaveBeenCalledWith('Generated handler for GET /test');
|
|
512
|
+
logSpy.mockRestore();
|
|
513
|
+
},
|
|
514
|
+
);
|
|
515
|
+
|
|
516
|
+
itWithDir(
|
|
517
|
+
'should log apigatewayv2 handler generation for each route',
|
|
518
|
+
async ({ dir }) => {
|
|
519
|
+
const logSpy = vi.spyOn(console, 'log');
|
|
520
|
+
const outputDir = join(dir, 'output');
|
|
521
|
+
const routesDir = join(dir, 'routes');
|
|
522
|
+
await mkdir(outputDir, { recursive: true });
|
|
523
|
+
|
|
524
|
+
await createMockEndpointFile(
|
|
525
|
+
routesDir,
|
|
526
|
+
'testEndpoint.ts',
|
|
527
|
+
'testEndpoint',
|
|
528
|
+
'/api/users',
|
|
529
|
+
'POST',
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
const constructs = await generator.load('**/routes/*.ts', dir);
|
|
533
|
+
|
|
534
|
+
await generator.build(context, constructs, outputDir, {
|
|
535
|
+
provider: 'aws-apigatewayv2',
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
expect(logSpy).toHaveBeenCalledWith(
|
|
539
|
+
'Generated handler for POST /api/users',
|
|
540
|
+
);
|
|
541
|
+
logSpy.mockRestore();
|
|
542
|
+
},
|
|
543
|
+
);
|
|
394
544
|
});
|