@dbml/parse 8.0.0-alpha.5 → 8.0.0-alpha.7
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.
package/dist/dbml-parse.mjs
CHANGED
|
@@ -8201,9 +8201,9 @@ const useUtils = { visibleName(r, M) {
|
|
|
8201
8201
|
nodeSymbol(N, P) {
|
|
8202
8202
|
if (!isUseSpecifier(P) || !P.name) return Report.create(PASS_THROUGH);
|
|
8203
8203
|
let F = P.getSymbolKind();
|
|
8204
|
-
if (F === void 0) return Report.create(PASS_THROUGH);
|
|
8204
|
+
if (F === void 0 || F === SymbolKind.Schema) return Report.create(PASS_THROUGH);
|
|
8205
8205
|
let I = N.nodeReferee(P.name).getFiltered(UNHANDLED);
|
|
8206
|
-
return I && !I.canBeImported
|
|
8206
|
+
return I && !I.canBeImported ? Report.create(PASS_THROUGH) : Report.create(N.symbolFactory.create(UseSymbol, {
|
|
8207
8207
|
useSpecifierDeclaration: P,
|
|
8208
8208
|
declaration: I?.declaration,
|
|
8209
8209
|
usedSymbol: I,
|
|
@@ -9446,12 +9446,14 @@ const schemaModule = { symbolMembers(N, P) {
|
|
|
9446
9446
|
for (let j of r) B.push(...expandTableGroup(N, P, j));
|
|
9447
9447
|
}
|
|
9448
9448
|
let V = /* @__PURE__ */ new Set(), H = B.filter((r) => {
|
|
9449
|
+
if (r instanceof UseSymbol && r.isKind(SymbolKind.Schema)) return !1;
|
|
9449
9450
|
let j = `${r.originalSymbol.intern()}:${r.name ?? ""}`;
|
|
9450
9451
|
return V.has(j) ? !1 : (V.add(j), !0);
|
|
9451
9452
|
}), U = /* @__PURE__ */ new Map();
|
|
9452
9453
|
for (let r of H) {
|
|
9453
9454
|
let j = `${r.kind}:${r.name}`;
|
|
9454
9455
|
if (U.get(j)) {
|
|
9456
|
+
if (r.isKind(SymbolKind.Schema)) continue;
|
|
9455
9457
|
let j = r instanceof UseSymbol ? r.useSpecifierDeclaration ?? r.declaration : r.declaration instanceof ElementDeclarationNode && r.declaration.name ? r.declaration.name : r.declaration;
|
|
9456
9458
|
j && r.name !== void 0 && z.push(getDuplicateSchemaMemberError(r.kind, r.name, F.join("."), j));
|
|
9457
9459
|
} else U.set(j, r);
|
|
@@ -9483,7 +9485,7 @@ function handleMemberSelectiveUses(r, N, P, F) {
|
|
|
9483
9485
|
function mergeImportedSchema(r, M, N, P = /* @__PURE__ */ new Set()) {
|
|
9484
9486
|
if (N.getSymbolKind() !== SymbolKind.Schema || !N.name) return [];
|
|
9485
9487
|
let F = r.nodeReferee(N.name).getFiltered(UNHANDLED);
|
|
9486
|
-
if (!F || !F.isKind(SymbolKind.Schema) ||
|
|
9488
|
+
if (!F || !F.isKind(SymbolKind.Schema) || (r.nodeAlias(N).getFiltered(UNHANDLED) ?? r.nodeFullname(N).getFiltered(UNHANDLED)?.at(0)) !== M.name) return [];
|
|
9487
9489
|
let I = F.intern();
|
|
9488
9490
|
if (P.has(I)) return [];
|
|
9489
9491
|
P.add(I);
|
|
@@ -12025,10 +12027,14 @@ function scanExistingUses(r, j, M) {
|
|
|
12025
12027
|
let r = N.importKind.value ?? void 0;
|
|
12026
12028
|
r && !j.has(r.toLowerCase()) && (F = r);
|
|
12027
12029
|
}
|
|
12028
|
-
F && F.toLowerCase() !== "from"
|
|
12029
|
-
|
|
12030
|
-
|
|
12031
|
-
|
|
12030
|
+
if (F && F.toLowerCase() !== "from") {
|
|
12031
|
+
let j = N.alias ? extractVariableFromExpression(N.alias) : void 0;
|
|
12032
|
+
P.push({
|
|
12033
|
+
kind: r,
|
|
12034
|
+
name: F,
|
|
12035
|
+
alias: j
|
|
12036
|
+
});
|
|
12037
|
+
}
|
|
12032
12038
|
}
|
|
12033
12039
|
} else r.specifiers instanceof WildcardNode && P.push({ name: "*" });
|
|
12034
12040
|
if (P.length === 0 && !(r.specifiers instanceof WildcardNode)) continue;
|
|
@@ -12052,7 +12058,7 @@ function mergeSymbolIntoUses(r, j, M, N, P, F) {
|
|
|
12052
12058
|
if (R !== -1) {
|
|
12053
12059
|
let r = I[R];
|
|
12054
12060
|
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),
|
|
12061
|
+
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
12062
|
removeRange: expandToFullLines(F, r.startOffset, r.endOffset)
|
|
12057
12063
|
};
|
|
12058
12064
|
}
|
|
@@ -13286,33 +13292,41 @@ function containerScopeKind(r, j) {
|
|
|
13286
13292
|
default: return ScopeKind.CUSTOM;
|
|
13287
13293
|
}
|
|
13288
13294
|
}
|
|
13289
|
-
function canonicalName(r,
|
|
13290
|
-
let
|
|
13291
|
-
if (
|
|
13292
|
-
let
|
|
13293
|
-
|
|
13294
|
-
|
|
13295
|
-
|
|
13296
|
-
|
|
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({
|
|
13295
|
+
function canonicalName(r, j) {
|
|
13296
|
+
let N = j.originalSymbol;
|
|
13297
|
+
if (N.filepath.intern() === r.intern()) return Report.create(fullnameToCanonical(this, N));
|
|
13298
|
+
let P = [...this.symbolUses(N).getValue(), ...this.symbolAliases(N).getValue()].filter((j) => j.filepath.equals(r));
|
|
13299
|
+
for (let r of P) {
|
|
13300
|
+
let j = r.name;
|
|
13301
|
+
if (!j) continue;
|
|
13302
|
+
if (j !== N.name) return Report.create({
|
|
13303
13303
|
schema: "",
|
|
13304
|
-
name:
|
|
13304
|
+
name: j
|
|
13305
|
+
});
|
|
13306
|
+
let P = getSchemaChain(this, r);
|
|
13307
|
+
if (P.length > 0) return Report.create({
|
|
13308
|
+
schema: P.join("."),
|
|
13309
|
+
name: j
|
|
13305
13310
|
});
|
|
13306
|
-
let
|
|
13307
|
-
return
|
|
13308
|
-
...
|
|
13309
|
-
name:
|
|
13311
|
+
let F = fullnameToCanonical(this, N);
|
|
13312
|
+
return F ? Report.create({
|
|
13313
|
+
...F,
|
|
13314
|
+
name: j
|
|
13310
13315
|
}) : Report.create({
|
|
13311
13316
|
schema: DEFAULT_SCHEMA_NAME,
|
|
13312
|
-
name:
|
|
13317
|
+
name: j
|
|
13313
13318
|
});
|
|
13314
13319
|
}
|
|
13315
|
-
return Report.create(fullnameToCanonical(this,
|
|
13320
|
+
return Report.create(fullnameToCanonical(this, N));
|
|
13321
|
+
}
|
|
13322
|
+
function getSchemaChain(r, j) {
|
|
13323
|
+
let M = [], N = j;
|
|
13324
|
+
for (; N;) {
|
|
13325
|
+
let j = r.symbolParent(N).find((r) => r instanceof SchemaSymbol && r.isKind(SymbolKind.Schema));
|
|
13326
|
+
if (!j || j.isPublicSchema()) break;
|
|
13327
|
+
M.unshift(j.name ?? ""), N = j;
|
|
13328
|
+
}
|
|
13329
|
+
return M;
|
|
13316
13330
|
}
|
|
13317
13331
|
function fullnameToCanonical(r, M) {
|
|
13318
13332
|
if (!M.declaration) return M.name ? {
|
|
@@ -14510,11 +14524,30 @@ function resolutionIndex() {
|
|
|
14510
14524
|
};
|
|
14511
14525
|
N(M);
|
|
14512
14526
|
}
|
|
14527
|
+
let L = /* @__PURE__ */ new Map(), R = /* @__PURE__ */ new Set();
|
|
14528
|
+
function z(r, M) {
|
|
14529
|
+
let N = M.intern();
|
|
14530
|
+
if (R.has(N)) return;
|
|
14531
|
+
R.add(N);
|
|
14532
|
+
let P = r.symbolMembers(M).getFiltered(UNHANDLED);
|
|
14533
|
+
if (P) for (let j of P) {
|
|
14534
|
+
let N = j.intern(), P = L.get(N);
|
|
14535
|
+
P || (P = [], L.set(N, P)), P.push(M), j instanceof SchemaSymbol && j.isKind(SymbolKind.Schema) && z(r, j);
|
|
14536
|
+
}
|
|
14537
|
+
}
|
|
14538
|
+
for (let r of N.values()) {
|
|
14539
|
+
let M = r.getValue().ast, N = this.nodeSymbol(M).getFiltered(UNHANDLED);
|
|
14540
|
+
N && z(this, N);
|
|
14541
|
+
}
|
|
14513
14542
|
return {
|
|
14514
14543
|
references: r,
|
|
14515
|
-
metadata: M
|
|
14544
|
+
metadata: M,
|
|
14545
|
+
parents: L
|
|
14516
14546
|
};
|
|
14517
14547
|
}
|
|
14548
|
+
function symbolParent(r) {
|
|
14549
|
+
return this.resolutionIndex().parents.get(r.intern()) ?? [];
|
|
14550
|
+
}
|
|
14518
14551
|
function symbolReferences(r) {
|
|
14519
14552
|
return this.resolutionIndex().references.get(r.intern()) ?? [];
|
|
14520
14553
|
}
|
|
@@ -14799,7 +14832,7 @@ function computeDeleteEdit(r, j, M) {
|
|
|
14799
14832
|
}
|
|
14800
14833
|
var COMPUTING = Symbol("COMPUTING"), Compiler = class {
|
|
14801
14834
|
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 = {
|
|
14835
|
+
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
14836
|
invalidStream: this.localQuery(invalidStream),
|
|
14804
14837
|
flatStream: this.localQuery(flatStream)
|
|
14805
14838
|
}, 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[];
|
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
|
+
"version": "8.0.0-alpha.7",
|
|
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": "
|
|
48
|
+
"gitHead": "4c4389c0126b09613bc4daec1c4b938dddb3c434"
|
|
49
49
|
}
|