typedapi-client-helpers 0.1.14 → 0.1.16
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/dist/index.cjs +19 -5
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -5
- package/package.json +26 -1
- package/scripts/generate-api-minimal.mjs +1103 -959
|
@@ -1,959 +1,1103 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
|
-
import { generateApi } from "swagger-typescript-api";
|
|
5
|
-
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = path.dirname(__filename);
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
...(
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
process.env.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
process.env.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
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
|
-
process.env.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
process.env.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
function
|
|
112
|
-
return
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
fs.
|
|
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
|
-
if (
|
|
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
|
-
function
|
|
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
|
-
const
|
|
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
|
-
if (
|
|
360
|
-
return
|
|
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
|
-
if (
|
|
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
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
);
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
)
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
)
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
)
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
ExtractResponse<
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
${
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
]
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
${
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
${
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
})
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { generateApi } from "swagger-typescript-api";
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
const packageRoot = path.resolve(__dirname, "..");
|
|
10
|
+
const runtimePackageJsonPath = path.join(packageRoot, "package.json");
|
|
11
|
+
const runtimePackageJson = JSON.parse(
|
|
12
|
+
fs.readFileSync(runtimePackageJsonPath, "utf8"),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const consumerPackageJsonPath = path.resolve(process.cwd(), "package.json");
|
|
16
|
+
const consumerPackageJson = fs.existsSync(consumerPackageJsonPath)
|
|
17
|
+
? JSON.parse(fs.readFileSync(consumerPackageJsonPath, "utf8"))
|
|
18
|
+
: {};
|
|
19
|
+
|
|
20
|
+
const isRunningInsidePackage =
|
|
21
|
+
path.resolve(process.cwd()) === path.resolve(__dirname, "..");
|
|
22
|
+
|
|
23
|
+
const runtimePackageName = isRunningInsidePackage
|
|
24
|
+
? "../.."
|
|
25
|
+
: runtimePackageJson.name;
|
|
26
|
+
|
|
27
|
+
const cwd = process.cwd();
|
|
28
|
+
|
|
29
|
+
const config = {
|
|
30
|
+
...(runtimePackageJson.config ?? {}),
|
|
31
|
+
...(consumerPackageJson.config ?? {}),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const swaggerFile =
|
|
35
|
+
process.env.SWAGGER_FILE ??
|
|
36
|
+
process.env.npm_config_swagger_file ??
|
|
37
|
+
config.swaggerFile;
|
|
38
|
+
|
|
39
|
+
const swaggerUrl =
|
|
40
|
+
process.env.SWAGGER_URL ??
|
|
41
|
+
process.env.npm_config_swagger_url ??
|
|
42
|
+
config.swaggerUrl;
|
|
43
|
+
|
|
44
|
+
const defaultSwaggerUrl = "https://localhost:7000/swagger/v1/swagger.json";
|
|
45
|
+
|
|
46
|
+
const swaggerBackupFileSetting = getStringSetting(
|
|
47
|
+
process.env.TYPED_API_SWAGGER_BACKUP_FILE,
|
|
48
|
+
process.env.npm_config_typed_api_swagger_backup_file,
|
|
49
|
+
config.typedApiSwaggerBackupFile,
|
|
50
|
+
"swagger/swagger.backup.json",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const swaggerBackupPath = path.resolve(packageRoot, swaggerBackupFileSetting);
|
|
54
|
+
|
|
55
|
+
const apiRoot = path.resolve(
|
|
56
|
+
cwd,
|
|
57
|
+
process.env.API_OUTPUT ??
|
|
58
|
+
process.env.npm_config_api_output ??
|
|
59
|
+
config.apiOutput ??
|
|
60
|
+
"src/api",
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const generatedDir = path.join(apiRoot, "generated");
|
|
64
|
+
const methodsDir = path.join(apiRoot, "methods");
|
|
65
|
+
|
|
66
|
+
const useTypeOnlyImports =
|
|
67
|
+
process.env.TYPED_API_USE_TYPE_ONLY_IMPORTS === "true" ||
|
|
68
|
+
process.env.npm_config_typed_api_use_type_only_imports === "true" ||
|
|
69
|
+
config.typedApiUseTypeOnlyImports === true;
|
|
70
|
+
|
|
71
|
+
const useFilterFormValues =
|
|
72
|
+
process.env.TYPED_API_USE_FILTER_FORM_VALUES === "true" ||
|
|
73
|
+
process.env.npm_config_typed_api_use_filter_form_values === "true" ||
|
|
74
|
+
config.typedApiUseFilterFormValues === true;
|
|
75
|
+
|
|
76
|
+
function getStringSetting(...values) {
|
|
77
|
+
for (const value of values) {
|
|
78
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
79
|
+
return value.trim();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const fallbackDefaultFunctionsPath = "defaultApiFunctions";
|
|
87
|
+
|
|
88
|
+
const defaultFunctionsPathSetting = getStringSetting(
|
|
89
|
+
process.env.TYPED_API_DEFAULT_FUNCTIONS_PATH,
|
|
90
|
+
process.env.npm_config_typed_api_default_functions_path,
|
|
91
|
+
config.typedApiDefaultFunctionsPath,
|
|
92
|
+
fallbackDefaultFunctionsPath,
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const defaultFunctionsFilePath = path.resolve(cwd, defaultFunctionsPathSetting);
|
|
96
|
+
|
|
97
|
+
const defaultSuccessHandlerName = getStringSetting(
|
|
98
|
+
process.env.TYPED_API_DEFAULT_SUCCESS_HANDLER,
|
|
99
|
+
process.env.npm_config_typed_api_default_success_handler,
|
|
100
|
+
config.typedApiDefaultSuccessHandler,
|
|
101
|
+
"handleGoodResult",
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const defaultErrorHandlerName = getStringSetting(
|
|
105
|
+
process.env.TYPED_API_DEFAULT_ERROR_HANDLER,
|
|
106
|
+
process.env.npm_config_typed_api_default_error_handler,
|
|
107
|
+
config.typedApiDefaultErrorHandler,
|
|
108
|
+
"handleErrors",
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
function pascalCase(value) {
|
|
112
|
+
return value
|
|
113
|
+
.split(/[-_]/)
|
|
114
|
+
.filter(Boolean)
|
|
115
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
116
|
+
.join("");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function toQueryName(methodName) {
|
|
120
|
+
return `${pascalCase(methodName)}Query`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function cleanDirectory(directory) {
|
|
124
|
+
if (fs.existsSync(directory)) {
|
|
125
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
function fileExists(filePath) {
|
|
133
|
+
try {
|
|
134
|
+
return fs.existsSync(filePath) && fs.statSync(filePath).isFile();
|
|
135
|
+
} catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function writeSwaggerBackup(content, sourceLabel) {
|
|
141
|
+
fs.mkdirSync(path.dirname(swaggerBackupPath), { recursive: true });
|
|
142
|
+
fs.writeFileSync(swaggerBackupPath, content);
|
|
143
|
+
|
|
144
|
+
console.log(
|
|
145
|
+
`Updated Swagger backup from ${sourceLabel}: ${path.relative(packageRoot, swaggerBackupPath)}`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function copySwaggerBackupFromFile(filePath) {
|
|
150
|
+
const content = fs.readFileSync(filePath, "utf8");
|
|
151
|
+
|
|
152
|
+
// Validate that the backup is at least JSON. This prevents overwriting a good
|
|
153
|
+
// backup with an invalid or empty file by accident.
|
|
154
|
+
JSON.parse(content);
|
|
155
|
+
|
|
156
|
+
writeSwaggerBackup(content, path.relative(cwd, filePath));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function downloadSwaggerBackupFromUrl(url) {
|
|
160
|
+
const response = await fetch(url);
|
|
161
|
+
|
|
162
|
+
if (!response.ok) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
`Swagger URL returned ${response.status} ${response.statusText}: ${url}`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const content = await response.text();
|
|
169
|
+
|
|
170
|
+
// Validate before saving, so a server error page is never stored as backup.
|
|
171
|
+
JSON.parse(content);
|
|
172
|
+
|
|
173
|
+
writeSwaggerBackup(content, url);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function useBackupSwaggerInput(reason) {
|
|
177
|
+
if (!fileExists(swaggerBackupPath)) {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
console.warn(
|
|
182
|
+
`${reason} Using Swagger backup: ${path.relative(packageRoot, swaggerBackupPath)}`,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
input: swaggerBackupPath,
|
|
187
|
+
label: swaggerBackupPath,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function resolveSwaggerInput() {
|
|
192
|
+
if (swaggerFile) {
|
|
193
|
+
const swaggerFilePath = path.resolve(cwd, swaggerFile);
|
|
194
|
+
|
|
195
|
+
if (fileExists(swaggerFilePath)) {
|
|
196
|
+
copySwaggerBackupFromFile(swaggerFilePath);
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
input: swaggerFilePath,
|
|
200
|
+
label: swaggerFilePath,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const backupInput = useBackupSwaggerInput(
|
|
205
|
+
`Swagger file was not found: ${swaggerFilePath}.`,
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
if (backupInput) {
|
|
209
|
+
return backupInput;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
throw new Error(
|
|
213
|
+
`Swagger file was not found and no backup exists: ${swaggerFilePath}`,
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (swaggerUrl) {
|
|
218
|
+
try {
|
|
219
|
+
await downloadSwaggerBackupFromUrl(swaggerUrl);
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
input: swaggerBackupPath,
|
|
223
|
+
label: swaggerUrl,
|
|
224
|
+
};
|
|
225
|
+
} catch (error) {
|
|
226
|
+
const backupInput = useBackupSwaggerInput(
|
|
227
|
+
`Swagger URL is not available: ${swaggerUrl}.`,
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
if (backupInput) {
|
|
231
|
+
return backupInput;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
throw error;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const defaultSwaggerFile = path.resolve(cwd, "swagger/swagger.json");
|
|
239
|
+
|
|
240
|
+
if (fileExists(defaultSwaggerFile)) {
|
|
241
|
+
copySwaggerBackupFromFile(defaultSwaggerFile);
|
|
242
|
+
|
|
243
|
+
return {
|
|
244
|
+
input: defaultSwaggerFile,
|
|
245
|
+
label: defaultSwaggerFile,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
try {
|
|
250
|
+
await downloadSwaggerBackupFromUrl(defaultSwaggerUrl);
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
input: swaggerBackupPath,
|
|
254
|
+
label: defaultSwaggerUrl,
|
|
255
|
+
};
|
|
256
|
+
} catch (error) {
|
|
257
|
+
const backupInput = useBackupSwaggerInput(
|
|
258
|
+
`Default Swagger file was not found and default Swagger URL is not available.`,
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
if (backupInput) {
|
|
262
|
+
return backupInput;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async function writeFormattedFile(filePath, content) {
|
|
270
|
+
fs.writeFileSync(filePath, content);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function removeGeneratedRouteFiles() {
|
|
274
|
+
const files = fs.readdirSync(generatedDir);
|
|
275
|
+
|
|
276
|
+
for (const file of files) {
|
|
277
|
+
if (/route\.ts$/i.test(file)) {
|
|
278
|
+
fs.rmSync(path.join(generatedDir, file), { force: true });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function generateOpenApiClient(swaggerInput) {
|
|
284
|
+
cleanDirectory(generatedDir);
|
|
285
|
+
cleanDirectory(methodsDir);
|
|
286
|
+
fs.mkdirSync(methodsDir, { recursive: true });
|
|
287
|
+
|
|
288
|
+
const generateOptions = {
|
|
289
|
+
name: "Api.ts",
|
|
290
|
+
output: generatedDir,
|
|
291
|
+
httpClientType: "fetch",
|
|
292
|
+
modular: true,
|
|
293
|
+
cleanOutput: true,
|
|
294
|
+
generateClient: true,
|
|
295
|
+
generateRouteTypes: true,
|
|
296
|
+
extractRequestParams: true,
|
|
297
|
+
extractRequestBody: true,
|
|
298
|
+
moduleNameFirstTag: true,
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
generateOptions.input = swaggerInput;
|
|
302
|
+
|
|
303
|
+
await generateApi(generateOptions);
|
|
304
|
+
|
|
305
|
+
removeGeneratedRouteFiles();
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function createImportStatement({ names, from, typeOnly = false }) {
|
|
309
|
+
if (!names || names.length === 0) {
|
|
310
|
+
return "";
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const importKeyword = typeOnly ? "import type" : "import";
|
|
314
|
+
|
|
315
|
+
return `${importKeyword} {
|
|
316
|
+
${names.map((name) => ` ${name},`).join("\n")}
|
|
317
|
+
} from "${from}";`;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function createAliasedImportStatement({ imports, from }) {
|
|
321
|
+
if (!imports || imports.length === 0) {
|
|
322
|
+
return "";
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return `import {
|
|
326
|
+
${imports
|
|
327
|
+
.map(({ name, alias }) =>
|
|
328
|
+
alias && alias !== name ? ` ${name} as ${alias},` : ` ${name},`,
|
|
329
|
+
)
|
|
330
|
+
.join("\n")}
|
|
331
|
+
} from "${from}";`;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function resolveImportFilePath(fromDirectory, importPath) {
|
|
335
|
+
if (!importPath.startsWith(".")) {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const basePath = path.resolve(fromDirectory, importPath);
|
|
340
|
+
const candidates = [
|
|
341
|
+
basePath,
|
|
342
|
+
`${basePath}.ts`,
|
|
343
|
+
`${basePath}.tsx`,
|
|
344
|
+
`${basePath}.js`,
|
|
345
|
+
`${basePath}.jsx`,
|
|
346
|
+
path.join(basePath, "index.ts"),
|
|
347
|
+
path.join(basePath, "index.tsx"),
|
|
348
|
+
path.join(basePath, "index.js"),
|
|
349
|
+
path.join(basePath, "index.jsx"),
|
|
350
|
+
];
|
|
351
|
+
|
|
352
|
+
return candidates.find((candidate) => fs.existsSync(candidate));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function createDefaultFunctionsFileIfMissing(filePath) {
|
|
356
|
+
const extension = path.extname(filePath);
|
|
357
|
+
const resolvedFilePath = extension ? filePath : `${filePath}.ts`;
|
|
358
|
+
|
|
359
|
+
if (fs.existsSync(resolvedFilePath)) {
|
|
360
|
+
return resolvedFilePath;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
fs.mkdirSync(path.dirname(resolvedFilePath), { recursive: true });
|
|
364
|
+
|
|
365
|
+
fs.writeFileSync(
|
|
366
|
+
resolvedFilePath,
|
|
367
|
+
`
|
|
368
|
+
${createImportStatement({
|
|
369
|
+
names: ["ApiErrorResult", "ApiSuccessResult"],
|
|
370
|
+
from: "typedapi-client-helpers",
|
|
371
|
+
typeOnly: true,
|
|
372
|
+
})}
|
|
373
|
+
|
|
374
|
+
export function ${defaultSuccessHandlerName}<T>(
|
|
375
|
+
_response: ApiSuccessResult<T>,
|
|
376
|
+
): void | Promise<void> {
|
|
377
|
+
// Add your default success handling here.
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export function ${defaultErrorHandlerName}<T>(
|
|
381
|
+
_error: ApiErrorResult<T>,
|
|
382
|
+
): void | Promise<void> {
|
|
383
|
+
// Add your default error handling here.
|
|
384
|
+
}
|
|
385
|
+
`,
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
console.log(
|
|
389
|
+
`Created default API handler file: ${path.relative(process.cwd(), resolvedFilePath)}`,
|
|
390
|
+
);
|
|
391
|
+
|
|
392
|
+
return resolvedFilePath;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function toRelativeImportPath(fromDirectory, filePath) {
|
|
396
|
+
let relativePath = path.relative(fromDirectory, filePath);
|
|
397
|
+
|
|
398
|
+
if (!relativePath.startsWith(".")) {
|
|
399
|
+
relativePath = `./${relativePath}`;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
relativePath = relativePath.replaceAll(path.sep, "/");
|
|
403
|
+
|
|
404
|
+
return relativePath.replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function escapeRegExp(value) {
|
|
408
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function fileExportsName(source, exportName) {
|
|
412
|
+
const escapedName = escapeRegExp(exportName);
|
|
413
|
+
|
|
414
|
+
const directExportPattern = new RegExp(
|
|
415
|
+
`export\\s+(?:async\\s+)?(?:function|const|let|var|class)\\s+${escapedName}\\b`,
|
|
416
|
+
"m",
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
if (directExportPattern.test(source)) {
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const namedExportBlocks = source.matchAll(/export\s*\{([\s\S]*?)\}/g);
|
|
424
|
+
|
|
425
|
+
for (const match of namedExportBlocks) {
|
|
426
|
+
const exportedNames = match[1]
|
|
427
|
+
.split(",")
|
|
428
|
+
.map((part) => part.trim())
|
|
429
|
+
.filter(Boolean);
|
|
430
|
+
|
|
431
|
+
if (
|
|
432
|
+
exportedNames.some((part) => {
|
|
433
|
+
const [localName, aliasName] = part
|
|
434
|
+
.split(/\s+as\s+/)
|
|
435
|
+
.map((name) => name.trim());
|
|
436
|
+
|
|
437
|
+
return (
|
|
438
|
+
aliasName === exportName || (!aliasName && localName === exportName)
|
|
439
|
+
);
|
|
440
|
+
})
|
|
441
|
+
) {
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
return false;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
function resolveDefaultHandlers(importFromDirectory) {
|
|
450
|
+
const defaultFunctionsFile =
|
|
451
|
+
resolveImportFilePath(importFromDirectory, defaultFunctionsFilePath) ??
|
|
452
|
+
createDefaultFunctionsFileIfMissing(defaultFunctionsFilePath);
|
|
453
|
+
|
|
454
|
+
const source = fs.readFileSync(defaultFunctionsFile, "utf8");
|
|
455
|
+
const hasSuccessHandler = fileExportsName(source, defaultSuccessHandlerName);
|
|
456
|
+
const hasErrorHandler = fileExportsName(source, defaultErrorHandlerName);
|
|
457
|
+
|
|
458
|
+
if (!hasSuccessHandler || !hasErrorHandler) {
|
|
459
|
+
const missingNames = [
|
|
460
|
+
...(!hasSuccessHandler ? [defaultSuccessHandlerName] : []),
|
|
461
|
+
...(!hasErrorHandler ? [defaultErrorHandlerName] : []),
|
|
462
|
+
];
|
|
463
|
+
|
|
464
|
+
console.warn(
|
|
465
|
+
`Default API handlers were not imported because ${path.relative(
|
|
466
|
+
process.cwd(),
|
|
467
|
+
defaultFunctionsFile,
|
|
468
|
+
)} does not export: ${missingNames.join(", ")}.`,
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
return undefined;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
return {
|
|
475
|
+
defaultFunctionsPath: toRelativeImportPath(
|
|
476
|
+
importFromDirectory,
|
|
477
|
+
defaultFunctionsFile,
|
|
478
|
+
),
|
|
479
|
+
defaultSuccessHandlerName,
|
|
480
|
+
defaultErrorHandlerName,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function callbackOptionsExpression(defaultHandlers) {
|
|
485
|
+
if (defaultHandlers) {
|
|
486
|
+
return `{
|
|
487
|
+
onSuccess: onSuccess ?? typedApiDefaultSuccessHandler,
|
|
488
|
+
onError: onError ?? typedApiDefaultErrorHandler
|
|
489
|
+
}`;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
return `{
|
|
493
|
+
onSuccess,
|
|
494
|
+
onError
|
|
495
|
+
}`;
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function getAllTsFiles(dir) {
|
|
499
|
+
let results = [];
|
|
500
|
+
|
|
501
|
+
if (!fs.existsSync(dir)) {
|
|
502
|
+
return results;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const list = fs.readdirSync(dir);
|
|
506
|
+
|
|
507
|
+
for (const file of list) {
|
|
508
|
+
const filePath = path.join(dir, file);
|
|
509
|
+
const stat = fs.statSync(filePath);
|
|
510
|
+
|
|
511
|
+
if (stat.isDirectory()) {
|
|
512
|
+
results = results.concat(getAllTsFiles(filePath));
|
|
513
|
+
} else if (filePath.endsWith(".ts")) {
|
|
514
|
+
results.push(filePath);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
return results;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function getGeneratedMethods(source) {
|
|
522
|
+
const methodRegex = /^\s*(\w+)\s*=\s*\(/gm;
|
|
523
|
+
const matches = [...source.matchAll(methodRegex)];
|
|
524
|
+
|
|
525
|
+
return matches.map((match, index) => {
|
|
526
|
+
const methodName = match[1];
|
|
527
|
+
const startIndex = match.index ?? 0;
|
|
528
|
+
const endIndex =
|
|
529
|
+
index + 1 < matches.length ? matches[index + 1].index : source.length;
|
|
530
|
+
|
|
531
|
+
const methodSource = source.slice(startIndex, endIndex);
|
|
532
|
+
|
|
533
|
+
return {
|
|
534
|
+
methodName,
|
|
535
|
+
methodSource,
|
|
536
|
+
isFormData: methodSource.includes("type: ContentType.FormData"),
|
|
537
|
+
};
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function splitTopLevelArguments(value) {
|
|
542
|
+
const args = [];
|
|
543
|
+
let current = "";
|
|
544
|
+
let depth = 0;
|
|
545
|
+
let quote = "";
|
|
546
|
+
|
|
547
|
+
for (let index = 0; index < value.length; index++) {
|
|
548
|
+
const char = value[index];
|
|
549
|
+
const previousChar = value[index - 1];
|
|
550
|
+
|
|
551
|
+
if (quote) {
|
|
552
|
+
current += char;
|
|
553
|
+
|
|
554
|
+
if (char === quote && previousChar !== "\\") {
|
|
555
|
+
quote = "";
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
continue;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (char === '"' || char === "'" || char === "`") {
|
|
562
|
+
quote = char;
|
|
563
|
+
current += char;
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (char === "(" || char === "{" || char === "[" || char === "<") {
|
|
568
|
+
depth++;
|
|
569
|
+
current += char;
|
|
570
|
+
continue;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (char === ")" || char === "}" || char === "]" || char === ">") {
|
|
574
|
+
depth--;
|
|
575
|
+
current += char;
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (char === "," && depth === 0) {
|
|
580
|
+
if (current.trim()) {
|
|
581
|
+
args.push(current.trim());
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
current = "";
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
current += char;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if (current.trim()) {
|
|
592
|
+
args.push(current.trim());
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
return args;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function getGeneratedMethodArgumentCount(signatureParams) {
|
|
599
|
+
const args = splitTopLevelArguments(signatureParams);
|
|
600
|
+
|
|
601
|
+
if (args.length === 0) {
|
|
602
|
+
return 0;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const lastArg = args[args.length - 1];
|
|
606
|
+
|
|
607
|
+
if (/\bparams\s*:\s*RequestParams\b/.test(lastArg)) {
|
|
608
|
+
return args.length - 1;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
return args.length;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
async function createMethodFiles() {
|
|
615
|
+
const defaultHandlers = resolveDefaultHandlers(methodsDir);
|
|
616
|
+
|
|
617
|
+
const generatedFiles = fs
|
|
618
|
+
.readdirSync(generatedDir)
|
|
619
|
+
.filter(
|
|
620
|
+
(file) =>
|
|
621
|
+
file.endsWith(".ts") &&
|
|
622
|
+
file !== "http-client.ts" &&
|
|
623
|
+
file !== "data-contracts.ts" &&
|
|
624
|
+
!/route\.ts$/i.test(file) &&
|
|
625
|
+
!file.includes(".api"),
|
|
626
|
+
);
|
|
627
|
+
|
|
628
|
+
const methodExports = [];
|
|
629
|
+
|
|
630
|
+
for (const file of generatedFiles) {
|
|
631
|
+
const filePath = path.join(generatedDir, file);
|
|
632
|
+
const source = fs.readFileSync(filePath, "utf8");
|
|
633
|
+
|
|
634
|
+
const baseName = file.replace(".ts", "");
|
|
635
|
+
const className = baseName.split("-").map(pascalCase).join("");
|
|
636
|
+
|
|
637
|
+
const instanceName = `${className.charAt(0).toLowerCase()}${className.slice(1)}Api`;
|
|
638
|
+
|
|
639
|
+
const paginatedMethods = [];
|
|
640
|
+
const simpleQueryMethods = [];
|
|
641
|
+
const nonQueryMethods = [];
|
|
642
|
+
|
|
643
|
+
const generatedMethods = getGeneratedMethods(source);
|
|
644
|
+
|
|
645
|
+
for (const generatedMethod of generatedMethods) {
|
|
646
|
+
const { methodName, methodSource, isFormData } = generatedMethod;
|
|
647
|
+
|
|
648
|
+
const signatureRegex = new RegExp(
|
|
649
|
+
`${methodName}\\s*=\\s*\\(([^)]*)\\)\\s*=>`,
|
|
650
|
+
"m",
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
const signatureMatch = methodSource.match(signatureRegex);
|
|
654
|
+
|
|
655
|
+
if (!signatureMatch) {
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const params = signatureMatch[1].trim();
|
|
660
|
+
const methodArgumentCount = getGeneratedMethodArgumentCount(params);
|
|
661
|
+
|
|
662
|
+
const returnTypeMatch = methodSource.match(/this\.request<([^,>]+)/m);
|
|
663
|
+
const returnType = returnTypeMatch?.[1] ?? "";
|
|
664
|
+
|
|
665
|
+
const isPaginated =
|
|
666
|
+
returnType.includes("ApiPaginationResponse") ||
|
|
667
|
+
returnType.trim().endsWith("[]");
|
|
668
|
+
|
|
669
|
+
if (params.startsWith("query")) {
|
|
670
|
+
if (isPaginated) {
|
|
671
|
+
paginatedMethods.push(methodName);
|
|
672
|
+
} else {
|
|
673
|
+
simpleQueryMethods.push(methodName);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
continue;
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
nonQueryMethods.push({
|
|
680
|
+
methodName,
|
|
681
|
+
isFormData,
|
|
682
|
+
methodArgumentCount,
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const queryTypes = [...paginatedMethods, ...simpleQueryMethods]
|
|
687
|
+
.map((methodName) =>
|
|
688
|
+
`
|
|
689
|
+
export type ${toQueryName(methodName)} =
|
|
690
|
+
NonNullable<
|
|
691
|
+
Parameters<${className}["${methodName}"]>[0]
|
|
692
|
+
>;
|
|
693
|
+
`.trim(),
|
|
694
|
+
)
|
|
695
|
+
.join("\n\n");
|
|
696
|
+
|
|
697
|
+
const hasPaginatedMethods = paginatedMethods.length > 0;
|
|
698
|
+
|
|
699
|
+
const hasFormDataMethods = nonQueryMethods.some(
|
|
700
|
+
({ isFormData }) => isFormData,
|
|
701
|
+
);
|
|
702
|
+
|
|
703
|
+
const hasRegularNonQueryMethods = nonQueryMethods.some(
|
|
704
|
+
({ isFormData }) => !isFormData,
|
|
705
|
+
);
|
|
706
|
+
|
|
707
|
+
const paginatedMethodWrappers = paginatedMethods
|
|
708
|
+
.map((methodName) => {
|
|
709
|
+
if (useFilterFormValues) {
|
|
710
|
+
return `
|
|
711
|
+
export async function ${methodName}(
|
|
712
|
+
filters: FilterFormValues<${toQueryName(methodName)}>[] = [],
|
|
713
|
+
page = 1,
|
|
714
|
+
pageSize = 100,
|
|
715
|
+
sortBy: SortableKeys<
|
|
716
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>
|
|
717
|
+
> | null = null,
|
|
718
|
+
sortDirection?: SortDirection,
|
|
719
|
+
options: ApiMethodOptions<
|
|
720
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
721
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
722
|
+
RequestParams
|
|
723
|
+
> = {}
|
|
724
|
+
): Promise<ApiResult<ExtractResponse<ReturnType<${className}["${methodName}"]>>>> {
|
|
725
|
+
const { onSuccess, onError, params } = options;
|
|
726
|
+
|
|
727
|
+
return handleApiResponse(
|
|
728
|
+
() =>
|
|
729
|
+
${instanceName}.${methodName}(
|
|
730
|
+
buildQuery<
|
|
731
|
+
${toQueryName(methodName)},
|
|
732
|
+
UnwrapArray<
|
|
733
|
+
ExtractDataIfPaginated<
|
|
734
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>
|
|
735
|
+
>
|
|
736
|
+
>
|
|
737
|
+
>(filters, page, pageSize, sortBy, sortDirection),
|
|
738
|
+
params ?? {}
|
|
739
|
+
),
|
|
740
|
+
${callbackOptionsExpression(defaultHandlers)}
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
`.trim();
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
return `
|
|
747
|
+
export async function ${methodName}(
|
|
748
|
+
query?: ${toQueryName(methodName)},
|
|
749
|
+
options: ApiMethodOptions<
|
|
750
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
751
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
752
|
+
RequestParams
|
|
753
|
+
> = {}
|
|
754
|
+
): Promise<ApiResult<ExtractResponse<ReturnType<${className}["${methodName}"]>>>> {
|
|
755
|
+
const { onSuccess, onError, params } = options;
|
|
756
|
+
|
|
757
|
+
return handleApiResponse(
|
|
758
|
+
() =>
|
|
759
|
+
${instanceName}.${methodName}(
|
|
760
|
+
(query ?? {}) as ${toQueryName(methodName)},
|
|
761
|
+
params ?? {}
|
|
762
|
+
),
|
|
763
|
+
${callbackOptionsExpression(defaultHandlers)}
|
|
764
|
+
);
|
|
765
|
+
}
|
|
766
|
+
`.trim();
|
|
767
|
+
})
|
|
768
|
+
.join("\n\n");
|
|
769
|
+
|
|
770
|
+
const simpleQueryMethodWrappers = simpleQueryMethods
|
|
771
|
+
.map((methodName) =>
|
|
772
|
+
`
|
|
773
|
+
export async function ${methodName}(
|
|
774
|
+
query?: ${toQueryName(methodName)},
|
|
775
|
+
options: ApiMethodOptions<
|
|
776
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
777
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
778
|
+
RequestParams
|
|
779
|
+
> = {}
|
|
780
|
+
): Promise<
|
|
781
|
+
ApiResult<
|
|
782
|
+
ExtractResponse<
|
|
783
|
+
ReturnType<
|
|
784
|
+
${className}["${methodName}"]
|
|
785
|
+
>
|
|
786
|
+
>
|
|
787
|
+
>
|
|
788
|
+
> {
|
|
789
|
+
const { onSuccess, onError, params } = options;
|
|
790
|
+
|
|
791
|
+
return handleApiResponse(
|
|
792
|
+
() =>
|
|
793
|
+
${instanceName}.${methodName}(
|
|
794
|
+
(query ?? {}) as ${toQueryName(methodName)},
|
|
795
|
+
params ?? {}
|
|
796
|
+
),
|
|
797
|
+
${callbackOptionsExpression(defaultHandlers)}
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
`.trim(),
|
|
801
|
+
)
|
|
802
|
+
.join("\n\n");
|
|
803
|
+
|
|
804
|
+
const nonQueryMethodWrappers = nonQueryMethods
|
|
805
|
+
.map(({ methodName, isFormData, methodArgumentCount }) => {
|
|
806
|
+
if (isFormData) {
|
|
807
|
+
return `
|
|
808
|
+
export async function ${methodName}(
|
|
809
|
+
data: Parameters<
|
|
810
|
+
${className}["${methodName}"]
|
|
811
|
+
>[0],
|
|
812
|
+
options: ApiMethodOptions<
|
|
813
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
814
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
815
|
+
RequestParams
|
|
816
|
+
> = {}
|
|
817
|
+
): Promise<
|
|
818
|
+
ApiResult<
|
|
819
|
+
ExtractResponse<
|
|
820
|
+
ReturnType<
|
|
821
|
+
${className}["${methodName}"]
|
|
822
|
+
>
|
|
823
|
+
>
|
|
824
|
+
>
|
|
825
|
+
> {
|
|
826
|
+
const { onSuccess, onError, params } = options;
|
|
827
|
+
const formData = toFormData(data);
|
|
828
|
+
|
|
829
|
+
return handleApiResponse(
|
|
830
|
+
() =>
|
|
831
|
+
${instanceName}.${methodName}(
|
|
832
|
+
formData as unknown as Parameters<
|
|
833
|
+
${className}["${methodName}"]
|
|
834
|
+
>[0],
|
|
835
|
+
params ?? {}
|
|
836
|
+
),
|
|
837
|
+
${callbackOptionsExpression(defaultHandlers)}
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
`.trim();
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
return `
|
|
844
|
+
export async function ${methodName}(
|
|
845
|
+
...argsWithOptions: [
|
|
846
|
+
...ApiMethodArguments<
|
|
847
|
+
${className}["${methodName}"],
|
|
848
|
+
RequestParams
|
|
849
|
+
>,
|
|
850
|
+
ApiMethodOptions<
|
|
851
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
852
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
853
|
+
RequestParams
|
|
854
|
+
>?
|
|
855
|
+
]
|
|
856
|
+
): Promise<
|
|
857
|
+
ApiResult<
|
|
858
|
+
ExtractResponse<
|
|
859
|
+
ReturnType<
|
|
860
|
+
${className}["${methodName}"]
|
|
861
|
+
>
|
|
862
|
+
>
|
|
863
|
+
>
|
|
864
|
+
> {
|
|
865
|
+
const args = [...argsWithOptions] as unknown[];
|
|
866
|
+
|
|
867
|
+
const options =
|
|
868
|
+
args.length > ${methodArgumentCount}
|
|
869
|
+
? (args.pop() as ApiMethodOptions<
|
|
870
|
+
ExtractResponse<ReturnType<${className}["${methodName}"]>>,
|
|
871
|
+
ExtractError<ReturnType<${className}["${methodName}"]>>,
|
|
872
|
+
RequestParams
|
|
873
|
+
>)
|
|
874
|
+
: {};
|
|
875
|
+
|
|
876
|
+
const { onSuccess, onError, params } = options ?? {};
|
|
877
|
+
|
|
878
|
+
const requestArgs = [
|
|
879
|
+
...args,
|
|
880
|
+
params ?? {}
|
|
881
|
+
] as unknown as Parameters<
|
|
882
|
+
${className}["${methodName}"]
|
|
883
|
+
>;
|
|
884
|
+
|
|
885
|
+
return handleApiResponse(
|
|
886
|
+
() =>
|
|
887
|
+
${instanceName}.${methodName}(
|
|
888
|
+
...requestArgs
|
|
889
|
+
),
|
|
890
|
+
${callbackOptionsExpression(defaultHandlers)}
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
`.trim();
|
|
894
|
+
})
|
|
895
|
+
.join("\n\n");
|
|
896
|
+
|
|
897
|
+
const runtimeValueImportNames = [
|
|
898
|
+
...(hasPaginatedMethods && useFilterFormValues ? ["buildQuery"] : []),
|
|
899
|
+
...(hasFormDataMethods ? ["toFormData"] : []),
|
|
900
|
+
"handleApiResponse",
|
|
901
|
+
];
|
|
902
|
+
|
|
903
|
+
const runtimeTypeImportNames = [
|
|
904
|
+
"ApiResult",
|
|
905
|
+
"ApiMethodOptions",
|
|
906
|
+
...(hasRegularNonQueryMethods ? ["ApiMethodArguments"] : []),
|
|
907
|
+
"ExtractResponse",
|
|
908
|
+
"ExtractError",
|
|
909
|
+
|
|
910
|
+
...(hasPaginatedMethods && useFilterFormValues
|
|
911
|
+
? [
|
|
912
|
+
"ExtractDataIfPaginated",
|
|
913
|
+
"FilterFormValues",
|
|
914
|
+
"SortableKeys",
|
|
915
|
+
"SortDirection",
|
|
916
|
+
"UnwrapArray",
|
|
917
|
+
]
|
|
918
|
+
: []),
|
|
919
|
+
];
|
|
920
|
+
|
|
921
|
+
const runtimeValueImports = createImportStatement({
|
|
922
|
+
names: runtimeValueImportNames,
|
|
923
|
+
from: runtimePackageName,
|
|
924
|
+
});
|
|
925
|
+
|
|
926
|
+
const defaultFunctionImports = defaultHandlers
|
|
927
|
+
? createAliasedImportStatement({
|
|
928
|
+
imports: [
|
|
929
|
+
{
|
|
930
|
+
name: defaultHandlers.defaultSuccessHandlerName,
|
|
931
|
+
alias: "typedApiDefaultSuccessHandler",
|
|
932
|
+
},
|
|
933
|
+
{
|
|
934
|
+
name: defaultHandlers.defaultErrorHandlerName,
|
|
935
|
+
alias: "typedApiDefaultErrorHandler",
|
|
936
|
+
},
|
|
937
|
+
],
|
|
938
|
+
from: defaultHandlers.defaultFunctionsPath,
|
|
939
|
+
})
|
|
940
|
+
: "";
|
|
941
|
+
|
|
942
|
+
const runtimeTypeImports = createImportStatement({
|
|
943
|
+
names: runtimeTypeImportNames,
|
|
944
|
+
from: runtimePackageName,
|
|
945
|
+
typeOnly: useTypeOnlyImports,
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
const generatedValueImports = createImportStatement({
|
|
949
|
+
names: [className],
|
|
950
|
+
from: `../generated/${baseName}`,
|
|
951
|
+
});
|
|
952
|
+
|
|
953
|
+
const generatedTypeImports =
|
|
954
|
+
generatedMethods.length > 0
|
|
955
|
+
? createImportStatement({
|
|
956
|
+
names: ["RequestParams"],
|
|
957
|
+
from: "../generated/http-client",
|
|
958
|
+
typeOnly: useTypeOnlyImports,
|
|
959
|
+
})
|
|
960
|
+
: "";
|
|
961
|
+
|
|
962
|
+
const content = `
|
|
963
|
+
${runtimeValueImports}
|
|
964
|
+
|
|
965
|
+
${defaultFunctionImports}
|
|
966
|
+
|
|
967
|
+
${runtimeTypeImports}
|
|
968
|
+
|
|
969
|
+
${generatedValueImports}
|
|
970
|
+
|
|
971
|
+
${generatedTypeImports}
|
|
972
|
+
|
|
973
|
+
/* =======================
|
|
974
|
+
Query Types
|
|
975
|
+
======================= */
|
|
976
|
+
${queryTypes}
|
|
977
|
+
|
|
978
|
+
/* =======================
|
|
979
|
+
API Instance
|
|
980
|
+
======================= */
|
|
981
|
+
const ${instanceName} = new ${className}();
|
|
982
|
+
|
|
983
|
+
/* =======================
|
|
984
|
+
Paginated Query Methods
|
|
985
|
+
======================= */
|
|
986
|
+
${paginatedMethodWrappers}
|
|
987
|
+
|
|
988
|
+
/* =======================
|
|
989
|
+
Simple Query Methods
|
|
990
|
+
======================= */
|
|
991
|
+
${simpleQueryMethodWrappers}
|
|
992
|
+
|
|
993
|
+
/* =======================
|
|
994
|
+
Non-Query Methods
|
|
995
|
+
======================= */
|
|
996
|
+
${nonQueryMethodWrappers}
|
|
997
|
+
`.trim();
|
|
998
|
+
|
|
999
|
+
const outputFile = path.join(methodsDir, `${className}.api.ts`);
|
|
1000
|
+
|
|
1001
|
+
await writeFormattedFile(outputFile, content);
|
|
1002
|
+
|
|
1003
|
+
methodExports.push(`export * from "./methods/${className}.api";`);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
const apiIndexContent = `
|
|
1007
|
+
export * from "./generated/data-contracts";
|
|
1008
|
+
export * from "./generated/http-client";
|
|
1009
|
+
${methodExports.join("\n")}
|
|
1010
|
+
`.trim();
|
|
1011
|
+
|
|
1012
|
+
await writeFormattedFile(path.join(apiRoot, "index.ts"), apiIndexContent);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
async function fixGeneratedMixedImports(apiDir) {
|
|
1016
|
+
const tsFiles = getAllTsFiles(apiDir);
|
|
1017
|
+
|
|
1018
|
+
for (const filePath of tsFiles) {
|
|
1019
|
+
if (
|
|
1020
|
+
filePath.endsWith("http-client.ts") ||
|
|
1021
|
+
filePath.endsWith("data-contracts.ts")
|
|
1022
|
+
) {
|
|
1023
|
+
continue;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
const originalContent = fs.readFileSync(filePath, "utf8");
|
|
1027
|
+
let content = originalContent;
|
|
1028
|
+
|
|
1029
|
+
content = content.replace(
|
|
1030
|
+
/import\s*\{([\s\S]*?)\}\s*from\s*["']\.\/http-client["'];/g,
|
|
1031
|
+
(_match, importsText) => {
|
|
1032
|
+
const importedNames = importsText
|
|
1033
|
+
.split(",")
|
|
1034
|
+
.map((name) => name.trim())
|
|
1035
|
+
.filter(Boolean);
|
|
1036
|
+
|
|
1037
|
+
const typeNames = importedNames.filter(
|
|
1038
|
+
(name) => name === "RequestParams",
|
|
1039
|
+
);
|
|
1040
|
+
|
|
1041
|
+
const valueNames = importedNames.filter(
|
|
1042
|
+
(name) => name !== "RequestParams",
|
|
1043
|
+
);
|
|
1044
|
+
|
|
1045
|
+
const statements = [];
|
|
1046
|
+
|
|
1047
|
+
if (valueNames.length > 0) {
|
|
1048
|
+
statements.push(
|
|
1049
|
+
`import { ${valueNames.join(", ")} } from "./http-client";`,
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
if (typeNames.length > 0 && useTypeOnlyImports) {
|
|
1054
|
+
statements.push(
|
|
1055
|
+
`import type { ${typeNames.join(", ")} } from "./http-client";`,
|
|
1056
|
+
);
|
|
1057
|
+
} else if (typeNames.length > 0) {
|
|
1058
|
+
statements.push(
|
|
1059
|
+
`import { ${typeNames.join(", ")} } from "./http-client";`,
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
return statements.join("\n");
|
|
1064
|
+
},
|
|
1065
|
+
);
|
|
1066
|
+
|
|
1067
|
+
if (useTypeOnlyImports) {
|
|
1068
|
+
content = content.replace(
|
|
1069
|
+
/import\s*\{([\s\S]*?)\}\s*from\s*["']\.\/data-contracts["'];/g,
|
|
1070
|
+
(_match, importsText) =>
|
|
1071
|
+
`import type {${importsText}} from "./data-contracts";`,
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
if (content !== originalContent) {
|
|
1076
|
+
await writeFormattedFile(filePath, content);
|
|
1077
|
+
|
|
1078
|
+
console.log(
|
|
1079
|
+
`Fixed mixed imports in ${path.relative(process.cwd(), filePath)}`,
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
async function main() {
|
|
1086
|
+
const swaggerInput = await resolveSwaggerInput();
|
|
1087
|
+
|
|
1088
|
+
console.log(`Generating API from: ${swaggerInput.label}`);
|
|
1089
|
+
console.log(`Output folder: ${apiRoot}`);
|
|
1090
|
+
|
|
1091
|
+
await generateOpenApiClient(swaggerInput.input);
|
|
1092
|
+
|
|
1093
|
+
await fixGeneratedMixedImports(generatedDir);
|
|
1094
|
+
|
|
1095
|
+
await createMethodFiles();
|
|
1096
|
+
|
|
1097
|
+
console.log("API generation completed.");
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
main().catch((error) => {
|
|
1101
|
+
console.error(error);
|
|
1102
|
+
process.exit(1);
|
|
1103
|
+
});
|