(options?: {
readonly contentType?: string | undefined
})
| 147 | * @category serialization |
| 148 | */ |
| 149 | export 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 |
no test coverage detected