Comparing version 0.0.18 to 0.0.19
@@ -21,19 +21,52 @@ declare type OkStatus = 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299; | ||
declare type Result<Success = unknown, Failure = unknown> = SuccessResult<Success> | FailureResult<Failure>; | ||
declare type NonUndefined<T> = T extends unknown ? { | ||
readonly [K in keyof T as T[K] extends undefined ? never : K]: Exclude<T[K], undefined>; | ||
} : never; | ||
declare type MapTextResponse<Resp extends BasicResponse> = { | ||
readonly text: (text: string, response: Resp) => Result; | ||
readonly text: (body: string, response: Resp) => Result; | ||
readonly json?: undefined; | ||
readonly blob?: undefined; | ||
readonly arrayBuffer?: undefined; | ||
readonly formData?: undefined; | ||
readonly noBody?: undefined; | ||
}; | ||
declare type MapJsonResponse<Resp extends BasicResponse> = { | ||
readonly json: (json: unknown, response: Resp) => Result; | ||
readonly json: (body: unknown, response: Resp) => Result; | ||
readonly text?: undefined; | ||
readonly blob?: undefined; | ||
readonly arrayBuffer?: undefined; | ||
readonly formData?: undefined; | ||
readonly noBody?: undefined; | ||
}; | ||
declare type MapBlobResponse<Resp extends BasicResponse> = { | ||
readonly blob: (blob: Blob, response: Resp) => Result; | ||
readonly blob: (body: Blob, response: Resp) => Result; | ||
readonly json?: undefined; | ||
readonly text?: undefined; | ||
readonly arrayBuffer?: undefined; | ||
readonly formData?: undefined; | ||
readonly noBody?: undefined; | ||
}; | ||
declare type MapArrayBufferResponse<Resp extends BasicResponse> = { | ||
readonly arrayBuffer: (arrayBuffer: ArrayBuffer, response: Resp) => Result; | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Resp) => Result; | ||
readonly json?: undefined; | ||
readonly blob?: undefined; | ||
readonly text?: undefined; | ||
readonly formData?: undefined; | ||
readonly noBody?: undefined; | ||
}; | ||
declare type MapFormDataResponse<Resp extends BasicResponse> = { | ||
readonly formData: (formData: FormData, response: Resp) => Result; | ||
readonly formData: (body: FormData, response: Resp) => Result; | ||
readonly json?: undefined; | ||
readonly blob?: undefined; | ||
readonly arrayBuffer?: undefined; | ||
readonly text?: undefined; | ||
readonly noBody?: undefined; | ||
}; | ||
declare type MapNoBodyResponse<Resp extends BasicResponse> = { | ||
readonly noBody: (response: Resp) => Result; | ||
readonly json?: undefined; | ||
readonly blob?: undefined; | ||
readonly arrayBuffer?: undefined; | ||
readonly formData?: undefined; | ||
readonly text?: undefined; | ||
}; | ||
@@ -46,3 +79,3 @@ declare type MapResponse<Resp extends BasicResponse> = MapTextResponse<Resp> | MapJsonResponse<Resp> | MapBlobResponse<Resp> | MapArrayBufferResponse<Resp> | MapFormDataResponse<Resp> | MapNoBodyResponse<Resp>; | ||
}; | ||
declare type MapResultOf<Resp extends BasicResponse, Map extends MapResponse<Resp>> = Map extends { | ||
declare type MapResultOf<Resp extends BasicResponse, Map extends NonUndefined<MapResponse<Resp>>> = Map extends { | ||
readonly noBody: (r: Resp) => infer T; | ||
@@ -75,3 +108,7 @@ } ? ('json' | 'blob' | 'arrayBuffer' | 'formData' | 'text') & keyof Map extends never ? T : never : Map extends { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapJsonResponse<Response_1> ? ReturnType<(MapJsonResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -84,3 +121,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapBlobResponse<Response_1> ? ReturnType<(MapBlobResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -93,3 +134,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapTextResponse<Response_1> ? ReturnType<(MapTextResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -102,3 +147,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapFormDataResponse<Response_1> ? ReturnType<(MapFormDataResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -111,3 +160,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapArrayBufferResponse<Response_1> ? ReturnType<(MapArrayBufferResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -120,3 +173,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapNoBodyResponse<Response_1> ? ReturnType<(MapNoBodyResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -129,23 +186,47 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapResponse<Response_1> ? MapResultOf<Response_1, MapJsonResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} ? MapResultOf<Response_1, { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapTextResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapBlobResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapArrayBufferResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapFormDataResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapNoBodyResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -166,3 +247,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapJsonResponse<Response_1> ? ReturnType<(MapJsonResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -175,3 +260,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapBlobResponse<Response_1> ? ReturnType<(MapBlobResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -184,3 +273,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapTextResponse<Response_1> ? ReturnType<(MapTextResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -193,3 +286,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapFormDataResponse<Response_1> ? ReturnType<(MapFormDataResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -202,3 +299,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapArrayBufferResponse<Response_1> ? ReturnType<(MapArrayBufferResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -211,3 +312,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapNoBodyResponse<Response_1> ? ReturnType<(MapNoBodyResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -220,23 +325,47 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapResponse<Response_1> ? MapResultOf<Response_1, MapJsonResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} ? MapResultOf<Response_1, { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapTextResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapBlobResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapArrayBufferResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapFormDataResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapNoBodyResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -248,16 +377,39 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["ok" | "notOk" | keyof Map_1] extends MapResponse<Response_1> ? FailureOf<MapResultOf<Response_1, MapJsonResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }["ok" | "notOk" | keyof Map_1] extends { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} ? FailureOf<MapResultOf<Response_1, { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, MapTextResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, MapBlobResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, MapArrayBufferResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, MapFormDataResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, MapNoBodyResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }["ok" | "notOk" | keyof Map_1]>> | FailureOf<MapResultOf<Response_1, { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["ok" | "notOk" | keyof Map_1]>> extends never ? never : { | ||
readonly status: number; | ||
readonly validationError: FailureOf<{ readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
@@ -267,3 +419,7 @@ readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapJsonResponse<Response_1> ? ReturnType<(MapJsonResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -276,3 +432,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapBlobResponse<Response_1> ? ReturnType<(MapBlobResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -285,3 +445,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapTextResponse<Response_1> ? ReturnType<(MapTextResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -294,3 +458,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapFormDataResponse<Response_1> ? ReturnType<(MapFormDataResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -303,3 +471,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapArrayBufferResponse<Response_1> ? ReturnType<(MapArrayBufferResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -312,3 +484,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapNoBodyResponse<Response_1> ? ReturnType<(MapNoBodyResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -321,23 +497,47 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>] extends MapResponse<Response_1> ? MapResultOf<Response_1, MapJsonResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>] extends { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} ? MapResultOf<Response_1, { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapTextResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapBlobResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapArrayBufferResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapFormDataResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }>]> | MapResultOf<Response_1, MapNoBodyResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }>]> | MapResultOf<Response_1, { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -350,3 +550,7 @@ }; }[OkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapJsonResponse<Response_1> ? ReturnType<(MapJsonResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -359,3 +563,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapBlobResponse<Response_1> ? ReturnType<(MapBlobResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -368,3 +576,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapTextResponse<Response_1> ? ReturnType<(MapTextResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -377,3 +589,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapFormDataResponse<Response_1> ? ReturnType<(MapFormDataResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -386,3 +602,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapArrayBufferResponse<Response_1> ? ReturnType<(MapArrayBufferResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -395,3 +615,7 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapNoBodyResponse<Response_1> ? ReturnType<(MapNoBodyResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} ? ReturnType<({ | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -404,23 +628,47 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>] extends MapResponse<Response_1> ? MapResultOf<Response_1, MapJsonResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>] extends { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} | { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} ? MapResultOf<Response_1, { | ||
readonly json: (body: unknown, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapTextResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly text: (body: string, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapBlobResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly blob: (body: Blob, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapArrayBufferResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapFormDataResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly formData: (body: FormData, response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, MapNoBodyResponse<Response_1> & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
}; }, keyof Map_1>]> | MapResultOf<Response_1, { | ||
readonly noBody: (response: Response_1) => Result<unknown, unknown>; | ||
} & { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { | ||
readonly noBody: (response: Response_1) => SuccessResult<Response_1>; | ||
@@ -427,0 +675,0 @@ }; }["notOk" | NotOkKeys<Response_1, { readonly [Key in "ok" | "notOk" | keyof Map_1]: Map_1[Key] extends MapResponse<Response_1> ? Map_1[Key] : { |
@@ -5,25 +5,24 @@ function createFetchmap(fetch) { | ||
const serverErrorFailure = (serverError) => failure({ serverError }); | ||
const validationErrorFailure = (validationError, status) => failure({ validationError, status }); | ||
const mapFun = async (response, map) => 'noBody' in map | ||
const validationErrorFailure = (validationError) => failure({ validationError }); | ||
const mapFun = async (response, map = { noBody: success }) => map.noBody !== undefined | ||
? map.noBody(response) | ||
: 'json' in map | ||
: map.json !== undefined | ||
? map.json(await response.json(), response) | ||
: 'text' in map | ||
: map.text !== undefined | ||
? map.text(await response.text(), response) | ||
: 'blob' in map | ||
: map.blob !== undefined | ||
? map.blob(await response.blob(), response) | ||
: 'arrayBuffer' in map | ||
: map.arrayBuffer !== undefined | ||
? map.arrayBuffer(await response.arrayBuffer(), response) | ||
: map.formData(await response.formData(), response); | ||
function fetchmap(map, input, init) { | ||
return fetch(input, init) | ||
.then(async (response) => { | ||
var _a, _b; | ||
async function fetchmap(map, input, init) { | ||
try { | ||
const response = await fetch(input, init); | ||
const { status } = response; | ||
const isOk = status >= 200 && status <= 299; | ||
try { | ||
const validated = await mapFun(response, (_b = (_a = map[status]) !== null && _a !== void 0 ? _a : (isOk ? map.ok : map.notOk)) !== null && _b !== void 0 ? _b : { noBody: success }); | ||
const validated = await mapFun(response, map[status] === undefined ? (isOk ? map.ok : map.notOk) : map[status]); | ||
return validated.tag === 'success' | ||
? (isOk ? success : serverErrorFailure)(validated.success) | ||
: validationErrorFailure(validated.failure, status); | ||
: validationErrorFailure(validated.failure); | ||
} | ||
@@ -33,4 +32,6 @@ catch (mapError) { | ||
} | ||
}) | ||
.catch((clientError) => failure({ clientError })); | ||
} | ||
catch (clientError) { | ||
return failure({ clientError }); | ||
} | ||
} | ||
@@ -37,0 +38,0 @@ return fetchmap; |
{ | ||
"name": "fetchmap", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"description": "Non-throwing fetch wrapper", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
192
src/index.ts
@@ -126,23 +126,60 @@ type OkStatus = | ||
// source: https://github.com/microsoft/TypeScript/issues/38646#issuecomment-1054510795 | ||
type NonUndefined<T> = T extends unknown | ||
? { readonly [K in keyof T as T[K] extends undefined ? never : K]: Exclude<T[K], undefined> } | ||
: never | ||
type MapTextResponse<Resp extends BasicResponse> = { | ||
readonly text: (text: string, response: Resp) => Result | ||
readonly text: (body: string, response: Resp) => Result | ||
readonly json?: undefined | ||
readonly blob?: undefined | ||
readonly arrayBuffer?: undefined | ||
readonly formData?: undefined | ||
readonly noBody?: undefined | ||
} | ||
type MapJsonResponse<Resp extends BasicResponse> = { | ||
readonly json: (json: unknown, response: Resp) => Result | ||
readonly json: (body: unknown, response: Resp) => Result | ||
readonly text?: undefined | ||
readonly blob?: undefined | ||
readonly arrayBuffer?: undefined | ||
readonly formData?: undefined | ||
readonly noBody?: undefined | ||
} | ||
type MapBlobResponse<Resp extends BasicResponse> = { | ||
readonly blob: (blob: Blob, response: Resp) => Result | ||
readonly blob: (body: Blob, response: Resp) => Result | ||
readonly json?: undefined | ||
readonly text?: undefined | ||
readonly arrayBuffer?: undefined | ||
readonly formData?: undefined | ||
readonly noBody?: undefined | ||
} | ||
type MapArrayBufferResponse<Resp extends BasicResponse> = { | ||
readonly arrayBuffer: (arrayBuffer: ArrayBuffer, response: Resp) => Result | ||
readonly arrayBuffer: (body: ArrayBuffer, response: Resp) => Result | ||
readonly json?: undefined | ||
readonly blob?: undefined | ||
readonly text?: undefined | ||
readonly formData?: undefined | ||
readonly noBody?: undefined | ||
} | ||
type MapFormDataResponse<Resp extends BasicResponse> = { | ||
readonly formData: (formData: FormData, response: Resp) => Result | ||
readonly formData: (body: FormData, response: Resp) => Result | ||
readonly json?: undefined | ||
readonly blob?: undefined | ||
readonly arrayBuffer?: undefined | ||
readonly text?: undefined | ||
readonly noBody?: undefined | ||
} | ||
type MapNoBodyResponse<Resp extends BasicResponse> = { readonly noBody: (response: Resp) => Result } | ||
type MapNoBodyResponse<Resp extends BasicResponse> = { | ||
readonly noBody: (response: Resp) => Result | ||
readonly json?: undefined | ||
readonly blob?: undefined | ||
readonly arrayBuffer?: undefined | ||
readonly formData?: undefined | ||
readonly text?: undefined | ||
} | ||
@@ -163,3 +200,12 @@ type MapResponse<Resp extends BasicResponse> = | ||
type MapResultOf<Resp extends BasicResponse, Map extends MapResponse<Resp>> = Map extends { | ||
type InternalMultiMapResponse<Resp extends BasicResponse> = { | ||
readonly [code: number]: NonUndefined<MapResponse<Resp>> | ||
readonly ok: NonUndefined<MapResponse<Resp>> | ||
readonly notOk: NonUndefined<MapResponse<Resp>> | ||
} | ||
type MapResultOf< | ||
Resp extends BasicResponse, | ||
Map extends NonUndefined<MapResponse<Resp>> | ||
> = Map extends { | ||
readonly noBody: (r: Resp) => infer T | ||
@@ -170,5 +216,3 @@ } | ||
: never | ||
: Map extends { | ||
readonly text: (b: string, r: Resp) => infer T | ||
} | ||
: Map extends { readonly text: (b: string, r: Resp) => infer T } | ||
? ('json' | 'blob' | 'arrayBuffer' | 'formData' | 'noBody') & keyof Map extends never | ||
@@ -210,36 +254,35 @@ ? T | ||
> = FailureResult< | ||
| (Map[keyof Map] extends MapResponse<Resp> | ||
| (Map[keyof Map] extends NonUndefined<MapResponse<Resp>> | ||
? FailureOf<MapResultOf<Resp, Map[keyof Map]>> extends never | ||
? never | ||
: { | ||
readonly status: number | ||
readonly validationError: FailureOf< | ||
| (Map[SuccessKeys] extends MapJsonResponse<Resp> | ||
| (Map[SuccessKeys] extends NonUndefined<MapJsonResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['json']> | ||
: Map[SuccessKeys] extends MapBlobResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapBlobResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['blob']> | ||
: Map[SuccessKeys] extends MapTextResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapTextResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['text']> | ||
: Map[SuccessKeys] extends MapFormDataResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapFormDataResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['formData']> | ||
: Map[SuccessKeys] extends MapArrayBufferResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapArrayBufferResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['arrayBuffer']> | ||
: Map[SuccessKeys] extends MapNoBodyResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapNoBodyResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['noBody']> | ||
: Map[SuccessKeys] extends MapResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapResponse<Resp>> | ||
? MapResultOf<Resp, Map[SuccessKeys]> | ||
: never) | ||
| (Map[FailureKeys] extends MapJsonResponse<Resp> | ||
| (Map[FailureKeys] extends NonUndefined<MapJsonResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['json']> | ||
: Map[FailureKeys] extends MapBlobResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapBlobResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['blob']> | ||
: Map[FailureKeys] extends MapTextResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapTextResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['text']> | ||
: Map[FailureKeys] extends MapFormDataResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapFormDataResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['formData']> | ||
: Map[FailureKeys] extends MapArrayBufferResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapArrayBufferResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['arrayBuffer']> | ||
: Map[FailureKeys] extends MapNoBodyResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapNoBodyResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['noBody']> | ||
: Map[FailureKeys] extends MapResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapResponse<Resp>> | ||
? MapResultOf<Resp, Map[FailureKeys]> | ||
@@ -252,15 +295,15 @@ : never) | ||
readonly serverError: SuccessOf< | ||
Map[FailureKeys] extends MapJsonResponse<Resp> | ||
Map[FailureKeys] extends NonUndefined<MapJsonResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['json']> | ||
: Map[FailureKeys] extends MapBlobResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapBlobResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['blob']> | ||
: Map[FailureKeys] extends MapTextResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapTextResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['text']> | ||
: Map[FailureKeys] extends MapFormDataResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapFormDataResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['formData']> | ||
: Map[FailureKeys] extends MapArrayBufferResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapArrayBufferResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['arrayBuffer']> | ||
: Map[FailureKeys] extends MapNoBodyResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapNoBodyResponse<Resp>> | ||
? ReturnType<Map[FailureKeys]['noBody']> | ||
: Map[FailureKeys] extends MapResponse<Resp> | ||
: Map[FailureKeys] extends NonUndefined<MapResponse<Resp>> | ||
? MapResultOf<Resp, Map[FailureKeys]> | ||
@@ -280,15 +323,15 @@ : never | ||
SuccessOf< | ||
Map[SuccessKeys] extends MapJsonResponse<Resp> | ||
Map[SuccessKeys] extends NonUndefined<MapJsonResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['json']> | ||
: Map[SuccessKeys] extends MapBlobResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapBlobResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['blob']> | ||
: Map[SuccessKeys] extends MapTextResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapTextResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['text']> | ||
: Map[SuccessKeys] extends MapFormDataResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapFormDataResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['formData']> | ||
: Map[SuccessKeys] extends MapArrayBufferResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapArrayBufferResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['arrayBuffer']> | ||
: Map[SuccessKeys] extends MapNoBodyResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapNoBodyResponse<Resp>> | ||
? ReturnType<Map[SuccessKeys]['noBody']> | ||
: Map[SuccessKeys] extends MapResponse<Resp> | ||
: Map[SuccessKeys] extends NonUndefined<MapResponse<Resp>> | ||
? MapResultOf<Resp, Map[SuccessKeys]> | ||
@@ -329,15 +372,17 @@ : never | ||
const serverErrorFailure = <T>(serverError: T) => failure({ serverError }) | ||
const validationErrorFailure = <T>(validationError: T, status: number) => | ||
failure({ validationError, status }) | ||
const validationErrorFailure = <T>(validationError: T) => failure({ validationError }) | ||
const mapFun = async <Resp extends BasicResponse>(response: Resp, map: MapResponse<Resp>) => | ||
'noBody' in map | ||
const mapFun = async <Resp extends BasicResponse>( | ||
response: Resp, | ||
map: MapResponse<Resp> = { noBody: success } | ||
) => | ||
map.noBody !== undefined | ||
? map.noBody(response) | ||
: 'json' in map | ||
: map.json !== undefined | ||
? map.json(await response.json(), response) | ||
: 'text' in map | ||
: map.text !== undefined | ||
? map.text(await response.text(), response) | ||
: 'blob' in map | ||
: map.blob !== undefined | ||
? map.blob(await response.blob(), response) | ||
: 'arrayBuffer' in map | ||
: map.arrayBuffer !== undefined | ||
? map.arrayBuffer(await response.arrayBuffer(), response) | ||
@@ -353,6 +398,6 @@ : map.formData(await response.formData(), response) | ||
* otherwise. Both `ok` and `notOk` just return `SuccessResult` with received `Response` object by | ||
* default. Each transform is a `(response: Response) => Result<Success, Failure>` function or an | ||
* object that represents a mapping from body reading method (`json`, `text`, `blob`, | ||
* `arrayBuffer`, `formData`) to `(body: BodyType, response: Response) => Result<Success, Failure>` | ||
* validating transform. | ||
* default. Each transform is an object that represents a mapping from body reading method | ||
* (`json`, `text`, `blob`, `arrayBuffer`, `formData`) to | ||
* `(body: BodyType, response: Response) => Result<Success, Failure>` validating transform or an | ||
* object without body mapping - `{ noBody: (response: Response) => Result<Success, Failure> }` | ||
* | ||
@@ -378,3 +423,3 @@ * @param input `fetch` function first argument | ||
*/ | ||
function fetchmap< | ||
async function fetchmap< | ||
Response extends Awaited<ReturnType<Fetch>>, | ||
@@ -384,26 +429,27 @@ Map extends Partial<MultiMapResponse<Response>> | ||
function fetchmap( | ||
map: Partial<MultiMapResponse<BasicResponse>>, | ||
async function fetchmap( | ||
map: Partial<InternalMultiMapResponse<BasicResponse>>, | ||
input: Input, | ||
init?: Init | ||
): Promise<FetchResult<BasicResponse, MultiMapResponse<BasicResponse>>> { | ||
return fetch(input, init) | ||
.then(async (response) => { | ||
const { status } = response | ||
const isOk = status >= 200 && status <= 299 | ||
): Promise<FetchResult<BasicResponse, InternalMultiMapResponse<BasicResponse>>> { | ||
try { | ||
const response = await fetch(input, init) | ||
const { status } = response | ||
const isOk = status >= 200 && status <= 299 | ||
try { | ||
const validated = await mapFun( | ||
response, | ||
map[status] ?? (isOk ? map.ok : map.notOk) ?? { noBody: success } | ||
) | ||
try { | ||
const validated = await mapFun( | ||
response, | ||
map[status] === undefined ? (isOk ? map.ok : map.notOk) : map[status] | ||
) | ||
return validated.tag === 'success' | ||
? (isOk ? success : serverErrorFailure)(validated.success) | ||
: validationErrorFailure(validated.failure, status) | ||
} catch (mapError) { | ||
return failure({ mapError }) | ||
} | ||
}) | ||
.catch((clientError: unknown) => failure({ clientError })) | ||
return validated.tag === 'success' | ||
? (isOk ? success : serverErrorFailure)(validated.success) | ||
: validationErrorFailure(validated.failure) | ||
} catch (mapError) { | ||
return failure({ mapError }) | ||
} | ||
} catch (clientError) { | ||
return failure({ clientError }) | ||
} | ||
} | ||
@@ -410,0 +456,0 @@ |
@@ -169,4 +169,4 @@ import { spawn } from 'child_process' | ||
const result = await fetchmap({ ok: { json: () => failure('fail') } }, url('json')) | ||
expect(result).toEqual<typeof result>(failure({ validationError: 'fail', status: 200 })) | ||
expect(result).toEqual<typeof result>(failure({ validationError: 'fail' })) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91635
1321