@replit/river 0.214.0 → 0.215.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.
Files changed (55) hide show
  1. package/dist/{adapter-Cp7_gIVA.d.ts → adapter-CgF7vQPu.d.ts} +3 -2
  2. package/dist/{adapter-DjiEwOYi.d.cts → adapter-IGrG4KLL.d.cts} +3 -2
  3. package/dist/{chunk-LECVFB2G.js → chunk-RDTQZ7HO.js} +15 -10
  4. package/dist/chunk-RDTQZ7HO.js.map +1 -0
  5. package/dist/{chunk-DRYCLL6N.js → chunk-VXRAFUA3.js} +178 -54
  6. package/dist/chunk-VXRAFUA3.js.map +1 -0
  7. package/dist/{client-Dw0JBBs3.d.ts → client-BhwlY0-L.d.ts} +2 -2
  8. package/dist/{client-DXJRow2s.d.cts → client-Dk4H7qeg.d.cts} +2 -2
  9. package/dist/codec/index.cjs.map +1 -1
  10. package/dist/codec/index.d.cts +3 -3
  11. package/dist/codec/index.d.ts +3 -3
  12. package/dist/codec/index.js +2 -2
  13. package/dist/{connection-Dzkqj18h.d.cts → connection-CS00EWuS.d.cts} +3 -3
  14. package/dist/{connection-C2lYgRh0.d.ts → connection-DU9v3y8a.d.ts} +3 -3
  15. package/dist/{index-D9R6UTMl.d.cts → index-CHCzvZ9D.d.cts} +1 -1
  16. package/dist/{index-CSM8soK7.d.ts → index-uF0cBM7z.d.ts} +1 -1
  17. package/dist/logging/index.d.cts +2 -2
  18. package/dist/logging/index.d.ts +2 -2
  19. package/dist/{message-Dlsh5WDF.d.cts → message-aABg0s5M.d.cts} +12 -1
  20. package/dist/{message-Dlsh5WDF.d.ts → message-aABg0s5M.d.ts} +12 -1
  21. package/dist/router/index.cjs +14 -9
  22. package/dist/router/index.cjs.map +1 -1
  23. package/dist/router/index.d.cts +10 -10
  24. package/dist/router/index.d.ts +10 -10
  25. package/dist/router/index.js +1 -1
  26. package/dist/{server-BDSYa-CO.d.cts → server-BR0DZaWi.d.cts} +4 -4
  27. package/dist/{server-DFOzjvLh.d.ts → server-uNzkzIRh.d.ts} +4 -4
  28. package/dist/{services-D47_GPCH.d.ts → services-B5SY771g.d.ts} +3 -3
  29. package/dist/{services-DqYQvm_L.d.cts → services-DBv2nmly.d.cts} +3 -3
  30. package/dist/testUtil/index.cjs +179 -53
  31. package/dist/testUtil/index.cjs.map +1 -1
  32. package/dist/testUtil/index.d.cts +7 -7
  33. package/dist/testUtil/index.d.ts +7 -7
  34. package/dist/testUtil/index.js +4 -2
  35. package/dist/testUtil/index.js.map +1 -1
  36. package/dist/transport/impls/ws/client.cjs +166 -53
  37. package/dist/transport/impls/ws/client.cjs.map +1 -1
  38. package/dist/transport/impls/ws/client.d.cts +6 -6
  39. package/dist/transport/impls/ws/client.d.ts +6 -6
  40. package/dist/transport/impls/ws/client.js +2 -2
  41. package/dist/transport/impls/ws/server.cjs +133 -53
  42. package/dist/transport/impls/ws/server.cjs.map +1 -1
  43. package/dist/transport/impls/ws/server.d.cts +6 -6
  44. package/dist/transport/impls/ws/server.d.ts +6 -6
  45. package/dist/transport/impls/ws/server.js +2 -2
  46. package/dist/transport/index.cjs +177 -53
  47. package/dist/transport/index.cjs.map +1 -1
  48. package/dist/transport/index.d.cts +7 -7
  49. package/dist/transport/index.d.ts +7 -7
  50. package/dist/transport/index.js +2 -2
  51. package/dist/{transport-CxT7y8Qk.d.cts → transport-BOL2p5s-.d.ts} +70 -64
  52. package/dist/{transport-pdbkDzmJ.d.ts → transport-D3jzhFSi.d.cts} +70 -64
  53. package/package.json +1 -1
  54. package/dist/chunk-DRYCLL6N.js.map +0 -1
  55. package/dist/chunk-LECVFB2G.js.map +0 -1
@@ -1,10 +1,10 @@
1
- export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../transport-CxT7y8Qk.cjs';
2
- export { C as ClientTransport } from '../client-DXJRow2s.cjs';
3
- export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-BDSYa-CO.cjs';
4
- export { W as WebSocketCloseError, a as WebSocketConnection } from '../connection-Dzkqj18h.cjs';
5
- export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-Dlsh5WDF.cjs';
1
+ export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../transport-D3jzhFSi.cjs';
2
+ export { C as ClientTransport } from '../client-Dk4H7qeg.cjs';
3
+ export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-BR0DZaWi.cjs';
4
+ export { W as WebSocketCloseError, a as WebSocketConnection } from '../connection-CS00EWuS.cjs';
5
+ export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-aABg0s5M.cjs';
6
6
  import '@sinclair/typebox';
7
- import '../index-D9R6UTMl.cjs';
8
- import '../adapter-DjiEwOYi.cjs';
7
+ import '../index-CHCzvZ9D.cjs';
8
+ import '../adapter-IGrG4KLL.cjs';
9
9
  import '@opentelemetry/api';
10
10
  import '../wslike-Dng9H1C7.cjs';
@@ -1,10 +1,10 @@
1
- export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../transport-pdbkDzmJ.js';
2
- export { C as ClientTransport } from '../client-Dw0JBBs3.js';
3
- export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-DFOzjvLh.js';
4
- export { W as WebSocketCloseError, a as WebSocketConnection } from '../connection-C2lYgRh0.js';
5
- export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-Dlsh5WDF.js';
1
+ export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../transport-BOL2p5s-.js';
2
+ export { C as ClientTransport } from '../client-BhwlY0-L.js';
3
+ export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-uNzkzIRh.js';
4
+ export { W as WebSocketCloseError, a as WebSocketConnection } from '../connection-DU9v3y8a.js';
5
+ export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-aABg0s5M.js';
6
6
  import '@sinclair/typebox';
7
- import '../index-CSM8soK7.js';
8
- import '../adapter-Cp7_gIVA.js';
7
+ import '../index-uF0cBM7z.js';
8
+ import '../adapter-CgF7vQPu.js';
9
9
  import '@opentelemetry/api';
10
10
  import '../wslike-Dng9H1C7.js';
@@ -7,12 +7,12 @@ import {
7
7
  Transport,
8
8
  WebSocketCloseError,
9
9
  WebSocketConnection
10
- } from "../chunk-DRYCLL6N.js";
10
+ } from "../chunk-VXRAFUA3.js";
11
11
  import "../chunk-CC7RN7GI.js";
12
12
  import {
13
13
  OpaqueTransportMessageSchema,
14
14
  TransportMessageSchema
15
- } from "../chunk-LECVFB2G.js";
15
+ } from "../chunk-RDTQZ7HO.js";
16
16
  export {
17
17
  ClientTransport,
18
18
  Connection,
@@ -1,64 +1,9 @@
1
1
  import { TSchema, Static } from '@sinclair/typebox';
2
- import { f as TelemetryInfo, c as TransportClientId, P as ProtocolVersion, b as OpaqueTransportMessage, e as PartialTransportMessage, a as TransportMessage, g as HandshakeErrorCustomHandlerFatalResponseCodes, H as HandshakeErrorResponseCodes } from './message-Dlsh5WDF.cjs';
3
- import { M as MessageMetadata, L as Logger, T as Tags, a as LogFn, b as LoggingLevel } from './index-D9R6UTMl.cjs';
4
- import { C as Codec, a as CodecMessageAdapter, S as SendResult, b as SendBufferResult } from './adapter-DjiEwOYi.cjs';
2
+ import { c as TransportClientId, f as TelemetryInfo, P as ProtocolVersion, e as PartialTransportMessage, E as EncodedTransportMessage, g as HandshakeErrorCustomHandlerFatalResponseCodes, b as OpaqueTransportMessage, H as HandshakeErrorResponseCodes, a as TransportMessage } from './message-aABg0s5M.js';
3
+ import { L as Logger, M as MessageMetadata, T as Tags, a as LogFn, b as LoggingLevel } from './index-uF0cBM7z.js';
4
+ import { C as Codec, a as CodecMessageAdapter, E as EncodeResult, S as SendResult, b as SendBufferResult } from './adapter-CgF7vQPu.js';
5
5
  import { Tracer } from '@opentelemetry/api';
6
6
 
7
- /**
8
- * A connection is the actual raw underlying transport connection.
9
- * It's responsible for dispatching to/from the actual connection itself
10
- * This should be instantiated as soon as the client/server has a connection
11
- * It's tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
12
- */
13
- declare abstract class Connection {
14
- id: string;
15
- telemetry?: TelemetryInfo;
16
- constructor();
17
- get loggingMetadata(): MessageMetadata;
18
- dataListener?: (msg: Uint8Array) => void;
19
- closeListener?: () => void;
20
- errorListener?: (err: Error) => void;
21
- onData(msg: Uint8Array): void;
22
- onError(err: Error): void;
23
- onClose(): void;
24
- /**
25
- * Set the callback for when a message is received.
26
- * @param cb The message handler callback.
27
- */
28
- setDataListener(cb: (msg: Uint8Array) => void): void;
29
- removeDataListener(): void;
30
- /**
31
- * Set the callback for when the connection is closed.
32
- * This should also be called if an error happens and after notifying the error listener.
33
- * @param cb The callback to call when the connection is closed.
34
- */
35
- setCloseListener(cb: () => void): void;
36
- removeCloseListener(): void;
37
- /**
38
- * Set the callback for when an error is received.
39
- * This should only be used for logging errors, all cleanup
40
- * should be delegated to setCloseListener.
41
- *
42
- * The implementer should take care such that the implemented
43
- * connection will call both the close and error callbacks
44
- * on an error.
45
- *
46
- * @param cb The callback to call when an error is received.
47
- */
48
- setErrorListener(cb: (err: Error) => void): void;
49
- removeErrorListener(): void;
50
- /**
51
- * Sends a message over the connection.
52
- * @param msg The message to send.
53
- * @returns true if the message was sent, false otherwise.
54
- */
55
- abstract send(msg: Uint8Array): boolean;
56
- /**
57
- * Closes the connection.
58
- */
59
- abstract close(): void;
60
- }
61
-
62
7
  declare const enum SessionState {
63
8
  NoConnection = "NoConnection",
64
9
  BackingOff = "BackingOff",
@@ -135,21 +80,28 @@ declare abstract class CommonSession extends StateMachineState {
135
80
  constructor({ from, options, log, tracer, codec }: CommonSessionProps);
136
81
  }
137
82
  type SessionId = string;
83
+ interface IdentifiedSessionListeners {
84
+ onMessageSendFailure: (msg: PartialTransportMessage & {
85
+ seq: number;
86
+ }, reason: string) => void;
87
+ }
138
88
  interface IdentifiedSessionProps extends CommonSessionProps {
139
89
  id: SessionId;
140
90
  to: TransportClientId;
141
91
  seq: number;
142
92
  ack: number;
143
93
  seqSent: number;
144
- sendBuffer: Array<OpaqueTransportMessage>;
94
+ sendBuffer: Array<EncodedTransportMessage>;
145
95
  telemetry: TelemetryInfo;
146
96
  protocolVersion: ProtocolVersion;
97
+ listeners: IdentifiedSessionListeners;
147
98
  }
148
99
  declare abstract class IdentifiedSession extends CommonSession {
149
100
  readonly id: SessionId;
150
101
  readonly telemetry: TelemetryInfo;
151
102
  readonly to: TransportClientId;
152
103
  readonly protocolVersion: ProtocolVersion;
104
+ listeners: IdentifiedSessionListeners;
153
105
  /**
154
106
  * Index of the message we will send next (excluding handshake)
155
107
  */
@@ -162,16 +114,16 @@ declare abstract class IdentifiedSession extends CommonSession {
162
114
  * Number of unique messages we've received this session (excluding handshake)
163
115
  */
164
116
  ack: number;
165
- sendBuffer: Array<OpaqueTransportMessage>;
117
+ sendBuffer: Array<EncodedTransportMessage>;
166
118
  constructor(props: IdentifiedSessionProps);
167
119
  get loggingMetadata(): MessageMetadata;
168
- constructMsg<Payload>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
120
+ encodeMsg(partialMsg: PartialTransportMessage): EncodeResult;
169
121
  nextSeq(): number;
170
122
  send(msg: PartialTransportMessage): SendResult;
171
123
  _handleStateExit(): void;
172
124
  _handleClose(): void;
173
125
  }
174
- interface IdentifiedSessionWithGracePeriodListeners {
126
+ interface IdentifiedSessionWithGracePeriodListeners extends IdentifiedSessionListeners {
175
127
  onSessionGracePeriodElapsed: () => void;
176
128
  }
177
129
  interface IdentifiedSessionWithGracePeriodProps extends IdentifiedSessionProps {
@@ -187,6 +139,61 @@ declare abstract class IdentifiedSessionWithGracePeriod extends IdentifiedSessio
187
139
  _handleClose(): void;
188
140
  }
189
141
 
142
+ /**
143
+ * A connection is the actual raw underlying transport connection.
144
+ * It's responsible for dispatching to/from the actual connection itself
145
+ * This should be instantiated as soon as the client/server has a connection
146
+ * It's tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
147
+ */
148
+ declare abstract class Connection {
149
+ id: string;
150
+ telemetry?: TelemetryInfo;
151
+ constructor();
152
+ get loggingMetadata(): MessageMetadata;
153
+ dataListener?: (msg: Uint8Array) => void;
154
+ closeListener?: () => void;
155
+ errorListener?: (err: Error) => void;
156
+ onData(msg: Uint8Array): void;
157
+ onError(err: Error): void;
158
+ onClose(): void;
159
+ /**
160
+ * Set the callback for when a message is received.
161
+ * @param cb The message handler callback.
162
+ */
163
+ setDataListener(cb: (msg: Uint8Array) => void): void;
164
+ removeDataListener(): void;
165
+ /**
166
+ * Set the callback for when the connection is closed.
167
+ * This should also be called if an error happens and after notifying the error listener.
168
+ * @param cb The callback to call when the connection is closed.
169
+ */
170
+ setCloseListener(cb: () => void): void;
171
+ removeCloseListener(): void;
172
+ /**
173
+ * Set the callback for when an error is received.
174
+ * This should only be used for logging errors, all cleanup
175
+ * should be delegated to setCloseListener.
176
+ *
177
+ * The implementer should take care such that the implemented
178
+ * connection will call both the close and error callbacks
179
+ * on an error.
180
+ *
181
+ * @param cb The callback to call when an error is received.
182
+ */
183
+ setErrorListener(cb: (err: Error) => void): void;
184
+ removeErrorListener(): void;
185
+ /**
186
+ * Sends a message over the connection.
187
+ * @param msg The message to send.
188
+ * @returns true if the message was sent, false otherwise.
189
+ */
190
+ abstract send(msg: Uint8Array): boolean;
191
+ /**
192
+ * Closes the connection.
193
+ */
194
+ abstract close(): void;
195
+ }
196
+
190
197
  type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
191
198
  type ValidateHandshake<T extends TSchema, ParsedMetadata> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata | Promise<Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata>;
192
199
  interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
@@ -347,11 +354,10 @@ declare class SessionHandshaking<ConnType extends Connection> extends Identified
347
354
  _handleClose(): void;
348
355
  }
349
356
 
350
- interface SessionConnectedListeners {
357
+ interface SessionConnectedListeners extends IdentifiedSessionListeners {
351
358
  onConnectionErrored: (err: unknown) => void;
352
359
  onConnectionClosed: () => void;
353
360
  onMessage: (msg: OpaqueTransportMessage) => void;
354
- onMessageSendFailure: (msg: PartialTransportMessage, reason: string) => void;
355
361
  onInvalidMessage: (reason: string) => void;
356
362
  }
357
363
  interface SessionConnectedProps<ConnType extends Connection> extends IdentifiedSessionProps {
@@ -1,64 +1,9 @@
1
1
  import { TSchema, Static } from '@sinclair/typebox';
2
- import { f as TelemetryInfo, c as TransportClientId, P as ProtocolVersion, b as OpaqueTransportMessage, e as PartialTransportMessage, a as TransportMessage, g as HandshakeErrorCustomHandlerFatalResponseCodes, H as HandshakeErrorResponseCodes } from './message-Dlsh5WDF.js';
3
- import { M as MessageMetadata, L as Logger, T as Tags, a as LogFn, b as LoggingLevel } from './index-CSM8soK7.js';
4
- import { C as Codec, a as CodecMessageAdapter, S as SendResult, b as SendBufferResult } from './adapter-Cp7_gIVA.js';
2
+ import { c as TransportClientId, f as TelemetryInfo, P as ProtocolVersion, e as PartialTransportMessage, E as EncodedTransportMessage, g as HandshakeErrorCustomHandlerFatalResponseCodes, b as OpaqueTransportMessage, H as HandshakeErrorResponseCodes, a as TransportMessage } from './message-aABg0s5M.cjs';
3
+ import { L as Logger, M as MessageMetadata, T as Tags, a as LogFn, b as LoggingLevel } from './index-CHCzvZ9D.cjs';
4
+ import { C as Codec, a as CodecMessageAdapter, E as EncodeResult, S as SendResult, b as SendBufferResult } from './adapter-IGrG4KLL.cjs';
5
5
  import { Tracer } from '@opentelemetry/api';
6
6
 
7
- /**
8
- * A connection is the actual raw underlying transport connection.
9
- * It's responsible for dispatching to/from the actual connection itself
10
- * This should be instantiated as soon as the client/server has a connection
11
- * It's tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
12
- */
13
- declare abstract class Connection {
14
- id: string;
15
- telemetry?: TelemetryInfo;
16
- constructor();
17
- get loggingMetadata(): MessageMetadata;
18
- dataListener?: (msg: Uint8Array) => void;
19
- closeListener?: () => void;
20
- errorListener?: (err: Error) => void;
21
- onData(msg: Uint8Array): void;
22
- onError(err: Error): void;
23
- onClose(): void;
24
- /**
25
- * Set the callback for when a message is received.
26
- * @param cb The message handler callback.
27
- */
28
- setDataListener(cb: (msg: Uint8Array) => void): void;
29
- removeDataListener(): void;
30
- /**
31
- * Set the callback for when the connection is closed.
32
- * This should also be called if an error happens and after notifying the error listener.
33
- * @param cb The callback to call when the connection is closed.
34
- */
35
- setCloseListener(cb: () => void): void;
36
- removeCloseListener(): void;
37
- /**
38
- * Set the callback for when an error is received.
39
- * This should only be used for logging errors, all cleanup
40
- * should be delegated to setCloseListener.
41
- *
42
- * The implementer should take care such that the implemented
43
- * connection will call both the close and error callbacks
44
- * on an error.
45
- *
46
- * @param cb The callback to call when an error is received.
47
- */
48
- setErrorListener(cb: (err: Error) => void): void;
49
- removeErrorListener(): void;
50
- /**
51
- * Sends a message over the connection.
52
- * @param msg The message to send.
53
- * @returns true if the message was sent, false otherwise.
54
- */
55
- abstract send(msg: Uint8Array): boolean;
56
- /**
57
- * Closes the connection.
58
- */
59
- abstract close(): void;
60
- }
61
-
62
7
  declare const enum SessionState {
63
8
  NoConnection = "NoConnection",
64
9
  BackingOff = "BackingOff",
@@ -135,21 +80,28 @@ declare abstract class CommonSession extends StateMachineState {
135
80
  constructor({ from, options, log, tracer, codec }: CommonSessionProps);
136
81
  }
137
82
  type SessionId = string;
83
+ interface IdentifiedSessionListeners {
84
+ onMessageSendFailure: (msg: PartialTransportMessage & {
85
+ seq: number;
86
+ }, reason: string) => void;
87
+ }
138
88
  interface IdentifiedSessionProps extends CommonSessionProps {
139
89
  id: SessionId;
140
90
  to: TransportClientId;
141
91
  seq: number;
142
92
  ack: number;
143
93
  seqSent: number;
144
- sendBuffer: Array<OpaqueTransportMessage>;
94
+ sendBuffer: Array<EncodedTransportMessage>;
145
95
  telemetry: TelemetryInfo;
146
96
  protocolVersion: ProtocolVersion;
97
+ listeners: IdentifiedSessionListeners;
147
98
  }
148
99
  declare abstract class IdentifiedSession extends CommonSession {
149
100
  readonly id: SessionId;
150
101
  readonly telemetry: TelemetryInfo;
151
102
  readonly to: TransportClientId;
152
103
  readonly protocolVersion: ProtocolVersion;
104
+ listeners: IdentifiedSessionListeners;
153
105
  /**
154
106
  * Index of the message we will send next (excluding handshake)
155
107
  */
@@ -162,16 +114,16 @@ declare abstract class IdentifiedSession extends CommonSession {
162
114
  * Number of unique messages we've received this session (excluding handshake)
163
115
  */
164
116
  ack: number;
165
- sendBuffer: Array<OpaqueTransportMessage>;
117
+ sendBuffer: Array<EncodedTransportMessage>;
166
118
  constructor(props: IdentifiedSessionProps);
167
119
  get loggingMetadata(): MessageMetadata;
168
- constructMsg<Payload>(partialMsg: PartialTransportMessage<Payload>): TransportMessage<Payload>;
120
+ encodeMsg(partialMsg: PartialTransportMessage): EncodeResult;
169
121
  nextSeq(): number;
170
122
  send(msg: PartialTransportMessage): SendResult;
171
123
  _handleStateExit(): void;
172
124
  _handleClose(): void;
173
125
  }
174
- interface IdentifiedSessionWithGracePeriodListeners {
126
+ interface IdentifiedSessionWithGracePeriodListeners extends IdentifiedSessionListeners {
175
127
  onSessionGracePeriodElapsed: () => void;
176
128
  }
177
129
  interface IdentifiedSessionWithGracePeriodProps extends IdentifiedSessionProps {
@@ -187,6 +139,61 @@ declare abstract class IdentifiedSessionWithGracePeriod extends IdentifiedSessio
187
139
  _handleClose(): void;
188
140
  }
189
141
 
142
+ /**
143
+ * A connection is the actual raw underlying transport connection.
144
+ * It's responsible for dispatching to/from the actual connection itself
145
+ * This should be instantiated as soon as the client/server has a connection
146
+ * It's tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
147
+ */
148
+ declare abstract class Connection {
149
+ id: string;
150
+ telemetry?: TelemetryInfo;
151
+ constructor();
152
+ get loggingMetadata(): MessageMetadata;
153
+ dataListener?: (msg: Uint8Array) => void;
154
+ closeListener?: () => void;
155
+ errorListener?: (err: Error) => void;
156
+ onData(msg: Uint8Array): void;
157
+ onError(err: Error): void;
158
+ onClose(): void;
159
+ /**
160
+ * Set the callback for when a message is received.
161
+ * @param cb The message handler callback.
162
+ */
163
+ setDataListener(cb: (msg: Uint8Array) => void): void;
164
+ removeDataListener(): void;
165
+ /**
166
+ * Set the callback for when the connection is closed.
167
+ * This should also be called if an error happens and after notifying the error listener.
168
+ * @param cb The callback to call when the connection is closed.
169
+ */
170
+ setCloseListener(cb: () => void): void;
171
+ removeCloseListener(): void;
172
+ /**
173
+ * Set the callback for when an error is received.
174
+ * This should only be used for logging errors, all cleanup
175
+ * should be delegated to setCloseListener.
176
+ *
177
+ * The implementer should take care such that the implemented
178
+ * connection will call both the close and error callbacks
179
+ * on an error.
180
+ *
181
+ * @param cb The callback to call when an error is received.
182
+ */
183
+ setErrorListener(cb: (err: Error) => void): void;
184
+ removeErrorListener(): void;
185
+ /**
186
+ * Sends a message over the connection.
187
+ * @param msg The message to send.
188
+ * @returns true if the message was sent, false otherwise.
189
+ */
190
+ abstract send(msg: Uint8Array): boolean;
191
+ /**
192
+ * Closes the connection.
193
+ */
194
+ abstract close(): void;
195
+ }
196
+
190
197
  type ConstructHandshake<T extends TSchema> = () => Static<T> | Promise<Static<T>>;
191
198
  type ValidateHandshake<T extends TSchema, ParsedMetadata> = (metadata: Static<T>, previousParsedMetadata?: ParsedMetadata) => Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata | Promise<Static<typeof HandshakeErrorCustomHandlerFatalResponseCodes> | ParsedMetadata>;
192
199
  interface ClientHandshakeOptions<MetadataSchema extends TSchema = TSchema> {
@@ -347,11 +354,10 @@ declare class SessionHandshaking<ConnType extends Connection> extends Identified
347
354
  _handleClose(): void;
348
355
  }
349
356
 
350
- interface SessionConnectedListeners {
357
+ interface SessionConnectedListeners extends IdentifiedSessionListeners {
351
358
  onConnectionErrored: (err: unknown) => void;
352
359
  onConnectionClosed: () => void;
353
360
  onMessage: (msg: OpaqueTransportMessage) => void;
354
- onMessageSendFailure: (msg: PartialTransportMessage, reason: string) => void;
355
361
  onInvalidMessage: (reason: string) => void;
356
362
  }
357
363
  interface SessionConnectedProps<ConnType extends Connection> extends IdentifiedSessionProps {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@replit/river",
3
3
  "description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4
- "version": "0.214.0",
4
+ "version": "0.215.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {