Skip to content

@codesoul-co/hypha-core / modules/runtime/event-store

Using this module

Use the Event store module for creating, recording, or reading Event contracts. It exports 1 class, 8 functions, 8 interfaces.

Import from the package entrypoint

ts
import {
  InMemoryDurableEventStore,
  createPersistedEventBatch,
  decodeEventStreamHeadCursor,
  encodeEventStreamHeadCursor,
  eventStreamKey,
  hashEventAppendRequest,
  streamHeadListLimit,
  validateEventAppendRequest,
} from '@codesoul-co/hypha-core';

import type {
  DurableEventStore,
  EventAppendRequest,
  EventAppendResult,
  EventStreamHead,
  EventStreamScope,
  InMemoryDurableEventStoreOptions,
  ListEventStreamHeadsRequest,
  ListEventStreamHeadsResult,
} from '@codesoul-co/hypha-core';

// The complete export list is documented below.

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

Public exports

SymbolKindSignatureDescription
InMemoryDurableEventStoreclassnew InMemoryDurableEventStore(options: InMemoryDurableEventStoreOptions): InMemoryDurableEventStoreIn Memory Durable Event Store class with 7 public constructor or member entries; its exact declarations are listed below.
createPersistedEventBatchfunctioncreatePersistedEventBatch(request: EventAppendRequest, firstSequence: number, firstGlobalSequence: number, recordedAt: string): PersistedFrameworkEvent[]Create Persisted Event Batch function with 1 public call signature; parameters and return types are listed below.
decodeEventStreamHeadCursorfunctiondecodeEventStreamHeadCursor(cursor: string): stringDecode Event Stream Head Cursor function with 1 public call signature; parameters and return types are listed below.
encodeEventStreamHeadCursorfunctionencodeEventStreamHeadCursor(streamKey: string): stringEncode Event Stream Head Cursor function with 1 public call signature; parameters and return types are listed below.
eventStreamKeyfunctioneventStreamKey(scope: EventStreamScope): stringEvent Stream Key function with 1 public call signature; parameters and return types are listed below.
hashEventAppendRequestfunctionhashEventAppendRequest(request: EventAppendRequest): stringHash Event Append Request function with 1 public call signature; parameters and return types are listed below.
streamHeadListLimitfunctionstreamHeadListLimit(limit?: number): numberStream Head List Limit function with 1 public call signature; parameters and return types are listed below.
validateEventAppendRequestfunctionvalidateEventAppendRequest(request: EventAppendRequest): voidValidate Event Append Request function with 1 public call signature; parameters and return types are listed below.
validateEventAppendSchemasfunctionvalidateEventAppendSchemas(registry: EventSchemaRegistry, request: EventAppendRequest): Promise<void>Validate Event Append Schemas function with 1 public call signature; parameters and return types are listed below.
DurableEventStoreinterfaceinterface DurableEventStoreDurable Event Store interface with 6 public fields or methods.
EventAppendRequestinterfaceinterface EventAppendRequestEvent Append Request interface with 7 public fields or methods.
EventAppendResultinterfaceinterface EventAppendResultEvent Append Result interface with 5 public fields or methods.
EventStreamHeadinterfaceinterface EventStreamHeadEvent Stream Head interface with 5 public fields or methods.
EventStreamScopeinterfaceinterface EventStreamScopeEvent Stream Scope interface with 3 public fields or methods.
InMemoryDurableEventStoreOptionsinterfaceinterface InMemoryDurableEventStoreOptionsIn Memory Durable Event Store Options interface with 2 public fields or methods.
ListEventStreamHeadsRequestinterfaceinterface ListEventStreamHeadsRequestList Event Stream Heads Request interface with 2 public fields or methods.
ListEventStreamHeadsResultinterfaceinterface ListEventStreamHeadsResultList Event Stream Heads Result interface with 2 public fields or methods.

InMemoryDurableEventStore

In Memory Durable Event Store class with 7 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class InMemoryDurableEventStore implements DurableEventStore {
    constructor(options: InMemoryDurableEventStoreOptions);
    append(request: EventAppendRequest): Promise<EventAppendResult>;
    readStream(scope: EventStreamScope, fromSequence?: number): Promise<PersistedFrameworkEvent[]>;
    readById(scope: EventStreamScope, eventId: string): Promise<PersistedFrameworkEvent | null>;
    getStreamHead(scope: EventStreamScope): Promise<EventStreamHead | null>;
    listStreamHeads(request?: ListEventStreamHeadsRequest): Promise<ListEventStreamHeadsResult>;
    health(): Promise<ProviderHealth>;
}

Public members

MemberKindSignatureDescription
appendmethodappend(request: EventAppendRequest): Promise<EventAppendResult>Public method; parameters and return type are shown in the signature.
constructorconstructor(options: InMemoryDurableEventStoreOptions): InMemoryDurableEventStoreCreates an instance of this class.
getStreamHeadmethodgetStreamHead(scope: EventStreamScope): Promise<EventStreamHead | 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.
listStreamHeadsmethodlistStreamHeads(request?: ListEventStreamHeadsRequest): Promise<ListEventStreamHeadsResult>Public method; parameters and return type are shown in the signature.
readByIdmethodreadById(scope: EventStreamScope, eventId: string): Promise<PersistedFrameworkEvent | null>Public method; parameters and return type are shown in the signature.
readStreammethodreadStream(scope: EventStreamScope, fromSequence?: number): Promise<PersistedFrameworkEvent[]>Public method; parameters and return type are shown in the signature.

createPersistedEventBatch

Create Persisted Event Batch function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function createPersistedEventBatch(request: EventAppendRequest, firstSequence: number, firstGlobalSequence: number, recordedAt: string): PersistedFrameworkEvent[];

Call signature

text
createPersistedEventBatch(request: EventAppendRequest, firstSequence: number, firstGlobalSequence: number, recordedAt: string): PersistedFrameworkEvent[]

Parameters

ParameterTypeRequiredDescription
requestEventAppendRequestYesRequired parameter; accepted values are defined by the type column.
firstSequencenumberYesRequired parameter; accepted values are defined by the type column.
firstGlobalSequencenumberYesRequired parameter; accepted values are defined by the type column.
recordedAtstringYesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: PersistedFrameworkEvent<unknown>[]
  • Description: The return contract is defined by the type shown above.

decodeEventStreamHeadCursor

Decode Event Stream Head Cursor function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function decodeEventStreamHeadCursor(cursor: string): string;

Call signature

text
decodeEventStreamHeadCursor(cursor: string): string

Parameters

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

Returns

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

encodeEventStreamHeadCursor

Encode Event Stream Head Cursor function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function encodeEventStreamHeadCursor(streamKey: string): string;

Call signature

text
encodeEventStreamHeadCursor(streamKey: string): string

Parameters

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

Returns

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

eventStreamKey

Event Stream Key function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function eventStreamKey(scope: EventStreamScope): string;

Call signature

text
eventStreamKey(scope: EventStreamScope): string

Parameters

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

Returns

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

hashEventAppendRequest

Hash Event Append Request function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function hashEventAppendRequest(request: EventAppendRequest): string;

Call signature

text
hashEventAppendRequest(request: EventAppendRequest): string

Parameters

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

Returns

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

streamHeadListLimit

Stream Head List Limit function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function streamHeadListLimit(limit?: number): number;

Call signature

text
streamHeadListLimit(limit?: number): number

Parameters

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

Returns

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

validateEventAppendRequest

Validate Event Append Request function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function validateEventAppendRequest(request: EventAppendRequest): void;

Call signature

text
validateEventAppendRequest(request: EventAppendRequest): void

Parameters

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

Returns

  • Type: void
  • Description: Returns no value.

validateEventAppendSchemas

Validate Event Append Schemas function with 1 public call signature; parameters and return types are listed below.

Declaration

text
export declare function validateEventAppendSchemas(registry: EventSchemaRegistry, request: EventAppendRequest): Promise<void>;

Call signature

text
validateEventAppendSchemas(registry: EventSchemaRegistry, request: EventAppendRequest): Promise<void>

Parameters

ParameterTypeRequiredDescription
registryEventSchemaRegistryYesRequired parameter; accepted values are defined by the type column.
requestEventAppendRequestYesRequired parameter; accepted values are defined by the type column.

Returns

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

DurableEventStore

Durable Event Store interface with 6 public fields or methods.

Declaration

text
export interface DurableEventStore {
    append(request: EventAppendRequest): Promise<EventAppendResult>;
    readStream(scope: EventStreamScope, fromSequence?: number): Promise<PersistedFrameworkEvent[]>;
    readById(scope: EventStreamScope, eventId: string): Promise<PersistedFrameworkEvent | null>;
    getStreamHead(scope: EventStreamScope): Promise<EventStreamHead | null>;
    listStreamHeads(request?: ListEventStreamHeadsRequest): Promise<ListEventStreamHeadsResult>;
    health(): Promise<ProviderHealth>;
}

Contract members

MemberKindSignatureDescription
appendmethodappend(request: EventAppendRequest): Promise<EventAppendResult>Public method; parameters and return type are shown in the signature.
getStreamHeadmethodgetStreamHead(scope: EventStreamScope): Promise<EventStreamHead | 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.
listStreamHeadsmethodlistStreamHeads(request?: ListEventStreamHeadsRequest): Promise<ListEventStreamHeadsResult>Public method; parameters and return type are shown in the signature.
readByIdmethodreadById(scope: EventStreamScope, eventId: string): Promise<PersistedFrameworkEvent | null>Public method; parameters and return type are shown in the signature.
readStreammethodreadStream(scope: EventStreamScope, fromSequence?: number): Promise<PersistedFrameworkEvent[]>Public method; parameters and return type are shown in the signature.

EventAppendRequest

Event Append Request interface with 7 public fields or methods.

Declaration

text
export interface EventAppendRequest {
    scope: EventStreamScope;
    events: EventCreateInput[];
    expectedLastSequence: number;
    expectedRunRevision?: number;
    fencingToken?: number;
    idempotencyKey: string;
    transactionGroupId?: string;
}

Contract members

MemberKindSignatureDescription
eventspropertyevents: EventCreateInput<unknown>[]Public property; its type, readonly modifier and optionality are shown in the signature.
expectedLastSequencepropertyexpectedLastSequence: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
expectedRunRevisionpropertyexpectedRunRevision?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
fencingTokenpropertyfencingToken?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
idempotencyKeypropertyidempotencyKey: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
scopepropertyscope: EventStreamScopePublic property; its type, readonly modifier and optionality are shown in the signature.
transactionGroupIdpropertytransactionGroupId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

EventAppendResult

Event Append Result interface with 5 public fields or methods.

Declaration

text
export interface EventAppendResult {
    events: PersistedFrameworkEvent[];
    firstSequence: number;
    lastSequence: number;
    runRevision: number;
    reused: boolean;
}

Contract members

MemberKindSignatureDescription
eventspropertyevents: PersistedFrameworkEvent<unknown>[]Public property; its type, readonly modifier and optionality are shown in the signature.
firstSequencepropertyfirstSequence: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
lastSequencepropertylastSequence: numberPublic 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.
runRevisionpropertyrunRevision: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

EventStreamHead

Event Stream Head interface with 5 public fields or methods.

Declaration

text
export interface EventStreamHead {
    scope: EventStreamScope;
    lastSequence: number;
    runRevision: number;
    fencingToken?: number;
    updatedAt: string;
}

Contract members

MemberKindSignatureDescription
fencingTokenpropertyfencingToken?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
lastSequencepropertylastSequence: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
runRevisionpropertyrunRevision: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
scopepropertyscope: EventStreamScopePublic property; its type, readonly modifier and optionality are shown in the signature.
updatedAtpropertyupdatedAt: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

EventStreamScope

Event Stream Scope interface with 3 public fields or methods.

Declaration

text
export interface EventStreamScope {
    tenantId?: string;
    userId: string;
    runId: string;
}

Contract members

MemberKindSignatureDescription
runIdpropertyrunId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
tenantIdpropertytenantId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
userIdpropertyuserId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

InMemoryDurableEventStoreOptions

In Memory Durable Event Store Options interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { InMemoryDurableEventStoreOptions } from '@codesoul-co/hypha-core';
  • Source module: modules/runtime/event-store

Declaration

text
export interface InMemoryDurableEventStoreOptions {
    schemaRegistry: EventSchemaRegistry;
    now?: () => string;
}

Contract members

MemberKindSignatureDescription
nowmethodnow?(): stringPublic method; parameters and return type are shown in the signature.
schemaRegistrypropertyschemaRegistry: EventSchemaRegistryPublic property; its type, readonly modifier and optionality are shown in the signature.

ListEventStreamHeadsRequest

List Event Stream Heads Request interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { ListEventStreamHeadsRequest } from '@codesoul-co/hypha-core';
  • Source module: modules/runtime/event-store

Declaration

text
export interface ListEventStreamHeadsRequest {
    cursor?: string;
    limit?: number;
}

Contract members

MemberKindSignatureDescription
cursorpropertycursor?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
limitpropertylimit?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

ListEventStreamHeadsResult

List Event Stream Heads Result interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { ListEventStreamHeadsResult } from '@codesoul-co/hypha-core';
  • Source module: modules/runtime/event-store

Declaration

text
export interface ListEventStreamHeadsResult {
    heads: EventStreamHead[];
    nextCursor?: string;
}

Contract members

MemberKindSignatureDescription
headspropertyheads: EventStreamHead[]Public property; its type, readonly modifier and optionality are shown in the signature.
nextCursorpropertynextCursor?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.