@replit/river 0.19.3 → 0.20.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 (56) hide show
  1. package/dist/{chunk-2Z2NE47H.js → chunk-5WFL722S.js} +15 -2
  2. package/dist/chunk-5WFL722S.js.map +1 -0
  3. package/dist/{chunk-LDCCELCJ.js → chunk-HGBAUTIW.js} +2 -2
  4. package/dist/{chunk-QZD2UTDJ.js → chunk-NYOK5VKK.js} +383 -245
  5. package/dist/chunk-NYOK5VKK.js.map +1 -0
  6. package/dist/{chunk-SLYSDRLE.js → chunk-YB5LRYL6.js} +517 -260
  7. package/dist/chunk-YB5LRYL6.js.map +1 -0
  8. package/dist/{chunk-YHKIWQOC.js → chunk-ZIWOHAQM.js} +2 -2
  9. package/dist/{connection-cfec12e6.d.ts → connection-d49d5d56.d.ts} +1 -1
  10. package/dist/{connection-aa0ea000.d.ts → connection-dba95bc8.d.ts} +1 -1
  11. package/dist/{index-e2513701.d.ts → index-3ac92295.d.ts} +12 -0
  12. package/dist/logging/index.d.cts +1 -1
  13. package/dist/logging/index.d.ts +1 -1
  14. package/dist/router/index.cjs +514 -257
  15. package/dist/router/index.cjs.map +1 -1
  16. package/dist/router/index.d.cts +4 -4
  17. package/dist/router/index.d.ts +4 -4
  18. package/dist/router/index.js +2 -2
  19. package/dist/{services-5fc5712d.d.ts → services-8496d6e8.d.ts} +1 -1
  20. package/dist/{services-4bba42d8.d.ts → services-abc077db.d.ts} +1 -1
  21. package/dist/transport/impls/uds/client.cjs +150 -74
  22. package/dist/transport/impls/uds/client.cjs.map +1 -1
  23. package/dist/transport/impls/uds/client.d.cts +2 -2
  24. package/dist/transport/impls/uds/client.d.ts +2 -2
  25. package/dist/transport/impls/uds/client.js +3 -3
  26. package/dist/transport/impls/uds/server.cjs +249 -169
  27. package/dist/transport/impls/uds/server.cjs.map +1 -1
  28. package/dist/transport/impls/uds/server.d.cts +2 -2
  29. package/dist/transport/impls/uds/server.d.ts +2 -2
  30. package/dist/transport/impls/uds/server.js +3 -3
  31. package/dist/transport/impls/ws/client.cjs +150 -74
  32. package/dist/transport/impls/ws/client.cjs.map +1 -1
  33. package/dist/transport/impls/ws/client.d.cts +2 -2
  34. package/dist/transport/impls/ws/client.d.ts +2 -2
  35. package/dist/transport/impls/ws/client.js +3 -3
  36. package/dist/transport/impls/ws/server.cjs +249 -169
  37. package/dist/transport/impls/ws/server.cjs.map +1 -1
  38. package/dist/transport/impls/ws/server.d.cts +2 -2
  39. package/dist/transport/impls/ws/server.d.ts +2 -2
  40. package/dist/transport/impls/ws/server.js +3 -3
  41. package/dist/transport/index.cjs +387 -243
  42. package/dist/transport/index.cjs.map +1 -1
  43. package/dist/transport/index.d.cts +3 -2
  44. package/dist/transport/index.d.ts +3 -2
  45. package/dist/transport/index.js +2 -2
  46. package/dist/util/testHelpers.cjs +1 -0
  47. package/dist/util/testHelpers.cjs.map +1 -1
  48. package/dist/util/testHelpers.d.cts +2 -2
  49. package/dist/util/testHelpers.d.ts +2 -2
  50. package/dist/util/testHelpers.js +3 -3
  51. package/package.json +2 -1
  52. package/dist/chunk-2Z2NE47H.js.map +0 -1
  53. package/dist/chunk-QZD2UTDJ.js.map +0 -1
  54. package/dist/chunk-SLYSDRLE.js.map +0 -1
  55. /package/dist/{chunk-LDCCELCJ.js.map → chunk-HGBAUTIW.js.map} +0 -0
  56. /package/dist/{chunk-YHKIWQOC.js.map → chunk-ZIWOHAQM.js.map} +0 -0
@@ -1,9 +1,9 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-4bba42d8.js';
2
- export { C as Client, E as Err, O as Ok, B as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, o as ProcedureMap, d as ProcedureResult, p as RPCProcedure, z as ResultUnwrapErr, y as ResultUnwrapOk, x as RiverErrorSchema, c as RiverUncaughtSchema, n as SerializedServerSchema, e as Service, f as ServiceConfiguration, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, m as ServiceSchema, r as StreamProcedure, q as SubscriptionProcedure, w as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, t as createClient, s as serializeSchema } from '../services-4bba42d8.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-abc077db.js';
2
+ export { C as Client, E as Err, O as Ok, B as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, o as ProcedureMap, d as ProcedureResult, p as RPCProcedure, z as ResultUnwrapErr, y as ResultUnwrapOk, x as RiverErrorSchema, c as RiverUncaughtSchema, n as SerializedServerSchema, e as Service, f as ServiceConfiguration, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, m as ServiceSchema, r as StreamProcedure, q as SubscriptionProcedure, w as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, t as createClient, s as serializeSchema } from '../services-abc077db.js';
3
3
  import { Static } from '@sinclair/typebox';
4
4
  import { ServerTransport } from '../transport/index.cjs';
5
5
  import { Pushable } from 'it-pushable';
6
- import { C as Connection } from '../index-e2513701.js';
6
+ import { C as Connection } from '../index-3ac92295.js';
7
7
  import '../types-3e5768ec.js';
8
8
 
9
9
  /**
@@ -36,6 +36,6 @@ interface ProcStream {
36
36
  */
37
37
  declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
38
38
 
39
- var version = "0.19.3";
39
+ var version = "0.20.0";
40
40
 
41
41
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -1,9 +1,9 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-5fc5712d.js';
2
- export { C as Client, E as Err, O as Ok, B as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, o as ProcedureMap, d as ProcedureResult, p as RPCProcedure, z as ResultUnwrapErr, y as ResultUnwrapOk, x as RiverErrorSchema, c as RiverUncaughtSchema, n as SerializedServerSchema, e as Service, f as ServiceConfiguration, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, m as ServiceSchema, r as StreamProcedure, q as SubscriptionProcedure, w as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, t as createClient, s as serializeSchema } from '../services-5fc5712d.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-8496d6e8.js';
2
+ export { C as Client, E as Err, O as Ok, B as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, o as ProcedureMap, d as ProcedureResult, p as RPCProcedure, z as ResultUnwrapErr, y as ResultUnwrapOk, x as RiverErrorSchema, c as RiverUncaughtSchema, n as SerializedServerSchema, e as Service, f as ServiceConfiguration, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, m as ServiceSchema, r as StreamProcedure, q as SubscriptionProcedure, w as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, t as createClient, s as serializeSchema } from '../services-8496d6e8.js';
3
3
  import { Static } from '@sinclair/typebox';
4
4
  import { ServerTransport } from '../transport/index.js';
5
5
  import { Pushable } from 'it-pushable';
6
- import { C as Connection } from '../index-e2513701.js';
6
+ import { C as Connection } from '../index-3ac92295.js';
7
7
  import '../types-3e5768ec.js';
8
8
 
9
9
  /**
@@ -36,6 +36,6 @@ interface ProcStream {
36
36
  */
37
37
  declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>;
38
38
 
39
- var version = "0.19.3";
39
+ var version = "0.20.0";
40
40
 
41
41
  export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer };
@@ -9,8 +9,8 @@ import {
9
9
  createServer,
10
10
  serializeSchema,
11
11
  version
12
- } from "../chunk-SLYSDRLE.js";
13
- import "../chunk-2Z2NE47H.js";
12
+ } from "../chunk-YB5LRYL6.js";
13
+ import "../chunk-5WFL722S.js";
14
14
  import "../chunk-DT5JS6TM.js";
15
15
  export {
16
16
  Err,
@@ -1,7 +1,7 @@
1
1
  import { Static, TObject, TUnion, TString, TSchema, TNever, TLiteral } from '@sinclair/typebox';
2
2
  import { ClientTransport } from './transport/index.js';
3
3
  import { Pushable } from 'it-pushable';
4
- import { C as Connection, T as TransportClientId, a as Session, b as ParsedHandshakeMetadata } from './index-e2513701.js';
4
+ import { C as Connection, T as TransportClientId, a as Session, b as ParsedHandshakeMetadata } from './index-3ac92295.js';
5
5
 
6
6
  type AsyncIter<T> = AsyncGenerator<T, T>;
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  import { Static, TObject, TUnion, TString, TSchema, TNever, TLiteral } from '@sinclair/typebox';
2
2
  import { ClientTransport } from './transport/index.cjs';
3
3
  import { Pushable } from 'it-pushable';
4
- import { C as Connection, T as TransportClientId, a as Session, b as ParsedHandshakeMetadata } from './index-e2513701.js';
4
+ import { C as Connection, T as TransportClientId, a as Session, b as ParsedHandshakeMetadata } from './index-3ac92295.js';
5
5
 
6
6
  type AsyncIter<T> = AsyncGenerator<T, T>;
7
7
  /**
@@ -44,6 +44,12 @@ var TransportMessageSchema = (t) => import_typebox.Type.Object({
44
44
  procedureName: import_typebox.Type.Optional(import_typebox.Type.String()),
45
45
  streamId: import_typebox.Type.String(),
46
46
  controlFlags: import_typebox.Type.Integer(),
47
+ tracing: import_typebox.Type.Optional(
48
+ import_typebox.Type.Object({
49
+ traceparent: import_typebox.Type.String(),
50
+ tracestate: import_typebox.Type.String()
51
+ })
52
+ ),
47
53
  payload: t
48
54
  });
49
55
  var ControlMessageAckSchema = import_typebox.Type.Object({
@@ -81,7 +87,7 @@ var ControlMessagePayloadSchema = import_typebox.Type.Union([
81
87
  var OpaqueTransportMessageSchema = TransportMessageSchema(
82
88
  import_typebox.Type.Unknown()
83
89
  );
84
- function handshakeRequestMessage(from, to, sessionId, metadata) {
90
+ function handshakeRequestMessage(from, to, sessionId, metadata, tracing) {
85
91
  return {
86
92
  id: (0, import_nanoid.nanoid)(),
87
93
  from,
@@ -90,6 +96,7 @@ function handshakeRequestMessage(from, to, sessionId, metadata) {
90
96
  ack: 0,
91
97
  streamId: (0, import_nanoid.nanoid)(),
92
98
  controlFlags: 0,
99
+ tracing,
93
100
  payload: {
94
101
  type: "HANDSHAKE_REQ",
95
102
  protocolVersion: PROTOCOL_VERSION,
@@ -434,6 +441,7 @@ var UdsConnection = class extends Connection {
434
441
 
435
442
  // transport/transport.ts
436
443
  var import_value = require("@sinclair/typebox/value");
444
+ var import_api2 = require("@opentelemetry/api");
437
445
 
438
446
  // transport/events.ts
439
447
  var ProtocolError = {
@@ -469,6 +477,11 @@ var EventDispatcher = class {
469
477
  }
470
478
  };
471
479
 
480
+ // tracing/index.ts
481
+ var import_api = require("@opentelemetry/api");
482
+ var tracer = import_api.trace.getTracer("river");
483
+ var tracing_default = tracer;
484
+
472
485
  // util/stringify.ts
473
486
  function coerceErrorString(err) {
474
487
  if (err instanceof Error) {
@@ -1028,82 +1041,142 @@ var ClientTransport = class extends Transport {
1028
1041
  * @param to The client ID of the node to connect to.
1029
1042
  */
1030
1043
  async connect(to) {
1031
- const canProceedWithConnection = () => this.state === "open";
1032
- if (!canProceedWithConnection()) {
1033
- log?.info(
1034
- `transport state is no longer open, cancelling attempt to connect to ${to}`,
1035
- { clientId: this.clientId, connectedTo: to }
1036
- );
1037
- return;
1038
- }
1039
- let reconnectPromise = this.inflightConnectionPromises.get(to);
1040
- if (!reconnectPromise) {
1041
- const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1042
- if (!this.retryBudget.hasBudget(to)) {
1043
- const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
1044
- log?.warn(errMsg, { clientId: this.clientId, connectedTo: to });
1045
- this.protocolError(ProtocolError.RetriesExceeded, errMsg);
1046
- return;
1047
- }
1048
- let sleep = Promise.resolve();
1049
- const backoffMs = this.retryBudget.getBackoffMs(to);
1050
- if (backoffMs > 0) {
1051
- sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
1052
- }
1053
- log?.info(`attempting connection to ${to} (${backoffMs}ms backoff)`, {
1054
- clientId: this.clientId,
1055
- connectedTo: to
1056
- });
1057
- this.retryBudget.consumeBudget(to);
1058
- reconnectPromise = sleep.then(() => {
1059
- if (!canProceedWithConnection()) {
1060
- throw new Error("transport state is no longer open");
1044
+ return tracing_default.startActiveSpan(
1045
+ "connect",
1046
+ {
1047
+ attributes: {
1048
+ component: "river",
1049
+ "span.kind": "client"
1050
+ },
1051
+ kind: import_api2.SpanKind.CLIENT
1052
+ },
1053
+ async (span) => {
1054
+ try {
1055
+ await this.connectAttempt(to);
1056
+ } catch (e) {
1057
+ if (e instanceof Error) {
1058
+ span.recordException(e);
1059
+ } else {
1060
+ span.recordException(coerceErrorString(e));
1061
+ }
1062
+ span.setStatus({ code: import_api2.SpanStatusCode.ERROR });
1063
+ } finally {
1064
+ span.end();
1061
1065
  }
1062
- }).then(() => this.createNewOutgoingConnection(to)).then((conn) => {
1063
- if (!canProceedWithConnection()) {
1064
- log?.info(
1065
- `transport state is no longer open, closing pre-handshake connection to ${to}`,
1066
- {
1067
- clientId: this.clientId,
1068
- connectedTo: to,
1069
- connId: conn.debugId
1066
+ }
1067
+ );
1068
+ }
1069
+ async connectAttempt(to, attempt = 0) {
1070
+ const retry = await tracing_default.startActiveSpan(
1071
+ "connect",
1072
+ {
1073
+ attributes: {
1074
+ component: "river",
1075
+ "river.attempt": attempt,
1076
+ "span.kind": "client"
1077
+ },
1078
+ kind: import_api2.SpanKind.CLIENT
1079
+ },
1080
+ async (span) => {
1081
+ try {
1082
+ const canProceedWithConnection = () => this.state === "open";
1083
+ if (!canProceedWithConnection()) {
1084
+ log?.info(
1085
+ `transport state is no longer open, cancelling attempt to connect to ${to}`,
1086
+ { clientId: this.clientId, connectedTo: to }
1087
+ );
1088
+ return false;
1089
+ }
1090
+ let reconnectPromise = this.inflightConnectionPromises.get(to);
1091
+ if (!reconnectPromise) {
1092
+ const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1093
+ if (!this.retryBudget.hasBudget(to)) {
1094
+ const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
1095
+ log?.warn(errMsg, { clientId: this.clientId, connectedTo: to });
1096
+ this.protocolError(ProtocolError.RetriesExceeded, errMsg);
1097
+ return false;
1070
1098
  }
1071
- );
1072
- conn.close();
1073
- throw new Error("transport state is no longer open");
1074
- }
1075
- return this.sendHandshake(to, conn).then((ok) => {
1076
- if (!ok) {
1077
- conn.close();
1078
- throw new Error("failed to send handshake");
1099
+ let sleep = Promise.resolve();
1100
+ const backoffMs = this.retryBudget.getBackoffMs(to);
1101
+ if (backoffMs > 0) {
1102
+ sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
1103
+ }
1104
+ log?.info(
1105
+ `attempting connection to ${to} (${backoffMs}ms backoff)`,
1106
+ {
1107
+ clientId: this.clientId,
1108
+ connectedTo: to
1109
+ }
1110
+ );
1111
+ this.retryBudget.consumeBudget(to);
1112
+ reconnectPromise = sleep.then(() => {
1113
+ if (!canProceedWithConnection()) {
1114
+ throw new Error("transport state is no longer open");
1115
+ }
1116
+ }).then(() => this.createNewOutgoingConnection(to)).then((conn) => {
1117
+ if (!canProceedWithConnection()) {
1118
+ log?.info(
1119
+ `transport state is no longer open, closing pre-handshake connection to ${to}`,
1120
+ {
1121
+ clientId: this.clientId,
1122
+ connectedTo: to,
1123
+ connId: conn.debugId
1124
+ }
1125
+ );
1126
+ conn.close();
1127
+ throw new Error("transport state is no longer open");
1128
+ }
1129
+ return this.sendHandshake(to, conn).then((ok) => {
1130
+ if (!ok) {
1131
+ conn.close();
1132
+ throw new Error("failed to send handshake");
1133
+ }
1134
+ return conn;
1135
+ });
1136
+ });
1137
+ this.inflightConnectionPromises.set(to, reconnectPromise);
1138
+ } else {
1139
+ log?.info(
1140
+ `attempting connection to ${to} (reusing previous attempt)`,
1141
+ {
1142
+ clientId: this.clientId,
1143
+ connectedTo: to
1144
+ }
1145
+ );
1079
1146
  }
1080
- return conn;
1081
- });
1082
- });
1083
- this.inflightConnectionPromises.set(to, reconnectPromise);
1084
- } else {
1085
- log?.info(`attempting connection to ${to} (reusing previous attempt)`, {
1086
- clientId: this.clientId,
1087
- connectedTo: to
1088
- });
1089
- }
1090
- try {
1091
- await reconnectPromise;
1092
- } catch (error) {
1093
- this.inflightConnectionPromises.delete(to);
1094
- const errStr = coerceErrorString(error);
1095
- if (!this.reconnectOnConnectionDrop || !canProceedWithConnection()) {
1096
- log?.warn(`connection to ${to} failed (${errStr})`, {
1097
- clientId: this.clientId,
1098
- connectedTo: to
1099
- });
1100
- } else {
1101
- log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
1102
- clientId: this.clientId,
1103
- connectedTo: to
1104
- });
1105
- return this.connect(to);
1147
+ try {
1148
+ await reconnectPromise;
1149
+ } catch (error) {
1150
+ this.inflightConnectionPromises.delete(to);
1151
+ const errStr = coerceErrorString(error);
1152
+ if (!this.reconnectOnConnectionDrop || !canProceedWithConnection()) {
1153
+ log?.warn(`connection to ${to} failed (${errStr})`, {
1154
+ clientId: this.clientId,
1155
+ connectedTo: to
1156
+ });
1157
+ } else {
1158
+ log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
1159
+ clientId: this.clientId,
1160
+ connectedTo: to
1161
+ });
1162
+ return true;
1163
+ }
1164
+ }
1165
+ } catch (e) {
1166
+ if (e instanceof Error) {
1167
+ span.recordException(e);
1168
+ } else {
1169
+ span.recordException(coerceErrorString(e));
1170
+ }
1171
+ span.setStatus({ code: import_api2.SpanStatusCode.ERROR });
1172
+ } finally {
1173
+ span.end();
1174
+ }
1175
+ return false;
1106
1176
  }
1177
+ );
1178
+ if (retry) {
1179
+ return this.connectAttempt(to, attempt + 1);
1107
1180
  }
1108
1181
  }
1109
1182
  deleteSession(session) {
@@ -1111,6 +1184,8 @@ var ClientTransport = class extends Transport {
1111
1184
  super.deleteSession(session);
1112
1185
  }
1113
1186
  async sendHandshake(to, conn) {
1187
+ const tracing = { traceparent: "", tracestate: "" };
1188
+ import_api2.propagation.inject(import_api2.context.active(), tracing);
1114
1189
  let metadata;
1115
1190
  if (this.options.handshake) {
1116
1191
  metadata = await this.options.handshake.get();
@@ -1131,7 +1206,8 @@ var ClientTransport = class extends Transport {
1131
1206
  this.clientId,
1132
1207
  to,
1133
1208
  session.id,
1134
- metadata
1209
+ metadata,
1210
+ tracing
1135
1211
  );
1136
1212
  log?.debug(`sending handshake request to ${to}`, {
1137
1213
  clientId: this.clientId,