wormajs 0.2.5 → 0.2.6
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/dist/constant.js +20 -20
- package/dist/core/loader/astLoader/generates/tuple.js +1 -1
- package/dist/core/loader/astLoader/normalize/index.js +1 -1
- package/dist/core/loader/astLoader/normalize/normalizer.js +8 -8
- package/dist/core/loader/astLoader/normalize/rules/mergeAnyOf.js +9 -8
- package/dist/core/loader/astLoader/normalize/rules/normalizeCombiningKeywords.js +6 -6
- package/dist/core/loader/astLoader/normalize/rules/normalizeNullType.js +1 -1
- package/dist/core/loader/astLoader/parsers/const.js +4 -4
- package/dist/core/loader/astLoader/parsers/enum.js +3 -3
- package/dist/core/loader/astLoader/parsers/forward/array.js +3 -3
- package/dist/core/loader/astLoader/parsers/forward/const.js +3 -3
- package/dist/core/loader/astLoader/parsers/forward/enum.js +2 -2
- package/dist/core/loader/astLoader/parsers/forward/group.js +4 -4
- package/dist/core/loader/astLoader/parsers/forward/object.js +4 -4
- package/dist/core/loader/astLoader/parsers/forward/tuple.js +3 -3
- package/dist/core/loader/astLoader/parsers/group.js +1 -1
- package/dist/core/loader/astLoader/parsers/tuple.js +2 -2
- package/dist/core/loader/standardLoader/helper.js +1 -1
- package/dist/core/parser/templateParser/helper.js +5 -5
- package/dist/core/parser/templateParser/index.js +5 -5
- package/dist/functions/wormaJson.js +2 -2
- package/dist/helper/config/ConfigManager.js +10 -10
- package/dist/helper/config/zType.js +1 -1
- package/dist/helper/document/index.js +11 -11
- package/dist/helper/logger/index.js +1 -1
- package/dist/helper/template/index.js +9 -9
- package/dist/plugins/presets/aiDoc.js +1 -1
- package/dist/plugins/presets/apifox.js +2 -2
- package/dist/plugins/presets/payloadModifier/index.js +3 -0
- package/dist/plugins/presets/rename.js +5 -0
- package/dist/readConfig.js +9 -9
- package/dist/template/index.js +14 -14
- package/dist/template/presets/ai-doc/SKILL.md.handlebars +3 -3
- package/dist/template/presets/alova/common/helper.cjs.handlebars +18 -3
- package/dist/template/presets/alova/common/services/#index.cjs.handlebars +2 -2
- package/dist/template/presets/alova/common/services/{tag}.cjs.handlebars +7 -9
- package/dist/template/presets/alova/common/services/{tag}.d.cts.handlebars +5 -7
- package/dist/template/presets/alova/module/helper.js.handlebars +17 -2
- package/dist/template/presets/alova/module/services/#index.js.handlebars +1 -1
- package/dist/template/presets/alova/module/services/{tag}.d.ts.handlebars +5 -7
- package/dist/template/presets/alova/module/services/{tag}.js.handlebars +6 -6
- package/dist/template/presets/alova/partials/comment.handlebars +11 -2
- package/dist/template/presets/alova/partials/extract-responded.handlebars +3 -3
- package/dist/template/presets/alova/partials/typed-body.handlebars +3 -1
- package/dist/template/presets/alova/typescript/helper.ts.handlebars +11 -6
- package/dist/template/presets/alova/typescript/services/#index.ts.handlebars +1 -1
- package/dist/template/presets/alova/typescript/services/{tag}.ts.handlebars +6 -8
- package/dist/template/presets/alova-globals/partials/comment.handlebars +11 -2
- package/dist/template/presets/alova-globals/partials/globals-d-ts.handlebars +1 -1
- package/dist/template/presets/axios/common/helper.cjs.handlebars +18 -3
- package/dist/template/presets/axios/common/services/#index.cjs.handlebars +2 -2
- package/dist/template/presets/axios/common/services/{tag}.cjs.handlebars +25 -28
- package/dist/template/presets/axios/common/services/{tag}.d.cts.handlebars +1 -3
- package/dist/template/presets/axios/module/helper.js.handlebars +17 -2
- package/dist/template/presets/axios/module/services/#index.js.handlebars +2 -2
- package/dist/template/presets/axios/module/services/{tag}.d.ts.handlebars +1 -3
- package/dist/template/presets/axios/module/services/{tag}.js.handlebars +20 -20
- package/dist/template/presets/axios/partials/comment.handlebars +11 -2
- package/dist/template/presets/axios/typescript/helper.ts.handlebars +11 -6
- package/dist/template/presets/axios/typescript/services/#index.ts.handlebars +1 -1
- package/dist/template/presets/axios/typescript/services/{tag}.ts.handlebars +6 -8
- package/dist/template/presets/fetch/common/helper.cjs.handlebars +18 -3
- package/dist/template/presets/fetch/common/services/#index.cjs.handlebars +2 -2
- package/dist/template/presets/fetch/common/services/{tag}.cjs.handlebars +6 -9
- package/dist/template/presets/fetch/common/services/{tag}.d.cts.handlebars +1 -3
- package/dist/template/presets/fetch/module/helper.js.handlebars +17 -2
- package/dist/template/presets/fetch/module/services/#index.js.handlebars +2 -2
- package/dist/template/presets/fetch/module/services/{tag}.d.ts.handlebars +1 -3
- package/dist/template/presets/fetch/module/services/{tag}.js.handlebars +6 -6
- package/dist/template/presets/fetch/partials/comment.handlebars +11 -2
- package/dist/template/presets/fetch/typescript/helper.ts.handlebars +11 -6
- package/dist/template/presets/fetch/typescript/services/#index.ts.handlebars +1 -1
- package/dist/template/presets/fetch/typescript/services/{tag}.ts.handlebars +6 -8
- package/dist/template/presets/ky/module/helper.js.handlebars +17 -2
- package/dist/template/presets/ky/module/services/#index.js.handlebars +2 -2
- package/dist/template/presets/ky/module/services/{tag}.d.ts.handlebars +1 -3
- package/dist/template/presets/ky/module/services/{tag}.js.handlebars +6 -6
- package/dist/template/presets/ky/partials/comment.handlebars +11 -2
- package/dist/template/presets/ky/typescript/helper.ts.handlebars +11 -6
- package/dist/template/presets/ky/typescript/services/#index.ts.handlebars +1 -1
- package/dist/template/presets/ky/typescript/services/{tag}.ts.handlebars +6 -8
- package/dist/utils/base.js +9 -9
- package/dist/utils/openapi.js +9 -9
- package/package.json +1 -1
- package/typings/index.d.ts +1 -1
- package/typings/plugins.d.ts +30 -19
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
2
|
import { alovaInstance } from '../index';
|
|
3
|
-
import { buildPayload } from '../helper';
|
|
3
|
+
import { buildPayload, resolveTagDefaultConfig } from '../helper';
|
|
4
|
+
import * as defaultConfig from '.';
|
|
4
5
|
import type { Alova2Method, Alova2MethodConfig } from '../typed';
|
|
5
|
-
{{#each tagedApis}}
|
|
6
|
-
import { {{{tagName}}}DefaultConfig } from '.';
|
|
7
|
-
{{/each}}
|
|
8
6
|
import type * as ComponentTypes from '../components';
|
|
9
7
|
|
|
10
|
-
{{
|
|
8
|
+
const {{{currentTag.tag}}}DefaultConfig = resolveTagDefaultConfig(defaultConfig, '{{{currentTag.tag}}}DefaultConfig');
|
|
9
|
+
|
|
11
10
|
{{> extract-responded}}
|
|
12
|
-
{{#each apis}}
|
|
11
|
+
{{#each currentTag.apis}}
|
|
13
12
|
|
|
14
13
|
interface {{{name}}}ExtraConfig {
|
|
15
14
|
{{#if pathParameters}}pathParams: {{addNamespace pathParameters @root.componentNames}};
|
|
@@ -19,7 +18,7 @@ interface {{{name}}}ExtraConfig {
|
|
|
19
18
|
}
|
|
20
19
|
{{> api-jsdoc}}
|
|
21
20
|
export function {{{name}}}<Config extends Alova2MethodConfig<{{addNamespace response @root.componentNames}}> & {{{name}}}ExtraConfig>(config{{#or pathParameters queryParameters requestBody }}{{else}}?{{/or}}: Config): Alova2Method<ExtractResponded<Config, '{{{name}}}', {{addNamespace response @root.componentNames}}>> {
|
|
22
|
-
const { url, data, mergedConfig } = buildPayload('{{{path}}}', {{
|
|
21
|
+
const { url, data, mergedConfig } = buildPayload('{{{path}}}', {{../currentTag.tag}}DefaultConfig, {{{name}}}.name, config);
|
|
23
22
|
return alovaInstance.Request<ExtractResponded<Config, '{{{name}}}', {{addNamespace response @root.componentNames}}>>({
|
|
24
23
|
...mergedConfig,
|
|
25
24
|
url,
|
|
@@ -32,4 +31,3 @@ export function {{{name}}}<Config extends Alova2MethodConfig<{{addNamespace resp
|
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
{{/each}}
|
|
35
|
-
{{/each}}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
1
|
/* eslint-disable */
|
|
2
|
+
/* biome-ignore-all */
|
|
3
|
+
/* stylelint-disable */
|
|
4
|
+
/* editorconfig-checker-disable-file */
|
|
5
|
+
/* oxlint-disable */
|
|
6
|
+
/* oxcformat-ignore */
|
|
3
7
|
/**
|
|
4
8
|
* {{title}} - version {{version}}
|
|
5
9
|
*
|
|
@@ -13,7 +17,12 @@
|
|
|
13
17
|
*
|
|
14
18
|
* NOTE: This file is auto generated by the alova's vscode plugin.
|
|
15
19
|
*
|
|
16
|
-
* https://
|
|
20
|
+
* https://worma.js.org
|
|
17
21
|
*
|
|
22
|
+
{{#if noOverwrite}}
|
|
23
|
+
* NOTE: This file is generated only once and will NOT be overwritten on regeneration.
|
|
24
|
+
* You can safely customize it to fit your needs.
|
|
25
|
+
{{else}}
|
|
18
26
|
* **Do not edit the file manually.**
|
|
27
|
+
{{/if}}
|
|
19
28
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
+
|
|
2
3
|
function buildPayload(url, defaultConfig, apiName, config) {
|
|
3
4
|
const mergedConfig = { ...defaultConfig[apiName], ...config };
|
|
4
5
|
const pathParams = mergedConfig.pathParams;
|
|
@@ -25,7 +26,7 @@ function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
25
26
|
/**
|
|
26
27
|
* @typedef {{#raw "{{" }}{{/raw}}
|
|
27
28
|
{{#each tagedApis}}
|
|
28
|
-
* {{{
|
|
29
|
+
* {{{tag}}}: typeof import('./services/{{{tag}}}.cjs')
|
|
29
30
|
{{/each}}
|
|
30
31
|
* {{#raw "}}" }}{{/raw}} ServicesMap
|
|
31
32
|
*/
|
|
@@ -38,6 +39,20 @@ function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
38
39
|
* @param {ConfigMap} configMap
|
|
39
40
|
* @returns {ConfigMap}
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
function setDefaultConfig(_, configMap) {
|
|
43
|
+
return configMap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @template {object} C
|
|
48
|
+
* @template {string} Key
|
|
49
|
+
* @param {C} defaultConfig
|
|
50
|
+
* @param {Key} tagName
|
|
51
|
+
* @returns {C extends { [K in Key]: infer V } ? V : {}}
|
|
52
|
+
*/
|
|
53
|
+
function resolveTagDefaultConfig(defaultConfig, tagName) {
|
|
54
|
+
const raw = defaultConfig[tagName];
|
|
55
|
+
return raw || {};
|
|
56
|
+
}
|
|
42
57
|
|
|
43
|
-
module.exports = { buildPayload, setDefaultConfig };
|
|
58
|
+
module.exports = { buildPayload, setDefaultConfig, resolveTagDefaultConfig };
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
const { setDefaultConfig } = require('../helper.cjs');
|
|
3
3
|
|
|
4
4
|
{{#each tagedApis}}
|
|
5
|
-
const {{{
|
|
5
|
+
const {{{tag}}}DefaultConfig = setDefaultConfig('{{{tag}}}', {});
|
|
6
6
|
{{/each}}
|
|
7
7
|
|
|
8
8
|
{{#each tagedApis}}
|
|
9
|
-
module.exports.{{{
|
|
9
|
+
module.exports.{{{tag}}}DefaultConfig = {{{tag}}}DefaultConfig;
|
|
10
10
|
{{/each}}
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
{{> comment}}
|
|
2
|
-
const { axiosInstance } = require('../index.cjs');
|
|
3
|
-
const { buildPayload } = require('../helper.cjs');
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
{{#each apis}}
|
|
9
|
-
{{> api-jsdoc}}
|
|
10
|
-
function {{{name}}}(config = {}) {
|
|
11
|
-
const { url, mergedConfig } = buildPayload('{{{path}}}',
|
|
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
|
-
{
|
|
22
|
-
|
|
23
|
-
{{
|
|
24
|
-
{{
|
|
25
|
-
|
|
26
|
-
{{/each}}
|
|
27
|
-
{{/each}}
|
|
28
|
-
};
|
|
1
|
+
{{> comment}}
|
|
2
|
+
const { axiosInstance } = require('../index.cjs');
|
|
3
|
+
const { buildPayload, resolveTagDefaultConfig } = require('../helper.cjs');
|
|
4
|
+
const defaultConfig = require('./index.cjs');
|
|
5
|
+
|
|
6
|
+
const {{{currentTag.tag}}}DefaultConfig = resolveTagDefaultConfig(defaultConfig, '{{{currentTag.tag}}}DefaultConfig');
|
|
7
|
+
|
|
8
|
+
{{#each currentTag.apis}}
|
|
9
|
+
{{> api-jsdoc}}
|
|
10
|
+
function {{{name}}}(config = {}) {
|
|
11
|
+
const { url, mergedConfig } = buildPayload('{{{path}}}', {{../currentTag.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
|
+
module.exports = {
|
|
22
|
+
{{#each currentTag.apis}}
|
|
23
|
+
{{{name}}},
|
|
24
|
+
{{/each}}
|
|
25
|
+
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type * as ComponentTypes from '../components.d.cts';
|
|
3
3
|
|
|
4
|
-
{{#each
|
|
5
|
-
{{#each apis}}
|
|
4
|
+
{{#each currentTag.apis}}
|
|
6
5
|
{{> dts-types}}
|
|
7
6
|
{{> api-jsdoc}}
|
|
8
7
|
{{> dts-fn-declare}}
|
|
9
8
|
|
|
10
9
|
{{/each}}
|
|
11
|
-
{{/each}}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
+
|
|
2
3
|
export function buildPayload(url, defaultConfig, apiName, config) {
|
|
3
4
|
const mergedConfig = { ...defaultConfig[apiName], ...config };
|
|
4
5
|
const pathParams = mergedConfig.pathParams;
|
|
@@ -25,7 +26,7 @@ export function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
25
26
|
/**
|
|
26
27
|
* @typedef {{#raw "{{" }}{{/raw}}
|
|
27
28
|
{{#each tagedApis}}
|
|
28
|
-
* {{{
|
|
29
|
+
* {{{tag}}}: typeof import('./services/{{{tag}}}')
|
|
29
30
|
{{/each}}
|
|
30
31
|
* {{#raw "}}" }}{{/raw}} ServicesMap
|
|
31
32
|
*/
|
|
@@ -38,4 +39,18 @@ export function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
38
39
|
* @param {ConfigMap} configMap
|
|
39
40
|
* @returns {ConfigMap}
|
|
40
41
|
*/
|
|
41
|
-
export
|
|
42
|
+
export function setDefaultConfig(_, configMap) {
|
|
43
|
+
return configMap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @template {object} C
|
|
48
|
+
* @template {string} Key
|
|
49
|
+
* @param {C} defaultConfig
|
|
50
|
+
* @param {Key} tagName
|
|
51
|
+
* @returns {C extends { [K in Key]: infer V } ? V : {}}
|
|
52
|
+
*/
|
|
53
|
+
export function resolveTagDefaultConfig(defaultConfig, tagName) {
|
|
54
|
+
const raw = defaultConfig[tagName];
|
|
55
|
+
return raw || {};
|
|
56
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
-
import { setDefaultConfig } from '../helper';
|
|
2
|
+
import { setDefaultConfig } from '../helper.js';
|
|
3
3
|
|
|
4
4
|
{{#each tagedApis}}
|
|
5
|
-
export const {{{
|
|
5
|
+
export const {{{tag}}}DefaultConfig = setDefaultConfig('{{{tag}}}', {});
|
|
6
6
|
{{/each}}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import type * as ComponentTypes from '../components';
|
|
3
3
|
|
|
4
|
-
{{#each
|
|
5
|
-
{{#each apis}}
|
|
4
|
+
{{#each currentTag.apis}}
|
|
6
5
|
{{> dts-types}}
|
|
7
6
|
{{> api-jsdoc}}
|
|
8
7
|
{{> dts-fn-declare}}
|
|
9
8
|
|
|
10
9
|
{{/each}}
|
|
11
|
-
{{/each}}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
{{> comment}}
|
|
2
|
-
import { axiosInstance } from '../index.js';
|
|
3
|
-
import { buildPayload } from '../helper.js';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
{{
|
|
7
|
-
|
|
8
|
-
{{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
{{/each}}
|
|
1
|
+
{{> comment}}
|
|
2
|
+
import { axiosInstance } from '../index.js';
|
|
3
|
+
import { buildPayload, resolveTagDefaultConfig } from '../helper.js';
|
|
4
|
+
import * as defaultConfig from './index.js';
|
|
5
|
+
|
|
6
|
+
const {{currentTag.tag}}DefaultConfig = resolveTagDefaultConfig(defaultConfig, '{{currentTag.tag}}DefaultConfig');
|
|
7
|
+
|
|
8
|
+
{{#each currentTag.apis}}
|
|
9
|
+
{{> api-jsdoc}}
|
|
10
|
+
export function {{{name}}}(config = {}) {
|
|
11
|
+
const { url, mergedConfig } = buildPayload('{{{path}}}', {{../currentTag.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}}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
1
|
/* eslint-disable */
|
|
2
|
+
/* biome-ignore-all */
|
|
3
|
+
/* stylelint-disable */
|
|
4
|
+
/* editorconfig-checker-disable-file */
|
|
5
|
+
/* oxlint-disable */
|
|
6
|
+
/* oxcformat-ignore */
|
|
3
7
|
/**
|
|
4
8
|
* {{title}} - version {{version}}
|
|
5
9
|
*
|
|
@@ -13,7 +17,12 @@
|
|
|
13
17
|
*
|
|
14
18
|
* NOTE: This file is auto generated by the alova's vscode plugin.
|
|
15
19
|
*
|
|
16
|
-
* https://
|
|
20
|
+
* https://worma.js.org
|
|
17
21
|
*
|
|
22
|
+
{{#if noOverwrite}}
|
|
23
|
+
* NOTE: This file is generated only once and will NOT be overwritten on regeneration.
|
|
24
|
+
* You can safely customize it to fit your needs.
|
|
25
|
+
{{else}}
|
|
18
26
|
* **Do not edit the file manually.**
|
|
27
|
+
{{/if}}
|
|
19
28
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
+
|
|
2
3
|
export function buildPayload(url: string, defaultConfig: Record<string, any>, apiName: string, config: any) {
|
|
3
4
|
const mergedConfig: any = { ...defaultConfig[apiName], ...config };
|
|
4
5
|
const pathParams = mergedConfig.pathParams;
|
|
@@ -24,15 +25,19 @@ export function buildPayload(url: string, defaultConfig: Record<string, any>, ap
|
|
|
24
25
|
|
|
25
26
|
export type ServicesMap = {
|
|
26
27
|
{{#each tagedApis}}
|
|
27
|
-
{{{
|
|
28
|
+
{{{tag}}}: typeof import('./services/{{{tag}}}');
|
|
28
29
|
{{/each}}
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
export
|
|
32
|
+
export function setDefaultConfig<
|
|
32
33
|
T extends keyof ServicesMap,
|
|
33
34
|
TagedMap extends Record<string, (config: any) => any> = ServicesMap[T],
|
|
34
35
|
ConfigMap = { [K in keyof TagedMap]?: Partial<Parameters<TagedMap[K]>[0]> }
|
|
35
|
-
>(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
>(_: T, configMap: ConfigMap): ConfigMap {
|
|
37
|
+
return configMap;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function resolveTagDefaultConfig<C extends object, Key extends string>(defaultConfig: C, tagName: Key) {
|
|
41
|
+
const raw = (defaultConfig as any)[tagName];
|
|
42
|
+
return (raw || {}) as C extends { [K in Key]: infer V } ? V : {};
|
|
43
|
+
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
2
|
import type { AxiosRequestConfig } from 'axios';
|
|
3
3
|
import { axiosInstance } from '../index';
|
|
4
|
-
import { buildPayload } from '../helper';
|
|
4
|
+
import { buildPayload, resolveTagDefaultConfig } from '../helper';
|
|
5
|
+
import * as defaultConfig from './index';
|
|
5
6
|
import type * as ComponentTypes from '../components';
|
|
6
|
-
{{#each tagedApis}}
|
|
7
|
-
import { {{{tagName}}}DefaultConfig } from '.';
|
|
8
|
-
{{/each}}
|
|
9
7
|
|
|
10
|
-
{{
|
|
11
|
-
|
|
8
|
+
const {{{currentTag.tag}}}DefaultConfig = resolveTagDefaultConfig(defaultConfig, '{{{currentTag.tag}}}DefaultConfig');
|
|
9
|
+
|
|
10
|
+
{{#each currentTag.apis}}
|
|
12
11
|
type {{{name}}}Response = {{addNamespace response @root.componentNames}};
|
|
13
12
|
type {{{name}}}ExtraConfig = Omit<AxiosRequestConfig, 'data' | 'params'> & {
|
|
14
13
|
{{#if pathParameters}}pathParams: {{addNamespace pathParameters @root.componentNames}};
|
|
@@ -18,7 +17,7 @@ type {{{name}}}ExtraConfig = Omit<AxiosRequestConfig, 'data' | 'params'> & {
|
|
|
18
17
|
};
|
|
19
18
|
{{> api-jsdoc}}
|
|
20
19
|
export function {{{name}}}(config{{#or pathParameters queryParameters requestBody }}{{else}}?{{/or}}: {{{name}}}ExtraConfig): Promise<{{{name}}}Response> {
|
|
21
|
-
const { url, mergedConfig } = buildPayload('{{{path}}}', {{
|
|
20
|
+
const { url, mergedConfig } = buildPayload('{{{path}}}', {{../currentTag.tag}}DefaultConfig, {{{name}}}.name, config);
|
|
22
21
|
return axiosInstance<unknown, {{{name}}}Response>({
|
|
23
22
|
method: '{{method}}',
|
|
24
23
|
url,
|
|
@@ -28,4 +27,3 @@ export function {{{name}}}(config{{#or pathParameters queryParameters requestBod
|
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
{{/each}}
|
|
31
|
-
{{/each}}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
+
|
|
2
3
|
function buildPayload(url, defaultConfig, apiName, config) {
|
|
3
4
|
const mergedConfig = { ...defaultConfig[apiName], ...config };
|
|
4
5
|
const pathParams = mergedConfig.pathParams;
|
|
@@ -25,7 +26,7 @@ function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
25
26
|
/**
|
|
26
27
|
* @typedef {{#raw "{{" }}{{/raw}}
|
|
27
28
|
{{#each tagedApis}}
|
|
28
|
-
* {{{
|
|
29
|
+
* {{{tag}}}: typeof import('./services/{{{tag}}}.cjs')
|
|
29
30
|
{{/each}}
|
|
30
31
|
* {{#raw "}}" }}{{/raw}} ServicesMap
|
|
31
32
|
*/
|
|
@@ -38,6 +39,20 @@ function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
38
39
|
* @param {ConfigMap} configMap
|
|
39
40
|
* @returns {ConfigMap}
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
function setDefaultConfig(_, configMap) {
|
|
43
|
+
return configMap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @template {object} C
|
|
48
|
+
* @template {string} Key
|
|
49
|
+
* @param {C} defaultConfig
|
|
50
|
+
* @param {Key} tagName
|
|
51
|
+
* @returns {C extends { [K in Key]: infer V } ? V : {}}
|
|
52
|
+
*/
|
|
53
|
+
function resolveTagDefaultConfig(defaultConfig, tagName) {
|
|
54
|
+
const raw = defaultConfig[tagName];
|
|
55
|
+
return raw || {};
|
|
56
|
+
}
|
|
42
57
|
|
|
43
|
-
module.exports = { buildPayload, setDefaultConfig };
|
|
58
|
+
module.exports = { buildPayload, setDefaultConfig, resolveTagDefaultConfig };
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
const { setDefaultConfig } = require('../helper.cjs');
|
|
3
3
|
|
|
4
4
|
{{#each tagedApis}}
|
|
5
|
-
const {{{
|
|
5
|
+
const {{{tag}}}DefaultConfig = setDefaultConfig('{{{tag}}}', {});
|
|
6
6
|
{{/each}}
|
|
7
7
|
|
|
8
8
|
{{#each tagedApis}}
|
|
9
|
-
module.exports.{{{
|
|
9
|
+
module.exports.{{{tag}}}DefaultConfig = {{{tag}}}DefaultConfig;
|
|
10
10
|
{{/each}}
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
2
|
const { fetchClient } = require('../index.cjs');
|
|
3
|
-
const { buildPayload } = require('../helper.cjs');
|
|
4
|
-
const
|
|
3
|
+
const { buildPayload, resolveTagDefaultConfig } = require('../helper.cjs');
|
|
4
|
+
const defaultConfig = require('./index.cjs');
|
|
5
5
|
|
|
6
|
+
const {{{currentTag.tag}}}DefaultConfig = resolveTagDefaultConfig(defaultConfig, '{{{currentTag.tag}}}DefaultConfig');
|
|
6
7
|
|
|
7
|
-
{{#each
|
|
8
|
-
{{#each apis}}
|
|
8
|
+
{{#each currentTag.apis}}
|
|
9
9
|
{{> api-jsdoc}}
|
|
10
10
|
async function {{{name}}}(config = {}) {
|
|
11
|
-
const { url, mergedConfig } = buildPayload('{{{path}}}',
|
|
11
|
+
const { url, mergedConfig } = buildPayload('{{{path}}}', {{../currentTag.tag}}DefaultConfig, {{{name}}}.name, config);
|
|
12
12
|
return fetchClient.request(url, { method: '{{method}}', ...mergedConfig{{#if (eq response "Blob")}}, blob: true{{/if}} });
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
{{/each}}
|
|
16
15
|
{{/each}}
|
|
17
16
|
module.exports = {
|
|
18
|
-
{{#each
|
|
19
|
-
{{#each apis}}
|
|
17
|
+
{{#each currentTag.apis}}
|
|
20
18
|
{{{name}}},
|
|
21
19
|
{{/each}}
|
|
22
|
-
{{/each}}
|
|
23
20
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
+
|
|
2
3
|
export function buildPayload(url, defaultConfig, apiName, config) {
|
|
3
4
|
const mergedConfig = { ...defaultConfig[apiName], ...config };
|
|
4
5
|
const pathParams = mergedConfig.pathParams;
|
|
@@ -25,7 +26,7 @@ export function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
25
26
|
/**
|
|
26
27
|
* @typedef {{#raw "{{" }}{{/raw}}
|
|
27
28
|
{{#each tagedApis}}
|
|
28
|
-
* {{{
|
|
29
|
+
* {{{tag}}}: typeof import('./services/{{{tag}}}')
|
|
29
30
|
{{/each}}
|
|
30
31
|
* {{#raw "}}" }}{{/raw}} ServicesMap
|
|
31
32
|
*/
|
|
@@ -38,4 +39,18 @@ export function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
38
39
|
* @param {ConfigMap} configMap
|
|
39
40
|
* @returns {ConfigMap}
|
|
40
41
|
*/
|
|
41
|
-
export
|
|
42
|
+
export function setDefaultConfig(_, configMap) {
|
|
43
|
+
return configMap;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @template {object} C
|
|
48
|
+
* @template {string} Key
|
|
49
|
+
* @param {C} defaultConfig
|
|
50
|
+
* @param {Key} tagName
|
|
51
|
+
* @returns {C extends { [K in Key]: infer V } ? V : {}}
|
|
52
|
+
*/
|
|
53
|
+
export function resolveTagDefaultConfig(defaultConfig, tagName) {
|
|
54
|
+
const raw = defaultConfig[tagName];
|
|
55
|
+
return raw || {};
|
|
56
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
-
import { setDefaultConfig } from '../helper';
|
|
2
|
+
import { setDefaultConfig } from '../helper.js';
|
|
3
3
|
|
|
4
4
|
{{#each tagedApis}}
|
|
5
|
-
export const {{{
|
|
5
|
+
export const {{{tag}}}DefaultConfig = setDefaultConfig('{{{tag}}}', {});
|
|
6
6
|
{{/each}}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
2
|
import { fetchClient } from '../index.js';
|
|
3
|
-
import { buildPayload } from '../helper.js';
|
|
4
|
-
import
|
|
3
|
+
import { buildPayload, resolveTagDefaultConfig } from '../helper.js';
|
|
4
|
+
import * as defaultConfig from './index.js';
|
|
5
5
|
|
|
6
|
-
{{
|
|
7
|
-
|
|
6
|
+
const {{currentTag.tag}}DefaultConfig = resolveTagDefaultConfig(defaultConfig, '{{currentTag.tag}}DefaultConfig');
|
|
7
|
+
|
|
8
|
+
{{#each currentTag.apis}}
|
|
8
9
|
{{> api-jsdoc}}
|
|
9
10
|
export async function {{{name}}}(config = {}) {
|
|
10
|
-
const { url, mergedConfig } = buildPayload('{{{path}}}', {{
|
|
11
|
+
const { url, mergedConfig } = buildPayload('{{{path}}}', {{../currentTag.tag}}DefaultConfig, {{{name}}}.name, config);
|
|
11
12
|
return fetchClient.request(url, { method: '{{method}}', ...mergedConfig{{#if (eq response "Blob")}}, blob: true{{/if}} });
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
{{/each}}
|
|
15
|
-
{{/each}}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
/* tslint:disable */
|
|
2
1
|
/* eslint-disable */
|
|
2
|
+
/* biome-ignore-all */
|
|
3
|
+
/* stylelint-disable */
|
|
4
|
+
/* editorconfig-checker-disable-file */
|
|
5
|
+
/* oxlint-disable */
|
|
6
|
+
/* oxcformat-ignore */
|
|
3
7
|
/**
|
|
4
8
|
* {{title}} - version {{version}}
|
|
5
9
|
*
|
|
@@ -13,7 +17,12 @@
|
|
|
13
17
|
*
|
|
14
18
|
* NOTE: This file is auto generated by the alova's vscode plugin.
|
|
15
19
|
*
|
|
16
|
-
* https://
|
|
20
|
+
* https://worma.js.org
|
|
17
21
|
*
|
|
22
|
+
{{#if noOverwrite}}
|
|
23
|
+
* NOTE: This file is generated only once and will NOT be overwritten on regeneration.
|
|
24
|
+
* You can safely customize it to fit your needs.
|
|
25
|
+
{{else}}
|
|
18
26
|
* **Do not edit the file manually.**
|
|
27
|
+
{{/if}}
|
|
19
28
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
+
|
|
2
3
|
export function buildPayload(url: string, defaultConfig: Record<string, any>, apiName: string, config: any) {
|
|
3
4
|
const mergedConfig: any = { ...defaultConfig[apiName], ...config };
|
|
4
5
|
const pathParams = mergedConfig.pathParams;
|
|
@@ -24,15 +25,19 @@ export function buildPayload(url: string, defaultConfig: Record<string, any>, ap
|
|
|
24
25
|
|
|
25
26
|
export type ServicesMap = {
|
|
26
27
|
{{#each tagedApis}}
|
|
27
|
-
{{{
|
|
28
|
+
{{{tag}}}: typeof import('./services/{{{tag}}}');
|
|
28
29
|
{{/each}}
|
|
29
30
|
};
|
|
30
31
|
|
|
31
|
-
export
|
|
32
|
+
export function setDefaultConfig<
|
|
32
33
|
T extends keyof ServicesMap,
|
|
33
34
|
TagedMap extends Record<string, (config: any) => any> = ServicesMap[T],
|
|
34
35
|
ConfigMap = { [K in keyof TagedMap]?: Partial<Parameters<TagedMap[K]>[0]> }
|
|
35
|
-
>(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
>(_: T, configMap: ConfigMap): ConfigMap {
|
|
37
|
+
return configMap;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function resolveTagDefaultConfig<C extends object, Key extends string>(defaultConfig: C, tagName: Key) {
|
|
41
|
+
const raw = (defaultConfig as any)[tagName];
|
|
42
|
+
return (raw || {}) as C extends { [K in Key]: infer V } ? V : {};
|
|
43
|
+
}
|