@hyper-fetch/core 6.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +8 -3
- package/README.md +5 -5
- package/dist/browser/index.js +3711 -0
- package/dist/browser/index.js.map +7 -0
- package/dist/index.d.ts +1669 -1091
- package/dist/index.js +3949 -0
- package/dist/index.js.map +7 -0
- package/package.json +16 -18
- package/src/adapter/adapter.bindings.ts +261 -165
- package/src/adapter/adapter.ts +480 -8
- package/src/adapter/adapter.types.ts +111 -139
- package/src/adapter/adapter.utils.ts +71 -25
- package/src/adapter/index.ts +1 -2
- package/src/cache/cache.events.ts +58 -14
- package/src/cache/cache.ts +158 -91
- package/src/cache/cache.types.ts +15 -25
- package/src/cache/cache.utils.ts +17 -10
- package/src/client/client.create.ts +17 -0
- package/src/client/client.ts +247 -266
- package/src/client/client.types.ts +43 -21
- package/src/client/client.utils.ts +7 -168
- package/src/client/index.ts +1 -0
- package/src/constants/http.constants.ts +6 -6
- package/src/constants/time.constants.ts +10 -10
- package/src/dispatcher/dispatcher.constants.ts +5 -5
- package/src/dispatcher/dispatcher.events.ts +85 -20
- package/src/dispatcher/dispatcher.ts +265 -199
- package/src/dispatcher/dispatcher.types.ts +6 -7
- package/src/dispatcher/dispatcher.utils.ts +26 -10
- package/src/http-adapter/http-adapter.browser.ts +101 -0
- package/src/http-adapter/http-adapter.constants.ts +8 -0
- package/src/http-adapter/http-adapter.server.ts +134 -0
- package/src/http-adapter/http-adapter.ts +11 -0
- package/src/http-adapter/http-adapter.types.ts +86 -0
- package/src/http-adapter/http-adapter.utils.ts +177 -0
- package/src/http-adapter/index.ts +4 -0
- package/src/index.ts +2 -1
- package/src/managers/app/app.manager.constants.ts +4 -4
- package/src/managers/app/app.manager.events.ts +12 -12
- package/src/managers/app/app.manager.ts +10 -7
- package/src/managers/app/app.manager.utils.ts +12 -2
- package/src/managers/logger/logger.manager.constants.ts +13 -18
- package/src/managers/logger/logger.manager.ts +37 -49
- package/src/managers/logger/logger.manager.types.ts +32 -21
- package/src/managers/logger/logger.manager.utils.ts +23 -17
- package/src/managers/request/request.manager.events.ts +222 -109
- package/src/managers/request/request.manager.ts +5 -2
- package/src/managers/request/request.manager.types.ts +35 -7
- package/src/managers/request/request.manager.utils.ts +29 -17
- package/src/mocker/mocker.ts +115 -81
- package/src/mocker/mocker.types.ts +29 -25
- package/src/plugin/index.ts +2 -0
- package/src/plugin/plugin.ts +159 -0
- package/src/plugin/plugin.types.ts +181 -0
- package/src/request/request.ts +371 -323
- package/src/request/request.types.ts +136 -145
- package/src/request/request.utils.ts +31 -30
- package/src/types/adapter.types.ts +63 -0
- package/src/types/client.types.ts +3 -3
- package/src/types/helpers.types.ts +16 -3
- package/src/types/hydration.types.ts +16 -0
- package/src/types/index.ts +3 -1
- package/src/types/request.types.ts +73 -0
- package/src/utils/emitter.utils.ts +52 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/uuid.utils.ts +4 -2
- package/tsconfig.base.json +4 -5
- package/tsconfig.json +5 -4
- package/dist/browser/index.cjs.js +0 -2420
- package/dist/browser/index.cjs.js.map +0 -7
- package/dist/browser/index.esm.js +0 -2395
- package/dist/browser/index.esm.js.map +0 -7
- package/dist/index.cjs.js +0 -2579
- package/dist/index.cjs.js.map +0 -7
- package/dist/index.esm.js +0 -2474
- package/dist/index.esm.js.map +0 -7
- package/src/adapter/adapter.browser.ts +0 -100
- package/src/adapter/adapter.constants.ts +0 -8
- package/src/adapter/adapter.server.ts +0 -93
- package/src/effect/index.ts +0 -2
- package/src/effect/request.effect.ts +0 -31
- package/src/effect/request.effect.types.ts +0 -44
- package/src/types/fetch.types.ts +0 -50
|
@@ -1,11 +1,32 @@
|
|
|
1
1
|
import { RequestInstance } from "request";
|
|
2
|
-
import {
|
|
2
|
+
import { AdapterInstance, ResponseType } from "adapter";
|
|
3
3
|
import { Client } from "client";
|
|
4
|
-
import {
|
|
4
|
+
import type { ExtendRequest, ExtractClientAdapterType, TypeWithDefaults } from "types";
|
|
5
5
|
|
|
6
6
|
export type ClientErrorType = Record<string, any> | string;
|
|
7
|
-
export type
|
|
8
|
-
|
|
7
|
+
export type ClientInstanceProperties = {
|
|
8
|
+
error?: any;
|
|
9
|
+
adapter?: AdapterInstance;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ClientInstance<
|
|
13
|
+
ClientProperties extends ClientInstanceProperties = {
|
|
14
|
+
error?: any;
|
|
15
|
+
adapter?: AdapterInstance;
|
|
16
|
+
},
|
|
17
|
+
> = Client<
|
|
18
|
+
TypeWithDefaults<ClientProperties, "error", any>,
|
|
19
|
+
TypeWithDefaults<ClientProperties, "adapter", AdapterInstance>
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
export type RequestGenericType<QueryParams> = {
|
|
23
|
+
response?: any;
|
|
24
|
+
payload?: any;
|
|
25
|
+
error?: any;
|
|
26
|
+
queryParams?: QueryParams;
|
|
27
|
+
endpoint?: string;
|
|
28
|
+
params?: Record<string, string | number>;
|
|
29
|
+
};
|
|
9
30
|
|
|
10
31
|
/**
|
|
11
32
|
* Configuration setup for the client
|
|
@@ -15,40 +36,41 @@ export type ClientOptionsType<C extends ClientInstance> = {
|
|
|
15
36
|
* Url to your server
|
|
16
37
|
*/
|
|
17
38
|
url: string;
|
|
18
|
-
/**
|
|
19
|
-
* Custom adapter initialization prop
|
|
20
|
-
*/
|
|
21
|
-
adapter?: AdapterType;
|
|
22
39
|
/**
|
|
23
40
|
* Custom cache initialization prop
|
|
24
41
|
*/
|
|
25
|
-
cache?: (
|
|
42
|
+
cache?: () => C["cache"];
|
|
26
43
|
/**
|
|
27
44
|
* Custom app manager initialization prop
|
|
28
45
|
*/
|
|
29
|
-
appManager?: (
|
|
46
|
+
appManager?: () => C["appManager"];
|
|
30
47
|
/**
|
|
31
48
|
* Custom fetch dispatcher initialization prop
|
|
32
49
|
*/
|
|
33
|
-
fetchDispatcher?: (
|
|
50
|
+
fetchDispatcher?: () => C["submitDispatcher"];
|
|
34
51
|
/**
|
|
35
52
|
* Custom submit dispatcher initialization prop
|
|
36
53
|
*/
|
|
37
|
-
submitDispatcher?: (
|
|
54
|
+
submitDispatcher?: () => C["fetchDispatcher"];
|
|
38
55
|
};
|
|
39
56
|
|
|
40
57
|
// Interceptors
|
|
41
58
|
|
|
42
59
|
export type RequestInterceptorType = (request: RequestInstance) => Promise<RequestInstance> | RequestInstance;
|
|
43
|
-
export type ResponseInterceptorType<
|
|
44
|
-
response:
|
|
45
|
-
request:
|
|
46
|
-
|
|
60
|
+
export type ResponseInterceptorType<Client extends ClientInstance, Response = any, Error = any> = (
|
|
61
|
+
response: ResponseType<Response, Error, ExtractClientAdapterType<Client>>,
|
|
62
|
+
request: ExtendRequest<
|
|
63
|
+
RequestInstance,
|
|
64
|
+
{
|
|
65
|
+
client: Client;
|
|
66
|
+
}
|
|
67
|
+
>,
|
|
68
|
+
) =>
|
|
69
|
+
| Promise<ResponseType<any, any, ExtractClientAdapterType<Client>>>
|
|
70
|
+
| ResponseType<any, any, ExtractClientAdapterType<Client>>;
|
|
47
71
|
|
|
48
72
|
// Stringify
|
|
49
73
|
|
|
50
|
-
export type
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export type DefaultEndpointMapper = (endpoint: any) => string;
|
|
74
|
+
export type ModifyQueryParamsCallbackType<QueryParams, ModifiedQueryParams> = (
|
|
75
|
+
queryParams: QueryParams,
|
|
76
|
+
) => ModifiedQueryParams;
|
|
@@ -1,26 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
QueryParamType,
|
|
3
|
-
QueryParamsType,
|
|
4
|
-
QueryParamValuesType,
|
|
5
|
-
ResponseReturnType,
|
|
6
|
-
QueryStringifyOptionsType,
|
|
7
|
-
AdapterInstance,
|
|
8
|
-
} from "adapter";
|
|
1
|
+
import { ResponseType } from "adapter";
|
|
9
2
|
import { RequestInstance } from "request";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { RequestInterceptorType, ResponseInterceptorType } from "./client.types";
|
|
13
|
-
import { hasWindow } from "managers";
|
|
14
|
-
|
|
15
|
-
// Utils
|
|
16
|
-
|
|
17
|
-
export const stringifyValue = (response: string | unknown): string => {
|
|
18
|
-
try {
|
|
19
|
-
return JSON.stringify(response as string);
|
|
20
|
-
} catch (err) {
|
|
21
|
-
return "";
|
|
22
|
-
}
|
|
23
|
-
};
|
|
3
|
+
import { ExtendRequest, ExtractClientAdapterType } from "types";
|
|
4
|
+
import { ClientInstance, RequestInterceptorType, ResponseInterceptorType } from "./client.types";
|
|
24
5
|
|
|
25
6
|
export const interceptRequest = async (interceptors: RequestInterceptorType[], request: RequestInstance) => {
|
|
26
7
|
let newRequest = request;
|
|
@@ -35,10 +16,10 @@ export const interceptRequest = async (interceptors: RequestInterceptorType[], r
|
|
|
35
16
|
return newRequest;
|
|
36
17
|
};
|
|
37
18
|
|
|
38
|
-
export const interceptResponse = async <GlobalErrorType,
|
|
39
|
-
interceptors: ResponseInterceptorType[],
|
|
40
|
-
response:
|
|
41
|
-
request: RequestInstance,
|
|
19
|
+
export const interceptResponse = async <GlobalErrorType, Client extends ClientInstance>(
|
|
20
|
+
interceptors: ResponseInterceptorType<Client>[],
|
|
21
|
+
response: ResponseType<any, GlobalErrorType, ExtractClientAdapterType<Client>>,
|
|
22
|
+
request: ExtendRequest<RequestInstance, { client: Client }>,
|
|
42
23
|
) => {
|
|
43
24
|
let newResponse = response;
|
|
44
25
|
if (!request.requestOptions.disableResponseInterceptors) {
|
|
@@ -51,145 +32,3 @@ export const interceptResponse = async <GlobalErrorType, Adapter extends Adapter
|
|
|
51
32
|
}
|
|
52
33
|
return newResponse;
|
|
53
34
|
};
|
|
54
|
-
// Mappers
|
|
55
|
-
|
|
56
|
-
export const getAdapterHeaders = (request: RequestInstance) => {
|
|
57
|
-
const isFormData = hasWindow() && request.data instanceof FormData;
|
|
58
|
-
const headers: HeadersInit = {};
|
|
59
|
-
|
|
60
|
-
if (!isFormData) headers["Content-Type"] = "application/json";
|
|
61
|
-
|
|
62
|
-
Object.assign(headers, request.headers);
|
|
63
|
-
return headers as HeadersInit;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export const getAdapterPayload = (data: unknown): string | FormData => {
|
|
67
|
-
const isFormData = hasWindow() && data instanceof FormData;
|
|
68
|
-
if (isFormData) return data;
|
|
69
|
-
|
|
70
|
-
return stringifyValue(data);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
// Stringify
|
|
74
|
-
|
|
75
|
-
const isValidValue = (options: QueryStringifyOptionsType) => {
|
|
76
|
-
return (value: QueryParamType) => {
|
|
77
|
-
const { skipNull, skipEmptyString } = options;
|
|
78
|
-
|
|
79
|
-
if (skipEmptyString && value === undefined) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
if (skipEmptyString && value === "") {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
if (skipNull && value === null) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const encodeValue = (
|
|
93
|
-
value: string,
|
|
94
|
-
{ encode, strict }: Pick<QueryStringifyOptionsType, "encode" | "strict">,
|
|
95
|
-
): string => {
|
|
96
|
-
if (encode && strict) {
|
|
97
|
-
return encodeURIComponent(value).replace(/[!'()*]/g, (s) => `%${s.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
98
|
-
}
|
|
99
|
-
if (encode) {
|
|
100
|
-
return encodeURIComponent(value);
|
|
101
|
-
}
|
|
102
|
-
return value;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const encodeParams = (key: string, value: QueryParamType, options: QueryStringifyOptionsType) => {
|
|
106
|
-
const shouldSkip = !isValidValue(options)(value);
|
|
107
|
-
|
|
108
|
-
if (!key || shouldSkip) {
|
|
109
|
-
return "";
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const parsedValue = () => {
|
|
113
|
-
if (value instanceof Date) {
|
|
114
|
-
return options.dateParser?.(value) || value.toISOString();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (typeof value === "object" && !Array.isArray(value)) {
|
|
118
|
-
return options.objectParser?.(value) || JSON.stringify(value);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return String(value);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
return `${encodeValue(key, options)}=${encodeValue(parsedValue(), options)}`;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const encodeArray = (key: string, array: Array<QueryParamValuesType>, options: QueryStringifyOptionsType): string => {
|
|
128
|
-
const { arrayFormat, arraySeparator } = options;
|
|
129
|
-
|
|
130
|
-
return array
|
|
131
|
-
.filter(isValidValue(options))
|
|
132
|
-
.reduce<string[]>((acc, value, index) => {
|
|
133
|
-
switch (arrayFormat) {
|
|
134
|
-
case "index": {
|
|
135
|
-
const keyValue = `${encodeValue(key, options)}[${encodeValue(String(index), options)}]=`;
|
|
136
|
-
acc.push(`${keyValue}${encodeValue(String(value), options)}`);
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
case "bracket": {
|
|
140
|
-
const keyValue = `${encodeValue(key, options)}[]=`;
|
|
141
|
-
acc.push(`${keyValue}${encodeValue(String(value), options)}`);
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case "comma": {
|
|
145
|
-
const keyValue = (!acc.length && `${encodeValue(key, options)}=`) || "";
|
|
146
|
-
return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(",")];
|
|
147
|
-
}
|
|
148
|
-
case "separator": {
|
|
149
|
-
const keyValue = (!acc.length && `${encodeValue(key, options)}=`) || "";
|
|
150
|
-
return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(arraySeparator || "|")];
|
|
151
|
-
}
|
|
152
|
-
case "bracket-separator": {
|
|
153
|
-
const keyValue = (!acc.length && `${encodeValue(key, options)}[]=`) || "";
|
|
154
|
-
return [[...acc, `${keyValue}${encodeValue(String(value), options)}`].join(arraySeparator || "|")];
|
|
155
|
-
}
|
|
156
|
-
default: {
|
|
157
|
-
const keyValue = `${encodeValue(key, options)}=`;
|
|
158
|
-
acc.push(`${keyValue}${encodeValue(String(value), options)}`);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return acc;
|
|
163
|
-
}, [])
|
|
164
|
-
.join("&");
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
export const stringifyQueryParams = (
|
|
168
|
-
queryParams: QueryParamsType | string | NegativeTypes,
|
|
169
|
-
options: QueryStringifyOptionsType = stringifyDefaultOptions,
|
|
170
|
-
): string => {
|
|
171
|
-
if (!queryParams || !Object.keys(queryParams).length) {
|
|
172
|
-
return "";
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (typeof queryParams === "string") {
|
|
176
|
-
const hasQuestionMark = queryParams[0] === "?";
|
|
177
|
-
return hasQuestionMark ? queryParams : `?${queryParams}`;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const stringified = Object.entries(queryParams)
|
|
181
|
-
.map(([key, value]): string => {
|
|
182
|
-
if (Array.isArray(value)) {
|
|
183
|
-
return encodeArray(key, value, options);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return encodeParams(key, value, options);
|
|
187
|
-
})
|
|
188
|
-
.filter(Boolean)
|
|
189
|
-
.join("&");
|
|
190
|
-
|
|
191
|
-
if (stringified) {
|
|
192
|
-
return `?${stringified}`;
|
|
193
|
-
}
|
|
194
|
-
return "";
|
|
195
|
-
};
|
package/src/client/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export enum
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export enum HttpMethods {
|
|
2
|
+
GET = "GET",
|
|
3
|
+
POST = "POST",
|
|
4
|
+
PUT = "PUT",
|
|
5
|
+
PATCH = "PATCH",
|
|
6
|
+
DELETE = "DELETE",
|
|
7
7
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export enum
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
export enum Time {
|
|
2
|
+
SEC = 1e3,
|
|
3
|
+
MIN = 6e4,
|
|
4
|
+
HOUR = 3.6e6,
|
|
5
|
+
DAY = 8.64e7,
|
|
6
|
+
WEEK = 6.048e8,
|
|
7
|
+
MONTH_30 = 2.592e9,
|
|
8
|
+
MONTH_31 = 2.6784e9,
|
|
9
|
+
YEAR = 3.1536e10,
|
|
10
|
+
YEAR_LEAP = 3.16224e10,
|
|
11
11
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export enum
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export enum DispatcherMode {
|
|
2
|
+
ONE_BY_ONE = "one-by-one",
|
|
3
|
+
ALL_AT_ONCE = "all-at-once",
|
|
4
|
+
PREVIOUS_CANCELED = "previous-canceled",
|
|
5
|
+
DEDUPLICATED = "deduplicated",
|
|
6
6
|
}
|
|
@@ -2,41 +2,106 @@ import EventEmitter from "events";
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
QueueDataType,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
getDispatcherChangeKey,
|
|
6
|
+
getDispatcherChangeByKey,
|
|
7
|
+
getDispatcherStatusKey,
|
|
8
|
+
getDispatcherStatusByKey,
|
|
9
|
+
getDispatcherDrainedKey,
|
|
10
|
+
getDispatcherDrainedByKey,
|
|
8
11
|
} from "dispatcher";
|
|
9
12
|
import { RequestInstance } from "request";
|
|
10
13
|
|
|
11
14
|
export const getDispatcherEvents = (emitter: EventEmitter) => ({
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
emitDrained: <Request extends RequestInstance>(
|
|
16
|
+
values: QueueDataType<Request>,
|
|
17
|
+
isTriggeredExternally?: boolean,
|
|
18
|
+
): void => {
|
|
19
|
+
emitter.emit(getDispatcherDrainedKey(), values, isTriggeredExternally);
|
|
20
|
+
emitter.emit(getDispatcherDrainedByKey(values.queryKey), values, isTriggeredExternally);
|
|
14
21
|
},
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
emitQueueStatusChanged: <Request extends RequestInstance>(
|
|
23
|
+
values: QueueDataType<Request>,
|
|
24
|
+
isTriggeredExternally?: boolean,
|
|
25
|
+
): void => {
|
|
26
|
+
emitter.emit(getDispatcherStatusKey(), values, isTriggeredExternally);
|
|
27
|
+
emitter.emit(getDispatcherStatusByKey(values.queryKey), values, isTriggeredExternally);
|
|
17
28
|
},
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
emitQueueChanged: <Request extends RequestInstance>(
|
|
30
|
+
values: QueueDataType<Request>,
|
|
31
|
+
isTriggeredExternally?: boolean,
|
|
32
|
+
): void => {
|
|
33
|
+
emitter.emit(getDispatcherChangeKey(), values, isTriggeredExternally);
|
|
34
|
+
emitter.emit(getDispatcherChangeByKey(values.queryKey), values, isTriggeredExternally);
|
|
20
35
|
},
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
/**
|
|
37
|
+
* When queue becomes empty
|
|
38
|
+
* @param callback
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
onDrained: <Request extends RequestInstance>(callback: (values: QueueDataType<Request>) => void): VoidFunction => {
|
|
42
|
+
emitter.on(getDispatcherDrainedKey(), callback);
|
|
43
|
+
return () => emitter.removeListener(getDispatcherDrainedKey(), callback);
|
|
44
|
+
},
|
|
45
|
+
/**
|
|
46
|
+
* When queue becomes empty
|
|
47
|
+
* @param queryKey
|
|
48
|
+
* @param callback
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
onDrainedByKey: <Request extends RequestInstance>(
|
|
52
|
+
queryKey: string,
|
|
53
|
+
callback: (values: QueueDataType<Request>) => void,
|
|
54
|
+
): VoidFunction => {
|
|
55
|
+
emitter.on(getDispatcherDrainedByKey(queryKey), callback);
|
|
56
|
+
return () => emitter.removeListener(getDispatcherDrainedByKey(queryKey), callback);
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* When queue status change from enabled to paused or vice versa
|
|
60
|
+
* @param callback
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
onQueueStatusChange: <Request extends RequestInstance>(
|
|
23
64
|
callback: (values: QueueDataType<Request>) => void,
|
|
24
65
|
): VoidFunction => {
|
|
25
|
-
emitter.on(
|
|
26
|
-
return () => emitter.removeListener(
|
|
66
|
+
emitter.on(getDispatcherStatusKey(), callback);
|
|
67
|
+
return () => emitter.removeListener(getDispatcherStatusKey(), callback);
|
|
27
68
|
},
|
|
28
|
-
|
|
29
|
-
|
|
69
|
+
/**
|
|
70
|
+
* When queue status change from enabled to paused or vice versa
|
|
71
|
+
* @param queryKey
|
|
72
|
+
* @param callback
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
onQueueStatusChangeByKey: <Request extends RequestInstance>(
|
|
76
|
+
queryKey: string,
|
|
30
77
|
callback: (values: QueueDataType<Request>) => void,
|
|
31
78
|
): VoidFunction => {
|
|
32
|
-
emitter.on(
|
|
33
|
-
return () => emitter.removeListener(
|
|
79
|
+
emitter.on(getDispatcherStatusByKey(queryKey), callback);
|
|
80
|
+
return () => emitter.removeListener(getDispatcherStatusByKey(queryKey), callback);
|
|
34
81
|
},
|
|
82
|
+
/**
|
|
83
|
+
* When new elements are added or removed from the queue
|
|
84
|
+
* @param queryKey
|
|
85
|
+
* @param callback
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
35
88
|
onQueueChange: <Request extends RequestInstance>(
|
|
36
|
-
queueKey: string,
|
|
37
89
|
callback: (values: QueueDataType<Request>) => void,
|
|
38
90
|
): VoidFunction => {
|
|
39
|
-
emitter.on(
|
|
40
|
-
return () => emitter.removeListener(
|
|
91
|
+
emitter.on(getDispatcherChangeKey(), callback);
|
|
92
|
+
return () => emitter.removeListener(getDispatcherChangeKey(), callback);
|
|
93
|
+
},
|
|
94
|
+
/**
|
|
95
|
+
* When new elements are added or removed from the queue
|
|
96
|
+
* @param queryKey
|
|
97
|
+
* @param callback
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
onQueueChangeByKey: <Request extends RequestInstance>(
|
|
101
|
+
queryKey: string,
|
|
102
|
+
callback: (values: QueueDataType<Request>) => void,
|
|
103
|
+
): VoidFunction => {
|
|
104
|
+
emitter.on(getDispatcherChangeByKey(queryKey), callback);
|
|
105
|
+
return () => emitter.removeListener(getDispatcherChangeByKey(queryKey), callback);
|
|
41
106
|
},
|
|
42
107
|
});
|