@kubb/ast 5.0.0-beta.57 → 5.0.0-beta.59
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 +21 -7
- package/dist/casing-BE2R1RXg.cjs +88 -0
- package/dist/casing-BE2R1RXg.cjs.map +1 -0
- package/dist/chunk-CNktS9qV.js +17 -0
- package/dist/extractStringsFromNodes-WMYJ8nQL.d.ts +82 -0
- package/dist/factory-BmcGBdeg.cjs +1251 -0
- package/dist/factory-BmcGBdeg.cjs.map +1 -0
- package/dist/factory-Du7nEP4B.js +282 -0
- package/dist/factory-Du7nEP4B.js.map +1 -0
- package/dist/factory.cjs +28 -0
- package/dist/factory.d.ts +62 -0
- package/dist/factory.js +3 -0
- package/dist/{types-C5aVnRE1.d.ts → index-BzjwdK2M.d.ts} +94 -1146
- package/dist/index.cjs +220 -1481
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +96 -58
- package/dist/index.js +182 -1920
- package/dist/index.js.map +1 -1
- package/dist/operationParams-BZ07xDm0.d.ts +204 -0
- package/dist/response-DKxTr522.js +683 -0
- package/dist/response-DKxTr522.js.map +1 -0
- package/dist/types-olVl9v5p.d.ts +764 -0
- package/dist/types.d.ts +5 -2
- package/dist/utils-BCtRXfhI.cjs +275 -0
- package/dist/utils-BCtRXfhI.cjs.map +1 -0
- package/dist/utils-SdZU0F3H.js +1336 -0
- package/dist/utils-SdZU0F3H.js.map +1 -0
- package/dist/utils.cjs +129 -13
- package/dist/utils.d.ts +127 -76
- package/dist/utils.js +3 -2
- package/package.json +5 -1
- package/src/constants.ts +8 -14
- package/src/dedupe.ts +8 -0
- package/src/factory.ts +18 -1
- package/src/guards.ts +1 -1
- package/src/index.ts +7 -50
- package/src/node.ts +1 -1
- package/src/nodes/base.ts +0 -10
- package/src/nodes/code.ts +29 -47
- package/src/nodes/content.ts +2 -2
- package/src/nodes/file.ts +28 -23
- package/src/nodes/function.ts +2 -17
- package/src/nodes/index.ts +1 -1
- package/src/nodes/input.ts +20 -19
- package/src/nodes/operation.ts +1 -1
- package/src/nodes/parameter.ts +0 -3
- package/src/nodes/property.ts +0 -3
- package/src/nodes/requestBody.ts +3 -6
- package/src/nodes/schema.ts +3 -2
- package/src/printer.ts +4 -4
- package/src/registry.ts +31 -26
- package/src/signature.ts +3 -3
- package/src/transformers.ts +28 -1
- package/src/types.ts +2 -53
- package/src/utils/codegen.ts +104 -0
- package/src/utils/extractStringsFromNodes.ts +34 -0
- package/src/utils/fileMerge.ts +184 -0
- package/src/utils/index.ts +8 -296
- package/src/utils/operationParams.ts +353 -0
- package/src/utils/refs.ts +112 -0
- package/src/utils/schemaGraph.ts +169 -0
- package/src/utils/strings.ts +139 -0
- package/src/visitor.ts +43 -19
- package/dist/chunk-C0LytTxp.js +0 -8
- package/dist/utils-0p8ZO287.js +0 -570
- package/dist/utils-0p8ZO287.js.map +0 -1
- package/dist/utils-cdQ6Pzyi.cjs +0 -726
- package/dist/utils-cdQ6Pzyi.cjs.map +0 -1
- package/src/utils/ast.ts +0 -879
package/src/constants.ts
CHANGED
|
@@ -17,9 +17,8 @@ export const visitorDepths = {
|
|
|
17
17
|
/**
|
|
18
18
|
* Schema type discriminators used by all AST schema nodes.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.
|
|
20
|
+
* Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
|
|
21
|
+
* Call `isScalarPrimitive()` to check for the scalar types.
|
|
23
22
|
*/
|
|
24
23
|
export const schemaTypes = {
|
|
25
24
|
/**
|
|
@@ -39,7 +38,7 @@ export const schemaTypes = {
|
|
|
39
38
|
*/
|
|
40
39
|
bigint: 'bigint',
|
|
41
40
|
/**
|
|
42
|
-
* Boolean value
|
|
41
|
+
* Boolean value.
|
|
43
42
|
*/
|
|
44
43
|
boolean: 'boolean',
|
|
45
44
|
/**
|
|
@@ -132,15 +131,12 @@ export type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'bool
|
|
|
132
131
|
|
|
133
132
|
/**
|
|
134
133
|
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
135
|
-
*
|
|
136
|
-
* Use `isScalarPrimitive()` to safely check whether a type is a scalar primitive.
|
|
137
134
|
*/
|
|
138
135
|
const SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])
|
|
139
136
|
|
|
140
137
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
* Use this to check if a schema type can be directly assigned without wrapping (e.g., `string | number | boolean`).
|
|
138
|
+
* Returns `true` when `type` is a scalar primitive that can be assigned without wrapping
|
|
139
|
+
* (for example `string | number | boolean`).
|
|
144
140
|
*/
|
|
145
141
|
export function isScalarPrimitive(type: string): type is ScalarPrimitive {
|
|
146
142
|
return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)
|
|
@@ -148,8 +144,6 @@ export function isScalarPrimitive(type: string): type is ScalarPrimitive {
|
|
|
148
144
|
|
|
149
145
|
/**
|
|
150
146
|
* HTTP method identifiers used by operation nodes.
|
|
151
|
-
*
|
|
152
|
-
* Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).
|
|
153
147
|
*/
|
|
154
148
|
export const httpMethods = {
|
|
155
149
|
get: 'GET',
|
|
@@ -163,10 +157,10 @@ export const httpMethods = {
|
|
|
163
157
|
} as const satisfies Record<Lowercase<HttpMethod>, HttpMethod>
|
|
164
158
|
|
|
165
159
|
/**
|
|
166
|
-
* Default concurrency limit for `walk()` traversal utility.
|
|
160
|
+
* Default concurrency limit for the `walk()` traversal utility.
|
|
167
161
|
*
|
|
168
|
-
* Set to 30 to balance I/O-bound resolver parallelism against event
|
|
169
|
-
*
|
|
162
|
+
* Set to 30 to balance I/O-bound resolver parallelism against event-loop and memory pressure
|
|
163
|
+
* during large spec traversals. Override it for different hardware constraints.
|
|
170
164
|
*
|
|
171
165
|
* @example
|
|
172
166
|
* ```ts
|
package/src/dedupe.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema-shape deduplication. `buildDedupePlan` finds top-level and inline schemas that share a
|
|
3
|
+
* structural signature, picks one canonical definition, and `applyDedupe` repoints every duplicate
|
|
4
|
+
* at it. This works on `SchemaNode` content, not on files.
|
|
5
|
+
*
|
|
6
|
+
* For merging a file's imports, exports, and source nodes, see `utils/fileMerge.ts`. Same idea of
|
|
7
|
+
* collapsing duplicates, but a different domain.
|
|
8
|
+
*/
|
|
1
9
|
import type { Node, OperationNode, SchemaNode } from './nodes/index.ts'
|
|
2
10
|
import { createSchema } from './nodes/schema.ts'
|
|
3
11
|
import { signatureOf } from './signature.ts'
|
package/src/factory.ts
CHANGED
|
@@ -2,7 +2,24 @@ import { hash } from 'node:crypto'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { trimExtName } from '@internals/utils'
|
|
4
4
|
import type { FileNode, Node } from './nodes/index.ts'
|
|
5
|
-
import {
|
|
5
|
+
import { extractStringsFromNodes } from './utils/extractStringsFromNodes.ts'
|
|
6
|
+
import { combineExports, combineImports, combineSources } from './utils/fileMerge.ts'
|
|
7
|
+
|
|
8
|
+
// Node constructors, grouped under the `factory` namespace the way the TypeScript compiler exposes
|
|
9
|
+
// `ts.factory.createX`. Aggregating them here lets `export * as factory from './factory.ts'` in the
|
|
10
|
+
// barrel surface every `createX` alongside the `createFile`/`update` helpers from a single module.
|
|
11
|
+
export { createArrowFunction, createBreak, createConst, createFunction, createJsx, createText, createType } from './nodes/code.ts'
|
|
12
|
+
export { createContent } from './nodes/content.ts'
|
|
13
|
+
export { createExport, createImport, createSource } from './nodes/file.ts'
|
|
14
|
+
export { createFunctionParameter, createFunctionParameters, createIndexedAccessType, createObjectBindingPattern, createTypeLiteral } from './nodes/function.ts'
|
|
15
|
+
export { createInput } from './nodes/input.ts'
|
|
16
|
+
export { createOperation } from './nodes/operation.ts'
|
|
17
|
+
export { createOutput } from './nodes/output.ts'
|
|
18
|
+
export { createParameter } from './nodes/parameter.ts'
|
|
19
|
+
export { createProperty } from './nodes/property.ts'
|
|
20
|
+
export { createRequestBody } from './nodes/requestBody.ts'
|
|
21
|
+
export { createResponse } from './nodes/response.ts'
|
|
22
|
+
export { createSchema } from './nodes/schema.ts'
|
|
6
23
|
|
|
7
24
|
/**
|
|
8
25
|
* Identity-preserving node update: returns `node` unchanged when every field in
|
package/src/guards.ts
CHANGED
|
@@ -14,7 +14,7 @@ export function narrowSchema<T extends SchemaNode['type']>(node: SchemaNode | un
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* Narrows an `OperationNode` to an `HttpOperationNode
|
|
17
|
+
* Narrows an `OperationNode` to an `HttpOperationNode` so `method` and `path` are present.
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
package/src/index.ts
CHANGED
|
@@ -1,62 +1,19 @@
|
|
|
1
1
|
export { httpMethods, schemaTypes } from './constants.ts'
|
|
2
2
|
export { applyDedupe, buildDedupePlan } from './dedupe.ts'
|
|
3
3
|
export { defineSchemaDialect } from './dialect.ts'
|
|
4
|
-
|
|
4
|
+
// Node constructors, also published as the `@kubb/ast/factory` subpath, mirroring `ts.factory.createX`.
|
|
5
|
+
export * as factory from './factory.ts'
|
|
5
6
|
export { isHttpOperationNode, narrowSchema } from './guards.ts'
|
|
6
7
|
export { defineNode } from './node.ts'
|
|
7
8
|
export type { NodeDef } from './node.ts'
|
|
8
9
|
export { syncOptionality } from './node.ts'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constDef,
|
|
13
|
-
createArrowFunction,
|
|
14
|
-
createBreak,
|
|
15
|
-
createConst,
|
|
16
|
-
createFunction,
|
|
17
|
-
createJsx,
|
|
18
|
-
createText,
|
|
19
|
-
createType,
|
|
20
|
-
functionDef,
|
|
21
|
-
jsxDef,
|
|
22
|
-
textDef,
|
|
23
|
-
typeDef,
|
|
24
|
-
} from './nodes/code.ts'
|
|
25
|
-
export { contentDef } from './nodes/content.ts'
|
|
26
|
-
export { createExport, createImport, createSource, exportDef, fileDef, importDef, sourceDef } from './nodes/file.ts'
|
|
27
|
-
export {
|
|
28
|
-
createFunctionParameter,
|
|
29
|
-
createFunctionParameters,
|
|
30
|
-
createIndexedAccessType,
|
|
31
|
-
createObjectBindingPattern,
|
|
32
|
-
createTypeLiteral,
|
|
33
|
-
functionParameterDef,
|
|
34
|
-
functionParametersDef,
|
|
35
|
-
indexedAccessTypeDef,
|
|
36
|
-
objectBindingPatternDef,
|
|
37
|
-
typeLiteralDef,
|
|
38
|
-
} from './nodes/function.ts'
|
|
39
|
-
export { createInput, createStreamInput, inputDef } from './nodes/input.ts'
|
|
40
|
-
export { createOperation, operationDef } from './nodes/operation.ts'
|
|
41
|
-
export { createOutput, outputDef } from './nodes/output.ts'
|
|
42
|
-
export { createParameter, parameterDef } from './nodes/parameter.ts'
|
|
43
|
-
export { createProperty, propertyDef } from './nodes/property.ts'
|
|
44
|
-
export { requestBodyDef } from './nodes/requestBody.ts'
|
|
45
|
-
export { createResponse, responseDef } from './nodes/response.ts'
|
|
46
|
-
export { createSchema, schemaDef } from './nodes/schema.ts'
|
|
10
|
+
// Every node def plus `nodeDefs` in one line, so adding a node never edits this barrel. The visitor
|
|
11
|
+
// tables derived from `nodeDefs` stay internal to `visitor.ts`.
|
|
12
|
+
export * from './registry.ts'
|
|
47
13
|
export { createPrinterFactory, definePrinter } from './printer.ts'
|
|
48
14
|
export { signatureOf } from './signature.ts'
|
|
49
15
|
export { mergeAdjacentObjectsLazy, setDiscriminatorEnum, setEnumName, simplifyUnion } from './transformers.ts'
|
|
50
16
|
export type * from './types.ts'
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
collectUsedSchemaNames,
|
|
54
|
-
containsCircularRef,
|
|
55
|
-
createDiscriminantNode,
|
|
56
|
-
createOperationParams,
|
|
57
|
-
extractStringsFromNodes,
|
|
58
|
-
findCircularSchemas,
|
|
59
|
-
isStringType,
|
|
60
|
-
syncSchemaRef,
|
|
61
|
-
} from './utils/ast.ts'
|
|
17
|
+
// The node/AST helpers in ./utils/ live on the `@kubb/ast/utils` subpath, not the root barrel.
|
|
18
|
+
export { extractStringsFromNodes } from './utils/extractStringsFromNodes.ts'
|
|
62
19
|
export { collect, transform, walk } from './visitor.ts'
|
package/src/node.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omi
|
|
|
23
23
|
/**
|
|
24
24
|
* Builds a type guard that matches nodes of the given `kind`.
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
function isKind<T extends BaseNode>(kind: NodeKind) {
|
|
27
27
|
return (node: unknown): node is T => (node as BaseNode).kind === kind
|
|
28
28
|
}
|
|
29
29
|
|
package/src/nodes/base.ts
CHANGED
package/src/nodes/code.ts
CHANGED
|
@@ -7,7 +7,11 @@ import type { BaseNode } from './base.ts'
|
|
|
7
7
|
export type JSDocNode = {
|
|
8
8
|
/**
|
|
9
9
|
* JSDoc comment lines. `undefined` entries are filtered out during rendering.
|
|
10
|
-
*
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* ['@description A pet resource', '@deprecated']
|
|
14
|
+
* ```
|
|
11
15
|
*/
|
|
12
16
|
comments?: Array<string | undefined>
|
|
13
17
|
}
|
|
@@ -25,9 +29,6 @@ export type JSDocNode = {
|
|
|
25
29
|
* ```
|
|
26
30
|
*/
|
|
27
31
|
export type ConstNode = BaseNode & {
|
|
28
|
-
/**
|
|
29
|
-
* Node kind.
|
|
30
|
-
*/
|
|
31
32
|
kind: 'Const'
|
|
32
33
|
/**
|
|
33
34
|
* Name of the constant declaration.
|
|
@@ -35,12 +36,13 @@ export type ConstNode = BaseNode & {
|
|
|
35
36
|
name: string
|
|
36
37
|
/**
|
|
37
38
|
* Whether the declaration should be exported.
|
|
38
|
-
* @default false
|
|
39
39
|
*/
|
|
40
40
|
export?: boolean | null
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* Explicit type annotation.
|
|
43
|
+
*
|
|
44
|
+
* @example Type reference
|
|
45
|
+
* `'Pet'`
|
|
44
46
|
*/
|
|
45
47
|
type?: string | null
|
|
46
48
|
/**
|
|
@@ -49,12 +51,11 @@ export type ConstNode = BaseNode & {
|
|
|
49
51
|
JSDoc?: JSDocNode | null
|
|
50
52
|
/**
|
|
51
53
|
* Whether to append `as const` to the declaration.
|
|
52
|
-
* @default false
|
|
53
54
|
*/
|
|
54
55
|
asConst?: boolean | null
|
|
55
56
|
/**
|
|
56
57
|
* Child nodes representing the value of the constant (children of the `Const` component).
|
|
57
|
-
* Each entry is a {@link CodeNode}
|
|
58
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
58
59
|
*/
|
|
59
60
|
nodes?: Array<CodeNode>
|
|
60
61
|
}
|
|
@@ -72,9 +73,6 @@ export type ConstNode = BaseNode & {
|
|
|
72
73
|
* ```
|
|
73
74
|
*/
|
|
74
75
|
export type TypeNode = BaseNode & {
|
|
75
|
-
/**
|
|
76
|
-
* Node kind.
|
|
77
|
-
*/
|
|
78
76
|
kind: 'Type'
|
|
79
77
|
/**
|
|
80
78
|
* Name of the type alias.
|
|
@@ -82,7 +80,6 @@ export type TypeNode = BaseNode & {
|
|
|
82
80
|
name: string
|
|
83
81
|
/**
|
|
84
82
|
* Whether the declaration should be exported.
|
|
85
|
-
* @default false
|
|
86
83
|
*/
|
|
87
84
|
export?: boolean | null
|
|
88
85
|
/**
|
|
@@ -91,7 +88,7 @@ export type TypeNode = BaseNode & {
|
|
|
91
88
|
JSDoc?: JSDocNode | null
|
|
92
89
|
/**
|
|
93
90
|
* Child nodes representing the type body (children of the `Type` component).
|
|
94
|
-
* Each entry is a {@link CodeNode}
|
|
91
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
95
92
|
*/
|
|
96
93
|
nodes?: Array<CodeNode>
|
|
97
94
|
}
|
|
@@ -109,9 +106,6 @@ export type TypeNode = BaseNode & {
|
|
|
109
106
|
* ```
|
|
110
107
|
*/
|
|
111
108
|
export type FunctionNode = BaseNode & {
|
|
112
|
-
/**
|
|
113
|
-
* Node kind.
|
|
114
|
-
*/
|
|
115
109
|
kind: 'Function'
|
|
116
110
|
/**
|
|
117
111
|
* Name of the function.
|
|
@@ -119,7 +113,6 @@ export type FunctionNode = BaseNode & {
|
|
|
119
113
|
name: string
|
|
120
114
|
/**
|
|
121
115
|
* Whether the function is a default export.
|
|
122
|
-
* @default false
|
|
123
116
|
*/
|
|
124
117
|
default?: boolean | null
|
|
125
118
|
/**
|
|
@@ -128,22 +121,24 @@ export type FunctionNode = BaseNode & {
|
|
|
128
121
|
params?: string | null
|
|
129
122
|
/**
|
|
130
123
|
* Whether the function should be exported.
|
|
131
|
-
* @default false
|
|
132
124
|
*/
|
|
133
125
|
export?: boolean | null
|
|
134
126
|
/**
|
|
135
127
|
* Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
136
|
-
* @default false
|
|
137
128
|
*/
|
|
138
129
|
async?: boolean | null
|
|
139
130
|
/**
|
|
140
131
|
* TypeScript generic type parameters.
|
|
141
|
-
*
|
|
132
|
+
*
|
|
133
|
+
* @example Constrained generics
|
|
134
|
+
* `['T', 'U extends string']`
|
|
142
135
|
*/
|
|
143
136
|
generics?: string | Array<string> | null
|
|
144
137
|
/**
|
|
145
138
|
* Return type annotation.
|
|
146
|
-
*
|
|
139
|
+
*
|
|
140
|
+
* @example Type reference
|
|
141
|
+
* `'Pet'`
|
|
147
142
|
*/
|
|
148
143
|
returnType?: string | null
|
|
149
144
|
/**
|
|
@@ -152,7 +147,7 @@ export type FunctionNode = BaseNode & {
|
|
|
152
147
|
JSDoc?: JSDocNode | null
|
|
153
148
|
/**
|
|
154
149
|
* Child nodes representing the function body (children of the `Function` component).
|
|
155
|
-
* Each entry is a {@link CodeNode}
|
|
150
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
156
151
|
*/
|
|
157
152
|
nodes?: Array<CodeNode>
|
|
158
153
|
}
|
|
@@ -170,9 +165,6 @@ export type FunctionNode = BaseNode & {
|
|
|
170
165
|
* ```
|
|
171
166
|
*/
|
|
172
167
|
export type ArrowFunctionNode = BaseNode & {
|
|
173
|
-
/**
|
|
174
|
-
* Node kind.
|
|
175
|
-
*/
|
|
176
168
|
kind: 'ArrowFunction'
|
|
177
169
|
/**
|
|
178
170
|
* Name of the arrow function (used as the `const` variable name).
|
|
@@ -180,7 +172,6 @@ export type ArrowFunctionNode = BaseNode & {
|
|
|
180
172
|
name: string
|
|
181
173
|
/**
|
|
182
174
|
* Whether the function is a default export.
|
|
183
|
-
* @default false
|
|
184
175
|
*/
|
|
185
176
|
default?: boolean | null
|
|
186
177
|
/**
|
|
@@ -189,22 +180,24 @@ export type ArrowFunctionNode = BaseNode & {
|
|
|
189
180
|
params?: string | null
|
|
190
181
|
/**
|
|
191
182
|
* Whether the arrow function should be exported.
|
|
192
|
-
* @default false
|
|
193
183
|
*/
|
|
194
184
|
export?: boolean | null
|
|
195
185
|
/**
|
|
196
186
|
* Whether the arrow function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
197
|
-
* @default false
|
|
198
187
|
*/
|
|
199
188
|
async?: boolean | null
|
|
200
189
|
/**
|
|
201
190
|
* TypeScript generic type parameters.
|
|
202
|
-
*
|
|
191
|
+
*
|
|
192
|
+
* @example Constrained generics
|
|
193
|
+
* `['T', 'U extends string']`
|
|
203
194
|
*/
|
|
204
195
|
generics?: string | Array<string> | null
|
|
205
196
|
/**
|
|
206
197
|
* Return type annotation.
|
|
207
|
-
*
|
|
198
|
+
*
|
|
199
|
+
* @example Type reference
|
|
200
|
+
* `'Pet'`
|
|
208
201
|
*/
|
|
209
202
|
returnType?: string | null
|
|
210
203
|
/**
|
|
@@ -213,12 +206,11 @@ export type ArrowFunctionNode = BaseNode & {
|
|
|
213
206
|
JSDoc?: JSDocNode | null
|
|
214
207
|
/**
|
|
215
208
|
* Render the arrow function body as a single-line expression.
|
|
216
|
-
* @default false
|
|
217
209
|
*/
|
|
218
210
|
singleLine?: boolean | null
|
|
219
211
|
/**
|
|
220
212
|
* Child nodes representing the function body (children of the `Function.Arrow` component).
|
|
221
|
-
* Each entry is a {@link CodeNode}
|
|
213
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
222
214
|
*/
|
|
223
215
|
nodes?: Array<CodeNode>
|
|
224
216
|
}
|
|
@@ -236,9 +228,6 @@ export type ArrowFunctionNode = BaseNode & {
|
|
|
236
228
|
* ```
|
|
237
229
|
*/
|
|
238
230
|
export type TextNode = BaseNode & {
|
|
239
|
-
/**
|
|
240
|
-
* Node kind.
|
|
241
|
-
*/
|
|
242
231
|
kind: 'Text'
|
|
243
232
|
/**
|
|
244
233
|
* The raw string content.
|
|
@@ -249,9 +238,8 @@ export type TextNode = BaseNode & {
|
|
|
249
238
|
/**
|
|
250
239
|
* AST node representing a line break in the source output.
|
|
251
240
|
*
|
|
252
|
-
* Corresponds to `<br/>` in JSX components. When printed
|
|
253
|
-
*
|
|
254
|
-
* between surrounding code nodes.
|
|
241
|
+
* Corresponds to `<br/>` in JSX components. When printed it produces an empty string,
|
|
242
|
+
* so joining nodes with `\n` in `printNodes` leaves a blank line between the surrounding code.
|
|
255
243
|
*
|
|
256
244
|
* @example
|
|
257
245
|
* ```ts
|
|
@@ -261,17 +249,14 @@ export type TextNode = BaseNode & {
|
|
|
261
249
|
* ```
|
|
262
250
|
*/
|
|
263
251
|
export type BreakNode = BaseNode & {
|
|
264
|
-
/**
|
|
265
|
-
* Node kind.
|
|
266
|
-
*/
|
|
267
252
|
kind: 'Break'
|
|
268
253
|
}
|
|
269
254
|
|
|
270
255
|
/**
|
|
271
256
|
* AST node representing a raw JSX fragment in the source output.
|
|
272
257
|
*
|
|
273
|
-
* Mirrors the `Jsx` component from `@kubb/renderer-jsx`.
|
|
274
|
-
*
|
|
258
|
+
* Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup
|
|
259
|
+
* (including fragments `<>…</>`) directly in generated code.
|
|
275
260
|
*
|
|
276
261
|
* @example
|
|
277
262
|
* ```ts
|
|
@@ -280,9 +265,6 @@ export type BreakNode = BaseNode & {
|
|
|
280
265
|
* ```
|
|
281
266
|
*/
|
|
282
267
|
export type JsxNode = BaseNode & {
|
|
283
|
-
/**
|
|
284
|
-
* Node kind.
|
|
285
|
-
*/
|
|
286
268
|
kind: 'Jsx'
|
|
287
269
|
/**
|
|
288
270
|
* The raw JSX string content.
|
package/src/nodes/content.ts
CHANGED
|
@@ -5,8 +5,8 @@ import type { SchemaNode } from './schema.ts'
|
|
|
5
5
|
/**
|
|
6
6
|
* AST node representing one content-type entry of a request body or response.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
* `multipart/form-data`), each
|
|
8
|
+
* There is one entry per content type declared in the spec (e.g. `application/json`,
|
|
9
|
+
* `multipart/form-data`), and each entry holds its own body schema.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
package/src/nodes/file.ts
CHANGED
|
@@ -36,27 +36,31 @@ export type ImportNode = BaseNode & {
|
|
|
36
36
|
kind: 'Import'
|
|
37
37
|
/**
|
|
38
38
|
* Import name(s) to be used.
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
39
|
+
*
|
|
40
|
+
* @example Named imports
|
|
41
|
+
* `['useState']`
|
|
42
|
+
*
|
|
43
|
+
* @example Default import
|
|
44
|
+
* `'React'`
|
|
41
45
|
*/
|
|
42
46
|
name: ImportName
|
|
43
47
|
/**
|
|
44
48
|
* Path for the import.
|
|
45
|
-
*
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* `'@kubb/core'`
|
|
46
52
|
*/
|
|
47
53
|
path: string
|
|
48
54
|
/**
|
|
49
|
-
* Add type-only import prefix.
|
|
55
|
+
* Add a type-only import prefix.
|
|
50
56
|
* - `true` generates `import type { Type } from './path'`
|
|
51
57
|
* - `false` generates `import { Type } from './path'`
|
|
52
|
-
* @default false
|
|
53
58
|
*/
|
|
54
59
|
isTypeOnly?: boolean | null
|
|
55
60
|
/**
|
|
56
|
-
* Import entire module as namespace.
|
|
61
|
+
* Import the entire module as a namespace.
|
|
57
62
|
* - `true` generates `import * as Name from './path'`
|
|
58
|
-
* - `false` generates standard import
|
|
59
|
-
* @default false
|
|
63
|
+
* - `false` generates a standard import
|
|
60
64
|
*/
|
|
61
65
|
isNameSpace?: boolean | null
|
|
62
66
|
/**
|
|
@@ -92,27 +96,31 @@ export type ExportNode = BaseNode & {
|
|
|
92
96
|
kind: 'Export'
|
|
93
97
|
/**
|
|
94
98
|
* Export name(s) to be used. When omitted, generates a wildcard export.
|
|
95
|
-
*
|
|
96
|
-
* @example
|
|
99
|
+
*
|
|
100
|
+
* @example Named exports
|
|
101
|
+
* `['useState']`
|
|
102
|
+
*
|
|
103
|
+
* @example Single export
|
|
104
|
+
* `'React'`
|
|
97
105
|
*/
|
|
98
106
|
name?: string | Array<string> | null
|
|
99
107
|
/**
|
|
100
108
|
* Path for the export.
|
|
101
|
-
*
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* `'@kubb/core'`
|
|
102
112
|
*/
|
|
103
113
|
path: string
|
|
104
114
|
/**
|
|
105
|
-
* Add type-only export prefix.
|
|
115
|
+
* Add a type-only export prefix.
|
|
106
116
|
* - `true` generates `export type { Type } from './path'`
|
|
107
117
|
* - `false` generates `export { Type } from './path'`
|
|
108
|
-
* @default false
|
|
109
118
|
*/
|
|
110
119
|
isTypeOnly?: boolean | null
|
|
111
120
|
/**
|
|
112
121
|
* Export as an aliased namespace.
|
|
113
122
|
* - `true` generates `export * as aliasName from './path'`
|
|
114
123
|
* - `false` generates a standard export
|
|
115
|
-
* @default false
|
|
116
124
|
*/
|
|
117
125
|
asAlias?: boolean | null
|
|
118
126
|
}
|
|
@@ -138,22 +146,19 @@ export type SourceNode = BaseNode & {
|
|
|
138
146
|
name?: string | null
|
|
139
147
|
/**
|
|
140
148
|
* Mark this source as a type-only export.
|
|
141
|
-
* @default false
|
|
142
149
|
*/
|
|
143
150
|
isTypeOnly?: boolean | null
|
|
144
151
|
/**
|
|
145
|
-
* Include `export` keyword in the generated source.
|
|
146
|
-
* @default false
|
|
152
|
+
* Include the `export` keyword in the generated source.
|
|
147
153
|
*/
|
|
148
154
|
isExportable?: boolean | null
|
|
149
155
|
/**
|
|
150
156
|
* Include this source in barrel/index file generation.
|
|
151
|
-
* @default false
|
|
152
157
|
*/
|
|
153
158
|
isIndexable?: boolean | null
|
|
154
159
|
/**
|
|
155
|
-
*
|
|
156
|
-
*
|
|
160
|
+
* Child nodes that make up this source fragment, in DOM order.
|
|
161
|
+
* Use a {@link TextNode} for raw string content.
|
|
157
162
|
*/
|
|
158
163
|
nodes?: Array<CodeNode>
|
|
159
164
|
}
|
|
@@ -181,8 +186,8 @@ export type SourceNode = BaseNode & {
|
|
|
181
186
|
export type FileNode<TMeta extends object = object> = BaseNode & {
|
|
182
187
|
kind: 'File'
|
|
183
188
|
/**
|
|
184
|
-
* Unique identifier derived from a SHA256 hash of the file path.
|
|
185
|
-
*
|
|
189
|
+
* Unique identifier derived from a SHA256 hash of the file path. `createFile`
|
|
190
|
+
* computes it, so callers do not need to provide it.
|
|
186
191
|
*/
|
|
187
192
|
id: string
|
|
188
193
|
/**
|
|
@@ -217,7 +222,7 @@ export type FileNode<TMeta extends object = object> = BaseNode & {
|
|
|
217
222
|
*/
|
|
218
223
|
exports: Array<ExportNode>
|
|
219
224
|
/**
|
|
220
|
-
* Optional metadata attached to this file
|
|
225
|
+
* Optional metadata attached to this file, read by plugins during barrel generation.
|
|
221
226
|
*/
|
|
222
227
|
meta?: TMeta
|
|
223
228
|
/**
|
package/src/nodes/function.ts
CHANGED
|
@@ -21,9 +21,6 @@ export type TypeExpression = string | TypeLiteralNode | IndexedAccessTypeNode
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
export type TypeLiteralNode = BaseNode & {
|
|
24
|
-
/**
|
|
25
|
-
* Node kind.
|
|
26
|
-
*/
|
|
27
24
|
kind: 'TypeLiteral'
|
|
28
25
|
/**
|
|
29
26
|
* Members of the object type, rendered in order.
|
|
@@ -55,9 +52,6 @@ export type TypeLiteralNode = BaseNode & {
|
|
|
55
52
|
* ```
|
|
56
53
|
*/
|
|
57
54
|
export type IndexedAccessTypeNode = BaseNode & {
|
|
58
|
-
/**
|
|
59
|
-
* Node kind.
|
|
60
|
-
*/
|
|
61
55
|
kind: 'IndexedAccessType'
|
|
62
56
|
/**
|
|
63
57
|
* Name of the type being indexed, e.g. `'GetPetPathParams'`.
|
|
@@ -80,9 +74,6 @@ export type IndexedAccessTypeNode = BaseNode & {
|
|
|
80
74
|
* ```
|
|
81
75
|
*/
|
|
82
76
|
export type ObjectBindingPatternNode = BaseNode & {
|
|
83
|
-
/**
|
|
84
|
-
* Node kind.
|
|
85
|
-
*/
|
|
86
77
|
kind: 'ObjectBindingPattern'
|
|
87
78
|
/**
|
|
88
79
|
* Bound elements, rendered in order.
|
|
@@ -121,9 +112,6 @@ export type ObjectBindingPatternNode = BaseNode & {
|
|
|
121
112
|
* `{ id, name? }: { id: string; name?: string } = {}`
|
|
122
113
|
*/
|
|
123
114
|
export type FunctionParameterNode = BaseNode & {
|
|
124
|
-
/**
|
|
125
|
-
* Node kind.
|
|
126
|
-
*/
|
|
127
115
|
kind: 'FunctionParameter'
|
|
128
116
|
/**
|
|
129
117
|
* Parameter name, or an {@link ObjectBindingPatternNode} for a destructured group.
|
|
@@ -158,9 +146,6 @@ export type FunctionParameterNode = BaseNode & {
|
|
|
158
146
|
* - `call` → `(id, { method, url })` function call arguments
|
|
159
147
|
*/
|
|
160
148
|
export type FunctionParametersNode = BaseNode & {
|
|
161
|
-
/**
|
|
162
|
-
* Node kind.
|
|
163
|
-
*/
|
|
164
149
|
kind: 'FunctionParameters'
|
|
165
150
|
/**
|
|
166
151
|
* Ordered parameter nodes.
|
|
@@ -174,9 +159,9 @@ export type FunctionParametersNode = BaseNode & {
|
|
|
174
159
|
export type FunctionParamNode = FunctionParameterNode | FunctionParametersNode | TypeLiteralNode | IndexedAccessTypeNode | ObjectBindingPatternNode
|
|
175
160
|
|
|
176
161
|
/**
|
|
177
|
-
* Handler
|
|
162
|
+
* Handler-map keys for the function-parameter printer, one per {@link FunctionParamNode} kind.
|
|
178
163
|
*/
|
|
179
|
-
export type
|
|
164
|
+
export type FunctionParamKind = FunctionParamNode['kind']
|
|
180
165
|
|
|
181
166
|
/**
|
|
182
167
|
* Definition for the {@link TypeLiteralNode}.
|
package/src/nodes/index.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type { ArrowFunctionNode, BreakNode, CodeNode, ConstNode, FunctionNode, J
|
|
|
16
16
|
export type { ContentNode } from './content.ts'
|
|
17
17
|
export type { ExportNode, FileNode, ImportNode, SourceNode } from './file.ts'
|
|
18
18
|
export type {
|
|
19
|
-
|
|
19
|
+
FunctionParamKind,
|
|
20
20
|
FunctionParameterNode,
|
|
21
21
|
FunctionParametersNode,
|
|
22
22
|
FunctionParamNode,
|