@naturalcycles/backend-lib 5.8.0 → 5.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,14 +3,11 @@ export interface BaseEnv {
|
|
|
3
3
|
name: string;
|
|
4
4
|
}
|
|
5
5
|
export interface EnvSharedServiceCfg<ENV> {
|
|
6
|
-
|
|
7
|
-
* Dir with ${envName}.env.ts files
|
|
8
|
-
*/
|
|
9
|
-
envMap: StringMap<ENV>;
|
|
6
|
+
environments: ENV[];
|
|
10
7
|
}
|
|
11
8
|
export declare class EnvSharedService<ENV extends BaseEnv> {
|
|
12
|
-
cfg: EnvSharedServiceCfg<ENV>;
|
|
13
9
|
constructor(cfg: EnvSharedServiceCfg<ENV>);
|
|
10
|
+
envMap: StringMap<ENV>;
|
|
14
11
|
private env?;
|
|
15
12
|
init(): void;
|
|
16
13
|
getEnv(): ENV;
|
|
@@ -5,7 +5,7 @@ const js_lib_1 = require("@naturalcycles/js-lib");
|
|
|
5
5
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
6
|
class EnvSharedService {
|
|
7
7
|
constructor(cfg) {
|
|
8
|
-
this.
|
|
8
|
+
this.envMap = (0, js_lib_1._by)(cfg.environments, e => e.name);
|
|
9
9
|
}
|
|
10
10
|
init() {
|
|
11
11
|
this.getEnv();
|
|
@@ -14,7 +14,7 @@ class EnvSharedService {
|
|
|
14
14
|
if (!this.env) {
|
|
15
15
|
const { APP_ENV } = process.env;
|
|
16
16
|
(0, js_lib_1._assert)(APP_ENV, 'APP_ENV should be defined!');
|
|
17
|
-
const env = this.
|
|
17
|
+
const env = this.envMap[APP_ENV];
|
|
18
18
|
(0, js_lib_1._assert)(env, `Environment ${APP_ENV} is not defined`);
|
|
19
19
|
this.env = env;
|
|
20
20
|
console.log(`APP_ENV=${(0, nodejs_lib_1.dimGrey)(APP_ENV)} loaded`);
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _assert, StringMap } from '@naturalcycles/js-lib'
|
|
1
|
+
import { _assert, _by, StringMap } from '@naturalcycles/js-lib'
|
|
2
2
|
import { dimGrey } from '@naturalcycles/nodejs-lib'
|
|
3
3
|
|
|
4
4
|
export interface BaseEnv {
|
|
@@ -6,14 +6,15 @@ export interface BaseEnv {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export interface EnvSharedServiceCfg<ENV> {
|
|
9
|
-
|
|
10
|
-
* Dir with ${envName}.env.ts files
|
|
11
|
-
*/
|
|
12
|
-
envMap: StringMap<ENV>
|
|
9
|
+
environments: ENV[]
|
|
13
10
|
}
|
|
14
11
|
|
|
15
12
|
export class EnvSharedService<ENV extends BaseEnv> {
|
|
16
|
-
constructor(
|
|
13
|
+
constructor(cfg: EnvSharedServiceCfg<ENV>) {
|
|
14
|
+
this.envMap = _by(cfg.environments, e => e.name)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
envMap: StringMap<ENV>
|
|
17
18
|
|
|
18
19
|
private env?: ENV
|
|
19
20
|
|
|
@@ -26,7 +27,7 @@ export class EnvSharedService<ENV extends BaseEnv> {
|
|
|
26
27
|
const { APP_ENV } = process.env
|
|
27
28
|
_assert(APP_ENV, 'APP_ENV should be defined!')
|
|
28
29
|
|
|
29
|
-
const env = this.
|
|
30
|
+
const env = this.envMap[APP_ENV]
|
|
30
31
|
_assert(env, `Environment ${APP_ENV} is not defined`)
|
|
31
32
|
|
|
32
33
|
this.env = env
|