nestjs-config-extended 1.0.1 → 1.2.0

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/README.md CHANGED
@@ -19,7 +19,7 @@
19
19
  </div>
20
20
  <br />
21
21
 
22
- > :warning: **Attention:** To support NestJS 8, this library will keep two stable versions. For NestJS 7, use `0.x` version.
22
+ > :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
23
 
24
24
  ## Description
25
25
 
@@ -121,6 +121,11 @@ await this.extendedConfigService.load(true);
121
121
  // get an environment variable
122
122
  const dbUser = this.extendedConfigService.get<string>('DATABASE_USER');
123
123
 
124
+ // get a proxy of an object from environment variable
125
+ const appConfig = this.extendedConfigService.getProxyOf<
126
+ Record<string, unknown>
127
+ >('APP_CONFIG');
128
+
124
129
  // verify if an environment variable exists
125
130
  const hasPassword = this.extendedConfigService.has('DATABASE_USER');
126
131
 
@@ -131,6 +136,8 @@ await this.extendedConfigService.reload();
131
136
  await this.extendedConfigService.reload('STRATEGY_IDENTIFIER');
132
137
  ```
133
138
 
139
+ > :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.
140
+
134
141
  ## Full example
135
142
 
136
143
  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.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "Extended Configuration Module for Nest to load environment variables package",
5
5
  "author": "Pedro Sodré",
6
6
  "license": "MIT",
@@ -17,11 +17,10 @@
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
- "@nestjs/common": "^8.0.4",
24
- "@nestjs/core": "^8.0.4",
25
24
  "dotenv": "8.2.0",
26
25
  "dotenv-expand": "5.1.0",
27
26
  "lodash.get": "4.4.2",
@@ -33,8 +32,10 @@
33
32
  "uuid": "8.3.2"
34
33
  },
35
34
  "devDependencies": {
36
- "@nestjs/platform-express": "^8.0.4",
37
- "@nestjs/testing": "^8.0.4",
35
+ "@nestjs/common": "^9.0.2",
36
+ "@nestjs/core": "^9.0.2",
37
+ "@nestjs/platform-express": "^9.0.2",
38
+ "@nestjs/testing": "^9.0.2",
38
39
  "@types/jest": "^26.0.20",
39
40
  "@types/lodash.get": "4.4.6",
40
41
  "@types/lodash.has": "4.5.6",
@@ -51,10 +52,12 @@
51
52
  "rimraf": "3.0.2",
52
53
  "ts-jest": "26.4.4",
53
54
  "tslint": "^6.1.3",
54
- "typescript": "4.1.3"
55
+ "typescript": "4.1.3",
56
+ "semantic-release": "^19.0.3"
55
57
  },
56
58
  "peerDependencies": {
57
- "@nestjs/common": "^8.0.4",
59
+ "@nestjs/common": "^8.0.0 || ^9.0.0",
60
+ "@nestjs/core": "^8.0.0 || ^9.0.0",
58
61
  "reflect-metadata": "^0.1.12",
59
62
  "rxjs": "^7.2.0"
60
63
  },