@kubb/ast 5.0.0-alpha.31 → 5.0.0-alpha.32
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 +1556 -1067
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +42 -3
- package/dist/index.js +1519 -1067
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/{visitor-z-5U8NoF.d.ts → visitor-DysNCWvh.d.ts} +794 -61
- package/package.json +1 -1
- package/src/constants.ts +7 -1
- package/src/factory.ts +296 -24
- package/src/guards.ts +17 -4
- package/src/index.ts +23 -5
- package/src/mocks.ts +6 -6
- package/src/nodes/base.ts +11 -2
- package/src/nodes/code.ts +237 -0
- package/src/nodes/file.ts +235 -0
- package/src/nodes/function.ts +35 -17
- package/src/nodes/index.ts +32 -7
- package/src/nodes/output.ts +26 -0
- package/src/nodes/root.ts +9 -8
- package/src/refs.ts +5 -5
- package/src/types.ts +14 -2
- package/src/utils.ts +177 -19
- package/src/visitor.ts +52 -25
|
@@ -5,6 +5,23 @@ 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 input: "Input";
|
|
10
|
+
readonly output: "Output";
|
|
11
|
+
readonly operation: "Operation";
|
|
12
|
+
readonly schema: "Schema";
|
|
13
|
+
readonly property: "Property";
|
|
14
|
+
readonly parameter: "Parameter";
|
|
15
|
+
readonly response: "Response";
|
|
16
|
+
readonly functionParameter: "FunctionParameter";
|
|
17
|
+
readonly parameterGroup: "ParameterGroup";
|
|
18
|
+
readonly functionParameters: "FunctionParameters";
|
|
19
|
+
readonly type: "Type";
|
|
20
|
+
readonly file: "File";
|
|
21
|
+
readonly import: "Import";
|
|
22
|
+
readonly export: "Export";
|
|
23
|
+
readonly source: "Source";
|
|
24
|
+
};
|
|
8
25
|
/**
|
|
9
26
|
* Canonical schema type strings used by AST schema nodes.
|
|
10
27
|
*
|
|
@@ -168,13 +185,13 @@ declare const mediaTypes: {
|
|
|
168
185
|
* const kind: NodeKind = 'Schema'
|
|
169
186
|
* ```
|
|
170
187
|
*/
|
|
171
|
-
type NodeKind = '
|
|
188
|
+
type NodeKind = 'Input' | 'Output' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'FunctionParameter' | 'ParameterGroup' | 'FunctionParameters' | 'Type' | 'ParamsType' | 'File' | 'Import' | 'Export' | 'Source' | 'Const' | 'Function' | 'ArrowFunction';
|
|
172
189
|
/**
|
|
173
190
|
* Base shape shared by all AST nodes.
|
|
174
191
|
*
|
|
175
192
|
* @example
|
|
176
193
|
* ```ts
|
|
177
|
-
* const base: BaseNode = { kind: '
|
|
194
|
+
* const base: BaseNode = { kind: 'Input' }
|
|
178
195
|
* ```
|
|
179
196
|
*/
|
|
180
197
|
type BaseNode = {
|
|
@@ -184,21 +201,502 @@ type BaseNode = {
|
|
|
184
201
|
kind: NodeKind;
|
|
185
202
|
};
|
|
186
203
|
//#endregion
|
|
204
|
+
//#region src/nodes/code.d.ts
|
|
205
|
+
/**
|
|
206
|
+
* JSDoc documentation metadata attached to code declarations.
|
|
207
|
+
*/
|
|
208
|
+
type JSDocNode = {
|
|
209
|
+
/**
|
|
210
|
+
* JSDoc comment lines. `undefined` entries are filtered out during rendering.
|
|
211
|
+
* @example ['@description A pet resource', '@deprecated']
|
|
212
|
+
*/
|
|
213
|
+
comments?: Array<string | undefined>;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* AST node representing a TypeScript `const` declaration.
|
|
217
|
+
*
|
|
218
|
+
* Mirrors the props of the `Const` component from `@kubb/react-fabric`.
|
|
219
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* createConst({ name: 'pet', export: true, asConst: true })
|
|
224
|
+
* // export const pet = ... as const
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
type ConstNode = BaseNode & {
|
|
228
|
+
/**
|
|
229
|
+
* Node kind.
|
|
230
|
+
*/
|
|
231
|
+
kind: 'Const';
|
|
232
|
+
/**
|
|
233
|
+
* Name of the constant declaration.
|
|
234
|
+
*/
|
|
235
|
+
name: string;
|
|
236
|
+
/**
|
|
237
|
+
* Whether the declaration should be exported.
|
|
238
|
+
* @default false
|
|
239
|
+
*/
|
|
240
|
+
export?: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Optional explicit type annotation.
|
|
243
|
+
* @example 'Pet'
|
|
244
|
+
*/
|
|
245
|
+
type?: string;
|
|
246
|
+
/**
|
|
247
|
+
* JSDoc documentation metadata.
|
|
248
|
+
*/
|
|
249
|
+
JSDoc?: JSDocNode;
|
|
250
|
+
/**
|
|
251
|
+
* Whether to append `as const` to the declaration.
|
|
252
|
+
* @default false
|
|
253
|
+
*/
|
|
254
|
+
asConst?: boolean;
|
|
255
|
+
/**
|
|
256
|
+
* Child nodes representing the value of the constant (children of the `Const` component).
|
|
257
|
+
* Each entry is either a structured {@link CodeNode} or a raw string expression.
|
|
258
|
+
*/
|
|
259
|
+
nodes?: Array<CodeNode | string>;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* AST node representing a TypeScript `type` alias declaration.
|
|
263
|
+
*
|
|
264
|
+
* Mirrors the props of the `Type` component from `@kubb/react-fabric`.
|
|
265
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* createType({ name: 'Pet', export: true })
|
|
270
|
+
* // export type Pet = ...
|
|
271
|
+
* ```
|
|
272
|
+
*/
|
|
273
|
+
type TypeNode = BaseNode & {
|
|
274
|
+
/**
|
|
275
|
+
* Node kind.
|
|
276
|
+
*/
|
|
277
|
+
kind: 'Type';
|
|
278
|
+
/**
|
|
279
|
+
* Name of the type alias.
|
|
280
|
+
*/
|
|
281
|
+
name: string;
|
|
282
|
+
/**
|
|
283
|
+
* Whether the declaration should be exported.
|
|
284
|
+
* @default false
|
|
285
|
+
*/
|
|
286
|
+
export?: boolean;
|
|
287
|
+
/**
|
|
288
|
+
* JSDoc documentation metadata.
|
|
289
|
+
*/
|
|
290
|
+
JSDoc?: JSDocNode;
|
|
291
|
+
/**
|
|
292
|
+
* Child nodes representing the type body (children of the `Type` component).
|
|
293
|
+
* Each entry is either a structured {@link CodeNode} or a raw string expression.
|
|
294
|
+
*/
|
|
295
|
+
nodes?: Array<CodeNode | string>;
|
|
296
|
+
};
|
|
297
|
+
/**
|
|
298
|
+
* Convenience alias for {@link TypeNode}.
|
|
299
|
+
* @deprecated Use `TypeNode` directly.
|
|
300
|
+
*/
|
|
301
|
+
type TypeDeclarationNode = TypeNode;
|
|
302
|
+
/**
|
|
303
|
+
* AST node representing a TypeScript `function` declaration.
|
|
304
|
+
*
|
|
305
|
+
* Mirrors the props of the `Function` component from `@kubb/react-fabric`.
|
|
306
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* createFunctionDeclaration({ name: 'getPet', export: true, async: true, returnType: 'Pet' })
|
|
311
|
+
* // export async function getPet(): Promise<Pet> { ... }
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
type FunctionNode = BaseNode & {
|
|
315
|
+
/**
|
|
316
|
+
* Node kind.
|
|
317
|
+
*/
|
|
318
|
+
kind: 'Function';
|
|
319
|
+
/**
|
|
320
|
+
* Name of the function.
|
|
321
|
+
*/
|
|
322
|
+
name: string;
|
|
323
|
+
/**
|
|
324
|
+
* Whether the function is a default export.
|
|
325
|
+
* @default false
|
|
326
|
+
*/
|
|
327
|
+
default?: boolean;
|
|
328
|
+
/**
|
|
329
|
+
* Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).
|
|
330
|
+
*/
|
|
331
|
+
params?: string;
|
|
332
|
+
/**
|
|
333
|
+
* Whether the function should be exported.
|
|
334
|
+
* @default false
|
|
335
|
+
*/
|
|
336
|
+
export?: boolean;
|
|
337
|
+
/**
|
|
338
|
+
* Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
339
|
+
* @default false
|
|
340
|
+
*/
|
|
341
|
+
async?: boolean;
|
|
342
|
+
/**
|
|
343
|
+
* TypeScript generic type parameters.
|
|
344
|
+
* @example ['T', 'U extends string']
|
|
345
|
+
*/
|
|
346
|
+
generics?: string | string[];
|
|
347
|
+
/**
|
|
348
|
+
* Return type annotation.
|
|
349
|
+
* @example 'Pet'
|
|
350
|
+
*/
|
|
351
|
+
returnType?: string;
|
|
352
|
+
/**
|
|
353
|
+
* JSDoc documentation metadata.
|
|
354
|
+
*/
|
|
355
|
+
JSDoc?: JSDocNode;
|
|
356
|
+
/**
|
|
357
|
+
* Child nodes representing the function body (children of the `Function` component).
|
|
358
|
+
* Each entry is either a structured {@link CodeNode} or a raw string statement.
|
|
359
|
+
*/
|
|
360
|
+
nodes?: Array<CodeNode | string>;
|
|
361
|
+
};
|
|
362
|
+
/**
|
|
363
|
+
* AST node representing a TypeScript arrow function (`const name = () => { ... }`).
|
|
364
|
+
*
|
|
365
|
+
* Mirrors the props of the `Function.Arrow` component from `@kubb/react-fabric`.
|
|
366
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* createArrowFunctionDeclaration({ name: 'getPet', export: true, singleLine: true })
|
|
371
|
+
* // export const getPet = () => ...
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
type ArrowFunctionNode = BaseNode & {
|
|
375
|
+
/**
|
|
376
|
+
* Node kind.
|
|
377
|
+
*/
|
|
378
|
+
kind: 'ArrowFunction';
|
|
379
|
+
/**
|
|
380
|
+
* Name of the arrow function (used as the `const` variable name).
|
|
381
|
+
*/
|
|
382
|
+
name: string;
|
|
383
|
+
/**
|
|
384
|
+
* Whether the function is a default export.
|
|
385
|
+
* @default false
|
|
386
|
+
*/
|
|
387
|
+
default?: boolean;
|
|
388
|
+
/**
|
|
389
|
+
* Function parameter list rendered as a string (e.g. from `FunctionParams.toConstructor()`).
|
|
390
|
+
*/
|
|
391
|
+
params?: string;
|
|
392
|
+
/**
|
|
393
|
+
* Whether the arrow function should be exported.
|
|
394
|
+
* @default false
|
|
395
|
+
*/
|
|
396
|
+
export?: boolean;
|
|
397
|
+
/**
|
|
398
|
+
* Whether the arrow function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
399
|
+
* @default false
|
|
400
|
+
*/
|
|
401
|
+
async?: boolean;
|
|
402
|
+
/**
|
|
403
|
+
* TypeScript generic type parameters.
|
|
404
|
+
* @example ['T', 'U extends string']
|
|
405
|
+
*/
|
|
406
|
+
generics?: string | string[];
|
|
407
|
+
/**
|
|
408
|
+
* Return type annotation.
|
|
409
|
+
* @example 'Pet'
|
|
410
|
+
*/
|
|
411
|
+
returnType?: string;
|
|
412
|
+
/**
|
|
413
|
+
* JSDoc documentation metadata.
|
|
414
|
+
*/
|
|
415
|
+
JSDoc?: JSDocNode;
|
|
416
|
+
/**
|
|
417
|
+
* Render the arrow function body as a single-line expression.
|
|
418
|
+
* @default false
|
|
419
|
+
*/
|
|
420
|
+
singleLine?: boolean;
|
|
421
|
+
/**
|
|
422
|
+
* Child nodes representing the function body (children of the `Function.Arrow` component).
|
|
423
|
+
* Each entry is either a structured {@link CodeNode} or a raw string statement.
|
|
424
|
+
*/
|
|
425
|
+
nodes?: Array<CodeNode | string>;
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* Union of all code-generation AST nodes.
|
|
429
|
+
*
|
|
430
|
+
* These nodes mirror the JSX components from `@kubb/react-fabric` and are used as
|
|
431
|
+
* structured children in {@link SourceNode.nodes}.
|
|
432
|
+
*/
|
|
433
|
+
type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode;
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/nodes/file.d.ts
|
|
436
|
+
/**
|
|
437
|
+
* Supported file extensions.
|
|
438
|
+
*/
|
|
439
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
440
|
+
type ImportName = string | Array<string | {
|
|
441
|
+
propertyName: string;
|
|
442
|
+
name?: string;
|
|
443
|
+
}>;
|
|
444
|
+
/**
|
|
445
|
+
* Represents a language-agnostic import/dependency declaration.
|
|
446
|
+
*
|
|
447
|
+
* @example Named import (TypeScript: `import { useState } from 'react'`)
|
|
448
|
+
* ```ts
|
|
449
|
+
* createImport({ name: ['useState'], path: 'react' })
|
|
450
|
+
* ```
|
|
451
|
+
*
|
|
452
|
+
* @example Default import (TypeScript: `import React from 'react'`)
|
|
453
|
+
* ```ts
|
|
454
|
+
* createImport({ name: 'React', path: 'react' })
|
|
455
|
+
* ```
|
|
456
|
+
*
|
|
457
|
+
* @example Type-only import (TypeScript: `import type { FC } from 'react'`)
|
|
458
|
+
* ```ts
|
|
459
|
+
* createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
|
|
460
|
+
* ```
|
|
461
|
+
*
|
|
462
|
+
* @example Namespace import (TypeScript: `import * as React from 'react'`)
|
|
463
|
+
* ```ts
|
|
464
|
+
* createImport({ name: 'React', path: 'react', isNameSpace: true })
|
|
465
|
+
* ```
|
|
466
|
+
*/
|
|
467
|
+
type ImportNode = BaseNode & {
|
|
468
|
+
kind: 'Import';
|
|
469
|
+
/**
|
|
470
|
+
* Import name(s) to be used.
|
|
471
|
+
* @example ['useState']
|
|
472
|
+
* @example 'React'
|
|
473
|
+
*/
|
|
474
|
+
name: ImportName;
|
|
475
|
+
/**
|
|
476
|
+
* Path for the import.
|
|
477
|
+
* @example '@kubb/core'
|
|
478
|
+
*/
|
|
479
|
+
path: string;
|
|
480
|
+
/**
|
|
481
|
+
* Add type-only import prefix.
|
|
482
|
+
* - `true` generates `import type { Type } from './path'`
|
|
483
|
+
* - `false` generates `import { Type } from './path'`
|
|
484
|
+
* @default false
|
|
485
|
+
*/
|
|
486
|
+
isTypeOnly?: boolean;
|
|
487
|
+
/**
|
|
488
|
+
* Import entire module as namespace.
|
|
489
|
+
* - `true` generates `import * as Name from './path'`
|
|
490
|
+
* - `false` generates standard import
|
|
491
|
+
* @default false
|
|
492
|
+
*/
|
|
493
|
+
isNameSpace?: boolean;
|
|
494
|
+
/**
|
|
495
|
+
* When set, the import path is resolved relative to this root.
|
|
496
|
+
*/
|
|
497
|
+
root?: string;
|
|
498
|
+
};
|
|
499
|
+
/**
|
|
500
|
+
* Represents a language-agnostic export/public API declaration.
|
|
501
|
+
*
|
|
502
|
+
* @example Named export (TypeScript: `export { Pets } from './Pets'`)
|
|
503
|
+
* ```ts
|
|
504
|
+
* createExport({ name: ['Pets'], path: './Pets' })
|
|
505
|
+
* ```
|
|
506
|
+
*
|
|
507
|
+
* @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
|
|
508
|
+
* ```ts
|
|
509
|
+
* createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })
|
|
510
|
+
* ```
|
|
511
|
+
*
|
|
512
|
+
* @example Wildcard export (TypeScript: `export * from './utils'`)
|
|
513
|
+
* ```ts
|
|
514
|
+
* createExport({ path: './utils' })
|
|
515
|
+
* ```
|
|
516
|
+
*
|
|
517
|
+
* @example Namespace alias (TypeScript: `export * as utils from './utils'`)
|
|
518
|
+
* ```ts
|
|
519
|
+
* createExport({ name: 'utils', path: './utils', asAlias: true })
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
type ExportNode = BaseNode & {
|
|
523
|
+
kind: 'Export';
|
|
524
|
+
/**
|
|
525
|
+
* Export name(s) to be used. When omitted, generates a wildcard export.
|
|
526
|
+
* @example ['useState']
|
|
527
|
+
* @example 'React'
|
|
528
|
+
*/
|
|
529
|
+
name?: string | Array<string>;
|
|
530
|
+
/**
|
|
531
|
+
* Path for the export.
|
|
532
|
+
* @example '@kubb/core'
|
|
533
|
+
*/
|
|
534
|
+
path: string;
|
|
535
|
+
/**
|
|
536
|
+
* Add type-only export prefix.
|
|
537
|
+
* - `true` generates `export type { Type } from './path'`
|
|
538
|
+
* - `false` generates `export { Type } from './path'`
|
|
539
|
+
* @default false
|
|
540
|
+
*/
|
|
541
|
+
isTypeOnly?: boolean;
|
|
542
|
+
/**
|
|
543
|
+
* Export as an aliased namespace.
|
|
544
|
+
* - `true` generates `export * as aliasName from './path'`
|
|
545
|
+
* - `false` generates a standard export
|
|
546
|
+
* @default false
|
|
547
|
+
*/
|
|
548
|
+
asAlias?: boolean;
|
|
549
|
+
};
|
|
550
|
+
/**
|
|
551
|
+
* Represents a fragment of source code within a file.
|
|
552
|
+
*
|
|
553
|
+
* @example Named exportable source
|
|
554
|
+
* ```ts
|
|
555
|
+
* createSource({ name: 'Pet', value: 'export type Pet = { id: number }', isExportable: true, isIndexable: true })
|
|
556
|
+
* ```
|
|
557
|
+
*
|
|
558
|
+
* @example Inline unnamed code block
|
|
559
|
+
* ```ts
|
|
560
|
+
* createSource({ value: 'const x = 1' })
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
563
|
+
type SourceNode = BaseNode & {
|
|
564
|
+
kind: 'Source';
|
|
565
|
+
/**
|
|
566
|
+
* Optional name identifying this source (used for deduplication and barrel generation).
|
|
567
|
+
*/
|
|
568
|
+
name?: string;
|
|
569
|
+
/**
|
|
570
|
+
* The source code value.
|
|
571
|
+
*/
|
|
572
|
+
value?: string;
|
|
573
|
+
/**
|
|
574
|
+
* Mark this source as a type-only export.
|
|
575
|
+
* @default false
|
|
576
|
+
*/
|
|
577
|
+
isTypeOnly?: boolean;
|
|
578
|
+
/**
|
|
579
|
+
* Include `export` keyword in the generated source.
|
|
580
|
+
* @default false
|
|
581
|
+
*/
|
|
582
|
+
isExportable?: boolean;
|
|
583
|
+
/**
|
|
584
|
+
* Include this source in barrel/index file generation.
|
|
585
|
+
* @default false
|
|
586
|
+
*/
|
|
587
|
+
isIndexable?: boolean;
|
|
588
|
+
/**
|
|
589
|
+
* Structured child nodes representing the content of this source fragment.
|
|
590
|
+
* These correspond to the children of the `File.Source` component from `@kubb/react-fabric`
|
|
591
|
+
* (e.g. `ConstNode`, `TypeDeclarationNode`, `FunctionDeclarationNode`, `ArrowFunctionDeclarationNode`).
|
|
592
|
+
*/
|
|
593
|
+
nodes?: Array<CodeNode>;
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* Represents a fully resolved file in the AST.
|
|
597
|
+
*
|
|
598
|
+
* Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input
|
|
599
|
+
* and deduplicates `imports`, `exports`, and `sources`.
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```ts
|
|
603
|
+
* const file = createFile({
|
|
604
|
+
* baseName: 'petStore.ts',
|
|
605
|
+
* path: 'src/models/petStore.ts',
|
|
606
|
+
* sources: [createSource({ name: 'Pet', value: 'export type Pet = { id: number }', isExportable: true })],
|
|
607
|
+
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
608
|
+
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
609
|
+
* })
|
|
610
|
+
* // file.id = SHA256 hash of the path
|
|
611
|
+
* // file.name = 'petStore'
|
|
612
|
+
* // file.extname = '.ts'
|
|
613
|
+
* ```
|
|
614
|
+
*/
|
|
615
|
+
type FileNode<TMeta extends object = object> = BaseNode & {
|
|
616
|
+
kind: 'File';
|
|
617
|
+
/**
|
|
618
|
+
* Unique identifier derived from a SHA256 hash of the file path.
|
|
619
|
+
* @default hash
|
|
620
|
+
*/
|
|
621
|
+
id: string;
|
|
622
|
+
/**
|
|
623
|
+
* File name without extension, derived from `baseName`.
|
|
624
|
+
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
625
|
+
*/
|
|
626
|
+
name: string;
|
|
627
|
+
/**
|
|
628
|
+
* File base name, including extension.
|
|
629
|
+
* Based on UNIX basename: `${name}${extname}`
|
|
630
|
+
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
631
|
+
*/
|
|
632
|
+
baseName: `${string}.${string}`;
|
|
633
|
+
/**
|
|
634
|
+
* Full qualified path to the file.
|
|
635
|
+
*/
|
|
636
|
+
path: string;
|
|
637
|
+
/**
|
|
638
|
+
* File extension extracted from `baseName`.
|
|
639
|
+
*/
|
|
640
|
+
extname: Extname;
|
|
641
|
+
/**
|
|
642
|
+
* Deduplicated list of source code fragments.
|
|
643
|
+
*/
|
|
644
|
+
sources: Array<SourceNode>;
|
|
645
|
+
/**
|
|
646
|
+
* Deduplicated list of import declarations.
|
|
647
|
+
*/
|
|
648
|
+
imports: Array<ImportNode>;
|
|
649
|
+
/**
|
|
650
|
+
* Deduplicated list of export declarations.
|
|
651
|
+
*/
|
|
652
|
+
exports: Array<ExportNode>;
|
|
653
|
+
/**
|
|
654
|
+
* Optional metadata attached to this file (used by plugins for barrel generation etc.).
|
|
655
|
+
*/
|
|
656
|
+
meta?: TMeta;
|
|
657
|
+
/**
|
|
658
|
+
* Optional banner prepended to the generated file content.
|
|
659
|
+
*/
|
|
660
|
+
banner?: string;
|
|
661
|
+
/**
|
|
662
|
+
* Optional footer appended to the generated file content.
|
|
663
|
+
*/
|
|
664
|
+
footer?: string;
|
|
665
|
+
};
|
|
666
|
+
//#endregion
|
|
187
667
|
//#region src/nodes/function.d.ts
|
|
188
668
|
/**
|
|
189
|
-
* AST node representing a language-agnostic type expression
|
|
190
|
-
* Each language printer renders the variant into its own syntax.
|
|
669
|
+
* AST node representing a language-agnostic type expression used as a function parameter
|
|
670
|
+
* type annotation. Each language printer renders the variant into its own syntax.
|
|
191
671
|
*
|
|
192
672
|
* - `struct` — an inline anonymous type grouping named fields.
|
|
193
|
-
* TypeScript renders as `{ petId: string; name?: string }
|
|
673
|
+
* TypeScript renders as `{ petId: string; name?: string }`.
|
|
194
674
|
* - `member` — a single named field accessed from a named group type.
|
|
195
|
-
* TypeScript renders as `PathParams['petId']
|
|
675
|
+
* TypeScript renders as `PathParams['petId']`.
|
|
676
|
+
*
|
|
677
|
+
* @example Reference variant
|
|
678
|
+
* ```ts
|
|
679
|
+
* createParamsType({ variant: 'reference', name: 'QueryParams' })
|
|
680
|
+
* // QueryParams
|
|
681
|
+
* ```
|
|
682
|
+
*
|
|
683
|
+
* @example Struct variant
|
|
684
|
+
* ```ts
|
|
685
|
+
* createParamsType({ variant: 'struct', properties: [{ name: 'petId', optional: false, type: createParamsType({ variant: 'reference', name: 'string' }) }] })
|
|
686
|
+
* // { petId: string }
|
|
687
|
+
* ```
|
|
688
|
+
*
|
|
689
|
+
* @example Member variant
|
|
690
|
+
* ```ts
|
|
691
|
+
* createParamsType({ variant: 'member', base: 'PathParams', key: 'petId' })
|
|
692
|
+
* // PathParams['petId']
|
|
693
|
+
* ```
|
|
196
694
|
*/
|
|
197
|
-
type
|
|
695
|
+
type ParamsTypeNode = BaseNode & {
|
|
198
696
|
/**
|
|
199
697
|
* Node kind.
|
|
200
698
|
*/
|
|
201
|
-
kind: '
|
|
699
|
+
kind: 'ParamsType';
|
|
202
700
|
} & ({
|
|
203
701
|
/**
|
|
204
702
|
* Reference variant — a plain type name or identifier.
|
|
@@ -221,7 +719,7 @@ type TypeNode = BaseNode & {
|
|
|
221
719
|
properties: Array<{
|
|
222
720
|
name: string;
|
|
223
721
|
optional: boolean;
|
|
224
|
-
type:
|
|
722
|
+
type: ParamsTypeNode;
|
|
225
723
|
}>;
|
|
226
724
|
} | {
|
|
227
725
|
/**
|
|
@@ -263,19 +761,19 @@ type FunctionParameterNode = BaseNode & {
|
|
|
263
761
|
*/
|
|
264
762
|
name: string;
|
|
265
763
|
/**
|
|
266
|
-
* Type annotation as a structured {@link
|
|
764
|
+
* Type annotation as a structured {@link ParamsTypeNode}.
|
|
267
765
|
* Omit for untyped output.
|
|
268
766
|
*
|
|
269
767
|
* @example Reference type node
|
|
270
|
-
* `{ kind: '
|
|
768
|
+
* `{ kind: 'ParamsType', variant: 'reference', name: 'string' }` → `petId: string`
|
|
271
769
|
*
|
|
272
770
|
* @example Struct type node
|
|
273
|
-
* `{ kind: '
|
|
771
|
+
* `{ kind: 'ParamsType', variant: 'struct', properties: [...] }` → `{ key: Type; other?: OtherType }`
|
|
274
772
|
*
|
|
275
773
|
* @example Member type node
|
|
276
|
-
* `{ kind: '
|
|
774
|
+
* `{ kind: 'ParamsType', variant: 'member', base: 'PathParams', key: 'petId' }` → `PathParams['petId']`
|
|
277
775
|
*/
|
|
278
|
-
type?:
|
|
776
|
+
type?: ParamsTypeNode;
|
|
279
777
|
/**
|
|
280
778
|
* When `true` the parameter is emitted as a rest parameter.
|
|
281
779
|
*
|
|
@@ -336,7 +834,7 @@ type ParameterGroupNode = BaseNode & {
|
|
|
336
834
|
* Optional explicit type annotation for the whole group.
|
|
337
835
|
* When absent, printers auto-compute it from `properties`.
|
|
338
836
|
*/
|
|
339
|
-
type?:
|
|
837
|
+
type?: ParamsTypeNode;
|
|
340
838
|
/**
|
|
341
839
|
* When `true`, `properties` are emitted as individual top-level parameters instead of
|
|
342
840
|
* being wrapped in a single grouped construct.
|
|
@@ -378,13 +876,13 @@ type FunctionParametersNode = BaseNode & {
|
|
|
378
876
|
params: ReadonlyArray<FunctionParameterNode | ParameterGroupNode>;
|
|
379
877
|
};
|
|
380
878
|
/**
|
|
381
|
-
*
|
|
879
|
+
* Union of all function-parameter AST node variants used by the function-parameter printer.
|
|
382
880
|
*/
|
|
383
|
-
type
|
|
881
|
+
type FunctionParamNode = FunctionParameterNode | ParameterGroupNode | FunctionParametersNode | ParamsTypeNode;
|
|
384
882
|
/**
|
|
385
|
-
* Handler map keys — one per `
|
|
883
|
+
* Handler map keys — one per `FunctionParamNode` kind.
|
|
386
884
|
*/
|
|
387
|
-
type FunctionNodeType = 'functionParameter' | 'parameterGroup' | 'functionParameters' | '
|
|
885
|
+
type FunctionNodeType = 'functionParameter' | 'parameterGroup' | 'functionParameters' | 'paramsType';
|
|
388
886
|
//#endregion
|
|
389
887
|
//#region src/nodes/property.d.ts
|
|
390
888
|
/**
|
|
@@ -1208,6 +1706,31 @@ type OperationNode = BaseNode & {
|
|
|
1208
1706
|
responses: Array<ResponseNode>;
|
|
1209
1707
|
};
|
|
1210
1708
|
//#endregion
|
|
1709
|
+
//#region src/nodes/output.d.ts
|
|
1710
|
+
/**
|
|
1711
|
+
* Output AST node that groups all generated file output for one API document.
|
|
1712
|
+
*
|
|
1713
|
+
* Produced by generators and consumed by the build pipeline to write files.
|
|
1714
|
+
*
|
|
1715
|
+
* @example
|
|
1716
|
+
* ```ts
|
|
1717
|
+
* const output: OutputNode = {
|
|
1718
|
+
* kind: 'Output',
|
|
1719
|
+
* files: [],
|
|
1720
|
+
* }
|
|
1721
|
+
* ```
|
|
1722
|
+
*/
|
|
1723
|
+
type OutputNode = BaseNode & {
|
|
1724
|
+
/**
|
|
1725
|
+
* Node kind.
|
|
1726
|
+
*/
|
|
1727
|
+
kind: 'Output';
|
|
1728
|
+
/**
|
|
1729
|
+
* Generated file nodes.
|
|
1730
|
+
*/
|
|
1731
|
+
files: Array<FileNode>;
|
|
1732
|
+
};
|
|
1733
|
+
//#endregion
|
|
1211
1734
|
//#region src/nodes/root.d.ts
|
|
1212
1735
|
/**
|
|
1213
1736
|
* Basic metadata for an API document.
|
|
@@ -1215,10 +1738,10 @@ type OperationNode = BaseNode & {
|
|
|
1215
1738
|
*
|
|
1216
1739
|
* @example
|
|
1217
1740
|
* ```ts
|
|
1218
|
-
* const meta:
|
|
1741
|
+
* const meta: InputMeta = { title: 'Pet API', version: '1.0.0' }
|
|
1219
1742
|
* ```
|
|
1220
1743
|
*/
|
|
1221
|
-
type
|
|
1744
|
+
type InputMeta = {
|
|
1222
1745
|
/**
|
|
1223
1746
|
* API title (from `info.title` in OAS/AsyncAPI).
|
|
1224
1747
|
*/
|
|
@@ -1238,22 +1761,23 @@ type RootMeta = {
|
|
|
1238
1761
|
baseURL?: string;
|
|
1239
1762
|
};
|
|
1240
1763
|
/**
|
|
1241
|
-
*
|
|
1764
|
+
* Input AST node that contains all schemas and operations for one API document.
|
|
1765
|
+
* Produced by the adapter and consumed by all Kubb plugins.
|
|
1242
1766
|
*
|
|
1243
1767
|
* @example
|
|
1244
1768
|
* ```ts
|
|
1245
|
-
* const
|
|
1246
|
-
* kind: '
|
|
1769
|
+
* const input: InputNode = {
|
|
1770
|
+
* kind: 'Input',
|
|
1247
1771
|
* schemas: [],
|
|
1248
1772
|
* operations: [],
|
|
1249
1773
|
* }
|
|
1250
1774
|
* ```
|
|
1251
1775
|
*/
|
|
1252
|
-
type
|
|
1776
|
+
type InputNode = BaseNode & {
|
|
1253
1777
|
/**
|
|
1254
1778
|
* Node kind.
|
|
1255
1779
|
*/
|
|
1256
|
-
kind: '
|
|
1780
|
+
kind: 'Input';
|
|
1257
1781
|
/**
|
|
1258
1782
|
* All schema nodes in the document.
|
|
1259
1783
|
*/
|
|
@@ -1265,7 +1789,7 @@ type RootNode = BaseNode & {
|
|
|
1265
1789
|
/**
|
|
1266
1790
|
* Optional document metadata populated by the adapter.
|
|
1267
1791
|
*/
|
|
1268
|
-
meta?:
|
|
1792
|
+
meta?: InputMeta;
|
|
1269
1793
|
};
|
|
1270
1794
|
//#endregion
|
|
1271
1795
|
//#region src/nodes/index.d.ts
|
|
@@ -1278,15 +1802,17 @@ type RootNode = BaseNode & {
|
|
|
1278
1802
|
* ```ts
|
|
1279
1803
|
* function getKind(node: Node): string {
|
|
1280
1804
|
* switch (node.kind) {
|
|
1281
|
-
* case '
|
|
1282
|
-
* return '
|
|
1805
|
+
* case 'Input':
|
|
1806
|
+
* return 'input'
|
|
1807
|
+
* case 'Output':
|
|
1808
|
+
* return 'output'
|
|
1283
1809
|
* default:
|
|
1284
1810
|
* return 'other'
|
|
1285
1811
|
* }
|
|
1286
1812
|
* }
|
|
1287
1813
|
* ```
|
|
1288
1814
|
*/
|
|
1289
|
-
type Node =
|
|
1815
|
+
type Node = InputNode | OutputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode | FunctionParamNode | FileNode | ImportNode | ExportNode | SourceNode | ConstNode | TypeNode | ParamsTypeNode | FunctionNode | ArrowFunctionNode;
|
|
1290
1816
|
//#endregion
|
|
1291
1817
|
//#region src/infer.d.ts
|
|
1292
1818
|
/**
|
|
@@ -1458,21 +1984,36 @@ type CreateSchemaOutput<T extends CreateSchemaInput> = InferSchemaNode<T> & {
|
|
|
1458
1984
|
kind: 'Schema';
|
|
1459
1985
|
};
|
|
1460
1986
|
/**
|
|
1461
|
-
* Creates
|
|
1987
|
+
* Creates an `InputNode` with stable defaults for `schemas` and `operations`.
|
|
1462
1988
|
*
|
|
1463
1989
|
* @example
|
|
1464
1990
|
* ```ts
|
|
1465
|
-
* const
|
|
1466
|
-
* // { kind: '
|
|
1991
|
+
* const input = createInput()
|
|
1992
|
+
* // { kind: 'Input', schemas: [], operations: [] }
|
|
1467
1993
|
* ```
|
|
1468
1994
|
*
|
|
1469
1995
|
* @example
|
|
1470
1996
|
* ```ts
|
|
1471
|
-
* const
|
|
1997
|
+
* const input = createInput({ schemas: [petSchema] })
|
|
1472
1998
|
* // keeps default operations: []
|
|
1473
1999
|
* ```
|
|
1474
2000
|
*/
|
|
1475
|
-
declare function
|
|
2001
|
+
declare function createInput(overrides?: Partial<Omit<InputNode, 'kind'>>): InputNode;
|
|
2002
|
+
/**
|
|
2003
|
+
* Creates an `OutputNode` with a stable default for `files`.
|
|
2004
|
+
*
|
|
2005
|
+
* @example
|
|
2006
|
+
* ```ts
|
|
2007
|
+
* const output = createOutput()
|
|
2008
|
+
* // { kind: 'Output', files: [] }
|
|
2009
|
+
* ```
|
|
2010
|
+
*
|
|
2011
|
+
* @example
|
|
2012
|
+
* ```ts
|
|
2013
|
+
* const output = createOutput({ files: [petFile] })
|
|
2014
|
+
* ```
|
|
2015
|
+
*/
|
|
2016
|
+
declare function createOutput(overrides?: Partial<Omit<OutputNode, 'kind'>>): OutputNode;
|
|
1476
2017
|
/**
|
|
1477
2018
|
* Creates an `OperationNode` with default empty arrays for `tags`, `parameters`, and `responses`.
|
|
1478
2019
|
*
|
|
@@ -1531,6 +2072,7 @@ declare function createOperation(props: Pick<OperationNode, 'operationId' | 'met
|
|
|
1531
2072
|
*/
|
|
1532
2073
|
declare function createSchema<T extends CreateSchemaInput>(props: T): CreateSchemaOutput<T>;
|
|
1533
2074
|
declare function createSchema(props: CreateSchemaInput): SchemaNode;
|
|
2075
|
+
type UserPropertyNode = Pick<PropertyNode, 'name' | 'schema'> & Partial<Omit<PropertyNode, 'kind' | 'name' | 'schema'>>;
|
|
1534
2076
|
/**
|
|
1535
2077
|
* Creates a `PropertyNode`.
|
|
1536
2078
|
*
|
|
@@ -1556,7 +2098,7 @@ declare function createSchema(props: CreateSchemaInput): SchemaNode;
|
|
|
1556
2098
|
* // required=true, no optional/nullish
|
|
1557
2099
|
* ```
|
|
1558
2100
|
*/
|
|
1559
|
-
declare function createProperty(props:
|
|
2101
|
+
declare function createProperty(props: UserPropertyNode): PropertyNode;
|
|
1560
2102
|
/**
|
|
1561
2103
|
* Creates a `ParameterNode`.
|
|
1562
2104
|
*
|
|
@@ -1604,25 +2146,25 @@ declare function createResponse(props: Pick<ResponseNode, 'statusCode' | 'schema
|
|
|
1604
2146
|
*
|
|
1605
2147
|
* @example Required typed param
|
|
1606
2148
|
* ```ts
|
|
1607
|
-
* createFunctionParameter({ name: 'petId', type:
|
|
2149
|
+
* createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }) })
|
|
1608
2150
|
* // → petId: string
|
|
1609
2151
|
* ```
|
|
1610
2152
|
*
|
|
1611
2153
|
* @example Optional param
|
|
1612
2154
|
* ```ts
|
|
1613
|
-
* createFunctionParameter({ name: 'params', type:
|
|
2155
|
+
* createFunctionParameter({ name: 'params', type: createParamsType({ variant: 'reference', name: 'QueryParams' }), optional: true })
|
|
1614
2156
|
* // → params?: QueryParams
|
|
1615
2157
|
* ```
|
|
1616
2158
|
*
|
|
1617
2159
|
* @example Param with default (implicitly optional; cannot combine with `optional: true`)
|
|
1618
2160
|
* ```ts
|
|
1619
|
-
* createFunctionParameter({ name: 'config', type:
|
|
2161
|
+
* createFunctionParameter({ name: 'config', type: createParamsType({ variant: 'reference', name: 'RequestConfig' }), default: '{}' })
|
|
1620
2162
|
* // → config: RequestConfig = {}
|
|
1621
2163
|
* ```
|
|
1622
2164
|
*/
|
|
1623
2165
|
declare function createFunctionParameter(props: {
|
|
1624
2166
|
name: string;
|
|
1625
|
-
type?:
|
|
2167
|
+
type?: ParamsTypeNode;
|
|
1626
2168
|
rest?: boolean;
|
|
1627
2169
|
} & ({
|
|
1628
2170
|
optional: true;
|
|
@@ -1640,20 +2182,20 @@ declare function createFunctionParameter(props: {
|
|
|
1640
2182
|
*
|
|
1641
2183
|
* @example Reference type (TypeScript: `QueryParams`)
|
|
1642
2184
|
* ```ts
|
|
1643
|
-
*
|
|
2185
|
+
* createParamsType({ variant: 'reference', name: 'QueryParams' })
|
|
1644
2186
|
* ```
|
|
1645
2187
|
*
|
|
1646
2188
|
* @example Struct type (TypeScript: `{ petId: string }`)
|
|
1647
2189
|
* ```ts
|
|
1648
|
-
*
|
|
2190
|
+
* createParamsType({ variant: 'struct', properties: [{ name: 'petId', optional: false, type: createParamsType({ variant: 'reference', name: 'string' }) }] })
|
|
1649
2191
|
* ```
|
|
1650
2192
|
*
|
|
1651
2193
|
* @example Member type (TypeScript: `DeletePetPathParams['petId']`)
|
|
1652
2194
|
* ```ts
|
|
1653
|
-
*
|
|
2195
|
+
* createParamsType({ variant: 'member', base: 'DeletePetPathParams', key: 'petId' })
|
|
1654
2196
|
* ```
|
|
1655
2197
|
*/
|
|
1656
|
-
declare function
|
|
2198
|
+
declare function createParamsType(props: {
|
|
1657
2199
|
variant: 'reference';
|
|
1658
2200
|
name: string;
|
|
1659
2201
|
} | {
|
|
@@ -1661,13 +2203,13 @@ declare function createTypeNode(props: {
|
|
|
1661
2203
|
properties: Array<{
|
|
1662
2204
|
name: string;
|
|
1663
2205
|
optional: boolean;
|
|
1664
|
-
type:
|
|
2206
|
+
type: ParamsTypeNode;
|
|
1665
2207
|
}>;
|
|
1666
2208
|
} | {
|
|
1667
2209
|
variant: 'member';
|
|
1668
2210
|
base: string;
|
|
1669
2211
|
key: string;
|
|
1670
|
-
}):
|
|
2212
|
+
}): ParamsTypeNode;
|
|
1671
2213
|
/**
|
|
1672
2214
|
* Creates a `ParameterGroupNode` representing a group of related parameters treated as a unit.
|
|
1673
2215
|
*
|
|
@@ -1675,8 +2217,8 @@ declare function createTypeNode(props: {
|
|
|
1675
2217
|
* ```ts
|
|
1676
2218
|
* createParameterGroup({
|
|
1677
2219
|
* properties: [
|
|
1678
|
-
* createFunctionParameter({ name: 'id', type:
|
|
1679
|
-
* createFunctionParameter({ name: 'name', type:
|
|
2220
|
+
* createFunctionParameter({ name: 'id', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false }),
|
|
2221
|
+
* createFunctionParameter({ name: 'name', type: createParamsType({ variant: 'reference', name: 'string' }), optional: true }),
|
|
1680
2222
|
* ],
|
|
1681
2223
|
* default: '{}',
|
|
1682
2224
|
* })
|
|
@@ -1687,7 +2229,7 @@ declare function createTypeNode(props: {
|
|
|
1687
2229
|
* @example Inline (spread) — children emitted as individual top-level parameters
|
|
1688
2230
|
* ```ts
|
|
1689
2231
|
* createParameterGroup({
|
|
1690
|
-
* properties: [createFunctionParameter({ name: 'petId', type:
|
|
2232
|
+
* properties: [createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false })],
|
|
1691
2233
|
* inline: true,
|
|
1692
2234
|
* })
|
|
1693
2235
|
* // declaration → petId: string
|
|
@@ -1702,8 +2244,8 @@ declare function createParameterGroup(props: Pick<ParameterGroupNode, 'propertie
|
|
|
1702
2244
|
* ```ts
|
|
1703
2245
|
* createFunctionParameters({
|
|
1704
2246
|
* params: [
|
|
1705
|
-
* createFunctionParameter({ name: 'petId', type:
|
|
1706
|
-
* createFunctionParameter({ name: 'config', type:
|
|
2247
|
+
* createFunctionParameter({ name: 'petId', type: createParamsType({ variant: 'reference', name: 'string' }), optional: false }),
|
|
2248
|
+
* createFunctionParameter({ name: 'config', type: createParamsType({ variant: 'reference', name: 'RequestConfig' }), optional: false, default: '{}' }),
|
|
1707
2249
|
* ],
|
|
1708
2250
|
* })
|
|
1709
2251
|
* ```
|
|
@@ -1715,6 +2257,193 @@ declare function createParameterGroup(props: Pick<ParameterGroupNode, 'propertie
|
|
|
1715
2257
|
* ```
|
|
1716
2258
|
*/
|
|
1717
2259
|
declare function createFunctionParameters(props?: Partial<Omit<FunctionParametersNode, 'kind'>>): FunctionParametersNode;
|
|
2260
|
+
/**
|
|
2261
|
+
* Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
|
|
2262
|
+
*
|
|
2263
|
+
* @example Named import
|
|
2264
|
+
* ```ts
|
|
2265
|
+
* createImport({ name: ['useState'], path: 'react' })
|
|
2266
|
+
* // import { useState } from 'react'
|
|
2267
|
+
* ```
|
|
2268
|
+
*
|
|
2269
|
+
* @example Type-only import
|
|
2270
|
+
* ```ts
|
|
2271
|
+
* createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
|
|
2272
|
+
* // import type { FC } from 'react'
|
|
2273
|
+
* ```
|
|
2274
|
+
*/
|
|
2275
|
+
declare function createImport(props: Omit<ImportNode, 'kind'>): ImportNode;
|
|
2276
|
+
/**
|
|
2277
|
+
* Creates an `ExportNode` representing a language-agnostic export/public API declaration.
|
|
2278
|
+
*
|
|
2279
|
+
* @example Named export
|
|
2280
|
+
* ```ts
|
|
2281
|
+
* createExport({ name: ['Pet'], path: './Pet' })
|
|
2282
|
+
* // export { Pet } from './Pet'
|
|
2283
|
+
* ```
|
|
2284
|
+
*
|
|
2285
|
+
* @example Wildcard export
|
|
2286
|
+
* ```ts
|
|
2287
|
+
* createExport({ path: './utils' })
|
|
2288
|
+
* // export * from './utils'
|
|
2289
|
+
* ```
|
|
2290
|
+
*/
|
|
2291
|
+
declare function createExport(props: Omit<ExportNode, 'kind'>): ExportNode;
|
|
2292
|
+
/**
|
|
2293
|
+
* Creates a `SourceNode` representing a fragment of source code within a file.
|
|
2294
|
+
*
|
|
2295
|
+
* @example
|
|
2296
|
+
* ```ts
|
|
2297
|
+
* createSource({ name: 'Pet', value: 'export type Pet = { id: number }', isExportable: true })
|
|
2298
|
+
* ```
|
|
2299
|
+
*/
|
|
2300
|
+
declare function createSource(props: Omit<SourceNode, 'kind'>): SourceNode;
|
|
2301
|
+
type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> & Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>;
|
|
2302
|
+
/**
|
|
2303
|
+
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
2304
|
+
*
|
|
2305
|
+
* Computes:
|
|
2306
|
+
* - `id` — SHA256 hash of the file path
|
|
2307
|
+
* - `name` — `baseName` without extension
|
|
2308
|
+
* - `extname` — extension extracted from `baseName`
|
|
2309
|
+
*
|
|
2310
|
+
* Deduplicates:
|
|
2311
|
+
* - `sources` via `combineSources`
|
|
2312
|
+
* - `exports` via `combineExports`
|
|
2313
|
+
* - `imports` via `combineImports` (also filters unused imports)
|
|
2314
|
+
*
|
|
2315
|
+
* @throws {Error} when `baseName` has no extension.
|
|
2316
|
+
*
|
|
2317
|
+
* @example
|
|
2318
|
+
* ```ts
|
|
2319
|
+
* const file = createFile({
|
|
2320
|
+
* baseName: 'petStore.ts',
|
|
2321
|
+
* path: 'src/models/petStore.ts',
|
|
2322
|
+
* sources: [createSource({ name: 'Pet', value: 'export type Pet = { id: number }' })],
|
|
2323
|
+
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
2324
|
+
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
2325
|
+
* })
|
|
2326
|
+
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
2327
|
+
* // file.name = 'petStore'
|
|
2328
|
+
* // file.extname = '.ts'
|
|
2329
|
+
* ```
|
|
2330
|
+
*/
|
|
2331
|
+
declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
|
|
2332
|
+
/**
|
|
2333
|
+
* Creates a `ConstNode` representing a TypeScript `const` declaration.
|
|
2334
|
+
*
|
|
2335
|
+
* Mirrors the `Const` component from `@kubb/react-fabric`.
|
|
2336
|
+
* The component's `children` are represented as `nodes`.
|
|
2337
|
+
*
|
|
2338
|
+
* @example Simple constant
|
|
2339
|
+
* ```ts
|
|
2340
|
+
* createConst({ name: 'pet' })
|
|
2341
|
+
* // const pet = ...
|
|
2342
|
+
* ```
|
|
2343
|
+
*
|
|
2344
|
+
* @example Exported constant with type and `as const`
|
|
2345
|
+
* ```ts
|
|
2346
|
+
* createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
|
|
2347
|
+
* // export const pets: Pet[] = ... as const
|
|
2348
|
+
* ```
|
|
2349
|
+
*
|
|
2350
|
+
* @example With JSDoc and child nodes
|
|
2351
|
+
* ```ts
|
|
2352
|
+
* createConst({
|
|
2353
|
+
* name: 'config',
|
|
2354
|
+
* export: true,
|
|
2355
|
+
* JSDoc: { comments: ['@description App configuration'] },
|
|
2356
|
+
* nodes: [],
|
|
2357
|
+
* })
|
|
2358
|
+
* ```
|
|
2359
|
+
*/
|
|
2360
|
+
declare function createConst(props: Omit<ConstNode, 'kind'>): ConstNode;
|
|
2361
|
+
/**
|
|
2362
|
+
* Creates a `TypeNode` representing a TypeScript `type` alias declaration.
|
|
2363
|
+
*
|
|
2364
|
+
* Mirrors the `Type` component from `@kubb/react-fabric`.
|
|
2365
|
+
* The component's `children` are represented as `nodes`.
|
|
2366
|
+
*
|
|
2367
|
+
* @example Simple type alias
|
|
2368
|
+
* ```ts
|
|
2369
|
+
* createType({ name: 'Pet' })
|
|
2370
|
+
* // type Pet = ...
|
|
2371
|
+
* ```
|
|
2372
|
+
*
|
|
2373
|
+
* @example Exported type with JSDoc
|
|
2374
|
+
* ```ts
|
|
2375
|
+
* createType({
|
|
2376
|
+
* name: 'PetStatus',
|
|
2377
|
+
* export: true,
|
|
2378
|
+
* JSDoc: { comments: ['@description Status of a pet'] },
|
|
2379
|
+
* })
|
|
2380
|
+
* // export type PetStatus = ...
|
|
2381
|
+
* ```
|
|
2382
|
+
*/
|
|
2383
|
+
declare function createType(props: Omit<TypeNode, 'kind'>): TypeNode;
|
|
2384
|
+
/**
|
|
2385
|
+
* Creates a `FunctionNode` representing a TypeScript `function` declaration.
|
|
2386
|
+
*
|
|
2387
|
+
* Mirrors the `Function` component from `@kubb/react-fabric`.
|
|
2388
|
+
* The component's `children` are represented as `nodes`.
|
|
2389
|
+
*
|
|
2390
|
+
* @example Simple function
|
|
2391
|
+
* ```ts
|
|
2392
|
+
* createFunction({ name: 'getPet' })
|
|
2393
|
+
* // function getPet() { ... }
|
|
2394
|
+
* ```
|
|
2395
|
+
*
|
|
2396
|
+
* @example Exported async function with return type
|
|
2397
|
+
* ```ts
|
|
2398
|
+
* createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
|
|
2399
|
+
* // export async function fetchPet(): Promise<Pet> { ... }
|
|
2400
|
+
* ```
|
|
2401
|
+
*
|
|
2402
|
+
* @example Function with generics and params
|
|
2403
|
+
* ```ts
|
|
2404
|
+
* createFunction({
|
|
2405
|
+
* name: 'identity',
|
|
2406
|
+
* export: true,
|
|
2407
|
+
* generics: ['T'],
|
|
2408
|
+
* params: 'value: T',
|
|
2409
|
+
* returnType: 'T',
|
|
2410
|
+
* })
|
|
2411
|
+
* // export function identity<T>(value: T): T { ... }
|
|
2412
|
+
* ```
|
|
2413
|
+
*/
|
|
2414
|
+
declare function createFunction(props: Omit<FunctionNode, 'kind'>): FunctionNode;
|
|
2415
|
+
/**
|
|
2416
|
+
* Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
|
|
2417
|
+
*
|
|
2418
|
+
* Mirrors the `Function.Arrow` component from `@kubb/react-fabric`.
|
|
2419
|
+
* The component's `children` are represented as `nodes`.
|
|
2420
|
+
*
|
|
2421
|
+
* @example Simple arrow function
|
|
2422
|
+
* ```ts
|
|
2423
|
+
* createArrowFunction({ name: 'getPet' })
|
|
2424
|
+
* // const getPet = () => { ... }
|
|
2425
|
+
* ```
|
|
2426
|
+
*
|
|
2427
|
+
* @example Single-line exported arrow function
|
|
2428
|
+
* ```ts
|
|
2429
|
+
* createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
|
|
2430
|
+
* // export const double = (n: number) => ...
|
|
2431
|
+
* ```
|
|
2432
|
+
*
|
|
2433
|
+
* @example Async arrow function with generics
|
|
2434
|
+
* ```ts
|
|
2435
|
+
* createArrowFunction({
|
|
2436
|
+
* name: 'fetchPet',
|
|
2437
|
+
* export: true,
|
|
2438
|
+
* async: true,
|
|
2439
|
+
* generics: ['T'],
|
|
2440
|
+
* params: 'id: string',
|
|
2441
|
+
* returnType: 'T',
|
|
2442
|
+
* })
|
|
2443
|
+
* // export const fetchPet = async <T>(id: string): Promise<T> => { ... }
|
|
2444
|
+
* ```
|
|
2445
|
+
*/
|
|
2446
|
+
declare function createArrowFunction(props: Omit<ArrowFunctionNode, 'kind'>): ArrowFunctionNode;
|
|
1718
2447
|
//#endregion
|
|
1719
2448
|
//#region src/printer.d.ts
|
|
1720
2449
|
/**
|
|
@@ -1936,7 +2665,7 @@ declare function extractRefName(ref: string): string;
|
|
|
1936
2665
|
*
|
|
1937
2666
|
* `ParentOf` uses this map to find parent types.
|
|
1938
2667
|
*/
|
|
1939
|
-
type ParentNodeMap = [[
|
|
2668
|
+
type ParentNodeMap = [[InputNode, undefined], [OutputNode, undefined], [OperationNode, InputNode], [SchemaNode, InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode], [PropertyNode, SchemaNode], [ParameterNode, OperationNode], [ResponseNode, OperationNode]];
|
|
1940
2669
|
/**
|
|
1941
2670
|
* Resolves the parent node type for a given AST node type.
|
|
1942
2671
|
*
|
|
@@ -1945,7 +2674,7 @@ type ParentNodeMap = [[RootNode, undefined], [OperationNode, RootNode], [SchemaN
|
|
|
1945
2674
|
*
|
|
1946
2675
|
* @example
|
|
1947
2676
|
* ```ts
|
|
1948
|
-
* type
|
|
2677
|
+
* type InputParent = ParentOf<InputNode>
|
|
1949
2678
|
* // undefined
|
|
1950
2679
|
* ```
|
|
1951
2680
|
*
|
|
@@ -1958,7 +2687,7 @@ type ParentNodeMap = [[RootNode, undefined], [OperationNode, RootNode], [SchemaN
|
|
|
1958
2687
|
* @example
|
|
1959
2688
|
* ```ts
|
|
1960
2689
|
* type SchemaParent = ParentOf<SchemaNode>
|
|
1961
|
-
* //
|
|
2690
|
+
* // InputNode | OperationNode | SchemaNode | PropertyNode | ParameterNode | ResponseNode
|
|
1962
2691
|
* ```
|
|
1963
2692
|
*/
|
|
1964
2693
|
type ParentOf<T extends Node, TEntries extends ReadonlyArray<[Node, unknown]> = ParentNodeMap> = TEntries extends [infer TEntry extends [Node, unknown], ...infer TRest extends ReadonlyArray<[Node, unknown]>] ? T extends TEntry[0] ? TEntry[1] : ParentOf<T, TRest> : Node;
|
|
@@ -1978,7 +2707,7 @@ type ParentOf<T extends Node, TEntries extends ReadonlyArray<[Node, unknown]> =
|
|
|
1978
2707
|
type VisitorContext<T extends Node = Node> = {
|
|
1979
2708
|
/**
|
|
1980
2709
|
* Parent node of the currently visited node.
|
|
1981
|
-
* For `
|
|
2710
|
+
* For `InputNode`, this is `undefined`.
|
|
1982
2711
|
*/
|
|
1983
2712
|
parent?: ParentOf<T>;
|
|
1984
2713
|
};
|
|
@@ -1995,7 +2724,8 @@ type VisitorContext<T extends Node = Node> = {
|
|
|
1995
2724
|
* ```
|
|
1996
2725
|
*/
|
|
1997
2726
|
type Visitor = {
|
|
1998
|
-
|
|
2727
|
+
input?(node: InputNode, context: VisitorContext<InputNode>): void | InputNode;
|
|
2728
|
+
output?(node: OutputNode, context: VisitorContext<OutputNode>): void | OutputNode;
|
|
1999
2729
|
operation?(node: OperationNode, context: VisitorContext<OperationNode>): void | OperationNode;
|
|
2000
2730
|
schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): void | SchemaNode;
|
|
2001
2731
|
property?(node: PropertyNode, context: VisitorContext<PropertyNode>): void | PropertyNode;
|
|
@@ -2019,7 +2749,8 @@ type MaybePromise<T> = T | Promise<T>;
|
|
|
2019
2749
|
* ```
|
|
2020
2750
|
*/
|
|
2021
2751
|
type AsyncVisitor = {
|
|
2022
|
-
|
|
2752
|
+
input?(node: InputNode, context: VisitorContext<InputNode>): MaybePromise<void | InputNode>;
|
|
2753
|
+
output?(node: OutputNode, context: VisitorContext<OutputNode>): MaybePromise<void | OutputNode>;
|
|
2023
2754
|
operation?(node: OperationNode, context: VisitorContext<OperationNode>): MaybePromise<void | OperationNode>;
|
|
2024
2755
|
schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): MaybePromise<void | SchemaNode>;
|
|
2025
2756
|
property?(node: PropertyNode, context: VisitorContext<PropertyNode>): MaybePromise<void | PropertyNode>;
|
|
@@ -2039,7 +2770,8 @@ type AsyncVisitor = {
|
|
|
2039
2770
|
* ```
|
|
2040
2771
|
*/
|
|
2041
2772
|
type CollectVisitor<T> = {
|
|
2042
|
-
|
|
2773
|
+
input?(node: InputNode, context: VisitorContext<InputNode>): T | undefined;
|
|
2774
|
+
output?(node: OutputNode, context: VisitorContext<OutputNode>): T | undefined;
|
|
2043
2775
|
operation?(node: OperationNode, context: VisitorContext<OperationNode>): T | undefined;
|
|
2044
2776
|
schema?(node: SchemaNode, context: VisitorContext<SchemaNode>): T | undefined;
|
|
2045
2777
|
property?(node: PropertyNode, context: VisitorContext<PropertyNode>): T | undefined;
|
|
@@ -2152,7 +2884,8 @@ declare function walk(node: Node, options: WalkOptions): Promise<void>;
|
|
|
2152
2884
|
* const next = transform(root, { depth: 'shallow', root: (node) => node })
|
|
2153
2885
|
* ```
|
|
2154
2886
|
*/
|
|
2155
|
-
declare function transform(node:
|
|
2887
|
+
declare function transform(node: InputNode, options: TransformOptions): InputNode;
|
|
2888
|
+
declare function transform(node: OutputNode, options: TransformOptions): OutputNode;
|
|
2156
2889
|
declare function transform(node: OperationNode, options: TransformOptions): OperationNode;
|
|
2157
2890
|
declare function transform(node: SchemaNode, options: TransformOptions): SchemaNode;
|
|
2158
2891
|
declare function transform(node: PropertyNode, options: TransformOptions): PropertyNode;
|
|
@@ -2196,5 +2929,5 @@ declare function composeTransformers(...visitors: Array<Visitor>): Visitor;
|
|
|
2196
2929
|
*/
|
|
2197
2930
|
declare function collect<T>(node: Node, options: CollectOptions<T>): Array<T>;
|
|
2198
2931
|
//#endregion
|
|
2199
|
-
export {
|
|
2200
|
-
//# sourceMappingURL=visitor-
|
|
2932
|
+
export { StatusCode as $, createOperation as A, FunctionParametersNode as At, syncOptionality as B, FunctionNode as Bt, createExport as C, TimeSchemaNode as Ct, createFunctionParameters as D, FunctionNodeType as Dt, createFunctionParameter as E, PropertyNode as Et, createProperty as F, ImportNode as Ft, InputMeta as G, NodeKind as Gt, InferSchemaNode as H, TypeDeclarationNode as Ht, createResponse as I, SourceNode as It, HttpMethod as J, httpMethods as Jt, InputNode as K, ScalarPrimitive as Kt, createSchema as L, ArrowFunctionNode as Lt, createParameter as M, ParamsTypeNode as Mt, createParameterGroup as N, ExportNode as Nt, createImport as O, FunctionParamNode as Ot, createParamsType as P, FileNode as Pt, MediaType as Q, schemaTypes as Qt, createSource as R, CodeNode as Rt, createConst as S, StringSchemaNode as St, createFunction as T, UrlSchemaNode as Tt, ParserOptions as U, TypeNode as Ut, InferSchema as V, JSDocNode as Vt, Node as W, BaseNode as Wt, ResponseNode as X, mediaTypes as Xt, OperationNode as Y, isScalarPrimitive as Yt, HttpStatusCode as Z, nodeKinds as Zt, PrinterPartial as _, ScalarSchemaType as _t, TransformOptions as a, DatetimeSchemaNode as at, DistributiveOmit as b, SchemaType as bt, WalkOptions as c, FormatStringSchemaNode as ct, transform as d, Ipv6SchemaNode as dt, ParameterLocation as et, walk as f, NumberSchemaNode as ft, PrinterFactoryOptions as g, ScalarSchemaNode as gt, Printer as h, RefSchemaNode as ht, ParentOf as i, DateSchemaNode as it, createOutput as j, ParameterGroupNode as jt, createInput as k, FunctionParameterNode as kt, collect as l, IntersectionSchemaNode as lt, extractRefName as m, PrimitiveSchemaType as mt, CollectOptions as n, ArraySchemaNode as nt, Visitor as o, EnumSchemaNode as ot, RefMap as p, ObjectSchemaNode as pt, OutputNode as q, VisitorDepth as qt, CollectVisitor as r, ComplexSchemaType as rt, VisitorContext as s, EnumValueNode as st, AsyncVisitor as t, ParameterNode as tt, composeTransformers as u, Ipv4SchemaNode as ut, createPrinterFactory as v, SchemaNode as vt, createFile as w, UnionSchemaNode as wt, createArrowFunction as x, SpecialSchemaType as xt, definePrinter as y, SchemaNodeByType as yt, createType as z, ConstNode as zt };
|
|
2933
|
+
//# sourceMappingURL=visitor-DysNCWvh.d.ts.map
|