-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.ts
33 lines (26 loc) · 1000 Bytes
/
store.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Session from "~/shared/types/Session";
/**
* CRUD interface for database
*/
export abstract class DatabaseStore {
public abstract getSession(sessionID: string): Promise<Session>;
public abstract updateSession(sessionID: string, session: Session): Promise<void>;
public abstract deleteSession(sessionID: string): Promise<void>;
}
/**
* Default implementation of DatabaseStore
*
* @summary Implements database as a native JS object. Simulates asynchronous database requests by returning values as Promises.
*/
export default class DatabaseStoreImpl extends DatabaseStore {
private _activeRooms: Record<string, Session> = {};
async getSession(sessionID: string): Promise<Session> {
return Promise.resolve(this._activeRooms[sessionID]);
}
async updateSession(sessionID: string, session: Session): Promise<void> {
this._activeRooms[sessionID] = session;
}
async deleteSession(sessionID: string): Promise<void> {
delete this._activeRooms[sessionID];
}
}