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.
publish
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 })}) Copy
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
MongoDB client instance
Scoped publish function that automatically uses the session
MongoDB session for the transaction - pass this to all MongoDB operations
Scope object provided to the WithScope callback.
Contains a MongoDB session and a scoped
publishfunction that automatically uses the session for transactional consistency.Event - Type of events (use discriminated unions for multiple event types)
Example
Using OutboxScope to publish multiple events
See
WithScope - Function type that creates this scope