@hyper-fetch/react 6.0.1 → 7.0.1
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/index.d.ts +167 -166
- package/dist/{index.esm.js → index.js} +462 -431
- package/dist/index.js.map +7 -0
- package/package.json +12 -13
- package/src/helpers/use-request-events/use-request-events.hooks.ts +79 -80
- package/src/helpers/use-request-events/use-request-events.types.ts +24 -22
- package/src/helpers/use-socket-state/use-socket-state.constants.ts +4 -1
- package/src/helpers/use-socket-state/use-socket-state.hooks.ts +39 -29
- package/src/helpers/use-socket-state/use-socket-state.types.ts +4 -1
- package/src/helpers/use-tracked-state/use-tracked-state.constants.ts +4 -3
- package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +82 -115
- package/src/helpers/use-tracked-state/use-tracked-state.types.ts +42 -25
- package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +45 -41
- package/src/hooks/use-app-manager/use-app-manager.hooks.ts +2 -2
- package/src/hooks/use-cache/use-cache.constants.ts +1 -1
- package/src/hooks/use-cache/use-cache.hooks.ts +32 -27
- package/src/hooks/use-cache/use-cache.types.ts +4 -22
- package/src/hooks/use-emitter/use-emitter.hooks.ts +50 -18
- package/src/hooks/use-fetch/use-fetch.constants.ts +6 -5
- package/src/hooks/use-fetch/use-fetch.hooks.ts +71 -79
- package/src/hooks/use-fetch/use-fetch.types.ts +28 -9
- package/src/hooks/use-listener/use-listener.hooks.ts +15 -21
- package/src/hooks/use-queue/use-queue.constants.ts +2 -1
- package/src/hooks/use-queue/use-queue.hooks.ts +123 -42
- package/src/hooks/use-queue/use-queue.types.ts +14 -5
- package/src/hooks/use-submit/use-submit.constants.ts +3 -3
- package/src/hooks/use-submit/use-submit.hooks.ts +39 -53
- package/src/hooks/use-submit/use-submit.types.ts +5 -6
- package/src/index.ts +1 -3
- package/src/provider/index.ts +2 -0
- package/src/{config-provider/config-provider.tsx → provider/provider.tsx} +8 -5
- package/src/{config-provider/config-provider.types.ts → provider/provider.types.ts} +15 -8
- package/src/utils/deep-equal.utils.ts +1 -3
- package/tsconfig.json +2 -2
- package/dist/index.cjs.js +0 -1550
- package/dist/index.cjs.js.map +0 -7
- package/dist/index.esm.js.map +0 -7
- package/src/config-provider/index.ts +0 -2
- package/src/hooks/use-event-messages/index.ts +0 -2
- package/src/hooks/use-event-messages/use-event-messages.hooks.ts +0 -69
- package/src/hooks/use-event-messages/use-event-messages.types.ts +0 -4
- package/src/types/index.ts +0 -1
- package/src/types/invalidation.types.ts +0 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import * as
|
|
4
|
-
import { SocketInstance, ListenerInstance, ExtractListenerResponseType, ExtractSocketExtraType, ExtractListenerAdapterType, EmitterInstance } from '@hyper-fetch/sockets';
|
|
1
|
+
import { RequestInstance, RequestResponseEventType, ResponseSuccessType, ExtractResponseType, ExtractAdapterType, ResponseErrorType, ExtractErrorType, ResponseType, RequestEventType, RequestProgressEventType, Dispatcher, LoggerMethods, CacheValueType, ExtractAdapterStatusType, ExtractAdapterExtraType, CacheSetState, NullableType, ExtractAdapterResolvedType, ResponseDetailsType, ExtendRequest, RequestSendOptionsType, EmptyTypes, RequiredKeys, RequestSendType, QueueItemType, ProgressType, ClientInstance } from '@hyper-fetch/core';
|
|
2
|
+
import { SocketInstance, ExtractSocketExtraType, ListenerInstance, ExtractListenerResponseType, EmitterInstance, EmitterCallbackErrorType, EmitType } from '@hyper-fetch/sockets';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
4
|
import React from 'react';
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -10,7 +9,7 @@ import React from 'react';
|
|
|
10
9
|
* @param options Hook options
|
|
11
10
|
* @returns
|
|
12
11
|
*/
|
|
13
|
-
declare const useFetch: <
|
|
12
|
+
declare const useFetch: <R extends RequestInstance>(request: R extends UseFetchRequest<R> ? R : UseFetchRequest<R>, options?: UseFetchOptionsType<R>) => UseFetchReturnType<R>;
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* This is helper hook that handles main Hyper-Fetch event/data flow
|
|
@@ -18,7 +17,7 @@ declare const useFetch: <RequestType extends RequestInstance>(request: RequestTy
|
|
|
18
17
|
* @param options
|
|
19
18
|
* @returns
|
|
20
19
|
*/
|
|
21
|
-
declare const useRequestEvents: <
|
|
20
|
+
declare const useRequestEvents: <R extends RequestInstance>({ request, dispatcher, logger, actions, setCacheData, getIsDataProcessing, }: UseRequestEventsPropsType<R>) => UseRequestEventsReturnType<R>;
|
|
22
21
|
|
|
23
22
|
type UseRequestEventsDataMap = {
|
|
24
23
|
unmount: VoidFunction;
|
|
@@ -28,15 +27,15 @@ type UseRequestEventsLifecycleMap = Map<string, {
|
|
|
28
27
|
}>;
|
|
29
28
|
type UseRequestEventsPropsType<T extends RequestInstance> = {
|
|
30
29
|
request: T;
|
|
31
|
-
dispatcher: Dispatcher
|
|
32
|
-
logger:
|
|
30
|
+
dispatcher: Dispatcher<ExtractAdapterType<T>>;
|
|
31
|
+
logger: LoggerMethods;
|
|
33
32
|
actions: UseTrackedStateActions<T>;
|
|
34
33
|
setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
|
|
35
34
|
getIsDataProcessing: (cacheKey: string) => boolean;
|
|
36
35
|
};
|
|
37
36
|
type UseRequestEventsActionsType<T extends RequestInstance> = {
|
|
38
37
|
/**
|
|
39
|
-
* Callback that allows canceling ongoing requests from the given
|
|
38
|
+
* Callback that allows canceling ongoing requests from the given queryKey.
|
|
40
39
|
*/
|
|
41
40
|
abort: () => void;
|
|
42
41
|
/**
|
|
@@ -79,26 +78,21 @@ type UseRequestEventsActionsType<T extends RequestInstance> = {
|
|
|
79
78
|
type UseRequestEventsReturnType<T extends RequestInstance> = [
|
|
80
79
|
UseRequestEventsActionsType<T>,
|
|
81
80
|
{
|
|
82
|
-
addCacheDataListener: (request:
|
|
81
|
+
addCacheDataListener: (request: T) => VoidFunction;
|
|
83
82
|
clearCacheDataListener: VoidFunction;
|
|
84
|
-
addLifecycleListeners: (request:
|
|
83
|
+
addLifecycleListeners: (request: T, requestId?: string) => VoidFunction;
|
|
85
84
|
removeLifecycleListener: (requestId: string) => void;
|
|
86
85
|
clearLifecycleListeners: () => void;
|
|
87
86
|
}
|
|
88
87
|
];
|
|
89
|
-
type CallbackParameters<Request, ResponseType> = {
|
|
88
|
+
type CallbackParameters<Request extends RequestInstance, ResponseType> = {
|
|
90
89
|
response: ResponseType;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
type
|
|
95
|
-
type
|
|
96
|
-
type
|
|
97
|
-
type OnStartCallbackType<Request extends RequestInstance> = (params: {
|
|
98
|
-
details: RequestEventType<Request>;
|
|
99
|
-
request: Request;
|
|
100
|
-
}) => void | Promise<void>;
|
|
101
|
-
type OnProgressCallbackType = <Request extends RequestInstance>(progress: ProgressType, details: RequestEventType<Request>) => void | Promise<void>;
|
|
90
|
+
} & Omit<RequestResponseEventType<Request>, "response">;
|
|
91
|
+
type OnSuccessCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ResponseSuccessType<ExtractResponseType<Request>, ExtractAdapterType<Request>>>) => void | Promise<void>;
|
|
92
|
+
type OnErrorCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ResponseErrorType<ExtractErrorType<Request>, ExtractAdapterType<Request>>>) => void | Promise<void>;
|
|
93
|
+
type OnFinishedCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>>>) => void | Promise<void>;
|
|
94
|
+
type OnStartCallbackType<Request extends RequestInstance> = (data: RequestEventType<Request>) => void | Promise<void>;
|
|
95
|
+
type OnProgressCallbackType = <Request extends RequestInstance>(data: RequestProgressEventType<Request>) => void | Promise<void>;
|
|
102
96
|
|
|
103
97
|
/**
|
|
104
98
|
* Check if value is empty
|
|
@@ -124,11 +118,10 @@ declare const getBounceData: (bounceData: {
|
|
|
124
118
|
|
|
125
119
|
type UseTrackedStateProps<T extends RequestInstance> = {
|
|
126
120
|
request: T;
|
|
127
|
-
logger:
|
|
128
|
-
|
|
129
|
-
dispatcher: Dispatcher
|
|
121
|
+
logger: LoggerMethods;
|
|
122
|
+
initialResponse: NullableType<Partial<ExtractAdapterResolvedType<T>>>;
|
|
123
|
+
dispatcher: Dispatcher<ExtractAdapterType<T>>;
|
|
130
124
|
dependencyTracking: boolean;
|
|
131
|
-
defaultCacheEmitting?: boolean;
|
|
132
125
|
deepCompare: boolean | typeof isEqual;
|
|
133
126
|
disabled?: boolean;
|
|
134
127
|
revalidate?: boolean;
|
|
@@ -159,11 +152,11 @@ type UseTrackedStateType<T extends RequestInstance = RequestInstance> = {
|
|
|
159
152
|
/**
|
|
160
153
|
* Request status
|
|
161
154
|
*/
|
|
162
|
-
status: ExtractAdapterStatusType<ExtractAdapterType<T
|
|
155
|
+
status: null | ExtractAdapterStatusType<ExtractAdapterType<T>> | null;
|
|
163
156
|
/**
|
|
164
157
|
* Request additional response data
|
|
165
158
|
*/
|
|
166
|
-
extra: ExtractAdapterExtraType<ExtractAdapterType<T>>;
|
|
159
|
+
extra: null | ExtractAdapterExtraType<ExtractAdapterType<T>>;
|
|
167
160
|
/**
|
|
168
161
|
* Information whether request succeeded
|
|
169
162
|
*/
|
|
@@ -175,41 +168,58 @@ type UseTrackedStateType<T extends RequestInstance = RequestInstance> = {
|
|
|
175
168
|
/**
|
|
176
169
|
* Request response timestamp
|
|
177
170
|
*/
|
|
178
|
-
|
|
171
|
+
responseTimestamp: null | Date;
|
|
172
|
+
/**
|
|
173
|
+
* Request response timestamp
|
|
174
|
+
*/
|
|
175
|
+
requestTimestamp: null | Date;
|
|
179
176
|
};
|
|
180
177
|
type UseTrackedStateActions<T extends RequestInstance> = {
|
|
181
178
|
/**
|
|
182
|
-
* Action to set custom data. We can do it locally(inside hook state)
|
|
179
|
+
* Action to set custom data. We can do it locally(inside hook state).
|
|
180
|
+
* If you need to update cache data use client.cache.update(). method.
|
|
183
181
|
*/
|
|
184
|
-
setData: (data: ExtractResponseType<T
|
|
182
|
+
setData: (data: CacheSetState<ExtractResponseType<T> | null>) => void;
|
|
185
183
|
/**
|
|
186
|
-
* Action to set custom error. We can do it locally(inside hook state)
|
|
184
|
+
* Action to set custom error. We can do it locally(inside hook state).
|
|
185
|
+
* If you need to update cache data use client.cache.update() method.
|
|
187
186
|
*/
|
|
188
|
-
setError: (error: ExtractErrorType<T
|
|
187
|
+
setError: (error: CacheSetState<ExtractErrorType<T> | null>) => void;
|
|
189
188
|
/**
|
|
190
|
-
* Action to set custom loading. We can do it locally(inside hook state)
|
|
189
|
+
* Action to set custom loading. We can do it locally(inside hook state).
|
|
190
|
+
* If you need to update cache data use client.cache.update() method.
|
|
191
191
|
*/
|
|
192
|
-
setLoading: (loading: boolean
|
|
192
|
+
setLoading: (loading: CacheSetState<boolean>) => void;
|
|
193
193
|
/**
|
|
194
|
-
* Action to set custom status. We can do it locally(inside hook state)
|
|
194
|
+
* Action to set custom status. We can do it locally(inside hook state).
|
|
195
|
+
* If you need to turn on loading for all listening hooks use client.requestManager.events.emitLoading() method.
|
|
195
196
|
*/
|
|
196
|
-
setStatus: (status: ExtractAdapterStatusType<ExtractAdapterType<T
|
|
197
|
+
setStatus: (status: CacheSetState<ExtractAdapterStatusType<ExtractAdapterType<T>>>) => void;
|
|
197
198
|
/**
|
|
198
|
-
* Action to set custom success. We can do it locally(inside hook state)
|
|
199
|
+
* Action to set custom success. We can do it locally(inside hook state).
|
|
200
|
+
* If you need to update cache data use client.cache.update() method.
|
|
199
201
|
*/
|
|
200
|
-
setSuccess: (success: boolean
|
|
202
|
+
setSuccess: (success: CacheSetState<boolean>) => void;
|
|
201
203
|
/**
|
|
202
|
-
* Action to set custom additional data. We can do it locally(inside hook state)
|
|
204
|
+
* Action to set custom additional data. We can do it locally(inside hook state).
|
|
205
|
+
* If you need to update cache data use client.cache.update() method.
|
|
203
206
|
*/
|
|
204
|
-
setExtra: (extra: ExtractAdapterExtraType<ExtractAdapterType<T
|
|
207
|
+
setExtra: (extra: CacheSetState<ExtractAdapterExtraType<ExtractAdapterType<T>> | null>) => void;
|
|
205
208
|
/**
|
|
206
|
-
* Action to set custom retries count. We can do it locally(inside hook state)
|
|
209
|
+
* Action to set custom retries count. We can do it locally(inside hook state).
|
|
210
|
+
* If you need to update cache data use client.cache.update() method.
|
|
207
211
|
*/
|
|
208
|
-
setRetries: (retries: number
|
|
212
|
+
setRetries: (retries: CacheSetState<number>) => void;
|
|
209
213
|
/**
|
|
210
|
-
* Action to set custom timestamp. We can do it locally(inside hook state)
|
|
214
|
+
* Action to set custom timestamp. We can do it locally(inside hook state).
|
|
215
|
+
* If you need to update cache data use client.cache.update() method.
|
|
211
216
|
*/
|
|
212
|
-
|
|
217
|
+
setResponseTimestamp: (timestamp: CacheSetState<Date>) => void;
|
|
218
|
+
/**
|
|
219
|
+
* Action to set custom timestamp. We can do it locally(inside hook state).
|
|
220
|
+
* If you need to update cache data use client.cache.update() method.
|
|
221
|
+
*/
|
|
222
|
+
setRequestTimestamp: (timestamp: CacheSetState<Date>) => void;
|
|
213
223
|
};
|
|
214
224
|
|
|
215
225
|
declare const initialState: UseTrackedStateType;
|
|
@@ -217,56 +227,56 @@ declare const initialState: UseTrackedStateType;
|
|
|
217
227
|
/**
|
|
218
228
|
*
|
|
219
229
|
* @param request
|
|
220
|
-
* @param
|
|
230
|
+
* @param initialResponse
|
|
221
231
|
* @param dispatcher
|
|
222
232
|
* @param dependencies
|
|
223
233
|
* @internal
|
|
224
234
|
*/
|
|
225
|
-
declare const useTrackedState: <T extends RequestInstance>({ request, dispatcher,
|
|
235
|
+
declare const useTrackedState: <T extends RequestInstance>({ request, dispatcher, initialResponse, deepCompare, dependencyTracking, disabled, revalidate, }: UseTrackedStateProps<T>) => UseTrackedStateReturn<T>;
|
|
226
236
|
|
|
227
237
|
declare const getDetailsState: (state?: UseTrackedStateType<RequestInstance>, details?: Partial<ResponseDetailsType>) => ResponseDetailsType;
|
|
228
|
-
declare const isStaleCacheData: (
|
|
229
|
-
declare const getValidCacheData: <T extends RequestInstance>(request: T,
|
|
230
|
-
declare const getTimestamp: (timestamp?: NullableType<number | Date>) => Date;
|
|
231
|
-
declare const getIsInitiallyLoading: ({ queryKey, dispatcher, hasState, revalidate, disabled, }: {
|
|
238
|
+
declare const isStaleCacheData: (staleTime: number, staleTimestamp: NullableType<Date | number>) => boolean;
|
|
239
|
+
declare const getValidCacheData: <T extends RequestInstance>(request: T, initialResponse: NullableType<Partial<ExtractAdapterResolvedType<T>>>, cacheData: NullableType<CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>>) => CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>> | null;
|
|
240
|
+
declare const getTimestamp: (timestamp?: NullableType<number | Date>) => Date | null;
|
|
241
|
+
declare const getIsInitiallyLoading: <T extends RequestInstance>({ queryKey, dispatcher, hasState, revalidate, disabled, }: {
|
|
232
242
|
queryKey: string;
|
|
233
|
-
dispatcher: Dispatcher
|
|
243
|
+
dispatcher: Dispatcher<ExtractAdapterType<T>>;
|
|
234
244
|
hasState: boolean;
|
|
235
245
|
revalidate?: boolean;
|
|
236
246
|
disabled?: boolean;
|
|
237
247
|
}) => boolean;
|
|
238
248
|
declare const getInitialState: <T extends RequestInstance>({ initialResponse, dispatcher, request, disabled, revalidate, }: {
|
|
239
|
-
initialResponse: Partial<
|
|
240
|
-
dispatcher: Dispatcher
|
|
249
|
+
initialResponse: NullableType<Partial<ExtractAdapterResolvedType<T>>>;
|
|
250
|
+
dispatcher: Dispatcher<ExtractAdapterType<T>>;
|
|
241
251
|
request: T;
|
|
242
|
-
/**
|
|
243
|
-
* useFetch only
|
|
244
|
-
*/
|
|
245
252
|
disabled?: boolean;
|
|
246
|
-
/**
|
|
247
|
-
* useFetch only
|
|
248
|
-
*/
|
|
249
253
|
revalidate?: boolean;
|
|
250
254
|
}) => UseTrackedStateType<T>;
|
|
251
255
|
|
|
252
|
-
declare const useSocketState: <DataType>(socket:
|
|
253
|
-
setData: (data: DataType) => void;
|
|
256
|
+
declare const useSocketState: <DataType, Socket extends SocketInstance>(socket: Socket, { dependencyTracking }: UseSocketStateProps) => readonly [UseSocketStateType<Socket, DataType>, {
|
|
257
|
+
setData: (data: DataType | null) => void;
|
|
258
|
+
setExtra: (extra: ExtractSocketExtraType<Socket> | null) => void;
|
|
254
259
|
setConnected: (connected: boolean) => void;
|
|
255
260
|
setConnecting: (connecting: boolean) => void;
|
|
256
261
|
setTimestamp: (timestamp: number | null) => void;
|
|
257
262
|
}, {
|
|
258
|
-
|
|
259
|
-
|
|
263
|
+
onConnected: (callback: VoidFunction) => void;
|
|
264
|
+
onDisconnected: (callback: VoidFunction) => void;
|
|
260
265
|
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
261
266
|
onConnecting: (callback: VoidFunction) => void;
|
|
262
|
-
onReconnecting: (callback: (
|
|
263
|
-
|
|
267
|
+
onReconnecting: (callback: (data: {
|
|
268
|
+
attempts: number;
|
|
269
|
+
}) => void) => void;
|
|
270
|
+
onReconnectingFailed: (callback: (data: {
|
|
271
|
+
attempts: number;
|
|
272
|
+
}) => void) => void;
|
|
264
273
|
}, {
|
|
265
|
-
readonly setRenderKey: (renderKey: keyof UseSocketStateType<DataType>) => void;
|
|
274
|
+
readonly setRenderKey: (renderKey: keyof UseSocketStateType<Socket, DataType>) => void;
|
|
266
275
|
}];
|
|
267
276
|
|
|
268
|
-
type UseSocketStateType<DataType = any> = {
|
|
277
|
+
type UseSocketStateType<Socket extends SocketInstance, DataType = any> = {
|
|
269
278
|
data: DataType | null;
|
|
279
|
+
extra: ExtractSocketExtraType<Socket> | null;
|
|
270
280
|
connected: boolean;
|
|
271
281
|
connecting: boolean;
|
|
272
282
|
timestamp: number | null;
|
|
@@ -275,11 +285,14 @@ type UseSocketStateProps = {
|
|
|
275
285
|
dependencyTracking?: boolean;
|
|
276
286
|
};
|
|
277
287
|
|
|
278
|
-
declare const initialSocketState: UseSocketStateType
|
|
279
|
-
|
|
280
|
-
type InvalidationKeyType = string | RequestInstance | RegExp;
|
|
288
|
+
declare const initialSocketState: UseSocketStateType<SocketInstance>;
|
|
281
289
|
|
|
282
|
-
type
|
|
290
|
+
type UseFetchRequest<R extends RequestInstance> = ExtendRequest<R, {
|
|
291
|
+
hasData: RequestSendOptionsType<R>["payload"] extends EmptyTypes ? true : false;
|
|
292
|
+
hasParams: RequestSendOptionsType<R>["params"] extends EmptyTypes ? true : false;
|
|
293
|
+
hasQuery: RequestSendOptionsType<R>["queryParams"] extends EmptyTypes ? true : false;
|
|
294
|
+
}>;
|
|
295
|
+
type UseFetchOptionsType<R extends RequestInstance> = {
|
|
283
296
|
/**
|
|
284
297
|
* Refetch dependencies
|
|
285
298
|
*/
|
|
@@ -299,7 +312,7 @@ type UseFetchOptionsType<T extends RequestInstance> = {
|
|
|
299
312
|
/**
|
|
300
313
|
* If cache is empty we can use placeholder data.
|
|
301
314
|
*/
|
|
302
|
-
|
|
315
|
+
initialResponse?: NullableType<Partial<ExtractAdapterResolvedType<UseFetchRequest<R>>>>;
|
|
303
316
|
/**
|
|
304
317
|
* Enable/disable refresh data
|
|
305
318
|
*/
|
|
@@ -341,6 +354,10 @@ type UseFetchOptionsType<T extends RequestInstance> = {
|
|
|
341
354
|
* How long it should bounce requests.
|
|
342
355
|
*/
|
|
343
356
|
bounceTime?: number;
|
|
357
|
+
/**
|
|
358
|
+
* Not applicable for debounce mode
|
|
359
|
+
*/
|
|
360
|
+
bounceTimeout?: void;
|
|
344
361
|
} | {
|
|
345
362
|
/**
|
|
346
363
|
* Possibility to choose between debounce and throttle approaches
|
|
@@ -355,7 +372,7 @@ type UseFetchOptionsType<T extends RequestInstance> = {
|
|
|
355
372
|
*/
|
|
356
373
|
bounceTimeout?: number;
|
|
357
374
|
});
|
|
358
|
-
type UseFetchReturnType<
|
|
375
|
+
type UseFetchReturnType<R extends RequestInstance> = UseTrackedStateType<UseFetchRequest<R>> & UseTrackedStateActions<UseFetchRequest<R>> & UseRequestEventsActionsType<UseFetchRequest<R>> & {
|
|
359
376
|
/**
|
|
360
377
|
* Data related to current state of the bounce usage
|
|
361
378
|
*/
|
|
@@ -370,15 +387,15 @@ type UseFetchReturnType<T extends RequestInstance> = UseTrackedStateType<T> & Us
|
|
|
370
387
|
reset: () => void;
|
|
371
388
|
};
|
|
372
389
|
/**
|
|
373
|
-
* Refetch current request
|
|
390
|
+
* Refetch current request
|
|
374
391
|
*/
|
|
375
|
-
refetch: (
|
|
392
|
+
refetch: () => void;
|
|
376
393
|
};
|
|
377
394
|
|
|
378
395
|
declare const getRefreshTime: (refreshTime: number, dataTimestamp?: Date) => number;
|
|
379
396
|
|
|
380
|
-
type DefaultOptionsType$1 = RequiredKeys<Omit<UseFetchOptionsType<RequestInstance>, "
|
|
381
|
-
|
|
397
|
+
type DefaultOptionsType$1 = RequiredKeys<Omit<UseFetchOptionsType<RequestInstance>, "initialResponse">> & {
|
|
398
|
+
initialResponse: null;
|
|
382
399
|
};
|
|
383
400
|
declare const useFetchDefaultOptions: DefaultOptionsType$1;
|
|
384
401
|
|
|
@@ -398,7 +415,7 @@ type UseSubmitOptionsType<T extends RequestInstance> = {
|
|
|
398
415
|
/**
|
|
399
416
|
* If cache is empty we can use placeholder data.
|
|
400
417
|
*/
|
|
401
|
-
|
|
418
|
+
initialResponse?: NullableType<Partial<ExtractAdapterResolvedType<T>>>;
|
|
402
419
|
/**
|
|
403
420
|
* Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.
|
|
404
421
|
*/
|
|
@@ -436,7 +453,7 @@ type UseSubmitOptionsType<T extends RequestInstance> = {
|
|
|
436
453
|
});
|
|
437
454
|
type UseSubmitReturnType<RequestType extends RequestInstance> = Omit<UseTrackedStateType<RequestType>, "loading"> & UseTrackedStateActions<RequestType> & {
|
|
438
455
|
/**
|
|
439
|
-
* Callback which allows to cancel ongoing requests from given
|
|
456
|
+
* Callback which allows to cancel ongoing requests from given queryKey.
|
|
440
457
|
*/
|
|
441
458
|
abort: () => void;
|
|
442
459
|
/**
|
|
@@ -497,13 +514,13 @@ type UseSubmitReturnType<RequestType extends RequestInstance> = Omit<UseTrackedS
|
|
|
497
514
|
reset: () => void;
|
|
498
515
|
};
|
|
499
516
|
/**
|
|
500
|
-
* Refetch current request
|
|
517
|
+
* Refetch current request
|
|
501
518
|
*/
|
|
502
|
-
refetch: (
|
|
519
|
+
refetch: () => void;
|
|
503
520
|
};
|
|
504
521
|
|
|
505
|
-
type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<RequestInstance>, "
|
|
506
|
-
|
|
522
|
+
type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<RequestInstance>, "initialResponse">> & {
|
|
523
|
+
initialResponse: null;
|
|
507
524
|
};
|
|
508
525
|
declare const useSubmitDefaultOptions: DefaultOptionsType;
|
|
509
526
|
|
|
@@ -513,20 +530,25 @@ declare const useSubmitDefaultOptions: DefaultOptionsType;
|
|
|
513
530
|
* @param options
|
|
514
531
|
* @returns
|
|
515
532
|
*/
|
|
516
|
-
declare const useQueue: <
|
|
533
|
+
declare const useQueue: <Request extends RequestInstance>(request: Request, options?: UseQueueOptionsType) => UseQueueReturnType<Request>;
|
|
517
534
|
|
|
518
535
|
type UseQueueOptionsType = {
|
|
519
|
-
|
|
536
|
+
dispatcherType?: "auto" | "fetch" | "submit";
|
|
537
|
+
keepFinishedRequests?: boolean;
|
|
520
538
|
};
|
|
521
|
-
type QueueRequest<Request extends RequestInstance> =
|
|
539
|
+
type QueueRequest<Request extends RequestInstance> = QueueItemType<Request> & {
|
|
540
|
+
failed?: boolean;
|
|
541
|
+
canceled?: boolean;
|
|
542
|
+
removed?: boolean;
|
|
543
|
+
success?: boolean;
|
|
522
544
|
/**
|
|
523
545
|
* Uploading progress for given request
|
|
524
546
|
*/
|
|
525
|
-
uploading
|
|
547
|
+
uploading: ProgressType;
|
|
526
548
|
/**
|
|
527
549
|
* Downloading progress for given request
|
|
528
550
|
*/
|
|
529
|
-
downloading
|
|
551
|
+
downloading: ProgressType;
|
|
530
552
|
/**
|
|
531
553
|
* Callback which allow to start previously stopped request.
|
|
532
554
|
*/
|
|
@@ -549,6 +571,10 @@ type UseQueueReturnType<T extends RequestInstance> = {
|
|
|
549
571
|
* List of requests for provided request
|
|
550
572
|
*/
|
|
551
573
|
requests: QueueRequest<T>[];
|
|
574
|
+
/**
|
|
575
|
+
* Request dispatcher instance
|
|
576
|
+
*/
|
|
577
|
+
dispatcher: Dispatcher<ExtractAdapterType<T>>;
|
|
552
578
|
/**
|
|
553
579
|
* Callback which allow to stop queue, it will cancel ongoing requests.
|
|
554
580
|
*/
|
|
@@ -569,7 +595,7 @@ declare const useCache: <T extends RequestInstance>(request: T, options?: UseCac
|
|
|
569
595
|
|
|
570
596
|
declare const useCacheDefaultOptions: {
|
|
571
597
|
dependencyTracking: boolean;
|
|
572
|
-
|
|
598
|
+
initialResponse: null;
|
|
573
599
|
deepCompare: boolean;
|
|
574
600
|
};
|
|
575
601
|
|
|
@@ -581,7 +607,7 @@ type UseCacheOptionsType<T extends RequestInstance> = {
|
|
|
581
607
|
/**
|
|
582
608
|
* If cache is empty we can use placeholder data.
|
|
583
609
|
*/
|
|
584
|
-
|
|
610
|
+
initialResponse?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
|
|
585
611
|
/**
|
|
586
612
|
* Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
|
|
587
613
|
*/
|
|
@@ -589,104 +615,71 @@ type UseCacheOptionsType<T extends RequestInstance> = {
|
|
|
589
615
|
};
|
|
590
616
|
type UseCacheReturnType<T extends RequestInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & {
|
|
591
617
|
/**
|
|
592
|
-
*
|
|
618
|
+
* Invalidate cache for the current request or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
|
|
593
619
|
*/
|
|
594
|
-
|
|
595
|
-
/**
|
|
596
|
-
* Helper hook listener for error response
|
|
597
|
-
*/
|
|
598
|
-
onCacheError: (callback: OnErrorCallbackType<T>) => void;
|
|
599
|
-
/**
|
|
600
|
-
* Helper hook listener for response
|
|
601
|
-
*/
|
|
602
|
-
onCacheChange: (callback: OnFinishedCallbackType<T>) => void;
|
|
603
|
-
/**
|
|
604
|
-
* Refetch current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
|
|
605
|
-
*/
|
|
606
|
-
refetch: (invalidateKey?: string | RegExp | RequestInstance) => void;
|
|
620
|
+
invalidate: (cacheKeys?: string | RegExp | RequestInstance | Array<string | RegExp | RequestInstance>) => void;
|
|
607
621
|
};
|
|
608
622
|
|
|
609
|
-
declare const useListener: <ListenerType extends ListenerInstance>(listener: ListenerType, options
|
|
623
|
+
declare const useListener: <ListenerType extends ListenerInstance>(listener: ListenerType, options?: UseListenerOptionsType) => {
|
|
610
624
|
listen: () => void;
|
|
611
|
-
onEvent: (callback: (response: {
|
|
625
|
+
onEvent: (callback: NonNullable<((response: {
|
|
612
626
|
data: ExtractListenerResponseType<ListenerType>;
|
|
613
|
-
extra:
|
|
614
|
-
}) => void) => void;
|
|
615
|
-
|
|
616
|
-
|
|
627
|
+
extra: Record<string, any>;
|
|
628
|
+
}) => void) | null>) => void;
|
|
629
|
+
onConnected: (callback: VoidFunction) => void;
|
|
630
|
+
onDisconnected: (callback: VoidFunction) => void;
|
|
617
631
|
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
618
632
|
onConnecting: (callback: VoidFunction) => void;
|
|
619
|
-
onReconnecting: (callback: (
|
|
620
|
-
|
|
633
|
+
onReconnecting: (callback: (data: {
|
|
634
|
+
attempts: number;
|
|
635
|
+
}) => void) => void;
|
|
636
|
+
onReconnectingFailed: (callback: (data: {
|
|
637
|
+
attempts: number;
|
|
638
|
+
}) => void) => void;
|
|
621
639
|
setData: (data: unknown) => void;
|
|
640
|
+
setExtra: (extra: any) => void;
|
|
622
641
|
setConnected: (connected: boolean) => void;
|
|
623
642
|
setConnecting: (connecting: boolean) => void;
|
|
624
|
-
setTimestamp: (timestamp: number) => void;
|
|
643
|
+
setTimestamp: (timestamp: number | null) => void;
|
|
625
644
|
data: unknown;
|
|
645
|
+
extra: any;
|
|
626
646
|
connected: boolean;
|
|
627
647
|
connecting: boolean;
|
|
628
|
-
timestamp: number;
|
|
648
|
+
timestamp: number | null;
|
|
629
649
|
};
|
|
630
650
|
|
|
631
651
|
type UseListenerOptionsType = {
|
|
632
652
|
dependencyTracking?: boolean;
|
|
633
653
|
};
|
|
634
654
|
|
|
635
|
-
declare const useEmitter: <EmitterType extends EmitterInstance>(emitter: EmitterType, options
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
655
|
+
declare const useEmitter: <EmitterType extends EmitterInstance>(emitter: EmitterType, options?: UseEmitterOptionsType) => {
|
|
656
|
+
onEmit: (callback: (emitter: EmitterType) => void) => void;
|
|
657
|
+
onEmitError: (callback: EmitterCallbackErrorType) => void;
|
|
658
|
+
emit: EmitType<EmitterType>;
|
|
659
|
+
onConnected: (callback: VoidFunction) => void;
|
|
660
|
+
onDisconnected: (callback: VoidFunction) => void;
|
|
641
661
|
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
642
662
|
onConnecting: (callback: VoidFunction) => void;
|
|
643
|
-
onReconnecting: (callback: (
|
|
644
|
-
|
|
663
|
+
onReconnecting: (callback: (data: {
|
|
664
|
+
attempts: number;
|
|
665
|
+
}) => void) => void;
|
|
666
|
+
onReconnectingFailed: (callback: (data: {
|
|
667
|
+
attempts: number;
|
|
668
|
+
}) => void) => void;
|
|
645
669
|
setData: (data: unknown) => void;
|
|
670
|
+
setExtra: (extra: any) => void;
|
|
646
671
|
setConnected: (connected: boolean) => void;
|
|
647
672
|
setConnecting: (connecting: boolean) => void;
|
|
648
|
-
setTimestamp: (timestamp: number) => void;
|
|
673
|
+
setTimestamp: (timestamp: number | null) => void;
|
|
649
674
|
connected: boolean;
|
|
650
675
|
connecting: boolean;
|
|
651
|
-
timestamp: number;
|
|
652
676
|
};
|
|
653
677
|
|
|
654
678
|
type UseEmitterOptionsType = {
|
|
655
679
|
dependencyTracking?: boolean;
|
|
656
680
|
};
|
|
657
681
|
|
|
658
|
-
|
|
659
|
-
* Allow to listen to all event messages received with sockets
|
|
660
|
-
* @param socket
|
|
661
|
-
* @param options
|
|
662
|
-
* @returns
|
|
663
|
-
*/
|
|
664
|
-
declare const useEventMessages: <ResponsesType extends {
|
|
665
|
-
endpoint: string;
|
|
666
|
-
}>(socket: SocketInstance, options: UseEventMessagesOptionsType<ResponsesType>) => {
|
|
667
|
-
onEvent: (callback: (data: ResponsesType, event: MessageEvent<ResponsesType>) => void) => void;
|
|
668
|
-
onOpen: (callback: VoidFunction) => void;
|
|
669
|
-
onClose: (callback: VoidFunction) => void;
|
|
670
|
-
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
671
|
-
onConnecting: (callback: VoidFunction) => void;
|
|
672
|
-
onReconnecting: (callback: (attempts: number) => void) => void;
|
|
673
|
-
onReconnectingStop: (callback: (attempts: number) => void) => void;
|
|
674
|
-
setData: (data: unknown) => void;
|
|
675
|
-
setConnected: (connected: boolean) => void;
|
|
676
|
-
setConnecting: (connecting: boolean) => void;
|
|
677
|
-
setTimestamp: (timestamp: number) => void;
|
|
678
|
-
data: unknown;
|
|
679
|
-
connected: boolean;
|
|
680
|
-
connecting: boolean;
|
|
681
|
-
timestamp: number;
|
|
682
|
-
};
|
|
683
|
-
|
|
684
|
-
type UseEventMessagesOptionsType<ResponsesType> = {
|
|
685
|
-
dependencyTracking?: boolean;
|
|
686
|
-
filter?: ((endpoint: string, data: ResponsesType) => boolean) | string[];
|
|
687
|
-
};
|
|
688
|
-
|
|
689
|
-
declare const useAppManager: <B extends ClientInstance>(client: B) => UseAppManagerReturnType;
|
|
682
|
+
declare const useAppManager: <Client extends ClientInstance>(client: Client) => UseAppManagerReturnType;
|
|
690
683
|
|
|
691
684
|
type UseAppManagerReturnType = {
|
|
692
685
|
/**
|
|
@@ -707,31 +700,39 @@ type UseAppManagerReturnType = {
|
|
|
707
700
|
setFocused: (isFocused: boolean) => void;
|
|
708
701
|
};
|
|
709
702
|
|
|
710
|
-
type
|
|
703
|
+
type ProviderOptionsType = {
|
|
711
704
|
useFetchConfig?: Partial<UseFetchOptionsType<RequestInstance>>;
|
|
712
705
|
useSubmitConfig?: Partial<UseSubmitOptionsType<RequestInstance>>;
|
|
713
706
|
useCacheConfig?: Partial<UseCacheOptionsType<RequestInstance>>;
|
|
714
707
|
useQueueConfig?: Partial<UseQueueOptionsType>;
|
|
715
708
|
useListener?: Partial<UseListenerOptionsType>;
|
|
716
709
|
useEmitter?: Partial<UseEmitterOptionsType>;
|
|
717
|
-
useEventMessages?: Partial<UseEventMessagesOptionsType<SocketResponses>>;
|
|
718
710
|
};
|
|
719
|
-
type
|
|
711
|
+
type ProviderProps = {
|
|
712
|
+
/**
|
|
713
|
+
* Children to render
|
|
714
|
+
*/
|
|
720
715
|
children: React.ReactNode;
|
|
721
|
-
|
|
716
|
+
/**
|
|
717
|
+
* Configuration to set for available hooks
|
|
718
|
+
*/
|
|
719
|
+
config?: ProviderOptionsType;
|
|
720
|
+
};
|
|
721
|
+
type ProviderValueType = {
|
|
722
|
+
config: ProviderOptionsType;
|
|
723
|
+
setConfig: (newConfig: ProviderOptionsType) => void;
|
|
722
724
|
};
|
|
723
|
-
type ConfigProviderValueType = [ConfigProviderOptionsType, (newConfig: ConfigProviderOptionsType) => void];
|
|
724
725
|
|
|
725
726
|
/**
|
|
726
727
|
* Context provider with configuration for hooks
|
|
727
728
|
* @param options
|
|
728
729
|
* @returns
|
|
729
730
|
*/
|
|
730
|
-
declare const
|
|
731
|
+
declare const Provider: ({ children, config }: ProviderProps) => react_jsx_runtime.JSX.Element;
|
|
731
732
|
/**
|
|
732
733
|
* Hook to allow reading current context config
|
|
733
734
|
* @returns
|
|
734
735
|
*/
|
|
735
|
-
declare const
|
|
736
|
+
declare const useProvider: () => ProviderValueType;
|
|
736
737
|
|
|
737
|
-
export { CallbackParameters,
|
|
738
|
+
export { type CallbackParameters, type OnErrorCallbackType, type OnFinishedCallbackType, type OnProgressCallbackType, type OnStartCallbackType, type OnSuccessCallbackType, Provider, type ProviderOptionsType, type ProviderProps, type ProviderValueType, type QueueRequest, type UseAppManagerReturnType, type UseCacheOptionsType, type UseCacheReturnType, type UseEmitterOptionsType, type UseFetchOptionsType, type UseFetchRequest, type UseFetchReturnType, type UseListenerOptionsType, type UseQueueOptionsType, type UseQueueReturnType, type UseRequestEventsActionsType, type UseRequestEventsDataMap, type UseRequestEventsLifecycleMap, type UseRequestEventsPropsType, type UseRequestEventsReturnType, type UseSocketStateProps, type UseSocketStateType, type UseSubmitOptionsType, type UseSubmitReturnType, type UseTrackedStateActions, type UseTrackedStateProps, type UseTrackedStateReturn, type UseTrackedStateType, getBounceData, getDetailsState, getInitialState, getIsInitiallyLoading, getRefreshTime, getTimestamp, getValidCacheData, initialSocketState, initialState, isEmpty, isEqual, isStaleCacheData, useAppManager, useCache, useCacheDefaultOptions, useEmitter, useFetch, useFetchDefaultOptions, useListener, useProvider, useQueue, useQueueDefaultOptions, useRequestEvents, useSocketState, useSubmit, useSubmitDefaultOptions, useTrackedState };
|