@replit/river 0.14.0 → 0.14.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.
package/README.md CHANGED
@@ -25,9 +25,6 @@ npm i @replit/river @sinclair/typebox
25
25
  npm i ws isomorphic-ws
26
26
  ```
27
27
 
28
- If you are planning on using River with React, also check out [`@replit/river-react`](https://npmjs.com/package/@replit/river-react)
29
- which provides some handy hooks and contexts for playing nicely with the React lifecycle.
30
-
31
28
  ## Writing Services
32
29
 
33
30
  ### Concepts
@@ -173,7 +173,7 @@ type Procedure<State, Ty extends ValidProcType, I extends PayloadType, O extends
173
173
  input: I;
174
174
  output: O;
175
175
  errors: E;
176
- handler: (context: ServiceContextWithTransportInfo<State>, input: Static<I>, output: Pushable<Result<Static<O>, Static<E>>>) => Promise<void>;
176
+ handler: (context: ServiceContextWithTransportInfo<State>, input: Static<I>, output: Pushable<Result<Static<O>, Static<E>>>) => Promise<(() => void) | void>;
177
177
  type: Ty;
178
178
  } : never : Ty extends 'stream' ? Init extends PayloadType ? {
179
179
  init: Init;
@@ -812,6 +812,7 @@ var RiverServer = class {
812
812
  const incoming = pushable({ objectMode: true });
813
813
  const outgoing = pushable({ objectMode: true });
814
814
  const needsClose = procedure.type === "subscription" || procedure.type === "stream";
815
+ const disposables = [];
815
816
  const outputHandler = (
816
817
  // sending outgoing messages back to client
817
818
  needsClose ? (
@@ -827,6 +828,7 @@ var RiverServer = class {
827
828
  if (!this.disconnectedSessions.has(message.from)) {
828
829
  this.transport.sendCloseStream(session.to, message.streamId);
829
830
  }
831
+ disposables.forEach((d) => d());
830
832
  })()
831
833
  ) : (
832
834
  // rpc and upload case, we just send the response back with close bit
@@ -838,6 +840,7 @@ var RiverServer = class {
838
840
  controlFlags: 4 /* StreamClosedBit */,
839
841
  payload: response
840
842
  });
843
+ disposables.forEach((d) => d());
841
844
  }
842
845
  })()
843
846
  )
@@ -906,11 +909,14 @@ var RiverServer = class {
906
909
  return;
907
910
  }
908
911
  try {
909
- await procedure.handler(
912
+ const dispose = await procedure.handler(
910
913
  serviceContextWithTransportInfo,
911
914
  inputMessage.value,
912
915
  outgoing
913
916
  );
917
+ if (dispose) {
918
+ disposables.push(dispose);
919
+ }
914
920
  } catch (err) {
915
921
  errorHandler(err);
916
922
  }
@@ -908,6 +908,7 @@ var RiverServer = class {
908
908
  const incoming = pushable({ objectMode: true });
909
909
  const outgoing = pushable({ objectMode: true });
910
910
  const needsClose = procedure.type === "subscription" || procedure.type === "stream";
911
+ const disposables = [];
911
912
  const outputHandler = (
912
913
  // sending outgoing messages back to client
913
914
  needsClose ? (
@@ -923,6 +924,7 @@ var RiverServer = class {
923
924
  if (!this.disconnectedSessions.has(message.from)) {
924
925
  this.transport.sendCloseStream(session.to, message.streamId);
925
926
  }
927
+ disposables.forEach((d) => d());
926
928
  })()
927
929
  ) : (
928
930
  // rpc and upload case, we just send the response back with close bit
@@ -934,6 +936,7 @@ var RiverServer = class {
934
936
  controlFlags: 4 /* StreamClosedBit */,
935
937
  payload: response
936
938
  });
939
+ disposables.forEach((d) => d());
937
940
  }
938
941
  })()
939
942
  )
@@ -1002,11 +1005,14 @@ var RiverServer = class {
1002
1005
  return;
1003
1006
  }
1004
1007
  try {
1005
- await procedure.handler(
1008
+ const dispose = await procedure.handler(
1006
1009
  serviceContextWithTransportInfo,
1007
1010
  inputMessage.value,
1008
1011
  outgoing
1009
1012
  );
1013
+ if (dispose) {
1014
+ disposables.push(dispose);
1015
+ }
1010
1016
  } catch (err) {
1011
1017
  errorHandler(err);
1012
1018
  }
@@ -1,5 +1,5 @@
1
- import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-0547e840.js';
2
- export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-0547e840.js';
1
+ import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-dfe46874.js';
2
+ export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-dfe46874.js';
3
3
  import { S as ServerTransport, C as Connection, a as ClientTransport, b as TransportClientId } from '../index-d1452d8f.js';
4
4
  import { Pushable } from 'it-pushable';
5
5
  import { Static } from '@sinclair/typebox';
@@ -1,5 +1,5 @@
1
- import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-0547e840.js';
2
- export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-0547e840.js';
1
+ import { A as AnyService, P as PayloadType, b as Result, R as RiverError, S as ServiceContext, d as ProcType, e as ProcInput, f as ProcOutput, g as ProcErrors, h as ProcHasInit, i as ProcInit } from '../builder-dfe46874.js';
2
+ export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, p as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, o as ServiceContextWithTransportInfo, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-dfe46874.js';
3
3
  import { S as ServerTransport, C as Connection, a as ClientTransport, b as TransportClientId } from '../index-d1452d8f.js';
4
4
  import { Pushable } from 'it-pushable';
5
5
  import { Static } from '@sinclair/typebox';
@@ -8,7 +8,7 @@ import {
8
8
  createClient,
9
9
  createServer,
10
10
  serializeService
11
- } from "../chunk-TVRCTAL2.js";
11
+ } from "../chunk-KWXQLQAF.js";
12
12
  import "../chunk-GFRAOY75.js";
13
13
  import "../chunk-H4BYJELI.js";
14
14
  export {
@@ -2,7 +2,7 @@ import * as it_pushable from 'it-pushable';
2
2
  import WebSocket from 'isomorphic-ws';
3
3
  import http from 'node:http';
4
4
  import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-d1452d8f.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-0547e840.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-dfe46874.js';
6
6
  import { Static } from '@sinclair/typebox';
7
7
  import net from 'node:net';
8
8
  import '../types-3e5768ec.js';
@@ -2,7 +2,7 @@ import * as it_pushable from 'it-pushable';
2
2
  import WebSocket from 'isomorphic-ws';
3
3
  import http from 'node:http';
4
4
  import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-d1452d8f.js';
5
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-0547e840.js';
5
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-dfe46874.js';
6
6
  import { Static } from '@sinclair/typebox';
7
7
  import net from 'node:net';
8
8
  import '../types-3e5768ec.js';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  UNCAUGHT_ERROR,
3
3
  pushable
4
- } from "../chunk-TVRCTAL2.js";
4
+ } from "../chunk-KWXQLQAF.js";
5
5
  import "../chunk-5IZ2UHWV.js";
6
6
  import {
7
7
  Session,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@replit/river",
3
3
  "description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4
- "version": "0.14.0",
4
+ "version": "0.14.1",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {