https://github.com/bojand/grpc-inspect
gRPC protocol buffer inspection utility
https://github.com/bojand/grpc-inspect
grpc
Last synced: about 1 year ago
JSON representation
gRPC protocol buffer inspection utility
- Host: GitHub
- URL: https://github.com/bojand/grpc-inspect
- Owner: bojand
- License: apache-2.0
- Created: 2016-12-19T01:45:39.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-02-05T12:32:40.000Z (over 7 years ago)
- Last Synced: 2025-03-19T07:03:30.240Z (over 1 year ago)
- Topics: grpc
- Language: JavaScript
- Homepage: https://bojand.github.io/grpc-inspect
- Size: 616 KB
- Stars: 9
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-grpc - grpc-inspect - gRPC protocol buffer inspection utility (Language-Specific / Node.js)
README
# grpc-inspect
[](https://www.npmjs.com/package/grpc-inspect)
[](https://travis-ci.org/bojand/grpc-inspect)
[](https://standardjs.com)
[](https://raw.githubusercontent.com/bojand/grpc-inspect/master/LICENSE)
[](https://greenkeeper.io/)
gRPC Protocol Buffer utility module that generates a descriptor object representing a
friendlier descriptor object with utility methods for protocol buffer inspection.
## Installation
`npm install grpc-inspect`
## Overview
`helloworld.proto`
```
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
```
Sample usage:
```js
const gi = require('grpc-inspect')
const grpc = require('grpc')
const pbpath = path.resolve(__dirname, './route_guide.proto')
const proto = grpc.load(pbpath)
const d = gi(proto)
console.dir(d)
```
Returned utility descriptor:
```js
{ namespaces:
{ helloworld:
{ name: 'helloworld',
messages:
{ HelloRequest:
{ name: 'HelloRequest',
fields:
[ { name: 'name',
type: 'string',
id: 1,
required: false,
repeated: false,
map: false,
defaultValue: '' } ] },
HelloReply:
{ name: 'HelloReply',
fields:
[ { name: 'message',
type: 'string',
id: 1,
required: false,
repeated: false,
map: false,
defaultValue: '' } ] } },
services:
{ Greeter:
{ name: 'Greeter',
package: 'helloworld',
methods:
[ { name: 'SayHello',
requestStream: false,
responseStream: false,
requestName: 'HelloRequest',
responseName: 'HelloReply' } ] } } } },
file: '/Users/me/protos/helloworld.proto',
options:
{ java_multiple_files: true,
java_package: 'io.grpc.examples.helloworld',
java_outer_classname: 'HelloWorldProto',
objc_class_prefix: 'HLW' } }
```
**NOTE** If no package name is specified in the protocol buffer definition an empty `''` string is used for the package / namespace name.
## API Reference
### descriptor : Object
Protocol Buffer utility descriptor represents friendlier descriptor object with utility methods for
protocol buffer inspection.
**Kind**: global class
**Access**: public
* [descriptor](#descriptor) : Object
* [.namespaceNames()](#descriptor.namespaceNames) ⇒ Array
* [.serviceNames(namespace)](#descriptor.serviceNames) ⇒ Array
* [.service(service)](#descriptor.service) ⇒ Object
* [.methodNames(service)](#descriptor.methodNames) ⇒ Array
* [.methods(service)](#descriptor.methods) ⇒ Array
* [.proto()](#descriptor.proto) ⇒ Object
* [.client(serviceName)](#descriptor.client) ⇒ Object
#### descriptor.namespaceNames() ⇒ Array
Returns an array of namespace names within the protocol buffer definition
**Kind**: static method of [descriptor](#descriptor)
**Returns**: Array - array of names
**Example**
```js
const grpcinspect = require('grpc-inspect')
const grpc = require('grpc')
const pbpath = path.resolve(__dirname, './route_guide.proto')
const proto = grpc.load(pbpath)
const d = grpcinspect(proto)
console.log(d.namespaceNames()) // ['routeguide']
```
#### descriptor.serviceNames(namespace) ⇒ Array
Returns an array of service names
**Kind**: static method of [descriptor](#descriptor)
**Returns**: Array - array of names
| Param | Type | Description |
| --- | --- | --- |
| namespace | String | Optional name of namespace to get services. If not present returns service names of all services within the definition. |
**Example**
```js
const grpcinspect = require('grpc-inspect')
const grpc = require('grpc')
const pbpath = path.resolve(__dirname, './route_guide.proto')
const proto = grpc.load(pbpath)
const d = const grpcinspect(proto)
console.log(d.serviceNames()) // ['RouteGuide']
```
#### descriptor.service(service) ⇒ Object
Returns the utility descriptor for the service given a servie name.
Assumes there are no duplicate service names within the definition.
**Kind**: static method of [descriptor](#descriptor)
**Returns**: Object - service utility descriptor
| Param | Type | Description |
| --- | --- | --- |
| service | String | name of the service |
**Example**
```js
const grpcinspect = require('grpc-inspect')
const grpc = require('grpc')
const pbpath = path.resolve(__dirname, './route_guide.proto')
const proto = grpc.load(pbpath)
const d = grpcinspect(proto)
console.dir(d.service('RouteGuide'))
```
#### descriptor.methodNames(service) ⇒ Array
Returns an array of method names for a service
**Kind**: static method of [descriptor](#descriptor)
**Returns**: Array - array of names
| Param | Type | Description |
| --- | --- | --- |
| service | String | name of the service |
**Example**
```js
const grpcinspect = require('grpc-inspect')
const grpc = require('grpc')
const pbpath = path.resolve(__dirname, './route_guide.proto')
const proto = grpc.load(pbpath)
const d = grpcinspect(proto)
console.log(d.methodNames('RouteGuide')) // [ 'GetFeature', 'ListFeatures', 'RecordRoute', 'RouteChat' ]
```
#### descriptor.methods(service) ⇒ Array
Returns an array the utility descriptors for the methods of a service.
Assumes there are no duplicate service names within the definition.
**Kind**: static method of [descriptor](#descriptor)
**Returns**: Array - array of method utility descriptors
| Param | Type | Description |
| --- | --- | --- |
| service | String | name of the service |
**Example**
```js
const grpcinspect = require('grpc-inspect')
const grpc = require('grpc')
const pbpath = path.resolve(__dirname, './route_guide.proto')
const proto = grpc.load(pbpath)
const d = grpcinspect(proto)
console.dir(d.methods('RouteGuide'))
```
#### descriptor.proto() ⇒ Object
Returns the internal proto object
**Kind**: static method of [descriptor](#descriptor)
**Returns**: Object - the internal proto object
**Example**
```js
const grpcinspect = require('grpc-inspect')
const grpc = require('grpc')
const pbpath = path.resolve(__dirname, './route_guide.proto')
const proto = grpc.load(pbpath)
const d = grpcinspect(proto)
console.dir(d.proto())
```
#### descriptor.client(serviceName) ⇒ Object
Gets the gRPC service / client object / function
**Kind**: static method of [descriptor](#descriptor)
**Returns**: Object - the Client object
| Param | Type | Description |
| --- | --- | --- |
| serviceName | serviceName | The service name. Can and should include package. |
**Example**
```js
const grpcinspect = require('grpc-inspect')
const grpc = require('grpc')
const pbpath = path.resolve(__dirname, './route_guide.proto')
const proto = grpc.load(pbpath)
const d = grpcinspect(proto)
console.dir(d.client('RouteGuide'))
console.dir(d.client('routeguide.RouteGuide'))
```
### grpcinspect(input) ⇒ Object
Returns protocol buffer utility descriptor.
Takes a loaded grpc / protocol buffer object and returns a friendlier descriptor object
**Kind**: global function
**Returns**: Object - the utility descriptor
| Param | Type | Description |
| --- | --- | --- |
| input | Object | loaded proto object |
**Example**
```js
const gi = require('grpc-inspect')
const grpc = require('grpc')
const pbpath = path.resolve(__dirname, './route_guide.proto')
const proto = grpc.load(pbpath)
const d = gi(proto)
console.dir(d)
```
## License
Apache 2.0