@replit/river 0.23.7 → 0.23.9

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 (54) hide show
  1. package/dist/{chunk-RLVU5DRX.js → chunk-KIWWKSRI.js} +2 -2
  2. package/dist/{chunk-M3TGXFWT.js → chunk-U4CSF3SQ.js} +2 -2
  3. package/dist/chunk-U4CSF3SQ.js.map +1 -0
  4. package/dist/{chunk-2KC75LS4.js → chunk-XKVIPKMR.js} +2 -3
  5. package/dist/chunk-XKVIPKMR.js.map +1 -0
  6. package/dist/{chunk-MFF6IPBA.js → chunk-XUVTMFTJ.js} +2 -2
  7. package/dist/{chunk-MFF6IPBA.js.map → chunk-XUVTMFTJ.js.map} +1 -1
  8. package/dist/{chunk-XYFXRL7Q.js → chunk-YGW5PYGV.js} +107 -33
  9. package/dist/chunk-YGW5PYGV.js.map +1 -0
  10. package/dist/{connection-6ce35bd5.d.ts → connection-afa08cf1.d.ts} +1 -1
  11. package/dist/{connection-a3fdfa3a.d.ts → connection-f5fb7805.d.ts} +1 -1
  12. package/dist/router/index.cjs +1 -1
  13. package/dist/router/index.cjs.map +1 -1
  14. package/dist/router/index.d.cts +5 -5
  15. package/dist/router/index.d.ts +5 -5
  16. package/dist/router/index.js +2 -2
  17. package/dist/{services-fd8a9894.d.ts → services-49b1b43d.d.ts} +10 -9
  18. package/dist/transport/impls/uds/client.cjs +101 -27
  19. package/dist/transport/impls/uds/client.cjs.map +1 -1
  20. package/dist/transport/impls/uds/client.d.cts +2 -2
  21. package/dist/transport/impls/uds/client.d.ts +2 -2
  22. package/dist/transport/impls/uds/client.js +3 -3
  23. package/dist/transport/impls/uds/server.cjs +83 -17
  24. package/dist/transport/impls/uds/server.cjs.map +1 -1
  25. package/dist/transport/impls/uds/server.d.cts +2 -2
  26. package/dist/transport/impls/uds/server.d.ts +2 -2
  27. package/dist/transport/impls/uds/server.js +3 -3
  28. package/dist/transport/impls/ws/client.cjs +101 -28
  29. package/dist/transport/impls/ws/client.cjs.map +1 -1
  30. package/dist/transport/impls/ws/client.d.cts +2 -2
  31. package/dist/transport/impls/ws/client.d.ts +2 -2
  32. package/dist/transport/impls/ws/client.js +3 -3
  33. package/dist/transport/impls/ws/server.cjs +83 -18
  34. package/dist/transport/impls/ws/server.cjs.map +1 -1
  35. package/dist/transport/impls/ws/server.d.cts +2 -2
  36. package/dist/transport/impls/ws/server.d.ts +2 -2
  37. package/dist/transport/impls/ws/server.js +3 -3
  38. package/dist/transport/index.cjs +106 -32
  39. package/dist/transport/index.cjs.map +1 -1
  40. package/dist/transport/index.d.cts +1 -1
  41. package/dist/transport/index.d.ts +1 -1
  42. package/dist/transport/index.js +2 -2
  43. package/dist/{transport-3d34f714.d.ts → transport-3d0ba1da.d.ts} +33 -7
  44. package/dist/util/testHelpers.cjs +46 -4
  45. package/dist/util/testHelpers.cjs.map +1 -1
  46. package/dist/util/testHelpers.d.cts +2 -2
  47. package/dist/util/testHelpers.d.ts +2 -2
  48. package/dist/util/testHelpers.js +3 -3
  49. package/dist/util/testHelpers.js.map +1 -1
  50. package/package.json +1 -1
  51. package/dist/chunk-2KC75LS4.js.map +0 -1
  52. package/dist/chunk-M3TGXFWT.js.map +0 -1
  53. package/dist/chunk-XYFXRL7Q.js.map +0 -1
  54. /package/dist/{chunk-RLVU5DRX.js.map → chunk-KIWWKSRI.js.map} +0 -0
@@ -1,8 +1,8 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-fd8a9894.js';
2
- export { C as Client, E as Err, O as Ok, x as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, n as ProcedureMap, d as ProcedureResult, o as RPCProcedure, w as ResultUnwrapErr, v as ResultUnwrapOk, u as RiverErrorSchema, c as RiverUncaughtSchema, m as SerializedServerSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, q as StreamProcedure, p as SubscriptionProcedure, t as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, r as createClient, s as serializeSchema } from '../services-fd8a9894.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-49b1b43d.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-49b1b43d.js';
3
3
  import { Static } from '@sinclair/typebox';
4
- import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-3d34f714.js';
5
- export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-3d34f714.js';
4
+ import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-3d0ba1da.js';
5
+ export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-3d0ba1da.js';
6
6
  import { Pushable } from 'it-pushable';
7
7
  import '../index-60f03cb7.js';
8
8
  import '@sinclair/typebox/value';
@@ -43,6 +43,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
43
43
  extendedContext?: Omit<ServiceContext, 'state'>;
44
44
  }>): Server<Services>;
45
45
 
46
- var version = "0.23.7";
46
+ var version = "0.23.9";
47
47
 
48
48
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -1,8 +1,8 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-fd8a9894.js';
2
- export { C as Client, E as Err, O as Ok, x as Output, j as ProcErrors, f as ProcHandler, g as ProcInit, h as ProcInput, i as ProcOutput, k as ProcType, a as Procedure, n as ProcedureMap, d as ProcedureResult, o as RPCProcedure, w as ResultUnwrapErr, v as ResultUnwrapOk, u as RiverErrorSchema, c as RiverUncaughtSchema, m as SerializedServerSchema, S as Service, e as ServiceConfiguration, l as ServiceSchema, q as StreamProcedure, p as SubscriptionProcedure, t as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, r as createClient, s as serializeSchema } from '../services-fd8a9894.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError } from '../services-49b1b43d.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-49b1b43d.js';
3
3
  import { Static } from '@sinclair/typebox';
4
- import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-3d34f714.js';
5
- export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-3d34f714.js';
4
+ import { d as ServerTransport, C as Connection, f as ServerHandshakeOptions, b as ServiceContext } from '../transport-3d0ba1da.js';
5
+ export { g as ParsedMetadata, h as ServiceContextWithState, i as ServiceContextWithTransportInfo, j as createClientHandshakeOptions, k as createServerHandshakeOptions } from '../transport-3d0ba1da.js';
6
6
  import { Pushable } from 'it-pushable';
7
7
  import '../index-60f03cb7.js';
8
8
  import '@sinclair/typebox/value';
@@ -43,6 +43,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
43
43
  extendedContext?: Omit<ServiceContext, 'state'>;
44
44
  }>): Server<Services>;
45
45
 
46
- var version = "0.23.7";
46
+ var version = "0.23.9";
47
47
 
48
48
  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-M3TGXFWT.js";
13
+ } from "../chunk-U4CSF3SQ.js";
14
14
  import {
15
15
  version
16
- } from "../chunk-MFF6IPBA.js";
16
+ } from "../chunk-XUVTMFTJ.js";
17
17
  export {
18
18
  Err,
19
19
  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-3d34f714.js';
2
+ import { c as ClientTransport, C as Connection, l as ClientHandshakeOptions, i as ServiceContextWithTransportInfo } from './transport-3d0ba1da.js';
3
3
  import { Pushable } from 'it-pushable';
4
4
  import { T as TransportClientId } from './index-60f03cb7.js';
5
5
 
@@ -477,14 +477,15 @@ interface ServiceConfiguration<State extends object> {
477
477
  */
478
478
  initializeState: () => State;
479
479
  }
480
+ interface SerializedProcedureSchema {
481
+ input: PayloadType;
482
+ output: PayloadType;
483
+ errors?: RiverError;
484
+ type: 'rpc' | 'subscription' | 'upload' | 'stream';
485
+ init?: PayloadType;
486
+ }
480
487
  interface SerializedServiceSchema {
481
- procedures: Record<string, {
482
- input: PayloadType;
483
- output: PayloadType;
484
- errors?: RiverError;
485
- type: 'rpc' | 'subscription' | 'upload' | 'stream';
486
- init?: PayloadType;
487
- }>;
488
+ procedures: Record<string, SerializedProcedureSchema>;
488
489
  }
489
490
  interface SerializedServerSchema {
490
491
  handshakeSchema?: TSchema;
@@ -704,4 +705,4 @@ declare class ServiceScaffold<State extends object> {
704
705
  }>;
705
706
  }
706
707
 
707
- export { AnyServiceSchemaMap as A, Client as C, Err as E, InstantiatedServiceSchemaMap as I, Ok as O, PayloadType as P, RiverError as R, Service as S, UploadProcedure as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, ProcedureResult as d, ServiceConfiguration as e, ProcHandler as f, ProcInit as g, ProcInput as h, ProcOutput as i, ProcErrors as j, ProcType as k, ServiceSchema as l, SerializedServerSchema as m, ProcedureMap as n, RpcProcedure as o, SubscriptionProcedure as p, StreamProcedure as q, createClient as r, serializeSchema as s, UNCAUGHT_ERROR as t, RiverErrorSchema as u, ResultUnwrapOk as v, ResultUnwrapErr as w, Output as x };
708
+ export { AnyServiceSchemaMap as A, Client as C, Err as E, InstantiatedServiceSchemaMap as I, Ok as O, PayloadType as P, RiverError as R, Service as S, UploadProcedure as U, ValidProcType as V, Procedure as a, Result as b, RiverUncaughtSchema as c, ProcedureResult as d, ServiceConfiguration as e, ProcHandler as f, ProcInit as g, ProcInput as h, ProcOutput as i, ProcErrors as j, ProcType as k, ServiceSchema as l, SerializedServerSchema as m, SerializedServiceSchema as n, SerializedProcedureSchema as o, ProcedureMap as p, RpcProcedure as q, SubscriptionProcedure as r, serializeSchema as s, StreamProcedure as t, createClient as u, UNCAUGHT_ERROR as v, RiverErrorSchema as w, ResultUnwrapOk as x, ResultUnwrapErr as y, Output as z };
@@ -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.7";
113
+ var version = "0.23.9";
114
114
 
115
115
  // tracing/index.ts
116
116
  function getPropagationContext(ctx) {
@@ -190,6 +190,11 @@ var Session = class {
190
190
  * The active connection associated with this session
191
191
  */
192
192
  connection;
193
+ /**
194
+ * A connection that is currently undergoing handshaking. Used to distinguish between the active
195
+ * connection, but still be able to close it if needed.
196
+ */
197
+ handshakingConnection;
193
198
  from;
194
199
  to;
195
200
  /**
@@ -369,23 +374,60 @@ var Session = class {
369
374
  this.cancelGrace();
370
375
  this.sendBufferedMessages(newConn);
371
376
  this.connection = newConn;
377
+ this.handshakingConnection = void 0;
378
+ }
379
+ replaceWithNewHandshakingConnection(newConn) {
380
+ this.handshakingConnection = newConn;
372
381
  }
373
382
  beginGrace(cb) {
374
383
  this.log?.info(
375
384
  `starting ${this.options.sessionDisconnectGraceMs}ms grace period until session to ${this.to} is closed`,
376
385
  this.loggingMetadata
377
386
  );
387
+ this.cancelGrace({ keepHeartbeatMisses: true });
378
388
  this.disconnectionGrace = setTimeout(() => {
379
- this.close();
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
+ this.log?.info(
401
+ `grace period for ${this.to} elapsed`,
402
+ this.loggingMetadata
403
+ );
380
404
  cb();
381
405
  }, this.options.sessionDisconnectGraceMs);
382
406
  }
383
407
  // called on reconnect of the underlying session
384
- cancelGrace() {
385
- this.heartbeatMisses = 0;
408
+ cancelGrace({ keepHeartbeatMisses } = {
409
+ keepHeartbeatMisses: false
410
+ }) {
411
+ if (!keepHeartbeatMisses) {
412
+ this.heartbeatMisses = 0;
413
+ }
414
+ if (this.disconnectionGrace === void 0)
415
+ return;
386
416
  clearTimeout(this.disconnectionGrace);
387
417
  this.disconnectionGrace = void 0;
388
418
  }
419
+ /**
420
+ * Used to close the handshaking connection, if set.
421
+ */
422
+ closeHandshakingConnection(expectedHandshakingConn) {
423
+ if (this.handshakingConnection === void 0)
424
+ return;
425
+ if (expectedHandshakingConn !== void 0 && this.handshakingConnection === expectedHandshakingConn) {
426
+ return;
427
+ }
428
+ this.handshakingConnection.close();
429
+ this.handshakingConnection = void 0;
430
+ }
389
431
  // closed when we want to discard the whole session
390
432
  // (i.e. shutdown or session disconnect)
391
433
  close() {
@@ -854,7 +896,13 @@ var Transport = class {
854
896
  });
855
897
  return session;
856
898
  }
857
- getOrCreateSession(to, conn, sessionId, propagationCtx) {
899
+ getOrCreateSession({
900
+ to,
901
+ conn,
902
+ handshakingConn,
903
+ sessionId,
904
+ propagationCtx
905
+ }) {
858
906
  let session = this.sessions.get(to);
859
907
  let isReconnect = session !== void 0;
860
908
  if (session?.advertisedSessionId !== void 0 && sessionId !== void 0 && session.advertisedSessionId !== sessionId) {
@@ -862,7 +910,11 @@ var Transport = class {
862
910
  `session for ${to} already exists but has a different session id (expected: ${session.advertisedSessionId}, got: ${sessionId}), creating a new one`,
863
911
  session.loggingMetadata
864
912
  );
865
- this.deleteSession(session);
913
+ this.deleteSession({
914
+ session,
915
+ closeHandshakingConnection: handshakingConn !== void 0,
916
+ handshakingConn
917
+ });
866
918
  isReconnect = false;
867
919
  session = void 0;
868
920
  }
@@ -876,9 +928,19 @@ var Transport = class {
876
928
  if (sessionId !== void 0) {
877
929
  session.advertisedSessionId = sessionId;
878
930
  }
931
+ if (handshakingConn !== void 0) {
932
+ session.replaceWithNewHandshakingConnection(handshakingConn);
933
+ }
879
934
  return { session, isReconnect };
880
935
  }
881
- deleteSession(session) {
936
+ deleteSession({
937
+ session,
938
+ closeHandshakingConnection,
939
+ handshakingConn
940
+ }) {
941
+ if (closeHandshakingConnection) {
942
+ session.closeHandshakingConnection(handshakingConn);
943
+ }
882
944
  session.close();
883
945
  session.telemetry.span.end();
884
946
  this.sessions.delete(session.to);
@@ -905,7 +967,11 @@ var Transport = class {
905
967
  session.connection = void 0;
906
968
  session.beginGrace(() => {
907
969
  session.telemetry.span.addEvent("session grace period expired");
908
- this.deleteSession(session);
970
+ this.deleteSession({
971
+ session,
972
+ closeHandshakingConnection: true,
973
+ handshakingConn: conn
974
+ });
909
975
  });
910
976
  }
911
977
  /**
@@ -985,7 +1051,7 @@ var Transport = class {
985
1051
  code: import_api3.SpanStatusCode.ERROR,
986
1052
  message: "message order violated"
987
1053
  });
988
- session.close();
1054
+ this.deleteSession({ session, closeHandshakingConnection: true });
989
1055
  }
990
1056
  return;
991
1057
  }
@@ -1039,7 +1105,7 @@ var Transport = class {
1039
1105
  });
1040
1106
  return void 0;
1041
1107
  }
1042
- return this.getOrCreateSession(to).session.send(msg);
1108
+ return this.getOrCreateSession({ to }).session.send(msg);
1043
1109
  }
1044
1110
  // control helpers
1045
1111
  sendCloseStream(to, streamId) {
@@ -1062,7 +1128,7 @@ var Transport = class {
1062
1128
  close() {
1063
1129
  this.state = "closed";
1064
1130
  for (const session of this.sessions.values()) {
1065
- this.deleteSession(session);
1131
+ this.deleteSession({ session, closeHandshakingConnection: true });
1066
1132
  }
1067
1133
  this.log?.info(`manually closed transport`, { clientId: this.clientId });
1068
1134
  }
@@ -1074,7 +1140,7 @@ var Transport = class {
1074
1140
  destroy() {
1075
1141
  this.state = "destroyed";
1076
1142
  for (const session of this.sessions.values()) {
1077
- this.deleteSession(session);
1143
+ this.deleteSession({ session, closeHandshakingConnection: true });
1078
1144
  }
1079
1145
  this.log?.info(`manually destroyed transport`, { clientId: this.clientId });
1080
1146
  }
@@ -1117,22 +1183,22 @@ var ClientTransport = class extends Transport {
1117
1183
  return;
1118
1184
  let session = void 0;
1119
1185
  const handshakeTimeout = setTimeout(() => {
1120
- if (!session) {
1121
- this.log?.warn(
1122
- `connection to ${to} timed out waiting for handshake, closing`,
1123
- { ...conn.loggingMetadata, clientId: this.clientId, connectedTo: to }
1124
- );
1125
- conn.close();
1126
- }
1186
+ if (session)
1187
+ return;
1188
+ this.log?.warn(
1189
+ `connection to ${to} timed out waiting for handshake, closing`,
1190
+ { ...conn.loggingMetadata, clientId: this.clientId, connectedTo: to }
1191
+ );
1192
+ conn.close();
1127
1193
  }, this.options.sessionDisconnectGraceMs);
1128
1194
  const handshakeHandler = (data) => {
1129
1195
  const maybeSession = this.receiveHandshakeResponseMessage(data, conn);
1196
+ clearTimeout(handshakeTimeout);
1130
1197
  if (!maybeSession) {
1131
1198
  conn.close();
1132
1199
  return;
1133
1200
  } else {
1134
1201
  session = maybeSession;
1135
- clearTimeout(handshakeTimeout);
1136
1202
  }
1137
1203
  conn.removeDataListener(handshakeHandler);
1138
1204
  conn.addDataListener((data2) => {
@@ -1239,11 +1305,11 @@ var ClientTransport = class extends Transport {
1239
1305
  connectedTo: parsed.from,
1240
1306
  transportMessage: parsed
1241
1307
  });
1242
- const { session, isReconnect } = this.getOrCreateSession(
1243
- parsed.from,
1308
+ const { session, isReconnect } = this.getOrCreateSession({
1309
+ to: parsed.from,
1244
1310
  conn,
1245
- parsed.payload.status.sessionId
1246
- );
1311
+ sessionId: parsed.payload.status.sessionId
1312
+ });
1247
1313
  this.onConnect(conn, parsed.from, session, isReconnect);
1248
1314
  this.retryBudget.startRestoringBudget(parsed.from);
1249
1315
  return session;
@@ -1349,9 +1415,17 @@ var ClientTransport = class extends Transport {
1349
1415
  }
1350
1416
  }
1351
1417
  }
1352
- deleteSession(session) {
1418
+ deleteSession({
1419
+ session,
1420
+ closeHandshakingConnection,
1421
+ handshakingConn
1422
+ }) {
1353
1423
  this.inflightConnectionPromises.delete(session.to);
1354
- super.deleteSession(session);
1424
+ super.deleteSession({
1425
+ session,
1426
+ closeHandshakingConnection,
1427
+ handshakingConn
1428
+ });
1355
1429
  }
1356
1430
  async sendHandshake(to, conn) {
1357
1431
  let metadata = void 0;
@@ -1378,7 +1452,7 @@ var ClientTransport = class extends Transport {
1378
1452
  return false;
1379
1453
  }
1380
1454
  }
1381
- const { session } = this.getOrCreateSession(to);
1455
+ const { session } = this.getOrCreateSession({ to, handshakingConn: conn });
1382
1456
  const requestMsg = handshakeRequestMessage(
1383
1457
  this.clientId,
1384
1458
  to,