dbdiagram 0.1.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 (74) hide show
  1. package/COPYRIGHT.md +3 -0
  2. package/README.md +189 -0
  3. package/dist/actions/auth/auth-login.action.js +44 -0
  4. package/dist/actions/auth/auth-logout.action.js +13 -0
  5. package/dist/actions/auth/auth-status.action.js +38 -0
  6. package/dist/actions/build/build-document.action.js +142 -0
  7. package/dist/actions/delete.action.js +67 -0
  8. package/dist/actions/init.action.js +105 -0
  9. package/dist/actions/list/list-document.action.js +130 -0
  10. package/dist/actions/list/list.action.js +103 -0
  11. package/dist/actions/pull.action.js +58 -0
  12. package/dist/actions/push.action.js +91 -0
  13. package/dist/actions/tokens/token-delete.action.js +50 -0
  14. package/dist/actions/tokens/token-generate.action.js +52 -0
  15. package/dist/actions/tokens/token-list.action.js +52 -0
  16. package/dist/assets/callback-error.html +109 -0
  17. package/dist/assets/callback-success.html +73 -0
  18. package/dist/commands/auth/auth-login.command.js +7 -0
  19. package/dist/commands/auth/auth-logout.command.js +7 -0
  20. package/dist/commands/auth/auth-status.command.js +8 -0
  21. package/dist/commands/auth/auth.command.js +16 -0
  22. package/dist/commands/build/build-document.command.js +23 -0
  23. package/dist/commands/build/build.command.js +10 -0
  24. package/dist/commands/command.loader.js +18 -0
  25. package/dist/commands/delete.command.js +12 -0
  26. package/dist/commands/init.command.js +14 -0
  27. package/dist/commands/list/list-document.command.js +11 -0
  28. package/dist/commands/list/list.command.js +15 -0
  29. package/dist/commands/pull.command.js +11 -0
  30. package/dist/commands/push.command.js +15 -0
  31. package/dist/commands/tokens/token-delete.command.js +9 -0
  32. package/dist/commands/tokens/token-generate.command.js +9 -0
  33. package/dist/commands/tokens/token-list.command.js +8 -0
  34. package/dist/commands/tokens/tokens.command.js +15 -0
  35. package/dist/config/credential-manager.js +52 -0
  36. package/dist/config/settings-manager.js +44 -0
  37. package/dist/config.js +14 -0
  38. package/dist/config.staging.js +14 -0
  39. package/dist/constants/auth-message.constant.js +1 -0
  40. package/dist/constants/document.constant.js +8 -0
  41. package/dist/constants/dot-dbdiagram-dir.constant.js +9 -0
  42. package/dist/constants/viz-read-error.constant.js +6 -0
  43. package/dist/errors/portal-api.error.js +37 -0
  44. package/dist/errors/portal-error-codes.js +23 -0
  45. package/dist/hooks/build-document.hook.js +30 -0
  46. package/dist/hooks/delete.hook.js +12 -0
  47. package/dist/hooks/global.hook.js +6 -0
  48. package/dist/hooks/list.hook.js +23 -0
  49. package/dist/hooks/pull.hook.js +15 -0
  50. package/dist/hooks/push.hook.js +19 -0
  51. package/dist/index.js +12 -0
  52. package/dist/integrations/portal/portal-http.integration.js +27 -0
  53. package/dist/integrations/portal/portal.integration.js +68 -0
  54. package/dist/libs/portal/client.js +114 -0
  55. package/dist/libs/portal/errors.js +20 -0
  56. package/dist/libs/portal/index.js +2 -0
  57. package/dist/libs/portal/server.js +70 -0
  58. package/dist/program.js +16 -0
  59. package/dist/services/dbml/dbml.service.js +30 -0
  60. package/dist/services/dbml/dbml.worker.js +40 -0
  61. package/dist/services/file.service.js +6 -0
  62. package/dist/services/viz/diagram-viz-converter.service.js +67 -0
  63. package/dist/services/viz/diagram-viz-file.service.js +43 -0
  64. package/dist/types/config.type.js +1 -0
  65. package/dist/types/diagram-viz.type.js +6 -0
  66. package/dist/types/integrations/portal.type.js +1 -0
  67. package/dist/utils/dbml.util.js +30 -0
  68. package/dist/utils/diagram-viz-error.util.js +11 -0
  69. package/dist/utils/logger.util.js +3 -0
  70. package/dist/utils/output.util.js +18 -0
  71. package/dist/utils/portal-error.util.js +18 -0
  72. package/dist/utils/table.util.js +10 -0
  73. package/dist/utils/validation.util.js +32 -0
  74. package/package.json +56 -0
@@ -0,0 +1,73 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>dbdiagram CLI - Completing Authentication</title>
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
16
+ display: flex;
17
+ align-items: center;
18
+ justify-content: center;
19
+ min-height: 100vh;
20
+ background: #f9fafb;
21
+ }
22
+
23
+ .container {
24
+ background: white;
25
+ border-radius: 6px;
26
+ border: 1px solid #eff0f3;
27
+ box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
28
+ padding: 32px;
29
+ width: 100%;
30
+ max-width: 400px;
31
+ text-align: center;
32
+ }
33
+
34
+ .logo-container {
35
+ margin-bottom: 16px;
36
+ }
37
+
38
+ .logo {
39
+ height: 48px;
40
+ }
41
+
42
+ h1 {
43
+ color: #048cff;
44
+ font-size: 24px;
45
+ font-weight: 600;
46
+ margin-bottom: 16px;
47
+ }
48
+
49
+ p {
50
+ color: #323740;
51
+ line-height: 1.6;
52
+ font-size: 14px;
53
+ }
54
+ </style>
55
+ </head>
56
+ <body>
57
+ <div class="container">
58
+ <div class="logo-container">
59
+ <svg class="logo" width="155" height="155" viewBox="0 0 155 155" fill="none" xmlns="http://www.w3.org/2000/svg">
60
+ <path d="M155 29C155 12.9837 142.016 0 126 0H29C12.9837 0 0 12.9837 0 29V126C0 142.016 12.9837 155 29 155H126C142.016 155 155 142.016 155 126V29Z" fill="#0246CC"/>
61
+ <path d="M77.5 54.6521C102.065 54.6521 121.978 47.8098 121.978 39.3694C121.978 30.929 102.065 24.0867 77.5 24.0867C52.9354 24.0867 33.0218 30.929 33.0218 39.3694C33.0218 47.8098 52.9354 54.6521 77.5 54.6521Z" fill="white"/>
62
+ <path d="M33.0399 76.4867V91.6759C33.0399 96.6868 50.3603 103.965 77.5001 103.965C104.64 103.965 121.96 96.6868 121.96 91.6759V76.4867C112.817 82.4469 95.0968 85.5314 77.5001 85.5314C59.9034 85.5314 42.1828 82.4469 33.0399 76.4867Z" fill="#287EFF"/>
63
+ <path d="M33.0399 50.5847V67.5282C33.0399 72.5391 50.3603 79.8172 77.5001 79.8172C104.64 79.8172 121.96 72.5391 121.96 67.5282V50.5847C113.453 57.1317 97.1229 61.3837 77.5001 61.3837C57.8772 61.3837 41.5476 57.1317 33.0399 50.5847Z" fill="#96C0FF"/>
64
+ <path d="M33.0399 101.065V116.254C33.0399 121.265 50.3603 128.543 77.5001 128.543C104.64 128.543 121.96 121.265 121.96 116.254V101.065C112.817 107.025 95.0968 110.11 77.5001 110.11C59.9034 110.11 42.1828 107.025 33.0399 101.065Z" fill="#0258ED"/>
65
+ </svg>
66
+ </div>
67
+
68
+ <h1>Completing Authentication</h1>
69
+
70
+ <p>You can close this window and return to your terminal to continue.</p>
71
+ </div>
72
+ </body>
73
+ </html>
@@ -0,0 +1,7 @@
1
+ import { loginAction } from '../../actions/auth/auth-login.action.js';
2
+ export function registerLoginCommand(auth) {
3
+ auth
4
+ .command('login')
5
+ .description('Log in')
6
+ .action(loginAction);
7
+ }
@@ -0,0 +1,7 @@
1
+ import { logoutAction } from '../../actions/auth/auth-logout.action.js';
2
+ export function registerLogoutCommand(auth) {
3
+ auth
4
+ .command('logout')
5
+ .description('Clear the local stored credentials and log out')
6
+ .action(logoutAction);
7
+ }
@@ -0,0 +1,8 @@
1
+ import { statusAction } from '../../actions/auth/auth-status.action.js';
2
+ export function registerStatusCommand(auth) {
3
+ auth
4
+ .command('status')
5
+ .description('Show current authentication status')
6
+ .option('--json', 'Output as JSON')
7
+ .action(statusAction);
8
+ }
@@ -0,0 +1,16 @@
1
+ import { registerLoginCommand } from './auth-login.command.js';
2
+ import { registerLogoutCommand } from './auth-logout.command.js';
3
+ import { registerStatusCommand } from './auth-status.command.js';
4
+ export function registerAuthCommand(program) {
5
+ const auth = program
6
+ .command('auth')
7
+ .description('Manage authentication')
8
+ .addHelpText('after', '\nAlternatively, set the DBDIAGRAM_TOKEN env var to authenticate with a\n' +
9
+ 'CLI token (see: dbdiagram tokens generate).')
10
+ .action(() => {
11
+ auth.help();
12
+ });
13
+ registerLoginCommand(auth);
14
+ registerLogoutCommand(auth);
15
+ registerStatusCommand(auth);
16
+ }
@@ -0,0 +1,23 @@
1
+ import { documentAction } from '../../actions/build/build-document.action.js';
2
+ import { DOCUMENT_SOURCE_TYPE } from '../../constants/document.constant.js';
3
+ import { buildDocumentPreAction } from '../../hooks/build-document.hook.js';
4
+ export function registerDocumentCommand(build) {
5
+ const cmd = build
6
+ .command('document')
7
+ .description('Publish a document to dbdocs.io from a local file or diagram')
8
+ .optionsGroup('DBML source (exactly one required):')
9
+ .option('--from-file <filepath>', 'Path to your local DBML file')
10
+ .option('--from-diagram <id>', 'The diagram ID to use as source')
11
+ .optionsGroup('Project settings:')
12
+ .option('--project <name>', 'Target project as <workspace>/<project> or just <project>')
13
+ .option('--version-name <name>', 'Version label for this publish')
14
+ .option('--json', 'Output as JSON')
15
+ .hook('preAction', buildDocumentPreAction)
16
+ .action(documentAction);
17
+ cmd.on('option:from-file', (val) => {
18
+ cmd.setOptionValue('source', { type: DOCUMENT_SOURCE_TYPE.FILE, value: val });
19
+ });
20
+ cmd.on('option:from-diagram', (val) => {
21
+ cmd.setOptionValue('source', { type: DOCUMENT_SOURCE_TYPE.DIAGRAM, value: val });
22
+ });
23
+ }
@@ -0,0 +1,10 @@
1
+ import { registerDocumentCommand } from './build-document.command.js';
2
+ export function registerBuildCommand(program) {
3
+ const build = program
4
+ .command('build')
5
+ .description('Publish documentation to dbdocs.io')
6
+ .action(() => {
7
+ build.help();
8
+ });
9
+ registerDocumentCommand(build);
10
+ }
@@ -0,0 +1,18 @@
1
+ import { registerAuthCommand } from './auth/auth.command.js';
2
+ import { registerBuildCommand } from './build/build.command.js';
3
+ import { registerPushCommand } from './push.command.js';
4
+ import { registerPullCommand } from './pull.command.js';
5
+ import { registerDeleteCommand } from './delete.command.js';
6
+ import { registerListCommand } from './list/list.command.js';
7
+ import { registerInitCommand } from './init.command.js';
8
+ import { registerTokensCommand } from './tokens/tokens.command.js';
9
+ export function load(program) {
10
+ registerInitCommand(program);
11
+ registerAuthCommand(program);
12
+ registerPushCommand(program);
13
+ registerPullCommand(program);
14
+ registerListCommand(program);
15
+ registerDeleteCommand(program);
16
+ registerBuildCommand(program);
17
+ registerTokensCommand(program);
18
+ }
@@ -0,0 +1,12 @@
1
+ import { deleteAction } from '../actions/delete.action.js';
2
+ import { deletePreAction } from '../hooks/delete.hook.js';
3
+ export function registerDeleteCommand(program) {
4
+ program
5
+ .command('delete')
6
+ .description('Delete a diagram')
7
+ .option('--diagram-id <id>', 'The diagram ID to delete')
8
+ .option('--force, -f', 'Skip confirmation and delete immediately')
9
+ .option('--json', 'Output as JSON')
10
+ .hook('preAction', deletePreAction)
11
+ .action(deleteAction);
12
+ }
@@ -0,0 +1,14 @@
1
+ import { initAction } from '../actions/init.action.js';
2
+ export function registerInitCommand(program) {
3
+ program
4
+ .command('init')
5
+ .description('Set up project settings for the current directory\n\n' +
6
+ 'Creates or updates .dbdiagram/settings.json so commands can run without repeated flags.')
7
+ .option('--entry <filepath>', 'Path to your DBML entry file')
8
+ .option('--diagram-id <id>', 'The diagram ID (from dbdiagram.io/d/<id>)')
9
+ .option('--workspace <id>', 'The workspace ID (omit for personal workspace)')
10
+ .option('--document-source <mode>', 'DBML source for build document: "file" (local entry file) or "diagram" (cloud diagram)')
11
+ .option('--workspace-url <name>', 'dbdocs workspace URL name (from dbdocs.io/<name>)')
12
+ .option('--project-url <name>', 'dbdocs project URL name (from dbdocs.io/<workspace>/<name>)')
13
+ .action(initAction);
14
+ }
@@ -0,0 +1,11 @@
1
+ import { listDocumentAction } from '../../actions/list/list-document.action.js';
2
+ import { listDocumentPreAction } from '../../hooks/list.hook.js';
3
+ export const registerListDocumentCommand = (list) => {
4
+ list
5
+ .command('document')
6
+ .description('List documents in a workspace')
7
+ .option('--workspace <name>', 'The workspace URL name to list documents from')
8
+ .option('--json', 'Output as JSON')
9
+ .hook('preAction', listDocumentPreAction)
10
+ .action(listDocumentAction);
11
+ };
@@ -0,0 +1,15 @@
1
+ import { listAction } from '../../actions/list/list.action.js';
2
+ import { listPreAction } from '../../hooks/list.hook.js';
3
+ import { registerListDocumentCommand } from './list-document.command.js';
4
+ export function registerListCommand(program) {
5
+ const list = program
6
+ .command('list')
7
+ .description('List diagrams')
8
+ .enablePositionalOptions(true)
9
+ .option('--workspace <id>', 'The workspace ID (omit for personal workspace)')
10
+ .option('--json', 'Output as JSON')
11
+ .passThroughOptions(true)
12
+ .hook('preAction', listPreAction)
13
+ .action(listAction);
14
+ registerListDocumentCommand(list);
15
+ }
@@ -0,0 +1,11 @@
1
+ import { pullAction } from '../actions/pull.action.js';
2
+ import { pullPreAction } from '../hooks/pull.hook.js';
3
+ export function registerPullCommand(program) {
4
+ program
5
+ .command('pull')
6
+ .description('Pull the DBML content of a diagram to your local machine')
7
+ .option('--diagram-id <id>', 'The diagram ID to pull from')
8
+ .option('--out-file, -o <filepath>', 'Save to a file (omit to use the configured entry file, or stdout)')
9
+ .hook('preAction', pullPreAction)
10
+ .action(pullAction);
11
+ }
@@ -0,0 +1,15 @@
1
+ import { pushAction } from '../actions/push.action.js';
2
+ import { pushPreAction } from '../hooks/push.hook.js';
3
+ export function registerPushCommand(program) {
4
+ program
5
+ .command('push')
6
+ .description('Push your local DBML to create or update a diagram')
7
+ .argument('[filepath]', 'Path to the DBML file to push')
8
+ .option('--name <name>', 'Name for the diagram')
9
+ .option('--diagram-id <id>', 'The diagram ID to update (omit to create a new diagram)')
10
+ .option('--workspace <id>', 'The workspace ID to create the diagram in (ignored when --diagram-id is set)')
11
+ .option('--new', 'Force create a new diagram, ignoring diagram.id from settings')
12
+ .option('--json', 'Output as JSON')
13
+ .hook('preAction', pushPreAction)
14
+ .action(pushAction);
15
+ }
@@ -0,0 +1,9 @@
1
+ import { tokenDeleteAction } from '../../actions/tokens/token-delete.action.js';
2
+ export function registerTokenDeleteCommand(tokens) {
3
+ tokens
4
+ .command('delete <token_id>')
5
+ .description('Delete a CLI token')
6
+ .option('--force, -f', 'Skip confirmation and delete immediately')
7
+ .option('--json', 'Output as JSON')
8
+ .action(tokenDeleteAction);
9
+ }
@@ -0,0 +1,9 @@
1
+ import { tokenGenerateAction } from '../../actions/tokens/token-generate.action.js';
2
+ export function registerTokenGenerateCommand(tokens) {
3
+ tokens
4
+ .command('generate')
5
+ .description('Generate a new CLI token')
6
+ .option('--name <name>', 'Name for your token')
7
+ .option('--json', 'Output as JSON')
8
+ .action(tokenGenerateAction);
9
+ }
@@ -0,0 +1,8 @@
1
+ import { tokenListAction } from '../../actions/tokens/token-list.action.js';
2
+ export function registerTokenListCommand(tokens) {
3
+ tokens
4
+ .command('list')
5
+ .description('List your CLI tokens')
6
+ .option('--json', 'Output as JSON')
7
+ .action(tokenListAction);
8
+ }
@@ -0,0 +1,15 @@
1
+ import { registerTokenGenerateCommand } from './token-generate.command.js';
2
+ import { registerTokenListCommand } from './token-list.command.js';
3
+ import { registerTokenDeleteCommand } from './token-delete.command.js';
4
+ export function registerTokensCommand(program) {
5
+ const tokens = program
6
+ .command('tokens')
7
+ .description('Manage your CLI tokens')
8
+ .addHelpText('after', '\nSet a token value as DBDIAGRAM_TOKEN env var to authenticate without browser login.')
9
+ .action(() => {
10
+ tokens.help();
11
+ });
12
+ registerTokenGenerateCommand(tokens);
13
+ registerTokenListCommand(tokens);
14
+ registerTokenDeleteCommand(tokens);
15
+ }
@@ -0,0 +1,52 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { DOT_DBDIAGRAM_DIR, CREDENTIALS_FILE_NAME } from '../constants/dot-dbdiagram-dir.constant.js';
5
+ let cachedCredential = null;
6
+ function readJsonSafe(filePath) {
7
+ try {
8
+ const contents = fs.readFileSync(filePath, 'utf8');
9
+ return JSON.parse(contents);
10
+ }
11
+ catch {
12
+ return null;
13
+ }
14
+ }
15
+ export function resolveCredential() {
16
+ if (process.env.DBDIAGRAM_TOKEN) {
17
+ cachedCredential = { token: process.env.DBDIAGRAM_TOKEN };
18
+ return cachedCredential;
19
+ }
20
+ const projectPath = path.join(process.cwd(), DOT_DBDIAGRAM_DIR, CREDENTIALS_FILE_NAME);
21
+ const projectCred = readJsonSafe(projectPath);
22
+ if (projectCred && typeof projectCred.token === 'string') {
23
+ cachedCredential = { token: projectCred.token };
24
+ return cachedCredential;
25
+ }
26
+ const userPath = path.join(os.homedir(), DOT_DBDIAGRAM_DIR, CREDENTIALS_FILE_NAME);
27
+ const userCred = readJsonSafe(userPath);
28
+ if (userCred && typeof userCred.token === 'string') {
29
+ cachedCredential = { token: userCred.token };
30
+ return cachedCredential;
31
+ }
32
+ cachedCredential = null;
33
+ return null;
34
+ }
35
+ export function storeCredential(token) {
36
+ const dir = path.join(os.homedir(), DOT_DBDIAGRAM_DIR);
37
+ const filePath = path.join(dir, CREDENTIALS_FILE_NAME);
38
+ fs.mkdirSync(dir, { recursive: true });
39
+ fs.writeFileSync(filePath, JSON.stringify({ token }, null, 2), { mode: 0o600 });
40
+ cachedCredential = { token };
41
+ }
42
+ export function getCredential() {
43
+ return cachedCredential;
44
+ }
45
+ export function getAccessToken() {
46
+ return cachedCredential?.token ?? null;
47
+ }
48
+ export function clearCredential() {
49
+ const filePath = path.join(os.homedir(), DOT_DBDIAGRAM_DIR, CREDENTIALS_FILE_NAME);
50
+ fs.rmSync(filePath, { force: true });
51
+ cachedCredential = null;
52
+ }
@@ -0,0 +1,44 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { DOT_DBDIAGRAM_DIR, SETTINGS_FILE_NAME } from '../constants/dot-dbdiagram-dir.constant.js';
4
+ let cachedSettings = null;
5
+ function settingsPath() {
6
+ return path.join(process.cwd(), DOT_DBDIAGRAM_DIR, SETTINGS_FILE_NAME);
7
+ }
8
+ export function settingsExists() {
9
+ return fs.existsSync(settingsPath());
10
+ }
11
+ export function defaultSettings() {
12
+ return {
13
+ dbml: { entry: '' },
14
+ diagram: { id: '', workspaceId: '' },
15
+ document: { source: 'file', workspaceUrlName: '', projectUrlName: '' },
16
+ };
17
+ }
18
+ export function readSettings() {
19
+ try {
20
+ const contents = fs.readFileSync(settingsPath(), 'utf8');
21
+ return JSON.parse(contents);
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ }
27
+ export function writeSettings(data) {
28
+ const dir = path.join(process.cwd(), DOT_DBDIAGRAM_DIR);
29
+ fs.mkdirSync(dir, { recursive: true });
30
+ fs.writeFileSync(settingsPath(), JSON.stringify(data, null, 2), 'utf8');
31
+ cachedSettings = data;
32
+ }
33
+ export function resolveSettings() {
34
+ try {
35
+ const contents = fs.readFileSync(settingsPath(), 'utf8');
36
+ cachedSettings = JSON.parse(contents);
37
+ }
38
+ catch {
39
+ cachedSettings = null;
40
+ }
41
+ }
42
+ export function getSettings() {
43
+ return cachedSettings;
44
+ }
package/dist/config.js ADDED
@@ -0,0 +1,14 @@
1
+ export const PORTAL_URLS = {
2
+ loginUrl: process.env.PORTAL_LOGIN_URL || 'https://dbdiagram.io',
3
+ apiUrl: process.env.PORTAL_API_URL || 'https://api.dbdocs.io',
4
+ };
5
+ export const PORTAL_LOGIN_CONFIGS = {
6
+ clientId: 'dbdiagram-cli',
7
+ loginTimeoutMs: 5 * 60 * 1000,
8
+ };
9
+ export const DBDIAGRAM_CONFIGS = {
10
+ baseUrl: process.env.DBDIAGRAM_BASE_URL || 'https://dbdiagram.io',
11
+ };
12
+ export const DBDOCS_CONFIGS = {
13
+ baseUrl: process.env.DBDOCS_BASE_URL || 'https://dbdocs.io',
14
+ };
@@ -0,0 +1,14 @@
1
+ export const PORTAL_URLS = {
2
+ loginUrl: process.env.PORTAL_LOGIN_URL || 'https://staging.dbdiagram.io',
3
+ apiUrl: process.env.PORTAL_API_URL || 'https://staging-api.dbdocs.io',
4
+ };
5
+ export const PORTAL_LOGIN_CONFIGS = {
6
+ clientId: 'dbdiagram-cli',
7
+ loginTimeoutMs: 5 * 60 * 1000,
8
+ };
9
+ export const DBDIAGRAM_CONFIGS = {
10
+ baseUrl: process.env.DBDIAGRAM_BASE_URL || 'https://staging.dbdiagram.io',
11
+ };
12
+ export const DBDOCS_CONFIGS = {
13
+ baseUrl: process.env.DBDOCS_BASE_URL || 'https://staging.dbdocs.io',
14
+ };
@@ -0,0 +1 @@
1
+ export const NOT_LOGGED_IN_MESSAGE = 'Not logged in. Run `dbdiagram auth login`, or set DBDIAGRAM_TOKEN, to authenticate.';
@@ -0,0 +1,8 @@
1
+ export const DOCUMENT_SOURCE_TYPE = {
2
+ FILE: 'file',
3
+ DIAGRAM: 'diagram',
4
+ };
5
+ export const PROJECT_URL_NAME_PATTERN = /^[A-Za-z0-9_\-@.\s]+$/;
6
+ export const WORKSPACE_URL_NAME_PATTERN = /^[A-Za-z0-9_\-@.\s]+$/;
7
+ export const URL_NAME_MAX_LENGTH = 255;
8
+ export const VERSION_NAME_MAX_LENGTH = 255;
@@ -0,0 +1,9 @@
1
+ export const DOT_DBDIAGRAM_DIR = '.dbdiagram';
2
+ export const CREDENTIALS_FILE_NAME = '.credentials.json';
3
+ export const SETTINGS_FILE_NAME = 'settings.json';
4
+ export const DBML_EXTENSION = '.dbml';
5
+ export const DIAGRAM_VIZ_EXTENSION = '.dbdiagram';
6
+ export const DIAGRAM_VIZ_FILE_VERSIONS = {
7
+ v1: '1.0.0',
8
+ v2: '2.0.0',
9
+ };
@@ -0,0 +1,6 @@
1
+ export const DIAGRAM_VIZ_READ_ERROR = {
2
+ file_not_found: 'file_not_found',
3
+ read_error: 'read_error',
4
+ invalid_json: 'invalid_json',
5
+ unknown_version: 'unknown_version',
6
+ };
@@ -0,0 +1,37 @@
1
+ export const PORTAL_API_ERROR_TYPE = {
2
+ response: 'response',
3
+ request: 'request',
4
+ unexpected: 'unexpected',
5
+ };
6
+ export class PortalApiError extends Error {
7
+ code;
8
+ errorCode;
9
+ data;
10
+ type;
11
+ constructor(message, code, errorCode, data, type) {
12
+ super(message);
13
+ this.code = code;
14
+ this.errorCode = errorCode;
15
+ this.data = data;
16
+ this.type = type;
17
+ this.name = 'PortalApiError';
18
+ }
19
+ static fromAxios(error) {
20
+ if (error.response) {
21
+ const message = error.response.data?.message ?? error.message;
22
+ const errorCode = error.response.data?.errorCode ?? 'unexpected_response_error';
23
+ return new PortalApiError(message, error.response.status, errorCode, error.response.data, PORTAL_API_ERROR_TYPE.response);
24
+ }
25
+ if (error.request) {
26
+ let message;
27
+ if (error.cause instanceof AggregateError && error.cause.errors.length > 0) {
28
+ message = error.cause.errors[0]?.message ?? error.message ?? 'Network error';
29
+ }
30
+ else {
31
+ message = error.message || 'Network error';
32
+ }
33
+ return new PortalApiError(message, null, 'unexpected_request_error', null, PORTAL_API_ERROR_TYPE.request);
34
+ }
35
+ return new PortalApiError(error.message, null, 'unexpected_error', null, PORTAL_API_ERROR_TYPE.unexpected);
36
+ }
37
+ }
@@ -0,0 +1,23 @@
1
+ export const DIAGRAM_NOT_FOUND = 'diagram_not_found';
2
+ export const DIAGRAM_PERMISSION_DENIED_VIEW = 'diagram_permission_denied_view';
3
+ export const DIAGRAM_PERMISSION_DENIED_EDIT = 'diagram_permission_denied_edit';
4
+ export const DIAGRAM_PERMISSION_DENIED_DELETE = 'diagram_permission_denied_delete';
5
+ export const DIAGRAM_LIMIT_EXCEEDED = 'diagram_limit_exceeded';
6
+ export const WORKSPACE_NOT_FOUND = 'workspace_not_found';
7
+ export const WORKSPACE_PERMISSION_DENIED_VIEW = 'workspace_permission_denied_view';
8
+ export const TOKEN_NOT_FOUND = 'token_not_found';
9
+ export const TOKEN_LIMIT_EXCEEDED = 'token_limit_exceeded';
10
+ export const VALIDATION_INVALID_PAYLOAD = 'validation_invalid_payload';
11
+ export const INTERNAL_SERVER_ERROR = 'internal_server_error';
12
+ export const PORTAL_ERROR_MESSAGES = {
13
+ [DIAGRAM_NOT_FOUND]: 'Diagram not found.',
14
+ [DIAGRAM_PERMISSION_DENIED_VIEW]: 'You do not have access to this diagram.',
15
+ [DIAGRAM_PERMISSION_DENIED_EDIT]: 'You do not have edit permission on this diagram.',
16
+ [DIAGRAM_PERMISSION_DENIED_DELETE]: 'You do not have permission to delete this diagram.',
17
+ [DIAGRAM_LIMIT_EXCEEDED]: 'Diagram limit exceeded for your current plan.',
18
+ [WORKSPACE_NOT_FOUND]: 'Workspace not found.',
19
+ [WORKSPACE_PERMISSION_DENIED_VIEW]: 'You do not have access to this workspace.',
20
+ [TOKEN_NOT_FOUND]: 'Token not found.',
21
+ [TOKEN_LIMIT_EXCEEDED]: 'Token limit reached. Delete an existing token before creating a new one.',
22
+ [INTERNAL_SERVER_ERROR]: 'An internal server error occurred. Please try again later.',
23
+ };
@@ -0,0 +1,30 @@
1
+ import { getSettings } from '../config/settings-manager.js';
2
+ import { DOCUMENT_SOURCE_TYPE } from '../constants/document.constant.js';
3
+ export function resolveBuildDocumentFlags(cmd, settings) {
4
+ if (cmd.getOptionValue('source') == null && settings.dbml?.entry) {
5
+ cmd.setOptionValue('source', { type: DOCUMENT_SOURCE_TYPE.FILE, value: settings.dbml.entry });
6
+ }
7
+ const projectFlag = cmd.getOptionValue('project');
8
+ if (projectFlag != null) {
9
+ const slashIndex = projectFlag.indexOf('/');
10
+ if (slashIndex >= 0) {
11
+ cmd.setOptionValue('workspaceUrlName', projectFlag.slice(0, slashIndex));
12
+ cmd.setOptionValue('projectUrlOrName', projectFlag.slice(slashIndex + 1));
13
+ }
14
+ else {
15
+ cmd.setOptionValue('projectUrlOrName', projectFlag);
16
+ }
17
+ }
18
+ if (cmd.getOptionValue('workspaceUrlName') == null && settings.document?.workspaceUrlName) {
19
+ cmd.setOptionValue('workspaceUrlName', settings.document.workspaceUrlName);
20
+ }
21
+ if (cmd.getOptionValue('projectUrlOrName') == null && settings.document?.projectUrlName) {
22
+ cmd.setOptionValue('projectUrlOrName', settings.document.projectUrlName);
23
+ }
24
+ }
25
+ export function buildDocumentPreAction(thisCommand) {
26
+ const settings = getSettings();
27
+ if (!settings)
28
+ return;
29
+ resolveBuildDocumentFlags(thisCommand, settings);
30
+ }
@@ -0,0 +1,12 @@
1
+ import { getSettings } from '../config/settings-manager.js';
2
+ export function resolveDeleteFlags(cmd, settings) {
3
+ if (cmd.getOptionValue('diagramId') == null && settings.diagram?.id) {
4
+ cmd.setOptionValue('diagramId', settings.diagram.id);
5
+ }
6
+ }
7
+ export function deletePreAction(thisCommand) {
8
+ const settings = getSettings();
9
+ if (!settings)
10
+ return;
11
+ resolveDeleteFlags(thisCommand, settings);
12
+ }
@@ -0,0 +1,6 @@
1
+ import { resolveCredential } from '../config/credential-manager.js';
2
+ import { resolveSettings } from '../config/settings-manager.js';
3
+ export function globalPreAction(_thisCommand, _actionCommand) {
4
+ resolveCredential();
5
+ resolveSettings();
6
+ }
@@ -0,0 +1,23 @@
1
+ import { getSettings } from '../config/settings-manager.js';
2
+ export function resolveListFlags(cmd, settings) {
3
+ if (cmd.getOptionValue('workspace') == null && settings.diagram?.workspaceId) {
4
+ cmd.setOptionValue('workspace', settings.diagram.workspaceId);
5
+ }
6
+ }
7
+ export function resolveListDocumentFlags(cmd, settings) {
8
+ if (cmd.getOptionValue('workspace') == null && settings.document?.workspaceUrlName) {
9
+ cmd.setOptionValue('workspace', settings.document.workspaceUrlName);
10
+ }
11
+ }
12
+ export function listPreAction(thisCommand) {
13
+ const settings = getSettings();
14
+ if (!settings)
15
+ return;
16
+ resolveListFlags(thisCommand, settings);
17
+ }
18
+ export function listDocumentPreAction(thisCommand) {
19
+ const settings = getSettings();
20
+ if (!settings)
21
+ return;
22
+ resolveListDocumentFlags(thisCommand, settings);
23
+ }
@@ -0,0 +1,15 @@
1
+ import { getSettings } from '../config/settings-manager.js';
2
+ export function resolvePullFlags(cmd, settings) {
3
+ if (cmd.getOptionValue('diagramId') == null && settings.diagram?.id) {
4
+ cmd.setOptionValue('diagramId', settings.diagram.id);
5
+ }
6
+ if (cmd.getOptionValue('outFile') == null && settings.dbml?.entry) {
7
+ cmd.setOptionValue('outFile', settings.dbml.entry);
8
+ }
9
+ }
10
+ export function pullPreAction(thisCommand) {
11
+ const settings = getSettings();
12
+ if (!settings)
13
+ return;
14
+ resolvePullFlags(thisCommand, settings);
15
+ }
@@ -0,0 +1,19 @@
1
+ import { getSettings } from '../config/settings-manager.js';
2
+ export function resolvePushArgsFlags(cmd, settings) {
3
+ if (!cmd.args[0] && settings.dbml?.entry) {
4
+ cmd.args[0] = settings.dbml.entry;
5
+ }
6
+ const isNewDiagram = cmd.getOptionValue('new');
7
+ if (!isNewDiagram && cmd.getOptionValue('diagramId') == null && settings.diagram?.id) {
8
+ cmd.setOptionValue('diagramId', settings.diagram.id);
9
+ }
10
+ if (cmd.getOptionValue('workspace') == null && settings.diagram?.workspaceId) {
11
+ cmd.setOptionValue('workspace', settings.diagram.workspaceId);
12
+ }
13
+ }
14
+ export function pushPreAction(thisCommand) {
15
+ const settings = getSettings();
16
+ if (!settings)
17
+ return;
18
+ resolvePushArgsFlags(thisCommand, settings);
19
+ }