New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rpc-protocol

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rpc-protocol - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

8

example-client.js

@@ -25,2 +25,10 @@ const { Protocol, unserialize } = require('./')

})
alice.createReadStream(alice.call('stream'))
.on('data', (d) => console.log(d.toString()))
.on('end', () => console.log('end'))
alice.createReadStream(alice.call('iterator'))
.on('data', (d) => console.log(d.toString()))
.on('end', () => console.log('end'))
})

13

example-server.js

@@ -0,3 +1,5 @@

const { Protocol, unserialize } = require('./')
const through = require('through2')
const Server = require('simple-websocket/server')
const { Protocol, unserialize } = require('./')
const fs= require('fs')

@@ -9,2 +11,11 @@ const server = new Server({ port: 3000 })

bob.command('stream', () => {
return fs.createReadStream('./package.json')
})
bob.command('iterator', () => {
return new Set([1,2,3,4,5]).values()
//return new Set(['a','b','c']).values()
})
bob.command('hey joe!', (command) => {

@@ -11,0 +22,0 @@ console.log('got command', command)

3

package.json
{
"name": "rpc-protocol",
"version": "0.1.3",
"version": "0.2.0",
"description": "Create and run commands over a RPC protocol stream",

@@ -29,2 +29,3 @@ "main": "index.js",

"dependencies": {
"is-stream": "^1.1.0",
"jitson": "^1.0.0",

@@ -31,0 +32,0 @@ "protocol-buffers-encodings": "^1.1.0",

@@ -7,2 +7,3 @@ const { deserialize } = require('./serialization')

const { unpack } = require('./unpack')
const isStream = require('is-stream')
const { pack } = require('./pack')

@@ -290,3 +291,24 @@ const { Fin } = require('./fin')

if (!responded && undefined !== results) {
respond(null, results)
if (isStream(results)) {
let reading = true
results.on('data', (data) => { reading && (reading = respond(null, data)) })
results.on('end', () => { reading && respond(null, null) })
} else if (
!Array.isArray(results) &&
'function' === typeof results[Symbol.iterator]
) {
let pending = 0
for (const value of results) {
pending++
process.nextTick(() => {
if (respond(null, value)) {
if (0 === --pending) {
respond(null, null)
}
}
})
}
} else {
respond(null, results)
}
}

@@ -293,0 +315,0 @@ } catch (err) {

@@ -5,3 +5,6 @@ const { unpack } = require('./unpack')

const varint = require('varint')
const jitson = require('jitson')
const parse = jitson()
function toMaybeError(err) {

@@ -51,4 +54,8 @@ if (!err) {

error: this.error || null,
results: this.results && this.results.map((result) => encoding.encode(result)),
results: this.results && this.results.map(encode),
}
function encode(result){
return encoding.encode(parse(JSON.stringify(result)))
}
}

@@ -55,0 +62,0 @@

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