@kubb/plugin-ts 5.0.0-alpha.22 → 5.0.0-alpha.23
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/index.cjs +1668 -49
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +466 -4
- package/dist/index.js +1641 -52
- package/dist/index.js.map +1 -1
- package/package.json +3 -42
- package/src/components/Enum.tsx +1 -1
- package/src/components/Type.tsx +3 -5
- package/src/generators/typeGenerator.tsx +10 -22
- package/src/generators/typeGeneratorLegacy.tsx +28 -38
- package/src/index.ts +13 -1
- package/src/plugin.ts +42 -23
- package/src/presets.ts +16 -34
- package/src/printers/functionPrinter.ts +194 -0
- package/src/printers/printerTs.ts +6 -6
- package/src/resolvers/resolverTs.ts +10 -47
- package/src/resolvers/resolverTsLegacy.ts +4 -31
- package/src/types.ts +85 -225
- package/src/utils.ts +103 -0
- package/dist/Type-Bf8raoQX.cjs +0 -124
- package/dist/Type-Bf8raoQX.cjs.map +0 -1
- package/dist/Type-BpXxT4l_.js +0 -113
- package/dist/Type-BpXxT4l_.js.map +0 -1
- package/dist/builderTs-COUg3xtQ.cjs +0 -135
- package/dist/builderTs-COUg3xtQ.cjs.map +0 -1
- package/dist/builderTs-DPpkJKd1.js +0 -131
- package/dist/builderTs-DPpkJKd1.js.map +0 -1
- package/dist/builders.cjs +0 -3
- package/dist/builders.d.ts +0 -23
- package/dist/builders.js +0 -2
- package/dist/casing-BJHFg-zZ.js +0 -84
- package/dist/casing-BJHFg-zZ.js.map +0 -1
- package/dist/casing-DHfdqpLi.cjs +0 -107
- package/dist/casing-DHfdqpLi.cjs.map +0 -1
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/components.cjs +0 -4
- package/dist/components.d.ts +0 -71
- package/dist/components.js +0 -2
- package/dist/generators-DFDut8o-.js +0 -555
- package/dist/generators-DFDut8o-.js.map +0 -1
- package/dist/generators-DKd7MYbx.cjs +0 -567
- package/dist/generators-DKd7MYbx.cjs.map +0 -1
- package/dist/generators.cjs +0 -4
- package/dist/generators.d.ts +0 -12
- package/dist/generators.js +0 -2
- package/dist/printerTs-BcHudagv.cjs +0 -594
- package/dist/printerTs-BcHudagv.cjs.map +0 -1
- package/dist/printerTs-CMBCOuqd.js +0 -558
- package/dist/printerTs-CMBCOuqd.js.map +0 -1
- package/dist/printers.cjs +0 -3
- package/dist/printers.d.ts +0 -81
- package/dist/printers.js +0 -2
- package/dist/resolverTsLegacy-CPiqqsO6.js +0 -185
- package/dist/resolverTsLegacy-CPiqqsO6.js.map +0 -1
- package/dist/resolverTsLegacy-CuR9XbKk.cjs +0 -196
- package/dist/resolverTsLegacy-CuR9XbKk.cjs.map +0 -1
- package/dist/resolvers.cjs +0 -4
- package/dist/resolvers.d.ts +0 -52
- package/dist/resolvers.js +0 -2
- package/dist/types-CRtcZOCz.d.ts +0 -374
- package/src/builders/builderTs.ts +0 -107
- package/src/builders/index.ts +0 -1
- package/src/components/index.ts +0 -2
- package/src/generators/index.ts +0 -2
- package/src/printers/index.ts +0 -1
- package/src/resolvers/index.ts +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,303 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { OperationParamsResolver } from "@kubb/ast";
|
|
4
|
+
import * as _$_kubb_core0 from "@kubb/core";
|
|
5
|
+
import { CompatibilityPreset, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, PrinterFactoryOptions, ResolvePathOptions, Resolver, UserGroup } from "@kubb/core";
|
|
6
|
+
import { EnumSchemaNode, FunctionNode, OperationNode, ParameterNode, SchemaNode, StatusCode, Visitor } from "@kubb/ast/types";
|
|
7
|
+
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
4
8
|
|
|
9
|
+
//#region src/types.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* The concrete resolver type for `@kubb/plugin-ts`.
|
|
12
|
+
* Extends the base `Resolver` (which provides `default` and `resolveOptions`) with
|
|
13
|
+
* plugin-specific naming helpers for operations, parameters, responses, and schemas.
|
|
14
|
+
*/
|
|
15
|
+
type ResolverTs = Resolver & OperationParamsResolver & {
|
|
16
|
+
/**
|
|
17
|
+
* Resolves the name for a given raw name (equivalent to `default(name, 'function')`).
|
|
18
|
+
* Since TypeScript only emits types, this is the canonical naming method.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* resolver.resolveName('list pets status 200') // → 'ListPetsStatus200'
|
|
22
|
+
*/
|
|
23
|
+
resolveName(name: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the file/path name for a given identifier using PascalCase.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* resolver.resolvePathName('list pets', 'file') // → 'ListPets'
|
|
29
|
+
*/
|
|
30
|
+
resolvePathName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string; /** Resolves the request body type name (required on ResolverTs). */
|
|
31
|
+
resolveDataName(node: OperationNode): string;
|
|
32
|
+
/**
|
|
33
|
+
* Resolves the name for an operation response by status code.
|
|
34
|
+
* Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* resolver.resolveResponseStatusName(node, 200) // → 'ListPetsStatus200'
|
|
38
|
+
*/
|
|
39
|
+
resolveResponseStatusName(node: OperationNode, statusCode: StatusCode): string;
|
|
40
|
+
/**
|
|
41
|
+
* Resolves the name for an operation's request config (`RequestConfig`).
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* resolver.resolveRequestConfigName(node) // → 'ListPetsRequestConfig'
|
|
45
|
+
*/
|
|
46
|
+
resolveRequestConfigName(node: OperationNode): string;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves the name for the collection of all operation responses (`Responses`).
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* resolver.resolveResponsesName(node) // → 'ListPetsResponses'
|
|
52
|
+
*/
|
|
53
|
+
resolveResponsesName(node: OperationNode): string;
|
|
54
|
+
/**
|
|
55
|
+
* Resolves the name for the union of all operation responses (`Response`).
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* resolver.resolveResponseName(node) // → 'ListPetsResponse'
|
|
59
|
+
*/
|
|
60
|
+
resolveResponseName(node: OperationNode): string;
|
|
61
|
+
/**
|
|
62
|
+
* Resolves the TypeScript type alias name for an enum schema's key variant.
|
|
63
|
+
* Appends `enumTypeSuffix` (default `'Key'`) after applying the default naming convention.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* resolver.resolveEnumKeyName(node, 'Key') // → 'PetStatusKey'
|
|
67
|
+
* resolver.resolveEnumKeyName(node, 'Value') // → 'PetStatusValue'
|
|
68
|
+
* resolver.resolveEnumKeyName(node, '') // → 'PetStatus'
|
|
69
|
+
*/
|
|
70
|
+
resolveEnumKeyName(node: SchemaNode, enumTypeSuffix: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Resolves the name for an operation's grouped path parameters type.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* resolver.resolvePathParamsName(node, param) // → 'GetPetByIdPathParams'
|
|
76
|
+
*/
|
|
77
|
+
resolvePathParamsName(node: OperationNode, param: ParameterNode): string;
|
|
78
|
+
/**
|
|
79
|
+
* Resolves the name for an operation's grouped query parameters type.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'
|
|
83
|
+
*/
|
|
84
|
+
resolveQueryParamsName(node: OperationNode, param: ParameterNode): string;
|
|
85
|
+
/**
|
|
86
|
+
* Resolves the name for an operation's grouped header parameters type.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'
|
|
90
|
+
*/
|
|
91
|
+
resolveHeaderParamsName(node: OperationNode, param: ParameterNode): string;
|
|
92
|
+
};
|
|
93
|
+
type Options = {
|
|
94
|
+
/**
|
|
95
|
+
* Specify the export location for the files and define the behavior of the output
|
|
96
|
+
* @default { path: 'types', barrelType: 'named' }
|
|
97
|
+
*/
|
|
98
|
+
output?: Output;
|
|
99
|
+
/**
|
|
100
|
+
* Define which contentType should be used.
|
|
101
|
+
* By default, uses the first valid JSON media type.
|
|
102
|
+
*/
|
|
103
|
+
contentType?: 'application/json' | (string & {});
|
|
104
|
+
/**
|
|
105
|
+
* Group the clients based on the provided name.
|
|
106
|
+
*/
|
|
107
|
+
group?: UserGroup;
|
|
108
|
+
/**
|
|
109
|
+
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
110
|
+
*/
|
|
111
|
+
exclude?: Array<Exclude>;
|
|
112
|
+
/**
|
|
113
|
+
* Array containing include parameters to include tags/operations/methods/paths.
|
|
114
|
+
*/
|
|
115
|
+
include?: Array<Include>;
|
|
116
|
+
/**
|
|
117
|
+
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
118
|
+
*/
|
|
119
|
+
override?: Array<Override<ResolvedOptions>>;
|
|
120
|
+
/**
|
|
121
|
+
* Choose to use enum, asConst, asPascalConst, constEnum, literal, or inlineLiteral for enums.
|
|
122
|
+
* - 'enum' generates TypeScript enum declarations.
|
|
123
|
+
* - 'asConst' generates const objects with camelCase names and as const assertion.
|
|
124
|
+
* - 'asPascalConst' generates const objects with PascalCase names and as const assertion.
|
|
125
|
+
* - 'constEnum' generates TypeScript const enum declarations.
|
|
126
|
+
* - 'literal' generates literal union types.
|
|
127
|
+
* - 'inlineLiteral' inline enum values directly into the type (default in v5).
|
|
128
|
+
* @default 'asConst'
|
|
129
|
+
* @note In Kubb v5, 'inlineLiteral' becomes the default.
|
|
130
|
+
*/
|
|
131
|
+
enumType?: 'enum' | 'asConst' | 'asPascalConst' | 'constEnum' | 'literal' | 'inlineLiteral';
|
|
132
|
+
/**
|
|
133
|
+
* Suffix appended to the generated type alias name when `enumType` is `asConst` or `asPascalConst`.
|
|
134
|
+
*
|
|
135
|
+
* Only affects the type alias — the const object name is unchanged.
|
|
136
|
+
*
|
|
137
|
+
* @default 'Key'
|
|
138
|
+
* @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
|
|
139
|
+
*/
|
|
140
|
+
enumTypeSuffix?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Choose the casing for enum key names.
|
|
143
|
+
* - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
|
|
144
|
+
* - 'snakeCase' generates keys in snake_case format.
|
|
145
|
+
* - 'pascalCase' generates keys in PascalCase format.
|
|
146
|
+
* - 'camelCase' generates keys in camelCase format.
|
|
147
|
+
* - 'none' uses the enum value as-is without transformation.
|
|
148
|
+
* @default 'none'
|
|
149
|
+
*/
|
|
150
|
+
enumKeyCasing?: 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none';
|
|
151
|
+
/**
|
|
152
|
+
* Switch between type or interface for creating TypeScript types.
|
|
153
|
+
* - 'type' generates type alias declarations.
|
|
154
|
+
* - 'interface' generates interface declarations.
|
|
155
|
+
* @default 'type'
|
|
156
|
+
*/
|
|
157
|
+
syntaxType?: 'type' | 'interface';
|
|
158
|
+
/**
|
|
159
|
+
* Choose what to use as mode for an optional value.
|
|
160
|
+
* - 'questionToken' marks the property as optional with ? (e.g., type?: string).
|
|
161
|
+
* - 'undefined' adds undefined to the type union (e.g., type: string | undefined).
|
|
162
|
+
* - 'questionTokenAndUndefined' combines both approaches (e.g., type?: string | undefined).
|
|
163
|
+
* @default 'questionToken'
|
|
164
|
+
*/
|
|
165
|
+
optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
|
|
166
|
+
/**
|
|
167
|
+
* Choose between Array<string> or string[] for array types.
|
|
168
|
+
* - 'generic' generates Array<Type> syntax.
|
|
169
|
+
* - 'array' generates Type[] syntax.
|
|
170
|
+
* @default 'array'
|
|
171
|
+
*/
|
|
172
|
+
arrayType?: 'generic' | 'array';
|
|
173
|
+
/**
|
|
174
|
+
* How to style your params, by default no casing is applied
|
|
175
|
+
* - 'camelcase' uses camelCase for pathParams, queryParams and headerParams property names
|
|
176
|
+
* @default undefined
|
|
177
|
+
* @note response types (data/body) are NOT affected by this option
|
|
178
|
+
*/
|
|
179
|
+
paramsCasing?: 'camelcase';
|
|
180
|
+
/**
|
|
181
|
+
* Define some generators next to the ts generators
|
|
182
|
+
*/
|
|
183
|
+
generators?: Array<Generator<PluginTs>>;
|
|
184
|
+
/**
|
|
185
|
+
* Apply a compatibility naming preset.
|
|
186
|
+
* Use `kubbV4` for strict v4 type-generation compatibility.
|
|
187
|
+
* You can further customize naming with `resolvers`.
|
|
188
|
+
* @default 'default'
|
|
189
|
+
*/
|
|
190
|
+
compatibilityPreset?: CompatibilityPreset;
|
|
191
|
+
/**
|
|
192
|
+
* Array of named resolvers that control naming conventions.
|
|
193
|
+
* Later entries override earlier ones (last wins).
|
|
194
|
+
* Built-in: `resolverTs` (default), `resolverTsLegacy`.
|
|
195
|
+
* @default [resolverTs]
|
|
196
|
+
*/
|
|
197
|
+
resolvers?: Array<ResolverTs>;
|
|
198
|
+
/**
|
|
199
|
+
* Array of AST visitors applied to each SchemaNode/OperationNode before printing.
|
|
200
|
+
* Uses `transform()` from `@kubb/ast` — visitors can modify, replace, or annotate nodes.
|
|
201
|
+
*
|
|
202
|
+
* @example Remove writeOnly properties from response types
|
|
203
|
+
* ```ts
|
|
204
|
+
* transformers: [{
|
|
205
|
+
* property(node) {
|
|
206
|
+
* if (node.schema.writeOnly) return undefined
|
|
207
|
+
* }
|
|
208
|
+
* }]
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @example Force all dates to plain strings
|
|
212
|
+
* ```ts
|
|
213
|
+
* transformers: [{
|
|
214
|
+
* schema(node) {
|
|
215
|
+
* if (node.type === 'date') return { ...node, type: 'string' }
|
|
216
|
+
* }
|
|
217
|
+
* }]
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
transformers?: Array<Visitor>;
|
|
221
|
+
};
|
|
222
|
+
type ResolvedOptions = {
|
|
223
|
+
output: Output;
|
|
224
|
+
group: Group | undefined;
|
|
225
|
+
enumType: NonNullable<Options['enumType']>;
|
|
226
|
+
enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>;
|
|
227
|
+
enumKeyCasing: NonNullable<Options['enumKeyCasing']>;
|
|
228
|
+
optionalType: NonNullable<Options['optionalType']>;
|
|
229
|
+
arrayType: NonNullable<Options['arrayType']>;
|
|
230
|
+
syntaxType: NonNullable<Options['syntaxType']>;
|
|
231
|
+
paramsCasing: Options['paramsCasing'];
|
|
232
|
+
transformers: Array<Visitor>;
|
|
233
|
+
};
|
|
234
|
+
type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs>;
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region src/components/Enum.d.ts
|
|
237
|
+
type Props$1 = {
|
|
238
|
+
node: EnumSchemaNode;
|
|
239
|
+
enumType: PluginTs['resolvedOptions']['enumType'];
|
|
240
|
+
enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix'];
|
|
241
|
+
enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing'];
|
|
242
|
+
resolver: ResolverTs;
|
|
243
|
+
};
|
|
244
|
+
/**
|
|
245
|
+
* Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
|
|
246
|
+
*
|
|
247
|
+
* The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
|
|
248
|
+
* valid TypeScript identifier. The resolver normalizes it; for inline enum
|
|
249
|
+
* properties the adapter already emits a PascalCase+suffix name so resolution is typically a no-op.
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* Renders the enum declaration(s) for a single named `EnumSchemaNode`.
|
|
253
|
+
*
|
|
254
|
+
* Depending on `enumType` this may emit:
|
|
255
|
+
* - A runtime object (`asConst` / `asPascalConst`) plus a `typeof` type alias
|
|
256
|
+
* - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
|
|
257
|
+
* - A union literal type alias (`literal`)
|
|
258
|
+
*
|
|
259
|
+
* The emitted `File.Source` nodes carry the resolved names so that the barrel
|
|
260
|
+
* index picks up the correct export identifiers.
|
|
261
|
+
*/
|
|
262
|
+
declare function Enum({
|
|
263
|
+
node,
|
|
264
|
+
enumType,
|
|
265
|
+
enumTypeSuffix,
|
|
266
|
+
enumKeyCasing,
|
|
267
|
+
resolver
|
|
268
|
+
}: Props$1): FabricReactNode;
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/components/Type.d.ts
|
|
271
|
+
type Props = {
|
|
272
|
+
name: string;
|
|
273
|
+
node: SchemaNode;
|
|
274
|
+
optionalType: PluginTs['resolvedOptions']['optionalType'];
|
|
275
|
+
arrayType: PluginTs['resolvedOptions']['arrayType'];
|
|
276
|
+
enumType: PluginTs['resolvedOptions']['enumType'];
|
|
277
|
+
enumTypeSuffix: PluginTs['resolvedOptions']['enumTypeSuffix'];
|
|
278
|
+
enumKeyCasing: PluginTs['resolvedOptions']['enumKeyCasing'];
|
|
279
|
+
syntaxType: PluginTs['resolvedOptions']['syntaxType'];
|
|
280
|
+
resolver: PluginTs['resolver'];
|
|
281
|
+
description?: string;
|
|
282
|
+
keysToOmit?: string[];
|
|
283
|
+
};
|
|
284
|
+
declare function Type({
|
|
285
|
+
name,
|
|
286
|
+
node,
|
|
287
|
+
keysToOmit,
|
|
288
|
+
optionalType,
|
|
289
|
+
arrayType,
|
|
290
|
+
syntaxType,
|
|
291
|
+
enumType,
|
|
292
|
+
enumTypeSuffix,
|
|
293
|
+
enumKeyCasing,
|
|
294
|
+
description,
|
|
295
|
+
resolver
|
|
296
|
+
}: Props): FabricReactNode;
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/generators/typeGenerator.d.ts
|
|
299
|
+
declare const typeGenerator: _$_kubb_core0.ReactGeneratorV2<PluginTs>;
|
|
300
|
+
//#endregion
|
|
5
301
|
//#region src/plugin.d.ts
|
|
6
302
|
/**
|
|
7
303
|
* Canonical plugin name for `@kubb/plugin-ts`, used to identify the plugin in driver lookups and warnings.
|
|
@@ -23,7 +319,173 @@ declare const pluginTsName = "plugin-ts";
|
|
|
23
319
|
* })
|
|
24
320
|
* ```
|
|
25
321
|
*/
|
|
26
|
-
declare const pluginTs: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle<PluginTs>;
|
|
322
|
+
declare const pluginTs: (options?: Options | undefined) => _$_kubb_core0.UserPluginWithLifeCycle<PluginTs>;
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region src/printers/functionPrinter.d.ts
|
|
325
|
+
type FunctionPrinterOptions = {
|
|
326
|
+
/**
|
|
327
|
+
* Rendering modes supported by `functionPrinter`.
|
|
328
|
+
*
|
|
329
|
+
* | Mode | Output example | Use case |
|
|
330
|
+
* |---------------|---------------------------------------------|---------------------------------|
|
|
331
|
+
* | `declaration` | `id: string, config: Config = {}` | Function parameter declaration |
|
|
332
|
+
* | `call` | `id, { method, url }` | Function call arguments |
|
|
333
|
+
* | `keys` | `{ id, config }` | Key names only (destructuring) |
|
|
334
|
+
* | `values` | `{ id: id, config: config }` | Key/value object entries |
|
|
335
|
+
*/
|
|
336
|
+
mode: 'declaration' | 'call' | 'keys' | 'values';
|
|
337
|
+
/**
|
|
338
|
+
* Optional transformation applied to every parameter name before printing.
|
|
339
|
+
*/
|
|
340
|
+
transformName?: (name: string) => string;
|
|
341
|
+
/**
|
|
342
|
+
* Optional transformation applied to every type string before printing.
|
|
343
|
+
*/
|
|
344
|
+
transformType?: (type: string) => string;
|
|
345
|
+
};
|
|
346
|
+
/**
|
|
347
|
+
* Default function-signature printer.
|
|
348
|
+
* Covers the four standard output modes used across Kubb plugins.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* const printer = functionPrinter({ mode: 'declaration' })
|
|
353
|
+
*
|
|
354
|
+
* const sig = createFunctionParameters({
|
|
355
|
+
* params: [
|
|
356
|
+
* createFunctionParameter({ name: 'petId', type: 'string', optional: false }),
|
|
357
|
+
* createFunctionParameter({ name: 'config', type: 'Config', optional: false, default: '{}' }),
|
|
358
|
+
* ],
|
|
359
|
+
* })
|
|
360
|
+
*
|
|
361
|
+
* printer.print(sig) // → "petId: string, config: Config = {}"
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
|
|
365
|
+
name: "functionParameters";
|
|
366
|
+
options: FunctionPrinterOptions;
|
|
367
|
+
transform: (node: FunctionNode) => string | null | undefined;
|
|
368
|
+
print: (node: FunctionNode) => string | null | undefined;
|
|
369
|
+
};
|
|
370
|
+
//#endregion
|
|
371
|
+
//#region src/printers/printerTs.d.ts
|
|
372
|
+
type TsOptions = {
|
|
373
|
+
/**
|
|
374
|
+
* @default `'questionToken'`
|
|
375
|
+
*/
|
|
376
|
+
optionalType: PluginTs['resolvedOptions']['optionalType'];
|
|
377
|
+
/**
|
|
378
|
+
* @default `'array'`
|
|
379
|
+
*/
|
|
380
|
+
arrayType: PluginTs['resolvedOptions']['arrayType'];
|
|
381
|
+
/**
|
|
382
|
+
* @default `'inlineLiteral'`
|
|
383
|
+
*/
|
|
384
|
+
enumType: PluginTs['resolvedOptions']['enumType'];
|
|
385
|
+
/**
|
|
386
|
+
* Suffix appended to the generated type alias name when `enumType` is `asConst` or `asPascalConst`.
|
|
387
|
+
*
|
|
388
|
+
* @default `'Key'`
|
|
389
|
+
*/
|
|
390
|
+
enumTypeSuffix?: PluginTs['resolvedOptions']['enumTypeSuffix'];
|
|
391
|
+
/**
|
|
392
|
+
* Controls whether a `type` alias or `interface` declaration is emitted.
|
|
393
|
+
* @default `'type'`
|
|
394
|
+
*/
|
|
395
|
+
syntaxType?: PluginTs['resolvedOptions']['syntaxType'];
|
|
396
|
+
/**
|
|
397
|
+
* When set, `printer.print(node)` produces a full `type Name = …` declaration.
|
|
398
|
+
* When omitted, `printer.print(node)` returns the raw type node.
|
|
399
|
+
*/
|
|
400
|
+
name?: string;
|
|
401
|
+
/**
|
|
402
|
+
* JSDoc `@description` comment added to the generated type or interface declaration.
|
|
403
|
+
*/
|
|
404
|
+
description?: string;
|
|
405
|
+
/**
|
|
406
|
+
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
407
|
+
* Forces type-alias syntax even when `syntaxType` is `'interface'`.
|
|
408
|
+
*/
|
|
409
|
+
keysToOmit?: Array<string>;
|
|
410
|
+
/**
|
|
411
|
+
* Resolver used to transform raw schema names into valid TypeScript identifiers.
|
|
412
|
+
*/
|
|
413
|
+
resolver: ResolverTs;
|
|
414
|
+
};
|
|
415
|
+
/**
|
|
416
|
+
* TypeScript printer factory options: maps `SchemaNode` → `ts.TypeNode` (raw) or `ts.Node` (full declaration).
|
|
417
|
+
*/
|
|
418
|
+
type TsPrinter = PrinterFactoryOptions<'typescript', TsOptions, ts.TypeNode, string>;
|
|
419
|
+
/**
|
|
420
|
+
* TypeScript type printer built with `definePrinter`.
|
|
421
|
+
*
|
|
422
|
+
* Converts a `SchemaNode` AST node into a TypeScript AST node:
|
|
423
|
+
* - **`printer.print(node)`** — when `options.typeName` is set, returns a full
|
|
424
|
+
* `type Name = …` or `interface Name { … }` declaration (`ts.Node`).
|
|
425
|
+
* Without `typeName`, returns the raw `ts.TypeNode` for the schema.
|
|
426
|
+
*
|
|
427
|
+
* Dispatches on `node.type` to the appropriate handler in `nodes`. Options are closed
|
|
428
|
+
* over per printer instance, so each call to `printerTs(options)` produces an independent printer.
|
|
429
|
+
*
|
|
430
|
+
* @example Raw type node (no `typeName`)
|
|
431
|
+
* ```ts
|
|
432
|
+
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral' })
|
|
433
|
+
* const typeNode = printer.print(schemaNode) // ts.TypeNode
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* @example Full declaration (with `typeName`)
|
|
437
|
+
* ```ts
|
|
438
|
+
* const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enumType: 'inlineLiteral', typeName: 'MyType' })
|
|
439
|
+
* const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
|
|
440
|
+
* ```
|
|
441
|
+
*/
|
|
442
|
+
declare const printerTs: (options?: TsOptions | undefined) => _$_kubb_core0.Printer<TsPrinter>;
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/resolvers/resolverTs.d.ts
|
|
445
|
+
/**
|
|
446
|
+
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
447
|
+
* helpers used by the plugin. Import this in other plugins to resolve the exact names and
|
|
448
|
+
* paths that `plugin-ts` generates without hardcoding the conventions.
|
|
449
|
+
*
|
|
450
|
+
* The `default` method is automatically injected by `defineResolver` — it uses `camelCase`
|
|
451
|
+
* for identifiers/files and `pascalCase` for type names.
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```ts
|
|
455
|
+
* import { resolver } from '@kubb/plugin-ts'
|
|
456
|
+
*
|
|
457
|
+
* resolver.default('list pets', 'type') // → 'ListPets'
|
|
458
|
+
* resolver.resolveName('list pets status 200') // → 'ListPetsStatus200'
|
|
459
|
+
* resolver.resolvePathName('list pets', 'file') // → 'listPets'
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
declare const resolverTs: ResolverTs;
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/resolvers/resolverTsLegacy.d.ts
|
|
465
|
+
/**
|
|
466
|
+
* Legacy resolver for `@kubb/plugin-ts` that reproduces the naming conventions
|
|
467
|
+
* used before the v2 resolver refactor. Enable via `compatibilityPreset: 'kubbV4'`
|
|
468
|
+
* (or by composing this resolver manually).
|
|
469
|
+
*
|
|
470
|
+
* Key differences from the default resolver:
|
|
471
|
+
* - Response status types: `<OperationId><StatusCode>` (e.g. `CreatePets201`) instead of `<OperationId>Status201`
|
|
472
|
+
* - Default/error responses: `<OperationId>Error` instead of `<OperationId>StatusDefault`
|
|
473
|
+
* - Request body: `<OperationId>MutationRequest` (non-GET) / `<OperationId>QueryRequest` (GET)
|
|
474
|
+
* - Combined responses type: `<OperationId>Mutation` / `<OperationId>Query`
|
|
475
|
+
* - Response union: `<OperationId>MutationResponse` / `<OperationId>QueryResponse`
|
|
476
|
+
*
|
|
477
|
+
* @example
|
|
478
|
+
* ```ts
|
|
479
|
+
* import { resolverTsLegacy } from '@kubb/plugin-ts'
|
|
480
|
+
*
|
|
481
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 201) // → 'CreatePets201'
|
|
482
|
+
* resolverTsLegacy.resolveResponseStatusTypedName(node, 'default') // → 'CreatePetsError'
|
|
483
|
+
* resolverTsLegacy.resolveDataTypedName(node) // → 'CreatePetsMutationRequest' (POST)
|
|
484
|
+
* resolverTsLegacy.resolveResponsesTypedName(node) // → 'CreatePetsMutation' (POST)
|
|
485
|
+
* resolverTsLegacy.resolveResponseTypedName(node) // → 'CreatePetsMutationResponse' (POST)
|
|
486
|
+
* ```
|
|
487
|
+
*/
|
|
488
|
+
declare const resolverTsLegacy: ResolverTs;
|
|
27
489
|
//#endregion
|
|
28
|
-
export { type PluginTs, pluginTs, pluginTsName };
|
|
490
|
+
export { Enum, type PluginTs, type ResolverTs, Type, functionPrinter, pluginTs, pluginTsName, printerTs, resolverTs, resolverTsLegacy, typeGenerator };
|
|
29
491
|
//# sourceMappingURL=index.d.ts.map
|