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