dbdiagram 0.4.0 → 0.5.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/README.md
CHANGED
|
@@ -55,6 +55,21 @@ dbdiagram init --entry schema.dbml --workspace-url myteam --project-url myteam/m
|
|
|
55
55
|
|
|
56
56
|
---
|
|
57
57
|
|
|
58
|
+
### Validate
|
|
59
|
+
|
|
60
|
+
Validate a local DBML file and report errors, warnings, and infos.
|
|
61
|
+
|
|
62
|
+
**Options:**
|
|
63
|
+
|
|
64
|
+
- `--json` — Output result as JSON
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
dbdiagram validate schema.dbml # validate a local DBML file
|
|
68
|
+
dbdiagram validate schema.dbml --json # output the result as JSON
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
58
73
|
### Push
|
|
59
74
|
|
|
60
75
|
Push a local DBML file to create or update a diagram on dbdiagram.io.
|
|
@@ -6,5 +6,7 @@ export const DIAGRAM_VIZ_EXTENSION = '.dbdiagram';
|
|
|
6
6
|
export const DIAGRAM_VIZ_FILE_VERSIONS = {
|
|
7
7
|
v1: '1.0.0',
|
|
8
8
|
v2: '2.0.0',
|
|
9
|
+
v3: '3.0.0',
|
|
9
10
|
};
|
|
11
|
+
export const LATEST_DIAGRAM_VIZ_FILE_VERSION = DIAGRAM_VIZ_FILE_VERSIONS.v3;
|
|
10
12
|
export const TELEMETRY_FILE_NAME = 'telemetry.json';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DIAGRAM_VIZ_FILE_VERSIONS } from '../../constants/dot-dbdiagram-dir.constant.js';
|
|
2
|
+
import { DEFAULT_DETAIL_LEVEL, DEFAULT_RELATIONSHIP_MODE, DetailLevel, RelationshipMode, } from '../../types/diagram-viz.type.js';
|
|
2
3
|
export const migrateDiagramVizV1ToV2 = (v1) => {
|
|
3
4
|
return {
|
|
4
5
|
version: DIAGRAM_VIZ_FILE_VERSIONS.v2,
|
|
@@ -15,6 +16,38 @@ export const migrateDiagramVizV1ToV2 = (v1) => {
|
|
|
15
16
|
views: {},
|
|
16
17
|
};
|
|
17
18
|
};
|
|
19
|
+
export const migrateDiagramVizV2ToV3 = (v2) => {
|
|
20
|
+
const withRelationshipMode = (view) => ({
|
|
21
|
+
...view,
|
|
22
|
+
relationshipMode: DEFAULT_RELATIONSHIP_MODE,
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
...v2,
|
|
26
|
+
version: DIAGRAM_VIZ_FILE_VERSIONS.v3,
|
|
27
|
+
defaultView: withRelationshipMode(v2.defaultView),
|
|
28
|
+
views: Object.fromEntries(Object.entries(v2.views).map(([name, view]) => [name, withRelationshipMode(view)])),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const DIAGRAM_VIZ_MIGRATIONS = [
|
|
32
|
+
{ from: DIAGRAM_VIZ_FILE_VERSIONS.v1, run: (d) => migrateDiagramVizV1ToV2(d) },
|
|
33
|
+
{ from: DIAGRAM_VIZ_FILE_VERSIONS.v2, run: (d) => migrateDiagramVizV2ToV3(d) },
|
|
34
|
+
];
|
|
35
|
+
export const migrateDiagramVizToLatest = (vizDataFromFile, fileVersion) => {
|
|
36
|
+
const startIndex = DIAGRAM_VIZ_MIGRATIONS.findIndex((migration) => migration.from === fileVersion);
|
|
37
|
+
if (startIndex === -1)
|
|
38
|
+
return null;
|
|
39
|
+
let vizData = vizDataFromFile;
|
|
40
|
+
for (const migration of DIAGRAM_VIZ_MIGRATIONS.slice(startIndex)) {
|
|
41
|
+
vizData = migration.run(vizData);
|
|
42
|
+
}
|
|
43
|
+
return vizData;
|
|
44
|
+
};
|
|
45
|
+
const toDetailLevel = (value) => (Object.values(DetailLevel).includes(value)
|
|
46
|
+
? value
|
|
47
|
+
: DEFAULT_DETAIL_LEVEL);
|
|
48
|
+
const toRelationshipMode = (value) => (Object.values(RelationshipMode).includes(value)
|
|
49
|
+
? value
|
|
50
|
+
: DEFAULT_RELATIONSHIP_MODE);
|
|
18
51
|
export const toServerFormat = (state, diagramViews) => {
|
|
19
52
|
const { defaultView, views } = state;
|
|
20
53
|
const viewEntitiesMap = new Map(diagramViews?.map((v) => [v.name, v.visibleEntities]));
|
|
@@ -23,11 +56,13 @@ export const toServerFormat = (state, diagramViews) => {
|
|
|
23
56
|
referencePaths: defaultView.referencePaths,
|
|
24
57
|
stickyNoteLayouts: defaultView.stickyNoteLayouts,
|
|
25
58
|
tableGroups: defaultView.tableGroupCollapseStates,
|
|
26
|
-
detailLevel: defaultView.detailLevel,
|
|
59
|
+
detailLevel: toDetailLevel(defaultView.detailLevel),
|
|
60
|
+
relationshipMode: toRelationshipMode(defaultView.relationshipMode),
|
|
27
61
|
visibleEntities: viewEntitiesMap.get('Default'),
|
|
28
62
|
views: Object.entries(views).map(([name, view]) => ({
|
|
29
63
|
name,
|
|
30
|
-
detailLevel: view.detailLevel,
|
|
64
|
+
detailLevel: toDetailLevel(view.detailLevel),
|
|
65
|
+
relationshipMode: toRelationshipMode(view.relationshipMode),
|
|
31
66
|
tablePositions: view.tablePositions,
|
|
32
67
|
tableGroupCollapsedStates: view.tableGroupCollapseStates,
|
|
33
68
|
stickyNoteLayouts: view.stickyNoteLayouts,
|
|
@@ -38,7 +73,8 @@ export const toServerFormat = (state, diagramViews) => {
|
|
|
38
73
|
};
|
|
39
74
|
const viewFromServer = (view) => {
|
|
40
75
|
return {
|
|
41
|
-
detailLevel: (view.detailLevel
|
|
76
|
+
detailLevel: toDetailLevel(view.detailLevel),
|
|
77
|
+
relationshipMode: toRelationshipMode(view.relationshipMode),
|
|
42
78
|
tablePositions: view.tablePositions ?? [],
|
|
43
79
|
tableGroupCollapseStates: view.tableGroupCollapsedStates ?? [],
|
|
44
80
|
stickyNoteLayouts: view.stickyNoteLayouts ?? [],
|
|
@@ -51,12 +87,13 @@ export const fromServerFormat = (serverData, existing) => {
|
|
|
51
87
|
views[view.name] = viewFromServer(view);
|
|
52
88
|
}
|
|
53
89
|
return {
|
|
54
|
-
version: DIAGRAM_VIZ_FILE_VERSIONS.
|
|
90
|
+
version: DIAGRAM_VIZ_FILE_VERSIONS.v3,
|
|
55
91
|
darkMode: existing?.darkMode ?? true,
|
|
56
92
|
gridEnabling: existing?.gridEnabling ?? false,
|
|
57
93
|
currentViewName: existing?.currentViewName ?? null,
|
|
58
94
|
defaultView: {
|
|
59
|
-
detailLevel: serverData.detailLevel,
|
|
95
|
+
detailLevel: toDetailLevel(serverData.detailLevel),
|
|
96
|
+
relationshipMode: toRelationshipMode(serverData.relationshipMode),
|
|
60
97
|
tablePositions: serverData.diagram.tables,
|
|
61
98
|
tableGroupCollapseStates: serverData.tableGroups,
|
|
62
99
|
stickyNoteLayouts: serverData.stickyNoteLayouts,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { writeFileWithDir } from '../file.service.js';
|
|
3
|
-
import { DBML_EXTENSION, DIAGRAM_VIZ_EXTENSION, DIAGRAM_VIZ_FILE_VERSIONS, } from '../../constants/dot-dbdiagram-dir.constant.js';
|
|
3
|
+
import { DBML_EXTENSION, DIAGRAM_VIZ_EXTENSION, DIAGRAM_VIZ_FILE_VERSIONS, LATEST_DIAGRAM_VIZ_FILE_VERSION, } from '../../constants/dot-dbdiagram-dir.constant.js';
|
|
4
4
|
import { DIAGRAM_VIZ_READ_ERROR } from '../../constants/viz-read-error.constant.js';
|
|
5
|
-
import {
|
|
5
|
+
import { migrateDiagramVizToLatest } from './diagram-viz-converter.service.js';
|
|
6
6
|
export const deriveDiagramVizPathFromDBML = (dbmlFilePath) => {
|
|
7
7
|
const base = dbmlFilePath.endsWith(DBML_EXTENSION)
|
|
8
8
|
? dbmlFilePath.slice(0, -DBML_EXTENSION.length)
|
|
@@ -28,15 +28,16 @@ export const readDiagramVizFile = async (vizPath) => {
|
|
|
28
28
|
return { ok: false, errorCode: DIAGRAM_VIZ_READ_ERROR.invalid_json };
|
|
29
29
|
}
|
|
30
30
|
const { version } = parsed;
|
|
31
|
-
|
|
31
|
+
const fileVersion = version ?? DIAGRAM_VIZ_FILE_VERSIONS.v1;
|
|
32
|
+
if (fileVersion === LATEST_DIAGRAM_VIZ_FILE_VERSION) {
|
|
32
33
|
return { ok: true, state: parsed };
|
|
33
34
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return { ok: true, state: migrated };
|
|
35
|
+
const migrated = migrateDiagramVizToLatest(parsed, fileVersion);
|
|
36
|
+
if (!migrated) {
|
|
37
|
+
return { ok: false, errorCode: DIAGRAM_VIZ_READ_ERROR.unknown_version };
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
await writeDiagramVizFile(vizPath, migrated);
|
|
40
|
+
return { ok: true, state: migrated };
|
|
40
41
|
};
|
|
41
42
|
export const writeDiagramVizFile = async (vizPath, state) => {
|
|
42
43
|
await writeFileWithDir(vizPath, JSON.stringify(state, null, 2));
|
|
@@ -4,3 +4,11 @@ export var DetailLevel;
|
|
|
4
4
|
DetailLevel["Keys"] = "Keys";
|
|
5
5
|
DetailLevel["All"] = "All";
|
|
6
6
|
})(DetailLevel || (DetailLevel = {}));
|
|
7
|
+
export const DEFAULT_DETAIL_LEVEL = DetailLevel.All;
|
|
8
|
+
export var RelationshipMode;
|
|
9
|
+
(function (RelationshipMode) {
|
|
10
|
+
RelationshipMode["Relationship"] = "Relationship";
|
|
11
|
+
RelationshipMode["Dependency"] = "Dependency";
|
|
12
|
+
RelationshipMode["All"] = "All";
|
|
13
|
+
})(RelationshipMode || (RelationshipMode = {}));
|
|
14
|
+
export const DEFAULT_RELATIONSHIP_MODE = RelationshipMode.All;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbdiagram",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"dbdiagram": "dist/index.js"
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@clack/prompts": "^1.4.0",
|
|
33
|
-
"@dbml/core": "
|
|
33
|
+
"@dbml/core": "10.1.1",
|
|
34
34
|
"@snowplow/node-tracker": "^4.9.0",
|
|
35
35
|
"axios": "^1.19.0",
|
|
36
36
|
"ci-info": "^4.4.0",
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"vitest": "^4.1.0"
|
|
61
61
|
},
|
|
62
62
|
"resolutions": {
|
|
63
|
-
"undici": "6.
|
|
63
|
+
"undici": "6.28.0"
|
|
64
64
|
}
|
|
65
65
|
}
|