@kubb/ast 5.21.2 → 5.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base-IpYuh3ZP.d.cts +173 -0
- package/dist/base-IpYuh3ZP.d.ts +173 -0
- package/dist/constants-Ckeonm-D.js +141 -0
- package/dist/constants-Ckeonm-D.js.map +1 -0
- package/dist/constants-CquR083U.cjs +152 -0
- package/dist/constants-CquR083U.cjs.map +1 -0
- package/dist/factory.cjs +23 -0
- package/dist/factory.d.cts +4 -0
- package/dist/factory.d.ts +4 -0
- package/dist/factory.js +4 -0
- package/dist/file-BVqSiSvV.d.cts +624 -0
- package/dist/file-Cg0T6cgz.cjs +319 -0
- package/dist/file-Cg0T6cgz.cjs.map +1 -0
- package/dist/file-CnuL8oUj.js +283 -0
- package/dist/file-CnuL8oUj.js.map +1 -0
- package/dist/file-CvlMAp_d.js +131 -0
- package/dist/file-CvlMAp_d.js.map +1 -0
- package/dist/file-Dd50jPkH.cjs +142 -0
- package/dist/file-Dd50jPkH.cjs.map +1 -0
- package/dist/file-xJnBQPGq.d.ts +624 -0
- package/dist/file.cjs +3 -0
- package/dist/file.d.cts +2 -0
- package/dist/file.d.ts +2 -0
- package/dist/file.js +1 -0
- package/dist/graph-BcwFCvei.js +144 -0
- package/dist/graph-BcwFCvei.js.map +1 -0
- package/dist/graph-DcIY6tQb.cjs +173 -0
- package/dist/graph-DcIY6tQb.cjs.map +1 -0
- package/dist/graph.cjs +6 -0
- package/dist/graph.d.cts +2 -0
- package/dist/graph.d.ts +2 -0
- package/dist/graph.js +1 -0
- package/dist/guards-B8qDgSaT.d.cts +23 -0
- package/dist/guards-COVJE6TU.cjs +41 -0
- package/dist/guards-COVJE6TU.cjs.map +1 -0
- package/dist/guards-D-h9R_sV.d.ts +23 -0
- package/dist/guards-DlJkKsT1.js +30 -0
- package/dist/guards-DlJkKsT1.js.map +1 -0
- package/dist/http-Bm5lhVK4.cjs +12 -0
- package/dist/http-Bm5lhVK4.cjs.map +1 -0
- package/dist/http-DwboM6pK.js +7 -0
- package/dist/http-DwboM6pK.js.map +1 -0
- package/dist/http.cjs +4 -0
- package/dist/http.d.cts +3 -0
- package/dist/http.d.ts +3 -0
- package/dist/http.js +2 -0
- package/dist/index-BWd95onW.d.cts +5 -0
- package/dist/index-Bb1kqq8H.d.cts +20 -0
- package/dist/index-BngGJux5.d.cts +12 -0
- package/dist/index-BwnMIoLl.d.ts +24 -0
- package/dist/index-C-vhkzwR.d.cts +79 -0
- package/dist/index-CAGuKv6t.d.ts +74 -0
- package/dist/index-CFH4ZC7q.d.ts +44 -0
- package/dist/index-CIqwy4EE.d.cts +74 -0
- package/dist/index-Cc2K3OzU.d.cts +11 -0
- package/dist/index-Cc2K3OzU.d.ts +11 -0
- package/dist/index-Csf8xsCc.d.cts +46 -0
- package/dist/index-D3M2spDR.d.ts +12 -0
- package/dist/index-DNiIem0x.d.ts +79 -0
- package/dist/index-DSVef1pp.d.cts +24 -0
- package/dist/index-DU_jYpBt.d.cts +44 -0
- package/dist/index-DYDha-3I.d.cts +67 -0
- package/dist/index-DaHsMJ_S.d.ts +5 -0
- package/dist/index-Dp50LM3a.d.ts +67 -0
- package/dist/index-cpjUxIik.d.ts +46 -0
- package/dist/index-eGkM4FE9.d.ts +20 -0
- package/dist/index.cjs +87 -2131
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -2745
- package/dist/index.d.ts +25 -2745
- package/dist/index.js +40 -2052
- package/dist/index.js.map +1 -1
- package/dist/json-DH7_lcWm.js +74 -0
- package/dist/json-DH7_lcWm.js.map +1 -0
- package/dist/json-DURdtz9A.cjs +91 -0
- package/dist/json-DURdtz9A.cjs.map +1 -0
- package/dist/json.cjs +4 -0
- package/dist/json.d.cts +2 -0
- package/dist/json.d.ts +2 -0
- package/dist/json.js +1 -0
- package/dist/macro-D0KfNtff.js +104 -0
- package/dist/macro-D0KfNtff.js.map +1 -0
- package/dist/macro-DrTBT7fh.cjs +127 -0
- package/dist/macro-DrTBT7fh.cjs.map +1 -0
- package/dist/macro.cjs +4 -0
- package/dist/macro.d.cts +2 -0
- package/dist/macro.d.ts +2 -0
- package/dist/macro.js +1 -0
- package/dist/mediaType-CRjggmoG.js +19 -0
- package/dist/mediaType-CRjggmoG.js.map +1 -0
- package/dist/mediaType-D8uIO8sG.cjs +35 -0
- package/dist/mediaType-D8uIO8sG.cjs.map +1 -0
- package/dist/mediaType.cjs +4 -0
- package/dist/mediaType.d.cts +2 -0
- package/dist/mediaType.d.ts +2 -0
- package/dist/mediaType.js +1 -0
- package/dist/node-DjcETnc8.cjs +19 -0
- package/dist/node-DjcETnc8.cjs.map +1 -0
- package/dist/node-Djh-mZB2.js +14 -0
- package/dist/node-Djh-mZB2.js.map +1 -0
- package/dist/node.cjs +9 -0
- package/dist/node.d.cts +4 -0
- package/dist/node.d.ts +4 -0
- package/dist/node.js +5 -0
- package/dist/nodeText-DRb_rVd1.cjs +58 -0
- package/dist/nodeText-DRb_rVd1.cjs.map +1 -0
- package/dist/nodeText-DVVDZQjF.js +47 -0
- package/dist/nodeText-DVVDZQjF.js.map +1 -0
- package/dist/nodes-BB60Bq2H.cjs +320 -0
- package/dist/nodes-BB60Bq2H.cjs.map +1 -0
- package/dist/nodes-CWMa9xhW.js +231 -0
- package/dist/nodes-CWMa9xhW.js.map +1 -0
- package/dist/operation-BgRyVS7z.d.ts +1272 -0
- package/dist/operation-X7chCdL2.d.cts +1272 -0
- package/dist/optionality-D-zqzVMH.cjs +22 -0
- package/dist/optionality-D-zqzVMH.cjs.map +1 -0
- package/dist/optionality-DISn8ytP.js +17 -0
- package/dist/optionality-DISn8ytP.js.map +1 -0
- package/dist/promise-BOdlgT0N.cjs +50 -0
- package/dist/promise-BOdlgT0N.cjs.map +1 -0
- package/dist/promise-RpnEev9D.js +45 -0
- package/dist/promise-RpnEev9D.js.map +1 -0
- package/dist/ref-Bu7PoHar.js +22 -0
- package/dist/ref-Bu7PoHar.js.map +1 -0
- package/dist/ref-P0ZLT1Bg.cjs +39 -0
- package/dist/ref-P0ZLT1Bg.cjs.map +1 -0
- package/dist/ref.cjs +7 -0
- package/dist/ref.d.cts +2 -0
- package/dist/ref.d.ts +2 -0
- package/dist/ref.js +3 -0
- package/dist/refs-CYHpRlQo.cjs +131 -0
- package/dist/refs-CYHpRlQo.cjs.map +1 -0
- package/dist/refs-YCV3CznS.js +102 -0
- package/dist/refs-YCV3CznS.js.map +1 -0
- package/dist/rolldown-runtime-BV8xUvPy.cjs +52 -0
- package/dist/rolldown-runtime-BYyVTPww.js +16 -0
- package/dist/schema-2ZAQk7qE.js +44 -0
- package/dist/schema-2ZAQk7qE.js.map +1 -0
- package/dist/schema-BIErWqgc.cjs +214 -0
- package/dist/schema-BIErWqgc.cjs.map +1 -0
- package/dist/schema-DloctnMm.js +179 -0
- package/dist/schema-DloctnMm.js.map +1 -0
- package/dist/schema-hxMlgCrV.cjs +49 -0
- package/dist/schema-hxMlgCrV.cjs.map +1 -0
- package/dist/schema.cjs +16 -0
- package/dist/schema.d.cts +5 -0
- package/dist/schema.d.ts +5 -0
- package/dist/schema.js +6 -0
- package/dist/visitor-BZozlXBF.d.ts +179 -0
- package/dist/visitor-Bw_opzjF.d.cts +179 -0
- package/dist/visitor-DTrzvA3R.cjs +382 -0
- package/dist/visitor-DTrzvA3R.cjs.map +1 -0
- package/dist/visitor-NoQSUQTu.js +347 -0
- package/dist/visitor-NoQSUQTu.js.map +1 -0
- package/package.json +101 -1
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
import { t as BaseNode } from "./base-IpYuh3ZP.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* JSDoc documentation metadata attached to code declarations.
|
|
4
|
+
*/
|
|
5
|
+
type JSDocNode = {
|
|
6
|
+
/**
|
|
7
|
+
* JSDoc comment lines. `undefined` entries are filtered out during rendering.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* ['@description A pet resource', '@deprecated']
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
comments?: Array<string | undefined>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* AST node representing a TypeScript `const` declaration.
|
|
18
|
+
*
|
|
19
|
+
* Mirrors the props of the `Const` component from `@kubb/renderer-jsx`.
|
|
20
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* createConst({ name: 'pet', export: true, asConst: true })
|
|
25
|
+
* // export const pet = ... as const
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
type ConstNode = BaseNode & {
|
|
29
|
+
kind: 'Const';
|
|
30
|
+
/**
|
|
31
|
+
* Name of the constant declaration.
|
|
32
|
+
*/
|
|
33
|
+
name: string;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the declaration should be exported.
|
|
36
|
+
*/
|
|
37
|
+
export?: boolean | null;
|
|
38
|
+
/**
|
|
39
|
+
* Explicit type annotation.
|
|
40
|
+
*
|
|
41
|
+
* @example Type reference
|
|
42
|
+
* `'Pet'`
|
|
43
|
+
*/
|
|
44
|
+
type?: string | null;
|
|
45
|
+
/**
|
|
46
|
+
* JSDoc documentation metadata.
|
|
47
|
+
*/
|
|
48
|
+
JSDoc?: JSDocNode | null;
|
|
49
|
+
/**
|
|
50
|
+
* Whether to append `as const` to the declaration.
|
|
51
|
+
*/
|
|
52
|
+
asConst?: boolean | null;
|
|
53
|
+
/**
|
|
54
|
+
* Child nodes representing the value of the constant (children of the `Const` component).
|
|
55
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
56
|
+
*/
|
|
57
|
+
nodes?: Array<CodeNode>;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* AST node representing a TypeScript `type` alias declaration.
|
|
61
|
+
*
|
|
62
|
+
* Mirrors the props of the `Type` component from `@kubb/renderer-jsx`.
|
|
63
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* createType({ name: 'Pet', export: true })
|
|
68
|
+
* // export type Pet = ...
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
type TypeNode = BaseNode & {
|
|
72
|
+
kind: 'Type';
|
|
73
|
+
/**
|
|
74
|
+
* Name of the type alias.
|
|
75
|
+
*/
|
|
76
|
+
name: string;
|
|
77
|
+
/**
|
|
78
|
+
* Whether the declaration should be exported.
|
|
79
|
+
*/
|
|
80
|
+
export?: boolean | null;
|
|
81
|
+
/**
|
|
82
|
+
* JSDoc documentation metadata.
|
|
83
|
+
*/
|
|
84
|
+
JSDoc?: JSDocNode | null;
|
|
85
|
+
/**
|
|
86
|
+
* Child nodes representing the type body (children of the `Type` component).
|
|
87
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
88
|
+
*/
|
|
89
|
+
nodes?: Array<CodeNode>;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* AST node representing a TypeScript `function` declaration.
|
|
93
|
+
*
|
|
94
|
+
* Mirrors the props of the `Function` component from `@kubb/renderer-jsx`.
|
|
95
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* createFunction({ name: 'getPet', export: true, async: true, returnType: 'Pet' })
|
|
100
|
+
* // export async function getPet(): Promise<Pet> { ... }
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
type FunctionNode = BaseNode & {
|
|
104
|
+
kind: 'Function';
|
|
105
|
+
/**
|
|
106
|
+
* Name of the function.
|
|
107
|
+
*/
|
|
108
|
+
name: string;
|
|
109
|
+
/**
|
|
110
|
+
* Whether the function is a default export.
|
|
111
|
+
*/
|
|
112
|
+
default?: boolean | null;
|
|
113
|
+
/**
|
|
114
|
+
* Function parameter list as a pre-rendered string, written verbatim between the parentheses.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* `'id: string, config: Config = {}'`
|
|
118
|
+
*/
|
|
119
|
+
params?: string | null;
|
|
120
|
+
/**
|
|
121
|
+
* Whether the function should be exported.
|
|
122
|
+
*/
|
|
123
|
+
export?: boolean | null;
|
|
124
|
+
/**
|
|
125
|
+
* Whether the function is async. When `true`, the return type is wrapped in `Promise<>`.
|
|
126
|
+
*/
|
|
127
|
+
async?: boolean | null;
|
|
128
|
+
/**
|
|
129
|
+
* TypeScript generic type parameters.
|
|
130
|
+
*
|
|
131
|
+
* @example Constrained generics
|
|
132
|
+
* `['T', 'U extends string']`
|
|
133
|
+
*/
|
|
134
|
+
generics?: string | Array<string> | null;
|
|
135
|
+
/**
|
|
136
|
+
* Return type annotation.
|
|
137
|
+
*
|
|
138
|
+
* @example Type reference
|
|
139
|
+
* `'Pet'`
|
|
140
|
+
*/
|
|
141
|
+
returnType?: string | null;
|
|
142
|
+
/**
|
|
143
|
+
* JSDoc documentation metadata.
|
|
144
|
+
*/
|
|
145
|
+
JSDoc?: JSDocNode | null;
|
|
146
|
+
/**
|
|
147
|
+
* Child nodes representing the function body (children of the `Function` component).
|
|
148
|
+
* Each entry is a {@link CodeNode}. Use {@link TextNode} for raw string content.
|
|
149
|
+
*/
|
|
150
|
+
nodes?: Array<CodeNode>;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* AST node representing a TypeScript arrow function (`const name = () => { ... }`).
|
|
154
|
+
*
|
|
155
|
+
* Mirrors the props of the `Function.Arrow` component from `@kubb/renderer-jsx`.
|
|
156
|
+
* The `children` prop of the component is represented as `nodes`.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* createArrowFunction({ name: 'getPet', export: true, singleLine: true })
|
|
161
|
+
* // export const getPet = () => ...
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
type ArrowFunctionNode = Omit<FunctionNode, 'kind'> & {
|
|
165
|
+
kind: 'ArrowFunction';
|
|
166
|
+
/**
|
|
167
|
+
* Render the arrow function body as a single-line expression.
|
|
168
|
+
*/
|
|
169
|
+
singleLine?: boolean | null;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* AST node representing a raw text/string fragment in the source output.
|
|
173
|
+
*
|
|
174
|
+
* Used instead of bare `string` values so that all entries in `nodes` arrays
|
|
175
|
+
* are typed `CodeNode` objects rather than a mixed `CodeNode | string` union.
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```ts
|
|
179
|
+
* createText('return fetch(id)')
|
|
180
|
+
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
type TextNode = BaseNode & {
|
|
184
|
+
kind: 'Text';
|
|
185
|
+
/**
|
|
186
|
+
* The raw string content.
|
|
187
|
+
*/
|
|
188
|
+
value: string;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* AST node representing a blank line in the source output.
|
|
192
|
+
*
|
|
193
|
+
* Corresponds to `<br/>` in JSX components. `printNodes` turns a `Break` between two
|
|
194
|
+
* statements into one blank line. Consecutive breaks, and breaks at the start or end of
|
|
195
|
+
* the list, are folded away, so a `Break` never produces more than one blank line.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```ts
|
|
199
|
+
* createBreak()
|
|
200
|
+
* // { kind: 'Break' }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
type BreakNode = BaseNode & {
|
|
204
|
+
kind: 'Break';
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* AST node representing a raw JSX fragment in the source output.
|
|
208
|
+
*
|
|
209
|
+
* Mirrors the `Jsx` component from `@kubb/renderer-jsx`. Embeds raw JSX/TSX markup
|
|
210
|
+
* (including fragments `<>…</>`) directly in generated code.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
215
|
+
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
|
+
type JsxNode = BaseNode & {
|
|
219
|
+
kind: 'Jsx';
|
|
220
|
+
/**
|
|
221
|
+
* The raw JSX string content.
|
|
222
|
+
*/
|
|
223
|
+
value: string;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Union of all code-generation AST nodes.
|
|
227
|
+
*
|
|
228
|
+
* These nodes mirror the JSX components from `@kubb/renderer-jsx` and are used as
|
|
229
|
+
* structured children in {@link SourceNode.nodes}.
|
|
230
|
+
*/
|
|
231
|
+
type CodeNode = ConstNode | TypeNode | FunctionNode | ArrowFunctionNode | TextNode | BreakNode | JsxNode;
|
|
232
|
+
/**
|
|
233
|
+
* Creates a `ConstNode` representing a TypeScript `const` declaration.
|
|
234
|
+
*
|
|
235
|
+
* @example Exported constant with type and `as const`
|
|
236
|
+
* ```ts
|
|
237
|
+
* createConst({ name: 'pets', export: true, type: 'Pet[]', asConst: true })
|
|
238
|
+
* // export const pets: Pet[] = ... as const
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
declare const createConst: (input: Omit<ConstNode, "kind">) => ConstNode;
|
|
242
|
+
/**
|
|
243
|
+
* Creates a `TypeNode` representing a TypeScript `type` alias declaration.
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* createType({ name: 'Pet', export: true })
|
|
248
|
+
* // export type Pet = ...
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
declare const createType: (input: Omit<TypeNode, "kind">) => TypeNode;
|
|
252
|
+
/**
|
|
253
|
+
* Creates a `FunctionNode` representing a TypeScript `function` declaration.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* createFunction({ name: 'fetchPet', export: true, async: true, returnType: 'Pet' })
|
|
258
|
+
* // export async function fetchPet(): Promise<Pet> { ... }
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
declare const createFunction: (input: Omit<FunctionNode, "kind">) => FunctionNode;
|
|
262
|
+
/**
|
|
263
|
+
* Creates an `ArrowFunctionNode` representing a TypeScript arrow function.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```ts
|
|
267
|
+
* createArrowFunction({ name: 'double', export: true, params: 'n: number', singleLine: true })
|
|
268
|
+
* // export const double = (n: number) => ...
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
declare const createArrowFunction: (input: Omit<ArrowFunctionNode, "kind">) => ArrowFunctionNode;
|
|
272
|
+
/**
|
|
273
|
+
* Creates a {@link TextNode} representing a raw string fragment in the source output.
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* createText('return fetch(id)')
|
|
278
|
+
* // { kind: 'Text', value: 'return fetch(id)' }
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
declare function createText(value: string): TextNode;
|
|
282
|
+
/**
|
|
283
|
+
* Creates a {@link BreakNode} representing a line break in the source output.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* createBreak()
|
|
288
|
+
* // { kind: 'Break' }
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
declare function createBreak(): BreakNode;
|
|
292
|
+
/**
|
|
293
|
+
* Creates a {@link JsxNode} representing a raw JSX fragment in the source output.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* createJsx('<>\n <a href={href}>Open</a>\n</>')
|
|
298
|
+
* // { kind: 'Jsx', value: '<>\n <a href={href}>Open</a>\n</>' }
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
declare function createJsx(value: string): JsxNode;
|
|
302
|
+
/**
|
|
303
|
+
* Supported file extensions.
|
|
304
|
+
*/
|
|
305
|
+
type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
|
|
306
|
+
type ImportName = string | Array<string | {
|
|
307
|
+
propertyName: string;
|
|
308
|
+
name?: string;
|
|
309
|
+
}>;
|
|
310
|
+
/**
|
|
311
|
+
* Represents a language-agnostic import/dependency declaration.
|
|
312
|
+
*
|
|
313
|
+
* @example Named import (TypeScript: `import { useState } from 'react'`)
|
|
314
|
+
* ```ts
|
|
315
|
+
* createImport({ name: ['useState'], path: 'react' })
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @example Default import (TypeScript: `import React from 'react'`)
|
|
319
|
+
* ```ts
|
|
320
|
+
* createImport({ name: 'React', path: 'react' })
|
|
321
|
+
* ```
|
|
322
|
+
*
|
|
323
|
+
* @example Type-only import (TypeScript: `import type { FC } from 'react'`)
|
|
324
|
+
* ```ts
|
|
325
|
+
* createImport({ name: ['FC'], path: 'react', isTypeOnly: true })
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* @example Namespace import (TypeScript: `import * as React from 'react'`)
|
|
329
|
+
* ```ts
|
|
330
|
+
* createImport({ name: 'React', path: 'react', isNameSpace: true })
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
type ImportNode = BaseNode & {
|
|
334
|
+
kind: 'Import';
|
|
335
|
+
/**
|
|
336
|
+
* Import name(s) to be used.
|
|
337
|
+
*
|
|
338
|
+
* @example Named imports
|
|
339
|
+
* `['useState']`
|
|
340
|
+
*
|
|
341
|
+
* @example Default import
|
|
342
|
+
* `'React'`
|
|
343
|
+
*/
|
|
344
|
+
name: ImportName;
|
|
345
|
+
/**
|
|
346
|
+
* Path for the import.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* `'@kubb/core'`
|
|
350
|
+
*/
|
|
351
|
+
path: string;
|
|
352
|
+
/**
|
|
353
|
+
* Add a type-only import prefix.
|
|
354
|
+
* - `true` generates `import type { Type } from './path'`
|
|
355
|
+
* - `false` generates `import { Type } from './path'`
|
|
356
|
+
*/
|
|
357
|
+
isTypeOnly?: boolean | null;
|
|
358
|
+
/**
|
|
359
|
+
* Import the entire module as a namespace.
|
|
360
|
+
* - `true` generates `import * as Name from './path'`
|
|
361
|
+
* - `false` generates a standard import
|
|
362
|
+
*/
|
|
363
|
+
isNameSpace?: boolean | null;
|
|
364
|
+
/**
|
|
365
|
+
* When set, the import path is resolved relative to this root.
|
|
366
|
+
*/
|
|
367
|
+
root?: string | null;
|
|
368
|
+
};
|
|
369
|
+
/**
|
|
370
|
+
* Represents a language-agnostic export/public API declaration.
|
|
371
|
+
*
|
|
372
|
+
* @example Named export (TypeScript: `export { Pets } from './Pets'`)
|
|
373
|
+
* ```ts
|
|
374
|
+
* createExport({ name: ['Pets'], path: './Pets' })
|
|
375
|
+
* ```
|
|
376
|
+
*
|
|
377
|
+
* @example Type-only export (TypeScript: `export type { Pet } from './Pet'`)
|
|
378
|
+
* ```ts
|
|
379
|
+
* createExport({ name: ['Pet'], path: './Pet', isTypeOnly: true })
|
|
380
|
+
* ```
|
|
381
|
+
*
|
|
382
|
+
* @example Wildcard export (TypeScript: `export * from './utils'`)
|
|
383
|
+
* ```ts
|
|
384
|
+
* createExport({ path: './utils' })
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
387
|
+
* @example Namespace alias (TypeScript: `export * as utils from './utils'`)
|
|
388
|
+
* ```ts
|
|
389
|
+
* createExport({ name: 'utils', path: './utils', asAlias: true })
|
|
390
|
+
* ```
|
|
391
|
+
*/
|
|
392
|
+
type ExportNode = BaseNode & {
|
|
393
|
+
kind: 'Export';
|
|
394
|
+
/**
|
|
395
|
+
* Export name(s) to be used. When omitted, generates a wildcard export.
|
|
396
|
+
*
|
|
397
|
+
* @example Named exports
|
|
398
|
+
* `['useState']`
|
|
399
|
+
*
|
|
400
|
+
* @example Single export
|
|
401
|
+
* `'React'`
|
|
402
|
+
*/
|
|
403
|
+
name?: string | Array<string> | null;
|
|
404
|
+
/**
|
|
405
|
+
* Path for the export.
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* `'@kubb/core'`
|
|
409
|
+
*/
|
|
410
|
+
path: string;
|
|
411
|
+
/**
|
|
412
|
+
* Add a type-only export prefix.
|
|
413
|
+
* - `true` generates `export type { Type } from './path'`
|
|
414
|
+
* - `false` generates `export { Type } from './path'`
|
|
415
|
+
*/
|
|
416
|
+
isTypeOnly?: boolean | null;
|
|
417
|
+
/**
|
|
418
|
+
* Export as an aliased namespace.
|
|
419
|
+
* - `true` generates `export * as aliasName from './path'`
|
|
420
|
+
* - `false` generates a standard export
|
|
421
|
+
*/
|
|
422
|
+
asAlias?: boolean | null;
|
|
423
|
+
};
|
|
424
|
+
/**
|
|
425
|
+
* Represents a fragment of source code within a file.
|
|
426
|
+
*
|
|
427
|
+
* @example Named exportable source
|
|
428
|
+
* ```ts
|
|
429
|
+
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true, isIndexable: true })
|
|
430
|
+
* ```
|
|
431
|
+
*
|
|
432
|
+
* @example Inline unnamed code block
|
|
433
|
+
* ```ts
|
|
434
|
+
* createSource({ nodes: [createText('const x = 1')] })
|
|
435
|
+
* ```
|
|
436
|
+
*/
|
|
437
|
+
type SourceNode = BaseNode & {
|
|
438
|
+
kind: 'Source';
|
|
439
|
+
/**
|
|
440
|
+
* Optional name identifying this source (used for deduplication and barrel generation).
|
|
441
|
+
*/
|
|
442
|
+
name?: string | null;
|
|
443
|
+
/**
|
|
444
|
+
* Mark this source as a type-only export.
|
|
445
|
+
*/
|
|
446
|
+
isTypeOnly?: boolean | null;
|
|
447
|
+
/**
|
|
448
|
+
* Mark this source as an exported declaration. The source text carries its own `export` keyword.
|
|
449
|
+
*/
|
|
450
|
+
isExportable?: boolean | null;
|
|
451
|
+
/**
|
|
452
|
+
* Include this source in barrel/index file generation.
|
|
453
|
+
*/
|
|
454
|
+
isIndexable?: boolean | null;
|
|
455
|
+
/**
|
|
456
|
+
* Marks the source as a definition that importing files absorb instead of import. `expression` is
|
|
457
|
+
* the declaration's right-hand side, such as `{ body: Pet }`.
|
|
458
|
+
*/
|
|
459
|
+
inline?: {
|
|
460
|
+
expression: string;
|
|
461
|
+
} | null;
|
|
462
|
+
/**
|
|
463
|
+
* Child nodes that make up this source fragment, in DOM order.
|
|
464
|
+
* Use a {@link TextNode} for raw string content.
|
|
465
|
+
*/
|
|
466
|
+
nodes?: Array<CodeNode>;
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* Represents a fully resolved file in the AST.
|
|
470
|
+
*
|
|
471
|
+
* Created via `createFile()`, which computes the `id`, `name`, and `extname` from the input
|
|
472
|
+
* and deduplicates `imports`, `exports`, and `sources`.
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```ts
|
|
476
|
+
* const file = createFile({
|
|
477
|
+
* baseName: 'petStore.ts',
|
|
478
|
+
* path: 'src/models/petStore.ts',
|
|
479
|
+
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })],
|
|
480
|
+
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
481
|
+
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
482
|
+
* })
|
|
483
|
+
* // file.id = SHA256 hash of the path
|
|
484
|
+
* // file.name = 'petStore'
|
|
485
|
+
* // file.extname = '.ts'
|
|
486
|
+
* ```
|
|
487
|
+
*/
|
|
488
|
+
type FileNode<TMeta extends object = object> = BaseNode & {
|
|
489
|
+
kind: 'File';
|
|
490
|
+
/**
|
|
491
|
+
* Unique identifier derived from a SHA256 hash of the file path. `createFile`
|
|
492
|
+
* computes it, so callers do not need to provide it.
|
|
493
|
+
*/
|
|
494
|
+
id: string;
|
|
495
|
+
/**
|
|
496
|
+
* File name without extension, derived from `baseName`.
|
|
497
|
+
*
|
|
498
|
+
* @see https://nodejs.org/api/path.html#pathformatpathobject
|
|
499
|
+
*/
|
|
500
|
+
name: string;
|
|
501
|
+
/**
|
|
502
|
+
* File base name, including extension, shaped like `${name}${extname}`.
|
|
503
|
+
*
|
|
504
|
+
* @see https://nodejs.org/api/path.html#pathbasenamepath-suffix
|
|
505
|
+
*/
|
|
506
|
+
baseName: `${string}.${string}`;
|
|
507
|
+
/**
|
|
508
|
+
* Full qualified path to the file.
|
|
509
|
+
*/
|
|
510
|
+
path: string;
|
|
511
|
+
/**
|
|
512
|
+
* File extension extracted from `baseName`.
|
|
513
|
+
*/
|
|
514
|
+
extname: Extname;
|
|
515
|
+
/**
|
|
516
|
+
* Deduplicated list of source code fragments.
|
|
517
|
+
*/
|
|
518
|
+
sources: Array<SourceNode>;
|
|
519
|
+
/**
|
|
520
|
+
* Deduplicated list of import declarations.
|
|
521
|
+
*/
|
|
522
|
+
imports: Array<ImportNode>;
|
|
523
|
+
/**
|
|
524
|
+
* Deduplicated list of export declarations.
|
|
525
|
+
*/
|
|
526
|
+
exports: Array<ExportNode>;
|
|
527
|
+
/**
|
|
528
|
+
* Optional metadata attached to this file, read by plugins during barrel generation.
|
|
529
|
+
*/
|
|
530
|
+
meta?: TMeta;
|
|
531
|
+
/**
|
|
532
|
+
* Optional banner prepended to the generated file content.
|
|
533
|
+
* Accepts `null` so `resolver.default.banner()` results can be passed directly.
|
|
534
|
+
*/
|
|
535
|
+
banner?: string | null;
|
|
536
|
+
/**
|
|
537
|
+
* Optional footer appended to the generated file content.
|
|
538
|
+
* Accepts `null` so `resolver.default.footer()` results can be passed directly.
|
|
539
|
+
*/
|
|
540
|
+
footer?: string | null;
|
|
541
|
+
/**
|
|
542
|
+
* Absolute on-disk path to copy into the output, through the parser's `copy` hook when it has one.
|
|
543
|
+
*
|
|
544
|
+
* Use to emit a real source file shipped inside a package (a template) into the generated
|
|
545
|
+
* folder. When set, `copy` provides the file content and any `sources` nodes are ignored for
|
|
546
|
+
* output; `sources` may still carry `name`/`isExportable`/`isIndexable` so barrel generation
|
|
547
|
+
* treats the file the same as a rendered one.
|
|
548
|
+
*/
|
|
549
|
+
copy?: string | null;
|
|
550
|
+
};
|
|
551
|
+
/**
|
|
552
|
+
* Creates an `ImportNode` representing a language-agnostic import/dependency declaration.
|
|
553
|
+
*
|
|
554
|
+
* @example Named import
|
|
555
|
+
* ```ts
|
|
556
|
+
* createImport({ name: ['useState'], path: 'react' })
|
|
557
|
+
* // import { useState } from 'react'
|
|
558
|
+
* ```
|
|
559
|
+
*/
|
|
560
|
+
declare const createImport: (input: Omit<ImportNode, "kind">) => ImportNode;
|
|
561
|
+
/**
|
|
562
|
+
* Creates an `ExportNode` representing a language-agnostic export/public API declaration.
|
|
563
|
+
*
|
|
564
|
+
* @example Named export
|
|
565
|
+
* ```ts
|
|
566
|
+
* createExport({ name: ['Pet'], path: './Pet' })
|
|
567
|
+
* // export { Pet } from './Pet'
|
|
568
|
+
* ```
|
|
569
|
+
*/
|
|
570
|
+
declare const createExport: (input: Omit<ExportNode, "kind">) => ExportNode;
|
|
571
|
+
/**
|
|
572
|
+
* Creates a `SourceNode` representing a fragment of source code within a file.
|
|
573
|
+
*
|
|
574
|
+
* @example
|
|
575
|
+
* ```ts
|
|
576
|
+
* createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')], isExportable: true })
|
|
577
|
+
* ```
|
|
578
|
+
*/
|
|
579
|
+
declare const createSource: (input: Omit<SourceNode, "kind">) => SourceNode;
|
|
580
|
+
/**
|
|
581
|
+
* Input descriptor for {@link createFile}, before `id`, `name`, and `extname` are computed
|
|
582
|
+
* and `imports`/`exports`/`sources` are deduplicated.
|
|
583
|
+
*/
|
|
584
|
+
type UserFileNode<TMeta extends object = object> = Omit<FileNode<TMeta>, 'kind' | 'id' | 'name' | 'extname' | 'imports' | 'exports' | 'sources'> & Pick<Partial<FileNode<TMeta>>, 'imports' | 'exports' | 'sources'>;
|
|
585
|
+
/**
|
|
586
|
+
* Creates a fully resolved `FileNode` from a file input descriptor.
|
|
587
|
+
*
|
|
588
|
+
* Computes:
|
|
589
|
+
* - `id` SHA256 hash of the file path
|
|
590
|
+
* - `name` `baseName` without extension
|
|
591
|
+
* - `extname` extension extracted from `baseName`
|
|
592
|
+
*
|
|
593
|
+
* Deduplicates:
|
|
594
|
+
* - `sources` via `combineSources`
|
|
595
|
+
* - `exports` via `combineExports`
|
|
596
|
+
* - `imports` via `combineImports` (also filters unused imports)
|
|
597
|
+
*
|
|
598
|
+
* @throws {Error} when `baseName` has no extension.
|
|
599
|
+
*
|
|
600
|
+
* @example
|
|
601
|
+
* ```ts
|
|
602
|
+
* const file = createFile({
|
|
603
|
+
* baseName: 'petStore.ts',
|
|
604
|
+
* path: 'src/models/petStore.ts',
|
|
605
|
+
* sources: [createSource({ name: 'Pet', nodes: [createText('export type Pet = { id: number }')] })],
|
|
606
|
+
* imports: [createImport({ name: ['z'], path: 'zod' })],
|
|
607
|
+
* exports: [createExport({ name: ['Pet'], path: './petStore' })],
|
|
608
|
+
* })
|
|
609
|
+
* // file.id = SHA256 hash of 'src/models/petStore.ts'
|
|
610
|
+
* // file.name = 'petStore'
|
|
611
|
+
* // file.extname = '.ts'
|
|
612
|
+
* ```
|
|
613
|
+
*
|
|
614
|
+
* @example Copy a real file into the output
|
|
615
|
+
* ```ts
|
|
616
|
+
* const file = createFile({
|
|
617
|
+
* baseName: 'client.ts',
|
|
618
|
+
* path: 'src/gen/client.ts',
|
|
619
|
+
* copy: '/abs/path/to/templates/client.ts',
|
|
620
|
+
* })
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
declare function createFile<TMeta extends object = object>(input: UserFileNode<TMeta>): FileNode<TMeta>;
|
|
624
|
+
export { createJsx as C, createFunction as S, createType as T, TextNode as _, UserFileNode as a, createBreak as b, createImport as c, BreakNode as d, CodeNode as f, JsxNode as g, JSDocNode as h, SourceNode as i, createSource as l, FunctionNode as m, FileNode as n, createExport as o, ConstNode as p, ImportNode as r, createFile as s, ExportNode as t, ArrowFunctionNode as u, TypeNode as v, createText as w, createConst as x, createArrowFunction as y };
|