@agoric/network 0.1.1-orchestration-dev-096c4e8.0 → 0.1.1-other-dev-3eb1a1d.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/src/types.d.ts CHANGED
@@ -1,34 +1,43 @@
1
- type PromiseVow<T> = Promise<T | import('@agoric/vow').Vow<T>>;
2
- type Data = string | Buffer | ArrayBuffer;
3
- type Bytes = string;
1
+ /**
2
+ * Rearrange the exo types to make a cast of the methods (M) and init function (I) to a specific type.
3
+ */
4
+ export type ExoClassMethods<M extends import("@endo/exo").Methods, I extends (...args: any[]) => any> = M & ThisType<{
5
+ self: import("@endo/exo").Guarded<M>;
6
+ state: ReturnType<I>;
7
+ }>;
8
+ /**
9
+ * Each character code carries 8-bit octets. Eventually we want to use passable Uint8Arrays.
10
+ */
11
+ export type Bytes = string;
4
12
  /**
5
13
  * A local or remote address See multiaddr.js for an
6
14
  * opinionated router implementation
7
15
  */
8
- type Endpoint = string;
16
+ export type Endpoint = string;
9
17
  /**
10
18
  * A closable object
11
19
  */
12
- type Closable = {
20
+ export type ClosableI = {
13
21
  /**
14
22
  * Terminate the object
15
23
  */
16
24
  close: () => PromiseVow<void>;
17
25
  };
26
+ export type Closable = RemotableObject & ClosableI;
18
27
  /**
19
28
  * The network Protocol
20
29
  */
21
- type Protocol = {
30
+ export type Protocol = {
22
31
  /**
23
32
  * Claim a port, or if
24
33
  * ending in ENDPOINT_SEPARATOR, a fresh name
25
34
  */
26
- bind: (prefix: Endpoint) => PromiseVow<Port>;
35
+ bindPort: (prefix: Endpoint) => PromiseVow<Port>;
27
36
  };
28
37
  /**
29
38
  * A port that has been bound to a protocol
30
39
  */
31
- type Port = {
40
+ export type Port = {
32
41
  /**
33
42
  * Get the locally bound name of this
34
43
  * port
@@ -37,53 +46,52 @@ type Port = {
37
46
  /**
38
47
  * Begin accepting incoming connections
39
48
  */
40
- addListener: (acceptHandler: ListenHandler) => PromiseVow<void>;
49
+ addListener: (acceptHandler: Remote<ListenHandler>) => PromiseVow<void>;
41
50
  /**
42
51
  * Make an outbound connection
43
52
  */
44
- connect: (remote: Endpoint, connectionHandler?: ConnectionHandler) => PromiseVow<Connection>;
53
+ connect: (remote: Endpoint, connectionHandler?: Remote<ConnectionHandler>) => PromiseVow<Connection>;
45
54
  /**
46
55
  * Remove the currently-bound listener
47
56
  */
48
- removeListener: (acceptHandler: ListenHandler) => PromiseVow<void>;
57
+ removeListener: (acceptHandler: Remote<ListenHandler>) => PromiseVow<void>;
49
58
  /**
50
59
  * Deallocate the port entirely, removing all
51
60
  * listeners and closing all active connections
52
61
  */
53
- revoke: () => void;
62
+ revoke: () => PromiseVow<void>;
54
63
  };
55
64
  /**
56
65
  * A handler for incoming connections
57
66
  */
58
- type ListenHandler = {
67
+ export type ListenHandler = {
59
68
  /**
60
- * The
61
- * listener has been registered
69
+ * The listener has been registered
62
70
  */
63
- onListen?: ((port: Port, l: ListenHandler) => PromiseVow<void>) | undefined;
71
+ onListen?: ((port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>) | undefined;
64
72
  /**
65
73
  * A new connection is incoming
66
74
  */
67
- onAccept: (port: Port, localAddr: Endpoint, remoteAddr: Endpoint, l: ListenHandler) => PromiseVow<ConnectionHandler>;
75
+ onAccept: (port: Remote<Port>, localAddr: Endpoint, remoteAddr: Endpoint, l: Remote<ListenHandler>) => PromiseVow<Remote<ConnectionHandler>>;
68
76
  /**
69
77
  * The connection was rejected
70
78
  */
71
- onReject?: ((port: Port, localAddr: Endpoint, remoteAddr: Endpoint, l: ListenHandler) => PromiseVow<void>) | undefined;
79
+ onReject?: ((port: Remote<Port>, localAddr: Endpoint, remoteAddr: Endpoint, l: Remote<ListenHandler>) => PromiseVow<void>) | undefined;
72
80
  /**
73
81
  * There was an error while listening
74
82
  */
75
- onError?: ((port: Port, rej: any, l: ListenHandler) => PromiseVow<void>) | undefined;
83
+ onError?: ((port: Remote<Port>, rej: any, l: Remote<ListenHandler>) => PromiseVow<void>) | undefined;
76
84
  /**
77
85
  * The
78
86
  * listener has been removed
79
87
  */
80
- onRemove?: ((port: Port, l: ListenHandler) => PromiseVow<void>) | undefined;
88
+ onRemove?: ((port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>) | undefined;
81
89
  };
82
- type Connection = {
90
+ export type ConnectionI = {
83
91
  /**
84
92
  * Send a packet on the connection
85
93
  */
86
- send: (packetBytes: Data, opts?: Record<string, any>) => PromiseVow<Bytes>;
94
+ send: (packetBytes: Bytes, opts?: Record<string, any>) => PromiseVow<Bytes>;
87
95
  /**
88
96
  * Close both ends of the connection
89
97
  */
@@ -98,29 +106,30 @@ type Connection = {
98
106
  */
99
107
  getRemoteAddress: () => Endpoint;
100
108
  };
109
+ export type Connection = RemotableObject & ConnectionI;
101
110
  /**
102
111
  * A handler for a given Connection
103
112
  */
104
- type ConnectionHandler = {
113
+ export type ConnectionHandler = {
105
114
  /**
106
115
  * The connection has been opened
107
116
  */
108
- onOpen?: ((connection: Connection, localAddr: Endpoint, remoteAddr: Endpoint, c: ConnectionHandler) => PromiseVow<void>) | undefined;
117
+ onOpen?: ((connection: Remote<Connection>, localAddr: Endpoint, remoteAddr: Endpoint, c: Remote<ConnectionHandler>) => PromiseVow<void>) | undefined;
109
118
  /**
110
119
  * The connection received a packet
111
120
  */
112
- onReceive?: ((connection: Connection, ack: Bytes, c: ConnectionHandler, opts?: Record<string, any>) => PromiseVow<Data>) | undefined;
121
+ onReceive?: ((connection: Remote<Connection>, ack: Bytes, c: Remote<ConnectionHandler>, opts?: Record<string, any>) => PromiseVow<Bytes>) | undefined;
113
122
  /**
114
123
  * The connection has been closed
115
124
  */
116
- onClose?: ((connection: Connection, reason?: CloseReason, c?: ConnectionHandler) => PromiseVow<void>) | undefined;
125
+ onClose?: ((connection: Remote<Connection>, reason?: CloseReason, c?: Remote<ConnectionHandler>) => PromiseVow<void>) | undefined;
117
126
  };
118
127
  /**
119
128
  * The reason a connection was closed
120
129
  */
121
- type CloseReason = any | null;
122
- type AttemptDescription = {
123
- handler: ConnectionHandler;
130
+ export type CloseReason = any | null;
131
+ export type AttemptDescription = {
132
+ handler: Remote<ConnectionHandler>;
124
133
  remoteAddress?: string | undefined;
125
134
  localAddress?: string | undefined;
126
135
  };
@@ -128,44 +137,44 @@ type AttemptDescription = {
128
137
  * A handler for things the protocol
129
138
  * implementation will invoke
130
139
  */
131
- type ProtocolHandler = {
140
+ export type ProtocolHandler = {
132
141
  /**
133
142
  * This protocol is created
134
143
  */
135
- onCreate: (protocol: ProtocolImpl, p: ProtocolHandler) => PromiseVow<void>;
144
+ onCreate: (protocol: Remote<ProtocolImpl>, p: Remote<ProtocolHandler>) => PromiseVow<void>;
136
145
  /**
137
146
  * Create a fresh port identifier for this protocol
138
147
  */
139
- generatePortID: (localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<string>;
148
+ generatePortID: (localAddr: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<string>;
140
149
  /**
141
150
  * A port will be bound
142
151
  */
143
- onBind: (port: Port, localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<void>;
152
+ onBind: (port: Remote<Port>, localAddr: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<void>;
144
153
  /**
145
154
  * A port was listening
146
155
  */
147
- onListen: (port: Port, localAddr: Endpoint, listenHandler: ListenHandler, p: ProtocolHandler) => PromiseVow<void>;
156
+ onListen: (port: Remote<Port>, localAddr: Endpoint, listenHandler: Remote<ListenHandler>, p: Remote<ProtocolHandler>) => PromiseVow<void>;
148
157
  /**
149
158
  * A port listener has been reset
150
159
  */
151
- onListenRemove: (port: Port, localAddr: Endpoint, listenHandler: ListenHandler, p: ProtocolHandler) => PromiseVow<void>;
160
+ onListenRemove: (port: Remote<Port>, localAddr: Endpoint, listenHandler: Remote<ListenHandler>, p: Remote<ProtocolHandler>) => PromiseVow<void>;
152
161
  /**
153
162
  * Return unique suffix for local address
154
163
  */
155
- onInstantiate?: ((port: Port, localAddr: Endpoint, remote: Endpoint, p: ProtocolHandler) => PromiseVow<Endpoint>) | undefined;
164
+ onInstantiate?: ((port: Remote<Port>, localAddr: Endpoint, remote: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<Endpoint>) | undefined;
156
165
  /**
157
166
  * A port initiates an outbound connection
158
167
  */
159
- onConnect: (port: Port, localAddr: Endpoint, remote: Endpoint, c: ConnectionHandler, p: ProtocolHandler) => PromiseVow<AttemptDescription>;
168
+ onConnect: (port: Remote<Port>, localAddr: Endpoint, remote: Endpoint, c: Remote<ConnectionHandler>, p: Remote<ProtocolHandler>) => PromiseVow<AttemptDescription>;
160
169
  /**
161
170
  * The port is being completely destroyed
162
171
  */
163
- onRevoke: (port: Port, localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<void>;
172
+ onRevoke: (port: Remote<Port>, localAddr: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<void>;
164
173
  };
165
174
  /**
166
175
  * An inbound connection attempt
167
176
  */
168
- type InboundAttempt = {
177
+ export type InboundAttempt = {
169
178
  /**
170
179
  * Establish the connection
171
180
  */
@@ -188,12 +197,12 @@ type InboundAttempt = {
188
197
  /**
189
198
  * Things the protocol can do for us
190
199
  */
191
- type ProtocolImpl = {
200
+ export type ProtocolImpl = {
192
201
  /**
193
202
  * Claim a port, or if
194
203
  * ending in ENDPOINT_SEPARATOR, a fresh name
195
204
  */
196
- bind: (prefix: Endpoint) => PromiseVow<Port>;
205
+ bindPort: (prefix: Endpoint) => PromiseVow<Remote<Port>>;
197
206
  /**
198
207
  * Make an attempt to connect into this protocol
199
208
  */
@@ -201,6 +210,9 @@ type ProtocolImpl = {
201
210
  /**
202
211
  * Create an outbound connection
203
212
  */
204
- outbound: (port: Port, remoteAddr: Endpoint, connectionHandler: ConnectionHandler) => PromiseVow<Connection>;
213
+ outbound: (port: Remote<Port>, remoteAddr: Endpoint, connectionHandler: Remote<ConnectionHandler>) => PromiseVow<Connection>;
205
214
  };
215
+ import type { PromiseVow } from '@agoric/vow';
216
+ import type { RemotableObject } from '@endo/pass-style';
217
+ import type { Remote } from '@agoric/vow';
206
218
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["types.js"],"names":[],"mappings":"qBAIa,QAAQ,CAAC,GAAG,OAAO,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;YAIzC,MAAM,GAAG,MAAM,GAAG,WAAW;aAE7B,MAAM;;;;;gBAIN,MAAM;;;;;;;;WAML,MAAM,WAAW,IAAI,CAAC;;;;;;;;;;mBAKb,QAAQ,KAAK,WAAW,IAAI,CAAC;;;;;;;;;;qBAMtC,MAAM,QAAQ;;;;iCAEE,aAAa,KAAK,WAAW,IAAI,CAAC;;;;sBAGnD,QAAQ,sBACI,iBAAiB,KAClC,WAAW,UAAU,CAAC;;;;oCAEA,aAAa,KAAK,WAAW,IAAI,CAAC;;;;;YAElD,MAAM,IAAI;;;;;;;;;;uBAMH,IAAI,KAAK,aAAa,KAAK,WAAW,IAAI,CAAC;;;;qBAGrD,IAAI,aACC,QAAQ,cACP,QAAQ,KACjB,aAAa,KACb,WAAW,iBAAiB,CAAC;;;;uBAG1B,IAAI,aACC,QAAQ,cACP,QAAQ,KACjB,aAAa,KACb,WAAW,IAAI,CAAC;;;;sBAEH,IAAI,OAAO,GAAG,KAAK,aAAa,KAAK,WAAW,IAAI,CAAC;;;;;uBAErD,IAAI,KAAK,aAAa,KAAK,WAAW,IAAI,CAAC;;;;;;wBAO9C,IAAI,SACV,OAAO,MAAM,EAAE,GAAG,CAAC,KACvB,WAAW,KAAK,CAAC;;;;WAEX,MAAM,WAAW,IAAI,CAAC;;;;;qBACtB,MAAM,QAAQ;;;;sBAEd,MAAM,QAAQ;;;;;;;;;2BAMX,UAAU,aACX,QAAQ,cACP,QAAQ,KACjB,iBAAiB,KACjB,WAAW,IAAI,CAAC;;;;8BAGP,UAAU,OACjB,KAAK,KACP,iBAAiB,SACb,OAAO,MA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AAO,IAAI,CAAC,aACP,QAAQ,UACX,QAAQ,KACb,OAAO,eAAe,CAAC,KACvB,WAAW,QAAQ,CAAC;;;;eAEd,CACT,IAAI,EAAE,OAAO,IAAI,CAAC,EAClB,SAAS,EAAE,QAAQ,EACnB,MAAM,EAAE,QAAQ,EAChB,CAAC,EAAE,OAAO,iBAAiB,CAAC,EAC5B,CAAC,EAAE,OAAO,eAAe,CAAC,KACvB,WAAW,kBAAkB,CAAC;;;;cAExB,CACT,IAAI,EAAE,OAAO,IAAI,CAAC,EAClB,SAAS,EAAE,QAAQ,EACnB,CAAC,EAAE,OAAO,eAAe,CAAC,KACvB,WAAW,IAAI,CAAC;;;;;;;;;YAIV,CAAC,IAAI,EAAE,kBAAkB,KAAK,WAAW,UAAU,CAAC;;;;;qBAEpD,MAAM,QAAQ;;;;;sBAEd,MAAM,QAAQ;;;;WAEd,MAAM,WAAW,IAAI,CAAC;;;;;;;;;;cAGtB,CAAC,MAAM,EAAE,QAAQ,KAAK,WAAW,OAAO,IAAI,CAAC,CAAC;;;;aAE9C,CACT,UAAU,EAAE,QAAQ,EACpB,UAAU,EAAE,QAAQ,KACjB,WAAW,cAAc,CAAC;;;;cAEpB,CACT,IAAI,EAAE,OAAO,IAAI,CAAC,EAClB,UAAU,EAAE,QAAQ,EACpB,iBAAiB,EAAE,OAAO,iBAAiB,CAAC,KACzC,WAAW,UAAU,CAAC;;gCAhMO,aAAa;qCADN,kBAAkB;4BACzB,aAAa"}
package/src/types.js CHANGED
@@ -1,14 +1,22 @@
1
1
  // @ts-check
2
2
 
3
+ // Ensure this is a module.
4
+ export {};
5
+
3
6
  /**
4
- * @template T
5
- * @typedef {Promise<T | import('@agoric/vow').Vow<T>>} PromiseVow
7
+ * @import {Passable, RemotableObject} from '@endo/pass-style';
8
+ * @import {PromiseVow, Remote} from '@agoric/vow';
6
9
  */
7
10
 
8
11
  /**
9
- * @typedef {string | Buffer | ArrayBuffer} Data
10
- *
11
- * @typedef {string} Bytes
12
+ * @template {import('@endo/exo').Methods} M
13
+ * @template {(...args: any[]) => any} I
14
+ * @typedef {M & ThisType<{ self: import('@endo/exo').Guarded<M>, state: ReturnType<I> }>} ExoClassMethods
15
+ * Rearrange the exo types to make a cast of the methods (M) and init function (I) to a specific type.
16
+ */
17
+
18
+ /**
19
+ * @typedef {string} Bytes Each character code carries 8-bit octets. Eventually we want to use passable Uint8Arrays.
12
20
  */
13
21
 
14
22
  /**
@@ -17,13 +25,16 @@
17
25
  */
18
26
 
19
27
  /**
20
- * @typedef {object} Closable A closable object
28
+ * @typedef {object} ClosableI A closable object
21
29
  * @property {() => PromiseVow<void>} close Terminate the object
22
30
  */
31
+ /**
32
+ * @typedef {RemotableObject & ClosableI} Closable
33
+ */
23
34
 
24
35
  /**
25
36
  * @typedef {object} Protocol The network Protocol
26
- * @property {(prefix: Endpoint) => PromiseVow<Port>} bind Claim a port, or if
37
+ * @property {(prefix: Endpoint) => PromiseVow<Port>} bindPort Claim a port, or if
27
38
  * ending in ENDPOINT_SEPARATOR, a fresh name
28
39
  */
29
40
 
@@ -31,47 +42,46 @@
31
42
  * @typedef {object} Port A port that has been bound to a protocol
32
43
  * @property {() => Endpoint} getLocalAddress Get the locally bound name of this
33
44
  * port
34
- * @property {(acceptHandler: ListenHandler) => PromiseVow<void>} addListener
45
+ * @property {(acceptHandler: Remote<ListenHandler>) => PromiseVow<void>} addListener
35
46
  * Begin accepting incoming connections
36
47
  * @property {(
37
48
  * remote: Endpoint,
38
- * connectionHandler?: ConnectionHandler,
49
+ * connectionHandler?: Remote<ConnectionHandler>,
39
50
  * ) => PromiseVow<Connection>} connect
40
51
  * Make an outbound connection
41
- * @property {(acceptHandler: ListenHandler) => PromiseVow<void>} removeListener
52
+ * @property {(acceptHandler: Remote<ListenHandler>) => PromiseVow<void>} removeListener
42
53
  * Remove the currently-bound listener
43
- * @property {() => void} revoke Deallocate the port entirely, removing all
54
+ * @property {() => PromiseVow<void>} revoke Deallocate the port entirely, removing all
44
55
  * listeners and closing all active connections
45
56
  */
46
57
 
47
58
  /**
48
59
  * @typedef {object} ListenHandler A handler for incoming connections
49
- * @property {(port: Port, l: ListenHandler) => PromiseVow<void>} [onListen] The
50
- * listener has been registered
60
+ * @property {(port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>} [onListen] The listener has been registered
51
61
  * @property {(
52
- * port: Port,
62
+ * port: Remote<Port>,
53
63
  * localAddr: Endpoint,
54
64
  * remoteAddr: Endpoint,
55
- * l: ListenHandler,
56
- * ) => PromiseVow<ConnectionHandler>} onAccept
65
+ * l: Remote<ListenHandler>,
66
+ * ) => PromiseVow<Remote<ConnectionHandler>>} onAccept
57
67
  * A new connection is incoming
58
68
  * @property {(
59
- * port: Port,
69
+ * port: Remote<Port>,
60
70
  * localAddr: Endpoint,
61
71
  * remoteAddr: Endpoint,
62
- * l: ListenHandler,
72
+ * l: Remote<ListenHandler>,
63
73
  * ) => PromiseVow<void>} [onReject]
64
74
  * The connection was rejected
65
- * @property {(port: Port, rej: any, l: ListenHandler) => PromiseVow<void>} [onError]
75
+ * @property {(port: Remote<Port>, rej: any, l: Remote<ListenHandler>) => PromiseVow<void>} [onError]
66
76
  * There was an error while listening
67
- * @property {(port: Port, l: ListenHandler) => PromiseVow<void>} [onRemove] The
77
+ * @property {(port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>} [onRemove] The
68
78
  * listener has been removed
69
79
  */
70
80
 
71
81
  /**
72
- * @typedef {object} Connection
82
+ * @typedef {object} ConnectionI
73
83
  * @property {(
74
- * packetBytes: Data,
84
+ * packetBytes: Bytes,
75
85
  * opts?: Record<string, any>,
76
86
  * ) => PromiseVow<Bytes>} send
77
87
  * Send a packet on the connection
@@ -80,27 +90,30 @@
80
90
  * connection
81
91
  * @property {() => Endpoint} getRemoteAddress Get the name of the counterparty
82
92
  */
93
+ /**
94
+ * @typedef {RemotableObject & ConnectionI} Connection
95
+ */
83
96
 
84
97
  /**
85
98
  * @typedef {object} ConnectionHandler A handler for a given Connection
86
99
  * @property {(
87
- * connection: Connection,
100
+ * connection: Remote<Connection>,
88
101
  * localAddr: Endpoint,
89
102
  * remoteAddr: Endpoint,
90
- * c: ConnectionHandler,
103
+ * c: Remote<ConnectionHandler>,
91
104
  * ) => PromiseVow<void>} [onOpen]
92
105
  * The connection has been opened
93
106
  * @property {(
94
- * connection: Connection,
107
+ * connection: Remote<Connection>,
95
108
  * ack: Bytes,
96
- * c: ConnectionHandler,
109
+ * c: Remote<ConnectionHandler>,
97
110
  * opts?: Record<string, any>,
98
- * ) => PromiseVow<Data>} [onReceive]
111
+ * ) => PromiseVow<Bytes>} [onReceive]
99
112
  * The connection received a packet
100
113
  * @property {(
101
- * connection: Connection,
114
+ * connection: Remote<Connection>,
102
115
  * reason?: CloseReason,
103
- * c?: ConnectionHandler,
116
+ * c?: Remote<ConnectionHandler>,
104
117
  * ) => PromiseVow<void>} [onClose]
105
118
  * The connection has been closed
106
119
  *
@@ -109,7 +122,7 @@
109
122
 
110
123
  /**
111
124
  * @typedef {object} AttemptDescription
112
- * @property {ConnectionHandler} handler
125
+ * @property {Remote<ConnectionHandler>} handler
113
126
  * @property {Endpoint} [remoteAddress]
114
127
  * @property {Endpoint} [localAddress]
115
128
  */
@@ -117,49 +130,49 @@
117
130
  /**
118
131
  * @typedef {object} ProtocolHandler A handler for things the protocol
119
132
  * implementation will invoke
120
- * @property {(protocol: ProtocolImpl, p: ProtocolHandler) => PromiseVow<void>} onCreate
133
+ * @property {(protocol: Remote<ProtocolImpl>, p: Remote<ProtocolHandler>) => PromiseVow<void>} onCreate
121
134
  * This protocol is created
122
- * @property {(localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<string>} generatePortID
135
+ * @property {(localAddr: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<string>} generatePortID
123
136
  * Create a fresh port identifier for this protocol
124
137
  * @property {(
125
- * port: Port,
138
+ * port: Remote<Port>,
126
139
  * localAddr: Endpoint,
127
- * p: ProtocolHandler,
140
+ * p: Remote<ProtocolHandler>,
128
141
  * ) => PromiseVow<void>} onBind
129
142
  * A port will be bound
130
143
  * @property {(
131
- * port: Port,
144
+ * port: Remote<Port>,
132
145
  * localAddr: Endpoint,
133
- * listenHandler: ListenHandler,
134
- * p: ProtocolHandler,
146
+ * listenHandler: Remote<ListenHandler>,
147
+ * p: Remote<ProtocolHandler>,
135
148
  * ) => PromiseVow<void>} onListen
136
149
  * A port was listening
137
150
  * @property {(
138
- * port: Port,
151
+ * port: Remote<Port>,
139
152
  * localAddr: Endpoint,
140
- * listenHandler: ListenHandler,
141
- * p: ProtocolHandler,
153
+ * listenHandler: Remote<ListenHandler>,
154
+ * p: Remote<ProtocolHandler>,
142
155
  * ) => PromiseVow<void>} onListenRemove
143
156
  * A port listener has been reset
144
157
  * @property {(
145
- * port: Port,
158
+ * port: Remote<Port>,
146
159
  * localAddr: Endpoint,
147
160
  * remote: Endpoint,
148
- * p: ProtocolHandler,
161
+ * p: Remote<ProtocolHandler>,
149
162
  * ) => PromiseVow<Endpoint>} [onInstantiate]
150
163
  * Return unique suffix for local address
151
164
  * @property {(
152
- * port: Port,
165
+ * port: Remote<Port>,
153
166
  * localAddr: Endpoint,
154
167
  * remote: Endpoint,
155
- * c: ConnectionHandler,
156
- * p: ProtocolHandler,
168
+ * c: Remote<ConnectionHandler>,
169
+ * p: Remote<ProtocolHandler>,
157
170
  * ) => PromiseVow<AttemptDescription>} onConnect
158
171
  * A port initiates an outbound connection
159
172
  * @property {(
160
- * port: Port,
173
+ * port: Remote<Port>,
161
174
  * localAddr: Endpoint,
162
- * p: ProtocolHandler,
175
+ * p: Remote<ProtocolHandler>,
163
176
  * ) => PromiseVow<void>} onRevoke
164
177
  * The port is being completely destroyed
165
178
  *
@@ -173,7 +186,7 @@
173
186
  * @property {() => PromiseVow<void>} close Abort the attempt
174
187
  *
175
188
  * @typedef {object} ProtocolImpl Things the protocol can do for us
176
- * @property {(prefix: Endpoint) => PromiseVow<Port>} bind Claim a port, or if
189
+ * @property {(prefix: Endpoint) => PromiseVow<Remote<Port>>} bindPort Claim a port, or if
177
190
  * ending in ENDPOINT_SEPARATOR, a fresh name
178
191
  * @property {(
179
192
  * listenAddr: Endpoint,
@@ -181,9 +194,9 @@
181
194
  * ) => PromiseVow<InboundAttempt>} inbound
182
195
  * Make an attempt to connect into this protocol
183
196
  * @property {(
184
- * port: Port,
197
+ * port: Remote<Port>,
185
198
  * remoteAddr: Endpoint,
186
- * connectionHandler: ConnectionHandler,
199
+ * connectionHandler: Remote<ConnectionHandler>,
187
200
  * ) => PromiseVow<Connection>} outbound
188
201
  * Create an outbound connection
189
202
  */
package/exported.js DELETED
@@ -1 +0,0 @@
1
- import './src/types.js';
@@ -1,6 +0,0 @@
1
- {
2
- "extends": [
3
- "./tsconfig.json",
4
- "../../tsconfig-build-options.json"
5
- ]
6
- }
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "checkJs": false,
5
- "maxNodeModuleJsDepth": 1,
6
- },
7
- "include": [
8
- "*.js",
9
- "scripts/**/*.js",
10
- "src/**/*.js",
11
- "test/**/*.js",
12
- "tools/**/*.js",
13
- ],
14
- }
package/typedoc.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "extends": [
3
- "../../typedoc.base.json"
4
- ],
5
- "entryPoints": [
6
- "./src/index.js",
7
- "./src/types.js",
8
- ]
9
- }