@dbml/cli 3.4.0 → 3.4.1-alpha.0

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 (55) hide show
  1. package/__test__/dbml2sql/filename --mysql --out-file/dbml-error.log +36 -0
  2. package/__test__/dbml2sql/filename --mysql --out-file/out-files/schema.sql +2 -2
  3. package/__test__/dbml2sql/filename --oracle --out-file/dbml-error.log +0 -0
  4. package/__test__/dbml2sql/filename --oracle --out-file/out-files/schema.sql +61 -0
  5. package/__test__/dbml2sql/filename --oracle stdout/dbml-error.log +0 -0
  6. package/__test__/dbml2sql/filename --out-file/dbml-error.log +36 -0
  7. package/__test__/dbml2sql/filename --out-file/out-files/schema.sql +2 -2
  8. package/__test__/dbml2sql/filename --postgres --out-file/dbml-error.log +24 -0
  9. package/__test__/dbml2sql/filename --postgres --out-file/out-files/schema.sql +2 -2
  10. package/__test__/dbml2sql/filenames --mysql --out-file/dbml-error.log +24 -0
  11. package/__test__/dbml2sql/filenames --mysql --out-file/out-files/schema.sql +2 -2
  12. package/__test__/dbml2sql/filenames --oracle --out-file/dbml-error.log +0 -0
  13. package/__test__/dbml2sql/filenames --oracle --out-file/out-files/schema.sql +172 -0
  14. package/__test__/dbml2sql/filenames --oracle stdout/dbml-error.log +0 -0
  15. package/__test__/dbml2sql/filenames --out-file/dbml-error.log +24 -0
  16. package/__test__/dbml2sql/filenames --out-file/out-files/schema.sql +2 -2
  17. package/__test__/dbml2sql/filenames --postgres --out-file/dbml-error.log +24 -0
  18. package/__test__/dbml2sql/filenames --postgres --out-file/out-files/schema.sql +2 -2
  19. package/__test__/dbml2sql/multiple_schema_mssql/dbml-error.log +24 -0
  20. package/__test__/dbml2sql/multiple_schema_mssql/out-files/multiple_schema.out.sql +2 -2
  21. package/__test__/dbml2sql/multiple_schema_mysql/dbml-error.log +24 -0
  22. package/__test__/dbml2sql/multiple_schema_mysql/out-files/multiple_schema.out.sql +2 -2
  23. package/__test__/dbml2sql/multiple_schema_oracle/dbml-error.log +0 -0
  24. package/__test__/dbml2sql/multiple_schema_oracle/out-files/multiple_schema.out.sql +88 -0
  25. package/__test__/dbml2sql/multiple_schema_pg/dbml-error.log +24 -0
  26. package/__test__/dbml2sql/multiple_schema_pg/out-files/multiple_schema.out.sql +2 -2
  27. package/__test__/dbml2sql/syntax-error/dbml-error.log +2158 -1074
  28. package/__test__/sql2dbml/filename --mssql --out-file/dbml-error.log +51 -0
  29. package/__test__/sql2dbml/filename --mysql --out-file/dbml-error.log +24 -0
  30. package/__test__/sql2dbml/filename --out-file/dbml-error.log +24 -0
  31. package/__test__/sql2dbml/filename --postgres --out-file/dbml-error.log +24 -0
  32. package/__test__/sql2dbml/filenames --mysql --out-file/dbml-error.log +239 -0
  33. package/__test__/sql2dbml/filenames --mysql stdout/dbml-error.log +218 -0
  34. package/__test__/sql2dbml/filenames --out-file/dbml-error.log +24 -0
  35. package/__test__/sql2dbml/filenames --postgres --out-file/dbml-error.log +24 -0
  36. package/__test__/sql2dbml/multiple_schema_mssql/dbml-error.log +121 -0
  37. package/__test__/sql2dbml/multiple_schema_mysql/dbml-error.log +104 -0
  38. package/__test__/sql2dbml/multiple_schema_pg/dbml-error.log +163 -32
  39. package/__test__/sql2dbml/syntax-error/dbml-error.log +2711 -1094
  40. package/__test__/sql2dbml/syntax-error-duplicate-endpoints --mssql/dbml-error.log +1990 -1130
  41. package/__test__/sql2dbml/syntax-error-duplicate-endpoints --mssql/stdout.txt +2 -1
  42. package/__test__/sql2dbml/syntax-error-duplicate-endpoints --mysql/dbml-error.log +1985 -1125
  43. package/__test__/sql2dbml/syntax-error-duplicate-endpoints --mysql/stdout.txt +2 -1
  44. package/bin/dbml-error.log +0 -0
  45. package/bin/dbml2sql.js +0 -0
  46. package/bin/sql2dbml.js +0 -0
  47. package/dbml-error.log +322 -258
  48. package/lib/cli/export.js +3 -3
  49. package/lib/cli/import.js +3 -3
  50. package/lib/cli/utils.js +8 -6
  51. package/package.json +3 -3
  52. package/src/cli/export.js +4 -4
  53. package/src/cli/import.js +4 -5
  54. package/src/cli/utils.js +4 -6
  55. package/yarn-error.log +0 -87
package/lib/cli/export.js CHANGED
@@ -14,6 +14,7 @@ var _outputConsolePlugin = _interopRequireDefault(require("./outputPlugins/outpu
14
14
  var _outputFilePlugin = _interopRequireDefault(require("./outputPlugins/outputFilePlugin"));
15
15
  var _config = _interopRequireDefault(require("./config"));
16
16
  var _logger = _interopRequireDefault(require("../helpers/logger"));
17
+ var _errors = require("../errors");
17
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19
  async function exportHandler(program) {
19
20
  try {
@@ -28,9 +29,8 @@ async function exportHandler(program) {
28
29
  (0, _utils.generate)(inputPaths, dbml => _core.exporter.export(dbml, format), new _outputFilePlugin.default((0, _utils.resolvePaths)(opts.outFile), header));
29
30
  console.log(` ${_chalk.default.green(_figures.default.main.tick)} Generated SQL dump file (${_config.default[format].name}): ${_path.default.basename(opts.outFile)}`);
30
31
  }
31
- } catch (errors) {
32
- // TODO: handle error in case errors object is not mappable
33
- _logger.default.error(`\n ${errors.map(({
32
+ } catch (error) {
33
+ _logger.default.error(`\n ${error.diags.map(diag => new _errors.SyntaxError(diag.filepath, diag)).map(({
34
34
  message
35
35
  }) => message).join('\n ')}`);
36
36
  }
package/lib/cli/import.js CHANGED
@@ -14,6 +14,7 @@ var _validatePlugins = require("./validatePlugins/validatePlugins");
14
14
  var _outputConsolePlugin = _interopRequireDefault(require("./outputPlugins/outputConsolePlugin"));
15
15
  var _outputFilePlugin = _interopRequireDefault(require("./outputPlugins/outputFilePlugin"));
16
16
  var _logger = _interopRequireDefault(require("../helpers/logger"));
17
+ var _errors = require("../errors");
17
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19
  async function importHandler(program) {
19
20
  try {
@@ -27,10 +28,9 @@ async function importHandler(program) {
27
28
  (0, _utils.generate)(inputPaths, sql => _core.importer.import(sql, format), new _outputFilePlugin.default((0, _utils.resolvePaths)(opts.outFile)));
28
29
  console.log(` ${_chalk.default.green(_figures.default.main.tick)} Generated DBML file from SQL file (${_config.default[format].name}): ${_path.default.basename(opts.outFile)}`);
29
30
  }
30
- } catch (err) {
31
- if (err instanceof Array) return _logger.default.error(`\n ${err.map(({
31
+ } catch (error) {
32
+ _logger.default.error(`\n ${error.diags.map(diag => new _errors.SyntaxError(diag.filepath, diag)).map(({
32
33
  message
33
34
  }) => message).join('\n ')}`);
34
- _logger.default.error(err);
35
35
  }
36
36
  }
package/lib/cli/utils.js CHANGED
@@ -9,7 +9,7 @@ exports.resolvePaths = resolvePaths;
9
9
  exports.validateInputFilePaths = validateInputFilePaths;
10
10
  var _path2 = _interopRequireDefault(require("path"));
11
11
  var _fs = _interopRequireDefault(require("fs"));
12
- var _errors = require("../errors");
12
+ var _core = require("@dbml/core");
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
  function resolvePaths(paths) {
15
15
  if (!Array.isArray(paths)) {
@@ -41,11 +41,13 @@ function generate(inputPaths, transform, outputPlugin) {
41
41
  try {
42
42
  const content = transform(source);
43
43
  outputPlugin.write(content);
44
- } catch (err) {
45
- if (Array.isArray(err)) {
46
- throw err.map(e => new _errors.SyntaxError(_path2.default.basename(_path), e));
47
- }
48
- throw new _errors.SyntaxError(_path2.default.basename(_path), err);
44
+ } catch (e) {
45
+ if (e instanceof _core.CompilerError) throw e.map(diag => ({
46
+ ...diag,
47
+ message: diag.message,
48
+ filepath: _path2.default.basename(_path)
49
+ }));
50
+ throw e;
49
51
  }
50
52
  });
51
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dbml/cli",
3
- "version": "3.4.0",
3
+ "version": "3.4.1-alpha.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "license": "Apache-2.0",
@@ -25,7 +25,7 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "@babel/cli": "^7.21.0",
28
- "@dbml/core": "^3.4.0",
28
+ "@dbml/core": "^3.4.1-alpha.0",
29
29
  "bluebird": "^3.5.5",
30
30
  "chalk": "^2.4.2",
31
31
  "commander": "^2.20.0",
@@ -53,5 +53,5 @@
53
53
  "^.+\\.js$": "babel-jest"
54
54
  }
55
55
  },
56
- "gitHead": "d46067f19bf80a245c77576106dac68bec5cbe5a"
56
+ "gitHead": "452294fcc48326294bf66a76daa418668d6ba8a9"
57
57
  }
package/src/cli/export.js CHANGED
@@ -13,6 +13,7 @@ import OutputConsolePlugin from './outputPlugins/outputConsolePlugin';
13
13
  import OutputFilePlugin from './outputPlugins/outputFilePlugin';
14
14
  import config from './config';
15
15
  import logger from '../helpers/logger';
16
+ import { SyntaxError } from '../errors';
16
17
 
17
18
  export default async function exportHandler (program) {
18
19
  try {
@@ -34,13 +35,12 @@ export default async function exportHandler (program) {
34
35
  generate(
35
36
  inputPaths,
36
37
  (dbml) => exporter.export(dbml, format),
37
- new OutputFilePlugin(resolvePaths(opts.outFile), header)
38
+ new OutputFilePlugin(resolvePaths(opts.outFile), header),
38
39
  );
39
40
 
40
41
  console.log(` ${chalk.green(figures.main.tick)} Generated SQL dump file (${config[format].name}): ${path.basename(opts.outFile)}`);
41
42
  }
42
- } catch (errors) {
43
- // TODO: handle error in case errors object is not mappable
44
- logger.error(`\n ${errors.map(({ message }) => message).join('\n ')}`);
43
+ } catch (error) {
44
+ logger.error(`\n ${error.diags.map((diag) => new SyntaxError(diag.filepath, diag)).map(({ message }) => message).join('\n ')}`);
45
45
  }
46
46
  }
package/src/cli/import.js CHANGED
@@ -13,6 +13,7 @@ import { validateFilePlugin } from './validatePlugins/validatePlugins';
13
13
  import OutputConsolePlugin from './outputPlugins/outputConsolePlugin';
14
14
  import OutputFilePlugin from './outputPlugins/outputFilePlugin';
15
15
  import logger from '../helpers/logger';
16
+ import { SyntaxError } from '../errors';
16
17
 
17
18
  export default async function importHandler (program) {
18
19
  try {
@@ -25,13 +26,11 @@ export default async function importHandler (program) {
25
26
  if (!opts.outFile && !opts.outDir) {
26
27
  generate(inputPaths, (sql) => importer.import(sql, format), OutputConsolePlugin);
27
28
  } else if (opts.outFile) {
28
- generate(inputPaths, (sql) => importer.import(sql, format),
29
- new OutputFilePlugin(resolvePaths(opts.outFile)));
29
+ generate(inputPaths, (sql) => importer.import(sql, format), new OutputFilePlugin(resolvePaths(opts.outFile)));
30
30
 
31
31
  console.log(` ${chalk.green(figures.main.tick)} Generated DBML file from SQL file (${config[format].name}): ${path.basename(opts.outFile)}`);
32
32
  }
33
- } catch (err) {
34
- if (err instanceof Array) return logger.error(`\n ${err.map(({ message }) => message).join('\n ')}`);
35
- logger.error(err);
33
+ } catch (error) {
34
+ logger.error(`\n ${error.diags.map((diag) => new SyntaxError(diag.filepath, diag)).map(({ message }) => message).join('\n ')}`);
36
35
  }
37
36
  }
package/src/cli/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import path from 'path';
2
2
  import fs from 'fs';
3
- import { SyntaxError } from '../errors';
3
+ import { CompilerError } from '@dbml/core';
4
4
 
5
5
  function resolvePaths (paths) {
6
6
  if (!Array.isArray(paths)) {
@@ -38,11 +38,9 @@ function generate (inputPaths, transform, outputPlugin) {
38
38
  try {
39
39
  const content = transform(source);
40
40
  outputPlugin.write(content);
41
- } catch (err) {
42
- if (Array.isArray(err)) {
43
- throw err.map((e) => new SyntaxError(path.basename(_path), e));
44
- }
45
- throw new SyntaxError(path.basename(_path), err);
41
+ } catch (e) {
42
+ if (e instanceof CompilerError) throw e.map((diag) => ({ ...diag, message: diag.message, filepath: path.basename(_path) }));
43
+ throw e;
46
44
  }
47
45
  });
48
46
  }
package/yarn-error.log DELETED
@@ -1,87 +0,0 @@
1
- Arguments:
2
- /usr/local/bin/node /usr/local/bin/yarn install
3
-
4
- PATH:
5
- /opt/homebrew/opt/openjdk/bin:/opt/homebrew/opt/postgresql@13/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/opt/postgresql@13/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/nguyenhoang/.cargo/bin
6
-
7
- Yarn version:
8
- 1.22.18
9
-
10
- Node version:
11
- 16.18.0
12
-
13
- Platform:
14
- darwin arm64
15
-
16
- Trace:
17
- SyntaxError: /Users/nguyenhoang/Documents/workspace/dbx/dbml/package.json: Unexpected token } in JSON at position 130
18
- at JSON.parse (<anonymous>)
19
- at /usr/local/lib/node_modules/yarn/lib/cli.js:1625:59
20
- at Generator.next (<anonymous>)
21
- at step (/usr/local/lib/node_modules/yarn/lib/cli.js:310:30)
22
- at /usr/local/lib/node_modules/yarn/lib/cli.js:321:13
23
-
24
- npm manifest:
25
- {
26
- "name": "@dbml/cli",
27
- "version": "2.5.3",
28
- "description": "",
29
- "main": "lib/index.js",
30
- "license": "Apache-2.0",
31
- "scripts": {
32
- "test": "jest",
33
- "build": "babel src --out-dir lib --copy-files",
34
- "prepublish": "npm run build"
35
- },
36
- "publishConfig": {
37
- "access": "public"
38
- },
39
- "bin": {
40
- "dbml2sql": "bin/dbml2sql.js",
41
- "sql2dbml": "bin/sql2dbml.js"
42
- },
43
- "author": "Holistics <dev@holistics.io>",
44
- "homepage": "https://dbml.dbdiagram.io",
45
- "repository": "https://github.com/holistics/dbml/tree/master/packages/dbml-cli",
46
- "keywords": [
47
- "dbml",
48
- "dbml-cli"
49
- ],
50
- "dependencies": {
51
- "@babel/cli": "^7.21.0",
52
- "@dbml/core": "^2.5.3",
53
- "bluebird": "^3.5.5",
54
- "chalk": "^2.4.2",
55
- "commander": "^2.20.0",
56
- "esm": "^3.2.25",
57
- "figures": "^3.2.0",
58
- "lodash": "^4.17.15",
59
- "pegjs-require-import": "^0.0.2",
60
- "strip-ansi": "^5.2.0",
61
- "winston": "^3.2.1"
62
- },
63
- "devDependencies": {
64
- "@babel/core": "^7.21.4",
65
- "@babel/node": "^7.20.7",
66
- "@babel/plugin-transform-runtime": "^7.21.4",
67
- "@babel/preset-env": "^7.21.4",
68
- "@babel/runtime": "^7.21.0",
69
- "babel-jest": "^29.5.0",
70
- "jest": "^29.5.0"
71
- },
72
- "jest": {
73
- "setupFiles": [
74
- "./jestHelpers.js"
75
- ],
76
- "transform": {
77
- "^.+\\.js$": "babel-jest"
78
- }
79
- },
80
- "gitHead": "5cb80e1aa38fb9a4dbe3079e39c9ef93cd4dc556"
81
- }
82
-
83
- yarn manifest:
84
- No manifest
85
-
86
- Lockfile:
87
- No lockfile