dbdocs 0.8.4 → 0.9.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.
package/bin/run CHANGED
File without changes
@@ -1 +1 @@
1
- {"version":"0.8.4","commands":{"build":{"id":"build","description":"build docs","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","description":"project name","multiple":false},"public":{"name":"public","type":"boolean","description":"anyone with the URL can access","helpGroup":"sharing","allowNo":false,"exclusive":["private","password"]},"private":{"name":"private","type":"boolean","description":"only invited people can access","helpGroup":"sharing","allowNo":false,"exclusive":["public","password"]},"password":{"name":"password","type":"option","char":"p","description":"anyone with the URL + password can access","helpGroup":"sharing","multiple":false,"exclusive":["public","private"]}},"args":[{"name":"filepath","description":"dbml file path"}]},"login":{"id":"login","description":"login to dbdocs\nlogin with your dbdocs credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"logout":{"id":"logout","description":"logout\nclears local login credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"ls":{"id":"ls","description":"list projects","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"password":{"id":"password","description":"set password for your project or remove password","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","char":"p","description":"project name","helpValue":"project name","multiple":false},"set":{"name":"set","type":"option","char":"s","description":"password for your project","helpValue":"password","multiple":false},"remove":{"name":"remove","type":"boolean","char":"r","description":"remove password from your project","allowNo":false}},"args":[]},"remove":{"id":"remove","description":"remove project","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"project_name","description":"name of the project which you want to remove"}]},"rename":{"id":"rename","description":"change your username","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"token":{"id":"token","description":"generate or revoke your authentication token","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"generate":{"name":"generate","type":"boolean","char":"g","description":"generate authentication token","allowNo":false},"revoke":{"name":"revoke","type":"boolean","char":"r","description":"revoke authentication token","allowNo":false}},"args":[]},"validate":{"id":"validate","description":"validate docs content","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"filepath","description":"dbml file path"}]}}}
1
+ {"version":"0.9.0","commands":{"build":{"id":"build","description":"build docs","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","description":"project name","multiple":false},"public":{"name":"public","type":"boolean","description":"anyone with the URL can access","helpGroup":"sharing","allowNo":false,"exclusive":["private","password"]},"private":{"name":"private","type":"boolean","description":"only invited people can access","helpGroup":"sharing","allowNo":false,"exclusive":["public","password"]},"password":{"name":"password","type":"option","char":"p","description":"anyone with the URL + password can access","helpGroup":"sharing","multiple":false,"exclusive":["public","private"]}},"args":[{"name":"filepath","description":"dbml file path"}]},"login":{"id":"login","description":"login to dbdocs\nlogin with your dbdocs credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"logout":{"id":"logout","description":"logout\nclears local login credentials\n","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"ls":{"id":"ls","description":"list projects","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"password":{"id":"password","description":"set password for your project or remove password","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"project":{"name":"project","type":"option","char":"p","description":"project name","helpValue":"project name","multiple":false},"set":{"name":"set","type":"option","char":"s","description":"password for your project","helpValue":"password","multiple":false},"remove":{"name":"remove","type":"boolean","char":"r","description":"remove password from your project","allowNo":false}},"args":[]},"remove":{"id":"remove","description":"remove project","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"project_name","description":"name of the project which you want to remove"}]},"rename":{"id":"rename","description":"change your username","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[]},"token":{"id":"token","description":"generate or revoke your authentication token","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{"generate":{"name":"generate","type":"boolean","char":"g","description":"generate authentication token","allowNo":false},"revoke":{"name":"revoke","type":"boolean","char":"r","description":"revoke authentication token","allowNo":false}},"args":[]},"validate":{"id":"validate","description":"validate docs content","strict":true,"pluginName":"dbdocs","pluginAlias":"dbdocs","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"filepath","description":"dbml file path"}]}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbdocs",
3
- "version": "0.8.4",
3
+ "version": "0.9.0",
4
4
  "author": "@holistics",
5
5
  "bin": {
6
6
  "dbdocs": "./bin/run"
@@ -9,10 +9,10 @@
9
9
  "oclif/**/ansi-regex": "^3.0.1"
10
10
  },
11
11
  "dependencies": {
12
- "@dbml/core": "^2.6.0",
12
+ "@dbml/core": "^3.2.0",
13
13
  "@oclif/core": "1.12.1",
14
14
  "@oclif/plugin-help": "5.1.12",
15
- "axios": "0.27.2",
15
+ "axios": "1.6.0",
16
16
  "chalk": "^3.0.0",
17
17
  "dotenv": "^8.2.0",
18
18
  "inquirer": "^7.0.1",
@@ -13,7 +13,9 @@ const { shouldAskForFeedback } = require('../utils/feedback');
13
13
  const { isValidName } = require('../validators/projectName');
14
14
  const parse = require('../utils/parse');
15
15
  const { PROJECT_GENERAL_ACCESS_TYPE, FLAG_HELP_GROUP } = require('../utils/constants');
16
+ const { getProjectUrl } = require('../utils/helper');
16
17
  const { getIsPublicValueFromBuildFlag } = require('../utils/helper');
18
+ const { formatParserV2ErrorMessage } = require('../utils/error-formatter');
17
19
 
18
20
  async function build (project, authConfig) {
19
21
  const res = await axios.post(`${vars.apiUrl}/projects`, project, authConfig);
@@ -61,8 +63,8 @@ class BuildCommand extends Command {
61
63
  }
62
64
  spinner.succeed('Parsing file content');
63
65
  } catch (error) {
64
- if (!error.location) throw error;
65
- const message = `You have syntax error in ${path.basename(filepath)} line ${error.location.start.line} column ${error.location.start.column}. ${error.message}`;
66
+ const rawMessage = formatParserV2ErrorMessage(error);
67
+ const message = rawMessage ? `You have syntax error(s) in ${path.basename(filepath)}\n${rawMessage}` : 'Something wrong :( Please try again.';
66
68
  throw new Error(message);
67
69
  }
68
70
 
@@ -106,7 +108,7 @@ class BuildCommand extends Command {
106
108
  default:
107
109
  break;
108
110
  }
109
- spinner.succeed(`Done. Visit: ${chalk.cyan(`${vars.hostUrl}/${newProject.org.name}/${newProject.urlName}`)}\n`);
111
+ spinner.succeed(`Done. Visit: ${chalk.cyan(getProjectUrl(vars.hostUrl, newProject.org.name, newProject.urlName))}\n`);
110
112
  if (shouldAskForFeedback()) {
111
113
  spinner.info(`Thanks for using dbdocs! We'd love to hear your feedback: ${chalk.cyan('https://form.jotform.com/200962053361448')}`);
112
114
  }
@@ -115,7 +117,7 @@ class BuildCommand extends Command {
115
117
  if (err.response) {
116
118
  const { error } = err.response.data;
117
119
  if (error.name === 'SyntaxError') {
118
- message = `You have syntax error in ${path.basename(filepath)} line ${error.location.start.line} column ${error.location.start.column}. ${error.message}`;
120
+ message = `You have syntax error(s) in ${path.basename(filepath)} line ${error.location.start.line} column ${error.location.start.column}. ${error.message}`;
119
121
  } else if (error.name === 'AccessDenied') {
120
122
  message = error.message;
121
123
  }
@@ -5,6 +5,7 @@ const verifyToken = require('../utils/verifyToken');
5
5
  const { getProjectsByOrg } = require('../utils/org');
6
6
  const { getOrg } = require('../utils/org');
7
7
  const { PROJECT_SHARING_TEXT } = require('../utils/constants');
8
+ const { getProjectUrl } = require('../utils/helper');
8
9
 
9
10
  class LsCommand extends Command {
10
11
  async run () {
@@ -15,7 +16,7 @@ class LsCommand extends Command {
15
16
  this.log(chalk.bold(org.name));
16
17
 
17
18
  const [maxUrlWidth, maxUpdatedAtWidth] = projects.reduce((accumulator, project) => {
18
- const url = `${vars.hostUrl}/${org.name}/${project.urlName}`;
19
+ const url = getProjectUrl(vars.hostUrl, org.name, project.urlName);
19
20
  const updatedAt = (new Date(project.updatedAt)).toLocaleString();
20
21
  return [
21
22
  accumulator[0] > url.length ? accumulator[0] : url.length,
@@ -33,7 +34,7 @@ class LsCommand extends Command {
33
34
  },
34
35
  url: {
35
36
  minWidth: maxUrlWidth + 2,
36
- get: (project) => chalk.cyan(`${vars.hostUrl}/${org.name}/${project.urlName}`),
37
+ get: (project) => chalk.cyan(getProjectUrl(vars.hostUrl, org.name, project.urlName)),
37
38
  },
38
39
  updatedAt: {
39
40
  minWidth: maxUpdatedAtWidth + 2,
@@ -3,6 +3,7 @@ const fs = require('fs');
3
3
  const path = require('path');
4
4
  const ora = require('ora');
5
5
  const parse = require('../utils/parse');
6
+ const { formatParserV2ErrorMessage } = require('../utils/error-formatter');
6
7
 
7
8
  class ValidateCommand extends Command {
8
9
  async run () {
@@ -21,13 +22,14 @@ class ValidateCommand extends Command {
21
22
  spinner.succeed('Validating file content');
22
23
  spinner.succeed('Done. Parse succeeded without errors.');
23
24
  } catch (error) {
24
- let message = error.message || 'Something wrong :( Please try again.';
25
- if (filepath && error.location) message = `You have syntax error in ${path.basename(filepath)} line ${error.location.start.line} column ${error.location.start.column}. ${error.message}`;
25
+ const rawMessage = formatParserV2ErrorMessage(error);
26
+ const message = rawMessage ? `You have syntax error(s) in ${path.basename(filepath)}\n${rawMessage}` : rawMessage;
27
+
26
28
  if (spinner.isSpinning) {
27
29
  spinner.fail(`Failed: ${message}`);
28
- } else {
29
- this.error(message);
30
+ return;
30
31
  }
32
+ this.error(message);
31
33
  }
32
34
  }
33
35
  }
@@ -0,0 +1,25 @@
1
+ function createSyntaxErrorMessage (line, column, msg) {
2
+ return `Syntax error at line ${line} column ${column}. ${msg}`;
3
+ }
4
+
5
+ function formatParserV2ErrorMessage (error) {
6
+ if (!Array.isArray(error)) {
7
+ if (!error.location) {
8
+ // this is a runtime error
9
+ return '';
10
+ }
11
+
12
+ return createSyntaxErrorMessage(error.location.start.line, error.location.start.column, error.message);
13
+ }
14
+
15
+ const messageList = [];
16
+ error.forEach((err) => {
17
+ messageList.push(createSyntaxErrorMessage(err.location.start.line, err.location.start.column, err.message));
18
+ });
19
+
20
+ return messageList.join('\n');
21
+ }
22
+
23
+ module.exports = {
24
+ formatParserV2ErrorMessage,
25
+ };
@@ -3,7 +3,9 @@ const getIsPublicValueFromBuildFlag = (publicFlag, privateFlag, passwordFlag) =>
3
3
  if (privateFlag) return false;
4
4
  return undefined; // 'undefined' means keep the old `isPublic` state
5
5
  };
6
+ const getProjectUrl = (hostUrl, orgName, projectUrl) => `${hostUrl}/${encodeURIComponent(orgName)}/${projectUrl}`;
6
7
 
7
8
  module.exports = {
8
9
  getIsPublicValueFromBuildFlag,
10
+ getProjectUrl,
9
11
  };
@@ -1,14 +1,14 @@
1
- const { parentPort, workerData } = require("worker_threads");
2
- const { Parser } = require("@dbml/core");
1
+ const { parentPort, workerData } = require('worker_threads');
2
+ const { Parser } = require('@dbml/core');
3
3
 
4
4
  function parse (content) {
5
- const databaseObject = Parser.parse(content, 'dbml');
6
- const schemas = databaseObject.schemas.map((schema) => {
7
- return {
8
- name: schema.name,
9
- tables: schema.tables.map((table) => table.name),
10
- };
11
- });
5
+ const parser = new Parser();
6
+ const databaseObject = parser.parse(content, 'dbmlv2');
7
+ const schemas = databaseObject.schemas.map((schema) => ({
8
+ name: schema.name,
9
+ tables: schema.tables.map((table) => table.name),
10
+ }));
11
+
12
12
  return {
13
13
  name: databaseObject.name,
14
14
  description: databaseObject.note,