export interface VectorClock { [nodeId: string]: number; } export interface ActorMetadata { namespace?: string; type: string; eventThreshold?: number; identifiedBy: string; searchableBy?: string[]; aggregateFrom?: string[]; storeEventPack?: boolean; snapshotOnRead?: boolean; _actorTypes: string[]; _eventTypes: string[]; _eventsRead?: number; [key: string]: unknown; } export interface HandlerDefinition { when: boolean | string | ((state: Record, message?: Record) => boolean); then: ((...args: unknown[]) => unknown); exclusive?: boolean; map?: boolean | ((fn: (...args: unknown[]) => unknown) => (...args: unknown[]) => unknown); } export interface ActorInstance { actor: ActorMetadata; state: Record; commands: Record; events: Record; [key: string]: unknown; } export interface ActorRegistration { factory: (id?: unknown) => unknown; metadata: ActorInstance; } export interface ActorMap { [type: string]: ActorRegistration; } export interface Message { type?: string; topic?: string; id?: string; [key: string]: unknown; } export interface Event extends Message { _actorId?: string; _actorType?: string; _createdByVector?: string; _createdByVersion?: number; _createdBy?: string; _createdById?: string; _createdOn?: string; _initiatedBy?: string; _initiatedById?: string; } export interface CommandResult { rejected?: boolean; message: Message; actor: ActorMetadata; state: Record; original?: Record; events?: Event[]; reason?: Error; } export interface ActorCacheInstance { fetch: (id: unknown) => Promise | undefined>; getSystemId?: (id: unknown, asOf?: unknown) => Promise; mapIds?: (systemId: string, actorId: unknown) => Promise; store: (id: unknown, vector: string, state: Record) => Promise; } export interface ActorStoreInstance { fetch: (id: unknown) => Promise | undefined>; fetchByLastEventDate?: (id: unknown, lastEventDate: unknown) => Promise | undefined>; fetchByLastEventId?: (id: unknown, lastEventId: unknown) => Promise | undefined>; getActorId?: (systemId: string, asOf?: unknown) => Promise; getSystemId?: (id: unknown, asOf?: unknown) => Promise; mapIds?: (systemId: string, actorId: unknown) => Promise; store: (id: unknown, vector: string, state: Record) => Promise; findAncestor?: (id: unknown, instances: unknown[], excluded: unknown[]) => Promise; } export interface EventCacheInstance { getEventsFor: (id: unknown, lastEventId?: unknown) => Promise; getEventPackFor?: (id: unknown, vector: string) => Promise; storeEvents: (id: unknown, events: Event[]) => Promise; storeEventPack?: (id: unknown, vector: string, events: Event[]) => Promise; } export interface EventStoreInstance { getEventsFor: (id: unknown, lastEventId?: unknown) => Promise; getEventPackFor?: (id: unknown, vector: string) => Promise; getEventStreamFor?: (id: unknown, options: StreamOptions) => Iterable; storeEvents: (id: unknown, events: Event[]) => Promise; storeEventPack?: (id: unknown, vector: string, events: Event[]) => Promise; findEvents?: (criteria: unknown, lastEventId?: unknown) => Promise; getEventsByIndex?: (indexName: string, indexValue: unknown, lastEventId?: unknown) => Promise; } export interface SearchAdapterInstance { find: (criteria: Record) => unknown[] | Promise; update: (fieldList: string[], updated: Record, original: Record) => Promise; } export interface AdapterLibrary { create: (type: string) => Promise; state?: Record; [key: string]: unknown; } export interface StreamOptions { since?: unknown; sinceId?: unknown; until?: unknown; untilId?: unknown; filter?: (event: Event) => boolean; eventTypes?: string[]; actorType?: string; actorId?: unknown; actorTypes?: string[]; actors?: Record; } export interface ConsequentConfig { actors?: string | ActorInstance[] | Record | (() => unknown); actorCache?: AdapterLibrary; actorStore?: AdapterLibrary; eventCache?: AdapterLibrary; eventStore?: AdapterLibrary; searchAdapter?: AdapterLibrary; fount?: Fount; queue?: Queue; concurrencyLimit?: number; nodeId?: string; logging?: LogConfig | { level: string; }; } export interface ConsequentApi { apply: (instance: ActorInstance, message: Message) => Promise; fetch: (type: string, id: unknown, readOnly?: boolean) => Promise; fetchAll: (options: Record, readOnly?: boolean) => Promise>; find: (type: string, criteria: Record) => Promise; getActorStream: (actorType: string, actorId: unknown, options: StreamOptions) => AsyncGenerator>; getEventStream: (actorId: unknown, options: StreamOptions) => Promise>; handle: (id: unknown, topic: string, message: Message) => Promise; topics: string[]; actors: ActorMap; } export interface Queue { add: (id: string | number, fn: () => unknown) => Promise; } export interface Fount { inject: (fn: unknown) => Promise; [key: string]: unknown; } export type Flakes = () => string; export interface Logger { debug: (msg: string) => void; info: (msg: string) => void; warn: (msg: string) => void; error: (msg: string) => void; } export interface LogConfig { level?: string; stream?: unknown; adapters?: Record; }