@alepha/devtools 0.16.1 → 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.
Files changed (236) hide show
  1. package/README.md +1 -5
  2. package/dist/index.browser.js +224 -0
  3. package/dist/index.browser.js.map +1 -0
  4. package/dist/index.d.ts +349 -321
  5. package/dist/index.js +293 -186
  6. package/dist/index.js.map +1 -1
  7. package/package.json +30 -23
  8. package/src/assets.ts +6 -0
  9. package/src/{api/entities → entities}/logs.ts +2 -2
  10. package/src/index.browser.ts +11 -0
  11. package/src/index.shared.ts +15 -0
  12. package/src/index.ts +11 -37
  13. package/src/{api/providers → providers}/DevToolsMetadataProvider.ts +84 -47
  14. package/src/providers/DevToolsProvider.ts +280 -0
  15. package/src/{api/schemas → schemas}/DevActionMetadata.ts +8 -0
  16. package/src/{api/schemas → schemas}/DevEntityMetadata.ts +3 -0
  17. package/src/{api/schemas → schemas}/DevMetadata.ts +13 -2
  18. package/src/{api/schemas → schemas}/DevPageMetadata.ts +3 -0
  19. package/src/{api/schemas → schemas}/DevTopicMetadata.ts +1 -0
  20. package/src/ui/AppRouter.tsx +55 -59
  21. package/src/ui/components/DevLayout.tsx +104 -84
  22. package/src/ui/components/configuration/ConfigAtoms.page.tsx +5 -0
  23. package/src/ui/components/configuration/ConfigAtoms.tsx +511 -0
  24. package/src/ui/components/configuration/ConfigEnv.page.tsx +5 -0
  25. package/src/ui/components/configuration/ConfigEnv.tsx +230 -0
  26. package/src/ui/components/configuration/DevConfiguration.tsx +36 -0
  27. package/src/ui/components/configuration/index.ts +3 -0
  28. package/src/ui/components/dashboard/DevDashboard.tsx +482 -0
  29. package/src/ui/components/database/DatabaseEditor.page.tsx +23 -0
  30. package/src/ui/components/database/DatabaseEditor.tsx +399 -0
  31. package/src/ui/components/database/DatabaseErd.page.tsx +28 -0
  32. package/src/ui/components/database/DatabaseErd.tsx +107 -0
  33. package/src/ui/components/database/DevDatabase.tsx +36 -0
  34. package/src/ui/components/database/EntityNode.tsx +83 -0
  35. package/src/ui/components/explorer/DevExplorer.tsx +351 -0
  36. package/src/ui/components/explorer/ExplorerTree.tsx +178 -0
  37. package/src/ui/components/explorer/panels/DevPanelAction.tsx +499 -0
  38. package/src/ui/components/explorer/panels/DevPanelCache.tsx +73 -0
  39. package/src/ui/components/explorer/panels/DevPanelPage.tsx +96 -0
  40. package/src/ui/components/explorer/panels/DevPanelQueue.tsx +51 -0
  41. package/src/ui/components/explorer/panels/DevPanelTopic.tsx +56 -0
  42. package/src/ui/components/explorer/panels/index.ts +5 -0
  43. package/src/ui/components/graph/DevDependencyGraph.tsx +35 -60
  44. package/src/ui/components/graph/GraphControls.tsx +10 -11
  45. package/src/ui/components/graph/NodeDetails.tsx +22 -29
  46. package/src/ui/components/graph/ProviderNode.tsx +4 -4
  47. package/src/ui/components/graph/helpers.ts +1 -1
  48. package/src/ui/components/logs/DevLogs.tsx +661 -0
  49. package/src/ui/components/logs/index.ts +1 -0
  50. package/src/ui/components/shared/TreeView.tsx +189 -0
  51. package/src/ui/main.css +17 -0
  52. package/src/ui/main.ts +2 -6
  53. package/LICENSE +0 -21
  54. package/assets/devtools/actions.html +0 -21
  55. package/assets/devtools/actions.html.br +0 -0
  56. package/assets/devtools/actions.html.gz +0 -0
  57. package/assets/devtools/asset.BZV40eAE.css +0 -1
  58. package/assets/devtools/asset.BZV40eAE.css.br +0 -0
  59. package/assets/devtools/asset.BZV40eAE.css.gz +0 -0
  60. package/assets/devtools/asset.CBnMq2vO.css +0 -1
  61. package/assets/devtools/asset.CBnMq2vO.css.br +0 -0
  62. package/assets/devtools/asset.CBnMq2vO.css.gz +0 -0
  63. package/assets/devtools/atoms.html +0 -21
  64. package/assets/devtools/atoms.html.br +0 -0
  65. package/assets/devtools/atoms.html.gz +0 -0
  66. package/assets/devtools/caches.html +0 -21
  67. package/assets/devtools/caches.html.br +0 -0
  68. package/assets/devtools/caches.html.gz +0 -0
  69. package/assets/devtools/chunk.6INqNjF0.js +0 -1
  70. package/assets/devtools/chunk.6INqNjF0.js.br +0 -0
  71. package/assets/devtools/chunk.6INqNjF0.js.gz +0 -0
  72. package/assets/devtools/chunk.9vpWpXSF.js +0 -1
  73. package/assets/devtools/chunk.9vpWpXSF.js.br +0 -0
  74. package/assets/devtools/chunk.9vpWpXSF.js.gz +0 -0
  75. package/assets/devtools/chunk.B4peH6PS.js +0 -1
  76. package/assets/devtools/chunk.B4peH6PS.js.br +0 -0
  77. package/assets/devtools/chunk.B4peH6PS.js.gz +0 -0
  78. package/assets/devtools/chunk.B8CNjZzU.js +0 -1
  79. package/assets/devtools/chunk.B8CNjZzU.js.br +0 -0
  80. package/assets/devtools/chunk.B8CNjZzU.js.gz +0 -0
  81. package/assets/devtools/chunk.Bgd10SVI.js +0 -1
  82. package/assets/devtools/chunk.Bgd10SVI.js.br +0 -0
  83. package/assets/devtools/chunk.Bgd10SVI.js.gz +0 -0
  84. package/assets/devtools/chunk.BjFrJKj1.js +0 -1
  85. package/assets/devtools/chunk.BjFrJKj1.js.br +0 -2
  86. package/assets/devtools/chunk.BjFrJKj1.js.gz +0 -0
  87. package/assets/devtools/chunk.BlqFPyLh.js +0 -1
  88. package/assets/devtools/chunk.BlqFPyLh.js.br +0 -0
  89. package/assets/devtools/chunk.BlqFPyLh.js.gz +0 -0
  90. package/assets/devtools/chunk.BqBNmfN9.js +0 -1
  91. package/assets/devtools/chunk.BqBNmfN9.js.br +0 -0
  92. package/assets/devtools/chunk.BqBNmfN9.js.gz +0 -0
  93. package/assets/devtools/chunk.Bt0_vkJm.js +0 -2
  94. package/assets/devtools/chunk.Bt0_vkJm.js.br +0 -0
  95. package/assets/devtools/chunk.Bt0_vkJm.js.gz +0 -0
  96. package/assets/devtools/chunk.C3GuU4pz.js +0 -2
  97. package/assets/devtools/chunk.C3GuU4pz.js.br +0 -0
  98. package/assets/devtools/chunk.C3GuU4pz.js.gz +0 -0
  99. package/assets/devtools/chunk.CGwoN_Mo.js +0 -1
  100. package/assets/devtools/chunk.CGwoN_Mo.js.br +0 -0
  101. package/assets/devtools/chunk.CGwoN_Mo.js.gz +0 -0
  102. package/assets/devtools/chunk.CJCvhHA7.js +0 -1
  103. package/assets/devtools/chunk.CJCvhHA7.js.br +0 -2
  104. package/assets/devtools/chunk.CJCvhHA7.js.gz +0 -0
  105. package/assets/devtools/chunk.CKr2VE6v.js +0 -1
  106. package/assets/devtools/chunk.CKr2VE6v.js.br +0 -0
  107. package/assets/devtools/chunk.CKr2VE6v.js.gz +0 -0
  108. package/assets/devtools/chunk.CLvTwbkw.js +0 -1
  109. package/assets/devtools/chunk.CLvTwbkw.js.br +0 -0
  110. package/assets/devtools/chunk.CLvTwbkw.js.gz +0 -0
  111. package/assets/devtools/chunk.CR13dZhE.js +0 -7
  112. package/assets/devtools/chunk.CR13dZhE.js.br +0 -0
  113. package/assets/devtools/chunk.CR13dZhE.js.gz +0 -0
  114. package/assets/devtools/chunk.C_C-cVqs.js +0 -1
  115. package/assets/devtools/chunk.C_C-cVqs.js.br +0 -1
  116. package/assets/devtools/chunk.C_C-cVqs.js.gz +0 -0
  117. package/assets/devtools/chunk.CjevPbPy.js +0 -1
  118. package/assets/devtools/chunk.CjevPbPy.js.br +0 -0
  119. package/assets/devtools/chunk.CjevPbPy.js.gz +0 -0
  120. package/assets/devtools/chunk.CkNMZqAe.js +0 -1
  121. package/assets/devtools/chunk.CkNMZqAe.js.br +0 -0
  122. package/assets/devtools/chunk.CkNMZqAe.js.gz +0 -0
  123. package/assets/devtools/chunk.Cl1Mlnqx.js +0 -1
  124. package/assets/devtools/chunk.Cl1Mlnqx.js.br +0 -0
  125. package/assets/devtools/chunk.Cl1Mlnqx.js.gz +0 -0
  126. package/assets/devtools/chunk.CyY8OGdZ.js +0 -1
  127. package/assets/devtools/chunk.CyY8OGdZ.js.br +0 -0
  128. package/assets/devtools/chunk.CyY8OGdZ.js.gz +0 -0
  129. package/assets/devtools/chunk.Cyx9kLqD.js +0 -1
  130. package/assets/devtools/chunk.Cyx9kLqD.js.br +0 -0
  131. package/assets/devtools/chunk.Cyx9kLqD.js.gz +0 -0
  132. package/assets/devtools/chunk.D1MGgxUI.js +0 -1
  133. package/assets/devtools/chunk.D1MGgxUI.js.br +0 -0
  134. package/assets/devtools/chunk.D1MGgxUI.js.gz +0 -0
  135. package/assets/devtools/chunk.D5Ci-dwk.js +0 -1
  136. package/assets/devtools/chunk.D5Ci-dwk.js.br +0 -0
  137. package/assets/devtools/chunk.D5Ci-dwk.js.gz +0 -0
  138. package/assets/devtools/chunk.DFrWQW5x.js +0 -9
  139. package/assets/devtools/chunk.DFrWQW5x.js.br +0 -0
  140. package/assets/devtools/chunk.DFrWQW5x.js.gz +0 -0
  141. package/assets/devtools/chunk.DaVlli3f.js +0 -1
  142. package/assets/devtools/chunk.DaVlli3f.js.br +0 -0
  143. package/assets/devtools/chunk.DaVlli3f.js.gz +0 -0
  144. package/assets/devtools/chunk.DdyBCs50.js +0 -1
  145. package/assets/devtools/chunk.DdyBCs50.js.br +0 -0
  146. package/assets/devtools/chunk.DdyBCs50.js.gz +0 -0
  147. package/assets/devtools/chunk.Dl0THvrP.js +0 -1
  148. package/assets/devtools/chunk.Dl0THvrP.js.br +0 -0
  149. package/assets/devtools/chunk.Dl0THvrP.js.gz +0 -0
  150. package/assets/devtools/chunk.DwUNDm68.js +0 -1
  151. package/assets/devtools/chunk.DwUNDm68.js.br +0 -0
  152. package/assets/devtools/chunk.DwUNDm68.js.gz +0 -0
  153. package/assets/devtools/chunk.DzDkh4C6.js +0 -1
  154. package/assets/devtools/chunk.DzDkh4C6.js.br +0 -0
  155. package/assets/devtools/chunk.DzDkh4C6.js.gz +0 -0
  156. package/assets/devtools/chunk.QTExp4CY.js +0 -1
  157. package/assets/devtools/chunk.QTExp4CY.js.br +0 -0
  158. package/assets/devtools/chunk.QTExp4CY.js.gz +0 -0
  159. package/assets/devtools/chunk.ReCPcJln.js +0 -1
  160. package/assets/devtools/chunk.ReCPcJln.js.br +0 -0
  161. package/assets/devtools/chunk.ReCPcJln.js.gz +0 -0
  162. package/assets/devtools/chunk.UEhIKOMY.js +0 -1
  163. package/assets/devtools/chunk.UEhIKOMY.js.br +0 -0
  164. package/assets/devtools/chunk.UEhIKOMY.js.gz +0 -0
  165. package/assets/devtools/chunk.mWQqK3dU.js +0 -1
  166. package/assets/devtools/chunk.mWQqK3dU.js.br +0 -0
  167. package/assets/devtools/chunk.mWQqK3dU.js.gz +0 -0
  168. package/assets/devtools/chunk.uyVen0u2.js +0 -1
  169. package/assets/devtools/chunk.uyVen0u2.js.br +0 -0
  170. package/assets/devtools/chunk.uyVen0u2.js.gz +0 -0
  171. package/assets/devtools/chunk.yLRX_cUF.js +0 -1
  172. package/assets/devtools/chunk.yLRX_cUF.js.br +0 -0
  173. package/assets/devtools/chunk.yLRX_cUF.js.gz +0 -0
  174. package/assets/devtools/chunk.zuZxBYZg.js +0 -1
  175. package/assets/devtools/chunk.zuZxBYZg.js.br +0 -0
  176. package/assets/devtools/chunk.zuZxBYZg.js.gz +0 -0
  177. package/assets/devtools/db.html +0 -21
  178. package/assets/devtools/db.html.br +0 -0
  179. package/assets/devtools/db.html.gz +0 -0
  180. package/assets/devtools/entry.Cry3rxEI.js +0 -79
  181. package/assets/devtools/entry.Cry3rxEI.js.br +0 -0
  182. package/assets/devtools/entry.Cry3rxEI.js.gz +0 -0
  183. package/assets/devtools/env.html +0 -21
  184. package/assets/devtools/env.html.br +0 -0
  185. package/assets/devtools/env.html.gz +0 -0
  186. package/assets/devtools/graph.html +0 -22
  187. package/assets/devtools/graph.html.br +0 -0
  188. package/assets/devtools/graph.html.gz +0 -0
  189. package/assets/devtools/index.html +0 -21
  190. package/assets/devtools/index.html.br +0 -0
  191. package/assets/devtools/index.html.gz +0 -0
  192. package/assets/devtools/logs.html +0 -21
  193. package/assets/devtools/logs.html.br +0 -0
  194. package/assets/devtools/logs.html.gz +0 -0
  195. package/assets/devtools/queues.html +0 -21
  196. package/assets/devtools/queues.html.br +0 -0
  197. package/assets/devtools/queues.html.gz +0 -0
  198. package/assets/devtools/topics.html +0 -21
  199. package/assets/devtools/topics.html.br +0 -0
  200. package/assets/devtools/topics.html.gz +0 -0
  201. package/src/api/DevToolsProvider.ts +0 -157
  202. package/src/api/providers/DevToolsDatabaseProvider.ts +0 -27
  203. package/src/api/repositories/LogRepository.ts +0 -8
  204. package/src/api/schemas/DevCommandMetadata.ts +0 -9
  205. package/src/ui/components/DevAtomsViewer.tsx +0 -637
  206. package/src/ui/components/DevCacheInspector.tsx +0 -423
  207. package/src/ui/components/DevDashboard.tsx +0 -38
  208. package/src/ui/components/DevEnvExplorer.tsx +0 -462
  209. package/src/ui/components/DevLogViewer.tsx +0 -252
  210. package/src/ui/components/DevQueueMonitor.tsx +0 -51
  211. package/src/ui/components/DevTopicsViewer.tsx +0 -686
  212. package/src/ui/components/actions/ActionGroup.tsx +0 -37
  213. package/src/ui/components/actions/ActionItem.tsx +0 -138
  214. package/src/ui/components/actions/DevActionsExplorer.tsx +0 -132
  215. package/src/ui/components/actions/MethodBadge.tsx +0 -18
  216. package/src/ui/components/actions/SchemaViewer.tsx +0 -21
  217. package/src/ui/components/actions/TryItPanel.tsx +0 -140
  218. package/src/ui/components/actions/constants.ts +0 -7
  219. package/src/ui/components/actions/helpers.ts +0 -18
  220. package/src/ui/components/actions/index.ts +0 -8
  221. package/src/ui/components/db/ColumnBadge.tsx +0 -55
  222. package/src/ui/components/db/DevDbStudio.tsx +0 -485
  223. package/src/ui/components/db/constants.ts +0 -11
  224. package/src/ui/components/db/index.ts +0 -4
  225. package/src/ui/components/db/types.ts +0 -7
  226. package/src/ui/styles.css +0 -1
  227. /package/src/{api/schemas → schemas}/DevAtomMetadata.ts +0 -0
  228. /package/src/{api/schemas → schemas}/DevBucketMetadata.ts +0 -0
  229. /package/src/{api/schemas → schemas}/DevCacheMetadata.ts +0 -0
  230. /package/src/{api/schemas → schemas}/DevEnvMetadata.ts +0 -0
  231. /package/src/{api/schemas → schemas}/DevModuleMetadata.ts +0 -0
  232. /package/src/{api/schemas → schemas}/DevProviderMetadata.ts +0 -0
  233. /package/src/{api/schemas → schemas}/DevQueueMetadata.ts +0 -0
  234. /package/src/{api/schemas → schemas}/DevRealmMetadata.ts +0 -0
  235. /package/src/{api/schemas → schemas}/DevRouteMetadata.ts +0 -0
  236. /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
+ };