@robinmalfait/event-source 0.0.13 → 0.0.15

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.
package/dist/index.d.cts CHANGED
@@ -44,6 +44,11 @@ declare function abort<T>(message: string, attributes?: T): void;
44
44
 
45
45
  declare function objectToYaml<T extends Object>(object: T): string;
46
46
 
47
+ interface JSON {
48
+ [x: string]: string | number | boolean | Date | JSON | JSONArray;
49
+ }
50
+ interface JSONArray extends Array<string | number | boolean | Date | JSON | JSONArray> {
51
+ }
47
52
  type MaybePromise<T> = T | Promise<T>;
48
53
  interface EventStore {
49
54
  persist(events: EventType[]): MaybePromise<void>;
@@ -53,6 +58,9 @@ interface EventStore {
53
58
  interface EventHandler {
54
59
  (event: EventType, es: EventSource): MaybePromise<unknown>;
55
60
  }
61
+ interface MetadataEnhancer {
62
+ (event: EventType): MaybePromise<JSON>;
63
+ }
56
64
  type ApplyConcreteProjectorEvents<Events extends EventType> = Events extends EventType<infer EventName, any> ? {
57
65
  [T in EventName]: (event: Extract<Events, {
58
66
  eventName: T;
@@ -91,9 +99,10 @@ declare class EventSource {
91
99
  private commandHandlers;
92
100
  private projectors;
93
101
  private eventHandlers;
102
+ private eventMetadataEnhancers;
94
103
  private constructor();
95
104
  static builder(store: EventStore): EventSourceBuilder;
96
- static new(store: EventStore, commandHandlers: Map<string, CommandHandler>, projectors: Projector[], eventHandlers: EventHandler[]): EventSource;
105
+ static new(store: EventStore, commandHandlers: Map<string, CommandHandler>, projectors: Projector[], eventHandlers: EventHandler[], eventMetadataEnhancers: MetadataEnhancer[]): EventSource;
97
106
  resetProjections(): Promise<void>;
98
107
  dispatch<T extends CommandType>(command: T): Promise<T>;
99
108
  loadEvents(): Promise<EventType<any, any, any>[]>;
@@ -106,11 +115,13 @@ declare class EventSourceBuilder {
106
115
  private commandHandlers;
107
116
  private projectors;
108
117
  private eventHandlers;
118
+ private eventMetadataEnhancers;
109
119
  constructor(store: EventStore);
110
120
  build(): EventSource;
111
121
  addCommandHandler(commandType: string, handler: CommandHandler): this;
112
122
  addProjector(projector: Projector): this;
113
123
  addEventHandler(eventHandler: EventHandler): this;
124
+ metadata(metadataEnhancer: MetadataEnhancer): this;
114
125
  }
115
126
 
116
127
  type EventMapper = Record<string, (event: EventType, es: EventSource) => void>;
@@ -123,4 +134,4 @@ declare function createTestEventStore(commandHandlers: Record<string, CommandHan
123
134
  then(expectation: EventType[] | Error): Promise<void>;
124
135
  };
125
136
 
126
- export { Aggregate, type ApplyEvents, Command, type CommandHandler, type CommandType, Event, type EventHandler, EventSource, type EventStore, type EventType, type PayloadOf, Projector, type TypeOf, abort, createEventMapper, createTestEventStore, objectToYaml };
137
+ export { Aggregate, type ApplyEvents, Command, type CommandHandler, type CommandType, Event, type EventHandler, EventSource, type EventStore, type EventType, type MetadataEnhancer, type PayloadOf, Projector, type TypeOf, abort, createEventMapper, createTestEventStore, objectToYaml };
package/dist/index.d.ts CHANGED
@@ -44,6 +44,11 @@ declare function abort<T>(message: string, attributes?: T): void;
44
44
 
45
45
  declare function objectToYaml<T extends Object>(object: T): string;
46
46
 
47
+ interface JSON {
48
+ [x: string]: string | number | boolean | Date | JSON | JSONArray;
49
+ }
50
+ interface JSONArray extends Array<string | number | boolean | Date | JSON | JSONArray> {
51
+ }
47
52
  type MaybePromise<T> = T | Promise<T>;
48
53
  interface EventStore {
49
54
  persist(events: EventType[]): MaybePromise<void>;
@@ -53,6 +58,9 @@ interface EventStore {
53
58
  interface EventHandler {
54
59
  (event: EventType, es: EventSource): MaybePromise<unknown>;
55
60
  }
61
+ interface MetadataEnhancer {
62
+ (event: EventType): MaybePromise<JSON>;
63
+ }
56
64
  type ApplyConcreteProjectorEvents<Events extends EventType> = Events extends EventType<infer EventName, any> ? {
57
65
  [T in EventName]: (event: Extract<Events, {
58
66
  eventName: T;
@@ -91,9 +99,10 @@ declare class EventSource {
91
99
  private commandHandlers;
92
100
  private projectors;
93
101
  private eventHandlers;
102
+ private eventMetadataEnhancers;
94
103
  private constructor();
95
104
  static builder(store: EventStore): EventSourceBuilder;
96
- static new(store: EventStore, commandHandlers: Map<string, CommandHandler>, projectors: Projector[], eventHandlers: EventHandler[]): EventSource;
105
+ static new(store: EventStore, commandHandlers: Map<string, CommandHandler>, projectors: Projector[], eventHandlers: EventHandler[], eventMetadataEnhancers: MetadataEnhancer[]): EventSource;
97
106
  resetProjections(): Promise<void>;
98
107
  dispatch<T extends CommandType>(command: T): Promise<T>;
99
108
  loadEvents(): Promise<EventType<any, any, any>[]>;
@@ -106,11 +115,13 @@ declare class EventSourceBuilder {
106
115
  private commandHandlers;
107
116
  private projectors;
108
117
  private eventHandlers;
118
+ private eventMetadataEnhancers;
109
119
  constructor(store: EventStore);
110
120
  build(): EventSource;
111
121
  addCommandHandler(commandType: string, handler: CommandHandler): this;
112
122
  addProjector(projector: Projector): this;
113
123
  addEventHandler(eventHandler: EventHandler): this;
124
+ metadata(metadataEnhancer: MetadataEnhancer): this;
114
125
  }
115
126
 
116
127
  type EventMapper = Record<string, (event: EventType, es: EventSource) => void>;
@@ -123,4 +134,4 @@ declare function createTestEventStore(commandHandlers: Record<string, CommandHan
123
134
  then(expectation: EventType[] | Error): Promise<void>;
124
135
  };
125
136
 
126
- export { Aggregate, type ApplyEvents, Command, type CommandHandler, type CommandType, Event, type EventHandler, EventSource, type EventStore, type EventType, type PayloadOf, Projector, type TypeOf, abort, createEventMapper, createTestEventStore, objectToYaml };
137
+ export { Aggregate, type ApplyEvents, Command, type CommandHandler, type CommandType, Event, type EventHandler, EventSource, type EventStore, type EventType, type MetadataEnhancer, type PayloadOf, Projector, type TypeOf, abort, createEventMapper, createTestEventStore, objectToYaml };