Hermes MongoDB
    Preparing search index...

    Type Alias OutboxScope<Event>Template

    Scope object provided to the WithScope callback.

    Contains a MongoDB session and a scoped publish function that automatically uses the session for transactional consistency.

    Event - Type of events (use discriminated unions for multiple event types)

    Using OutboxScope to publish multiple events

    await outbox.withScope(async ({ publish, session, client }) => {
    // All publishes use the same transaction
    await publish({ type: 'Event1', data: 'foo' })
    await publish({ type: 'Event2', data: 'bar' })

    // Session available for MongoDB operations
    await db.collection('logs').insertOne({ ... }, { session })
    })

    WithScope - Function type that creates this scope

    type OutboxScope<Event extends OutboxEvent> = {
        client: MongoClient;
        publish: (event: Event | Event[]) => Promise<void>;
        session: ClientSession;
    }

    Type Parameters

    Index

    Properties

    client: MongoClient

    MongoDB client instance

    publish: (event: Event | Event[]) => Promise<void>

    Scoped publish function that automatically uses the session

    session: ClientSession

    MongoDB session for the transaction - pass this to all MongoDB operations