Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grpc-inspect

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grpc-inspect - npm Package Compare versions

Comparing version 0.3.3 to 0.4.0

130

index.js

@@ -181,6 +181,83 @@ const _ = require('lodash')

function isService (obj) {
function isMessage (obj) {
return ((typeof obj.name === 'string' && obj.name.toLowerCase() === 'message') || !obj.service)
}
function isService (v) {
return !!(v && typeof v === 'function' && v.super_ && typeof v.super_ === 'function')
}
function hasPackage (proto) {
let hasPkg = false
_.forOwn(proto, (nv, k) => {
if (!hasPkg) {
_.forOwn(nv, (v, k) => {
if (v && typeof v === 'function' && v.super_ && typeof v.super_ === 'function') {
hasPkg = true
}
})
}
})
if (hasPkg) {
return hasPkg
}
_.forOwn(proto, (nv, k) => {
if (!hasPkg) {
_.forOwn(nv, (v, k) => {
if (v && typeof v === 'function' && v.encode && typeof v.encode === 'function') {
hasPkg = true
}
})
}
})
if (hasPkg) {
return hasPkg
}
let packageDetected = false
_.forOwn(proto, (nv, k) => {
if (nv && typeof nv === 'function' && nv.super_ && typeof nv.super_ === 'function') {
packageDetected = true
}
})
if (packageDetected) {
return false
}
_.forOwn(proto, (nv, k) => {
if (!hasPkg) {
_.forOwn(nv, (v, k) => {
if (v && _.isPlainObject(v)) {
hasPkg = true
}
})
}
})
return hasPkg
}
function hasService (proto, hasPackage) {
let hasSrvc = false
_.forOwn(proto, (nv, k) => {
if (!hasPackage) {
if (!hasSrvc) {
hasSrvc = isService(nv)
}
} else {
_.forOwn(nv, (v, kk) => {
if (!hasSrvc) {
hasSrvc = isService(v)
}
})
}
})
return hasSrvc
}
function create (proto) {

@@ -202,15 +279,8 @@ if (!proto) {

// check if the proto specifies a package name
let hasPackage = true
if (_.keys(proto).length === 1) {
_.forOwn(proto, (nv, k) => {
if (hasPackage && isService(nv)) {
hasPackage = false
}
})
}
const hasPkg = hasPackage(proto)
const hasSrvc = hasService(proto, hasPkg)
_.forOwn(proto, (nv, k) => {
const hasPackage = _.keys(proto).length === 1
const packageName = hasPackage ? k : ''
const serviceObject = hasPackage ? nv : proto
const packageName = hasPkg ? k : ''
const serviceObject = hasPkg ? nv : proto

@@ -224,3 +294,3 @@ const namespace = {

_.forOwn(serviceObject, (npv, k) => {
if (isService(npv)) {
if (isMessage(npv)) {
namespace.messages[k] = {

@@ -232,21 +302,27 @@ name: k

_.forOwn(serviceObject, (npv, k) => {
if (npv && ((_.isString(npv.name) && npv.name.toLowerCase() === 'client') || (npv.service))) {
clients[k] = npv
if (hasSrvc) {
_.forOwn(serviceObject, (npv, k) => {
if (npv &&
(((_.isString(npv.name) && npv.name.toLowerCase() === 'client') || (npv.service)) ||
(npv && typeof npv === 'function' && npv.super_ && typeof npv.super_ === 'function'))) {
clients[k] = npv
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) {
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)
}
} else {
doProto13(k, def, namespace, npv)
}
} else {
throw new Error('Unsupported service format')
}
} else {
throw new Error('Unsupported service format')
}
}
})
})
}

@@ -253,0 +329,0 @@ def.namespaces[namespace.name] = namespace

{
"name": "grpc-inspect",
"version": "0.3.3",
"version": "0.4.0",
"description": "gRPC protocol buffer inspection utility",

@@ -32,6 +32,5 @@ "main": "index.js",

"devDependencies": {
"ava": "^0.22.0",
"babel-eslint": "^7.1.1",
"grpc": "^1.4.1",
"jsdoc-to-markdown": "^3.0.0",
"ava": "^0.23.0",
"grpc": "^1.7.0",
"jsdoc-to-markdown": "^3.0.2",
"md-wrap-code": "^0.1.1",

@@ -44,5 +43,2 @@ "protobufjs": "^6.8.0",

},
"standard": {
"parser": "babel-eslint"
},
"ava": {

@@ -49,0 +45,0 @@ "files": [

@@ -104,2 +104,4 @@ # grpc-inspect

**NOTE** If no package name is specified in the protocol buffer definition an empty `''` string is used for the package / namespace name.
## API Reference

@@ -106,0 +108,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc