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

Function encodeJsonRpcResponse

packages/rpc/src/RpcSerialization.ts:321–361  ·  view source on GitHub ↗
(
  response:
    | RpcMessage.FromServerEncoded
    | RpcMessage.FromClientEncoded
    | Array<RpcMessage.FromServerEncoded | RpcMessage.FromClientEncoded>,
  batches: Map<string, {
    readonly size: number
    readonly responses: Map<string, RpcMessage.FromServerEncoded>
  }>
)

Source from the content-addressed store, hash-verified

319}
320
321function encodeJsonRpcResponse(
322 response:
323 | RpcMessage.FromServerEncoded
324 | RpcMessage.FromClientEncoded
325 | Array<RpcMessage.FromServerEncoded | RpcMessage.FromClientEncoded>,
326 batches: Map<string, {
327 readonly size: number
328 readonly responses: Map<string, RpcMessage.FromServerEncoded>
329 }>
330) {
331 if (Array.isArray(response) === false) {
332 return encodeJsonRpcRaw(response, batches)
333 }
334 if (response.length === 0) {
335 return undefined
336 }
337 const encoded: Array<JsonRpcMessage | Array<JsonRpcMessage>> = []
338 for (let i = 0; i < response.length; i++) {
339 const current = encodeJsonRpcRaw(response[i], batches)
340 if (current !== undefined) {
341 encoded.push(current)
342 }
343 }
344 if (encoded.length === 0) {
345 return undefined
346 }
347 if (encoded.length === 1) {
348 return encoded[0]
349 }
350 const messages: Array<JsonRpcMessage> = []
351 for (let i = 0; i < encoded.length; i++) {
352 const current = encoded[i]
353 if (Array.isArray(current)) {
354 // eslint-disable-next-line no-restricted-syntax
355 messages.push(...current)
356 } else {
357 messages.push(current)
358 }
359 }
360 return messages
361}
362
363function encodeJsonRpcMessage(response: RpcMessage.FromServerEncoded | RpcMessage.FromClientEncoded): JsonRpcMessage {
364 switch (response._tag) {

Callers 2

jsonRpcFunction · 0.85
ndJsonRpcFunction · 0.85

Calls 1

encodeJsonRpcRawFunction · 0.85

Tested by

no test coverage detected