nestjs-config-extended 1.0.2 → 1.2.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.
- package/.releaserc +31 -0
- package/README.md +8 -2
- package/dist/extended-config.service.d.ts +1 -0
- package/dist/extended-config.service.js +11 -0
- package/package.json +11 -9
package/.releaserc
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"plugins": [
|
|
3
|
+
[
|
|
4
|
+
"@semantic-release/commit-analyzer",
|
|
5
|
+
{
|
|
6
|
+
"preset": "angular",
|
|
7
|
+
"releaseRules": [
|
|
8
|
+
{
|
|
9
|
+
"type": "docs",
|
|
10
|
+
"scope": "README",
|
|
11
|
+
"release": "patch"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"type": "refactor",
|
|
15
|
+
"release": "patch"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"type": "build",
|
|
19
|
+
"release": "patch"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"parserOpts": {
|
|
23
|
+
"noteKeywords": [
|
|
24
|
+
"BREAKING CHANGE",
|
|
25
|
+
"BREAKING CHANGES"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
]
|
|
31
|
+
}
|
package/README.md
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
9
|
<div>
|
|
10
|
-
<img src="https://visitor-badge.glitch.me/badge?page_id=pedrosodre.nestjs-config-extended" alt="Visitor count" />
|
|
11
10
|
<img src="https://img.shields.io/github/package-json/v/pedrosodre/nestjs-config-extended" alt="Module Version" />
|
|
12
11
|
<img src="https://sonarcloud.io/api/project_badges/measure?project=nestjs-config-extended&metric=alert_status" alt="SonarCloud Alert Status">
|
|
13
12
|
<img src="https://sonarcloud.io/api/project_badges/measure?project=nestjs-config-extended&metric=security_rating" alt="SonarCloud Security Rating">
|
|
@@ -19,7 +18,7 @@
|
|
|
19
18
|
</div>
|
|
20
19
|
<br />
|
|
21
20
|
|
|
22
|
-
> :warning: **Attention:**
|
|
21
|
+
> :warning: **Attention:** For NestJS v7, this library will maintain `0.x` version in maintenance mode only. The `1.x` version supports NestJS v8 or later.
|
|
23
22
|
|
|
24
23
|
## Description
|
|
25
24
|
|
|
@@ -121,6 +120,11 @@ await this.extendedConfigService.load(true);
|
|
|
121
120
|
// get an environment variable
|
|
122
121
|
const dbUser = this.extendedConfigService.get<string>('DATABASE_USER');
|
|
123
122
|
|
|
123
|
+
// get a proxy of an object from environment variable
|
|
124
|
+
const appConfig = this.extendedConfigService.getProxyOf<
|
|
125
|
+
Record<string, unknown>
|
|
126
|
+
>('APP_CONFIG');
|
|
127
|
+
|
|
124
128
|
// verify if an environment variable exists
|
|
125
129
|
const hasPassword = this.extendedConfigService.has('DATABASE_USER');
|
|
126
130
|
|
|
@@ -131,6 +135,8 @@ await this.extendedConfigService.reload();
|
|
|
131
135
|
await this.extendedConfigService.reload('STRATEGY_IDENTIFIER');
|
|
132
136
|
```
|
|
133
137
|
|
|
138
|
+
> :warning: **Important:** `getProxyOf()` method only returns a proxy when returned value is an object, in any other cases, it will return the value directly. If you need a non-object value from the proxy, try encapsulate it with a transformer.
|
|
139
|
+
|
|
134
140
|
## Full example
|
|
135
141
|
|
|
136
142
|
The examples below uses all availables options to help you to understand the module, but some of them are conflicting.
|
|
@@ -15,6 +15,7 @@ export declare class ExtendedConfigService<K = Record<string, any>> {
|
|
|
15
15
|
private set isLoading(value);
|
|
16
16
|
load(ensureLoad?: boolean): Promise<void>;
|
|
17
17
|
get<T = any>(propertyPath: keyof K, defaultValue?: T): T | undefined;
|
|
18
|
+
getProxyOf<T = any>(propertyPath: keyof K, defaultValue?: T): T | undefined;
|
|
18
19
|
private getFromCache;
|
|
19
20
|
private getFromProcessEnv;
|
|
20
21
|
private hasOnCache;
|
|
@@ -108,6 +108,17 @@ let ExtendedConfigService = class ExtendedConfigService {
|
|
|
108
108
|
}
|
|
109
109
|
return defaultValue;
|
|
110
110
|
}
|
|
111
|
+
getProxyOf(propertyPath, defaultValue) {
|
|
112
|
+
const baseTarget = this.get(propertyPath, defaultValue);
|
|
113
|
+
if (baseTarget && typeof baseTarget === 'object')
|
|
114
|
+
return new Proxy(baseTarget, {
|
|
115
|
+
get: (_target, property) => {
|
|
116
|
+
const target = this.get(propertyPath, defaultValue) || {};
|
|
117
|
+
return target === null || target === void 0 ? void 0 : target[property];
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
return baseTarget;
|
|
121
|
+
}
|
|
111
122
|
getFromCache(propertyPath) {
|
|
112
123
|
return lodash_get_1.default(this.cache, propertyPath);
|
|
113
124
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nestjs-config-extended",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Extended Configuration Module for Nest to load environment variables package",
|
|
5
5
|
"author": "Pedro Sodré",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"test:watch": "jest --watch",
|
|
18
18
|
"test:coverage": "jest --runInBand --coverage",
|
|
19
19
|
"prerelease": "npm run build",
|
|
20
|
-
"release": "npm publish --access=public"
|
|
20
|
+
"release": "npm publish --access=public",
|
|
21
|
+
"semantic-release": "semantic-release"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
24
|
"dotenv": "8.2.0",
|
|
@@ -31,10 +32,10 @@
|
|
|
31
32
|
"uuid": "8.3.2"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@nestjs/common": "^9.
|
|
35
|
-
"@nestjs/core": "^9.
|
|
36
|
-
"@nestjs/platform-express": "^9.
|
|
37
|
-
"@nestjs/testing": "^9.
|
|
35
|
+
"@nestjs/common": "^9.4.3",
|
|
36
|
+
"@nestjs/core": "^9.4.3",
|
|
37
|
+
"@nestjs/platform-express": "^9.4.3",
|
|
38
|
+
"@nestjs/testing": "^9.4.3",
|
|
38
39
|
"@types/jest": "^26.0.20",
|
|
39
40
|
"@types/lodash.get": "4.4.6",
|
|
40
41
|
"@types/lodash.has": "4.5.6",
|
|
@@ -49,13 +50,14 @@
|
|
|
49
50
|
"prettier": "2.2.1",
|
|
50
51
|
"reflect-metadata": "0.1.13",
|
|
51
52
|
"rimraf": "3.0.2",
|
|
53
|
+
"semantic-release": "^19.0.3",
|
|
52
54
|
"ts-jest": "26.4.4",
|
|
53
55
|
"tslint": "^6.1.3",
|
|
54
56
|
"typescript": "4.1.3"
|
|
55
57
|
},
|
|
56
58
|
"peerDependencies": {
|
|
57
|
-
"@nestjs/common": "^8.0.0 || ^9.0.0",
|
|
58
|
-
"@nestjs/core": "^8.0.0 || ^9.0.0",
|
|
59
|
+
"@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
60
|
+
"@nestjs/core": "^8.0.0 || ^9.0.0 || ^10.0.0",
|
|
59
61
|
"reflect-metadata": "^0.1.12",
|
|
60
62
|
"rxjs": "^7.2.0"
|
|
61
63
|
},
|
|
@@ -84,4 +86,4 @@
|
|
|
84
86
|
"type": "git",
|
|
85
87
|
"url": "https://github.com/pedrosodre/nestjs-config-extended"
|
|
86
88
|
}
|
|
87
|
-
}
|
|
89
|
+
}
|