basalt / realtime/src / BridgeRule
Interface: BridgeRule<K>
Defined in: realtime/src/plugin.ts:21
Pushes a hook's payload to a realtime channel. Wire domain events straight to connected clients without touching the emitting code:
bridge: [{ hook: 'note:created', tenant: (p) => p.tenantId, // omit to use the tenant in context channel: 'notes', event: 'created', data: (p) => p.note, }]
Type Parameters
K
K extends keyof BasaltHooks & string = keyof BasaltHooks & string
Properties
channel
> channel: string | ((payload) => string)
Defined in: realtime/src/plugin.ts:35
data?
> optional data?: (payload) => unknown
Defined in: realtime/src/plugin.ts:38
What to send. Default: the whole hook payload.
Parameters
payload
BasaltHooks[K]
Returns
unknown
event
> event: string
Defined in: realtime/src/plugin.ts:36
hook
> hook: K
Defined in: realtime/src/plugin.ts:22
tenant?
> optional tenant?: (payload) => string | undefined
Defined in: realtime/src/plugin.ts:34
Tenant to deliver to; return undefined to skip this event (silently — an explicit opt-out).
Omit it when the payload carries no tenant id — e.g. schema- or database-per-tenant apps, whose domain models have no tenantId column. The tenant is then read from the active context at emit time (ctx().tenant.id, set by @basaltkit/tenancy); hook handlers run inside the emitter's async context. With no tenant in context the event is skipped and reported through onBridgeSkipped.
Parameters
payload
BasaltHooks[K]
Returns
string | undefined