import { type ZodSchema, type ZodTypeDef, z } from "zod"; export const singletonArray = ( schema: ZodSchema, ) => z .array(schema) .length(1) // eslint-disable-next-line @typescript-eslint/no-non-null-assertion .transform((value) => value[0]!); export const safeFetch = async ( schema: ZodSchema, ...fetchArgs: Parameters ) => { const response = await fetch(...fetchArgs); const json: unknown = await response.json(); return schema.parseAsync(json); };