Skip to content

Commit

Permalink
fix(frontend): fix proto file methods parsing (#3324)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeepc committed Nov 1, 2023
1 parent 586a3a4 commit e6882fa
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions 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';
Expand All @@ -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<string[]>(
Expand Down

0 comments on commit e6882fa

Please sign in to comment.