Skip to content

Add RxDB Viewer plugin for remote database inspection via WebRTC#8115

Open
pubkey wants to merge 5 commits intomasterfrom
claude/rxdb-viewer-plugin-ZB8Td
Open

Add RxDB Viewer plugin for remote database inspection via WebRTC#8115
pubkey wants to merge 5 commits intomasterfrom
claude/rxdb-viewer-plugin-ZB8Td

Conversation

@pubkey
Copy link
Copy Markdown
Owner

@pubkey pubkey commented Mar 18, 2026

This PR contains:

  • A NEW FEATURE

Describe the problem you have without this PR

There is no built-in way to remotely inspect and interact with RxDB databases in real-time. Developers need a tool to view collections, query documents, observe changes, and perform CRUD operations on remote databases without direct access to the application code.

Solution

This PR introduces the RxDB Viewer plugin, a comprehensive remote database inspection tool that enables:

  • Remote Connection: Connect to any RxDB database via WebRTC peer-to-peer connection using a signaling server
  • Database Inspection: View all collections, schemas, and document counts
  • Document Management: Query, view, edit, and delete documents with a modern UI
  • Real-time Observation: Subscribe to query results and see live updates as data changes
  • Data Export: Export entire collections as JSON
  • Connection Sharing: Share connection parameters to allow others to inspect the same database

Key Components

  1. viewer-server.ts: Server-side implementation that handles WebRTC connections and processes viewer requests

    • Manages peer connections via simple-peer
    • Implements RPC-style request/response protocol
    • Handles query execution, document CRUD, and subscription management
    • Supports multiple concurrent viewer connections
  2. viewer.html: Standalone single-file web application (1700+ lines)

    • React-based UI with modern dark theme matching RxDB docs design
    • Sidebar with collection browser and schema viewer
    • Document table with sorting and filtering
    • Detail panel for viewing/editing individual documents
    • Query observer panel showing live subscriptions
    • Connection management and status indicators
    • Modal dialogs for editing and exporting data
  3. viewer-types.ts: TypeScript type definitions for the viewer protocol

    • Request/response message types
    • Connection parameters and state types
    • Signaling protocol messages
  4. index.ts: Public API exports

Features

  • Zero-setup connection: Uses default signaling server (wss://signaling.rxdb.info/) or custom server
  • Secure: WebRTC peer-to-peer communication, no data passes through signaling server
  • Real-time: Live query subscriptions with instant updates
  • User-friendly: Modern UI with syntax highlighting, JSON formatting, and intuitive controls
  • Production-ready: Error handling, connection recovery, and resource cleanup

Design Decisions

  • Single HTML file for viewer UI enables easy distribution and embedding
  • WebRTC for secure peer-to-peer communication
  • RPC protocol for request/response pattern
  • Matches RxDB documentation design tokens for visual consistency
  • Supports both Node.js and browser environments

Todos

  • Typings
  • Tests (viewer functionality requires integration testing with running database)
  • Documentation (separate PR recommended for docs-src)
  • Changelog

https://claude.ai/code/session_01E4LPySRrjXCCRdV9pVKJom

claude added 5 commits March 18, 2026 16:08
Adds a new viewer plugin that allows developers to connect to any running
RxDB database remotely via WebRTC and inspect its data in a browser-based UI.

Server-side plugin (src/plugins/viewer/):
- startRxDBViewer(database, options) sets up WebRTC listener on signaling server
- getDatabaseConnectionParams(database) returns JSON connection params
- Uses same signaling server protocol as the replication-webrtc plugin
- Handles viewer requests: getDbInfo, query, count, observeQuery, exportCollection,
  writeDocument, deleteDocument, getCollectionInfo, unobserveQuery

Single-file HTML viewer (viewer.html):
- Self-contained React app with all CSS inline
- Connects via WebRTC using simple-peer (loaded from CDN)
- Dark theme matching RxDB website style (colors, gradients, typography)
- Features: collection sidebar with doc counts, document table with sortable columns,
  Mango query bar, document detail panel with JSON syntax highlighting,
  live query observer, document CRUD (add/edit/delete), collection JSON export,
  schema viewer, connection status indicator

https://claude.ai/code/session_01E4LPySRrjXCCRdV9pVKJom
Align viewer.html with docs-src design system:
- CSS variables now reference docs-src tokens (--color-top, --color-middle,
  --color-bottom, --bg-color, --bg-color-dark, --bg-color-code)
- Button styles match docs-src Button component (gradient primary, border
  secondary with white inversion on hover)
- Added ViewerButton React component mirroring button.tsx behavior including
  mouse-following radial gradient on primary hover
- Tab active indicator uses gradient border-image matching side-tabs pattern
- Collection sidebar active state uses gradient left-border indicator from
  docs-src side-tabs__tab--active
- Modal matches docs-src Modal component (no border-radius, bg-color
  background, close button styling)
- Badge/pill shapes use border-radius: 20px matching docs-src Tag component
- Transition timing updated to 0.2s matching docs-src standard

https://claude.ai/code/session_01E4LPySRrjXCCRdV9pVKJom
- getDatabaseConnectionParams() now creates the viewer server on first
  call and caches it per database, removing the need to call
  startRxDBViewer() beforehand
- Viewer server auto-closes when the database closes via database.onClose
- Removed VW1 error code and newRxError import since the function no
  longer throws when no server exists
- startRxDBViewer() still available but now also reuses cached state
- Made startViewerServer() a private function since the public API is
  getDatabaseConnectionParams() and startRxDBViewer()

https://claude.ai/code/session_01E4LPySRrjXCCRdV9pVKJom
- Add docs-src/docs/viewer.md with usage guide covering lazy init,
  options, lifecycle, query examples, and security notes
- Add viewer to sidebar under Advanced Features in sidebars.js
- Add test/unit/viewer.test.ts with 12 tests covering:
  - getDatabaseConnectionParams() lazy creation, caching, custom options
  - startRxDBViewer() state management, shared state with getParams
  - Auto-close on database close
  - VIEWER_DEFAULT_SIGNALING_SERVER export
- Fix WebSocket cleanup in viewer-server.ts: handle async errors from
  ws.terminate() via error listener, guard onclose/peer-close reconnect
  with closed flag, add idempotent close()

https://claude.ai/code/session_01E4LPySRrjXCCRdV9pVKJom
Add a dedicated test-viewer job to main.yml that builds and runs the
viewer plugin unit tests with the memory storage backend. Fix lint
errors in viewer test (unused imports) and pre-existing docs-src files.

https://claude.ai/code/session_01E4LPySRrjXCCRdV9pVKJom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants