@kubb/ast 5.0.0-beta.63 → 5.0.0-beta.65
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/{defineMacro-Shz8f6SG.js → defineMacro-B76LsJwO.js} +4 -4
- package/dist/{defineMacro-Shz8f6SG.js.map → defineMacro-B76LsJwO.js.map} +1 -1
- package/dist/{defineMacro-BATi7xoC.d.ts → defineMacro-BQpu6Ags.d.ts} +3 -3
- package/dist/factory-B_qPwA1b.d.ts +27 -0
- package/dist/factory.d.ts +3 -27
- package/dist/factory.js +2 -2
- package/dist/{index-B9cc8MBS.d.ts → index-CeJAFegf.d.ts} +4 -4
- package/dist/index.cjs +55 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +32 -29
- package/dist/index.js +55 -9
- package/dist/index.js.map +1 -1
- package/dist/macros.d.ts +2 -2
- package/dist/macros.js +4 -4
- package/dist/{operationParams-k5CKwSWZ.d.ts → operationParams-DCY3q4C7.d.ts} +3 -3
- package/dist/{refs-BjNDuCBD.js → refs-Dx6U5LoE.js} +3 -3
- package/dist/{refs-BjNDuCBD.js.map → refs-Dx6U5LoE.js.map} +1 -1
- package/dist/schema-BkvrrOAr.cjs.map +1 -1
- package/dist/{schema-Cbnxmz4b.js → schema-YNbOtTCM.js} +2 -2
- package/dist/{schema-Cbnxmz4b.js.map → schema-YNbOtTCM.js.map} +1 -1
- package/dist/{types-BB_xgRJ3.d.ts → types-B6thixAv.d.ts} +8 -8
- package/dist/types.d.ts +5 -5
- package/dist/{utils-DaXkewb1.js → utils-BJi0y-xg.js} +4 -4
- package/dist/utils-BJi0y-xg.js.map +1 -0
- package/dist/utils-CEepwqmb.cjs.map +1 -1
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +3 -3
- package/package.json +1 -2
- package/dist/utils-DaXkewb1.js.map +0 -1
- package/src/constants.ts +0 -150
- package/src/defineMacro.ts +0 -139
- package/src/defineNode.ts +0 -102
- package/src/definePrinter.ts +0 -258
- package/src/dialect.ts +0 -86
- package/src/factory.ts +0 -44
- package/src/guards.ts +0 -28
- package/src/index.ts +0 -13
- package/src/infer.ts +0 -132
- package/src/macros/index.ts +0 -3
- package/src/macros/macroDiscriminatorEnum.ts +0 -50
- package/src/macros/macroEnumName.ts +0 -33
- package/src/macros/macroSimplifyUnion.ts +0 -60
- package/src/nodes/base.ts +0 -49
- package/src/nodes/code.ts +0 -355
- package/src/nodes/content.ts +0 -51
- package/src/nodes/file.ts +0 -380
- package/src/nodes/function.ts +0 -283
- package/src/nodes/index.ts +0 -93
- package/src/nodes/input.ts +0 -144
- package/src/nodes/operation.ts +0 -168
- package/src/nodes/output.ts +0 -49
- package/src/nodes/parameter.ts +0 -71
- package/src/nodes/property.ts +0 -67
- package/src/nodes/requestBody.ts +0 -54
- package/src/nodes/response.ts +0 -173
- package/src/nodes/schema.ts +0 -732
- package/src/optionality.ts +0 -15
- package/src/registry.ts +0 -75
- package/src/signature.ts +0 -207
- package/src/types.ts +0 -8
- package/src/utils/codegen.ts +0 -103
- package/src/utils/extractStringsFromNodes.ts +0 -35
- package/src/utils/fileMerge.ts +0 -183
- package/src/utils/index.ts +0 -11
- package/src/utils/operationParams.ts +0 -353
- package/src/utils/refs.ts +0 -134
- package/src/utils/schemaGraph.ts +0 -177
- package/src/utils/schemaMerge.ts +0 -34
- package/src/utils/schemaTraversal.ts +0 -86
- package/src/utils/strings.ts +0 -139
- package/src/visitor.ts +0 -519
- /package/dist/{chunk-CNktS9qV.js → rolldown-runtime-CNktS9qV.js} +0 -0
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { defineMacro } from '../defineMacro.ts'
|
|
2
|
-
import { narrowSchema } from '../guards.ts'
|
|
3
|
-
import type { SchemaNode } from '../nodes/schema.ts'
|
|
4
|
-
|
|
5
|
-
type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Scalar primitive schema types used for union simplification and type narrowing.
|
|
9
|
-
*/
|
|
10
|
-
const SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])
|
|
11
|
-
|
|
12
|
-
function isScalarPrimitive(type: string): type is ScalarPrimitive {
|
|
13
|
-
return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Filters union members, dropping enum members that a broader scalar primitive already covers.
|
|
18
|
-
*/
|
|
19
|
-
function simplifyUnionMembers(members: Array<SchemaNode>): Array<SchemaNode> {
|
|
20
|
-
const scalarPrimitives = new Set(members.filter((member) => isScalarPrimitive(member.type)).map((m) => m.type))
|
|
21
|
-
if (!scalarPrimitives.size) return members
|
|
22
|
-
|
|
23
|
-
return members.filter((member) => {
|
|
24
|
-
const enumNode = narrowSchema(member, 'enum')
|
|
25
|
-
if (!enumNode) return true
|
|
26
|
-
|
|
27
|
-
const primitive = enumNode.primitive
|
|
28
|
-
if (!primitive) return true
|
|
29
|
-
|
|
30
|
-
const enumValueCount = enumNode.namedEnumValues?.length ?? enumNode.enumValues?.length ?? 0
|
|
31
|
-
if (enumValueCount <= 1) return true
|
|
32
|
-
|
|
33
|
-
if (scalarPrimitives.has(primitive)) return false
|
|
34
|
-
if ((primitive === 'integer' || primitive === 'number') && (scalarPrimitives.has('integer') || scalarPrimitives.has('number'))) return false
|
|
35
|
-
|
|
36
|
-
return true
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Removes union members a broader scalar primitive already covers, such as a multi-value string enum
|
|
42
|
-
* sitting next to a plain `string`. Single-value enums are kept.
|
|
43
|
-
*
|
|
44
|
-
* @example
|
|
45
|
-
* ```ts
|
|
46
|
-
* const next = applyMacros(unionSchema, [macroSimplifyUnion], { depth: 'shallow' })
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export const macroSimplifyUnion = defineMacro({
|
|
50
|
-
name: 'simplify-union',
|
|
51
|
-
schema(node) {
|
|
52
|
-
const unionNode = narrowSchema(node, 'union')
|
|
53
|
-
if (!unionNode?.members?.length) return undefined
|
|
54
|
-
|
|
55
|
-
const simplified = simplifyUnionMembers(unionNode.members)
|
|
56
|
-
if (simplified.length === unionNode.members.length) return undefined
|
|
57
|
-
|
|
58
|
-
return { ...unionNode, members: simplified }
|
|
59
|
-
},
|
|
60
|
-
})
|
package/src/nodes/base.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `kind` values used by AST nodes.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* const kind: NodeKind = 'Schema'
|
|
7
|
-
* ```
|
|
8
|
-
*/
|
|
9
|
-
export type NodeKind =
|
|
10
|
-
| 'Input'
|
|
11
|
-
| 'Output'
|
|
12
|
-
| 'Operation'
|
|
13
|
-
| 'Schema'
|
|
14
|
-
| 'Property'
|
|
15
|
-
| 'Parameter'
|
|
16
|
-
| 'Response'
|
|
17
|
-
| 'RequestBody'
|
|
18
|
-
| 'Content'
|
|
19
|
-
| 'FunctionParameter'
|
|
20
|
-
| 'FunctionParameters'
|
|
21
|
-
| 'TypeLiteral'
|
|
22
|
-
| 'IndexedAccessType'
|
|
23
|
-
| 'ObjectBindingPattern'
|
|
24
|
-
| 'Type'
|
|
25
|
-
| 'File'
|
|
26
|
-
| 'Import'
|
|
27
|
-
| 'Export'
|
|
28
|
-
| 'Source'
|
|
29
|
-
| 'Const'
|
|
30
|
-
| 'Function'
|
|
31
|
-
| 'ArrowFunction'
|
|
32
|
-
| 'Text'
|
|
33
|
-
| 'Break'
|
|
34
|
-
| 'Jsx'
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Base shape shared by all AST nodes.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const base: BaseNode = { kind: 'Input' }
|
|
42
|
-
* ```
|
|
43
|
-
*/
|
|
44
|
-
export type BaseNode = {
|
|
45
|
-
/**
|
|
46
|
-
* Node discriminator.
|
|
47
|
-
*/
|
|
48
|
-
kind: NodeKind
|
|
49
|
-
}
|
package/src/nodes/code.ts
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import { defineNode } from '../defineNode.ts'
|
|
2
|
-
import type { BaseNode } from './base.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* JSDoc documentation metadata attached to code declarations.
|
|
6
|
-
*/
|
|
7
|
-
export type JSDocNode = {
|
|
8
|
-
/**
|
|
9
|
-
* JSDoc comment lines. `undefined` entries are filtered out during rendering.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* ['@description A pet resource', '@deprecated']
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
|
-
comments?: Array<string | undefined>
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* AST node representing a TypeScript `const` declaration.
|
|
21
|
-
*
|
|
22
|
-
* Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.
|
|
23
|
-
* The `children` prop of the component is represented as `nodes`.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* createConst({ name: 'pet', export: true, asConst: true })
|
|
28
|
-
* // export const pet = ... as const
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export type ConstNode = BaseNode & {
|
|
32
|
-
kind: 'Const'
|
|
33
|
-
/**
|
|
34
|
-
* Name of the constant declaration.
|
|
35
|
-
*/
|
|
36
|
-
name: string
|
|
37
|
-
/**
|
|
38
|
-
* Whether the declaration should be exported.
|
|
39
|
-
*/
|
|
40
|
-
export?: boolean | null
|
|
41
|
-
/**
|
|
42
|
-
* Explicit type annotation.
|
|
43
|
-
*
|
|
44
|
-
* @example Type reference
|
|
45
|
-
* `'Pet'`
|
|
46
|
-
*/
|
|
47
|
-
type?: string | null
|
|
48
|
-
/**
|
|
49
|
-
* JSDoc documentation metadata.
|
|
50
|
-
*/
|
|
51
|
-
JSDoc?: JSDocNode | null
|
|
52
|
-
/**
|
|
53
|
-
* Whether to append `as const` to the declaration.
|
|
54
|
-
*/
|
|
55
|
-
asConst?: boolean | null
|
|
56
|
-
/**
|
|
57
|
-
* Child nodes representing the value of the constant (children of the `Const` component).
|
|
58
|
-
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
59
|
-
*/
|
|
60
|
-
nodes?: Array<CodeNode>
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* AST node representing a TypeScript `type` alias declaration.
|
|
65
|
-
*
|
|
66
|
-
* Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.
|
|
67
|
-
* The `children` prop of the component is represented as `nodes`.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* createType({ name: 'Pet', export: true })
|
|
72
|
-
* // export type Pet = ...
|
|
73
|
-
* ```
|
|
74
|
-
*/
|
|
75
|
-
export type TypeNode = BaseNode & {
|
|
76
|
-
kind: 'Type'
|
|
77
|
-
/**
|
|
78
|
-
* Name of the type alias.
|
|
79
|
-
*/
|
|
80
|
-
name: string
|
|
81
|
-
/**
|
|
82
|
-
* Whether the declaration should be exported.
|
|
83
|
-
*/
|
|
84
|
-
export?: boolean | null
|
|
85
|
-
/**
|
|
86
|
-
* JSDoc documentation metadata.
|
|
87
|
-
*/
|
|
88
|
-
JSDoc?: JSDocNode | null
|
|
89
|
-
/**
|
|
90
|
-
* Child nodes representing the type body (children of the `Type` component).
|
|
91
|
-
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
92
|
-
*/
|
|
93
|
-
nodes?: Array<CodeNode>
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* AST node representing a TypeScript `function` declaration.
|
|
98
|
-
*
|
|
99
|
-
* Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.
|
|
100
|
-
* The `children` prop of the component is represented as `nodes`.
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* ```ts
|
|
104
|
-
* createFunctionDeclaration({ name: 'getPet', export: true, async: true, returnType: 'Pet' })
|
|
105
|
-
* // export async function getPet(): Promise<Pet> { ... }
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
export type FunctionNode = BaseNode & {
|
|
109
|
-
kind: 'Function'
|
|
110
|
-
/**
|
|
111
|
-
* Name of the function.
|
|
112
|
-
*/
|
|
113
|
-
name: string
|
|
114
|
-
/**
|
|
115
|
-
* Whether the function is a default export.
|
|
116
|
-
*/
|
|
117
|
-
default?: boolean | null
|
|
118
|
-
/**
|
|
119
|
-
* Function parameter list as a pre-rendered string, written verbatim between the parentheses.
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* `'id: string, config: Config = {}'`
|
|
123
|
-
*/
|
|
124
|
-
params?: string | null
|
|
125
|
-
/**
|
|
126
|
-
* Whether the function should be exported.
|
|
127
|
-
*/
|
|
128
|
-
export?: boolean | null
|
|
129
|
-
/**
|
|
130
|
-
* Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
131
|
-
*/
|
|
132
|
-
async?: boolean | null
|
|
133
|
-
/**
|
|
134
|
-
* TypeScript generic type parameters.
|
|
135
|
-
*
|
|
136
|
-
* @example Constrained generics
|
|
137
|
-
* `['T', 'U extends string']`
|
|
138
|
-
*/
|
|
139
|
-
generics?: string | Array<string> | null
|
|
140
|
-
/**
|
|
141
|
-
* Return type annotation.
|
|
142
|
-
*
|
|
143
|
-
* @example Type reference
|
|
144
|
-
* `'Pet'`
|
|
145
|
-
*/
|
|
146
|
-
returnType?: string | null
|
|
147
|
-
/**
|
|
148
|
-
* JSDoc documentation metadata.
|
|
149
|
-
*/
|
|
150
|
-
JSDoc?: JSDocNode | null
|
|
151
|
-
/**
|
|
152
|
-
* Child nodes representing the function body (children of the `Function` component).
|
|
153
|
-
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
154
|
-
*/
|
|
155
|
-
nodes?: Array<CodeNode>
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* AST node representing a TypeScript arrow function (`const name = () => { ... }`).
|
|
160
|
-
*
|
|
161
|
-
* Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.
|
|
162
|
-
* The `children` prop of the component is represented as `nodes`.
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```ts
|
|
166
|
-
* createArrowFunctionDeclaration({ name: 'getPet', export: true, singleLine: true })
|
|
167
|
-
* // export const getPet = () => ...
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
export type ArrowFunctionNode = Omit<FunctionNode, 'kind'> & {
|
|
171
|
-
kind: 'ArrowFunction'
|
|
172
|
-
/**
|
|
173
|
-
* Render the arrow function body as a single-line expression.
|
|
174
|
-
*/
|
|
175
|
-
singleLine?: boolean | null
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* AST node representing a raw text/string fragment in the source output.
|
|
180
|
-
*
|
|
181
|
-
* Used instead of bare `string` values so that all entries in `nodes` arrays
|
|
182
|
-
* are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* ```ts
|
|
186
|
-
* createText('return fetch(id)')
|
|
187
|
-
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
export type TextNode = BaseNode & {
|
|
191
|
-
kind: 'Text'
|
|
192
|
-
/**
|
|
193
|
-
* The raw string content.
|
|
194
|
-
*/
|
|
195
|
-
value: string
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* AST node representing a blank line in the source output.
|
|
200
|
-
*
|
|
201
|
-
* Corresponds to `<br/>` in JSX components. `printNodes` turns a `Break` between two
|
|
202
|
-
* statements into one blank line. Consecutive breaks, and breaks at the start or end of
|
|
203
|
-
* the list, are folded away, so a `Break` never produces more than one blank line.
|
|
204
|
-
*
|
|
205
|
-
* @example
|
|
206
|
-
* ```ts
|
|
207
|
-
* createBreak()
|
|
208
|
-
* // { kind: 'Break' }
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
export type BreakNode = BaseNode & {
|
|
212
|
-
kind: 'Break'
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* AST node representing a raw JSX fragment in the source output.
|
|
217
|
-
*
|
|
218
|
-
* Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup
|
|
219
|
-
* (including fragments `<>…</>`) directly in generated code.
|
|
220
|
-
*
|
|
221
|
-
* @example
|
|
222
|
-
* ```ts
|
|
223
|
-
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
224
|
-
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
225
|
-
* ```
|
|
226
|
-
*/
|
|
227
|
-
export type JsxNode = BaseNode & {
|
|
228
|
-
kind: 'Jsx'
|
|
229
|
-
/**
|
|
230
|
-
* The raw JSX string content.
|
|
231
|
-
*/
|
|
232
|
-
value: string
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Union of all code-generation AST nodes.
|
|
237
|
-
*
|
|
238
|
-
* These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as
|
|
239
|
-
* structured children in {@link SourceNode.nodes}.
|
|
240
|
-
*/
|
|
241
|
-
export type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Definition for the {@link ConstNode}.
|
|
245
|
-
*/
|
|
246
|
-
export const constDef = defineNode<ConstNode>({ kind: 'Const' })
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Definition for the {@link TypeNode}.
|
|
250
|
-
*/
|
|
251
|
-
export const typeDef = defineNode<TypeNode>({ kind: 'Type' })
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Definition for the {@link FunctionNode}.
|
|
255
|
-
*/
|
|
256
|
-
export const functionDef = defineNode<FunctionNode>({ kind: 'Function' })
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Definition for the {@link ArrowFunctionNode}.
|
|
260
|
-
*/
|
|
261
|
-
export const arrowFunctionDef = defineNode<ArrowFunctionNode>({ kind: 'ArrowFunction' })
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Definition for the {@link TextNode}.
|
|
265
|
-
*/
|
|
266
|
-
export const textDef = defineNode<TextNode, string>({ kind: 'Text', build: (value) => ({ value }) })
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Definition for the {@link BreakNode}.
|
|
270
|
-
*/
|
|
271
|
-
export const breakDef = defineNode<BreakNode, void>({ kind: 'Break', build: () => ({}) })
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Definition for the {@link JsxNode}.
|
|
275
|
-
*/
|
|
276
|
-
export const jsxDef = defineNode<JsxNode, string>({ kind: 'Jsx', build: (value) => ({ value }) })
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Creates a `ConstNode` representing a TypeScript `const` declaration.
|
|
280
|
-
*
|
|
281
|
-
* @example Exported constant with type and `as const`
|
|
282
|
-
* ```ts
|
|
283
|
-
* createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
|
|
284
|
-
* // export const pets: Pet[] = ... as const
|
|
285
|
-
* ```
|
|
286
|
-
*/
|
|
287
|
-
export const createConst = constDef.create
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Creates a `TypeNode` representing a TypeScript `type` alias declaration.
|
|
291
|
-
*
|
|
292
|
-
* @example
|
|
293
|
-
* ```ts
|
|
294
|
-
* createType({ name: 'Pet', export: true })
|
|
295
|
-
* // export type Pet = ...
|
|
296
|
-
* ```
|
|
297
|
-
*/
|
|
298
|
-
export const createType = typeDef.create
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Creates a `FunctionNode` representing a TypeScript `function` declaration.
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* ```ts
|
|
305
|
-
* createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
|
|
306
|
-
* // export async function fetchPet(): Promise<Pet> { ... }
|
|
307
|
-
* ```
|
|
308
|
-
*/
|
|
309
|
-
export const createFunction = functionDef.create
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
|
|
313
|
-
*
|
|
314
|
-
* @example
|
|
315
|
-
* ```ts
|
|
316
|
-
* createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
|
|
317
|
-
* // export const double = (n: number) => ...
|
|
318
|
-
* ```
|
|
319
|
-
*/
|
|
320
|
-
export const createArrowFunction = arrowFunctionDef.create
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Creates a {@link TextNode} representing a raw string fragment in the source output.
|
|
324
|
-
*
|
|
325
|
-
* @example
|
|
326
|
-
* ```ts
|
|
327
|
-
* createText('return fetch(id)')
|
|
328
|
-
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
329
|
-
* ```
|
|
330
|
-
*/
|
|
331
|
-
export const createText = textDef.create
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Creates a {@link BreakNode} representing a line break in the source output.
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* ```ts
|
|
338
|
-
* createBreak()
|
|
339
|
-
* // { kind: 'Break' }
|
|
340
|
-
* ```
|
|
341
|
-
*/
|
|
342
|
-
export function createBreak(): BreakNode {
|
|
343
|
-
return breakDef.create()
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
|
|
348
|
-
*
|
|
349
|
-
* @example
|
|
350
|
-
* ```ts
|
|
351
|
-
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
352
|
-
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
353
|
-
* ```
|
|
354
|
-
*/
|
|
355
|
-
export const createJsx = jsxDef.create
|
package/src/nodes/content.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { defineNode } from '../defineNode.ts'
|
|
2
|
-
import type { BaseNode } from './base.ts'
|
|
3
|
-
import type { SchemaNode } from './schema.ts'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* AST node representing one content-type entry of a request body or response.
|
|
7
|
-
*
|
|
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
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* const content: ContentNode = {
|
|
14
|
-
* kind: 'Content',
|
|
15
|
-
* contentType: 'application/json',
|
|
16
|
-
* schema: createSchema({ type: 'string' }),
|
|
17
|
-
* }
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export type ContentNode = BaseNode & {
|
|
21
|
-
/**
|
|
22
|
-
* Node kind.
|
|
23
|
-
*/
|
|
24
|
-
kind: 'Content'
|
|
25
|
-
/**
|
|
26
|
-
* The content type for this entry (e.g. `'application/json'`).
|
|
27
|
-
*/
|
|
28
|
-
contentType: string
|
|
29
|
-
/**
|
|
30
|
-
* Body schema for this content type.
|
|
31
|
-
*/
|
|
32
|
-
schema?: SchemaNode
|
|
33
|
-
/**
|
|
34
|
-
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
35
|
-
* Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.
|
|
36
|
-
*/
|
|
37
|
-
keysToOmit?: Array<string> | null
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Definition for the {@link ContentNode}.
|
|
42
|
-
*/
|
|
43
|
-
export const contentDef = defineNode<ContentNode>({
|
|
44
|
-
kind: 'Content',
|
|
45
|
-
children: ['schema'],
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Creates a `ContentNode` for a single request-body or response content type.
|
|
50
|
-
*/
|
|
51
|
-
export const createContent = contentDef.create
|