@dbml/parse 8.0.0-alpha.5 → 8.0.0-alpha.6

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.
@@ -9483,7 +9483,7 @@ function handleMemberSelectiveUses(r, N, P, F) {
9483
9483
  function mergeImportedSchema(r, M, N, P = /* @__PURE__ */ new Set()) {
9484
9484
  if (N.getSymbolKind() !== SymbolKind.Schema || !N.name) return [];
9485
9485
  let F = r.nodeReferee(N.name).getFiltered(UNHANDLED);
9486
- if (!F || !F.isKind(SymbolKind.Schema) || F.name !== M.name) return [];
9486
+ if (!F || !F.isKind(SymbolKind.Schema) || (r.nodeAlias(N).getFiltered(UNHANDLED) ?? r.nodeFullname(N).getFiltered(UNHANDLED)?.at(0)) !== M.name) return [];
9487
9487
  let I = F.intern();
9488
9488
  if (P.has(I)) return [];
9489
9489
  P.add(I);
@@ -12025,10 +12025,14 @@ function scanExistingUses(r, j, M) {
12025
12025
  let r = N.importKind.value ?? void 0;
12026
12026
  r && !j.has(r.toLowerCase()) && (F = r);
12027
12027
  }
12028
- F && F.toLowerCase() !== "from" && P.push({
12029
- kind: r,
12030
- name: F
12031
- });
12028
+ if (F && F.toLowerCase() !== "from") {
12029
+ let j = N.alias ? extractVariableFromExpression(N.alias) : void 0;
12030
+ P.push({
12031
+ kind: r,
12032
+ name: F,
12033
+ alias: j
12034
+ });
12035
+ }
12032
12036
  }
12033
12037
  } else r.specifiers instanceof WildcardNode && P.push({ name: "*" });
12034
12038
  if (P.length === 0 && !(r.specifiers instanceof WildcardNode)) continue;
@@ -12052,7 +12056,7 @@ function mergeSymbolIntoUses(r, j, M, N, P, F) {
12052
12056
  if (R !== -1) {
12053
12057
  let r = I[R];
12054
12058
  return r.specifiers.some((r) => r.name === j) ? { topInsert: "" } : {
12055
- topInsert: buildUseStatement(uniqueInOrder([...r.specifiers.filter((r) => r.name !== "*").map((r) => `${r.kind ?? M} ${r.name}`), z]), L, B),
12059
+ topInsert: buildUseStatement(uniqueInOrder([...r.specifiers.filter((r) => r.name !== "*").map((r) => `${r.kind ?? M} ${r.name}${r.alias ? ` as ${r.alias}` : ""}`), z]), L, B),
12056
12060
  removeRange: expandToFullLines(F, r.startOffset, r.endOffset)
12057
12061
  };
12058
12062
  }
@@ -13286,33 +13290,41 @@ function containerScopeKind(r, j) {
13286
13290
  default: return ScopeKind.CUSTOM;
13287
13291
  }
13288
13292
  }
13289
- function canonicalName(r, N) {
13290
- let P = N.originalSymbol;
13291
- if (P.filepath.intern() === r.intern()) return Report.create(fullnameToCanonical(this, P));
13292
- let F = this.parseFile(r).getValue().ast, I = this.nodeSymbol(F).getFiltered(UNHANDLED);
13293
- if (!I) return Report.create(fullnameToCanonical(this, P));
13294
- let L = this.symbolMembers(I).getFiltered(UNHANDLED) ?? [], R = [...L];
13295
- for (let r of L) if (r instanceof SchemaSymbol && r.isKind(SymbolKind.Schema)) {
13296
- let M = this.symbolMembers(r).getFiltered(UNHANDLED);
13297
- M && R.push(...M);
13298
- }
13299
- for (let j of R) if (j.filepath.intern() === r.intern() && j.originalSymbol === P && (j instanceof UseSymbol || j instanceof AliasSymbol)) {
13300
- let r = j.name;
13301
- if (!r) continue;
13302
- if (r !== P.name) return Report.create({
13293
+ function canonicalName(r, j) {
13294
+ let N = j.originalSymbol;
13295
+ if (N.filepath.intern() === r.intern()) return Report.create(fullnameToCanonical(this, N));
13296
+ let P = [...this.symbolUses(N).getValue(), ...this.symbolAliases(N).getValue()].filter((j) => j.filepath.equals(r));
13297
+ for (let r of P) {
13298
+ let j = r.name;
13299
+ if (!j) continue;
13300
+ if (j !== N.name) return Report.create({
13303
13301
  schema: "",
13304
- name: r
13302
+ name: j
13303
+ });
13304
+ let P = getSchemaChain(this, r);
13305
+ if (P.length > 0) return Report.create({
13306
+ schema: P.join("."),
13307
+ name: j
13305
13308
  });
13306
- let N = fullnameToCanonical(this, P);
13307
- return N ? Report.create({
13308
- ...N,
13309
- name: r
13309
+ let F = fullnameToCanonical(this, N);
13310
+ return F ? Report.create({
13311
+ ...F,
13312
+ name: j
13310
13313
  }) : Report.create({
13311
13314
  schema: DEFAULT_SCHEMA_NAME,
13312
- name: r
13315
+ name: j
13313
13316
  });
13314
13317
  }
13315
- return Report.create(fullnameToCanonical(this, P));
13318
+ return Report.create(fullnameToCanonical(this, N));
13319
+ }
13320
+ function getSchemaChain(r, j) {
13321
+ let M = [], N = j;
13322
+ for (; N;) {
13323
+ let j = r.symbolParent(N).find((r) => r instanceof SchemaSymbol && r.isKind(SymbolKind.Schema));
13324
+ if (!j || j.isPublicSchema()) break;
13325
+ M.unshift(j.name ?? ""), N = j;
13326
+ }
13327
+ return M;
13316
13328
  }
13317
13329
  function fullnameToCanonical(r, M) {
13318
13330
  if (!M.declaration) return M.name ? {
@@ -14510,11 +14522,30 @@ function resolutionIndex() {
14510
14522
  };
14511
14523
  N(M);
14512
14524
  }
14525
+ let L = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Set();
14526
+ function z(r, M) {
14527
+ let N = M.intern();
14528
+ if (R.has(N)) return;
14529
+ R.add(N);
14530
+ let P = r.symbolMembers(M).getFiltered(UNHANDLED);
14531
+ if (P) for (let j of P) {
14532
+ let N = j.intern(), P = L.get(N);
14533
+ P || (P = [], L.set(N, P)), P.push(M), j instanceof SchemaSymbol && j.isKind(SymbolKind.Schema) && z(r, j);
14534
+ }
14535
+ }
14536
+ for (let r of N.values()) {
14537
+ let M = r.getValue().ast, N = this.nodeSymbol(M).getFiltered(UNHANDLED);
14538
+ N && z(this, N);
14539
+ }
14513
14540
  return {
14514
14541
  references: r,
14515
- metadata: M
14542
+ metadata: M,
14543
+ parents: L
14516
14544
  };
14517
14545
  }
14546
+ function symbolParent(r) {
14547
+ return this.resolutionIndex().parents.get(r.intern()) ?? [];
14548
+ }
14518
14549
  function symbolReferences(r) {
14519
14550
  return this.resolutionIndex().references.get(r.intern()) ?? [];
14520
14551
  }
@@ -14799,7 +14830,7 @@ function computeDeleteEdit(r, j, M) {
14799
14830
  }
14800
14831
  var COMPUTING = Symbol("COMPUTING"), Compiler = class {
14801
14832
  constructor() {
14802
- this.nodeIdGenerator = new SyntaxNodeIdGenerator(), this.symbolIdGenerator = new NodeSymbolIdGenerator(), this.symbolFactory = new SymbolFactory(this.symbolIdGenerator), this.layout = new MemoryProjectLayout(), this.globalCache = /* @__PURE__ */ new Map(), this.localCache = /* @__PURE__ */ new Map(), this.parseFile = this.localQuery(parseFile), this.parseProject = this.globalQuery(parseProject), this.validateNode = this.localQuery(validateNode), this.validateFile = this.localQuery(validateFile), this.nodeFullname = this.localQuery(nodeFullname), this.nodeAlias = this.localQuery(nodeAlias), this.nodeSettings = this.localQuery(nodeSettings), this.canonicalName = this.globalQuery(canonicalName), this.bindNode = this.globalQuery(bindNode), this.bindFile = this.globalQuery(bindFile), this.bindProject = this.globalQuery(bindProject), this.interpretSymbol = this.globalQuery(interpretSymbol), this.interpretMetadata = interpretMetadata.bind(this), this.interpretFile = this.globalQuery(interpretFile), this.interpretProject = this.globalQuery(interpretProject), this.nodeSymbol = this.globalQuery(nodeSymbol), this.nodeMetadata = this.globalQuery(nodeMetadata), this.symbolMembers = this.globalQuery(symbolMembers), this.lookupMembers = this.globalQuery(lookupMembers), this.nodeReferee = this.globalQuery(nodeReferee), this.resolutionIndex = this.globalQuery(resolutionIndex), this.symbolReferences = this.globalQuery(symbolReferences), this.symbolMetadata = this.globalQuery(symbolMetadata), this.symbolAliases = this.globalQuery(symbolAliases), this.symbolUses = this.globalQuery(symbolUses), this.fileDependencies = this.localQuery(fileDependencies), this.reachableFiles = this.globalQuery(reachableFiles), this.usableMembers = this.globalQuery(usableMembers), this.nodeAtPosition = this.localQuery(nodeAtPosition), this.renameTable = renameTable.bind(this), this.syncDiagramView = syncDiagramView.bind(this), this.token = {
14833
+ this.nodeIdGenerator = new SyntaxNodeIdGenerator(), this.symbolIdGenerator = new NodeSymbolIdGenerator(), this.symbolFactory = new SymbolFactory(this.symbolIdGenerator), this.layout = new MemoryProjectLayout(), this.globalCache = /* @__PURE__ */ new Map(), this.localCache = /* @__PURE__ */ new Map(), this.parseFile = this.localQuery(parseFile), this.parseProject = this.globalQuery(parseProject), this.validateNode = this.localQuery(validateNode), this.validateFile = this.localQuery(validateFile), this.nodeFullname = this.localQuery(nodeFullname), this.nodeAlias = this.localQuery(nodeAlias), this.nodeSettings = this.localQuery(nodeSettings), this.canonicalName = this.globalQuery(canonicalName), this.bindNode = this.globalQuery(bindNode), this.bindFile = this.globalQuery(bindFile), this.bindProject = this.globalQuery(bindProject), this.interpretSymbol = this.globalQuery(interpretSymbol), this.interpretMetadata = interpretMetadata.bind(this), this.interpretFile = this.globalQuery(interpretFile), this.interpretProject = this.globalQuery(interpretProject), this.nodeSymbol = this.globalQuery(nodeSymbol), this.nodeMetadata = this.globalQuery(nodeMetadata), this.symbolMembers = this.globalQuery(symbolMembers), this.lookupMembers = this.globalQuery(lookupMembers), this.nodeReferee = this.globalQuery(nodeReferee), this.resolutionIndex = this.globalQuery(resolutionIndex), this.symbolReferences = this.globalQuery(symbolReferences), this.symbolParent = this.globalQuery(symbolParent), this.symbolMetadata = this.globalQuery(symbolMetadata), this.symbolAliases = this.globalQuery(symbolAliases), this.symbolUses = this.globalQuery(symbolUses), this.fileDependencies = this.localQuery(fileDependencies), this.reachableFiles = this.globalQuery(reachableFiles), this.usableMembers = this.globalQuery(usableMembers), this.nodeAtPosition = this.localQuery(nodeAtPosition), this.renameTable = renameTable.bind(this), this.syncDiagramView = syncDiagramView.bind(this), this.token = {
14803
14834
  invalidStream: this.localQuery(invalidStream),
14804
14835
  flatStream: this.localQuery(flatStream)
14805
14836
  }, this.parse = {
@@ -42,6 +42,7 @@ export default class Compiler {
42
42
  nodeReferee: (node: SyntaxNode) => import('../core/types/report').default<typeof import('..').UNHANDLED> | import('../core/types/report').default<import('../core/types/symbol').NodeSymbol | undefined>;
43
43
  resolutionIndex: () => import('./queries/resolutionIndex').ResolutionIndex;
44
44
  symbolReferences: (symbol: import('../core/types/symbol').NodeSymbol) => SyntaxNode[];
45
+ symbolParent: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/symbol').NodeSymbol[];
45
46
  symbolMetadata: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/symbol').NodeMetadata[];
46
47
  symbolAliases: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').AliasSymbol[]>;
47
48
  symbolUses: (symbol: import('../core/types/symbol').NodeSymbol) => import('../core/types/report').default<import('../core/types/symbol').UseSymbol[]>;
@@ -5,7 +5,9 @@ import { default as Compiler } from '../index';
5
5
  export interface ResolutionIndex {
6
6
  references: Map<InternedNodeSymbol, SyntaxNode[]>;
7
7
  metadata: Map<InternedNodeSymbol, NodeMetadata[]>;
8
+ parents: Map<InternedNodeSymbol, NodeSymbol[]>;
8
9
  }
9
10
  export declare function resolutionIndex(this: Compiler): ResolutionIndex;
11
+ export declare function symbolParent(this: Compiler, symbol: NodeSymbol): NodeSymbol[];
10
12
  export declare function symbolReferences(this: Compiler, symbol: NodeSymbol): SyntaxNode[];
11
13
  export declare function symbolMetadata(this: Compiler, symbol: NodeSymbol): NodeMetadata[];
@@ -5,6 +5,7 @@ import { UseDeclarationNode } from '../../../core/types/nodes';
5
5
  export interface ParsedUseSpecifier {
6
6
  kind?: string;
7
7
  name: string;
8
+ alias?: string;
8
9
  }
9
10
  export interface ParsedUseStatement {
10
11
  startOffset: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dbml/parse",
4
- "version": "8.0.0-alpha.5",
4
+ "version": "8.0.0-alpha.6",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -45,5 +45,5 @@
45
45
  "engines": {
46
46
  "node": ">=18"
47
47
  },
48
- "gitHead": "2e6795b120c2ca4f16bb542295b2152f091d6ed9"
48
+ "gitHead": "52721b96504df2eeb4ff7fc13292896221a837ef"
49
49
  }