Skip to content

@codesoul-co/hypha-core / modules/runtime/projection

Using this module

Use the Projection module for executing runtime behavior at this boundary. It exports 2 classes, 1 function, 4 interfaces.

Import from the package entrypoint

ts
import {
  InMemoryProjectionStore,
  ProjectionEngine,
  validateProjectionRecord,
} from '@codesoul-co/hypha-core';

import type {
  ProjectionDefinition,
  ProjectionEngineOptions,
  ProjectionRecord,
  ProjectionStore,
} from '@codesoul-co/hypha-core';

Usage patterns

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

Public exports

SymbolKindSignatureDescription
InMemoryProjectionStoreclassnew InMemoryProjectionStore<TState = unknown>(): InMemoryProjectionStore<TState>In Memory Projection Store class with 4 public constructor or member entries; its exact declarations are listed below.
ProjectionEngineclassnew ProjectionEngine(options: ProjectionEngineOptions): ProjectionEngineProjection Engine class with 3 public constructor or member entries; its exact declarations are listed below.
validateProjectionRecordfunctionvalidateProjectionRecord<TState>(record: ProjectionRecord<TState>): voidValidate Projection Record function with 1 public call signature; parameters and return types are listed below.
ProjectionDefinitioninterfaceinterface ProjectionDefinitionProjection Definition interface with 5 public fields or methods.
ProjectionEngineOptionsinterfaceinterface ProjectionEngineOptionsProjection Engine Options interface with 2 public fields or methods.
ProjectionRecordinterfaceinterface ProjectionRecordProjection Record interface with 7 public fields or methods.
ProjectionStoreinterfaceinterface ProjectionStoreProjection Store interface with 3 public fields or methods.

InMemoryProjectionStore

In Memory Projection Store class with 4 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class InMemoryProjectionStore<TState = unknown> implements ProjectionStore<TState> {
    get(projectionId: string, key: string): Promise<ProjectionRecord<TState> | null>;
    put(record: ProjectionRecord<TState>, expectedRevision?: number): Promise<void>;
    delete(projectionId: string, key: string): Promise<void>;
}

Public members

MemberKindSignatureDescription
constructorconstructor<TState = unknown>(): InMemoryProjectionStore<TState>Creates an instance of this class.
deletemethoddelete(projectionId: string, key: string): Promise<void>Public method; parameters and return type are shown in the signature.
getmethodget(projectionId: string, key: string): Promise<ProjectionRecord<TState> | null>Public method; parameters and return type are shown in the signature.
putmethodput(record: ProjectionRecord<TState>, expectedRevision?: number): Promise<void>Public method; parameters and return type are shown in the signature.

ProjectionEngine

Projection Engine class with 3 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class ProjectionEngine {
    constructor(options: ProjectionEngineOptions);
    update<TState>(definition: ProjectionDefinition<TState>, store: ProjectionStore<TState>, scope: EventStreamScope, key?: string): Promise<ProjectionRecord<TState>>;
    rebuild<TState>(definition: ProjectionDefinition<TState>, store: ProjectionStore<TState>, scope: EventStreamScope, key?: string): Promise<ProjectionRecord<TState>>;
}

Public members

MemberKindSignatureDescription
constructorconstructor(options: ProjectionEngineOptions): ProjectionEngineCreates an instance of this class.
rebuildmethodrebuild<TState>(definition: ProjectionDefinition<TState>, store: ProjectionStore<TState>, scope: EventStreamScope, key?: string): Promise<ProjectionRecord<TState>>Public method; parameters and return type are shown in the signature.
updatemethodupdate<TState>(definition: ProjectionDefinition<TState>, store: ProjectionStore<TState>, scope: EventStreamScope, key?: string): Promise<ProjectionRecord<TState>>Public method; parameters and return type are shown in the signature.

validateProjectionRecord

Validate Projection Record function with 1 public call signature; parameters and return types are listed below.

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

Declaration

text
export declare function validateProjectionRecord<TState>(record: ProjectionRecord<TState>): void;

Call signature

text
validateProjectionRecord<TState>(record: ProjectionRecord<TState>): void

Parameters

ParameterTypeRequiredDescription
recordProjectionRecord<TState>YesRequired parameter; accepted values are defined by the type column.

Returns

  • Type: void
  • Description: Returns no value.

ProjectionDefinition

Projection Definition interface with 5 public fields or methods.

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

Declaration

text
export interface ProjectionDefinition<TState> {
    id: string;
    version: string;
    initialState(): TState;
    applies(event: PersistedFrameworkEvent): boolean;
    reduce(state: TState, event: PersistedFrameworkEvent): TState;
}

Contract members

MemberKindSignatureDescription
appliesmethodapplies(event: PersistedFrameworkEvent): booleanPublic method; parameters and return type are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
initialStatemethodinitialState(): TStatePublic method; parameters and return type are shown in the signature.
reducemethodreduce(state: TState, event: PersistedFrameworkEvent): TStatePublic method; parameters and return type are shown in the signature.
versionpropertyversion: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

ProjectionEngineOptions

Projection Engine Options interface with 2 public fields or methods.

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

Declaration

text
export interface ProjectionEngineOptions {
    events: Pick<EventRuntime, 'read'>;
    now?: () => string;
}

Contract members

MemberKindSignatureDescription
eventspropertyevents: Pick<EventRuntime, "read">Public property; its type, readonly modifier and optionality are shown in the signature.
nowmethodnow?(): stringPublic method; parameters and return type are shown in the signature.

ProjectionRecord

Projection Record interface with 7 public fields or methods.

Declaration

text
export interface ProjectionRecord<TState = unknown> {
    projectionId: string;
    projectionVersion: string;
    key: string;
    state: TState;
    lastSequence: number;
    revision: number;
    updatedAt: string;
}

Contract members

MemberKindSignatureDescription
keypropertykey: stringPublic 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.
projectionIdpropertyprojectionId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
projectionVersionpropertyprojectionVersion: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
revisionpropertyrevision: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
statepropertystate: TStatePublic 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.

ProjectionStore

Projection Store interface with 3 public fields or methods.

Declaration

text
export interface ProjectionStore<TState = unknown> {
    get(projectionId: string, key: string): Promise<ProjectionRecord<TState> | null>;
    put(record: ProjectionRecord<TState>, expectedRevision?: number): Promise<void>;
    delete?(projectionId: string, key: string): Promise<void>;
}

Contract members

MemberKindSignatureDescription
deletemethoddelete?(projectionId: string, key: string): Promise<void>Public method; parameters and return type are shown in the signature.
getmethodget(projectionId: string, key: string): Promise<ProjectionRecord<TState> | null>Public method; parameters and return type are shown in the signature.
putmethodput(record: ProjectionRecord<TState>, expectedRevision?: number): Promise<void>Public method; parameters and return type are shown in the signature.