@kubb/ast 5.0.0-beta.80 → 5.0.0-beta.82

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.
@@ -1,5 +1,187 @@
1
1
  import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
2
2
 
3
+ //#region src/constants.d.ts
4
+ /**
5
+ * Traversal depth for AST visitor utilities.
6
+ *
7
+ * - `'shallow'` visits only the immediate node, skipping children.
8
+ * - `'deep'` recursively visits all descendant nodes.
9
+ */
10
+ type VisitorDepth = 'shallow' | 'deep';
11
+ /**
12
+ * Schema type discriminators used by all AST schema nodes.
13
+ *
14
+ * Each value is a stable discriminator across the AST (for example `schema.type === schemaTypes.object`).
15
+ */
16
+ declare const schemaTypes: {
17
+ /**
18
+ * Text value.
19
+ */
20
+ readonly string: "string";
21
+ /**
22
+ * Floating-point number (`float`, `double`).
23
+ */
24
+ readonly number: "number";
25
+ /**
26
+ * Whole number (`int32`). Use `bigint` for `int64`.
27
+ */
28
+ readonly integer: "integer";
29
+ /**
30
+ * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
31
+ */
32
+ readonly bigint: "bigint";
33
+ /**
34
+ * Boolean value.
35
+ */
36
+ readonly boolean: "boolean";
37
+ /**
38
+ * Explicit null value.
39
+ */
40
+ readonly null: "null";
41
+ /**
42
+ * Any value (no type restriction).
43
+ */
44
+ readonly any: "any";
45
+ /**
46
+ * Unknown value (must be narrowed before usage).
47
+ */
48
+ readonly unknown: "unknown";
49
+ /**
50
+ * No return value (`void`).
51
+ */
52
+ readonly void: "void";
53
+ /**
54
+ * Object with named properties.
55
+ */
56
+ readonly object: "object";
57
+ /**
58
+ * Sequential list of items.
59
+ */
60
+ readonly array: "array";
61
+ /**
62
+ * Fixed-length list with position-specific items.
63
+ */
64
+ readonly tuple: "tuple";
65
+ /**
66
+ * "One of" multiple schema members.
67
+ */
68
+ readonly union: "union";
69
+ /**
70
+ * "All of" multiple schema members.
71
+ */
72
+ readonly intersection: "intersection";
73
+ /**
74
+ * Enum schema.
75
+ */
76
+ readonly enum: "enum";
77
+ /**
78
+ * Reference to another schema.
79
+ */
80
+ readonly ref: "ref";
81
+ /**
82
+ * Calendar date (for example `2026-03-24`).
83
+ */
84
+ readonly date: "date";
85
+ /**
86
+ * Date-time value (for example `2026-03-24T09:00:00Z`).
87
+ */
88
+ readonly datetime: "datetime";
89
+ /**
90
+ * Time-only value (for example `09:00:00`).
91
+ */
92
+ readonly time: "time";
93
+ /**
94
+ * UUID value.
95
+ */
96
+ readonly uuid: "uuid";
97
+ /**
98
+ * Email address value.
99
+ */
100
+ readonly email: "email";
101
+ /**
102
+ * URL value.
103
+ */
104
+ readonly url: "url";
105
+ /**
106
+ * IPv4 address value.
107
+ */
108
+ readonly ipv4: "ipv4";
109
+ /**
110
+ * IPv6 address value.
111
+ */
112
+ readonly ipv6: "ipv6";
113
+ /**
114
+ * Binary/blob value.
115
+ */
116
+ readonly blob: "blob";
117
+ /**
118
+ * Impossible value (`never`).
119
+ */
120
+ readonly never: "never";
121
+ };
122
+ //#endregion
123
+ //#region src/defineDialect.d.ts
124
+ /**
125
+ * The spec-specific questions a schema parser answers while turning a source document into Kubb
126
+ * AST nodes. The rest of the pipeline is generic, so this is the one seam where source formats
127
+ * differ.
128
+ */
129
+ type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {
130
+ /**
131
+ * Whether the schema is nullable.
132
+ */
133
+ isNullable(schema?: TSchema): boolean;
134
+ /**
135
+ * Whether the value is a `$ref` pointer.
136
+ */
137
+ isReference(value?: unknown): value is TRef;
138
+ /**
139
+ * Whether the schema carries a discriminator for polymorphism.
140
+ */
141
+ isDiscriminator(value?: unknown): value is TDiscriminated;
142
+ /**
143
+ * Whether the schema is binary data, converted to a `blob` node.
144
+ */
145
+ isBinary(schema: TSchema): boolean;
146
+ /**
147
+ * Resolves a local `$ref` against the document, or nullish when it cannot.
148
+ */
149
+ resolveRef<TResolved>(document: TDocument, ref: string): TResolved | null | undefined;
150
+ };
151
+ /**
152
+ * A spec adapter's dialect. `name` identifies it in logs and diagnostics, and `schema` holds the
153
+ * spec-specific schema questions the parser answers.
154
+ */
155
+ type Dialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {
156
+ /**
157
+ * Identifies the dialect in logs and diagnostics.
158
+ */
159
+ name: string;
160
+ /**
161
+ * The spec-specific schema behavior. See {@link SchemaDialect}.
162
+ */
163
+ schema: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>;
164
+ };
165
+ /**
166
+ * Types a {@link Dialect} for an adapter. Adds no runtime behavior and only pins the
167
+ * dialect's type for inference.
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * export const oasDialect = defineDialect({
172
+ * name: 'oas',
173
+ * schema: {
174
+ * isNullable,
175
+ * isReference,
176
+ * isDiscriminator,
177
+ * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',
178
+ * resolveRef,
179
+ * },
180
+ * })
181
+ * ```
182
+ */
183
+ declare function defineDialect<TSchema, TRef, TDiscriminated, TDocument>(dialect: Dialect<TSchema, TRef, TDiscriminated, TDocument>): Dialect<TSchema, TRef, TDiscriminated, TDocument>;
184
+ //#endregion
3
185
  //#region src/nodes/base.d.ts
4
186
  /**
5
187
  * `kind` values used by AST nodes.
@@ -2184,5 +2366,538 @@ declare function createOutput(overrides?: Partial<Omit<OutputNode, 'kind'>>): Ou
2184
2366
  */
2185
2367
  type Node = InputNode | OutputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | RequestBodyNode | ContentNode | FileNode | ImportNode | ExportNode | SourceNode | ConstNode | TypeNode | FunctionNode | ArrowFunctionNode;
2186
2368
  //#endregion
2187
- export { ScalarSchemaType as $, SourceNode as A, createFunction as At, ContentNode as B, defineNode as Bt, ParameterNode as C, TypeNode as Ct, ExportNode as D, createArrowFunction as Dt, parameterDef as E, constDef as Et, createSource as F, jsxDef as Ft, DatetimeSchemaNode as G, createContent as H, NodeKind as Ht, exportDef as I, textDef as It, NumberSchemaNode as J, EnumSchemaNode as K, fileDef as L, typeDef as Lt, createExport as M, createText as Mt, createFile as N, createType as Nt, FileNode as O, createBreak as Ot, createImport as P, functionDef as Pt, ScalarSchemaNode as Q, importDef as R, DistributiveOmit as Rt, ParameterLocation as S, TextNode as St, createParameter as T, breakDef as Tt, ArraySchemaNode as U, contentDef as V, BaseNode as Vt, DateSchemaNode as W, PrimitiveSchemaType as X, ObjectSchemaNode as Y, RefSchemaNode as Z, createResponse as _, CodeNode as _t, InputMeta as a, UnionSchemaNode as at, createRequestBody as b, JSDocNode as bt, inputDef as c, schemaDef as ct, HttpOperationNode as d, createProperty as dt, SchemaNode as et, OperationNode as f, propertyDef as ft, StatusCode as g, BreakNode as gt, ResponseNode as h, ArrowFunctionNode as ht, outputDef as i, TimeSchemaNode as it, UserFileNode as j, createJsx as jt, ImportNode as k, createConst as kt, GenericOperationNode as l, PropertyNode as lt, operationDef as m, ParserOptions as mt, OutputNode as n, SchemaType as nt, InputNode as o, UrlSchemaNode as ot, createOperation as p, InferSchemaNode as pt, IntersectionSchemaNode as q, createOutput as r, StringSchemaNode as rt, createInput as s, createSchema as st, Node as t, SchemaNodeByType as tt, HttpMethod as u, UserPropertyNode as ut, responseDef as v, ConstNode as vt, ParameterStyle as w, arrowFunctionDef as wt, requestBodyDef as x, JsxNode as xt, RequestBodyNode as y, FunctionNode as yt, sourceDef as z, NodeDef as zt };
2188
- //# sourceMappingURL=index-Cu2zmNxv.d.ts.map
2369
+ //#region src/visitor.d.ts
2370
+ /**
2371
+ * Ordered mapping of `[NodeType, ParentType]` pairs.
2372
+ *
2373
+ * `ParentOf` uses this map to find parent types.
2374
+ */
2375
+ type ParentNodeMap = [[InputNode, undefined], [OutputNode, undefined], [OperationNode, InputNode], [RequestBodyNode, OperationNode], [ContentNode, RequestBodyNode | ResponseNode], [SchemaNode, InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode], [PropertyNode, SchemaNode], [ParameterNode, OperationNode], [ResponseNode, OperationNode]];
2376
+ /**
2377
+ * Resolves the parent node type for a given AST node type.
2378
+ *
2379
+ * Visitor context relies on this so `ctx.parent` is typed for each callback.
2380
+ *
2381
+ * @example
2382
+ * ```ts
2383
+ * type InputParent = ParentOf<InputNode>
2384
+ * // undefined
2385
+ * ```
2386
+ *
2387
+ * @example
2388
+ * ```ts
2389
+ * type PropertyParent = ParentOf<PropertyNode>
2390
+ * // SchemaNode
2391
+ * ```
2392
+ *
2393
+ * @example
2394
+ * ```ts
2395
+ * type SchemaParent = ParentOf<SchemaNode>
2396
+ * // InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode
2397
+ * ```
2398
+ */
2399
+ type ParentOf<T extends Node, TEntries extends ReadonlyArray<[Node, unknown]> = ParentNodeMap> = TEntries extends [infer TEntry extends [Node, unknown], ...infer TRest extends ReadonlyArray<[Node, unknown]>] ? T extends TEntry[0] ? TEntry[1] : ParentOf<T, TRest> : Node;
2400
+ /**
2401
+ * Traversal context passed as the second argument to every visitor callback.
2402
+ * `parent` is typed from the current node type.
2403
+ *
2404
+ * @example
2405
+ * ```ts
2406
+ * const visitor: Visitor = {
2407
+ * schema(node, { parent }) {
2408
+ * // parent type is narrowed by node kind
2409
+ * },
2410
+ * }
2411
+ * ```
2412
+ */
2413
+ type VisitorContext<T extends Node = Node> = {
2414
+ /**
2415
+ * Parent node of the currently visited node.
2416
+ * For `InputNode`, this is `undefined`.
2417
+ */
2418
+ parent?: ParentOf<T>;
2419
+ };
2420
+ /**
2421
+ * Synchronous visitor consumed by `transform`. Each optional callback runs
2422
+ * for the matching node type. Return a new node to replace it, or `undefined`
2423
+ * to leave it untouched.
2424
+ *
2425
+ * Plugins typically expose `transformer` so users can supply a `Visitor` that
2426
+ * rewrites the AST before printing.
2427
+ *
2428
+ * @example Prefix every operationId
2429
+ * ```ts
2430
+ * const visitor: Visitor = {
2431
+ * operation(node) {
2432
+ * return { ...node, operationId: `api_${node.operationId}` }
2433
+ * },
2434
+ * }
2435
+ * ```
2436
+ *
2437
+ * @example Strip schema descriptions
2438
+ * ```ts
2439
+ * const visitor: Visitor = {
2440
+ * schema(node) {
2441
+ * return { ...node, description: undefined }
2442
+ * },
2443
+ * }
2444
+ * ```
2445
+ */
2446
+ type Visitor = {
2447
+ input?(node: InputNode, context: VisitorContext<InputNode>): undefined | null | InputNode;
2448
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): undefined | null | OutputNode;
2449
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): undefined | null | OperationNode;
2450
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): undefined | null | SchemaNode;
2451
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): undefined | null | PropertyNode;
2452
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): undefined | null | ParameterNode;
2453
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): undefined | null | ResponseNode;
2454
+ };
2455
+ /**
2456
+ * A visitor callback result that may be sync or async.
2457
+ */
2458
+ type MaybePromise<T> = T | Promise<T>;
2459
+ /**
2460
+ * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.
2461
+ *
2462
+ * @example
2463
+ * ```ts
2464
+ * const visitor: AsyncVisitor = {
2465
+ * async operation(node) {
2466
+ * await Promise.resolve(node.operationId)
2467
+ * },
2468
+ * }
2469
+ * ```
2470
+ */
2471
+ type AsyncVisitor = {
2472
+ input?(node: InputNode, context: VisitorContext<InputNode>): MaybePromise<undefined | null | InputNode>;
2473
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): MaybePromise<undefined | null | OutputNode>;
2474
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<undefined | null | OperationNode>;
2475
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<undefined | null | SchemaNode>;
2476
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<undefined | null | PropertyNode>;
2477
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<undefined | null | ParameterNode>;
2478
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<undefined | null | ResponseNode>;
2479
+ };
2480
+ /**
2481
+ * Visitor used by `collect`.
2482
+ *
2483
+ * @example
2484
+ * ```ts
2485
+ * const visitor: CollectVisitor<string> = {
2486
+ * operation(node) {
2487
+ * return node.operationId
2488
+ * },
2489
+ * }
2490
+ * ```
2491
+ */
2492
+ type CollectVisitor<T> = {
2493
+ input?(node: InputNode, context: VisitorContext<InputNode>): T | null | undefined;
2494
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): T | null | undefined;
2495
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | null | undefined;
2496
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | null | undefined;
2497
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | null | undefined;
2498
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | null | undefined;
2499
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | null | undefined;
2500
+ };
2501
+ /**
2502
+ * Options for `transform`.
2503
+ *
2504
+ * @example
2505
+ * ```ts
2506
+ * const options: TransformOptions = { depth: 'deep', schema: (node) => node }
2507
+ * ```
2508
+ *
2509
+ * @example
2510
+ * ```ts
2511
+ * // Only transform the current node, not nested children
2512
+ * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }
2513
+ * ```
2514
+ */
2515
+ type TransformOptions = Visitor & {
2516
+ /**
2517
+ * Traversal depth.
2518
+ * @default 'deep'
2519
+ */
2520
+ depth?: VisitorDepth;
2521
+ /**
2522
+ * Internal parent override used during recursion.
2523
+ */
2524
+ parent?: Node;
2525
+ };
2526
+ /**
2527
+ * Options for `walk`.
2528
+ *
2529
+ * @example
2530
+ * ```ts
2531
+ * const options: WalkOptions = { depth: 'deep', concurrency: 10, root: () => {} }
2532
+ * ```
2533
+ */
2534
+ type WalkOptions = AsyncVisitor & {
2535
+ /**
2536
+ * Traversal depth.
2537
+ * @default 'deep'
2538
+ */
2539
+ depth?: VisitorDepth;
2540
+ /**
2541
+ * Maximum number of sibling nodes visited concurrently.
2542
+ * @default 30
2543
+ */
2544
+ concurrency?: number;
2545
+ };
2546
+ /**
2547
+ * Options for `collect`.
2548
+ *
2549
+ * @example
2550
+ * ```ts
2551
+ * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }
2552
+ * ```
2553
+ */
2554
+ type CollectOptions<T> = CollectVisitor<T> & {
2555
+ /**
2556
+ * Traversal depth.
2557
+ * @default 'deep'
2558
+ */
2559
+ depth?: VisitorDepth;
2560
+ /**
2561
+ * Internal parent override used during recursion.
2562
+ */
2563
+ parent?: Node;
2564
+ };
2565
+ /**
2566
+ * Async depth-first traversal for side effects. Visitor return values are
2567
+ * ignored. Use `transform` when you want to rewrite nodes.
2568
+ *
2569
+ * Sibling nodes at each depth run concurrently up to `options.concurrency`
2570
+ * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor
2571
+ * work. Lower values reduce memory pressure.
2572
+ *
2573
+ * @example Log every operation
2574
+ * ```ts
2575
+ * await walk(root, {
2576
+ * operation(node) {
2577
+ * console.log(node.operationId)
2578
+ * },
2579
+ * })
2580
+ * ```
2581
+ *
2582
+ * @example Only visit the root node
2583
+ * ```ts
2584
+ * await walk(root, { depth: 'shallow', input: () => {} })
2585
+ * ```
2586
+ */
2587
+ declare function walk(node: Node, options: WalkOptions): Promise<void>;
2588
+ /**
2589
+ * Synchronous depth-first transform. Each visitor callback can return a
2590
+ * replacement node. Returning `undefined` keeps the original.
2591
+ *
2592
+ * The original tree is never mutated, a new tree is returned. Pass
2593
+ * `depth: 'shallow'` to skip recursion into children.
2594
+ *
2595
+ * @example Prefix every operationId
2596
+ * ```ts
2597
+ * const next = transform(root, {
2598
+ * operation(node) {
2599
+ * return { ...node, operationId: `prefixed_${node.operationId}` }
2600
+ * },
2601
+ * })
2602
+ * ```
2603
+ *
2604
+ * @example Replace only the root node
2605
+ * ```ts
2606
+ * const next = transform(root, {
2607
+ * depth: 'shallow',
2608
+ * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),
2609
+ * })
2610
+ * ```
2611
+ */
2612
+ declare function transform(node: InputNode, options: TransformOptions): InputNode;
2613
+ declare function transform(node: OutputNode, options: TransformOptions): OutputNode;
2614
+ declare function transform(node: OperationNode, options: TransformOptions): OperationNode;
2615
+ declare function transform(node: SchemaNode, options: TransformOptions): SchemaNode;
2616
+ declare function transform(node: PropertyNode, options: TransformOptions): PropertyNode;
2617
+ declare function transform(node: ParameterNode, options: TransformOptions): ParameterNode;
2618
+ declare function transform(node: ResponseNode, options: TransformOptions): ResponseNode;
2619
+ declare function transform(node: Node, options: TransformOptions): Node;
2620
+ /**
2621
+ * Eager depth-first collection pass. Gathers every non-null value the visitor
2622
+ * callbacks return into an array.
2623
+ *
2624
+ * @example Collect every operationId
2625
+ * ```ts
2626
+ * const ids = collect<string>(root, {
2627
+ * operation(node) {
2628
+ * return node.operationId
2629
+ * },
2630
+ * })
2631
+ * ```
2632
+ */
2633
+ declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
2634
+ //#endregion
2635
+ //#region src/defineMacro.d.ts
2636
+ /**
2637
+ * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,
2638
+ * and `undefined` keeps declaration order.
2639
+ */
2640
+ type Enforce = 'pre' | 'post';
2641
+ /**
2642
+ * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a
2643
+ * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an
2644
+ * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter
2645
+ * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).
2646
+ */
2647
+ type Macro = Visitor & {
2648
+ /**
2649
+ * Macro identifier used to tell macros apart, for example `'simplify-union'`.
2650
+ */
2651
+ name: string;
2652
+ /**
2653
+ * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.
2654
+ * Ordering within a bucket follows list order.
2655
+ */
2656
+ enforce?: Enforce;
2657
+ /**
2658
+ * Gate checked against the current node before any callback runs. When it returns `false`
2659
+ * the macro is skipped for that node.
2660
+ */
2661
+ when?: (node: Node) => boolean;
2662
+ };
2663
+ /**
2664
+ * Types a macro for inference and a single construction site, mirroring `definePlugin`.
2665
+ * Adds no runtime behavior.
2666
+ *
2667
+ * @example
2668
+ * ```ts
2669
+ * const macroUntagged = defineMacro({
2670
+ * name: 'untagged',
2671
+ * operation(node) {
2672
+ * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }
2673
+ * },
2674
+ * })
2675
+ * ```
2676
+ */
2677
+ declare function defineMacro(macro: Macro): Macro;
2678
+ /**
2679
+ * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin
2680
+ * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied
2681
+ * sequentially per node so later macros see earlier output. This differs from a plain visitor, which
2682
+ * has no names, ordering, or composition.
2683
+ *
2684
+ * @example
2685
+ * ```ts
2686
+ * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])
2687
+ * const next = transform(root, visitor)
2688
+ * ```
2689
+ */
2690
+ declare function composeMacros(macros: ReadonlyArray<Macro>): Visitor;
2691
+ /**
2692
+ * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s
2693
+ * structural sharing, so an empty or no-op macro list returns the same reference. Pass
2694
+ * `depth: 'shallow'` to rewrite the root node only.
2695
+ *
2696
+ * @example
2697
+ * ```ts
2698
+ * const next = applyMacros(root, [macroIntegerToString])
2699
+ * ```
2700
+ *
2701
+ * @example Apply to the root node only
2702
+ * ```ts
2703
+ * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })
2704
+ * ```
2705
+ */
2706
+ declare function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: {
2707
+ depth?: VisitorDepth;
2708
+ }): TNode;
2709
+ //#endregion
2710
+ //#region src/createPrinter.d.ts
2711
+ /**
2712
+ * Runtime context passed as `this` to printer handlers.
2713
+ *
2714
+ * `this.transform` dispatches to node-level handlers from `nodes`.
2715
+ *
2716
+ * @example
2717
+ * ```ts
2718
+ * const context: PrinterHandlerContext<string, {}> = {
2719
+ * options: {},
2720
+ * transform: () => 'value',
2721
+ * }
2722
+ * ```
2723
+ */
2724
+ type PrinterHandlerContext<TOutput, TOptions extends object> = {
2725
+ /**
2726
+ * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.
2727
+ * Use `this.transform` inside `nodes` handlers and inside the `print` override.
2728
+ */
2729
+ transform: (node: SchemaNode) => TOutput | null;
2730
+ /**
2731
+ * Run the printer's built-in handler for the node, ignoring any override for its type.
2732
+ * Inside an override, `this.base(node)` returns what the printer would have emitted,
2733
+ * so the override can wrap it instead of re-implementing the handler. Nested nodes
2734
+ * still dispatch through the overrides.
2735
+ */
2736
+ base: (node: SchemaNode) => TOutput | null;
2737
+ /**
2738
+ * Options for this printer instance.
2739
+ */
2740
+ options: TOptions;
2741
+ };
2742
+ /**
2743
+ * Handler for one schema node type.
2744
+ *
2745
+ * Use a regular function (not an arrow function) if you need `this`.
2746
+ *
2747
+ * @example
2748
+ * ```ts
2749
+ * const handler: PrinterHandler<string, {}, 'string'> = function () {
2750
+ * return 'string'
2751
+ * }
2752
+ * ```
2753
+ */
2754
+ type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null;
2755
+ /**
2756
+ * Partial map of per-node-type handler overrides for a printer.
2757
+ *
2758
+ * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).
2759
+ * Supply only the handlers you want to replace. The printer's built-in
2760
+ * defaults fill in the rest.
2761
+ *
2762
+ * @example
2763
+ * ```ts
2764
+ * pluginZod({
2765
+ * printer: {
2766
+ * nodes: {
2767
+ * date(): string {
2768
+ * return 'z.string().date()'
2769
+ * },
2770
+ * } satisfies PrinterPartial<string, PrinterZodOptions>,
2771
+ * },
2772
+ * })
2773
+ * ```
2774
+ */
2775
+ type PrinterPartial<TOutput, TOptions extends object> = Partial<{ [K in SchemaType]: PrinterHandler<TOutput, TOptions, K> }>;
2776
+ /**
2777
+ * Generic shape used by `definePrinter`.
2778
+ *
2779
+ * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)
2780
+ * - `TOptions` options passed to and stored on the printer instance
2781
+ * - `TOutput` the type emitted by node handlers
2782
+ * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)
2783
+ *
2784
+ * @example
2785
+ * ```ts
2786
+ * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>
2787
+ * ```
2788
+ */
2789
+ type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
2790
+ name: TName;
2791
+ options: TOptions;
2792
+ output: TOutput;
2793
+ printOutput: TPrintOutput;
2794
+ };
2795
+ /**
2796
+ * Printer instance returned by a printer factory.
2797
+ *
2798
+ * @example
2799
+ * ```ts
2800
+ * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})
2801
+ * ```
2802
+ */
2803
+ type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
2804
+ /**
2805
+ * Unique identifier supplied at creation time.
2806
+ */
2807
+ name: T['name'];
2808
+ /**
2809
+ * Options for this printer instance.
2810
+ */
2811
+ options: T['options'];
2812
+ /**
2813
+ * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
2814
+ * Always dispatches through the `nodes` map. Never calls the `print` override.
2815
+ * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
2816
+ */
2817
+ transform: (node: SchemaNode) => T['output'] | null;
2818
+ /**
2819
+ * Public printer. If the builder provides a root-level `print`, this calls that
2820
+ * higher-level function (which may produce full declarations).
2821
+ * Otherwise, falls back to the node-level dispatcher.
2822
+ */
2823
+ print: (node: SchemaNode) => T['printOutput'] | null;
2824
+ };
2825
+ /**
2826
+ * Builder function passed to `definePrinter`.
2827
+ *
2828
+ * It receives resolved options and returns:
2829
+ * - `name`
2830
+ * - `options`
2831
+ * - `nodes` handlers
2832
+ * - optional top-level `print` override
2833
+ *
2834
+ * @example
2835
+ * ```ts
2836
+ * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })
2837
+ * ```
2838
+ */
2839
+ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
2840
+ name: T['name'];
2841
+ /**
2842
+ * Options to store on the printer.
2843
+ */
2844
+ options: T['options'];
2845
+ nodes: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
2846
+ /**
2847
+ * User-supplied handler overrides. An override wins over the matching `nodes` handler,
2848
+ * and can call `this.base(node)` to reuse the handler it replaced. Pass overrides here
2849
+ * instead of spreading them into `nodes`, otherwise `this.base` cannot find the original.
2850
+ */
2851
+ overrides?: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
2852
+ /**
2853
+ * Optional root-level print override. When provided, becomes the public `printer.print`.
2854
+ * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
2855
+ * not the override itself, so recursion is safe.
2856
+ */
2857
+ print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null;
2858
+ };
2859
+ /**
2860
+ * Creates a schema printer: a function that takes a `SchemaNode` and emits
2861
+ * code in your target language. Each plugin that produces code from schemas
2862
+ * (TypeScript types, Zod schemas, Faker factories) ships a printer built
2863
+ * with this helper.
2864
+ *
2865
+ * The builder receives resolved options and returns:
2866
+ *
2867
+ * - `name` unique identifier for the printer.
2868
+ * - `options` stored on the returned printer instance.
2869
+ * - `nodes` map of `SchemaType` → handler. Handlers return the rendered
2870
+ * output (a string, a TypeScript AST node, ...) for that schema type.
2871
+ * - `overrides` (optional), user-supplied handlers that win over `nodes`.
2872
+ * An override can call `this.base(node)` to reuse the handler it replaced.
2873
+ * - `print` (optional), top-level override exposed as `printer.print`.
2874
+ * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
2875
+ *
2876
+ * Without a `print` override, `printer.print` falls back to `printer.transform`
2877
+ * (the node-level dispatcher).
2878
+ *
2879
+ * @example Tiny Zod printer
2880
+ * ```ts
2881
+ * import { createPrinter, type PrinterFactoryOptions } from '@kubb/ast'
2882
+ *
2883
+ * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
2884
+ *
2885
+ * export const zodPrinter = createPrinter<PrinterZod>((options) => ({
2886
+ * name: 'zod',
2887
+ * options: { strict: options.strict ?? true },
2888
+ * nodes: {
2889
+ * string: () => 'z.string()',
2890
+ * object(node) {
2891
+ * const props = node.properties
2892
+ * .map((p) => `${p.name}: ${this.transform(p.schema)}`)
2893
+ * .join(', ')
2894
+ * return `z.object({ ${props} })`
2895
+ * },
2896
+ * },
2897
+ * }))
2898
+ * ```
2899
+ */
2900
+ declare function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
2901
+ //#endregion
2902
+ export { importDef as $, DistributiveOmit as $t, ResponseNode as A, ArrowFunctionNode as At, createParameter as B, breakDef as Bt, inputDef as C, schemaDef as Ct, OperationNode as D, propertyDef as Dt, HttpOperationNode as E, createProperty as Et, createRequestBody as F, JSDocNode as Ft, SourceNode as G, createFunction as Gt, ExportNode as H, createArrowFunction as Ht, requestBodyDef as I, JsxNode as It, createFile as J, createType as Jt, UserFileNode as K, createJsx as Kt, ParameterLocation as L, TextNode as Lt, createResponse as M, CodeNode as Mt, responseDef as N, ConstNode as Nt, createOperation as O, InferSchemaNode as Ot, RequestBodyNode as P, FunctionNode as Pt, fileDef as Q, typeDef as Qt, ParameterNode as R, TypeNode as Rt, createInput as S, createSchema as St, HttpMethod as T, UserPropertyNode as Tt, FileNode as U, createBreak as Ut, parameterDef as V, constDef as Vt, ImportNode as W, createConst as Wt, createSource as X, jsxDef as Xt, createImport as Y, functionDef as Yt, exportDef as Z, textDef as Zt, OutputNode as _, SchemaType as _t, Enforce as a, SchemaDialect as an, DateSchemaNode as at, InputMeta as b, UnionSchemaNode as bt, composeMacros as c, IntersectionSchemaNode as ct, Visitor as d, PrimitiveSchemaType as dt, NodeDef as en, sourceDef as et, VisitorContext as f, RefSchemaNode as ft, Node as g, SchemaNodeByType as gt, walk as h, SchemaNode as ht, createPrinter as i, Dialect as in, ArraySchemaNode as it, StatusCode as j, BreakNode as jt, operationDef as k, ParserOptions as kt, defineMacro as l, NumberSchemaNode as lt, transform as m, ScalarSchemaType as mt, PrinterFactoryOptions as n, BaseNode as nn, contentDef as nt, Macro as o, defineDialect as on, DatetimeSchemaNode as ot, collect as p, ScalarSchemaNode as pt, createExport as q, createText as qt, PrinterPartial as r, NodeKind as rn, createContent as rt, applyMacros as s, schemaTypes as sn, EnumSchemaNode as st, Printer as t, defineNode as tn, ContentNode as tt, ParentOf as u, ObjectSchemaNode as ut, createOutput as v, StringSchemaNode as vt, GenericOperationNode as w, PropertyNode as wt, InputNode as x, UrlSchemaNode as xt, outputDef as y, TimeSchemaNode as yt, ParameterStyle as z, arrowFunctionDef as zt };
2903
+ //# sourceMappingURL=types-XcYJovdT.d.ts.map