File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " strontium" ,
3
- "version" : " 2.7.1 " ,
3
+ "version" : " 2.7.2 " ,
4
4
"description" : " Strontium is a TypeScript toolkit for High Performance API servers built for Production not Projects." ,
5
5
"main" : " lib/src/index.js" ,
6
6
"types" : " lib/src/index.d.ts" ,
Original file line number Diff line number Diff line change
1
+ import { Container } from "inversify"
2
+ import { Process } from "../../runtime"
3
+ import { ObjectValidator , ValidatedObject , isObject } from "../../validation"
4
+
5
+ export class Environment < O extends ObjectValidator > implements Process {
6
+ private validatedEnvironment ?: ValidatedObject < O >
7
+
8
+ constructor ( private validator : O ) { }
9
+
10
+ public getKey < K extends keyof ValidatedObject < O > > ( key : K ) : O [ K ] {
11
+ if ( this . validatedEnvironment !== undefined ) {
12
+ return this . validatedEnvironment [ key ]
13
+ } else {
14
+ throw new Error (
15
+ "An environment value was accessed before the Environment container completed initialization."
16
+ )
17
+ }
18
+ }
19
+
20
+ public isHealthy ( ) : boolean {
21
+ return this . validatedEnvironment !== undefined
22
+ }
23
+
24
+ public async startup ( container : Container ) : Promise < void > {
25
+ container . bind ( Environment ) . toConstantValue ( this )
26
+
27
+ this . validatedEnvironment = await isObject ( this . validator ) ( process . env )
28
+ }
29
+
30
+ public async shutdown ( container : Container ) : Promise < void > {
31
+ container . unbind ( Environment )
32
+
33
+ this . validatedEnvironment = undefined
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ export * from "./drivers/Environment"
Original file line number Diff line number Diff line change
1
+ export * from "./bootstrap"
1
2
export * from "./cryptography"
2
3
export * from "./datastore"
3
4
export * from "./errors"
You can’t perform that action at this time.
0 commit comments