bare-rpc 1.1.0 → 1.2.0

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.d.ts CHANGED
@@ -1,11 +1,5 @@
1
1
  import Buffer, { BufferEncoding } from 'bare-buffer'
2
- import {
3
- Readable,
4
- ReadableOptions,
5
- Writable,
6
- WritableOptions,
7
- Duplex
8
- } from 'bare-stream'
2
+ import { Readable, ReadableOptions, Writable, WritableOptions, Duplex } from 'bare-stream'
9
3
 
10
4
  declare const constants: {
11
5
  type: { REQUEST: 1; RESPONSE: 2; STREAM: 3 }
@@ -106,10 +100,7 @@ interface RPC {
106
100
  }
107
101
 
108
102
  declare class RPC {
109
- constructor(
110
- stream: Duplex,
111
- onrequest: (req: RPCIncomingRequest) => void | Promise<void>
112
- )
103
+ constructor(stream: Duplex, onrequest: (req: RPCIncomingRequest) => void | Promise<void>)
113
104
  }
114
105
 
115
106
  declare namespace RPC {
package/index.js CHANGED
@@ -39,10 +39,7 @@ module.exports = exports = class RPC {
39
39
  this._ondata = this._ondata.bind(this)
40
40
  this._ondrain = this._ondrain.bind(this)
41
41
 
42
- this._stream
43
- .on('error', this._onerror)
44
- .on('data', this._ondata)
45
- .on('drain', this._ondrain)
42
+ this._stream.on('error', this._onerror).on('data', this._ondata).on('drain', this._ondrain)
46
43
  }
47
44
 
48
45
  event(command) {
@@ -92,25 +89,13 @@ module.exports = exports = class RPC {
92
89
  if (isInitiator) {
93
90
  this._outgoingRequests.set(request.id, request)
94
91
 
95
- request._requestStream = new OutgoingStream(
96
- this,
97
- request,
98
- t.REQUEST,
99
- opts
100
- )
92
+ request._requestStream = new OutgoingStream(this, request, t.REQUEST, opts)
101
93
  } else {
102
94
  this._incomingRequests.set(request.id, request)
103
95
 
104
- request._requestStream = new IncomingStream(
105
- this,
106
- request,
107
- t.REQUEST,
108
- opts
109
- )
96
+ request._requestStream = new IncomingStream(this, request, t.REQUEST, opts)
110
97
 
111
- request._requestStream.on('close', () =>
112
- this._incomingRequests.delete(request.id)
113
- )
98
+ request._requestStream.on('close', () => this._incomingRequests.delete(request.id))
114
99
  }
115
100
  }
116
101
 
@@ -128,25 +113,13 @@ module.exports = exports = class RPC {
128
113
  if (isInitiator) {
129
114
  this._outgoingResponses.set(request.id, request)
130
115
 
131
- request._responseStream = new OutgoingStream(
132
- this,
133
- request,
134
- t.RESPONSE,
135
- opts
136
- )
116
+ request._responseStream = new OutgoingStream(this, request, t.RESPONSE, opts)
137
117
  } else {
138
118
  this._incomingResponses.set(request.id, request)
139
119
 
140
- request._responseStream = new IncomingStream(
141
- this,
142
- request,
143
- t.RESPONSE,
144
- opts
145
- )
120
+ request._responseStream = new IncomingStream(this, request, t.RESPONSE, opts)
146
121
 
147
- request._responseStream.on('close', () =>
148
- this._incomingResponses.delete(request.id)
149
- )
122
+ request._responseStream.on('close', () => this._incomingResponses.delete(request.id))
150
123
  }
151
124
  }
152
125
 
@@ -180,8 +153,7 @@ module.exports = exports = class RPC {
180
153
  _onbeforeframe() {
181
154
  if (this._buffered < 4) return
182
155
 
183
- const buffer =
184
- this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer)
156
+ const buffer = this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer)
185
157
 
186
158
  this._buffer = [buffer]
187
159
  this._frame = 4 + c.uint32.decode(c.state(0, 4, buffer))
@@ -192,8 +164,7 @@ module.exports = exports = class RPC {
192
164
  _onafterframe() {
193
165
  if (this._buffered < this._frame) return
194
166
 
195
- const buffer =
196
- this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer)
167
+ const buffer = this._buffer.length === 1 ? this._buffer[0] : b4a.concat(this._buffer)
197
168
 
198
169
  const frame = this._frame
199
170
 
@@ -220,12 +191,7 @@ module.exports = exports = class RPC {
220
191
  const request =
221
192
  message.id === 0
222
193
  ? new IncomingEvent(this, message.command, message.data)
223
- : new IncomingRequest(
224
- this,
225
- message.id,
226
- message.command,
227
- message.data
228
- )
194
+ : new IncomingRequest(this, message.id, message.command, message.data)
229
195
 
230
196
  try {
231
197
  await this._onrequest(request)
package/lib/messages.js CHANGED
@@ -95,10 +95,7 @@ exports.header = {
95
95
 
96
96
  state.start = frame
97
97
 
98
- c.uint32.encode(
99
- state,
100
- end - start + (hasData && m.data ? m.data.byteLength : 0)
101
- )
98
+ c.uint32.encode(state, end - start + (hasData && m.data ? m.data.byteLength : 0))
102
99
 
103
100
  state.start = end
104
101
  }
@@ -44,9 +44,7 @@ module.exports = class RPCOutgoingRequest {
44
44
 
45
45
  this.received = true
46
46
 
47
- return encoding
48
- ? this._promise.then((data) => c.decode(encoding, data))
49
- : this._promise
47
+ return encoding ? this._promise.then((data) => c.decode(encoding, data)) : this._promise
50
48
  }
51
49
 
52
50
  createRequestStream(opts = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-rpc",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "librpc ABI compatible RPC for Bare",
5
5
  "exports": {
6
6
  ".": {
@@ -11,7 +11,8 @@
11
11
  "./errors": {
12
12
  "types": "./lib/errors.d.ts",
13
13
  "default": "./lib/errors.js"
14
- }
14
+ },
15
+ "./messages": "./lib/messages.js"
15
16
  },
16
17
  "files": [
17
18
  "index.js",
@@ -19,7 +20,8 @@
19
20
  "lib"
20
21
  ],
21
22
  "scripts": {
22
- "test": "prettier . --check && bare test.js"
23
+ "test": "prettier . --check && bare test.js",
24
+ "format": "prettier --write ."
23
25
  },
24
26
  "repository": {
25
27
  "type": "git",
@@ -42,7 +44,7 @@
42
44
  "bare-ipc": "^1.1.0",
43
45
  "brittle": "^3.2.1",
44
46
  "prettier": "^3.4.2",
45
- "prettier-config-standard": "^7.0.0"
47
+ "prettier-config-holepunch": "^2.0.0"
46
48
  },
47
49
  "peerDependencies": {
48
50
  "bare-buffer": "*"