@dbml/parse 10.3.0-alpha.0 → 10.3.1
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
|
@@ -1425,6 +1425,7 @@ var ho = function(e) {
|
|
|
1425
1425
|
return t && r.endsWith(t) ? r.slice(0, -t.length) : r;
|
|
1426
1426
|
}, bo = /^[a-zA-Z]:\//, xo = class e {
|
|
1427
1427
|
constructor(e, t = {}) {
|
|
1428
|
+
e = e.split("/").map(So).join("/");
|
|
1428
1429
|
let n = lo(e);
|
|
1429
1430
|
if (!ho(n)) throw Error(`FilePath requires an absolute path, got: "${e}"`);
|
|
1430
1431
|
this.path = n, this.protocol = t.protocol;
|
|
@@ -1449,14 +1450,17 @@ var ho = function(e) {
|
|
|
1449
1450
|
get absolute() {
|
|
1450
1451
|
return this.path;
|
|
1451
1452
|
}
|
|
1453
|
+
get fsPath() {
|
|
1454
|
+
return this.path.split("/").map(decodeURIComponent).join("/");
|
|
1455
|
+
}
|
|
1452
1456
|
get dirname() {
|
|
1453
|
-
return vo(this.
|
|
1457
|
+
return vo(this.fsPath);
|
|
1454
1458
|
}
|
|
1455
1459
|
get basename() {
|
|
1456
|
-
return yo(this.
|
|
1460
|
+
return yo(this.fsPath);
|
|
1457
1461
|
}
|
|
1458
1462
|
get extname() {
|
|
1459
|
-
return go(this.
|
|
1463
|
+
return go(this.fsPath);
|
|
1460
1464
|
}
|
|
1461
1465
|
resolve(t) {
|
|
1462
1466
|
return new e(po(this.dirname, t));
|
|
@@ -1465,14 +1469,14 @@ var ho = function(e) {
|
|
|
1465
1469
|
return new e(uo(this.path, ...t));
|
|
1466
1470
|
}
|
|
1467
1471
|
relativeTo(e) {
|
|
1468
|
-
let t = _o(e, this.
|
|
1472
|
+
let t = _o(e, this.fsPath);
|
|
1469
1473
|
return !t.startsWith("./") && !t.startsWith("../") && ![".", ".."].includes(t) ? `./${t}` : t;
|
|
1470
1474
|
}
|
|
1471
|
-
|
|
1475
|
+
toKey() {
|
|
1472
1476
|
return this.path;
|
|
1473
1477
|
}
|
|
1474
1478
|
equals(e) {
|
|
1475
|
-
return this.
|
|
1479
|
+
return this.toKey() === e.toKey();
|
|
1476
1480
|
}
|
|
1477
1481
|
isParentOf(e) {
|
|
1478
1482
|
if (this.path === e.path) return !1;
|
|
@@ -1489,10 +1493,12 @@ var ho = function(e) {
|
|
|
1489
1493
|
return !ho(lo(e));
|
|
1490
1494
|
}
|
|
1491
1495
|
};
|
|
1492
|
-
function So(e
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
+
function So(e) {
|
|
1497
|
+
try {
|
|
1498
|
+
return encodeURIComponent(decodeURIComponent(e));
|
|
1499
|
+
} catch {
|
|
1500
|
+
return encodeURIComponent(e);
|
|
1501
|
+
}
|
|
1496
1502
|
}
|
|
1497
1503
|
//#endregion
|
|
1498
1504
|
//#region src/constants.ts
|
|
@@ -9593,9 +9599,9 @@ var o_ = { visibleName(e, n) {
|
|
|
9593
9599
|
if (c === void 0) return n.create(void 0);
|
|
9594
9600
|
let l = i.parentOfKind(fm);
|
|
9595
9601
|
if (l?.importPath?.value === void 0) return n.create(void 0);
|
|
9596
|
-
let u =
|
|
9602
|
+
let u = r.layout.resolveFileSpecifier(i.filepath, l.importPath.value);
|
|
9597
9603
|
if (!u) return n.create(void 0, [new T(w.BINDING_ERROR, `Import path must be relative, got '${l.importPath.value}'`, i)]);
|
|
9598
|
-
if (!r.layout.exists(u)) return n.create(void 0, [new T(w.NONEXISTENT_MODULE, `${o} '${s?.join(".") ?? c}' does not exist in file ${u.
|
|
9604
|
+
if (!r.layout.exists(u)) return n.create(void 0, [new T(w.NONEXISTENT_MODULE, `${o} '${s?.join(".") ?? c}' does not exist in file ${u.toKey()}. Does the file exist?`, i)]);
|
|
9599
9605
|
let d = i.parentOfKind(gm)?.leftExpression;
|
|
9600
9606
|
if (d && d !== i) {
|
|
9601
9607
|
let e = r.nodeReferee(d).getFiltered(t);
|
|
@@ -9604,14 +9610,14 @@ var o_ = { visibleName(e, n) {
|
|
|
9604
9610
|
return a ? n.create(a) : new n(void 0, [new T(w.BINDING_ERROR, `Could not find ${o} '${c}'`, i)]);
|
|
9605
9611
|
}
|
|
9606
9612
|
let f = c_(r, u, c, o);
|
|
9607
|
-
return f ? n.create(f) : n.create(void 0, [new T(w.BINDING_ERROR, `${o} '${c}' does not exist in file ${u.
|
|
9613
|
+
return f ? n.create(f) : n.create(void 0, [new T(w.BINDING_ERROR, `${o} '${c}' does not exist in file ${u.toKey()}`, i)]);
|
|
9608
9614
|
},
|
|
9609
9615
|
bindNode(t, r) {
|
|
9610
9616
|
if (Kf(r)) {
|
|
9611
9617
|
let e = [];
|
|
9612
9618
|
if (r.importPath?.value) {
|
|
9613
|
-
let n =
|
|
9614
|
-
n
|
|
9619
|
+
let n = t.layout.resolveFileSpecifier(r.filepath, r.importPath.value);
|
|
9620
|
+
(!n || !t.layout.exists(n)) && e.push(new T(w.NONEXISTENT_MODULE, `Failed to resolve the non-existent file '${r.importPath.value}'`, r.importPath));
|
|
9615
9621
|
}
|
|
9616
9622
|
if (r.specifiers) {
|
|
9617
9623
|
let n = t.bindNode(r.specifiers);
|
|
@@ -9647,7 +9653,7 @@ function c_(e, n, r, i, a = /* @__PURE__ */ new Set()) {
|
|
|
9647
9653
|
for (let t of o.reuses.selective) if (M(t.alias ?? t.name)?.at(-1) === r) {
|
|
9648
9654
|
let o = t.parentOfKind(fm);
|
|
9649
9655
|
if (o?.importPath?.value) {
|
|
9650
|
-
let s = c_(e,
|
|
9656
|
+
let s = c_(e, e.layout.resolveFileSpecifier(n, o.importPath.value), M(t.name)?.at(-1) ?? r, i, a);
|
|
9651
9657
|
if (s) return s;
|
|
9652
9658
|
}
|
|
9653
9659
|
}
|
|
@@ -9688,16 +9694,16 @@ function u_(e, n, r) {
|
|
|
9688
9694
|
}
|
|
9689
9695
|
function d_(e, t) {
|
|
9690
9696
|
let n = e.parseFile(t), { ast: r } = n.getValue(), i = [], a = [], o = [], s = [];
|
|
9691
|
-
for (let
|
|
9692
|
-
if (!(
|
|
9693
|
-
let
|
|
9694
|
-
|
|
9695
|
-
importPath:
|
|
9696
|
-
node:
|
|
9697
|
-
}) : a.push(...
|
|
9698
|
-
importPath:
|
|
9699
|
-
node:
|
|
9700
|
-
}) : s.push(...
|
|
9697
|
+
for (let n of r.body) {
|
|
9698
|
+
if (!(n instanceof fm) || !n.specifiers || !n.importPath) continue;
|
|
9699
|
+
let r = e.layout.resolveFileSpecifier(t, n.importPath.value);
|
|
9700
|
+
r && (n.isReuse ? n.specifiers instanceof wm ? i.push({
|
|
9701
|
+
importPath: r,
|
|
9702
|
+
node: n.specifiers
|
|
9703
|
+
}) : a.push(...n.specifiers.specifiers) : n.specifiers instanceof wm ? o.push({
|
|
9704
|
+
importPath: r,
|
|
9705
|
+
node: n.specifiers
|
|
9706
|
+
}) : s.push(...n.specifiers.specifiers));
|
|
9701
9707
|
}
|
|
9702
9708
|
return {
|
|
9703
9709
|
ast: r,
|
|
@@ -12873,7 +12879,7 @@ var gy = {
|
|
|
12873
12879
|
}
|
|
12874
12880
|
validateBody() {
|
|
12875
12881
|
let e = [];
|
|
12876
|
-
if (this.declarationNode.
|
|
12882
|
+
if (this.declarationNode.specifiers instanceof wm) return [];
|
|
12877
12883
|
for (let t of this.declarationNode.specifiers?.specifiers || []) e.push(...this.validateSpecifier(t));
|
|
12878
12884
|
return e;
|
|
12879
12885
|
}
|
|
@@ -14128,7 +14134,7 @@ function ex() {
|
|
|
14128
14134
|
}
|
|
14129
14135
|
function tx(e, n, r, i) {
|
|
14130
14136
|
if (!r) return X();
|
|
14131
|
-
let a =
|
|
14137
|
+
let a = e.layout.resolveFileSpecifier(n, r.value);
|
|
14132
14138
|
if (!a) return X();
|
|
14133
14139
|
let o = e.usableMembers(a).getFiltered(t);
|
|
14134
14140
|
if (!o) return X();
|
|
@@ -15243,7 +15249,7 @@ function vS(e) {
|
|
|
15243
15249
|
let { ast: t } = this.parseFile(e).getValue(), n = [], r = /* @__PURE__ */ new Set();
|
|
15244
15250
|
for (let i of t.body) {
|
|
15245
15251
|
if (!(i instanceof fm) || !i.importPath) continue;
|
|
15246
|
-
let t =
|
|
15252
|
+
let t = this.layout.resolveFileSpecifier(e, i.importPath.value);
|
|
15247
15253
|
!t || r.has(t.absolute) || (r.add(t.absolute), n.push(t));
|
|
15248
15254
|
}
|
|
15249
15255
|
return n;
|
|
@@ -17143,6 +17149,11 @@ var nw = Symbol("COMPUTING"), rw = class {
|
|
|
17143
17149
|
constructor(e = {}) {
|
|
17144
17150
|
this.files = e instanceof Map ? new Map(e) : new Map(Object.entries(e));
|
|
17145
17151
|
}
|
|
17152
|
+
resolveFileSpecifier(e, t) {
|
|
17153
|
+
if (!xo.isRelative(t)) return;
|
|
17154
|
+
let n = xo.resolve(e.dirname, t);
|
|
17155
|
+
return n.absolute.endsWith(".dbml") ? n : xo.from(n.absolute + ".dbml");
|
|
17156
|
+
}
|
|
17146
17157
|
setSource(e, t) {
|
|
17147
17158
|
this.files.set(e.absolute, t);
|
|
17148
17159
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Filepath } from '../../core/types/filepath';
|
|
2
2
|
export interface DbmlProjectLayout {
|
|
3
|
+
resolveFileSpecifier(currentFilepath: Filepath, specifier: string): Filepath | undefined;
|
|
3
4
|
getSource(filePath: Filepath): string | undefined;
|
|
4
5
|
exists(filePath: Filepath): boolean;
|
|
5
6
|
isFile(filePath: Filepath): boolean;
|
|
@@ -10,6 +11,7 @@ export interface DbmlProjectLayout {
|
|
|
10
11
|
export declare class MemoryProjectLayout implements DbmlProjectLayout {
|
|
11
12
|
private readonly files;
|
|
12
13
|
constructor(files?: Map<string, string> | Record<string, string>);
|
|
14
|
+
resolveFileSpecifier(currentFilepath: Filepath, relativePath: string): Filepath | undefined;
|
|
13
15
|
setSource(filePath: Filepath, content: string): void;
|
|
14
16
|
getSource(filePath: Filepath): string | undefined;
|
|
15
17
|
deleteSource(filePath: Filepath): void;
|
|
@@ -14,13 +14,14 @@ export declare class Filepath implements Internable<FilepathId> {
|
|
|
14
14
|
static resolve(fromDir: string, relativePath: string): Filepath;
|
|
15
15
|
static fromUri(uri: string): Filepath;
|
|
16
16
|
get absolute(): string;
|
|
17
|
+
get fsPath(): string;
|
|
17
18
|
get dirname(): string;
|
|
18
19
|
get basename(): string;
|
|
19
20
|
get extname(): string;
|
|
20
21
|
resolve(relativePath: string): Filepath;
|
|
21
22
|
join(...segments: string[]): Filepath;
|
|
22
23
|
relativeTo(baseDir: string): string;
|
|
23
|
-
|
|
24
|
+
toKey(): string;
|
|
24
25
|
equals(other: Filepath): boolean;
|
|
25
26
|
isParentOf(other: Filepath): boolean;
|
|
26
27
|
toUri(options?: {
|
|
@@ -28,5 +29,4 @@ export declare class Filepath implements Internable<FilepathId> {
|
|
|
28
29
|
}): string;
|
|
29
30
|
static isRelative(p: string): boolean;
|
|
30
31
|
}
|
|
31
|
-
export declare function resolveImportFilepath(currentFilepath: Filepath, relativePath: string): Filepath | undefined;
|
|
32
32
|
export {};
|
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": "10.3.
|
|
4
|
+
"version": "10.3.1",
|
|
5
5
|
"description": "DBML parser v2",
|
|
6
6
|
"author": "Holistics <dev@holistics.io>",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">=18"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "34108bb9346df5f22d5224549c106ff47ca931c8"
|
|
55
55
|
}
|