@kubb/plugin-ts 5.3.0-canary.20261025T201031 → 5.3.0
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.cjs +207 -92
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -237
- package/dist/index.d.ts +2 -237
- package/dist/index.js +207 -92
- package/dist/index.js.map +1 -1
- package/kubb-extension.json +1 -1
- package/package.json +6 -6
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
2
|
import { KubbReactNode } from "kubb/jsx";
|
|
3
|
-
declare namespace factory_d_exports {
|
|
4
|
-
export { TsNode, appendJSDocToNode, buildIndexSignatures, buildMemberNodes, buildPropertyType, buildTupleNode, constToTypeNode, createArrayDeclaration, createEnumDeclaration, createIntersectionDeclaration, createOmitDeclaration, createPropertySignature, createRaw, createTypeDeclaration, createTypeLiteralNode, createTypeReferenceNode, createUnionDeclaration, createUrlTemplateType, dateOrStringNode, isNonNullable, keywordTypeNodes, print, wrapNullableOptional };
|
|
5
|
-
}
|
|
6
3
|
/**
|
|
7
4
|
* A TS-ESTree node, the AST shape `yuku-codegen` prints. Nodes built here carry no source positions.
|
|
8
5
|
*/
|
|
@@ -10,218 +7,6 @@ type TsNode = {
|
|
|
10
7
|
type: string;
|
|
11
8
|
[key: string]: unknown;
|
|
12
9
|
};
|
|
13
|
-
declare function isNonNullable<T>(value: T | null | undefined): value is T;
|
|
14
|
-
/**
|
|
15
|
-
* Prints `node` as TypeScript source with single quotes and two-space indentation.
|
|
16
|
-
*/
|
|
17
|
-
declare function print(node: TsNode): string;
|
|
18
|
-
/**
|
|
19
|
-
* Wraps already printed TypeScript, such as a user override result, so it can sit inside a node tree.
|
|
20
|
-
* Parentheses keep a union or function type intact when it lands inside an array or intersection.
|
|
21
|
-
*/
|
|
22
|
-
declare function createRaw(text: string): TsNode;
|
|
23
|
-
/**
|
|
24
|
-
* Creates a TypeScript intersection type.
|
|
25
|
-
* Returns the single type if only one is provided. `yuku-codegen` adds the parentheses a union member needs.
|
|
26
|
-
*/
|
|
27
|
-
declare function createIntersectionDeclaration({ nodes, withParentheses }: {
|
|
28
|
-
nodes: Array<TsNode>;
|
|
29
|
-
withParentheses?: boolean;
|
|
30
|
-
}): TsNode | null;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a TypeScript array type.
|
|
33
|
-
* Use `arrayType: 'array'` for bracket syntax (`T[]`), or `'generic'` for `Array<T>`.
|
|
34
|
-
*
|
|
35
|
-
* @example Array bracket syntax
|
|
36
|
-
* `createArrayDeclaration({ nodes: [string], arrayType: 'array' }) // → string[]`
|
|
37
|
-
*
|
|
38
|
-
* @example Generic Array syntax
|
|
39
|
-
* `createArrayDeclaration({ nodes: [string], arrayType: 'generic' }) // → Array<string>`
|
|
40
|
-
*/
|
|
41
|
-
declare function createArrayDeclaration({ nodes, arrayType }: {
|
|
42
|
-
nodes: Array<TsNode>;
|
|
43
|
-
arrayType?: 'array' | 'generic';
|
|
44
|
-
}): TsNode;
|
|
45
|
-
/**
|
|
46
|
-
* Minimum nodes length of 2
|
|
47
|
-
* @example Union type example
|
|
48
|
-
* `string | number`
|
|
49
|
-
*/
|
|
50
|
-
declare function createUnionDeclaration({ nodes, withParentheses }: {
|
|
51
|
-
nodes: Array<TsNode>;
|
|
52
|
-
withParentheses?: boolean;
|
|
53
|
-
}): TsNode;
|
|
54
|
-
/**
|
|
55
|
-
* Creates a TypeScript property signature for object/interface members.
|
|
56
|
-
* Supports optional markers, readonly modifiers, and type annotations.
|
|
57
|
-
*/
|
|
58
|
-
declare function createPropertySignature({ readOnly, name, questionToken, type }: {
|
|
59
|
-
readOnly?: boolean;
|
|
60
|
-
name: string;
|
|
61
|
-
questionToken?: boolean;
|
|
62
|
-
type?: TsNode;
|
|
63
|
-
}): TsNode;
|
|
64
|
-
/**
|
|
65
|
-
* Attaches a JSDoc block built from `comments` to `node`, dropping empty comments.
|
|
66
|
-
*/
|
|
67
|
-
declare function appendJSDocToNode<TNode extends TsNode>({ node, comments }: {
|
|
68
|
-
node: TNode;
|
|
69
|
-
comments: Array<string | undefined>;
|
|
70
|
-
}): TNode;
|
|
71
|
-
/**
|
|
72
|
-
* Creates a TypeScript type literal (anonymous object type) with one member per line.
|
|
73
|
-
*/
|
|
74
|
-
declare function createTypeLiteralNode(members: Array<TsNode>): TsNode;
|
|
75
|
-
/**
|
|
76
|
-
* Creates a TypeScript type reference (e.g., `Array<string>`, `Record<K, V>`).
|
|
77
|
-
*/
|
|
78
|
-
declare function createTypeReferenceNode(name: string, typeArguments?: Array<TsNode>): TsNode;
|
|
79
|
-
/**
|
|
80
|
-
* Prints a TypeScript type declaration as either a type alias or interface.
|
|
81
|
-
* Uses interface syntax only when requested and the type is an object literal, and attaches JSDoc comments.
|
|
82
|
-
*/
|
|
83
|
-
declare function createTypeDeclaration({ syntax, isExportable, comments, name, type }: {
|
|
84
|
-
syntax: 'type' | 'interface';
|
|
85
|
-
comments: Array<string | undefined>;
|
|
86
|
-
isExportable?: boolean;
|
|
87
|
-
name: string;
|
|
88
|
-
type: TsNode;
|
|
89
|
-
}): string;
|
|
90
|
-
/**
|
|
91
|
-
* Creates a TypeScript enum declaration or equivalent construct in various formats.
|
|
92
|
-
* Returns a tuple of [name declaration, type declaration] - the name declaration may be undefined for certain types.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* const [name, type] = createEnumDeclaration({
|
|
97
|
-
* type: 'enum',
|
|
98
|
-
* name: 'petType',
|
|
99
|
-
* typeName: 'PetType',
|
|
100
|
-
* enums: [['cat', 'cat', 'A cat'], ['dog', 'dog']],
|
|
101
|
-
* })
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
declare function createEnumDeclaration({ type, name, typeName, enums, enumKeyCasing }: {
|
|
105
|
-
/**
|
|
106
|
-
* Choose to use `enum`, `asConst`, `constEnum`, or `literal` for enums.
|
|
107
|
-
* - `enum`: TypeScript enum
|
|
108
|
-
* - `asConst`: const object asserted with `as const` (the caller decides the const name casing)
|
|
109
|
-
* - `constEnum`: const enum
|
|
110
|
-
* - `literal`: literal union type
|
|
111
|
-
* @default `'enum'`
|
|
112
|
-
*/
|
|
113
|
-
type?: 'enum' | 'asConst' | 'constEnum' | 'literal' | 'inlineLiteral';
|
|
114
|
-
/**
|
|
115
|
-
* Enum name in camelCase.
|
|
116
|
-
*/
|
|
117
|
-
name: string;
|
|
118
|
-
/**
|
|
119
|
-
* Enum name in PascalCase.
|
|
120
|
-
*/
|
|
121
|
-
typeName: string;
|
|
122
|
-
enums: Array<[key: string | number, value: string | number | boolean, description?: string]>;
|
|
123
|
-
/**
|
|
124
|
-
* Choose the casing for enum key names.
|
|
125
|
-
* @default 'none'
|
|
126
|
-
*/
|
|
127
|
-
enumKeyCasing?: 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none';
|
|
128
|
-
}): [name: string | undefined, type: string];
|
|
129
|
-
/**
|
|
130
|
-
* Creates a TypeScript `Omit<T, Keys>` type reference.
|
|
131
|
-
* Optionally wraps the type in `NonNullable<T>` if `nonNullable` is true.
|
|
132
|
-
*/
|
|
133
|
-
declare function createOmitDeclaration({ keys, type, nonNullable }: {
|
|
134
|
-
keys: Array<string> | string;
|
|
135
|
-
type: TsNode;
|
|
136
|
-
nonNullable?: boolean;
|
|
137
|
-
}): TsNode;
|
|
138
|
-
/**
|
|
139
|
-
* TypeScript keyword types for common primitive types.
|
|
140
|
-
*/
|
|
141
|
-
declare const keywordTypeNodes: {
|
|
142
|
-
readonly any: {
|
|
143
|
-
readonly type: 'TSAnyKeyword';
|
|
144
|
-
};
|
|
145
|
-
readonly unknown: {
|
|
146
|
-
readonly type: 'TSUnknownKeyword';
|
|
147
|
-
};
|
|
148
|
-
readonly void: {
|
|
149
|
-
readonly type: 'TSVoidKeyword';
|
|
150
|
-
};
|
|
151
|
-
readonly number: {
|
|
152
|
-
readonly type: 'TSNumberKeyword';
|
|
153
|
-
};
|
|
154
|
-
readonly integer: {
|
|
155
|
-
readonly type: 'TSNumberKeyword';
|
|
156
|
-
};
|
|
157
|
-
readonly bigint: {
|
|
158
|
-
readonly type: 'TSBigIntKeyword';
|
|
159
|
-
};
|
|
160
|
-
readonly object: {
|
|
161
|
-
readonly type: 'TSObjectKeyword';
|
|
162
|
-
};
|
|
163
|
-
readonly string: {
|
|
164
|
-
readonly type: 'TSStringKeyword';
|
|
165
|
-
};
|
|
166
|
-
readonly boolean: {
|
|
167
|
-
readonly type: 'TSBooleanKeyword';
|
|
168
|
-
};
|
|
169
|
-
readonly undefined: {
|
|
170
|
-
readonly type: 'TSUndefinedKeyword';
|
|
171
|
-
};
|
|
172
|
-
readonly null: {
|
|
173
|
-
readonly type: 'TSNullKeyword';
|
|
174
|
-
};
|
|
175
|
-
readonly never: {
|
|
176
|
-
readonly type: 'TSNeverKeyword';
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* Converts an OAS-style path (e.g. `/pets/{petId}`) or an Express-style path
|
|
181
|
-
* (e.g. `/pets/:petId`) to a TypeScript template literal type
|
|
182
|
-
* like `` `/pets/${string}` ``.
|
|
183
|
-
*/
|
|
184
|
-
declare function createUrlTemplateType(path: string): TsNode;
|
|
185
|
-
/**
|
|
186
|
-
* Converts a primitive const value to a TypeScript literal type.
|
|
187
|
-
*/
|
|
188
|
-
declare function constToTypeNode(value: string | number | boolean, format: 'string' | 'number' | 'boolean'): TsNode | undefined;
|
|
189
|
-
/**
|
|
190
|
-
* Returns a `Date` reference type when `representation` is `'date'`, otherwise falls back to `string`.
|
|
191
|
-
*/
|
|
192
|
-
declare function dateOrStringNode(node: {
|
|
193
|
-
representation?: string;
|
|
194
|
-
}): TsNode;
|
|
195
|
-
/**
|
|
196
|
-
* Maps an array of `SchemaNode`s through the printer, filtering out `null` and `undefined` results.
|
|
197
|
-
*/
|
|
198
|
-
declare function buildMemberNodes(members: Array<ast.SchemaNode> | undefined, print: (node: ast.SchemaNode) => TsNode | null | undefined): Array<TsNode>;
|
|
199
|
-
/**
|
|
200
|
-
* Builds a TypeScript tuple type from an array schema's `items`,
|
|
201
|
-
* applying min/max slice and optional/rest element rules.
|
|
202
|
-
*/
|
|
203
|
-
declare function buildTupleNode(node: ast.ArraySchemaNode, print: (node: ast.SchemaNode) => TsNode | null | undefined): TsNode;
|
|
204
|
-
/**
|
|
205
|
-
* Appends `| null` and then `| undefined` to a type when requested.
|
|
206
|
-
*/
|
|
207
|
-
declare function wrapNullableOptional(type: TsNode, nullable: boolean, addsUndefined: boolean): TsNode;
|
|
208
|
-
/**
|
|
209
|
-
* Applies `nullable` and optional/nullish `| undefined` union modifiers to a property's resolved base type.
|
|
210
|
-
*/
|
|
211
|
-
declare function buildPropertyType(schema: ast.SchemaNode, baseType: TsNode, optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined', optional?: boolean): TsNode;
|
|
212
|
-
/**
|
|
213
|
-
* Creates a TypeScript index signature for `additionalProperties` and `patternProperties` on an
|
|
214
|
-
* object schema node. TypeScript allows only one string index signature and its value must be
|
|
215
|
-
* assignable from every named property, so both keywords collapse into a single signature: the
|
|
216
|
-
* union of all value types (deduplicated), or `unknown` when the object also has fixed properties.
|
|
217
|
-
* The key regex of `patternProperties` cannot be expressed by an index signature and is dropped.
|
|
218
|
-
*/
|
|
219
|
-
declare function buildIndexSignatures(node: {
|
|
220
|
-
additionalProperties?: ast.SchemaNode | boolean;
|
|
221
|
-
patternProperties?: Record<string, ast.SchemaNode>;
|
|
222
|
-
}, propertyCount: number, printNode: (node: ast.SchemaNode) => TsNode | null | undefined): Array<TsNode>;
|
|
223
|
-
//#endregion
|
|
224
|
-
//#region src/printers/printerTs.d.ts
|
|
225
10
|
/**
|
|
226
11
|
* Partial map of node-type overrides for the TypeScript printer.
|
|
227
12
|
*
|
|
@@ -333,8 +118,6 @@ type PrinterTsFactory = ast.PrinterFactoryOptions<'typescript', PrinterTsOptions
|
|
|
333
118
|
* ```
|
|
334
119
|
*/
|
|
335
120
|
export declare const printerTs: (options?: PrinterTsOptions | undefined) => ast.Printer<PrinterTsFactory>;
|
|
336
|
-
//#endregion
|
|
337
|
-
//#region src/types.d.ts
|
|
338
121
|
/**
|
|
339
122
|
* The concrete resolver type for `@kubb/plugin-ts`.
|
|
340
123
|
* Extends the base `Resolver` (which provides `default` naming and option helpers, the top-level
|
|
@@ -665,8 +448,6 @@ declare global {
|
|
|
665
448
|
}
|
|
666
449
|
}
|
|
667
450
|
}
|
|
668
|
-
//#endregion
|
|
669
|
-
//#region src/components/Enum.d.ts
|
|
670
451
|
type EnumOptions = PluginTs['resolvedOptions']['enum'];
|
|
671
452
|
type Props$1 = {
|
|
672
453
|
node: ast.EnumSchemaNode;
|
|
@@ -686,8 +467,6 @@ type Props$1 = {
|
|
|
686
467
|
* index picks up the correct export identifiers.
|
|
687
468
|
*/
|
|
688
469
|
export declare function Enum({ node, enum: enumOptions, resolver }: Props$1): KubbReactNode;
|
|
689
|
-
//#endregion
|
|
690
|
-
//#region src/components/Type.d.ts
|
|
691
470
|
type Props = {
|
|
692
471
|
name: string;
|
|
693
472
|
node: ast.SchemaNode;
|
|
@@ -704,8 +483,6 @@ type Props = {
|
|
|
704
483
|
inline?: boolean;
|
|
705
484
|
};
|
|
706
485
|
export declare function Type({ name, node, printer, enum: enumOptions, resolver, inline }: Props): KubbReactNode;
|
|
707
|
-
//#endregion
|
|
708
|
-
//#region src/generators/typeGenerator.d.ts
|
|
709
486
|
/**
|
|
710
487
|
* Built-in generator for `@kubb/plugin-ts`. Emits one TypeScript file per
|
|
711
488
|
* schema in the spec plus per-operation request, response, and parameter
|
|
@@ -713,8 +490,6 @@ export declare function Type({ name, node, printer, enum: enumOptions, resolver,
|
|
|
713
490
|
* TypeScript output is produced.
|
|
714
491
|
*/
|
|
715
492
|
export declare const typeGenerator: import("kubb/kit").Generator<PluginTs, unknown>;
|
|
716
|
-
//#endregion
|
|
717
|
-
//#region src/plugin.d.ts
|
|
718
493
|
/**
|
|
719
494
|
* Canonical plugin name for `@kubb/plugin-ts`. Used for driver lookups and
|
|
720
495
|
* cross-plugin dependency references.
|
|
@@ -745,8 +520,6 @@ export declare const pluginTsName = "plugin-ts";
|
|
|
745
520
|
* ```
|
|
746
521
|
*/
|
|
747
522
|
export declare const pluginTs: import("kubb/kit").PluginFactory<PluginTs>;
|
|
748
|
-
//#endregion
|
|
749
|
-
//#region src/printers/functionParams.d.ts
|
|
750
523
|
/**
|
|
751
524
|
* A type expression used as a function parameter type annotation.
|
|
752
525
|
*
|
|
@@ -946,8 +719,6 @@ export declare function createFunctionParameter(input: FunctionParameterInput):
|
|
|
946
719
|
* ```
|
|
947
720
|
*/
|
|
948
721
|
export declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
|
|
949
|
-
//#endregion
|
|
950
|
-
//#region src/printers/functionPrinter.d.ts
|
|
951
722
|
/**
|
|
952
723
|
* Renders a {@link TypeExpression} to its TypeScript source.
|
|
953
724
|
*
|
|
@@ -1001,13 +772,10 @@ export declare function functionPrinter(options: FunctionPrinterOptions): {
|
|
|
1001
772
|
options: FunctionPrinterOptions;
|
|
1002
773
|
print(node: FunctionParametersNode): string;
|
|
1003
774
|
};
|
|
1004
|
-
//#endregion
|
|
1005
|
-
//#region src/resolvers/resolverTs.d.ts
|
|
1006
775
|
/**
|
|
1007
776
|
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|
|
1008
|
-
* for
|
|
1009
|
-
*
|
|
1010
|
-
* casing/file-layout rules.
|
|
777
|
+
* for generated TypeScript types. Other plugins should read the build's resolver
|
|
778
|
+
* through `driver.getResolver(pluginTsName)` to share its name allocations.
|
|
1011
779
|
*
|
|
1012
780
|
* The `default` helpers are supplied by `createResolver`. This plugin overrides the top-level `name`
|
|
1013
781
|
* to use PascalCase for value and type names and `file` to write PascalCase file paths (dotted names
|
|
@@ -1023,8 +791,6 @@ export declare function functionPrinter(options: FunctionPrinterOptions): {
|
|
|
1023
791
|
* ```
|
|
1024
792
|
*/
|
|
1025
793
|
export declare const resolverTs: ResolverTs;
|
|
1026
|
-
//#endregion
|
|
1027
|
-
//#region src/utils.d.ts
|
|
1028
794
|
/**
|
|
1029
795
|
* Resolves the type name an enum schema is referenced by. An enum emitted as a `const` object
|
|
1030
796
|
* with a `typeSuffix` uses its suffixed key alias (e.g. `StatusKey`); every other schema uses its
|
|
@@ -1049,6 +815,5 @@ type BuildParamsSchemaOptions = {
|
|
|
1049
815
|
* separate per-param type — the group itself is the only type these params get exported as.
|
|
1050
816
|
*/
|
|
1051
817
|
export declare function buildParams({ params }: BuildParamsSchemaOptions): ast.SchemaNode;
|
|
1052
|
-
//#endregion
|
|
1053
818
|
export { type FunctionParameterNode, type FunctionParametersNode, type IndexedAccessTypeNode, type ObjectBindingPatternNode, type PluginTs, type PrinterTsFactory, type PrinterTsNodes, type PrinterTsOptions, type ResolverTs, type TypeExpression, type TypeLiteralNode, pluginTs as default };
|
|
1054
819
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginType, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
2
2
|
import { KubbReactNode } from "kubb/jsx";
|
|
3
|
-
declare namespace factory_d_exports {
|
|
4
|
-
export { TsNode, appendJSDocToNode, buildIndexSignatures, buildMemberNodes, buildPropertyType, buildTupleNode, constToTypeNode, createArrayDeclaration, createEnumDeclaration, createIntersectionDeclaration, createOmitDeclaration, createPropertySignature, createRaw, createTypeDeclaration, createTypeLiteralNode, createTypeReferenceNode, createUnionDeclaration, createUrlTemplateType, dateOrStringNode, isNonNullable, keywordTypeNodes, print, wrapNullableOptional };
|
|
5
|
-
}
|
|
6
3
|
/**
|
|
7
4
|
* A TS-ESTree node, the AST shape `yuku-codegen` prints. Nodes built here carry no source positions.
|
|
8
5
|
*/
|
|
@@ -10,218 +7,6 @@ type TsNode = {
|
|
|
10
7
|
type: string;
|
|
11
8
|
[key: string]: unknown;
|
|
12
9
|
};
|
|
13
|
-
declare function isNonNullable<T>(value: T | null | undefined): value is T;
|
|
14
|
-
/**
|
|
15
|
-
* Prints `node` as TypeScript source with single quotes and two-space indentation.
|
|
16
|
-
*/
|
|
17
|
-
declare function print(node: TsNode): string;
|
|
18
|
-
/**
|
|
19
|
-
* Wraps already printed TypeScript, such as a user override result, so it can sit inside a node tree.
|
|
20
|
-
* Parentheses keep a union or function type intact when it lands inside an array or intersection.
|
|
21
|
-
*/
|
|
22
|
-
declare function createRaw(text: string): TsNode;
|
|
23
|
-
/**
|
|
24
|
-
* Creates a TypeScript intersection type.
|
|
25
|
-
* Returns the single type if only one is provided. `yuku-codegen` adds the parentheses a union member needs.
|
|
26
|
-
*/
|
|
27
|
-
declare function createIntersectionDeclaration({ nodes, withParentheses }: {
|
|
28
|
-
nodes: Array<TsNode>;
|
|
29
|
-
withParentheses?: boolean;
|
|
30
|
-
}): TsNode | null;
|
|
31
|
-
/**
|
|
32
|
-
* Creates a TypeScript array type.
|
|
33
|
-
* Use `arrayType: 'array'` for bracket syntax (`T[]`), or `'generic'` for `Array<T>`.
|
|
34
|
-
*
|
|
35
|
-
* @example Array bracket syntax
|
|
36
|
-
* `createArrayDeclaration({ nodes: [string], arrayType: 'array' }) // → string[]`
|
|
37
|
-
*
|
|
38
|
-
* @example Generic Array syntax
|
|
39
|
-
* `createArrayDeclaration({ nodes: [string], arrayType: 'generic' }) // → Array<string>`
|
|
40
|
-
*/
|
|
41
|
-
declare function createArrayDeclaration({ nodes, arrayType }: {
|
|
42
|
-
nodes: Array<TsNode>;
|
|
43
|
-
arrayType?: 'array' | 'generic';
|
|
44
|
-
}): TsNode;
|
|
45
|
-
/**
|
|
46
|
-
* Minimum nodes length of 2
|
|
47
|
-
* @example Union type example
|
|
48
|
-
* `string | number`
|
|
49
|
-
*/
|
|
50
|
-
declare function createUnionDeclaration({ nodes, withParentheses }: {
|
|
51
|
-
nodes: Array<TsNode>;
|
|
52
|
-
withParentheses?: boolean;
|
|
53
|
-
}): TsNode;
|
|
54
|
-
/**
|
|
55
|
-
* Creates a TypeScript property signature for object/interface members.
|
|
56
|
-
* Supports optional markers, readonly modifiers, and type annotations.
|
|
57
|
-
*/
|
|
58
|
-
declare function createPropertySignature({ readOnly, name, questionToken, type }: {
|
|
59
|
-
readOnly?: boolean;
|
|
60
|
-
name: string;
|
|
61
|
-
questionToken?: boolean;
|
|
62
|
-
type?: TsNode;
|
|
63
|
-
}): TsNode;
|
|
64
|
-
/**
|
|
65
|
-
* Attaches a JSDoc block built from `comments` to `node`, dropping empty comments.
|
|
66
|
-
*/
|
|
67
|
-
declare function appendJSDocToNode<TNode extends TsNode>({ node, comments }: {
|
|
68
|
-
node: TNode;
|
|
69
|
-
comments: Array<string | undefined>;
|
|
70
|
-
}): TNode;
|
|
71
|
-
/**
|
|
72
|
-
* Creates a TypeScript type literal (anonymous object type) with one member per line.
|
|
73
|
-
*/
|
|
74
|
-
declare function createTypeLiteralNode(members: Array<TsNode>): TsNode;
|
|
75
|
-
/**
|
|
76
|
-
* Creates a TypeScript type reference (e.g., `Array<string>`, `Record<K, V>`).
|
|
77
|
-
*/
|
|
78
|
-
declare function createTypeReferenceNode(name: string, typeArguments?: Array<TsNode>): TsNode;
|
|
79
|
-
/**
|
|
80
|
-
* Prints a TypeScript type declaration as either a type alias or interface.
|
|
81
|
-
* Uses interface syntax only when requested and the type is an object literal, and attaches JSDoc comments.
|
|
82
|
-
*/
|
|
83
|
-
declare function createTypeDeclaration({ syntax, isExportable, comments, name, type }: {
|
|
84
|
-
syntax: 'type' | 'interface';
|
|
85
|
-
comments: Array<string | undefined>;
|
|
86
|
-
isExportable?: boolean;
|
|
87
|
-
name: string;
|
|
88
|
-
type: TsNode;
|
|
89
|
-
}): string;
|
|
90
|
-
/**
|
|
91
|
-
* Creates a TypeScript enum declaration or equivalent construct in various formats.
|
|
92
|
-
* Returns a tuple of [name declaration, type declaration] - the name declaration may be undefined for certain types.
|
|
93
|
-
*
|
|
94
|
-
* @example
|
|
95
|
-
* ```ts
|
|
96
|
-
* const [name, type] = createEnumDeclaration({
|
|
97
|
-
* type: 'enum',
|
|
98
|
-
* name: 'petType',
|
|
99
|
-
* typeName: 'PetType',
|
|
100
|
-
* enums: [['cat', 'cat', 'A cat'], ['dog', 'dog']],
|
|
101
|
-
* })
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
declare function createEnumDeclaration({ type, name, typeName, enums, enumKeyCasing }: {
|
|
105
|
-
/**
|
|
106
|
-
* Choose to use `enum`, `asConst`, `constEnum`, or `literal` for enums.
|
|
107
|
-
* - `enum`: TypeScript enum
|
|
108
|
-
* - `asConst`: const object asserted with `as const` (the caller decides the const name casing)
|
|
109
|
-
* - `constEnum`: const enum
|
|
110
|
-
* - `literal`: literal union type
|
|
111
|
-
* @default `'enum'`
|
|
112
|
-
*/
|
|
113
|
-
type?: 'enum' | 'asConst' | 'constEnum' | 'literal' | 'inlineLiteral';
|
|
114
|
-
/**
|
|
115
|
-
* Enum name in camelCase.
|
|
116
|
-
*/
|
|
117
|
-
name: string;
|
|
118
|
-
/**
|
|
119
|
-
* Enum name in PascalCase.
|
|
120
|
-
*/
|
|
121
|
-
typeName: string;
|
|
122
|
-
enums: Array<[key: string | number, value: string | number | boolean, description?: string]>;
|
|
123
|
-
/**
|
|
124
|
-
* Choose the casing for enum key names.
|
|
125
|
-
* @default 'none'
|
|
126
|
-
*/
|
|
127
|
-
enumKeyCasing?: 'screamingSnakeCase' | 'snakeCase' | 'pascalCase' | 'camelCase' | 'none';
|
|
128
|
-
}): [name: string | undefined, type: string];
|
|
129
|
-
/**
|
|
130
|
-
* Creates a TypeScript `Omit<T, Keys>` type reference.
|
|
131
|
-
* Optionally wraps the type in `NonNullable<T>` if `nonNullable` is true.
|
|
132
|
-
*/
|
|
133
|
-
declare function createOmitDeclaration({ keys, type, nonNullable }: {
|
|
134
|
-
keys: Array<string> | string;
|
|
135
|
-
type: TsNode;
|
|
136
|
-
nonNullable?: boolean;
|
|
137
|
-
}): TsNode;
|
|
138
|
-
/**
|
|
139
|
-
* TypeScript keyword types for common primitive types.
|
|
140
|
-
*/
|
|
141
|
-
declare const keywordTypeNodes: {
|
|
142
|
-
readonly any: {
|
|
143
|
-
readonly type: 'TSAnyKeyword';
|
|
144
|
-
};
|
|
145
|
-
readonly unknown: {
|
|
146
|
-
readonly type: 'TSUnknownKeyword';
|
|
147
|
-
};
|
|
148
|
-
readonly void: {
|
|
149
|
-
readonly type: 'TSVoidKeyword';
|
|
150
|
-
};
|
|
151
|
-
readonly number: {
|
|
152
|
-
readonly type: 'TSNumberKeyword';
|
|
153
|
-
};
|
|
154
|
-
readonly integer: {
|
|
155
|
-
readonly type: 'TSNumberKeyword';
|
|
156
|
-
};
|
|
157
|
-
readonly bigint: {
|
|
158
|
-
readonly type: 'TSBigIntKeyword';
|
|
159
|
-
};
|
|
160
|
-
readonly object: {
|
|
161
|
-
readonly type: 'TSObjectKeyword';
|
|
162
|
-
};
|
|
163
|
-
readonly string: {
|
|
164
|
-
readonly type: 'TSStringKeyword';
|
|
165
|
-
};
|
|
166
|
-
readonly boolean: {
|
|
167
|
-
readonly type: 'TSBooleanKeyword';
|
|
168
|
-
};
|
|
169
|
-
readonly undefined: {
|
|
170
|
-
readonly type: 'TSUndefinedKeyword';
|
|
171
|
-
};
|
|
172
|
-
readonly null: {
|
|
173
|
-
readonly type: 'TSNullKeyword';
|
|
174
|
-
};
|
|
175
|
-
readonly never: {
|
|
176
|
-
readonly type: 'TSNeverKeyword';
|
|
177
|
-
};
|
|
178
|
-
};
|
|
179
|
-
/**
|
|
180
|
-
* Converts an OAS-style path (e.g. `/pets/{petId}`) or an Express-style path
|
|
181
|
-
* (e.g. `/pets/:petId`) to a TypeScript template literal type
|
|
182
|
-
* like `` `/pets/${string}` ``.
|
|
183
|
-
*/
|
|
184
|
-
declare function createUrlTemplateType(path: string): TsNode;
|
|
185
|
-
/**
|
|
186
|
-
* Converts a primitive const value to a TypeScript literal type.
|
|
187
|
-
*/
|
|
188
|
-
declare function constToTypeNode(value: string | number | boolean, format: 'string' | 'number' | 'boolean'): TsNode | undefined;
|
|
189
|
-
/**
|
|
190
|
-
* Returns a `Date` reference type when `representation` is `'date'`, otherwise falls back to `string`.
|
|
191
|
-
*/
|
|
192
|
-
declare function dateOrStringNode(node: {
|
|
193
|
-
representation?: string;
|
|
194
|
-
}): TsNode;
|
|
195
|
-
/**
|
|
196
|
-
* Maps an array of `SchemaNode`s through the printer, filtering out `null` and `undefined` results.
|
|
197
|
-
*/
|
|
198
|
-
declare function buildMemberNodes(members: Array<ast.SchemaNode> | undefined, print: (node: ast.SchemaNode) => TsNode | null | undefined): Array<TsNode>;
|
|
199
|
-
/**
|
|
200
|
-
* Builds a TypeScript tuple type from an array schema's `items`,
|
|
201
|
-
* applying min/max slice and optional/rest element rules.
|
|
202
|
-
*/
|
|
203
|
-
declare function buildTupleNode(node: ast.ArraySchemaNode, print: (node: ast.SchemaNode) => TsNode | null | undefined): TsNode;
|
|
204
|
-
/**
|
|
205
|
-
* Appends `| null` and then `| undefined` to a type when requested.
|
|
206
|
-
*/
|
|
207
|
-
declare function wrapNullableOptional(type: TsNode, nullable: boolean, addsUndefined: boolean): TsNode;
|
|
208
|
-
/**
|
|
209
|
-
* Applies `nullable` and optional/nullish `| undefined` union modifiers to a property's resolved base type.
|
|
210
|
-
*/
|
|
211
|
-
declare function buildPropertyType(schema: ast.SchemaNode, baseType: TsNode, optionalType: 'questionToken' | 'undefined' | 'questionTokenAndUndefined', optional?: boolean): TsNode;
|
|
212
|
-
/**
|
|
213
|
-
* Creates a TypeScript index signature for `additionalProperties` and `patternProperties` on an
|
|
214
|
-
* object schema node. TypeScript allows only one string index signature and its value must be
|
|
215
|
-
* assignable from every named property, so both keywords collapse into a single signature: the
|
|
216
|
-
* union of all value types (deduplicated), or `unknown` when the object also has fixed properties.
|
|
217
|
-
* The key regex of `patternProperties` cannot be expressed by an index signature and is dropped.
|
|
218
|
-
*/
|
|
219
|
-
declare function buildIndexSignatures(node: {
|
|
220
|
-
additionalProperties?: ast.SchemaNode | boolean;
|
|
221
|
-
patternProperties?: Record<string, ast.SchemaNode>;
|
|
222
|
-
}, propertyCount: number, printNode: (node: ast.SchemaNode) => TsNode | null | undefined): Array<TsNode>;
|
|
223
|
-
//#endregion
|
|
224
|
-
//#region src/printers/printerTs.d.ts
|
|
225
10
|
/**
|
|
226
11
|
* Partial map of node-type overrides for the TypeScript printer.
|
|
227
12
|
*
|
|
@@ -333,8 +118,6 @@ type PrinterTsFactory = ast.PrinterFactoryOptions<'typescript', PrinterTsOptions
|
|
|
333
118
|
* ```
|
|
334
119
|
*/
|
|
335
120
|
export declare const printerTs: (options?: PrinterTsOptions | undefined) => ast.Printer<PrinterTsFactory>;
|
|
336
|
-
//#endregion
|
|
337
|
-
//#region src/types.d.ts
|
|
338
121
|
/**
|
|
339
122
|
* The concrete resolver type for `@kubb/plugin-ts`.
|
|
340
123
|
* Extends the base `Resolver` (which provides `default` naming and option helpers, the top-level
|
|
@@ -665,8 +448,6 @@ declare global {
|
|
|
665
448
|
}
|
|
666
449
|
}
|
|
667
450
|
}
|
|
668
|
-
//#endregion
|
|
669
|
-
//#region src/components/Enum.d.ts
|
|
670
451
|
type EnumOptions = PluginTs['resolvedOptions']['enum'];
|
|
671
452
|
type Props$1 = {
|
|
672
453
|
node: ast.EnumSchemaNode;
|
|
@@ -686,8 +467,6 @@ type Props$1 = {
|
|
|
686
467
|
* index picks up the correct export identifiers.
|
|
687
468
|
*/
|
|
688
469
|
export declare function Enum({ node, enum: enumOptions, resolver }: Props$1): KubbReactNode;
|
|
689
|
-
//#endregion
|
|
690
|
-
//#region src/components/Type.d.ts
|
|
691
470
|
type Props = {
|
|
692
471
|
name: string;
|
|
693
472
|
node: ast.SchemaNode;
|
|
@@ -704,8 +483,6 @@ type Props = {
|
|
|
704
483
|
inline?: boolean;
|
|
705
484
|
};
|
|
706
485
|
export declare function Type({ name, node, printer, enum: enumOptions, resolver, inline }: Props): KubbReactNode;
|
|
707
|
-
//#endregion
|
|
708
|
-
//#region src/generators/typeGenerator.d.ts
|
|
709
486
|
/**
|
|
710
487
|
* Built-in generator for `@kubb/plugin-ts`. Emits one TypeScript file per
|
|
711
488
|
* schema in the spec plus per-operation request, response, and parameter
|
|
@@ -713,8 +490,6 @@ export declare function Type({ name, node, printer, enum: enumOptions, resolver,
|
|
|
713
490
|
* TypeScript output is produced.
|
|
714
491
|
*/
|
|
715
492
|
export declare const typeGenerator: import("kubb/kit").Generator<PluginTs, unknown>;
|
|
716
|
-
//#endregion
|
|
717
|
-
//#region src/plugin.d.ts
|
|
718
493
|
/**
|
|
719
494
|
* Canonical plugin name for `@kubb/plugin-ts`. Used for driver lookups and
|
|
720
495
|
* cross-plugin dependency references.
|
|
@@ -745,8 +520,6 @@ export declare const pluginTsName = "plugin-ts";
|
|
|
745
520
|
* ```
|
|
746
521
|
*/
|
|
747
522
|
export declare const pluginTs: import("kubb/kit").PluginFactory<PluginTs>;
|
|
748
|
-
//#endregion
|
|
749
|
-
//#region src/printers/functionParams.d.ts
|
|
750
523
|
/**
|
|
751
524
|
* A type expression used as a function parameter type annotation.
|
|
752
525
|
*
|
|
@@ -946,8 +719,6 @@ export declare function createFunctionParameter(input: FunctionParameterInput):
|
|
|
946
719
|
* ```
|
|
947
720
|
*/
|
|
948
721
|
export declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
|
|
949
|
-
//#endregion
|
|
950
|
-
//#region src/printers/functionPrinter.d.ts
|
|
951
722
|
/**
|
|
952
723
|
* Renders a {@link TypeExpression} to its TypeScript source.
|
|
953
724
|
*
|
|
@@ -1001,13 +772,10 @@ export declare function functionPrinter(options: FunctionPrinterOptions): {
|
|
|
1001
772
|
options: FunctionPrinterOptions;
|
|
1002
773
|
print(node: FunctionParametersNode): string;
|
|
1003
774
|
};
|
|
1004
|
-
//#endregion
|
|
1005
|
-
//#region src/resolvers/resolverTs.d.ts
|
|
1006
775
|
/**
|
|
1007
776
|
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|
|
1008
|
-
* for
|
|
1009
|
-
*
|
|
1010
|
-
* casing/file-layout rules.
|
|
777
|
+
* for generated TypeScript types. Other plugins should read the build's resolver
|
|
778
|
+
* through `driver.getResolver(pluginTsName)` to share its name allocations.
|
|
1011
779
|
*
|
|
1012
780
|
* The `default` helpers are supplied by `createResolver`. This plugin overrides the top-level `name`
|
|
1013
781
|
* to use PascalCase for value and type names and `file` to write PascalCase file paths (dotted names
|
|
@@ -1023,8 +791,6 @@ export declare function functionPrinter(options: FunctionPrinterOptions): {
|
|
|
1023
791
|
* ```
|
|
1024
792
|
*/
|
|
1025
793
|
export declare const resolverTs: ResolverTs;
|
|
1026
|
-
//#endregion
|
|
1027
|
-
//#region src/utils.d.ts
|
|
1028
794
|
/**
|
|
1029
795
|
* Resolves the type name an enum schema is referenced by. An enum emitted as a `const` object
|
|
1030
796
|
* with a `typeSuffix` uses its suffixed key alias (e.g. `StatusKey`); every other schema uses its
|
|
@@ -1049,6 +815,5 @@ type BuildParamsSchemaOptions = {
|
|
|
1049
815
|
* separate per-param type — the group itself is the only type these params get exported as.
|
|
1050
816
|
*/
|
|
1051
817
|
export declare function buildParams({ params }: BuildParamsSchemaOptions): ast.SchemaNode;
|
|
1052
|
-
//#endregion
|
|
1053
818
|
export { type FunctionParameterNode, type FunctionParametersNode, type IndexedAccessTypeNode, type ObjectBindingPatternNode, type PluginTs, type PrinterTsFactory, type PrinterTsNodes, type PrinterTsOptions, type ResolverTs, type TypeExpression, type TypeLiteralNode, pluginTs as default };
|
|
1054
819
|
//# sourceMappingURL=index.d.ts.map
|