@antelopejs/dms-database 0.2.3 → 0.3.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 +4 -4
- package/dist/frontend-module.d.ts +2 -0
- package/dist/frontend-module.js +17 -0
- package/dist/frontend-module.js.map +1 -0
- package/dist/index.js +2 -11
- package/dist/index.js.map +1 -1
- package/dist/pages/overview.d.ts +0 -1
- package/dist/pages/overview.js +0 -14
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/schemas.js +3 -0
- package/dist/pages/schemas.js.map +1 -1
- package/frontend-vue/app/build/composables/useDatabaseHealth.ts +11 -7
- package/frontend-vue/app/build/composables/useDatabaseSchemas.ts +8 -1
- package/frontend-vue/app/build/data/cellValues.ts +50 -0
- package/frontend-vue/app/build/diagram/graph.ts +211 -47
- package/frontend-vue/app/build/diagram/packing.ts +283 -0
- package/frontend-vue/app/build/utils/fieldTypes.ts +16 -1
- package/frontend-vue/app/components/ConnectionStatus.vue +5 -1
- package/frontend-vue/app/components/DataBrowser.vue +2 -2
- package/frontend-vue/app/components/DataBrowserSidebar.vue +1 -1
- package/frontend-vue/app/components/DataGrid.vue +44 -34
- package/frontend-vue/app/components/DiagramTableNode.vue +25 -1
- package/frontend-vue/app/components/DrawerTabs.vue +57 -0
- package/frontend-vue/app/components/JsonCellPanel.vue +81 -85
- package/frontend-vue/app/components/QueryConsole.vue +6 -1
- package/frontend-vue/app/components/RowDrawer.vue +98 -124
- package/frontend-vue/app/components/SchemaDiagram.vue +134 -17
- package/frontend-vue/app/components/TableInspector.vue +122 -149
- package/frontend-vue/i18n/locales/database-en-GB.json +8 -12
- package/frontend-vue/i18n/locales/database-fr-FR.json +8 -12
- package/frontend-vue/package.json +2 -2
- package/frontend-vue/pnpm-lock.yaml +5 -5
- package/frontend-vue/tests/clientNavigation.test.ts +93 -0
- package/frontend-vue/tests/dataBrowser.test.ts +91 -1
- package/frontend-vue/tests/diagramLayout.test.ts +383 -0
- package/frontend-vue/tests/fixtures/serverRender.ts +114 -0
- package/frontend-vue/tests/locales.test.ts +48 -0
- package/frontend-vue/tests/onDemandReads.test.ts +81 -0
- package/frontend-vue/tests/serverRender.test.ts +83 -1
- package/frontend-vue/vitest.config.ts +8 -1
- package/package.json +9 -8
- package/skills/dms-database/SKILL.md +2 -1
package/README.md
CHANGED
|
@@ -56,12 +56,12 @@ Restart the backend, then the frontend, sign in as the platform owner and open *
|
|
|
56
56
|
|
|
57
57
|
| Package | Version |
|
|
58
58
|
| --- | --- |
|
|
59
|
-
| `@antelopejs/dms` | `>=0.
|
|
60
|
-
| `@antelopejs/interface-dms` | `>=0.
|
|
61
|
-
| `@antelopejs/dms-frontend` (renderer) | `>=0.
|
|
59
|
+
| `@antelopejs/dms` | `>=0.11.0 <1.0.0` |
|
|
60
|
+
| `@antelopejs/interface-dms` | `>=0.9.0 <1.0.0` |
|
|
61
|
+
| `@antelopejs/dms-frontend` (renderer) | `>=0.9.0 <0.10.0` |
|
|
62
62
|
| Database | an `@antelopejs/interface-database` implementation, such as `@antelopejs/mongodb` |
|
|
63
63
|
|
|
64
|
-
On DMS 0.
|
|
64
|
+
On DMS 0.10 or earlier, use `@antelopejs/dms-database` 0.3.
|
|
65
65
|
|
|
66
66
|
## Documentation
|
|
67
67
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.frontendModule = frontendModule;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
function frontendModule() {
|
|
9
|
+
return {
|
|
10
|
+
name: "@antelopejs/dms-database-frontend-vue",
|
|
11
|
+
sourcePath: node_path_1.default.join(__dirname, "../frontend-vue"),
|
|
12
|
+
renderer: { name: "vue", version: "3" },
|
|
13
|
+
configKey: "dmsDatabase",
|
|
14
|
+
priority: 0,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=frontend-module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontend-module.js","sourceRoot":"","sources":["../src/frontend-module.ts"],"names":[],"mappings":";;;;;AASA,wCAQC;AAjBD,0DAA6B;AAS7B,SAAgB,cAAc;IAC5B,OAAO;QACL,IAAI,EAAE,uCAAuC;QAC7C,UAAU,EAAE,mBAAI,CAAC,IAAI,CAAC,SAAS,EAAE,iBAAiB,CAAC;QACnD,QAAQ,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE;QACvC,SAAS,EAAE,aAAa;QACxB,QAAQ,EAAE,CAAC;KACZ,CAAC;AACJ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,32 +13,23 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
17
|
exports.construct = construct;
|
|
21
18
|
exports.start = start;
|
|
22
19
|
exports.stop = stop;
|
|
23
20
|
require("./db");
|
|
24
21
|
require("./module");
|
|
25
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
26
22
|
const interface_database_decorators_1 = require("@antelopejs/interface-database-decorators");
|
|
27
23
|
const page_1 = require("@antelopejs/interface-dms/page");
|
|
28
24
|
const automation_1 = require("./automation");
|
|
29
25
|
const config_1 = require("./config");
|
|
30
26
|
const constants_1 = require("./types/constants");
|
|
27
|
+
const frontend_module_1 = require("./frontend-module");
|
|
31
28
|
__exportStar(require("./pages"), exports);
|
|
32
29
|
__exportStar(require("./routes"), exports);
|
|
33
30
|
async function construct(config) {
|
|
34
31
|
(0, config_1.setModuleConfig)(config);
|
|
35
|
-
await (0, page_1.AddFrontendModule)(
|
|
36
|
-
name: "@antelopejs/dms-database-frontend-vue",
|
|
37
|
-
sourcePath: node_path_1.default.join(__dirname, "../frontend-vue"),
|
|
38
|
-
renderer: { name: "vue", version: "3" },
|
|
39
|
-
configKey: "dmsDatabase",
|
|
40
|
-
priority: 0,
|
|
41
|
-
});
|
|
32
|
+
await (0, page_1.AddFrontendModule)((0, frontend_module_1.frontendModule)());
|
|
42
33
|
}
|
|
43
34
|
async function start() {
|
|
44
35
|
await (0, interface_database_decorators_1.RegisterSchema)(constants_1.SCHEMA_NAME);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAgBA,8BAGC;AAED,sBAGC;AAED,oBAEC;AA5BD,gBAAc;AACd,oBAAkB;AAClB,6FAA2E;AAC3E,yDAAmE;AACnE,6CAGsB;AACtB,qCAAmE;AACnE,iDAAgD;AAChD,uDAAmD;AAGnD,0CAAwB;AACxB,2CAAyB;AAElB,KAAK,UAAU,SAAS,CAAC,MAA0B;IACxD,IAAA,wBAAe,EAAC,MAAM,CAAC,CAAC;IACxB,MAAM,IAAA,wBAAiB,EAAC,IAAA,gCAAc,GAAE,CAAC,CAAC;AAC5C,CAAC;AAEM,KAAK,UAAU,KAAK;IACzB,MAAM,IAAA,8CAAc,EAAC,uBAAW,CAAC,CAAC;IAClC,IAAA,oCAAuB,GAAE,CAAC;AAC5B,CAAC;AAED,SAAgB,IAAI;IAClB,IAAA,sCAAyB,GAAE,CAAC;AAC9B,CAAC"}
|
package/dist/pages/overview.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ declare const DatabaseOverviewPage_base: {
|
|
|
4
4
|
location: string;
|
|
5
5
|
};
|
|
6
6
|
export declare class DatabaseOverviewPage extends DatabaseOverviewPage_base {
|
|
7
|
-
static beta: import("@antelopejs/interface-dms").ComponentBuilder<import("@antelopejs/interface-dms/base").BannerProps>;
|
|
8
7
|
static connection: import("@antelopejs/interface-dms").ComponentBuilder<unknown>;
|
|
9
8
|
static schemas: import("@antelopejs/interface-dms").ComponentBuilder<import("@antelopejs/interface-dms/base").SectionProps>;
|
|
10
9
|
static activity: import("@antelopejs/interface-dms").ComponentBuilder<import("@antelopejs/interface-dms/base").GridOptions>;
|
package/dist/pages/overview.js
CHANGED
|
@@ -9,7 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.DatabaseOverviewPage = void 0;
|
|
10
10
|
const button_1 = require("@antelopejs/interface-dms/base/types/button");
|
|
11
11
|
const activity_feed_1 = require("@antelopejs/interface-dms/base/activity-feed");
|
|
12
|
-
const banner_1 = require("@antelopejs/interface-dms/base/banner");
|
|
13
12
|
const custom_1 = require("@antelopejs/interface-dms/base/custom");
|
|
14
13
|
const grid_1 = require("@antelopejs/interface-dms/base/grid");
|
|
15
14
|
const layouts_1 = require("@antelopejs/interface-dms/base/layouts");
|
|
@@ -19,7 +18,6 @@ const top_list_card_1 = require("@antelopejs/interface-dms/base/top-list-card");
|
|
|
19
18
|
const page_1 = require("@antelopejs/interface-dms/page");
|
|
20
19
|
const module_1 = require("../module");
|
|
21
20
|
const constants_1 = require("../types/constants");
|
|
22
|
-
const BETA_NOTICE_KEY = "dms-database-beta-v2";
|
|
23
21
|
let DatabaseOverviewPage = class DatabaseOverviewPage extends (0, page_1.PageController)("overview", {
|
|
24
22
|
displayName: "$dms_database.overview.title",
|
|
25
23
|
description: "$dms_database.overview.description",
|
|
@@ -47,18 +45,6 @@ let DatabaseOverviewPage = class DatabaseOverviewPage extends (0, page_1.PageCon
|
|
|
47
45
|
},
|
|
48
46
|
],
|
|
49
47
|
})) {
|
|
50
|
-
static beta = (0, banner_1.Banner)({
|
|
51
|
-
tone: "warning",
|
|
52
|
-
size: "sm",
|
|
53
|
-
title: "$dms_database.overview.beta.title",
|
|
54
|
-
description: "$dms_database.overview.beta.body",
|
|
55
|
-
dismissible: true,
|
|
56
|
-
dismissKey: BETA_NOTICE_KEY,
|
|
57
|
-
}).meta({
|
|
58
|
-
name: "$dms_database.overview.beta.meta",
|
|
59
|
-
icon: "i-ph-flask",
|
|
60
|
-
description: "$dms_database.overview.beta.meta_description",
|
|
61
|
-
});
|
|
62
48
|
static connection = (0, custom_1.CustomComponent)("DmsDatabaseConnectionStatus").meta({
|
|
63
49
|
name: "$dms_database.overview.connection.meta",
|
|
64
50
|
icon: "i-ph-heartbeat",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overview.js","sourceRoot":"","sources":["../../src/pages/overview.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wEAA4E;AAC5E,gFAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"overview.js","sourceRoot":"","sources":["../../src/pages/overview.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wEAA4E;AAC5E,gFAA4E;AAC5E,kEAAwE;AACxE,8DAAoE;AACpE,oEAAuE;AACvE,gFAA2E;AAC3E,oEAAiE;AACjE,gFAA2E;AAC3E,yDAA8E;AAC9E,sCAA+E;AAC/E,kDAAyD;AAGlD,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,IAAA,qBAAc,EACtD,UAAU,EACV;IACE,WAAW,EAAE,8BAA8B;IAC3C,WAAW,EAAE,oCAAoC;IACjD,IAAI,EAAE,YAAY;IAClB,MAAM,EAAE,2BAAkB;IAC1B,QAAQ,EAAE,uBAAc;IACxB,KAAK,EAAE,CAAC;CACT,EACD,IAAA,uBAAa,EAAC;IACZ,aAAa,EAAE;QACb;YACE,EAAE,EAAE,Y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AK,EACL,IAAA,cAAO,GAAE;SACN,KAAK,CACJ,SAAS,EACT,IAAA,2BAAW,EAAC;QACV,KAAK,EAAE,sCAAsC;QAC7C,WAAW,EAAE,4CAA4C;QACzD,QAAQ,EAAE,gCAAgC;QAC1C,WAAW,EAAE,SAAS;QACtB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE,+BAAmB;QAClC,UAAU,EAAE,sCAAsC;KACnD,CAAC,CAAC,IAAI,CAAC;QACN,IAAI,EAAE,sCAAsC;QAC5C,IAAI,EAAE,2BAA2B;KAClC,CAAC,CACH;SACA,KAAK,CACJ,QAAQ,EACR,IAAA,4BAAY,EAAC;QACX,KAAK,EAAE,qCAAqC;QAC5C,QAAQ,EAAE,uCAAuC;QACjD,IAAI,EAAE,IAAI;QACV,UAAU,EAAE,KAAK;QACjB,QAAQ,EAAE,+BAAmB;QAC7B,aAAa,EAAE,+BAAmB;QAClC,IAAI,EAAE,IAAI;QACV,OAAO,EAAE;YACP;gBACE,KAAK,EAAE,uCAAuC;gBAC9C,EAAE,EAAE,uBAAc,CAAC,KAAK;gBACxB,IAAI,EAAE,kBAAkB;aACzB;SACF;QACD,KAAK,EAAE;YACL,KAAK,EAAE,2CAA2C;YAClD,WAAW,EAAE,iDAAiD;SAC/D;KACF,CAAC,CAAC,IAAI,CAAC;QACN,IAAI,EAAE,qCAAqC;QAC3C,IAAI,EAAE,8BAA8B;KACrC,CAAC,CACH,CACJ;SACA,IAAI,CAAC;QACJ,IAAI,EAAE,sCAAsC;QAC5C,IAAI,EAAE,mBAAmB;KAC1B,CAAC,CAAC;;AAjHM,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAY,GAAE;GACF,oBAAoB,CAkHhC"}
|
package/dist/pages/schemas.js
CHANGED
|
@@ -25,6 +25,7 @@ const tables = table_view_1.TableView.fromSource({
|
|
|
25
25
|
capabilities: { search: false, filter: true },
|
|
26
26
|
defaultSort: { field: "elementCount", desc: true },
|
|
27
27
|
pageSize: 50,
|
|
28
|
+
rowClick: "single",
|
|
28
29
|
columns: {
|
|
29
30
|
name: {
|
|
30
31
|
name: "$dms_database.schemas.cols.table",
|
|
@@ -81,6 +82,8 @@ const tables = table_view_1.TableView.fromSource({
|
|
|
81
82
|
type: "drawer",
|
|
82
83
|
direction: "right",
|
|
83
84
|
title: "$dms_database.schemas.inspector.title",
|
|
85
|
+
rowTitle: "{name}",
|
|
86
|
+
positionLabel: "$dms_database.schemas.inspector.position",
|
|
84
87
|
component: (0, custom_1.CustomComponent)("DmsDatabaseTableInspector").meta({
|
|
85
88
|
name: "$dms_database.schemas.inspector.meta",
|
|
86
89
|
icon: "i-ph-sidebar-simple",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/pages/schemas.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wEAA4E;AAC5E,kEAAwE;AACxE,0EAA6E;AAC7E,oEAAuE;AACvE,0EAGmD;AACnD,yDAA8E;AAC9E,sCAA+E;AAC/E,4DAA4D;AAG5D,MAAM,WAAW,GAAG,0CAA0C,CAAC;AAE/D,MAAM,MAAM,GAAG,sBAAS,CAAC,UAAU,CAAC;IAClC,OAAO,EAAE,+BAA+B;IACxC,QAAQ,EAAE,6BAA6B;IAGvC,WAAW,EAAE,+CAA+C;IAC5D,QAAQ,EAAE,IAAI;IACd,QAAQ,EAAE,MAAM;IAChB,YAAY,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE;IAC7C,WAAW,EAAE,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,IAAI,EAAE;IAClD,QAAQ,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/pages/schemas.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wEAA4E;AAC5E,kEAAwE;AACxE,0EAA6E;AAC7E,oEAAuE;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M,EAAE,GAAG,EAAE,uBAAc,CAAC,OAAO,EAAE;SACtD;KACF;CACF,CAAC,CACH;IACC,MAAM,CAAC,SAAS,GAAG,IAAA,wBAAe,EAAC,6BAA6B,CAAC,CAAC,IAAI,CAAC;QACrE,IAAI,EAAE,oCAAoC;QAC1C,IAAI,EAAE,aAAa;QACnB,WAAW,EAAE,gDAAgD;KAC9D,CAAC,CAAC;IACH,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;;AA5BZ,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAY,GAAE;GACF,mBAAmB,CA6B/B"}
|
|
@@ -36,18 +36,22 @@ const EMPTY_HEALTH: OverviewHealth = {
|
|
|
36
36
|
|
|
37
37
|
/** `refreshInterval` probes again on that interval while the page shows it. */
|
|
38
38
|
export function useDatabaseHealth(options: { refreshInterval?: number } = {}) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
)
|
|
39
|
+
const read = useApiData<OverviewHealth>(HEALTH_ENDPOINT, {
|
|
40
|
+
default: () => ({ ...EMPTY_HEALTH }),
|
|
41
|
+
refreshInterval: options.refreshInterval,
|
|
42
|
+
})
|
|
43
|
+
const { data, pending, error, refresh } = read
|
|
46
44
|
|
|
47
45
|
return {
|
|
48
46
|
health: computed(() => data.value ?? { ...EMPTY_HEALTH }),
|
|
49
47
|
isLoading: pending,
|
|
50
48
|
error,
|
|
51
49
|
refresh,
|
|
50
|
+
/**
|
|
51
|
+
* Settles once the first probe is in, at once when it ran before:
|
|
52
|
+
* awaited in a setup, a client navigation shows the probe, not the
|
|
53
|
+
* empty health it replaces.
|
|
54
|
+
*/
|
|
55
|
+
ready: read.then(() => undefined),
|
|
52
56
|
}
|
|
53
57
|
}
|
|
@@ -110,9 +110,10 @@ export function inboundRelationsIn(
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export function useDatabaseSchemas() {
|
|
113
|
-
const
|
|
113
|
+
const read = useApiData<{
|
|
114
114
|
schemas: SchemaSummary[]
|
|
115
115
|
}>(SCHEMAS_ENDPOINT, { default: () => EMPTY_SCHEMAS })
|
|
116
|
+
const { data, pending, error, status, refresh } = read
|
|
116
117
|
|
|
117
118
|
const schemas = computed(() => data.value?.schemas ?? [])
|
|
118
119
|
|
|
@@ -127,6 +128,12 @@ export function useDatabaseSchemas() {
|
|
|
127
128
|
),
|
|
128
129
|
error,
|
|
129
130
|
refresh,
|
|
131
|
+
/**
|
|
132
|
+
* Settles once the first read is in, at once when the schemas were read
|
|
133
|
+
* before. Awaited in a setup, a client navigation waits for the
|
|
134
|
+
* schemas instead of showing the page without what they decide.
|
|
135
|
+
*/
|
|
136
|
+
ready: read.then(() => undefined),
|
|
130
137
|
}
|
|
131
138
|
}
|
|
132
139
|
|
|
@@ -130,3 +130,53 @@ export function cellLabel(value: unknown): string {
|
|
|
130
130
|
export function isStructured(value: unknown): boolean {
|
|
131
131
|
return value !== null && typeof value === 'object'
|
|
132
132
|
}
|
|
133
|
+
|
|
134
|
+
// Past this length a text no longer reads whole in the drawer's value column.
|
|
135
|
+
const WIDE_TEXT_LENGTH = 48
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Whether a row drawer gives the value the drawer's width, its label above:
|
|
139
|
+
* an object or a list (edited as JSON), and a text of several lines or too
|
|
140
|
+
* long for the value column (edited in a text area).
|
|
141
|
+
*/
|
|
142
|
+
export function isWideValue(value: unknown): boolean {
|
|
143
|
+
if (isStructured(value)) return true
|
|
144
|
+
return (
|
|
145
|
+
typeof value === 'string' &&
|
|
146
|
+
(value.length > WIDE_TEXT_LENGTH || value.includes('\n'))
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
type JsonDraftResult =
|
|
151
|
+
| { ok: true; value: unknown }
|
|
152
|
+
| { ok: false; reason: 'invalid' | 'not_structured'; detail?: string }
|
|
153
|
+
|
|
154
|
+
/** The text the JSON editor opens a structured cell with. */
|
|
155
|
+
export function jsonDraftText(value: unknown): string {
|
|
156
|
+
try {
|
|
157
|
+
return JSON.stringify(value, null, 2) ?? ''
|
|
158
|
+
} catch {
|
|
159
|
+
return ''
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* The value a JSON editor's draft stands for: an object, a list, or null to
|
|
165
|
+
* empty the cell. A scalar is not a structured cell.
|
|
166
|
+
*/
|
|
167
|
+
export function parseJsonDraft(text: string): JsonDraftResult {
|
|
168
|
+
let value: unknown
|
|
169
|
+
try {
|
|
170
|
+
value = JSON.parse(text)
|
|
171
|
+
} catch (error) {
|
|
172
|
+
// The engine's parse detail (position, token…).
|
|
173
|
+
return {
|
|
174
|
+
ok: false,
|
|
175
|
+
reason: 'invalid',
|
|
176
|
+
detail: error instanceof Error ? error.message : undefined,
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (value !== null && typeof value !== 'object')
|
|
180
|
+
return { ok: false, reason: 'not_structured' }
|
|
181
|
+
return { ok: true, value }
|
|
182
|
+
}
|
|
@@ -8,12 +8,26 @@ import type {
|
|
|
8
8
|
DiagramPosition,
|
|
9
9
|
DiagramPositions,
|
|
10
10
|
} from '../composables/useDiagramPersistence'
|
|
11
|
+
import { isPrimaryKey } from '../utils/fieldTypes'
|
|
12
|
+
import {
|
|
13
|
+
type Block,
|
|
14
|
+
boundsOf,
|
|
15
|
+
DEFAULT_ASPECT,
|
|
16
|
+
linkedGroups,
|
|
17
|
+
overlaps,
|
|
18
|
+
packBlocks,
|
|
19
|
+
prefixOrder,
|
|
20
|
+
type Rect,
|
|
21
|
+
type Size,
|
|
22
|
+
} from './packing'
|
|
11
23
|
|
|
12
24
|
// Turns a schema into the nodes and edges of the diagram: one node per table,
|
|
13
25
|
// a dashed stub for a table a relation points to that is not drawn, the
|
|
14
26
|
// notes, and one edge per relation column. Table positions come from the
|
|
15
|
-
// saved layout; a table without one takes the place
|
|
16
|
-
//
|
|
27
|
+
// saved layout; a table without one takes the place the layout of the whole
|
|
28
|
+
// schema gives it, so it stays put when the canvas focuses on a few tables.
|
|
29
|
+
// That layout runs dagre on each group of related tables, then sets the
|
|
30
|
+
// groups and the tables on their own in rows shaped like the canvas.
|
|
17
31
|
|
|
18
32
|
export const NODE_WIDTH = 232
|
|
19
33
|
const NODE_HEIGHT_PER_FIELD = 24
|
|
@@ -21,6 +35,8 @@ const NODE_HEIGHT_HEADER = 44
|
|
|
21
35
|
export const STUB_NODE_WIDTH = 180
|
|
22
36
|
const STUB_NODE_HEIGHT = 28
|
|
23
37
|
const LAYOUT = { rankdir: 'LR', nodesep: 48, ranksep: 120 } as const
|
|
38
|
+
/** Columns a folded table shows, besides the ones an arrow ends on. */
|
|
39
|
+
export const FOLDED_COLUMNS = 12
|
|
24
40
|
const HYSTERESIS_PX = 15
|
|
25
41
|
// Notes sit above the tables, so a new one is never hidden under a table.
|
|
26
42
|
export const NOTE_Z_INDEX = 10
|
|
@@ -56,6 +72,14 @@ export interface TableNodeData {
|
|
|
56
72
|
dimmed: boolean
|
|
57
73
|
/** Picked on the canvas, by a search or from a link. */
|
|
58
74
|
selected: boolean
|
|
75
|
+
/** The columns drawn, in the table's order: all of them when unfolded. */
|
|
76
|
+
columns: string[]
|
|
77
|
+
/** Columns the folded table leaves out; 0 when it shows them all. */
|
|
78
|
+
hiddenCount: number
|
|
79
|
+
/** Has more columns than a folded table shows. */
|
|
80
|
+
foldable: boolean
|
|
81
|
+
expanded: boolean
|
|
82
|
+
onToggleColumns: (tableName: string) => void
|
|
59
83
|
}
|
|
60
84
|
|
|
61
85
|
export interface NoteNodeData {
|
|
@@ -134,10 +158,14 @@ export interface GraphInput {
|
|
|
134
158
|
/** Sides each edge used last, so an edge does not flip on every drag. */
|
|
135
159
|
routing: Map<string, Sides>
|
|
136
160
|
/**
|
|
137
|
-
* Where
|
|
138
|
-
* The canvas keeps it per schema, so a render does not lay out
|
|
161
|
+
* Where the layout puts every table of the whole schema; computed when
|
|
162
|
+
* absent. The canvas keeps it per schema, so a render does not lay out
|
|
163
|
+
* again.
|
|
139
164
|
*/
|
|
140
165
|
layout?: SchemaLayout
|
|
166
|
+
/** Tables showing all their columns; the others are folded. */
|
|
167
|
+
expanded?: Set<string>
|
|
168
|
+
onToggleColumns?: (tableName: string) => void
|
|
141
169
|
}
|
|
142
170
|
|
|
143
171
|
export interface BuiltGraph {
|
|
@@ -157,13 +185,92 @@ export function noteNodeId(noteId: string): string {
|
|
|
157
185
|
return `note::${noteId}`
|
|
158
186
|
}
|
|
159
187
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Columns of `table` an arrow ends on: its primary key, its relation
|
|
190
|
+
* columns, and the columns relations of `schema` point at.
|
|
191
|
+
*/
|
|
192
|
+
function anchorColumns(
|
|
193
|
+
schema: SchemaSummary,
|
|
194
|
+
table: TableSummary,
|
|
195
|
+
): Set<string> {
|
|
196
|
+
const anchors = new Set(table.relations.map((r) => r.fromField))
|
|
197
|
+
for (const field of Object.keys(table.fields))
|
|
198
|
+
if (isPrimaryKey(field, table.indexes ?? {})) anchors.add(field)
|
|
199
|
+
for (const other of schema.tables) {
|
|
200
|
+
for (const relation of other.relations) {
|
|
201
|
+
if (relation.toSchema === schema.id && relation.toTable === table.name)
|
|
202
|
+
anchors.add(relation.toField)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return anchors
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface ShownColumns {
|
|
209
|
+
columns: string[]
|
|
210
|
+
hiddenCount: number
|
|
211
|
+
foldable: boolean
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The columns a table node draws: every one when expanded; folded, the first
|
|
216
|
+
* FOLDED_COLUMNS and every column an arrow ends on, so no edge points to a
|
|
217
|
+
* row that is not drawn.
|
|
218
|
+
*/
|
|
219
|
+
export function shownColumns(
|
|
220
|
+
schema: SchemaSummary,
|
|
221
|
+
table: TableSummary,
|
|
222
|
+
expanded: boolean,
|
|
223
|
+
): ShownColumns {
|
|
224
|
+
const all = Object.keys(table.fields)
|
|
225
|
+
const foldable = all.length > FOLDED_COLUMNS
|
|
226
|
+
if (!foldable || expanded) return { columns: all, hiddenCount: 0, foldable }
|
|
227
|
+
const anchors = anchorColumns(schema, table)
|
|
228
|
+
const columns = all.filter(
|
|
229
|
+
(name, i) => i < FOLDED_COLUMNS || anchors.has(name),
|
|
230
|
+
)
|
|
231
|
+
return { columns, hiddenCount: all.length - columns.length, foldable }
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The height of a table node: its header, its rows, and the row that folds
|
|
236
|
+
* or unfolds it when it has one.
|
|
237
|
+
*/
|
|
238
|
+
export function nodeHeight(
|
|
239
|
+
schema: SchemaSummary,
|
|
240
|
+
table: TableSummary,
|
|
241
|
+
expanded = false,
|
|
242
|
+
): number {
|
|
243
|
+
const shown = shownColumns(schema, table, expanded)
|
|
244
|
+
const rows = shown.columns.length + (shown.foldable ? 1 : 0)
|
|
245
|
+
return NODE_HEIGHT_HEADER + rows * NODE_HEIGHT_PER_FIELD
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** Column names of `table` that hold `needle`, as the search reads it. */
|
|
249
|
+
function matchingColumns(table: TableSummary, needle: string): string[] {
|
|
250
|
+
const text = needle.trim().toLowerCase()
|
|
251
|
+
if (!text) return []
|
|
252
|
+
return Object.keys(table.fields).filter((field) =>
|
|
253
|
+
field.toLowerCase().includes(text),
|
|
164
254
|
)
|
|
165
255
|
}
|
|
166
256
|
|
|
257
|
+
/**
|
|
258
|
+
* The expanded tables once a search lands on `tableName`: it unfolds when a
|
|
259
|
+
* column the search finds is folded away.
|
|
260
|
+
*/
|
|
261
|
+
export function expandForSearch(
|
|
262
|
+
schema: SchemaSummary,
|
|
263
|
+
tableName: string,
|
|
264
|
+
needle: string,
|
|
265
|
+
expanded: Set<string>,
|
|
266
|
+
): Set<string> {
|
|
267
|
+
const table = schema.tables.find((t) => t.name === tableName)
|
|
268
|
+
if (!table || expanded.has(tableName)) return expanded
|
|
269
|
+
const shown = new Set(shownColumns(schema, table, false).columns)
|
|
270
|
+
const folded = matchingColumns(table, needle).some((c) => !shown.has(c))
|
|
271
|
+
return folded ? new Set([...expanded, tableName]) : expanded
|
|
272
|
+
}
|
|
273
|
+
|
|
167
274
|
/** Ids of a table and of every table it points to or is pointed at from. */
|
|
168
275
|
export function neighbourIds(
|
|
169
276
|
schema: SchemaSummary,
|
|
@@ -285,34 +392,104 @@ function relationEdges(
|
|
|
285
392
|
return { stubs, pending }
|
|
286
393
|
}
|
|
287
394
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
*/
|
|
292
|
-
|
|
395
|
+
export interface LayoutOptions {
|
|
396
|
+
/** Width / height of the canvas: the shape the rows aim at. */
|
|
397
|
+
aspect?: number
|
|
398
|
+
/** What the tables must not cover: the notes, which never move. */
|
|
399
|
+
obstacles?: Rect[]
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
interface LaidGroup extends Size {
|
|
403
|
+
/** Each node's top-left corner, from the group's own. */
|
|
404
|
+
offsets: Map<string, DiagramPosition>
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/** Lays out one group of related nodes with dagre. */
|
|
408
|
+
function layOutGroup(
|
|
409
|
+
ids: string[],
|
|
410
|
+
sizes: Map<string, Size>,
|
|
411
|
+
links: [string, string][],
|
|
412
|
+
): LaidGroup {
|
|
293
413
|
const graph = new dagre.graphlib.Graph()
|
|
294
414
|
graph.setDefaultEdgeLabel(() => ({}))
|
|
295
415
|
graph.setGraph({ ...LAYOUT })
|
|
296
|
-
const
|
|
416
|
+
const members = new Set(ids)
|
|
417
|
+
for (const id of ids) graph.setNode(id, { ...sizes.get(id) })
|
|
418
|
+
for (const [from, to] of links)
|
|
419
|
+
if (members.has(from) && members.has(to)) graph.setEdge(from, to)
|
|
420
|
+
dagre.layout(graph)
|
|
421
|
+
const rects = ids.map((id) => {
|
|
422
|
+
const laid = graph.node(id) as LaidNode
|
|
423
|
+
const x = laid.x - laid.width / 2
|
|
424
|
+
const y = laid.y - laid.height / 2
|
|
425
|
+
return { id, x, y, width: laid.width, height: laid.height }
|
|
426
|
+
})
|
|
427
|
+
const bounds = boundsOf(rects)
|
|
428
|
+
const offsets = new Map(
|
|
429
|
+
rects.map((r) => [r.id, { x: r.x - bounds.x, y: r.y - bounds.y }]),
|
|
430
|
+
)
|
|
431
|
+
return { offsets, width: bounds.width, height: bounds.height }
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Lays out the whole schema, every table and a stub for each table of
|
|
436
|
+
* another schema a relation points to: dagre on each group of tables linked
|
|
437
|
+
* by relations, a stub staying with the tables it hangs from, then the
|
|
438
|
+
* groups, largest first, and the tables on their own, by name prefix then
|
|
439
|
+
* name, in rows shaped like the canvas. Tables count at their folded height.
|
|
440
|
+
*/
|
|
441
|
+
export function layOutSchema(
|
|
442
|
+
schema: SchemaSummary,
|
|
443
|
+
options: LayoutOptions = {},
|
|
444
|
+
): SchemaLayout {
|
|
445
|
+
const sizes = new Map<string, Size>()
|
|
446
|
+
const names = new Map<string, string>()
|
|
297
447
|
for (const table of schema.tables) {
|
|
298
448
|
const id = tableNodeId(schema.id, table.name)
|
|
299
|
-
|
|
300
|
-
|
|
449
|
+
names.set(id, table.name)
|
|
450
|
+
sizes.set(id, { width: NODE_WIDTH, height: nodeHeight(schema, table) })
|
|
301
451
|
}
|
|
302
|
-
const { stubs, pending } = relationEdges(schema, null,
|
|
452
|
+
const { stubs, pending } = relationEdges(schema, null, new Set(names.keys()))
|
|
303
453
|
for (const id of stubs.keys())
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
454
|
+
sizes.set(id, { width: STUB_NODE_WIDTH, height: STUB_NODE_HEIGHT })
|
|
455
|
+
const links = pending.map((e): [string, string] => [e.sourceId, e.targetId])
|
|
456
|
+
|
|
457
|
+
const groups: (Block & LaidGroup & { count: number })[] = []
|
|
458
|
+
const alone: string[] = []
|
|
459
|
+
for (const ids of linkedGroups([...sizes.keys()], links)) {
|
|
460
|
+
const [first = ''] = ids
|
|
461
|
+
if (ids.length === 1 && names.has(first)) {
|
|
462
|
+
alone.push(names.get(first) ?? first)
|
|
463
|
+
continue
|
|
464
|
+
}
|
|
465
|
+
const laid = layOutGroup(ids, sizes, links)
|
|
466
|
+
groups.push({ id: `group::${first}`, count: ids.length, ...laid })
|
|
467
|
+
}
|
|
468
|
+
groups.sort(
|
|
469
|
+
(a, b) => b.count - a.count || b.width * b.height - a.width * a.height,
|
|
470
|
+
)
|
|
471
|
+
const single: Block[] = prefixOrder(alone).map((name) => {
|
|
472
|
+
const id = tableNodeId(schema.id, name)
|
|
473
|
+
return { id, ...(sizes.get(id) as Size) }
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
const packed = packBlocks(
|
|
477
|
+
[...groups, ...single],
|
|
478
|
+
options.aspect ?? DEFAULT_ASPECT,
|
|
479
|
+
options.obstacles,
|
|
480
|
+
)
|
|
481
|
+
const positions = new Map(packed)
|
|
482
|
+
for (const group of groups) {
|
|
483
|
+
const at = packed.get(group.id) ?? { x: 0, y: 0 }
|
|
484
|
+
for (const [id, offset] of group.offsets)
|
|
485
|
+
positions.set(id, { x: at.x + offset.x, y: at.y + offset.y })
|
|
310
486
|
}
|
|
311
487
|
const tables: DiagramPositions = {}
|
|
312
|
-
for (const
|
|
313
|
-
tables[
|
|
488
|
+
for (const [id, name] of names)
|
|
489
|
+
tables[name] = positions.get(id) ?? { x: 0, y: 0 }
|
|
314
490
|
const stubPositions: DiagramPositions = {}
|
|
315
|
-
for (const id of stubs.keys())
|
|
491
|
+
for (const id of stubs.keys())
|
|
492
|
+
stubPositions[id] = positions.get(id) ?? { x: 0, y: 0 }
|
|
316
493
|
return { tables, stubs: stubPositions }
|
|
317
494
|
}
|
|
318
495
|
|
|
@@ -363,6 +540,7 @@ function tableNodes(
|
|
|
363
540
|
.map((table) => {
|
|
364
541
|
const id = tableNodeId(input.schema.id, table.name)
|
|
365
542
|
const highlighted = highlightedColumns(input, table)
|
|
543
|
+
const expanded = input.expanded?.has(table.name) ?? false
|
|
366
544
|
const data: TableNodeData = {
|
|
367
545
|
schemaId: input.schema.id,
|
|
368
546
|
tableName: table.name,
|
|
@@ -374,10 +552,15 @@ function tableNodes(
|
|
|
374
552
|
input.selectedId !== null &&
|
|
375
553
|
input.selectedId !== id &&
|
|
376
554
|
highlighted.length === 0,
|
|
555
|
+
...shownColumns(input.schema, table, expanded),
|
|
556
|
+
expanded,
|
|
557
|
+
onToggleColumns: input.onToggleColumns ?? (() => undefined),
|
|
377
558
|
}
|
|
378
559
|
return {
|
|
379
560
|
id,
|
|
380
561
|
type: TABLE_NODE_TYPE,
|
|
562
|
+
// An unfolded table runs over the tables below it: drawn above them.
|
|
563
|
+
...(expanded ? { zIndex: 1 } : {}),
|
|
381
564
|
position: { ...tablePosition(input, layout, table.name) },
|
|
382
565
|
// The canvas keeps its own selection (`data.selected`), and a
|
|
383
566
|
// table leaves the diagram only with its schema.
|
|
@@ -396,7 +579,7 @@ export interface StubNodeData {
|
|
|
396
579
|
|
|
397
580
|
/**
|
|
398
581
|
* A stub for a table of this schema left out by the focus sits where that
|
|
399
|
-
* table is; one for another schema takes the place
|
|
582
|
+
* table is; one for another schema takes the place the layout gives it.
|
|
400
583
|
*/
|
|
401
584
|
function stubPosition(
|
|
402
585
|
input: GraphInput,
|
|
@@ -523,30 +706,11 @@ export function searchTables(schema: SchemaSummary, needle: string): string[] {
|
|
|
523
706
|
)
|
|
524
707
|
const byColumn = schema.tables.filter(
|
|
525
708
|
(table) =>
|
|
526
|
-
!byName.includes(table) &&
|
|
527
|
-
Object.keys(table.fields).some((field) =>
|
|
528
|
-
field.toLowerCase().includes(text),
|
|
529
|
-
),
|
|
709
|
+
!byName.includes(table) && matchingColumns(table, text).length > 0,
|
|
530
710
|
)
|
|
531
711
|
return [...byName, ...byColumn].map((table) => table.name)
|
|
532
712
|
}
|
|
533
713
|
|
|
534
|
-
export interface Rect {
|
|
535
|
-
x: number
|
|
536
|
-
y: number
|
|
537
|
-
width: number
|
|
538
|
-
height: number
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
function overlaps(a: Rect, b: Rect, margin: number): boolean {
|
|
542
|
-
return (
|
|
543
|
-
a.x < b.x + b.width + margin &&
|
|
544
|
-
b.x < a.x + a.width + margin &&
|
|
545
|
-
a.y < b.y + b.height + margin &&
|
|
546
|
-
b.y < a.y + a.height + margin
|
|
547
|
-
)
|
|
548
|
-
}
|
|
549
|
-
|
|
550
714
|
const FREE_SPOT_STEP = 40
|
|
551
715
|
const FREE_SPOT_RINGS = 12
|
|
552
716
|
const FREE_SPOT_MARGIN = 16
|