1 // Copyright Jerome Benoit. 2021-2024. All Rights Reserved.
3 import { JsonFileStorage
} from
'./JsonFileStorage.js'
4 import { MikroOrmStorage
} from
'./MikroOrmStorage.js'
5 import { MongoDBStorage
} from
'./MongoDBStorage.js'
6 import type { Storage
} from
'./Storage.js'
7 import { BaseError
} from
'../../exception/index.js'
8 import { StorageType
} from
'../../types/index.js'
10 // eslint-disable-next-line @typescript-eslint/no-extraneous-class
11 export class StorageFactory
{
12 private constructor () {
13 // This is intentional
16 public static getStorage (
18 connectionUri
: string,
20 ): Storage
| undefined {
21 let storageInstance
: Storage
23 case StorageType
.JSON_FILE
:
24 storageInstance
= new JsonFileStorage(connectionUri
, logPrefix
)
26 case StorageType
.MONGO_DB
:
27 storageInstance
= new MongoDBStorage(connectionUri
, logPrefix
)
29 case StorageType
.SQLITE
:
30 case StorageType
.MARIA_DB
:
31 case StorageType
.MYSQL
:
32 storageInstance
= new MikroOrmStorage(connectionUri
, logPrefix
, type)
35 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
36 throw new BaseError(`${logPrefix} Unknown storage type: ${type}`)
38 return storageInstance