bare-ipc 1.1.2 → 1.1.3

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/README.md CHANGED
@@ -27,66 +27,7 @@ b.on('data', (data) => {
27
27
 
28
28
  ## API
29
29
 
30
- ### `IPC`
31
-
32
- #### `const [portA, portB] = IPC.open()`
33
-
34
- Returns a pair of connected `IPCPort`s for constructing the IPC duplex stream based on `bare-pipe`. Each port is transferable and can be sent to another thread or process before being connected.
35
-
36
- #### `const ipc = new IPC(port)`
37
-
38
- Returns a duplex stream using the provided `port`. See `bare-stream`'s `Duplex` (<https://github.com/holepunchto/bare-stream>) for the duplex stream API.
39
-
40
- Errors emitted by the underlying incoming or outgoing pipes are propagated to the stream as `error` events, after which the stream is destroyed.
41
-
42
- #### `ipc.incoming`
43
-
44
- The underlying `bare-pipe` `Pipe` used for reading. Read-only.
45
-
46
- #### `ipc.outgoing`
47
-
48
- The underlying `bare-pipe` `Pipe` used for writing. Read-only.
49
-
50
- #### `ipc.ref()`
51
-
52
- Increase the reference count for the IPC to keep the event loop alive.
53
-
54
- A common pattern is to `ipc.ref()` on `Bare.on('resume')` and `ipc.unref()` on suspend like so:
55
-
56
- ```js
57
- Bare.on('suspend', () => ipc.unref()).on('resume', () => ipc.ref())
58
- ```
59
-
60
- #### `ipc.unref()`
61
-
62
- Decrease the reference count for the IPC to allow the event loop to exit.
63
-
64
- See `ipc.ref()` for the common pattern to keep the event loop alive.
65
-
66
- ### `IPCPort`
67
-
68
- #### `const port = new IPCPort(incoming, outgoing)`
69
-
70
- Constructs a port from a pair of file handles. The arguments are:
71
-
72
- - `incoming` is the read file handle.
73
- - `outgoing` is the write file handle.
74
-
75
- #### `port.connect()`
76
-
77
- Returns an `IPC` connected to the `port` and marks the `port` as detached.
78
-
79
- #### `port.incoming`
80
-
81
- The read file handle. Read-only.
82
-
83
- #### `port.outgoing`
84
-
85
- The write file handle. Read-only.
86
-
87
- #### `port.detached`
88
-
89
- A boolean for whether the `port` is detached. A port becomes detached once it is connected or transferred, and a detached port cannot be transferred again.
30
+ See the [`bare-ipc` reference](https://docs.pears.com/reference/bare/modules/bare-ipc).
90
31
 
91
32
  ## License
92
33
 
package/index.d.ts CHANGED
@@ -3,26 +3,49 @@ import Pipe from 'bare-pipe'
3
3
  import { Transferable, symbols } from 'bare-structured-clone'
4
4
 
5
5
  interface IPC extends Duplex {
6
+ /** The underlying `bare-pipe` `Pipe` used for reading. Read-only. */
6
7
  readonly incoming: Pipe
8
+ /** The underlying `bare-pipe` `Pipe` used for writing. Read-only. */
7
9
  readonly outgoing: Pipe
8
10
 
11
+ /** Increase the reference count for the IPC to keep the event loop alive. */
9
12
  ref(): this
13
+ /** Decrease the reference count for the IPC to allow the event loop to exit. */
10
14
  unref(): this
11
15
  }
12
16
 
13
17
  declare class IPC {
18
+ /**
19
+ * Returns a duplex stream using the provided `port`. See `bare-stream`'s `Duplex`
20
+ * (<https://github.com/holepunchto/bare-stream>) for the duplex stream API.
21
+ * @param port - The port to open the stream over, as returned by `IPC.open()`.
22
+ */
14
23
  constructor(port: IPCPort)
15
24
  }
16
25
 
17
26
  interface IPCPort extends Transferable<[incoming: number, outgoing: number]> {
27
+ /** The file handle used for reading. Read-only. */
18
28
  readonly incoming: number
29
+ /** The file handle used for writing. Read-only. */
19
30
  readonly outgoing: number
31
+ /**
32
+ * A boolean for whether the `port` is detached. A port becomes detached once it is connected or
33
+ * transferred, and a detached port cannot be transferred again.
34
+ */
20
35
  readonly detached: boolean
21
36
 
37
+ /**
38
+ * @returns An `IPC` duplex stream connected to the port.
39
+ */
22
40
  connect(): IPC
23
41
  }
24
42
 
25
43
  declare class IPCPort {
44
+ /**
45
+ * Constructs a port from a pair of file handles, `incoming` and `outgoing`.
46
+ * @param incoming - The file handle used for reading.
47
+ * @param outgoing - The file handle used for writing.
48
+ */
26
49
  constructor(incoming: number, outgoing: number)
27
50
 
28
51
  static [symbols.attach](input: [incoming: number, outgoing: number]): IPCPort
@@ -31,6 +54,12 @@ declare class IPCPort {
31
54
  declare namespace IPC {
32
55
  export { IPCPort }
33
56
 
57
+ /**
58
+ * Returns a pair of connected `IPCPort`s for constructing the IPC duplex stream based on
59
+ * `bare-pipe`. Each port is transferable and can be sent to another thread or process before
60
+ * being connected.
61
+ * @returns A pair of connected ports, one for each end of the IPC channel.
62
+ */
34
63
  export function open(): [IPCPort, IPCPort]
35
64
  }
36
65
 
package/lib/errors.d.ts CHANGED
@@ -1,4 +1,10 @@
1
1
  declare class IPCError extends Error {
2
+ /**
3
+ * Create the error thrown when transferring a port that has already been connected or
4
+ * transferred.
5
+ * @param msg - The error message.
6
+ * @returns An error with code `ALREADY_CONNECTED`.
7
+ */
2
8
  static ALREADY_CONNECTED(msg: string): IPCError
3
9
  }
4
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-ipc",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Lightweight pipe-based IPC for Bare",
5
5
  "exports": {
6
6
  ".": {
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "bare-pipe": "^4.0.0",
38
38
  "bare-stream": "^2.1.3",
39
- "bare-structured-clone": "^1.4.0"
39
+ "bare-structured-clone": "^2.0.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "brittle": "^3.2.1",