-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrequireRepository.ts
More file actions
22 lines (20 loc) · 738 Bytes
/
requireRepository.ts
File metadata and controls
22 lines (20 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { RepositoryIsNotDefinedException } from "../exception";
/**
* Ensures that a repository is defined.
*
* @param {T | null | undefined} repository The repository object to check.
* @param {string} [message="Repository is not defined."] The error message to throw if the repository is not defined.
* @returns {T} The repository object.
* @throws {RepositoryIsNotDefinedException} If the repository is null or undefined.
* @since 1.5.0
* @template T
*/
export function requireRepository<T>(
repository: T | null | undefined,
message: string = "Repository is not defined."
): T {
if (repository === null || repository === undefined) {
throw new RepositoryIsNotDefinedException(message);
}
return repository;
}