@dbml/parse 8.0.0-alpha.4 → 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.
@@ -8196,7 +8196,7 @@ function nodeRefereeOfRefEndpoint(r, N, P) {
8196
8196
  }
8197
8197
  const useUtils = { visibleName(r, M) {
8198
8198
  let N = M instanceof SyntaxNode ? M : M.useSpecifierDeclaration instanceof UseSpecifierNode ? M.useSpecifierDeclaration : M.declaration;
8199
- if (N) return r.nodeAlias(N).mapFiltered((r) => [r], UNHANDLED, void 0).getFiltered(UNHANDLED) || r.nodeFullname(N).getFiltered(UNHANDLED);
8199
+ if (N instanceof UseSpecifierNode && M instanceof NodeSymbol && N.getSymbolKind() !== M.kind && (N = M.declaration), N) return r.nodeAlias(N).mapFiltered((r) => [r], UNHANDLED, void 0).getFiltered(UNHANDLED) || r.nodeFullname(N).getFiltered(UNHANDLED);
8200
8200
  } }, useModule$1 = {
8201
8201
  nodeSymbol(N, P) {
8202
8202
  if (!isUseSpecifier(P) || !P.name) return Report.create(PASS_THROUGH);
@@ -9097,16 +9097,11 @@ function nodeRefereeOfTableGroupField(r, N, P) {
9097
9097
  let F = extractVarNameFromPrimaryVariable(P) ?? "";
9098
9098
  if (!isAccessExpression(P.parentNode)) {
9099
9099
  let I = r.symbolMembers(N).getFiltered(UNHANDLED);
9100
- if (I) for (let N of I) {
9101
- if (!(N instanceof SchemaSymbol)) continue;
9102
- let P = r.lookupMembers(N, SymbolKind.Table, F);
9103
- if (P) return Report.create(P);
9104
- if (!N.isPublicSchema()) {
9105
- let P = r.symbolMembers(N).getFiltered(UNHANDLED);
9106
- if (P) {
9107
- let N = P.find((M) => !M.isKind(SymbolKind.Table) || !M.declaration ? !1 : r.nodeAlias(M.declaration).getFiltered(UNHANDLED) === F);
9108
- if (N) return new Report(N);
9109
- }
9100
+ if (I) {
9101
+ let j = I.find((r) => r instanceof SchemaSymbol && r.isPublicSchema());
9102
+ if (j) {
9103
+ let N = r.lookupMembers(j, SymbolKind.Table, F);
9104
+ if (N) return Report.create(N);
9110
9105
  }
9111
9106
  }
9112
9107
  let L = r.lookupMembers(N, SymbolKind.Table, F);
@@ -9439,7 +9434,17 @@ const schemaModule = { symbolMembers(N, P) {
9439
9434
  for (let { importPath: r, node: j } of I.uses.wildcard) L.push(...handleMemberWildcardUses(N, P, r, j, R));
9440
9435
  L.push(...R.values());
9441
9436
  let B = [...L];
9442
- for (let r of L) r.isKind(SymbolKind.TableGroup) && B.push(...expandTableGroup(N, r));
9437
+ {
9438
+ let r = L.filter((r) => r.isKind(SymbolKind.TableGroup));
9439
+ if (!P.isPublicSchema()) {
9440
+ let M = N.usableMembers(P.filepath).getFiltered(UNHANDLED)?.schemaMembers.find((r) => r.isPublicSchema());
9441
+ if (M) {
9442
+ let P = N.symbolMembers(M).getFiltered(UNHANDLED);
9443
+ P && r.push(...P.filter((r) => r.isKind(SymbolKind.TableGroup)));
9444
+ }
9445
+ }
9446
+ for (let j of r) B.push(...expandTableGroup(N, P, j));
9447
+ }
9443
9448
  let V = /* @__PURE__ */ new Set(), H = B.filter((r) => {
9444
9449
  let j = `${r.originalSymbol.intern()}:${r.name ?? ""}`;
9445
9450
  return V.has(j) ? !1 : (V.add(j), !0);
@@ -9478,7 +9483,7 @@ function handleMemberSelectiveUses(r, N, P, F) {
9478
9483
  function mergeImportedSchema(r, M, N, P = /* @__PURE__ */ new Set()) {
9479
9484
  if (N.getSymbolKind() !== SymbolKind.Schema || !N.name) return [];
9480
9485
  let F = r.nodeReferee(N.name).getFiltered(UNHANDLED);
9481
- 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 [];
9482
9487
  let I = F.intern();
9483
9488
  if (P.has(I)) return [];
9484
9489
  P.add(I);
@@ -9488,9 +9493,10 @@ function mergeImportedSchema(r, M, N, P = /* @__PURE__ */ new Set()) {
9488
9493
  kind: j.kind,
9489
9494
  declaration: j.originalSymbol.declaration,
9490
9495
  usedSymbol: j.originalSymbol,
9491
- useSpecifierDeclaration: void 0,
9496
+ useSpecifierDeclaration: N,
9492
9497
  name: j.name
9493
9498
  }, M.filepath));
9499
+ for (let j of [...R]) j.isKind(SymbolKind.TableGroup) && R.push(...expandTableGroup(r, M, j));
9494
9500
  for (let j of L.reuses.selective) R.push(...mergeImportedSchema(r, M, j, P));
9495
9501
  return R;
9496
9502
  }
@@ -9512,7 +9518,7 @@ function handleMemberWildcardUses(r, M, N, P, F, I = /* @__PURE__ */ new Set())
9512
9518
  let { reuses: { selective: B, wildcard: V } } = R;
9513
9519
  for (let N of B) {
9514
9520
  let P = handleMemberSelectiveUses(r, M, N, F).getFiltered(UNHANDLED);
9515
- P && z.push(P);
9521
+ P && z.push(P), z.push(...mergeImportedSchema(r, M, N));
9516
9522
  }
9517
9523
  for (let { importPath: j } of V) z.push(...handleMemberWildcardUses(r, M, j, P, F, I));
9518
9524
  return z;
@@ -9530,34 +9536,36 @@ function findSchemaSymbolInFilepath(r, M, N) {
9530
9536
  }
9531
9537
  return I;
9532
9538
  }
9533
- function expandTableGroup(r, M) {
9534
- if (!M.isKind(SymbolKind.TableGroup)) return [];
9535
- let N = M.originalSymbol, P = r.symbolMembers(N).getFiltered(UNHANDLED);
9536
- if (!P) return [];
9537
- let F = [];
9538
- for (let j of P) {
9539
+ function expandTableGroup(r, M, N) {
9540
+ if (!N.isKind(SymbolKind.TableGroup) || !(N instanceof UseSymbol)) return [];
9541
+ let P = N.originalSymbol, F = r.symbolMembers(P).getFiltered(UNHANDLED);
9542
+ if (!F) return [];
9543
+ let I = M.qualifiedName, L = [];
9544
+ for (let j of F) {
9539
9545
  if (!j.isKind(SymbolKind.TableGroupField) || !j.declaration) continue;
9540
- let N = j.declaration.callee;
9541
- if (!N) continue;
9542
- let P = destructureComplexVariable(N);
9546
+ let M = j.declaration.callee;
9547
+ if (!M) continue;
9548
+ let P = destructureComplexVariable(M);
9543
9549
  if (!P || P.length === 0) continue;
9544
- let I = j.declaration.filepath, L = lookupTableInFile(r, I, P);
9545
- L && M instanceof UseSymbol && F.push(r.symbolFactory.create(UseSymbol, {
9550
+ let F = P.length <= 1 ? [DEFAULT_SCHEMA_NAME] : P.slice(0, -1);
9551
+ if (F.length !== I.length || !I.every((r, j) => r === F[j])) continue;
9552
+ let R = j.declaration.filepath, z = lookupTableInFile(r, R, P);
9553
+ z && L.push(r.symbolFactory.create(UseSymbol, {
9546
9554
  kind: SymbolKind.Table,
9547
- declaration: L.declaration,
9548
- usedSymbol: L,
9555
+ declaration: z.declaration,
9556
+ usedSymbol: z,
9549
9557
  useSpecifierDeclaration: void 0,
9550
- name: L.name
9551
- }, M.filepath));
9558
+ name: z.name
9559
+ }, N.filepath));
9552
9560
  }
9553
- return F;
9561
+ return L;
9554
9562
  }
9555
9563
  function lookupTableInFile(r, M, N) {
9556
9564
  if (N.length === 1) {
9557
9565
  let P = r.usableMembers(M).getFiltered(UNHANDLED);
9558
9566
  return P ? P.nonSchemaMembers.find((r) => r.isKind(SymbolKind.Table) && r.name === N[0]) : void 0;
9559
9567
  }
9560
- let [P, F] = [N[0], N[N.length - 1]], I = r.usableMembers(M).getFiltered(UNHANDLED);
9568
+ let P = N[0], F = N[N.length - 1], I = r.usableMembers(M).getFiltered(UNHANDLED);
9561
9569
  if (!I) return;
9562
9570
  let L = I.schemaMembers.find((r) => r.name === P);
9563
9571
  if (!L) return;
@@ -12017,10 +12025,14 @@ function scanExistingUses(r, j, M) {
12017
12025
  let r = N.importKind.value ?? void 0;
12018
12026
  r && !j.has(r.toLowerCase()) && (F = r);
12019
12027
  }
12020
- F && F.toLowerCase() !== "from" && P.push({
12021
- kind: r,
12022
- name: F
12023
- });
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
+ }
12024
12036
  }
12025
12037
  } else r.specifiers instanceof WildcardNode && P.push({ name: "*" });
12026
12038
  if (P.length === 0 && !(r.specifiers instanceof WildcardNode)) continue;
@@ -12044,7 +12056,7 @@ function mergeSymbolIntoUses(r, j, M, N, P, F) {
12044
12056
  if (R !== -1) {
12045
12057
  let r = I[R];
12046
12058
  return r.specifiers.some((r) => r.name === j) ? { topInsert: "" } : {
12047
- 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),
12048
12060
  removeRange: expandToFullLines(F, r.startOffset, r.endOffset)
12049
12061
  };
12050
12062
  }
@@ -13278,33 +13290,41 @@ function containerScopeKind(r, j) {
13278
13290
  default: return ScopeKind.CUSTOM;
13279
13291
  }
13280
13292
  }
13281
- function canonicalName(r, N) {
13282
- let P = N.originalSymbol;
13283
- if (P.filepath.intern() === r.intern()) return Report.create(fullnameToCanonical(this, P));
13284
- let F = this.parseFile(r).getValue().ast, I = this.nodeSymbol(F).getFiltered(UNHANDLED);
13285
- if (!I) return Report.create(fullnameToCanonical(this, P));
13286
- let L = this.symbolMembers(I).getFiltered(UNHANDLED) ?? [], R = [...L];
13287
- for (let r of L) if (r instanceof SchemaSymbol && r.isKind(SymbolKind.Schema)) {
13288
- let M = this.symbolMembers(r).getFiltered(UNHANDLED);
13289
- M && R.push(...M);
13290
- }
13291
- for (let j of R) if (j.filepath.intern() === r.intern() && j.originalSymbol === P && (j instanceof UseSymbol || j instanceof AliasSymbol)) {
13292
- let r = j.name;
13293
- if (!r) continue;
13294
- 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({
13295
13301
  schema: "",
13296
- 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
13297
13308
  });
13298
- let N = fullnameToCanonical(this, P);
13299
- return N ? Report.create({
13300
- ...N,
13301
- name: r
13309
+ let F = fullnameToCanonical(this, N);
13310
+ return F ? Report.create({
13311
+ ...F,
13312
+ name: j
13302
13313
  }) : Report.create({
13303
13314
  schema: DEFAULT_SCHEMA_NAME,
13304
- name: r
13315
+ name: j
13305
13316
  });
13306
13317
  }
13307
- 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;
13308
13328
  }
13309
13329
  function fullnameToCanonical(r, M) {
13310
13330
  if (!M.declaration) return M.name ? {
@@ -14502,11 +14522,30 @@ function resolutionIndex() {
14502
14522
  };
14503
14523
  N(M);
14504
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
+ }
14505
14540
  return {
14506
14541
  references: r,
14507
- metadata: M
14542
+ metadata: M,
14543
+ parents: L
14508
14544
  };
14509
14545
  }
14546
+ function symbolParent(r) {
14547
+ return this.resolutionIndex().parents.get(r.intern()) ?? [];
14548
+ }
14510
14549
  function symbolReferences(r) {
14511
14550
  return this.resolutionIndex().references.get(r.intern()) ?? [];
14512
14551
  }
@@ -14791,7 +14830,7 @@ function computeDeleteEdit(r, j, M) {
14791
14830
  }
14792
14831
  var COMPUTING = Symbol("COMPUTING"), Compiler = class {
14793
14832
  constructor() {
14794
- 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 = {
14795
14834
  invalidStream: this.localQuery(invalidStream),
14796
14835
  flatStream: this.localQuery(flatStream)
14797
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.4",
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": "17d4675433b702912a20dcc65a63c03c73c56db5"
48
+ "gitHead": "52721b96504df2eeb4ff7fc13292896221a837ef"
49
49
  }