@replit/river 0.205.2 → 0.207.1
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/dist/{chunk-FCN2JPOE.js → chunk-7LMZNSVC.js} +2 -2
- package/dist/{chunk-BYA34LH3.js → chunk-BCCZA7SX.js} +14 -27
- package/dist/chunk-BCCZA7SX.js.map +1 -0
- package/dist/{chunk-W337YQLT.js → chunk-CRD3HDVN.js} +3 -3
- package/dist/{chunk-TP4OJAKI.js → chunk-I27WBSMZ.js} +3 -3
- package/dist/{chunk-FTOB2HQN.js → chunk-QMAVXV4Z.js} +8 -3
- package/dist/chunk-QMAVXV4Z.js.map +1 -0
- package/dist/{connection-8ed39cb5.d.ts → connection-933c87b2.d.ts} +2 -2
- package/dist/logging/index.d.cts +1 -1
- package/dist/logging/index.d.ts +1 -1
- package/dist/{message-865bba35.d.ts → message-ffacb98a.d.ts} +1 -1
- package/dist/router/index.cjs +15 -29
- package/dist/router/index.cjs.map +1 -1
- package/dist/router/index.d.cts +5 -8
- package/dist/router/index.d.ts +5 -8
- package/dist/router/index.js +2 -4
- package/dist/{services-036dcc97.d.ts → services-4cd29829.d.ts} +731 -16
- package/dist/testUtil/index.cjs +7 -2
- package/dist/testUtil/index.cjs.map +1 -1
- package/dist/testUtil/index.d.cts +3 -5
- package/dist/testUtil/index.d.ts +3 -5
- package/dist/testUtil/index.js +4 -4
- package/dist/transport/impls/ws/client.cjs +7 -2
- package/dist/transport/impls/ws/client.cjs.map +1 -1
- package/dist/transport/impls/ws/client.d.cts +3 -4
- package/dist/transport/impls/ws/client.d.ts +3 -4
- package/dist/transport/impls/ws/client.js +4 -4
- package/dist/transport/impls/ws/server.cjs +7 -2
- package/dist/transport/impls/ws/server.cjs.map +1 -1
- package/dist/transport/impls/ws/server.d.cts +4 -4
- package/dist/transport/impls/ws/server.d.ts +4 -4
- package/dist/transport/impls/ws/server.js +4 -4
- package/dist/transport/index.cjs +7 -2
- package/dist/transport/index.cjs.map +1 -1
- package/dist/transport/index.d.cts +72 -5
- package/dist/transport/index.d.ts +72 -5
- package/dist/transport/index.js +4 -4
- package/package.json +1 -1
- package/dist/chunk-BYA34LH3.js.map +0 -1
- package/dist/chunk-FTOB2HQN.js.map +0 -1
- package/dist/client-8ab60722.d.ts +0 -54
- package/dist/context-2c4bb66b.d.ts +0 -670
- package/dist/server-dc261419.d.ts +0 -70
- /package/dist/{chunk-FCN2JPOE.js.map → chunk-7LMZNSVC.js.map} +0 -0
- /package/dist/{chunk-W337YQLT.js.map → chunk-CRD3HDVN.js.map} +0 -0
- /package/dist/{chunk-TP4OJAKI.js.map → chunk-I27WBSMZ.js.map} +0 -0
|
@@ -1,670 +0,0 @@
|
|
|
1
|
-
import { g as TelemetryInfo, M as MessageMetadata, c as TransportClientId, L as Logger, b as OpaqueTransportMessage, P as ProtocolVersion, f as PartialTransportMessage, a as TransportMessage, e as Tags, H as HandshakeErrorResponseCodes, h as LogFn, j as LoggingLevel, k as HandshakeErrorCustomHandlerFatalResponseCodes } from './message-865bba35.js';
|
|
2
|
-
import { Static, TSchema } from '@sinclair/typebox';
|
|
3
|
-
import { Tracer, Span } from '@opentelemetry/api';
|
|
4
|
-
import { C as Codec } from './types-3e5768ec.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A connection is the actual raw underlying transport connection.
|
|
8
|
-
* It’s responsible for dispatching to/from the actual connection itself
|
|
9
|
-
* This should be instantiated as soon as the client/server has a connection
|
|
10
|
-
* It’s tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
|
|
11
|
-
*/
|
|
12
|
-
declare abstract class Connection {
|
|
13
|
-
id: string;
|
|
14
|
-
telemetry?: TelemetryInfo;
|
|
15
|
-
constructor();
|
|
16
|
-
get loggingMetadata(): MessageMetadata;
|
|
17
|
-
private _dataListeners;
|
|
18
|
-
private _closeListeners;
|
|
19
|
-
private _errorListeners;
|
|
20
|
-
get dataListeners(): ((msg: Uint8Array) => void)[];
|
|
21
|
-
get closeListeners(): (() => void)[];
|
|
22
|
-
get errorListeners(): ((err: Error) => void)[];
|
|
23
|
-
onData(msg: Uint8Array): void;
|
|
24
|
-
onError(err: Error): void;
|
|
25
|
-
onClose(): void;
|
|
26
|
-
/**
|
|
27
|
-
* Handle adding a callback for when a message is received.
|
|
28
|
-
* @param msg The message that was received.
|
|
29
|
-
*/
|
|
30
|
-
addDataListener(cb: (msg: Uint8Array) => void): void;
|
|
31
|
-
removeDataListener(cb: (msg: Uint8Array) => void): void;
|
|
32
|
-
/**
|
|
33
|
-
* Handle adding a callback for when the connection is closed.
|
|
34
|
-
* This should also be called if an error happens and after notifying all the error listeners.
|
|
35
|
-
* @param cb The callback to call when the connection is closed.
|
|
36
|
-
*/
|
|
37
|
-
addCloseListener(cb: () => void): void;
|
|
38
|
-
removeCloseListener(cb: () => void): void;
|
|
39
|
-
/**
|
|
40
|
-
* Handle adding a callback for when an error is received.
|
|
41
|
-
* This should only be used for this.logging errors, all cleanup
|
|
42
|
-
* should be delegated to addCloseListener.
|
|
43
|
-
*
|
|
44
|
-
* The implementer should take care such that the implemented
|
|
45
|
-
* connection will call both the close and error callbacks
|
|
46
|
-
* on an error.
|
|
47
|
-
*
|
|
48
|
-
* @param cb The callback to call when an error is received.
|
|
49
|
-
*/
|
|
50
|
-
addErrorListener(cb: (err: Error) => void): void;
|
|
51
|
-
removeErrorListener(cb: (err: Error) => void): void;
|
|
52
|
-
/**
|
|
53
|
-
* Sends a message over the connection.
|
|
54
|
-
* @param msg The message to send.
|
|
55
|
-
* @returns true if the message was sent, false otherwise.
|
|
56
|
-
*/
|
|
57
|
-
abstract send(msg: Uint8Array): boolean;
|
|
58
|
-
/**
|
|
59
|
-
* Closes the connection.
|
|
60
|
-
*/
|
|
61
|
-
abstract close(): void;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
declare const enum SessionState {
|
|
65
|
-
NoConnection = "NoConnection",
|
|
66
|
-
BackingOff = "BackingOff",
|
|
67
|
-
Connecting = "Connecting",
|
|
68
|
-
Handshaking = "Handshaking",
|
|
69
|
-
Connected = "Connected",
|
|
70
|
-
WaitingForHandshake = "WaitingForHandshake"
|
|
71
|
-
}
|
|
72
|
-
declare abstract class StateMachineState {
|
|
73
|
-
abstract readonly state: SessionState;
|
|
74
|
-
_isConsumed: boolean;
|
|
75
|
-
abstract _handleStateExit(): void;
|
|
76
|
-
abstract _handleClose(): void;
|
|
77
|
-
/**
|
|
78
|
-
* Cleanup this state machine state and mark it as consumed.
|
|
79
|
-
* After calling close, it is an error to access any properties on the state.
|
|
80
|
-
* You should never need to call this as a consumer.
|
|
81
|
-
*
|
|
82
|
-
* If you're looking to close the session from the client,
|
|
83
|
-
* use `.hardDisconnect` on the client transport.
|
|
84
|
-
*/
|
|
85
|
-
close(): void;
|
|
86
|
-
constructor();
|
|
87
|
-
}
|
|
88
|
-
interface SessionOptions {
|
|
89
|
-
/**
|
|
90
|
-
* Frequency at which to send heartbeat acknowledgements
|
|
91
|
-
*/
|
|
92
|
-
heartbeatIntervalMs: number;
|
|
93
|
-
/**
|
|
94
|
-
* Number of elapsed heartbeats without a response message before we consider
|
|
95
|
-
* the connection dead.
|
|
96
|
-
*/
|
|
97
|
-
heartbeatsUntilDead: number;
|
|
98
|
-
/**
|
|
99
|
-
* Max duration that a session can be without a connection before we consider
|
|
100
|
-
* it dead. This deadline is carried between states and is used to determine
|
|
101
|
-
* when to consider the session a lost cause and delete it entirely.
|
|
102
|
-
* Generally, this should be strictly greater than the sum of
|
|
103
|
-
* {@link connectionTimeoutMs} and {@link handshakeTimeoutMs}.
|
|
104
|
-
*/
|
|
105
|
-
sessionDisconnectGraceMs: number;
|
|
106
|
-
/**
|
|
107
|
-
* Connection timeout in milliseconds
|
|
108
|
-
*/
|
|
109
|
-
connectionTimeoutMs: number;
|
|
110
|
-
/**
|
|
111
|
-
* Handshake timeout in milliseconds
|
|
112
|
-
*/
|
|
113
|
-
handshakeTimeoutMs: number;
|
|
114
|
-
/**
|
|
115
|
-
* Whether to enable transparent session reconnects
|
|
116
|
-
*/
|
|
117
|
-
enableTransparentSessionReconnects: boolean;
|
|
118
|
-
/**
|
|
119
|
-
* The codec to use for encoding/decoding messages over the wire
|
|
120
|
-
*/
|
|
121
|
-
codec: Codec;
|
|
122
|
-
}
|
|
123
|
-
interface CommonSessionProps {
|
|
124
|
-
from: TransportClientId;
|
|
125
|
-
options: SessionOptions;
|
|
126
|
-
tracer: Tracer;
|
|
127
|
-
log: Logger | undefined;
|
|
128
|
-
}
|
|
129
|
-
declare abstract class CommonSession extends StateMachineState {
|
|
130
|
-
readonly from: TransportClientId;
|
|
131
|
-
readonly options: SessionOptions;
|
|
132
|
-
tracer: Tracer;
|
|
133
|
-
log?: Logger;
|
|
134
|
-
abstract get loggingMetadata(): MessageMetadata;
|
|
135
|
-
constructor({ from, options, log, tracer }: CommonSessionProps);
|
|
136
|
-
parseMsg(msg: Uint8Array): OpaqueTransportMessage | null;
|
|
137
|
-
}
|
|
138
|
-
type SessionId = string;
|
|
139
|
-
interface IdentifiedSessionProps extends CommonSessionProps {
|
|
140
|
-
id: SessionId;
|
|
141
|
-
to: TransportClientId;
|
|
142
|
-
seq: number;
|
|
143
|
-
ack: number;
|
|
144
|
-
seqSent: number;
|
|
145
|
-
sendBuffer: Array<OpaqueTransportMessage>;
|
|
146
|
-
telemetry: TelemetryInfo;
|
|
147
|
-
protocolVersion: ProtocolVersion;
|
|
148
|
-
}
|
|
149
|
-
declare abstract class IdentifiedSession extends CommonSession {
|
|
150
|
-
readonly id: SessionId;
|
|
151
|
-
readonly telemetry: TelemetryInfo;
|
|
152
|
-
readonly to: TransportClientId;
|
|
153
|
-
readonly protocolVersion: ProtocolVersion;
|
|
154
|
-
/**
|
|
155
|
-
* Index of the message we will send next (excluding handshake)
|
|
156
|
-
*/
|
|
157
|
-
seq: number;
|
|
158
|
-
/**
|
|
159
|
-
* Last seq we sent over the wire this session (excluding handshake) and retransmissions
|
|
160
|
-
*/
|
|
161
|
-
seqSent: number;
|
|
162
|
-
/**
|
|
163
|
-
* Number of unique messages we've received this session (excluding handshake)
|
|
164
|
-
*/
|
|
165
|
-
ack: number;
|
|
166
|
-
sendBuffer: Array<OpaqueTransportMessage>;
|
|
167
|
-
constructor(props: IdentifiedSessionProps);
|
|
168
|
-
get loggingMetadata(): MessageMetadata;
|
|
169
|
-
constructMsg<Payload>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
|
|
170
|
-
nextSeq(): number;
|
|
171
|
-
send(msg: PartialTransportMessage): string;
|
|
172
|
-
_handleStateExit(): void;
|
|
173
|
-
_handleClose(): void;
|
|
174
|
-
}
|
|
175
|
-
interface IdentifiedSessionWithGracePeriodListeners {
|
|
176
|
-
onSessionGracePeriodElapsed: () => void;
|
|
177
|
-
}
|
|
178
|
-
interface IdentifiedSessionWithGracePeriodProps extends IdentifiedSessionProps {
|
|
179
|
-
graceExpiryTime: number;
|
|
180
|
-
listeners: IdentifiedSessionWithGracePeriodListeners;
|
|
181
|
-
}
|
|
182
|
-
declare abstract class IdentifiedSessionWithGracePeriod extends IdentifiedSession {
|
|
183
|
-
graceExpiryTime: number;
|
|
184
|
-
protected gracePeriodTimeout?: ReturnType<typeof setTimeout>;
|
|
185
|
-
listeners: IdentifiedSessionWithGracePeriodListeners;
|
|
186
|
-
constructor(props: IdentifiedSessionWithGracePeriodProps);
|
|
187
|
-
_handleStateExit(): void;
|
|
188
|
-
_handleClose(): void;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
interface SessionConnectingListeners extends IdentifiedSessionWithGracePeriodListeners {
|
|
192
|
-
onConnectionEstablished: (conn: Connection) => void;
|
|
193
|
-
onConnectionFailed: (err: unknown) => void;
|
|
194
|
-
onConnectionTimeout: () => void;
|
|
195
|
-
}
|
|
196
|
-
interface SessionConnectingProps<ConnType extends Connection> extends IdentifiedSessionWithGracePeriodProps {
|
|
197
|
-
connPromise: Promise<ConnType>;
|
|
198
|
-
listeners: SessionConnectingListeners;
|
|
199
|
-
}
|
|
200
|
-
declare class SessionConnecting<ConnType extends Connection> extends IdentifiedSessionWithGracePeriod {
|
|
201
|
-
readonly state: SessionState.Connecting;
|
|
202
|
-
connPromise: Promise<ConnType>;
|
|
203
|
-
listeners: SessionConnectingListeners;
|
|
204
|
-
connectionTimeout?: ReturnType<typeof setTimeout>;
|
|
205
|
-
constructor(props: SessionConnectingProps<ConnType>);
|
|
206
|
-
bestEffortClose(): void;
|
|
207
|
-
_handleStateExit(): void;
|
|
208
|
-
_handleClose(): void;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
declare class SessionNoConnection extends IdentifiedSessionWithGracePeriod {
|
|
212
|
-
readonly state: SessionState.NoConnection;
|
|
213
|
-
_handleClose(): void;
|
|
214
|
-
_handleStateExit(): void;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
interface SessionHandshakingListeners extends IdentifiedSessionWithGracePeriodListeners {
|
|
218
|
-
onConnectionErrored: (err: unknown) => void;
|
|
219
|
-
onConnectionClosed: () => void;
|
|
220
|
-
onHandshake: (msg: OpaqueTransportMessage) => void;
|
|
221
|
-
onInvalidHandshake: (reason: string, code: Static<typeof HandshakeErrorResponseCodes>) => void;
|
|
222
|
-
onHandshakeTimeout: () => void;
|
|
223
|
-
}
|
|
224
|
-
interface SessionHandshakingProps<ConnType extends Connection> extends IdentifiedSessionWithGracePeriodProps {
|
|
225
|
-
conn: ConnType;
|
|
226
|
-
listeners: SessionHandshakingListeners;
|
|
227
|
-
}
|
|
228
|
-
declare class SessionHandshaking<ConnType extends Connection> extends IdentifiedSessionWithGracePeriod {
|
|
229
|
-
readonly state: SessionState.Handshaking;
|
|
230
|
-
conn: ConnType;
|
|
231
|
-
listeners: SessionHandshakingListeners;
|
|
232
|
-
handshakeTimeout?: ReturnType<typeof setTimeout>;
|
|
233
|
-
constructor(props: SessionHandshakingProps<ConnType>);
|
|
234
|
-
get loggingMetadata(): {
|
|
235
|
-
protocolVersion?: ProtocolVersion | undefined;
|
|
236
|
-
clientId?: string | undefined;
|
|
237
|
-
connectedTo?: string | undefined;
|
|
238
|
-
sessionId?: string | undefined;
|
|
239
|
-
connId?: string | undefined;
|
|
240
|
-
transportMessage?: Partial<OpaqueTransportMessage> | undefined;
|
|
241
|
-
validationErrors?: {
|
|
242
|
-
path: string;
|
|
243
|
-
message: string;
|
|
244
|
-
}[] | undefined;
|
|
245
|
-
tags?: Tags[] | undefined;
|
|
246
|
-
telemetry?: {
|
|
247
|
-
traceId: string;
|
|
248
|
-
spanId: string;
|
|
249
|
-
} | undefined;
|
|
250
|
-
extras?: Record<string, unknown> | undefined;
|
|
251
|
-
};
|
|
252
|
-
onHandshakeData: (msg: Uint8Array) => void;
|
|
253
|
-
sendHandshake(msg: TransportMessage): boolean;
|
|
254
|
-
_handleStateExit(): void;
|
|
255
|
-
_handleClose(): void;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
interface SessionConnectedListeners {
|
|
259
|
-
onConnectionErrored: (err: unknown) => void;
|
|
260
|
-
onConnectionClosed: () => void;
|
|
261
|
-
onMessage: (msg: OpaqueTransportMessage) => void;
|
|
262
|
-
onInvalidMessage: (reason: string) => void;
|
|
263
|
-
}
|
|
264
|
-
interface SessionConnectedProps<ConnType extends Connection> extends IdentifiedSessionProps {
|
|
265
|
-
conn: ConnType;
|
|
266
|
-
listeners: SessionConnectedListeners;
|
|
267
|
-
}
|
|
268
|
-
declare class SessionConnected<ConnType extends Connection> extends IdentifiedSession {
|
|
269
|
-
readonly state: SessionState.Connected;
|
|
270
|
-
conn: ConnType;
|
|
271
|
-
listeners: SessionConnectedListeners;
|
|
272
|
-
private heartbeatHandle?;
|
|
273
|
-
private heartbeatMisses;
|
|
274
|
-
isActivelyHeartbeating: boolean;
|
|
275
|
-
updateBookkeeping(ack: number, seq: number): void;
|
|
276
|
-
private assertSendOrdering;
|
|
277
|
-
send(msg: PartialTransportMessage): string;
|
|
278
|
-
constructor(props: SessionConnectedProps<ConnType>);
|
|
279
|
-
get loggingMetadata(): {
|
|
280
|
-
protocolVersion?: ProtocolVersion | undefined;
|
|
281
|
-
clientId?: string | undefined;
|
|
282
|
-
connectedTo?: string | undefined;
|
|
283
|
-
sessionId?: string | undefined;
|
|
284
|
-
connId?: string | undefined;
|
|
285
|
-
transportMessage?: Partial<OpaqueTransportMessage> | undefined;
|
|
286
|
-
validationErrors?: {
|
|
287
|
-
path: string;
|
|
288
|
-
message: string;
|
|
289
|
-
}[] | undefined;
|
|
290
|
-
tags?: Tags[] | undefined;
|
|
291
|
-
telemetry?: {
|
|
292
|
-
traceId: string;
|
|
293
|
-
spanId: string;
|
|
294
|
-
} | undefined;
|
|
295
|
-
extras?: Record<string, unknown> | undefined;
|
|
296
|
-
};
|
|
297
|
-
startActiveHeartbeat(): void;
|
|
298
|
-
private sendHeartbeat;
|
|
299
|
-
closeConnection(): void;
|
|
300
|
-
onMessageData: (msg: Uint8Array) => void;
|
|
301
|
-
_handleStateExit(): void;
|
|
302
|
-
_handleClose(): void;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
interface SessionBackingOffListeners extends IdentifiedSessionWithGracePeriodListeners {
|
|
306
|
-
onBackoffFinished: () => void;
|
|
307
|
-
}
|
|
308
|
-
interface SessionBackingOffProps extends IdentifiedSessionWithGracePeriodProps {
|
|
309
|
-
backoffMs: number;
|
|
310
|
-
listeners: SessionBackingOffListeners;
|
|
311
|
-
}
|
|
312
|
-
declare class SessionBackingOff extends IdentifiedSessionWithGracePeriod {
|
|
313
|
-
readonly state: SessionState.BackingOff;
|
|
314
|
-
listeners: SessionBackingOffListeners;
|
|
315
|
-
backoffTimeout?: ReturnType<typeof setTimeout>;
|
|
316
|
-
constructor(props: SessionBackingOffProps);
|
|
317
|
-
_handleClose(): void;
|
|
318
|
-
_handleStateExit(): void;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
type ClientSession<ConnType extends Connection> = SessionNoConnection | SessionBackingOff | SessionConnecting<ConnType> | SessionHandshaking<ConnType> | SessionConnected<ConnType>;
|
|
322
|
-
type ServerSession<ConnType extends Connection> = SessionConnected<ConnType> | SessionNoConnection;
|
|
323
|
-
type Session<ConnType extends Connection> = ClientSession<ConnType> | ServerSession<ConnType>;
|
|
324
|
-
|
|
325
|
-
declare const ProtocolError: {
|
|
326
|
-
readonly RetriesExceeded: "conn_retry_exceeded";
|
|
327
|
-
readonly HandshakeFailed: "handshake_failed";
|
|
328
|
-
readonly MessageOrderingViolated: "message_ordering_violated";
|
|
329
|
-
readonly InvalidMessage: "invalid_message";
|
|
330
|
-
};
|
|
331
|
-
type ProtocolErrorType = (typeof ProtocolError)[keyof typeof ProtocolError];
|
|
332
|
-
interface EventMap {
|
|
333
|
-
message: OpaqueTransportMessage;
|
|
334
|
-
sessionStatus: {
|
|
335
|
-
status: 'created' | 'closing';
|
|
336
|
-
session: Session<Connection>;
|
|
337
|
-
} | {
|
|
338
|
-
status: 'closed';
|
|
339
|
-
session: Pick<Session<Connection>, 'id' | 'to'>;
|
|
340
|
-
};
|
|
341
|
-
sessionTransition: {
|
|
342
|
-
state: SessionState.Connected;
|
|
343
|
-
id: SessionId;
|
|
344
|
-
} | {
|
|
345
|
-
state: SessionState.Handshaking;
|
|
346
|
-
id: SessionId;
|
|
347
|
-
} | {
|
|
348
|
-
state: SessionState.Connecting;
|
|
349
|
-
id: SessionId;
|
|
350
|
-
} | {
|
|
351
|
-
state: SessionState.BackingOff;
|
|
352
|
-
id: SessionId;
|
|
353
|
-
} | {
|
|
354
|
-
state: SessionState.NoConnection;
|
|
355
|
-
id: SessionId;
|
|
356
|
-
};
|
|
357
|
-
protocolError: {
|
|
358
|
-
type: (typeof ProtocolError)['HandshakeFailed'];
|
|
359
|
-
code: Static<typeof HandshakeErrorResponseCodes>;
|
|
360
|
-
message: string;
|
|
361
|
-
} | {
|
|
362
|
-
type: Omit<ProtocolErrorType, (typeof ProtocolError)['HandshakeFailed']>;
|
|
363
|
-
message: string;
|
|
364
|
-
};
|
|
365
|
-
transportStatus: {
|
|
366
|
-
status: TransportStatus;
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
type EventTypes = keyof EventMap;
|
|
370
|
-
type EventHandler<K extends EventTypes> = (event: EventMap[K]) => unknown;
|
|
371
|
-
declare class EventDispatcher<T extends EventTypes> {
|
|
372
|
-
private eventListeners;
|
|
373
|
-
removeAllListeners(): void;
|
|
374
|
-
numberOfListeners<K extends T>(eventType: K): number;
|
|
375
|
-
addEventListener<K extends T>(eventType: K, handler: EventHandler<K>): void;
|
|
376
|
-
removeEventListener<K extends T>(eventType: K, handler: EventHandler<K>): void;
|
|
377
|
-
dispatchEvent<K extends T>(eventType: K, event: EventMap[K]): void;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Options to control the backoff and retry behavior of the client transport's connection behaviour.
|
|
382
|
-
*
|
|
383
|
-
* River implements exponential backoff with jitter to prevent flooding the server
|
|
384
|
-
* when there's an issue with connection establishment.
|
|
385
|
-
*
|
|
386
|
-
* The backoff is calculated via the following:
|
|
387
|
-
* backOff = min(jitter + {@link baseIntervalMs} * 2 ^ budget_consumed, {@link maxBackoffMs})
|
|
388
|
-
*
|
|
389
|
-
* We use a leaky bucket rate limit with a budget of {@link attemptBudgetCapacity} reconnection attempts.
|
|
390
|
-
* Budget only starts to restore after a successful handshake at a rate of one budget per {@link budgetRestoreIntervalMs}.
|
|
391
|
-
*/
|
|
392
|
-
interface ConnectionRetryOptions {
|
|
393
|
-
/**
|
|
394
|
-
* The base interval to wait before retrying a connection.
|
|
395
|
-
*/
|
|
396
|
-
baseIntervalMs: number;
|
|
397
|
-
/**
|
|
398
|
-
* The maximum random jitter to add to the total backoff time.
|
|
399
|
-
*/
|
|
400
|
-
maxJitterMs: number;
|
|
401
|
-
/**
|
|
402
|
-
* The maximum amount of time to wait before retrying a connection.
|
|
403
|
-
* This does not include the jitter.
|
|
404
|
-
*/
|
|
405
|
-
maxBackoffMs: number;
|
|
406
|
-
/**
|
|
407
|
-
* The max number of times to attempt a connection before a successful handshake.
|
|
408
|
-
* This persists across connections but starts restoring budget after a successful handshake.
|
|
409
|
-
* The restoration interval depends on {@link budgetRestoreIntervalMs}
|
|
410
|
-
*/
|
|
411
|
-
attemptBudgetCapacity: number;
|
|
412
|
-
/**
|
|
413
|
-
* After a successful connection attempt, how long to wait before we restore a single budget.
|
|
414
|
-
*/
|
|
415
|
-
budgetRestoreIntervalMs: number;
|
|
416
|
-
}
|
|
417
|
-
declare class LeakyBucketRateLimit {
|
|
418
|
-
private budgetConsumed;
|
|
419
|
-
private intervalHandle?;
|
|
420
|
-
private readonly options;
|
|
421
|
-
constructor(options: ConnectionRetryOptions);
|
|
422
|
-
getBackoffMs(): number;
|
|
423
|
-
get totalBudgetRestoreTime(): number;
|
|
424
|
-
consumeBudget(): void;
|
|
425
|
-
getBudgetConsumed(): number;
|
|
426
|
-
hasBudget(): boolean;
|
|
427
|
-
startRestoringBudget(): void;
|
|
428
|
-
private stopLeak;
|
|
429
|
-
close(): void;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
type TransportOptions = SessionOptions;
|
|
433
|
-
type ProvidedTransportOptions = Partial<TransportOptions>;
|
|
434
|
-
type ClientTransportOptions = TransportOptions & ConnectionRetryOptions;
|
|
435
|
-
type ProvidedClientTransportOptions = Partial<ClientTransportOptions>;
|
|
436
|
-
type ServerTransportOptions = TransportOptions;
|
|
437
|
-
type ProvidedServerTransportOptions = Partial<ServerTransportOptions>;
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* Represents the possible states of a transport.
|
|
441
|
-
* @property {'open'} open - The transport is open and operational (note that this doesn't mean it is actively connected)
|
|
442
|
-
* @property {'closed'} closed - The transport is permanently closed and cannot be reopened.
|
|
443
|
-
*/
|
|
444
|
-
type TransportStatus = 'open' | 'closed';
|
|
445
|
-
interface DeleteSessionOptions {
|
|
446
|
-
unhealthy: boolean;
|
|
447
|
-
}
|
|
448
|
-
type SessionBoundSendFn = (msg: PartialTransportMessage) => string | undefined;
|
|
449
|
-
/**
|
|
450
|
-
* Transports manage the lifecycle (creation/deletion) of sessions
|
|
451
|
-
*
|
|
452
|
-
* ```plaintext
|
|
453
|
-
* ▲
|
|
454
|
-
* incoming │
|
|
455
|
-
* messages │
|
|
456
|
-
* ▼
|
|
457
|
-
* ┌─────────────┐ 1:N ┌───────────┐ 1:1* ┌────────────┐
|
|
458
|
-
* │ Transport │ ◄─────► │ Session │ ◄─────► │ Connection │
|
|
459
|
-
* └─────────────┘ └───────────┘ └────────────┘
|
|
460
|
-
* ▲ * (may or may not be initialized yet)
|
|
461
|
-
* │
|
|
462
|
-
* ▼
|
|
463
|
-
* ┌───────────┐
|
|
464
|
-
* │ Message │
|
|
465
|
-
* │ Listeners │
|
|
466
|
-
* └───────────┘
|
|
467
|
-
* ```
|
|
468
|
-
* @abstract
|
|
469
|
-
*/
|
|
470
|
-
declare abstract class Transport<ConnType extends Connection> {
|
|
471
|
-
/**
|
|
472
|
-
* The status of the transport.
|
|
473
|
-
*/
|
|
474
|
-
private status;
|
|
475
|
-
/**
|
|
476
|
-
* The client ID of this transport.
|
|
477
|
-
*/
|
|
478
|
-
clientId: TransportClientId;
|
|
479
|
-
/**
|
|
480
|
-
* The event dispatcher for handling events of type EventTypes.
|
|
481
|
-
*/
|
|
482
|
-
eventDispatcher: EventDispatcher<EventTypes>;
|
|
483
|
-
/**
|
|
484
|
-
* The options for this transport.
|
|
485
|
-
*/
|
|
486
|
-
protected options: TransportOptions;
|
|
487
|
-
log?: Logger;
|
|
488
|
-
tracer: Tracer;
|
|
489
|
-
sessions: Map<TransportClientId, Session<ConnType>>;
|
|
490
|
-
/**
|
|
491
|
-
* Creates a new Transport instance.
|
|
492
|
-
* @param codec The codec used to encode and decode messages.
|
|
493
|
-
* @param clientId The client ID of this transport.
|
|
494
|
-
*/
|
|
495
|
-
constructor(clientId: TransportClientId, providedOptions?: ProvidedTransportOptions);
|
|
496
|
-
bindLogger(fn: LogFn | Logger, level?: LoggingLevel): void;
|
|
497
|
-
/**
|
|
498
|
-
* Called when a message is received by this transport.
|
|
499
|
-
* You generally shouldn't need to override this in downstream transport implementations.
|
|
500
|
-
* @param message The received message.
|
|
501
|
-
*/
|
|
502
|
-
protected handleMsg(message: OpaqueTransportMessage): void;
|
|
503
|
-
/**
|
|
504
|
-
* Adds a listener to this transport.
|
|
505
|
-
* @param the type of event to listen for
|
|
506
|
-
* @param handler The message handler to add.
|
|
507
|
-
*/
|
|
508
|
-
addEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
|
|
509
|
-
/**
|
|
510
|
-
* Removes a listener from this transport.
|
|
511
|
-
* @param the type of event to un-listen on
|
|
512
|
-
* @param handler The message handler to remove.
|
|
513
|
-
*/
|
|
514
|
-
removeEventListener<K extends EventTypes, T extends EventHandler<K>>(type: K, handler: T): void;
|
|
515
|
-
protected protocolError(message: EventMap['protocolError']): void;
|
|
516
|
-
/**
|
|
517
|
-
* Default close implementation for transports. You should override this in the downstream
|
|
518
|
-
* implementation if you need to do any additional cleanup and call super.close() at the end.
|
|
519
|
-
* Closes the transport. Any messages sent while the transport is closed will be silently discarded.
|
|
520
|
-
*/
|
|
521
|
-
close(): void;
|
|
522
|
-
getStatus(): TransportStatus;
|
|
523
|
-
protected createSession<S extends Session<ConnType>>(session: S): void;
|
|
524
|
-
protected updateSession<S extends Session<ConnType>>(session: S): void;
|
|
525
|
-
protected deleteSession(session: Session<ConnType>, options?: DeleteSessionOptions): void;
|
|
526
|
-
protected onSessionGracePeriodElapsed(session: Session<ConnType>): void;
|
|
527
|
-
protected onConnectingFailed(session: SessionConnecting<ConnType>): SessionNoConnection;
|
|
528
|
-
protected onConnClosed(session: SessionHandshaking<ConnType> | SessionConnected<ConnType>): SessionNoConnection;
|
|
529
|
-
/**
|
|
530
|
-
* Gets a send closure scoped to a specific session. Sending using the returned
|
|
531
|
-
* closure after the session has transitioned to a different state will be a noop.
|
|
532
|
-
*
|
|
533
|
-
* Session objects themselves can become stale as they transition between
|
|
534
|
-
* states. As stale sessions cannot be used again (and will throw), holding
|
|
535
|
-
* onto a session object is not recommended.
|
|
536
|
-
*/
|
|
537
|
-
getSessionBoundSendFn(to: TransportClientId, sessionId: SessionId): SessionBoundSendFn;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
|
|
541
|
-
type ValidateHandshake<T extends TSchema> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata | Promise<Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata>;
|
|
542
|
-
interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
|
|
543
|
-
/**
|
|
544
|
-
* Schema for the metadata that the client sends to the server
|
|
545
|
-
* during the handshake.
|
|
546
|
-
*/
|
|
547
|
-
schema: MetadataSchema;
|
|
548
|
-
/**
|
|
549
|
-
* Gets the {@link HandshakeRequestMetadata} to send to the server.
|
|
550
|
-
*/
|
|
551
|
-
construct: ConstructHandshake<MetadataSchema>;
|
|
552
|
-
}
|
|
553
|
-
interface ServerHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
|
|
554
|
-
/**
|
|
555
|
-
* Schema for the metadata that the server receives from the client
|
|
556
|
-
* during the handshake.
|
|
557
|
-
*/
|
|
558
|
-
schema: MetadataSchema;
|
|
559
|
-
/**
|
|
560
|
-
* Parses the {@link HandshakeRequestMetadata} sent by the client, transforming
|
|
561
|
-
* it into {@link ParsedHandshakeMetadata}.
|
|
562
|
-
*
|
|
563
|
-
* May return `false` if the client should be rejected.
|
|
564
|
-
*
|
|
565
|
-
* @param metadata - The metadata sent by the client.
|
|
566
|
-
* @param session - The session that the client would be associated with.
|
|
567
|
-
* @param isReconnect - Whether the client is reconnecting to the session,
|
|
568
|
-
* or if this is a new session.
|
|
569
|
-
*/
|
|
570
|
-
validate: ValidateHandshake<MetadataSchema>;
|
|
571
|
-
}
|
|
572
|
-
declare function createClientHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, construct: ConstructHandshake<MetadataSchema>): ClientHandshakeOptions;
|
|
573
|
-
declare function createServerHandshakeOptions<MetadataSchema extends TSchema = TSchema>(schema: MetadataSchema, validate: ValidateHandshake<MetadataSchema>): ServerHandshakeOptions;
|
|
574
|
-
|
|
575
|
-
/**
|
|
576
|
-
* ServiceContext exist for the purpose of declaration merging
|
|
577
|
-
* to extend the context with additional properties.
|
|
578
|
-
*
|
|
579
|
-
* For example:
|
|
580
|
-
*
|
|
581
|
-
* ```ts
|
|
582
|
-
* declare module '@replit/river' {
|
|
583
|
-
* interface ServiceContext {
|
|
584
|
-
* db: Database;
|
|
585
|
-
* }
|
|
586
|
-
* }
|
|
587
|
-
*
|
|
588
|
-
* createServer(someTransport, myServices, { extendedContext: { db: myDb } });
|
|
589
|
-
* ```
|
|
590
|
-
*
|
|
591
|
-
* Once you do this, your {@link ProcedureHandlerContext} will have `db` property on it.
|
|
592
|
-
*/
|
|
593
|
-
interface ServiceContext {
|
|
594
|
-
}
|
|
595
|
-
/**
|
|
596
|
-
* The parsed metadata schema for a service. This is the
|
|
597
|
-
* return value of the {@link ServerHandshakeOptions.validate}
|
|
598
|
-
* if the handshake extension is used.
|
|
599
|
-
*
|
|
600
|
-
* You should use declaration merging to extend this interface
|
|
601
|
-
* with the sanitized metadata.
|
|
602
|
-
*
|
|
603
|
-
* ```ts
|
|
604
|
-
* declare module '@replit/river' {
|
|
605
|
-
* interface ParsedMetadata {
|
|
606
|
-
* userId: number;
|
|
607
|
-
* }
|
|
608
|
-
* }
|
|
609
|
-
* ```
|
|
610
|
-
*/
|
|
611
|
-
interface ParsedMetadata extends Record<string, unknown> {
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* This is passed to every procedure handler and contains various context-level
|
|
615
|
-
* information and utilities. This may be extended, see {@link ServiceContext}
|
|
616
|
-
*/
|
|
617
|
-
type ProcedureHandlerContext<State> = ServiceContext & {
|
|
618
|
-
/**
|
|
619
|
-
* State for this service as defined by the service definition.
|
|
620
|
-
*/
|
|
621
|
-
state: State;
|
|
622
|
-
/**
|
|
623
|
-
* The span for this procedure call. You can use this to add attributes, events, and
|
|
624
|
-
* links to the span.
|
|
625
|
-
*/
|
|
626
|
-
span: Span;
|
|
627
|
-
/**
|
|
628
|
-
* Metadata parsed on the server. See {@link ParsedMetadata}
|
|
629
|
-
*/
|
|
630
|
-
metadata: ParsedMetadata;
|
|
631
|
-
/**
|
|
632
|
-
* The ID of the session that sent this request.
|
|
633
|
-
*/
|
|
634
|
-
sessionId: SessionId;
|
|
635
|
-
/**
|
|
636
|
-
* The ID of the client that sent this request. There may be multiple sessions per client.
|
|
637
|
-
*/
|
|
638
|
-
from: TransportClientId;
|
|
639
|
-
/**
|
|
640
|
-
* This is used to cancel the procedure call from the handler and notify the client that the
|
|
641
|
-
* call was cancelled.
|
|
642
|
-
*
|
|
643
|
-
* Cancelling is not the same as closing procedure calls gracefully, please refer to
|
|
644
|
-
* the river documentation to understand the difference between the two concepts.
|
|
645
|
-
*/
|
|
646
|
-
cancel: () => void;
|
|
647
|
-
/**
|
|
648
|
-
* This signal is a standard [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
|
|
649
|
-
* triggered when the procedure invocation is done. This signal tracks the invocation/request finishing
|
|
650
|
-
* for _any_ reason, for example:
|
|
651
|
-
* - client explicit cancellation
|
|
652
|
-
* - procedure handler explicit cancellation via {@link cancel}
|
|
653
|
-
* - client session disconnect
|
|
654
|
-
* - server cancellation due to client invalid payload
|
|
655
|
-
* - invocation finishes cleanly, this depends on the type of the procedure (i.e. rpc handler return, or in a stream after the client-side has closed the request writable and the server-side has closed the response writable)
|
|
656
|
-
*
|
|
657
|
-
* You can use this to pass it on to asynchronous operations (such as fetch).
|
|
658
|
-
*
|
|
659
|
-
* You may also want to explicitly register callbacks on the
|
|
660
|
-
* ['abort' event](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/abort_event)
|
|
661
|
-
* as a way to cleanup after the request is finished.
|
|
662
|
-
*
|
|
663
|
-
* Note that (per standard AbortSignals) callbacks registered _after_ the procedure invocation
|
|
664
|
-
* is done are not triggered. In such cases, you can check the "aborted" property and cleanup
|
|
665
|
-
* immediately if needed.
|
|
666
|
-
*/
|
|
667
|
-
signal: AbortSignal;
|
|
668
|
-
};
|
|
669
|
-
|
|
670
|
-
export { SessionOptions as A, SessionBoundSendFn as B, Connection as C, DeleteSessionOptions as D, EventMap as E, LeakyBucketRateLimit as L, ProvidedTransportOptions as P, Session as S, Transport as T, TransportStatus as a, ProvidedClientTransportOptions as b, ProvidedServerTransportOptions as c, SessionState as d, SessionNoConnection as e, SessionConnecting as f, SessionHandshaking as g, SessionConnected as h, EventTypes as i, EventHandler as j, ProtocolError as k, ProtocolErrorType as l, ClientTransportOptions as m, ClientHandshakeOptions as n, ClientSession as o, SessionBackingOff as p, ParsedMetadata as q, ServerHandshakeOptions as r, ServiceContext as s, ProcedureHandlerContext as t, createClientHandshakeOptions as u, createServerHandshakeOptions as v, CommonSession as w, CommonSessionProps as x, ServerTransportOptions as y, ServerSession as z };
|