@geekmidas/cli 0.10.0 → 0.12.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-DRXCw_YR.mjs +70 -0
- package/dist/bundler-DRXCw_YR.mjs.map +1 -0
- package/dist/bundler-WsEvH_b2.cjs +71 -0
- package/dist/bundler-WsEvH_b2.cjs.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 +2116 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +2134 -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-BUYQJgz7.cjs +4 -0
- package/dist/storage-BXoJvmv2.cjs +149 -0
- package/dist/storage-BXoJvmv2.cjs.map +1 -0
- package/dist/storage-C9PU_30f.mjs +101 -0
- package/dist/storage-C9PU_30f.mjs.map +1 -0
- package/dist/storage-DLJAYxzJ.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__/index-new.spec.ts +474 -474
- package/src/build/__tests__/manifests.spec.ts +333 -333
- package/src/build/bundler.ts +141 -0
- package/src/build/endpoint-analyzer.ts +236 -0
- package/src/build/handler-templates.ts +1253 -0
- package/src/build/index.ts +250 -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 +403 -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 +134 -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
|
@@ -6,501 +6,501 @@ import { generateReactQueryCommand } from '../openapi-react-query';
|
|
|
6
6
|
import { cleanupDir, createTempDir, createTestFile } from './test-helpers';
|
|
7
7
|
|
|
8
8
|
describe('React Query Generation', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
9
|
+
let tempDir: string;
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
tempDir = await createTempDir('react-query-test-');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
afterEach(async () => {
|
|
16
|
+
await cleanupDir(tempDir);
|
|
17
|
+
vi.restoreAllMocks();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe('generateReactQueryCommand', () => {
|
|
21
|
+
it('should generate React Query hooks from OpenAPI spec', async () => {
|
|
22
|
+
// Create mock OpenAPI spec
|
|
23
|
+
const spec = {
|
|
24
|
+
openapi: '3.0.0',
|
|
25
|
+
info: {
|
|
26
|
+
title: 'Test API',
|
|
27
|
+
version: '1.0.0',
|
|
28
|
+
},
|
|
29
|
+
paths: {
|
|
30
|
+
'/users': {
|
|
31
|
+
get: {
|
|
32
|
+
operationId: 'getUsers',
|
|
33
|
+
responses: {
|
|
34
|
+
'200': {
|
|
35
|
+
description: 'Success',
|
|
36
|
+
content: {
|
|
37
|
+
'application/json': {
|
|
38
|
+
schema: {
|
|
39
|
+
type: 'array',
|
|
40
|
+
items: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: {
|
|
43
|
+
id: { type: 'string' },
|
|
44
|
+
name: { type: 'string' },
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
post: {
|
|
54
|
+
operationId: 'createUser',
|
|
55
|
+
requestBody: {
|
|
56
|
+
content: {
|
|
57
|
+
'application/json': {
|
|
58
|
+
schema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
name: { type: 'string' },
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
responses: {
|
|
68
|
+
'201': {
|
|
69
|
+
description: 'Created',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
78
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
79
|
+
|
|
80
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
81
|
+
|
|
82
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
83
|
+
|
|
84
|
+
await generateReactQueryCommand({
|
|
85
|
+
input: inputPath,
|
|
86
|
+
output: outputPath,
|
|
87
|
+
name: 'TestAPI',
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Verify hooks file was created
|
|
91
|
+
expect(existsSync(outputPath)).toBe(true);
|
|
92
|
+
|
|
93
|
+
// Verify content
|
|
94
|
+
const content = await readFile(outputPath, 'utf-8');
|
|
95
|
+
|
|
96
|
+
expect(content).toContain('createTypedQueryClient');
|
|
97
|
+
expect(content).toContain('testapi');
|
|
98
|
+
expect(content).toContain('useGetUsers');
|
|
99
|
+
expect(content).toContain('useCreateUser');
|
|
100
|
+
expect(content).toContain('export');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should throw error when OpenAPI spec not found', async () => {
|
|
104
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
105
|
+
|
|
106
|
+
await expect(
|
|
107
|
+
generateReactQueryCommand({
|
|
108
|
+
input: join(tempDir, 'nonexistent.json'),
|
|
109
|
+
}),
|
|
110
|
+
).rejects.toThrow(/OpenAPI spec not found/);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should use default input and output paths', async () => {
|
|
114
|
+
// Create spec in default location
|
|
115
|
+
const spec = {
|
|
116
|
+
openapi: '3.0.0',
|
|
117
|
+
info: { title: 'API', version: '1.0.0' },
|
|
118
|
+
paths: {
|
|
119
|
+
'/test': {
|
|
120
|
+
get: {
|
|
121
|
+
operationId: 'test',
|
|
122
|
+
responses: { '200': { description: 'OK' } },
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
129
|
+
|
|
130
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
131
|
+
|
|
132
|
+
await generateReactQueryCommand();
|
|
133
|
+
|
|
134
|
+
// Should create in default location
|
|
135
|
+
const defaultPath = join(tempDir, 'src', 'api', 'hooks.ts');
|
|
136
|
+
expect(existsSync(defaultPath)).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should generate query hooks for GET requests', async () => {
|
|
140
|
+
const spec = {
|
|
141
|
+
openapi: '3.0.0',
|
|
142
|
+
info: { title: 'API', version: '1.0.0' },
|
|
143
|
+
paths: {
|
|
144
|
+
'/users': {
|
|
145
|
+
get: {
|
|
146
|
+
operationId: 'listUsers',
|
|
147
|
+
responses: { '200': { description: 'Success' } },
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
'/users/{id}': {
|
|
151
|
+
get: {
|
|
152
|
+
operationId: 'getUser',
|
|
153
|
+
parameters: [
|
|
154
|
+
{
|
|
155
|
+
name: 'id',
|
|
156
|
+
in: 'path',
|
|
157
|
+
required: true,
|
|
158
|
+
schema: { type: 'string' },
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
responses: { '200': { description: 'Success' } },
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
168
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
169
|
+
|
|
170
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
171
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
172
|
+
|
|
173
|
+
await generateReactQueryCommand({
|
|
174
|
+
input: inputPath,
|
|
175
|
+
output: outputPath,
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
const content = await readFile(outputPath, 'utf-8');
|
|
179
|
+
|
|
180
|
+
expect(content).toContain('useListUsers');
|
|
181
|
+
expect(content).toContain('useGetUser');
|
|
182
|
+
expect(content).toContain('Query Hooks');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should generate mutation hooks for non-GET requests', async () => {
|
|
186
|
+
const spec = {
|
|
187
|
+
openapi: '3.0.0',
|
|
188
|
+
info: { title: 'API', version: '1.0.0' },
|
|
189
|
+
paths: {
|
|
190
|
+
'/users': {
|
|
191
|
+
post: {
|
|
192
|
+
operationId: 'createUser',
|
|
193
|
+
responses: { '201': { description: 'Created' } },
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
'/users/{id}': {
|
|
197
|
+
put: {
|
|
198
|
+
operationId: 'updateUser',
|
|
199
|
+
responses: { '200': { description: 'Updated' } },
|
|
200
|
+
},
|
|
201
|
+
delete: {
|
|
202
|
+
operationId: 'deleteUser',
|
|
203
|
+
responses: { '204': { description: 'Deleted' } },
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
210
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
211
|
+
|
|
212
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
213
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
214
|
+
|
|
215
|
+
await generateReactQueryCommand({
|
|
216
|
+
input: inputPath,
|
|
217
|
+
output: outputPath,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const content = await readFile(outputPath, 'utf-8');
|
|
221
|
+
|
|
222
|
+
expect(content).toContain('useCreateUser');
|
|
223
|
+
expect(content).toContain('useUpdateUser');
|
|
224
|
+
expect(content).toContain('useDeleteUser');
|
|
225
|
+
expect(content).toContain('Mutation Hooks');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('should create output directory if it does not exist', async () => {
|
|
229
|
+
const spec = {
|
|
230
|
+
openapi: '3.0.0',
|
|
231
|
+
info: { title: 'API', version: '1.0.0' },
|
|
232
|
+
paths: {
|
|
233
|
+
'/test': {
|
|
234
|
+
get: {
|
|
235
|
+
operationId: 'test',
|
|
236
|
+
responses: { '200': { description: 'OK' } },
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
243
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
244
|
+
|
|
245
|
+
const outputPath = join(tempDir, 'nested', 'dir', 'hooks.ts');
|
|
246
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
247
|
+
|
|
248
|
+
await generateReactQueryCommand({
|
|
249
|
+
input: inputPath,
|
|
250
|
+
output: outputPath,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
expect(existsSync(outputPath)).toBe(true);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('should generate TypeScript types file', async () => {
|
|
257
|
+
const spec = {
|
|
258
|
+
openapi: '3.0.0',
|
|
259
|
+
info: { title: 'API', version: '1.0.0' },
|
|
260
|
+
paths: {
|
|
261
|
+
'/test': {
|
|
262
|
+
get: {
|
|
263
|
+
operationId: 'test',
|
|
264
|
+
responses: { '200': { description: 'OK' } },
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
271
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
272
|
+
|
|
273
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
274
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
275
|
+
|
|
276
|
+
await generateReactQueryCommand({
|
|
277
|
+
input: inputPath,
|
|
278
|
+
output: outputPath,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// Should generate openapi-types.d.ts
|
|
282
|
+
const typesPath = join(tempDir, 'openapi-types.d.ts');
|
|
283
|
+
expect(existsSync(typesPath)).toBe(true);
|
|
284
|
+
|
|
285
|
+
const typesContent = await readFile(typesPath, 'utf-8');
|
|
286
|
+
expect(typesContent).toContain('export interface paths');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('should handle operations without operationId', async () => {
|
|
290
|
+
const spec = {
|
|
291
|
+
openapi: '3.0.0',
|
|
292
|
+
info: { title: 'API', version: '1.0.0' },
|
|
293
|
+
paths: {
|
|
294
|
+
'/with-id': {
|
|
295
|
+
get: {
|
|
296
|
+
operationId: 'withId',
|
|
297
|
+
responses: { '200': { description: 'OK' } },
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
'/without-id': {
|
|
301
|
+
get: {
|
|
302
|
+
// No operationId
|
|
303
|
+
responses: { '200': { description: 'OK' } },
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
310
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
311
|
+
|
|
312
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
313
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
314
|
+
|
|
315
|
+
await generateReactQueryCommand({
|
|
316
|
+
input: inputPath,
|
|
317
|
+
output: outputPath,
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
const content = await readFile(outputPath, 'utf-8');
|
|
321
|
+
|
|
322
|
+
// Should only generate hook for operation with ID
|
|
323
|
+
expect(content).toContain('useWithId');
|
|
324
|
+
expect(content).not.toContain('useWithoutId');
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('should log generation progress', async () => {
|
|
328
|
+
const spec = {
|
|
329
|
+
openapi: '3.0.0',
|
|
330
|
+
info: { title: 'API', version: '1.0.0' },
|
|
331
|
+
paths: {
|
|
332
|
+
'/test': {
|
|
333
|
+
get: {
|
|
334
|
+
operationId: 'test',
|
|
335
|
+
responses: { '200': { description: 'OK' } },
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
342
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
343
|
+
|
|
344
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
345
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
346
|
+
const consoleSpy = vi.spyOn(console, 'log');
|
|
347
|
+
|
|
348
|
+
await generateReactQueryCommand({
|
|
349
|
+
input: inputPath,
|
|
350
|
+
output: outputPath,
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
354
|
+
expect.stringContaining('Generating TypeScript types'),
|
|
355
|
+
);
|
|
356
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
357
|
+
expect.stringContaining('React Query hooks generated'),
|
|
358
|
+
);
|
|
359
|
+
expect(consoleSpy).toHaveBeenCalledWith(
|
|
360
|
+
expect.stringContaining('Generated'),
|
|
361
|
+
);
|
|
362
|
+
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('hooks'));
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('should handle invalid JSON in OpenAPI spec', async () => {
|
|
366
|
+
const inputPath = join(tempDir, 'invalid.json');
|
|
367
|
+
await createTestFile(tempDir, 'invalid.json', 'not valid json {[}]');
|
|
368
|
+
|
|
369
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
370
|
+
|
|
371
|
+
await expect(
|
|
372
|
+
generateReactQueryCommand({ input: inputPath }),
|
|
373
|
+
).rejects.toThrow(/React Query generation failed/);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it('should use custom API name', async () => {
|
|
377
|
+
const spec = {
|
|
378
|
+
openapi: '3.0.0',
|
|
379
|
+
info: { title: 'API', version: '1.0.0' },
|
|
380
|
+
paths: {
|
|
381
|
+
'/test': {
|
|
382
|
+
get: {
|
|
383
|
+
operationId: 'test',
|
|
384
|
+
responses: { '200': { description: 'OK' } },
|
|
385
|
+
},
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
391
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
392
|
+
|
|
393
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
394
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
395
|
+
|
|
396
|
+
await generateReactQueryCommand({
|
|
397
|
+
input: inputPath,
|
|
398
|
+
output: outputPath,
|
|
399
|
+
name: 'MyCustomAPI',
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
const content = await readFile(outputPath, 'utf-8');
|
|
403
|
+
|
|
404
|
+
expect(content).toContain('mycustomapi');
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it('should generate hooks with parameters', async () => {
|
|
408
|
+
const spec = {
|
|
409
|
+
openapi: '3.0.0',
|
|
410
|
+
info: { title: 'API', version: '1.0.0' },
|
|
411
|
+
paths: {
|
|
412
|
+
'/users/{userId}/posts/{postId}': {
|
|
413
|
+
get: {
|
|
414
|
+
operationId: 'getUserPost',
|
|
415
|
+
parameters: [
|
|
416
|
+
{ name: 'userId', in: 'path', required: true },
|
|
417
|
+
{ name: 'postId', in: 'path', required: true },
|
|
418
|
+
{ name: 'include', in: 'query' },
|
|
419
|
+
],
|
|
420
|
+
responses: { '200': { description: 'OK' } },
|
|
421
|
+
},
|
|
422
|
+
},
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
427
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
428
|
+
|
|
429
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
430
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
431
|
+
|
|
432
|
+
await generateReactQueryCommand({
|
|
433
|
+
input: inputPath,
|
|
434
|
+
output: outputPath,
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
const content = await readFile(outputPath, 'utf-8');
|
|
438
|
+
|
|
439
|
+
expect(content).toContain('useGetUserPost');
|
|
440
|
+
// Should generate hook with params
|
|
441
|
+
expect(content).toContain('config');
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it('should generate type exports', async () => {
|
|
445
|
+
const spec = {
|
|
446
|
+
openapi: '3.0.0',
|
|
447
|
+
info: { title: 'API', version: '1.0.0' },
|
|
448
|
+
paths: {
|
|
449
|
+
'/users': {
|
|
450
|
+
get: {
|
|
451
|
+
operationId: 'getUsers',
|
|
452
|
+
responses: { '200': { description: 'OK' } },
|
|
453
|
+
},
|
|
454
|
+
post: {
|
|
455
|
+
operationId: 'createUser',
|
|
456
|
+
responses: { '201': { description: 'Created' } },
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
463
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
464
|
+
|
|
465
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
466
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
467
|
+
|
|
468
|
+
await generateReactQueryCommand({
|
|
469
|
+
input: inputPath,
|
|
470
|
+
output: outputPath,
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
const content = await readFile(outputPath, 'utf-8');
|
|
474
|
+
|
|
475
|
+
expect(content).toContain('Type exports for convenience');
|
|
476
|
+
expect(content).toContain('GetUsersResponse');
|
|
477
|
+
expect(content).toContain('CreateUserResponse');
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it('should handle spec with no paths', async () => {
|
|
481
|
+
const spec = {
|
|
482
|
+
openapi: '3.0.0',
|
|
483
|
+
info: { title: 'API', version: '1.0.0' },
|
|
484
|
+
paths: {},
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
const inputPath = join(tempDir, 'openapi.json');
|
|
488
|
+
await createTestFile(tempDir, 'openapi.json', JSON.stringify(spec));
|
|
489
|
+
|
|
490
|
+
const outputPath = join(tempDir, 'hooks.ts');
|
|
491
|
+
vi.spyOn(process, 'cwd').mockReturnValue(tempDir);
|
|
492
|
+
|
|
493
|
+
await generateReactQueryCommand({
|
|
494
|
+
input: inputPath,
|
|
495
|
+
output: outputPath,
|
|
496
|
+
});
|
|
497
|
+
|
|
498
|
+
const content = await readFile(outputPath, 'utf-8');
|
|
499
|
+
|
|
500
|
+
// Should still generate base structure
|
|
501
|
+
expect(content).toContain('createTypedQueryClient');
|
|
502
|
+
expect(content).toContain('Query Hooks');
|
|
503
|
+
expect(content).toContain('Mutation Hooks');
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
506
|
});
|