@hey-api/codegen-core 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +358 -477
- package/dist/index.d.ts +358 -477
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
//#region src/bimap/types.d.ts
|
|
1
2
|
/**
|
|
2
3
|
* Bi-directional map interface.
|
|
3
4
|
*
|
|
@@ -6,7 +7,7 @@
|
|
|
6
7
|
* @template Key Type of the map keys
|
|
7
8
|
* @template Value Type of the map values
|
|
8
9
|
*/
|
|
9
|
-
interface
|
|
10
|
+
interface IBiMap<Key, Value> {
|
|
10
11
|
/**
|
|
11
12
|
* Deletes a key and its associated value from the map.
|
|
12
13
|
*
|
|
@@ -72,651 +73,531 @@ interface ICodegenBiMap<Key, Value> {
|
|
|
72
73
|
*/
|
|
73
74
|
[Symbol.iterator](): IterableIterator<[Key, Value]>;
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
private reverse;
|
|
79
|
-
delete(key: Key): boolean;
|
|
80
|
-
deleteValue(value: Value): boolean;
|
|
81
|
-
entries(): IterableIterator<[Key, Value]>;
|
|
82
|
-
get(key: Key): Value | undefined;
|
|
83
|
-
getKey(value: Value): Key | undefined;
|
|
84
|
-
hasKey(key: Key): boolean;
|
|
85
|
-
hasValue(value: Value): boolean;
|
|
86
|
-
keys(): IterableIterator<Key>;
|
|
87
|
-
set(key: Key, value: Value): this;
|
|
88
|
-
get size(): number;
|
|
89
|
-
values(): IterableIterator<Value>;
|
|
90
|
-
[Symbol.iterator](): IterableIterator<[Key, Value]>;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Arbitrary metadata passed to render functions.
|
|
95
|
-
*
|
|
96
|
-
* Implementors should extend this interface for their own needs.
|
|
97
|
-
*/
|
|
98
|
-
interface ICodegenMeta {
|
|
99
|
-
[key: string]: unknown;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
interface ICodegenOutput {
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/bindings/types.d.ts
|
|
78
|
+
interface IBinding {
|
|
103
79
|
/**
|
|
104
|
-
*
|
|
80
|
+
* Optional aliasing map for named symbols.
|
|
105
81
|
*
|
|
106
|
-
*
|
|
82
|
+
* Keys must be a subset of `names`, values are aliases.
|
|
107
83
|
*
|
|
108
|
-
* @example
|
|
84
|
+
* @example { User: "ImportedUser" }
|
|
109
85
|
*/
|
|
110
|
-
|
|
86
|
+
aliases?: Record<string, string>;
|
|
111
87
|
/**
|
|
112
|
-
*
|
|
113
|
-
* source maps, or language-specific flags.
|
|
88
|
+
* Name of the default binding, if any.
|
|
114
89
|
*
|
|
115
|
-
* @example
|
|
90
|
+
* @example "React"
|
|
116
91
|
*/
|
|
117
|
-
|
|
92
|
+
defaultBinding?: string;
|
|
118
93
|
/**
|
|
119
|
-
*
|
|
94
|
+
* Source file or external module from which symbols are imported.
|
|
120
95
|
*
|
|
121
|
-
* @example "models/user
|
|
96
|
+
* @example "./models/user"
|
|
97
|
+
* @example "node:path"
|
|
122
98
|
*/
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
interface ICodegenRenderer {
|
|
99
|
+
from: string;
|
|
127
100
|
/**
|
|
128
|
-
*
|
|
101
|
+
* Names of the symbols imported from the source.
|
|
102
|
+
*
|
|
103
|
+
* Must be non-empty unless `namespaceBinding` is true.
|
|
104
|
+
* All imported names, regardless of whether they are used as types or values.
|
|
105
|
+
*
|
|
106
|
+
* @example ["User", "UserDTO"]
|
|
129
107
|
*/
|
|
130
|
-
|
|
108
|
+
names?: ReadonlyArray<string>;
|
|
131
109
|
/**
|
|
132
|
-
*
|
|
110
|
+
* If this import is a namespace import (e.g. `import * as ns from "..."`),
|
|
111
|
+
* this should be the namespace alias. Set to `true` if no alias is needed.
|
|
133
112
|
*
|
|
134
|
-
* @example "
|
|
113
|
+
* @example "utils"
|
|
114
|
+
* @example true
|
|
135
115
|
*/
|
|
136
|
-
|
|
116
|
+
namespaceBinding?: boolean | string;
|
|
137
117
|
/**
|
|
138
|
-
*
|
|
118
|
+
* Whether the default binding is type-only.
|
|
139
119
|
*
|
|
140
|
-
* @
|
|
141
|
-
* @param meta Arbitrary metadata.
|
|
142
|
-
* @returns Printable string containing header and imports.
|
|
120
|
+
* @example true
|
|
143
121
|
*/
|
|
144
|
-
|
|
122
|
+
typeDefaultBinding?: boolean;
|
|
145
123
|
/**
|
|
146
|
-
*
|
|
124
|
+
* Subset of `names` that are imported using the `type` modifier.
|
|
125
|
+
* These symbols will be emitted as type-only imports in TypeScript.
|
|
147
126
|
*
|
|
148
|
-
* @
|
|
149
|
-
* @param meta Arbitrary metadata.
|
|
150
|
-
* @returns Printable string containing symbols and exports.
|
|
127
|
+
* @example ["UserDTO"]
|
|
151
128
|
*/
|
|
152
|
-
|
|
129
|
+
typeNames?: ReadonlyArray<string>;
|
|
153
130
|
/**
|
|
154
|
-
*
|
|
131
|
+
* Whether the namespace binding is type-only.
|
|
155
132
|
*
|
|
156
|
-
* @
|
|
133
|
+
* @example true
|
|
157
134
|
*/
|
|
158
|
-
|
|
159
|
-
file: ICodegenFile;
|
|
160
|
-
headless?: boolean;
|
|
161
|
-
scope?: 'file' | 'project';
|
|
162
|
-
symbolId: number;
|
|
163
|
-
}): string | undefined;
|
|
135
|
+
typeNamespaceBinding?: boolean;
|
|
164
136
|
}
|
|
165
|
-
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/selectors/types.d.ts
|
|
166
139
|
/**
|
|
167
|
-
* Selector array used to
|
|
168
|
-
*
|
|
140
|
+
* Selector array used to reference resources. We don't enforce
|
|
141
|
+
* uniqueness, but in practice it's desirable.
|
|
169
142
|
*
|
|
170
143
|
* @example ["zod", "#/components/schemas/Foo"]
|
|
171
144
|
*/
|
|
172
|
-
type
|
|
173
|
-
|
|
174
|
-
|
|
145
|
+
type ISelector = ReadonlyArray<string>;
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/files/types.d.ts
|
|
148
|
+
interface IFileIn {
|
|
175
149
|
/**
|
|
176
|
-
*
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* Example 1: We register headless symbol `foo`, headed `bar`, and headed
|
|
184
|
-
* `foo`. The render order is [`bar`, `foo`].
|
|
185
|
-
*
|
|
186
|
-
* Example 2: We register headed symbol `foo` and headed `bar`. The render
|
|
187
|
-
* order is [`foo`, `bar`].
|
|
188
|
-
*
|
|
189
|
-
* Headless symbols can be used to claim a symbol or to represent imports
|
|
190
|
-
* or exports.
|
|
150
|
+
* File extension, if any.
|
|
151
|
+
*/
|
|
152
|
+
readonly extension?: string;
|
|
153
|
+
/**
|
|
154
|
+
* Indicates whether the file is external, meaning it is not generated
|
|
155
|
+
* as part of the project but is referenced (e.g., a module from
|
|
156
|
+
* node_modules).
|
|
191
157
|
*
|
|
192
|
-
* @
|
|
158
|
+
* @example true
|
|
193
159
|
*/
|
|
194
|
-
|
|
160
|
+
readonly external?: boolean;
|
|
195
161
|
/**
|
|
196
|
-
*
|
|
162
|
+
* Unique file ID. If one is not provided, it will be auto-generated.
|
|
163
|
+
*/
|
|
164
|
+
readonly id?: number;
|
|
165
|
+
/**
|
|
166
|
+
* The desired name for the file within the project. If there are multiple files
|
|
197
167
|
* with the same desired name, this might not end up being the actual name.
|
|
198
168
|
*
|
|
199
169
|
* @example "UserModel"
|
|
200
170
|
*/
|
|
201
|
-
readonly name
|
|
171
|
+
readonly name?: string;
|
|
202
172
|
/**
|
|
203
|
-
*
|
|
173
|
+
* Absolute logical output path for the file.
|
|
174
|
+
*
|
|
175
|
+
* @example "/src/models/user.ts"
|
|
176
|
+
*/
|
|
177
|
+
readonly path?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Selector array used to select this file. It doesn't have to be
|
|
204
180
|
* unique, but in practice it might be desirable.
|
|
205
181
|
*
|
|
206
182
|
* @example ["zod", "#/components/schemas/Foo"]
|
|
207
183
|
*/
|
|
208
|
-
readonly selector?:
|
|
184
|
+
readonly selector?: ISelector;
|
|
185
|
+
}
|
|
186
|
+
interface IFileOut extends IFileIn {
|
|
209
187
|
/**
|
|
210
|
-
*
|
|
211
|
-
* Used to generate output. If left undefined, this symbol becomes `headless`.
|
|
188
|
+
* Unique file ID.
|
|
212
189
|
*/
|
|
213
|
-
readonly
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
interface ICodegenSymbolOut extends ICodegenSymbolIn {
|
|
190
|
+
readonly id: number;
|
|
217
191
|
/**
|
|
218
|
-
*
|
|
192
|
+
* Map holding resolved names for symbols in this file.
|
|
219
193
|
*/
|
|
220
|
-
readonly
|
|
194
|
+
readonly resolvedNames: IBiMap<number, string>;
|
|
221
195
|
/**
|
|
222
|
-
*
|
|
196
|
+
* Symbols in this file, categorized by their role.
|
|
223
197
|
*/
|
|
224
|
-
readonly
|
|
198
|
+
readonly symbols: {
|
|
199
|
+
/**
|
|
200
|
+
* Symbols declared in the body of this file.
|
|
201
|
+
*/
|
|
202
|
+
body: Array<number>;
|
|
203
|
+
/**
|
|
204
|
+
* Symbols re-exported from other files.
|
|
205
|
+
*/
|
|
206
|
+
exports: Array<number>;
|
|
207
|
+
/**
|
|
208
|
+
* Symbols imported from other files.
|
|
209
|
+
*/
|
|
210
|
+
imports: Array<number>;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
interface IFileRegistry {
|
|
225
214
|
/**
|
|
226
|
-
*
|
|
215
|
+
* Get a file by its ID.
|
|
227
216
|
*
|
|
228
|
-
* @
|
|
217
|
+
* @param fileIdOrSelector File ID or selector to reference.
|
|
218
|
+
* @returns The file, or undefined if not found.
|
|
229
219
|
*/
|
|
230
|
-
|
|
220
|
+
get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
|
|
231
221
|
/**
|
|
232
|
-
*
|
|
222
|
+
* Returns the current file ID and increments it.
|
|
233
223
|
*
|
|
234
|
-
* @
|
|
235
|
-
* @returns The updated symbol.
|
|
224
|
+
* @returns File ID before being incremented
|
|
236
225
|
*/
|
|
237
|
-
readonly
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
interface SelectorMethods {
|
|
226
|
+
readonly id: number;
|
|
241
227
|
/**
|
|
242
|
-
*
|
|
228
|
+
* Returns a file by ID or selector, registering it if it doesn't exist.
|
|
243
229
|
*
|
|
244
|
-
* @param
|
|
245
|
-
* @
|
|
246
|
-
* @returns The array of all symbols matching the selector.
|
|
247
|
-
* @example
|
|
248
|
-
* const symbols = project.selectSymbolAll(["zod", "#/components/schemas/Foo"]);
|
|
230
|
+
* @param fileIdOrSelector File ID or selector to reference.
|
|
231
|
+
* @returns The referenced or newly registered file.
|
|
249
232
|
*/
|
|
250
|
-
|
|
251
|
-
selector: ICodegenSymbolSelector,
|
|
252
|
-
file?: ICodegenFile,
|
|
253
|
-
): ReadonlyArray<ICodegenSymbolOut>;
|
|
233
|
+
reference(fileIdOrSelector: number | ISelector): IFileOut;
|
|
254
234
|
/**
|
|
255
|
-
*
|
|
235
|
+
* Get all unregistered files in the order they were referenced.
|
|
256
236
|
*
|
|
257
|
-
* @
|
|
258
|
-
* @param file Find symbols only in this file.
|
|
259
|
-
* @returns The symbol if found, or undefined otherwise.
|
|
260
|
-
* @example
|
|
261
|
-
* const symbol = project.selectSymbolFirst(["zod", "#/components/schemas/Foo"]);
|
|
237
|
+
* @returns Array of all unregistered files, in reference order.
|
|
262
238
|
*/
|
|
263
|
-
|
|
264
|
-
selector: ICodegenSymbolSelector,
|
|
265
|
-
file?: ICodegenFile,
|
|
266
|
-
): ICodegenSymbolOut | undefined;
|
|
239
|
+
referenced(): IterableIterator<IFileOut>;
|
|
267
240
|
/**
|
|
268
|
-
*
|
|
241
|
+
* Register a file globally.
|
|
269
242
|
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
* @
|
|
273
|
-
* @
|
|
274
|
-
* const symbol = project.selectSymbolFirstOrThrow(["zod", "#/components/schemas/Foo"]);
|
|
243
|
+
* Deduplicates identical files by ID.
|
|
244
|
+
*
|
|
245
|
+
* @param file File to register.
|
|
246
|
+
* @returns true if added, false if duplicate.
|
|
275
247
|
*/
|
|
276
|
-
|
|
277
|
-
selector: ICodegenSymbolSelector,
|
|
278
|
-
file?: ICodegenFile,
|
|
279
|
-
): ICodegenSymbolOut;
|
|
248
|
+
register(file: IFileIn): IFileOut;
|
|
280
249
|
/**
|
|
281
|
-
*
|
|
250
|
+
* Get all files in the order they were registered.
|
|
282
251
|
*
|
|
283
|
-
* @
|
|
284
|
-
* @param file Find symbols only in this file.
|
|
285
|
-
* @returns The symbol if found, or undefined otherwise.
|
|
286
|
-
* @example
|
|
287
|
-
* const symbol = project.selectSymbolLast(["zod", "#/components/schemas/Foo"]);
|
|
252
|
+
* @returns Array of all registered files, in insert order.
|
|
288
253
|
*/
|
|
289
|
-
|
|
290
|
-
selector: ICodegenSymbolSelector,
|
|
291
|
-
file?: ICodegenFile,
|
|
292
|
-
): ICodegenSymbolOut | undefined;
|
|
254
|
+
registered(): IterableIterator<IFileOut>;
|
|
293
255
|
}
|
|
294
|
-
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region src/extensions/types.d.ts
|
|
295
258
|
/**
|
|
296
|
-
*
|
|
297
|
-
*
|
|
259
|
+
* Arbitrary metadata passed to the project's render function.
|
|
260
|
+
*
|
|
261
|
+
* Implementers should extend this interface for their own needs.
|
|
262
|
+
*/
|
|
263
|
+
interface IProjectRenderMeta {
|
|
264
|
+
[key: string]: unknown;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Additional metadata about the symbol.
|
|
268
|
+
*
|
|
269
|
+
* Implementers should extend this interface for their own needs.
|
|
298
270
|
*/
|
|
299
|
-
interface
|
|
271
|
+
interface ISymbolMeta {
|
|
272
|
+
[key: string]: unknown;
|
|
273
|
+
}
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/symbols/types.d.ts
|
|
276
|
+
interface ISymbolIn {
|
|
300
277
|
/**
|
|
301
|
-
*
|
|
278
|
+
* Array of file names (without extensions) from which this symbol is re-exported.
|
|
302
279
|
*
|
|
303
|
-
* @
|
|
304
|
-
* @param imp - The export declaration to add.
|
|
305
|
-
* @example
|
|
306
|
-
* project.addExport("models/user.ts", { from: "lib", names: ["User"] });
|
|
280
|
+
* @default undefined
|
|
307
281
|
*/
|
|
308
|
-
|
|
282
|
+
readonly exportFrom?: ReadonlyArray<string>;
|
|
309
283
|
/**
|
|
310
|
-
*
|
|
284
|
+
* Whether this symbol is exported from its own file.
|
|
311
285
|
*
|
|
312
|
-
* @
|
|
313
|
-
* @param imp - The import declaration to add.
|
|
314
|
-
* @example
|
|
315
|
-
* project.addImport("models/user.ts", { from: "lib", names: ["User"] });
|
|
286
|
+
* @default false
|
|
316
287
|
*/
|
|
317
|
-
|
|
288
|
+
readonly exported?: boolean;
|
|
318
289
|
/**
|
|
319
|
-
*
|
|
290
|
+
* External module name if this symbol is imported from a module not managed
|
|
291
|
+
* by the project (e.g. "zod", "lodash").
|
|
320
292
|
*
|
|
321
|
-
* @
|
|
322
|
-
* @param symbol - The symbol to add.
|
|
323
|
-
* @returns The inserted symbol.
|
|
324
|
-
* @example
|
|
325
|
-
* project.addSymbol("models/user.ts", { name: "User", value: tsNode });
|
|
293
|
+
* @default undefined
|
|
326
294
|
*/
|
|
327
|
-
|
|
328
|
-
fileOrPath: ICodegenFile | string,
|
|
329
|
-
symbol: ICodegenSymbolIn,
|
|
330
|
-
): ICodegenSymbolOut;
|
|
295
|
+
readonly external?: string;
|
|
331
296
|
/**
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
* If a file with the same path already exists, it is returned instead.
|
|
297
|
+
* Optional output strategy to override default behavior.
|
|
335
298
|
*
|
|
336
|
-
* @
|
|
337
|
-
* @param meta - Optional renderer and metadata to attach to the file (e.g. { isInternal: true }).
|
|
338
|
-
* @returns The newly created file instance.
|
|
339
|
-
* @example
|
|
340
|
-
* const file = project.createFile("models/user.ts", { isInternal: true });
|
|
299
|
+
* @returns The file path to output the symbol to, or undefined to fallback to default behavior.
|
|
341
300
|
*/
|
|
342
|
-
|
|
343
|
-
path: string,
|
|
344
|
-
meta?: ICodegenFile['meta'] & { renderer?: ICodegenRenderer },
|
|
345
|
-
): ICodegenFile;
|
|
301
|
+
readonly getFilePath?: (symbol: ISymbolOut) => string | undefined;
|
|
346
302
|
/**
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
* If a file does not exist yet, it is created with minimal information.
|
|
350
|
-
* Later, it is expected `createFile()` will be called which will fill in
|
|
351
|
-
* the missing information such as optional metadata.
|
|
352
|
-
*
|
|
353
|
-
* @param fileOrPath - The logical output path for the file or the file itself.
|
|
354
|
-
* @returns The file instance.
|
|
355
|
-
* @example
|
|
356
|
-
* const file = project.ensureFile("models/user.ts");
|
|
303
|
+
* Unique symbol ID. If one is not provided, it will be auto-generated.
|
|
357
304
|
*/
|
|
358
|
-
|
|
305
|
+
readonly id?: number;
|
|
359
306
|
/**
|
|
360
|
-
*
|
|
307
|
+
* Arbitrary metadata about the symbol.
|
|
361
308
|
*
|
|
362
|
-
* @
|
|
363
|
-
* project.files.forEach(file => console.log(file.path));
|
|
309
|
+
* @default undefined
|
|
364
310
|
*/
|
|
365
|
-
readonly
|
|
311
|
+
readonly meta?: ISymbolMeta & {
|
|
312
|
+
/**
|
|
313
|
+
* Kind of import if this symbol represents an import.
|
|
314
|
+
*/
|
|
315
|
+
importKind?: 'namespace' | 'default' | 'named';
|
|
316
|
+
/**
|
|
317
|
+
* Kind of symbol.
|
|
318
|
+
*/
|
|
319
|
+
kind?: 'type';
|
|
320
|
+
};
|
|
366
321
|
/**
|
|
367
|
-
*
|
|
322
|
+
* The desired name for the symbol within its file. If there are multiple symbols
|
|
323
|
+
* with the same desired name, this might not end up being the actual name.
|
|
368
324
|
*
|
|
369
|
-
* @
|
|
370
|
-
* @example
|
|
371
|
-
* project.getAllSymbols().filter(s => s.name === "User");
|
|
325
|
+
* @example "UserModel"
|
|
372
326
|
*/
|
|
373
|
-
|
|
327
|
+
readonly name?: string;
|
|
374
328
|
/**
|
|
375
|
-
*
|
|
329
|
+
* Placeholder name for the symbol to be replaced later with the final value.
|
|
376
330
|
*
|
|
377
|
-
* @
|
|
378
|
-
* @returns The file if found, or undefined otherwise.
|
|
379
|
-
* @example
|
|
380
|
-
* const file = project.getFileByPath("models/user.ts");
|
|
331
|
+
* @example "_heyapi_31_"
|
|
381
332
|
*/
|
|
382
|
-
|
|
333
|
+
readonly placeholder?: string;
|
|
383
334
|
/**
|
|
384
|
-
*
|
|
335
|
+
* Selector array used to select this symbol. It doesn't have to be
|
|
336
|
+
* unique, but in practice it might be desirable.
|
|
385
337
|
*
|
|
386
|
-
* @
|
|
387
|
-
* @returns The file if found, undefined otherwise.
|
|
388
|
-
* @example
|
|
389
|
-
* const file = project.getFileBySymbolId(31);
|
|
338
|
+
* @example ["zod", "#/components/schemas/Foo"]
|
|
390
339
|
*/
|
|
391
|
-
|
|
340
|
+
readonly selector?: ISelector;
|
|
341
|
+
}
|
|
342
|
+
interface ISymbolOut extends ISymbolIn {
|
|
392
343
|
/**
|
|
393
|
-
*
|
|
394
|
-
*
|
|
395
|
-
* @param id The symbol ID to find.
|
|
396
|
-
* @returns The symbol if found, undefined otherwise.
|
|
397
|
-
* @example
|
|
398
|
-
* const symbol = project.getSymbolById(31);
|
|
344
|
+
* Array of file names (without extensions) from which this symbol is re-exported.
|
|
399
345
|
*/
|
|
400
|
-
|
|
346
|
+
readonly exportFrom: ReadonlyArray<string>;
|
|
401
347
|
/**
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
* @returns File ID before being incremented
|
|
348
|
+
* Unique symbol ID.
|
|
405
349
|
*/
|
|
406
|
-
|
|
350
|
+
readonly id: number;
|
|
407
351
|
/**
|
|
408
|
-
*
|
|
352
|
+
* Placeholder name for the symbol to be replaced later with the final value.
|
|
409
353
|
*
|
|
410
|
-
* @
|
|
354
|
+
* @example "_heyapi_31_"
|
|
411
355
|
*/
|
|
412
|
-
|
|
356
|
+
readonly placeholder: string;
|
|
357
|
+
}
|
|
358
|
+
interface ISymbolRegistry {
|
|
413
359
|
/**
|
|
414
|
-
*
|
|
360
|
+
* Get a symbol by its ID.
|
|
415
361
|
*
|
|
416
|
-
* @param
|
|
417
|
-
* @
|
|
362
|
+
* @param symbolIdOrSelector Symbol ID or selector to reference.
|
|
363
|
+
* @returns The symbol, or undefined if not found.
|
|
418
364
|
*/
|
|
419
|
-
|
|
365
|
+
get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
|
|
420
366
|
/**
|
|
421
|
-
*
|
|
367
|
+
* Returns the value associated with a symbol ID.
|
|
422
368
|
*
|
|
423
|
-
* @param
|
|
424
|
-
* @
|
|
425
|
-
* @example
|
|
426
|
-
* project.render().forEach(output => writeFile(output));
|
|
369
|
+
* @param symbolId Symbol ID.
|
|
370
|
+
* @return The value associated with the symbol ID, or undefined if not found.
|
|
427
371
|
*/
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
interface ICodegenFile extends SelectorMethods {
|
|
372
|
+
getValue(symbolId: number): unknown;
|
|
432
373
|
/**
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* This is also known as a re-export.
|
|
374
|
+
* Checks if the registry has a value associated with a symbol ID.
|
|
436
375
|
*
|
|
437
|
-
* @param
|
|
376
|
+
* @param symbolId Symbol ID.
|
|
377
|
+
* @returns True if the registry has a value for symbol ID, false otherwise.
|
|
438
378
|
*/
|
|
439
|
-
|
|
379
|
+
hasValue(symbolId: number): boolean;
|
|
440
380
|
/**
|
|
441
|
-
*
|
|
381
|
+
* Returns the current symbol ID and increments it.
|
|
442
382
|
*
|
|
443
|
-
* @
|
|
383
|
+
* @returns Symbol ID before being incremented.
|
|
444
384
|
*/
|
|
445
|
-
|
|
385
|
+
readonly id: number;
|
|
446
386
|
/**
|
|
447
|
-
*
|
|
387
|
+
* Returns a symbol by ID or selector, registering it if it doesn't exist.
|
|
448
388
|
*
|
|
449
|
-
* @param
|
|
389
|
+
* @param symbolIdOrSelector Symbol ID or selector to reference.
|
|
390
|
+
* @returns The referenced or newly registered symbol.
|
|
450
391
|
*/
|
|
451
|
-
|
|
392
|
+
reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
|
|
452
393
|
/**
|
|
453
|
-
*
|
|
454
|
-
* safely used.
|
|
394
|
+
* Register a symbol globally.
|
|
455
395
|
*
|
|
456
|
-
*
|
|
457
|
-
* to match a symbol. If there's no match, we create a headless
|
|
458
|
-
* instance with the provided fields.
|
|
459
|
-
* @returns The symbol if it exists, headless instance otherwise.
|
|
460
|
-
*/
|
|
461
|
-
ensureSymbol(
|
|
462
|
-
symbol: Partial<ICodegenSymbolIn> &
|
|
463
|
-
Pick<Required<ICodegenSymbolIn>, 'selector'>,
|
|
464
|
-
): ICodegenSymbolOut;
|
|
465
|
-
/**
|
|
466
|
-
* Symbols exported from other files.
|
|
467
|
-
**/
|
|
468
|
-
exports: ReadonlyArray<ICodegenImport>;
|
|
469
|
-
/**
|
|
470
|
-
* Returns all symbols used in this file (declared + imported).
|
|
396
|
+
* Deduplicates identical symbols by ID.
|
|
471
397
|
*
|
|
472
|
-
* @
|
|
398
|
+
* @param symbol Symbol to register.
|
|
399
|
+
* @returns The registered symbol.
|
|
473
400
|
*/
|
|
474
|
-
|
|
401
|
+
register(symbol: ISymbolIn): ISymbolOut;
|
|
475
402
|
/**
|
|
476
|
-
*
|
|
403
|
+
* Get all symbols in the order they were registered.
|
|
477
404
|
*
|
|
478
|
-
* @
|
|
479
|
-
* @returns The symbol if it exists, undefined otherwise.
|
|
405
|
+
* @returns Array of all registered symbols, in insert order.
|
|
480
406
|
*/
|
|
481
|
-
|
|
407
|
+
registered(): IterableIterator<ISymbolOut>;
|
|
482
408
|
/**
|
|
483
|
-
*
|
|
409
|
+
* Sets a value for a symbol by its ID.
|
|
484
410
|
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
* @returns True if the file contains content
|
|
411
|
+
* @param symbolId Symbol ID.
|
|
412
|
+
* @param value The value to set.
|
|
413
|
+
* @returns void
|
|
489
414
|
*/
|
|
490
|
-
|
|
415
|
+
setValue(symbolId: number, value: unknown): Map<number, unknown>;
|
|
416
|
+
}
|
|
417
|
+
//#endregion
|
|
418
|
+
//#region src/bindings/utils.d.ts
|
|
419
|
+
declare const createBinding: ({
|
|
420
|
+
file,
|
|
421
|
+
modulePath,
|
|
422
|
+
symbol,
|
|
423
|
+
symbolFile
|
|
424
|
+
}: {
|
|
425
|
+
file: IFileOut;
|
|
426
|
+
modulePath: string;
|
|
427
|
+
symbol: ISymbolOut;
|
|
428
|
+
symbolFile: IFileOut;
|
|
429
|
+
}) => IBinding;
|
|
430
|
+
declare const mergeBindings: (target: IBinding, source: IBinding) => void;
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/output/types.d.ts
|
|
433
|
+
interface IOutput {
|
|
491
434
|
/**
|
|
492
|
-
*
|
|
435
|
+
* The main content of the file to output.
|
|
493
436
|
*
|
|
494
|
-
*
|
|
495
|
-
*
|
|
496
|
-
|
|
497
|
-
hasSymbol(id: number): boolean;
|
|
498
|
-
/**
|
|
499
|
-
* File ID within the project.
|
|
437
|
+
* A raw string representing source code.
|
|
438
|
+
*
|
|
439
|
+
* @example "function foo(): void {\n // implementation\n}\n"
|
|
500
440
|
*/
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Symbols imported from other files.
|
|
504
|
-
**/
|
|
505
|
-
imports: ReadonlyArray<ICodegenImport>;
|
|
506
|
-
/**
|
|
507
|
-
* Optional metadata about the file.
|
|
508
|
-
**/
|
|
509
|
-
meta: {
|
|
510
|
-
/**
|
|
511
|
-
* Optional file extension.
|
|
512
|
-
*
|
|
513
|
-
* @example ".ts"
|
|
514
|
-
*/
|
|
515
|
-
extension?: '.ts' | (string & {});
|
|
516
|
-
/**
|
|
517
|
-
* Optional logical module or package name.
|
|
518
|
-
*
|
|
519
|
-
* @example "models.user"
|
|
520
|
-
*/
|
|
521
|
-
moduleName?: string;
|
|
522
|
-
/**
|
|
523
|
-
* Optional path transformer.
|
|
524
|
-
*
|
|
525
|
-
* @param path Original file path passed to the constructor.
|
|
526
|
-
*/
|
|
527
|
-
path?: ((path: string) => string) | string;
|
|
528
|
-
/**
|
|
529
|
-
* Renderer ID.
|
|
530
|
-
*
|
|
531
|
-
* @example "typescript"
|
|
532
|
-
*/
|
|
533
|
-
renderer?: ICodegenRenderer['id'];
|
|
534
|
-
};
|
|
441
|
+
content: string;
|
|
535
442
|
/**
|
|
536
443
|
* Logical output path (used for writing the file).
|
|
537
444
|
*
|
|
538
445
|
* @example "models/user.ts"
|
|
539
446
|
*/
|
|
540
447
|
path: string;
|
|
448
|
+
}
|
|
449
|
+
//#endregion
|
|
450
|
+
//#region src/files/registry.d.ts
|
|
451
|
+
declare class FileRegistry implements IFileRegistry {
|
|
452
|
+
private _id;
|
|
453
|
+
private referenceOrder;
|
|
454
|
+
private registerOrder;
|
|
455
|
+
private selectorToId;
|
|
456
|
+
private values;
|
|
457
|
+
get(fileIdOrSelector: number | ISelector): IFileOut | undefined;
|
|
458
|
+
get id(): number;
|
|
459
|
+
private idOrSelector;
|
|
460
|
+
reference(fileIdOrSelector: number | ISelector): IFileOut;
|
|
461
|
+
referenced(): IterableIterator<IFileOut>;
|
|
462
|
+
register(file: IFileIn): IFileOut;
|
|
463
|
+
registered(): IterableIterator<IFileOut>;
|
|
464
|
+
}
|
|
465
|
+
//#endregion
|
|
466
|
+
//#region src/project/types.d.ts
|
|
467
|
+
/**
|
|
468
|
+
* Represents a code generation project consisting of multiple codegen files.
|
|
469
|
+
* Manages imports, symbols, and output generation across the project.
|
|
470
|
+
*/
|
|
471
|
+
interface IProject {
|
|
541
472
|
/**
|
|
542
|
-
*
|
|
543
|
-
*/
|
|
544
|
-
project: ICodegenProject;
|
|
545
|
-
/**
|
|
546
|
-
* Returns a relative path to this file from another file.
|
|
547
|
-
*
|
|
548
|
-
* @param file The file from which we want the relative path to this file.
|
|
549
|
-
* @example "./this-file.ts"
|
|
550
|
-
*/
|
|
551
|
-
relativePathFromFile(file: Pick<ICodegenFile, 'path'>): string;
|
|
552
|
-
/**
|
|
553
|
-
* Returns a relative path to file from this file.
|
|
473
|
+
* The default file to assign symbols without a specific file selector.
|
|
554
474
|
*
|
|
555
|
-
* @
|
|
556
|
-
* @example "./another-file.ts"
|
|
475
|
+
* @default 'main'
|
|
557
476
|
*/
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Map holding resolved names for symbols in this file.
|
|
561
|
-
*/
|
|
562
|
-
resolvedNames: ICodegenBiMap<number, string>;
|
|
563
|
-
/**
|
|
564
|
-
* Top-level symbols declared in this file.
|
|
565
|
-
**/
|
|
566
|
-
symbols: ReadonlyArray<ICodegenSymbolOut>;
|
|
477
|
+
readonly defaultFileName?: string;
|
|
567
478
|
/**
|
|
568
|
-
*
|
|
479
|
+
* Optional function to transform file names before they are used.
|
|
569
480
|
*
|
|
570
|
-
* @param
|
|
571
|
-
* @
|
|
572
|
-
* @returns The updated symbol.
|
|
481
|
+
* @param name The original file name.
|
|
482
|
+
* @returns The transformed file name.
|
|
573
483
|
*/
|
|
574
|
-
|
|
575
|
-
id: number,
|
|
576
|
-
symbol: Partial<ICodegenSymbolOut>,
|
|
577
|
-
): ICodegenSymbolOut;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
interface ICodegenImport {
|
|
484
|
+
readonly fileName?: (name: string) => string;
|
|
581
485
|
/**
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
* Keys must be a subset of `names`, values are aliases.
|
|
585
|
-
*
|
|
586
|
-
* @example { User: "ImportedUser" }
|
|
486
|
+
* Centralized file registry for the project.
|
|
587
487
|
*/
|
|
588
|
-
|
|
488
|
+
readonly files: IFileRegistry;
|
|
589
489
|
/**
|
|
590
|
-
*
|
|
490
|
+
* Produces output representations for all files in the project.
|
|
591
491
|
*
|
|
592
|
-
* @
|
|
492
|
+
* @param meta Arbitrary metadata.
|
|
493
|
+
* @returns Array of outputs ready for writing or further processing.
|
|
494
|
+
* @example
|
|
495
|
+
* project.render().forEach(output => writeFile(output));
|
|
593
496
|
*/
|
|
594
|
-
|
|
497
|
+
render(meta?: IProjectRenderMeta): ReadonlyArray<IOutput>;
|
|
595
498
|
/**
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
* For internal files, this should be a ICodegenFile instance to enable
|
|
599
|
-
* dynamic path computation. For external or system modules, use a string.
|
|
499
|
+
* Map of available renderers by file extension.
|
|
600
500
|
*
|
|
601
|
-
* @example
|
|
602
|
-
*
|
|
501
|
+
* @example
|
|
502
|
+
* {
|
|
503
|
+
* ".ts": tsRenderer,
|
|
504
|
+
* ".js": jsRenderer,
|
|
505
|
+
* }
|
|
603
506
|
*/
|
|
604
|
-
|
|
507
|
+
readonly renderers: Record<string, IRenderer>;
|
|
605
508
|
/**
|
|
606
|
-
*
|
|
607
|
-
*
|
|
608
|
-
* Must be non-empty unless `isNamespaceImport` is true.
|
|
609
|
-
* All imported names, regardless of whether they are used as types or values.
|
|
610
|
-
*
|
|
611
|
-
* @example ["User", "UserDTO"]
|
|
509
|
+
* The absolute path to the root folder of the project.
|
|
612
510
|
*/
|
|
613
|
-
|
|
511
|
+
readonly root: string;
|
|
614
512
|
/**
|
|
615
|
-
*
|
|
616
|
-
*
|
|
513
|
+
* Retrieves files that include symbol ID. The first file is the one
|
|
514
|
+
* where the symbol is declared, the rest are files that re-export it.
|
|
617
515
|
*
|
|
618
|
-
* @
|
|
619
|
-
* @
|
|
516
|
+
* @param symbolId The symbol ID to find.
|
|
517
|
+
* @returns An array of files containing the symbol.
|
|
518
|
+
* @example
|
|
519
|
+
* const files = project.symbolIdToFiles(31);
|
|
520
|
+
* for (const file of files) {
|
|
521
|
+
* console.log(file.path);
|
|
522
|
+
* }
|
|
620
523
|
*/
|
|
621
|
-
|
|
524
|
+
symbolIdToFiles(symbolId: number): ReadonlyArray<IFileOut>;
|
|
622
525
|
/**
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
* @example true
|
|
526
|
+
* Centralized symbol registry for the project.
|
|
626
527
|
*/
|
|
627
|
-
|
|
528
|
+
readonly symbols: ISymbolRegistry;
|
|
529
|
+
}
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/renderer/types.d.ts
|
|
532
|
+
interface IRenderer {
|
|
628
533
|
/**
|
|
629
|
-
*
|
|
630
|
-
* These symbols will be emitted as type-only imports in TypeScript.
|
|
534
|
+
* Renders content with replaced symbols.
|
|
631
535
|
*
|
|
632
|
-
* @
|
|
536
|
+
* @param content Content to render.
|
|
537
|
+
* @param file The file to render.
|
|
538
|
+
* @param project The parent project the file belongs to.
|
|
539
|
+
* @returns Rendered content.
|
|
633
540
|
*/
|
|
634
|
-
|
|
541
|
+
renderFile(content: string, file: IFile, project: IProject, meta?: IProjectRenderMeta): string;
|
|
635
542
|
/**
|
|
636
|
-
*
|
|
543
|
+
* Returns printable data containing symbols and exports.
|
|
637
544
|
*
|
|
638
|
-
* @
|
|
545
|
+
* @param file The file to render.
|
|
546
|
+
* @param project The parent project the file belongs to.
|
|
547
|
+
* @param meta Arbitrary metadata.
|
|
548
|
+
* @returns Printable string containing symbols and exports.
|
|
639
549
|
*/
|
|
640
|
-
|
|
550
|
+
renderSymbols(file: IFileOut, project: IProject, meta?: IProjectRenderMeta): string;
|
|
641
551
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
get exports(): ReadonlyArray<ICodegenImport>;
|
|
660
|
-
getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>;
|
|
661
|
-
private getImportExportKey;
|
|
662
|
-
getSymbolById(id: number): ICodegenSymbolOut | undefined;
|
|
663
|
-
hasContent(): boolean;
|
|
664
|
-
hasSymbol(id: number): boolean;
|
|
665
|
-
get imports(): ReadonlyArray<ICodegenImport>;
|
|
666
|
-
private mergeImportExportValues;
|
|
667
|
-
static pathToFilePath(source: string): string;
|
|
668
|
-
relativePathFromFile(file: Pick<ICodegenFile, 'path'>): string;
|
|
669
|
-
relativePathToFile(file: Pick<ICodegenFile, 'path'>): string;
|
|
670
|
-
selectSymbolAll(selector: ICodegenSymbolSelector): ReadonlyArray<ICodegenSymbolOut>;
|
|
671
|
-
selectSymbolFirst(selector: ICodegenSymbolSelector): ICodegenSymbolOut | undefined;
|
|
672
|
-
selectSymbolFirstOrThrow(selector: ICodegenSymbolSelector): ICodegenSymbolOut;
|
|
673
|
-
selectSymbolLast(selector: ICodegenSymbolSelector): ICodegenSymbolOut | undefined;
|
|
674
|
-
get symbols(): ReadonlyArray<ICodegenSymbolOut>;
|
|
675
|
-
updateSymbol(id: number, symbol: Partial<ICodegenSymbolOut>): ICodegenSymbolOut;
|
|
552
|
+
//#endregion
|
|
553
|
+
//#region src/symbols/registry.d.ts
|
|
554
|
+
declare class SymbolRegistry implements ISymbolRegistry {
|
|
555
|
+
private _id;
|
|
556
|
+
private nodes;
|
|
557
|
+
private registerOrder;
|
|
558
|
+
private selectorToId;
|
|
559
|
+
private values;
|
|
560
|
+
get(symbolIdOrSelector: number | ISelector): ISymbolOut | undefined;
|
|
561
|
+
getValue(symbolId: number): unknown;
|
|
562
|
+
hasValue(symbolId: number): boolean;
|
|
563
|
+
get id(): number;
|
|
564
|
+
private idOrSelector;
|
|
565
|
+
reference(symbolIdOrSelector: number | ISelector): ISymbolOut;
|
|
566
|
+
register(symbol: ISymbolIn): ISymbolOut;
|
|
567
|
+
registered(): IterableIterator<ISymbolOut>;
|
|
568
|
+
setValue(symbolId: number, value: unknown): Map<number, unknown>;
|
|
676
569
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
get files(): ReadonlyArray<ICodegenFile>;
|
|
699
|
-
getAllSymbols(): ReadonlyArray<Pick<ICodegenSymbolOut, 'name'>>;
|
|
700
|
-
getFileByPath(path: string): ICodegenFile | undefined;
|
|
701
|
-
getFileBySymbolId(id: number): ICodegenFile | undefined;
|
|
702
|
-
private getFileRenderer;
|
|
703
|
-
getSymbolById(id: number): ICodegenSymbolOut | undefined;
|
|
704
|
-
incrementFileId(): number;
|
|
705
|
-
incrementSymbolId(): number;
|
|
706
|
-
registerSymbol(symbol: ICodegenSymbolOut, file: ICodegenFile): void;
|
|
707
|
-
render(meta?: ICodegenMeta): ReadonlyArray<ICodegenOutput>;
|
|
708
|
-
selectSymbolAll(selector: ICodegenSymbolSelector, file?: ICodegenFile): ReadonlyArray<ICodegenSymbolOut>;
|
|
709
|
-
selectSymbolFirst(selector: ICodegenSymbolSelector, file?: ICodegenFile): ICodegenSymbolOut | undefined;
|
|
710
|
-
selectSymbolFirstOrThrow(selector: ICodegenSymbolSelector, file?: ICodegenFile): ICodegenSymbolOut;
|
|
711
|
-
selectSymbolLast(selector: ICodegenSymbolSelector, file?: ICodegenFile): ICodegenSymbolOut | undefined;
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region src/project/project.d.ts
|
|
572
|
+
declare class Project implements IProject {
|
|
573
|
+
private symbolIdToFileIds;
|
|
574
|
+
readonly defaultFileName: string;
|
|
575
|
+
readonly files: FileRegistry;
|
|
576
|
+
readonly fileName?: (name: string) => string;
|
|
577
|
+
readonly renderers: Record<string, IRenderer>;
|
|
578
|
+
readonly root: string;
|
|
579
|
+
readonly symbols: SymbolRegistry;
|
|
580
|
+
constructor({
|
|
581
|
+
defaultFileName,
|
|
582
|
+
fileName,
|
|
583
|
+
renderers,
|
|
584
|
+
root
|
|
585
|
+
}: Pick<IProject, 'defaultFileName' | 'fileName' | 'renderers' | 'root'>);
|
|
586
|
+
private getRenderer;
|
|
587
|
+
private prepareFiles;
|
|
588
|
+
render(meta?: IProjectRenderMeta): ReadonlyArray<IOutput>;
|
|
589
|
+
symbolIdToFiles(symbolId: number): ReadonlyArray<IFileOut>;
|
|
590
|
+
private symbolToFileSelector;
|
|
712
591
|
}
|
|
713
|
-
|
|
592
|
+
//#endregion
|
|
593
|
+
//#region src/renderer/utils.d.ts
|
|
714
594
|
/**
|
|
715
595
|
*
|
|
716
596
|
* @param source The source string to replace.
|
|
717
597
|
* @param replacerFn Accepts a symbol ID, returns resolved symbol name.
|
|
718
598
|
* @returns The replaced source string.
|
|
719
599
|
*/
|
|
720
|
-
declare const
|
|
721
|
-
|
|
722
|
-
export { BiMap,
|
|
600
|
+
declare const renderIds: (source: string, replacerFn: (symbolId: number) => string | undefined) => string;
|
|
601
|
+
//#endregion
|
|
602
|
+
export { type IBiMap as BiMap, type IBinding as Binding, type IFileOut as File, type IFileIn as FileIn, type IProject, type IOutput as Output, Project, type IProjectRenderMeta as ProjectRenderMeta, type IRenderer as Renderer, type ISelector as Selector, type ISymbolOut as Symbol, type ISymbolIn as SymbolIn, type ISymbolMeta as SymbolMeta, createBinding, mergeBindings, renderIds };
|
|
603
|
+
//# sourceMappingURL=index.d.ts.map
|