@kubb/ast 5.0.0-alpha.15 → 5.0.0-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,961 +0,0 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
-
3
- //#region src/constants.d.ts
4
- /**
5
- * Depth for schema traversal in visitor functions.
6
- */
7
- type VisitorDepth = 'shallow' | 'deep';
8
- declare const nodeKinds: {
9
- readonly root: "Root";
10
- readonly operation: "Operation";
11
- readonly schema: "Schema";
12
- readonly property: "Property";
13
- readonly parameter: "Parameter";
14
- readonly response: "Response";
15
- readonly functionParameter: "FunctionParameter";
16
- readonly objectBindingParameter: "ObjectBindingParameter";
17
- readonly functionParameters: "FunctionParameters";
18
- };
19
- declare const schemaTypes: {
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
- readonly boolean: "boolean";
34
- readonly null: "null";
35
- readonly any: "any";
36
- readonly unknown: "unknown";
37
- readonly void: "void";
38
- readonly object: "object";
39
- readonly array: "array";
40
- readonly tuple: "tuple";
41
- readonly union: "union";
42
- readonly intersection: "intersection";
43
- readonly enum: "enum";
44
- readonly ref: "ref";
45
- readonly date: "date";
46
- readonly datetime: "datetime";
47
- readonly time: "time";
48
- readonly uuid: "uuid";
49
- readonly email: "email";
50
- readonly url: "url";
51
- readonly blob: "blob";
52
- readonly never: "never";
53
- };
54
- declare const httpMethods: {
55
- readonly get: "GET";
56
- readonly post: "POST";
57
- readonly put: "PUT";
58
- readonly patch: "PATCH";
59
- readonly delete: "DELETE";
60
- readonly head: "HEAD";
61
- readonly options: "OPTIONS";
62
- readonly trace: "TRACE";
63
- };
64
- declare const mediaTypes: {
65
- readonly applicationJson: "application/json";
66
- readonly applicationXml: "application/xml";
67
- readonly applicationFormUrlEncoded: "application/x-www-form-urlencoded";
68
- readonly applicationOctetStream: "application/octet-stream";
69
- readonly applicationPdf: "application/pdf";
70
- readonly applicationZip: "application/zip";
71
- readonly applicationGraphql: "application/graphql";
72
- readonly multipartFormData: "multipart/form-data";
73
- readonly textPlain: "text/plain";
74
- readonly textHtml: "text/html";
75
- readonly textCsv: "text/csv";
76
- readonly textXml: "text/xml";
77
- readonly imagePng: "image/png";
78
- readonly imageJpeg: "image/jpeg";
79
- readonly imageGif: "image/gif";
80
- readonly imageWebp: "image/webp";
81
- readonly imageSvgXml: "image/svg+xml";
82
- readonly audioMpeg: "audio/mpeg";
83
- readonly videoMp4: "video/mp4";
84
- };
85
- //#endregion
86
- //#region src/nodes/base.d.ts
87
- /**
88
- * Kind discriminant for every AST node.
89
- */
90
- type NodeKind = 'Root' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'FunctionParameter' | 'ObjectBindingParameter' | 'FunctionParameters';
91
- /**
92
- * Common base for all AST nodes.
93
- */
94
- type BaseNode = {
95
- kind: NodeKind;
96
- };
97
- //#endregion
98
- //#region src/nodes/function.d.ts
99
- /**
100
- * A single named function parameter.
101
- *
102
- * @example Simple required param
103
- * `name: Type`
104
- *
105
- * @example Optional param
106
- * `name?: Type`
107
- *
108
- * @example Param with default
109
- * `name: Type = defaultValue`
110
- *
111
- * @example Rest / spread param
112
- * `...name: Type[]`
113
- */
114
- type FunctionParameterNode = BaseNode & {
115
- kind: 'FunctionParameter';
116
- /**
117
- * The parameter name as it appears in the function signature.
118
- */
119
- name: string;
120
- /**
121
- * TypeScript type annotation (raw string, e.g. `"string"`, `"Pet[]"`, `"Partial<Config>"`).
122
- * Omit for untyped JavaScript output.
123
- */
124
- type?: string;
125
- /**
126
- * When `true` the parameter is emitted as a rest parameter (`...name`).
127
- * @default false
128
- */
129
- rest?: boolean;
130
- }
131
- /**
132
- * Explicitly optional parameter — rendered with `?` in the signature.
133
- * Cannot be combined with `default`; a parameter with a default is implicitly optional.
134
- * @example `name?: Type`
135
- */
136
- & ({
137
- optional: true;
138
- default?: never;
139
- }
140
- /**
141
- * Required parameter, or a parameter with a default value (implicitly optional).
142
- * @example Required: `name: Type`
143
- * @example With default: `name: Type = default`
144
- */
145
- | {
146
- optional?: false;
147
- default?: string;
148
- });
149
- /**
150
- * An object-destructured function parameter group.
151
- *
152
- * Renders as `{ key1, key2 }: { key1: Type1; key2: Type2 } = {}` in a declaration,
153
- * or as individual top-level params when `inline` is `true`.
154
- *
155
- * Replaces `mode: 'object'` / `mode: 'inlineSpread'` from the legacy `FunctionParams` API.
156
- *
157
- * @example Object destructuring with auto-computed type (declaration)
158
- * `{ id, name }: { id: string; name: string } = {}`
159
- *
160
- * @example Inline (spread) — children emitted as individual top-level params
161
- * `id: string, name: string`
162
- */
163
- type ObjectBindingParameterNode = BaseNode & {
164
- kind: 'ObjectBindingParameter';
165
- /**
166
- * The individual parameters that form the destructured object.
167
- * Rendered as `{ key1, key2 }` in declarations, or spread inline when `inline` is `true`.
168
- */
169
- properties: Array<FunctionParameterNode>;
170
- /**
171
- * Explicit TypeScript type annotation for the whole object param.
172
- * When absent the printer auto-computes `{ key1: Type1; key2: Type2 }` from `params`.
173
- */
174
- type?: string;
175
- /**
176
- * When `true` the `params` are emitted as individual top-level parameters instead of
177
- * being wrapped in a destructuring pattern (`{ key1, key2 }`).
178
- *
179
- * Equivalent to `mode: 'inlineSpread'` in the legacy `FunctionParams` API.
180
- * @default false
181
- */
182
- inline?: boolean;
183
- /**
184
- * Whether the whole object group is optional.
185
- * When absent the printer auto-computes this: optional if every child param is optional.
186
- */
187
- optional?: boolean;
188
- /**
189
- * Default value for the object group, written verbatim after `=`.
190
- * Commonly `'{}'` to allow omitting the argument entirely.
191
- */
192
- default?: string;
193
- };
194
- /**
195
- * A complete ordered parameter list for a function.
196
- *
197
- * The printer is responsible for sorting (required → optional → has-default).
198
- * Nodes themselves are treated as plain, immutable data.
199
- *
200
- * Renders differently depending on the output mode:
201
- * - `declaration` → `(id: string, config: Config = {})` — typed function parameter list
202
- * - `call` → `(id, { method, url })` — function call arguments
203
- * - `keys` → `{ id, config }` — key names only (for destructuring)
204
- * - `values` → `{ id: id, config: config }` — key → value pairs
205
- */
206
- type FunctionParametersNode = BaseNode & {
207
- kind: 'FunctionParameters';
208
- params: Array<FunctionParameterNode | ObjectBindingParameterNode>;
209
- };
210
- /**
211
- * The three function-signature AST node variants.
212
- */
213
- type FunctionNode = FunctionParameterNode | ObjectBindingParameterNode | FunctionParametersNode;
214
- /**
215
- * Handler map keys — one per `FunctionNode` kind.
216
- */
217
- type FunctionNodeType = 'functionParameter' | 'objectBindingParameter' | 'functionParameters';
218
- //#endregion
219
- //#region src/nodes/property.d.ts
220
- /**
221
- * A named property within an object schema.
222
- */
223
- type PropertyNode = BaseNode & {
224
- kind: 'Property';
225
- name: string;
226
- schema: SchemaNode;
227
- required: boolean;
228
- };
229
- //#endregion
230
- //#region src/nodes/schema.d.ts
231
- type PrimitiveSchemaType = 'string' | 'number' | 'integer' | 'bigint' | 'boolean' | 'null' | 'any' | 'unknown' | 'void' | 'never' | 'object' | 'array' | 'date';
232
- type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum';
233
- /**
234
- * Semantic types requiring special handling in code generation (e.g. generating a `Date` object or a branded type).
235
- */
236
- type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'blob';
237
- type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchemaType;
238
- type ScalarSchemaType = Exclude<SchemaType, 'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint' | 'url'>;
239
- /**
240
- * Base fields shared by every schema variant. Does not include spec-specific fields.
241
- */
242
- type SchemaNodeBase = BaseNode & {
243
- kind: 'Schema';
244
- /**
245
- * Named schema identifier (e.g. `"Pet"` from `#/components/schemas/Pet`). `undefined` for inline schemas.
246
- */
247
- name?: string;
248
- title?: string;
249
- description?: string;
250
- nullable?: boolean;
251
- optional?: boolean;
252
- /**
253
- * Both optional and nullable (`optional` + `nullable`).
254
- */
255
- nullish?: boolean;
256
- deprecated?: boolean;
257
- readOnly?: boolean;
258
- writeOnly?: boolean;
259
- default?: unknown;
260
- example?: unknown;
261
- /**
262
- * Underlying primitive before format/semantic promotion (e.g. `'string'` for a `uuid` node).
263
- */
264
- primitive?: PrimitiveSchemaType;
265
- };
266
- /**
267
- * Object schema with ordered property definitions.
268
- */
269
- type ObjectSchemaNode = SchemaNodeBase & {
270
- type: 'object';
271
- properties: Array<PropertyNode>;
272
- /**
273
- * `true` allows any value; a `SchemaNode` constrains it; absent means not permitted.
274
- */
275
- additionalProperties?: SchemaNode | true;
276
- patternProperties?: Record<string, SchemaNode>;
277
- };
278
- /**
279
- * Array or tuple schema.
280
- */
281
- type ArraySchemaNode = SchemaNodeBase & {
282
- type: 'array' | 'tuple';
283
- items?: Array<SchemaNode>;
284
- /**
285
- * Additional items beyond positional `items` in a tuple.
286
- */
287
- rest?: SchemaNode;
288
- min?: number;
289
- max?: number;
290
- unique?: boolean;
291
- };
292
- /**
293
- * Shared base for union and intersection schemas.
294
- */
295
- type CompositeSchemaNodeBase = SchemaNodeBase & {
296
- members?: Array<SchemaNode>;
297
- };
298
- /**
299
- * Union schema (`oneOf` / `anyOf`).
300
- */
301
- type UnionSchemaNode = CompositeSchemaNodeBase & {
302
- type: 'union';
303
- /**
304
- * Discriminator property from OAS `discriminator.propertyName`.
305
- */
306
- discriminatorPropertyName?: string;
307
- };
308
- /**
309
- * Intersection schema (`allOf`).
310
- */
311
- type IntersectionSchemaNode = CompositeSchemaNodeBase & {
312
- type: 'intersection';
313
- };
314
- /**
315
- * A named enum variant.
316
- */
317
- type EnumValueNode = {
318
- name: string;
319
- value: string | number | boolean;
320
- format: 'string' | 'number' | 'boolean';
321
- };
322
- /**
323
- * Enum schema.
324
- */
325
- type EnumSchemaNode = SchemaNodeBase & {
326
- type: 'enum';
327
- /**
328
- * Enum member type. Generators should use const assertions for `'number'` / `'boolean'`.
329
- */
330
- enumType?: 'string' | 'number' | 'boolean';
331
- /**
332
- * Allowed values (simple form).
333
- */
334
- enumValues?: Array<string | number | boolean | null>;
335
- /**
336
- * Named variants (rich form). Takes priority over `enumValues` when present.
337
- */
338
- namedEnumValues?: Array<EnumValueNode>;
339
- };
340
- /**
341
- * Ref schema — pointer to another schema definition.
342
- */
343
- type RefSchemaNode = SchemaNodeBase & {
344
- type: 'ref';
345
- name?: string;
346
- /**
347
- * Original `$ref` path (e.g. `#/components/schemas/Order`). Used for name resolution.
348
- */
349
- ref?: string;
350
- /**
351
- * Pattern constraint propagated from a sibling `pattern` field next to the `$ref`.
352
- */
353
- pattern?: string;
354
- };
355
- /**
356
- * Datetime schema.
357
- */
358
- type DatetimeSchemaNode = SchemaNodeBase & {
359
- type: 'datetime';
360
- /**
361
- * Includes timezone offset (`dateType: 'stringOffset'`).
362
- */
363
- offset?: boolean;
364
- /**
365
- * Local datetime without timezone (`dateType: 'stringLocal'`).
366
- */
367
- local?: boolean;
368
- };
369
- /**
370
- * Base for `date` and `time` schemas.
371
- */
372
- type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
373
- type: T;
374
- /**
375
- * Representation in generated code: native `Date` or plain string.
376
- */
377
- representation: 'date' | 'string';
378
- };
379
- /**
380
- * Date schema.
381
- */
382
- type DateSchemaNode = TemporalSchemaNodeBase<'date'>;
383
- /**
384
- * Time schema.
385
- */
386
- type TimeSchemaNode = TemporalSchemaNodeBase<'time'>;
387
- /**
388
- * String schema.
389
- */
390
- type StringSchemaNode = SchemaNodeBase & {
391
- type: 'string';
392
- min?: number;
393
- max?: number;
394
- pattern?: string;
395
- };
396
- /**
397
- * Number, integer, or bigint schema.
398
- */
399
- type NumberSchemaNode = SchemaNodeBase & {
400
- type: 'number' | 'integer' | 'bigint';
401
- min?: number;
402
- max?: number;
403
- exclusiveMinimum?: number;
404
- exclusiveMaximum?: number;
405
- };
406
- /**
407
- * Schema for scalar types with no additional constraints.
408
- */
409
- type ScalarSchemaNode = SchemaNodeBase & {
410
- type: ScalarSchemaType;
411
- };
412
- /**
413
- * URL schema, optionally carrying an Express-style path template for template literal generation.
414
- */
415
- type UrlSchemaNode = SchemaNodeBase & {
416
- type: 'url';
417
- /**
418
- * Express-style path (e.g. `'/pets/:petId'`). When set, printers may emit a template literal type.
419
- */
420
- path?: string;
421
- };
422
- /**
423
- * Maps each schema type string to its `SchemaNode` variant. Used by `narrowSchema`.
424
- */
425
- type SchemaNodeByType = {
426
- object: ObjectSchemaNode;
427
- array: ArraySchemaNode;
428
- tuple: ArraySchemaNode;
429
- union: UnionSchemaNode;
430
- intersection: IntersectionSchemaNode;
431
- enum: EnumSchemaNode;
432
- ref: RefSchemaNode;
433
- datetime: DatetimeSchemaNode;
434
- date: DateSchemaNode;
435
- time: TimeSchemaNode;
436
- string: StringSchemaNode;
437
- number: NumberSchemaNode;
438
- integer: NumberSchemaNode;
439
- bigint: NumberSchemaNode;
440
- boolean: ScalarSchemaNode;
441
- null: ScalarSchemaNode;
442
- any: ScalarSchemaNode;
443
- unknown: ScalarSchemaNode;
444
- void: ScalarSchemaNode;
445
- never: ScalarSchemaNode;
446
- uuid: ScalarSchemaNode;
447
- email: ScalarSchemaNode;
448
- url: UrlSchemaNode;
449
- blob: ScalarSchemaNode;
450
- };
451
- /**
452
- * Discriminated union of all schema variants.
453
- */
454
- type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | ScalarSchemaNode;
455
- //#endregion
456
- //#region src/nodes/parameter.d.ts
457
- type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
458
- /**
459
- * A single input parameter for an operation.
460
- */
461
- type ParameterNode = BaseNode & {
462
- kind: 'Parameter';
463
- name: string;
464
- in: ParameterLocation;
465
- schema: SchemaNode;
466
- required: boolean;
467
- };
468
- //#endregion
469
- //#region src/nodes/http.d.ts
470
- /**
471
- * All IANA-registered HTTP status codes as string literals, matching how
472
- * they appear as keys in API specifications (e.g. `"200"`, `"404"`).
473
- */
474
- 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';
475
- /**
476
- * A status code as used in an operation response: a specific HTTP status
477
- * code string or `"default"` as a catch-all fallback.
478
- */
479
- type StatusCode = HttpStatusCode | 'default';
480
- /**
481
- * Common IANA media types used in API request/response bodies.
482
- */
483
- type MediaType = 'application/json' | 'application/xml' | 'application/x-www-form-urlencoded' | 'application/octet-stream' | 'application/pdf' | 'application/zip' | 'application/graphql' | 'multipart/form-data' | 'text/plain' | 'text/html' | 'text/csv' | 'text/xml' | 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp' | 'image/svg+xml' | 'audio/mpeg' | 'video/mp4';
484
- //#endregion
485
- //#region src/nodes/response.d.ts
486
- /**
487
- * A single response variant for an operation.
488
- */
489
- type ResponseNode = BaseNode & {
490
- kind: 'Response';
491
- /**
492
- * HTTP status code or `'default'` for a fallback response.
493
- */
494
- statusCode: StatusCode;
495
- description?: string;
496
- schema: SchemaNode;
497
- mediaType?: MediaType;
498
- /**
499
- * Property keys to exclude from the generated type via `Omit<Type, Keys>`.
500
- * Populated when the response schema is a `$ref` and the referenced schema has
501
- * `writeOnly` properties that should not appear in response types.
502
- */
503
- keysToOmit?: Array<string>;
504
- };
505
- //#endregion
506
- //#region src/nodes/operation.d.ts
507
- type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
508
- /**
509
- * A spec-agnostic representation of a single API operation.
510
- */
511
- type OperationNode = BaseNode & {
512
- kind: 'Operation';
513
- /**
514
- * Unique operation identifier (maps to `operationId` in OAS).
515
- */
516
- operationId: string;
517
- method: HttpMethod;
518
- /**
519
- * Express-style path string, e.g. `/pets/:petId`.
520
- * Derived from the OpenAPI path by converting `{param}` tokens to `:param`.
521
- */
522
- path: string;
523
- tags: Array<string>;
524
- summary?: string;
525
- description?: string;
526
- deprecated?: boolean;
527
- parameters: Array<ParameterNode>;
528
- /**
529
- * Request body for OAS operations. Bundles the schema with optional keys to exclude.
530
- */
531
- requestBody?: {
532
- /**
533
- * Human-readable description of the request body (maps to `requestBody.description` in OAS).
534
- */
535
- description?: string;
536
- /**
537
- * The request body schema. For OAS, this is the schema of the first content entry.
538
- */
539
- schema?: SchemaNode;
540
- /**
541
- * Property keys to exclude from the generated request body type via `Omit<Type, Keys>`.
542
- * Populated when the schema is a `$ref` and the referenced schema has `readOnly` properties
543
- * that should not appear in request types.
544
- */
545
- keysToOmit?: Array<string>;
546
- };
547
- responses: Array<ResponseNode>;
548
- };
549
- //#endregion
550
- //#region src/nodes/root.d.ts
551
- /**
552
- * Format-agnostic metadata about the API document.
553
- * Adapters populate whichever fields are available in their source format.
554
- */
555
- type RootMeta = {
556
- /**
557
- * API title (from `info.title` in OAS/AsyncAPI).
558
- */
559
- title?: string;
560
- /**
561
- * API description (from `info.description` in OAS/AsyncAPI).
562
- */
563
- description?: string;
564
- /**
565
- * API version string (from `info.version` in OAS/AsyncAPI).
566
- */
567
- version?: string;
568
- /**
569
- * Resolved base URL for the API.
570
- * OAS: derived from `servers[serverIndex].url` with variable substitution.
571
- * AsyncAPI: derived from `servers[serverIndex].url`.
572
- * Drizzle / schema-only formats: not set.
573
- */
574
- baseURL?: string;
575
- };
576
- /**
577
- * Top-level container for all schemas and operations in a single API document.
578
- */
579
- type RootNode = BaseNode & {
580
- kind: 'Root';
581
- schemas: Array<SchemaNode>;
582
- operations: Array<OperationNode>;
583
- /**
584
- * Format-agnostic document metadata populated by the adapter.
585
- */
586
- meta?: RootMeta;
587
- };
588
- //#endregion
589
- //#region src/nodes/index.d.ts
590
- /**
591
- * Discriminated union of every AST node.
592
- *
593
- * Using a concrete union (instead of the bare `BaseNode` alias) lets
594
- * TypeScript narrow the type automatically inside `switch (node.kind)`
595
- * blocks, eliminating the need for manual `as TypeName` casts.
596
- */
597
- type Node = RootNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | FunctionNode;
598
- //#endregion
599
- //#region src/factory.d.ts
600
- /**
601
- * Distributive variant of `Omit` that preserves union members.
602
- */
603
- type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
604
- /**
605
- * Creates a `RootNode`.
606
- */
607
- declare function createRoot(overrides?: Partial<Omit<RootNode, 'kind'>>): RootNode;
608
- /**
609
- * Creates an `OperationNode`.
610
- */
611
- declare function createOperation(props: Pick<OperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<OperationNode, 'kind' | 'operationId' | 'method' | 'path'>>): OperationNode;
612
- /**
613
- * Creates a `SchemaNode`, narrowed to the variant of `props.type`.
614
- * For object schemas, `properties` defaults to `[]` when not provided.
615
- */
616
- declare function createSchema<T extends Omit<ObjectSchemaNode, 'kind' | 'properties'> & {
617
- properties?: Array<PropertyNode>;
618
- }>(props: T): Omit<T, 'properties'> & {
619
- properties: Array<PropertyNode>;
620
- kind: 'Schema';
621
- };
622
- declare function createSchema<T extends DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>>(props: T): T & {
623
- kind: 'Schema';
624
- };
625
- declare function createSchema(props: DistributiveOmit<SchemaNode, 'kind'>): SchemaNode;
626
- /**
627
- * Derives `schema.optional` and `schema.nullish` from `required` and `schema.nullable`.
628
- * This keeps `PropertyNode.required` as the single source of truth for optionality.
629
- */
630
- declare function syncPropertySchema(required: boolean, schema: SchemaNode): SchemaNode;
631
- /**
632
- * Creates a `PropertyNode`. `required` defaults to `false`.
633
- * `schema.optional` and `schema.nullish` are auto-derived from `required` and `schema.nullable`.
634
- */
635
- declare function createProperty(props: Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>): PropertyNode;
636
- /**
637
- * Creates a `ParameterNode`. `required` defaults to `false`.
638
- * `schema.optional` is auto-derived from `required` and `schema.nullable`.
639
- */
640
- declare function createParameter(props: Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>): ParameterNode;
641
- /**
642
- * Creates a `ResponseNode`.
643
- */
644
- declare function createResponse(props: Pick<ResponseNode, 'statusCode' | 'schema'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'schema'>>): ResponseNode;
645
- /**
646
- * Creates a `FunctionParameterNode`. `optional` defaults to `false`.
647
- *
648
- * @example Required typed param
649
- * ```ts
650
- * createFunctionParameter({ name: 'petId', type: 'string' })
651
- * // → petId: string
652
- * ```
653
- *
654
- * @example Optional param
655
- * ```ts
656
- * createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })
657
- * // → params?: QueryParams
658
- * ```
659
- *
660
- * @example Param with default (implicitly optional — cannot combine with `optional: true`)
661
- * ```ts
662
- * createFunctionParameter({ name: 'config', type: 'RequestConfig', default: '{}' })
663
- * // → config: RequestConfig = {}
664
- * ```
665
- */
666
- declare function createFunctionParameter(props: {
667
- name: string;
668
- type?: string;
669
- rest?: boolean;
670
- } & ({
671
- optional: true;
672
- default?: never;
673
- } | {
674
- optional?: false;
675
- default?: string;
676
- })): FunctionParameterNode;
677
- /**
678
- * Creates an `ObjectBindingParameterNode` — an object-destructured parameter group.
679
- *
680
- * @example Destructured object param
681
- * ```ts
682
- * createObjectBindingParameter({
683
- * properties: [
684
- * createFunctionParameter({ name: 'id', type: 'string', optional: false }),
685
- * createFunctionParameter({ name: 'name', type: 'string', optional: true }),
686
- * ],
687
- * default: '{}',
688
- * })
689
- * // declaration → { id, name? }: { id: string; name?: string } = {}
690
- * // call → { id, name }
691
- * ```
692
- *
693
- * @example Inline — children emitted as individual top-level params
694
- * ```ts
695
- * createObjectBindingParameter({
696
- * properties: [createFunctionParameter({ name: 'petId', type: 'string', optional: false })],
697
- * inline: true,
698
- * })
699
- * // declaration → petId: string
700
- * // call → petId
701
- * ```
702
- */
703
- declare function createObjectBindingParameter(props: Pick<ObjectBindingParameterNode, 'properties'> & Partial<Omit<ObjectBindingParameterNode, 'kind' | 'properties'>>): ObjectBindingParameterNode;
704
- /**
705
- * Creates a `FunctionParametersNode` from an ordered list of params.
706
- *
707
- * @example
708
- * ```ts
709
- * createFunctionParameters({
710
- * params: [
711
- * createFunctionParameter({ name: 'petId', type: 'string', optional: false }),
712
- * createFunctionParameter({ name: 'config', type: 'RequestConfig', optional: false, default: '{}' }),
713
- * ],
714
- * })
715
- * ```
716
- */
717
- declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
718
- //#endregion
719
- //#region src/printer.d.ts
720
- /**
721
- * Handler context for `definePrinter` — mirrors `PluginContext` from `@kubb/core`.
722
- * Available as `this` inside each node handler and the optional root-level `print`.
723
- * `this.print` always dispatches to the `nodes` handlers (node-level printer).
724
- */
725
- type PrinterHandlerContext<TOutput, TOptions extends object> = {
726
- /**
727
- * Recursively print a nested `SchemaNode` using the node-level handlers.
728
- */
729
- print: (node: SchemaNode) => TOutput | null | undefined;
730
- /**
731
- * Options for this printer instance.
732
- */
733
- options: TOptions;
734
- };
735
- /**
736
- * Handler for a specific `SchemaNode` variant identified by `SchemaType` key `T`.
737
- * Use a regular function (not an arrow function) so that `this` is available.
738
- */
739
- type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null | undefined;
740
- /**
741
- * Shape of the type parameter passed to `definePrinter`.
742
- * Mirrors `AdapterFactoryOptions` / `PluginFactoryOptions` from `@kubb/core`.
743
- *
744
- * - `TName` — unique string identifier (e.g. `'zod'`, `'ts'`)
745
- * - `TOptions` — options passed to and stored on the printer
746
- * - `TOutput` — the type emitted by node handlers
747
- * - `TPrintOutput` — the type emitted by the public `print` override (defaults to `TOutput`)
748
- */
749
- type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
750
- name: TName;
751
- options: TOptions;
752
- output: TOutput;
753
- printOutput: TPrintOutput;
754
- };
755
- /**
756
- * The object returned by calling a `definePrinter` instance.
757
- */
758
- type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
759
- /**
760
- * Unique identifier supplied at creation time.
761
- */
762
- name: T['name'];
763
- /**
764
- * Options for this printer instance.
765
- */
766
- options: T['options'];
767
- /**
768
- * Public printer. If the builder provides a root-level `print`, this calls that
769
- * higher-level function (which may produce full declarations). Otherwise falls back
770
- * to the node-level dispatcher
771
- */
772
- print: (node: SchemaNode) => T['printOutput'] | null | undefined;
773
- };
774
- /**
775
- * Builder function passed to `definePrinter`. Receives the resolved options and returns the
776
- * printer configuration: a unique `name`, the stored `options`, node-level `nodes` handlers,
777
- * and an optional root-level `print` override.
778
- */
779
- type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
780
- name: T['name'];
781
- /**
782
- * Options to store on the printer.
783
- */
784
- options: T['options'];
785
- nodes: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
786
- /**
787
- * Optional root-level print override. When provided, becomes the public `printer.print`.
788
- * `this.print(node)` inside this function calls the node-level dispatcher (`nodes` handlers),
789
- * not the override itself — so recursion is safe.
790
- */
791
- print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null | undefined;
792
- };
793
- /**
794
- * Creates a named printer factory. Mirrors the `createPlugin` / `createAdapter` pattern
795
- * from `@kubb/core` — wraps a builder to make options optional and separates raw options
796
- * from resolved options.
797
- *
798
- * The builder receives resolved options and returns:
799
- * - `name` — a unique identifier for the printer
800
- * - `options` — options stored on the returned printer instance
801
- * - `nodes` — a map of `SchemaType` → handler functions that convert a `SchemaNode` to `TOutput`
802
- * - `print` _(optional)_ — a root-level override that becomes the public `printer.print`.
803
- * Inside it, `this.print(node)` still dispatches to the `nodes` map — safe recursion, no infinite loop.
804
- *
805
- * When no `print` override is provided, `printer.print` is the node-level dispatcher directly.
806
- *
807
- * @example Basic usage — Zod schema printer
808
- * ```ts
809
- * type ZodPrinter = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
810
- *
811
- * export const zodPrinter = definePrinter<ZodPrinter>((options) => ({
812
- * name: 'zod',
813
- * options: { strict: options.strict ?? true },
814
- * nodes: {
815
- * string: () => 'z.string()',
816
- * object(node) {
817
- * const props = node.properties.map(p => `${p.name}: ${this.print(p.schema)}`).join(', ')
818
- * return `z.object({ ${props} })`
819
- * },
820
- * },
821
- * }))
822
- * ```
823
- *
824
- * @example With a root-level `print` override to wrap output in a full declaration
825
- * ```ts
826
- * type TsPrinter = PrinterFactoryOptions<'ts', { typeName?: string }, ts.TypeNode, ts.Node>
827
- *
828
- * export const printerTs = definePrinter<TsPrinter>((options) => ({
829
- * name: 'ts',
830
- * options,
831
- * nodes: { string: () => factory.keywordTypeNodes.string },
832
- * print(node) {
833
- * const type = this.print(node) // calls the node-level dispatcher
834
- * if (!type || !this.options.typeName) return type
835
- * return factory.createTypeAliasDeclaration(this.options.typeName, type)
836
- * },
837
- * }))
838
- * ```
839
- */
840
- declare function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
841
- //#endregion
842
- //#region src/refs.d.ts
843
- /**
844
- * Schema name to `SchemaNode` mapping.
845
- */
846
- type RefMap = Map<string, SchemaNode>;
847
- /**
848
- * Indexes named schemas from `root.schemas` by name. Unnamed schemas are skipped.
849
- */
850
- declare function buildRefMap(root: RootNode): RefMap;
851
- /**
852
- * Looks up a schema by name. Prefer over `RefMap.get()` to keep the resolution strategy swappable.
853
- */
854
- declare function resolveRef(refMap: RefMap, ref: string): SchemaNode | undefined;
855
- /**
856
- * Converts a `RefMap` to a plain object.
857
- */
858
- declare function refMapToObject(refMap: RefMap): Record<string, SchemaNode>;
859
- //#endregion
860
- //#region src/visitor.d.ts
861
- /**
862
- * Single source of truth: ordered list of `[NodeType, ParentType]` pairs
863
- * describing which node types can be the parent of a given node in the AST.
864
- *
865
- * `ParentOf` walks this tuple and returns the parent type of the first matching entry.
866
- */
867
- type ParentNodeMap = [[RootNode, undefined], [OperationNode, RootNode], [SchemaNode, RootNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode], [PropertyNode, SchemaNode], [ParameterNode, OperationNode], [ResponseNode, OperationNode]];
868
- 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;
869
- /**
870
- * Traversal context passed as the second argument to every visitor callback.
871
- * The `parent` field is narrowed based on the node type being visited.
872
- */
873
- type VisitorContext<T extends Node = Node> = {
874
- parent?: ParentOf<T>;
875
- };
876
- /**
877
- * Synchronous visitor for `transform` and `walk`.
878
- */
879
- type Visitor = {
880
- root?(node: RootNode, context: VisitorContext<RootNode>): void | RootNode;
881
- operation?(node: OperationNode, context: VisitorContext<OperationNode>): void | OperationNode;
882
- schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): void | SchemaNode;
883
- property?(node: PropertyNode, context: VisitorContext<PropertyNode>): void | PropertyNode;
884
- parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): void | ParameterNode;
885
- response?(node: ResponseNode, context: VisitorContext<ResponseNode>): void | ResponseNode;
886
- };
887
- type MaybePromise<T> = T | Promise<T>;
888
- /**
889
- * Async visitor for `walk`. Synchronous `Visitor` objects are compatible.
890
- */
891
- type AsyncVisitor = {
892
- root?(node: RootNode, context: VisitorContext<RootNode>): MaybePromise<void | RootNode>;
893
- operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<void | OperationNode>;
894
- schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<void | SchemaNode>;
895
- property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<void | PropertyNode>;
896
- parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): MaybePromise<void | ParameterNode>;
897
- response?(node: ResponseNode, context: VisitorContext<ResponseNode>): MaybePromise<void | ResponseNode>;
898
- };
899
- /**
900
- * Visitor for `collect`.
901
- */
902
- type CollectVisitor<T> = {
903
- root?(node: RootNode, context: VisitorContext<RootNode>): T | undefined;
904
- operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | undefined;
905
- schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | undefined;
906
- property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | undefined;
907
- parameter?(node: ParameterNode, context: VisitorContext<ParameterNode>): T | undefined;
908
- response?(node: ResponseNode, context: VisitorContext<ResponseNode>): T | undefined;
909
- };
910
- /**
911
- * Options for `transform` and `collect`. Extends `Visitor` with traversal settings.
912
- */
913
- type TransformOptions = Visitor & {
914
- depth?: VisitorDepth;
915
- parent?: Node;
916
- };
917
- /**
918
- * Options for `walk`. Extends `AsyncVisitor` with traversal settings.
919
- */
920
- type WalkOptions = AsyncVisitor & {
921
- depth?: VisitorDepth;
922
- /**
923
- * Maximum number of sibling nodes visited concurrently.
924
- * @default 30
925
- */
926
- concurrency?: number;
927
- };
928
- /**
929
- * Options for `collect`. Extends `CollectVisitor` with traversal settings.
930
- */
931
- type CollectOptions<T> = CollectVisitor<T> & {
932
- depth?: VisitorDepth;
933
- parent?: Node;
934
- };
935
- /**
936
- * Depth-first traversal for side effects. Visitor return values are ignored.
937
- * Sibling nodes at each level are visited concurrently up to `options.concurrency` (default: 30).
938
- */
939
- declare function walk(node: Node, options: WalkOptions): Promise<void>;
940
- /**
941
- * Depth-first immutable transformation. Visitor return values replace nodes; `undefined` keeps the original.
942
- */
943
- declare function transform(node: RootNode, options: TransformOptions): RootNode;
944
- declare function transform(node: OperationNode, options: TransformOptions): OperationNode;
945
- declare function transform(node: SchemaNode, options: TransformOptions): SchemaNode;
946
- declare function transform(node: PropertyNode, options: TransformOptions): PropertyNode;
947
- declare function transform(node: ParameterNode, options: TransformOptions): ParameterNode;
948
- declare function transform(node: ResponseNode, options: TransformOptions): ResponseNode;
949
- declare function transform(node: Node, options: TransformOptions): Node;
950
- /**
951
- * Combines multiple visitors into a single visitor that applies them sequentially (left to right).
952
- * For each node kind, the output of one visitor becomes the input of the next.
953
- */
954
- declare function composeTransformers(...visitors: Array<Visitor>): Visitor;
955
- /**
956
- * Depth-first synchronous reduction. Collects non-`undefined` visitor return values into an array.
957
- */
958
- declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
959
- //#endregion
960
- export { ScalarSchemaNode as $, syncPropertySchema as A, ParameterLocation as B, createObjectBindingParameter as C, createResponse as D, createProperty as E, OperationNode as F, DatetimeSchemaNode as G, ArraySchemaNode as H, ResponseNode as I, IntersectionSchemaNode as J, EnumSchemaNode as K, HttpStatusCode as L, RootMeta as M, RootNode as N, createRoot as O, HttpMethod as P, RefSchemaNode as Q, MediaType as R, createFunctionParameters as S, createParameter as T, ComplexSchemaType as U, ParameterNode as V, DateSchemaNode as W, ObjectSchemaNode as X, NumberSchemaNode as Y, PrimitiveSchemaType as Z, Printer as _, VisitorDepth as _t, TransformOptions as a, StringSchemaNode as at, DistributiveOmit as b, nodeKinds as bt, WalkOptions as c, UrlSchemaNode as ct, transform as d, FunctionNodeType as dt, ScalarSchemaType as et, walk as f, FunctionParameterNode as ft, resolveRef as g, NodeKind as gt, refMapToObject as h, BaseNode as ht, ParentOf as i, SpecialSchemaType as it, Node as j, createSchema as k, collect as l, PropertyNode as lt, buildRefMap as m, ObjectBindingParameterNode as mt, CollectOptions as n, SchemaNodeByType as nt, Visitor as o, TimeSchemaNode as ot, RefMap as p, FunctionParametersNode as pt, EnumValueNode as q, CollectVisitor as r, SchemaType as rt, VisitorContext as s, UnionSchemaNode as st, AsyncVisitor as t, SchemaNode as tt, composeTransformers as u, FunctionNode as ut, PrinterFactoryOptions as v, httpMethods as vt, createOperation as w, createFunctionParameter as x, schemaTypes as xt, definePrinter as y, mediaTypes as yt, StatusCode as z };
961
- //# sourceMappingURL=visitor-UlWOe-In.d.ts.map