@kubb/renderer-jsx 5.0.0-alpha.34 → 5.0.0-alpha.36
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/{chunk-CErwXX-a.js → chunk-Bb7HlUDG.js} +1 -1
- package/dist/index.cjs +271 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +336 -47
- package/dist/index.js +273 -110
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.cjs +1 -1
- package/dist/jsx-dev-runtime.d.ts +3 -3
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/{jsx-namespace-Cx1KMEbe.d.ts → jsx-namespace-DdqdFHqm.d.ts} +3 -3
- package/dist/{jsx-runtime-Dmf9wTKR.js → jsx-runtime-7z5lYBqC.js} +2 -2
- package/dist/{jsx-runtime-Dmf9wTKR.js.map → jsx-runtime-7z5lYBqC.js.map} +1 -1
- package/dist/{jsx-runtime-CeMde2cR.cjs → jsx-runtime-Dnd1wztY.cjs} +2 -2
- package/dist/{jsx-runtime-CeMde2cR.cjs.map → jsx-runtime-Dnd1wztY.cjs.map} +1 -1
- package/dist/jsx-runtime.cjs +1 -1
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/jsx-runtime.js +2 -2
- package/dist/types-BEu94Tb3.d.ts +176 -0
- package/dist/types.d.ts +2 -2
- package/package.json +2 -2
- package/src/Runtime.tsx +3 -4
- package/src/components/Const.tsx +35 -7
- package/src/components/File.tsx +96 -16
- package/src/components/Function.tsx +59 -14
- package/src/components/Root.tsx +11 -5
- package/src/components/Type.tsx +32 -6
- package/src/constants.ts +28 -0
- package/src/context/KubbContext.ts +1 -1
- package/src/createRenderer.tsx +64 -3
- package/src/dom.ts +35 -21
- package/src/index.ts +1 -1
- package/src/types.ts +107 -5
- package/src/utils.ts +74 -108
- package/dist/types-C7FD9BLg.d.ts +0 -119
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,110 @@
|
|
|
1
|
-
import { n as __name } from "./chunk-
|
|
2
|
-
import {
|
|
3
|
-
import { ExportNode, FileNode, ImportNode, SourceNode } from "@kubb/ast
|
|
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-BEu94Tb3.js";
|
|
3
|
+
import { ExportNode, FileNode, ImportNode, SourceNode } from "@kubb/ast";
|
|
4
4
|
import * as _$react from "react";
|
|
5
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;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Provides a value to descendant components (Vue 3 style)
|
|
16
|
+
*
|
|
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)
|
|
26
|
+
*
|
|
27
|
+
* @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)
|
|
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 }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function createContext<T>(defaultValue: T): Context<T>;
|
|
49
|
+
//#endregion
|
|
6
50
|
//#region src/components/Const.d.ts
|
|
7
51
|
type ConstProps = {
|
|
8
52
|
key?: Key;
|
|
9
53
|
/**
|
|
10
|
-
*
|
|
54
|
+
* Identifier of the generated constant declaration.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* `name: 'petSchema'`
|
|
11
58
|
*/
|
|
12
59
|
name: string;
|
|
13
60
|
/**
|
|
14
|
-
*
|
|
61
|
+
* Emit the `export` keyword before the `const` declaration.
|
|
62
|
+
* - `true` generates `export const name = …`
|
|
63
|
+
* - `false` generates `const name = …`
|
|
64
|
+
* @default false
|
|
15
65
|
*/
|
|
16
66
|
export?: boolean;
|
|
17
67
|
/**
|
|
18
|
-
*
|
|
68
|
+
* TypeScript type annotation for the constant, written verbatim after `const name:`.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* `type: 'Pet'` → `const pet: Pet = …`
|
|
19
72
|
*/
|
|
20
73
|
type?: string;
|
|
21
74
|
/**
|
|
22
|
-
*
|
|
75
|
+
* JSDoc block to prepend to the constant declaration.
|
|
76
|
+
* Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
|
|
23
77
|
*/
|
|
24
78
|
JSDoc?: JSDoc;
|
|
25
79
|
/**
|
|
26
|
-
*
|
|
80
|
+
* Append `as const` after the initialiser, enabling TypeScript const assertions.
|
|
81
|
+
* - `true` generates `const name = … as const`
|
|
82
|
+
* - `false` generates `const name = …`
|
|
83
|
+
* @default false
|
|
27
84
|
*/
|
|
28
85
|
asConst?: boolean;
|
|
29
86
|
/**
|
|
30
|
-
*
|
|
87
|
+
* Child nodes rendered as the initialiser expression of the constant.
|
|
31
88
|
*/
|
|
32
89
|
children?: KubbReactNode;
|
|
33
90
|
};
|
|
34
91
|
/**
|
|
35
92
|
* Generates a TypeScript constant declaration.
|
|
93
|
+
*
|
|
94
|
+
* @example Named export with type annotation
|
|
95
|
+
* ```tsx
|
|
96
|
+
* <Const export name="petSchema" type="z.ZodType<Pet>">
|
|
97
|
+
* {`z.object({ id: z.number() })`}
|
|
98
|
+
* </Const>
|
|
99
|
+
* // export const petSchema: z.ZodType<Pet> = z.object({ id: z.number() })
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @example With JSDoc and const assertion
|
|
103
|
+
* ```tsx
|
|
104
|
+
* <Const name="HTTP_METHODS" asConst JSDoc={{ comments: ['@description Supported HTTP methods.'] }}>
|
|
105
|
+
* {`['GET', 'POST', 'PUT', 'DELETE']`}
|
|
106
|
+
* </Const>
|
|
107
|
+
* ```
|
|
36
108
|
*/
|
|
37
109
|
declare function Const({
|
|
38
110
|
children,
|
|
@@ -45,33 +117,67 @@ declare namespace Const {
|
|
|
45
117
|
//#region src/components/File.d.ts
|
|
46
118
|
type BasePropsWithBaseName = {
|
|
47
119
|
/**
|
|
48
|
-
*
|
|
49
|
-
* Based on UNIX basename
|
|
120
|
+
* Base file name including extension, derived from the input path.
|
|
121
|
+
* Based on UNIX basename convention: `${name}${extname}`.
|
|
122
|
+
*
|
|
50
123
|
* @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* `baseName: 'petStore.ts'`
|
|
51
127
|
*/
|
|
52
128
|
baseName: `${string}.${string}`;
|
|
53
129
|
/**
|
|
54
|
-
*
|
|
130
|
+
* Fully qualified path to the generated file.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* `path: 'src/models/petStore.ts'`
|
|
55
134
|
*/
|
|
56
135
|
path: string;
|
|
57
136
|
};
|
|
58
137
|
type BasePropsWithoutBaseName = {
|
|
59
138
|
baseName?: never;
|
|
60
139
|
/**
|
|
61
|
-
*
|
|
140
|
+
* Fully qualified path to the generated file.
|
|
141
|
+
* Optional when `baseName` is omitted — the component renders its children inline.
|
|
62
142
|
*/
|
|
63
143
|
path?: string;
|
|
64
144
|
};
|
|
65
145
|
type BaseProps = BasePropsWithBaseName | BasePropsWithoutBaseName;
|
|
66
146
|
type Props$2<TMeta> = BaseProps & {
|
|
67
147
|
key?: Key;
|
|
148
|
+
/**
|
|
149
|
+
* Arbitrary metadata attached to the file node.
|
|
150
|
+
* Used by plugins for barrel generation and custom post-processing.
|
|
151
|
+
*/
|
|
68
152
|
meta?: TMeta;
|
|
153
|
+
/**
|
|
154
|
+
* Text prepended to the generated file content before any source blocks.
|
|
155
|
+
*/
|
|
69
156
|
banner?: string;
|
|
157
|
+
/**
|
|
158
|
+
* Text appended to the generated file content after all source blocks.
|
|
159
|
+
*/
|
|
70
160
|
footer?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Child nodes rendered as the content of this file (source blocks, imports, exports).
|
|
163
|
+
*/
|
|
71
164
|
children?: KubbReactNode;
|
|
72
165
|
};
|
|
73
166
|
/**
|
|
74
|
-
*
|
|
167
|
+
* Declares a generated file entry to be collected by the renderer.
|
|
168
|
+
*
|
|
169
|
+
* When both `baseName` and `path` are provided, the component registers a new
|
|
170
|
+
* `FileNode` and passes its children through as source blocks.
|
|
171
|
+
* When either is omitted the children are rendered inline without creating a file entry.
|
|
172
|
+
*
|
|
173
|
+
* @example Basic file with a source block
|
|
174
|
+
* ```tsx
|
|
175
|
+
* <File baseName="petStore.ts" path="src/models/petStore.ts">
|
|
176
|
+
* <File.Source name="Pet" isExportable isIndexable>
|
|
177
|
+
* {`export type Pet = { id: number; name: string }`}
|
|
178
|
+
* </File.Source>
|
|
179
|
+
* </File>
|
|
180
|
+
* ```
|
|
75
181
|
*/
|
|
76
182
|
declare function File<TMeta extends object = object>({
|
|
77
183
|
children,
|
|
@@ -85,13 +191,30 @@ declare namespace File {
|
|
|
85
191
|
}
|
|
86
192
|
type FileSourceProps = Omit<SourceNode, 'kind' | 'value'> & {
|
|
87
193
|
key?: Key;
|
|
194
|
+
/**
|
|
195
|
+
* Child nodes rendered as the source content of this block.
|
|
196
|
+
*/
|
|
88
197
|
children?: KubbReactNode;
|
|
89
198
|
};
|
|
90
199
|
/**
|
|
91
|
-
* File.
|
|
200
|
+
* Marks a block of source text to be associated with the enclosing {@link File}.
|
|
201
|
+
*
|
|
202
|
+
* Children are treated as the source string. When `isExportable` is `true` the
|
|
203
|
+
* `name` is used for deduplication and barrel generation.
|
|
92
204
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
205
|
+
* @example Exportable, indexable source block
|
|
206
|
+
* ```tsx
|
|
207
|
+
* <File.Source name="Pet" isExportable isIndexable>
|
|
208
|
+
* {`export type Pet = { id: number; name: string }`}
|
|
209
|
+
* </File.Source>
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @example Type-only source block
|
|
213
|
+
* ```tsx
|
|
214
|
+
* <File.Source name="PetId" isTypeOnly isExportable>
|
|
215
|
+
* {`export type PetId = string`}
|
|
216
|
+
* </File.Source>
|
|
217
|
+
* ```
|
|
95
218
|
*/
|
|
96
219
|
declare function FileSource({
|
|
97
220
|
children,
|
|
@@ -104,10 +227,21 @@ type FileExportProps = Omit<ExportNode, 'kind'> & {
|
|
|
104
227
|
key?: Key;
|
|
105
228
|
};
|
|
106
229
|
/**
|
|
107
|
-
* File.
|
|
230
|
+
* Declares an export entry for the enclosing {@link File}.
|
|
231
|
+
*
|
|
232
|
+
* The export is collected by the renderer and emitted at the top of the generated file.
|
|
108
233
|
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
234
|
+
* @example Named export
|
|
235
|
+
* ```tsx
|
|
236
|
+
* <File.Export name={['Pet']} path="./models/petStore" />
|
|
237
|
+
* // export { Pet } from './models/petStore'
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* @example Type-only wildcard export
|
|
241
|
+
* ```tsx
|
|
242
|
+
* <File.Export path="./models/petStore" isTypeOnly />
|
|
243
|
+
* // export type * from './models/petStore'
|
|
244
|
+
* ```
|
|
111
245
|
*/
|
|
112
246
|
declare function FileExport(props: FileExportProps): KubbReactElement;
|
|
113
247
|
declare namespace FileExport {
|
|
@@ -117,9 +251,27 @@ type FileImportProps = Omit<ImportNode, 'kind'> & {
|
|
|
117
251
|
key?: Key;
|
|
118
252
|
};
|
|
119
253
|
/**
|
|
120
|
-
* File.
|
|
254
|
+
* Declares an import entry for the enclosing {@link File}.
|
|
121
255
|
*
|
|
122
|
-
*
|
|
256
|
+
* The import is collected by the renderer and emitted at the top of the generated file.
|
|
257
|
+
*
|
|
258
|
+
* @example Named import
|
|
259
|
+
* ```tsx
|
|
260
|
+
* <File.Import name={['useState']} path="react" />
|
|
261
|
+
* // import { useState } from 'react'
|
|
262
|
+
* ```
|
|
263
|
+
*
|
|
264
|
+
* @example Type-only import
|
|
265
|
+
* ```tsx
|
|
266
|
+
* <File.Import name={['Pet']} path="./models" isTypeOnly />
|
|
267
|
+
* // import type { Pet } from './models'
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* @example Namespace import
|
|
271
|
+
* ```tsx
|
|
272
|
+
* <File.Import name="z" path="zod" isNameSpace />
|
|
273
|
+
* // import * as z from 'zod'
|
|
274
|
+
* ```
|
|
123
275
|
*/
|
|
124
276
|
declare function FileImport(props: FileImportProps): KubbReactElement;
|
|
125
277
|
declare namespace FileImport {
|
|
@@ -130,45 +282,80 @@ declare namespace FileImport {
|
|
|
130
282
|
type Props$1 = {
|
|
131
283
|
key?: Key;
|
|
132
284
|
/**
|
|
133
|
-
*
|
|
285
|
+
* Identifier of the generated function declaration.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* `name: 'getPet'`
|
|
134
289
|
*/
|
|
135
290
|
name: string;
|
|
136
291
|
/**
|
|
137
|
-
*
|
|
292
|
+
* Emit `default` after the `export` keyword, making this the module's default export.
|
|
293
|
+
* Requires `export` to also be `true`.
|
|
294
|
+
* @default false
|
|
138
295
|
*/
|
|
139
296
|
default?: boolean;
|
|
140
297
|
/**
|
|
141
|
-
*
|
|
298
|
+
* Parameter list written verbatim between the function's parentheses.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* `params: 'petId: string, options?: RequestOptions'`
|
|
142
302
|
*/
|
|
143
303
|
params?: string;
|
|
144
304
|
/**
|
|
145
|
-
*
|
|
305
|
+
* Emit the `export` keyword before the function declaration.
|
|
306
|
+
* - `true` generates `export function name(…) { … }`
|
|
307
|
+
* - `false` generates `function name(…) { … }`
|
|
308
|
+
* @default false
|
|
146
309
|
*/
|
|
147
310
|
export?: boolean;
|
|
148
311
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
312
|
+
* Emit the `async` keyword, making this an async function.
|
|
313
|
+
* The return type is automatically wrapped in `Promise<returnType>` when both
|
|
314
|
+
* `async` and `returnType` are set.
|
|
315
|
+
* @default false
|
|
151
316
|
*/
|
|
152
317
|
async?: boolean;
|
|
153
318
|
/**
|
|
154
|
-
*
|
|
319
|
+
* TypeScript generic type parameters written verbatim between `<` and `>`.
|
|
320
|
+
* Pass an array to emit multiple parameters separated by commas.
|
|
321
|
+
*
|
|
322
|
+
* @example Single generic
|
|
323
|
+
* `generics: 'TData'`
|
|
324
|
+
*
|
|
325
|
+
* @example Multiple generics
|
|
326
|
+
* `generics: ['TData', 'TError = unknown']`
|
|
155
327
|
*/
|
|
156
328
|
generics?: string | string[];
|
|
157
329
|
/**
|
|
158
|
-
*
|
|
330
|
+
* TypeScript return type annotation written verbatim after `:`.
|
|
331
|
+
* When `async` is `true`, the value is automatically wrapped in `Promise<…>`.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* `returnType: 'Pet'`
|
|
159
335
|
*/
|
|
160
336
|
returnType?: string;
|
|
161
337
|
/**
|
|
162
|
-
*
|
|
338
|
+
* JSDoc block to prepend to the function declaration.
|
|
339
|
+
* Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
|
|
163
340
|
*/
|
|
164
341
|
JSDoc?: JSDoc;
|
|
165
342
|
/**
|
|
166
|
-
*
|
|
343
|
+
* Child nodes rendered as the body of the function.
|
|
167
344
|
*/
|
|
168
345
|
children?: KubbReactNode;
|
|
169
346
|
};
|
|
170
347
|
/**
|
|
171
348
|
* Generates a TypeScript function declaration.
|
|
349
|
+
*
|
|
350
|
+
* @example Async exported function with generics
|
|
351
|
+
* ```tsx
|
|
352
|
+
* <Function export async name="getPet" generics={['TData = Pet']} params="petId: string" returnType="TData">
|
|
353
|
+
* {`return client.get(\`/pets/\${petId}\`)`}
|
|
354
|
+
* </Function>
|
|
355
|
+
* // export async function getPet<TData = Pet>(petId: string): Promise<TData> {
|
|
356
|
+
* // return client.get(`/pets/${petId}`)
|
|
357
|
+
* // }
|
|
358
|
+
* ```
|
|
172
359
|
*/
|
|
173
360
|
declare function Function({
|
|
174
361
|
children,
|
|
@@ -180,15 +367,25 @@ declare namespace Function {
|
|
|
180
367
|
}
|
|
181
368
|
type ArrowFunctionProps = Props$1 & {
|
|
182
369
|
/**
|
|
183
|
-
*
|
|
370
|
+
* Render the arrow function as a single-line expression (no braces around the body).
|
|
371
|
+
* - `true` generates `const name = (…) => expression`
|
|
372
|
+
* - `false` generates `const name = (…) => { … }`
|
|
373
|
+
* @default false
|
|
184
374
|
*/
|
|
185
375
|
singleLine?: boolean;
|
|
186
376
|
};
|
|
187
377
|
/**
|
|
188
|
-
*
|
|
378
|
+
* Generates an arrow function expression assigned to a `const`.
|
|
379
|
+
* Supports the same flags as {@link Function}.
|
|
380
|
+
* Use `singleLine` to render the body as a concise expression rather than a block.
|
|
189
381
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
382
|
+
* @example Single-line arrow function
|
|
383
|
+
* ```tsx
|
|
384
|
+
* <Function.Arrow export name="double" params="n: number" returnType="number" singleLine>
|
|
385
|
+
* {`n * 2`}
|
|
386
|
+
* </Function.Arrow>
|
|
387
|
+
* // export const double = (n: number): number => n * 2
|
|
388
|
+
* ```
|
|
192
389
|
*/
|
|
193
390
|
declare function ArrowFunction({
|
|
194
391
|
children,
|
|
@@ -235,20 +432,26 @@ declare namespace Jsx {
|
|
|
235
432
|
//#region src/components/Root.d.ts
|
|
236
433
|
type RootProps = {
|
|
237
434
|
/**
|
|
238
|
-
*
|
|
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.
|
|
239
438
|
*/
|
|
240
439
|
onExit: (error?: Error) => void;
|
|
241
440
|
/**
|
|
242
|
-
*
|
|
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}.
|
|
243
443
|
*/
|
|
244
444
|
onError: (error: Error) => void;
|
|
245
445
|
/**
|
|
246
|
-
*
|
|
446
|
+
* Child nodes rendered inside the error boundary.
|
|
247
447
|
*/
|
|
248
448
|
children?: KubbReactNode;
|
|
249
449
|
};
|
|
250
450
|
/**
|
|
251
|
-
*
|
|
451
|
+
* Root component for the Kubb renderer tree.
|
|
452
|
+
*
|
|
453
|
+
* Wraps all children in an `ErrorBoundary` so that render errors are caught
|
|
454
|
+
* and forwarded to `onError` rather than crashing the process.
|
|
252
455
|
*/
|
|
253
456
|
declare function Root({
|
|
254
457
|
onError,
|
|
@@ -262,24 +465,50 @@ declare namespace Root {
|
|
|
262
465
|
type TypeProps = {
|
|
263
466
|
key?: Key;
|
|
264
467
|
/**
|
|
265
|
-
*
|
|
468
|
+
* Identifier of the generated type alias.
|
|
469
|
+
* Must start with an uppercase letter to follow TypeScript naming conventions.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* `name: 'Pet'`
|
|
266
473
|
*/
|
|
267
474
|
name: string;
|
|
268
475
|
/**
|
|
269
|
-
*
|
|
476
|
+
* Emit the `export` keyword before the type alias declaration.
|
|
477
|
+
* - `true` generates `export type Name = …`
|
|
478
|
+
* - `false` generates `type Name = …`
|
|
479
|
+
* @default false
|
|
270
480
|
*/
|
|
271
481
|
export?: boolean;
|
|
272
482
|
/**
|
|
273
|
-
*
|
|
483
|
+
* JSDoc block to prepend to the type alias declaration.
|
|
484
|
+
* Each entry in `comments` becomes one line inside the emitted `/** … *\/` block.
|
|
274
485
|
*/
|
|
275
486
|
JSDoc?: JSDoc;
|
|
276
487
|
/**
|
|
277
|
-
*
|
|
488
|
+
* Child nodes rendered as the type expression on the right-hand side of the alias.
|
|
278
489
|
*/
|
|
279
490
|
children?: KubbReactNode;
|
|
280
491
|
};
|
|
281
492
|
/**
|
|
282
|
-
* Generates a TypeScript type declaration.
|
|
493
|
+
* Generates a TypeScript type alias declaration.
|
|
494
|
+
*
|
|
495
|
+
* Throws if `name` does not start with an uppercase letter — TypeScript type aliases
|
|
496
|
+
* should follow PascalCase naming conventions.
|
|
497
|
+
*
|
|
498
|
+
* @example Simple exported type alias
|
|
499
|
+
* ```tsx
|
|
500
|
+
* <Type export name="PetId">
|
|
501
|
+
* {`string | number`}
|
|
502
|
+
* </Type>
|
|
503
|
+
* // export type PetId = string | number
|
|
504
|
+
* ```
|
|
505
|
+
*
|
|
506
|
+
* @example Type alias with JSDoc
|
|
507
|
+
* ```tsx
|
|
508
|
+
* <Type export name="Pet" JSDoc={{ comments: ['@description A pet in the store.'] }}>
|
|
509
|
+
* {`{ id: number; name: string }`}
|
|
510
|
+
* </Type>
|
|
511
|
+
* ```
|
|
283
512
|
*/
|
|
284
513
|
declare function Type({
|
|
285
514
|
children,
|
|
@@ -315,16 +544,76 @@ declare const OasContext: Context<unknown>;
|
|
|
315
544
|
//#region src/createRenderer.d.ts
|
|
316
545
|
type Options = {
|
|
317
546
|
/**
|
|
318
|
-
*
|
|
547
|
+
* Print each render result to the console for debugging.
|
|
548
|
+
* Useful when diagnosing output differences between renders.
|
|
549
|
+
* @default false
|
|
319
550
|
*/
|
|
320
551
|
debug?: boolean;
|
|
321
552
|
};
|
|
553
|
+
/**
|
|
554
|
+
* The renderer instance returned by {@link createRenderer}.
|
|
555
|
+
*/
|
|
322
556
|
type Renderer = {
|
|
557
|
+
/**
|
|
558
|
+
* Render a JSX element tree and collect the resulting {@link FileNode} entries.
|
|
559
|
+
* Resolves once all synchronous render work (including React's flush) is done.
|
|
560
|
+
*/
|
|
323
561
|
render(Element: KubbReactElement): Promise<void>;
|
|
562
|
+
/**
|
|
563
|
+
* Tear down the renderer and release all React resources.
|
|
564
|
+
* Pass an `Error` to signal an abnormal shutdown.
|
|
565
|
+
*/
|
|
324
566
|
unmount(error?: Error | number | null): void;
|
|
567
|
+
/**
|
|
568
|
+
* The {@link FileNode} entries collected from the most recent `render` call.
|
|
569
|
+
*/
|
|
325
570
|
files: Array<FileNode>;
|
|
326
571
|
};
|
|
572
|
+
/**
|
|
573
|
+
* Create a Kubb JSX renderer.
|
|
574
|
+
*
|
|
575
|
+
* The renderer converts a React JSX element tree — built from the components in this
|
|
576
|
+
* package — into an array of {@link FileNode} entries representing the generated files.
|
|
577
|
+
*
|
|
578
|
+
* @example Basic usage
|
|
579
|
+
* ```ts
|
|
580
|
+
* import { createRenderer, File } from '@kubb/renderer-jsx'
|
|
581
|
+
*
|
|
582
|
+
* const renderer = createRenderer()
|
|
583
|
+
* await renderer.render(
|
|
584
|
+
* <File baseName="pet.ts" path="src/models/pet.ts">
|
|
585
|
+
* <File.Source name="Pet" isExportable isIndexable>
|
|
586
|
+
* {`export type Pet = { id: number; name: string }`}
|
|
587
|
+
* </File.Source>
|
|
588
|
+
* </File>
|
|
589
|
+
* )
|
|
590
|
+
* console.log(renderer.files) // [FileNode]
|
|
591
|
+
* renderer.unmount()
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
327
594
|
declare function createRenderer(options?: Options): Renderer;
|
|
595
|
+
/**
|
|
596
|
+
* A renderer factory for generators that produce JSX output.
|
|
597
|
+
*
|
|
598
|
+
* Pass this as the `renderer` property of a `defineGenerator` call so that
|
|
599
|
+
* core can render the JSX element tree returned by your generator methods
|
|
600
|
+
* without a hard dependency on `@kubb/renderer-jsx`.
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* import { jsxRenderer } from '@kubb/renderer-jsx'
|
|
605
|
+
* import { defineGenerator } from '@kubb/core'
|
|
606
|
+
*
|
|
607
|
+
* export const myGenerator = defineGenerator<PluginTs>({
|
|
608
|
+
* name: 'my-generator',
|
|
609
|
+
* renderer: jsxRenderer,
|
|
610
|
+
* schema(node, options) {
|
|
611
|
+
* return <File baseName="output.ts" path="src/output.ts">...</File>
|
|
612
|
+
* },
|
|
613
|
+
* })
|
|
614
|
+
* ```
|
|
615
|
+
*/
|
|
616
|
+
declare const jsxRenderer: () => Renderer;
|
|
328
617
|
//#endregion
|
|
329
|
-
export { Const, File, Function, Jsx, KubbContext, OasContext, Root, Type, createContext, createRenderer, inject, provide, unprovide };
|
|
618
|
+
export { Const, File, Function, Jsx, KubbContext, OasContext, Root, Type, createContext, createRenderer, inject, jsxRenderer, provide, unprovide };
|
|
330
619
|
//# sourceMappingURL=index.d.ts.map
|