@alepha/devtools 0.16.0 → 0.19.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 +1 -5
- package/dist/index.browser.js +224 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.d.ts +349 -321
- package/dist/index.js +293 -186
- package/dist/index.js.map +1 -1
- package/package.json +30 -23
- package/src/assets.ts +6 -0
- package/src/{api/entities → entities}/logs.ts +2 -2
- package/src/index.browser.ts +11 -0
- package/src/index.shared.ts +15 -0
- package/src/index.ts +11 -37
- package/src/{api/providers → providers}/DevToolsMetadataProvider.ts +84 -47
- package/src/providers/DevToolsProvider.ts +280 -0
- package/src/{api/schemas → schemas}/DevActionMetadata.ts +8 -0
- package/src/{api/schemas → schemas}/DevEntityMetadata.ts +3 -0
- package/src/{api/schemas → schemas}/DevMetadata.ts +13 -2
- package/src/{api/schemas → schemas}/DevPageMetadata.ts +3 -0
- package/src/{api/schemas → schemas}/DevTopicMetadata.ts +1 -0
- package/src/ui/AppRouter.tsx +55 -59
- package/src/ui/components/DevLayout.tsx +104 -84
- package/src/ui/components/configuration/ConfigAtoms.page.tsx +5 -0
- package/src/ui/components/configuration/ConfigAtoms.tsx +511 -0
- package/src/ui/components/configuration/ConfigEnv.page.tsx +5 -0
- package/src/ui/components/configuration/ConfigEnv.tsx +230 -0
- package/src/ui/components/configuration/DevConfiguration.tsx +36 -0
- package/src/ui/components/configuration/index.ts +3 -0
- package/src/ui/components/dashboard/DevDashboard.tsx +482 -0
- package/src/ui/components/database/DatabaseEditor.page.tsx +23 -0
- package/src/ui/components/database/DatabaseEditor.tsx +399 -0
- package/src/ui/components/database/DatabaseErd.page.tsx +28 -0
- package/src/ui/components/database/DatabaseErd.tsx +107 -0
- package/src/ui/components/database/DevDatabase.tsx +36 -0
- package/src/ui/components/database/EntityNode.tsx +83 -0
- package/src/ui/components/explorer/DevExplorer.tsx +351 -0
- package/src/ui/components/explorer/ExplorerTree.tsx +178 -0
- package/src/ui/components/explorer/panels/DevPanelAction.tsx +499 -0
- package/src/ui/components/explorer/panels/DevPanelCache.tsx +73 -0
- package/src/ui/components/explorer/panels/DevPanelPage.tsx +96 -0
- package/src/ui/components/explorer/panels/DevPanelQueue.tsx +51 -0
- package/src/ui/components/explorer/panels/DevPanelTopic.tsx +56 -0
- package/src/ui/components/explorer/panels/index.ts +5 -0
- package/src/ui/components/graph/DevDependencyGraph.tsx +35 -60
- package/src/ui/components/graph/GraphControls.tsx +10 -11
- package/src/ui/components/graph/NodeDetails.tsx +22 -29
- package/src/ui/components/graph/ProviderNode.tsx +4 -4
- package/src/ui/components/graph/helpers.ts +1 -1
- package/src/ui/components/logs/DevLogs.tsx +661 -0
- package/src/ui/components/logs/index.ts +1 -0
- package/src/ui/components/shared/TreeView.tsx +189 -0
- package/src/ui/main.css +17 -0
- package/src/ui/main.ts +2 -6
- package/LICENSE +0 -21
- package/assets/devtools/actions.html +0 -21
- package/assets/devtools/actions.html.br +0 -0
- package/assets/devtools/actions.html.gz +0 -0
- package/assets/devtools/asset.BJSLFcNT.css +0 -1
- package/assets/devtools/asset.BJSLFcNT.css.br +0 -0
- package/assets/devtools/asset.BJSLFcNT.css.gz +0 -0
- package/assets/devtools/asset.BZV40eAE.css +0 -1
- package/assets/devtools/asset.BZV40eAE.css.br +0 -0
- package/assets/devtools/asset.BZV40eAE.css.gz +0 -0
- package/assets/devtools/atoms.html +0 -21
- package/assets/devtools/atoms.html.br +0 -0
- package/assets/devtools/atoms.html.gz +0 -0
- package/assets/devtools/caches.html +0 -21
- package/assets/devtools/caches.html.br +0 -0
- package/assets/devtools/caches.html.gz +0 -0
- package/assets/devtools/chunk.1h5GuATm.js +0 -1
- package/assets/devtools/chunk.1h5GuATm.js.br +0 -0
- package/assets/devtools/chunk.1h5GuATm.js.gz +0 -0
- package/assets/devtools/chunk.3PgxxOdM.js +0 -1
- package/assets/devtools/chunk.3PgxxOdM.js.br +0 -0
- package/assets/devtools/chunk.3PgxxOdM.js.gz +0 -0
- package/assets/devtools/chunk.A_W3H6Aa.js +0 -1
- package/assets/devtools/chunk.A_W3H6Aa.js.br +0 -0
- package/assets/devtools/chunk.A_W3H6Aa.js.gz +0 -0
- package/assets/devtools/chunk.B5tL0VjH.js +0 -1
- package/assets/devtools/chunk.B5tL0VjH.js.br +0 -0
- package/assets/devtools/chunk.B5tL0VjH.js.gz +0 -0
- package/assets/devtools/chunk.B8p_Szro.js +0 -1
- package/assets/devtools/chunk.B8p_Szro.js.br +0 -0
- package/assets/devtools/chunk.B8p_Szro.js.gz +0 -0
- package/assets/devtools/chunk.BANy8c2v.js +0 -1
- package/assets/devtools/chunk.BANy8c2v.js.br +0 -0
- package/assets/devtools/chunk.BANy8c2v.js.gz +0 -0
- package/assets/devtools/chunk.BKph0hv1.js +0 -1
- package/assets/devtools/chunk.BKph0hv1.js.br +0 -0
- package/assets/devtools/chunk.BKph0hv1.js.gz +0 -0
- package/assets/devtools/chunk.BUs1kuwE.js +0 -1
- package/assets/devtools/chunk.BUs1kuwE.js.br +0 -0
- package/assets/devtools/chunk.BUs1kuwE.js.gz +0 -0
- package/assets/devtools/chunk.BVIEr21R.js +0 -1
- package/assets/devtools/chunk.BVIEr21R.js.br +0 -0
- package/assets/devtools/chunk.BVIEr21R.js.gz +0 -0
- package/assets/devtools/chunk.Bb3re2d8.js +0 -1
- package/assets/devtools/chunk.Bb3re2d8.js.br +0 -2
- package/assets/devtools/chunk.Bb3re2d8.js.gz +0 -0
- package/assets/devtools/chunk.BjFrJKj1.js +0 -1
- package/assets/devtools/chunk.BjFrJKj1.js.br +0 -2
- package/assets/devtools/chunk.BjFrJKj1.js.gz +0 -0
- package/assets/devtools/chunk.BkXzz14p.js +0 -1
- package/assets/devtools/chunk.BkXzz14p.js.br +0 -0
- package/assets/devtools/chunk.BkXzz14p.js.gz +0 -0
- package/assets/devtools/chunk.BlqFPyLh.js +0 -1
- package/assets/devtools/chunk.BlqFPyLh.js.br +0 -0
- package/assets/devtools/chunk.BlqFPyLh.js.gz +0 -0
- package/assets/devtools/chunk.BymZ9jU5.js +0 -1
- package/assets/devtools/chunk.BymZ9jU5.js.br +0 -0
- package/assets/devtools/chunk.BymZ9jU5.js.gz +0 -0
- package/assets/devtools/chunk.C0BD3Ujz.js +0 -1
- package/assets/devtools/chunk.C0BD3Ujz.js.br +0 -0
- package/assets/devtools/chunk.C0BD3Ujz.js.gz +0 -0
- package/assets/devtools/chunk.C63rzhbT.js +0 -1
- package/assets/devtools/chunk.C63rzhbT.js.br +0 -0
- package/assets/devtools/chunk.C63rzhbT.js.gz +0 -0
- package/assets/devtools/chunk.CJrYVzjN.js +0 -9
- package/assets/devtools/chunk.CJrYVzjN.js.br +0 -0
- package/assets/devtools/chunk.CJrYVzjN.js.gz +0 -0
- package/assets/devtools/chunk.CPGX3Xpx.js +0 -1
- package/assets/devtools/chunk.CPGX3Xpx.js.br +0 -1
- package/assets/devtools/chunk.CPGX3Xpx.js.gz +0 -0
- package/assets/devtools/chunk.Cf-3skUw.js +0 -1
- package/assets/devtools/chunk.Cf-3skUw.js.br +0 -0
- package/assets/devtools/chunk.Cf-3skUw.js.gz +0 -0
- package/assets/devtools/chunk.D7JLxcoJ.js +0 -7
- package/assets/devtools/chunk.D7JLxcoJ.js.br +0 -0
- package/assets/devtools/chunk.D7JLxcoJ.js.gz +0 -0
- package/assets/devtools/chunk.D7e5mBY4.js +0 -1
- package/assets/devtools/chunk.D7e5mBY4.js.br +0 -0
- package/assets/devtools/chunk.D7e5mBY4.js.gz +0 -0
- package/assets/devtools/chunk.DClU9Z1_.js +0 -1
- package/assets/devtools/chunk.DClU9Z1_.js.br +0 -0
- package/assets/devtools/chunk.DClU9Z1_.js.gz +0 -0
- package/assets/devtools/chunk.DE_M8b3Z.js +0 -1
- package/assets/devtools/chunk.DE_M8b3Z.js.br +0 -0
- package/assets/devtools/chunk.DE_M8b3Z.js.gz +0 -0
- package/assets/devtools/chunk.DWASJDBE.js +0 -1
- package/assets/devtools/chunk.DWASJDBE.js.br +0 -0
- package/assets/devtools/chunk.DWASJDBE.js.gz +0 -0
- package/assets/devtools/chunk.DfzRLqwW.js +0 -1
- package/assets/devtools/chunk.DfzRLqwW.js.br +0 -0
- package/assets/devtools/chunk.DfzRLqwW.js.gz +0 -0
- package/assets/devtools/chunk.Dww1YQtc.js +0 -1
- package/assets/devtools/chunk.Dww1YQtc.js.br +0 -0
- package/assets/devtools/chunk.Dww1YQtc.js.gz +0 -0
- package/assets/devtools/chunk.HFLdduaf.js +0 -1
- package/assets/devtools/chunk.HFLdduaf.js.br +0 -0
- package/assets/devtools/chunk.HFLdduaf.js.gz +0 -0
- package/assets/devtools/chunk.J-htqECs.js +0 -1
- package/assets/devtools/chunk.J-htqECs.js.br +0 -2
- package/assets/devtools/chunk.J-htqECs.js.gz +0 -0
- package/assets/devtools/chunk.JjTGVewZ.js +0 -2
- package/assets/devtools/chunk.JjTGVewZ.js.br +0 -0
- package/assets/devtools/chunk.JjTGVewZ.js.gz +0 -0
- package/assets/devtools/chunk.OV_89czZ.js +0 -1
- package/assets/devtools/chunk.OV_89czZ.js.br +0 -0
- package/assets/devtools/chunk.OV_89czZ.js.gz +0 -0
- package/assets/devtools/chunk.YFkMUqFM.js +0 -1
- package/assets/devtools/chunk.YFkMUqFM.js.br +0 -0
- package/assets/devtools/chunk.YFkMUqFM.js.gz +0 -0
- package/assets/devtools/chunk._KdUFIrt.js +0 -1
- package/assets/devtools/chunk._KdUFIrt.js.br +0 -0
- package/assets/devtools/chunk._KdUFIrt.js.gz +0 -0
- package/assets/devtools/chunk.pjP6xqG8.js +0 -1
- package/assets/devtools/chunk.pjP6xqG8.js.br +0 -0
- package/assets/devtools/chunk.pjP6xqG8.js.gz +0 -0
- package/assets/devtools/chunk.uTFtY0ae.js +0 -2
- package/assets/devtools/chunk.uTFtY0ae.js.br +0 -0
- package/assets/devtools/chunk.uTFtY0ae.js.gz +0 -0
- package/assets/devtools/chunk.uyVen0u2.js +0 -1
- package/assets/devtools/chunk.uyVen0u2.js.br +0 -0
- package/assets/devtools/chunk.uyVen0u2.js.gz +0 -0
- package/assets/devtools/chunk.vHjNjQS8.js +0 -1
- package/assets/devtools/chunk.vHjNjQS8.js.br +0 -0
- package/assets/devtools/chunk.vHjNjQS8.js.gz +0 -0
- package/assets/devtools/db.html +0 -21
- package/assets/devtools/db.html.br +0 -0
- package/assets/devtools/db.html.gz +0 -0
- package/assets/devtools/entry.DhzNl8q_.js +0 -79
- package/assets/devtools/entry.DhzNl8q_.js.br +0 -0
- package/assets/devtools/entry.DhzNl8q_.js.gz +0 -0
- package/assets/devtools/env.html +0 -21
- package/assets/devtools/env.html.br +0 -0
- package/assets/devtools/env.html.gz +0 -0
- package/assets/devtools/graph.html +0 -22
- package/assets/devtools/graph.html.br +0 -0
- package/assets/devtools/graph.html.gz +0 -0
- package/assets/devtools/index.html +0 -21
- package/assets/devtools/index.html.br +0 -0
- package/assets/devtools/index.html.gz +0 -0
- package/assets/devtools/logs.html +0 -21
- package/assets/devtools/logs.html.br +0 -0
- package/assets/devtools/logs.html.gz +0 -0
- package/assets/devtools/queues.html +0 -21
- package/assets/devtools/queues.html.br +0 -0
- package/assets/devtools/queues.html.gz +0 -0
- package/assets/devtools/topics.html +0 -21
- package/assets/devtools/topics.html.br +0 -0
- package/assets/devtools/topics.html.gz +0 -0
- package/src/api/DevToolsProvider.ts +0 -157
- package/src/api/providers/DevToolsDatabaseProvider.ts +0 -27
- package/src/api/repositories/LogRepository.ts +0 -8
- package/src/api/schemas/DevCommandMetadata.ts +0 -9
- package/src/ui/components/DevAtomsViewer.tsx +0 -637
- package/src/ui/components/DevCacheInspector.tsx +0 -423
- package/src/ui/components/DevDashboard.tsx +0 -38
- package/src/ui/components/DevEnvExplorer.tsx +0 -462
- package/src/ui/components/DevLogViewer.tsx +0 -252
- package/src/ui/components/DevQueueMonitor.tsx +0 -51
- package/src/ui/components/DevTopicsViewer.tsx +0 -686
- package/src/ui/components/actions/ActionGroup.tsx +0 -37
- package/src/ui/components/actions/ActionItem.tsx +0 -138
- package/src/ui/components/actions/DevActionsExplorer.tsx +0 -132
- package/src/ui/components/actions/MethodBadge.tsx +0 -18
- package/src/ui/components/actions/SchemaViewer.tsx +0 -21
- package/src/ui/components/actions/TryItPanel.tsx +0 -140
- package/src/ui/components/actions/constants.ts +0 -7
- package/src/ui/components/actions/helpers.ts +0 -18
- package/src/ui/components/actions/index.ts +0 -8
- package/src/ui/components/db/ColumnBadge.tsx +0 -55
- package/src/ui/components/db/DevDbStudio.tsx +0 -485
- package/src/ui/components/db/constants.ts +0 -11
- package/src/ui/components/db/index.ts +0 -4
- package/src/ui/components/db/types.ts +0 -7
- package/src/ui/styles.css +0 -1
- /package/src/{api/schemas → schemas}/DevAtomMetadata.ts +0 -0
- /package/src/{api/schemas → schemas}/DevBucketMetadata.ts +0 -0
- /package/src/{api/schemas → schemas}/DevCacheMetadata.ts +0 -0
- /package/src/{api/schemas → schemas}/DevEnvMetadata.ts +0 -0
- /package/src/{api/schemas → schemas}/DevModuleMetadata.ts +0 -0
- /package/src/{api/schemas → schemas}/DevProviderMetadata.ts +0 -0
- /package/src/{api/schemas → schemas}/DevQueueMetadata.ts +0 -0
- /package/src/{api/schemas → schemas}/DevRealmMetadata.ts +0 -0
- /package/src/{api/schemas → schemas}/DevRouteMetadata.ts +0 -0
- /package/src/{api/schemas → schemas}/DevSchedulerMetadata.ts +0 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
import { ActionButton, Flex, TypeForm, ui } from "@alepha/ui";
|
|
2
|
+
import {
|
|
3
|
+
Badge,
|
|
4
|
+
Loader,
|
|
5
|
+
ScrollArea,
|
|
6
|
+
Text,
|
|
7
|
+
TextInput,
|
|
8
|
+
UnstyledButton,
|
|
9
|
+
} from "@mantine/core";
|
|
10
|
+
import {
|
|
11
|
+
IconDatabase,
|
|
12
|
+
IconPlus,
|
|
13
|
+
IconSearch,
|
|
14
|
+
IconTrash,
|
|
15
|
+
} from "@tabler/icons-react";
|
|
16
|
+
import { jsonSchemaToTypeBox, t } from "alepha";
|
|
17
|
+
import { useInject } from "alepha/react";
|
|
18
|
+
import { useForm } from "alepha/react/form";
|
|
19
|
+
import { useRouter } from "alepha/react/router";
|
|
20
|
+
import { HttpClient } from "alepha/server";
|
|
21
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
22
|
+
import { TreeView, type TreeViewNode } from "../shared/TreeView.tsx";
|
|
23
|
+
|
|
24
|
+
const EMPTY_SCHEMA = t.object({});
|
|
25
|
+
|
|
26
|
+
const toTypeBoxSchema = (jsonSchema: any): any => {
|
|
27
|
+
if (!jsonSchema) return null;
|
|
28
|
+
try {
|
|
29
|
+
const converted = jsonSchemaToTypeBox(jsonSchema);
|
|
30
|
+
if (converted?.properties) return converted;
|
|
31
|
+
} catch {
|
|
32
|
+
// Schema conversion failed
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const RecordForm = ({
|
|
38
|
+
entity,
|
|
39
|
+
record,
|
|
40
|
+
isNew,
|
|
41
|
+
onSave,
|
|
42
|
+
onDelete,
|
|
43
|
+
pkColumn,
|
|
44
|
+
}: {
|
|
45
|
+
entity: any;
|
|
46
|
+
record: any;
|
|
47
|
+
isNew: boolean;
|
|
48
|
+
onSave: (values: any) => void;
|
|
49
|
+
onDelete: () => void;
|
|
50
|
+
pkColumn: string;
|
|
51
|
+
}) => {
|
|
52
|
+
const schema = useMemo(() => {
|
|
53
|
+
const jsonSchema = isNew ? entity.insertSchema : entity.updateSchema;
|
|
54
|
+
return toTypeBoxSchema(jsonSchema) ?? EMPTY_SCHEMA;
|
|
55
|
+
}, [entity, isNew]);
|
|
56
|
+
|
|
57
|
+
const form = useForm(
|
|
58
|
+
{
|
|
59
|
+
schema,
|
|
60
|
+
handler: () => {},
|
|
61
|
+
initialValues: isNew ? undefined : record,
|
|
62
|
+
},
|
|
63
|
+
[schema, record, isNew],
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Flex direction="column" gap="md">
|
|
68
|
+
<Flex justify="space-between">
|
|
69
|
+
<Text fz="sm" fw={600}>
|
|
70
|
+
{isNew
|
|
71
|
+
? "New Record"
|
|
72
|
+
: `Edit Record (${pkColumn}: ${record?.[pkColumn]})`}
|
|
73
|
+
</Text>
|
|
74
|
+
<Flex gap="xs">
|
|
75
|
+
<ActionButton size="xs" onClick={() => onSave(form.currentValues)}>
|
|
76
|
+
{isNew ? "Create" : "Save"}
|
|
77
|
+
</ActionButton>
|
|
78
|
+
{!isNew && (
|
|
79
|
+
<ActionButton
|
|
80
|
+
size="sm"
|
|
81
|
+
variant="light"
|
|
82
|
+
intent="danger"
|
|
83
|
+
onClick={onDelete}
|
|
84
|
+
icon={<IconTrash size={14} />}
|
|
85
|
+
/>
|
|
86
|
+
)}
|
|
87
|
+
</Flex>
|
|
88
|
+
</Flex>
|
|
89
|
+
<TypeForm form={form} skipSubmitButton skipFormElement columns={1} />
|
|
90
|
+
</Flex>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** Parse /db/editor/:table/:id from pathname */
|
|
95
|
+
const parseEditorPath = (pathname: string) => {
|
|
96
|
+
const prefix = "/db/editor/";
|
|
97
|
+
if (!pathname.startsWith(prefix)) return { table: "", recordId: "" };
|
|
98
|
+
const rest = pathname.slice(prefix.length);
|
|
99
|
+
const slashIdx = rest.indexOf("/");
|
|
100
|
+
if (slashIdx === -1) return { table: decodeURIComponent(rest), recordId: "" };
|
|
101
|
+
return {
|
|
102
|
+
table: decodeURIComponent(rest.slice(0, slashIdx)),
|
|
103
|
+
recordId: decodeURIComponent(rest.slice(slashIdx + 1)),
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const DatabaseEditor = ({ entities }: { entities: any[] }) => {
|
|
108
|
+
const http = useInject(HttpClient);
|
|
109
|
+
const router = useRouter();
|
|
110
|
+
const [records, setRecords] = useState<any[]>([]);
|
|
111
|
+
const [loading, setLoading] = useState(false);
|
|
112
|
+
const [search, setSearch] = useState("");
|
|
113
|
+
const [pageInfo, setPageInfo] = useState<any>(null);
|
|
114
|
+
|
|
115
|
+
const { table: selectedEntity, recordId } = parseEditorPath(router.pathname);
|
|
116
|
+
const isNew = recordId === "new";
|
|
117
|
+
|
|
118
|
+
const entity = entities.find((e) => e.name === selectedEntity);
|
|
119
|
+
const pkColumn =
|
|
120
|
+
entity?.columns?.find((c: any) => c.primaryKey)?.name ?? "id";
|
|
121
|
+
|
|
122
|
+
const fetchRecords = useCallback(async () => {
|
|
123
|
+
if (!selectedEntity) return;
|
|
124
|
+
setLoading(true);
|
|
125
|
+
try {
|
|
126
|
+
const res = await http.fetch(
|
|
127
|
+
`/__devtools/api/db/${selectedEntity}/records?size=50`,
|
|
128
|
+
);
|
|
129
|
+
setRecords((res.data as any)?.content ?? []);
|
|
130
|
+
setPageInfo((res.data as any)?.page);
|
|
131
|
+
} catch {
|
|
132
|
+
setRecords([]);
|
|
133
|
+
} finally {
|
|
134
|
+
setLoading(false);
|
|
135
|
+
}
|
|
136
|
+
}, [http, selectedEntity]);
|
|
137
|
+
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
fetchRecords();
|
|
140
|
+
}, [selectedEntity, fetchRecords]);
|
|
141
|
+
|
|
142
|
+
const selectedRecord = useMemo(() => {
|
|
143
|
+
if (!recordId || isNew) return null;
|
|
144
|
+
return records.find((r) => String(r[pkColumn]) === recordId) ?? null;
|
|
145
|
+
}, [records, recordId, isNew, pkColumn]);
|
|
146
|
+
|
|
147
|
+
const navigateToEntity = useCallback(
|
|
148
|
+
(name: string) => {
|
|
149
|
+
router.push(`/db/editor/${encodeURIComponent(name)}`);
|
|
150
|
+
},
|
|
151
|
+
[router],
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const navigateToRecord = useCallback(
|
|
155
|
+
(record: any) => {
|
|
156
|
+
const id = record[pkColumn];
|
|
157
|
+
router.push(
|
|
158
|
+
`/db/editor/${encodeURIComponent(selectedEntity)}/${encodeURIComponent(String(id))}`,
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
[router, selectedEntity, pkColumn],
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
const navigateToNew = useCallback(() => {
|
|
165
|
+
router.push(`/db/editor/${encodeURIComponent(selectedEntity)}/new`);
|
|
166
|
+
}, [router, selectedEntity]);
|
|
167
|
+
|
|
168
|
+
const handleSave = async (data: any) => {
|
|
169
|
+
try {
|
|
170
|
+
if (isNew) {
|
|
171
|
+
await http.fetch(`/__devtools/api/db/${selectedEntity}/records`, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
body: JSON.stringify(data),
|
|
174
|
+
headers: { "Content-Type": "application/json" },
|
|
175
|
+
});
|
|
176
|
+
router.push(`/db/editor/${encodeURIComponent(selectedEntity)}`);
|
|
177
|
+
} else if (selectedRecord) {
|
|
178
|
+
const idValue = selectedRecord[pkColumn];
|
|
179
|
+
await http.fetch(
|
|
180
|
+
`/__devtools/api/db/${selectedEntity}/records/${idValue}`,
|
|
181
|
+
{
|
|
182
|
+
method: "PUT",
|
|
183
|
+
body: JSON.stringify(data),
|
|
184
|
+
headers: { "Content-Type": "application/json" },
|
|
185
|
+
},
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
await fetchRecords();
|
|
189
|
+
} catch {
|
|
190
|
+
// handle error
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const handleDelete = async () => {
|
|
195
|
+
if (!selectedRecord) return;
|
|
196
|
+
const idValue = selectedRecord[pkColumn];
|
|
197
|
+
try {
|
|
198
|
+
await http.fetch(
|
|
199
|
+
`/__devtools/api/db/${selectedEntity}/records/${idValue}`,
|
|
200
|
+
{ method: "DELETE" },
|
|
201
|
+
);
|
|
202
|
+
router.push(`/db/editor/${encodeURIComponent(selectedEntity)}`);
|
|
203
|
+
await fetchRecords();
|
|
204
|
+
} catch {
|
|
205
|
+
// handle error
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const entityNodes: TreeViewNode[] = useMemo(() => {
|
|
210
|
+
const filtered = entities.filter((e) =>
|
|
211
|
+
e.name.toLowerCase().includes(search.toLowerCase()),
|
|
212
|
+
);
|
|
213
|
+
return filtered.map((e) => ({
|
|
214
|
+
id: `entity:${e.name}`,
|
|
215
|
+
label: e.name,
|
|
216
|
+
icon: (
|
|
217
|
+
<IconDatabase
|
|
218
|
+
size={13}
|
|
219
|
+
color="var(--mantine-color-blue-text)"
|
|
220
|
+
style={{ flexShrink: 0 }}
|
|
221
|
+
/>
|
|
222
|
+
),
|
|
223
|
+
badge: (
|
|
224
|
+
<Badge size="xs" variant="light" color="gray">
|
|
225
|
+
{e.columns?.length ?? 0}
|
|
226
|
+
</Badge>
|
|
227
|
+
),
|
|
228
|
+
}));
|
|
229
|
+
}, [entities, search]);
|
|
230
|
+
|
|
231
|
+
const handleEntitySelect = useCallback(
|
|
232
|
+
(id: string) => {
|
|
233
|
+
const name = id.replace(/^entity:/, "");
|
|
234
|
+
navigateToEntity(name);
|
|
235
|
+
},
|
|
236
|
+
[navigateToEntity],
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const emptyOpenNodes = useMemo(() => new Set<string>(), []);
|
|
240
|
+
const selectedEntityId = selectedEntity ? `entity:${selectedEntity}` : "";
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<Flex style={{ flex: 1, overflow: "hidden" }}>
|
|
244
|
+
{/* Entity list */}
|
|
245
|
+
<Flex
|
|
246
|
+
w={200}
|
|
247
|
+
style={{
|
|
248
|
+
borderRight: `1px solid ${ui.colors.border}`,
|
|
249
|
+
flexShrink: 0,
|
|
250
|
+
display: "flex",
|
|
251
|
+
flexDirection: "column",
|
|
252
|
+
}}
|
|
253
|
+
>
|
|
254
|
+
<Flex p="xs">
|
|
255
|
+
<TextInput
|
|
256
|
+
size="xs"
|
|
257
|
+
placeholder="Filter tables..."
|
|
258
|
+
leftSection={<IconSearch size={14} />}
|
|
259
|
+
value={search}
|
|
260
|
+
onChange={(e) => setSearch(e.currentTarget.value)}
|
|
261
|
+
/>
|
|
262
|
+
</Flex>
|
|
263
|
+
<ScrollArea style={{ flex: 1 }} px="xs">
|
|
264
|
+
<TreeView
|
|
265
|
+
nodes={entityNodes}
|
|
266
|
+
selectedId={selectedEntityId}
|
|
267
|
+
openNodes={emptyOpenNodes}
|
|
268
|
+
onSelect={handleEntitySelect}
|
|
269
|
+
onToggle={() => {}}
|
|
270
|
+
showLeafCount={false}
|
|
271
|
+
/>
|
|
272
|
+
</ScrollArea>
|
|
273
|
+
</Flex>
|
|
274
|
+
|
|
275
|
+
{/* Records list */}
|
|
276
|
+
{selectedEntity && (
|
|
277
|
+
<Flex
|
|
278
|
+
w={200}
|
|
279
|
+
style={{
|
|
280
|
+
borderRight: `1px solid ${ui.colors.border}`,
|
|
281
|
+
flexShrink: 0,
|
|
282
|
+
display: "flex",
|
|
283
|
+
flexDirection: "column",
|
|
284
|
+
}}
|
|
285
|
+
>
|
|
286
|
+
<Flex
|
|
287
|
+
px="xs"
|
|
288
|
+
py="xs"
|
|
289
|
+
style={{
|
|
290
|
+
borderBottom: `1px solid ${ui.colors.border}`,
|
|
291
|
+
flexShrink: 0,
|
|
292
|
+
}}
|
|
293
|
+
>
|
|
294
|
+
<Flex gap="xs" justify="space-between">
|
|
295
|
+
<Text fz={10} c="dimmed" tt="uppercase" fw={600} lts={0.5}>
|
|
296
|
+
Records{" "}
|
|
297
|
+
{pageInfo?.totalElements != null &&
|
|
298
|
+
`(${pageInfo.totalElements})`}
|
|
299
|
+
</Text>
|
|
300
|
+
<ActionButton
|
|
301
|
+
size="xs"
|
|
302
|
+
variant="subtle"
|
|
303
|
+
color="teal"
|
|
304
|
+
onClick={navigateToNew}
|
|
305
|
+
icon={<IconPlus size={14} />}
|
|
306
|
+
/>
|
|
307
|
+
</Flex>
|
|
308
|
+
</Flex>
|
|
309
|
+
<ScrollArea style={{ flex: 1 }} px="xs" py="xs">
|
|
310
|
+
<UnstyledButton
|
|
311
|
+
w="100%"
|
|
312
|
+
py={4}
|
|
313
|
+
className="devtools-tree-node"
|
|
314
|
+
data-selected={isNew || undefined}
|
|
315
|
+
style={{
|
|
316
|
+
borderRadius: 6,
|
|
317
|
+
paddingLeft: 8,
|
|
318
|
+
paddingRight: 8,
|
|
319
|
+
transition: "background 100ms ease",
|
|
320
|
+
}}
|
|
321
|
+
onClick={navigateToNew}
|
|
322
|
+
>
|
|
323
|
+
<Flex gap={8} wrap="nowrap">
|
|
324
|
+
<IconPlus
|
|
325
|
+
size={13}
|
|
326
|
+
color="var(--mantine-color-teal-text)"
|
|
327
|
+
style={{ flexShrink: 0 }}
|
|
328
|
+
/>
|
|
329
|
+
<Text fz={12} c="teal">
|
|
330
|
+
New Record
|
|
331
|
+
</Text>
|
|
332
|
+
</Flex>
|
|
333
|
+
</UnstyledButton>
|
|
334
|
+
{loading ? (
|
|
335
|
+
<Flex justify="center" py="md">
|
|
336
|
+
<Loader size="xs" />
|
|
337
|
+
</Flex>
|
|
338
|
+
) : (
|
|
339
|
+
records.map((record, i) => {
|
|
340
|
+
const idVal = record[pkColumn] ?? i;
|
|
341
|
+
const isActive = !isNew && String(idVal) === recordId;
|
|
342
|
+
return (
|
|
343
|
+
<UnstyledButton
|
|
344
|
+
key={String(idVal)}
|
|
345
|
+
w="100%"
|
|
346
|
+
py={4}
|
|
347
|
+
className="devtools-tree-node"
|
|
348
|
+
data-selected={isActive || undefined}
|
|
349
|
+
style={{
|
|
350
|
+
borderRadius: 6,
|
|
351
|
+
paddingLeft: 8,
|
|
352
|
+
paddingRight: 8,
|
|
353
|
+
transition: "background 100ms ease",
|
|
354
|
+
}}
|
|
355
|
+
onClick={() => navigateToRecord(record)}
|
|
356
|
+
>
|
|
357
|
+
<Text fz={12} ff="monospace" truncate>
|
|
358
|
+
{pkColumn}: {String(idVal)}
|
|
359
|
+
</Text>
|
|
360
|
+
</UnstyledButton>
|
|
361
|
+
);
|
|
362
|
+
})
|
|
363
|
+
)}
|
|
364
|
+
</ScrollArea>
|
|
365
|
+
</Flex>
|
|
366
|
+
)}
|
|
367
|
+
|
|
368
|
+
{/* Editor panel */}
|
|
369
|
+
<Flex style={{ flex: 1, overflow: "auto" }} p="md">
|
|
370
|
+
{!selectedEntity && (
|
|
371
|
+
<Flex align="center" justify="center" h="100%">
|
|
372
|
+
<Text c="dimmed" fz="sm">
|
|
373
|
+
Select a table to browse records
|
|
374
|
+
</Text>
|
|
375
|
+
</Flex>
|
|
376
|
+
)}
|
|
377
|
+
|
|
378
|
+
{selectedEntity && !selectedRecord && !isNew && (
|
|
379
|
+
<Flex align="center" justify="center" h="100%">
|
|
380
|
+
<Text c="dimmed" fz="sm">
|
|
381
|
+
Select a record or create a new one
|
|
382
|
+
</Text>
|
|
383
|
+
</Flex>
|
|
384
|
+
)}
|
|
385
|
+
|
|
386
|
+
{(selectedRecord || isNew) && entity && (
|
|
387
|
+
<RecordForm
|
|
388
|
+
entity={entity}
|
|
389
|
+
record={selectedRecord}
|
|
390
|
+
isNew={isNew}
|
|
391
|
+
onSave={handleSave}
|
|
392
|
+
onDelete={handleDelete}
|
|
393
|
+
pkColumn={pkColumn}
|
|
394
|
+
/>
|
|
395
|
+
)}
|
|
396
|
+
</Flex>
|
|
397
|
+
</Flex>
|
|
398
|
+
);
|
|
399
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { devMetadataSchema } from "@alepha/devtools";
|
|
2
|
+
import { Flex } from "@mantine/core";
|
|
3
|
+
import { useInject } from "alepha/react";
|
|
4
|
+
import { HttpClient } from "alepha/server";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { DatabaseErd } from "./DatabaseErd.tsx";
|
|
7
|
+
|
|
8
|
+
const DatabaseErdPage = () => {
|
|
9
|
+
const http = useInject(HttpClient);
|
|
10
|
+
const [entities, setEntities] = useState<any[]>([]);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
http
|
|
14
|
+
.fetch("/__devtools/api/metadata", {
|
|
15
|
+
schema: { response: devMetadataSchema },
|
|
16
|
+
})
|
|
17
|
+
.then((res) => setEntities(res.data.entities ?? []))
|
|
18
|
+
.catch(() => {});
|
|
19
|
+
}, [http]);
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Flex flex={1} style={{ position: "relative" }}>
|
|
23
|
+
<DatabaseErd entities={entities} />
|
|
24
|
+
</Flex>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default DatabaseErdPage;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ui } from "@alepha/ui";
|
|
2
|
+
import { Flex } from "@mantine/core";
|
|
3
|
+
import {
|
|
4
|
+
Background,
|
|
5
|
+
BackgroundVariant,
|
|
6
|
+
Controls,
|
|
7
|
+
type Edge,
|
|
8
|
+
MiniMap,
|
|
9
|
+
type Node,
|
|
10
|
+
ReactFlow,
|
|
11
|
+
ReactFlowProvider,
|
|
12
|
+
useEdgesState,
|
|
13
|
+
useNodesState,
|
|
14
|
+
} from "@xyflow/react";
|
|
15
|
+
import "@xyflow/react/dist/style.css";
|
|
16
|
+
import { useEffect, useMemo } from "react";
|
|
17
|
+
import { EntityNode } from "./EntityNode.tsx";
|
|
18
|
+
|
|
19
|
+
const nodeTypes = { entity: EntityNode };
|
|
20
|
+
|
|
21
|
+
const buildGraph = (entities: any[]): { nodes: Node[]; edges: Edge[] } => {
|
|
22
|
+
const nodes: Node[] = entities.map((entity, i) => {
|
|
23
|
+
const cols = Math.ceil(Math.sqrt(entities.length));
|
|
24
|
+
const row = Math.floor(i / cols);
|
|
25
|
+
const col = i % cols;
|
|
26
|
+
return {
|
|
27
|
+
id: entity.name,
|
|
28
|
+
type: "entity",
|
|
29
|
+
position: { x: col * 320, y: row * 300 },
|
|
30
|
+
data: entity,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const edges: Edge[] = [];
|
|
35
|
+
for (const entity of entities) {
|
|
36
|
+
for (const column of entity.columns ?? []) {
|
|
37
|
+
if (column.ref) {
|
|
38
|
+
edges.push({
|
|
39
|
+
id: `${entity.name}.${column.name}->${column.ref.entity}`,
|
|
40
|
+
source: entity.name,
|
|
41
|
+
target: column.ref.entity,
|
|
42
|
+
label: `${column.name} → ${column.ref.column}`,
|
|
43
|
+
style: { stroke: "var(--mantine-color-blue-6)", strokeWidth: 1.5 },
|
|
44
|
+
labelStyle: { fontSize: 10, fill: "var(--mantine-color-dimmed)" },
|
|
45
|
+
animated: true,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return { nodes, edges };
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const ErdFlow = ({ entities }: { entities: any[] }) => {
|
|
55
|
+
const graph = useMemo(() => buildGraph(entities), [entities]);
|
|
56
|
+
const [nodes, setNodes, onNodesChange] = useNodesState(graph.nodes);
|
|
57
|
+
const [edges, setEdges, onEdgesChange] = useEdgesState(graph.edges);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
setNodes(graph.nodes);
|
|
61
|
+
setEdges(graph.edges);
|
|
62
|
+
}, [graph, setNodes, setEdges]);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<ReactFlow
|
|
66
|
+
nodes={nodes}
|
|
67
|
+
edges={edges}
|
|
68
|
+
onNodesChange={onNodesChange}
|
|
69
|
+
onEdgesChange={onEdgesChange}
|
|
70
|
+
nodeTypes={nodeTypes}
|
|
71
|
+
fitView
|
|
72
|
+
fitViewOptions={{ padding: 0.2 }}
|
|
73
|
+
minZoom={0.1}
|
|
74
|
+
maxZoom={2}
|
|
75
|
+
proOptions={{ hideAttribution: true }}
|
|
76
|
+
style={{ background: ui.colors.background }}
|
|
77
|
+
>
|
|
78
|
+
<Background variant={BackgroundVariant.Dots} gap={20} size={1} />
|
|
79
|
+
<Controls />
|
|
80
|
+
<MiniMap
|
|
81
|
+
nodeColor="var(--mantine-color-dark-4)"
|
|
82
|
+
maskColor="rgba(0,0,0,0.6)"
|
|
83
|
+
style={{ backgroundColor: ui.colors.surface }}
|
|
84
|
+
/>
|
|
85
|
+
</ReactFlow>
|
|
86
|
+
);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const DatabaseErd = ({ entities }: { entities: any[] }) => {
|
|
90
|
+
return (
|
|
91
|
+
<Flex
|
|
92
|
+
flex={1}
|
|
93
|
+
h="100%"
|
|
94
|
+
style={{
|
|
95
|
+
position: "absolute",
|
|
96
|
+
top: 0,
|
|
97
|
+
left: 0,
|
|
98
|
+
right: 0,
|
|
99
|
+
bottom: 0,
|
|
100
|
+
}}
|
|
101
|
+
>
|
|
102
|
+
<ReactFlowProvider>
|
|
103
|
+
<ErdFlow entities={entities} />
|
|
104
|
+
</ReactFlowProvider>
|
|
105
|
+
</Flex>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Flex, ui } from "@alepha/ui";
|
|
2
|
+
import { SegmentedControl } from "@mantine/core";
|
|
3
|
+
import { NestedView, useRouter, useRouterState } from "alepha/react/router";
|
|
4
|
+
|
|
5
|
+
export const DevDatabase = () => {
|
|
6
|
+
const router = useRouter();
|
|
7
|
+
const state = useRouterState();
|
|
8
|
+
const tab = state.url.pathname.startsWith("/db/editor") ? "editor" : "erd";
|
|
9
|
+
|
|
10
|
+
const handleTabChange = (value: string) => {
|
|
11
|
+
router.push(value === "editor" ? "/db/editor" : "/db/erd");
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Flex direction="column" style={{ flex: 1 }}>
|
|
16
|
+
<Flex
|
|
17
|
+
px="md"
|
|
18
|
+
py="xs"
|
|
19
|
+
style={{ borderBottom: `1px solid ${ui.colors.border}` }}
|
|
20
|
+
>
|
|
21
|
+
<SegmentedControl
|
|
22
|
+
size="xs"
|
|
23
|
+
value={tab}
|
|
24
|
+
onChange={handleTabChange}
|
|
25
|
+
data={[
|
|
26
|
+
{ label: "ERD", value: "erd" },
|
|
27
|
+
{ label: "Editor", value: "editor" },
|
|
28
|
+
]}
|
|
29
|
+
/>
|
|
30
|
+
</Flex>
|
|
31
|
+
<NestedView />
|
|
32
|
+
</Flex>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default DevDatabase;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Flex, ui } from "@alepha/ui";
|
|
2
|
+
import { Badge, Text } from "@mantine/core";
|
|
3
|
+
import { IconKey, IconLink } from "@tabler/icons-react";
|
|
4
|
+
import { Handle, type NodeProps, Position } from "@xyflow/react";
|
|
5
|
+
|
|
6
|
+
export const EntityNode = ({ data }: NodeProps) => {
|
|
7
|
+
const entity = data as any;
|
|
8
|
+
|
|
9
|
+
return (
|
|
10
|
+
<div
|
|
11
|
+
style={{
|
|
12
|
+
background: ui.colors.surface,
|
|
13
|
+
border: `1px solid ${ui.colors.border}`,
|
|
14
|
+
borderRadius: 8,
|
|
15
|
+
minWidth: 240,
|
|
16
|
+
overflow: "hidden",
|
|
17
|
+
}}
|
|
18
|
+
>
|
|
19
|
+
<Handle
|
|
20
|
+
type="target"
|
|
21
|
+
position={Position.Top}
|
|
22
|
+
style={{ background: "var(--mantine-color-blue-6)" }}
|
|
23
|
+
/>
|
|
24
|
+
|
|
25
|
+
{/* Header */}
|
|
26
|
+
<div
|
|
27
|
+
style={{
|
|
28
|
+
padding: "8px 12px",
|
|
29
|
+
borderBottom: `1px solid ${ui.colors.border}`,
|
|
30
|
+
background: ui.colors.elevated,
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
<Flex gap="xs">
|
|
34
|
+
<Text fz="sm" fw={700}>
|
|
35
|
+
{entity.name}
|
|
36
|
+
</Text>
|
|
37
|
+
<Badge size="xs" variant="light" color="gray">
|
|
38
|
+
{entity.provider}
|
|
39
|
+
</Badge>
|
|
40
|
+
</Flex>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
{/* Columns */}
|
|
44
|
+
<Flex direction="column" gap={0} p={0}>
|
|
45
|
+
{(entity.columns ?? []).map((col: any) => (
|
|
46
|
+
<Flex
|
|
47
|
+
key={col.name}
|
|
48
|
+
gap="xs"
|
|
49
|
+
px="sm"
|
|
50
|
+
py={4}
|
|
51
|
+
style={{ borderBottom: `1px solid ${ui.colors.border}20` }}
|
|
52
|
+
wrap="nowrap"
|
|
53
|
+
>
|
|
54
|
+
{col.primaryKey && (
|
|
55
|
+
<IconKey size={10} color="var(--mantine-color-yellow-6)" />
|
|
56
|
+
)}
|
|
57
|
+
{col.ref && (
|
|
58
|
+
<IconLink size={10} color="var(--mantine-color-blue-6)" />
|
|
59
|
+
)}
|
|
60
|
+
{!col.primaryKey && !col.ref && <span style={{ width: 10 }} />}
|
|
61
|
+
<Text fz={11} ff="monospace" style={{ flex: 1 }}>
|
|
62
|
+
{col.name}
|
|
63
|
+
</Text>
|
|
64
|
+
<Text fz={10} c="dimmed" ff="monospace">
|
|
65
|
+
{col.type}
|
|
66
|
+
</Text>
|
|
67
|
+
{col.nullable && (
|
|
68
|
+
<Text fz={9} c="dimmed">
|
|
69
|
+
?
|
|
70
|
+
</Text>
|
|
71
|
+
)}
|
|
72
|
+
</Flex>
|
|
73
|
+
))}
|
|
74
|
+
</Flex>
|
|
75
|
+
|
|
76
|
+
<Handle
|
|
77
|
+
type="source"
|
|
78
|
+
position={Position.Bottom}
|
|
79
|
+
style={{ background: "var(--mantine-color-blue-6)" }}
|
|
80
|
+
/>
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
};
|