@replit/river
Advanced tools
Comparing version 0.21.1 to 0.22.0
@@ -1,3 +0,4 @@ | ||
export { m as LogFn, L as Logger, M as MessageMetadata, l as bindLogger, j as coloredStringLogger, k as jsonLogger, s as stringLogger } from '../index-dfad460e.js'; | ||
export { n as LogFn, L as Logger, M as MessageMetadata, m as bindLogger, k as coloredStringLogger, l as jsonLogger, s as stringLogger } from '../index-2ece5234.js'; | ||
import '@sinclair/typebox'; | ||
import '../types-3e5768ec.js'; | ||
import '@opentelemetry/api'; |
@@ -1,8 +0,9 @@ | ||
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-9c496c6e.js'; | ||
export { C as Client, E as Err, O as Ok, B as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, o as ProcedureMap, d as ProcedureResult, p as RPCProcedure, z as ResultUnwrapErr, y as ResultUnwrapOk, x as RiverErrorSchema, c as RiverUncaughtSchema, n as SerializedServerSchema, e as Service, f as ServiceConfiguration, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, m as ServiceSchema, r as StreamProcedure, q as SubscriptionProcedure, w as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, t as createClient, s as serializeSchema } from '../services-9c496c6e.js'; | ||
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, P as PayloadType, b as Result, R as RiverError, S as ServiceContext } from '../services-cb01a7a8.js'; | ||
export { C as Client, E as Err, O as Ok, B as Output, k as ProcErrors, g as ProcHandler, h as ProcInit, i as ProcInput, j as ProcOutput, l as ProcType, a as Procedure, o as ProcedureMap, d as ProcedureResult, p as RPCProcedure, z as ResultUnwrapErr, y as ResultUnwrapOk, x as RiverErrorSchema, c as RiverUncaughtSchema, n as SerializedServerSchema, e as Service, f as ServiceConfiguration, u as ServiceContextWithState, v as ServiceContextWithTransportInfo, m as ServiceSchema, r as StreamProcedure, q as SubscriptionProcedure, w as UNCAUGHT_ERROR, U as UploadProcedure, V as ValidProcType, t as createClient, s as serializeSchema } from '../services-cb01a7a8.js'; | ||
import { Static } from '@sinclair/typebox'; | ||
import { ServerTransport } from '../transport/index.js'; | ||
import { Pushable } from 'it-pushable'; | ||
import { C as Connection } from '../index-dfad460e.js'; | ||
import { C as Connection } from '../index-2ece5234.js'; | ||
import '../types-3e5768ec.js'; | ||
import '@opentelemetry/api'; | ||
@@ -39,4 +40,4 @@ /** | ||
var version = "0.21.1"; | ||
var version = "0.22.0"; | ||
export { PayloadType, version as RIVER_VERSION, Result, RiverError, Server, ServiceContext, createServer }; |
@@ -10,6 +10,7 @@ import { | ||
createServer, | ||
serializeSchema, | ||
serializeSchema | ||
} from "../chunk-GCLEWC26.js"; | ||
import { | ||
version | ||
} from "../chunk-NCXUFDVL.js"; | ||
import "../chunk-5WFL722S.js"; | ||
} from "../chunk-3MFX6NXA.js"; | ||
import "../chunk-OTQNCLFH.js"; | ||
@@ -16,0 +17,0 @@ export { |
@@ -1,4 +0,4 @@ | ||
import { U as UdsConnection } from '../../../connection-975b25c9.js'; | ||
import { U as UdsConnection } from '../../../connection-bbfe1147.js'; | ||
import { ClientTransport, ClientTransportOptions as ProvidedClientTransportOptions } from '../../index.js'; | ||
import { T as TransportClientId } from '../../../index-dfad460e.js'; | ||
import { T as TransportClientId } from '../../../index-2ece5234.js'; | ||
import 'node:net'; | ||
@@ -8,2 +8,3 @@ import 'node:stream'; | ||
import '@sinclair/typebox'; | ||
import '@opentelemetry/api'; | ||
@@ -10,0 +11,0 @@ declare class UnixDomainSocketClientTransport extends ClientTransport<UdsConnection> { |
import { | ||
UdsConnection | ||
} from "../../../chunk-FDLAPYCK.js"; | ||
} from "../../../chunk-S3YKQT4J.js"; | ||
import { | ||
ClientTransport | ||
} from "../../../chunk-JMXO5L2X.js"; | ||
import "../../../chunk-5WFL722S.js"; | ||
} from "../../../chunk-ZPBWKBM5.js"; | ||
import "../../../chunk-3MFX6NXA.js"; | ||
import { | ||
@@ -9,0 +9,0 @@ log |
import { Server, Socket } from 'node:net'; | ||
import { ServerTransport, ServerTransportOptions as ProvidedServerTransportOptions } from '../../index.js'; | ||
import { T as TransportClientId } from '../../../index-dfad460e.js'; | ||
import { U as UdsConnection } from '../../../connection-975b25c9.js'; | ||
import { T as TransportClientId } from '../../../index-2ece5234.js'; | ||
import { U as UdsConnection } from '../../../connection-bbfe1147.js'; | ||
import '../../../types-3e5768ec.js'; | ||
import '@sinclair/typebox'; | ||
import '@opentelemetry/api'; | ||
import 'node:stream'; | ||
@@ -8,0 +9,0 @@ |
import { | ||
UdsConnection | ||
} from "../../../chunk-FDLAPYCK.js"; | ||
} from "../../../chunk-S3YKQT4J.js"; | ||
import { | ||
ServerTransport | ||
} from "../../../chunk-JMXO5L2X.js"; | ||
import "../../../chunk-5WFL722S.js"; | ||
} from "../../../chunk-ZPBWKBM5.js"; | ||
import "../../../chunk-3MFX6NXA.js"; | ||
import "../../../chunk-OTQNCLFH.js"; | ||
@@ -9,0 +9,0 @@ import "../../../chunk-3AW3IXVD.js"; |
import { ClientTransport, ClientTransportOptions as ProvidedClientTransportOptions } from '../../index.js'; | ||
import { T as TransportClientId } from '../../../index-dfad460e.js'; | ||
import { W as WebSocketConnection } from '../../../connection-76c5ed01.js'; | ||
import { T as TransportClientId } from '../../../index-2ece5234.js'; | ||
import { W as WebSocketConnection } from '../../../connection-8b059ac4.js'; | ||
import { W as WsLike } from '../../../wslike-e0b32dd5.js'; | ||
import '../../../types-3e5768ec.js'; | ||
import '@sinclair/typebox'; | ||
import 'agnostic-ws'; | ||
import '@opentelemetry/api'; | ||
type UrlGetter = (to: TransportClientId) => Promise<string> | string; | ||
/** | ||
@@ -18,3 +18,3 @@ * A transport implementation that uses a WebSocket connection with automatic reconnection. | ||
*/ | ||
urlGetter: (to: TransportClientId) => Promise<string> | string; | ||
wsGetter: (to: TransportClientId) => Promise<WsLike> | WsLike; | ||
/** | ||
@@ -27,3 +27,3 @@ * Creates a new WebSocketClientTransport instance. | ||
*/ | ||
constructor(urlGetter: UrlGetter, clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions); | ||
constructor(wsGetter: (to: TransportClientId) => Promise<WsLike> | WsLike, clientId: TransportClientId, providedOptions?: ProvidedClientTransportOptions); | ||
createNewOutgoingConnection(to: string): Promise<WebSocketConnection>; | ||
@@ -30,0 +30,0 @@ } |
import { | ||
WebSocketConnection | ||
} from "../../../chunk-3Y7AB5EB.js"; | ||
} from "../../../chunk-HUBFYN37.js"; | ||
import { | ||
ClientTransport | ||
} from "../../../chunk-JMXO5L2X.js"; | ||
import "../../../chunk-5WFL722S.js"; | ||
} from "../../../chunk-ZPBWKBM5.js"; | ||
import "../../../chunk-3MFX6NXA.js"; | ||
import { | ||
@@ -14,3 +14,2 @@ log | ||
// transport/impls/ws/client.ts | ||
import WebSocket from "agnostic-ws"; | ||
var WebSocketClientTransport = class extends ClientTransport { | ||
@@ -20,3 +19,3 @@ /** | ||
*/ | ||
urlGetter; | ||
wsGetter; | ||
/** | ||
@@ -29,49 +28,35 @@ * Creates a new WebSocketClientTransport instance. | ||
*/ | ||
constructor(urlGetter, clientId, providedOptions) { | ||
constructor(wsGetter, clientId, providedOptions) { | ||
super(clientId, providedOptions); | ||
this.urlGetter = urlGetter; | ||
this.wsGetter = wsGetter; | ||
} | ||
async createNewOutgoingConnection(to) { | ||
const wsRes = await new Promise((resolve) => { | ||
log?.info(`establishing a new websocket to ${to}`, { | ||
clientId: this.clientId, | ||
connectedTo: to | ||
}); | ||
Promise.resolve(this.urlGetter(to)).then((url) => new WebSocket(url)).then((ws) => { | ||
if (ws.readyState === WebSocket.OPEN) { | ||
resolve({ ws }); | ||
return; | ||
} | ||
if (ws.readyState === WebSocket.CLOSING || ws.readyState === WebSocket.CLOSED) { | ||
resolve({ err: "ws is closing or closed" }); | ||
return; | ||
} | ||
ws.onopen = () => { | ||
resolve({ ws }); | ||
}; | ||
ws.onclose = (evt) => { | ||
resolve({ err: evt.reason }); | ||
}; | ||
ws.onerror = (evt) => { | ||
const err = evt.error; | ||
resolve({ | ||
err: `${err.name}: ${err.message}` | ||
}); | ||
}; | ||
}).catch((e) => { | ||
const reason = e instanceof Error ? e.message : "unknown reason"; | ||
resolve({ err: `couldn't get a new websocket: ${reason}` }); | ||
}); | ||
log?.info(`establishing a new websocket to ${to}`, { | ||
clientId: this.clientId, | ||
connectedTo: to | ||
}); | ||
if ("ws" in wsRes) { | ||
const conn = new WebSocketConnection(wsRes.ws); | ||
log?.info(`raw websocket to ${to} ok, starting handshake`, { | ||
clientId: this.clientId, | ||
connectedTo: to | ||
}); | ||
this.handleConnection(conn, to); | ||
return conn; | ||
} else { | ||
throw new Error(wsRes.err); | ||
} | ||
const ws = await this.wsGetter(to); | ||
await new Promise((resolve, reject) => { | ||
if (ws.readyState === ws.OPEN) { | ||
resolve(); | ||
return; | ||
} | ||
if (ws.readyState === ws.CLOSING || ws.readyState === ws.CLOSED) { | ||
reject(new Error("ws is closing or closed")); | ||
return; | ||
} | ||
ws.onopen = () => { | ||
resolve(); | ||
}; | ||
ws.onclose = (evt) => { | ||
reject(new Error(evt.reason)); | ||
}; | ||
}); | ||
const conn = new WebSocketConnection(ws); | ||
log?.info(`raw websocket to ${to} ok, starting handshake`, { | ||
clientId: this.clientId, | ||
connectedTo: to | ||
}); | ||
this.handleConnection(conn, to); | ||
return conn; | ||
} | ||
@@ -78,0 +63,0 @@ }; |
@@ -1,8 +0,9 @@ | ||
import { T as TransportClientId } from '../../../index-dfad460e.js'; | ||
import { T as TransportClientId } from '../../../index-2ece5234.js'; | ||
import { ServerTransport, ServerTransportOptions as ProvidedServerTransportOptions } from '../../index.js'; | ||
import { WebSocketServer } from 'ws'; | ||
import WebSocket from 'agnostic-ws'; | ||
import { W as WebSocketConnection } from '../../../connection-76c5ed01.js'; | ||
import { W as WebSocketConnection } from '../../../connection-8b059ac4.js'; | ||
import { W as WsLike } from '../../../wslike-e0b32dd5.js'; | ||
import '@sinclair/typebox'; | ||
import '../../../types-3e5768ec.js'; | ||
import '@opentelemetry/api'; | ||
@@ -12,3 +13,3 @@ declare class WebSocketServerTransport extends ServerTransport<WebSocketConnection> { | ||
constructor(wss: WebSocketServer, clientId: TransportClientId, providedOptions?: ProvidedServerTransportOptions); | ||
connectionHandler: (ws: WebSocket) => void; | ||
connectionHandler: (ws: WsLike) => void; | ||
close(): void; | ||
@@ -15,0 +16,0 @@ } |
import { | ||
WebSocketConnection | ||
} from "../../../chunk-3Y7AB5EB.js"; | ||
} from "../../../chunk-HUBFYN37.js"; | ||
import { | ||
ServerTransport | ||
} from "../../../chunk-JMXO5L2X.js"; | ||
import "../../../chunk-5WFL722S.js"; | ||
} from "../../../chunk-ZPBWKBM5.js"; | ||
import "../../../chunk-3MFX6NXA.js"; | ||
import "../../../chunk-OTQNCLFH.js"; | ||
@@ -9,0 +9,0 @@ import "../../../chunk-3AW3IXVD.js"; |
import { C as Codec } from '../types-3e5768ec.js'; | ||
import { O as OpaqueTransportMessage, C as Connection, a as Session, T as TransportClientId, P as PartialTransportMessage, S as SessionOptions, f as ClientHandshakeOptions, g as ServerHandshakeOptions } from '../index-dfad460e.js'; | ||
export { H as HandshakeRequestMetadata, d as OpaqueTransportMessageSchema, b as ParsedHandshakeMetadata, e as TransportMessage, c as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-dfad460e.js'; | ||
import { O as OpaqueTransportMessage, C as Connection, a as Session, T as TransportClientId, j as PropagationContext, P as PartialTransportMessage, S as SessionOptions, f as ClientHandshakeOptions, g as ServerHandshakeOptions } from '../index-2ece5234.js'; | ||
export { H as HandshakeRequestMetadata, d as OpaqueTransportMessageSchema, b as ParsedHandshakeMetadata, e as TransportMessage, c as TransportMessageSchema, h as isStreamClose, i as isStreamOpen } from '../index-2ece5234.js'; | ||
import '@sinclair/typebox'; | ||
import '@opentelemetry/api'; | ||
@@ -190,4 +191,4 @@ type ConnectionStatus = 'connect' | 'disconnect'; | ||
protected onConnect(conn: ConnType, connectedTo: TransportClientId, session: Session<ConnType>, isReconnect: boolean): void; | ||
protected createSession(to: TransportClientId, conn?: ConnType): Session<ConnType>; | ||
protected getOrCreateSession(to: TransportClientId, conn?: ConnType, sessionId?: string): { | ||
protected createSession(to: TransportClientId, conn?: ConnType, propagationCtx?: PropagationContext): Session<ConnType>; | ||
protected getOrCreateSession(to: TransportClientId, conn?: ConnType, sessionId?: string, propagationCtx?: PropagationContext): { | ||
session: Session<ConnType>; | ||
@@ -283,3 +284,2 @@ isReconnect: boolean; | ||
connect(to: TransportClientId): Promise<void>; | ||
private connectAttempt; | ||
protected deleteSession(session: Session<ConnType>): void; | ||
@@ -286,0 +286,0 @@ protected sendHandshake(to: TransportClientId, conn: ConnType): Promise<boolean>; |
@@ -8,7 +8,7 @@ import { | ||
Transport | ||
} from "../chunk-JMXO5L2X.js"; | ||
} from "../chunk-ZPBWKBM5.js"; | ||
import { | ||
OpaqueTransportMessageSchema, | ||
TransportMessageSchema | ||
} from "../chunk-5WFL722S.js"; | ||
} from "../chunk-3MFX6NXA.js"; | ||
import "../chunk-OTQNCLFH.js"; | ||
@@ -15,0 +15,0 @@ import "../chunk-3AW3IXVD.js"; |
import { Static } from '@sinclair/typebox'; | ||
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../services-9c496c6e.js'; | ||
import { P as PayloadType, R as RiverError, a as Procedure, S as ServiceContext, b as Result, c as RiverUncaughtSchema, d as ProcedureResult } from '../services-cb01a7a8.js'; | ||
import { Transport } from '../transport/index.js'; | ||
import * as it_pushable from 'it-pushable'; | ||
import { P as PartialTransportMessage, C as Connection, O as OpaqueTransportMessage, S as SessionOptions, a as Session } from '../index-dfad460e.js'; | ||
import * as ws from 'ws'; | ||
import { P as PartialTransportMessage, C as Connection, O as OpaqueTransportMessage, S as SessionOptions, a as Session } from '../index-2ece5234.js'; | ||
import NodeWs from 'ws'; | ||
import http from 'node:http'; | ||
import net from 'node:net'; | ||
import { W as WsLike } from '../wslike-e0b32dd5.js'; | ||
import '../types-3e5768ec.js'; | ||
import '@opentelemetry/api'; | ||
/** | ||
* Creates a WebSocket client that connects to a local server at the specified port. | ||
* This should only be used for testing. | ||
* @param port - The port number to connect to. | ||
* @returns A Promise that resolves to a WebSocket instance. | ||
*/ | ||
declare function createLocalWebSocketClient(port: number): WsLike; | ||
/** | ||
* Creates a WebSocket server instance using the provided HTTP server. | ||
@@ -17,3 +26,3 @@ * Only used as helper for testing. | ||
*/ | ||
declare function createWebSocketServer(server: http.Server): ws.Server<typeof ws, typeof http.IncomingMessage>; | ||
declare function createWebSocketServer(server: http.Server): NodeWs.Server<typeof NodeWs, typeof http.IncomingMessage>; | ||
/** | ||
@@ -62,2 +71,2 @@ * Starts listening on the given server and returns the automatically allocated port number. | ||
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createWebSocketServer, getUnixSocketPath, iterNext, onUdsServeReady, onWsServerReady, payloadToTransportMessage, testingSessionOptions, waitForMessage }; | ||
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, getUnixSocketPath, iterNext, onUdsServeReady, onWsServerReady, payloadToTransportMessage, testingSessionOptions, waitForMessage }; |
@@ -5,10 +5,10 @@ import { | ||
pushable | ||
} from "../chunk-NCXUFDVL.js"; | ||
} from "../chunk-GCLEWC26.js"; | ||
import { | ||
Session, | ||
defaultTransportOptions | ||
} from "../chunk-JMXO5L2X.js"; | ||
} from "../chunk-ZPBWKBM5.js"; | ||
import { | ||
coerceErrorString | ||
} from "../chunk-5WFL722S.js"; | ||
} from "../chunk-3MFX6NXA.js"; | ||
import "../chunk-OTQNCLFH.js"; | ||
@@ -18,4 +18,9 @@ import "../chunk-3AW3IXVD.js"; | ||
// util/testHelpers.ts | ||
import { WebSocketServer } from "ws"; | ||
import NodeWs, { WebSocketServer } from "ws"; | ||
import { nanoid } from "nanoid"; | ||
function createLocalWebSocketClient(port) { | ||
const sock = new NodeWs(`ws://localhost:${port}`); | ||
sock.binaryType = "arraybuffer"; | ||
return sock; | ||
} | ||
function createWebSocketServer(server) { | ||
@@ -150,2 +155,3 @@ return new WebSocketServer({ server }); | ||
createDummyTransportMessage, | ||
createLocalWebSocketClient, | ||
createWebSocketServer, | ||
@@ -152,0 +158,0 @@ getUnixSocketPath, |
{ | ||
"name": "@replit/river", | ||
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!", | ||
"version": "0.21.1", | ||
"version": "0.22.0", | ||
"type": "module", | ||
@@ -53,9 +53,8 @@ "exports": { | ||
"it-pushable": "^3.2.3", | ||
"nanoid": "^4.0.2" | ||
"nanoid": "^4.0.2", | ||
"ws": "^8.17.0" | ||
}, | ||
"peerDependencies": { | ||
"@sinclair/typebox": "~0.32.8", | ||
"@opentelemetry/api": "^1.7.0", | ||
"agnostic-ws": "^0.1.4", | ||
"ws": "^8.13.0" | ||
"@sinclair/typebox": "~0.32.8" | ||
}, | ||
@@ -62,0 +61,0 @@ "devDependencies": { |
@@ -140,3 +140,3 @@ # River | ||
const transport = new WebSocketClientTransport( | ||
async () => `ws://localhost:3000`, | ||
async () => new WebSocket('ws://localhost:3000'), | ||
'my-client-id', | ||
@@ -143,0 +143,0 @@ ); |
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
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
1469024
6
78
14717
+ Addedws@^8.17.0
- Removedagnostic-ws@0.1.5(transitive)