@dbml/cli 10.4.0-alpha.1 → 10.4.0-alpha.3
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/__tests__/db2dbml/mssql/dbml-error.log +44 -0
- package/__tests__/db2dbml/mysql/dbml-error.log +12 -0
- package/__tests__/db2dbml/oracle/dbml-error.log +42 -0
- package/__tests__/db2dbml/postgres/dbml-error.log +21 -0
- package/__tests__/dbml2sql/filename --mysql --out-file/out-files/schema.sql +1 -1
- package/__tests__/dbml2sql/filename --oracle --out-file/out-files/schema.sql +3 -3
- package/__tests__/dbml2sql/filename --out-file/out-files/schema.sql +1 -1
- package/__tests__/dbml2sql/filename --postgres --out-file/out-files/schema.sql +1 -1
- package/__tests__/dbml2sql/filenames --mysql --out-file/out-files/schema.sql +1 -1
- package/__tests__/dbml2sql/filenames --oracle --out-file/out-files/schema.sql +1 -1
- package/__tests__/dbml2sql/filenames --out-file/out-files/schema.sql +1 -1
- package/__tests__/dbml2sql/filenames --postgres --out-file/out-files/schema.sql +1 -1
- package/__tests__/dbml2sql/multifile --postgres stdout/in-files/main.dbml +2 -0
- package/__tests__/dbml2sql/multifile --postgres stdout/in-files/sub/orders.dbml +6 -0
- package/__tests__/dbml2sql/multifile --postgres stdout/in-files/types.dbml +4 -0
- package/__tests__/dbml2sql/multifile --postgres stdout/options.json +6 -0
- package/__tests__/dbml2sql/multifile --postgres stdout/stdout.txt +12 -0
- package/__tests__/dbml2sql/multifile error entry-syntax-error/dbml-error.log +20 -0
- package/__tests__/dbml2sql/multifile error entry-syntax-error/stdout.txt +1 -1
- package/__tests__/dbml2sql/multifile error import-not-found/dbml-error.log +1784 -0
- package/__tests__/dbml2sql/multifile error imported-syntax-error/dbml-error.log +20 -0
- package/__tests__/dbml2sql/multifile error imported-syntax-error/stdout.txt +1 -1
- package/__tests__/dbml2sql/multifile error transitive-use-not-visible/dbml-error.log +16 -0
- package/__tests__/dbml2sql/multiple_schema_mssql/out-files/multiple_schema.out.sql +9 -9
- package/__tests__/dbml2sql/multiple_schema_mysql/out-files/multiple_schema.out.sql +1 -1
- package/__tests__/dbml2sql/multiple_schema_oracle/out-files/multiple_schema.out.sql +1 -1
- package/__tests__/dbml2sql/multiple_schema_pg/out-files/multiple_schema.out.sql +1 -1
- package/__tests__/dbml2sql/syntax-error/dbml-error.log +20 -0
- package/__tests__/dbml2sql/syntax-error/stdout.txt +1 -1
- package/__tests__/sql2dbml/custom-error-alter-table-column-not-found --oracle/dbml-error.log +16 -0
- package/__tests__/sql2dbml/custom-error-alter-table-column-not-found --oracle/stdout.txt +1 -1
- package/__tests__/sql2dbml/custom-error-alter-table-table-not-found --oracle/dbml-error.log +16 -0
- package/__tests__/sql2dbml/custom-error-column-comment-column-not-found --oracle/dbml-error.log +16 -0
- package/__tests__/sql2dbml/custom-error-column-comment-table-not-found --oracle/dbml-error.log +16 -0
- package/__tests__/sql2dbml/custom-error-create-index-table-not-found --oracle/dbml-error.log +16 -0
- package/__tests__/sql2dbml/custom-error-table-comment-table-not-found --oracle/dbml-error.log +16 -0
- package/__tests__/sql2dbml/filename --mysql --out-file/out-files/schema.dbml +6 -6
- package/__tests__/sql2dbml/filename --oracle --out-file/out-files/schema.dbml +12 -12
- package/__tests__/sql2dbml/filename --out-file/out-files/schema.dbml +6 -6
- package/__tests__/sql2dbml/filename --postgres --out-file/out-files/schema.dbml +6 -6
- package/__tests__/sql2dbml/filenames --mysql --out-file/out-files/schema.dbml +15 -15
- package/__tests__/sql2dbml/filenames --out-file/out-files/schema.dbml +15 -15
- package/__tests__/sql2dbml/filenames --postgres --out-file/out-files/schema.dbml +15 -15
- package/__tests__/sql2dbml/multiple_schema_mssql/out-files/multiple_schema.out.dbml +9 -9
- package/__tests__/sql2dbml/multiple_schema_mysql/out-files/multiple_schema.out.dbml +8 -8
- package/__tests__/sql2dbml/multiple_schema_pg/out-files/multiple_schema.out.dbml +7 -7
- package/__tests__/sql2dbml/syntax-error/dbml-error.log +16 -0
- package/__tests__/sql2dbml/syntax-error-duplicate-endpoints --mssql/dbml-error.log +16 -0
- package/__tests__/sql2dbml/syntax-error-duplicate-endpoints --mssql/stdout.txt +1 -1
- package/__tests__/sql2dbml/syntax-error-duplicate-endpoints --mysql/dbml-error.log +16 -0
- package/__tests__/sql2dbml/syntax-error-duplicate-endpoints --mysql/stdout.txt +1 -1
- package/__tests__/windows/multifile-backslash/in-files/main.dbml +2 -0
- package/__tests__/windows/multifile-backslash/in-files/sub/orders.dbml +6 -0
- package/__tests__/windows/multifile-backslash/in-files/types.dbml +4 -0
- package/__tests__/windows/multifile-backslash/options.json +6 -0
- package/__tests__/windows/multifile-backslash/stdout.txt +12 -0
- package/__tests__/windows/multifile-relative/in-files/main.dbml +2 -0
- package/__tests__/windows/multifile-relative/in-files/sub/orders.dbml +6 -0
- package/__tests__/windows/multifile-relative/in-files/types.dbml +4 -0
- package/__tests__/windows/multifile-relative/options.json +6 -0
- package/__tests__/windows/multifile-relative/stdout.txt +12 -0
- package/__tests__/windows.test.ts +34 -0
- package/lib/index.js +14 -9
- package/package.json +6 -6
- package/src/NodeProjectLayout.ts +9 -1
- package/src/cli/import.ts +4 -5
- package/src/cli/utils.ts +4 -3
|
@@ -70,21 +70,21 @@ Table "orders4" {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
Ref "FK_1":"schemaA"."locations"."id"
|
|
73
|
+
Ref "FK_1":"schemaA"."locations"."id" ?<? "schemaA"."products"."lid" [delete: cascade]
|
|
74
74
|
|
|
75
|
-
Ref:"schemaA"."products"."id"
|
|
75
|
+
Ref:"schemaA"."products"."id" ?<? "orders"."pid"
|
|
76
76
|
|
|
77
|
-
Ref:"schemaA"."products"."id"
|
|
77
|
+
Ref:"schemaA"."products"."id" ?<? "orders2"."pid"
|
|
78
78
|
|
|
79
|
-
Ref "CFK_1":"orders".("id1", "id2")
|
|
79
|
+
Ref "CFK_1":"orders".("id1", "id2") ?<? "orders2".("id1", "id2") [update: set null, delete: cascade]
|
|
80
80
|
|
|
81
|
-
Ref:"users"."id"
|
|
81
|
+
Ref:"users"."id" <? "ecommerce"."users"."id"
|
|
82
82
|
|
|
83
|
-
Ref "name_optional":"users"."name"
|
|
83
|
+
Ref "name_optional":"users"."name" <? "ecommerce"."users"."id"
|
|
84
84
|
|
|
85
|
-
Ref:"ecommerce"."users"."id"
|
|
85
|
+
Ref:"ecommerce"."users"."id" ?<? "schemaA"."products"."name"
|
|
86
86
|
|
|
87
|
-
Ref:"users"."id"
|
|
87
|
+
Ref:"users"."id" ?<? "schemaA"."locations"."name"
|
|
88
88
|
|
|
89
89
|
Enum "ecommerce"."users_ejs_enum" {
|
|
90
90
|
"created2"
|
|
@@ -56,19 +56,19 @@ Table "br_flight" {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
Ref "fk_1":"schemaA"."locations"."id"
|
|
59
|
+
Ref "fk_1":"schemaA"."locations"."id" ?<? "schemaA"."products"."lid"
|
|
60
60
|
|
|
61
|
-
Ref:"users"."id"
|
|
61
|
+
Ref:"users"."id" <? "ecommerce"."users"."id"
|
|
62
62
|
|
|
63
|
-
Ref "name_optional":"users"."name"
|
|
63
|
+
Ref "name_optional":"users"."name" <? "ecommerce"."users"."id"
|
|
64
64
|
|
|
65
|
-
Ref:"ecommerce"."users"."id"
|
|
65
|
+
Ref:"ecommerce"."users"."id" ?<? "schemaA"."products"."name"
|
|
66
66
|
|
|
67
|
-
Ref:"users"."id"
|
|
67
|
+
Ref:"users"."id" ?<? "schemaA"."locations"."name"
|
|
68
68
|
|
|
69
|
-
Ref "fk_composite":"booking_reference".("reference_id", "cust_id")
|
|
69
|
+
Ref "fk_composite":"booking_reference".("reference_id", "cust_id") <? "br_flight".("reference_id", "cust_id")
|
|
70
70
|
|
|
71
|
-
Ref "fk_country_code":"countries"."code"
|
|
71
|
+
Ref "fk_country_code":"countries"."code" ?<? "users"."country_code"
|
|
72
72
|
|
|
73
73
|
Enum "schemaB"."gender" {
|
|
74
74
|
"male"
|
|
@@ -18,3 +18,19 @@
|
|
|
18
18
|
|
|
19
19
|
You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
|
|
20
20
|
|
|
21
|
+
2026-10-19T04:22:24.215Z
|
|
22
|
+
|
|
23
|
+
You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
|
|
24
|
+
|
|
25
|
+
2026-10-19T04:25:33.331Z
|
|
26
|
+
|
|
27
|
+
You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
|
|
28
|
+
|
|
29
|
+
2026-10-19T08:38:05.172Z
|
|
30
|
+
|
|
31
|
+
You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
|
|
32
|
+
|
|
33
|
+
2026-10-20T03:59:42.784Z
|
|
34
|
+
|
|
35
|
+
You have a syntax error at "business.sql" line 6 column 2. no viable alternative at input 'CREATE TABLE `staff` (\n `id` int PRIMARY KEY,\n `first_name` varchar(255),\n `last_name` varchar(255),\n `address_id` int\n `picture`'
|
|
36
|
+
|
|
@@ -18,3 +18,19 @@
|
|
|
18
18
|
|
|
19
19
|
You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
20
20
|
|
|
21
|
+
2026-10-19T04:22:24.950Z
|
|
22
|
+
|
|
23
|
+
You have a syntax error at "schema.sql". Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
24
|
+
|
|
25
|
+
2026-10-19T04:25:34.066Z
|
|
26
|
+
|
|
27
|
+
You have a syntax error at "schema.sql". Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
28
|
+
|
|
29
|
+
2026-10-19T08:38:05.917Z
|
|
30
|
+
|
|
31
|
+
You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
32
|
+
|
|
33
|
+
2026-10-20T03:59:43.596Z
|
|
34
|
+
|
|
35
|
+
You have a syntax error at "schema.sql". Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
36
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
ERROR:
|
|
2
|
-
You have a syntax error at "schema.sql"
|
|
2
|
+
You have a syntax error at "schema.sql". Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
3
3
|
|
|
4
4
|
A complete log can be found in:
|
|
@@ -18,3 +18,19 @@
|
|
|
18
18
|
|
|
19
19
|
You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
20
20
|
|
|
21
|
+
2026-10-19T04:22:25.649Z
|
|
22
|
+
|
|
23
|
+
You have a syntax error at "schema.sql". Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
24
|
+
|
|
25
|
+
2026-10-19T04:25:34.792Z
|
|
26
|
+
|
|
27
|
+
You have a syntax error at "schema.sql". Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
28
|
+
|
|
29
|
+
2026-10-19T08:38:06.607Z
|
|
30
|
+
|
|
31
|
+
You have a syntax error at "schema.sql" line 1 column 1. Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
32
|
+
|
|
33
|
+
2026-10-20T03:59:44.342Z
|
|
34
|
+
|
|
35
|
+
You have a syntax error at "schema.sql". Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
36
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
ERROR:
|
|
2
|
-
You have a syntax error at "schema.sql"
|
|
2
|
+
You have a syntax error at "schema.sql". Reference with the same endpoints already exists: "student"("subject_id", "score_id") references "score_subject"("subject_id", "score_id")
|
|
3
3
|
|
|
4
4
|
A complete log can be found in:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
CREATE TABLE "users" (
|
|
2
|
+
"id" int PRIMARY KEY,
|
|
3
|
+
"name" varchar
|
|
4
|
+
);
|
|
5
|
+
|
|
6
|
+
CREATE TABLE "orders" (
|
|
7
|
+
"id" int PRIMARY KEY,
|
|
8
|
+
"user_id" int
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
ALTER TABLE "orders" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id") DEFERRABLE INITIALLY IMMEDIATE;
|
|
12
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
CREATE TABLE "users" (
|
|
2
|
+
"id" int PRIMARY KEY,
|
|
3
|
+
"name" varchar
|
|
4
|
+
);
|
|
5
|
+
|
|
6
|
+
CREATE TABLE "orders" (
|
|
7
|
+
"id" int PRIMARY KEY,
|
|
8
|
+
"user_id" int
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
ALTER TABLE "orders" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id") DEFERRABLE INITIALLY IMMEDIATE;
|
|
12
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import childProcess from 'child_process';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import util from 'util';
|
|
5
|
+
import stripAnsi from 'strip-ansi';
|
|
6
|
+
import {
|
|
7
|
+
scanDirNames,
|
|
8
|
+
} from './testHelpers';
|
|
9
|
+
|
|
10
|
+
const exec = util.promisify(childProcess.exec);
|
|
11
|
+
|
|
12
|
+
// Only run on Windows - skipped on other platforms
|
|
13
|
+
const describeOnWindows = process.platform === 'win32' ? describe : describe.skip;
|
|
14
|
+
|
|
15
|
+
describeOnWindows('@dbml/cli - Windows paths', () => {
|
|
16
|
+
const runTest = async (dirName: string) => {
|
|
17
|
+
process.chdir(dirName);
|
|
18
|
+
const binFile = path.join(__dirname, '../bin/dbml2sql.js');
|
|
19
|
+
const optsRaw = fs.readFileSync(path.join(dirName, './options.json'), 'utf-8');
|
|
20
|
+
const opts = JSON.parse(optsRaw);
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
stdout,
|
|
24
|
+
} = await exec(`node "${binFile}" ${opts.args.join(' ')}`);
|
|
25
|
+
const expectStdout = fs.readFileSync(path.join(dirName, './stdout.txt'), 'utf-8').replaceAll('\r\n', '\n');
|
|
26
|
+
const actualStdout = stripAnsi(stdout).replaceAll('\r\n', '\n');
|
|
27
|
+
|
|
28
|
+
expect(actualStdout).toBe(expectStdout);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
test.each(scanDirNames(__dirname, 'windows'))('windows/%s', async (dirName) => {
|
|
32
|
+
await runTest(path.join(__dirname, 'windows', dirName));
|
|
33
|
+
}, 100000);
|
|
34
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -39,7 +39,7 @@ let node_fs = require("node:fs");
|
|
|
39
39
|
var package_default = {
|
|
40
40
|
$schema: "https://json.schemastore.org/package",
|
|
41
41
|
name: "@dbml/cli",
|
|
42
|
-
version: "10.4.0-alpha.
|
|
42
|
+
version: "10.4.0-alpha.3",
|
|
43
43
|
description: "",
|
|
44
44
|
main: "lib/index.js",
|
|
45
45
|
license: "Apache-2.0",
|
|
@@ -47,7 +47,7 @@ var package_default = {
|
|
|
47
47
|
"test": "vitest run",
|
|
48
48
|
"test:watch": "vitest watch",
|
|
49
49
|
"coverage": "vitest --coverage",
|
|
50
|
-
"build": "
|
|
50
|
+
"build": "rimraf ./lib && tsc --noEmit && vite build",
|
|
51
51
|
"dev": "vite build --watch",
|
|
52
52
|
"prepublish": "npm run build",
|
|
53
53
|
"lint": "eslint $(git diff --relative --name-only --diff-filter=ACMRTUXB master -- . | grep -E '\\.(js|ts)$')",
|
|
@@ -66,9 +66,9 @@ var package_default = {
|
|
|
66
66
|
keywords: ["dbml", "dbml-cli"],
|
|
67
67
|
dependencies: {
|
|
68
68
|
"@babel/cli": "^7.21.0",
|
|
69
|
-
"@dbml/connector": "^10.4.0-alpha.
|
|
70
|
-
"@dbml/core": "^10.4.0-alpha.
|
|
71
|
-
"@dbml/parse": "^10.4.0-alpha.
|
|
69
|
+
"@dbml/connector": "^10.4.0-alpha.3",
|
|
70
|
+
"@dbml/core": "^10.4.0-alpha.3",
|
|
71
|
+
"@dbml/parse": "^10.4.0-alpha.3",
|
|
72
72
|
"bluebird": "^3.5.5",
|
|
73
73
|
"chalk": "^2.4.2",
|
|
74
74
|
"commander": "^2.20.0",
|
|
@@ -79,7 +79,7 @@ var package_default = {
|
|
|
79
79
|
"strip-ansi": "^5.2.0",
|
|
80
80
|
"winston": "^3.2.1"
|
|
81
81
|
},
|
|
82
|
-
gitHead: "
|
|
82
|
+
gitHead: "3c5f2624711c16e2b5011f118c62899f41abca7d",
|
|
83
83
|
engines: { "node": ">=18" }
|
|
84
84
|
};
|
|
85
85
|
//#endregion
|
|
@@ -2612,7 +2612,7 @@ function generate(inputPaths, transform, outputPlugin) {
|
|
|
2612
2612
|
const content = transform(source);
|
|
2613
2613
|
outputPlugin.write(content);
|
|
2614
2614
|
} catch (e) {
|
|
2615
|
-
if (e instanceof _dbml_core.
|
|
2615
|
+
if (e instanceof _dbml_core.CompilerDiagnostics) throw e.map((diag) => ({
|
|
2616
2616
|
...diag,
|
|
2617
2617
|
message: diag.message,
|
|
2618
2618
|
filepath: path.default.basename(_path),
|
|
@@ -2656,6 +2656,11 @@ var NodeProjectLayout = class {
|
|
|
2656
2656
|
const resolved = _dbml_parse.Filepath.resolve(currentFilepath.dirname, relativePath);
|
|
2657
2657
|
return resolved.absolute.endsWith(".dbml") ? resolved : _dbml_parse.Filepath.from(resolved.absolute + ".dbml");
|
|
2658
2658
|
}
|
|
2659
|
+
getFileSpecifierInfo(currentFilepath, targetFilepath) {
|
|
2660
|
+
let specifier = targetFilepath.relativeTo(currentFilepath.dirname);
|
|
2661
|
+
if (specifier.endsWith(".dbml")) specifier = specifier.slice(0, -5);
|
|
2662
|
+
return { specifier };
|
|
2663
|
+
}
|
|
2659
2664
|
getSource(filePath) {
|
|
2660
2665
|
return safeReadFileSync(filePath.fsPath, "utf-8");
|
|
2661
2666
|
}
|
|
@@ -2778,8 +2783,8 @@ async function importHandler(program) {
|
|
|
2778
2783
|
console.log(` ${chalk.default.green(figures.default.main.tick)} Generated DBML file from SQL file (${config[format].name}): ${path.default.basename(opts.outFile)}`);
|
|
2779
2784
|
}
|
|
2780
2785
|
} catch (error) {
|
|
2781
|
-
if (error instanceof _dbml_core.
|
|
2782
|
-
const msg = `\n ${error.diags.map((diag) => new SyntaxError(diag.filepath ?? "", diag)).map((
|
|
2786
|
+
if (error instanceof _dbml_core.CompilerDiagnostics) {
|
|
2787
|
+
const msg = `\n ${error.diags.map((diag) => new SyntaxError(diag.filepath ?? "", diag)).map((e) => e.message).join("\n ")}`;
|
|
2783
2788
|
consoleLogger.error(msg);
|
|
2784
2789
|
fileLogger.error(msg);
|
|
2785
2790
|
return;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@dbml/cli",
|
|
4
|
-
"version": "10.4.0-alpha.
|
|
4
|
+
"version": "10.4.0-alpha.3",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"test": "vitest run",
|
|
10
10
|
"test:watch": "vitest watch",
|
|
11
11
|
"coverage": "vitest --coverage",
|
|
12
|
-
"build": "
|
|
12
|
+
"build": "rimraf ./lib && tsc --noEmit && vite build",
|
|
13
13
|
"dev": "vite build --watch",
|
|
14
14
|
"prepublish": "npm run build",
|
|
15
15
|
"lint": "eslint $(git diff --relative --name-only --diff-filter=ACMRTUXB master -- . | grep -E '\\.(js|ts)$')",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/cli": "^7.21.0",
|
|
36
|
-
"@dbml/connector": "^10.4.0-alpha.
|
|
37
|
-
"@dbml/core": "^10.4.0-alpha.
|
|
38
|
-
"@dbml/parse": "^10.4.0-alpha.
|
|
36
|
+
"@dbml/connector": "^10.4.0-alpha.3",
|
|
37
|
+
"@dbml/core": "^10.4.0-alpha.3",
|
|
38
|
+
"@dbml/parse": "^10.4.0-alpha.3",
|
|
39
39
|
"bluebird": "^3.5.5",
|
|
40
40
|
"chalk": "^2.4.2",
|
|
41
41
|
"commander": "^2.20.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"strip-ansi": "^5.2.0",
|
|
47
47
|
"winston": "^3.2.1"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "3c5f2624711c16e2b5011f118c62899f41abca7d",
|
|
50
50
|
"engines": {
|
|
51
51
|
"node": ">=18"
|
|
52
52
|
}
|
package/src/NodeProjectLayout.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
readFileSync, readdirSync, statSync,
|
|
3
3
|
} from 'node:fs';
|
|
4
4
|
import {
|
|
5
|
-
type DbmlProjectLayout, Filepath,
|
|
5
|
+
type DbmlProjectLayout, type FileSpecifierInfo, Filepath,
|
|
6
6
|
} from '@dbml/parse';
|
|
7
7
|
import {
|
|
8
8
|
fileLogger,
|
|
@@ -26,6 +26,14 @@ export class NodeProjectLayout implements DbmlProjectLayout {
|
|
|
26
26
|
return resolved.absolute.endsWith('.dbml') ? resolved : Filepath.from(resolved.absolute + '.dbml');
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
getFileSpecifierInfo (currentFilepath: Filepath, targetFilepath: Filepath): FileSpecifierInfo | undefined {
|
|
30
|
+
let specifier = targetFilepath.relativeTo(currentFilepath.dirname);
|
|
31
|
+
if (specifier.endsWith('.dbml')) specifier = specifier.slice(0, -'.dbml'.length);
|
|
32
|
+
return {
|
|
33
|
+
specifier,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
getSource (filePath: Filepath): string | undefined {
|
|
30
38
|
return safeReadFileSync(filePath.fsPath, 'utf-8');
|
|
31
39
|
}
|
package/src/cli/import.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
CompilerDiagnostics, importer,
|
|
4
4
|
} from '@dbml/core';
|
|
5
5
|
import type {
|
|
6
|
+
CompilerDiagnostic,
|
|
6
7
|
ImportFormat,
|
|
7
8
|
} from '@dbml/core';
|
|
8
9
|
import chalk from 'chalk';
|
|
@@ -45,10 +46,8 @@ export default async function importHandler (program: Command) {
|
|
|
45
46
|
console.log(` ${chalk.green(figures.main.tick)} Generated DBML file from SQL file (${config[format].name}): ${path.basename(opts.outFile)}`);
|
|
46
47
|
}
|
|
47
48
|
} catch (error) {
|
|
48
|
-
if (error instanceof
|
|
49
|
-
const msg = `\n ${error.diags.map((diag) => new SyntaxError(diag.filepath ?? '', diag)).map((
|
|
50
|
-
message,
|
|
51
|
-
}) => message).join('\n ')}`;
|
|
49
|
+
if (error instanceof CompilerDiagnostics) {
|
|
50
|
+
const msg = `\n ${error.diags.map((diag: CompilerDiagnostic) => new SyntaxError(diag.filepath ?? '', diag)).map((e: SyntaxError) => e.message).join('\n ')}`;
|
|
52
51
|
consoleLogger.error(msg);
|
|
53
52
|
fileLogger.error(msg);
|
|
54
53
|
return;
|
package/src/cli/utils.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
CompilerDiagnostics,
|
|
5
|
+
type CompilerDiagnostic,
|
|
5
6
|
type ExportFormat,
|
|
6
7
|
} from '@dbml/core';
|
|
7
8
|
import {
|
|
@@ -88,8 +89,8 @@ function generate (
|
|
|
88
89
|
const content = transform(source);
|
|
89
90
|
outputPlugin.write(content);
|
|
90
91
|
} catch (e) {
|
|
91
|
-
if (e instanceof
|
|
92
|
-
throw e.map((diag) => ({
|
|
92
|
+
if (e instanceof CompilerDiagnostics) {
|
|
93
|
+
throw e.map((diag: CompilerDiagnostic) => ({
|
|
93
94
|
...diag,
|
|
94
95
|
message: diag.message,
|
|
95
96
|
filepath: path.basename(_path),
|