@kubb/plugin-ts 5.0.0-alpha.31 → 5.0.0-alpha.33
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 +37 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +17 -16
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/components/Enum.tsx +4 -4
- package/src/components/Type.tsx +3 -3
- package/src/generators/typeGenerator.tsx +7 -7
- package/src/generators/typeGeneratorLegacy.tsx +5 -5
- package/src/printers/functionPrinter.ts +6 -5
- package/src/printers/printerTs.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-ts",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.33",
|
|
4
4
|
"description": "TypeScript code generation plugin for Kubb, transforming OpenAPI schemas into TypeScript interfaces, types, and utility functions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
}
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@kubb/fabric-core": "0.15.1",
|
|
53
|
-
"@kubb/react-fabric": "0.15.1",
|
|
54
52
|
"remeda": "^2.33.7",
|
|
55
53
|
"typescript": "5.9.3",
|
|
56
|
-
"@kubb/ast": "5.0.0-alpha.
|
|
57
|
-
"@kubb/core": "5.0.0-alpha.
|
|
54
|
+
"@kubb/ast": "5.0.0-alpha.33",
|
|
55
|
+
"@kubb/core": "5.0.0-alpha.33",
|
|
56
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.33",
|
|
57
|
+
"@kubb/parser-ts": "5.0.0-alpha.33"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@kubb/
|
|
60
|
+
"@kubb/renderer-jsx": "5.0.0-alpha.33"
|
|
61
61
|
},
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=22"
|
package/src/components/Enum.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { camelCase, trimQuotes } from '@internals/utils'
|
|
2
2
|
import type { EnumSchemaNode } from '@kubb/ast/types'
|
|
3
|
-
import { safePrint } from '@kubb/
|
|
4
|
-
import { File } from '@kubb/
|
|
5
|
-
import type {
|
|
3
|
+
import { safePrint } from '@kubb/parser-ts'
|
|
4
|
+
import { File } from '@kubb/renderer-jsx'
|
|
5
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
6
|
import { ENUM_TYPES_WITH_KEY_SUFFIX, ENUM_TYPES_WITH_RUNTIME_VALUE, ENUM_TYPES_WITH_TYPE_ONLY } from '../constants.ts'
|
|
7
7
|
import * as factory from '../factory.ts'
|
|
8
8
|
import type { PluginTs, ResolverTs } from '../types.ts'
|
|
@@ -54,7 +54,7 @@ export function getEnumNames({
|
|
|
54
54
|
* The emitted `File.Source` nodes carry the resolved names so that the barrel
|
|
55
55
|
* index picks up the correct export identifiers.
|
|
56
56
|
*/
|
|
57
|
-
export function Enum({ node, enumType, enumTypeSuffix, enumKeyCasing, resolver }: Props):
|
|
57
|
+
export function Enum({ node, enumType, enumTypeSuffix, enumKeyCasing, resolver }: Props): KubbReactNode {
|
|
58
58
|
const { enumName, typeName } = getEnumNames({ node, enumType, enumTypeSuffix, resolver })
|
|
59
59
|
|
|
60
60
|
const [nameNode, typeNode] = factory.createEnumDeclaration({
|
package/src/components/Type.tsx
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Printer } from '@kubb/ast'
|
|
2
2
|
import { collect, narrowSchema, schemaTypes } from '@kubb/ast'
|
|
3
3
|
import type { EnumSchemaNode, SchemaNode } from '@kubb/ast/types'
|
|
4
|
-
import { File } from '@kubb/
|
|
5
|
-
import type {
|
|
4
|
+
import { File } from '@kubb/renderer-jsx'
|
|
5
|
+
import type { KubbReactNode } from '@kubb/renderer-jsx/types'
|
|
6
6
|
import type { PrinterTsFactory } from '../printers/printerTs.ts'
|
|
7
7
|
import type { PluginTs } from '../types.ts'
|
|
8
8
|
import { Enum, getEnumNames } from './Enum.tsx'
|
|
@@ -21,7 +21,7 @@ type Props = {
|
|
|
21
21
|
resolver: PluginTs['resolver']
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function Type({ name, node, printer, enumType, enumTypeSuffix, enumKeyCasing, resolver }: Props):
|
|
24
|
+
export function Type({ name, node, printer, enumType, enumTypeSuffix, enumKeyCasing, resolver }: Props): KubbReactNode {
|
|
25
25
|
const enumSchemaNodes = collect<EnumSchemaNode>(node, {
|
|
26
26
|
schema(n): EnumSchemaNode | undefined {
|
|
27
27
|
const enumNode = narrowSchema(n, schemaTypes.enum)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { caseParams, narrowSchema, schemaTypes } from '@kubb/ast'
|
|
2
2
|
import type { SchemaNode } from '@kubb/ast/types'
|
|
3
3
|
import { defineGenerator } from '@kubb/core'
|
|
4
|
-
import { File } from '@kubb/
|
|
4
|
+
import { File } from '@kubb/renderer-jsx'
|
|
5
5
|
import { Type } from '../components/Type.tsx'
|
|
6
6
|
import { ENUM_TYPES_WITH_KEY_SUFFIX } from '../constants.ts'
|
|
7
7
|
import { printerTs } from '../printers/printerTs.ts'
|
|
@@ -20,7 +20,7 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
20
20
|
const mode = this.getMode(output)
|
|
21
21
|
// Build a set of schema names that are enums so the ref handler and getImports
|
|
22
22
|
// callback can use the suffixed type name (e.g. `StatusKey`) for those refs.
|
|
23
|
-
const enumSchemaNames = new Set((adapter.
|
|
23
|
+
const enumSchemaNames = new Set((adapter.inputNode?.schemas ?? []).filter((s) => narrowSchema(s, schemaTypes.enum) && s.name).map((s) => s.name!))
|
|
24
24
|
|
|
25
25
|
function resolveImportName(schemaName: string): string {
|
|
26
26
|
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) {
|
|
@@ -59,8 +59,8 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
59
59
|
baseName={meta.file.baseName}
|
|
60
60
|
path={meta.file.path}
|
|
61
61
|
meta={meta.file.meta}
|
|
62
|
-
banner={resolver.resolveBanner(adapter.
|
|
63
|
-
footer={resolver.resolveFooter(adapter.
|
|
62
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
63
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
64
64
|
>
|
|
65
65
|
{mode === 'split' &&
|
|
66
66
|
imports.map((imp) => (
|
|
@@ -92,7 +92,7 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
92
92
|
|
|
93
93
|
// Build a set of schema names that are enums so the ref handler and getImports
|
|
94
94
|
// callback can use the suffixed type name (e.g. `StatusKey`) for those refs.
|
|
95
|
-
const enumSchemaNames = new Set((adapter.
|
|
95
|
+
const enumSchemaNames = new Set((adapter.inputNode?.schemas ?? []).filter((s) => narrowSchema(s, schemaTypes.enum) && s.name).map((s) => s.name!))
|
|
96
96
|
|
|
97
97
|
function resolveImportName(schemaName: string): string {
|
|
98
98
|
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) {
|
|
@@ -193,8 +193,8 @@ export const typeGenerator = defineGenerator<PluginTs>({
|
|
|
193
193
|
baseName={meta.file.baseName}
|
|
194
194
|
path={meta.file.path}
|
|
195
195
|
meta={meta.file.meta}
|
|
196
|
-
banner={resolver.resolveBanner(adapter.
|
|
197
|
-
footer={resolver.resolveFooter(adapter.
|
|
196
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
197
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
198
198
|
>
|
|
199
199
|
{paramTypes}
|
|
200
200
|
{responseTypes}
|
|
@@ -2,7 +2,7 @@ import { pascalCase } from '@internals/utils'
|
|
|
2
2
|
import { caseParams, createProperty, createSchema, narrowSchema, schemaTypes, transform } from '@kubb/ast'
|
|
3
3
|
import type { OperationNode, ParameterNode, SchemaNode } from '@kubb/ast/types'
|
|
4
4
|
import { defineGenerator } from '@kubb/core'
|
|
5
|
-
import { File } from '@kubb/
|
|
5
|
+
import { File } from '@kubb/renderer-jsx'
|
|
6
6
|
import { Type } from '../components/Type.tsx'
|
|
7
7
|
import { ENUM_TYPES_WITH_KEY_SUFFIX } from '../constants.ts'
|
|
8
8
|
import { printerTs } from '../printers/printerTs.ts'
|
|
@@ -195,8 +195,8 @@ export const typeGeneratorLegacy = defineGenerator<PluginTs>({
|
|
|
195
195
|
baseName={meta.file.baseName}
|
|
196
196
|
path={meta.file.path}
|
|
197
197
|
meta={meta.file.meta}
|
|
198
|
-
banner={resolver.resolveBanner(adapter.
|
|
199
|
-
footer={resolver.resolveFooter(adapter.
|
|
198
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
199
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
200
200
|
>
|
|
201
201
|
{mode === 'split' &&
|
|
202
202
|
imports.map((imp) => (
|
|
@@ -335,8 +335,8 @@ export const typeGeneratorLegacy = defineGenerator<PluginTs>({
|
|
|
335
335
|
baseName={meta.file.baseName}
|
|
336
336
|
path={meta.file.path}
|
|
337
337
|
meta={meta.file.meta}
|
|
338
|
-
banner={resolver.resolveBanner(adapter.
|
|
339
|
-
footer={resolver.resolveFooter(adapter.
|
|
338
|
+
banner={resolver.resolveBanner(adapter.inputNode, { output, config })}
|
|
339
|
+
footer={resolver.resolveFooter(adapter.inputNode, { output, config })}
|
|
340
340
|
>
|
|
341
341
|
{legacyParamTypes}
|
|
342
342
|
{responseTypes}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PrinterFactoryOptions } from '@kubb/ast'
|
|
2
2
|
import { createPrinterFactory } from '@kubb/ast'
|
|
3
|
-
import type {
|
|
3
|
+
import type { FunctionNodeType, FunctionParameterNode, FunctionParametersNode, FunctionParamNode, ParameterGroupNode, ParamsTypeNode } from '@kubb/ast/types'
|
|
4
4
|
import { PARAM_RANK } from '../constants.ts'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -10,14 +10,14 @@ export type FunctionNodeByType = {
|
|
|
10
10
|
functionParameter: FunctionParameterNode
|
|
11
11
|
parameterGroup: ParameterGroupNode
|
|
12
12
|
functionParameters: FunctionParametersNode
|
|
13
|
-
|
|
13
|
+
paramsType: ParamsTypeNode
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const kindToHandlerKey = {
|
|
17
17
|
FunctionParameter: 'functionParameter',
|
|
18
18
|
ParameterGroup: 'parameterGroup',
|
|
19
19
|
FunctionParameters: 'functionParameters',
|
|
20
|
-
|
|
20
|
+
ParamsType: 'paramsType',
|
|
21
21
|
} satisfies Record<string, FunctionNodeType>
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -26,7 +26,7 @@ const kindToHandlerKey = {
|
|
|
26
26
|
* Uses `createPrinterFactory` and dispatches handlers by `node.kind`
|
|
27
27
|
* (for function nodes) rather than by `node.type` (for schema nodes).
|
|
28
28
|
*/
|
|
29
|
-
export const defineFunctionPrinter = createPrinterFactory<
|
|
29
|
+
export const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionNodeType, FunctionNodeByType>((node) => kindToHandlerKey[node.kind])
|
|
30
30
|
|
|
31
31
|
export type FunctionPrinterOptions = {
|
|
32
32
|
/**
|
|
@@ -93,7 +93,8 @@ export const functionPrinter = defineFunctionPrinter<DefaultPrinter>((options) =
|
|
|
93
93
|
name: 'functionParameters',
|
|
94
94
|
options,
|
|
95
95
|
nodes: {
|
|
96
|
-
|
|
96
|
+
paramsType(node) {
|
|
97
|
+
if (node.kind !== 'ParamsType') return null
|
|
97
98
|
if (node.variant === 'member') {
|
|
98
99
|
return `${node.base}['${node.key}']`
|
|
99
100
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { extractRefName, isStringType, narrowSchema, schemaTypes, syncSchemaRef } from '@kubb/ast'
|
|
2
2
|
import type { PrinterFactoryOptions, PrinterPartial } from '@kubb/core'
|
|
3
3
|
import { definePrinter } from '@kubb/core'
|
|
4
|
-
import { safePrint } from '@kubb/
|
|
4
|
+
import { safePrint } from '@kubb/parser-ts'
|
|
5
5
|
import type ts from 'typescript'
|
|
6
6
|
import { ENUM_TYPES_WITH_KEY_SUFFIX, OPTIONAL_ADDS_QUESTION_TOKEN, OPTIONAL_ADDS_UNDEFINED } from '../constants.ts'
|
|
7
7
|
import * as factory from '../factory.ts'
|