grpc-inspect
Advanced tools
Comparing version 0.2.0 to 0.3.0
179
index.js
@@ -6,4 +6,5 @@ const _ = require('lodash') | ||
const FIELD_PROPS = ['options', 'name', 'type', 'rule', 'id', 'extend', 'required', 'optional', 'repeated', 'map', 'defaultValue', 'long'] | ||
const SERVICE_PROPS = ['name', 'options'] | ||
const SERVICE_PROPS = ['name', 'options', 'path'] | ||
const METHOD_PROPS = ['name', 'options', 'type', 'requestType', 'requestStream', 'responseType', 'responseStream', 'requestName', 'responseName'] | ||
const METHOD_PROPS_13 = ['name', 'options', 'type', 'requestStream', 'responseStream', 'requestName', 'responseName'] | ||
@@ -191,3 +192,3 @@ module.exports = grpcinspect | ||
_.forOwn(nv, (npv, k) => { | ||
if ((typeof npv.name === 'string' && npv.name.toLowerCase() === 'message') || !npv.service) { | ||
if (((typeof npv.name === 'string' && npv.name.toLowerCase() === 'message') || !npv.service)) { | ||
namespace.messages[k] = { | ||
@@ -200,81 +201,149 @@ name: k | ||
_.forOwn(nv, (npv, k) => { | ||
if ((_.isString(npv.name) && npv.name.toLowerCase() === 'client') || (npv.service)) { | ||
if (npv && ((_.isString(npv.name) && npv.name.toLowerCase() === 'client') || (npv.service))) { | ||
clients[k] = npv | ||
const srvc = mapp(npv, SERVICE_PROPS) | ||
srvc.name = k | ||
const msgChildren = _.get(npv, 'service.parent.children') | ||
if (msgChildren && | ||
Array.isArray(msgChildren) && | ||
msgChildren.length) { | ||
msgChildren.forEach(c => { | ||
let isMsg = true | ||
if (_.isString(c.className) && c.className.toLowerCase() === 'service') { | ||
isMsg = false | ||
if (_.has(npv, 'service.parent.children')) { | ||
doProto12(k, def, namespace, npv) | ||
} else if (npv.service) { | ||
const nskeys = Object.keys(npv.service) | ||
if (nskeys && nskeys.length) { | ||
const zk = nskeys[0] | ||
if (npv.service[zk] && npv.service[zk].originalName) { | ||
doProto13(k, def, namespace, npv) | ||
} | ||
if (isMsg) { | ||
const msg = mapp(c, TYPE_PROPS) | ||
if (msg.name) { | ||
msg.fields = _.map(c._fields, f => { | ||
const nf = mapp(f, FIELD_PROPS) | ||
if (_.isObject(f.resolvedType) && f.resolvedType.name) { | ||
nf.type = f.resolvedType.name | ||
} else if (_.isObject(f.type) && f.type.name) { | ||
nf.type = f.type.name | ||
} | ||
return nf | ||
}) | ||
namespace.messages[msg.name] = msg | ||
} | ||
} | ||
}) | ||
} | ||
} else { | ||
throw new Error('Unsupported service format') | ||
} | ||
} | ||
}) | ||
const srvcChidren = _.get(npv, 'service.children') | ||
if (srvcChidren && | ||
Array.isArray(srvcChidren) && | ||
srvcChidren.length) { | ||
srvc.methods = _.map(srvcChidren, m => mapp(m, METHOD_PROPS)) | ||
def.namespaces[namespace.name] = namespace | ||
}) | ||
return createDescriptor(def, clients, proto) | ||
} | ||
function doProto13 (k, def, namespace, npv) { | ||
const srvc = mapp(npv, SERVICE_PROPS) | ||
srvc.name = k | ||
srvc.package = namespace.name | ||
srvc.methods = [] | ||
_.forOwn(npv.service, (method, methodName) => { | ||
const name = method.originalName | ||
const md = mapp(method, METHOD_PROPS_13) | ||
md.name = name || methodName | ||
if (_.has(method, 'requestType.name')) { | ||
md.requestName = _.get(method, 'requestType.name') | ||
// fill in the message in the name space from the request type | ||
if (!namespace.messages[method.requestType.name]) { | ||
namespace.messages[method.requestType.name] = { | ||
name: method.requestType.name | ||
} | ||
} | ||
if (!namespace.messages[method.requestType.name].fields) { | ||
const fp = method.requestType._fields || method.requestType.fields | ||
const fields = _.map(fp, getFieldDef) | ||
namespace.messages[method.requestType.name].fields = fields | ||
} | ||
if (_.has(npv, 'service.options') && !_.isEmpty(npv.service.options)) { | ||
srvc.options = npv.service.options | ||
// fill in options if not there | ||
if ((!def.options || _.isEmpty(def.options)) && | ||
(_.has(method, 'requestType.parent.options') && !_.isEmpty(method.requestType.parent.options))) { | ||
def.options = method.requestType.parent.options | ||
} | ||
} | ||
if (_.has(method, 'responseType.name')) { | ||
md.responseName = _.get(method, 'responseType.name') | ||
// fill in the message in the name space from the response type | ||
if (!namespace.messages[method.responseType.name]) { | ||
namespace.messages[method.requestType.name] = { | ||
name: method.requestType.name | ||
} | ||
} | ||
if (!namespace.messages[method.responseType.name].fields) { | ||
const fp = method.responseType._fields || method.responseType.fields | ||
const fields = _.map(fp, getFieldDef) | ||
namespace.messages[method.responseType.name].fields = fields | ||
} | ||
} | ||
namespace.services[k] = srvc | ||
srvc.methods.push(md) | ||
}) | ||
if ((!def.options || _.isEmpty(def.options)) && | ||
(_.has(npv, 'service.parent.options') && !_.isEmpty(npv.service.parent.options))) { | ||
def.options = npv.service.parent.options | ||
namespace.services[k] = srvc | ||
} | ||
function doProto12 (k, def, namespace, npv) { | ||
const srvc = mapp(npv, SERVICE_PROPS) | ||
srvc.name = k | ||
srvc.package = namespace.name | ||
const msgChildren = _.get(npv, 'service.parent.children') | ||
if (msgChildren && | ||
Array.isArray(msgChildren) && | ||
msgChildren.length) { | ||
msgChildren.forEach(c => { | ||
let isMsg = true | ||
if (_.isString(c.className) && c.className.toLowerCase() === 'service') { | ||
isMsg = false | ||
} | ||
if (isMsg) { | ||
const msg = mapp(c, TYPE_PROPS) | ||
if (msg.name) { | ||
msg.fields = _.map(c._fields, getFieldDef) | ||
namespace.messages[msg.name] = msg | ||
} | ||
} | ||
}) | ||
def.namespaces[namespace.name] = namespace | ||
}) | ||
} | ||
return createDescriptor(def, clients, proto) | ||
const srvcChidren = _.get(npv, 'service.children') | ||
if (srvcChidren && | ||
Array.isArray(srvcChidren) && | ||
srvcChidren.length) { | ||
srvc.methods = _.map(srvcChidren, m => mapp(m, METHOD_PROPS)) | ||
} | ||
// if (_.has(npv, 'service.options') && !_.isEmpty(npv.service.options)) { | ||
// srvc.options = npv.service.options | ||
// } | ||
namespace.services[k] = srvc | ||
if ((!def.options || _.isEmpty(def.options)) && | ||
(_.has(npv, 'service.parent.options') && !_.isEmpty(npv.service.parent.options))) { | ||
def.options = npv.service.parent.options | ||
} | ||
} | ||
function getFieldDef (f) { | ||
const nf = mapp(f, FIELD_PROPS) | ||
if (_.isObject(f.resolvedType) && f.resolvedType.name) { | ||
nf.type = f.resolvedType.name | ||
} else if (_.isObject(f.type) && f.type.name) { | ||
nf.type = f.type.name | ||
} | ||
return nf | ||
} | ||
/** | ||
* Returns protocol buffer utility descriptor. | ||
* Takes a path to proto definition file and loads it using <code>grpc</code> and generates a | ||
* friendlier descriptor object with utility methods. | ||
* If object is passed it's assumed to be an already loaded proto. | ||
* @param {String|Object} input path to proto definition or loaded proto object | ||
* @param {String} root specify the directory in which to search for imports | ||
* Takes a loaded grpc / protocol buffer object and returns a friendlier descriptor object | ||
* @param {Object} input loaded proto object | ||
* @return {Object} the utility descriptor | ||
* @example | ||
* 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(pbpath) | ||
* console.dir(d) | ||
*/ | ||
function grpcinspect (input, root) { | ||
function grpcinspect (input) { | ||
let proto | ||
if (_.isString(input) && _.isString(root)) { | ||
proto = grpc.load({file: input, root: root}) | ||
} else if (_.isString(input)) { | ||
proto = grpc.load(input) | ||
} else if (_.isObject(input)) { | ||
if (_.isObject(input)) { | ||
proto = input | ||
@@ -281,0 +350,0 @@ } else { |
{ | ||
"name": "grpc-inspect", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "gRPC protocol buffer inspection utility", | ||
@@ -29,11 +29,12 @@ "main": "index.js", | ||
"dependencies": { | ||
"grpc": "^1.0.1", | ||
"lodash": "^4.17.2" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.17.0", | ||
"ava": "^0.19.0", | ||
"babel-eslint": "^7.1.1", | ||
"jsdoc-to-markdown": "^2.0.1", | ||
"grpc": "^1.3.0", | ||
"jsdoc-to-markdown": "^3.0.0", | ||
"md-wrap-code": "^0.1.1", | ||
"standard": "^8.5.0" | ||
"protobufjs": "^6.7.3", | ||
"standard": "^10.0.0" | ||
}, | ||
@@ -40,0 +41,0 @@ "directories": { |
@@ -106,3 +106,3 @@ # grpc-inspect | ||
**Kind**: global class | ||
**Access:** public | ||
**Access**: public | ||
@@ -123,3 +123,3 @@ * [descriptor](#descriptor) : <code>Object</code> | ||
**Kind**: static method of <code>[descriptor](#descriptor)</code> | ||
**Kind**: static method of [<code>descriptor</code>](#descriptor) | ||
**Returns**: <code>Array</code> - array of names | ||
@@ -140,3 +140,3 @@ **Example** | ||
**Kind**: static method of <code>[descriptor](#descriptor)</code> | ||
**Kind**: static method of [<code>descriptor</code>](#descriptor) | ||
**Returns**: <code>Array</code> - array of names | ||
@@ -163,3 +163,3 @@ | ||
**Kind**: static method of <code>[descriptor](#descriptor)</code> | ||
**Kind**: static method of [<code>descriptor</code>](#descriptor) | ||
**Returns**: <code>Object</code> - service utility descriptor | ||
@@ -185,3 +185,3 @@ | ||
**Kind**: static method of <code>[descriptor](#descriptor)</code> | ||
**Kind**: static method of [<code>descriptor</code>](#descriptor) | ||
**Returns**: <code>Array</code> - array of names | ||
@@ -208,3 +208,3 @@ | ||
**Kind**: static method of <code>[descriptor](#descriptor)</code> | ||
**Kind**: static method of [<code>descriptor</code>](#descriptor) | ||
**Returns**: <code>Array</code> - array of method utility descriptors | ||
@@ -230,3 +230,3 @@ | ||
**Kind**: static method of <code>[descriptor](#descriptor)</code> | ||
**Kind**: static method of [<code>descriptor</code>](#descriptor) | ||
**Returns**: <code>Object</code> - the internal proto object | ||
@@ -247,3 +247,3 @@ **Example** | ||
**Kind**: static method of <code>[descriptor](#descriptor)</code> | ||
**Kind**: static method of [<code>descriptor</code>](#descriptor) | ||
**Returns**: <code>Object</code> - the Client object | ||
@@ -266,7 +266,5 @@ | ||
### grpcinspect(input, root) ⇒ <code>Object</code> | ||
### grpcinspect(input) ⇒ <code>Object</code> | ||
Returns protocol buffer utility descriptor. | ||
Takes a path to proto definition file and loads it using <code>grpc</code> and generates a | ||
friendlier descriptor object with utility methods. | ||
If object is passed it's assumed to be an already loaded proto. | ||
Takes a loaded grpc / protocol buffer object and returns a friendlier descriptor object | ||
@@ -278,4 +276,3 @@ **Kind**: global function | ||
| --- | --- | --- | | ||
| input | <code>String</code> | <code>Object</code> | path to proto definition or loaded proto object | | ||
| root | <code>String</code> | specify the directory in which to search for imports | | ||
| input | <code>Object</code> | loaded proto object | | ||
@@ -286,3 +283,5 @@ **Example** | ||
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(pbpath) | ||
@@ -289,0 +288,0 @@ console.dir(d) |
33340
1
313
7
283
- Removedgrpc@^1.0.1
- Removed@mapbox/node-pre-gyp@1.0.11(transitive)
- Removed@types/bytebuffer@5.0.49(transitive)
- Removed@types/long@3.0.32(transitive)
- Removed@types/node@22.10.7(transitive)
- Removedabbrev@1.1.1(transitive)
- Removedagent-base@6.0.2(transitive)
- Removedansi-regex@2.1.15.0.1(transitive)
- Removedaproba@2.0.0(transitive)
- Removedare-we-there-yet@2.0.0(transitive)
- Removedascli@1.0.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbytebuffer@5.0.1(transitive)
- Removedcamelcase@2.1.1(transitive)
- Removedchownr@2.0.0(transitive)
- Removedcliui@3.2.0(transitive)
- Removedcode-point-at@1.1.0(transitive)
- Removedcolor-support@1.1.3(transitive)
- Removedcolour@0.7.1(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconsole-control-strings@1.1.0(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removeddelegates@1.0.0(transitive)
- Removeddetect-libc@2.0.3(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedfs-minipass@2.1.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedgauge@3.0.2(transitive)
- Removedglob@7.2.3(transitive)
- Removedgrpc@1.24.11(transitive)
- Removedhas-unicode@2.0.1(transitive)
- Removedhttps-proxy-agent@5.0.1(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedinvert-kv@1.0.0(transitive)
- Removedis-fullwidth-code-point@1.0.03.0.0(transitive)
- Removedlcid@1.0.0(transitive)
- Removedlodash.camelcase@4.3.0(transitive)
- Removedlodash.clone@4.5.0(transitive)
- Removedlong@3.2.0(transitive)
- Removedmake-dir@3.1.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminipass@3.3.65.0.0(transitive)
- Removedminizlib@2.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedms@2.1.3(transitive)
- Removednan@2.22.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removednopt@5.0.0(transitive)
- Removednpmlog@5.0.1(transitive)
- Removednumber-is-nan@1.0.1(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedonce@1.4.0(transitive)
- Removedoptjs@3.2.2(transitive)
- Removedos-locale@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedprotobufjs@5.0.3(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedrimraf@3.0.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@6.3.17.6.3(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedstring-width@1.0.24.2.3(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedstrip-ansi@3.0.16.0.1(transitive)
- Removedtar@6.2.1(transitive)
- Removedtr46@0.0.3(transitive)
- Removedundici-types@6.20.0(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
- Removedwide-align@1.1.5(transitive)
- Removedwindow-size@0.1.4(transitive)
- Removedwrap-ansi@2.1.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedy18n@3.2.2(transitive)
- Removedyallist@4.0.0(transitive)
- Removedyargs@3.32.0(transitive)