@replit/river 0.201.0 → 0.203.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 (44) hide show
  1. package/dist/{chunk-UBUD2LMZ.js → chunk-D5EIDBUT.js} +3 -3
  2. package/dist/{chunk-OZ3ITXW5.js → chunk-DGT3MPD4.js} +13 -3
  3. package/dist/chunk-DGT3MPD4.js.map +1 -0
  4. package/dist/{chunk-PJ4GJ5CU.js → chunk-FG22HHCY.js} +11 -4
  5. package/dist/chunk-FG22HHCY.js.map +1 -0
  6. package/dist/{chunk-7IUEEQP7.js → chunk-SZHNMLKC.js} +2 -2
  7. package/dist/{chunk-7IUEEQP7.js.map → chunk-SZHNMLKC.js.map} +1 -1
  8. package/dist/{chunk-52DVJUVZ.js → chunk-XBPEUVWN.js} +2 -2
  9. package/dist/{client-a32692b0.d.ts → client-5d2e41a3.d.ts} +7 -1
  10. package/dist/{connection-48d021ca.d.ts → connection-11a4af0f.d.ts} +1 -1
  11. package/dist/{context-8d263a7f.d.ts → context-d6dd8a1a.d.ts} +14 -0
  12. package/dist/router/index.cjs +27 -9
  13. package/dist/router/index.cjs.map +1 -1
  14. package/dist/router/index.d.cts +9 -8
  15. package/dist/router/index.d.ts +9 -8
  16. package/dist/router/index.js +27 -9
  17. package/dist/router/index.js.map +1 -1
  18. package/dist/{server-48d90a77.d.ts → server-e46399f9.d.ts} +1 -1
  19. package/dist/{services-e71ea921.d.ts → services-56cbea0d.d.ts} +9 -4
  20. package/dist/testUtil/index.cjs +20 -3
  21. package/dist/testUtil/index.cjs.map +1 -1
  22. package/dist/testUtil/index.d.cts +5 -5
  23. package/dist/testUtil/index.d.ts +5 -5
  24. package/dist/testUtil/index.js +4 -4
  25. package/dist/transport/impls/ws/client.cjs +20 -3
  26. package/dist/transport/impls/ws/client.cjs.map +1 -1
  27. package/dist/transport/impls/ws/client.d.cts +3 -3
  28. package/dist/transport/impls/ws/client.d.ts +3 -3
  29. package/dist/transport/impls/ws/client.js +4 -4
  30. package/dist/transport/impls/ws/server.cjs +10 -3
  31. package/dist/transport/impls/ws/server.cjs.map +1 -1
  32. package/dist/transport/impls/ws/server.d.cts +3 -3
  33. package/dist/transport/impls/ws/server.d.ts +3 -3
  34. package/dist/transport/impls/ws/server.js +4 -4
  35. package/dist/transport/index.cjs +20 -3
  36. package/dist/transport/index.cjs.map +1 -1
  37. package/dist/transport/index.d.cts +4 -4
  38. package/dist/transport/index.d.ts +4 -4
  39. package/dist/transport/index.js +4 -4
  40. package/package.json +1 -1
  41. package/dist/chunk-OZ3ITXW5.js.map +0 -1
  42. package/dist/chunk-PJ4GJ5CU.js.map +0 -1
  43. /package/dist/{chunk-UBUD2LMZ.js.map → chunk-D5EIDBUT.js.map} +0 -0
  44. /package/dist/{chunk-52DVJUVZ.js.map → chunk-XBPEUVWN.js.map} +0 -0
@@ -1,11 +1,11 @@
1
- import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, a as AnyProcedure } from '../services-e71ea921.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-e71ea921.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';
@@ -25,6 +25,7 @@ interface Server<Services extends AnyServiceSchemaMap> {
25
25
  * A set of stream ids that are currently open.
26
26
  */
27
27
  streams: Map<StreamId, ProcStream>;
28
+ close: () => Promise<void>;
28
29
  }
29
30
  interface ProcStream {
30
31
  streamId: StreamId;
@@ -47,7 +48,7 @@ interface ProcStream {
47
48
  */
48
49
  declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, providedServerOptions?: Partial<{
49
50
  handshakeOptions?: ServerHandshakeOptions;
50
- extendedContext?: Omit<ServiceContext, 'state'>;
51
+ extendedContext?: ServiceContext;
51
52
  /**
52
53
  * Maximum number of cancelled streams to keep track of to avoid
53
54
  * cascading stream errors.
@@ -55,6 +56,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
55
56
  maxCancelledStreamTombstonesPerSession?: number;
56
57
  }>): Server<Services>;
57
58
 
58
- var version = "0.201.0";
59
+ var version = "0.203.0";
59
60
 
60
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-e71ea921.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-e71ea921.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';
@@ -25,6 +25,7 @@ interface Server<Services extends AnyServiceSchemaMap> {
25
25
  * A set of stream ids that are currently open.
26
26
  */
27
27
  streams: Map<StreamId, ProcStream>;
28
+ close: () => Promise<void>;
28
29
  }
29
30
  interface ProcStream {
30
31
  streamId: StreamId;
@@ -47,7 +48,7 @@ interface ProcStream {
47
48
  */
48
49
  declare function createServer<Services extends AnyServiceSchemaMap>(transport: ServerTransport<Connection>, services: Services, providedServerOptions?: Partial<{
49
50
  handshakeOptions?: ServerHandshakeOptions;
50
- extendedContext?: Omit<ServiceContext, 'state'>;
51
+ extendedContext?: ServiceContext;
51
52
  /**
52
53
  * Maximum number of cancelled streams to keep track of to avoid
53
54
  * cascading stream errors.
@@ -55,6 +56,6 @@ declare function createServer<Services extends AnyServiceSchemaMap>(transport: S
55
56
  maxCancelledStreamTombstonesPerSession?: number;
56
57
  }>): Server<Services>;
57
58
 
58
- var version = "0.201.0";
59
+ var version = "0.203.0";
59
60
 
60
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-7IUEEQP7.js";
15
+ } from "../chunk-SZHNMLKC.js";
16
16
 
17
17
  // router/services.ts
18
18
  import { Type as Type2, Kind as Kind2 } from "@sinclair/typebox";
@@ -260,9 +260,15 @@ var ServiceSchema = class _ServiceSchema {
260
260
  * for you.
261
261
  */
262
262
  instantiate(extendedContext) {
263
+ const state = this.initializeState(extendedContext);
264
+ const dispose = async () => {
265
+ await state[Symbol.asyncDispose]?.();
266
+ state[Symbol.dispose]?.();
267
+ };
263
268
  return Object.freeze({
264
- state: this.initializeState(extendedContext),
265
- procedures: this.procedures
269
+ state,
270
+ procedures: this.procedures,
271
+ [Symbol.asyncDispose]: dispose
266
272
  });
267
273
  }
268
274
  };
@@ -949,6 +955,7 @@ var RiverServer = class {
949
955
  maxCancelledStreamTombstonesPerSession;
950
956
  streams;
951
957
  services;
958
+ unregisterTransportListeners;
952
959
  constructor(transport, services, handshakeOptions, extendedContext, maxCancelledStreamTombstonesPerSession = 200) {
953
960
  const instances = {};
954
961
  this.services = instances;
@@ -1016,6 +1023,9 @@ var RiverServer = class {
1016
1023
  const handleTransportStatus = (evt) => {
1017
1024
  if (evt.status !== "closed")
1018
1025
  return;
1026
+ this.unregisterTransportListeners();
1027
+ };
1028
+ this.unregisterTransportListeners = () => {
1019
1029
  this.transport.removeEventListener("message", handleCreatingNewStreams);
1020
1030
  this.transport.removeEventListener("sessionStatus", handleSessionStatus);
1021
1031
  this.transport.removeEventListener(
@@ -1246,11 +1256,12 @@ var RiverServer = class {
1246
1256
  if (procClosesWithInit) {
1247
1257
  closeReadable();
1248
1258
  }
1249
- const handlerContext = {
1259
+ const handlerContextWithSpan = (span) => ({
1250
1260
  ...serviceContext,
1251
1261
  from,
1252
1262
  sessionId,
1253
1263
  metadata: sessionMetadata,
1264
+ span,
1254
1265
  cancel: () => {
1255
1266
  onServerCancel({
1256
1267
  code: CANCEL_CODE,
@@ -1258,7 +1269,7 @@ var RiverServer = class {
1258
1269
  });
1259
1270
  },
1260
1271
  signal: finishedController.signal
1261
- };
1272
+ });
1262
1273
  switch (procedure.type) {
1263
1274
  case "rpc":
1264
1275
  void createHandlerSpan(
@@ -1270,7 +1281,7 @@ var RiverServer = class {
1270
1281
  async (span) => {
1271
1282
  try {
1272
1283
  const responsePayload = await procedure.handler({
1273
- ctx: handlerContext,
1284
+ ctx: handlerContextWithSpan(span),
1274
1285
  reqInit: initPayload
1275
1286
  });
1276
1287
  if (resWritable.isClosed()) {
@@ -1295,7 +1306,7 @@ var RiverServer = class {
1295
1306
  async (span) => {
1296
1307
  try {
1297
1308
  await procedure.handler({
1298
- ctx: handlerContext,
1309
+ ctx: handlerContextWithSpan(span),
1299
1310
  reqInit: initPayload,
1300
1311
  reqReadable,
1301
1312
  resWritable
@@ -1318,7 +1329,7 @@ var RiverServer = class {
1318
1329
  async (span) => {
1319
1330
  try {
1320
1331
  await procedure.handler({
1321
- ctx: handlerContext,
1332
+ ctx: handlerContextWithSpan(span),
1322
1333
  reqInit: initPayload,
1323
1334
  resWritable
1324
1335
  });
@@ -1340,7 +1351,7 @@ var RiverServer = class {
1340
1351
  async (span) => {
1341
1352
  try {
1342
1353
  const responsePayload = await procedure.handler({
1343
- ctx: handlerContext,
1354
+ ctx: handlerContextWithSpan(span),
1344
1355
  reqInit: initPayload,
1345
1356
  reqReadable
1346
1357
  });
@@ -1553,6 +1564,13 @@ var RiverServer = class {
1553
1564
  const msg = cancelMessage(streamId, payload);
1554
1565
  sessionScopedSend(msg);
1555
1566
  }
1567
+ async close() {
1568
+ this.unregisterTransportListeners();
1569
+ for (const serviceName of Object.keys(this.services)) {
1570
+ const service = this.services[serviceName];
1571
+ await service[Symbol.asyncDispose]();
1572
+ }
1573
+ }
1556
1574
  };
1557
1575
  var LRUSet = class {
1558
1576
  items;