@replit/river 0.26.4 → 0.26.6

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 (58) hide show
  1. package/dist/{chunk-RSCUADHY.js → chunk-3NZ73HXL.js} +12 -7
  2. package/dist/chunk-3NZ73HXL.js.map +1 -0
  3. package/dist/{chunk-CYD6GTCU.js → chunk-5INVLQT5.js} +2 -2
  4. package/dist/{chunk-CYD6GTCU.js.map → chunk-5INVLQT5.js.map} +1 -1
  5. package/dist/{chunk-PXRKBNWN.js → chunk-APGOIQC4.js} +2 -2
  6. package/dist/{chunk-HPOR6FST.js → chunk-CER7XNCN.js} +13 -10
  7. package/dist/chunk-CER7XNCN.js.map +1 -0
  8. package/dist/{chunk-65EMTMCV.js → chunk-H2RVJ32Z.js} +4 -9
  9. package/dist/chunk-H2RVJ32Z.js.map +1 -0
  10. package/dist/{chunk-42SXIIHP.js → chunk-H677UET6.js} +20 -12
  11. package/dist/chunk-H677UET6.js.map +1 -0
  12. package/dist/{chunk-DS5LF6PS.js → chunk-J7AQMYUQ.js} +9 -9
  13. package/dist/chunk-J7AQMYUQ.js.map +1 -0
  14. package/dist/{chunk-TAH2GVTJ.js → chunk-MZM234IB.js} +1 -1
  15. package/dist/chunk-MZM234IB.js.map +1 -0
  16. package/dist/{client-6c67339a.d.ts → client-96810511.d.ts} +2 -2
  17. package/dist/{connection-03ffb583.d.ts → connection-48133ec3.d.ts} +1 -1
  18. package/dist/{handshake-154a0bb2.d.ts → handshake-65e0e848.d.ts} +8 -3
  19. package/dist/logging/index.cjs.map +1 -1
  20. package/dist/logging/index.d.cts +1 -1
  21. package/dist/logging/index.d.ts +1 -1
  22. package/dist/logging/index.js +1 -1
  23. package/dist/{message-ff78a233.d.ts → message-e917ee98.d.ts} +1 -1
  24. package/dist/router/index.cjs +3 -8
  25. package/dist/router/index.cjs.map +1 -1
  26. package/dist/router/index.d.cts +8 -8
  27. package/dist/router/index.d.ts +8 -8
  28. package/dist/router/index.js +2 -2
  29. package/dist/{server-1f5eb427.d.ts → server-b8aaf116.d.ts} +3 -3
  30. package/dist/{services-6140f578.d.ts → services-40e7c5cf.d.ts} +3 -3
  31. package/dist/transport/impls/ws/client.cjs +38 -27
  32. package/dist/transport/impls/ws/client.cjs.map +1 -1
  33. package/dist/transport/impls/ws/client.d.cts +4 -4
  34. package/dist/transport/impls/ws/client.d.ts +4 -4
  35. package/dist/transport/impls/ws/client.js +6 -6
  36. package/dist/transport/impls/ws/server.cjs +34 -26
  37. package/dist/transport/impls/ws/server.cjs.map +1 -1
  38. package/dist/transport/impls/ws/server.d.cts +4 -4
  39. package/dist/transport/impls/ws/server.d.ts +4 -4
  40. package/dist/transport/impls/ws/server.js +6 -6
  41. package/dist/transport/index.cjs +43 -32
  42. package/dist/transport/index.cjs.map +1 -1
  43. package/dist/transport/index.d.cts +4 -4
  44. package/dist/transport/index.d.ts +4 -4
  45. package/dist/transport/index.js +6 -6
  46. package/dist/util/testHelpers.cjs +21 -18
  47. package/dist/util/testHelpers.cjs.map +1 -1
  48. package/dist/util/testHelpers.d.cts +4 -4
  49. package/dist/util/testHelpers.d.ts +4 -4
  50. package/dist/util/testHelpers.js +3 -3
  51. package/package.json +1 -1
  52. package/dist/chunk-42SXIIHP.js.map +0 -1
  53. package/dist/chunk-65EMTMCV.js.map +0 -1
  54. package/dist/chunk-DS5LF6PS.js.map +0 -1
  55. package/dist/chunk-HPOR6FST.js.map +0 -1
  56. package/dist/chunk-RSCUADHY.js.map +0 -1
  57. package/dist/chunk-TAH2GVTJ.js.map +0 -1
  58. /package/dist/{chunk-PXRKBNWN.js.map → chunk-APGOIQC4.js.map} +0 -0
@@ -1,14 +1,14 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-6140f578.js';
2
- export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-6140f578.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-40e7c5cf.js';
2
+ export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-40e7c5cf.js';
3
3
  import { Static } from '@sinclair/typebox';
4
4
  import { Pushable } from 'it-pushable';
5
- import { C as Connection, s as ServerHandshakeOptions, o as ServiceContext } from '../handshake-154a0bb2.js';
6
- export { t as ParsedMetadata, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../handshake-154a0bb2.js';
7
- import { S as ServerTransport } from '../server-1f5eb427.js';
8
- import '../message-ff78a233.js';
5
+ import { C as Connection, s as ServerHandshakeOptions, o as ServiceContext } from '../handshake-65e0e848.js';
6
+ export { t as ParsedMetadata, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../handshake-65e0e848.js';
7
+ import { S as ServerTransport } from '../server-b8aaf116.js';
8
+ import '../message-e917ee98.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
- import '../client-6c67339a.js';
11
+ import '../client-96810511.js';
12
12
  import '@sinclair/typebox/errors';
13
13
  import '../types-3e5768ec.js';
14
14
 
@@ -46,6 +46,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
46
46
  extendedContext?: Omit<ServiceContext, 'state'>;
47
47
  }>): Server<Services>;
48
48
 
49
- var version = "0.26.4";
49
+ var version = "0.26.6";
50
50
 
51
51
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -1,14 +1,14 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-6140f578.js';
2
- export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-6140f578.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-40e7c5cf.js';
2
+ export { C as Client, E as Err, O as Ok, z as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, p as ProcedureMap, d as ProcedureResult, q as RPCProcedure, y as ResultUnwrapErr, x as ResultUnwrapOk, w as RiverErrorSchema, c as RiverUncaughtSchema, o as SerializedProcedureSchema, m as SerializedServerSchema, n as SerializedServiceSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, v as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, u as createClient, s as serializeSchema } from '../services-40e7c5cf.js';
3
3
  import { Static } from '@sinclair/typebox';
4
4
  import { Pushable } from 'it-pushable';
5
- import { C as Connection, s as ServerHandshakeOptions, o as ServiceContext } from '../handshake-154a0bb2.js';
6
- export { t as ParsedMetadata, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../handshake-154a0bb2.js';
7
- import { S as ServerTransport } from '../server-1f5eb427.js';
8
- import '../message-ff78a233.js';
5
+ import { C as Connection, s as ServerHandshakeOptions, o as ServiceContext } from '../handshake-65e0e848.js';
6
+ export { t as ParsedMetadata, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../handshake-65e0e848.js';
7
+ import { S as ServerTransport } from '../server-b8aaf116.js';
8
+ import '../message-e917ee98.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
- import '../client-6c67339a.js';
11
+ import '../client-96810511.js';
12
12
  import '@sinclair/typebox/errors';
13
13
  import '../types-3e5768ec.js';
14
14
 
@@ -46,6 +46,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
46
46
  extendedContext?: Omit<ServiceContext, 'state'>;
47
47
  }>): Server<Services>;
48
48
 
49
- var version = "0.26.4";
49
+ var version = "0.26.6";
50
50
 
51
51
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -10,10 +10,10 @@ import {
10
10
  createServer,
11
11
  createServerHandshakeOptions,
12
12
  serializeSchema
13
- } from "../chunk-PXRKBNWN.js";
13
+ } from "../chunk-APGOIQC4.js";
14
14
  import {
15
15
  version
16
- } from "../chunk-65EMTMCV.js";
16
+ } from "../chunk-H2RVJ32Z.js";
17
17
  export {
18
18
  Err,
19
19
  Ok,
@@ -1,5 +1,5 @@
1
- import { C as Connection, y as CommonSession, d as SessionState, z as CommonSessionProps, T as Transport, A as ServerTransportOptions, s as ServerHandshakeOptions, t as ParsedMetadata, B as ServerSession, c as ProvidedServerTransportOptions } from './handshake-154a0bb2.js';
2
- import { b as OpaqueTransportMessage, e as Tags, a as TransportMessage, H as HandshakeErrorResponseCodes, c as TransportClientId, P as PartialTransportMessage } from './message-ff78a233.js';
1
+ import { C as Connection, y as CommonSession, d as SessionState, z as CommonSessionProps, T as Transport, A as ServerTransportOptions, s as ServerHandshakeOptions, t as ParsedMetadata, B as ServerSession, c as ProvidedServerTransportOptions, D as DeleteSessionOptions } from './handshake-65e0e848.js';
2
+ import { b as OpaqueTransportMessage, e as Tags, a as TransportMessage, H as HandshakeErrorResponseCodes, c as TransportClientId, P as PartialTransportMessage } from './message-e917ee98.js';
3
3
  import * as _sinclair_typebox_errors from '@sinclair/typebox/errors';
4
4
  import { Static } from '@sinclair/typebox';
5
5
 
@@ -59,7 +59,7 @@ declare abstract class ServerTransport<ConnType extends Connection> extends Tran
59
59
  extendHandshake(options: ServerHandshakeOptions): void;
60
60
  send(to: string, msg: PartialTransportMessage): string;
61
61
  protected deletePendingSession(pendingSession: SessionWaitingForHandshake<ConnType>): void;
62
- protected deleteSession(session: ServerSession<ConnType>): void;
62
+ protected deleteSession(session: ServerSession<ConnType>, options?: DeleteSessionOptions): void;
63
63
  protected handleConnection(conn: ConnType): void;
64
64
  private rejectHandshakeRequest;
65
65
  protected onHandshakeRequest(session: SessionWaitingForHandshake<ConnType>, msg: OpaqueTransportMessage): Promise<void>;
@@ -1,8 +1,8 @@
1
1
  import { Static, TObject, TUnion, TString, TSchema, TNever, TLiteral } from '@sinclair/typebox';
2
2
  import { Pushable } from 'it-pushable';
3
- import { C as Connection, p as ClientHandshakeOptions, v as ServiceContextWithTransportInfo, o as ServiceContext } from './handshake-154a0bb2.js';
4
- import { c as TransportClientId } from './message-ff78a233.js';
5
- import { C as ClientTransport } from './client-6c67339a.js';
3
+ import { C as Connection, p as ClientHandshakeOptions, v as ServiceContextWithTransportInfo, o as ServiceContext } from './handshake-65e0e848.js';
4
+ import { c as TransportClientId } from './message-e917ee98.js';
5
+ import { C as ClientTransport } from './client-96810511.js';
6
6
 
7
7
  type AsyncIter<T> = AsyncGenerator<T, T>;
8
8
  /**
@@ -75,10 +75,7 @@ var ControlMessageHandshakeRequestSchema = import_typebox.Type.Object({
75
75
  expectedSessionState: import_typebox.Type.Object({
76
76
  // what the client expects the server to send next
77
77
  nextExpectedSeq: import_typebox.Type.Integer(),
78
- // TODO: remove optional once we know all servers
79
- // are nextSentSeq here
80
- // what the server expects the client to send next
81
- nextSentSeq: import_typebox.Type.Optional(import_typebox.Type.Integer())
78
+ nextSentSeq: import_typebox.Type.Integer()
82
79
  }),
83
80
  metadata: import_typebox.Type.Optional(import_typebox.Type.Unknown())
84
81
  });
@@ -114,9 +111,7 @@ var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
114
111
  import_typebox.Type.Object({
115
112
  ok: import_typebox.Type.Literal(false),
116
113
  reason: import_typebox.Type.String(),
117
- // TODO: remove optional once we know all servers
118
- // are sending code here
119
- code: import_typebox.Type.Optional(HandshakeErrorResponseCodes)
114
+ code: HandshakeErrorResponseCodes
120
115
  })
121
116
  ])
122
117
  });
@@ -360,7 +355,8 @@ var createLogProxy = (log) => ({
360
355
  var ProtocolError = {
361
356
  RetriesExceeded: "conn_retry_exceeded",
362
357
  HandshakeFailed: "handshake_failed",
363
- MessageOrderingViolated: "message_ordering_violated"
358
+ MessageOrderingViolated: "message_ordering_violated",
359
+ InvalidMessage: "invalid_message"
364
360
  };
365
361
  var EventDispatcher = class {
366
362
  eventListeners = {};
@@ -636,7 +632,7 @@ var SessionNoConnection = class extends IdentifiedSessionWithGracePeriod {
636
632
  var import_api = require("@opentelemetry/api");
637
633
 
638
634
  // package.json
639
- var version = "0.26.4";
635
+ var version = "0.26.6";
640
636
 
641
637
  // tracing/index.ts
642
638
  function getPropagationContext(ctx) {
@@ -798,13 +794,13 @@ var SessionConnected = class extends IdentifiedSession {
798
794
  this.conn.addCloseListener(this.listeners.onConnectionClosed);
799
795
  this.conn.addErrorListener(this.listeners.onConnectionErrored);
800
796
  if (this.sendBuffer.length > 0) {
801
- this.log?.debug(
802
- `sending ${this.sendBuffer.length} buffered messages`,
797
+ this.log?.info(
798
+ `sending ${this.sendBuffer.length} buffered messages, starting at seq ${this.nextSeq()}`,
803
799
  this.loggingMetadata
804
800
  );
805
- }
806
- for (const msg of this.sendBuffer) {
807
- this.conn.send(this.options.codec.toBuffer(msg));
801
+ for (const msg of this.sendBuffer) {
802
+ this.conn.send(this.options.codec.toBuffer(msg));
803
+ }
808
804
  }
809
805
  this.isActivelyHeartbeating = false;
810
806
  this.heartbeatHandle = setInterval(() => {
@@ -846,6 +842,12 @@ var SessionConnected = class extends IdentifiedSession {
846
842
  }
847
843
  });
848
844
  }
845
+ closeConnection() {
846
+ this.conn.removeDataListener(this.onMessageData);
847
+ this.conn.removeCloseListener(this.listeners.onConnectionClosed);
848
+ this.conn.removeErrorListener(this.listeners.onConnectionErrored);
849
+ this.conn.close();
850
+ }
849
851
  onMessageData = (msg) => {
850
852
  const parsedMsg = this.parseMsg(msg);
851
853
  if (parsedMsg === null) {
@@ -862,8 +864,8 @@ var SessionConnected = class extends IdentifiedSession {
862
864
  }
863
865
  );
864
866
  } else {
865
- const reason = `received out-of-order msg (got seq: ${parsedMsg.seq}, wanted seq: ${this.ack})`;
866
- this.log?.error(reason, {
867
+ const reason = `received out-of-order msg, closing connection (got seq: ${parsedMsg.seq}, wanted seq: ${this.ack})`;
868
+ this.log?.warn(reason, {
867
869
  ...this.loggingMetadata,
868
870
  transportMessage: parsedMsg,
869
871
  tags: ["invariant-violation"]
@@ -872,7 +874,7 @@ var SessionConnected = class extends IdentifiedSession {
872
874
  code: import_api2.SpanStatusCode.ERROR,
873
875
  message: reason
874
876
  });
875
- this.listeners.onInvalidMessage(reason);
877
+ this.closeConnection();
876
878
  }
877
879
  return;
878
880
  }
@@ -898,8 +900,10 @@ var SessionConnected = class extends IdentifiedSession {
898
900
  this.conn.removeDataListener(this.onMessageData);
899
901
  this.conn.removeCloseListener(this.listeners.onConnectionClosed);
900
902
  this.conn.removeErrorListener(this.listeners.onConnectionErrored);
901
- clearInterval(this.heartbeatHandle);
902
- this.heartbeatHandle = void 0;
903
+ if (this.heartbeatHandle) {
904
+ clearInterval(this.heartbeatHandle);
905
+ this.heartbeatHandle = void 0;
906
+ }
903
907
  }
904
908
  _handleClose() {
905
909
  super._handleClose();
@@ -1328,8 +1332,12 @@ var Transport = class {
1328
1332
  return session;
1329
1333
  }
1330
1334
  // state transitions
1331
- deleteSession(session) {
1332
- session.log?.info(`closing session ${session.id}`, session.loggingMetadata);
1335
+ deleteSession(session, options) {
1336
+ const loggingMetadata = session.loggingMetadata;
1337
+ if (loggingMetadata.tags && options?.unhealthy) {
1338
+ loggingMetadata.tags.push("unhealthy-session");
1339
+ }
1340
+ session.log?.info(`closing session ${session.id}`, loggingMetadata);
1333
1341
  this.eventDispatcher.dispatchEvent("sessionStatus", {
1334
1342
  status: "disconnect",
1335
1343
  session
@@ -1491,7 +1499,7 @@ var ClientTransport = class extends Transport {
1491
1499
  `invalid handshake: ${reason}`,
1492
1500
  handshakingSession.loggingMetadata
1493
1501
  );
1494
- this.deleteSession(session);
1502
+ this.deleteSession(session, { unhealthy: true });
1495
1503
  this.protocolError({
1496
1504
  type: ProtocolError.HandshakeFailed,
1497
1505
  code,
@@ -1520,7 +1528,7 @@ var ClientTransport = class extends Transport {
1520
1528
  message: reason
1521
1529
  });
1522
1530
  this.log?.warn(reason, metadata);
1523
- this.deleteSession(session);
1531
+ this.deleteSession(session, { unhealthy: true });
1524
1532
  }
1525
1533
  onHandshakeResponse(session, msg) {
1526
1534
  if (!import_value2.Value.Check(ControlMessageHandshakeResponseSchema, msg.payload)) {
@@ -1535,10 +1543,10 @@ var ClientTransport = class extends Transport {
1535
1543
  return;
1536
1544
  }
1537
1545
  if (!msg.payload.status.ok) {
1538
- const retriable = msg.payload.status.code ? import_value2.Value.Check(
1546
+ const retriable = import_value2.Value.Check(
1539
1547
  HandshakeErrorRetriableResponseCodes,
1540
1548
  msg.payload.status.code
1541
- ) : false;
1549
+ );
1542
1550
  const reason = `handshake failed: ${msg.payload.status.reason}`;
1543
1551
  const to = session.to;
1544
1552
  this.rejectHandshakeResponse(session, reason, {
@@ -1585,9 +1593,9 @@ var ClientTransport = class extends Transport {
1585
1593
  },
1586
1594
  onMessage: (msg2) => this.handleMsg(msg2),
1587
1595
  onInvalidMessage: (reason) => {
1588
- this.deleteSession(connectedSession);
1596
+ this.deleteSession(connectedSession, { unhealthy: true });
1589
1597
  this.protocolError({
1590
- type: ProtocolError.MessageOrderingViolated,
1598
+ type: ProtocolError.InvalidMessage,
1591
1599
  message: reason
1592
1600
  });
1593
1601
  }
@@ -1699,6 +1707,9 @@ var ClientTransport = class extends Transport {
1699
1707
  if (this.handshakeExtensions) {
1700
1708
  metadata = await this.handshakeExtensions.construct();
1701
1709
  }
1710
+ if (session._isConsumed) {
1711
+ return;
1712
+ }
1702
1713
  const requestMsg = handshakeRequestMessage({
1703
1714
  from: this.clientId,
1704
1715
  to: session.to,