@mondart/nestjs-common-module 1.1.8 → 1.1.9

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,5 +1,6 @@
1
1
  export declare class EnvValidator {
2
- private readonly envSchema;
3
- constructor(envSchema: any);
2
+ private readonly envSchemaClass;
3
+ private readonly extendedClasses;
4
+ constructor(envSchemaClass: any, extendedClasses: any[]);
4
5
  validate(configuration: Record<string, unknown>): object;
5
6
  }
@@ -4,11 +4,19 @@ 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(envSchema) {
8
- this.envSchema = envSchema;
7
+ constructor(envSchemaClass, extendedClasses) {
8
+ this.envSchemaClass = envSchemaClass;
9
+ this.extendedClasses = extendedClasses;
9
10
  }
10
11
  validate(configuration) {
11
- const finalConfig = (0, class_transformer_1.plainToClass)(this.envSchema, configuration, {
12
+ let transformedConfig = {};
13
+ this.extendedClasses.forEach((schema) => {
14
+ transformedConfig = {
15
+ ...transformedConfig,
16
+ [schema.name]: (0, class_transformer_1.plainToClass)(schema, configuration),
17
+ };
18
+ });
19
+ const finalConfig = (0, class_transformer_1.plainToClass)(this.envSchemaClass, transformedConfig, {
12
20
  enableImplicitConversion: true,
13
21
  });
14
22
  const errors = (0, class_validator_1.validateSync)(finalConfig, { skipMissingProperties: false });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validationOptions = void 0;
4
4
  const common_1 = require("@nestjs/common");
5
- const message_formatter_helper_1 = require("../helper/message-formatter.helper");
5
+ const helpers_1 = require("../helpers");
6
6
  exports.validationOptions = {
7
7
  transform: true,
8
8
  whitelist: true,
@@ -17,7 +17,7 @@ function mapValidationErrors(errors) {
17
17
  return errors.reduce((result, error) => {
18
18
  const constraints = error.constraints
19
19
  ? Object.values(error.constraints)
20
- .map((message) => message_formatter_helper_1.MessageFormatter.replace(message, error.property))
20
+ .map((message) => helpers_1.MessageFormatter.replace(message, error.property))
21
21
  .join(', ')
22
22
  : null;
23
23
  result[error.property] =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mondart/nestjs-common-module",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "",
5
5
  "author": {
6
6
  "name": "Mondart"
@@ -1 +0,0 @@
1
- export declare function env(key: any, defaultValue?: any): any;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.env = env;
4
- function env(key, defaultValue = null) {
5
- return process?.env?.[key] ?? defaultValue;
6
- }
@@ -1,2 +0,0 @@
1
- export * from './get-env';
2
- export * from './multi-inheritance.util';
@@ -1 +0,0 @@
1
- export declare const multiInheritance: (baseClass: any, extendedClasses: any[]) => void;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.multiInheritance = void 0;
4
- const multiInheritance = (baseClass, extendedClasses) => {
5
- extendedClasses.forEach((extendedClass) => {
6
- Object.getOwnPropertyNames(extendedClass.prototype).forEach((name) => {
7
- Object.defineProperty(baseClass.prototype, name, Object.getOwnPropertyDescriptor(extendedClass.prototype, name) ||
8
- Object.create(null));
9
- });
10
- });
11
- };
12
- exports.multiInheritance = multiInheritance;
File without changes
File without changes