import { Schema, z } from 'zod'; import fetchWithValidation from './fetchWithValidation'; // https://stackoverflow.com/a/64919133 class Wrapper { // eslint-disable-next-line class-methods-use-this wrapped( url: string, schema: Schema, options?: RequestInit, errorSchema?: Schema, ) { return fetchWithValidation(url, schema, options, errorSchema); } } type FetchWithValidationInternalType = ReturnType['wrapped']> export default function simpleFetch( f: (...params: P) => FetchWithValidationInternalType, ) { return async (...params: Parameters) => { const result = await f(...params); if (result.isErr()) throw new Error(result.error.message); return result.value; }; }