wormajs 0.2.4 → 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/bin/renderer.js +8 -2
- package/dist/constant.js +20 -20
- package/dist/core/WorkerPool.js +5 -3
- package/dist/core/loader/astLoader/generates/tuple.js +1 -1
- package/dist/core/loader/astLoader/index.js +1 -3
- package/dist/core/loader/astLoader/normalize/index.js +1 -1
- package/dist/core/loader/astLoader/normalize/normalizer.js +9 -11
- 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/callingCodeLoader/index.js +1 -3
- package/dist/core/loader/schemaLoader/index.js +1 -3
- package/dist/core/loader/standardLoader/helper.js +1 -1
- package/dist/core/loader/standardLoader/index.js +1 -3
- package/dist/core/parser/openApiParser/index.js +1 -3
- package/dist/core/parser/templateParser/helper.js +5 -5
- package/dist/core/parser/templateParser/index.js +14 -14
- package/dist/core/workerPool/poolManager.js +3 -3
- package/dist/functions/wormaJson.js +2 -2
- package/dist/helper/PluginDriver.js +2 -0
- package/dist/helper/comment.js +18 -20
- package/dist/helper/config/ConfigHelper.js +2 -3
- package/dist/helper/config/ConfigManager.js +16 -14
- package/dist/helper/config/GeneratorHelper.js +15 -13
- package/dist/helper/config/zType.js +1 -1
- package/dist/helper/document/index.js +13 -14
- package/dist/helper/logger/index.js +6 -8
- package/dist/helper/progress.js +5 -3
- package/dist/helper/template/index.js +13 -11
- 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/dts-fn-declare.handlebars +1 -1
- 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 +7 -9
- 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/partials/dts-fn-declare.handlebars +1 -1
- 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 +7 -9
- 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/partials/dts-fn-declare.handlebars +1 -1
- 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 +7 -9
- 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/partials/dts-fn-declare.handlebars +1 -1
- 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 +7 -9
- package/dist/utils/base.js +9 -9
- package/dist/utils/openapi.js +15 -15
- package/package.json +2 -2
- package/typings/index.d.ts +1 -1
- package/typings/plugins.d.ts +30 -19
- package/dist/tsconfig.build.tsbuildinfo +0 -1
package/dist/template/index.js
CHANGED
|
@@ -13,16 +13,16 @@ exports.ky = ky;
|
|
|
13
13
|
const node_path_1 = __importDefault(require("node:path"));
|
|
14
14
|
const constant_1 = require("../constant");
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Get the full path of a preset template
|
|
17
17
|
*/
|
|
18
18
|
function getPresetTemplatePath(presetName) {
|
|
19
|
-
//
|
|
20
|
-
//
|
|
19
|
+
// preset templates are in the src/template/presets directory
|
|
20
|
+
// after build they are in the dist/template/presets directory
|
|
21
21
|
return node_path_1.default.join(__dirname, 'presets', presetName);
|
|
22
22
|
}
|
|
23
23
|
// ========== Template Preset Plugins ==========
|
|
24
24
|
/**
|
|
25
|
-
* worma.config
|
|
25
|
+
* worma.config template preset - plugin mode
|
|
26
26
|
*/
|
|
27
27
|
function config() {
|
|
28
28
|
return {
|
|
@@ -36,8 +36,8 @@ function config() {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
|
-
* globals
|
|
40
|
-
*
|
|
39
|
+
* globals template preset - plugin mode
|
|
40
|
+
* Global template: an existing global template, used via global mounting
|
|
41
41
|
*/
|
|
42
42
|
function alovaGlobals(opts) {
|
|
43
43
|
return {
|
|
@@ -69,8 +69,8 @@ function alovaGlobals(opts) {
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
|
-
* functional
|
|
73
|
-
*
|
|
72
|
+
* functional template preset - plugin mode
|
|
73
|
+
* Functional template that generates functional API calls, supports tree-shaking, only for alova v3
|
|
74
74
|
*/
|
|
75
75
|
function alova(opts) {
|
|
76
76
|
return {
|
|
@@ -88,8 +88,8 @@ function alova(opts) {
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
|
-
* axios
|
|
92
|
-
* Axios
|
|
91
|
+
* axios template preset - plugin mode
|
|
92
|
+
* Axios-related template
|
|
93
93
|
*/
|
|
94
94
|
function axios(opts) {
|
|
95
95
|
return {
|
|
@@ -107,8 +107,8 @@ function axios(opts) {
|
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
/**
|
|
110
|
-
* fetch
|
|
111
|
-
* Fetch
|
|
110
|
+
* fetch template preset - plugin mode
|
|
111
|
+
* Fetch-related template
|
|
112
112
|
*/
|
|
113
113
|
function fetch(opts) {
|
|
114
114
|
return {
|
|
@@ -126,8 +126,8 @@ function fetch(opts) {
|
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
128
|
/**
|
|
129
|
-
* ky
|
|
130
|
-
* Ky
|
|
129
|
+
* ky template preset - plugin mode
|
|
130
|
+
* Ky-related template
|
|
131
131
|
*/
|
|
132
132
|
function ky(opts) {
|
|
133
133
|
return {
|
|
@@ -7,7 +7,7 @@ description: >-
|
|
|
7
7
|
Use this skill whenever you need to: call {{{serverName}}} backend APIs,
|
|
8
8
|
look up endpoint details and parameter requirements, understand request/response
|
|
9
9
|
data structures, or integrate frontend code with {{{serverName}}} services.
|
|
10
|
-
Key domains covered: {{#each tagedApis}}{{{
|
|
10
|
+
Key domains covered: {{#each tagedApis}}{{{tag}}}{{#unless @last}}, {{/unless}}{{/each}}.
|
|
11
11
|
---
|
|
12
12
|
|
|
13
13
|
> version {{{version}}}
|
|
@@ -22,8 +22,8 @@ request/response formats, and usage examples.
|
|
|
22
22
|
## API Directory ({{{serverName}}})
|
|
23
23
|
|
|
24
24
|
{{#each tagedApis}}
|
|
25
|
-
- **{{{
|
|
25
|
+
- **{{{tag}}}**
|
|
26
26
|
{{#each apis}}
|
|
27
|
-
- [{{{summary}}}](./references/{{{../
|
|
27
|
+
- [{{{summary}}}](./references/{{{../tag}}}/{{{name}}}.md) `[{{{method}}}] {{{path}}}`
|
|
28
28
|
{{/each}}
|
|
29
29
|
{{/each}}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
+
|
|
2
3
|
function buildPayload(url, defaultConfig, apiName, config) {
|
|
3
4
|
{{> build-payload-body}}
|
|
4
5
|
}
|
|
@@ -6,7 +7,7 @@ function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {{#raw "{{" }}{{/raw}}
|
|
8
9
|
{{#each tagedApis}}
|
|
9
|
-
* {{{
|
|
10
|
+
* {{{tag}}}: typeof import('./services/{{{tag}}}.cjs')
|
|
10
11
|
{{/each}}
|
|
11
12
|
* {{#raw "}}" }}{{/raw}} ServicesMap
|
|
12
13
|
*/
|
|
@@ -19,6 +20,20 @@ function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
19
20
|
* @param {ConfigMap} configMap
|
|
20
21
|
* @returns {ConfigMap}
|
|
21
22
|
*/
|
|
22
|
-
|
|
23
|
+
function setMethodDefaultConfig(_, configMap) {
|
|
24
|
+
return configMap;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @template {object} C
|
|
29
|
+
* @template {string} Key
|
|
30
|
+
* @param {C} defaultConfig
|
|
31
|
+
* @param {Key} tagName
|
|
32
|
+
* @returns {C extends { [K in Key]: infer V } ? V : {}}
|
|
33
|
+
*/
|
|
34
|
+
function resolveTagDefaultConfig(defaultConfig, tagName) {
|
|
35
|
+
const raw = defaultConfig[tagName];
|
|
36
|
+
return raw || {};
|
|
37
|
+
}
|
|
23
38
|
|
|
24
|
-
module.exports = { buildPayload, setMethodDefaultConfig };
|
|
39
|
+
module.exports = { buildPayload, setMethodDefaultConfig, resolveTagDefaultConfig };
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
const { setMethodDefaultConfig } = require('../helper.cjs');
|
|
3
3
|
|
|
4
4
|
{{#each tagedApis}}
|
|
5
|
-
const {{{
|
|
5
|
+
const {{{tag}}}DefaultConfig = setMethodDefaultConfig('{{{tag}}}', {});
|
|
6
6
|
{{/each}}
|
|
7
7
|
|
|
8
8
|
{{#each tagedApis}}
|
|
9
|
-
module.exports.{{{
|
|
9
|
+
module.exports.{{{tag}}}DefaultConfig = {{{tag}}}DefaultConfig;
|
|
10
10
|
{{/each}}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
2
|
const { alovaInstance } = 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
|
-
{{
|
|
7
|
-
|
|
6
|
+
const {{{currentTag.tag}}}DefaultConfig = resolveTagDefaultConfig(defaultConfig, '{{{currentTag.tag}}}DefaultConfig');
|
|
7
|
+
|
|
8
|
+
{{#each currentTag.apis}}
|
|
8
9
|
{{> api-jsdoc}}
|
|
9
10
|
function {{{name}}}(config) {
|
|
10
|
-
const { url, data, mergedConfig } = buildPayload('{{{path}}}',
|
|
11
|
+
const { url, data, mergedConfig } = buildPayload('{{{path}}}', {{../currentTag.tag}}DefaultConfig, {{{name}}}.name, config);
|
|
11
12
|
return alovaInstance.Request({
|
|
12
13
|
...mergedConfig,
|
|
13
14
|
url,
|
|
@@ -17,12 +18,9 @@ function {{{name}}}(config) {
|
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
{{/each}}
|
|
21
21
|
{{/each}}
|
|
22
22
|
module.exports = {
|
|
23
|
-
{{#each
|
|
24
|
-
{{#each apis}}
|
|
23
|
+
{{#each currentTag.apis}}
|
|
25
24
|
{{{name}}},
|
|
26
25
|
{{/each}}
|
|
27
|
-
{{/each}}
|
|
28
26
|
};
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type { Alova2Method, Alova2MethodConfig } from '../typed.d.cts';
|
|
2
|
-
{{#each tagedApis}}
|
|
3
|
-
import type { {{{tagName}}}DefaultConfig } from '.';
|
|
4
|
-
{{/each}}
|
|
1
|
+
import type { Alova2Method, Alova2MethodConfig, TagDefaultConfig } from '../typed.d.cts';
|
|
5
2
|
import type * as ComponentTypes from '../components.d.cts';
|
|
3
|
+
import type * as defaultConfig from './index.cjs';
|
|
4
|
+
|
|
5
|
+
type {{{currentTag.tag}}}DefaultConfig = TagDefaultConfig<typeof defaultConfig, '{{{currentTag.tag}}}DefaultConfig'>;
|
|
6
6
|
|
|
7
|
-
{{#each tagedApis}}
|
|
8
7
|
{{> extract-responded}}
|
|
9
|
-
{{#each apis}}
|
|
8
|
+
{{#each currentTag.apis}}
|
|
10
9
|
{{> dts-extra-config}}
|
|
11
10
|
{{> api-jsdoc}}
|
|
12
11
|
{{> dts-fn-declare}}
|
|
13
12
|
|
|
14
13
|
{{/each}}
|
|
15
|
-
{{/each}}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
+
|
|
2
3
|
export function buildPayload(url, defaultConfig, apiName, config) {
|
|
3
4
|
{{> build-payload-body}}
|
|
4
5
|
}
|
|
@@ -6,7 +7,7 @@ export function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
6
7
|
/**
|
|
7
8
|
* @typedef {{#raw "{{" }}{{/raw}}
|
|
8
9
|
{{#each tagedApis}}
|
|
9
|
-
* {{{
|
|
10
|
+
* {{{tag}}}: typeof import('./services/{{{tag}}}')
|
|
10
11
|
{{/each}}
|
|
11
12
|
* {{#raw "}}" }}{{/raw}} ServicesMap
|
|
12
13
|
*/
|
|
@@ -19,4 +20,18 @@ export function buildPayload(url, defaultConfig, apiName, config) {
|
|
|
19
20
|
* @param {ConfigMap} configMap
|
|
20
21
|
* @returns {ConfigMap}
|
|
21
22
|
*/
|
|
22
|
-
export
|
|
23
|
+
export function setMethodDefaultConfig(_, configMap) {
|
|
24
|
+
return configMap;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @template {object} C
|
|
29
|
+
* @template {string} Key
|
|
30
|
+
* @param {C} defaultConfig
|
|
31
|
+
* @param {Key} tagName
|
|
32
|
+
* @returns {C extends { [K in Key]: infer V } ? V : {}}
|
|
33
|
+
*/
|
|
34
|
+
export function resolveTagDefaultConfig(defaultConfig, tagName) {
|
|
35
|
+
const raw = defaultConfig[tagName];
|
|
36
|
+
return raw || {};
|
|
37
|
+
}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type { Alova2Method, Alova2MethodConfig } from '../typed';
|
|
2
|
-
{{#each tagedApis}}
|
|
3
|
-
import type { {{{tagName}}}DefaultConfig } from '.';
|
|
4
|
-
{{/each}}
|
|
1
|
+
import type { Alova2Method, Alova2MethodConfig, TagDefaultConfig } from '../typed';
|
|
5
2
|
import type * as ComponentTypes from '../components';
|
|
3
|
+
import type * as defaultConfig from './index.js';
|
|
4
|
+
|
|
5
|
+
type {{{currentTag.tag}}}DefaultConfig = TagDefaultConfig<typeof defaultConfig, '{{{currentTag.tag}}}DefaultConfig'>;
|
|
6
6
|
|
|
7
|
-
{{#each tagedApis}}
|
|
8
7
|
{{> extract-responded}}
|
|
9
|
-
{{#each apis}}
|
|
8
|
+
{{#each currentTag.apis}}
|
|
10
9
|
{{> dts-extra-config}}
|
|
11
10
|
{{> api-jsdoc}}
|
|
12
11
|
{{> dts-fn-declare}}
|
|
13
12
|
|
|
14
13
|
{{/each}}
|
|
15
|
-
{{/each}}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
2
|
import { alovaInstance } 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 function {{{name}}}(config) {
|
|
10
|
-
const { url, data, mergedConfig } = buildPayload('{{{path}}}', {{
|
|
11
|
+
const { url, data, mergedConfig } = buildPayload('{{{path}}}', {{../currentTag.tag}}DefaultConfig, {{{name}}}.name, config);
|
|
11
12
|
return alovaInstance.Request({
|
|
12
13
|
...mergedConfig,
|
|
13
14
|
url,
|
|
@@ -18,4 +19,3 @@ export function {{{name}}}(config) {
|
|
|
18
19
|
}
|
|
19
20
|
|
|
20
21
|
{{/each}}
|
|
21
|
-
{{/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 +1 @@
|
|
|
1
|
-
export declare function {{{name}}}<Config extends Alova2MethodConfig<{{addNamespace response @root.componentNames}}> & {{{name}}}ExtraConfig>(config: Config): Alova2Method<ExtractResponded<Config, '{{{name}}}', {{addNamespace response @root.componentNames}}>>;
|
|
1
|
+
export declare 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}}>>;
|
|
@@ -4,8 +4,8 @@ export type ExtractResponded<
|
|
|
4
4
|
Default,
|
|
5
5
|
> = UserDefinedConfig extends { transform: (...args: any[]) => any }
|
|
6
6
|
? Awaited<ReturnType<UserDefinedConfig['transform']>>
|
|
7
|
-
: UnifiedConfigKey extends keyof typeof {{{
|
|
8
|
-
? typeof {{{
|
|
9
|
-
? Awaited<ReturnType<typeof {{{
|
|
7
|
+
: UnifiedConfigKey extends keyof typeof {{{currentTag.tag}}}DefaultConfig
|
|
8
|
+
? typeof {{{currentTag.tag}}}DefaultConfig[UnifiedConfigKey] extends { transform: (...args: any[]) => any }
|
|
9
|
+
? Awaited<ReturnType<typeof {{{currentTag.tag}}}DefaultConfig[UnifiedConfigKey]['transform']>>
|
|
10
10
|
: Default
|
|
11
11
|
: Default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { alovaInstance } from './index{{#if (eq type "commonjs")}}.cjs{{/if}}';
|
|
1
|
+
import type { alovaInstance } from './index{{#if (eq type "commonjs")}}.cjs{{else if (eq type "module")}}.js{{/if}}';
|
|
2
2
|
import type { Alova, AlovaGenerics, AlovaMethodCreateConfig, Method } from 'alova';
|
|
3
3
|
|
|
4
4
|
type CollapsedAlova = typeof alovaInstance;
|
|
@@ -41,3 +41,5 @@ export type Alova2Method<Responded> = CollapsedAlova extends Alova<
|
|
|
41
41
|
AlovaGenerics<Responded, any, RequestConfig, Response, ResponseHeader, L1Cache, L2Cache, SE>
|
|
42
42
|
>
|
|
43
43
|
: never;
|
|
44
|
+
|
|
45
|
+
export type TagDefaultConfig<C, Key extends string> = C extends { [K in Key]: infer V } ? V : {}
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
{{> comment}}
|
|
2
|
+
|
|
2
3
|
export function buildPayload(url: string, defaultConfig: Record<string, any>, apiName: string, config: any) {
|
|
3
4
|
{{> build-payload-body}}
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
export type ServicesMap = {
|
|
7
8
|
{{#each tagedApis}}
|
|
8
|
-
{{{
|
|
9
|
+
{{{tag}}}: typeof import('./services/{{{tag}}}');
|
|
9
10
|
{{/each}}
|
|
10
11
|
};
|
|
11
12
|
|
|
12
|
-
export
|
|
13
|
+
export function setMethodDefaultConfig<
|
|
13
14
|
T extends keyof ServicesMap,
|
|
14
15
|
TagedMap extends Record<string, (config: any) => any> = ServicesMap[T],
|
|
15
16
|
ConfigMap = { [K in keyof TagedMap]?: Partial<Parameters<TagedMap[K]>[0]> }
|
|
16
|
-
>(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
>(_: T, configMap: ConfigMap): ConfigMap {
|
|
18
|
+
return configMap;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function resolveTagDefaultConfig<C extends object, Key extends string>(defaultConfig: C, tagName: Key) {
|
|
22
|
+
const raw = (defaultConfig as any)[tagName];
|
|
23
|
+
return (raw || {}) as C extends { [K in Key]: infer V } ? V : {};
|
|
24
|
+
}
|
|
20
25
|
|
|
@@ -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}};
|
|
@@ -18,8 +17,8 @@ interface {{{name}}}ExtraConfig {
|
|
|
18
17
|
{{/if}}
|
|
19
18
|
}
|
|
20
19
|
{{> api-jsdoc}}
|
|
21
|
-
export function {{{name}}}<Config extends Alova2MethodConfig<{{addNamespace response @root.componentNames}}> & {{{name}}}ExtraConfig>(config: Config): Alova2Method<ExtractResponded<Config, '{{{name}}}', {{addNamespace response @root.componentNames}}>> {
|
|
22
|
-
const { url, data, mergedConfig } = buildPayload('{{{path}}}', {{
|
|
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}}>> {
|
|
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}}
|