@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/router.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @import {Endpoint, Port, Protocol, ProtocolHandler} from './types.js';
3
+ * @import {PromiseVow, Remote, VowTools} from '@agoric/vow';
4
+ */
1
5
  /**
2
6
  * @template T
3
7
  * @typedef {object} Router A delimited string router implementation
@@ -13,7 +17,7 @@ export const RouterI: import("@endo/patterns").InterfaceGuard<{
13
17
  register: import("@endo/patterns").MethodGuard;
14
18
  unregister: import("@endo/patterns").MethodGuard;
15
19
  }>;
16
- export function prepareRouter<T>(zone: import('@agoric/base-zone').Zone): () => import("@endo/exo/src/exo-makers.js").Guarded<{
20
+ export function prepareRouter<T>(zone: import("@agoric/base-zone").Zone): () => import("@endo/exo").Guarded<{
17
21
  /** @param {Endpoint} addr */
18
22
  getRoutes(addr: Endpoint): [string, T][];
19
23
  /**
@@ -27,35 +31,28 @@ export function prepareRouter<T>(zone: import('@agoric/base-zone').Zone): () =>
27
31
  */
28
32
  unregister(prefix: string, route: T): void;
29
33
  }>;
30
- export function prepareRouterProtocol(zone: import('@agoric/base-zone').Zone, powers: ReturnType<(zone: import("@agoric/base-zone").Zone, powers?: {
31
- isRetryableReason?: ((reason: any) => boolean) | undefined;
32
- watchPromise?: ((p: PromiseLike<any>, watcher: import("@agoric/vow/src/watch-promise.js").PromiseWatcher, ...args: unknown[]) => void) | undefined;
33
- } | undefined) => {
34
- when: <T = any, TResult1 = import("@agoric/vow/src/E.js").Unwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow/src/E.js").Unwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
35
- watch: <T_1 = any, TResult1_1 = T_1, TResult2_1 = T_1>(specimenP: import("@agoric/vow").ERef<T_1 | import("@agoric/vow").Vow<T_1>>, watcher?: import("@agoric/vow").Watcher<T_1, TResult1_1, TResult2_1> | undefined, watcherContext?: unknown) => import("@agoric/vow").Vow<TResult1_1 | TResult2_1>;
36
- makeVowKit: <T_2>() => import("@agoric/vow").VowKit<T_2>;
37
- }>, E?: ((<T_3>(x: T_3) => import("@endo/eventual-send/src/E.js").ECallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T_3>>) & {
38
- readonly get: <T_1>(x: T_1) => import("@endo/eventual-send/src/E.js").EGetters<import("@endo/eventual-send").LocalRecord<T_1>>;
34
+ export function prepareRouterProtocol(zone: import("@agoric/base-zone").Zone, powers: import("./network.js").Powers, E?: ((<T>(x: T) => import("../../../node_modules/@endo/eventual-send/src/E.js").ECallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T>>) & {
35
+ readonly get: <T>(x: T) => import("../../../node_modules/@endo/eventual-send/src/E.js").EGetters<import("@endo/eventual-send").LocalRecord<T>>;
39
36
  readonly resolve: {
40
37
  (): Promise<void>;
41
- <T_2>(value: T_2): Promise<Awaited<T_2>>;
42
- <T_3>(value: T_3 | PromiseLike<T_3>): Promise<Awaited<T_3>>;
38
+ <T>(value: T): Promise<Awaited<T>>;
39
+ <T>(value: T | PromiseLike<T>): Promise<Awaited<T>>;
43
40
  };
44
- readonly sendOnly: <T_4>(x: T_4) => import("@endo/eventual-send/src/E.js").ESendOnlyCallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T_4>>;
45
- readonly when: <T_5, U = T_5>(x: T_5 | PromiseLike<T_5>, onfulfilled?: ((value: T_5) => import("@endo/eventual-send").ERef<U>) | undefined, onrejected?: ((reason: any) => import("@endo/eventual-send").ERef<U>) | undefined) => Promise<U>;
46
- }) | undefined): () => import("@endo/exo/src/exo-makers.js").Guarded<{
41
+ readonly sendOnly: <T>(x: T) => import("../../../node_modules/@endo/eventual-send/src/E.js").ESendOnlyCallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T>>;
42
+ readonly when: <T, U = T>(x: T | PromiseLike<T>, onfulfilled?: ((value: T) => import("@endo/eventual-send").ERef<U>) | undefined, onrejected?: ((reason: any) => import("@endo/eventual-send").ERef<U>) | undefined) => Promise<U>;
43
+ }) | undefined): () => import("@endo/exo").Guarded<{
47
44
  /**
48
45
  * @param {string[]} paths
49
- * @param {ProtocolHandler} protocolHandler
46
+ * @param {Remote<ProtocolHandler>} protocolHandler
50
47
  */
51
- registerProtocolHandler(paths: string[], protocolHandler: ProtocolHandler): void;
48
+ registerProtocolHandler(paths: string[], protocolHandler: Remote<ProtocolHandler>): void;
52
49
  /**
53
50
  * @param {string} prefix
54
- * @param {ProtocolHandler} protocolHandler
51
+ * @param {Remote<ProtocolHandler>} protocolHandler
55
52
  */
56
- unregisterProtocolHandler(prefix: string, protocolHandler: ProtocolHandler): void;
53
+ unregisterProtocolHandler(prefix: string, protocolHandler: Remote<ProtocolHandler>): void;
57
54
  /** @param {Endpoint} localAddr */
58
- bind(localAddr: Endpoint): Promise<Port | import("@agoric/vow").Vow<Port>>;
55
+ bindPort(localAddr: Endpoint): Promise<Port | import("@agoric/vow").Vow<Port>>;
59
56
  }>;
60
57
  /**
61
58
  * A delimited string router implementation
@@ -78,8 +75,13 @@ export type Router<T> = {
78
75
  unregister: (prefix: string, route: T) => void;
79
76
  };
80
77
  export type RouterProtocol = {
81
- bind: (prefix: string) => PromiseVow<Port>;
78
+ bindPort: (prefix: string) => PromiseVow<Port>;
82
79
  registerProtocolHandler: (paths: string[], protocolHandler: ProtocolHandler) => void;
83
80
  unregisterProtocolHandler: (prefix: string, protocolHandler: ProtocolHandler) => void;
84
81
  };
82
+ import type { Endpoint } from './types.js';
83
+ import type { ProtocolHandler } from './types.js';
84
+ import type { Remote } from '@agoric/vow';
85
+ import type { Port } from './types.js';
86
+ import type { PromiseVow } from '@agoric/vow';
85
87
  //# sourceMappingURL=router.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["router.js"],"names":[],"mappings":"AAaA;;;;;;;;;GASG;AAEH;;;;GAIG;AAMI,uCAFI,OAAO,mBAAmB,EAAE,IAAI;IAiBrC,6BAA6B;oBAAjB,QAAQ;IAyBpB;;;OAGG;qBAFQ,MAAM;IAMjB;;;OAGG;uBAFQ,MAAM;GAYtB;AAgBM,4CAJI,OAAO,mBAAmB,EAAE,IAAI,UAChC;;;;;;;EAAiD;;;;;;;;;;IAoCtD;;;OAGG;mCAFQ,MAAM,EAAE,mBACR,eAAe;IAY1B;;;OAGG;sCAFQ,MAAM,mBACN,eAAe;IAc1B,kCAAkC;oBAAtB,QAAQ;GAUzB;;;;;;;;;sBAvKoB,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE;;;;;uBAEtB,MAAM,SAAS,CAAC,KAAK,IAAI;;;;;yBAEzB,MAAM,SAAS,CAAC,KAAK,IAAI;;;mBA8EzB,MAAM,KAAK,WAAW,IAAI,CAAC;qCAC5B,MAAM,EAAE,mBAAmB,eAAe,KAAK,IAAI;wCAClD,MAAM,mBAAmB,eAAe,KAAK,IAAI"}
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["router.js"],"names":[],"mappings":"AAWA;;;GAGG;AAEH;;;;;;;;;GASG;AAEH;;;;GAIG;AAMI,8BAHM,CAAC,QACH,OAAO,mBAAmB,EAAE,IAAI;IAiBrC,6BAA6B;oBAAjB,QAAQ;IAyBpB;;;OAGG;qBAFQ,MAAM,SACN,CAAC;IAKZ;;;OAGG;uBAFQ,MAAM,SACN,CAAC;GAWjB;AAgBM,4CAJI,OAAO,mBAAmB,EAAE,IAAI,UAChC,OAAO,cAAc,EAAE,MAAM;;;;;;;;gEAjGR,CAAC,+EAItB,CAAC;;IAiIN;;;OAGG;mCAFQ,MAAM,EAAE,mBACR,OAAO,eAAe,CAAC;IAYlC;;;OAGG;sCAFQ,MAAM,mBACN,OAAO,eAAe,CAAC;IAclC,kCAAkC;wBAAtB,QAAQ;GAUzB;;;;mBAzKY,CAAC;;;;;eAEA,CAAC,IAAI,EAAE,MAAM,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE;;;;;cAE/B,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI;;;;;gBAElC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI;;;cA8ElC,CAAC,MAAM,EAAE,MAAM,KAAK,WAAW,IAAI,CAAC;6BACpC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,eAAe,KAAK,IAAI;+BAC3D,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,eAAe,KAAK,IAAI;;8BA3FZ,YAAY;qCAAZ,YAAY;4BACzB,aAAa;0BADA,YAAY;gCACzB,aAAa"}
package/src/router.js CHANGED
@@ -1,15 +1,18 @@
1
1
  // @ts-check
2
+
3
+ /// <reference types="@agoric/store/exported.js" />
4
+ /// <reference path="./types.js" />
5
+
6
+ import { Fail } from '@endo/errors';
2
7
  import { E as defaultE } from '@endo/far';
3
8
  import { M } from '@endo/patterns';
4
- import { Fail } from '@agoric/assert';
5
- import {
6
- ENDPOINT_SEPARATOR,
7
- Shape,
8
- prepareNetworkProtocol,
9
- } from './network.js';
10
-
11
- import '@agoric/store/exported.js';
12
- /// <reference path="./types.js" />
9
+ import { ENDPOINT_SEPARATOR, prepareNetworkProtocol } from './network.js';
10
+ import { Shape } from './shapes.js';
11
+
12
+ /**
13
+ * @import {Endpoint, Port, Protocol, ProtocolHandler} from './types.js';
14
+ * @import {PromiseVow, Remote, VowTools} from '@agoric/vow';
15
+ */
13
16
 
14
17
  /**
15
18
  * @template T
@@ -59,7 +62,7 @@ export const prepareRouter = zone => {
59
62
  ret.push([prefix, this.state.prefixToRoute.get(prefix)]);
60
63
  }
61
64
  // Trim off the last value (after the slash).
62
- const defaultPrefix = prefix.substr(
65
+ const defaultPrefix = prefix.slice(
63
66
  0,
64
67
  prefix.lastIndexOf(ENDPOINT_SEPARATOR) + 1,
65
68
  );
@@ -96,7 +99,7 @@ export const prepareRouter = zone => {
96
99
 
97
100
  /**
98
101
  * @typedef {object} RouterProtocol
99
- * @property {(prefix: string) => PromiseVow<Port>} bind
102
+ * @property {(prefix: string) => PromiseVow<Port>} bindPort
100
103
  * @property {(paths: string[], protocolHandler: ProtocolHandler) => void} registerProtocolHandler
101
104
  * @property {(prefix: string, protocolHandler: ProtocolHandler) => void} unregisterProtocolHandler
102
105
  */
@@ -105,7 +108,7 @@ export const prepareRouter = zone => {
105
108
  * Create a router that behaves like a Protocol.
106
109
  *
107
110
  * @param {import('@agoric/base-zone').Zone} zone
108
- * @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
111
+ * @param {import('./network.js').Powers} powers
109
112
  * @param {typeof defaultE} [E] Eventual sender
110
113
  */
111
114
  export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
@@ -122,7 +125,7 @@ export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
122
125
  M.remotable(),
123
126
  ).returns(),
124
127
  unregisterProtocolHandler: M.call(M.string(), M.remotable()).returns(),
125
- bind: M.callWhen(Shape.Endpoint).returns(Shape.Vow$(Shape.Port)),
128
+ bindPort: M.callWhen(Shape.Endpoint).returns(Shape.Vow$(Shape.Port)),
126
129
  }),
127
130
  () => {
128
131
  /** @type {Router<Protocol>} */
@@ -131,7 +134,7 @@ export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
131
134
  /** @type {MapStore<string, Protocol>} */
132
135
  const protocols = detached.mapStore('prefix');
133
136
 
134
- /** @type {MapStore<string, ProtocolHandler>} */
137
+ /** @type {MapStore<string, Remote<ProtocolHandler>>} */
135
138
  const protocolHandlers = detached.mapStore('prefix');
136
139
 
137
140
  return {
@@ -143,7 +146,7 @@ export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
143
146
  {
144
147
  /**
145
148
  * @param {string[]} paths
146
- * @param {ProtocolHandler} protocolHandler
149
+ * @param {Remote<ProtocolHandler>} protocolHandler
147
150
  */
148
151
  registerProtocolHandler(paths, protocolHandler) {
149
152
  const protocol = makeNetworkProtocol(protocolHandler);
@@ -157,13 +160,13 @@ export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
157
160
  // Needs to account for multiple paths.
158
161
  /**
159
162
  * @param {string} prefix
160
- * @param {ProtocolHandler} protocolHandler
163
+ * @param {Remote<ProtocolHandler>} protocolHandler
161
164
  */
162
165
  unregisterProtocolHandler(prefix, protocolHandler) {
163
166
  const ph = this.state.protocolHandlers.get(prefix);
164
167
  ph === protocolHandler ||
165
168
  Fail`Protocol handler is not registered at prefix ${prefix}`;
166
- // TODO: unmap protocol hanlders to their corresponding protocol
169
+ // TODO: unmap protocol handlers to their corresponding protocol
167
170
  // e.g. using a map
168
171
  // before unregistering
169
172
  // @ts-expect-error note FIXME above
@@ -172,10 +175,10 @@ export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
172
175
  this.state.protocolHandlers.delete(prefix);
173
176
  },
174
177
  /** @param {Endpoint} localAddr */
175
- async bind(localAddr) {
178
+ async bindPort(localAddr) {
176
179
  const [route] = this.state.router.getRoutes(localAddr);
177
180
  route !== undefined || Fail`No registered router for ${localAddr}`;
178
- return E(route[1]).bind(localAddr);
181
+ return E(route[1]).bindPort(localAddr);
179
182
  },
180
183
  },
181
184
  );
@@ -0,0 +1,117 @@
1
+ export namespace Shape {
2
+ namespace ConnectionI {
3
+ let connection: import("@endo/patterns").InterfaceGuard<{
4
+ send: import("@endo/patterns").MethodGuard;
5
+ close: import("@endo/patterns").MethodGuard;
6
+ getLocalAddress: import("@endo/patterns").MethodGuard;
7
+ getRemoteAddress: import("@endo/patterns").MethodGuard;
8
+ }>;
9
+ let openConnectionAckWatcher: import("@endo/patterns").InterfaceGuard<{
10
+ onFulfilled: import("@endo/patterns").MethodGuard;
11
+ }>;
12
+ let rethrowUnlessMissingWatcher: import("@endo/patterns").InterfaceGuard<{
13
+ onRejected: import("@endo/patterns").MethodGuard;
14
+ }>;
15
+ let sinkWatcher: import("@endo/patterns").InterfaceGuard<{
16
+ onFulfilled: import("@endo/patterns").MethodGuard;
17
+ }>;
18
+ }
19
+ namespace InboundAttemptI {
20
+ export let inboundAttempt: import("@endo/patterns").InterfaceGuard<{
21
+ accept: import("@endo/patterns").MethodGuard;
22
+ getLocalAddress: import("@endo/patterns").MethodGuard;
23
+ getRemoteAddress: import("@endo/patterns").MethodGuard;
24
+ close: import("@endo/patterns").MethodGuard;
25
+ }>;
26
+ export let inboundAttemptAcceptWatcher: import("@endo/patterns").InterfaceGuard<{
27
+ onFulfilled: import("@endo/patterns").MethodGuard;
28
+ }>;
29
+ let rethrowUnlessMissingWatcher_1: import("@endo/patterns").InterfaceGuard<{
30
+ onRejected: import("@endo/patterns").MethodGuard;
31
+ }>;
32
+ export { rethrowUnlessMissingWatcher_1 as rethrowUnlessMissingWatcher };
33
+ let sinkWatcher_1: import("@endo/patterns").InterfaceGuard<{
34
+ onFulfilled: import("@endo/patterns").MethodGuard;
35
+ }>;
36
+ export { sinkWatcher_1 as sinkWatcher };
37
+ }
38
+ namespace PortI {
39
+ export let port: import("@endo/patterns").InterfaceGuard<{
40
+ getLocalAddress: import("@endo/patterns").MethodGuard;
41
+ addListener: import("@endo/patterns").MethodGuard;
42
+ connect: import("@endo/patterns").MethodGuard;
43
+ removeListener: import("@endo/patterns").MethodGuard;
44
+ revoke: import("@endo/patterns").MethodGuard;
45
+ }>;
46
+ export let portAddListenerWatcher: import("@endo/patterns").InterfaceGuard<{
47
+ onFulfilled: import("@endo/patterns").MethodGuard;
48
+ }>;
49
+ export let portRemoveListenerWatcher: import("@endo/patterns").InterfaceGuard<{
50
+ onFulfilled: import("@endo/patterns").MethodGuard;
51
+ }>;
52
+ export let portConnectWatcher: import("@endo/patterns").InterfaceGuard<{
53
+ onFulfilled: import("@endo/patterns").MethodGuard;
54
+ }>;
55
+ export let portRevokeWatcher: import("@endo/patterns").InterfaceGuard<{
56
+ onFulfilled: import("@endo/patterns").MethodGuard;
57
+ }>;
58
+ export let portRevokeCleanupWatcher: import("@endo/patterns").InterfaceGuard<{
59
+ onFulfilled: import("@endo/patterns").MethodGuard;
60
+ }>;
61
+ let rethrowUnlessMissingWatcher_2: import("@endo/patterns").InterfaceGuard<{
62
+ onRejected: import("@endo/patterns").MethodGuard;
63
+ }>;
64
+ export { rethrowUnlessMissingWatcher_2 as rethrowUnlessMissingWatcher };
65
+ let sinkWatcher_2: import("@endo/patterns").InterfaceGuard<{
66
+ onFulfilled: import("@endo/patterns").MethodGuard;
67
+ onRejected: import("@endo/patterns").MethodGuard;
68
+ }>;
69
+ export { sinkWatcher_2 as sinkWatcher };
70
+ }
71
+ namespace ProtocolHandlerI {
72
+ export let protocolHandler: import("@endo/patterns").InterfaceGuard<{
73
+ onCreate: import("@endo/patterns").MethodGuard;
74
+ generatePortID: import("@endo/patterns").MethodGuard;
75
+ onBind: import("@endo/patterns").MethodGuard;
76
+ onListen: import("@endo/patterns").MethodGuard;
77
+ onListenRemove: import("@endo/patterns").MethodGuard;
78
+ onInstantiate: import("@endo/patterns").MethodGuard;
79
+ onConnect: import("@endo/patterns").MethodGuard;
80
+ onRevoke: import("@endo/patterns").MethodGuard;
81
+ }>;
82
+ export let protocolHandlerAcceptWatcher: import("@endo/patterns").InterfaceGuard<{
83
+ onFulfilled: import("@endo/patterns").MethodGuard;
84
+ }>;
85
+ export let protocolHandlerInstantiateWatcher: import("@endo/patterns").InterfaceGuard<{
86
+ onFulfilled: import("@endo/patterns").MethodGuard;
87
+ }>;
88
+ export let protocolHandlerConnectWatcher: import("@endo/patterns").InterfaceGuard<{
89
+ onFulfilled: import("@endo/patterns").MethodGuard;
90
+ }>;
91
+ let rethrowUnlessMissingWatcher_3: import("@endo/patterns").InterfaceGuard<{
92
+ onRejected: import("@endo/patterns").MethodGuard;
93
+ }>;
94
+ export { rethrowUnlessMissingWatcher_3 as rethrowUnlessMissingWatcher };
95
+ }
96
+ let ProtocolImplI: import("@endo/patterns").InterfaceGuard<{
97
+ bindPort: import("@endo/patterns").MethodGuard;
98
+ inbound: import("@endo/patterns").MethodGuard;
99
+ outbound: import("@endo/patterns").MethodGuard;
100
+ }>;
101
+ function Vow$(shape: any): import("@endo/patterns").Matcher;
102
+ let AttemptDescription: import("@endo/patterns").Matcher;
103
+ let Opts: import("@endo/patterns").Matcher;
104
+ let Data: import("@endo/patterns").Matcher;
105
+ let Bytes: import("@endo/patterns").Matcher;
106
+ let Endpoint: import("@endo/patterns").Matcher;
107
+ let Vow: import("@endo/patterns").Matcher;
108
+ let ConnectionHandler: import("@endo/patterns").Matcher;
109
+ let Connection: import("@endo/patterns").Matcher;
110
+ let InboundAttempt: import("@endo/patterns").Matcher;
111
+ let Listener: import("@endo/patterns").Matcher;
112
+ let ListenHandler: import("@endo/patterns").Matcher;
113
+ let Port: import("@endo/patterns").Matcher;
114
+ let ProtocolHandler: import("@endo/patterns").Matcher;
115
+ let ProtocolImpl: import("@endo/patterns").Matcher;
116
+ }
117
+ //# sourceMappingURL=shapes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shapes.d.ts","sourceRoot":"","sources":["shapes.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6BQ,4DAAgC"}
package/src/shapes.js ADDED
@@ -0,0 +1,191 @@
1
+ // @ts-check
2
+ import { M } from '@endo/patterns';
3
+
4
+ const Shape1 = /** @type {const} */ ({
5
+ /**
6
+ * Data is string | Buffer | ArrayBuffer
7
+ * but only string is passable
8
+ */
9
+ Data: M.string(),
10
+ Bytes: M.string(),
11
+ Endpoint: M.string(),
12
+ Vow: M.tagged(
13
+ 'Vow',
14
+ harden({
15
+ vowV0: M.remotable('VowV0'),
16
+ }),
17
+ ),
18
+ ConnectionHandler: M.remotable('ConnectionHandler'),
19
+ Connection: M.remotable('Connection'),
20
+ InboundAttempt: M.remotable('InboundAttempt'),
21
+ Listener: M.remotable('Listener'),
22
+ ListenHandler: M.remotable('ListenHandler'),
23
+ Port: M.remotable('Port'),
24
+ ProtocolHandler: M.remotable('ProtocolHandler'),
25
+ ProtocolImpl: M.remotable('ProtocolImpl'),
26
+ });
27
+
28
+ const Shape2 = /** @type {const} */ ({
29
+ ...Shape1,
30
+ Vow$: shape => M.or(shape, Shape1.Vow),
31
+ AttemptDescription: M.splitRecord(
32
+ { handler: Shape1.ConnectionHandler },
33
+ { remoteAddress: Shape1.Endpoint, localAddress: Shape1.Endpoint },
34
+ ),
35
+ Opts: M.recordOf(M.string(), M.any()),
36
+ });
37
+
38
+ export const Shape = /** @type {const} */ harden({
39
+ ...Shape2,
40
+ ConnectionI: {
41
+ connection: M.interface('Connection', {
42
+ send: M.callWhen(Shape2.Data)
43
+ .optional(Shape2.Opts)
44
+ .returns(Shape2.Vow$(Shape2.Bytes)),
45
+ close: M.callWhen().returns(Shape2.Vow$(M.undefined())),
46
+ getLocalAddress: M.call().returns(Shape2.Endpoint),
47
+ getRemoteAddress: M.call().returns(Shape2.Endpoint),
48
+ }),
49
+ openConnectionAckWatcher: M.interface('OpenConnectionAckWatcher', {
50
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
51
+ }),
52
+ rethrowUnlessMissingWatcher: M.interface('RethrowUnlessMissingWatcher', {
53
+ onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
54
+ }),
55
+ sinkWatcher: M.interface('SinkWatcher', {
56
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(),
57
+ }),
58
+ },
59
+ InboundAttemptI: {
60
+ inboundAttempt: M.interface('InboundAttempt', {
61
+ accept: M.callWhen(Shape2.AttemptDescription).returns(
62
+ Shape2.Vow$(Shape2.Connection),
63
+ ),
64
+ getLocalAddress: M.call().returns(Shape2.Endpoint),
65
+ getRemoteAddress: M.call().returns(Shape2.Endpoint),
66
+ close: M.callWhen().returns(Shape2.Vow$(M.undefined())),
67
+ }),
68
+ inboundAttemptAcceptWatcher: M.interface('InboundAttemptAcceptWatcher', {
69
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
70
+ }),
71
+ rethrowUnlessMissingWatcher: M.interface('RethrowUnlessMissingWatcher', {
72
+ onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
73
+ }),
74
+ sinkWatcher: M.interface('SinkWatcher', {
75
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(),
76
+ }),
77
+ },
78
+ PortI: {
79
+ port: M.interface('Port', {
80
+ getLocalAddress: M.call().returns(Shape2.Endpoint),
81
+ addListener: M.callWhen(Shape2.Listener).returns(
82
+ Shape2.Vow$(M.undefined()),
83
+ ),
84
+ connect: M.callWhen(Shape2.Endpoint)
85
+ .optional(Shape2.ConnectionHandler)
86
+ .returns(Shape2.Vow$(Shape2.Connection)),
87
+ removeListener: M.callWhen(Shape2.Listener).returns(
88
+ Shape2.Vow$(M.undefined()),
89
+ ),
90
+ revoke: M.callWhen().returns(Shape2.Vow$(M.undefined())),
91
+ }),
92
+ portAddListenerWatcher: M.interface('PortAddListenerWatcher', {
93
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
94
+ }),
95
+ portRemoveListenerWatcher: M.interface('PortRemoveListenerWatcher', {
96
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
97
+ }),
98
+ portConnectWatcher: M.interface('PortConnectWatcher', {
99
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
100
+ }),
101
+ portRevokeWatcher: M.interface('PortRevokeWatcher', {
102
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
103
+ }),
104
+ portRevokeCleanupWatcher: M.interface('PortRevokeCleanupWatcher', {
105
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
106
+ }),
107
+ rethrowUnlessMissingWatcher: M.interface('RethrowUnlessMissingWatcher', {
108
+ onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
109
+ }),
110
+ sinkWatcher: M.interface('SinkWatcher', {
111
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(),
112
+ onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
113
+ }),
114
+ },
115
+ ProtocolHandlerI: {
116
+ protocolHandler: M.interface('ProtocolHandler', {
117
+ onCreate: M.callWhen(M.remotable(), Shape2.ProtocolHandler).returns(
118
+ Shape2.Vow$(M.undefined()),
119
+ ),
120
+ generatePortID: M.callWhen(
121
+ Shape2.Endpoint,
122
+ Shape2.ProtocolHandler,
123
+ ).returns(Shape2.Vow$(M.string())),
124
+ onBind: M.callWhen(
125
+ Shape2.Port,
126
+ Shape2.Endpoint,
127
+ Shape2.ProtocolHandler,
128
+ ).returns(Shape2.Vow$(M.undefined())),
129
+ onListen: M.callWhen(
130
+ Shape2.Port,
131
+ Shape2.Endpoint,
132
+ Shape2.ListenHandler,
133
+ Shape2.ProtocolHandler,
134
+ ).returns(Shape2.Vow$(M.undefined())),
135
+ onListenRemove: M.callWhen(
136
+ Shape2.Port,
137
+ Shape2.Endpoint,
138
+ Shape2.ListenHandler,
139
+ Shape2.ProtocolHandler,
140
+ ).returns(Shape2.Vow$(M.undefined())),
141
+ onInstantiate: M.callWhen(
142
+ Shape2.Port,
143
+ Shape2.Endpoint,
144
+ Shape2.Endpoint,
145
+ Shape2.ProtocolHandler,
146
+ ).returns(Shape2.Vow$(Shape2.Endpoint)),
147
+ onConnect: M.callWhen(
148
+ Shape2.Port,
149
+ Shape2.Endpoint,
150
+ Shape2.Endpoint,
151
+ Shape2.ConnectionHandler,
152
+ Shape2.ProtocolHandler,
153
+ ).returns(Shape2.Vow$(Shape2.AttemptDescription)),
154
+ onRevoke: M.callWhen(
155
+ Shape2.Port,
156
+ Shape2.Endpoint,
157
+ Shape2.ProtocolHandler,
158
+ ).returns(Shape2.Vow$(M.undefined())),
159
+ }),
160
+ protocolHandlerAcceptWatcher: M.interface('ProtocolHandlerAcceptWatcher', {
161
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
162
+ }),
163
+ protocolHandlerInstantiateWatcher: M.interface(
164
+ 'ProtocolHandlerInstantiateWatcher',
165
+ {
166
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
167
+ },
168
+ ),
169
+ protocolHandlerConnectWatcher: M.interface(
170
+ 'ProtocolHandlerConnectWatcher',
171
+ {
172
+ onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
173
+ },
174
+ ),
175
+ rethrowUnlessMissingWatcher: M.interface('RethrowUnlessMissingWatcher', {
176
+ onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
177
+ }),
178
+ },
179
+
180
+ ProtocolImplI: M.interface('ProtocolImpl', {
181
+ bindPort: M.callWhen(Shape2.Endpoint).returns(Shape2.Vow$(Shape2.Port)),
182
+ inbound: M.callWhen(Shape2.Endpoint, Shape2.Endpoint).returns(
183
+ Shape2.Vow$(Shape2.InboundAttempt),
184
+ ),
185
+ outbound: M.callWhen(
186
+ Shape2.Port,
187
+ Shape2.Endpoint,
188
+ Shape2.ConnectionHandler,
189
+ ).returns(Shape2.Vow$(Shape2.Connection)),
190
+ }),
191
+ });