wormajs 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.
- package/LICENSE +21 -0
- package/README.md +49 -0
- package/dist/bin/actions.js +245 -0
- package/dist/bin/cli.js +27 -0
- package/dist/bin/progressRenderer.js +47 -0
- package/dist/bin/renderer.js +551 -0
- package/dist/bin/theme.js +26 -0
- package/dist/config.js +19 -0
- package/dist/constant.js +162 -0
- package/dist/core/WorkerPool.js +102 -0
- package/dist/core/loader/astLoader/generates/array.js +34 -0
- package/dist/core/loader/astLoader/generates/enum.js +61 -0
- package/dist/core/loader/astLoader/generates/group.js +41 -0
- package/dist/core/loader/astLoader/generates/index.js +71 -0
- package/dist/core/loader/astLoader/generates/interface.js +59 -0
- package/dist/core/loader/astLoader/generates/simple.js +67 -0
- package/dist/core/loader/astLoader/generates/tuple.js +54 -0
- package/dist/core/loader/astLoader/generates/type.js +2 -0
- package/dist/core/loader/astLoader/generates/utils.js +86 -0
- package/dist/core/loader/astLoader/helper.js +21 -0
- package/dist/core/loader/astLoader/index.js +24 -0
- package/dist/core/loader/astLoader/normalize/index.js +70 -0
- package/dist/core/loader/astLoader/normalize/normalizer.js +69 -0
- package/dist/core/loader/astLoader/normalize/rules/convertTypeArray.js +68 -0
- package/dist/core/loader/astLoader/normalize/rules/handleEmptyType.js +8 -0
- package/dist/core/loader/astLoader/normalize/rules/inferType.js +43 -0
- package/dist/core/loader/astLoader/normalize/rules/mergeAnyOf.js +45 -0
- package/dist/core/loader/astLoader/normalize/rules/normalizeCombiningKeywords.js +26 -0
- package/dist/core/loader/astLoader/normalize/rules/normalizeEnum.js +38 -0
- package/dist/core/loader/astLoader/normalize/rules/normalizeNullType.js +24 -0
- package/dist/core/loader/astLoader/normalize/rules/removeRedundantKeywords.js +27 -0
- package/dist/core/loader/astLoader/normalize/rules/simplifySingleType.js +8 -0
- package/dist/core/loader/astLoader/normalize/rules/validateSchema.js +14 -0
- package/dist/core/loader/astLoader/parsers/array.js +28 -0
- package/dist/core/loader/astLoader/parsers/enum.js +49 -0
- package/dist/core/loader/astLoader/parsers/forward/array.js +12 -0
- package/dist/core/loader/astLoader/parsers/forward/enum.js +10 -0
- package/dist/core/loader/astLoader/parsers/forward/group.js +12 -0
- package/dist/core/loader/astLoader/parsers/forward/index.js +20 -0
- package/dist/core/loader/astLoader/parsers/forward/object.js +12 -0
- package/dist/core/loader/astLoader/parsers/forward/tuple.js +11 -0
- package/dist/core/loader/astLoader/parsers/forward/type.js +2 -0
- package/dist/core/loader/astLoader/parsers/group.js +50 -0
- package/dist/core/loader/astLoader/parsers/index.js +66 -0
- package/dist/core/loader/astLoader/parsers/object.js +44 -0
- package/dist/core/loader/astLoader/parsers/reference.js +41 -0
- package/dist/core/loader/astLoader/parsers/simple.js +48 -0
- package/dist/core/loader/astLoader/parsers/tuple.js +36 -0
- package/dist/core/loader/astLoader/parsers/type.js +2 -0
- package/dist/core/loader/astLoader/parsers/utils.js +58 -0
- package/dist/core/loader/callingCodeLoader/helper.js +183 -0
- package/dist/core/loader/callingCodeLoader/index.js +40 -0
- package/dist/core/loader/index.js +20 -0
- package/dist/core/loader/schemaLoader/index.js +101 -0
- package/dist/core/loader/standardLoader/helper.js +142 -0
- package/dist/core/loader/standardLoader/index.js +38 -0
- package/dist/core/loader/standardLoader/standards.js +105 -0
- package/dist/core/parser/index.js +18 -0
- package/dist/core/parser/openApiParser/helper.js +165 -0
- package/dist/core/parser/openApiParser/index.js +14 -0
- package/dist/core/parser/templateParser/helper.js +333 -0
- package/dist/core/parser/templateParser/index.js +314 -0
- package/dist/core/workerPool/index.js +6 -0
- package/dist/core/workerPool/poolManager.js +45 -0
- package/dist/core/workerPool/swagger2Worker.js +24 -0
- package/dist/core/workerPool/worker.js +61 -0
- package/dist/createConfig.js +37 -0
- package/dist/defineConfig.js +6 -0
- package/dist/functions/getAutoTemplateType.js +37 -0
- package/dist/functions/getFrameworkTag.js +18 -0
- package/dist/functions/prepareConfig.js +41 -0
- package/dist/functions/readWormaRc.js +155 -0
- package/dist/functions/wormaJson.js +232 -0
- package/dist/generate.js +84 -0
- package/dist/helper/PluginDriver.js +98 -0
- package/dist/helper/comment.js +88 -0
- package/dist/helper/config/ConfigHelper.js +79 -0
- package/dist/helper/config/ConfigManager.js +88 -0
- package/dist/helper/config/GeneratorHelper.js +343 -0
- package/dist/helper/config/index.js +19 -0
- package/dist/helper/config/type.js +2 -0
- package/dist/helper/config/zType.js +170 -0
- package/dist/helper/document/index.js +160 -0
- package/dist/helper/index.js +23 -0
- package/dist/helper/logger/index.js +76 -0
- package/dist/helper/progress.js +66 -0
- package/dist/helper/template/index.js +475 -0
- package/dist/index.js +33 -0
- package/dist/plugins/createPlugin.js +30 -0
- package/dist/plugins/index.js +34 -0
- package/dist/plugins/presets/aiDoc.js +173 -0
- package/dist/plugins/presets/apifox.js +56 -0
- package/dist/plugins/presets/filterApi.js +129 -0
- package/dist/plugins/presets/importType.js +49 -0
- package/dist/plugins/presets/payloadModifier/hepler.js +195 -0
- package/dist/plugins/presets/payloadModifier/index.js +122 -0
- package/dist/plugins/presets/payloadModifier/type.js +2 -0
- package/dist/plugins/presets/platform.js +73 -0
- package/dist/plugins/presets/rename.js +209 -0
- package/dist/plugins/presets/tagModifier.js +104 -0
- package/dist/plugins/presets/utils.js +36 -0
- package/dist/readConfig.js +92 -0
- package/dist/resolveWorkspaces.js +83 -0
- package/dist/template/index.js +180 -0
- package/dist/template/presets/ai-doc/SKILL.md.handlebars +29 -0
- package/dist/template/presets/ai-doc/references/{tag}/{api}.md.handlebars +54 -0
- package/dist/template/presets/alova/common/#index.cjs.handlebars +12 -0
- package/dist/template/presets/alova/common/components.d.cts.handlebars +1 -0
- package/dist/template/presets/alova/common/helper.cjs.handlebars +13 -0
- package/dist/template/presets/alova/common/services/#index.cjs.handlebars +13 -0
- package/dist/template/presets/alova/common/services/{tag}.cjs.handlebars +28 -0
- package/dist/template/presets/alova/common/services/{tag}.d.cts.handlebars +15 -0
- package/dist/template/presets/alova/common/typed.d.cts.handlebars +1 -0
- package/dist/template/presets/alova/module/#index.js.handlebars +12 -0
- package/dist/template/presets/alova/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/alova/module/helper.js.handlebars +11 -0
- package/dist/template/presets/alova/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/alova/module/services/{tag}.d.ts.handlebars +15 -0
- package/dist/template/presets/alova/module/services/{tag}.js.handlebars +21 -0
- package/dist/template/presets/alova/module/typed.d.ts.handlebars +1 -0
- package/dist/template/presets/alova/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/alova/partials/build-payload-body.handlebars +22 -0
- package/dist/template/presets/alova/partials/comment.handlebars +19 -0
- package/dist/template/presets/alova/partials/components-body.handlebars +4 -0
- package/dist/template/presets/alova/partials/dts-extra-config.handlebars +8 -0
- package/dist/template/presets/alova/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/alova/partials/extract-responded.handlebars +11 -0
- package/dist/template/presets/alova/partials/stateshook-import.handlebars +9 -0
- package/dist/template/presets/alova/partials/stateshook-option.handlebars +9 -0
- package/dist/template/presets/alova/partials/typed-body.handlebars +43 -0
- package/dist/template/presets/alova/typescript/#index.ts.handlebars +14 -0
- package/dist/template/presets/alova/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/alova/typescript/helper.ts.handlebars +9 -0
- package/dist/template/presets/alova/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/alova/typescript/services/{tag}.ts.handlebars +35 -0
- package/dist/template/presets/alova/typescript/typed.ts.handlebars +1 -0
- package/dist/template/presets/alova-globals/common/#index.cjs.handlebars +41 -0
- package/dist/template/presets/alova-globals/common/apiDefinitions.cjs.handlebars +12 -0
- package/dist/template/presets/alova-globals/common/createApis.cjs.handlebars +48 -0
- package/dist/template/presets/alova-globals/common/globals.d.cts.handlebars +2 -0
- package/dist/template/presets/alova-globals/module/#index.js.handlebars +2 -0
- package/dist/template/presets/alova-globals/module/apiDefinitions.js.handlebars +12 -0
- package/dist/template/presets/alova-globals/module/createApis.js.handlebars +44 -0
- package/dist/template/presets/alova-globals/module/globals.d.ts.handlebars +2 -0
- package/dist/template/presets/alova-globals/partials/comment.handlebars +19 -0
- package/dist/template/presets/alova-globals/partials/createApis-proxy-js.handlebars +55 -0
- package/dist/template/presets/alova-globals/partials/globals-d-ts.handlebars +148 -0
- package/dist/template/presets/alova-globals/partials/index-esm.handlebars +38 -0
- package/dist/template/presets/alova-globals/partials/withConfigType-jsdoc.handlebars +22 -0
- package/dist/template/presets/alova-globals/typescript/#index.ts.handlebars +2 -0
- package/dist/template/presets/alova-globals/typescript/apiDefinitions.ts.handlebars +12 -0
- package/dist/template/presets/alova-globals/typescript/createApis.ts.handlebars +99 -0
- package/dist/template/presets/alova-globals/typescript/globals.d.ts.handlebars +2 -0
- package/dist/template/presets/axios/common/#index.cjs.handlebars +22 -0
- package/dist/template/presets/axios/common/components.d.cts.handlebars +1 -0
- package/dist/template/presets/axios/common/helper.cjs.handlebars +27 -0
- package/dist/template/presets/axios/common/services/#index.cjs.handlebars +13 -0
- package/dist/template/presets/axios/common/services/{tag}.cjs.handlebars +28 -0
- package/dist/template/presets/axios/common/services/{tag}.d.cts.handlebars +11 -0
- package/dist/template/presets/axios/module/#index.js.handlebars +20 -0
- package/dist/template/presets/axios/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/axios/module/helper.js.handlebars +25 -0
- package/dist/template/presets/axios/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/axios/module/services/{tag}.d.ts.handlebars +11 -0
- package/dist/template/presets/axios/module/services/{tag}.js.handlebars +20 -0
- package/dist/template/presets/axios/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/axios/partials/comment.handlebars +19 -0
- package/dist/template/presets/axios/partials/components-body.handlebars +4 -0
- package/dist/template/presets/axios/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/axios/partials/dts-types.handlebars +7 -0
- package/dist/template/presets/axios/typescript/#index.ts.handlebars +20 -0
- package/dist/template/presets/axios/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/axios/typescript/helper.ts.handlebars +28 -0
- package/dist/template/presets/axios/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/axios/typescript/services/{tag}.ts.handlebars +31 -0
- package/dist/template/presets/config/common/worma.config.js.handlebars +9 -0
- package/dist/template/presets/config/module/worma.config.js.handlebars +9 -0
- package/dist/template/presets/config/partials/generator-content.handlebars +45 -0
- package/dist/template/presets/config/typescript/worma.config.ts.handlebars +9 -0
- package/dist/template/presets/fetch/common/#index.cjs.handlebars +17 -0
- package/dist/template/presets/fetch/common/FetchClient.cjs.handlebars +48 -0
- package/dist/template/presets/fetch/common/components.d.cts.handlebars +1 -0
- package/dist/template/presets/fetch/common/helper.cjs.handlebars +27 -0
- package/dist/template/presets/fetch/common/services/#index.cjs.handlebars +13 -0
- package/dist/template/presets/fetch/common/services/{tag}.cjs.handlebars +23 -0
- package/dist/template/presets/fetch/common/services/{tag}.d.cts.handlebars +10 -0
- package/dist/template/presets/fetch/module/#index.js.handlebars +15 -0
- package/dist/template/presets/fetch/module/FetchClient.js.handlebars +46 -0
- package/dist/template/presets/fetch/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/fetch/module/helper.js.handlebars +25 -0
- package/dist/template/presets/fetch/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/fetch/module/services/{tag}.d.ts.handlebars +10 -0
- package/dist/template/presets/fetch/module/services/{tag}.js.handlebars +15 -0
- package/dist/template/presets/fetch/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/fetch/partials/comment.handlebars +19 -0
- package/dist/template/presets/fetch/partials/components-body.handlebars +4 -0
- package/dist/template/presets/fetch/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/fetch/partials/dts-types.handlebars +7 -0
- package/dist/template/presets/fetch/typescript/#index.ts.handlebars +15 -0
- package/dist/template/presets/fetch/typescript/FetchClient.ts.handlebars +59 -0
- package/dist/template/presets/fetch/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/fetch/typescript/helper.ts.handlebars +28 -0
- package/dist/template/presets/fetch/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/fetch/typescript/services/{tag}.ts.handlebars +25 -0
- package/dist/template/presets/ky/module/#index.js.handlebars +14 -0
- package/dist/template/presets/ky/module/components.d.ts.handlebars +1 -0
- package/dist/template/presets/ky/module/helper.js.handlebars +27 -0
- package/dist/template/presets/ky/module/services/#index.js.handlebars +9 -0
- package/dist/template/presets/ky/module/services/{tag}.d.ts.handlebars +11 -0
- package/dist/template/presets/ky/module/services/{tag}.js.handlebars +19 -0
- package/dist/template/presets/ky/partials/api-jsdoc.handlebars +44 -0
- package/dist/template/presets/ky/partials/comment.handlebars +19 -0
- package/dist/template/presets/ky/partials/components-body.handlebars +4 -0
- package/dist/template/presets/ky/partials/dts-fn-declare.handlebars +1 -0
- package/dist/template/presets/ky/partials/dts-types.handlebars +9 -0
- package/dist/template/presets/ky/typescript/#index.ts.handlebars +14 -0
- package/dist/template/presets/ky/typescript/components.d.ts.handlebars +1 -0
- package/dist/template/presets/ky/typescript/helper.ts.handlebars +30 -0
- package/dist/template/presets/ky/typescript/services/#index.ts.handlebars +9 -0
- package/dist/template/presets/ky/typescript/services/{tag}.ts.handlebars +30 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/type/api.js +14 -0
- package/dist/type/ast.js +24 -0
- package/dist/type/base.js +17 -0
- package/dist/type/index.js +20 -0
- package/dist/type/lib.js +17 -0
- package/dist/type/openapi.js +2 -0
- package/dist/utils/base.js +212 -0
- package/dist/utils/format.js +64 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/openapi.js +417 -0
- package/dist/utils/readPackageJson.js +35 -0
- package/dist/utils/template.js +93 -0
- package/package.json +88 -0
- package/typings/index.d.ts +512 -0
- package/typings/plugins.d.ts +727 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
import type {
|
|
3
|
+
Alova,
|
|
4
|
+
MethodType,
|
|
5
|
+
AlovaGenerics,
|
|
6
|
+
AlovaMethodCreateConfig,
|
|
7
|
+
} from 'alova';
|
|
8
|
+
import { Method } from 'alova';
|
|
9
|
+
import apiDefinitions from './apiDefinitions';
|
|
10
|
+
|
|
11
|
+
const cache = Object.create(null);
|
|
12
|
+
const createFunctionalProxy = (
|
|
13
|
+
array: (string | symbol)[],
|
|
14
|
+
alovaInstance: Alova<AlovaGenerics>,
|
|
15
|
+
configMap: any
|
|
16
|
+
) => {
|
|
17
|
+
const apiPathKey = array.join('.') as keyof typeof apiDefinitions;
|
|
18
|
+
if (cache[apiPathKey]) {
|
|
19
|
+
return cache[apiPathKey];
|
|
20
|
+
}
|
|
21
|
+
const proxy = new Proxy(function () {}, {
|
|
22
|
+
get(_, property) {
|
|
23
|
+
const newArray = [...array, property];
|
|
24
|
+
return createFunctionalProxy(newArray, alovaInstance, configMap);
|
|
25
|
+
},
|
|
26
|
+
apply(_, __, [config]) {
|
|
27
|
+
const apiItem = apiDefinitions[apiPathKey];
|
|
28
|
+
if (!apiItem) {
|
|
29
|
+
throw new Error(`the api path of \`${apiPathKey}\` is not found`);
|
|
30
|
+
}
|
|
31
|
+
const mergedConfig = {
|
|
32
|
+
...configMap[apiPathKey],
|
|
33
|
+
...config
|
|
34
|
+
};
|
|
35
|
+
const [method, url] = apiItem;
|
|
36
|
+
const pathParams = mergedConfig.pathParams;
|
|
37
|
+
const urlReplaced = url!.replace(/\{([^}]+)\}/g, (_, key) => {
|
|
38
|
+
const pathParam = pathParams[key];
|
|
39
|
+
return pathParam;
|
|
40
|
+
});
|
|
41
|
+
delete mergedConfig.pathParams;
|
|
42
|
+
let data = mergedConfig.data;
|
|
43
|
+
if (Object.prototype.toString.call(data) === '[object Object]' && typeof FormData !== 'undefined') {
|
|
44
|
+
let hasBlobData = false;
|
|
45
|
+
const formData = new FormData();
|
|
46
|
+
for (const key in data) {
|
|
47
|
+
if(Array.isArray(data[key])){
|
|
48
|
+
for (const ele of data[key]) {
|
|
49
|
+
formData.append(key, ele);
|
|
50
|
+
if (ele instanceof Blob) {
|
|
51
|
+
hasBlobData = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
formData.append(key, data[key]);
|
|
56
|
+
if (data[key] instanceof Blob) {
|
|
57
|
+
hasBlobData = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
data = hasBlobData ? formData : data;
|
|
62
|
+
}
|
|
63
|
+
return new Method(method!.toUpperCase() as MethodType, alovaInstance, urlReplaced, mergedConfig, data);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
cache[apiPathKey] = proxy;
|
|
67
|
+
return proxy;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const createApis = (alovaInstance: Alova<AlovaGenerics>, configMap: any) =>{
|
|
71
|
+
const Apis = new Proxy(
|
|
72
|
+
{} as {{{config.global}}},
|
|
73
|
+
{
|
|
74
|
+
get(_, property) {
|
|
75
|
+
return createFunctionalProxy([property], alovaInstance, configMap);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
return Apis;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const mountApis = (Apis: {{{config.global}}}) =>{
|
|
83
|
+
(({{{config.globalHost}}}) as any).{{{config.global}}} = Apis;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
type MethodConfig<T> = AlovaMethodCreateConfig<typeof import('./index')['alovaInstance'] extends Alova<infer AG> ? AG : any, any, T>;
|
|
87
|
+
type APISofParameters<Tag extends string, Url extends string> = Tag extends keyof {{{config.global}}}
|
|
88
|
+
? Url extends keyof {{{config.global}}}[Tag]
|
|
89
|
+
? {{{config.global}}}[Tag][Url] extends (...args: any) => any
|
|
90
|
+
? Parameters<{{{config.global}}}[Tag][Url]>
|
|
91
|
+
: any
|
|
92
|
+
: any
|
|
93
|
+
: any;
|
|
94
|
+
type MethodsConfigMap = {
|
|
95
|
+
[P in keyof typeof import('./apiDefinitions').default]?: MethodConfig<
|
|
96
|
+
P extends `${infer Tag}.${infer Url}` ? Parameters<NonNullable<APISofParameters<Tag, Url>[0]>['transform']>[0] : any
|
|
97
|
+
>;
|
|
98
|
+
};
|
|
99
|
+
export const withConfigType = <Config extends MethodsConfigMap>(config: Config) => config;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
|
|
4
|
+
const axiosInstance = axios.create({
|
|
5
|
+
baseURL: '{{{baseUrl}}}',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
axiosInstance.interceptors.request.use(
|
|
9
|
+
config => {
|
|
10
|
+
return config;
|
|
11
|
+
},
|
|
12
|
+
error => Promise.reject(error),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
axiosInstance.interceptors.response.use(
|
|
16
|
+
response => {
|
|
17
|
+
return response.data;
|
|
18
|
+
},
|
|
19
|
+
error => Promise.reject(error),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
module.exports = { axiosInstance };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{{> components-body}}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
function buildPayload(url, defaultConfig, apiName, config) {
|
|
3
|
+
const mergedConfig = { ...defaultConfig[apiName], ...config };
|
|
4
|
+
const pathParams = mergedConfig.pathParams;
|
|
5
|
+
const resolvedUrl = url.replace(/\{([^}]+)\}/g, (_, key) => {
|
|
6
|
+
return pathParams?.[key] ?? _;
|
|
7
|
+
});
|
|
8
|
+
delete mergedConfig.pathParams;
|
|
9
|
+
let data = mergedConfig.data;
|
|
10
|
+
if (Object.prototype.toString.call(data) === '[object Object]' && typeof FormData !== 'undefined') {
|
|
11
|
+
let hasBlobData = false;
|
|
12
|
+
const formData = new FormData();
|
|
13
|
+
for (const key in data) {
|
|
14
|
+
formData.append(key, data[key]);
|
|
15
|
+
if (data[key] instanceof Blob) {
|
|
16
|
+
hasBlobData = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
data = hasBlobData ? formData : data;
|
|
20
|
+
mergedConfig.data = data;
|
|
21
|
+
}
|
|
22
|
+
return { url: resolvedUrl, mergedConfig };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const setDefaultConfig = (_, configMap) => configMap;
|
|
26
|
+
|
|
27
|
+
module.exports = { buildPayload, setDefaultConfig };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
const { setDefaultConfig } = require('../helper.cjs');
|
|
3
|
+
{{#each tagedApis}}
|
|
4
|
+
const {{{tagName}}} = require('./{{{tagName}}}.cjs');
|
|
5
|
+
{{/each}}
|
|
6
|
+
|
|
7
|
+
{{#each tagedApis}}
|
|
8
|
+
const {{{tagName}}}DefaultConfig = setDefaultConfig({{{tagName}}}, {});
|
|
9
|
+
{{/each}}
|
|
10
|
+
|
|
11
|
+
{{#each tagedApis}}
|
|
12
|
+
module.exports.{{{tagName}}}DefaultConfig = {{{tagName}}}DefaultConfig;
|
|
13
|
+
{{/each}}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
const { axiosInstance } = require('../index.cjs');
|
|
3
|
+
const { buildPayload } = require('../helper.cjs');
|
|
4
|
+
const _index = require('./index.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
{{#each tagedApis}}
|
|
8
|
+
{{#each apis}}
|
|
9
|
+
{{> api-jsdoc}}
|
|
10
|
+
function {{{name}}}(config = {}) {
|
|
11
|
+
const { url, mergedConfig } = buildPayload('{{{path}}}', _index.{{{tag}}}DefaultConfig, {{{name}}}.name, config);
|
|
12
|
+
return axiosInstance({
|
|
13
|
+
method: '{{method}}',
|
|
14
|
+
url,
|
|
15
|
+
...mergedConfig,{{#if (eq response "Blob")}}
|
|
16
|
+
responseType: 'blob',{{/if}}
|
|
17
|
+
}){{#if (eq response "Blob")}}.then(data => data instanceof Blob ? data : new Blob([data])){{/if}};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
{{/each}}
|
|
21
|
+
{{/each}}
|
|
22
|
+
module.exports = {
|
|
23
|
+
{{#each tagedApis}}
|
|
24
|
+
{{#each apis}}
|
|
25
|
+
{{{name}}},
|
|
26
|
+
{{/each}}
|
|
27
|
+
{{/each}}
|
|
28
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
export const axiosInstance = axios.create({
|
|
5
|
+
baseURL: '{{{baseUrl}}}',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
axiosInstance.interceptors.request.use(
|
|
9
|
+
config => {
|
|
10
|
+
return config;
|
|
11
|
+
},
|
|
12
|
+
error => Promise.reject(error),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
axiosInstance.interceptors.response.use(
|
|
16
|
+
response => {
|
|
17
|
+
return response.data;
|
|
18
|
+
},
|
|
19
|
+
error => Promise.reject(error),
|
|
20
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{{> components-body}}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
export function buildPayload(url, defaultConfig, apiName, config) {
|
|
3
|
+
const mergedConfig = { ...defaultConfig[apiName], ...config };
|
|
4
|
+
const pathParams = mergedConfig.pathParams;
|
|
5
|
+
const resolvedUrl = url.replace(/\{([^}]+)\}/g, (_, key) => {
|
|
6
|
+
return pathParams?.[key] ?? _;
|
|
7
|
+
});
|
|
8
|
+
delete mergedConfig.pathParams;
|
|
9
|
+
let data = mergedConfig.data;
|
|
10
|
+
if (Object.prototype.toString.call(data) === '[object Object]' && typeof FormData !== 'undefined') {
|
|
11
|
+
let hasBlobData = false;
|
|
12
|
+
const formData = new FormData();
|
|
13
|
+
for (const key in data) {
|
|
14
|
+
formData.append(key, data[key]);
|
|
15
|
+
if (data[key] instanceof Blob) {
|
|
16
|
+
hasBlobData = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
data = hasBlobData ? formData : data;
|
|
20
|
+
mergedConfig.data = data;
|
|
21
|
+
}
|
|
22
|
+
return { url: resolvedUrl, mergedConfig };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const setDefaultConfig = (_, configMap) => configMap;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
import { setDefaultConfig } from '../helper.js';
|
|
3
|
+
{{#each tagedApis}}
|
|
4
|
+
import * as {{{tagName}}} from './{{{tagName}}}.js';
|
|
5
|
+
{{/each}}
|
|
6
|
+
|
|
7
|
+
{{#each tagedApis}}
|
|
8
|
+
export const {{{tagName}}}DefaultConfig = setDefaultConfig({{{tagName}}}, {});
|
|
9
|
+
{{/each}}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
import { axiosInstance } from '../index.js';
|
|
3
|
+
import { buildPayload } from '../helper.js';
|
|
4
|
+
import { {{currentTag.tagName}}DefaultConfig } from './index.js';
|
|
5
|
+
|
|
6
|
+
{{#each tagedApis}}
|
|
7
|
+
{{#each apis}}
|
|
8
|
+
{{> api-jsdoc}}
|
|
9
|
+
export function {{{name}}}(config = {}) {
|
|
10
|
+
const { url, mergedConfig } = buildPayload('{{{path}}}', {{{tag}}}DefaultConfig, {{{name}}}.name, config);
|
|
11
|
+
return axiosInstance({
|
|
12
|
+
method: '{{method}}',
|
|
13
|
+
url,
|
|
14
|
+
...mergedConfig,{{#if (eq response "Blob")}}
|
|
15
|
+
responseType: 'blob',{{/if}}
|
|
16
|
+
}){{#if (eq response "Blob")}}.then(data => data instanceof Blob ? data : new Blob([data])){{/if}};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
{{/each}}
|
|
20
|
+
{{/each}}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ---
|
|
3
|
+
*
|
|
4
|
+
* [{{method}}] {{{summary}}}
|
|
5
|
+
*
|
|
6
|
+
* **path:** {{{path}}}
|
|
7
|
+
*
|
|
8
|
+
{{#if pathParametersComment}}
|
|
9
|
+
* ---
|
|
10
|
+
*
|
|
11
|
+
* **Path Parameters**
|
|
12
|
+
* ```ts
|
|
13
|
+
* type PathParameters = {{{pathParametersComment}}}
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
{{/if}}
|
|
17
|
+
{{#if queryParametersComment}}
|
|
18
|
+
* ---
|
|
19
|
+
*
|
|
20
|
+
* **Query Parameters**
|
|
21
|
+
* ```ts
|
|
22
|
+
* type QueryParameters = {{{queryParametersComment}}}
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
{{/if}}
|
|
26
|
+
{{#if requestBodyComment}}
|
|
27
|
+
* ---
|
|
28
|
+
*
|
|
29
|
+
* **RequestBody**
|
|
30
|
+
* ```ts
|
|
31
|
+
* type RequestBody = {{{requestBodyComment}}}
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
{{/if}}
|
|
35
|
+
{{#if responseComment}}
|
|
36
|
+
* ---
|
|
37
|
+
*
|
|
38
|
+
* **Response**
|
|
39
|
+
* ```ts
|
|
40
|
+
* type Response = {{{responseComment}}}
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
{{/if}}
|
|
44
|
+
*/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* {{title}} - version {{version}}
|
|
5
|
+
*
|
|
6
|
+
* {{description}}
|
|
7
|
+
*
|
|
8
|
+
* OpenAPI version: {{openapi}}
|
|
9
|
+
*
|
|
10
|
+
{{#contact}}
|
|
11
|
+
* Contact: {{#contact.name}}[{{contact.name}}]{{/contact.name}}{{#contact.url}}{{{contact.url}}}{{/contact.url}}{{^contact.url}}{{{contact.email}}}{{/contact.url}}
|
|
12
|
+
{{/contact}}
|
|
13
|
+
*
|
|
14
|
+
* NOTE: This file is auto generated by the alova's vscode plugin.
|
|
15
|
+
*
|
|
16
|
+
* https://alova.js.org/devtools/vscode
|
|
17
|
+
*
|
|
18
|
+
* **Do not edit the file manually.**
|
|
19
|
+
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function {{{name}}}(config: {{{name}}}ExtraConfig): Promise<{{{name}}}Response>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type {{{name}}}Response = {{processType response @root.componentNames}};
|
|
2
|
+
type {{{name}}}ExtraConfig = Omit<AxiosRequestConfig, 'data' | 'params'> & {
|
|
3
|
+
{{#if pathParameters}}pathParams: {{processType pathParameters @root.componentNames}};
|
|
4
|
+
{{/if}}{{#if queryParameters}}params: {{processType queryParameters @root.componentNames}};
|
|
5
|
+
{{/if}}{{#if requestBody}}data: {{processType requestBody @root.componentNames}};
|
|
6
|
+
{{/if}}
|
|
7
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
export const axiosInstance = axios.create({
|
|
5
|
+
baseURL: '{{{baseUrl}}}',
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
axiosInstance.interceptors.request.use(
|
|
9
|
+
config => {
|
|
10
|
+
return config;
|
|
11
|
+
},
|
|
12
|
+
error => Promise.reject(error),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
axiosInstance.interceptors.response.use(
|
|
16
|
+
response => {
|
|
17
|
+
return response.data;
|
|
18
|
+
},
|
|
19
|
+
error => Promise.reject(error),
|
|
20
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{{> components-body}}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
export function buildPayload(url: string, defaultConfig: Record<string, any>, apiName: string, config: any) {
|
|
3
|
+
const mergedConfig: any = { ...defaultConfig[apiName], ...config };
|
|
4
|
+
const pathParams = mergedConfig.pathParams;
|
|
5
|
+
const resolvedUrl = url.replace(/\{([^}]+)\}/g, (_, key: string) => {
|
|
6
|
+
return pathParams?.[key] ?? _;
|
|
7
|
+
});
|
|
8
|
+
delete mergedConfig.pathParams;
|
|
9
|
+
let data = mergedConfig.data;
|
|
10
|
+
if (Object.prototype.toString.call(data) === '[object Object]' && typeof FormData !== 'undefined') {
|
|
11
|
+
let hasBlobData = false;
|
|
12
|
+
const formData = new FormData();
|
|
13
|
+
for (const key in data) {
|
|
14
|
+
formData.append(key, data[key]);
|
|
15
|
+
if (data[key] instanceof Blob) {
|
|
16
|
+
hasBlobData = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
data = hasBlobData ? formData : data;
|
|
20
|
+
mergedConfig.data = data;
|
|
21
|
+
}
|
|
22
|
+
return { url: resolvedUrl, mergedConfig };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const setDefaultConfig = <
|
|
26
|
+
ApiMap extends Record<string, (config: any) => any>,
|
|
27
|
+
ConfigMap extends { [K in keyof ApiMap]?: Partial<Parameters<ApiMap[K]>[0]> },
|
|
28
|
+
>(_: ApiMap, configMap: ConfigMap) => configMap;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
import { setDefaultConfig } from '../helper';
|
|
3
|
+
{{#each tagedApis}}
|
|
4
|
+
import * as {{{tagName}}} from './{{{tagName}}}';
|
|
5
|
+
{{/each}}
|
|
6
|
+
|
|
7
|
+
{{#each tagedApis}}
|
|
8
|
+
export const {{{tagName}}}DefaultConfig = setDefaultConfig({{{tagName}}}, {});
|
|
9
|
+
{{/each}}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
3
|
+
import { axiosInstance } from '../index';
|
|
4
|
+
import { buildPayload } from '../helper';
|
|
5
|
+
import type * as ComponentTypes from '../components';
|
|
6
|
+
{{#each tagedApis}}
|
|
7
|
+
import { {{{tagName}}}DefaultConfig } from '.';
|
|
8
|
+
{{/each}}
|
|
9
|
+
|
|
10
|
+
{{#each tagedApis}}
|
|
11
|
+
{{#each apis}}
|
|
12
|
+
type {{{name}}}Response = {{processType response @root.componentNames}};
|
|
13
|
+
type {{{name}}}ExtraConfig = Omit<AxiosRequestConfig, 'data' | 'params'> & {
|
|
14
|
+
{{#if pathParameters}}pathParams: {{processType pathParameters @root.componentNames}};
|
|
15
|
+
{{/if}}{{#if queryParameters}}params: {{processType queryParameters @root.componentNames}};
|
|
16
|
+
{{/if}}{{#if requestBody}}data: {{processType requestBody @root.componentNames}};
|
|
17
|
+
{{/if}}
|
|
18
|
+
};
|
|
19
|
+
{{> api-jsdoc}}
|
|
20
|
+
export function {{{name}}}(config: {{{name}}}ExtraConfig): Promise<{{{name}}}Response> {
|
|
21
|
+
const { url, mergedConfig } = buildPayload('{{{path}}}', {{{tag}}}DefaultConfig, {{{name}}}.name, config);
|
|
22
|
+
return axiosInstance<{{{name}}}Response>({
|
|
23
|
+
method: '{{method}}',
|
|
24
|
+
url,
|
|
25
|
+
...mergedConfig,{{#if (eq response "Blob")}}
|
|
26
|
+
responseType: 'blob',{{/if}}
|
|
27
|
+
}){{#if (eq response "Blob")}}.then((data: any) => data instanceof Blob ? data : new Blob([data])){{/if}} as Promise<{{{name}}}Response>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
{{/each}}
|
|
31
|
+
{{/each}}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const { defineConfig } = require('worma');
|
|
2
|
+
const { platform, aiDoc{{#if templateImport}}, {{{templateImport}}}{{/if}} } = require('worma/plugin');
|
|
3
|
+
|
|
4
|
+
// For more config detailed visit:
|
|
5
|
+
// https://github.com/alovajs/devtools
|
|
6
|
+
|
|
7
|
+
module.exports = defineConfig({
|
|
8
|
+
{{> generator-content}}
|
|
9
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineConfig } from 'worma';
|
|
2
|
+
import { platform, aiDoc{{#if templateImport}}, {{{templateImport}}}{{/if}} } from 'worma/plugin';
|
|
3
|
+
|
|
4
|
+
// For more config detailed visit:
|
|
5
|
+
// https://github.com/alovajs/devtools
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
{{> generator-content}}
|
|
9
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
generator: [
|
|
2
|
+
{
|
|
3
|
+
/**
|
|
4
|
+
* file input. support:
|
|
5
|
+
* 1. openapi json file url
|
|
6
|
+
* 2. local file
|
|
7
|
+
* 3. string array — each URL will be tried in order, first success wins
|
|
8
|
+
*/
|
|
9
|
+
input: 'http://localhost:3000',
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* output path of interface file and type file.
|
|
13
|
+
* Multiple generators cannot have the same address, otherwise the generated code will overwrite each other.
|
|
14
|
+
*/
|
|
15
|
+
output: 'src/api',
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* platform plugin: auto-resolves OpenAPI file URLs from platform type.
|
|
19
|
+
* Uses config.input as base URL to construct candidate OpenAPI endpoints.
|
|
20
|
+
*/
|
|
21
|
+
plugins: [platform('swagger'), aiDoc({ installSkill: true }), {{{templateCall}}}],
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* the mediaType of the generated response data. default is `application/json`
|
|
25
|
+
*/
|
|
26
|
+
// responseMediaType: 'application/json',
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* the bodyMediaType of the generated request body data. default is `application/json`
|
|
30
|
+
*/
|
|
31
|
+
// bodyMediaType: 'application/json',
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* type of generated code. The options are `auto/ts/typescript/module/commonjs`
|
|
35
|
+
*/
|
|
36
|
+
// type: 'auto',
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* filter or convert the generated api information, return an apiDescriptor, if this function is not specified, the apiDescriptor object is not converted
|
|
40
|
+
*/
|
|
41
|
+
// handleApi: apiDescriptor => {
|
|
42
|
+
// return apiDescriptor;
|
|
43
|
+
// }
|
|
44
|
+
}
|
|
45
|
+
]
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineConfig } from 'worma';
|
|
2
|
+
import { platform, aiDoc{{#if templateImport}}, {{{templateImport}}}{{/if}} } from 'worma/plugin';
|
|
3
|
+
|
|
4
|
+
// For more config detailed visit:
|
|
5
|
+
// https://github.com/alovajs/devtools
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
{{> generator-content}}
|
|
9
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
const { FetchClient } = require('./FetchClient.cjs');
|
|
3
|
+
|
|
4
|
+
const fetchClient = new FetchClient({ baseURL: '{{{baseUrl}}}' });
|
|
5
|
+
|
|
6
|
+
fetchClient.addRequestInterceptor(config => {
|
|
7
|
+
return config;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
fetchClient.addResponseInterceptor(async (response, config) => {
|
|
11
|
+
if (!response.ok) {
|
|
12
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
13
|
+
}
|
|
14
|
+
return config.blob ? response.blob() : response.json();
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
module.exports = { fetchClient };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
class FetchClient {
|
|
3
|
+
#requestInterceptors = [];
|
|
4
|
+
#responseInterceptors = [];
|
|
5
|
+
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = config;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get baseURL() {
|
|
11
|
+
return this.config.baseURL;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
addRequestInterceptor(fn) {
|
|
15
|
+
this.#requestInterceptors.push(fn);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
addResponseInterceptor(fn) {
|
|
20
|
+
this.#responseInterceptors.push(fn);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async request(path, init = {}) {
|
|
25
|
+
const { params, ...rest } = init;
|
|
26
|
+
const base = this.config.baseURL + path;
|
|
27
|
+
let url = base;
|
|
28
|
+
if (params) {
|
|
29
|
+
url += (base.includes('?') ? '&' : '?') + new URLSearchParams(params).toString();
|
|
30
|
+
}
|
|
31
|
+
if (rest.body && Object.prototype.toString.call(rest.body) === '[object Object]') {
|
|
32
|
+
rest.body = JSON.stringify(rest.body);
|
|
33
|
+
rest.headers = { 'Content-Type': 'application/json', ...rest.headers };
|
|
34
|
+
}
|
|
35
|
+
let config = { ...rest, url, params };
|
|
36
|
+
for (const interceptor of this.#requestInterceptors) {
|
|
37
|
+
config = await interceptor(config);
|
|
38
|
+
}
|
|
39
|
+
const { url: resolvedUrl, params: _params, ...fetchInit } = config;
|
|
40
|
+
let response = await fetch(resolvedUrl, fetchInit);
|
|
41
|
+
for (const interceptor of this.#responseInterceptors) {
|
|
42
|
+
response = await interceptor(response, config);
|
|
43
|
+
}
|
|
44
|
+
return response;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = { FetchClient };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{{> components-body}}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{{> comment}}
|
|
2
|
+
function buildPayload(url, defaultConfig, apiName, config) {
|
|
3
|
+
const mergedConfig = { ...defaultConfig[apiName], ...config };
|
|
4
|
+
const pathParams = mergedConfig.pathParams;
|
|
5
|
+
const resolvedUrl = url.replace(/\{([^}]+)\}/g, (_, key) => {
|
|
6
|
+
return pathParams?.[key] ?? _;
|
|
7
|
+
});
|
|
8
|
+
delete mergedConfig.pathParams;
|
|
9
|
+
let body = mergedConfig.body;
|
|
10
|
+
if (Object.prototype.toString.call(body) === '[object Object]' && typeof FormData !== 'undefined') {
|
|
11
|
+
let hasBlobData = false;
|
|
12
|
+
const formData = new FormData();
|
|
13
|
+
for (const key in body) {
|
|
14
|
+
formData.append(key, body[key]);
|
|
15
|
+
if (body[key] instanceof Blob) {
|
|
16
|
+
hasBlobData = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
body = hasBlobData ? formData : body;
|
|
20
|
+
mergedConfig.body = body;
|
|
21
|
+
}
|
|
22
|
+
return { url: resolvedUrl, mergedConfig };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const setDefaultConfig = (_, configMap) => configMap;
|
|
26
|
+
|
|
27
|
+
module.exports = { buildPayload, setDefaultConfig };
|