@hey-api/codegen-core 0.3.2 → 0.4.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.
@@ -0,0 +1,983 @@
1
+ import colors from "ansi-colors";
2
+
3
+ //#region src/refs/types.d.ts
4
+
5
+ /**
6
+ * Ref wrapper which ensures a stable reference for a value.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * type NumRef = Ref<number>; // { '~ref': number }
11
+ * const num: NumRef = { '~ref': 42 };
12
+ * console.log(num['~ref']); // 42
13
+ * ```
14
+ */
15
+ type Ref<T> = {
16
+ '~ref': T;
17
+ };
18
+ /**
19
+ * Maps every property of `T` to a `Ref` of that property.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * type Foo = { a: number; b: string };
24
+ * type Refs = Refs<Foo>; // { a: Ref<number>; b: Ref<string> }
25
+ * const refs: Refs = { a: { '~ref': 1 }, b: { '~ref': 'x' } };
26
+ * console.log(refs.a['~ref'], refs.b['~ref']); // 1 'x'
27
+ * ```
28
+ */
29
+ type Refs<T> = { [K in keyof T]: Ref<T[K]> };
30
+ /**
31
+ * Unwraps a Ref to its value type.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * type N = FromRef<{ '~ref': number }>; // number
36
+ * ```
37
+ */
38
+ type FromRef<T> = T extends Ref<infer V> ? V : T;
39
+ /**
40
+ * Maps every property of a Ref-wrapped object back to its plain value.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * type Foo = { a: number; b: string };
45
+ * type Refs = Refs<Foo>; // { a: Ref<number>; b: Ref<string> }
46
+ * type Foo2 = FromRefs<Refs>; // { a: number; b: string }
47
+ * ```
48
+ */
49
+ type FromRefs<T> = { [K in keyof T]: T[K] extends Ref<infer V> ? V : T[K] };
50
+ //#endregion
51
+ //#region src/extensions.d.ts
52
+ /**
53
+ * Arbitrary metadata passed to the project's render function.
54
+ *
55
+ * Implementers should extend this interface for their own needs.
56
+ */
57
+ interface IProjectRenderMeta {
58
+ [key: string]: unknown;
59
+ }
60
+ /**
61
+ * Additional metadata about the symbol.
62
+ *
63
+ * Implementers should extend this interface for their own needs.
64
+ */
65
+ interface ISymbolMeta {
66
+ [key: string]: unknown;
67
+ }
68
+ //#endregion
69
+ //#region src/nodes/node.d.ts
70
+ interface INode<T = unknown> {
71
+ /** Perform semantic analysis. */
72
+ analyze(ctx: IAnalysisContext): void;
73
+ /** Whether this node is exported from its file. */
74
+ exported?: boolean;
75
+ /** The file this node belongs to. */
76
+ file?: File;
77
+ /** The programming language associated with this node */
78
+ language: Language;
79
+ /** Parent node in the syntax tree. */
80
+ parent?: INode;
81
+ /** Root node of the syntax tree. */
82
+ root?: INode;
83
+ /** The symbol associated with this node. */
84
+ symbol?: Symbol;
85
+ /** Convert this node into AST representation. */
86
+ toAst(): T;
87
+ /** Brand used for renderer dispatch. */
88
+ readonly '~brand': string;
89
+ }
90
+ //#endregion
91
+ //#region src/symbols/types.d.ts
92
+ type BindingKind = 'default' | 'named' | 'namespace';
93
+ type ISymbolIdentifier = number | ISymbolMeta;
94
+ type SymbolKind = 'class' | 'enum' | 'function' | 'interface' | 'namespace' | 'type' | 'var';
95
+ type SymbolNameSanitizer = (name: string) => string;
96
+ type ISymbolIn = {
97
+ /**
98
+ * Array of file names (without extensions) from which this symbol is re-exported.
99
+ *
100
+ * @default undefined
101
+ */
102
+ exportFrom?: ReadonlyArray<string>;
103
+ /**
104
+ * Whether this symbol is exported from its own file.
105
+ *
106
+ * @default false
107
+ */
108
+ exported?: boolean;
109
+ /**
110
+ * External module name if this symbol is imported from a module not managed
111
+ * by the project (e.g. "zod", "lodash").
112
+ *
113
+ * @default undefined
114
+ */
115
+ external?: string;
116
+ /**
117
+ * Optional output strategy to override default behavior.
118
+ *
119
+ * @returns The file path to output the symbol to, or undefined to fallback to default behavior.
120
+ */
121
+ getFilePath?: Symbol['getFilePath'];
122
+ /**
123
+ * Kind of import if this symbol represents an import.
124
+ */
125
+ importKind?: BindingKind;
126
+ /**
127
+ * Kind of symbol.
128
+ */
129
+ kind?: SymbolKind;
130
+ /**
131
+ * Arbitrary metadata about the symbol.
132
+ *
133
+ * @default undefined
134
+ */
135
+ meta?: ISymbolMeta;
136
+ /**
137
+ * The intended, user-facing name of the symbol before any conflict resolution.
138
+ * It is **not** guaranteed to be the final emitted name — aliasing may occur if the
139
+ * file contains conflicting local identifiers or other symbols with the same intended name.
140
+ *
141
+ * @example "UserModel"
142
+ */
143
+ name: string;
144
+ };
145
+ interface ISymbolRegistry {
146
+ /**
147
+ * Get a symbol.
148
+ *
149
+ * @param identifier Symbol identifier to reference.
150
+ * @returns The symbol, or undefined if not found.
151
+ */
152
+ get(identifier: ISymbolIdentifier): Symbol | undefined;
153
+ /**
154
+ * Returns whether a symbol is registered in the registry.
155
+ *
156
+ * @param identifier Symbol identifier to check.
157
+ * @returns True if the symbol is registered, false otherwise.
158
+ */
159
+ isRegistered(identifier: ISymbolIdentifier): boolean;
160
+ /**
161
+ * Returns the current symbol ID and increments it.
162
+ *
163
+ * @returns Symbol ID before being incremented.
164
+ */
165
+ readonly nextId: number;
166
+ /**
167
+ * Queries symbols by metadata filter.
168
+ *
169
+ * @param filter Metadata filter to query symbols by.
170
+ * @returns Array of symbols matching the filter.
171
+ */
172
+ query(filter: ISymbolMeta): ReadonlyArray<Symbol>;
173
+ /**
174
+ * References a symbol.
175
+ *
176
+ * @param meta Metadata filter to reference symbol by.
177
+ * @returns The referenced symbol.
178
+ */
179
+ reference(meta: ISymbolMeta): Symbol;
180
+ /**
181
+ * Register a symbol globally.
182
+ *
183
+ * Deduplicates identical symbols by ID.
184
+ *
185
+ * @param symbol Symbol to register.
186
+ * @returns The registered symbol.
187
+ */
188
+ register(symbol: ISymbolIn): Symbol;
189
+ /**
190
+ * Get all symbols in the order they were registered.
191
+ *
192
+ * @returns Array of all registered symbols, in insert order.
193
+ */
194
+ registered(): IterableIterator<Symbol>;
195
+ }
196
+ //#endregion
197
+ //#region src/symbols/symbol.d.ts
198
+ declare class Symbol {
199
+ /**
200
+ * Canonical symbol this stub resolves to, if any.
201
+ *
202
+ * Stubs created during DSL construction may later be associated
203
+ * with a fully registered symbol. Once set, all property lookups
204
+ * should defer to the canonical symbol.
205
+ */
206
+ private _canonical?;
207
+ /**
208
+ * True if this symbol is exported from its defining file.
209
+ *
210
+ * @default false
211
+ */
212
+ private _exported;
213
+ /**
214
+ * Names of files (without extension) from which this symbol is re-exported.
215
+ *
216
+ * @default []
217
+ */
218
+ private _exportFrom;
219
+ /**
220
+ * External module name if this symbol is imported from a module not managed
221
+ * by the project (e.g. "zod", "lodash").
222
+ *
223
+ * @default undefined
224
+ */
225
+ private _external?;
226
+ /**
227
+ * The file this symbol is ultimately emitted into.
228
+ *
229
+ * Only top-level symbols have an assigned file.
230
+ */
231
+ private _file?;
232
+ /**
233
+ * The alias-resolved, conflict-free emitted name.
234
+ */
235
+ private _finalName?;
236
+ /**
237
+ * Custom strategy to determine file output path.
238
+ *
239
+ * @returns The file path to output the symbol to, or undefined to fallback to default behavior.
240
+ */
241
+ private _getFilePath?;
242
+ /**
243
+ * How this symbol should be imported (namespace/default/named).
244
+ *
245
+ * @default 'named'
246
+ */
247
+ private _importKind;
248
+ /**
249
+ * Kind of symbol (class, type, alias, etc.).
250
+ *
251
+ * @default 'var'
252
+ */
253
+ private _kind;
254
+ /**
255
+ * Arbitrary user metadata.
256
+ *
257
+ * @default undefined
258
+ */
259
+ private _meta?;
260
+ /**
261
+ * Intended user-facing name before conflict resolution.
262
+ *
263
+ * @example "UserModel"
264
+ */
265
+ private _name;
266
+ /**
267
+ * Optional function to sanitize the symbol name.
268
+ *
269
+ * @default undefined
270
+ */
271
+ private _nameSanitizer?;
272
+ /**
273
+ * Node that defines this symbol.
274
+ */
275
+ private _node?;
276
+ /** Brand used for identifying symbols. */
277
+ readonly '~brand' = "heyapi.symbol";
278
+ /** Globally unique, stable symbol ID. */
279
+ readonly id: number;
280
+ constructor(input: ISymbolIn, id: number);
281
+ /**
282
+ * Returns the canonical symbol for this instance.
283
+ *
284
+ * If this symbol was created as a stub, this getter returns
285
+ * the fully registered canonical symbol. Otherwise, it returns
286
+ * the symbol itself.
287
+ */
288
+ get canonical(): Symbol;
289
+ /**
290
+ * Indicates whether this symbol is exported from its defining file.
291
+ */
292
+ get exported(): boolean;
293
+ /**
294
+ * Names of files (without extension) that re-export this symbol.
295
+ */
296
+ get exportFrom(): ReadonlyArray<string>;
297
+ /**
298
+ * External module from which this symbol originates, if any.
299
+ */
300
+ get external(): string | undefined;
301
+ /**
302
+ * Read‑only accessor for the assigned output file.
303
+ *
304
+ * Only top-level symbols have an assigned file.
305
+ */
306
+ get file(): File | undefined;
307
+ /**
308
+ * Read‑only accessor for the resolved final emitted name.
309
+ */
310
+ get finalName(): string;
311
+ /**
312
+ * Custom file path resolver, if provided.
313
+ */
314
+ get getFilePath(): ((symbol: Symbol) => string | undefined) | undefined;
315
+ /**
316
+ * How this symbol should be imported (named/default/namespace).
317
+ */
318
+ get importKind(): BindingKind;
319
+ /**
320
+ * Indicates whether this is a canonical symbol (not a stub).
321
+ */
322
+ get isCanonical(): boolean;
323
+ /**
324
+ * The symbol's kind (class, type, alias, variable, etc.).
325
+ */
326
+ get kind(): SymbolKind;
327
+ /**
328
+ * Arbitrary user‑provided metadata associated with this symbol.
329
+ */
330
+ get meta(): ISymbolMeta | undefined;
331
+ /**
332
+ * User-intended name before aliasing or conflict resolution.
333
+ */
334
+ get name(): string;
335
+ /**
336
+ * Optional function to sanitize the symbol name.
337
+ */
338
+ get nameSanitizer(): SymbolNameSanitizer | undefined;
339
+ /**
340
+ * Read‑only accessor for the defining node.
341
+ */
342
+ get node(): INode | undefined;
343
+ /**
344
+ * Marks this symbol as a stub and assigns its canonical symbol.
345
+ *
346
+ * After calling this, all semantic queries (name, kind, file,
347
+ * meta, etc.) should reflect the canonical symbol's values.
348
+ *
349
+ * @param symbol — The canonical symbol this stub should resolve to.
350
+ */
351
+ setCanonical(symbol: Symbol): void;
352
+ /**
353
+ * Marks the symbol as exported from its file.
354
+ *
355
+ * @param exported — Whether the symbol is exported.
356
+ */
357
+ setExported(exported: boolean): void;
358
+ /**
359
+ * Records file names that re‑export this symbol.
360
+ *
361
+ * @param list — Source files re‑exporting this symbol.
362
+ */
363
+ setExportFrom(list: ReadonlyArray<string>): void;
364
+ /**
365
+ * Assigns the output file this symbol will be emitted into.
366
+ *
367
+ * This may only be set once.
368
+ */
369
+ setFile(file: File): void;
370
+ /**
371
+ * Assigns the conflict‑resolved final local name for this symbol.
372
+ *
373
+ * This may only be set once.
374
+ */
375
+ setFinalName(name: string): void;
376
+ /**
377
+ * Sets how this symbol should be imported.
378
+ *
379
+ * @param kind — The import strategy (named/default/namespace).
380
+ */
381
+ setImportKind(kind: BindingKind): void;
382
+ /**
383
+ * Sets the symbol's kind (class, type, alias, variable, etc.).
384
+ *
385
+ * @param kind — The new symbol kind.
386
+ */
387
+ setKind(kind: SymbolKind): void;
388
+ /**
389
+ * Updates the intended user‑facing name for this symbol.
390
+ *
391
+ * @param name — The new name.
392
+ */
393
+ setName(name: string): void;
394
+ /**
395
+ * Sets a custom function to sanitize the symbol's name.
396
+ *
397
+ * @param fn — The name sanitizer function to apply.
398
+ */
399
+ setNameSanitizer(fn: SymbolNameSanitizer): void;
400
+ /**
401
+ * Binds the node that defines this symbol.
402
+ *
403
+ * This may only be set once.
404
+ */
405
+ setNode(node: INode): void;
406
+ /**
407
+ * Returns a debug‑friendly string representation identifying the symbol.
408
+ */
409
+ toString(): string;
410
+ /**
411
+ * Ensures this symbol is canonical before allowing mutation.
412
+ *
413
+ * A symbol that has been marked as a stub (i.e., its `_canonical` points
414
+ * to a different symbol) may not be mutated. This guard throws an error
415
+ * if any setter attempts to modify a stub, preventing accidental writes
416
+ * to non‑canonical instances.
417
+ *
418
+ * @throws {Error} If the symbol is a stub and is being mutated.
419
+ */
420
+ private assertCanonical;
421
+ }
422
+ //#endregion
423
+ //#region src/planner/types.d.ts
424
+ type Input = Ref<object> | object | string | number | undefined;
425
+ type NameScopes = Map<string, Set<SymbolKind>>;
426
+ type NameConflictResolver = (args: {
427
+ attempt: number;
428
+ baseName: string;
429
+ }) => string | null;
430
+ type Scope = {
431
+ /** Child scopes. */
432
+ children: Array<Scope>;
433
+ /** Resolved names in this scope. */
434
+ localNames: NameScopes;
435
+ /** Parent scope, if any. */
436
+ parent?: Scope;
437
+ /** Symbols registered in this scope. */
438
+ symbols: Array<Ref<Symbol>>;
439
+ };
440
+ interface IAnalysisContext {
441
+ /** Register a dependency on another symbol. */
442
+ addDependency(symbol: Ref<Symbol>): void;
443
+ /** Register a dependency on another symbol or analyze further. */
444
+ analyze(input: Input): void;
445
+ /** Get local names in the current scope. */
446
+ localNames(scope: Scope): NameScopes;
447
+ /** Pop the current local scope. */
448
+ popScope(): void;
449
+ /** Push a new local scope. */
450
+ pushScope(): void;
451
+ /** Current local scope. */
452
+ scope: Scope;
453
+ /** Stack of local name scopes. */
454
+ scopes: Scope;
455
+ /** Top-level symbol for the current analysis pass. */
456
+ symbol?: Symbol;
457
+ /** Walks all symbols in the scope tree in depth-first order. */
458
+ walkScopes(callback: (symbol: Ref<Symbol>, scope: Scope) => void, scope?: Scope): void;
459
+ }
460
+ //#endregion
461
+ //#region src/languages/types.d.ts
462
+ type Extensions = Partial<Record<Language, ReadonlyArray<string>>>;
463
+ type Language = 'c' | 'c#' | 'c++' | 'css' | 'dart' | 'go' | 'haskell' | 'html' | 'java' | 'javascript' | 'json' | 'kotlin' | 'lua' | 'markdown' | 'matlab' | 'perl' | 'php' | 'python' | 'r' | 'ruby' | 'rust' | 'scala' | 'shell' | 'sql' | 'swift' | 'typescript' | 'yaml' | (string & {});
464
+ // other/custom language
465
+
466
+ type NameConflictResolvers = Partial<Record<Language, NameConflictResolver>>;
467
+ //#endregion
468
+ //#region src/files/types.d.ts
469
+ type FileKeyArgs = Pick<Required<File>, 'logicalFilePath'> & Pick<Partial<File>, 'external' | 'language'>;
470
+ type IFileIn = {
471
+ /**
472
+ * Indicates whether the file is external, meaning it is not generated
473
+ * as part of the project but is referenced (e.g., a module from
474
+ * node_modules).
475
+ *
476
+ * @example true
477
+ */
478
+ external?: boolean;
479
+ /**
480
+ * Language of the file.
481
+ *
482
+ * @example "typescript"
483
+ */
484
+ language?: Language;
485
+ /**
486
+ * Logical, extension-free path used for planning and routing.
487
+ *
488
+ * @example "src/models/user"
489
+ */
490
+ logicalFilePath: string;
491
+ /**
492
+ * The desired name for the file within the project. If there are multiple files
493
+ * with the same desired name, this might not end up being the actual name.
494
+ *
495
+ * @example "UserModel"
496
+ */
497
+ name?: string;
498
+ };
499
+ interface IFileRegistry {
500
+ /**
501
+ * Get a file.
502
+ *
503
+ * @returns The file, or undefined if not found.
504
+ */
505
+ get(args: FileKeyArgs): File | undefined;
506
+ /**
507
+ * Returns whether a file is registered in the registry.
508
+ *
509
+ * @returns True if the file is registered, false otherwise.
510
+ */
511
+ isRegistered(args: FileKeyArgs): boolean;
512
+ /**
513
+ * Returns the current file ID and increments it.
514
+ *
515
+ * @returns File ID before being incremented
516
+ */
517
+ readonly nextId: number;
518
+ /**
519
+ * Register a file globally.
520
+ *
521
+ * @param file File to register.
522
+ * @returns Newly registered file if created, merged file otherwise.
523
+ */
524
+ register(file: IFileIn): File;
525
+ /**
526
+ * Get all files in the order they were registered.
527
+ *
528
+ * @returns Array of all registered files, in insert order.
529
+ */
530
+ registered(): IterableIterator<File>;
531
+ }
532
+ //#endregion
533
+ //#region src/nodes/types.d.ts
534
+ interface INodeRegistry {
535
+ /**
536
+ * Register a syntax node.
537
+ *
538
+ * @returns The index of the registered node.
539
+ */
540
+ add(node: INode | null): number;
541
+ /**
542
+ * All nodes in insertion order.
543
+ */
544
+ all(): Iterable<INode>;
545
+ /**
546
+ * Remove a node by its index.
547
+ *
548
+ * @param index Index of the node to remove.
549
+ */
550
+ remove(index: number): void;
551
+ /**
552
+ * Update a node at the given index.
553
+ *
554
+ * @param index Index of the node to update.
555
+ * @param node New node to set.
556
+ */
557
+ update(index: number, node: INode | null): void;
558
+ }
559
+ //#endregion
560
+ //#region src/output.d.ts
561
+ interface IOutput {
562
+ /**
563
+ * The main content of the file to output.
564
+ *
565
+ * A raw string representing source code.
566
+ *
567
+ * @example "function foo(): void {\n // implementation\n}\n"
568
+ */
569
+ content: string;
570
+ /**
571
+ * Logical output path (used for writing the file).
572
+ *
573
+ * @example "models/user.ts"
574
+ */
575
+ path: string;
576
+ }
577
+ //#endregion
578
+ //#region src/renderer.d.ts
579
+ interface RenderContext {
580
+ /**
581
+ * The current file.
582
+ */
583
+ file: File;
584
+ /**
585
+ * Arbitrary metadata.
586
+ */
587
+ meta?: IProjectRenderMeta;
588
+ /**
589
+ * The project the file belongs to.
590
+ */
591
+ project: IProject;
592
+ }
593
+ interface Renderer {
594
+ /** Renders the given file. */
595
+ render(ctx: RenderContext): string;
596
+ /** Returns whether this renderer can render the given file. */
597
+ supports(ctx: RenderContext): boolean;
598
+ }
599
+ //#endregion
600
+ //#region src/project/types.d.ts
601
+ /**
602
+ * Represents a code generation project consisting of codegen files.
603
+ *
604
+ * Manages imports, symbols, and output generation across the project.
605
+ */
606
+ interface IProject {
607
+ /**
608
+ * The default file to assign symbols without a specific file selector.
609
+ *
610
+ * @default 'main'
611
+ */
612
+ readonly defaultFileName: string;
613
+ /** Default name conflict resolver used when a file has no specific resolver. */
614
+ readonly defaultNameConflictResolver: NameConflictResolver;
615
+ /** Maps language to array of extensions. First element is used by default. */
616
+ readonly extensions: Extensions;
617
+ /**
618
+ * Function to transform file names before they are used.
619
+ *
620
+ * @param name The original file name.
621
+ * @returns The transformed file name.
622
+ */
623
+ readonly fileName?: (name: string) => string;
624
+ /** Centralized file registry for the project. */
625
+ readonly files: IFileRegistry;
626
+ /** Map of language-specific name conflict resolvers for files in the project. */
627
+ readonly nameConflictResolvers: NameConflictResolvers;
628
+ /** Centralized node registry for the project. */
629
+ readonly nodes: INodeRegistry;
630
+ /**
631
+ * Produces output representations for all files in the project.
632
+ *
633
+ * @param meta Arbitrary metadata.
634
+ * @returns Array of outputs ready for writing or further processing.
635
+ * @example
636
+ * project.render().forEach(output => writeFile(output));
637
+ */
638
+ render(meta?: IProjectRenderMeta): ReadonlyArray<IOutput>;
639
+ /**
640
+ * List of available renderers.
641
+ *
642
+ * @example
643
+ * [new TypeScriptRenderer()]
644
+ */
645
+ readonly renderers: ReadonlyArray<Renderer>;
646
+ /** The absolute path to the root folder of the project. */
647
+ readonly root: string;
648
+ /** Centralized symbol registry for the project. */
649
+ readonly symbols: ISymbolRegistry;
650
+ }
651
+ //#endregion
652
+ //#region src/files/file.d.ts
653
+ declare class File {
654
+ /**
655
+ * Exports from this file.
656
+ */
657
+ private _exports;
658
+ /**
659
+ * File extension (e.g. `.ts`).
660
+ */
661
+ private _extension?;
662
+ /**
663
+ * Actual emitted file path, including extension and directories.
664
+ */
665
+ private _finalPath?;
666
+ /**
667
+ * Imports to this file.
668
+ */
669
+ private _imports;
670
+ /**
671
+ * Language of the file.
672
+ */
673
+ private _language?;
674
+ /**
675
+ * Logical, extension-free path used for planning and routing.
676
+ */
677
+ private _logicalFilePath;
678
+ /**
679
+ * Base name of the file (without extension).
680
+ */
681
+ private _name?;
682
+ /**
683
+ * Syntax nodes contained in this file.
684
+ */
685
+ private _nodes;
686
+ /**
687
+ * Renderer assigned to this file.
688
+ */
689
+ private _renderer?;
690
+ /** Brand used for identifying files. */
691
+ readonly '~brand' = "heyapi.file";
692
+ /** All names defined in this file, including local scopes. */
693
+ allNames: NameScopes;
694
+ /** Whether this file is external to the project. */
695
+ external: boolean;
696
+ /** Unique identifier for the file. */
697
+ readonly id: number;
698
+ /** The project this file belongs to. */
699
+ readonly project: IProject;
700
+ /** Names declared at the top level of the file. */
701
+ topLevelNames: NameScopes;
702
+ constructor(input: IFileIn, id: number, project: IProject);
703
+ /**
704
+ * Exports from this file.
705
+ */
706
+ get exports(): ReadonlyArray<ExportModule>;
707
+ /**
708
+ * Read-only accessor for the file extension.
709
+ */
710
+ get extension(): string | undefined;
711
+ /**
712
+ * Read-only accessor for the final emitted path.
713
+ *
714
+ * If undefined, the file has not yet been assigned a final path
715
+ * or is external to the project and should not be emitted.
716
+ */
717
+ get finalPath(): string | undefined;
718
+ /**
719
+ * Imports to this file.
720
+ */
721
+ get imports(): ReadonlyArray<ImportModule>;
722
+ /**
723
+ * Language of the file; inferred from nodes or fallback if not set explicitly.
724
+ */
725
+ get language(): Language | undefined;
726
+ /**
727
+ * Logical, extension-free path used for planning and routing.
728
+ */
729
+ get logicalFilePath(): string;
730
+ /**
731
+ * Base name of the file (without extension).
732
+ *
733
+ * If no name was set explicitly, it is inferred from the logical file path.
734
+ */
735
+ get name(): string;
736
+ /**
737
+ * Syntax nodes contained in this file.
738
+ */
739
+ get nodes(): ReadonlyArray<INode>;
740
+ /**
741
+ * Renderer assigned to this file.
742
+ */
743
+ get renderer(): Renderer | undefined;
744
+ /**
745
+ * Add an export group to the file.
746
+ */
747
+ addExport(group: ExportModule): void;
748
+ /**
749
+ * Add an import group to the file.
750
+ */
751
+ addImport(group: ImportModule): void;
752
+ /**
753
+ * Add a syntax node to the file.
754
+ */
755
+ addNode(node: INode): void;
756
+ /**
757
+ * Sets the file extension.
758
+ */
759
+ setExtension(extension: string): void;
760
+ /**
761
+ * Sets the final emitted path of the file.
762
+ */
763
+ setFinalPath(path: string): void;
764
+ /**
765
+ * Sets the language of the file.
766
+ */
767
+ setLanguage(lang: Language): void;
768
+ /**
769
+ * Sets the name of the file.
770
+ */
771
+ setName(name: string): void;
772
+ /**
773
+ * Sets the renderer assigned to this file.
774
+ */
775
+ setRenderer(renderer: Renderer): void;
776
+ /**
777
+ * Returns a debug‑friendly string representation identifying the file.
778
+ */
779
+ toString(): string;
780
+ }
781
+ //#endregion
782
+ //#region src/bindings.d.ts
783
+ interface ExportMember {
784
+ /**
785
+ * Name under which the symbol is exported in this file.
786
+ *
787
+ * export { Foo as Bar } from "./models"
788
+ *
789
+ * exportedName === "Bar"
790
+ */
791
+ exportedName: string;
792
+ /** Whether this export is type-only. */
793
+ isTypeOnly: boolean;
794
+ /** Export flavor. */
795
+ kind: BindingKind;
796
+ /** The exported name of the symbol in its source file. */
797
+ sourceName: string;
798
+ }
799
+ type ExportModule = Pick<ExportMember, 'isTypeOnly'> & {
800
+ /** Whether this module can export all symbols: `export * from 'module'`. */
801
+ canExportAll: boolean;
802
+ /** Members exported from this module. */
803
+ exports: Array<ExportMember>;
804
+ /** Source file. */
805
+ from: File;
806
+ /** Namespace export: `export * as ns from 'module'`. Mutually exclusive with `exports`. */
807
+ namespaceExport?: string;
808
+ };
809
+ interface ImportMember {
810
+ /** Whether this import is type-only. */
811
+ isTypeOnly: boolean;
812
+ /** Import flavor. */
813
+ kind: BindingKind;
814
+ /**
815
+ * The name this symbol will have locally in this file.
816
+ * This is where aliasing is applied:
817
+ *
818
+ * import { Foo as Foo$2 } from "./x"
819
+ *
820
+ * localName === "Foo$2"
821
+ */
822
+ localName: string;
823
+ /** The exported name of the symbol in its source file. */
824
+ sourceName: string;
825
+ }
826
+ type ImportModule = Pick<ImportMember, 'isTypeOnly'> & {
827
+ /** Source file. */
828
+ from: File;
829
+ /** List of symbols imported from this module. */
830
+ imports: Array<ImportMember>;
831
+ /** Namespace import: `import * as name from 'module'`. Mutually exclusive with `imports`. */
832
+ namespaceImport?: string;
833
+ };
834
+ //#endregion
835
+ //#region src/brands.d.ts
836
+ declare const nodeBrand = "heyapi.node";
837
+ declare const symbolBrand = "heyapi.symbol";
838
+ //#endregion
839
+ //#region src/debug.d.ts
840
+ declare const DEBUG_GROUPS: {
841
+ readonly analyzer: colors.StyleFunction;
842
+ readonly dsl: colors.StyleFunction;
843
+ readonly file: colors.StyleFunction;
844
+ readonly registry: colors.StyleFunction;
845
+ readonly symbol: colors.StyleFunction;
846
+ };
847
+ declare function debug(message: string, group: keyof typeof DEBUG_GROUPS): void;
848
+ //#endregion
849
+ //#region src/guards.d.ts
850
+ declare function isNode(value: unknown): value is INode;
851
+ declare function isNodeRef(value: Ref<unknown>): value is Ref<INode>;
852
+ declare function isSymbol(value: unknown): value is Symbol;
853
+ declare function isSymbolRef(value: Ref<unknown>): value is Ref<Symbol>;
854
+ //#endregion
855
+ //#region src/languages/extensions.d.ts
856
+ declare const defaultExtensions: Extensions;
857
+ //#endregion
858
+ //#region src/languages/resolvers.d.ts
859
+ declare const defaultNameConflictResolvers: NameConflictResolvers;
860
+ //#endregion
861
+ //#region src/planner/resolvers.d.ts
862
+ declare const simpleNameConflictResolver: NameConflictResolver;
863
+ declare const underscoreNameConflictResolver: NameConflictResolver;
864
+ //#endregion
865
+ //#region src/files/registry.d.ts
866
+ type FileId = number;
867
+ declare class FileRegistry implements IFileRegistry {
868
+ private _id;
869
+ private _values;
870
+ private readonly project;
871
+ constructor(project: IProject);
872
+ get(args: FileKeyArgs): File | undefined;
873
+ isRegistered(args: FileKeyArgs): boolean;
874
+ get nextId(): FileId;
875
+ register(file: IFileIn): File;
876
+ registered(): IterableIterator<File>;
877
+ private createFileKey;
878
+ }
879
+ //#endregion
880
+ //#region src/nodes/registry.d.ts
881
+ declare class NodeRegistry implements INodeRegistry {
882
+ private list;
883
+ add(node: INode | null): number;
884
+ all(): Iterable<INode>;
885
+ remove(index: number): void;
886
+ update(index: number, node: INode | null): void;
887
+ }
888
+ //#endregion
889
+ //#region src/symbols/registry.d.ts
890
+ type SymbolId = number;
891
+ declare class SymbolRegistry implements ISymbolRegistry {
892
+ private _id;
893
+ private _indices;
894
+ private _queryCache;
895
+ private _queryCacheDependencies;
896
+ private _registered;
897
+ private _stubs;
898
+ private _stubCache;
899
+ private _values;
900
+ get(identifier: ISymbolIdentifier): Symbol | undefined;
901
+ isRegistered(identifier: ISymbolIdentifier): boolean;
902
+ get nextId(): SymbolId;
903
+ query(filter: ISymbolMeta): ReadonlyArray<Symbol>;
904
+ reference(meta: ISymbolMeta): Symbol;
905
+ register(symbol: ISymbolIn): Symbol;
906
+ registered(): IterableIterator<Symbol>;
907
+ private buildCacheKey;
908
+ private buildIndexKeySpace;
909
+ private indexSymbol;
910
+ private invalidateCache;
911
+ private isSubset;
912
+ private replaceStubs;
913
+ private serializeIndexEntry;
914
+ }
915
+ //#endregion
916
+ //#region src/project/project.d.ts
917
+ declare class Project implements IProject {
918
+ readonly files: FileRegistry;
919
+ readonly nodes: NodeRegistry;
920
+ readonly symbols: SymbolRegistry;
921
+ readonly defaultFileName: string;
922
+ readonly defaultNameConflictResolver: NameConflictResolver;
923
+ readonly extensions: Extensions;
924
+ readonly fileName?: (name: string) => string;
925
+ readonly nameConflictResolvers: NameConflictResolvers;
926
+ readonly renderers: ReadonlyArray<Renderer>;
927
+ readonly root: string;
928
+ constructor(args: Pick<Partial<IProject>, 'defaultFileName' | 'defaultNameConflictResolver' | 'extensions' | 'fileName' | 'nameConflictResolvers' | 'renderers'> & Pick<IProject, 'root'>);
929
+ render(meta?: IProjectRenderMeta): ReadonlyArray<IOutput>;
930
+ }
931
+ //#endregion
932
+ //#region src/refs/refs.d.ts
933
+ /**
934
+ * Wraps a single value in a Ref object.
935
+ *
936
+ * @example
937
+ * ```ts
938
+ * const r = ref(123); // { '~ref': 123 }
939
+ * console.log(r['~ref']); // 123
940
+ * ```
941
+ */
942
+ declare const ref: <T>(value: T) => Ref<T>;
943
+ /**
944
+ * Converts a plain object to an object of Refs (deep, per property).
945
+ *
946
+ * @example
947
+ * ```ts
948
+ * const obj = { a: 1, b: "x" };
949
+ * const refs = refs(obj); // { a: { '~ref': 1 }, b: { '~ref': "x" } }
950
+ * ```
951
+ */
952
+ declare const refs: <T extends Record<string, unknown>>(obj: T) => Refs<T>;
953
+ /**
954
+ * Unwraps a single Ref object to its value.
955
+ *
956
+ * @example
957
+ * ```ts
958
+ * const r = { '~ref': 42 };
959
+ * const n = fromRef(r); // 42
960
+ * console.log(n); // 42
961
+ * ```
962
+ */
963
+ declare const fromRef: <T extends Ref<unknown> | undefined>(ref: T) => T extends Ref<infer U> ? U : undefined;
964
+ /**
965
+ * Converts an object of Refs back to a plain object (unwraps all refs).
966
+ *
967
+ * @example
968
+ * ```ts
969
+ * const refs = { a: { '~ref': 1 }, b: { '~ref': "x" } };
970
+ * const plain = fromRefs(refs); // { a: 1, b: "x" }
971
+ * ```
972
+ */
973
+ declare const fromRefs: <T extends Refs<Record<string, unknown>>>(obj: T) => FromRefs<T>;
974
+ /**
975
+ * Checks whether a value is a Ref object.
976
+ *
977
+ * @param value Value to check
978
+ * @returns True if the value is a Ref object.
979
+ */
980
+ declare const isRef: <T>(value: unknown) => value is Ref<T>;
981
+ //#endregion
982
+ export { type IAnalysisContext as AnalysisContext, type BindingKind, type ExportMember, type ExportModule, type Extensions, File, type IFileIn as FileIn, type FromRef, type FromRefs, type IProject, type ImportMember, type ImportModule, type Language, type NameConflictResolver, type NameConflictResolvers, type INode as Node, type IOutput as Output, Project, type IProjectRenderMeta as ProjectRenderMeta, type Ref, type Refs, type RenderContext, type Renderer, Symbol, type ISymbolIdentifier as SymbolIdentifier, type ISymbolIn as SymbolIn, type ISymbolMeta as SymbolMeta, debug, defaultExtensions, defaultNameConflictResolvers, fromRef, fromRefs, isNode, isNodeRef, isRef, isSymbol, isSymbolRef, nodeBrand, ref, refs, simpleNameConflictResolver, symbolBrand, underscoreNameConflictResolver };
983
+ //# sourceMappingURL=index.d.mts.map