@citec-spbu/common 1.1.6 → 1.1.8

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.
@@ -0,0 +1 @@
1
+ export * from "./validate-env";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./validate-env"), exports);
@@ -0,0 +1,2 @@
1
+ import { type ClassConstructor } from "class-transformer";
2
+ export declare function validateEnv<T extends object>(config: Record<string, unknown>, envVariablesClass: ClassConstructor<T>): T;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateEnv = validateEnv;
4
+ const class_transformer_1 = require("class-transformer");
5
+ const class_validator_1 = require("class-validator");
6
+ function validateEnv(config, envVariablesClass) {
7
+ const validatedConfig = (0, class_transformer_1.plainToInstance)(envVariablesClass, config, {
8
+ enableImplicitConversion: true
9
+ });
10
+ const errors = (0, class_validator_1.validateSync)(validatedConfig, { skipMissingProperties: false });
11
+ if (errors.length) {
12
+ const errorMessage = errors
13
+ .map(error => `\nError in ${error.property}:\n` +
14
+ Object.entries(error.constraints ?? {})
15
+ .map(([key, value]) => `+ ${key}: ${value}`)
16
+ .join("\n"))
17
+ .join("\n");
18
+ console.error(`\n${errors.toString()}`);
19
+ throw new Error(errorMessage);
20
+ }
21
+ return validatedConfig;
22
+ }
@@ -2,13 +2,52 @@ export declare const GRPC_CLIENTS: {
2
2
  readonly AUTH_PACKAGE: {
3
3
  readonly package: "auth.v1";
4
4
  readonly protoPath: string;
5
+ readonly loader: {
6
+ keepCase?: boolean;
7
+ alternateCommentMode?: boolean;
8
+ longs?: Function;
9
+ enums?: Function;
10
+ bytes?: Function;
11
+ defaults?: boolean;
12
+ arrays?: boolean;
13
+ objects?: boolean;
14
+ oneofs?: boolean;
15
+ json?: boolean;
16
+ includeDirs?: string[];
17
+ };
5
18
  };
6
19
  readonly ACCOUNT_PACKAGE: {
7
20
  readonly package: "account.v1";
8
21
  readonly protoPath: string;
22
+ readonly loader: {
23
+ keepCase?: boolean;
24
+ alternateCommentMode?: boolean;
25
+ longs?: Function;
26
+ enums?: Function;
27
+ bytes?: Function;
28
+ defaults?: boolean;
29
+ arrays?: boolean;
30
+ objects?: boolean;
31
+ oneofs?: boolean;
32
+ json?: boolean;
33
+ includeDirs?: string[];
34
+ };
9
35
  };
10
36
  readonly USERS_PACKAGE: {
11
37
  readonly package: "users.v1";
12
38
  readonly protoPath: string;
39
+ readonly loader: {
40
+ keepCase?: boolean;
41
+ alternateCommentMode?: boolean;
42
+ longs?: Function;
43
+ enums?: Function;
44
+ bytes?: Function;
45
+ defaults?: boolean;
46
+ arrays?: boolean;
47
+ objects?: boolean;
48
+ oneofs?: boolean;
49
+ json?: boolean;
50
+ includeDirs?: string[];
51
+ };
13
52
  };
14
53
  };
@@ -5,17 +5,27 @@ const contracts_1 = require("@citec-spbu/contracts");
5
5
  const account_1 = require("@citec-spbu/contracts/gen/ts/account");
6
6
  const auth_1 = require("@citec-spbu/contracts/gen/ts/auth");
7
7
  const users_1 = require("@citec-spbu/contracts/gen/ts/users");
8
+ const grpcLoader = {
9
+ keepCase: false,
10
+ longs: String,
11
+ enums: String,
12
+ defaults: true,
13
+ oneofs: true
14
+ };
8
15
  exports.GRPC_CLIENTS = {
9
16
  AUTH_PACKAGE: {
10
17
  package: auth_1.AUTH_V1_PACKAGE_NAME,
11
- protoPath: contracts_1.PROTO_PATHS.AUTH
18
+ protoPath: contracts_1.PROTO_PATHS.AUTH,
19
+ loader: grpcLoader
12
20
  },
13
21
  ACCOUNT_PACKAGE: {
14
22
  package: account_1.ACCOUNT_V1_PACKAGE_NAME,
15
- protoPath: contracts_1.PROTO_PATHS.ACCOUNT
23
+ protoPath: contracts_1.PROTO_PATHS.ACCOUNT,
24
+ loader: grpcLoader
16
25
  },
17
26
  USERS_PACKAGE: {
18
27
  package: users_1.USERS_V1_PACKAGE_NAME,
19
- protoPath: contracts_1.PROTO_PATHS.USERS
28
+ protoPath: contracts_1.PROTO_PATHS.USERS,
29
+ loader: grpcLoader
20
30
  }
21
31
  };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./enums";
2
2
  export * from "./grpc";
3
+ export * from "./env";
package/dist/index.js CHANGED
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./enums"), exports);
18
18
  __exportStar(require("./grpc"), exports);
19
+ __exportStar(require("./env"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citec-spbu/common",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Core shared components for microservices",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,6 +24,8 @@
24
24
  "@citec-spbu/contracts": "^1.0.9",
25
25
  "@nestjs/common": "^11.1.12",
26
26
  "@nestjs/microservices": "^11.1.12",
27
+ "class-transformer": "^0.5.1",
28
+ "class-validator": "^0.14.3",
27
29
  "rxjs": "^7.8.2"
28
30
  }
29
31
  }