API Reference
The public API of @visualbravo/zenstack-live.
ZenStackLive
The entry point. It connects to Redis as soon as it's created.
import { ZenStackLive } from '@visualbravo/zenstack-live'
const live = new ZenStackLive({
client,
redis: {
url: process.env.REDIS_URL!,
},
})Prop
Type
live.stream()
Creates a LiveStream. It throws if a filter is invalid or unsupported.
const stream = live.stream({
model: 'User',
slug: 'send-welcome-email',
when: { created: {} },
})Prop
Type
live.prune()
Removes what's left behind by streams that are gone. See Pruning.
const report = await live.prune({
olderThan: 7 * 24 * 60 * 60 * 1000,
dryRun: true,
})Prop
Type
It returns a LivePruneReport:
Prop
Type
type PrunedStream = {
slug?: string // Missing for streams last run by a version that didn't record them.
model?: string
redisStream: string
consumerGroup: string
lastSeenAt: Date | null
}
type PrunedConsumer = {
name: string
redisStream: string
consumerGroup: string
lastSeenAt: Date
}
type PrunedTable = {
table?: { schema: string; name: string } // Missing if the table is no longer published.
redisStream: string
replicaIdentityFull: boolean
}live.disconnect()
Stops background trimming and closes the Redis connections. Streams from this instance stop reading, and may reject rather than end cleanly. Your ZenStack client is left open.
LiveStream
Returned by live.stream(). It's an AsyncIterable of events, typed according to when.
Prop
Type
Events
All events share these fields.
Prop
Type
Each event type adds one field, holding the record. See Reading Events.
| Type | type | Field |
|---|---|---|
RecordCreatedEvent | created | created |
RecordUpdatedEvent | updated | updated.before and updated.after |
RecordDeletedEvent | deleted | deleted |
beforeAfter()
Gives every event the same { before, after } shape. See beforeAfter.
function beforeAfter<Event extends BeforeAfterEvent>(event: Event): BeforeAfterResult<Event>Types
Prop
Type