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,512 @@
|
|
|
1
|
+
import { MethodType, RequestBody } from 'alova';
|
|
2
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
|
+
import { z } from 'zod/v3';
|
|
4
|
+
|
|
5
|
+
declare const DEFAULT_CONFIG: {
|
|
6
|
+
cacheDir: string;
|
|
7
|
+
/** Overrides cacheDir's parent directory for monorepo unified cache. */
|
|
8
|
+
cacheRoot: string | undefined;
|
|
9
|
+
Error: ErrorConstructor;
|
|
10
|
+
templateData: Map<string, any>;
|
|
11
|
+
};
|
|
12
|
+
export declare function setGlobalConfig(config: Partial<typeof DEFAULT_CONFIG>): void;
|
|
13
|
+
export type OpenAPIDocument = OpenAPIV3_1.Document;
|
|
14
|
+
export type SchemaObject = OpenAPIV3_1.SchemaObject;
|
|
15
|
+
export type Parameter = OpenAPIV3_1.ParameterObject;
|
|
16
|
+
export type OperationObject = OpenAPIV3_1.OperationObject;
|
|
17
|
+
export interface FetchOptions {
|
|
18
|
+
headers?: Record<string, string>;
|
|
19
|
+
/** timeout in milliseconds */
|
|
20
|
+
timeout?: number;
|
|
21
|
+
method?: MethodType;
|
|
22
|
+
data?: RequestBody;
|
|
23
|
+
params?: Record<string, any>;
|
|
24
|
+
/** when true, do not throw on non-2xx but still return text; default false */
|
|
25
|
+
insecure?: boolean;
|
|
26
|
+
}
|
|
27
|
+
declare const zConfigType: z.ZodEnum<[
|
|
28
|
+
"auto",
|
|
29
|
+
"ts",
|
|
30
|
+
"typescript",
|
|
31
|
+
"module",
|
|
32
|
+
"commonjs"
|
|
33
|
+
]>;
|
|
34
|
+
declare const zTemplateType: z.ZodEnum<[
|
|
35
|
+
"typescript",
|
|
36
|
+
"module",
|
|
37
|
+
"commonjs"
|
|
38
|
+
]>;
|
|
39
|
+
/**
|
|
40
|
+
* Find the corresponding input attribute value
|
|
41
|
+
*/
|
|
42
|
+
export type ConfigType = z.infer<typeof zConfigType>;
|
|
43
|
+
/**
|
|
44
|
+
* template type
|
|
45
|
+
*/
|
|
46
|
+
export type TemplateType = z.infer<typeof zTemplateType>;
|
|
47
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Function injected into plugin hooks for reporting plugin-scoped progress.
|
|
50
|
+
*/
|
|
51
|
+
export type ReportProgress = (progress: number, message?: string) => void;
|
|
52
|
+
export interface ConfigHookParams {
|
|
53
|
+
config: GeneratorConfig;
|
|
54
|
+
projectPath: string;
|
|
55
|
+
reportProgress: ReportProgress;
|
|
56
|
+
}
|
|
57
|
+
export interface BeforeOpenapiParseHookParams {
|
|
58
|
+
config: Readonly<GeneratorConfig>;
|
|
59
|
+
projectPath: string;
|
|
60
|
+
reportProgress: ReportProgress;
|
|
61
|
+
}
|
|
62
|
+
export interface OpenapiParsedHookParams {
|
|
63
|
+
config: Readonly<GeneratorConfig>;
|
|
64
|
+
document: OpenAPIDocument;
|
|
65
|
+
projectPath: string;
|
|
66
|
+
reportProgress: ReportProgress;
|
|
67
|
+
}
|
|
68
|
+
export interface BeforeCodeGenerateHookParams {
|
|
69
|
+
config: Readonly<GeneratorConfig>;
|
|
70
|
+
data: TemplateData;
|
|
71
|
+
projectPath: string;
|
|
72
|
+
reportProgress: ReportProgress;
|
|
73
|
+
}
|
|
74
|
+
export interface BeforeFileWriteHookParams {
|
|
75
|
+
config: Readonly<GeneratorConfig>;
|
|
76
|
+
data: TemplateData;
|
|
77
|
+
filePath: string;
|
|
78
|
+
content: string;
|
|
79
|
+
projectPath: string;
|
|
80
|
+
reportProgress: ReportProgress;
|
|
81
|
+
/** Template file metadata: tag/api/global */
|
|
82
|
+
meta: {
|
|
83
|
+
templateType?: "tag" | "api";
|
|
84
|
+
tag?: string;
|
|
85
|
+
api?: string;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Parameters for the convenience renderTemplate function passed to codeGenerated hook */
|
|
89
|
+
export interface RenderTemplateParams {
|
|
90
|
+
templatePath: string;
|
|
91
|
+
type: TemplateType;
|
|
92
|
+
outputDir: string;
|
|
93
|
+
data: TemplateData;
|
|
94
|
+
options?: {
|
|
95
|
+
changedTags?: Set<string>;
|
|
96
|
+
beforeFileWrite?: (params: {
|
|
97
|
+
filePath: string;
|
|
98
|
+
content: string;
|
|
99
|
+
meta: {
|
|
100
|
+
templateType?: "tag" | "api";
|
|
101
|
+
tag?: string;
|
|
102
|
+
api?: string;
|
|
103
|
+
};
|
|
104
|
+
}) => MaybePromise<string>;
|
|
105
|
+
writeConcurrency?: number;
|
|
106
|
+
formatFile?: boolean;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
export interface CodeGeneratedHookParams {
|
|
110
|
+
config: Readonly<GeneratorConfig>;
|
|
111
|
+
data: TemplateData;
|
|
112
|
+
/** Paths of all generated files (for notification; content is not held) */
|
|
113
|
+
filePaths: string[];
|
|
114
|
+
/** Absolute output directory */
|
|
115
|
+
outputDir: string;
|
|
116
|
+
projectPath: string;
|
|
117
|
+
error?: Error;
|
|
118
|
+
reportProgress: ReportProgress;
|
|
119
|
+
/** Convenience: render a template to a directory in one call */
|
|
120
|
+
renderTemplate: (params: RenderTemplateParams) => Promise<{
|
|
121
|
+
filePaths: string[];
|
|
122
|
+
}>;
|
|
123
|
+
}
|
|
124
|
+
export interface GetTemplateHookParams {
|
|
125
|
+
config: Readonly<GeneratorConfig>;
|
|
126
|
+
projectPath: string;
|
|
127
|
+
reportProgress: ReportProgress;
|
|
128
|
+
}
|
|
129
|
+
export interface OnHandlebarsCreatedHookParams {
|
|
130
|
+
hbs: typeof import("handlebars");
|
|
131
|
+
config: Readonly<GeneratorConfig>;
|
|
132
|
+
projectPath: string;
|
|
133
|
+
reportProgress: ReportProgress;
|
|
134
|
+
}
|
|
135
|
+
export interface ApiPlugin {
|
|
136
|
+
name?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Replaces or manipulates the options object passed to worma.
|
|
139
|
+
* Returning null does NOT replacing anything.
|
|
140
|
+
*/
|
|
141
|
+
config?: (params: ConfigHookParams) => MaybePromise<GeneratorConfig | undefined | null | void>;
|
|
142
|
+
/**
|
|
143
|
+
* Called before parsing the OpenAPI file.
|
|
144
|
+
*/
|
|
145
|
+
beforeOpenapiParse?: (params: BeforeOpenapiParseHookParams) => void;
|
|
146
|
+
/**
|
|
147
|
+
* Manipulate the openapi document after parsing.
|
|
148
|
+
* Returning null does NOT replacing anything.
|
|
149
|
+
*/
|
|
150
|
+
openapiParsed?: (params: OpenapiParsedHookParams) => MaybePromise<OpenAPIDocument | undefined | null | void>;
|
|
151
|
+
/**
|
|
152
|
+
* Called before code generation. Mutate `params.data` directly to inject
|
|
153
|
+
* configuration data (no longer returns a value).
|
|
154
|
+
*/
|
|
155
|
+
beforeCodeGenerate?: (params: BeforeCodeGenerateHookParams) => MaybePromise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Called right before each file is written to disk.
|
|
158
|
+
* Can modify the file content by returning the new content.
|
|
159
|
+
*/
|
|
160
|
+
beforeFileWrite?: (params: BeforeFileWriteHookParams) => MaybePromise<string>;
|
|
161
|
+
/**
|
|
162
|
+
* Called after ALL files have been written to disk.
|
|
163
|
+
* Used for post-processing e.g. generating additional documentation, displaying notifications.
|
|
164
|
+
* The `filePaths` array contains all generated file paths (no content).
|
|
165
|
+
*/
|
|
166
|
+
codeGenerated?: (params: CodeGeneratedHookParams) => MaybePromise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Provide the template path for code generation.
|
|
169
|
+
* Multiple plugins can implement this; the last non-nil return value wins.
|
|
170
|
+
*/
|
|
171
|
+
getTemplate?: (params: GetTemplateHookParams) => MaybePromise<TemplateConfigResult | undefined | null | void>;
|
|
172
|
+
/**
|
|
173
|
+
* Called when a new Handlebars instance is created for template rendering.
|
|
174
|
+
* Use this to register custom helpers or partials on the hbs instance.
|
|
175
|
+
*/
|
|
176
|
+
onHandlebarsCreated?: (params: OnHandlebarsCreatedHookParams) => MaybePromise<void>;
|
|
177
|
+
}
|
|
178
|
+
export interface HandleApi {
|
|
179
|
+
(apiDescriptor: ApiDescriptor): ApiDescriptor | void | undefined | null;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Template configuration result
|
|
183
|
+
*/
|
|
184
|
+
export interface TemplateConfigResult {
|
|
185
|
+
/**
|
|
186
|
+
* Template path string (relative to project root or absolute path).
|
|
187
|
+
* Relative paths are resolved relative to process.cwd()
|
|
188
|
+
* This field is required.
|
|
189
|
+
*/
|
|
190
|
+
path: string;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Performance tuning options for code generation.
|
|
194
|
+
*/
|
|
195
|
+
export interface PerformanceConfig {
|
|
196
|
+
/** schema→TS worker pool strategy. Default 'auto' (adaptive by API count) */
|
|
197
|
+
workerPool?: "auto" | number | false;
|
|
198
|
+
/** Max concurrency for transform phase. Default auto (min(64, max(8, cpus*4))) */
|
|
199
|
+
transformConcurrency?: number;
|
|
200
|
+
/** Max parallelism for file writes. Default 32 */
|
|
201
|
+
writeConcurrency?: number;
|
|
202
|
+
/** Apply prettier formatting to final files before write. Default true (schema-level prettier is always disabled) */
|
|
203
|
+
formatFile?: boolean;
|
|
204
|
+
/** Sort tags/APIs/components alphabetically for deterministic output. Default true */
|
|
205
|
+
deterministicSort?: boolean;
|
|
206
|
+
}
|
|
207
|
+
export interface GeneratorConfig {
|
|
208
|
+
/**
|
|
209
|
+
* Openapi file path, it supports json and yaml file, and network url.
|
|
210
|
+
* Can be a single URL string or an array of URLs. When set to an array,
|
|
211
|
+
* each URL will be tried in order and the first successful response is returned.
|
|
212
|
+
* @requires true
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* input: 'http://localhost:3000/openapi.json'
|
|
216
|
+
* input: 'openapi/api.json' -> Take the current project as the local address of the relative directory
|
|
217
|
+
* input: ['https://primary.com/openapi.json', 'https://fallback.com/openapi.json'] -> Try each URL in order
|
|
218
|
+
*/
|
|
219
|
+
input?: string | string[];
|
|
220
|
+
fetchOptions?: FetchOptions;
|
|
221
|
+
/**
|
|
222
|
+
* A list of type identifiers to exclude from generation.
|
|
223
|
+
* Matches against type names parsed from the OpenAPI schema; matched types
|
|
224
|
+
* are skipped and referenced directly by their identifier in generated code
|
|
225
|
+
* to avoid duplicate or conflicting declarations.
|
|
226
|
+
* Use this when you already have hand-written types or types provided by
|
|
227
|
+
* frameworks/libraries that should not be generated.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* externalTypes: ['File', 'Blob', 'FormData', 'Pagination']
|
|
231
|
+
*/
|
|
232
|
+
externalTypes?: string[];
|
|
233
|
+
/**
|
|
234
|
+
* The output path of the interface file and type file, multiple generators cannot have repeated addresses, otherwise the generated codes will cover each other, which is meaningless.
|
|
235
|
+
* @requires true
|
|
236
|
+
*/
|
|
237
|
+
output?: string;
|
|
238
|
+
/**
|
|
239
|
+
* Whether to generate documentation comments, default is true.
|
|
240
|
+
* Set to false to improve generation performance.
|
|
241
|
+
* @default true
|
|
242
|
+
*/
|
|
243
|
+
docComment?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Specify the media type of the generated response data. After specifying, use this data type to generate the response ts format of the 2xx status code.
|
|
246
|
+
* Can be a string or an array of strings for fallback media types.
|
|
247
|
+
* @default 'application/json'
|
|
248
|
+
*/
|
|
249
|
+
responseMediaType?: string | string[];
|
|
250
|
+
/**
|
|
251
|
+
* Specify the media type of the generated request body data. After specifying, use this data type to generate the ts format of the request body.
|
|
252
|
+
* Can be a string or an array of strings for fallback media types.
|
|
253
|
+
* @default 'application/json'
|
|
254
|
+
*/
|
|
255
|
+
bodyMediaType?: string | string[];
|
|
256
|
+
/**
|
|
257
|
+
* Custom server name for displaying in the sidebar when multiple API docs are configured.
|
|
258
|
+
* Default names are server1, server2, server3...
|
|
259
|
+
*/
|
|
260
|
+
serverName?: string;
|
|
261
|
+
/**
|
|
262
|
+
* The type of generated code. The optional value is `auto/ts/typescript/module/commonjs`.
|
|
263
|
+
* default is `auto`, it means the type of current project will be determined through certain rules.
|
|
264
|
+
*
|
|
265
|
+
* @param type
|
|
266
|
+
* 1. ts/typescript: The same meaning means generating ts type files
|
|
267
|
+
* 2. module: generate esModule specification file
|
|
268
|
+
* 3. commonjs: means generating commonjs specification file
|
|
269
|
+
*
|
|
270
|
+
* @default 'auto'
|
|
271
|
+
*/
|
|
272
|
+
type?: ConfigType;
|
|
273
|
+
/**
|
|
274
|
+
* When there is no require, it defaults to require, and only nullable takes effect.
|
|
275
|
+
*/
|
|
276
|
+
defaultRequire?: boolean;
|
|
277
|
+
/**
|
|
278
|
+
* plugin will be executed before `handleApi`
|
|
279
|
+
*/
|
|
280
|
+
plugins?: ApiPlugin[];
|
|
281
|
+
/**
|
|
282
|
+
* Performance tuning options for code generation.
|
|
283
|
+
*/
|
|
284
|
+
performance?: PerformanceConfig;
|
|
285
|
+
/**
|
|
286
|
+
* Filter or convert the generated api function and return a new `apiDescriptor` to generate the api.
|
|
287
|
+
* When this function is not specified, `apiDescriptor` object is not converted.
|
|
288
|
+
* The type of `apiDescriptor` is the same as the api item of openapi file.
|
|
289
|
+
*
|
|
290
|
+
* @see https://spec.openapis.org/oas/v3.1.0.html#operation-object
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```js
|
|
294
|
+
* // Do not generate the apis that starts with `/user`
|
|
295
|
+
* handleApi(apiDescriptor) {
|
|
296
|
+
* if (apiDescriptor.path.startsWith('/user')) {
|
|
297
|
+
* return;
|
|
298
|
+
* }
|
|
299
|
+
* return apiDescriptor;
|
|
300
|
+
* }
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* ```js
|
|
304
|
+
* // modify the api's parameters
|
|
305
|
+
* handleApi(apiDescriptor) {
|
|
306
|
+
* apiDescriptor.parameters = (apiDescriptor.parameters || []).filter(
|
|
307
|
+
* param => param.in === 'header' && param.name === 'token'
|
|
308
|
+
* );
|
|
309
|
+
* delete apiDescriptor.requestBody.id;
|
|
310
|
+
* apiDescriptor.url = apiDescriptor.url.replace('/user', '');
|
|
311
|
+
* return apiDescriptor;
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
315
|
+
handleApi?: HandleApi;
|
|
316
|
+
}
|
|
317
|
+
export interface Config {
|
|
318
|
+
/**
|
|
319
|
+
* API generation settings are arrays. Each item represents an automatically generated rule, including the generated input and output directories, specification file addresses, etc.
|
|
320
|
+
* Currently, only OpenAPI specifications are supported, including OpenAPI 2.0 and 3.0 specifications.
|
|
321
|
+
*/
|
|
322
|
+
generator: GeneratorConfig[];
|
|
323
|
+
}
|
|
324
|
+
export type UserConfig = Config;
|
|
325
|
+
export type UserConfigFnObject = () => UserConfig;
|
|
326
|
+
export type UserConfigFnPromise = () => Promise<UserConfig>;
|
|
327
|
+
export type UserConfigFn = () => UserConfig | Promise<UserConfig>;
|
|
328
|
+
export type UserConfigExport = UserConfig | Promise<UserConfig> | UserConfigFnObject | UserConfigFnPromise | UserConfigFn;
|
|
329
|
+
export interface Api {
|
|
330
|
+
tag: string;
|
|
331
|
+
method: string;
|
|
332
|
+
summary: string;
|
|
333
|
+
path: string;
|
|
334
|
+
pathParameters: string;
|
|
335
|
+
queryParameters: string;
|
|
336
|
+
pathParametersComment?: string;
|
|
337
|
+
queryParametersComment?: string;
|
|
338
|
+
responseComment?: string;
|
|
339
|
+
requestBodyComment?: string;
|
|
340
|
+
name: string;
|
|
341
|
+
response: string;
|
|
342
|
+
requestBody?: string;
|
|
343
|
+
callingCode?: string;
|
|
344
|
+
}
|
|
345
|
+
export interface ApiDoc {
|
|
346
|
+
apis: Api[];
|
|
347
|
+
tagName: string;
|
|
348
|
+
}
|
|
349
|
+
export type ApiDescriptor = Omit<OperationObject, "requestBody" | "parameters" | "responses"> & {
|
|
350
|
+
url: string;
|
|
351
|
+
method: string;
|
|
352
|
+
parameters?: Parameter[];
|
|
353
|
+
refNameMap?: Record<string, string>;
|
|
354
|
+
requestBody?: SchemaObject;
|
|
355
|
+
responses?: SchemaObject;
|
|
356
|
+
};
|
|
357
|
+
export interface TemplateData {
|
|
358
|
+
title: OpenAPIDocument["info"]["title"];
|
|
359
|
+
openapi: OpenAPIDocument["openapi"];
|
|
360
|
+
version: OpenAPIDocument["info"]["version"];
|
|
361
|
+
description: OpenAPIDocument["info"]["description"];
|
|
362
|
+
contact: OpenAPIDocument["info"]["contact"];
|
|
363
|
+
/** Framework tag: vue | react | svelte | solid-js | nuxt */
|
|
364
|
+
framework?: string;
|
|
365
|
+
defaultKey?: boolean;
|
|
366
|
+
baseUrl: string;
|
|
367
|
+
/** Schema/Component definitions */
|
|
368
|
+
components: string[];
|
|
369
|
+
/** Names of all generated component schemas (keys of schemasMap) */
|
|
370
|
+
componentNames: string[];
|
|
371
|
+
/** All apis array */
|
|
372
|
+
allApis: Api[];
|
|
373
|
+
/** Apis grouped by tag */
|
|
374
|
+
tagedApis: ApiDoc[];
|
|
375
|
+
type: TemplateType;
|
|
376
|
+
/** Config passed from template configuration */
|
|
377
|
+
config: Record<string, any>;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Standardized cache data for VSCode extension
|
|
381
|
+
* Used for rendering sidebar API tree and quick search
|
|
382
|
+
*/
|
|
383
|
+
export interface CacheData {
|
|
384
|
+
path: string;
|
|
385
|
+
/** Server name displayed in sidebar */
|
|
386
|
+
serverName?: string;
|
|
387
|
+
/** All APIs as a flat array */
|
|
388
|
+
apis: Api[];
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Per-generator progress event.
|
|
392
|
+
*
|
|
393
|
+
* Emitted by `generate()` (when `onProgress` is provided) for each
|
|
394
|
+
* generator in the config, covering the full lifecycle:
|
|
395
|
+
*
|
|
396
|
+
* active → progress → done/failed/skipped
|
|
397
|
+
*
|
|
398
|
+
* Use TypeScript's discriminated union on `phase` to narrow the event type.
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* generate(config, {
|
|
402
|
+
* onProgress(event) {
|
|
403
|
+
* switch (event.phase) {
|
|
404
|
+
* case 'active': renderer.setActive(event.index); break
|
|
405
|
+
* case 'progress': renderer.setProgress(event.index, event.progress, event.message); break
|
|
406
|
+
* case 'done': renderer.setDone(event.index); break
|
|
407
|
+
* case 'skipped': renderer.setSkipped(event.index); break
|
|
408
|
+
* case 'failed': renderer.setFailed(event.index, event.error); break
|
|
409
|
+
* }
|
|
410
|
+
* }
|
|
411
|
+
* })
|
|
412
|
+
*/
|
|
413
|
+
export type GeneratorProgressEvent = {
|
|
414
|
+
/** 0-based index in config.generator[] */
|
|
415
|
+
index: number;
|
|
416
|
+
} & ({
|
|
417
|
+
phase: "active";
|
|
418
|
+
} | {
|
|
419
|
+
phase: "progress";
|
|
420
|
+
/** 0–100 percentage */
|
|
421
|
+
progress: number;
|
|
422
|
+
/** Human-readable stage (e.g. 'parsing openapi document') */
|
|
423
|
+
message: string;
|
|
424
|
+
/** Source of the progress event. `'core'` for the framework lifecycle, otherwise the plugin name. */
|
|
425
|
+
source?: string;
|
|
426
|
+
} | {
|
|
427
|
+
phase: "done"; /** The actual URL that was successfully parsed (may differ from config.input) */
|
|
428
|
+
resolvedInput?: string;
|
|
429
|
+
} | {
|
|
430
|
+
phase: "skipped"; /** The actual URL that was successfully parsed (may differ from config.input) */
|
|
431
|
+
resolvedInput?: string;
|
|
432
|
+
} | {
|
|
433
|
+
phase: "failed";
|
|
434
|
+
error: string;
|
|
435
|
+
});
|
|
436
|
+
export interface GenerateApiOptions {
|
|
437
|
+
force?: boolean;
|
|
438
|
+
projectPath?: string;
|
|
439
|
+
/** Per-generator lifecycle callback. Receives a discriminated union of {@link GeneratorProgressEvent}. */
|
|
440
|
+
onProgress?: (event: GeneratorProgressEvent) => void;
|
|
441
|
+
}
|
|
442
|
+
export type TemplatePreset = "alova" | "alovaGlobals" | "axios" | "fetch" | "ky";
|
|
443
|
+
export interface ConfigCreationOptions {
|
|
444
|
+
projectPath?: string;
|
|
445
|
+
type?: TemplateType;
|
|
446
|
+
template?: TemplatePreset;
|
|
447
|
+
}
|
|
448
|
+
export declare function createConfig({ projectPath, type, template }?: ConfigCreationOptions): Promise<void>;
|
|
449
|
+
/**
|
|
450
|
+
* Type helper to make it easier to use worma.config.ts
|
|
451
|
+
* accepts a direct {@link UserConfig} object, or a function that returns it.
|
|
452
|
+
*/
|
|
453
|
+
export declare function defineConfig(config: UserConfig): UserConfig;
|
|
454
|
+
export declare function defineConfig(config: Promise<UserConfig>): Promise<UserConfig>;
|
|
455
|
+
export declare function defineConfig(config: UserConfigFnObject): UserConfigFnObject;
|
|
456
|
+
export declare function defineConfig(config: UserConfigFnPromise): UserConfigFnPromise;
|
|
457
|
+
export declare function defineConfig(config: UserConfigFn): UserConfigFn;
|
|
458
|
+
export declare function defineConfig(config: UserConfigExport): UserConfigExport;
|
|
459
|
+
/**
|
|
460
|
+
* Generate relevant API information based on the configuration object.
|
|
461
|
+
*
|
|
462
|
+
* When `options.onProgress` is provided, each generator independently reports
|
|
463
|
+
* its lifecycle via {@link GeneratorProgressEvent} discriminated union events.
|
|
464
|
+
*
|
|
465
|
+
* @param config generating config
|
|
466
|
+
* @param options config rules that contains `force`, `projectPath`, `onProgress`
|
|
467
|
+
* @returns An array that contains the result of `generator` items in configuration whether generation is successful.
|
|
468
|
+
*/
|
|
469
|
+
export declare function generate(config: Config, options?: GenerateApiOptions): Promise<boolean[]>;
|
|
470
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
471
|
+
export interface LoggerOptions {
|
|
472
|
+
level: LogLevel;
|
|
473
|
+
prefix?: string;
|
|
474
|
+
timestamp?: boolean;
|
|
475
|
+
colors?: boolean;
|
|
476
|
+
}
|
|
477
|
+
declare class Logger$1 {
|
|
478
|
+
private options;
|
|
479
|
+
configure(options: Partial<LoggerOptions>): this;
|
|
480
|
+
private getTimestamp;
|
|
481
|
+
private formatMessage;
|
|
482
|
+
private shouldLog;
|
|
483
|
+
debug(message: string, details?: unknown): void;
|
|
484
|
+
info(message: string, details?: unknown): void;
|
|
485
|
+
warn(message: string, details?: unknown): void;
|
|
486
|
+
private errorMsg;
|
|
487
|
+
error(message: string, details?: unknown): void;
|
|
488
|
+
throwError(error: string | Error, details?: unknown): Error;
|
|
489
|
+
}
|
|
490
|
+
export declare const logger: Logger$1;
|
|
491
|
+
/**
|
|
492
|
+
* Read the worma.config configuration file and return the parsed configuration object.
|
|
493
|
+
* @param projectPath The project path where the configuration file is located. The default value is `process.cwd()`.
|
|
494
|
+
* @returns a promise instance that contains configuration object.
|
|
495
|
+
*/
|
|
496
|
+
export declare function readConfig(projectPath?: string): Promise<Readonly<Config>>;
|
|
497
|
+
/**
|
|
498
|
+
* Get cached API docs. Cache is self-describing — no config needed.
|
|
499
|
+
* In monorepo, pass ANY sub-package path; cache is always read from the unified cacheRoot.
|
|
500
|
+
* @param outputs Optional filter: only return entries matching these output paths.
|
|
501
|
+
* If omitted, returns ALL cached entries (including all monorepo sub-projects).
|
|
502
|
+
* @param projectPath Project root, defaults to `process.cwd()`.
|
|
503
|
+
*/
|
|
504
|
+
export declare function getApiDocs(outputs?: string[], projectPath?: string): Promise<CacheData[]>;
|
|
505
|
+
/**
|
|
506
|
+
* Search for all directories containing worma.config configuration files under the monorepo project. It will search for configuration files based on `workspaces` in `package.json` or sub packages defined in `pnpm-workspace.yaml`
|
|
507
|
+
* @param projectPath The project path to search, defaults to `process.cwd()`.
|
|
508
|
+
* @returns An array of relative paths to directories containing worma.config configuration files.
|
|
509
|
+
*/
|
|
510
|
+
export function resolveWorkspaces(projectPath?: string): Promise<string[]>;
|
|
511
|
+
|
|
512
|
+
export {};
|