-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d555e2c
commit 8cf76f6
Showing
17 changed files
with
1,217 additions
and
793 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { SyncOrAsyncIterable } from '@mithic/commons'; | ||
|
||
export async function collect<T>(entries: SyncOrAsyncIterable<T>): Promise<T[]> { | ||
const results = []; | ||
for await (const entry of entries) { | ||
results.push(entry); | ||
} | ||
return results; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,16 @@ | ||
import { AbortOptions, MaybePromise } from '@mithic/commons'; | ||
|
||
/** Aggregate command haler. */ | ||
export interface AggregateCommandHandler<Store, Command, Event> { | ||
export interface AggregateCommandHandler<State, Command, Event> { | ||
/** Handles a command and produces an event. */ | ||
handle(store: Store, command: Command, options?: AbortOptions): MaybePromise<Event | undefined>; | ||
handle(store: State, command: Command, options?: AbortOptions): MaybePromise<Event | undefined>; | ||
} | ||
|
||
/** Aggregate state projection. */ | ||
export interface AggregateProjection<Store, Event> { | ||
export interface AggregateProjection<State, Event> { | ||
/** Applies an event to state. */ | ||
reduce(store: Store, event: Event, options?: AbortOptions): MaybePromise<Store>; | ||
reduce(store: State, event: Event, options?: AbortOptions): MaybePromise<State>; | ||
|
||
/** Validates an event and returns any error. */ | ||
validate(store: Store, event: Event, options?: AbortOptions): MaybePromise<Error | undefined>; | ||
validate(store: State, event: Event, options?: AbortOptions): MaybePromise<Error | undefined>; | ||
} | ||
|
||
/** Aggregate state query resolver. */ | ||
export interface AggregateQueryResolver<Store, Query> { | ||
/** Resolves query to current state. */ | ||
resolve(store: Store, query: Query, options?: AbortOptions): AggregateQueryResult<Query>; | ||
} | ||
|
||
declare const ResultMarker: unique symbol; | ||
|
||
/** Aggregate query object type. */ | ||
export interface AggregateQuery<Result = unknown> { | ||
/** Result type marker */ | ||
[ResultMarker]?: Result; | ||
} | ||
|
||
/** Aggregate query result type. */ | ||
export type AggregateQueryResult<Query> = Query extends AggregateQuery<infer Result> ? Result : unknown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.