@replit/river 0.214.0 → 0.215.1

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-DjiEwOYi.d.cts → adapter-CjgmjtUJ.d.cts} +3 -2
  2. package/dist/{adapter-Cp7_gIVA.d.ts → adapter-Dtt4bYL-.d.ts} +3 -2
  3. package/dist/{chunk-DRYCLL6N.js → chunk-3DDZCLJM.js} +182 -54
  4. package/dist/chunk-3DDZCLJM.js.map +1 -0
  5. package/dist/{chunk-LECVFB2G.js → chunk-NUGV5QWU.js} +15 -10
  6. package/dist/chunk-NUGV5QWU.js.map +1 -0
  7. package/dist/{client-DXJRow2s.d.cts → client-B9aKi9Li.d.cts} +2 -2
  8. package/dist/{client-Dw0JBBs3.d.ts → client-BOc8blGj.d.ts} +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-1hFoyxuX.d.cts} +3 -3
  14. package/dist/{connection-C2lYgRh0.d.ts → connection-DnMYvolf.d.ts} +3 -3
  15. package/dist/{index-D9R6UTMl.d.cts → index-Bf9PGbS4.d.cts} +1 -1
  16. package/dist/{index-CSM8soK7.d.ts → index-DiAq34gk.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-DL74OqsX.d.cts} +12 -1
  20. package/dist/{message-Dlsh5WDF.d.ts → message-DL74OqsX.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 +11 -11
  24. package/dist/router/index.d.ts +11 -11
  25. package/dist/router/index.js +1 -1
  26. package/dist/{server-BDSYa-CO.d.cts → server-BkEzDYIv.d.cts} +4 -4
  27. package/dist/{server-DFOzjvLh.d.ts → server-_bfE7LYc.d.ts} +4 -4
  28. package/dist/{services-D47_GPCH.d.ts → services-KdKBWdJr.d.ts} +4 -4
  29. package/dist/{services-DqYQvm_L.d.cts → services-zaansuuR.d.cts} +4 -4
  30. package/dist/testUtil/index.cjs +183 -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 +170 -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 +181 -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-pdbkDzmJ.d.ts → transport-CCBNESLA.d.cts} +72 -65
  52. package/dist/{transport-CxT7y8Qk.d.cts → transport-kW92H6x-.d.ts} +72 -65
  53. package/package.json +1 -1
  54. package/dist/chunk-DRYCLL6N.js.map +0 -1
  55. package/dist/chunk-LECVFB2G.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { b as OpaqueTransportMessage } from './message-Dlsh5WDF.cjs';
1
+ import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-DL74OqsX.cjs';
2
2
 
3
3
  /**
4
4
  * Codec interface for encoding and decoding objects to and from Uint8 buffers.
@@ -28,6 +28,7 @@ type SessionApiResult<T> = {
28
28
  };
29
29
  type SendResult = SessionApiResult<string>;
30
30
  type SendBufferResult = SessionApiResult<undefined>;
31
+ type EncodeResult = SessionApiResult<EncodedTransportMessage>;
31
32
  type SerializeResult = SessionApiResult<Uint8Array>;
32
33
  type DeserializeResult = SessionApiResult<OpaqueTransportMessage>;
33
34
 
@@ -43,4 +44,4 @@ declare class CodecMessageAdapter {
43
44
  fromBuffer(buf: Uint8Array): DeserializeResult;
44
45
  }
45
46
 
46
- export { type Codec as C, type SendResult as S, CodecMessageAdapter as a, type SendBufferResult as b };
47
+ export { type Codec as C, type EncodeResult as E, type SendResult as S, CodecMessageAdapter as a, type SendBufferResult as b };
@@ -1,4 +1,4 @@
1
- import { b as OpaqueTransportMessage } from './message-Dlsh5WDF.js';
1
+ import { O as OpaqueTransportMessage, E as EncodedTransportMessage } from './message-DL74OqsX.js';
2
2
 
3
3
  /**
4
4
  * Codec interface for encoding and decoding objects to and from Uint8 buffers.
@@ -28,6 +28,7 @@ type SessionApiResult<T> = {
28
28
  };
29
29
  type SendResult = SessionApiResult<string>;
30
30
  type SendBufferResult = SessionApiResult<undefined>;
31
+ type EncodeResult = SessionApiResult<EncodedTransportMessage>;
31
32
  type SerializeResult = SessionApiResult<Uint8Array>;
32
33
  type DeserializeResult = SessionApiResult<OpaqueTransportMessage>;
33
34
 
@@ -43,4 +44,4 @@ declare class CodecMessageAdapter {
43
44
  fromBuffer(buf: Uint8Array): DeserializeResult;
44
45
  }
45
46
 
46
- export { type Codec as C, type SendResult as S, CodecMessageAdapter as a, type SendBufferResult as b };
47
+ export { type Codec as C, type EncodeResult as E, type SendResult as S, CodecMessageAdapter as a, type SendBufferResult as b };
@@ -20,7 +20,7 @@ import {
20
20
  handshakeResponseMessage,
21
21
  isAcceptedProtocolVersion,
22
22
  isAck
23
- } from "./chunk-LECVFB2G.js";
23
+ } from "./chunk-NUGV5QWU.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;
@@ -1400,6 +1469,10 @@ var LeakyBucketRateLimit = class {
1400
1469
  clearInterval(this.intervalHandle);
1401
1470
  this.intervalHandle = void 0;
1402
1471
  }
1472
+ resetBudget() {
1473
+ this.stopLeak();
1474
+ this.budgetConsumed = 0;
1475
+ }
1403
1476
  close() {
1404
1477
  this.stopLeak();
1405
1478
  }
@@ -1457,6 +1530,17 @@ var ClientTransport = class extends Transport {
1457
1530
  {
1458
1531
  onSessionGracePeriodElapsed: () => {
1459
1532
  this.onSessionGracePeriodElapsed(session);
1533
+ },
1534
+ onMessageSendFailure: (msg, reason) => {
1535
+ this.log?.error(`failed to send message: ${reason}`, {
1536
+ ...session.loggingMetadata,
1537
+ transportMessage: msg
1538
+ });
1539
+ this.protocolError({
1540
+ type: ProtocolError.MessageSendFailure,
1541
+ message: reason
1542
+ });
1543
+ this.deleteSession(session, { unhealthy: true });
1460
1544
  }
1461
1545
  },
1462
1546
  this.options,
@@ -1521,6 +1605,17 @@ var ClientTransport = class extends Transport {
1521
1605
  },
1522
1606
  onSessionGracePeriodElapsed: () => {
1523
1607
  this.onSessionGracePeriodElapsed(handshakingSession);
1608
+ },
1609
+ onMessageSendFailure: (msg, reason) => {
1610
+ this.log?.error(`failed to send message: ${reason}`, {
1611
+ ...handshakingSession.loggingMetadata,
1612
+ transportMessage: msg
1613
+ });
1614
+ this.protocolError({
1615
+ type: ProtocolError.MessageSendFailure,
1616
+ message: reason
1617
+ });
1618
+ this.deleteSession(handshakingSession, { unhealthy: true });
1524
1619
  }
1525
1620
  }
1526
1621
  );
@@ -1682,6 +1777,17 @@ var ClientTransport = class extends Transport {
1682
1777
  },
1683
1778
  onSessionGracePeriodElapsed: () => {
1684
1779
  this.onSessionGracePeriodElapsed(backingOffSession);
1780
+ },
1781
+ onMessageSendFailure: (msg, reason) => {
1782
+ this.log?.error(`failed to send message: ${reason}`, {
1783
+ ...backingOffSession.loggingMetadata,
1784
+ transportMessage: msg
1785
+ });
1786
+ this.protocolError({
1787
+ type: ProtocolError.MessageSendFailure,
1788
+ message: reason
1789
+ });
1790
+ this.deleteSession(backingOffSession, { unhealthy: true });
1685
1791
  }
1686
1792
  }
1687
1793
  );
@@ -1745,6 +1851,17 @@ var ClientTransport = class extends Transport {
1745
1851
  },
1746
1852
  onSessionGracePeriodElapsed: () => {
1747
1853
  this.onSessionGracePeriodElapsed(connectingSession);
1854
+ },
1855
+ onMessageSendFailure: (msg, reason) => {
1856
+ this.log?.error(`failed to send message: ${reason}`, {
1857
+ ...connectingSession.loggingMetadata,
1858
+ transportMessage: msg
1859
+ });
1860
+ this.protocolError({
1861
+ type: ProtocolError.MessageSendFailure,
1862
+ message: reason
1863
+ });
1864
+ this.deleteSession(connectingSession, { unhealthy: true });
1748
1865
  }
1749
1866
  }
1750
1867
  );
@@ -2075,6 +2192,17 @@ var ServerTransport = class extends Transport {
2075
2192
  {
2076
2193
  onSessionGracePeriodElapsed: () => {
2077
2194
  this.onSessionGracePeriodElapsed(noConnectionSession);
2195
+ },
2196
+ onMessageSendFailure: (msg2, reason) => {
2197
+ this.log?.error(`failed to send message: ${reason}`, {
2198
+ ...noConnectionSession.loggingMetadata,
2199
+ transportMessage: msg2
2200
+ });
2201
+ this.protocolError({
2202
+ type: ProtocolError.MessageSendFailure,
2203
+ message: reason
2204
+ });
2205
+ this.deleteSession(noConnectionSession, { unhealthy: true });
2078
2206
  }
2079
2207
  }
2080
2208
  );
@@ -2345,4 +2473,4 @@ export {
2345
2473
  WebSocketConnection,
2346
2474
  CodecMessageAdapter
2347
2475
  };
2348
- //# sourceMappingURL=chunk-DRYCLL6N.js.map
2476
+ //# sourceMappingURL=chunk-3DDZCLJM.js.map