@kubb/ast 5.0.0-beta.9 → 5.0.0-beta.91

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.
@@ -0,0 +1,2801 @@
1
+ import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
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
185
+ //#region src/nodes/base.d.ts
186
+ /**
187
+ * `kind` values used by AST nodes.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * const kind: NodeKind = 'Schema'
192
+ * ```
193
+ */
194
+ type NodeKind = 'Input' | 'Output' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'RequestBody' | 'Content' | 'Type' | 'File' | 'Import' | 'Export' | 'Source' | 'Const' | 'Function' | 'ArrowFunction' | 'Text' | 'Break' | 'Jsx';
195
+ /**
196
+ * Base shape shared by all AST nodes.
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * const base: BaseNode = { kind: 'Input' }
201
+ * ```
202
+ */
203
+ type BaseNode = {
204
+ /**
205
+ * Node discriminator.
206
+ */
207
+ kind: NodeKind;
208
+ };
209
+ //#endregion
210
+ //#region src/defineNode.d.ts
211
+ /**
212
+ * Visitor callback names, one per traversable node kind, in traversal order.
213
+ * Kept in sync with the keys of `Visitor` in `visitor.ts`.
214
+ */
215
+ declare const visitorKeys: readonly ["input", "output", "operation", "schema", "property", "parameter", "response"];
216
+ /**
217
+ * One of the {@link visitorKeys} callback names.
218
+ */
219
+ type VisitorKey = (typeof visitorKeys)[number];
220
+ /**
221
+ * Distributive `Omit` that preserves each member of a union.
222
+ *
223
+ * @example
224
+ * ```ts
225
+ * type A = { kind: 'a'; keep: string; drop: number }
226
+ * type B = { kind: 'b'; keep: boolean; drop: number }
227
+ * type Result = DistributiveOmit<A | B, 'drop'>
228
+ * // -> { kind: 'a'; keep: string } | { kind: 'b'; keep: boolean }
229
+ * ```
230
+ */
231
+ type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
232
+ /**
233
+ * The single definition derived from one {@link defineNode} call: the node's
234
+ * `create` builder, its `is` guard, and the traversal metadata the registry
235
+ * collects into the visitor tables.
236
+ */
237
+ type NodeDef<TNode extends BaseNode = BaseNode, TInput = never> = {
238
+ /**
239
+ * Node discriminator this definition owns.
240
+ */
241
+ kind: NodeKind;
242
+ /**
243
+ * Builds a node from its input, applying `defaults` and the optional `build` hook.
244
+ */
245
+ create: (input: TInput) => TNode;
246
+ /**
247
+ * Type guard matching this node kind.
248
+ */
249
+ is: (node: unknown) => node is TNode;
250
+ /**
251
+ * Child node fields in traversal order. Feeds `VISITOR_KEYS`.
252
+ */
253
+ children?: ReadonlyArray<string>;
254
+ /**
255
+ * Visitor callback name. Feeds `VISITOR_KEY_BY_KIND`.
256
+ */
257
+ visitorKey?: VisitorKey;
258
+ };
259
+ type DefineNodeConfig<TNode extends BaseNode, TInput, TBuilt extends object> = {
260
+ kind: TNode['kind'];
261
+ defaults?: Partial<TNode>;
262
+ build?: (input: TInput) => TBuilt;
263
+ children?: ReadonlyArray<string>;
264
+ visitorKey?: VisitorKey;
265
+ };
266
+ /**
267
+ * Defines a node once and derives its `create` builder, `is` guard, and traversal
268
+ * metadata. `create` merges `defaults`, the `build` hook (or the raw input), and the
269
+ * `kind`, so node construction lives in one place without scattered `as` casts.
270
+ *
271
+ * @example Simple node
272
+ * ```ts
273
+ * const importDef = defineNode<ImportNode>({ kind: 'Import' })
274
+ * const createImport = importDef.create
275
+ * ```
276
+ *
277
+ * @example Node with a build hook
278
+ * ```ts
279
+ * const propertyDef = defineNode<PropertyNode, UserPropertyNode>({
280
+ * kind: 'Property',
281
+ * build: (props) => ({ ...props, required: props.required ?? false }),
282
+ * children: ['schema'],
283
+ * visitorKey: 'property',
284
+ * })
285
+ * ```
286
+ */
287
+ declare function defineNode<TNode extends BaseNode, TInput = Omit<TNode, 'kind'>, TBuilt extends object = Omit<TNode, 'kind'>>(config: DefineNodeConfig<TNode, TInput, TBuilt>): NodeDef<TNode, TInput>;
288
+ //#endregion
289
+ //#region src/nodes/code.d.ts
290
+ /**
291
+ * JSDoc documentation metadata attached to code declarations.
292
+ */
293
+ type JSDocNode = {
294
+ /**
295
+ * JSDoc comment lines. `undefined` entries are filtered out during rendering.
296
+ *
297
+ * @example
298
+ * ```ts
299
+ * ['@description A pet resource', '@deprecated']
300
+ * ```
301
+ */
302
+ comments?: Array<string | undefined>;
303
+ };
304
+ /**
305
+ * AST node representing a TypeScript `const` declaration.
306
+ *
307
+ * Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.
308
+ * The `children` prop of the component is represented as `nodes`.
309
+ *
310
+ * @example
311
+ * ```ts
312
+ * createConst({ name: 'pet', export: true, asConst: true })
313
+ * // export const pet = ... as const
314
+ * ```
315
+ */
316
+ type ConstNode = BaseNode & {
317
+ kind: 'Const';
318
+ /**
319
+ * Name of the constant declaration.
320
+ */
321
+ name: string;
322
+ /**
323
+ * Whether the declaration should be exported.
324
+ */
325
+ export?: boolean | null;
326
+ /**
327
+ * Explicit type annotation.
328
+ *
329
+ * @example Type reference
330
+ * `'Pet'`
331
+ */
332
+ type?: string | null;
333
+ /**
334
+ * JSDoc documentation metadata.
335
+ */
336
+ JSDoc?: JSDocNode | null;
337
+ /**
338
+ * Whether to append `as const` to the declaration.
339
+ */
340
+ asConst?: boolean | null;
341
+ /**
342
+ * Child nodes representing the value of the constant (children of the `Const` component).
343
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
344
+ */
345
+ nodes?: Array<CodeNode>;
346
+ };
347
+ /**
348
+ * AST node representing a TypeScript `type` alias declaration.
349
+ *
350
+ * Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.
351
+ * The `children` prop of the component is represented as `nodes`.
352
+ *
353
+ * @example
354
+ * ```ts
355
+ * createType({ name: 'Pet', export: true })
356
+ * // export type Pet = ...
357
+ * ```
358
+ */
359
+ type TypeNode = BaseNode & {
360
+ kind: 'Type';
361
+ /**
362
+ * Name of the type alias.
363
+ */
364
+ name: string;
365
+ /**
366
+ * Whether the declaration should be exported.
367
+ */
368
+ export?: boolean | null;
369
+ /**
370
+ * JSDoc documentation metadata.
371
+ */
372
+ JSDoc?: JSDocNode | null;
373
+ /**
374
+ * Child nodes representing the type body (children of the `Type` component).
375
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
376
+ */
377
+ nodes?: Array<CodeNode>;
378
+ };
379
+ /**
380
+ * AST node representing a TypeScript `function` declaration.
381
+ *
382
+ * Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.
383
+ * The `children` prop of the component is represented as `nodes`.
384
+ *
385
+ * @example
386
+ * ```ts
387
+ * createFunctionDeclaration({ name: 'getPet', export: true, async: true, returnType: 'Pet' })
388
+ * // export async function getPet(): Promise<Pet> { ... }
389
+ * ```
390
+ */
391
+ type FunctionNode = BaseNode & {
392
+ kind: 'Function';
393
+ /**
394
+ * Name of the function.
395
+ */
396
+ name: string;
397
+ /**
398
+ * Whether the function is a default export.
399
+ */
400
+ default?: boolean | null;
401
+ /**
402
+ * Function parameter list as a pre-rendered string, written verbatim between the parentheses.
403
+ *
404
+ * @example
405
+ * `'id: string, config: Config = {}'`
406
+ */
407
+ params?: string | null;
408
+ /**
409
+ * Whether the function should be exported.
410
+ */
411
+ export?: boolean | null;
412
+ /**
413
+ * Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
414
+ */
415
+ async?: boolean | null;
416
+ /**
417
+ * TypeScript generic type parameters.
418
+ *
419
+ * @example Constrained generics
420
+ * `['T', 'U extends string']`
421
+ */
422
+ generics?: string | Array<string> | null;
423
+ /**
424
+ * Return type annotation.
425
+ *
426
+ * @example Type reference
427
+ * `'Pet'`
428
+ */
429
+ returnType?: string | null;
430
+ /**
431
+ * JSDoc documentation metadata.
432
+ */
433
+ JSDoc?: JSDocNode | null;
434
+ /**
435
+ * Child nodes representing the function body (children of the `Function` component).
436
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
437
+ */
438
+ nodes?: Array<CodeNode>;
439
+ };
440
+ /**
441
+ * AST node representing a TypeScript arrow function (`const name = () => { ... }`).
442
+ *
443
+ * Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.
444
+ * The `children` prop of the component is represented as `nodes`.
445
+ *
446
+ * @example
447
+ * ```ts
448
+ * createArrowFunctionDeclaration({ name: 'getPet', export: true, singleLine: true })
449
+ * // export const getPet = () => ...
450
+ * ```
451
+ */
452
+ type ArrowFunctionNode = Omit<FunctionNode, 'kind'> & {
453
+ kind: 'ArrowFunction';
454
+ /**
455
+ * Render the arrow function body as a single-line expression.
456
+ */
457
+ singleLine?: boolean | null;
458
+ };
459
+ /**
460
+ * AST node representing a raw text/string fragment in the source output.
461
+ *
462
+ * Used instead of bare `string` values so that all entries in `nodes` arrays
463
+ * are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.
464
+ *
465
+ * @example
466
+ * ```ts
467
+ * createText('return fetch(id)')
468
+ * // { kind: 'Text', value: 'return fetch(id)' }
469
+ * ```
470
+ */
471
+ type TextNode = BaseNode & {
472
+ kind: 'Text';
473
+ /**
474
+ * The raw string content.
475
+ */
476
+ value: string;
477
+ };
478
+ /**
479
+ * AST node representing a blank line in the source output.
480
+ *
481
+ * Corresponds to `<br/>` in JSX components. `printNodes` turns a `Break` between two
482
+ * statements into one blank line. Consecutive breaks, and breaks at the start or end of
483
+ * the list, are folded away, so a `Break` never produces more than one blank line.
484
+ *
485
+ * @example
486
+ * ```ts
487
+ * createBreak()
488
+ * // { kind: 'Break' }
489
+ * ```
490
+ */
491
+ type BreakNode = BaseNode & {
492
+ kind: 'Break';
493
+ };
494
+ /**
495
+ * AST node representing a raw JSX fragment in the source output.
496
+ *
497
+ * Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup
498
+ * (including fragments `<>…</>`) directly in generated code.
499
+ *
500
+ * @example
501
+ * ```ts
502
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
503
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
504
+ * ```
505
+ */
506
+ type JsxNode = BaseNode & {
507
+ kind: 'Jsx';
508
+ /**
509
+ * The raw JSX string content.
510
+ */
511
+ value: string;
512
+ };
513
+ /**
514
+ * Union of all code-generation AST nodes.
515
+ *
516
+ * These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as
517
+ * structured children in {@link SourceNode.nodes}.
518
+ */
519
+ type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
520
+ /**
521
+ * Definition for the {@link ConstNode}.
522
+ */
523
+ declare const constDef: NodeDef<ConstNode, Omit<ConstNode, "kind">>;
524
+ /**
525
+ * Definition for the {@link TypeNode}.
526
+ */
527
+ declare const typeDef: NodeDef<TypeNode, Omit<TypeNode, "kind">>;
528
+ /**
529
+ * Definition for the {@link FunctionNode}.
530
+ */
531
+ declare const functionDef: NodeDef<FunctionNode, Omit<FunctionNode, "kind">>;
532
+ /**
533
+ * Definition for the {@link ArrowFunctionNode}.
534
+ */
535
+ declare const arrowFunctionDef: NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">>;
536
+ /**
537
+ * Definition for the {@link TextNode}.
538
+ */
539
+ declare const textDef: NodeDef<TextNode, string>;
540
+ /**
541
+ * Definition for the {@link BreakNode}.
542
+ */
543
+ declare const breakDef: NodeDef<BreakNode, void>;
544
+ /**
545
+ * Definition for the {@link JsxNode}.
546
+ */
547
+ declare const jsxDef: NodeDef<JsxNode, string>;
548
+ /**
549
+ * Creates a `ConstNode` representing a TypeScript `const` declaration.
550
+ *
551
+ * @example Exported constant with type and `as const`
552
+ * ```ts
553
+ * createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
554
+ * // export const pets: Pet[] = ... as const
555
+ * ```
556
+ */
557
+ declare const createConst: (input: Omit<ConstNode, "kind">) => ConstNode;
558
+ /**
559
+ * Creates a `TypeNode` representing a TypeScript `type` alias declaration.
560
+ *
561
+ * @example
562
+ * ```ts
563
+ * createType({ name: 'Pet', export: true })
564
+ * // export type Pet = ...
565
+ * ```
566
+ */
567
+ declare const createType: (input: Omit<TypeNode, "kind">) => TypeNode;
568
+ /**
569
+ * Creates a `FunctionNode` representing a TypeScript `function` declaration.
570
+ *
571
+ * @example
572
+ * ```ts
573
+ * createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
574
+ * // export async function fetchPet(): Promise<Pet> { ... }
575
+ * ```
576
+ */
577
+ declare const createFunction: (input: Omit<FunctionNode, "kind">) => FunctionNode;
578
+ /**
579
+ * Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
580
+ *
581
+ * @example
582
+ * ```ts
583
+ * createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
584
+ * // export const double = (n: number) => ...
585
+ * ```
586
+ */
587
+ declare const createArrowFunction: (input: Omit<ArrowFunctionNode, "kind">) => ArrowFunctionNode;
588
+ /**
589
+ * Creates a {@link TextNode} representing a raw string fragment in the source output.
590
+ *
591
+ * @example
592
+ * ```ts
593
+ * createText('return fetch(id)')
594
+ * // { kind: 'Text', value: 'return fetch(id)' }
595
+ * ```
596
+ */
597
+ declare const createText: (input: string) => TextNode;
598
+ /**
599
+ * Creates a {@link BreakNode} representing a line break in the source output.
600
+ *
601
+ * @example
602
+ * ```ts
603
+ * createBreak()
604
+ * // { kind: 'Break' }
605
+ * ```
606
+ */
607
+ declare function createBreak(): BreakNode;
608
+ /**
609
+ * Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
610
+ *
611
+ * @example
612
+ * ```ts
613
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
614
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
615
+ * ```
616
+ */
617
+ declare const createJsx: (input: string) => JsxNode;
618
+ //#endregion
619
+ //#region src/infer.d.ts
620
+ /**
621
+ * Options that control how the adapter parser maps source schemas to AST nodes.
622
+ */
623
+ type ParserOptions = {
624
+ /**
625
+ * How `format: 'date-time'` schemas are represented downstream.
626
+ * - `false` falls through to a plain `string` (no validation).
627
+ * - `'string'` emits a datetime string node.
628
+ * - `'stringOffset'` emits a datetime node with timezone offset.
629
+ * - `'stringLocal'` emits a local datetime node.
630
+ * - `'date'` emits a `date` node (JavaScript `Date` object).
631
+ */
632
+ dateType: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
633
+ /**
634
+ * How `type: 'integer'` (and `format: 'int64'`) maps to TypeScript.
635
+ * - `'bigint'` is exact for 64-bit IDs, but does not round-trip through JSON.
636
+ * - `'number'` fits most JSON APIs. Loses precision above `Number.MAX_SAFE_INTEGER`.
637
+ *
638
+ * @default 'bigint'
639
+ */
640
+ integerType?: 'number' | 'bigint';
641
+ /**
642
+ * AST type used when a schema's type cannot be inferred from the spec
643
+ * (`additionalProperties: true`, missing `type`, ...).
644
+ */
645
+ unknownType: 'any' | 'unknown' | 'void';
646
+ /**
647
+ * AST type used for completely empty schemas (`{}`).
648
+ */
649
+ emptySchemaType: 'any' | 'unknown' | 'void';
650
+ /**
651
+ * Suffix appended to derived enum names when Kubb has to invent one
652
+ * (typically for inline enums on object properties).
653
+ */
654
+ enumSuffix: 'enum' | (string & {});
655
+ };
656
+ /**
657
+ * Maps each `dateType` option value to the AST node produced by `format: 'date-time'`.
658
+ */
659
+ type DateTimeNodeByDateType = {
660
+ date: DateSchemaNode;
661
+ string: DatetimeSchemaNode;
662
+ stringOffset: DatetimeSchemaNode;
663
+ stringLocal: DatetimeSchemaNode;
664
+ false: StringSchemaNode;
665
+ };
666
+ /**
667
+ * Resolves the AST node produced by `format: 'date-time'` based on the `dateType` option.
668
+ */
669
+ type ResolveDateTimeNode<TDateType extends ParserOptions['dateType']> = DateTimeNodeByDateType[TDateType extends keyof DateTimeNodeByDateType ? TDateType : 'string'];
670
+ /**
671
+ * Ordered list of `[schema-shape, SchemaNode]` pairs.
672
+ * `InferSchemaNode` walks this tuple in order and returns the first matching node type.
673
+ */
674
+ type SchemaNodeMap<TDateType extends ParserOptions['dateType'] = 'string'> = [[{
675
+ $ref: string;
676
+ }, RefSchemaNode], [{
677
+ allOf: ReadonlyArray<unknown>;
678
+ properties: object;
679
+ }, IntersectionSchemaNode], [{
680
+ allOf: readonly [unknown, unknown, ...Array<unknown>];
681
+ }, IntersectionSchemaNode], [{
682
+ allOf: ReadonlyArray<unknown>;
683
+ }, SchemaNode], [{
684
+ oneOf: ReadonlyArray<unknown>;
685
+ }, UnionSchemaNode], [{
686
+ anyOf: ReadonlyArray<unknown>;
687
+ }, UnionSchemaNode], [{
688
+ const: null;
689
+ }, ScalarSchemaNode], [{
690
+ const: string | number | boolean;
691
+ }, EnumSchemaNode], [{
692
+ type: ReadonlyArray<string>;
693
+ }, UnionSchemaNode], [{
694
+ type: 'array';
695
+ enum: ReadonlyArray<unknown>;
696
+ }, ArraySchemaNode], [{
697
+ enum: ReadonlyArray<unknown>;
698
+ }, EnumSchemaNode], [{
699
+ type: 'enum';
700
+ }, EnumSchemaNode], [{
701
+ type: 'union';
702
+ }, UnionSchemaNode], [{
703
+ type: 'intersection';
704
+ }, IntersectionSchemaNode], [{
705
+ type: 'tuple';
706
+ }, ArraySchemaNode], [{
707
+ type: 'ref';
708
+ }, RefSchemaNode], [{
709
+ type: 'datetime';
710
+ }, DatetimeSchemaNode], [{
711
+ type: 'date';
712
+ }, DateSchemaNode], [{
713
+ type: 'time';
714
+ }, TimeSchemaNode], [{
715
+ type: 'url';
716
+ }, UrlSchemaNode], [{
717
+ type: 'object';
718
+ }, ObjectSchemaNode], [{
719
+ additionalProperties: boolean | {};
720
+ }, ObjectSchemaNode], [{
721
+ type: 'array';
722
+ }, ArraySchemaNode], [{
723
+ items: object;
724
+ }, ArraySchemaNode], [{
725
+ prefixItems: ReadonlyArray<unknown>;
726
+ }, ArraySchemaNode], [{
727
+ type: string;
728
+ format: 'date-time';
729
+ }, ResolveDateTimeNode<TDateType>], [{
730
+ type: string;
731
+ format: 'date';
732
+ }, DateSchemaNode], [{
733
+ type: string;
734
+ format: 'time';
735
+ }, TimeSchemaNode], [{
736
+ format: 'date-time';
737
+ }, ResolveDateTimeNode<TDateType>], [{
738
+ format: 'date';
739
+ }, DateSchemaNode], [{
740
+ format: 'time';
741
+ }, TimeSchemaNode], [{
742
+ type: 'string';
743
+ }, StringSchemaNode], [{
744
+ type: 'number';
745
+ }, NumberSchemaNode], [{
746
+ type: 'integer';
747
+ }, NumberSchemaNode], [{
748
+ type: 'bigint';
749
+ }, NumberSchemaNode], [{
750
+ type: string;
751
+ }, ScalarSchemaNode], [{
752
+ minLength: number;
753
+ }, StringSchemaNode], [{
754
+ maxLength: number;
755
+ }, StringSchemaNode], [{
756
+ pattern: string;
757
+ }, StringSchemaNode], [{
758
+ minimum: number;
759
+ }, NumberSchemaNode], [{
760
+ maximum: number;
761
+ }, NumberSchemaNode]];
762
+ /**
763
+ * Infers the matching AST `SchemaNode` type from an input schema shape.
764
+ */
765
+ type InferSchemaNode<TSchema extends object, TDateType extends ParserOptions['dateType'] = 'string', TEntries extends ReadonlyArray<[object, SchemaNode]> = SchemaNodeMap<TDateType>> = TEntries extends [infer TEntry extends [object, SchemaNode], ...infer TRest extends ReadonlyArray<[object, SchemaNode]>] ? TSchema extends TEntry[0] ? TEntry[1] : InferSchemaNode<TSchema, TDateType, TRest> : SchemaNode;
766
+ //#endregion
767
+ //#region src/nodes/property.d.ts
768
+ /**
769
+ * AST node representing one named object property.
770
+ *
771
+ * @example
772
+ * ```ts
773
+ * const property: PropertyNode = {
774
+ * kind: 'Property',
775
+ * name: 'id',
776
+ * schema: createSchema({ type: 'integer' }),
777
+ * required: true,
778
+ * }
779
+ * ```
780
+ */
781
+ type PropertyNode = BaseNode & {
782
+ kind: 'Property';
783
+ /**
784
+ * Property key.
785
+ */
786
+ name: string;
787
+ /**
788
+ * Property schema.
789
+ */
790
+ schema: SchemaNode;
791
+ /**
792
+ * Whether the property is required.
793
+ */
794
+ required: boolean;
795
+ };
796
+ /**
797
+ * Loosely-typed property accepted by `createProperty`, with `required` optional.
798
+ */
799
+ type UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>;
800
+ /**
801
+ * Definition for the {@link PropertyNode}. `required` defaults to `false`, and the schema's
802
+ * `optional`/`nullish` flags are derived from it through {@link optionality}.
803
+ */
804
+ declare const propertyDef: NodeDef<PropertyNode, UserPropertyNode>;
805
+ /**
806
+ * Creates a `PropertyNode`.
807
+ *
808
+ * @example
809
+ * ```ts
810
+ * const property = createProperty({
811
+ * name: 'status',
812
+ * required: true,
813
+ * schema: createSchema({ type: 'string', nullable: true }),
814
+ * })
815
+ * // required=true, no optional/nullish
816
+ * ```
817
+ */
818
+ declare const createProperty: (input: UserPropertyNode) => PropertyNode;
819
+ //#endregion
820
+ //#region src/nodes/schema.d.ts
821
+ type PrimitiveSchemaType =
822
+ /**
823
+ * Text value.
824
+ */
825
+ 'string'
826
+ /**
827
+ * Floating-point number.
828
+ */
829
+ | 'number'
830
+ /**
831
+ * Integer number.
832
+ */
833
+ | 'integer'
834
+ /**
835
+ * Big integer number.
836
+ */
837
+ | 'bigint'
838
+ /**
839
+ * Boolean value.
840
+ */
841
+ | 'boolean'
842
+ /**
843
+ * Null value.
844
+ */
845
+ | 'null'
846
+ /**
847
+ * Any value.
848
+ */
849
+ | 'any'
850
+ /**
851
+ * Unknown value.
852
+ */
853
+ | 'unknown'
854
+ /**
855
+ * No value (`void`).
856
+ */
857
+ | 'void'
858
+ /**
859
+ * Never value.
860
+ */
861
+ | 'never'
862
+ /**
863
+ * Object value.
864
+ */
865
+ | 'object'
866
+ /**
867
+ * Array value.
868
+ */
869
+ | 'array'
870
+ /**
871
+ * Date value.
872
+ */
873
+ | 'date';
874
+ /**
875
+ * Composite schema types.
876
+ */
877
+ type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum';
878
+ /**
879
+ * Schema types that need special handling in generators.
880
+ */
881
+ type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'ipv4' | 'ipv6' | 'blob';
882
+ /**
883
+ * All schema type strings.
884
+ */
885
+ type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchemaType;
886
+ /**
887
+ * Scalar schema types without extra object/array/ref structure.
888
+ */
889
+ type ScalarSchemaType = Exclude<SchemaType, 'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint' | 'url' | 'uuid' | 'email'>;
890
+ /**
891
+ * Fields shared by all schema nodes.
892
+ */
893
+ type SchemaNodeBase = BaseNode & {
894
+ /**
895
+ * Node kind.
896
+ */
897
+ kind: 'Schema';
898
+ /**
899
+ * Schema name for named definitions (for example, `"Pet"`).
900
+ * Inline schemas omit this field.
901
+ * `null` means Kubb has processed this and determined there is no applicable name.
902
+ * `undefined` means the name has not been set yet.
903
+ */
904
+ name?: string | null;
905
+ /**
906
+ * Short schema title.
907
+ */
908
+ title?: string;
909
+ /**
910
+ * Schema description text.
911
+ */
912
+ description?: string;
913
+ /**
914
+ * Whether `null` is allowed.
915
+ */
916
+ nullable?: boolean;
917
+ /**
918
+ * Whether the field is optional.
919
+ */
920
+ optional?: boolean;
921
+ /**
922
+ * Both optional and nullable (`optional` + `nullable`).
923
+ */
924
+ nullish?: boolean;
925
+ /**
926
+ * Whether the schema is deprecated.
927
+ */
928
+ deprecated?: boolean;
929
+ /**
930
+ * Whether the schema is read-only.
931
+ */
932
+ readOnly?: boolean;
933
+ /**
934
+ * Whether the schema is write-only.
935
+ */
936
+ writeOnly?: boolean;
937
+ /**
938
+ * Default value.
939
+ */
940
+ default?: unknown;
941
+ /**
942
+ * Example values from an `examples` array.
943
+ */
944
+ examples?: Array<unknown>;
945
+ /**
946
+ * Base primitive type.
947
+ * For example, this is `'string'` for a `uuid` schema.
948
+ */
949
+ primitive?: PrimitiveSchemaType;
950
+ /**
951
+ * Schema `format` value.
952
+ */
953
+ format?: string;
954
+ };
955
+ /**
956
+ * Object schema with ordered properties.
957
+ *
958
+ * @example
959
+ * ```ts
960
+ * const objectSchema: ObjectSchemaNode = {
961
+ * kind: 'Schema',
962
+ * type: 'object',
963
+ * properties: [],
964
+ * }
965
+ * ```
966
+ */
967
+ type ObjectSchemaNode = SchemaNodeBase & {
968
+ /**
969
+ * Schema type discriminator.
970
+ */
971
+ type: 'object';
972
+ /**
973
+ * Primitive type, always `'object'` for object schemas.
974
+ */
975
+ primitive: 'object';
976
+ /**
977
+ * Ordered object properties.
978
+ */
979
+ properties: Array<PropertyNode>;
980
+ /**
981
+ * Additional object properties behavior:
982
+ * - `true`: allow any value
983
+ * - `false`: reject unknown properties
984
+ * - `SchemaNode`: allow values that match that schema
985
+ * - `undefined`: no additional properties constraint (open object)
986
+ */
987
+ additionalProperties?: SchemaNode | boolean;
988
+ /**
989
+ * Pattern-based property schemas.
990
+ */
991
+ patternProperties?: Record<string, SchemaNode>;
992
+ /**
993
+ * Minimum number of properties allowed.
994
+ */
995
+ minProperties?: number;
996
+ /**
997
+ * Maximum number of properties allowed.
998
+ */
999
+ maxProperties?: number;
1000
+ };
1001
+ /**
1002
+ * Array-like schema (`array` or `tuple`).
1003
+ *
1004
+ * @example
1005
+ * ```ts
1006
+ * const arraySchema: ArraySchemaNode = {
1007
+ * kind: 'Schema',
1008
+ * type: 'array',
1009
+ * items: [],
1010
+ * }
1011
+ * ```
1012
+ */
1013
+ type ArraySchemaNode = SchemaNodeBase & {
1014
+ /**
1015
+ * Schema type discriminator (`array` or `tuple`).
1016
+ */
1017
+ type: 'array' | 'tuple';
1018
+ /**
1019
+ * Item schemas.
1020
+ */
1021
+ items?: Array<SchemaNode>;
1022
+ /**
1023
+ * Tuple rest-item schema for elements beyond positional `items`.
1024
+ */
1025
+ rest?: SchemaNode;
1026
+ /**
1027
+ * Minimum item count (or tuple length).
1028
+ */
1029
+ min?: number;
1030
+ /**
1031
+ * Maximum item count (or tuple length).
1032
+ */
1033
+ max?: number;
1034
+ /**
1035
+ * Whether all items must be unique.
1036
+ */
1037
+ unique?: boolean;
1038
+ };
1039
+ /**
1040
+ * Shared shape for union and intersection schemas.
1041
+ */
1042
+ type CompositeSchemaNodeBase = SchemaNodeBase & {
1043
+ /**
1044
+ * Member schemas.
1045
+ */
1046
+ members?: Array<SchemaNode>;
1047
+ };
1048
+ /**
1049
+ * Union schema, often from `oneOf` or `anyOf`.
1050
+ *
1051
+ * @example
1052
+ * ```ts
1053
+ * const unionSchema: UnionSchemaNode = {
1054
+ * kind: 'Schema',
1055
+ * type: 'union',
1056
+ * members: [],
1057
+ * }
1058
+ * ```
1059
+ */
1060
+ type UnionSchemaNode = CompositeSchemaNodeBase & {
1061
+ /**
1062
+ * Schema type discriminator.
1063
+ */
1064
+ type: 'union';
1065
+ /**
1066
+ * Discriminator property name for a polymorphic union.
1067
+ */
1068
+ discriminatorPropertyName?: string;
1069
+ /**
1070
+ * How many union members must be valid.
1071
+ * - `'one'`: exactly one member, from `oneOf`
1072
+ * - `'any'`: any number of members, from `anyOf`
1073
+ */
1074
+ strategy?: 'one' | 'any';
1075
+ };
1076
+ /**
1077
+ * Intersection schema, often from `allOf`.
1078
+ *
1079
+ * @example
1080
+ * ```ts
1081
+ * const intersectionSchema: IntersectionSchemaNode = {
1082
+ * kind: 'Schema',
1083
+ * type: 'intersection',
1084
+ * members: [],
1085
+ * }
1086
+ * ```
1087
+ */
1088
+ type IntersectionSchemaNode = CompositeSchemaNodeBase & {
1089
+ /**
1090
+ * Schema type discriminator.
1091
+ */
1092
+ type: 'intersection';
1093
+ };
1094
+ /**
1095
+ * One named enum item.
1096
+ */
1097
+ type EnumValueNode = {
1098
+ /**
1099
+ * Enum item name.
1100
+ */
1101
+ name: string;
1102
+ /**
1103
+ * Enum item value.
1104
+ */
1105
+ value: string | number | boolean;
1106
+ /**
1107
+ * Primitive type of the enum value.
1108
+ */
1109
+ primitive: Extract<PrimitiveSchemaType, 'string' | 'number' | 'boolean'>;
1110
+ /**
1111
+ * Label for the enum item, taken from the `x-enumDescriptions` or
1112
+ * `x-enum-descriptions` vendor extension. `@kubb/plugin-ts` renders it as
1113
+ * JSDoc on the matching enum member.
1114
+ */
1115
+ description?: string;
1116
+ };
1117
+ /**
1118
+ * Enum schema node.
1119
+ *
1120
+ * @example
1121
+ * ```ts
1122
+ * const enumSchema: EnumSchemaNode = {
1123
+ * kind: 'Schema',
1124
+ * type: 'enum',
1125
+ * enumValues: ['a', 'b'],
1126
+ * }
1127
+ * ```
1128
+ */
1129
+ type EnumSchemaNode = SchemaNodeBase & {
1130
+ /**
1131
+ * Schema type discriminator.
1132
+ */
1133
+ type: 'enum';
1134
+ /**
1135
+ * Enum values in simple form.
1136
+ */
1137
+ enumValues?: Array<string | number | boolean | null>;
1138
+ /**
1139
+ * Enum values in named form.
1140
+ * If present, this is used instead of `enumValues`.
1141
+ */
1142
+ namedEnumValues?: Array<EnumValueNode>;
1143
+ };
1144
+ /**
1145
+ * Reference schema that points to another schema definition.
1146
+ *
1147
+ * @example
1148
+ * ```ts
1149
+ * const refSchema: RefSchemaNode = {
1150
+ * kind: 'Schema',
1151
+ * type: 'ref',
1152
+ * ref: '#/components/schemas/Pet',
1153
+ * }
1154
+ * ```
1155
+ */
1156
+ type RefSchemaNode = SchemaNodeBase & {
1157
+ /**
1158
+ * Schema type discriminator.
1159
+ */
1160
+ type: 'ref';
1161
+ /**
1162
+ * Referenced schema name.
1163
+ * `null` means Kubb has processed this and determined there is no applicable name.
1164
+ */
1165
+ name?: string | null;
1166
+ /**
1167
+ * Original `$ref` path, for example, `#/components/schemas/Order`.
1168
+ * Used to resolve names later.
1169
+ */
1170
+ ref?: string;
1171
+ /**
1172
+ * Pattern copied from a sibling `pattern` field.
1173
+ */
1174
+ pattern?: string;
1175
+ /**
1176
+ * The fully-parsed schema this ref resolves to, so its structure (`primitive`, `properties`)
1177
+ * can be read without following the reference. Populated during parsing when the
1178
+ * definition resolves, `null` when it can't or the ref is circular, and `undefined` when
1179
+ * resolution has not been attempted.
1180
+ */
1181
+ schema?: SchemaNode | null;
1182
+ };
1183
+ /**
1184
+ * Datetime schema.
1185
+ *
1186
+ * @example
1187
+ * ```ts
1188
+ * const datetimeSchema: DatetimeSchemaNode = { kind: 'Schema', type: 'datetime' }
1189
+ * ```
1190
+ */
1191
+ type DatetimeSchemaNode = SchemaNodeBase & {
1192
+ /**
1193
+ * Schema type discriminator.
1194
+ */
1195
+ type: 'datetime';
1196
+ /**
1197
+ * Whether the datetime includes a timezone offset (`dateType: 'stringOffset'`).
1198
+ */
1199
+ offset?: boolean;
1200
+ /**
1201
+ * Whether the datetime is local (no timezone, `dateType: 'stringLocal'`).
1202
+ */
1203
+ local?: boolean;
1204
+ };
1205
+ /**
1206
+ * Shared base for `date` and `time` schemas.
1207
+ */
1208
+ type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
1209
+ /**
1210
+ * Schema type discriminator.
1211
+ */
1212
+ type: T;
1213
+ /**
1214
+ * Output representation in generated code.
1215
+ */
1216
+ representation: 'date' | 'string';
1217
+ };
1218
+ /**
1219
+ * Date schema node.
1220
+ *
1221
+ * @example
1222
+ * ```ts
1223
+ * const dateSchema: DateSchemaNode = { kind: 'Schema', type: 'date', representation: 'string' }
1224
+ * ```
1225
+ */
1226
+ type DateSchemaNode = TemporalSchemaNodeBase<'date'>;
1227
+ /**
1228
+ * Time schema node.
1229
+ *
1230
+ * @example
1231
+ * ```ts
1232
+ * const timeSchema: TimeSchemaNode = { kind: 'Schema', type: 'time', representation: 'string' }
1233
+ * ```
1234
+ */
1235
+ type TimeSchemaNode = TemporalSchemaNodeBase<'time'>;
1236
+ /**
1237
+ * String schema node.
1238
+ *
1239
+ * @example
1240
+ * ```ts
1241
+ * const stringSchema: StringSchemaNode = { kind: 'Schema', type: 'string' }
1242
+ * ```
1243
+ */
1244
+ type StringSchemaNode = SchemaNodeBase & {
1245
+ /**
1246
+ * Schema type discriminator.
1247
+ */
1248
+ type: 'string';
1249
+ /**
1250
+ * Minimum string length.
1251
+ */
1252
+ min?: number;
1253
+ /**
1254
+ * Maximum string length.
1255
+ */
1256
+ max?: number;
1257
+ /**
1258
+ * Regex pattern.
1259
+ */
1260
+ pattern?: string;
1261
+ };
1262
+ /**
1263
+ * Numeric schema (`number`, `integer`, or `bigint`).
1264
+ *
1265
+ * @example
1266
+ * ```ts
1267
+ * const numberSchema: NumberSchemaNode = { kind: 'Schema', type: 'number' }
1268
+ * ```
1269
+ */
1270
+ type NumberSchemaNode = SchemaNodeBase & {
1271
+ /**
1272
+ * Schema type discriminator.
1273
+ */
1274
+ type: 'number' | 'integer' | 'bigint';
1275
+ /**
1276
+ * Minimum value.
1277
+ */
1278
+ min?: number;
1279
+ /**
1280
+ * Maximum value.
1281
+ */
1282
+ max?: number;
1283
+ /**
1284
+ * Exclusive minimum value.
1285
+ */
1286
+ exclusiveMinimum?: number;
1287
+ /**
1288
+ * Exclusive maximum value.
1289
+ */
1290
+ exclusiveMaximum?: number;
1291
+ /**
1292
+ * The value must be a multiple of this number.
1293
+ */
1294
+ multipleOf?: number;
1295
+ };
1296
+ /**
1297
+ * Scalar schema with no extra constraints.
1298
+ *
1299
+ * @example
1300
+ * ```ts
1301
+ * const anySchema: ScalarSchemaNode = { kind: 'Schema', type: 'any' }
1302
+ * ```
1303
+ */
1304
+ type ScalarSchemaNode = SchemaNodeBase & {
1305
+ /**
1306
+ * Schema type discriminator.
1307
+ */
1308
+ type: ScalarSchemaType;
1309
+ };
1310
+ /**
1311
+ * URL schema node.
1312
+ * Can include a path template for template literal types.
1313
+ *
1314
+ * @example
1315
+ * ```ts
1316
+ * const urlSchema: UrlSchemaNode = { kind: 'Schema', type: 'url', path: '/pets/{petId}' }
1317
+ * ```
1318
+ */
1319
+ type UrlSchemaNode = SchemaNodeBase & {
1320
+ /**
1321
+ * Schema type discriminator.
1322
+ */
1323
+ type: 'url';
1324
+ /**
1325
+ * Path template, for example, `'/pets/{petId}'`.
1326
+ */
1327
+ path?: string;
1328
+ /**
1329
+ * Minimum string length.
1330
+ */
1331
+ min?: number;
1332
+ /**
1333
+ * Maximum string length.
1334
+ */
1335
+ max?: number;
1336
+ };
1337
+ /**
1338
+ * Format-string schema for string-based formats that support length constraints.
1339
+ *
1340
+ * @example
1341
+ * ```ts
1342
+ * const uuidSchema: FormatStringSchemaNode = { kind: 'Schema', type: 'uuid', min: 36, max: 36 }
1343
+ * ```
1344
+ */
1345
+ type FormatStringSchemaNode = SchemaNodeBase & {
1346
+ /**
1347
+ * Schema type discriminator.
1348
+ */
1349
+ type: 'uuid' | 'email';
1350
+ /**
1351
+ * Minimum string length.
1352
+ */
1353
+ min?: number;
1354
+ /**
1355
+ * Maximum string length.
1356
+ */
1357
+ max?: number;
1358
+ };
1359
+ /**
1360
+ * IPv4 address schema node.
1361
+ *
1362
+ * @example
1363
+ * ```ts
1364
+ * const ipv4Schema: Ipv4SchemaNode = { kind: 'Schema', type: 'ipv4' }
1365
+ * ```
1366
+ */
1367
+ type Ipv4SchemaNode = SchemaNodeBase & {
1368
+ /**
1369
+ * Schema type discriminator.
1370
+ */
1371
+ type: 'ipv4';
1372
+ };
1373
+ /**
1374
+ * IPv6 address schema node.
1375
+ *
1376
+ * @example
1377
+ * ```ts
1378
+ * const ipv6Schema: Ipv6SchemaNode = { kind: 'Schema', type: 'ipv6' }
1379
+ * ```
1380
+ */
1381
+ type Ipv6SchemaNode = SchemaNodeBase & {
1382
+ /**
1383
+ * Schema type discriminator.
1384
+ */
1385
+ type: 'ipv6';
1386
+ };
1387
+ /**
1388
+ * Mapping from schema type literals to concrete schema node types.
1389
+ * Used by `narrowSchema`.
1390
+ */
1391
+ type SchemaNodeByType = {
1392
+ object: ObjectSchemaNode;
1393
+ array: ArraySchemaNode;
1394
+ tuple: ArraySchemaNode;
1395
+ union: UnionSchemaNode;
1396
+ intersection: IntersectionSchemaNode;
1397
+ enum: EnumSchemaNode;
1398
+ ref: RefSchemaNode;
1399
+ datetime: DatetimeSchemaNode;
1400
+ date: DateSchemaNode;
1401
+ time: TimeSchemaNode;
1402
+ string: StringSchemaNode;
1403
+ number: NumberSchemaNode;
1404
+ integer: NumberSchemaNode;
1405
+ bigint: NumberSchemaNode;
1406
+ boolean: ScalarSchemaNode;
1407
+ null: ScalarSchemaNode;
1408
+ any: ScalarSchemaNode;
1409
+ unknown: ScalarSchemaNode;
1410
+ void: ScalarSchemaNode;
1411
+ never: ScalarSchemaNode;
1412
+ uuid: FormatStringSchemaNode;
1413
+ email: FormatStringSchemaNode;
1414
+ url: UrlSchemaNode;
1415
+ ipv4: Ipv4SchemaNode;
1416
+ ipv6: Ipv6SchemaNode;
1417
+ blob: ScalarSchemaNode;
1418
+ };
1419
+ /**
1420
+ * Union of all schema node types.
1421
+ */
1422
+ type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | FormatStringSchemaNode | Ipv4SchemaNode | Ipv6SchemaNode | ScalarSchemaNode;
1423
+ type CreateSchemaObjectInput = Omit<ObjectSchemaNode, 'kind' | 'properties' | 'primitive'> & {
1424
+ properties?: Array<PropertyNode>;
1425
+ primitive?: 'object';
1426
+ };
1427
+ type CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>;
1428
+ type CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {
1429
+ kind: 'Schema';
1430
+ };
1431
+ /**
1432
+ * Definition for the {@link SchemaNode}. Object schemas default `properties` to an
1433
+ * empty array, and `primitive` is inferred from `type` when not explicitly provided.
1434
+ */
1435
+ declare const schemaDef: NodeDef<SchemaNode, CreateSchemaInput>;
1436
+ /**
1437
+ * Creates a `SchemaNode`, narrowed to the variant of `props.type`.
1438
+ *
1439
+ * @example
1440
+ * ```ts
1441
+ * const scalar = createSchema({ type: 'string' })
1442
+ * // { kind: 'Schema', type: 'string', primitive: 'string' }
1443
+ * ```
1444
+ *
1445
+ * @example
1446
+ * ```ts
1447
+ * const object = createSchema({ type: 'object' })
1448
+ * // { kind: 'Schema', type: 'object', primitive: 'object', properties: [] }
1449
+ * ```
1450
+ */
1451
+ declare function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>;
1452
+ declare function createSchema(props: CreateSchemaInput): SchemaNode;
1453
+ //#endregion
1454
+ //#region src/nodes/content.d.ts
1455
+ /**
1456
+ * AST node representing one content-type entry of a request body or response.
1457
+ *
1458
+ * There is one entry per content type declared in the spec (e.g. `application/json`,
1459
+ * `multipart/form-data`), and each entry holds its own body schema.
1460
+ *
1461
+ * @example
1462
+ * ```ts
1463
+ * const content: ContentNode = {
1464
+ * kind: 'Content',
1465
+ * contentType: 'application/json',
1466
+ * schema: createSchema({ type: 'string' }),
1467
+ * }
1468
+ * ```
1469
+ */
1470
+ type ContentNode = BaseNode & {
1471
+ /**
1472
+ * Node kind.
1473
+ */
1474
+ kind: 'Content';
1475
+ /**
1476
+ * The content type for this entry (e.g. `'application/json'`).
1477
+ */
1478
+ contentType: string;
1479
+ /**
1480
+ * Body schema for this content type.
1481
+ */
1482
+ schema?: SchemaNode;
1483
+ /**
1484
+ * Property keys to exclude from the generated type via `Omit<Type, Keys>`.
1485
+ * Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.
1486
+ */
1487
+ keysToOmit?: Array<string> | null;
1488
+ };
1489
+ /**
1490
+ * Definition for the {@link ContentNode}.
1491
+ */
1492
+ declare const contentDef: NodeDef<ContentNode, Omit<ContentNode, "kind">>;
1493
+ /**
1494
+ * Creates a `ContentNode` for a single request-body or response content type.
1495
+ */
1496
+ declare const createContent: (input: Omit<ContentNode, "kind">) => ContentNode;
1497
+ //#endregion
1498
+ //#region src/nodes/file.d.ts
1499
+ /**
1500
+ * Supported file extensions.
1501
+ */
1502
+ type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
1503
+ type ImportName = string | Array<string | {
1504
+ propertyName: string;
1505
+ name?: string;
1506
+ }>;
1507
+ /**
1508
+ * Represents a language-agnostic import/dependency declaration.
1509
+ *
1510
+ * @example Named import (TypeScript: `import { useState } from 'react'`)
1511
+ * ```ts
1512
+ * createImport({ name: ['useState'], path: 'react' })
1513
+ * ```
1514
+ *
1515
+ * @example Default import (TypeScript: `import React from 'react'`)
1516
+ * ```ts
1517
+ * createImport({ name: 'React', path: 'react' })
1518
+ * ```
1519
+ *
1520
+ * @example Type-only import (TypeScript: `import type { FC } from 'react'`)
1521
+ * ```ts
1522
+ * createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
1523
+ * ```
1524
+ *
1525
+ * @example Namespace import (TypeScript: `import * as React from 'react'`)
1526
+ * ```ts
1527
+ * createImport({ name: 'React', path: 'react', isNameSpace: true })
1528
+ * ```
1529
+ */
1530
+ type ImportNode = BaseNode & {
1531
+ kind: 'Import';
1532
+ /**
1533
+ * Import name(s) to be used.
1534
+ *
1535
+ * @example Named imports
1536
+ * `['useState']`
1537
+ *
1538
+ * @example Default import
1539
+ * `'React'`
1540
+ */
1541
+ name: ImportName;
1542
+ /**
1543
+ * Path for the import.
1544
+ *
1545
+ * @example
1546
+ * `'@kubb/core'`
1547
+ */
1548
+ path: string;
1549
+ /**
1550
+ * Add a type-only import prefix.
1551
+ * - `true` generates `import type { Type } from './path'`
1552
+ * - `false` generates `import { Type } from './path'`
1553
+ */
1554
+ isTypeOnly?: boolean | null;
1555
+ /**
1556
+ * Import the entire module as a namespace.
1557
+ * - `true` generates `import * as Name from './path'`
1558
+ * - `false` generates a standard import
1559
+ */
1560
+ isNameSpace?: boolean | null;
1561
+ /**
1562
+ * When set, the import path is resolved relative to this root.
1563
+ */
1564
+ root?: string | null;
1565
+ };
1566
+ /**
1567
+ * Represents a language-agnostic export/public API declaration.
1568
+ *
1569
+ * @example Named export (TypeScript: `export { Pets } from './Pets'`)
1570
+ * ```ts
1571
+ * createExport({ name: ['Pets'], path: './Pets' })
1572
+ * ```
1573
+ *
1574
+ * @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
1575
+ * ```ts
1576
+ * createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })
1577
+ * ```
1578
+ *
1579
+ * @example Wildcard export (TypeScript: `export * from './utils'`)
1580
+ * ```ts
1581
+ * createExport({ path: './utils' })
1582
+ * ```
1583
+ *
1584
+ * @example Namespace alias (TypeScript: `export * as utils from './utils'`)
1585
+ * ```ts
1586
+ * createExport({ name: 'utils', path: './utils', asAlias: true })
1587
+ * ```
1588
+ */
1589
+ type ExportNode = BaseNode & {
1590
+ kind: 'Export';
1591
+ /**
1592
+ * Export name(s) to be used. When omitted, generates a wildcard export.
1593
+ *
1594
+ * @example Named exports
1595
+ * `['useState']`
1596
+ *
1597
+ * @example Single export
1598
+ * `'React'`
1599
+ */
1600
+ name?: string | Array<string> | null;
1601
+ /**
1602
+ * Path for the export.
1603
+ *
1604
+ * @example
1605
+ * `'@kubb/core'`
1606
+ */
1607
+ path: string;
1608
+ /**
1609
+ * Add a type-only export prefix.
1610
+ * - `true` generates `export type { Type } from './path'`
1611
+ * - `false` generates `export { Type } from './path'`
1612
+ */
1613
+ isTypeOnly?: boolean | null;
1614
+ /**
1615
+ * Export as an aliased namespace.
1616
+ * - `true` generates `export * as aliasName from './path'`
1617
+ * - `false` generates a standard export
1618
+ */
1619
+ asAlias?: boolean | null;
1620
+ };
1621
+ /**
1622
+ * Represents a fragment of source code within a file.
1623
+ *
1624
+ * @example Named exportable source
1625
+ * ```ts
1626
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })
1627
+ * ```
1628
+ *
1629
+ * @example Inline unnamed code block
1630
+ * ```ts
1631
+ * createSource({ nodes: [createText('const x = 1')] })
1632
+ * ```
1633
+ */
1634
+ type SourceNode = BaseNode & {
1635
+ kind: 'Source';
1636
+ /**
1637
+ * Optional name identifying this source (used for deduplication and barrel generation).
1638
+ */
1639
+ name?: string | null;
1640
+ /**
1641
+ * Mark this source as a type-only export.
1642
+ */
1643
+ isTypeOnly?: boolean | null;
1644
+ /**
1645
+ * Include the `export` keyword in the generated source.
1646
+ */
1647
+ isExportable?: boolean | null;
1648
+ /**
1649
+ * Include this source in barrel/index file generation.
1650
+ */
1651
+ isIndexable?: boolean | null;
1652
+ /**
1653
+ * Child nodes that make up this source fragment, in DOM order.
1654
+ * Use a {@link TextNode} for raw string content.
1655
+ */
1656
+ nodes?: Array<CodeNode>;
1657
+ };
1658
+ /**
1659
+ * Represents a fully resolved file in the AST.
1660
+ *
1661
+ * Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input
1662
+ * and deduplicates `imports`, `exports`, and `sources`.
1663
+ *
1664
+ * @example
1665
+ * ```ts
1666
+ * const file = createFile({
1667
+ * baseName: 'petStore.ts',
1668
+ * path: 'src/models/petStore.ts',
1669
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })],
1670
+ * imports: [createImport({ name: ['z'], path: 'zod' })],
1671
+ * exports: [createExport({ name: ['Pet'], path: './petStore' })],
1672
+ * })
1673
+ * // file.id = SHA256 hash of the path
1674
+ * // file.name = 'petStore'
1675
+ * // file.extname = '.ts'
1676
+ * ```
1677
+ */
1678
+ type FileNode<TMeta extends object = object> = BaseNode & {
1679
+ kind: 'File';
1680
+ /**
1681
+ * Unique identifier derived from a SHA256 hash of the file path. `createFile`
1682
+ * computes it, so callers do not need to provide it.
1683
+ */
1684
+ id: string;
1685
+ /**
1686
+ * File name without extension, derived from `baseName`.
1687
+ *
1688
+ * @see https://nodejs.org/api/path.html#pathformatpathobject
1689
+ */
1690
+ name: string;
1691
+ /**
1692
+ * File base name, including extension, shaped like `${name}${extname}`.
1693
+ *
1694
+ * @see https://nodejs.org/api/path.html#pathbasenamepath-suffix
1695
+ */
1696
+ baseName: `${string}.${string}`;
1697
+ /**
1698
+ * Full qualified path to the file.
1699
+ */
1700
+ path: string;
1701
+ /**
1702
+ * File extension extracted from `baseName`.
1703
+ */
1704
+ extname: Extname;
1705
+ /**
1706
+ * Deduplicated list of source code fragments.
1707
+ */
1708
+ sources: Array<SourceNode>;
1709
+ /**
1710
+ * Deduplicated list of import declarations.
1711
+ */
1712
+ imports: Array<ImportNode>;
1713
+ /**
1714
+ * Deduplicated list of export declarations.
1715
+ */
1716
+ exports: Array<ExportNode>;
1717
+ /**
1718
+ * Optional metadata attached to this file, read by plugins during barrel generation.
1719
+ */
1720
+ meta?: TMeta;
1721
+ /**
1722
+ * Optional banner prepended to the generated file content.
1723
+ * Accepts `null` so `resolver.default.banner()` results can be passed directly.
1724
+ */
1725
+ banner?: string | null;
1726
+ /**
1727
+ * Optional footer appended to the generated file content.
1728
+ * Accepts `null` so `resolver.default.footer()` results can be passed directly.
1729
+ */
1730
+ footer?: string | null;
1731
+ /**
1732
+ * Absolute on-disk path to copy verbatim into the output, bypassing the parser.
1733
+ *
1734
+ * Use to emit a real source file shipped inside a package (a template) into the generated
1735
+ * folder without reformatting or import reordering. Only `banner` and `footer` are applied
1736
+ * around the copied content. When set, `copy` provides the file content and any `sources`
1737
+ * nodes are ignored for output; `sources` may still carry `name`/`isExportable`/`isIndexable`
1738
+ * so barrel generation treats the file the same as a rendered one.
1739
+ */
1740
+ copy?: string | null;
1741
+ };
1742
+ /**
1743
+ * Definition for the {@link ImportNode}.
1744
+ */
1745
+ declare const importDef: NodeDef<ImportNode, Omit<ImportNode, "kind">>;
1746
+ /**
1747
+ * Definition for the {@link ExportNode}.
1748
+ */
1749
+ declare const exportDef: NodeDef<ExportNode, Omit<ExportNode, "kind">>;
1750
+ /**
1751
+ * Definition for the {@link SourceNode}.
1752
+ */
1753
+ declare const sourceDef: NodeDef<SourceNode, Omit<SourceNode, "kind">>;
1754
+ /**
1755
+ * Definition for the {@link FileNode}. The fully resolved builder lives in
1756
+ * `createFile`, so this definition only supplies the guard.
1757
+ */
1758
+ declare const fileDef: NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>;
1759
+ /**
1760
+ * Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
1761
+ *
1762
+ * @example Named import
1763
+ * ```ts
1764
+ * createImport({ name: ['useState'], path: 'react' })
1765
+ * // import { useState } from 'react'
1766
+ * ```
1767
+ */
1768
+ declare const createImport: (input: Omit<ImportNode, "kind">) => ImportNode;
1769
+ /**
1770
+ * Creates an `ExportNode` representing a language-agnostic export/public API declaration.
1771
+ *
1772
+ * @example Named export
1773
+ * ```ts
1774
+ * createExport({ name: ['Pet'], path: './Pet' })
1775
+ * // export { Pet } from './Pet'
1776
+ * ```
1777
+ */
1778
+ declare const createExport: (input: Omit<ExportNode, "kind">) => ExportNode;
1779
+ /**
1780
+ * Creates a `SourceNode` representing a fragment of source code within a file.
1781
+ *
1782
+ * @example
1783
+ * ```ts
1784
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
1785
+ * ```
1786
+ */
1787
+ declare const createSource: (input: Omit<SourceNode, "kind">) => SourceNode;
1788
+ /**
1789
+ * Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed
1790
+ * and `imports`/`exports`/`sources` are deduplicated.
1791
+ */
1792
+ type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> & Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>;
1793
+ /**
1794
+ * Creates a fully resolved `FileNode` from a file input descriptor.
1795
+ *
1796
+ * Computes:
1797
+ * - `id` SHA256 hash of the file path
1798
+ * - `name` `baseName` without extension
1799
+ * - `extname` extension extracted from `baseName`
1800
+ *
1801
+ * Deduplicates:
1802
+ * - `sources` via `combineSources`
1803
+ * - `exports` via `combineExports`
1804
+ * - `imports` via `combineImports` (also filters unused imports)
1805
+ *
1806
+ * @throws {Error} when `baseName` has no extension.
1807
+ *
1808
+ * @example
1809
+ * ```ts
1810
+ * const file = createFile({
1811
+ * baseName: 'petStore.ts',
1812
+ * path: 'src/models/petStore.ts',
1813
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
1814
+ * imports: [createImport({ name: ['z'], path: 'zod' })],
1815
+ * exports: [createExport({ name: ['Pet'], path: './petStore' })],
1816
+ * })
1817
+ * // file.id = SHA256 hash of 'src/models/petStore.ts'
1818
+ * // file.name = 'petStore'
1819
+ * // file.extname = '.ts'
1820
+ * ```
1821
+ *
1822
+ * @example Copy a real file into the output verbatim
1823
+ * ```ts
1824
+ * const file = createFile({
1825
+ * baseName: 'client.ts',
1826
+ * path: 'src/gen/client.ts',
1827
+ * copy: '/abs/path/to/templates/client.ts',
1828
+ * })
1829
+ * ```
1830
+ */
1831
+ declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
1832
+ //#endregion
1833
+ //#region src/nodes/parameter.d.ts
1834
+ type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
1835
+ /**
1836
+ * Parameter serialization style, controlling how a parameter value is rendered into the request.
1837
+ */
1838
+ type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
1839
+ /**
1840
+ * AST node representing one operation parameter.
1841
+ *
1842
+ * @example
1843
+ * ```ts
1844
+ * const param: ParameterNode = {
1845
+ * kind: 'Parameter',
1846
+ * name: 'petId',
1847
+ * in: 'path',
1848
+ * schema: createSchema({ type: 'string' }),
1849
+ * required: true,
1850
+ * }
1851
+ * ```
1852
+ */
1853
+ type ParameterNode = BaseNode & {
1854
+ kind: 'Parameter';
1855
+ /**
1856
+ * Parameter name.
1857
+ */
1858
+ name: string;
1859
+ /**
1860
+ * Parameter location (`path`, `query`, `header`, or `cookie`).
1861
+ */
1862
+ in: ParameterLocation;
1863
+ /**
1864
+ * Parameter schema.
1865
+ */
1866
+ schema: SchemaNode;
1867
+ /**
1868
+ * Whether the parameter is required.
1869
+ */
1870
+ required: boolean;
1871
+ /**
1872
+ * Serialization style. Absent when the source omits it, leaving consumers to apply the
1873
+ * per-location default.
1874
+ */
1875
+ style?: ParameterStyle;
1876
+ /**
1877
+ * Whether array and object values expand into separate values. Absent when the source omits it,
1878
+ * leaving consumers to apply the default for the style.
1879
+ */
1880
+ explode?: boolean;
1881
+ };
1882
+ type UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>;
1883
+ /**
1884
+ * Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's
1885
+ * `optional`/`nullish` flags are derived from it through {@link optionality}.
1886
+ */
1887
+ declare const parameterDef: NodeDef<ParameterNode, UserParameterNode>;
1888
+ /**
1889
+ * Creates a `ParameterNode`.
1890
+ *
1891
+ * @example
1892
+ * ```ts
1893
+ * const param = createParameter({
1894
+ * name: 'petId',
1895
+ * in: 'path',
1896
+ * required: true,
1897
+ * schema: createSchema({ type: 'string' }),
1898
+ * })
1899
+ * ```
1900
+ */
1901
+ declare const createParameter: (input: UserParameterNode) => ParameterNode;
1902
+ //#endregion
1903
+ //#region src/nodes/requestBody.d.ts
1904
+ /**
1905
+ * AST node representing an operation request body.
1906
+ *
1907
+ * Body schemas live exclusively inside the `content` array (one entry per content type),
1908
+ * mirroring {@link ResponseNode}.
1909
+ *
1910
+ * @example
1911
+ * ```ts
1912
+ * const requestBody: RequestBodyNode = {
1913
+ * kind: 'RequestBody',
1914
+ * required: true,
1915
+ * content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
1916
+ * }
1917
+ * ```
1918
+ */
1919
+ type RequestBodyNode = BaseNode & {
1920
+ kind: 'RequestBody';
1921
+ /**
1922
+ * Request body description carried over from the spec.
1923
+ */
1924
+ description?: string;
1925
+ /**
1926
+ * Whether the request body is required (`requestBody.required: true` in the spec).
1927
+ * When `false` or absent, the generated `data` parameter should be optional.
1928
+ */
1929
+ required?: boolean;
1930
+ /**
1931
+ * Content type entries for this request body.
1932
+ *
1933
+ * When the adapter `contentType` option is set, this array contains exactly one entry for
1934
+ * that content type. Otherwise it contains one entry per content type declared in the spec,
1935
+ * so plugins can generate code for every variant (for example, separate hooks for
1936
+ * `application/json` and `multipart/form-data`).
1937
+ */
1938
+ content?: Array<ContentNode>;
1939
+ };
1940
+ /**
1941
+ * Definition for the {@link RequestBodyNode}. Content entries are built upfront with
1942
+ * {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes.
1943
+ */
1944
+ declare const requestBodyDef: NodeDef<RequestBodyNode, Omit<RequestBodyNode, "kind">>;
1945
+ /**
1946
+ * Creates a `RequestBodyNode`.
1947
+ */
1948
+ declare const createRequestBody: (input: Omit<RequestBodyNode, "kind">) => RequestBodyNode;
1949
+ //#endregion
1950
+ //#region src/nodes/response.d.ts
1951
+ /**
1952
+ * All supported HTTP status code literals as strings, as used in API specs
1953
+ * (for example, `"200"` and `"404"`).
1954
+ */
1955
+ type HttpStatusCode = '100' | '101' | '102' | '103' | '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226' | '300' | '301' | '302' | '303' | '304' | '305' | '307' | '308' | '400' | '401' | '402' | '403' | '404' | '405' | '406' | '407' | '408' | '409' | '410' | '411' | '412' | '413' | '414' | '415' | '416' | '417' | '418' | '421' | '422' | '423' | '424' | '425' | '426' | '428' | '429' | '431' | '451' | '500' | '501' | '502' | '503' | '504' | '505' | '506' | '507' | '508' | '510' | '511';
1956
+ /**
1957
+ * Response status code literal used by operations.
1958
+ *
1959
+ * Includes specific HTTP status code strings and `"default"` for catch-all responses.
1960
+ *
1961
+ * @example
1962
+ * ```ts
1963
+ * const status: StatusCode = '200'
1964
+ * const fallback: StatusCode = 'default'
1965
+ * ```
1966
+ */
1967
+ type StatusCode = HttpStatusCode | 'default';
1968
+ /**
1969
+ * AST node representing one operation response variant.
1970
+ *
1971
+ * Mirrors {@link OperationNode.requestBody}: the response body schemas live exclusively inside
1972
+ * the `content` array (one entry per content type), so the same schema is never duplicated at the
1973
+ * node root and inside `content`.
1974
+ *
1975
+ * @example
1976
+ * ```ts
1977
+ * const response: ResponseNode = {
1978
+ * kind: 'Response',
1979
+ * statusCode: '200',
1980
+ * content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
1981
+ * }
1982
+ * ```
1983
+ */
1984
+ type ResponseNode = BaseNode & {
1985
+ /**
1986
+ * Node kind.
1987
+ */
1988
+ kind: 'Response';
1989
+ /**
1990
+ * HTTP status code or `'default'` for a fallback response.
1991
+ */
1992
+ statusCode: StatusCode;
1993
+ /**
1994
+ * Optional response description.
1995
+ */
1996
+ description?: string;
1997
+ /**
1998
+ * All available content type entries for this response.
1999
+ *
2000
+ * When the adapter `contentType` option is set, this array contains exactly one entry for that
2001
+ * content type. Otherwise it contains one entry per content type declared in the spec, so that
2002
+ * plugins can generate a union of response types (e.g. `application/json` and `application/xml`).
2003
+ * Body-less responses keep a single entry whose `schema` is the empty/`void` placeholder.
2004
+ *
2005
+ * @example
2006
+ * ```ts
2007
+ * // spec response declares both application/json and application/xml
2008
+ * response.content[0].contentType // 'application/json'
2009
+ * response.content[1].contentType // 'application/xml'
2010
+ * ```
2011
+ */
2012
+ content?: Array<ContentNode>;
2013
+ };
2014
+ type ResponseInput = Pick<ResponseNode, 'statusCode'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'content'>> & {
2015
+ content?: Array<ContentNode>;
2016
+ schema?: SchemaNode;
2017
+ mediaType?: string | null;
2018
+ keysToOmit?: Array<string> | null;
2019
+ };
2020
+ /**
2021
+ * Definition for the {@link ResponseNode}. A single legacy `schema` (with optional
2022
+ * `mediaType`/`keysToOmit`) is normalized into one `content` entry.
2023
+ */
2024
+ declare const responseDef: NodeDef<ResponseNode, ResponseInput>;
2025
+ /**
2026
+ * Creates a `ResponseNode`.
2027
+ *
2028
+ * @example
2029
+ * ```ts
2030
+ * const response = createResponse({
2031
+ * statusCode: '200',
2032
+ * content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })],
2033
+ * })
2034
+ * ```
2035
+ */
2036
+ declare const createResponse: (input: ResponseInput) => ResponseNode;
2037
+ //#endregion
2038
+ //#region src/nodes/operation.d.ts
2039
+ /**
2040
+ * HTTP method an operation responds to.
2041
+ */
2042
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
2043
+ /**
2044
+ * Transport an operation belongs to.
2045
+ */
2046
+ type OperationProtocol = 'http';
2047
+ /**
2048
+ * Fields shared by every operation, regardless of transport.
2049
+ */
2050
+ type OperationNodeBase = BaseNode & {
2051
+ /**
2052
+ * Node kind.
2053
+ */
2054
+ kind: 'Operation';
2055
+ /**
2056
+ * Stable identifier for the operation.
2057
+ */
2058
+ operationId: string;
2059
+ /**
2060
+ * Group labels for the operation.
2061
+ */
2062
+ tags: Array<string>;
2063
+ /**
2064
+ * Short one-line operation summary.
2065
+ */
2066
+ summary?: string;
2067
+ /**
2068
+ * Full operation description.
2069
+ */
2070
+ description?: string;
2071
+ /**
2072
+ * Marks the operation as deprecated.
2073
+ */
2074
+ deprecated?: boolean;
2075
+ /**
2076
+ * Query, path, header, and cookie parameters for the operation.
2077
+ */
2078
+ parameters: Array<ParameterNode>;
2079
+ /**
2080
+ * Request body for the operation.
2081
+ */
2082
+ requestBody?: RequestBodyNode;
2083
+ /**
2084
+ * Operation responses.
2085
+ */
2086
+ responses: Array<ResponseNode>;
2087
+ };
2088
+ /**
2089
+ * Operation served over HTTP. `method` and `path` are guaranteed.
2090
+ *
2091
+ * @example
2092
+ * ```ts
2093
+ * const operation: HttpOperationNode = {
2094
+ * kind: 'Operation',
2095
+ * operationId: 'listPets',
2096
+ * protocol: 'http',
2097
+ * method: 'GET',
2098
+ * path: '/pets',
2099
+ * tags: [],
2100
+ * parameters: [],
2101
+ * responses: [],
2102
+ * }
2103
+ * ```
2104
+ */
2105
+ type HttpOperationNode = OperationNodeBase & {
2106
+ /**
2107
+ * Transport the operation belongs to.
2108
+ */
2109
+ protocol?: 'http';
2110
+ /**
2111
+ * HTTP method like `'GET'`.
2112
+ */
2113
+ method: HttpMethod;
2114
+ /**
2115
+ * Path string, for example `/pets/{petId}`, with `{param}` notation preserved.
2116
+ */
2117
+ path: string;
2118
+ };
2119
+ /**
2120
+ * Operation for a non-HTTP transport. HTTP-only fields are forbidden.
2121
+ */
2122
+ type GenericOperationNode = OperationNodeBase & {
2123
+ /**
2124
+ * Transport the operation belongs to.
2125
+ */
2126
+ protocol?: Exclude<OperationProtocol, 'http'>;
2127
+ method?: never;
2128
+ path?: never;
2129
+ };
2130
+ /**
2131
+ * AST node representing one API operation.
2132
+ *
2133
+ * Discriminated on `protocol`: an {@link HttpOperationNode} (`protocol: 'http'`) guarantees
2134
+ * `method` and `path`, while a {@link GenericOperationNode} omits them. Narrow with
2135
+ * `isHttpOperationNode(node)` or `node.protocol === 'http'` before reading `method`/`path`.
2136
+ */
2137
+ type OperationNode = HttpOperationNode | GenericOperationNode;
2138
+ type OperationInput = {
2139
+ operationId: string;
2140
+ method?: HttpOperationNode['method'];
2141
+ path?: HttpOperationNode['path'];
2142
+ requestBody?: Omit<RequestBodyNode, 'kind'>;
2143
+ [key: string]: unknown;
2144
+ };
2145
+ /**
2146
+ * Definition for the {@link OperationNode}. HTTP operations (those carrying both
2147
+ * `method` and `path`) are tagged with `protocol: 'http'`, and the request body is
2148
+ * normalized into a `RequestBodyNode`.
2149
+ */
2150
+ declare const operationDef: NodeDef<OperationNode, OperationInput>;
2151
+ /**
2152
+ * Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.
2153
+ *
2154
+ * @example
2155
+ * ```ts
2156
+ * const operation = createOperation({ operationId: 'getPetById', method: 'GET', path: '/pet/{petId}' })
2157
+ * // tags, parameters, and responses are []
2158
+ * ```
2159
+ */
2160
+ declare function createOperation(props: Pick<HttpOperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<HttpOperationNode, 'kind' | 'operationId' | 'method' | 'path' | 'requestBody'>> & {
2161
+ requestBody?: Omit<RequestBodyNode, 'kind'>;
2162
+ }): HttpOperationNode;
2163
+ declare function createOperation(props: Pick<GenericOperationNode, 'operationId'> & Partial<Omit<GenericOperationNode, 'kind' | 'operationId' | 'requestBody'>> & {
2164
+ requestBody?: Omit<RequestBodyNode, 'kind'>;
2165
+ }): GenericOperationNode;
2166
+ //#endregion
2167
+ //#region src/nodes/input.d.ts
2168
+ /**
2169
+ * Metadata for an API document, populated by the adapter and available to every generator.
2170
+ *
2171
+ * All fields are plain JSON-serializable values, no `Set`, no `Map`, no class instances.
2172
+ * Computed fields (`circularNames`, `enumNames`) are pre-calculated once during the adapter
2173
+ * pre-scan so generators never need to iterate the full schema list themselves.
2174
+ *
2175
+ * @example
2176
+ * ```ts
2177
+ * const meta: InputMeta = { title: 'Pet Store', version: '1.0.0', baseURL: 'https://api.example.com/v2', circularNames: [], enumNames: [] }
2178
+ * ```
2179
+ */
2180
+ type InputMeta = {
2181
+ /**
2182
+ * API title from `info.title` in the source document.
2183
+ */
2184
+ title?: string;
2185
+ /**
2186
+ * API description from `info.description` in the source document.
2187
+ */
2188
+ description?: string;
2189
+ /**
2190
+ * API version string from `info.version` in the source document.
2191
+ */
2192
+ version?: string;
2193
+ /**
2194
+ * Resolved base URL from the first matching server entry in the source document.
2195
+ */
2196
+ baseURL?: string | null;
2197
+ /**
2198
+ * Names of schemas that participate in a circular reference chain.
2199
+ * Computed once during the adapter pre-scan, so a generator never has to
2200
+ * call `findCircularSchemas` itself.
2201
+ *
2202
+ * Convert to a `Set` once at the start of a generator, not per-schema,
2203
+ * so lookups stay O(1) without repeated allocations.
2204
+ *
2205
+ * @example Wrap a circular schema in z.lazy()
2206
+ * ```ts
2207
+ * const circular = new Set(meta.circularNames)
2208
+ * if (circular.has(schema.name)) { ... }
2209
+ * ```
2210
+ */
2211
+ circularNames: ReadonlyArray<string>;
2212
+ /**
2213
+ * Names of schemas whose type is `enum`.
2214
+ * Computed once during the adapter pre-scan, so a generator never has to
2215
+ * filter the schema list itself.
2216
+ *
2217
+ * Convert to a `Set` once at the start of a generator when you need repeated
2218
+ * membership checks, so each check stays O(1) instead of an array scan.
2219
+ *
2220
+ * @example Check if a referenced schema is an enum
2221
+ * `const enums = new Set(meta.enumNames)`
2222
+ * `const isEnum = enums.has(schemaName)`
2223
+ */
2224
+ enumNames: ReadonlyArray<string>;
2225
+ };
2226
+ /**
2227
+ * Input AST node that contains all schemas and operations for one API document.
2228
+ * Produced by the adapter and consumed by all Kubb plugins.
2229
+ *
2230
+ * @example
2231
+ * ```ts
2232
+ * const input: InputNode = {
2233
+ * kind: 'Input',
2234
+ * schemas: [],
2235
+ * operations: [],
2236
+ * meta: { circularNames: [], enumNames: [] },
2237
+ * }
2238
+ * ```
2239
+ */
2240
+ type InputNode = BaseNode & {
2241
+ /**
2242
+ * Node kind.
2243
+ */
2244
+ kind: 'Input';
2245
+ /**
2246
+ * All schema nodes in the document.
2247
+ */
2248
+ schemas: Array<SchemaNode>;
2249
+ /**
2250
+ * All operation nodes in the document.
2251
+ */
2252
+ operations: Array<OperationNode>;
2253
+ /**
2254
+ * Document metadata populated by the adapter.
2255
+ */
2256
+ meta: InputMeta;
2257
+ };
2258
+ /**
2259
+ * Definition for the {@link InputNode}.
2260
+ */
2261
+ declare const inputDef: NodeDef<InputNode, Partial<Omit<InputNode, "kind">>>;
2262
+ /**
2263
+ * Creates an `InputNode`, defaulting `schemas`/`operations` to empty arrays and `meta` per
2264
+ * {@link inputDef}.
2265
+ *
2266
+ * @example
2267
+ * ```ts
2268
+ * const input = createInput()
2269
+ * // { kind: 'Input', schemas: [], operations: [] }
2270
+ * ```
2271
+ */
2272
+ declare function createInput(overrides?: Partial<Omit<InputNode, 'kind'>>): InputNode;
2273
+ //#endregion
2274
+ //#region src/nodes/output.d.ts
2275
+ /**
2276
+ * Output AST node that groups all generated file output for one API document.
2277
+ *
2278
+ * Produced by generators and consumed by the build pipeline to write files.
2279
+ *
2280
+ * @example
2281
+ * ```ts
2282
+ * const output: OutputNode = {
2283
+ * kind: 'Output',
2284
+ * files: [],
2285
+ * }
2286
+ * ```
2287
+ */
2288
+ type OutputNode = BaseNode & {
2289
+ /**
2290
+ * Node kind.
2291
+ */
2292
+ kind: 'Output';
2293
+ /**
2294
+ * Generated file nodes.
2295
+ */
2296
+ files: Array<FileNode>;
2297
+ };
2298
+ /**
2299
+ * Definition for the {@link OutputNode}.
2300
+ */
2301
+ declare const outputDef: NodeDef<OutputNode, Partial<Omit<OutputNode, "kind">>>;
2302
+ /**
2303
+ * Creates an `OutputNode` with a stable default for `files`.
2304
+ *
2305
+ * @example
2306
+ * ```ts
2307
+ * const output = createOutput()
2308
+ * // { kind: 'Output', files: [] }
2309
+ * ```
2310
+ */
2311
+ declare function createOutput(overrides?: Partial<Omit<OutputNode, 'kind'>>): OutputNode;
2312
+ //#endregion
2313
+ //#region src/nodes/index.d.ts
2314
+ /**
2315
+ * Union of all AST node types.
2316
+ *
2317
+ * This lets TypeScript narrow types in `switch (node.kind)` blocks.
2318
+ *
2319
+ * @example
2320
+ * ```ts
2321
+ * function getKind(node: Node): string {
2322
+ * switch (node.kind) {
2323
+ * case 'Input':
2324
+ * return 'input'
2325
+ * case 'Output':
2326
+ * return 'output'
2327
+ * default:
2328
+ * return 'other'
2329
+ * }
2330
+ * }
2331
+ * ```
2332
+ */
2333
+ type Node = InputNode | OutputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | RequestBodyNode | ContentNode | FileNode | ImportNode | ExportNode | SourceNode | ConstNode | TypeNode | FunctionNode | ArrowFunctionNode;
2334
+ //#endregion
2335
+ //#region src/visitor.d.ts
2336
+ /**
2337
+ * Ordered mapping of `[NodeType, ParentType]` pairs.
2338
+ *
2339
+ * `ParentOf` uses this map to find parent types.
2340
+ */
2341
+ 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]];
2342
+ /**
2343
+ * Resolves the parent node type for a given AST node type.
2344
+ *
2345
+ * Visitor context relies on this so `ctx.parent` is typed for each callback.
2346
+ *
2347
+ * @example
2348
+ * ```ts
2349
+ * type InputParent = ParentOf<InputNode>
2350
+ * // undefined
2351
+ * ```
2352
+ *
2353
+ * @example
2354
+ * ```ts
2355
+ * type PropertyParent = ParentOf<PropertyNode>
2356
+ * // SchemaNode
2357
+ * ```
2358
+ *
2359
+ * @example
2360
+ * ```ts
2361
+ * type SchemaParent = ParentOf<SchemaNode>
2362
+ * // InputNode | ContentNode | SchemaNode | PropertyNode | ParameterNode
2363
+ * ```
2364
+ */
2365
+ 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;
2366
+ /**
2367
+ * Traversal context passed as the second argument to every visitor callback.
2368
+ * `parent` is typed from the current node type.
2369
+ *
2370
+ * @example
2371
+ * ```ts
2372
+ * const visitor: Visitor = {
2373
+ * schema(node, { parent }) {
2374
+ * // parent type is narrowed by node kind
2375
+ * },
2376
+ * }
2377
+ * ```
2378
+ */
2379
+ type VisitorContext<T extends Node = Node> = {
2380
+ /**
2381
+ * Parent node of the currently visited node.
2382
+ * For `InputNode`, this is `undefined`.
2383
+ */
2384
+ parent?: ParentOf<T>;
2385
+ };
2386
+ /**
2387
+ * Synchronous visitor consumed by `transform`. Each optional callback runs
2388
+ * for the matching node type. Return a new node to replace it, or `undefined`
2389
+ * to leave it untouched.
2390
+ *
2391
+ * Plugins typically expose `transformer` so users can supply a `Visitor` that
2392
+ * rewrites the AST before printing.
2393
+ *
2394
+ * @example Prefix every operationId
2395
+ * ```ts
2396
+ * const visitor: Visitor = {
2397
+ * operation(node) {
2398
+ * return { ...node, operationId: `api_${node.operationId}` }
2399
+ * },
2400
+ * }
2401
+ * ```
2402
+ *
2403
+ * @example Strip schema descriptions
2404
+ * ```ts
2405
+ * const visitor: Visitor = {
2406
+ * schema(node) {
2407
+ * return { ...node, description: undefined }
2408
+ * },
2409
+ * }
2410
+ * ```
2411
+ */
2412
+ type Visitor = {
2413
+ input?(node: InputNode, context: VisitorContext<InputNode>): undefined | null | InputNode;
2414
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): undefined | null | OutputNode;
2415
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): undefined | null | OperationNode;
2416
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): undefined | null | SchemaNode;
2417
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): undefined | null | PropertyNode;
2418
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): undefined | null | ParameterNode;
2419
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): undefined | null | ResponseNode;
2420
+ };
2421
+ /**
2422
+ * Visitor used by `collect`.
2423
+ *
2424
+ * @example
2425
+ * ```ts
2426
+ * const visitor: CollectVisitor<string> = {
2427
+ * operation(node) {
2428
+ * return node.operationId
2429
+ * },
2430
+ * }
2431
+ * ```
2432
+ */
2433
+ type CollectVisitor<T> = {
2434
+ input?(node: InputNode, context: VisitorContext<InputNode>): T | null | undefined;
2435
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): T | null | undefined;
2436
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | null | undefined;
2437
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | null | undefined;
2438
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | null | undefined;
2439
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | null | undefined;
2440
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | null | undefined;
2441
+ };
2442
+ /**
2443
+ * Options for `transform`.
2444
+ *
2445
+ * @example
2446
+ * ```ts
2447
+ * const options: TransformOptions = { depth: 'deep', schema: (node) => node }
2448
+ * ```
2449
+ *
2450
+ * @example
2451
+ * ```ts
2452
+ * // Only transform the current node, not nested children
2453
+ * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }
2454
+ * ```
2455
+ */
2456
+ type TransformOptions = Visitor & {
2457
+ /**
2458
+ * Traversal depth.
2459
+ * @default 'deep'
2460
+ */
2461
+ depth?: VisitorDepth;
2462
+ /**
2463
+ * Internal parent override used during recursion.
2464
+ */
2465
+ parent?: Node;
2466
+ };
2467
+ /**
2468
+ * Options for `collect`.
2469
+ *
2470
+ * @example
2471
+ * ```ts
2472
+ * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }
2473
+ * ```
2474
+ */
2475
+ type CollectOptions<T> = CollectVisitor<T> & {
2476
+ /**
2477
+ * Traversal depth.
2478
+ * @default 'deep'
2479
+ */
2480
+ depth?: VisitorDepth;
2481
+ /**
2482
+ * Internal parent override used during recursion.
2483
+ */
2484
+ parent?: Node;
2485
+ };
2486
+ /**
2487
+ * Synchronous depth-first transform. Each visitor callback can return a
2488
+ * replacement node. Returning `undefined` keeps the original.
2489
+ *
2490
+ * The original tree is never mutated, a new tree is returned. Pass
2491
+ * `depth: 'shallow'` to skip recursion into children.
2492
+ *
2493
+ * @example Prefix every operationId
2494
+ * ```ts
2495
+ * const next = transform(root, {
2496
+ * operation(node) {
2497
+ * return { ...node, operationId: `prefixed_${node.operationId}` }
2498
+ * },
2499
+ * })
2500
+ * ```
2501
+ *
2502
+ * @example Replace only the root node
2503
+ * ```ts
2504
+ * const next = transform(root, {
2505
+ * depth: 'shallow',
2506
+ * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),
2507
+ * })
2508
+ * ```
2509
+ */
2510
+ declare function transform(node: InputNode, options: TransformOptions): InputNode;
2511
+ declare function transform(node: OutputNode, options: TransformOptions): OutputNode;
2512
+ declare function transform(node: OperationNode, options: TransformOptions): OperationNode;
2513
+ declare function transform(node: SchemaNode, options: TransformOptions): SchemaNode;
2514
+ declare function transform(node: PropertyNode, options: TransformOptions): PropertyNode;
2515
+ declare function transform(node: ParameterNode, options: TransformOptions): ParameterNode;
2516
+ declare function transform(node: ResponseNode, options: TransformOptions): ResponseNode;
2517
+ declare function transform(node: Node, options: TransformOptions): Node;
2518
+ /**
2519
+ * Eager depth-first collection pass. Gathers every non-null value the visitor
2520
+ * callbacks return into an array.
2521
+ *
2522
+ * @example Collect every operationId
2523
+ * ```ts
2524
+ * const ids = collect<string>(root, {
2525
+ * operation(node) {
2526
+ * return node.operationId
2527
+ * },
2528
+ * })
2529
+ * ```
2530
+ */
2531
+ declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
2532
+ //#endregion
2533
+ //#region src/defineMacro.d.ts
2534
+ /**
2535
+ * Ordering hint shared by macros and plugins. `pre` runs before unmarked items, `post` after,
2536
+ * and `undefined` keeps declaration order.
2537
+ */
2538
+ type Enforce = 'pre' | 'post';
2539
+ /**
2540
+ * A named, composable transform over the Kubb AST. It carries the same per-kind callbacks as a
2541
+ * {@link Visitor} (`schema`, `operation`, …), plus a `name`, an optional `enforce` order, and an
2542
+ * optional `when` gate. Macros run on the shared AST, so the same macro works across every adapter
2543
+ * and output target. Exports follow the `macro<Name>` convention, mirroring plugins (`pluginTs`).
2544
+ */
2545
+ type Macro = Visitor & {
2546
+ /**
2547
+ * Macro identifier used to tell macros apart, for example `'simplify-union'`.
2548
+ */
2549
+ name: string;
2550
+ /**
2551
+ * Ordering hint. `pre` macros run before unmarked macros, `post` macros run after.
2552
+ * Ordering within a bucket follows list order.
2553
+ */
2554
+ enforce?: Enforce;
2555
+ /**
2556
+ * Gate checked against the current node before any callback runs. When it returns `false`
2557
+ * the macro is skipped for that node.
2558
+ */
2559
+ when?: (node: Node) => boolean;
2560
+ };
2561
+ /**
2562
+ * Types a macro for inference and a single construction site, mirroring `definePlugin`.
2563
+ * Adds no runtime behavior.
2564
+ *
2565
+ * @example
2566
+ * ```ts
2567
+ * const macroUntagged = defineMacro({
2568
+ * name: 'untagged',
2569
+ * operation(node) {
2570
+ * return node.tags?.length ? undefined : { ...node, tags: ['untagged'] }
2571
+ * },
2572
+ * })
2573
+ * ```
2574
+ */
2575
+ declare function defineMacro(macro: Macro): Macro;
2576
+ /**
2577
+ * Folds an ordered list of macros into a single {@link Visitor} that `transform` (and the per-plugin
2578
+ * transform layer in `@kubb/core`) can run. Macros are stable-sorted by `enforce`, then applied
2579
+ * sequentially per node so later macros see earlier output. This differs from a plain visitor, which
2580
+ * has no names, ordering, or composition.
2581
+ *
2582
+ * @example
2583
+ * ```ts
2584
+ * const visitor = composeMacros([macroSimplifyUnion, macroDiscriminatorEnum])
2585
+ * const next = transform(root, visitor)
2586
+ * ```
2587
+ */
2588
+ declare function composeMacros(macros: ReadonlyArray<Macro>): Visitor;
2589
+ /**
2590
+ * Runs a list of macros over a node tree and returns the rewritten tree. Keeps `transform`'s
2591
+ * structural sharing, so an empty or no-op macro list returns the same reference. Pass
2592
+ * `depth: 'shallow'` to rewrite the root node only.
2593
+ *
2594
+ * @example
2595
+ * ```ts
2596
+ * const next = applyMacros(root, [macroIntegerToString])
2597
+ * ```
2598
+ *
2599
+ * @example Apply to the root node only
2600
+ * ```ts
2601
+ * const named = applyMacros(node, [macroEnumName({ parentName, propName, enumSuffix })], { depth: 'shallow' })
2602
+ * ```
2603
+ */
2604
+ declare function applyMacros<TNode extends Node>(root: TNode, macros: ReadonlyArray<Macro>, options?: {
2605
+ depth?: VisitorDepth;
2606
+ }): TNode;
2607
+ //#endregion
2608
+ //#region src/createPrinter.d.ts
2609
+ /**
2610
+ * Runtime context passed as `this` to printer handlers.
2611
+ *
2612
+ * `this.transform` dispatches to node-level handlers from `nodes`.
2613
+ *
2614
+ * @example
2615
+ * ```ts
2616
+ * const context: PrinterHandlerContext<string, {}> = {
2617
+ * options: {},
2618
+ * transform: () => 'value',
2619
+ * }
2620
+ * ```
2621
+ */
2622
+ type PrinterHandlerContext<TOutput, TOptions extends object> = {
2623
+ /**
2624
+ * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.
2625
+ * Use `this.transform` inside `nodes` handlers and inside the `print` override.
2626
+ */
2627
+ transform: (node: SchemaNode) => TOutput | null;
2628
+ /**
2629
+ * Run the printer's built-in handler for the node, ignoring any override for its type.
2630
+ * Inside an override, `this.base(node)` returns what the printer would have emitted,
2631
+ * so the override can wrap it instead of re-implementing the handler. Nested nodes
2632
+ * still dispatch through the overrides.
2633
+ */
2634
+ base: (node: SchemaNode) => TOutput | null;
2635
+ /**
2636
+ * Options for this printer instance.
2637
+ */
2638
+ options: TOptions;
2639
+ };
2640
+ /**
2641
+ * Handler for one schema node type.
2642
+ *
2643
+ * Use a regular function (not an arrow function) if you need `this`.
2644
+ *
2645
+ * @example
2646
+ * ```ts
2647
+ * const handler: PrinterHandler<string, {}, 'string'> = function () {
2648
+ * return 'string'
2649
+ * }
2650
+ * ```
2651
+ */
2652
+ type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null;
2653
+ /**
2654
+ * Partial map of per-node-type handler overrides for a printer.
2655
+ *
2656
+ * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).
2657
+ * Supply only the handlers you want to replace. The printer's built-in
2658
+ * defaults fill in the rest.
2659
+ *
2660
+ * @example
2661
+ * ```ts
2662
+ * pluginZod({
2663
+ * printer: {
2664
+ * nodes: {
2665
+ * date(): string {
2666
+ * return 'z.string().date()'
2667
+ * },
2668
+ * } satisfies PrinterPartial<string, PrinterZodOptions>,
2669
+ * },
2670
+ * })
2671
+ * ```
2672
+ */
2673
+ type PrinterPartial<TOutput, TOptions extends object> = Partial<{ [K in SchemaType]: PrinterHandler<TOutput, TOptions, K> }>;
2674
+ /**
2675
+ * Generic shape used by `definePrinter`.
2676
+ *
2677
+ * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)
2678
+ * - `TOptions` options passed to and stored on the printer instance
2679
+ * - `TOutput` the type emitted by node handlers
2680
+ * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)
2681
+ *
2682
+ * @example
2683
+ * ```ts
2684
+ * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>
2685
+ * ```
2686
+ */
2687
+ type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
2688
+ name: TName;
2689
+ options: TOptions;
2690
+ output: TOutput;
2691
+ printOutput: TPrintOutput;
2692
+ };
2693
+ /**
2694
+ * Printer instance returned by a printer factory.
2695
+ *
2696
+ * @example
2697
+ * ```ts
2698
+ * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})
2699
+ * ```
2700
+ */
2701
+ type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
2702
+ /**
2703
+ * Unique identifier supplied at creation time.
2704
+ */
2705
+ name: T['name'];
2706
+ /**
2707
+ * Options for this printer instance.
2708
+ */
2709
+ options: T['options'];
2710
+ /**
2711
+ * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
2712
+ * Always dispatches through the `nodes` map. Never calls the `print` override.
2713
+ * Reach for it when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
2714
+ */
2715
+ transform: (node: SchemaNode) => T['output'] | null;
2716
+ /**
2717
+ * Public printer. If the builder provides a root-level `print`, this calls that
2718
+ * higher-level function (which may produce full declarations).
2719
+ * Otherwise, falls back to the node-level dispatcher.
2720
+ */
2721
+ print: (node: SchemaNode) => T['printOutput'] | null;
2722
+ };
2723
+ /**
2724
+ * Builder function passed to `definePrinter`.
2725
+ *
2726
+ * It receives resolved options and returns:
2727
+ * - `name`
2728
+ * - `options`
2729
+ * - `nodes` handlers
2730
+ * - optional top-level `print` override
2731
+ *
2732
+ * @example
2733
+ * ```ts
2734
+ * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })
2735
+ * ```
2736
+ */
2737
+ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
2738
+ name: T['name'];
2739
+ /**
2740
+ * Options to store on the printer.
2741
+ */
2742
+ options: T['options'];
2743
+ nodes: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
2744
+ /**
2745
+ * User-supplied handler overrides. An override wins over the matching `nodes` handler,
2746
+ * and can call `this.base(node)` to reuse the handler it replaced. Pass overrides here
2747
+ * instead of spreading them into `nodes`, otherwise `this.base` cannot find the original.
2748
+ */
2749
+ overrides?: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
2750
+ /**
2751
+ * Optional root-level print override. When provided, becomes the public `printer.print`.
2752
+ * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
2753
+ * not the override itself, so recursion is safe.
2754
+ */
2755
+ print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null;
2756
+ };
2757
+ /**
2758
+ * Creates a schema printer: a function that takes a `SchemaNode` and emits
2759
+ * code in your target language. Each plugin that produces code from schemas
2760
+ * (TypeScript types, Zod schemas, Faker factories) ships a printer built
2761
+ * with this helper.
2762
+ *
2763
+ * The builder receives resolved options and returns:
2764
+ *
2765
+ * - `name` unique identifier for the printer.
2766
+ * - `options` stored on the returned printer instance.
2767
+ * - `nodes` map of `SchemaType` → handler. Handlers return the rendered
2768
+ * output (a string, a TypeScript AST node, ...) for that schema type.
2769
+ * - `overrides` (optional), user-supplied handlers that win over `nodes`.
2770
+ * An override can call `this.base(node)` to reuse the handler it replaced.
2771
+ * - `print` (optional), top-level override exposed as `printer.print`.
2772
+ * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
2773
+ *
2774
+ * Without a `print` override, `printer.print` falls back to `printer.transform`
2775
+ * (the node-level dispatcher).
2776
+ *
2777
+ * @example Tiny Zod printer
2778
+ * ```ts
2779
+ * import { createPrinter, type PrinterFactoryOptions } from '@kubb/ast'
2780
+ *
2781
+ * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
2782
+ *
2783
+ * export const zodPrinter = createPrinter<PrinterZod>((options) => ({
2784
+ * name: 'zod',
2785
+ * options: { strict: options.strict ?? true },
2786
+ * nodes: {
2787
+ * string: () => 'z.string()',
2788
+ * object(node) {
2789
+ * const props = node.properties
2790
+ * .map((p) => `${p.name}: ${this.transform(p.schema)}`)
2791
+ * .join(', ')
2792
+ * return `z.object({ ${props} })`
2793
+ * },
2794
+ * },
2795
+ * }))
2796
+ * ```
2797
+ */
2798
+ declare function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
2799
+ //#endregion
2800
+ export { sourceDef as $, NodeDef as $t, StatusCode as A, BreakNode as At, parameterDef as B, constDef as Bt, GenericOperationNode as C, PropertyNode as Ct, createOperation as D, InferSchemaNode as Dt, OperationNode as E, propertyDef as Et, requestBodyDef as F, JsxNode as Ft, UserFileNode as G, createJsx as Gt, FileNode as H, createBreak as Ht, ParameterLocation as I, TextNode as It, createImport as J, functionDef as Jt, createExport as K, createText as Kt, ParameterNode as L, TypeNode as Lt, responseDef as M, ConstNode as Mt, RequestBodyNode as N, FunctionNode as Nt, operationDef as O, ParserOptions as Ot, createRequestBody as P, JSDocNode as Pt, importDef as Q, DistributiveOmit as Qt, ParameterStyle as R, arrowFunctionDef as Rt, inputDef as S, schemaDef as St, HttpOperationNode as T, createProperty as Tt, ImportNode as U, createConst as Ut, ExportNode as V, createArrowFunction as Vt, SourceNode as W, createFunction as Wt, exportDef as X, textDef as Xt, createSource as Y, jsxDef as Yt, fileDef as Z, typeDef as Zt, createOutput as _, StringSchemaNode as _t, Enforce as a, defineDialect as an, DatetimeSchemaNode as at, InputNode as b, UrlSchemaNode as bt, composeMacros as c, NumberSchemaNode as ct, Visitor as d, RefSchemaNode as dt, defineNode as en, ContentNode as et, VisitorContext as f, ScalarSchemaNode as ft, OutputNode as g, SchemaType as gt, Node as h, SchemaNodeByType as ht, createPrinter as i, SchemaDialect as in, DateSchemaNode as it, createResponse as j, CodeNode as jt, ResponseNode as k, ArrowFunctionNode as kt, defineMacro as l, ObjectSchemaNode as lt, transform as m, SchemaNode as mt, PrinterFactoryOptions as n, NodeKind as nn, createContent as nt, Macro as o, schemaTypes as on, EnumSchemaNode as ot, collect as p, ScalarSchemaType as pt, createFile as q, createType as qt, PrinterPartial as r, Dialect as rn, ArraySchemaNode as rt, applyMacros as s, IntersectionSchemaNode as st, Printer as t, BaseNode as tn, contentDef as tt, ParentOf as u, PrimitiveSchemaType as ut, outputDef as v, TimeSchemaNode as vt, HttpMethod as w, UserPropertyNode as wt, createInput as x, createSchema as xt, InputMeta as y, UnionSchemaNode as yt, createParameter as z, breakDef as zt };
2801
+ //# sourceMappingURL=types-D12-e8Av.d.ts.map