Commit | Line | Data |
---|---|---|
72f041bd JB |
1 | import { JSONFileStorage } from './JSONFileStorage'; |
2 | import { MongoDBStorage } from './MongoDBStorage'; | |
3 | import { Storage } from './Storage'; | |
4 | import { StorageType } from '../../types/Storage'; | |
72f041bd JB |
5 | |
6 | export class StorageFactory { | |
7 | // eslint-disable-next-line @typescript-eslint/no-empty-function | |
6c3cfef8 JB |
8 | private constructor() { |
9 | // This is intentional | |
10 | } | |
72f041bd JB |
11 | |
12 | public static getStorage(type: StorageType, connectionURI: string, logPrefix: string): Storage { | |
13 | let storageInstance: Storage = null; | |
14 | switch (type) { | |
15 | case StorageType.JSON_FILE: | |
16 | storageInstance = new JSONFileStorage(connectionURI, logPrefix); | |
17 | break; | |
18 | case StorageType.MONGO_DB: | |
19 | storageInstance = new MongoDBStorage(connectionURI, logPrefix); | |
20 | break; | |
21 | default: | |
fb226c9b | 22 | throw new Error(`${logPrefix} Unknown storage type: ${type}`); |
72f041bd JB |
23 | } |
24 | return storageInstance; | |
25 | } | |
26 | } |