@kubb/renderer-jsx 5.0.0-beta.1 → 5.0.0-beta.100

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.
Files changed (47) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +135 -0
  3. package/dist/index.cjs +363 -17931
  4. package/dist/index.d.ts +719 -179
  5. package/dist/index.js +347 -17912
  6. package/dist/jsx-dev-runtime.cjs +3 -10
  7. package/dist/jsx-dev-runtime.d.ts +4 -9
  8. package/dist/jsx-dev-runtime.js +1 -9
  9. package/dist/jsx-runtime.cjs +24 -6
  10. package/dist/jsx-runtime.d.ts +83 -11
  11. package/dist/jsx-runtime.js +24 -7
  12. package/dist/rolldown-runtime-C0LytTxp.js +8 -0
  13. package/dist/rolldown-runtime-ClG-MNz_.cjs +13 -0
  14. package/dist/types-seYG0czS.d.ts +44 -0
  15. package/dist/types.d.ts +2 -2
  16. package/package.json +7 -42
  17. package/dist/chunk-Bb7HlUDG.js +0 -28
  18. package/dist/index.cjs.map +0 -1
  19. package/dist/index.js.map +0 -1
  20. package/dist/jsx-dev-runtime.cjs.map +0 -1
  21. package/dist/jsx-dev-runtime.js.map +0 -1
  22. package/dist/jsx-namespace-CNp0arTN.d.ts +0 -39
  23. package/dist/jsx-runtime-Cvu_ZYgL.js +0 -1448
  24. package/dist/jsx-runtime-Cvu_ZYgL.js.map +0 -1
  25. package/dist/jsx-runtime-DdmO3p0U.cjs +0 -1503
  26. package/dist/jsx-runtime-DdmO3p0U.cjs.map +0 -1
  27. package/dist/jsx-runtime.cjs.map +0 -1
  28. package/dist/jsx-runtime.js.map +0 -1
  29. package/dist/types-nAFMiWFw.d.ts +0 -168
  30. package/src/Renderer.ts +0 -184
  31. package/src/Runtime.tsx +0 -170
  32. package/src/components/Const.tsx +0 -72
  33. package/src/components/File.tsx +0 -186
  34. package/src/components/Function.tsx +0 -152
  35. package/src/components/Jsx.tsx +0 -34
  36. package/src/components/Root.tsx +0 -70
  37. package/src/components/Type.tsx +0 -66
  38. package/src/constants.ts +0 -28
  39. package/src/createRenderer.tsx +0 -93
  40. package/src/dom.ts +0 -105
  41. package/src/globals.ts +0 -34
  42. package/src/index.ts +0 -8
  43. package/src/jsx-dev-runtime.ts +0 -10
  44. package/src/jsx-namespace.d.ts +0 -52
  45. package/src/jsx-runtime.ts +0 -12
  46. package/src/types.ts +0 -207
  47. package/src/utils.ts +0 -267
package/dist/index.d.ts CHANGED
@@ -1,53 +1,54 @@
1
- import { n as __name } from "./chunk-Bb7HlUDG.js";
2
- import { a as JSDoc, h as KubbReactNode, m as KubbReactElement, o as Key } from "./types-nAFMiWFw.js";
3
- import { ExportNode, FileNode, ImportNode, SourceNode } from "@kubb/ast";
4
- import * as _$react from "react";
5
-
6
- //#region ../../internals/utils/src/context.d.ts
7
- /**
8
- * Context type that carries type information about its value
9
- * This is a branded symbol type that enables type-safe context usage
10
- */
11
- type Context<T> = symbol & {
12
- readonly __type: T;
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ import { i as KubbReactNode, n as Key, r as KubbReactElement, t as JSDoc } from "./types-seYG0czS.js";
3
+ import { ast } from "@kubb/kit";
4
+ //#region src/components/md/Callout.d.ts
5
+ declare const CALLOUT_LABEL: {
6
+ readonly tip: "TIP";
7
+ readonly note: "NOTE";
8
+ readonly important: "IMPORTANT";
9
+ readonly warning: "WARNING";
10
+ readonly caution: "CAUTION";
11
+ };
12
+ type CalloutType = keyof typeof CALLOUT_LABEL;
13
+ type Props$7 = {
14
+ key?: Key;
15
+ /**
16
+ * Callout kind. Maps to the uppercase label inside the `> [!TYPE]` marker.
17
+ */
18
+ type: CalloutType;
19
+ /**
20
+ * Optional title rendered on the same line as the marker.
21
+ */
22
+ title?: string | null;
23
+ /**
24
+ * Body text. Each line is quoted with `> ` so multi-line content stays
25
+ * inside the callout block.
26
+ */
27
+ children: string;
13
28
  };
14
29
  /**
15
- * Provides a value to descendant components (Vue 3 style)
30
+ * Renders a GitHub-style alert callout using the `> [!TYPE]` blockquote syntax.
16
31
  *
17
- * @example
18
- * ```ts
19
- * const ThemeKey = Symbol('theme')
20
- * provide(ThemeKey, { color: 'blue' })
21
- * ```
22
- */
23
- declare function provide<T>(key: symbol | Context<T>, value: T): void;
24
- /**
25
- * Injects a value provided by an ancestor component (Vue 3 style)
32
+ * Emits a `<File.Source>` block containing `> [!TYPE] Title` followed by the
33
+ * body with every line prefixed by `> `.
26
34
  *
27
35
  * @example
28
- * ```ts
29
- * const theme = inject(ThemeKey, { color: 'default' })
30
- * ```
31
- */
32
- declare function inject<T>(key: symbol | Context<T>, defaultValue?: T): T;
33
- /**
34
- * Removes a provided value from the context stack (for cleanup)
35
- * @internal
36
- */
37
- declare function unprovide<T>(key: symbol | Context<T>): void;
38
- /**
39
- * Creates a context key with a default value (React-style compatibility)
36
+ * ```tsx
37
+ * <Callout type="tip">Run `kubb start --watch` to keep the generator hot.</Callout>
38
+ * // > [!TIP]
39
+ * // > Run `kubb start --watch` to keep the generator hot.
40
40
  *
41
- * @example
42
- * ```ts
43
- * const ThemeContext = createContext({ color: 'blue' })
44
- * // ThemeContext is now typed as Context<{ color: string }>
45
- * const theme = useContext(ThemeContext) // theme is { color: string }
41
+ * <Callout type="warning" title="Heads up">Breaking change in v6.</Callout>
42
+ * // > [!WARNING] Heads up
43
+ * // > Breaking change in v6.
46
44
  * ```
47
45
  */
48
- declare function createContext<T>(defaultValue: T): Context<T>;
46
+ declare function Callout({ type, title, children }: Props$7): KubbReactElement;
47
+ declare namespace Callout {
48
+ var displayName: string;
49
+ }
49
50
  //#endregion
50
- //#region src/components/Const.d.ts
51
+ //#region src/components/js/Const.d.ts
51
52
  type ConstProps = {
52
53
  key?: Key;
53
54
  /**
@@ -61,30 +62,28 @@ type ConstProps = {
61
62
  * Emit the `export` keyword before the `const` declaration.
62
63
  * - `true` generates `export const name = …`
63
64
  * - `false` generates `const name = …`
64
- * @default false
65
65
  */
66
- export?: boolean;
66
+ export?: boolean | null;
67
67
  /**
68
68
  * TypeScript type annotation for the constant, written verbatim after `const name:`.
69
69
  *
70
70
  * @example
71
71
  * `type: 'Pet'` → `const pet: Pet = …`
72
72
  */
73
- type?: string;
73
+ type?: string | null;
74
74
  /**
75
75
  * JSDoc block to prepend to the constant declaration.
76
76
  * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
77
77
  */
78
- JSDoc?: JSDoc;
78
+ JSDoc?: JSDoc | null;
79
79
  /**
80
- * Append `as const` after the initialiser, enabling TypeScript const assertions.
80
+ * Append `as const` after the initializer, enabling TypeScript const assertions.
81
81
  * - `true` generates `const name = … as const`
82
82
  * - `false` generates `const name = …`
83
- * @default false
84
83
  */
85
- asConst?: boolean;
84
+ asConst?: boolean | null;
86
85
  /**
87
- * Child nodes rendered as the initialiser expression of the constant.
86
+ * Child nodes rendered as the initializer expression of the constant.
88
87
  */
89
88
  children?: KubbReactNode;
90
89
  };
@@ -106,10 +105,7 @@ type ConstProps = {
106
105
  * </Const>
107
106
  * ```
108
107
  */
109
- declare function Const({
110
- children,
111
- ...props
112
- }: ConstProps): KubbReactElement;
108
+ declare function Const({ children, ...props }: ConstProps): KubbReactElement;
113
109
  declare namespace Const {
114
110
  var displayName: string;
115
111
  }
@@ -138,26 +134,34 @@ type BasePropsWithoutBaseName = {
138
134
  baseName?: never;
139
135
  /**
140
136
  * Fully qualified path to the generated file.
141
- * Optional when `baseName` is omitted the component renders its children inline.
137
+ * Optional when `baseName` is omitted, the component renders its children inline.
142
138
  */
143
- path?: string;
139
+ path?: string | null;
144
140
  };
145
141
  type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
146
- type Props$2<TMeta> = BaseProps & {
142
+ type Props$6<TMeta> = BaseProps & {
147
143
  key?: Key;
148
144
  /**
149
- * Arbitrary metadata attached to the file node.
150
- * Used by plugins for barrel generation and custom post-processing.
145
+ * Arbitrary metadata attached to the file node for plugins to read.
151
146
  */
152
- meta?: TMeta;
147
+ meta?: TMeta | null;
153
148
  /**
154
149
  * Text prepended to the generated file content before any source blocks.
150
+ * Accepts `null` so `resolver.default.banner()` results can be passed directly.
155
151
  */
156
- banner?: string;
152
+ banner?: string | null;
157
153
  /**
158
154
  * Text appended to the generated file content after all source blocks.
155
+ * Accepts `null` so `resolver.default.footer()` results can be passed directly.
159
156
  */
160
- footer?: string;
157
+ footer?: string | null;
158
+ /**
159
+ * Absolute on-disk path to copy verbatim into the output, bypassing the parser. Use to emit a
160
+ * real source file shipped inside a package (a template) into the generated folder. Only
161
+ * `banner`/`footer` are applied around the copied content; child source blocks are ignored for
162
+ * output but still drive barrel generation.
163
+ */
164
+ copy?: string | null;
161
165
  /**
162
166
  * Child nodes rendered as the content of this file (source blocks, imports, exports).
163
167
  */
@@ -179,17 +183,14 @@ type Props$2<TMeta> = BaseProps & {
179
183
  * </File>
180
184
  * ```
181
185
  */
182
- declare function File<TMeta extends object = object>({
183
- children,
184
- ...props
185
- }: Props$2<TMeta>): KubbReactElement;
186
+ declare function File<TMeta extends object = object>({ children, ...props }: Props$6<TMeta>): KubbReactElement;
186
187
  declare namespace File {
187
188
  var displayName: string;
188
189
  var Export: typeof FileExport;
189
190
  var Import: typeof FileImport;
190
191
  var Source: typeof FileSource;
191
192
  }
192
- type FileSourceProps = Omit<SourceNode, 'kind' | 'value'> & {
193
+ type FileSourceProps = Omit<ast.SourceNode, 'kind' | 'value'> & {
193
194
  key?: Key;
194
195
  /**
195
196
  * Child nodes rendered as the source content of this block.
@@ -199,8 +200,8 @@ type FileSourceProps = Omit<SourceNode, 'kind' | 'value'> & {
199
200
  /**
200
201
  * Marks a block of source text to be associated with the enclosing {@link File}.
201
202
  *
202
- * Children are treated as the source string. When `isExportable` is `true` the
203
- * `name` is used for deduplication and barrel generation.
203
+ * Children are treated as the source string. `isExportable` prepends the `export` keyword,
204
+ * `isIndexable` includes the source in barrel/index generation, and `name` keys deduplication.
204
205
  *
205
206
  * @example Exportable, indexable source block
206
207
  * ```tsx
@@ -216,14 +217,11 @@ type FileSourceProps = Omit<SourceNode, 'kind' | 'value'> & {
216
217
  * </File.Source>
217
218
  * ```
218
219
  */
219
- declare function FileSource({
220
- children,
221
- ...props
222
- }: FileSourceProps): KubbReactElement;
220
+ declare function FileSource({ children, ...props }: FileSourceProps): KubbReactElement;
223
221
  declare namespace FileSource {
224
222
  var displayName: string;
225
223
  }
226
- type FileExportProps = Omit<ExportNode, 'kind'> & {
224
+ type FileExportProps = Omit<ast.ExportNode, 'kind'> & {
227
225
  key?: Key;
228
226
  };
229
227
  /**
@@ -247,7 +245,7 @@ declare function FileExport(props: FileExportProps): KubbReactElement;
247
245
  declare namespace FileExport {
248
246
  var displayName: string;
249
247
  }
250
- type FileImportProps = Omit<ImportNode, 'kind'> & {
248
+ type FileImportProps = Omit<ast.ImportNode, 'kind'> & {
251
249
  key?: Key;
252
250
  };
253
251
  /**
@@ -278,8 +276,41 @@ declare namespace FileImport {
278
276
  var displayName: string;
279
277
  }
280
278
  //#endregion
281
- //#region src/components/Function.d.ts
282
- type Props$1 = {
279
+ //#region src/components/md/Frontmatter.d.ts
280
+ type Props$5 = {
281
+ key?: Key;
282
+ /**
283
+ * Plain object serialized as YAML between `---` fences.
284
+ *
285
+ * @example
286
+ * `{ title: 'Pets', layout: 'doc' }`
287
+ */
288
+ data: Record<string, unknown>;
289
+ };
290
+ /**
291
+ * Emits a YAML frontmatter envelope at the top of a generated markdown file.
292
+ *
293
+ * Renders a `<File.Source>` block containing `---\n<yaml>\n---`. Place it as
294
+ * the first child of `<File>` so it appears at the top of the output. Pair with
295
+ * `parserMd` to write `.md` files whose frontmatter downstream tooling can read.
296
+ *
297
+ * @example Page frontmatter at the top of a generated markdown file
298
+ * ```tsx
299
+ * <File baseName="pets.md" path="src/pets.md">
300
+ * <Frontmatter data={{ title: 'Pets', layout: 'doc' }} />
301
+ * <File.Source>
302
+ * {'# Pets\n\nList of pets.'}
303
+ * </File.Source>
304
+ * </File>
305
+ * ```
306
+ */
307
+ declare function Frontmatter({ data }: Props$5): KubbReactElement;
308
+ declare namespace Frontmatter {
309
+ var displayName: string;
310
+ }
311
+ //#endregion
312
+ //#region src/components/js/Function.d.ts
313
+ type Props$4 = {
283
314
  key?: Key;
284
315
  /**
285
316
  * Identifier of the generated function declaration.
@@ -291,30 +322,27 @@ type Props$1 = {
291
322
  /**
292
323
  * Emit `default` after the `export` keyword, making this the module's default export.
293
324
  * Requires `export` to also be `true`.
294
- * @default false
295
325
  */
296
- default?: boolean;
326
+ default?: boolean | null;
297
327
  /**
298
328
  * Parameter list written verbatim between the function's parentheses.
299
329
  *
300
330
  * @example
301
331
  * `params: 'petId: string, options?: RequestOptions'`
302
332
  */
303
- params?: string;
333
+ params?: string | null;
304
334
  /**
305
335
  * Emit the `export` keyword before the function declaration.
306
336
  * - `true` generates `export function name(…) { … }`
307
337
  * - `false` generates `function name(…) { … }`
308
- * @default false
309
338
  */
310
- export?: boolean;
339
+ export?: boolean | null;
311
340
  /**
312
341
  * Emit the `async` keyword, making this an async function.
313
342
  * The return type is automatically wrapped in `Promise<returnType>` when both
314
343
  * `async` and `returnType` are set.
315
- * @default false
316
344
  */
317
- async?: boolean;
345
+ async?: boolean | null;
318
346
  /**
319
347
  * TypeScript generic type parameters written verbatim between `<` and `>`.
320
348
  * Pass an array to emit multiple parameters separated by commas.
@@ -325,7 +353,7 @@ type Props$1 = {
325
353
  * @example Multiple generics
326
354
  * `generics: ['TData', 'TError = unknown']`
327
355
  */
328
- generics?: string | string[];
356
+ generics?: string | Array<string> | null;
329
357
  /**
330
358
  * TypeScript return type annotation written verbatim after `:`.
331
359
  * When `async` is `true`, the value is automatically wrapped in `Promise<…>`.
@@ -333,12 +361,12 @@ type Props$1 = {
333
361
  * @example
334
362
  * `returnType: 'Pet'`
335
363
  */
336
- returnType?: string;
364
+ returnType?: string | null;
337
365
  /**
338
366
  * JSDoc block to prepend to the function declaration.
339
367
  * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
340
368
  */
341
- JSDoc?: JSDoc;
369
+ JSDoc?: JSDoc | null;
342
370
  /**
343
371
  * Child nodes rendered as the body of the function.
344
372
  */
@@ -357,22 +385,18 @@ type Props$1 = {
357
385
  * // }
358
386
  * ```
359
387
  */
360
- declare function Function({
361
- children,
362
- ...props
363
- }: Props$1): KubbReactElement;
388
+ declare function Function({ children, ...props }: Props$4): KubbReactElement;
364
389
  declare namespace Function {
365
390
  var displayName: string;
366
391
  var Arrow: typeof ArrowFunction;
367
392
  }
368
- type ArrowFunctionProps = Props$1 & {
393
+ type ArrowFunctionProps = Props$4 & {
369
394
  /**
370
395
  * Render the arrow function as a single-line expression (no braces around the body).
371
396
  * - `true` generates `const name = (…) => expression`
372
397
  * - `false` generates `const name = (…) => { … }`
373
- * @default false
374
398
  */
375
- singleLine?: boolean;
399
+ singleLine?: boolean | null;
376
400
  };
377
401
  /**
378
402
  * Generates an arrow function expression assigned to a `const`.
@@ -387,19 +411,48 @@ type ArrowFunctionProps = Props$1 & {
387
411
  * // export const double = (n: number): number => n * 2
388
412
  * ```
389
413
  */
390
- declare function ArrowFunction({
391
- children,
392
- ...props
393
- }: ArrowFunctionProps): _$react.JSX.Element;
414
+ declare function ArrowFunction({ children, ...props }: ArrowFunctionProps): any;
394
415
  declare namespace ArrowFunction {
395
416
  var displayName: string;
396
417
  }
397
418
  //#endregion
398
- //#region src/components/Jsx.d.ts
399
- type Props = {
419
+ //#region src/components/md/Heading.d.ts
420
+ type Level = 1 | 2 | 3 | 4 | 5 | 6;
421
+ type Props$3 = {
422
+ key?: Key;
423
+ /**
424
+ * Heading depth, `1` through `6`. Matches the number of `#` characters
425
+ * prefixed to the heading text.
426
+ */
427
+ level: Level;
428
+ /**
429
+ * Heading text. Inline markdown (links, emphasis) is passed through verbatim.
430
+ */
431
+ children: string;
432
+ };
433
+ /**
434
+ * Renders an ATX-style markdown heading.
435
+ *
436
+ * Emits a `<File.Source>` block containing `${'#'.repeat(level)} ${children}`.
437
+ * Use inside a `<File>` rendered by `parserMd`.
438
+ *
439
+ * @example
440
+ * ```tsx
441
+ * <Heading level={2}>Installation</Heading>
442
+ * // ## Installation
443
+ * ```
444
+ */
445
+ declare function Heading({ level, children }: Props$3): KubbReactElement;
446
+ declare namespace Heading {
447
+ var displayName: string;
448
+ }
449
+ //#endregion
450
+ //#region src/components/jsx/Jsx.d.ts
451
+ type Props$2 = {
400
452
  /**
401
- * Raw JSX string to embed verbatim in the generated code.
402
- * Supports JSX fragments (`<>…</>`), elements, and any valid JSX syntax.
453
+ * Raw JSX string embedded verbatim in the generated code, including
454
+ * fragments (`<>…</>`).
455
+ *
403
456
  * @example
404
457
  * ```tsx
405
458
  * <Jsx>{'<>\n <a href={href}>Open</a>\n</>'}</Jsx>
@@ -410,10 +463,10 @@ type Props = {
410
463
  /**
411
464
  * Embeds a raw JSX string verbatim in the generated source code.
412
465
  *
413
- * Use this component when you need to include JSX markup (including fragments
414
- * `<>…</>`) in the body of a generated function or component. The `children`
415
- * prop must be a plain string expression attributes that reference runtime
416
- * values should be written as template literals.
466
+ * Use this component to include JSX markup (including fragments `<>…</>`) in the
467
+ * body of a generated function or component. The `children` prop must be a plain
468
+ * string. Write expression attributes that reference runtime values as template
469
+ * literals.
417
470
  *
418
471
  * @example
419
472
  * ```tsx
@@ -422,46 +475,75 @@ type Props = {
422
475
  * </Function>
423
476
  * ```
424
477
  */
425
- declare function Jsx({
426
- children
427
- }: Props): KubbReactElement;
478
+ declare function Jsx({ children }: Props$2): KubbReactElement;
428
479
  declare namespace Jsx {
429
480
  var displayName: string;
430
481
  }
431
482
  //#endregion
432
- //#region src/components/Root.d.ts
433
- type RootProps = {
483
+ //#region src/components/md/List.d.ts
484
+ type Props$1 = {
485
+ key?: Key;
434
486
  /**
435
- * Callback invoked to unmount the entire renderer tree.
436
- * Called with an `Error` when the exit is caused by a render error,
437
- * or with `undefined` for a clean shutdown.
487
+ * When `true`, emits a numbered list (`1. …`). When `false` or omitted,
488
+ * emits a bullet list (`- …`).
489
+ *
490
+ * @default false
438
491
  */
439
- onExit: (error?: Error) => void;
492
+ ordered?: boolean | null;
440
493
  /**
441
- * Callback invoked whenever a render error is caught by the error boundary.
442
- * Use this to propagate errors up to the caller of {@link createRenderer}.
494
+ * One entry per line. Inline markdown is passed through verbatim.
443
495
  */
444
- onError: (error: Error) => void;
496
+ items: ReadonlyArray<string>;
497
+ };
498
+ /**
499
+ * Renders a markdown list.
500
+ *
501
+ * Emits a `<File.Source>` block containing one entry per line, prefixed with
502
+ * `1.` / `2.` … when `ordered`, or `-` otherwise.
503
+ *
504
+ * @example
505
+ * ```tsx
506
+ * <List items={['Add the parser', 'Render the page']} />
507
+ * // - Add the parser
508
+ * // - Render the page
509
+ *
510
+ * <List ordered items={['First', 'Second']} />
511
+ * // 1. First
512
+ * // 2. Second
513
+ * ```
514
+ */
515
+ declare function List({ ordered, items }: Props$1): KubbReactElement;
516
+ declare namespace List {
517
+ var displayName: string;
518
+ }
519
+ //#endregion
520
+ //#region src/components/md/Paragraph.d.ts
521
+ type Props = {
522
+ key?: Key;
445
523
  /**
446
- * Child nodes rendered inside the error boundary.
524
+ * Paragraph text. Inline markdown (links, emphasis, code spans) is passed
525
+ * through verbatim.
447
526
  */
448
- children?: KubbReactNode;
527
+ children: string;
449
528
  };
450
529
  /**
451
- * Root component for the Kubb renderer tree.
530
+ * Renders a markdown paragraph.
452
531
  *
453
- * Wraps all children in an `ErrorBoundary` so that render errors are caught
454
- * and forwarded to `onError` rather than crashing the process.
532
+ * Emits a `<File.Source>` block containing the text as-is. Paragraphs are
533
+ * separated from surrounding blocks by blank lines via the parser's source
534
+ * joining.
535
+ *
536
+ * @example
537
+ * ```tsx
538
+ * <Paragraph>{'A pet object with `id` and `name` fields.'}</Paragraph>
539
+ * ```
455
540
  */
456
- declare function Root({
457
- onError,
458
- children
459
- }: RootProps): KubbReactElement;
460
- declare namespace Root {
541
+ declare function Paragraph({ children }: Props): KubbReactElement;
542
+ declare namespace Paragraph {
461
543
  var displayName: string;
462
544
  }
463
545
  //#endregion
464
- //#region src/components/Type.d.ts
546
+ //#region src/components/js/Type.d.ts
465
547
  type TypeProps = {
466
548
  key?: Key;
467
549
  /**
@@ -476,14 +558,13 @@ type TypeProps = {
476
558
  * Emit the `export` keyword before the type alias declaration.
477
559
  * - `true` generates `export type Name = …`
478
560
  * - `false` generates `type Name = …`
479
- * @default false
480
561
  */
481
- export?: boolean;
562
+ export?: boolean | null;
482
563
  /**
483
564
  * JSDoc block to prepend to the type alias declaration.
484
565
  * Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
485
566
  */
486
- JSDoc?: JSDoc;
567
+ JSDoc?: JSDoc | null;
487
568
  /**
488
569
  * Child nodes rendered as the type expression on the right-hand side of the alias.
489
570
  */
@@ -492,7 +573,7 @@ type TypeProps = {
492
573
  /**
493
574
  * Generates a TypeScript type alias declaration.
494
575
  *
495
- * Throws if `name` does not start with an uppercase letter TypeScript type aliases
576
+ * Throws if `name` does not start with an uppercase letter. TypeScript type aliases
496
577
  * should follow PascalCase naming conventions.
497
578
  *
498
579
  * @example Simple exported type alias
@@ -510,87 +591,546 @@ type TypeProps = {
510
591
  * </Type>
511
592
  * ```
512
593
  */
513
- declare function Type({
514
- children,
515
- ...props
516
- }: TypeProps): KubbReactElement;
594
+ declare function Type({ children, ...props }: TypeProps): KubbReactElement;
517
595
  declare namespace Type {
518
596
  var displayName: string;
519
597
  }
520
598
  //#endregion
521
- //#region src/createRenderer.d.ts
522
- type Options = {
599
+ //#region ../ast/src/nodes/base.d.ts
600
+ /**
601
+ * `kind` values used by AST nodes.
602
+ *
603
+ * @example
604
+ * ```ts
605
+ * const kind: NodeKind = 'Schema'
606
+ * ```
607
+ */
608
+ type NodeKind = 'Input' | 'Output' | 'Operation' | 'Schema' | 'Property' | 'Parameter' | 'Response' | 'RequestBody' | 'Content' | 'Type' | 'File' | 'Import' | 'Export' | 'Source' | 'Const' | 'Function' | 'ArrowFunction' | 'Text' | 'Break' | 'Jsx';
609
+ /**
610
+ * Base shape shared by all AST nodes.
611
+ *
612
+ * @example
613
+ * ```ts
614
+ * const base: BaseNode = { kind: 'Input' }
615
+ * ```
616
+ */
617
+ type BaseNode = {
618
+ /**
619
+ * Node discriminator.
620
+ */
621
+ kind: NodeKind;
622
+ };
623
+ //#endregion
624
+ //#region ../ast/src/nodes/code.d.ts
625
+ /**
626
+ * JSDoc documentation metadata attached to code declarations.
627
+ */
628
+ type JSDocNode = {
523
629
  /**
524
- * Print each render result to the console for debugging.
525
- * Useful when diagnosing output differences between renders.
526
- * @default false
630
+ * JSDoc comment lines. `undefined` entries are filtered out during rendering.
631
+ *
632
+ * @example
633
+ * ```ts
634
+ * ['@description A pet resource', '@deprecated']
635
+ * ```
527
636
  */
528
- debug?: boolean;
637
+ comments?: Array<string | undefined>;
529
638
  };
530
639
  /**
531
- * The renderer instance returned by {@link createRenderer}.
640
+ * AST node representing a TypeScript `const` declaration.
641
+ *
642
+ * Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.
643
+ * The `children` prop of the component is represented as `nodes`.
644
+ *
645
+ * @example
646
+ * ```ts
647
+ * createConst({ name: 'pet', export: true, asConst: true })
648
+ * // export const pet = ... as const
649
+ * ```
532
650
  */
533
- type Renderer = {
651
+ type ConstNode = BaseNode & {
652
+ kind: 'Const';
653
+ /**
654
+ * Name of the constant declaration.
655
+ */
656
+ name: string;
657
+ /**
658
+ * Whether the declaration should be exported.
659
+ */
660
+ export?: boolean | null;
661
+ /**
662
+ * Explicit type annotation.
663
+ *
664
+ * @example Type reference
665
+ * `'Pet'`
666
+ */
667
+ type?: string | null;
534
668
  /**
535
- * Render a JSX element tree and collect the resulting {@link FileNode} entries.
536
- * Resolves once all synchronous render work (including React's flush) is done.
669
+ * JSDoc documentation metadata.
537
670
  */
538
- render(Element: KubbReactElement): Promise<void>;
671
+ JSDoc?: JSDocNode | null;
539
672
  /**
540
- * Tear down the renderer and release all React resources.
541
- * Pass an `Error` to signal an abnormal shutdown.
673
+ * Whether to append `as const` to the declaration.
542
674
  */
543
- unmount(error?: Error | number | null): void;
675
+ asConst?: boolean | null;
544
676
  /**
545
- * The {@link FileNode} entries collected from the most recent `render` call.
677
+ * Child nodes representing the value of the constant (children of the `Const` component).
678
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
546
679
  */
547
- files: Array<FileNode>;
680
+ nodes?: Array<CodeNode>;
548
681
  };
549
682
  /**
550
- * Create a Kubb JSX renderer.
683
+ * AST node representing a TypeScript `type` alias declaration.
551
684
  *
552
- * The renderer converts a React JSX element tree — built from the components in this
553
- * package into an array of {@link FileNode} entries representing the generated files.
685
+ * Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.
686
+ * The `children` prop of the component is represented as `nodes`.
554
687
  *
555
- * @example Basic usage
688
+ * @example
556
689
  * ```ts
557
- * import { createRenderer, File } from '@kubb/renderer-jsx'
558
- *
559
- * const renderer = createRenderer()
560
- * await renderer.render(
561
- * <File baseName="pet.ts" path="src/models/pet.ts">
562
- * <File.Source name="Pet" isExportable isIndexable>
563
- * {`export type Pet = { id: number; name: string }`}
564
- * </File.Source>
565
- * </File>
566
- * )
567
- * console.log(renderer.files) // [FileNode]
568
- * renderer.unmount()
690
+ * createType({ name: 'Pet', export: true })
691
+ * // export type Pet = ...
569
692
  * ```
570
693
  */
571
- declare function createRenderer(options?: Options): Renderer;
694
+ type TypeNode = BaseNode & {
695
+ kind: 'Type';
696
+ /**
697
+ * Name of the type alias.
698
+ */
699
+ name: string;
700
+ /**
701
+ * Whether the declaration should be exported.
702
+ */
703
+ export?: boolean | null;
704
+ /**
705
+ * JSDoc documentation metadata.
706
+ */
707
+ JSDoc?: JSDocNode | null;
708
+ /**
709
+ * Child nodes representing the type body (children of the `Type` component).
710
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
711
+ */
712
+ nodes?: Array<CodeNode>;
713
+ };
572
714
  /**
573
- * A renderer factory for generators that produce JSX output.
715
+ * AST node representing a TypeScript `function` declaration.
574
716
  *
575
- * Pass this as the `renderer` property of a `defineGenerator` call so that
576
- * core can render the JSX element tree returned by your generator methods
577
- * without a hard dependency on `@kubb/renderer-jsx`.
717
+ * Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.
718
+ * The `children` prop of the component is represented as `nodes`.
578
719
  *
579
720
  * @example
580
721
  * ```ts
581
- * import { jsxRenderer } from '@kubb/renderer-jsx'
722
+ * createFunction({ name: 'getPet', export: true, async: true, returnType: 'Pet' })
723
+ * // export async function getPet(): Promise<Pet> { ... }
724
+ * ```
725
+ */
726
+ type FunctionNode = BaseNode & {
727
+ kind: 'Function';
728
+ /**
729
+ * Name of the function.
730
+ */
731
+ name: string;
732
+ /**
733
+ * Whether the function is a default export.
734
+ */
735
+ default?: boolean | null;
736
+ /**
737
+ * Function parameter list as a pre-rendered string, written verbatim between the parentheses.
738
+ *
739
+ * @example
740
+ * `'id: string, config: Config = {}'`
741
+ */
742
+ params?: string | null;
743
+ /**
744
+ * Whether the function should be exported.
745
+ */
746
+ export?: boolean | null;
747
+ /**
748
+ * Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
749
+ */
750
+ async?: boolean | null;
751
+ /**
752
+ * TypeScript generic type parameters.
753
+ *
754
+ * @example Constrained generics
755
+ * `['T', 'U extends string']`
756
+ */
757
+ generics?: string | Array<string> | null;
758
+ /**
759
+ * Return type annotation.
760
+ *
761
+ * @example Type reference
762
+ * `'Pet'`
763
+ */
764
+ returnType?: string | null;
765
+ /**
766
+ * JSDoc documentation metadata.
767
+ */
768
+ JSDoc?: JSDocNode | null;
769
+ /**
770
+ * Child nodes representing the function body (children of the `Function` component).
771
+ * Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
772
+ */
773
+ nodes?: Array<CodeNode>;
774
+ };
775
+ /**
776
+ * AST node representing a TypeScript arrow function (`const name = () => { ... }`).
777
+ *
778
+ * Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.
779
+ * The `children` prop of the component is represented as `nodes`.
780
+ *
781
+ * @example
782
+ * ```ts
783
+ * createArrowFunction({ name: 'getPet', export: true, singleLine: true })
784
+ * // export const getPet = () => ...
785
+ * ```
786
+ */
787
+ type ArrowFunctionNode = Omit<FunctionNode, 'kind'> & {
788
+ kind: 'ArrowFunction';
789
+ /**
790
+ * Render the arrow function body as a single-line expression.
791
+ */
792
+ singleLine?: boolean | null;
793
+ };
794
+ /**
795
+ * AST node representing a raw text/string fragment in the source output.
796
+ *
797
+ * Used instead of bare `string` values so that all entries in `nodes` arrays
798
+ * are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.
799
+ *
800
+ * @example
801
+ * ```ts
802
+ * createText('return fetch(id)')
803
+ * // { kind: 'Text', value: 'return fetch(id)' }
804
+ * ```
805
+ */
806
+ type TextNode = BaseNode & {
807
+ kind: 'Text';
808
+ /**
809
+ * The raw string content.
810
+ */
811
+ value: string;
812
+ };
813
+ /**
814
+ * AST node representing a blank line in the source output.
815
+ *
816
+ * Corresponds to `<br/>` in JSX components. `printNodes` turns a `Break` between two
817
+ * statements into one blank line. Consecutive breaks, and breaks at the start or end of
818
+ * the list, are folded away, so a `Break` never produces more than one blank line.
819
+ *
820
+ * @example
821
+ * ```ts
822
+ * createBreak()
823
+ * // { kind: 'Break' }
824
+ * ```
825
+ */
826
+ type BreakNode = BaseNode & {
827
+ kind: 'Break';
828
+ };
829
+ /**
830
+ * AST node representing a raw JSX fragment in the source output.
831
+ *
832
+ * Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup
833
+ * (including fragments `<>…</>`) directly in generated code.
834
+ *
835
+ * @example
836
+ * ```ts
837
+ * createJsx('<>\n <a href={href}>Open</a>\n</>')
838
+ * // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
839
+ * ```
840
+ */
841
+ type JsxNode = BaseNode & {
842
+ kind: 'Jsx';
843
+ /**
844
+ * The raw JSX string content.
845
+ */
846
+ value: string;
847
+ };
848
+ /**
849
+ * Union of all code-generation AST nodes.
850
+ *
851
+ * These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as
852
+ * structured children in {@link SourceNode.nodes}.
853
+ */
854
+ type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
855
+ //#endregion
856
+ //#region ../ast/src/nodes/file.d.ts
857
+ /**
858
+ * Supported file extensions.
859
+ */
860
+ type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
861
+ type ImportName = string | Array<string | {
862
+ propertyName: string;
863
+ name?: string;
864
+ }>;
865
+ /**
866
+ * Represents a language-agnostic import/dependency declaration.
867
+ *
868
+ * @example Named import (TypeScript: `import { useState } from 'react'`)
869
+ * ```ts
870
+ * createImport({ name: ['useState'], path: 'react' })
871
+ * ```
872
+ *
873
+ * @example Default import (TypeScript: `import React from 'react'`)
874
+ * ```ts
875
+ * createImport({ name: 'React', path: 'react' })
876
+ * ```
877
+ *
878
+ * @example Type-only import (TypeScript: `import type { FC } from 'react'`)
879
+ * ```ts
880
+ * createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
881
+ * ```
882
+ *
883
+ * @example Namespace import (TypeScript: `import * as React from 'react'`)
884
+ * ```ts
885
+ * createImport({ name: 'React', path: 'react', isNameSpace: true })
886
+ * ```
887
+ */
888
+ type ImportNode = BaseNode & {
889
+ kind: 'Import';
890
+ /**
891
+ * Import name(s) to be used.
892
+ *
893
+ * @example Named imports
894
+ * `['useState']`
895
+ *
896
+ * @example Default import
897
+ * `'React'`
898
+ */
899
+ name: ImportName;
900
+ /**
901
+ * Path for the import.
902
+ *
903
+ * @example
904
+ * `'@kubb/core'`
905
+ */
906
+ path: string;
907
+ /**
908
+ * Add a type-only import prefix.
909
+ * - `true` generates `import type { Type } from './path'`
910
+ * - `false` generates `import { Type } from './path'`
911
+ */
912
+ isTypeOnly?: boolean | null;
913
+ /**
914
+ * Import the entire module as a namespace.
915
+ * - `true` generates `import * as Name from './path'`
916
+ * - `false` generates a standard import
917
+ */
918
+ isNameSpace?: boolean | null;
919
+ /**
920
+ * When set, the import path is resolved relative to this root.
921
+ */
922
+ root?: string | null;
923
+ };
924
+ /**
925
+ * Represents a language-agnostic export/public API declaration.
926
+ *
927
+ * @example Named export (TypeScript: `export { Pets } from './Pets'`)
928
+ * ```ts
929
+ * createExport({ name: ['Pets'], path: './Pets' })
930
+ * ```
931
+ *
932
+ * @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
933
+ * ```ts
934
+ * createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })
935
+ * ```
936
+ *
937
+ * @example Wildcard export (TypeScript: `export * from './utils'`)
938
+ * ```ts
939
+ * createExport({ path: './utils' })
940
+ * ```
941
+ *
942
+ * @example Namespace alias (TypeScript: `export * as utils from './utils'`)
943
+ * ```ts
944
+ * createExport({ name: 'utils', path: './utils', asAlias: true })
945
+ * ```
946
+ */
947
+ type ExportNode = BaseNode & {
948
+ kind: 'Export';
949
+ /**
950
+ * Export name(s) to be used. When omitted, generates a wildcard export.
951
+ *
952
+ * @example Named exports
953
+ * `['useState']`
954
+ *
955
+ * @example Single export
956
+ * `'React'`
957
+ */
958
+ name?: string | Array<string> | null;
959
+ /**
960
+ * Path for the export.
961
+ *
962
+ * @example
963
+ * `'@kubb/core'`
964
+ */
965
+ path: string;
966
+ /**
967
+ * Add a type-only export prefix.
968
+ * - `true` generates `export type { Type } from './path'`
969
+ * - `false` generates `export { Type } from './path'`
970
+ */
971
+ isTypeOnly?: boolean | null;
972
+ /**
973
+ * Export as an aliased namespace.
974
+ * - `true` generates `export * as aliasName from './path'`
975
+ * - `false` generates a standard export
976
+ */
977
+ asAlias?: boolean | null;
978
+ };
979
+ /**
980
+ * Represents a fragment of source code within a file.
981
+ *
982
+ * @example Named exportable source
983
+ * ```ts
984
+ * createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })
985
+ * ```
986
+ *
987
+ * @example Inline unnamed code block
988
+ * ```ts
989
+ * createSource({ nodes: [createText('const x = 1')] })
990
+ * ```
991
+ */
992
+ type SourceNode = BaseNode & {
993
+ kind: 'Source';
994
+ /**
995
+ * Optional name identifying this source (used for deduplication and barrel generation).
996
+ */
997
+ name?: string | null;
998
+ /**
999
+ * Mark this source as a type-only export.
1000
+ */
1001
+ isTypeOnly?: boolean | null;
1002
+ /**
1003
+ * Include the `export` keyword in the generated source.
1004
+ */
1005
+ isExportable?: boolean | null;
1006
+ /**
1007
+ * Include this source in barrel/index file generation.
1008
+ */
1009
+ isIndexable?: boolean | null;
1010
+ /**
1011
+ * Child nodes that make up this source fragment, in DOM order.
1012
+ * Use a {@link TextNode} for raw string content.
1013
+ */
1014
+ nodes?: Array<CodeNode>;
1015
+ };
1016
+ /**
1017
+ * Represents a fully resolved file in the AST.
1018
+ *
1019
+ * Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input
1020
+ * and deduplicates `imports`, `exports`, and `sources`.
1021
+ *
1022
+ * @example
1023
+ * ```ts
1024
+ * const file = createFile({
1025
+ * baseName: 'petStore.ts',
1026
+ * path: 'src/models/petStore.ts',
1027
+ * sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })],
1028
+ * imports: [createImport({ name: ['z'], path: 'zod' })],
1029
+ * exports: [createExport({ name: ['Pet'], path: './petStore' })],
1030
+ * })
1031
+ * // file.id = SHA256 hash of the path
1032
+ * // file.name = 'petStore'
1033
+ * // file.extname = '.ts'
1034
+ * ```
1035
+ */
1036
+ type FileNode<TMeta extends object = object> = BaseNode & {
1037
+ kind: 'File';
1038
+ /**
1039
+ * Unique identifier derived from a SHA256 hash of the file path. `createFile`
1040
+ * computes it, so callers do not need to provide it.
1041
+ */
1042
+ id: string;
1043
+ /**
1044
+ * File name without extension, derived from `baseName`.
1045
+ *
1046
+ * @see https://nodejs.org/api/path.html#pathformatpathobject
1047
+ */
1048
+ name: string;
1049
+ /**
1050
+ * File base name, including extension, shaped like `${name}${extname}`.
1051
+ *
1052
+ * @see https://nodejs.org/api/path.html#pathbasenamepath-suffix
1053
+ */
1054
+ baseName: `${string}.${string}`;
1055
+ /**
1056
+ * Full qualified path to the file.
1057
+ */
1058
+ path: string;
1059
+ /**
1060
+ * File extension extracted from `baseName`.
1061
+ */
1062
+ extname: Extname;
1063
+ /**
1064
+ * Deduplicated list of source code fragments.
1065
+ */
1066
+ sources: Array<SourceNode>;
1067
+ /**
1068
+ * Deduplicated list of import declarations.
1069
+ */
1070
+ imports: Array<ImportNode>;
1071
+ /**
1072
+ * Deduplicated list of export declarations.
1073
+ */
1074
+ exports: Array<ExportNode>;
1075
+ /**
1076
+ * Optional metadata attached to this file, read by plugins during barrel generation.
1077
+ */
1078
+ meta?: TMeta;
1079
+ /**
1080
+ * Optional banner prepended to the generated file content.
1081
+ * Accepts `null` so `resolver.default.banner()` results can be passed directly.
1082
+ */
1083
+ banner?: string | null;
1084
+ /**
1085
+ * Optional footer appended to the generated file content.
1086
+ * Accepts `null` so `resolver.default.footer()` results can be passed directly.
1087
+ */
1088
+ footer?: string | null;
1089
+ /**
1090
+ * Absolute on-disk path to copy verbatim into the output, bypassing the parser.
1091
+ *
1092
+ * Use to emit a real source file shipped inside a package (a template) into the generated
1093
+ * folder without reformatting or import reordering. Only `banner` and `footer` are applied
1094
+ * around the copied content. When set, `copy` provides the file content and any `sources`
1095
+ * nodes are ignored for output; `sources` may still carry `name`/`isExportable`/`isIndexable`
1096
+ * so barrel generation treats the file the same as a rendered one.
1097
+ */
1098
+ copy?: string | null;
1099
+ };
1100
+ //#endregion
1101
+ //#region src/jsxRenderer.d.ts
1102
+ /**
1103
+ * Factory for a renderer that walks the JSX tree in a single recursive pass,
1104
+ * with no React reconciler or scheduler. Pass it as the `renderer` property on
1105
+ * `defineGenerator`. Kubb core calls the factory once per render cycle and stays
1106
+ * generic, with no hard dependency on `@kubb/renderer-jsx`.
1107
+ *
1108
+ * Every component must be a pure function. Hooks, suspense, and class
1109
+ * components are not supported.
1110
+ *
1111
+ * @example Wire up a JSX generator
1112
+ * ```tsx
582
1113
  * import { defineGenerator } from '@kubb/core'
1114
+ * import { jsxRenderer } from '@kubb/renderer-jsx'
583
1115
  *
584
1116
  * export const myGenerator = defineGenerator<PluginTs>({
585
- * name: 'my-generator',
1117
+ * name: 'types',
586
1118
  * renderer: jsxRenderer,
587
- * schema(node, options) {
588
- * return <File baseName="output.ts" path="src/output.ts">...</File>
1119
+ * schema(node, ctx) {
1120
+ * return (
1121
+ * <File baseName="output.ts" path={`${ctx.root}/output.ts`}>
1122
+ * <Type node={node} resolver={ctx.resolver} />
1123
+ * </File>
1124
+ * )
589
1125
  * },
590
1126
  * })
591
1127
  * ```
592
1128
  */
593
- declare const jsxRenderer: () => Renderer;
1129
+ declare const jsxRenderer: () => {
1130
+ render(element: KubbReactElement): Promise<void>;
1131
+ readonly files: FileNode[];
1132
+ [Symbol.dispose](): void;
1133
+ };
594
1134
  //#endregion
595
- export { Const, File, Function, Jsx, Root, Type, createContext, createRenderer, inject, jsxRenderer, provide, unprovide };
1135
+ export { Callout, Const, File, Frontmatter, Function, Heading, Jsx, List, Paragraph, Type, jsxRenderer };
596
1136
  //# sourceMappingURL=index.d.ts.map