@kubb/plugin-ts 5.0.0-alpha.9 → 5.0.0-beta.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +38 -23
  3. package/dist/index.cjs +2376 -5
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +941 -40
  6. package/dist/index.js +2321 -2
  7. package/dist/index.js.map +1 -0
  8. package/dist/rolldown-runtime-CNktS9qV.js +17 -0
  9. package/package.json +38 -74
  10. package/dist/chunk--u3MIqq1.js +0 -8
  11. package/dist/components-CRu8IKY3.js +0 -729
  12. package/dist/components-CRu8IKY3.js.map +0 -1
  13. package/dist/components-DeNDKlzf.cjs +0 -982
  14. package/dist/components-DeNDKlzf.cjs.map +0 -1
  15. package/dist/components.cjs +0 -3
  16. package/dist/components.d.ts +0 -36
  17. package/dist/components.js +0 -2
  18. package/dist/generators.cjs +0 -4
  19. package/dist/generators.d.ts +0 -509
  20. package/dist/generators.js +0 -2
  21. package/dist/plugin-BZkBwnEA.js +0 -1269
  22. package/dist/plugin-BZkBwnEA.js.map +0 -1
  23. package/dist/plugin-Bunz1oGa.cjs +0 -1322
  24. package/dist/plugin-Bunz1oGa.cjs.map +0 -1
  25. package/dist/types-mSXmB8WU.d.ts +0 -298
  26. package/src/components/Type.tsx +0 -190
  27. package/src/components/index.ts +0 -1
  28. package/src/components/v2/Enum.tsx +0 -67
  29. package/src/components/v2/Type.tsx +0 -59
  30. package/src/constants.ts +0 -29
  31. package/src/factory.ts +0 -726
  32. package/src/generators/index.ts +0 -2
  33. package/src/generators/typeGenerator.tsx +0 -468
  34. package/src/generators/v2/typeGenerator.tsx +0 -167
  35. package/src/generators/v2/utils.ts +0 -140
  36. package/src/index.ts +0 -3
  37. package/src/parser.ts +0 -389
  38. package/src/plugin.ts +0 -232
  39. package/src/printer.ts +0 -368
  40. package/src/resolverTs.ts +0 -77
  41. package/src/types.ts +0 -296
package/dist/index.d.ts CHANGED
@@ -1,49 +1,950 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { n as PluginTs, t as Options } from "./types-mSXmB8WU.js";
3
- import * as _kubb_core0 from "@kubb/core";
4
- import * as _kubb_ast_types0 from "@kubb/ast/types";
5
-
1
+ import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
2
+ import { KubbReactNode } from "kubb/jsx";
3
+ import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
4
+ import ts from "typescript";
5
+ import "@kubb/adapter-oas";
6
+ //#region src/printers/printerTs.d.ts
7
+ /**
8
+ * Partial map of node-type overrides for the TypeScript printer.
9
+ *
10
+ * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`). The function
11
+ * replaces the built-in handler for that node type. Use `this.transform` to
12
+ * recurse into nested schema nodes, and `this.options` to read printer options.
13
+ *
14
+ * @example Override the `date` handler
15
+ * ```ts
16
+ * pluginTs({
17
+ * printer: {
18
+ * nodes: {
19
+ * date(node) {
20
+ * return ts.factory.createTypeReferenceNode('Date', [])
21
+ * },
22
+ * },
23
+ * },
24
+ * })
25
+ * ```
26
+ */
27
+ type PrinterTsNodes = ast.PrinterPartial<ts.TypeNode, PrinterTsOptions>;
28
+ type PrinterTsOptions = {
29
+ /**
30
+ * Mark parameters as optional with `?` or `| undefined`.
31
+ * - `'questionToken'` adds `?` to properties
32
+ * - `'undefined'` adds `| undefined` to types
33
+ *
34
+ * @default `'questionToken'`
35
+ */
36
+ optionalType: PluginTs['resolvedOptions']['optionalType'];
37
+ /**
38
+ * Array representation style.
39
+ * - `'array'` uses bracket notation (`T[]`)
40
+ * - `'generic'` uses generic syntax (`Array<T>`)
41
+ *
42
+ * @default `'array'`
43
+ */
44
+ arrayType: PluginTs['resolvedOptions']['arrayType'];
45
+ /**
46
+ * Grouped enum settings. The printer emits references to enums, not the enum declarations, so only
47
+ * `type` (the output format) and `typeSuffix` (the enum key reference suffix) matter here.
48
+ * `constCasing` and `keyCasing` are ignored.
49
+ */
50
+ enum: PluginTs['resolvedOptions']['enum'];
51
+ /**
52
+ * Syntax for generated declarations.
53
+ * - `'type'` generates type aliases
54
+ * - `'interface'` generates interface declarations
55
+ *
56
+ * @default `'type'`
57
+ */
58
+ syntaxType?: PluginTs['resolvedOptions']['syntaxType'];
59
+ /**
60
+ * Exported name for the type declaration.
61
+ * When omitted, returns only the raw type node.
62
+ */
63
+ name?: string;
64
+ /**
65
+ * JSDoc comment to attach to the generated type.
66
+ */
67
+ description?: string;
68
+ /**
69
+ * Properties to exclude using `Omit<Type, Keys>`.
70
+ * Forces type alias syntax regardless of `syntaxType` setting.
71
+ */
72
+ keysToOmit?: Array<string> | null;
73
+ /**
74
+ * Transforms raw schema names into valid TypeScript identifiers.
75
+ */
76
+ resolver: ResolverTs;
77
+ /**
78
+ * Schema names that represent enums for suffixed key references.
79
+ */
80
+ enumSchemaNames?: Set<string>;
81
+ /**
82
+ * Custom handler map for node type overrides.
83
+ */
84
+ nodes?: PrinterTsNodes;
85
+ };
86
+ /**
87
+ * TypeScript printer factory options: maps `SchemaNode` → `ts.TypeNode` (raw) or `ts.Node` (full declaration).
88
+ */
89
+ type PrinterTsFactory = ast.PrinterFactoryOptions<'typescript', PrinterTsOptions, ts.TypeNode, string>;
90
+ /**
91
+ * TypeScript type printer built with `definePrinter`.
92
+ *
93
+ * Converts a `SchemaNode` AST node into a TypeScript AST node:
94
+ * - **`printer.print(node)`** — when `options.typeName` is set, returns a full
95
+ * `type Name = …` or `interface Name { … }` declaration (`ts.Node`).
96
+ * Without `typeName`, returns the raw `ts.TypeNode` for the schema.
97
+ *
98
+ * Dispatches on `node.type` to the appropriate handler in `nodes`. Options are closed
99
+ * over per printer instance, so each call to `printerTs(options)` produces an independent printer.
100
+ *
101
+ * @example Raw type node (no `typeName`)
102
+ * ```ts
103
+ * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enum: { type: 'inlineLiteral' } })
104
+ * const typeNode = printer.print(schemaNode) // ts.TypeNode
105
+ * ```
106
+ *
107
+ * @example Full declaration (with `typeName`)
108
+ * ```ts
109
+ * const printer = printerTs({ optionalType: 'questionToken', arrayType: 'array', enum: { type: 'inlineLiteral' }, typeName: 'MyType' })
110
+ * const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
111
+ * ```
112
+ */
113
+ declare const printerTs: (options?: PrinterTsOptions | undefined) => ast.Printer<PrinterTsFactory>;
114
+ //#endregion
115
+ //#region src/types.d.ts
116
+ /**
117
+ * The concrete resolver type for `@kubb/plugin-ts`.
118
+ * Extends the base `Resolver` (which provides `default` naming and option helpers, the top-level
119
+ * `name` casing, and the `file` builder) with plugin-specific naming namespaces for operation
120
+ * parameters, responses, and enum schemas.
121
+ */
122
+ type ResolverTs = Resolver & {
123
+ /**
124
+ * Naming for an operation's parameters, grouped by location.
125
+ */
126
+ param: {
127
+ /**
128
+ * Resolves the type name for an individual parameter.
129
+ *
130
+ * @example Individual parameter name
131
+ * `resolver.param.name(node, param) // → 'DeletePetPathPetId'`
132
+ */
133
+ name(node: ast.OperationNode, param: ast.ParameterNode): string;
134
+ /**
135
+ * Resolves the name for an operation's grouped path parameters type.
136
+ *
137
+ * @example Path parameters names
138
+ * `resolver.param.path(node, param) // → 'GetPetByIdPath'`
139
+ */
140
+ path(node: ast.OperationNode, param: ast.ParameterNode): string;
141
+ /**
142
+ * Resolves the name for an operation's grouped query parameters type.
143
+ *
144
+ * @example Query parameters names
145
+ * `resolver.param.query(node, param) // → 'FindPetsByStatusQuery'`
146
+ */
147
+ query(node: ast.OperationNode, param: ast.ParameterNode): string;
148
+ /**
149
+ * Resolves the name for an operation's grouped header parameters type.
150
+ *
151
+ * @example Header parameters names
152
+ * `resolver.param.headers(node, param) // → 'DeletePetHeaders'`
153
+ */
154
+ headers(node: ast.OperationNode, param: ast.ParameterNode): string;
155
+ };
156
+ /**
157
+ * Naming for an operation's request and response types.
158
+ */
159
+ response: {
160
+ /**
161
+ * Resolves the name for an operation response by status code.
162
+ * Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
163
+ *
164
+ * @example Response status names
165
+ * `resolver.response.status(node, 200) // → 'ListPetsStatus200'`
166
+ */
167
+ status(node: ast.OperationNode, statusCode: ast.StatusCode): string;
168
+ /**
169
+ * Resolves the name for an operation's grouped request options type (`Options`), the
170
+ * `{ body, path, query, headers }` bag passed to call an operation.
171
+ *
172
+ * @example Options type names
173
+ * `resolver.response.options(node) // → 'ListPetsOptions'`
174
+ */
175
+ options(node: ast.OperationNode): string;
176
+ /**
177
+ * Resolves the name for the collection of all operation responses (`Responses`).
178
+ *
179
+ * @example Responses collection names
180
+ * `resolver.response.responses(node) // → 'ListPetsResponses'`
181
+ */
182
+ responses(node: ast.OperationNode): string;
183
+ /**
184
+ * Resolves the name for the union of all operation responses (`Response`).
185
+ *
186
+ * @example Response union names
187
+ * `resolver.response.response(node) // → 'ListPetsResponse'`
188
+ */
189
+ response(node: ast.OperationNode): string;
190
+ /**
191
+ * Resolves the request body type name.
192
+ *
193
+ * @example Request body type name
194
+ * `resolver.response.body(node) // → 'CreatePetBody'`
195
+ */
196
+ body(node: ast.OperationNode): string;
197
+ };
198
+ /**
199
+ * Naming for enum schemas.
200
+ */
201
+ enum: {
202
+ /**
203
+ * Resolves the TypeScript type alias name for an enum schema's key variant.
204
+ * Appends `enumTypeSuffix` (default `'key'`) after applying the default naming convention.
205
+ *
206
+ * @example Enum key names with different suffixes
207
+ * ```ts
208
+ * resolver.enum.keyName(node, 'Key') // → 'PetStatusKey'
209
+ * resolver.enum.keyName(node, 'Value') // → 'PetStatusValue'
210
+ * resolver.enum.keyName(node, '') // → 'PetStatus'
211
+ * ```
212
+ */
213
+ keyName(node: {
214
+ name?: string | null;
215
+ }, enumTypeSuffix?: string): string;
216
+ };
217
+ };
218
+ type EnumKeyCasing = 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none';
219
+ type EnumConstCasing = 'camelCase' | 'pascalCase';
220
+ /**
221
+ * Grouped enum settings. Each `type` uses only some of the other fields.
222
+ *
223
+ * - `'asConst'` emits a `const` object plus a `typeof` type alias, so `constCasing`, `typeSuffix`, and `keyCasing` all apply.
224
+ * - `'enum'` and `'constEnum'` emit a TypeScript enum, so only `keyCasing` (the member names) applies.
225
+ * - `'literal'` and `'inlineLiteral'` emit union literals and drop the keys, so none of the other fields apply.
226
+ *
227
+ * @example Share one name between the const and the type
228
+ * ```ts
229
+ * enum: { type: 'asConst', constCasing: 'pascalCase', typeSuffix: '' }
230
+ * // export const VehicleType = { … } as const
231
+ * // export type VehicleType = (typeof VehicleType)[keyof typeof VehicleType]
232
+ * ```
233
+ */
234
+ type EnumOptions$1 = {
235
+ /**
236
+ * Emit a `const` object asserted with `as const`, paired with a `typeof` type alias.
237
+ * This is tree-shakeable and adds no enum runtime.
238
+ *
239
+ * @default 'asConst'
240
+ */
241
+ type?: 'asConst';
242
+ /**
243
+ * Casing of the generated const variable.
244
+ * - 'camelCase' names the const `vehicleType`.
245
+ * - 'pascalCase' names the const `VehicleType`, matching the schema name.
246
+ *
247
+ * @default 'camelCase'
248
+ */
249
+ constCasing?: EnumConstCasing;
250
+ /**
251
+ * Suffix appended to the generated type alias name. Only the type alias is renamed. The const
252
+ * object name stays the same. Set it to `''` together with `constCasing: 'pascalCase'` to merge
253
+ * the const and type under the schema's exact name.
254
+ *
255
+ * @default 'Key'
256
+ * @example A custom suffix
257
+ * `typeSuffix: 'Value'` renames the alias to `PetStatusValue`
258
+ */
259
+ typeSuffix?: string;
260
+ /**
261
+ * Choose the casing for enum key names.
262
+ * - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
263
+ * - 'snakeCase' generates keys in snake_case format.
264
+ * - 'pascalCase' generates keys in PascalCase format.
265
+ * - 'camelCase' generates keys in camelCase format.
266
+ * - 'none' uses the enum value as-is without transformation.
267
+ * @default 'none'
268
+ */
269
+ keyCasing?: EnumKeyCasing;
270
+ } | {
271
+ /**
272
+ * Emit a TypeScript `enum` (`'enum'`) or `const enum` (`'constEnum'`) declaration.
273
+ *
274
+ * @default 'asConst'
275
+ */
276
+ type?: 'enum' | 'constEnum';
277
+ /**
278
+ * `constCasing` has no effect for this `type`. Only `'asConst'` emits a const object.
279
+ */
280
+ constCasing?: never;
281
+ /**
282
+ * `typeSuffix` has no effect for this `type`. Only `'asConst'` emits a separate type alias.
283
+ */
284
+ typeSuffix?: never;
285
+ /**
286
+ * Choose the casing for enum member names.
287
+ * - 'screamingSnakeCase' generates keys in SCREAMING_SNAKE_CASE format.
288
+ * - 'snakeCase' generates keys in snake_case format.
289
+ * - 'pascalCase' generates keys in PascalCase format.
290
+ * - 'camelCase' generates keys in camelCase format.
291
+ * - 'none' uses the enum value as-is without transformation.
292
+ * @default 'none'
293
+ */
294
+ keyCasing?: EnumKeyCasing;
295
+ } | {
296
+ /**
297
+ * Emit a union of literals as a named alias (`'literal'`) or inline the union at every usage
298
+ * site (`'inlineLiteral'`).
299
+ *
300
+ * @default 'asConst'
301
+ * @note In Kubb v5, 'inlineLiteral' becomes the default.
302
+ */
303
+ type?: 'literal' | 'inlineLiteral';
304
+ /**
305
+ * `constCasing` has no effect for this `type`; literal modes emit no const object.
306
+ */
307
+ constCasing?: never;
308
+ /**
309
+ * `typeSuffix` has no effect for this `type`; literal modes emit no separate type alias.
310
+ */
311
+ typeSuffix?: never;
312
+ /**
313
+ * `keyCasing` has no effect for this `type`. Literal and inlineLiteral modes emit only values,
314
+ * so the keys are discarded.
315
+ */
316
+ keyCasing?: never;
317
+ };
318
+ /**
319
+ * Where the generated `.ts` files are written and how they are exported, plus the optional
320
+ * `group` strategy. The `group` option organizes `output.mode: 'directory'` output into per-tag or per-path subdirectories.
321
+ *
322
+ * @default { path: 'types', barrel: { type: 'named' } }
323
+ */
324
+ type Options = OutputOptions & {
325
+ /**
326
+ * Skip operations matching at least one entry in the list.
327
+ */
328
+ exclude?: Array<Exclude>;
329
+ /**
330
+ * Restrict generation to operations matching at least one entry in the list.
331
+ */
332
+ include?: Array<Include>;
333
+ /**
334
+ * Apply a different options object to operations matching a pattern.
335
+ */
336
+ override?: Array<Override<ResolvedOptions>>;
337
+ /**
338
+ * Whether object schemas are emitted as `type` aliases or `interface` declarations.
339
+ * - `'type'` emits closed type aliases. Safer default for generated code.
340
+ * - `'interface'` emits interfaces. Useful when consumers rely on declaration merging.
341
+ *
342
+ * @default 'type'
343
+ * @see https://www.totaltypescript.com/type-vs-interface-which-should-you-use
344
+ */
345
+ syntaxType?: 'type' | 'interface';
346
+ /**
347
+ * How optional properties are written in generated types.
348
+ * - `'questionToken'` — `type?: string`. The property may be missing.
349
+ * - `'undefined'` — `type: string | undefined`. Required to exist, may be `undefined`.
350
+ * - `'questionTokenAndUndefined'` — `type?: string | undefined`. Strictest.
351
+ *
352
+ * @default 'questionToken'
353
+ * @note Pick `'questionTokenAndUndefined'` when `exactOptionalPropertyTypes` is on in `tsconfig.json`.
354
+ */
355
+ optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
356
+ /**
357
+ * Syntax used for array types.
358
+ * - `'array'` — `Type[]`. Shorter.
359
+ * - `'generic'` — `Array<Type>`. More readable for complex element types.
360
+ *
361
+ * @default 'array'
362
+ */
363
+ arrayType?: 'generic' | 'array';
364
+ /**
365
+ * Override how names and file paths are built for generated symbols.
366
+ * Methods you omit fall back to the default `resolverTs`. `this` is bound to the
367
+ * full resolver, so `this.default.name(name)` delegates to the built-in implementation.
368
+ */
369
+ resolver?: ResolverPatch<ResolverTs>;
370
+ /**
371
+ * Macros applied to each schema or operation node before printing.
372
+ * Callbacks you omit fall back to the preset behavior.
373
+ *
374
+ * @example Drop writeOnly properties from response types
375
+ * ```ts
376
+ * macros: [
377
+ * {
378
+ * name: 'drop-write-only',
379
+ * property(node) {
380
+ * if (node.schema.writeOnly) return undefined
381
+ * },
382
+ * },
383
+ * ]
384
+ * ```
385
+ */
386
+ macros?: Array<ast.Macro>;
387
+ /**
388
+ * Replace the TypeScript handler for a specific schema type (`'integer'`, `'date'`, ...).
389
+ * Each handler returns a TypeScript AST node for that schema type. Use `this.transform`
390
+ * to recurse into nested schema nodes.
391
+ *
392
+ * @example Use the JavaScript `Date` object for date schemas
393
+ * ```ts
394
+ * import ts from 'typescript'
395
+ * pluginTs({
396
+ * printer: {
397
+ * nodes: {
398
+ * date() {
399
+ * return ts.factory.createTypeReferenceNode('Date', [])
400
+ * },
401
+ * },
402
+ * },
403
+ * })
404
+ * ```
405
+ */
406
+ printer?: {
407
+ nodes?: PrinterTsNodes;
408
+ };
409
+ /**
410
+ * How OpenAPI enums are represented in the generated TypeScript, and how their names are cased.
411
+ */
412
+ enum?: EnumOptions$1;
413
+ };
414
+ type ResolvedEnumOptions = {
415
+ type: NonNullable<EnumOptions$1['type']>;
416
+ constCasing: EnumConstCasing;
417
+ typeSuffix: string;
418
+ keyCasing: EnumKeyCasing;
419
+ };
420
+ type ResolvedOptions = {
421
+ output: Output;
422
+ exclude: Array<Exclude>;
423
+ include: Array<Include> | undefined;
424
+ override: Array<Override<ResolvedOptions>>;
425
+ group: Group | null;
426
+ enum: ResolvedEnumOptions;
427
+ optionalType: NonNullable<Options['optionalType']>;
428
+ arrayType: NonNullable<Options['arrayType']>;
429
+ syntaxType: NonNullable<Options['syntaxType']>;
430
+ printer: Options['printer'];
431
+ };
432
+ type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, ResolverTs>;
433
+ declare global {
434
+ namespace Kubb {
435
+ interface PluginRegistry {
436
+ 'plugin-ts': PluginTs;
437
+ }
438
+ }
439
+ }
440
+ //#endregion
441
+ //#region src/components/Enum.d.ts
442
+ type EnumOptions = PluginTs['resolvedOptions']['enum'];
443
+ type Props$1 = {
444
+ node: ast.EnumSchemaNode;
445
+ enum: EnumOptions;
446
+ resolver: ResolverTs;
447
+ key?: string | number | null;
448
+ };
449
+ /**
450
+ * Renders the enum declaration(s) for a single named `EnumSchemaNode`.
451
+ *
452
+ * Depending on `enum.type` this may emit:
453
+ * - A runtime object (`asConst`) plus a `typeof` type alias
454
+ * - A `const enum` or plain `enum` declaration (`constEnum` / `enum`)
455
+ * - A union literal type alias (`literal`)
456
+ *
457
+ * The emitted `File.Source` nodes carry the resolved names so that the barrel
458
+ * index picks up the correct export identifiers.
459
+ */
460
+ declare function Enum({ node, enum: enumOptions, resolver }: Props$1): KubbReactNode;
461
+ //#endregion
462
+ //#region src/components/Type.d.ts
463
+ type Props = {
464
+ name: string;
465
+ node: ast.SchemaNode;
466
+ /**
467
+ * Pre-configured printer instance created by the generator.
468
+ * Created with `printerTs({ ..., nodes: options.printer?.nodes })`.
469
+ */
470
+ printer: ast.Printer<PrinterTsFactory>;
471
+ enum: PluginTs['resolvedOptions']['enum'];
472
+ resolver: ResolverTs;
473
+ };
474
+ declare function Type({ name, node, printer, enum: enumOptions, resolver }: Props): KubbReactNode;
475
+ //#endregion
476
+ //#region src/generators/typeGenerator.d.ts
477
+ /**
478
+ * Built-in generator for `@kubb/plugin-ts`. Emits one TypeScript file per
479
+ * schema in the spec plus per-operation request, response, and parameter
480
+ * types. Drop-replace with a custom `Generator<PluginTs>` to change how
481
+ * TypeScript output is produced.
482
+ */
483
+ declare const typeGenerator: import("kubb/kit").Generator<PluginTs, unknown>;
484
+ //#endregion
6
485
  //#region src/plugin.d.ts
486
+ /**
487
+ * Canonical plugin name for `@kubb/plugin-ts`. Used for driver lookups and
488
+ * cross-plugin dependency references.
489
+ */
7
490
  declare const pluginTsName = "plugin-ts";
8
- declare const pluginTs: (options?: Options | undefined) => _kubb_core0.UserPluginWithLifeCycle<PluginTs>;
491
+ /**
492
+ * Generates TypeScript `type` aliases and `interface` declarations from an
493
+ * OpenAPI spec. The foundation that every other Kubb plugin builds on:
494
+ * clients, query hooks, mocks, and validators all reference the names this
495
+ * plugin produces.
496
+ *
497
+ * @example
498
+ * ```ts
499
+ * import { defineConfig } from 'kubb/config'
500
+ * import { pluginTs } from '@kubb/plugin-ts'
501
+ *
502
+ * export default defineConfig({
503
+ * input: './petStore.yaml',
504
+ * output: { path: './src/gen' },
505
+ * plugins: [
506
+ * pluginTs({
507
+ * output: { path: './types' },
508
+ * enum: { type: 'asConst' },
509
+ * optionalType: 'questionTokenAndUndefined',
510
+ * }),
511
+ * ],
512
+ * })
513
+ * ```
514
+ */
515
+ declare const pluginTs: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginTs>;
9
516
  //#endregion
10
- //#region src/resolverTs.d.ts
517
+ //#region src/printers/functionParams.d.ts
518
+ /**
519
+ * A type expression used as a function parameter type annotation.
520
+ *
521
+ * - a plain `string` is a type reference rendered as-is, e.g. `'string'`, `'QueryParams'`, `'Partial<Config>'`
522
+ * - a {@link TypeLiteralNode} is an inline anonymous type, e.g. `{ petId: string; name?: string }`
523
+ * - an {@link IndexedAccessTypeNode} is a single field accessed from a named type, e.g. `PathParams['petId']`
524
+ */
525
+ type TypeExpression = string | TypeLiteralNode | IndexedAccessTypeNode;
526
+ /**
527
+ * An inline anonymous object type grouping named fields.
528
+ * Renders as `{ key: Type; other?: OtherType }`.
529
+ */
530
+ type TypeLiteralNode = {
531
+ kind: 'TypeLiteral';
532
+ /**
533
+ * Members of the object type, rendered in order.
534
+ */
535
+ members: Array<{
536
+ /**
537
+ * Member key.
538
+ */
539
+ name: string;
540
+ /**
541
+ * Member type expression.
542
+ */
543
+ type: TypeExpression;
544
+ /**
545
+ * Whether the member is optional, rendered with `?`.
546
+ */
547
+ optional?: boolean;
548
+ }>;
549
+ };
11
550
  /**
12
- * Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
13
- * helpers used by the plugin. Import this in other plugins to resolve the exact names and
14
- * paths that `plugin-ts` generates without hardcoding the conventions.
551
+ * A single field accessed from a named group type. Renders as `target['key']`.
552
+ */
553
+ type IndexedAccessTypeNode = {
554
+ kind: 'IndexedAccessType';
555
+ /**
556
+ * Name of the type being indexed, e.g. `'GetPetPathParams'`.
557
+ */
558
+ target: string;
559
+ /**
560
+ * Field key to access, e.g. `'petId'`.
561
+ */
562
+ key: string;
563
+ };
564
+ /**
565
+ * An object destructuring binding, used as the name of a grouped function parameter.
566
+ * Renders as `{ id, name }` or `{ id: renamed }` when `propertyName` differs.
567
+ */
568
+ type ObjectBindingPatternNode = {
569
+ kind: 'ObjectBindingPattern';
570
+ /**
571
+ * Bound elements, rendered in order.
572
+ */
573
+ elements: Array<{
574
+ /**
575
+ * Local binding name.
576
+ */
577
+ name: string;
578
+ /**
579
+ * Source key when it differs from the binding name, rendered as `propertyName: name`.
580
+ */
581
+ propertyName?: string;
582
+ }>;
583
+ };
584
+ /**
585
+ * One function parameter.
586
+ *
587
+ * A simple parameter has a `string` name. A destructured group has an
588
+ * {@link ObjectBindingPatternNode} name paired with a {@link TypeLiteralNode} type.
589
+ *
590
+ * @example Required parameter
591
+ * `name: Type`
592
+ *
593
+ * @example Optional parameter
594
+ * `name?: Type`
595
+ *
596
+ * @example Parameter with default value
597
+ * `name: Type = defaultValue`
15
598
  *
16
- * The `default` method is automatically injected by `defineResolver` — it uses `camelCase`
17
- * for identifiers/files and `pascalCase` for type names.
599
+ * @example Rest parameter
600
+ * `...name: Type[]`
601
+ *
602
+ * @example Destructured group
603
+ * `{ id, name? }: { id: string; name?: string } = {}`
604
+ */
605
+ type FunctionParameterNode = {
606
+ kind: 'FunctionParameter';
607
+ /**
608
+ * Parameter name, or an {@link ObjectBindingPatternNode} for a destructured group.
609
+ */
610
+ name: string | ObjectBindingPatternNode;
611
+ /**
612
+ * Type annotation as a {@link TypeExpression}. Omit for untyped output.
613
+ */
614
+ type?: TypeExpression;
615
+ /**
616
+ * Whether the parameter is optional, rendered with `?`.
617
+ */
618
+ optional?: boolean;
619
+ /**
620
+ * Default value, written verbatim after `=`. Commonly `'{}'` for a destructured group.
621
+ */
622
+ default?: string;
623
+ /**
624
+ * When `true` the parameter is emitted as a rest parameter, e.g. `...name: Type[]`.
625
+ */
626
+ rest?: boolean;
627
+ };
628
+ /**
629
+ * A complete function parameter list.
630
+ *
631
+ * Printers are responsible for sorting (`required` → `optional` → `defaulted`).
632
+ */
633
+ type FunctionParametersNode = {
634
+ kind: 'FunctionParameters';
635
+ /**
636
+ * Ordered parameter nodes.
637
+ */
638
+ params: ReadonlyArray<FunctionParameterNode>;
639
+ };
640
+ /**
641
+ * Creates a {@link TypeLiteralNode} representing an inline anonymous object type.
642
+ *
643
+ * @example
644
+ * ```ts
645
+ * createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })
646
+ * // { petId: string }
647
+ * ```
648
+ */
649
+ declare function createTypeLiteral(props: Omit<TypeLiteralNode, 'kind'>): TypeLiteralNode;
650
+ /**
651
+ * Creates an {@link IndexedAccessTypeNode} representing a single field accessed from a named type.
652
+ *
653
+ * @example
654
+ * ```ts
655
+ * createIndexedAccessType({ target: 'DeletePetPathParams', key: 'petId' })
656
+ * // DeletePetPathParams['petId']
657
+ * ```
658
+ */
659
+ declare function createIndexedAccessType(props: Omit<IndexedAccessTypeNode, 'kind'>): IndexedAccessTypeNode;
660
+ /**
661
+ * Creates an {@link ObjectBindingPatternNode} for a destructured parameter binding.
662
+ *
663
+ * @example
664
+ * ```ts
665
+ * createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })
666
+ * // { id, name }
667
+ * ```
668
+ */
669
+ declare function createObjectBindingPattern(props: Omit<ObjectBindingPatternNode, 'kind'>): ObjectBindingPatternNode;
670
+ /**
671
+ * Plain property descriptor for a destructured group built by {@link createFunctionParameter}.
672
+ */
673
+ type FunctionParameterProperty = {
674
+ name: string;
675
+ type: TypeExpression;
676
+ optional?: boolean;
677
+ };
678
+ type FunctionParameterInput = {
679
+ name: string | ObjectBindingPatternNode;
680
+ type?: TypeExpression;
681
+ optional?: boolean;
682
+ default?: string;
683
+ rest?: boolean;
684
+ } | {
685
+ properties: Array<FunctionParameterProperty>;
686
+ optional?: boolean;
687
+ default?: string;
688
+ };
689
+ /**
690
+ * Creates a {@link FunctionParameterNode}. `optional` defaults to `false`.
691
+ * Passing `properties` builds a destructured group: an {@link ObjectBindingPatternNode} name
692
+ * paired with a {@link TypeLiteralNode} type.
693
+ *
694
+ * @example Optional param
695
+ * ```ts
696
+ * createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })
697
+ * // → params?: QueryParams
698
+ * ```
699
+ *
700
+ * @example Destructured group
701
+ * ```ts
702
+ * createFunctionParameter({ properties: [{ name: 'id', type: 'string' }, { name: 'name', type: 'string', optional: true }], default: '{}' })
703
+ * // → { id, name }: { id: string; name?: string } = {}
704
+ * ```
705
+ */
706
+ declare function createFunctionParameter(input: FunctionParameterInput): FunctionParameterNode;
707
+ /**
708
+ * Creates a {@link FunctionParametersNode} from an ordered list of parameters.
709
+ *
710
+ * @example
711
+ * ```ts
712
+ * const empty = createFunctionParameters()
713
+ * // { params: [] }
714
+ * ```
715
+ */
716
+ declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
717
+ //#endregion
718
+ //#region src/printers/functionPrinter.d.ts
719
+ /**
720
+ * Renders a {@link TypeExpression} to its TypeScript source.
721
+ *
722
+ * - a `string` is a type reference, returned as-is
723
+ * - an `IndexedAccessType` becomes `objectType['indexType']`
724
+ * - a `TypeLiteral` becomes `{ key: Type; key?: Type }`
725
+ *
726
+ * `transformType` is applied once to the fully rendered type, matching how the
727
+ * printer wrapped reference types before the `ts.factory` model.
728
+ */
729
+ declare function renderType(type: TypeExpression, transformType?: (type: string) => string): string;
730
+ type FunctionPrinterOptions = {
731
+ /**
732
+ * Rendering modes supported by `functionPrinter`.
733
+ *
734
+ * | Mode | Output example | Use case |
735
+ * |---------------|-----------------------------------|--------------------------------|
736
+ * | `declaration` | `id: string, config: Config = {}` | Function parameter declaration |
737
+ * | `call` | `id, { method, url }` | Function call arguments |
738
+ */
739
+ mode: 'declaration' | 'call';
740
+ /**
741
+ * Optional transformation applied to every parameter name before printing.
742
+ */
743
+ transformName?: (name: string) => string;
744
+ /**
745
+ * Optional transformation applied to every type string before printing.
746
+ */
747
+ transformType?: (type: string) => string;
748
+ };
749
+ /**
750
+ * Default function-signature printer. Renders a parameter list in one of two modes:
751
+ * `declaration` for the function signature and `call` for the call arguments.
18
752
  *
19
753
  * @example
20
754
  * ```ts
21
- * import { resolver } from '@kubb/plugin-ts'
22
- *
23
- * resolver.default('list pets', 'type') // → 'ListPets'
24
- * resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
25
- * resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'
26
- * resolver.resolvePathName('list pets', 'file') // → 'listPets'
27
- * ```
28
- */
29
- declare const resolverTs: _kubb_core0.Resolver & {
30
- resolveName(name: string): string;
31
- resolveTypedName(name: string): string;
32
- resolvePathName(name: string, type?: "file" | "function" | "type" | "const"): string;
33
- resolveParamName(node: _kubb_ast_types0.OperationNode, param: _kubb_ast_types0.ParameterNode): string;
34
- resolveParamTypedName(node: _kubb_ast_types0.OperationNode, param: _kubb_ast_types0.ParameterNode): string;
35
- resolveResponseStatusName(node: _kubb_ast_types0.OperationNode, statusCode: _kubb_ast_types0.StatusCode): string;
36
- resolveResponseStatusTypedName(node: _kubb_ast_types0.OperationNode, statusCode: _kubb_ast_types0.StatusCode): string;
37
- resolveDataName(node: _kubb_ast_types0.OperationNode): string;
38
- resolveDataTypedName(node: _kubb_ast_types0.OperationNode): string;
39
- resolveRequestConfigName(node: _kubb_ast_types0.OperationNode): string;
40
- resolveRequestConfigTypedName(node: _kubb_ast_types0.OperationNode): string;
41
- resolveResponsesName(node: _kubb_ast_types0.OperationNode): string;
42
- resolveResponsesTypedName(node: _kubb_ast_types0.OperationNode): string;
43
- resolveResponseName(node: _kubb_ast_types0.OperationNode): string;
44
- resolveResponseTypedName(node: _kubb_ast_types0.OperationNode): string;
45
- resolveEnumKeyTypedName(node: _kubb_ast_types0.SchemaNode): string;
46
- };
47
- //#endregion
48
- export { type PluginTs, pluginTs, pluginTsName, resolverTs };
755
+ * const printer = functionPrinter({ mode: 'declaration' })
756
+ *
757
+ * const sig = createFunctionParameters({
758
+ * params: [
759
+ * createFunctionParameter({ name: 'petId', type: 'string', optional: false }),
760
+ * createFunctionParameter({ name: 'config', type: 'Config', optional: false, default: '{}' }),
761
+ * ],
762
+ * })
763
+ *
764
+ * printer.print(sig) // → "petId: string, config: Config = {}"
765
+ * ```
766
+ */
767
+ declare function functionPrinter(options: FunctionPrinterOptions): {
768
+ name: "functionParameters";
769
+ options: FunctionPrinterOptions;
770
+ print(node: FunctionParametersNode): string;
771
+ };
772
+ //#endregion
773
+ //#region ../../internals/shared/src/operation.d.ts
774
+ /**
775
+ * Resolver interface for building operation parameters.
776
+ *
777
+ * `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.
778
+ */
779
+ type OperationParamsResolver = {
780
+ /**
781
+ * Naming for an operation's parameters, grouped by location.
782
+ */
783
+ param: {
784
+ /**
785
+ * Resolves the type name for an individual parameter.
786
+ *
787
+ * @example Individual path parameter name
788
+ * `resolver.param.name(node, param) // → 'DeletePetPathPetId'`
789
+ */
790
+ name(node: ast.OperationNode, param: ast.ParameterNode): string;
791
+ /**
792
+ * Resolves the grouped path parameters type name.
793
+ * When the return value equals `resolver.param.name`, no indexed access is emitted.
794
+ *
795
+ * @example Grouped path params type name
796
+ * `resolver.param.path(node, param) // → 'DeletePetPath'`
797
+ */
798
+ path(node: ast.OperationNode, param: ast.ParameterNode): string;
799
+ /**
800
+ * Resolves the grouped query parameters type name.
801
+ * When the return value equals `resolver.param.name`, an inline struct type is emitted instead.
802
+ *
803
+ * @example Grouped query params type name
804
+ * `resolver.param.query(node, param) // → 'FindPetsByStatusQuery'`
805
+ */
806
+ query(node: ast.OperationNode, param: ast.ParameterNode): string;
807
+ /**
808
+ * Resolves the grouped header parameters type name.
809
+ * When the return value equals `resolver.param.name`, an inline struct type is emitted instead.
810
+ *
811
+ * @example Grouped header params type name
812
+ * `resolver.param.headers(node, param) // → 'DeletePetHeaders'`
813
+ */
814
+ headers(node: ast.OperationNode, param: ast.ParameterNode): string;
815
+ };
816
+ /**
817
+ * Naming for an operation's request and response types.
818
+ */
819
+ response: {
820
+ /**
821
+ * Resolves the request body type name.
822
+ *
823
+ * @example Request body type name
824
+ * `resolver.response.body(node) // → 'CreatePetBody'`
825
+ */
826
+ body(node: ast.OperationNode): string;
827
+ };
828
+ };
829
+ //#endregion
830
+ //#region src/printers/operationParams.d.ts
831
+ /**
832
+ * Options for {@link createOperationParams}.
833
+ */
834
+ type CreateOperationParamsOptions = {
835
+ /**
836
+ * How all operation parameters are grouped in the function signature.
837
+ * - `'object'` wraps all params into a single destructured object `{ petId, data, params }`
838
+ * - `'inline'` emits each param category as a separate top-level parameter
839
+ */
840
+ paramsType: 'object' | 'inline';
841
+ /**
842
+ * How path parameters are emitted when `paramsType` is `'inline'`.
843
+ * - `'object'` groups them as `{ petId, storeId }: PathParams`
844
+ * - `'inline'` spreads them as individual parameters `petId: string, storeId: string`
845
+ * - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`
846
+ */
847
+ pathParamsType: 'object' | 'inline' | 'inlineSpread';
848
+ /**
849
+ * Resolver for parameter and request body type names.
850
+ * Pass `ResolverTs` from `@kubb/plugin-ts` directly.
851
+ * When omitted, falls back to the schema primitive or `'unknown'`.
852
+ */
853
+ resolver?: OperationParamsResolver;
854
+ /**
855
+ * Default value for the path parameters binding when `pathParamsType` is `'object'`.
856
+ * Falls back to `'{}'` when all path params are optional.
857
+ */
858
+ pathParamsDefault?: string;
859
+ /**
860
+ * Extra parameters appended after the standard operation parameters.
861
+ *
862
+ * @example Plugin-specific trailing parameter
863
+ * ```ts
864
+ * extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]
865
+ * ```
866
+ */
867
+ extraParams?: Array<FunctionParameterNode>;
868
+ /**
869
+ * Override the default parameter names used for body, query, header, and rest-path groups.
870
+ *
871
+ * Useful when targeting languages or frameworks with different naming conventions.
872
+ *
873
+ * @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }
874
+ */
875
+ paramNames?: {
876
+ /**
877
+ * Name for the request body parameter.
878
+ * @default 'data'
879
+ */
880
+ data?: string;
881
+ /**
882
+ * Name for the query parameters group parameter.
883
+ * @default 'params'
884
+ */
885
+ params?: string;
886
+ /**
887
+ * Name for the header parameters group parameter.
888
+ * @default 'headers'
889
+ */
890
+ headers?: string;
891
+ /**
892
+ * Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.
893
+ * @default 'pathParams'
894
+ */
895
+ path?: string;
896
+ };
897
+ /**
898
+ * Transforms every resolved type name before it lands in a parameter node, for framework-level
899
+ * type wrappers.
900
+ *
901
+ * @example Vue Query, wrap every parameter type with `MaybeRefOrGetter`
902
+ * `typeWrapper: (t) => \`MaybeRefOrGetter<${t}>\``
903
+ */
904
+ typeWrapper?: (type: string) => string;
905
+ };
906
+ /**
907
+ * Converts an `OperationNode` into function parameters for code generation.
908
+ *
909
+ * Centralizes parameter grouping logic for all plugins. `paramsType` chooses between one
910
+ * destructured object parameter (`object`) and separate top-level parameters (`inline`), while
911
+ * `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type
912
+ * name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.
913
+ */
914
+ declare function createOperationParams(node: ast.OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
915
+ //#endregion
916
+ //#region src/resolvers/resolverTs.d.ts
917
+ /**
918
+ * Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
919
+ * for every generated TypeScript type. Import this in other plugins that need
920
+ * to reference the exact names `plugin-ts` produces without duplicating the
921
+ * casing/file-layout rules.
922
+ *
923
+ * The `default` helpers are supplied by `createResolver`. This plugin overrides the top-level `name`
924
+ * to use PascalCase for value and type names and `file` to write PascalCase file paths (dotted names
925
+ * become `/`-joined), and groups the operation-specific naming under the `param`, `response`, and
926
+ * `enum` namespaces.
927
+ *
928
+ * @example Resolve a type and file name
929
+ * ```ts
930
+ * import { resolverTs } from '@kubb/plugin-ts'
931
+ *
932
+ * resolverTs.name('list pets') // 'ListPets'
933
+ * resolverTs.response.status(node, 200) // 'ListPetsStatus200'
934
+ * ```
935
+ */
936
+ declare const resolverTs: ResolverTs;
937
+ //#endregion
938
+ //#region src/utils.d.ts
939
+ type BuildParamsSchemaOptions = {
940
+ params: Array<ast.ParameterNode>;
941
+ };
942
+ /**
943
+ * Builds the object schema for a group of parameters sharing one `in` location (path, query, or
944
+ * header), embedding each param's own schema (and JSDoc) directly rather than referencing a
945
+ * separate per-param type — the group itself is the only type these params get exported as.
946
+ */
947
+ declare function buildParams({ params }: BuildParamsSchemaOptions): ast.SchemaNode;
948
+ //#endregion
949
+ export { type CreateOperationParamsOptions, Enum, type FunctionParameterNode, type FunctionParametersNode, type IndexedAccessTypeNode, type ObjectBindingPatternNode, type PluginTs, type PrinterTsFactory, type PrinterTsNodes, type PrinterTsOptions, type ResolverTs, Type, type TypeExpression, type TypeLiteralNode, buildParams, createFunctionParameter, createFunctionParameters, createIndexedAccessType, createObjectBindingPattern, createOperationParams, createTypeLiteral, pluginTs as default, pluginTs, functionPrinter, pluginTsName, printerTs, renderType, resolverTs, typeGenerator };
49
950
  //# sourceMappingURL=index.d.ts.map