Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nestjs grpc reflection #331

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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