@othree.io/chisel
Version:
Event sourcing made easy
9 lines • 1.42 kB
TypeScript
import { Optional } from '@othree.io/optional';
import { ChiselEvent, TriggeredEvent, EventSourceConfiguration, State, NewState, Command, InternalTriggeredEvent } from './types';
export type PersistEvent = (event: InternalTriggeredEvent) => Promise<Optional<InternalTriggeredEvent>>;
export type Reduce<AggregateRoot, Event extends ChiselEvent> = (state: AggregateRoot, event: TriggeredEvent<Event>) => AggregateRoot;
export type LoadState<AggregateRoot> = (contextId: Optional<string>) => Promise<Optional<State<AggregateRoot>>>;
export declare const loadState: <AggregateRoot>(configuration: EventSourceConfiguration<AggregateRoot>) => (getEvents: (contextId: string) => Promise<Optional<Array<InternalTriggeredEvent>>>) => (getInitialState: (contextId: Optional<string>) => Promise<Optional<AggregateRoot>>) => <Event extends ChiselEvent>(reduce: Reduce<AggregateRoot, Event>) => LoadState<AggregateRoot>;
export type CalculateNewState<AggregateRoot> = (command: Command, state: State<AggregateRoot>, newEvents: Array<ChiselEvent>) => Promise<Optional<NewState<AggregateRoot>>>;
export declare const calculateNewState: <AggregateRoot>(configuration: EventSourceConfiguration<AggregateRoot>) => (newId: () => string) => (now: () => number) => (persistEvent: PersistEvent) => <Event extends ChiselEvent>(reduce: Reduce<AggregateRoot, Event>) => CalculateNewState<AggregateRoot>;
//# sourceMappingURL=event-source.d.ts.map