-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathMyGlobal.ts
66 lines (57 loc) · 1.5 KB
/
MyGlobal.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { PrismaClient } from "@prisma/client";
import dotenv from "dotenv";
import dotenvExpand from "dotenv-expand";
import { Singleton } from "tstl";
import typia from "typia";
/**
* Global variables of the server.
*
* @author Samchon
*/
export class MyGlobal {
public static testing: boolean = false;
public static readonly prisma: PrismaClient = new PrismaClient();
public static get env(): IEnvironments {
return environments.get();
}
/**
* Current mode.
*
* - local: The server is on your local machine.
* - dev: The server is for the developer.
* - real: The server is for the real service.
*/
public static get mode(): "local" | "dev" | "real" {
return (modeWrapper.value ??= environments.get().MODE);
}
/**
* Set current mode.
*
* @param mode The new mode
*/
public static setMode(mode: typeof MyGlobal.mode): void {
typia.assert<typeof mode>(mode);
modeWrapper.value = mode;
}
}
interface IEnvironments {
MODE: "local" | "dev" | "real";
API_PORT: `${number}`;
SYSTEM_PASSWORD: string;
POSTGRES_HOST: string;
POSTGRES_PORT: `${number}`;
POSTGRES_DATABASE: string;
POSTGRES_SCHEMA: string;
POSTGRES_USERNAME: string;
POSTGRES_USERNAME_READONLY: string;
POSTGRES_PASSWORD: string;
}
interface IMode {
value?: "local" | "dev" | "real";
}
const modeWrapper: IMode = {};
const environments = new Singleton(() => {
const env = dotenv.config();
dotenvExpand.expand(env);
return typia.assert<IEnvironments>(process.env);
});