@kubb/plugin-ts 5.0.0-alpha.2 → 5.0.0-alpha.21

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 (76) hide show
  1. package/dist/Type-B6fo0gSk.js +120 -0
  2. package/dist/Type-B6fo0gSk.js.map +1 -0
  3. package/dist/Type-oFwUfkZv.cjs +131 -0
  4. package/dist/Type-oFwUfkZv.cjs.map +1 -0
  5. package/dist/builderTs-Cd3juc2G.cjs +120 -0
  6. package/dist/builderTs-Cd3juc2G.cjs.map +1 -0
  7. package/dist/builderTs-DausqHpc.js +116 -0
  8. package/dist/builderTs-DausqHpc.js.map +1 -0
  9. package/dist/builders.cjs +3 -0
  10. package/dist/builders.d.ts +8 -0
  11. package/dist/builders.js +2 -0
  12. package/dist/casing-BJHFg-zZ.js +84 -0
  13. package/dist/casing-BJHFg-zZ.js.map +1 -0
  14. package/dist/casing-DHfdqpLi.cjs +107 -0
  15. package/dist/casing-DHfdqpLi.cjs.map +1 -0
  16. package/dist/chunk-ByKO4r7w.cjs +38 -0
  17. package/dist/components.cjs +3 -2
  18. package/dist/components.d.ts +40 -11
  19. package/dist/components.js +2 -2
  20. package/dist/generators-ByK18qUn.js +551 -0
  21. package/dist/generators-ByK18qUn.js.map +1 -0
  22. package/dist/generators-aSsiTfUO.cjs +563 -0
  23. package/dist/generators-aSsiTfUO.cjs.map +1 -0
  24. package/dist/generators.cjs +3 -2
  25. package/dist/generators.d.ts +7 -492
  26. package/dist/generators.js +2 -2
  27. package/dist/index.cjs +148 -3
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +146 -1
  31. package/dist/index.js.map +1 -0
  32. package/dist/printerTs-BgZucv4T.js +559 -0
  33. package/dist/printerTs-BgZucv4T.js.map +1 -0
  34. package/dist/printerTs-CFXc_LpP.cjs +595 -0
  35. package/dist/printerTs-CFXc_LpP.cjs.map +1 -0
  36. package/dist/printers.cjs +3 -0
  37. package/dist/printers.d.ts +75 -0
  38. package/dist/printers.js +2 -0
  39. package/dist/resolverTsLegacy-DLl854-P.js +185 -0
  40. package/dist/resolverTsLegacy-DLl854-P.js.map +1 -0
  41. package/dist/resolverTsLegacy-sJ16Iqrl.cjs +196 -0
  42. package/dist/resolverTsLegacy-sJ16Iqrl.cjs.map +1 -0
  43. package/dist/resolvers.cjs +4 -0
  44. package/dist/resolvers.d.ts +52 -0
  45. package/dist/resolvers.js +2 -0
  46. package/dist/types-BcyuFDn9.d.ts +344 -0
  47. package/package.json +27 -8
  48. package/src/builders/builderTs.ts +92 -0
  49. package/src/builders/index.ts +1 -0
  50. package/src/components/Enum.tsx +83 -0
  51. package/src/components/Type.tsx +24 -145
  52. package/src/components/index.ts +1 -0
  53. package/src/constants.ts +29 -0
  54. package/src/factory.ts +14 -48
  55. package/src/generators/index.ts +1 -0
  56. package/src/generators/typeGenerator.tsx +119 -403
  57. package/src/generators/typeGeneratorLegacy.tsx +345 -0
  58. package/src/plugin.ts +80 -122
  59. package/src/presets.ts +26 -0
  60. package/src/printers/index.ts +1 -0
  61. package/src/printers/printerTs.ts +389 -0
  62. package/src/resolvers/index.ts +2 -0
  63. package/src/resolvers/resolverTs.ts +107 -0
  64. package/src/resolvers/resolverTsLegacy.ts +87 -0
  65. package/src/types.ts +261 -72
  66. package/dist/components-9wydyqUx.cjs +0 -848
  67. package/dist/components-9wydyqUx.cjs.map +0 -1
  68. package/dist/components-LmqJfxMv.js +0 -721
  69. package/dist/components-LmqJfxMv.js.map +0 -1
  70. package/dist/plugin-CNkzbtpl.cjs +0 -508
  71. package/dist/plugin-CNkzbtpl.cjs.map +0 -1
  72. package/dist/plugin-DoLrDl9P.js +0 -476
  73. package/dist/plugin-DoLrDl9P.js.map +0 -1
  74. package/dist/types-BpeKGgCn.d.ts +0 -170
  75. package/src/parser.ts +0 -396
  76. package/src/printer.ts +0 -221
package/src/types.ts CHANGED
@@ -1,20 +1,235 @@
1
- import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
- import type { contentType, Oas } from '@kubb/oas'
3
- import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
4
- import type { Generator } from '@kubb/plugin-oas/generators'
5
- import type ts from 'typescript'
1
+ import type { OperationNode, ParameterNode, SchemaNode, StatusCode, Visitor } from '@kubb/ast/types'
2
+ import type {
3
+ Builder,
4
+ CompatibilityPreset,
5
+ Exclude,
6
+ Generator,
7
+ Group,
8
+ Include,
9
+ Output,
10
+ Override,
11
+ PluginFactoryOptions,
12
+ ResolvePathOptions,
13
+ Resolver,
14
+ } from '@kubb/core'
15
+ /**
16
+ * The concrete resolver type for `@kubb/plugin-ts`.
17
+ * Extends the base `Resolver` (which provides `default` and `resolveOptions`) with
18
+ * plugin-specific naming helpers for operations, parameters, responses, and schemas.
19
+ */
20
+ export type ResolverTs = Resolver & {
21
+ /**
22
+ * Resolves the variable/function name for a given raw name (equivalent to `default(name, 'function')`).
23
+ * Use this shorthand when matching the `name` field produced by the v2 TypeGenerator,
24
+ * so call-sites don't need to repeat the `'function'` type literal.
25
+ *
26
+ * @example
27
+ * resolver.resolveName('list pets status 200') // → 'listPetsStatus200'
28
+ */
29
+ resolveName(name: string): string
30
+ /**
31
+ * Resolves the TypeScript type name for a given raw name (equivalent to `default(name, 'type')`).
32
+ * Use this shorthand when matching the `typedName` field produced by the v2 TypeGenerator,
33
+ * so call-sites don't need to repeat the `'type'` type literal.
34
+ *
35
+ * @example
36
+ * resolver.resolveTypedName('list pets status 200') // → 'ListPetsStatus200'
37
+ */
38
+ resolveTypedName(name: string): string
39
+ /**
40
+ * Resolves the file/path name for a given identifier using PascalCase.
41
+ *
42
+ * @example
43
+ * resolver.resolvePathName('list pets', 'file') // → 'ListPets'
44
+ */
45
+ resolvePathName(name: string, type?: 'file' | 'function' | 'type' | 'const'): string
46
+ /**
47
+ * Resolves the variable/function name for an operation parameter.
48
+ * Encapsulates the `<operationId> <PascalCase(paramIn)> <paramName>` naming convention.
49
+ *
50
+ * @example
51
+ * resolver.resolveParamName(node, param) // → 'ListPetsQueryLimit'
52
+ */
53
+ resolveParamName(node: OperationNode, param: ParameterNode): string
54
+ /**
55
+ * Resolves the TypeScript type alias name for an operation parameter
56
+ * (equivalent to `resolveParamName` with `type: 'type'`).
57
+ * In the default implementation both return the same PascalCase string;
58
+ * the distinction is preserved so overrides can diverge the two forms.
59
+ *
60
+ * @example
61
+ * resolver.resolveParamTypedName(node, param) // → 'ListPetsQueryLimit'
62
+ */
63
+ resolveParamTypedName(node: OperationNode, param: ParameterNode): string
64
+ /**
65
+ * Resolves the variable/function name for an operation response by status code.
66
+ * Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
67
+ *
68
+ * @example
69
+ * resolver.resolveResponseStatusName(node, 200) // → 'ListPetsStatus200'
70
+ */
71
+ resolveResponseStatusName(node: OperationNode, statusCode: StatusCode): string
72
+ /**
73
+ * Resolves the TypeScript type alias name for an operation response by status code.
74
+ * Encapsulates the `<operationId> Status <statusCode>` template with PascalCase applied to the result.
75
+ *
76
+ * @example
77
+ * resolver.resolveResponseStatusTypedName(node, 200) // → 'ListPetsStatus200'
78
+ */
79
+ resolveResponseStatusTypedName(node: OperationNode, statusCode: StatusCode): string
80
+ /**
81
+ * Resolves the variable/function name for an operation's request body (`Data`).
82
+ *
83
+ * @example
84
+ * resolver.resolveDataName(node) // → 'ListPetsData'
85
+ */
86
+ resolveDataName(node: OperationNode): string
87
+ /**
88
+ * Resolves the TypeScript type alias name for an operation's request body (`Data`).
89
+ *
90
+ * @example
91
+ * resolver.resolveDataTypedName(node) // → 'ListPetsData'
92
+ */
93
+ resolveDataTypedName(node: OperationNode): string
94
+ /**
95
+ * Resolves the variable/function name for an operation's request config (`RequestConfig`).
96
+ *
97
+ * @example
98
+ * resolver.resolveRequestConfigName(node) // → 'ListPetsRequestConfig'
99
+ */
100
+ resolveRequestConfigName(node: OperationNode): string
101
+ /**
102
+ * Resolves the TypeScript type alias name for an operation's request config (`RequestConfig`).
103
+ *
104
+ * @example
105
+ * resolver.resolveRequestConfigTypedName(node) // → 'ListPetsRequestConfig'
106
+ */
107
+ resolveRequestConfigTypedName(node: OperationNode): string
108
+ /**
109
+ * Resolves the variable/function name for the collection of all operation responses (`Responses`).
110
+ *
111
+ * @example
112
+ * resolver.resolveResponsesName(node) // → 'ListPetsResponses'
113
+ */
114
+ resolveResponsesName(node: OperationNode): string
115
+ /**
116
+ * Resolves the TypeScript type alias name for the collection of all operation responses.
117
+ *
118
+ * @example
119
+ * resolver.resolveResponsesTypedName(node) // → 'ListPetsResponses'
120
+ */
121
+ resolveResponsesTypedName(node: OperationNode): string
122
+ /**
123
+ * Resolves the variable/function name for the union of all operation responses (`Response`).
124
+ *
125
+ * @example
126
+ * resolver.resolveResponseName(node) // → 'ListPetsResponse'
127
+ */
128
+ resolveResponseName(node: OperationNode): string
129
+ /**
130
+ * Resolves the TypeScript type alias name for the union of all operation responses.
131
+ *
132
+ * @example
133
+ * resolver.resolveResponseTypedName(node) // → 'ListPetsResponse'
134
+ */
135
+ resolveResponseTypedName(node: OperationNode): string
136
+ /**
137
+ * Resolves the TypeScript type alias name for an enum schema's key variant.
138
+ * Appends the `Key` suffix after applying the default naming convention.
139
+ *
140
+ * @example
141
+ * resolver.resolveEnumKeyTypedName(node) // → 'PetStatusKey'
142
+ */
143
+ resolveEnumKeyTypedName(node: SchemaNode): string
144
+ /**
145
+ * Resolves the variable/function name for an operation's grouped path parameters type.
146
+ * Only available with `compatibilityPreset: 'kubbV4'`.
147
+ *
148
+ * @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
149
+ * @example
150
+ * resolver.resolvePathParamsName(node) // → 'GetPetByIdPathParams'
151
+ */
152
+ resolvePathParamsName?(node: OperationNode): string
153
+ /**
154
+ * Resolves the TypeScript type alias name for an operation's grouped path parameters type.
155
+ * Only available with `compatibilityPreset: 'kubbV4'`.
156
+ *
157
+ * @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
158
+ * @example
159
+ * resolver.resolvePathParamsTypedName(node) // → 'GetPetByIdPathParams'
160
+ */
161
+ resolvePathParamsTypedName?(node: OperationNode): string
162
+ /**
163
+ * Resolves the variable/function name for an operation's grouped query parameters type.
164
+ * Only available with `compatibilityPreset: 'kubbV4'`.
165
+ *
166
+ * @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
167
+ * @example
168
+ * resolver.resolveQueryParamsName(node) // → 'FindPetsByStatusQueryParams'
169
+ */
170
+ resolveQueryParamsName?(node: OperationNode): string
171
+ /**
172
+ * Resolves the TypeScript type alias name for an operation's grouped query parameters type.
173
+ * Only available with `compatibilityPreset: 'kubbV4'`.
174
+ *
175
+ * @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
176
+ * @example
177
+ * resolver.resolveQueryParamsTypedName(node) // → 'FindPetsByStatusQueryParams'
178
+ */
179
+ resolveQueryParamsTypedName?(node: OperationNode): string
180
+ /**
181
+ * Resolves the variable/function name for an operation's grouped header parameters type.
182
+ * Only available with `compatibilityPreset: 'kubbV4'`.
183
+ *
184
+ * @deprecated Kubb v4 compatibility only — use `resolveParamName` per individual parameter instead.
185
+ * @example
186
+ * resolver.resolveHeaderParamsName(node) // → 'DeletePetHeaderParams'
187
+ */
188
+ resolveHeaderParamsName?(node: OperationNode): string
189
+ /**
190
+ * Resolves the TypeScript type alias name for an operation's grouped header parameters type.
191
+ * Only available with `compatibilityPreset: 'kubbV4'`.
192
+ *
193
+ * @deprecated Kubb v4 compatibility only — use `resolveParamTypedName` per individual parameter instead.
194
+ * @example
195
+ * resolver.resolveHeaderParamsTypedName(node) // → 'DeletePetHeaderParams'
196
+ */
197
+ resolveHeaderParamsTypedName?(node: OperationNode): string
198
+ }
199
+
200
+ type BuildParamsSchemaOptions = {
201
+ params: Array<ParameterNode>
202
+ node: OperationNode
203
+ resolver: ResolverTs
204
+ }
205
+
206
+ type BuildOperationSchemaOptions = {
207
+ node: OperationNode
208
+ resolver: ResolverTs
209
+ }
210
+
211
+ /**
212
+ * The concrete builder type for `@kubb/plugin-ts`.
213
+ * Extends the base `Builder` with schema-building helpers used by the v5 type generator.
214
+ */
215
+ export type BuilderTs = Builder & {
216
+ buildParams(options: BuildParamsSchemaOptions): SchemaNode
217
+ buildData(options: BuildOperationSchemaOptions): SchemaNode
218
+ buildResponses(options: BuildOperationSchemaOptions): SchemaNode | null
219
+ buildResponseUnion(options: BuildOperationSchemaOptions): SchemaNode | null
220
+ }
6
221
 
7
222
  export type Options = {
8
223
  /**
9
224
  * Specify the export location for the files and define the behavior of the output
10
225
  * @default { path: 'types', barrelType: 'named' }
11
226
  */
12
- output?: Output<Oas>
227
+ output?: Output
13
228
  /**
14
229
  * Define which contentType should be used.
15
230
  * By default, uses the first valid JSON media type.
16
231
  */
17
- contentType?: contentType
232
+ contentType?: 'application/json' | (string & {})
18
233
  /**
19
234
  * Group the clients based on the provided name.
20
235
  */
@@ -60,42 +275,6 @@ export type Options = {
60
275
  * @default 'type'
61
276
  */
62
277
  syntaxType?: 'type' | 'interface'
63
- /**
64
- * Set a suffix for the generated enums.
65
- * @default 'enum'
66
- */
67
- enumSuffix?: string
68
- /**
69
- * Choose to use date or datetime as JavaScript Date instead of string.
70
- * - 'string' represents dates as string values.
71
- * - 'date' represents dates as JavaScript Date objects.
72
- * @default 'string'
73
- */
74
- dateType?: 'string' | 'date'
75
- /**
76
- * Choose to use `number` or `bigint` for integer fields with `int64` format.
77
- * - 'number' uses the TypeScript `number` type (matches JSON.parse() runtime behavior).
78
- * - 'bigint' uses the TypeScript `bigint` type (accurate for values exceeding Number.MAX_SAFE_INTEGER).
79
- * @note in v5 of Kubb 'bigint' will become the default to better align with OpenAPI's int64 specification.
80
- * @default 'number'
81
- */
82
- integerType?: 'number' | 'bigint'
83
- /**
84
- * Which type to use when the Swagger/OpenAPI file is not providing more information.
85
- * - 'any' allows any value.
86
- * - 'unknown' requires type narrowing before use.
87
- * - 'void' represents no value.
88
- * @default 'any'
89
- */
90
- unknownType?: 'any' | 'unknown' | 'void'
91
- /**
92
- * Which type to use for empty schema values.
93
- * - 'any' allows any value.
94
- * - 'unknown' requires type narrowing before use.
95
- * - 'void' represents no value.
96
- * @default `unknownType`
97
- */
98
- emptySchemaType?: 'any' | 'unknown' | 'void'
99
278
  /**
100
279
  * Choose what to use as mode for an optional value.
101
280
  * - 'questionToken' marks the property as optional with ? (e.g., type?: string).
@@ -111,23 +290,6 @@ export type Options = {
111
290
  * @default 'array'
112
291
  */
113
292
  arrayType?: 'generic' | 'array'
114
- transformers?: {
115
- /**
116
- * Customize the names based on the type that is provided by the plugin.
117
- */
118
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
119
- }
120
- /**
121
- * @example
122
- * Use https://ts-ast-viewer.com to generate factory code(see createPropertySignature)
123
- * category: factory.createPropertySignature(
124
- * undefined,
125
- * factory.createIdentifier("category"),
126
- * factory.createToken(ts.SyntaxKind.QuestionToken),
127
- * factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
128
- * )
129
- */
130
- mapper?: Record<string, ts.PropertySignature>
131
293
  /**
132
294
  * How to style your params, by default no casing is applied
133
295
  * - 'camelcase' uses camelCase for pathParams, queryParams and headerParams property names
@@ -140,28 +302,55 @@ export type Options = {
140
302
  */
141
303
  generators?: Array<Generator<PluginTs>>
142
304
  /**
143
- * Unstable naming for v5
305
+ * Apply a compatibility naming preset.
306
+ * Use `kubbV4` for strict v4 type-generation compatibility.
307
+ * You can further customize naming with `resolvers`.
308
+ * @default 'default'
309
+ */
310
+ compatibilityPreset?: CompatibilityPreset
311
+ /**
312
+ * Array of named resolvers that control naming conventions.
313
+ * Later entries override earlier ones (last wins).
314
+ * Built-in: `resolverTs` (default), `resolverTsLegacy`.
315
+ * @default [resolverTs]
316
+ */
317
+ resolvers?: Array<ResolverTs>
318
+ /**
319
+ * Array of AST visitors applied to each SchemaNode/OperationNode before printing.
320
+ * Uses `transform()` from `@kubb/ast` — visitors can modify, replace, or annotate nodes.
321
+ *
322
+ * @example Remove writeOnly properties from response types
323
+ * ```ts
324
+ * transformers: [{
325
+ * property(node) {
326
+ * if (node.schema.writeOnly) return undefined
327
+ * }
328
+ * }]
329
+ * ```
330
+ *
331
+ * @example Force all dates to plain strings
332
+ * ```ts
333
+ * transformers: [{
334
+ * schema(node) {
335
+ * if (node.type === 'date') return { ...node, type: 'string' }
336
+ * }
337
+ * }]
338
+ * ```
144
339
  */
145
- UNSTABLE_NAMING?: true
340
+ transformers?: Array<Visitor>
146
341
  }
147
342
 
148
343
  type ResolvedOptions = {
149
- output: Output<Oas>
344
+ output: Output
150
345
  group: Options['group']
151
- override: NonNullable<Options['override']>
152
346
  enumType: NonNullable<Options['enumType']>
153
347
  enumKeyCasing: NonNullable<Options['enumKeyCasing']>
154
- enumSuffix: NonNullable<Options['enumSuffix']>
155
- dateType: NonNullable<Options['dateType']>
156
- integerType: NonNullable<Options['integerType']>
157
- unknownType: NonNullable<Options['unknownType']>
158
- emptySchemaType: NonNullable<Options['emptySchemaType']>
159
348
  optionalType: NonNullable<Options['optionalType']>
160
349
  arrayType: NonNullable<Options['arrayType']>
161
- transformers: NonNullable<Options['transformers']>
162
350
  syntaxType: NonNullable<Options['syntaxType']>
163
- mapper: Record<string, any>
164
351
  paramsCasing: Options['paramsCasing']
352
+ resolver: ResolverTs
353
+ transformers: Array<Visitor>
165
354
  }
166
355
 
167
- export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions>
356
+ export type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, never, ResolvePathOptions, ResolverTs, BuilderTs>