@kubb/ast 5.0.0-beta.6 → 5.0.0-beta.60

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.
Files changed (78) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +50 -27
  3. package/dist/chunk-CNktS9qV.js +17 -0
  4. package/dist/extractStringsFromNodes-WMYJ8nQL.d.ts +82 -0
  5. package/dist/factory-Cl8Z7mcc.cjs +299 -0
  6. package/dist/factory-Cl8Z7mcc.cjs.map +1 -0
  7. package/dist/factory-Du7nEP4B.js +282 -0
  8. package/dist/factory-Du7nEP4B.js.map +1 -0
  9. package/dist/factory.cjs +29 -0
  10. package/dist/factory.d.ts +62 -0
  11. package/dist/factory.js +3 -0
  12. package/dist/index-BzjwdK2M.d.ts +2433 -0
  13. package/dist/index.cjs +442 -2180
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +93 -3408
  16. package/dist/index.js +392 -2101
  17. package/dist/index.js.map +1 -1
  18. package/dist/operationParams-BZ07xDm0.d.ts +204 -0
  19. package/dist/response-DKxTr522.js +683 -0
  20. package/dist/response-DKxTr522.js.map +1 -0
  21. package/dist/response-DS5S3IG4.cjs +1058 -0
  22. package/dist/response-DS5S3IG4.cjs.map +1 -0
  23. package/dist/types-olVl9v5p.d.ts +764 -0
  24. package/dist/types.cjs +0 -0
  25. package/dist/types.d.ts +5 -0
  26. package/dist/types.js +1 -0
  27. package/dist/utils-D83JA6Xx.cjs +1645 -0
  28. package/dist/utils-D83JA6Xx.cjs.map +1 -0
  29. package/dist/utils-Dj_KoXMv.js +1389 -0
  30. package/dist/utils-Dj_KoXMv.js.map +1 -0
  31. package/dist/utils.cjs +34 -0
  32. package/dist/utils.d.ts +332 -0
  33. package/dist/utils.js +3 -0
  34. package/package.json +17 -6
  35. package/src/constants.ts +19 -64
  36. package/src/dedupe.ts +239 -0
  37. package/src/dialect.ts +53 -0
  38. package/src/factory.ts +67 -678
  39. package/src/guards.ts +10 -92
  40. package/src/index.ts +16 -43
  41. package/src/infer.ts +16 -14
  42. package/src/mocks.ts +7 -127
  43. package/src/node.ts +128 -0
  44. package/src/nodes/base.ts +5 -12
  45. package/src/nodes/code.ts +165 -74
  46. package/src/nodes/content.ts +56 -0
  47. package/src/nodes/file.ts +97 -36
  48. package/src/nodes/function.ts +216 -156
  49. package/src/nodes/http.ts +1 -35
  50. package/src/nodes/index.ts +23 -15
  51. package/src/nodes/input.ts +140 -0
  52. package/src/nodes/operation.ts +122 -68
  53. package/src/nodes/output.ts +23 -0
  54. package/src/nodes/parameter.ts +33 -3
  55. package/src/nodes/property.ts +36 -3
  56. package/src/nodes/requestBody.ts +61 -0
  57. package/src/nodes/response.ts +58 -13
  58. package/src/nodes/schema.ts +93 -17
  59. package/src/printer.ts +48 -42
  60. package/src/registry.ts +75 -0
  61. package/src/signature.ts +207 -0
  62. package/src/transformers.ts +50 -18
  63. package/src/types.ts +7 -68
  64. package/src/utils/codegen.ts +104 -0
  65. package/src/utils/extractStringsFromNodes.ts +34 -0
  66. package/src/utils/fileMerge.ts +184 -0
  67. package/src/utils/index.ts +11 -0
  68. package/src/utils/operationParams.ts +353 -0
  69. package/src/utils/refs.ts +112 -0
  70. package/src/utils/schemaGraph.ts +169 -0
  71. package/src/utils/schemaTraversal.ts +86 -0
  72. package/src/utils/strings.ts +139 -0
  73. package/src/visitor.ts +227 -289
  74. package/dist/chunk--u3MIqq1.js +0 -8
  75. package/src/nodes/root.ts +0 -64
  76. package/src/refs.ts +0 -67
  77. package/src/resolvers.ts +0 -45
  78. package/src/utils.ts +0 -915
package/src/nodes/code.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { defineNode } from '../node.ts'
1
2
  import type { BaseNode } from './base.ts'
2
3
 
3
4
  /**
@@ -6,7 +7,11 @@ import type { BaseNode } from './base.ts'
6
7
  export type JSDocNode = {
7
8
  /**
8
9
  * JSDoc comment lines. `undefined` entries are filtered out during rendering.
9
- * @example ['@description A pet resource', '@deprecated']
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * ['@description A pet resource', '@deprecated']
14
+ * ```
10
15
  */
11
16
  comments?: Array<string | undefined>
12
17
  }
@@ -24,9 +29,6 @@ export type JSDocNode = {
24
29
  * ```
25
30
  */
26
31
  export type ConstNode = BaseNode & {
27
- /**
28
- * Node kind.
29
- */
30
32
  kind: 'Const'
31
33
  /**
32
34
  * Name of the constant declaration.
@@ -34,26 +36,26 @@ export type ConstNode = BaseNode & {
34
36
  name: string
35
37
  /**
36
38
  * Whether the declaration should be exported.
37
- * @default false
38
39
  */
39
- export?: boolean
40
+ export?: boolean | null
40
41
  /**
41
- * Optional explicit type annotation.
42
- * @example 'Pet'
42
+ * Explicit type annotation.
43
+ *
44
+ * @example Type reference
45
+ * `'Pet'`
43
46
  */
44
- type?: string
47
+ type?: string | null
45
48
  /**
46
49
  * JSDoc documentation metadata.
47
50
  */
48
- JSDoc?: JSDocNode
51
+ JSDoc?: JSDocNode | null
49
52
  /**
50
53
  * Whether to append `as const` to the declaration.
51
- * @default false
52
54
  */
53
- asConst?: boolean
55
+ asConst?: boolean | null
54
56
  /**
55
57
  * Child nodes representing the value of the constant (children of the `Const` component).
56
- * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
58
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
57
59
  */
58
60
  nodes?: Array<CodeNode>
59
61
  }
@@ -71,9 +73,6 @@ export type ConstNode = BaseNode & {
71
73
  * ```
72
74
  */
73
75
  export type TypeNode = BaseNode & {
74
- /**
75
- * Node kind.
76
- */
77
76
  kind: 'Type'
78
77
  /**
79
78
  * Name of the type alias.
@@ -81,26 +80,19 @@ export type TypeNode = BaseNode & {
81
80
  name: string
82
81
  /**
83
82
  * Whether the declaration should be exported.
84
- * @default false
85
83
  */
86
- export?: boolean
84
+ export?: boolean | null
87
85
  /**
88
86
  * JSDoc documentation metadata.
89
87
  */
90
- JSDoc?: JSDocNode
88
+ JSDoc?: JSDocNode | null
91
89
  /**
92
90
  * Child nodes representing the type body (children of the `Type` component).
93
- * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
91
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
94
92
  */
95
93
  nodes?: Array<CodeNode>
96
94
  }
97
95
 
98
- /**
99
- * Convenience alias for {@link TypeNode}.
100
- * @deprecated Use `TypeNode` directly.
101
- */
102
- export type TypeDeclarationNode = TypeNode
103
-
104
96
  /**
105
97
  * AST node representing a TypeScript `function` declaration.
106
98
  *
@@ -114,9 +106,6 @@ export type TypeDeclarationNode = TypeNode
114
106
  * ```
115
107
  */
116
108
  export type FunctionNode = BaseNode & {
117
- /**
118
- * Node kind.
119
- */
120
109
  kind: 'Function'
121
110
  /**
122
111
  * Name of the function.
@@ -124,40 +113,41 @@ export type FunctionNode = BaseNode & {
124
113
  name: string
125
114
  /**
126
115
  * Whether the function is a default export.
127
- * @default false
128
116
  */
129
- default?: boolean
117
+ default?: boolean | null
130
118
  /**
131
119
  * Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).
132
120
  */
133
- params?: string
121
+ params?: string | null
134
122
  /**
135
123
  * Whether the function should be exported.
136
- * @default false
137
124
  */
138
- export?: boolean
125
+ export?: boolean | null
139
126
  /**
140
127
  * Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
141
- * @default false
142
128
  */
143
- async?: boolean
129
+ async?: boolean | null
144
130
  /**
145
131
  * TypeScript generic type parameters.
146
- * @example ['T', 'U extends string']
132
+ *
133
+ * @example Constrained generics
134
+ * `['T', 'U extends string']`
147
135
  */
148
- generics?: string | string[]
136
+ generics?: string | Array<string> | null
149
137
  /**
150
138
  * Return type annotation.
151
- * @example 'Pet'
139
+ *
140
+ * @example Type reference
141
+ * `'Pet'`
152
142
  */
153
- returnType?: string
143
+ returnType?: string | null
154
144
  /**
155
145
  * JSDoc documentation metadata.
156
146
  */
157
- JSDoc?: JSDocNode
147
+ JSDoc?: JSDocNode | null
158
148
  /**
159
149
  * Child nodes representing the function body (children of the `Function` component).
160
- * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
150
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
161
151
  */
162
152
  nodes?: Array<CodeNode>
163
153
  }
@@ -175,9 +165,6 @@ export type FunctionNode = BaseNode & {
175
165
  * ```
176
166
  */
177
167
  export type ArrowFunctionNode = BaseNode & {
178
- /**
179
- * Node kind.
180
- */
181
168
  kind: 'ArrowFunction'
182
169
  /**
183
170
  * Name of the arrow function (used as the `const` variable name).
@@ -185,45 +172,45 @@ export type ArrowFunctionNode = BaseNode & {
185
172
  name: string
186
173
  /**
187
174
  * Whether the function is a default export.
188
- * @default false
189
175
  */
190
- default?: boolean
176
+ default?: boolean | null
191
177
  /**
192
178
  * Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).
193
179
  */
194
- params?: string
180
+ params?: string | null
195
181
  /**
196
182
  * Whether the arrow function should be exported.
197
- * @default false
198
183
  */
199
- export?: boolean
184
+ export?: boolean | null
200
185
  /**
201
186
  * Whether the arrow function is async. When `true`, the return type is wrapped in `Promise<>`.
202
- * @default false
203
187
  */
204
- async?: boolean
188
+ async?: boolean | null
205
189
  /**
206
190
  * TypeScript generic type parameters.
207
- * @example ['T', 'U extends string']
191
+ *
192
+ * @example Constrained generics
193
+ * `['T', 'U extends string']`
208
194
  */
209
- generics?: string | string[]
195
+ generics?: string | Array<string> | null
210
196
  /**
211
197
  * Return type annotation.
212
- * @example 'Pet'
198
+ *
199
+ * @example Type reference
200
+ * `'Pet'`
213
201
  */
214
- returnType?: string
202
+ returnType?: string | null
215
203
  /**
216
204
  * JSDoc documentation metadata.
217
205
  */
218
- JSDoc?: JSDocNode
206
+ JSDoc?: JSDocNode | null
219
207
  /**
220
208
  * Render the arrow function body as a single-line expression.
221
- * @default false
222
209
  */
223
- singleLine?: boolean
210
+ singleLine?: boolean | null
224
211
  /**
225
212
  * Child nodes representing the function body (children of the `Function.Arrow` component).
226
- * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
213
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
227
214
  */
228
215
  nodes?: Array<CodeNode>
229
216
  }
@@ -241,9 +228,6 @@ export type ArrowFunctionNode = BaseNode & {
241
228
  * ```
242
229
  */
243
230
  export type TextNode = BaseNode & {
244
- /**
245
- * Node kind.
246
- */
247
231
  kind: 'Text'
248
232
  /**
249
233
  * The raw string content.
@@ -254,9 +238,8 @@ export type TextNode = BaseNode & {
254
238
  /**
255
239
  * AST node representing a line break in the source output.
256
240
  *
257
- * Corresponds to `<br/>` in JSX components. When printed, produces an empty
258
- * string that joined with `\n` by `printNodes` creates a blank line
259
- * 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.
260
243
  *
261
244
  * @example
262
245
  * ```ts
@@ -266,17 +249,14 @@ export type TextNode = BaseNode & {
266
249
  * ```
267
250
  */
268
251
  export type BreakNode = BaseNode & {
269
- /**
270
- * Node kind.
271
- */
272
252
  kind: 'Break'
273
253
  }
274
254
 
275
255
  /**
276
256
  * AST node representing a raw JSX fragment in the source output.
277
257
  *
278
- * Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Use this to embed raw
279
- * JSX/TSX markup (including fragments `<>…</>`) directly in generated code.
258
+ * Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup
259
+ * (including fragments `<>…</>`) directly in generated code.
280
260
  *
281
261
  * @example
282
262
  * ```ts
@@ -285,9 +265,6 @@ export type BreakNode = BaseNode & {
285
265
  * ```
286
266
  */
287
267
  export type JsxNode = BaseNode & {
288
- /**
289
- * Node kind.
290
- */
291
268
  kind: 'Jsx'
292
269
  /**
293
270
  * The raw JSX string content.
@@ -302,3 +279,117 @@ export type JsxNode = BaseNode & {
302
279
  * structured children in {@link SourceNode.nodes}.
303
280
  */
304
281
  export type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode
282
+
283
+ /**
284
+ * Definition for the {@link ConstNode}.
285
+ */
286
+ export const constDef = defineNode<ConstNode>({ kind: 'Const' })
287
+
288
+ /**
289
+ * Creates a `ConstNode` representing a TypeScript `const` declaration.
290
+ *
291
+ * @example Exported constant with type and `as const`
292
+ * ```ts
293
+ * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
294
+ * // export const pets: Pet[] = ... as const
295
+ * ```
296
+ */
297
+ export const createConst = constDef.create
298
+
299
+ /**
300
+ * Definition for the {@link TypeNode}.
301
+ */
302
+ export const typeDef = defineNode<TypeNode>({ kind: 'Type' })
303
+
304
+ /**
305
+ * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
306
+ *
307
+ * @example
308
+ * ```ts
309
+ * createType({ name: 'Pet', export: true })
310
+ * // export type Pet = ...
311
+ * ```
312
+ */
313
+ export const createType = typeDef.create
314
+
315
+ /**
316
+ * Definition for the {@link FunctionNode}.
317
+ */
318
+ export const functionDef = defineNode<FunctionNode>({ kind: 'Function' })
319
+
320
+ /**
321
+ * Creates a `FunctionNode` representing a TypeScript `function` declaration.
322
+ *
323
+ * @example
324
+ * ```ts
325
+ * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
326
+ * // export async function fetchPet(): Promise<Pet> { ... }
327
+ * ```
328
+ */
329
+ export const createFunction = functionDef.create
330
+
331
+ /**
332
+ * Definition for the {@link ArrowFunctionNode}.
333
+ */
334
+ export const arrowFunctionDef = defineNode<ArrowFunctionNode>({ kind: 'ArrowFunction' })
335
+
336
+ /**
337
+ * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
342
+ * // export const double = (n: number) => ...
343
+ * ```
344
+ */
345
+ export const createArrowFunction = arrowFunctionDef.create
346
+
347
+ /**
348
+ * Definition for the {@link TextNode}.
349
+ */
350
+ export const textDef = defineNode<TextNode, string>({ kind: 'Text', build: (value) => ({ value }) })
351
+
352
+ /**
353
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
354
+ *
355
+ * @example
356
+ * ```ts
357
+ * createText('return fetch(id)')
358
+ * // { kind: 'Text', value: 'return fetch(id)' }
359
+ * ```
360
+ */
361
+ export const createText = textDef.create
362
+
363
+ /**
364
+ * Definition for the {@link BreakNode}.
365
+ */
366
+ export const breakDef = defineNode<BreakNode, void>({ kind: 'Break', build: () => ({}) })
367
+
368
+ /**
369
+ * Creates a {@link BreakNode} representing a line break in the source output.
370
+ *
371
+ * @example
372
+ * ```ts
373
+ * createBreak()
374
+ * // { kind: 'Break' }
375
+ * ```
376
+ */
377
+ export function createBreak(): BreakNode {
378
+ return breakDef.create()
379
+ }
380
+
381
+ /**
382
+ * Definition for the {@link JsxNode}.
383
+ */
384
+ export const jsxDef = defineNode<JsxNode, string>({ kind: 'Jsx', build: (value) => ({ value }) })
385
+
386
+ /**
387
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
388
+ *
389
+ * @example
390
+ * ```ts
391
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
392
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
393
+ * ```
394
+ */
395
+ export const createJsx = jsxDef.create
@@ -0,0 +1,56 @@
1
+ import { defineNode } from '../node.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
+ * Loosely-typed content entry accepted by the builders, normalized into a {@link ContentNode}.
42
+ */
43
+ export type UserContent = Omit<ContentNode, 'kind'>
44
+
45
+ /**
46
+ * Definition for the {@link ContentNode}.
47
+ */
48
+ export const contentDef = defineNode<ContentNode, UserContent>({
49
+ kind: 'Content',
50
+ children: ['schema'],
51
+ })
52
+
53
+ /**
54
+ * Creates a `ContentNode` for a single request-body or response content type.
55
+ */
56
+ export const createContent = contentDef.create
package/src/nodes/file.ts CHANGED
@@ -1,10 +1,11 @@
1
+ import { defineNode } from '../node.ts'
1
2
  import type { BaseNode } from './base.ts'
2
3
  import type { CodeNode } from './code.ts'
3
4
 
4
5
  /**
5
6
  * Supported file extensions.
6
7
  */
7
- export type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`
8
+ type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`
8
9
 
9
10
  type ImportName = string | Array<string | { propertyName: string; name?: string }>
10
11
 
@@ -35,33 +36,37 @@ export type ImportNode = BaseNode & {
35
36
  kind: 'Import'
36
37
  /**
37
38
  * Import name(s) to be used.
38
- * @example ['useState']
39
- * @example 'React'
39
+ *
40
+ * @example Named imports
41
+ * `['useState']`
42
+ *
43
+ * @example Default import
44
+ * `'React'`
40
45
  */
41
46
  name: ImportName
42
47
  /**
43
48
  * Path for the import.
44
- * @example '@kubb/core'
49
+ *
50
+ * @example
51
+ * `'@kubb/core'`
45
52
  */
46
53
  path: string
47
54
  /**
48
- * Add type-only import prefix.
55
+ * Add a type-only import prefix.
49
56
  * - `true` generates `import type { Type } from './path'`
50
57
  * - `false` generates `import { Type } from './path'`
51
- * @default false
52
58
  */
53
- isTypeOnly?: boolean
59
+ isTypeOnly?: boolean | null
54
60
  /**
55
- * Import entire module as namespace.
61
+ * Import the entire module as a namespace.
56
62
  * - `true` generates `import * as Name from './path'`
57
- * - `false` generates standard import
58
- * @default false
63
+ * - `false` generates a standard import
59
64
  */
60
- isNameSpace?: boolean
65
+ isNameSpace?: boolean | null
61
66
  /**
62
67
  * When set, the import path is resolved relative to this root.
63
68
  */
64
- root?: string
69
+ root?: string | null
65
70
  }
66
71
 
67
72
  /**
@@ -91,29 +96,33 @@ export type ExportNode = BaseNode & {
91
96
  kind: 'Export'
92
97
  /**
93
98
  * Export name(s) to be used. When omitted, generates a wildcard export.
94
- * @example ['useState']
95
- * @example 'React'
99
+ *
100
+ * @example Named exports
101
+ * `['useState']`
102
+ *
103
+ * @example Single export
104
+ * `'React'`
96
105
  */
97
- name?: string | Array<string>
106
+ name?: string | Array<string> | null
98
107
  /**
99
108
  * Path for the export.
100
- * @example '@kubb/core'
109
+ *
110
+ * @example
111
+ * `'@kubb/core'`
101
112
  */
102
113
  path: string
103
114
  /**
104
- * Add type-only export prefix.
115
+ * Add a type-only export prefix.
105
116
  * - `true` generates `export type { Type } from './path'`
106
117
  * - `false` generates `export { Type } from './path'`
107
- * @default false
108
118
  */
109
- isTypeOnly?: boolean
119
+ isTypeOnly?: boolean | null
110
120
  /**
111
121
  * Export as an aliased namespace.
112
122
  * - `true` generates `export * as aliasName from './path'`
113
123
  * - `false` generates a standard export
114
- * @default false
115
124
  */
116
- asAlias?: boolean
125
+ asAlias?: boolean | null
117
126
  }
118
127
 
119
128
  /**
@@ -134,25 +143,22 @@ export type SourceNode = BaseNode & {
134
143
  /**
135
144
  * Optional name identifying this source (used for deduplication and barrel generation).
136
145
  */
137
- name?: string
146
+ name?: string | null
138
147
  /**
139
148
  * Mark this source as a type-only export.
140
- * @default false
141
149
  */
142
- isTypeOnly?: boolean
150
+ isTypeOnly?: boolean | null
143
151
  /**
144
- * Include `export` keyword in the generated source.
145
- * @default false
152
+ * Include the `export` keyword in the generated source.
146
153
  */
147
- isExportable?: boolean
154
+ isExportable?: boolean | null
148
155
  /**
149
156
  * Include this source in barrel/index file generation.
150
- * @default false
151
157
  */
152
- isIndexable?: boolean
158
+ isIndexable?: boolean | null
153
159
  /**
154
- * Structured child nodes representing the content of this source fragment, in DOM order.
155
- * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
160
+ * Child nodes that make up this source fragment, in DOM order.
161
+ * Use a {@link TextNode} for raw string content.
156
162
  */
157
163
  nodes?: Array<CodeNode>
158
164
  }
@@ -180,8 +186,8 @@ export type SourceNode = BaseNode & {
180
186
  export type FileNode<TMeta extends object = object> = BaseNode & {
181
187
  kind: 'File'
182
188
  /**
183
- * Unique identifier derived from a SHA256 hash of the file path.
184
- * @default hash
189
+ * Unique identifier derived from a SHA256 hash of the file path. `createFile`
190
+ * computes it, so callers do not need to provide it.
185
191
  */
186
192
  id: string
187
193
  /**
@@ -216,15 +222,70 @@ export type FileNode<TMeta extends object = object> = BaseNode & {
216
222
  */
217
223
  exports: Array<ExportNode>
218
224
  /**
219
- * Optional metadata attached to this file (used by plugins for barrel generation etc.).
225
+ * Optional metadata attached to this file, read by plugins during barrel generation.
220
226
  */
221
227
  meta?: TMeta
222
228
  /**
223
229
  * Optional banner prepended to the generated file content.
230
+ * Accepts `null` so `resolver.resolveBanner()` results can be passed directly.
224
231
  */
225
- banner?: string
232
+ banner?: string | null
226
233
  /**
227
234
  * Optional footer appended to the generated file content.
235
+ * Accepts `null` so `resolver.resolveFooter()` results can be passed directly.
228
236
  */
229
- footer?: string
237
+ footer?: string | null
230
238
  }
239
+
240
+ /**
241
+ * Definition for the {@link ImportNode}.
242
+ */
243
+ export const importDef = defineNode<ImportNode>({ kind: 'Import' })
244
+
245
+ /**
246
+ * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
247
+ *
248
+ * @example Named import
249
+ * ```ts
250
+ * createImport({ name: ['useState'], path: 'react' })
251
+ * // import { useState } from 'react'
252
+ * ```
253
+ */
254
+ export const createImport = importDef.create
255
+
256
+ /**
257
+ * Definition for the {@link ExportNode}.
258
+ */
259
+ export const exportDef = defineNode<ExportNode>({ kind: 'Export' })
260
+
261
+ /**
262
+ * Creates an `ExportNode` representing a language-agnostic export/public API declaration.
263
+ *
264
+ * @example Named export
265
+ * ```ts
266
+ * createExport({ name: ['Pet'], path: './Pet' })
267
+ * // export { Pet } from './Pet'
268
+ * ```
269
+ */
270
+ export const createExport = exportDef.create
271
+
272
+ /**
273
+ * Definition for the {@link SourceNode}.
274
+ */
275
+ export const sourceDef = defineNode<SourceNode>({ kind: 'Source' })
276
+
277
+ /**
278
+ * Creates a `SourceNode` representing a fragment of source code within a file.
279
+ *
280
+ * @example
281
+ * ```ts
282
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
283
+ * ```
284
+ */
285
+ export const createSource = sourceDef.create
286
+
287
+ /**
288
+ * Definition for the {@link FileNode}. The fully resolved builder lives in
289
+ * `createFile`, so this definition only supplies the guard.
290
+ */
291
+ export const fileDef = defineNode<FileNode>({ kind: 'File' })