@replit/river 0.19.3 → 0.20.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 (63) hide show
  1. package/README.md +2 -0
  2. package/dist/{chunk-XAG3SC7R.js → chunk-3AW3IXVD.js} +4 -2
  3. package/dist/chunk-3AW3IXVD.js.map +1 -0
  4. package/dist/{chunk-2Z2NE47H.js → chunk-5WFL722S.js} +15 -2
  5. package/dist/chunk-5WFL722S.js.map +1 -0
  6. package/dist/{chunk-SLYSDRLE.js → chunk-DP5X7CCT.js} +517 -260
  7. package/dist/chunk-DP5X7CCT.js.map +1 -0
  8. package/dist/{chunk-YHKIWQOC.js → chunk-FNK44ZN3.js} +2 -2
  9. package/dist/{chunk-LDCCELCJ.js → chunk-MJR36SUY.js} +8 -3
  10. package/dist/{chunk-LDCCELCJ.js.map → chunk-MJR36SUY.js.map} +1 -1
  11. package/dist/{chunk-QZD2UTDJ.js → chunk-QU2EE6YU.js} +384 -246
  12. package/dist/chunk-QU2EE6YU.js.map +1 -0
  13. package/dist/codec/index.cjs +3 -1
  14. package/dist/codec/index.cjs.map +1 -1
  15. package/dist/codec/index.js +1 -1
  16. package/dist/{connection-cfec12e6.d.ts → connection-d49d5d56.d.ts} +1 -1
  17. package/dist/{connection-aa0ea000.d.ts → connection-dba95bc8.d.ts} +1 -1
  18. package/dist/{index-e2513701.d.ts → index-3ac92295.d.ts} +12 -0
  19. package/dist/logging/index.d.cts +1 -1
  20. package/dist/logging/index.d.ts +1 -1
  21. package/dist/router/index.cjs +514 -257
  22. package/dist/router/index.cjs.map +1 -1
  23. package/dist/router/index.d.cts +4 -4
  24. package/dist/router/index.d.ts +4 -4
  25. package/dist/router/index.js +2 -2
  26. package/dist/{services-5fc5712d.d.ts → services-8496d6e8.d.ts} +1 -1
  27. package/dist/{services-4bba42d8.d.ts → services-abc077db.d.ts} +1 -1
  28. package/dist/transport/impls/uds/client.cjs +156 -75
  29. package/dist/transport/impls/uds/client.cjs.map +1 -1
  30. package/dist/transport/impls/uds/client.d.cts +2 -2
  31. package/dist/transport/impls/uds/client.d.ts +2 -2
  32. package/dist/transport/impls/uds/client.js +4 -4
  33. package/dist/transport/impls/uds/server.cjs +255 -170
  34. package/dist/transport/impls/uds/server.cjs.map +1 -1
  35. package/dist/transport/impls/uds/server.d.cts +2 -2
  36. package/dist/transport/impls/uds/server.d.ts +2 -2
  37. package/dist/transport/impls/uds/server.js +4 -4
  38. package/dist/transport/impls/ws/client.cjs +150 -74
  39. package/dist/transport/impls/ws/client.cjs.map +1 -1
  40. package/dist/transport/impls/ws/client.d.cts +2 -2
  41. package/dist/transport/impls/ws/client.d.ts +2 -2
  42. package/dist/transport/impls/ws/client.js +4 -4
  43. package/dist/transport/impls/ws/server.cjs +249 -169
  44. package/dist/transport/impls/ws/server.cjs.map +1 -1
  45. package/dist/transport/impls/ws/server.d.cts +2 -2
  46. package/dist/transport/impls/ws/server.d.ts +2 -2
  47. package/dist/transport/impls/ws/server.js +4 -4
  48. package/dist/transport/index.cjs +387 -243
  49. package/dist/transport/index.cjs.map +1 -1
  50. package/dist/transport/index.d.cts +3 -2
  51. package/dist/transport/index.d.ts +3 -2
  52. package/dist/transport/index.js +3 -3
  53. package/dist/util/testHelpers.cjs +1 -0
  54. package/dist/util/testHelpers.cjs.map +1 -1
  55. package/dist/util/testHelpers.d.cts +2 -2
  56. package/dist/util/testHelpers.d.ts +2 -2
  57. package/dist/util/testHelpers.js +4 -4
  58. package/package.json +2 -1
  59. package/dist/chunk-2Z2NE47H.js.map +0 -1
  60. package/dist/chunk-QZD2UTDJ.js.map +0 -1
  61. package/dist/chunk-SLYSDRLE.js.map +0 -1
  62. package/dist/chunk-XAG3SC7R.js.map +0 -1
  63. /package/dist/{chunk-YHKIWQOC.js.map → chunk-FNK44ZN3.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.1";
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.1";
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-DP5X7CCT.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,
@@ -419,7 +426,12 @@ var UdsConnection = class extends Connection {
419
426
  this.sock.on("close", cb);
420
427
  }
421
428
  addErrorListener(cb) {
422
- this.sock.on("error", cb);
429
+ this.sock.on("error", (err) => {
430
+ if (err instanceof Error && "code" in err && err.code === "EPIPE") {
431
+ return;
432
+ }
433
+ cb(err);
434
+ });
423
435
  }
424
436
  send(payload) {
425
437
  if (this.framer.destroyed || !this.sock.writable)
@@ -434,6 +446,7 @@ var UdsConnection = class extends Connection {
434
446
 
435
447
  // transport/transport.ts
436
448
  var import_value = require("@sinclair/typebox/value");
449
+ var import_api2 = require("@opentelemetry/api");
437
450
 
438
451
  // transport/events.ts
439
452
  var ProtocolError = {
@@ -469,6 +482,11 @@ var EventDispatcher = class {
469
482
  }
470
483
  };
471
484
 
485
+ // tracing/index.ts
486
+ var import_api = require("@opentelemetry/api");
487
+ var tracer = import_api.trace.getTracer("river");
488
+ var tracing_default = tracer;
489
+
472
490
  // util/stringify.ts
473
491
  function coerceErrorString(err) {
474
492
  if (err instanceof Error) {
@@ -1028,82 +1046,142 @@ var ClientTransport = class extends Transport {
1028
1046
  * @param to The client ID of the node to connect to.
1029
1047
  */
1030
1048
  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");
1049
+ return tracing_default.startActiveSpan(
1050
+ "connect",
1051
+ {
1052
+ attributes: {
1053
+ component: "river",
1054
+ "span.kind": "client"
1055
+ },
1056
+ kind: import_api2.SpanKind.CLIENT
1057
+ },
1058
+ async (span) => {
1059
+ try {
1060
+ await this.connectAttempt(to);
1061
+ } catch (e) {
1062
+ if (e instanceof Error) {
1063
+ span.recordException(e);
1064
+ } else {
1065
+ span.recordException(coerceErrorString(e));
1066
+ }
1067
+ span.setStatus({ code: import_api2.SpanStatusCode.ERROR });
1068
+ } finally {
1069
+ span.end();
1061
1070
  }
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
1071
+ }
1072
+ );
1073
+ }
1074
+ async connectAttempt(to, attempt = 0) {
1075
+ const retry = await tracing_default.startActiveSpan(
1076
+ "connect",
1077
+ {
1078
+ attributes: {
1079
+ component: "river",
1080
+ "river.attempt": attempt,
1081
+ "span.kind": "client"
1082
+ },
1083
+ kind: import_api2.SpanKind.CLIENT
1084
+ },
1085
+ async (span) => {
1086
+ try {
1087
+ const canProceedWithConnection = () => this.state === "open";
1088
+ if (!canProceedWithConnection()) {
1089
+ log?.info(
1090
+ `transport state is no longer open, cancelling attempt to connect to ${to}`,
1091
+ { clientId: this.clientId, connectedTo: to }
1092
+ );
1093
+ return false;
1094
+ }
1095
+ let reconnectPromise = this.inflightConnectionPromises.get(to);
1096
+ if (!reconnectPromise) {
1097
+ const budgetConsumed = this.retryBudget.getBudgetConsumed(to);
1098
+ if (!this.retryBudget.hasBudget(to)) {
1099
+ const errMsg = `tried to connect to ${to} but retry budget exceeded (more than ${budgetConsumed} attempts in the last ${this.retryBudget.totalBudgetRestoreTime}ms)`;
1100
+ log?.warn(errMsg, { clientId: this.clientId, connectedTo: to });
1101
+ this.protocolError(ProtocolError.RetriesExceeded, errMsg);
1102
+ return false;
1070
1103
  }
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");
1104
+ let sleep = Promise.resolve();
1105
+ const backoffMs = this.retryBudget.getBackoffMs(to);
1106
+ if (backoffMs > 0) {
1107
+ sleep = new Promise((resolve) => setTimeout(resolve, backoffMs));
1108
+ }
1109
+ log?.info(
1110
+ `attempting connection to ${to} (${backoffMs}ms backoff)`,
1111
+ {
1112
+ clientId: this.clientId,
1113
+ connectedTo: to
1114
+ }
1115
+ );
1116
+ this.retryBudget.consumeBudget(to);
1117
+ reconnectPromise = sleep.then(() => {
1118
+ if (!canProceedWithConnection()) {
1119
+ throw new Error("transport state is no longer open");
1120
+ }
1121
+ }).then(() => this.createNewOutgoingConnection(to)).then((conn) => {
1122
+ if (!canProceedWithConnection()) {
1123
+ log?.info(
1124
+ `transport state is no longer open, closing pre-handshake connection to ${to}`,
1125
+ {
1126
+ clientId: this.clientId,
1127
+ connectedTo: to,
1128
+ connId: conn.debugId
1129
+ }
1130
+ );
1131
+ conn.close();
1132
+ throw new Error("transport state is no longer open");
1133
+ }
1134
+ return this.sendHandshake(to, conn).then((ok) => {
1135
+ if (!ok) {
1136
+ conn.close();
1137
+ throw new Error("failed to send handshake");
1138
+ }
1139
+ return conn;
1140
+ });
1141
+ });
1142
+ this.inflightConnectionPromises.set(to, reconnectPromise);
1143
+ } else {
1144
+ log?.info(
1145
+ `attempting connection to ${to} (reusing previous attempt)`,
1146
+ {
1147
+ clientId: this.clientId,
1148
+ connectedTo: to
1149
+ }
1150
+ );
1079
1151
  }
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);
1152
+ try {
1153
+ await reconnectPromise;
1154
+ } catch (error) {
1155
+ this.inflightConnectionPromises.delete(to);
1156
+ const errStr = coerceErrorString(error);
1157
+ if (!this.reconnectOnConnectionDrop || !canProceedWithConnection()) {
1158
+ log?.warn(`connection to ${to} failed (${errStr})`, {
1159
+ clientId: this.clientId,
1160
+ connectedTo: to
1161
+ });
1162
+ } else {
1163
+ log?.warn(`connection to ${to} failed (${errStr}), retrying`, {
1164
+ clientId: this.clientId,
1165
+ connectedTo: to
1166
+ });
1167
+ return true;
1168
+ }
1169
+ }
1170
+ } catch (e) {
1171
+ if (e instanceof Error) {
1172
+ span.recordException(e);
1173
+ } else {
1174
+ span.recordException(coerceErrorString(e));
1175
+ }
1176
+ span.setStatus({ code: import_api2.SpanStatusCode.ERROR });
1177
+ } finally {
1178
+ span.end();
1179
+ }
1180
+ return false;
1106
1181
  }
1182
+ );
1183
+ if (retry) {
1184
+ return this.connectAttempt(to, attempt + 1);
1107
1185
  }
1108
1186
  }
1109
1187
  deleteSession(session) {
@@ -1111,6 +1189,8 @@ var ClientTransport = class extends Transport {
1111
1189
  super.deleteSession(session);
1112
1190
  }
1113
1191
  async sendHandshake(to, conn) {
1192
+ const tracing = { traceparent: "", tracestate: "" };
1193
+ import_api2.propagation.inject(import_api2.context.active(), tracing);
1114
1194
  let metadata;
1115
1195
  if (this.options.handshake) {
1116
1196
  metadata = await this.options.handshake.get();
@@ -1131,7 +1211,8 @@ var ClientTransport = class extends Transport {
1131
1211
  this.clientId,
1132
1212
  to,
1133
1213
  session.id,
1134
- metadata
1214
+ metadata,
1215
+ tracing
1135
1216
  );
1136
1217
  log?.debug(`sending handshake request to ${to}`, {
1137
1218
  clientId: this.clientId,