@@ -11,35 +11,16 @@ export interface TokenPosition {
1111 filepath : Filepath ;
1212}
1313
14- // A reference to an element imported via `use` or `reuse`.
15- // `name` + `schemaName` identify the original element in the source file.
16- // `visibleNames` lists every local name under which the element is reachable
17- // in this file (original name if directly imported, alias name if `as` used,
18- // multiple entries when re-exported under several names).
14+ // Reference to an imported element. Resolved by exportSchemaJson.
1915export interface ElementRef {
20- // Canonical name of the element in its source file.
21- name : string ;
16+ name : string ; // canonical name in source file
2217 schemaName : string | null ;
23-
24- // All names this element is visible under in the importing file.
25- // Priority during export:
26- // visibleNames[0] becomes the PRIMARY name in the reconciled Database.
27- // visibleNames[1..] become Alias entries pointing at the primary.
28- // If an alias was used (`use { table users as u }`), the alias appears
29- // first, so `u` becomes the primary and `users` is dropped. The alias
30- // also strips schemaName (schemaName: null) so the element appears
31- // unqualified in the importing file's namespace.
32- visibleNames : {
33- schemaName : string | null ;
34- name : string ;
35- } [ ] ;
18+ // [0] = primary name in exported JSON, [1..] = aliases.
19+ // Alias strips schemaName to null.
20+ visibleNames : { schemaName : string | null ; name : string } [ ] ;
3621}
3722
38- // Elements imported into this file via `use` / `reuse` declarations.
39- // These are NOT the elements themselves — they are references pointing at
40- // elements that live in other files. `exportSchemaJson` resolves each ref
41- // into an actual element from the MasterDatabase and inserts it into the
42- // reconciled Database under the local visible name.
23+ // Imported elements - refs to other files, resolved by exportSchemaJson.
4324export interface DatabaseExternals {
4425 tables : ElementRef [ ] ;
4526 enums : ElementRef [ ] ;
@@ -71,11 +52,8 @@ export interface DiagramView {
7152 token : TokenPosition ;
7253}
7354
74- // Per-file interpreted schema. Contains both local elements (declared in
75- // this file) and `externals` (references to elements imported from other
76- // files). After `exportSchemaJson` reconciliation, the externals are
77- // resolved into real elements and merged into the top-level arrays, so the
78- // output looks like a single-file Database to downstream consumers.
55+ // Per-file schema. Local elements + externals (import refs).
56+ // After exportSchemaJson, externals are merged in and output looks single-file.
7957export interface Database {
8058 schemas : [ ] ;
8159 tables : Table [ ] ;
@@ -87,18 +65,12 @@ export interface Database {
8765 project ?: Project ;
8866 tablePartials : TablePartial [ ] ;
8967 records : TableRecord [ ] ;
90- // Imported elements — populated by interpretNode, consumed by exportSchemaJson.
91- externals : DatabaseExternals ;
68+ externals : DatabaseExternals ; // populated by interpretNode, consumed by exportSchemaJson
9269 diagramViews : DiagramView [ ] ;
9370 token ?: TokenPosition ;
9471}
9572
96- // The full project view produced by `interpretProject()`.
97- // - `files`: one Database per source file (keyed by absolute filepath).
98- // Each contains only that file's own elements + its externals list.
99- // - `items`: a flat merge of ALL files' elements (no externals, no dedup).
100- // Used by `exportSchemaJson` to look up canonical elements by name
101- // when resolving a file's imports.
73+ // Full project: files = per-file Database, items = flat merge for canonical lookup.
10274export interface MasterDatabase {
10375 files : Record < string , Database > ;
10476 items : Database ;
0 commit comments