@replit/river 0.17.3 → 0.17.4

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.
@@ -1,4 +1,4 @@
1
- import { C as Connection } from './index-80f87385.js';
1
+ import { C as Connection } from './index-9e300e8a.js';
2
2
  import { Socket } from 'node:net';
3
3
  import stream, { Transform, TransformCallback, TransformOptions } from 'node:stream';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { C as Connection } from './index-80f87385.js';
2
+ import { C as Connection } from './index-9e300e8a.js';
3
3
 
4
4
  declare class WebSocketConnection extends Connection {
5
5
  ws: WebSocket;
@@ -499,4 +499,4 @@ declare abstract class ServerTransport<ConnType extends Connection> extends Tran
499
499
  receiveHandshakeRequestMessage(data: Uint8Array, conn: ConnType): Session<ConnType> | false;
500
500
  }
501
501
 
502
- export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P, SessionOptions as S, Transport as T, ClientTransport as a, TransportClientId as b, ProvidedClientTransportOptions as c, ServerTransport as d, ProvidedTransportOptions as e, Session as f, TransportStatus as g, TransportMessageSchema as h, OpaqueTransportMessageSchema as i, TransportMessage as j, isStreamOpen as k, isStreamClose as l, EventTypes as m, EventHandler as n, ProtocolError as o, ProtocolErrorType as p };
502
+ export { Connection as C, EventMap as E, OpaqueTransportMessage as O, PartialTransportMessage as P, SessionOptions as S, Transport as T, Session as a, ClientTransport as b, TransportClientId as c, ProvidedClientTransportOptions as d, ServerTransport as e, ProvidedTransportOptions as f, TransportStatus as g, TransportMessageSchema as h, OpaqueTransportMessageSchema as i, TransportMessage as j, isStreamOpen as k, isStreamClose as l, EventTypes as m, EventHandler as n, ProtocolError as o, ProtocolErrorType as p };
@@ -1,6 +1,6 @@
1
1
  import { TObject, TUnion, TString, TSchema, TNever, TLiteral, Static } from '@sinclair/typebox';
2
2
  import { Pushable } from 'it-pushable';
3
- import { b as TransportClientId, f as Session, C as Connection } from './index-80f87385.js';
3
+ import { c as TransportClientId, a as Session, C as Connection } from './index-9e300e8a.js';
4
4
 
5
5
  type TLiteralString = TLiteral<string>;
6
6
  type RiverErrorSchema = TObject<{
@@ -1,7 +1,7 @@
1
1
  import { TUnion, Static } from '@sinclair/typebox';
2
- import { e as ProcedureMap, P as PayloadType, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, R as RiverError, b as Result, S as ServiceContext } from '../procedures-79a5f07e.js';
3
- export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-79a5f07e.js';
4
- import { d as ServerTransport, C as Connection, a as ClientTransport, b as TransportClientId } from '../index-80f87385.js';
2
+ import { e as ProcedureMap, P as PayloadType, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, R as RiverError, b as Result, S as ServiceContext } from '../procedures-1c0d2eee.js';
3
+ export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-1c0d2eee.js';
4
+ import { e as ServerTransport, C as Connection, b as ClientTransport, c as TransportClientId } from '../index-9e300e8a.js';
5
5
  import { Pushable } from 'it-pushable';
6
6
  import '../types-3e5768ec.js';
7
7
 
@@ -1,7 +1,7 @@
1
1
  import { TUnion, Static } from '@sinclair/typebox';
2
- import { e as ProcedureMap, P as PayloadType, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, R as RiverError, b as Result, S as ServiceContext } from '../procedures-79a5f07e.js';
3
- export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-79a5f07e.js';
4
- import { d as ServerTransport, C as Connection, a as ClientTransport, b as TransportClientId } from '../index-80f87385.js';
2
+ import { e as ProcedureMap, P as PayloadType, c as RiverUncaughtSchema, U as Unbranded, B as Branded, A as AnyProcedure, R as RiverError, b as Result, S as ServiceContext } from '../procedures-1c0d2eee.js';
3
+ export { E as Err, O as Ok, a as Procedure, d as ProcedureResult, f as RPCProcedure, m as RiverErrorSchema, j as ServiceContextWithState, k as ServiceContextWithTransportInfo, i as StreamProcedure, h as SubscriptionProcedure, l as UNCAUGHT_ERROR, g as UploadProcedure, V as ValidProcType } from '../procedures-1c0d2eee.js';
4
+ import { e as ServerTransport, C as Connection, b as ClientTransport, c as TransportClientId } from '../index-9e300e8a.js';
5
5
  import { Pushable } from 'it-pushable';
6
6
  import '../types-3e5768ec.js';
7
7
 
@@ -1,5 +1,5 @@
1
- import { a as ClientTransport, c as ProvidedClientTransportOptions, b as TransportClientId } from '../../../index-80f87385.js';
2
- import { U as UdsConnection } from '../../../connection-713c8c66.js';
1
+ import { b as ClientTransport, d as ProvidedClientTransportOptions, c as TransportClientId } from '../../../index-9e300e8a.js';
2
+ import { U as UdsConnection } from '../../../connection-bdbd20da.js';
3
3
  import '../../../types-3e5768ec.js';
4
4
  import '@sinclair/typebox';
5
5
  import 'node:net';
@@ -1,5 +1,5 @@
1
- import { a as ClientTransport, c as ProvidedClientTransportOptions, b as TransportClientId } from '../../../index-80f87385.js';
2
- import { U as UdsConnection } from '../../../connection-713c8c66.js';
1
+ import { b as ClientTransport, d as ProvidedClientTransportOptions, c as TransportClientId } from '../../../index-9e300e8a.js';
2
+ import { U as UdsConnection } from '../../../connection-bdbd20da.js';
3
3
  import '../../../types-3e5768ec.js';
4
4
  import '@sinclair/typebox';
5
5
  import 'node:net';
@@ -1,6 +1,6 @@
1
1
  import { Server, Socket } from 'node:net';
2
- import { d as ServerTransport, b as TransportClientId, e as ProvidedTransportOptions } from '../../../index-80f87385.js';
3
- import { U as UdsConnection } from '../../../connection-713c8c66.js';
2
+ import { e as ServerTransport, c as TransportClientId, f as ProvidedTransportOptions } from '../../../index-9e300e8a.js';
3
+ import { U as UdsConnection } from '../../../connection-bdbd20da.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
  import 'node:stream';
@@ -1,6 +1,6 @@
1
1
  import { Server, Socket } from 'node:net';
2
- import { d as ServerTransport, b as TransportClientId, e as ProvidedTransportOptions } from '../../../index-80f87385.js';
3
- import { U as UdsConnection } from '../../../connection-713c8c66.js';
2
+ import { e as ServerTransport, c as TransportClientId, f as ProvidedTransportOptions } from '../../../index-9e300e8a.js';
3
+ import { U as UdsConnection } from '../../../connection-bdbd20da.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
  import 'node:stream';
@@ -1,6 +1,6 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { a as ClientTransport, b as TransportClientId, c as ProvidedClientTransportOptions } from '../../../index-80f87385.js';
3
- import { W as WebSocketConnection } from '../../../connection-b79329de.js';
2
+ import { b as ClientTransport, c as TransportClientId, d as ProvidedClientTransportOptions } from '../../../index-9e300e8a.js';
3
+ import { W as WebSocketConnection } from '../../../connection-c4a17403.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- import { a as ClientTransport, b as TransportClientId, c as ProvidedClientTransportOptions } from '../../../index-80f87385.js';
3
- import { W as WebSocketConnection } from '../../../connection-b79329de.js';
2
+ import { b as ClientTransport, c as TransportClientId, d as ProvidedClientTransportOptions } from '../../../index-9e300e8a.js';
3
+ import { W as WebSocketConnection } from '../../../connection-c4a17403.js';
4
4
  import '../../../types-3e5768ec.js';
5
5
  import '@sinclair/typebox';
6
6
 
@@ -1,7 +1,7 @@
1
- import { d as ServerTransport, b as TransportClientId, e as ProvidedTransportOptions } from '../../../index-80f87385.js';
1
+ import { e as ServerTransport, c as TransportClientId, f as ProvidedTransportOptions } from '../../../index-9e300e8a.js';
2
2
  import { WebSocketServer } from 'ws';
3
3
  import { WebSocket } from 'isomorphic-ws';
4
- import { W as WebSocketConnection } from '../../../connection-b79329de.js';
4
+ import { W as WebSocketConnection } from '../../../connection-c4a17403.js';
5
5
  import '../../../types-3e5768ec.js';
6
6
  import '@sinclair/typebox';
7
7
 
@@ -1,7 +1,7 @@
1
- import { d as ServerTransport, b as TransportClientId, e as ProvidedTransportOptions } from '../../../index-80f87385.js';
1
+ import { e as ServerTransport, c as TransportClientId, f as ProvidedTransportOptions } from '../../../index-9e300e8a.js';
2
2
  import { WebSocketServer } from 'ws';
3
3
  import { WebSocket } from 'isomorphic-ws';
4
- import { W as WebSocketConnection } from '../../../connection-b79329de.js';
4
+ import { W as WebSocketConnection } from '../../../connection-c4a17403.js';
5
5
  import '../../../types-3e5768ec.js';
6
6
  import '@sinclair/typebox';
7
7
 
@@ -1,3 +1,3 @@
1
- export { a as ClientTransport, c as ClientTransportOptions, C as Connection, n as EventHandler, E as EventMap, m as EventTypes, O as OpaqueTransportMessage, i as OpaqueTransportMessageSchema, o as ProtocolError, p as ProtocolErrorType, d as ServerTransport, f as Session, T as Transport, b as TransportClientId, j as TransportMessage, h as TransportMessageSchema, e as TransportOptions, g as TransportStatus, l as isStreamClose, k as isStreamOpen } from '../index-80f87385.js';
1
+ export { b as ClientTransport, d as ClientTransportOptions, C as Connection, n as EventHandler, E as EventMap, m as EventTypes, O as OpaqueTransportMessage, i as OpaqueTransportMessageSchema, o as ProtocolError, p as ProtocolErrorType, e as ServerTransport, a as Session, T as Transport, c as TransportClientId, j as TransportMessage, h as TransportMessageSchema, f as TransportOptions, g as TransportStatus, l as isStreamClose, k as isStreamOpen } from '../index-9e300e8a.js';
2
2
  import '../types-3e5768ec.js';
3
3
  import '@sinclair/typebox';
@@ -1,3 +1,3 @@
1
- export { a as ClientTransport, c as ClientTransportOptions, C as Connection, n as EventHandler, E as EventMap, m as EventTypes, O as OpaqueTransportMessage, i as OpaqueTransportMessageSchema, o as ProtocolError, p as ProtocolErrorType, d as ServerTransport, f as Session, T as Transport, b as TransportClientId, j as TransportMessage, h as TransportMessageSchema, e as TransportOptions, g as TransportStatus, l as isStreamClose, k as isStreamOpen } from '../index-80f87385.js';
1
+ export { b as ClientTransport, d as ClientTransportOptions, C as Connection, n as EventHandler, E as EventMap, m as EventTypes, O as OpaqueTransportMessage, i as OpaqueTransportMessageSchema, o as ProtocolError, p as ProtocolErrorType, e as ServerTransport, a as Session, T as Transport, c as TransportClientId, j as TransportMessage, h as TransportMessageSchema, f as TransportOptions, g as TransportStatus, l as isStreamClose, k as isStreamOpen } from '../index-9e300e8a.js';
2
2
  import '../types-3e5768ec.js';
3
3
  import '@sinclair/typebox';
@@ -696,28 +696,30 @@ function catchProcError(err) {
696
696
  };
697
697
  }
698
698
  var testingSessionOptions = defaultTransportOptions;
699
- function dummyCtx(state, extendedContext) {
700
- const session = new Session(
699
+ function dummySession() {
700
+ return new Session(
701
701
  void 0,
702
702
  "client",
703
- "SERVER",
703
+ "server",
704
704
  testingSessionOptions
705
705
  );
706
+ }
707
+ function dummyCtx(state, session, extendedContext) {
706
708
  return {
707
709
  ...extendedContext,
708
710
  state,
709
- to: "SERVER",
710
- from: "client",
711
+ to: session.to,
712
+ from: session.from,
711
713
  streamId: (0, import_nanoid2.nanoid)(),
712
714
  session
713
715
  };
714
716
  }
715
- function asClientRpc(state, proc, extendedContext) {
717
+ function asClientRpc(state, proc, extendedContext, session = dummySession()) {
716
718
  return async (msg) => {
717
- return await proc.handler(dummyCtx(state, extendedContext), msg).catch(catchProcError);
719
+ return await proc.handler(dummyCtx(state, session, extendedContext), msg).catch(catchProcError);
718
720
  };
719
721
  }
720
- function asClientStream(state, proc, init, extendedContext) {
722
+ function asClientStream(state, proc, init, extendedContext, session = dummySession()) {
721
723
  const input = pushable({ objectMode: true });
722
724
  const output = pushable({
723
725
  objectMode: true
@@ -725,34 +727,34 @@ function asClientStream(state, proc, init, extendedContext) {
725
727
  void (async () => {
726
728
  if (init) {
727
729
  const _proc = proc;
728
- await _proc.handler(dummyCtx(state, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
730
+ await _proc.handler(dummyCtx(state, session, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
729
731
  } else {
730
732
  const _proc = proc;
731
- await _proc.handler(dummyCtx(state, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
733
+ await _proc.handler(dummyCtx(state, session, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
732
734
  }
733
735
  })();
734
736
  return [input, output];
735
737
  }
736
- function asClientSubscription(state, proc, extendedContext) {
738
+ function asClientSubscription(state, proc, extendedContext, session = dummySession()) {
737
739
  const output = pushable({
738
740
  objectMode: true
739
741
  });
740
742
  return (msg) => {
741
743
  void (async () => {
742
- return await proc.handler(dummyCtx(state, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
744
+ return await proc.handler(dummyCtx(state, session, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
743
745
  })();
744
746
  return output;
745
747
  };
746
748
  }
747
- function asClientUpload(state, proc, init, extendedContext) {
749
+ function asClientUpload(state, proc, init, extendedContext, session = dummySession()) {
748
750
  const input = pushable({ objectMode: true });
749
751
  if (init) {
750
752
  const _proc = proc;
751
- const result = _proc.handler(dummyCtx(state, extendedContext), init, input).catch(catchProcError);
753
+ const result = _proc.handler(dummyCtx(state, session, extendedContext), init, input).catch(catchProcError);
752
754
  return [input, result];
753
755
  } else {
754
756
  const _proc = proc;
755
- const result = _proc.handler(dummyCtx(state, extendedContext), input).catch(catchProcError);
757
+ const result = _proc.handler(dummyCtx(state, session, extendedContext), input).catch(catchProcError);
756
758
  return [input, result];
757
759
  }
758
760
  }
@@ -1,6 +1,6 @@
1
1
  import { Static } from '@sinclair/typebox';
2
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../procedures-79a5f07e.js';
3
- import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage, S as SessionOptions } from '../index-80f87385.js';
2
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../procedures-1c0d2eee.js';
3
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage, S as SessionOptions, a as Session } from '../index-9e300e8a.js';
4
4
  import * as it_pushable from 'it-pushable';
5
5
  import WebSocket from 'isomorphic-ws';
6
6
  import http from 'node:http';
@@ -49,10 +49,10 @@ declare function createDummyTransportMessage(): PartialTransportMessage<{
49
49
  */
50
50
  declare function waitForMessage(t: Transport<Connection>, filter?: (msg: OpaqueTransportMessage) => boolean, rejectMismatch?: boolean): Promise<unknown>;
51
51
  declare const testingSessionOptions: SessionOptions;
52
- declare function asClientRpc<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
53
- declare function asClientStream<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
54
- declare function asClientSubscription<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
55
- declare function asClientUpload<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
52
+ declare function asClientRpc<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
53
+ declare function asClientStream<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
54
+ declare function asClientSubscription<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): (msg: Static<I>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
55
+ declare function asClientUpload<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
56
56
  ok: boolean;
57
57
  payload: {
58
58
  code: string;
@@ -1,6 +1,6 @@
1
1
  import { Static } from '@sinclair/typebox';
2
- import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../procedures-79a5f07e.js';
3
- import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage, S as SessionOptions } from '../index-80f87385.js';
2
+ import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../procedures-1c0d2eee.js';
3
+ import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage, S as SessionOptions, a as Session } from '../index-9e300e8a.js';
4
4
  import * as it_pushable from 'it-pushable';
5
5
  import WebSocket from 'isomorphic-ws';
6
6
  import http from 'node:http';
@@ -49,10 +49,10 @@ declare function createDummyTransportMessage(): PartialTransportMessage<{
49
49
  */
50
50
  declare function waitForMessage(t: Transport<Connection>, filter?: (msg: OpaqueTransportMessage) => boolean, rejectMismatch?: boolean): Promise<unknown>;
51
51
  declare const testingSessionOptions: SessionOptions;
52
- declare function asClientRpc<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
53
- declare function asClientStream<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
54
- declare function asClientSubscription<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>): (msg: Static<I>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
55
- declare function asClientUpload<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
52
+ declare function asClientRpc<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'rpc', I, O, E, Init>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): (msg: Static<I>) => Promise<Result<Static<O>, Static<E> | Static<typeof RiverUncaughtSchema>>>;
53
+ declare function asClientStream<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'stream', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>];
54
+ declare function asClientSubscription<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError>(state: State, proc: Procedure<State, 'subscription', I, O, E>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): (msg: Static<I>) => it_pushable.Pushable<Result<Static<O>, Static<E>>, void, unknown>;
55
+ declare function asClientUpload<State extends object, I extends PayloadType, O extends PayloadType, E extends RiverError, Init extends PayloadType | null = null>(state: State, proc: Procedure<State, 'upload', I, O, E, Init>, init?: Init extends PayloadType ? Static<Init> : null, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): readonly [it_pushable.Pushable<Static<I>, void, unknown>, Promise<{
56
56
  ok: boolean;
57
57
  payload: {
58
58
  code: string;
@@ -86,28 +86,30 @@ function catchProcError(err) {
86
86
  };
87
87
  }
88
88
  var testingSessionOptions = defaultTransportOptions;
89
- function dummyCtx(state, extendedContext) {
90
- const session = new Session(
89
+ function dummySession() {
90
+ return new Session(
91
91
  void 0,
92
92
  "client",
93
- "SERVER",
93
+ "server",
94
94
  testingSessionOptions
95
95
  );
96
+ }
97
+ function dummyCtx(state, session, extendedContext) {
96
98
  return {
97
99
  ...extendedContext,
98
100
  state,
99
- to: "SERVER",
100
- from: "client",
101
+ to: session.to,
102
+ from: session.from,
101
103
  streamId: nanoid(),
102
104
  session
103
105
  };
104
106
  }
105
- function asClientRpc(state, proc, extendedContext) {
107
+ function asClientRpc(state, proc, extendedContext, session = dummySession()) {
106
108
  return async (msg) => {
107
- return await proc.handler(dummyCtx(state, extendedContext), msg).catch(catchProcError);
109
+ return await proc.handler(dummyCtx(state, session, extendedContext), msg).catch(catchProcError);
108
110
  };
109
111
  }
110
- function asClientStream(state, proc, init, extendedContext) {
112
+ function asClientStream(state, proc, init, extendedContext, session = dummySession()) {
111
113
  const input = pushable({ objectMode: true });
112
114
  const output = pushable({
113
115
  objectMode: true
@@ -115,34 +117,34 @@ function asClientStream(state, proc, init, extendedContext) {
115
117
  void (async () => {
116
118
  if (init) {
117
119
  const _proc = proc;
118
- await _proc.handler(dummyCtx(state, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
120
+ await _proc.handler(dummyCtx(state, session, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err)));
119
121
  } else {
120
122
  const _proc = proc;
121
- await _proc.handler(dummyCtx(state, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
123
+ await _proc.handler(dummyCtx(state, session, extendedContext), input, output).catch((err) => output.push(catchProcError(err)));
122
124
  }
123
125
  })();
124
126
  return [input, output];
125
127
  }
126
- function asClientSubscription(state, proc, extendedContext) {
128
+ function asClientSubscription(state, proc, extendedContext, session = dummySession()) {
127
129
  const output = pushable({
128
130
  objectMode: true
129
131
  });
130
132
  return (msg) => {
131
133
  void (async () => {
132
- return await proc.handler(dummyCtx(state, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
134
+ return await proc.handler(dummyCtx(state, session, extendedContext), msg, output).catch((err) => output.push(catchProcError(err)));
133
135
  })();
134
136
  return output;
135
137
  };
136
138
  }
137
- function asClientUpload(state, proc, init, extendedContext) {
139
+ function asClientUpload(state, proc, init, extendedContext, session = dummySession()) {
138
140
  const input = pushable({ objectMode: true });
139
141
  if (init) {
140
142
  const _proc = proc;
141
- const result = _proc.handler(dummyCtx(state, extendedContext), init, input).catch(catchProcError);
143
+ const result = _proc.handler(dummyCtx(state, session, extendedContext), init, input).catch(catchProcError);
142
144
  return [input, result];
143
145
  } else {
144
146
  const _proc = proc;
145
- const result = _proc.handler(dummyCtx(state, extendedContext), input).catch(catchProcError);
147
+ const result = _proc.handler(dummyCtx(state, session, extendedContext), input).catch(catchProcError);
146
148
  return [input, result];
147
149
  }
148
150
  }
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.17.3",
4
+ "version": "0.17.4",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {