Skip to content

Commit

Permalink
fix: nestjs grpc reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
OsirisAnubiz committed Nov 6, 2024
1 parent 617ce49 commit 4bc984d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class GrpcReflectionController {
validHost: '',
originalRequest: reflectionRequest,
fileDescriptorResponse: {
fileDescriptorProto: [fileDescriptorProto],
fileDescriptorProto: [fileDescriptorProto as unknown as Uint8Array],
},
})
} else {
Expand Down
14 changes: 4 additions & 10 deletions packages/nestjs-grpc-reflection/src/grpc/grpc-services.registry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { ServiceDefinition } from '@grpc/proto-loader'

import { Injectable } from '@nestjs/common'
// @ts-expect-error
import { FileDescriptorProto } from 'google-protobuf/google/protobuf/descriptor_pb'
import { FileDescriptorProto } from 'google-protobuf/google/protobuf/descriptor_pb.js'

@Injectable()
export class GrpcServicesRegistry {
Expand All @@ -28,32 +27,27 @@ export class GrpcServicesRegistry {

getFileDescriptorProtoByFileContainingSymbol(
fileContainingSymbol: string
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
): FileDescriptorProto | undefined {
// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
// @ts-expect-error
return this.services.reduce<FileDescriptorProto | undefined>((fileDescriptorProto, service) => {
if (fileDescriptorProto) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return fileDescriptorProto
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-redundant-type-constituents
// @ts-expect-error
return Object.values(service).reduce<FileDescriptorProto | undefined>((
descriptor,
method
) => {
if (descriptor) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return descriptor
}

if (method.path.includes(fileContainingSymbol)) {
return method.requestType.fileDescriptorProtos.find((fdp) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const fileDescriptor = FileDescriptorProto.deserializeBinary(fdp)

// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
return fileContainingSymbol.includes(fileDescriptor.getPackage())
return fileContainingSymbol.includes(fileDescriptor.getPackage()!)
})
}

Expand Down

0 comments on commit 4bc984d

Please sign in to comment.