From 26f6fcbea82fd07dbc18f31f90851138c161c9a0 Mon Sep 17 00:00:00 2001 From: Jorge Padilla Date: Tue, 31 Oct 2023 13:09:02 -0500 Subject: [PATCH] fix(frontend): fix proto file methods parsing --- web/src/services/Triggers/Grpc.service.ts | 25 ++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/web/src/services/Triggers/Grpc.service.ts b/web/src/services/Triggers/Grpc.service.ts index 244965fc42..ad8eb5df9f 100644 --- a/web/src/services/Triggers/Grpc.service.ts +++ b/web/src/services/Triggers/Grpc.service.ts @@ -1,4 +1,4 @@ -import {parse, NamespaceBase, Service} from 'protobufjs'; +import {parse, Namespace, ReflectionObject, Service} from 'protobufjs'; import {IRpcValues, ITriggerService} from 'types/Test.types'; import Validator from 'utils/Validator'; import GrpcRequest from 'models/GrpcRequest.model'; @@ -7,17 +7,28 @@ interface IRpcTriggerService extends ITriggerService { getMethodList(protoFile: string): string[]; } +function isService(ro: ReflectionObject): ro is Service { + return (ro as Service).methods !== undefined; +} + const RpcTriggerService = (): IRpcTriggerService => ({ getMethodList(protoFile) { const parsedData = parse(protoFile); - const methodList = parsedData.root.nestedArray.flatMap(a => { - const namespace = a as NamespaceBase; + const methodList = parsedData.root.nestedArray.flatMap(aReflection => { + if (isService(aReflection)) { + return aReflection.methodsArray; + } + + return ( + (aReflection as Namespace)?.nestedArray?.flatMap(bReflection => { + if (isService(bReflection)) { + return bReflection.methodsArray; + } - return namespace.nestedArray.flatMap(b => { - const service = b as Service; - return service.methods ? service.methodsArray : []; - }); + return []; + }) ?? [] + ); }); return methodList.reduce(