2021-08-12 15:04:37 +02:00
|
|
|
import { IEventStore } from '../../lib/types/stores/event-store';
|
2021-11-12 13:15:51 +01:00
|
|
|
import { IEvent } from '../../lib/types/events';
|
2022-08-16 15:33:33 +02:00
|
|
|
import { AnyEventEmitter } from '../../lib/util/anyEventEmitter';
|
2017-06-28 10:20:22 +02:00
|
|
|
|
2022-08-16 15:33:33 +02:00
|
|
|
class FakeEventStore extends AnyEventEmitter implements IEventStore {
|
2021-04-27 20:47:11 +02:00
|
|
|
events: IEvent[];
|
2021-01-19 10:42:45 +01:00
|
|
|
|
|
|
|
constructor() {
|
2021-08-12 15:04:37 +02:00
|
|
|
super();
|
2021-01-19 10:42:45 +01:00
|
|
|
this.setMaxListeners(0);
|
|
|
|
this.events = [];
|
|
|
|
}
|
|
|
|
|
2021-04-27 20:47:11 +02:00
|
|
|
store(event: IEvent): Promise<void> {
|
2021-01-19 10:42:45 +01:00
|
|
|
this.events.push(event);
|
|
|
|
this.emit(event.type, event);
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2021-04-27 20:47:11 +02:00
|
|
|
batchStore(events: IEvent[]): Promise<void> {
|
2021-08-12 15:04:37 +02:00
|
|
|
events.forEach((event) => {
|
2021-03-12 11:08:10 +01:00
|
|
|
this.events.push(event);
|
|
|
|
this.emit(event.type, event);
|
|
|
|
});
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
async getEvents(): Promise<IEvent[]> {
|
|
|
|
return this.events;
|
|
|
|
}
|
|
|
|
|
|
|
|
async delete(key: number): Promise<void> {
|
|
|
|
this.events.splice(
|
|
|
|
this.events.findIndex((t) => t.id === key),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async deleteAll(): Promise<void> {
|
|
|
|
this.events = [];
|
|
|
|
}
|
|
|
|
|
2022-09-02 08:35:31 +02:00
|
|
|
async count(): Promise<number> {
|
|
|
|
return Promise.resolve(this.events.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
filteredCount(): Promise<number> {
|
|
|
|
throw new Error('Method not implemented');
|
|
|
|
}
|
|
|
|
|
2021-08-12 15:04:37 +02:00
|
|
|
destroy(): void {}
|
|
|
|
|
|
|
|
async exists(key: number): Promise<boolean> {
|
|
|
|
return this.events.some((e) => e.id === key);
|
|
|
|
}
|
|
|
|
|
|
|
|
async get(key: number): Promise<IEvent> {
|
|
|
|
return this.events.find((e) => e.id === key);
|
|
|
|
}
|
|
|
|
|
|
|
|
async getAll(): Promise<IEvent[]> {
|
|
|
|
return this.events;
|
|
|
|
}
|
|
|
|
|
2022-08-09 16:14:50 +02:00
|
|
|
async searchEvents(): Promise<IEvent[]> {
|
|
|
|
throw new Error('Method not implemented.');
|
2021-09-20 12:13:38 +02:00
|
|
|
}
|
2021-01-19 10:42:45 +01:00
|
|
|
}
|
|
|
|
|
2021-04-27 20:47:11 +02:00
|
|
|
module.exports = FakeEventStore;
|
|
|
|
export default FakeEventStore;
|