@dbml/parse 8.0.0-alpha.10 → 8.0.0-alpha.12

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.
@@ -1235,7 +1235,7 @@ var isAbsolute = function(r) {
1235
1235
  }
1236
1236
  relativeTo(r) {
1237
1237
  let j = relative$1(r, this.path);
1238
- return j.startsWith(".") ? j : `./${j}`;
1238
+ return !j.startsWith("./") && !j.startsWith("../") && ![".", ".."].includes(j) ? `./${j}` : j;
1239
1239
  }
1240
1240
  toString() {
1241
1241
  return this.path;
@@ -7359,14 +7359,17 @@ var ProgramInterpreter = class {
7359
7359
  let P = N.getValue();
7360
7360
  P && this.pushElement(M, P);
7361
7361
  }
7362
- let r = /* @__PURE__ */ new Set(), M = this.compiler.symbolMembers(this.programSymbol).getFiltered(UNHANDLED) ?? [];
7363
- for (let N of M) {
7364
- if (!(N instanceof SchemaSymbol)) continue;
7365
- let M = this.compiler.symbolMembers(N).getFiltered(UNHANDLED) ?? [];
7366
- for (let j of M) {
7362
+ let r = /* @__PURE__ */ new Set(), M = (this.compiler.symbolMembers(this.programSymbol).getFiltered(UNHANDLED) ?? []).filter((r) => r instanceof SchemaSymbol);
7363
+ for (; M.length > 0;) {
7364
+ let N = M.shift(), P = this.compiler.symbolMembers(N).getFiltered(UNHANDLED) ?? [];
7365
+ for (let j of P) {
7366
+ if (j instanceof SchemaSymbol) {
7367
+ M.push(j);
7368
+ continue;
7369
+ }
7367
7370
  if (!(j instanceof UseSymbol)) continue;
7368
- let M = j.originalSymbol.intern();
7369
- r.has(M) || (r.add(M), this.interpretUseSymbol(j));
7371
+ let N = j.originalSymbol.intern();
7372
+ r.has(N) || (r.add(N), this.interpretUseSymbol(j));
7370
7373
  }
7371
7374
  }
7372
7375
  }
@@ -7635,7 +7638,7 @@ var ProjectBinder = class {
7635
7638
  interpretBody(r) {
7636
7639
  return r.body.flatMap((r) => {
7637
7640
  let j = r;
7638
- switch (j.type?.value.toLowerCase()) {
7641
+ switch (j.getElementKind()) {
7639
7642
  case ElementKind.Table: {
7640
7643
  let r = this.interpretSubElement(j);
7641
7644
  return r.getValue() && this.project.tables?.push(r.getValue()), r.getErrors();
@@ -8324,7 +8327,7 @@ function usableMembers(r) {
8324
8327
  function schemaMembership(r, M, N) {
8325
8328
  let P = M.qualifiedName, F;
8326
8329
  if (F = N instanceof UseSpecifierNode ? useUtils.visibleName(r, N) : r.nodeFullname(N).getFiltered(UNHANDLED), !F) return { kind: "none" };
8327
- let I = F.length <= 1 ? [DEFAULT_SCHEMA_NAME] : F.slice(0, -1);
8330
+ let I = N instanceof UseSpecifierNode && N.getSymbolKind() === SymbolKind.Schema ? F : F.length <= 1 ? [DEFAULT_SCHEMA_NAME] : F.slice(0, -1);
8328
8331
  return I.length < P.length || !P.every((r, j) => r === I[j]) ? { kind: "none" } : I.length === P.length ? { kind: "direct" } : {
8329
8332
  kind: "child",
8330
8333
  schemaName: I[P.length]
@@ -8588,7 +8591,7 @@ var TableBinder = class {
8588
8591
  }
8589
8592
  interpretSubElements(r) {
8590
8593
  return r.flatMap((r) => {
8591
- switch (r.type?.value.toLowerCase()) {
8594
+ switch (r.getElementKind()) {
8592
8595
  case ElementKind.Note: return this.table.note = {
8593
8596
  value: normalizeNote(extractQuotedStringToken(r.body instanceof BlockExpressionNode ? r.body.body[0].callee : r.body.callee)),
8594
8597
  token: getTokenPosition(r)
@@ -8608,8 +8611,8 @@ var TableBinder = class {
8608
8611
  P.name = extractVariableFromExpression(r.expression) || "";
8609
8612
  let F = r.expression ? this.compiler.nodeReferee(r.expression).getFiltered(UNHANDLED) : void 0, I = this.compiler.parseFile(this.filepath).getValue().ast, L = this.compiler.nodeSymbol(I).getFiltered(UNHANDLED);
8610
8613
  if (F && !L.inNestedSchema(this.compiler, F)) {
8611
- let M = this.compiler.nodeSymbol(this.declarationNode).getFiltered(UNHANDLED), P = M ? (this.compiler.symbolUses(M).getFiltered(UNHANDLED) ?? []).find((r) => r.filepath.equals(this.filepath)) : void 0;
8612
- N.push(new CompileError(CompileErrorCode.UNSUPPORTED, `Import TablePartial from '${F.filepath}' first. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`, P?.useSpecifierDeclaration ?? r));
8614
+ let M = this.compiler.nodeSymbol(this.declarationNode).getFiltered(UNHANDLED), I = M ? (this.compiler.symbolUses(M).getFiltered(UNHANDLED) ?? []).find((r) => r.filepath.equals(this.filepath)) : void 0;
8615
+ N.push(new CompileError(CompileErrorCode.UNSUPPORTED, `Import TablePartial ${P.name} from '${F.filepath}' first. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`, I?.useSpecifierDeclaration ?? r));
8613
8616
  }
8614
8617
  return this.table.partials.push(P), N;
8615
8618
  }
@@ -9011,8 +9014,8 @@ var TableGroupBinder = class {
9011
9014
  }
9012
9015
  interpretSubElements(r) {
9013
9016
  return r.flatMap((r) => {
9014
- switch (r.type?.value.toLowerCase()) {
9015
- case "note":
9017
+ switch (r.getElementKind()) {
9018
+ case ElementKind.Note:
9016
9019
  this.tableGroup.note = {
9017
9020
  value: normalizeNote(extractQuotedStringToken(r.body instanceof BlockExpressionNode ? r.body.body[0].callee : r.body.callee)),
9018
9021
  token: getTokenPosition(r)
@@ -9233,7 +9236,7 @@ var TablePartialBinder = class {
9233
9236
  }
9234
9237
  interpretSubElements(r) {
9235
9238
  return r.flatMap((r) => {
9236
- switch (r.type?.value.toLowerCase()) {
9239
+ switch (r.getElementKind()) {
9237
9240
  case ElementKind.Note: return this.tablePartial.note = {
9238
9241
  value: normalizeNote(extractQuotedStringToken(r.body instanceof BlockExpressionNode ? r.body.body[0].callee : r.body.callee)),
9239
9242
  token: getTokenPosition(r)
@@ -9498,11 +9501,15 @@ function handleMemberSelectiveUses(r, N, P, F) {
9498
9501
  function mergeImportedSchema(r, M, N, P = /* @__PURE__ */ new Set()) {
9499
9502
  if (N.getSymbolKind() !== SymbolKind.Schema || !N.name) return [];
9500
9503
  let F = r.nodeReferee(N.name).getFiltered(UNHANDLED);
9501
- if (!F || !F.isKind(SymbolKind.Schema) || (r.nodeAlias(N).getFiltered(UNHANDLED) ?? r.nodeFullname(N).getFiltered(UNHANDLED)?.at(0)) !== M.name) return [];
9502
- let I = F.intern();
9503
- if (P.has(I)) return [];
9504
- P.add(I);
9505
- let L = r.usableMembers(F).getFiltered(UNHANDLED);
9504
+ if (!F || !F.isKind(SymbolKind.Schema)) return [];
9505
+ let I = useUtils.visibleName(r, N), L = M.qualifiedName;
9506
+ return !I || I.length !== L.length || !I.every((r, j) => r === L[j]) ? [] : mergeSchemaMembers(r, M, N, F, P);
9507
+ }
9508
+ function mergeSchemaMembers(r, M, N, P, F) {
9509
+ let I = P.intern();
9510
+ if (F.has(I)) return [];
9511
+ F.add(I);
9512
+ let L = r.usableMembers(P).getFiltered(UNHANDLED);
9506
9513
  if (!L) return [];
9507
9514
  let R = L.nonSchemaMembers.filter((r) => r.canBeImported).map((j) => r.symbolFactory.create(UseSymbol, {
9508
9515
  kind: j.kind,
@@ -9512,7 +9519,20 @@ function mergeImportedSchema(r, M, N, P = /* @__PURE__ */ new Set()) {
9512
9519
  name: j.name
9513
9520
  }, M.filepath));
9514
9521
  for (let j of [...R]) j.isKind(SymbolKind.TableGroup) && R.push(...expandTableGroup(r, M, j));
9515
- for (let j of L.reuses.selective) R.push(...mergeImportedSchema(r, M, j, P));
9522
+ for (let P of L.reuses.selective) if (R.push(...mergeImportedSchema(r, M, P, F)), schemaMembership(r, M, P).kind === "direct") {
9523
+ let F = r.nodeSymbol(P).getFiltered(UNHANDLED);
9524
+ F && F.canBeImported && R.push(r.symbolFactory.create(UseSymbol, {
9525
+ kind: F.kind,
9526
+ declaration: F.originalSymbol.declaration,
9527
+ usedSymbol: F.originalSymbol,
9528
+ useSpecifierDeclaration: N,
9529
+ name: F.name
9530
+ }, M.filepath));
9531
+ }
9532
+ for (let { importPath: j } of L.reuses.wildcard) {
9533
+ let P = findSchemaSymbolInFilepath(r, j, M.qualifiedName);
9534
+ P && R.push(...mergeSchemaMembers(r, M, N, P, F));
9535
+ }
9516
9536
  return R;
9517
9537
  }
9518
9538
  function handleMemberWildcardUses(r, M, N, P, F, I = /* @__PURE__ */ new Set()) {
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.10",
4
+ "version": "8.0.0-alpha.12",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -46,5 +46,5 @@
46
46
  "engines": {
47
47
  "node": ">=18"
48
48
  },
49
- "gitHead": "219525258181f597943175cf46783566dcddb441"
49
+ "gitHead": "53557d9ec226c4e7b8177229efce49594535502b"
50
50
  }