@kubb/ast 5.0.0-alpha.32 → 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/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as StatusCode, At as FunctionParametersNode, Bt as FunctionNode, Ct as TimeSchemaNode, Dt as FunctionNodeType, Et as PropertyNode, Ft as ImportNode, G as InputMeta, Gt as NodeKind, H as InferSchemaNode, Ht as TypeDeclarationNode, It as SourceNode, J as HttpMethod, K as InputNode, Lt as ArrowFunctionNode, Mt as ParamsTypeNode, Nt as ExportNode, Ot as FunctionParamNode, Pt as FileNode, Q as MediaType, Rt as CodeNode, St as StringSchemaNode, Tt as UrlSchemaNode, U as ParserOptions, Ut as TypeNode, V as InferSchema, Vt as JSDocNode, W as Node, Wt as BaseNode, X as ResponseNode, Y as OperationNode, Z as HttpStatusCode, _ as PrinterPartial, _t as ScalarSchemaType, a as TransformOptions, at as DatetimeSchemaNode, b as DistributiveOmit, bt as SchemaType, c as WalkOptions, ct as FormatStringSchemaNode, dt as Ipv6SchemaNode, et as ParameterLocation, ft as NumberSchemaNode, g as PrinterFactoryOptions, gt as ScalarSchemaNode, h as Printer, ht as RefSchemaNode, i as ParentOf, it as DateSchemaNode, jt as ParameterGroupNode, kt as FunctionParameterNode, lt as IntersectionSchemaNode, mt as PrimitiveSchemaType, n as CollectOptions, nt as ArraySchemaNode, o as Visitor, ot as EnumSchemaNode, p as RefMap, pt as ObjectSchemaNode, q as OutputNode, qt as VisitorDepth, r as CollectVisitor, rt as ComplexSchemaType, s as VisitorContext, st as EnumValueNode, t as AsyncVisitor, tt as ParameterNode, ut as Ipv4SchemaNode, vt as SchemaNode, wt as UnionSchemaNode, xt as SpecialSchemaType, yt as SchemaNodeByType, zt as ConstNode } from "./visitor-DysNCWvh.js";
2
- export { type ArraySchemaNode, type ArrowFunctionNode, type AsyncVisitor, type BaseNode, type CodeNode, type CollectOptions, type CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpStatusCode, type ImportNode, type InferSchema, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type MediaType, type Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefMap, type RefSchemaNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TimeSchemaNode, type TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type Visitor, type VisitorContext, type VisitorDepth, type WalkOptions };
1
+ import { $ as ResponseNode, $t as VisitorDepth, At as FunctionNodeType, Bt as ArrowFunctionNode, Ct as SchemaType, Dt as UnionSchemaNode, Et as TimeSchemaNode, Ft as ParamsTypeNode, G as InferSchemaNode, Gt as JSDocNode, Ht as CodeNode, It as ExportNode, J as InputMeta, Jt as TypeDeclarationNode, K as ParserOptions, Kt as JsxNode, Lt as FileNode, Mt as FunctionParameterNode, Nt as FunctionParametersNode, Ot as UrlSchemaNode, Pt as ParameterGroupNode, Q as OperationNode, Rt as ImportNode, St as SchemaNodeByType, Tt as StringSchemaNode, Ut as ConstNode, Vt as BreakNode, W as InferSchema, Wt as FunctionNode, X as OutputNode, Xt as BaseNode, Y as InputNode, Yt as TypeNode, Z as HttpMethod, Zt as NodeKind, _ as PrinterPartial, _t as PrimitiveSchemaType, a as TransformOptions, at as ArraySchemaNode, b as DistributiveOmit, bt as ScalarSchemaType, c as WalkOptions, ct as DatetimeSchemaNode, dt as FormatStringSchemaNode, et as HttpStatusCode, ft as IntersectionSchemaNode, g as PrinterFactoryOptions, gt as ObjectSchemaNode, h as Printer, ht as NumberSchemaNode, i as ParentOf, it as ParameterNode, jt as FunctionParamNode, kt as PropertyNode, lt as EnumSchemaNode, mt as Ipv6SchemaNode, n as CollectOptions, nt as StatusCode, o as Visitor, ot as ComplexSchemaType, p as RefMap, pt as Ipv4SchemaNode, q as Node, qt as TextNode, r as CollectVisitor, rt as ParameterLocation, s as VisitorContext, st as DateSchemaNode, t as AsyncVisitor, tt as MediaType, ut as EnumValueNode, vt as RefSchemaNode, wt as SpecialSchemaType, xt as SchemaNode, yt as ScalarSchemaNode, zt as SourceNode } from "./visitor-CJMIoAE3.js";
2
+ export { type ArraySchemaNode, type ArrowFunctionNode, type AsyncVisitor, type BaseNode, type BreakNode, type CodeNode, type CollectOptions, type CollectVisitor, type ComplexSchemaType, type ConstNode, type DateSchemaNode, type DatetimeSchemaNode, type DistributiveOmit, type EnumSchemaNode, type EnumValueNode, type ExportNode, type FileNode, type FormatStringSchemaNode, type FunctionNode, type FunctionNodeType, type FunctionParamNode, type FunctionParameterNode, type FunctionParametersNode, type HttpMethod, type HttpStatusCode, type ImportNode, type InferSchema, type InferSchemaNode, type InputMeta, type InputNode, type IntersectionSchemaNode, type Ipv4SchemaNode, type Ipv6SchemaNode, type JSDocNode, type JsxNode, type MediaType, type Node, type NodeKind, type NumberSchemaNode, type ObjectSchemaNode, type OperationNode, type OutputNode, type ParameterGroupNode, type ParameterLocation, type ParameterNode, type ParamsTypeNode, type ParentOf, type ParserOptions, type PrimitiveSchemaType, type Printer, type PrinterFactoryOptions, type PrinterPartial, type PropertyNode, type RefMap, type RefSchemaNode, type ResponseNode, type ScalarSchemaNode, type ScalarSchemaType, type SchemaNode, type SchemaNodeByType, type SchemaType, type SourceNode, type SpecialSchemaType, type StatusCode, type StringSchemaNode, type TextNode, type TimeSchemaNode, type TransformOptions, type TypeDeclarationNode, type TypeNode, type UnionSchemaNode, type UrlSchemaNode, type Visitor, type VisitorContext, type VisitorDepth, type WalkOptions };
@@ -21,6 +21,8 @@ declare const nodeKinds: {
21
21
  readonly import: "Import";
22
22
  readonly export: "Export";
23
23
  readonly source: "Source";
24
+ readonly text: "Text";
25
+ readonly break: "Break";
24
26
  };
25
27
  /**
26
28
  * Canonical schema type strings used by AST schema nodes.
@@ -185,7 +187,7 @@ declare const mediaTypes: {
185
187
  * const kind: NodeKind = 'Schema'
186
188
  * ```
187
189
  */
188
- type NodeKind = 'Input' | 'Output' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'FunctionParameter' | 'ParameterGroup' | 'FunctionParameters' | 'Type' | 'ParamsType' | 'File' | 'Import' | 'Export' | 'Source' | 'Const' | 'Function' | 'ArrowFunction';
190
+ type NodeKind = 'Input' | 'Output' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'FunctionParameter' | 'ParameterGroup' | 'FunctionParameters' | 'Type' | 'ParamsType' | 'File' | 'Import' | 'Export' | 'Source' | 'Const' | 'Function' | 'ArrowFunction' | 'Text' | 'Break' | 'Jsx';
189
191
  /**
190
192
  * Base shape shared by all AST nodes.
191
193
  *
@@ -215,7 +217,7 @@ type JSDocNode = {
215
217
  /**
216
218
  * AST node representing a TypeScript `const` declaration.
217
219
  *
218
- * Mirrors the props of the `Const` component from `@kubb/react-fabric`.
220
+ * Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.
219
221
  * The `children` prop of the component is represented as `nodes`.
220
222
  *
221
223
  * @example
@@ -254,14 +256,14 @@ type ConstNode = BaseNode & {
254
256
  asConst?: boolean;
255
257
  /**
256
258
  * Child nodes representing the value of the constant (children of the `Const` component).
257
- * Each entry is either a structured {@link CodeNode} or a raw string expression.
259
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
258
260
  */
259
- nodes?: Array<CodeNode | string>;
261
+ nodes?: Array<CodeNode>;
260
262
  };
261
263
  /**
262
264
  * AST node representing a TypeScript `type` alias declaration.
263
265
  *
264
- * Mirrors the props of the `Type` component from `@kubb/react-fabric`.
266
+ * Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.
265
267
  * The `children` prop of the component is represented as `nodes`.
266
268
  *
267
269
  * @example
@@ -290,9 +292,9 @@ type TypeNode = BaseNode & {
290
292
  JSDoc?: JSDocNode;
291
293
  /**
292
294
  * Child nodes representing the type body (children of the `Type` component).
293
- * Each entry is either a structured {@link CodeNode} or a raw string expression.
295
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
294
296
  */
295
- nodes?: Array<CodeNode | string>;
297
+ nodes?: Array<CodeNode>;
296
298
  };
297
299
  /**
298
300
  * Convenience alias for {@link TypeNode}.
@@ -302,7 +304,7 @@ type TypeDeclarationNode = TypeNode;
302
304
  /**
303
305
  * AST node representing a TypeScript `function` declaration.
304
306
  *
305
- * Mirrors the props of the `Function` component from `@kubb/react-fabric`.
307
+ * Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.
306
308
  * The `children` prop of the component is represented as `nodes`.
307
309
  *
308
310
  * @example
@@ -355,14 +357,14 @@ type FunctionNode = BaseNode & {
355
357
  JSDoc?: JSDocNode;
356
358
  /**
357
359
  * Child nodes representing the function body (children of the `Function` component).
358
- * Each entry is either a structured {@link CodeNode} or a raw string statement.
360
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
359
361
  */
360
- nodes?: Array<CodeNode | string>;
362
+ nodes?: Array<CodeNode>;
361
363
  };
362
364
  /**
363
365
  * AST node representing a TypeScript arrow function (`const name = () => { ... }`).
364
366
  *
365
- * Mirrors the props of the `Function.Arrow` component from `@kubb/react-fabric`.
367
+ * Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.
366
368
  * The `children` prop of the component is represented as `nodes`.
367
369
  *
368
370
  * @example
@@ -420,17 +422,81 @@ type ArrowFunctionNode = BaseNode & {
420
422
  singleLine?: boolean;
421
423
  /**
422
424
  * Child nodes representing the function body (children of the `Function.Arrow` component).
423
- * Each entry is either a structured {@link CodeNode} or a raw string statement.
425
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
426
+ */
427
+ nodes?: Array<CodeNode>;
428
+ };
429
+ /**
430
+ * AST node representing a raw text/string fragment in the source output.
431
+ *
432
+ * Used instead of bare `string` values so that all entries in `nodes` arrays
433
+ * are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.
434
+ *
435
+ * @example
436
+ * ```ts
437
+ * createText('return fetch(id)')
438
+ * // { kind: 'Text', value: 'return fetch(id)' }
439
+ * ```
440
+ */
441
+ type TextNode = BaseNode & {
442
+ /**
443
+ * Node kind.
444
+ */
445
+ kind: 'Text';
446
+ /**
447
+ * The raw string content.
448
+ */
449
+ value: string;
450
+ };
451
+ /**
452
+ * AST node representing a line break in the source output.
453
+ *
454
+ * Corresponds to `<br/>` in JSX components. When printed, produces an empty
455
+ * string that — joined with `\n` by `printNodes` — creates a blank line
456
+ * between surrounding code nodes.
457
+ *
458
+ * @example
459
+ * ```ts
460
+ * createBreak()
461
+ * // { kind: 'Break' }
462
+ * // prints as '' → blank line when surrounded by other nodes
463
+ * ```
464
+ */
465
+ type BreakNode = BaseNode & {
466
+ /**
467
+ * Node kind.
468
+ */
469
+ kind: 'Break';
470
+ };
471
+ /**
472
+ * AST node representing a raw JSX fragment in the source output.
473
+ *
474
+ * Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Use this to embed raw
475
+ * JSX/TSX markup (including fragments `<>…</>`) directly in generated code.
476
+ *
477
+ * @example
478
+ * ```ts
479
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
480
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
481
+ * ```
482
+ */
483
+ type JsxNode = BaseNode & {
484
+ /**
485
+ * Node kind.
486
+ */
487
+ kind: 'Jsx';
488
+ /**
489
+ * The raw JSX string content.
424
490
  */
425
- nodes?: Array<CodeNode | string>;
491
+ value: string;
426
492
  };
427
493
  /**
428
494
  * Union of all code-generation AST nodes.
429
495
  *
430
- * These nodes mirror the JSX components from `@kubb/react-fabric` and are used as
496
+ * These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as
431
497
  * structured children in {@link SourceNode.nodes}.
432
498
  */
433
- type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode;
499
+ type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
434
500
  //#endregion
435
501
  //#region src/nodes/file.d.ts
436
502
  /**
@@ -552,12 +618,12 @@ type ExportNode = BaseNode & {
552
618
  *
553
619
  * @example Named exportable source
554
620
  * ```ts
555
- * createSource({ name: 'Pet', value: 'export type Pet = { id: number }', isExportable: true, isIndexable: true })
621
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })
556
622
  * ```
557
623
  *
558
624
  * @example Inline unnamed code block
559
625
  * ```ts
560
- * createSource({ value: 'const x = 1' })
626
+ * createSource({ nodes: [createText('const x = 1')] })
561
627
  * ```
562
628
  */
563
629
  type SourceNode = BaseNode & {
@@ -566,10 +632,6 @@ type SourceNode = BaseNode & {
566
632
  * Optional name identifying this source (used for deduplication and barrel generation).
567
633
  */
568
634
  name?: string;
569
- /**
570
- * The source code value.
571
- */
572
- value?: string;
573
635
  /**
574
636
  * Mark this source as a type-only export.
575
637
  * @default false
@@ -586,9 +648,8 @@ type SourceNode = BaseNode & {
586
648
  */
587
649
  isIndexable?: boolean;
588
650
  /**
589
- * Structured child nodes representing the content of this source fragment.
590
- * These correspond to the children of the `File.Source` component from `@kubb/react-fabric`
591
- * (e.g. `ConstNode`, `TypeDeclarationNode`, `FunctionDeclarationNode`, `ArrowFunctionDeclarationNode`).
651
+ * Structured child nodes representing the content of this source fragment, in DOM order.
652
+ * Each entry is a {@link CodeNode}; use {@link TextNode} for raw string content.
592
653
  */
593
654
  nodes?: Array<CodeNode>;
594
655
  };
@@ -603,7 +664,7 @@ type SourceNode = BaseNode & {
603
664
  * const file = createFile({
604
665
  * baseName: 'petStore.ts',
605
666
  * path: 'src/models/petStore.ts',
606
- * sources: [createSource({ name: 'Pet', value: 'export type Pet = { id: number }', isExportable: true })],
667
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })],
607
668
  * imports: [createImport({ name: ['z'], path: 'zod' })],
608
669
  * exports: [createExport({ name: ['Pet'], path: './petStore' })],
609
670
  * })
@@ -2294,7 +2355,7 @@ declare function createExport(props: Omit<ExportNode, 'kind'>): ExportNode;
2294
2355
  *
2295
2356
  * @example
2296
2357
  * ```ts
2297
- * createSource({ name: 'Pet', value: 'export type Pet = { id: number }', isExportable: true })
2358
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
2298
2359
  * ```
2299
2360
  */
2300
2361
  declare function createSource(props: Omit<SourceNode, 'kind'>): SourceNode;
@@ -2319,7 +2380,7 @@ type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind'
2319
2380
  * const file = createFile({
2320
2381
  * baseName: 'petStore.ts',
2321
2382
  * path: 'src/models/petStore.ts',
2322
- * sources: [createSource({ name: 'Pet', value: 'export type Pet = { id: number }' })],
2383
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
2323
2384
  * imports: [createImport({ name: ['z'], path: 'zod' })],
2324
2385
  * exports: [createExport({ name: ['Pet'], path: './petStore' })],
2325
2386
  * })
@@ -2332,7 +2393,7 @@ declare function createFile<TMeta extends object = object>(input: UserFileNode<T
2332
2393
  /**
2333
2394
  * Creates a `ConstNode` representing a TypeScript `const` declaration.
2334
2395
  *
2335
- * Mirrors the `Const` component from `@kubb/react-fabric`.
2396
+ * Mirrors the `Const` component from `@kubb/renderer-jsx`.
2336
2397
  * The component's `children` are represented as `nodes`.
2337
2398
  *
2338
2399
  * @example Simple constant
@@ -2361,7 +2422,7 @@ declare function createConst(props: Omit<ConstNode, 'kind'>): ConstNode;
2361
2422
  /**
2362
2423
  * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
2363
2424
  *
2364
- * Mirrors the `Type` component from `@kubb/react-fabric`.
2425
+ * Mirrors the `Type` component from `@kubb/renderer-jsx`.
2365
2426
  * The component's `children` are represented as `nodes`.
2366
2427
  *
2367
2428
  * @example Simple type alias
@@ -2384,7 +2445,7 @@ declare function createType(props: Omit<TypeNode, 'kind'>): TypeNode;
2384
2445
  /**
2385
2446
  * Creates a `FunctionNode` representing a TypeScript `function` declaration.
2386
2447
  *
2387
- * Mirrors the `Function` component from `@kubb/react-fabric`.
2448
+ * Mirrors the `Function` component from `@kubb/renderer-jsx`.
2388
2449
  * The component's `children` are represented as `nodes`.
2389
2450
  *
2390
2451
  * @example Simple function
@@ -2415,7 +2476,7 @@ declare function createFunction(props: Omit<FunctionNode, 'kind'>): FunctionNode
2415
2476
  /**
2416
2477
  * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
2417
2478
  *
2418
- * Mirrors the `Function.Arrow` component from `@kubb/react-fabric`.
2479
+ * Mirrors the `Function.Arrow` component from `@kubb/renderer-jsx`.
2419
2480
  * The component's `children` are represented as `nodes`.
2420
2481
  *
2421
2482
  * @example Simple arrow function
@@ -2444,6 +2505,44 @@ declare function createFunction(props: Omit<FunctionNode, 'kind'>): FunctionNode
2444
2505
  * ```
2445
2506
  */
2446
2507
  declare function createArrowFunction(props: Omit<ArrowFunctionNode, 'kind'>): ArrowFunctionNode;
2508
+ /**
2509
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
2510
+ *
2511
+ * Use this instead of bare strings when building `nodes` arrays so that every
2512
+ * entry in the array is a typed {@link CodeNode}.
2513
+ *
2514
+ * @example
2515
+ * ```ts
2516
+ * createText('return fetch(id)')
2517
+ * // { kind: 'Text', value: 'return fetch(id)' }
2518
+ * ```
2519
+ */
2520
+ declare function createText(value: string): TextNode;
2521
+ /**
2522
+ * Creates a {@link BreakNode} representing a line break in the source output.
2523
+ *
2524
+ * Corresponds to `<br/>` in JSX components. Prints as an empty string which,
2525
+ * when joined with `\n` by `printNodes`, produces a blank line.
2526
+ *
2527
+ * @example
2528
+ * ```ts
2529
+ * createBreak()
2530
+ * // { kind: 'Break' }
2531
+ * ```
2532
+ */
2533
+ declare function createBreak(): BreakNode;
2534
+ /**
2535
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
2536
+ *
2537
+ * Use this to embed JSX markup (including fragments `<>…</>`) directly in generated code.
2538
+ *
2539
+ * @example
2540
+ * ```ts
2541
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
2542
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
2543
+ * ```
2544
+ */
2545
+ declare function createJsx(value: string): JsxNode;
2447
2546
  //#endregion
2448
2547
  //#region src/printer.d.ts
2449
2548
  /**
@@ -2929,5 +3028,5 @@ declare function composeTransformers(...visitors: Array<Visitor>): Visitor;
2929
3028
  */
2930
3029
  declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
2931
3030
  //#endregion
2932
- export { StatusCode as $, createOperation as A, FunctionParametersNode as At, syncOptionality as B, FunctionNode as Bt, createExport as C, TimeSchemaNode as Ct, createFunctionParameters as D, FunctionNodeType as Dt, createFunctionParameter as E, PropertyNode as Et, createProperty as F, ImportNode as Ft, InputMeta as G, NodeKind as Gt, InferSchemaNode as H, TypeDeclarationNode as Ht, createResponse as I, SourceNode as It, HttpMethod as J, httpMethods as Jt, InputNode as K, ScalarPrimitive as Kt, createSchema as L, ArrowFunctionNode as Lt, createParameter as M, ParamsTypeNode as Mt, createParameterGroup as N, ExportNode as Nt, createImport as O, FunctionParamNode as Ot, createParamsType as P, FileNode as Pt, MediaType as Q, schemaTypes as Qt, createSource as R, CodeNode as Rt, createConst as S, StringSchemaNode as St, createFunction as T, UrlSchemaNode as Tt, ParserOptions as U, TypeNode as Ut, InferSchema as V, JSDocNode as Vt, Node as W, BaseNode as Wt, ResponseNode as X, mediaTypes as Xt, OperationNode as Y, isScalarPrimitive as Yt, HttpStatusCode as Z, nodeKinds as Zt, PrinterPartial as _, ScalarSchemaType as _t, TransformOptions as a, DatetimeSchemaNode as at, DistributiveOmit as b, SchemaType as bt, WalkOptions as c, FormatStringSchemaNode as ct, transform as d, Ipv6SchemaNode as dt, ParameterLocation as et, walk as f, NumberSchemaNode as ft, PrinterFactoryOptions as g, ScalarSchemaNode as gt, Printer as h, RefSchemaNode as ht, ParentOf as i, DateSchemaNode as it, createOutput as j, ParameterGroupNode as jt, createInput as k, FunctionParameterNode as kt, collect as l, IntersectionSchemaNode as lt, extractRefName as m, PrimitiveSchemaType as mt, CollectOptions as n, ArraySchemaNode as nt, Visitor as o, EnumSchemaNode as ot, RefMap as p, ObjectSchemaNode as pt, OutputNode as q, VisitorDepth as qt, CollectVisitor as r, ComplexSchemaType as rt, VisitorContext as s, EnumValueNode as st, AsyncVisitor as t, ParameterNode as tt, composeTransformers as u, Ipv4SchemaNode as ut, createPrinterFactory as v, SchemaNode as vt, createFile as w, UnionSchemaNode as wt, createArrowFunction as x, SpecialSchemaType as xt, definePrinter as y, SchemaNodeByType as yt, createType as z, ConstNode as zt };
2933
- //# sourceMappingURL=visitor-DysNCWvh.d.ts.map
3031
+ export { ResponseNode as $, VisitorDepth as $t, createInput as A, FunctionNodeType as At, createSource as B, ArrowFunctionNode as Bt, createConst as C, SchemaType as Ct, createFunctionParameter as D, UnionSchemaNode as Dt, createFunction as E, TimeSchemaNode as Et, createParameterGroup as F, ParamsTypeNode as Ft, InferSchemaNode as G, JSDocNode as Gt, createType as H, CodeNode as Ht, createParamsType as I, ExportNode as It, InputMeta as J, TypeDeclarationNode as Jt, ParserOptions as K, JsxNode as Kt, createProperty as L, FileNode as Lt, createOperation as M, FunctionParameterNode as Mt, createOutput as N, FunctionParametersNode as Nt, createFunctionParameters as O, UrlSchemaNode as Ot, createParameter as P, ParameterGroupNode as Pt, OperationNode as Q, ScalarPrimitive as Qt, createResponse as R, ImportNode as Rt, createBreak as S, SchemaNodeByType as St, createFile as T, StringSchemaNode as Tt, syncOptionality as U, ConstNode as Ut, createText as V, BreakNode as Vt, InferSchema as W, FunctionNode as Wt, OutputNode as X, BaseNode as Xt, InputNode as Y, TypeNode as Yt, HttpMethod as Z, NodeKind as Zt, PrinterPartial as _, PrimitiveSchemaType as _t, TransformOptions as a, ArraySchemaNode as at, DistributiveOmit as b, ScalarSchemaType as bt, WalkOptions as c, DatetimeSchemaNode as ct, transform as d, FormatStringSchemaNode as dt, httpMethods as en, HttpStatusCode as et, walk as f, IntersectionSchemaNode as ft, PrinterFactoryOptions as g, ObjectSchemaNode as gt, Printer as h, NumberSchemaNode as ht, ParentOf as i, schemaTypes as in, ParameterNode as it, createJsx as j, FunctionParamNode as jt, createImport as k, PropertyNode as kt, collect as l, EnumSchemaNode as lt, extractRefName as m, Ipv6SchemaNode as mt, CollectOptions as n, mediaTypes as nn, StatusCode as nt, Visitor as o, ComplexSchemaType as ot, RefMap as p, Ipv4SchemaNode as pt, Node as q, TextNode as qt, CollectVisitor as r, nodeKinds as rn, ParameterLocation as rt, VisitorContext as s, DateSchemaNode as st, AsyncVisitor as t, isScalarPrimitive as tn, MediaType as tt, composeTransformers as u, EnumValueNode as ut, createPrinterFactory as v, RefSchemaNode as vt, createExport as w, SpecialSchemaType as wt, createArrowFunction as x, SchemaNode as xt, definePrinter as y, ScalarSchemaNode as yt, createSchema as z, SourceNode as zt };
3032
+ //# sourceMappingURL=visitor-CJMIoAE3.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/ast",
3
- "version": "5.0.0-alpha.32",
3
+ "version": "5.0.0-alpha.33",
4
4
  "description": "Spec-agnostic AST layer for Kubb. Defines nodes, visitor pattern, and factory functions used across codegen plugins.",
5
5
  "keywords": [
6
6
  "kubb",
package/src/constants.ts CHANGED
@@ -30,6 +30,8 @@ export const nodeKinds = {
30
30
  import: 'Import',
31
31
  export: 'Export',
32
32
  source: 'Source',
33
+ text: 'Text',
34
+ break: 'Break',
33
35
  } as const satisfies Record<string, NodeKind>
34
36
 
35
37
  /**
package/src/factory.ts CHANGED
@@ -4,6 +4,7 @@ import { trimExtName } from '@internals/utils'
4
4
  import type { InferSchemaNode } from './infer.ts'
5
5
  import type {
6
6
  ArrowFunctionNode,
7
+ BreakNode,
7
8
  ConstNode,
8
9
  ExportNode,
9
10
  FileNode,
@@ -12,6 +13,7 @@ import type {
12
13
  FunctionParametersNode,
13
14
  ImportNode,
14
15
  InputNode,
16
+ JsxNode,
15
17
  ObjectSchemaNode,
16
18
  OperationNode,
17
19
  OutputNode,
@@ -23,9 +25,10 @@ import type {
23
25
  ResponseNode,
24
26
  SchemaNode,
25
27
  SourceNode,
28
+ TextNode,
26
29
  TypeNode,
27
30
  } from './nodes/index.ts'
28
- import { combineExports, combineImports, combineSources } from './utils.ts'
31
+ import { combineExports, combineImports, combineSources, extractStringsFromNodes } from './utils.ts'
29
32
 
30
33
  /**
31
34
  * Syncs property/parameter schema optionality flags from `required` and `schema.nullable`.
@@ -477,7 +480,7 @@ export function createExport(props: Omit<ExportNode, 'kind'>): ExportNode {
477
480
  *
478
481
  * @example
479
482
  * ```ts
480
- * createSource({ name: 'Pet', value: 'export type Pet = { id: number }', isExportable: true })
483
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
481
484
  * ```
482
485
  */
483
486
  export function createSource(props: Omit<SourceNode, 'kind'>): SourceNode {
@@ -507,7 +510,7 @@ type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind'
507
510
  * const file = createFile({
508
511
  * baseName: 'petStore.ts',
509
512
  * path: 'src/models/petStore.ts',
510
- * sources: [createSource({ name: 'Pet', value: 'export type Pet = { id: number }' })],
513
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
511
514
  * imports: [createImport({ name: ['z'], path: 'zod' })],
512
515
  * exports: [createExport({ name: ['Pet'], path: './petStore' })],
513
516
  * })
@@ -524,9 +527,13 @@ export function createFile<TMeta extends object = object>(input: UserFileNode<TM
524
527
  throw new Error(`No extname found for ${input.baseName}`)
525
528
  }
526
529
 
527
- const source = (input.sources ?? []).map((item) => item.value).join('\n\n')
530
+ const source = (input.sources ?? [])
531
+ .flatMap((item) => item.nodes ?? [])
532
+ .map((node) => extractStringsFromNodes([node]))
533
+ .filter(Boolean)
534
+ .join('\n\n')
528
535
  const resolvedExports = input.exports?.length ? combineExports(input.exports) : []
529
- const resolvedImports = input.imports?.length && source ? combineImports(input.imports, resolvedExports, source) : []
536
+ const resolvedImports = input.imports?.length ? combineImports(input.imports, resolvedExports, source || undefined) : []
530
537
  const resolvedSources = input.sources?.length ? combineSources(input.sources) : []
531
538
 
532
539
  return {
@@ -545,7 +552,7 @@ export function createFile<TMeta extends object = object>(input: UserFileNode<TM
545
552
  /**
546
553
  * Creates a `ConstNode` representing a TypeScript `const` declaration.
547
554
  *
548
- * Mirrors the `Const` component from `@kubb/react-fabric`.
555
+ * Mirrors the `Const` component from `@kubb/renderer-jsx`.
549
556
  * The component's `children` are represented as `nodes`.
550
557
  *
551
558
  * @example Simple constant
@@ -577,7 +584,7 @@ export function createConst(props: Omit<ConstNode, 'kind'>): ConstNode {
577
584
  /**
578
585
  * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
579
586
  *
580
- * Mirrors the `Type` component from `@kubb/react-fabric`.
587
+ * Mirrors the `Type` component from `@kubb/renderer-jsx`.
581
588
  * The component's `children` are represented as `nodes`.
582
589
  *
583
590
  * @example Simple type alias
@@ -603,7 +610,7 @@ export function createType(props: Omit<TypeNode, 'kind'>): TypeNode {
603
610
  /**
604
611
  * Creates a `FunctionNode` representing a TypeScript `function` declaration.
605
612
  *
606
- * Mirrors the `Function` component from `@kubb/react-fabric`.
613
+ * Mirrors the `Function` component from `@kubb/renderer-jsx`.
607
614
  * The component's `children` are represented as `nodes`.
608
615
  *
609
616
  * @example Simple function
@@ -637,7 +644,7 @@ export function createFunction(props: Omit<FunctionNode, 'kind'>): FunctionNode
637
644
  /**
638
645
  * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
639
646
  *
640
- * Mirrors the `Function.Arrow` component from `@kubb/react-fabric`.
647
+ * Mirrors the `Function.Arrow` component from `@kubb/renderer-jsx`.
641
648
  * The component's `children` are represented as `nodes`.
642
649
  *
643
650
  * @example Simple arrow function
@@ -668,3 +675,50 @@ export function createFunction(props: Omit<FunctionNode, 'kind'>): FunctionNode
668
675
  export function createArrowFunction(props: Omit<ArrowFunctionNode, 'kind'>): ArrowFunctionNode {
669
676
  return { ...props, kind: 'ArrowFunction' }
670
677
  }
678
+
679
+ /**
680
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
681
+ *
682
+ * Use this instead of bare strings when building `nodes` arrays so that every
683
+ * entry in the array is a typed {@link CodeNode}.
684
+ *
685
+ * @example
686
+ * ```ts
687
+ * createText('return fetch(id)')
688
+ * // { kind: 'Text', value: 'return fetch(id)' }
689
+ * ```
690
+ */
691
+ export function createText(value: string): TextNode {
692
+ return { value, kind: 'Text' }
693
+ }
694
+
695
+ /**
696
+ * Creates a {@link BreakNode} representing a line break in the source output.
697
+ *
698
+ * Corresponds to `<br/>` in JSX components. Prints as an empty string which,
699
+ * when joined with `\n` by `printNodes`, produces a blank line.
700
+ *
701
+ * @example
702
+ * ```ts
703
+ * createBreak()
704
+ * // { kind: 'Break' }
705
+ * ```
706
+ */
707
+ export function createBreak(): BreakNode {
708
+ return { kind: 'Break' }
709
+ }
710
+
711
+ /**
712
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
713
+ *
714
+ * Use this to embed JSX markup (including fragments `<>…</>`) directly in generated code.
715
+ *
716
+ * @example
717
+ * ```ts
718
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
719
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
720
+ * ```
721
+ */
722
+ export function createJsx(value: string): JsxNode {
723
+ return { value, kind: 'Jsx' }
724
+ }
package/src/index.ts CHANGED
@@ -2,6 +2,7 @@ export type { ScalarPrimitive } from './constants.ts'
2
2
  export { httpMethods, isScalarPrimitive, mediaTypes, nodeKinds, schemaTypes } from './constants.ts'
3
3
  export {
4
4
  createArrowFunction,
5
+ createBreak,
5
6
  createConst,
6
7
  createExport,
7
8
  createFile,
@@ -10,6 +11,7 @@ export {
10
11
  createFunctionParameters,
11
12
  createImport,
12
13
  createInput,
14
+ createJsx,
13
15
  createOperation,
14
16
  createOutput,
15
17
  createParameter,
@@ -19,6 +21,7 @@ export {
19
21
  createResponse,
20
22
  createSchema,
21
23
  createSource,
24
+ createText,
22
25
  createType,
23
26
  syncOptionality,
24
27
  } from './factory.ts'
@@ -32,11 +35,9 @@ export { mergeAdjacentObjects, setDiscriminatorEnum, setEnumName, simplifyUnion
32
35
  export type { OperationParamsResolver } from './utils.ts'
33
36
  export {
34
37
  caseParams,
35
- combineExports,
36
- combineImports,
37
- combineSources,
38
38
  createDiscriminantNode,
39
39
  createOperationParams,
40
+ extractStringsFromNodes,
40
41
  isStringType,
41
42
  syncSchemaRef,
42
43
  } from './utils.ts'
package/src/nodes/base.ts CHANGED
@@ -26,6 +26,9 @@ export type NodeKind =
26
26
  | 'Const'
27
27
  | 'Function'
28
28
  | 'ArrowFunction'
29
+ | 'Text'
30
+ | 'Break'
31
+ | 'Jsx'
29
32
 
30
33
  /**
31
34
  * Base shape shared by all AST nodes.