feat: add peerDependencies

This commit is contained in:
2025-07-07 13:11:16 +02:00
parent 2093dd7097
commit dd1570d52e
36 changed files with 481 additions and 274 deletions

View File

@@ -8,9 +8,10 @@ import { EventFactory } from "./event-factory.ts";
*
* @param aggregate - Aggregate to instantiate and create an instance of.
*/
export function makeAggregateReducer<TEventFactory extends EventFactory, TAggregateRoot extends typeof AggregateRoot<TEventFactory>>(
aggregate: TAggregateRoot,
): Reducer<TEventFactory, InstanceType<TAggregateRoot>> {
export function makeAggregateReducer<
TEventFactory extends EventFactory,
TAggregateRoot extends typeof AggregateRoot<TEventFactory>,
>(aggregate: TAggregateRoot): Reducer<TEventFactory, InstanceType<TAggregateRoot>> {
return {
from(snapshot: Unknown) {
return aggregate.from(snapshot);
@@ -45,7 +46,10 @@ export function makeReducer<TEventFactory extends EventFactory, TState extends U
};
}
export type Reducer<TEventFactory extends EventFactory = EventFactory, TState extends Record<string, unknown> | AggregateRoot<TEventFactory> = any> = {
export type Reducer<
TEventFactory extends EventFactory = EventFactory,
TState extends Record<string, unknown> | AggregateRoot<TEventFactory> = any,
> = {
/**
* Return result directly from a snapshot that does not have any subsequent
* events to fold onto a state.
@@ -80,10 +84,10 @@ export type Reducer<TEventFactory extends EventFactory = EventFactory, TState ex
* })
* ```
*/
export type ReducerLeftFold<TState extends Record<string, unknown> = any, TEventFactory extends EventFactory = EventFactory> = (
state: TState,
event: TEventFactory["$events"][number]["$record"],
) => TState;
export type ReducerLeftFold<
TState extends Record<string, unknown> = any,
TEventFactory extends EventFactory = EventFactory,
> = (state: TState, event: TEventFactory["$events"][number]["$record"]) => TState;
export type ReducerState<TState extends Unknown> = () => TState;