-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add basic support for last-event-id in Events API
- Loading branch information
Showing
7 changed files
with
166 additions
and
19 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
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
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
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
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,59 @@ | ||
import { TDLifeCycleEvent } from './../common/models/events'; | ||
import { ConfigService } from '../config/config.service'; | ||
import { | ||
DeleteArgs, | ||
ExistArgs, | ||
FindArgs, | ||
FindFirstArgs, | ||
FindOneArgs, | ||
Repository, | ||
UpdateArgs, | ||
} from './repository.interface'; | ||
|
||
let ids = 0; | ||
/** | ||
* In memory implementation of an Event Repository. | ||
* TODO: we should store events in a database like Redis. | ||
*/ | ||
export class TDLifeCycleEventRepository implements Repository<TDLifeCycleEvent> { | ||
private events: TDLifeCycleEvent[]; | ||
private maxEvents: number; | ||
|
||
//TODO: check injection of ConfigService | ||
public constructor(config: ConfigService) { | ||
this.events = []; | ||
this.maxEvents = config?.maxEvents || 100; | ||
} | ||
|
||
public async create(item: Omit<TDLifeCycleEvent, 'id'>): Promise<TDLifeCycleEvent> { | ||
if (this.events.length >= this.maxEvents) { | ||
this.events.shift(); | ||
} | ||
const event = { ...item, id: ids++ }; | ||
this.events.push(event); | ||
return event; | ||
} | ||
public update(args: UpdateArgs<TDLifeCycleEvent>): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
public delete(args: DeleteArgs<TDLifeCycleEvent>): Promise<void> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
public find(args?: FindArgs<TDLifeCycleEvent> | undefined): Promise<TDLifeCycleEvent[]> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
public findOne(args: FindOneArgs<TDLifeCycleEvent>): Promise<TDLifeCycleEvent> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
public findFirst(args: FindFirstArgs<TDLifeCycleEvent>): Promise<TDLifeCycleEvent> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
public exist(args: ExistArgs<TDLifeCycleEvent>): Promise<boolean> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
|
||
public async findAfter(id: TDLifeCycleEvent['id']): Promise<TDLifeCycleEvent[]> { | ||
const index = this.events.findIndex((event) => event.id >= id); | ||
return this.events.slice(index + 1); | ||
} | ||
} |
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
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