-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(server): access env via repository (#12987)
- Loading branch information
Showing
6 changed files
with
82 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { VectorExtension } from 'src/interfaces/database.interface'; | ||
|
||
export const IConfigRepository = 'IConfigRepository'; | ||
|
||
export interface EnvData { | ||
database: { | ||
skipMigrations: boolean; | ||
vectorExtension: VectorExtension; | ||
}; | ||
} | ||
|
||
export interface IConfigRepository { | ||
getEnv(): EnvData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { getVectorExtension } from 'src/database.config'; | ||
import { EnvData, IConfigRepository } from 'src/interfaces/config.interface'; | ||
|
||
@Injectable() | ||
export class ConfigRepository implements IConfigRepository { | ||
getEnv(): EnvData { | ||
return { | ||
database: { | ||
skipMigrations: process.env.DB_SKIP_MIGRATIONS === 'true', | ||
vectorExtension: getVectorExtension(), | ||
}, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { IConfigRepository } from 'src/interfaces/config.interface'; | ||
import { DatabaseExtension } from 'src/interfaces/database.interface'; | ||
import { Mocked, vitest } from 'vitest'; | ||
|
||
export const newConfigRepositoryMock = (): Mocked<IConfigRepository> => { | ||
return { | ||
getEnv: vitest.fn().mockReturnValue({ | ||
database: { | ||
skipMigration: false, | ||
vectorExtension: DatabaseExtension.VECTORS, | ||
}, | ||
}), | ||
}; | ||
}; |