@dbml/core 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.
Files changed (3) hide show
  1. package/lib/index.cjs +87 -87
  2. package/lib/index.mjs +102 -63
  3. package/package.json +3 -3
package/lib/index.mjs CHANGED
@@ -9395,7 +9395,7 @@ function nodeRefereeOfRefEndpoint(_, VY, P) {
9395
9395
  }
9396
9396
  var useUtils = { visibleName(_, VY) {
9397
9397
  let P = VY instanceof SyntaxNode ? VY : VY.useSpecifierDeclaration instanceof UseSpecifierNode ? VY.useSpecifierDeclaration : VY.declaration;
9398
- if (P) return _.nodeAlias(P).mapFiltered((_) => [_], UNHANDLED, void 0).getFiltered(UNHANDLED) || _.nodeFullname(P).getFiltered(UNHANDLED);
9398
+ if (P instanceof UseSpecifierNode && VY instanceof NodeSymbol && P.getSymbolKind() !== VY.kind && (P = VY.declaration), P) return _.nodeAlias(P).mapFiltered((_) => [_], UNHANDLED, void 0).getFiltered(UNHANDLED) || _.nodeFullname(P).getFiltered(UNHANDLED);
9399
9399
  } }, useModule$1 = {
9400
9400
  nodeSymbol(_, VY) {
9401
9401
  if (!isUseSpecifier(VY) || !VY.name) return Report.create(PASS_THROUGH);
@@ -10294,16 +10294,11 @@ function nodeRefereeOfTableGroupField(_, VY, P) {
10294
10294
  let HY = extractVarNameFromPrimaryVariable(P) ?? "";
10295
10295
  if (!isAccessExpression(P.parentNode)) {
10296
10296
  let UY = _.symbolMembers(VY).getFiltered(UNHANDLED);
10297
- if (UY) for (let VY of UY) {
10298
- if (!(VY instanceof SchemaSymbol)) continue;
10299
- let P = _.lookupMembers(VY, SymbolKind.Table, HY);
10300
- if (P) return Report.create(P);
10301
- if (!VY.isPublicSchema()) {
10302
- let P = _.symbolMembers(VY).getFiltered(UNHANDLED);
10303
- if (P) {
10304
- let VY = P.find((VY) => !VY.isKind(SymbolKind.Table) || !VY.declaration ? !1 : _.nodeAlias(VY.declaration).getFiltered(UNHANDLED) === HY);
10305
- if (VY) return new Report(VY);
10306
- }
10297
+ if (UY) {
10298
+ let VY = UY.find((_) => _ instanceof SchemaSymbol && _.isPublicSchema());
10299
+ if (VY) {
10300
+ let P = _.lookupMembers(VY, SymbolKind.Table, HY);
10301
+ if (P) return Report.create(P);
10307
10302
  }
10308
10303
  }
10309
10304
  let WY = _.lookupMembers(VY, SymbolKind.Table, HY);
@@ -10635,7 +10630,17 @@ var schemaModule = { symbolMembers(_, VY) {
10635
10630
  for (let { importPath: P, node: GY } of HY.uses.wildcard) UY.push(...handleMemberWildcardUses(_, VY, P, GY, WY));
10636
10631
  UY.push(...WY.values());
10637
10632
  let KY = [...UY];
10638
- for (let VY of UY) VY.isKind(SymbolKind.TableGroup) && KY.push(...expandTableGroup(_, VY));
10633
+ {
10634
+ let P = UY.filter((_) => _.isKind(SymbolKind.TableGroup));
10635
+ if (!VY.isPublicSchema()) {
10636
+ let HY = _.usableMembers(VY.filepath).getFiltered(UNHANDLED)?.schemaMembers.find((_) => _.isPublicSchema());
10637
+ if (HY) {
10638
+ let VY = _.symbolMembers(HY).getFiltered(UNHANDLED);
10639
+ VY && P.push(...VY.filter((_) => _.isKind(SymbolKind.TableGroup)));
10640
+ }
10641
+ }
10642
+ for (let HY of P) KY.push(...expandTableGroup(_, VY, HY));
10643
+ }
10639
10644
  let qY = /* @__PURE__ */ new Set(), JY = KY.filter((_) => {
10640
10645
  let VY = `${_.originalSymbol.intern()}:${_.name ?? ""}`;
10641
10646
  return qY.has(VY) ? !1 : (qY.add(VY), !0);
@@ -10674,19 +10679,20 @@ function handleMemberSelectiveUses(_, VY, P, HY) {
10674
10679
  function mergeImportedSchema(_, VY, P, HY = /* @__PURE__ */ new Set()) {
10675
10680
  if (P.getSymbolKind() !== SymbolKind.Schema || !P.name) return [];
10676
10681
  let UY = _.nodeReferee(P.name).getFiltered(UNHANDLED);
10677
- if (!UY || !UY.isKind(SymbolKind.Schema) || UY.name !== VY.name) return [];
10682
+ if (!UY || !UY.isKind(SymbolKind.Schema) || (_.nodeAlias(P).getFiltered(UNHANDLED) ?? _.nodeFullname(P).getFiltered(UNHANDLED)?.at(0)) !== VY.name) return [];
10678
10683
  let WY = UY.intern();
10679
10684
  if (HY.has(WY)) return [];
10680
10685
  HY.add(WY);
10681
10686
  let GY = _.usableMembers(UY).getFiltered(UNHANDLED);
10682
10687
  if (!GY) return [];
10683
- let KY = GY.nonSchemaMembers.filter((_) => _.canBeImported).map((P) => _.symbolFactory.create(UseSymbol, {
10684
- kind: P.kind,
10685
- declaration: P.originalSymbol.declaration,
10686
- usedSymbol: P.originalSymbol,
10687
- useSpecifierDeclaration: void 0,
10688
- name: P.name
10688
+ let KY = GY.nonSchemaMembers.filter((_) => _.canBeImported).map((HY) => _.symbolFactory.create(UseSymbol, {
10689
+ kind: HY.kind,
10690
+ declaration: HY.originalSymbol.declaration,
10691
+ usedSymbol: HY.originalSymbol,
10692
+ useSpecifierDeclaration: P,
10693
+ name: HY.name
10689
10694
  }, VY.filepath));
10695
+ for (let P of [...KY]) P.isKind(SymbolKind.TableGroup) && KY.push(...expandTableGroup(_, VY, P));
10690
10696
  for (let P of GY.reuses.selective) KY.push(...mergeImportedSchema(_, VY, P, HY));
10691
10697
  return KY;
10692
10698
  }
@@ -10708,7 +10714,7 @@ function handleMemberWildcardUses(_, VY, P, HY, UY, WY = /* @__PURE__ */ new Set
10708
10714
  let { reuses: { selective: JY, wildcard: YY } } = KY;
10709
10715
  for (let P of JY) {
10710
10716
  let HY = handleMemberSelectiveUses(_, VY, P, UY).getFiltered(UNHANDLED);
10711
- HY && qY.push(HY);
10717
+ HY && qY.push(HY), qY.push(...mergeImportedSchema(_, VY, P));
10712
10718
  }
10713
10719
  for (let { importPath: P } of YY) qY.push(...handleMemberWildcardUses(_, VY, P, HY, UY, WY));
10714
10720
  return qY;
@@ -10726,34 +10732,36 @@ function findSchemaSymbolInFilepath(_, VY, P) {
10726
10732
  }
10727
10733
  return WY;
10728
10734
  }
10729
- function expandTableGroup(_, VY) {
10730
- if (!VY.isKind(SymbolKind.TableGroup)) return [];
10731
- let P = VY.originalSymbol, HY = _.symbolMembers(P).getFiltered(UNHANDLED);
10732
- if (!HY) return [];
10733
- let UY = [];
10734
- for (let P of HY) {
10735
- if (!P.isKind(SymbolKind.TableGroupField) || !P.declaration) continue;
10736
- let HY = P.declaration.callee;
10735
+ function expandTableGroup(_, VY, P) {
10736
+ if (!P.isKind(SymbolKind.TableGroup) || !(P instanceof UseSymbol)) return [];
10737
+ let HY = P.originalSymbol, UY = _.symbolMembers(HY).getFiltered(UNHANDLED);
10738
+ if (!UY) return [];
10739
+ let WY = VY.qualifiedName, GY = [];
10740
+ for (let VY of UY) {
10741
+ if (!VY.isKind(SymbolKind.TableGroupField) || !VY.declaration) continue;
10742
+ let HY = VY.declaration.callee;
10737
10743
  if (!HY) continue;
10738
- let WY = destructureComplexVariable(HY);
10739
- if (!WY || WY.length === 0) continue;
10740
- let GY = P.declaration.filepath, KY = lookupTableInFile(_, GY, WY);
10741
- KY && VY instanceof UseSymbol && UY.push(_.symbolFactory.create(UseSymbol, {
10744
+ let UY = destructureComplexVariable(HY);
10745
+ if (!UY || UY.length === 0) continue;
10746
+ let KY = UY.length <= 1 ? [DEFAULT_SCHEMA_NAME$1] : UY.slice(0, -1);
10747
+ if (KY.length !== WY.length || !WY.every((_, VY) => _ === KY[VY])) continue;
10748
+ let qY = VY.declaration.filepath, JY = lookupTableInFile(_, qY, UY);
10749
+ JY && GY.push(_.symbolFactory.create(UseSymbol, {
10742
10750
  kind: SymbolKind.Table,
10743
- declaration: KY.declaration,
10744
- usedSymbol: KY,
10751
+ declaration: JY.declaration,
10752
+ usedSymbol: JY,
10745
10753
  useSpecifierDeclaration: void 0,
10746
- name: KY.name
10747
- }, VY.filepath));
10754
+ name: JY.name
10755
+ }, P.filepath));
10748
10756
  }
10749
- return UY;
10757
+ return GY;
10750
10758
  }
10751
10759
  function lookupTableInFile(_, VY, P) {
10752
10760
  if (P.length === 1) {
10753
10761
  let HY = _.usableMembers(VY).getFiltered(UNHANDLED);
10754
10762
  return HY ? HY.nonSchemaMembers.find((_) => _.isKind(SymbolKind.Table) && _.name === P[0]) : void 0;
10755
10763
  }
10756
- let [HY, UY] = [P[0], P[P.length - 1]], WY = _.usableMembers(VY).getFiltered(UNHANDLED);
10764
+ let HY = P[0], UY = P[P.length - 1], WY = _.usableMembers(VY).getFiltered(UNHANDLED);
10757
10765
  if (!WY) return;
10758
10766
  let GY = WY.schemaMembers.find((_) => _.name === HY);
10759
10767
  if (!GY) return;
@@ -13185,10 +13193,14 @@ function scanExistingUses(_, VY, P) {
13185
13193
  let _ = HY.importKind.value ?? void 0;
13186
13194
  _ && !VY.has(_.toLowerCase()) && (WY = _);
13187
13195
  }
13188
- WY && WY.toLowerCase() !== "from" && UY.push({
13189
- kind: _,
13190
- name: WY
13191
- });
13196
+ if (WY && WY.toLowerCase() !== "from") {
13197
+ let VY = HY.alias ? extractVariableFromExpression(HY.alias) : void 0;
13198
+ UY.push({
13199
+ kind: _,
13200
+ name: WY,
13201
+ alias: VY
13202
+ });
13203
+ }
13192
13204
  }
13193
13205
  } else _.specifiers instanceof WildcardNode && UY.push({ name: "*" });
13194
13206
  if (UY.length === 0 && !(_.specifiers instanceof WildcardNode)) continue;
@@ -13212,7 +13224,7 @@ function mergeSymbolIntoUses(_, VY, P, HY, UY, WY) {
13212
13224
  if (qY !== -1) {
13213
13225
  let _ = GY[qY];
13214
13226
  return _.specifiers.some((_) => _.name === VY) ? { topInsert: "" } : {
13215
- topInsert: buildUseStatement(uniqueInOrder([..._.specifiers.filter((_) => _.name !== "*").map((_) => `${_.kind ?? P} ${_.name}`), JY]), KY, YY),
13227
+ topInsert: buildUseStatement(uniqueInOrder([..._.specifiers.filter((_) => _.name !== "*").map((_) => `${_.kind ?? P} ${_.name}${_.alias ? ` as ${_.alias}` : ""}`), JY]), KY, YY),
13216
13228
  removeRange: expandToFullLines(WY, _.startOffset, _.endOffset)
13217
13229
  };
13218
13230
  }
@@ -14382,31 +14394,39 @@ function containerScopeKind(_, VY) {
14382
14394
  function canonicalName(_, VY) {
14383
14395
  let P = VY.originalSymbol;
14384
14396
  if (P.filepath.intern() === _.intern()) return Report.create(fullnameToCanonical(this, P));
14385
- let HY = this.parseFile(_).getValue().ast, UY = this.nodeSymbol(HY).getFiltered(UNHANDLED);
14386
- if (!UY) return Report.create(fullnameToCanonical(this, P));
14387
- let WY = this.symbolMembers(UY).getFiltered(UNHANDLED) ?? [], GY = [...WY];
14388
- for (let _ of WY) if (_ instanceof SchemaSymbol && _.isKind(SymbolKind.Schema)) {
14389
- let VY = this.symbolMembers(_).getFiltered(UNHANDLED);
14390
- VY && GY.push(...VY);
14391
- }
14392
- for (let VY of GY) if (VY.filepath.intern() === _.intern() && VY.originalSymbol === P && (VY instanceof UseSymbol || VY instanceof AliasSymbol)) {
14393
- let _ = VY.name;
14394
- if (!_) continue;
14395
- if (_ !== P.name) return Report.create({
14397
+ let HY = [...this.symbolUses(P).getValue(), ...this.symbolAliases(P).getValue()].filter((VY) => VY.filepath.equals(_));
14398
+ for (let _ of HY) {
14399
+ let VY = _.name;
14400
+ if (!VY) continue;
14401
+ if (VY !== P.name) return Report.create({
14396
14402
  schema: "",
14397
- name: _
14403
+ name: VY
14398
14404
  });
14399
- let HY = fullnameToCanonical(this, P);
14400
- return HY ? Report.create({
14401
- ...HY,
14402
- name: _
14405
+ let HY = getSchemaChain(this, _);
14406
+ if (HY.length > 0) return Report.create({
14407
+ schema: HY.join("."),
14408
+ name: VY
14409
+ });
14410
+ let UY = fullnameToCanonical(this, P);
14411
+ return UY ? Report.create({
14412
+ ...UY,
14413
+ name: VY
14403
14414
  }) : Report.create({
14404
14415
  schema: DEFAULT_SCHEMA_NAME$1,
14405
- name: _
14416
+ name: VY
14406
14417
  });
14407
14418
  }
14408
14419
  return Report.create(fullnameToCanonical(this, P));
14409
14420
  }
14421
+ function getSchemaChain(_, VY) {
14422
+ let P = [], HY = VY;
14423
+ for (; HY;) {
14424
+ let VY = _.symbolParent(HY).find((_) => _ instanceof SchemaSymbol && _.isKind(SymbolKind.Schema));
14425
+ if (!VY || VY.isPublicSchema()) break;
14426
+ P.unshift(VY.name ?? ""), HY = VY;
14427
+ }
14428
+ return P;
14429
+ }
14410
14430
  function fullnameToCanonical(_, VY) {
14411
14431
  if (!VY.declaration) return VY.name ? {
14412
14432
  schema: DEFAULT_SCHEMA_NAME$1,
@@ -15601,11 +15621,30 @@ function resolutionIndex() {
15601
15621
  };
15602
15622
  P(VY);
15603
15623
  }
15624
+ let GY = /* @__PURE__ */ new Map(), KY = /* @__PURE__ */ new Set();
15625
+ function qY(_, VY) {
15626
+ let P = VY.intern();
15627
+ if (KY.has(P)) return;
15628
+ KY.add(P);
15629
+ let HY = _.symbolMembers(VY).getFiltered(UNHANDLED);
15630
+ if (HY) for (let P of HY) {
15631
+ let HY = P.intern(), UY = GY.get(HY);
15632
+ UY || (UY = [], GY.set(HY, UY)), UY.push(VY), P instanceof SchemaSymbol && P.isKind(SymbolKind.Schema) && qY(_, P);
15633
+ }
15634
+ }
15635
+ for (let _ of P.values()) {
15636
+ let VY = _.getValue().ast, P = this.nodeSymbol(VY).getFiltered(UNHANDLED);
15637
+ P && qY(this, P);
15638
+ }
15604
15639
  return {
15605
15640
  references: _,
15606
- metadata: VY
15641
+ metadata: VY,
15642
+ parents: GY
15607
15643
  };
15608
15644
  }
15645
+ function symbolParent(_) {
15646
+ return this.resolutionIndex().parents.get(_.intern()) ?? [];
15647
+ }
15609
15648
  function symbolReferences(_) {
15610
15649
  return this.resolutionIndex().references.get(_.intern()) ?? [];
15611
15650
  }
@@ -15890,7 +15929,7 @@ function computeDeleteEdit(_, VY, P) {
15890
15929
  }
15891
15930
  var COMPUTING = Symbol("COMPUTING"), Compiler = class {
15892
15931
  constructor() {
15893
- 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$1.bind(this), this.syncDiagramView = syncDiagramView$1.bind(this), this.token = {
15932
+ 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$1.bind(this), this.syncDiagramView = syncDiagramView$1.bind(this), this.token = {
15894
15933
  invalidStream: this.localQuery(invalidStream),
15895
15934
  flatStream: this.localQuery(flatStream)
15896
15935
  }, this.parse = {
@@ -1825734,5 +1825773,5 @@ function findDiagramViewBlocks(_) {
1825734
1825773
  let VY = new Compiler();
1825735
1825774
  return VY.setSource(DEFAULT_ENTRY, _), VY.findDiagramViewBlocks(DEFAULT_ENTRY);
1825736
1825775
  }
1825737
- const VERSION = "8.0.0-alpha.4";
1825776
+ const VERSION = "8.0.0-alpha.6";
1825738
1825777
  export { CompilerError, ModelExporter_default as ModelExporter, Parser_default as Parser, VERSION, addDoubleQuoteIfNeeded, dbmlMonarchTokensProvider, export_default as exporter, findDiagramViewBlocks, formatRecordValue, import_default as importer, isBinaryType, isBooleanType, isDateTimeType, isFloatType, isIntegerType, isNumericType, isSerialType, isStringType, renameTable, syncDiagramView, tryExtractBoolean, tryExtractDateTime, tryExtractEnum, tryExtractInteger, tryExtractNumeric, tryExtractString };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dbml/core",
4
- "version": "8.0.0-alpha.4",
4
+ "version": "8.0.0-alpha.6",
5
5
  "description": "> TODO: description",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -46,7 +46,7 @@
46
46
  "lint:fix": "eslint --fix ."
47
47
  },
48
48
  "dependencies": {
49
- "@dbml/parse": "^8.0.0-alpha.4",
49
+ "@dbml/parse": "^8.0.0-alpha.6",
50
50
  "antlr4": "^4.13.1",
51
51
  "lodash": "^4.18.1",
52
52
  "lodash-es": "^4.18.1",
@@ -57,7 +57,7 @@
57
57
  "devDependencies": {
58
58
  "bluebird": "^3.5.5"
59
59
  },
60
- "gitHead": "17d4675433b702912a20dcc65a63c03c73c56db5",
60
+ "gitHead": "52721b96504df2eeb4ff7fc13292896221a837ef",
61
61
  "engines": {
62
62
  "node": ">=16"
63
63
  }