wormajs 0.2.5 → 0.2.7
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/README.md +2 -2
- 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 +9 -7
- 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
|
@@ -20,39 +20,39 @@ class ConfigManager {
|
|
|
20
20
|
this.config = this.defaultConfig;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Load and validate the configuration
|
|
24
24
|
*/
|
|
25
25
|
async load(config, projectPath = process.cwd(), tracker) {
|
|
26
|
-
//
|
|
26
|
+
// process config
|
|
27
27
|
const userConfig = await this.handleConfig(config, projectPath, tracker);
|
|
28
|
-
//
|
|
28
|
+
// validate config
|
|
29
29
|
const validatedConfig = this.validateConfig(userConfig);
|
|
30
|
-
//
|
|
30
|
+
// update config
|
|
31
31
|
this.config = validatedConfig;
|
|
32
32
|
this.readConfig = Object.freeze(this.config);
|
|
33
33
|
logger_1.logger.debug('Configuration loaded successfully', this.config);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Get the full configuration
|
|
37
37
|
*/
|
|
38
38
|
getConfig() {
|
|
39
39
|
return this.readConfig;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Update configuration
|
|
43
43
|
*/
|
|
44
44
|
async update(partialConfig) {
|
|
45
45
|
await this.load({ ...this.config, ...partialConfig });
|
|
46
46
|
}
|
|
47
47
|
async handleConfig(config, projectPath = process.cwd(), tracker) {
|
|
48
|
-
//
|
|
48
|
+
// merge config
|
|
49
49
|
const userConfig = this.mergeConfig(this.defaultConfig, config);
|
|
50
|
-
//
|
|
50
|
+
// process plugin config configurations
|
|
51
51
|
userConfig.generator = await Promise.all(userConfig.generator.map(item => (0, prepareConfig_1.default)(item, projectPath, tracker)));
|
|
52
52
|
return userConfig;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
*
|
|
55
|
+
* Validate configuration
|
|
56
56
|
*/
|
|
57
57
|
validateConfig(config) {
|
|
58
58
|
let result = config;
|
|
@@ -66,7 +66,7 @@ class ConfigManager {
|
|
|
66
66
|
return result;
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* Merge configuration (shallow copy)
|
|
70
70
|
*/
|
|
71
71
|
mergeConfig(defaultConfig, userConfig) {
|
|
72
72
|
const result = { ...defaultConfig, ...userConfig };
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.zConfig = exports.zGeneratorConfig = exports._zGeneratorConfig = exports.zApiPlugin = exports.zFetchOptions = exports.zHandleApi = exports.zApiDescriptor = exports.zTemplateResult = exports.zTemplateType = exports.zConfigType = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const v3_1 = require("zod/v3"); // v4
|
|
8
|
+
const v3_1 = require("zod/v3"); // v4 is unstable, temporarily using v3
|
|
9
9
|
/**
|
|
10
10
|
* Find the corresponding input attribute value
|
|
11
11
|
*/
|
|
@@ -4,7 +4,7 @@ exports.openApiHelper = exports.OpenApiHelper = exports.supportedApiMethods = vo
|
|
|
4
4
|
const type_1 = require("../../type");
|
|
5
5
|
const utils_1 = require("../../utils");
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* List of supported API methods
|
|
8
8
|
* @see https://github.com/alovajs/alova/blob/main/packages/alova/typings/index.d.ts#L640
|
|
9
9
|
*/
|
|
10
10
|
exports.supportedApiMethods = [
|
|
@@ -53,12 +53,12 @@ class OpenApiHelper {
|
|
|
53
53
|
return apiMethods;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* Write the ApiMethods array back into the openapi document's paths.
|
|
57
|
+
* Only updates the operationObject for the passed url+method, keeping the rest untouched.
|
|
58
58
|
*/
|
|
59
59
|
saveApiMethods(apiMethods) {
|
|
60
60
|
this.document.paths = {};
|
|
61
|
-
//
|
|
61
|
+
// build a url -> { method -> operationObject } map; later writes overwrite earlier ones
|
|
62
62
|
const grouped = {};
|
|
63
63
|
for (const item of apiMethods || []) {
|
|
64
64
|
if (!item || !item.url || !item.method || !item.operationObject) {
|
|
@@ -66,7 +66,7 @@ class OpenApiHelper {
|
|
|
66
66
|
}
|
|
67
67
|
const method = String(item.method).toLowerCase();
|
|
68
68
|
if (!exports.supportedApiMethods.includes(method)) {
|
|
69
|
-
//
|
|
69
|
+
// skip unsupported http methods
|
|
70
70
|
continue;
|
|
71
71
|
}
|
|
72
72
|
if (!grouped[item.url]) {
|
|
@@ -74,7 +74,7 @@ class OpenApiHelper {
|
|
|
74
74
|
}
|
|
75
75
|
grouped[item.url][method] = item.operationObject;
|
|
76
76
|
}
|
|
77
|
-
//
|
|
77
|
+
// write the grouped methods back into document.paths
|
|
78
78
|
for (const [url, methodsMap] of Object.entries(grouped)) {
|
|
79
79
|
const pathInfo = (this.document.paths?.[url] || {});
|
|
80
80
|
for (const [method, operationObject] of Object.entries(methodsMap)) {
|
|
@@ -84,13 +84,13 @@ class OpenApiHelper {
|
|
|
84
84
|
this.document.paths[url] = pathInfo;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
//
|
|
87
|
+
// clear the reference cache after updating, ensuring subsequent used-reference computations are up to date
|
|
88
88
|
this.usedRefsCache.clear();
|
|
89
89
|
return this;
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
*
|
|
93
|
-
* @param ref ReferenceObject
|
|
92
|
+
* Check whether a reference is used in the document
|
|
93
|
+
* @param ref ReferenceObject or its `$ref` path string
|
|
94
94
|
*/
|
|
95
95
|
isReferenceUsed(ref) {
|
|
96
96
|
const refPath = typeof ref === 'string' ? ref : ref.$ref;
|
|
@@ -98,7 +98,7 @@ class OpenApiHelper {
|
|
|
98
98
|
return usedSet.has(refPath);
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
*
|
|
101
|
+
* Precompute and return the set of used `$ref`s, reachable only from paths
|
|
102
102
|
*/
|
|
103
103
|
getUsedReferenceSet() {
|
|
104
104
|
if (this.usedRefsCache.size > 0) {
|
|
@@ -145,7 +145,7 @@ class OpenApiHelper {
|
|
|
145
145
|
return used;
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
|
-
*
|
|
148
|
+
* Filter out unused references and return the list of still-used references
|
|
149
149
|
*/
|
|
150
150
|
filterUsedReferences(refs) {
|
|
151
151
|
const usedSet = this.getUsedReferenceSet();
|
|
@@ -11,13 +11,13 @@ const constant_1 = require("../../constant");
|
|
|
11
11
|
const wormaJson_1 = require("../../functions/wormaJson");
|
|
12
12
|
const logger_1 = require("../../helper/logger");
|
|
13
13
|
const utils_1 = require("../../utils");
|
|
14
|
-
/** M1-A2: Handlebars
|
|
14
|
+
/** M1-A2: Handlebars instance cache — reuse compiled partials and helpers for the same templatePath */
|
|
15
15
|
const hbsInstanceCache = new Map();
|
|
16
16
|
const templateCompileCache = new Map();
|
|
17
17
|
function cacheKey(projectPath, output) {
|
|
18
18
|
return `${projectPath}::${output}`;
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
20
|
+
/** module-type directory name (differs from config.type: commonjs -> common) */
|
|
21
21
|
exports.MODULE_TYPES = [constant_1.ModuleTypeDir.TYPESCRIPT, constant_1.ModuleTypeDir.MODULE, constant_1.ModuleTypeDir.COMMON];
|
|
22
22
|
// ---- helpers ----
|
|
23
23
|
const TEMPLATE_EXTENSIONS = [
|
|
@@ -97,7 +97,7 @@ class TemplateHelper {
|
|
|
97
97
|
static getModuleType(type) {
|
|
98
98
|
return constant_1.MODULE_TYPE_TO_KIND[type] ?? constant_1.ModuleKind.ES_MODULE;
|
|
99
99
|
}
|
|
100
|
-
// ============
|
|
100
|
+
// ============ cache ============
|
|
101
101
|
static async readData(projectPath, output) {
|
|
102
102
|
const key = cacheKey(projectPath, output);
|
|
103
103
|
const cached = TemplateHelper._cacheData.get(key);
|
|
@@ -148,7 +148,7 @@ class TemplateHelper {
|
|
|
148
148
|
await promises_1.default.unlink(p);
|
|
149
149
|
}));
|
|
150
150
|
}
|
|
151
|
-
// ============
|
|
151
|
+
// ============ template resolution ============
|
|
152
152
|
async resolveTemplateFiles(templatePath) {
|
|
153
153
|
const absolute = node_path_1.default.isAbsolute(templatePath) ? templatePath : node_path_1.default.resolve(process.cwd(), templatePath);
|
|
154
154
|
if (!(await (0, utils_1.existsPromise)(absolute)))
|
|
@@ -239,7 +239,7 @@ class TemplateHelper {
|
|
|
239
239
|
insideTagDir,
|
|
240
240
|
};
|
|
241
241
|
}
|
|
242
|
-
// ============
|
|
242
|
+
// ============ render & output ============
|
|
243
243
|
async renderTemplate(templateFilePath, data) {
|
|
244
244
|
const p = node_path_1.default.isAbsolute(this.config.templatePath)
|
|
245
245
|
? node_path_1.default.join(this.config.templatePath, `${templateFilePath}${constant_1.FileExtension.HANDLEBARS}`)
|
|
@@ -258,7 +258,7 @@ class TemplateHelper {
|
|
|
258
258
|
}
|
|
259
259
|
return template(data);
|
|
260
260
|
}
|
|
261
|
-
/** M1-A2:
|
|
261
|
+
/** M1-A2: clear Handlebars compile and instance caches (used by tests and watch mode) */
|
|
262
262
|
static clearTemplateCache() {
|
|
263
263
|
hbsInstanceCache.clear();
|
|
264
264
|
templateCompileCache.clear();
|
|
@@ -356,10 +356,10 @@ class TemplateHelper {
|
|
|
356
356
|
});
|
|
357
357
|
const { changedTags, beforeFileWrite, writeConcurrency = 32, formatFile = true } = options ?? {};
|
|
358
358
|
const hbs = await this.createHbs();
|
|
359
|
-
const tags = data.tagedApis?.map(item => item.
|
|
359
|
+
const tags = data.tagedApis?.map(item => item.tag) || [];
|
|
360
360
|
const apis = data.allApis || [];
|
|
361
361
|
const tagApisMap = new Map();
|
|
362
|
-
data.tagedApis?.forEach(item => tagApisMap.set(item.
|
|
362
|
+
data.tagedApis?.forEach(item => tagApisMap.set(item.tag, item));
|
|
363
363
|
// Collect all file paths for codeGenerated notification
|
|
364
364
|
const allFilePaths = [];
|
|
365
365
|
// --- Phase 1: Per-tag streaming (render → collect → batch write) ---
|
|
@@ -461,7 +461,7 @@ class TemplateHelper {
|
|
|
461
461
|
}
|
|
462
462
|
async renderOne(hbs, tf, data, outputDir, placeholders) {
|
|
463
463
|
const renderData = data.config ? { ...data.config, ...data } : data;
|
|
464
|
-
const content = await this.renderTemplateFromPath(hbs, tf.absolutePath, renderData);
|
|
464
|
+
const content = await this.renderTemplateFromPath(hbs, tf.absolutePath, { ...renderData, noOverwrite: tf.isNoOverwrite });
|
|
465
465
|
let relPath = tf.relativePath;
|
|
466
466
|
if (placeholders?.tag)
|
|
467
467
|
relPath = relPath.replace(constant_1.TemplatePlaceholder.TAG, placeholders.tag);
|
|
@@ -54,7 +54,7 @@ function aiDoc(config) {
|
|
|
54
54
|
...group,
|
|
55
55
|
apis: group.apis.map(api => ({
|
|
56
56
|
...api,
|
|
57
|
-
...(isGlobals ? {} : { fileLocation: `${outputRel.replace(/\\/g, '/')}/${group.
|
|
57
|
+
...(isGlobals ? {} : { fileLocation: `${outputRel.replace(/\\/g, '/')}/${group.tag}` }),
|
|
58
58
|
})),
|
|
59
59
|
})),
|
|
60
60
|
};
|
|
@@ -18,10 +18,10 @@ function apifox({ projectId, locale = 'zh-CN', apifoxVersion = '2024-03-28', sco
|
|
|
18
18
|
branchId,
|
|
19
19
|
moduleId,
|
|
20
20
|
};
|
|
21
|
-
//
|
|
21
|
+
// set the corresponding params based on the scope type
|
|
22
22
|
switch (scopeType) {
|
|
23
23
|
case 'ALL':
|
|
24
|
-
//
|
|
24
|
+
// exporting all does not require extra params
|
|
25
25
|
break;
|
|
26
26
|
case 'SELECTED_ENDPOINTS':
|
|
27
27
|
body.scope.selectedEndpointIds = selectedEndpointIds;
|
|
@@ -128,6 +128,9 @@ function applyToSchemaField(schema, config) {
|
|
|
128
128
|
function payloadModifierApiDescriptor(apiDescriptor, config) {
|
|
129
129
|
if (!apiDescriptor)
|
|
130
130
|
return null;
|
|
131
|
+
// API path filter: if path does not match, return as-is and this config does not apply
|
|
132
|
+
if (!(0, utils_1.isMatch)(apiDescriptor.url, config.path))
|
|
133
|
+
return apiDescriptor;
|
|
131
134
|
const newDescriptor = { ...apiDescriptor };
|
|
132
135
|
const { scope } = config;
|
|
133
136
|
switch (scope) {
|
|
@@ -241,6 +241,11 @@ function transformRefNameMap(refNameMap, config, apiDescriptor) {
|
|
|
241
241
|
function renameApiDescriptor(apiDescriptor, config) {
|
|
242
242
|
if (!apiDescriptor)
|
|
243
243
|
return apiDescriptor;
|
|
244
|
+
// API path filter: when `path` is set and the url does not match, this config
|
|
245
|
+
// is a no-op and the descriptor is returned unchanged (same reference).
|
|
246
|
+
if (config.path && !(0, utils_1.isMatch)(apiDescriptor.url, config.path)) {
|
|
247
|
+
return apiDescriptor;
|
|
248
|
+
}
|
|
244
249
|
const newDescriptor = { ...apiDescriptor };
|
|
245
250
|
const scope = config.scope || constant_1.RenameScope.URL;
|
|
246
251
|
switch (scope) {
|
package/dist/readConfig.js
CHANGED
|
@@ -36,20 +36,20 @@ async function readConfig(projectPath = process.cwd()) {
|
|
|
36
36
|
}
|
|
37
37
|
return config;
|
|
38
38
|
}
|
|
39
|
-
//
|
|
39
|
+
// get the dependencies installed by the user
|
|
40
40
|
const userDependencies = await (0, utils_1.getUserInstalledDependencies)(projectPath);
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
// monorepo
|
|
41
|
+
// always treat worma itself as an external dependency to prevent esbuild from bundling worma source into the temp file
|
|
42
|
+
// otherwise __dirname would point to the user project directory, causing preset template path resolution to fail
|
|
43
|
+
// monorepo sub-packages may not directly depend on wormajs, but the config file imports from 'wormajs'
|
|
44
44
|
const allExternals = [...new Set([...userDependencies, 'worma', 'wormajs/plugin'])];
|
|
45
45
|
const configTmpFileName = `worma_tmp_${Date.now()}.cjs`;
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
//
|
|
46
|
+
// use an absolute path: esbuild resolves relative outfile against cwd,
|
|
47
|
+
// while require() resolves relative paths against the calling module's directory, and the mismatch would cause require to fail.
|
|
48
|
+
// an absolute path ensures writing and require point to the same file.
|
|
49
49
|
const outfile = node_path_1.default.resolve(projectPath, configTmpFileName);
|
|
50
50
|
await esbuild_1.default.build({
|
|
51
51
|
entryPoints: [configFile],
|
|
52
|
-
//
|
|
52
|
+
// exclude dependencies installed by the user to avoid bundling them into the final file
|
|
53
53
|
external: allExternals,
|
|
54
54
|
bundle: true,
|
|
55
55
|
format: 'cjs',
|
|
@@ -57,7 +57,7 @@ async function readConfig(projectPath = process.cwd()) {
|
|
|
57
57
|
outfile,
|
|
58
58
|
logLevel: 'silent',
|
|
59
59
|
});
|
|
60
|
-
// try/finally
|
|
60
|
+
// try/finally ensures the temp file is cleaned up in all cases (including require errors)
|
|
61
61
|
let module;
|
|
62
62
|
try {
|
|
63
63
|
// eslint-disable-next-line ts/no-require-imports
|
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
|
*/
|
|
@@ -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;
|