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

Function jsonRpc

packages/effect/src/unstable/rpc/RpcSerialization.ts:181–206  ·  view source on GitHub ↗
(options?: {
  readonly contentType?: string | undefined
})

Source from the content-addressed store, hash-verified

179 * @since 4.0.0
180 */
181export const jsonRpc = (options?: {
182 readonly contentType?: string | undefined
183}): RpcSerialization["Service"] =>
184 RpcSerialization.of({
185 contentType: options?.contentType ?? "application/json",
186 includesFraming: false,
187 makeUnsafe: () => {
188 const decoder = new TextDecoder()
189 const batches = new Map<string | number, {
190 readonly size: number
191 readonly responses: Map<string | number, RpcMessage.FromServerEncoded>
192 }>()
193 return {
194 decode: (bytes) => {
195 const decoded: JsonRpcMessage | Array<JsonRpcMessage> = JSON.parse(
196 typeof bytes === "string" ? bytes : decoder.decode(bytes)
197 )
198 return decodeJsonRpcRaw(decoded, batches)
199 },
200 encode: (response) => {
201 const encoded = encodeJsonRpcResponse(response as any, batches)
202 return encoded && JSON.stringify(encoded)
203 }
204 }
205 }
206 })
207
208/**
209 * Creates a newline-delimited JSON-RPC 2.0 serialization for RPC protocol

Callers 1

layerJsonRpcFunction · 0.85

Calls 4

decodeJsonRpcRawFunction · 0.85
encodeJsonRpcResponseFunction · 0.85
ofMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected