| 1 | import { JSONFileStorage } from './JSONFileStorage'; |
| 2 | import { MongoDBStorage } from './MongoDBStorage'; |
| 3 | import { Storage } from './Storage'; |
| 4 | import { StorageType } from '../../types/Storage'; |
| 5 | |
| 6 | export class StorageFactory { |
| 7 | // eslint-disable-next-line @typescript-eslint/no-empty-function |
| 8 | private constructor() { |
| 9 | // This is intentional |
| 10 | } |
| 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: |
| 22 | throw new Error(`${logPrefix} Unknown storage type: ${type}`); |
| 23 | } |
| 24 | return storageInstance; |
| 25 | } |
| 26 | } |