@kubb/plugin-ts 5.0.0-beta.4 → 5.0.0-beta.42

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.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import * as _$_kubb_core0 from "@kubb/core";
1
+ import { t as __name } from "./chunk-C0LytTxp.js";
3
2
  import { Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
4
3
  import ts from "typescript";
5
4
  import { KubbReactNode } from "@kubb/renderer-jsx/types";
@@ -82,7 +81,7 @@ type PrinterTsOptions = {
82
81
  * Properties to exclude using `Omit<Type, Keys>`.
83
82
  * Forces type alias syntax regardless of `syntaxType` setting.
84
83
  */
85
- keysToOmit?: Array<string>;
84
+ keysToOmit?: Array<string> | null;
86
85
  /**
87
86
  * Transforms raw schema names into valid TypeScript identifiers.
88
87
  */
@@ -238,7 +237,7 @@ type EnumTypeOptions = {
238
237
  /**
239
238
  * Suffix appended to the generated type alias name.
240
239
  *
241
- * Only affects the type alias the const object name is unchanged.
240
+ * Only affects the type alias; the const object name is unchanged.
242
241
  *
243
242
  * @default 'Key'
244
243
  * @example enumTypeSuffix: 'Value' → `export type PetStatusValue = …`
@@ -293,80 +292,88 @@ type EnumTypeOptions = {
293
292
  enumTypeSuffix?: never;
294
293
  /**
295
294
  * `enumKeyCasing` has no effect for this `enumType`.
296
- * Literal and inlineLiteral modes emit only values keys are discarded entirely.
295
+ * Literal and inlineLiteral modes emit only values; keys are discarded entirely.
297
296
  */
298
297
  enumKeyCasing?: never;
299
298
  };
300
299
  type Options = {
301
300
  /**
302
- * Specify the export location for the files and define the behavior of the output
303
- * @default { path: 'types', barrelType: 'named' }
301
+ * Where the generated `.ts` files are written and how they are exported.
302
+ *
303
+ * @default { path: 'types', barrel: { type: 'named' } }
304
304
  */
305
305
  output?: Output;
306
306
  /**
307
- * Define which contentType should be used.
308
- * By default, uses the first valid JSON media type.
307
+ * Media type read from the OpenAPI spec when an operation defines several.
308
+ * Defaults to the first JSON-compatible media type Kubb finds.
309
309
  */
310
310
  contentType?: 'application/json' | (string & {});
311
311
  /**
312
- * Group the clients based on the provided name.
312
+ * Split generated files into subfolders based on the operation's tag.
313
313
  */
314
314
  group?: Group;
315
315
  /**
316
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
316
+ * Skip operations matching at least one entry in the list.
317
317
  */
318
318
  exclude?: Array<Exclude>;
319
319
  /**
320
- * Array containing include parameters to include tags/operations/methods/paths.
320
+ * Restrict generation to operations matching at least one entry in the list.
321
321
  */
322
322
  include?: Array<Include>;
323
323
  /**
324
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
324
+ * Apply a different options object to operations matching a pattern.
325
325
  */
326
326
  override?: Array<Override<ResolvedOptions>>;
327
327
  /**
328
- * Switch between type or interface for creating TypeScript types.
329
- * - 'type' generates type alias declarations.
330
- * - 'interface' generates interface declarations.
328
+ * Whether object schemas are emitted as `type` aliases or `interface` declarations.
329
+ * - `'type'` emits closed type aliases. Safer default for generated code.
330
+ * - `'interface'` emits interfaces. Useful when consumers rely on declaration merging.
331
+ *
331
332
  * @default 'type'
333
+ * @see https://www.totaltypescript.com/type-vs-interface-which-should-you-use
332
334
  */
333
335
  syntaxType?: 'type' | 'interface';
334
336
  /**
335
- * Choose what to use as mode for an optional value.
336
- * - 'questionToken' marks the property as optional with ? (e.g., type?: string).
337
- * - 'undefined' adds undefined to the type union (e.g., type: string | undefined).
338
- * - 'questionTokenAndUndefined' combines both approaches (e.g., type?: string | undefined).
337
+ * How optional properties are written in generated types.
338
+ * - `'questionToken'` `type?: string`. The property may be missing.
339
+ * - `'undefined'` `type: string | undefined`. Required to exist, may be `undefined`.
340
+ * - `'questionTokenAndUndefined'` `type?: string | undefined`. Strictest.
341
+ *
339
342
  * @default 'questionToken'
343
+ * @note Pick `'questionTokenAndUndefined'` when `exactOptionalPropertyTypes` is on in `tsconfig.json`.
340
344
  */
341
345
  optionalType?: 'questionToken' | 'undefined' | 'questionTokenAndUndefined';
342
346
  /**
343
- * Choose between Array<string> or string[] for array types.
344
- * - 'generic' generates Array<Type> syntax.
345
- * - 'array' generates Type[] syntax.
347
+ * Syntax used for array types.
348
+ * - `'array'` `Type[]`. Shorter.
349
+ * - `'generic'` `Array<Type>`. More readable for complex element types.
350
+ *
346
351
  * @default 'array'
347
352
  */
348
353
  arrayType?: 'generic' | 'array';
349
354
  /**
350
- * How to style your params, by default no casing is applied
351
- * - 'camelcase' uses camelCase for pathParams, queryParams and headerParams property names
352
- * @default undefined
353
- * @note response types (data/body) are NOT affected by this option
355
+ * Rename properties inside `PathParams`, `QueryParams`, and `HeaderParams` types.
356
+ * Response and request body types are not affected.
357
+ *
358
+ * @note Every plugin that touches operation parameters must use the same value.
354
359
  */
355
360
  paramsCasing?: 'camelcase';
356
361
  /**
357
- * Define some generators next to the ts generators
362
+ * Custom generators that run alongside the built-in TypeScript generators.
358
363
  */
359
364
  generators?: Array<Generator<PluginTs>>;
360
365
  /**
361
- * Override naming conventions. When a method returns `null` or `undefined`, the preset
362
- * resolver (`resolverTs`) is used as fallback.
366
+ * Override how names and file paths are built for generated symbols.
367
+ * Methods you omit fall back to the default `resolverTs`. `this` is bound to the
368
+ * full resolver, so `this.default(name, 'function')` delegates to the built-in
369
+ * implementation.
363
370
  */
364
371
  resolver?: Partial<ResolverTs> & ThisType<ResolverTs>;
365
372
  /**
366
- * AST visitor applied to each schema/operation node before printing.
367
- * Returning `null` or `undefined` from a visitor method falls back to the preset transformer.
373
+ * AST visitor applied to each schema or operation node before printing.
374
+ * Methods you omit fall back to the preset transformer.
368
375
  *
369
- * @example Remove writeOnly properties from response types
376
+ * @example Drop writeOnly properties from response types
370
377
  * ```ts
371
378
  * transformer: {
372
379
  * property(node) {
@@ -377,18 +384,17 @@ type Options = {
377
384
  */
378
385
  transformer?: ast.Visitor;
379
386
  /**
380
- * Override individual printer node handlers to customize rendering of specific schema types.
381
- *
382
- * Each key is a `SchemaType` (e.g. `'date'`, `'string'`). The function replaces the
383
- * built-in handler for that type. Use `this.transform` to recurse into nested schema nodes.
387
+ * Replace the TypeScript handler for a specific schema type (`'integer'`, `'date'`, ...).
388
+ * Each handler returns a TypeScript AST node for that schema type. Use `this.transform`
389
+ * to recurse into nested schema nodes.
384
390
  *
385
- * @example Override the `date` node to use the `Date` object type
391
+ * @example Use the JavaScript `Date` object for date schemas
386
392
  * ```ts
387
393
  * import ts from 'typescript'
388
394
  * pluginTs({
389
395
  * printer: {
390
396
  * nodes: {
391
- * date(node) {
397
+ * date() {
392
398
  * return ts.factory.createTypeReferenceNode('Date', [])
393
399
  * },
394
400
  * },
@@ -405,7 +411,7 @@ type ResolvedOptions = {
405
411
  exclude: Array<Exclude>;
406
412
  include: Array<Include> | undefined;
407
413
  override: Array<Override<ResolvedOptions>>;
408
- group: Group | undefined;
414
+ group: Group | null;
409
415
  enumType: NonNullable<Options['enumType']>;
410
416
  enumTypeSuffix: NonNullable<Options['enumTypeSuffix']>;
411
417
  enumKeyCasing: EnumKeyCasing;
@@ -484,30 +490,45 @@ declare function Type({
484
490
  }: Props): KubbReactNode;
485
491
  //#endregion
486
492
  //#region src/generators/typeGenerator.d.ts
487
- declare const typeGenerator: _$_kubb_core0.Generator<PluginTs, unknown>;
493
+ /**
494
+ * Built-in generator for `@kubb/plugin-ts`. Emits one TypeScript file per
495
+ * schema in the spec plus per-operation request, response, and parameter
496
+ * types. Drop-replace with a custom `Generator<PluginTs>` to change how
497
+ * TypeScript output is produced.
498
+ */
499
+ declare const typeGenerator: import("@kubb/core").Generator<PluginTs, unknown>;
488
500
  //#endregion
489
501
  //#region src/plugin.d.ts
490
502
  /**
491
- * Canonical plugin name for `@kubb/plugin-ts`, used to identify the plugin in driver lookups and warnings.
503
+ * Canonical plugin name for `@kubb/plugin-ts`. Used for driver lookups and
504
+ * cross-plugin dependency references.
492
505
  */
493
506
  declare const pluginTsName = "plugin-ts";
494
507
  /**
495
- * The `@kubb/plugin-ts` plugin factory.
496
- *
497
- * Generates TypeScript type declarations from an OpenAPI/AST `RootNode`.
498
- * Walks schemas and operations, delegates rendering to the active generators,
499
- * and writes barrel files based on `output.barrelType`.
508
+ * Generates TypeScript `type` aliases and `interface` declarations from an
509
+ * OpenAPI spec. The foundation that every other Kubb plugin builds on:
510
+ * clients, query hooks, mocks, and validators all reference the names this
511
+ * plugin produces.
500
512
  *
501
513
  * @example
502
514
  * ```ts
503
- * import pluginTs from '@kubb/plugin-ts'
515
+ * import { defineConfig } from 'kubb'
516
+ * import { pluginTs } from '@kubb/plugin-ts'
504
517
  *
505
518
  * export default defineConfig({
506
- * plugins: [pluginTs({ output: { path: 'types' }, enumType: 'asConst' })],
519
+ * input: { path: './petStore.yaml' },
520
+ * output: { path: './src/gen' },
521
+ * plugins: [
522
+ * pluginTs({
523
+ * output: { path: './types' },
524
+ * enumType: 'asConst',
525
+ * optionalType: 'questionTokenAndUndefined',
526
+ * }),
527
+ * ],
507
528
  * })
508
529
  * ```
509
530
  */
510
- declare const pluginTs: (options?: Options | undefined) => _$_kubb_core0.Plugin<PluginTs>;
531
+ declare const pluginTs: (options?: Options | undefined) => import("@kubb/core").Plugin<PluginTs>;
511
532
  //#endregion
512
533
  //#region src/printers/functionPrinter.d.ts
513
534
  type FunctionPrinterOptions = {
@@ -552,26 +573,27 @@ type FunctionPrinterOptions = {
552
573
  declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
553
574
  name: "functionParameters";
554
575
  options: FunctionPrinterOptions;
555
- transform: (node: ast.FunctionParamNode) => string | null | undefined;
556
- print: (node: ast.FunctionParamNode) => string | null | undefined;
576
+ transform: (node: ast.FunctionParamNode) => string | null;
577
+ print: (node: ast.FunctionParamNode) => string | null;
557
578
  };
558
579
  //#endregion
559
580
  //#region src/resolvers/resolverTs.d.ts
560
581
  /**
561
- * Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
562
- * helpers used by the plugin. Import this in other plugins to resolve the exact names and
563
- * paths that `plugin-ts` generates without hardcoding the conventions.
582
+ * Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
583
+ * for every generated TypeScript type. Import this in other plugins that need
584
+ * to reference the exact names `plugin-ts` produces without duplicating the
585
+ * casing/file-layout rules.
564
586
  *
565
- * The `default` method is automatically injected by `defineResolver` it uses `camelCase`
566
- * for identifiers/files and `pascalCase` for type names.
587
+ * The `default` method is supplied by `defineResolver`. It uses PascalCase for
588
+ * type names and PascalCase-with-isFile for files.
567
589
  *
568
- * @example
590
+ * @example Resolve a type and file name
569
591
  * ```ts
570
- * import { resolver } from '@kubb/plugin-ts'
592
+ * import { resolverTs } from '@kubb/plugin-ts'
571
593
  *
572
- * resolver.default('list pets', 'type') // 'ListPets'
573
- * resolver.resolveName('list pets status 200') // 'ListPetsStatus200'
574
- * resolver.resolvePathName('list pets', 'file') // 'listPets'
594
+ * resolverTs.default('list pets', 'type') // 'ListPets'
595
+ * resolverTs.resolvePathName('list pets', 'file') // 'ListPets'
596
+ * resolverTs.resolveResponseStatusName(node, 200) // 'ListPetsStatus200'
575
597
  * ```
576
598
  */
577
599
  declare const resolverTs: ResolverTs;