@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/README.md +39 -22
- package/dist/index.cjs +432 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +84 -62
- package/dist/index.js +427 -125
- package/dist/index.js.map +1 -1
- package/extension.yaml +713 -265
- package/package.json +10 -12
- package/src/components/Enum.tsx +3 -3
- package/src/factory.ts +54 -25
- package/src/generators/typeGenerator.tsx +100 -39
- package/src/plugin.ts +20 -21
- package/src/printers/functionPrinter.ts +2 -2
- package/src/printers/printerTs.ts +31 -30
- package/src/resolvers/resolverTs.ts +28 -25
- package/src/types.ts +44 -37
- package/src/utils.ts +23 -13
- /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { t as __name } from "./chunk
|
|
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
|
|
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
|
|
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
|
-
*
|
|
303
|
-
*
|
|
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
|
-
*
|
|
308
|
-
*
|
|
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
|
-
*
|
|
312
|
+
* Split generated files into subfolders based on the operation's tag.
|
|
313
313
|
*/
|
|
314
314
|
group?: Group;
|
|
315
315
|
/**
|
|
316
|
-
*
|
|
316
|
+
* Skip operations matching at least one entry in the list.
|
|
317
317
|
*/
|
|
318
318
|
exclude?: Array<Exclude>;
|
|
319
319
|
/**
|
|
320
|
-
*
|
|
320
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
321
321
|
*/
|
|
322
322
|
include?: Array<Include>;
|
|
323
323
|
/**
|
|
324
|
-
*
|
|
324
|
+
* Apply a different options object to operations matching a pattern.
|
|
325
325
|
*/
|
|
326
326
|
override?: Array<Override<ResolvedOptions>>;
|
|
327
327
|
/**
|
|
328
|
-
*
|
|
329
|
-
* - 'type'
|
|
330
|
-
* - 'interface'
|
|
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
|
-
*
|
|
336
|
-
* - 'questionToken'
|
|
337
|
-
* - 'undefined'
|
|
338
|
-
* - 'questionTokenAndUndefined'
|
|
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
|
-
*
|
|
344
|
-
* - '
|
|
345
|
-
* - '
|
|
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
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
* @note
|
|
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
|
-
*
|
|
362
|
+
* Custom generators that run alongside the built-in TypeScript generators.
|
|
358
363
|
*/
|
|
359
364
|
generators?: Array<Generator<PluginTs>>;
|
|
360
365
|
/**
|
|
361
|
-
* Override
|
|
362
|
-
*
|
|
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
|
|
367
|
-
*
|
|
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
|
|
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
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
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
|
|
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(
|
|
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 |
|
|
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
|
-
|
|
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
|
|
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
|
-
*
|
|
496
|
-
*
|
|
497
|
-
*
|
|
498
|
-
*
|
|
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
|
|
515
|
+
* import { defineConfig } from 'kubb'
|
|
516
|
+
* import { pluginTs } from '@kubb/plugin-ts'
|
|
504
517
|
*
|
|
505
518
|
* export default defineConfig({
|
|
506
|
-
*
|
|
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) =>
|
|
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
|
|
556
|
-
print: (node: ast.FunctionParamNode) => string | null
|
|
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
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
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
|
|
566
|
-
*
|
|
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 {
|
|
592
|
+
* import { resolverTs } from '@kubb/plugin-ts'
|
|
571
593
|
*
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
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;
|