277e6420420135f98b87729f637b3f29bf127787
1 // Copyright Jerome Benoit. 2021-2024. All Rights Reserved.
3 import type { Storage
} from
'./Storage.js'
5 import { BaseError
} from
'../../exception/index.js'
6 import { StorageType
} from
'../../types/index.js'
7 import { JsonFileStorage
} from
'./JsonFileStorage.js'
8 import { MikroOrmStorage
} from
'./MikroOrmStorage.js'
9 import { MongoDBStorage
} from
'./MongoDBStorage.js'
10 import { None
} from
'./None.js'
12 // eslint-disable-next-line @typescript-eslint/no-extraneous-class
13 export class StorageFactory
{
14 private constructor () {
15 // This is intentional
18 public static getStorage (
20 connectionUri
: string,
22 ): Storage
| undefined {
23 let storageInstance
: Storage
25 case StorageType
.JSON_FILE
:
26 storageInstance
= new JsonFileStorage(connectionUri
, logPrefix
)
28 case StorageType
.MARIA_DB
:
29 case StorageType
.MYSQL
:
30 case StorageType
.SQLITE
:
31 storageInstance
= new MikroOrmStorage(connectionUri
, logPrefix
, type)
33 case StorageType
.MONGO_DB
:
34 storageInstance
= new MongoDBStorage(connectionUri
, logPrefix
)
36 case StorageType
.NONE
:
37 storageInstance
= new None()
40 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
41 throw new BaseError(`${logPrefix} Unknown storage type: ${type}`)
43 return storageInstance