(options?: {
readonly contentType?: string | undefined
})
| 179 | * @since 4.0.0 |
| 180 | */ |
| 181 | export 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 |
no test coverage detected