-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement env variables in graph-client
- Loading branch information
1 parent
0bc5eeb
commit f9fae16
Showing
3 changed files
with
32 additions
and
1 deletion.
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,2 @@ | ||
# Depth necessary on a block to call it "confirmed", omit to use default value: 6 | ||
CONFIRMED_CONFIRMATION_DEPTH= |
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,27 @@ | ||
export interface IEnvInterface { | ||
CONFIRMED_CONFIRMATION_DEPTH?: number; | ||
} | ||
|
||
type RequiredEnv = Required<IEnvInterface>; | ||
|
||
export const dotenv: IEnvInterface = { | ||
CONFIRMED_CONFIRMATION_DEPTH: Number( | ||
process.env.CONFIRMED_CONFIRMATION_DEPTH, | ||
), | ||
}; | ||
|
||
export const env = <T extends keyof RequiredEnv, TDefault>( | ||
key: T, | ||
defaultValue: TDefault, | ||
): TDefault | NonNullable<RequiredEnv[T]> => { | ||
console.log(dotenv[key]); | ||
const falsyKey = | ||
(typeof dotenv[key] === 'number' && isNaN(Number(dotenv[key]))) || | ||
dotenv[key] === null || | ||
dotenv[key] === undefined; | ||
// TODO: uncomment this line when there's env vars that are strings | ||
//dotenv[key] === ''; | ||
return falsyKey | ||
? (defaultValue as TDefault) | ||
: (dotenv[key] as NonNullable<RequiredEnv[T]>); | ||
}; |