(value: IOPacket)
| 11 | }; |
| 12 | |
| 13 | export async function parsePacket(value: IOPacket): Promise<any> { |
| 14 | if (!value.data) { |
| 15 | return undefined; |
| 16 | } |
| 17 | |
| 18 | switch (value.dataType) { |
| 19 | case "application/json": |
| 20 | return JSON.parse(value.data); |
| 21 | case "application/super+json": |
| 22 | const { parse } = await loadSuperJSON(); |
| 23 | |
| 24 | return parse(value.data); |
| 25 | case "text/plain": |
| 26 | return value.data; |
| 27 | case "application/store": |
| 28 | throw new Error( |
| 29 | `Cannot parse an application/store packet (${value.data}). Needs to be imported first.` |
| 30 | ); |
| 31 | default: |
| 32 | return value.data; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | export async function stringifyIO(value: any): Promise<IOPacket> { |
| 37 | if (value === undefined) { |
no test coverage detected
searching dependent graphs…