@kubb/ast 5.0.0-alpha.8 → 5.0.0-beta.75
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.
- package/README.md +24 -10
- package/dist/index.cjs +1975 -531
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3379 -24
- package/dist/index.js +1911 -519
- package/dist/index.js.map +1 -1
- package/package.json +23 -34
- package/src/constants.ts +133 -15
- package/src/factory.ts +680 -22
- package/src/guards.ts +77 -9
- package/src/index.ts +44 -6
- package/src/infer.ts +130 -0
- package/src/mocks.ts +101 -25
- package/src/nodes/base.ts +44 -4
- package/src/nodes/code.ts +304 -0
- package/src/nodes/file.ts +230 -0
- package/src/nodes/function.ts +223 -0
- package/src/nodes/http.ts +17 -5
- package/src/nodes/index.ts +47 -7
- package/src/nodes/operation.ts +84 -6
- package/src/nodes/output.ts +26 -0
- package/src/nodes/parameter.ts +27 -1
- package/src/nodes/property.ts +23 -1
- package/src/nodes/response.ts +29 -3
- package/src/nodes/root.ts +34 -12
- package/src/nodes/schema.ts +419 -42
- package/src/printer.ts +152 -59
- package/src/refs.ts +39 -7
- package/src/resolvers.ts +45 -0
- package/src/transformers.ts +159 -0
- package/src/types.ts +32 -4
- package/src/utils.ts +799 -14
- package/src/visitor.ts +411 -96
- package/dist/types.cjs +0 -0
- package/dist/types.d.ts +0 -2
- package/dist/types.js +0 -1
- package/dist/visitor-CrkOJoGa.d.ts +0 -702
|
@@ -1,702 +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
|
-
};
|
|
16
|
-
declare const schemaTypes: {
|
|
17
|
-
readonly string: "string";
|
|
18
|
-
/**
|
|
19
|
-
* Floating-point number (`float`, `double`).
|
|
20
|
-
*/
|
|
21
|
-
readonly number: "number";
|
|
22
|
-
/**
|
|
23
|
-
* Whole number (`int32`). Use `bigint` for `int64`.
|
|
24
|
-
*/
|
|
25
|
-
readonly integer: "integer";
|
|
26
|
-
/**
|
|
27
|
-
* 64-bit integer (`int64`). Only used when `integerType` is set to `'bigint'`.
|
|
28
|
-
*/
|
|
29
|
-
readonly bigint: "bigint";
|
|
30
|
-
readonly boolean: "boolean";
|
|
31
|
-
readonly null: "null";
|
|
32
|
-
readonly any: "any";
|
|
33
|
-
readonly unknown: "unknown";
|
|
34
|
-
readonly void: "void";
|
|
35
|
-
readonly object: "object";
|
|
36
|
-
readonly array: "array";
|
|
37
|
-
readonly tuple: "tuple";
|
|
38
|
-
readonly union: "union";
|
|
39
|
-
readonly intersection: "intersection";
|
|
40
|
-
readonly enum: "enum";
|
|
41
|
-
readonly ref: "ref";
|
|
42
|
-
readonly date: "date";
|
|
43
|
-
readonly datetime: "datetime";
|
|
44
|
-
readonly time: "time";
|
|
45
|
-
readonly uuid: "uuid";
|
|
46
|
-
readonly email: "email";
|
|
47
|
-
readonly url: "url";
|
|
48
|
-
readonly blob: "blob";
|
|
49
|
-
readonly never: "never";
|
|
50
|
-
};
|
|
51
|
-
declare const httpMethods: {
|
|
52
|
-
readonly get: "GET";
|
|
53
|
-
readonly post: "POST";
|
|
54
|
-
readonly put: "PUT";
|
|
55
|
-
readonly patch: "PATCH";
|
|
56
|
-
readonly delete: "DELETE";
|
|
57
|
-
readonly head: "HEAD";
|
|
58
|
-
readonly options: "OPTIONS";
|
|
59
|
-
readonly trace: "TRACE";
|
|
60
|
-
};
|
|
61
|
-
declare const mediaTypes: {
|
|
62
|
-
readonly applicationJson: "application/json";
|
|
63
|
-
readonly applicationXml: "application/xml";
|
|
64
|
-
readonly applicationFormUrlEncoded: "application/x-www-form-urlencoded";
|
|
65
|
-
readonly applicationOctetStream: "application/octet-stream";
|
|
66
|
-
readonly applicationPdf: "application/pdf";
|
|
67
|
-
readonly applicationZip: "application/zip";
|
|
68
|
-
readonly applicationGraphql: "application/graphql";
|
|
69
|
-
readonly multipartFormData: "multipart/form-data";
|
|
70
|
-
readonly textPlain: "text/plain";
|
|
71
|
-
readonly textHtml: "text/html";
|
|
72
|
-
readonly textCsv: "text/csv";
|
|
73
|
-
readonly textXml: "text/xml";
|
|
74
|
-
readonly imagePng: "image/png";
|
|
75
|
-
readonly imageJpeg: "image/jpeg";
|
|
76
|
-
readonly imageGif: "image/gif";
|
|
77
|
-
readonly imageWebp: "image/webp";
|
|
78
|
-
readonly imageSvgXml: "image/svg+xml";
|
|
79
|
-
readonly audioMpeg: "audio/mpeg";
|
|
80
|
-
readonly videoMp4: "video/mp4";
|
|
81
|
-
};
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/nodes/base.d.ts
|
|
84
|
-
/**
|
|
85
|
-
* Kind discriminant for every AST node.
|
|
86
|
-
*/
|
|
87
|
-
type NodeKind = 'Root' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response';
|
|
88
|
-
/**
|
|
89
|
-
* Common base for all AST nodes.
|
|
90
|
-
*/
|
|
91
|
-
type BaseNode = {
|
|
92
|
-
kind: NodeKind;
|
|
93
|
-
};
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/nodes/property.d.ts
|
|
96
|
-
/**
|
|
97
|
-
* A named property within an object schema.
|
|
98
|
-
*/
|
|
99
|
-
type PropertyNode = BaseNode & {
|
|
100
|
-
kind: 'Property';
|
|
101
|
-
name: string;
|
|
102
|
-
schema: SchemaNode;
|
|
103
|
-
required: boolean;
|
|
104
|
-
};
|
|
105
|
-
//#endregion
|
|
106
|
-
//#region src/nodes/schema.d.ts
|
|
107
|
-
type PrimitiveSchemaType = 'string' | 'number' | 'integer' | 'bigint' | 'boolean' | 'null' | 'any' | 'unknown' | 'void' | 'never' | 'object' | 'array' | 'date';
|
|
108
|
-
type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum';
|
|
109
|
-
/**
|
|
110
|
-
* Semantic types requiring special handling in code generation (e.g. generating a `Date` object or a branded type).
|
|
111
|
-
*/
|
|
112
|
-
type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'blob';
|
|
113
|
-
type SchemaType = PrimitiveSchemaType | ComplexSchemaType | SpecialSchemaType;
|
|
114
|
-
type ScalarSchemaType = Exclude<SchemaType, 'object' | 'array' | 'tuple' | 'union' | 'intersection' | 'enum' | 'ref' | 'datetime' | 'date' | 'time' | 'string' | 'number' | 'integer' | 'bigint' | 'url'>;
|
|
115
|
-
/**
|
|
116
|
-
* Base fields shared by every schema variant. Does not include spec-specific fields.
|
|
117
|
-
*/
|
|
118
|
-
type SchemaNodeBase = BaseNode & {
|
|
119
|
-
kind: 'Schema';
|
|
120
|
-
/**
|
|
121
|
-
* Named schema identifier (e.g. `"Pet"` from `#/components/schemas/Pet`). `undefined` for inline schemas.
|
|
122
|
-
*/
|
|
123
|
-
name?: string;
|
|
124
|
-
title?: string;
|
|
125
|
-
description?: string;
|
|
126
|
-
nullable?: boolean;
|
|
127
|
-
optional?: boolean;
|
|
128
|
-
/**
|
|
129
|
-
* Both optional and nullable (`optional` + `nullable`).
|
|
130
|
-
*/
|
|
131
|
-
nullish?: boolean;
|
|
132
|
-
deprecated?: boolean;
|
|
133
|
-
readOnly?: boolean;
|
|
134
|
-
writeOnly?: boolean;
|
|
135
|
-
default?: unknown;
|
|
136
|
-
example?: unknown;
|
|
137
|
-
/**
|
|
138
|
-
* Underlying primitive before format/semantic promotion (e.g. `'string'` for a `uuid` node).
|
|
139
|
-
*/
|
|
140
|
-
primitive?: PrimitiveSchemaType;
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* Object schema with ordered property definitions.
|
|
144
|
-
*/
|
|
145
|
-
type ObjectSchemaNode = SchemaNodeBase & {
|
|
146
|
-
type: 'object';
|
|
147
|
-
properties: Array<PropertyNode>;
|
|
148
|
-
/**
|
|
149
|
-
* `true` allows any value; a `SchemaNode` constrains it; absent means not permitted.
|
|
150
|
-
*/
|
|
151
|
-
additionalProperties?: SchemaNode | true;
|
|
152
|
-
patternProperties?: Record<string, SchemaNode>;
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* Array or tuple schema.
|
|
156
|
-
*/
|
|
157
|
-
type ArraySchemaNode = SchemaNodeBase & {
|
|
158
|
-
type: 'array' | 'tuple';
|
|
159
|
-
items?: Array<SchemaNode>;
|
|
160
|
-
/**
|
|
161
|
-
* Additional items beyond positional `items` in a tuple.
|
|
162
|
-
*/
|
|
163
|
-
rest?: SchemaNode;
|
|
164
|
-
min?: number;
|
|
165
|
-
max?: number;
|
|
166
|
-
unique?: boolean;
|
|
167
|
-
};
|
|
168
|
-
/**
|
|
169
|
-
* Shared base for union and intersection schemas.
|
|
170
|
-
*/
|
|
171
|
-
type CompositeSchemaNodeBase = SchemaNodeBase & {
|
|
172
|
-
members?: Array<SchemaNode>;
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* Union schema (`oneOf` / `anyOf`).
|
|
176
|
-
*/
|
|
177
|
-
type UnionSchemaNode = CompositeSchemaNodeBase & {
|
|
178
|
-
type: 'union';
|
|
179
|
-
/**
|
|
180
|
-
* Discriminator property from OAS `discriminator.propertyName`.
|
|
181
|
-
*/
|
|
182
|
-
discriminatorPropertyName?: string;
|
|
183
|
-
};
|
|
184
|
-
/**
|
|
185
|
-
* Intersection schema (`allOf`).
|
|
186
|
-
*/
|
|
187
|
-
type IntersectionSchemaNode = CompositeSchemaNodeBase & {
|
|
188
|
-
type: 'intersection';
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* A named enum variant.
|
|
192
|
-
*/
|
|
193
|
-
type EnumValueNode = {
|
|
194
|
-
name: string;
|
|
195
|
-
value: string | number | boolean;
|
|
196
|
-
format: 'string' | 'number' | 'boolean';
|
|
197
|
-
};
|
|
198
|
-
/**
|
|
199
|
-
* Enum schema.
|
|
200
|
-
*/
|
|
201
|
-
type EnumSchemaNode = SchemaNodeBase & {
|
|
202
|
-
type: 'enum';
|
|
203
|
-
/**
|
|
204
|
-
* Enum member type. Generators should use const assertions for `'number'` / `'boolean'`.
|
|
205
|
-
*/
|
|
206
|
-
enumType?: 'string' | 'number' | 'boolean';
|
|
207
|
-
/**
|
|
208
|
-
* Allowed values (simple form).
|
|
209
|
-
*/
|
|
210
|
-
enumValues?: Array<string | number | boolean | null>;
|
|
211
|
-
/**
|
|
212
|
-
* Named variants (rich form). Takes priority over `enumValues` when present.
|
|
213
|
-
*/
|
|
214
|
-
namedEnumValues?: Array<EnumValueNode>;
|
|
215
|
-
};
|
|
216
|
-
/**
|
|
217
|
-
* Ref schema — pointer to another schema definition.
|
|
218
|
-
*/
|
|
219
|
-
type RefSchemaNode = SchemaNodeBase & {
|
|
220
|
-
type: 'ref';
|
|
221
|
-
name?: string;
|
|
222
|
-
/**
|
|
223
|
-
* Original `$ref` path (e.g. `#/components/schemas/Order`). Used for name resolution.
|
|
224
|
-
*/
|
|
225
|
-
ref?: string;
|
|
226
|
-
/**
|
|
227
|
-
* Pattern constraint propagated from a sibling `pattern` field next to the `$ref`.
|
|
228
|
-
*/
|
|
229
|
-
pattern?: string;
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Datetime schema.
|
|
233
|
-
*/
|
|
234
|
-
type DatetimeSchemaNode = SchemaNodeBase & {
|
|
235
|
-
type: 'datetime';
|
|
236
|
-
/**
|
|
237
|
-
* Includes timezone offset (`dateType: 'stringOffset'`).
|
|
238
|
-
*/
|
|
239
|
-
offset?: boolean;
|
|
240
|
-
/**
|
|
241
|
-
* Local datetime without timezone (`dateType: 'stringLocal'`).
|
|
242
|
-
*/
|
|
243
|
-
local?: boolean;
|
|
244
|
-
};
|
|
245
|
-
/**
|
|
246
|
-
* Base for `date` and `time` schemas.
|
|
247
|
-
*/
|
|
248
|
-
type TemporalSchemaNodeBase<T extends 'date' | 'time'> = SchemaNodeBase & {
|
|
249
|
-
type: T;
|
|
250
|
-
/**
|
|
251
|
-
* Representation in generated code: native `Date` or plain string.
|
|
252
|
-
*/
|
|
253
|
-
representation: 'date' | 'string';
|
|
254
|
-
};
|
|
255
|
-
/**
|
|
256
|
-
* Date schema.
|
|
257
|
-
*/
|
|
258
|
-
type DateSchemaNode = TemporalSchemaNodeBase<'date'>;
|
|
259
|
-
/**
|
|
260
|
-
* Time schema.
|
|
261
|
-
*/
|
|
262
|
-
type TimeSchemaNode = TemporalSchemaNodeBase<'time'>;
|
|
263
|
-
/**
|
|
264
|
-
* String schema.
|
|
265
|
-
*/
|
|
266
|
-
type StringSchemaNode = SchemaNodeBase & {
|
|
267
|
-
type: 'string';
|
|
268
|
-
min?: number;
|
|
269
|
-
max?: number;
|
|
270
|
-
pattern?: string;
|
|
271
|
-
};
|
|
272
|
-
/**
|
|
273
|
-
* Number, integer, or bigint schema.
|
|
274
|
-
*/
|
|
275
|
-
type NumberSchemaNode = SchemaNodeBase & {
|
|
276
|
-
type: 'number' | 'integer' | 'bigint';
|
|
277
|
-
min?: number;
|
|
278
|
-
max?: number;
|
|
279
|
-
exclusiveMinimum?: number;
|
|
280
|
-
exclusiveMaximum?: number;
|
|
281
|
-
};
|
|
282
|
-
/**
|
|
283
|
-
* Schema for scalar types with no additional constraints.
|
|
284
|
-
*/
|
|
285
|
-
type ScalarSchemaNode = SchemaNodeBase & {
|
|
286
|
-
type: ScalarSchemaType;
|
|
287
|
-
};
|
|
288
|
-
/**
|
|
289
|
-
* URL schema, optionally carrying an Express-style path template for template literal generation.
|
|
290
|
-
*/
|
|
291
|
-
type UrlSchemaNode = SchemaNodeBase & {
|
|
292
|
-
type: 'url';
|
|
293
|
-
/**
|
|
294
|
-
* Express-style path (e.g. `'/pets/:petId'`). When set, printers may emit a template literal type.
|
|
295
|
-
*/
|
|
296
|
-
path?: string;
|
|
297
|
-
};
|
|
298
|
-
/**
|
|
299
|
-
* Maps each schema type string to its `SchemaNode` variant. Used by `narrowSchema`.
|
|
300
|
-
*/
|
|
301
|
-
type SchemaNodeByType = {
|
|
302
|
-
object: ObjectSchemaNode;
|
|
303
|
-
array: ArraySchemaNode;
|
|
304
|
-
tuple: ArraySchemaNode;
|
|
305
|
-
union: UnionSchemaNode;
|
|
306
|
-
intersection: IntersectionSchemaNode;
|
|
307
|
-
enum: EnumSchemaNode;
|
|
308
|
-
ref: RefSchemaNode;
|
|
309
|
-
datetime: DatetimeSchemaNode;
|
|
310
|
-
date: DateSchemaNode;
|
|
311
|
-
time: TimeSchemaNode;
|
|
312
|
-
string: StringSchemaNode;
|
|
313
|
-
number: NumberSchemaNode;
|
|
314
|
-
integer: NumberSchemaNode;
|
|
315
|
-
bigint: NumberSchemaNode;
|
|
316
|
-
boolean: ScalarSchemaNode;
|
|
317
|
-
null: ScalarSchemaNode;
|
|
318
|
-
any: ScalarSchemaNode;
|
|
319
|
-
unknown: ScalarSchemaNode;
|
|
320
|
-
void: ScalarSchemaNode;
|
|
321
|
-
never: ScalarSchemaNode;
|
|
322
|
-
uuid: ScalarSchemaNode;
|
|
323
|
-
email: ScalarSchemaNode;
|
|
324
|
-
url: UrlSchemaNode;
|
|
325
|
-
blob: ScalarSchemaNode;
|
|
326
|
-
};
|
|
327
|
-
/**
|
|
328
|
-
* Discriminated union of all schema variants.
|
|
329
|
-
*/
|
|
330
|
-
type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | ScalarSchemaNode;
|
|
331
|
-
//#endregion
|
|
332
|
-
//#region src/nodes/parameter.d.ts
|
|
333
|
-
type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
|
|
334
|
-
/**
|
|
335
|
-
* A single input parameter for an operation.
|
|
336
|
-
*/
|
|
337
|
-
type ParameterNode = BaseNode & {
|
|
338
|
-
kind: 'Parameter';
|
|
339
|
-
name: string;
|
|
340
|
-
in: ParameterLocation;
|
|
341
|
-
schema: SchemaNode;
|
|
342
|
-
required: boolean;
|
|
343
|
-
};
|
|
344
|
-
//#endregion
|
|
345
|
-
//#region src/nodes/http.d.ts
|
|
346
|
-
/**
|
|
347
|
-
* All IANA-registered HTTP status codes as string literals, matching how
|
|
348
|
-
* they appear as keys in API specifications (e.g. `"200"`, `"404"`).
|
|
349
|
-
*/
|
|
350
|
-
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';
|
|
351
|
-
/**
|
|
352
|
-
* A status code as used in an operation response: a specific HTTP status
|
|
353
|
-
* code string or `"default"` as a catch-all fallback.
|
|
354
|
-
*/
|
|
355
|
-
type StatusCode = HttpStatusCode | 'default';
|
|
356
|
-
/**
|
|
357
|
-
* Common IANA media types used in API request/response bodies.
|
|
358
|
-
*/
|
|
359
|
-
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';
|
|
360
|
-
//#endregion
|
|
361
|
-
//#region src/nodes/response.d.ts
|
|
362
|
-
/**
|
|
363
|
-
* A single response variant for an operation.
|
|
364
|
-
*/
|
|
365
|
-
type ResponseNode = BaseNode & {
|
|
366
|
-
kind: 'Response';
|
|
367
|
-
/**
|
|
368
|
-
* HTTP status code or `'default'` for a fallback response.
|
|
369
|
-
*/
|
|
370
|
-
statusCode: StatusCode;
|
|
371
|
-
description?: string;
|
|
372
|
-
schema?: SchemaNode;
|
|
373
|
-
mediaType?: MediaType;
|
|
374
|
-
};
|
|
375
|
-
//#endregion
|
|
376
|
-
//#region src/nodes/operation.d.ts
|
|
377
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
|
|
378
|
-
/**
|
|
379
|
-
* A spec-agnostic representation of a single API operation.
|
|
380
|
-
*/
|
|
381
|
-
type OperationNode = BaseNode & {
|
|
382
|
-
kind: 'Operation';
|
|
383
|
-
/**
|
|
384
|
-
* Unique operation identifier (maps to `operationId` in OAS).
|
|
385
|
-
*/
|
|
386
|
-
operationId: string;
|
|
387
|
-
method: HttpMethod;
|
|
388
|
-
/**
|
|
389
|
-
* Express-style path string, e.g. `/pets/:petId`.
|
|
390
|
-
* Derived from the OpenAPI path by converting `{param}` tokens to `:param`.
|
|
391
|
-
*/
|
|
392
|
-
path: string;
|
|
393
|
-
tags: Array<string>;
|
|
394
|
-
summary?: string;
|
|
395
|
-
description?: string;
|
|
396
|
-
deprecated?: boolean;
|
|
397
|
-
parameters: Array<ParameterNode>;
|
|
398
|
-
/**
|
|
399
|
-
* Request body schema. For OAS, this is the schema of the first content entry.
|
|
400
|
-
*/
|
|
401
|
-
requestBody?: SchemaNode;
|
|
402
|
-
responses: Array<ResponseNode>;
|
|
403
|
-
};
|
|
404
|
-
//#endregion
|
|
405
|
-
//#region src/nodes/root.d.ts
|
|
406
|
-
/**
|
|
407
|
-
* Format-agnostic metadata about the API document.
|
|
408
|
-
* Adapters populate whichever fields are available in their source format.
|
|
409
|
-
*/
|
|
410
|
-
type RootMeta = {
|
|
411
|
-
/**
|
|
412
|
-
* API title (from `info.title` in OAS/AsyncAPI).
|
|
413
|
-
*/
|
|
414
|
-
title?: string;
|
|
415
|
-
/**
|
|
416
|
-
* API description (from `info.description` in OAS/AsyncAPI).
|
|
417
|
-
*/
|
|
418
|
-
description?: string;
|
|
419
|
-
/**
|
|
420
|
-
* API version string (from `info.version` in OAS/AsyncAPI).
|
|
421
|
-
*/
|
|
422
|
-
version?: string;
|
|
423
|
-
/**
|
|
424
|
-
* Resolved base URL for the API.
|
|
425
|
-
* OAS: derived from `servers[serverIndex].url` with variable substitution.
|
|
426
|
-
* AsyncAPI: derived from `servers[serverIndex].url`.
|
|
427
|
-
* Drizzle / schema-only formats: not set.
|
|
428
|
-
*/
|
|
429
|
-
baseURL?: string;
|
|
430
|
-
};
|
|
431
|
-
/**
|
|
432
|
-
* Top-level container for all schemas and operations in a single API document.
|
|
433
|
-
*/
|
|
434
|
-
type RootNode = BaseNode & {
|
|
435
|
-
kind: 'Root';
|
|
436
|
-
schemas: Array<SchemaNode>;
|
|
437
|
-
operations: Array<OperationNode>;
|
|
438
|
-
/**
|
|
439
|
-
* Format-agnostic document metadata populated by the adapter.
|
|
440
|
-
*/
|
|
441
|
-
meta?: RootMeta;
|
|
442
|
-
};
|
|
443
|
-
//#endregion
|
|
444
|
-
//#region src/nodes/index.d.ts
|
|
445
|
-
/**
|
|
446
|
-
* Discriminated union of every AST node.
|
|
447
|
-
*
|
|
448
|
-
* Using a concrete union (instead of the bare `BaseNode` alias) lets
|
|
449
|
-
* TypeScript narrow the type automatically inside `switch (node.kind)`
|
|
450
|
-
* blocks, eliminating the need for manual `as TypeName` casts.
|
|
451
|
-
*/
|
|
452
|
-
type Node = RootNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode;
|
|
453
|
-
//#endregion
|
|
454
|
-
//#region src/factory.d.ts
|
|
455
|
-
/**
|
|
456
|
-
* Distributive variant of `Omit` that preserves union members.
|
|
457
|
-
*/
|
|
458
|
-
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
459
|
-
/**
|
|
460
|
-
* Creates a `RootNode`.
|
|
461
|
-
*/
|
|
462
|
-
declare function createRoot(overrides?: Partial<Omit<RootNode, 'kind'>>): RootNode;
|
|
463
|
-
/**
|
|
464
|
-
* Creates an `OperationNode`.
|
|
465
|
-
*/
|
|
466
|
-
declare function createOperation(props: Pick<OperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<OperationNode, 'kind' | 'operationId' | 'method' | 'path'>>): OperationNode;
|
|
467
|
-
/**
|
|
468
|
-
* Creates a `SchemaNode`, narrowed to the variant of `props.type`.
|
|
469
|
-
* For object schemas, `properties` defaults to `[]` when not provided.
|
|
470
|
-
*/
|
|
471
|
-
declare function createSchema<T extends Omit<ObjectSchemaNode, 'kind' | 'properties'> & {
|
|
472
|
-
properties?: Array<PropertyNode>;
|
|
473
|
-
}>(props: T): Omit<T, 'properties'> & {
|
|
474
|
-
properties: Array<PropertyNode>;
|
|
475
|
-
kind: 'Schema';
|
|
476
|
-
};
|
|
477
|
-
declare function createSchema<T extends DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>>(props: T): T & {
|
|
478
|
-
kind: 'Schema';
|
|
479
|
-
};
|
|
480
|
-
declare function createSchema(props: DistributiveOmit<SchemaNode, 'kind'>): SchemaNode;
|
|
481
|
-
/**
|
|
482
|
-
* Creates a `PropertyNode`. `required` defaults to `false`.
|
|
483
|
-
*/
|
|
484
|
-
declare function createProperty(props: Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>): PropertyNode;
|
|
485
|
-
/**
|
|
486
|
-
* Creates a `ParameterNode`. `required` defaults to `false`.
|
|
487
|
-
*/
|
|
488
|
-
declare function createParameter(props: Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>): ParameterNode;
|
|
489
|
-
/**
|
|
490
|
-
* Creates a `ResponseNode`.
|
|
491
|
-
*/
|
|
492
|
-
declare function createResponse(props: Pick<ResponseNode, 'statusCode'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode'>>): ResponseNode;
|
|
493
|
-
//#endregion
|
|
494
|
-
//#region src/printer.d.ts
|
|
495
|
-
/**
|
|
496
|
-
* Handler context for `definePrinter` — mirrors `PluginContext` from `@kubb/core`.
|
|
497
|
-
* Available as `this` inside each node handler and the optional root-level `print`.
|
|
498
|
-
* `this.print` always dispatches to the `nodes` handlers (node-level printer).
|
|
499
|
-
*/
|
|
500
|
-
type PrinterHandlerContext<TOutput, TOptions extends object> = {
|
|
501
|
-
/**
|
|
502
|
-
* Recursively print a nested `SchemaNode` using the node-level handlers.
|
|
503
|
-
*/
|
|
504
|
-
print: (node: SchemaNode) => TOutput | null | undefined;
|
|
505
|
-
/**
|
|
506
|
-
* Options for this printer instance.
|
|
507
|
-
*/
|
|
508
|
-
options: TOptions;
|
|
509
|
-
};
|
|
510
|
-
/**
|
|
511
|
-
* Handler for a specific `SchemaNode` variant identified by `SchemaType` key `T`.
|
|
512
|
-
* Use a regular function (not an arrow function) so that `this` is available.
|
|
513
|
-
*/
|
|
514
|
-
type PrinterHandler<TOutput, TOptions extends object, T extends SchemaType = SchemaType> = (this: PrinterHandlerContext<TOutput, TOptions>, node: SchemaNodeByType[T]) => TOutput | null | undefined;
|
|
515
|
-
/**
|
|
516
|
-
* Shape of the type parameter passed to `definePrinter`.
|
|
517
|
-
* Mirrors `AdapterFactoryOptions` / `PluginFactoryOptions` from `@kubb/core`.
|
|
518
|
-
*
|
|
519
|
-
* - `TName` — unique string identifier (e.g. `'zod'`, `'ts'`)
|
|
520
|
-
* - `TOptions` — options passed to and stored on the printer
|
|
521
|
-
* - `TOutput` — the type emitted by node handlers
|
|
522
|
-
* - `TPrintOutput` — the type emitted by the public `print` override (defaults to `TOutput`)
|
|
523
|
-
*/
|
|
524
|
-
type PrinterFactoryOptions<TName extends string = string, TOptions extends object = object, TOutput = unknown, TPrintOutput = TOutput> = {
|
|
525
|
-
name: TName;
|
|
526
|
-
options: TOptions;
|
|
527
|
-
output: TOutput;
|
|
528
|
-
printOutput: TPrintOutput;
|
|
529
|
-
};
|
|
530
|
-
/**
|
|
531
|
-
* The object returned by calling a `definePrinter` instance.
|
|
532
|
-
*/
|
|
533
|
-
type Printer<T extends PrinterFactoryOptions = PrinterFactoryOptions> = {
|
|
534
|
-
/**
|
|
535
|
-
* Unique identifier supplied at creation time.
|
|
536
|
-
*/
|
|
537
|
-
name: T['name'];
|
|
538
|
-
/**
|
|
539
|
-
* Options for this printer instance.
|
|
540
|
-
*/
|
|
541
|
-
options: T['options'];
|
|
542
|
-
/**
|
|
543
|
-
* Public printer. If the builder provides a root-level `print`, this calls that
|
|
544
|
-
* higher-level function (which may produce full declarations). Otherwise falls back
|
|
545
|
-
* to the node-level dispatcher
|
|
546
|
-
*/
|
|
547
|
-
print: (node: SchemaNode) => T['printOutput'] | null | undefined;
|
|
548
|
-
};
|
|
549
|
-
/**
|
|
550
|
-
* Builder function passed to `definePrinter`. Receives the resolved options and returns the
|
|
551
|
-
* printer configuration: a unique `name`, the stored `options`, node-level `nodes` handlers,
|
|
552
|
-
* and an optional root-level `print` override.
|
|
553
|
-
*/
|
|
554
|
-
type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) => {
|
|
555
|
-
name: T['name'];
|
|
556
|
-
/**
|
|
557
|
-
* Options to store on the printer.
|
|
558
|
-
*/
|
|
559
|
-
options: T['options'];
|
|
560
|
-
nodes: Partial<{ [K in SchemaType]: PrinterHandler<T['output'], T['options'], K> }>;
|
|
561
|
-
/**
|
|
562
|
-
* Optional root-level print override. When provided, becomes the public `printer.print`.
|
|
563
|
-
* `this.print(node)` inside this function calls the node-level dispatcher (`nodes` handlers),
|
|
564
|
-
* not the override itself — so recursion is safe.
|
|
565
|
-
*/
|
|
566
|
-
print?: (this: PrinterHandlerContext<T['output'], T['options']>, node: SchemaNode) => T['printOutput'] | null | undefined;
|
|
567
|
-
};
|
|
568
|
-
/**
|
|
569
|
-
* Creates a named printer factory. Mirrors the `createPlugin` / `createAdapter` pattern
|
|
570
|
-
* from `@kubb/core` — wraps a builder to make options optional and separates raw options
|
|
571
|
-
* from resolved options.
|
|
572
|
-
*
|
|
573
|
-
* The builder receives resolved options and returns:
|
|
574
|
-
* - `name` — a unique identifier for the printer
|
|
575
|
-
* - `options` — options stored on the returned printer instance
|
|
576
|
-
* - `nodes` — a map of `SchemaType` → handler functions that convert a `SchemaNode` to `TOutput`
|
|
577
|
-
* - `print` _(optional)_ — a root-level override that becomes the public `printer.print`.
|
|
578
|
-
* Inside it, `this.print(node)` still dispatches to the `nodes` map — safe recursion, no infinite loop.
|
|
579
|
-
*
|
|
580
|
-
* When no `print` override is provided, `printer.print` is the node-level dispatcher directly.
|
|
581
|
-
*
|
|
582
|
-
* @example Basic usage — Zod schema printer
|
|
583
|
-
* ```ts
|
|
584
|
-
* type ZodPrinter = PrinterFactoryOptions<'zod', { strict?: boolean }, string>
|
|
585
|
-
*
|
|
586
|
-
* export const zodPrinter = definePrinter<ZodPrinter>((options) => ({
|
|
587
|
-
* name: 'zod',
|
|
588
|
-
* options: { strict: options.strict ?? true },
|
|
589
|
-
* nodes: {
|
|
590
|
-
* string: () => 'z.string()',
|
|
591
|
-
* object(node) {
|
|
592
|
-
* const props = node.properties.map(p => `${p.name}: ${this.print(p.schema)}`).join(', ')
|
|
593
|
-
* return `z.object({ ${props} })`
|
|
594
|
-
* },
|
|
595
|
-
* },
|
|
596
|
-
* }))
|
|
597
|
-
* ```
|
|
598
|
-
*
|
|
599
|
-
* @example With a root-level `print` override to wrap output in a full declaration
|
|
600
|
-
* ```ts
|
|
601
|
-
* type TsPrinter = PrinterFactoryOptions<'ts', { typeName?: string }, ts.TypeNode, ts.Node>
|
|
602
|
-
*
|
|
603
|
-
* export const printerTs = definePrinter<TsPrinter>((options) => ({
|
|
604
|
-
* name: 'ts',
|
|
605
|
-
* options,
|
|
606
|
-
* nodes: { string: () => factory.keywordTypeNodes.string },
|
|
607
|
-
* print(node) {
|
|
608
|
-
* const type = this.print(node) // calls the node-level dispatcher
|
|
609
|
-
* if (!type || !this.options.typeName) return type
|
|
610
|
-
* return factory.createTypeAliasDeclaration(this.options.typeName, type)
|
|
611
|
-
* },
|
|
612
|
-
* }))
|
|
613
|
-
* ```
|
|
614
|
-
*/
|
|
615
|
-
declare function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
|
|
616
|
-
//#endregion
|
|
617
|
-
//#region src/refs.d.ts
|
|
618
|
-
/**
|
|
619
|
-
* Schema name to `SchemaNode` mapping.
|
|
620
|
-
*/
|
|
621
|
-
type RefMap = Map<string, SchemaNode>;
|
|
622
|
-
/**
|
|
623
|
-
* Indexes named schemas from `root.schemas` by name. Unnamed schemas are skipped.
|
|
624
|
-
*/
|
|
625
|
-
declare function buildRefMap(root: RootNode): RefMap;
|
|
626
|
-
/**
|
|
627
|
-
* Looks up a schema by name. Prefer over `RefMap.get()` to keep the resolution strategy swappable.
|
|
628
|
-
*/
|
|
629
|
-
declare function resolveRef(refMap: RefMap, ref: string): SchemaNode | undefined;
|
|
630
|
-
/**
|
|
631
|
-
* Converts a `RefMap` to a plain object.
|
|
632
|
-
*/
|
|
633
|
-
declare function refMapToObject(refMap: RefMap): Record<string, SchemaNode>;
|
|
634
|
-
//#endregion
|
|
635
|
-
//#region src/visitor.d.ts
|
|
636
|
-
/**
|
|
637
|
-
* Shared options for `walk`, `transform`, and `collect`.
|
|
638
|
-
*/
|
|
639
|
-
type VisitorOptions = {
|
|
640
|
-
depth?: VisitorDepth;
|
|
641
|
-
/**
|
|
642
|
-
* Maximum number of sibling nodes visited concurrently inside `walk`.
|
|
643
|
-
* @default 30
|
|
644
|
-
*/
|
|
645
|
-
concurrency?: number;
|
|
646
|
-
};
|
|
647
|
-
/**
|
|
648
|
-
* Synchronous visitor for `transform` and `walk`.
|
|
649
|
-
*/
|
|
650
|
-
type Visitor = {
|
|
651
|
-
root?(node: RootNode): void | RootNode;
|
|
652
|
-
operation?(node: OperationNode): void | OperationNode;
|
|
653
|
-
schema?(node: SchemaNode): void | SchemaNode;
|
|
654
|
-
property?(node: PropertyNode): void | PropertyNode;
|
|
655
|
-
parameter?(node: ParameterNode): void | ParameterNode;
|
|
656
|
-
response?(node: ResponseNode): void | ResponseNode;
|
|
657
|
-
};
|
|
658
|
-
type MaybePromise<T> = T | Promise<T>;
|
|
659
|
-
/**
|
|
660
|
-
* Async visitor for `walk`. Synchronous `Visitor` objects are compatible.
|
|
661
|
-
*/
|
|
662
|
-
type AsyncVisitor = {
|
|
663
|
-
root?(node: RootNode): MaybePromise<void | RootNode>;
|
|
664
|
-
operation?(node: OperationNode): MaybePromise<void | OperationNode>;
|
|
665
|
-
schema?(node: SchemaNode): MaybePromise<void | SchemaNode>;
|
|
666
|
-
property?(node: PropertyNode): MaybePromise<void | PropertyNode>;
|
|
667
|
-
parameter?(node: ParameterNode): MaybePromise<void | ParameterNode>;
|
|
668
|
-
response?(node: ResponseNode): MaybePromise<void | ResponseNode>;
|
|
669
|
-
};
|
|
670
|
-
/**
|
|
671
|
-
* Visitor for `collect`.
|
|
672
|
-
*/
|
|
673
|
-
type CollectVisitor<T> = {
|
|
674
|
-
root?(node: RootNode): T | undefined;
|
|
675
|
-
operation?(node: OperationNode): T | undefined;
|
|
676
|
-
schema?(node: SchemaNode): T | undefined;
|
|
677
|
-
property?(node: PropertyNode): T | undefined;
|
|
678
|
-
parameter?(node: ParameterNode): T | undefined;
|
|
679
|
-
response?(node: ResponseNode): T | undefined;
|
|
680
|
-
};
|
|
681
|
-
/**
|
|
682
|
-
* Depth-first traversal for side effects. Visitor return values are ignored.
|
|
683
|
-
* Sibling nodes at each level are visited concurrently up to `options.concurrency` (default: 30).
|
|
684
|
-
*/
|
|
685
|
-
declare function walk(node: Node, visitor: AsyncVisitor, options?: VisitorOptions): Promise<void>;
|
|
686
|
-
/**
|
|
687
|
-
* Depth-first immutable transformation. Visitor return values replace nodes; `undefined` keeps the original.
|
|
688
|
-
*/
|
|
689
|
-
declare function transform(node: RootNode, visitor: Visitor, options?: VisitorOptions): RootNode;
|
|
690
|
-
declare function transform(node: OperationNode, visitor: Visitor, options?: VisitorOptions): OperationNode;
|
|
691
|
-
declare function transform(node: SchemaNode, visitor: Visitor, options?: VisitorOptions): SchemaNode;
|
|
692
|
-
declare function transform(node: PropertyNode, visitor: Visitor, options?: VisitorOptions): PropertyNode;
|
|
693
|
-
declare function transform(node: ParameterNode, visitor: Visitor, options?: VisitorOptions): ParameterNode;
|
|
694
|
-
declare function transform(node: ResponseNode, visitor: Visitor, options?: VisitorOptions): ResponseNode;
|
|
695
|
-
declare function transform(node: Node, visitor: Visitor, options?: VisitorOptions): Node;
|
|
696
|
-
/**
|
|
697
|
-
* Depth-first synchronous reduction. Collects non-`undefined` visitor return values into an array.
|
|
698
|
-
*/
|
|
699
|
-
declare function collect<T>(node: Node, visitor: CollectVisitor<T>, options?: VisitorOptions): Array<T>;
|
|
700
|
-
//#endregion
|
|
701
|
-
export { UnionSchemaNode as $, MediaType as A, IntersectionSchemaNode as B, Node as C, OperationNode as D, HttpMethod as E, ComplexSchemaType as F, ScalarSchemaNode as G, ObjectSchemaNode as H, DateSchemaNode as I, SchemaNodeByType as J, ScalarSchemaType as K, DatetimeSchemaNode as L, ParameterLocation as M, ParameterNode as N, ResponseNode as O, ArraySchemaNode as P, TimeSchemaNode as Q, EnumSchemaNode as R, createSchema as S, RootNode as T, PrimitiveSchemaType as U, NumberSchemaNode as V, RefSchemaNode as W, SpecialSchemaType as X, SchemaType as Y, StringSchemaNode as Z, createOperation as _, transform as a, httpMethods as at, createResponse as b, buildRefMap as c, schemaTypes as ct, Printer as d, UrlSchemaNode as et, PrinterFactoryOptions as f, DistributiveOmit as g, definePrinter as h, collect as i, VisitorDepth as it, StatusCode as j, HttpStatusCode as k, refMapToObject as l, PrinterHandlerContext as m, CollectVisitor as n, BaseNode as nt, walk as o, mediaTypes as ot, PrinterHandler as p, SchemaNode as q, Visitor as r, NodeKind as rt, RefMap as s, nodeKinds as st, AsyncVisitor as t, PropertyNode as tt, resolveRef as u, createParameter as v, RootMeta as w, createRoot as x, createProperty as y, EnumValueNode as z };
|
|
702
|
-
//# sourceMappingURL=visitor-CrkOJoGa.d.ts.map
|