Skip to content

Commit 0b1d5d3

Browse files
committed
docs: add devtools section to api.md and getting-started; update ROADMAP
1 parent d201461 commit 0b1d5d3

3 files changed

Lines changed: 81 additions & 1 deletion

File tree

ROADMAP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Today datum uses last-write-wins based on `updated_at`. For collaborative editin
2020

2121
## Recently shipped
2222

23+
- **DevTools (v0.8.0)**`datum-sync/devtools` adds a floating browser panel with a SQL REPL (full PostGIS), schema inspector, and live sync status. Activated by `initDatumDevtools(db)`. Toggle with `Ctrl+Shift+D`. Zero production bundle impact via dynamic import. Try it at the [live demo](https://a-saed.github.io/datum/demo/).
2324
- **Typed column support (v0.7.0)** — datum auto-introspects the server table at startup and mirrors the exact column structure in PGlite. Any columns beyond the 4 required ones (`id`, `geom`, `updated_at`, `properties`) are synced automatically and queryable with normal SQL on both sides — no extra configuration.
2425
- **Per-user authentication (v0.6.0)** — JWT auth (HS256/RS256/ES256). Token in `subscribe` message, all claims forwarded as `datum.<key>` Postgres session variables for RLS. Auto token refresh before expiry. Startup warning when connected as superuser. Fully opt-in.
2526
- **Security and correctness hardening (0.5.0)** — Ack-based write sync (server acks writes before client marks synced; retries on reconnect). WS per-connection read limits, read deadlines, ping/pong keepalive. Write batch capped at 500. Rate limiter uses real client IP (X-Forwarded-For aware). Delta broadcast uses full geometry bbox (not just first vertex) for correct routing of polygons and lines. Graceful shutdown on SIGTERM. Outbox ordered by insertion seq not feature timestamp.

docs/api.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,70 @@ function FeatureList() {
228228

229229
---
230230

231+
## DevTools (`datum-sync/devtools`)
232+
233+
A floating browser panel for inspecting the local PGlite database, schema, and sync state while building. Zero production bundle impact — loaded only when you import it.
234+
235+
```ts
236+
import { initDatumDevtools } from 'datum-sync/devtools'
237+
```
238+
239+
### `initDatumDevtools(client)`
240+
241+
Injects the devtools panel into the page. Call once after `DatumClient.connect()`.
242+
243+
```ts
244+
const db = await DatumClient.connect({ serverUrl, bbox })
245+
246+
// Dev only — tree-shaken out of production builds when using dynamic import
247+
if (import.meta.env.DEV) {
248+
const { initDatumDevtools } = await import('datum-sync/devtools')
249+
initDatumDevtools(db)
250+
}
251+
```
252+
253+
For multiple tables, pass an array — a dropdown appears in the toolbar to switch between clients:
254+
255+
```ts
256+
initDatumDevtools([featuresDb, waypointsDb])
257+
```
258+
259+
Calling `initDatumDevtools` more than once is a no-op (idempotent).
260+
261+
**Toggle:** `Ctrl+Shift+D` (Windows/Linux) or `Cmd+Shift+D` (Mac). The panel remembers its open/closed state and height across page reloads via `localStorage`.
262+
263+
### Tabs
264+
265+
| Tab | What it shows |
266+
|---|---|
267+
| **Query** | SQL REPL against local PGlite. Full PostGIS available. `Cmd+Enter` to run. |
268+
| **Schema** | Every column from the server's schema message — name, type, role badge, nullable. Schema hash and "mirrored from server ✓" confirmation. |
269+
| **Status** | Connection state, pending write count, schema hash, schema version. When a schema wipe occurs, shows a diff of added/removed columns. |
270+
271+
### `onSchemaChange` callback
272+
273+
Called whenever the local DB is wiped and recreated (schema changed or first visit). Available in `DatumConfig` and as a post-connect subscription:
274+
275+
```ts
276+
// In config (set at connect time):
277+
const db = await DatumClient.connect({
278+
serverUrl,
279+
bbox,
280+
onSchemaChange: ({ prev, next }) => {
281+
console.log('Schema changed — columns now:', next.map(c => c.name))
282+
},
283+
})
284+
285+
// Post-connect subscription (returns unsubscribe function):
286+
const unsub = db.onSchemaChange(({ prev, next }) => {
287+
console.log('added columns:', next.filter(c => !prev?.find(p => p.name === c.name)))
288+
})
289+
```
290+
291+
`prev` is `null` on first visit (no previous schema). `next` is the full column list after the wipe.
292+
293+
---
294+
231295
## datum-server (Go binary)
232296

233297
### Config file

docs/getting-started.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,24 @@ import { useDatum } from 'datum-sync/react'
9191
const { rows } = useDatum(db, `SELECT * FROM features`)
9292
```
9393

94+
## DevTools
95+
96+
Add the datum devtools panel to inspect your local PGlite database while building:
97+
98+
```ts
99+
const db = await DatumClient.connect({ serverUrl, bbox })
100+
101+
if (import.meta.env.DEV) {
102+
const { initDatumDevtools } = await import('datum-sync/devtools')
103+
initDatumDevtools(db)
104+
}
105+
```
106+
107+
Press `Ctrl+Shift+D` to toggle the panel. Three tabs: **Query** (SQL REPL), **Schema** (column inspector), **Status** (sync state). No extra dependencies — included in `datum-sync`.
108+
94109
## Next steps
95110

96111
- [How It Works](/how-it-works) — understand the local-first model, bbox subscriptions, and sync cycle
97-
- [API Reference](/api) — full TypeScript client, React hooks, and server documentation
112+
- [API Reference](/api) — full TypeScript client, React hooks, devtools, and server documentation
98113
- [Authentication](/auth) — add per-user JWT auth and Postgres Row Level Security
99114
- [Self-Hosting](/self-hosting) — deploy to production (free-tier guide included)

0 commit comments

Comments
 (0)