Skip to content

basalt / events/src / Outbox

Class: Outbox ​

Defined in: events/src/outbox.ts:300

Constructors ​

Constructor ​

> new Outbox(store, options?): Outbox

Defined in: events/src/outbox.ts:318

Parameters ​

store ​

OutboxStore

options? ​

OutboxOptions = {}

Returns ​

Outbox

Methods ​

enqueue() ​

> enqueue(event, payload, tenantIdOrOptions?, options?): Promise<OutboxEntry>

Defined in: events/src/outbox.ts:358

Records an event. Pass { tx } to write it inside your transaction, next to the state change it describes:

await prisma.$transaction(async (tx) => {
  await tx.order.update({ where: { id }, data: { status: 'paid' } })
  await outbox.enqueue('order.paid', { id }, { tenantId, tx })
})

Accepts enqueue(event, payload, tenantId?, options?) or enqueue(event, payload, { tenantId?, tx? }).

Parameters ​

event ​

string

payload ​

unknown

tenantIdOrOptions? ​

string | OutboxEnqueueOptions

options? ​

OutboxStoreEnqueueOptions

Returns ​

Promise<OutboxEntry>


flush() ​

> flush(dispatch, batchSize?): Promise<FlushResult>

Defined in: events/src/outbox.ts:382

Delivers up to batchSize pending entries with dispatch, marking outcomes. Overlap-safe: while a flush is in flight, further calls await and return that flush's result instead of re-selecting (and double-delivering) the same batch.

Parameters ​

dispatch ​

OutboxDispatch

batchSize? ​

number = 50

Returns ​

Promise<FlushResult>

Released under the MIT License.