@kubb/ast 5.0.0-alpha.22 → 5.0.0-alpha.24
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/dist/index.cjs +471 -441
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +159 -160
- package/dist/index.js +467 -426
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/{visitor-COwfCgLK.d.ts → visitor-DsdLcLjR.d.ts} +206 -117
- package/package.json +1 -1
- package/src/constants.ts +15 -2
- package/src/factory.ts +69 -49
- package/src/guards.ts +3 -3
- package/src/index.ts +13 -20
- package/src/nodes/base.ts +2 -1
- package/src/nodes/function.ts +104 -34
- package/src/nodes/index.ts +1 -1
- package/src/nodes/operation.ts +7 -2
- package/src/nodes/schema.ts +3 -3
- package/src/{printers/printer.ts → printer.ts} +1 -1
- package/src/transformers.ts +2 -42
- package/src/types.ts +3 -2
- package/src/utils.ts +364 -13
- package/src/visitor.ts +6 -4
- package/src/printers/functionPrinter.ts +0 -196
- package/src/printers/index.ts +0 -3
|
@@ -5,17 +5,6 @@ import { t as __name } from "./chunk--u3MIqq1.js";
|
|
|
5
5
|
* Traversal depth used by AST visitor utilities.
|
|
6
6
|
*/
|
|
7
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
8
|
/**
|
|
20
9
|
* Canonical schema type strings used by AST schema nodes.
|
|
21
10
|
*
|
|
@@ -125,10 +114,11 @@ declare const schemaTypes: {
|
|
|
125
114
|
*/
|
|
126
115
|
readonly never: "never";
|
|
127
116
|
};
|
|
117
|
+
type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean';
|
|
128
118
|
/**
|
|
129
|
-
*
|
|
119
|
+
* Returns `true` when `type` is a scalar primitive schema type.
|
|
130
120
|
*/
|
|
131
|
-
declare
|
|
121
|
+
declare function isScalarPrimitive(type: string): type is ScalarPrimitive;
|
|
132
122
|
declare const httpMethods: {
|
|
133
123
|
readonly get: "GET";
|
|
134
124
|
readonly post: "POST";
|
|
@@ -170,7 +160,7 @@ declare const mediaTypes: {
|
|
|
170
160
|
* const kind: NodeKind = 'Schema'
|
|
171
161
|
* ```
|
|
172
162
|
*/
|
|
173
|
-
type NodeKind = 'Root' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'FunctionParameter' | '
|
|
163
|
+
type NodeKind = 'Root' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'FunctionParameter' | 'ParameterGroup' | 'FunctionParameters' | 'Type';
|
|
174
164
|
/**
|
|
175
165
|
* Base shape shared by all AST nodes.
|
|
176
166
|
*
|
|
@@ -187,16 +177,69 @@ type BaseNode = {
|
|
|
187
177
|
};
|
|
188
178
|
//#endregion
|
|
189
179
|
//#region src/nodes/function.d.ts
|
|
180
|
+
/**
|
|
181
|
+
* AST node representing a language-agnostic type expression produced during parameter resolution.
|
|
182
|
+
* Each language printer renders the variant into its own syntax.
|
|
183
|
+
*
|
|
184
|
+
* - `struct` — an inline anonymous type grouping named fields.
|
|
185
|
+
* TypeScript renders as `{ petId: string; name?: string }`, Python as a `TypedDict` reference.
|
|
186
|
+
* - `member` — a single named field accessed from a named group type.
|
|
187
|
+
* TypeScript renders as `PathParams['petId']`, C# as `PathParams.PetId`.
|
|
188
|
+
*/
|
|
189
|
+
type TypeNode = BaseNode & {
|
|
190
|
+
/**
|
|
191
|
+
* Node kind.
|
|
192
|
+
*/
|
|
193
|
+
kind: 'Type';
|
|
194
|
+
} & ({
|
|
195
|
+
/**
|
|
196
|
+
* Reference variant — a plain type name or identifier.
|
|
197
|
+
* TypeScript renders as-is, e.g. `string`, `QueryParams`, `Partial<Config>`.
|
|
198
|
+
*/
|
|
199
|
+
variant: 'reference';
|
|
200
|
+
/**
|
|
201
|
+
* The full type name string, e.g. `'string'`, `'QueryParams'`, `'Partial<Config>'`.
|
|
202
|
+
*/
|
|
203
|
+
name: string;
|
|
204
|
+
} | {
|
|
205
|
+
/**
|
|
206
|
+
* Struct variant — an inline anonymous type grouping named fields.
|
|
207
|
+
* TypeScript renders as `{ key: Type; other?: OtherType }`.
|
|
208
|
+
*/
|
|
209
|
+
variant: 'struct';
|
|
210
|
+
/**
|
|
211
|
+
* Properties of the struct type.
|
|
212
|
+
*/
|
|
213
|
+
properties: Array<{
|
|
214
|
+
name: string;
|
|
215
|
+
optional: boolean;
|
|
216
|
+
type: TypeNode;
|
|
217
|
+
}>;
|
|
218
|
+
} | {
|
|
219
|
+
/**
|
|
220
|
+
* Member variant — a single named field accessed from a group type.
|
|
221
|
+
* TypeScript renders as `Base['key']`.
|
|
222
|
+
*/
|
|
223
|
+
variant: 'member';
|
|
224
|
+
/**
|
|
225
|
+
* Base type name, e.g. `'DeletePetPathParams'`.
|
|
226
|
+
*/
|
|
227
|
+
base: string;
|
|
228
|
+
/**
|
|
229
|
+
* The field name to access, e.g. `'petId'`.
|
|
230
|
+
*/
|
|
231
|
+
key: string;
|
|
232
|
+
});
|
|
190
233
|
/**
|
|
191
234
|
* AST node for one function parameter.
|
|
192
235
|
*
|
|
193
236
|
* @example Required parameter
|
|
194
237
|
* `name: Type`
|
|
195
238
|
*
|
|
196
|
-
* @example Optional
|
|
239
|
+
* @example Optional parameter
|
|
197
240
|
* `name?: Type`
|
|
198
241
|
*
|
|
199
|
-
* @example Parameter with default
|
|
242
|
+
* @example Parameter with default value
|
|
200
243
|
* `name: Type = defaultValue`
|
|
201
244
|
*
|
|
202
245
|
* @example Rest parameter
|
|
@@ -212,78 +255,94 @@ type FunctionParameterNode = BaseNode & {
|
|
|
212
255
|
*/
|
|
213
256
|
name: string;
|
|
214
257
|
/**
|
|
215
|
-
*
|
|
216
|
-
* Omit for untyped
|
|
258
|
+
* Type annotation as a structured {@link TypeNode}.
|
|
259
|
+
* Omit for untyped output.
|
|
260
|
+
*
|
|
261
|
+
* @example Reference type node
|
|
262
|
+
* `{ kind: 'Type', variant: 'reference', name: 'string' }` → `petId: string`
|
|
263
|
+
*
|
|
264
|
+
* @example Struct type node
|
|
265
|
+
* `{ kind: 'Type', variant: 'struct', properties: [...] }` → `{ key: Type; other?: OtherType }`
|
|
266
|
+
*
|
|
267
|
+
* @example Member type node
|
|
268
|
+
* `{ kind: 'Type', variant: 'member', base: 'PathParams', key: 'petId' }` → `PathParams['petId']`
|
|
217
269
|
*/
|
|
218
|
-
type?:
|
|
270
|
+
type?: TypeNode;
|
|
219
271
|
/**
|
|
220
|
-
* When `true` the parameter is emitted as a rest parameter
|
|
221
|
-
*
|
|
272
|
+
* When `true` the parameter is emitted as a rest parameter.
|
|
273
|
+
*
|
|
274
|
+
* @example Rest parameter
|
|
275
|
+
* `...name: Type[]`
|
|
222
276
|
*/
|
|
223
277
|
rest?: boolean;
|
|
224
278
|
}
|
|
225
279
|
/**
|
|
226
|
-
* Optional parameter
|
|
227
|
-
* Cannot be combined with `default` because defaulted
|
|
228
|
-
* @example `name?: Type`
|
|
280
|
+
* Optional parameter — rendered with `?` and may be omitted by the caller.
|
|
281
|
+
* Cannot be combined with `default` because a defaulted parameter is already optional.
|
|
229
282
|
*/
|
|
230
283
|
& ({
|
|
231
284
|
optional: true;
|
|
232
285
|
default?: never;
|
|
233
286
|
}
|
|
234
287
|
/**
|
|
235
|
-
* Required parameter, or parameter with a default value.
|
|
236
|
-
*
|
|
237
|
-
* @example
|
|
288
|
+
* Required parameter, or a parameter with a default value.
|
|
289
|
+
*
|
|
290
|
+
* @example Required
|
|
291
|
+
* `name: Type`
|
|
292
|
+
*
|
|
293
|
+
* @example With default
|
|
294
|
+
* `name: Type = default`
|
|
238
295
|
*/
|
|
239
296
|
| {
|
|
240
297
|
optional?: false;
|
|
241
298
|
default?: string;
|
|
242
299
|
});
|
|
243
300
|
/**
|
|
244
|
-
* AST node for
|
|
301
|
+
* AST node for a group of related function parameters treated as a single unit.
|
|
245
302
|
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
303
|
+
* Each language printer decides how to render this group:
|
|
304
|
+
* - TypeScript/JS: destructured object `{ key1, key2 }: { key1: Type1; key2: Type2 } = {}`
|
|
305
|
+
* - Python: keyword-only args or a typed dict parameter
|
|
306
|
+
* - C# / Kotlin: named record / data-class parameter
|
|
248
307
|
*
|
|
249
|
-
*
|
|
308
|
+
* When `inline` is `true`, the group is spread as individual top-level parameters
|
|
309
|
+
* rather than wrapped in a single grouped construct.
|
|
250
310
|
*
|
|
251
|
-
* @example
|
|
311
|
+
* @example Grouped destructuring
|
|
252
312
|
* `{ id, name }: { id: string; name: string } = {}`
|
|
253
313
|
*
|
|
254
|
-
* @example Inline (spread
|
|
314
|
+
* @example Inline (spread as individual parameters)
|
|
255
315
|
* `id: string, name: string`
|
|
256
316
|
*/
|
|
257
|
-
type
|
|
317
|
+
type ParameterGroupNode = BaseNode & {
|
|
258
318
|
/**
|
|
259
319
|
* Node kind.
|
|
260
320
|
*/
|
|
261
|
-
kind: '
|
|
321
|
+
kind: 'ParameterGroup';
|
|
262
322
|
/**
|
|
263
|
-
* The individual parameters that form the
|
|
264
|
-
* Rendered as
|
|
323
|
+
* The individual parameters that form the group.
|
|
324
|
+
* Rendered as a destructured object or spread inline when `inline` is `true`.
|
|
265
325
|
*/
|
|
266
326
|
properties: Array<FunctionParameterNode>;
|
|
267
327
|
/**
|
|
268
|
-
* Optional type
|
|
269
|
-
* When absent,
|
|
328
|
+
* Optional explicit type annotation for the whole group.
|
|
329
|
+
* When absent, printers auto-compute it from `properties`.
|
|
270
330
|
*/
|
|
271
|
-
type?:
|
|
331
|
+
type?: TypeNode;
|
|
272
332
|
/**
|
|
273
333
|
* When `true`, `properties` are emitted as individual top-level parameters instead of
|
|
274
|
-
* being wrapped in a
|
|
334
|
+
* being wrapped in a single grouped construct.
|
|
275
335
|
*
|
|
276
|
-
* Equivalent to `mode: 'inlineSpread'` in the legacy `FunctionParams` API.
|
|
277
336
|
* @default false
|
|
278
337
|
*/
|
|
279
338
|
inline?: boolean;
|
|
280
339
|
/**
|
|
281
|
-
* Whether the
|
|
340
|
+
* Whether the group as a whole is optional.
|
|
282
341
|
* If omitted, printers infer this from child properties.
|
|
283
342
|
*/
|
|
284
343
|
optional?: boolean;
|
|
285
344
|
/**
|
|
286
|
-
* Default value for the
|
|
345
|
+
* Default value for the group, written verbatim after `=`.
|
|
287
346
|
* Commonly `'{}'` to allow omitting the argument entirely.
|
|
288
347
|
*/
|
|
289
348
|
default?: string;
|
|
@@ -308,16 +367,16 @@ type FunctionParametersNode = BaseNode & {
|
|
|
308
367
|
/**
|
|
309
368
|
* Ordered parameter nodes.
|
|
310
369
|
*/
|
|
311
|
-
params:
|
|
370
|
+
params: ReadonlyArray<FunctionParameterNode | ParameterGroupNode>;
|
|
312
371
|
};
|
|
313
372
|
/**
|
|
314
|
-
* The
|
|
373
|
+
* The four function-signature AST node variants.
|
|
315
374
|
*/
|
|
316
|
-
type FunctionNode = FunctionParameterNode |
|
|
375
|
+
type FunctionNode = FunctionParameterNode | ParameterGroupNode | FunctionParametersNode | TypeNode;
|
|
317
376
|
/**
|
|
318
377
|
* Handler map keys — one per `FunctionNode` kind.
|
|
319
378
|
*/
|
|
320
|
-
type FunctionNodeType = 'functionParameter' | '
|
|
379
|
+
type FunctionNodeType = 'functionParameter' | 'parameterGroup' | 'functionParameters' | 'type';
|
|
321
380
|
//#endregion
|
|
322
381
|
//#region src/nodes/property.d.ts
|
|
323
382
|
/**
|
|
@@ -803,11 +862,11 @@ type ScalarSchemaNode = SchemaNodeBase & {
|
|
|
803
862
|
};
|
|
804
863
|
/**
|
|
805
864
|
* URL schema node.
|
|
806
|
-
* Can include an
|
|
865
|
+
* Can include an OpenAPI-style path template for template literal types.
|
|
807
866
|
*
|
|
808
867
|
* @example
|
|
809
868
|
* ```ts
|
|
810
|
-
* const urlSchema: UrlSchemaNode = { kind: 'Schema', type: 'url', path: '/pets
|
|
869
|
+
* const urlSchema: UrlSchemaNode = { kind: 'Schema', type: 'url', path: '/pets/{petId}' }
|
|
811
870
|
* ```
|
|
812
871
|
*/
|
|
813
872
|
type UrlSchemaNode = SchemaNodeBase & {
|
|
@@ -816,7 +875,7 @@ type UrlSchemaNode = SchemaNodeBase & {
|
|
|
816
875
|
*/
|
|
817
876
|
type: 'url';
|
|
818
877
|
/**
|
|
819
|
-
*
|
|
878
|
+
* OpenAPI-style path template, for example, `'/pets/{petId}'`.
|
|
820
879
|
*/
|
|
821
880
|
path?: string;
|
|
822
881
|
};
|
|
@@ -995,8 +1054,8 @@ type OperationNode = BaseNode & {
|
|
|
995
1054
|
*/
|
|
996
1055
|
method: HttpMethod;
|
|
997
1056
|
/**
|
|
998
|
-
*
|
|
999
|
-
*
|
|
1057
|
+
* OpenAPI-style path string, for example `/pets/{petId}`.
|
|
1058
|
+
* Path parameters retain the `{param}` notation from the original spec.
|
|
1000
1059
|
*/
|
|
1001
1060
|
path: string;
|
|
1002
1061
|
/**
|
|
@@ -1038,6 +1097,11 @@ type OperationNode = BaseNode & {
|
|
|
1038
1097
|
* Set when a referenced schema has `readOnly` fields that should be omitted in request types.
|
|
1039
1098
|
*/
|
|
1040
1099
|
keysToOmit?: Array<string>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Whether the request body is required (`requestBody.required: true` in the spec).
|
|
1102
|
+
* When `false` or absent, the generated `data` parameter should be optional.
|
|
1103
|
+
*/
|
|
1104
|
+
required?: boolean;
|
|
1041
1105
|
};
|
|
1042
1106
|
/**
|
|
1043
1107
|
* Operation responses.
|
|
@@ -1267,6 +1331,13 @@ type InferSchemaNode<TSchema extends object, TDateType extends ParserOptions['da
|
|
|
1267
1331
|
type InferSchema<TSchema extends object, TDateType extends ParserOptions['dateType'] = 'string', TEntries extends ReadonlyArray<[object, SchemaNode]> = SchemaNodeMap<TDateType>> = InferSchemaNode<TSchema, TDateType, TEntries>;
|
|
1268
1332
|
//#endregion
|
|
1269
1333
|
//#region src/factory.d.ts
|
|
1334
|
+
/**
|
|
1335
|
+
* Syncs property/parameter schema optionality flags from `required` and `schema.nullable`.
|
|
1336
|
+
*
|
|
1337
|
+
* - `optional` is set for non-required, non-nullable schemas.
|
|
1338
|
+
* - `nullish` is set for non-required, nullable schemas.
|
|
1339
|
+
*/
|
|
1340
|
+
declare function syncOptionality(schema: SchemaNode, required: boolean): SchemaNode;
|
|
1270
1341
|
/**
|
|
1271
1342
|
* Distributive `Omit` that preserves each member of a union.
|
|
1272
1343
|
*
|
|
@@ -1419,22 +1490,6 @@ declare function createParameter(props: Pick<ParameterNode, 'name' | 'in' | 'sch
|
|
|
1419
1490
|
* ```
|
|
1420
1491
|
*/
|
|
1421
1492
|
declare function createResponse(props: Pick<ResponseNode, 'statusCode' | 'schema'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'schema'>>): ResponseNode;
|
|
1422
|
-
/**
|
|
1423
|
-
* Creates a single-property object schema used as a discriminator literal.
|
|
1424
|
-
*
|
|
1425
|
-
* @example
|
|
1426
|
-
* ```ts
|
|
1427
|
-
* createDiscriminantNode({ propertyName: 'type', value: 'dog' })
|
|
1428
|
-
* // -> { type: 'object', properties: [{ name: 'type', required: true, schema: enum('dog') }] }
|
|
1429
|
-
* ```
|
|
1430
|
-
*/
|
|
1431
|
-
declare function createDiscriminantNode({
|
|
1432
|
-
propertyName,
|
|
1433
|
-
value
|
|
1434
|
-
}: {
|
|
1435
|
-
propertyName: string;
|
|
1436
|
-
value: string;
|
|
1437
|
-
}): SchemaNode;
|
|
1438
1493
|
/**
|
|
1439
1494
|
* Creates a `FunctionParameterNode`.
|
|
1440
1495
|
*
|
|
@@ -1442,25 +1497,25 @@ declare function createDiscriminantNode({
|
|
|
1442
1497
|
*
|
|
1443
1498
|
* @example Required typed param
|
|
1444
1499
|
* ```ts
|
|
1445
|
-
* createFunctionParameter({ name: 'petId', type: 'string' })
|
|
1500
|
+
* createFunctionParameter({ name: 'petId', type: createTypeNode({ variant: 'reference', name: 'string' }) })
|
|
1446
1501
|
* // → petId: string
|
|
1447
1502
|
* ```
|
|
1448
1503
|
*
|
|
1449
1504
|
* @example Optional param
|
|
1450
1505
|
* ```ts
|
|
1451
|
-
* createFunctionParameter({ name: 'params', type: 'QueryParams', optional: true })
|
|
1506
|
+
* createFunctionParameter({ name: 'params', type: createTypeNode({ variant: 'reference', name: 'QueryParams' }), optional: true })
|
|
1452
1507
|
* // → params?: QueryParams
|
|
1453
1508
|
* ```
|
|
1454
1509
|
*
|
|
1455
1510
|
* @example Param with default (implicitly optional; cannot combine with `optional: true`)
|
|
1456
1511
|
* ```ts
|
|
1457
|
-
* createFunctionParameter({ name: 'config', type: 'RequestConfig', default: '{}' })
|
|
1512
|
+
* createFunctionParameter({ name: 'config', type: createTypeNode({ variant: 'reference', name: 'RequestConfig' }), default: '{}' })
|
|
1458
1513
|
* // → config: RequestConfig = {}
|
|
1459
1514
|
* ```
|
|
1460
1515
|
*/
|
|
1461
1516
|
declare function createFunctionParameter(props: {
|
|
1462
1517
|
name: string;
|
|
1463
|
-
type?:
|
|
1518
|
+
type?: TypeNode;
|
|
1464
1519
|
rest?: boolean;
|
|
1465
1520
|
} & ({
|
|
1466
1521
|
optional: true;
|
|
@@ -1470,14 +1525,51 @@ declare function createFunctionParameter(props: {
|
|
|
1470
1525
|
default?: string;
|
|
1471
1526
|
})): FunctionParameterNode;
|
|
1472
1527
|
/**
|
|
1473
|
-
* Creates
|
|
1528
|
+
* Creates a {@link TypeNode} representing a language-agnostic structured type expression.
|
|
1529
|
+
*
|
|
1530
|
+
* Use `variant: 'struct'` for inline anonymous types and `variant: 'member'` for a single
|
|
1531
|
+
* named field accessed from a group type. Each language's printer renders the variant
|
|
1532
|
+
* into its own syntax (TypeScript, Python, C#, Kotlin, …).
|
|
1533
|
+
*
|
|
1534
|
+
* @example Reference type (TypeScript: `QueryParams`)
|
|
1535
|
+
* ```ts
|
|
1536
|
+
* createTypeNode({ variant: 'reference', name: 'QueryParams' })
|
|
1537
|
+
* ```
|
|
1538
|
+
*
|
|
1539
|
+
* @example Struct type (TypeScript: `{ petId: string }`)
|
|
1540
|
+
* ```ts
|
|
1541
|
+
* createTypeNode({ variant: 'struct', properties: [{ name: 'petId', optional: false, type: createTypeNode({ variant: 'reference', name: 'string' }) }] })
|
|
1542
|
+
* ```
|
|
1543
|
+
*
|
|
1544
|
+
* @example Member type (TypeScript: `DeletePetPathParams['petId']`)
|
|
1545
|
+
* ```ts
|
|
1546
|
+
* createTypeNode({ variant: 'member', base: 'DeletePetPathParams', key: 'petId' })
|
|
1547
|
+
* ```
|
|
1548
|
+
*/
|
|
1549
|
+
declare function createTypeNode(props: {
|
|
1550
|
+
variant: 'reference';
|
|
1551
|
+
name: string;
|
|
1552
|
+
} | {
|
|
1553
|
+
variant: 'struct';
|
|
1554
|
+
properties: Array<{
|
|
1555
|
+
name: string;
|
|
1556
|
+
optional: boolean;
|
|
1557
|
+
type: TypeNode;
|
|
1558
|
+
}>;
|
|
1559
|
+
} | {
|
|
1560
|
+
variant: 'member';
|
|
1561
|
+
base: string;
|
|
1562
|
+
key: string;
|
|
1563
|
+
}): TypeNode;
|
|
1564
|
+
/**
|
|
1565
|
+
* Creates a `ParameterGroupNode` representing a group of related parameters treated as a unit.
|
|
1474
1566
|
*
|
|
1475
|
-
* @example
|
|
1567
|
+
* @example Grouped param (TypeScript declaration)
|
|
1476
1568
|
* ```ts
|
|
1477
|
-
*
|
|
1569
|
+
* createParameterGroup({
|
|
1478
1570
|
* properties: [
|
|
1479
|
-
* createFunctionParameter({ name: 'id', type: 'string', optional: false }),
|
|
1480
|
-
* createFunctionParameter({ name: 'name', type: 'string', optional: true }),
|
|
1571
|
+
* createFunctionParameter({ name: 'id', type: createTypeNode({ variant: 'reference', name: 'string' }), optional: false }),
|
|
1572
|
+
* createFunctionParameter({ name: 'name', type: createTypeNode({ variant: 'reference', name: 'string' }), optional: true }),
|
|
1481
1573
|
* ],
|
|
1482
1574
|
* default: '{}',
|
|
1483
1575
|
* })
|
|
@@ -1485,17 +1577,17 @@ declare function createFunctionParameter(props: {
|
|
|
1485
1577
|
* // call → { id, name }
|
|
1486
1578
|
* ```
|
|
1487
1579
|
*
|
|
1488
|
-
* @example Inline
|
|
1580
|
+
* @example Inline (spread) — children emitted as individual top-level parameters
|
|
1489
1581
|
* ```ts
|
|
1490
|
-
*
|
|
1491
|
-
* properties: [createFunctionParameter({ name: 'petId', type: 'string', optional: false })],
|
|
1582
|
+
* createParameterGroup({
|
|
1583
|
+
* properties: [createFunctionParameter({ name: 'petId', type: createTypeNode({ variant: 'reference', name: 'string' }), optional: false })],
|
|
1492
1584
|
* inline: true,
|
|
1493
1585
|
* })
|
|
1494
1586
|
* // declaration → petId: string
|
|
1495
1587
|
* // call → petId
|
|
1496
1588
|
* ```
|
|
1497
1589
|
*/
|
|
1498
|
-
declare function
|
|
1590
|
+
declare function createParameterGroup(props: Pick<ParameterGroupNode, 'properties'> & Partial<Omit<ParameterGroupNode, 'kind' | 'properties'>>): ParameterGroupNode;
|
|
1499
1591
|
/**
|
|
1500
1592
|
* Creates a `FunctionParametersNode` from an ordered list of parameters.
|
|
1501
1593
|
*
|
|
@@ -1503,8 +1595,8 @@ declare function createObjectBindingParameter(props: Pick<ObjectBindingParameter
|
|
|
1503
1595
|
* ```ts
|
|
1504
1596
|
* createFunctionParameters({
|
|
1505
1597
|
* params: [
|
|
1506
|
-
* createFunctionParameter({ name: 'petId', type: 'string', optional: false }),
|
|
1507
|
-
* createFunctionParameter({ name: 'config', type: 'RequestConfig', optional: false, default: '{}' }),
|
|
1598
|
+
* createFunctionParameter({ name: 'petId', type: createTypeNode({ variant: 'reference', name: 'string' }), optional: false }),
|
|
1599
|
+
* createFunctionParameter({ name: 'config', type: createTypeNode({ variant: 'reference', name: 'RequestConfig' }), optional: false, default: '{}' }),
|
|
1508
1600
|
* ],
|
|
1509
1601
|
* })
|
|
1510
1602
|
* ```
|
|
@@ -1517,7 +1609,7 @@ declare function createObjectBindingParameter(props: Pick<ObjectBindingParameter
|
|
|
1517
1609
|
*/
|
|
1518
1610
|
declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
|
|
1519
1611
|
//#endregion
|
|
1520
|
-
//#region src/
|
|
1612
|
+
//#region src/printer.d.ts
|
|
1521
1613
|
/**
|
|
1522
1614
|
* Runtime context passed as `this` to printer handlers.
|
|
1523
1615
|
*
|
|
@@ -1665,6 +1757,33 @@ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) =
|
|
|
1665
1757
|
* ```
|
|
1666
1758
|
*/
|
|
1667
1759
|
declare function definePrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
|
|
1760
|
+
/**
|
|
1761
|
+
* Generic printer-factory function used by `definePrinter` and `defineFunctionPrinter`.
|
|
1762
|
+
**
|
|
1763
|
+
* @example
|
|
1764
|
+
* ```ts
|
|
1765
|
+
* export const defineFunctionPrinter = createPrinterFactory<FunctionNode, FunctionNodeType, FunctionNodeByType>(
|
|
1766
|
+
* (node) => kindToHandlerKey[node.kind],
|
|
1767
|
+
* )
|
|
1768
|
+
* ```
|
|
1769
|
+
*/
|
|
1770
|
+
declare function createPrinterFactory<TNode, TKey extends string, TNodeByKey extends Partial<Record<TKey, TNode>>>(getKey: (node: TNode) => TKey | undefined): <T extends PrinterFactoryOptions>(build: (options: T["options"]) => {
|
|
1771
|
+
name: T["name"];
|
|
1772
|
+
options: T["options"];
|
|
1773
|
+
nodes: Partial<{ [K in TKey]: (this: {
|
|
1774
|
+
transform: (node: TNode) => T["output"] | null | undefined;
|
|
1775
|
+
options: T["options"];
|
|
1776
|
+
}, node: TNodeByKey[K]) => T["output"] | null | undefined }>;
|
|
1777
|
+
print?: (this: {
|
|
1778
|
+
transform: (node: TNode) => T["output"] | null | undefined;
|
|
1779
|
+
options: T["options"];
|
|
1780
|
+
}, node: TNode) => T["printOutput"] | null | undefined;
|
|
1781
|
+
}) => (options?: T["options"]) => {
|
|
1782
|
+
name: T["name"];
|
|
1783
|
+
options: T["options"];
|
|
1784
|
+
transform: (node: TNode) => T["output"] | null | undefined;
|
|
1785
|
+
print: (node: TNode) => T["printOutput"] | null | undefined;
|
|
1786
|
+
};
|
|
1668
1787
|
//#endregion
|
|
1669
1788
|
//#region src/refs.d.ts
|
|
1670
1789
|
/**
|
|
@@ -1682,36 +1801,6 @@ type RefMap = Map<string, SchemaNode>;
|
|
|
1682
1801
|
* ```
|
|
1683
1802
|
*/
|
|
1684
1803
|
declare function extractRefName(ref: string): string;
|
|
1685
|
-
/**
|
|
1686
|
-
* Builds a `RefMap` from `root.schemas` using each schema's `name`.
|
|
1687
|
-
*
|
|
1688
|
-
* Unnamed schemas are skipped.
|
|
1689
|
-
*
|
|
1690
|
-
* @example
|
|
1691
|
-
* ```ts
|
|
1692
|
-
* const refMap = buildRefMap(root)
|
|
1693
|
-
* const pet = refMap.get('Pet')
|
|
1694
|
-
* ```
|
|
1695
|
-
*/
|
|
1696
|
-
declare function buildRefMap(root: RootNode): RefMap;
|
|
1697
|
-
/**
|
|
1698
|
-
* Resolves a schema by name from a `RefMap`.
|
|
1699
|
-
*
|
|
1700
|
-
* @example
|
|
1701
|
-
* ```ts
|
|
1702
|
-
* const petSchema = resolveRef(refMap, 'Pet')
|
|
1703
|
-
* ```
|
|
1704
|
-
*/
|
|
1705
|
-
declare function resolveRef(refMap: RefMap, ref: string): SchemaNode | undefined;
|
|
1706
|
-
/**
|
|
1707
|
-
* Converts a `RefMap` into a plain object.
|
|
1708
|
-
*
|
|
1709
|
-
* @example
|
|
1710
|
-
* ```ts
|
|
1711
|
-
* const refsObject = refMapToObject(refMap)
|
|
1712
|
-
* ```
|
|
1713
|
-
*/
|
|
1714
|
-
declare function refMapToObject(refMap: RefMap): Record<string, SchemaNode>;
|
|
1715
1804
|
//#endregion
|
|
1716
1805
|
//#region src/visitor.d.ts
|
|
1717
1806
|
/**
|
|
@@ -1979,5 +2068,5 @@ declare function composeTransformers(...visitors: Array<Visitor>): Visitor;
|
|
|
1979
2068
|
*/
|
|
1980
2069
|
declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
|
|
1981
2070
|
//#endregion
|
|
1982
|
-
export {
|
|
1983
|
-
//# sourceMappingURL=visitor-
|
|
2071
|
+
export { ObjectSchemaNode as $, syncOptionality as A, HttpStatusCode as B, createParameter as C, httpMethods as Ct, createRoot as D, createResponse as E, schemaTypes as Et, RootMeta as F, ArraySchemaNode as G, StatusCode as H, RootNode as I, DatetimeSchemaNode as J, ComplexSchemaType as K, HttpMethod as L, InferSchemaNode as M, ParserOptions as N, createSchema as O, Node as P, NumberSchemaNode as Q, OperationNode as R, createOperation as S, VisitorDepth as St, createProperty as T, mediaTypes as Tt, ParameterLocation as U, MediaType as V, ParameterNode as W, EnumValueNode as X, EnumSchemaNode as Y, IntersectionSchemaNode as Z, createPrinterFactory as _, ParameterGroupNode as _t, TransformOptions as a, SchemaNodeByType as at, createFunctionParameter as b, NodeKind as bt, WalkOptions as c, StringSchemaNode as ct, transform as d, UrlSchemaNode as dt, PrimitiveSchemaType as et, walk as f, PropertyNode as ft, PrinterFactoryOptions as g, FunctionParametersNode as gt, Printer as h, FunctionParameterNode as ht, ParentOf as i, SchemaNode as it, InferSchema as j, createTypeNode as k, collect as l, TimeSchemaNode as lt, extractRefName as m, FunctionNodeType as mt, CollectOptions as n, ScalarSchemaNode as nt, Visitor as o, SchemaType as ot, RefMap as p, FunctionNode as pt, DateSchemaNode as q, CollectVisitor as r, ScalarSchemaType as rt, VisitorContext as s, SpecialSchemaType as st, AsyncVisitor as t, RefSchemaNode as tt, composeTransformers as u, UnionSchemaNode as ut, definePrinter as v, TypeNode as vt, createParameterGroup as w, isScalarPrimitive as wt, createFunctionParameters as x, ScalarPrimitive as xt, DistributiveOmit as y, BaseNode as yt, ResponseNode as z };
|
|
2072
|
+
//# sourceMappingURL=visitor-DsdLcLjR.d.ts.map
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -22,7 +22,7 @@ export const nodeKinds = {
|
|
|
22
22
|
parameter: 'Parameter',
|
|
23
23
|
response: 'Response',
|
|
24
24
|
functionParameter: 'FunctionParameter',
|
|
25
|
-
|
|
25
|
+
parameterGroup: 'ParameterGroup',
|
|
26
26
|
functionParameters: 'FunctionParameters',
|
|
27
27
|
} as const satisfies Record<string, NodeKind>
|
|
28
28
|
|
|
@@ -136,10 +136,19 @@ export const schemaTypes = {
|
|
|
136
136
|
never: 'never',
|
|
137
137
|
} as const satisfies Record<SchemaType, SchemaType>
|
|
138
138
|
|
|
139
|
+
export type ScalarPrimitive = 'string' | 'number' | 'integer' | 'bigint' | 'boolean'
|
|
140
|
+
|
|
139
141
|
/**
|
|
140
142
|
* Primitive scalar schema types used when simplifying union members.
|
|
141
143
|
*/
|
|
142
|
-
export const SCALAR_PRIMITIVE_TYPES = new Set(['string', 'number', 'integer', 'bigint', 'boolean']
|
|
144
|
+
export const SCALAR_PRIMITIVE_TYPES = new Set<ScalarPrimitive>(['string', 'number', 'integer', 'bigint', 'boolean'])
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Returns `true` when `type` is a scalar primitive schema type.
|
|
148
|
+
*/
|
|
149
|
+
export function isScalarPrimitive(type: string): type is ScalarPrimitive {
|
|
150
|
+
return SCALAR_PRIMITIVE_TYPES.has(type as ScalarPrimitive)
|
|
151
|
+
}
|
|
143
152
|
|
|
144
153
|
export const httpMethods = {
|
|
145
154
|
get: 'GET',
|
|
@@ -162,6 +171,10 @@ export const parameterLocations = {
|
|
|
162
171
|
/**
|
|
163
172
|
* Default maximum number of concurrent callbacks used by `walk`.
|
|
164
173
|
*
|
|
174
|
+
* 30 is chosen to allow enough parallelism to overlap I/O-bound resolver calls
|
|
175
|
+
* without overwhelming the event loop or causing excessive memory pressure during
|
|
176
|
+
* large spec traversals.
|
|
177
|
+
*
|
|
165
178
|
* @example
|
|
166
179
|
* ```ts
|
|
167
180
|
* walk(root, { concurrency: WALK_CONCURRENCY, root: () => {} })
|