@agoric/network 0.1.1-calypso-dev-84eb287.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/CHANGELOG.md +0 -0
- package/LICENSE +201 -0
- package/README.md +155 -0
- package/package.json +71 -0
- package/src/bytes.d.ts +46 -0
- package/src/bytes.d.ts.map +1 -0
- package/src/bytes.js +103 -0
- package/src/index.d.ts +7 -0
- package/src/index.d.ts.map +1 -0
- package/src/index.js +7 -0
- package/src/multiaddr.d.ts +68 -0
- package/src/multiaddr.d.ts.map +1 -0
- package/src/multiaddr.js +72 -0
- package/src/network.d.ts +163 -0
- package/src/network.d.ts.map +1 -0
- package/src/network.js +1525 -0
- package/src/router.d.ts +106 -0
- package/src/router.d.ts.map +1 -0
- package/src/router.js +187 -0
- package/src/shapes.d.ts +119 -0
- package/src/shapes.d.ts.map +1 -0
- package/src/shapes.js +187 -0
- package/src/types.d.ts +218 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.js +202 -0
package/src/router.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import {AttemptDescription, Bytes, Closable, CloseReason, Connection, ConnectionHandler, Endpoint, ListenHandler, Port, Protocol, ProtocolHandler, ProtocolImpl} from './types.js';
|
|
3
|
+
* @import {PromiseVow, Remote, VowKit, VowResolver, VowTools} from '@agoric/vow';
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @template T
|
|
7
|
+
* @typedef {object} Router A delimited string router implementation
|
|
8
|
+
* @property {(addr: string) => [string, T][]} getRoutes Return the match and
|
|
9
|
+
* route in order of preference
|
|
10
|
+
* @property {(prefix: string, route: T) => void} register Add a prefix->route
|
|
11
|
+
* to the database
|
|
12
|
+
* @property {(prefix: string, route: T) => void} unregister Remove a
|
|
13
|
+
* prefix->route from the database
|
|
14
|
+
*/
|
|
15
|
+
export const RouterI: import("@endo/patterns").InterfaceGuard<{
|
|
16
|
+
getRoutes: import("@endo/patterns").MethodGuard;
|
|
17
|
+
register: import("@endo/patterns").MethodGuard;
|
|
18
|
+
unregister: import("@endo/patterns").MethodGuard;
|
|
19
|
+
}>;
|
|
20
|
+
export function prepareRouter<T>(zone: import("@agoric/base-zone").Zone): () => import("@endo/exo").Guarded<{
|
|
21
|
+
/** @param {Endpoint} addr */
|
|
22
|
+
getRoutes(addr: Endpoint): [string, T][];
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} prefix
|
|
25
|
+
* @param {T} route
|
|
26
|
+
*/
|
|
27
|
+
register(prefix: string, route: T): void;
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} prefix
|
|
30
|
+
* @param {T} route
|
|
31
|
+
*/
|
|
32
|
+
unregister(prefix: string, route: T): void;
|
|
33
|
+
}>;
|
|
34
|
+
export function prepareRouterProtocol(zone: import("@agoric/base-zone").Zone, powers: ReturnType<(zone: import("@agoric/base-zone").Zone, powers?: {
|
|
35
|
+
isRetryableReason?: import("@agoric/vow").IsRetryableReason | undefined;
|
|
36
|
+
} | undefined) => {
|
|
37
|
+
E: (<T>(x: T, opts?: import("@agoric/vow").EUnwrapOptions | undefined) => ECallableOrMethods<RemoteFunctions<T>>) & {
|
|
38
|
+
readonly get: <T>(x: T, opts?: import("@agoric/vow").EUnwrapOptions | undefined) => EGetters<LocalRecord<T>>;
|
|
39
|
+
readonly resolve: <T>(x: T, opts?: import("@agoric/vow").EUnwrapOptions | undefined) => Promise<Awaited<T>>;
|
|
40
|
+
readonly sendOnly: <T>(x: T, opts?: import("@agoric/vow").EUnwrapOptions | undefined) => ESendOnlyCallableOrMethods<RemoteFunctions<T>>;
|
|
41
|
+
readonly when: <T, TResult1 = import("@agoric/vow").EUnwrap<T>, TResult2 = never>(x: import("@agoric/vow/src/E.js").ERef<T>, onfulfilled?: ((value: import("@agoric/vow").EUnwrap<T>) => ERef<TResult1>) | undefined, onrejected?: ((reason: any) => ERef<TResult2>) | undefined, opts?: import("@agoric/vow").EUnwrapOptions | undefined) => Promise<TResult1 | TResult2>;
|
|
42
|
+
} & {
|
|
43
|
+
when: <T, TResult1 = import("@agoric/vow").EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
|
|
44
|
+
watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(specimenP: import("@agoric/vow").EVow<T>, watcher?: import("@agoric/vow").Watcher<T, TResult1, TResult2, C> | undefined, ...watcherArgs: C) => import("@agoric/vow").Vow<Exclude<TResult1, void> | Exclude<TResult2, void> extends never ? TResult1 : Exclude<TResult1, void> | Exclude<TResult2, void>>;
|
|
45
|
+
};
|
|
46
|
+
when: <T, TResult1 = import("@agoric/vow").EUnwrap<T>, TResult2 = never>(specimenP: T, onFulfilled?: ((value: import("@agoric/vow").EUnwrap<T>) => TResult1 | PromiseLike<TResult1>) | undefined, onRejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined) => Promise<TResult1 | TResult2>;
|
|
47
|
+
watch: <T = any, TResult1 = T, TResult2 = never, C extends any[] = any[]>(specimenP: import("@agoric/vow").EVow<T>, watcher?: import("@agoric/vow").Watcher<T, TResult1, TResult2, C> | undefined, ...watcherArgs: C) => import("@agoric/vow").Vow<Exclude<TResult1, void> | Exclude<TResult2, void> extends never ? TResult1 : Exclude<TResult1, void> | Exclude<TResult2, void>>;
|
|
48
|
+
makeVowKit: <T>() => VowKit<T>;
|
|
49
|
+
allVows: (maybeVows: import("@agoric/vow").EVow<unknown>[]) => import("@agoric/vow").Vow<any[]>;
|
|
50
|
+
asVow: <T extends unknown>(fn: (...args: any[]) => import("@agoric/vow").Vow<Awaited<T>> | Awaited<T> | PromiseVow<T>) => import("@agoric/vow").Vow<Awaited<T>>;
|
|
51
|
+
asPromise: import("@agoric/vow").AsPromiseFunction;
|
|
52
|
+
}>, E?: ((<T>(x: T) => import("../../../node_modules/@endo/eventual-send/src/E.js").ECallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T>>) & {
|
|
53
|
+
readonly get: <T_1>(x: T_1) => import("../../../node_modules/@endo/eventual-send/src/E.js").EGetters<import("@endo/eventual-send").LocalRecord<T_1>>;
|
|
54
|
+
readonly resolve: {
|
|
55
|
+
(): Promise<void>;
|
|
56
|
+
<T_2>(value: T_2): Promise<Awaited<T_2>>;
|
|
57
|
+
<T_3>(value: T_3 | PromiseLike<T_3>): Promise<Awaited<T_3>>;
|
|
58
|
+
};
|
|
59
|
+
readonly sendOnly: <T_4>(x: T_4) => import("../../../node_modules/@endo/eventual-send/src/E.js").ESendOnlyCallableOrMethods<import("@endo/eventual-send").RemoteFunctions<T_4>>;
|
|
60
|
+
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>;
|
|
61
|
+
}) | undefined): () => import("@endo/exo").Guarded<{
|
|
62
|
+
/**
|
|
63
|
+
* @param {string[]} paths
|
|
64
|
+
* @param {Remote<ProtocolHandler>} protocolHandler
|
|
65
|
+
*/
|
|
66
|
+
registerProtocolHandler(paths: string[], protocolHandler: Remote<ProtocolHandler>): void;
|
|
67
|
+
/**
|
|
68
|
+
* @param {string} prefix
|
|
69
|
+
* @param {Remote<ProtocolHandler>} protocolHandler
|
|
70
|
+
*/
|
|
71
|
+
unregisterProtocolHandler(prefix: string, protocolHandler: Remote<ProtocolHandler>): void;
|
|
72
|
+
/** @param {Endpoint} localAddr */
|
|
73
|
+
bindPort(localAddr: Endpoint): Promise<Port | import("@agoric/vow").Vow<Port>>;
|
|
74
|
+
}>;
|
|
75
|
+
/**
|
|
76
|
+
* A delimited string router implementation
|
|
77
|
+
*/
|
|
78
|
+
export type Router<T> = {
|
|
79
|
+
/**
|
|
80
|
+
* Return the match and
|
|
81
|
+
* route in order of preference
|
|
82
|
+
*/
|
|
83
|
+
getRoutes: (addr: string) => [string, T][];
|
|
84
|
+
/**
|
|
85
|
+
* Add a prefix->route
|
|
86
|
+
* to the database
|
|
87
|
+
*/
|
|
88
|
+
register: (prefix: string, route: T) => void;
|
|
89
|
+
/**
|
|
90
|
+
* Remove a
|
|
91
|
+
* prefix->route from the database
|
|
92
|
+
*/
|
|
93
|
+
unregister: (prefix: string, route: T) => void;
|
|
94
|
+
};
|
|
95
|
+
export type RouterProtocol = {
|
|
96
|
+
bindPort: (prefix: string) => PromiseVow<Port>;
|
|
97
|
+
registerProtocolHandler: (paths: string[], protocolHandler: ProtocolHandler) => void;
|
|
98
|
+
unregisterProtocolHandler: (prefix: string, protocolHandler: ProtocolHandler) => void;
|
|
99
|
+
};
|
|
100
|
+
import type { Endpoint } from './types.js';
|
|
101
|
+
import type { VowKit } from '@agoric/vow';
|
|
102
|
+
import type { PromiseVow } from '@agoric/vow';
|
|
103
|
+
import type { ProtocolHandler } from './types.js';
|
|
104
|
+
import type { Remote } from '@agoric/vow';
|
|
105
|
+
import type { Port } from './types.js';
|
|
106
|
+
//# sourceMappingURL=router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,UAAU,CAAC;;;;;;;;;;;;;;;;oCArBoB,GAAG;;CAqBc,CAAC;;;;;;;;wEAjGJ,CAAC,0BACxD,qBAEE,kCAEe,CAAC,2BAA4B,qBAAO;;IAgIhD;;;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;;8BA3FkG,YAAY;4BAClH,aAAa;gCAAb,aAAa;qCADyF,YAAY;4BAClH,aAAa;0BADyF,YAAY"}
|
package/src/router.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/// <reference types="@agoric/store/exported.js" />
|
|
4
|
+
/// <reference path="./types.js" />
|
|
5
|
+
|
|
6
|
+
import { E as defaultE } from '@endo/far';
|
|
7
|
+
import { M } from '@endo/patterns';
|
|
8
|
+
import { Fail } from '@agoric/assert';
|
|
9
|
+
import { ENDPOINT_SEPARATOR, prepareNetworkProtocol } from './network.js';
|
|
10
|
+
import { Shape } from './shapes.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @import {AttemptDescription, Bytes, Closable, CloseReason, Connection, ConnectionHandler, Endpoint, ListenHandler, Port, Protocol, ProtocolHandler, ProtocolImpl} from './types.js';
|
|
14
|
+
* @import {PromiseVow, Remote, VowKit, VowResolver, VowTools} from '@agoric/vow';
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @template T
|
|
19
|
+
* @typedef {object} Router A delimited string router implementation
|
|
20
|
+
* @property {(addr: string) => [string, T][]} getRoutes Return the match and
|
|
21
|
+
* route in order of preference
|
|
22
|
+
* @property {(prefix: string, route: T) => void} register Add a prefix->route
|
|
23
|
+
* to the database
|
|
24
|
+
* @property {(prefix: string, route: T) => void} unregister Remove a
|
|
25
|
+
* prefix->route from the database
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export const RouterI = M.interface('Router', {
|
|
29
|
+
getRoutes: M.call(Shape.Endpoint).returns(M.arrayOf([M.string(), M.any()])),
|
|
30
|
+
register: M.call(M.string(), M.any()).returns(M.undefined()),
|
|
31
|
+
unregister: M.call(M.string(), M.any()).returns(M.undefined()),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @template T
|
|
36
|
+
* @param {import('@agoric/base-zone').Zone} zone
|
|
37
|
+
*/
|
|
38
|
+
export const prepareRouter = zone => {
|
|
39
|
+
const detached = zone.detached();
|
|
40
|
+
|
|
41
|
+
const makeRouter = zone.exoClass(
|
|
42
|
+
'Router',
|
|
43
|
+
RouterI,
|
|
44
|
+
() => {
|
|
45
|
+
/** @type {MapStore<string, T>} */
|
|
46
|
+
const prefixToRoute = detached.mapStore('prefix');
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
prefixToRoute,
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
/** @param {Endpoint} addr */
|
|
54
|
+
getRoutes(addr) {
|
|
55
|
+
const parts = addr.split(ENDPOINT_SEPARATOR);
|
|
56
|
+
/** @type {[string, T][]} */
|
|
57
|
+
const ret = [];
|
|
58
|
+
for (let i = parts.length; i > 0; i -= 1) {
|
|
59
|
+
// Try most specific match.
|
|
60
|
+
const prefix = parts.slice(0, i).join(ENDPOINT_SEPARATOR);
|
|
61
|
+
if (this.state.prefixToRoute.has(prefix)) {
|
|
62
|
+
ret.push([prefix, this.state.prefixToRoute.get(prefix)]);
|
|
63
|
+
}
|
|
64
|
+
// Trim off the last value (after the slash).
|
|
65
|
+
const defaultPrefix = prefix.slice(
|
|
66
|
+
0,
|
|
67
|
+
prefix.lastIndexOf(ENDPOINT_SEPARATOR) + 1,
|
|
68
|
+
);
|
|
69
|
+
if (this.state.prefixToRoute.has(defaultPrefix)) {
|
|
70
|
+
ret.push([
|
|
71
|
+
defaultPrefix,
|
|
72
|
+
this.state.prefixToRoute.get(defaultPrefix),
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return harden(ret);
|
|
77
|
+
},
|
|
78
|
+
/**
|
|
79
|
+
* @param {string} prefix
|
|
80
|
+
* @param {T} route
|
|
81
|
+
*/
|
|
82
|
+
register(prefix, route) {
|
|
83
|
+
this.state.prefixToRoute.init(prefix, route);
|
|
84
|
+
},
|
|
85
|
+
/**
|
|
86
|
+
* @param {string} prefix
|
|
87
|
+
* @param {T} route
|
|
88
|
+
*/
|
|
89
|
+
unregister(prefix, route) {
|
|
90
|
+
this.state.prefixToRoute.get(prefix) === route ||
|
|
91
|
+
Fail`Router is not registered at prefix ${prefix}`;
|
|
92
|
+
this.state.prefixToRoute.delete(prefix);
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return makeRouter;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @typedef {object} RouterProtocol
|
|
102
|
+
* @property {(prefix: string) => PromiseVow<Port>} bindPort
|
|
103
|
+
* @property {(paths: string[], protocolHandler: ProtocolHandler) => void} registerProtocolHandler
|
|
104
|
+
* @property {(prefix: string, protocolHandler: ProtocolHandler) => void} unregisterProtocolHandler
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Create a router that behaves like a Protocol.
|
|
109
|
+
*
|
|
110
|
+
* @param {import('@agoric/base-zone').Zone} zone
|
|
111
|
+
* @param {ReturnType<import('@agoric/vow').prepareVowTools>} powers
|
|
112
|
+
* @param {typeof defaultE} [E] Eventual sender
|
|
113
|
+
*/
|
|
114
|
+
export const prepareRouterProtocol = (zone, powers, E = defaultE) => {
|
|
115
|
+
const detached = zone.detached();
|
|
116
|
+
|
|
117
|
+
const makeRouter = prepareRouter(zone);
|
|
118
|
+
const makeNetworkProtocol = prepareNetworkProtocol(zone, powers);
|
|
119
|
+
|
|
120
|
+
const makeRouterProtocol = zone.exoClass(
|
|
121
|
+
'RouterProtocol',
|
|
122
|
+
M.interface('RouterProtocol', {
|
|
123
|
+
registerProtocolHandler: M.call(
|
|
124
|
+
M.arrayOf(M.string()),
|
|
125
|
+
M.remotable(),
|
|
126
|
+
).returns(),
|
|
127
|
+
unregisterProtocolHandler: M.call(M.string(), M.remotable()).returns(),
|
|
128
|
+
bindPort: M.callWhen(Shape.Endpoint).returns(Shape.Vow$(Shape.Port)),
|
|
129
|
+
}),
|
|
130
|
+
() => {
|
|
131
|
+
/** @type {Router<Protocol>} */
|
|
132
|
+
const router = makeRouter();
|
|
133
|
+
|
|
134
|
+
/** @type {MapStore<string, Protocol>} */
|
|
135
|
+
const protocols = detached.mapStore('prefix');
|
|
136
|
+
|
|
137
|
+
/** @type {MapStore<string, Remote<ProtocolHandler>>} */
|
|
138
|
+
const protocolHandlers = detached.mapStore('prefix');
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
router,
|
|
142
|
+
protocolHandlers,
|
|
143
|
+
protocols,
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
/**
|
|
148
|
+
* @param {string[]} paths
|
|
149
|
+
* @param {Remote<ProtocolHandler>} protocolHandler
|
|
150
|
+
*/
|
|
151
|
+
registerProtocolHandler(paths, protocolHandler) {
|
|
152
|
+
const protocol = makeNetworkProtocol(protocolHandler);
|
|
153
|
+
for (const prefix of paths) {
|
|
154
|
+
this.state.router.register(prefix, protocol);
|
|
155
|
+
this.state.protocols.init(prefix, protocol);
|
|
156
|
+
this.state.protocolHandlers.init(prefix, protocolHandler);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
// FIXME: Buggy.
|
|
160
|
+
// Needs to account for multiple paths.
|
|
161
|
+
/**
|
|
162
|
+
* @param {string} prefix
|
|
163
|
+
* @param {Remote<ProtocolHandler>} protocolHandler
|
|
164
|
+
*/
|
|
165
|
+
unregisterProtocolHandler(prefix, protocolHandler) {
|
|
166
|
+
const ph = this.state.protocolHandlers.get(prefix);
|
|
167
|
+
ph === protocolHandler ||
|
|
168
|
+
Fail`Protocol handler is not registered at prefix ${prefix}`;
|
|
169
|
+
// TODO: unmap protocol handlers to their corresponding protocol
|
|
170
|
+
// e.g. using a map
|
|
171
|
+
// before unregistering
|
|
172
|
+
// @ts-expect-error note FIXME above
|
|
173
|
+
this.state.router.unregister(prefix, ph);
|
|
174
|
+
this.state.protocols.delete(prefix);
|
|
175
|
+
this.state.protocolHandlers.delete(prefix);
|
|
176
|
+
},
|
|
177
|
+
/** @param {Endpoint} localAddr */
|
|
178
|
+
async bindPort(localAddr) {
|
|
179
|
+
const [route] = this.state.router.getRoutes(localAddr);
|
|
180
|
+
route !== undefined || Fail`No registered router for ${localAddr}`;
|
|
181
|
+
return E(route[1]).bindPort(localAddr);
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
return makeRouterProtocol;
|
|
187
|
+
};
|
package/src/shapes.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export namespace Shape {
|
|
2
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export 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
|
+
export let AttemptDescription: import("@endo/patterns").Matcher;
|
|
102
|
+
export let Opts: import("@endo/patterns").Matcher;
|
|
103
|
+
export let Data: import("@endo/patterns").Matcher;
|
|
104
|
+
export let Bytes: import("@endo/patterns").Matcher;
|
|
105
|
+
export let Endpoint: import("@endo/patterns").Matcher;
|
|
106
|
+
export { OrVow$ as Vow$ };
|
|
107
|
+
export { VowShape as Vow };
|
|
108
|
+
export let ConnectionHandler: import("@endo/patterns").Matcher;
|
|
109
|
+
export let Connection: import("@endo/patterns").Matcher;
|
|
110
|
+
export let InboundAttempt: import("@endo/patterns").Matcher;
|
|
111
|
+
export let Listener: import("@endo/patterns").Matcher;
|
|
112
|
+
export let ListenHandler: import("@endo/patterns").Matcher;
|
|
113
|
+
export let Port: import("@endo/patterns").Matcher;
|
|
114
|
+
export let ProtocolHandler: import("@endo/patterns").Matcher;
|
|
115
|
+
export let ProtocolImpl: import("@endo/patterns").Matcher;
|
|
116
|
+
}
|
|
117
|
+
import { OrVow$ } from '@agoric/vow';
|
|
118
|
+
import { VowShape } from '@agoric/vow';
|
|
119
|
+
//# sourceMappingURL=shapes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.d.ts","sourceRoot":"","sources":["shapes.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBAEiC,aAAa;yBAAb,aAAa"}
|
package/src/shapes.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { M } from '@endo/patterns';
|
|
3
|
+
import { VowShape, OrVow$ } from '@agoric/vow';
|
|
4
|
+
|
|
5
|
+
const Shape1 = /** @type {const} */ ({
|
|
6
|
+
/**
|
|
7
|
+
* Data is string | Buffer | ArrayBuffer
|
|
8
|
+
* but only string is passable
|
|
9
|
+
*/
|
|
10
|
+
Data: M.string(),
|
|
11
|
+
Bytes: M.string(),
|
|
12
|
+
Endpoint: M.string(),
|
|
13
|
+
Vow$: OrVow$,
|
|
14
|
+
Vow: VowShape,
|
|
15
|
+
ConnectionHandler: M.remotable('ConnectionHandler'),
|
|
16
|
+
Connection: M.remotable('Connection'),
|
|
17
|
+
InboundAttempt: M.remotable('InboundAttempt'),
|
|
18
|
+
Listener: M.remotable('Listener'),
|
|
19
|
+
ListenHandler: M.remotable('ListenHandler'),
|
|
20
|
+
Port: M.remotable('Port'),
|
|
21
|
+
ProtocolHandler: M.remotable('ProtocolHandler'),
|
|
22
|
+
ProtocolImpl: M.remotable('ProtocolImpl'),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const Shape2 = /** @type {const} */ ({
|
|
26
|
+
...Shape1,
|
|
27
|
+
AttemptDescription: M.splitRecord(
|
|
28
|
+
{ handler: Shape1.ConnectionHandler },
|
|
29
|
+
{ remoteAddress: Shape1.Endpoint, localAddress: Shape1.Endpoint },
|
|
30
|
+
),
|
|
31
|
+
Opts: M.recordOf(M.string(), M.any()),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const Shape = /** @type {const} */ harden({
|
|
35
|
+
...Shape2,
|
|
36
|
+
ConnectionI: {
|
|
37
|
+
connection: M.interface('Connection', {
|
|
38
|
+
send: M.callWhen(Shape2.Data)
|
|
39
|
+
.optional(Shape2.Opts)
|
|
40
|
+
.returns(Shape2.Vow$(Shape2.Bytes)),
|
|
41
|
+
close: M.callWhen().returns(Shape2.Vow$(M.undefined())),
|
|
42
|
+
getLocalAddress: M.call().returns(Shape2.Endpoint),
|
|
43
|
+
getRemoteAddress: M.call().returns(Shape2.Endpoint),
|
|
44
|
+
}),
|
|
45
|
+
openConnectionAckWatcher: M.interface('OpenConnectionAckWatcher', {
|
|
46
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
47
|
+
}),
|
|
48
|
+
rethrowUnlessMissingWatcher: M.interface('RethrowUnlessMissingWatcher', {
|
|
49
|
+
onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
50
|
+
}),
|
|
51
|
+
sinkWatcher: M.interface('SinkWatcher', {
|
|
52
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(),
|
|
53
|
+
}),
|
|
54
|
+
},
|
|
55
|
+
InboundAttemptI: {
|
|
56
|
+
inboundAttempt: M.interface('InboundAttempt', {
|
|
57
|
+
accept: M.callWhen(Shape2.AttemptDescription).returns(
|
|
58
|
+
Shape2.Vow$(Shape2.Connection),
|
|
59
|
+
),
|
|
60
|
+
getLocalAddress: M.call().returns(Shape2.Endpoint),
|
|
61
|
+
getRemoteAddress: M.call().returns(Shape2.Endpoint),
|
|
62
|
+
close: M.callWhen().returns(Shape2.Vow$(M.undefined())),
|
|
63
|
+
}),
|
|
64
|
+
inboundAttemptAcceptWatcher: M.interface('InboundAttemptAcceptWatcher', {
|
|
65
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
66
|
+
}),
|
|
67
|
+
rethrowUnlessMissingWatcher: M.interface('RethrowUnlessMissingWatcher', {
|
|
68
|
+
onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
69
|
+
}),
|
|
70
|
+
sinkWatcher: M.interface('SinkWatcher', {
|
|
71
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(),
|
|
72
|
+
}),
|
|
73
|
+
},
|
|
74
|
+
PortI: {
|
|
75
|
+
port: M.interface('Port', {
|
|
76
|
+
getLocalAddress: M.call().returns(Shape2.Endpoint),
|
|
77
|
+
addListener: M.callWhen(Shape2.Listener).returns(
|
|
78
|
+
Shape2.Vow$(M.undefined()),
|
|
79
|
+
),
|
|
80
|
+
connect: M.callWhen(Shape2.Endpoint)
|
|
81
|
+
.optional(Shape2.ConnectionHandler)
|
|
82
|
+
.returns(Shape2.Vow$(Shape2.Connection)),
|
|
83
|
+
removeListener: M.callWhen(Shape2.Listener).returns(
|
|
84
|
+
Shape2.Vow$(M.undefined()),
|
|
85
|
+
),
|
|
86
|
+
revoke: M.callWhen().returns(Shape2.Vow$(M.undefined())),
|
|
87
|
+
}),
|
|
88
|
+
portAddListenerWatcher: M.interface('PortAddListenerWatcher', {
|
|
89
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
90
|
+
}),
|
|
91
|
+
portRemoveListenerWatcher: M.interface('PortRemoveListenerWatcher', {
|
|
92
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
93
|
+
}),
|
|
94
|
+
portConnectWatcher: M.interface('PortConnectWatcher', {
|
|
95
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
96
|
+
}),
|
|
97
|
+
portRevokeWatcher: M.interface('PortRevokeWatcher', {
|
|
98
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
99
|
+
}),
|
|
100
|
+
portRevokeCleanupWatcher: M.interface('PortRevokeCleanupWatcher', {
|
|
101
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
102
|
+
}),
|
|
103
|
+
rethrowUnlessMissingWatcher: M.interface('RethrowUnlessMissingWatcher', {
|
|
104
|
+
onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
105
|
+
}),
|
|
106
|
+
sinkWatcher: M.interface('SinkWatcher', {
|
|
107
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(),
|
|
108
|
+
onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
109
|
+
}),
|
|
110
|
+
},
|
|
111
|
+
ProtocolHandlerI: {
|
|
112
|
+
protocolHandler: M.interface('ProtocolHandler', {
|
|
113
|
+
onCreate: M.callWhen(M.remotable(), Shape2.ProtocolHandler).returns(
|
|
114
|
+
Shape2.Vow$(M.undefined()),
|
|
115
|
+
),
|
|
116
|
+
generatePortID: M.callWhen(
|
|
117
|
+
Shape2.Endpoint,
|
|
118
|
+
Shape2.ProtocolHandler,
|
|
119
|
+
).returns(Shape2.Vow$(M.string())),
|
|
120
|
+
onBind: M.callWhen(
|
|
121
|
+
Shape2.Port,
|
|
122
|
+
Shape2.Endpoint,
|
|
123
|
+
Shape2.ProtocolHandler,
|
|
124
|
+
).returns(Shape2.Vow$(M.undefined())),
|
|
125
|
+
onListen: M.callWhen(
|
|
126
|
+
Shape2.Port,
|
|
127
|
+
Shape2.Endpoint,
|
|
128
|
+
Shape2.ListenHandler,
|
|
129
|
+
Shape2.ProtocolHandler,
|
|
130
|
+
).returns(Shape2.Vow$(M.undefined())),
|
|
131
|
+
onListenRemove: M.callWhen(
|
|
132
|
+
Shape2.Port,
|
|
133
|
+
Shape2.Endpoint,
|
|
134
|
+
Shape2.ListenHandler,
|
|
135
|
+
Shape2.ProtocolHandler,
|
|
136
|
+
).returns(Shape2.Vow$(M.undefined())),
|
|
137
|
+
onInstantiate: M.callWhen(
|
|
138
|
+
Shape2.Port,
|
|
139
|
+
Shape2.Endpoint,
|
|
140
|
+
Shape2.Endpoint,
|
|
141
|
+
Shape2.ProtocolHandler,
|
|
142
|
+
).returns(Shape2.Vow$(Shape2.Endpoint)),
|
|
143
|
+
onConnect: M.callWhen(
|
|
144
|
+
Shape2.Port,
|
|
145
|
+
Shape2.Endpoint,
|
|
146
|
+
Shape2.Endpoint,
|
|
147
|
+
Shape2.ConnectionHandler,
|
|
148
|
+
Shape2.ProtocolHandler,
|
|
149
|
+
).returns(Shape2.Vow$(Shape2.AttemptDescription)),
|
|
150
|
+
onRevoke: M.callWhen(
|
|
151
|
+
Shape2.Port,
|
|
152
|
+
Shape2.Endpoint,
|
|
153
|
+
Shape2.ProtocolHandler,
|
|
154
|
+
).returns(Shape2.Vow$(M.undefined())),
|
|
155
|
+
}),
|
|
156
|
+
protocolHandlerAcceptWatcher: M.interface('ProtocolHandlerAcceptWatcher', {
|
|
157
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(),
|
|
158
|
+
}),
|
|
159
|
+
protocolHandlerInstantiateWatcher: M.interface(
|
|
160
|
+
'ProtocolHandlerInstantiateWatcher',
|
|
161
|
+
{
|
|
162
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(),
|
|
163
|
+
},
|
|
164
|
+
),
|
|
165
|
+
protocolHandlerConnectWatcher: M.interface(
|
|
166
|
+
'ProtocolHandlerConnectWatcher',
|
|
167
|
+
{
|
|
168
|
+
onFulfilled: M.call(M.any()).rest(M.any()).returns(),
|
|
169
|
+
},
|
|
170
|
+
),
|
|
171
|
+
rethrowUnlessMissingWatcher: M.interface('RethrowUnlessMissingWatcher', {
|
|
172
|
+
onRejected: M.call(M.any()).rest(M.any()).returns(M.any()),
|
|
173
|
+
}),
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
ProtocolImplI: M.interface('ProtocolImpl', {
|
|
177
|
+
bindPort: M.callWhen(Shape2.Endpoint).returns(Shape2.Vow$(Shape2.Port)),
|
|
178
|
+
inbound: M.callWhen(Shape2.Endpoint, Shape2.Endpoint).returns(
|
|
179
|
+
Shape2.Vow$(Shape2.InboundAttempt),
|
|
180
|
+
),
|
|
181
|
+
outbound: M.callWhen(
|
|
182
|
+
Shape2.Port,
|
|
183
|
+
Shape2.Endpoint,
|
|
184
|
+
Shape2.ConnectionHandler,
|
|
185
|
+
).returns(Shape2.Vow$(Shape2.Connection)),
|
|
186
|
+
}),
|
|
187
|
+
});
|