X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fperformance%2Fstorage%2FStorageFactory.ts;h=9da6b54e98fa1d181b9a8c982e0b9d365535fa9f;hb=17ba3be0bb5c0bcb7fff2cefa877af975c0d043a;hp=619e7f5c4a05bb33b2d32c0e32779b352e8c336b;hpb=1f5df42ad17d09d3a1f53f6618eba325a403d7ad;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/storage/StorageFactory.ts b/src/performance/storage/StorageFactory.ts index 619e7f5c..9da6b54e 100644 --- a/src/performance/storage/StorageFactory.ts +++ b/src/performance/storage/StorageFactory.ts @@ -1,33 +1,44 @@ -// Copyright Jerome Benoit. 2021. All Rights Reserved. +// Copyright Jerome Benoit. 2021-2024. All Rights Reserved. -import { JSONFileStorage } from './JSONFileStorage'; -import { MikroORMStorage } from './MikroORMStorage'; -import { MongoDBStorage } from './MongoDBStorage'; -import { Storage } from './Storage'; -import { StorageType } from '../../types/Storage'; +import { JsonFileStorage } from './JsonFileStorage.js' +import { MikroOrmStorage } from './MikroOrmStorage.js' +import { MongoDBStorage } from './MongoDBStorage.js' +import { None } from './None.js' +import type { Storage } from './Storage.js' +import { BaseError } from '../../exception/index.js' +import { StorageType } from '../../types/index.js' +// eslint-disable-next-line @typescript-eslint/no-extraneous-class export class StorageFactory { - private constructor() { + private constructor () { // This is intentional } - public static getStorage(type: StorageType, connectionUri: string, logPrefix: string): Storage { - let storageInstance: Storage = null; + public static getStorage ( + type: StorageType, + connectionUri: string, + logPrefix: string + ): Storage | undefined { + let storageInstance: Storage switch (type) { case StorageType.JSON_FILE: - storageInstance = new JSONFileStorage(connectionUri, logPrefix); - break; + storageInstance = new JsonFileStorage(connectionUri, logPrefix) + break case StorageType.MONGO_DB: - storageInstance = new MongoDBStorage(connectionUri, logPrefix); - break; - // case StorageType.MYSQL: - // case StorageType.MARIA_DB: - // case StorageType.SQLITE: - // storageInstance = new MikroORMStorage(connectionURI, logPrefix, type); - // break; + storageInstance = new MongoDBStorage(connectionUri, logPrefix) + break + case StorageType.SQLITE: + case StorageType.MARIA_DB: + case StorageType.MYSQL: + storageInstance = new MikroOrmStorage(connectionUri, logPrefix, type) + break + case StorageType.NONE: + storageInstance = new None() + break default: - throw new Error(`${logPrefix} Unknown storage type: ${type}`); + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions + throw new BaseError(`${logPrefix} Unknown storage type: ${type}`) } - return storageInstance; + return storageInstance } }