@kubb/plugin-ts 5.0.1 → 5.0.3
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 +9 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -17
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/package.json +8 -4
package/dist/index.d.ts
CHANGED
|
@@ -110,7 +110,7 @@ type PrinterTsFactory = ast.PrinterFactoryOptions<'typescript', PrinterTsOptions
|
|
|
110
110
|
* const declaration = printer.print(schemaNode) // ts.TypeAliasDeclaration | ts.InterfaceDeclaration
|
|
111
111
|
* ```
|
|
112
112
|
*/
|
|
113
|
-
declare const printerTs: (options?: PrinterTsOptions | undefined) => ast.Printer<PrinterTsFactory>;
|
|
113
|
+
export declare const printerTs: (options?: PrinterTsOptions | undefined) => ast.Printer<PrinterTsFactory>;
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region src/types.d.ts
|
|
116
116
|
/**
|
|
@@ -457,7 +457,7 @@ type Props$1 = {
|
|
|
457
457
|
* The emitted `File.Source` nodes carry the resolved names so that the barrel
|
|
458
458
|
* index picks up the correct export identifiers.
|
|
459
459
|
*/
|
|
460
|
-
declare function Enum({ node, enum: enumOptions, resolver }: Props$1): KubbReactNode;
|
|
460
|
+
export declare function Enum({ node, enum: enumOptions, resolver }: Props$1): KubbReactNode;
|
|
461
461
|
//#endregion
|
|
462
462
|
//#region src/components/Type.d.ts
|
|
463
463
|
type Props = {
|
|
@@ -471,7 +471,7 @@ type Props = {
|
|
|
471
471
|
enum: PluginTs['resolvedOptions']['enum'];
|
|
472
472
|
resolver: ResolverTs;
|
|
473
473
|
};
|
|
474
|
-
declare function Type({ name, node, printer, enum: enumOptions, resolver }: Props): KubbReactNode;
|
|
474
|
+
export declare function Type({ name, node, printer, enum: enumOptions, resolver }: Props): KubbReactNode;
|
|
475
475
|
//#endregion
|
|
476
476
|
//#region src/generators/typeGenerator.d.ts
|
|
477
477
|
/**
|
|
@@ -480,14 +480,14 @@ declare function Type({ name, node, printer, enum: enumOptions, resolver }: Prop
|
|
|
480
480
|
* types. Drop-replace with a custom `Generator<PluginTs>` to change how
|
|
481
481
|
* TypeScript output is produced.
|
|
482
482
|
*/
|
|
483
|
-
declare const typeGenerator: import("kubb/kit").Generator<PluginTs, unknown>;
|
|
483
|
+
export declare const typeGenerator: import("kubb/kit").Generator<PluginTs, unknown>;
|
|
484
484
|
//#endregion
|
|
485
485
|
//#region src/plugin.d.ts
|
|
486
486
|
/**
|
|
487
487
|
* Canonical plugin name for `@kubb/plugin-ts`. Used for driver lookups and
|
|
488
488
|
* cross-plugin dependency references.
|
|
489
489
|
*/
|
|
490
|
-
declare const pluginTsName = "plugin-ts";
|
|
490
|
+
export declare const pluginTsName = "plugin-ts";
|
|
491
491
|
/**
|
|
492
492
|
* Generates TypeScript `type` aliases and `interface` declarations from an
|
|
493
493
|
* OpenAPI spec. The foundation that every other Kubb plugin builds on:
|
|
@@ -512,7 +512,7 @@ declare const pluginTsName = "plugin-ts";
|
|
|
512
512
|
* })
|
|
513
513
|
* ```
|
|
514
514
|
*/
|
|
515
|
-
declare const pluginTs: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginTs>;
|
|
515
|
+
export declare const pluginTs: (options?: Options | undefined) => import("kubb/kit").Plugin<PluginTs>;
|
|
516
516
|
//#endregion
|
|
517
517
|
//#region src/printers/functionParams.d.ts
|
|
518
518
|
/**
|
|
@@ -646,7 +646,7 @@ type FunctionParametersNode = {
|
|
|
646
646
|
* // { petId: string }
|
|
647
647
|
* ```
|
|
648
648
|
*/
|
|
649
|
-
declare function createTypeLiteral(props: Omit<TypeLiteralNode, 'kind'>): TypeLiteralNode;
|
|
649
|
+
export declare function createTypeLiteral(props: Omit<TypeLiteralNode, 'kind'>): TypeLiteralNode;
|
|
650
650
|
/**
|
|
651
651
|
* Creates an {@link IndexedAccessTypeNode} representing a single field accessed from a named type.
|
|
652
652
|
*
|
|
@@ -656,7 +656,7 @@ declare function createTypeLiteral(props: Omit<TypeLiteralNode, 'kind'>): TypeLi
|
|
|
656
656
|
* // DeletePetPathParams['petId']
|
|
657
657
|
* ```
|
|
658
658
|
*/
|
|
659
|
-
declare function createIndexedAccessType(props: Omit<IndexedAccessTypeNode, 'kind'>): IndexedAccessTypeNode;
|
|
659
|
+
export declare function createIndexedAccessType(props: Omit<IndexedAccessTypeNode, 'kind'>): IndexedAccessTypeNode;
|
|
660
660
|
/**
|
|
661
661
|
* Creates an {@link ObjectBindingPatternNode} for a destructured parameter binding.
|
|
662
662
|
*
|
|
@@ -666,7 +666,7 @@ declare function createIndexedAccessType(props: Omit<IndexedAccessTypeNode, 'kin
|
|
|
666
666
|
* // { id, name }
|
|
667
667
|
* ```
|
|
668
668
|
*/
|
|
669
|
-
declare function createObjectBindingPattern(props: Omit<ObjectBindingPatternNode, 'kind'>): ObjectBindingPatternNode;
|
|
669
|
+
export declare function createObjectBindingPattern(props: Omit<ObjectBindingPatternNode, 'kind'>): ObjectBindingPatternNode;
|
|
670
670
|
/**
|
|
671
671
|
* Plain property descriptor for a destructured group built by {@link createFunctionParameter}.
|
|
672
672
|
*/
|
|
@@ -703,7 +703,7 @@ type FunctionParameterInput = {
|
|
|
703
703
|
* // → { id, name }: { id: string; name?: string } = {}
|
|
704
704
|
* ```
|
|
705
705
|
*/
|
|
706
|
-
declare function createFunctionParameter(input: FunctionParameterInput): FunctionParameterNode;
|
|
706
|
+
export declare function createFunctionParameter(input: FunctionParameterInput): FunctionParameterNode;
|
|
707
707
|
/**
|
|
708
708
|
* Creates a {@link FunctionParametersNode} from an ordered list of parameters.
|
|
709
709
|
*
|
|
@@ -713,7 +713,7 @@ declare function createFunctionParameter(input: FunctionParameterInput): Functio
|
|
|
713
713
|
* // { params: [] }
|
|
714
714
|
* ```
|
|
715
715
|
*/
|
|
716
|
-
declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
|
|
716
|
+
export declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
|
|
717
717
|
//#endregion
|
|
718
718
|
//#region src/printers/functionPrinter.d.ts
|
|
719
719
|
/**
|
|
@@ -726,7 +726,7 @@ declare function createFunctionParameters(props?: Partial<Omit<FunctionParameter
|
|
|
726
726
|
* `transformType` is applied once to the fully rendered type, matching how the
|
|
727
727
|
* printer wrapped reference types before the `ts.factory` model.
|
|
728
728
|
*/
|
|
729
|
-
declare function renderType(type: TypeExpression, transformType?: (type: string) => string): string;
|
|
729
|
+
export declare function renderType(type: TypeExpression, transformType?: (type: string) => string): string;
|
|
730
730
|
type FunctionPrinterOptions = {
|
|
731
731
|
/**
|
|
732
732
|
* Rendering modes supported by `functionPrinter`.
|
|
@@ -764,7 +764,7 @@ type FunctionPrinterOptions = {
|
|
|
764
764
|
* printer.print(sig) // → "petId: string, config: Config = {}"
|
|
765
765
|
* ```
|
|
766
766
|
*/
|
|
767
|
-
declare function functionPrinter(options: FunctionPrinterOptions): {
|
|
767
|
+
export declare function functionPrinter(options: FunctionPrinterOptions): {
|
|
768
768
|
name: "functionParameters";
|
|
769
769
|
options: FunctionPrinterOptions;
|
|
770
770
|
print(node: FunctionParametersNode): string;
|
|
@@ -911,7 +911,7 @@ type CreateOperationParamsOptions = {
|
|
|
911
911
|
* `pathParamsType` controls how path params render in inline mode. Provide a `resolver` for type
|
|
912
912
|
* name resolution and `extraParams` for plugin-specific trailing parameters such as an `options` object.
|
|
913
913
|
*/
|
|
914
|
-
declare function createOperationParams(node: ast.OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
|
|
914
|
+
export declare function createOperationParams(node: ast.OperationNode, options: CreateOperationParamsOptions): FunctionParametersNode;
|
|
915
915
|
//#endregion
|
|
916
916
|
//#region src/resolvers/resolverTs.d.ts
|
|
917
917
|
/**
|
|
@@ -933,7 +933,7 @@ declare function createOperationParams(node: ast.OperationNode, options: CreateO
|
|
|
933
933
|
* resolverTs.response.status(node, 200) // 'ListPetsStatus200'
|
|
934
934
|
* ```
|
|
935
935
|
*/
|
|
936
|
-
declare const resolverTs: ResolverTs;
|
|
936
|
+
export declare const resolverTs: ResolverTs;
|
|
937
937
|
//#endregion
|
|
938
938
|
//#region src/utils.d.ts
|
|
939
939
|
type BuildParamsSchemaOptions = {
|
|
@@ -944,7 +944,7 @@ type BuildParamsSchemaOptions = {
|
|
|
944
944
|
* header), embedding each param's own schema (and JSDoc) directly rather than referencing a
|
|
945
945
|
* separate per-param type — the group itself is the only type these params get exported as.
|
|
946
946
|
*/
|
|
947
|
-
declare function buildParams({ params }: BuildParamsSchemaOptions): ast.SchemaNode;
|
|
947
|
+
export declare function buildParams({ params }: BuildParamsSchemaOptions): ast.SchemaNode;
|
|
948
948
|
//#endregion
|
|
949
|
-
export { type CreateOperationParamsOptions,
|
|
949
|
+
export { type CreateOperationParamsOptions, 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 };
|
|
950
950
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -626,8 +626,10 @@ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCa
|
|
|
626
626
|
}).filter((node) => node !== void 0)))];
|
|
627
627
|
if (type === "enum" || type === "constEnum") return [void 0, factory.createEnumDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword), type === "constEnum" ? factory.createToken(ts.SyntaxKind.ConstKeyword) : void 0].filter((modifier) => modifier !== void 0), factory.createIdentifier(typeName), enums.map(([key, value, description]) => {
|
|
628
628
|
let initializer = factory.createStringLiteral(value?.toString());
|
|
629
|
-
if (Number.parseInt(value.toString(), 10) === value && isNumber(value))
|
|
630
|
-
|
|
629
|
+
if (Number.parseInt(value.toString(), 10) === value && isNumber(value)) {
|
|
630
|
+
if (value < 0) initializer = factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
631
|
+
else initializer = factory.createNumericLiteral(value);
|
|
632
|
+
}
|
|
631
633
|
if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
|
|
632
634
|
if (isNumber(Number.parseInt(key.toString(), 10))) {
|
|
633
635
|
const casingKey = applyEnumKeyCasing(`${typeName}_${key}`, enumKeyCasing);
|
|
@@ -648,8 +650,10 @@ function createEnumDeclaration({ type = "enum", name, typeName, enums, enumKeyCa
|
|
|
648
650
|
if (enums.length === 0) return [void 0, factory.createTypeAliasDeclaration([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier(typeName), void 0, factory.createKeywordTypeNode(ts.SyntaxKind.NeverKeyword))];
|
|
649
651
|
return [factory.createVariableStatement([factory.createToken(ts.SyntaxKind.ExportKeyword)], factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(identifierName), void 0, void 0, factory.createAsExpression(factory.createObjectLiteralExpression(enums.map(([key, value, description]) => {
|
|
650
652
|
let initializer = factory.createStringLiteral(value?.toString());
|
|
651
|
-
if (isNumber(value))
|
|
652
|
-
|
|
653
|
+
if (isNumber(value)) {
|
|
654
|
+
if (value < 0) initializer = factory.createPrefixUnaryExpression(ts.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(value)));
|
|
655
|
+
else initializer = factory.createNumericLiteral(value);
|
|
656
|
+
}
|
|
653
657
|
if (typeof value === "boolean") initializer = value ? factory.createTrue() : factory.createFalse();
|
|
654
658
|
if (key !== null && key !== void 0) {
|
|
655
659
|
const casingKey = applyEnumKeyCasing(key.toString(), enumKeyCasing);
|
|
@@ -1430,7 +1434,7 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1430
1434
|
return createTypeReferenceNode(name, void 0);
|
|
1431
1435
|
},
|
|
1432
1436
|
enum(node) {
|
|
1433
|
-
const values =
|
|
1437
|
+
const values = ast.getSchemaLiteralValues(node);
|
|
1434
1438
|
if (this.options.enum.type === "inlineLiteral" || !node.name || isInlineConstEnum(node, this.options.enumSchemaNames)) return createUnionDeclaration({
|
|
1435
1439
|
withParentheses: true,
|
|
1436
1440
|
nodes: values.filter((v) => v !== null && v !== void 0).map((value) => constToTypeNode(value, typeof value)).filter(isNonNullable)
|