feat: add ReBAC event relays and live document updates - #1594
Closed
JohnChantz wants to merge 6 commits into
Closed
Conversation
| function extractDocumentId(id: unknown): string | null { | ||
| if (id === undefined || id === null) return null; | ||
| if (typeof id === 'string' || typeof id === 'number') return String(id); | ||
| if (typeof id === 'object' && id !== null && 'toHexString' in id) { |
| const hex = (id as { toHexString: () => string }).toHexString(); | ||
| return typeof hex === 'string' && hex.length > 0 ? hex : null; | ||
| } | ||
| if (typeof id === 'object' && id !== null && 'toString' in id) { |
JohnChantz
force-pushed
the
feat/event-relays
branch
from
September 9, 2026 09:11
d814270 to
2ea72b3
Compare
Forward exact Redis bus events as templated Socket.io messages on /events/, with resource-scoped rooms and local-only HA emission.
MongoDB change streams require a replica set, so local Compose now initializes a single-node rs0. Schemas can opt in via realtime.enabled.
Mongo 4.4 keyfiles reject hyphens, and rs.status() returns ok:0 instead of throwing, so Compose never elected a primary for replicaSet URIs.
Stop duplicate admin/router deliveries and apply handshake auth on connect. Retry change-stream leadership after lock races.
Extend realtime beyond MongoDB so PostgreSQL, MySQL, MariaDB, and SQLite emit the same metadata-only change events using table triggers and a durable internal log.
JohnChantz
force-pushed
the
feat/event-relays
branch
from
September 11, 2026 11:05
b0391e0 to
2c637c8
Compare
Contributor
Author
|
Split into three stacked PRs for review:
Tree is identical to this branch ( |
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.
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
Local Compose Mongo now runs as a single-node replica set (
rs0) so change streams work. Existing deployments are unchanged; localDB_CONN_URImust includereplicaSet=rs0.The PR fulfills these requirements:
mainbranchfix #xxx, where "xxx" is the issue number)If adding a new feature, the PR's description includes:
Other information:
Apps need two live-update paths that REST polling cannot cover: forwarding exact Redis bus events to Socket.io, and watching opted-in MongoDB collections for document changes. Both stay authorization-aware (ReBAC on relays; schema/document checks on live updates) and keep secrets out of browser handshakes.
Summary
/events/. Clients subscribe withrelayId+resourceId; rooms are derived server-side. Subscribe is allowed only whenUser:<id>has the relaypermissionon<resourceType>:<resourceId>. Admin CRUD is at/router/event-relays.realtime.enabledplusmodelOptions.conduit.realtime.enabled). Clients connect to/database/(path/realtime) and emitsubscribe/unsubscribe. Events arechangemetadata only (no document fields); consumers refetch through authorized REST. Admin clients usePOST /realtime/ticketfor a 30-second handshake token.rs0(docker/mongo/init-replica.sh+ keyfile) because change streams require a replica set or sharded cluster.Test plan
modules/router/src/event-relays/*.test.ts): channel matching, template rendering, ReBAC authorize, subscribe/unsubscribe roomsmodules/database/src/realtime/__tests__/): coordinator, authorize, topology, subscriptions, rooms, normalize, statuspackages/core/src/admin/realtime/*.test.ts): ticket, handshake, namespacedocker compose --profile mongodb up: Mongo becomes replica setrs0;DB_CONN_URIincludesreplicaSet=rs0/events/with a user token, confirm subscribe is denied without the ReBAC grant and allowed with itrealtime.enabled, opt a schema in, subscribe on/database/, mutate a document, confirm achangeevent with no document payloadPOST /realtime/ticket(session JWT / masterkey not sent from the browser)