@citec-spbu/common 1.1.5 → 1.1.7
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/dist/env/index.d.ts +1 -0
- package/dist/env/index.js +17 -0
- package/dist/env/validate-env.d.ts +2 -0
- package/dist/env/validate-env.js +22 -0
- package/dist/grpc/decorators/inject-grpc-client.decorator.d.ts +2 -1
- package/dist/grpc/grpc.abstract-client.d.ts +13 -0
- package/dist/grpc/grpc.abstract-client.js +27 -0
- package/dist/grpc/index.d.ts +1 -0
- package/dist/grpc/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +5 -2
|
@@ -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,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
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { GRPC_CLIENTS } from "../registry/grpc.registry";
|
|
2
|
+
export declare const InjectGrpcClient: (token: keyof typeof GRPC_CLIENTS) => PropertyDecorator & ParameterDecorator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { ClientGrpc } from "@nestjs/microservices";
|
|
3
|
+
import { type Observable } from "rxjs";
|
|
4
|
+
type UnwrapObservable<U> = U extends Observable<infer R> ? R : U;
|
|
5
|
+
export declare abstract class AbstractGrpcClient<T extends Record<string, any>> implements OnModuleInit {
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly serviceName;
|
|
8
|
+
protected service: T;
|
|
9
|
+
protected constructor(client: ClientGrpc, serviceName: string);
|
|
10
|
+
onModuleInit(): void;
|
|
11
|
+
call<K extends keyof T>(method: K, payload: Parameters<T[K]>[0]): Promise<UnwrapObservable<ReturnType<T[K]>>>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AbstractGrpcClient = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
class AbstractGrpcClient {
|
|
6
|
+
client;
|
|
7
|
+
serviceName;
|
|
8
|
+
service;
|
|
9
|
+
constructor(client, serviceName) {
|
|
10
|
+
this.client = client;
|
|
11
|
+
this.serviceName = serviceName;
|
|
12
|
+
}
|
|
13
|
+
onModuleInit() {
|
|
14
|
+
this.service = this.client.getService(this.serviceName);
|
|
15
|
+
}
|
|
16
|
+
async call(method, payload) {
|
|
17
|
+
try {
|
|
18
|
+
const observable = this.service[method](payload);
|
|
19
|
+
const result = await (0, rxjs_1.lastValueFrom)(observable);
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.AbstractGrpcClient = AbstractGrpcClient;
|
package/dist/grpc/index.d.ts
CHANGED
package/dist/grpc/index.js
CHANGED
|
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./grpc.module"), exports);
|
|
18
18
|
__exportStar(require("./decorators"), exports);
|
|
19
19
|
__exportStar(require("./interfaces"), exports);
|
|
20
|
+
__exportStar(require("./grpc.abstract-client"), exports);
|
package/dist/index.d.ts
CHANGED
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.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "Core shared components for microservices",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@citec-spbu/contracts": "^1.0.9",
|
|
25
25
|
"@nestjs/common": "^11.1.12",
|
|
26
|
-
"@nestjs/microservices": "^11.1.12"
|
|
26
|
+
"@nestjs/microservices": "^11.1.12",
|
|
27
|
+
"class-transformer": "^0.5.1",
|
|
28
|
+
"class-validator": "^0.14.3",
|
|
29
|
+
"rxjs": "^7.8.2"
|
|
27
30
|
}
|
|
28
31
|
}
|