@replit/river 0.23.13 → 0.23.15

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 (62) hide show
  1. package/dist/{chunk-2FNLANTJ.js → chunk-5HK7ZQYH.js} +10 -2
  2. package/dist/{chunk-2FNLANTJ.js.map → chunk-5HK7ZQYH.js.map} +1 -1
  3. package/dist/{chunk-KFTGQ3QC.js → chunk-AEY7BBOZ.js} +2 -2
  4. package/dist/{chunk-S4DUN7KK.js → chunk-IJTGEBLG.js} +41 -20
  5. package/dist/chunk-IJTGEBLG.js.map +1 -0
  6. package/dist/{chunk-ZUKDZY54.js → chunk-JMVKSGND.js} +89 -25
  7. package/dist/chunk-JMVKSGND.js.map +1 -0
  8. package/dist/{chunk-XM656KMN.js → chunk-MD4S7GO2.js} +71 -3
  9. package/dist/chunk-MD4S7GO2.js.map +1 -0
  10. package/dist/{chunk-ES4XO2XD.js → chunk-OXVWMLID.js} +33 -4
  11. package/dist/chunk-OXVWMLID.js.map +1 -0
  12. package/dist/{chunk-SX6HI63Q.js → chunk-RQQZUQGE.js} +2 -2
  13. package/dist/{chunk-4QZOW4DH.js → chunk-XYEOXPZQ.js} +2 -2
  14. package/dist/{client-dd5c9dd0.d.ts → client-e13979ac.d.ts} +1 -1
  15. package/dist/{connection-39816c00.d.ts → connection-5d0978ce.d.ts} +1 -1
  16. package/dist/{connection-40318f22.d.ts → connection-e57e98ea.d.ts} +1 -1
  17. package/dist/{handshake-e428d1c8.d.ts → handshake-5665ffd3.d.ts} +13 -0
  18. package/dist/router/index.cjs +16 -1
  19. package/dist/router/index.cjs.map +1 -1
  20. package/dist/router/index.d.cts +7 -7
  21. package/dist/router/index.d.ts +7 -7
  22. package/dist/router/index.js +2 -2
  23. package/dist/{server-ebf80863.d.ts → server-1cfc88d1.d.ts} +1 -1
  24. package/dist/{services-f406b3aa.d.ts → services-86c4d10d.d.ts} +2 -2
  25. package/dist/transport/impls/uds/client.cjs +138 -18
  26. package/dist/transport/impls/uds/client.cjs.map +1 -1
  27. package/dist/transport/impls/uds/client.d.cts +3 -3
  28. package/dist/transport/impls/uds/client.d.ts +3 -3
  29. package/dist/transport/impls/uds/client.js +5 -5
  30. package/dist/transport/impls/uds/server.cjs +182 -23
  31. package/dist/transport/impls/uds/server.cjs.map +1 -1
  32. package/dist/transport/impls/uds/server.d.cts +3 -3
  33. package/dist/transport/impls/uds/server.d.ts +3 -3
  34. package/dist/transport/impls/uds/server.js +5 -5
  35. package/dist/transport/impls/ws/client.cjs +138 -18
  36. package/dist/transport/impls/ws/client.cjs.map +1 -1
  37. package/dist/transport/impls/ws/client.d.cts +3 -3
  38. package/dist/transport/impls/ws/client.d.ts +3 -3
  39. package/dist/transport/impls/ws/client.js +5 -5
  40. package/dist/transport/impls/ws/server.cjs +182 -23
  41. package/dist/transport/impls/ws/server.cjs.map +1 -1
  42. package/dist/transport/impls/ws/server.d.cts +3 -3
  43. package/dist/transport/impls/ws/server.d.ts +3 -3
  44. package/dist/transport/impls/ws/server.js +5 -5
  45. package/dist/transport/index.cjs +227 -40
  46. package/dist/transport/index.cjs.map +1 -1
  47. package/dist/transport/index.d.cts +3 -3
  48. package/dist/transport/index.d.ts +3 -3
  49. package/dist/transport/index.js +5 -5
  50. package/dist/util/testHelpers.cjs +9 -1
  51. package/dist/util/testHelpers.cjs.map +1 -1
  52. package/dist/util/testHelpers.d.cts +3 -3
  53. package/dist/util/testHelpers.d.ts +3 -3
  54. package/dist/util/testHelpers.js +3 -3
  55. package/package.json +13 -14
  56. package/dist/chunk-ES4XO2XD.js.map +0 -1
  57. package/dist/chunk-S4DUN7KK.js.map +0 -1
  58. package/dist/chunk-XM656KMN.js.map +0 -1
  59. package/dist/chunk-ZUKDZY54.js.map +0 -1
  60. /package/dist/{chunk-KFTGQ3QC.js.map → chunk-AEY7BBOZ.js.map} +0 -0
  61. /package/dist/{chunk-SX6HI63Q.js.map → chunk-RQQZUQGE.js.map} +0 -0
  62. /package/dist/{chunk-4QZOW4DH.js.map → chunk-XYEOXPZQ.js.map} +0 -0
@@ -1,14 +1,14 @@
1
- import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-f406b3aa.js';
2
- export { C as Client, E as Err, O as Ok, z as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l 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, n as SerializedServiceSchema, e as Service, f as ServiceConfiguration, m 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-f406b3aa.js';
1
+ import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-86c4d10d.js';
2
+ export { C as Client, E as Err, O as Ok, z as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l 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, n as SerializedServiceSchema, e as Service, f as ServiceConfiguration, m 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-86c4d10d.js';
3
3
  import { Static } from '@sinclair/typebox';
4
4
  import { Pushable } from 'it-pushable';
5
- import { C as Connection, m as ServerHandshakeOptions, i as ServiceContext } from '../handshake-e428d1c8.js';
6
- export { n as ParsedMetadata, o as ServiceContextWithState, p as ServiceContextWithTransportInfo, q as createClientHandshakeOptions, r as createServerHandshakeOptions } from '../handshake-e428d1c8.js';
7
- import { S as ServerTransport } from '../server-ebf80863.js';
5
+ import { C as Connection, m as ServerHandshakeOptions, i as ServiceContext } from '../handshake-5665ffd3.js';
6
+ export { n as ParsedMetadata, o as ServiceContextWithState, p as ServiceContextWithTransportInfo, q as createClientHandshakeOptions, r as createServerHandshakeOptions } from '../handshake-5665ffd3.js';
7
+ import { S as ServerTransport } from '../server-1cfc88d1.js';
8
8
  import '../index-ea74cdbb.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
- import '../client-dd5c9dd0.js';
11
+ import '../client-e13979ac.js';
12
12
  import '../types-3e5768ec.js';
13
13
 
14
14
  interface ServerBreakage {
@@ -83,6 +83,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
83
83
  extendedContext?: Omit<ServiceContext, 'state'>;
84
84
  }>): Server<Services>;
85
85
 
86
- var version = "0.23.13";
86
+ var version = "0.23.15";
87
87
 
88
88
  export { DiffOptions, PayloadBreakage, PayloadType, ProcedureBreakage, version as RIVER_VERSION, Result, RiverError, SerializedServerSchema, Server, ServerBreakage, ServiceBreakage, ServiceContext, createServer, diffServerSchema };
@@ -1,14 +1,14 @@
1
- import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-f406b3aa.js';
2
- export { C as Client, E as Err, O as Ok, z as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l 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, n as SerializedServiceSchema, e as Service, f as ServiceConfiguration, m 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-f406b3aa.js';
1
+ import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-86c4d10d.js';
2
+ export { C as Client, E as Err, O as Ok, z as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l 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, n as SerializedServiceSchema, e as Service, f as ServiceConfiguration, m 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-86c4d10d.js';
3
3
  import { Static } from '@sinclair/typebox';
4
4
  import { Pushable } from 'it-pushable';
5
- import { C as Connection, m as ServerHandshakeOptions, i as ServiceContext } from '../handshake-e428d1c8.js';
6
- export { n as ParsedMetadata, o as ServiceContextWithState, p as ServiceContextWithTransportInfo, q as createClientHandshakeOptions, r as createServerHandshakeOptions } from '../handshake-e428d1c8.js';
7
- import { S as ServerTransport } from '../server-ebf80863.js';
5
+ import { C as Connection, m as ServerHandshakeOptions, i as ServiceContext } from '../handshake-5665ffd3.js';
6
+ export { n as ParsedMetadata, o as ServiceContextWithState, p as ServiceContextWithTransportInfo, q as createClientHandshakeOptions, r as createServerHandshakeOptions } from '../handshake-5665ffd3.js';
7
+ import { S as ServerTransport } from '../server-1cfc88d1.js';
8
8
  import '../index-ea74cdbb.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
- import '../client-dd5c9dd0.js';
11
+ import '../client-e13979ac.js';
12
12
  import '../types-3e5768ec.js';
13
13
 
14
14
  interface ServerBreakage {
@@ -83,6 +83,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
83
83
  extendedContext?: Omit<ServiceContext, 'state'>;
84
84
  }>): Server<Services>;
85
85
 
86
- var version = "0.23.13";
86
+ var version = "0.23.15";
87
87
 
88
88
  export { DiffOptions, PayloadBreakage, PayloadType, ProcedureBreakage, version as RIVER_VERSION, Result, RiverError, SerializedServerSchema, Server, ServerBreakage, ServiceBreakage, ServiceContext, createServer, diffServerSchema };
@@ -11,10 +11,10 @@ import {
11
11
  createServerHandshakeOptions,
12
12
  diffServerSchema,
13
13
  serializeSchema
14
- } from "../chunk-KFTGQ3QC.js";
14
+ } from "../chunk-AEY7BBOZ.js";
15
15
  import {
16
16
  version
17
- } from "../chunk-ES4XO2XD.js";
17
+ } from "../chunk-OXVWMLID.js";
18
18
  export {
19
19
  Err,
20
20
  Ok,
@@ -1,4 +1,4 @@
1
- import { C as Connection, T as Transport, l as ServerTransportOptions, m as ServerHandshakeOptions, S as Session, n as ParsedMetadata, c as ProvidedServerTransportOptions } from './handshake-e428d1c8.js';
1
+ import { C as Connection, T as Transport, l as ServerTransportOptions, m as ServerHandshakeOptions, S as Session, n as ParsedMetadata, c as ProvidedServerTransportOptions } from './handshake-5665ffd3.js';
2
2
  import { c as TransportClientId } from './index-ea74cdbb.js';
3
3
 
4
4
  declare abstract class ServerTransport<ConnType extends Connection> extends Transport<ConnType> {
@@ -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, k as ClientHandshakeOptions, p as ServiceContextWithTransportInfo } from './handshake-e428d1c8.js';
3
+ import { C as Connection, k as ClientHandshakeOptions, p as ServiceContextWithTransportInfo } from './handshake-5665ffd3.js';
4
4
  import { c as TransportClientId } from './index-ea74cdbb.js';
5
- import { C as ClientTransport } from './client-dd5c9dd0.js';
5
+ import { C as ClientTransport } from './client-e13979ac.js';
6
6
 
7
7
  type AsyncIter<T> = AsyncGenerator<T, T>;
8
8
  /**
@@ -60,6 +60,21 @@ var ControlMessageHandshakeRequestSchema = import_typebox.Type.Object({
60
60
  type: import_typebox.Type.Literal("HANDSHAKE_REQ"),
61
61
  protocolVersion: import_typebox.Type.String(),
62
62
  sessionId: import_typebox.Type.String(),
63
+ /**
64
+ * Specifies what the server's expected session state (from the pov of the client). This can be
65
+ * used by the server to know whether this is a new or a reestablished connection, and whether it
66
+ * is compatible with what it already has.
67
+ */
68
+ expectedSessionState: import_typebox.Type.Optional(
69
+ import_typebox.Type.Object({
70
+ /**
71
+ * reconnect is set to true if the client explicitly wants to reestablish an existing
72
+ * connection.
73
+ */
74
+ reconnect: import_typebox.Type.Boolean(),
75
+ nextExpectedSeq: import_typebox.Type.Integer()
76
+ })
77
+ ),
63
78
  metadata: import_typebox.Type.Optional(import_typebox.Type.Unknown())
64
79
  });
65
80
  var ControlMessageHandshakeResponseSchema = import_typebox.Type.Object({
@@ -84,7 +99,14 @@ var ControlMessagePayloadSchema = import_typebox.Type.Union([
84
99
  var OpaqueTransportMessageSchema = TransportMessageSchema(
85
100
  import_typebox.Type.Unknown()
86
101
  );
87
- function handshakeRequestMessage(from, to, sessionId, metadata, tracing) {
102
+ function handshakeRequestMessage({
103
+ from,
104
+ to,
105
+ sessionId,
106
+ expectedSessionState,
107
+ metadata,
108
+ tracing
109
+ }) {
88
110
  return {
89
111
  id: (0, import_nanoid.nanoid)(),
90
112
  from,
@@ -98,10 +120,12 @@ function handshakeRequestMessage(from, to, sessionId, metadata, tracing) {
98
120
  type: "HANDSHAKE_REQ",
99
121
  protocolVersion: PROTOCOL_VERSION,
100
122
  sessionId,
123
+ expectedSessionState,
101
124
  metadata
102
125
  }
103
126
  };
104
127
  }
128
+ var SESSION_STATE_MISMATCH = "session state mismatch";
105
129
  function isAck(controlFlag) {
106
130
  return (controlFlag & 1 /* AckBit */) === 1 /* AckBit */;
107
131
  }
@@ -110,7 +134,7 @@ function isAck(controlFlag) {
110
134
  var import_api = require("@opentelemetry/api");
111
135
 
112
136
  // package.json
113
- var version = "0.23.13";
137
+ var version = "0.23.15";
114
138
 
115
139
  // tracing/index.ts
116
140
  function getPropagationContext(ctx) {
@@ -424,9 +448,17 @@ var Session = class {
424
448
  get connected() {
425
449
  return this.connection !== void 0;
426
450
  }
451
+ get nextExpectedAck() {
452
+ return this.seq;
453
+ }
427
454
  get nextExpectedSeq() {
428
455
  return this.ack;
429
456
  }
457
+ // This is only used in tests to make the session misbehave.
458
+ /* @internal */
459
+ advanceAckForTesting(by) {
460
+ this.ack += by;
461
+ }
430
462
  constructMsg(partialMsg) {
431
463
  const msg = {
432
464
  ...partialMsg,
@@ -869,6 +901,20 @@ var Transport = class {
869
901
  if (this.log) {
870
902
  session.bindLogger(this.log);
871
903
  }
904
+ const currentSession = this.sessions.get(session.to);
905
+ if (currentSession) {
906
+ this.log?.warn(
907
+ `session ${session.id} from ${session.to} surreptitiously replacing ${currentSession.id}`,
908
+ {
909
+ ...currentSession.loggingMetadata,
910
+ tags: ["invariant-violation"]
911
+ }
912
+ );
913
+ this.deleteSession({
914
+ session: currentSession,
915
+ closeHandshakingConnection: false
916
+ });
917
+ }
872
918
  this.sessions.set(session.to, session);
873
919
  this.eventDispatcher.dispatchEvent("sessionStatus", {
874
920
  status: "connect",
@@ -876,6 +922,49 @@ var Transport = class {
876
922
  });
877
923
  return session;
878
924
  }
925
+ createNewSession({
926
+ to,
927
+ conn,
928
+ sessionId,
929
+ propagationCtx
930
+ }) {
931
+ let session = this.sessions.get(to);
932
+ if (session !== void 0) {
933
+ this.log?.info(
934
+ `session for ${to} already exists, replacing it with a new session as requested`,
935
+ session.loggingMetadata
936
+ );
937
+ this.deleteSession({
938
+ session,
939
+ closeHandshakingConnection: false
940
+ });
941
+ session = void 0;
942
+ }
943
+ session = this.createSession(to, conn, propagationCtx);
944
+ session.advertisedSessionId = sessionId;
945
+ this.log?.info(`created new session for ${to}`, session.loggingMetadata);
946
+ return session;
947
+ }
948
+ getExistingSession({
949
+ to,
950
+ sessionId,
951
+ nextExpectedSeq
952
+ }) {
953
+ const session = this.sessions.get(to);
954
+ if (
955
+ // reject this request if there was no previous session to replace
956
+ session === void 0 || // or if both parties do not agree about the next expected sequence number
957
+ session.nextExpectedAck < nextExpectedSeq || // or if both parties do not agree on the advertised session id
958
+ session.advertisedSessionId !== sessionId
959
+ ) {
960
+ return false;
961
+ }
962
+ this.log?.info(
963
+ `reused existing session for ${to}`,
964
+ session.loggingMetadata
965
+ );
966
+ return session;
967
+ }
879
968
  getOrCreateSession({
880
969
  to,
881
970
  conn,
@@ -924,6 +1013,17 @@ var Transport = class {
924
1013
  }
925
1014
  session.close();
926
1015
  session.telemetry.span.end();
1016
+ const currentSession = this.sessions.get(session.to);
1017
+ if (currentSession && currentSession.id !== session.id) {
1018
+ this.log?.warn(
1019
+ `session ${session.id} disconnect from ${session.to}, mismatch with ${currentSession.id}`,
1020
+ {
1021
+ ...session.loggingMetadata,
1022
+ tags: ["invariant-violation"]
1023
+ }
1024
+ );
1025
+ return;
1026
+ }
927
1027
  this.sessions.delete(session.to);
928
1028
  this.log?.info(
929
1029
  `session ${session.id} disconnect from ${session.to}`,
@@ -1286,24 +1386,40 @@ var ClientTransport = class extends Transport {
1286
1386
  );
1287
1387
  return false;
1288
1388
  }
1389
+ const previousSession = this.sessions.get(parsed.from);
1289
1390
  if (!parsed.payload.status.ok) {
1290
- conn.telemetry?.span.setStatus({
1291
- code: import_api4.SpanStatusCode.ERROR,
1292
- message: "handshake rejected"
1293
- });
1294
- this.log?.warn(`received handshake rejection`, {
1295
- ...conn.loggingMetadata,
1296
- clientId: this.clientId,
1297
- connectedTo: parsed.from,
1298
- transportMessage: parsed
1299
- });
1391
+ if (parsed.payload.status.reason === SESSION_STATE_MISMATCH) {
1392
+ if (previousSession) {
1393
+ this.deleteSession({
1394
+ session: previousSession,
1395
+ closeHandshakingConnection: true
1396
+ });
1397
+ }
1398
+ conn.telemetry?.span.setStatus({
1399
+ code: import_api4.SpanStatusCode.ERROR,
1400
+ message: parsed.payload.status.reason
1401
+ });
1402
+ } else {
1403
+ conn.telemetry?.span.setStatus({
1404
+ code: import_api4.SpanStatusCode.ERROR,
1405
+ message: "handshake rejected"
1406
+ });
1407
+ }
1408
+ this.log?.warn(
1409
+ `received handshake rejection: ${parsed.payload.status.reason}`,
1410
+ {
1411
+ ...conn.loggingMetadata,
1412
+ clientId: this.clientId,
1413
+ connectedTo: parsed.from,
1414
+ transportMessage: parsed
1415
+ }
1416
+ );
1300
1417
  this.protocolError(
1301
1418
  ProtocolError.HandshakeFailed,
1302
1419
  parsed.payload.status.reason
1303
1420
  );
1304
1421
  return false;
1305
1422
  }
1306
- const previousSession = this.sessions.get(parsed.from);
1307
1423
  if (previousSession?.advertisedSessionId && previousSession.advertisedSessionId !== parsed.payload.status.sessionId) {
1308
1424
  this.deleteSession({
1309
1425
  session: previousSession,
@@ -1483,13 +1599,17 @@ var ClientTransport = class extends Transport {
1483
1599
  }
1484
1600
  }
1485
1601
  const { session } = this.getOrCreateSession({ to, handshakingConn: conn });
1486
- const requestMsg = handshakeRequestMessage(
1487
- this.clientId,
1602
+ const requestMsg = handshakeRequestMessage({
1603
+ from: this.clientId,
1488
1604
  to,
1489
- session.id,
1605
+ sessionId: session.id,
1606
+ expectedSessionState: {
1607
+ reconnect: session.advertisedSessionId !== void 0,
1608
+ nextExpectedSeq: session.nextExpectedSeq
1609
+ },
1490
1610
  metadata,
1491
- getPropagationContext(session.telemetry.ctx)
1492
- );
1611
+ tracing: getPropagationContext(session.telemetry.ctx)
1612
+ });
1493
1613
  this.log?.debug(`sending handshake request to ${to}`, {
1494
1614
  ...conn.loggingMetadata,
1495
1615
  clientId: this.clientId,