@kubb/plugin-ts 5.0.0-beta.64 → 5.0.0-beta.73

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,8 +1,56 @@
1
- import { t as __name } from "./chunk-C0LytTxp.js";
1
+ import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
2
2
  import ts from "typescript";
3
- import { Exclude, Generator, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
3
+ import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "@kubb/core";
4
4
  import { KubbReactNode } from "@kubb/renderer-jsx/types";
5
+ import { OperationNode } from "@kubb/ast";
5
6
 
7
+ //#region ../../internals/shared/src/operation.d.ts
8
+ /**
9
+ * Resolver interface for building operation parameters.
10
+ *
11
+ * `ResolverTs` from `@kubb/plugin-ts` satisfies this interface and can be passed directly.
12
+ */
13
+ type OperationParamsResolver = {
14
+ /**
15
+ * Resolves the type name for an individual parameter.
16
+ *
17
+ * @example Individual path parameter name
18
+ * `resolver.resolveParamName(node, param) // → 'DeletePetPathPetId'`
19
+ */
20
+ resolveParamName(node: ast.OperationNode, param: ast.ParameterNode): string;
21
+ /**
22
+ * Resolves the request body type name.
23
+ *
24
+ * @example Request body type name
25
+ * `resolver.resolveDataName(node) // → 'CreatePetData'`
26
+ */
27
+ resolveDataName(node: ast.OperationNode): string;
28
+ /**
29
+ * Resolves the grouped path parameters type name.
30
+ * When the return value equals `resolveParamName`, no indexed access is emitted.
31
+ *
32
+ * @example Grouped path params type name
33
+ * `resolver.resolvePathParamsName(node, param) // → 'DeletePetPathParams'`
34
+ */
35
+ resolvePathParamsName(node: ast.OperationNode, param: ast.ParameterNode): string;
36
+ /**
37
+ * Resolves the grouped query parameters type name.
38
+ * When the return value equals `resolveParamName`, an inline struct type is emitted instead.
39
+ *
40
+ * @example Grouped query params type name
41
+ * `resolver.resolveQueryParamsName(node, param) // → 'FindPetsByStatusQueryParams'`
42
+ */
43
+ resolveQueryParamsName(node: ast.OperationNode, param: ast.ParameterNode): string;
44
+ /**
45
+ * Resolves the grouped header parameters type name.
46
+ * When the return value equals `resolveParamName`, an inline struct type is emitted instead.
47
+ *
48
+ * @example Grouped header params type name
49
+ * `resolver.resolveHeaderParamsName(node, param) // → 'DeletePetHeaderParams'`
50
+ */
51
+ resolveHeaderParamsName(node: ast.OperationNode, param: ast.ParameterNode): string;
52
+ };
53
+ //#endregion
6
54
  //#region src/printers/printerTs.d.ts
7
55
  /**
8
56
  * Partial map of node-type overrides for the TypeScript printer.
@@ -118,7 +166,7 @@ declare const printerTs: (options?: PrinterTsOptions | undefined) => ast.Printer
118
166
  * Extends the base `Resolver` (which provides `default` and `resolveOptions`) with
119
167
  * plugin-specific naming helpers for operations, parameters, responses, and schemas.
120
168
  */
121
- type ResolverTs = Resolver & ast.OperationParamsResolver & {
169
+ type ResolverTs = Resolver & OperationParamsResolver & {
122
170
  /**
123
171
  * Resolves the name for a given raw name (equivalent to `default(name, 'function')`).
124
172
  * Since TypeScript only emits types, this is the canonical naming method.
@@ -149,6 +197,9 @@ type ResolverTs = Resolver & ast.OperationParamsResolver & {
149
197
  /**
150
198
  * Resolves the name for an operation's request config (`RequestConfig`).
151
199
  *
200
+ * The `RequestConfig` suffix is kept through the v5 beta to avoid churn, but it overlaps with the
201
+ * runtime client's `RequestConfig`. Renaming to `Request` is on the table before stable.
202
+ *
152
203
  * @example Request config names
153
204
  * `resolver.resolveRequestConfigName(node) // → 'ListPetsRequestConfig'`
154
205
  */
@@ -349,17 +400,6 @@ type Options = OutputOptions & {
349
400
  * @default 'array'
350
401
  */
351
402
  arrayType?: 'generic' | 'array';
352
- /**
353
- * Rename properties inside `PathParams`, `QueryParams`, and `HeaderParams` types.
354
- * Response and request body types are not affected.
355
- *
356
- * @note Every plugin that touches operation parameters must use the same value.
357
- */
358
- paramsCasing?: 'camelcase';
359
- /**
360
- * Custom generators that run alongside the built-in TypeScript generators.
361
- */
362
- generators?: Array<Generator<PluginTs>>;
363
403
  /**
364
404
  * Override how names and file paths are built for generated symbols.
365
405
  * Methods you omit fall back to the default `resolverTs`. `this` is bound to the
@@ -427,7 +467,6 @@ type ResolvedOptions = {
427
467
  optionalType: NonNullable<Options['optionalType']>;
428
468
  arrayType: NonNullable<Options['arrayType']>;
429
469
  syntaxType: NonNullable<Options['syntaxType']>;
430
- paramsCasing: Options['paramsCasing'];
431
470
  printer: Options['printer'];
432
471
  };
433
472
  type PluginTs = PluginFactoryOptions<'plugin-ts', Options, ResolvedOptions, ResolverTs>;
@@ -535,9 +574,210 @@ declare const pluginTsName = "plugin-ts";
535
574
  */
536
575
  declare const pluginTs: (options?: Options | undefined) => import("@kubb/core").Plugin<PluginTs>;
537
576
  //#endregion
577
+ //#region src/printers/functionParams.d.ts
578
+ /**
579
+ * A type expression used as a function parameter type annotation.
580
+ *
581
+ * - a plain `string` is a type reference rendered as-is, e.g. `'string'`, `'QueryParams'`, `'Partial<Config>'`
582
+ * - a {@link TypeLiteralNode} is an inline anonymous type, e.g. `{ petId: string; name?: string }`
583
+ * - an {@link IndexedAccessTypeNode} is a single field accessed from a named type, e.g. `PathParams['petId']`
584
+ */
585
+ type TypeExpression = string | TypeLiteralNode | IndexedAccessTypeNode;
586
+ /**
587
+ * An inline anonymous object type grouping named fields.
588
+ * Renders as `{ key: Type; other?: OtherType }`.
589
+ */
590
+ type TypeLiteralNode = {
591
+ kind: 'TypeLiteral';
592
+ /**
593
+ * Members of the object type, rendered in order.
594
+ */
595
+ members: Array<{
596
+ /**
597
+ * Member key.
598
+ */
599
+ name: string;
600
+ /**
601
+ * Member type expression.
602
+ */
603
+ type: TypeExpression;
604
+ /**
605
+ * Whether the member is optional, rendered with `?`.
606
+ */
607
+ optional?: boolean;
608
+ }>;
609
+ };
610
+ /**
611
+ * A single field accessed from a named group type. Renders as `target['key']`.
612
+ */
613
+ type IndexedAccessTypeNode = {
614
+ kind: 'IndexedAccessType';
615
+ /**
616
+ * Name of the type being indexed, e.g. `'GetPetPathParams'`.
617
+ */
618
+ target: string;
619
+ /**
620
+ * Field key to access, e.g. `'petId'`.
621
+ */
622
+ key: string;
623
+ };
624
+ /**
625
+ * An object destructuring binding, used as the name of a grouped function parameter.
626
+ * Renders as `{ id, name }` or `{ id: renamed }` when `propertyName` differs.
627
+ */
628
+ type ObjectBindingPatternNode = {
629
+ kind: 'ObjectBindingPattern';
630
+ /**
631
+ * Bound elements, rendered in order.
632
+ */
633
+ elements: Array<{
634
+ /**
635
+ * Local binding name.
636
+ */
637
+ name: string;
638
+ /**
639
+ * Source key when it differs from the binding name, rendered as `propertyName: name`.
640
+ */
641
+ propertyName?: string;
642
+ }>;
643
+ };
644
+ /**
645
+ * One function parameter.
646
+ *
647
+ * A simple parameter has a `string` name. A destructured group has an
648
+ * {@link ObjectBindingPatternNode} name paired with a {@link TypeLiteralNode} type.
649
+ *
650
+ * @example Required parameter
651
+ * `name: Type`
652
+ *
653
+ * @example Optional parameter
654
+ * `name?: Type`
655
+ *
656
+ * @example Parameter with default value
657
+ * `name: Type = defaultValue`
658
+ *
659
+ * @example Rest parameter
660
+ * `...name: Type[]`
661
+ *
662
+ * @example Destructured group
663
+ * `{ id, name? }: { id: string; name?: string } = {}`
664
+ */
665
+ type FunctionParameterNode = {
666
+ kind: 'FunctionParameter';
667
+ /**
668
+ * Parameter name, or an {@link ObjectBindingPatternNode} for a destructured group.
669
+ */
670
+ name: string | ObjectBindingPatternNode;
671
+ /**
672
+ * Type annotation as a {@link TypeExpression}. Omit for untyped output.
673
+ */
674
+ type?: TypeExpression;
675
+ /**
676
+ * Whether the parameter is optional, rendered with `?`.
677
+ */
678
+ optional?: boolean;
679
+ /**
680
+ * Default value, written verbatim after `=`. Commonly `'{}'` for a destructured group.
681
+ */
682
+ default?: string;
683
+ /**
684
+ * When `true` the parameter is emitted as a rest parameter, e.g. `...name: Type[]`.
685
+ */
686
+ rest?: boolean;
687
+ };
688
+ /**
689
+ * A complete function parameter list.
690
+ *
691
+ * Printers are responsible for sorting (`required` → `optional` → `defaulted`).
692
+ */
693
+ type FunctionParametersNode = {
694
+ kind: 'FunctionParameters';
695
+ /**
696
+ * Ordered parameter nodes.
697
+ */
698
+ params: ReadonlyArray<FunctionParameterNode>;
699
+ };
700
+ /**
701
+ * Creates a {@link TypeLiteralNode} representing an inline anonymous object type.
702
+ *
703
+ * @example
704
+ * ```ts
705
+ * createTypeLiteral({ members: [{ name: 'petId', type: 'string', optional: false }] })
706
+ * // { petId: string }
707
+ * ```
708
+ */
709
+ declare function createTypeLiteral(props: Omit<TypeLiteralNode, 'kind'>): TypeLiteralNode;
710
+ /**
711
+ * Creates an {@link IndexedAccessTypeNode} representing a single field accessed from a named type.
712
+ *
713
+ * @example
714
+ * ```ts
715
+ * createIndexedAccessType({ target: 'DeletePetPathParams', key: 'petId' })
716
+ * // DeletePetPathParams['petId']
717
+ * ```
718
+ */
719
+ declare function createIndexedAccessType(props: Omit<IndexedAccessTypeNode, 'kind'>): IndexedAccessTypeNode;
720
+ /**
721
+ * Creates an {@link ObjectBindingPatternNode} for a destructured parameter binding.
722
+ *
723
+ * @example
724
+ * ```ts
725
+ * createObjectBindingPattern({ elements: [{ name: 'id' }, { name: 'name' }] })
726
+ * // { id, name }
727
+ * ```
728
+ */
729
+ declare function createObjectBindingPattern(props: Omit<ObjectBindingPatternNode, 'kind'>): ObjectBindingPatternNode;
730
+ /**
731
+ * Plain property descriptor for a destructured group built by {@link createFunctionParameter}.
732
+ */
733
+ type FunctionParameterProperty = {
734
+ name: string;
735
+ type: TypeExpression;
736
+ optional?: boolean;
737
+ };
738
+ type FunctionParameterInput = {
739
+ name: string | ObjectBindingPatternNode;
740
+ type?: TypeExpression;
741
+ optional?: boolean;
742
+ default?: string;
743
+ rest?: boolean;
744
+ } | {
745
+ properties: Array<FunctionParameterProperty>;
746
+ optional?: boolean;
747
+ default?: string;
748
+ };
749
+ /**
750
+ * Creates a {@link FunctionParameterNode}. `optional` defaults to `false`.
751
+ * Passing `properties` builds a destructured group: an {@link ObjectBindingPatternNode} name
752
+ * paired with a {@link TypeLiteralNode} type.
753
+ *
754
+ * @example Optional param
755
+ * ```ts
756
+ * createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })
757
+ * // → params?: QueryParams
758
+ * ```
759
+ *
760
+ * @example Destructured group
761
+ * ```ts
762
+ * createFunctionParameter({ properties: [{ name: 'id', type: 'string' }, { name: 'name', type: 'string', optional: true }], default: '{}' })
763
+ * // → { id, name }: { id: string; name?: string } = {}
764
+ * ```
765
+ */
766
+ declare function createFunctionParameter(input: FunctionParameterInput): FunctionParameterNode;
767
+ /**
768
+ * Creates a {@link FunctionParametersNode} from an ordered list of parameters.
769
+ *
770
+ * @example
771
+ * ```ts
772
+ * const empty = createFunctionParameters()
773
+ * // { params: [] }
774
+ * ```
775
+ */
776
+ declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
777
+ //#endregion
538
778
  //#region src/printers/functionPrinter.d.ts
539
779
  /**
540
- * Renders a {@link ast.TypeExpression} to its TypeScript source.
780
+ * Renders a {@link TypeExpression} to its TypeScript source.
541
781
  *
542
782
  * - a `string` is a type reference, returned as-is
543
783
  * - an `IndexedAccessType` becomes `objectType['indexType']`
@@ -546,7 +786,7 @@ declare const pluginTs: (options?: Options | undefined) => import("@kubb/core").
546
786
  * `transformType` is applied once to the fully rendered type, matching how the
547
787
  * printer wrapped reference types before the `ts.factory` model.
548
788
  */
549
- declare function renderType(type: ast.TypeExpression, transformType?: (type: string) => string): string;
789
+ declare function renderType(type: TypeExpression, transformType?: (type: string) => string): string;
550
790
  type FunctionPrinterOptions = {
551
791
  /**
552
792
  * Rendering modes supported by `functionPrinter`.
@@ -584,13 +824,102 @@ type FunctionPrinterOptions = {
584
824
  * printer.print(sig) // → "petId: string, config: Config = {}"
585
825
  * ```
586
826
  */
587
- declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) => {
827
+ declare function functionPrinter(options: FunctionPrinterOptions): {
588
828
  name: "functionParameters";
589
829
  options: FunctionPrinterOptions;
590
- transform: (node: ast.FunctionParamNode) => string | null;
591
- print: (node: ast.FunctionParamNode) => string | null;
830
+ print(node: FunctionParametersNode): string;
592
831
  };
593
832
  //#endregion
833
+ //#region src/printers/operationParams.d.ts
834
+ /**
835
+ * Options for {@link createOperationParams}.
836
+ */
837
+ type CreateOperationParamsOptions = {
838
+ /**
839
+ * How all operation parameters are grouped in the function signature.
840
+ * - `'object'` wraps all params into a single destructured object `{ petId, data, params }`
841
+ * - `'inline'` emits each param category as a separate top-level parameter
842
+ */
843
+ paramsType: 'object' | 'inline';
844
+ /**
845
+ * How path parameters are emitted when `paramsType` is `'inline'`.
846
+ * - `'object'` groups them as `{ petId, storeId }: PathParams`
847
+ * - `'inline'` spreads them as individual parameters `petId: string, storeId: string`
848
+ * - `'inlineSpread'` emits a single rest parameter `...pathParams: PathParams`
849
+ */
850
+ pathParamsType: 'object' | 'inline' | 'inlineSpread';
851
+ /**
852
+ * Converts parameter names to camelCase before output.
853
+ */
854
+ paramsCasing?: 'camelcase';
855
+ /**
856
+ * Resolver for parameter and request body type names.
857
+ * Pass `ResolverTs` from `@kubb/plugin-ts` directly.
858
+ * When omitted, falls back to the schema primitive or `'unknown'`.
859
+ */
860
+ resolver?: OperationParamsResolver;
861
+ /**
862
+ * Default value for the path parameters binding when `pathParamsType` is `'object'`.
863
+ * Falls back to `'{}'` when all path params are optional.
864
+ */
865
+ pathParamsDefault?: string;
866
+ /**
867
+ * Extra parameters appended after the standard operation parameters.
868
+ *
869
+ * @example Plugin-specific trailing parameter
870
+ * ```ts
871
+ * extraParams: [createFunctionParameter({ name: 'options', type: 'Partial<RequestOptions>', default: '{}' })]
872
+ * ```
873
+ */
874
+ extraParams?: Array<FunctionParameterNode>;
875
+ /**
876
+ * Override the default parameter names used for body, query, header, and rest-path groups.
877
+ *
878
+ * Useful when targeting languages or frameworks with different naming conventions.
879
+ *
880
+ * @default { data: 'data', params: 'params', headers: 'headers', path: 'pathParams' }
881
+ */
882
+ paramNames?: {
883
+ /**
884
+ * Name for the request body parameter.
885
+ * @default 'data'
886
+ */
887
+ data?: string;
888
+ /**
889
+ * Name for the query parameters group parameter.
890
+ * @default 'params'
891
+ */
892
+ params?: string;
893
+ /**
894
+ * Name for the header parameters group parameter.
895
+ * @default 'headers'
896
+ */
897
+ headers?: string;
898
+ /**
899
+ * Name for the rest path-parameters parameter when `pathParamsType` is `'inlineSpread'`.
900
+ * @default 'pathParams'
901
+ */
902
+ path?: string;
903
+ };
904
+ /**
905
+ * Transforms every resolved type name before it lands in a parameter node, for framework-level
906
+ * type wrappers.
907
+ *
908
+ * @example Vue Query, wrap every parameter type with `MaybeRefOrGetter`
909
+ * `typeWrapper: (t) => \`MaybeRefOrGetter<${t}>\``
910
+ */
911
+ typeWrapper?: (type: string) => string;
912
+ };
913
+ /**
914
+ * Converts an `OperationNode` into function parameters for code generation.
915
+ *
916
+ * Centralizes parameter grouping logic for all plugins. `paramsType` chooses between one
917
+ * destructured object parameter (`object`) and separate top-level parameters (`inline`), while
918
+ * `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type
919
+ * name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.
920
+ */
921
+ declare function createOperationParams(node: OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
922
+ //#endregion
594
923
  //#region src/resolvers/resolverTs.d.ts
595
924
  /**
596
925
  * Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
@@ -612,5 +941,5 @@ declare const functionPrinter: (options?: FunctionPrinterOptions | undefined) =>
612
941
  */
613
942
  declare const resolverTs: ResolverTs;
614
943
  //#endregion
615
- export { Enum, type PluginTs, type PrinterTsFactory, type PrinterTsNodes, type PrinterTsOptions, type ResolverTs, Type, pluginTs as default, pluginTs, functionPrinter, pluginTsName, printerTs, renderType, resolverTs, typeGenerator };
944
+ 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, createFunctionParameter, createFunctionParameters, createIndexedAccessType, createObjectBindingPattern, createOperationParams, createTypeLiteral, pluginTs as default, pluginTs, functionPrinter, pluginTsName, printerTs, renderType, resolverTs, typeGenerator };
616
945
  //# sourceMappingURL=index.d.ts.map