@source-repo/rpc 3.0.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/LICENSE +21 -0
- package/README.md +1208 -0
- package/dist/Logging/ILogger.d.ts +7 -0
- package/dist/Logging/ILogger.d.ts.map +1 -0
- package/dist/Logging/ILogger.js +2 -0
- package/dist/Logging/ILogger.js.map +1 -0
- package/dist/NodeRpcServer.d.ts +55 -0
- package/dist/NodeRpcServer.d.ts.map +1 -0
- package/dist/NodeRpcServer.js +46 -0
- package/dist/NodeRpcServer.js.map +1 -0
- package/dist/RPC/Auth.d.ts +98 -0
- package/dist/RPC/Auth.d.ts.map +1 -0
- package/dist/RPC/Auth.js +14 -0
- package/dist/RPC/Auth.js.map +1 -0
- package/dist/RPC/Codec.d.ts +24 -0
- package/dist/RPC/Codec.d.ts.map +1 -0
- package/dist/RPC/Codec.js +21 -0
- package/dist/RPC/Codec.js.map +1 -0
- package/dist/RPC/Compatibility.d.ts +39 -0
- package/dist/RPC/Compatibility.d.ts.map +1 -0
- package/dist/RPC/Compatibility.js +195 -0
- package/dist/RPC/Compatibility.js.map +1 -0
- package/dist/RPC/Core.d.ts +188 -0
- package/dist/RPC/Core.d.ts.map +1 -0
- package/dist/RPC/Core.js +354 -0
- package/dist/RPC/Core.js.map +1 -0
- package/dist/RPC/Expose.d.ts +90 -0
- package/dist/RPC/Expose.d.ts.map +1 -0
- package/dist/RPC/Expose.js +110 -0
- package/dist/RPC/Expose.js.map +1 -0
- package/dist/RPC/Idempotency.d.ts +90 -0
- package/dist/RPC/Idempotency.d.ts.map +1 -0
- package/dist/RPC/Idempotency.js +46 -0
- package/dist/RPC/Idempotency.js.map +1 -0
- package/dist/RPC/Introspection.d.ts +92 -0
- package/dist/RPC/Introspection.d.ts.map +1 -0
- package/dist/RPC/Introspection.js +188 -0
- package/dist/RPC/Introspection.js.map +1 -0
- package/dist/RPC/Introspection.types.json +1093 -0
- package/dist/RPC/Messages.d.ts +108 -0
- package/dist/RPC/Messages.d.ts.map +1 -0
- package/dist/RPC/Messages.js +30 -0
- package/dist/RPC/Messages.js.map +1 -0
- package/dist/RPC/Rpc.d.ts +51 -0
- package/dist/RPC/Rpc.d.ts.map +1 -0
- package/dist/RPC/Rpc.js +54 -0
- package/dist/RPC/Rpc.js.map +1 -0
- package/dist/RPC/RpcClientHandler.d.ts +129 -0
- package/dist/RPC/RpcClientHandler.d.ts.map +1 -0
- package/dist/RPC/RpcClientHandler.js +267 -0
- package/dist/RPC/RpcClientHandler.js.map +1 -0
- package/dist/RPC/RpcServerHandler.d.ts +226 -0
- package/dist/RPC/RpcServerHandler.d.ts.map +1 -0
- package/dist/RPC/RpcServerHandler.js +676 -0
- package/dist/RPC/RpcServerHandler.js.map +1 -0
- package/dist/RPC/Schema.d.ts +150 -0
- package/dist/RPC/Schema.d.ts.map +1 -0
- package/dist/RPC/Schema.js +198 -0
- package/dist/RPC/Schema.js.map +1 -0
- package/dist/RPC/Signing.d.ts +118 -0
- package/dist/RPC/Signing.d.ts.map +1 -0
- package/dist/RPC/Signing.js +171 -0
- package/dist/RPC/Signing.js.map +1 -0
- package/dist/RPC/Tokens.d.ts +49 -0
- package/dist/RPC/Tokens.d.ts.map +1 -0
- package/dist/RPC/Tokens.js +45 -0
- package/dist/RPC/Tokens.js.map +1 -0
- package/dist/RpcClient.d.ts +91 -0
- package/dist/RpcClient.d.ts.map +1 -0
- package/dist/RpcClient.js +145 -0
- package/dist/RpcClient.js.map +1 -0
- package/dist/RpcServer.d.ts +191 -0
- package/dist/RpcServer.d.ts.map +1 -0
- package/dist/RpcServer.js +293 -0
- package/dist/RpcServer.js.map +1 -0
- package/dist/Transports/Mqtt5Frame.d.ts +107 -0
- package/dist/Transports/Mqtt5Frame.d.ts.map +1 -0
- package/dist/Transports/Mqtt5Frame.js +162 -0
- package/dist/Transports/Mqtt5Frame.js.map +1 -0
- package/dist/Transports/MqttTransport.d.ts +279 -0
- package/dist/Transports/MqttTransport.d.ts.map +1 -0
- package/dist/Transports/MqttTransport.js +843 -0
- package/dist/Transports/MqttTransport.js.map +1 -0
- package/dist/Transports/Presence.d.ts +68 -0
- package/dist/Transports/Presence.d.ts.map +1 -0
- package/dist/Transports/Presence.js +21 -0
- package/dist/Transports/Presence.js.map +1 -0
- package/dist/Transports/SocketIoClientTransport.d.ts +89 -0
- package/dist/Transports/SocketIoClientTransport.d.ts.map +1 -0
- package/dist/Transports/SocketIoClientTransport.js +280 -0
- package/dist/Transports/SocketIoClientTransport.js.map +1 -0
- package/dist/Transports/SocketIoServerTransport.d.ts +135 -0
- package/dist/Transports/SocketIoServerTransport.d.ts.map +1 -0
- package/dist/Transports/SocketIoServerTransport.js +505 -0
- package/dist/Transports/SocketIoServerTransport.js.map +1 -0
- package/dist/Utilities/Converters.d.ts +22 -0
- package/dist/Utilities/Converters.d.ts.map +1 -0
- package/dist/Utilities/Converters.js +58 -0
- package/dist/Utilities/Converters.js.map +1 -0
- package/dist/Utilities/Filter.d.ts +7 -0
- package/dist/Utilities/Filter.d.ts.map +1 -0
- package/dist/Utilities/Filter.js +14 -0
- package/dist/Utilities/Filter.js.map +1 -0
- package/dist/Utilities/ReadableName.d.ts +38 -0
- package/dist/Utilities/ReadableName.d.ts.map +1 -0
- package/dist/Utilities/ReadableName.js +58 -0
- package/dist/Utilities/ReadableName.js.map +1 -0
- package/dist/Utilities/Switch.d.ts +21 -0
- package/dist/Utilities/Switch.d.ts.map +1 -0
- package/dist/Utilities/Switch.js +70 -0
- package/dist/Utilities/Switch.js.map +1 -0
- package/dist/Utilities/TryCatch.d.ts +11 -0
- package/dist/Utilities/TryCatch.d.ts.map +1 -0
- package/dist/Utilities/TryCatch.js +13 -0
- package/dist/Utilities/TryCatch.js.map +1 -0
- package/dist/index-web.d.ts +25 -0
- package/dist/index-web.d.ts.map +1 -0
- package/dist/index-web.js +28 -0
- package/dist/index-web.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { GenericModule, PeerRegistry, Transport } from './RPC/Core.js';
|
|
2
|
+
import { RpcAuthenticator, RpcAuthorizer, type TrustedCertificateAuthority } from './RPC/Auth.js';
|
|
3
|
+
import { RpcSchema } from './RPC/Schema.js';
|
|
4
|
+
import { ExposeOptions, RpcServerHandler } from './RPC/RpcServerHandler.js';
|
|
5
|
+
import type { RpcIdempotencyStore } from './RPC/Idempotency.js';
|
|
6
|
+
import { RpcClientHandler } from './RPC/RpcClientHandler.js';
|
|
7
|
+
import { RpcProxy } from './RpcClient.js';
|
|
8
|
+
import { RelayRule } from './Transports/Presence.js';
|
|
9
|
+
import { Switch } from './Utilities/Switch.js';
|
|
10
|
+
import { IManageRpc } from './RPC/Rpc.js';
|
|
11
|
+
export interface ServerOptions {
|
|
12
|
+
description?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Serve over a connection this server opens, rather than one it accepts. A browser page cannot
|
|
16
|
+
* listen, so this is the only way it can host an RpcServer: it dials a hub, announces its name, and
|
|
17
|
+
* the hub relays calls to it.
|
|
18
|
+
*/
|
|
19
|
+
export interface ConnectServerOptions extends ServerOptions {
|
|
20
|
+
connect: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
/** Presented to a hub that authenticates. */
|
|
23
|
+
credentials?: unknown;
|
|
24
|
+
/**
|
|
25
|
+
* Dial an `https://` or `wss://` hub without checking its certificate. Deliberately unsafe:
|
|
26
|
+
* anything able to answer on that address can then read and rewrite this link. For a
|
|
27
|
+
* development hub with a self-signed certificate.
|
|
28
|
+
*/
|
|
29
|
+
allowInsecureTls?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* A certificate authority to trust when dialling the hub, on top of the system ones. What a
|
|
32
|
+
* plant issuing its own certificates wants, and what to reach for before `allowInsecureTls`:
|
|
33
|
+
* verification stays on, so anything this does not vouch for is still refused.
|
|
34
|
+
*/
|
|
35
|
+
ca?: TrustedCertificateAuthority;
|
|
36
|
+
}
|
|
37
|
+
export interface RpcServerOptions {
|
|
38
|
+
name: string;
|
|
39
|
+
/**
|
|
40
|
+
* What this server serves over. Only the two a browser can use are here; NodeRpcServer widens
|
|
41
|
+
* it with a socket.io listener, an existing http.Server and a broker connection, which is what
|
|
42
|
+
* makes `{ port: 8080 }` in browser code a compile error rather than a surprise at runtime.
|
|
43
|
+
*/
|
|
44
|
+
transports: (ConnectServerOptions | Transport)[];
|
|
45
|
+
useMsgPack: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Verify credentials when a peer connects. Applied to socket.io transports this server builds.
|
|
48
|
+
* MQTT has no server-side handshake, so MQTT peers are authenticated by the broker instead.
|
|
49
|
+
*/
|
|
50
|
+
authenticate?: RpcAuthenticator;
|
|
51
|
+
/** Called for every call and every event subscription. Return false to reject it. */
|
|
52
|
+
authorize?: RpcAuthorizer;
|
|
53
|
+
/**
|
|
54
|
+
* Reject calls from peers no transport can vouch for. Defaults to true when `authenticate` is
|
|
55
|
+
* set. Note that MQTT peers can never be vouched for at this layer, so a server that mixes an
|
|
56
|
+
* authenticating socket.io transport with MQTT will reject its MQTT peers unless this is
|
|
57
|
+
* explicitly false.
|
|
58
|
+
*/
|
|
59
|
+
requireAuthenticatedPeers?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Forward frames addressed to another peer connected to this server's socket.io transports,
|
|
62
|
+
* instead of running them here. On by default, because a peer that can only dial out has no
|
|
63
|
+
* other way to be reached. A predicate decides per connection; `false` forwards nothing.
|
|
64
|
+
*/
|
|
65
|
+
relay?: RelayRule;
|
|
66
|
+
/**
|
|
67
|
+
* Publish manageRpc.createRpcInstance so peers can instantiate exposed classes remotely.
|
|
68
|
+
* Off by default: it is remote object construction, and it is rarely needed.
|
|
69
|
+
*/
|
|
70
|
+
exposeManagement?: boolean;
|
|
71
|
+
/** How long ready() waits for every transport to connect before throwing. 0 waits forever. */
|
|
72
|
+
readyTimeout: number;
|
|
73
|
+
/** How long this server's own outgoing calls wait. See proxy(). */
|
|
74
|
+
callTimeout?: number;
|
|
75
|
+
/** Describes what exposed methods accept, so arguments off the wire can be checked. */
|
|
76
|
+
schema?: RpcSchema;
|
|
77
|
+
/**
|
|
78
|
+
* 'described' (the default when a schema is given) checks the namespaces the schema covers.
|
|
79
|
+
* 'required' refuses anything undescribed. 'off' disables checking without removing the schema.
|
|
80
|
+
*/
|
|
81
|
+
validation?: 'off' | 'described' | 'required';
|
|
82
|
+
/** Check what handlers return against the schema too. Off by default: it is a self-check. */
|
|
83
|
+
validateResults?: boolean;
|
|
84
|
+
/** Refuse to expose a class that marks no @rpc methods, rather than publishing all of them. */
|
|
85
|
+
requireExplicitExposure?: boolean;
|
|
86
|
+
/** Refuse a caller declaring a contract version the schema has no history for. Default 'allow'. */
|
|
87
|
+
unknownVersion?: 'allow' | 'reject';
|
|
88
|
+
/**
|
|
89
|
+
* Where to record what a non-repeatable command did, so a request redelivered after this
|
|
90
|
+
* process died is answered from the record instead of run a second time.
|
|
91
|
+
*
|
|
92
|
+
* Without one, delivery and execution are at least once - which is the honest description of
|
|
93
|
+
* every RPC system that has no such store. See RPC/Idempotency.ts for what exactly it closes.
|
|
94
|
+
*/
|
|
95
|
+
idempotency?: RpcIdempotencyStore;
|
|
96
|
+
/**
|
|
97
|
+
* Publish msgrpc.describe(), which reports the exposed namespaces, their methods and events,
|
|
98
|
+
* and which instances are live. Off by default: listing all of that is reconnaissance, and it
|
|
99
|
+
* is subject to authorize() like any other call.
|
|
100
|
+
*/
|
|
101
|
+
exposeIntrospection?: boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Everything that works anywhere: a peer serves over connections it opens, or over transports it
|
|
105
|
+
* was handed. Listening for connections and speaking MQTT need Node, and live in NodeRpcServer,
|
|
106
|
+
* which is what `RpcServer` means when imported outside a browser.
|
|
107
|
+
*/
|
|
108
|
+
export declare class RpcServerBase implements IManageRpc {
|
|
109
|
+
rpc: RpcServerHandler;
|
|
110
|
+
/**
|
|
111
|
+
* This server as a caller. A server on a bus is rarely only a server: it answers its peers and
|
|
112
|
+
* calls them back. Sharing the transports means it does so under its own name, over the
|
|
113
|
+
* connection it already has, rather than needing a second RpcClient with a second name - which
|
|
114
|
+
* over MQTT means a second broker session, and over socket.io a second announced peer.
|
|
115
|
+
*/
|
|
116
|
+
caller: RpcClientHandler;
|
|
117
|
+
readyFlag: boolean;
|
|
118
|
+
switch?: Switch;
|
|
119
|
+
transports: Transport[];
|
|
120
|
+
/** Peer name -> transport, shared by this server's modules and nothing outside them. */
|
|
121
|
+
readonly peers: PeerRegistry;
|
|
122
|
+
options: RpcServerOptions;
|
|
123
|
+
constructor(options?: Partial<RpcServerOptions>);
|
|
124
|
+
/** Why init() failed, rethrown by ready() so the caller sees the cause and not a timeout. */
|
|
125
|
+
private initError?;
|
|
126
|
+
/** Resolves when every transport has been built and wired. ready() waits on it. */
|
|
127
|
+
private starting;
|
|
128
|
+
/**
|
|
129
|
+
* Build each configured transport and wire it in. The socket.io listener and the MQTT client
|
|
130
|
+
* are imported here rather than at the top of the file: a page hosting an RpcServer over a
|
|
131
|
+
* connection it dials has no use for either, and a static import would put both in its bundle.
|
|
132
|
+
*/
|
|
133
|
+
/** What to build when nothing was configured. A peer that cannot listen has no useful default. */
|
|
134
|
+
protected configuredTransports(): unknown[];
|
|
135
|
+
/**
|
|
136
|
+
* Turn one configuration entry into a transport, or undefined if this class does not know that
|
|
137
|
+
* shape. NodeRpcServer overrides it for the shapes that need Node and defers here for the rest.
|
|
138
|
+
*/
|
|
139
|
+
protected buildTransport(serveroption: unknown): Promise<Transport | undefined>;
|
|
140
|
+
private buildTransports;
|
|
141
|
+
/** Put one transport into the graph: piped into both handlers, routable from the switch. */
|
|
142
|
+
private attach;
|
|
143
|
+
/**
|
|
144
|
+
* Pass a presence change from the transport that saw it to the other links: told directly to
|
|
145
|
+
* the peers connected here, and advertised to the hubs this server has dialled into. The
|
|
146
|
+
* advertisement is what makes a network deeper than a star work - and it never includes a peer
|
|
147
|
+
* back on the link it was learned from, or two hubs each end up believing the other is the way
|
|
148
|
+
* to it.
|
|
149
|
+
*/
|
|
150
|
+
private relayPresence;
|
|
151
|
+
private advertiseReachability;
|
|
152
|
+
/** Not 'error': an EventEmitter throws on an unhandled 'error' event. */
|
|
153
|
+
private emitSafely;
|
|
154
|
+
/**
|
|
155
|
+
* Run a presence reaction without letting it escape into the transport that emitted the event.
|
|
156
|
+
* Bookkeeping here failing is worth reporting; it is not worth ending the process over.
|
|
157
|
+
*/
|
|
158
|
+
private safely;
|
|
159
|
+
/**
|
|
160
|
+
* A typed proxy for calling another peer, over this server's own transports and under its own
|
|
161
|
+
* name. The mirror of RpcClient.proxy, so a peer that both serves and calls needs one object.
|
|
162
|
+
*/
|
|
163
|
+
proxy<T>(name: string, target?: string): Promise<RpcProxy<T>>;
|
|
164
|
+
close(): Promise<void>;
|
|
165
|
+
exposeClassInstance(instance: object, name?: string, options?: number | ExposeOptions): void;
|
|
166
|
+
exposeClass<T>(constructor: new (...args: unknown[]) => T, aliasName?: string): void;
|
|
167
|
+
exposeObject(obj: object, name: string): void;
|
|
168
|
+
expose(methodName: string, method: () => void): void;
|
|
169
|
+
createRpcInstance(className: string, instanceName?: string, ...args: unknown[]): Promise<string | undefined>;
|
|
170
|
+
addTarget(target: string, transport: GenericModule): void;
|
|
171
|
+
init(): Promise<void>;
|
|
172
|
+
ready(): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Wait until a peer is addressable from here, rather than calling it and hoping.
|
|
175
|
+
*
|
|
176
|
+
* `ready()` says this peer's own links are up. It says nothing about anyone else, and it cannot:
|
|
177
|
+
* presence arrives over those links a moment after they open, and over MQTT a retained
|
|
178
|
+
* announcement lands a moment after the subscription does. Calling in that moment reaches a
|
|
179
|
+
* switch with no route and fails.
|
|
180
|
+
*
|
|
181
|
+
* This is the wait that closes it, and the reason it is here rather than in each application is
|
|
182
|
+
* that everything built on this library has needed it - the CLI's verbs, its recorder, its
|
|
183
|
+
* replayer and its console each grew their own copy before this existed.
|
|
184
|
+
*
|
|
185
|
+
* Returns true when the peer is addressable, false if it never appeared. A `false` is worth
|
|
186
|
+
* reporting as "nobody is answering to that name" rather than retrying: the usual cause is a
|
|
187
|
+
* peer that is not running or is running under a different name.
|
|
188
|
+
*/
|
|
189
|
+
awaitPeer(peer: string, timeout?: number): Promise<boolean>;
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=RpcServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RpcServer.d.ts","sourceRoot":"","sources":["../src/RpcServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAkB,MAAM,eAAe,CAAA;AACtF,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,KAAK,2BAA2B,EAAE,MAAM,eAAe,CAAA;AACjG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA;AAC/D,OAAO,EAAsB,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,MAAM,WAAW,aAAa;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAqB,SAAQ,aAAa;IACvD,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,6CAA6C;IAC7C,W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D;IACD,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE3G;IACD,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,QAEjD;IACK,IAAI,kBAAK;IACT,KAAK,kBAuBV;IAED;;;;;;;;;;;;;;;OAeG;IACG,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,SAAO,oBAO3C;CACJ"}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { GenericModule, PeerRegistry, TransportEvent } from './RPC/Core.js';
|
|
2
|
+
import { Introspection, withIntrospection } from './RPC/Introspection.js';
|
|
3
|
+
import { RpcServerHandler } from './RPC/RpcServerHandler.js';
|
|
4
|
+
import { defaultCallTimeout, RpcClientHandler } from './RPC/RpcClientHandler.js';
|
|
5
|
+
import { SocketIoClientTransport } from './Transports/SocketIoClientTransport.js';
|
|
6
|
+
import { codecFor } from './RPC/Codec.js';
|
|
7
|
+
import { Switch } from './Utilities/Switch.js';
|
|
8
|
+
/**
|
|
9
|
+
* Everything that works anywhere: a peer serves over connections it opens, or over transports it
|
|
10
|
+
* was handed. Listening for connections and speaking MQTT need Node, and live in NodeRpcServer,
|
|
11
|
+
* which is what `RpcServer` means when imported outside a browser.
|
|
12
|
+
*/
|
|
13
|
+
export class RpcServerBase {
|
|
14
|
+
rpc;
|
|
15
|
+
/**
|
|
16
|
+
* This server as a caller. A server on a bus is rarely only a server: it answers its peers and
|
|
17
|
+
* calls them back. Sharing the transports means it does so under its own name, over the
|
|
18
|
+
* connection it already has, rather than needing a second RpcClient with a second name - which
|
|
19
|
+
* over MQTT means a second broker session, and over socket.io a second announced peer.
|
|
20
|
+
*/
|
|
21
|
+
caller;
|
|
22
|
+
readyFlag = false;
|
|
23
|
+
switch;
|
|
24
|
+
transports = [];
|
|
25
|
+
/** Peer name -> transport, shared by this server's modules and nothing outside them. */
|
|
26
|
+
peers = new PeerRegistry();
|
|
27
|
+
options = { name: '*', transports: [], useMsgPack: true, readyTimeout: 30000 };
|
|
28
|
+
constructor(options = {}) {
|
|
29
|
+
this.options = { ...this.options, ...options };
|
|
30
|
+
// Handlers first, with no sources. Transports attach to them as they are built, which is
|
|
31
|
+
// what lets exposeClassInstance() run before any link exists - and lets the two node-only
|
|
32
|
+
// transports be imported on demand, so a browser bundle carrying RpcServer does not carry
|
|
33
|
+
// socket.io's server and the MQTT client to reach a hub it dials.
|
|
34
|
+
this.rpc = new RpcServerHandler(this.options.name);
|
|
35
|
+
this.caller = new RpcClientHandler(this.options.name, [], this.options.callTimeout ?? defaultCallTimeout);
|
|
36
|
+
this.switch = new Switch([this.rpc, this.caller]);
|
|
37
|
+
// One registry for this server's modules only. The transports record which peer they saw a
|
|
38
|
+
// message from; the switch reads it back to route the reply out of the same transport.
|
|
39
|
+
for (const module of [this.rpc, this.caller, this.switch])
|
|
40
|
+
module.usePeerRegistry(this.peers);
|
|
41
|
+
this.rpc.authorize = this.options.authorize;
|
|
42
|
+
this.rpc.requireIdentity = this.options.requireAuthenticatedPeers ?? !!this.options.authenticate;
|
|
43
|
+
// Identity comes from whichever transport the peer is connected to, never from the message
|
|
44
|
+
// itself. Authenticating transports pin a peer name to one connection, so this lookup
|
|
45
|
+
// cannot be spoofed by claiming someone else's source.
|
|
46
|
+
this.rpc.resolveIdentity = (source) => {
|
|
47
|
+
for (const transport of this.transports) {
|
|
48
|
+
const identity = transport.getIdentity(source);
|
|
49
|
+
if (identity)
|
|
50
|
+
return identity;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
|
54
|
+
this.rpc.schema = this.options.schema;
|
|
55
|
+
this.rpc.validation = this.options.validation ?? (this.options.schema ? 'described' : 'off');
|
|
56
|
+
this.rpc.validateResults = this.options.validateResults ?? false;
|
|
57
|
+
this.rpc.unknownVersion = this.options.unknownVersion ?? 'allow';
|
|
58
|
+
this.rpc.idempotency = this.options.idempotency;
|
|
59
|
+
this.rpc.manageRpc.requireExplicitExposure = this.options.requireExplicitExposure ?? false;
|
|
60
|
+
if (this.options.exposeManagement)
|
|
61
|
+
this.rpc.manageRpc.exposeManagement();
|
|
62
|
+
if (this.options.exposeIntrospection) {
|
|
63
|
+
this.rpc.manageRpc.exposeClassInstance(new Introspection(this.rpc));
|
|
64
|
+
// Describing the describer. Without this the one call a peer makes to find out what is
|
|
65
|
+
// here is the only undescribed thing on the server, and 'required' refuses it outright.
|
|
66
|
+
this.rpc.schema = withIntrospection(this.rpc.schema);
|
|
67
|
+
}
|
|
68
|
+
// Building a listener or a broker connection means loading a module, so this is where the
|
|
69
|
+
// constructor stops being synchronous. ready() awaits it and reports what went wrong.
|
|
70
|
+
this.starting = this.buildTransports().then(() => {
|
|
71
|
+
this.readyFlag = true;
|
|
72
|
+
}, (e) => {
|
|
73
|
+
this.initError = e;
|
|
74
|
+
});
|
|
75
|
+
// init() is a no-op here but is meant to be overridden, and the constructor cannot await
|
|
76
|
+
// it. Left unguarded, a subclass whose init() rejected took the process down from a
|
|
77
|
+
// constructor; kept instead, so ready() can name the cause.
|
|
78
|
+
void this.init().catch((e) => {
|
|
79
|
+
this.initError = e;
|
|
80
|
+
this.emitSafely('initError', e);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/** Why init() failed, rethrown by ready() so the caller sees the cause and not a timeout. */
|
|
84
|
+
initError;
|
|
85
|
+
/** Resolves when every transport has been built and wired. ready() waits on it. */
|
|
86
|
+
starting = Promise.resolve();
|
|
87
|
+
/**
|
|
88
|
+
* Build each configured transport and wire it in. The socket.io listener and the MQTT client
|
|
89
|
+
* are imported here rather than at the top of the file: a page hosting an RpcServer over a
|
|
90
|
+
* connection it dials has no use for either, and a static import would put both in its bundle.
|
|
91
|
+
*/
|
|
92
|
+
/** What to build when nothing was configured. A peer that cannot listen has no useful default. */
|
|
93
|
+
configuredTransports() {
|
|
94
|
+
return this.options.transports;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Turn one configuration entry into a transport, or undefined if this class does not know that
|
|
98
|
+
* shape. NodeRpcServer overrides it for the shapes that need Node and defers here for the rest.
|
|
99
|
+
*/
|
|
100
|
+
async buildTransport(serveroption) {
|
|
101
|
+
if (serveroption instanceof GenericModule)
|
|
102
|
+
return serveroption;
|
|
103
|
+
if (serveroption.connect) {
|
|
104
|
+
const connectOptions = serveroption;
|
|
105
|
+
return new SocketIoClientTransport(this.options.name, connectOptions.connect, [], {
|
|
106
|
+
...(connectOptions.path ? { path: connectOptions.path } : {}),
|
|
107
|
+
...(connectOptions.credentials ? { auth: connectOptions.credentials } : {}),
|
|
108
|
+
// The typings narrow `ca` to a string; the runtime takes what Node's tls does.
|
|
109
|
+
...(connectOptions.ca ? { ca: connectOptions.ca } : {})
|
|
110
|
+
}, true, connectOptions.allowInsecureTls);
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
async buildTransports() {
|
|
115
|
+
const codec = codecFor(this.options.useMsgPack);
|
|
116
|
+
for (const serveroption of this.configuredTransports()) {
|
|
117
|
+
const transport = await this.buildTransport(serveroption);
|
|
118
|
+
if (!transport)
|
|
119
|
+
throw new Error(`RpcServer '${this.options.name}': no transport can be built from ${JSON.stringify(serveroption)}`);
|
|
120
|
+
// The transports encode, so there is no converter between them and the handler. A
|
|
121
|
+
// structured wire format such as MQTT 5 needs to see the message rather than bytes a
|
|
122
|
+
// converter already flattened.
|
|
123
|
+
transport.codec = codec;
|
|
124
|
+
if (this.options.relay !== undefined && 'relay' in transport)
|
|
125
|
+
transport.relay = this.options.relay;
|
|
126
|
+
this.attach(transport);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/** Put one transport into the graph: piped into both handlers, routable from the switch. */
|
|
130
|
+
attach(transport) {
|
|
131
|
+
this.transports.push(transport);
|
|
132
|
+
transport.usePeerRegistry(this.peers);
|
|
133
|
+
transport.pipe(this.rpc);
|
|
134
|
+
transport.pipe(this.caller);
|
|
135
|
+
this.switch?.setTarget(transport);
|
|
136
|
+
// Both listeners are guarded: a transport emits these synchronously from its own inbound
|
|
137
|
+
// path, so anything thrown here unwinds into the transport rather than into something able
|
|
138
|
+
// to report it.
|
|
139
|
+
transport.on(TransportEvent.peerGone, (peer) => this.safely('peerGone', peer, () => {
|
|
140
|
+
// Drop the peer's event subscriptions and forget its route as soon as it goes.
|
|
141
|
+
this.rpc.removePeer(peer);
|
|
142
|
+
this.peers.delete(peer);
|
|
143
|
+
this.relayPresence(transport, peer, 'offline');
|
|
144
|
+
// A gateway subscription taken out for this peer has nothing left to collect.
|
|
145
|
+
for (const other of this.transports) {
|
|
146
|
+
const gateway = other;
|
|
147
|
+
if (gateway.stopWatchingFor)
|
|
148
|
+
void gateway.stopWatchingFor(peer).catch((e) => this.emitSafely('presenceError', { peer, error: e }));
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
// A peer that arrives on one transport is announced on the others, so a browser connected
|
|
152
|
+
// over socket.io learns about a peer that only exists on the broker.
|
|
153
|
+
transport.on(TransportEvent.peerOnline, (peer) => this.safely('peerOnline', peer, () => this.relayPresence(transport, peer, 'online')));
|
|
154
|
+
// Subscriptions this server holds on other peers are replayed when a link returns, the same
|
|
155
|
+
// way RpcClient does it - otherwise a server that watches its peers goes deaf after a blip
|
|
156
|
+
// with nothing to say so.
|
|
157
|
+
transport.on(TransportEvent.connected, () => void this.caller.resubscribe().catch((e) => this.emitSafely('resubscribeError', e)));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Pass a presence change from the transport that saw it to the other links: told directly to
|
|
161
|
+
* the peers connected here, and advertised to the hubs this server has dialled into. The
|
|
162
|
+
* advertisement is what makes a network deeper than a star work - and it never includes a peer
|
|
163
|
+
* back on the link it was learned from, or two hubs each end up believing the other is the way
|
|
164
|
+
* to it.
|
|
165
|
+
*/
|
|
166
|
+
relayPresence(from, peer, state) {
|
|
167
|
+
for (const transport of this.transports) {
|
|
168
|
+
if (transport === from)
|
|
169
|
+
continue;
|
|
170
|
+
const listener = transport;
|
|
171
|
+
if (listener.announcePeer)
|
|
172
|
+
listener.announcePeer(peer, state);
|
|
173
|
+
}
|
|
174
|
+
this.advertiseReachability();
|
|
175
|
+
}
|
|
176
|
+
advertiseReachability() {
|
|
177
|
+
for (const transport of this.transports) {
|
|
178
|
+
if (!(transport instanceof SocketIoClientTransport))
|
|
179
|
+
continue;
|
|
180
|
+
transport.advertise(this.peers.names().filter((name) => name !== this.options.name && this.peers.get(name) !== transport));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** Not 'error': an EventEmitter throws on an unhandled 'error' event. */
|
|
184
|
+
emitSafely(event, payload) {
|
|
185
|
+
for (const transport of this.transports)
|
|
186
|
+
transport.emit(event, payload);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Run a presence reaction without letting it escape into the transport that emitted the event.
|
|
190
|
+
* Bookkeeping here failing is worth reporting; it is not worth ending the process over.
|
|
191
|
+
*/
|
|
192
|
+
safely(what, peer, react) {
|
|
193
|
+
try {
|
|
194
|
+
react();
|
|
195
|
+
}
|
|
196
|
+
catch (e) {
|
|
197
|
+
this.emitSafely('presenceError', { what, peer, error: e });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* A typed proxy for calling another peer, over this server's own transports and under its own
|
|
202
|
+
* name. The mirror of RpcClient.proxy, so a peer that both serves and calls needs one object.
|
|
203
|
+
*/
|
|
204
|
+
async proxy(name, target) {
|
|
205
|
+
await this.ready();
|
|
206
|
+
const result = { name };
|
|
207
|
+
if (target)
|
|
208
|
+
result.target = target;
|
|
209
|
+
result.remote = this.caller.proxy(name, target ?? '*');
|
|
210
|
+
return result;
|
|
211
|
+
}
|
|
212
|
+
async close() {
|
|
213
|
+
this.caller.failPendingCalls('server closed');
|
|
214
|
+
this.caller.subscriptions.clear();
|
|
215
|
+
await this.caller.close();
|
|
216
|
+
// forEach with an async callback did not await anything, so close() returned while the
|
|
217
|
+
// listeners were still open.
|
|
218
|
+
await Promise.all(this.transports.map((transport) => transport.close()));
|
|
219
|
+
this.transports = [];
|
|
220
|
+
this.peers.clear();
|
|
221
|
+
}
|
|
222
|
+
exposeClassInstance(instance, name, options) {
|
|
223
|
+
this.rpc.manageRpc.exposeClassInstance(instance, name, options);
|
|
224
|
+
}
|
|
225
|
+
exposeClass(constructor, aliasName) {
|
|
226
|
+
this.rpc.manageRpc.exposeClass(constructor, aliasName);
|
|
227
|
+
}
|
|
228
|
+
exposeObject(obj, name) {
|
|
229
|
+
this.rpc.manageRpc.exposeObject(obj, name);
|
|
230
|
+
}
|
|
231
|
+
expose(methodName, method) {
|
|
232
|
+
this.rpc.manageRpc.expose(methodName, method);
|
|
233
|
+
}
|
|
234
|
+
createRpcInstance(className, instanceName, ...args) {
|
|
235
|
+
return this.rpc.manageRpc.createRpcInstance(className, instanceName, ...args);
|
|
236
|
+
}
|
|
237
|
+
addTarget(target, transport) {
|
|
238
|
+
this.switch?.setTarget(transport);
|
|
239
|
+
}
|
|
240
|
+
async init() { }
|
|
241
|
+
async ready() {
|
|
242
|
+
await this.starting;
|
|
243
|
+
const allTransportsReady = () => {
|
|
244
|
+
return this.transports.filter((trp) => !trp.readyFlag).length == 0;
|
|
245
|
+
};
|
|
246
|
+
// Previously an unbounded wait, so a server whose broker was unreachable hung at startup
|
|
247
|
+
// with no diagnostic at all.
|
|
248
|
+
const deadline = Date.now() + this.options.readyTimeout;
|
|
249
|
+
while (!allTransportsReady() || !this.readyFlag) {
|
|
250
|
+
// A transport that can never come up says so, rather than being waited out: a port
|
|
251
|
+
// already in use is not something more time fixes.
|
|
252
|
+
const failed = this.transports.find((transport) => transport.startupError !== undefined);
|
|
253
|
+
if (failed)
|
|
254
|
+
this.initError = failed.startupError;
|
|
255
|
+
if (this.initError !== undefined)
|
|
256
|
+
throw new Error(`RpcServer '${this.options.name}': could not start: ${this.initError instanceof Error ? this.initError.message : String(this.initError)}`, {
|
|
257
|
+
cause: this.initError
|
|
258
|
+
});
|
|
259
|
+
if (this.options.readyTimeout > 0 && Date.now() > deadline) {
|
|
260
|
+
const pending = this.transports.filter((trp) => !trp.readyFlag).map((trp) => trp.getName());
|
|
261
|
+
throw new Error(`RpcServer '${this.options.name}': transports not ready within ${this.options.readyTimeout} ms: ${pending.join(', ')}`);
|
|
262
|
+
}
|
|
263
|
+
await new Promise((res) => setTimeout(res, 10));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Wait until a peer is addressable from here, rather than calling it and hoping.
|
|
268
|
+
*
|
|
269
|
+
* `ready()` says this peer's own links are up. It says nothing about anyone else, and it cannot:
|
|
270
|
+
* presence arrives over those links a moment after they open, and over MQTT a retained
|
|
271
|
+
* announcement lands a moment after the subscription does. Calling in that moment reaches a
|
|
272
|
+
* switch with no route and fails.
|
|
273
|
+
*
|
|
274
|
+
* This is the wait that closes it, and the reason it is here rather than in each application is
|
|
275
|
+
* that everything built on this library has needed it - the CLI's verbs, its recorder, its
|
|
276
|
+
* replayer and its console each grew their own copy before this existed.
|
|
277
|
+
*
|
|
278
|
+
* Returns true when the peer is addressable, false if it never appeared. A `false` is worth
|
|
279
|
+
* reporting as "nobody is answering to that name" rather than retrying: the usual cause is a
|
|
280
|
+
* peer that is not running or is running under a different name.
|
|
281
|
+
*/
|
|
282
|
+
async awaitPeer(peer, timeout = 5000) {
|
|
283
|
+
const deadline = Date.now() + timeout;
|
|
284
|
+
for (;;) {
|
|
285
|
+
if (this.peers.get(peer))
|
|
286
|
+
return true;
|
|
287
|
+
if (Date.now() >= deadline)
|
|
288
|
+
return false;
|
|
289
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
//# sourceMappingURL=RpcServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Rp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EAAE,GAAG,QAAQ,EAAE,CAAC;gBACzD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAA;gBAC3F,MAAM,IAAI,KAAK,CAAC,cAAc,IAAI,CAAC,OAAO,CAAC,IAAI,kCAAkC,IAAI,CAAC,OAAO,CAAC,YAAY,QAAQ,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC3I,CAAC;YACD,MAAM,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAA;QACnD,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,SAAS,CAAC,IAAY,EAAE,OAAO,GAAG,IAAI;QACxC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAA;QACrC,SAAS,CAAC;YACN,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAA;YACrC,IAAI,IAAI,CAAC,GAAG,EAAE,IAAI,QAAQ;gBAAE,OAAO,KAAK,CAAA;YACxC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAA;QAC3D,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Message } from '../RPC/Core.js';
|
|
2
|
+
/**
|
|
3
|
+
* Mapping between msgrpc messages and the MQTT 5 packet layout described in
|
|
4
|
+
* docs/mqtt5-frame-spec.md.
|
|
5
|
+
*
|
|
6
|
+
* The point is that a peer needs no msgrpc code to take part: where to reply and how to correlate
|
|
7
|
+
* come from the protocol's own Response Topic and Correlation Data, and everything else is a
|
|
8
|
+
* readable user property. Kept separate from the transport so the mapping can be read, and tested,
|
|
9
|
+
* without a broker.
|
|
10
|
+
*/
|
|
11
|
+
/** Control properties are prefixed so a broker or gateway injecting its own cannot be mistaken for one. */
|
|
12
|
+
export declare const MR: {
|
|
13
|
+
readonly version: 'mr-v';
|
|
14
|
+
readonly source: 'mr-src';
|
|
15
|
+
readonly kind: 'mr-kind';
|
|
16
|
+
readonly path: 'mr-path';
|
|
17
|
+
readonly method: 'mr-method';
|
|
18
|
+
readonly event: 'mr-event';
|
|
19
|
+
readonly code: 'mr-code';
|
|
20
|
+
readonly nonce: 'mr-nonce';
|
|
21
|
+
readonly timestamp: 'mr-ts';
|
|
22
|
+
readonly signature: 'mr-sig';
|
|
23
|
+
readonly contractVersion: 'mr-ver';
|
|
24
|
+
/**
|
|
25
|
+
* Milliseconds the caller will still wait, counted from when it sent. Carried alongside MQTT's
|
|
26
|
+
* own messageExpiryInterval rather than instead of it: expiry is coarse (whole seconds), the
|
|
27
|
+
* broker decrements it, and it stops at the broker - it says nothing about how long a frame then
|
|
28
|
+
* sat in the receiving process. This is the caller's own statement, signed, and it survives
|
|
29
|
+
* relaying through a transport that does not speak MQTT at all.
|
|
30
|
+
*/
|
|
31
|
+
readonly ttl: 'mr-ttl';
|
|
32
|
+
/**
|
|
33
|
+
* Names the command a request is an attempt at, when the caller distinguishes the two. Absent
|
|
34
|
+
* means the correlation data is the name, so a redelivered packet is the same command and a
|
|
35
|
+
* fresh attempt is a different one.
|
|
36
|
+
*/
|
|
37
|
+
readonly idempotencyKey: 'mr-idem';
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Version 2 covers contentType, the error code, the declared contract version, the response topic,
|
|
41
|
+
* the ttl and the idempotency key in the signature; version 1 covered none of them, and a frame
|
|
42
|
+
* signed under one cannot verify under the other. Bumped rather than negotiated: a receiver that quietly accepted either
|
|
43
|
+
* would let an attacker choose the weaker.
|
|
44
|
+
*/
|
|
45
|
+
export declare const FRAME_VERSION = "2";
|
|
46
|
+
/** Frame versions this build will accept. A frame announcing anything else is refused, not guessed at. */
|
|
47
|
+
export declare const SUPPORTED_FRAME_VERSIONS: Set<string>;
|
|
48
|
+
export type FrameKind = 'call' | 'subscribe' | 'unsubscribe' | 'result' | 'error' | 'event';
|
|
49
|
+
/** Which per-peer topic a frame belongs on. */
|
|
50
|
+
export type Channel = 'req' | 'rsp' | 'evt';
|
|
51
|
+
export interface OutboundFrame {
|
|
52
|
+
kind: FrameKind;
|
|
53
|
+
channel: Channel;
|
|
54
|
+
/** The request id, carried as MQTT correlation data. Absent on events. */
|
|
55
|
+
correlation?: string;
|
|
56
|
+
path?: string;
|
|
57
|
+
method?: string;
|
|
58
|
+
event?: string;
|
|
59
|
+
code?: string;
|
|
60
|
+
/** Contract version the caller declares, when it has one. */
|
|
61
|
+
version?: string;
|
|
62
|
+
/** Milliseconds the caller will still wait. Drives the MQTT message expiry as well. */
|
|
63
|
+
ttl?: number;
|
|
64
|
+
/** Names the command rather than this attempt at it, when the caller says so. */
|
|
65
|
+
idempotencyKey?: string;
|
|
66
|
+
/** Encoded as the packet payload: arguments for a request, the value for a result. */
|
|
67
|
+
body: unknown;
|
|
68
|
+
}
|
|
69
|
+
/** Kinds that expect an answer, and so are the only ones entitled to say where it should go. */
|
|
70
|
+
export declare const isRequestKind: (kind: string | undefined) => kind is "call" | "subscribe" | "unsubscribe";
|
|
71
|
+
/** Undefined for anything this layout has no representation for, which the transport drops. */
|
|
72
|
+
export declare const toOutboundFrame: (message: Message) => OutboundFrame | undefined;
|
|
73
|
+
export interface InboundFrame {
|
|
74
|
+
kind: string;
|
|
75
|
+
correlation?: string;
|
|
76
|
+
path?: string;
|
|
77
|
+
method?: string;
|
|
78
|
+
event?: string;
|
|
79
|
+
code?: string;
|
|
80
|
+
version?: string;
|
|
81
|
+
/** What the caller said it would still wait, already narrowed by anything the broker reported. */
|
|
82
|
+
ttl?: number;
|
|
83
|
+
idempotencyKey?: string;
|
|
84
|
+
body: unknown;
|
|
85
|
+
}
|
|
86
|
+
/** Undefined when the frame does not describe anything this RPC layer can dispatch. */
|
|
87
|
+
export declare const fromInboundFrame: (frame: InboundFrame) => Message | undefined;
|
|
88
|
+
export type RawUserProperties = {
|
|
89
|
+
[key: string]: string | string[];
|
|
90
|
+
} | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Read the control properties, refusing any that appear more than once.
|
|
93
|
+
*
|
|
94
|
+
* MQTT permits a repeated user property, and mqtt.js surfaces repeats as an array. Taking the
|
|
95
|
+
* first or the last would let a sender show one value to a check and a different one to the
|
|
96
|
+
* dispatcher, so a repeat is an ambiguity to refuse rather than resolve.
|
|
97
|
+
*/
|
|
98
|
+
export declare const readControlProperties: (properties: RawUserProperties) => {
|
|
99
|
+
values: {
|
|
100
|
+
[key: string]: string;
|
|
101
|
+
};
|
|
102
|
+
} | {
|
|
103
|
+
duplicate: string;
|
|
104
|
+
};
|
|
105
|
+
export declare const correlationToString: (correlation: Uint8Array | undefined) => string | undefined;
|
|
106
|
+
export declare const correlationToBytes: (correlation: string | undefined) => Uint8Array<ArrayBuffer> | undefined;
|
|
107
|
+
//# sourceMappingURL=Mqtt5Frame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mqtt5Frame.d.ts","sourceRoot":"","sources":["../../src/Transports/Mqtt5Frame.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAe,MAAM,gBAAgB,CAAA;AAYrD;;;;;;;;GAQG;AAEH,2GAA2G;AAC3G,eAAO,MAAM,EAAE;aACX,OAAO,EAAE,MAAM;aACf,MAAM,EAAE,QAAQ;aAChB,IAAI,EAAE,SAAS;aACf,IAAI,EAAE,SAAS;aACf,MAAM,EAAE,WAAW;aACnB,KAAK,EAAE,UAAU;aACjB,IAAI,EAAE,SAAS;aACf,KAAK,EAAE,UAAU;aACjB,SAAS,EAA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