Skip to content

@codesoul-co/hypha-core / modules/runtime/message-bus

Using this module

Use the Message bus module for executing runtime behavior at this boundary. It exports 1 class, 7 functions, 6 interfaces.

Import from the package entrypoint

ts
import {
  InMemoryMessageBus,
  addMilliseconds,
  busError,
  createRuntimeMessageEnvelope,
  isAtOrBefore,
  nonEmpty,
  nonNegative,
  positive,
} from '@codesoul-co/hypha-core';

import type {
  InMemoryMessageBusOptions,
  MessageBus,
  MessageDelivery,
  MessagePublishRequest,
  MessagePublishResult,
  MessageSubscriptionRequest,
} from '@codesoul-co/hypha-core';

Usage patterns

  • Use the 6 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 1 class as constructable runtime implementations. Each symbol entry lists its constructor and public methods.
  • The module exposes 7 functions as direct operation entrypoints. Every overload, required/optional parameter, and return type is documented below.

Public exports

SymbolKindSignatureDescription
InMemoryMessageBusclassnew InMemoryMessageBus(options?: InMemoryMessageBusOptions): InMemoryMessageBusIn Memory Message Bus class with 7 public constructor or member entries; its exact declarations are listed below.
addMillisecondsfunctionaddMilliseconds(timestamp: string, milliseconds: number): stringAdd Milliseconds function with 1 public call signature; parameters and return types are listed below.
busErrorfunctionbusError(code: string, message: string, context?: Record<string, unknown>): FrameworkErrorBus Error function with 1 public call signature; parameters and return types are listed below.
createRuntimeMessageEnvelopefunctioncreateRuntimeMessageEnvelope<TPayload>(input: RuntimeMessageEnvelopeInput<TPayload>): RuntimeMessageEnvelope<TPayload>Create Runtime Message Envelope function with 1 public call signature; parameters and return types are listed below.
isAtOrBeforefunctionisAtOrBefore(left: string, right: string): booleanIs At Or Before function with 1 public call signature; parameters and return types are listed below.
nonEmptyfunctionnonEmpty(value: unknown, label: string): asserts value is stringNon Empty function with 1 public call signature; parameters and return types are listed below.
nonNegativefunctionnonNegative(value: number, label?: string): numberNon Negative function with 1 public call signature; parameters and return types are listed below.
positivefunctionpositive(value: number, label: string): numberPositive function with 1 public call signature; parameters and return types are listed below.
InMemoryMessageBusOptionsinterfaceinterface InMemoryMessageBusOptionsIn Memory Message Bus Options interface with 6 public fields or methods.
MessageBusinterfaceinterface MessageBusMessage Bus interface with 5 public fields or methods.
MessageDeliveryinterfaceinterface MessageDeliveryMessage Delivery interface with 9 public fields or methods.
MessagePublishRequestinterfaceinterface MessagePublishRequestMessage Publish Request interface with 1 public fields or methods.
MessagePublishResultinterfaceinterface MessagePublishResultMessage Publish Result interface with 6 public fields or methods.
MessageSubscriptionRequestinterfaceinterface MessageSubscriptionRequestMessage Subscription Request interface with 8 public fields or methods.

InMemoryMessageBus

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

Declaration

text
export declare class InMemoryMessageBus implements MessageBus {
    constructor(options?: InMemoryMessageBusOptions);
    publish<TPayload>(request: MessagePublishRequest<TPayload>): Promise<MessagePublishResult>;
    publishBatch<TPayload>(requests: MessagePublishRequest<TPayload>[]): Promise<MessagePublishResult[]>;
    subscribe<TPayload>(request: MessageSubscriptionRequest): AsyncIterable<MessageDelivery<TPayload>>;
    health(): Promise<ProviderHealth>;
    close(): Promise<void>;
    listDeadLetters(consumerGroup: string): RuntimeMessageEnvelope[];
}

Public members

MemberKindSignatureDescription
closemethodclose(): Promise<void>Public method; parameters and return type are shown in the signature.
constructorconstructor(options?: InMemoryMessageBusOptions): InMemoryMessageBusCreates an instance of this class.
healthmethodhealth(): Promise<ProviderHealth>Public method; parameters and return type are shown in the signature.
listDeadLettersmethodlistDeadLetters(consumerGroup: string): RuntimeMessageEnvelope[]Public method; parameters and return type are shown in the signature.
publishmethodpublish<TPayload>(request: MessagePublishRequest<TPayload>): Promise<MessagePublishResult>Public method; parameters and return type are shown in the signature.
publishBatchmethodpublishBatch<TPayload>(requests: MessagePublishRequest<TPayload>[]): Promise<MessagePublishResult[]>Public method; parameters and return type are shown in the signature.
subscribemethodsubscribe<TPayload>(request: MessageSubscriptionRequest): AsyncIterable<MessageDelivery<TPayload>>Public method; parameters and return type are shown in the signature.

addMilliseconds

Add Milliseconds function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function addMilliseconds(timestamp: string, milliseconds: number): string;

Call signature

text
addMilliseconds(timestamp: string, milliseconds: number): string

Parameters

ParameterTypeRequiredDescription
timestampstringYesRequired parameter; accepted values are defined by the type column.
millisecondsnumberYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: string
  • Description: The return contract is defined by the type shown above.

busError

Bus Error function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function busError(code: string, message: string, context?: Record<string, unknown>): FrameworkError;

Call signature

text
busError(code: string, message: string, context?: Record<string, unknown>): FrameworkError

Parameters

ParameterTypeRequiredDescription
codestringYesRequired parameter; accepted values are defined by the type column.
messagestringYesRequired parameter; accepted values are defined by the type column.
contextRecord<string, unknown>NoOptional parameter; accepted values are defined by the type column.

Returns

  • Type: FrameworkError
  • Description: The return contract is defined by the type shown above.

createRuntimeMessageEnvelope

Create Runtime Message Envelope function with 1 public call signature; parameters and return types are listed below.

  • Kind: function
  • Import: import { createRuntimeMessageEnvelope } from '@codesoul-co/hypha-core';
  • Source module: modules/runtime/message-bus

Declaration

text
export declare function createRuntimeMessageEnvelope<TPayload>(input: RuntimeMessageEnvelopeInput<TPayload>): RuntimeMessageEnvelope<TPayload>;

Call signature

text
createRuntimeMessageEnvelope<TPayload>(input: RuntimeMessageEnvelopeInput<TPayload>): RuntimeMessageEnvelope<TPayload>

Parameters

ParameterTypeRequiredDescription
inputRuntimeMessageEnvelopeInput<TPayload>YesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: RuntimeMessageEnvelope<TPayload>
  • Description: The return contract is defined by the type shown above.

isAtOrBefore

Is At Or Before function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function isAtOrBefore(left: string, right: string): boolean;

Call signature

text
isAtOrBefore(left: string, right: string): boolean

Parameters

ParameterTypeRequiredDescription
leftstringYesRequired parameter; accepted values are defined by the type column.
rightstringYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: boolean
  • Description: The return contract is defined by the type shown above.

nonEmpty

Non Empty function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function nonEmpty(value: unknown, label: string): asserts value is string;

Call signature

text
nonEmpty(value: unknown, label: string): asserts value is string

Parameters

ParameterTypeRequiredDescription
valueunknownYesRequired parameter; accepted values are defined by the type column.
labelstringYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: asserts value is string
  • Description: The return contract is defined by the type shown above.

nonNegative

Non Negative function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function nonNegative(value: number, label?: string): number;

Call signature

text
nonNegative(value: number, label?: string): number

Parameters

ParameterTypeRequiredDescription
valuenumberYesRequired parameter; accepted values are defined by the type column.
labelstringNoOptional parameter; accepted values are defined by the type column.

Returns

  • Type: number
  • Description: The return contract is defined by the type shown above.

positive

Positive function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function positive(value: number, label: string): number;

Call signature

text
positive(value: number, label: string): number

Parameters

ParameterTypeRequiredDescription
valuenumberYesRequired parameter; accepted values are defined by the type column.
labelstringYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: number
  • Description: The return contract is defined by the type shown above.

InMemoryMessageBusOptions

In Memory Message Bus Options interface with 6 public fields or methods.

  • Kind: interface
  • Import: import type { InMemoryMessageBusOptions } from '@codesoul-co/hypha-core';
  • Source module: modules/runtime/message-bus

Declaration

text
export interface InMemoryMessageBusOptions {
    now?: () => string;
    maxDeliveryAttempts?: number;
    defaultAckDeadlineMs?: number;
    maxMessageBytes?: number;
    maxQueueDepth?: number;
    pollIntervalMs?: number;
}

Contract members

MemberKindSignatureDescription
defaultAckDeadlineMspropertydefaultAckDeadlineMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxDeliveryAttemptspropertymaxDeliveryAttempts?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxMessageBytespropertymaxMessageBytes?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxQueueDepthpropertymaxQueueDepth?: 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.
pollIntervalMspropertypollIntervalMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

MessageBus

Message Bus interface with 5 public fields or methods.

Declaration

text
export interface MessageBus {
    publish<TPayload>(request: MessagePublishRequest<TPayload>): Promise<MessagePublishResult>;
    publishBatch<TPayload>(requests: MessagePublishRequest<TPayload>[]): Promise<MessagePublishResult[]>;
    subscribe<TPayload>(request: MessageSubscriptionRequest): AsyncIterable<MessageDelivery<TPayload>>;
    health(): Promise<ProviderHealth>;
    close(): Promise<void>;
}

Contract members

MemberKindSignatureDescription
closemethodclose(): Promise<void>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.
publishmethodpublish<TPayload>(request: MessagePublishRequest<TPayload>): Promise<MessagePublishResult>Public method; parameters and return type are shown in the signature.
publishBatchmethodpublishBatch<TPayload>(requests: MessagePublishRequest<TPayload>[]): Promise<MessagePublishResult[]>Public method; parameters and return type are shown in the signature.
subscribemethodsubscribe<TPayload>(request: MessageSubscriptionRequest): AsyncIterable<MessageDelivery<TPayload>>Public method; parameters and return type are shown in the signature.

MessageDelivery

Message Delivery interface with 9 public fields or methods.

Declaration

text
export interface MessageDelivery<TPayload = unknown> {
    envelope: RuntimeMessageEnvelope<TPayload>;
    deliveryId: string;
    attempt: number;
    receivedAt: string;
    ackDeadlineAt: string;
    ack(): Promise<void>;
    nack(options?: {
        delayMs?: number;
        reason?: string;
    }): Promise<void>;
    deadLetter(reason: string): Promise<void>;
    extendAckDeadline(extensionMs: number): Promise<void>;
}

Contract members

MemberKindSignatureDescription
ackmethodack(): Promise<void>Public method; parameters and return type are shown in the signature.
ackDeadlineAtpropertyackDeadlineAt: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
attemptpropertyattempt: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
deadLettermethoddeadLetter(reason: string): Promise<void>Public method; parameters and return type are shown in the signature.
deliveryIdpropertydeliveryId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
envelopepropertyenvelope: RuntimeMessageEnvelope<TPayload>Public property; its type, readonly modifier and optionality are shown in the signature.
extendAckDeadlinemethodextendAckDeadline(extensionMs: number): Promise<void>Public method; parameters and return type are shown in the signature.
nackmethodnack(options?: { delayMs?: number; reason?: string; }): Promise<void>Public method; parameters and return type are shown in the signature.
receivedAtpropertyreceivedAt: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

MessagePublishRequest

Message Publish Request interface with 1 public fields or methods.

Declaration

text
export interface MessagePublishRequest<TPayload = unknown> {
    envelope: RuntimeMessageEnvelopeInput<TPayload>;
}

Contract members

MemberKindSignatureDescription
envelopepropertyenvelope: RuntimeMessageEnvelopeInput<TPayload>Public property; its type, readonly modifier and optionality are shown in the signature.

MessagePublishResult

Message Publish Result interface with 6 public fields or methods.

Declaration

text
export interface MessagePublishResult {
    messageId: string;
    topic: string;
    partitionKey: string;
    sequence: number;
    publishedAt: string;
    reused: boolean;
}

Contract members

MemberKindSignatureDescription
messageIdpropertymessageId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
partitionKeypropertypartitionKey: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
publishedAtpropertypublishedAt: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
reusedpropertyreused: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
sequencepropertysequence: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
topicpropertytopic: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

MessageSubscriptionRequest

Message Subscription Request interface with 8 public fields or methods.

  • Kind: interface
  • Import: import type { MessageSubscriptionRequest } from '@codesoul-co/hypha-core';
  • Source module: modules/runtime/message-bus

Declaration

text
export interface MessageSubscriptionRequest {
    consumerId: string;
    consumerGroup?: string;
    topic: string;
    partitionKey?: string;
    maxMessages?: number;
    idleTimeoutMs?: number;
    ackDeadlineMs?: number;
    signal?: AbortSignal;
}

Contract members

MemberKindSignatureDescription
ackDeadlineMspropertyackDeadlineMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
consumerGrouppropertyconsumerGroup?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
consumerIdpropertyconsumerId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
idleTimeoutMspropertyidleTimeoutMs?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxMessagespropertymaxMessages?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
partitionKeypropertypartitionKey?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
signalpropertysignal?: AbortSignalPublic property; its type, readonly modifier and optionality are shown in the signature.
topicpropertytopic: stringPublic property; its type, readonly modifier and optionality are shown in the signature.