@mondart/nestjs-common-module 1.1.9 → 1.1.11
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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export declare class EnvValidator {
|
|
2
|
-
private readonly envSchemaClass;
|
|
3
2
|
private readonly extendedClasses;
|
|
4
|
-
constructor(
|
|
5
|
-
validate(configuration: Record<string, unknown>):
|
|
3
|
+
constructor(extendedClasses: any[]);
|
|
4
|
+
validate(configuration: Record<string, unknown>): any;
|
|
6
5
|
}
|
|
@@ -4,26 +4,32 @@ exports.EnvValidator = void 0;
|
|
|
4
4
|
const class_transformer_1 = require("class-transformer");
|
|
5
5
|
const class_validator_1 = require("class-validator");
|
|
6
6
|
class EnvValidator {
|
|
7
|
-
constructor(
|
|
8
|
-
this.envSchemaClass = envSchemaClass;
|
|
7
|
+
constructor(extendedClasses) {
|
|
9
8
|
this.extendedClasses = extendedClasses;
|
|
10
9
|
}
|
|
11
10
|
validate(configuration) {
|
|
12
|
-
let
|
|
11
|
+
let errors = [];
|
|
12
|
+
let transformedConfiguration = {};
|
|
13
13
|
this.extendedClasses.forEach((schema) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
14
|
+
const finalConfig = (0, class_transformer_1.plainToClass)(schema, configuration, {
|
|
15
|
+
enableImplicitConversion: true,
|
|
16
|
+
});
|
|
17
|
+
const error = (0, class_validator_1.validateSync)(finalConfig, { skipMissingProperties: false });
|
|
18
|
+
if (error.length > 0)
|
|
19
|
+
errors.push(error);
|
|
20
|
+
else
|
|
21
|
+
transformedConfiguration = {
|
|
22
|
+
...transformedConfiguration,
|
|
23
|
+
...finalConfig,
|
|
24
|
+
};
|
|
18
25
|
});
|
|
19
|
-
const finalConfig = (0, class_transformer_1.plainToClass)(this.envSchemaClass, transformedConfig, {
|
|
20
|
-
enableImplicitConversion: true,
|
|
21
|
-
});
|
|
22
|
-
const errors = (0, class_validator_1.validateSync)(finalConfig, { skipMissingProperties: false });
|
|
23
26
|
if (errors.length > 0) {
|
|
24
27
|
throw new Error(errors.toString());
|
|
25
28
|
}
|
|
26
|
-
return
|
|
29
|
+
return {
|
|
30
|
+
...configuration,
|
|
31
|
+
...transformedConfiguration,
|
|
32
|
+
};
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
35
|
exports.EnvValidator = EnvValidator;
|