grpc-inspect
Advanced tools
Comparing version
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) |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
33340
5.62%1
-50%313
23.23%7
40%283
-0.35%1
Infinity%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed