@robinmalfait/event-source 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,13 @@
1
- interface EventType<T extends string = any, P = any> {
1
+ interface EventType<T extends string = any, P = any, M = any> {
2
2
  aggregateId: string;
3
3
  eventId: string;
4
4
  eventName: T;
5
5
  payload: P;
6
+ metadata: M;
6
7
  recordedAt: Date;
7
8
  version: number;
8
9
  }
9
- declare function Event<const T extends string, P = null>(eventName: T, aggregateId: string, payload?: P): EventType<T, P>;
10
+ declare function Event<const T extends string, P = null, M = null>(eventName: T, aggregateId: string, payload?: P, metadata?: M): EventType<T, P>;
10
11
 
11
12
  type ApplyConcreteEvents<Events extends EventType> = Events extends EventType<infer EventName, any> ? {
12
13
  [T in EventName]: (event: Extract<Events, {
@@ -23,7 +24,7 @@ declare abstract class Aggregate {
23
24
  replayEvents(events?: EventType[]): this;
24
25
  private applyAnEvent;
25
26
  protected recordThat<T extends EventType>(event: T): this;
26
- releaseEvents(): EventType<any, any>[];
27
+ releaseEvents(): EventType<any, any, any>[];
27
28
  }
28
29
 
29
30
  interface CommandType<T extends string = any, P = any> {
@@ -95,7 +96,7 @@ declare class EventSource {
95
96
  static new(store: EventStore, commandHandlers: Map<string, CommandHandler>, projectors: Projector[], eventHandlers: EventHandler[]): EventSource;
96
97
  resetProjections(): Promise<void>;
97
98
  dispatch<T extends CommandType>(command: T): Promise<T>;
98
- loadEvents(): Promise<EventType<any, any>[]>;
99
+ loadEvents(): Promise<EventType<any, any, any>[]>;
99
100
  load<T extends Aggregate>(aggregate: T, aggregateId: string): Promise<T>;
100
101
  persist(aggregate: Aggregate): Promise<void>;
101
102
  loadPersist<T extends Aggregate>(aggregate: T, aggregateId: string, handle: (aggregate: T) => Promise<void> | void): Promise<void>;
@@ -118,7 +119,7 @@ declare function createEventMapper(mapper: EventMapper): (event: EventType, es:
118
119
  declare function createTestEventStore(commandHandlers: Record<string, CommandHandler>, projectors?: Projector[]): {
119
120
  ___: any;
120
121
  given(events?: EventType[]): Promise<void>;
121
- when<T extends CommandType<any, any>>(command: T | (() => T)): Promise<T>;
122
+ when<T extends CommandType>(command: T | (() => T)): Promise<T> | never;
122
123
  then(expectation: EventType[] | Error): Promise<void>;
123
124
  };
124
125
 
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- interface EventType<T extends string = any, P = any> {
1
+ interface EventType<T extends string = any, P = any, M = any> {
2
2
  aggregateId: string;
3
3
  eventId: string;
4
4
  eventName: T;
5
5
  payload: P;
6
+ metadata: M;
6
7
  recordedAt: Date;
7
8
  version: number;
8
9
  }
9
- declare function Event<const T extends string, P = null>(eventName: T, aggregateId: string, payload?: P): EventType<T, P>;
10
+ declare function Event<const T extends string, P = null, M = null>(eventName: T, aggregateId: string, payload?: P, metadata?: M): EventType<T, P>;
10
11
 
11
12
  type ApplyConcreteEvents<Events extends EventType> = Events extends EventType<infer EventName, any> ? {
12
13
  [T in EventName]: (event: Extract<Events, {
@@ -23,7 +24,7 @@ declare abstract class Aggregate {
23
24
  replayEvents(events?: EventType[]): this;
24
25
  private applyAnEvent;
25
26
  protected recordThat<T extends EventType>(event: T): this;
26
- releaseEvents(): EventType<any, any>[];
27
+ releaseEvents(): EventType<any, any, any>[];
27
28
  }
28
29
 
29
30
  interface CommandType<T extends string = any, P = any> {
@@ -95,7 +96,7 @@ declare class EventSource {
95
96
  static new(store: EventStore, commandHandlers: Map<string, CommandHandler>, projectors: Projector[], eventHandlers: EventHandler[]): EventSource;
96
97
  resetProjections(): Promise<void>;
97
98
  dispatch<T extends CommandType>(command: T): Promise<T>;
98
- loadEvents(): Promise<EventType<any, any>[]>;
99
+ loadEvents(): Promise<EventType<any, any, any>[]>;
99
100
  load<T extends Aggregate>(aggregate: T, aggregateId: string): Promise<T>;
100
101
  persist(aggregate: Aggregate): Promise<void>;
101
102
  loadPersist<T extends Aggregate>(aggregate: T, aggregateId: string, handle: (aggregate: T) => Promise<void> | void): Promise<void>;
@@ -118,7 +119,7 @@ declare function createEventMapper(mapper: EventMapper): (event: EventType, es:
118
119
  declare function createTestEventStore(commandHandlers: Record<string, CommandHandler>, projectors?: Projector[]): {
119
120
  ___: any;
120
121
  given(events?: EventType[]): Promise<void>;
121
- when<T extends CommandType<any, any>>(command: T | (() => T)): Promise<T>;
122
+ when<T extends CommandType>(command: T | (() => T)): Promise<T> | never;
122
123
  then(expectation: EventType[] | Error): Promise<void>;
123
124
  };
124
125