dbdocs 0.7.5 → 0.8.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/README.md CHANGED
@@ -122,7 +122,7 @@ OPTIONS
122
122
 
123
123
  ## `dbdocs remove [PROJECT_NAME]`
124
124
 
125
- remove docs
125
+ remove project
126
126
 
127
127
  ```
128
128
  USAGE
@@ -1 +1 @@
1
- {"version":"0.7.5","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},"password":{"name":"password","type":"option","char":"p","description":"password for project","multiple":false}},"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 docs","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.8.1","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.7.5",
3
+ "version": "0.8.1",
4
4
  "author": "@holistics",
5
5
  "bin": {
6
6
  "dbdocs": "./bin/run"
@@ -19,7 +19,7 @@
19
19
  "netrc-parser": "^3.1.6",
20
20
  "open": "^7.0.0",
21
21
  "ora": "^4.0.3",
22
- "update-notifier": "^4.1.0"
22
+ "update-notifier": "^6.0.2"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@oclif/test": "2.1.1",
@@ -44,8 +44,12 @@
44
44
  "license": "MIT",
45
45
  "main": "src/index.js",
46
46
  "oclif": {
47
- "additionalHelpFlags": ["help"],
48
- "additionalVersionFlags": ["version"],
47
+ "additionalHelpFlags": [
48
+ "help"
49
+ ],
50
+ "additionalVersionFlags": [
51
+ "version"
52
+ ],
49
53
  "commands": "./src/commands",
50
54
  "bin": "dbdocs",
51
55
  "plugins": [
@@ -11,6 +11,8 @@ const { getOrg } = require('../utils/org');
11
11
  const { shouldAskForFeedback } = require('../utils/feedback');
12
12
  const { isValidName } = require('../validators/projectName');
13
13
  const parse = require('../utils/parse');
14
+ const { PROJECT_GENERAL_ACCESS_TYPE, FLAG_HELP_GROUP } = require('../utils/constants');
15
+ const { getIsPublicValueFromBuildFlag } = require('../utils/helper');
14
16
 
15
17
  async function build (project, authConfig) {
16
18
  const res = await axios.post(`${vars.apiUrl}/projects`, project, authConfig);
@@ -36,9 +38,9 @@ class BuildCommand extends Command {
36
38
 
37
39
  try {
38
40
  const authConfig = await verifyToken();
39
-
40
- let { flags: { project, password } } = await this.parse(BuildCommand);
41
- const { args } = await this.parse(BuildCommand);
41
+ const { flags, args } = await this.parse(BuildCommand);
42
+ const { public: publicFlag, private: privateFlag, password } = flags;
43
+ let { project } = flags;
42
44
 
43
45
  const { filepath } = args;
44
46
  let content = '';
@@ -70,6 +72,7 @@ class BuildCommand extends Command {
70
72
 
71
73
  while (!isValidName(project)) {
72
74
  spinner.warn('Invalid project name! Project name can only contain only alphabets, numbers, space, "-" or "_" and can not be blanked!');
75
+ // eslint-disable-next-line no-await-in-loop
73
76
  project = await enterProjectName();
74
77
  }
75
78
 
@@ -77,8 +80,10 @@ class BuildCommand extends Command {
77
80
  spinner.text = `Pushing new database to project ${project}`;
78
81
  spinner.start();
79
82
  try {
80
- const { newProject, isCreated } = await build({
83
+ const isPublic = getIsPublicValueFromBuildFlag(publicFlag, privateFlag, password);
84
+ const { newProject } = await build({
81
85
  projectName: project,
86
+ isPublic,
82
87
  password,
83
88
  orgName: org,
84
89
  doc: {
@@ -86,12 +91,18 @@ class BuildCommand extends Command {
86
91
  },
87
92
  shallowSchema: model.schemas,
88
93
  }, authConfig);
89
- if (!newProject.isPublic) {
90
- if (isCreated || password) {
91
- spinner.succeed(`Password is set for '${newProject.name}'`);
92
- }
93
- } else {
94
- spinner.warn(`Password is not set for '${newProject.name}'`);
94
+ switch (newProject.generalAccessType) {
95
+ case PROJECT_GENERAL_ACCESS_TYPE.public:
96
+ spinner.warn(`Project '${newProject.name}' is public, consider setting password or restricting access to it`);
97
+ break;
98
+ case PROJECT_GENERAL_ACCESS_TYPE.protected:
99
+ spinner.succeed(`Project '${newProject.name}' is protected with password`);
100
+ break;
101
+ case PROJECT_GENERAL_ACCESS_TYPE.restricted:
102
+ spinner.succeed(`Project '${newProject.name}' is private`);
103
+ break;
104
+ default:
105
+ break;
95
106
  }
96
107
  spinner.succeed(`Done. Visit: ${chalk.cyan(`${vars.hostUrl}/${newProject.org.name}/${newProject.urlName}`)}\n`);
97
108
  if (shouldAskForFeedback()) {
@@ -136,9 +147,20 @@ class BuildCommand extends Command {
136
147
 
137
148
  BuildCommand.description = 'build docs';
138
149
 
150
+ // `public`, `private` and `password` are mutually exclusive flags. For example:
151
+ // dbdocs build ./abc.dbml --project abc --public # works
152
+ // dbdocs build ./abc.dbml --project abc --private # works
153
+ // dbdocs build ./abc.dbml --project abc --password 123456 # works
154
+ // dbdocs build ./abc.dbml --project abc --password 123456 --private # error
155
+ // dbdocs build ./abc.dbml --project abc --public --private # error
156
+ // dbdocs build ./abc.dbml --project abc --public --password 123456 # error
139
157
  BuildCommand.flags = {
140
158
  project: Flags.string({ description: 'project name' }),
141
- password: Flags.string({ char: 'p', description: 'password for project' }),
159
+ public: Flags.boolean({ description: 'anyone with the URL can access', helpGroup: FLAG_HELP_GROUP.sharing, exclusive: ['private', 'password'] }),
160
+ private: Flags.boolean({ description: 'only invited people can access', helpGroup: FLAG_HELP_GROUP.sharing, exclusive: ['public', 'password'] }),
161
+ password: Flags.string({
162
+ char: 'p', description: 'anyone with the URL + password can access', helpGroup: FLAG_HELP_GROUP.sharing, exclusive: ['public', 'private'],
163
+ }),
142
164
  };
143
165
 
144
166
  BuildCommand.args = [
@@ -4,6 +4,7 @@ const { vars } = require('../vars');
4
4
  const verifyToken = require('../utils/verifyToken');
5
5
  const { getProjectsByOrg } = require('../utils/org');
6
6
  const { getOrg } = require('../utils/org');
7
+ const { PROJECT_SHARING_TEXT } = require('../utils/constants');
7
8
 
8
9
  class LsCommand extends Command {
9
10
  async run () {
@@ -26,11 +27,9 @@ class LsCommand extends Command {
26
27
  name: {
27
28
  minWidth: 20,
28
29
  },
29
- isPublic: {
30
- minWidth: 12,
31
- header: 'Password',
32
- // eslint-disable-next-line no-confusing-arrow
33
- get: (project) => project.isPublic ? 'No' : 'Yes',
30
+ sharing: {
31
+ minWidth: 23,
32
+ get: (project) => PROJECT_SHARING_TEXT[project.generalAccessType],
34
33
  },
35
34
  url: {
36
35
  minWidth: maxUrlWidth + 2,
@@ -67,7 +67,7 @@ class RemoveCommand extends Command {
67
67
  }
68
68
  }
69
69
 
70
- RemoveCommand.description = 'remove docs';
70
+ RemoveCommand.description = 'remove project';
71
71
 
72
72
  RemoveCommand.args = [
73
73
  { name: 'project_name', description: 'name of the project which you want to remove' },
@@ -1,6 +1,12 @@
1
- const updateNotifier = require('update-notifier');
2
1
  const pkg = require('../../../package.json');
3
2
 
4
3
  module.exports = async function () {
5
- updateNotifier({ pkg }).notify({ isGlobal: true });
4
+ // update-notifier v6.x is pure ESM, can not use require() to load it,
5
+ // see: https://github.com/yeoman/update-notifier/releases/tag/v6.0.0
6
+ const updateNotifier = (await import('update-notifier')).default;
7
+ const notifier = updateNotifier({ pkg });
8
+
9
+ notifier.notify({ isGlobal: true });
10
+ // uncomment to check the update information
11
+ // console.log(await notifier.fetchInfo());
6
12
  };
@@ -0,0 +1,21 @@
1
+ const PROJECT_GENERAL_ACCESS_TYPE = {
2
+ public: 'public',
3
+ protected: 'protected',
4
+ restricted: 'restricted',
5
+ };
6
+
7
+ const PROJECT_SHARING_TEXT = {
8
+ public: 'Shared URL',
9
+ protected: 'Shared URL & password',
10
+ restricted: 'Only invited',
11
+ };
12
+
13
+ const FLAG_HELP_GROUP = {
14
+ sharing: 'sharing',
15
+ };
16
+
17
+ module.exports = {
18
+ PROJECT_GENERAL_ACCESS_TYPE,
19
+ PROJECT_SHARING_TEXT,
20
+ FLAG_HELP_GROUP,
21
+ };
@@ -0,0 +1,9 @@
1
+ const getIsPublicValueFromBuildFlag = (publicFlag, privateFlag, passwordFlag) => {
2
+ if (publicFlag || passwordFlag) return true;
3
+ if (privateFlag) return false;
4
+ return undefined; // 'undefined' means keep the old `isPublic` state
5
+ };
6
+
7
+ module.exports = {
8
+ getIsPublicValueFromBuildFlag,
9
+ };