UNPKG

1.28 kBTypeScriptView Raw
1import * as fatcher from 'fatcher';
2import { Context } from 'fatcher';
3
4declare type RoadSign = {
5 abort: () => void;
6 signal: AbortSignal;
7};
8declare type RoadMap = Record<string, RoadSign[]>;
9interface AborterMiddlewareContext extends Readonly<Context> {
10 /**
11 * Provides with aborter
12 *
13 * @require `@fatcherjs/middleware-aborter`
14 */
15 abort: () => void;
16 signal: AbortSignal;
17}
18interface AborterOptions {
19 /**
20 * Request timeout
21 *
22 * `ms`
23 *
24 * @default 0
25 */
26 timeout?: number;
27 /**
28 * Callback with aborted request.
29 *
30 * @default null
31 */
32 onAbort?: (() => void) | null;
33 /**
34 * Request concurrency restrictions
35 *
36 * @default false
37 */
38 concurrency?: boolean;
39 /**
40 * Concurrency key.
41 */
42 groupBy?: (context: Readonly<Context>) => string;
43}
44
45/**
46 * A middleware for aborting fatcher request.
47 * @param options
48 * @returns
49 */
50declare function aborter(options?: AborterOptions): fatcher.Middleware[];
51
52/**
53 * Confirm an error whether is DOMException
54 * @param error
55 * @returns
56 */
57declare function isAbortError(error: unknown): error is DOMException;
58
59export { AborterMiddlewareContext, AborterOptions, RoadMap, RoadSign, aborter, isAbortError };