nestjs-config-extended 0.3.3 → 1.0.2

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.
Files changed (2) hide show
  1. package/README.md +102 -104
  2. package/package.json +9 -8
package/README.md CHANGED
@@ -17,12 +17,16 @@
17
17
  <img src="https://img.shields.io/github/issues-raw/pedrosodre/nestjs-config-extended" alt="Issues" />
18
18
  <img src="https://img.shields.io/github/last-commit/pedrosodre/nestjs-config-extended" alt="GitHub Last Commit" />
19
19
  </div>
20
+ <br />
21
+
22
+ > :warning: **Attention:** To support NestJS v8 and v9, this library will keep two stable versions. For NestJS v7, use `0.x` version.
20
23
 
21
24
  ## Description
22
25
 
23
26
  Extended Configuration Module for [Nest](https://github.com/nestjs/nest) based on the [Nest's Configuration Module](https://docs.nestjs.com/techniques/configuration) to load environment variables.
24
27
 
25
28
  ## Installation
29
+
26
30
  To begin using it, we first install the module itself.
27
31
 
28
32
  ```bash
@@ -38,7 +42,7 @@ import { Module } from '@nestjs/common';
38
42
  import { ExtendedConfigModule } from 'nestjs-config-extended';
39
43
 
40
44
  @Module({
41
- imports: [ExtendedConfigModule],
45
+ imports: [ExtendedConfigModule],
42
46
  })
43
47
  export class AppModule {}
44
48
  ```
@@ -50,11 +54,11 @@ import { Module } from '@nestjs/common';
50
54
  import { ExtendedConfigModule } from 'nestjs-config-extended';
51
55
 
52
56
  @Module({
53
- imports: [
54
- ExtendedConfigModule.forRoot({
55
- cache: false,
56
- }),
57
- ],
57
+ imports: [
58
+ ExtendedConfigModule.forRoot({
59
+ cache: false,
60
+ }),
61
+ ],
58
62
  })
59
63
  export class AppModule {}
60
64
  ```
@@ -65,30 +69,30 @@ If needed, you can also initialize `ExtendedConfigModule` using `.forRootAsync()
65
69
 
66
70
  To customize module's configuration, you can setup few options by importing it using one of `.forRoot()` or `.forRootAsync()` method.
67
71
 
68
- | Option | Default value | Required | Type | Description |
69
- | --- | --- | --- | --- | --- |
70
- | `strategies` | `[]` | `false` | `ConfigLoaderStrategy[]` | Array with all strategies used to load configuration variables. |
71
- | `cache` | `true` | `false` | `boolean` | If `false`, values will be stored directly in process.env object. <br> If `true`, values will be stored only in the memory. |
72
- | `debug` | `false` | `false` | `boolean` | If `true`, module will log some internal process information. |
73
- | `isGlobal` | `false` | `false` | `boolean` | If `true`, registers `ExtendedConfigModule` as a global module. |
74
- | `preload` | `false` | `false` | `boolean` | If `true`, variables load will be done by the module and injected on service. This option is required if you need to inject the service on a custom provider and retrieve a variable before application is totally ready. |
72
+ | Option | Default value | Required | Type | Description |
73
+ | ------------ | ------------- | -------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
74
+ | `strategies` | `[]` | `false` | `ConfigLoaderStrategy[]` | Array with all strategies used to load configuration variables. |
75
+ | `cache` | `true` | `false` | `boolean` | If `false`, values will be stored directly in process.env object. <br> If `true`, values will be stored only in the memory. |
76
+ | `debug` | `false` | `false` | `boolean` | If `true`, module will log some internal process information. |
77
+ | `isGlobal` | `false` | `false` | `boolean` | If `true`, registers `ExtendedConfigModule` as a global module. |
78
+ | `preload` | `false` | `false` | `boolean` | If `true`, variables load will be done by the module and injected on service. This option is required if you need to inject the service on a custom provider and retrieve a variable before application is totally ready. |
75
79
 
76
80
  ### Strategies
77
81
 
78
82
  To keep everything as flexible as possible, `ExtendedConfigModule` works with an array of strategies, that are specialized objects in load environment variables. Each strategy has its own options, as described below:
79
83
 
80
- | Option | Default value | Required | Type | Description |
81
- | --- | --- | --- | --- | --- |
82
- | `loader` | - | `true` | `LoaderClass | LoaderMethod` | Class or function responsible for loading environment variables for this strategy. Accepts a custom function or class with load() method. |
83
- | `identifier` | - | `false` | `string | Symbol` | Identify a strategy to allow module to manipulate it directly on helper functions. |
84
- | `disable` | `false` | `false` | `boolean` | If `true`, this strategy will not used. This flag is useful to perform conditional strategy disabling. |
85
- | `options` | - | `false` | `Record<string, any>` | Set options to loader class or function. |
86
- | `reloadable` | `false` | `false` | `boolean` | If `false`, this strategy will not be called again when service or scheduler requests a reload. |
87
- | `schedule` | - | `false` | `string` | Schedules the strategy reload (if reloadable) using cron syntax. This feature may not work correctly with serverless functions. |
88
- | `scheduleTimezone` | - | `false` | `Timezone` | Set scheduler timezone. |
89
- | `registerAs` | - | `false` | `string` | If set, all configuration will be set under the key passed on this variable. |
90
- | `transformer` | - | `false` | `TransformerClass | TransformerMethod` | If you wish to transform the loaded configuration variables, you can pass a function to handle it. Accepts a function or a class with transform() method. |
91
- | `validator` | - | `false` | `ValidatorClass | ValidatorMethod` | If you wish to transform the loaded configuration variables, you can pass a function to handle it. Accepts a function or a class with validate() method. |
84
+ | Option | Default value | Required | Type | Description |
85
+ | ------------------ | ------------- | -------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
86
+ | `loader` | - | `true` | `LoaderClass | LoaderMethod` | Class or function responsible for loading environment variables for this strategy. Accepts a custom function or class with load() method. |
87
+ | `identifier` | - | `false` | `string | Symbol` | Identify a strategy to allow module to manipulate it directly on helper functions. |
88
+ | `disable` | `false` | `false` | `boolean` | If `true`, this strategy will not used. This flag is useful to perform conditional strategy disabling. |
89
+ | `options` | - | `false` | `Record<string, any>` | Set options to loader class or function. |
90
+ | `reloadable` | `false` | `false` | `boolean` | If `false`, this strategy will not be called again when service or scheduler requests a reload. |
91
+ | `schedule` | - | `false` | `string` | Schedules the strategy reload (if reloadable) using cron syntax. This feature may not work correctly with serverless functions. |
92
+ | `scheduleTimezone` | - | `false` | `Timezone` | Set scheduler timezone. |
93
+ | `registerAs` | - | `false` | `string` | If set, all configuration will be set under the key passed on this variable. |
94
+ | `transformer` | - | `false` | `TransformerClass | TransformerMethod` | If you wish to transform the loaded configuration variables, you can pass a function to handle it. Accepts a function or a class with transform() method. |
95
+ | `validator` | - | `false` | `ValidatorClass | ValidatorMethod` | If you wish to transform the loaded configuration variables, you can pass a function to handle it. Accepts a function or a class with validate() method. |
92
96
 
93
97
  #### Pre-made loaders
94
98
 
@@ -135,47 +139,44 @@ The examples below uses all availables options to help you to understand the mod
135
139
 
136
140
  ```typescript
137
141
  import { Module } from '@nestjs/common';
138
- import {
139
- ExtendedConfigModule,
140
- dotEnvLoader,
141
- } from 'nestjs-config-extended';
142
+ import { ExtendedConfigModule, dotEnvLoader } from 'nestjs-config-extended';
142
143
 
143
144
  @Module({
144
- imports: [
145
- ExtendedConfigModule.forRoot({
146
- cache: true,
147
- debug: false,
148
- isGlobal: true,
149
- preload: true,
150
- strategies: [
151
- {
152
- identifier: 'DOT_ENV_STRATEGY',
153
- loader: dotEnvLoader,
154
- disable: false,
155
- options: {
156
- path: '.env',
157
- encoding: 'UTF-8',
158
- expandVariables: true,
159
- },
160
- reloadable: false,
161
- schedule: '* * * * *', // Every minute, but will not schedule since strategy is not reloadable
162
- scheduleTimezone: 'America/Sao_Paulo',
163
- registerAs: 'anyKey',
164
- transformer: (variables: Record<string, any>) => {
165
- variables.number = Number(variables.number);
166
- return variables;
167
- },
168
- validator: (variables: Record<string, any>) => {
169
- if (variables.number > 0) {
170
- return true;
171
- }
172
-
173
- return false;
174
- },
175
- },
176
- ],
177
- }),
178
- ],
145
+ imports: [
146
+ ExtendedConfigModule.forRoot({
147
+ cache: true,
148
+ debug: false,
149
+ isGlobal: true,
150
+ preload: true,
151
+ strategies: [
152
+ {
153
+ identifier: 'DOT_ENV_STRATEGY',
154
+ loader: dotEnvLoader,
155
+ disable: false,
156
+ options: {
157
+ path: '.env',
158
+ encoding: 'UTF-8',
159
+ expandVariables: true,
160
+ },
161
+ reloadable: false,
162
+ schedule: '* * * * *', // Every minute, but will not schedule since strategy is not reloadable
163
+ scheduleTimezone: 'America/Sao_Paulo',
164
+ registerAs: 'anyKey',
165
+ transformer: (variables: Record<string, any>) => {
166
+ variables.number = Number(variables.number);
167
+ return variables;
168
+ },
169
+ validator: (variables: Record<string, any>) => {
170
+ if (variables.number > 0) {
171
+ return true;
172
+ }
173
+
174
+ return false;
175
+ },
176
+ },
177
+ ],
178
+ }),
179
+ ],
179
180
  })
180
181
  export class AppModule {}
181
182
  ```
@@ -184,48 +185,45 @@ export class AppModule {}
184
185
 
185
186
  ```typescript
186
187
  import { Module } from '@nestjs/common';
187
- import {
188
- ExtendedConfigModule,
189
- dotEnvLoader,
190
- } from 'nestjs-config-extended';
188
+ import { ExtendedConfigModule, dotEnvLoader } from 'nestjs-config-extended';
191
189
 
192
190
  @Module({
193
- imports: [
194
- ExtendedConfigModule.forRootAsync({
195
- isGlobal: true,
196
- imports: [SampleStrategyModule],
191
+ imports: [
192
+ ExtendedConfigModule.forRootAsync({
193
+ isGlobal: true,
194
+ imports: [SampleStrategyModule],
197
195
  inject: [SampleStrategyService],
198
- useFactory: async (loaderClass: SampleStrategyService) => {
199
- return {
200
- cache: true,
201
- debug: false,
202
- strategies: [
203
- {
204
- identifier: 'INJECTED_CLASS_STRATEGY',
205
- loader: loaderClass,
206
- disable: false,
207
- options: {},
208
- reloadable: true,
209
- schedule: '* * * * *', // Every minute
210
- scheduleTimezone: 'America/Sao_Paulo',
211
- registerAs: 'anyKey',
212
- transformer: (variables: Record<string, any>) => {
213
- variables.number = Number(variables.number);
214
- return variables;
215
- },
216
- validator: (variables: Record<string, any>) => {
217
- if (variables.number > 0) {
218
- return true;
219
- }
220
-
221
- return false;
222
- },
223
- },
224
- ],
225
- };
226
- },
227
- }),
228
- ],
196
+ useFactory: async (loaderClass: SampleStrategyService) => {
197
+ return {
198
+ cache: true,
199
+ debug: false,
200
+ strategies: [
201
+ {
202
+ identifier: 'INJECTED_CLASS_STRATEGY',
203
+ loader: loaderClass,
204
+ disable: false,
205
+ options: {},
206
+ reloadable: true,
207
+ schedule: '* * * * *', // Every minute
208
+ scheduleTimezone: 'America/Sao_Paulo',
209
+ registerAs: 'anyKey',
210
+ transformer: (variables: Record<string, any>) => {
211
+ variables.number = Number(variables.number);
212
+ return variables;
213
+ },
214
+ validator: (variables: Record<string, any>) => {
215
+ if (variables.number > 0) {
216
+ return true;
217
+ }
218
+
219
+ return false;
220
+ },
221
+ },
222
+ ],
223
+ };
224
+ },
225
+ }),
226
+ ],
229
227
  })
230
228
  export class AppModule {}
231
229
  ```
@@ -238,4 +236,4 @@ export class AppModule {}
238
236
 
239
237
  This module is [MIT licensed](LICENSE).
240
238
 
241
- Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
239
+ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-config-extended",
3
- "version": "0.3.3",
3
+ "version": "1.0.2",
4
4
  "description": "Extended Configuration Module for Nest to load environment variables package",
5
5
  "author": "Pedro Sodré",
6
6
  "license": "MIT",
@@ -27,13 +27,14 @@
27
27
  "lodash.isfunction": "^3.0.9",
28
28
  "lodash.set": "4.3.2",
29
29
  "node-cron": "^2.0.3",
30
+ "rxjs": "^7.2.0",
30
31
  "uuid": "8.3.2"
31
32
  },
32
33
  "devDependencies": {
33
- "@nestjs/common": "^7.6.5",
34
- "@nestjs/core": "^7.6.5",
35
- "@nestjs/platform-express": "^7.6.5",
36
- "@nestjs/testing": "^7.6.5",
34
+ "@nestjs/common": "^9.0.2",
35
+ "@nestjs/core": "^9.0.2",
36
+ "@nestjs/platform-express": "^9.0.2",
37
+ "@nestjs/testing": "^9.0.2",
37
38
  "@types/jest": "^26.0.20",
38
39
  "@types/lodash.get": "4.4.6",
39
40
  "@types/lodash.has": "4.5.6",
@@ -48,15 +49,15 @@
48
49
  "prettier": "2.2.1",
49
50
  "reflect-metadata": "0.1.13",
50
51
  "rimraf": "3.0.2",
51
- "rxjs": "6.6.3",
52
52
  "ts-jest": "26.4.4",
53
53
  "tslint": "^6.1.3",
54
54
  "typescript": "4.1.3"
55
55
  },
56
56
  "peerDependencies": {
57
- "@nestjs/common": "^6.10.0 || ^7.0.0",
57
+ "@nestjs/common": "^8.0.0 || ^9.0.0",
58
+ "@nestjs/core": "^8.0.0 || ^9.0.0",
58
59
  "reflect-metadata": "^0.1.12",
59
- "rxjs": "^6.0.0"
60
+ "rxjs": "^7.2.0"
60
61
  },
61
62
  "husky": {
62
63
  "hooks": {