@barumetric/common 1.1.2 → 1.1.4

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,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;
@@ -1,2 +1,3 @@
1
1
  export * from './decorators';
2
2
  export * from './grpc.module';
3
+ export * from './abstract-grpc.client';
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./decorators"), exports);
18
18
  __exportStar(require("./grpc.module"), exports);
19
+ __exportStar(require("./abstract-grpc.client"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barumetric/common",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Core shared components for BaruMetric microservice ecosystem",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",