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

Function jsonRpc

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

Source from the content-addressed store, hash-verified

147 * @category serialization
148 */
149export const jsonRpc = (options?: {
150 readonly contentType?: string | undefined
151}): RpcSerialization["Type"] =>
152 RpcSerialization.of({
153 contentType: options?.contentType ?? "application/json",
154 includesFraming: false,
155 unsafeMake: () => {
156 const decoder = new TextDecoder()
157 const batches = new Map<string, {
158 readonly size: number
159 readonly responses: Map<string, RpcMessage.FromServerEncoded>
160 }>()
161 return {
162 decode: (bytes) => {
163 const decoded: JsonRpcMessage | Array<JsonRpcMessage> = JSON.parse(
164 typeof bytes === "string" ? bytes : decoder.decode(bytes)
165 )
166 return decodeJsonRpcRaw(decoded, batches)
167 },
168 encode: (response) => {
169 const encoded = encodeJsonRpcResponse(response as any, batches)
170 return encoded && JSON.stringify(encoded)
171 }
172 }
173 }
174 })
175
176/**
177 * @since 1.0.0

Callers 1

layerJsonRpcFunction · 0.85

Calls 5

decodeJsonRpcRawFunction · 0.85
encodeJsonRpcResponseFunction · 0.85
parseMethod · 0.80
decodeMethod · 0.80
ofMethod · 0.65

Tested by

no test coverage detected