@replit/river
Advanced tools
Comparing version 0.200.0-rc.20 to 0.200.1
import { | ||
NaiveJsonCodec | ||
} from "../chunk-4PVU7J25.js"; | ||
} from "../chunk-AJGIY2UB.js"; | ||
@@ -5,0 +5,0 @@ // codec/binary.ts |
@@ -1,4 +0,4 @@ | ||
export { g as LogFn, L as Logger, M as MessageMetadata, k as coloredStringLogger, l as jsonLogger, s as stringLogger } from '../message-59fe53e1.js'; | ||
export { h as LogFn, L as Logger, M as MessageMetadata, l as coloredStringLogger, m as jsonLogger, s as stringLogger } from '../message-57bb8187.js'; | ||
import '@sinclair/typebox/value'; | ||
import '@sinclair/typebox'; | ||
import '@opentelemetry/api'; |
@@ -5,3 +5,3 @@ import { | ||
stringLogger | ||
} from "../chunk-BAGOAJ3K.js"; | ||
} from "../chunk-YTMS7OP6.js"; | ||
export { | ||
@@ -8,0 +8,0 @@ coloredStringLogger, |
@@ -1,11 +0,11 @@ | ||
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap } from '../services-aa49a9fb.js'; | ||
export { B as BaseErrorSchemaType, F as CANCEL_CODE, H as Client, J as Err, L as ErrResult, E as INVALID_REQUEST_CODE, O as Ok, M as OkResult, P as PayloadType, l as ProcErrors, h as ProcHandler, i as ProcInit, j as ProcRequest, k as ProcResponse, m as ProcType, d as Procedure, c as ProcedureErrorSchemaType, w as ProcedureMap, x as RPCProcedure, R as Readable, f as ReaderErrorSchema, T as ResponseData, e as Result, Q as ResultUnwrapErr, N as ResultUnwrapOk, q as SerializedProcedureSchema, v as SerializedProcedureSchemaProtocolv1, o as SerializedServerSchema, t as SerializedServerSchemaProtocolv1, p as SerializedServiceSchema, u as SerializedServiceSchemaProtocolv1, S as Service, g as ServiceConfiguration, n as ServiceSchema, z as StreamProcedure, y as SubscriptionProcedure, C as UNCAUGHT_ERROR_CODE, D as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, G as createClient, s as serializeSchema, r as serializeSchemaV1Compat, K as unwrapOrThrow } from '../services-aa49a9fb.js'; | ||
import { C as Connection, s as ServerHandshakeOptions, o as ServiceContext } from '../context-9c907028.js'; | ||
export { t as ParsedMetadata, u as ProcedureHandlerContext, v as createClientHandshakeOptions, w as createServerHandshakeOptions } from '../context-9c907028.js'; | ||
import { S as ServerTransport } from '../server-109a29e2.js'; | ||
import { A as AnyServiceSchemaMap, I as InstantiatedServiceSchemaMap, g as AnyProcedure } from '../services-e4f28470.js'; | ||
export { B as BaseErrorSchemaType, H as CANCEL_CODE, K as Client, L as Err, N as ErrResult, G as INVALID_REQUEST_CODE, O as Ok, Q as OkResult, P as PayloadType, m as ProcErrors, i as ProcHandler, j as ProcInit, k as ProcRequest, l as ProcResponse, n as ProcType, d as Procedure, c as ProcedureErrorSchemaType, x as ProcedureMap, y as RPCProcedure, R as Readable, f as ReaderErrorSchema, Y as ResponseData, e as Result, X as ResultUnwrapErr, T as ResultUnwrapOk, r as SerializedProcedureSchema, w as SerializedProcedureSchemaProtocolv1, p as SerializedServerSchema, u as SerializedServerSchemaProtocolv1, q as SerializedServiceSchema, v as SerializedServiceSchemaProtocolv1, S as Service, h as ServiceConfiguration, o as ServiceSchema, C as StreamProcedure, z as SubscriptionProcedure, E as UNCAUGHT_ERROR_CODE, F as UNEXPECTED_DISCONNECT_CODE, U as UploadProcedure, V as ValidProcType, W as Writable, J as createClient, D as flattenErrorType, s as serializeSchema, t as serializeSchemaV1Compat, M as unwrapOrThrow } from '../services-e4f28470.js'; | ||
import { c as TransportClientId, b as OpaqueTransportMessage } from '../message-57bb8187.js'; | ||
import { t as ParsedMetadata, C as Connection, u as ServerHandshakeOptions, p as ServiceContext } from '../context-85b8690e.js'; | ||
export { v as ProcedureHandlerContext, w as createClientHandshakeOptions, x as createServerHandshakeOptions } from '../context-85b8690e.js'; | ||
import { S as ServerTransport } from '../server-456bf6cb.js'; | ||
import '@sinclair/typebox'; | ||
import '../message-59fe53e1.js'; | ||
import '../client-095a929e.js'; | ||
import '@sinclair/typebox/value'; | ||
import '@opentelemetry/api'; | ||
import '../client-75090f07.js'; | ||
import '@sinclair/typebox/errors'; | ||
@@ -27,4 +27,14 @@ import '../types-3e5768ec.js'; | ||
*/ | ||
openStreams: Set<StreamId>; | ||
streams: Map<StreamId, ProcStream>; | ||
} | ||
interface ProcStream { | ||
streamId: StreamId; | ||
from: TransportClientId; | ||
procedureName: string; | ||
serviceName: string; | ||
sessionMetadata: ParsedMetadata; | ||
procedure: AnyProcedure; | ||
handleMsg: (msg: OpaqueTransportMessage) => void; | ||
handleSessionDisconnect: () => void; | ||
} | ||
/** | ||
@@ -49,4 +59,4 @@ * Creates a server instance that listens for incoming messages from a transport and routes them to the appropriate service and procedure. | ||
var version = "0.200.0-rc.20"; | ||
var version = "0.200.1"; | ||
export { version as RIVER_VERSION, Server, ServiceContext, createServer }; | ||
export { ParsedMetadata, version as RIVER_VERSION, Server, ServiceContext, createServer }; |
@@ -8,3 +8,2 @@ import { | ||
Ok, | ||
Procedure, | ||
ReadableImpl, | ||
@@ -15,4 +14,5 @@ ReaderErrorSchema, | ||
WritableImpl, | ||
flattenErrorType, | ||
unwrapOrThrow | ||
} from "../chunk-YBCQVIPR.js"; | ||
} from "../chunk-MADS7AI5.js"; | ||
import { | ||
@@ -32,3 +32,3 @@ ControlMessageCloseSchema, | ||
version | ||
} from "../chunk-BYCR4VEM.js"; | ||
} from "../chunk-UQHYJZTP.js"; | ||
@@ -299,2 +299,79 @@ // router/services.ts | ||
// router/procedures.ts | ||
import { Type as Type2 } from "@sinclair/typebox"; | ||
function rpc({ | ||
requestInit, | ||
responseData, | ||
responseError = Type2.Never(), | ||
description, | ||
handler | ||
}) { | ||
return { | ||
...description ? { description } : {}, | ||
type: "rpc", | ||
requestInit, | ||
responseData, | ||
responseError, | ||
handler | ||
}; | ||
} | ||
function upload({ | ||
requestInit, | ||
requestData, | ||
responseData, | ||
responseError = Type2.Never(), | ||
description, | ||
handler | ||
}) { | ||
return { | ||
type: "upload", | ||
...description ? { description } : {}, | ||
requestInit, | ||
requestData, | ||
responseData, | ||
responseError, | ||
handler | ||
}; | ||
} | ||
function subscription({ | ||
requestInit, | ||
responseData, | ||
responseError = Type2.Never(), | ||
description, | ||
handler | ||
}) { | ||
return { | ||
type: "subscription", | ||
...description ? { description } : {}, | ||
requestInit, | ||
responseData, | ||
responseError, | ||
handler | ||
}; | ||
} | ||
function stream({ | ||
requestInit, | ||
requestData, | ||
responseData, | ||
responseError = Type2.Never(), | ||
description, | ||
handler | ||
}) { | ||
return { | ||
type: "stream", | ||
...description ? { description } : {}, | ||
requestInit, | ||
requestData, | ||
responseData, | ||
responseError, | ||
handler | ||
}; | ||
} | ||
var Procedure = { | ||
rpc, | ||
upload, | ||
subscription, | ||
stream | ||
}; | ||
// router/client.ts | ||
@@ -363,2 +440,7 @@ import { Value } from "@sinclair/typebox/value"; | ||
function handleProc(procType, transport, serverId, init, serviceName, procedureName, abortSignal) { | ||
const session = transport.sessions.get(serverId) ?? transport.createUnconnectedSession(serverId); | ||
const sessionScopedSend = transport.getSessionBoundSendFn( | ||
serverId, | ||
session.id | ||
); | ||
const procClosesWithInit = procType === "rpc" || procType === "subscription"; | ||
@@ -374,6 +456,5 @@ const streamId = generateId(); | ||
let cleanClose = true; | ||
const reqWritable = new WritableImpl( | ||
// write callback | ||
(rawIn) => { | ||
transport.send(serverId, { | ||
const reqWritable = new WritableImpl({ | ||
writeCb: (rawIn) => { | ||
sessionScopedSend({ | ||
streamId, | ||
@@ -385,6 +466,6 @@ payload: rawIn, | ||
// close callback | ||
() => { | ||
closeCb: () => { | ||
span.addEvent("reqWritable closed"); | ||
if (!procClosesWithInit && cleanClose) { | ||
transport.send(serverId, closeStreamMessage(streamId)); | ||
sessionScopedSend(closeStreamMessage(streamId)); | ||
} | ||
@@ -395,3 +476,3 @@ if (resReadable.isClosed()) { | ||
} | ||
); | ||
}); | ||
const resReadable = new ReadableImpl(); | ||
@@ -427,4 +508,3 @@ const closeReadable = () => { | ||
reqWritable.close(); | ||
transport.send( | ||
serverId, | ||
sessionScopedSend( | ||
cancelMessage( | ||
@@ -512,8 +592,5 @@ streamId, | ||
function onSessionStatus(evt) { | ||
if (evt.status !== "disconnect") { | ||
if (evt.status !== "disconnect" || evt.session.to !== serverId || session.id !== evt.session.id) { | ||
return; | ||
} | ||
if (evt.session.to !== serverId) { | ||
return; | ||
} | ||
cleanClose = false; | ||
@@ -534,3 +611,3 @@ if (!resReadable.isClosed()) { | ||
transport.addEventListener("sessionStatus", onSessionStatus); | ||
transport.send(serverId, { | ||
sessionScopedSend({ | ||
streamId, | ||
@@ -584,9 +661,9 @@ serviceName, | ||
// router/server.ts | ||
import { Type as Type2 } from "@sinclair/typebox"; | ||
import { Type as Type3 } from "@sinclair/typebox"; | ||
import { Value as Value2 } from "@sinclair/typebox/value"; | ||
import { SpanStatusCode } from "@opentelemetry/api"; | ||
var CancelResultSchema = ErrResultSchema( | ||
Type2.Object({ | ||
code: Type2.Literal(CANCEL_CODE), | ||
message: Type2.String() | ||
Type3.Object({ | ||
code: Type3.Literal(CANCEL_CODE), | ||
message: Type3.String() | ||
}) | ||
@@ -602,3 +679,3 @@ ); | ||
* requests it sent before it saw the cancel. | ||
* We track cancelled streams for every session separately, so | ||
* We track cancelled streams for every client separately, so | ||
* that bad clients don't affect good clients. | ||
@@ -608,3 +685,3 @@ */ | ||
maxCancelledStreamTombstonesPerSession; | ||
openStreams; | ||
streams; | ||
services; | ||
@@ -627,8 +704,8 @@ constructor(transport, services, handshakeOptions, extendedContext, maxCancelledStreamTombstonesPerSession = 200) { | ||
this.transport = transport; | ||
this.openStreams = /* @__PURE__ */ new Set(); | ||
this.streams = /* @__PURE__ */ new Map(); | ||
this.serverCancelledStreams = /* @__PURE__ */ new Map(); | ||
this.maxCancelledStreamTombstonesPerSession = maxCancelledStreamTombstonesPerSession; | ||
this.log = transport.log; | ||
const handleMessage = (msg) => { | ||
if (msg.to !== this.transport.clientId) { | ||
const handleCreatingNewStreams = (message) => { | ||
if (message.to !== this.transport.clientId) { | ||
this.log?.info( | ||
@@ -638,3 +715,3 @@ `got msg with destination that isn't this server, ignoring`, | ||
clientId: this.transport.clientId, | ||
transportMessage: msg | ||
transportMessage: message | ||
} | ||
@@ -644,15 +721,21 @@ ); | ||
} | ||
if (this.openStreams.has(msg.streamId)) { | ||
const streamId = message.streamId; | ||
const stream2 = this.streams.get(streamId); | ||
if (stream2) { | ||
stream2.handleMsg(message); | ||
return; | ||
} | ||
if (this.serverCancelledStreams.get(msg.from)?.has(msg.streamId)) { | ||
if (this.serverCancelledStreams.get(message.from)?.has(streamId)) { | ||
return; | ||
} | ||
const validated = this.validateNewProcStream(msg); | ||
if (!validated) { | ||
const newStreamProps = this.validateNewProcStream(message); | ||
if (!newStreamProps) { | ||
return; | ||
} | ||
this.createNewProcStream(validated); | ||
const newStream = this.createNewProcStream({ | ||
...newStreamProps, | ||
...message | ||
}); | ||
this.streams.set(streamId, newStream); | ||
}; | ||
this.transport.addEventListener("message", handleMessage); | ||
const handleSessionStatus = (evt) => { | ||
@@ -666,70 +749,48 @@ if (evt.status !== "disconnect") | ||
); | ||
for (const stream2 of this.streams.values()) { | ||
if (stream2.from === disconnectedClientId) { | ||
stream2.handleSessionDisconnect(); | ||
} | ||
} | ||
this.serverCancelledStreams.delete(disconnectedClientId); | ||
}; | ||
this.transport.addEventListener("sessionStatus", handleSessionStatus); | ||
this.transport.addEventListener("transportStatus", (evt) => { | ||
const handleTransportStatus = (evt) => { | ||
if (evt.status !== "closed") | ||
return; | ||
this.transport.removeEventListener("message", handleMessage); | ||
this.transport.removeEventListener("message", handleCreatingNewStreams); | ||
this.transport.removeEventListener("sessionStatus", handleSessionStatus); | ||
}); | ||
this.transport.removeEventListener( | ||
"transportStatus", | ||
handleTransportStatus | ||
); | ||
}; | ||
this.transport.addEventListener("message", handleCreatingNewStreams); | ||
this.transport.addEventListener("sessionStatus", handleSessionStatus); | ||
this.transport.addEventListener("transportStatus", handleTransportStatus); | ||
} | ||
createNewProcStream({ | ||
procedure, | ||
procedureName, | ||
service, | ||
serviceName, | ||
sessionMetadata, | ||
loggingMetadata, | ||
streamId, | ||
controlFlags, | ||
initPayload, | ||
from, | ||
sessionId, | ||
tracingCtx, | ||
protocolVersion, | ||
passInitAsDataForBackwardsCompat | ||
}) { | ||
this.openStreams.add(streamId); | ||
createNewProcStream(props) { | ||
const { | ||
streamId, | ||
initialSession, | ||
procedureName, | ||
serviceName, | ||
procedure, | ||
sessionMetadata, | ||
serviceContext, | ||
initPayload, | ||
tracingCtx, | ||
procClosesWithInit, | ||
passInitAsDataForBackwardsCompat | ||
} = props; | ||
const { | ||
to: from, | ||
loggingMetadata, | ||
protocolVersion, | ||
id: sessionId | ||
} = initialSession; | ||
let cleanClose = true; | ||
const onServerCancel = (e) => { | ||
if (reqReadable.isClosed() && resWritable.isClosed()) { | ||
return; | ||
} | ||
cleanClose = false; | ||
const result = Err(e); | ||
if (!reqReadable.isClosed()) { | ||
reqReadable._pushValue(result); | ||
closeReadable(); | ||
} | ||
resWritable.close(); | ||
this.cancelStream(from, streamId, result); | ||
}; | ||
const onSessionStatus = (evt) => { | ||
if (evt.status !== "disconnect") { | ||
return; | ||
} | ||
if (evt.session.to !== from) { | ||
return; | ||
} | ||
cleanClose = false; | ||
const errPayload = { | ||
code: UNEXPECTED_DISCONNECT_CODE, | ||
message: `client unexpectedly disconnected` | ||
}; | ||
if (!reqReadable.isClosed()) { | ||
reqReadable._pushValue(Err(errPayload)); | ||
closeReadable(); | ||
} | ||
resWritable.close(); | ||
}; | ||
this.transport.addEventListener("sessionStatus", onSessionStatus); | ||
const onMessage = (msg) => { | ||
if (streamId !== msg.streamId) { | ||
return; | ||
} | ||
if (msg.from !== from) { | ||
this.log?.error("got stream message from unexpected client", { | ||
...loggingMetadata, | ||
clientId: this.transport.clientId, | ||
transportMessage: msg, | ||
@@ -751,3 +812,2 @@ tags: ["invariant-violation"] | ||
...loggingMetadata, | ||
clientId: this.transport.clientId, | ||
transportMessage: msg, | ||
@@ -770,3 +830,2 @@ validationErrors: [ | ||
...loggingMetadata, | ||
clientId: this.transport.clientId, | ||
transportMessage: msg, | ||
@@ -807,3 +866,2 @@ tags: ["invalid-request"] | ||
...loggingMetadata, | ||
clientId: this.transport.clientId, | ||
transportMessage: msg, | ||
@@ -818,9 +876,47 @@ validationErrors, | ||
}; | ||
this.transport.addEventListener("message", onMessage); | ||
const procStream = { | ||
from, | ||
streamId, | ||
procedureName, | ||
serviceName, | ||
sessionMetadata, | ||
procedure, | ||
handleMsg: onMessage, | ||
handleSessionDisconnect: () => { | ||
cleanClose = false; | ||
const errPayload = { | ||
code: UNEXPECTED_DISCONNECT_CODE, | ||
message: "client unexpectedly disconnected" | ||
}; | ||
if (!reqReadable.isClosed()) { | ||
reqReadable._pushValue(Err(errPayload)); | ||
closeReadable(); | ||
} | ||
resWritable.close(); | ||
} | ||
}; | ||
const sessionScopedSend = this.transport.getSessionBoundSendFn( | ||
from, | ||
sessionId | ||
); | ||
const cancelStream = (streamId2, payload) => { | ||
this.cancelStream(from, sessionScopedSend, streamId2, payload); | ||
}; | ||
const onServerCancel = (e) => { | ||
if (reqReadable.isClosed() && resWritable.isClosed()) { | ||
return; | ||
} | ||
cleanClose = false; | ||
const result = Err(e); | ||
if (!reqReadable.isClosed()) { | ||
reqReadable._pushValue(result); | ||
closeReadable(); | ||
} | ||
resWritable.close(); | ||
cancelStream(streamId, result); | ||
}; | ||
const finishedController = new AbortController(); | ||
const cleanup = () => { | ||
this.transport.removeEventListener("message", onMessage); | ||
this.transport.removeEventListener("sessionStatus", onSessionStatus); | ||
finishedController.abort(); | ||
this.openStreams.delete(streamId); | ||
this.streams.delete(streamId); | ||
}; | ||
@@ -843,6 +939,5 @@ const procClosesWithResponse = procedure.type === "rpc" || procedure.type === "upload"; | ||
} | ||
const resWritable = new WritableImpl( | ||
// write callback | ||
(response) => { | ||
this.transport.send(from, { | ||
const resWritable = new WritableImpl({ | ||
writeCb: (response) => { | ||
sessionScopedSend({ | ||
streamId, | ||
@@ -852,9 +947,12 @@ controlFlags: procClosesWithResponse ? getStreamCloseBackwardsCompat(protocolVersion) : 0, | ||
}); | ||
if (procClosesWithResponse) { | ||
resWritable.close(); | ||
} | ||
}, | ||
// close callback | ||
() => { | ||
closeCb: () => { | ||
if (!procClosesWithResponse && cleanClose) { | ||
const message = closeStreamMessage(streamId); | ||
message.controlFlags = getStreamCloseBackwardsCompat(protocolVersion); | ||
this.transport.send(from, closeStreamMessage(streamId)); | ||
sessionScopedSend(message); | ||
} | ||
@@ -870,3 +968,3 @@ if (protocolVersion === "v1.1") { | ||
} | ||
); | ||
}); | ||
const onHandlerError = (err, span) => { | ||
@@ -881,3 +979,3 @@ const errorMsg = coerceErrorString(err); | ||
}; | ||
if (isStreamCloseBackwardsCompat(controlFlags, protocolVersion)) { | ||
if (procClosesWithInit) { | ||
closeReadable(); | ||
@@ -891,3 +989,3 @@ } else if (procedure.type === "rpc" || procedure.type === "subscription") { | ||
const handlerContext = { | ||
...this.getContext(service, serviceName), | ||
...serviceContext, | ||
from, | ||
@@ -922,3 +1020,2 @@ sessionId, | ||
resWritable.write(responsePayload); | ||
resWritable.close(); | ||
} catch (err) { | ||
@@ -995,3 +1092,2 @@ onHandlerError(err, span); | ||
resWritable.write(responsePayload); | ||
resWritable.close(); | ||
} catch (err) { | ||
@@ -1005,12 +1101,4 @@ onHandlerError(err, span); | ||
break; | ||
default: | ||
this.log?.error( | ||
`got request for invalid procedure type ${procedure.type} at ${serviceName}.${procedureName}`, | ||
{ | ||
...loggingMetadata, | ||
tags: ["invariant-violation"] | ||
} | ||
); | ||
return; | ||
} | ||
return procStream; | ||
} | ||
@@ -1032,3 +1120,2 @@ getContext(service, serviceName) { | ||
if (!session) { | ||
const errMessage = `couldn't find a session for ${initMessage.from}`; | ||
this.log?.error(`couldn't find session for ${initMessage.from}`, { | ||
@@ -1039,12 +1126,11 @@ clientId: this.transport.clientId, | ||
}); | ||
this.cancelStream( | ||
initMessage.from, | ||
initMessage.streamId, | ||
Err({ | ||
code: UNCAUGHT_ERROR_CODE, | ||
message: errMessage | ||
}) | ||
); | ||
return null; | ||
} | ||
const sessionScopedSend = this.transport.getSessionBoundSendFn( | ||
initMessage.from, | ||
session.id | ||
); | ||
const cancelStream = (streamId, payload) => { | ||
this.cancelStream(initMessage.from, sessionScopedSend, streamId, payload); | ||
}; | ||
const sessionMetadata = this.transport.sessionHandshakeMetadata.get( | ||
@@ -1059,4 +1145,3 @@ session.to | ||
}); | ||
this.cancelStream( | ||
initMessage.from, | ||
cancelStream( | ||
initMessage.streamId, | ||
@@ -1078,4 +1163,3 @@ Err({ | ||
}); | ||
this.cancelStream( | ||
initMessage.from, | ||
cancelStream( | ||
initMessage.streamId, | ||
@@ -1093,8 +1177,6 @@ Err({ | ||
...session.loggingMetadata, | ||
clientId: this.transport.clientId, | ||
transportMessage: initMessage, | ||
tags: ["invalid-request"] | ||
}); | ||
this.cancelStream( | ||
initMessage.from, | ||
cancelStream( | ||
initMessage.streamId, | ||
@@ -1112,8 +1194,6 @@ Err({ | ||
...session.loggingMetadata, | ||
clientId: this.transport.clientId, | ||
transportMessage: initMessage, | ||
tags: ["invalid-request"] | ||
}); | ||
this.cancelStream( | ||
initMessage.from, | ||
cancelStream( | ||
initMessage.streamId, | ||
@@ -1135,4 +1215,3 @@ Err({ | ||
}); | ||
this.cancelStream( | ||
initMessage.from, | ||
cancelStream( | ||
initMessage.streamId, | ||
@@ -1151,8 +1230,6 @@ Err({ | ||
...session.loggingMetadata, | ||
clientId: this.transport.clientId, | ||
transportMessage: initMessage, | ||
tags: ["invalid-request"] | ||
}); | ||
this.cancelStream( | ||
initMessage.from, | ||
cancelStream( | ||
initMessage.streamId, | ||
@@ -1166,3 +1243,15 @@ Err({ | ||
} | ||
const serviceContext = this.getContext(service, initMessage.serviceName); | ||
const procedure = service.procedures[initMessage.procedureName]; | ||
if (!["rpc", "upload", "stream", "subscription"].includes(procedure.type)) { | ||
this.log?.error( | ||
`got request for invalid procedure type ${procedure.type} at ${initMessage.serviceName}.${initMessage.procedureName}`, | ||
{ | ||
...session.loggingMetadata, | ||
transportMessage: initMessage, | ||
tags: ["invariant-violation"] | ||
} | ||
); | ||
return null; | ||
} | ||
let passInitAsDataForBackwardsCompat = false; | ||
@@ -1179,4 +1268,3 @@ if (session.protocolVersion === "v1.1" && (procedure.type === "upload" || procedure.type === "stream") && Value2.Check(procedure.requestData, initMessage.payload) && Value2.Check(procedure.requestInit, {})) { | ||
}); | ||
this.cancelStream( | ||
initMessage.from, | ||
cancelStream( | ||
initMessage.streamId, | ||
@@ -1191,35 +1279,29 @@ Err({ | ||
return { | ||
sessionMetadata, | ||
procedure, | ||
initialSession: session, | ||
streamId: initMessage.streamId, | ||
procedureName: initMessage.procedureName, | ||
service, | ||
serviceName: initMessage.serviceName, | ||
loggingMetadata: { | ||
...session.loggingMetadata, | ||
transportMessage: initMessage | ||
}, | ||
streamId: initMessage.streamId, | ||
controlFlags: initMessage.controlFlags, | ||
tracingCtx: initMessage.tracing, | ||
initPayload: initMessage.payload, | ||
from: initMessage.from, | ||
sessionId: session.id, | ||
protocolVersion: session.protocolVersion, | ||
sessionMetadata, | ||
procedure, | ||
serviceContext, | ||
procClosesWithInit: isStreamCloseBackwardsCompat( | ||
initMessage.controlFlags, | ||
session.protocolVersion | ||
), | ||
passInitAsDataForBackwardsCompat | ||
}; | ||
} | ||
cancelStream(to, streamId, payload) { | ||
let cancelledForSession = this.serverCancelledStreams.get(to); | ||
if (!cancelledForSession) { | ||
cancelledForSession = new LRUSet( | ||
cancelStream(to, sessionScopedSend, streamId, payload) { | ||
let cancelledStreamsInSession = this.serverCancelledStreams.get(to); | ||
if (!cancelledStreamsInSession) { | ||
cancelledStreamsInSession = new LRUSet( | ||
this.maxCancelledStreamTombstonesPerSession | ||
); | ||
this.serverCancelledStreams.set(to, cancelledForSession); | ||
this.serverCancelledStreams.set(to, cancelledStreamsInSession); | ||
} | ||
cancelledForSession.add(streamId); | ||
this.transport.send( | ||
to, | ||
// TODO remove once clients migrate to v2 | ||
this.transport.sessions.get(to)?.protocolVersion === "v1.1" ? closeStreamMessage(streamId) : cancelMessage(streamId, payload) | ||
); | ||
cancelledStreamsInSession.add(streamId); | ||
const msg = cancelMessage(streamId, payload); | ||
sessionScopedSend(msg); | ||
} | ||
@@ -1299,2 +1381,3 @@ }; | ||
createServerHandshakeOptions, | ||
flattenErrorType, | ||
serializeSchema, | ||
@@ -1301,0 +1384,0 @@ serializeSchemaV1Compat, |
@@ -1,5 +0,5 @@ | ||
import { C as ClientTransport } from '../../../client-75090f07.js'; | ||
import { c as TransportClientId } from '../../../message-59fe53e1.js'; | ||
import { b as ProvidedClientTransportOptions } from '../../../context-9c907028.js'; | ||
import { W as WebSocketConnection } from '../../../connection-c9f96b64.js'; | ||
import { C as ClientTransport } from '../../../client-095a929e.js'; | ||
import { c as TransportClientId } from '../../../message-57bb8187.js'; | ||
import { b as ProvidedClientTransportOptions } from '../../../context-85b8690e.js'; | ||
import { W as WebSocketConnection } from '../../../connection-623d75e9.js'; | ||
import { W as WsLike } from '../../../wslike-e0b32dd5.js'; | ||
@@ -6,0 +6,0 @@ import '@sinclair/typebox/value'; |
import { | ||
ClientTransport | ||
} from "../../../chunk-WKBWCRGN.js"; | ||
} from "../../../chunk-SONGYR7A.js"; | ||
import { | ||
WebSocketConnection | ||
} from "../../../chunk-DM5QR4HQ.js"; | ||
import "../../../chunk-3HI3IJTL.js"; | ||
import "../../../chunk-BAGOAJ3K.js"; | ||
import "../../../chunk-OLWVR5AB.js"; | ||
import "../../../chunk-BYCR4VEM.js"; | ||
import "../../../chunk-4PVU7J25.js"; | ||
} from "../../../chunk-ZNJM2HIE.js"; | ||
import "../../../chunk-ZDYZ2FCN.js"; | ||
import "../../../chunk-YTMS7OP6.js"; | ||
import "../../../chunk-6VA5DW7N.js"; | ||
import "../../../chunk-UQHYJZTP.js"; | ||
import "../../../chunk-AJGIY2UB.js"; | ||
@@ -13,0 +13,0 @@ // transport/impls/ws/client.ts |
@@ -1,7 +0,7 @@ | ||
import { c as TransportClientId } from '../../../message-59fe53e1.js'; | ||
import { c as TransportClientId } from '../../../message-57bb8187.js'; | ||
import { WebSocketServer } from 'ws'; | ||
import { W as WebSocketConnection } from '../../../connection-c9f96b64.js'; | ||
import { W as WebSocketConnection } from '../../../connection-623d75e9.js'; | ||
import { W as WsLike } from '../../../wslike-e0b32dd5.js'; | ||
import { S as ServerTransport } from '../../../server-109a29e2.js'; | ||
import { c as ProvidedServerTransportOptions } from '../../../context-9c907028.js'; | ||
import { S as ServerTransport } from '../../../server-456bf6cb.js'; | ||
import { c as ProvidedServerTransportOptions } from '../../../context-85b8690e.js'; | ||
import { IncomingMessage } from 'http'; | ||
@@ -8,0 +8,0 @@ import '@sinclair/typebox/value'; |
import { | ||
ServerTransport | ||
} from "../../../chunk-5L5RNZXH.js"; | ||
} from "../../../chunk-YQPJ3HZK.js"; | ||
import { | ||
WebSocketConnection | ||
} from "../../../chunk-DM5QR4HQ.js"; | ||
import "../../../chunk-3HI3IJTL.js"; | ||
import "../../../chunk-BAGOAJ3K.js"; | ||
import "../../../chunk-OLWVR5AB.js"; | ||
import "../../../chunk-BYCR4VEM.js"; | ||
import "../../../chunk-4PVU7J25.js"; | ||
} from "../../../chunk-ZNJM2HIE.js"; | ||
import "../../../chunk-ZDYZ2FCN.js"; | ||
import "../../../chunk-YTMS7OP6.js"; | ||
import "../../../chunk-6VA5DW7N.js"; | ||
import "../../../chunk-UQHYJZTP.js"; | ||
import "../../../chunk-AJGIY2UB.js"; | ||
@@ -13,0 +13,0 @@ // transport/impls/ws/server.ts |
@@ -1,5 +0,5 @@ | ||
export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../context-9c907028.js'; | ||
export { C as ClientTransport } from '../client-75090f07.js'; | ||
export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-109a29e2.js'; | ||
export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-59fe53e1.js'; | ||
export { b as ClientTransportOptions, C as Connection, j as EventHandler, E as EventMap, i as EventTypes, k as ProtocolError, l as ProtocolErrorType, c as ServerTransportOptions, S as Session, h as SessionConnected, f as SessionConnecting, g as SessionHandshaking, e as SessionNoConnection, d as SessionState, T as Transport, P as TransportOptions, a as TransportStatus } from '../context-85b8690e.js'; | ||
export { C as ClientTransport } from '../client-095a929e.js'; | ||
export { S as ServerTransport, a as SessionWaitingForHandshake } from '../server-456bf6cb.js'; | ||
export { b as OpaqueTransportMessage, O as OpaqueTransportMessageSchema, c as TransportClientId, a as TransportMessage, T as TransportMessageSchema, d as isStreamClose, i as isStreamOpen } from '../message-57bb8187.js'; | ||
import '@sinclair/typebox'; | ||
@@ -6,0 +6,0 @@ import '@sinclair/typebox/errors'; |
import { | ||
ClientTransport | ||
} from "../chunk-WKBWCRGN.js"; | ||
} from "../chunk-SONGYR7A.js"; | ||
import { | ||
ServerTransport | ||
} from "../chunk-5L5RNZXH.js"; | ||
} from "../chunk-YQPJ3HZK.js"; | ||
import { | ||
@@ -11,12 +11,12 @@ Connection, | ||
Transport | ||
} from "../chunk-3HI3IJTL.js"; | ||
import "../chunk-BAGOAJ3K.js"; | ||
} from "../chunk-ZDYZ2FCN.js"; | ||
import "../chunk-YTMS7OP6.js"; | ||
import { | ||
SessionState | ||
} from "../chunk-OLWVR5AB.js"; | ||
} from "../chunk-6VA5DW7N.js"; | ||
import { | ||
OpaqueTransportMessageSchema, | ||
TransportMessageSchema | ||
} from "../chunk-BYCR4VEM.js"; | ||
import "../chunk-4PVU7J25.js"; | ||
} from "../chunk-UQHYJZTP.js"; | ||
import "../chunk-AJGIY2UB.js"; | ||
export { | ||
@@ -23,0 +23,0 @@ ClientTransport, |
@@ -1,7 +0,9 @@ | ||
import { T as Transport, C as Connection, m as SessionOptions, n as ClientTransportOptions, e as SessionNoConnection, o as ServiceContext, S as Session } from '../context-9c907028.js'; | ||
import { T as Transport, C as Connection, m as SessionOptions, n as ClientTransportOptions, e as SessionNoConnection, o as SessionBoundSendFn, p as ServiceContext, S as Session } from '../context-85b8690e.js'; | ||
import { C as ClientTransport } from '../client-095a929e.js'; | ||
import { S as ServerTransport } from '../server-456bf6cb.js'; | ||
import { P as PartialTransportMessage, b as OpaqueTransportMessage } from '../message-57bb8187.js'; | ||
import { Static } from '@sinclair/typebox'; | ||
import { P as PartialTransportMessage, b as OpaqueTransportMessage } from '../message-59fe53e1.js'; | ||
import NodeWs from 'ws'; | ||
import http from 'node:http'; | ||
import { B as BaseErrorSchemaType, R as Readable, a as ReadableIterator, b as ReadableResult, P as PayloadType, c as ProcedureErrorSchemaType, d as Procedure, e as Result, f as ReaderErrorSchema, W as Writable } from '../services-aa49a9fb.js'; | ||
import { B as BaseErrorSchemaType, R as Readable, a as ReadableIterator, b as ReadableResult, P as PayloadType, c as ProcedureErrorSchemaType, d as Procedure, e as Result, f as ReaderErrorSchema, W as Writable } from '../services-e4f28470.js'; | ||
import { W as WsLike } from '../wslike-e0b32dd5.js'; | ||
@@ -12,3 +14,2 @@ import '@sinclair/typebox/errors'; | ||
import '@opentelemetry/api'; | ||
import '../client-75090f07.js'; | ||
@@ -72,2 +73,4 @@ /** | ||
declare function dummySession(): SessionNoConnection; | ||
declare function getClientSendFn(clientTransport: ClientTransport<Connection>, serverTransport: ServerTransport<Connection>): SessionBoundSendFn; | ||
declare function getServerSendFn(serverTransport: ServerTransport<Connection>, clientTransport: ClientTransport<Connection>): SessionBoundSendFn; | ||
declare function asClientRpc<State extends object, Init extends PayloadType, Res extends PayloadType, Err extends ProcedureErrorSchemaType>(state: State, proc: Procedure<State, 'rpc', Init, null, Res, Err>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): (msg: Static<Init>) => Promise<Result<Static<Res>, Static<Err> | Static<typeof ReaderErrorSchema>>>; | ||
@@ -89,2 +92,2 @@ declare function asClientStream<State extends object, Init extends PayloadType, Req extends PayloadType, Res extends PayloadType, Err extends ProcedureErrorSchemaType>(state: State, proc: Procedure<State, 'stream', Init, Req, Res, Err>, reqInit?: Static<Init>, extendedContext?: Omit<ServiceContext, 'state'>, session?: Session<Connection>): { | ||
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, closeAllConnections, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, dummySession, getReadableIterator, getTransportConnections, isReadableDone, numberOfConnections, onWsServerReady, payloadToTransportMessage, readNextResult, testingClientSessionOptions, testingSessionOptions, waitForMessage }; | ||
export { asClientRpc, asClientStream, asClientSubscription, asClientUpload, closeAllConnections, createDummyTransportMessage, createLocalWebSocketClient, createWebSocketServer, dummySession, getClientSendFn, getReadableIterator, getServerSendFn, getTransportConnections, isReadableDone, numberOfConnections, onWsServerReady, payloadToTransportMessage, readNextResult, testingClientSessionOptions, testingSessionOptions, waitForMessage }; |
@@ -7,3 +7,3 @@ import { | ||
WritableImpl | ||
} from "../chunk-YBCQVIPR.js"; | ||
} from "../chunk-MADS7AI5.js"; | ||
import { | ||
@@ -13,8 +13,8 @@ SessionStateGraph, | ||
defaultTransportOptions | ||
} from "../chunk-OLWVR5AB.js"; | ||
} from "../chunk-6VA5DW7N.js"; | ||
import { | ||
coerceErrorString, | ||
currentProtocolVersion | ||
} from "../chunk-BYCR4VEM.js"; | ||
import "../chunk-4PVU7J25.js"; | ||
} from "../chunk-UQHYJZTP.js"; | ||
import "../chunk-AJGIY2UB.js"; | ||
@@ -111,2 +111,19 @@ // util/testHelpers.ts | ||
} | ||
function getClientSendFn(clientTransport, serverTransport) { | ||
const session = clientTransport.sessions.get(serverTransport.clientId) ?? clientTransport.createUnconnectedSession(serverTransport.clientId); | ||
return clientTransport.getSessionBoundSendFn( | ||
serverTransport.clientId, | ||
session.id | ||
); | ||
} | ||
function getServerSendFn(serverTransport, clientTransport) { | ||
const session = serverTransport.sessions.get(clientTransport.clientId); | ||
if (!session) { | ||
throw new Error("session not found"); | ||
} | ||
return serverTransport.getSessionBoundSendFn( | ||
clientTransport.clientId, | ||
session.id | ||
); | ||
} | ||
function dummyCtx(state, session, extendedContext) { | ||
@@ -134,7 +151,7 @@ return { | ||
const readable = new ReadableImpl(); | ||
const writable = new WritableImpl( | ||
(v) => { | ||
const writable = new WritableImpl({ | ||
writeCb: (v) => { | ||
readable._pushValue(v); | ||
}, | ||
() => { | ||
closeCb: () => { | ||
void Promise.resolve().then(() => { | ||
@@ -144,3 +161,3 @@ readable._triggerClose(); | ||
} | ||
); | ||
}); | ||
return { readable, writable }; | ||
@@ -150,7 +167,7 @@ } | ||
const readable = new ReadableImpl(); | ||
const writable = new WritableImpl( | ||
(v) => { | ||
const writable = new WritableImpl({ | ||
writeCb: (v) => { | ||
readable._pushValue(Ok(v)); | ||
}, | ||
() => { | ||
closeCb: () => { | ||
void Promise.resolve().then(() => { | ||
@@ -160,3 +177,3 @@ readable._triggerClose(); | ||
} | ||
); | ||
}); | ||
return { readable, writable }; | ||
@@ -227,3 +244,5 @@ } | ||
dummySession, | ||
getClientSendFn, | ||
getReadableIterator, | ||
getServerSendFn, | ||
getTransportConnections, | ||
@@ -230,0 +249,0 @@ isReadableDone, |
{ | ||
"name": "@replit/river", | ||
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!", | ||
"version": "0.200.0-rc.20", | ||
"version": "0.200.1", | ||
"type": "module", | ||
@@ -63,2 +63,3 @@ "exports": { | ||
"@opentelemetry/sdk-trace-web": "^1.24.1", | ||
"@stylistic/eslint-plugin": "^2.6.4", | ||
"@types/ws": "^8.5.5", | ||
@@ -65,0 +66,0 @@ "@typescript-eslint/eslint-plugin": "^7.8.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
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
1568005
16074
15