rpc-protocol
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -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')) | ||
}) |
@@ -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) |
{ | ||
"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 @@ |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
48176
1351
8
1
+ Addedis-stream@^1.1.0
+ Addedis-stream@1.1.0(transitive)