@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,11 +1,11 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, a as AnyProcedure } from '../services-a05f5174.js';
2
- export { E as BaseErrorSchemaType, C as CANCEL_CODE, G as Client, H as Err, L as ErrResult, B as INVALID_REQUEST_CODE, O as Ok, M as OkResult, p as PayloadType, f as ProcErrors, P as ProcHandler, c as ProcInit, d as ProcRequest, e as ProcResponse, g as ProcType, v as Procedure, w as ProcedureErrorSchemaType, q as ProcedureMap, R as RPCProcedure, u as Readable, D as ReaderErrorSchema, T as ResponseData, K as Result, Q as ResultUnwrapErr, N as ResultUnwrapOk, k as SerializedProcedureSchema, o as SerializedProcedureSchemaProtocolv1, i as SerializedServerSchema, m as SerializedServerSchemaProtocolv1, j as SerializedServiceSchema, n as SerializedServiceSchemaProtocolv1, S as Service, b as ServiceConfiguration, h as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, y as UNCAUGHT_ERROR_CODE, z as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, F as createClient, x as flattenErrorType, s as serializeSchema, l as serializeSchemaV1Compat, J as unwrapOrThrow } from '../services-a05f5174.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, a as AnyProcedure } from '../services-56cbea0d.js';
2
+ export { E as BaseErrorSchemaType, C as CANCEL_CODE, G as Client, H as Err, L as ErrResult, B as INVALID_REQUEST_CODE, O as Ok, M as OkResult, p as PayloadType, f as ProcErrors, P as ProcHandler, c as ProcInit, d as ProcRequest, e as ProcResponse, g as ProcType, v as Procedure, w as ProcedureErrorSchemaType, q as ProcedureMap, R as RPCProcedure, u as Readable, D as ReaderErrorSchema, T as ResponseData, K as Result, Q as ResultUnwrapErr, N as ResultUnwrapOk, k as SerializedProcedureSchema, o as SerializedProcedureSchemaProtocolv1, i as SerializedServerSchema, m as SerializedServerSchemaProtocolv1, j as SerializedServiceSchema, n as SerializedServiceSchemaProtocolv1, S as Service, b as ServiceConfiguration, h as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, y as UNCAUGHT_ERROR_CODE, z as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, F as createClient, x as flattenErrorType, s as serializeSchema, l as serializeSchemaV1Compat, J as unwrapOrThrow } from '../services-56cbea0d.js';
3
3
  import { c as TransportClientId, b as OpaqueTransportMessage } from '../message-3def9ded.js';
4
- import { q as ParsedMetadata, C as Connection, r as ServerHandshakeOptions, s as ServiceContext } from '../context-8d263a7f.js';
5
- export { t as ProcedureHandlerContext, u as createClientHandshakeOptions, v as createServerHandshakeOptions } from '../context-8d263a7f.js';
6
- import { S as ServerTransport } from '../server-48d90a77.js';
4
+ import { q as ParsedMetadata, C as Connection, r as ServerHandshakeOptions, s as ServiceContext } from '../context-d6dd8a1a.js';
5
+ export { t as ProcedureHandlerContext, u as createClientHandshakeOptions, v as createServerHandshakeOptions } from '../context-d6dd8a1a.js';
6
+ import { S as ServerTransport } from '../server-e46399f9.js';
7
7
  import '@sinclair/typebox';
8
- import '../client-a32692b0.js';
8
+ import '../client-5d2e41a3.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
11
  import '@sinclair/typebox/errors';
@@ -56,6 +56,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
56
56
  maxCancelledStreamTombstonesPerSession?: number;
57
57
  }>): Server<Services>;
58
58
 
59
- var version = "0.202.0";
59
+ var version = "0.203.1";
60
60
 
61
61
  export { ParsedMetadata, version as RIVER_VERSION, Server, ServiceContext, createServer };
@@ -1,11 +1,11 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, a as AnyProcedure } from '../services-a05f5174.js';
2
- export { E as BaseErrorSchemaType, C as CANCEL_CODE, G as Client, H as Err, L as ErrResult, B as INVALID_REQUEST_CODE, O as Ok, M as OkResult, p as PayloadType, f as ProcErrors, P as ProcHandler, c as ProcInit, d as ProcRequest, e as ProcResponse, g as ProcType, v as Procedure, w as ProcedureErrorSchemaType, q as ProcedureMap, R as RPCProcedure, u as Readable, D as ReaderErrorSchema, T as ResponseData, K as Result, Q as ResultUnwrapErr, N as ResultUnwrapOk, k as SerializedProcedureSchema, o as SerializedProcedureSchemaProtocolv1, i as SerializedServerSchema, m as SerializedServerSchemaProtocolv1, j as SerializedServiceSchema, n as SerializedServiceSchemaProtocolv1, S as Service, b as ServiceConfiguration, h as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, y as UNCAUGHT_ERROR_CODE, z as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, F as createClient, x as flattenErrorType, s as serializeSchema, l as serializeSchemaV1Compat, J as unwrapOrThrow } from '../services-a05f5174.js';
1
+ import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, a as AnyProcedure } from '../services-56cbea0d.js';
2
+ export { E as BaseErrorSchemaType, C as CANCEL_CODE, G as Client, H as Err, L as ErrResult, B as INVALID_REQUEST_CODE, O as Ok, M as OkResult, p as PayloadType, f as ProcErrors, P as ProcHandler, c as ProcInit, d as ProcRequest, e as ProcResponse, g as ProcType, v as Procedure, w as ProcedureErrorSchemaType, q as ProcedureMap, R as RPCProcedure, u as Readable, D as ReaderErrorSchema, T as ResponseData, K as Result, Q as ResultUnwrapErr, N as ResultUnwrapOk, k as SerializedProcedureSchema, o as SerializedProcedureSchemaProtocolv1, i as SerializedServerSchema, m as SerializedServerSchemaProtocolv1, j as SerializedServiceSchema, n as SerializedServiceSchemaProtocolv1, S as Service, b as ServiceConfiguration, h as ServiceSchema, t as StreamProcedure, r as SubscriptionProcedure, y as UNCAUGHT_ERROR_CODE, z as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, F as createClient, x as flattenErrorType, s as serializeSchema, l as serializeSchemaV1Compat, J as unwrapOrThrow } from '../services-56cbea0d.js';
3
3
  import { c as TransportClientId, b as OpaqueTransportMessage } from '../message-3def9ded.js';
4
- import { q as ParsedMetadata, C as Connection, r as ServerHandshakeOptions, s as ServiceContext } from '../context-8d263a7f.js';
5
- export { t as ProcedureHandlerContext, u as createClientHandshakeOptions, v as createServerHandshakeOptions } from '../context-8d263a7f.js';
6
- import { S as ServerTransport } from '../server-48d90a77.js';
4
+ import { q as ParsedMetadata, C as Connection, r as ServerHandshakeOptions, s as ServiceContext } from '../context-d6dd8a1a.js';
5
+ export { t as ProcedureHandlerContext, u as createClientHandshakeOptions, v as createServerHandshakeOptions } from '../context-d6dd8a1a.js';
6
+ import { S as ServerTransport } from '../server-e46399f9.js';
7
7
  import '@sinclair/typebox';
8
- import '../client-a32692b0.js';
8
+ import '../client-5d2e41a3.js';
9
9
  import '@sinclair/typebox/value';
10
10
  import '@opentelemetry/api';
11
11
  import '@sinclair/typebox/errors';
@@ -56,6 +56,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
56
56
  maxCancelledStreamTombstonesPerSession?: number;
57
57
  }>): Server<Services>;
58
58
 
59
- var version = "0.202.0";
59
+ var version = "0.203.1";
60
60
 
61
61
  export { ParsedMetadata, version as RIVER_VERSION, Server, ServiceContext, createServer };
@@ -12,7 +12,7 @@ import {
12
12
  isStreamClose,
13
13
  isStreamOpen,
14
14
  version
15
- } from "../chunk-QMXUCLGE.js";
15
+ } from "../chunk-AK7NTFAM.js";
16
16
 
17
17
  // router/services.ts
18
18
  import { Type as Type2, Kind as Kind2 } from "@sinclair/typebox";
@@ -725,7 +725,7 @@ function handleProc(procType, transport, serverId, init, serviceName, procedureN
725
725
  const procClosesWithInit = procType === "rpc" || procType === "subscription";
726
726
  const streamId = generateId();
727
727
  const { span, ctx } = createProcTelemetryInfo(
728
- transport,
728
+ session,
729
729
  procType,
730
730
  serviceName,
731
731
  procedureName,
@@ -1000,10 +1000,17 @@ var RiverServer = class {
1000
1000
  if (!newStreamProps) {
1001
1001
  return;
1002
1002
  }
1003
- this.createNewProcStream({
1004
- ...newStreamProps,
1005
- ...message
1006
- });
1003
+ createHandlerSpan(
1004
+ newStreamProps.initialSession,
1005
+ newStreamProps.procedure.type,
1006
+ newStreamProps.serviceName,
1007
+ newStreamProps.procedureName,
1008
+ newStreamProps.streamId,
1009
+ newStreamProps.tracingCtx,
1010
+ (span) => {
1011
+ this.createNewProcStream(span, newStreamProps);
1012
+ }
1013
+ );
1007
1014
  };
1008
1015
  const handleSessionStatus = (evt) => {
1009
1016
  if (evt.status !== "disconnect")
@@ -1037,7 +1044,7 @@ var RiverServer = class {
1037
1044
  this.transport.addEventListener("sessionStatus", handleSessionStatus);
1038
1045
  this.transport.addEventListener("transportStatus", handleTransportStatus);
1039
1046
  }
1040
- createNewProcStream(props) {
1047
+ createNewProcStream(span, props) {
1041
1048
  const {
1042
1049
  streamId,
1043
1050
  initialSession,
@@ -1047,7 +1054,6 @@ var RiverServer = class {
1047
1054
  sessionMetadata,
1048
1055
  serviceContext,
1049
1056
  initPayload,
1050
- tracingCtx,
1051
1057
  procClosesWithInit,
1052
1058
  passInitAsDataForBackwardsCompat
1053
1059
  } = props;
@@ -1057,6 +1063,10 @@ var RiverServer = class {
1057
1063
  protocolVersion,
1058
1064
  id: sessionId
1059
1065
  } = initialSession;
1066
+ loggingMetadata.telemetry = {
1067
+ traceId: span.spanContext().traceId,
1068
+ spanId: span.spanContext().spanId
1069
+ };
1060
1070
  let cleanClose = true;
1061
1071
  const onMessage = (msg) => {
1062
1072
  if (msg.from !== from) {
@@ -1229,10 +1239,10 @@ var RiverServer = class {
1229
1239
  }
1230
1240
  }
1231
1241
  });
1232
- const onHandlerError = (err, span) => {
1242
+ const onHandlerError = (err, span2) => {
1233
1243
  const errorMsg = coerceErrorString(err);
1234
- span.recordException(err instanceof Error ? err : new Error(errorMsg));
1235
- span.setStatus({ code: SpanStatusCode.ERROR });
1244
+ span2.recordException(err instanceof Error ? err : new Error(errorMsg));
1245
+ span2.setStatus({ code: SpanStatusCode.ERROR });
1236
1246
  this.log?.error(
1237
1247
  `${serviceName}.${procedureName} handler threw an uncaught error`,
1238
1248
  {
@@ -1256,11 +1266,12 @@ var RiverServer = class {
1256
1266
  if (procClosesWithInit) {
1257
1267
  closeReadable();
1258
1268
  }
1259
- const handlerContext = {
1269
+ const handlerContextWithSpan = (span2) => ({
1260
1270
  ...serviceContext,
1261
1271
  from,
1262
1272
  sessionId,
1263
1273
  metadata: sessionMetadata,
1274
+ span: span2,
1264
1275
  cancel: () => {
1265
1276
  onServerCancel({
1266
1277
  code: CANCEL_CODE,
@@ -1268,103 +1279,75 @@ var RiverServer = class {
1268
1279
  });
1269
1280
  },
1270
1281
  signal: finishedController.signal
1271
- };
1282
+ });
1272
1283
  switch (procedure.type) {
1273
1284
  case "rpc":
1274
- void createHandlerSpan(
1275
- procedure.type,
1276
- serviceName,
1277
- procedureName,
1278
- streamId,
1279
- tracingCtx,
1280
- async (span) => {
1281
- try {
1282
- const responsePayload = await procedure.handler({
1283
- ctx: handlerContext,
1284
- reqInit: initPayload
1285
- });
1286
- if (resWritable.isClosed()) {
1287
- return;
1288
- }
1289
- resWritable.write(responsePayload);
1290
- } catch (err) {
1291
- onHandlerError(err, span);
1292
- } finally {
1293
- span.end();
1285
+ void (async () => {
1286
+ try {
1287
+ const responsePayload = await procedure.handler({
1288
+ ctx: handlerContextWithSpan(span),
1289
+ reqInit: initPayload
1290
+ });
1291
+ if (resWritable.isClosed()) {
1292
+ return;
1294
1293
  }
1294
+ resWritable.write(responsePayload);
1295
+ } catch (err) {
1296
+ onHandlerError(err, span);
1297
+ } finally {
1298
+ span.end();
1295
1299
  }
1296
- );
1300
+ })();
1297
1301
  break;
1298
1302
  case "stream":
1299
- void createHandlerSpan(
1300
- procedure.type,
1301
- serviceName,
1302
- procedureName,
1303
- streamId,
1304
- tracingCtx,
1305
- async (span) => {
1306
- try {
1307
- await procedure.handler({
1308
- ctx: handlerContext,
1309
- reqInit: initPayload,
1310
- reqReadable,
1311
- resWritable
1312
- });
1313
- } catch (err) {
1314
- onHandlerError(err, span);
1315
- } finally {
1316
- span.end();
1317
- }
1303
+ void (async () => {
1304
+ try {
1305
+ await procedure.handler({
1306
+ ctx: handlerContextWithSpan(span),
1307
+ reqInit: initPayload,
1308
+ reqReadable,
1309
+ resWritable
1310
+ });
1311
+ } catch (err) {
1312
+ onHandlerError(err, span);
1313
+ } finally {
1314
+ span.end();
1318
1315
  }
1319
- );
1316
+ })();
1320
1317
  break;
1321
1318
  case "subscription":
1322
- void createHandlerSpan(
1323
- procedure.type,
1324
- serviceName,
1325
- procedureName,
1326
- streamId,
1327
- tracingCtx,
1328
- async (span) => {
1329
- try {
1330
- await procedure.handler({
1331
- ctx: handlerContext,
1332
- reqInit: initPayload,
1333
- resWritable
1334
- });
1335
- } catch (err) {
1336
- onHandlerError(err, span);
1337
- } finally {
1338
- span.end();
1339
- }
1319
+ void (async () => {
1320
+ try {
1321
+ await procedure.handler({
1322
+ ctx: handlerContextWithSpan(span),
1323
+ reqInit: initPayload,
1324
+ resWritable
1325
+ });
1326
+ } catch (err) {
1327
+ onHandlerError(err, span);
1328
+ } finally {
1329
+ span.end();
1340
1330
  }
1341
- );
1331
+ })();
1342
1332
  break;
1343
1333
  case "upload":
1344
- void createHandlerSpan(
1345
- procedure.type,
1346
- serviceName,
1347
- procedureName,
1348
- streamId,
1349
- tracingCtx,
1350
- async (span) => {
1351
- try {
1352
- const responsePayload = await procedure.handler({
1353
- ctx: handlerContext,
1354
- reqInit: initPayload,
1355
- reqReadable
1356
- });
1357
- if (resWritable.isClosed()) {
1358
- return;
1359
- }
1360
- resWritable.write(responsePayload);
1361
- } catch (err) {
1362
- onHandlerError(err, span);
1363
- } finally {
1364
- span.end();
1334
+ void (async () => {
1335
+ try {
1336
+ const responsePayload = await procedure.handler({
1337
+ ctx: handlerContextWithSpan(span),
1338
+ reqInit: initPayload,
1339
+ reqReadable
1340
+ });
1341
+ if (resWritable.isClosed()) {
1342
+ return;
1365
1343
  }
1344
+ resWritable.write(responsePayload);
1345
+ } catch (err) {
1346
+ onHandlerError(err, span);
1347
+ } finally {
1348
+ span.end();
1366
1349
  }
1367
- );
1350
+ })();
1368
1351
  break;
1369
1352
  }
1370
1353
  if (!finishedController.signal.aborted) {