@replit/river
Advanced tools
Comparing version 0.12.6 to 0.13.0
@@ -1,4 +0,4 @@ | ||
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-c593de11.js'; | ||
export { E as Err, O as Ok, m as ProcHandler, k as ProcListing, a as Procedure, o as RiverErrorSchema, c as RiverUncaughtSchema, l as Service, j as ServiceBuilder, n as ServiceContextWithState, U as UNCAUGHT_ERROR, V as ValidProcType, s as serializeService } from '../builder-c593de11.js'; | ||
import { T as Transport, C as Connection, b as TransportClientId } from '../index-54e0f99c.js'; | ||
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-169fbf7f.js'; | ||
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-169fbf7f.js'; | ||
import { S as ServerTransport, C as Connection, a as ClientTransport } from '../index-21c1b21d.js'; | ||
import { Pushable } from 'it-pushable'; | ||
@@ -53,3 +53,3 @@ import { Static } from '@sinclair/typebox'; | ||
*/ | ||
declare function createServer<Services extends ServiceDefs>(transport: Transport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>; | ||
declare function createServer<Services extends ServiceDefs>(transport: ServerTransport<Connection>, services: Services, extendedContext?: Omit<ServiceContext, 'state'>): Server<Services>; | ||
@@ -114,4 +114,4 @@ type AsyncIter<T> = AsyncGenerator<T, T>; | ||
*/ | ||
declare const createClient: <Srv extends Server<ServiceDefs>>(transport: Transport<Connection>, serverId?: TransportClientId) => ServerClient<Srv>; | ||
declare const createClient: <Srv extends Server<ServiceDefs>>(transport: ClientTransport<Connection>) => ServerClient<Srv>; | ||
export { PayloadType, ProcInput, ProcOutput, ProcType, Result, RiverError, Server, ServerClient, ServiceContext, ServiceDefs, buildServiceDefs, createClient, createServer }; |
@@ -11,4 +11,4 @@ import { | ||
serializeService | ||
} from "../chunk-AFLZ6INU.js"; | ||
import "../chunk-XFFS4UOD.js"; | ||
} from "../chunk-CBRQM65K.js"; | ||
import "../chunk-MGGIUH5O.js"; | ||
import "../chunk-H4BYJELI.js"; | ||
@@ -15,0 +15,0 @@ export { |
@@ -1,7 +0,6 @@ | ||
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-54e0f99c.js'; | ||
import { U as UdsConnection } from '../../../connection-24d878ac.js'; | ||
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js'; | ||
import { U as UdsConnection } from '../../../connection-dd789651.js'; | ||
import '../../../types-3e5768ec.js'; | ||
import '@sinclair/typebox'; | ||
import 'node:net'; | ||
import '../../../messageFraming-b200ef25.js'; | ||
import 'node:stream'; | ||
@@ -8,0 +7,0 @@ |
import { | ||
UdsConnection | ||
} from "../../../chunk-PBPXYLI6.js"; | ||
import "../../../chunk-IIBVKYDB.js"; | ||
} from "../../../chunk-CDH7QSB4.js"; | ||
import { | ||
ClientTransport | ||
} from "../../../chunk-4SDJ5VN4.js"; | ||
import "../../../chunk-GZ7HCLLM.js"; | ||
import "../../../chunk-XFFS4UOD.js"; | ||
} from "../../../chunk-R2IMXRVU.js"; | ||
import "../../../chunk-MGGIUH5O.js"; | ||
import { | ||
log | ||
} from "../../../chunk-H4BYJELI.js"; | ||
import "../../../chunk-GZ7HCLLM.js"; | ||
@@ -20,3 +19,3 @@ // transport/impls/uds/client.ts | ||
constructor(socketPath, clientId, serverId, providedOptions) { | ||
super(clientId, providedOptions); | ||
super(clientId, serverId, providedOptions); | ||
this.path = socketPath; | ||
@@ -23,0 +22,0 @@ this.serverId = serverId; |
import { Server, Socket } from 'node:net'; | ||
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-54e0f99c.js'; | ||
import { U as UdsConnection } from '../../../connection-24d878ac.js'; | ||
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js'; | ||
import { U as UdsConnection } from '../../../connection-dd789651.js'; | ||
import '../../../types-3e5768ec.js'; | ||
import '@sinclair/typebox'; | ||
import '../../../messageFraming-b200ef25.js'; | ||
import 'node:stream'; | ||
@@ -8,0 +7,0 @@ |
import { | ||
UdsConnection | ||
} from "../../../chunk-PBPXYLI6.js"; | ||
import "../../../chunk-IIBVKYDB.js"; | ||
} from "../../../chunk-CDH7QSB4.js"; | ||
import { | ||
ServerTransport | ||
} from "../../../chunk-4SDJ5VN4.js"; | ||
import "../../../chunk-GZ7HCLLM.js"; | ||
import "../../../chunk-XFFS4UOD.js"; | ||
} from "../../../chunk-R2IMXRVU.js"; | ||
import "../../../chunk-MGGIUH5O.js"; | ||
import { | ||
log | ||
} from "../../../chunk-H4BYJELI.js"; | ||
import "../../../chunk-GZ7HCLLM.js"; | ||
@@ -14,0 +13,0 @@ // transport/impls/uds/server.ts |
import WebSocket from 'isomorphic-ws'; | ||
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-54e0f99c.js'; | ||
import { W as WebSocketConnection } from '../../../connection-ba37d174.js'; | ||
import { a as ClientTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js'; | ||
import { W as WebSocketConnection } from '../../../connection-ab681c08.js'; | ||
import '../../../types-3e5768ec.js'; | ||
@@ -21,7 +21,7 @@ import '@sinclair/typebox'; | ||
* @param wsGetter A function that returns a Promise that resolves to a WebSocket instance. | ||
* @param sessionId The ID of the client using the transport. This should be unique per session. | ||
* @param clientId The ID of the client using the transport. This should be unique per session. | ||
* @param serverId The ID of the server this transport is connecting to. | ||
* @param providedOptions An optional object containing configuration options for the transport. | ||
*/ | ||
constructor(wsGetter: () => Promise<WebSocket>, sessionId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<TransportOptions>); | ||
constructor(wsGetter: () => Promise<WebSocket>, clientId: TransportClientId, serverId: TransportClientId, providedOptions?: Partial<TransportOptions>); | ||
reopen(): void; | ||
@@ -28,0 +28,0 @@ createNewOutgoingConnection(to: string): Promise<WebSocketConnection>; |
import { | ||
WebSocketConnection | ||
} from "../../../chunk-VLBVQX5H.js"; | ||
} from "../../../chunk-NPXAAD7M.js"; | ||
import { | ||
ClientTransport | ||
} from "../../../chunk-4SDJ5VN4.js"; | ||
import "../../../chunk-GZ7HCLLM.js"; | ||
import "../../../chunk-XFFS4UOD.js"; | ||
} from "../../../chunk-R2IMXRVU.js"; | ||
import "../../../chunk-MGGIUH5O.js"; | ||
import { | ||
log | ||
} from "../../../chunk-H4BYJELI.js"; | ||
import "../../../chunk-GZ7HCLLM.js"; | ||
@@ -23,8 +23,8 @@ // transport/impls/ws/client.ts | ||
* @param wsGetter A function that returns a Promise that resolves to a WebSocket instance. | ||
* @param sessionId The ID of the client using the transport. This should be unique per session. | ||
* @param clientId The ID of the client using the transport. This should be unique per session. | ||
* @param serverId The ID of the server this transport is connecting to. | ||
* @param providedOptions An optional object containing configuration options for the transport. | ||
*/ | ||
constructor(wsGetter, sessionId, serverId, providedOptions) { | ||
super(sessionId, providedOptions); | ||
constructor(wsGetter, clientId, serverId, providedOptions) { | ||
super(clientId, serverId, providedOptions); | ||
this.wsGetter = wsGetter; | ||
@@ -31,0 +31,0 @@ this.serverId = serverId; |
@@ -1,5 +0,5 @@ | ||
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-54e0f99c.js'; | ||
import { S as ServerTransport, b as TransportClientId, c as TransportOptions } from '../../../index-21c1b21d.js'; | ||
import { WebSocketServer } from 'ws'; | ||
import { WebSocket } from 'isomorphic-ws'; | ||
import { W as WebSocketConnection } from '../../../connection-ba37d174.js'; | ||
import { W as WebSocketConnection } from '../../../connection-ab681c08.js'; | ||
import '../../../types-3e5768ec.js'; | ||
@@ -6,0 +6,0 @@ import '@sinclair/typebox'; |
import { | ||
WebSocketConnection | ||
} from "../../../chunk-VLBVQX5H.js"; | ||
} from "../../../chunk-NPXAAD7M.js"; | ||
import { | ||
ServerTransport | ||
} from "../../../chunk-4SDJ5VN4.js"; | ||
import "../../../chunk-GZ7HCLLM.js"; | ||
import "../../../chunk-XFFS4UOD.js"; | ||
} from "../../../chunk-R2IMXRVU.js"; | ||
import "../../../chunk-MGGIUH5O.js"; | ||
import { | ||
log | ||
} from "../../../chunk-H4BYJELI.js"; | ||
import "../../../chunk-GZ7HCLLM.js"; | ||
@@ -13,0 +13,0 @@ // transport/impls/ws/server.ts |
@@ -1,3 +0,3 @@ | ||
export { a as ClientTransport, C as Connection, k as EventHandler, E as EventMap, j as EventTypes, O as OpaqueTransportMessage, f as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, g as TransportMessage, e as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-54e0f99c.js'; | ||
export { a as ClientTransport, C as Connection, k as EventHandler, E as EventMap, j as EventTypes, O as OpaqueTransportMessage, f as OpaqueTransportMessageSchema, S as ServerTransport, d as Session, T as Transport, b as TransportClientId, g as TransportMessage, e as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-21c1b21d.js'; | ||
import '../types-3e5768ec.js'; | ||
import '@sinclair/typebox'; |
@@ -8,9 +8,9 @@ import "../chunk-5IZ2UHWV.js"; | ||
Transport | ||
} from "../chunk-4SDJ5VN4.js"; | ||
import "../chunk-GZ7HCLLM.js"; | ||
} from "../chunk-R2IMXRVU.js"; | ||
import { | ||
OpaqueTransportMessageSchema, | ||
TransportMessageSchema | ||
} from "../chunk-XFFS4UOD.js"; | ||
} from "../chunk-MGGIUH5O.js"; | ||
import "../chunk-H4BYJELI.js"; | ||
import "../chunk-GZ7HCLLM.js"; | ||
export { | ||
@@ -17,0 +17,0 @@ ClientTransport, |
import * as it_pushable from 'it-pushable'; | ||
import WebSocket from 'isomorphic-ws'; | ||
import http from 'node:http'; | ||
import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-54e0f99c.js'; | ||
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-c593de11.js'; | ||
import { P as PartialTransportMessage, T as Transport, C as Connection, O as OpaqueTransportMessage } from '../index-21c1b21d.js'; | ||
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema } from '../builder-169fbf7f.js'; | ||
import { Static } from '@sinclair/typebox'; | ||
@@ -7,0 +7,0 @@ import net from 'node:net'; |
import { | ||
UNCAUGHT_ERROR, | ||
pushable | ||
} from "../chunk-AFLZ6INU.js"; | ||
} from "../chunk-CBRQM65K.js"; | ||
import "../chunk-5IZ2UHWV.js"; | ||
import { | ||
Session, | ||
defaultSessionOptions | ||
} from "../chunk-R2IMXRVU.js"; | ||
import { | ||
coerceErrorString | ||
} from "../chunk-XFFS4UOD.js"; | ||
} from "../chunk-MGGIUH5O.js"; | ||
import "../chunk-H4BYJELI.js"; | ||
import "../chunk-GZ7HCLLM.js"; | ||
@@ -81,5 +87,21 @@ // util/testHelpers.ts | ||
} | ||
function dummyCtx(state, extendedContext) { | ||
const session = new Session( | ||
"client", | ||
"SERVER", | ||
void 0, | ||
defaultSessionOptions | ||
); | ||
return { | ||
...extendedContext, | ||
state, | ||
to: "SERVER", | ||
from: "client", | ||
streamId: nanoid(), | ||
session | ||
}; | ||
} | ||
function asClientRpc(state, proc, extendedContext) { | ||
return async (msg) => { | ||
return await proc.handler({ ...extendedContext, state }, msg).catch(catchProcError); | ||
return await proc.handler(dummyCtx(state, extendedContext), msg).catch(catchProcError); | ||
}; | ||
@@ -95,6 +117,6 @@ } | ||
const _proc = proc; | ||
await _proc.handler({ ...extendedContext, state }, init, input, output).catch((err) => output.push(catchProcError(err))); | ||
await _proc.handler(dummyCtx(state, extendedContext), init, input, output).catch((err) => output.push(catchProcError(err))); | ||
} else { | ||
const _proc = proc; | ||
await _proc.handler({ ...extendedContext, state }, input, output).catch((err) => output.push(catchProcError(err))); | ||
await _proc.handler(dummyCtx(state, extendedContext), input, output).catch((err) => output.push(catchProcError(err))); | ||
} | ||
@@ -110,3 +132,3 @@ })(); | ||
void (async () => { | ||
return await proc.handler({ ...extendedContext, state }, msg, output).catch((err) => output.push(catchProcError(err))); | ||
return await proc.handler(dummyCtx(state, extendedContext), msg, output).catch((err) => output.push(catchProcError(err))); | ||
})(); | ||
@@ -120,7 +142,7 @@ return output; | ||
const _proc = proc; | ||
const result = _proc.handler({ ...extendedContext, state }, init, input).catch(catchProcError); | ||
const result = _proc.handler(dummyCtx(state, extendedContext), init, input).catch(catchProcError); | ||
return [input, result]; | ||
} else { | ||
const _proc = proc; | ||
const result = _proc.handler({ ...extendedContext, state }, input).catch(catchProcError); | ||
const result = _proc.handler(dummyCtx(state, extendedContext), input).catch(catchProcError); | ||
return [input, result]; | ||
@@ -127,0 +149,0 @@ } |
{ | ||
"name": "@replit/river", | ||
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!", | ||
"version": "0.12.6", | ||
"version": "0.13.0", | ||
"type": "module", | ||
@@ -39,10 +39,2 @@ "exports": { | ||
}, | ||
"./transport/stdio/client": { | ||
"import": "./dist/transport/impls/stdio/client.js", | ||
"require": "./dist/transport/impls/stdio/client.cjs" | ||
}, | ||
"./transport/stdio/server": { | ||
"import": "./dist/transport/impls/stdio/server.js", | ||
"require": "./dist/transport/impls/stdio/server.cjs" | ||
}, | ||
"./test-util": { | ||
@@ -49,0 +41,0 @@ "import": "./dist/util/testHelpers.js", |
@@ -11,3 +11,3 @@ # river - Long-lived Streaming Remote Procedure Calls | ||
- transparent reconnect support for long-lived sessions | ||
- over any transport (WebSockets, stdio, Unix Domain Socket out of the box) | ||
- over any transport (WebSockets and Unix Domain Socket out of the box) | ||
@@ -51,2 +51,3 @@ ## Installation | ||
ServiceBuilder.create('example') | ||
// initializer for shared state | ||
.initialState({ | ||
@@ -60,3 +61,5 @@ count: 0, | ||
errors: Type.Never(), | ||
// note that a handler is unique per user RPC | ||
async handler(ctx, { n }) { | ||
// access and mutate shared state | ||
ctx.state.count += n; | ||
@@ -63,0 +66,0 @@ return Ok({ result: ctx.state.count }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179
341974
52
10076