@kubb/plugin-ts 5.0.0-alpha.12 → 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/{Type-CX1HRooG.js → Type-C8EHVKjc.js} +6 -84
- package/dist/Type-C8EHVKjc.js.map +1 -0
- package/dist/{Type-Cat0_htq.cjs → Type-DrOq6-nh.cjs} +11 -139
- package/dist/Type-DrOq6-nh.cjs.map +1 -0
- package/dist/casing-Cp-jbC_k.js +84 -0
- package/dist/casing-Cp-jbC_k.js.map +1 -0
- package/dist/casing-D2uQKLWS.cjs +144 -0
- package/dist/casing-D2uQKLWS.cjs.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.ts +2 -1
- package/dist/components.js +1 -1
- package/dist/{generators-DWBU-MuW.cjs → generators-B6JGhHkV.cjs} +54 -33
- package/dist/generators-B6JGhHkV.cjs.map +1 -0
- package/dist/{generators-CLuCmfUz.js → generators-BTTcjgbY.js} +52 -31
- 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 +15 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -46
- package/dist/index.js +11 -187
- package/dist/index.js.map +1 -1
- package/dist/resolvers-C_vYX56l.js +183 -0
- package/dist/resolvers-C_vYX56l.js.map +1 -0
- package/dist/resolvers-DDZC7d43.cjs +193 -0
- package/dist/resolvers-DDZC7d43.cjs.map +1 -0
- package/dist/resolvers.cjs +4 -0
- package/dist/resolvers.d.ts +2 -0
- package/dist/resolvers.js +2 -0
- package/dist/{types-BA1ZCQ5p.d.ts → types-D9zzvE0V.d.ts} +40 -16
- package/package.json +12 -5
- package/src/components/Type.tsx +1 -0
- package/src/generators/typeGenerator.tsx +33 -14
- package/src/generators/utils.ts +18 -9
- package/src/index.ts +2 -2
- package/src/plugin.ts +55 -69
- package/src/printer.ts +5 -2
- package/src/resolvers/index.ts +2 -0
- package/src/{resolverTs.ts → resolvers/resolverTs.ts} +6 -89
- package/src/resolvers/resolverTsLegacy.ts +86 -0
- package/src/types.ts +39 -15
- package/dist/Type-CX1HRooG.js.map +0 -1
- package/dist/Type-Cat0_htq.cjs.map +0 -1
- package/dist/generators-CLuCmfUz.js.map +0 -1
- package/dist/generators-DWBU-MuW.cjs.map +0 -1
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
const require_casing = require("./casing-D2uQKLWS.cjs");
|
|
2
|
+
let _kubb_core = require("@kubb/core");
|
|
3
|
+
//#region src/resolvers/resolverTs.ts
|
|
4
|
+
function resolveName(name, type) {
|
|
5
|
+
return require_casing.pascalCase(name, { isFile: type === "file" });
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
9
|
+
* helpers used by the plugin. Import this in other plugins to resolve the exact names and
|
|
10
|
+
* paths that `plugin-ts` generates without hardcoding the conventions.
|
|
11
|
+
*
|
|
12
|
+
* The `default` method is automatically injected by `defineResolver` — it uses `camelCase`
|
|
13
|
+
* for identifiers/files and `pascalCase` for type names.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { resolver } from '@kubb/plugin-ts'
|
|
18
|
+
*
|
|
19
|
+
* resolver.default('list pets', 'type') // → 'ListPets'
|
|
20
|
+
* resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
|
|
21
|
+
* resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'
|
|
22
|
+
* resolver.resolvePathName('list pets', 'file') // → 'listPets'
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
const resolverTs = (0, _kubb_core.defineResolver)(() => {
|
|
26
|
+
return {
|
|
27
|
+
name: "default",
|
|
28
|
+
default(name, type) {
|
|
29
|
+
return resolveName(name, type);
|
|
30
|
+
},
|
|
31
|
+
resolveName(name) {
|
|
32
|
+
return this.default(name, "function");
|
|
33
|
+
},
|
|
34
|
+
resolveTypedName(name) {
|
|
35
|
+
return this.default(name, "type");
|
|
36
|
+
},
|
|
37
|
+
resolvePathName(name, type) {
|
|
38
|
+
return this.default(name, type);
|
|
39
|
+
},
|
|
40
|
+
resolveParamName(node, param) {
|
|
41
|
+
return this.resolveName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
|
|
42
|
+
},
|
|
43
|
+
resolveParamTypedName(node, param) {
|
|
44
|
+
return this.resolveTypedName(`${node.operationId} ${this.default(param.in)} ${param.name}`);
|
|
45
|
+
},
|
|
46
|
+
resolveResponseStatusName(node, statusCode) {
|
|
47
|
+
return this.resolveName(`${node.operationId} Status ${statusCode}`);
|
|
48
|
+
},
|
|
49
|
+
resolveResponseStatusTypedName(node, statusCode) {
|
|
50
|
+
return this.resolveTypedName(`${node.operationId} Status ${statusCode}`);
|
|
51
|
+
},
|
|
52
|
+
resolveDataName(node) {
|
|
53
|
+
return this.resolveName(`${node.operationId} Data`);
|
|
54
|
+
},
|
|
55
|
+
resolveDataTypedName(node) {
|
|
56
|
+
return this.resolveTypedName(`${node.operationId} Data`);
|
|
57
|
+
},
|
|
58
|
+
resolveRequestConfigName(node) {
|
|
59
|
+
return this.resolveName(`${node.operationId} RequestConfig`);
|
|
60
|
+
},
|
|
61
|
+
resolveRequestConfigTypedName(node) {
|
|
62
|
+
return this.resolveTypedName(`${node.operationId} RequestConfig`);
|
|
63
|
+
},
|
|
64
|
+
resolveResponsesName(node) {
|
|
65
|
+
return this.resolveName(`${node.operationId} Responses`);
|
|
66
|
+
},
|
|
67
|
+
resolveResponsesTypedName(node) {
|
|
68
|
+
return this.resolveTypedName(`${node.operationId} Responses`);
|
|
69
|
+
},
|
|
70
|
+
resolveResponseName(node) {
|
|
71
|
+
return this.resolveName(`${node.operationId} Response`);
|
|
72
|
+
},
|
|
73
|
+
resolveResponseTypedName(node) {
|
|
74
|
+
return this.resolveTypedName(`${node.operationId} Response`);
|
|
75
|
+
},
|
|
76
|
+
resolveEnumKeyTypedName(node) {
|
|
77
|
+
return `${this.resolveTypedName(node.name ?? "")}Key`;
|
|
78
|
+
},
|
|
79
|
+
resolvePathParamsName(_node) {
|
|
80
|
+
throw new Error("resolvePathParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
|
|
81
|
+
},
|
|
82
|
+
resolvePathParamsTypedName(_node) {
|
|
83
|
+
throw new Error("resolvePathParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
|
|
84
|
+
},
|
|
85
|
+
resolveQueryParamsName(node) {
|
|
86
|
+
return this.resolveName(`${node.operationId} QueryParams`);
|
|
87
|
+
},
|
|
88
|
+
resolveQueryParamsTypedName(node) {
|
|
89
|
+
return this.resolveTypedName(`${node.operationId} QueryParams`);
|
|
90
|
+
},
|
|
91
|
+
resolveHeaderParamsName(_node) {
|
|
92
|
+
throw new Error("resolveHeaderParamsName is only available in legacy mode (legacy: true). Use resolveParamName per individual parameter instead.");
|
|
93
|
+
},
|
|
94
|
+
resolveHeaderParamsTypedName(_node) {
|
|
95
|
+
throw new Error("resolveHeaderParamsTypedName is only available in legacy mode (legacy: true). Use resolveParamTypedName per individual parameter instead.");
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/resolvers/resolverTsLegacy.ts
|
|
101
|
+
/**
|
|
102
|
+
* Legacy resolver for `@kubb/plugin-ts` that reproduces the naming conventions
|
|
103
|
+
* used before the v2 resolver refactor. Enable via `legacy: true` in plugin options.
|
|
104
|
+
*
|
|
105
|
+
* Key differences from the default resolver:
|
|
106
|
+
* - Response status types: `<OperationId><StatusCode>` (e.g. `CreatePets201`) instead of `<OperationId>Status201`
|
|
107
|
+
* - Default/error responses: `<OperationId>Error` instead of `<OperationId>StatusDefault`
|
|
108
|
+
* - Request body: `<OperationId>MutationRequest` (non-GET) / `<OperationId>QueryRequest` (GET)
|
|
109
|
+
* - Combined responses type: `<OperationId>Mutation` / `<OperationId>Query`
|
|
110
|
+
* - Response union: `<OperationId>MutationResponse` / `<OperationId>QueryResponse`
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
115
|
+
*
|
|
116
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 201) // → 'CreatePets201'
|
|
117
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 'default') // → 'CreatePetsError'
|
|
118
|
+
* resolverTsLegacy.resolveDataTypedName(node) // → 'CreatePetsMutationRequest' (POST)
|
|
119
|
+
* resolverTsLegacy.resolveResponsesTypedName(node) // → 'CreatePetsMutation' (POST)
|
|
120
|
+
* resolverTsLegacy.resolveResponseTypedName(node) // → 'CreatePetsMutationResponse' (POST)
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
const resolverTsLegacy = (0, _kubb_core.defineResolver)(() => {
|
|
124
|
+
return {
|
|
125
|
+
...resolverTs,
|
|
126
|
+
name: "legacy",
|
|
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.default(node.operationId, "function")}${suffix}`;
|
|
146
|
+
},
|
|
147
|
+
resolveResponsesTypedName(node) {
|
|
148
|
+
const suffix = node.method === "GET" ? "Query" : "Mutation";
|
|
149
|
+
return `${this.default(node.operationId, "type")}${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
|
+
Object.defineProperty(exports, "resolverTs", {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
get: function() {
|
|
183
|
+
return resolverTs;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(exports, "resolverTsLegacy", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function() {
|
|
189
|
+
return resolverTsLegacy;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
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":"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"}
|
|
@@ -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,13 +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;
|
|
327
|
+
/**
|
|
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.
|
|
331
|
+
*/
|
|
332
|
+
baseResolver: ResolverTs;
|
|
333
|
+
transformers: Array<Visitor>;
|
|
310
334
|
};
|
|
311
335
|
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>;
|
|
312
336
|
//#endregion
|
|
313
337
|
export { PluginTs as n, ResolverTs as r, Options as t };
|
|
314
|
-
//# 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",
|
|
@@ -39,6 +39,10 @@
|
|
|
39
39
|
"import": "./dist/generators.js",
|
|
40
40
|
"require": "./dist/generators.cjs"
|
|
41
41
|
},
|
|
42
|
+
"./resolvers": {
|
|
43
|
+
"import": "./dist/resolvers.js",
|
|
44
|
+
"require": "./dist/resolvers.cjs"
|
|
45
|
+
},
|
|
42
46
|
"./package.json": "./package.json"
|
|
43
47
|
},
|
|
44
48
|
"types": "./dist/index.d.ts",
|
|
@@ -49,6 +53,9 @@
|
|
|
49
53
|
],
|
|
50
54
|
"generators": [
|
|
51
55
|
"./dist/generators.d.ts"
|
|
56
|
+
],
|
|
57
|
+
"resolvers": [
|
|
58
|
+
"./dist/resolvers.d.ts"
|
|
52
59
|
]
|
|
53
60
|
}
|
|
54
61
|
},
|
|
@@ -71,10 +78,10 @@
|
|
|
71
78
|
"@kubb/react-fabric": "0.14.0",
|
|
72
79
|
"remeda": "^2.33.6",
|
|
73
80
|
"typescript": "5.9.3",
|
|
74
|
-
"@kubb/
|
|
75
|
-
"@kubb/
|
|
76
|
-
"@kubb/
|
|
77
|
-
"@kubb/
|
|
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"
|
|
78
85
|
},
|
|
79
86
|
"peerDependencies": {
|
|
80
87
|
"@kubb/react-fabric": "0.14.0"
|
package/src/components/Type.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyParamsCasing } from '@kubb/ast'
|
|
1
|
+
import { applyParamsCasing, composeTransformers, transform } from '@kubb/ast'
|
|
2
2
|
import type { SchemaNode } from '@kubb/ast/types'
|
|
3
3
|
import { defineGenerator } from '@kubb/core'
|
|
4
4
|
import { useKubb } from '@kubb/core/hooks'
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
buildGroupedParamsSchema,
|
|
12
12
|
buildLegacyResponsesSchemaNode,
|
|
13
13
|
buildLegacyResponseUnionSchemaNode,
|
|
14
|
+
buildParamsSchema,
|
|
14
15
|
buildResponsesSchemaNode,
|
|
15
16
|
buildResponseUnionSchemaNode,
|
|
16
17
|
nameUnnamedEnums,
|
|
@@ -20,7 +21,7 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
20
21
|
name: 'typescript',
|
|
21
22
|
type: 'react',
|
|
22
23
|
Operation({ node, adapter, options }) {
|
|
23
|
-
const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, resolver, legacy } = options
|
|
24
|
+
const { enumType, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, resolver, baseResolver, legacy, transformers = [] } = options
|
|
24
25
|
const { mode, getFile, resolveBanner, resolveFooter } = useKubb<PluginTs>()
|
|
25
26
|
|
|
26
27
|
const file = getFile({
|
|
@@ -50,7 +51,9 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
50
51
|
return null
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
const
|
|
54
|
+
const transformedNode = transform(schemaNode, composeTransformers(...transformers))
|
|
55
|
+
|
|
56
|
+
const imports = adapter.getImports(transformedNode, (schemaName) => ({
|
|
54
57
|
name: resolver.default(schemaName, 'type'),
|
|
55
58
|
path: getFile({ name: schemaName, extname: '.ts', mode }).path,
|
|
56
59
|
}))
|
|
@@ -62,7 +65,7 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
62
65
|
<Type
|
|
63
66
|
name={name}
|
|
64
67
|
typedName={typedName}
|
|
65
|
-
node={
|
|
68
|
+
node={transformedNode}
|
|
66
69
|
description={description}
|
|
67
70
|
enumType={enumType}
|
|
68
71
|
enumKeyCasing={enumKeyCasing}
|
|
@@ -71,6 +74,7 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
71
74
|
syntaxType={syntaxType}
|
|
72
75
|
resolver={resolver}
|
|
73
76
|
keysToOmit={keysToOmit}
|
|
77
|
+
legacy={legacy}
|
|
74
78
|
/>
|
|
75
79
|
</>
|
|
76
80
|
)
|
|
@@ -79,9 +83,10 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
79
83
|
const responseTypes = legacy
|
|
80
84
|
? node.responses.map((res) => {
|
|
81
85
|
const responseName = resolver.resolveResponseStatusName(node, res.statusCode)
|
|
86
|
+
const baseResponseName = baseResolver.resolveResponseStatusName(node, res.statusCode)
|
|
82
87
|
|
|
83
88
|
return renderSchemaType({
|
|
84
|
-
node: res.schema ? nameUnnamedEnums(res.schema,
|
|
89
|
+
node: res.schema ? nameUnnamedEnums(res.schema, baseResponseName) : res.schema,
|
|
85
90
|
name: responseName,
|
|
86
91
|
typedName: resolver.resolveResponseStatusTypedName(node, res.statusCode),
|
|
87
92
|
description: res.description,
|
|
@@ -100,10 +105,10 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
100
105
|
|
|
101
106
|
const requestType = node.requestBody?.schema
|
|
102
107
|
? renderSchemaType({
|
|
103
|
-
node: legacy ? nameUnnamedEnums(node.requestBody.schema,
|
|
108
|
+
node: legacy ? nameUnnamedEnums(node.requestBody.schema, baseResolver.resolveDataName(node)) : node.requestBody.schema,
|
|
104
109
|
name: resolver.resolveDataName(node),
|
|
105
110
|
typedName: resolver.resolveDataTypedName(node),
|
|
106
|
-
description: node.requestBody.schema.description,
|
|
111
|
+
description: node.requestBody.description ?? node.requestBody.schema.description,
|
|
107
112
|
keysToOmit: node.requestBody.keysToOmit,
|
|
108
113
|
})
|
|
109
114
|
: null
|
|
@@ -116,21 +121,21 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
116
121
|
const legacyParamTypes = [
|
|
117
122
|
pathParams.length > 0
|
|
118
123
|
? renderSchemaType({
|
|
119
|
-
node: buildGroupedParamsSchema({ params: pathParams, parentName:
|
|
124
|
+
node: buildGroupedParamsSchema({ params: pathParams, parentName: baseResolver.resolvePathParamsName!(node) }),
|
|
120
125
|
name: resolver.resolvePathParamsName!(node),
|
|
121
126
|
typedName: resolver.resolvePathParamsTypedName!(node),
|
|
122
127
|
})
|
|
123
128
|
: null,
|
|
124
129
|
queryParams.length > 0
|
|
125
130
|
? renderSchemaType({
|
|
126
|
-
node: buildGroupedParamsSchema({ params: queryParams, parentName:
|
|
131
|
+
node: buildGroupedParamsSchema({ params: queryParams, parentName: baseResolver.resolveQueryParamsName!(node) }),
|
|
127
132
|
name: resolver.resolveQueryParamsName!(node),
|
|
128
133
|
typedName: resolver.resolveQueryParamsTypedName!(node),
|
|
129
134
|
})
|
|
130
135
|
: null,
|
|
131
136
|
headerParams.length > 0
|
|
132
137
|
? renderSchemaType({
|
|
133
|
-
node: buildGroupedParamsSchema({ params: headerParams, parentName:
|
|
138
|
+
node: buildGroupedParamsSchema({ params: headerParams, parentName: baseResolver.resolveHeaderParamsName!(node) }),
|
|
134
139
|
name: resolver.resolveHeaderParamsName!(node),
|
|
135
140
|
typedName: resolver.resolveHeaderParamsTypedName!(node),
|
|
136
141
|
})
|
|
@@ -154,8 +159,8 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
154
159
|
{legacyParamTypes}
|
|
155
160
|
{responseTypes}
|
|
156
161
|
{requestType}
|
|
157
|
-
{legacyResponsesType}
|
|
158
162
|
{legacyResponseType}
|
|
163
|
+
{legacyResponsesType}
|
|
159
164
|
</File>
|
|
160
165
|
)
|
|
161
166
|
}
|
|
@@ -168,6 +173,16 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
168
173
|
}),
|
|
169
174
|
)
|
|
170
175
|
|
|
176
|
+
const queryParamsList = params.filter((p) => p.in === 'query')
|
|
177
|
+
const queryParamsType =
|
|
178
|
+
queryParamsList.length > 0
|
|
179
|
+
? renderSchemaType({
|
|
180
|
+
node: buildParamsSchema({ params: queryParamsList, node, resolver }),
|
|
181
|
+
name: resolver.resolveQueryParamsName!(node),
|
|
182
|
+
typedName: resolver.resolveQueryParamsTypedName!(node),
|
|
183
|
+
})
|
|
184
|
+
: null
|
|
185
|
+
|
|
171
186
|
const dataType = renderSchemaType({
|
|
172
187
|
node: buildDataSchemaNode({ node: { ...node, parameters: params }, resolver }),
|
|
173
188
|
name: resolver.resolveRequestConfigName(node),
|
|
@@ -190,6 +205,7 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
190
205
|
return (
|
|
191
206
|
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={resolveBanner()} footer={resolveFooter()}>
|
|
192
207
|
{paramTypes}
|
|
208
|
+
{queryParamsType}
|
|
193
209
|
{responseTypes}
|
|
194
210
|
{requestType}
|
|
195
211
|
{dataType}
|
|
@@ -199,14 +215,16 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
199
215
|
)
|
|
200
216
|
},
|
|
201
217
|
Schema({ node, adapter, options }) {
|
|
202
|
-
const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, resolver } = options
|
|
218
|
+
const { enumType, enumKeyCasing, syntaxType, optionalType, arrayType, resolver, legacy, transformers = [] } = options
|
|
203
219
|
const { mode, getFile, resolveBanner, resolveFooter } = useKubb<PluginTs>()
|
|
204
220
|
|
|
205
221
|
if (!node.name) {
|
|
206
222
|
return
|
|
207
223
|
}
|
|
208
224
|
|
|
209
|
-
const
|
|
225
|
+
const transformedNode = transform(node, composeTransformers(...transformers))
|
|
226
|
+
|
|
227
|
+
const imports = adapter.getImports(transformedNode, (schemaName) => ({
|
|
210
228
|
name: resolver.default(schemaName, 'type'),
|
|
211
229
|
path: getFile({ name: schemaName, extname: '.ts', mode }).path,
|
|
212
230
|
}))
|
|
@@ -230,13 +248,14 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
230
248
|
<Type
|
|
231
249
|
name={type.name}
|
|
232
250
|
typedName={type.typedName}
|
|
233
|
-
node={
|
|
251
|
+
node={transformedNode}
|
|
234
252
|
enumType={enumType}
|
|
235
253
|
enumKeyCasing={enumKeyCasing}
|
|
236
254
|
optionalType={optionalType}
|
|
237
255
|
arrayType={arrayType}
|
|
238
256
|
syntaxType={syntaxType}
|
|
239
257
|
resolver={resolver}
|
|
258
|
+
legacy={legacy}
|
|
240
259
|
/>
|
|
241
260
|
</File>
|
|
242
261
|
)
|
package/src/generators/utils.ts
CHANGED
|
@@ -21,10 +21,10 @@ export function buildParamsSchema({ params, node, resolver }: BuildParamsSchemaO
|
|
|
21
21
|
properties: params.map((param) =>
|
|
22
22
|
createProperty({
|
|
23
23
|
name: param.name,
|
|
24
|
+
required: param.required,
|
|
24
25
|
schema: createSchema({
|
|
25
26
|
type: 'ref',
|
|
26
27
|
name: resolver.resolveParamName(node, param),
|
|
27
|
-
optional: !param.required,
|
|
28
28
|
}),
|
|
29
29
|
}),
|
|
30
30
|
),
|
|
@@ -65,7 +65,8 @@ export function buildDataSchemaNode({ node, resolver }: BuildOperationSchemaOpti
|
|
|
65
65
|
}),
|
|
66
66
|
createProperty({
|
|
67
67
|
name: 'pathParams',
|
|
68
|
-
|
|
68
|
+
required: pathParams.length > 0,
|
|
69
|
+
schema: pathParams.length > 0 ? buildParamsSchema({ params: pathParams, node, resolver }) : createSchema({ type: 'never' }),
|
|
69
70
|
}),
|
|
70
71
|
createProperty({
|
|
71
72
|
name: 'queryParams',
|
|
@@ -83,6 +84,7 @@ export function buildDataSchemaNode({ node, resolver }: BuildOperationSchemaOpti
|
|
|
83
84
|
}),
|
|
84
85
|
createProperty({
|
|
85
86
|
name: 'url',
|
|
87
|
+
required: true,
|
|
86
88
|
schema: createSchema({ type: 'url', path: node.path }),
|
|
87
89
|
}),
|
|
88
90
|
],
|
|
@@ -104,6 +106,7 @@ export function buildResponsesSchemaNode({ node, resolver }: BuildOperationSchem
|
|
|
104
106
|
properties: node.responses.map((res) =>
|
|
105
107
|
createProperty({
|
|
106
108
|
name: String(res.statusCode),
|
|
109
|
+
required: true,
|
|
107
110
|
schema: createSchema({
|
|
108
111
|
type: 'ref',
|
|
109
112
|
name: resolver.resolveResponseStatusTypedName(node, res.statusCode),
|
|
@@ -154,13 +157,13 @@ export function buildGroupedParamsSchema({ params, parentName }: BuildGroupedPar
|
|
|
154
157
|
return createSchema({
|
|
155
158
|
type: 'object',
|
|
156
159
|
properties: params.map((param) => {
|
|
157
|
-
let schema =
|
|
158
|
-
// Name unnamed enum properties so they are emitted as enum declarations
|
|
160
|
+
let schema = param.schema
|
|
159
161
|
if (narrowSchema(schema, 'enum') && !schema.name && parentName) {
|
|
160
162
|
schema = { ...schema, name: pascalCase([parentName, param.name, 'enum'].join(' ')) }
|
|
161
163
|
}
|
|
162
164
|
return createProperty({
|
|
163
165
|
name: param.name,
|
|
166
|
+
required: param.required,
|
|
164
167
|
schema,
|
|
165
168
|
})
|
|
166
169
|
}),
|
|
@@ -169,7 +172,7 @@ export function buildGroupedParamsSchema({ params, parentName }: BuildGroupedPar
|
|
|
169
172
|
|
|
170
173
|
/**
|
|
171
174
|
* Builds the legacy wrapper `ObjectSchemaNode` for `<OperationId>Mutation` / `<OperationId>Query`.
|
|
172
|
-
* Structure: `{ Response, Request
|
|
175
|
+
* Structure: `{ Response, Request?, QueryParams?, PathParams?, HeaderParams?, Errors }`.
|
|
173
176
|
* Mirrors the v4 naming convention where this type acts as a namespace for the operation's shapes.
|
|
174
177
|
*
|
|
175
178
|
* @deprecated Legacy only — will be removed in v6.
|
|
@@ -202,20 +205,24 @@ export function buildLegacyResponsesSchemaNode({ node, resolver }: BuildOperatio
|
|
|
202
205
|
})
|
|
203
206
|
: createSchema({ type: 'any' })
|
|
204
207
|
|
|
205
|
-
const properties = [createProperty({ name: 'Response', schema: responseSchema })]
|
|
208
|
+
const properties = [createProperty({ name: 'Response', required: true, schema: responseSchema })]
|
|
206
209
|
|
|
207
210
|
if (!isGet && node.requestBody?.schema) {
|
|
208
211
|
properties.push(
|
|
209
212
|
createProperty({
|
|
210
213
|
name: 'Request',
|
|
214
|
+
required: true,
|
|
211
215
|
schema: createSchema({ type: 'ref', name: resolver.resolveDataTypedName(node) }),
|
|
212
216
|
}),
|
|
213
217
|
)
|
|
214
|
-
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (node.parameters.some((p) => p.in === 'query') && resolver.resolveQueryParamsTypedName) {
|
|
215
221
|
properties.push(
|
|
216
222
|
createProperty({
|
|
217
223
|
name: 'QueryParams',
|
|
218
|
-
|
|
224
|
+
required: true,
|
|
225
|
+
schema: createSchema({ type: 'ref', name: resolver.resolveQueryParamsTypedName(node) }),
|
|
219
226
|
}),
|
|
220
227
|
)
|
|
221
228
|
}
|
|
@@ -224,6 +231,7 @@ export function buildLegacyResponsesSchemaNode({ node, resolver }: BuildOperatio
|
|
|
224
231
|
properties.push(
|
|
225
232
|
createProperty({
|
|
226
233
|
name: 'PathParams',
|
|
234
|
+
required: true,
|
|
227
235
|
schema: createSchema({ type: 'ref', name: resolver.resolvePathParamsTypedName(node) }),
|
|
228
236
|
}),
|
|
229
237
|
)
|
|
@@ -233,12 +241,13 @@ export function buildLegacyResponsesSchemaNode({ node, resolver }: BuildOperatio
|
|
|
233
241
|
properties.push(
|
|
234
242
|
createProperty({
|
|
235
243
|
name: 'HeaderParams',
|
|
244
|
+
required: true,
|
|
236
245
|
schema: createSchema({ type: 'ref', name: resolver.resolveHeaderParamsTypedName(node) }),
|
|
237
246
|
}),
|
|
238
247
|
)
|
|
239
248
|
}
|
|
240
249
|
|
|
241
|
-
properties.push(createProperty({ name: 'Errors', schema: errorsSchema }))
|
|
250
|
+
properties.push(createProperty({ name: 'Errors', required: true, schema: errorsSchema }))
|
|
242
251
|
|
|
243
252
|
return createSchema({ type: 'object', properties })
|
|
244
253
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { pluginTs, pluginTsName } from './plugin.ts'
|
|
2
|
-
export { resolverTs, resolverTsLegacy } from './
|
|
3
|
-
export type { PluginTs } from './types.ts'
|
|
2
|
+
export { resolverTs, resolverTsLegacy } from './resolvers/index.ts'
|
|
3
|
+
export type { PluginTs, ResolverTs } from './types.ts'
|