MCPcopy Create free account
hub / github.com/Effect-TS/effect / onRequest

Function onRequest

packages/effect/src/rpc/RpcClient.ts:315–360  ·  view source on GitHub ↗
(rpc: Rpc.AnyWithProps)

Source from the content-addressed store, hash-verified

313 }
314
315 const onRequest = (rpc: Rpc.AnyWithProps) => {
316 const isStream = RpcSchema.isStreamSchema(rpc.successSchema)
317 const middleware = getRpcClientMiddleware(rpc)
318 const tracing = Context.get(rpc.annotations, Rpc.TracingEnabled)
319 const createSpan = !disableTracing && (tracing === "both" || tracing === "client")
320 return (payload: any, opts?: {
321 readonly asQueue?: boolean | undefined
322 readonly streamBufferSize?: number | undefined
323 readonly headers?: Headers.Input | undefined
324 readonly context?: Context.Context<never> | undefined
325 readonly discard?: boolean | undefined
326 }) => {
327 const headers = opts?.headers ? Headers.fromInput(opts.headers) : Headers.empty
328 const context = opts?.context ?? Context.empty()
329 if (!isStream) {
330 const onRequest = (span: Tracer.Span | undefined) =>
331 onEffectRequest(
332 rpc,
333 middleware,
334 span,
335 rpc.payloadSchema.make(payload),
336 headers,
337 context,
338 opts?.discard ?? false
339 )
340 if (!createSpan) return onRequest(undefined)
341 const method = RpcTracing.methodName(groupTracing, rpc._tag)
342 return Effect.useSpan(
343 RpcTracing.spanName(spanPrefix, method),
344 { kind: "client", attributes: RpcTracing.spanAttributes(groupTracing, method, options.spanAttributes) },
345 onRequest
346 )
347 }
348 const queue = onStreamRequest(
349 rpc,
350 createSpan,
351 middleware,
352 rpc.payloadSchema.make(payload),
353 headers,
354 opts?.streamBufferSize ?? 16,
355 context
356 )
357 if (opts?.asQueue) return queue
358 return Stream.unwrap(Effect.map(queue, Stream.fromQueue))
359 }
360 }
361
362 const onEffectRequest = (
363 rpc: Rpc.AnyWithProps,

Callers 4

RpcClient.tsFile · 0.70
clientLayerFunction · 0.50
clientLayerFunction · 0.50
sendFunction · 0.50

Calls 5

getRpcClientMiddlewareFunction · 0.85
onEffectRequestFunction · 0.85
getMethod · 0.65
makeMethod · 0.65
mapMethod · 0.45

Tested by 3

clientLayerFunction · 0.40
clientLayerFunction · 0.40
sendFunction · 0.40