A package for dispatching and listening to events in Fauna.
Construct a FaunaEventClient around an existing FaunaClient. Bind the event handlers to arbitrarily named events using .on.
import {Client} from "faunadb";
import {FaunaEventClient} from "fauna-event";
import {MySendApi} from "my-package";
const client = new Client({
// your params
});
const eventClient = new FaunaEventClient(client);
client.on("sendEvent", (payload)=>{
MySendApi.send(`Handled a send event, at ${new Date().toLocaleString()}.`);
})Dispatch a new event to the the FaunaEvents collection, using NewEvent in a FaunaQuery.
client.query(NewEvent({
eventType : "sendEvent"
data : "A cool message."
}));To safely handle concurrency, a FaunaEventClient uses a sliding window, listening only to documents within the window.
The Head document is the document to which all event dispatches should be appended. However, in case of events occurring
- Fauna-side Blocking:
FaunaEventClientscan be instantiated such that only one client in a cluster will handle an event. - Rooms/Targeting: events can be dispatched which may only be handled by particular subset of
FaunaEventClients.