@replit/river 0.23.10 → 0.23.12

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 (52) hide show
  1. package/dist/{chunk-FRICSBDW.js → chunk-7RUKEUKE.js} +2 -2
  2. package/dist/{chunk-FRICSBDW.js.map → chunk-7RUKEUKE.js.map} +1 -1
  3. package/dist/{chunk-UXQMGZKP.js → chunk-H6KTH6W6.js} +2 -2
  4. package/dist/{chunk-Z4G27Y2I.js → chunk-HDBVL7EF.js} +2 -2
  5. package/dist/{chunk-KBAZ5TWE.js → chunk-VRU4IKRT.js} +62 -50
  6. package/dist/chunk-VRU4IKRT.js.map +1 -0
  7. package/dist/{chunk-B323CECK.js → chunk-XZ6IOBM5.js} +9 -9
  8. package/dist/chunk-XZ6IOBM5.js.map +1 -0
  9. package/dist/{connection-efcd4e1a.d.ts → connection-581558f8.d.ts} +1 -1
  10. package/dist/{connection-700340c4.d.ts → connection-8debd45f.d.ts} +1 -1
  11. package/dist/router/index.cjs +8 -8
  12. package/dist/router/index.cjs.map +1 -1
  13. package/dist/router/index.d.cts +11 -7
  14. package/dist/router/index.d.ts +11 -7
  15. package/dist/router/index.js +2 -2
  16. package/dist/{services-409c5545.d.ts → services-ca72c9f8.d.ts} +1 -1
  17. package/dist/transport/impls/uds/client.cjs +59 -47
  18. package/dist/transport/impls/uds/client.cjs.map +1 -1
  19. package/dist/transport/impls/uds/client.d.cts +2 -2
  20. package/dist/transport/impls/uds/client.d.ts +2 -2
  21. package/dist/transport/impls/uds/client.js +3 -3
  22. package/dist/transport/impls/uds/server.cjs +20 -38
  23. package/dist/transport/impls/uds/server.cjs.map +1 -1
  24. package/dist/transport/impls/uds/server.d.cts +2 -2
  25. package/dist/transport/impls/uds/server.d.ts +2 -2
  26. package/dist/transport/impls/uds/server.js +3 -3
  27. package/dist/transport/impls/ws/client.cjs +59 -47
  28. package/dist/transport/impls/ws/client.cjs.map +1 -1
  29. package/dist/transport/impls/ws/client.d.cts +2 -2
  30. package/dist/transport/impls/ws/client.d.ts +2 -2
  31. package/dist/transport/impls/ws/client.js +3 -3
  32. package/dist/transport/impls/ws/server.cjs +20 -38
  33. package/dist/transport/impls/ws/server.cjs.map +1 -1
  34. package/dist/transport/impls/ws/server.d.cts +2 -2
  35. package/dist/transport/impls/ws/server.d.ts +2 -2
  36. package/dist/transport/impls/ws/server.js +3 -3
  37. package/dist/transport/index.cjs +61 -49
  38. package/dist/transport/index.cjs.map +1 -1
  39. package/dist/transport/index.d.cts +1 -1
  40. package/dist/transport/index.d.ts +1 -1
  41. package/dist/transport/index.js +2 -2
  42. package/dist/{transport-cf856c41.d.ts → transport-47af1c81.d.ts} +4 -5
  43. package/dist/util/testHelpers.cjs +8 -23
  44. package/dist/util/testHelpers.cjs.map +1 -1
  45. package/dist/util/testHelpers.d.cts +2 -2
  46. package/dist/util/testHelpers.d.ts +2 -2
  47. package/dist/util/testHelpers.js +3 -3
  48. package/package.json +1 -1
  49. package/dist/chunk-B323CECK.js.map +0 -1
  50. package/dist/chunk-KBAZ5TWE.js.map +0 -1
  51. /package/dist/{chunk-UXQMGZKP.js.map → chunk-H6KTH6W6.js.map} +0 -0
  52. /package/dist/{chunk-Z4G27Y2I.js.map → chunk-HDBVL7EF.js.map} +0 -0
@@ -1,8 +1,8 @@
1
- import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-409c5545.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-409c5545.js';
1
+ import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-ca72c9f8.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-ca72c9f8.js';
3
3
  import { Static } from '@sinclair/typebox';
4
- import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-cf856c41.js';
5
- export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-cf856c41.js';
4
+ import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-47af1c81.js';
5
+ export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-47af1c81.js';
6
6
  import { Pushable } from 'it-pushable';
7
7
  import '../index-60f03cb7.js';
8
8
  import '@sinclair/typebox/value';
@@ -42,7 +42,11 @@ type PayloadBreakage = {
42
42
  reason: 'field-breakage';
43
43
  fieldBreakages: Record<string, PayloadBreakage>;
44
44
  };
45
- declare function diffServerSchema(oldServer: SerializedServerSchema, newServer: SerializedServerSchema): ServerBreakage | null;
45
+ interface DiffOptions {
46
+ allowServiceRemoval?: boolean;
47
+ allowProcedureRemoval?: boolean;
48
+ }
49
+ declare function diffServerSchema(oldServer: SerializedServerSchema, newServer: SerializedServerSchema, options?: DiffOptions): ServerBreakage | null;
46
50
 
47
51
  /**
48
52
  * Represents a server with a set of services. Use {@link createServer} to create it.
@@ -77,6 +81,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
77
81
  extendedContext?: Omit<ServiceContext, 'state'>;
78
82
  }>): Server<Services>;
79
83
 
80
- var version = "0.23.10";
84
+ var version = "0.23.12";
81
85
 
82
- export { PayloadBreakage, PayloadType, ProcedureBreakage, version as RIVER_VERSION, Result, RiverError, SerializedServerSchema, Server, ServerBreakage, ServiceBreakage, ServiceContext, createServer, diffServerSchema };
86
+ export { DiffOptions, PayloadBreakage, PayloadType, ProcedureBreakage, version as RIVER_VERSION, Result, RiverError, SerializedServerSchema, Server, ServerBreakage, ServiceBreakage, ServiceContext, createServer, diffServerSchema };
@@ -1,8 +1,8 @@
1
- import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-409c5545.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-409c5545.js';
1
+ import { S as SerializedServerSchema, A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-ca72c9f8.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-ca72c9f8.js';
3
3
  import { Static } from '@sinclair/typebox';
4
- import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-cf856c41.js';
5
- export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-cf856c41.js';
4
+ import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-47af1c81.js';
5
+ export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-47af1c81.js';
6
6
  import { Pushable } from 'it-pushable';
7
7
  import '../index-60f03cb7.js';
8
8
  import '@sinclair/typebox/value';
@@ -42,7 +42,11 @@ type PayloadBreakage = {
42
42
  reason: 'field-breakage';
43
43
  fieldBreakages: Record<string, PayloadBreakage>;
44
44
  };
45
- declare function diffServerSchema(oldServer: SerializedServerSchema, newServer: SerializedServerSchema): ServerBreakage | null;
45
+ interface DiffOptions {
46
+ allowServiceRemoval?: boolean;
47
+ allowProcedureRemoval?: boolean;
48
+ }
49
+ declare function diffServerSchema(oldServer: SerializedServerSchema, newServer: SerializedServerSchema, options?: DiffOptions): ServerBreakage | null;
46
50
 
47
51
  /**
48
52
  * Represents a server with a set of services. Use {@link createServer} to create it.
@@ -77,6 +81,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
77
81
  extendedContext?: Omit<ServiceContext, 'state'>;
78
82
  }>): Server<Services>;
79
83
 
80
- var version = "0.23.10";
84
+ var version = "0.23.12";
81
85
 
82
- export { PayloadBreakage, PayloadType, ProcedureBreakage, version as RIVER_VERSION, Result, RiverError, SerializedServerSchema, Server, ServerBreakage, ServiceBreakage, ServiceContext, createServer, diffServerSchema };
86
+ 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-B323CECK.js";
14
+ } from "../chunk-XZ6IOBM5.js";
15
15
  import {
16
16
  version
17
- } from "../chunk-FRICSBDW.js";
17
+ } from "../chunk-7RUKEUKE.js";
18
18
  export {
19
19
  Err,
20
20
  Ok,
@@ -1,5 +1,5 @@
1
1
  import { Static, TObject, TUnion, TString, TSchema, TNever, TLiteral } from '@sinclair/typebox';
2
- import { c as ClientTransport, C as Connection, l as ClientHandshakeOptions, i as ServiceContextWithTransportInfo } from './transport-cf856c41.js';
2
+ import { c as ClientTransport, C as Connection, l as ClientHandshakeOptions, i as ServiceContextWithTransportInfo } from './transport-47af1c81.js';
3
3
  import { Pushable } from 'it-pushable';
4
4
  import { T as TransportClientId } from './index-60f03cb7.js';
5
5
 
@@ -110,7 +110,7 @@ function isAck(controlFlag) {
110
110
  var import_api = require("@opentelemetry/api");
111
111
 
112
112
  // package.json
113
- var version = "0.23.10";
113
+ var version = "0.23.12";
114
114
 
115
115
  // tracing/index.ts
116
116
  function getPropagationContext(ctx) {
@@ -369,10 +369,12 @@ var Session = class {
369
369
  this.connection.close();
370
370
  this.connection = void 0;
371
371
  }
372
- replaceWithNewConnection(newConn) {
372
+ replaceWithNewConnection(newConn, isTransparentReconnect) {
373
373
  this.closeStaleConnection(newConn);
374
374
  this.cancelGrace();
375
- this.sendBufferedMessages(newConn);
375
+ if (isTransparentReconnect) {
376
+ this.sendBufferedMessages(newConn);
377
+ }
376
378
  this.connection = newConn;
377
379
  this.handshakingConnection = void 0;
378
380
  }
@@ -384,19 +386,8 @@ var Session = class {
384
386
  `starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
385
387
  this.loggingMetadata
386
388
  );
387
- this.cancelGrace({ keepHeartbeatMisses: true });
389
+ this.cancelGrace();
388
390
  this.disconnectionGrace = setTimeout(() => {
389
- if (this.connection !== void 0) {
390
- this.log?.warn(
391
- `grace period for ${this.to} elapsed while connected. not calling callback`,
392
- {
393
- ...this.loggingMetadata,
394
- connId: this.connection.id,
395
- tags: ["invariant-violation"]
396
- }
397
- );
398
- return;
399
- }
400
391
  this.log?.info(
401
392
  `grace period for ${this.to} elapsed`,
402
393
  this.loggingMetadata
@@ -405,14 +396,8 @@ var Session = class {
405
396
  }, this.options.sessionDisconnectGraceMs);
406
397
  }
407
398
  // called on reconnect of the underlying session
408
- cancelGrace({ keepHeartbeatMisses } = {
409
- keepHeartbeatMisses: false
410
- }) {
411
- if (!keepHeartbeatMisses) {
412
- this.heartbeatMisses = 0;
413
- }
414
- if (this.disconnectionGrace === void 0)
415
- return;
399
+ cancelGrace() {
400
+ this.heartbeatMisses = 0;
416
401
  clearTimeout(this.disconnectionGrace);
417
402
  this.disconnectionGrace = void 0;
418
403
  }
@@ -864,21 +849,17 @@ var Transport = class {
864
849
  * and we know the identity of the connected client.
865
850
  * @param conn The connection object.
866
851
  */
867
- onConnect(conn, connectedTo, session, isReconnect) {
852
+ onConnect(conn, session, isTransparentReconnect) {
868
853
  this.eventDispatcher.dispatchEvent("connectionStatus", {
869
854
  status: "connect",
870
855
  conn
871
856
  });
872
857
  conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
873
- if (isReconnect) {
874
- session.replaceWithNewConnection(conn);
875
- this.log?.info(`reconnected to ${connectedTo}`, {
876
- ...conn.loggingMetadata,
877
- ...session.loggingMetadata,
878
- clientId: this.clientId,
879
- connectedTo
880
- });
881
- }
858
+ session.replaceWithNewConnection(conn, isTransparentReconnect);
859
+ this.log?.info(`connected to ${session.to}`, {
860
+ ...conn.loggingMetadata,
861
+ ...session.loggingMetadata
862
+ });
882
863
  }
883
864
  createSession(to, conn, propagationCtx) {
884
865
  const session = new Session(
@@ -906,7 +887,8 @@ var Transport = class {
906
887
  propagationCtx
907
888
  }) {
908
889
  let session = this.sessions.get(to);
909
- let isReconnect = session !== void 0;
890
+ const isReconnect = session !== void 0;
891
+ let isTransparentReconnect = isReconnect;
910
892
  if (session?.advertisedSessionId !== void 0 && sessionId !== void 0 && session.advertisedSessionId !== sessionId) {
911
893
  this.log?.info(
912
894
  `session for ${to} already exists but has a different session id (expected: ${session.advertisedSessionId}, got: ${sessionId}), creating a new one`,
@@ -917,7 +899,7 @@ var Transport = class {
917
899
  closeHandshakingConnection: handshakingConn !== void 0,
918
900
  handshakingConn
919
901
  });
920
- isReconnect = false;
902
+ isTransparentReconnect = false;
921
903
  session = void 0;
922
904
  }
923
905
  if (!session) {
@@ -933,7 +915,7 @@ var Transport = class {
933
915
  if (handshakingConn !== void 0) {
934
916
  session.replaceWithNewHandshakingConnection(handshakingConn);
935
917
  }
936
- return { session, isReconnect };
918
+ return { session, isReconnect, isTransparentReconnect };
937
919
  }
938
920
  deleteSession({
939
921
  session,
@@ -1209,12 +1191,16 @@ var ClientTransport = class extends Transport {
1209
1191
  if (session) {
1210
1192
  this.onDisconnect(conn, session);
1211
1193
  }
1212
- this.log?.info(`connection to ${to} disconnected`, {
1213
- ...conn.loggingMetadata,
1214
- ...session?.loggingMetadata,
1215
- clientId: this.clientId,
1216
- connectedTo: to
1217
- });
1194
+ const willReconnect = this.reconnectOnConnectionDrop && this.getStatus() === "open";
1195
+ this.log?.info(
1196
+ `connection to ${to} disconnected` + (willReconnect ? ", reconnecting" : ""),
1197
+ {
1198
+ ...conn.loggingMetadata,
1199
+ ...session?.loggingMetadata,
1200
+ clientId: this.clientId,
1201
+ connectedTo: to
1202
+ }
1203
+ );
1218
1204
  this.inflightConnectionPromises.delete(to);
1219
1205
  if (this.reconnectOnConnectionDrop) {
1220
1206
  void this.connect(to);
@@ -1289,19 +1275,38 @@ var ClientTransport = class extends Transport {
1289
1275
  );
1290
1276
  return false;
1291
1277
  }
1278
+ const previousSession = this.sessions.get(parsed.from);
1279
+ if (previousSession?.advertisedSessionId && previousSession.advertisedSessionId !== parsed.payload.status.sessionId) {
1280
+ this.deleteSession({
1281
+ session: previousSession,
1282
+ closeHandshakingConnection: true
1283
+ });
1284
+ conn.telemetry?.span.setStatus({
1285
+ code: import_api3.SpanStatusCode.ERROR,
1286
+ message: "session id mismatch"
1287
+ });
1288
+ this.log?.warn(`handshake from ${parsed.from} session id mismatch`, {
1289
+ ...conn.loggingMetadata,
1290
+ clientId: this.clientId,
1291
+ connectedTo: parsed.from,
1292
+ transportMessage: parsed
1293
+ });
1294
+ this.protocolError(ProtocolError.HandshakeFailed, "session id mismatch");
1295
+ return false;
1296
+ }
1292
1297
  this.log?.debug(`handshake from ${parsed.from} ok`, {
1293
1298
  ...conn.loggingMetadata,
1294
1299
  clientId: this.clientId,
1295
1300
  connectedTo: parsed.from,
1296
1301
  transportMessage: parsed
1297
1302
  });
1298
- const { session, isReconnect } = this.getOrCreateSession({
1303
+ const { session, isTransparentReconnect } = this.getOrCreateSession({
1299
1304
  to: parsed.from,
1300
1305
  conn,
1301
1306
  sessionId: parsed.payload.status.sessionId
1302
1307
  });
1303
- this.onConnect(conn, parsed.from, session, isReconnect);
1304
- this.retryBudget.startRestoringBudget(parsed.from);
1308
+ this.onConnect(conn, session, isTransparentReconnect);
1309
+ this.retryBudget.startRestoringBudget(session.to);
1305
1310
  return session;
1306
1311
  }
1307
1312
  /**
@@ -1309,6 +1314,13 @@ var ClientTransport = class extends Transport {
1309
1314
  * @param to The client ID of the node to connect to.
1310
1315
  */
1311
1316
  async connect(to) {
1317
+ if (this.connections.has(to)) {
1318
+ this.log?.info(`already connected to ${to}, skipping connect attempt`, {
1319
+ clientId: this.clientId,
1320
+ connectedTo: to
1321
+ });
1322
+ return;
1323
+ }
1312
1324
  const canProceedWithConnection = () => this.getStatus() === "open";
1313
1325
  if (!canProceedWithConnection()) {
1314
1326
  this.log?.info(
@@ -1319,8 +1331,8 @@ var ClientTransport = class extends Transport {
1319
1331
  }
1320
1332
  let reconnectPromise = this.inflightConnectionPromises.get(to);
1321
1333
  if (!reconnectPromise) {
1322
- const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1323
1334
  if (!this.retryBudget.hasBudget(to)) {
1335
+ const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1324
1336
  const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
1325
1337
  this.log?.error(errMsg, { clientId: this.clientId, connectedTo: to });
1326
1338
  this.protocolError(ProtocolError.RetriesExceeded, errMsg);
@@ -1401,7 +1413,7 @@ var ClientTransport = class extends Transport {
1401
1413
  clientId: this.clientId,
1402
1414
  connectedTo: to
1403
1415
  });
1404
- return this.connect(to);
1416
+ await this.connect(to);
1405
1417
  }
1406
1418
  }
1407
1419
  }