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.
Files changed (236) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +49 -0
  3. package/dist/bin/actions.js +245 -0
  4. package/dist/bin/cli.js +27 -0
  5. package/dist/bin/progressRenderer.js +47 -0
  6. package/dist/bin/renderer.js +551 -0
  7. package/dist/bin/theme.js +26 -0
  8. package/dist/config.js +19 -0
  9. package/dist/constant.js +162 -0
  10. package/dist/core/WorkerPool.js +102 -0
  11. package/dist/core/loader/astLoader/generates/array.js +34 -0
  12. package/dist/core/loader/astLoader/generates/enum.js +61 -0
  13. package/dist/core/loader/astLoader/generates/group.js +41 -0
  14. package/dist/core/loader/astLoader/generates/index.js +71 -0
  15. package/dist/core/loader/astLoader/generates/interface.js +59 -0
  16. package/dist/core/loader/astLoader/generates/simple.js +67 -0
  17. package/dist/core/loader/astLoader/generates/tuple.js +54 -0
  18. package/dist/core/loader/astLoader/generates/type.js +2 -0
  19. package/dist/core/loader/astLoader/generates/utils.js +86 -0
  20. package/dist/core/loader/astLoader/helper.js +21 -0
  21. package/dist/core/loader/astLoader/index.js +24 -0
  22. package/dist/core/loader/astLoader/normalize/index.js +70 -0
  23. package/dist/core/loader/astLoader/normalize/normalizer.js +69 -0
  24. package/dist/core/loader/astLoader/normalize/rules/convertTypeArray.js +68 -0
  25. package/dist/core/loader/astLoader/normalize/rules/handleEmptyType.js +8 -0
  26. package/dist/core/loader/astLoader/normalize/rules/inferType.js +43 -0
  27. package/dist/core/loader/astLoader/normalize/rules/mergeAnyOf.js +45 -0
  28. package/dist/core/loader/astLoader/normalize/rules/normalizeCombiningKeywords.js +26 -0
  29. package/dist/core/loader/astLoader/normalize/rules/normalizeEnum.js +38 -0
  30. package/dist/core/loader/astLoader/normalize/rules/normalizeNullType.js +24 -0
  31. package/dist/core/loader/astLoader/normalize/rules/removeRedundantKeywords.js +27 -0
  32. package/dist/core/loader/astLoader/normalize/rules/simplifySingleType.js +8 -0
  33. package/dist/core/loader/astLoader/normalize/rules/validateSchema.js +14 -0
  34. package/dist/core/loader/astLoader/parsers/array.js +28 -0
  35. package/dist/core/loader/astLoader/parsers/enum.js +49 -0
  36. package/dist/core/loader/astLoader/parsers/forward/array.js +12 -0
  37. package/dist/core/loader/astLoader/parsers/forward/enum.js +10 -0
  38. package/dist/core/loader/astLoader/parsers/forward/group.js +12 -0
  39. package/dist/core/loader/astLoader/parsers/forward/index.js +20 -0
  40. package/dist/core/loader/astLoader/parsers/forward/object.js +12 -0
  41. package/dist/core/loader/astLoader/parsers/forward/tuple.js +11 -0
  42. package/dist/core/loader/astLoader/parsers/forward/type.js +2 -0
  43. package/dist/core/loader/astLoader/parsers/group.js +50 -0
  44. package/dist/core/loader/astLoader/parsers/index.js +66 -0
  45. package/dist/core/loader/astLoader/parsers/object.js +44 -0
  46. package/dist/core/loader/astLoader/parsers/reference.js +41 -0
  47. package/dist/core/loader/astLoader/parsers/simple.js +48 -0
  48. package/dist/core/loader/astLoader/parsers/tuple.js +36 -0
  49. package/dist/core/loader/astLoader/parsers/type.js +2 -0
  50. package/dist/core/loader/astLoader/parsers/utils.js +58 -0
  51. package/dist/core/loader/callingCodeLoader/helper.js +183 -0
  52. package/dist/core/loader/callingCodeLoader/index.js +40 -0
  53. package/dist/core/loader/index.js +20 -0
  54. package/dist/core/loader/schemaLoader/index.js +101 -0
  55. package/dist/core/loader/standardLoader/helper.js +142 -0
  56. package/dist/core/loader/standardLoader/index.js +38 -0
  57. package/dist/core/loader/standardLoader/standards.js +105 -0
  58. package/dist/core/parser/index.js +18 -0
  59. package/dist/core/parser/openApiParser/helper.js +165 -0
  60. package/dist/core/parser/openApiParser/index.js +14 -0
  61. package/dist/core/parser/templateParser/helper.js +333 -0
  62. package/dist/core/parser/templateParser/index.js +314 -0
  63. package/dist/core/workerPool/index.js +6 -0
  64. package/dist/core/workerPool/poolManager.js +45 -0
  65. package/dist/core/workerPool/swagger2Worker.js +24 -0
  66. package/dist/core/workerPool/worker.js +61 -0
  67. package/dist/createConfig.js +37 -0
  68. package/dist/defineConfig.js +6 -0
  69. package/dist/functions/getAutoTemplateType.js +37 -0
  70. package/dist/functions/getFrameworkTag.js +18 -0
  71. package/dist/functions/prepareConfig.js +41 -0
  72. package/dist/functions/readWormaRc.js +155 -0
  73. package/dist/functions/wormaJson.js +232 -0
  74. package/dist/generate.js +84 -0
  75. package/dist/helper/PluginDriver.js +98 -0
  76. package/dist/helper/comment.js +88 -0
  77. package/dist/helper/config/ConfigHelper.js +79 -0
  78. package/dist/helper/config/ConfigManager.js +88 -0
  79. package/dist/helper/config/GeneratorHelper.js +343 -0
  80. package/dist/helper/config/index.js +19 -0
  81. package/dist/helper/config/type.js +2 -0
  82. package/dist/helper/config/zType.js +170 -0
  83. package/dist/helper/document/index.js +160 -0
  84. package/dist/helper/index.js +23 -0
  85. package/dist/helper/logger/index.js +76 -0
  86. package/dist/helper/progress.js +66 -0
  87. package/dist/helper/template/index.js +475 -0
  88. package/dist/index.js +33 -0
  89. package/dist/plugins/createPlugin.js +30 -0
  90. package/dist/plugins/index.js +34 -0
  91. package/dist/plugins/presets/aiDoc.js +173 -0
  92. package/dist/plugins/presets/apifox.js +56 -0
  93. package/dist/plugins/presets/filterApi.js +129 -0
  94. package/dist/plugins/presets/importType.js +49 -0
  95. package/dist/plugins/presets/payloadModifier/hepler.js +195 -0
  96. package/dist/plugins/presets/payloadModifier/index.js +122 -0
  97. package/dist/plugins/presets/payloadModifier/type.js +2 -0
  98. package/dist/plugins/presets/platform.js +73 -0
  99. package/dist/plugins/presets/rename.js +209 -0
  100. package/dist/plugins/presets/tagModifier.js +104 -0
  101. package/dist/plugins/presets/utils.js +36 -0
  102. package/dist/readConfig.js +92 -0
  103. package/dist/resolveWorkspaces.js +83 -0
  104. package/dist/template/index.js +180 -0
  105. package/dist/template/presets/ai-doc/SKILL.md.handlebars +29 -0
  106. package/dist/template/presets/ai-doc/references/{tag}/{api}.md.handlebars +54 -0
  107. package/dist/template/presets/alova/common/#index.cjs.handlebars +12 -0
  108. package/dist/template/presets/alova/common/components.d.cts.handlebars +1 -0
  109. package/dist/template/presets/alova/common/helper.cjs.handlebars +13 -0
  110. package/dist/template/presets/alova/common/services/#index.cjs.handlebars +13 -0
  111. package/dist/template/presets/alova/common/services/{tag}.cjs.handlebars +28 -0
  112. package/dist/template/presets/alova/common/services/{tag}.d.cts.handlebars +15 -0
  113. package/dist/template/presets/alova/common/typed.d.cts.handlebars +1 -0
  114. package/dist/template/presets/alova/module/#index.js.handlebars +12 -0
  115. package/dist/template/presets/alova/module/components.d.ts.handlebars +1 -0
  116. package/dist/template/presets/alova/module/helper.js.handlebars +11 -0
  117. package/dist/template/presets/alova/module/services/#index.js.handlebars +9 -0
  118. package/dist/template/presets/alova/module/services/{tag}.d.ts.handlebars +15 -0
  119. package/dist/template/presets/alova/module/services/{tag}.js.handlebars +21 -0
  120. package/dist/template/presets/alova/module/typed.d.ts.handlebars +1 -0
  121. package/dist/template/presets/alova/partials/api-jsdoc.handlebars +44 -0
  122. package/dist/template/presets/alova/partials/build-payload-body.handlebars +22 -0
  123. package/dist/template/presets/alova/partials/comment.handlebars +19 -0
  124. package/dist/template/presets/alova/partials/components-body.handlebars +4 -0
  125. package/dist/template/presets/alova/partials/dts-extra-config.handlebars +8 -0
  126. package/dist/template/presets/alova/partials/dts-fn-declare.handlebars +1 -0
  127. package/dist/template/presets/alova/partials/extract-responded.handlebars +11 -0
  128. package/dist/template/presets/alova/partials/stateshook-import.handlebars +9 -0
  129. package/dist/template/presets/alova/partials/stateshook-option.handlebars +9 -0
  130. package/dist/template/presets/alova/partials/typed-body.handlebars +43 -0
  131. package/dist/template/presets/alova/typescript/#index.ts.handlebars +14 -0
  132. package/dist/template/presets/alova/typescript/components.d.ts.handlebars +1 -0
  133. package/dist/template/presets/alova/typescript/helper.ts.handlebars +9 -0
  134. package/dist/template/presets/alova/typescript/services/#index.ts.handlebars +9 -0
  135. package/dist/template/presets/alova/typescript/services/{tag}.ts.handlebars +35 -0
  136. package/dist/template/presets/alova/typescript/typed.ts.handlebars +1 -0
  137. package/dist/template/presets/alova-globals/common/#index.cjs.handlebars +41 -0
  138. package/dist/template/presets/alova-globals/common/apiDefinitions.cjs.handlebars +12 -0
  139. package/dist/template/presets/alova-globals/common/createApis.cjs.handlebars +48 -0
  140. package/dist/template/presets/alova-globals/common/globals.d.cts.handlebars +2 -0
  141. package/dist/template/presets/alova-globals/module/#index.js.handlebars +2 -0
  142. package/dist/template/presets/alova-globals/module/apiDefinitions.js.handlebars +12 -0
  143. package/dist/template/presets/alova-globals/module/createApis.js.handlebars +44 -0
  144. package/dist/template/presets/alova-globals/module/globals.d.ts.handlebars +2 -0
  145. package/dist/template/presets/alova-globals/partials/comment.handlebars +19 -0
  146. package/dist/template/presets/alova-globals/partials/createApis-proxy-js.handlebars +55 -0
  147. package/dist/template/presets/alova-globals/partials/globals-d-ts.handlebars +148 -0
  148. package/dist/template/presets/alova-globals/partials/index-esm.handlebars +38 -0
  149. package/dist/template/presets/alova-globals/partials/withConfigType-jsdoc.handlebars +22 -0
  150. package/dist/template/presets/alova-globals/typescript/#index.ts.handlebars +2 -0
  151. package/dist/template/presets/alova-globals/typescript/apiDefinitions.ts.handlebars +12 -0
  152. package/dist/template/presets/alova-globals/typescript/createApis.ts.handlebars +99 -0
  153. package/dist/template/presets/alova-globals/typescript/globals.d.ts.handlebars +2 -0
  154. package/dist/template/presets/axios/common/#index.cjs.handlebars +22 -0
  155. package/dist/template/presets/axios/common/components.d.cts.handlebars +1 -0
  156. package/dist/template/presets/axios/common/helper.cjs.handlebars +27 -0
  157. package/dist/template/presets/axios/common/services/#index.cjs.handlebars +13 -0
  158. package/dist/template/presets/axios/common/services/{tag}.cjs.handlebars +28 -0
  159. package/dist/template/presets/axios/common/services/{tag}.d.cts.handlebars +11 -0
  160. package/dist/template/presets/axios/module/#index.js.handlebars +20 -0
  161. package/dist/template/presets/axios/module/components.d.ts.handlebars +1 -0
  162. package/dist/template/presets/axios/module/helper.js.handlebars +25 -0
  163. package/dist/template/presets/axios/module/services/#index.js.handlebars +9 -0
  164. package/dist/template/presets/axios/module/services/{tag}.d.ts.handlebars +11 -0
  165. package/dist/template/presets/axios/module/services/{tag}.js.handlebars +20 -0
  166. package/dist/template/presets/axios/partials/api-jsdoc.handlebars +44 -0
  167. package/dist/template/presets/axios/partials/comment.handlebars +19 -0
  168. package/dist/template/presets/axios/partials/components-body.handlebars +4 -0
  169. package/dist/template/presets/axios/partials/dts-fn-declare.handlebars +1 -0
  170. package/dist/template/presets/axios/partials/dts-types.handlebars +7 -0
  171. package/dist/template/presets/axios/typescript/#index.ts.handlebars +20 -0
  172. package/dist/template/presets/axios/typescript/components.d.ts.handlebars +1 -0
  173. package/dist/template/presets/axios/typescript/helper.ts.handlebars +28 -0
  174. package/dist/template/presets/axios/typescript/services/#index.ts.handlebars +9 -0
  175. package/dist/template/presets/axios/typescript/services/{tag}.ts.handlebars +31 -0
  176. package/dist/template/presets/config/common/worma.config.js.handlebars +9 -0
  177. package/dist/template/presets/config/module/worma.config.js.handlebars +9 -0
  178. package/dist/template/presets/config/partials/generator-content.handlebars +45 -0
  179. package/dist/template/presets/config/typescript/worma.config.ts.handlebars +9 -0
  180. package/dist/template/presets/fetch/common/#index.cjs.handlebars +17 -0
  181. package/dist/template/presets/fetch/common/FetchClient.cjs.handlebars +48 -0
  182. package/dist/template/presets/fetch/common/components.d.cts.handlebars +1 -0
  183. package/dist/template/presets/fetch/common/helper.cjs.handlebars +27 -0
  184. package/dist/template/presets/fetch/common/services/#index.cjs.handlebars +13 -0
  185. package/dist/template/presets/fetch/common/services/{tag}.cjs.handlebars +23 -0
  186. package/dist/template/presets/fetch/common/services/{tag}.d.cts.handlebars +10 -0
  187. package/dist/template/presets/fetch/module/#index.js.handlebars +15 -0
  188. package/dist/template/presets/fetch/module/FetchClient.js.handlebars +46 -0
  189. package/dist/template/presets/fetch/module/components.d.ts.handlebars +1 -0
  190. package/dist/template/presets/fetch/module/helper.js.handlebars +25 -0
  191. package/dist/template/presets/fetch/module/services/#index.js.handlebars +9 -0
  192. package/dist/template/presets/fetch/module/services/{tag}.d.ts.handlebars +10 -0
  193. package/dist/template/presets/fetch/module/services/{tag}.js.handlebars +15 -0
  194. package/dist/template/presets/fetch/partials/api-jsdoc.handlebars +44 -0
  195. package/dist/template/presets/fetch/partials/comment.handlebars +19 -0
  196. package/dist/template/presets/fetch/partials/components-body.handlebars +4 -0
  197. package/dist/template/presets/fetch/partials/dts-fn-declare.handlebars +1 -0
  198. package/dist/template/presets/fetch/partials/dts-types.handlebars +7 -0
  199. package/dist/template/presets/fetch/typescript/#index.ts.handlebars +15 -0
  200. package/dist/template/presets/fetch/typescript/FetchClient.ts.handlebars +59 -0
  201. package/dist/template/presets/fetch/typescript/components.d.ts.handlebars +1 -0
  202. package/dist/template/presets/fetch/typescript/helper.ts.handlebars +28 -0
  203. package/dist/template/presets/fetch/typescript/services/#index.ts.handlebars +9 -0
  204. package/dist/template/presets/fetch/typescript/services/{tag}.ts.handlebars +25 -0
  205. package/dist/template/presets/ky/module/#index.js.handlebars +14 -0
  206. package/dist/template/presets/ky/module/components.d.ts.handlebars +1 -0
  207. package/dist/template/presets/ky/module/helper.js.handlebars +27 -0
  208. package/dist/template/presets/ky/module/services/#index.js.handlebars +9 -0
  209. package/dist/template/presets/ky/module/services/{tag}.d.ts.handlebars +11 -0
  210. package/dist/template/presets/ky/module/services/{tag}.js.handlebars +19 -0
  211. package/dist/template/presets/ky/partials/api-jsdoc.handlebars +44 -0
  212. package/dist/template/presets/ky/partials/comment.handlebars +19 -0
  213. package/dist/template/presets/ky/partials/components-body.handlebars +4 -0
  214. package/dist/template/presets/ky/partials/dts-fn-declare.handlebars +1 -0
  215. package/dist/template/presets/ky/partials/dts-types.handlebars +9 -0
  216. package/dist/template/presets/ky/typescript/#index.ts.handlebars +14 -0
  217. package/dist/template/presets/ky/typescript/components.d.ts.handlebars +1 -0
  218. package/dist/template/presets/ky/typescript/helper.ts.handlebars +30 -0
  219. package/dist/template/presets/ky/typescript/services/#index.ts.handlebars +9 -0
  220. package/dist/template/presets/ky/typescript/services/{tag}.ts.handlebars +30 -0
  221. package/dist/tsconfig.build.tsbuildinfo +1 -0
  222. package/dist/type/api.js +14 -0
  223. package/dist/type/ast.js +24 -0
  224. package/dist/type/base.js +17 -0
  225. package/dist/type/index.js +20 -0
  226. package/dist/type/lib.js +17 -0
  227. package/dist/type/openapi.js +2 -0
  228. package/dist/utils/base.js +212 -0
  229. package/dist/utils/format.js +64 -0
  230. package/dist/utils/index.js +21 -0
  231. package/dist/utils/openapi.js +417 -0
  232. package/dist/utils/readPackageJson.js +35 -0
  233. package/dist/utils/template.js +93 -0
  234. package/package.json +88 -0
  235. package/typings/index.d.ts +512 -0
  236. package/typings/plugins.d.ts +727 -0
@@ -0,0 +1,727 @@
1
+ import { MethodType, RequestBody } from 'alova';
2
+ import { OpenAPIV3_1 } from 'openapi-types';
3
+ import { z } from 'zod/v3';
4
+
5
+ export interface FetchOptions {
6
+ headers?: Record<string, string>;
7
+ /** timeout in milliseconds */
8
+ timeout?: number;
9
+ method?: MethodType;
10
+ data?: RequestBody;
11
+ params?: Record<string, any>;
12
+ /** when true, do not throw on non-2xx but still return text; default false */
13
+ insecure?: boolean;
14
+ }
15
+ declare const zConfigType: z.ZodEnum<[
16
+ "auto",
17
+ "ts",
18
+ "typescript",
19
+ "module",
20
+ "commonjs"
21
+ ]>;
22
+ declare const zTemplateType: z.ZodEnum<[
23
+ "typescript",
24
+ "module",
25
+ "commonjs"
26
+ ]>;
27
+ /**
28
+ * Find the corresponding input attribute value
29
+ */
30
+ export type ConfigType = z.infer<typeof zConfigType>;
31
+ /**
32
+ * template type
33
+ */
34
+ export type TemplateType = z.infer<typeof zTemplateType>;
35
+ export type MaybePromise<T> = T | Promise<T>;
36
+ /**
37
+ * Function injected into plugin hooks for reporting plugin-scoped progress.
38
+ */
39
+ export type ReportProgress = (progress: number, message?: string) => void;
40
+ export interface ConfigHookParams {
41
+ config: GeneratorConfig;
42
+ projectPath: string;
43
+ reportProgress: ReportProgress;
44
+ }
45
+ export interface BeforeOpenapiParseHookParams {
46
+ config: Readonly<GeneratorConfig>;
47
+ projectPath: string;
48
+ reportProgress: ReportProgress;
49
+ }
50
+ export interface OpenapiParsedHookParams {
51
+ config: Readonly<GeneratorConfig>;
52
+ document: OpenAPIDocument;
53
+ projectPath: string;
54
+ reportProgress: ReportProgress;
55
+ }
56
+ export interface BeforeCodeGenerateHookParams {
57
+ config: Readonly<GeneratorConfig>;
58
+ data: TemplateData;
59
+ projectPath: string;
60
+ reportProgress: ReportProgress;
61
+ }
62
+ export interface BeforeFileWriteHookParams {
63
+ config: Readonly<GeneratorConfig>;
64
+ data: TemplateData;
65
+ filePath: string;
66
+ content: string;
67
+ projectPath: string;
68
+ reportProgress: ReportProgress;
69
+ /** Template file metadata: tag/api/global */
70
+ meta: {
71
+ templateType?: "tag" | "api";
72
+ tag?: string;
73
+ api?: string;
74
+ };
75
+ }
76
+ /** Parameters for the convenience renderTemplate function passed to codeGenerated hook */
77
+ export interface RenderTemplateParams {
78
+ templatePath: string;
79
+ type: TemplateType;
80
+ outputDir: string;
81
+ data: TemplateData;
82
+ options?: {
83
+ changedTags?: Set<string>;
84
+ beforeFileWrite?: (params: {
85
+ filePath: string;
86
+ content: string;
87
+ meta: {
88
+ templateType?: "tag" | "api";
89
+ tag?: string;
90
+ api?: string;
91
+ };
92
+ }) => MaybePromise<string>;
93
+ writeConcurrency?: number;
94
+ formatFile?: boolean;
95
+ };
96
+ }
97
+ export interface CodeGeneratedHookParams {
98
+ config: Readonly<GeneratorConfig>;
99
+ data: TemplateData;
100
+ /** Paths of all generated files (for notification; content is not held) */
101
+ filePaths: string[];
102
+ /** Absolute output directory */
103
+ outputDir: string;
104
+ projectPath: string;
105
+ error?: Error;
106
+ reportProgress: ReportProgress;
107
+ /** Convenience: render a template to a directory in one call */
108
+ renderTemplate: (params: RenderTemplateParams) => Promise<{
109
+ filePaths: string[];
110
+ }>;
111
+ }
112
+ export interface GetTemplateHookParams {
113
+ config: Readonly<GeneratorConfig>;
114
+ projectPath: string;
115
+ reportProgress: ReportProgress;
116
+ }
117
+ export interface OnHandlebarsCreatedHookParams {
118
+ hbs: typeof import("handlebars");
119
+ config: Readonly<GeneratorConfig>;
120
+ projectPath: string;
121
+ reportProgress: ReportProgress;
122
+ }
123
+ export interface ApiPlugin {
124
+ name?: string;
125
+ /**
126
+ * Replaces or manipulates the options object passed to worma.
127
+ * Returning null does NOT replacing anything.
128
+ */
129
+ config?: (params: ConfigHookParams) => MaybePromise<GeneratorConfig | undefined | null | void>;
130
+ /**
131
+ * Called before parsing the OpenAPI file.
132
+ */
133
+ beforeOpenapiParse?: (params: BeforeOpenapiParseHookParams) => void;
134
+ /**
135
+ * Manipulate the openapi document after parsing.
136
+ * Returning null does NOT replacing anything.
137
+ */
138
+ openapiParsed?: (params: OpenapiParsedHookParams) => MaybePromise<OpenAPIDocument | undefined | null | void>;
139
+ /**
140
+ * Called before code generation. Mutate `params.data` directly to inject
141
+ * configuration data (no longer returns a value).
142
+ */
143
+ beforeCodeGenerate?: (params: BeforeCodeGenerateHookParams) => MaybePromise<void>;
144
+ /**
145
+ * Called right before each file is written to disk.
146
+ * Can modify the file content by returning the new content.
147
+ */
148
+ beforeFileWrite?: (params: BeforeFileWriteHookParams) => MaybePromise<string>;
149
+ /**
150
+ * Called after ALL files have been written to disk.
151
+ * Used for post-processing e.g. generating additional documentation, displaying notifications.
152
+ * The `filePaths` array contains all generated file paths (no content).
153
+ */
154
+ codeGenerated?: (params: CodeGeneratedHookParams) => MaybePromise<void>;
155
+ /**
156
+ * Provide the template path for code generation.
157
+ * Multiple plugins can implement this; the last non-nil return value wins.
158
+ */
159
+ getTemplate?: (params: GetTemplateHookParams) => MaybePromise<TemplateConfigResult | undefined | null | void>;
160
+ /**
161
+ * Called when a new Handlebars instance is created for template rendering.
162
+ * Use this to register custom helpers or partials on the hbs instance.
163
+ */
164
+ onHandlebarsCreated?: (params: OnHandlebarsCreatedHookParams) => MaybePromise<void>;
165
+ }
166
+ export interface HandleApi {
167
+ (apiDescriptor: ApiDescriptor): ApiDescriptor | void | undefined | null;
168
+ }
169
+ /**
170
+ * Template configuration result
171
+ */
172
+ export interface TemplateConfigResult {
173
+ /**
174
+ * Template path string (relative to project root or absolute path).
175
+ * Relative paths are resolved relative to process.cwd()
176
+ * This field is required.
177
+ */
178
+ path: string;
179
+ }
180
+ /**
181
+ * Options for globals template
182
+ */
183
+ export interface GlobalsTemplateOptions {
184
+ /**
185
+ * Globally exported api name, you can access the automatically generated api globally through this name.
186
+ * Default is 'Apis'. Required when multiple generators are configured, and cannot be repeated.
187
+ */
188
+ global?: string;
189
+ /**
190
+ * The host object of global mounting, default is `globalThis`, it means `window` in browser and `global` in nodejs
191
+ * @default 'globalThis'
192
+ */
193
+ globalHost?: string;
194
+ /**
195
+ * Whether to use `import` statement to import the type. When this option is set to `true`, the generated apiDefinitions.ts file will use `import` statement to import types instead of ///<reference types="..." />
196
+ * @default false
197
+ */
198
+ useImportType?: boolean;
199
+ }
200
+ /**
201
+ * Options for functional template
202
+ */
203
+ export interface FunctionalTemplateOptions {
204
+ /**
205
+ * Whether to use `import` statement to import the type. When this option is set to `true`, the generated apiDefinitions.ts file will use `import` statement to import types instead of ///<reference types="..." />
206
+ * @default false
207
+ */
208
+ useImportType?: boolean;
209
+ }
210
+ /**
211
+ * Options for axios/fetch/ky templates
212
+ */
213
+ export interface RequestLibTemplateOptions {
214
+ /**
215
+ * Whether to use `import` statement to import the type. When this option is set to `true`, the generated apiDefinitions.ts file will use `import` statement to import types instead of ///<reference types="..." />
216
+ * @default false
217
+ */
218
+ useImportType?: boolean;
219
+ }
220
+ /**
221
+ * Performance tuning options for code generation.
222
+ */
223
+ export interface PerformanceConfig {
224
+ /** schema→TS worker pool strategy. Default 'auto' (adaptive by API count) */
225
+ workerPool?: "auto" | number | false;
226
+ /** Max concurrency for transform phase. Default auto (min(64, max(8, cpus*4))) */
227
+ transformConcurrency?: number;
228
+ /** Max parallelism for file writes. Default 32 */
229
+ writeConcurrency?: number;
230
+ /** Apply prettier formatting to final files before write. Default true (schema-level prettier is always disabled) */
231
+ formatFile?: boolean;
232
+ /** Sort tags/APIs/components alphabetically for deterministic output. Default true */
233
+ deterministicSort?: boolean;
234
+ }
235
+ export interface GeneratorConfig {
236
+ /**
237
+ * Openapi file path, it supports json and yaml file, and network url.
238
+ * Can be a single URL string or an array of URLs. When set to an array,
239
+ * each URL will be tried in order and the first successful response is returned.
240
+ * @requires true
241
+ *
242
+ * @example
243
+ * input: 'http://localhost:3000/openapi.json'
244
+ * input: 'openapi/api.json' -> Take the current project as the local address of the relative directory
245
+ * input: ['https://primary.com/openapi.json', 'https://fallback.com/openapi.json'] -> Try each URL in order
246
+ */
247
+ input?: string | string[];
248
+ fetchOptions?: FetchOptions;
249
+ /**
250
+ * A list of type identifiers to exclude from generation.
251
+ * Matches against type names parsed from the OpenAPI schema; matched types
252
+ * are skipped and referenced directly by their identifier in generated code
253
+ * to avoid duplicate or conflicting declarations.
254
+ * Use this when you already have hand-written types or types provided by
255
+ * frameworks/libraries that should not be generated.
256
+ *
257
+ * @example
258
+ * externalTypes: ['File', 'Blob', 'FormData', 'Pagination']
259
+ */
260
+ externalTypes?: string[];
261
+ /**
262
+ * 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.
263
+ * @requires true
264
+ */
265
+ output?: string;
266
+ /**
267
+ * Whether to generate documentation comments, default is true.
268
+ * Set to false to improve generation performance.
269
+ * @default true
270
+ */
271
+ docComment?: boolean;
272
+ /**
273
+ * 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.
274
+ * Can be a string or an array of strings for fallback media types.
275
+ * @default 'application/json'
276
+ */
277
+ responseMediaType?: string | string[];
278
+ /**
279
+ * 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.
280
+ * Can be a string or an array of strings for fallback media types.
281
+ * @default 'application/json'
282
+ */
283
+ bodyMediaType?: string | string[];
284
+ /**
285
+ * Custom server name for displaying in the sidebar when multiple API docs are configured.
286
+ * Default names are server1, server2, server3...
287
+ */
288
+ serverName?: string;
289
+ /**
290
+ * The type of generated code. The optional value is `auto/ts/typescript/module/commonjs`.
291
+ * default is `auto`, it means the type of current project will be determined through certain rules.
292
+ *
293
+ * @param type
294
+ * 1. ts/typescript: The same meaning means generating ts type files
295
+ * 2. module: generate esModule specification file
296
+ * 3. commonjs: means generating commonjs specification file
297
+ *
298
+ * @default 'auto'
299
+ */
300
+ type?: ConfigType;
301
+ /**
302
+ * When there is no require, it defaults to require, and only nullable takes effect.
303
+ */
304
+ defaultRequire?: boolean;
305
+ /**
306
+ * plugin will be executed before `handleApi`
307
+ */
308
+ plugins?: ApiPlugin[];
309
+ /**
310
+ * Performance tuning options for code generation.
311
+ */
312
+ performance?: PerformanceConfig;
313
+ /**
314
+ * Filter or convert the generated api function and return a new `apiDescriptor` to generate the api.
315
+ * When this function is not specified, `apiDescriptor` object is not converted.
316
+ * The type of `apiDescriptor` is the same as the api item of openapi file.
317
+ *
318
+ * @see https://spec.openapis.org/oas/v3.1.0.html#operation-object
319
+ *
320
+ * @example
321
+ * ```js
322
+ * // Do not generate the apis that starts with `/user`
323
+ * handleApi(apiDescriptor) {
324
+ * if (apiDescriptor.path.startsWith('/user')) {
325
+ * return;
326
+ * }
327
+ * return apiDescriptor;
328
+ * }
329
+ * ```
330
+ *
331
+ * ```js
332
+ * // modify the api's parameters
333
+ * handleApi(apiDescriptor) {
334
+ * apiDescriptor.parameters = (apiDescriptor.parameters || []).filter(
335
+ * param => param.in === 'header' && param.name === 'token'
336
+ * );
337
+ * delete apiDescriptor.requestBody.id;
338
+ * apiDescriptor.url = apiDescriptor.url.replace('/user', '');
339
+ * return apiDescriptor;
340
+ * }
341
+ * ```
342
+ */
343
+ handleApi?: HandleApi;
344
+ }
345
+ export type OpenAPIDocument = OpenAPIV3_1.Document;
346
+ export type SchemaObject = OpenAPIV3_1.SchemaObject;
347
+ export type Parameter = OpenAPIV3_1.ParameterObject;
348
+ export type OperationObject = OpenAPIV3_1.OperationObject;
349
+ export interface Api {
350
+ tag: string;
351
+ method: string;
352
+ summary: string;
353
+ path: string;
354
+ pathParameters: string;
355
+ queryParameters: string;
356
+ pathParametersComment?: string;
357
+ queryParametersComment?: string;
358
+ responseComment?: string;
359
+ requestBodyComment?: string;
360
+ name: string;
361
+ response: string;
362
+ requestBody?: string;
363
+ callingCode?: string;
364
+ }
365
+ export interface ApiDoc {
366
+ apis: Api[];
367
+ tagName: string;
368
+ }
369
+ export type ApiDescriptor = Omit<OperationObject, "requestBody" | "parameters" | "responses"> & {
370
+ url: string;
371
+ method: string;
372
+ parameters?: Parameter[];
373
+ refNameMap?: Record<string, string>;
374
+ requestBody?: SchemaObject;
375
+ responses?: SchemaObject;
376
+ };
377
+ export interface TemplateData {
378
+ title: OpenAPIDocument["info"]["title"];
379
+ openapi: OpenAPIDocument["openapi"];
380
+ version: OpenAPIDocument["info"]["version"];
381
+ description: OpenAPIDocument["info"]["description"];
382
+ contact: OpenAPIDocument["info"]["contact"];
383
+ /** Framework tag: vue | react | svelte | solid-js | nuxt */
384
+ framework?: string;
385
+ defaultKey?: boolean;
386
+ baseUrl: string;
387
+ /** Schema/Component definitions */
388
+ components: string[];
389
+ /** Names of all generated component schemas (keys of schemasMap) */
390
+ componentNames: string[];
391
+ /** All apis array */
392
+ allApis: Api[];
393
+ /** Apis grouped by tag */
394
+ tagedApis: ApiDoc[];
395
+ type: TemplateType;
396
+ /** Config passed from template configuration */
397
+ config: Record<string, any>;
398
+ }
399
+ /**
400
+ * Creates a plugin factory function with proper typing
401
+ *
402
+ * @param plugin - Function that creates a plugin instance
403
+ * @returns The original plugin function with proper typing
404
+ *
405
+ * @example
406
+ * // Create a custom plugin
407
+ * const myPlugin = createPlugin((options: MyOptions) => ({
408
+ * handleApi: (apiDescriptor) => {
409
+ * // Plugin implementation
410
+ * return apiDescriptor;
411
+ * }
412
+ * }));
413
+ *
414
+ * // Use the plugin
415
+ * generate({
416
+ * generator: [{
417
+ * // ...
418
+ * plugins: [myPlugin({ key: 'value' })]
419
+ * }]
420
+ * });
421
+ */
422
+ export declare function createPlugin<T extends any[]>(plugin: (...args: T) => ApiPlugin): (...args: T) => ApiPlugin;
423
+ export interface AiDocConfig {
424
+ template?: string;
425
+ outputDir?: string;
426
+ installSkill?: boolean;
427
+ }
428
+ export declare function aiDoc(config?: AiDocConfig): ApiPlugin;
429
+ export type ScopeType = "ALL" | "SELECTED_ENDPOINTS" | "SELECTED_TAGS" | "SELECTED_FOLDERS";
430
+ export interface APIFoxBody {
431
+ scope?: {
432
+ type?: ScopeType;
433
+ selectedEndpointIds?: number[];
434
+ selectedTags?: string[];
435
+ selectedFolderIds?: number[];
436
+ excludedByTags?: string[];
437
+ };
438
+ options?: {
439
+ includeApifoxExtensionProperties?: boolean;
440
+ addFoldersToTags?: boolean;
441
+ };
442
+ oasVersion?: "2.0" | "3.0" | "3.1";
443
+ exportFormat?: "JSON" | "YAML";
444
+ environmentIds?: number[];
445
+ branchId?: number;
446
+ moduleId?: number;
447
+ }
448
+ export interface ApifoxOptions extends Pick<APIFoxBody, "oasVersion" | "exportFormat" | "environmentIds" | "branchId" | "moduleId">, Pick<NonNullable<APIFoxBody["options"]>, "includeApifoxExtensionProperties" | "addFoldersToTags"> {
449
+ projectId: string;
450
+ apifoxToken: string;
451
+ locale?: string;
452
+ apifoxVersion?: string;
453
+ scopeType?: ScopeType;
454
+ selectedEndpointIds?: number[];
455
+ selectedTags?: string[];
456
+ selectedFolderIds?: number[];
457
+ excludedByTags?: string[];
458
+ }
459
+ export declare function apifox({ projectId, locale, apifoxVersion, scopeType, selectedEndpointIds, selectedTags, selectedFolderIds, excludedByTags, apifoxToken, oasVersion, exportFormat, includeApifoxExtensionProperties, addFoldersToTags, environmentIds, branchId, moduleId, }: ApifoxOptions): ApiPlugin;
460
+ /**
461
+ * Filter configuration interface
462
+ */
463
+ export interface FilterApiConfig {
464
+ /**
465
+ * Target scope for filtering, defaults to 'url'
466
+ */
467
+ scope?: "url" | "tag";
468
+ /**
469
+ * Include rule:
470
+ * - string: target contains this string
471
+ * - RegExp: target matches this pattern
472
+ * - function: custom matching logic
473
+ */
474
+ include?: string | RegExp | ((key: string) => boolean);
475
+ /**
476
+ * Exclude rule:
477
+ * - string: target contains this string
478
+ * - RegExp: target matches this pattern
479
+ * - function: custom matching logic
480
+ */
481
+ exclude?: string | RegExp | ((key: string) => boolean);
482
+ }
483
+ /**
484
+ * Main processing function for filtering API descriptors
485
+ * @param apiDescriptor API descriptor
486
+ * @param configs Configuration array
487
+ * @returns Filtered API descriptor, or null if filtered out
488
+ */
489
+ export declare function filterApiDescriptor(apiDescriptor: ApiDescriptor, configs: FilterApiConfig[]): ApiDescriptor | null;
490
+ /**
491
+ * Creates a plugin for filtering APIs
492
+ *
493
+ * @param config Filter configuration, can be a single config or array of configs
494
+ * @returns API plugin instance
495
+ *
496
+ * @example
497
+ * ```ts
498
+ * // Only include URLs containing 'user'
499
+ * const userOnlyFilter = apiFilter({
500
+ * include: 'user'
501
+ * });
502
+ *
503
+ * // Exclude tags containing 'internal'
504
+ * const noInternalFilter = apiFilter({
505
+ * scope: 'tag',
506
+ * exclude: 'internal'
507
+ * });
508
+ *
509
+ * // Multi-condition filtering (union)
510
+ * const multiFilter = apiFilter([
511
+ * { include: 'user' },
512
+ * { include: 'admin' }
513
+ * ]);
514
+ * ```
515
+ */
516
+ export declare function apiFilter(config: FilterApiConfig | FilterApiConfig[]): ApiPlugin;
517
+ export interface ImportTypeOptions {
518
+ imports: Record<string, string[]>;
519
+ files?: string[];
520
+ }
521
+ export declare function importType(imports: Record<string, string[]>, options?: {
522
+ files?: string[];
523
+ }): ApiPlugin;
524
+ declare enum ModifierScope {
525
+ PARAMS = "params",
526
+ PATH_PARAMS = "pathParams",
527
+ DATA = "data",
528
+ RESPONSE = "response"
529
+ }
530
+ export type SchemaPrimitive = "number" | "string" | "boolean" | "undefined" | "null" | "unknown" | "any" | "never" | ({} & string);
531
+ /**
532
+ * 表示数组类型
533
+ */
534
+ export interface SchemaArray {
535
+ type: "array";
536
+ items: Schema | Schema[];
537
+ }
538
+ /**
539
+ * 修改参数为引用类型
540
+ * 在key末端添加上?表示为可选值
541
+ */
542
+ export interface SchemaReference {
543
+ [attr: string]: Schema;
544
+ }
545
+ /**
546
+ * 枚举类型表示
547
+ */
548
+ export interface SchemaEnum {
549
+ enum: Array<string | number | boolean | null>;
550
+ type?: SchemaPrimitive;
551
+ }
552
+ /**
553
+ * 组合类型表示(与/或/交叉)
554
+ */
555
+ export interface SchemaOneOf {
556
+ oneOf: Schema[];
557
+ }
558
+ export interface SchemaAnyOf {
559
+ anyOf: Schema[];
560
+ }
561
+ export interface SchemaAllOf {
562
+ allOf: Schema[];
563
+ }
564
+ /**
565
+ * 数据Schema
566
+ * SchemaArray表示类型数组,而数组表示“或”的意思
567
+ */
568
+ export type Schema = SchemaPrimitive | SchemaReference | SchemaArray | SchemaEnum | SchemaOneOf | SchemaAnyOf | SchemaAllOf | Array<SchemaPrimitive | SchemaReference | SchemaArray | SchemaEnum>;
569
+ export interface ModifierConfig<T extends Schema> {
570
+ /**
571
+ * 生效范围,表示处理哪个位置的参数
572
+ */
573
+ scope: ModifierScope;
574
+ /**
575
+ * 匹配规则,只有匹配到的才会进行转换,不指定则转换全部
576
+ * string:原参数名包含此string;RegExp:原参数名匹配此正则;函数时接收key并返回是否匹配的boolean值
577
+ */
578
+ match?: string | RegExp | ((key: string) => boolean);
579
+ /**
580
+ * handler用于灵活修改参数类型值
581
+ * @param schema Schema中的一种,由用户自行定义
582
+ * @returns 返回多种参数,具体为:Schema表示修改的类型;{ required: boolean, value: Schema }表示可将当前值修改为是否必填;void | null | undefined表示移除当前字段
583
+ */
584
+ handler: (schema: T) => Schema | {
585
+ required: boolean;
586
+ value: Schema;
587
+ } | void | null | undefined;
588
+ }
589
+ export type PayloadModifierConfig = ModifierConfig<Schema>;
590
+ export declare function payloadModifier(configs: PayloadModifierConfig[]): ApiPlugin;
591
+ /**
592
+ * Supported platform types
593
+ */
594
+ export type PlatformType = "swagger" | "knife4j" | "fastapi" | "yapi";
595
+ /**
596
+ * Platform plugin for auto-resolving OpenAPI file URLs.
597
+ *
598
+ * Pass a platform type (e.g., `'swagger'`) and the plugin will use `config.input`
599
+ * as the base URL to generate candidate OpenAPI file URLs. The framework will try
600
+ * each URL in order and use the first successful response.
601
+ *
602
+ * @param platformType - The platform type: 'swagger' | 'knife4j' | 'fastapi' | 'yapi'
603
+ * @returns ApiPlugin
604
+ *
605
+ * @example
606
+ * ```ts
607
+ * import { platform, alovaGlobals } from 'worma/plugin';
608
+ *
609
+ * defineConfig({
610
+ * generator: [{
611
+ * input: 'https://petstore3.swagger.io',
612
+ * plugins: [platform('swagger'), alovaGlobals()],
613
+ * output: './src/api',
614
+ * }]
615
+ * });
616
+ * ```
617
+ */
618
+ export declare function platform(platformType: PlatformType): ApiPlugin;
619
+ /**
620
+ * Rename style options
621
+ */
622
+ export type RenameStyle = "camelCase" | "kebabCase" | "snakeCase" | "pascalCase";
623
+ /**
624
+ * Rename plugin configuration
625
+ */
626
+ export interface RenameConfig {
627
+ /**
628
+ * Target scope for renaming, defaults to 'url'
629
+ */
630
+ scope?: "url" | "params" | "pathParams" | "data" | "response" | "refName";
631
+ /**
632
+ * Matching rule for selective renaming:
633
+ * - string: target contains this string
634
+ * - RegExp: target matches this pattern
635
+ * - function: custom matching logic
636
+ * If not specified, all targets will be processed
637
+ */
638
+ match?: string | RegExp | ((key: string) => boolean);
639
+ /**
640
+ * Naming style to apply
641
+ */
642
+ style?: RenameStyle;
643
+ /**
644
+ * Custom transformation function
645
+ * Will be applied before style transformation
646
+ */
647
+ transform?: (apiDescriptor: ApiDescriptor, value: string) => string;
648
+ }
649
+ /**
650
+ * Creates a rename plugin that transforms API descriptors
651
+ * according to specified naming rules
652
+ */
653
+ export declare function rename(config: RenameConfig | RenameConfig[]): ApiPlugin;
654
+ /**
655
+ * Tag modifier handler function type
656
+ * Receives a tag string and returns the modified tag string, or null/undefined/void to remove the tag
657
+ */
658
+ export type ModifierHandler = (tag: string) => string | null | undefined | void;
659
+ /**
660
+ * Processes tags in the API descriptor
661
+ * @param apiDescriptor The API descriptor
662
+ * @param handler Tag modifier handler function
663
+ * @returns Modified API descriptor
664
+ */
665
+ export declare function processApiTags(apiDescriptor: ApiDescriptor, handler: ModifierHandler): ApiDescriptor;
666
+ /**
667
+ * Creates a tag modifier plugin
668
+ *
669
+ * @param handler Tag modifier handler function that receives a tag string and returns modified tag or null/undefined/void to remove the tag
670
+ * @returns API plugin instance
671
+ *
672
+ * @example
673
+ * ```ts
674
+ * // Convert all tags to uppercase
675
+ * const upperCasePlugin = tagModifier(tag => tag.toUpperCase());
676
+ *
677
+ * // Add prefix to tags
678
+ * const prefixPlugin = tagModifier(tag => `api-${tag}`);
679
+ *
680
+ * // Remove specific tags
681
+ * const filterPlugin = tagModifier(tag => tag === 'internal' ? null : tag);
682
+ *
683
+ * // Use the plugin
684
+ * export default {
685
+ * generator: [{
686
+ * // ...other config
687
+ * plugins: [upperCasePlugin]
688
+ * }]
689
+ * };
690
+ * ```
691
+ */
692
+ export declare function tagModifier(handler: ModifierHandler): ApiPlugin;
693
+ /**
694
+ * worma.config 模板预设 - plugin mode
695
+ */
696
+ export declare function config(): ApiPlugin;
697
+ /**
698
+ * globals 模板预设 - plugin mode
699
+ * 全局模板,现有的全局模板,通过全局挂载的方式使用
700
+ */
701
+ export declare function alovaGlobals(opts?: GlobalsTemplateOptions): ApiPlugin;
702
+ /**
703
+ * functional 模板预设 - plugin mode
704
+ * 函数式模板,生成函数式API调用,支持tree-shaking,仅支持alova v3
705
+ */
706
+ export declare function alova(opts?: FunctionalTemplateOptions): ApiPlugin;
707
+ /**
708
+ * axios 模板预设 - plugin mode
709
+ * Axios相关模板
710
+ */
711
+ export declare function axios(opts?: RequestLibTemplateOptions): ApiPlugin;
712
+ /**
713
+ * fetch 模板预设 - plugin mode
714
+ * Fetch相关模板
715
+ */
716
+ declare function fetch$1(opts?: RequestLibTemplateOptions): ApiPlugin;
717
+ /**
718
+ * ky 模板预设 - plugin mode
719
+ * Ky相关模板
720
+ */
721
+ export declare function ky(opts?: RequestLibTemplateOptions): ApiPlugin;
722
+
723
+ export {
724
+ fetch$1 as fetch,
725
+ };
726
+
727
+ export {};