Skip to content

@codesoul-co/hypha-core / modules/runtime/message-inbox-outbox

Using this module

Use the Message inbox outbox module for executing runtime behavior at this boundary. It exports 4 classes, 8 interfaces.

Import from the package entrypoint

ts
import {
  InMemoryRuntimeMessageInboxStore,
  InMemoryRuntimeMessageOutboxStore,
  RuntimeInboxProcessor,
  RuntimeOutboxDispatcher,
} from '@codesoul-co/hypha-core';

import type {
  InboxClaimRequest,
  InboxClaimResult,
  RuntimeInboxHandleResult,
  RuntimeInboxProcessorOptions,
  RuntimeMessageInboxStore,
  RuntimeMessageOutboxStore,
  RuntimeOutboxDispatcherOptions,
  RuntimeOutboxDispatchResult,
} from '@codesoul-co/hypha-core';

Usage patterns

  • Use the 8 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.
  • The module exposes 4 classes as constructable runtime implementations. Each symbol entry lists its constructor and public methods.

Public exports

SymbolKindSignatureDescription
InMemoryRuntimeMessageInboxStoreclassnew InMemoryRuntimeMessageInboxStore(): InMemoryRuntimeMessageInboxStoreIn Memory Runtime Message Inbox Store class with 6 public constructor or member entries; its exact declarations are listed below.
InMemoryRuntimeMessageOutboxStoreclassnew InMemoryRuntimeMessageOutboxStore(): InMemoryRuntimeMessageOutboxStoreIn Memory Runtime Message Outbox Store class with 7 public constructor or member entries; its exact declarations are listed below.
RuntimeInboxProcessorclassnew RuntimeInboxProcessor(options: RuntimeInboxProcessorOptions): RuntimeInboxProcessorRuntime Inbox Processor class with 2 public constructor or member entries; its exact declarations are listed below.
RuntimeOutboxDispatcherclassnew RuntimeOutboxDispatcher(options: RuntimeOutboxDispatcherOptions): RuntimeOutboxDispatcherRuntime Outbox Dispatcher class with 2 public constructor or member entries; its exact declarations are listed below.
InboxClaimRequestinterfaceinterface InboxClaimRequestInbox Claim Request interface with 7 public fields or methods.
InboxClaimResultinterfaceinterface InboxClaimResultInbox Claim Result interface with 2 public fields or methods.
RuntimeInboxHandleResultinterfaceinterface RuntimeInboxHandleResultRuntime Inbox Handle Result interface with 3 public fields or methods.
RuntimeInboxProcessorOptionsinterfaceinterface RuntimeInboxProcessorOptionsRuntime Inbox Processor Options interface with 5 public fields or methods.
RuntimeMessageInboxStoreinterfaceinterface RuntimeMessageInboxStoreRuntime Message Inbox Store interface with 5 public fields or methods.
RuntimeMessageOutboxStoreinterfaceinterface RuntimeMessageOutboxStoreRuntime Message Outbox Store interface with 6 public fields or methods.
RuntimeOutboxDispatcherOptionsinterfaceinterface RuntimeOutboxDispatcherOptionsRuntime Outbox Dispatcher Options interface with 7 public fields or methods.
RuntimeOutboxDispatchResultinterfaceinterface RuntimeOutboxDispatchResultRuntime Outbox Dispatch Result interface with 4 public fields or methods.

InMemoryRuntimeMessageInboxStore

In Memory Runtime Message Inbox Store class with 6 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class InMemoryRuntimeMessageInboxStore implements RuntimeMessageInboxStore {
    claim(request: InboxClaimRequest): Promise<InboxClaimResult>;
    complete(consumerId: string, messageId: string, ownerId: string, appliedEventIds: string[], completedAt: string): Promise<void>;
    fail(consumerId: string, messageId: string, ownerId: string, error: NormalizedRuntimeError, failedAt: string): Promise<void>;
    get(consumerId: string, messageId: string): Promise<RuntimeMessageInboxRecord | null>;
    health(): Promise<ProviderHealth>;
}

Public members

MemberKindSignatureDescription
claimmethodclaim(request: InboxClaimRequest): Promise<InboxClaimResult>Public method; parameters and return type are shown in the signature.
completemethodcomplete(consumerId: string, messageId: string, ownerId: string, appliedEventIds: string[], completedAt: string): Promise<void>Public method; parameters and return type are shown in the signature.
constructorconstructor(): InMemoryRuntimeMessageInboxStoreCreates an instance of this class.
failmethodfail(consumerId: string, messageId: string, ownerId: string, error: NormalizedRuntimeError, failedAt: string): Promise<void>Public method; parameters and return type are shown in the signature.
getmethodget(consumerId: string, messageId: string): Promise<RuntimeMessageInboxRecord | null>Public method; parameters and return type are shown in the signature.
healthmethodhealth(): Promise<ProviderHealth>Public method; parameters and return type are shown in the signature.

InMemoryRuntimeMessageOutboxStore

In Memory Runtime Message Outbox Store class with 7 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class InMemoryRuntimeMessageOutboxStore implements RuntimeMessageOutboxStore {
    enqueue(input: {
            id: string;
            eventId?: string;
            envelope: RuntimeMessageEnvelope;
            availableAt?: string;
            createdAt: string;
        }): Promise<RuntimeMessageOutboxRecord>;
    claim(input: {
            ownerId: string;
            now: string;
            leaseMs: number;
            limit: number;
        }): Promise<RuntimeMessageOutboxRecord[]>;
    markPublished(id: string, ownerId: string, publishedAt: string): Promise<void>;
    markFailed(input: {
            id: string;
            ownerId: string;
            failedAt: string;
            error: NormalizedRuntimeError;
            retryAt?: string;
            deadLetter?: boolean;
        }): Promise<void>;
    get(id: string): Promise<RuntimeMessageOutboxRecord | null>;
    health(): Promise<ProviderHealth>;
}

Public members

MemberKindSignatureDescription
claimmethodclaim(input: { ownerId: string; now: string; leaseMs: number; limit: number; }): Promise<RuntimeMessageOutboxRecord[]>Public method; parameters and return type are shown in the signature.
constructorconstructor(): InMemoryRuntimeMessageOutboxStoreCreates an instance of this class.
enqueuemethodenqueue(input: { id: string; eventId?: string; envelope: RuntimeMessageEnvelope; availableAt?: string; createdAt: string; }): Promise<RuntimeMessageOutboxRecord>Public method; parameters and return type are shown in the signature.
getmethodget(id: string): Promise<RuntimeMessageOutboxRecord | null>Public method; parameters and return type are shown in the signature.
healthmethodhealth(): Promise<ProviderHealth>Public method; parameters and return type are shown in the signature.
markFailedmethodmarkFailed(input: { id: string; ownerId: string; failedAt: string; error: NormalizedRuntimeError; retryAt?: string; deadLetter?: boolean; }): Promise<void>Public method; parameters and return type are shown in the signature.
markPublishedmethodmarkPublished(id: string, ownerId: string, publishedAt: string): Promise<void>Public method; parameters and return type are shown in the signature.

RuntimeInboxProcessor

Runtime Inbox Processor class with 2 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class RuntimeInboxProcessor {
    constructor(options: RuntimeInboxProcessorOptions);
    handle(delivery: MessageDelivery, apply: (envelope: RuntimeMessageEnvelope) => Promise<string[]>): Promise<RuntimeInboxHandleResult>;
}

Public members

MemberKindSignatureDescription
constructorconstructor(options: RuntimeInboxProcessorOptions): RuntimeInboxProcessorCreates an instance of this class.
handlemethodhandle(delivery: MessageDelivery, apply: (envelope: RuntimeMessageEnvelope) => Promise<string[]>): Promise<RuntimeInboxHandleResult>Public method; parameters and return type are shown in the signature.

RuntimeOutboxDispatcher

Runtime Outbox Dispatcher class with 2 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class RuntimeOutboxDispatcher {
    constructor(options: RuntimeOutboxDispatcherOptions);
    dispatch(limit?: number): Promise<RuntimeOutboxDispatchResult>;
}

Public members

MemberKindSignatureDescription
constructorconstructor(options: RuntimeOutboxDispatcherOptions): RuntimeOutboxDispatcherCreates an instance of this class.
dispatchmethoddispatch(limit?: number): Promise<RuntimeOutboxDispatchResult>Public method; parameters and return type are shown in the signature.

InboxClaimRequest

Inbox Claim Request interface with 7 public fields or methods.

Declaration

text
export interface InboxClaimRequest {
    consumerId: string;
    ownerId: string;
    messageId: string;
    payloadHash: string;
    receivedAt: string;
    processingLeaseMs: number;
    expiresAt?: string;
}

Contract members

MemberKindSignatureDescription
consumerIdpropertyconsumerId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
expiresAtpropertyexpiresAt?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
messageIdpropertymessageId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
ownerIdpropertyownerId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
payloadHashpropertypayloadHash: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
processingLeaseMspropertyprocessingLeaseMs: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
receivedAtpropertyreceivedAt: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

InboxClaimResult

Inbox Claim Result interface with 2 public fields or methods.

Declaration

text
export interface InboxClaimResult {
    disposition: 'claimed' | 'duplicate' | 'busy' | 'conflict' | 'expired';
    record: RuntimeMessageInboxRecord;
}

Contract members

MemberKindSignatureDescription
dispositionpropertydisposition: "busy" | "expired" | "claimed" | "conflict" | "duplicate"Public property; its type, readonly modifier and optionality are shown in the signature.
recordpropertyrecord: RuntimeMessageInboxRecordPublic property; its type, readonly modifier and optionality are shown in the signature.

RuntimeInboxHandleResult

Runtime Inbox Handle Result interface with 3 public fields or methods.

Declaration

text
export interface RuntimeInboxHandleResult {
    disposition: 'applied' | 'duplicate' | 'busy' | 'failed' | 'dead_lettered' | 'expired';
    appliedEventIds: string[];
    ackPending?: boolean;
}

Contract members

MemberKindSignatureDescription
ackPendingpropertyackPending?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
appliedEventIdspropertyappliedEventIds: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
dispositionpropertydisposition: "failed" | "busy" | "expired" | "applied" | "dead_lettered" | "duplicate"Public property; its type, readonly modifier and optionality are shown in the signature.

RuntimeInboxProcessorOptions

Runtime Inbox Processor Options interface with 5 public fields or methods.

Declaration

text
export interface RuntimeInboxProcessorOptions {
    consumerId: string;
    ownerId: string;
    inbox: RuntimeMessageInboxStore;
    now?: () => string;
    processingLeaseMs?: number;
}

Contract members

MemberKindSignatureDescription
consumerIdpropertyconsumerId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
inboxpropertyinbox: RuntimeMessageInboxStorePublic property; its type, readonly modifier and optionality are shown in the signature.
nowmethodnow?(): stringPublic method; parameters and return type are shown in the signature.
ownerIdpropertyownerId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
processingLeaseMspropertyprocessingLeaseMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

RuntimeMessageInboxStore

Runtime Message Inbox Store interface with 5 public fields or methods.

Declaration

text
export interface RuntimeMessageInboxStore {
    claim(request: InboxClaimRequest): Promise<InboxClaimResult>;
    complete(consumerId: string, messageId: string, ownerId: string, appliedEventIds: string[], completedAt: string): Promise<void>;
    fail(consumerId: string, messageId: string, ownerId: string, error: NormalizedRuntimeError, failedAt: string): Promise<void>;
    get(consumerId: string, messageId: string): Promise<RuntimeMessageInboxRecord | null>;
    health(): Promise<ProviderHealth>;
}

Contract members

MemberKindSignatureDescription
claimmethodclaim(request: InboxClaimRequest): Promise<InboxClaimResult>Public method; parameters and return type are shown in the signature.
completemethodcomplete(consumerId: string, messageId: string, ownerId: string, appliedEventIds: string[], completedAt: string): Promise<void>Public method; parameters and return type are shown in the signature.
failmethodfail(consumerId: string, messageId: string, ownerId: string, error: NormalizedRuntimeError, failedAt: string): Promise<void>Public method; parameters and return type are shown in the signature.
getmethodget(consumerId: string, messageId: string): Promise<RuntimeMessageInboxRecord | null>Public method; parameters and return type are shown in the signature.
healthmethodhealth(): Promise<ProviderHealth>Public method; parameters and return type are shown in the signature.

RuntimeMessageOutboxStore

Runtime Message Outbox Store interface with 6 public fields or methods.

Declaration

text
export interface RuntimeMessageOutboxStore {
    enqueue(input: {
        id: string;
        eventId?: string;
        envelope: RuntimeMessageEnvelope;
        availableAt?: string;
        createdAt: string;
    }): Promise<RuntimeMessageOutboxRecord>;
    claim(input: {
        ownerId: string;
        now: string;
        leaseMs: number;
        limit: number;
    }): Promise<RuntimeMessageOutboxRecord[]>;
    markPublished(id: string, ownerId: string, publishedAt: string): Promise<void>;
    markFailed(input: {
        id: string;
        ownerId: string;
        failedAt: string;
        error: NormalizedRuntimeError;
        retryAt?: string;
        deadLetter?: boolean;
    }): Promise<void>;
    get(id: string): Promise<RuntimeMessageOutboxRecord | null>;
    health(): Promise<ProviderHealth>;
}

Contract members

MemberKindSignatureDescription
claimmethodclaim(input: { ownerId: string; now: string; leaseMs: number; limit: number; }): Promise<RuntimeMessageOutboxRecord[]>Public method; parameters and return type are shown in the signature.
enqueuemethodenqueue(input: { id: string; eventId?: string; envelope: RuntimeMessageEnvelope; availableAt?: string; createdAt: string; }): Promise<RuntimeMessageOutboxRecord>Public method; parameters and return type are shown in the signature.
getmethodget(id: string): Promise<RuntimeMessageOutboxRecord | null>Public method; parameters and return type are shown in the signature.
healthmethodhealth(): Promise<ProviderHealth>Public method; parameters and return type are shown in the signature.
markFailedmethodmarkFailed(input: { id: string; ownerId: string; failedAt: string; error: NormalizedRuntimeError; retryAt?: string; deadLetter?: boolean; }): Promise<void>Public method; parameters and return type are shown in the signature.
markPublishedmethodmarkPublished(id: string, ownerId: string, publishedAt: string): Promise<void>Public method; parameters and return type are shown in the signature.

RuntimeOutboxDispatcherOptions

Runtime Outbox Dispatcher Options interface with 7 public fields or methods.

Declaration

text
export interface RuntimeOutboxDispatcherOptions {
    ownerId: string;
    outbox: RuntimeMessageOutboxStore;
    bus: MessageBus;
    now?: () => string;
    leaseMs?: number;
    maxAttempts?: number;
    retryDelayMs?: (attempt: number) => number;
}

Contract members

MemberKindSignatureDescription
buspropertybus: MessageBusPublic property; its type, readonly modifier and optionality are shown in the signature.
leaseMspropertyleaseMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxAttemptspropertymaxAttempts?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
nowmethodnow?(): stringPublic method; parameters and return type are shown in the signature.
outboxpropertyoutbox: RuntimeMessageOutboxStorePublic property; its type, readonly modifier and optionality are shown in the signature.
ownerIdpropertyownerId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
retryDelayMsmethodretryDelayMs?(attempt: number): numberPublic method; parameters and return type are shown in the signature.

RuntimeOutboxDispatchResult

Runtime Outbox Dispatch Result interface with 4 public fields or methods.

Declaration

text
export interface RuntimeOutboxDispatchResult {
    claimed: number;
    published: number;
    failed: number;
    deadLettered: number;
}

Contract members

MemberKindSignatureDescription
claimedpropertyclaimed: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
deadLetteredpropertydeadLettered: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
failedpropertyfailed: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
publishedpropertypublished: numberPublic property; its type, readonly modifier and optionality are shown in the signature.