@kubb/ast 5.5.5 → 5.6.0
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 +254 -262
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +31 -4
- package/dist/index.js +253 -263
- package/dist/index.js.map +1 -1
- package/dist/{types-D10wBFnV.d.ts → types-NNGUervC.d.ts} +928 -959
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -224,336 +224,6 @@ type DefineNodeConfig<TNode extends BaseNode, TInput, TBuilt extends object> = {
|
|
|
224
224
|
*/
|
|
225
225
|
declare function defineNode<TNode extends BaseNode, TInput = Omit<TNode, 'kind'>, TBuilt extends object = Omit<TNode, 'kind'>>(config: DefineNodeConfig<TNode, TInput, TBuilt>): NodeDef<TNode, TInput>;
|
|
226
226
|
//#endregion
|
|
227
|
-
//#region src/nodes/code.d.ts
|
|
228
|
-
/**
|
|
229
|
-
* JSDoc documentation metadata attached to code declarations.
|
|
230
|
-
*/
|
|
231
|
-
type JSDocNode = {
|
|
232
|
-
/**
|
|
233
|
-
* JSDoc comment lines. `undefined` entries are filtered out during rendering.
|
|
234
|
-
*
|
|
235
|
-
* @example
|
|
236
|
-
* ```ts
|
|
237
|
-
* ['@description A pet resource', '@deprecated']
|
|
238
|
-
* ```
|
|
239
|
-
*/
|
|
240
|
-
comments?: Array<string | undefined>;
|
|
241
|
-
};
|
|
242
|
-
/**
|
|
243
|
-
* AST node representing a TypeScript `const` declaration.
|
|
244
|
-
*
|
|
245
|
-
* Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.
|
|
246
|
-
* The `children` prop of the component is represented as `nodes`.
|
|
247
|
-
*
|
|
248
|
-
* @example
|
|
249
|
-
* ```ts
|
|
250
|
-
* createConst({ name: 'pet', export: true, asConst: true })
|
|
251
|
-
* // export const pet = ... as const
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
type ConstNode = BaseNode & {
|
|
255
|
-
kind: 'Const';
|
|
256
|
-
/**
|
|
257
|
-
* Name of the constant declaration.
|
|
258
|
-
*/
|
|
259
|
-
name: string;
|
|
260
|
-
/**
|
|
261
|
-
* Whether the declaration should be exported.
|
|
262
|
-
*/
|
|
263
|
-
export?: boolean | null;
|
|
264
|
-
/**
|
|
265
|
-
* Explicit type annotation.
|
|
266
|
-
*
|
|
267
|
-
* @example Type reference
|
|
268
|
-
* `'Pet'`
|
|
269
|
-
*/
|
|
270
|
-
type?: string | null;
|
|
271
|
-
/**
|
|
272
|
-
* JSDoc documentation metadata.
|
|
273
|
-
*/
|
|
274
|
-
JSDoc?: JSDocNode | null;
|
|
275
|
-
/**
|
|
276
|
-
* Whether to append `as const` to the declaration.
|
|
277
|
-
*/
|
|
278
|
-
asConst?: boolean | null;
|
|
279
|
-
/**
|
|
280
|
-
* Child nodes representing the value of the constant (children of the `Const` component).
|
|
281
|
-
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
282
|
-
*/
|
|
283
|
-
nodes?: Array<CodeNode>;
|
|
284
|
-
};
|
|
285
|
-
/**
|
|
286
|
-
* AST node representing a TypeScript `type` alias declaration.
|
|
287
|
-
*
|
|
288
|
-
* Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.
|
|
289
|
-
* The `children` prop of the component is represented as `nodes`.
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* ```ts
|
|
293
|
-
* createType({ name: 'Pet', export: true })
|
|
294
|
-
* // export type Pet = ...
|
|
295
|
-
* ```
|
|
296
|
-
*/
|
|
297
|
-
type TypeNode = BaseNode & {
|
|
298
|
-
kind: 'Type';
|
|
299
|
-
/**
|
|
300
|
-
* Name of the type alias.
|
|
301
|
-
*/
|
|
302
|
-
name: string;
|
|
303
|
-
/**
|
|
304
|
-
* Whether the declaration should be exported.
|
|
305
|
-
*/
|
|
306
|
-
export?: boolean | null;
|
|
307
|
-
/**
|
|
308
|
-
* JSDoc documentation metadata.
|
|
309
|
-
*/
|
|
310
|
-
JSDoc?: JSDocNode | null;
|
|
311
|
-
/**
|
|
312
|
-
* Child nodes representing the type body (children of the `Type` component).
|
|
313
|
-
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
314
|
-
*/
|
|
315
|
-
nodes?: Array<CodeNode>;
|
|
316
|
-
};
|
|
317
|
-
/**
|
|
318
|
-
* AST node representing a TypeScript `function` declaration.
|
|
319
|
-
*
|
|
320
|
-
* Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.
|
|
321
|
-
* The `children` prop of the component is represented as `nodes`.
|
|
322
|
-
*
|
|
323
|
-
* @example
|
|
324
|
-
* ```ts
|
|
325
|
-
* createFunction({ name: 'getPet', export: true, async: true, returnType: 'Pet' })
|
|
326
|
-
* // export async function getPet(): Promise<Pet> { ... }
|
|
327
|
-
* ```
|
|
328
|
-
*/
|
|
329
|
-
type FunctionNode = BaseNode & {
|
|
330
|
-
kind: 'Function';
|
|
331
|
-
/**
|
|
332
|
-
* Name of the function.
|
|
333
|
-
*/
|
|
334
|
-
name: string;
|
|
335
|
-
/**
|
|
336
|
-
* Whether the function is a default export.
|
|
337
|
-
*/
|
|
338
|
-
default?: boolean | null;
|
|
339
|
-
/**
|
|
340
|
-
* Function parameter list as a pre-rendered string, written verbatim between the parentheses.
|
|
341
|
-
*
|
|
342
|
-
* @example
|
|
343
|
-
* `'id: string, config: Config = {}'`
|
|
344
|
-
*/
|
|
345
|
-
params?: string | null;
|
|
346
|
-
/**
|
|
347
|
-
* Whether the function should be exported.
|
|
348
|
-
*/
|
|
349
|
-
export?: boolean | null;
|
|
350
|
-
/**
|
|
351
|
-
* Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
352
|
-
*/
|
|
353
|
-
async?: boolean | null;
|
|
354
|
-
/**
|
|
355
|
-
* TypeScript generic type parameters.
|
|
356
|
-
*
|
|
357
|
-
* @example Constrained generics
|
|
358
|
-
* `['T', 'U extends string']`
|
|
359
|
-
*/
|
|
360
|
-
generics?: string | Array<string> | null;
|
|
361
|
-
/**
|
|
362
|
-
* Return type annotation.
|
|
363
|
-
*
|
|
364
|
-
* @example Type reference
|
|
365
|
-
* `'Pet'`
|
|
366
|
-
*/
|
|
367
|
-
returnType?: string | null;
|
|
368
|
-
/**
|
|
369
|
-
* JSDoc documentation metadata.
|
|
370
|
-
*/
|
|
371
|
-
JSDoc?: JSDocNode | null;
|
|
372
|
-
/**
|
|
373
|
-
* Child nodes representing the function body (children of the `Function` component).
|
|
374
|
-
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
375
|
-
*/
|
|
376
|
-
nodes?: Array<CodeNode>;
|
|
377
|
-
};
|
|
378
|
-
/**
|
|
379
|
-
* AST node representing a TypeScript arrow function (`const name = () => { ... }`).
|
|
380
|
-
*
|
|
381
|
-
* Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.
|
|
382
|
-
* The `children` prop of the component is represented as `nodes`.
|
|
383
|
-
*
|
|
384
|
-
* @example
|
|
385
|
-
* ```ts
|
|
386
|
-
* createArrowFunction({ name: 'getPet', export: true, singleLine: true })
|
|
387
|
-
* // export const getPet = () => ...
|
|
388
|
-
* ```
|
|
389
|
-
*/
|
|
390
|
-
type ArrowFunctionNode = Omit<FunctionNode, 'kind'> & {
|
|
391
|
-
kind: 'ArrowFunction';
|
|
392
|
-
/**
|
|
393
|
-
* Render the arrow function body as a single-line expression.
|
|
394
|
-
*/
|
|
395
|
-
singleLine?: boolean | null;
|
|
396
|
-
};
|
|
397
|
-
/**
|
|
398
|
-
* AST node representing a raw text/string fragment in the source output.
|
|
399
|
-
*
|
|
400
|
-
* Used instead of bare `string` values so that all entries in `nodes` arrays
|
|
401
|
-
* are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.
|
|
402
|
-
*
|
|
403
|
-
* @example
|
|
404
|
-
* ```ts
|
|
405
|
-
* createText('return fetch(id)')
|
|
406
|
-
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
407
|
-
* ```
|
|
408
|
-
*/
|
|
409
|
-
type TextNode = BaseNode & {
|
|
410
|
-
kind: 'Text';
|
|
411
|
-
/**
|
|
412
|
-
* The raw string content.
|
|
413
|
-
*/
|
|
414
|
-
value: string;
|
|
415
|
-
};
|
|
416
|
-
/**
|
|
417
|
-
* AST node representing a blank line in the source output.
|
|
418
|
-
*
|
|
419
|
-
* Corresponds to `<br/>` in JSX components. `printNodes` turns a `Break` between two
|
|
420
|
-
* statements into one blank line. Consecutive breaks, and breaks at the start or end of
|
|
421
|
-
* the list, are folded away, so a `Break` never produces more than one blank line.
|
|
422
|
-
*
|
|
423
|
-
* @example
|
|
424
|
-
* ```ts
|
|
425
|
-
* createBreak()
|
|
426
|
-
* // { kind: 'Break' }
|
|
427
|
-
* ```
|
|
428
|
-
*/
|
|
429
|
-
type BreakNode = BaseNode & {
|
|
430
|
-
kind: 'Break';
|
|
431
|
-
};
|
|
432
|
-
/**
|
|
433
|
-
* AST node representing a raw JSX fragment in the source output.
|
|
434
|
-
*
|
|
435
|
-
* Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup
|
|
436
|
-
* (including fragments `<>…</>`) directly in generated code.
|
|
437
|
-
*
|
|
438
|
-
* @example
|
|
439
|
-
* ```ts
|
|
440
|
-
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
441
|
-
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
442
|
-
* ```
|
|
443
|
-
*/
|
|
444
|
-
type JsxNode = BaseNode & {
|
|
445
|
-
kind: 'Jsx';
|
|
446
|
-
/**
|
|
447
|
-
* The raw JSX string content.
|
|
448
|
-
*/
|
|
449
|
-
value: string;
|
|
450
|
-
};
|
|
451
|
-
/**
|
|
452
|
-
* Union of all code-generation AST nodes.
|
|
453
|
-
*
|
|
454
|
-
* These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as
|
|
455
|
-
* structured children in {@link SourceNode.nodes}.
|
|
456
|
-
*/
|
|
457
|
-
type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
|
|
458
|
-
/**
|
|
459
|
-
* Definition for the {@link ConstNode}.
|
|
460
|
-
*/
|
|
461
|
-
declare const constDef: NodeDef<ConstNode, Omit<ConstNode, "kind">>;
|
|
462
|
-
/**
|
|
463
|
-
* Definition for the {@link TypeNode}.
|
|
464
|
-
*/
|
|
465
|
-
declare const typeDef: NodeDef<TypeNode, Omit<TypeNode, "kind">>;
|
|
466
|
-
/**
|
|
467
|
-
* Definition for the {@link FunctionNode}.
|
|
468
|
-
*/
|
|
469
|
-
declare const functionDef: NodeDef<FunctionNode, Omit<FunctionNode, "kind">>;
|
|
470
|
-
/**
|
|
471
|
-
* Definition for the {@link ArrowFunctionNode}.
|
|
472
|
-
*/
|
|
473
|
-
declare const arrowFunctionDef: NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">>;
|
|
474
|
-
/**
|
|
475
|
-
* Definition for the {@link TextNode}.
|
|
476
|
-
*/
|
|
477
|
-
declare const textDef: NodeDef<TextNode, string>;
|
|
478
|
-
/**
|
|
479
|
-
* Definition for the {@link BreakNode}.
|
|
480
|
-
*/
|
|
481
|
-
declare const breakDef: NodeDef<BreakNode, void>;
|
|
482
|
-
/**
|
|
483
|
-
* Definition for the {@link JsxNode}.
|
|
484
|
-
*/
|
|
485
|
-
declare const jsxDef: NodeDef<JsxNode, string>;
|
|
486
|
-
/**
|
|
487
|
-
* Creates a `ConstNode` representing a TypeScript `const` declaration.
|
|
488
|
-
*
|
|
489
|
-
* @example Exported constant with type and `as const`
|
|
490
|
-
* ```ts
|
|
491
|
-
* createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
|
|
492
|
-
* // export const pets: Pet[] = ... as const
|
|
493
|
-
* ```
|
|
494
|
-
*/
|
|
495
|
-
declare const createConst: (input: Omit<ConstNode, "kind">) => ConstNode;
|
|
496
|
-
/**
|
|
497
|
-
* Creates a `TypeNode` representing a TypeScript `type` alias declaration.
|
|
498
|
-
*
|
|
499
|
-
* @example
|
|
500
|
-
* ```ts
|
|
501
|
-
* createType({ name: 'Pet', export: true })
|
|
502
|
-
* // export type Pet = ...
|
|
503
|
-
* ```
|
|
504
|
-
*/
|
|
505
|
-
declare const createType: (input: Omit<TypeNode, "kind">) => TypeNode;
|
|
506
|
-
/**
|
|
507
|
-
* Creates a `FunctionNode` representing a TypeScript `function` declaration.
|
|
508
|
-
*
|
|
509
|
-
* @example
|
|
510
|
-
* ```ts
|
|
511
|
-
* createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
|
|
512
|
-
* // export async function fetchPet(): Promise<Pet> { ... }
|
|
513
|
-
* ```
|
|
514
|
-
*/
|
|
515
|
-
declare const createFunction: (input: Omit<FunctionNode, "kind">) => FunctionNode;
|
|
516
|
-
/**
|
|
517
|
-
* Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
|
|
518
|
-
*
|
|
519
|
-
* @example
|
|
520
|
-
* ```ts
|
|
521
|
-
* createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
|
|
522
|
-
* // export const double = (n: number) => ...
|
|
523
|
-
* ```
|
|
524
|
-
*/
|
|
525
|
-
declare const createArrowFunction: (input: Omit<ArrowFunctionNode, "kind">) => ArrowFunctionNode;
|
|
526
|
-
/**
|
|
527
|
-
* Creates a {@link TextNode} representing a raw string fragment in the source output.
|
|
528
|
-
*
|
|
529
|
-
* @example
|
|
530
|
-
* ```ts
|
|
531
|
-
* createText('return fetch(id)')
|
|
532
|
-
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
533
|
-
* ```
|
|
534
|
-
*/
|
|
535
|
-
declare const createText: (input: string) => TextNode;
|
|
536
|
-
/**
|
|
537
|
-
* Creates a {@link BreakNode} representing a line break in the source output.
|
|
538
|
-
*
|
|
539
|
-
* @example
|
|
540
|
-
* ```ts
|
|
541
|
-
* createBreak()
|
|
542
|
-
* // { kind: 'Break' }
|
|
543
|
-
* ```
|
|
544
|
-
*/
|
|
545
|
-
declare function createBreak(): BreakNode;
|
|
546
|
-
/**
|
|
547
|
-
* Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
|
|
548
|
-
*
|
|
549
|
-
* @example
|
|
550
|
-
* ```ts
|
|
551
|
-
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
552
|
-
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
553
|
-
* ```
|
|
554
|
-
*/
|
|
555
|
-
declare const createJsx: (input: string) => JsxNode;
|
|
556
|
-
//#endregion
|
|
557
227
|
//#region src/infer.d.ts
|
|
558
228
|
/**
|
|
559
229
|
* How `format: 'date-time'` schemas are represented downstream.
|
|
@@ -633,7 +303,7 @@ type DateTimeNodeByDateType = {
|
|
|
633
303
|
/**
|
|
634
304
|
* Resolves the AST node produced by `format: 'date-time'` based on the `dateType` option.
|
|
635
305
|
*/
|
|
636
|
-
type ResolveDateTimeNode<TDateType extends ParserOptions['dateType']> = DateTimeNodeByDateType[TDateType extends keyof DateTimeNodeByDateType ? TDateType : 'string'];
|
|
306
|
+
type ResolveDateTimeNode<TDateType extends ParserOptions['dateType']> = DateTimeNodeByDateType[TDateType extends false ? 'false' : TDateType extends keyof DateTimeNodeByDateType ? TDateType : 'string'];
|
|
637
307
|
/**
|
|
638
308
|
* Ordered list of `[schema-shape, SchemaNode]` pairs.
|
|
639
309
|
* `InferSchemaNode` walks this tuple in order and returns the first matching node type.
|
|
@@ -766,7 +436,7 @@ type PropertyNode = BaseNode & {
|
|
|
766
436
|
type UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>;
|
|
767
437
|
/**
|
|
768
438
|
* Definition for the {@link PropertyNode}. `required` defaults to `false`, and the schema's
|
|
769
|
-
* `optional`/`nullish` flags are derived from it through {@link
|
|
439
|
+
* `optional`/`nullish` flags are derived from it through {@link withRequired}.
|
|
770
440
|
*/
|
|
771
441
|
declare const propertyDef: NodeDef<PropertyNode, UserPropertyNode>;
|
|
772
442
|
/**
|
|
@@ -839,21 +509,13 @@ type PrimitiveSchemaType =
|
|
|
839
509
|
*/
|
|
840
510
|
'date';
|
|
841
511
|
/**
|
|
842
|
-
*
|
|
843
|
-
*/
|
|
844
|
-
type ComplexSchemaType = 'tuple' | 'union' | 'intersection' | 'enum';
|
|
845
|
-
/**
|
|
846
|
-
* Schema types that need special handling in generators.
|
|
847
|
-
*/
|
|
848
|
-
type SpecialSchemaType = 'ref' | 'datetime' | 'time' | 'uuid' | 'email' | 'url' | 'ipv4' | 'ipv6' | 'blob';
|
|
849
|
-
/**
|
|
850
|
-
* All schema type strings.
|
|
512
|
+
* All schema type strings, one per key of {@link SchemaNodeByType}.
|
|
851
513
|
*/
|
|
852
|
-
type SchemaType =
|
|
514
|
+
type SchemaType = keyof SchemaNodeByType;
|
|
853
515
|
/**
|
|
854
|
-
* Scalar schema types without extra object/array/ref structure.
|
|
516
|
+
* Scalar schema types without extra object/array/ref structure or constraints.
|
|
855
517
|
*/
|
|
856
|
-
type ScalarSchemaType =
|
|
518
|
+
type ScalarSchemaType = 'boolean' | 'null' | 'any' | 'unknown' | 'void' | 'never' | 'blob';
|
|
857
519
|
/**
|
|
858
520
|
* Fields shared by all schema nodes.
|
|
859
521
|
*/
|
|
@@ -1300,842 +962,1172 @@ type UrlSchemaNode = SchemaNodeBase & {
|
|
|
1300
962
|
*/
|
|
1301
963
|
path?: string;
|
|
1302
964
|
/**
|
|
1303
|
-
* Minimum string length.
|
|
965
|
+
* Minimum string length.
|
|
966
|
+
*/
|
|
967
|
+
min?: number;
|
|
968
|
+
/**
|
|
969
|
+
* Maximum string length.
|
|
970
|
+
*/
|
|
971
|
+
max?: number;
|
|
972
|
+
};
|
|
973
|
+
/**
|
|
974
|
+
* Format-string schema for string-based formats that support length constraints.
|
|
975
|
+
*
|
|
976
|
+
* @example
|
|
977
|
+
* ```ts
|
|
978
|
+
* const uuidSchema: FormatStringSchemaNode = { kind: 'Schema', type: 'uuid', min: 36, max: 36 }
|
|
979
|
+
* ```
|
|
980
|
+
*/
|
|
981
|
+
type FormatStringSchemaNode = SchemaNodeBase & {
|
|
982
|
+
/**
|
|
983
|
+
* Schema type discriminator.
|
|
984
|
+
*/
|
|
985
|
+
type: 'uuid' | 'email';
|
|
986
|
+
/**
|
|
987
|
+
* Minimum string length.
|
|
988
|
+
*/
|
|
989
|
+
min?: number;
|
|
990
|
+
/**
|
|
991
|
+
* Maximum string length.
|
|
992
|
+
*/
|
|
993
|
+
max?: number;
|
|
994
|
+
};
|
|
995
|
+
/**
|
|
996
|
+
* IPv4 address schema node.
|
|
997
|
+
*
|
|
998
|
+
* @example
|
|
999
|
+
* ```ts
|
|
1000
|
+
* const ipv4Schema: Ipv4SchemaNode = { kind: 'Schema', type: 'ipv4' }
|
|
1001
|
+
* ```
|
|
1002
|
+
*/
|
|
1003
|
+
type Ipv4SchemaNode = SchemaNodeBase & {
|
|
1004
|
+
/**
|
|
1005
|
+
* Schema type discriminator.
|
|
1006
|
+
*/
|
|
1007
|
+
type: 'ipv4';
|
|
1008
|
+
};
|
|
1009
|
+
/**
|
|
1010
|
+
* IPv6 address schema node.
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```ts
|
|
1014
|
+
* const ipv6Schema: Ipv6SchemaNode = { kind: 'Schema', type: 'ipv6' }
|
|
1015
|
+
* ```
|
|
1016
|
+
*/
|
|
1017
|
+
type Ipv6SchemaNode = SchemaNodeBase & {
|
|
1018
|
+
/**
|
|
1019
|
+
* Schema type discriminator.
|
|
1020
|
+
*/
|
|
1021
|
+
type: 'ipv6';
|
|
1022
|
+
};
|
|
1023
|
+
/**
|
|
1024
|
+
* Mapping from schema type literals to concrete schema node types.
|
|
1025
|
+
* Used by `narrowSchema`.
|
|
1026
|
+
*/
|
|
1027
|
+
type SchemaNodeByType = {
|
|
1028
|
+
object: ObjectSchemaNode;
|
|
1029
|
+
array: ArraySchemaNode;
|
|
1030
|
+
tuple: ArraySchemaNode;
|
|
1031
|
+
union: UnionSchemaNode;
|
|
1032
|
+
intersection: IntersectionSchemaNode;
|
|
1033
|
+
enum: EnumSchemaNode;
|
|
1034
|
+
ref: RefSchemaNode;
|
|
1035
|
+
datetime: DatetimeSchemaNode;
|
|
1036
|
+
date: DateSchemaNode;
|
|
1037
|
+
time: TimeSchemaNode;
|
|
1038
|
+
string: StringSchemaNode;
|
|
1039
|
+
number: NumberSchemaNode;
|
|
1040
|
+
integer: NumberSchemaNode;
|
|
1041
|
+
bigint: NumberSchemaNode;
|
|
1042
|
+
boolean: ScalarSchemaNode;
|
|
1043
|
+
null: ScalarSchemaNode;
|
|
1044
|
+
any: ScalarSchemaNode;
|
|
1045
|
+
unknown: ScalarSchemaNode;
|
|
1046
|
+
void: ScalarSchemaNode;
|
|
1047
|
+
never: ScalarSchemaNode;
|
|
1048
|
+
uuid: FormatStringSchemaNode;
|
|
1049
|
+
email: FormatStringSchemaNode;
|
|
1050
|
+
url: UrlSchemaNode;
|
|
1051
|
+
ipv4: Ipv4SchemaNode;
|
|
1052
|
+
ipv6: Ipv6SchemaNode;
|
|
1053
|
+
blob: ScalarSchemaNode;
|
|
1054
|
+
};
|
|
1055
|
+
/**
|
|
1056
|
+
* Union of all schema node types.
|
|
1057
|
+
*/
|
|
1058
|
+
type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | FormatStringSchemaNode | Ipv4SchemaNode | Ipv6SchemaNode | ScalarSchemaNode;
|
|
1059
|
+
type CreateSchemaObjectInput = Omit<ObjectSchemaNode, 'kind' | 'properties' | 'primitive'> & {
|
|
1060
|
+
properties?: Array<PropertyNode>;
|
|
1061
|
+
primitive?: 'object';
|
|
1062
|
+
};
|
|
1063
|
+
type CreateSchemaInput = CreateSchemaObjectInput | DistributiveOmit<Exclude<SchemaNode, ObjectSchemaNode>, 'kind'>;
|
|
1064
|
+
type CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {
|
|
1065
|
+
kind: 'Schema';
|
|
1066
|
+
};
|
|
1067
|
+
/**
|
|
1068
|
+
* Definition for the {@link SchemaNode}. Object schemas default `properties` to an
|
|
1069
|
+
* empty array, and `primitive` is inferred from `type` when not explicitly provided.
|
|
1070
|
+
*/
|
|
1071
|
+
declare const schemaDef: NodeDef<SchemaNode, CreateSchemaInput>;
|
|
1072
|
+
/**
|
|
1073
|
+
* Creates a `SchemaNode`, narrowed to the variant of `props.type`.
|
|
1074
|
+
*
|
|
1075
|
+
* @example
|
|
1076
|
+
* ```ts
|
|
1077
|
+
* const scalar = createSchema({ type: 'string' })
|
|
1078
|
+
* // { kind: 'Schema', type: 'string', primitive: 'string' }
|
|
1079
|
+
* ```
|
|
1080
|
+
*
|
|
1081
|
+
* @example
|
|
1082
|
+
* ```ts
|
|
1083
|
+
* const object = createSchema({ type: 'object' })
|
|
1084
|
+
* // { kind: 'Schema', type: 'object', primitive: 'object', properties: [] }
|
|
1085
|
+
* ```
|
|
1086
|
+
*/
|
|
1087
|
+
declare function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>;
|
|
1088
|
+
declare function createSchema(props: CreateSchemaInput): SchemaNode;
|
|
1089
|
+
//#endregion
|
|
1090
|
+
//#region src/nodes/parameter.d.ts
|
|
1091
|
+
type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
|
|
1092
|
+
/**
|
|
1093
|
+
* Parameter serialization style, controlling how a parameter value is rendered into the request.
|
|
1094
|
+
*/
|
|
1095
|
+
type ParameterStyle = 'matrix' | 'label' | 'form' | 'simple' | 'spaceDelimited' | 'pipeDelimited' | 'deepObject';
|
|
1096
|
+
/**
|
|
1097
|
+
* AST node representing one operation parameter.
|
|
1098
|
+
*
|
|
1099
|
+
* @example
|
|
1100
|
+
* ```ts
|
|
1101
|
+
* const param: ParameterNode = {
|
|
1102
|
+
* kind: 'Parameter',
|
|
1103
|
+
* name: 'petId',
|
|
1104
|
+
* in: 'path',
|
|
1105
|
+
* schema: createSchema({ type: 'string' }),
|
|
1106
|
+
* required: true,
|
|
1107
|
+
* }
|
|
1108
|
+
* ```
|
|
1109
|
+
*/
|
|
1110
|
+
type ParameterNode = BaseNode & {
|
|
1111
|
+
kind: 'Parameter';
|
|
1112
|
+
/**
|
|
1113
|
+
* Parameter name.
|
|
1114
|
+
*/
|
|
1115
|
+
name: string;
|
|
1116
|
+
/**
|
|
1117
|
+
* Parameter location (`path`, `query`, `header`, or `cookie`).
|
|
1118
|
+
*/
|
|
1119
|
+
in: ParameterLocation;
|
|
1120
|
+
/**
|
|
1121
|
+
* Parameter schema.
|
|
1122
|
+
*/
|
|
1123
|
+
schema: SchemaNode;
|
|
1124
|
+
/**
|
|
1125
|
+
* Whether the parameter is required.
|
|
1126
|
+
*/
|
|
1127
|
+
required: boolean;
|
|
1128
|
+
/**
|
|
1129
|
+
* Serialization style. Absent when the source omits it, leaving consumers to apply the
|
|
1130
|
+
* per-location default.
|
|
1131
|
+
*/
|
|
1132
|
+
style?: ParameterStyle;
|
|
1133
|
+
/**
|
|
1134
|
+
* Whether array and object values expand into separate values. Absent when the source omits it,
|
|
1135
|
+
* leaving consumers to apply the default for the style.
|
|
1136
|
+
*/
|
|
1137
|
+
explode?: boolean;
|
|
1138
|
+
};
|
|
1139
|
+
type UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>;
|
|
1140
|
+
/**
|
|
1141
|
+
* Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's
|
|
1142
|
+
* `optional`/`nullish` flags are derived from it through {@link withRequired}.
|
|
1143
|
+
*/
|
|
1144
|
+
declare const parameterDef: NodeDef<ParameterNode, UserParameterNode>;
|
|
1145
|
+
/**
|
|
1146
|
+
* Creates a `ParameterNode`.
|
|
1147
|
+
*
|
|
1148
|
+
* @example
|
|
1149
|
+
* ```ts
|
|
1150
|
+
* const param = createParameter({
|
|
1151
|
+
* name: 'petId',
|
|
1152
|
+
* in: 'path',
|
|
1153
|
+
* required: true,
|
|
1154
|
+
* schema: createSchema({ type: 'string' }),
|
|
1155
|
+
* })
|
|
1156
|
+
* ```
|
|
1157
|
+
*/
|
|
1158
|
+
declare const createParameter: (input: UserParameterNode) => ParameterNode;
|
|
1159
|
+
//#endregion
|
|
1160
|
+
//#region src/nodes/content.d.ts
|
|
1161
|
+
/**
|
|
1162
|
+
* AST node representing one content-type entry of a request body or response.
|
|
1163
|
+
*
|
|
1164
|
+
* There is one entry per content type declared in the spec (e.g. `application/json`,
|
|
1165
|
+
* `multipart/form-data`), and each entry holds its own body schema.
|
|
1166
|
+
*
|
|
1167
|
+
* @example
|
|
1168
|
+
* ```ts
|
|
1169
|
+
* const content: ContentNode = {
|
|
1170
|
+
* kind: 'Content',
|
|
1171
|
+
* contentType: 'application/json',
|
|
1172
|
+
* schema: createSchema({ type: 'string' }),
|
|
1173
|
+
* }
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
1176
|
+
type ContentNode = BaseNode & {
|
|
1177
|
+
/**
|
|
1178
|
+
* Node kind.
|
|
1179
|
+
*/
|
|
1180
|
+
kind: 'Content';
|
|
1181
|
+
/**
|
|
1182
|
+
* The content type for this entry (e.g. `'application/json'`).
|
|
1183
|
+
*/
|
|
1184
|
+
contentType: string;
|
|
1185
|
+
/**
|
|
1186
|
+
* Body schema for this content type.
|
|
1304
1187
|
*/
|
|
1305
|
-
|
|
1188
|
+
schema?: SchemaNode;
|
|
1306
1189
|
/**
|
|
1307
|
-
*
|
|
1190
|
+
* Property keys to exclude from the generated type via `Omit<Type, Keys>`.
|
|
1191
|
+
* Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.
|
|
1308
1192
|
*/
|
|
1309
|
-
|
|
1193
|
+
keysToOmit?: Array<string> | null;
|
|
1310
1194
|
};
|
|
1311
1195
|
/**
|
|
1312
|
-
*
|
|
1196
|
+
* Definition for the {@link ContentNode}.
|
|
1197
|
+
*/
|
|
1198
|
+
declare const contentDef: NodeDef<ContentNode, Omit<ContentNode, "kind">>;
|
|
1199
|
+
/**
|
|
1200
|
+
* Creates a `ContentNode` for a single request-body or response content type.
|
|
1201
|
+
*/
|
|
1202
|
+
declare const createContent: (input: Omit<ContentNode, "kind">) => ContentNode;
|
|
1203
|
+
//#endregion
|
|
1204
|
+
//#region src/nodes/requestBody.d.ts
|
|
1205
|
+
/**
|
|
1206
|
+
* AST node representing an operation request body.
|
|
1207
|
+
*
|
|
1208
|
+
* Body schemas live exclusively inside the `content` array (one entry per content type),
|
|
1209
|
+
* mirroring {@link ResponseNode}.
|
|
1313
1210
|
*
|
|
1314
1211
|
* @example
|
|
1315
1212
|
* ```ts
|
|
1316
|
-
* const
|
|
1213
|
+
* const requestBody: RequestBodyNode = {
|
|
1214
|
+
* kind: 'RequestBody',
|
|
1215
|
+
* required: true,
|
|
1216
|
+
* content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
|
|
1217
|
+
* }
|
|
1317
1218
|
* ```
|
|
1318
1219
|
*/
|
|
1319
|
-
type
|
|
1220
|
+
type RequestBodyNode = BaseNode & {
|
|
1221
|
+
kind: 'RequestBody';
|
|
1320
1222
|
/**
|
|
1321
|
-
*
|
|
1223
|
+
* Request body description carried over from the spec.
|
|
1322
1224
|
*/
|
|
1323
|
-
|
|
1225
|
+
description?: string;
|
|
1324
1226
|
/**
|
|
1325
|
-
*
|
|
1227
|
+
* Whether the request body is required (`requestBody.required: true` in the spec).
|
|
1228
|
+
* When `false` or absent, the generated `data` parameter should be optional.
|
|
1326
1229
|
*/
|
|
1327
|
-
|
|
1230
|
+
required?: boolean;
|
|
1328
1231
|
/**
|
|
1329
|
-
*
|
|
1232
|
+
* Content type entries for this request body.
|
|
1233
|
+
*
|
|
1234
|
+
* When the adapter `contentType` option is set, this array contains exactly one entry for
|
|
1235
|
+
* that content type. Otherwise it contains one entry per content type declared in the spec,
|
|
1236
|
+
* so plugins can generate code for every variant (for example, separate hooks for
|
|
1237
|
+
* `application/json` and `multipart/form-data`).
|
|
1330
1238
|
*/
|
|
1331
|
-
|
|
1239
|
+
content?: Array<ContentNode>;
|
|
1332
1240
|
};
|
|
1333
1241
|
/**
|
|
1334
|
-
*
|
|
1242
|
+
* Definition for the {@link RequestBodyNode}. Content entries are built upfront with
|
|
1243
|
+
* {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes.
|
|
1244
|
+
*/
|
|
1245
|
+
declare const requestBodyDef: NodeDef<RequestBodyNode, Omit<RequestBodyNode, "kind">>;
|
|
1246
|
+
/**
|
|
1247
|
+
* Creates a `RequestBodyNode`.
|
|
1248
|
+
*/
|
|
1249
|
+
declare const createRequestBody: (input: Omit<RequestBodyNode, "kind">) => RequestBodyNode;
|
|
1250
|
+
//#endregion
|
|
1251
|
+
//#region src/nodes/response.d.ts
|
|
1252
|
+
/**
|
|
1253
|
+
* All supported HTTP status code literals as strings, as used in API specs
|
|
1254
|
+
* (for example, `"200"` and `"404"`).
|
|
1255
|
+
*/
|
|
1256
|
+
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';
|
|
1257
|
+
/**
|
|
1258
|
+
* Response status code literal used by operations.
|
|
1259
|
+
*
|
|
1260
|
+
* Includes specific HTTP status code strings and `"default"` for catch-all responses.
|
|
1335
1261
|
*
|
|
1336
1262
|
* @example
|
|
1337
1263
|
* ```ts
|
|
1338
|
-
* const
|
|
1264
|
+
* const status: StatusCode = '200'
|
|
1265
|
+
* const fallback: StatusCode = 'default'
|
|
1339
1266
|
* ```
|
|
1340
1267
|
*/
|
|
1341
|
-
type
|
|
1342
|
-
/**
|
|
1343
|
-
* Schema type discriminator.
|
|
1344
|
-
*/
|
|
1345
|
-
type: 'ipv4';
|
|
1346
|
-
};
|
|
1268
|
+
type StatusCode = HttpStatusCode | 'default';
|
|
1347
1269
|
/**
|
|
1348
|
-
*
|
|
1270
|
+
* AST node representing one operation response variant.
|
|
1271
|
+
*
|
|
1272
|
+
* Mirrors {@link OperationNode.requestBody}: the response body schemas live exclusively inside
|
|
1273
|
+
* the `content` array (one entry per content type), so the same schema is never duplicated at the
|
|
1274
|
+
* node root and inside `content`.
|
|
1349
1275
|
*
|
|
1350
1276
|
* @example
|
|
1351
1277
|
* ```ts
|
|
1352
|
-
* const
|
|
1278
|
+
* const response: ResponseNode = {
|
|
1279
|
+
* kind: 'Response',
|
|
1280
|
+
* statusCode: '200',
|
|
1281
|
+
* content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
|
|
1282
|
+
* }
|
|
1353
1283
|
* ```
|
|
1354
1284
|
*/
|
|
1355
|
-
type
|
|
1285
|
+
type ResponseNode = BaseNode & {
|
|
1356
1286
|
/**
|
|
1357
|
-
*
|
|
1287
|
+
* Node kind.
|
|
1358
1288
|
*/
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
void: ScalarSchemaNode;
|
|
1385
|
-
never: ScalarSchemaNode;
|
|
1386
|
-
uuid: FormatStringSchemaNode;
|
|
1387
|
-
email: FormatStringSchemaNode;
|
|
1388
|
-
url: UrlSchemaNode;
|
|
1389
|
-
ipv4: Ipv4SchemaNode;
|
|
1390
|
-
ipv6: Ipv6SchemaNode;
|
|
1391
|
-
blob: ScalarSchemaNode;
|
|
1392
|
-
};
|
|
1393
|
-
/**
|
|
1394
|
-
* Union of all schema node types.
|
|
1395
|
-
*/
|
|
1396
|
-
type SchemaNode = ObjectSchemaNode | ArraySchemaNode | UnionSchemaNode | IntersectionSchemaNode | EnumSchemaNode | RefSchemaNode | DatetimeSchemaNode | DateSchemaNode | TimeSchemaNode | StringSchemaNode | NumberSchemaNode | UrlSchemaNode | FormatStringSchemaNode | Ipv4SchemaNode | Ipv6SchemaNode | ScalarSchemaNode;
|
|
1397
|
-
type CreateSchemaObjectInput = Omit<ObjectSchemaNode, 'kind' | 'properties' | 'primitive'> & {
|
|
1398
|
-
properties?: Array<PropertyNode>;
|
|
1399
|
-
primitive?: 'object';
|
|
1289
|
+
kind: 'Response';
|
|
1290
|
+
/**
|
|
1291
|
+
* HTTP status code or `'default'` for a fallback response.
|
|
1292
|
+
*/
|
|
1293
|
+
statusCode: StatusCode;
|
|
1294
|
+
/**
|
|
1295
|
+
* Optional response description.
|
|
1296
|
+
*/
|
|
1297
|
+
description?: string;
|
|
1298
|
+
/**
|
|
1299
|
+
* All available content type entries for this response.
|
|
1300
|
+
*
|
|
1301
|
+
* When the adapter `contentType` option is set, this array contains exactly one entry for that
|
|
1302
|
+
* content type. Otherwise it contains one entry per content type declared in the spec, so that
|
|
1303
|
+
* plugins can generate a union of response types (e.g. `application/json` and `application/xml`).
|
|
1304
|
+
* Body-less responses keep a single entry whose `schema` is the empty/`void` placeholder.
|
|
1305
|
+
*
|
|
1306
|
+
* @example
|
|
1307
|
+
* ```ts
|
|
1308
|
+
* // spec response declares both application/json and application/xml
|
|
1309
|
+
* response.content[0].contentType // 'application/json'
|
|
1310
|
+
* response.content[1].contentType // 'application/xml'
|
|
1311
|
+
* ```
|
|
1312
|
+
*/
|
|
1313
|
+
content?: Array<ContentNode>;
|
|
1400
1314
|
};
|
|
1401
|
-
type
|
|
1402
|
-
|
|
1403
|
-
|
|
1315
|
+
type ResponseInput = Pick<ResponseNode, 'statusCode'> & Partial<Omit<ResponseNode, 'kind' | 'statusCode' | 'content'>> & {
|
|
1316
|
+
content?: Array<ContentNode>;
|
|
1317
|
+
schema?: SchemaNode;
|
|
1318
|
+
mediaType?: string | null;
|
|
1319
|
+
keysToOmit?: Array<string> | null;
|
|
1404
1320
|
};
|
|
1405
1321
|
/**
|
|
1406
|
-
* Definition for the {@link
|
|
1407
|
-
*
|
|
1322
|
+
* Definition for the {@link ResponseNode}. A single legacy `schema` (with optional
|
|
1323
|
+
* `mediaType`/`keysToOmit`) is normalized into one `content` entry.
|
|
1408
1324
|
*/
|
|
1409
|
-
declare const
|
|
1325
|
+
declare const responseDef: NodeDef<ResponseNode, ResponseInput>;
|
|
1410
1326
|
/**
|
|
1411
|
-
* Creates a `
|
|
1412
|
-
*
|
|
1413
|
-
* @example
|
|
1414
|
-
* ```ts
|
|
1415
|
-
* const scalar = createSchema({ type: 'string' })
|
|
1416
|
-
* // { kind: 'Schema', type: 'string', primitive: 'string' }
|
|
1417
|
-
* ```
|
|
1327
|
+
* Creates a `ResponseNode`.
|
|
1418
1328
|
*
|
|
1419
1329
|
* @example
|
|
1420
1330
|
* ```ts
|
|
1421
|
-
* const
|
|
1422
|
-
*
|
|
1331
|
+
* const response = createResponse({
|
|
1332
|
+
* statusCode: '200',
|
|
1333
|
+
* content: [createContent({ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) })],
|
|
1334
|
+
* })
|
|
1423
1335
|
* ```
|
|
1424
1336
|
*/
|
|
1425
|
-
declare
|
|
1426
|
-
declare function createSchema(props: CreateSchemaInput): SchemaNode;
|
|
1337
|
+
declare const createResponse: (input: ResponseInput) => ResponseNode;
|
|
1427
1338
|
//#endregion
|
|
1428
|
-
//#region src/nodes/
|
|
1339
|
+
//#region src/nodes/operation.d.ts
|
|
1429
1340
|
/**
|
|
1430
|
-
*
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1341
|
+
* HTTP method an operation responds to.
|
|
1342
|
+
*/
|
|
1343
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
|
|
1344
|
+
/**
|
|
1345
|
+
* Transport an operation belongs to.
|
|
1346
|
+
*/
|
|
1347
|
+
type OperationProtocol = 'http';
|
|
1348
|
+
/**
|
|
1349
|
+
* Fields shared by every operation, regardless of transport.
|
|
1350
|
+
*/
|
|
1351
|
+
type OperationNodeBase = BaseNode & {
|
|
1352
|
+
/**
|
|
1353
|
+
* Node kind.
|
|
1354
|
+
*/
|
|
1355
|
+
kind: 'Operation';
|
|
1356
|
+
/**
|
|
1357
|
+
* Stable identifier for the operation.
|
|
1358
|
+
*/
|
|
1359
|
+
operationId: string;
|
|
1360
|
+
/**
|
|
1361
|
+
* Group labels for the operation.
|
|
1362
|
+
*/
|
|
1363
|
+
tags: Array<string>;
|
|
1364
|
+
/**
|
|
1365
|
+
* Short one-line operation summary.
|
|
1366
|
+
*/
|
|
1367
|
+
summary?: string;
|
|
1368
|
+
/**
|
|
1369
|
+
* Full operation description.
|
|
1370
|
+
*/
|
|
1371
|
+
description?: string;
|
|
1372
|
+
/**
|
|
1373
|
+
* Marks the operation as deprecated.
|
|
1374
|
+
*/
|
|
1375
|
+
deprecated?: boolean;
|
|
1376
|
+
/**
|
|
1377
|
+
* Query, path, header, and cookie parameters for the operation.
|
|
1378
|
+
*/
|
|
1379
|
+
parameters: Array<ParameterNode>;
|
|
1380
|
+
/**
|
|
1381
|
+
* Request body for the operation.
|
|
1382
|
+
*/
|
|
1383
|
+
requestBody?: RequestBodyNode;
|
|
1384
|
+
/**
|
|
1385
|
+
* Operation responses.
|
|
1386
|
+
*/
|
|
1387
|
+
responses: Array<ResponseNode>;
|
|
1388
|
+
};
|
|
1389
|
+
/**
|
|
1390
|
+
* Operation served over HTTP. `method` and `path` are guaranteed.
|
|
1434
1391
|
*
|
|
1435
1392
|
* @example
|
|
1436
1393
|
* ```ts
|
|
1437
|
-
* const
|
|
1438
|
-
* kind: '
|
|
1439
|
-
*
|
|
1440
|
-
*
|
|
1394
|
+
* const operation: HttpOperationNode = {
|
|
1395
|
+
* kind: 'Operation',
|
|
1396
|
+
* operationId: 'listPets',
|
|
1397
|
+
* protocol: 'http',
|
|
1398
|
+
* method: 'GET',
|
|
1399
|
+
* path: '/pets',
|
|
1400
|
+
* tags: [],
|
|
1401
|
+
* parameters: [],
|
|
1402
|
+
* responses: [],
|
|
1441
1403
|
* }
|
|
1442
1404
|
* ```
|
|
1443
1405
|
*/
|
|
1444
|
-
type
|
|
1445
|
-
/**
|
|
1446
|
-
* Node kind.
|
|
1447
|
-
*/
|
|
1448
|
-
kind: 'Content';
|
|
1406
|
+
type HttpOperationNode = OperationNodeBase & {
|
|
1449
1407
|
/**
|
|
1450
|
-
*
|
|
1408
|
+
* Transport the operation belongs to.
|
|
1451
1409
|
*/
|
|
1452
|
-
|
|
1410
|
+
protocol?: 'http';
|
|
1453
1411
|
/**
|
|
1454
|
-
*
|
|
1412
|
+
* HTTP method like `'GET'`.
|
|
1455
1413
|
*/
|
|
1456
|
-
|
|
1414
|
+
method: HttpMethod;
|
|
1457
1415
|
/**
|
|
1458
|
-
*
|
|
1459
|
-
* Set when a referenced schema has `readOnly`/`writeOnly` fields that should be omitted.
|
|
1416
|
+
* Path string, for example `/pets/{petId}`, with `{param}` notation preserved.
|
|
1460
1417
|
*/
|
|
1461
|
-
|
|
1418
|
+
path: string;
|
|
1462
1419
|
};
|
|
1463
1420
|
/**
|
|
1464
|
-
*
|
|
1421
|
+
* Operation for a non-HTTP transport. HTTP-only fields are forbidden.
|
|
1465
1422
|
*/
|
|
1466
|
-
|
|
1423
|
+
type GenericOperationNode = OperationNodeBase & {
|
|
1424
|
+
/**
|
|
1425
|
+
* Transport the operation belongs to.
|
|
1426
|
+
*/
|
|
1427
|
+
protocol?: Exclude<OperationProtocol, 'http'>;
|
|
1428
|
+
method?: never;
|
|
1429
|
+
path?: never;
|
|
1430
|
+
};
|
|
1467
1431
|
/**
|
|
1468
|
-
*
|
|
1432
|
+
* AST node representing one API operation.
|
|
1433
|
+
*
|
|
1434
|
+
* Discriminated on `protocol`: an {@link HttpOperationNode} (`protocol: 'http'`) guarantees
|
|
1435
|
+
* `method` and `path`, while a {@link GenericOperationNode} omits them. Narrow with
|
|
1436
|
+
* `isHttpOperationNode(node)` or `node.protocol === 'http'` before reading `method`/`path`.
|
|
1469
1437
|
*/
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1438
|
+
type OperationNode = HttpOperationNode | GenericOperationNode;
|
|
1439
|
+
type OperationInput = {
|
|
1440
|
+
operationId: string;
|
|
1441
|
+
method?: HttpOperationNode['method'];
|
|
1442
|
+
path?: HttpOperationNode['path'];
|
|
1443
|
+
requestBody?: Omit<RequestBodyNode, 'kind'>;
|
|
1444
|
+
[key: string]: unknown;
|
|
1445
|
+
};
|
|
1473
1446
|
/**
|
|
1474
|
-
*
|
|
1447
|
+
* Definition for the {@link OperationNode}. HTTP operations (those carrying both
|
|
1448
|
+
* `method` and `path`) are tagged with `protocol: 'http'`, and the request body is
|
|
1449
|
+
* normalized into a `RequestBodyNode`.
|
|
1475
1450
|
*/
|
|
1476
|
-
|
|
1477
|
-
type ImportName = string | Array<string | {
|
|
1478
|
-
propertyName: string;
|
|
1479
|
-
name?: string;
|
|
1480
|
-
}>;
|
|
1451
|
+
declare const operationDef: NodeDef<OperationNode, OperationInput>;
|
|
1481
1452
|
/**
|
|
1482
|
-
*
|
|
1483
|
-
*
|
|
1484
|
-
* @example Named import (TypeScript: `import { useState } from 'react'`)
|
|
1485
|
-
* ```ts
|
|
1486
|
-
* createImport({ name: ['useState'], path: 'react' })
|
|
1487
|
-
* ```
|
|
1488
|
-
*
|
|
1489
|
-
* @example Default import (TypeScript: `import React from 'react'`)
|
|
1490
|
-
* ```ts
|
|
1491
|
-
* createImport({ name: 'React', path: 'react' })
|
|
1492
|
-
* ```
|
|
1493
|
-
*
|
|
1494
|
-
* @example Type-only import (TypeScript: `import type { FC } from 'react'`)
|
|
1495
|
-
* ```ts
|
|
1496
|
-
* createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
|
|
1497
|
-
* ```
|
|
1453
|
+
* Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.
|
|
1498
1454
|
*
|
|
1499
|
-
* @example
|
|
1455
|
+
* @example
|
|
1500
1456
|
* ```ts
|
|
1501
|
-
*
|
|
1457
|
+
* const operation = createOperation({ operationId: 'getPetById', method: 'GET', path: '/pet/{petId}' })
|
|
1458
|
+
* // tags, parameters, and responses are []
|
|
1502
1459
|
* ```
|
|
1503
1460
|
*/
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1461
|
+
declare function createOperation(props: Pick<HttpOperationNode, 'operationId' | 'method' | 'path'> & Partial<Omit<HttpOperationNode, 'kind' | 'operationId' | 'method' | 'path' | 'requestBody'>> & {
|
|
1462
|
+
requestBody?: Omit<RequestBodyNode, 'kind'>;
|
|
1463
|
+
}): HttpOperationNode;
|
|
1464
|
+
declare function createOperation(props: Pick<GenericOperationNode, 'operationId'> & Partial<Omit<GenericOperationNode, 'kind' | 'operationId' | 'requestBody'>> & {
|
|
1465
|
+
requestBody?: Omit<RequestBodyNode, 'kind'>;
|
|
1466
|
+
}): GenericOperationNode;
|
|
1467
|
+
//#endregion
|
|
1468
|
+
//#region src/nodes/code.d.ts
|
|
1469
|
+
/**
|
|
1470
|
+
* JSDoc documentation metadata attached to code declarations.
|
|
1471
|
+
*/
|
|
1472
|
+
type JSDocNode = {
|
|
1516
1473
|
/**
|
|
1517
|
-
*
|
|
1474
|
+
* JSDoc comment lines. `undefined` entries are filtered out during rendering.
|
|
1518
1475
|
*
|
|
1519
1476
|
* @example
|
|
1520
|
-
*
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
/**
|
|
1524
|
-
* Add a type-only import prefix.
|
|
1525
|
-
* - `true` generates `import type { Type } from './path'`
|
|
1526
|
-
* - `false` generates `import { Type } from './path'`
|
|
1527
|
-
*/
|
|
1528
|
-
isTypeOnly?: boolean | null;
|
|
1529
|
-
/**
|
|
1530
|
-
* Import the entire module as a namespace.
|
|
1531
|
-
* - `true` generates `import * as Name from './path'`
|
|
1532
|
-
* - `false` generates a standard import
|
|
1533
|
-
*/
|
|
1534
|
-
isNameSpace?: boolean | null;
|
|
1535
|
-
/**
|
|
1536
|
-
* When set, the import path is resolved relative to this root.
|
|
1477
|
+
* ```ts
|
|
1478
|
+
* ['@description A pet resource', '@deprecated']
|
|
1479
|
+
* ```
|
|
1537
1480
|
*/
|
|
1538
|
-
|
|
1481
|
+
comments?: Array<string | undefined>;
|
|
1539
1482
|
};
|
|
1540
1483
|
/**
|
|
1541
|
-
*
|
|
1542
|
-
*
|
|
1543
|
-
* @example Named export (TypeScript: `export { Pets } from './Pets'`)
|
|
1544
|
-
* ```ts
|
|
1545
|
-
* createExport({ name: ['Pets'], path: './Pets' })
|
|
1546
|
-
* ```
|
|
1547
|
-
*
|
|
1548
|
-
* @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
|
|
1549
|
-
* ```ts
|
|
1550
|
-
* createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })
|
|
1551
|
-
* ```
|
|
1484
|
+
* AST node representing a TypeScript `const` declaration.
|
|
1552
1485
|
*
|
|
1553
|
-
*
|
|
1554
|
-
*
|
|
1555
|
-
* createExport({ path: './utils' })
|
|
1556
|
-
* ```
|
|
1486
|
+
* Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.
|
|
1487
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
1557
1488
|
*
|
|
1558
|
-
* @example
|
|
1489
|
+
* @example
|
|
1559
1490
|
* ```ts
|
|
1560
|
-
*
|
|
1491
|
+
* createConst({ name: 'pet', export: true, asConst: true })
|
|
1492
|
+
* // export const pet = ... as const
|
|
1561
1493
|
* ```
|
|
1562
1494
|
*/
|
|
1563
|
-
type
|
|
1564
|
-
kind: '
|
|
1495
|
+
type ConstNode = BaseNode & {
|
|
1496
|
+
kind: 'Const';
|
|
1565
1497
|
/**
|
|
1566
|
-
*
|
|
1567
|
-
*
|
|
1568
|
-
* @example Named exports
|
|
1569
|
-
* `['useState']`
|
|
1570
|
-
*
|
|
1571
|
-
* @example Single export
|
|
1572
|
-
* `'React'`
|
|
1498
|
+
* Name of the constant declaration.
|
|
1573
1499
|
*/
|
|
1574
|
-
name
|
|
1500
|
+
name: string;
|
|
1575
1501
|
/**
|
|
1576
|
-
*
|
|
1502
|
+
* Whether the declaration should be exported.
|
|
1503
|
+
*/
|
|
1504
|
+
export?: boolean | null;
|
|
1505
|
+
/**
|
|
1506
|
+
* Explicit type annotation.
|
|
1577
1507
|
*
|
|
1578
|
-
* @example
|
|
1579
|
-
* `'
|
|
1508
|
+
* @example Type reference
|
|
1509
|
+
* `'Pet'`
|
|
1580
1510
|
*/
|
|
1581
|
-
|
|
1511
|
+
type?: string | null;
|
|
1582
1512
|
/**
|
|
1583
|
-
*
|
|
1584
|
-
* - `true` generates `export type { Type } from './path'`
|
|
1585
|
-
* - `false` generates `export { Type } from './path'`
|
|
1513
|
+
* JSDoc documentation metadata.
|
|
1586
1514
|
*/
|
|
1587
|
-
|
|
1515
|
+
JSDoc?: JSDocNode | null;
|
|
1588
1516
|
/**
|
|
1589
|
-
*
|
|
1590
|
-
* - `true` generates `export * as aliasName from './path'`
|
|
1591
|
-
* - `false` generates a standard export
|
|
1517
|
+
* Whether to append `as const` to the declaration.
|
|
1592
1518
|
*/
|
|
1593
|
-
|
|
1519
|
+
asConst?: boolean | null;
|
|
1520
|
+
/**
|
|
1521
|
+
* Child nodes representing the value of the constant (children of the `Const` component).
|
|
1522
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
1523
|
+
*/
|
|
1524
|
+
nodes?: Array<CodeNode>;
|
|
1594
1525
|
};
|
|
1595
1526
|
/**
|
|
1596
|
-
*
|
|
1527
|
+
* AST node representing a TypeScript `type` alias declaration.
|
|
1597
1528
|
*
|
|
1598
|
-
*
|
|
1599
|
-
*
|
|
1600
|
-
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })
|
|
1601
|
-
* ```
|
|
1529
|
+
* Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.
|
|
1530
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
1602
1531
|
*
|
|
1603
|
-
* @example
|
|
1532
|
+
* @example
|
|
1604
1533
|
* ```ts
|
|
1605
|
-
*
|
|
1534
|
+
* createType({ name: 'Pet', export: true })
|
|
1535
|
+
* // export type Pet = ...
|
|
1606
1536
|
* ```
|
|
1607
1537
|
*/
|
|
1608
|
-
type
|
|
1609
|
-
kind: '
|
|
1610
|
-
/**
|
|
1611
|
-
* Optional name identifying this source (used for deduplication and barrel generation).
|
|
1612
|
-
*/
|
|
1613
|
-
name?: string | null;
|
|
1538
|
+
type TypeNode = BaseNode & {
|
|
1539
|
+
kind: 'Type';
|
|
1614
1540
|
/**
|
|
1615
|
-
*
|
|
1541
|
+
* Name of the type alias.
|
|
1616
1542
|
*/
|
|
1617
|
-
|
|
1543
|
+
name: string;
|
|
1618
1544
|
/**
|
|
1619
|
-
*
|
|
1545
|
+
* Whether the declaration should be exported.
|
|
1620
1546
|
*/
|
|
1621
|
-
|
|
1547
|
+
export?: boolean | null;
|
|
1622
1548
|
/**
|
|
1623
|
-
*
|
|
1549
|
+
* JSDoc documentation metadata.
|
|
1624
1550
|
*/
|
|
1625
|
-
|
|
1551
|
+
JSDoc?: JSDocNode | null;
|
|
1626
1552
|
/**
|
|
1627
|
-
* Child nodes
|
|
1628
|
-
*
|
|
1553
|
+
* Child nodes representing the type body (children of the `Type` component).
|
|
1554
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
1629
1555
|
*/
|
|
1630
1556
|
nodes?: Array<CodeNode>;
|
|
1631
1557
|
};
|
|
1632
1558
|
/**
|
|
1633
|
-
*
|
|
1634
|
-
*
|
|
1635
|
-
* Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input
|
|
1636
|
-
* and deduplicates `imports`, `exports`, and `sources`.
|
|
1559
|
+
* AST node representing a TypeScript `function` declaration.
|
|
1637
1560
|
*
|
|
1638
|
-
*
|
|
1639
|
-
*
|
|
1640
|
-
*
|
|
1641
|
-
*
|
|
1642
|
-
*
|
|
1643
|
-
*
|
|
1644
|
-
*
|
|
1645
|
-
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
1646
|
-
* })
|
|
1647
|
-
* // file.id = SHA256 hash of the path
|
|
1648
|
-
* // file.name = 'petStore'
|
|
1649
|
-
* // file.extname = '.ts'
|
|
1561
|
+
* Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.
|
|
1562
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
1563
|
+
*
|
|
1564
|
+
* @example
|
|
1565
|
+
* ```ts
|
|
1566
|
+
* createFunction({ name: 'getPet', export: true, async: true, returnType: 'Pet' })
|
|
1567
|
+
* // export async function getPet(): Promise<Pet> { ... }
|
|
1650
1568
|
* ```
|
|
1651
1569
|
*/
|
|
1652
|
-
type
|
|
1653
|
-
kind: '
|
|
1570
|
+
type FunctionNode = BaseNode & {
|
|
1571
|
+
kind: 'Function';
|
|
1654
1572
|
/**
|
|
1655
|
-
*
|
|
1656
|
-
* computes it, so callers do not need to provide it.
|
|
1573
|
+
* Name of the function.
|
|
1657
1574
|
*/
|
|
1658
|
-
|
|
1575
|
+
name: string;
|
|
1659
1576
|
/**
|
|
1660
|
-
*
|
|
1661
|
-
*
|
|
1662
|
-
* @see https://nodejs.org/api/path.html#pathformatpathobject
|
|
1577
|
+
* Whether the function is a default export.
|
|
1663
1578
|
*/
|
|
1664
|
-
|
|
1579
|
+
default?: boolean | null;
|
|
1665
1580
|
/**
|
|
1666
|
-
*
|
|
1581
|
+
* Function parameter list as a pre-rendered string, written verbatim between the parentheses.
|
|
1667
1582
|
*
|
|
1668
|
-
* @
|
|
1583
|
+
* @example
|
|
1584
|
+
* `'id: string, config: Config = {}'`
|
|
1669
1585
|
*/
|
|
1670
|
-
|
|
1586
|
+
params?: string | null;
|
|
1671
1587
|
/**
|
|
1672
|
-
*
|
|
1588
|
+
* Whether the function should be exported.
|
|
1673
1589
|
*/
|
|
1674
|
-
|
|
1590
|
+
export?: boolean | null;
|
|
1675
1591
|
/**
|
|
1676
|
-
*
|
|
1592
|
+
* Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
1677
1593
|
*/
|
|
1678
|
-
|
|
1594
|
+
async?: boolean | null;
|
|
1679
1595
|
/**
|
|
1680
|
-
*
|
|
1596
|
+
* TypeScript generic type parameters.
|
|
1597
|
+
*
|
|
1598
|
+
* @example Constrained generics
|
|
1599
|
+
* `['T', 'U extends string']`
|
|
1681
1600
|
*/
|
|
1682
|
-
|
|
1601
|
+
generics?: string | Array<string> | null;
|
|
1683
1602
|
/**
|
|
1684
|
-
*
|
|
1603
|
+
* Return type annotation.
|
|
1604
|
+
*
|
|
1605
|
+
* @example Type reference
|
|
1606
|
+
* `'Pet'`
|
|
1685
1607
|
*/
|
|
1686
|
-
|
|
1608
|
+
returnType?: string | null;
|
|
1687
1609
|
/**
|
|
1688
|
-
*
|
|
1610
|
+
* JSDoc documentation metadata.
|
|
1689
1611
|
*/
|
|
1690
|
-
|
|
1612
|
+
JSDoc?: JSDocNode | null;
|
|
1691
1613
|
/**
|
|
1692
|
-
*
|
|
1614
|
+
* Child nodes representing the function body (children of the `Function` component).
|
|
1615
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
1693
1616
|
*/
|
|
1694
|
-
|
|
1617
|
+
nodes?: Array<CodeNode>;
|
|
1618
|
+
};
|
|
1619
|
+
/**
|
|
1620
|
+
* AST node representing a TypeScript arrow function (`const name = () => { ... }`).
|
|
1621
|
+
*
|
|
1622
|
+
* Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.
|
|
1623
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
1624
|
+
*
|
|
1625
|
+
* @example
|
|
1626
|
+
* ```ts
|
|
1627
|
+
* createArrowFunction({ name: 'getPet', export: true, singleLine: true })
|
|
1628
|
+
* // export const getPet = () => ...
|
|
1629
|
+
* ```
|
|
1630
|
+
*/
|
|
1631
|
+
type ArrowFunctionNode = Omit<FunctionNode, 'kind'> & {
|
|
1632
|
+
kind: 'ArrowFunction';
|
|
1695
1633
|
/**
|
|
1696
|
-
*
|
|
1697
|
-
* Accepts `null` so `resolver.default.banner()` results can be passed directly.
|
|
1634
|
+
* Render the arrow function body as a single-line expression.
|
|
1698
1635
|
*/
|
|
1699
|
-
|
|
1636
|
+
singleLine?: boolean | null;
|
|
1637
|
+
};
|
|
1638
|
+
/**
|
|
1639
|
+
* AST node representing a raw text/string fragment in the source output.
|
|
1640
|
+
*
|
|
1641
|
+
* Used instead of bare `string` values so that all entries in `nodes` arrays
|
|
1642
|
+
* are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.
|
|
1643
|
+
*
|
|
1644
|
+
* @example
|
|
1645
|
+
* ```ts
|
|
1646
|
+
* createText('return fetch(id)')
|
|
1647
|
+
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
1648
|
+
* ```
|
|
1649
|
+
*/
|
|
1650
|
+
type TextNode = BaseNode & {
|
|
1651
|
+
kind: 'Text';
|
|
1700
1652
|
/**
|
|
1701
|
-
*
|
|
1702
|
-
* Accepts `null` so `resolver.default.footer()` results can be passed directly.
|
|
1653
|
+
* The raw string content.
|
|
1703
1654
|
*/
|
|
1704
|
-
|
|
1655
|
+
value: string;
|
|
1656
|
+
};
|
|
1657
|
+
/**
|
|
1658
|
+
* AST node representing a blank line in the source output.
|
|
1659
|
+
*
|
|
1660
|
+
* Corresponds to `<br/>` in JSX components. `printNodes` turns a `Break` between two
|
|
1661
|
+
* statements into one blank line. Consecutive breaks, and breaks at the start or end of
|
|
1662
|
+
* the list, are folded away, so a `Break` never produces more than one blank line.
|
|
1663
|
+
*
|
|
1664
|
+
* @example
|
|
1665
|
+
* ```ts
|
|
1666
|
+
* createBreak()
|
|
1667
|
+
* // { kind: 'Break' }
|
|
1668
|
+
* ```
|
|
1669
|
+
*/
|
|
1670
|
+
type BreakNode = BaseNode & {
|
|
1671
|
+
kind: 'Break';
|
|
1672
|
+
};
|
|
1673
|
+
/**
|
|
1674
|
+
* AST node representing a raw JSX fragment in the source output.
|
|
1675
|
+
*
|
|
1676
|
+
* Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup
|
|
1677
|
+
* (including fragments `<>…</>`) directly in generated code.
|
|
1678
|
+
*
|
|
1679
|
+
* @example
|
|
1680
|
+
* ```ts
|
|
1681
|
+
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
1682
|
+
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
1683
|
+
* ```
|
|
1684
|
+
*/
|
|
1685
|
+
type JsxNode = BaseNode & {
|
|
1686
|
+
kind: 'Jsx';
|
|
1705
1687
|
/**
|
|
1706
|
-
*
|
|
1707
|
-
*
|
|
1708
|
-
* Use to emit a real source file shipped inside a package (a template) into the generated
|
|
1709
|
-
* folder. When set, `copy` provides the file content and any `sources` nodes are ignored for
|
|
1710
|
-
* output; `sources` may still carry `name`/`isExportable`/`isIndexable` so barrel generation
|
|
1711
|
-
* treats the file the same as a rendered one.
|
|
1688
|
+
* The raw JSX string content.
|
|
1712
1689
|
*/
|
|
1713
|
-
|
|
1690
|
+
value: string;
|
|
1714
1691
|
};
|
|
1715
1692
|
/**
|
|
1716
|
-
*
|
|
1693
|
+
* Union of all code-generation AST nodes.
|
|
1694
|
+
*
|
|
1695
|
+
* These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as
|
|
1696
|
+
* structured children in {@link SourceNode.nodes}.
|
|
1717
1697
|
*/
|
|
1718
|
-
|
|
1698
|
+
type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
|
|
1719
1699
|
/**
|
|
1720
|
-
* Definition for the {@link
|
|
1700
|
+
* Definition for the {@link ConstNode}.
|
|
1721
1701
|
*/
|
|
1722
|
-
declare const
|
|
1702
|
+
declare const constDef: NodeDef<ConstNode, Omit<ConstNode, "kind">>;
|
|
1723
1703
|
/**
|
|
1724
|
-
* Definition for the {@link
|
|
1704
|
+
* Definition for the {@link TypeNode}.
|
|
1725
1705
|
*/
|
|
1726
|
-
declare const
|
|
1706
|
+
declare const typeDef: NodeDef<TypeNode, Omit<TypeNode, "kind">>;
|
|
1727
1707
|
/**
|
|
1728
|
-
* Definition for the {@link
|
|
1729
|
-
* `createFile`, so this definition only supplies the guard.
|
|
1708
|
+
* Definition for the {@link FunctionNode}.
|
|
1730
1709
|
*/
|
|
1731
|
-
declare const
|
|
1710
|
+
declare const functionDef: NodeDef<FunctionNode, Omit<FunctionNode, "kind">>;
|
|
1732
1711
|
/**
|
|
1733
|
-
*
|
|
1712
|
+
* Definition for the {@link ArrowFunctionNode}.
|
|
1713
|
+
*/
|
|
1714
|
+
declare const arrowFunctionDef: NodeDef<ArrowFunctionNode, Omit<ArrowFunctionNode, "kind">>;
|
|
1715
|
+
/**
|
|
1716
|
+
* Definition for the {@link TextNode}.
|
|
1717
|
+
*/
|
|
1718
|
+
declare const textDef: NodeDef<TextNode, string>;
|
|
1719
|
+
/**
|
|
1720
|
+
* Definition for the {@link BreakNode}.
|
|
1721
|
+
*/
|
|
1722
|
+
declare const breakDef: NodeDef<BreakNode, void>;
|
|
1723
|
+
/**
|
|
1724
|
+
* Definition for the {@link JsxNode}.
|
|
1725
|
+
*/
|
|
1726
|
+
declare const jsxDef: NodeDef<JsxNode, string>;
|
|
1727
|
+
/**
|
|
1728
|
+
* Creates a `ConstNode` representing a TypeScript `const` declaration.
|
|
1734
1729
|
*
|
|
1735
|
-
* @example
|
|
1730
|
+
* @example Exported constant with type and `as const`
|
|
1736
1731
|
* ```ts
|
|
1737
|
-
*
|
|
1738
|
-
* //
|
|
1732
|
+
* createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
|
|
1733
|
+
* // export const pets: Pet[] = ... as const
|
|
1739
1734
|
* ```
|
|
1740
1735
|
*/
|
|
1741
|
-
declare const
|
|
1736
|
+
declare const createConst: (input: Omit<ConstNode, "kind">) => ConstNode;
|
|
1742
1737
|
/**
|
|
1743
|
-
* Creates
|
|
1738
|
+
* Creates a `TypeNode` representing a TypeScript `type` alias declaration.
|
|
1744
1739
|
*
|
|
1745
|
-
* @example
|
|
1740
|
+
* @example
|
|
1746
1741
|
* ```ts
|
|
1747
|
-
*
|
|
1748
|
-
* // export
|
|
1742
|
+
* createType({ name: 'Pet', export: true })
|
|
1743
|
+
* // export type Pet = ...
|
|
1749
1744
|
* ```
|
|
1750
1745
|
*/
|
|
1751
|
-
declare const
|
|
1746
|
+
declare const createType: (input: Omit<TypeNode, "kind">) => TypeNode;
|
|
1752
1747
|
/**
|
|
1753
|
-
* Creates a `
|
|
1748
|
+
* Creates a `FunctionNode` representing a TypeScript `function` declaration.
|
|
1754
1749
|
*
|
|
1755
1750
|
* @example
|
|
1756
1751
|
* ```ts
|
|
1757
|
-
*
|
|
1752
|
+
* createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
|
|
1753
|
+
* // export async function fetchPet(): Promise<Pet> { ... }
|
|
1758
1754
|
* ```
|
|
1759
1755
|
*/
|
|
1760
|
-
declare const
|
|
1756
|
+
declare const createFunction: (input: Omit<FunctionNode, "kind">) => FunctionNode;
|
|
1761
1757
|
/**
|
|
1762
|
-
*
|
|
1763
|
-
*
|
|
1758
|
+
* Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
|
|
1759
|
+
*
|
|
1760
|
+
* @example
|
|
1761
|
+
* ```ts
|
|
1762
|
+
* createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
|
|
1763
|
+
* // export const double = (n: number) => ...
|
|
1764
|
+
* ```
|
|
1764
1765
|
*/
|
|
1765
|
-
|
|
1766
|
+
declare const createArrowFunction: (input: Omit<ArrowFunctionNode, "kind">) => ArrowFunctionNode;
|
|
1766
1767
|
/**
|
|
1767
|
-
* Creates a
|
|
1768
|
-
*
|
|
1769
|
-
* Computes:
|
|
1770
|
-
* - `id` SHA256 hash of the file path
|
|
1771
|
-
* - `name` `baseName` without extension
|
|
1772
|
-
* - `extname` extension extracted from `baseName`
|
|
1773
|
-
*
|
|
1774
|
-
* Deduplicates:
|
|
1775
|
-
* - `sources` via `combineSources`
|
|
1776
|
-
* - `exports` via `combineExports`
|
|
1777
|
-
* - `imports` via `combineImports` (also filters unused imports)
|
|
1778
|
-
*
|
|
1779
|
-
* @throws {Error} when `baseName` has no extension.
|
|
1768
|
+
* Creates a {@link TextNode} representing a raw string fragment in the source output.
|
|
1780
1769
|
*
|
|
1781
1770
|
* @example
|
|
1782
1771
|
* ```ts
|
|
1783
|
-
*
|
|
1784
|
-
*
|
|
1785
|
-
* path: 'src/models/petStore.ts',
|
|
1786
|
-
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
1787
|
-
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
1788
|
-
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
1789
|
-
* })
|
|
1790
|
-
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
1791
|
-
* // file.name = 'petStore'
|
|
1792
|
-
* // file.extname = '.ts'
|
|
1772
|
+
* createText('return fetch(id)')
|
|
1773
|
+
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
1793
1774
|
* ```
|
|
1775
|
+
*/
|
|
1776
|
+
declare const createText: (input: string) => TextNode;
|
|
1777
|
+
/**
|
|
1778
|
+
* Creates a {@link BreakNode} representing a line break in the source output.
|
|
1794
1779
|
*
|
|
1795
|
-
* @example
|
|
1780
|
+
* @example
|
|
1796
1781
|
* ```ts
|
|
1797
|
-
*
|
|
1798
|
-
*
|
|
1799
|
-
*
|
|
1800
|
-
|
|
1801
|
-
|
|
1782
|
+
* createBreak()
|
|
1783
|
+
* // { kind: 'Break' }
|
|
1784
|
+
* ```
|
|
1785
|
+
*/
|
|
1786
|
+
declare function createBreak(): BreakNode;
|
|
1787
|
+
/**
|
|
1788
|
+
* Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
|
|
1789
|
+
*
|
|
1790
|
+
* @example
|
|
1791
|
+
* ```ts
|
|
1792
|
+
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
1793
|
+
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
1802
1794
|
* ```
|
|
1803
1795
|
*/
|
|
1804
|
-
declare
|
|
1796
|
+
declare const createJsx: (input: string) => JsxNode;
|
|
1805
1797
|
//#endregion
|
|
1806
|
-
//#region src/nodes/
|
|
1807
|
-
type ParameterLocation = 'path' | 'query' | 'header' | 'cookie';
|
|
1798
|
+
//#region src/nodes/file.d.ts
|
|
1808
1799
|
/**
|
|
1809
|
-
*
|
|
1800
|
+
* Supported file extensions.
|
|
1810
1801
|
*/
|
|
1811
|
-
type
|
|
1802
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
1803
|
+
type ImportName = string | Array<string | {
|
|
1804
|
+
propertyName: string;
|
|
1805
|
+
name?: string;
|
|
1806
|
+
}>;
|
|
1812
1807
|
/**
|
|
1813
|
-
*
|
|
1808
|
+
* Represents a language-agnostic import/dependency declaration.
|
|
1814
1809
|
*
|
|
1815
|
-
* @example
|
|
1810
|
+
* @example Named import (TypeScript: `import { useState } from 'react'`)
|
|
1816
1811
|
* ```ts
|
|
1817
|
-
*
|
|
1818
|
-
*
|
|
1819
|
-
*
|
|
1820
|
-
*
|
|
1821
|
-
*
|
|
1822
|
-
*
|
|
1823
|
-
*
|
|
1812
|
+
* createImport({ name: ['useState'], path: 'react' })
|
|
1813
|
+
* ```
|
|
1814
|
+
*
|
|
1815
|
+
* @example Default import (TypeScript: `import React from 'react'`)
|
|
1816
|
+
* ```ts
|
|
1817
|
+
* createImport({ name: 'React', path: 'react' })
|
|
1818
|
+
* ```
|
|
1819
|
+
*
|
|
1820
|
+
* @example Type-only import (TypeScript: `import type { FC } from 'react'`)
|
|
1821
|
+
* ```ts
|
|
1822
|
+
* createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
|
|
1823
|
+
* ```
|
|
1824
|
+
*
|
|
1825
|
+
* @example Namespace import (TypeScript: `import * as React from 'react'`)
|
|
1826
|
+
* ```ts
|
|
1827
|
+
* createImport({ name: 'React', path: 'react', isNameSpace: true })
|
|
1824
1828
|
* ```
|
|
1825
1829
|
*/
|
|
1826
|
-
type
|
|
1827
|
-
kind: '
|
|
1828
|
-
/**
|
|
1829
|
-
* Parameter name.
|
|
1830
|
-
*/
|
|
1831
|
-
name: string;
|
|
1830
|
+
type ImportNode = BaseNode & {
|
|
1831
|
+
kind: 'Import';
|
|
1832
1832
|
/**
|
|
1833
|
-
*
|
|
1833
|
+
* Import name(s) to be used.
|
|
1834
|
+
*
|
|
1835
|
+
* @example Named imports
|
|
1836
|
+
* `['useState']`
|
|
1837
|
+
*
|
|
1838
|
+
* @example Default import
|
|
1839
|
+
* `'React'`
|
|
1834
1840
|
*/
|
|
1835
|
-
|
|
1841
|
+
name: ImportName;
|
|
1836
1842
|
/**
|
|
1837
|
-
*
|
|
1843
|
+
* Path for the import.
|
|
1844
|
+
*
|
|
1845
|
+
* @example
|
|
1846
|
+
* `'@kubb/core'`
|
|
1838
1847
|
*/
|
|
1839
|
-
|
|
1848
|
+
path: string;
|
|
1840
1849
|
/**
|
|
1841
|
-
*
|
|
1850
|
+
* Add a type-only import prefix.
|
|
1851
|
+
* - `true` generates `import type { Type } from './path'`
|
|
1852
|
+
* - `false` generates `import { Type } from './path'`
|
|
1842
1853
|
*/
|
|
1843
|
-
|
|
1854
|
+
isTypeOnly?: boolean | null;
|
|
1844
1855
|
/**
|
|
1845
|
-
*
|
|
1846
|
-
*
|
|
1856
|
+
* Import the entire module as a namespace.
|
|
1857
|
+
* - `true` generates `import * as Name from './path'`
|
|
1858
|
+
* - `false` generates a standard import
|
|
1847
1859
|
*/
|
|
1848
|
-
|
|
1860
|
+
isNameSpace?: boolean | null;
|
|
1849
1861
|
/**
|
|
1850
|
-
*
|
|
1851
|
-
* leaving consumers to apply the default for the style.
|
|
1862
|
+
* When set, the import path is resolved relative to this root.
|
|
1852
1863
|
*/
|
|
1853
|
-
|
|
1864
|
+
root?: string | null;
|
|
1854
1865
|
};
|
|
1855
|
-
type UserParameterNode = Pick<ParameterNode, 'name' | 'in' | 'schema'> & Partial<Omit<ParameterNode, 'kind' | 'name' | 'in' | 'schema'>>;
|
|
1856
|
-
/**
|
|
1857
|
-
* Definition for the {@link ParameterNode}. `required` defaults to `false`, and the schema's
|
|
1858
|
-
* `optional`/`nullish` flags are derived from it through {@link optionality}.
|
|
1859
|
-
*/
|
|
1860
|
-
declare const parameterDef: NodeDef<ParameterNode, UserParameterNode>;
|
|
1861
1866
|
/**
|
|
1862
|
-
*
|
|
1867
|
+
* Represents a language-agnostic export/public API declaration.
|
|
1863
1868
|
*
|
|
1864
|
-
* @example
|
|
1869
|
+
* @example Named export (TypeScript: `export { Pets } from './Pets'`)
|
|
1865
1870
|
* ```ts
|
|
1866
|
-
*
|
|
1867
|
-
* name: 'petId',
|
|
1868
|
-
* in: 'path',
|
|
1869
|
-
* required: true,
|
|
1870
|
-
* schema: createSchema({ type: 'string' }),
|
|
1871
|
-
* })
|
|
1871
|
+
* createExport({ name: ['Pets'], path: './Pets' })
|
|
1872
1872
|
* ```
|
|
1873
|
-
*/
|
|
1874
|
-
declare const createParameter: (input: UserParameterNode) => ParameterNode;
|
|
1875
|
-
//#endregion
|
|
1876
|
-
//#region src/nodes/requestBody.d.ts
|
|
1877
|
-
/**
|
|
1878
|
-
* AST node representing an operation request body.
|
|
1879
1873
|
*
|
|
1880
|
-
*
|
|
1881
|
-
*
|
|
1874
|
+
* @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
|
|
1875
|
+
* ```ts
|
|
1876
|
+
* createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })
|
|
1877
|
+
* ```
|
|
1882
1878
|
*
|
|
1883
|
-
* @example
|
|
1879
|
+
* @example Wildcard export (TypeScript: `export * from './utils'`)
|
|
1884
1880
|
* ```ts
|
|
1885
|
-
*
|
|
1886
|
-
*
|
|
1887
|
-
*
|
|
1888
|
-
*
|
|
1889
|
-
*
|
|
1881
|
+
* createExport({ path: './utils' })
|
|
1882
|
+
* ```
|
|
1883
|
+
*
|
|
1884
|
+
* @example Namespace alias (TypeScript: `export * as utils from './utils'`)
|
|
1885
|
+
* ```ts
|
|
1886
|
+
* createExport({ name: 'utils', path: './utils', asAlias: true })
|
|
1890
1887
|
* ```
|
|
1891
1888
|
*/
|
|
1892
|
-
type
|
|
1893
|
-
kind: '
|
|
1889
|
+
type ExportNode = BaseNode & {
|
|
1890
|
+
kind: 'Export';
|
|
1894
1891
|
/**
|
|
1895
|
-
*
|
|
1892
|
+
* Export name(s) to be used. When omitted, generates a wildcard export.
|
|
1893
|
+
*
|
|
1894
|
+
* @example Named exports
|
|
1895
|
+
* `['useState']`
|
|
1896
|
+
*
|
|
1897
|
+
* @example Single export
|
|
1898
|
+
* `'React'`
|
|
1896
1899
|
*/
|
|
1897
|
-
|
|
1900
|
+
name?: string | Array<string> | null;
|
|
1898
1901
|
/**
|
|
1899
|
-
*
|
|
1900
|
-
*
|
|
1902
|
+
* Path for the export.
|
|
1903
|
+
*
|
|
1904
|
+
* @example
|
|
1905
|
+
* `'@kubb/core'`
|
|
1901
1906
|
*/
|
|
1902
|
-
|
|
1907
|
+
path: string;
|
|
1903
1908
|
/**
|
|
1904
|
-
*
|
|
1905
|
-
*
|
|
1906
|
-
*
|
|
1907
|
-
* that content type. Otherwise it contains one entry per content type declared in the spec,
|
|
1908
|
-
* so plugins can generate code for every variant (for example, separate hooks for
|
|
1909
|
-
* `application/json` and `multipart/form-data`).
|
|
1909
|
+
* Add a type-only export prefix.
|
|
1910
|
+
* - `true` generates `export type { Type } from './path'`
|
|
1911
|
+
* - `false` generates `export { Type } from './path'`
|
|
1910
1912
|
*/
|
|
1911
|
-
|
|
1913
|
+
isTypeOnly?: boolean | null;
|
|
1914
|
+
/**
|
|
1915
|
+
* Export as an aliased namespace.
|
|
1916
|
+
* - `true` generates `export * as aliasName from './path'`
|
|
1917
|
+
* - `false` generates a standard export
|
|
1918
|
+
*/
|
|
1919
|
+
asAlias?: boolean | null;
|
|
1912
1920
|
};
|
|
1913
1921
|
/**
|
|
1914
|
-
*
|
|
1915
|
-
* {@link createContent}, mirroring how `parameters` and `responses` take prebuilt nodes.
|
|
1916
|
-
*/
|
|
1917
|
-
declare const requestBodyDef: NodeDef<RequestBodyNode, Omit<RequestBodyNode, "kind">>;
|
|
1918
|
-
/**
|
|
1919
|
-
* Creates a `RequestBodyNode`.
|
|
1920
|
-
*/
|
|
1921
|
-
declare const createRequestBody: (input: Omit<RequestBodyNode, "kind">) => RequestBodyNode;
|
|
1922
|
-
//#endregion
|
|
1923
|
-
//#region src/nodes/response.d.ts
|
|
1924
|
-
/**
|
|
1925
|
-
* All supported HTTP status code literals as strings, as used in API specs
|
|
1926
|
-
* (for example, `"200"` and `"404"`).
|
|
1927
|
-
*/
|
|
1928
|
-
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';
|
|
1929
|
-
/**
|
|
1930
|
-
* Response status code literal used by operations.
|
|
1931
|
-
*
|
|
1932
|
-
* Includes specific HTTP status code strings and `"default"` for catch-all responses.
|
|
1922
|
+
* Represents a fragment of source code within a file.
|
|
1933
1923
|
*
|
|
1934
|
-
* @example
|
|
1924
|
+
* @example Named exportable source
|
|
1935
1925
|
* ```ts
|
|
1936
|
-
*
|
|
1937
|
-
* const fallback: StatusCode = 'default'
|
|
1926
|
+
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })
|
|
1938
1927
|
* ```
|
|
1939
|
-
*/
|
|
1940
|
-
type StatusCode = HttpStatusCode | 'default';
|
|
1941
|
-
/**
|
|
1942
|
-
* AST node representing one operation response variant.
|
|
1943
|
-
*
|
|
1944
|
-
* Mirrors {@link OperationNode.requestBody}: the response body schemas live exclusively inside
|
|
1945
|
-
* the `content` array (one entry per content type), so the same schema is never duplicated at the
|
|
1946
|
-
* node root and inside `content`.
|
|
1947
1928
|
*
|
|
1948
|
-
* @example
|
|
1929
|
+
* @example Inline unnamed code block
|
|
1949
1930
|
* ```ts
|
|
1950
|
-
*
|
|
1951
|
-
* kind: 'Response',
|
|
1952
|
-
* statusCode: '200',
|
|
1953
|
-
* content: [{ kind: 'Content', contentType: 'application/json', schema: createSchema({ type: 'string' }) }],
|
|
1954
|
-
* }
|
|
1931
|
+
* createSource({ nodes: [createText('const x = 1')] })
|
|
1955
1932
|
* ```
|
|
1956
1933
|
*/
|
|
1957
|
-
type
|
|
1934
|
+
type SourceNode = BaseNode & {
|
|
1935
|
+
kind: 'Source';
|
|
1958
1936
|
/**
|
|
1959
|
-
*
|
|
1937
|
+
* Optional name identifying this source (used for deduplication and barrel generation).
|
|
1960
1938
|
*/
|
|
1961
|
-
|
|
1939
|
+
name?: string | null;
|
|
1962
1940
|
/**
|
|
1963
|
-
*
|
|
1941
|
+
* Mark this source as a type-only export.
|
|
1964
1942
|
*/
|
|
1965
|
-
|
|
1943
|
+
isTypeOnly?: boolean | null;
|
|
1966
1944
|
/**
|
|
1967
|
-
*
|
|
1945
|
+
* Include the `export` keyword in the generated source.
|
|
1968
1946
|
*/
|
|
1969
|
-
|
|
1947
|
+
isExportable?: boolean | null;
|
|
1970
1948
|
/**
|
|
1971
|
-
*
|
|
1972
|
-
*
|
|
1973
|
-
* When the adapter `contentType` option is set, this array contains exactly one entry for that
|
|
1974
|
-
* content type. Otherwise it contains one entry per content type declared in the spec, so that
|
|
1975
|
-
* plugins can generate a union of response types (e.g. `application/json` and `application/xml`).
|
|
1976
|
-
* Body-less responses keep a single entry whose `schema` is the empty/`void` placeholder.
|
|
1977
|
-
*
|
|
1978
|
-
* @example
|
|
1979
|
-
* ```ts
|
|
1980
|
-
* // spec response declares both application/json and application/xml
|
|
1981
|
-
* response.content[0].contentType // 'application/json'
|
|
1982
|
-
* response.content[1].contentType // 'application/xml'
|
|
1983
|
-
* ```
|
|
1949
|
+
* Include this source in barrel/index file generation.
|
|
1984
1950
|
*/
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
};
|
|
1993
|
-
/**
|
|
1994
|
-
* Definition for the {@link ResponseNode}. A single legacy `schema` (with optional
|
|
1995
|
-
* `mediaType`/`keysToOmit`) is normalized into one `content` entry.
|
|
1996
|
-
*/
|
|
1997
|
-
declare const responseDef: NodeDef<ResponseNode, ResponseInput>;
|
|
1951
|
+
isIndexable?: boolean | null;
|
|
1952
|
+
/**
|
|
1953
|
+
* Child nodes that make up this source fragment, in DOM order.
|
|
1954
|
+
* Use a {@link TextNode} for raw string content.
|
|
1955
|
+
*/
|
|
1956
|
+
nodes?: Array<CodeNode>;
|
|
1957
|
+
};
|
|
1998
1958
|
/**
|
|
1999
|
-
*
|
|
1959
|
+
* Represents a fully resolved file in the AST.
|
|
1960
|
+
*
|
|
1961
|
+
* Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input
|
|
1962
|
+
* and deduplicates `imports`, `exports`, and `sources`.
|
|
2000
1963
|
*
|
|
2001
1964
|
* @example
|
|
2002
1965
|
* ```ts
|
|
2003
|
-
* const
|
|
2004
|
-
*
|
|
2005
|
-
*
|
|
1966
|
+
* const file = createFile({
|
|
1967
|
+
* baseName: 'petStore.ts',
|
|
1968
|
+
* path: 'src/models/petStore.ts',
|
|
1969
|
+
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })],
|
|
1970
|
+
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
1971
|
+
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
2006
1972
|
* })
|
|
1973
|
+
* // file.id = SHA256 hash of the path
|
|
1974
|
+
* // file.name = 'petStore'
|
|
1975
|
+
* // file.extname = '.ts'
|
|
2007
1976
|
* ```
|
|
2008
1977
|
*/
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
//#region src/nodes/operation.d.ts
|
|
2012
|
-
/**
|
|
2013
|
-
* HTTP method an operation responds to.
|
|
2014
|
-
*/
|
|
2015
|
-
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'TRACE';
|
|
2016
|
-
/**
|
|
2017
|
-
* Transport an operation belongs to.
|
|
2018
|
-
*/
|
|
2019
|
-
type OperationProtocol = 'http';
|
|
2020
|
-
/**
|
|
2021
|
-
* Fields shared by every operation, regardless of transport.
|
|
2022
|
-
*/
|
|
2023
|
-
type OperationNodeBase = BaseNode & {
|
|
1978
|
+
type FileNode<TMeta extends object = object> = BaseNode & {
|
|
1979
|
+
kind: 'File';
|
|
2024
1980
|
/**
|
|
2025
|
-
*
|
|
1981
|
+
* Unique identifier derived from a SHA256 hash of the file path. `createFile`
|
|
1982
|
+
* computes it, so callers do not need to provide it.
|
|
2026
1983
|
*/
|
|
2027
|
-
|
|
1984
|
+
id: string;
|
|
2028
1985
|
/**
|
|
2029
|
-
*
|
|
1986
|
+
* File name without extension, derived from `baseName`.
|
|
1987
|
+
*
|
|
1988
|
+
* @see https://nodejs.org/api/path.html#pathformatpathobject
|
|
2030
1989
|
*/
|
|
2031
|
-
|
|
1990
|
+
name: string;
|
|
2032
1991
|
/**
|
|
2033
|
-
*
|
|
1992
|
+
* File base name, including extension, shaped like `${name}${extname}`.
|
|
1993
|
+
*
|
|
1994
|
+
* @see https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
2034
1995
|
*/
|
|
2035
|
-
|
|
1996
|
+
baseName: `${string}.${string}`;
|
|
2036
1997
|
/**
|
|
2037
|
-
*
|
|
1998
|
+
* Full qualified path to the file.
|
|
2038
1999
|
*/
|
|
2039
|
-
|
|
2000
|
+
path: string;
|
|
2040
2001
|
/**
|
|
2041
|
-
*
|
|
2002
|
+
* File extension extracted from `baseName`.
|
|
2042
2003
|
*/
|
|
2043
|
-
|
|
2004
|
+
extname: Extname;
|
|
2044
2005
|
/**
|
|
2045
|
-
*
|
|
2006
|
+
* Deduplicated list of source code fragments.
|
|
2046
2007
|
*/
|
|
2047
|
-
|
|
2008
|
+
sources: Array<SourceNode>;
|
|
2048
2009
|
/**
|
|
2049
|
-
*
|
|
2010
|
+
* Deduplicated list of import declarations.
|
|
2050
2011
|
*/
|
|
2051
|
-
|
|
2012
|
+
imports: Array<ImportNode>;
|
|
2052
2013
|
/**
|
|
2053
|
-
*
|
|
2014
|
+
* Deduplicated list of export declarations.
|
|
2054
2015
|
*/
|
|
2055
|
-
|
|
2016
|
+
exports: Array<ExportNode>;
|
|
2056
2017
|
/**
|
|
2057
|
-
*
|
|
2018
|
+
* Optional metadata attached to this file, read by plugins during barrel generation.
|
|
2058
2019
|
*/
|
|
2059
|
-
|
|
2060
|
-
};
|
|
2061
|
-
/**
|
|
2062
|
-
* Operation served over HTTP. `method` and `path` are guaranteed.
|
|
2063
|
-
*
|
|
2064
|
-
* @example
|
|
2065
|
-
* ```ts
|
|
2066
|
-
* const operation: HttpOperationNode = {
|
|
2067
|
-
* kind: 'Operation',
|
|
2068
|
-
* operationId: 'listPets',
|
|
2069
|
-
* protocol: 'http',
|
|
2070
|
-
* method: 'GET',
|
|
2071
|
-
* path: '/pets',
|
|
2072
|
-
* tags: [],
|
|
2073
|
-
* parameters: [],
|
|
2074
|
-
* responses: [],
|
|
2075
|
-
* }
|
|
2076
|
-
* ```
|
|
2077
|
-
*/
|
|
2078
|
-
type HttpOperationNode = OperationNodeBase & {
|
|
2020
|
+
meta?: TMeta;
|
|
2079
2021
|
/**
|
|
2080
|
-
*
|
|
2022
|
+
* Optional banner prepended to the generated file content.
|
|
2023
|
+
* Accepts `null` so `resolver.default.banner()` results can be passed directly.
|
|
2081
2024
|
*/
|
|
2082
|
-
|
|
2025
|
+
banner?: string | null;
|
|
2083
2026
|
/**
|
|
2084
|
-
*
|
|
2027
|
+
* Optional footer appended to the generated file content.
|
|
2028
|
+
* Accepts `null` so `resolver.default.footer()` results can be passed directly.
|
|
2085
2029
|
*/
|
|
2086
|
-
|
|
2030
|
+
footer?: string | null;
|
|
2087
2031
|
/**
|
|
2088
|
-
*
|
|
2032
|
+
* Absolute on-disk path to copy into the output, through the parser's `copy` hook when it has one.
|
|
2033
|
+
*
|
|
2034
|
+
* Use to emit a real source file shipped inside a package (a template) into the generated
|
|
2035
|
+
* folder. When set, `copy` provides the file content and any `sources` nodes are ignored for
|
|
2036
|
+
* output; `sources` may still carry `name`/`isExportable`/`isIndexable` so barrel generation
|
|
2037
|
+
* treats the file the same as a rendered one.
|
|
2089
2038
|
*/
|
|
2090
|
-
|
|
2039
|
+
copy?: string | null;
|
|
2091
2040
|
};
|
|
2092
2041
|
/**
|
|
2093
|
-
*
|
|
2042
|
+
* Definition for the {@link ImportNode}.
|
|
2094
2043
|
*/
|
|
2095
|
-
|
|
2096
|
-
/**
|
|
2097
|
-
* Transport the operation belongs to.
|
|
2098
|
-
*/
|
|
2099
|
-
protocol?: Exclude<OperationProtocol, 'http'>;
|
|
2100
|
-
method?: never;
|
|
2101
|
-
path?: never;
|
|
2102
|
-
};
|
|
2044
|
+
declare const importDef: NodeDef<ImportNode, Omit<ImportNode, "kind">>;
|
|
2103
2045
|
/**
|
|
2104
|
-
*
|
|
2046
|
+
* Definition for the {@link ExportNode}.
|
|
2047
|
+
*/
|
|
2048
|
+
declare const exportDef: NodeDef<ExportNode, Omit<ExportNode, "kind">>;
|
|
2049
|
+
/**
|
|
2050
|
+
* Definition for the {@link SourceNode}.
|
|
2051
|
+
*/
|
|
2052
|
+
declare const sourceDef: NodeDef<SourceNode, Omit<SourceNode, "kind">>;
|
|
2053
|
+
/**
|
|
2054
|
+
* Definition for the {@link FileNode}. The fully resolved builder lives in
|
|
2055
|
+
* `createFile`, so this definition only supplies the guard.
|
|
2056
|
+
*/
|
|
2057
|
+
declare const fileDef: NodeDef<FileNode<object>, Omit<FileNode<object>, "kind">>;
|
|
2058
|
+
/**
|
|
2059
|
+
* Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
|
|
2105
2060
|
*
|
|
2106
|
-
*
|
|
2107
|
-
*
|
|
2108
|
-
*
|
|
2061
|
+
* @example Named import
|
|
2062
|
+
* ```ts
|
|
2063
|
+
* createImport({ name: ['useState'], path: 'react' })
|
|
2064
|
+
* // import { useState } from 'react'
|
|
2065
|
+
* ```
|
|
2109
2066
|
*/
|
|
2110
|
-
|
|
2111
|
-
type OperationInput = {
|
|
2112
|
-
operationId: string;
|
|
2113
|
-
method?: HttpOperationNode['method'];
|
|
2114
|
-
path?: HttpOperationNode['path'];
|
|
2115
|
-
requestBody?: Omit<RequestBodyNode, 'kind'>;
|
|
2116
|
-
[key: string]: unknown;
|
|
2117
|
-
};
|
|
2067
|
+
declare const createImport: (input: Omit<ImportNode, "kind">) => ImportNode;
|
|
2118
2068
|
/**
|
|
2119
|
-
*
|
|
2120
|
-
*
|
|
2121
|
-
*
|
|
2069
|
+
* Creates an `ExportNode` representing a language-agnostic export/public API declaration.
|
|
2070
|
+
*
|
|
2071
|
+
* @example Named export
|
|
2072
|
+
* ```ts
|
|
2073
|
+
* createExport({ name: ['Pet'], path: './Pet' })
|
|
2074
|
+
* // export { Pet } from './Pet'
|
|
2075
|
+
* ```
|
|
2122
2076
|
*/
|
|
2123
|
-
declare const
|
|
2077
|
+
declare const createExport: (input: Omit<ExportNode, "kind">) => ExportNode;
|
|
2124
2078
|
/**
|
|
2125
|
-
* Creates
|
|
2079
|
+
* Creates a `SourceNode` representing a fragment of source code within a file.
|
|
2126
2080
|
*
|
|
2127
2081
|
* @example
|
|
2128
2082
|
* ```ts
|
|
2129
|
-
*
|
|
2130
|
-
* // tags, parameters, and responses are []
|
|
2083
|
+
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
|
|
2131
2084
|
* ```
|
|
2132
2085
|
*/
|
|
2133
|
-
declare
|
|
2134
|
-
|
|
2135
|
-
}
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2086
|
+
declare const createSource: (input: Omit<SourceNode, "kind">) => SourceNode;
|
|
2087
|
+
/**
|
|
2088
|
+
* Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed
|
|
2089
|
+
* and `imports`/`exports`/`sources` are deduplicated.
|
|
2090
|
+
*/
|
|
2091
|
+
type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> & Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>;
|
|
2092
|
+
/**
|
|
2093
|
+
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
2094
|
+
*
|
|
2095
|
+
* Computes:
|
|
2096
|
+
* - `id` SHA256 hash of the file path
|
|
2097
|
+
* - `name` `baseName` without extension
|
|
2098
|
+
* - `extname` extension extracted from `baseName`
|
|
2099
|
+
*
|
|
2100
|
+
* Deduplicates:
|
|
2101
|
+
* - `sources` via `combineSources`
|
|
2102
|
+
* - `exports` via `combineExports`
|
|
2103
|
+
* - `imports` via `combineImports` (also filters unused imports)
|
|
2104
|
+
*
|
|
2105
|
+
* @throws {Error} when `baseName` has no extension.
|
|
2106
|
+
*
|
|
2107
|
+
* @example
|
|
2108
|
+
* ```ts
|
|
2109
|
+
* const file = createFile({
|
|
2110
|
+
* baseName: 'petStore.ts',
|
|
2111
|
+
* path: 'src/models/petStore.ts',
|
|
2112
|
+
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
2113
|
+
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
2114
|
+
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
2115
|
+
* })
|
|
2116
|
+
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
2117
|
+
* // file.name = 'petStore'
|
|
2118
|
+
* // file.extname = '.ts'
|
|
2119
|
+
* ```
|
|
2120
|
+
*
|
|
2121
|
+
* @example Copy a real file into the output
|
|
2122
|
+
* ```ts
|
|
2123
|
+
* const file = createFile({
|
|
2124
|
+
* baseName: 'client.ts',
|
|
2125
|
+
* path: 'src/gen/client.ts',
|
|
2126
|
+
* copy: '/abs/path/to/templates/client.ts',
|
|
2127
|
+
* })
|
|
2128
|
+
* ```
|
|
2129
|
+
*/
|
|
2130
|
+
declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
|
|
2139
2131
|
//#endregion
|
|
2140
2132
|
//#region src/nodes/input.d.ts
|
|
2141
2133
|
/**
|
|
@@ -2392,25 +2384,29 @@ type Visitor = {
|
|
|
2392
2384
|
response?(node: ResponseNode, context: VisitorContext<ResponseNode>): undefined | null | ResponseNode;
|
|
2393
2385
|
};
|
|
2394
2386
|
/**
|
|
2395
|
-
* Visitor
|
|
2387
|
+
* The callbacks of {@link Visitor} with every return type replaced by `TResult`. `collect` uses it
|
|
2388
|
+
* so a visitor can yield values instead of replacement nodes.
|
|
2396
2389
|
*
|
|
2397
2390
|
* @example
|
|
2398
2391
|
* ```ts
|
|
2399
|
-
* const visitor:
|
|
2392
|
+
* const visitor: VisitorOf<string> = {
|
|
2400
2393
|
* operation(node) {
|
|
2401
2394
|
* return node.operationId
|
|
2402
2395
|
* },
|
|
2403
2396
|
* }
|
|
2404
2397
|
* ```
|
|
2405
2398
|
*/
|
|
2406
|
-
type
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2399
|
+
type VisitorOf<TResult> = { [K in keyof Visitor]?: (node: Parameters<NonNullable<Visitor[K]>>[0], context: Parameters<NonNullable<Visitor[K]>>[1]) => TResult | null | undefined; };
|
|
2400
|
+
type TraversalOptions = {
|
|
2401
|
+
/**
|
|
2402
|
+
* Traversal depth.
|
|
2403
|
+
* @default 'deep'
|
|
2404
|
+
*/
|
|
2405
|
+
depth?: VisitorDepth;
|
|
2406
|
+
/**
|
|
2407
|
+
* Internal parent override used during recursion.
|
|
2408
|
+
*/
|
|
2409
|
+
parent?: Node;
|
|
2414
2410
|
};
|
|
2415
2411
|
/**
|
|
2416
2412
|
* Options for `transform`.
|
|
@@ -2426,17 +2422,7 @@ type CollectVisitor<T> = {
|
|
|
2426
2422
|
* const options: TransformOptions = { depth: 'shallow', schema: (node) => node }
|
|
2427
2423
|
* ```
|
|
2428
2424
|
*/
|
|
2429
|
-
type TransformOptions = Visitor &
|
|
2430
|
-
/**
|
|
2431
|
-
* Traversal depth.
|
|
2432
|
-
* @default 'deep'
|
|
2433
|
-
*/
|
|
2434
|
-
depth?: VisitorDepth;
|
|
2435
|
-
/**
|
|
2436
|
-
* Internal parent override used during recursion.
|
|
2437
|
-
*/
|
|
2438
|
-
parent?: Node;
|
|
2439
|
-
};
|
|
2425
|
+
type TransformOptions = Visitor & TraversalOptions;
|
|
2440
2426
|
/**
|
|
2441
2427
|
* Options for `collect`.
|
|
2442
2428
|
*
|
|
@@ -2445,17 +2431,7 @@ type TransformOptions = Visitor & {
|
|
|
2445
2431
|
* const options: CollectOptions<string> = { depth: 'shallow', schema: () => undefined }
|
|
2446
2432
|
* ```
|
|
2447
2433
|
*/
|
|
2448
|
-
type CollectOptions<T> =
|
|
2449
|
-
/**
|
|
2450
|
-
* Traversal depth.
|
|
2451
|
-
* @default 'deep'
|
|
2452
|
-
*/
|
|
2453
|
-
depth?: VisitorDepth;
|
|
2454
|
-
/**
|
|
2455
|
-
* Internal parent override used during recursion.
|
|
2456
|
-
*/
|
|
2457
|
-
parent?: Node;
|
|
2458
|
-
};
|
|
2434
|
+
type CollectOptions<T> = VisitorOf<T> & TraversalOptions;
|
|
2459
2435
|
/**
|
|
2460
2436
|
* Synchronous depth-first transform. Each visitor callback can return a
|
|
2461
2437
|
* replacement node. Returning `undefined` keeps the original.
|
|
@@ -2480,14 +2456,7 @@ type CollectOptions<T> = CollectVisitor<T> & {
|
|
|
2480
2456
|
* })
|
|
2481
2457
|
* ```
|
|
2482
2458
|
*/
|
|
2483
|
-
declare function transform(node:
|
|
2484
|
-
declare function transform(node: OutputNode, options: TransformOptions): OutputNode;
|
|
2485
|
-
declare function transform(node: OperationNode, options: TransformOptions): OperationNode;
|
|
2486
|
-
declare function transform(node: SchemaNode, options: TransformOptions): SchemaNode;
|
|
2487
|
-
declare function transform(node: PropertyNode, options: TransformOptions): PropertyNode;
|
|
2488
|
-
declare function transform(node: ParameterNode, options: TransformOptions): ParameterNode;
|
|
2489
|
-
declare function transform(node: ResponseNode, options: TransformOptions): ResponseNode;
|
|
2490
|
-
declare function transform(node: Node, options: TransformOptions): Node;
|
|
2459
|
+
declare function transform<T extends Node>(node: T, options: TransformOptions): T;
|
|
2491
2460
|
/**
|
|
2492
2461
|
* Lazy depth-first collection pass. Yields every non-null value returned by
|
|
2493
2462
|
* the visitor callbacks. Use `collectSync` for the eager array form.
|
|
@@ -2735,13 +2704,13 @@ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) =
|
|
|
2735
2704
|
* Options to store on the printer.
|
|
2736
2705
|
*/
|
|
2737
2706
|
options: T['options'];
|
|
2738
|
-
nodes:
|
|
2707
|
+
nodes: PrinterPartial<T['output'], T['options']>;
|
|
2739
2708
|
/**
|
|
2740
2709
|
* User-supplied handler overrides. An override wins over the matching `nodes` handler,
|
|
2741
2710
|
* and can call `this.base(node)` to reuse the handler it replaced. Pass overrides here
|
|
2742
2711
|
* instead of spreading them into `nodes`, otherwise `this.base` cannot find the original.
|
|
2743
2712
|
*/
|
|
2744
|
-
overrides?:
|
|
2713
|
+
overrides?: PrinterPartial<T['output'], T['options']>;
|
|
2745
2714
|
/**
|
|
2746
2715
|
* Optional root-level print override. When provided, becomes the public `printer.print`.
|
|
2747
2716
|
* Use `this.transform(node)` inside this function to dispatch to the node-level handlers (`nodes`),
|
|
@@ -2792,5 +2761,5 @@ type PrinterBuilder<T extends PrinterFactoryOptions> = (options: T['options']) =
|
|
|
2792
2761
|
*/
|
|
2793
2762
|
declare function createPrinter<T extends PrinterFactoryOptions = PrinterFactoryOptions>(build: PrinterBuilder<T>): (options?: T['options']) => Printer<T>;
|
|
2794
2763
|
//#endregion
|
|
2795
|
-
export {
|
|
2796
|
-
//# sourceMappingURL=types-
|
|
2764
|
+
export { createJsx as $, InferSchemaNode as $t, createFile as A, EnumSchemaNode as At, ConstNode as B, SchemaType as Bt, inputDef as C, ParameterNode as Ct, SourceNode as D, ArraySchemaNode as Dt, ImportNode as E, parameterDef as Et, importDef as F, RefSchemaNode as Ft, TypeNode as G, createSchema as Gt, JSDocNode as H, TimeSchemaNode as Ht, sourceDef as I, ScalarSchemaNode as It, constDef as J, createProperty as Jt, arrowFunctionDef as K, schemaDef as Kt, ArrowFunctionNode as L, ScalarSchemaType as Lt, createSource as M, NumberSchemaNode as Mt, exportDef as N, ObjectSchemaNode as Nt, UserFileNode as O, DateSchemaNode as Ot, fileDef as P, PrimitiveSchemaType as Pt, createFunction as Q, DateTypeOptions as Qt, BreakNode as R, SchemaNode as Rt, createInput as S, ParameterLocation as St, FileNode as T, createParameter as Tt, JsxNode as U, UnionSchemaNode as Ut, FunctionNode as V, StringSchemaNode as Vt, TextNode as W, UrlSchemaNode as Wt, createBreak as X, DateOnlyTypeValue as Xt, createArrowFunction as Y, propertyDef as Yt, createConst as Z, DateTimeTypeValue as Zt, OutputNode as _, createRequestBody as _t, Enforce as a, NodeKind as an, typeDef as at, InputMeta as b, contentDef as bt, composeMacros as c, HttpOperationNode as ct, Visitor as d, operationDef as dt, ParserOptions as en, createText as et, VisitorContext as f, ResponseNode as ft, Node as g, RequestBodyNode as gt, transform as h, responseDef as ht, createPrinter as i, BaseNode as in, textDef as it, createImport as j, IntersectionSchemaNode as jt, createExport as k, DatetimeSchemaNode as kt, defineMacro as l, OperationNode as lt, collectSync as m, createResponse as mt, PrinterFactoryOptions as n, NodeDef as nn, functionDef as nt, Macro as o, schemaTypes as on, GenericOperationNode as ot, collect as p, StatusCode as pt, breakDef as q, PropertyNode as qt, PrinterPartial as r, defineNode as rn, jsxDef as rt, applyMacros as s, HttpMethod as st, Printer as t, DistributiveOmit as tn, createType as tt, ParentOf as u, createOperation as ut, createOutput as v, requestBodyDef as vt, ExportNode as w, ParameterStyle as wt, InputNode as x, createContent as xt, outputDef as y, ContentNode as yt, CodeNode as z, SchemaNodeByType as zt };
|
|
2765
|
+
//# sourceMappingURL=types-NNGUervC.d.ts.map
|