Skip to content

Commit dc60fa9

Browse files
committed
refactor: concise comments in schemaJson and symbols
1 parent 6b3837d commit dc60fa9

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

packages/dbml-parse/src/core/types/schemaJson.ts

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
1915
export 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.
4324
export 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.
7957
export 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.
10274
export interface MasterDatabase {
10375
files: Record<string, Database>;
10476
items: Database;

packages/dbml-parse/src/core/types/symbol/symbols.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class NodeSymbol implements Internable<InternedNodeSymbol> {
156156
export class AliasSymbol extends NodeSymbol {
157157
declare declaration: ElementDeclarationNode;
158158
declare name: string;
159-
// The symbol this alias points at (may itself be an alias use
159+
// The symbol this alias points at (may itself be an alias - use
160160
// `originalSymbol` to reach the root).
161161
aliasedSymbol: NodeSymbol;
162162

@@ -192,7 +192,7 @@ export class AliasSymbol extends NodeSymbol {
192192

193193
// A symbol created by a `use`/`reuse` import specifier.
194194
// `usedSymbol` points at the imported symbol in the source file.
195-
// `canBeImported` is true only for `reuse` (re-exported) plain `use`
195+
// `canBeImported` is true only for `reuse` (re-exported) - plain `use`
196196
// imports are non-transitive and invisible to further importers.
197197
export class UseSymbol extends NodeSymbol {
198198
// The `UseSpecifierNode` or `WildcardNode` that produced this symbol.
@@ -309,4 +309,3 @@ export class SchemaSymbol extends NodeSymbol {
309309
return this.qualifiedName.join('.') === DEFAULT_SCHEMA_NAME;
310310
}
311311
}
312-

0 commit comments

Comments
 (0)