@dbml/cli 8.0.0-alpha.0 → 8.0.0-alpha.10

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 (33) hide show
  1. package/__tests__/db2dbml/mssql/dbml-error.log +70 -0
  2. package/__tests__/db2dbml/mysql/dbml-error.log +91 -0
  3. package/__tests__/db2dbml/oracle/dbml-error.log +98 -0
  4. package/__tests__/db2dbml/postgres/dbml-error.log +56 -0
  5. package/__tests__/dbml2sql/filename --mysql --out-file/out-files/schema.sql +1 -1
  6. package/__tests__/dbml2sql/filename --oracle --out-file/out-files/schema.sql +1 -1
  7. package/__tests__/dbml2sql/filename --out-file/out-files/schema.sql +1 -1
  8. package/__tests__/dbml2sql/filename --postgres --out-file/out-files/schema.sql +1 -1
  9. package/__tests__/dbml2sql/filenames --mysql --out-file/out-files/schema.sql +1 -1
  10. package/__tests__/dbml2sql/filenames --oracle --out-file/out-files/schema.sql +1 -1
  11. package/__tests__/dbml2sql/filenames --out-file/out-files/schema.sql +1 -1
  12. package/__tests__/dbml2sql/filenames --postgres --out-file/out-files/schema.sql +1 -1
  13. package/__tests__/dbml2sql/multiple_schema_mssql/out-files/multiple_schema.out.sql +1 -1
  14. package/__tests__/dbml2sql/multiple_schema_mysql/out-files/multiple_schema.out.sql +1 -1
  15. package/__tests__/dbml2sql/multiple_schema_oracle/out-files/multiple_schema.out.sql +1 -1
  16. package/__tests__/dbml2sql/multiple_schema_pg/out-files/multiple_schema.out.sql +1 -1
  17. package/__tests__/dbml2sql/syntax-error/dbml-error.log +46 -0
  18. package/__tests__/dbml2sql/syntax-error/stdout.txt +2 -2
  19. package/__tests__/sql2dbml/custom-error-alter-table-column-not-found --oracle/dbml-error.log +38 -0
  20. package/__tests__/sql2dbml/custom-error-alter-table-table-not-found --oracle/dbml-error.log +38 -0
  21. package/__tests__/sql2dbml/custom-error-column-comment-column-not-found --oracle/dbml-error.log +38 -0
  22. package/__tests__/sql2dbml/custom-error-column-comment-table-not-found --oracle/dbml-error.log +38 -0
  23. package/__tests__/sql2dbml/custom-error-create-index-table-not-found --oracle/dbml-error.log +38 -0
  24. package/__tests__/sql2dbml/custom-error-table-comment-table-not-found --oracle/dbml-error.log +38 -0
  25. package/__tests__/sql2dbml/syntax-error/dbml-error.log +31 -0
  26. package/__tests__/sql2dbml/syntax-error-duplicate-endpoints --mssql/dbml-error.log +31 -0
  27. package/__tests__/sql2dbml/syntax-error-duplicate-endpoints --mysql/dbml-error.log +27 -0
  28. package/lib/index.js +23 -52
  29. package/package.json +4 -4
  30. package/src/NodeProjectLayout.ts +12 -76
  31. package/src/cli/connector.ts +1 -1
  32. package/src/cli/export.ts +3 -4
  33. package/src/helpers/logger.ts +5 -7
@@ -106,3 +106,41 @@ undefined
106
106
  2026-05-04T17:07:48.660Z
107
107
  undefined
108
108
 
109
+ 2026-05-06T08:11:01.868Z
110
+
111
+ You have a syntax error at "schema.sql" line 5 column 19. Table "Posts" not found
112
+
113
+ 2026-05-06T08:13:56.089Z
114
+
115
+ You have a syntax error at "schema.sql" line 5 column 19. Table "Posts" not found
116
+
117
+ 2026-05-06T08:16:21.046Z
118
+
119
+ You have a syntax error at "schema.sql" line 5 column 19. Table "Posts" not found
120
+
121
+ 2026-05-06T08:17:29.142Z
122
+ undefined
123
+
124
+ 2026-05-06T08:18:45.383Z
125
+ undefined
126
+
127
+ 2026-05-06T08:31:57.068Z
128
+
129
+ You have a syntax error at "schema.sql" line 5 column 19. Table "Posts" not found
130
+
131
+ 2026-05-06T10:17:06.468Z
132
+
133
+ You have a syntax error at "schema.sql" line 5 column 19. Table "Posts" not found
134
+
135
+ 2026-05-07T08:40:44.510Z
136
+
137
+ You have a syntax error at "schema.sql" line 5 column 19. Table "Posts" not found
138
+
139
+ 2026-05-07T08:42:39.340Z
140
+
141
+ You have a syntax error at "schema.sql" line 5 column 19. Table "Posts" not found
142
+
143
+ 2026-05-12T10:00:10.389Z
144
+
145
+ You have a syntax error at "schema.sql" line 5 column 19. Table "Posts" not found
146
+
@@ -106,3 +106,41 @@ undefined
106
106
  2026-05-04T17:07:49.994Z
107
107
  undefined
108
108
 
109
+ 2026-05-06T08:11:03.157Z
110
+
111
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
112
+
113
+ 2026-05-06T08:13:57.435Z
114
+
115
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
116
+
117
+ 2026-05-06T08:16:22.365Z
118
+
119
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
120
+
121
+ 2026-05-06T08:17:30.519Z
122
+ undefined
123
+
124
+ 2026-05-06T08:18:46.726Z
125
+ undefined
126
+
127
+ 2026-05-06T08:31:58.490Z
128
+
129
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
130
+
131
+ 2026-05-06T10:17:07.902Z
132
+
133
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
134
+
135
+ 2026-05-07T08:40:46.177Z
136
+
137
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
138
+
139
+ 2026-05-07T08:42:40.824Z
140
+
141
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
142
+
143
+ 2026-05-12T10:00:12.045Z
144
+
145
+ You have a syntax error at "schema.sql" line 1 column 28. Table Users not found
146
+
@@ -106,3 +106,41 @@ undefined
106
106
  2026-05-04T17:07:51.317Z
107
107
  undefined
108
108
 
109
+ 2026-05-06T08:11:04.457Z
110
+
111
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
112
+
113
+ 2026-05-06T08:13:58.756Z
114
+
115
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
116
+
117
+ 2026-05-06T08:16:23.709Z
118
+
119
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
120
+
121
+ 2026-05-06T08:17:31.997Z
122
+ undefined
123
+
124
+ 2026-05-06T08:18:48.105Z
125
+ undefined
126
+
127
+ 2026-05-06T08:31:59.877Z
128
+
129
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
130
+
131
+ 2026-05-06T10:17:09.292Z
132
+
133
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
134
+
135
+ 2026-05-07T08:40:47.729Z
136
+
137
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
138
+
139
+ 2026-05-07T08:42:42.345Z
140
+
141
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
142
+
143
+ 2026-05-12T10:00:13.619Z
144
+
145
+ You have a syntax error at "schema.sql" line 5 column 18. Table "Posts" not found
146
+
@@ -100,3 +100,34 @@ undefined
100
100
  2026-05-04T17:08:20.676Z
101
101
  undefined
102
102
 
103
+ 2026-05-06T08:11:32.725Z
104
+
105
+ 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`'
106
+
107
+ 2026-05-06T08:14:29.008Z
108
+
109
+ 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`'
110
+
111
+ 2026-05-06T08:18:03.492Z
112
+ undefined
113
+
114
+ 2026-05-06T08:32:30.153Z
115
+
116
+ 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`'
117
+
118
+ 2026-05-06T10:17:39.447Z
119
+
120
+ 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`'
121
+
122
+ 2026-05-07T08:41:20.977Z
123
+
124
+ 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`'
125
+
126
+ 2026-05-07T08:43:18.594Z
127
+
128
+ 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`'
129
+
130
+ 2026-05-12T10:00:47.485Z
131
+
132
+ 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`'
133
+
@@ -97,3 +97,34 @@ undefined
97
97
  2026-05-04T17:07:07.077Z
98
98
  undefined
99
99
 
100
+ 2026-05-06T08:11:34.178Z
101
+
102
+ 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")
103
+
104
+ 2026-05-06T08:14:30.449Z
105
+
106
+ 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")
107
+
108
+ 2026-05-06T08:18:04.905Z
109
+ undefined
110
+
111
+ 2026-05-06T08:32:31.718Z
112
+
113
+ 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")
114
+
115
+ 2026-05-06T10:17:40.917Z
116
+
117
+ 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")
118
+
119
+ 2026-05-07T08:41:22.546Z
120
+
121
+ 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")
122
+
123
+ 2026-05-07T08:43:20.245Z
124
+
125
+ 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")
126
+
127
+ 2026-05-12T10:00:49.171Z
128
+
129
+ 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")
130
+
@@ -97,3 +97,30 @@ undefined
97
97
  2026-05-04T17:07:08.426Z
98
98
  undefined
99
99
 
100
+ 2026-05-06T08:11:35.478Z
101
+
102
+ 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")
103
+
104
+ 2026-05-06T08:14:31.766Z
105
+
106
+ 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")
107
+
108
+ 2026-05-06T08:18:06.210Z
109
+ undefined
110
+
111
+ 2026-05-06T10:17:42.282Z
112
+
113
+ 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")
114
+
115
+ 2026-05-07T08:41:24.076Z
116
+
117
+ 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")
118
+
119
+ 2026-05-07T08:43:21.697Z
120
+
121
+ 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")
122
+
123
+ 2026-05-12T10:00:50.634Z
124
+
125
+ 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")
126
+
package/lib/index.js CHANGED
@@ -29,6 +29,8 @@ let chalk = require("chalk");
29
29
  chalk = __toESM(chalk);
30
30
  let figures = require("figures");
31
31
  figures = __toESM(figures);
32
+ let strip_ansi = require("strip-ansi");
33
+ strip_ansi = __toESM(strip_ansi);
32
34
  let winston = require("winston");
33
35
  let fs = require("fs");
34
36
  fs = __toESM(fs);
@@ -36,7 +38,7 @@ let __dbml_parse = require("@dbml/parse");
36
38
  let node_fs = require("node:fs");
37
39
  const $schema = "https://json.schemastore.org/package";
38
40
  const name = "@dbml/cli";
39
- const version = "8.0.0-alpha.0";
41
+ const version = "8.0.0-alpha.10";
40
42
  const description = "";
41
43
  const main = "lib/index.js";
42
44
  const license = "Apache-2.0";
@@ -63,8 +65,8 @@ const keywords = ["dbml", "dbml-cli"];
63
65
  const dependencies = {
64
66
  "@babel/cli": "^7.21.0",
65
67
  "@dbml/connector": "^8.0.0-alpha.0",
66
- "@dbml/core": "^8.0.0-alpha.0",
67
- "@dbml/parse": "^8.0.0-alpha.0",
68
+ "@dbml/core": "^8.0.0-alpha.10",
69
+ "@dbml/parse": "^8.0.0-alpha.10",
68
70
  "bluebird": "^3.5.5",
69
71
  "chalk": "^2.4.2",
70
72
  "commander": "^2.20.0",
@@ -75,7 +77,7 @@ const dependencies = {
75
77
  "strip-ansi": "^5.2.0",
76
78
  "winston": "^3.2.1"
77
79
  };
78
- const gitHead = "4b99e7eab601b7d53e268d5d80048ee035614a79";
80
+ const gitHead = "219525258181f597943175cf46783566dcddb441";
79
81
  const engines = { "node": ">=18" };
80
82
  var package_default = {
81
83
  $schema,
@@ -103,8 +105,8 @@ var consoleFormat = printf((info) => {
103
105
  ${path.default.resolve(process.cwd(), "dbml-error.log")}`;
104
106
  });
105
107
  var fileFormat = printf((info) => {
106
- const { timestamp: ts, stack, rootError } = info;
107
- let logContent = `${ts}\n${stack}\n`;
108
+ const { timestamp: ts, message, stack, rootError } = info;
109
+ let logContent = `${ts}\n${(0, strip_ansi.default)(stack ?? message ?? "")}\n`;
108
110
  if (rootError) {
109
111
  logContent += "\nROOT_ERROR:";
110
112
  logContent += `\n${rootError.stack}`;
@@ -512,8 +514,8 @@ ListCache.prototype.get = _listCacheGet_default;
512
514
  ListCache.prototype.has = _listCacheHas_default;
513
515
  ListCache.prototype.set = _listCacheSet_default;
514
516
  var _ListCache_default = ListCache;
515
- var Map$1 = _getNative_default(_root_default, "Map");
516
- var _Map_default = Map$1;
517
+ var Map = _getNative_default(_root_default, "Map");
518
+ var _Map_default = Map;
517
519
  function mapCacheClear() {
518
520
  this.size = 0;
519
521
  this.__data__ = {
@@ -726,8 +728,8 @@ var DataView = _getNative_default(_root_default, "DataView");
726
728
  var _DataView_default = DataView;
727
729
  var Promise$1 = _getNative_default(_root_default, "Promise");
728
730
  var _Promise_default = Promise$1;
729
- var Set$1 = _getNative_default(_root_default, "Set");
730
- var _Set_default = Set$1;
731
+ var Set = _getNative_default(_root_default, "Set");
732
+ var _Set_default = Set;
731
733
  var mapTag$2 = "[object Map]", objectTag$1 = "[object Object]", promiseTag = "[object Promise]", setTag$2 = "[object Set]", weakMapTag = "[object WeakMap]";
732
734
  var dataViewTag$1 = "[object DataView]";
733
735
  var dataViewCtorString = _toSource_default(_DataView_default), mapCtorString = _toSource_default(_Map_default), promiseCtorString = _toSource_default(_Promise_default), setCtorString = _toSource_default(_Set_default), weakMapCtorString = _toSource_default(_WeakMap_default);
@@ -1178,75 +1180,45 @@ async function connectionHandler(program$1) {
1178
1180
  logger_default.error(error);
1179
1181
  }
1180
1182
  }
1181
- var NodeProjectLayout = class NodeProjectLayout {
1183
+ var NodeProjectLayout = class {
1182
1184
  constructor(entryPoints) {
1183
- this.overlay = /* @__PURE__ */ new Map();
1184
1185
  this.entryPoints = [...entryPoints];
1185
1186
  }
1186
- setSource(filePath, content) {
1187
- this.overlay.set(filePath.absolute, content);
1188
- }
1189
1187
  getSource(filePath) {
1190
- const absolutePath = filePath.absolute;
1191
- if (this.overlay.has(absolutePath)) return this.overlay.get(absolutePath) ?? void 0;
1192
1188
  try {
1193
- return (0, node_fs.readFileSync)(absolutePath, "utf-8");
1189
+ return (0, node_fs.readFileSync)(filePath.absolute, "utf-8");
1194
1190
  } catch {
1195
1191
  return;
1196
1192
  }
1197
1193
  }
1198
- deleteSource(filePath) {
1199
- this.overlay.set(filePath.absolute, null);
1200
- }
1201
- clearSource() {
1202
- this.overlay.clear();
1203
- this.entryPoints = [];
1204
- }
1205
1194
  exists(filePath) {
1206
1195
  return this.isFile(filePath) || this.isDirectory(filePath);
1207
1196
  }
1208
1197
  isFile(filePath) {
1209
- const absolutePath = filePath.absolute;
1210
- if (this.overlay.has(absolutePath)) return this.overlay.get(absolutePath) !== null;
1211
1198
  try {
1212
- return (0, node_fs.statSync)(absolutePath).isFile();
1199
+ return (0, node_fs.statSync)(filePath.absolute).isFile();
1213
1200
  } catch {
1214
1201
  return false;
1215
1202
  }
1216
1203
  }
1217
1204
  isDirectory(filePath) {
1218
- const absolutePath = filePath.absolute;
1219
1205
  try {
1220
- if ((0, node_fs.statSync)(absolutePath).isDirectory()) return true;
1221
- } catch {}
1222
- for (const [overlayPath, content] of this.overlay) {
1223
- if (content === null) continue;
1224
- if (overlayPath.startsWith(absolutePath)) return true;
1206
+ return (0, node_fs.statSync)(filePath.absolute).isDirectory();
1207
+ } catch {
1208
+ return false;
1225
1209
  }
1226
- return false;
1227
1210
  }
1228
1211
  listDirectory(dirPath) {
1229
1212
  const basePath = dirPath?.absolute ?? "/";
1230
- const results = /* @__PURE__ */ new Set();
1231
1213
  try {
1232
- for (const entry of (0, node_fs.readdirSync)(basePath)) results.add(basePath + entry);
1233
- } catch {}
1234
- for (const [abs, content] of this.overlay) {
1235
- if (content === null) continue;
1236
- if (!abs.startsWith(basePath)) continue;
1237
- if (!abs.slice(basePath.length).includes("/")) results.add(abs);
1214
+ return (0, node_fs.readdirSync)(basePath).map((entry) => basePath + entry).sort().map(__dbml_parse.Filepath.from);
1215
+ } catch {
1216
+ return [];
1238
1217
  }
1239
- for (const [overlayPath, content] of this.overlay) if (content === null) results.delete(overlayPath);
1240
- return [...results].sort().map(__dbml_parse.Filepath.from);
1241
1218
  }
1242
- getEntryPoints() {
1219
+ getEntrypoints() {
1243
1220
  return this.entryPoints.filter((fp) => this.exists(fp));
1244
1221
  }
1245
- clone() {
1246
- const copy = new NodeProjectLayout([...this.entryPoints]);
1247
- for (const [overlayPath, content] of this.overlay) copy.overlay.set(overlayPath, content);
1248
- return copy;
1249
- }
1250
1222
  };
1251
1223
  var config = {
1252
1224
  mysql: { name: "MySQL" },
@@ -1285,8 +1257,7 @@ async function exportHandler(program$1) {
1285
1257
  const pos = e.nodeOrToken.startPos;
1286
1258
  const line = pos.line + 1;
1287
1259
  const col = pos.column + 1;
1288
- if (isMultifile) return `${e.filepath.basename}(${line},${col}): ${e.message}`;
1289
- return `You have a syntax error at "${e.filepath.basename}" line ${line} column ${col}. ${e.message}`;
1260
+ return `${chalk.default.cyan(isMultifile ? e.filepath.relativeTo(process.cwd()) : e.filepath.basename)}${chalk.default.yellow(`(${line},${col})`)}: ${e.message}`;
1290
1261
  }).join("\n ")}`);
1291
1262
  continue;
1292
1263
  }
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": "8.0.0-alpha.0",
4
+ "version": "8.0.0-alpha.10",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "license": "Apache-2.0",
@@ -33,8 +33,8 @@
33
33
  "dependencies": {
34
34
  "@babel/cli": "^7.21.0",
35
35
  "@dbml/connector": "^8.0.0-alpha.0",
36
- "@dbml/core": "^8.0.0-alpha.0",
37
- "@dbml/parse": "^8.0.0-alpha.0",
36
+ "@dbml/core": "^8.0.0-alpha.10",
37
+ "@dbml/parse": "^8.0.0-alpha.10",
38
38
  "bluebird": "^3.5.5",
39
39
  "chalk": "^2.4.2",
40
40
  "commander": "^2.20.0",
@@ -45,7 +45,7 @@
45
45
  "strip-ansi": "^5.2.0",
46
46
  "winston": "^3.2.1"
47
47
  },
48
- "gitHead": "4b99e7eab601b7d53e268d5d80048ee035614a79",
48
+ "gitHead": "219525258181f597943175cf46783566dcddb441",
49
49
  "engines": {
50
50
  "node": ">=18"
51
51
  }
@@ -1,125 +1,61 @@
1
1
  import {
2
- existsSync, readFileSync, readdirSync, statSync,
2
+ readFileSync, readdirSync, statSync,
3
3
  } from 'node:fs';
4
4
  import {
5
5
  type DbmlProjectLayout, Filepath,
6
6
  } from '@dbml/parse';
7
7
 
8
8
  /**
9
- * A DbmlProjectLayout backed by the Node.js filesystem.
10
- * Reads source files on demand from disk; setSource/deleteSource maintain an
11
- * in-memory overlay (e.g. for unsaved edits) without touching the real FS.
9
+ * A read-only DbmlProjectLayout backed by the Node.js filesystem.
12
10
  */
13
11
  export class NodeProjectLayout implements DbmlProjectLayout {
14
- // Overlay is an overriding map of file absolute paths to file content
15
- // `null`: The file is deleted
16
- private overlay = new Map<string, string | null>();
17
12
  private entryPoints: Filepath[];
18
13
 
19
14
  constructor (entryPoints: Filepath[]) {
20
15
  this.entryPoints = [...entryPoints];
21
16
  }
22
17
 
23
- setSource (filePath: Filepath, content: string): void {
24
- this.overlay.set(filePath.absolute, content);
25
- }
26
-
27
18
  getSource (filePath: Filepath): string | undefined {
28
- const absolutePath = filePath.absolute;
29
-
30
- // If overlay already has the file,
31
- // return its content
32
- if (this.overlay.has(absolutePath)) {
33
- const value = this.overlay.get(absolutePath);
34
- return value ?? undefined; // null (deleted) -> undefined
35
- }
36
19
  try {
37
- return readFileSync(absolutePath, 'utf-8');
20
+ return readFileSync(filePath.absolute, 'utf-8');
38
21
  } catch {
39
22
  return undefined;
40
23
  }
41
24
  }
42
25
 
43
- deleteSource (filePath: Filepath): void {
44
- this.overlay.set(filePath.absolute, null);
45
- }
46
-
47
- clearSource (): void {
48
- this.overlay.clear();
49
- this.entryPoints = [];
50
- }
51
-
52
26
  exists (filePath: Filepath): boolean {
53
27
  return this.isFile(filePath) || this.isDirectory(filePath);
54
28
  }
55
29
 
56
30
  isFile (filePath: Filepath): boolean {
57
- const absolutePath = filePath.absolute;
58
-
59
- if (this.overlay.has(absolutePath)) return this.overlay.get(absolutePath) !== null;
60
-
61
31
  try {
62
- // `statSync` (not lstatSync) so symlinks resolve to their target, matching
63
- // how node reads the file on disk.
64
- return statSync(absolutePath).isFile();
32
+ return statSync(filePath.absolute).isFile();
65
33
  } catch {
66
34
  return false;
67
35
  }
68
36
  }
69
37
 
70
38
  isDirectory (filePath: Filepath): boolean {
71
- const absolutePath = filePath.absolute;
72
-
73
39
  try {
74
- // Exist in filesystem
75
- if (statSync(absolutePath).isDirectory()) return true;
40
+ return statSync(filePath.absolute).isDirectory();
76
41
  } catch {
77
- // fall through: the path may exist only in the overlay
78
- }
79
- for (const [overlayPath, content] of this.overlay) {
80
- if (content === null) continue;
81
- if (overlayPath.startsWith(absolutePath)) return true;
42
+ return false;
82
43
  }
83
- return false;
84
44
  }
85
45
 
86
46
  listDirectory (dirPath?: Filepath): Filepath[] {
87
47
  const basePath = dirPath?.absolute ?? '/';
88
- const results = new Set<string>();
89
-
90
48
  try {
91
- // Filesystem entries
92
- for (const entry of readdirSync(basePath)) {
93
- results.add(basePath + entry);
94
- }
49
+ return readdirSync(basePath)
50
+ .map((entry) => basePath + entry)
51
+ .sort()
52
+ .map(Filepath.from);
95
53
  } catch {
96
- // Not a readable directory - ignore
54
+ return [];
97
55
  }
98
-
99
- // Overlay additions: non-deleted files directly under base
100
- for (const [abs, content] of this.overlay) {
101
- if (content === null) continue;
102
- if (!abs.startsWith(basePath)) continue;
103
- if (!abs.slice(basePath.length).includes('/')) results.add(abs);
104
- }
105
-
106
- // Remove overlay-deleted paths
107
- for (const [overlayPath, content] of this.overlay) {
108
- if (content === null) results.delete(overlayPath);
109
- }
110
-
111
- return [...results].sort().map(Filepath.from);
112
56
  }
113
57
 
114
- getEntryPoints (): Filepath[] {
58
+ getEntrypoints (): Filepath[] {
115
59
  return this.entryPoints.filter((fp) => this.exists(fp));
116
60
  }
117
-
118
- clone (): NodeProjectLayout {
119
- const copy = new NodeProjectLayout([...this.entryPoints]);
120
- for (const [overlayPath, content] of this.overlay) {
121
- copy.overlay.set(overlayPath, content);
122
- }
123
- return copy;
124
- }
125
61
  }
@@ -37,6 +37,6 @@ export default async function connectionHandler (program: Command) {
37
37
  console.log(` ${chalk.green(figures.main.tick)} Generated DBML file from database's connection: ${path.basename(opts.outFile)}`);
38
38
  }
39
39
  } catch (error) {
40
- logger.error(error);
40
+ logger.error(error as Error | string);
41
41
  }
42
42
  }
package/src/cli/export.ts CHANGED
@@ -62,10 +62,9 @@ export default async function exportHandler (program: Command): Promise<void> {
62
62
  const pos = e.nodeOrToken.startPos;
63
63
  const line = pos.line + 1;
64
64
  const col = pos.column + 1;
65
- if (isMultifile) {
66
- return `${e.filepath.basename}(${line},${col}): ${e.message}`;
67
- }
68
- return `You have a syntax error at "${e.filepath.basename}" line ${line} column ${col}. ${e.message}`;
65
+ const location = chalk.cyan(isMultifile ? e.filepath.relativeTo(process.cwd()) : e.filepath.basename);
66
+ const position = chalk.yellow(`(${line},${col})`);
67
+ return `${location}${position}: ${e.message}`;
69
68
  })
70
69
  .join('\n ')}`,
71
70
  );
@@ -1,5 +1,6 @@
1
1
  import path from 'path';
2
2
  import chalk from 'chalk';
3
+ import stripAnsi from 'strip-ansi';
3
4
  import {
4
5
  createLogger, format, transports,
5
6
  } from 'winston';
@@ -19,12 +20,9 @@ const consoleFormat = printf((info) => {
19
20
 
20
21
  const fileFormat = printf((info) => {
21
22
  const {
22
- timestamp: ts, stack, rootError,
23
- } = info as unknown as { timestamp: string;
24
- stack?: string;
25
- rootError?: { stack?: string;
26
- location?: unknown; }; };
27
- let logContent = `${ts}\n${stack}\n`;
23
+ timestamp: ts, message, stack, rootError,
24
+ } = info as any;
25
+ let logContent = `${ts}\n${stripAnsi(stack ?? message ?? '')}\n`;
28
26
  if (rootError) {
29
27
  logContent += '\nROOT_ERROR:';
30
28
  logContent += `\n${rootError.stack}`;
@@ -71,7 +69,7 @@ const logger = {
71
69
  consoleLogger.warn(msg);
72
70
  },
73
71
 
74
- error (msg: any) {
72
+ error (msg: Error | string) {
75
73
  consoleLogger.error(msg);
76
74
  fileLogger.error(msg);
77
75
  },