mirror of https://github.com/grpc/grpc-node.git
feat(grpc-reflection): created new grpc-reflection package ported from nestjs-grpc-reflection library
This commit is contained in:
parent
779e970099
commit
54df17727f
|
@ -46,3 +46,11 @@ Directory: [`packages/grpc-health-check`](https://github.com/grpc/grpc-node/tree
|
|||
npm package: [grpc-health-check](https://www.npmjs.com/package/grpc-health-check)
|
||||
|
||||
Health check service for gRPC servers.
|
||||
|
||||
### gRPC Reflection API Service
|
||||
|
||||
Directory: [`packages/grpc-reflection`](https://github.com/grpc/grpc-node/tree/master/packages/grpc-reflection)
|
||||
|
||||
npm package: [@grpc/reflection](https://www.npmjs.com/package/@grpc/reflection)
|
||||
|
||||
Reflection API service for gRPC servers.
|
||||
|
|
|
@ -19,10 +19,11 @@ import * as gulp from 'gulp';
|
|||
import * as healthCheck from './packages/grpc-health-check/gulpfile';
|
||||
import * as jsCore from './packages/grpc-js/gulpfile';
|
||||
import * as jsXds from './packages/grpc-js-xds/gulpfile';
|
||||
import * as reflection from './packages/grpc-reflection/gulpfile';
|
||||
import * as protobuf from './packages/proto-loader/gulpfile';
|
||||
import * as internalTest from './test/gulpfile';
|
||||
|
||||
const installAll = gulp.series(jsCore.install, healthCheck.install, protobuf.install, internalTest.install, jsXds.install);
|
||||
const installAll = gulp.series(jsCore.install, healthCheck.install, protobuf.install, internalTest.install, jsXds.install, reflection.install);
|
||||
|
||||
const lint = gulp.parallel(jsCore.lint);
|
||||
|
||||
|
@ -36,7 +37,7 @@ const clean = gulp.series(jsCore.clean, protobuf.clean, jsXds.clean);
|
|||
|
||||
const cleanAll = gulp.series(jsXds.cleanAll, jsCore.cleanAll, internalTest.cleanAll, protobuf.cleanAll);
|
||||
|
||||
const nativeTestOnly = gulp.parallel(healthCheck.test);
|
||||
const nativeTestOnly = gulp.parallel(healthCheck.test, reflection.test);
|
||||
|
||||
const nativeTest = gulp.series(build, nativeTestOnly);
|
||||
|
||||
|
|
|
@ -0,0 +1,201 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,42 @@
|
|||
# gRPC Reflection
|
||||
|
||||
gRPC reflection API service for use with gRPC-node.
|
||||
|
||||
## Background
|
||||
|
||||
This package provides an implementation of the [gRPC Server Reflection Protocol](https://github.com/grpc/grpc/blob/master/doc/server-reflection.md) service which can be added to an existing gRPC server. Adding this service to your server will allow clients [such as postman](https://blog.postman.com/postman-now-supports-grpc/) to dynamically load the API specification from your running application rather than needing to pass around and load proto files manually.
|
||||
|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
Use the package manager [npm](https://www.npmjs.com/get-npm) to install `@grpc/reflection`.
|
||||
|
||||
```bash
|
||||
npm install @grpc/reflection
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Any gRPC-node server can use `@grpc/reflection` to expose reflection information about their gRPC API.
|
||||
|
||||
```typescript
|
||||
import { ReflectionServer } from '@grpc/reflection';
|
||||
|
||||
const pkg = protoLoader.load(...); // Load your gRPC package definition as normal
|
||||
|
||||
// Create the reflection implementation based on your gRPC package and add it to your existing server
|
||||
const reflection = new ReflectionServer(pkg);
|
||||
reflection.addToServer(server);
|
||||
```
|
||||
|
||||
Congrats! Your server now allows any client to request reflection information about its API.
|
||||
|
||||
## Contributing
|
||||
|
||||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. The original proposal for this library can be found in [gRFC L108](https://github.com/grpc/proposal/blob/master/L108-node-grpc-reflection-library.md)
|
||||
|
||||
Please make sure to update tests as appropriate.
|
||||
|
||||
## License
|
||||
[Apache License 2.0](https://choosealicense.com/licenses/apache-2.0/)
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2019 gRPC authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
import * as gulp from 'gulp';
|
||||
import * as mocha from 'gulp-mocha';
|
||||
import * as execa from 'execa';
|
||||
import * as path from 'path';
|
||||
|
||||
const reflectionDir = __dirname;
|
||||
const outDir = path.resolve(reflectionDir, 'build');
|
||||
|
||||
const execNpmVerb = (verb: string, ...args: string[]) =>
|
||||
execa('npm', [verb, ...args], {cwd: reflectionDir, stdio: 'inherit'});
|
||||
const execNpmCommand = execNpmVerb.bind(null, 'run');
|
||||
|
||||
const install = () => execNpmVerb('install', '--unsafe-perm');
|
||||
|
||||
/**
|
||||
* Transpiles TypeScript files in src/ to JavaScript according to the settings
|
||||
* found in tsconfig.json.
|
||||
*/
|
||||
const compile = () => execNpmCommand('compile');
|
||||
|
||||
const runTests = () => {
|
||||
return gulp.src(`${outDir}/test/**/*.js`)
|
||||
.pipe(mocha({reporter: 'mocha-jenkins-reporter',
|
||||
require: ['ts-node/register']}));
|
||||
};
|
||||
|
||||
const test = gulp.series(install, runTests);
|
||||
|
||||
export {
|
||||
install,
|
||||
compile,
|
||||
test
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.0 MiB |
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"name": "@grpc/reflection",
|
||||
"version": "1.0.0",
|
||||
"author": "Justin Timmons",
|
||||
"description": "Reflection API service for use with gRPC-node",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/grpc/grpc-node.git",
|
||||
"directory": "packages/grpc-reflection"
|
||||
},
|
||||
"bugs": "https://github.com/grpc/grpc-node/issues",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Justin Timmons",
|
||||
"email": "justinmtimmons@gmail.com"
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
"src",
|
||||
"build",
|
||||
"proto"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"scripts": {
|
||||
"compile": "tsc -p .",
|
||||
"postcompile": "copyfiles './proto/**/*.proto' build/",
|
||||
"prepare": "npm run generate-types && npm run compile",
|
||||
"test": "mocha --require ts-node/register test/**.ts",
|
||||
"generate-types": "proto-loader-gen-types --longs String --enums String --bytes Array --defaults --oneofs --includeComments --includeDirs proto/ -O src/generated grpc/reflection/v1/reflection.proto grpc/reflection/v1alpha/reflection.proto"
|
||||
},
|
||||
"dependencies": {
|
||||
"google-protobuf": "^3.21.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@grpc/grpc-js": ">=1.5.4",
|
||||
"@grpc/proto-loader": ">=0.6.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@grpc/grpc-js": "^1.8.21",
|
||||
"@grpc/proto-loader": "^0.7.10",
|
||||
"@types/google-protobuf": "^3.15.7",
|
||||
"copyfiles": "^2.4.1",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
// Taken from spec https://raw.githubusercontent.com/grpc/grpc/master/src/proto/grpc/reflection/v1/reflection.proto
|
||||
// Additional versions can be found here: https://github.com/grpc/grpc/tree/master/src/proto/grpc/reflection
|
||||
|
||||
// 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.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// 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.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
|
||||
// all related requests go to a single server.
|
||||
rpc ServerReflectionInfo(stream ServerReflectionRequest)
|
||||
returns (stream ServerReflectionResponse);
|
||||
}
|
||||
|
||||
// The message sent by the client when calling ServerReflectionInfo method.
|
||||
message ServerReflectionRequest {
|
||||
string host = 1;
|
||||
// To use reflection service, the client should set one of the following
|
||||
// fields in message_request. The server distinguishes requests by their
|
||||
// defined field and then handles them using corresponding methods.
|
||||
oneof message_request {
|
||||
// Find a proto file by the file name.
|
||||
string file_by_filename = 3;
|
||||
|
||||
// Find the proto file that declares the given fully-qualified symbol name.
|
||||
// This field should be a fully-qualified symbol name
|
||||
// (e.g. <package>.<service>[.<method>] or <package>.<type>).
|
||||
string file_containing_symbol = 4;
|
||||
|
||||
// Find the proto file which defines an extension extending the given
|
||||
// message type with the given field number.
|
||||
ExtensionRequest file_containing_extension = 5;
|
||||
|
||||
// Finds the tag numbers used by all known extensions of the given message
|
||||
// type, and appends them to ExtensionNumberResponse in an undefined order.
|
||||
// Its corresponding method is best-effort: it's not guaranteed that the
|
||||
// reflection service will implement this method, and it's not guaranteed
|
||||
// that this method will provide all extensions. Returns
|
||||
// StatusCode::UNIMPLEMENTED if it's not implemented.
|
||||
// This field should be a fully-qualified type name. The format is
|
||||
// <package>.<type>
|
||||
string all_extension_numbers_of_type = 6;
|
||||
|
||||
// List the full names of registered services. The content will not be
|
||||
// checked.
|
||||
string list_services = 7;
|
||||
}
|
||||
}
|
||||
|
||||
// The type name and extension number sent by the client when requesting
|
||||
// file_containing_extension.
|
||||
message ExtensionRequest {
|
||||
// Fully-qualified type name. The format should be <package>.<type>
|
||||
string containing_type = 1;
|
||||
int32 extension_number = 2;
|
||||
}
|
||||
|
||||
// The message sent by the server to answer ServerReflectionInfo method.
|
||||
message ServerReflectionResponse {
|
||||
string valid_host = 1;
|
||||
ServerReflectionRequest original_request = 2;
|
||||
// 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
|
||||
// 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 requests.
|
||||
ExtensionNumberResponse all_extension_numbers_response = 5;
|
||||
|
||||
// This message is used to answer list_services requests.
|
||||
ListServiceResponse list_services_response = 6;
|
||||
|
||||
// This message is used when an error occurs.
|
||||
ErrorResponse error_response = 7;
|
||||
}
|
||||
}
|
||||
|
||||
// Serialized FileDescriptorProto messages sent by the server answering
|
||||
// a file_by_filename, file_containing_symbol, or file_containing_extension
|
||||
// request.
|
||||
message FileDescriptorResponse {
|
||||
// Serialized FileDescriptorProto messages. We avoid taking a dependency on
|
||||
// descriptor.proto, which uses proto2 only features, by making them opaque
|
||||
// bytes instead.
|
||||
repeated bytes file_descriptor_proto = 1;
|
||||
}
|
||||
|
||||
// A list of extension numbers sent by the server answering
|
||||
// all_extension_numbers_of_type request.
|
||||
message ExtensionNumberResponse {
|
||||
// Full name of the base type, including the package name. The format
|
||||
// is <package>.<type>
|
||||
string base_type_name = 1;
|
||||
repeated int32 extension_number = 2;
|
||||
}
|
||||
|
||||
// A list of ServiceResponse sent by the server answering list_services request.
|
||||
message ListServiceResponse {
|
||||
// The information of each service may be expanded in the future, so we use
|
||||
// ServiceResponse message to encapsulate it.
|
||||
repeated ServiceResponse service = 1;
|
||||
}
|
||||
|
||||
// The information of a single service used by ListServiceResponse to answer
|
||||
// list_services request.
|
||||
message ServiceResponse {
|
||||
// Full name of a registered service, including its package name. The format
|
||||
// is <package>.<service>
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
// The error code and error message sent by the server when an error occurs.
|
||||
message ErrorResponse {
|
||||
// This field uses the error codes defined in grpc::StatusCode.
|
||||
int32 error_code = 1;
|
||||
string error_message = 2;
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
// Taken from spec https://raw.githubusercontent.com/grpc/grpc/master/src/proto/grpc/reflection/v1alpha/reflection.proto
|
||||
// Additional versions can be found here: https://github.com/grpc/grpc/tree/master/src/proto/grpc/reflection
|
||||
|
||||
// Copyright 2016 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Service exported by server reflection
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
package grpc.reflection.v1alpha;
|
||||
|
||||
service ServerReflection {
|
||||
// The reflection service is structured as a bidirectional stream, ensuring
|
||||
// all related requests go to a single server.
|
||||
rpc ServerReflectionInfo(stream ServerReflectionRequest)
|
||||
returns (stream ServerReflectionResponse);
|
||||
}
|
||||
|
||||
// The message sent by the client when calling ServerReflectionInfo method.
|
||||
message ServerReflectionRequest {
|
||||
string host = 1;
|
||||
// To use reflection service, the client should set one of the following
|
||||
// fields in message_request. The server distinguishes requests by their
|
||||
// defined field and then handles them using corresponding methods.
|
||||
oneof message_request {
|
||||
// Find a proto file by the file name.
|
||||
string file_by_filename = 3;
|
||||
|
||||
// Find the proto file that declares the given fully-qualified symbol name.
|
||||
// This field should be a fully-qualified symbol name
|
||||
// (e.g. <package>.<service>[.<method>] or <package>.<type>).
|
||||
string file_containing_symbol = 4;
|
||||
|
||||
// Find the proto file which defines an extension extending the given
|
||||
// message type with the given field number.
|
||||
ExtensionRequest file_containing_extension = 5;
|
||||
|
||||
// Finds the tag numbers used by all known extensions of the given message
|
||||
// type, and appends them to ExtensionNumberResponse in an undefined order.
|
||||
// Its corresponding method is best-effort: it's not guaranteed that the
|
||||
// reflection service will implement this method, and it's not guaranteed
|
||||
// that this method will provide all extensions. Returns
|
||||
// StatusCode::UNIMPLEMENTED if it's not implemented.
|
||||
// This field should be a fully-qualified type name. The format is
|
||||
// <package>.<type>
|
||||
string all_extension_numbers_of_type = 6;
|
||||
|
||||
// List the full names of registered services. The content will not be
|
||||
// checked.
|
||||
string list_services = 7;
|
||||
}
|
||||
}
|
||||
|
||||
// The type name and extension number sent by the client when requesting
|
||||
// file_containing_extension.
|
||||
message ExtensionRequest {
|
||||
// Fully-qualified type name. The format should be <package>.<type>
|
||||
string containing_type = 1;
|
||||
int32 extension_number = 2;
|
||||
}
|
||||
|
||||
// The message sent by the server to answer ServerReflectionInfo method.
|
||||
message ServerReflectionResponse {
|
||||
string valid_host = 1;
|
||||
ServerReflectionRequest original_request = 2;
|
||||
// The server set one of the following fields accroding 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
|
||||
// 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.
|
||||
ExtensionNumberResponse all_extension_numbers_response = 5;
|
||||
|
||||
// This message is used to answer list_services request.
|
||||
ListServiceResponse list_services_response = 6;
|
||||
|
||||
// This message is used when an error occurs.
|
||||
ErrorResponse error_response = 7;
|
||||
}
|
||||
}
|
||||
|
||||
// Serialized FileDescriptorProto messages sent by the server answering
|
||||
// a file_by_filename, file_containing_symbol, or file_containing_extension
|
||||
// request.
|
||||
message FileDescriptorResponse {
|
||||
// Serialized FileDescriptorProto messages. We avoid taking a dependency on
|
||||
// descriptor.proto, which uses proto2 only features, by making them opaque
|
||||
// bytes instead.
|
||||
repeated bytes file_descriptor_proto = 1;
|
||||
}
|
||||
|
||||
// A list of extension numbers sent by the server answering
|
||||
// all_extension_numbers_of_type request.
|
||||
message ExtensionNumberResponse {
|
||||
// Full name of the base type, including the package name. The format
|
||||
// is <package>.<type>
|
||||
string base_type_name = 1;
|
||||
repeated int32 extension_number = 2;
|
||||
}
|
||||
|
||||
// A list of ServiceResponse sent by the server answering list_services request.
|
||||
message ListServiceResponse {
|
||||
// The information of each service may be expanded in the future, so we use
|
||||
// ServiceResponse message to encapsulate it.
|
||||
repeated ServiceResponse service = 1;
|
||||
}
|
||||
|
||||
// The information of a single service used by ListServiceResponse to answer
|
||||
// list_services request.
|
||||
message ServiceResponse {
|
||||
// Full name of a registered service, including its package name. The format
|
||||
// is <package>.<service>
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
// The error code and error message sent by the server when an error occurs.
|
||||
message ErrorResponse {
|
||||
// This field uses the error codes defined in grpc::StatusCode.
|
||||
int32 error_code = 1;
|
||||
string error_message = 2;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package sample;
|
||||
|
||||
import 'vendor.proto';
|
||||
|
||||
service SampleService {
|
||||
rpc Hello (HelloRequest) returns (HelloResponse) {}
|
||||
rpc Hello2 (HelloRequest) returns (CommonMessage) {}
|
||||
}
|
||||
|
||||
message HelloRequest {
|
||||
string hello = 1;
|
||||
HelloNested nested = 2;
|
||||
ShadowedMessage nestedShadowedMessage = 3;
|
||||
|
||||
message HelloNested {
|
||||
string hello = 1;
|
||||
CommonMessage field = 2;
|
||||
}
|
||||
|
||||
message ShadowedMessage {
|
||||
int32 item = 1;
|
||||
}
|
||||
}
|
||||
|
||||
enum HelloStatus {
|
||||
HELLO = 1;
|
||||
WORLD = 2;
|
||||
}
|
||||
|
||||
message HelloResponse {
|
||||
string world = 1;
|
||||
HelloStatus status = 2;
|
||||
}
|
||||
|
||||
message ShadowedMessage {
|
||||
string hello = 1;
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
syntax = "proto2";
|
||||
|
||||
// NOTE: intentionally using the same 'vendor' package here to document the
|
||||
// file/package merging behavior of the reflection service.
|
||||
//
|
||||
// this file should be combined with vendor.proto to a single definition because
|
||||
// it's under the same 'vendor' package
|
||||
package vendor;
|
||||
|
||||
message CommonMessage {
|
||||
optional string common = 1;
|
||||
optional DependentMessage dependency = 2;
|
||||
|
||||
extensions 100 to 199;
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
syntax = "proto2";
|
||||
|
||||
package vendor.dependency;
|
||||
|
||||
message DependentMessage {
|
||||
optional string something = 1;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
syntax = "proto2";
|
||||
|
||||
package vendor;
|
||||
|
||||
import "./common.proto";
|
||||
import "./dependency/dependency.proto";
|
||||
|
||||
extend CommonMessage {
|
||||
optional bool ext = 101;
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// Original file: proto/grpc/reflection/v1/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* The error code and error message sent by the server when an error occurs.
|
||||
*/
|
||||
export interface ErrorResponse {
|
||||
/**
|
||||
* This field uses the error codes defined in grpc::StatusCode.
|
||||
*/
|
||||
'errorCode'?: (number);
|
||||
'errorMessage'?: (string);
|
||||
}
|
||||
|
||||
/**
|
||||
* The error code and error message sent by the server when an error occurs.
|
||||
*/
|
||||
export interface ErrorResponse__Output {
|
||||
/**
|
||||
* This field uses the error codes defined in grpc::StatusCode.
|
||||
*/
|
||||
'errorCode': (number);
|
||||
'errorMessage': (string);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
// Original file: proto/grpc/reflection/v1/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* A list of extension numbers sent by the server answering
|
||||
* all_extension_numbers_of_type request.
|
||||
*/
|
||||
export interface ExtensionNumberResponse {
|
||||
/**
|
||||
* Full name of the base type, including the package name. The format
|
||||
* is <package>.<type>
|
||||
*/
|
||||
'baseTypeName'?: (string);
|
||||
'extensionNumber'?: (number)[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of extension numbers sent by the server answering
|
||||
* all_extension_numbers_of_type request.
|
||||
*/
|
||||
export interface ExtensionNumberResponse__Output {
|
||||
/**
|
||||
* Full name of the base type, including the package name. The format
|
||||
* is <package>.<type>
|
||||
*/
|
||||
'baseTypeName': (string);
|
||||
'extensionNumber': (number)[];
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// Original file: proto/grpc/reflection/v1/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* The type name and extension number sent by the client when requesting
|
||||
* file_containing_extension.
|
||||
*/
|
||||
export interface ExtensionRequest {
|
||||
/**
|
||||
* Fully-qualified type name. The format should be <package>.<type>
|
||||
*/
|
||||
'containingType'?: (string);
|
||||
'extensionNumber'?: (number);
|
||||
}
|
||||
|
||||
/**
|
||||
* The type name and extension number sent by the client when requesting
|
||||
* file_containing_extension.
|
||||
*/
|
||||
export interface ExtensionRequest__Output {
|
||||
/**
|
||||
* Fully-qualified type name. The format should be <package>.<type>
|
||||
*/
|
||||
'containingType': (string);
|
||||
'extensionNumber': (number);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// Original file: proto/grpc/reflection/v1/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* Serialized FileDescriptorProto messages sent by the server answering
|
||||
* a file_by_filename, file_containing_symbol, or file_containing_extension
|
||||
* request.
|
||||
*/
|
||||
export interface FileDescriptorResponse {
|
||||
/**
|
||||
* Serialized FileDescriptorProto messages. We avoid taking a dependency on
|
||||
* descriptor.proto, which uses proto2 only features, by making them opaque
|
||||
* bytes instead.
|
||||
*/
|
||||
'fileDescriptorProto'?: (Buffer | Uint8Array | string)[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialized FileDescriptorProto messages sent by the server answering
|
||||
* a file_by_filename, file_containing_symbol, or file_containing_extension
|
||||
* request.
|
||||
*/
|
||||
export interface FileDescriptorResponse__Output {
|
||||
/**
|
||||
* Serialized FileDescriptorProto messages. We avoid taking a dependency on
|
||||
* descriptor.proto, which uses proto2 only features, by making them opaque
|
||||
* bytes instead.
|
||||
*/
|
||||
'fileDescriptorProto': (Uint8Array)[];
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
// Original file: proto/grpc/reflection/v1/reflection.proto
|
||||
|
||||
import type { ServiceResponse as _grpc_reflection_v1_ServiceResponse, ServiceResponse__Output as _grpc_reflection_v1_ServiceResponse__Output } from '../../../grpc/reflection/v1/ServiceResponse';
|
||||
|
||||
/**
|
||||
* A list of ServiceResponse sent by the server answering list_services request.
|
||||
*/
|
||||
export interface ListServiceResponse {
|
||||
/**
|
||||
* The information of each service may be expanded in the future, so we use
|
||||
* ServiceResponse message to encapsulate it.
|
||||
*/
|
||||
'service'?: (_grpc_reflection_v1_ServiceResponse)[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of ServiceResponse sent by the server answering list_services request.
|
||||
*/
|
||||
export interface ListServiceResponse__Output {
|
||||
/**
|
||||
* The information of each service may be expanded in the future, so we use
|
||||
* ServiceResponse message to encapsulate it.
|
||||
*/
|
||||
'service': (_grpc_reflection_v1_ServiceResponse__Output)[];
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
// Original file: proto/grpc/reflection/v1/reflection.proto
|
||||
|
||||
import type { MethodDefinition } from '@grpc/proto-loader'
|
||||
import type { ServerReflectionRequest as _grpc_reflection_v1_ServerReflectionRequest, ServerReflectionRequest__Output as _grpc_reflection_v1_ServerReflectionRequest__Output } from '../../../grpc/reflection/v1/ServerReflectionRequest';
|
||||
import type { ServerReflectionResponse as _grpc_reflection_v1_ServerReflectionResponse, ServerReflectionResponse__Output as _grpc_reflection_v1_ServerReflectionResponse__Output } from '../../../grpc/reflection/v1/ServerReflectionResponse';
|
||||
|
||||
export interface ServerReflectionDefinition {
|
||||
ServerReflectionInfo: MethodDefinition<_grpc_reflection_v1_ServerReflectionRequest, _grpc_reflection_v1_ServerReflectionResponse, _grpc_reflection_v1_ServerReflectionRequest__Output, _grpc_reflection_v1_ServerReflectionResponse__Output>
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
// Original file: proto/grpc/reflection/v1/reflection.proto
|
||||
|
||||
import type { ExtensionRequest as _grpc_reflection_v1_ExtensionRequest, ExtensionRequest__Output as _grpc_reflection_v1_ExtensionRequest__Output } from '../../../grpc/reflection/v1/ExtensionRequest';
|
||||
|
||||
/**
|
||||
* The message sent by the client when calling ServerReflectionInfo method.
|
||||
*/
|
||||
export interface ServerReflectionRequest {
|
||||
'host'?: (string);
|
||||
/**
|
||||
* Find a proto file by the file name.
|
||||
*/
|
||||
'fileByFilename'?: (string);
|
||||
/**
|
||||
* Find the proto file that declares the given fully-qualified symbol name.
|
||||
* This field should be a fully-qualified symbol name
|
||||
* (e.g. <package>.<service>[.<method>] or <package>.<type>).
|
||||
*/
|
||||
'fileContainingSymbol'?: (string);
|
||||
/**
|
||||
* Find the proto file which defines an extension extending the given
|
||||
* message type with the given field number.
|
||||
*/
|
||||
'fileContainingExtension'?: (_grpc_reflection_v1_ExtensionRequest | null);
|
||||
/**
|
||||
* Finds the tag numbers used by all known extensions of the given message
|
||||
* type, and appends them to ExtensionNumberResponse in an undefined order.
|
||||
* Its corresponding method is best-effort: it's not guaranteed that the
|
||||
* reflection service will implement this method, and it's not guaranteed
|
||||
* that this method will provide all extensions. Returns
|
||||
* StatusCode::UNIMPLEMENTED if it's not implemented.
|
||||
* This field should be a fully-qualified type name. The format is
|
||||
* <package>.<type>
|
||||
*/
|
||||
'allExtensionNumbersOfType'?: (string);
|
||||
/**
|
||||
* List the full names of registered services. The content will not be
|
||||
* checked.
|
||||
*/
|
||||
'listServices'?: (string);
|
||||
/**
|
||||
* To use reflection service, the client should set one of the following
|
||||
* fields in message_request. The server distinguishes requests by their
|
||||
* defined field and then handles them using corresponding methods.
|
||||
*/
|
||||
'messageRequest'?: "fileByFilename"|"fileContainingSymbol"|"fileContainingExtension"|"allExtensionNumbersOfType"|"listServices";
|
||||
}
|
||||
|
||||
/**
|
||||
* The message sent by the client when calling ServerReflectionInfo method.
|
||||
*/
|
||||
export interface ServerReflectionRequest__Output {
|
||||
'host': (string);
|
||||
/**
|
||||
* Find a proto file by the file name.
|
||||
*/
|
||||
'fileByFilename'?: (string);
|
||||
/**
|
||||
* Find the proto file that declares the given fully-qualified symbol name.
|
||||
* This field should be a fully-qualified symbol name
|
||||
* (e.g. <package>.<service>[.<method>] or <package>.<type>).
|
||||
*/
|
||||
'fileContainingSymbol'?: (string);
|
||||
/**
|
||||
* Find the proto file which defines an extension extending the given
|
||||
* message type with the given field number.
|
||||
*/
|
||||
'fileContainingExtension'?: (_grpc_reflection_v1_ExtensionRequest__Output | null);
|
||||
/**
|
||||
* Finds the tag numbers used by all known extensions of the given message
|
||||
* type, and appends them to ExtensionNumberResponse in an undefined order.
|
||||
* Its corresponding method is best-effort: it's not guaranteed that the
|
||||
* reflection service will implement this method, and it's not guaranteed
|
||||
* that this method will provide all extensions. Returns
|
||||
* StatusCode::UNIMPLEMENTED if it's not implemented.
|
||||
* This field should be a fully-qualified type name. The format is
|
||||
* <package>.<type>
|
||||
*/
|
||||
'allExtensionNumbersOfType'?: (string);
|
||||
/**
|
||||
* List the full names of registered services. The content will not be
|
||||
* checked.
|
||||
*/
|
||||
'listServices'?: (string);
|
||||
/**
|
||||
* To use reflection service, the client should set one of the following
|
||||
* fields in message_request. The server distinguishes requests by their
|
||||
* defined field and then handles them using corresponding methods.
|
||||
*/
|
||||
'messageRequest': "fileByFilename"|"fileContainingSymbol"|"fileContainingExtension"|"allExtensionNumbersOfType"|"listServices";
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
// Original file: proto/grpc/reflection/v1/reflection.proto
|
||||
|
||||
import type { ServerReflectionRequest as _grpc_reflection_v1_ServerReflectionRequest, ServerReflectionRequest__Output as _grpc_reflection_v1_ServerReflectionRequest__Output } from '../../../grpc/reflection/v1/ServerReflectionRequest';
|
||||
import type { FileDescriptorResponse as _grpc_reflection_v1_FileDescriptorResponse, FileDescriptorResponse__Output as _grpc_reflection_v1_FileDescriptorResponse__Output } from '../../../grpc/reflection/v1/FileDescriptorResponse';
|
||||
import type { ExtensionNumberResponse as _grpc_reflection_v1_ExtensionNumberResponse, ExtensionNumberResponse__Output as _grpc_reflection_v1_ExtensionNumberResponse__Output } from '../../../grpc/reflection/v1/ExtensionNumberResponse';
|
||||
import type { ListServiceResponse as _grpc_reflection_v1_ListServiceResponse, ListServiceResponse__Output as _grpc_reflection_v1_ListServiceResponse__Output } from '../../../grpc/reflection/v1/ListServiceResponse';
|
||||
import type { ErrorResponse as _grpc_reflection_v1_ErrorResponse, ErrorResponse__Output as _grpc_reflection_v1_ErrorResponse__Output } from '../../../grpc/reflection/v1/ErrorResponse';
|
||||
|
||||
/**
|
||||
* The message sent by the server to answer ServerReflectionInfo method.
|
||||
*/
|
||||
export interface ServerReflectionResponse {
|
||||
'validHost'?: (string);
|
||||
'originalRequest'?: (_grpc_reflection_v1_ServerReflectionRequest | null);
|
||||
/**
|
||||
* 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
|
||||
* 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'?: (_grpc_reflection_v1_FileDescriptorResponse | null);
|
||||
/**
|
||||
* This message is used to answer all_extension_numbers_of_type requests.
|
||||
*/
|
||||
'allExtensionNumbersResponse'?: (_grpc_reflection_v1_ExtensionNumberResponse | null);
|
||||
/**
|
||||
* This message is used to answer list_services requests.
|
||||
*/
|
||||
'listServicesResponse'?: (_grpc_reflection_v1_ListServiceResponse | null);
|
||||
/**
|
||||
* This message is used when an error occurs.
|
||||
*/
|
||||
'errorResponse'?: (_grpc_reflection_v1_ErrorResponse | null);
|
||||
/**
|
||||
* The server sets one of the following fields according to the message_request
|
||||
* in the request.
|
||||
*/
|
||||
'messageResponse'?: "fileDescriptorResponse"|"allExtensionNumbersResponse"|"listServicesResponse"|"errorResponse";
|
||||
}
|
||||
|
||||
/**
|
||||
* The message sent by the server to answer ServerReflectionInfo method.
|
||||
*/
|
||||
export interface ServerReflectionResponse__Output {
|
||||
'validHost': (string);
|
||||
'originalRequest': (_grpc_reflection_v1_ServerReflectionRequest__Output | null);
|
||||
/**
|
||||
* 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
|
||||
* 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'?: (_grpc_reflection_v1_FileDescriptorResponse__Output | null);
|
||||
/**
|
||||
* This message is used to answer all_extension_numbers_of_type requests.
|
||||
*/
|
||||
'allExtensionNumbersResponse'?: (_grpc_reflection_v1_ExtensionNumberResponse__Output | null);
|
||||
/**
|
||||
* This message is used to answer list_services requests.
|
||||
*/
|
||||
'listServicesResponse'?: (_grpc_reflection_v1_ListServiceResponse__Output | null);
|
||||
/**
|
||||
* This message is used when an error occurs.
|
||||
*/
|
||||
'errorResponse'?: (_grpc_reflection_v1_ErrorResponse__Output | null);
|
||||
/**
|
||||
* The server sets one of the following fields according to the message_request
|
||||
* in the request.
|
||||
*/
|
||||
'messageResponse': "fileDescriptorResponse"|"allExtensionNumbersResponse"|"listServicesResponse"|"errorResponse";
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// Original file: proto/grpc/reflection/v1/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* The information of a single service used by ListServiceResponse to answer
|
||||
* list_services request.
|
||||
*/
|
||||
export interface ServiceResponse {
|
||||
/**
|
||||
* Full name of a registered service, including its package name. The format
|
||||
* is <package>.<service>
|
||||
*/
|
||||
'name'?: (string);
|
||||
}
|
||||
|
||||
/**
|
||||
* The information of a single service used by ListServiceResponse to answer
|
||||
* list_services request.
|
||||
*/
|
||||
export interface ServiceResponse__Output {
|
||||
/**
|
||||
* Full name of a registered service, including its package name. The format
|
||||
* is <package>.<service>
|
||||
*/
|
||||
'name': (string);
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
// Original file: proto/grpc/reflection/v1alpha/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* The error code and error message sent by the server when an error occurs.
|
||||
*/
|
||||
export interface ErrorResponse {
|
||||
/**
|
||||
* This field uses the error codes defined in grpc::StatusCode.
|
||||
*/
|
||||
'errorCode'?: (number);
|
||||
'errorMessage'?: (string);
|
||||
}
|
||||
|
||||
/**
|
||||
* The error code and error message sent by the server when an error occurs.
|
||||
*/
|
||||
export interface ErrorResponse__Output {
|
||||
/**
|
||||
* This field uses the error codes defined in grpc::StatusCode.
|
||||
*/
|
||||
'errorCode': (number);
|
||||
'errorMessage': (string);
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
// Original file: proto/grpc/reflection/v1alpha/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* A list of extension numbers sent by the server answering
|
||||
* all_extension_numbers_of_type request.
|
||||
*/
|
||||
export interface ExtensionNumberResponse {
|
||||
/**
|
||||
* Full name of the base type, including the package name. The format
|
||||
* is <package>.<type>
|
||||
*/
|
||||
'baseTypeName'?: (string);
|
||||
'extensionNumber'?: (number)[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of extension numbers sent by the server answering
|
||||
* all_extension_numbers_of_type request.
|
||||
*/
|
||||
export interface ExtensionNumberResponse__Output {
|
||||
/**
|
||||
* Full name of the base type, including the package name. The format
|
||||
* is <package>.<type>
|
||||
*/
|
||||
'baseTypeName': (string);
|
||||
'extensionNumber': (number)[];
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// Original file: proto/grpc/reflection/v1alpha/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* The type name and extension number sent by the client when requesting
|
||||
* file_containing_extension.
|
||||
*/
|
||||
export interface ExtensionRequest {
|
||||
/**
|
||||
* Fully-qualified type name. The format should be <package>.<type>
|
||||
*/
|
||||
'containingType'?: (string);
|
||||
'extensionNumber'?: (number);
|
||||
}
|
||||
|
||||
/**
|
||||
* The type name and extension number sent by the client when requesting
|
||||
* file_containing_extension.
|
||||
*/
|
||||
export interface ExtensionRequest__Output {
|
||||
/**
|
||||
* Fully-qualified type name. The format should be <package>.<type>
|
||||
*/
|
||||
'containingType': (string);
|
||||
'extensionNumber': (number);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
// Original file: proto/grpc/reflection/v1alpha/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* Serialized FileDescriptorProto messages sent by the server answering
|
||||
* a file_by_filename, file_containing_symbol, or file_containing_extension
|
||||
* request.
|
||||
*/
|
||||
export interface FileDescriptorResponse {
|
||||
/**
|
||||
* Serialized FileDescriptorProto messages. We avoid taking a dependency on
|
||||
* descriptor.proto, which uses proto2 only features, by making them opaque
|
||||
* bytes instead.
|
||||
*/
|
||||
'fileDescriptorProto'?: (Buffer | Uint8Array | string)[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialized FileDescriptorProto messages sent by the server answering
|
||||
* a file_by_filename, file_containing_symbol, or file_containing_extension
|
||||
* request.
|
||||
*/
|
||||
export interface FileDescriptorResponse__Output {
|
||||
/**
|
||||
* Serialized FileDescriptorProto messages. We avoid taking a dependency on
|
||||
* descriptor.proto, which uses proto2 only features, by making them opaque
|
||||
* bytes instead.
|
||||
*/
|
||||
'fileDescriptorProto': (Uint8Array)[];
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
// Original file: proto/grpc/reflection/v1alpha/reflection.proto
|
||||
|
||||
import type { ServiceResponse as _grpc_reflection_v1alpha_ServiceResponse, ServiceResponse__Output as _grpc_reflection_v1alpha_ServiceResponse__Output } from '../../../grpc/reflection/v1alpha/ServiceResponse';
|
||||
|
||||
/**
|
||||
* A list of ServiceResponse sent by the server answering list_services request.
|
||||
*/
|
||||
export interface ListServiceResponse {
|
||||
/**
|
||||
* The information of each service may be expanded in the future, so we use
|
||||
* ServiceResponse message to encapsulate it.
|
||||
*/
|
||||
'service'?: (_grpc_reflection_v1alpha_ServiceResponse)[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of ServiceResponse sent by the server answering list_services request.
|
||||
*/
|
||||
export interface ListServiceResponse__Output {
|
||||
/**
|
||||
* The information of each service may be expanded in the future, so we use
|
||||
* ServiceResponse message to encapsulate it.
|
||||
*/
|
||||
'service': (_grpc_reflection_v1alpha_ServiceResponse__Output)[];
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
// Original file: proto/grpc/reflection/v1alpha/reflection.proto
|
||||
|
||||
import type { MethodDefinition } from '@grpc/proto-loader'
|
||||
import type { ServerReflectionRequest as _grpc_reflection_v1alpha_ServerReflectionRequest, ServerReflectionRequest__Output as _grpc_reflection_v1alpha_ServerReflectionRequest__Output } from '../../../grpc/reflection/v1alpha/ServerReflectionRequest';
|
||||
import type { ServerReflectionResponse as _grpc_reflection_v1alpha_ServerReflectionResponse, ServerReflectionResponse__Output as _grpc_reflection_v1alpha_ServerReflectionResponse__Output } from '../../../grpc/reflection/v1alpha/ServerReflectionResponse';
|
||||
|
||||
export interface ServerReflectionDefinition {
|
||||
ServerReflectionInfo: MethodDefinition<_grpc_reflection_v1alpha_ServerReflectionRequest, _grpc_reflection_v1alpha_ServerReflectionResponse, _grpc_reflection_v1alpha_ServerReflectionRequest__Output, _grpc_reflection_v1alpha_ServerReflectionResponse__Output>
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
// Original file: proto/grpc/reflection/v1alpha/reflection.proto
|
||||
|
||||
import type { ExtensionRequest as _grpc_reflection_v1alpha_ExtensionRequest, ExtensionRequest__Output as _grpc_reflection_v1alpha_ExtensionRequest__Output } from '../../../grpc/reflection/v1alpha/ExtensionRequest';
|
||||
|
||||
/**
|
||||
* The message sent by the client when calling ServerReflectionInfo method.
|
||||
*/
|
||||
export interface ServerReflectionRequest {
|
||||
'host'?: (string);
|
||||
/**
|
||||
* Find a proto file by the file name.
|
||||
*/
|
||||
'fileByFilename'?: (string);
|
||||
/**
|
||||
* Find the proto file that declares the given fully-qualified symbol name.
|
||||
* This field should be a fully-qualified symbol name
|
||||
* (e.g. <package>.<service>[.<method>] or <package>.<type>).
|
||||
*/
|
||||
'fileContainingSymbol'?: (string);
|
||||
/**
|
||||
* Find the proto file which defines an extension extending the given
|
||||
* message type with the given field number.
|
||||
*/
|
||||
'fileContainingExtension'?: (_grpc_reflection_v1alpha_ExtensionRequest | null);
|
||||
/**
|
||||
* Finds the tag numbers used by all known extensions of the given message
|
||||
* type, and appends them to ExtensionNumberResponse in an undefined order.
|
||||
* Its corresponding method is best-effort: it's not guaranteed that the
|
||||
* reflection service will implement this method, and it's not guaranteed
|
||||
* that this method will provide all extensions. Returns
|
||||
* StatusCode::UNIMPLEMENTED if it's not implemented.
|
||||
* This field should be a fully-qualified type name. The format is
|
||||
* <package>.<type>
|
||||
*/
|
||||
'allExtensionNumbersOfType'?: (string);
|
||||
/**
|
||||
* List the full names of registered services. The content will not be
|
||||
* checked.
|
||||
*/
|
||||
'listServices'?: (string);
|
||||
/**
|
||||
* To use reflection service, the client should set one of the following
|
||||
* fields in message_request. The server distinguishes requests by their
|
||||
* defined field and then handles them using corresponding methods.
|
||||
*/
|
||||
'messageRequest'?: "fileByFilename"|"fileContainingSymbol"|"fileContainingExtension"|"allExtensionNumbersOfType"|"listServices";
|
||||
}
|
||||
|
||||
/**
|
||||
* The message sent by the client when calling ServerReflectionInfo method.
|
||||
*/
|
||||
export interface ServerReflectionRequest__Output {
|
||||
'host': (string);
|
||||
/**
|
||||
* Find a proto file by the file name.
|
||||
*/
|
||||
'fileByFilename'?: (string);
|
||||
/**
|
||||
* Find the proto file that declares the given fully-qualified symbol name.
|
||||
* This field should be a fully-qualified symbol name
|
||||
* (e.g. <package>.<service>[.<method>] or <package>.<type>).
|
||||
*/
|
||||
'fileContainingSymbol'?: (string);
|
||||
/**
|
||||
* Find the proto file which defines an extension extending the given
|
||||
* message type with the given field number.
|
||||
*/
|
||||
'fileContainingExtension'?: (_grpc_reflection_v1alpha_ExtensionRequest__Output | null);
|
||||
/**
|
||||
* Finds the tag numbers used by all known extensions of the given message
|
||||
* type, and appends them to ExtensionNumberResponse in an undefined order.
|
||||
* Its corresponding method is best-effort: it's not guaranteed that the
|
||||
* reflection service will implement this method, and it's not guaranteed
|
||||
* that this method will provide all extensions. Returns
|
||||
* StatusCode::UNIMPLEMENTED if it's not implemented.
|
||||
* This field should be a fully-qualified type name. The format is
|
||||
* <package>.<type>
|
||||
*/
|
||||
'allExtensionNumbersOfType'?: (string);
|
||||
/**
|
||||
* List the full names of registered services. The content will not be
|
||||
* checked.
|
||||
*/
|
||||
'listServices'?: (string);
|
||||
/**
|
||||
* To use reflection service, the client should set one of the following
|
||||
* fields in message_request. The server distinguishes requests by their
|
||||
* defined field and then handles them using corresponding methods.
|
||||
*/
|
||||
'messageRequest': "fileByFilename"|"fileContainingSymbol"|"fileContainingExtension"|"allExtensionNumbersOfType"|"listServices";
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
// Original file: proto/grpc/reflection/v1alpha/reflection.proto
|
||||
|
||||
import type { ServerReflectionRequest as _grpc_reflection_v1alpha_ServerReflectionRequest, ServerReflectionRequest__Output as _grpc_reflection_v1alpha_ServerReflectionRequest__Output } from '../../../grpc/reflection/v1alpha/ServerReflectionRequest';
|
||||
import type { FileDescriptorResponse as _grpc_reflection_v1alpha_FileDescriptorResponse, FileDescriptorResponse__Output as _grpc_reflection_v1alpha_FileDescriptorResponse__Output } from '../../../grpc/reflection/v1alpha/FileDescriptorResponse';
|
||||
import type { ExtensionNumberResponse as _grpc_reflection_v1alpha_ExtensionNumberResponse, ExtensionNumberResponse__Output as _grpc_reflection_v1alpha_ExtensionNumberResponse__Output } from '../../../grpc/reflection/v1alpha/ExtensionNumberResponse';
|
||||
import type { ListServiceResponse as _grpc_reflection_v1alpha_ListServiceResponse, ListServiceResponse__Output as _grpc_reflection_v1alpha_ListServiceResponse__Output } from '../../../grpc/reflection/v1alpha/ListServiceResponse';
|
||||
import type { ErrorResponse as _grpc_reflection_v1alpha_ErrorResponse, ErrorResponse__Output as _grpc_reflection_v1alpha_ErrorResponse__Output } from '../../../grpc/reflection/v1alpha/ErrorResponse';
|
||||
|
||||
/**
|
||||
* The message sent by the server to answer ServerReflectionInfo method.
|
||||
*/
|
||||
export interface ServerReflectionResponse {
|
||||
'validHost'?: (string);
|
||||
'originalRequest'?: (_grpc_reflection_v1alpha_ServerReflectionRequest | null);
|
||||
/**
|
||||
* 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
|
||||
* 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'?: (_grpc_reflection_v1alpha_FileDescriptorResponse | null);
|
||||
/**
|
||||
* This message is used to answer all_extension_numbers_of_type requst.
|
||||
*/
|
||||
'allExtensionNumbersResponse'?: (_grpc_reflection_v1alpha_ExtensionNumberResponse | null);
|
||||
/**
|
||||
* This message is used to answer list_services request.
|
||||
*/
|
||||
'listServicesResponse'?: (_grpc_reflection_v1alpha_ListServiceResponse | null);
|
||||
/**
|
||||
* This message is used when an error occurs.
|
||||
*/
|
||||
'errorResponse'?: (_grpc_reflection_v1alpha_ErrorResponse | null);
|
||||
/**
|
||||
* The server set one of the following fields accroding to the message_request
|
||||
* in the request.
|
||||
*/
|
||||
'messageResponse'?: "fileDescriptorResponse"|"allExtensionNumbersResponse"|"listServicesResponse"|"errorResponse";
|
||||
}
|
||||
|
||||
/**
|
||||
* The message sent by the server to answer ServerReflectionInfo method.
|
||||
*/
|
||||
export interface ServerReflectionResponse__Output {
|
||||
'validHost': (string);
|
||||
'originalRequest': (_grpc_reflection_v1alpha_ServerReflectionRequest__Output | null);
|
||||
/**
|
||||
* 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
|
||||
* 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'?: (_grpc_reflection_v1alpha_FileDescriptorResponse__Output | null);
|
||||
/**
|
||||
* This message is used to answer all_extension_numbers_of_type requst.
|
||||
*/
|
||||
'allExtensionNumbersResponse'?: (_grpc_reflection_v1alpha_ExtensionNumberResponse__Output | null);
|
||||
/**
|
||||
* This message is used to answer list_services request.
|
||||
*/
|
||||
'listServicesResponse'?: (_grpc_reflection_v1alpha_ListServiceResponse__Output | null);
|
||||
/**
|
||||
* This message is used when an error occurs.
|
||||
*/
|
||||
'errorResponse'?: (_grpc_reflection_v1alpha_ErrorResponse__Output | null);
|
||||
/**
|
||||
* The server set one of the following fields accroding to the message_request
|
||||
* in the request.
|
||||
*/
|
||||
'messageResponse': "fileDescriptorResponse"|"allExtensionNumbersResponse"|"listServicesResponse"|"errorResponse";
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// Original file: proto/grpc/reflection/v1alpha/reflection.proto
|
||||
|
||||
|
||||
/**
|
||||
* The information of a single service used by ListServiceResponse to answer
|
||||
* list_services request.
|
||||
*/
|
||||
export interface ServiceResponse {
|
||||
/**
|
||||
* Full name of a registered service, including its package name. The format
|
||||
* is <package>.<service>
|
||||
*/
|
||||
'name'?: (string);
|
||||
}
|
||||
|
||||
/**
|
||||
* The information of a single service used by ListServiceResponse to answer
|
||||
* list_services request.
|
||||
*/
|
||||
export interface ServiceResponse__Output {
|
||||
/**
|
||||
* Full name of a registered service, including its package name. The format
|
||||
* is <package>.<service>
|
||||
*/
|
||||
'name': (string);
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
import {
|
||||
DescriptorProto,
|
||||
EnumDescriptorProto,
|
||||
EnumValueDescriptorProto,
|
||||
FieldDescriptorProto,
|
||||
FileDescriptorProto,
|
||||
MethodDescriptorProto,
|
||||
OneofDescriptorProto,
|
||||
ServiceDescriptorProto,
|
||||
} from 'google-protobuf/google/protobuf/descriptor_pb';
|
||||
|
||||
/** A set of functions for operating on protobuf objects as we visit them in a traversal */
|
||||
interface Visitor {
|
||||
field?: (fqn: string, file: FileDescriptorProto, field: FieldDescriptorProto) => void;
|
||||
extension?: (fqn: string, file: FileDescriptorProto, extension: FieldDescriptorProto) => void;
|
||||
oneOf?: (fqn: string, file: FileDescriptorProto, decl: OneofDescriptorProto) => void;
|
||||
message?: (fqn: string, file: FileDescriptorProto, msg: DescriptorProto) => void;
|
||||
enum?: (fqn: string, file: FileDescriptorProto, msg: EnumDescriptorProto) => void;
|
||||
enumValue?: (fqn: string, file: FileDescriptorProto, msg: EnumValueDescriptorProto) => void;
|
||||
service?: (fqn: string, file: FileDescriptorProto, msg: ServiceDescriptorProto) => void;
|
||||
method?: (fqn: string, file: FileDescriptorProto, method: MethodDescriptorProto) => void;
|
||||
}
|
||||
|
||||
/** Visit each node in a protobuf file and perform an operation on it
|
||||
*
|
||||
* This is useful because protocol buffers has nested objects so if we need to
|
||||
* traverse them multiple times then we don't want to duplicate that traversal
|
||||
* logic
|
||||
*
|
||||
* @see Visitor for the interface to interact with the nodes
|
||||
*/
|
||||
export const visit = (file: FileDescriptorProto, visitor: Visitor): void => {
|
||||
const processField = (prefix: string, file: FileDescriptorProto, field: FieldDescriptorProto) => {
|
||||
const fqn = `${prefix}.${field.getName()}`;
|
||||
if (visitor.field) {
|
||||
visitor.field(fqn, file, field);
|
||||
}
|
||||
};
|
||||
|
||||
const processExtension = (
|
||||
prefix: string,
|
||||
file: FileDescriptorProto,
|
||||
ext: FieldDescriptorProto,
|
||||
) => {
|
||||
const fqn = `${prefix}.${ext.getName()}`;
|
||||
if (visitor.extension) {
|
||||
visitor.extension(fqn, file, ext);
|
||||
}
|
||||
};
|
||||
|
||||
const processOneOf = (prefix: string, file: FileDescriptorProto, decl: OneofDescriptorProto) => {
|
||||
const fqn = `${prefix}.${decl.getName()}`;
|
||||
if (visitor.oneOf) {
|
||||
visitor.oneOf(fqn, file, decl);
|
||||
}
|
||||
};
|
||||
|
||||
const processEnum = (prefix: string, file: FileDescriptorProto, decl: EnumDescriptorProto) => {
|
||||
const fqn = `${prefix}.${decl.getName()}`;
|
||||
|
||||
if (visitor.enum) {
|
||||
visitor.enum(fqn, file, decl);
|
||||
}
|
||||
|
||||
decl.getValueList().forEach((value) => {
|
||||
const valueFqn = `${fqn}.${value.getName()}`;
|
||||
if (visitor.enumValue) {
|
||||
visitor.enumValue(valueFqn, file, value);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const processMessage = (prefix: string, file: FileDescriptorProto, msg: DescriptorProto) => {
|
||||
const fqn = `${prefix}.${msg.getName()}`;
|
||||
if (visitor.message) {
|
||||
visitor.message(fqn, file, msg);
|
||||
}
|
||||
|
||||
msg.getNestedTypeList().forEach((type) => processMessage(fqn, file, type));
|
||||
msg.getEnumTypeList().forEach((type) => processEnum(fqn, file, type));
|
||||
msg.getFieldList().forEach((field) => processField(fqn, file, field));
|
||||
msg.getOneofDeclList().forEach((decl) => processOneOf(fqn, file, decl));
|
||||
msg.getExtensionList().forEach((ext) => processExtension(fqn, file, ext));
|
||||
};
|
||||
|
||||
const processService = (
|
||||
prefix: string,
|
||||
file: FileDescriptorProto,
|
||||
service: ServiceDescriptorProto,
|
||||
) => {
|
||||
const fqn = `${prefix}.${service.getName()}`;
|
||||
if (visitor.service) {
|
||||
visitor.service(fqn, file, service);
|
||||
}
|
||||
|
||||
service.getMethodList().forEach((method) => {
|
||||
const methodFqn = `${fqn}.${method.getName()}`;
|
||||
if (visitor.method) {
|
||||
visitor.method(methodFqn, file, method);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const packageName = file.getPackage();
|
||||
file.getEnumTypeList().forEach((type) => processEnum(packageName, file, type));
|
||||
file.getMessageTypeList().forEach((type) => processMessage(packageName, file, type));
|
||||
file.getServiceList().forEach((service) => processService(packageName, file, service));
|
||||
|
||||
file.getExtensionList().forEach((ext) => processExtension(packageName, file, ext));
|
||||
};
|
|
@ -0,0 +1,252 @@
|
|||
import {
|
||||
FileDescriptorProto,
|
||||
FileDescriptorSet,
|
||||
} from 'google-protobuf/google/protobuf/descriptor_pb';
|
||||
|
||||
import * as grpc from '@grpc/grpc-js';
|
||||
import * as protoLoader from '@grpc/proto-loader';
|
||||
|
||||
import { ExtensionNumberResponse__Output } from './generated/grpc/reflection/v1/ExtensionNumberResponse';
|
||||
import { FileDescriptorResponse__Output } from './generated/grpc/reflection/v1/FileDescriptorResponse';
|
||||
import { ListServiceResponse__Output } from './generated/grpc/reflection/v1/ListServiceResponse';
|
||||
import { visit } from './protobuf-visitor';
|
||||
import { scope } from './utils';
|
||||
|
||||
export class ReflectionError extends Error {
|
||||
constructor(
|
||||
readonly statusCode: grpc.status,
|
||||
readonly message: string,
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/** Analyzes a gRPC server and exposes methods to reflect on it
|
||||
*
|
||||
* NOTE: the files returned by this service may not match the handwritten ones 1:1.
|
||||
* This is because proto-loader reorients files based on their package definition,
|
||||
* combining any that have the same package.
|
||||
*
|
||||
* For example: if files 'a.proto' and 'b.proto' are both for the same package 'c' then
|
||||
* we will always return a reference to a combined 'c.proto' instead of the 2 files.
|
||||
*/
|
||||
export class ReflectionV1Implementation {
|
||||
|
||||
/** The full list of proto files (including imported deps) that the gRPC server includes */
|
||||
private fileDescriptorSet = new FileDescriptorSet();
|
||||
|
||||
/** An index of proto files by file name (eg. 'sample.proto') */
|
||||
private fileNameIndex: Record<string, FileDescriptorProto> = {};
|
||||
|
||||
/** An index of proto files by type extension relationship
|
||||
*
|
||||
* extensionIndex[<pkg>.<msg>][<field#>] contains a reference to the file containing an
|
||||
* extension for the type "<pkg>.<msg>" and field number "<field#>"
|
||||
*/
|
||||
private extensionIndex: Record<string, Record<number, FileDescriptorProto>> = {};
|
||||
|
||||
/** An index of fully qualified symbol names (eg. 'sample.Message') to the files that contain them */
|
||||
private symbolMap: Record<string, FileDescriptorProto> = {};
|
||||
|
||||
constructor(root: protoLoader.PackageDefinition) {
|
||||
Object.values(root).forEach(({ fileDescriptorProtos }) => {
|
||||
// Add file descriptors to the FileDescriptorSet.
|
||||
// We use the Array check here because a ServiceDefinition could have a method named the same thing
|
||||
if (Array.isArray(fileDescriptorProtos)) {
|
||||
fileDescriptorProtos.forEach((bin) => {
|
||||
const proto = FileDescriptorProto.deserializeBinary(bin);
|
||||
const isFileInSet = this.fileDescriptorSet
|
||||
.getFileList()
|
||||
.map((f) => f.getName())
|
||||
.includes(proto.getName());
|
||||
if (!isFileInSet) {
|
||||
this.fileDescriptorSet.addFile(proto);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.fileNameIndex = Object.fromEntries(
|
||||
this.fileDescriptorSet.getFileList().map((f) => [f.getName(), f]),
|
||||
);
|
||||
|
||||
// Pass 1: Index Values
|
||||
const index = (fqn: string, file: FileDescriptorProto) => (this.symbolMap[fqn] = file);
|
||||
this.fileDescriptorSet.getFileList().forEach((file) =>
|
||||
visit(file, {
|
||||
field: index,
|
||||
oneOf: index,
|
||||
message: index,
|
||||
service: index,
|
||||
method: index,
|
||||
enum: index,
|
||||
enumValue: index,
|
||||
extension: (fqn, file, ext) => {
|
||||
index(fqn, file);
|
||||
|
||||
const extendeeName = ext.getExtendee();
|
||||
this.extensionIndex[extendeeName] = {
|
||||
...(this.extensionIndex[extendeeName] || {}),
|
||||
[ext.getNumber()]: file,
|
||||
};
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
// Pass 2: Link References To Values
|
||||
const addReference = (ref: string, sourceFile: FileDescriptorProto, pkgScope: string) => {
|
||||
if (!ref) {
|
||||
return; // nothing to do
|
||||
}
|
||||
|
||||
let referencedFile: FileDescriptorProto | null = null;
|
||||
if (ref.startsWith('.')) {
|
||||
// absolute reference -- just remove the leading '.' and use the ref directly
|
||||
referencedFile = this.symbolMap[ref.replace(/^\./, '')];
|
||||
} else {
|
||||
// relative reference -- need to seek upwards up the current package scope until we find it
|
||||
let pkg = pkgScope;
|
||||
while (pkg && !referencedFile) {
|
||||
referencedFile = this.symbolMap[`${pkg}.${ref}`];
|
||||
pkg = scope(pkg);
|
||||
}
|
||||
|
||||
// if we didn't find anything then try just a FQN lookup
|
||||
if (!referencedFile) {
|
||||
referencedFile = this.symbolMap[ref];
|
||||
}
|
||||
}
|
||||
|
||||
if (!referencedFile) {
|
||||
console.warn(`Could not find file associated with reference ${ref}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (referencedFile !== sourceFile) {
|
||||
sourceFile.addDependency(referencedFile.getName());
|
||||
}
|
||||
};
|
||||
|
||||
this.fileDescriptorSet.getFileList().forEach((file) =>
|
||||
visit(file, {
|
||||
field: (fqn, file, field) => addReference(field.getTypeName(), file, scope(fqn)),
|
||||
extension: (fqn, file, ext) => addReference(ext.getTypeName(), file, scope(fqn)),
|
||||
method: (fqn, file, method) => {
|
||||
addReference(method.getInputType(), file, scope(fqn));
|
||||
addReference(method.getOutputType(), file, scope(fqn));
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/** List the full names of registered gRPC services
|
||||
*
|
||||
* note: the spec is unclear as to what the 'listServices' param can be; most
|
||||
* clients seem to only pass '*' but unsure if this should behave like a
|
||||
* filter. Until we know how this should behave with different inputs this
|
||||
* just always returns *all* services.
|
||||
*
|
||||
* @returns full-qualified service names (eg. 'sample.SampleService')
|
||||
*/
|
||||
listServices(listServices: string): ListServiceResponse__Output {
|
||||
const services = this.fileDescriptorSet
|
||||
.getFileList()
|
||||
.map((file) =>
|
||||
file.getServiceList().map((service) => `${file.getPackage()}.${service.getName()}`),
|
||||
)
|
||||
.flat();
|
||||
|
||||
return { service: services.map((service) => ({ name: service })) };
|
||||
}
|
||||
|
||||
/** Find the proto file(s) that declares the given fully-qualified symbol name
|
||||
*
|
||||
* @param symbol fully-qualified name of the symbol to lookup
|
||||
* (e.g. package.service[.method] or package.type)
|
||||
*
|
||||
* @returns descriptors of the file which contains this symbol and its imports
|
||||
*/
|
||||
fileContainingSymbol(symbol: string): FileDescriptorResponse__Output {
|
||||
const file = this.symbolMap[symbol];
|
||||
|
||||
if (!file) {
|
||||
throw new ReflectionError(grpc.status.NOT_FOUND, `Symbol not found: ${symbol}`);
|
||||
}
|
||||
|
||||
const deps = this.getFileDependencies(file);
|
||||
|
||||
return {
|
||||
fileDescriptorProto: [file, ...deps].map((proto) => proto.serializeBinary()),
|
||||
};
|
||||
}
|
||||
|
||||
/** Find a proto file by the file name
|
||||
*
|
||||
* @returns descriptors of the file which contains this symbol and its imports
|
||||
*/
|
||||
fileByFilename(filename: string): FileDescriptorResponse__Output {
|
||||
const file = this.fileNameIndex[filename];
|
||||
|
||||
if (!file) {
|
||||
throw new ReflectionError(grpc.status.NOT_FOUND, `Proto file not found: ${filename}`);
|
||||
}
|
||||
|
||||
const deps = this.getFileDependencies(file);
|
||||
|
||||
return {
|
||||
fileDescriptorProto: [file, ...deps].map((f) => f.serializeBinary()),
|
||||
};
|
||||
}
|
||||
|
||||
/** Find a proto file containing an extension to a message type
|
||||
*
|
||||
* @returns descriptors of the file which contains this symbol and its imports
|
||||
*/
|
||||
fileContainingExtension(symbol: string, field: number): FileDescriptorResponse__Output {
|
||||
const extensionsByFieldNumber = this.extensionIndex[symbol] || {};
|
||||
const file = extensionsByFieldNumber[field];
|
||||
|
||||
if (!file) {
|
||||
throw new ReflectionError(
|
||||
grpc.status.NOT_FOUND,
|
||||
`Extension not found for symbol ${symbol} at field ${field}`,
|
||||
);
|
||||
}
|
||||
|
||||
const deps = this.getFileDependencies(file);
|
||||
|
||||
return {
|
||||
fileDescriptorProto: [file, ...deps].map((f) => f.serializeBinary()),
|
||||
};
|
||||
}
|
||||
|
||||
allExtensionNumbersOfType(symbol: string): ExtensionNumberResponse__Output {
|
||||
if (!(symbol in this.extensionIndex)) {
|
||||
throw new ReflectionError(grpc.status.NOT_FOUND, `Extensions not found for symbol ${symbol}`);
|
||||
}
|
||||
|
||||
const fieldNumbers = Object.keys(this.extensionIndex[symbol]).map((key) => Number(key));
|
||||
|
||||
return {
|
||||
baseTypeName: symbol,
|
||||
extensionNumber: fieldNumbers,
|
||||
};
|
||||
}
|
||||
|
||||
private getFileDependencies(
|
||||
file: FileDescriptorProto,
|
||||
visited: Set<FileDescriptorProto> = new Set(),
|
||||
): FileDescriptorProto[] {
|
||||
const newVisited = visited.add(file);
|
||||
|
||||
const directDeps = file.getDependencyList().map((dep) => this.fileNameIndex[dep]);
|
||||
const transitiveDeps = directDeps
|
||||
.filter((dep) => !newVisited.has(dep))
|
||||
.map((dep) => this.getFileDependencies(dep, newVisited))
|
||||
.flat();
|
||||
|
||||
const allDeps = [...directDeps, ...transitiveDeps];
|
||||
|
||||
return [...new Set(allDeps)];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
/** Gets the package scope for a type name
|
||||
*
|
||||
* @example scope('grpc.reflection.v1.Type') == 'grpc.reflection.v1'
|
||||
*/
|
||||
export const scope = (path: string, separator: string = '.') => {
|
||||
if (!path.includes(separator)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return path.split(separator).slice(0, -1).join(separator);
|
||||
};
|
|
@ -0,0 +1,182 @@
|
|||
import * as assert from 'assert';
|
||||
import * as path from 'path';
|
||||
import { FileDescriptorProto } from 'google-protobuf/google/protobuf/descriptor_pb';
|
||||
import * as protoLoader from '@grpc/proto-loader';
|
||||
|
||||
import { ReflectionV1Implementation } from '../src/reflection-v1-implementation';
|
||||
|
||||
describe('GrpcReflectionService', () => {
|
||||
let reflectionService: ReflectionV1Implementation;
|
||||
|
||||
beforeEach(async () => {
|
||||
console.log(path.join(__dirname, '../proto/sample/sample.proto'));
|
||||
console.log([path.join(__dirname, '../proto/sample/vendor')]);
|
||||
const root = protoLoader.loadSync(path.join(__dirname, '../proto/sample/sample.proto'), {
|
||||
includeDirs: [path.join(__dirname, '../proto/sample/vendor')]
|
||||
});
|
||||
|
||||
reflectionService = new ReflectionV1Implementation(root);
|
||||
});
|
||||
|
||||
describe('listServices()', () => {
|
||||
it('lists all services', () => {
|
||||
const { service: services } = reflectionService.listServices('*');
|
||||
assert.equal(services.length, 1);
|
||||
assert(services.find((s) => s.name === 'sample.SampleService'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('fileByFilename()', () => {
|
||||
it('finds files with transitive dependencies', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileByFilename('sample.proto')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
const names = descriptors.map((desc) => desc.getName());
|
||||
assert.deepEqual(
|
||||
new Set(names),
|
||||
new Set(['sample.proto', 'vendor.proto', 'vendor_dependency.proto'])
|
||||
);
|
||||
});
|
||||
|
||||
it('finds files with fewer transitive dependencies', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileByFilename('vendor.proto')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
const names = descriptors.map((desc) => desc.getName());
|
||||
assert.deepEqual(new Set(names), new Set(['vendor.proto', 'vendor_dependency.proto']));
|
||||
});
|
||||
|
||||
it('finds files with no transitive dependencies', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileByFilename('vendor_dependency.proto')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
assert.equal(descriptors.length, 1);
|
||||
assert.equal(descriptors[0].getName(), 'vendor_dependency.proto');
|
||||
});
|
||||
|
||||
it('merges files based on package name', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileByFilename('vendor.proto')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
const names = descriptors.map((desc) => desc.getName());
|
||||
assert(!names.includes('common.proto')); // file merged into vendor.proto
|
||||
});
|
||||
|
||||
it('errors with no file found', () => {
|
||||
assert.throws(
|
||||
() => reflectionService.fileByFilename('nonexistent.proto'),
|
||||
'Proto file not found',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fileContainingSymbol()', () => {
|
||||
it('finds symbols and returns transitive file dependencies', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileContainingSymbol('sample.HelloRequest')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
const names = descriptors.map((desc) => desc.getName());
|
||||
assert.deepEqual(
|
||||
new Set(names),
|
||||
new Set(['sample.proto', 'vendor.proto', 'vendor_dependency.proto']),
|
||||
);
|
||||
});
|
||||
|
||||
it('finds imported message types', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileContainingSymbol('vendor.CommonMessage')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
const names = descriptors.map((desc) => desc.getName());
|
||||
assert.deepEqual(new Set(names), new Set(['vendor.proto', 'vendor_dependency.proto']));
|
||||
});
|
||||
|
||||
it('finds transitively imported message types', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileContainingSymbol('vendor.dependency.DependentMessage')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
assert.equal(descriptors.length, 1);
|
||||
assert.equal(descriptors[0].getName(), 'vendor_dependency.proto');
|
||||
});
|
||||
|
||||
it('finds nested message types', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileContainingSymbol('sample.HelloRequest.HelloNested')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
const names = descriptors.map((desc) => desc.getName());
|
||||
assert.deepEqual(
|
||||
new Set(names),
|
||||
new Set(['sample.proto', 'vendor.proto', 'vendor_dependency.proto']),
|
||||
);
|
||||
});
|
||||
|
||||
it('merges files based on package name', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileContainingSymbol('vendor.CommonMessage')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
const names = descriptors.map((desc) => desc.getName());
|
||||
assert(!names.includes('common.proto')); // file merged into vendor.proto
|
||||
});
|
||||
|
||||
it('errors with no symbol found', () => {
|
||||
assert.throws(
|
||||
() => reflectionService.fileContainingSymbol('non.existant.symbol'),
|
||||
'Symbol not found:',
|
||||
);
|
||||
});
|
||||
|
||||
it('resolves references to method types', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileContainingSymbol('sample.SampleService.Hello2')
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
const names = descriptors.map((desc) => desc.getName());
|
||||
assert.deepEqual(
|
||||
new Set(names),
|
||||
new Set(['sample.proto', 'vendor.proto', 'vendor_dependency.proto']),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fileContainingExtension()', () => {
|
||||
it('finds extensions and returns transitive file dependencies', () => {
|
||||
const descriptors = reflectionService
|
||||
.fileContainingExtension('.vendor.CommonMessage', 101)
|
||||
.fileDescriptorProto.map(FileDescriptorProto.deserializeBinary);
|
||||
|
||||
const names = descriptors.map((desc) => desc.getName());
|
||||
assert.deepEqual(new Set(names), new Set(['vendor.proto', 'vendor_dependency.proto']));
|
||||
});
|
||||
|
||||
it('errors with no symbol found', () => {
|
||||
assert.throws(
|
||||
() => reflectionService.fileContainingExtension('non.existant.symbol', 0),
|
||||
'Extension not found',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('allExtensionNumbersOfType()', () => {
|
||||
it('finds extensions and returns transitive file dependencies', () => {
|
||||
const response = reflectionService.allExtensionNumbersOfType('.vendor.CommonMessage');
|
||||
|
||||
assert.equal(response.extensionNumber.length, 1);
|
||||
assert.equal(response.extensionNumber[0], 101);
|
||||
});
|
||||
|
||||
it('errors with no symbol found', () => {
|
||||
assert.throws(
|
||||
() => reflectionService.allExtensionNumbersOfType('non.existant.symbol'),
|
||||
'Extensions not found',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
import * as assert from 'assert';
|
||||
|
||||
import { scope } from '../src/utils';
|
||||
|
||||
describe('scope', () => {
|
||||
it('traverses upwards in the package scope', () => {
|
||||
assert.strictEqual(scope('grpc.health.v1.HealthCheckResponse.ServiceStatus'), 'grpc.health.v1.HealthCheckResponse');
|
||||
assert.strictEqual(scope(scope(scope(scope('grpc.health.v1.HealthCheckResponse.ServiceStatus')))), 'grpc');
|
||||
});
|
||||
it('returns an empty package when at the top', () => {
|
||||
assert.strictEqual(scope('Message'), '');
|
||||
assert.strictEqual(scope(''), '');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"allowUnreachableCode": false,
|
||||
"allowUnusedLabels": false,
|
||||
"declaration": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noEmitOnError": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"pretty": true,
|
||||
"sourceMap": true,
|
||||
"strictNullChecks": false,
|
||||
"lib": ["es2017"],
|
||||
"outDir": "build",
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"resolveJsonModule": true,
|
||||
"incremental": true,
|
||||
"types": ["mocha"],
|
||||
"noUnusedLocals": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
"test/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue