( schema: z.Schema<T>, json: string )
| 13 | } |
| 14 | |
| 15 | export function safeJsonZodParse<T>( |
| 16 | schema: z.Schema<T>, |
| 17 | json: string |
| 18 | ): z.SafeParseReturnType<unknown, T> | undefined { |
| 19 | const parsed = safeJsonParse(json); |
| 20 | |
| 21 | if (parsed === null) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | return schema.safeParse(parsed); |
| 26 | } |
| 27 | |
| 28 | export async function safeJsonFromResponse(response: Response) { |
| 29 | const json = await response.text(); |
no test coverage detected
searching dependent graphs…