bare-rpc 0.1.0 → 0.1.1

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 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 = Buffer.concat([this._buffer, data])
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 }
@@ -1,3 +1,4 @@
1
+ const b4a = require('b4a')
1
2
  const errors = require('./errors')
2
3
 
3
4
  module.exports = class RPCIncomingRequest {
@@ -16,7 +17,7 @@ module.exports = class RPCIncomingRequest {
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' ? Buffer.from(data) : data)
20
+ this.rpc._sendResponse(this, typeof data === 'string' ? b4a.from(data) : data)
20
21
  }
21
22
 
22
23
  createResponseStream (opts = {}) {
@@ -1,3 +1,4 @@
1
+ const b4a = require('b4a')
1
2
  const errors = require('./errors')
2
3
 
3
4
  module.exports = class RPCOutgoingRequest {
@@ -7,11 +8,10 @@ module.exports = class RPCOutgoingRequest {
7
8
  this.command = command
8
9
  this.sent = false
9
10
 
10
- const { promise, resolve, reject } = Promise.withResolvers()
11
-
12
- this._promise = promise
13
- this._resolve = resolve
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
@@ -21,7 +21,7 @@ module.exports = class RPCOutgoingRequest {
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' ? Buffer.from(data) : data)
24
+ this.rpc._sendRequest(this, typeof data === 'string' ? b4a.from(data) : data)
25
25
  }
26
26
 
27
27
  reply () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-rpc",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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"