@nestbridge/core 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -8
- package/build/nestbridge.core.d.ts +132 -114
- package/build/nestbridge.core.js +914 -957
- package/build/nestbridge.core.js.map +1 -1
- package/package.json +5 -5
package/build/nestbridge.core.js
CHANGED
|
@@ -1,958 +1,915 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
const
|
|
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
|
-
const
|
|
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
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
const
|
|
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
|
-
const
|
|
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
|
-
const
|
|
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
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
const
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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
|
-
const
|
|
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
|
-
(method) => ` ${method.name}(...args: Parameters<${serverAlias}['${method.name}']>): RemoteResult<${serverAlias}['${method.name}']>;`
|
|
914
|
-
);
|
|
915
|
-
const classBody = [" constructor();", "", ...methodDeclarations].join("\n");
|
|
916
|
-
return [
|
|
917
|
-
`import type { ${controller.name} as ${serverAlias} } from '${importSpecifier}';`,
|
|
918
|
-
`import type { RemoteResult } from '@nestbridge/runtime';`,
|
|
919
|
-
"",
|
|
920
|
-
"/**",
|
|
921
|
-
" * Generated by NestBridge — client-facing methods only.",
|
|
922
|
-
` * @see {@link ${sourceFileSpecifier}} for the real controller implementation.`,
|
|
923
|
-
" */",
|
|
924
|
-
`export declare class ${controller.name} {`,
|
|
925
|
-
classBody,
|
|
926
|
-
"}",
|
|
927
|
-
""
|
|
928
|
-
].join("\n");
|
|
929
|
-
};
|
|
930
|
-
|
|
931
|
-
const formatDiagnostic = (diagnostic) => {
|
|
932
|
-
const subject = diagnostic.memberName.length > 0 ? `${diagnostic.controllerName}.${diagnostic.memberName}` : diagnostic.controllerName;
|
|
933
|
-
const lines = [`[NestBridge] ${diagnostic.title}`, "", subject, "", diagnostic.detail];
|
|
934
|
-
if (diagnostic.found !== void 0) {
|
|
935
|
-
lines.push("", "Found:", diagnostic.found);
|
|
936
|
-
}
|
|
937
|
-
if (diagnostic.expected !== void 0) {
|
|
938
|
-
lines.push("", "Expected:", diagnostic.expected);
|
|
939
|
-
}
|
|
940
|
-
lines.push("", `${diagnostic.filePath}:${diagnostic.line}:${diagnostic.column}`);
|
|
941
|
-
return lines.join("\n");
|
|
942
|
-
};
|
|
943
|
-
|
|
944
|
-
class NestBridgeDiagnosticError extends Error {
|
|
945
|
-
diagnostic;
|
|
946
|
-
constructor(diagnostic) {
|
|
947
|
-
super(formatDiagnostic(diagnostic));
|
|
948
|
-
this.name = "NestBridgeDiagnosticError";
|
|
949
|
-
this.diagnostic = diagnostic;
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
const version = "1.0.0";
|
|
954
|
-
|
|
955
|
-
const VERSION = version;
|
|
956
|
-
|
|
1
|
+
import { SyntaxKind, isArrayLiteralExpression, isArrayTypeNode, isArrowFunction, isBlock, isCallExpression, isClassDeclaration, isDecorator, isExportDeclaration, isFunctionExpression, isIdentifier, isImportDeclaration, isMethodDeclaration, isNamedExports, isNamedImports, isObjectLiteralExpression, isPropertyAssignment, isPropertyDeclaration, isReturnStatement, isStringLiteralLikeNode, isTypeReferenceNode, isUnionTypeNode } from "typescript/unstable/ast";
|
|
2
|
+
import { API } from "typescript/unstable/sync";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { dirname, extname, relative, resolve } from "node:path";
|
|
5
|
+
//#region src/analysis/decorator-inspection.ts
|
|
6
|
+
var getDecorators = (node) => {
|
|
7
|
+
const decorators = node.modifiers?.filter(isDecorator);
|
|
8
|
+
return decorators === void 0 || decorators.length === 0 ? void 0 : decorators;
|
|
9
|
+
};
|
|
10
|
+
var findDecorator = (node, decoratorName) => {
|
|
11
|
+
const decorators = getDecorators(node);
|
|
12
|
+
if (decorators === void 0) return;
|
|
13
|
+
return decorators.find((decorator) => decoratorNameOf(decorator) === decoratorName);
|
|
14
|
+
};
|
|
15
|
+
var findAnyDecorator = (node, decoratorNames) => {
|
|
16
|
+
const decorators = getDecorators(node);
|
|
17
|
+
if (decorators === void 0) return;
|
|
18
|
+
return decorators.find((decorator) => decoratorNames.includes(decoratorNameOf(decorator) ?? ""));
|
|
19
|
+
};
|
|
20
|
+
var decoratorNameOf = (decorator) => {
|
|
21
|
+
const expression = decorator.expression;
|
|
22
|
+
if (isCallExpression(expression) && isIdentifier(expression.expression)) return expression.expression.text;
|
|
23
|
+
if (isIdentifier(expression)) return expression.text;
|
|
24
|
+
};
|
|
25
|
+
var readStaticStringArgument = (decorator) => {
|
|
26
|
+
const expression = decorator.expression;
|
|
27
|
+
if (!isCallExpression(expression)) return {
|
|
28
|
+
ok: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
};
|
|
31
|
+
const [firstArgument] = expression.arguments;
|
|
32
|
+
if (firstArgument === void 0) return {
|
|
33
|
+
ok: true,
|
|
34
|
+
value: void 0
|
|
35
|
+
};
|
|
36
|
+
if (isStringLiteralLikeNode(firstArgument)) return {
|
|
37
|
+
ok: true,
|
|
38
|
+
value: firstArgument.text
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
ok: false,
|
|
42
|
+
argumentText: firstArgument.getText()
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/models/http-method.ts
|
|
47
|
+
var HTTP_METHOD_DECORATOR_NAMES = {
|
|
48
|
+
Get: "GET",
|
|
49
|
+
Post: "POST",
|
|
50
|
+
Put: "PUT",
|
|
51
|
+
Patch: "PATCH",
|
|
52
|
+
Delete: "DELETE"
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/analysis/node-location.ts
|
|
56
|
+
var locationOf = (sourceFile, node) => {
|
|
57
|
+
const { line, character } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
58
|
+
return {
|
|
59
|
+
line: line + 1,
|
|
60
|
+
column: character + 1
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
//#region src/analysis/extract-parameter-definition.ts
|
|
65
|
+
var SUPPORTED_PARAMETER_DECORATORS = [
|
|
66
|
+
"Param",
|
|
67
|
+
"Query",
|
|
68
|
+
"Body",
|
|
69
|
+
"Headers"
|
|
70
|
+
];
|
|
71
|
+
var KNOWN_UNSUPPORTED_PARAMETER_DECORATORS = [
|
|
72
|
+
"Req",
|
|
73
|
+
"Res",
|
|
74
|
+
"Request",
|
|
75
|
+
"Response"
|
|
76
|
+
];
|
|
77
|
+
var extractParameterDefinition = (parameter, index, context) => {
|
|
78
|
+
const decorator = findAnyDecorator(parameter, [...SUPPORTED_PARAMETER_DECORATORS, ...KNOWN_UNSUPPORTED_PARAMETER_DECORATORS]);
|
|
79
|
+
const location = locationOf(context.sourceFile, parameter);
|
|
80
|
+
if (decorator === void 0) {
|
|
81
|
+
context.diagnostics.push({
|
|
82
|
+
code: "unsupported-parameter",
|
|
83
|
+
title: "Unsupported parameter.",
|
|
84
|
+
controllerName: context.controllerName,
|
|
85
|
+
memberName: context.methodName,
|
|
86
|
+
detail: `Parameter "${parameter.name.getText()}" must be decorated with one of @Param, @Query, @Body, or @Headers to be transported through a NestBridge HTTP client.`,
|
|
87
|
+
filePath: context.filePath,
|
|
88
|
+
line: location.line,
|
|
89
|
+
column: location.column
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const decoratorName = decoratorNameOf(decorator);
|
|
94
|
+
if (decoratorName !== void 0 && KNOWN_UNSUPPORTED_PARAMETER_DECORATORS.includes(decoratorName)) {
|
|
95
|
+
context.diagnostics.push({
|
|
96
|
+
code: "unsupported-parameter",
|
|
97
|
+
title: "Unsupported parameter.",
|
|
98
|
+
controllerName: context.controllerName,
|
|
99
|
+
memberName: context.methodName,
|
|
100
|
+
detail: `@${decoratorName}() cannot be transported through a NestBridge HTTP client.`,
|
|
101
|
+
filePath: context.filePath,
|
|
102
|
+
line: location.line,
|
|
103
|
+
column: location.column
|
|
104
|
+
});
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!isIdentifier(parameter.name)) {
|
|
108
|
+
context.diagnostics.push({
|
|
109
|
+
code: "unsupported-parameter",
|
|
110
|
+
title: "Unsupported parameter.",
|
|
111
|
+
controllerName: context.controllerName,
|
|
112
|
+
memberName: context.methodName,
|
|
113
|
+
detail: "Destructured parameters cannot be transported through a NestBridge HTTP client.",
|
|
114
|
+
filePath: context.filePath,
|
|
115
|
+
line: location.line,
|
|
116
|
+
column: location.column
|
|
117
|
+
});
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const argument = readStaticStringArgument(decorator);
|
|
121
|
+
if (!argument.ok) {
|
|
122
|
+
context.diagnostics.push({
|
|
123
|
+
code: "unsupported-parameter",
|
|
124
|
+
title: "Unsupported parameter.",
|
|
125
|
+
controllerName: context.controllerName,
|
|
126
|
+
memberName: context.methodName,
|
|
127
|
+
detail: `@${decoratorName}() arguments must be statically analyzable string literals.`,
|
|
128
|
+
found: `@${decoratorName}(${argument.argumentText})`,
|
|
129
|
+
filePath: context.filePath,
|
|
130
|
+
line: location.line,
|
|
131
|
+
column: location.column
|
|
132
|
+
});
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const base = {
|
|
136
|
+
index,
|
|
137
|
+
parameterName: parameter.name.text
|
|
138
|
+
};
|
|
139
|
+
if (decoratorName === "Param") {
|
|
140
|
+
if (argument.value === void 0) {
|
|
141
|
+
context.diagnostics.push({
|
|
142
|
+
code: "unsupported-parameter",
|
|
143
|
+
title: "Unsupported parameter.",
|
|
144
|
+
controllerName: context.controllerName,
|
|
145
|
+
memberName: context.methodName,
|
|
146
|
+
detail: "A whole @Param() is not supported; provide a route parameter name such as @Param('id').",
|
|
147
|
+
filePath: context.filePath,
|
|
148
|
+
line: location.line,
|
|
149
|
+
column: location.column
|
|
150
|
+
});
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
...base,
|
|
155
|
+
kind: "param",
|
|
156
|
+
name: argument.value
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (decoratorName === "Headers") {
|
|
160
|
+
if (argument.value === void 0) {
|
|
161
|
+
context.diagnostics.push({
|
|
162
|
+
code: "unsupported-parameter",
|
|
163
|
+
title: "Unsupported parameter.",
|
|
164
|
+
controllerName: context.controllerName,
|
|
165
|
+
memberName: context.methodName,
|
|
166
|
+
detail: "A whole @Headers() is not supported; provide a header name such as @Headers('x-example').",
|
|
167
|
+
filePath: context.filePath,
|
|
168
|
+
line: location.line,
|
|
169
|
+
column: location.column
|
|
170
|
+
});
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
...base,
|
|
175
|
+
kind: "header",
|
|
176
|
+
name: argument.value
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
if (decoratorName === "Query") return {
|
|
180
|
+
...base,
|
|
181
|
+
kind: "query",
|
|
182
|
+
name: argument.value
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
...base,
|
|
186
|
+
kind: "body",
|
|
187
|
+
name: argument.value
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region src/analysis/graphql-scalar-type.ts
|
|
192
|
+
var PRIMITIVE_SCALAR_TYPES = {
|
|
193
|
+
string: "String",
|
|
194
|
+
number: "Float",
|
|
195
|
+
boolean: "Boolean"
|
|
196
|
+
};
|
|
197
|
+
var unwrapPromise = (typeNode) => {
|
|
198
|
+
if (isTypeReferenceNode(typeNode) && isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Promise" && typeNode.typeArguments?.[0] !== void 0) return unwrapPromise(typeNode.typeArguments[0]);
|
|
199
|
+
return typeNode;
|
|
200
|
+
};
|
|
201
|
+
var unwrapNullable = (typeNode) => {
|
|
202
|
+
if (!isUnionTypeNode(typeNode)) return {
|
|
203
|
+
inner: typeNode,
|
|
204
|
+
isNullable: false
|
|
205
|
+
};
|
|
206
|
+
const nonNullMembers = typeNode.types.filter((member) => member.kind !== SyntaxKind.NullKeyword && member.kind !== SyntaxKind.UndefinedKeyword);
|
|
207
|
+
const [onlyMember] = nonNullMembers;
|
|
208
|
+
if (nonNullMembers.length !== 1 || onlyMember === void 0) return {
|
|
209
|
+
inner: typeNode,
|
|
210
|
+
isNullable: nonNullMembers.length !== typeNode.types.length
|
|
211
|
+
};
|
|
212
|
+
return {
|
|
213
|
+
inner: onlyMember,
|
|
214
|
+
isNullable: true
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
var unwrapArrayElement = (typeNode) => {
|
|
218
|
+
if (isArrayTypeNode(typeNode)) return typeNode.elementType;
|
|
219
|
+
if (isTypeReferenceNode(typeNode) && isIdentifier(typeNode.typeName) && typeNode.typeName.text === "Array" && typeNode.typeArguments?.[0] !== void 0) return typeNode.typeArguments[0];
|
|
220
|
+
};
|
|
221
|
+
var identifierTextOf = (typeNode) => {
|
|
222
|
+
if (isTypeReferenceNode(typeNode) && isIdentifier(typeNode.typeName)) return typeNode.typeName.text;
|
|
223
|
+
switch (typeNode.kind) {
|
|
224
|
+
case SyntaxKind.StringKeyword: return "string";
|
|
225
|
+
case SyntaxKind.NumberKeyword: return "number";
|
|
226
|
+
case SyntaxKind.BooleanKeyword: return "boolean";
|
|
227
|
+
default: return;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var unwrapTypeNode = (typeNode) => {
|
|
231
|
+
const { inner: withoutNullable, isNullable } = unwrapNullable(unwrapPromise(typeNode));
|
|
232
|
+
const arrayElement = unwrapArrayElement(withoutNullable);
|
|
233
|
+
const identifierText = identifierTextOf(arrayElement === void 0 ? withoutNullable : unwrapNullable(arrayElement).inner);
|
|
234
|
+
if (identifierText === void 0) return;
|
|
235
|
+
return {
|
|
236
|
+
identifierText,
|
|
237
|
+
isArray: arrayElement !== void 0,
|
|
238
|
+
isNullable
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
var graphqlScalarNameFor = (identifierText) => PRIMITIVE_SCALAR_TYPES[identifierText] ?? identifierText;
|
|
242
|
+
var graphqlTypeStringFor = (unwrapped, explicitTypeName) => {
|
|
243
|
+
const baseName = explicitTypeName ?? graphqlScalarNameFor(unwrapped.identifierText);
|
|
244
|
+
const wrapped = unwrapped.isArray ? `[${baseName}!]` : baseName;
|
|
245
|
+
return unwrapped.isNullable ? wrapped : `${wrapped}!`;
|
|
246
|
+
};
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/analysis/read-response-kind.ts
|
|
249
|
+
var OBSERVABLE_TYPE_NAME = "Observable";
|
|
250
|
+
var STREAMABLE_FILE_TYPE_NAME = "StreamableFile";
|
|
251
|
+
var readResponseKind = (returnType) => {
|
|
252
|
+
if (returnType === void 0) return "json";
|
|
253
|
+
const unwrapped = unwrapPromise(returnType);
|
|
254
|
+
if (!isTypeReferenceNode(unwrapped) || !isIdentifier(unwrapped.typeName)) return "json";
|
|
255
|
+
if (unwrapped.typeName.text === OBSERVABLE_TYPE_NAME) return "observable";
|
|
256
|
+
if (unwrapped.typeName.text === STREAMABLE_FILE_TYPE_NAME) return "stream";
|
|
257
|
+
return "json";
|
|
258
|
+
};
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/analysis/route-path.ts
|
|
261
|
+
var trimSlashes = (segment) => segment.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
262
|
+
var joinRoutePath = (controllerPath, methodPath) => {
|
|
263
|
+
return `/${[trimSlashes(controllerPath), trimSlashes(methodPath ?? "")].filter((segment) => segment.length > 0).join("/")}`;
|
|
264
|
+
};
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/analysis/extract-method-definition.ts
|
|
267
|
+
var extractMethodDefinition = (method, context) => {
|
|
268
|
+
const decorator = findAnyDecorator(method, Object.keys(HTTP_METHOD_DECORATOR_NAMES));
|
|
269
|
+
if (decorator === void 0) return;
|
|
270
|
+
const methodName = method.name.getText();
|
|
271
|
+
const decoratorName = decoratorNameOf(decorator);
|
|
272
|
+
const location = locationOf(context.sourceFile, method);
|
|
273
|
+
if (decoratorName === void 0) return;
|
|
274
|
+
const httpMethod = HTTP_METHOD_DECORATOR_NAMES[decoratorName];
|
|
275
|
+
if (httpMethod === void 0) return;
|
|
276
|
+
const routeArgument = readStaticStringArgument(decorator);
|
|
277
|
+
if (!routeArgument.ok) {
|
|
278
|
+
context.diagnostics.push({
|
|
279
|
+
code: "unsupported-route",
|
|
280
|
+
title: "Unsupported route.",
|
|
281
|
+
controllerName: context.controllerName,
|
|
282
|
+
memberName: methodName,
|
|
283
|
+
detail: "Route paths must be statically analyzable.",
|
|
284
|
+
found: `@${decoratorName}(${routeArgument.argumentText})`,
|
|
285
|
+
filePath: context.filePath,
|
|
286
|
+
line: location.line,
|
|
287
|
+
column: location.column
|
|
288
|
+
});
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const parameters = method.parameters.map((parameter, index) => extractParameterDefinition(parameter, index, {
|
|
292
|
+
sourceFile: context.sourceFile,
|
|
293
|
+
filePath: context.filePath,
|
|
294
|
+
controllerName: context.controllerName,
|
|
295
|
+
methodName,
|
|
296
|
+
diagnostics: context.diagnostics
|
|
297
|
+
}));
|
|
298
|
+
if (parameters.some((parameter) => parameter === void 0)) return;
|
|
299
|
+
return {
|
|
300
|
+
name: methodName,
|
|
301
|
+
httpMethod,
|
|
302
|
+
path: joinRoutePath(context.controllerPath, routeArgument.value),
|
|
303
|
+
parameters: parameters.filter((parameter) => parameter !== void 0),
|
|
304
|
+
responseKind: readResponseKind(method.type),
|
|
305
|
+
line: location.line,
|
|
306
|
+
column: location.column
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/analysis/extract-controller-definition.ts
|
|
311
|
+
var extractControllerDefinition = (classDeclaration, sourceFile, filePath, diagnostics) => {
|
|
312
|
+
const controllerName = classDeclaration.name?.text ?? "(anonymous controller)";
|
|
313
|
+
const decorator = findDecorator(classDeclaration, "Controller");
|
|
314
|
+
if (decorator === void 0) return;
|
|
315
|
+
const location = locationOf(sourceFile, classDeclaration);
|
|
316
|
+
const argument = readStaticStringArgument(decorator);
|
|
317
|
+
if (!argument.ok) {
|
|
318
|
+
diagnostics.push({
|
|
319
|
+
code: "unsupported-route",
|
|
320
|
+
title: "Unsupported route.",
|
|
321
|
+
controllerName,
|
|
322
|
+
memberName: "",
|
|
323
|
+
detail: "Controller paths must be statically analyzable.",
|
|
324
|
+
found: `@Controller(${argument.argumentText})`,
|
|
325
|
+
filePath,
|
|
326
|
+
line: location.line,
|
|
327
|
+
column: location.column
|
|
328
|
+
});
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const methods = classDeclaration.members.filter((member) => isMethodDeclaration(member)).map((method) => extractMethodDefinition(method, {
|
|
332
|
+
sourceFile,
|
|
333
|
+
filePath,
|
|
334
|
+
controllerName,
|
|
335
|
+
controllerPath: argument.value ?? "",
|
|
336
|
+
diagnostics
|
|
337
|
+
})).filter((method) => method !== void 0);
|
|
338
|
+
return {
|
|
339
|
+
name: controllerName,
|
|
340
|
+
path: argument.value ?? "",
|
|
341
|
+
sourceFile: filePath,
|
|
342
|
+
methods
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/analysis/find-controller-classes.ts
|
|
347
|
+
var findControllerClasses = (sourceFile) => {
|
|
348
|
+
return sourceFile.statements.filter((statement) => isClassDeclaration(statement) && findDecorator(statement, "Controller") !== void 0);
|
|
349
|
+
};
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/analysis/parse-source-file.ts
|
|
352
|
+
var sharedApi;
|
|
353
|
+
var parseSourceFile = (filePath) => {
|
|
354
|
+
sharedApi ??= new API();
|
|
355
|
+
const sourceFile = sharedApi.updateSnapshot({ openFiles: [filePath] }).getDefaultProjectForFile(filePath)?.program.getSourceFile(filePath);
|
|
356
|
+
if (sourceFile === void 0) throw new Error(`Unable to parse source file: ${filePath}`);
|
|
357
|
+
return sourceFile;
|
|
358
|
+
};
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/analysis/analyze-controllers.ts
|
|
361
|
+
var analyzeControllers = (filePaths) => {
|
|
362
|
+
const diagnostics = [];
|
|
363
|
+
const controllers = [];
|
|
364
|
+
for (const filePath of filePaths) {
|
|
365
|
+
const sourceFile = parseSourceFile(filePath);
|
|
366
|
+
for (const classDeclaration of findControllerClasses(sourceFile)) {
|
|
367
|
+
const controller = extractControllerDefinition(classDeclaration, sourceFile, filePath, diagnostics);
|
|
368
|
+
if (controller !== void 0) controllers.push(controller);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
controllers,
|
|
373
|
+
diagnostics
|
|
374
|
+
};
|
|
375
|
+
};
|
|
376
|
+
//#endregion
|
|
377
|
+
//#region src/models/graphql-operation-kind.ts
|
|
378
|
+
var GRAPHQL_OPERATION_DECORATOR_NAMES = {
|
|
379
|
+
Query: "query",
|
|
380
|
+
Mutation: "mutation"
|
|
381
|
+
};
|
|
382
|
+
//#endregion
|
|
383
|
+
//#region src/analysis/read-type-thunk-expression.ts
|
|
384
|
+
var readTypeThunkExpression = (thunk) => {
|
|
385
|
+
if (!isBlock(thunk.body)) return thunk.body;
|
|
386
|
+
return thunk.body.statements.find(isReturnStatement)?.expression;
|
|
387
|
+
};
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region src/analysis/read-args-type-option.ts
|
|
390
|
+
var readArgsTypeOption = (decorator) => {
|
|
391
|
+
if (!isCallExpression(decorator.expression)) return;
|
|
392
|
+
const optionsArgument = decorator.expression.arguments.find(isObjectLiteralExpression);
|
|
393
|
+
if (optionsArgument === void 0) return;
|
|
394
|
+
const typeProperty = optionsArgument.properties.find((property) => isPropertyAssignment(property) && isIdentifier(property.name) && property.name.text === "type");
|
|
395
|
+
if (typeProperty === void 0) return;
|
|
396
|
+
const thunk = typeProperty.initializer;
|
|
397
|
+
if (!isArrowFunction(thunk) && !isFunctionExpression(thunk)) return;
|
|
398
|
+
const returnedExpression = readTypeThunkExpression(thunk);
|
|
399
|
+
if (returnedExpression === void 0) return;
|
|
400
|
+
if (isArrayLiteralExpression(returnedExpression)) {
|
|
401
|
+
const element = returnedExpression.elements[0];
|
|
402
|
+
return element !== void 0 && isIdentifier(element) ? {
|
|
403
|
+
typeName: element.text,
|
|
404
|
+
isArray: true
|
|
405
|
+
} : void 0;
|
|
406
|
+
}
|
|
407
|
+
return isIdentifier(returnedExpression) ? {
|
|
408
|
+
typeName: returnedExpression.text,
|
|
409
|
+
isArray: false
|
|
410
|
+
} : void 0;
|
|
411
|
+
};
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/analysis/extract-resolver-argument-definition.ts
|
|
414
|
+
var extractResolverArgumentDefinition = (parameter, index, context) => {
|
|
415
|
+
const decorator = findAnyDecorator(parameter, ["Args"]);
|
|
416
|
+
const location = locationOf(context.sourceFile, parameter);
|
|
417
|
+
if (decorator === void 0) {
|
|
418
|
+
context.diagnostics.push({
|
|
419
|
+
code: "unsupported-argument",
|
|
420
|
+
title: "Unsupported argument.",
|
|
421
|
+
controllerName: context.resolverName,
|
|
422
|
+
memberName: context.methodName,
|
|
423
|
+
detail: `Parameter "${parameter.name.getText()}" must be decorated with @Args to be transported through a NestBridge GraphQL client.`,
|
|
424
|
+
filePath: context.filePath,
|
|
425
|
+
line: location.line,
|
|
426
|
+
column: location.column
|
|
427
|
+
});
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (!isIdentifier(parameter.name)) {
|
|
431
|
+
context.diagnostics.push({
|
|
432
|
+
code: "unsupported-argument",
|
|
433
|
+
title: "Unsupported argument.",
|
|
434
|
+
controllerName: context.resolverName,
|
|
435
|
+
memberName: context.methodName,
|
|
436
|
+
detail: "Destructured parameters cannot be transported through a NestBridge GraphQL client.",
|
|
437
|
+
filePath: context.filePath,
|
|
438
|
+
line: location.line,
|
|
439
|
+
column: location.column
|
|
440
|
+
});
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
const nameArgument = readStaticStringArgument(decorator);
|
|
444
|
+
if (!nameArgument.ok) {
|
|
445
|
+
context.diagnostics.push({
|
|
446
|
+
code: "unsupported-argument",
|
|
447
|
+
title: "Unsupported argument.",
|
|
448
|
+
controllerName: context.resolverName,
|
|
449
|
+
memberName: context.methodName,
|
|
450
|
+
detail: "@Args() name must be a statically analyzable string literal.",
|
|
451
|
+
found: `@Args(${nameArgument.argumentText})`,
|
|
452
|
+
filePath: context.filePath,
|
|
453
|
+
line: location.line,
|
|
454
|
+
column: location.column
|
|
455
|
+
});
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (nameArgument.value === void 0) {
|
|
459
|
+
context.diagnostics.push({
|
|
460
|
+
code: "unsupported-argument",
|
|
461
|
+
title: "Unsupported argument.",
|
|
462
|
+
controllerName: context.resolverName,
|
|
463
|
+
memberName: context.methodName,
|
|
464
|
+
detail: "A whole @Args() is not supported; provide an argument name such as @Args('id').",
|
|
465
|
+
filePath: context.filePath,
|
|
466
|
+
line: location.line,
|
|
467
|
+
column: location.column
|
|
468
|
+
});
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (parameter.type === void 0) {
|
|
472
|
+
context.diagnostics.push({
|
|
473
|
+
code: "unsupported-argument",
|
|
474
|
+
title: "Unsupported argument.",
|
|
475
|
+
controllerName: context.resolverName,
|
|
476
|
+
memberName: context.methodName,
|
|
477
|
+
detail: `@Args() parameter "${parameter.name.text}" needs an explicit type annotation.`,
|
|
478
|
+
filePath: context.filePath,
|
|
479
|
+
line: location.line,
|
|
480
|
+
column: location.column
|
|
481
|
+
});
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
const unwrapped = unwrapTypeNode(parameter.type);
|
|
485
|
+
if (unwrapped === void 0) {
|
|
486
|
+
context.diagnostics.push({
|
|
487
|
+
code: "unsupported-argument",
|
|
488
|
+
title: "Unsupported argument.",
|
|
489
|
+
controllerName: context.resolverName,
|
|
490
|
+
memberName: context.methodName,
|
|
491
|
+
detail: `@Args() parameter "${parameter.name.text}" has a type NestBridge cannot statically resolve to a GraphQL type.`,
|
|
492
|
+
found: parameter.type.getText(),
|
|
493
|
+
filePath: context.filePath,
|
|
494
|
+
line: location.line,
|
|
495
|
+
column: location.column
|
|
496
|
+
});
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const explicitType = readArgsTypeOption(decorator);
|
|
500
|
+
return {
|
|
501
|
+
index,
|
|
502
|
+
parameterName: parameter.name.text,
|
|
503
|
+
name: nameArgument.value,
|
|
504
|
+
graphqlType: graphqlTypeStringFor(unwrapped, explicitType?.typeName)
|
|
505
|
+
};
|
|
506
|
+
};
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/analysis/resolve-type-declaration.ts
|
|
509
|
+
var parsedFilesByPath = /* @__PURE__ */ new Map();
|
|
510
|
+
var parseFile = (filePath) => {
|
|
511
|
+
const cached = parsedFilesByPath.get(filePath);
|
|
512
|
+
if (cached !== void 0) return cached;
|
|
513
|
+
const sourceFile = parseSourceFile(filePath);
|
|
514
|
+
parsedFilesByPath.set(filePath, sourceFile);
|
|
515
|
+
return sourceFile;
|
|
516
|
+
};
|
|
517
|
+
var resolveModuleFile = (fromFilePath, moduleSpecifierText) => {
|
|
518
|
+
if (!moduleSpecifierText.startsWith(".")) return;
|
|
519
|
+
const base = resolve(dirname(fromFilePath), moduleSpecifierText);
|
|
520
|
+
return [
|
|
521
|
+
`${base}.ts`,
|
|
522
|
+
`${base}.tsx`,
|
|
523
|
+
resolve(base, "index.ts")
|
|
524
|
+
].find((candidate) => existsSync(candidate));
|
|
525
|
+
};
|
|
526
|
+
var findExportedDeclaration = (sourceFile, name) => sourceFile.statements.find((statement) => isClassDeclaration(statement) && statement.name?.text === name);
|
|
527
|
+
var findImportSource = (sourceFile, localName) => {
|
|
528
|
+
for (const statement of sourceFile.statements) {
|
|
529
|
+
if (!isImportDeclaration(statement) || !isStringLiteralLikeNode(statement.moduleSpecifier)) continue;
|
|
530
|
+
const namedBindings = statement.importClause?.namedBindings;
|
|
531
|
+
if (namedBindings === void 0 || !isNamedImports(namedBindings)) continue;
|
|
532
|
+
const element = namedBindings.elements.find((candidate) => candidate.name.text === localName);
|
|
533
|
+
if (element !== void 0) return {
|
|
534
|
+
moduleSpecifierText: statement.moduleSpecifier.text,
|
|
535
|
+
importedName: element.propertyName?.text ?? element.name.text
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
var findReExportSource = (sourceFile, name) => {
|
|
540
|
+
for (const statement of sourceFile.statements) {
|
|
541
|
+
if (!isExportDeclaration(statement) || statement.moduleSpecifier === void 0 || !isStringLiteralLikeNode(statement.moduleSpecifier)) continue;
|
|
542
|
+
if (statement.exportClause === void 0) return statement.moduleSpecifier.text;
|
|
543
|
+
if (isNamedExports(statement.exportClause) && statement.exportClause.elements.some((element) => (element.propertyName?.text ?? element.name.text) === name)) return statement.moduleSpecifier.text;
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
var resolveClassDeclaration = (name, fromSourceFile, fromFilePath, visited = /* @__PURE__ */ new Set()) => {
|
|
547
|
+
if (visited.has(fromFilePath)) return;
|
|
548
|
+
visited.add(fromFilePath);
|
|
549
|
+
const direct = findExportedDeclaration(fromSourceFile, name);
|
|
550
|
+
if (direct !== void 0) return {
|
|
551
|
+
classDeclaration: direct,
|
|
552
|
+
sourceFile: fromSourceFile,
|
|
553
|
+
filePath: fromFilePath
|
|
554
|
+
};
|
|
555
|
+
const importSource = findImportSource(fromSourceFile, name);
|
|
556
|
+
if (importSource !== void 0) {
|
|
557
|
+
const resolvedPath = resolveModuleFile(fromFilePath, importSource.moduleSpecifierText);
|
|
558
|
+
if (resolvedPath !== void 0) {
|
|
559
|
+
const nextSourceFile = parseFile(resolvedPath);
|
|
560
|
+
const result = resolveClassDeclaration(importSource.importedName, nextSourceFile, resolvedPath, visited);
|
|
561
|
+
if (result !== void 0) return result;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
const reExportModuleSpecifierText = findReExportSource(fromSourceFile, name);
|
|
565
|
+
if (reExportModuleSpecifierText !== void 0) {
|
|
566
|
+
const resolvedPath = resolveModuleFile(fromFilePath, reExportModuleSpecifierText);
|
|
567
|
+
if (resolvedPath !== void 0) return resolveClassDeclaration(name, parseFile(resolvedPath), resolvedPath, visited);
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region src/analysis/extract-selection-fields.ts
|
|
572
|
+
var PRIMITIVE_SCALAR_NAMES$1 = /* @__PURE__ */ new Set([
|
|
573
|
+
"string",
|
|
574
|
+
"number",
|
|
575
|
+
"boolean"
|
|
576
|
+
]);
|
|
577
|
+
var extractSelectionFields = (classDeclaration, sourceFile, filePath, context) => {
|
|
578
|
+
const typeName = classDeclaration.name?.text ?? "(anonymous type)";
|
|
579
|
+
const location = locationOf(sourceFile, classDeclaration);
|
|
580
|
+
if (context.visitedTypeNames.has(typeName)) {
|
|
581
|
+
context.diagnostics.push({
|
|
582
|
+
code: "circular-type",
|
|
583
|
+
title: "Circular type.",
|
|
584
|
+
controllerName: context.resolverName,
|
|
585
|
+
memberName: context.methodName,
|
|
586
|
+
detail: `Type "${typeName}" references itself, directly or indirectly. NestBridge cannot build a finite GraphQL selection set for it.`,
|
|
587
|
+
filePath,
|
|
588
|
+
line: location.line,
|
|
589
|
+
column: location.column
|
|
590
|
+
});
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
const nextVisited = new Set(context.visitedTypeNames).add(typeName);
|
|
594
|
+
const properties = classDeclaration.members.filter((member) => isPropertyDeclaration(member) && findDecorator(member, "Field") !== void 0);
|
|
595
|
+
const fields = [];
|
|
596
|
+
for (const property of properties) {
|
|
597
|
+
if (!isIdentifier(property.name)) continue;
|
|
598
|
+
const fieldName = property.name.text;
|
|
599
|
+
const fieldLocation = locationOf(sourceFile, property);
|
|
600
|
+
if (property.type === void 0) {
|
|
601
|
+
context.diagnostics.push({
|
|
602
|
+
code: "unsupported-return-type",
|
|
603
|
+
title: "Unsupported field type.",
|
|
604
|
+
controllerName: context.resolverName,
|
|
605
|
+
memberName: context.methodName,
|
|
606
|
+
detail: `Field "${fieldName}" on "${typeName}" needs an explicit type annotation.`,
|
|
607
|
+
filePath,
|
|
608
|
+
line: fieldLocation.line,
|
|
609
|
+
column: fieldLocation.column
|
|
610
|
+
});
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
const unwrapped = unwrapTypeNode(property.type);
|
|
614
|
+
if (unwrapped === void 0) {
|
|
615
|
+
context.diagnostics.push({
|
|
616
|
+
code: "unsupported-return-type",
|
|
617
|
+
title: "Unsupported field type.",
|
|
618
|
+
controllerName: context.resolverName,
|
|
619
|
+
memberName: context.methodName,
|
|
620
|
+
detail: `Field "${fieldName}" on "${typeName}" has a type NestBridge cannot statically resolve.`,
|
|
621
|
+
found: property.type.getText(),
|
|
622
|
+
filePath,
|
|
623
|
+
line: fieldLocation.line,
|
|
624
|
+
column: fieldLocation.column
|
|
625
|
+
});
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
if (PRIMITIVE_SCALAR_NAMES$1.has(unwrapped.identifierText)) {
|
|
629
|
+
fields.push({ name: fieldName });
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
const resolved = resolveClassDeclaration(unwrapped.identifierText, sourceFile, filePath);
|
|
633
|
+
if (resolved === void 0) {
|
|
634
|
+
fields.push({ name: fieldName });
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
if (findDecorator(resolved.classDeclaration, "ObjectType") === void 0) {
|
|
638
|
+
context.diagnostics.push({
|
|
639
|
+
code: "unsupported-return-type",
|
|
640
|
+
title: "Unsupported field type.",
|
|
641
|
+
controllerName: context.resolverName,
|
|
642
|
+
memberName: context.methodName,
|
|
643
|
+
detail: `Field "${fieldName}" on "${typeName}" resolves to class "${unwrapped.identifierText}", which is not decorated with @ObjectType(). NestBridge cannot build a GraphQL selection set for it.`,
|
|
644
|
+
filePath,
|
|
645
|
+
line: fieldLocation.line,
|
|
646
|
+
column: fieldLocation.column
|
|
647
|
+
});
|
|
648
|
+
return;
|
|
649
|
+
}
|
|
650
|
+
const children = extractSelectionFields(resolved.classDeclaration, resolved.sourceFile, resolved.filePath, {
|
|
651
|
+
...context,
|
|
652
|
+
visitedTypeNames: nextVisited
|
|
653
|
+
});
|
|
654
|
+
if (children === void 0) return;
|
|
655
|
+
fields.push({
|
|
656
|
+
name: fieldName,
|
|
657
|
+
children
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
return fields;
|
|
661
|
+
};
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region src/analysis/read-graphql-operation-name.ts
|
|
664
|
+
var readNameFromOptions = (optionsArgument) => {
|
|
665
|
+
const nameProperty = optionsArgument.properties.find((property) => isPropertyAssignment(property) && isIdentifier(property.name) && property.name.text === "name");
|
|
666
|
+
if (nameProperty === void 0 || !isStringLiteralLikeNode(nameProperty.initializer)) return;
|
|
667
|
+
return nameProperty.initializer.text;
|
|
668
|
+
};
|
|
669
|
+
var readGraphqlOperationName = (decorator) => {
|
|
670
|
+
const expression = decorator.expression;
|
|
671
|
+
if (!isCallExpression(expression)) return {
|
|
672
|
+
ok: true,
|
|
673
|
+
value: void 0
|
|
674
|
+
};
|
|
675
|
+
let value;
|
|
676
|
+
for (const argument of expression.arguments) {
|
|
677
|
+
if (isArrowFunction(argument) || isFunctionExpression(argument)) continue;
|
|
678
|
+
if (isStringLiteralLikeNode(argument)) {
|
|
679
|
+
value = argument.text;
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
if (isObjectLiteralExpression(argument)) {
|
|
683
|
+
value = readNameFromOptions(argument) ?? value;
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
return {
|
|
687
|
+
ok: false,
|
|
688
|
+
argumentText: argument.getText()
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
return {
|
|
692
|
+
ok: true,
|
|
693
|
+
value
|
|
694
|
+
};
|
|
695
|
+
};
|
|
696
|
+
//#endregion
|
|
697
|
+
//#region src/analysis/read-graphql-return-type-option.ts
|
|
698
|
+
var readGraphqlReturnTypeOption = (decorator) => {
|
|
699
|
+
if (!isCallExpression(decorator.expression)) return;
|
|
700
|
+
const thunk = decorator.expression.arguments.find((argument) => isArrowFunction(argument) || isFunctionExpression(argument));
|
|
701
|
+
if (thunk === void 0) return;
|
|
702
|
+
const returnedExpression = readTypeThunkExpression(thunk);
|
|
703
|
+
if (returnedExpression === void 0) return;
|
|
704
|
+
if (isArrayLiteralExpression(returnedExpression)) {
|
|
705
|
+
const element = returnedExpression.elements[0];
|
|
706
|
+
return element !== void 0 && isIdentifier(element) ? element.text : void 0;
|
|
707
|
+
}
|
|
708
|
+
return isIdentifier(returnedExpression) ? returnedExpression.text : void 0;
|
|
709
|
+
};
|
|
710
|
+
//#endregion
|
|
711
|
+
//#region src/analysis/extract-resolver-method-definition.ts
|
|
712
|
+
var PRIMITIVE_SCALAR_NAMES = /* @__PURE__ */ new Set([
|
|
713
|
+
"string",
|
|
714
|
+
"number",
|
|
715
|
+
"boolean"
|
|
716
|
+
]);
|
|
717
|
+
var extractResolverMethodDefinition = (method, context) => {
|
|
718
|
+
const decorator = findAnyDecorator(method, Object.keys(GRAPHQL_OPERATION_DECORATOR_NAMES));
|
|
719
|
+
if (decorator === void 0) return;
|
|
720
|
+
const methodName = method.name.getText();
|
|
721
|
+
const decoratorName = decoratorNameOf(decorator);
|
|
722
|
+
const location = locationOf(context.sourceFile, method);
|
|
723
|
+
if (decoratorName === void 0) return;
|
|
724
|
+
const operationKind = GRAPHQL_OPERATION_DECORATOR_NAMES[decoratorName];
|
|
725
|
+
if (operationKind === void 0) return;
|
|
726
|
+
const nameArgument = readGraphqlOperationName(decorator);
|
|
727
|
+
if (!nameArgument.ok) {
|
|
728
|
+
context.diagnostics.push({
|
|
729
|
+
code: "unsupported-route",
|
|
730
|
+
title: "Unsupported operation name.",
|
|
731
|
+
controllerName: context.resolverName,
|
|
732
|
+
memberName: methodName,
|
|
733
|
+
detail: "GraphQL operation names must be statically analyzable string literals.",
|
|
734
|
+
found: `@${decoratorName}(${nameArgument.argumentText})`,
|
|
735
|
+
filePath: context.filePath,
|
|
736
|
+
line: location.line,
|
|
737
|
+
column: location.column
|
|
738
|
+
});
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
const decoratorReturnType = readGraphqlReturnTypeOption(decorator);
|
|
742
|
+
const identifierText = decoratorReturnType ?? (method.type === void 0 ? void 0 : unwrapTypeNode(method.type)?.identifierText);
|
|
743
|
+
if (identifierText === void 0) {
|
|
744
|
+
context.diagnostics.push({
|
|
745
|
+
code: "unsupported-return-type",
|
|
746
|
+
title: "Unsupported return type.",
|
|
747
|
+
controllerName: context.resolverName,
|
|
748
|
+
memberName: methodName,
|
|
749
|
+
detail: "GraphQL resolver methods need a type thunk on @Query()/@Mutation() (e.g. \"() => UserType\") or an explicit return type annotation so NestBridge can build a selection set.",
|
|
750
|
+
filePath: context.filePath,
|
|
751
|
+
line: location.line,
|
|
752
|
+
column: location.column
|
|
753
|
+
});
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
let selection = [];
|
|
757
|
+
if (!PRIMITIVE_SCALAR_NAMES.has(identifierText.toLowerCase())) {
|
|
758
|
+
const resolved = resolveClassDeclaration(identifierText, context.sourceFile, context.filePath);
|
|
759
|
+
if (resolved === void 0 && decoratorReturnType === void 0) {
|
|
760
|
+
context.diagnostics.push({
|
|
761
|
+
code: "unsupported-return-type",
|
|
762
|
+
title: "Unsupported return type.",
|
|
763
|
+
controllerName: context.resolverName,
|
|
764
|
+
memberName: methodName,
|
|
765
|
+
detail: `NestBridge could not locate the declaration of type "${identifierText}".`,
|
|
766
|
+
filePath: context.filePath,
|
|
767
|
+
line: location.line,
|
|
768
|
+
column: location.column
|
|
769
|
+
});
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
if (resolved !== void 0) {
|
|
773
|
+
const fields = extractSelectionFields(resolved.classDeclaration, resolved.sourceFile, resolved.filePath, {
|
|
774
|
+
resolverName: context.resolverName,
|
|
775
|
+
methodName,
|
|
776
|
+
diagnostics: context.diagnostics,
|
|
777
|
+
visitedTypeNames: /* @__PURE__ */ new Set()
|
|
778
|
+
});
|
|
779
|
+
if (fields === void 0) return;
|
|
780
|
+
selection = fields;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const args = method.parameters.map((parameter, index) => extractResolverArgumentDefinition(parameter, index, {
|
|
784
|
+
sourceFile: context.sourceFile,
|
|
785
|
+
filePath: context.filePath,
|
|
786
|
+
resolverName: context.resolverName,
|
|
787
|
+
methodName,
|
|
788
|
+
diagnostics: context.diagnostics
|
|
789
|
+
}));
|
|
790
|
+
if (args.some((argument) => argument === void 0)) return;
|
|
791
|
+
return {
|
|
792
|
+
name: methodName,
|
|
793
|
+
operationKind,
|
|
794
|
+
operationName: nameArgument.value ?? methodName,
|
|
795
|
+
arguments: args.filter((argument) => argument !== void 0),
|
|
796
|
+
selection,
|
|
797
|
+
line: location.line,
|
|
798
|
+
column: location.column
|
|
799
|
+
};
|
|
800
|
+
};
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region src/analysis/extract-resolver-definition.ts
|
|
803
|
+
var extractResolverDefinition = (classDeclaration, sourceFile, filePath, diagnostics) => {
|
|
804
|
+
const resolverName = classDeclaration.name?.text ?? "(anonymous resolver)";
|
|
805
|
+
return {
|
|
806
|
+
name: resolverName,
|
|
807
|
+
sourceFile: filePath,
|
|
808
|
+
methods: classDeclaration.members.filter((member) => isMethodDeclaration(member)).map((method) => extractResolverMethodDefinition(method, {
|
|
809
|
+
sourceFile,
|
|
810
|
+
filePath,
|
|
811
|
+
resolverName,
|
|
812
|
+
diagnostics
|
|
813
|
+
})).filter((method) => method !== void 0)
|
|
814
|
+
};
|
|
815
|
+
};
|
|
816
|
+
//#endregion
|
|
817
|
+
//#region src/analysis/find-resolver-classes.ts
|
|
818
|
+
var findResolverClasses = (sourceFile) => {
|
|
819
|
+
return sourceFile.statements.filter((statement) => isClassDeclaration(statement) && findDecorator(statement, "Resolver") !== void 0);
|
|
820
|
+
};
|
|
821
|
+
//#endregion
|
|
822
|
+
//#region src/analysis/analyze-resolvers.ts
|
|
823
|
+
var analyzeResolvers = (filePaths) => {
|
|
824
|
+
const diagnostics = [];
|
|
825
|
+
const resolvers = [];
|
|
826
|
+
for (const filePath of filePaths) {
|
|
827
|
+
const sourceFile = parseSourceFile(filePath);
|
|
828
|
+
for (const classDeclaration of findResolverClasses(sourceFile)) {
|
|
829
|
+
const resolver = extractResolverDefinition(classDeclaration, sourceFile, filePath, diagnostics);
|
|
830
|
+
if (resolver !== void 0) resolvers.push(resolver);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
return {
|
|
834
|
+
resolvers,
|
|
835
|
+
diagnostics
|
|
836
|
+
};
|
|
837
|
+
};
|
|
838
|
+
//#endregion
|
|
839
|
+
//#region src/declarations/generate-controller-declaration.ts
|
|
840
|
+
var REMOTE_RESULT_HELPERS = {
|
|
841
|
+
json: "RemoteResult",
|
|
842
|
+
observable: "RemoteObservableResult",
|
|
843
|
+
stream: "RemoteStreamResult"
|
|
844
|
+
};
|
|
845
|
+
var toPosixPath = (filePath) => filePath.replace(/\\/g, "/");
|
|
846
|
+
var importSpecifierFor = (sourceFile, outputFilePath) => {
|
|
847
|
+
if (!sourceFile.startsWith(".") && !/^[A-Za-z]:[\\/]/.test(sourceFile) && !sourceFile.startsWith("/")) return sourceFile;
|
|
848
|
+
const relativePath = toPosixPath(relative(dirname(outputFilePath), sourceFile));
|
|
849
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
850
|
+
};
|
|
851
|
+
var stripExtension = (filePath) => {
|
|
852
|
+
const extension = extname(filePath);
|
|
853
|
+
return extension.length > 0 ? filePath.slice(0, -extension.length) : filePath;
|
|
854
|
+
};
|
|
855
|
+
var generateControllerDeclaration = (controller, outputFilePath) => {
|
|
856
|
+
const sourceFileSpecifier = importSpecifierFor(controller.sourceFile, outputFilePath);
|
|
857
|
+
const importSpecifier = stripExtension(sourceFileSpecifier);
|
|
858
|
+
const serverAlias = `__Server${controller.name}`;
|
|
859
|
+
const classBody = [
|
|
860
|
+
" constructor();",
|
|
861
|
+
"",
|
|
862
|
+
...controller.methods.map((method) => {
|
|
863
|
+
const helperName = REMOTE_RESULT_HELPERS[method.responseKind ?? "json"];
|
|
864
|
+
return ` ${method.name}(...args: Parameters<${serverAlias}['${method.name}']>): ${helperName}<${serverAlias}['${method.name}']>;`;
|
|
865
|
+
})
|
|
866
|
+
].join("\n");
|
|
867
|
+
const usedHelperNames = new Set(controller.methods.map((method) => REMOTE_RESULT_HELPERS[method.responseKind ?? "json"]));
|
|
868
|
+
const helperImports = Array.from(usedHelperNames.size > 0 ? usedHelperNames : ["RemoteResult"]).sort();
|
|
869
|
+
return [
|
|
870
|
+
`import type { ${controller.name} as ${serverAlias} } from '${importSpecifier}';`,
|
|
871
|
+
`import type { ${helperImports.join(", ")} } from 'nestbridge';`,
|
|
872
|
+
"",
|
|
873
|
+
"/**",
|
|
874
|
+
" * Generated by NestBridge — client-facing methods only.",
|
|
875
|
+
` * @see {@link ${sourceFileSpecifier}} for the real controller implementation.`,
|
|
876
|
+
" */",
|
|
877
|
+
`export declare class ${controller.name} {`,
|
|
878
|
+
classBody,
|
|
879
|
+
"}",
|
|
880
|
+
""
|
|
881
|
+
].join("\n");
|
|
882
|
+
};
|
|
883
|
+
//#endregion
|
|
884
|
+
//#region src/diagnostics/format-diagnostic.ts
|
|
885
|
+
var formatDiagnostic = (diagnostic) => {
|
|
886
|
+
const subject = diagnostic.memberName.length > 0 ? `${diagnostic.controllerName}.${diagnostic.memberName}` : diagnostic.controllerName;
|
|
887
|
+
const lines = [
|
|
888
|
+
`[NestBridge] ${diagnostic.title}`,
|
|
889
|
+
"",
|
|
890
|
+
subject,
|
|
891
|
+
"",
|
|
892
|
+
diagnostic.detail
|
|
893
|
+
];
|
|
894
|
+
if (diagnostic.found !== void 0) lines.push("", "Found:", diagnostic.found);
|
|
895
|
+
if (diagnostic.expected !== void 0) lines.push("", "Expected:", diagnostic.expected);
|
|
896
|
+
lines.push("", `${diagnostic.filePath}:${diagnostic.line}:${diagnostic.column}`);
|
|
897
|
+
return lines.join("\n");
|
|
898
|
+
};
|
|
899
|
+
//#endregion
|
|
900
|
+
//#region src/diagnostics/nestbridge-diagnostic-error.ts
|
|
901
|
+
var NestBridgeDiagnosticError = class extends Error {
|
|
902
|
+
diagnostic;
|
|
903
|
+
constructor(diagnostic) {
|
|
904
|
+
super(formatDiagnostic(diagnostic));
|
|
905
|
+
this.name = "NestBridgeDiagnosticError";
|
|
906
|
+
this.diagnostic = diagnostic;
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
//#endregion
|
|
910
|
+
//#region src/version.ts
|
|
911
|
+
var VERSION = "1.1.1";
|
|
912
|
+
//#endregion
|
|
957
913
|
export { NestBridgeDiagnosticError, VERSION, analyzeControllers, analyzeResolvers, formatDiagnostic, generateControllerDeclaration };
|
|
958
|
-
|
|
914
|
+
|
|
915
|
+
//# sourceMappingURL=nestbridge.core.js.map
|