import * as protoLoader from "@grpc/proto-loader" ; export function loadProtoFile ( protoPath ) { try { const packageDefinition = protoLoader . loadSync ( protoPath , { keepCase : true , longs : String , enums : String , defaults : true , oneofs : true , } ) ; return packageDefinition ; } catch { return Error ( "Cannot load protofile" ) ; } } export function parsePackageDefinition ( pkgDefn ) { const protoMessages = { } ; const protoServices = { } ; Object . entries ( pkgDefn ) . forEach ( entry => { const [ key , value ] = entry ; if ( ! Object . hasOwnProperty . call ( value , "fileDescriptorProtos" ) ) { protoServices [ key ] = < protoLoader . ServiceDefinition > value ; } else { protoMessages [ value . type . name ] = < protoLoader . MessageTypeDefinition > value ; } } ) ; return { protoServices , protoMessages , } ; }