@agoric/network 0.1.1-dev-501c093.0 → 0.1.1-dev-db972d4.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.js CHANGED
@@ -2,13 +2,23 @@
2
2
 
3
3
  /**
4
4
  * @template T
5
- * @typedef {Promise<T | import('@agoric/vow').Vow<T>>} PromiseVow
5
+ * @typedef {import('@agoric/vow').PromiseVow<T>} PromiseVow
6
6
  */
7
7
 
8
8
  /**
9
- * @typedef {string | Buffer | ArrayBuffer} Data
10
- *
11
- * @typedef {string} Bytes
9
+ * @template T
10
+ * @typedef {import('@agoric/vow').Remote<T>} Remote
11
+ */
12
+
13
+ /**
14
+ * @template {import('@endo/exo/src/exo-makers').Methods} M
15
+ * @template {(...args: any[]) => any} I
16
+ * @typedef {M & ThisType<{ self: import('@endo/exo/src/exo-makers').Guarded<M>, state: ReturnType<I> }>} ExoClassMethods
17
+ * Rearrange the exo types to make a cast of the methods (M) and init function (I) to a specific type.
18
+ */
19
+
20
+ /**
21
+ * @typedef {string} Bytes Each character code carries 8-bit octets. Eventually we want to use passable Uint8Arrays.
12
22
  */
13
23
 
14
24
  /**
@@ -31,14 +41,14 @@
31
41
  * @typedef {object} Port A port that has been bound to a protocol
32
42
  * @property {() => Endpoint} getLocalAddress Get the locally bound name of this
33
43
  * port
34
- * @property {(acceptHandler: ListenHandler) => PromiseVow<void>} addListener
44
+ * @property {(acceptHandler: Remote<ListenHandler>) => PromiseVow<void>} addListener
35
45
  * Begin accepting incoming connections
36
46
  * @property {(
37
47
  * remote: Endpoint,
38
- * connectionHandler?: ConnectionHandler,
48
+ * connectionHandler?: Remote<ConnectionHandler>,
39
49
  * ) => PromiseVow<Connection>} connect
40
50
  * Make an outbound connection
41
- * @property {(acceptHandler: ListenHandler) => PromiseVow<void>} removeListener
51
+ * @property {(acceptHandler: Remote<ListenHandler>) => PromiseVow<void>} removeListener
42
52
  * Remove the currently-bound listener
43
53
  * @property {() => PromiseVow<void>} revoke Deallocate the port entirely, removing all
44
54
  * listeners and closing all active connections
@@ -46,32 +56,31 @@
46
56
 
47
57
  /**
48
58
  * @typedef {object} ListenHandler A handler for incoming connections
49
- * @property {(port: Port, l: ListenHandler) => PromiseVow<void>} [onListen] The
50
- * listener has been registered
59
+ * @property {(port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>} [onListen] The listener has been registered
51
60
  * @property {(
52
- * port: Port,
61
+ * port: Remote<Port>,
53
62
  * localAddr: Endpoint,
54
63
  * remoteAddr: Endpoint,
55
- * l: ListenHandler,
56
- * ) => PromiseVow<ConnectionHandler>} onAccept
64
+ * l: Remote<ListenHandler>,
65
+ * ) => PromiseVow<Remote<ConnectionHandler>>} onAccept
57
66
  * A new connection is incoming
58
67
  * @property {(
59
- * port: Port,
68
+ * port: Remote<Port>,
60
69
  * localAddr: Endpoint,
61
70
  * remoteAddr: Endpoint,
62
- * l: ListenHandler,
71
+ * l: Remote<ListenHandler>,
63
72
  * ) => PromiseVow<void>} [onReject]
64
73
  * The connection was rejected
65
- * @property {(port: Port, rej: any, l: ListenHandler) => PromiseVow<void>} [onError]
74
+ * @property {(port: Remote<Port>, rej: any, l: Remote<ListenHandler>) => PromiseVow<void>} [onError]
66
75
  * There was an error while listening
67
- * @property {(port: Port, l: ListenHandler) => PromiseVow<void>} [onRemove] The
76
+ * @property {(port: Remote<Port>, l: Remote<ListenHandler>) => PromiseVow<void>} [onRemove] The
68
77
  * listener has been removed
69
78
  */
70
79
 
71
80
  /**
72
81
  * @typedef {object} Connection
73
82
  * @property {(
74
- * packetBytes: Data,
83
+ * packetBytes: Bytes,
75
84
  * opts?: Record<string, any>,
76
85
  * ) => PromiseVow<Bytes>} send
77
86
  * Send a packet on the connection
@@ -84,23 +93,23 @@
84
93
  /**
85
94
  * @typedef {object} ConnectionHandler A handler for a given Connection
86
95
  * @property {(
87
- * connection: Connection,
96
+ * connection: Remote<Connection>,
88
97
  * localAddr: Endpoint,
89
98
  * remoteAddr: Endpoint,
90
- * c: ConnectionHandler,
99
+ * c: Remote<ConnectionHandler>,
91
100
  * ) => PromiseVow<void>} [onOpen]
92
101
  * The connection has been opened
93
102
  * @property {(
94
- * connection: Connection,
103
+ * connection: Remote<Connection>,
95
104
  * ack: Bytes,
96
- * c: ConnectionHandler,
105
+ * c: Remote<ConnectionHandler>,
97
106
  * opts?: Record<string, any>,
98
- * ) => PromiseVow<Data>} [onReceive]
107
+ * ) => PromiseVow<Bytes>} [onReceive]
99
108
  * The connection received a packet
100
109
  * @property {(
101
- * connection: Connection,
110
+ * connection: Remote<Connection>,
102
111
  * reason?: CloseReason,
103
- * c?: ConnectionHandler,
112
+ * c?: Remote<ConnectionHandler>,
104
113
  * ) => PromiseVow<void>} [onClose]
105
114
  * The connection has been closed
106
115
  *
@@ -109,7 +118,7 @@
109
118
 
110
119
  /**
111
120
  * @typedef {object} AttemptDescription
112
- * @property {ConnectionHandler} handler
121
+ * @property {Remote<ConnectionHandler>} handler
113
122
  * @property {Endpoint} [remoteAddress]
114
123
  * @property {Endpoint} [localAddress]
115
124
  */
@@ -117,49 +126,49 @@
117
126
  /**
118
127
  * @typedef {object} ProtocolHandler A handler for things the protocol
119
128
  * implementation will invoke
120
- * @property {(protocol: ProtocolImpl, p: ProtocolHandler) => PromiseVow<void>} onCreate
129
+ * @property {(protocol: Remote<ProtocolImpl>, p: Remote<ProtocolHandler>) => PromiseVow<void>} onCreate
121
130
  * This protocol is created
122
- * @property {(localAddr: Endpoint, p: ProtocolHandler) => PromiseVow<string>} generatePortID
131
+ * @property {(localAddr: Endpoint, p: Remote<ProtocolHandler>) => PromiseVow<string>} generatePortID
123
132
  * Create a fresh port identifier for this protocol
124
133
  * @property {(
125
- * port: Port,
134
+ * port: Remote<Port>,
126
135
  * localAddr: Endpoint,
127
- * p: ProtocolHandler,
136
+ * p: Remote<ProtocolHandler>,
128
137
  * ) => PromiseVow<void>} onBind
129
138
  * A port will be bound
130
139
  * @property {(
131
- * port: Port,
140
+ * port: Remote<Port>,
132
141
  * localAddr: Endpoint,
133
- * listenHandler: ListenHandler,
134
- * p: ProtocolHandler,
142
+ * listenHandler: Remote<ListenHandler>,
143
+ * p: Remote<ProtocolHandler>,
135
144
  * ) => PromiseVow<void>} onListen
136
145
  * A port was listening
137
146
  * @property {(
138
- * port: Port,
147
+ * port: Remote<Port>,
139
148
  * localAddr: Endpoint,
140
- * listenHandler: ListenHandler,
141
- * p: ProtocolHandler,
149
+ * listenHandler: Remote<ListenHandler>,
150
+ * p: Remote<ProtocolHandler>,
142
151
  * ) => PromiseVow<void>} onListenRemove
143
152
  * A port listener has been reset
144
153
  * @property {(
145
- * port: Port,
154
+ * port: Remote<Port>,
146
155
  * localAddr: Endpoint,
147
156
  * remote: Endpoint,
148
- * p: ProtocolHandler,
157
+ * p: Remote<ProtocolHandler>,
149
158
  * ) => PromiseVow<Endpoint>} [onInstantiate]
150
159
  * Return unique suffix for local address
151
160
  * @property {(
152
- * port: Port,
161
+ * port: Remote<Port>,
153
162
  * localAddr: Endpoint,
154
163
  * remote: Endpoint,
155
- * c: ConnectionHandler,
156
- * p: ProtocolHandler,
164
+ * c: Remote<ConnectionHandler>,
165
+ * p: Remote<ProtocolHandler>,
157
166
  * ) => PromiseVow<AttemptDescription>} onConnect
158
167
  * A port initiates an outbound connection
159
168
  * @property {(
160
- * port: Port,
169
+ * port: Remote<Port>,
161
170
  * localAddr: Endpoint,
162
- * p: ProtocolHandler,
171
+ * p: Remote<ProtocolHandler>,
163
172
  * ) => PromiseVow<void>} onRevoke
164
173
  * The port is being completely destroyed
165
174
  *
@@ -173,7 +182,7 @@
173
182
  * @property {() => PromiseVow<void>} close Abort the attempt
174
183
  *
175
184
  * @typedef {object} ProtocolImpl Things the protocol can do for us
176
- * @property {(prefix: Endpoint) => PromiseVow<Port>} bind Claim a port, or if
185
+ * @property {(prefix: Endpoint) => PromiseVow<Remote<Port>>} bind Claim a port, or if
177
186
  * ending in ENDPOINT_SEPARATOR, a fresh name
178
187
  * @property {(
179
188
  * listenAddr: Endpoint,
@@ -181,9 +190,9 @@
181
190
  * ) => PromiseVow<InboundAttempt>} inbound
182
191
  * Make an attempt to connect into this protocol
183
192
  * @property {(
184
- * port: Port,
193
+ * port: Remote<Port>,
185
194
  * remoteAddr: Endpoint,
186
- * connectionHandler: ConnectionHandler,
195
+ * connectionHandler: Remote<ConnectionHandler>,
187
196
  * ) => PromiseVow<Connection>} outbound
188
197
  * Create an outbound connection
189
198
  */