@replit/river 0.207.3 → 0.208.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.
Files changed (40) hide show
  1. package/dist/{chunk-BO7MFCO6.js → chunk-2WFRHXDZ.js} +47 -84
  2. package/dist/chunk-2WFRHXDZ.js.map +1 -0
  3. package/dist/{chunk-B7REV3ZV.js → chunk-BXKBENJE.js} +2 -2
  4. package/dist/{chunk-QGPYCXV4.js → chunk-EVAQ2QMB.js} +61 -38
  5. package/dist/chunk-EVAQ2QMB.js.map +1 -0
  6. package/dist/codec/index.cjs +1 -1
  7. package/dist/codec/index.cjs.map +1 -1
  8. package/dist/codec/index.js +2 -2
  9. package/dist/{connection-06d72f2e.d.ts → connection-098d4aad.d.ts} +1 -1
  10. package/dist/router/index.cjs +58 -35
  11. package/dist/router/index.cjs.map +1 -1
  12. package/dist/router/index.d.cts +24 -5
  13. package/dist/router/index.d.ts +24 -5
  14. package/dist/router/index.js +1 -1
  15. package/dist/{services-87887bc5.d.ts → services-44be1b6b.d.ts} +22 -25
  16. package/dist/testUtil/index.cjs +51 -94
  17. package/dist/testUtil/index.cjs.map +1 -1
  18. package/dist/testUtil/index.d.cts +1 -1
  19. package/dist/testUtil/index.d.ts +1 -1
  20. package/dist/testUtil/index.js +5 -11
  21. package/dist/testUtil/index.js.map +1 -1
  22. package/dist/transport/impls/ws/client.cjs +48 -73
  23. package/dist/transport/impls/ws/client.cjs.map +1 -1
  24. package/dist/transport/impls/ws/client.d.cts +2 -2
  25. package/dist/transport/impls/ws/client.d.ts +2 -2
  26. package/dist/transport/impls/ws/client.js +3 -3
  27. package/dist/transport/impls/ws/server.cjs +48 -76
  28. package/dist/transport/impls/ws/server.cjs.map +1 -1
  29. package/dist/transport/impls/ws/server.d.cts +2 -2
  30. package/dist/transport/impls/ws/server.d.ts +2 -2
  31. package/dist/transport/impls/ws/server.js +3 -3
  32. package/dist/transport/index.cjs +48 -85
  33. package/dist/transport/index.cjs.map +1 -1
  34. package/dist/transport/index.d.cts +2 -2
  35. package/dist/transport/index.d.ts +2 -2
  36. package/dist/transport/index.js +2 -2
  37. package/package.json +3 -3
  38. package/dist/chunk-BO7MFCO6.js.map +0 -1
  39. package/dist/chunk-QGPYCXV4.js.map +0 -1
  40. /package/dist/{chunk-B7REV3ZV.js.map → chunk-BXKBENJE.js.map} +0 -0
@@ -1,8 +1,8 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, c as ParsedMetadata, d as AnyProcedure, b as Connection, S as ServerHandshakeOptions, e as ServiceContext } from '../services-87887bc5.js';
2
- export { M as BaseErrorSchemaType, K as CANCEL_CODE, O as Client, X as Err, Z as ErrResult, J as INVALID_REQUEST_CODE, T as Ok, _ as OkResult, w as PayloadType, l as ProcErrors, h as ProcHandler, i as ProcInit, j as ProcRequest, k as ProcResponse, m as ProcType, D as Procedure, E as ProcedureErrorSchemaType, Q as ProcedureHandlerContext, x as ProcedureMap, R as RPCProcedure, B as Readable, L as ReaderErrorSchema, a1 as ResponseData, Y as Result, a0 as ResultUnwrapErr, $ as ResultUnwrapOk, q as SerializedProcedureSchema, v as SerializedProcedureSchemaProtocolv1, o as SerializedServerSchema, t as SerializedServerSchemaProtocolv1, p as SerializedServiceSchema, u as SerializedServiceSchemaProtocolv1, f as Service, g as ServiceConfiguration, n as ServiceSchema, z as StreamProcedure, y as SubscriptionProcedure, G as UNCAUGHT_ERROR_CODE, H as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, N as createClient, a2 as createClientHandshakeOptions, a3 as createServerHandshakeOptions, F as flattenErrorType, s as serializeSchema, r as serializeSchemaV1Compat } from '../services-87887bc5.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, c as ParsedMetadata, d as AnyProcedure, e as ProcedureHandlerContext, f as PayloadType, b as Connection, S as ServerHandshakeOptions, g as ServiceContext } from '../services-44be1b6b.js';
2
+ export { N as BaseErrorSchemaType, L as CANCEL_CODE, Q as Client, X as Err, Z as ErrResult, K as INVALID_REQUEST_CODE, T as Ok, _ as OkResult, n as ProcErrors, j as ProcHandler, k as ProcInit, l as ProcRequest, m as ProcResponse, o as ProcType, E as Procedure, F as ProcedureErrorSchemaType, y as ProcedureMap, R as RPCProcedure, D as Readable, M as ReaderErrorSchema, a1 as ResponseData, Y as Result, a0 as ResultUnwrapErr, $ as ResultUnwrapOk, t as SerializedProcedureSchema, x as SerializedProcedureSchemaProtocolv1, q as SerializedServerSchema, v as SerializedServerSchemaProtocolv1, r as SerializedServiceSchema, w as SerializedServiceSchemaProtocolv1, h as Service, i as ServiceConfiguration, p as ServiceSchema, B as StreamProcedure, z as SubscriptionProcedure, H as UNCAUGHT_ERROR_CODE, J as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, O as createClient, a2 as createClientHandshakeOptions, a3 as createServerHandshakeOptions, G as flattenErrorType, s as serializeSchema, u as serializeSchemaV1Compat } from '../services-44be1b6b.js';
3
+ import { Static } from '@sinclair/typebox';
3
4
  import { T as TransportClientId, O as OpaqueTransportMessage } from '../message-01c3e85a.js';
4
5
  import { ServerTransport } from '../transport/index.cjs';
5
- import '@sinclair/typebox';
6
6
  import '@opentelemetry/api';
7
7
  import '../index-02554794.js';
8
8
  import '../adapter-f2b6e211.js';
@@ -33,6 +33,21 @@ interface ProcStream {
33
33
  handleMsg: (msg: OpaqueTransportMessage) => void;
34
34
  handleSessionDisconnect: () => void;
35
35
  }
36
+ interface MiddlewareContext extends Readonly<Omit<ProcedureHandlerContext<unknown>, 'cancel'>> {
37
+ readonly streamId: StreamId;
38
+ readonly procedureName: string;
39
+ readonly serviceName: string;
40
+ }
41
+ interface MiddlewareParam {
42
+ readonly ctx: MiddlewareContext;
43
+ readonly reqInit: Static<PayloadType>;
44
+ next: () => void;
45
+ }
46
+ /**
47
+ * Middleware is a function that can inspect requests as they are received.
48
+ * For now modification of the request is not supported behavior.
49
+ */
50
+ type Middleware = (param: MiddlewareParam) => void;
36
51
  /**
37
52
  * Creates a server instance that listens for incoming messages from a transport and routes them to the appropriate service and procedure.
38
53
  * The server tracks the state of each service along with open streams and the extended context object.
@@ -50,8 +65,12 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
50
65
  * cascading stream errors.
51
66
  */
52
67
  maxCancelledStreamTombstonesPerSession?: number;
68
+ /**
69
+ * Middlewares run before procedure handlers allowing you to inspect requests and responses..
70
+ */
71
+ middlewares?: Array<Middleware>;
53
72
  }>): Server<Services>;
54
73
 
55
- var version = "0.207.3";
74
+ var version = "0.208.1";
56
75
 
57
- export { ParsedMetadata, version as RIVER_VERSION, Server, ServiceContext, createServer };
76
+ export { Middleware, MiddlewareContext, MiddlewareParam, ParsedMetadata, PayloadType, ProcedureHandlerContext, version as RIVER_VERSION, Server, ServiceContext, createServer };
@@ -1,8 +1,8 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, c as ParsedMetadata, d as AnyProcedure, b as Connection, S as ServerHandshakeOptions, e as ServiceContext } from '../services-87887bc5.js';
2
- export { M as BaseErrorSchemaType, K as CANCEL_CODE, O as Client, X as Err, Z as ErrResult, J as INVALID_REQUEST_CODE, T as Ok, _ as OkResult, w as PayloadType, l as ProcErrors, h as ProcHandler, i as ProcInit, j as ProcRequest, k as ProcResponse, m as ProcType, D as Procedure, E as ProcedureErrorSchemaType, Q as ProcedureHandlerContext, x as ProcedureMap, R as RPCProcedure, B as Readable, L as ReaderErrorSchema, a1 as ResponseData, Y as Result, a0 as ResultUnwrapErr, $ as ResultUnwrapOk, q as SerializedProcedureSchema, v as SerializedProcedureSchemaProtocolv1, o as SerializedServerSchema, t as SerializedServerSchemaProtocolv1, p as SerializedServiceSchema, u as SerializedServiceSchemaProtocolv1, f as Service, g as ServiceConfiguration, n as ServiceSchema, z as StreamProcedure, y as SubscriptionProcedure, G as UNCAUGHT_ERROR_CODE, H as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, N as createClient, a2 as createClientHandshakeOptions, a3 as createServerHandshakeOptions, F as flattenErrorType, s as serializeSchema, r as serializeSchemaV1Compat } from '../services-87887bc5.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, c as ParsedMetadata, d as AnyProcedure, e as ProcedureHandlerContext, f as PayloadType, b as Connection, S as ServerHandshakeOptions, g as ServiceContext } from '../services-44be1b6b.js';
2
+ export { N as BaseErrorSchemaType, L as CANCEL_CODE, Q as Client, X as Err, Z as ErrResult, K as INVALID_REQUEST_CODE, T as Ok, _ as OkResult, n as ProcErrors, j as ProcHandler, k as ProcInit, l as ProcRequest, m as ProcResponse, o as ProcType, E as Procedure, F as ProcedureErrorSchemaType, y as ProcedureMap, R as RPCProcedure, D as Readable, M as ReaderErrorSchema, a1 as ResponseData, Y as Result, a0 as ResultUnwrapErr, $ as ResultUnwrapOk, t as SerializedProcedureSchema, x as SerializedProcedureSchemaProtocolv1, q as SerializedServerSchema, v as SerializedServerSchemaProtocolv1, r as SerializedServiceSchema, w as SerializedServiceSchemaProtocolv1, h as Service, i as ServiceConfiguration, p as ServiceSchema, B as StreamProcedure, z as SubscriptionProcedure, H as UNCAUGHT_ERROR_CODE, J as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, O as createClient, a2 as createClientHandshakeOptions, a3 as createServerHandshakeOptions, G as flattenErrorType, s as serializeSchema, u as serializeSchemaV1Compat } from '../services-44be1b6b.js';
3
+ import { Static } from '@sinclair/typebox';
3
4
  import { T as TransportClientId, O as OpaqueTransportMessage } from '../message-01c3e85a.js';
4
5
  import { ServerTransport } from '../transport/index.js';
5
- import '@sinclair/typebox';
6
6
  import '@opentelemetry/api';
7
7
  import '../index-02554794.js';
8
8
  import '../adapter-f2b6e211.js';
@@ -33,6 +33,21 @@ interface ProcStream {
33
33
  handleMsg: (msg: OpaqueTransportMessage) => void;
34
34
  handleSessionDisconnect: () => void;
35
35
  }
36
+ interface MiddlewareContext extends Readonly<Omit<ProcedureHandlerContext<unknown>, 'cancel'>> {
37
+ readonly streamId: StreamId;
38
+ readonly procedureName: string;
39
+ readonly serviceName: string;
40
+ }
41
+ interface MiddlewareParam {
42
+ readonly ctx: MiddlewareContext;
43
+ readonly reqInit: Static<PayloadType>;
44
+ next: () => void;
45
+ }
46
+ /**
47
+ * Middleware is a function that can inspect requests as they are received.
48
+ * For now modification of the request is not supported behavior.
49
+ */
50
+ type Middleware = (param: MiddlewareParam) => void;
36
51
  /**
37
52
  * Creates a server instance that listens for incoming messages from a transport and routes them to the appropriate service and procedure.
38
53
  * The server tracks the state of each service along with open streams and the extended context object.
@@ -50,8 +65,12 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
50
65
  * cascading stream errors.
51
66
  */
52
67
  maxCancelledStreamTombstonesPerSession?: number;
68
+ /**
69
+ * Middlewares run before procedure handlers allowing you to inspect requests and responses..
70
+ */
71
+ middlewares?: Array<Middleware>;
53
72
  }>): Server<Services>;
54
73
 
55
- var version = "0.207.3";
74
+ var version = "0.208.1";
56
75
 
57
- export { ParsedMetadata, version as RIVER_VERSION, Server, ServiceContext, createServer };
76
+ export { Middleware, MiddlewareContext, MiddlewareParam, ParsedMetadata, PayloadType, ProcedureHandlerContext, version as RIVER_VERSION, Server, ServiceContext, createServer };
@@ -16,7 +16,7 @@ import {
16
16
  serializeSchema,
17
17
  serializeSchemaV1Compat,
18
18
  version
19
- } from "../chunk-QGPYCXV4.js";
19
+ } from "../chunk-EVAQ2QMB.js";
20
20
  export {
21
21
  CANCEL_CODE,
22
22
  Err,
@@ -7,41 +7,38 @@ import { C as Codec, a as CodecMessageAdapter, S as SendResult, b as SendBufferR
7
7
 
8
8
  /**
9
9
  * A connection is the actual raw underlying transport connection.
10
- * Its responsible for dispatching to/from the actual connection itself
10
+ * It's responsible for dispatching to/from the actual connection itself
11
11
  * This should be instantiated as soon as the client/server has a connection
12
- * Its tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
12
+ * It's tied to the lifecycle of the underlying transport connection (i.e. if the WS drops, this connection should be deleted)
13
13
  */
14
14
  declare abstract class Connection {
15
15
  id: string;
16
16
  telemetry?: TelemetryInfo;
17
17
  constructor();
18
18
  get loggingMetadata(): MessageMetadata;
19
- private _dataListeners;
20
- private _closeListeners;
21
- private _errorListeners;
22
- get dataListeners(): ((msg: Uint8Array) => void)[];
23
- get closeListeners(): (() => void)[];
24
- get errorListeners(): ((err: Error) => void)[];
19
+ dataListener?: (msg: Uint8Array) => void;
20
+ closeListener?: () => void;
21
+ errorListener?: (err: Error) => void;
25
22
  onData(msg: Uint8Array): void;
26
23
  onError(err: Error): void;
27
24
  onClose(): void;
28
25
  /**
29
- * Handle adding a callback for when a message is received.
30
- * @param msg The message that was received.
26
+ * Set the callback for when a message is received.
27
+ * @param cb The message handler callback.
31
28
  */
32
- addDataListener(cb: (msg: Uint8Array) => void): void;
33
- removeDataListener(cb: (msg: Uint8Array) => void): void;
29
+ setDataListener(cb: (msg: Uint8Array) => void): void;
30
+ removeDataListener(): void;
34
31
  /**
35
- * Handle adding a callback for when the connection is closed.
36
- * This should also be called if an error happens and after notifying all the error listeners.
32
+ * Set the callback for when the connection is closed.
33
+ * This should also be called if an error happens and after notifying the error listener.
37
34
  * @param cb The callback to call when the connection is closed.
38
35
  */
39
- addCloseListener(cb: () => void): void;
40
- removeCloseListener(cb: () => void): void;
36
+ setCloseListener(cb: () => void): void;
37
+ removeCloseListener(): void;
41
38
  /**
42
- * Handle adding a callback for when an error is received.
43
- * This should only be used for this.logging errors, all cleanup
44
- * should be delegated to addCloseListener.
39
+ * Set the callback for when an error is received.
40
+ * This should only be used for logging errors, all cleanup
41
+ * should be delegated to setCloseListener.
45
42
  *
46
43
  * The implementer should take care such that the implemented
47
44
  * connection will call both the close and error callbacks
@@ -49,8 +46,8 @@ declare abstract class Connection {
49
46
  *
50
47
  * @param cb The callback to call when an error is received.
51
48
  */
52
- addErrorListener(cb: (err: Error) => void): void;
53
- removeErrorListener(cb: (err: Error) => void): void;
49
+ setErrorListener(cb: (err: Error) => void): void;
50
+ removeErrorListener(): void;
54
51
  /**
55
52
  * Sends a message over the connection.
56
53
  * @param msg The message to send.
@@ -658,7 +655,7 @@ type BaseErrorSchemaType = TObject<{
658
655
  /**
659
656
  * A schema for cancel payloads sent from the client
660
657
  */
661
- declare const CancelResultSchema: TObject<{
658
+ declare const CancelErrorSchema: TObject<{
662
659
  code: TLiteral<"CANCEL">;
663
660
  message: TString;
664
661
  }>;
@@ -978,7 +975,7 @@ type ProcedureHandlerContext<State> = ServiceContext & {
978
975
  * Cancelling is not the same as closing procedure calls gracefully, please refer to
979
976
  * the river documentation to understand the difference between the two concepts.
980
977
  */
981
- cancel: (message?: string) => ErrResult<Static<typeof CancelResultSchema>>;
978
+ cancel: (message?: string) => ErrResult<Static<typeof CancelErrorSchema>>;
982
979
  /**
983
980
  * This signal is a standard [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
984
981
  * triggered when the procedure invocation is done. This signal tracks the invocation/request finishing
@@ -1022,7 +1019,7 @@ type ValidProcType = 'rpc' | 'upload' | 'subscription' | 'stream';
1022
1019
  * Represents the payload type for {@link Procedure}s.
1023
1020
  */
1024
1021
  type PayloadType = TSchema;
1025
- type Cancellable<T> = T | Static<typeof CancelResultSchema>;
1022
+ type Cancellable<T> = T | Static<typeof CancelErrorSchema>;
1026
1023
  /**
1027
1024
  * Procedure for a single message in both directions (1:1).
1028
1025
  *
@@ -1566,4 +1563,4 @@ declare class ServiceScaffold<State extends object> {
1566
1563
  }>;
1567
1564
  }
1568
1565
 
1569
- export { ResultUnwrapOk as $, AnyServiceSchemaMap as A, Readable as B, ClientTransport as C, Procedure as D, ProcedureErrorSchemaType as E, flattenErrorType as F, UNCAUGHT_ERROR_CODE as G, UNEXPECTED_DISCONNECT_CODE as H, InstantiatedServiceSchemaMap as I, INVALID_REQUEST_CODE as J, CANCEL_CODE as K, ReaderErrorSchema as L, BaseErrorSchemaType as M, createClient as N, Client as O, ProvidedClientTransportOptions as P, ProcedureHandlerContext as Q, RpcProcedure as R, ServerHandshakeOptions as S, Ok as T, UploadProcedure as U, ValidProcType as V, Writable as W, Err as X, Result as Y, ErrResult as Z, OkResult as _, ProvidedServerTransportOptions as a, ResultUnwrapErr as a0, ResponseData as a1, createClientHandshakeOptions as a2, createServerHandshakeOptions as a3, ClientHandshakeOptions as a4, ReadableIterator as a5, ReadableResult as a6, Transport as a7, SessionOptions as a8, ClientTransportOptions as a9, SessionNoConnection as aa, SessionBoundSendFn as ab, CommonSession as ac, SessionState as ad, CommonSessionProps as ae, ServerTransportOptions as af, ServerSession as ag, DeleteSessionOptions as ah, TransportStatus as ai, ProvidedTransportOptions as aj, Session as ak, SessionConnecting as al, SessionHandshaking as am, SessionConnected as an, EventMap as ao, EventTypes as ap, EventHandler as aq, ProtocolError as ar, ProtocolErrorType as as, Connection as b, ParsedMetadata as c, AnyProcedure as d, ServiceContext as e, Service as f, ServiceConfiguration as g, ProcHandler as h, ProcInit as i, ProcRequest as j, ProcResponse as k, ProcErrors as l, ProcType as m, ServiceSchema as n, SerializedServerSchema as o, SerializedServiceSchema as p, SerializedProcedureSchema as q, serializeSchemaV1Compat as r, serializeSchema as s, SerializedServerSchemaProtocolv1 as t, SerializedServiceSchemaProtocolv1 as u, SerializedProcedureSchemaProtocolv1 as v, PayloadType as w, ProcedureMap as x, SubscriptionProcedure as y, StreamProcedure as z };
1566
+ export { ResultUnwrapOk as $, AnyServiceSchemaMap as A, StreamProcedure as B, ClientTransport as C, Readable as D, Procedure as E, ProcedureErrorSchemaType as F, flattenErrorType as G, UNCAUGHT_ERROR_CODE as H, InstantiatedServiceSchemaMap as I, UNEXPECTED_DISCONNECT_CODE as J, INVALID_REQUEST_CODE as K, CANCEL_CODE as L, ReaderErrorSchema as M, BaseErrorSchemaType as N, createClient as O, ProvidedClientTransportOptions as P, Client as Q, RpcProcedure as R, ServerHandshakeOptions as S, Ok as T, UploadProcedure as U, ValidProcType as V, Writable as W, Err as X, Result as Y, ErrResult as Z, OkResult as _, ProvidedServerTransportOptions as a, ResultUnwrapErr as a0, ResponseData as a1, createClientHandshakeOptions as a2, createServerHandshakeOptions as a3, ClientHandshakeOptions as a4, ReadableIterator as a5, ReadableResult as a6, Transport as a7, SessionOptions as a8, ClientTransportOptions as a9, SessionNoConnection as aa, SessionBoundSendFn as ab, CommonSession as ac, SessionState as ad, CommonSessionProps as ae, ServerTransportOptions as af, ServerSession as ag, DeleteSessionOptions as ah, TransportStatus as ai, ProvidedTransportOptions as aj, Session as ak, SessionConnecting as al, SessionHandshaking as am, SessionConnected as an, EventMap as ao, EventTypes as ap, EventHandler as aq, ProtocolError as ar, ProtocolErrorType as as, Connection as b, ParsedMetadata as c, AnyProcedure as d, ProcedureHandlerContext as e, PayloadType as f, ServiceContext as g, Service as h, ServiceConfiguration as i, ProcHandler as j, ProcInit as k, ProcRequest as l, ProcResponse as m, ProcErrors as n, ProcType as o, ServiceSchema as p, SerializedServerSchema as q, SerializedServiceSchema as r, serializeSchema as s, SerializedProcedureSchema as t, serializeSchemaV1Compat as u, SerializedServerSchemaProtocolv1 as v, SerializedServiceSchemaProtocolv1 as w, SerializedProcedureSchemaProtocolv1 as x, ProcedureMap as y, SubscriptionProcedure as z };
@@ -238,7 +238,7 @@ var NaiveJsonCodec = {
238
238
  const parsed = JSON.parse(
239
239
  decoder.decode(buff),
240
240
  function reviver(_key, val) {
241
- if (val?.$t) {
241
+ if (val?.$t !== void 0) {
242
242
  return base64ToUint8Array(val.$t);
243
243
  } else {
244
244
  return val;
@@ -555,7 +555,7 @@ function coerceErrorString(err) {
555
555
  }
556
556
 
557
557
  // package.json
558
- var version = "0.207.3";
558
+ var version = "0.208.1";
559
559
 
560
560
  // tracing/index.ts
561
561
  function getPropagationContext(ctx) {
@@ -569,7 +569,7 @@ function getPropagationContext(ctx) {
569
569
  function createSessionTelemetryInfo(tracer, sessionId, to, from, propagationCtx) {
570
570
  const parentCtx = propagationCtx ? import_api.propagation.extract(import_api.context.active(), propagationCtx) : import_api.context.active();
571
571
  const span = tracer.startSpan(
572
- `river.session.${sessionId}`,
572
+ `river.session`,
573
573
  {
574
574
  attributes: {
575
575
  component: "river",
@@ -585,7 +585,7 @@ function createSessionTelemetryInfo(tracer, sessionId, to, from, propagationCtx)
585
585
  }
586
586
  function createConnectionTelemetryInfo(tracer, connection, info) {
587
587
  const span = tracer.startSpan(
588
- `connection ${connection.id}`,
588
+ `river.connection`,
589
589
  {
590
590
  attributes: {
591
591
  component: "river",
@@ -615,9 +615,9 @@ var SessionWaitingForHandshake = class extends CommonSession {
615
615
  this.handshakeTimeout = setTimeout(() => {
616
616
  this.listeners.onHandshakeTimeout();
617
617
  }, this.options.handshakeTimeoutMs);
618
- this.conn.addDataListener(this.onHandshakeData);
619
- this.conn.addErrorListener(this.listeners.onConnectionErrored);
620
- this.conn.addCloseListener(this.listeners.onConnectionClosed);
618
+ this.conn.setDataListener(this.onHandshakeData);
619
+ this.conn.setErrorListener(this.listeners.onConnectionErrored);
620
+ this.conn.setCloseListener(this.listeners.onConnectionClosed);
621
621
  }
622
622
  get loggingMetadata() {
623
623
  return {
@@ -641,9 +641,9 @@ var SessionWaitingForHandshake = class extends CommonSession {
641
641
  return sendMessage(this.conn, this.codec, msg);
642
642
  }
643
643
  _handleStateExit() {
644
- this.conn.removeDataListener(this.onHandshakeData);
645
- this.conn.removeErrorListener(this.listeners.onConnectionErrored);
646
- this.conn.removeCloseListener(this.listeners.onConnectionClosed);
644
+ this.conn.removeDataListener();
645
+ this.conn.removeErrorListener();
646
+ this.conn.removeCloseListener();
647
647
  clearTimeout(this.handshakeTimeout);
648
648
  this.handshakeTimeout = void 0;
649
649
  }
@@ -665,9 +665,9 @@ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
665
665
  this.handshakeTimeout = setTimeout(() => {
666
666
  this.listeners.onHandshakeTimeout();
667
667
  }, this.options.handshakeTimeoutMs);
668
- this.conn.addDataListener(this.onHandshakeData);
669
- this.conn.addErrorListener(this.listeners.onConnectionErrored);
670
- this.conn.addCloseListener(this.listeners.onConnectionClosed);
668
+ this.conn.setDataListener(this.onHandshakeData);
669
+ this.conn.setErrorListener(this.listeners.onConnectionErrored);
670
+ this.conn.setCloseListener(this.listeners.onConnectionClosed);
671
671
  }
672
672
  get loggingMetadata() {
673
673
  return {
@@ -691,9 +691,9 @@ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
691
691
  }
692
692
  _handleStateExit() {
693
693
  super._handleStateExit();
694
- this.conn.removeDataListener(this.onHandshakeData);
695
- this.conn.removeErrorListener(this.listeners.onConnectionErrored);
696
- this.conn.removeCloseListener(this.listeners.onConnectionClosed);
694
+ this.conn.removeDataListener();
695
+ this.conn.removeErrorListener();
696
+ this.conn.removeCloseListener();
697
697
  if (this.handshakeTimeout) {
698
698
  clearTimeout(this.handshakeTimeout);
699
699
  this.handshakeTimeout = void 0;
@@ -749,9 +749,9 @@ var SessionConnected = class extends IdentifiedSession {
749
749
  super(props);
750
750
  this.conn = props.conn;
751
751
  this.listeners = props.listeners;
752
- this.conn.addDataListener(this.onMessageData);
753
- this.conn.addCloseListener(this.listeners.onConnectionClosed);
754
- this.conn.addErrorListener(this.listeners.onConnectionErrored);
752
+ this.conn.setDataListener(this.onMessageData);
753
+ this.conn.setCloseListener(this.listeners.onConnectionClosed);
754
+ this.conn.setErrorListener(this.listeners.onConnectionErrored);
755
755
  }
756
756
  sendBufferedMessages() {
757
757
  if (this.sendBuffer.length > 0) {
@@ -860,9 +860,9 @@ var SessionConnected = class extends IdentifiedSession {
860
860
  };
861
861
  _handleStateExit() {
862
862
  super._handleStateExit();
863
- this.conn.removeDataListener(this.onMessageData);
864
- this.conn.removeCloseListener(this.listeners.onConnectionClosed);
865
- this.conn.removeErrorListener(this.listeners.onConnectionErrored);
863
+ this.conn.removeDataListener();
864
+ this.conn.removeCloseListener();
865
+ this.conn.removeErrorListener();
866
866
  if (this.heartbeatHandle) {
867
867
  clearInterval(this.heartbeatHandle);
868
868
  this.heartbeatHandle = void 0;
@@ -1164,7 +1164,7 @@ var Transport = class {
1164
1164
  }
1165
1165
  // common listeners
1166
1166
  onSessionGracePeriodElapsed(session) {
1167
- this.log?.warn(
1167
+ this.log?.info(
1168
1168
  `session to ${session.to} grace period elapsed, closing`,
1169
1169
  session.loggingMetadata
1170
1170
  );
@@ -1521,15 +1521,6 @@ var ClientTransport = class extends Transport {
1521
1521
  });
1522
1522
  const res = connectedSession.sendBufferedMessages();
1523
1523
  if (!res.ok) {
1524
- this.log?.error(`failed to send buffered messages: ${res.reason}`, {
1525
- ...connectedSession.loggingMetadata,
1526
- transportMessage: msg
1527
- });
1528
- this.protocolError({
1529
- type: ProtocolError.MessageSendFailure,
1530
- message: res.reason
1531
- });
1532
- this.deleteSession(connectedSession, { unhealthy: true });
1533
1524
  return;
1534
1525
  }
1535
1526
  this.updateSession(connectedSession);
@@ -2076,18 +2067,6 @@ var ServerTransport = class extends Transport {
2076
2067
  );
2077
2068
  const bufferSendRes = connectedSession.sendBufferedMessages();
2078
2069
  if (!bufferSendRes.ok) {
2079
- this.log?.error(
2080
- `failed to send buffered messages: ${bufferSendRes.reason}`,
2081
- {
2082
- ...connectedSession.loggingMetadata,
2083
- transportMessage: msg
2084
- }
2085
- );
2086
- this.protocolError({
2087
- type: ProtocolError.MessageSendFailure,
2088
- message: bufferSendRes.reason
2089
- });
2090
- this.deleteSession(connectedSession, { unhealthy: true });
2091
2070
  return;
2092
2071
  }
2093
2072
  this.sessionHandshakeMetadata.set(connectedSession.to, parsedMetadata);
@@ -2118,60 +2097,44 @@ var Connection = class {
2118
2097
  }
2119
2098
  return metadata;
2120
2099
  }
2121
- // can't use event emitter because we need this to work in both node + browser
2122
- _dataListeners = /* @__PURE__ */ new Set();
2123
- _closeListeners = /* @__PURE__ */ new Set();
2124
- _errorListeners = /* @__PURE__ */ new Set();
2125
- get dataListeners() {
2126
- return [...this._dataListeners];
2127
- }
2128
- get closeListeners() {
2129
- return [...this._closeListeners];
2130
- }
2131
- get errorListeners() {
2132
- return [...this._errorListeners];
2133
- }
2100
+ dataListener;
2101
+ closeListener;
2102
+ errorListener;
2134
2103
  onData(msg) {
2135
- for (const cb of this.dataListeners) {
2136
- cb(msg);
2137
- }
2104
+ this.dataListener?.(msg);
2138
2105
  }
2139
2106
  onError(err) {
2140
- for (const cb of this.errorListeners) {
2141
- cb(err);
2142
- }
2107
+ this.errorListener?.(err);
2143
2108
  }
2144
2109
  onClose() {
2145
- for (const cb of this.closeListeners) {
2146
- cb();
2147
- }
2110
+ this.closeListener?.();
2148
2111
  this.telemetry?.span.end();
2149
2112
  }
2150
2113
  /**
2151
- * Handle adding a callback for when a message is received.
2152
- * @param msg The message that was received.
2114
+ * Set the callback for when a message is received.
2115
+ * @param cb The message handler callback.
2153
2116
  */
2154
- addDataListener(cb) {
2155
- this._dataListeners.add(cb);
2117
+ setDataListener(cb) {
2118
+ this.dataListener = cb;
2156
2119
  }
2157
- removeDataListener(cb) {
2158
- this._dataListeners.delete(cb);
2120
+ removeDataListener() {
2121
+ this.dataListener = void 0;
2159
2122
  }
2160
2123
  /**
2161
- * Handle adding a callback for when the connection is closed.
2162
- * This should also be called if an error happens and after notifying all the error listeners.
2124
+ * Set the callback for when the connection is closed.
2125
+ * This should also be called if an error happens and after notifying the error listener.
2163
2126
  * @param cb The callback to call when the connection is closed.
2164
2127
  */
2165
- addCloseListener(cb) {
2166
- this._closeListeners.add(cb);
2128
+ setCloseListener(cb) {
2129
+ this.closeListener = cb;
2167
2130
  }
2168
- removeCloseListener(cb) {
2169
- this._closeListeners.delete(cb);
2131
+ removeCloseListener() {
2132
+ this.closeListener = void 0;
2170
2133
  }
2171
2134
  /**
2172
- * Handle adding a callback for when an error is received.
2173
- * This should only be used for this.logging errors, all cleanup
2174
- * should be delegated to addCloseListener.
2135
+ * Set the callback for when an error is received.
2136
+ * This should only be used for logging errors, all cleanup
2137
+ * should be delegated to setCloseListener.
2175
2138
  *
2176
2139
  * The implementer should take care such that the implemented
2177
2140
  * connection will call both the close and error callbacks
@@ -2179,11 +2142,11 @@ var Connection = class {
2179
2142
  *
2180
2143
  * @param cb The callback to call when an error is received.
2181
2144
  */
2182
- addErrorListener(cb) {
2183
- this._errorListeners.add(cb);
2145
+ setErrorListener(cb) {
2146
+ this.errorListener = cb;
2184
2147
  }
2185
- removeErrorListener(cb) {
2186
- this._errorListeners.delete(cb);
2148
+ removeErrorListener() {
2149
+ this.errorListener = void 0;
2187
2150
  }
2188
2151
  };
2189
2152
 
@@ -2652,19 +2615,13 @@ var InMemoryConnection = class extends Connection {
2652
2615
  this.conn = pipe;
2653
2616
  this.conn.allowHalfOpen = false;
2654
2617
  this.conn.on("data", (data) => {
2655
- for (const cb of this.dataListeners) {
2656
- cb(data);
2657
- }
2618
+ this.dataListener?.(data);
2658
2619
  });
2659
2620
  this.conn.on("close", () => {
2660
- for (const cb of this.closeListeners) {
2661
- cb();
2662
- }
2621
+ this.closeListener?.();
2663
2622
  });
2664
2623
  this.conn.on("error", (err) => {
2665
- for (const cb of this.errorListeners) {
2666
- cb(err);
2667
- }
2624
+ this.errorListener?.(err);
2668
2625
  });
2669
2626
  }
2670
2627
  send(payload) {