sqlite-hub 0.2.0 → 0.3.2

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.
@@ -1,9 +1,10 @@
1
- import { renderMetricCard } from "../components/metricCard.js";
2
1
  import { renderPageHeader } from "../components/pageHeader.js";
3
- import { getCurrentStructureEntryDetail } from "../store.js";
2
+ import { clearInspector, renderInspector } from "../components/structureGraph.js";
4
3
  import { escapeHtml, formatNumber } from "../utils/format.js";
5
4
 
6
- function renderEntryGroup(title, entries, activeName) {
5
+ function renderEntryGroup(title, entries, activeName, options = {}) {
6
+ const { compact = false, showMeta = true } = options;
7
+
7
8
  return `
8
9
  <section class="shell-section p-5">
9
10
  <div class="mb-4 text-[10px] font-bold uppercase tracking-[0.25em] text-primary-container">
@@ -17,13 +18,18 @@ function renderEntryGroup(title, entries, activeName) {
17
18
  .map(
18
19
  (entry) => `
19
20
  <button
20
- class="w-full border px-3 py-3 text-left transition-colors ${
21
+ class="w-full border px-3 ${compact ? "py-2.5" : "py-3"} text-left transition-colors ${
21
22
  entry.name === activeName
22
23
  ? "border-primary-container/30 bg-surface-container-high"
23
24
  : "border-outline-variant/10 bg-surface-container-lowest hover:bg-surface-container-high"
24
25
  }"
25
26
  data-action="select-structure-entry"
26
27
  data-entry-name="${escapeHtml(entry.name)}"
28
+ ${
29
+ entry.type === "table"
30
+ ? `data-structure-entry-name="${escapeHtml(entry.name)}"`
31
+ : ""
32
+ }
27
33
  type="button"
28
34
  >
29
35
  <div class="font-mono text-xs ${
@@ -33,9 +39,15 @@ function renderEntryGroup(title, entries, activeName) {
33
39
  }">
34
40
  ${escapeHtml(entry.name)}
35
41
  </div>
36
- <div class="mt-1 text-[10px] uppercase tracking-[0.16em] text-on-surface-variant/45">
37
- ${escapeHtml(entry.tableName || entry.type)}
38
- </div>
42
+ ${
43
+ showMeta
44
+ ? `
45
+ <div class="mt-1 text-[10px] uppercase tracking-[0.16em] text-on-surface-variant/45">
46
+ ${escapeHtml(entry.tableName || entry.type)}
47
+ </div>
48
+ `
49
+ : ""
50
+ }
39
51
  </button>
40
52
  `
41
53
  )
@@ -50,136 +62,242 @@ function renderEntryGroup(title, entries, activeName) {
50
62
  `;
51
63
  }
52
64
 
53
- function renderDetail(detail) {
65
+ function renderLoadingInspector() {
66
+ return `
67
+ <div class="structure-graph__panel is-empty">
68
+ <span class="material-symbols-outlined structure-graph__empty-icon">progress_activity</span>
69
+ <div class="structure-graph__title">Loading</div>
70
+ <p class="text-sm leading-7 text-on-surface-variant/55">
71
+ Loading structure metadata for the selected object.
72
+ </p>
73
+ </div>
74
+ `;
75
+ }
76
+
77
+ function renderObjectInspector(detail) {
54
78
  if (!detail) {
55
- return `
56
- <div class="shell-section p-8">
57
- <p class="text-sm text-on-surface-variant/55">Select a structure object to inspect metadata and relational detail.</p>
58
- </div>
59
- `;
79
+ return clearInspector();
60
80
  }
61
81
 
82
+ const visibleColumns = (detail.columns ?? []).filter((column) => column.visible !== false);
83
+ const foreignKeyLinks = (detail.foreignKeys ?? []).reduce(
84
+ (count, foreignKey) => count + (foreignKey.mappings?.length ?? 0),
85
+ 0
86
+ );
87
+
62
88
  return `
63
- <section class="shell-section p-8">
64
- <div class="mb-6 flex items-center justify-between border-b border-outline-variant/10 pb-4">
65
- <div>
66
- <h2 class="font-headline text-2xl font-black uppercase tracking-tight text-primary-container">
67
- ${escapeHtml(detail.name)}
68
- </h2>
69
- <p class="mt-2 font-mono text-[10px] uppercase tracking-[0.2em] text-on-surface-variant/50">
70
- ${escapeHtml(detail.type ?? "table")}
71
- </p>
72
- </div>
73
- <div class="flex items-center gap-3">
89
+ <div class="structure-graph__panel">
90
+ <div class="space-y-3">
91
+ <div class="structure-graph__eyebrow">Object Inspector</div>
92
+ <div class="structure-graph__title">${escapeHtml(detail.name)}</div>
93
+ <div class="flex flex-wrap items-center gap-3">
94
+ <div class="structure-graph__subtitle">${escapeHtml(detail.type ?? "object")}</div>
74
95
  ${
75
- detail.type === "table"
96
+ detail.tableName
76
97
  ? `
77
- <button
78
- class="border border-outline-variant/20 px-4 py-3 text-[10px] font-bold uppercase tracking-[0.16em] text-on-surface hover:bg-surface-container-highest"
79
- data-action="navigate"
80
- data-to="/data/${encodeURIComponent(detail.name)}"
81
- type="button"
82
- >
83
- Open Data
84
- </button>
98
+ <div class="structure-graph__subtitle">
99
+ TABLE ${escapeHtml(detail.tableName)}
100
+ </div>
85
101
  `
86
102
  : ""
87
103
  }
88
- <div class="flex h-12 w-12 items-center justify-center bg-primary-container/10">
89
- <span class="material-symbols-outlined text-2xl text-primary-container">account_tree</span>
90
- </div>
91
104
  </div>
92
105
  </div>
93
- <div class="grid grid-cols-1 gap-6 xl:grid-cols-[0.95fr_1.05fr]">
94
- <div class="space-y-6">
95
- <div class="bg-surface-container-lowest p-4">
96
- <div class="mb-3 text-[10px] font-bold uppercase tracking-[0.2em] text-primary-container">Columns</div>
97
- ${
98
- detail.columns?.length
99
- ? `
100
- <div class="space-y-2 font-mono text-[11px] text-on-surface/65">
101
- ${detail.columns
102
- .map(
103
- (column) => `
104
- <div class="flex justify-between gap-3">
105
- <span>${escapeHtml(column.name)}</span>
106
- <span class="text-primary-container">${escapeHtml(
107
- column.declaredType || column.affinity
108
- )}</span>
109
- </div>
110
- `
111
- )
112
- .join("")}
113
- </div>
114
- `
115
- : '<div class="text-sm text-on-surface-variant/45">No column metadata for this object.</div>'
116
- }
117
- </div>
118
- <div class="bg-surface-container-lowest p-4">
119
- <div class="mb-3 text-[10px] font-bold uppercase tracking-[0.2em] text-primary-container">Relational Detail</div>
120
- <div class="space-y-2 font-mono text-[11px] text-on-surface/65">
121
- <div class="flex justify-between">
122
- <span>Foreign Keys</span>
123
- <span class="text-primary-container">${escapeHtml(
124
- formatNumber(detail.foreignKeys?.length ?? 0)
125
- )}</span>
126
- </div>
127
- <div class="flex justify-between">
128
- <span>Indexes</span>
129
- <span class="text-primary-container">${escapeHtml(
130
- formatNumber(detail.indexes?.length ?? 0)
131
- )}</span>
132
- </div>
133
- <div class="flex justify-between">
134
- <span>Triggers</span>
135
- <span class="text-primary-container">${escapeHtml(
136
- formatNumber(detail.triggers?.length ?? 0)
137
- )}</span>
138
- </div>
139
- <div class="flex justify-between">
140
- <span>Identity</span>
141
- <span class="text-primary-container">${escapeHtml(
142
- detail.identityStrategy?.type ?? "n/a"
143
- )}</span>
144
- </div>
145
- </div>
106
+
107
+ <div class="structure-graph__summary">
108
+ <div class="structure-graph__summary-card">
109
+ <div class="structure-graph__summary-label">Columns</div>
110
+ <div class="structure-graph__summary-value">${escapeHtml(
111
+ formatNumber(visibleColumns.length)
112
+ )}</div>
113
+ </div>
114
+ <div class="structure-graph__summary-card">
115
+ <div class="structure-graph__summary-label">FK Links</div>
116
+ <div class="structure-graph__summary-value">${escapeHtml(
117
+ formatNumber(foreignKeyLinks)
118
+ )}</div>
119
+ </div>
120
+ <div class="structure-graph__summary-card">
121
+ <div class="structure-graph__summary-label">Indexes</div>
122
+ <div class="structure-graph__summary-value">${escapeHtml(
123
+ formatNumber(detail.indexes?.length ?? 0)
124
+ )}</div>
125
+ </div>
126
+ <div class="structure-graph__summary-card">
127
+ <div class="structure-graph__summary-label">Triggers</div>
128
+ <div class="structure-graph__summary-value">${escapeHtml(
129
+ formatNumber(detail.triggers?.length ?? 0)
130
+ )}</div>
131
+ </div>
132
+ </div>
133
+
134
+ ${
135
+ visibleColumns.length
136
+ ? `
137
+ <section class="structure-graph__section">
138
+ <div class="structure-graph__section-title">Columns</div>
139
+ <div class="structure-graph__column-list">
140
+ ${visibleColumns
141
+ .map(
142
+ (column) => `
143
+ <div class="structure-graph__column-row">
144
+ <div class="min-w-0 space-y-1">
145
+ <div class="structure-graph__column-name">${escapeHtml(
146
+ column.name
147
+ )}</div>
148
+ <div class="structure-graph__column-type">${escapeHtml(
149
+ column.declaredType || column.affinity || "BLOB"
150
+ )}</div>
151
+ </div>
152
+ <div class="structure-graph__column-flags">
153
+ ${
154
+ column.primaryKeyPosition > 0
155
+ ? `<span class="structure-graph__flag is-key">PK${
156
+ column.primaryKeyPosition > 1
157
+ ? ` ${escapeHtml(String(column.primaryKeyPosition))}`
158
+ : ""
159
+ }</span>`
160
+ : ""
161
+ }
162
+ <span class="structure-graph__flag is-nullable">${
163
+ column.notNull ? "NOT NULL" : "NULLABLE"
164
+ }</span>
165
+ </div>
166
+ </div>
167
+ `
168
+ )
169
+ .join("")}
170
+ </div>
171
+ </section>
172
+ `
173
+ : ""
174
+ }
175
+
176
+ <section class="structure-graph__section">
177
+ <div class="structure-graph__section-title">DDL</div>
178
+ <pre class="structure-graph__ddl custom-scrollbar">${escapeHtml(
179
+ detail.ddl || "No DDL available."
180
+ )}</pre>
181
+ </section>
182
+ </div>
183
+ `;
184
+ }
185
+
186
+ function renderGraphSurface(structure, selectedName, detail, detailLoading) {
187
+ const graph = structure?.graph ?? { tables: [], relationshipCount: 0 };
188
+ const selectedGraphTable =
189
+ graph.tables?.find((table) => table.name === selectedName && table.type === "table") ?? null;
190
+ const inspectorMarkup = selectedGraphTable
191
+ ? renderInspector(selectedGraphTable)
192
+ : detailLoading
193
+ ? renderLoadingInspector()
194
+ : detail
195
+ ? renderObjectInspector(detail)
196
+ : clearInspector();
197
+
198
+ return `
199
+ <section class="structure-graph" data-structure-graph-root>
200
+ <div class="structure-graph__toolbar">
201
+ <div class="structure-graph__toolbar-main">
202
+ <label class="structure-graph__search" data-structure-graph-search>
203
+ <span class="material-symbols-outlined structure-graph__search-icon">search</span>
204
+ <input
205
+ class="structure-graph__search-input"
206
+ data-structure-graph-search-input
207
+ placeholder="Find table"
208
+ spellcheck="false"
209
+ type="search"
210
+ />
211
+ </label>
212
+ <div class="structure-graph__toolbar-meta">
213
+ ${escapeHtml(formatNumber(graph.tables?.length ?? 0))} TABLES //
214
+ ${escapeHtml(formatNumber(graph.relationshipCount ?? 0))} RELATIONSHIPS
146
215
  </div>
147
216
  </div>
148
- <div class="bg-surface-container-lowest p-4">
149
- <div class="mb-3 text-[10px] font-bold uppercase tracking-[0.2em] text-primary-container">DDL</div>
150
- <pre class="custom-scrollbar max-h-[520px] overflow-auto whitespace-pre-wrap font-mono text-[11px] leading-6 text-on-surface-variant/75">${escapeHtml(
151
- detail.ddl || "No DDL available."
152
- )}</pre>
217
+ <div class="structure-graph__toolbar-actions">
218
+ <button
219
+ class="structure-graph__button"
220
+ data-structure-graph-action="fit"
221
+ type="button"
222
+ >
223
+ <span class="material-symbols-outlined text-sm">fit_screen</span>
224
+ Fit Graph
225
+ </button>
226
+ <button
227
+ class="structure-graph__button"
228
+ data-structure-graph-action="relayout"
229
+ type="button"
230
+ >
231
+ <span class="material-symbols-outlined text-sm">device_hub</span>
232
+ Recalculate Layout
233
+ </button>
234
+ <button
235
+ class="structure-graph__button"
236
+ data-structure-graph-action="clear"
237
+ type="button"
238
+ >
239
+ <span class="material-symbols-outlined text-sm">close</span>
240
+ Clear Selection
241
+ </button>
242
+ <button
243
+ class="structure-graph__button is-disabled"
244
+ data-structure-graph-action="open-data"
245
+ disabled
246
+ type="button"
247
+ >
248
+ <span class="material-symbols-outlined text-sm">table_rows</span>
249
+ Open Data
250
+ </button>
251
+ <button
252
+ class="structure-graph__button"
253
+ data-structure-graph-action="toggle-inspector"
254
+ type="button"
255
+ >
256
+ <span class="material-symbols-outlined text-sm">right_panel_close</span>
257
+ Hide Inspector
258
+ </button>
153
259
  </div>
154
260
  </div>
261
+
262
+ <div class="structure-graph__workspace">
263
+ <div class="structure-graph__canvas-shell">
264
+ <div class="structure-graph__canvas" data-structure-graph-canvas></div>
265
+ <div
266
+ class="structure-graph__empty"
267
+ data-structure-graph-empty
268
+ ${graph.tables?.length ? "hidden" : ""}
269
+ >
270
+ <span class="material-symbols-outlined structure-graph__empty-icon">account_tree</span>
271
+ <div class="structure-graph__title">No Tables</div>
272
+ <p class="text-sm leading-7 text-on-surface-variant/55">
273
+ The active database does not expose table metadata for the schema graph.
274
+ </p>
275
+ </div>
276
+ </div>
277
+
278
+ <aside
279
+ class="structure-graph__inspector custom-scrollbar"
280
+ data-structure-graph-inspector
281
+ >
282
+ ${inspectorMarkup}
283
+ </aside>
284
+ </div>
155
285
  </section>
156
286
  `;
157
287
  }
158
288
 
159
289
  export function renderStructureView(state) {
160
290
  const structure = state.structure.data;
161
- const detail = getCurrentStructureEntryDetail(state);
162
- const counts = structure
163
- ? [
164
- { label: "Tables", value: formatNumber(structure.grouped.tables.length) },
165
- { label: "Views", value: formatNumber(structure.grouped.views.length) },
166
- { label: "Indexes", value: formatNumber(structure.grouped.indexes.length) },
167
- {
168
- label: "Triggers",
169
- value: formatNumber(structure.grouped.triggers.length),
170
- accent: true,
171
- },
172
- ]
173
- : [];
291
+ const detail =
292
+ state.structure.detail?.name === state.structure.selectedName ? state.structure.detail : null;
174
293
 
175
294
  return {
176
295
  main: `
177
296
  <section class="view-surface min-h-full bg-surface-container">
178
- <div class="view-frame mx-auto max-w-7xl space-y-8">
297
+ <div class="view-frame space-y-8">
179
298
  ${renderPageHeader({
180
- eyebrow: "Structure // sqlite_master + PRAGMA",
181
299
  title: "Structure",
182
- subtitle: "Raw DDL, table identity, foreign keys, and index metadata",
300
+ subtitle: "Schema graph, foreign-key paths, raw DDL, and object metadata",
183
301
  })}
184
302
 
185
303
  ${
@@ -203,15 +321,13 @@ export function renderStructureView(state) {
203
321
  `
204
322
  : structure
205
323
  ? `
206
- <div class="grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4">
207
- ${counts.map((metric) => renderMetricCard(metric)).join("")}
208
- </div>
209
- <section class="grid grid-cols-1 gap-6 xl:grid-cols-[0.45fr_1.55fr]">
324
+ <section class="grid grid-cols-1 gap-6 xl:grid-cols-[18.5rem_minmax(0,1fr)] 2xl:grid-cols-[19.5rem_minmax(0,1fr)]">
210
325
  <div class="space-y-6">
211
326
  ${renderEntryGroup(
212
327
  "Tables",
213
328
  structure.grouped.tables,
214
- state.structure.selectedName
329
+ state.structure.selectedName,
330
+ { compact: true, showMeta: false }
215
331
  )}
216
332
  ${renderEntryGroup(
217
333
  "Views",
@@ -221,7 +337,8 @@ export function renderStructureView(state) {
221
337
  ${renderEntryGroup(
222
338
  "Indexes",
223
339
  structure.grouped.indexes,
224
- state.structure.selectedName
340
+ state.structure.selectedName,
341
+ { compact: true, showMeta: false }
225
342
  )}
226
343
  ${renderEntryGroup(
227
344
  "Triggers",
@@ -229,7 +346,12 @@ export function renderStructureView(state) {
229
346
  state.structure.selectedName
230
347
  )}
231
348
  </div>
232
- ${renderDetail(detail)}
349
+ ${renderGraphSurface(
350
+ structure,
351
+ state.structure.selectedName,
352
+ detail,
353
+ state.structure.detailLoading
354
+ )}
233
355
  </section>
234
356
  `
235
357
  : ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlite-hub",
3
- "version": "0.2.0",
3
+ "version": "0.3.2",
4
4
  "description": "SQLite-only local management app backend and SPA shell",
5
5
  "main": "server/server.js",
6
6
  "bin": {
@@ -8,11 +8,14 @@
8
8
  },
9
9
  "scripts": {
10
10
  "start": "node bin/sqlite-hub.js",
11
- "dev": "node --watch server/server.js",
11
+ "dev": "node --watch server/server.js --port:4180",
12
12
  "publish": "bash publish_brew.sh && bash publish_npm.sh"
13
13
  },
14
14
  "dependencies": {
15
15
  "better-sqlite3": "^11.8.1",
16
+ "cytoscape": "^3.33.2",
17
+ "cytoscape-elk": "^2.3.0",
18
+ "elkjs": "^0.11.1",
16
19
  "express": "^4.21.2"
17
20
  }
18
21
  }
package/publish_brew.sh CHANGED
@@ -304,6 +304,27 @@ commit_and_push_tap() {
304
304
  run git -C "$TAP_DIR" push origin HEAD
305
305
  }
306
306
 
307
+ refresh_local_brew_tap_checkout() {
308
+ local brew_repo
309
+ local installed_tap_path
310
+
311
+ if ! command -v brew >/dev/null 2>&1; then
312
+ info "brew not found, skipping local tap refresh"
313
+ return
314
+ fi
315
+
316
+ brew_repo="$(brew --repository)"
317
+ installed_tap_path="${brew_repo}/Library/Taps/${TAP_OWNER}/${TAP_REPO_NAME}"
318
+
319
+ if [[ ! -d "$installed_tap_path/.git" ]]; then
320
+ info "No installed Homebrew tap checkout at ${installed_tap_path}, skipping local refresh"
321
+ return
322
+ fi
323
+
324
+ info "Refreshing installed Homebrew tap checkout at ${installed_tap_path}"
325
+ run git -C "$installed_tap_path" pull --ff-only
326
+ }
327
+
307
328
  run_brew_audit() {
308
329
  if [[ "$SKIP_AUDIT" == "1" ]]; then
309
330
  info "Skipping brew audit"
@@ -439,6 +460,7 @@ ensure_tap_repo
439
460
  write_formula
440
461
  run_brew_audit
441
462
  commit_and_push_tap
463
+ refresh_local_brew_tap_checkout
442
464
 
443
465
  info "Published ${FORMULA_NAME} ${VERSION}"
444
466
  info "Install with: brew install ${BREW_TAP_NAME}/${FORMULA_NAME}"
@@ -1,7 +1,7 @@
1
1
  const express = require("express");
2
2
  const { route, successResponse } = require("../utils/errors");
3
3
 
4
- function createConnectionsRouter({ connectionManager, importService }) {
4
+ function createConnectionsRouter({ connectionManager, importService, backupService }) {
5
5
  const router = express.Router();
6
6
 
7
7
  router.post(
@@ -68,6 +68,20 @@ function createConnectionsRouter({ connectionManager, importService }) {
68
68
  })
69
69
  );
70
70
 
71
+ router.post(
72
+ "/backup-active",
73
+ route((req, res) => {
74
+ const backup = backupService.createActiveBackup();
75
+
76
+ res.json(
77
+ successResponse({
78
+ message: `Backup created: ${backup.fileName}`,
79
+ data: backup,
80
+ })
81
+ );
82
+ })
83
+ );
84
+
71
85
  router.get(
72
86
  "/recent",
73
87
  route((req, res) => {
@@ -51,6 +51,20 @@ function createDataRouter({ dataBrowserService }) {
51
51
  })
52
52
  );
53
53
 
54
+ router.delete(
55
+ "/:tableName/rows",
56
+ route((req, res) => {
57
+ const data = dataBrowserService.deleteTableRow(req.params.tableName, req.body ?? {});
58
+
59
+ res.json(
60
+ successResponse({
61
+ message: "Table row deleted.",
62
+ data,
63
+ })
64
+ );
65
+ })
66
+ );
67
+
54
68
  return router;
55
69
  }
56
70
 
@@ -4,16 +4,36 @@ const { route } = require("../utils/errors");
4
4
  function createExportRouter({ exportService }) {
5
5
  const router = express.Router();
6
6
 
7
+ function sendCsv(res, result) {
8
+ res.setHeader("Content-Type", "text/csv; charset=utf-8");
9
+ res.setHeader(
10
+ "Content-Disposition",
11
+ `attachment; filename="${result.filename}"`
12
+ );
13
+ res.send(result.csv);
14
+ }
15
+
7
16
  router.post(
8
17
  "/query.csv",
9
18
  route((req, res) => {
10
19
  const result = exportService.exportQuery(req.body.sql);
11
- res.setHeader("Content-Type", "text/csv; charset=utf-8");
12
- res.setHeader(
13
- "Content-Disposition",
14
- `attachment; filename="${result.filename}"`
15
- );
16
- res.send(result.csv);
20
+ sendCsv(res, result);
21
+ })
22
+ );
23
+
24
+ router.post(
25
+ "/table.csv",
26
+ route((req, res) => {
27
+ const result = exportService.exportTable(req.body?.tableName);
28
+ sendCsv(res, result);
29
+ })
30
+ );
31
+
32
+ router.get(
33
+ "/table/:tableName.csv",
34
+ route((req, res) => {
35
+ const result = exportService.exportTable(req.params.tableName);
36
+ sendCsv(res, result);
17
37
  })
18
38
  );
19
39