Skip to content

@codesoul-co/hypha-core / modules/runtime/event-schema-registry

Using this module

Use the Event schema registry module for declaring and runtime-validating contracts. It exports 1 class, 5 interfaces.

Import from the package entrypoint

ts
import {
  InMemoryEventSchemaRegistry,
} from '@codesoul-co/hypha-core';

import type {
  EventSchemaDefinition,
  EventSchemaRegistry,
  EventUpcaster,
  EventValidationIssue,
  EventValidationResult,
} from '@codesoul-co/hypha-core';

Usage patterns

  • Use the 5 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.

Public exports

SymbolKindSignatureDescription
InMemoryEventSchemaRegistryclassnew InMemoryEventSchemaRegistry(): InMemoryEventSchemaRegistryIn Memory Event Schema Registry class with 5 public constructor or member entries; its exact declarations are listed below.
EventSchemaDefinitioninterfaceinterface EventSchemaDefinitionEvent Schema Definition interface with 6 public fields or methods.
EventSchemaRegistryinterfaceinterface EventSchemaRegistryEvent Schema Registry interface with 4 public fields or methods.
EventUpcasterinterfaceinterface EventUpcasterEvent Upcaster interface with 5 public fields or methods.
EventValidationIssueinterfaceinterface EventValidationIssueEvent Validation Issue interface with 3 public fields or methods.
EventValidationResultinterfaceinterface EventValidationResultEvent Validation Result interface with 5 public fields or methods.

InMemoryEventSchemaRegistry

In Memory Event Schema Registry class with 5 public constructor or member entries; its exact declarations are listed below.

Declaration

text
export declare class InMemoryEventSchemaRegistry implements EventSchemaRegistry {
    constructor();
    register(definition: EventSchemaDefinition): Promise<void>;
    registerUpcaster(upcaster: EventUpcaster): Promise<void>;
    validate(event: EventCreateInput): Promise<EventValidationResult>;
    upcast(event: PersistedFrameworkEvent, targetVersion?: string): Promise<PersistedFrameworkEvent>;
}

Public members

MemberKindSignatureDescription
constructorconstructor(): InMemoryEventSchemaRegistryCreates an instance of this class.
registermethodregister(definition: EventSchemaDefinition): Promise<void>Public method; parameters and return type are shown in the signature.
registerUpcastermethodregisterUpcaster(upcaster: EventUpcaster): Promise<void>Public method; parameters and return type are shown in the signature.
upcastmethodupcast(event: PersistedFrameworkEvent, targetVersion?: string): Promise<PersistedFrameworkEvent>Public method; parameters and return type are shown in the signature.
validatemethodvalidate(event: EventCreateInput): Promise<EventValidationResult>Public method; parameters and return type are shown in the signature.

EventSchemaDefinition

Event Schema Definition interface with 6 public fields or methods.

Declaration

text
export interface EventSchemaDefinition {
    eventType: string;
    version: string;
    schema: JsonSchema;
    schemaHash: string;
    sensitivePaths?: string[];
    upcasterRefs?: string[];
}

Contract members

MemberKindSignatureDescription
eventTypepropertyeventType: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
schemapropertyschema: JsonSchemaPublic property; its type, readonly modifier and optionality are shown in the signature.
schemaHashpropertyschemaHash: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
sensitivePathspropertysensitivePaths?: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
upcasterRefspropertyupcasterRefs?: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
versionpropertyversion: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

EventSchemaRegistry

Event Schema Registry interface with 4 public fields or methods.

Declaration

text
export interface EventSchemaRegistry {
    register(definition: EventSchemaDefinition): Promise<void>;
    registerUpcaster(upcaster: EventUpcaster): Promise<void>;
    validate(event: EventCreateInput): Promise<EventValidationResult>;
    upcast(event: PersistedFrameworkEvent, targetVersion?: string): Promise<PersistedFrameworkEvent>;
}

Contract members

MemberKindSignatureDescription
registermethodregister(definition: EventSchemaDefinition): Promise<void>Public method; parameters and return type are shown in the signature.
registerUpcastermethodregisterUpcaster(upcaster: EventUpcaster): Promise<void>Public method; parameters and return type are shown in the signature.
upcastmethodupcast(event: PersistedFrameworkEvent, targetVersion?: string): Promise<PersistedFrameworkEvent>Public method; parameters and return type are shown in the signature.
validatemethodvalidate(event: EventCreateInput): Promise<EventValidationResult>Public method; parameters and return type are shown in the signature.

EventUpcaster

Event Upcaster interface with 5 public fields or methods.

Declaration

text
export interface EventUpcaster {
    ref: string;
    eventType: string;
    fromVersion: string;
    toVersion: string;
    upcast(payload: unknown): unknown;
}

Contract members

MemberKindSignatureDescription
eventTypepropertyeventType: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
fromVersionpropertyfromVersion: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
refpropertyref: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
toVersionpropertytoVersion: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
upcastmethodupcast(payload: unknown): unknownPublic method; parameters and return type are shown in the signature.

EventValidationIssue

Event Validation Issue interface with 3 public fields or methods.

Declaration

text
export interface EventValidationIssue {
    path: string;
    code: string;
    message: string;
}

Contract members

MemberKindSignatureDescription
codepropertycode: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
messagepropertymessage: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
pathpropertypath: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

EventValidationResult

Event Validation Result interface with 5 public fields or methods.

Declaration

text
export interface EventValidationResult {
    valid: boolean;
    eventType: string;
    version: string;
    schemaHash?: string;
    issues: EventValidationIssue[];
}

Contract members

MemberKindSignatureDescription
eventTypepropertyeventType: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
issuespropertyissues: EventValidationIssue[]Public property; its type, readonly modifier and optionality are shown in the signature.
schemaHashpropertyschemaHash?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
validpropertyvalid: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
versionpropertyversion: stringPublic property; its type, readonly modifier and optionality are shown in the signature.