@@ -136,7 +136,7 @@ export type EnvironmentRpcStreamFailure<TTag extends EnvironmentStreamRpcTag> =
136136 ? E
137137 : never ;
138138
139- const currentSession = Effect . fn ( "EnvironmentRpc.currentSession" ) ( function * ( ) {
139+ export const currentSession = Effect . fn ( "EnvironmentRpc.currentSession" ) ( function * ( ) {
140140 const supervisor = yield * EnvironmentSupervisor . EnvironmentSupervisor ;
141141 return yield * SubscriptionRef . get ( supervisor . session ) . pipe (
142142 Effect . flatMap (
@@ -194,7 +194,7 @@ const authorizeRequest = Effect.fn("EnvironmentRpc.authorize")(function* (
194194 yield * guard . authorize ( supervisor . target . environmentId , method , input ) ;
195195} ) ;
196196
197- const requestInSession = Effect . fn ( "EnvironmentRpc.request" ) ( function * <
197+ export const requestInSession = Effect . fn ( "EnvironmentRpc.request" ) ( function * <
198198 TTag extends EnvironmentUnaryRpcTag ,
199199> ( session : RpcSession , tag : TTag , input : EnvironmentRpcInput < TTag > ) {
200200 const supervisor = yield * EnvironmentSupervisor . EnvironmentSupervisor ;
@@ -234,16 +234,23 @@ export function runStreamGuarded<TTag extends EnvironmentStreamCommandRpcTag>(
234234 EnvironmentSupervisor . EnvironmentSupervisor
235235> {
236236 return Stream . unwrap (
237- authorizeRequest ( tag , input ) . pipe (
238- Effect . andThen ( currentSession ( ) ) ,
239- Effect . map ( ( session ) => {
240- const method = session . client [ tag ] as (
241- input : EnvironmentRpcInput < TTag > ,
242- ) => Stream . Stream < EnvironmentRpcStreamValue < TTag > , EnvironmentRpcStreamFailure < TTag > > ;
243- return method ( input ) ;
244- } ) ,
245- ) ,
246- ) . pipe (
237+ currentSession ( ) . pipe ( Effect . map ( ( session ) => runStreamInSession ( session , tag , input ) ) ) ,
238+ ) ;
239+ }
240+
241+ export function runStreamInSession < TTag extends EnvironmentStreamCommandRpcTag > (
242+ session : RpcSession ,
243+ tag : TTag ,
244+ input : EnvironmentRpcInput < TTag > ,
245+ ) : Stream . Stream <
246+ EnvironmentRpcStreamValue < TTag > ,
247+ EnvironmentRpcStreamFailure < TTag > | EnvironmentAuthorizationError ,
248+ EnvironmentSupervisor . EnvironmentSupervisor
249+ > {
250+ const method = session . client [ tag ] as (
251+ input : EnvironmentRpcInput < TTag > ,
252+ ) => Stream . Stream < EnvironmentRpcStreamValue < TTag > , EnvironmentRpcStreamFailure < TTag > > ;
253+ return Stream . unwrap ( authorizeRequest ( tag , input ) . pipe ( Effect . map ( ( ) => method ( input ) ) ) ) . pipe (
247254 Stream . withSpan ( "EnvironmentRpc.runStream" , {
248255 attributes : { "rpc.method" : tag } ,
249256 } ) ,
0 commit comments