@robinmalfait/event-source 0.0.11 → 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> {
@@ -43,18 +44,6 @@ declare function abort<T>(message: string, attributes?: T): void;
43
44
 
44
45
  declare function objectToYaml<T extends Object>(object: T): string;
45
46
 
46
- interface Job {
47
- handle: () => void;
48
- resolve: (value: unknown) => unknown;
49
- reject: (value: unknown) => unknown;
50
- }
51
- declare class Queue {
52
- constructor();
53
- get length(): number;
54
- start(): Promise<void>;
55
- push(handle: Job['handle']): Promise<unknown>;
56
- }
57
-
58
47
  type MaybePromise<T> = T | Promise<T>;
59
48
  interface EventStore {
60
49
  persist(events: EventType[]): MaybePromise<void>;
@@ -74,10 +63,22 @@ type ApplyLazyProjectorEvents<Events extends Lazy<EventType>> = ApplyConcretePro
74
63
  type MaybeLazy<T> = T | Lazy<T>;
75
64
  type ApplyProjectorEvents<Events extends MaybeLazy<EventType> = any> = Events extends Lazy<EventType> ? ApplyLazyProjectorEvents<Events> : Events extends EventType ? ApplyConcreteProjectorEvents<Events> : never;
76
65
  declare abstract class Projector<T extends ApplyProjectorEvents<any> = any> {
66
+ #private;
67
+ /**
68
+ * Name of the projector
69
+ */
77
70
  abstract name: string;
78
- abstract apply?: T;
71
+ /**
72
+ * Map from event name to projection to apply an individual event.
73
+ */
74
+ apply?: T;
75
+ /**
76
+ * Initialize the projector.
77
+ *
78
+ * Executed before loading all existing events to get the projection up to
79
+ * date.
80
+ */
79
81
  initializer?(): void | Promise<void>;
80
- q: Queue;
81
82
  init(es: EventSource): Promise<void>;
82
83
  applyEvent(event: EventType): Promise<void>;
83
84
  project(event: EventType): void | Promise<void>;
@@ -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> {
@@ -43,18 +44,6 @@ declare function abort<T>(message: string, attributes?: T): void;
43
44
 
44
45
  declare function objectToYaml<T extends Object>(object: T): string;
45
46
 
46
- interface Job {
47
- handle: () => void;
48
- resolve: (value: unknown) => unknown;
49
- reject: (value: unknown) => unknown;
50
- }
51
- declare class Queue {
52
- constructor();
53
- get length(): number;
54
- start(): Promise<void>;
55
- push(handle: Job['handle']): Promise<unknown>;
56
- }
57
-
58
47
  type MaybePromise<T> = T | Promise<T>;
59
48
  interface EventStore {
60
49
  persist(events: EventType[]): MaybePromise<void>;
@@ -74,10 +63,22 @@ type ApplyLazyProjectorEvents<Events extends Lazy<EventType>> = ApplyConcretePro
74
63
  type MaybeLazy<T> = T | Lazy<T>;
75
64
  type ApplyProjectorEvents<Events extends MaybeLazy<EventType> = any> = Events extends Lazy<EventType> ? ApplyLazyProjectorEvents<Events> : Events extends EventType ? ApplyConcreteProjectorEvents<Events> : never;
76
65
  declare abstract class Projector<T extends ApplyProjectorEvents<any> = any> {
66
+ #private;
67
+ /**
68
+ * Name of the projector
69
+ */
77
70
  abstract name: string;
78
- abstract apply?: T;
71
+ /**
72
+ * Map from event name to projection to apply an individual event.
73
+ */
74
+ apply?: T;
75
+ /**
76
+ * Initialize the projector.
77
+ *
78
+ * Executed before loading all existing events to get the projection up to
79
+ * date.
80
+ */
79
81
  initializer?(): void | Promise<void>;
80
- q: Queue;
81
82
  init(es: EventSource): Promise<void>;
82
83
  applyEvent(event: EventType): Promise<void>;
83
84
  project(event: EventType): void | Promise<void>;
@@ -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