open-api-typescript-request-generator 0.0.1-alpha.2 → 0.0.2

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.
@@ -1,978 +0,0 @@
1
- "use strict";
2
-
3
- var __assign = void 0 && (void 0).__assign || function () {
4
- __assign = Object.assign || function (t) {
5
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6
- s = arguments[i];
7
-
8
- for (var p in s) {
9
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
10
- }
11
- }
12
-
13
- return t;
14
- };
15
-
16
- return __assign.apply(this, arguments);
17
- };
18
-
19
- var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
20
- if (k2 === undefined) k2 = k;
21
- var desc = Object.getOwnPropertyDescriptor(m, k);
22
-
23
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
- desc = {
25
- enumerable: true,
26
- get: function get() {
27
- return m[k];
28
- }
29
- };
30
- }
31
-
32
- Object.defineProperty(o, k2, desc);
33
- } : function (o, m, k, k2) {
34
- if (k2 === undefined) k2 = k;
35
- o[k2] = m[k];
36
- });
37
-
38
- var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
39
- Object.defineProperty(o, "default", {
40
- enumerable: true,
41
- value: v
42
- });
43
- } : function (o, v) {
44
- o["default"] = v;
45
- });
46
-
47
- var __importStar = void 0 && (void 0).__importStar || function (mod) {
48
- if (mod && mod.__esModule) return mod;
49
- var result = {};
50
- if (mod != null) for (var k in mod) {
51
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
52
- }
53
-
54
- __setModuleDefault(result, mod);
55
-
56
- return result;
57
- };
58
-
59
- var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
60
- function adopt(value) {
61
- return value instanceof P ? value : new P(function (resolve) {
62
- resolve(value);
63
- });
64
- }
65
-
66
- return new (P || (P = Promise))(function (resolve, reject) {
67
- function fulfilled(value) {
68
- try {
69
- step(generator.next(value));
70
- } catch (e) {
71
- reject(e);
72
- }
73
- }
74
-
75
- function rejected(value) {
76
- try {
77
- step(generator["throw"](value));
78
- } catch (e) {
79
- reject(e);
80
- }
81
- }
82
-
83
- function step(result) {
84
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
85
- }
86
-
87
- step((generator = generator.apply(thisArg, _arguments || [])).next());
88
- });
89
- };
90
-
91
- var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
92
- var _ = {
93
- label: 0,
94
- sent: function sent() {
95
- if (t[0] & 1) throw t[1];
96
- return t[1];
97
- },
98
- trys: [],
99
- ops: []
100
- },
101
- f,
102
- y,
103
- t,
104
- g;
105
- return g = {
106
- next: verb(0),
107
- "throw": verb(1),
108
- "return": verb(2)
109
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
110
- return this;
111
- }), g;
112
-
113
- function verb(n) {
114
- return function (v) {
115
- return step([n, v]);
116
- };
117
- }
118
-
119
- function step(op) {
120
- if (f) throw new TypeError("Generator is already executing.");
121
-
122
- while (_) {
123
- try {
124
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
125
- if (y = 0, t) op = [op[0] & 2, t.value];
126
-
127
- switch (op[0]) {
128
- case 0:
129
- case 1:
130
- t = op;
131
- break;
132
-
133
- case 4:
134
- _.label++;
135
- return {
136
- value: op[1],
137
- done: false
138
- };
139
-
140
- case 5:
141
- _.label++;
142
- y = op[1];
143
- op = [0];
144
- continue;
145
-
146
- case 7:
147
- op = _.ops.pop();
148
-
149
- _.trys.pop();
150
-
151
- continue;
152
-
153
- default:
154
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
155
- _ = 0;
156
- continue;
157
- }
158
-
159
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
160
- _.label = op[1];
161
- break;
162
- }
163
-
164
- if (op[0] === 6 && _.label < t[1]) {
165
- _.label = t[1];
166
- t = op;
167
- break;
168
- }
169
-
170
- if (t && _.label < t[2]) {
171
- _.label = t[2];
172
-
173
- _.ops.push(op);
174
-
175
- break;
176
- }
177
-
178
- if (t[2]) _.ops.pop();
179
-
180
- _.trys.pop();
181
-
182
- continue;
183
- }
184
-
185
- op = body.call(thisArg, _);
186
- } catch (e) {
187
- op = [6, e];
188
- y = 0;
189
- } finally {
190
- f = t = 0;
191
- }
192
- }
193
-
194
- if (op[0] & 5) throw op[1];
195
- return {
196
- value: op[0] ? op[1] : void 0,
197
- done: true
198
- };
199
- }
200
- };
201
-
202
- var __spreadArray = void 0 && (void 0).__spreadArray || function (to, from, pack) {
203
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
204
- if (ar || !(i in from)) {
205
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
206
- ar[i] = from[i];
207
- }
208
- }
209
- return to.concat(ar || Array.prototype.slice.call(from));
210
- };
211
-
212
- var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
213
- return mod && mod.__esModule ? mod : {
214
- "default": mod
215
- };
216
- };
217
-
218
- Object.defineProperty(exports, "__esModule", {
219
- value: true
220
- });
221
- exports.getProjectInfoAndInterfaces = exports.getInterfacesByCategoryIds = exports.fetchCatInterfaceById = exports.fetchInterfaceById = exports.fetchProjectInfo = exports.fetchProjectInfoById = exports.fetchInterfaceList = exports.fetchInterfaceListById = exports.fetchExport = exports.fetchExportById = exports.fetchProject = exports.fetchProjectById = exports.fetchToken = exports.fetchApi = exports.loginPrompts = void 0;
222
- /**
223
- * 获取yapi数据
224
- */
225
-
226
- var got_1 = __importDefault(require("got"));
227
-
228
- var prompts_1 = __importDefault(require("prompts"));
229
-
230
- var vtils_1 = require("vtils");
231
-
232
- var constants_1 = require("./constants");
233
-
234
- var conso = __importStar(require("./console"));
235
-
236
- var spinner_1 = require("./spinner");
237
-
238
- var helpers_1 = require("./helpers");
239
-
240
- var client = got_1.default.extend({
241
- responseType: 'json',
242
- https: {
243
- rejectUnauthorized: false
244
- }
245
- });
246
-
247
- var emailValidate = function emailValidate(prev, values) {
248
- return !prev ? '请输入邮箱' : true;
249
- };
250
-
251
- var passwordValidate = function passwordValidate(prev, values) {
252
- return !prev ? '请输入密码' : true;
253
- };
254
-
255
- var inputs = [{
256
- type: 'text',
257
- name: 'email',
258
- message: '请输入yapi的邮箱账号',
259
- validate: emailValidate
260
- }, {
261
- type: 'password',
262
- name: 'password',
263
- message: '请输入密码',
264
- validate: passwordValidate
265
- }];
266
- /**
267
- * 登录提示框,账号密码录入
268
- * @returns
269
- */
270
-
271
- var loginPrompts = function loginPrompts(serverUrl) {
272
- return __awaiter(void 0, void 0, void 0, function () {
273
- var formatInputs, res;
274
- return __generator(this, function (_a) {
275
- switch (_a.label) {
276
- case 0:
277
- formatInputs = __spreadArray([], inputs, true);
278
-
279
- if (serverUrl) {
280
- formatInputs[0].message = "\u8BF7\u8F93\u5165".concat(serverUrl, "\u7684\u90AE\u7BB1\u8D26\u53F7");
281
- }
282
-
283
- return [4
284
- /*yield*/
285
- , (0, prompts_1.default)(formatInputs)];
286
-
287
- case 1:
288
- res = _a.sent();
289
- return [2
290
- /*return*/
291
- , res];
292
- }
293
- });
294
- });
295
- };
296
-
297
- exports.loginPrompts = loginPrompts;
298
- /**
299
- *
300
- * @param url 请求方法
301
- * @param query
302
- * @returns
303
- */
304
-
305
- var fetchApi = function fetchApi(path, data, config) {
306
- return __awaiter(this, void 0, void 0, function () {
307
- var _a, _b, serverUrl, _c, errorExit, method, url, params, response, res;
308
-
309
- return __generator(this, function (_d) {
310
- switch (_d.label) {
311
- case 0:
312
- _a = config || {}, _b = _a.serverUrl, serverUrl = _b === void 0 ? constants_1.DefaultServerUrl : _b, _c = _a.errorExit, errorExit = _c === void 0 ? true : _c;
313
- method = (config === null || config === void 0 ? void 0 : config.method) || 'get';
314
- url = path.startsWith('http') ? path : "".concat(serverUrl).concat(path);
315
- params = __assign({}, data);
316
-
317
- if (config === null || config === void 0 ? void 0 : config.token) {
318
- params.token = config.token;
319
- }
320
-
321
- return [4
322
- /*yield*/
323
- , client(url, {
324
- method: method,
325
- json: method.toLowerCase() !== 'get' ? params : undefined,
326
- searchParams: method.toLowerCase() === 'get' ? params : undefined
327
- }).catch(function (e) {
328
- return {
329
- body: {
330
- errcode: 1111,
331
- errmsg: e.message || '接口请求异常',
332
- data: null
333
- }
334
- };
335
- })];
336
-
337
- case 1:
338
- response = _d.sent();
339
- res = response.body;
340
-
341
- if (res && res.errcode) {
342
- spinner_1.spinnerInstance.stop();
343
-
344
- if (res.errcode === constants_1.ResponseErrorCode.UnLogin) {
345
- conso.error('登录已过期或token异常', url, data);
346
- } else {
347
- conso.error(res.errmsg, url, data);
348
- }
349
-
350
- if (errorExit) process.exit();
351
- }
352
-
353
- return [2
354
- /*return*/
355
- , res.data || res];
356
- }
357
- });
358
- });
359
- };
360
-
361
- exports.fetchApi = fetchApi;
362
- /**
363
- * 获取项目token
364
- */
365
-
366
- var fetchToken = function fetchToken(id, config) {
367
- return __awaiter(void 0, void 0, void 0, function () {
368
- var res;
369
- return __generator(this, function (_a) {
370
- switch (_a.label) {
371
- case 0:
372
- return [4
373
- /*yield*/
374
- , (0, exports.fetchApi)(constants_1.yapiApiToken, {
375
- project_id: id
376
- }, config)];
377
-
378
- case 1:
379
- res = _a.sent();
380
- return [2
381
- /*return*/
382
- , res];
383
- }
384
- });
385
- });
386
- };
387
-
388
- exports.fetchToken = fetchToken;
389
- /**
390
- * 获取项目基本信息 by id
391
- */
392
-
393
- var fetchProjectById = function fetchProjectById(config) {
394
- return __awaiter(void 0, void 0, void 0, function () {
395
- var projectId, projectInfo, basePath;
396
- return __generator(this, function (_a) {
397
- switch (_a.label) {
398
- case 0:
399
- projectId = config.projectId;
400
- return [4
401
- /*yield*/
402
- , (0, exports.fetchApi)(constants_1.yapiApiGetProject, {
403
- id: projectId
404
- }, config)];
405
-
406
- case 1:
407
- projectInfo = _a.sent();
408
- basePath = "/".concat(projectInfo.basepath || '/').replace(/\/+$/, '').replace(/^\/+/, '/');
409
- projectInfo.basepath = basePath;
410
- return [2
411
- /*return*/
412
- , projectInfo];
413
- }
414
- });
415
- });
416
- };
417
-
418
- exports.fetchProjectById = fetchProjectById;
419
- /**
420
- * 获取项目基本信息
421
- *
422
- */
423
-
424
- var fetchProject = function fetchProject(config) {
425
- return __awaiter(void 0, void 0, void 0, function () {
426
- var projectInfo, basePath;
427
- return __generator(this, function (_a) {
428
- switch (_a.label) {
429
- case 0:
430
- if (!config.token) {
431
- return [2
432
- /*return*/
433
- , (0, exports.fetchProjectById)(config)];
434
- }
435
-
436
- return [4
437
- /*yield*/
438
- , (0, exports.fetchApi)(constants_1.yapiApiGetProject, {
439
- token: config.token
440
- }, config)];
441
-
442
- case 1:
443
- projectInfo = _a.sent();
444
- basePath = "/".concat(projectInfo.basepath || '/').replace(/\/+$/, '').replace(/^\/+/, '/');
445
- projectInfo.basepath = basePath;
446
- return [2
447
- /*return*/
448
- , projectInfo];
449
- }
450
- });
451
- });
452
- };
453
-
454
- exports.fetchProject = fetchProject;
455
- /**
456
- * 通过导出接口获取项目下的所有接口 by id
457
- */
458
-
459
- var fetchExportById = function fetchExportById(config) {
460
- return __awaiter(void 0, void 0, void 0, function () {
461
- var projectInfo, categoryList;
462
- return __generator(this, function (_a) {
463
- switch (_a.label) {
464
- case 0:
465
- return [4
466
- /*yield*/
467
- , (0, exports.fetchProjectById)(config)];
468
-
469
- case 1:
470
- projectInfo = _a.sent();
471
- return [4
472
- /*yield*/
473
- , (0, exports.fetchApi)(constants_1.yapiApiExport, {
474
- type: 'json',
475
- status: 'all',
476
- isWiki: 'false',
477
- token: projectInfo.token
478
- }, config)];
479
-
480
- case 2:
481
- categoryList = _a.sent();
482
- return [2
483
- /*return*/
484
- , categoryList.map(function (cat) {
485
- cat.list = (cat.list || []).map(function (item) {
486
- item.path = "".concat(projectInfo.basepath).concat(item.path);
487
- return item;
488
- });
489
- return cat;
490
- })];
491
- }
492
- });
493
- });
494
- };
495
-
496
- exports.fetchExportById = fetchExportById;
497
- /**
498
- * 通过导出接口获取项目下的所有接口
499
- */
500
-
501
- var fetchExport = function fetchExport(config) {
502
- return __awaiter(void 0, void 0, void 0, function () {
503
- var projectInfo, categoryList;
504
- return __generator(this, function (_a) {
505
- switch (_a.label) {
506
- case 0:
507
- if (!config.token) {
508
- return [2
509
- /*return*/
510
- , (0, exports.fetchExportById)(config)];
511
- }
512
-
513
- return [4
514
- /*yield*/
515
- , (0, exports.fetchProject)(config)];
516
-
517
- case 1:
518
- projectInfo = _a.sent();
519
- return [4
520
- /*yield*/
521
- , (0, exports.fetchApi)(constants_1.yapiApiExport, {
522
- type: 'json',
523
- status: 'all',
524
- isWiki: 'false',
525
- token: config.token
526
- }, config)];
527
-
528
- case 2:
529
- categoryList = _a.sent();
530
- return [2
531
- /*return*/
532
- , categoryList.map(function (cat) {
533
- cat.list = (cat.list || []).map(function (item) {
534
- item.path = "".concat(projectInfo.basepath).concat(item.path);
535
- return item;
536
- });
537
- return cat;
538
- })];
539
- }
540
- });
541
- });
542
- };
543
-
544
- exports.fetchExport = fetchExport;
545
- /**
546
- * 获取所有接口 by id
547
- * @param param0
548
- * @returns
549
- */
550
-
551
- var fetchInterfaceListById = function fetchInterfaceListById(config) {
552
- return __awaiter(this, void 0, void 0, function () {
553
- var id, allData, category;
554
- return __generator(this, function (_a) {
555
- switch (_a.label) {
556
- case 0:
557
- id = config.id;
558
- return [4
559
- /*yield*/
560
- , (0, exports.fetchExportById)(config)];
561
-
562
- case 1:
563
- allData = _a.sent();
564
- category = (allData || []).filter(function (cat) {
565
- return !(0, vtils_1.isEmpty)(cat) && !(0, vtils_1.isEmpty)(cat.list) && (!id || id && cat.list[0].catid === id);
566
- });
567
-
568
- if (category) {
569
- category.forEach(function (interfaceInfo) {
570
- interfaceInfo._id = interfaceInfo.list[0].catid;
571
- interfaceInfo.list.forEach(function (item) {
572
- // 实现 _category 字段
573
- item._category = (0, vtils_1.omit)(interfaceInfo, ['list']);
574
- });
575
- });
576
- }
577
-
578
- return [2
579
- /*return*/
580
- , category];
581
- }
582
- });
583
- });
584
- };
585
-
586
- exports.fetchInterfaceListById = fetchInterfaceListById;
587
- /**
588
- * 获取所有接口
589
- * @param param0
590
- * @returns
591
- */
592
-
593
- var fetchInterfaceList = function fetchInterfaceList(config) {
594
- return __awaiter(this, void 0, void 0, function () {
595
- var id, token, allData, category;
596
- return __generator(this, function (_a) {
597
- switch (_a.label) {
598
- case 0:
599
- id = config.id, token = config.token;
600
-
601
- if (!token) {
602
- return [2
603
- /*return*/
604
- , (0, exports.fetchInterfaceListById)(config)];
605
- }
606
-
607
- return [4
608
- /*yield*/
609
- , (0, exports.fetchExport)(config)];
610
-
611
- case 1:
612
- allData = _a.sent();
613
- category = (allData || []).filter(function (cat) {
614
- return !(0, vtils_1.isEmpty)(cat) && !(0, vtils_1.isEmpty)(cat.list) && (!id || id && cat.list[0].catid === id);
615
- });
616
-
617
- if (category) {
618
- category.forEach(function (interfaceInfo) {
619
- interfaceInfo._id = interfaceInfo.list[0].catid;
620
- interfaceInfo.list.forEach(function (item) {
621
- // 实现 _category 字段
622
- item._category = (0, vtils_1.omit)(interfaceInfo, ['list']);
623
- });
624
- });
625
- }
626
-
627
- return [2
628
- /*return*/
629
- , category];
630
- }
631
- });
632
- });
633
- };
634
-
635
- exports.fetchInterfaceList = fetchInterfaceList;
636
- /**
637
- * 获取项目信息 by id
638
- * @param config
639
- * @returns
640
- */
641
-
642
- var fetchProjectInfoById = function fetchProjectInfoById(config) {
643
- return __awaiter(this, void 0, void 0, function () {
644
- var serverUrl, projectId, projectInfo, projectCats;
645
- return __generator(this, function (_a) {
646
- switch (_a.label) {
647
- case 0:
648
- serverUrl = config.serverUrl, projectId = config.projectId;
649
- return [4
650
- /*yield*/
651
- , (0, exports.fetchProjectById)(config)];
652
-
653
- case 1:
654
- projectInfo = _a.sent();
655
- return [4
656
- /*yield*/
657
- , (0, exports.fetchApi)(constants_1.yapiApiGetMenu, {
658
- project_id: projectId
659
- }, config)];
660
-
661
- case 2:
662
- projectCats = _a.sent();
663
- return [2
664
- /*return*/
665
- , __assign(__assign({}, projectInfo), {
666
- cats: projectCats,
667
- getMockUrl: function getMockUrl() {
668
- return "".concat(serverUrl, "/mock/").concat(projectInfo._id);
669
- }
670
- })];
671
- }
672
- });
673
- });
674
- };
675
-
676
- exports.fetchProjectInfoById = fetchProjectInfoById;
677
- /**
678
- * 获取项目信息
679
- * @param config
680
- * @returns
681
- */
682
-
683
- var fetchProjectInfo = function fetchProjectInfo(config) {
684
- return __awaiter(this, void 0, void 0, function () {
685
- var token, serverUrl, projectInfo, projectCats;
686
- return __generator(this, function (_a) {
687
- switch (_a.label) {
688
- case 0:
689
- token = config.token, serverUrl = config.serverUrl;
690
-
691
- if (!token) {
692
- return [2
693
- /*return*/
694
- , (0, exports.fetchProjectInfoById)(config)];
695
- }
696
-
697
- return [4
698
- /*yield*/
699
- , (0, exports.fetchProject)(config)];
700
-
701
- case 1:
702
- projectInfo = _a.sent();
703
- return [4
704
- /*yield*/
705
- , (0, exports.fetchApi)(constants_1.yapiApiGetMenu, {
706
- token: token
707
- }, config)];
708
-
709
- case 2:
710
- projectCats = _a.sent();
711
- return [2
712
- /*return*/
713
- , __assign(__assign({}, projectInfo), {
714
- cats: projectCats,
715
- getMockUrl: function getMockUrl() {
716
- return "".concat(serverUrl, "/mock/").concat(projectInfo._id);
717
- }
718
- })];
719
- }
720
- });
721
- });
722
- };
723
-
724
- exports.fetchProjectInfo = fetchProjectInfo;
725
- /**
726
- * 获取单个接口信息 by id
727
- */
728
-
729
- var fetchInterfaceById = function fetchInterfaceById(id, config) {
730
- return __awaiter(void 0, void 0, void 0, function () {
731
- var res;
732
- return __generator(this, function (_a) {
733
- switch (_a.label) {
734
- case 0:
735
- return [4
736
- /*yield*/
737
- , (0, exports.fetchApi)(constants_1.yapiApiInterfaceDetail, {
738
- id: id
739
- }, config)];
740
-
741
- case 1:
742
- res = _a.sent();
743
- return [2
744
- /*return*/
745
- , res];
746
- }
747
- });
748
- });
749
- };
750
-
751
- exports.fetchInterfaceById = fetchInterfaceById;
752
- /**
753
- * 获取分类下的接口列表信息 by id
754
- */
755
-
756
- var fetchCatInterfaceById = function fetchCatInterfaceById(catid, config) {
757
- return __awaiter(void 0, void 0, void 0, function () {
758
- var res, list;
759
- return __generator(this, function (_a) {
760
- switch (_a.label) {
761
- case 0:
762
- return [4
763
- /*yield*/
764
- , (0, exports.fetchApi)(constants_1.yapiApiCatInterfaceList, {
765
- catid: catid,
766
- page: 1,
767
- limit: 5000
768
- }, __assign(__assign({}, config), {
769
- errorExit: false
770
- }))];
771
-
772
- case 1:
773
- res = _a.sent();
774
- list = res.list; // if (list.length) {
775
- // const resList = await Promise.all(
776
- // list.map(async item => fetchInterfaceById(item._id, { ...config, errorExit: false }))
777
- // );
778
- // return resList;
779
- // }
780
-
781
- return [2
782
- /*return*/
783
- , list];
784
- }
785
- });
786
- });
787
- };
788
-
789
- exports.fetchCatInterfaceById = fetchCatInterfaceById;
790
- /**
791
- * 批量获取分类下的详细接口信息
792
- * @param categoryList
793
- * @param config
794
- * @returns
795
- */
796
-
797
- var getInterfacesByCategoryIds = function getInterfacesByCategoryIds(categoryIds, config) {
798
- return __awaiter(void 0, void 0, void 0, function () {
799
- var res, allInterface, result;
800
- return __generator(this, function (_a) {
801
- switch (_a.label) {
802
- case 0:
803
- return [4
804
- /*yield*/
805
- , (0, helpers_1.autoAsyncSplitQueue)(categoryIds.map(function (id) {
806
- return function () {
807
- return __awaiter(void 0, void 0, void 0, function () {
808
- var rr;
809
- return __generator(this, function (_a) {
810
- switch (_a.label) {
811
- case 0:
812
- return [4
813
- /*yield*/
814
- , (0, exports.fetchCatInterfaceById)(id, config)];
815
-
816
- case 1:
817
- rr = _a.sent();
818
- return [2
819
- /*return*/
820
- , rr];
821
- }
822
- });
823
- });
824
- };
825
- }))];
826
-
827
- case 1:
828
- res = _a.sent();
829
- allInterface = res.flat();
830
- return [4
831
- /*yield*/
832
- , (0, helpers_1.autoAsyncSplitQueue)(allInterface.map(function (j) {
833
- return function () {
834
- return __awaiter(void 0, void 0, void 0, function () {
835
- var info;
836
- return __generator(this, function (_a) {
837
- switch (_a.label) {
838
- case 0:
839
- return [4
840
- /*yield*/
841
- , (0, exports.fetchInterfaceById)(j._id, config)];
842
-
843
- case 1:
844
- info = _a.sent();
845
- return [2
846
- /*return*/
847
- , info];
848
- }
849
- });
850
- });
851
- };
852
- }))];
853
-
854
- case 2:
855
- result = _a.sent();
856
- return [2
857
- /*return*/
858
- , result.flat()];
859
- }
860
- });
861
- });
862
- };
863
-
864
- exports.getInterfacesByCategoryIds = getInterfacesByCategoryIds;
865
- /**
866
- * 获取项目信息和接口
867
- * @param config
868
- * @returns
869
- */
870
-
871
- var getProjectInfoAndInterfaces = function getProjectInfoAndInterfaces(config) {
872
- return __awaiter(void 0, void 0, void 0, function () {
873
- var _a, categories, token, projectInfo, allInterfaceList, simpleProjectInfo, catList;
874
-
875
- return __generator(this, function (_b) {
876
- switch (_b.label) {
877
- case 0:
878
- _a = config.categories, categories = _a === void 0 ? [] : _a, token = config.token;
879
- allInterfaceList = [];
880
- if (!token) return [3
881
- /*break*/
882
- , 3];
883
- return [4
884
- /*yield*/
885
- , (0, exports.fetchProjectInfo)(config)];
886
-
887
- case 1:
888
- simpleProjectInfo = _b.sent();
889
- return [4
890
- /*yield*/
891
- , (0, exports.fetchProjectInfoById)(__assign(__assign({}, config), {
892
- projectId: simpleProjectInfo._id
893
- }))];
894
-
895
- case 2:
896
- projectInfo = _b.sent();
897
- return [3
898
- /*break*/
899
- , 5];
900
-
901
- case 3:
902
- return [4
903
- /*yield*/
904
- , (0, exports.fetchProjectInfoById)(config)];
905
-
906
- case 4:
907
- projectInfo = _b.sent();
908
- _b.label = 5;
909
-
910
- case 5:
911
- catList = ((projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.cat) || []).filter(function (item) {
912
- return (categories === null || categories === void 0 ? void 0 : categories.findIndex(function (i) {
913
- return i.id === item._id;
914
- })) >= 0;
915
- });
916
- if (!(catList === null || catList === void 0 ? void 0 : catList.length)) return [3
917
- /*break*/
918
- , 7];
919
- return [4
920
- /*yield*/
921
- , Promise.all(catList.map(function (item, index) {
922
- return __awaiter(void 0, void 0, void 0, function () {
923
- var interfaceList;
924
- return __generator(this, function (_a) {
925
- switch (_a.label) {
926
- case 0:
927
- return [4
928
- /*yield*/
929
- , (0, exports.getInterfacesByCategoryIds)([item._id], config)];
930
-
931
- case 1:
932
- interfaceList = _a.sent();
933
- catList[index].list = interfaceList.map(function (kk) {
934
- kk._category = (0, vtils_1.omit)(item, ['list']); // 追加分类信息
935
-
936
- return kk;
937
- });
938
- return [2
939
- /*return*/
940
- ];
941
- }
942
- });
943
- });
944
- }))];
945
-
946
- case 6:
947
- _b.sent();
948
-
949
- allInterfaceList = catList;
950
- return [3
951
- /*break*/
952
- , 9];
953
-
954
- case 7:
955
- return [4
956
- /*yield*/
957
- , (0, exports.fetchInterfaceList)(__assign(__assign({}, config), {
958
- token: token || projectInfo.token
959
- }))];
960
-
961
- case 8:
962
- // 未配置,则全量生成,此时用export接口更高效
963
- allInterfaceList = _b.sent();
964
- _b.label = 9;
965
-
966
- case 9:
967
- return [2
968
- /*return*/
969
- , {
970
- projectInfo: projectInfo,
971
- allInterfaceList: allInterfaceList
972
- }];
973
- }
974
- });
975
- });
976
- };
977
-
978
- exports.getProjectInfoAndInterfaces = getProjectInfoAndInterfaces;