@kubb/plugin-ts 5.0.0-alpha.13 → 5.0.0-alpha.14
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.d.ts +1 -1
- package/dist/{generators-CX3cSSdF.cjs → generators-B6JGhHkV.cjs} +28 -22
- package/dist/generators-B6JGhHkV.cjs.map +1 -0
- package/dist/{generators-dCqW0ECC.js → generators-BTTcjgbY.js} +29 -23
- package/dist/generators-BTTcjgbY.js.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index-B5pSjbZv.d.ts +51 -0
- package/dist/index.cjs +10 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +10 -15
- package/dist/index.js.map +1 -1
- package/dist/{resolvers-CH7hINyz.js → resolvers-C_vYX56l.js} +3 -1
- package/dist/resolvers-C_vYX56l.js.map +1 -0
- package/dist/{resolvers-ebHaaCyw.cjs → resolvers-DDZC7d43.cjs} +3 -1
- package/dist/resolvers-DDZC7d43.cjs.map +1 -0
- package/dist/resolvers.cjs +1 -1
- package/dist/resolvers.d.ts +2 -51
- package/dist/resolvers.js +1 -1
- package/dist/{types-BSRhtbGl.d.ts → types-D9zzvE0V.d.ts} +38 -21
- package/package.json +5 -5
- package/src/generators/typeGenerator.tsx +16 -12
- package/src/generators/utils.ts +13 -6
- package/src/index.ts +2 -1
- package/src/plugin.ts +52 -67
- package/src/resolvers/resolverTs.ts +1 -0
- package/src/resolvers/resolverTsLegacy.ts +1 -0
- package/src/types.ts +37 -20
- package/dist/generators-CX3cSSdF.cjs.map +0 -1
- package/dist/generators-dCqW0ECC.js.map +0 -1
- package/dist/resolvers-CH7hINyz.js.map +0 -1
- package/dist/resolvers-ebHaaCyw.cjs.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
+
import { r as ResolverTs } from "./types-D9zzvE0V.js";
|
|
3
|
+
|
|
4
|
+
//#region src/resolvers/resolverTs.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
7
|
+
* helpers used by the plugin. Import this in other plugins to resolve the exact names and
|
|
8
|
+
* paths that `plugin-ts` generates without hardcoding the conventions.
|
|
9
|
+
*
|
|
10
|
+
* The `default` method is automatically injected by `defineResolver` — it uses `camelCase`
|
|
11
|
+
* for identifiers/files and `pascalCase` for type names.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { resolver } from '@kubb/plugin-ts'
|
|
16
|
+
*
|
|
17
|
+
* resolver.default('list pets', 'type') // → 'ListPets'
|
|
18
|
+
* resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
|
|
19
|
+
* resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'
|
|
20
|
+
* resolver.resolvePathName('list pets', 'file') // → 'listPets'
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare const resolverTs: ResolverTs;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/resolvers/resolverTsLegacy.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Legacy resolver for `@kubb/plugin-ts` that reproduces the naming conventions
|
|
28
|
+
* used before the v2 resolver refactor. Enable via `legacy: true` in plugin options.
|
|
29
|
+
*
|
|
30
|
+
* Key differences from the default resolver:
|
|
31
|
+
* - Response status types: `<OperationId><StatusCode>` (e.g. `CreatePets201`) instead of `<OperationId>Status201`
|
|
32
|
+
* - Default/error responses: `<OperationId>Error` instead of `<OperationId>StatusDefault`
|
|
33
|
+
* - Request body: `<OperationId>MutationRequest` (non-GET) / `<OperationId>QueryRequest` (GET)
|
|
34
|
+
* - Combined responses type: `<OperationId>Mutation` / `<OperationId>Query`
|
|
35
|
+
* - Response union: `<OperationId>MutationResponse` / `<OperationId>QueryResponse`
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
40
|
+
*
|
|
41
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 201) // → 'CreatePets201'
|
|
42
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 'default') // → 'CreatePetsError'
|
|
43
|
+
* resolverTsLegacy.resolveDataTypedName(node) // → 'CreatePetsMutationRequest' (POST)
|
|
44
|
+
* resolverTsLegacy.resolveResponsesTypedName(node) // → 'CreatePetsMutation' (POST)
|
|
45
|
+
* resolverTsLegacy.resolveResponseTypedName(node) // → 'CreatePetsMutationResponse' (POST)
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare const resolverTsLegacy: ResolverTs;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { resolverTs as n, resolverTsLegacy as t };
|
|
51
|
+
//# sourceMappingURL=index-B5pSjbZv.d.ts.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_casing = require("./casing-D2uQKLWS.cjs");
|
|
3
|
-
const require_generators = require("./generators-
|
|
4
|
-
const require_resolvers = require("./resolvers-
|
|
3
|
+
const require_generators = require("./generators-B6JGhHkV.cjs");
|
|
4
|
+
const require_resolvers = require("./resolvers-DDZC7d43.cjs");
|
|
5
5
|
let node_path = require("node:path");
|
|
6
6
|
node_path = require_casing.__toESM(node_path);
|
|
7
7
|
let _kubb_ast = require("@kubb/ast");
|
|
@@ -12,21 +12,14 @@ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
|
12
12
|
const { output = {
|
|
13
13
|
path: "types",
|
|
14
14
|
barrelType: "named"
|
|
15
|
-
}, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type",
|
|
15
|
+
}, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", paramsCasing, generators = [require_generators.typeGenerator].filter(Boolean), legacy = false, resolvers: userResolvers, transformers = [] } = options;
|
|
16
16
|
const baseResolver = legacy ? require_resolvers.resolverTsLegacy : require_resolvers.resolverTs;
|
|
17
|
-
const resolver =
|
|
18
|
-
...baseResolver,
|
|
19
|
-
default(name, type) {
|
|
20
|
-
const resolved = baseResolver.default(name, type);
|
|
21
|
-
return transformers.name(resolved, type) || resolved;
|
|
22
|
-
}
|
|
23
|
-
} : baseResolver;
|
|
17
|
+
const resolver = (0, _kubb_core.mergeResolvers)(...userResolvers ?? [baseResolver]);
|
|
24
18
|
let resolveNameWarning = false;
|
|
25
19
|
return {
|
|
26
20
|
name: pluginTsName,
|
|
27
21
|
options: {
|
|
28
22
|
output,
|
|
29
|
-
transformers,
|
|
30
23
|
optionalType,
|
|
31
24
|
arrayType,
|
|
32
25
|
enumType,
|
|
@@ -37,7 +30,8 @@ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
|
37
30
|
paramsCasing,
|
|
38
31
|
legacy,
|
|
39
32
|
resolver,
|
|
40
|
-
baseResolver
|
|
33
|
+
baseResolver,
|
|
34
|
+
transformers
|
|
41
35
|
},
|
|
42
36
|
resolvePath(baseName, pathMode, options) {
|
|
43
37
|
const root = node_path.default.resolve(this.config.root, this.config.output.path);
|
|
@@ -70,6 +64,7 @@ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
|
70
64
|
if (!adapter) throw new Error("Plugin cannot work without adapter being set");
|
|
71
65
|
await openInStudio({ ast: true });
|
|
72
66
|
await (0, _kubb_ast.walk)(rootNode, {
|
|
67
|
+
depth: "shallow",
|
|
73
68
|
async schema(schemaNode) {
|
|
74
69
|
const writeTasks = generators.map(async (generator) => {
|
|
75
70
|
if (generator.type === "react" && generator.version === "2") {
|
|
@@ -118,7 +113,7 @@ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
|
118
113
|
});
|
|
119
114
|
await Promise.all(writeTasks);
|
|
120
115
|
}
|
|
121
|
-
}
|
|
116
|
+
});
|
|
122
117
|
const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
|
|
123
118
|
type: output.barrelType ?? "named",
|
|
124
119
|
root,
|
|
@@ -132,5 +127,7 @@ const pluginTs = (0, _kubb_core.createPlugin)((options) => {
|
|
|
132
127
|
//#endregion
|
|
133
128
|
exports.pluginTs = pluginTs;
|
|
134
129
|
exports.pluginTsName = pluginTsName;
|
|
130
|
+
exports.resolverTs = require_resolvers.resolverTs;
|
|
131
|
+
exports.resolverTsLegacy = require_resolvers.resolverTsLegacy;
|
|
135
132
|
|
|
136
133
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["typeGenerator","resolverTsLegacy","resolverTs","path","camelCase"],"sources":["../src/plugin.ts"],"sourcesContent":["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/index.ts'\nimport { resolverTs, resolverTsLegacy } from './resolvers/index.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
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["typeGenerator","resolverTsLegacy","resolverTs","path","camelCase"],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { walk } from '@kubb/ast'\nimport { createPlugin, type Group, getBarrelFiles, getMode, mergeResolvers, renderOperation, renderSchema } from '@kubb/core'\nimport { typeGenerator } from './generators/index.ts'\nimport { resolverTs, resolverTsLegacy } from './resolvers/index.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 paramsCasing,\n generators = [typeGenerator].filter(Boolean),\n legacy = false,\n resolvers: userResolvers,\n transformers = [],\n } = options\n\n const baseResolver = legacy ? resolverTsLegacy : resolverTs\n const resolver = mergeResolvers(...(userResolvers ?? [baseResolver]))\n\n let resolveNameWarning = false\n\n return {\n name: pluginTsName,\n options: {\n output,\n optionalType,\n arrayType,\n enumType,\n enumKeyCasing,\n syntaxType,\n group,\n override,\n paramsCasing,\n legacy,\n resolver,\n baseResolver,\n transformers,\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(rootNode, {\n depth: 'shallow',\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\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":";;;;;;;;;AAQA,MAAa,eAAe;AAE5B,MAAa,YAAA,GAAA,WAAA,eAAmC,YAAY;CAC1D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,WAAW,WACX,gBAAgB,QAChB,eAAe,iBACf,YAAY,SACZ,aAAa,QACb,cACA,aAAa,CAACA,mBAAAA,cAAc,CAAC,OAAO,QAAQ,EAC5C,SAAS,OACT,WAAW,eACX,eAAe,EAAE,KACf;CAEJ,MAAM,eAAe,SAASC,kBAAAA,mBAAm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js";
|
|
2
|
-
import { n as PluginTs, t as Options } from "./types-
|
|
2
|
+
import { n as PluginTs, r as ResolverTs, t as Options } from "./types-D9zzvE0V.js";
|
|
3
|
+
import { n as resolverTs, t as resolverTsLegacy } from "./index-B5pSjbZv.js";
|
|
3
4
|
import * as _kubb_core0 from "@kubb/core";
|
|
4
5
|
|
|
5
6
|
//#region src/plugin.d.ts
|
|
6
7
|
declare const pluginTsName = "plugin-ts";
|
|
7
8
|
declare const pluginTs: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle<PluginTs>;
|
|
8
9
|
//#endregion
|
|
9
|
-
export { type PluginTs, pluginTs, pluginTsName };
|
|
10
|
+
export { type PluginTs, type ResolverTs, pluginTs, pluginTsName, resolverTs, resolverTsLegacy };
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
2
|
import { t as camelCase } from "./casing-Cp-jbC_k.js";
|
|
3
|
-
import { t as typeGenerator } from "./generators-
|
|
4
|
-
import { n as resolverTs, t as resolverTsLegacy } from "./resolvers-
|
|
3
|
+
import { t as typeGenerator } from "./generators-BTTcjgbY.js";
|
|
4
|
+
import { n as resolverTs, t as resolverTsLegacy } from "./resolvers-C_vYX56l.js";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { walk } from "@kubb/ast";
|
|
7
|
-
import { createPlugin, getBarrelFiles, getMode, renderOperation, renderSchema } from "@kubb/core";
|
|
7
|
+
import { createPlugin, getBarrelFiles, getMode, mergeResolvers, renderOperation, renderSchema } from "@kubb/core";
|
|
8
8
|
//#region src/plugin.ts
|
|
9
9
|
const pluginTsName = "plugin-ts";
|
|
10
10
|
const pluginTs = createPlugin((options) => {
|
|
11
11
|
const { output = {
|
|
12
12
|
path: "types",
|
|
13
13
|
barrelType: "named"
|
|
14
|
-
}, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type",
|
|
14
|
+
}, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", paramsCasing, generators = [typeGenerator].filter(Boolean), legacy = false, resolvers: userResolvers, transformers = [] } = options;
|
|
15
15
|
const baseResolver = legacy ? resolverTsLegacy : resolverTs;
|
|
16
|
-
const resolver =
|
|
17
|
-
...baseResolver,
|
|
18
|
-
default(name, type) {
|
|
19
|
-
const resolved = baseResolver.default(name, type);
|
|
20
|
-
return transformers.name(resolved, type) || resolved;
|
|
21
|
-
}
|
|
22
|
-
} : baseResolver;
|
|
16
|
+
const resolver = mergeResolvers(...userResolvers ?? [baseResolver]);
|
|
23
17
|
let resolveNameWarning = false;
|
|
24
18
|
return {
|
|
25
19
|
name: pluginTsName,
|
|
26
20
|
options: {
|
|
27
21
|
output,
|
|
28
|
-
transformers,
|
|
29
22
|
optionalType,
|
|
30
23
|
arrayType,
|
|
31
24
|
enumType,
|
|
@@ -36,7 +29,8 @@ const pluginTs = createPlugin((options) => {
|
|
|
36
29
|
paramsCasing,
|
|
37
30
|
legacy,
|
|
38
31
|
resolver,
|
|
39
|
-
baseResolver
|
|
32
|
+
baseResolver,
|
|
33
|
+
transformers
|
|
40
34
|
},
|
|
41
35
|
resolvePath(baseName, pathMode, options) {
|
|
42
36
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
@@ -69,6 +63,7 @@ const pluginTs = createPlugin((options) => {
|
|
|
69
63
|
if (!adapter) throw new Error("Plugin cannot work without adapter being set");
|
|
70
64
|
await openInStudio({ ast: true });
|
|
71
65
|
await walk(rootNode, {
|
|
66
|
+
depth: "shallow",
|
|
72
67
|
async schema(schemaNode) {
|
|
73
68
|
const writeTasks = generators.map(async (generator) => {
|
|
74
69
|
if (generator.type === "react" && generator.version === "2") {
|
|
@@ -117,7 +112,7 @@ const pluginTs = createPlugin((options) => {
|
|
|
117
112
|
});
|
|
118
113
|
await Promise.all(writeTasks);
|
|
119
114
|
}
|
|
120
|
-
}
|
|
115
|
+
});
|
|
121
116
|
const barrelFiles = await getBarrelFiles(this.fabric.files, {
|
|
122
117
|
type: output.barrelType ?? "named",
|
|
123
118
|
root,
|
|
@@ -129,6 +124,6 @@ const pluginTs = createPlugin((options) => {
|
|
|
129
124
|
};
|
|
130
125
|
});
|
|
131
126
|
//#endregion
|
|
132
|
-
export { pluginTs, pluginTsName };
|
|
127
|
+
export { pluginTs, pluginTsName, resolverTs, resolverTsLegacy };
|
|
133
128
|
|
|
134
129
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["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/index.ts'\nimport { resolverTs, resolverTsLegacy } from './resolvers/index.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
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { camelCase } from '@internals/utils'\nimport { walk } from '@kubb/ast'\nimport { createPlugin, type Group, getBarrelFiles, getMode, mergeResolvers, renderOperation, renderSchema } from '@kubb/core'\nimport { typeGenerator } from './generators/index.ts'\nimport { resolverTs, resolverTsLegacy } from './resolvers/index.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 paramsCasing,\n generators = [typeGenerator].filter(Boolean),\n legacy = false,\n resolvers: userResolvers,\n transformers = [],\n } = options\n\n const baseResolver = legacy ? resolverTsLegacy : resolverTs\n const resolver = mergeResolvers(...(userResolvers ?? [baseResolver]))\n\n let resolveNameWarning = false\n\n return {\n name: pluginTsName,\n options: {\n output,\n optionalType,\n arrayType,\n enumType,\n enumKeyCasing,\n syntaxType,\n group,\n override,\n paramsCasing,\n legacy,\n resolver,\n baseResolver,\n transformers,\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(rootNode, {\n depth: 'shallow',\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\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":";;;;;;;;AAQA,MAAa,eAAe;AAE5B,MAAa,WAAW,cAAwB,YAAY;CAC1D,MAAM,EACJ,SAAS;EAAE,MAAM;EAAS,YAAY;EAAS,EAC/C,OACA,UAAU,EAAE,EACZ,SACA,WAAW,EAAE,EACb,WAAW,WACX,gBAAgB,QAChB,eAAe,iBACf,YAAY,SACZ,aAAa,QACb,cACA,aAAa,CAAC,cAAc,CAAC,OAAO,QAAQ,EAC5C,SAAS,OACT,WAAW,eACX,eAAe,EAAE,KACf;CAEJ,MAAM,eAAe,SAAS,mBAAmB;CACjD,MAAM,WAAW,eAAe,GAAI,iBAAiB,CAAC,aAAa,CAAE;CAErE,IAAI,qBAAqB;AAEzB,QAAO;EACL,MAAM;EACN,SAAS;GACP;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD;EACD,YAAY,UAAU,UAAU,SAAS;GACvC,MAA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AAE,SAAS,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,CAAC;GAEF,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"}
|
|
@@ -25,6 +25,7 @@ function resolveName(name, type) {
|
|
|
25
25
|
*/
|
|
26
26
|
const resolverTs = defineResolver(() => {
|
|
27
27
|
return {
|
|
28
|
+
name: "default",
|
|
28
29
|
default(name, type) {
|
|
29
30
|
return resolveName(name, type);
|
|
30
31
|
},
|
|
@@ -123,6 +124,7 @@ const resolverTs = defineResolver(() => {
|
|
|
123
124
|
const resolverTsLegacy = defineResolver(() => {
|
|
124
125
|
return {
|
|
125
126
|
...resolverTs,
|
|
127
|
+
name: "legacy",
|
|
126
128
|
resolveResponseStatusName(node, statusCode) {
|
|
127
129
|
if (statusCode === "default") return this.resolveName(`${node.operationId} Error`);
|
|
128
130
|
return this.resolveName(`${node.operationId} ${statusCode}`);
|
|
@@ -178,4 +180,4 @@ const resolverTsLegacy = defineResolver(() => {
|
|
|
178
180
|
//#endregion
|
|
179
181
|
export { resolverTs as n, resolverTsLegacy as t };
|
|
180
182
|
|
|
181
|
-
//# sourceMappingURL=resolvers-
|
|
183
|
+
//# sourceMappingURL=resolvers-C_vYX56l.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers-C_vYX56l.js","names":[],"sources":["../src/resolvers/resolverTs.ts","../src/resolvers/resolverTsLegacy.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 name: 'default',\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 return this.resolveName(`${node.operationId} QueryParams`)\n },\n resolveQueryParamsTypedName(node) {\n return this.resolveTypedName(`${node.operationId} QueryParams`)\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","import { defineResolver } from '@kubb/core'\nimport type { PluginTs } from '../types.ts'\nimport { resolverTs } from './resolverTs.ts'\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 name: 'legacy',\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.default(node.operationId, 'function')}${suffix}`\n },\n resolveResponsesTypedName(node) {\n const suffix = node.method === 'GET' ? 'Query' : 'Mutation'\n return `${this.default(node.operationId, 'type')}${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"],"mappings":";;;;AAIA,SAAS,YAAY,MAAc,MAAuD;AACxF,QAAO,WAAW,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;AAqBtD,MAAa,aAAa,qBAA+B;AACvD,QAAO;EACL,MAAM;EACN,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,UAAO,KAAK,QAAQ,MAAM,KAAK;;EAEjC,iBAAiB,MAAM,OAAO;AAC5B,UAAO,KAAK,YAAY,GAAG,KAAK,YAAY,GAAG,KAAK,QAAQ,MAAM,GAAG,CAAC,GAAG,MAAM,OAAO;;EAExF,sBAAsB,MAAM,OAAO;AACjC,UAAO,KAAK,iBAAiB,GAAG,KAAK,YAAY,GAAG,KAAK,QAAQ,MAAM,GAAG,CAAC,GAAG,MA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C/B,UAAO,KAAK,iBAAiB,GAAG,KAAK,YAAY,aAAa;;EAEhE,uBAAuB,MAAM;AAC3B,UAAO,KAAK,YAAY,GAAG,KAAK,YAAY,cAAc;;EAE5D,4BAA4B,MAAM;AAChC,UAAO,KAAK,iBAAiB,GAAG,KAAK,YAAY,cAAc;;EAEjE,wBAAwB,MAAM;AAC5B,UAAO,KAAK,YAAY,GAAG,KAAK,YAAY,eAAe;;EAE7D,6BAA6B,MAAM;AACjC,UAAO,KAAK,iBAAiB,GAAG,KAAK,YAAY,eAAe;;EAEnE;EACD"}
|
|
@@ -24,6 +24,7 @@ function resolveName(name, type) {
|
|
|
24
24
|
*/
|
|
25
25
|
const resolverTs = (0, _kubb_core.defineResolver)(() => {
|
|
26
26
|
return {
|
|
27
|
+
name: "default",
|
|
27
28
|
default(name, type) {
|
|
28
29
|
return resolveName(name, type);
|
|
29
30
|
},
|
|
@@ -122,6 +123,7 @@ const resolverTs = (0, _kubb_core.defineResolver)(() => {
|
|
|
122
123
|
const resolverTsLegacy = (0, _kubb_core.defineResolver)(() => {
|
|
123
124
|
return {
|
|
124
125
|
...resolverTs,
|
|
126
|
+
name: "legacy",
|
|
125
127
|
resolveResponseStatusName(node, statusCode) {
|
|
126
128
|
if (statusCode === "default") return this.resolveName(`${node.operationId} Error`);
|
|
127
129
|
return this.resolveName(`${node.operationId} ${statusCode}`);
|
|
@@ -188,4 +190,4 @@ Object.defineProperty(exports, "resolverTsLegacy", {
|
|
|
188
190
|
}
|
|
189
191
|
});
|
|
190
192
|
|
|
191
|
-
//# sourceMappingURL=resolvers-
|
|
193
|
+
//# sourceMappingURL=resolvers-DDZC7d43.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers-DDZC7d43.cjs","names":["pascalCase"],"sources":["../src/resolvers/resolverTs.ts","../src/resolvers/resolverTsLegacy.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 name: 'default',\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 return this.resolveName(`${node.operationId} QueryParams`)\n },\n resolveQueryParamsTypedName(node) {\n return this.resolveTypedName(`${node.operationId} QueryParams`)\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","import { defineResolver } from '@kubb/core'\nimport type { PluginTs } from '../types.ts'\nimport { resolverTs } from './resolverTs.ts'\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 name: 'legacy',\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.default(node.operationId, 'function')}${suffix}`\n },\n resolveResponsesTypedName(node) {\n const suffix = node.method === 'GET' ? 'Query' : 'Mutation'\n return `${this.default(node.operationId, 'type')}${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"],"mappings":";;;AAIA,SAAS,YAAY,MAAc,MAAuD;AACxF,QAAOA,eAAAA,WAAW,MAAM,EAAE,QAAQ,SAAS,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;AAqBtD,MAAa,cAAA,GAAA,WAAA,sBAA4C;AACvD,QAAO;EACL,MAAM;EACN,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,UAAO,KAAK,QAAQ,MAAM,KAAK;;EAEjC,iBAAiB,MAAM,OAAO;AAC5B,UAAO,KAAK,YAAY,GAAG,KAAK,YAAY,GAAG,KAAK,QAAQ,MAAM,GAAG,CAAC,GAAG,MAAM,OAAO;;EAExF,sBAAsB,MAAM,OAAO;AACjC,UAAO,KAAK,iBAAiB,GAAG,KAAK,YAAY,GAAG,KAAK,QAAQ,MAAM,GAAG,CAAC,GAAG,MAAM,OAAO;;EAE7F,0BAA0B,MAAM,YAAY;AAC1C,UAAO,KAAK,YAAY,GAAG,KAAK,YAAY,UAAU,aAAa;;EAErE,+BAA+B,MAAM,YAAY;AAC/C,UAAO,KAAK,iBAAiB,GAAG,KAAK,YAAY,UAAU,aAAa;;EAE1E,gBAAgB,MAAM;AACpB,UAAO,KAAK,YAAY,GAAG,KAAK,YAAY,OAAO;;EAErD,qBAAqB,MAAM;AACzB,UAAO,KAAK,iBAAiB,GAAG,KAAK,YAAY,OAAO;;EAE1D,yBAAyB,MAAM;AAC7B,UAAO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E;EACD"}
|
package/dist/resolvers.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_resolvers = require("./resolvers-
|
|
2
|
+
const require_resolvers = require("./resolvers-DDZC7d43.cjs");
|
|
3
3
|
exports.resolverTs = require_resolvers.resolverTs;
|
|
4
4
|
exports.resolverTsLegacy = require_resolvers.resolverTsLegacy;
|
package/dist/resolvers.d.ts
CHANGED
|
@@ -1,51 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
//#region src/resolvers/resolverTs.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
7
|
-
* helpers used by the plugin. Import this in other plugins to resolve the exact names and
|
|
8
|
-
* paths that `plugin-ts` generates without hardcoding the conventions.
|
|
9
|
-
*
|
|
10
|
-
* The `default` method is automatically injected by `defineResolver` — it uses `camelCase`
|
|
11
|
-
* for identifiers/files and `pascalCase` for type names.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```ts
|
|
15
|
-
* import { resolver } from '@kubb/plugin-ts'
|
|
16
|
-
*
|
|
17
|
-
* resolver.default('list pets', 'type') // → 'ListPets'
|
|
18
|
-
* resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
|
|
19
|
-
* resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'
|
|
20
|
-
* resolver.resolvePathName('list pets', 'file') // → 'listPets'
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
declare const resolverTs: ResolverTs;
|
|
24
|
-
//#endregion
|
|
25
|
-
//#region src/resolvers/resolverTsLegacy.d.ts
|
|
26
|
-
/**
|
|
27
|
-
* Legacy resolver for `@kubb/plugin-ts` that reproduces the naming conventions
|
|
28
|
-
* used before the v2 resolver refactor. Enable via `legacy: true` in plugin options.
|
|
29
|
-
*
|
|
30
|
-
* Key differences from the default resolver:
|
|
31
|
-
* - Response status types: `<OperationId><StatusCode>` (e.g. `CreatePets201`) instead of `<OperationId>Status201`
|
|
32
|
-
* - Default/error responses: `<OperationId>Error` instead of `<OperationId>StatusDefault`
|
|
33
|
-
* - Request body: `<OperationId>MutationRequest` (non-GET) / `<OperationId>QueryRequest` (GET)
|
|
34
|
-
* - Combined responses type: `<OperationId>Mutation` / `<OperationId>Query`
|
|
35
|
-
* - Response union: `<OperationId>MutationResponse` / `<OperationId>QueryResponse`
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
40
|
-
*
|
|
41
|
-
* resolverTsLegacy.resolveResponseStatusTypedName(node, 201) // → 'CreatePets201'
|
|
42
|
-
* resolverTsLegacy.resolveResponseStatusTypedName(node, 'default') // → 'CreatePetsError'
|
|
43
|
-
* resolverTsLegacy.resolveDataTypedName(node) // → 'CreatePetsMutationRequest' (POST)
|
|
44
|
-
* resolverTsLegacy.resolveResponsesTypedName(node) // → 'CreatePetsMutation' (POST)
|
|
45
|
-
* resolverTsLegacy.resolveResponseTypedName(node) // → 'CreatePetsMutationResponse' (POST)
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
declare const resolverTsLegacy: ResolverTs;
|
|
49
|
-
//#endregion
|
|
50
|
-
export { resolverTs, resolverTsLegacy };
|
|
51
|
-
//# sourceMappingURL=resolvers.d.ts.map
|
|
1
|
+
import { n as resolverTs, t as resolverTsLegacy } from "./index-B5pSjbZv.js";
|
|
2
|
+
export { resolverTs, resolverTsLegacy };
|
package/dist/resolvers.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as resolverTs, t as resolverTsLegacy } from "./resolvers-
|
|
1
|
+
import { n as resolverTs, t as resolverTsLegacy } from "./resolvers-C_vYX56l.js";
|
|
2
2
|
export { resolverTs, resolverTsLegacy };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { Group, Output, PluginFactoryOptions,
|
|
3
|
-
import { OperationNode, ParameterNode, SchemaNode, StatusCode } from "@kubb/ast/types";
|
|
2
|
+
import { Group, Output, PluginFactoryOptions, Resolver } from "@kubb/core";
|
|
3
|
+
import { OperationNode, ParameterNode, SchemaNode, StatusCode, Visitor } from "@kubb/ast/types";
|
|
4
4
|
import { Oas, contentType } from "@kubb/oas";
|
|
5
5
|
import { Exclude, Include, Override, ResolvePathOptions } from "@kubb/plugin-oas";
|
|
6
6
|
import { Generator } from "@kubb/plugin-oas/generators";
|
|
@@ -261,12 +261,6 @@ type Options = {
|
|
|
261
261
|
* @default 'array'
|
|
262
262
|
*/
|
|
263
263
|
arrayType?: 'generic' | 'array';
|
|
264
|
-
transformers?: {
|
|
265
|
-
/**
|
|
266
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
267
|
-
*/
|
|
268
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
269
|
-
};
|
|
270
264
|
/**
|
|
271
265
|
* How to style your params, by default no casing is applied
|
|
272
266
|
* - 'camelcase' uses camelCase for pathParams, queryParams and headerParams property names
|
|
@@ -284,15 +278,39 @@ type Options = {
|
|
|
284
278
|
UNSTABLE_NAMING?: true;
|
|
285
279
|
/**
|
|
286
280
|
* 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
281
|
* @default false
|
|
294
282
|
*/
|
|
295
283
|
legacy?: boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Array of named resolvers that control naming conventions.
|
|
286
|
+
* Later entries override earlier ones (last wins).
|
|
287
|
+
* Built-in: `resolverTs` (default), `resolverTsLegacy`.
|
|
288
|
+
* @default [resolverTs]
|
|
289
|
+
*/
|
|
290
|
+
resolvers?: Array<ResolverTs>;
|
|
291
|
+
/**
|
|
292
|
+
* Array of AST visitors applied to each SchemaNode/OperationNode before printing.
|
|
293
|
+
* Uses `transform()` from `@kubb/ast` — visitors can modify, replace, or annotate nodes.
|
|
294
|
+
*
|
|
295
|
+
* @example Remove writeOnly properties from response types
|
|
296
|
+
* ```ts
|
|
297
|
+
* transformers: [{
|
|
298
|
+
* property(node) {
|
|
299
|
+
* if (node.schema.writeOnly) return undefined
|
|
300
|
+
* }
|
|
301
|
+
* }]
|
|
302
|
+
* ```
|
|
303
|
+
*
|
|
304
|
+
* @example Force all dates to plain strings
|
|
305
|
+
* ```ts
|
|
306
|
+
* transformers: [{
|
|
307
|
+
* schema(node) {
|
|
308
|
+
* if (node.type === 'date') return { ...node, type: 'string' }
|
|
309
|
+
* }
|
|
310
|
+
* }]
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
transformers?: Array<Visitor>;
|
|
296
314
|
};
|
|
297
315
|
type ResolvedOptions = {
|
|
298
316
|
output: Output<Oas>;
|
|
@@ -302,20 +320,19 @@ type ResolvedOptions = {
|
|
|
302
320
|
enumKeyCasing: NonNullable<Options['enumKeyCasing']>;
|
|
303
321
|
optionalType: NonNullable<Options['optionalType']>;
|
|
304
322
|
arrayType: NonNullable<Options['arrayType']>;
|
|
305
|
-
transformers: NonNullable<Options['transformers']>;
|
|
306
323
|
syntaxType: NonNullable<Options['syntaxType']>;
|
|
307
324
|
paramsCasing: Options['paramsCasing'];
|
|
308
325
|
legacy: NonNullable<Options['legacy']>;
|
|
309
326
|
resolver: ResolverTs;
|
|
310
327
|
/**
|
|
311
|
-
* The
|
|
312
|
-
* Used internally to derive
|
|
313
|
-
*
|
|
314
|
-
* the middle of inline-enum identifiers.
|
|
328
|
+
* The resolver without user naming overrides applied.
|
|
329
|
+
* Used internally to derive stable names for unnamed enums and grouped params
|
|
330
|
+
* so that the schema tree stays consistent regardless of `transformers.name` / custom resolvers.
|
|
315
331
|
*/
|
|
316
|
-
baseResolver
|
|
332
|
+
baseResolver: ResolverTs;
|
|
333
|
+
transformers: Array<Visitor>;
|
|
317
334
|
};
|
|
318
335
|
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>;
|
|
319
336
|
//#endregion
|
|
320
337
|
export { PluginTs as n, ResolverTs as r, Options as t };
|
|
321
|
-
//# sourceMappingURL=types-
|
|
338
|
+
//# sourceMappingURL=types-D9zzvE0V.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.14",
|
|
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",
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
"@kubb/react-fabric": "0.14.0",
|
|
79
79
|
"remeda": "^2.33.6",
|
|
80
80
|
"typescript": "5.9.3",
|
|
81
|
-
"@kubb/ast": "5.0.0-alpha.
|
|
82
|
-
"@kubb/core": "5.0.0-alpha.
|
|
83
|
-
"@kubb/oas": "5.0.0-alpha.
|
|
84
|
-
"@kubb/plugin-oas": "5.0.0-alpha.
|
|
81
|
+
"@kubb/ast": "5.0.0-alpha.14",
|
|
82
|
+
"@kubb/core": "5.0.0-alpha.14",
|
|
83
|
+
"@kubb/oas": "5.0.0-alpha.14",
|
|
84
|
+
"@kubb/plugin-oas": "5.0.0-alpha.14"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"@kubb/react-fabric": "0.14.0"
|