bare-ipc 1.0.1 → 1.1.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 +33 -0
- package/index.js +62 -46
- package/lib/errors.d.ts +5 -0
- package/package.json +12 -4
package/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Duplex } from 'bare-stream'
|
|
2
|
+
import { Transferable, symbols } from 'bare-structured-clone'
|
|
3
|
+
|
|
4
|
+
interface IPC extends Duplex {
|
|
5
|
+
ref(): this
|
|
6
|
+
unref(): this
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare class IPC {
|
|
10
|
+
constructor(port: IPCPort)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface IPCPort extends Transferable<[incoming: number, outgoing: number]> {
|
|
14
|
+
readonly incoming: number
|
|
15
|
+
readonly outgoing: number
|
|
16
|
+
readonly detached: boolean
|
|
17
|
+
|
|
18
|
+
connect(): IPC
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare class IPCPort {
|
|
22
|
+
constructor(incoming: number, outgoing: number)
|
|
23
|
+
|
|
24
|
+
static [symbols.attach](input: [incoming: number, outgoing: number]): IPCPort
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare namespace IPC {
|
|
28
|
+
export { IPCPort }
|
|
29
|
+
|
|
30
|
+
export function open(): [IPCPort, IPCPort]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export = IPC
|
package/index.js
CHANGED
|
@@ -2,52 +2,68 @@ const Pipe = require('bare-pipe')
|
|
|
2
2
|
const { Duplex } = require('bare-stream')
|
|
3
3
|
const errors = require('./lib/errors')
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
5
|
+
module.exports = exports = class IPC extends Duplex {
|
|
6
|
+
constructor(port) {
|
|
7
|
+
const { incoming, outgoing } = port
|
|
8
|
+
|
|
9
|
+
super()
|
|
10
|
+
|
|
11
|
+
this._incoming = new Pipe(incoming)
|
|
12
|
+
this._outgoing = new Pipe(outgoing)
|
|
13
|
+
|
|
14
|
+
this._pendingWrite = null
|
|
15
|
+
|
|
16
|
+
this._incoming
|
|
17
|
+
.on('data', this._ondata.bind(this))
|
|
18
|
+
.on('end', this._onend.bind(this))
|
|
19
|
+
.pause()
|
|
20
|
+
|
|
21
|
+
this._outgoing.on('drain', this._ondrain.bind(this))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
ref() {
|
|
25
|
+
this._incoming.ref()
|
|
26
|
+
this._outgoing.ref()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
unref() {
|
|
30
|
+
this._incoming.unref()
|
|
31
|
+
this._outgoing.unref()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_read() {
|
|
35
|
+
this._incoming.resume()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_write(chunk, encoding, cb) {
|
|
39
|
+
if (this._outgoing.write(chunk)) cb(null)
|
|
40
|
+
else this._pendingWrite = cb
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
_final(cb) {
|
|
44
|
+
this._outgoing.end()
|
|
45
|
+
cb(null)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
_ondata(data) {
|
|
49
|
+
if (this.push(data) === false) {
|
|
50
|
+
this._incoming.pause()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_onend() {
|
|
55
|
+
this.push(null)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_ondrain() {
|
|
59
|
+
if (this._pendingWrite === null) return
|
|
60
|
+
const cb = this._pendingWrite
|
|
61
|
+
this._pendingWrite = null
|
|
62
|
+
cb(null)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const IPC = module.exports
|
|
51
67
|
|
|
52
68
|
class IPCPort {
|
|
53
69
|
constructor(incoming, outgoing) {
|
package/lib/errors.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-ipc",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Lightweight pipe-based IPC for Bare",
|
|
5
5
|
"exports": {
|
|
6
|
-
".":
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"default": "./index.js"
|
|
9
|
+
},
|
|
7
10
|
"./package": "./package.json",
|
|
8
|
-
"./errors":
|
|
11
|
+
"./errors": {
|
|
12
|
+
"types": "./lib/errors.d.ts",
|
|
13
|
+
"default": "./lib/errors.js"
|
|
14
|
+
}
|
|
9
15
|
},
|
|
10
16
|
"files": [
|
|
11
17
|
"index.js",
|
|
18
|
+
"index.d.ts",
|
|
12
19
|
"lib"
|
|
13
20
|
],
|
|
14
21
|
"scripts": {
|
|
@@ -26,7 +33,8 @@
|
|
|
26
33
|
"homepage": "https://github.com/holepunchto/bare-ipc#readme",
|
|
27
34
|
"dependencies": {
|
|
28
35
|
"bare-pipe": "^4.0.0",
|
|
29
|
-
"bare-stream": "^2.1.3"
|
|
36
|
+
"bare-stream": "^2.1.3",
|
|
37
|
+
"bare-structured-clone": "^1.4.0"
|
|
30
38
|
},
|
|
31
39
|
"devDependencies": {
|
|
32
40
|
"brittle": "^3.2.1",
|