diff --git a/src/main.ts b/src/main.ts index 0a74d9a..89a8e6e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,6 +12,7 @@ import { AppModule } from './app.module'; import { setupSwagger } from './setup-swagger'; import { ApiConfigService } from './shared/services/api-config.service'; import { SharedModule } from './shared/shared.module'; +import { MANAGER_V1_PACKAGE_NAME } from './modules/grpc/gen/ts/config'; async function bootstrap() { const app = await NestFactory.create(AppModule, new ExpressAdapter(), { @@ -69,7 +70,7 @@ async function bootstrap() { onLoadPackageDefinition: (pkg, server) => { new ReflectionService(pkg).addToServer(server); }, - package: 'kraken', + package: MANAGER_V1_PACKAGE_NAME, protoPath: configService.grpcConfig.protoPath, url: `0.0.0.0:${configService.grpcConfig.port}`, }, diff --git a/src/modules/config/controllers/config-grpc.controller.ts b/src/modules/config/controllers/config-grpc.controller.ts index 2926c8a..c0f8104 100644 --- a/src/modules/config/controllers/config-grpc.controller.ts +++ b/src/modules/config/controllers/config-grpc.controller.ts @@ -1,18 +1,17 @@ import { Controller, UseInterceptors } from '@nestjs/common'; -import type { ConfigController, EmptyRequest, getConfigResponse } from '../../../../src/modules/grpc/gen/ts/kraken'; -import { ConfigControllerMethods } from '../../../../src/modules/grpc/gen/ts/kraken'; import { GrpcInvalidArgumentException, GrpcToHttpInterceptor } from 'nestjs-grpc-exceptions'; import { ConfigService } from '../config.service'; import { Metadata } from '@grpc/grpc-js'; +import { GetParametersRequest, GetParametersResponse, ParametersController, ParametersControllerMethods } from '../../../../src/modules/grpc/gen/ts/config'; @Controller() -@ConfigControllerMethods() +@ParametersControllerMethods() @UseInterceptors(GrpcToHttpInterceptor) -export class ConfigGrpcController implements ConfigController { +export class ConfigGrpcController implements ParametersController { constructor(private readonly configService: ConfigService) {} - async getConfig(_request: EmptyRequest, _metadata?: Metadata): Promise { + async getParameters(_request: GetParametersRequest, _metadata?: Metadata): Promise { const token = _metadata?.get('x-identifier')?.[0] as string | undefined; if (!token) { throw new GrpcInvalidArgumentException("input 'x-identifier' is not valid."); @@ -37,6 +36,6 @@ export class ConfigGrpcController implements ConfigController { defaultQueryLimit: limitations?.default_query_limit, maxQueryLimit: limitations?.max_limit, }, - } as getConfigResponse; + } as GetParametersResponse; } } diff --git a/src/modules/grpc/gen/ts/config.ts b/src/modules/grpc/gen/ts/config.ts new file mode 100644 index 0000000..59798a7 --- /dev/null +++ b/src/modules/grpc/gen/ts/config.ts @@ -0,0 +1,67 @@ +// Code generated by protoc-gen-ts_proto. DO NOT EDIT. +// versions: +// protoc-gen-ts_proto v2.2.7 +// protoc v3.12.4 +// source: config.proto + +/* eslint-disable */ +import { Metadata } from "@grpc/grpc-js"; +import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices"; +import { Observable } from "rxjs"; + +export const protobufPackage = "manager.v1"; + +export interface Limitations { + maxMessageLength: number; + maxSubscriptions: number; + maxFilters: number; + maxSubidLength: number; + minPowDifficulty: number; + authRequired: boolean; + paymentRequired: boolean; + restrictedWrites: boolean; + maxEventTags: number; + maxContentLength: number; + createdAtLowerLimit: number; + createdAtUpperLimit: number; + defaultQueryLimit: number; + maxQueryLimit: number; +} + +export interface GetParametersRequest { +} + +export interface GetParametersResponse { + limitations: Limitations | undefined; + url: string; +} + +export const MANAGER_V1_PACKAGE_NAME = "manager.v1"; + +export interface ParametersClient { + getParameters(request: GetParametersRequest, metadata?: Metadata): Observable; +} + +export interface ParametersController { + getParameters( + request: GetParametersRequest, + metadata?: Metadata, + ): Promise | Observable | GetParametersResponse; +} + +export function ParametersControllerMethods() { + return function (constructor: Function) { + const grpcMethods: string[] = ["getParameters"]; + for (const method of grpcMethods) { + const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); + GrpcMethod("Parameters", method)(constructor.prototype[method], method, descriptor); + } + const grpcStreamMethods: string[] = []; + for (const method of grpcStreamMethods) { + const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); + GrpcStreamMethod("Parameters", method)(constructor.prototype[method], method, descriptor); + } + }; +} + +export const PARAMETERS_SERVICE_NAME = "Parameters"; diff --git a/src/modules/grpc/gen/ts/kraken.ts b/src/modules/grpc/gen/ts/kraken.ts deleted file mode 100644 index 1ea728c..0000000 --- a/src/modules/grpc/gen/ts/kraken.ts +++ /dev/null @@ -1,219 +0,0 @@ -// Code generated by protoc-gen-ts_proto. DO NOT EDIT. -// versions: -// protoc-gen-ts_proto v2.2.7 -// protoc v3.12.4 -// source: kraken.proto - -/* eslint-disable */ -import { Metadata } from "@grpc/grpc-js"; -import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices"; -import { Observable } from "rxjs"; - -export const protobufPackage = "kraken"; - -/** Define the syntax version for Protocol Buffers */ - -/** Types of services that can be registered */ -export enum ServiceTypeEnum { - /** UNKNOWN - Unknown service type */ - UNKNOWN = 0, - /** RELAY - Relay service type */ - RELAY = 1, - UNRECOGNIZED = -1, -} - -/** Request to register a service */ -export interface registerServiceRequest { - /** Service grpc port */ - port: string; - /** Heartbeat interval in seconds */ - heartbeatDurationInSec: number; - /** Type of the service (e.g., RELAY) */ - type: ServiceTypeEnum; - /** Region of the service */ - region: string; -} - -/** Response after registering a service */ -export interface registerServiceResponse { - /** Indicates if registration was successful */ - success: boolean; - /** Optional message with additional information */ - message?: - | string - | undefined; - /** Token assigned to the registered service */ - token: string; -} - -/** Empty request used for methods that do not require parameters */ -export interface EmptyRequest { -} - -/** Request to add a log entry */ -export interface addLogRequest { - /** Log message content */ - message: string; - /** Stack trace or additional log details */ - stack: string; -} - -/** Response after adding a log entry */ -export interface addLogResponse { - /** Indicates if the log entry was successfully added */ - success: boolean; - /** Optional message with additional information */ - message?: string | undefined; -} - -/** Configuration limitations */ -export interface limitations { - /** Maximum allowed message length */ - maxMessageLength: number; - /** Maximum number of subscriptions allowed */ - maxSubscriptions: number; - /** Maximum number of filters allowed */ - maxFilters: number; - /** Maximum length of a subscription ID */ - maxSubidLength: number; - /** Minimum proof-of-work difficulty */ - minPowDifficulty: number; - /** Indicates if authentication is required */ - authRequired: boolean; - /** Indicates if payment is required */ - paymentRequired: boolean; - /** Indicates if writes are restricted */ - restrictedWrites: boolean; - /** Maximum number of event tags allowed */ - maxEventTags: number; - /** Maximum length of content allowed */ - maxContentLength: number; - /** Lower limit for creation timestamps */ - createdAtLowerLimit: number; - /** Upper limit for creation timestamps */ - createdAtUpperLimit: number; - /** Defualt of query limit */ - defaultQueryLimit: number; - /** Maximum of query limit */ - maxQueryLimit: number; -} - -/** Response containing configuration details */ -export interface getConfigResponse { - /** Configuration limitations */ - limitations: - | limitations - | undefined; - /** Service URL */ - url: string; -} - -export const KRAKEN_PACKAGE_NAME = "kraken"; - -/** ServiceRegistry handles service registration */ - -export interface ServiceRegistryClient { - /** Registers a service with the registry */ - - registerService(request: registerServiceRequest, metadata?: Metadata): Observable; -} - -/** ServiceRegistry handles service registration */ - -export interface ServiceRegistryController { - /** Registers a service with the registry */ - - registerService( - request: registerServiceRequest, - metadata?: Metadata, - ): Promise | Observable | registerServiceResponse; -} - -export function ServiceRegistryControllerMethods() { - return function (constructor: Function) { - const grpcMethods: string[] = ["registerService"]; - for (const method of grpcMethods) { - const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); - GrpcMethod("ServiceRegistry", method)(constructor.prototype[method], method, descriptor); - } - const grpcStreamMethods: string[] = []; - for (const method of grpcStreamMethods) { - const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); - GrpcStreamMethod("ServiceRegistry", method)(constructor.prototype[method], method, descriptor); - } - }; -} - -export const SERVICE_REGISTRY_SERVICE_NAME = "ServiceRegistry"; - -/** Config service provides configuration details */ - -export interface ConfigClient { - /** Retrieves the current configuration */ - - getConfig(request: EmptyRequest, metadata?: Metadata): Observable; -} - -/** Config service provides configuration details */ - -export interface ConfigController { - /** Retrieves the current configuration */ - - getConfig( - request: EmptyRequest, - metadata?: Metadata, - ): Promise | Observable | getConfigResponse; -} - -export function ConfigControllerMethods() { - return function (constructor: Function) { - const grpcMethods: string[] = ["getConfig"]; - for (const method of grpcMethods) { - const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); - GrpcMethod("Config", method)(constructor.prototype[method], method, descriptor); - } - const grpcStreamMethods: string[] = []; - for (const method of grpcStreamMethods) { - const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); - GrpcStreamMethod("Config", method)(constructor.prototype[method], method, descriptor); - } - }; -} - -export const CONFIG_SERVICE_NAME = "Config"; - -/** Log service handles logging operations */ - -export interface LogClient { - /** Adds a log entry */ - - addLog(request: addLogRequest, metadata?: Metadata): Observable; -} - -/** Log service handles logging operations */ - -export interface LogController { - /** Adds a log entry */ - - addLog( - request: addLogRequest, - metadata?: Metadata, - ): Promise | Observable | addLogResponse; -} - -export function LogControllerMethods() { - return function (constructor: Function) { - const grpcMethods: string[] = ["addLog"]; - for (const method of grpcMethods) { - const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); - GrpcMethod("Log", method)(constructor.prototype[method], method, descriptor); - } - const grpcStreamMethods: string[] = []; - for (const method of grpcStreamMethods) { - const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); - GrpcStreamMethod("Log", method)(constructor.prototype[method], method, descriptor); - } - }; -} - -export const LOG_SERVICE_NAME = "Log"; diff --git a/src/modules/grpc/gen/ts/log.ts b/src/modules/grpc/gen/ts/log.ts new file mode 100644 index 0000000..f82b969 --- /dev/null +++ b/src/modules/grpc/gen/ts/log.ts @@ -0,0 +1,52 @@ +// Code generated by protoc-gen-ts_proto. DO NOT EDIT. +// versions: +// protoc-gen-ts_proto v2.2.7 +// protoc v3.12.4 +// source: log.proto + +/* eslint-disable */ +import { Metadata } from "@grpc/grpc-js"; +import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices"; +import { Observable } from "rxjs"; + +export const protobufPackage = "manager.v1"; + +export interface AddLogRequest { + message: string; + stack: string; +} + +export interface AddLogResponse { + success: boolean; + message?: string | undefined; +} + +export const MANAGER_V1_PACKAGE_NAME = "manager.v1"; + +export interface LogClient { + addLog(request: AddLogRequest, metadata?: Metadata): Observable; +} + +export interface LogController { + addLog( + request: AddLogRequest, + metadata?: Metadata, + ): Promise | Observable | AddLogResponse; +} + +export function LogControllerMethods() { + return function (constructor: Function) { + const grpcMethods: string[] = ["addLog"]; + for (const method of grpcMethods) { + const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); + GrpcMethod("Log", method)(constructor.prototype[method], method, descriptor); + } + const grpcStreamMethods: string[] = []; + for (const method of grpcStreamMethods) { + const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); + GrpcStreamMethod("Log", method)(constructor.prototype[method], method, descriptor); + } + }; +} + +export const LOG_SERVICE_NAME = "Log"; diff --git a/src/modules/grpc/gen/ts/immortal-health-service.ts b/src/modules/grpc/gen/ts/relay-health.ts similarity index 92% rename from src/modules/grpc/gen/ts/immortal-health-service.ts rename to src/modules/grpc/gen/ts/relay-health.ts index b4e49e4..9b5c5da 100644 --- a/src/modules/grpc/gen/ts/immortal-health-service.ts +++ b/src/modules/grpc/gen/ts/relay-health.ts @@ -2,14 +2,14 @@ // versions: // protoc-gen-ts_proto v2.2.7 // protoc v3.12.4 -// source: immortal-health-service.proto +// source: relay-health.proto /* eslint-disable */ import { Metadata } from "@grpc/grpc-js"; import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices"; import { Observable } from "rxjs"; -export const protobufPackage = "immortal"; +export const protobufPackage = "relay.v1"; export enum Status { UNKNOWN = 0, @@ -33,7 +33,7 @@ export interface StatusResponse { version: string; } -export const IMMORTAL_PACKAGE_NAME = "immortal"; +export const RELAY_V1_PACKAGE_NAME = "relay.v1"; export interface HealthServiceClient { status(request: StatusRequest, metadata?: Metadata): Observable; diff --git a/src/modules/grpc/gen/ts/service_registry.ts b/src/modules/grpc/gen/ts/service_registry.ts new file mode 100644 index 0000000..569d32f --- /dev/null +++ b/src/modules/grpc/gen/ts/service_registry.ts @@ -0,0 +1,61 @@ +// Code generated by protoc-gen-ts_proto. DO NOT EDIT. +// versions: +// protoc-gen-ts_proto v2.2.7 +// protoc v3.12.4 +// source: service_registry.proto + +/* eslint-disable */ +import { Metadata } from "@grpc/grpc-js"; +import { GrpcMethod, GrpcStreamMethod } from "@nestjs/microservices"; +import { Observable } from "rxjs"; + +export const protobufPackage = "manager.v1"; + +export enum ServiceTypeEnum { + UNKNOWN = 0, + RELAY = 1, + UNRECOGNIZED = -1, +} + +export interface RegisterServiceRequest { + port: string; + heartbeatDurationInSec: number; + type: ServiceTypeEnum; + region: string; +} + +export interface RegisterServiceResponse { + success: boolean; + message?: string | undefined; + token: string; +} + +export const MANAGER_V1_PACKAGE_NAME = "manager.v1"; + +export interface ServiceRegistryClient { + registerService(request: RegisterServiceRequest, metadata?: Metadata): Observable; +} + +export interface ServiceRegistryController { + registerService( + request: RegisterServiceRequest, + metadata?: Metadata, + ): Promise | Observable | RegisterServiceResponse; +} + +export function ServiceRegistryControllerMethods() { + return function (constructor: Function) { + const grpcMethods: string[] = ["registerService"]; + for (const method of grpcMethods) { + const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); + GrpcMethod("ServiceRegistry", method)(constructor.prototype[method], method, descriptor); + } + const grpcStreamMethods: string[] = []; + for (const method of grpcStreamMethods) { + const descriptor: any = Reflect.getOwnPropertyDescriptor(constructor.prototype, method); + GrpcStreamMethod("ServiceRegistry", method)(constructor.prototype[method], method, descriptor); + } + }; +} + +export const SERVICE_REGISTRY_SERVICE_NAME = "ServiceRegistry"; diff --git a/src/modules/grpc/immortal-grpc.client.ts b/src/modules/grpc/immortal-grpc.client.ts index 140b0e5..3043aa0 100644 --- a/src/modules/grpc/immortal-grpc.client.ts +++ b/src/modules/grpc/immortal-grpc.client.ts @@ -2,9 +2,8 @@ import path from 'node:path'; import { ChannelCredentials } from '@grpc/grpc-js'; import { Injectable, OnModuleInit } from '@nestjs/common'; import { ClientGrpc, ClientOptions, ClientProxyFactory, Transport } from '@nestjs/microservices'; +import { HEALTH_SERVICE_NAME, HealthServiceClient, RELAY_V1_PACKAGE_NAME } from './gen/ts/relay-health'; -import type { HealthServiceClient } from './gen/ts/immortal-health-service'; -import { HEALTH_SERVICE_NAME, IMMORTAL_PACKAGE_NAME } from './gen/ts/immortal-health-service'; @Injectable() export class ImmortalGrpcClient implements OnModuleInit { @@ -35,8 +34,8 @@ export class ImmortalGrpcClient implements OnModuleInit { transport: Transport.GRPC, options: { url: this.url, - package: IMMORTAL_PACKAGE_NAME, - protoPath: path.join(__dirname, 'proto', 'immortal-health-service.proto'), + package: RELAY_V1_PACKAGE_NAME, + protoPath: path.join(__dirname, 'proto', 'relay-health.proto'), credentials: this.isSecure ? ChannelCredentials.createSsl() : ChannelCredentials.createInsecure(), }, }; diff --git a/src/modules/grpc/proto/config.proto b/src/modules/grpc/proto/config.proto new file mode 100644 index 0000000..482b189 --- /dev/null +++ b/src/modules/grpc/proto/config.proto @@ -0,0 +1,31 @@ +syntax = "proto3"; + +package manager.v1; + +service Parameters { + rpc GetParameters (GetParametersRequest) returns (GetParametersResponse); +} + +message Limitations { + int32 max_message_length = 1; + int32 max_subscriptions = 2; + int32 max_filters = 3; + int32 max_subid_length = 4; + int32 min_pow_difficulty = 5; + bool auth_required = 6; + bool payment_required = 7; + bool restricted_writes = 8; + int32 max_event_tags = 9; + int32 max_content_length = 10; + int64 created_at_lower_limit = 11; + int64 created_at_upper_limit = 12; + uint32 default_query_limit = 13; + uint32 max_query_limit = 14; +} + +message GetParametersRequest {} + +message GetParametersResponse { + Limitations limitations = 1; + string url = 2; +} diff --git a/src/modules/grpc/proto/kraken.proto b/src/modules/grpc/proto/kraken.proto deleted file mode 100644 index 5585a29..0000000 --- a/src/modules/grpc/proto/kraken.proto +++ /dev/null @@ -1,89 +0,0 @@ -// Define the syntax version for Protocol Buffers -syntax = "proto3"; - -// Define the package for the services and messages -package kraken; - -// Service definitions - -// ServiceRegistry handles service registration -service ServiceRegistry { - // Registers a service with the registry - rpc registerService (registerServiceRequest) returns (registerServiceResponse); -} - -// Config service provides configuration details -service Config { - // Retrieves the current configuration - rpc getConfig (EmptyRequest) returns (getConfigResponse); -} - -// Log service handles logging operations -service Log { - // Adds a log entry - rpc addLog (addLogRequest) returns (addLogResponse); -} - -// Message definitions - -// Request to register a service -message registerServiceRequest { - string port = 1; // Service grpc port - uint32 heartbeat_duration_in_sec = 2; // Heartbeat interval in seconds - ServiceTypeEnum type = 3; // Type of the service (e.g., RELAY) - string region = 4; // Region of the service -} - -// Response after registering a service -message registerServiceResponse { - bool success = 1; // Indicates if registration was successful - optional string message = 2; // Optional message with additional information - string token = 3; // Token assigned to the registered service -} - -// Empty request used for methods that do not require parameters -message EmptyRequest {} - -// Request to add a log entry -message addLogRequest { - string message = 1; // Log message content - string stack = 2; // Stack trace or additional log details -} - -// Response after adding a log entry -message addLogResponse { - bool success = 1; // Indicates if the log entry was successfully added - optional string message = 2; // Optional message with additional information -} - -// Configuration limitations -message limitations { - int32 max_message_length = 1; // Maximum allowed message length - int32 max_subscriptions = 2; // Maximum number of subscriptions allowed - int32 max_filters = 3; // Maximum number of filters allowed - int32 max_subid_length = 4; // Maximum length of a subscription ID - int32 min_pow_difficulty = 5; // Minimum proof-of-work difficulty - bool auth_required = 6; // Indicates if authentication is required - bool payment_required = 7; // Indicates if payment is required - bool restricted_writes = 8; // Indicates if writes are restricted - int32 max_event_tags = 9; // Maximum number of event tags allowed - int32 max_content_length = 10; // Maximum length of content allowed - int64 created_at_lower_limit = 11; // Lower limit for creation timestamps - int64 created_at_upper_limit = 12; // Upper limit for creation timestamps - uint32 default_query_limit = 13; // Defualt of query limit - uint32 max_query_limit = 14; // Maximum of query limit -} - -// Response containing configuration details -message getConfigResponse { - limitations limitations = 1; // Configuration limitations - string url = 2; // Service URL -} - -// Enum definitions - -// Types of services that can be registered -enum ServiceTypeEnum { - UNKNOWN = 0; // Unknown service type - RELAY = 1; // Relay service type -} diff --git a/src/modules/grpc/proto/log.proto b/src/modules/grpc/proto/log.proto new file mode 100644 index 0000000..e73138f --- /dev/null +++ b/src/modules/grpc/proto/log.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; + +package manager.v1; + +service Log { + rpc AddLog (AddLogRequest) returns (AddLogResponse); +} + +message AddLogRequest { + string message = 1; + string stack = 2; +} + +message AddLogResponse { + bool success = 1; + optional string message = 2; +} diff --git a/src/modules/grpc/proto/immortal-health-service.proto b/src/modules/grpc/proto/relay-health.proto similarity index 95% rename from src/modules/grpc/proto/immortal-health-service.proto rename to src/modules/grpc/proto/relay-health.proto index 63aee4b..cf5cb8e 100644 --- a/src/modules/grpc/proto/immortal-health-service.proto +++ b/src/modules/grpc/proto/relay-health.proto @@ -1,17 +1,11 @@ syntax = "proto3"; -package immortal; +package relay.v1; service HealthService { rpc Status (StatusRequest) returns (StatusResponse); } -enum Status { - UNKNOWN = 0; - CONNECTED = 1; - DISCONNECTED = 2; -} - message Service { string name = 1; Status status = 2; @@ -24,4 +18,10 @@ message StatusResponse { repeated Service services = 1; int64 uptime = 2; string version = 3; -} \ No newline at end of file +} + +enum Status { + UNKNOWN = 0; + CONNECTED = 1; + DISCONNECTED = 2; +} diff --git a/src/modules/grpc/proto/service_registry.proto b/src/modules/grpc/proto/service_registry.proto new file mode 100644 index 0000000..ef7f2aa --- /dev/null +++ b/src/modules/grpc/proto/service_registry.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; + +package manager.v1; + +service ServiceRegistry { + rpc RegisterService (RegisterServiceRequest) returns (RegisterServiceResponse); +} + +message RegisterServiceRequest { + string port = 1; + uint32 heartbeat_duration_in_sec = 2; + ServiceTypeEnum type = 3; + string region = 4; +} + +message RegisterServiceResponse { + bool success = 1; + optional string message = 2; + string token = 3; +} + +enum ServiceTypeEnum { + UNKNOWN = 0; + RELAY = 1; +} diff --git a/src/modules/log/controllers/log-grpc.controller.ts b/src/modules/log/controllers/log-grpc.controller.ts index 3fd92da..72673b8 100644 --- a/src/modules/log/controllers/log-grpc.controller.ts +++ b/src/modules/log/controllers/log-grpc.controller.ts @@ -3,9 +3,8 @@ import { Controller } from '@nestjs/common'; import ServiceRegistryService from '../../../../src/modules/service-registry/services/service-registry.service'; import { ApiConfigService } from '../../../shared/services/api-config.service'; -import type { addLogRequest, addLogResponse, LogController } from '../../grpc/gen/ts/kraken'; -import { LogControllerMethods } from '../../grpc/gen/ts/kraken'; import { LogService } from '../log.service'; +import { AddLogRequest, AddLogResponse, LogController, LogControllerMethods } from '../../../../src/modules/grpc/gen/ts/log'; @Controller() @LogControllerMethods() @@ -16,7 +15,7 @@ export class LogGrpcController implements LogController { private readonly serviceRegistryService: ServiceRegistryService, ) {} - async addLog(request: addLogRequest, metadata?: Metadata): Promise { + async addLog(request: AddLogRequest, metadata?: Metadata): Promise { try { const token = metadata?.getMap().token?.toString(); diff --git a/src/modules/service-registry/controllers/service-registry-grpc.controller.ts b/src/modules/service-registry/controllers/service-registry-grpc.controller.ts index 69be0f4..134f1be 100644 --- a/src/modules/service-registry/controllers/service-registry-grpc.controller.ts +++ b/src/modules/service-registry/controllers/service-registry-grpc.controller.ts @@ -2,10 +2,14 @@ import type { ServerUnaryCall, Metadata } from '@grpc/grpc-js'; import { Controller } from '@nestjs/common'; import { ApiConfigService } from '../../../../src/shared/services/api-config.service'; -import type { registerServiceRequest, registerServiceResponse } from '../../grpc/gen/ts/kraken'; -import { ServiceRegistryControllerMethods, ServiceTypeEnum } from '../../grpc/gen/ts/kraken'; import { ServiceType } from '../enums/service-types.enum'; import ServiceRegistryService from '../services/service-registry.service'; +import { + RegisterServiceRequest, + RegisterServiceResponse, + ServiceRegistryControllerMethods, + ServiceTypeEnum, +} from '../../../../src/modules/grpc/gen/ts/service_registry'; @Controller() @ServiceRegistryControllerMethods() @@ -16,10 +20,10 @@ export class ServiceRegistryGrpcController implements ServiceRegistryGrpcControl ) {} async registerService( - request: registerServiceRequest, + request: RegisterServiceRequest, _metadata: Metadata, - call: ServerUnaryCall, - ): Promise { + call: ServerUnaryCall, + ): Promise { try { const { port, heartbeatDurationInSec, type, region } = request; diff --git a/src/modules/service-registry/services/service-registry-health-check.service.ts b/src/modules/service-registry/services/service-registry-health-check.service.ts index 84ae9c4..b71c9d1 100644 --- a/src/modules/service-registry/services/service-registry-health-check.service.ts +++ b/src/modules/service-registry/services/service-registry-health-check.service.ts @@ -2,13 +2,13 @@ import type { OnModuleDestroy, OnModuleInit } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common'; import { lastValueFrom } from 'rxjs'; -import { Status } from '../../../../src/modules/grpc/gen/ts/immortal-health-service'; import { ImmortalGrpcClient } from '../../../../src/modules/grpc/immortal-grpc.client'; import type { ServiceRegistryEntity } from '../entities/service-registry.entity'; import { ServiceStatus } from '../enums/service-status.enum'; import { ServiceType } from '../enums/service-types.enum'; import { ServiceRegistryRepository } from '../service-registry.repository'; import ServiceRegistryService from './service-registry.service'; +import { Status } from '../../../../src/modules/grpc/gen/ts/relay-health'; @Injectable() export default class ServiceRegistryHealthCheckService implements OnModuleInit, OnModuleDestroy { diff --git a/src/shared/services/api-config.service.ts b/src/shared/services/api-config.service.ts index 375aee6..ece0aa4 100644 --- a/src/shared/services/api-config.service.ts +++ b/src/shared/services/api-config.service.ts @@ -107,7 +107,11 @@ export class ApiConfigService { get grpcConfig() { return { port: this.getString('GRPC_PORT'), - protoPath: join(__dirname, '..', '..', 'modules', 'grpc', 'proto', 'kraken.proto'), + protoPath: [ + join(__dirname, '..', '..', 'modules', 'grpc', 'proto', 'config.proto'), + join(__dirname, '..', '..', 'modules', 'grpc', 'proto', 'log.proto'), + join(__dirname, '..', '..', 'modules', 'grpc', 'proto', 'service_registry.proto'), + ], }; }