Add RxDB Viewer plugin for remote database inspection via WebRTC#8115
Open
Add RxDB Viewer plugin for remote database inspection via WebRTC#8115
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains:
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:
Key Components
viewer-server.ts: Server-side implementation that handles WebRTC connections and processes viewer requests
viewer.html: Standalone single-file web application (1700+ lines)
viewer-types.ts: TypeScript type definitions for the viewer protocol
index.ts: Public API exports
Features
Design Decisions
Todos
https://claude.ai/code/session_01E4LPySRrjXCCRdV9pVKJom