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 { None
} from
'./None.js'
7 import type { Storage
} from
'./Storage.js'
8 import { BaseError
} from
'../../exception/index.js'
9 import { StorageType
} from
'../../types/index.js'
11 // eslint-disable-next-line @typescript-eslint/no-extraneous-class
12 export class StorageFactory
{
13 private constructor () {
14 // This is intentional
17 public static getStorage (
19 connectionUri
: string,
21 ): Storage
| undefined {
22 let storageInstance
: Storage
24 case StorageType
.JSON_FILE
:
25 storageInstance
= new JsonFileStorage(connectionUri
, logPrefix
)
27 case StorageType
.MONGO_DB
:
28 storageInstance
= new MongoDBStorage(connectionUri
, logPrefix
)
30 case StorageType
.SQLITE
:
31 case StorageType
.MARIA_DB
:
32 case StorageType
.MYSQL
:
33 storageInstance
= new MikroOrmStorage(connectionUri
, logPrefix
, type)
35 case StorageType
.NONE
:
36 storageInstance
= new None()
39 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
40 throw new BaseError(`${logPrefix} Unknown storage type: ${type}`)
42 return storageInstance