@kubb/plugin-ts 5.0.0-alpha.11 → 5.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{components-CRu8IKY3.js → Type-CX1HRooG.js} +377 -365
- package/dist/Type-CX1HRooG.js.map +1 -0
- package/dist/Type-Cat0_htq.cjs +808 -0
- package/dist/Type-Cat0_htq.cjs.map +1 -0
- package/dist/components.cjs +3 -2
- package/dist/components.d.ts +40 -9
- package/dist/components.js +2 -2
- package/dist/generators-CLuCmfUz.js +532 -0
- package/dist/generators-CLuCmfUz.js.map +1 -0
- package/dist/generators-DWBU-MuW.cjs +536 -0
- package/dist/generators-DWBU-MuW.cjs.map +1 -0
- package/dist/generators.cjs +2 -3
- package/dist/generators.d.ts +3 -503
- package/dist/generators.js +2 -2
- package/dist/index.cjs +308 -4
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +26 -21
- package/dist/index.js +305 -2
- package/dist/index.js.map +1 -0
- package/dist/{types-mSXmB8WU.d.ts → types-BA1ZCQ5p.d.ts} +73 -57
- package/package.json +5 -5
- package/src/components/{v2/Enum.tsx → Enum.tsx} +27 -11
- package/src/components/Type.tsx +23 -141
- package/src/components/index.ts +1 -0
- package/src/generators/index.ts +0 -1
- package/src/generators/typeGenerator.tsx +189 -413
- package/src/generators/utils.ts +298 -0
- package/src/index.ts +1 -1
- package/src/plugin.ts +80 -126
- package/src/printer.ts +15 -4
- package/src/resolverTs.ts +109 -1
- package/src/types.ts +68 -52
- package/dist/components-CRu8IKY3.js.map +0 -1
- package/dist/components-DeNDKlzf.cjs +0 -982
- package/dist/components-DeNDKlzf.cjs.map +0 -1
- package/dist/plugin-CJ29AwE2.cjs +0 -1320
- package/dist/plugin-CJ29AwE2.cjs.map +0 -1
- package/dist/plugin-D60XNJSD.js +0 -1267
- package/dist/plugin-D60XNJSD.js.map +0 -1
- package/src/components/v2/Type.tsx +0 -59
- package/src/generators/v2/typeGenerator.tsx +0 -167
- package/src/generators/v2/utils.ts +0 -140
- package/src/parser.ts +0 -389
package/dist/index.js
CHANGED
|
@@ -1,2 +1,305 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import "./chunk--u3MIqq1.js";
|
|
2
|
+
import { a as pascalCase, i as camelCase } from "./Type-CX1HRooG.js";
|
|
3
|
+
import { t as typeGenerator } from "./generators-CLuCmfUz.js";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { walk } from "@kubb/ast";
|
|
6
|
+
import { createPlugin, defineResolver, getBarrelFiles, getMode, renderOperation, renderSchema } from "@kubb/core";
|
|
7
|
+
//#region src/resolverTs.ts
|
|
8
|
+
function resolveName(name, type) {
|
|
9
|
+
return pascalCase(name, { isFile: type === "file" });
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
13
|
+
* helpers used by the plugin. Import this in other plugins to resolve the exact names and
|
|
14
|
+
* paths that `plugin-ts` generates without hardcoding the conventions.
|
|
15
|
+
*
|
|
16
|
+
* The `default` method is automatically injected by `defineResolver` — it uses `camelCase`
|
|
17
|
+
* for identifiers/files and `pascalCase` for type names.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { resolver } from '@kubb/plugin-ts'
|
|
22
|
+
*
|
|
23
|
+
* resolver.default('list pets', 'type') // → 'ListPets'
|
|
24
|
+
* resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
|
|
25
|
+
* resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'
|
|
26
|
+
* resolver.resolvePathName('list pets', 'file') // → 'listPets'
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const resolverTs = defineResolver(() => {
|
|
30
|
+
return {
|
|
31
|
+
default(name, type) {
|
|
32
|
+
return resolveName(name, type);
|
|
33
|
+
},
|
|
34
|
+
resolveName(name) {
|
|
35
|
+
return this.default(name, "function");
|
|
36
|
+
},
|
|
37
|
+
resolveTypedName(name) {
|
|
38
|
+
return this.default(name, "type");
|
|
39
|
+
},
|
|
40
|
+
resolvePathName(name, type) {
|
|
41
|
+
return this.default(name, type);
|
|
42
|
+
},
|
|
43
|
+
resolveParamName(node, param) {
|
|
44
|
+
return this.resolveName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
|
|
45
|
+
},
|
|
46
|
+
resolveParamTypedName(node, param) {
|
|
47
|
+
return this.resolveTypedName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
|
|
48
|
+
},
|
|
49
|
+
resolveResponseStatusName(node, statusCode) {
|
|
50
|
+
return this.resolveName(`${node.operationId} Status ${statusCode}`);
|
|
51
|
+
},
|
|
52
|
+
resolveResponseStatusTypedName(node, statusCode) {
|
|
53
|
+
return this.resolveTypedName(`${node.operationId} Status ${statusCode}`);
|
|
54
|
+
},
|
|
55
|
+
resolveDataName(node) {
|
|
56
|
+
return this.resolveName(`${node.operationId} Data`);
|
|
57
|
+
},
|
|
58
|
+
resolveDataTypedName(node) {
|
|
59
|
+
return this.resolveTypedName(`${node.operationId} Data`);
|
|
60
|
+
},
|
|
61
|
+
resolveRequestConfigName(node) {
|
|
62
|
+
return this.resolveName(`${node.operationId} RequestConfig`);
|
|
63
|
+
},
|
|
64
|
+
resolveRequestConfigTypedName(node) {
|
|
65
|
+
return this.resolveTypedName(`${node.operationId} RequestConfig`);
|
|
66
|
+
},
|
|
67
|
+
resolveResponsesName(node) {
|
|
68
|
+
return this.resolveName(`${node.operationId} Responses`);
|
|
69
|
+
},
|
|
70
|
+
resolveResponsesTypedName(node) {
|
|
71
|
+
return this.resolveTypedName(`${node.operationId} Responses`);
|
|
72
|
+
},
|
|
73
|
+
resolveResponseName(node) {
|
|
74
|
+
return this.resolveName(`${node.operationId} Response`);
|
|
75
|
+
},
|
|
76
|
+
resolveResponseTypedName(node) {
|
|
77
|
+
return this.resolveTypedName(`${node.operationId} Response`);
|
|
78
|
+
},
|
|
79
|
+
resolveEnumKeyTypedName(node) {
|
|
80
|
+
return `${this.resolveTypedName(node.name ?? "")}Key`;
|
|
81
|
+
},
|
|
82
|
+
resolvePathParamsName(_node) {
|
|
83
|
+
throw new Error("resolvePathParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
|
|
84
|
+
},
|
|
85
|
+
resolvePathParamsTypedName(_node) {
|
|
86
|
+
throw new Error("resolvePathParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
|
|
87
|
+
},
|
|
88
|
+
resolveQueryParamsName(_node) {
|
|
89
|
+
throw new Error("resolveQueryParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
|
|
90
|
+
},
|
|
91
|
+
resolveQueryParamsTypedName(_node) {
|
|
92
|
+
throw new Error("resolveQueryParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
|
|
93
|
+
},
|
|
94
|
+
resolveHeaderParamsName(_node) {
|
|
95
|
+
throw new Error("resolveHeaderParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
|
|
96
|
+
},
|
|
97
|
+
resolveHeaderParamsTypedName(_node) {
|
|
98
|
+
throw new Error("resolveHeaderParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
/**
|
|
103
|
+
* Legacy resolver for `@kubb/plugin-ts` that reproduces the naming conventions
|
|
104
|
+
* used before the v2 resolver refactor. Enable via `legacy: true` in plugin options.
|
|
105
|
+
*
|
|
106
|
+
* Key differences from the default resolver:
|
|
107
|
+
* - Response status types: `<OperationId><StatusCode>` (e.g. `CreatePets201`) instead of `<OperationId>Status201`
|
|
108
|
+
* - Default/error responses: `<OperationId>Error` instead of `<OperationId>StatusDefault`
|
|
109
|
+
* - Request body: `<OperationId>MutationRequest` (non-GET) / `<OperationId>QueryRequest` (GET)
|
|
110
|
+
* - Combined responses type: `<OperationId>Mutation` / `<OperationId>Query`
|
|
111
|
+
* - Response union: `<OperationId>MutationResponse` / `<OperationId>QueryResponse`
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
116
|
+
*
|
|
117
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 201) // → 'CreatePets201'
|
|
118
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 'default') // → 'CreatePetsError'
|
|
119
|
+
* resolverTsLegacy.resolveDataTypedName(node) // → 'CreatePetsMutationRequest' (POST)
|
|
120
|
+
* resolverTsLegacy.resolveResponsesTypedName(node) // → 'CreatePetsMutation' (POST)
|
|
121
|
+
* resolverTsLegacy.resolveResponseTypedName(node) // → 'CreatePetsMutationResponse' (POST)
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
const resolverTsLegacy = defineResolver(() => {
|
|
125
|
+
return {
|
|
126
|
+
...resolverTs,
|
|
127
|
+
resolveResponseStatusName(node, statusCode) {
|
|
128
|
+
if (statusCode === "default") return this.resolveName(`${node.operationId} Error`);
|
|
129
|
+
return this.resolveName(`${node.operationId} ${statusCode}`);
|
|
130
|
+
},
|
|
131
|
+
resolveResponseStatusTypedName(node, statusCode) {
|
|
132
|
+
if (statusCode === "default") return this.resolveTypedName(`${node.operationId} Error`);
|
|
133
|
+
return this.resolveTypedName(`${node.operationId} ${statusCode}`);
|
|
134
|
+
},
|
|
135
|
+
resolveDataName(node) {
|
|
136
|
+
const suffix = node.method === "GET" ? "QueryRequest" : "MutationRequest";
|
|
137
|
+
return this.resolveName(`${node.operationId} ${suffix}`);
|
|
138
|
+
},
|
|
139
|
+
resolveDataTypedName(node) {
|
|
140
|
+
const suffix = node.method === "GET" ? "QueryRequest" : "MutationRequest";
|
|
141
|
+
return this.resolveTypedName(`${node.operationId} ${suffix}`);
|
|
142
|
+
},
|
|
143
|
+
resolveResponsesName(node) {
|
|
144
|
+
const suffix = node.method === "GET" ? "Query" : "Mutation";
|
|
145
|
+
return this.resolveName(`${node.operationId} ${suffix}`);
|
|
146
|
+
},
|
|
147
|
+
resolveResponsesTypedName(node) {
|
|
148
|
+
const suffix = node.method === "GET" ? "Query" : "Mutation";
|
|
149
|
+
return this.resolveTypedName(`${node.operationId} ${suffix}`);
|
|
150
|
+
},
|
|
151
|
+
resolveResponseName(node) {
|
|
152
|
+
const suffix = node.method === "GET" ? "QueryResponse" : "MutationResponse";
|
|
153
|
+
return this.resolveName(`${node.operationId} ${suffix}`);
|
|
154
|
+
},
|
|
155
|
+
resolveResponseTypedName(node) {
|
|
156
|
+
const suffix = node.method === "GET" ? "QueryResponse" : "MutationResponse";
|
|
157
|
+
return this.resolveTypedName(`${node.operationId} ${suffix}`);
|
|
158
|
+
},
|
|
159
|
+
resolvePathParamsName(node) {
|
|
160
|
+
return this.resolveName(`${node.operationId} PathParams`);
|
|
161
|
+
},
|
|
162
|
+
resolvePathParamsTypedName(node) {
|
|
163
|
+
return this.resolveTypedName(`${node.operationId} PathParams`);
|
|
164
|
+
},
|
|
165
|
+
resolveQueryParamsName(node) {
|
|
166
|
+
return this.resolveName(`${node.operationId} QueryParams`);
|
|
167
|
+
},
|
|
168
|
+
resolveQueryParamsTypedName(node) {
|
|
169
|
+
return this.resolveTypedName(`${node.operationId} QueryParams`);
|
|
170
|
+
},
|
|
171
|
+
resolveHeaderParamsName(node) {
|
|
172
|
+
return this.resolveName(`${node.operationId} HeaderParams`);
|
|
173
|
+
},
|
|
174
|
+
resolveHeaderParamsTypedName(node) {
|
|
175
|
+
return this.resolveTypedName(`${node.operationId} HeaderParams`);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/plugin.ts
|
|
181
|
+
const pluginTsName = "plugin-ts";
|
|
182
|
+
const pluginTs = createPlugin((options) => {
|
|
183
|
+
const { output = {
|
|
184
|
+
path: "types",
|
|
185
|
+
barrelType: "named"
|
|
186
|
+
}, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", transformers = {}, paramsCasing, generators = [typeGenerator].filter(Boolean), legacy = false } = options;
|
|
187
|
+
const baseResolver = legacy ? resolverTsLegacy : resolverTs;
|
|
188
|
+
const resolver = transformers?.name ? {
|
|
189
|
+
...baseResolver,
|
|
190
|
+
default(name, type) {
|
|
191
|
+
const resolved = baseResolver.default(name, type);
|
|
192
|
+
return transformers.name(resolved, type) || resolved;
|
|
193
|
+
}
|
|
194
|
+
} : baseResolver;
|
|
195
|
+
let resolveNameWarning = false;
|
|
196
|
+
return {
|
|
197
|
+
name: pluginTsName,
|
|
198
|
+
options: {
|
|
199
|
+
output,
|
|
200
|
+
transformers,
|
|
201
|
+
optionalType,
|
|
202
|
+
arrayType,
|
|
203
|
+
enumType,
|
|
204
|
+
enumKeyCasing,
|
|
205
|
+
syntaxType,
|
|
206
|
+
group,
|
|
207
|
+
override,
|
|
208
|
+
paramsCasing,
|
|
209
|
+
legacy,
|
|
210
|
+
resolver
|
|
211
|
+
},
|
|
212
|
+
resolvePath(baseName, pathMode, options) {
|
|
213
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
214
|
+
if ((pathMode ?? getMode(path.resolve(root, output.path))) === "single")
|
|
215
|
+
/**
|
|
216
|
+
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
217
|
+
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
218
|
+
*/
|
|
219
|
+
return path.resolve(root, output.path);
|
|
220
|
+
if (group && (options?.group?.path || options?.group?.tag)) {
|
|
221
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
222
|
+
if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
|
|
223
|
+
return `${camelCase(ctx.group)}Controller`;
|
|
224
|
+
};
|
|
225
|
+
return path.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
|
|
226
|
+
}
|
|
227
|
+
return path.resolve(root, output.path, baseName);
|
|
228
|
+
},
|
|
229
|
+
resolveName(name, type) {
|
|
230
|
+
if (!resolveNameWarning) {
|
|
231
|
+
this.driver.events.emit("warn", "Do not use resolveName for pluginTs, use resolverTs instead");
|
|
232
|
+
resolveNameWarning = true;
|
|
233
|
+
}
|
|
234
|
+
return resolver.default(name, type);
|
|
235
|
+
},
|
|
236
|
+
async install() {
|
|
237
|
+
const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this;
|
|
238
|
+
const root = path.resolve(config.root, config.output.path);
|
|
239
|
+
const mode = getMode(path.resolve(root, output.path));
|
|
240
|
+
if (!adapter) throw new Error("Plugin cannot work without adapter being set");
|
|
241
|
+
await openInStudio({ ast: true });
|
|
242
|
+
await walk(rootNode, {
|
|
243
|
+
async schema(schemaNode) {
|
|
244
|
+
const writeTasks = generators.map(async (generator) => {
|
|
245
|
+
if (generator.type === "react" && generator.version === "2") {
|
|
246
|
+
const options = resolver.resolveOptions(schemaNode, {
|
|
247
|
+
options: plugin.options,
|
|
248
|
+
exclude,
|
|
249
|
+
include,
|
|
250
|
+
override
|
|
251
|
+
});
|
|
252
|
+
if (options === null) return;
|
|
253
|
+
await renderSchema(schemaNode, {
|
|
254
|
+
options,
|
|
255
|
+
adapter,
|
|
256
|
+
config,
|
|
257
|
+
fabric,
|
|
258
|
+
Component: generator.Schema,
|
|
259
|
+
plugin,
|
|
260
|
+
driver,
|
|
261
|
+
mode
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
await Promise.all(writeTasks);
|
|
266
|
+
},
|
|
267
|
+
async operation(operationNode) {
|
|
268
|
+
const writeTasks = generators.map(async (generator) => {
|
|
269
|
+
if (generator.type === "react" && generator.version === "2") {
|
|
270
|
+
const options = resolver.resolveOptions(operationNode, {
|
|
271
|
+
options: plugin.options,
|
|
272
|
+
exclude,
|
|
273
|
+
include,
|
|
274
|
+
override
|
|
275
|
+
});
|
|
276
|
+
if (options === null) return;
|
|
277
|
+
await renderOperation(operationNode, {
|
|
278
|
+
options,
|
|
279
|
+
adapter,
|
|
280
|
+
config,
|
|
281
|
+
fabric,
|
|
282
|
+
Component: generator.Operation,
|
|
283
|
+
plugin,
|
|
284
|
+
driver,
|
|
285
|
+
mode
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
await Promise.all(writeTasks);
|
|
290
|
+
}
|
|
291
|
+
}, { depth: "shallow" });
|
|
292
|
+
const barrelFiles = await getBarrelFiles(this.fabric.files, {
|
|
293
|
+
type: output.barrelType ?? "named",
|
|
294
|
+
root,
|
|
295
|
+
output,
|
|
296
|
+
meta: { pluginName: this.plugin.name }
|
|
297
|
+
});
|
|
298
|
+
await this.upsertFile(...barrelFiles);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
});
|
|
302
|
+
//#endregion
|
|
303
|
+
export { pluginTs, pluginTsName, resolverTs, resolverTsLegacy };
|
|
304
|
+
|
|
305
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/resolverTs.ts","../src/plugin.ts"],"sourcesContent":["import { pascalCase } from '@internals/utils'\nimport { defineResolver } from '@kubb/core'\nimport type { PluginTs } from './types.ts'\n\nfunction resolveName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string {\n return pascalCase(name, { isFile: type === 'file' })\n}\n\n/**\n * Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution\n * helpers used by the plugin. Import this in other plugins to resolve the exact names and\n * paths that `plugin-ts` generates without hardcoding the conventions.\n *\n * The `default` method is automatically injected by `defineResolver` — it uses `camelCase`\n * for identifiers/files and `pascalCase` for type names.\n *\n * @example\n * ```ts\n * import { resolver } from '@kubb/plugin-ts'\n *\n * resolver.default('list pets', 'type') // → 'ListPets'\n * resolver.resolveName('list pets status 200') // → 'listPetsStatus200'\n * resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'\n * resolver.resolvePathName('list pets', 'file') // → 'listPets'\n * ```\n */\nexport const resolverTs = defineResolver<PluginTs>(() => {\n return {\n default(name, type) {\n return resolveName(name, type)\n },\n resolveName(name) {\n return this.default(name, 'function')\n },\n resolveTypedName(name) {\n return this.default(name, 'type')\n },\n resolvePathName(name, type) {\n return this.default(name, type)\n },\n resolveParamName(node, param) {\n return this.resolveName(`${node.operationId} ${this.default(param.in)} ${param.name}`)\n },\n resolveParamTypedName(node, param) {\n return this.resolveTypedName(`${node.operationId} ${this.default(param.in)} ${param.name}`)\n },\n resolveResponseStatusName(node, statusCode) {\n return this.resolveName(`${node.operationId} Status ${statusCode}`)\n },\n resolveResponseStatusTypedName(node, statusCode) {\n return this.resolveTypedName(`${node.operationId} Status ${statusCode}`)\n },\n resolveDataName(node) {\n return this.resolveName(`${node.operationId} Data`)\n },\n resolveDataTypedName(node) {\n return this.resolveTypedName(`${node.operationId} Data`)\n },\n resolveRequestConfigName(node) {\n return this.resolveName(`${node.operationId} RequestConfig`)\n },\n resolveRequestConfigTypedName(node) {\n return this.resolveTypedName(`${node.operationId} RequestConfig`)\n },\n resolveResponsesName(node) {\n return this.resolveName(`${node.operationId} Responses`)\n },\n resolveResponsesTypedName(node) {\n return this.resolveTypedName(`${node.operationId} Responses`)\n },\n resolveResponseName(node) {\n return this.resolveName(`${node.operationId} Response`)\n },\n resolveResponseTypedName(node) {\n return this.resolveTypedName(`${node.operationId} Response`)\n },\n resolveEnumKeyTypedName(node) {\n return `${this.resolveTypedName(node.name ?? '')}Key`\n },\n resolvePathParamsName(_node) {\n throw new Error('resolvePathParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.')\n },\n resolvePathParamsTypedName(_node) {\n throw new Error('resolvePathParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.')\n },\n resolveQueryParamsName(_node) {\n throw new Error('resolveQueryParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.')\n },\n resolveQueryParamsTypedName(_node) {\n throw new Error(\n 'resolveQueryParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.',\n )\n },\n resolveHeaderParamsName(_node) {\n throw new Error('resolveHeaderParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.')\n },\n resolveHeaderParamsTypedName(_node) {\n throw new Error(\n 'resolveHeaderParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.',\n )\n },\n }\n})\n\n/**\n * Legacy resolver for `@kubb/plugin-ts` that reproduces the naming conventions\n * used before the v2 resolver refactor. Enable via `legacy: true` in plugin options.\n *\n * Key differences from the default resolver:\n * - Response status types: `<OperationId><StatusCode>` (e.g. `CreatePets201`) instead of `<OperationId>Status201`\n * - Default/error responses: `<OperationId>Error` instead of `<OperationId>StatusDefault`\n * - Request body: `<OperationId>MutationRequest` (non-GET) / `<OperationId>QueryRequest` (GET)\n * - Combined responses type: `<OperationId>Mutation` / `<OperationId>Query`\n * - Response union: `<OperationId>MutationResponse` / `<OperationId>QueryResponse`\n *\n * @example\n * ```ts\n * import { resolverTsLegacy } from '@kubb/plugin-ts'\n *\n * resolverTsLegacy.resolveResponseStatusTypedName(node, 201) // → 'CreatePets201'\n * resolverTsLegacy.resolveResponseStatusTypedName(node, 'default') // → 'CreatePetsError'\n * resolverTsLegacy.resolveDataTypedName(node) // → 'CreatePetsMutationRequest' (POST)\n * resolverTsLegacy.resolveResponsesTypedName(node) // → 'CreatePetsMutation' (POST)\n * resolverTsLegacy.resolveResponseTypedName(node) // → 'CreatePetsMutationResponse' (POST)\n * ```\n */\nexport const resolverTsLegacy = defineResolver<PluginTs>(() => {\n return {\n ...resolverTs,\n resolveResponseStatusName(node, statusCode) {\n if (statusCode === 'default') {\n return this.resolveName(`${node.operationId} Error`)\n }\n return this.resolveName(`${node.operationId} ${statusCode}`)\n },\n resolveResponseStatusTypedName(node, statusCode) {\n if (statusCode === 'default') {\n return this.resolveTypedName(`${node.operationId} Error`)\n }\n return this.resolveTypedName(`${node.operationId} ${statusCode}`)\n },\n resolveDataName(node) {\n const suffix = node.method === 'GET' ? 'QueryRequest' : 'MutationRequest'\n return this.resolveName(`${node.operationId} ${suffix}`)\n },\n resolveDataTypedName(node) {\n const suffix = node.method === 'GET' ? 'QueryRequest' : 'MutationRequest'\n return this.resolveTypedName(`${node.operationId} ${suffix}`)\n },\n resolveResponsesName(node) {\n const suffix = node.method === 'GET' ? 'Query' : 'Mutation'\n return this.resolveName(`${node.operationId} ${suffix}`)\n },\n resolveResponsesTypedName(node) {\n const suffix = node.method === 'GET' ? 'Query' : 'Mutation'\n return this.resolveTypedName(`${node.operationId} ${suffix}`)\n },\n resolveResponseName(node) {\n const suffix = node.method === 'GET' ? 'QueryResponse' : 'MutationResponse'\n return this.resolveName(`${node.operationId} ${suffix}`)\n },\n resolveResponseTypedName(node) {\n const suffix = node.method === 'GET' ? 'QueryResponse' : 'MutationResponse'\n return this.resolveTypedName(`${node.operationId} ${suffix}`)\n },\n resolvePathParamsName(node) {\n return this.resolveName(`${node.operationId} PathParams`)\n },\n resolvePathParamsTypedName(node) {\n return this.resolveTypedName(`${node.operationId} PathParams`)\n },\n resolveQueryParamsName(node) {\n return this.resolveName(`${node.operationId} QueryParams`)\n },\n resolveQueryParamsTypedName(node) {\n return this.resolveTypedName(`${node.operationId} QueryParams`)\n },\n resolveHeaderParamsName(node) {\n return this.resolveName(`${node.operationId} HeaderParams`)\n },\n resolveHeaderParamsTypedName(node) {\n return this.resolveTypedName(`${node.operationId} HeaderParams`)\n },\n }\n})\n","import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { walk } from '@kubb/ast'\nimport { createPlugin, type Group, getBarrelFiles, getMode, renderOperation, renderSchema } from '@kubb/core'\nimport { typeGenerator } from './generators'\nimport { resolverTs, resolverTsLegacy } from './resolverTs.ts'\nimport type { PluginTs } from './types.ts'\n\nexport const pluginTsName = 'plugin-ts' satisfies PluginTs['name']\n\nexport const pluginTs = createPlugin<PluginTs>((options) => {\n const {\n output = { path: 'types', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n enumType = 'asConst',\n enumKeyCasing = 'none',\n optionalType = 'questionToken',\n arrayType = 'array',\n syntaxType = 'type',\n transformers = {},\n paramsCasing,\n generators = [typeGenerator].filter(Boolean),\n legacy = false,\n } = options\n\n const baseResolver = legacy ? resolverTsLegacy : resolverTs\n\n // When a `transformers.name` callback is provided, wrap the resolver so that\n // every name produced by `default()` (and therefore by every helper that calls\n // `this.default(...)`) flows through the user's transformer.\n const resolver: typeof baseResolver = transformers?.name\n ? {\n ...baseResolver,\n default(name, type) {\n const resolved = baseResolver.default(name, type)\n\n return transformers.name!(resolved, type) || resolved\n },\n }\n : baseResolver\n\n let resolveNameWarning = false\n\n return {\n name: pluginTsName,\n options: {\n output,\n transformers,\n optionalType,\n arrayType,\n enumType,\n enumKeyCasing,\n syntaxType,\n group,\n override,\n paramsCasing,\n legacy,\n resolver,\n },\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n if (!resolveNameWarning) {\n this.driver.events.emit('warn', 'Do not use resolveName for pluginTs, use resolverTs instead')\n resolveNameWarning = true\n }\n\n return resolver.default(name, type)\n },\n async install() {\n const { config, fabric, plugin, adapter, rootNode, driver, openInStudio } = this\n\n const root = path.resolve(config.root, config.output.path)\n const mode = getMode(path.resolve(root, output.path))\n\n if (!adapter) {\n throw new Error('Plugin cannot work without adapter being set')\n }\n\n await openInStudio({ ast: true })\n\n await walk(\n rootNode,\n {\n async schema(schemaNode) {\n const writeTasks = generators.map(async (generator) => {\n if (generator.type === 'react' && generator.version === '2') {\n const options = resolver.resolveOptions(schemaNode, { options: plugin.options, exclude, include, override })\n\n if (options === null) {\n return\n }\n\n await renderSchema(schemaNode, {\n options,\n adapter,\n config,\n fabric,\n Component: generator.Schema,\n plugin,\n driver,\n mode,\n })\n }\n })\n\n await Promise.all(writeTasks)\n },\n async operation(operationNode) {\n const writeTasks = generators.map(async (generator) => {\n if (generator.type === 'react' && generator.version === '2') {\n const options = resolver.resolveOptions(operationNode, { options: plugin.options, exclude, include, override })\n\n if (options === null) {\n return\n }\n\n await renderOperation(operationNode, {\n options,\n adapter,\n config,\n fabric,\n Component: generator.Operation,\n plugin,\n driver,\n mode,\n })\n }\n })\n\n await Promise.all(writeTasks)\n },\n },\n { depth: 'shallow' },\n )\n\n const barrelFiles = await getBarrelFiles(this.fabric.files, {\n type: output.barrelType ?? 'named',\n root,\n output,\n meta: {\n pluginName: this.plugin.name,\n },\n })\n\n await this.upsertFile(...barrelFiles)\n },\n }\n})\n"],"mappings":";;;;;;;AAIA,SAAS,YAAY,MAAc,MAAuD;AACxF,QAAO,WAAW,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;AAqBtD,MAAa,aAAa,qBAA+B;AACvD,QAAO;EACL,QAAQ,MAAM,MAAM;AAClB,UAAO,YAAY,MAAM,KAAK;;EAEhC,YAAY,MAAM;AAChB,UAAO,KAAK,QAAQ,MAAM,WAAW;;EAEvC,iBAAiB,MAAM;AACrB,UAAO,KAAK,QAAQ,MAAM,OAAO;;EAEnC,gBAAgB,MAAM,MAAM;AAC1B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AAS,OAAO;QAAS;QAAS;QAAS;QAAU,CAAC;AAE5G,WAAI,YAAY,KACd;AAGF,aAAM,aAAa,YAAY;QAC7B;QACA;QACA;QACA;QACA,WAAW,UAAU;QACrB;QACA;QACA;QACD,CAAC;;OAEJ;AAEF,WAAM,QAAQ,IAAI,WAAW;;IAE/B,MAAM,UAAU,eAAe;KAC7B,MAAM,aAAa,WAAW,IAAI,OAAO,cAAc;AACrD,UAAI,UAAU,SAAS,WAAW,UAAU,YAAY,KAAK;OAC3D,MAAM,UAAU,SAAS,eAAe,eAAe;QAAE,SAAS,OAAO;QAAS;QAAS;QAAS;QAAU,CAAC;AAE/G,WAAI,YAAY,KACd;AAGF,aAAM,gBAAgB,eAAe;QACnC;QACA;QACA;QACA;QACA,WAAW,UAAU;QACrB;QACA;QACA;QACD,CAAC;;OAEJ;AAEF,WAAM,QAAQ,IAAI,WAAW;;IAEhC,EACD,EAAE,OAAO,WAAW,CACrB;GAED,MAAM,cAAc,MAAM,eAAe,KAAK,OAAO,OAAO;IAC1D,MAAM,OAAO,cAAc;IAC3B;IACA;IACA,MAAM,EACJ,YAAY,KAAK,OAAO,MACzB;IACF,CAAC;AAEF,SAAM,KAAK,WAAW,GAAG,YAAY;;EAExC;EACD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { Group, Output, PluginFactoryOptions, ResolveNameParams, Resolver } from "@kubb/core";
|
|
3
|
-
import { Exclude, Include, Override, ResolvePathOptions } from "@kubb/plugin-oas";
|
|
4
|
-
import { Generator as Generator$1 } from "@kubb/plugin-oas/generators";
|
|
5
|
-
import { Oas, contentType } from "@kubb/oas";
|
|
6
3
|
import { OperationNode, ParameterNode, SchemaNode, StatusCode } from "@kubb/ast/types";
|
|
4
|
+
import { Oas, contentType } from "@kubb/oas";
|
|
5
|
+
import { Exclude, Include, Override, ResolvePathOptions } from "@kubb/plugin-oas";
|
|
6
|
+
import { Generator } from "@kubb/plugin-oas/generators";
|
|
7
7
|
|
|
8
8
|
//#region src/types.d.ts
|
|
9
9
|
/**
|
|
@@ -135,6 +135,60 @@ type ResolverTs = Resolver & {
|
|
|
135
135
|
* resolver.resolveEnumKeyTypedName(node) // → 'PetStatusKey'
|
|
136
136
|
*/
|
|
137
137
|
resolveEnumKeyTypedName(node: SchemaNode): string;
|
|
138
|
+
/**
|
|
139
|
+
* Resolves the variable/function name for an operation's grouped path parameters type.
|
|
140
|
+
* Only available in legacy mode (`legacy: true`).
|
|
141
|
+
*
|
|
142
|
+
* @deprecated Legacy only — will be removed in v6. Use `resolveParamName` per individual parameter instead.
|
|
143
|
+
* @example
|
|
144
|
+
* resolver.resolvePathParamsName(node) // → 'GetPetByIdPathParams'
|
|
145
|
+
*/
|
|
146
|
+
resolvePathParamsName?(node: OperationNode): string;
|
|
147
|
+
/**
|
|
148
|
+
* Resolves the TypeScript type alias name for an operation's grouped path parameters type.
|
|
149
|
+
* Only available in legacy mode (`legacy: true`).
|
|
150
|
+
*
|
|
151
|
+
* @deprecated Legacy only — will be removed in v6. Use `resolveParamTypedName` per individual parameter instead.
|
|
152
|
+
* @example
|
|
153
|
+
* resolver.resolvePathParamsTypedName(node) // → 'GetPetByIdPathParams'
|
|
154
|
+
*/
|
|
155
|
+
resolvePathParamsTypedName?(node: OperationNode): string;
|
|
156
|
+
/**
|
|
157
|
+
* Resolves the variable/function name for an operation's grouped query parameters type.
|
|
158
|
+
* Only available in legacy mode (`legacy: true`).
|
|
159
|
+
*
|
|
160
|
+
* @deprecated Legacy only — will be removed in v6. Use `resolveParamName` per individual parameter instead.
|
|
161
|
+
* @example
|
|
162
|
+
* resolver.resolveQueryParamsName(node) // → 'FindPetsByStatusQueryParams'
|
|
163
|
+
*/
|
|
164
|
+
resolveQueryParamsName?(node: OperationNode): string;
|
|
165
|
+
/**
|
|
166
|
+
* Resolves the TypeScript type alias name for an operation's grouped query parameters type.
|
|
167
|
+
* Only available in legacy mode (`legacy: true`).
|
|
168
|
+
*
|
|
169
|
+
* @deprecated Legacy only — will be removed in v6. Use `resolveParamTypedName` per individual parameter instead.
|
|
170
|
+
* @example
|
|
171
|
+
* resolver.resolveQueryParamsTypedName(node) // → 'FindPetsByStatusQueryParams'
|
|
172
|
+
*/
|
|
173
|
+
resolveQueryParamsTypedName?(node: OperationNode): string;
|
|
174
|
+
/**
|
|
175
|
+
* Resolves the variable/function name for an operation's grouped header parameters type.
|
|
176
|
+
* Only available in legacy mode (`legacy: true`).
|
|
177
|
+
*
|
|
178
|
+
* @deprecated Legacy only — will be removed in v6. Use `resolveParamName` per individual parameter instead.
|
|
179
|
+
* @example
|
|
180
|
+
* resolver.resolveHeaderParamsName(node) // → 'DeletePetHeaderParams'
|
|
181
|
+
*/
|
|
182
|
+
resolveHeaderParamsName?(node: OperationNode): string;
|
|
183
|
+
/**
|
|
184
|
+
* Resolves the TypeScript type alias name for an operation's grouped header parameters type.
|
|
185
|
+
* Only available in legacy mode (`legacy: true`).
|
|
186
|
+
*
|
|
187
|
+
* @deprecated Legacy only — will be removed in v6. Use `resolveParamTypedName` per individual parameter instead.
|
|
188
|
+
* @example
|
|
189
|
+
* resolver.resolveHeaderParamsTypedName(node) // → 'DeletePetHeaderParams'
|
|
190
|
+
*/
|
|
191
|
+
resolveHeaderParamsTypedName?(node: OperationNode): string;
|
|
138
192
|
};
|
|
139
193
|
type Options = {
|
|
140
194
|
/**
|
|
@@ -192,52 +246,6 @@ type Options = {
|
|
|
192
246
|
* @default 'type'
|
|
193
247
|
*/
|
|
194
248
|
syntaxType?: 'type' | 'interface';
|
|
195
|
-
/**
|
|
196
|
-
* Set a suffix for the generated enums.
|
|
197
|
-
* @default 'enum'
|
|
198
|
-
* @deprecated Set `enumSuffix` on the adapter (`adapterOas({ enumSuffix })`) instead.
|
|
199
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
200
|
-
*/
|
|
201
|
-
enumSuffix?: string;
|
|
202
|
-
/**
|
|
203
|
-
* Choose to use date or datetime as JavaScript Date instead of string.
|
|
204
|
-
* - 'string' represents dates as string values.
|
|
205
|
-
* - 'date' represents dates as JavaScript Date objects.
|
|
206
|
-
* @default 'string'
|
|
207
|
-
* @deprecated Set `dateType` on the adapter (`adapterOas({ dateType })`) instead.
|
|
208
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
209
|
-
*/
|
|
210
|
-
dateType?: 'string' | 'date';
|
|
211
|
-
/**
|
|
212
|
-
* Choose to use `number` or `bigint` for integer fields with `int64` format.
|
|
213
|
-
* - 'number' uses the TypeScript `number` type (matches JSON.parse() runtime behavior).
|
|
214
|
-
* - 'bigint' uses the TypeScript `bigint` type (accurate for values exceeding Number.MAX_SAFE_INTEGER).
|
|
215
|
-
* @note in v5 of Kubb 'bigint' will become the default to better align with OpenAPI's int64 specification.
|
|
216
|
-
* @default 'number'
|
|
217
|
-
* @deprecated Set `integerType` on the adapter (`adapterOas({ integerType })`) instead.
|
|
218
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
219
|
-
*/
|
|
220
|
-
integerType?: 'number' | 'bigint';
|
|
221
|
-
/**
|
|
222
|
-
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
223
|
-
* - 'any' allows any value.
|
|
224
|
-
* - 'unknown' requires type narrowing before use.
|
|
225
|
-
* - 'void' represents no value.
|
|
226
|
-
* @default 'any'
|
|
227
|
-
* @deprecated Set `unknownType` on the adapter (`adapterOas({ unknownType })`) instead.
|
|
228
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
229
|
-
*/
|
|
230
|
-
unknownType?: 'any' | 'unknown' | 'void';
|
|
231
|
-
/**
|
|
232
|
-
* Which type to use for empty schema values.
|
|
233
|
-
* - 'any' allows any value.
|
|
234
|
-
* - 'unknown' requires type narrowing before use.
|
|
235
|
-
* - 'void' represents no value.
|
|
236
|
-
* @default `unknownType`
|
|
237
|
-
* @deprecated Set `emptySchemaType` on the adapter (`adapterOas({ emptySchemaType })`) instead.
|
|
238
|
-
* In v5, the adapter owns this decision at parse time; the plugin option is ignored.
|
|
239
|
-
*/
|
|
240
|
-
emptySchemaType?: 'any' | 'unknown' | 'void';
|
|
241
249
|
/**
|
|
242
250
|
* Choose what to use as mode for an optional value.
|
|
243
251
|
* - 'questionToken' marks the property as optional with ? (e.g., type?: string).
|
|
@@ -269,11 +277,22 @@ type Options = {
|
|
|
269
277
|
/**
|
|
270
278
|
* Define some generators next to the ts generators
|
|
271
279
|
*/
|
|
272
|
-
generators?: Array<Generator
|
|
280
|
+
generators?: Array<Generator<PluginTs>>;
|
|
273
281
|
/**
|
|
274
282
|
* Unstable naming for v5
|
|
275
283
|
*/
|
|
276
284
|
UNSTABLE_NAMING?: true;
|
|
285
|
+
/**
|
|
286
|
+
* Enable legacy naming conventions for backwards compatibility.
|
|
287
|
+
* When enabled, operation-level types use the old naming scheme:
|
|
288
|
+
* - GET responses → `<OperationId>QueryResponse`, `<OperationId>Query`
|
|
289
|
+
* - Non-GET responses → `<OperationId>MutationResponse`, `<OperationId>Mutation`
|
|
290
|
+
* - Request body → `<OperationId>QueryRequest` / `<OperationId>MutationRequest`
|
|
291
|
+
* - Response status codes → `<OperationId><StatusCode>` (e.g. `CreatePets201`)
|
|
292
|
+
* - Default/error response → `<OperationId>Error`
|
|
293
|
+
* @default false
|
|
294
|
+
*/
|
|
295
|
+
legacy?: boolean;
|
|
277
296
|
};
|
|
278
297
|
type ResolvedOptions = {
|
|
279
298
|
output: Output<Oas>;
|
|
@@ -281,18 +300,15 @@ type ResolvedOptions = {
|
|
|
281
300
|
override: NonNullable<Options['override']>;
|
|
282
301
|
enumType: NonNullable<Options['enumType']>;
|
|
283
302
|
enumKeyCasing: NonNullable<Options['enumKeyCasing']>;
|
|
284
|
-
enumSuffix: NonNullable<Options['enumSuffix']>;
|
|
285
|
-
dateType: NonNullable<Options['dateType']>;
|
|
286
|
-
integerType: NonNullable<Options['integerType']>;
|
|
287
|
-
unknownType: NonNullable<Options['unknownType']>;
|
|
288
|
-
emptySchemaType: NonNullable<Options['emptySchemaType']>;
|
|
289
303
|
optionalType: NonNullable<Options['optionalType']>;
|
|
290
304
|
arrayType: NonNullable<Options['arrayType']>;
|
|
291
305
|
transformers: NonNullable<Options['transformers']>;
|
|
292
306
|
syntaxType: NonNullable<Options['syntaxType']>;
|
|
293
307
|
paramsCasing: Options['paramsCasing'];
|
|
308
|
+
legacy: NonNullable<Options['legacy']>;
|
|
309
|
+
resolver: ResolverTs;
|
|
294
310
|
};
|
|
295
311
|
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>;
|
|
296
312
|
//#endregion
|
|
297
|
-
export { PluginTs as n, Options as t };
|
|
298
|
-
//# sourceMappingURL=types-
|
|
313
|
+
export { PluginTs as n, ResolverTs as r, Options as t };
|
|
314
|
+
//# sourceMappingURL=types-BA1ZCQ5p.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ts",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.12",
|
|
4
4
|
"description": "TypeScript code generation plugin for Kubb, transforming OpenAPI schemas into TypeScript interfaces, types, and utility functions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
"@kubb/react-fabric": "0.14.0",
|
|
72
72
|
"remeda": "^2.33.6",
|
|
73
73
|
"typescript": "5.9.3",
|
|
74
|
-
"@kubb/
|
|
75
|
-
"@kubb/
|
|
76
|
-
"@kubb/
|
|
77
|
-
"@kubb/
|
|
74
|
+
"@kubb/oas": "5.0.0-alpha.12",
|
|
75
|
+
"@kubb/plugin-oas": "5.0.0-alpha.12",
|
|
76
|
+
"@kubb/ast": "5.0.0-alpha.12",
|
|
77
|
+
"@kubb/core": "5.0.0-alpha.12"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"@kubb/react-fabric": "0.14.0"
|
|
@@ -1,31 +1,40 @@
|
|
|
1
|
-
import { camelCase,
|
|
1
|
+
import { camelCase, trimQuotes } from '@internals/utils'
|
|
2
2
|
import type { EnumSchemaNode } from '@kubb/ast/types'
|
|
3
3
|
import { safePrint } from '@kubb/fabric-core/parsers/typescript'
|
|
4
4
|
import { File } from '@kubb/react-fabric'
|
|
5
5
|
import type { FabricReactNode } from '@kubb/react-fabric/types'
|
|
6
|
-
import { ENUM_TYPES_WITH_KEY_SUFFIX, ENUM_TYPES_WITH_RUNTIME_VALUE, ENUM_TYPES_WITH_TYPE_ONLY } from '
|
|
7
|
-
import * as factory from '
|
|
8
|
-
import type { PluginTs } from '
|
|
6
|
+
import { ENUM_TYPES_WITH_KEY_SUFFIX, ENUM_TYPES_WITH_RUNTIME_VALUE, ENUM_TYPES_WITH_TYPE_ONLY } from '../constants.ts'
|
|
7
|
+
import * as factory from '../factory.ts'
|
|
8
|
+
import type { PluginTs, ResolverTs } from '../types.ts'
|
|
9
9
|
|
|
10
10
|
type Props = {
|
|
11
11
|
node: EnumSchemaNode
|
|
12
12
|
enumType: PluginTs['resolvedOptions']['enumType']
|
|
13
13
|
enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing']
|
|
14
|
+
resolver: ResolverTs
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
|
|
18
19
|
*
|
|
19
20
|
* The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
|
|
20
|
-
* valid TypeScript identifier.
|
|
21
|
-
* properties the adapter already emits a PascalCase+suffix name so
|
|
21
|
+
* valid TypeScript identifier. The resolver normalizes it; for inline enum
|
|
22
|
+
* properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.
|
|
22
23
|
*/
|
|
23
|
-
export function getEnumNames(node: EnumSchemaNode
|
|
24
|
-
|
|
24
|
+
export function getEnumNames({ node, enumType, resolver }: { node: EnumSchemaNode; enumType: PluginTs['resolvedOptions']['enumType']; resolver: ResolverTs }): {
|
|
25
|
+
enumName: string
|
|
26
|
+
typeName: string
|
|
27
|
+
/**
|
|
28
|
+
* The PascalCase name that `$ref` importers will use to reference this enum type.
|
|
29
|
+
* For `asConst`/`asPascalConst` this differs from `typeName` (which has a `Key` suffix).
|
|
30
|
+
*/
|
|
31
|
+
refName: string
|
|
32
|
+
} {
|
|
33
|
+
const resolved = resolver.default(node.name!, 'type')
|
|
25
34
|
const enumName = enumType === 'asPascalConst' ? resolved : camelCase(node.name!)
|
|
26
35
|
const typeName = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) ? `${resolved}Key` : resolved
|
|
27
36
|
|
|
28
|
-
return { enumName, typeName }
|
|
37
|
+
return { enumName, typeName, refName: resolved }
|
|
29
38
|
}
|
|
30
39
|
|
|
31
40
|
/**
|
|
@@ -39,8 +48,8 @@ export function getEnumNames(node: EnumSchemaNode, enumType: PluginTs['resolvedO
|
|
|
39
48
|
* The emitted `File.Source` nodes carry the resolved names so that the barrel
|
|
40
49
|
* index picks up the correct export identifiers.
|
|
41
50
|
*/
|
|
42
|
-
export function Enum({ node, enumType, enumKeyCasing }: Props): FabricReactNode {
|
|
43
|
-
const { enumName, typeName } = getEnumNames(node, enumType)
|
|
51
|
+
export function Enum({ node, enumType, enumKeyCasing, resolver }: Props): FabricReactNode {
|
|
52
|
+
const { enumName, typeName, refName } = getEnumNames({ node, enumType, resolver })
|
|
44
53
|
|
|
45
54
|
const [nameNode, typeNode] = factory.createEnumDeclaration({
|
|
46
55
|
name: enumName,
|
|
@@ -52,6 +61,8 @@ export function Enum({ node, enumType, enumKeyCasing }: Props): FabricReactNode
|
|
|
52
61
|
enumKeyCasing,
|
|
53
62
|
})
|
|
54
63
|
|
|
64
|
+
const needsRefAlias = ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && refName !== typeName
|
|
65
|
+
|
|
55
66
|
return (
|
|
56
67
|
<>
|
|
57
68
|
{nameNode && (
|
|
@@ -62,6 +73,11 @@ export function Enum({ node, enumType, enumKeyCasing }: Props): FabricReactNode
|
|
|
62
73
|
<File.Source name={typeName} isIndexable isExportable={ENUM_TYPES_WITH_RUNTIME_VALUE.has(enumType)} isTypeOnly={ENUM_TYPES_WITH_TYPE_ONLY.has(enumType)}>
|
|
63
74
|
{safePrint(typeNode)}
|
|
64
75
|
</File.Source>
|
|
76
|
+
{needsRefAlias && (
|
|
77
|
+
<File.Source name={refName} isExportable isIndexable isTypeOnly>
|
|
78
|
+
{`export type ${refName} = ${typeName}`}
|
|
79
|
+
</File.Source>
|
|
80
|
+
)}
|
|
65
81
|
</>
|
|
66
82
|
)
|
|
67
83
|
}
|