bare-rpc 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -1
- package/lib/incoming-request.js +3 -2
- package/lib/outgoing-request.js +11 -9
- package/package.json +2 -4
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const safetyCatch = require('safety-catch')
|
|
2
|
+
const b4a = require('b4a')
|
|
2
3
|
const c = require('compact-encoding')
|
|
3
4
|
const m = require('./lib/messages')
|
|
4
5
|
const { type: t, stream: s } = require('./lib/constants')
|
|
@@ -99,7 +100,7 @@ module.exports = class RPC {
|
|
|
99
100
|
|
|
100
101
|
_ondata (data) {
|
|
101
102
|
if (this._buffer === null) this._buffer = data
|
|
102
|
-
else this._buffer =
|
|
103
|
+
else this._buffer = b4a.concat([this._buffer, data])
|
|
103
104
|
|
|
104
105
|
while (this._buffer !== null) {
|
|
105
106
|
const state = { start: 0, end: this._buffer.length, buffer: this._buffer }
|
package/lib/incoming-request.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const b4a = require('b4a')
|
|
1
2
|
const errors = require('./errors')
|
|
2
3
|
|
|
3
4
|
module.exports = class RPCIncomingRequest {
|
|
@@ -12,11 +13,11 @@ module.exports = class RPCIncomingRequest {
|
|
|
12
13
|
this._responseStream = null
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
reply (data) {
|
|
16
|
+
reply (data, encoding) {
|
|
16
17
|
if (this.sent) throw errors.ALREADY_SENT('Response has already been sent')
|
|
17
18
|
this.sent = true
|
|
18
19
|
|
|
19
|
-
this.rpc._sendResponse(this, typeof data === 'string' ?
|
|
20
|
+
this.rpc._sendResponse(this, typeof data === 'string' ? b4a.from(data, encoding) : data)
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
createResponseStream (opts = {}) {
|
package/lib/outgoing-request.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const b4a = require('b4a')
|
|
1
2
|
const errors = require('./errors')
|
|
2
3
|
|
|
3
4
|
module.exports = class RPCOutgoingRequest {
|
|
@@ -7,25 +8,26 @@ module.exports = class RPCOutgoingRequest {
|
|
|
7
8
|
this.command = command
|
|
8
9
|
this.sent = false
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this._reject = reject
|
|
11
|
+
this._promise = new Promise((resolve, reject) => {
|
|
12
|
+
this._resolve = resolve
|
|
13
|
+
this._reject = reject
|
|
14
|
+
})
|
|
15
15
|
|
|
16
16
|
this._requestStream = null
|
|
17
17
|
this._responseStream = null
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
send (data) {
|
|
20
|
+
send (data, encoding) {
|
|
21
21
|
if (this.sent) throw errors.ALREADY_SENT('Request has already been sent')
|
|
22
22
|
this.sent = true
|
|
23
23
|
|
|
24
|
-
this.rpc._sendRequest(this, typeof data === 'string' ?
|
|
24
|
+
this.rpc._sendRequest(this, typeof data === 'string' ? b4a.from(data, encoding) : data)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
reply () {
|
|
28
|
-
return
|
|
27
|
+
reply (encoding) {
|
|
28
|
+
return encoding && encoding !== 'buffer'
|
|
29
|
+
? this._promise.then((data) => b4a.toString(data, encoding))
|
|
30
|
+
: this._promise
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
createRequestStream (opts = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-rpc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "librpc ABI compatible RPC for Bare",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -24,10 +24,8 @@
|
|
|
24
24
|
"url": "https://github.com/holepunchto/bare-rpc/issues"
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/holepunchto/bare-rpc#readme",
|
|
27
|
-
"engines": {
|
|
28
|
-
"bare": ">=1.4.0"
|
|
29
|
-
},
|
|
30
27
|
"dependencies": {
|
|
28
|
+
"b4a": "^1.6.6",
|
|
31
29
|
"bare-stream": "^2.1.3",
|
|
32
30
|
"compact-encoding": "^2.15.0",
|
|
33
31
|
"safety-catch": "^1.0.2"
|