@kubb/ast 5.0.0-beta.57 → 5.0.0-beta.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +11 -7
  2. package/dist/{types-C5aVnRE1.d.ts → ast-ClnJg9BN.d.ts} +82 -836
  3. package/dist/chunk-CNktS9qV.js +17 -0
  4. package/dist/extractStringsFromNodes-Bn9cOos9.d.ts +14 -0
  5. package/dist/factory-C5gHvtLU.js +138 -0
  6. package/dist/factory-C5gHvtLU.js.map +1 -0
  7. package/dist/factory-JN-Ylfl6.cjs +155 -0
  8. package/dist/factory-JN-Ylfl6.cjs.map +1 -0
  9. package/dist/factory.cjs +31 -0
  10. package/dist/factory.d.ts +62 -0
  11. package/dist/factory.js +3 -0
  12. package/dist/index.cjs +86 -1746
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +6 -3
  15. package/dist/index.js +177 -1809
  16. package/dist/index.js.map +1 -1
  17. package/dist/types-CB2oY8Dw.d.ts +769 -0
  18. package/dist/types.d.ts +4 -2
  19. package/dist/utils-C8bWAzhv.cjs +2696 -0
  20. package/dist/utils-C8bWAzhv.cjs.map +1 -0
  21. package/dist/utils-DN4XLVqz.js +2099 -0
  22. package/dist/utils-DN4XLVqz.js.map +1 -0
  23. package/dist/utils.cjs +12 -1
  24. package/dist/utils.d.ts +21 -2
  25. package/dist/utils.js +2 -2
  26. package/package.json +5 -1
  27. package/src/factory.ts +19 -1
  28. package/src/index.ts +14 -48
  29. package/src/node.ts +1 -1
  30. package/src/nodes/base.ts +0 -10
  31. package/src/nodes/function.ts +2 -2
  32. package/src/nodes/index.ts +1 -1
  33. package/src/nodes/input.ts +14 -13
  34. package/src/printer.ts +3 -3
  35. package/src/types.ts +1 -1
  36. package/src/utils/ast.ts +3 -66
  37. package/src/utils/extractStringsFromNodes.ts +34 -0
  38. package/src/utils/index.ts +44 -0
  39. package/dist/chunk-C0LytTxp.js +0 -8
  40. package/dist/utils-0p8ZO287.js +0 -570
  41. package/dist/utils-0p8ZO287.js.map +0 -1
  42. package/dist/utils-cdQ6Pzyi.cjs +0 -726
  43. package/dist/utils-cdQ6Pzyi.cjs.map +0 -1
@@ -0,0 +1,769 @@
1
+ import { n as __name } from "./chunk-CNktS9qV.js";
2
+ import { Dt as SchemaNode, I as ParameterNode, It as PropertyNode, M as RequestBodyNode, O as ResponseNode, Ot as SchemaNodeByType, T as OperationNode, b as InputNode, g as OutputNode, h as Node, kt as SchemaType, mt as ContentNode } from "./ast-ClnJg9BN.js";
3
+
4
+ //#region src/constants.d.ts
5
+ /**
6
+ * Traversal depth for AST visitor utilities.
7
+ *
8
+ * - `'shallow'` visits only the immediate node, skipping children.
9
+ * - `'deep'` recursively visits all descendant nodes.
10
+ */
11
+ type VisitorDepth = 'shallow' | 'deep';
12
+ /**
13
+ * Schema type discriminators used by all AST schema nodes.
14
+ *
15
+ * These values serve as stable discriminators across the AST (e.g., `schema.type === schemaTypes.object`).
16
+ * Grouped by category: primitives (`string`, `number`, `boolean`), structural types (`object`, `array`, `union`),
17
+ * and format-specific types (`date`, `uuid`, `email`). Use `isScalarPrimitive()` to check for scalar types.
18
+ */
19
+ declare const schemaTypes: {
20
+ /**
21
+ * Text value.
22
+ */
23
+ readonly string: "string";
24
+ /**
25
+ * Floating-point number (`float`, `double`).
26
+ */
27
+ readonly number: "number";
28
+ /**
29
+ * Whole number (`int32`). Use `bigint` for `int64`.
30
+ */
31
+ readonly integer: "integer";
32
+ /**
33
+ * 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
34
+ */
35
+ readonly bigint: "bigint";
36
+ /**
37
+ * Boolean value
38
+ */
39
+ readonly boolean: "boolean";
40
+ /**
41
+ * Explicit null value.
42
+ */
43
+ readonly null: "null";
44
+ /**
45
+ * Any value (no type restriction).
46
+ */
47
+ readonly any: "any";
48
+ /**
49
+ * Unknown value (must be narrowed before usage).
50
+ */
51
+ readonly unknown: "unknown";
52
+ /**
53
+ * No return value (`void`).
54
+ */
55
+ readonly void: "void";
56
+ /**
57
+ * Object with named properties.
58
+ */
59
+ readonly object: "object";
60
+ /**
61
+ * Sequential list of items.
62
+ */
63
+ readonly array: "array";
64
+ /**
65
+ * Fixed-length list with position-specific items.
66
+ */
67
+ readonly tuple: "tuple";
68
+ /**
69
+ * "One of" multiple schema members.
70
+ */
71
+ readonly union: "union";
72
+ /**
73
+ * "All of" multiple schema members.
74
+ */
75
+ readonly intersection: "intersection";
76
+ /**
77
+ * Enum schema.
78
+ */
79
+ readonly enum: "enum";
80
+ /**
81
+ * Reference to another schema.
82
+ */
83
+ readonly ref: "ref";
84
+ /**
85
+ * Calendar date (for example `2026-03-24`).
86
+ */
87
+ readonly date: "date";
88
+ /**
89
+ * Date-time value (for example `2026-03-24T09:00:00Z`).
90
+ */
91
+ readonly datetime: "datetime";
92
+ /**
93
+ * Time-only value (for example `09:00:00`).
94
+ */
95
+ readonly time: "time";
96
+ /**
97
+ * UUID value.
98
+ */
99
+ readonly uuid: "uuid";
100
+ /**
101
+ * Email address value.
102
+ */
103
+ readonly email: "email";
104
+ /**
105
+ * URL value.
106
+ */
107
+ readonly url: "url";
108
+ /**
109
+ * IPv4 address value.
110
+ */
111
+ readonly ipv4: "ipv4";
112
+ /**
113
+ * IPv6 address value.
114
+ */
115
+ readonly ipv6: "ipv6";
116
+ /**
117
+ * Binary/blob value.
118
+ */
119
+ readonly blob: "blob";
120
+ /**
121
+ * Impossible value (`never`).
122
+ */
123
+ readonly never: "never";
124
+ };
125
+ /**
126
+ * HTTP method identifiers used by operation nodes.
127
+ *
128
+ * Includes all standard HTTP methods (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS, TRACE).
129
+ */
130
+ declare const httpMethods: {
131
+ readonly get: "GET";
132
+ readonly post: "POST";
133
+ readonly put: "PUT";
134
+ readonly patch: "PATCH";
135
+ readonly delete: "DELETE";
136
+ readonly head: "HEAD";
137
+ readonly options: "OPTIONS";
138
+ readonly trace: "TRACE";
139
+ };
140
+ //#endregion
141
+ //#region src/dedupe.d.ts
142
+ /**
143
+ * A canonical destination for a deduplicated shape: the shared schema name and
144
+ * the synthetic `$ref` path that points at it.
145
+ */
146
+ type DedupeCanonical = {
147
+ /**
148
+ * Canonical schema name every duplicate occurrence refers to.
149
+ */
150
+ name: string;
151
+ /**
152
+ * `$ref` path stored on the generated `ref` nodes (for example `#/components/schemas/Status`).
153
+ */
154
+ ref: string;
155
+ };
156
+ /**
157
+ * The result of {@link buildDedupePlan}: a lookup from structural signature to its
158
+ * canonical target, plus the freshly hoisted definitions that must be added to
159
+ * the schema list.
160
+ */
161
+ type DedupePlan = {
162
+ /**
163
+ * Maps a structural signature to the canonical schema that represents it.
164
+ */
165
+ canonicalBySignature: Map<string, DedupeCanonical>;
166
+ /**
167
+ * Maps the name of a top-level schema that duplicates a canonical one to that canonical, so
168
+ * references to the duplicate can be repointed at the first schema with the same content.
169
+ */
170
+ aliasNames: Map<string, DedupeCanonical>;
171
+ /**
172
+ * New top-level schema definitions created for inline shapes that had no existing
173
+ * named component. Nested duplicates inside each definition are already collapsed.
174
+ */
175
+ hoisted: Array<SchemaNode>;
176
+ };
177
+ /**
178
+ * The lookups {@link applyDedupe} needs from a {@link DedupePlan}.
179
+ */
180
+ type DedupeLookups = Pick<DedupePlan, 'canonicalBySignature' | 'aliasNames'>;
181
+ /**
182
+ * Options that inject the naming and candidate policy into {@link buildDedupePlan}.
183
+ * The mechanics (grouping, counting, rewriting) live here. The policy lives in the caller.
184
+ */
185
+ type BuildDedupePlanOptions = {
186
+ /**
187
+ * Returns `true` when a node should be deduplicated. This is the only gate, so it must
188
+ * reject both ineligible kinds (return `false` for anything other than, say, enums and
189
+ * objects) and unsafe shapes (e.g. nodes that reference a circular schema).
190
+ */
191
+ isCandidate: (node: SchemaNode) => boolean;
192
+ /**
193
+ * Produces the canonical name for an inline shape with no existing named component.
194
+ * Return `null` to leave the shape inline (for example when no contextual name exists).
195
+ */
196
+ nameFor: (node: SchemaNode, signature: string) => string | null;
197
+ /**
198
+ * Builds the `$ref` path for a canonical name.
199
+ */
200
+ refFor: (name: string) => string;
201
+ /**
202
+ * Minimum number of occurrences before a shape is deduplicated.
203
+ *
204
+ * @default 2
205
+ */
206
+ minOccurrences?: number;
207
+ };
208
+ /**
209
+ * Rewrites a node, replacing every candidate sub-schema whose signature has a canonical
210
+ * target with a `ref` to that target. Replacing a node with a `ref` prunes its subtree,
211
+ * so nested duplicates inside a replaced shape are not visited again. A `ref` that points
212
+ * at a duplicate top-level schema (see `aliasNames`) is repointed at the first schema with
213
+ * the same content.
214
+ *
215
+ * Pass `skipRootMatch` when rewriting a canonical definition so its own root is not
216
+ * turned into a reference to itself. Nested duplicates are still collapsed.
217
+ *
218
+ * @example
219
+ * ```ts
220
+ * const next = applyDedupe(operationNode, plan)
221
+ * ```
222
+ */
223
+ declare function applyDedupe(node: SchemaNode, plan: DedupeLookups, skipRootMatch?: boolean): SchemaNode;
224
+ declare function applyDedupe(node: OperationNode, plan: DedupeLookups, skipRootMatch?: boolean): OperationNode;
225
+ /**
226
+ * Scans a forest of schema and operation nodes and produces a {@link DedupePlan}.
227
+ *
228
+ * A shape that occurs at least `minOccurrences` times is deduplicated: if any occurrence
229
+ * is a named top-level schema, the first one becomes the canonical (so other top-level
230
+ * duplicates and inline copies turn into references to it). Every other top-level name with
231
+ * the same content is recorded in `aliasNames`, so refs to it can be repointed at the
232
+ * canonical. Otherwise a new definition is hoisted using `nameFor`. The plan is then applied
233
+ * per node with {@link applyDedupe}.
234
+ *
235
+ * @example
236
+ * ```ts
237
+ * const plan = buildDedupePlan([...schemaNodes, ...operationNodes], {
238
+ * isCandidate: (node) => node.type === 'enum' || node.type === 'object',
239
+ * nameFor: (node) => node.name ?? null,
240
+ * refFor: (name) => `#/components/schemas/${name}`,
241
+ * })
242
+ * ```
243
+ */
244
+ declare function buildDedupePlan(roots: ReadonlyArray<Node>, options: BuildDedupePlanOptions): DedupePlan;
245
+ //#endregion
246
+ //#region src/dialect.d.ts
247
+ /**
248
+ * The spec-specific questions a schema parser answers while turning a source document into Kubb
249
+ * AST nodes. The rest of the pipeline is generic JSON Schema, so this is the one seam where
250
+ * OpenAPI, AsyncAPI, and plain JSON Schema differ.
251
+ */
252
+ type SchemaDialect<TSchema = unknown, TRef = TSchema, TDiscriminated = TSchema, TDocument = unknown> = {
253
+ /**
254
+ * Identifies the dialect in logs and diagnostics.
255
+ */
256
+ name: string;
257
+ /**
258
+ * Whether the schema is nullable.
259
+ */
260
+ isNullable: (schema?: TSchema) => boolean;
261
+ /**
262
+ * Whether the value is a `$ref` pointer.
263
+ */
264
+ isReference: (value?: unknown) => value is TRef;
265
+ /**
266
+ * Whether the schema carries a discriminator for polymorphism.
267
+ */
268
+ isDiscriminator: (value?: unknown) => value is TDiscriminated;
269
+ /**
270
+ * Whether the schema is binary data, converted to a `blob` node.
271
+ */
272
+ isBinary: (schema: TSchema) => boolean;
273
+ /**
274
+ * Resolves a local `$ref` against the document, or nullish when it cannot.
275
+ */
276
+ resolveRef: <TResolved>(document: TDocument, ref: string) => TResolved | null | undefined;
277
+ };
278
+ /**
279
+ * Types a {@link SchemaDialect} for an adapter. Adds no runtime behavior and only pins the
280
+ * dialect's type for inference.
281
+ *
282
+ * @example
283
+ * ```ts
284
+ * export const oasDialect = defineSchemaDialect({
285
+ * name: 'oas',
286
+ * isNullable,
287
+ * isReference,
288
+ * isDiscriminator,
289
+ * isBinary: (schema) => schema.type === 'string' && schema.contentMediaType === 'application/octet-stream',
290
+ * resolveRef,
291
+ * })
292
+ * ```
293
+ */
294
+ declare function defineSchemaDialect<TSchema, TRef, TDiscriminated, TDocument>(dialect: SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>): SchemaDialect<TSchema, TRef, TDiscriminated, TDocument>;
295
+ //#endregion
296
+ //#region src/printer.d.ts
297
+ /**
298
+ * Runtime context passed as `this` to printer handlers.
299
+ *
300
+ * `this.transform` dispatches to node-level handlers from `nodes`.
301
+ *
302
+ * @example
303
+ * ```ts
304
+ * const context: PrinterHandlerContext<string, {}> = {
305
+ * options: {},
306
+ * transform: () => 'value',
307
+ * }
308
+ * ```
309
+ */
310
+ type PrinterHandlerContext<TOutput, TOptions extends object> = {
311
+ /**
312
+ * Recursively transform a nested `SchemaNode` to `TOutput` using the node-level handlers.
313
+ * Use `this.transform` inside `nodes` handlers and inside the `print` override.
314
+ */
315
+ transform: (node: SchemaNode) => TOutput | null;
316
+ /**
317
+ * Options for this printer instance.
318
+ */
319
+ options: TOptions;
320
+ };
321
+ /**
322
+ * Handler for one schema node type.
323
+ *
324
+ * Use a regular function (not an arrow function) if you need `this`.
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * const handler: PrinterHandler<string, {}, 'string'> = function () {
329
+ * return 'string'
330
+ * }
331
+ * ```
332
+ */
333
+ type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null;
334
+ /**
335
+ * Partial map of per-node-type handler overrides for a printer.
336
+ *
337
+ * Each key is a `SchemaType` string (e.g. `'date'`, `'string'`).
338
+ * Supply only the handlers you want to replace. The printer's built-in
339
+ * defaults fill in the rest.
340
+ *
341
+ * @example
342
+ * ```ts
343
+ * pluginZod({
344
+ * printer: {
345
+ * nodes: {
346
+ * date(): string {
347
+ * return 'z.string().date()'
348
+ * },
349
+ * } satisfies PrinterPartial<string, PrinterZodOptions>,
350
+ * },
351
+ * })
352
+ * ```
353
+ */
354
+ type PrinterPartial<TOutput, TOptions extends object> = Partial<{ [K in SchemaType]: PrinterHandler<TOutput, TOptions, K> }>;
355
+ /**
356
+ * Generic shape used by `definePrinter`.
357
+ *
358
+ * - `TName` unique string identifier (e.g. `'zod'`, `'ts'`)
359
+ * - `TOptions` options passed to and stored on the printer instance
360
+ * - `TOutput` the type emitted by node handlers
361
+ * - `TPrintOutput` type returned by public `print` (defaults to `TOutput`)
362
+ *
363
+ * @example
364
+ * ```ts
365
+ * type MyPrinter = PrinterFactoryOptions<'my', { strict: boolean }, string>
366
+ * ```
367
+ */
368
+ type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
369
+ name: TName;
370
+ options: TOptions;
371
+ output: TOutput;
372
+ printOutput: TPrintOutput;
373
+ };
374
+ /**
375
+ * Printer instance returned by a printer factory.
376
+ *
377
+ * @example
378
+ * ```ts
379
+ * const printer = definePrinter((options: {}) => ({ name: 'x', options, nodes: {} }))({})
380
+ * ```
381
+ */
382
+ type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
383
+ /**
384
+ * Unique identifier supplied at creation time.
385
+ */
386
+ name: T['name'];
387
+ /**
388
+ * Options for this printer instance.
389
+ */
390
+ options: T['options'];
391
+ /**
392
+ * Node-level dispatcher, converts a `SchemaNode` directly to `TOutput` using the `nodes` handlers.
393
+ * Always dispatches through the `nodes` map. Never calls the `print` override.
394
+ * Use this when you need the raw output (e.g. `ts.TypeNode`) without declaration wrapping.
395
+ */
396
+ transform: (node: SchemaNode) => T['output'] | null;
397
+ /**
398
+ * Public printer. If the builder provides a root-level `print`, this calls that
399
+ * higher-level function (which may produce full declarations).
400
+ * Otherwise, falls back to the node-level dispatcher.
401
+ */
402
+ print: (node: SchemaNode) => T['printOutput'] | null;
403
+ };
404
+ /**
405
+ * Builder function passed to `definePrinter`.
406
+ *
407
+ * It receives resolved options and returns:
408
+ * - `name`
409
+ * - `options`
410
+ * - `nodes` handlers
411
+ * - optional top-level `print` override
412
+ *
413
+ * @example
414
+ * ```ts
415
+ * const build = (options: {}) => ({ name: 'x' as const, options, nodes: {} })
416
+ * ```
417
+ */
418
+ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
419
+ name: T['name'];
420
+ /**
421
+ * Options to store on the printer.
422
+ */
423
+ options: T['options'];
424
+ nodes: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
425
+ /**
426
+ * Optional root-level print override. When provided, becomes the public `printer.print`.
427
+ * Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
428
+ * not the override itself, so recursion is safe.
429
+ */
430
+ print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null;
431
+ };
432
+ /**
433
+ * Defines a schema printer: a function that takes a `SchemaNode` and emits
434
+ * code in your target language. Each plugin that produces code from schemas
435
+ * (TypeScript types, Zod schemas, Faker factories) ships a printer built
436
+ * with this helper.
437
+ *
438
+ * The builder receives resolved options and returns:
439
+ *
440
+ * - `name` unique identifier for the printer.
441
+ * - `options` stored on the returned printer instance.
442
+ * - `nodes` map of `SchemaType` → handler. Handlers return the rendered
443
+ * output (a string, a TypeScript AST node, ...) for that schema type.
444
+ * - `print` (optional), top-level override exposed as `printer.print`.
445
+ * Use `this.transform(node)` inside it to dispatch to `nodes` recursively.
446
+ *
447
+ * Without a `print` override, `printer.print` falls back to `printer.transform`
448
+ * (the node-level dispatcher).
449
+ *
450
+ * @example Tiny Zod printer
451
+ * ```ts
452
+ * import { definePrinter, type PrinterFactoryOptions } from '@kubb/ast'
453
+ *
454
+ * type PrinterZod = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
455
+ *
456
+ * export const zodPrinter = definePrinter<PrinterZod>((options) => ({
457
+ * name: 'zod',
458
+ * options: { strict: options.strict ?? true },
459
+ * nodes: {
460
+ * string: () => 'z.string()',
461
+ * object(node) {
462
+ * const props = node.properties
463
+ * .map((p) => `${p.name}: ${this.transform(p.schema)}`)
464
+ * .join(', ')
465
+ * return `z.object({ ${props} })`
466
+ * },
467
+ * },
468
+ * }))
469
+ * ```
470
+ */
471
+ declare function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
472
+ /**
473
+ * Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.
474
+ *
475
+ * @example
476
+ * ```ts
477
+ * export const defineFunctionPrinter = createPrinterFactory<FunctionParamNode, FunctionParamKind, Partial<Record<FunctionParamKind, FunctionParamNode>>>(
478
+ * (node) => node.kind,
479
+ * )
480
+ * ```
481
+ */
482
+ declare function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | null): <T extends PrinterFactoryOptions>(build: (options: T["options"]) => {
483
+ name: T["name"];
484
+ options: T["options"];
485
+ nodes: Partial<{ [K in TKey]: (this: {
486
+ transform: (node: TNode) => T["output"] | null;
487
+ options: T["options"];
488
+ }, node: TNodeByKey[K]) => T["output"] | null }>;
489
+ print?: (this: {
490
+ transform: (node: TNode) => T["output"] | null;
491
+ options: T["options"];
492
+ }, node: TNode) => T["printOutput"] | null;
493
+ }) => (options?: T["options"]) => {
494
+ name: T["name"];
495
+ options: T["options"];
496
+ transform: (node: TNode) => T["output"] | null;
497
+ print: (node: TNode) => T["printOutput"] | null;
498
+ };
499
+ //#endregion
500
+ //#region src/visitor.d.ts
501
+ /**
502
+ * Ordered mapping of `[NodeType, ParentType]` pairs.
503
+ *
504
+ * `ParentOf` uses this map to find parent types.
505
+ */
506
+ 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]];
507
+ /**
508
+ * Resolves the parent node type for a given AST node type.
509
+ *
510
+ * This is used by visitor context so `ctx.parent` is correctly typed
511
+ * for each callback.
512
+ *
513
+ * @example
514
+ * ```ts
515
+ * type InputParent = ParentOf<InputNode>
516
+ * // undefined
517
+ * ```
518
+ *
519
+ * @example
520
+ * ```ts
521
+ * type PropertyParent = ParentOf<PropertyNode>
522
+ * // SchemaNode
523
+ * ```
524
+ *
525
+ * @example
526
+ * ```ts
527
+ * type SchemaParent = ParentOf<SchemaNode>
528
+ * // InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode
529
+ * ```
530
+ */
531
+ 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;
532
+ /**
533
+ * Traversal context passed as the second argument to every visitor callback.
534
+ * `parent` is typed from the current node type.
535
+ *
536
+ * @example
537
+ * ```ts
538
+ * const visitor: Visitor = {
539
+ * schema(node, { parent }) {
540
+ * // parent type is narrowed by node kind
541
+ * },
542
+ * }
543
+ * ```
544
+ */
545
+ type VisitorContext<T extends Node = Node> = {
546
+ /**
547
+ * Parent node of the currently visited node.
548
+ * For `InputNode`, this is `undefined`.
549
+ */
550
+ parent?: ParentOf<T>;
551
+ };
552
+ /**
553
+ * Synchronous visitor consumed by `transform`. Each optional callback runs
554
+ * for the matching node type. Return a new node to replace it, or `undefined`
555
+ * to leave it untouched.
556
+ *
557
+ * Plugins typically expose `transformer` so users can supply a `Visitor` that
558
+ * rewrites operation IDs, drops descriptions, or otherwise tweaks the AST
559
+ * before printing.
560
+ *
561
+ * @example Prefix every operationId
562
+ * ```ts
563
+ * const visitor: Visitor = {
564
+ * operation(node) {
565
+ * return { ...node, operationId: `api_${node.operationId}` }
566
+ * },
567
+ * }
568
+ * ```
569
+ *
570
+ * @example Strip schema descriptions
571
+ * ```ts
572
+ * const visitor: Visitor = {
573
+ * schema(node) {
574
+ * return { ...node, description: undefined }
575
+ * },
576
+ * }
577
+ * ```
578
+ */
579
+ type Visitor = {
580
+ input?(node: InputNode, context: VisitorContext<InputNode>): undefined | null | InputNode;
581
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): undefined | null | OutputNode;
582
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): undefined | null | OperationNode;
583
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): undefined | null | SchemaNode;
584
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): undefined | null | PropertyNode;
585
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): undefined | null | ParameterNode;
586
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): undefined | null | ResponseNode;
587
+ };
588
+ /**
589
+ * Utility type for values that can be returned directly or asynchronously.
590
+ */
591
+ type MaybePromise<T> = T | Promise<T>;
592
+ /**
593
+ * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.
594
+ *
595
+ * @example
596
+ * ```ts
597
+ * const visitor: AsyncVisitor = {
598
+ * async operation(node) {
599
+ * await Promise.resolve(node.operationId)
600
+ * },
601
+ * }
602
+ * ```
603
+ */
604
+ type AsyncVisitor = {
605
+ input?(node: InputNode, context: VisitorContext<InputNode>): MaybePromise<undefined | null | InputNode>;
606
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): MaybePromise<undefined | null | OutputNode>;
607
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<undefined | null | OperationNode>;
608
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<undefined | null | SchemaNode>;
609
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<undefined | null | PropertyNode>;
610
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<undefined | null | ParameterNode>;
611
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<undefined | null | ResponseNode>;
612
+ };
613
+ /**
614
+ * Visitor used by `collect`.
615
+ *
616
+ * @example
617
+ * ```ts
618
+ * const visitor: CollectVisitor<string> = {
619
+ * operation(node) {
620
+ * return node.operationId
621
+ * },
622
+ * }
623
+ * ```
624
+ */
625
+ type CollectVisitor<T> = {
626
+ input?(node: InputNode, context: VisitorContext<InputNode>): T | null | undefined;
627
+ output?(node: OutputNode, context: VisitorContext<OutputNode>): T | null | undefined;
628
+ operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | null | undefined;
629
+ schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | null | undefined;
630
+ property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | null | undefined;
631
+ parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | null | undefined;
632
+ response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | null | undefined;
633
+ };
634
+ /**
635
+ * Options for `transform`.
636
+ *
637
+ * @example
638
+ * ```ts
639
+ * const options: TransformOptions = { depth: 'deep', schema: (node) => node }
640
+ * ```
641
+ *
642
+ * @example
643
+ * ```ts
644
+ * // Only transform the current node, not nested children
645
+ * const options: TransformOptions = { depth: 'shallow', schema: (node) => node }
646
+ * ```
647
+ */
648
+ type TransformOptions = Visitor & {
649
+ /**
650
+ * Traversal depth (`'deep'` by default).
651
+ * @default 'deep'
652
+ */
653
+ depth?: VisitorDepth;
654
+ /**
655
+ * Internal parent override used during recursion.
656
+ */
657
+ parent?: Node;
658
+ };
659
+ /**
660
+ * Options for `walk`.
661
+ *
662
+ * @example
663
+ * ```ts
664
+ * const options: WalkOptions = { depth: 'deep', concurrency: 10, root: () => {} }
665
+ * ```
666
+ */
667
+ type WalkOptions = AsyncVisitor & {
668
+ /**
669
+ * Traversal depth (`'deep'` by default).
670
+ * @default 'deep'
671
+ */
672
+ depth?: VisitorDepth;
673
+ /**
674
+ * Maximum number of sibling nodes visited concurrently.
675
+ * @default 30
676
+ */
677
+ concurrency?: number;
678
+ };
679
+ /**
680
+ * Options for `collect`.
681
+ *
682
+ * @example
683
+ * ```ts
684
+ * const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }
685
+ * ```
686
+ */
687
+ type CollectOptions<T> = CollectVisitor<T> & {
688
+ /**
689
+ * Traversal depth (`'deep'` by default).
690
+ * @default 'deep'
691
+ */
692
+ depth?: VisitorDepth;
693
+ /**
694
+ * Internal parent override used during recursion.
695
+ */
696
+ parent?: Node;
697
+ };
698
+ /**
699
+ * Async depth-first traversal for side effects. Visitor return values are
700
+ * ignored. Use `transform` when you want to rewrite nodes.
701
+ *
702
+ * Sibling nodes at each depth run concurrently up to `options.concurrency`
703
+ * (defaults to `WALK_CONCURRENCY`). Higher values overlap I/O-bound visitor
704
+ * work. Lower values reduce memory pressure.
705
+ *
706
+ * @example Log every operation
707
+ * ```ts
708
+ * await walk(root, {
709
+ * operation(node) {
710
+ * console.log(node.operationId)
711
+ * },
712
+ * })
713
+ * ```
714
+ *
715
+ * @example Only visit the root node
716
+ * ```ts
717
+ * await walk(root, { depth: 'shallow', input: () => {} })
718
+ * ```
719
+ */
720
+ declare function walk(node: Node, options: WalkOptions): Promise<void>;
721
+ /**
722
+ * Synchronous depth-first transform. Each visitor callback gets a chance to
723
+ * return a replacement node; `undefined` keeps the original.
724
+ *
725
+ * The transform is immutable. The original tree is not mutated. A new tree
726
+ * is returned. Use `depth: 'shallow'` to skip recursion into children.
727
+ *
728
+ * @example Prefix every operationId
729
+ * ```ts
730
+ * const next = transform(root, {
731
+ * operation(node) {
732
+ * return { ...node, operationId: `prefixed_${node.operationId}` }
733
+ * },
734
+ * })
735
+ * ```
736
+ *
737
+ * @example Replace only the root node
738
+ * ```ts
739
+ * const next = transform(root, {
740
+ * depth: 'shallow',
741
+ * input: (node) => ({ ...node, meta: { ...node.meta, title: 'Rewritten' } }),
742
+ * })
743
+ * ```
744
+ */
745
+ declare function transform(node: InputNode, options: TransformOptions): InputNode;
746
+ declare function transform(node: OutputNode, options: TransformOptions): OutputNode;
747
+ declare function transform(node: OperationNode, options: TransformOptions): OperationNode;
748
+ declare function transform(node: SchemaNode, options: TransformOptions): SchemaNode;
749
+ declare function transform(node: PropertyNode, options: TransformOptions): PropertyNode;
750
+ declare function transform(node: ParameterNode, options: TransformOptions): ParameterNode;
751
+ declare function transform(node: ResponseNode, options: TransformOptions): ResponseNode;
752
+ declare function transform(node: Node, options: TransformOptions): Node;
753
+ /**
754
+ * Eager depth-first collection pass. Returns an array of every non-null value
755
+ * the visitor callbacks return.
756
+ *
757
+ * @example Collect every operationId
758
+ * ```ts
759
+ * const ids = collect<string>(root, {
760
+ * operation(node) {
761
+ * return node.operationId
762
+ * },
763
+ * })
764
+ * ```
765
+ */
766
+ declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
767
+ //#endregion
768
+ export { applyDedupe as _, transform as a, schemaTypes as b, PrinterFactoryOptions as c, definePrinter as d, SchemaDialect as f, DedupePlan as g, DedupeLookups as h, collect as i, PrinterPartial as l, DedupeCanonical as m, Visitor as n, walk as o, defineSchemaDialect as p, VisitorContext as r, Printer as s, ParentOf as t, createPrinterFactory as u, buildDedupePlan as v, httpMethods as y };
769
+ //# sourceMappingURL=types-CB2oY8Dw.d.ts.map