mushroom-cli 1.2.0-alpha.8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +199 -154
- package/dist/check-update.js +6 -0
- package/dist/common.js +280 -0
- package/dist/config.js +394 -0
- package/dist/docs/bootstrap-theme.min.css +6 -0
- package/dist/docs/bootstrap.min.css +6 -0
- package/dist/docs/bootstrap.min.js +7 -0
- package/dist/docs/doc-mt.js +633 -0
- package/dist/docs/docs.html +5380 -0
- package/{docs → dist/docs}/docs.v2.html +5205 -6615
- package/dist/docs/docs.v2.js +2036 -0
- package/dist/docs/jquery.min.js +4 -0
- package/dist/docs/mt-dom-1.0.js +1398 -0
- package/dist/docs/mt.extension.js +199 -0
- package/dist/gen/gen-api-docs-v1.js +110 -0
- package/dist/gen/gen-api-docs.js +327 -0
- package/{gen → dist/gen}/gen-csharp.js +1256 -1399
- package/{gen → dist/gen}/gen-db-docs.js +204 -222
- package/{gen → dist/gen}/gen-js-driver-tarball.js +81 -101
- package/{gen → dist/gen}/gen-js-driver.js +116 -133
- package/dist/gen/gen-ts-driver.js +600 -0
- package/{gen.js → dist/gen.js} +109 -124
- package/{help.js → dist/help.js} +53 -55
- package/dist/init/init-json.js +92 -0
- package/dist/init/init-netcore.js +30 -0
- package/dist/init.js +23 -0
- package/dist/master-file/master-file.js +185 -0
- package/dist/merge.js +70 -0
- package/dist/mr.js +77 -0
- package/dist/types.js +1 -0
- package/dist/update/tsCode.js +82 -0
- package/dist/update.js +20 -0
- package/package.json +64 -28
- package/check-update.js +0 -9
- package/common.js +0 -273
- package/config.js +0 -445
- package/docs/doc-mt.js +0 -523
- package/docs/docs.html +0 -5190
- package/docs/mt-dom-1.0.js +0 -1268
- package/docs/mt.extension.js +0 -174
- package/gen/gen-api-docs-v1.js +0 -125
- package/gen/gen-api-docs.js +0 -259
- package/gen/gen-ts-driver.js +0 -471
- package/init/init-json.js +0 -106
- package/init/init-netcore.js +0 -32
- package/init.js +0 -28
- package/master-file/master-file.js +0 -234
- package/merge.js +0 -84
- package/mr.js +0 -86
- package/update/tsCode.js +0 -20
- package/update.js +0 -24
|
@@ -1,1399 +1,1256 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
// ReSharper disable
|
|
12
|
-
// ReSharper disable
|
|
13
|
-
// ReSharper disable
|
|
14
|
-
// ReSharper disable
|
|
15
|
-
// ReSharper disable
|
|
16
|
-
// ReSharper disable
|
|
17
|
-
// ReSharper disable
|
|
18
|
-
// ReSharper disable
|
|
19
|
-
// ReSharper disable
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
case
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
case
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return
|
|
88
|
-
case
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (!
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
strEnumClasses += `
|
|
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
|
-
if (field.items
|
|
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
|
-
if (field.items.type ===
|
|
235
|
-
content +=
|
|
236
|
-
}
|
|
237
|
-
if (field.items.type ===
|
|
238
|
-
content +=
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
content += ` public ${type} ${propertyName} { get; set; }
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
out.strEnumClasses
|
|
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
|
-
public static
|
|
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
|
-
type
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
{
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
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
|
-
if (
|
|
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
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
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
|
-
const
|
|
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
|
-
const
|
|
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
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
}
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
public
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
`;
|
|
1103
|
-
break;
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
`;
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
`;
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
{
|
|
1131
|
-
return
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
`;
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
{
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
entity.views[viewName].forEach(view => {
|
|
1258
|
-
let role = view.grant === "*" ? "" : `_${toCSharpName(view.grant)}`;
|
|
1259
|
-
let hasParameter = view.parameters && view.parameters.length;
|
|
1260
|
-
if (hasParameter) {
|
|
1261
|
-
codeExtraClasses += ` public System.Threading.Tasks.Task<System.Collections.Generic.List<${className}View_${viewMethodName}Result>> ${viewMethodName}(${className}View${role}_${viewMethodName}Arg arg)
|
|
1262
|
-
{
|
|
1263
|
-
return InternalExecuteView<${className}View_${viewMethodName}Result>(new MushroomDriver.ViewArg<${className}View${role}_${viewMethodName}Arg> {
|
|
1264
|
-
Parameters = arg,
|
|
1265
|
-
Resource = FnResource?.Invoke(),
|
|
1266
|
-
ViewName = "${viewName}"
|
|
1267
|
-
});
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
`;
|
|
1271
|
-
viewExtraClass += ` ${accessModifier} partial class ${className}View${role}_${viewMethodName}Arg
|
|
1272
|
-
{
|
|
1273
|
-
`;
|
|
1274
|
-
view.parameters.forEach(p => {
|
|
1275
|
-
var type = getCSharpTypeFromMushroomType(source, p.type, p.validation && p.validation.required);
|
|
1276
|
-
if (p.isArray)
|
|
1277
|
-
type = `System.Collections.Generic.List<${type}>`;
|
|
1278
|
-
viewExtraClass += ` [Newtonsoft.Json.JsonProperty(PropertyName = "${p.field}")]
|
|
1279
|
-
public ${type} ${toCSharpName(p.field)} { get; set; }
|
|
1280
|
-
|
|
1281
|
-
`;
|
|
1282
|
-
});
|
|
1283
|
-
viewExtraClass += ` }
|
|
1284
|
-
|
|
1285
|
-
`;
|
|
1286
|
-
}
|
|
1287
|
-
else if (!hasNoParamView) {
|
|
1288
|
-
hasNoParamView = true;
|
|
1289
|
-
codeExtraClasses += ` public System.Threading.Tasks.Task<System.Collections.Generic.List<${className}View_${viewMethodName}Result>> ${viewMethodName}()
|
|
1290
|
-
{
|
|
1291
|
-
return InternalExecuteView<${className}View_${viewMethodName}Result>(new MushroomDriver.ViewArg {
|
|
1292
|
-
Resource = FnResource?.Invoke(),
|
|
1293
|
-
ViewName = "${viewName}"
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
`;
|
|
1298
|
-
}
|
|
1299
|
-
});
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
viewExtraClass += ` ${accessModifier} partial class ${className}View_${viewMethodName}Result
|
|
1303
|
-
{
|
|
1304
|
-
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
`;
|
|
1308
|
-
}
|
|
1309
|
-
codeExtraClasses += ` }
|
|
1310
|
-
|
|
1311
|
-
${viewExtraClass}`;
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
codeConnectors += " }" + newLine + newLine;
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
if (out.strEnumClasses)
|
|
1318
|
-
strEnumClasses += out.strEnumClasses;
|
|
1319
|
-
|
|
1320
|
-
const code = `// This file was generated by Mushroom CLI ${package.version} (https://www.npmjs.com/package/mushroom-cli), please do not modify
|
|
1321
|
-
|
|
1322
|
-
// Require package: Mushroom.Driver version 1.4.0 or later (https://www.nuget.org/packages/Mushroom.Driver/)
|
|
1323
|
-
|
|
1324
|
-
// ReSharper disable InconsistentNaming
|
|
1325
|
-
// ReSharper disable PartialTypeWithSinglePart
|
|
1326
|
-
// ReSharper disable PartialMethodWithSinglePart
|
|
1327
|
-
// ReSharper disable UnusedMember.Global
|
|
1328
|
-
// ReSharper disable UnusedMember.Local
|
|
1329
|
-
// ReSharper disable IdentifierTypo
|
|
1330
|
-
// ReSharper disable StringLiteralTypo
|
|
1331
|
-
// ReSharper disable CommentTypo
|
|
1332
|
-
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute;
|
|
1336
|
-
using NullValueHandling = Newtonsoft.Json.NullValueHandling;
|
|
1337
|
-
using ${namespace}.Resources;
|
|
1338
|
-
|
|
1339
|
-
namespace ${namespace}
|
|
1340
|
-
{
|
|
1341
|
-
${accessModifier} partial class API
|
|
1342
|
-
{
|
|
1343
|
-
static API()
|
|
1344
|
-
{
|
|
1345
|
-
CustomizeRootApiUrl();
|
|
1346
|
-
var client = new MushroomDriver.MushroomClient(_rootApiUrl);
|
|
1347
|
-
MushroomClient = client;
|
|
1348
|
-
|
|
1349
|
-
${Array.isArray(aliasProject.features) && aliasProject.features.indexOf("auth") !== -1 ? "Authentication = new MushroomDriver.Auth.Authentication(_rootApiUrl);" : ""}
|
|
1350
|
-
${Array.isArray(aliasProject.features) && aliasProject.features.indexOf("file") !== -1 ? "FileExtension = new MushroomDriver.File.FileExtension(_rootApiUrl);" : ""}
|
|
1351
|
-
|
|
1352
|
-
${codeStaticCtor}
|
|
1353
|
-
}
|
|
1354
|
-
|
|
1355
|
-
static partial void CustomizeRootApiUrl();
|
|
1356
|
-
|
|
1357
|
-
private static string _rootApiUrl = ${JSON.stringify(common.getRootUrl(source))};
|
|
1358
|
-
|
|
1359
|
-
public static MushroomDriver.MushroomClient MushroomClient { get; }
|
|
1360
|
-
|
|
1361
|
-
${Array.isArray(aliasProject.features) && aliasProject.features.indexOf("auth") !== -1 ? "public static MushroomDriver.Auth.Authentication Authentication { get; }" : ""}
|
|
1362
|
-
|
|
1363
|
-
${Array.isArray(aliasProject.features) && aliasProject.features.indexOf("file") !== -1 ? "public static MushroomDriver.File.FileExtension FileExtension { get; }" : ""}
|
|
1364
|
-
|
|
1365
|
-
${codeStaticProperties}
|
|
1366
|
-
}
|
|
1367
|
-
|
|
1368
|
-
/*${accessModifier} partial class API
|
|
1369
|
-
{
|
|
1370
|
-
static partial void CustomizeRootApiUrl()
|
|
1371
|
-
{
|
|
1372
|
-
_rootApiUrl = "your customized root api url";
|
|
1373
|
-
}
|
|
1374
|
-
}*/
|
|
1375
|
-
|
|
1376
|
-
${codeConnectors}${codeExtraClasses}
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
namespace ${namespace}.Resources
|
|
1380
|
-
{
|
|
1381
|
-
${strClasses}
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
|
-
namespace ${namespace}.Enums
|
|
1385
|
-
{
|
|
1386
|
-
${strEnumClasses}
|
|
1387
|
-
}`;
|
|
1388
|
-
|
|
1389
|
-
common.ensureFolder(aliasProject.output);
|
|
1390
|
-
|
|
1391
|
-
fs.writeFileSync(aliasProject.output, code);
|
|
1392
|
-
console.log(`Generated CSharp Driver for ${projectName}@${alias} to ${aliasProject.output}`);
|
|
1393
|
-
}
|
|
1394
|
-
//#endregion
|
|
1395
|
-
|
|
1396
|
-
module.exports = {
|
|
1397
|
-
genCSharpMongoDbClasses: genCSharpMongoDbClasses,
|
|
1398
|
-
genCSharpDriver: genCSharpDriver
|
|
1399
|
-
};
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import * as common from '../common.js';
|
|
3
|
+
const packageVersion = common.getPackageVersion();
|
|
4
|
+
const newLine = '\n';
|
|
5
|
+
const header = `// NOTE: Please do not modify this file
|
|
6
|
+
// NOTE: Version and compatibility information: please see in Info.cs file
|
|
7
|
+
|
|
8
|
+
// ReSharper disable CheckNamespace
|
|
9
|
+
// ReSharper disable CommentTypo
|
|
10
|
+
// ReSharper disable EmptyNamespace
|
|
11
|
+
// ReSharper disable IdentifierTypo
|
|
12
|
+
// ReSharper disable InconsistentNaming
|
|
13
|
+
// ReSharper disable PartialTypeWithSinglePart
|
|
14
|
+
// ReSharper disable RedundantUsingDirective
|
|
15
|
+
// ReSharper disable StringLiteralTypo
|
|
16
|
+
// ReSharper disable UnusedMember.Global
|
|
17
|
+
// ReSharper disable UnusedMember.Local
|
|
18
|
+
// ReSharper disable UnusedParameter.Local
|
|
19
|
+
// ReSharper disable UnusedTypeParameter
|
|
20
|
+
`;
|
|
21
|
+
function singleLine(str) {
|
|
22
|
+
if (!str)
|
|
23
|
+
return '';
|
|
24
|
+
return str.replace(/\r/g, '').replace(/\n/g, '<br/>');
|
|
25
|
+
}
|
|
26
|
+
function toVietnameseNonTongue(str) {
|
|
27
|
+
const signText = 'ăâđêôơưàảãạáằẳẵặắầẩẫậấèẻẽẹéềểễệếìỉĩịíòỏõọóồổỗộốờởỡợớùủũụúừửữựứỳỷỹỵýĂÂĐÐÊÔƠƯÀẢÃẠÁẰẲẴẶẮẦẨẪẬẤÈẺẼẸÉỀỂỄỆẾÌỈĨỊÍÒỎÕỌÓỒỔỖỘỐỜỞỠỢỚÙỦŨỤÚỪỬỮỰỨỲỶỸỴÝ';
|
|
28
|
+
const unsignedText = 'aadeoouaaaaaaaaaaaaaaaeeeeeeeeeeiiiiiooooooooooooooouuuuuuuuuuyyyyyAADDEOOUAAAAAAAAAAAAAAAEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOUUUUUUUUUUYYYYY';
|
|
29
|
+
let returnValue = '';
|
|
30
|
+
for (let i = 0; i < str.length; i++) {
|
|
31
|
+
const index = signText.indexOf(str.charAt(i));
|
|
32
|
+
returnValue += index !== -1 ? unsignedText.charAt(index) : str.charAt(i);
|
|
33
|
+
}
|
|
34
|
+
return returnValue;
|
|
35
|
+
}
|
|
36
|
+
function toCSharpName(str) {
|
|
37
|
+
if (!str)
|
|
38
|
+
return '_';
|
|
39
|
+
const name = toVietnameseNonTongue(str).replace(/\W/g, '_');
|
|
40
|
+
const c = name.charAt(0);
|
|
41
|
+
return ('0' <= c && c <= '9' ? '_' : '') + c.toUpperCase() + name.substring(1);
|
|
42
|
+
}
|
|
43
|
+
function getCSharpTypeFromMushroomType(source, type, required) {
|
|
44
|
+
switch (type) {
|
|
45
|
+
case 'string':
|
|
46
|
+
return 'string';
|
|
47
|
+
case 'object':
|
|
48
|
+
return '';
|
|
49
|
+
case 'boolean':
|
|
50
|
+
return required ? 'bool' : 'bool?';
|
|
51
|
+
case 'integer':
|
|
52
|
+
return required ? 'int' : 'int?';
|
|
53
|
+
case 'long':
|
|
54
|
+
return required ? 'long' : 'long?';
|
|
55
|
+
case 'double':
|
|
56
|
+
return required ? 'double' : 'double?';
|
|
57
|
+
case 'array':
|
|
58
|
+
return '';
|
|
59
|
+
case 'datetime':
|
|
60
|
+
return required ? 'System.DateTime' : 'System.DateTime?';
|
|
61
|
+
case 'IdRef':
|
|
62
|
+
case 'AutoId':
|
|
63
|
+
if (source.idType === 'ObjectId' || source.idType === 'GUID')
|
|
64
|
+
return 'string';
|
|
65
|
+
if (source.idType === 'AutoIncInt')
|
|
66
|
+
return 'int';
|
|
67
|
+
if (source.idType === 'AutoIncLong')
|
|
68
|
+
return 'long';
|
|
69
|
+
}
|
|
70
|
+
return 'UNKNOWN_TYPE';
|
|
71
|
+
}
|
|
72
|
+
function getCSharpInitValue(csType, value) {
|
|
73
|
+
switch (csType) {
|
|
74
|
+
case 'string':
|
|
75
|
+
return JSON.stringify(value);
|
|
76
|
+
case 'int':
|
|
77
|
+
return parseInt(value);
|
|
78
|
+
case 'long':
|
|
79
|
+
return parseInt(value) + 'L';
|
|
80
|
+
case 'double':
|
|
81
|
+
return Number(value);
|
|
82
|
+
case 'bool':
|
|
83
|
+
if (value === 'false')
|
|
84
|
+
return false;
|
|
85
|
+
if (value === 'true')
|
|
86
|
+
return true;
|
|
87
|
+
return 'NotABoolean';
|
|
88
|
+
case 'datetime':
|
|
89
|
+
return `System.DateTime.Parse(${JSON.stringify(value)})`;
|
|
90
|
+
default:
|
|
91
|
+
return 'UNSUPPORTED';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function generateEnumClass(source, out, field, defaultClassName) {
|
|
95
|
+
if (!out)
|
|
96
|
+
return '';
|
|
97
|
+
let strEnumClasses = '';
|
|
98
|
+
const validation = field.type === 'array' ? field.items?.validation : field.validation;
|
|
99
|
+
if (!validation)
|
|
100
|
+
return '';
|
|
101
|
+
if (!validation.validValues)
|
|
102
|
+
return '';
|
|
103
|
+
const mrType = field.type === 'array' ? field.items?.type : field.type;
|
|
104
|
+
if (!mrType) {
|
|
105
|
+
common.logWarning('Missing type', mrType, field);
|
|
106
|
+
return '';
|
|
107
|
+
}
|
|
108
|
+
if (mrType == 'object' || mrType == 'array') {
|
|
109
|
+
common.logWarning('Unsuported enum type for type', mrType, field);
|
|
110
|
+
return '';
|
|
111
|
+
}
|
|
112
|
+
const type = getCSharpTypeFromMushroomType(source, mrType, true);
|
|
113
|
+
validation.codeHint = validation.codeHint || {};
|
|
114
|
+
if (validation.validValues) {
|
|
115
|
+
validation.codeHint.validValues = validation.codeHint.validValues || {};
|
|
116
|
+
if (!validation.codeHint.validValues.disabled) {
|
|
117
|
+
const enumClassName = validation.codeHint.validValues.className || defaultClassName;
|
|
118
|
+
out.arrEnumClassNames ?? (out.arrEnumClassNames = []);
|
|
119
|
+
if (!out.arrEnumClassNames.includes(enumClassName)) {
|
|
120
|
+
out.arrEnumClassNames.push(enumClassName);
|
|
121
|
+
strEnumClasses += ` /// <summary>
|
|
122
|
+
/// ${singleLine(validation.codeHint.validValues.description || field.description)}
|
|
123
|
+
/// </summary>
|
|
124
|
+
public partial class ${enumClassName}
|
|
125
|
+
{
|
|
126
|
+
private ${enumClassName}() { }
|
|
127
|
+
|
|
128
|
+
`;
|
|
129
|
+
const enumProperties = validation.codeHint.validValues.nameMap || validation.validValues;
|
|
130
|
+
for (let i = 0; i < enumProperties.length && i < validation.validValues.length; i++) {
|
|
131
|
+
strEnumClasses += ` public const ${type} ${toCSharpName(enumProperties[i])} = ${getCSharpInitValue(type, validation.validValues[i])};
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
134
|
+
strEnumClasses += ` }
|
|
135
|
+
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return strEnumClasses;
|
|
141
|
+
}
|
|
142
|
+
function groupCSharpMethodHandlerByMethod(handlers) {
|
|
143
|
+
if (!handlers)
|
|
144
|
+
return {};
|
|
145
|
+
return handlers.reduce((prev, cur) => {
|
|
146
|
+
if (cur.method in prev) {
|
|
147
|
+
if (prev[cur.method].every((handler) => handler.source !== cur.source)) {
|
|
148
|
+
prev[cur.method].push(cur);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
prev[cur.method] = [cur];
|
|
153
|
+
}
|
|
154
|
+
return prev;
|
|
155
|
+
}, {});
|
|
156
|
+
}
|
|
157
|
+
function generateCSharpClassMongoDb(source, className, fields, isRoot, description, out) {
|
|
158
|
+
let strClasses = '';
|
|
159
|
+
let strEnumClasses = '';
|
|
160
|
+
let content = '';
|
|
161
|
+
if (description) {
|
|
162
|
+
content += ` /// <summary>
|
|
163
|
+
/// ${singleLine(description)}
|
|
164
|
+
/// </summary>
|
|
165
|
+
`;
|
|
166
|
+
}
|
|
167
|
+
let supperClass = '';
|
|
168
|
+
if (isRoot) {
|
|
169
|
+
if (!fields.id) {
|
|
170
|
+
fields.id = {
|
|
171
|
+
type: 'AutoId',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (!fields.id.type)
|
|
175
|
+
fields.id.type = 'AutoId';
|
|
176
|
+
supperClass = ' : Mushroom.Models.IResource<' + getCSharpTypeFromMushroomType(source, fields.id.type, true) + '>';
|
|
177
|
+
}
|
|
178
|
+
content += ` public partial class ${className}${supperClass}
|
|
179
|
+
{
|
|
180
|
+
`;
|
|
181
|
+
for (const fieldName in fields) {
|
|
182
|
+
const field = fields[fieldName];
|
|
183
|
+
let type;
|
|
184
|
+
const propertyName = toCSharpName(fieldName);
|
|
185
|
+
if (field.codeHint && field.codeHint.type && field.codeHint.type.csharp) {
|
|
186
|
+
type = field.codeHint.type.csharp;
|
|
187
|
+
}
|
|
188
|
+
else if (field.type === 'object') {
|
|
189
|
+
strClasses +=
|
|
190
|
+
generateCSharpClassMongoDb(source, className + '_' + propertyName, field.fields ?? {}, false, null, out) +
|
|
191
|
+
newLine;
|
|
192
|
+
type = className + '_' + propertyName;
|
|
193
|
+
}
|
|
194
|
+
else if (field.type === 'array') {
|
|
195
|
+
if (field.items?.type === 'object') {
|
|
196
|
+
strClasses +=
|
|
197
|
+
generateCSharpClassMongoDb(source, className + '_' + propertyName, field.items.fields ?? {}, false, null, out) + newLine;
|
|
198
|
+
type = `System.Collections.Generic.List<${className}_${propertyName}>`;
|
|
199
|
+
}
|
|
200
|
+
else if (field.items) {
|
|
201
|
+
type = `System.Collections.Generic.List<${getCSharpTypeFromMushroomType(source, field.items.type, field.items.validation && field.items.validation.required)}>`;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else
|
|
205
|
+
type = getCSharpTypeFromMushroomType(source, field.type, field.validation && field.validation.required);
|
|
206
|
+
content += ` /// <summary>
|
|
207
|
+
/// ${singleLine(field.description)}
|
|
208
|
+
/// </summary>
|
|
209
|
+
`;
|
|
210
|
+
if (isRoot && fieldName === 'id') {
|
|
211
|
+
content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === 'AutoId' && source.idType === 'GUID' ? '(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))' : ''}]\n`;
|
|
212
|
+
}
|
|
213
|
+
content += ` [MongoDB.Bson.Serialization.Attributes.BsonElement("${isRoot && fieldName === 'id' ? '_id' : fieldName}")]
|
|
214
|
+
[MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
|
|
215
|
+
[Newtonsoft.Json.JsonProperty(PropertyName = "${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore${type === 'System.DateTime' ? ', DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore' : ''})]
|
|
216
|
+
[System.Text.Json.Serialization.JsonPropertyName("${fieldName}")]
|
|
217
|
+
[System.Text.Json.Serialization.JsonIgnore(Condition = ${type === 'System.DateTime' ? 'System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault' : 'System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull'})]
|
|
218
|
+
`;
|
|
219
|
+
if ((field.type === 'AutoId' || field.type === 'IdRef') && source.idType === 'ObjectId') {
|
|
220
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]\n';
|
|
221
|
+
}
|
|
222
|
+
if (field.type === 'AutoId' && source.idType === 'GUID') {
|
|
223
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]\n';
|
|
224
|
+
}
|
|
225
|
+
if (field.type === 'datetime') {
|
|
226
|
+
content +=
|
|
227
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]\n';
|
|
228
|
+
}
|
|
229
|
+
if (field.type === 'array' && field.items) {
|
|
230
|
+
if ((field.items.type === 'AutoId' || field.items.type === 'IdRef') && source.idType === 'ObjectId') {
|
|
231
|
+
content +=
|
|
232
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]\n';
|
|
233
|
+
}
|
|
234
|
+
if (field.items.type === 'AutoId' && source.idType === 'GUID') {
|
|
235
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]\n';
|
|
236
|
+
}
|
|
237
|
+
if (field.items.type === 'datetime') {
|
|
238
|
+
content +=
|
|
239
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]\n';
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
content += ` public ${type} ${propertyName} { get; set; }\n\n`;
|
|
243
|
+
strEnumClasses += generateEnumClass(source, out, field, `${className.toUpperCase()}_${propertyName.toUpperCase()}_ENUM`);
|
|
244
|
+
}
|
|
245
|
+
content += ` [MongoDB.Bson.Serialization.Attributes.BsonExtraElements]
|
|
246
|
+
public System.Collections.Generic.Dictionary<string, object> Mushroom_ExtraProperties { get; set; }
|
|
247
|
+
|
|
248
|
+
}
|
|
249
|
+
`;
|
|
250
|
+
if (strEnumClasses) {
|
|
251
|
+
out.strEnumClasses ?? (out.strEnumClasses = '');
|
|
252
|
+
out.strEnumClasses += strEnumClasses;
|
|
253
|
+
}
|
|
254
|
+
return strClasses + newLine + content;
|
|
255
|
+
}
|
|
256
|
+
function getCSharpFunc(methodName, methodType) {
|
|
257
|
+
if (methodType === 'static')
|
|
258
|
+
return methodName;
|
|
259
|
+
const idx = methodName.lastIndexOf('.');
|
|
260
|
+
if (idx === -1)
|
|
261
|
+
return methodName;
|
|
262
|
+
return `new ${methodName.substring(0, idx)}()${methodName.substring(idx)}`;
|
|
263
|
+
}
|
|
264
|
+
export function genCSharpMongoDbClasses(args, projectName, project, alias, source) {
|
|
265
|
+
const aliasProject = ((project.csharpMongo || {}).alias || {})[alias];
|
|
266
|
+
if (!aliasProject) {
|
|
267
|
+
throw new Error(`Not found gen c#-mongo configuration. Please run 'npx mushroom-cli config ${projectName} gen c#-mongo OUTPUT_FILE.cs${alias === 'default' ? '' : ' alias ' + alias}' first`);
|
|
268
|
+
}
|
|
269
|
+
if (aliasProject.outputToFolder) {
|
|
270
|
+
genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProject);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const entities = common.getEntities(source, aliasProject.allowRoles, true);
|
|
274
|
+
const namespace = toCSharpName(source.name);
|
|
275
|
+
let strClasses = '';
|
|
276
|
+
let strEnumClasses = '';
|
|
277
|
+
let collectionNames = '';
|
|
278
|
+
let resourceNames = '';
|
|
279
|
+
let roleNames = '';
|
|
280
|
+
source.roles?.forEach((role) => {
|
|
281
|
+
if (!role.name)
|
|
282
|
+
return;
|
|
283
|
+
roleNames += `
|
|
284
|
+
/// <summary>
|
|
285
|
+
/// ${role.description ?? ''}
|
|
286
|
+
/// </summary>
|
|
287
|
+
public static string ${toCSharpName(role.name)} => "${role.name}";
|
|
288
|
+
`;
|
|
289
|
+
});
|
|
290
|
+
const out = {
|
|
291
|
+
strEnumClasses: '',
|
|
292
|
+
};
|
|
293
|
+
for (const entityName in entities) {
|
|
294
|
+
const className = toCSharpName(entityName);
|
|
295
|
+
collectionNames += ` public static string ${className}CollectionName => "${entities[entityName].storageName}";
|
|
296
|
+
public static IMongoCollection<Resources.${className}> ${className}Collection => GetDatabase().GetCollection<Resources.${className}>(${className}CollectionName);
|
|
297
|
+
`;
|
|
298
|
+
resourceNames += ` public static string ${className} => "${entityName}";\n`;
|
|
299
|
+
strClasses += generateCSharpClassMongoDb(source, className, entities[entityName].fields, true, entities[entityName].description, out);
|
|
300
|
+
const actions = entities[entityName].actions || {};
|
|
301
|
+
for (const actionName in actions) {
|
|
302
|
+
const action = actions[actionName];
|
|
303
|
+
if (!Array.isArray(action))
|
|
304
|
+
continue;
|
|
305
|
+
action.forEach((a) => {
|
|
306
|
+
if (!a)
|
|
307
|
+
return;
|
|
308
|
+
if (typeof a.delegator === 'string' && a.delegator.indexOf('lib:') === 0) {
|
|
309
|
+
const method = a.delegator.substring(4);
|
|
310
|
+
let type = a.codeHint && a.codeHint.delegator && a.codeHint.delegator.csharp
|
|
311
|
+
? a.codeHint.delegator.csharp.methodType
|
|
312
|
+
: null;
|
|
313
|
+
if (type !== 'non-static')
|
|
314
|
+
type = 'static';
|
|
315
|
+
out.delegators ?? (out.delegators = []);
|
|
316
|
+
out.delegators.push({
|
|
317
|
+
method: method,
|
|
318
|
+
source: `entity: ${entityName}, action: ${actionName}, grant: ${a.grant}`,
|
|
319
|
+
type: type,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
if (!a.events && !(typeof a.events === 'object'))
|
|
323
|
+
return;
|
|
324
|
+
for (const eventName in a.events) {
|
|
325
|
+
if (!Array.isArray(a.events[eventName]))
|
|
326
|
+
return;
|
|
327
|
+
a.events[eventName].forEach((ev, i) => {
|
|
328
|
+
if (typeof ev !== 'string' || ev.indexOf('lib:') !== 0)
|
|
329
|
+
return;
|
|
330
|
+
const method = ev.substring(4);
|
|
331
|
+
let type = a.codeHint &&
|
|
332
|
+
a.codeHint.events &&
|
|
333
|
+
Array.isArray(a.codeHint.events[eventName]) &&
|
|
334
|
+
a.codeHint.events[eventName][i] &&
|
|
335
|
+
a.codeHint.events[eventName][i].csharp
|
|
336
|
+
? a.codeHint.events[eventName][i].csharp.methodType
|
|
337
|
+
: null;
|
|
338
|
+
if (type !== 'non-static')
|
|
339
|
+
type = 'static';
|
|
340
|
+
out.eventHandlers ?? (out.eventHandlers = []);
|
|
341
|
+
out.eventHandlers.push({
|
|
342
|
+
method: method,
|
|
343
|
+
source: `entity: ${entityName}, action: ${actionName}, grant: ${a.grant}, event: ${eventName}`,
|
|
344
|
+
type: type,
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
const views = entities[entityName].views || {};
|
|
351
|
+
for (const viewName in views) {
|
|
352
|
+
const view = views[viewName];
|
|
353
|
+
if (!Array.isArray(view))
|
|
354
|
+
continue;
|
|
355
|
+
view.forEach((v) => {
|
|
356
|
+
if (!v)
|
|
357
|
+
return;
|
|
358
|
+
if (typeof v.query === 'string' && v.query.indexOf('lib:') === 0) {
|
|
359
|
+
const method = v.query.substring(4);
|
|
360
|
+
let type = v.codeHint && v.codeHint.query && v.codeHint.query.csharp ? v.codeHint.query.csharp.methodType : null;
|
|
361
|
+
if (type !== 'non-static')
|
|
362
|
+
type = 'static';
|
|
363
|
+
out.viewHandlers ?? (out.viewHandlers = []);
|
|
364
|
+
out.viewHandlers.push({
|
|
365
|
+
method: method,
|
|
366
|
+
source: `entity: ${entityName}, view: ${viewName}, grant: ${v.grant}`,
|
|
367
|
+
type: type,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
const channels = entities[entityName].features?.vn_text?.channels;
|
|
373
|
+
if (channels != null) {
|
|
374
|
+
channels.forEach((channel) => {
|
|
375
|
+
if (!channel.nativeBuilder ||
|
|
376
|
+
typeof channel.nativeBuilder !== 'string' ||
|
|
377
|
+
channel.nativeBuilder.indexOf('lib:') !== 0)
|
|
378
|
+
return;
|
|
379
|
+
const method = channel.nativeBuilder.substring(4);
|
|
380
|
+
let type = channel.codeHint && channel.codeHint.nativeBuilder && channel.codeHint.nativeBuilder.csharp
|
|
381
|
+
? channel.codeHint.nativeBuilder.csharp.methodType
|
|
382
|
+
: null;
|
|
383
|
+
if (type !== 'non-static')
|
|
384
|
+
type = 'static';
|
|
385
|
+
out.vnTextChannels ?? (out.vnTextChannels = []);
|
|
386
|
+
out.vnTextChannels.push({
|
|
387
|
+
method: method,
|
|
388
|
+
source: `entity: ${entityName}, feature: vn_text, channel: ${channel.name}`,
|
|
389
|
+
type: type,
|
|
390
|
+
});
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (out.strEnumClasses)
|
|
395
|
+
strEnumClasses += out.strEnumClasses;
|
|
396
|
+
const delegators = groupCSharpMethodHandlerByMethod(out.delegators);
|
|
397
|
+
const strDelegatorReferences = Object.keys(delegators)
|
|
398
|
+
.map((method) => delegators[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
399
|
+
`\n RegisterCustomMethod(${getCSharpFunc(method, delegators[method][0].type)});`)
|
|
400
|
+
.join(newLine);
|
|
401
|
+
const viewHandlers = groupCSharpMethodHandlerByMethod(out.viewHandlers);
|
|
402
|
+
const strViewHandlerReferences = Object.keys(viewHandlers)
|
|
403
|
+
.map((method) => viewHandlers[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
404
|
+
`\n RegisterCustomViewMethod(${getCSharpFunc(method, viewHandlers[method][0].type)});`)
|
|
405
|
+
.join(newLine);
|
|
406
|
+
const vnTextChannels = groupCSharpMethodHandlerByMethod(out.vnTextChannels);
|
|
407
|
+
const strVnTextChannels = Object.keys(vnTextChannels)
|
|
408
|
+
.map((method) => vnTextChannels[method].map((channel) => ` // ${channel.source}`).join(newLine) +
|
|
409
|
+
`\n RegisterCustomVnTextBuilderMethod(${getCSharpFunc(method, vnTextChannels[method][0].type)});`)
|
|
410
|
+
.join(newLine);
|
|
411
|
+
const eventHandlers = groupCSharpMethodHandlerByMethod(out.eventHandlers);
|
|
412
|
+
const strEventHandlerReferences = Object.keys(eventHandlers)
|
|
413
|
+
.map((method) => eventHandlers[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
414
|
+
`\n RegisterEvent(${getCSharpFunc(method, eventHandlers[method][0].type)});`)
|
|
415
|
+
.join(newLine);
|
|
416
|
+
const strJobReferences = Array.isArray(source.jobs)
|
|
417
|
+
? source.jobs
|
|
418
|
+
.filter((job) => job !== null &&
|
|
419
|
+
typeof job === 'object' &&
|
|
420
|
+
job.action &&
|
|
421
|
+
typeof job.action === 'string' &&
|
|
422
|
+
job.action.indexOf('lib:') === 0)
|
|
423
|
+
.map((job) => ` RegisterJob<${job.action.substring(4).split(',')[0]}>();`)
|
|
424
|
+
.join(newLine)
|
|
425
|
+
: '';
|
|
426
|
+
const code = `// This file was generated by Mushroom CLI ${packageVersion} (https://www.npmjs.com/package/mushroom-cli), please do not modify
|
|
427
|
+
|
|
428
|
+
// NOTE: Compatible with Mushroom Server version 0.2.18 or higher (https://www.nuget.org/packages/Mushroom/)
|
|
429
|
+
|
|
430
|
+
// ReSharper disable RedundantUsingDirective
|
|
431
|
+
// ReSharper disable InconsistentNaming
|
|
432
|
+
// ReSharper disable PartialTypeWithSinglePart
|
|
433
|
+
// ReSharper disable UnusedMember.Global
|
|
434
|
+
// ReSharper disable UnusedMember.Local
|
|
435
|
+
// ReSharper disable UnusedParameter.Local
|
|
436
|
+
// ReSharper disable IdentifierTypo
|
|
437
|
+
// ReSharper disable StringLiteralTypo
|
|
438
|
+
// ReSharper disable CommentTypo
|
|
439
|
+
// ReSharper disable EmptyNamespace
|
|
440
|
+
|
|
441
|
+
namespace ${namespace}
|
|
442
|
+
{
|
|
443
|
+
using MongoDB.Driver;
|
|
444
|
+
|
|
445
|
+
public static class DbConnector
|
|
446
|
+
{
|
|
447
|
+
${collectionNames}
|
|
448
|
+
public static IMongoDatabase GetDatabase() => Mushroom.MushroomDaoFactory.GetDbAdapter() as IMongoDatabase;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
public class ResourceNames
|
|
452
|
+
{
|
|
453
|
+
private ResourceNames() { }
|
|
454
|
+
|
|
455
|
+
${resourceNames}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
public class RoleNames {
|
|
459
|
+
private RoleNames() { }
|
|
460
|
+
|
|
461
|
+
${roleNames}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
namespace ${namespace}.Resources
|
|
466
|
+
{
|
|
467
|
+
${strClasses}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
namespace ${namespace}.Enums
|
|
471
|
+
{
|
|
472
|
+
${strEnumClasses}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
#if DEBUG
|
|
476
|
+
namespace ${namespace}.CodeHelper
|
|
477
|
+
{
|
|
478
|
+
class RefactorHelper
|
|
479
|
+
{
|
|
480
|
+
private RefactorHelper() { }
|
|
481
|
+
private void RegisterCustomMethod(System.Func<Mushroom.ActionArguments, System.Threading.Tasks.Task> fn) { }
|
|
482
|
+
private void RegisterCustomMethod(System.Action<Mushroom.ActionArguments> fn) { }
|
|
483
|
+
private void RegisterCustomViewMethod(System.Func<Mushroom.ViewArguments, System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<object>>> fn) { }
|
|
484
|
+
private void RegisterCustomViewMethod(System.Action<Mushroom.ViewArguments> fn) { }
|
|
485
|
+
private void RegisterCustomVnTextBuilderMethod(System.Func<System.Collections.Generic.IEnumerable<string>, System.Collections.Generic.IEnumerable<string>> fn) { }
|
|
486
|
+
private void RegisterEvent(System.Func<object, Mushroom.ActionArguments, System.Threading.Tasks.Task> fn) { }
|
|
487
|
+
private void RegisterEvent(System.Action<object, Mushroom.ActionArguments> fn) { }
|
|
488
|
+
private void RegisterJob<T>() where T : Mushroom.Job.JobBase { }
|
|
489
|
+
private void Help()
|
|
490
|
+
{
|
|
491
|
+
${strDelegatorReferences}
|
|
492
|
+
${strViewHandlerReferences}
|
|
493
|
+
${strVnTextChannels}
|
|
494
|
+
${strEventHandlerReferences}
|
|
495
|
+
${strJobReferences}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
#endif
|
|
500
|
+
`;
|
|
501
|
+
common.ensureFolder(aliasProject.output);
|
|
502
|
+
fs.writeFile(aliasProject.output, code, (err) => {
|
|
503
|
+
if (err)
|
|
504
|
+
throw err;
|
|
505
|
+
common.logInfo(`Generated CSharp MongoDb Classes for ${projectName}@${alias} to ${aliasProject.output}`);
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
function generateCSharpClassMongoDbToFolder(source, className, fields, isRoot, description, out, aliasProject) {
|
|
509
|
+
let content = '';
|
|
510
|
+
const namespace = toCSharpName(source.name);
|
|
511
|
+
if (description) {
|
|
512
|
+
content += ` /// <summary>
|
|
513
|
+
/// ${singleLine(description)}
|
|
514
|
+
/// </summary>
|
|
515
|
+
`;
|
|
516
|
+
}
|
|
517
|
+
let supperClass = '';
|
|
518
|
+
if (isRoot) {
|
|
519
|
+
if (!fields.id) {
|
|
520
|
+
fields.id = {
|
|
521
|
+
type: 'AutoId',
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
if (!fields.id.type)
|
|
525
|
+
fields.id.type = 'AutoId';
|
|
526
|
+
supperClass = ' : Mushroom.Models.IResource<' + getCSharpTypeFromMushroomType(source, fields.id.type, true) + '>';
|
|
527
|
+
}
|
|
528
|
+
content += ` public partial class ${className}${supperClass}
|
|
529
|
+
{
|
|
530
|
+
`;
|
|
531
|
+
for (const fieldName in fields) {
|
|
532
|
+
const field = fields[fieldName];
|
|
533
|
+
let type;
|
|
534
|
+
const propertyName = toCSharpName(fieldName);
|
|
535
|
+
if (field.codeHint && field.codeHint.type && field.codeHint.type.csharp) {
|
|
536
|
+
type = field.codeHint.type.csharp;
|
|
537
|
+
}
|
|
538
|
+
else if (field.type === 'object') {
|
|
539
|
+
generateCSharpClassMongoDbToFolder(source, className + '_' + propertyName, field.fields ?? {}, false, null, out, aliasProject);
|
|
540
|
+
type = className + '_' + propertyName;
|
|
541
|
+
}
|
|
542
|
+
else if (field.type === 'array') {
|
|
543
|
+
if (field.items?.type === 'object') {
|
|
544
|
+
generateCSharpClassMongoDbToFolder(source, className + '_' + propertyName, field.items.fields ?? {}, false, null, out, aliasProject);
|
|
545
|
+
type = `System.Collections.Generic.List<${className}_${propertyName}>`;
|
|
546
|
+
}
|
|
547
|
+
else if (field.items) {
|
|
548
|
+
type = `System.Collections.Generic.List<${getCSharpTypeFromMushroomType(source, field.items.type, field.items.validation && field.items.validation.required)}>`;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
else
|
|
552
|
+
type = getCSharpTypeFromMushroomType(source, field.type, field.validation && field.validation.required);
|
|
553
|
+
content += ` /// <summary>
|
|
554
|
+
/// ${singleLine(field.description)}
|
|
555
|
+
/// </summary>
|
|
556
|
+
`;
|
|
557
|
+
if (isRoot && fieldName === 'id') {
|
|
558
|
+
content += ` [MongoDB.Bson.Serialization.Attributes.BsonId${field.type === 'AutoId' && source.idType === 'GUID' ? '(IdGenerator = typeof(MongoDB.Bson.Serialization.IdGenerators.GuidGenerator))' : ''}]\n`;
|
|
559
|
+
}
|
|
560
|
+
content += ` [MongoDB.Bson.Serialization.Attributes.BsonElement("${isRoot && fieldName === 'id' ? '_id' : fieldName}")]
|
|
561
|
+
[MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
|
|
562
|
+
[Newtonsoft.Json.JsonProperty(PropertyName = "${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore${type === 'System.DateTime' ? ', DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore' : ''})]
|
|
563
|
+
[System.Text.Json.Serialization.JsonPropertyName("${fieldName}")]
|
|
564
|
+
[System.Text.Json.Serialization.JsonIgnore(Condition = ${type === 'System.DateTime' ? 'System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault' : 'System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull'})]
|
|
565
|
+
`;
|
|
566
|
+
if ((field.type === 'AutoId' || field.type === 'IdRef') && source.idType === 'ObjectId') {
|
|
567
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]\n';
|
|
568
|
+
}
|
|
569
|
+
if (field.type === 'AutoId' && source.idType === 'GUID') {
|
|
570
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]\n';
|
|
571
|
+
}
|
|
572
|
+
if (field.type === 'datetime') {
|
|
573
|
+
content +=
|
|
574
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]\n';
|
|
575
|
+
}
|
|
576
|
+
if (field.type === 'array') {
|
|
577
|
+
if ((field.items?.type === 'AutoId' || field.items?.type === 'IdRef') && source.idType === 'ObjectId') {
|
|
578
|
+
content +=
|
|
579
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]\n';
|
|
580
|
+
}
|
|
581
|
+
if (field.items?.type === 'AutoId' && source.idType === 'GUID') {
|
|
582
|
+
content += ' [MongoDB.Bson.Serialization.Attributes.BsonRepresentation(MongoDB.Bson.BsonType.String)]\n';
|
|
583
|
+
}
|
|
584
|
+
if (field.items?.type === 'datetime') {
|
|
585
|
+
content +=
|
|
586
|
+
' [MongoDB.Bson.Serialization.Attributes.BsonDateTimeOptions(Kind = System.DateTimeKind.Local)]\n';
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
content += ` public ${type} ${propertyName} { get; set; }
|
|
590
|
+
|
|
591
|
+
`;
|
|
592
|
+
let strEnumClasses = generateEnumClass(source, {}, field, `${className.toUpperCase()}_${propertyName.toUpperCase()}_ENUM`);
|
|
593
|
+
const match = strEnumClasses.match(/public partial class\s+(\w+)/);
|
|
594
|
+
if (!match)
|
|
595
|
+
continue;
|
|
596
|
+
common.ensureFolder(aliasProject.output + '/Enums', true);
|
|
597
|
+
strEnumClasses = `${header}
|
|
598
|
+
|
|
599
|
+
namespace ${namespace}.Enums
|
|
600
|
+
{
|
|
601
|
+
${strEnumClasses}
|
|
602
|
+
}
|
|
603
|
+
`;
|
|
604
|
+
fs.writeFileSync(aliasProject.output + '/Enums/' + match[1] + '.cs', strEnumClasses);
|
|
605
|
+
}
|
|
606
|
+
content += ` [MongoDB.Bson.Serialization.Attributes.BsonExtraElements]
|
|
607
|
+
[Newtonsoft.Json.JsonIgnore]
|
|
608
|
+
public System.Collections.Generic.Dictionary<string, object> Mushroom_ExtraProperties { get; set; }
|
|
609
|
+
|
|
610
|
+
}
|
|
611
|
+
`;
|
|
612
|
+
common.ensureFolder(aliasProject.output + '/Resources', true);
|
|
613
|
+
content = `${header}
|
|
614
|
+
|
|
615
|
+
namespace ${namespace}.Resources
|
|
616
|
+
{
|
|
617
|
+
${content}
|
|
618
|
+
}
|
|
619
|
+
`;
|
|
620
|
+
const normalizedName = className.toLowerCase();
|
|
621
|
+
out.allClasses ?? (out.allClasses = []);
|
|
622
|
+
const duplicate = out.allClasses.find((c) => c.normalizedName == normalizedName);
|
|
623
|
+
if (duplicate) {
|
|
624
|
+
fs.appendFileSync(aliasProject.output + '/Resources/' + duplicate.className + '.cs', content);
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
out.allClasses.push({
|
|
628
|
+
className,
|
|
629
|
+
normalizedName,
|
|
630
|
+
});
|
|
631
|
+
fs.writeFileSync(aliasProject.output + '/Resources/' + className + '.cs', content);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
function genCSharpMongoDbClassesToFolder(projectName, alias, source, aliasProject) {
|
|
635
|
+
if (fs.existsSync(aliasProject.output)) {
|
|
636
|
+
try {
|
|
637
|
+
fs.unlinkSync(aliasProject.output);
|
|
638
|
+
}
|
|
639
|
+
catch { }
|
|
640
|
+
try {
|
|
641
|
+
fs.rmSync(aliasProject.output, { recursive: true, force: true });
|
|
642
|
+
}
|
|
643
|
+
catch { }
|
|
644
|
+
}
|
|
645
|
+
fs.mkdirSync(aliasProject.output, { recursive: true, mode: 0o755 });
|
|
646
|
+
const entities = common.getEntities(source, aliasProject.allowRoles, true);
|
|
647
|
+
const namespace = toCSharpName(source.name);
|
|
648
|
+
let collectionNames = '';
|
|
649
|
+
let resourceNames = '';
|
|
650
|
+
let roleNames = '';
|
|
651
|
+
source.roles?.forEach((role) => {
|
|
652
|
+
if (!role.name)
|
|
653
|
+
return;
|
|
654
|
+
roleNames += `
|
|
655
|
+
/// <summary>
|
|
656
|
+
/// ${role.description ?? ''}
|
|
657
|
+
/// </summary>
|
|
658
|
+
public static string ${toCSharpName(role.name)} => "${role.name}";
|
|
659
|
+
`;
|
|
660
|
+
});
|
|
661
|
+
const out = {};
|
|
662
|
+
for (const entityName in entities) {
|
|
663
|
+
const className = toCSharpName(entityName);
|
|
664
|
+
collectionNames += ` public static string ${className}CollectionName => "${entities[entityName].storageName}";
|
|
665
|
+
public static IMongoCollection<Resources.${className}> ${className}Collection => GetDatabase().GetCollection<Resources.${className}>(${className}CollectionName);
|
|
666
|
+
`;
|
|
667
|
+
resourceNames += ` public static string ${className} => "${entityName}";
|
|
668
|
+
`;
|
|
669
|
+
generateCSharpClassMongoDbToFolder(source, className, entities[entityName].fields, true, entities[entityName].description, out, aliasProject);
|
|
670
|
+
const actions = entities[entityName].actions || {};
|
|
671
|
+
for (const actionName in actions) {
|
|
672
|
+
const action = actions[actionName];
|
|
673
|
+
if (!Array.isArray(action))
|
|
674
|
+
continue;
|
|
675
|
+
action.forEach((a) => {
|
|
676
|
+
if (!a)
|
|
677
|
+
return;
|
|
678
|
+
if (typeof a.delegator === 'string' && a.delegator.indexOf('lib:') === 0) {
|
|
679
|
+
const method = a.delegator.substring(4);
|
|
680
|
+
let type = a.codeHint && a.codeHint.delegator && a.codeHint.delegator.csharp
|
|
681
|
+
? a.codeHint.delegator.csharp.methodType
|
|
682
|
+
: null;
|
|
683
|
+
if (type !== 'non-static')
|
|
684
|
+
type = 'static';
|
|
685
|
+
out.delegators ?? (out.delegators = []);
|
|
686
|
+
out.delegators.push({
|
|
687
|
+
method: method,
|
|
688
|
+
source: `entity: ${entityName}, action: ${actionName}, grant: ${a.grant}`,
|
|
689
|
+
type: type,
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
if (!a.events && !(typeof a.events === 'object'))
|
|
693
|
+
return;
|
|
694
|
+
for (const eventName in a.events) {
|
|
695
|
+
if (!Array.isArray(a.events[eventName]))
|
|
696
|
+
return;
|
|
697
|
+
a.events[eventName].forEach((ev, i) => {
|
|
698
|
+
if (typeof ev !== 'string' || ev.indexOf('lib:') !== 0)
|
|
699
|
+
return;
|
|
700
|
+
const method = ev.substring(4);
|
|
701
|
+
let type = a.codeHint &&
|
|
702
|
+
a.codeHint.events &&
|
|
703
|
+
Array.isArray(a.codeHint.events[eventName]) &&
|
|
704
|
+
a.codeHint.events[eventName][i] &&
|
|
705
|
+
a.codeHint.events[eventName][i].csharp
|
|
706
|
+
? a.codeHint.events[eventName][i].csharp.methodType
|
|
707
|
+
: null;
|
|
708
|
+
if (type !== 'non-static')
|
|
709
|
+
type = 'static';
|
|
710
|
+
out.eventHandlers ?? (out.eventHandlers = []);
|
|
711
|
+
out.eventHandlers.push({
|
|
712
|
+
method: method,
|
|
713
|
+
source: `entity: ${entityName}, action: ${actionName}, grant: ${a.grant}, event: ${eventName}`,
|
|
714
|
+
type: type,
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
const views = entities[entityName].views || {};
|
|
721
|
+
for (const viewName in views) {
|
|
722
|
+
const view = views[viewName];
|
|
723
|
+
if (!Array.isArray(view))
|
|
724
|
+
continue;
|
|
725
|
+
view.forEach((v) => {
|
|
726
|
+
if (!v)
|
|
727
|
+
return;
|
|
728
|
+
if (typeof v.query === 'string' && v.query.indexOf('lib:') === 0) {
|
|
729
|
+
const method = v.query.substring(4);
|
|
730
|
+
let type = v.codeHint && v.codeHint.query && v.codeHint.query.csharp ? v.codeHint.query.csharp.methodType : null;
|
|
731
|
+
if (type !== 'non-static')
|
|
732
|
+
type = 'static';
|
|
733
|
+
out.viewHandlers ?? (out.viewHandlers = []);
|
|
734
|
+
out.viewHandlers.push({
|
|
735
|
+
method: method,
|
|
736
|
+
source: `entity: ${entityName}, view: ${viewName}, grant: ${v.grant}`,
|
|
737
|
+
type: type,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
const channels = entities[entityName].features?.vn_text?.channels;
|
|
743
|
+
if (channels != null) {
|
|
744
|
+
channels.forEach((channel) => {
|
|
745
|
+
if (!channel.nativeBuilder ||
|
|
746
|
+
typeof channel.nativeBuilder !== 'string' ||
|
|
747
|
+
channel.nativeBuilder.indexOf('lib:') !== 0)
|
|
748
|
+
return;
|
|
749
|
+
const method = channel.nativeBuilder.substring(4);
|
|
750
|
+
let type = channel.codeHint && channel.codeHint.nativeBuilder && channel.codeHint.nativeBuilder.csharp
|
|
751
|
+
? channel.codeHint.nativeBuilder.csharp.methodType
|
|
752
|
+
: null;
|
|
753
|
+
if (type !== 'non-static')
|
|
754
|
+
type = 'static';
|
|
755
|
+
out.vnTextChannels ?? (out.vnTextChannels = []);
|
|
756
|
+
out.vnTextChannels.push({
|
|
757
|
+
method: method,
|
|
758
|
+
source: `entity: ${entityName}, feature: vn_text, channel: ${channel.name}`,
|
|
759
|
+
type: type,
|
|
760
|
+
});
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
const delegators = groupCSharpMethodHandlerByMethod(out.delegators);
|
|
765
|
+
const strDelegatorReferences = Object.keys(delegators)
|
|
766
|
+
.map((method) => delegators[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
767
|
+
`\n RegisterCustomMethod(${getCSharpFunc(method, delegators[method][0].type)});`)
|
|
768
|
+
.join(newLine);
|
|
769
|
+
const viewHandlers = groupCSharpMethodHandlerByMethod(out.viewHandlers);
|
|
770
|
+
const strViewHandlerReferences = Object.keys(viewHandlers)
|
|
771
|
+
.map((method) => viewHandlers[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
772
|
+
`\n RegisterCustomViewMethod(${getCSharpFunc(method, viewHandlers[method][0].type)});`)
|
|
773
|
+
.join(newLine);
|
|
774
|
+
const vnTextChannels = groupCSharpMethodHandlerByMethod(out.vnTextChannels);
|
|
775
|
+
const strVnTextChannels = Object.keys(vnTextChannels)
|
|
776
|
+
.map((method) => vnTextChannels[method].map((channel) => ` // ${channel.source}`).join(newLine) +
|
|
777
|
+
`\n RegisterCustomVnTextBuilderMethod(${getCSharpFunc(method, vnTextChannels[method][0].type)});`)
|
|
778
|
+
.join(newLine);
|
|
779
|
+
const eventHandlers = groupCSharpMethodHandlerByMethod(out.eventHandlers);
|
|
780
|
+
const strEventHandlerReferences = Object.keys(eventHandlers)
|
|
781
|
+
.map((method) => eventHandlers[method].map((ev) => ` // ${ev.source}`).join(newLine) +
|
|
782
|
+
`\n RegisterEvent(${getCSharpFunc(method, eventHandlers[method][0].type)});`)
|
|
783
|
+
.join(newLine);
|
|
784
|
+
const strJobReferences = Array.isArray(source.jobs)
|
|
785
|
+
? source.jobs
|
|
786
|
+
.filter((job) => job !== null &&
|
|
787
|
+
typeof job === 'object' &&
|
|
788
|
+
job.action &&
|
|
789
|
+
typeof job.action === 'string' &&
|
|
790
|
+
job.action.indexOf('lib:') === 0)
|
|
791
|
+
.map((job) => ` RegisterJob<${job.action.substring(4).split(',')[0]}>();`)
|
|
792
|
+
.join(newLine)
|
|
793
|
+
: '';
|
|
794
|
+
const dbConnectorFileContent = `${header}
|
|
795
|
+
using MongoDB.Driver;
|
|
796
|
+
|
|
797
|
+
namespace ${namespace}
|
|
798
|
+
{
|
|
799
|
+
public static class DbConnector
|
|
800
|
+
{
|
|
801
|
+
${collectionNames}
|
|
802
|
+
public static IMongoDatabase GetDatabase() => Mushroom.MushroomDaoFactory.GetDbAdapter() as IMongoDatabase;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
`;
|
|
806
|
+
const resourceNamesFileContent = `${header}
|
|
807
|
+
|
|
808
|
+
namespace ${namespace}
|
|
809
|
+
{
|
|
810
|
+
public class ResourceNames
|
|
811
|
+
{
|
|
812
|
+
private ResourceNames() { }
|
|
813
|
+
|
|
814
|
+
${resourceNames}
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
`;
|
|
818
|
+
const roleNamesFileContent = `${header}
|
|
819
|
+
|
|
820
|
+
namespace ${namespace}
|
|
821
|
+
{
|
|
822
|
+
public class RoleNames
|
|
823
|
+
{
|
|
824
|
+
private RoleNames() { }
|
|
825
|
+
|
|
826
|
+
${roleNames}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
`;
|
|
830
|
+
const refactorHelperFileContent = `${header}
|
|
831
|
+
|
|
832
|
+
#if DEBUG
|
|
833
|
+
namespace ${namespace}
|
|
834
|
+
{
|
|
835
|
+
class RefactorHelper
|
|
836
|
+
{
|
|
837
|
+
private RefactorHelper() { }
|
|
838
|
+
private void RegisterCustomMethod(System.Func<Mushroom.ActionArguments, System.Threading.Tasks.Task> fn) { }
|
|
839
|
+
private void RegisterCustomMethod(System.Action<Mushroom.ActionArguments> fn) { }
|
|
840
|
+
private void RegisterCustomViewMethod(System.Func<Mushroom.ViewArguments, System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<object>>> fn) { }
|
|
841
|
+
private void RegisterCustomViewMethod(System.Action<Mushroom.ViewArguments> fn) { }
|
|
842
|
+
private void RegisterCustomVnTextBuilderMethod(System.Func<System.Collections.Generic.IEnumerable<string>, System.Collections.Generic.IEnumerable<string>> fn) { }
|
|
843
|
+
private void RegisterEvent(System.Func<object, Mushroom.ActionArguments, System.Threading.Tasks.Task> fn) { }
|
|
844
|
+
private void RegisterEvent(System.Action<object, Mushroom.ActionArguments> fn) { }
|
|
845
|
+
private void RegisterRespondingEvent(System.Func<object, Mushroom.ActionArguments, Mushroom.ActionResult, System.Threading.Tasks.Task> fn) { }
|
|
846
|
+
private void RegisterRespondingEvent(System.Action<object, Mushroom.ActionArguments, Mushroom.ActionResult> fn) { }
|
|
847
|
+
private void RegisterJob<T>() where T : Mushroom.Job.JobBase { }
|
|
848
|
+
private void Help()
|
|
849
|
+
{
|
|
850
|
+
${strDelegatorReferences}
|
|
851
|
+
${strViewHandlerReferences}
|
|
852
|
+
${strVnTextChannels}
|
|
853
|
+
${strEventHandlerReferences}
|
|
854
|
+
${strJobReferences}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
#endif
|
|
859
|
+
`;
|
|
860
|
+
const infoFileContent = `// Mushroom CLI version: ${packageVersion}
|
|
861
|
+
// Compatible with Mushroom Server version: 0.2.25.4 or higher (https://www.nuget.org/packages/Mushroom/)
|
|
862
|
+
// For Mushroom Server 0.2.18 to 0.2.25.4: Please remove all FindById methods in DbConnector.cs`;
|
|
863
|
+
fs.writeFileSync(aliasProject.output + '/DbConnector.cs', dbConnectorFileContent);
|
|
864
|
+
fs.writeFileSync(aliasProject.output + '/ResourceNames.cs', resourceNamesFileContent);
|
|
865
|
+
fs.writeFileSync(aliasProject.output + '/RoleNames.cs', roleNamesFileContent);
|
|
866
|
+
fs.writeFileSync(aliasProject.output + '/RefactorHelper.cs', refactorHelperFileContent);
|
|
867
|
+
fs.writeFileSync(aliasProject.output + '/Info.cs', infoFileContent);
|
|
868
|
+
common.logInfo(`Generated CSharp MongoDb Classes for ${projectName}@${alias} to folder ${aliasProject.output}`);
|
|
869
|
+
}
|
|
870
|
+
function generateCSharpClassDriver(source, className, fields, description, out) {
|
|
871
|
+
let strClasses = '';
|
|
872
|
+
let strEnumClasses = '';
|
|
873
|
+
let content = '';
|
|
874
|
+
if (description) {
|
|
875
|
+
content += ` /// <summary>
|
|
876
|
+
/// ${singleLine(description)}
|
|
877
|
+
/// </summary>
|
|
878
|
+
`;
|
|
879
|
+
}
|
|
880
|
+
content += ` public partial class ${className}
|
|
881
|
+
{
|
|
882
|
+
`;
|
|
883
|
+
for (const fieldName in fields) {
|
|
884
|
+
const field = fields[fieldName];
|
|
885
|
+
const propertyName = toCSharpName(fieldName);
|
|
886
|
+
let type;
|
|
887
|
+
if (field.type === 'object') {
|
|
888
|
+
strClasses +=
|
|
889
|
+
generateCSharpClassDriver(source, className + '_' + propertyName, field.fields ?? {}, null, out) + newLine;
|
|
890
|
+
type = className + '_' + propertyName;
|
|
891
|
+
}
|
|
892
|
+
else if (field.type === 'array') {
|
|
893
|
+
if (field.items?.type === 'object') {
|
|
894
|
+
strClasses +=
|
|
895
|
+
generateCSharpClassDriver(source, className + '_' + propertyName, field.items.fields ?? {}, null, out) +
|
|
896
|
+
newLine;
|
|
897
|
+
type = `System.Collections.Generic.List<${className}_${propertyName}>`;
|
|
898
|
+
}
|
|
899
|
+
else if (field.items) {
|
|
900
|
+
type = `System.Collections.Generic.List<${getCSharpTypeFromMushroomType(source, field.items.type, field.items.validation && field.items.validation.required)}>`;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
else
|
|
904
|
+
type = getCSharpTypeFromMushroomType(source, field.type, field.validation && field.validation.required);
|
|
905
|
+
content += ` /// <summary>
|
|
906
|
+
/// ${singleLine(field.description)}
|
|
907
|
+
/// </summary>
|
|
908
|
+
[Newtonsoft.Json.JsonProperty(PropertyName ="${fieldName}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore${type === 'System.Datetime' ? ', DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore' : ''})]
|
|
909
|
+
[System.Text.Json.Serialization.JsonPropertyName("${fieldName}")]
|
|
910
|
+
[System.Text.Json.Serialization.JsonIgnore(Condition = ${type === 'System.DateTime' ? 'System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault' : 'System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull'})]
|
|
911
|
+
public ${type} ${propertyName} { get; set; }
|
|
912
|
+
|
|
913
|
+
`;
|
|
914
|
+
strEnumClasses += generateEnumClass(source, out, field, `${className.toUpperCase()}_${propertyName.toUpperCase()}_ENUM`);
|
|
915
|
+
}
|
|
916
|
+
if (strEnumClasses) {
|
|
917
|
+
out.strEnumClasses ?? (out.strEnumClasses = '');
|
|
918
|
+
out.strEnumClasses += strEnumClasses;
|
|
919
|
+
}
|
|
920
|
+
content += ' }\n';
|
|
921
|
+
return strClasses + newLine + content;
|
|
922
|
+
}
|
|
923
|
+
export function genCSharpDriver(args, projectName, project, alias, source) {
|
|
924
|
+
const aliasProject = ((project.csharpDriver || {}).alias || {})[alias];
|
|
925
|
+
if (!aliasProject) {
|
|
926
|
+
throw new Error(`Not found gen c#-driver configuration. Please run 'npx mushroom-cli config ${projectName} gen c#-driver OUTPUT_FILE.cs${alias === 'default' ? '' : ' alias ' + alias}' first`);
|
|
927
|
+
}
|
|
928
|
+
const entities = common.getEntities(source, aliasProject.allowRoles);
|
|
929
|
+
const namespace = toCSharpName(source.name);
|
|
930
|
+
let strClasses = '';
|
|
931
|
+
let strEnumClasses = '';
|
|
932
|
+
let codeStaticCtor = '';
|
|
933
|
+
let codeStaticProperties = '';
|
|
934
|
+
let codeConnectors = '';
|
|
935
|
+
let codeExtraClasses = '';
|
|
936
|
+
const out = {};
|
|
937
|
+
const accessModifier = aliasProject.accessModifier || 'internal';
|
|
938
|
+
for (const entityName in entities) {
|
|
939
|
+
const className = toCSharpName(entityName);
|
|
940
|
+
strClasses += generateCSharpClassDriver(source, className, entities[entityName].fields, entities[entityName].description, out);
|
|
941
|
+
codeStaticCtor += ` ${className} = new ${className}Connector(client);\n`;
|
|
942
|
+
codeStaticProperties += ` public static ${className}Connector ${className} { get; }\n\n`;
|
|
943
|
+
const entity = entities[entityName];
|
|
944
|
+
codeConnectors += ` ${accessModifier} partial class ${className}Connector : MushroomDriver.MushroomResourceConnector<${className}>
|
|
945
|
+
{
|
|
946
|
+
protected override string Resource { get; } = ${JSON.stringify(entityName)};
|
|
947
|
+
|
|
948
|
+
`;
|
|
949
|
+
if (Object.keys(entity.views ?? {}).length) {
|
|
950
|
+
codeConnectors += ` public ${className}Connector(MushroomDriver.MushroomClient client) : base(client)
|
|
951
|
+
{
|
|
952
|
+
Views = new ${className}Views(Client, () => Resource);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
`;
|
|
956
|
+
}
|
|
957
|
+
else {
|
|
958
|
+
codeConnectors += ` public ${className}Connector(MushroomDriver.MushroomClient client) : base(client) { }
|
|
959
|
+
|
|
960
|
+
`;
|
|
961
|
+
}
|
|
962
|
+
for (const actionName in entity.actions) {
|
|
963
|
+
switch (actionName) {
|
|
964
|
+
case 'findMany':
|
|
965
|
+
codeConnectors += ` public System.Threading.Tasks.Task<System.Collections.Generic.List<${className}>> List(MushroomDriver.ListArg arg = null)
|
|
966
|
+
{
|
|
967
|
+
return InternalList(arg);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
`;
|
|
971
|
+
break;
|
|
972
|
+
case 'findById':
|
|
973
|
+
codeConnectors += ` public System.Threading.Tasks.Task<${className}> FindById(MushroomDriver.FindByIdArg arg)
|
|
974
|
+
{
|
|
975
|
+
return InternalFindById(arg);
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
`;
|
|
979
|
+
break;
|
|
980
|
+
case 'createOne':
|
|
981
|
+
codeConnectors += ` public System.Threading.Tasks.Task<string> Create(MushroomDriver.CreateArg<${className}> arg)
|
|
982
|
+
{
|
|
983
|
+
return InternalCreate(arg);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
`;
|
|
987
|
+
break;
|
|
988
|
+
case 'createMany':
|
|
989
|
+
codeConnectors += ` public System.Threading.Tasks.Task<System.Collections.Generic.List<string>> Create(MushroomDriver.BatchCreateArg<${className}> arg)
|
|
990
|
+
{
|
|
991
|
+
return InternalCreate(arg);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
`;
|
|
995
|
+
break;
|
|
996
|
+
case 'updateOne':
|
|
997
|
+
codeConnectors += ` public System.Threading.Tasks.Task<string> Update(MushroomDriver.UpdateArg<${className}> arg)
|
|
998
|
+
{
|
|
999
|
+
return InternalUpdate(arg);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
`;
|
|
1003
|
+
break;
|
|
1004
|
+
case 'updateMany':
|
|
1005
|
+
codeConnectors += ` public System.Threading.Tasks.Task<System.Collections.Generic.List<string>> Update(MushroomDriver.BatchUpdateArg<${className}> arg)
|
|
1006
|
+
{
|
|
1007
|
+
return InternalUpdate(arg);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
`;
|
|
1011
|
+
break;
|
|
1012
|
+
case 'updatePartially':
|
|
1013
|
+
codeConnectors += ` public System.Threading.Tasks.Task<string> Update(MushroomDriver.PartialUpdateArg<${className}> arg)
|
|
1014
|
+
{
|
|
1015
|
+
return InternalUpdate(arg);
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
public System.Threading.Tasks.Task<string> Update(MushroomDriver.PartialUpdateArg<System.Collections.Generic.Dictionary<string, object>> arg)
|
|
1019
|
+
{
|
|
1020
|
+
return InternalUpdate(arg);
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
`;
|
|
1024
|
+
break;
|
|
1025
|
+
case 'deleteOne':
|
|
1026
|
+
codeConnectors += ` public System.Threading.Tasks.Task<long> Delete(MushroomDriver.DeleteArg arg)
|
|
1027
|
+
{
|
|
1028
|
+
return InternalDelete(arg);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
`;
|
|
1032
|
+
break;
|
|
1033
|
+
case 'deleteMany':
|
|
1034
|
+
codeConnectors += ` public System.Threading.Tasks.Task<long> Delete(MushroomDriver.BatchDeleteArg arg)
|
|
1035
|
+
{
|
|
1036
|
+
return InternalDelete(arg);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
`;
|
|
1040
|
+
break;
|
|
1041
|
+
default: {
|
|
1042
|
+
if (actionName.indexOf('_raw_http_method_'))
|
|
1043
|
+
break;
|
|
1044
|
+
const customMethod = toCSharpName(actionName.substring('_raw_http_method_'.length));
|
|
1045
|
+
codeConnectors += ` public async System.Threading.Tasks.Task<${className}${customMethod}Result> ${customMethod}(${className}${customMethod}Arg arg)
|
|
1046
|
+
{
|
|
1047
|
+
if (arg == null)
|
|
1048
|
+
throw new System.ArgumentNullException(nameof(arg));
|
|
1049
|
+
|
|
1050
|
+
var request = new MushroomDriver.MushroomRequest
|
|
1051
|
+
{
|
|
1052
|
+
RootApiUrl = Client.RootApiUrl,
|
|
1053
|
+
Url = Client.RootApiUrl + arg.BuildUrl(),
|
|
1054
|
+
Method = arg.Method
|
|
1055
|
+
};
|
|
1056
|
+
var headers = new System.Collections.Generic.Dictionary<string, string>
|
|
1057
|
+
{
|
|
1058
|
+
{"X-Requested-With", "Mushroom Driver " + MushroomDriver.MushroomConnector.Version}
|
|
1059
|
+
};
|
|
1060
|
+
if (arg.UseXHttpMethodOverride)
|
|
1061
|
+
{
|
|
1062
|
+
headers["X-Http-Method-Override"] = request.Method;
|
|
1063
|
+
request.Method = "POST";
|
|
1064
|
+
}
|
|
1065
|
+
request.Headers = headers;
|
|
1066
|
+
request.Data = arg.CustomData ?? arg.Data;
|
|
1067
|
+
var response = await MushroomDriver.MushroomConnector.Execute(request);
|
|
1068
|
+
var result = response.GetResult<${className}${customMethod}Result>();
|
|
1069
|
+
result.MushroomResponseMetadata = response.Metadata;
|
|
1070
|
+
return result;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
`;
|
|
1074
|
+
codeExtraClasses += ` ${accessModifier} partial class ${className}${customMethod}Result
|
|
1075
|
+
{
|
|
1076
|
+
public System.Collections.Generic.Dictionary<string, object> MushroomResponseMetadata { get; set; }
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
${accessModifier} partial class ${className}${customMethod}Body { }
|
|
1080
|
+
|
|
1081
|
+
${accessModifier} partial class ${className}${customMethod}Arg : MushroomDriver.MushroomRequestArg
|
|
1082
|
+
{
|
|
1083
|
+
public override string BuildUrl()
|
|
1084
|
+
{
|
|
1085
|
+
BuildCustomUrl();
|
|
1086
|
+
return CustomUrl;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
partial void BuildCustomUrl();
|
|
1090
|
+
|
|
1091
|
+
private string OriginUrl => "${entityName}s/${actionName.substring('_raw_http_method_'.length)}";
|
|
1092
|
+
|
|
1093
|
+
private string CustomUrl { get; set; } = "${entityName}s/${actionName.substring('_raw_http_method_'.length)}";
|
|
1094
|
+
|
|
1095
|
+
public override string Method { get; } = "${actionName.substring('_raw_http_method_'.length)}";
|
|
1096
|
+
|
|
1097
|
+
public ${className}${customMethod}Body Data { get; set; }
|
|
1098
|
+
|
|
1099
|
+
public object CustomData { get; set; }
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
`;
|
|
1103
|
+
break;
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
if (Object.keys(entity.views ?? {}).length) {
|
|
1108
|
+
codeConnectors += ` public ${className}Views Views { get; }
|
|
1109
|
+
|
|
1110
|
+
`;
|
|
1111
|
+
codeExtraClasses += ` ${accessModifier} partial class ${className}Views : MushroomDriver.MushroomViewConnector
|
|
1112
|
+
{
|
|
1113
|
+
protected System.Func<string> FnResource;
|
|
1114
|
+
|
|
1115
|
+
public ${className}Views(MushroomDriver.MushroomClient client, System.Func<string> fnResource) : base(client)
|
|
1116
|
+
{
|
|
1117
|
+
FnResource = fnResource;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
`;
|
|
1121
|
+
let viewExtraClass = '';
|
|
1122
|
+
for (const viewName in entity.views) {
|
|
1123
|
+
const viewMethodName = toCSharpName(viewName);
|
|
1124
|
+
let hasNoParamView = false;
|
|
1125
|
+
entity.views[viewName].forEach((view) => {
|
|
1126
|
+
const role = view.grant === '*' ? '' : `_${toCSharpName(view.grant)}`;
|
|
1127
|
+
const hasParameter = view.parameters && view.parameters.length;
|
|
1128
|
+
if (hasParameter) {
|
|
1129
|
+
codeExtraClasses += ` public System.Threading.Tasks.Task<System.Collections.Generic.List<${className}View_${viewMethodName}Result>> ${viewMethodName}(${className}View${role}_${viewMethodName}Arg arg)
|
|
1130
|
+
{
|
|
1131
|
+
return InternalExecuteView<${className}View_${viewMethodName}Result>(new MushroomDriver.ViewArg<${className}View${role}_${viewMethodName}Arg> {
|
|
1132
|
+
Parameters = arg,
|
|
1133
|
+
Resource = FnResource?.Invoke(),
|
|
1134
|
+
ViewName = "${viewName}"
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
`;
|
|
1139
|
+
viewExtraClass += ` ${accessModifier} partial class ${className}View${role}_${viewMethodName}Arg
|
|
1140
|
+
{
|
|
1141
|
+
`;
|
|
1142
|
+
view.parameters?.forEach((p) => {
|
|
1143
|
+
let type = getCSharpTypeFromMushroomType(source, p.type, p.validation && p.validation.required);
|
|
1144
|
+
if (p.isArray)
|
|
1145
|
+
type = `System.Collections.Generic.List<${type}>`;
|
|
1146
|
+
viewExtraClass += ` [Newtonsoft.Json.JsonProperty(PropertyName = "${p.field}", NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore${type === 'System.Datetime' ? ', DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore' : ''})]
|
|
1147
|
+
[System.Text.Json.Serialization.JsonPropertyName("${p.field}")]
|
|
1148
|
+
[System.Text.Json.Serialization.JsonIgnore(Condition = ${type === 'System.DateTime' ? 'System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault' : 'System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull'})]
|
|
1149
|
+
public ${type} ${toCSharpName(p.field)} { get; set; }
|
|
1150
|
+
|
|
1151
|
+
`;
|
|
1152
|
+
});
|
|
1153
|
+
viewExtraClass += ` }
|
|
1154
|
+
|
|
1155
|
+
`;
|
|
1156
|
+
}
|
|
1157
|
+
else if (!hasNoParamView) {
|
|
1158
|
+
hasNoParamView = true;
|
|
1159
|
+
codeExtraClasses += ` public System.Threading.Tasks.Task<System.Collections.Generic.List<${className}View_${viewMethodName}Result>> ${viewMethodName}()
|
|
1160
|
+
{
|
|
1161
|
+
return InternalExecuteView<${className}View_${viewMethodName}Result>(new MushroomDriver.ViewArg {
|
|
1162
|
+
Resource = FnResource?.Invoke(),
|
|
1163
|
+
ViewName = "${viewName}"
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
`;
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
viewExtraClass += ` ${accessModifier} partial class ${className}View_${viewMethodName}Result
|
|
1171
|
+
{
|
|
1172
|
+
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
`;
|
|
1176
|
+
}
|
|
1177
|
+
codeExtraClasses += ` }
|
|
1178
|
+
|
|
1179
|
+
${viewExtraClass}`;
|
|
1180
|
+
}
|
|
1181
|
+
codeConnectors += ' }\n\n';
|
|
1182
|
+
}
|
|
1183
|
+
if (out.strEnumClasses)
|
|
1184
|
+
strEnumClasses += out.strEnumClasses;
|
|
1185
|
+
const code = `// This file was generated by Mushroom CLI ${packageVersion} (https://www.npmjs.com/package/mushroom-cli), please do not modify
|
|
1186
|
+
|
|
1187
|
+
// Require package: Mushroom.Driver version 1.4.0 or later (https://www.nuget.org/packages/Mushroom.Driver/)
|
|
1188
|
+
|
|
1189
|
+
// ReSharper disable InconsistentNaming
|
|
1190
|
+
// ReSharper disable PartialTypeWithSinglePart
|
|
1191
|
+
// ReSharper disable PartialMethodWithSinglePart
|
|
1192
|
+
// ReSharper disable UnusedMember.Global
|
|
1193
|
+
// ReSharper disable UnusedMember.Local
|
|
1194
|
+
// ReSharper disable IdentifierTypo
|
|
1195
|
+
// ReSharper disable StringLiteralTypo
|
|
1196
|
+
// ReSharper disable CommentTypo
|
|
1197
|
+
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
using JsonPropertyAttribute = Newtonsoft.Json.JsonPropertyAttribute;
|
|
1201
|
+
using NullValueHandling = Newtonsoft.Json.NullValueHandling;
|
|
1202
|
+
using ${namespace}.Resources;
|
|
1203
|
+
|
|
1204
|
+
namespace ${namespace}
|
|
1205
|
+
{
|
|
1206
|
+
${accessModifier} partial class API
|
|
1207
|
+
{
|
|
1208
|
+
static API()
|
|
1209
|
+
{
|
|
1210
|
+
CustomizeRootApiUrl();
|
|
1211
|
+
var client = new MushroomDriver.MushroomClient(_rootApiUrl);
|
|
1212
|
+
MushroomClient = client;
|
|
1213
|
+
|
|
1214
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.indexOf('auth') !== -1 ? 'Authentication = new MushroomDriver.Auth.Authentication(_rootApiUrl);' : ''}
|
|
1215
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.indexOf('file') !== -1 ? 'FileExtension = new MushroomDriver.File.FileExtension(_rootApiUrl);' : ''}
|
|
1216
|
+
|
|
1217
|
+
${codeStaticCtor}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
static partial void CustomizeRootApiUrl();
|
|
1221
|
+
|
|
1222
|
+
private static string _rootApiUrl = ${JSON.stringify(common.getRootUrl(source))};
|
|
1223
|
+
|
|
1224
|
+
public static MushroomDriver.MushroomClient MushroomClient { get; }
|
|
1225
|
+
|
|
1226
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.indexOf('auth') !== -1 ? 'public static MushroomDriver.Auth.Authentication Authentication { get; }' : ''}
|
|
1227
|
+
|
|
1228
|
+
${Array.isArray(aliasProject.features) && aliasProject.features.indexOf('file') !== -1 ? 'public static MushroomDriver.File.FileExtension FileExtension { get; }' : ''}
|
|
1229
|
+
|
|
1230
|
+
${codeStaticProperties}
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/*${accessModifier} partial class API
|
|
1234
|
+
{
|
|
1235
|
+
static partial void CustomizeRootApiUrl()
|
|
1236
|
+
{
|
|
1237
|
+
_rootApiUrl = "your customized root api url";
|
|
1238
|
+
}
|
|
1239
|
+
}*/
|
|
1240
|
+
|
|
1241
|
+
${codeConnectors}${codeExtraClasses}
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
namespace ${namespace}.Resources
|
|
1245
|
+
{
|
|
1246
|
+
${strClasses}
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
namespace ${namespace}.Enums
|
|
1250
|
+
{
|
|
1251
|
+
${strEnumClasses}
|
|
1252
|
+
}`;
|
|
1253
|
+
common.ensureFolder(aliasProject.output);
|
|
1254
|
+
fs.writeFileSync(aliasProject.output, code);
|
|
1255
|
+
common.logInfo(`Generated CSharp Driver for ${projectName}@${alias} to ${aliasProject.output}`);
|
|
1256
|
+
}
|