@replit/river 0.202.0 → 0.203.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 (50) hide show
  1. package/dist/{chunk-BDUOHZMF.js → chunk-2FHJVQBE.js} +2 -2
  2. package/dist/{chunk-2T22KY5X.js → chunk-7MKTFUJO.js} +3 -3
  3. package/dist/{chunk-QMXUCLGE.js → chunk-AK7NTFAM.js} +31 -10
  4. package/dist/{chunk-QMXUCLGE.js.map → chunk-AK7NTFAM.js.map} +1 -1
  5. package/dist/{chunk-NSH4D6OB.js → chunk-T4WWG42M.js} +13 -3
  6. package/dist/chunk-T4WWG42M.js.map +1 -0
  7. package/dist/{chunk-W4AGHFXK.js → chunk-TMOCPK63.js} +18 -8
  8. package/dist/chunk-TMOCPK63.js.map +1 -0
  9. package/dist/{chunk-LHH5LQ7C.js → chunk-WBGKPIFS.js} +11 -1
  10. package/dist/chunk-WBGKPIFS.js.map +1 -0
  11. package/dist/{client-a32692b0.d.ts → client-5d2e41a3.d.ts} +7 -1
  12. package/dist/{connection-48d021ca.d.ts → connection-11a4af0f.d.ts} +1 -1
  13. package/dist/{context-8d263a7f.d.ts → context-d6dd8a1a.d.ts} +14 -0
  14. package/dist/logging/index.cjs +1 -0
  15. package/dist/logging/index.cjs.map +1 -1
  16. package/dist/logging/index.js +1 -1
  17. package/dist/router/index.cjs +91 -103
  18. package/dist/router/index.cjs.map +1 -1
  19. package/dist/router/index.d.cts +7 -7
  20. package/dist/router/index.d.ts +7 -7
  21. package/dist/router/index.js +78 -95
  22. package/dist/router/index.js.map +1 -1
  23. package/dist/{server-48d90a77.d.ts → server-e46399f9.d.ts} +1 -1
  24. package/dist/{services-a05f5174.d.ts → services-56cbea0d.d.ts} +2 -2
  25. package/dist/testUtil/index.cjs +55 -11
  26. package/dist/testUtil/index.cjs.map +1 -1
  27. package/dist/testUtil/index.d.cts +5 -5
  28. package/dist/testUtil/index.d.ts +5 -5
  29. package/dist/testUtil/index.js +5 -5
  30. package/dist/transport/impls/ws/client.cjs +60 -16
  31. package/dist/transport/impls/ws/client.cjs.map +1 -1
  32. package/dist/transport/impls/ws/client.d.cts +3 -3
  33. package/dist/transport/impls/ws/client.d.ts +3 -3
  34. package/dist/transport/impls/ws/client.js +5 -5
  35. package/dist/transport/impls/ws/server.cjs +48 -14
  36. package/dist/transport/impls/ws/server.cjs.map +1 -1
  37. package/dist/transport/impls/ws/server.d.cts +3 -3
  38. package/dist/transport/impls/ws/server.d.ts +3 -3
  39. package/dist/transport/impls/ws/server.js +5 -5
  40. package/dist/transport/index.cjs +62 -18
  41. package/dist/transport/index.cjs.map +1 -1
  42. package/dist/transport/index.d.cts +4 -4
  43. package/dist/transport/index.d.ts +4 -4
  44. package/dist/transport/index.js +5 -5
  45. package/package.json +2 -2
  46. package/dist/chunk-LHH5LQ7C.js.map +0 -1
  47. package/dist/chunk-NSH4D6OB.js.map +0 -1
  48. package/dist/chunk-W4AGHFXK.js.map +0 -1
  49. /package/dist/{chunk-BDUOHZMF.js.map → chunk-2FHJVQBE.js.map} +0 -0
  50. /package/dist/{chunk-2T22KY5X.js.map → chunk-7MKTFUJO.js.map} +0 -0
@@ -1,7 +1,7 @@
1
- import { C as ClientTransport } from '../../../client-a32692b0.js';
1
+ import { C as ClientTransport } from '../../../client-5d2e41a3.js';
2
2
  import { c as TransportClientId } from '../../../message-3def9ded.js';
3
- import { b as ProvidedClientTransportOptions } from '../../../context-8d263a7f.js';
4
- import { W as WebSocketConnection } from '../../../connection-48d021ca.js';
3
+ import { b as ProvidedClientTransportOptions } from '../../../context-d6dd8a1a.js';
4
+ import { W as WebSocketConnection } from '../../../connection-11a4af0f.js';
5
5
  import { W as WsLike } from '../../../wslike-e0b32dd5.js';
6
6
  import '@sinclair/typebox/value';
7
7
  import '@sinclair/typebox';
@@ -1,7 +1,7 @@
1
- import { C as ClientTransport } from '../../../client-a32692b0.js';
1
+ import { C as ClientTransport } from '../../../client-5d2e41a3.js';
2
2
  import { c as TransportClientId } from '../../../message-3def9ded.js';
3
- import { b as ProvidedClientTransportOptions } from '../../../context-8d263a7f.js';
4
- import { W as WebSocketConnection } from '../../../connection-48d021ca.js';
3
+ import { b as ProvidedClientTransportOptions } from '../../../context-d6dd8a1a.js';
4
+ import { W as WebSocketConnection } from '../../../connection-11a4af0f.js';
5
5
  import { W as WsLike } from '../../../wslike-e0b32dd5.js';
6
6
  import '@sinclair/typebox/value';
7
7
  import '@sinclair/typebox';
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  ClientTransport
3
- } from "../../../chunk-NSH4D6OB.js";
3
+ } from "../../../chunk-T4WWG42M.js";
4
4
  import {
5
5
  WebSocketConnection
6
- } from "../../../chunk-BDUOHZMF.js";
7
- import "../../../chunk-W4AGHFXK.js";
8
- import "../../../chunk-QMXUCLGE.js";
9
- import "../../../chunk-LHH5LQ7C.js";
6
+ } from "../../../chunk-2FHJVQBE.js";
7
+ import "../../../chunk-TMOCPK63.js";
8
+ import "../../../chunk-AK7NTFAM.js";
9
+ import "../../../chunk-WBGKPIFS.js";
10
10
  import "../../../chunk-AJGIY2UB.js";
11
11
 
12
12
  // transport/impls/ws/client.ts
@@ -40,8 +40,8 @@ var Connection = class {
40
40
  }
41
41
  get loggingMetadata() {
42
42
  const metadata = { connId: this.id };
43
- const spanContext = this.telemetry?.span.spanContext();
44
- if (this.telemetry?.span.isRecording() && spanContext) {
43
+ if (this.telemetry?.span.isRecording()) {
44
+ const spanContext = this.telemetry.span.spanContext();
45
45
  metadata.telemetry = {
46
46
  traceId: spanContext.traceId,
47
47
  spanId: spanContext.spanId
@@ -155,7 +155,7 @@ var WebSocketConnection = class extends Connection {
155
155
  };
156
156
 
157
157
  // transport/server.ts
158
- var import_api3 = require("@opentelemetry/api");
158
+ var import_api4 = require("@opentelemetry/api");
159
159
 
160
160
  // transport/message.ts
161
161
  var import_typebox = require("@sinclair/typebox");
@@ -350,6 +350,7 @@ var defaultServerTransportOptions = {
350
350
  };
351
351
 
352
352
  // logging/log.ts
353
+ var import_api = require("@opentelemetry/api");
353
354
  var LoggingLevels = {
354
355
  debug: -1,
355
356
  info: 0,
@@ -358,6 +359,15 @@ var LoggingLevels = {
358
359
  };
359
360
  var cleanedLogFn = (log) => {
360
361
  return (msg, metadata) => {
362
+ if (metadata && !metadata.telemetry) {
363
+ const span = import_api.trace.getSpan(import_api.context.active());
364
+ if (span) {
365
+ metadata.telemetry = {
366
+ traceId: span.spanContext().traceId,
367
+ spanId: span.spanContext().spanId
368
+ };
369
+ }
370
+ }
361
371
  if (!metadata?.transportMessage) {
362
372
  log(msg, metadata);
363
373
  return;
@@ -449,6 +459,14 @@ var StateMachineState = class {
449
459
  * and we've moved on to another state
450
460
  */
451
461
  _isConsumed;
462
+ /**
463
+ * Cleanup this state machine state and mark it as consumed.
464
+ * After calling close, it is an error to access any properties on the state.
465
+ * You should never need to call this as a consumer.
466
+ *
467
+ * If you're looking to close the session from the client,
468
+ * use `.hardDisconnect` on the client transport.
469
+ */
452
470
  close() {
453
471
  this._handleClose();
454
472
  }
@@ -503,9 +521,8 @@ var CommonSession = class extends StateMachineState {
503
521
  parseMsg(msg) {
504
522
  const parsedMsg = this.options.codec.fromBuffer(msg);
505
523
  if (parsedMsg === null) {
506
- const decodedBuffer = new TextDecoder().decode(Buffer.from(msg));
507
524
  this.log?.error(
508
- `received malformed msg: ${decodedBuffer}`,
525
+ `received malformed msg: ${Buffer.from(msg).toString("base64")}`,
509
526
  this.loggingMetadata
510
527
  );
511
528
  return null;
@@ -549,13 +566,13 @@ var IdentifiedSession = class extends CommonSession {
549
566
  this.protocolVersion = protocolVersion;
550
567
  }
551
568
  get loggingMetadata() {
552
- const spanContext = this.telemetry.span.spanContext();
553
569
  const metadata = {
554
570
  clientId: this.from,
555
571
  connectedTo: this.to,
556
572
  sessionId: this.id
557
573
  };
558
574
  if (this.telemetry.span.isRecording()) {
575
+ const spanContext = this.telemetry.span.spanContext();
559
576
  metadata.telemetry = {
560
577
  traceId: spanContext.traceId,
561
578
  spanId: spanContext.spanId
@@ -682,14 +699,14 @@ var SessionNoConnection = class extends IdentifiedSessionWithGracePeriod {
682
699
  };
683
700
 
684
701
  // tracing/index.ts
685
- var import_api = require("@opentelemetry/api");
702
+ var import_api2 = require("@opentelemetry/api");
686
703
 
687
704
  // package.json
688
- var version = "0.202.0";
705
+ var version = "0.203.1";
689
706
 
690
707
  // tracing/index.ts
691
708
  function createSessionTelemetryInfo(sessionId, to, from, propagationCtx) {
692
- const parentCtx = propagationCtx ? import_api.propagation.extract(import_api.context.active(), propagationCtx) : import_api.context.active();
709
+ const parentCtx = propagationCtx ? import_api2.propagation.extract(import_api2.context.active(), propagationCtx) : import_api2.context.active();
693
710
  const span = tracer.startSpan(
694
711
  `session ${sessionId}`,
695
712
  {
@@ -702,10 +719,25 @@ function createSessionTelemetryInfo(sessionId, to, from, propagationCtx) {
702
719
  },
703
720
  parentCtx
704
721
  );
705
- const ctx = import_api.trace.setSpan(parentCtx, span);
722
+ const ctx = import_api2.trace.setSpan(parentCtx, span);
723
+ return { span, ctx };
724
+ }
725
+ function createConnectionTelemetryInfo(connection, info) {
726
+ const span = tracer.startSpan(
727
+ `connection ${connection.id}`,
728
+ {
729
+ attributes: {
730
+ component: "river",
731
+ "river.connection.id": connection.id
732
+ },
733
+ links: [{ context: info.span.spanContext() }]
734
+ },
735
+ info.ctx
736
+ );
737
+ const ctx = import_api2.trace.setSpan(info.ctx, span);
706
738
  return { span, ctx };
707
739
  }
708
- var tracer = import_api.trace.getTracer("river", version);
740
+ var tracer = import_api2.trace.getTracer("river", version);
709
741
 
710
742
  // transport/sessionStateMachine/SessionWaitingForHandshake.ts
711
743
  var SessionWaitingForHandshake = class extends CommonSession {
@@ -811,7 +843,7 @@ var SessionHandshaking = class extends IdentifiedSessionWithGracePeriod {
811
843
  };
812
844
 
813
845
  // transport/sessionStateMachine/SessionConnected.ts
814
- var import_api2 = require("@opentelemetry/api");
846
+ var import_api3 = require("@opentelemetry/api");
815
847
  var SessionConnected = class extends IdentifiedSession {
816
848
  state = "Connected" /* Connected */;
817
849
  conn;
@@ -915,7 +947,7 @@ var SessionConnected = class extends IdentifiedSession {
915
947
  tags: ["invariant-violation"]
916
948
  });
917
949
  this.telemetry.span.setStatus({
918
- code: import_api2.SpanStatusCode.ERROR,
950
+ code: import_api3.SpanStatusCode.ERROR,
919
951
  message: reason
920
952
  });
921
953
  this.closeConnection();
@@ -1087,6 +1119,7 @@ var SessionStateGraph = {
1087
1119
  listeners,
1088
1120
  ...carriedState
1089
1121
  });
1122
+ conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
1090
1123
  session.log?.info(
1091
1124
  `session ${session.id} transition from Connecting to Handshaking`,
1092
1125
  {
@@ -1147,6 +1180,7 @@ var SessionStateGraph = {
1147
1180
  listeners,
1148
1181
  ...carriedState
1149
1182
  });
1183
+ conn.telemetry = createConnectionTelemetryInfo(conn, session.telemetry);
1150
1184
  session.log?.info(
1151
1185
  `session ${session.id} transition from WaitingForHandshake to Connected`,
1152
1186
  {
@@ -1603,7 +1637,7 @@ var ServerTransport = class extends Transport {
1603
1637
  }
1604
1638
  rejectHandshakeRequest(session, to, reason, code, metadata) {
1605
1639
  session.conn.telemetry?.span.setStatus({
1606
- code: import_api3.SpanStatusCode.ERROR,
1640
+ code: import_api4.SpanStatusCode.ERROR,
1607
1641
  message: reason
1608
1642
  });
1609
1643
  this.log?.warn(reason, metadata);