open-api-typescript-request-generator 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +26 -0
  2. package/bin/apits-gener +4 -0
  3. package/es/Generator.d.ts +43 -0
  4. package/es/Generator.js +892 -0
  5. package/es/cli.d.ts +19 -0
  6. package/es/cli.js +547 -0
  7. package/es/console.d.ts +48 -0
  8. package/es/console.js +151 -0
  9. package/es/constants.d.ts +22 -0
  10. package/es/constants.js +39 -0
  11. package/es/dependenciesHandler.d.ts +16 -0
  12. package/es/dependenciesHandler.js +270 -0
  13. package/es/genIndex.d.ts +23 -0
  14. package/es/genIndex.js +354 -0
  15. package/es/genRequest.d.ts +3 -0
  16. package/es/genRequest.js +216 -0
  17. package/es/getOutputPath.d.ts +5 -0
  18. package/es/getOutputPath.js +28 -0
  19. package/es/helpers.d.ts +63 -0
  20. package/es/helpers.js +458 -0
  21. package/es/index.d.ts +2 -0
  22. package/es/index.js +34 -0
  23. package/es/requestYapiData.d.ts +157 -0
  24. package/es/requestYapiData.js +1010 -0
  25. package/es/responseDataJsonSchemaHandler.d.ts +11 -0
  26. package/es/responseDataJsonSchemaHandler.js +193 -0
  27. package/es/server/mock.d.ts +1 -0
  28. package/es/server/mock.js +7 -0
  29. package/es/server/swaggerJsonToYApiData.d.ts +10 -0
  30. package/es/server/swaggerJsonToYApiData.js +614 -0
  31. package/es/spinner.d.ts +15 -0
  32. package/es/spinner.js +58 -0
  33. package/es/types.d.ts +736 -0
  34. package/es/types.js +143 -0
  35. package/es/utils.d.ts +97 -0
  36. package/es/utils.js +783 -0
  37. package/lib/Generator.d.ts +43 -0
  38. package/lib/Generator.js +892 -0
  39. package/lib/cli.d.ts +19 -0
  40. package/lib/cli.js +547 -0
  41. package/lib/console.d.ts +48 -0
  42. package/lib/console.js +151 -0
  43. package/lib/constants.d.ts +22 -0
  44. package/lib/constants.js +39 -0
  45. package/lib/dependenciesHandler.d.ts +16 -0
  46. package/lib/dependenciesHandler.js +270 -0
  47. package/lib/genIndex.d.ts +23 -0
  48. package/lib/genIndex.js +354 -0
  49. package/lib/genRequest.d.ts +3 -0
  50. package/lib/genRequest.js +216 -0
  51. package/lib/getOutputPath.d.ts +5 -0
  52. package/lib/getOutputPath.js +28 -0
  53. package/lib/helpers.d.ts +63 -0
  54. package/lib/helpers.js +458 -0
  55. package/lib/index.d.ts +2 -0
  56. package/lib/index.js +34 -0
  57. package/lib/requestYapiData.d.ts +157 -0
  58. package/lib/requestYapiData.js +1010 -0
  59. package/lib/responseDataJsonSchemaHandler.d.ts +11 -0
  60. package/lib/responseDataJsonSchemaHandler.js +193 -0
  61. package/lib/server/mock.d.ts +1 -0
  62. package/lib/server/mock.js +7 -0
  63. package/lib/server/swaggerJsonToYApiData.d.ts +10 -0
  64. package/lib/server/swaggerJsonToYApiData.js +614 -0
  65. package/lib/spinner.d.ts +15 -0
  66. package/lib/spinner.js +58 -0
  67. package/lib/types.d.ts +736 -0
  68. package/lib/types.js +143 -0
  69. package/lib/utils.d.ts +97 -0
  70. package/lib/utils.js +783 -0
  71. package/package.json +106 -0
@@ -0,0 +1,354 @@
1
+ "use strict";
2
+ /**
3
+ * 生成入口文件
4
+ */
5
+
6
+ var __makeTemplateObject = void 0 && (void 0).__makeTemplateObject || function (cooked, raw) {
7
+ if (Object.defineProperty) {
8
+ Object.defineProperty(cooked, "raw", {
9
+ value: raw
10
+ });
11
+ } else {
12
+ cooked.raw = raw;
13
+ }
14
+
15
+ return cooked;
16
+ };
17
+
18
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ var desc = Object.getOwnPropertyDescriptor(m, k);
21
+
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = {
24
+ enumerable: true,
25
+ get: function get() {
26
+ return m[k];
27
+ }
28
+ };
29
+ }
30
+
31
+ Object.defineProperty(o, k2, desc);
32
+ } : function (o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ o[k2] = m[k];
35
+ });
36
+
37
+ var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
38
+ Object.defineProperty(o, "default", {
39
+ enumerable: true,
40
+ value: v
41
+ });
42
+ } : function (o, v) {
43
+ o["default"] = v;
44
+ });
45
+
46
+ var __importStar = void 0 && (void 0).__importStar || function (mod) {
47
+ if (mod && mod.__esModule) return mod;
48
+ var result = {};
49
+ if (mod != null) for (var k in mod) {
50
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
51
+ }
52
+
53
+ __setModuleDefault(result, mod);
54
+
55
+ return result;
56
+ };
57
+
58
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
59
+ function adopt(value) {
60
+ return value instanceof P ? value : new P(function (resolve) {
61
+ resolve(value);
62
+ });
63
+ }
64
+
65
+ return new (P || (P = Promise))(function (resolve, reject) {
66
+ function fulfilled(value) {
67
+ try {
68
+ step(generator.next(value));
69
+ } catch (e) {
70
+ reject(e);
71
+ }
72
+ }
73
+
74
+ function rejected(value) {
75
+ try {
76
+ step(generator["throw"](value));
77
+ } catch (e) {
78
+ reject(e);
79
+ }
80
+ }
81
+
82
+ function step(result) {
83
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
84
+ }
85
+
86
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
87
+ });
88
+ };
89
+
90
+ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
91
+ var _ = {
92
+ label: 0,
93
+ sent: function sent() {
94
+ if (t[0] & 1) throw t[1];
95
+ return t[1];
96
+ },
97
+ trys: [],
98
+ ops: []
99
+ },
100
+ f,
101
+ y,
102
+ t,
103
+ g;
104
+ return g = {
105
+ next: verb(0),
106
+ "throw": verb(1),
107
+ "return": verb(2)
108
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
109
+ return this;
110
+ }), g;
111
+
112
+ function verb(n) {
113
+ return function (v) {
114
+ return step([n, v]);
115
+ };
116
+ }
117
+
118
+ function step(op) {
119
+ if (f) throw new TypeError("Generator is already executing.");
120
+
121
+ while (_) {
122
+ try {
123
+ 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;
124
+ if (y = 0, t) op = [op[0] & 2, t.value];
125
+
126
+ switch (op[0]) {
127
+ case 0:
128
+ case 1:
129
+ t = op;
130
+ break;
131
+
132
+ case 4:
133
+ _.label++;
134
+ return {
135
+ value: op[1],
136
+ done: false
137
+ };
138
+
139
+ case 5:
140
+ _.label++;
141
+ y = op[1];
142
+ op = [0];
143
+ continue;
144
+
145
+ case 7:
146
+ op = _.ops.pop();
147
+
148
+ _.trys.pop();
149
+
150
+ continue;
151
+
152
+ default:
153
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
154
+ _ = 0;
155
+ continue;
156
+ }
157
+
158
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
159
+ _.label = op[1];
160
+ break;
161
+ }
162
+
163
+ if (op[0] === 6 && _.label < t[1]) {
164
+ _.label = t[1];
165
+ t = op;
166
+ break;
167
+ }
168
+
169
+ if (t && _.label < t[2]) {
170
+ _.label = t[2];
171
+
172
+ _.ops.push(op);
173
+
174
+ break;
175
+ }
176
+
177
+ if (t[2]) _.ops.pop();
178
+
179
+ _.trys.pop();
180
+
181
+ continue;
182
+ }
183
+
184
+ op = body.call(thisArg, _);
185
+ } catch (e) {
186
+ op = [6, e];
187
+ y = 0;
188
+ } finally {
189
+ f = t = 0;
190
+ }
191
+ }
192
+
193
+ if (op[0] & 5) throw op[1];
194
+ return {
195
+ value: op[0] ? op[1] : void 0,
196
+ done: true
197
+ };
198
+ }
199
+ };
200
+
201
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
202
+ return mod && mod.__esModule ? mod : {
203
+ "default": mod
204
+ };
205
+ };
206
+
207
+ Object.defineProperty(exports, "__esModule", {
208
+ value: true
209
+ });
210
+ exports.genGitRepoIndex = exports.getIndexGitInfo = exports.prepareIndexFile = void 0;
211
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
212
+
213
+ var fs_extra_1 = __importDefault(require("fs-extra"));
214
+
215
+ var path_1 = __importDefault(require("path"));
216
+
217
+ var vtils_1 = require("vtils");
218
+
219
+ var getOutputPath_1 = require("./getOutputPath");
220
+
221
+ var utils_1 = require("./utils");
222
+
223
+ var conso = __importStar(require("./console"));
224
+ /** 提前准备好'src/api/index.ts'文件 */
225
+
226
+
227
+ function prepareIndexFile(config) {
228
+ return __awaiter(this, void 0, void 0, function () {
229
+ var indexFilePath;
230
+ return __generator(this, function (_a) {
231
+ switch (_a.label) {
232
+ case 0:
233
+ indexFilePath = (0, getOutputPath_1.getOutputFilePath)(config, 'index.ts');
234
+ return [4
235
+ /*yield*/
236
+ , fs_extra_1.default.pathExists(indexFilePath)];
237
+
238
+ case 1:
239
+ if (!_a.sent()) {
240
+ fs_extra_1.default.outputFileSync(indexFilePath, (0, vtils_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), (0, utils_1.topNotesContent)()) + '\n');
241
+ }
242
+
243
+ return [2
244
+ /*return*/
245
+ ];
246
+ }
247
+ });
248
+ });
249
+ }
250
+
251
+ exports.prepareIndexFile = prepareIndexFile;
252
+
253
+ exports.default = function (config, categoryList) {
254
+ return __awaiter(void 0, void 0, void 0, function () {
255
+ var prettierConfigPath, indexFilePath, originFileContent, exportAllInterface, content;
256
+ return __generator(this, function (_a) {
257
+ switch (_a.label) {
258
+ case 0:
259
+ prettierConfigPath = config.prettierConfigPath;
260
+ indexFilePath = (0, getOutputPath_1.getOutputFilePath)(config, 'index.ts');
261
+ originFileContent = '';
262
+ return [4
263
+ /*yield*/
264
+ , fs_extra_1.default.pathExists(indexFilePath)];
265
+
266
+ case 1:
267
+ if (_a.sent()) {
268
+ originFileContent = fs_extra_1.default.readFileSync(indexFilePath, {
269
+ encoding: 'utf-8'
270
+ });
271
+ }
272
+
273
+ exportAllInterface = categoryList.reduce(function (list, _a, index) {
274
+ var projectId = _a.projectId; // return `export * from "./${projectId}/${categoryId}"`;
275
+
276
+ if (originFileContent.indexOf("".concat(projectId)) === -1) {
277
+ list.push("export * from \"./".concat(projectId, "\""));
278
+ }
279
+
280
+ return list;
281
+ }, []);
282
+ content = "\n ".concat(exportAllInterface.join(';'), "\n "); // 输出index文件
283
+
284
+ fs_extra_1.default.appendFile(indexFilePath, (0, utils_1.formatContent)((0, vtils_1.dedent)(templateObject_2 || (templateObject_2 = __makeTemplateObject(["", ""], ["", ""])), content), prettierConfigPath));
285
+ return [2
286
+ /*return*/
287
+ ];
288
+ }
289
+ });
290
+ });
291
+ };
292
+
293
+ var getIndexGitInfo = function getIndexGitInfo(config) {
294
+ var indexFilePath = (0, getOutputPath_1.getOutputFilePath)(config, 'index.ts');
295
+ var result = {};
296
+
297
+ try {
298
+ var fileContent_1 = fs_extra_1.default.readFileSync(indexFilePath, {
299
+ encoding: 'utf-8'
300
+ });
301
+ ['repo', 'branch', 'commitId'].forEach(function (k) {
302
+ var reg = new RegExp("".concat(k, ":\\s?([A-Za-z0-9_\\-/://]+)\\s"));
303
+ var matchRes = fileContent_1.match(reg) || [];
304
+ result[k] = matchRes[1] || '';
305
+ });
306
+ } catch (e) {
307
+ conso.tips("\u672A\u627E\u5230".concat(indexFilePath, "\uFF0C\u5C06\u91CD\u65B0\u751F\u6210"));
308
+ }
309
+
310
+ return result;
311
+ };
312
+
313
+ exports.getIndexGitInfo = getIndexGitInfo;
314
+
315
+ var genGitRepoIndex = function genGitRepoIndex(config, filePathList, notes) {
316
+ return __awaiter(void 0, void 0, void 0, function () {
317
+ var prettierConfigPath, indexFilePath, originFileContent, exportAllInterface, content;
318
+ return __generator(this, function (_a) {
319
+ switch (_a.label) {
320
+ case 0:
321
+ prettierConfigPath = config.prettierConfigPath;
322
+ indexFilePath = (0, getOutputPath_1.getOutputFilePath)(config, 'index.ts');
323
+ originFileContent = '';
324
+ return [4
325
+ /*yield*/
326
+ , fs_extra_1.default.pathExists(indexFilePath)];
327
+
328
+ case 1:
329
+ if (_a.sent()) {
330
+ originFileContent = fs_extra_1.default.readFileSync(indexFilePath, {
331
+ encoding: 'utf-8'
332
+ });
333
+ }
334
+
335
+ exportAllInterface = filePathList.reduce(function (list, filePath, index) {
336
+ if (originFileContent.indexOf(filePath) === -1) {
337
+ list.push("export * from \"./".concat(path_1.default.join('./', filePath), "\""));
338
+ }
339
+
340
+ return list;
341
+ }, []);
342
+ content = "\n ".concat(exportAllInterface.join(';'), "\n "); // 输出index文件
343
+
344
+ fs_extra_1.default.appendFile(indexFilePath, (0, utils_1.formatContent)((0, vtils_1.dedent)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["", ""], ["", ""])), content), prettierConfigPath));
345
+ return [2
346
+ /*return*/
347
+ ];
348
+ }
349
+ });
350
+ });
351
+ };
352
+
353
+ exports.genGitRepoIndex = genGitRepoIndex;
354
+ var templateObject_1, templateObject_2, templateObject_3;
@@ -0,0 +1,3 @@
1
+ import { Config } from './types';
2
+ declare const _default: (config: Config) => Promise<void>;
3
+ export default _default;
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+
3
+ var __makeTemplateObject = void 0 && (void 0).__makeTemplateObject || function (cooked, raw) {
4
+ if (Object.defineProperty) {
5
+ Object.defineProperty(cooked, "raw", {
6
+ value: raw
7
+ });
8
+ } else {
9
+ cooked.raw = raw;
10
+ }
11
+
12
+ return cooked;
13
+ };
14
+
15
+ var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
16
+ function adopt(value) {
17
+ return value instanceof P ? value : new P(function (resolve) {
18
+ resolve(value);
19
+ });
20
+ }
21
+
22
+ return new (P || (P = Promise))(function (resolve, reject) {
23
+ function fulfilled(value) {
24
+ try {
25
+ step(generator.next(value));
26
+ } catch (e) {
27
+ reject(e);
28
+ }
29
+ }
30
+
31
+ function rejected(value) {
32
+ try {
33
+ step(generator["throw"](value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ }
38
+
39
+ function step(result) {
40
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
41
+ }
42
+
43
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
44
+ });
45
+ };
46
+
47
+ var __generator = void 0 && (void 0).__generator || function (thisArg, body) {
48
+ var _ = {
49
+ label: 0,
50
+ sent: function sent() {
51
+ if (t[0] & 1) throw t[1];
52
+ return t[1];
53
+ },
54
+ trys: [],
55
+ ops: []
56
+ },
57
+ f,
58
+ y,
59
+ t,
60
+ g;
61
+ return g = {
62
+ next: verb(0),
63
+ "throw": verb(1),
64
+ "return": verb(2)
65
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
66
+ return this;
67
+ }), g;
68
+
69
+ function verb(n) {
70
+ return function (v) {
71
+ return step([n, v]);
72
+ };
73
+ }
74
+
75
+ function step(op) {
76
+ if (f) throw new TypeError("Generator is already executing.");
77
+
78
+ while (_) {
79
+ try {
80
+ 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;
81
+ if (y = 0, t) op = [op[0] & 2, t.value];
82
+
83
+ switch (op[0]) {
84
+ case 0:
85
+ case 1:
86
+ t = op;
87
+ break;
88
+
89
+ case 4:
90
+ _.label++;
91
+ return {
92
+ value: op[1],
93
+ done: false
94
+ };
95
+
96
+ case 5:
97
+ _.label++;
98
+ y = op[1];
99
+ op = [0];
100
+ continue;
101
+
102
+ case 7:
103
+ op = _.ops.pop();
104
+
105
+ _.trys.pop();
106
+
107
+ continue;
108
+
109
+ default:
110
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
111
+ _ = 0;
112
+ continue;
113
+ }
114
+
115
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
116
+ _.label = op[1];
117
+ break;
118
+ }
119
+
120
+ if (op[0] === 6 && _.label < t[1]) {
121
+ _.label = t[1];
122
+ t = op;
123
+ break;
124
+ }
125
+
126
+ if (t && _.label < t[2]) {
127
+ _.label = t[2];
128
+
129
+ _.ops.push(op);
130
+
131
+ break;
132
+ }
133
+
134
+ if (t[2]) _.ops.pop();
135
+
136
+ _.trys.pop();
137
+
138
+ continue;
139
+ }
140
+
141
+ op = body.call(thisArg, _);
142
+ } catch (e) {
143
+ op = [6, e];
144
+ y = 0;
145
+ } finally {
146
+ f = t = 0;
147
+ }
148
+ }
149
+
150
+ if (op[0] & 5) throw op[1];
151
+ return {
152
+ value: op[0] ? op[1] : void 0,
153
+ done: true
154
+ };
155
+ }
156
+ };
157
+
158
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
159
+ return mod && mod.__esModule ? mod : {
160
+ "default": mod
161
+ };
162
+ };
163
+
164
+ Object.defineProperty(exports, "__esModule", {
165
+ value: true
166
+ });
167
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
168
+
169
+ var fs_extra_1 = __importDefault(require("fs-extra"));
170
+
171
+ var vtils_1 = require("vtils");
172
+
173
+ var getOutputPath_1 = require("./getOutputPath");
174
+
175
+ var utils_1 = require("./utils");
176
+
177
+ exports.default = function (config) {
178
+ return __awaiter(void 0, void 0, void 0, function () {
179
+ var prettierConfigPath, defaultRequestLib, rawRequestFunctionFilePath, content;
180
+ return __generator(this, function (_a) {
181
+ switch (_a.label) {
182
+ case 0:
183
+ prettierConfigPath = config.prettierConfigPath, defaultRequestLib = config.defaultRequestLib;
184
+ if (defaultRequestLib === false) return [2
185
+ /*return*/
186
+ ];
187
+ rawRequestFunctionFilePath = (0, getOutputPath_1.getOutputFilePath)(config, 'request.ts');
188
+ if (!!config.typesOnly) return [3
189
+ /*break*/
190
+ , 2];
191
+ return [4
192
+ /*yield*/
193
+ , fs_extra_1.default.pathExists(rawRequestFunctionFilePath)];
194
+
195
+ case 1:
196
+ if (_a.sent()) {
197
+ // conso.tips(`输出目录${outputFilePath}下检测到已有request.ts,如果需要重新生成,请删除该文件 \n`);
198
+ return [2
199
+ /*return*/
200
+ ];
201
+ }
202
+
203
+ _a.label = 2;
204
+
205
+ case 2:
206
+ content = "\n ".concat((0, utils_1.topNotesContent)(), "\n\n import request,{ AxiosRequestConfig } from 'axios'; // axios\u7248\u672C>=0.18.1\n\n const instance = request.create({\n withCredentials: true,\n baseURL: process.env.BASE_URL,\n });\n\n // \u81EA\u5B9A\u4E49request\u62E6\u622A\u5668\n instance.interceptors.request.use((config) => {\n return {\n ...config\n }\n });\n\n // \u81EA\u5B9A\u4E49response\u62E6\u622A\u5668\uFF0C\n // \u6CE8\u610F\uFF1A\u5982\u679C\u4FEE\u6539\u63A5\u53E3\u6B63\u5E38\u8FD4\u56DE\u7684\u7ED3\u6784\uFF0C\u5BF9\u5E94\u7684response\u58F0\u660E\u9700\u8981\u4FEE\u6539\n instance.interceptors.response.use((r) => {\n const { data, config } = r;\n if (data.code === 0) {\n\n return data.data;\n }\n return Promise.reject(data);\n });\n\n export default {\n get: <RQ, RP>(url: string, config?: AxiosRequestConfig) => {\n return instance.get<RP>(url, config);\n },\n post: <RQ, RP>(url: string, config?: AxiosRequestConfig) => {\n return instance.post<RP>(url, config);\n }\n };\n");
207
+ fs_extra_1.default.outputFile(rawRequestFunctionFilePath, (0, utils_1.formatContent)((0, vtils_1.dedent)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), content), prettierConfigPath));
208
+ return [2
209
+ /*return*/
210
+ ];
211
+ }
212
+ });
213
+ });
214
+ };
215
+
216
+ var templateObject_1;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 生成入口文件
3
+ */
4
+ import { Config } from './types';
5
+ export declare const getOutputFilePath: (config: Config, file: string) => string;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ /**
3
+ * 生成入口文件
4
+ */
5
+
6
+ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
7
+ return mod && mod.__esModule ? mod : {
8
+ "default": mod
9
+ };
10
+ };
11
+
12
+ Object.defineProperty(exports, "__esModule", {
13
+ value: true
14
+ });
15
+ exports.getOutputFilePath = void 0;
16
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
17
+
18
+ var path_1 = __importDefault(require("path"));
19
+
20
+ var getOutputFilePath = function getOutputFilePath(config, file) {
21
+ var _a = path_1.default.parse(config.outputFilePath || ''),
22
+ dir = _a.dir,
23
+ name = _a.name;
24
+
25
+ return path_1.default.join(dir, name, file);
26
+ };
27
+
28
+ exports.getOutputFilePath = getOutputFilePath;
@@ -0,0 +1,63 @@
1
+ import type { AppendOptions } from 'form-data';
2
+ import type { Config, RequestConfig, RequestFunctionParams } from './types';
3
+ /**
4
+ * 定义配置。
5
+ *
6
+ * @param config 配置
7
+ */
8
+ export declare function defineConfig(config: Partial<Config> | Partial<Config>[]): Config[];
9
+ export declare class FileData<T = any> {
10
+ /**
11
+ * 原始文件数据。
12
+ */
13
+ private originalFileData;
14
+ /**
15
+ * 选项。
16
+ */
17
+ private options;
18
+ /**
19
+ * 文件数据辅助类,统一网页、小程序等平台的文件上传。
20
+ *
21
+ * @param originalFileData 原始文件数据
22
+ * @param options 若使用内部的 getFormData,则选项会被其使用
23
+ */
24
+ constructor(originalFileData: T, options?: AppendOptions);
25
+ /**
26
+ * 获取原始文件数据。
27
+ *
28
+ * @returns 原始文件数据
29
+ */
30
+ getOriginalFileData(): T;
31
+ /**
32
+ * 获取选项。
33
+ */
34
+ getOptions(): AppendOptions | undefined;
35
+ }
36
+ /**
37
+ * 解析请求数据,从请求数据中分离出普通数据和文件数据。
38
+ *
39
+ * @param [requestData] 要解析的请求数据
40
+ * @returns 包含普通数据(data)和文件数据(fileData)的对象,data、fileData 为空对象时,表示没有此类数据
41
+ */
42
+ export declare function parseRequestData(requestData?: any): {
43
+ data: any;
44
+ fileData: any;
45
+ };
46
+ /**
47
+ * 准备要传给请求函数的参数。
48
+ */
49
+ export declare function prepare(requestConfig: RequestConfig, requestData: any): RequestFunctionParams;
50
+ /**
51
+ * 顺序执行异步函数队列
52
+ * @param fns
53
+ * @param results
54
+ * @returns
55
+ */
56
+ export declare const asyncFnArrayOrderRun: <T = any>(fns: (() => Promise<T>)[], results?: T[]) => Promise<T[]>;
57
+ /**
58
+ * 并发请求队列
59
+ * @param fns
60
+ * @param limit
61
+ * @returns
62
+ */
63
+ export declare const autoAsyncSplitQueue: <T = any>(fns: (() => Promise<T>)[], limit?: number) => Promise<Awaited<T>[]>;