@replit/river 0.23.13 → 0.23.14

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-SX6HI63Q.js → chunk-BEALFLCB.js} +2 -2
  2. package/dist/{chunk-S4DUN7KK.js → chunk-D2DHRRBN.js} +41 -20
  3. package/dist/chunk-D2DHRRBN.js.map +1 -0
  4. package/dist/{chunk-ES4XO2XD.js → chunk-GCCRVSMR.js} +33 -4
  5. package/dist/chunk-GCCRVSMR.js.map +1 -0
  6. package/dist/{chunk-KFTGQ3QC.js → chunk-GN4YEXT7.js} +2 -2
  7. package/dist/{chunk-2FNLANTJ.js → chunk-O2AVDJCQ.js} +10 -2
  8. package/dist/{chunk-2FNLANTJ.js.map → chunk-O2AVDJCQ.js.map} +1 -1
  9. package/dist/{chunk-XM656KMN.js → chunk-OTVTKAN6.js} +46 -3
  10. package/dist/chunk-OTVTKAN6.js.map +1 -0
  11. package/dist/{chunk-ZUKDZY54.js → chunk-WUL63FR6.js} +89 -25
  12. package/dist/chunk-WUL63FR6.js.map +1 -0
  13. package/dist/{chunk-4QZOW4DH.js → chunk-YCLZWES2.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 +113 -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 +157 -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 +113 -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 +157 -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 +202 -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-SX6HI63Q.js.map → chunk-BEALFLCB.js.map} +0 -0
  61. /package/dist/{chunk-KFTGQ3QC.js.map → chunk-GN4YEXT7.js.map} +0 -0
  62. /package/dist/{chunk-4QZOW4DH.js.map → chunk-YCLZWES2.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.14";
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.14";
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-GN4YEXT7.js";
15
15
  import {
16
16
  version
17
- } from "../chunk-ES4XO2XD.js";
17
+ } from "../chunk-GCCRVSMR.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.14";
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,
@@ -876,6 +908,49 @@ var Transport = class {
876
908
  });
877
909
  return session;
878
910
  }
911
+ createNewSession({
912
+ to,
913
+ conn,
914
+ sessionId,
915
+ propagationCtx
916
+ }) {
917
+ let session = this.sessions.get(to);
918
+ if (session !== void 0) {
919
+ this.log?.info(
920
+ `session for ${to} already exists, replacing it with a new session as requested`,
921
+ session.loggingMetadata
922
+ );
923
+ this.deleteSession({
924
+ session,
925
+ closeHandshakingConnection: false
926
+ });
927
+ session = void 0;
928
+ }
929
+ session = this.createSession(to, conn, propagationCtx);
930
+ session.advertisedSessionId = sessionId;
931
+ this.log?.info(`created new session for ${to}`, session.loggingMetadata);
932
+ return session;
933
+ }
934
+ getExistingSession({
935
+ to,
936
+ sessionId,
937
+ nextExpectedSeq
938
+ }) {
939
+ const session = this.sessions.get(to);
940
+ if (
941
+ // reject this request if there was no previous session to replace
942
+ session === void 0 || // or if both parties do not agree about the next expected sequence number
943
+ session.nextExpectedAck < nextExpectedSeq || // or if both parties do not agree on the advertised session id
944
+ session.advertisedSessionId !== sessionId
945
+ ) {
946
+ return false;
947
+ }
948
+ this.log?.info(
949
+ `reused existing session for ${to}`,
950
+ session.loggingMetadata
951
+ );
952
+ return session;
953
+ }
879
954
  getOrCreateSession({
880
955
  to,
881
956
  conn,
@@ -1286,24 +1361,40 @@ var ClientTransport = class extends Transport {
1286
1361
  );
1287
1362
  return false;
1288
1363
  }
1364
+ const previousSession = this.sessions.get(parsed.from);
1289
1365
  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
- });
1366
+ if (parsed.payload.status.reason === SESSION_STATE_MISMATCH) {
1367
+ if (previousSession) {
1368
+ this.deleteSession({
1369
+ session: previousSession,
1370
+ closeHandshakingConnection: true
1371
+ });
1372
+ }
1373
+ conn.telemetry?.span.setStatus({
1374
+ code: import_api4.SpanStatusCode.ERROR,
1375
+ message: parsed.payload.status.reason
1376
+ });
1377
+ } else {
1378
+ conn.telemetry?.span.setStatus({
1379
+ code: import_api4.SpanStatusCode.ERROR,
1380
+ message: "handshake rejected"
1381
+ });
1382
+ }
1383
+ this.log?.warn(
1384
+ `received handshake rejection: ${parsed.payload.status.reason}`,
1385
+ {
1386
+ ...conn.loggingMetadata,
1387
+ clientId: this.clientId,
1388
+ connectedTo: parsed.from,
1389
+ transportMessage: parsed
1390
+ }
1391
+ );
1300
1392
  this.protocolError(
1301
1393
  ProtocolError.HandshakeFailed,
1302
1394
  parsed.payload.status.reason
1303
1395
  );
1304
1396
  return false;
1305
1397
  }
1306
- const previousSession = this.sessions.get(parsed.from);
1307
1398
  if (previousSession?.advertisedSessionId && previousSession.advertisedSessionId !== parsed.payload.status.sessionId) {
1308
1399
  this.deleteSession({
1309
1400
  session: previousSession,
@@ -1483,13 +1574,17 @@ var ClientTransport = class extends Transport {
1483
1574
  }
1484
1575
  }
1485
1576
  const { session } = this.getOrCreateSession({ to, handshakingConn: conn });
1486
- const requestMsg = handshakeRequestMessage(
1487
- this.clientId,
1577
+ const requestMsg = handshakeRequestMessage({
1578
+ from: this.clientId,
1488
1579
  to,
1489
- session.id,
1580
+ sessionId: session.id,
1581
+ expectedSessionState: {
1582
+ reconnect: session.advertisedSessionId !== void 0,
1583
+ nextExpectedSeq: session.nextExpectedSeq
1584
+ },
1490
1585
  metadata,
1491
- getPropagationContext(session.telemetry.ctx)
1492
- );
1586
+ tracing: getPropagationContext(session.telemetry.ctx)
1587
+ });
1493
1588
  this.log?.debug(`sending handshake request to ${to}`, {
1494
1589
  ...conn.loggingMetadata,
1495
1590
  clientId: this.clientId,