@replit/river 0.214.0 → 0.215.0

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 (55) hide show
  1. package/dist/{adapter-Cp7_gIVA.d.ts → adapter-CgF7vQPu.d.ts} +3 -2
  2. package/dist/{adapter-DjiEwOYi.d.cts → adapter-IGrG4KLL.d.cts} +3 -2
  3. package/dist/{chunk-LECVFB2G.js → chunk-RDTQZ7HO.js} +15 -10
  4. package/dist/chunk-RDTQZ7HO.js.map +1 -0
  5. package/dist/{chunk-DRYCLL6N.js → chunk-VXRAFUA3.js} +178 -54
  6. package/dist/chunk-VXRAFUA3.js.map +1 -0
  7. package/dist/{client-Dw0JBBs3.d.ts → client-BhwlY0-L.d.ts} +2 -2
  8. package/dist/{client-DXJRow2s.d.cts → client-Dk4H7qeg.d.cts} +2 -2
  9. package/dist/codec/index.cjs.map +1 -1
  10. package/dist/codec/index.d.cts +3 -3
  11. package/dist/codec/index.d.ts +3 -3
  12. package/dist/codec/index.js +2 -2
  13. package/dist/{connection-Dzkqj18h.d.cts → connection-CS00EWuS.d.cts} +3 -3
  14. package/dist/{connection-C2lYgRh0.d.ts → connection-DU9v3y8a.d.ts} +3 -3
  15. package/dist/{index-D9R6UTMl.d.cts → index-CHCzvZ9D.d.cts} +1 -1
  16. package/dist/{index-CSM8soK7.d.ts → index-uF0cBM7z.d.ts} +1 -1
  17. package/dist/logging/index.d.cts +2 -2
  18. package/dist/logging/index.d.ts +2 -2
  19. package/dist/{message-Dlsh5WDF.d.cts → message-aABg0s5M.d.cts} +12 -1
  20. package/dist/{message-Dlsh5WDF.d.ts → message-aABg0s5M.d.ts} +12 -1
  21. package/dist/router/index.cjs +14 -9
  22. package/dist/router/index.cjs.map +1 -1
  23. package/dist/router/index.d.cts +10 -10
  24. package/dist/router/index.d.ts +10 -10
  25. package/dist/router/index.js +1 -1
  26. package/dist/{server-BDSYa-CO.d.cts → server-BR0DZaWi.d.cts} +4 -4
  27. package/dist/{server-DFOzjvLh.d.ts → server-uNzkzIRh.d.ts} +4 -4
  28. package/dist/{services-D47_GPCH.d.ts → services-B5SY771g.d.ts} +3 -3
  29. package/dist/{services-DqYQvm_L.d.cts → services-DBv2nmly.d.cts} +3 -3
  30. package/dist/testUtil/index.cjs +179 -53
  31. package/dist/testUtil/index.cjs.map +1 -1
  32. package/dist/testUtil/index.d.cts +7 -7
  33. package/dist/testUtil/index.d.ts +7 -7
  34. package/dist/testUtil/index.js +4 -2
  35. package/dist/testUtil/index.js.map +1 -1
  36. package/dist/transport/impls/ws/client.cjs +166 -53
  37. package/dist/transport/impls/ws/client.cjs.map +1 -1
  38. package/dist/transport/impls/ws/client.d.cts +6 -6
  39. package/dist/transport/impls/ws/client.d.ts +6 -6
  40. package/dist/transport/impls/ws/client.js +2 -2
  41. package/dist/transport/impls/ws/server.cjs +133 -53
  42. package/dist/transport/impls/ws/server.cjs.map +1 -1
  43. package/dist/transport/impls/ws/server.d.cts +6 -6
  44. package/dist/transport/impls/ws/server.d.ts +6 -6
  45. package/dist/transport/impls/ws/server.js +2 -2
  46. package/dist/transport/index.cjs +177 -53
  47. package/dist/transport/index.cjs.map +1 -1
  48. package/dist/transport/index.d.cts +7 -7
  49. package/dist/transport/index.d.ts +7 -7
  50. package/dist/transport/index.js +2 -2
  51. package/dist/{transport-CxT7y8Qk.d.cts → transport-BOL2p5s-.d.ts} +70 -64
  52. package/dist/{transport-pdbkDzmJ.d.ts → transport-D3jzhFSi.d.cts} +70 -64
  53. package/package.json +1 -1
  54. package/dist/chunk-DRYCLL6N.js.map +0 -1
  55. package/dist/chunk-LECVFB2G.js.map +0 -1
@@ -20,7 +20,7 @@ import {
20
20
  handshakeResponseMessage,
21
21
  isAcceptedProtocolVersion,
22
22
  isAck
23
- } from "./chunk-LECVFB2G.js";
23
+ } from "./chunk-RDTQZ7HO.js";
24
24
 
25
25
  // transport/events.ts
26
26
  var ProtocolError = {
@@ -226,6 +226,7 @@ var IdentifiedSession = class extends CommonSession {
226
226
  telemetry;
227
227
  to;
228
228
  protocolVersion;
229
+ listeners;
229
230
  /**
230
231
  * Index of the message we will send next (excluding handshake)
231
232
  */
@@ -249,7 +250,8 @@ var IdentifiedSession = class extends CommonSession {
249
250
  telemetry,
250
251
  log,
251
252
  protocolVersion,
252
- seqSent: messagesSent
253
+ seqSent: messagesSent,
254
+ listeners
253
255
  } = props;
254
256
  super(props);
255
257
  this.id = id;
@@ -261,6 +263,7 @@ var IdentifiedSession = class extends CommonSession {
261
263
  this.log = log;
262
264
  this.protocolVersion = protocolVersion;
263
265
  this.seqSent = messagesSent;
266
+ this.listeners = listeners;
264
267
  }
265
268
  get loggingMetadata() {
266
269
  const metadata = {
@@ -277,7 +280,7 @@ var IdentifiedSession = class extends CommonSession {
277
280
  }
278
281
  return metadata;
279
282
  }
280
- constructMsg(partialMsg) {
283
+ encodeMsg(partialMsg) {
281
284
  const msg = {
282
285
  ...partialMsg,
283
286
  id: generateId(),
@@ -286,18 +289,37 @@ var IdentifiedSession = class extends CommonSession {
286
289
  seq: this.seq,
287
290
  ack: this.ack
288
291
  };
292
+ const encoded = this.codec.toBuffer(msg);
293
+ if (!encoded.ok) {
294
+ this.listeners.onMessageSendFailure(
295
+ { ...partialMsg, seq: this.seq },
296
+ encoded.reason
297
+ );
298
+ return encoded;
299
+ }
289
300
  this.seq++;
290
- return msg;
301
+ return {
302
+ ok: true,
303
+ value: {
304
+ id: msg.id,
305
+ seq: msg.seq,
306
+ msg: partialMsg,
307
+ data: encoded.value
308
+ }
309
+ };
291
310
  }
292
311
  nextSeq() {
293
312
  return this.sendBuffer.length > 0 ? this.sendBuffer[0].seq : this.seq;
294
313
  }
295
314
  send(msg) {
296
- const constructedMsg = this.constructMsg(msg);
297
- this.sendBuffer.push(constructedMsg);
315
+ const encodeResult = this.encodeMsg(msg);
316
+ if (!encodeResult.ok) {
317
+ return encodeResult;
318
+ }
319
+ this.sendBuffer.push(encodeResult.value);
298
320
  return {
299
321
  ok: true,
300
- value: constructedMsg.id
322
+ value: encodeResult.value.id
301
323
  };
302
324
  }
303
325
  _handleStateExit() {
@@ -330,23 +352,6 @@ var IdentifiedSessionWithGracePeriod = class extends IdentifiedSession {
330
352
  super._handleClose();
331
353
  }
332
354
  };
333
- function sendMessage(conn, codec, msg) {
334
- const buff = codec.toBuffer(msg);
335
- if (!buff.ok) {
336
- return buff;
337
- }
338
- const sent = conn.send(buff.value);
339
- if (!sent) {
340
- return {
341
- ok: false,
342
- reason: "failed to send message"
343
- };
344
- }
345
- return {
346
- ok: true,
347
- value: msg.id
348
- };
349
- }
350
355
 
351
356
  // transport/sessionStateMachine/SessionConnecting.ts
352
357
  var SessionConnecting = class extends IdentifiedSessionWithGracePeriod {
@@ -449,7 +454,21 @@ var SessionWaitingForHandshake = class extends CommonSession {
449
454
  this.listeners.onHandshake(parsedMsgRes.value);
450
455
  };
451
456
  sendHandshake(msg) {
452
- return sendMessage(this.conn, this.codec, msg);
457
+ const buff = this.codec.toBuffer(msg);
458
+ if (!buff.ok) {
459
+ return buff;
460
+ }
461
+ const sent = this.conn.send(buff.value);
462
+ if (!sent) {
463
+ return {
464
+ ok: false,
465
+ reason: "failed to send handshake"
466
+ };
467
+ }
468
+ return {
469
+ ok: true,
470
+ value: msg.id
471
+ };
453
472
  }
454
473
  _handleStateExit() {
455
474
  this.conn.removeDataListener();
@@ -498,7 +517,21 @@ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
498
517
  this.listeners.onHandshake(parsedMsgRes.value);
499
518
  };
500
519
  sendHandshake(msg) {
501
- return sendMessage(this.conn, this.codec, msg);
520
+ const buff = this.codec.toBuffer(msg);
521
+ if (!buff.ok) {
522
+ return buff;
523
+ }
524
+ const sent = this.conn.send(buff.value);
525
+ if (!sent) {
526
+ return {
527
+ ok: false,
528
+ reason: "failed to send handshake"
529
+ };
530
+ }
531
+ return {
532
+ ok: true,
533
+ value: msg.id
534
+ };
502
535
  }
503
536
  _handleStateExit() {
504
537
  super._handleStateExit();
@@ -533,28 +566,35 @@ var SessionConnected = class extends IdentifiedSession {
533
566
  }
534
567
  this.startMissingHeartbeatTimeout();
535
568
  }
536
- assertSendOrdering(constructedMsg) {
537
- if (constructedMsg.seq > this.seqSent + 1) {
538
- const msg = `invariant violation: would have sent out of order msg (seq: ${constructedMsg.seq}, expected: ${this.seqSent} + 1)`;
569
+ assertSendOrdering(encodedMsg) {
570
+ if (encodedMsg.seq > this.seqSent + 1) {
571
+ const msg = `invariant violation: would have sent out of order msg (seq: ${encodedMsg.seq}, expected: ${this.seqSent} + 1)`;
539
572
  this.log?.error(msg, {
540
573
  ...this.loggingMetadata,
541
- transportMessage: constructedMsg,
542
574
  tags: ["invariant-violation"]
543
575
  });
544
576
  throw new Error(msg);
545
577
  }
546
578
  }
547
579
  send(msg) {
548
- const constructedMsg = this.constructMsg(msg);
549
- this.assertSendOrdering(constructedMsg);
550
- this.sendBuffer.push(constructedMsg);
551
- const res = sendMessage(this.conn, this.codec, constructedMsg);
552
- if (!res.ok) {
553
- this.listeners.onMessageSendFailure(constructedMsg, res.reason);
554
- return res;
580
+ const encodeResult = this.encodeMsg(msg);
581
+ if (!encodeResult.ok) {
582
+ return encodeResult;
583
+ }
584
+ const encodedMsg = encodeResult.value;
585
+ this.assertSendOrdering(encodedMsg);
586
+ this.sendBuffer.push(encodedMsg);
587
+ const sent = this.conn.send(encodedMsg.data);
588
+ if (!sent) {
589
+ const reason = "failed to send message";
590
+ this.listeners.onMessageSendFailure(
591
+ { ...encodedMsg.msg, seq: encodedMsg.seq },
592
+ reason
593
+ );
594
+ return { ok: false, reason };
555
595
  }
556
- this.seqSent = constructedMsg.seq;
557
- return res;
596
+ this.seqSent = encodedMsg.seq;
597
+ return { ok: true, value: encodedMsg.id };
558
598
  }
559
599
  constructor(props) {
560
600
  super(props);
@@ -572,10 +612,14 @@ var SessionConnected = class extends IdentifiedSession {
572
612
  );
573
613
  for (const msg of this.sendBuffer) {
574
614
  this.assertSendOrdering(msg);
575
- const res = sendMessage(this.conn, this.codec, msg);
576
- if (!res.ok) {
577
- this.listeners.onMessageSendFailure(msg, res.reason);
578
- return res;
615
+ const sent = this.conn.send(msg.data);
616
+ if (!sent) {
617
+ const reason = "failed to send buffered message";
618
+ this.listeners.onMessageSendFailure(
619
+ { ...msg.msg, seq: msg.seq },
620
+ reason
621
+ );
622
+ return { ok: false, reason };
579
623
  }
580
624
  this.seqSent = msg.seq;
581
625
  }
@@ -1278,6 +1322,17 @@ var Transport = class {
1278
1322
  const noConnectionSession = SessionStateGraph.transition.ConnectingToNoConnection(session, {
1279
1323
  onSessionGracePeriodElapsed: () => {
1280
1324
  this.onSessionGracePeriodElapsed(noConnectionSession);
1325
+ },
1326
+ onMessageSendFailure: (msg, reason) => {
1327
+ this.log?.error(`failed to send message: ${reason}`, {
1328
+ ...noConnectionSession.loggingMetadata,
1329
+ transportMessage: msg
1330
+ });
1331
+ this.protocolError({
1332
+ type: ProtocolError.MessageSendFailure,
1333
+ message: reason
1334
+ });
1335
+ this.deleteSession(noConnectionSession, { unhealthy: true });
1281
1336
  }
1282
1337
  });
1283
1338
  this.updateSession(noConnectionSession);
@@ -1285,18 +1340,32 @@ var Transport = class {
1285
1340
  }
1286
1341
  onConnClosed(session) {
1287
1342
  let noConnectionSession;
1343
+ const listeners = {
1344
+ onSessionGracePeriodElapsed: () => {
1345
+ this.onSessionGracePeriodElapsed(noConnectionSession);
1346
+ },
1347
+ onMessageSendFailure: (msg, reason) => {
1348
+ this.log?.error(`failed to send message: ${reason}`, {
1349
+ ...noConnectionSession.loggingMetadata,
1350
+ transportMessage: msg
1351
+ });
1352
+ this.protocolError({
1353
+ type: ProtocolError.MessageSendFailure,
1354
+ message: reason
1355
+ });
1356
+ this.deleteSession(noConnectionSession, { unhealthy: true });
1357
+ }
1358
+ };
1288
1359
  if (session.state === "Handshaking" /* Handshaking */) {
1289
- noConnectionSession = SessionStateGraph.transition.HandshakingToNoConnection(session, {
1290
- onSessionGracePeriodElapsed: () => {
1291
- this.onSessionGracePeriodElapsed(noConnectionSession);
1292
- }
1293
- });
1360
+ noConnectionSession = SessionStateGraph.transition.HandshakingToNoConnection(
1361
+ session,
1362
+ listeners
1363
+ );
1294
1364
  } else {
1295
- noConnectionSession = SessionStateGraph.transition.ConnectedToNoConnection(session, {
1296
- onSessionGracePeriodElapsed: () => {
1297
- this.onSessionGracePeriodElapsed(noConnectionSession);
1298
- }
1299
- });
1365
+ noConnectionSession = SessionStateGraph.transition.ConnectedToNoConnection(
1366
+ session,
1367
+ listeners
1368
+ );
1300
1369
  }
1301
1370
  this.updateSession(noConnectionSession);
1302
1371
  return noConnectionSession;
@@ -1457,6 +1526,17 @@ var ClientTransport = class extends Transport {
1457
1526
  {
1458
1527
  onSessionGracePeriodElapsed: () => {
1459
1528
  this.onSessionGracePeriodElapsed(session);
1529
+ },
1530
+ onMessageSendFailure: (msg, reason) => {
1531
+ this.log?.error(`failed to send message: ${reason}`, {
1532
+ ...session.loggingMetadata,
1533
+ transportMessage: msg
1534
+ });
1535
+ this.protocolError({
1536
+ type: ProtocolError.MessageSendFailure,
1537
+ message: reason
1538
+ });
1539
+ this.deleteSession(session, { unhealthy: true });
1460
1540
  }
1461
1541
  },
1462
1542
  this.options,
@@ -1521,6 +1601,17 @@ var ClientTransport = class extends Transport {
1521
1601
  },
1522
1602
  onSessionGracePeriodElapsed: () => {
1523
1603
  this.onSessionGracePeriodElapsed(handshakingSession);
1604
+ },
1605
+ onMessageSendFailure: (msg, reason) => {
1606
+ this.log?.error(`failed to send message: ${reason}`, {
1607
+ ...handshakingSession.loggingMetadata,
1608
+ transportMessage: msg
1609
+ });
1610
+ this.protocolError({
1611
+ type: ProtocolError.MessageSendFailure,
1612
+ message: reason
1613
+ });
1614
+ this.deleteSession(handshakingSession, { unhealthy: true });
1524
1615
  }
1525
1616
  }
1526
1617
  );
@@ -1682,6 +1773,17 @@ var ClientTransport = class extends Transport {
1682
1773
  },
1683
1774
  onSessionGracePeriodElapsed: () => {
1684
1775
  this.onSessionGracePeriodElapsed(backingOffSession);
1776
+ },
1777
+ onMessageSendFailure: (msg, reason) => {
1778
+ this.log?.error(`failed to send message: ${reason}`, {
1779
+ ...backingOffSession.loggingMetadata,
1780
+ transportMessage: msg
1781
+ });
1782
+ this.protocolError({
1783
+ type: ProtocolError.MessageSendFailure,
1784
+ message: reason
1785
+ });
1786
+ this.deleteSession(backingOffSession, { unhealthy: true });
1685
1787
  }
1686
1788
  }
1687
1789
  );
@@ -1745,6 +1847,17 @@ var ClientTransport = class extends Transport {
1745
1847
  },
1746
1848
  onSessionGracePeriodElapsed: () => {
1747
1849
  this.onSessionGracePeriodElapsed(connectingSession);
1850
+ },
1851
+ onMessageSendFailure: (msg, reason) => {
1852
+ this.log?.error(`failed to send message: ${reason}`, {
1853
+ ...connectingSession.loggingMetadata,
1854
+ transportMessage: msg
1855
+ });
1856
+ this.protocolError({
1857
+ type: ProtocolError.MessageSendFailure,
1858
+ message: reason
1859
+ });
1860
+ this.deleteSession(connectingSession, { unhealthy: true });
1748
1861
  }
1749
1862
  }
1750
1863
  );
@@ -2075,6 +2188,17 @@ var ServerTransport = class extends Transport {
2075
2188
  {
2076
2189
  onSessionGracePeriodElapsed: () => {
2077
2190
  this.onSessionGracePeriodElapsed(noConnectionSession);
2191
+ },
2192
+ onMessageSendFailure: (msg2, reason) => {
2193
+ this.log?.error(`failed to send message: ${reason}`, {
2194
+ ...noConnectionSession.loggingMetadata,
2195
+ transportMessage: msg2
2196
+ });
2197
+ this.protocolError({
2198
+ type: ProtocolError.MessageSendFailure,
2199
+ message: reason
2200
+ });
2201
+ this.deleteSession(noConnectionSession, { unhealthy: true });
2078
2202
  }
2079
2203
  }
2080
2204
  );
@@ -2345,4 +2469,4 @@ export {
2345
2469
  WebSocketConnection,
2346
2470
  CodecMessageAdapter
2347
2471
  };
2348
- //# sourceMappingURL=chunk-DRYCLL6N.js.map
2472
+ //# sourceMappingURL=chunk-VXRAFUA3.js.map