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

feat(nestjs): update grpc reflection #341

Merged
merged 5 commits into from
Jan 24, 2025
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
400 changes: 281 additions & 119 deletions .pnp.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/grpc-http-proxy/src/server.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import echo from '../proto/examples/echo/v1/echo.proto'
export const serverOptions: GrpcOptions = {
transport: Transport.GRPC,
options: {
package: ['grpc.reflection.v1alpha', 'examples.echo.v1'],
package: ['grpc.reflection.v1', 'examples.echo.v1'],
protoPath: [reflection, echo],
url: '0.0.0.0:50051',
loader: {
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc-playground/src/server.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import playground from '../proto/examples/playground/v1/playground.pro
export const serverOptions: GrpcOptions = {
transport: Transport.GRPC,
options: {
package: ['grpc.reflection.v1alpha', 'examples.playground.v1'],
package: ['grpc.reflection.v1', 'examples.playground.v1'],
protoPath: [reflection, playground],
url: '0.0.0.0:50051',
loader: {
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc-reflection/src/server.options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import echo from '../proto/examples/echo/v1/echo.proto'
export const serverOptions: GrpcOptions = {
transport: Transport.GRPC,
options: {
package: ['grpc.reflection.v1alpha', 'examples.echo.v1'],
package: ['grpc.reflection.v1', 'examples.echo.v1'],
protoPath: [reflection, echo],
url: '0.0.0.0:50051',
loader: {
Expand Down
8 changes: 1 addition & 7 deletions packages/nestjs-connectrpc-errors/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@


# 0.0.0 (2025-01-22)


### Features


* **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))


- **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))
10 changes: 2 additions & 8 deletions packages/nestjs-connectrpc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@


## 0.0.2 (2025-01-22)


### Features


* **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
* **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))


- **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
- **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))
15 changes: 4 additions & 11 deletions packages/nestjs-external-renderer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@


## 0.0.8 (2025-01-22)


### Bug Fixes


* typecheck, build ([1f9ca05](https://github.com/atls/nestjs/commit/1f9ca0533705c5977ccbfd152a59f545d3f01f1c))
- typecheck, build ([1f9ca05](https://github.com/atls/nestjs/commit/1f9ca0533705c5977ccbfd152a59f545d3f01f1c))

### Features


* **batch-queue:** init ([6ecbffa](https://github.com/atls/nestjs/commit/6ecbffa3fc54f9bb33ac1ae57b274772b99c8e9d))
* **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
* **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))


- **batch-queue:** init ([6ecbffa](https://github.com/atls/nestjs/commit/6ecbffa3fc54f9bb33ac1ae57b274772b99c8e9d))
- **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
- **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))
12 changes: 3 additions & 9 deletions packages/nestjs-gateway/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@


## 0.0.16 (2025-01-22)


### Features


* **batch-queue:** init ([6ecbffa](https://github.com/atls/nestjs/commit/6ecbffa3fc54f9bb33ac1ae57b274772b99c8e9d))
* **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
* **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))


- **batch-queue:** init ([6ecbffa](https://github.com/atls/nestjs/commit/6ecbffa3fc54f9bb33ac1ae57b274772b99c8e9d))
- **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
- **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))
10 changes: 2 additions & 8 deletions packages/nestjs-grpc-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@


## 0.0.12 (2025-01-22)


### Features


* **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
* **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))


- **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
- **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))
15 changes: 4 additions & 11 deletions packages/nestjs-grpc-keto/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@


## 0.0.2 (2025-01-22)


### Bug Fixes


* typecheck, build ([1f9ca05](https://github.com/atls/nestjs/commit/1f9ca0533705c5977ccbfd152a59f545d3f01f1c))
- typecheck, build ([1f9ca05](https://github.com/atls/nestjs/commit/1f9ca0533705c5977ccbfd152a59f545d3f01f1c))

### Features


* **batch-queue:** init ([6ecbffa](https://github.com/atls/nestjs/commit/6ecbffa3fc54f9bb33ac1ae57b274772b99c8e9d))
* **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
* **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))


- **batch-queue:** init ([6ecbffa](https://github.com/atls/nestjs/commit/6ecbffa3fc54f9bb33ac1ae57b274772b99c8e9d))
- **common:** bump yarn, trigger release ([#338](https://github.com/atls/nestjs/issues/338)) ([9837d48](https://github.com/atls/nestjs/commit/9837d482f75928a3ac132d0306ab6de04d8a04b9))
- **connectrpc:** init ([#339](https://github.com/atls/nestjs/issues/339)) ([663389c](https://github.com/atls/nestjs/commit/663389cd20156a9c10e93d6dbb8326bf8dcac781))
11 changes: 9 additions & 2 deletions packages/nestjs-grpc-reflection/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
version: v1beta1
version: v1

plugins:
- name: ts_proto
out: src
opt: ts_proto_out=proto,nestJs=true,addGrpcMetadata=true,esModuleInterop=true,useOptionals=true,outputServices=grpc-js
opt:
- nestJs=true
- addGrpcMetadata=true
- esModuleInterop=true
- importSuffix=.js
- useOptionals=messages
- outputServices=grpc-js
- env=node
10 changes: 5 additions & 5 deletions packages/nestjs-grpc-reflection/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: v1beta1

build:
roots:
- proto
version: v1

lint:
use:
- DEFAULT
ignore:
- grpc

breaking:
use:
- FILE
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import path from 'path'
export const serverOptions: GrpcOptions = {
transport: Transport.GRPC,
options: {
package: ['grpc.reflection.v1alpha', 'test'],
package: ['grpc.reflection.v1', 'test'],
protoPath: [
path.join(__dirname, '../../proto/grpc/reflection/v1alpha/reflection.proto'),
path.join(__dirname, '../../proto/grpc/reflection/v1/reflection.proto'),
path.join(__dirname, 'test1_service.proto'),
path.join(__dirname, 'test2_service.proto'),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**

Check failure on line 1 in packages/nestjs-grpc-reflection/integration/test/grpc-reflection.test.ts

View workflow job for this annotation

GitHub Actions / Test:Unit

test failed

test failed
Raw output
test failed
* @jest-environment node
*/

Expand All @@ -15,8 +15,7 @@
import { it } from '@jest/globals'
import { expect } from '@jest/globals'
import { afterAll } from '@jest/globals'
// @ts-expect-error
import { FileDescriptorProto } from 'google-protobuf/google/protobuf/descriptor_pb'
import { FileDescriptorProto } from 'google-protobuf/google/protobuf/descriptor_pb.js'
import { ReplaySubject } from 'rxjs'
import getPort from 'get-port'
import path from 'path'
Expand All @@ -40,11 +39,8 @@
transport: Transport.GRPC,
options: {
url: `0.0.0.0:${servicePort}`,
package: 'grpc.reflection.v1alpha',
protoPath: path.join(
__dirname,
'../../proto/grpc/reflection/v1alpha/reflection.proto'
),
package: 'grpc.reflection.v1',
protoPath: path.join(__dirname, '../../proto/grpc/reflection/v1/reflection.proto'),
loader: {
arrays: true,
keepCase: false,
Expand Down Expand Up @@ -96,7 +92,7 @@
expect(response?.listServicesResponse?.service).toEqual(
expect.arrayContaining([
expect.objectContaining({
name: 'grpc.reflection.v1alpha.ServerReflection',
name: 'grpc.reflection.v1.ServerReflection',
}),
])
)
Expand All @@ -110,18 +106,20 @@
listServices: undefined,
fileByFilename: undefined,
allExtensionNumbersOfType: undefined,
fileContainingSymbol: 'grpc.reflection.v1alpha.ServerReflection',
fileContainingSymbol: 'grpc.reflection.v1.ServerReflection',
})

request.complete()

const response = await serverReflection.serverReflectionInfo(request.asObservable()).toPromise()

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const descriptor = FileDescriptorProto.deserializeBinary(
response?.fileDescriptorResponse?.fileDescriptorProto[0]
)
if (response?.fileDescriptorResponse) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const descriptor = FileDescriptorProto.deserializeBinary(
response?.fileDescriptorResponse?.fileDescriptorProto[0]
)

expect(descriptor.array).toContain('grpc_reflection_v1alpha.proto')
expect(descriptor.toArray()).toContain('grpc_reflection_v1.proto')
}
})
})
17 changes: 9 additions & 8 deletions packages/nestjs-grpc-reflection/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@atls/nestjs-grpc-reflection",
"version": "0.0.16",
"version": "1.0.0",
"license": "BSD-3-Clause",
"type": "module",
"exports": {
Expand All @@ -25,25 +25,26 @@
},
"dependencies": {
"@atls/nestjs-proto-types": "workspace:*",
"@grpc/grpc-js": "1.11.2",
"@bufbuild/protobuf": "2.2.3",
"@grpc/grpc-js": "1.12.5",
"@grpc/proto-loader": "0.7.13",
"google-protobuf": "3.21.4",
"long": "5.2.3",
"protobufjs": "7.4.0"
},
"devDependencies": {
"@jest/globals": "29.7.0",
"@nestjs/common": "10.4.1",
"@nestjs/core": "10.4.1",
"@nestjs/microservices": "10.4.1",
"@nestjs/testing": "10.4.1",
"@nestjs/common": "10.4.15",
"@nestjs/core": "10.4.15",
"@nestjs/microservices": "10.4.15",
"@nestjs/testing": "10.4.15",
"@types/google-protobuf": "3.15.12",
"@types/long": "5.0.0",
"get-port": "7.1.0",
"long": "5.2.3",
"reflect-metadata": "0.2.2",
"rxjs": "7.8.1",
"supertest": "6.3.4",
"ts-proto": "1.156.7"
"ts-proto": "2.6.0"
},
"peerDependencies": {
"@nestjs/common": "10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016 gRPC authors.
// Copyright 2016 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,11 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Service exported by server reflection
// Service exported by server reflection. A more complete description of how
// server reflection works can be found at
// https://github.com/grpc/grpc/blob/master/doc/server-reflection.md
//
// The canonical version of this proto can be found at
// https://github.com/grpc/grpc-proto/blob/master/grpc/reflection/v1/reflection.proto

syntax = "proto3";

package grpc.reflection.v1alpha;
package grpc.reflection.v1;

option go_package = "google.golang.org/grpc/reflection/grpc_reflection_v1";
option java_multiple_files = true;
option java_package = "io.grpc.reflection.v1";
option java_outer_classname = "ServerReflectionProto";

service ServerReflection {
// The reflection service is structured as a bidirectional stream, ensuring
Expand Down Expand Up @@ -72,21 +82,21 @@ message ExtensionRequest {
message ServerReflectionResponse {
string valid_host = 1;
ServerReflectionRequest original_request = 2;
// The server set one of the following fields accroding to the message_request
// The server sets one of the following fields according to the message_request
// in the request.
oneof message_response {
// This message is used to answer file_by_filename, file_containing_symbol,
// file_containing_extension requests with transitive dependencies. As
// the repeated label is not allowed in oneof fields, we use a
// file_containing_extension requests with transitive dependencies.
// As the repeated label is not allowed in oneof fields, we use a
// FileDescriptorResponse message to encapsulate the repeated fields.
// The reflection service is allowed to avoid sending FileDescriptorProtos
// that were previously sent in response to earlier requests in the stream.
FileDescriptorResponse file_descriptor_response = 4;

// This message is used to answer all_extension_numbers_of_type requst.
// This message is used to answer all_extension_numbers_of_type requests.
ExtensionNumberResponse all_extension_numbers_response = 5;

// This message is used to answer list_services request.
// This message is used to answer list_services requests.
ListServiceResponse list_services_response = 6;

// This message is used when an error occurs.
Expand Down
5 changes: 1 addition & 4 deletions packages/nestjs-grpc-reflection/proto/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
Object.defineProperty(exports, '__esModule', { value: true })
exports.serverReflectionPath = void 0
const path_1 = require('path')
exports.serverReflectionPath =
typeof __non_webpack_require__ === 'undefined'
? path_1.join(__dirname, './grpc/reflection/v1alpha/reflection.proto')
: require('./grpc/reflection/v1alpha/reflection.proto').default
exports.serverReflectionPath = path_1.join(__dirname, './grpc/reflection/v1/reflection.proto')
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class GrpcServicesRegistry {
getServiceNameFromServiceDefinition(serviceDefinition: ServiceDefinition): string {
const methodDefinition = Object.values(serviceDefinition).shift()

return methodDefinition!.path.split('/')[1]
return methodDefinition?.path.split('/')[1] || ''
}

addService(service: ServiceDefinition): void {
Expand All @@ -28,13 +28,12 @@ export class GrpcServicesRegistry {
getFileDescriptorProtoByFileContainingSymbol(
fileContainingSymbol: string
): FileDescriptorProto | undefined {
// @ts-expect-error
// @ts-expect-error correct return type
return this.services.reduce<FileDescriptorProto | undefined>((fileDescriptorProto, service) => {
if (fileDescriptorProto) {
return fileDescriptorProto
}

// @ts-expect-error
// @ts-expect-error correct return type
return Object.values(service).reduce<FileDescriptorProto | undefined>((
descriptor,
method
Expand All @@ -47,7 +46,9 @@ export class GrpcServicesRegistry {
return method.requestType.fileDescriptorProtos.find((fdp) => {
const fileDescriptor = FileDescriptorProto.deserializeBinary(fdp)

return fileContainingSymbol.includes(fileDescriptor.getPackage()!)
const filePackage = fileDescriptor.getPackage()

return filePackage ? fileContainingSymbol.includes(filePackage) : false
})
}

Expand Down
Loading
Loading