Hermes MongoDB
    Preparing search index...

    Type Alias OutboxEvent

    OutboxEvent: object

    Base type for all events.

    Events can be any object type. Use discriminated unions with a type field for type-safe event handling.

    Domain events with discriminated union

    type DomainEvent =
    | { type: 'MedicineAssigned'; patientId: string; medicineId: string }
    | { type: 'TaskCompleted'; taskId: string; completedAt: Date }
    | { type: 'UserRegistered'; userId: string; email: string }

    const outbox = createOutboxConsumer<DomainEvent>({
    // ...
    publish: async (event) => {
    switch (event.type) {
    case 'MedicineAssigned':
    // TypeScript knows event has patientId and medicineId
    await handleMedicineAssignment(event)
    break
    case 'TaskCompleted':
    // TypeScript knows event has taskId and completedAt
    await handleTaskCompletion(event)
    break
    case 'UserRegistered':
    // TypeScript knows event has userId and email
    await handleUserRegistration(event)
    break
    }
    }
    })