@hyper-fetch/react 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/index.d.ts +179 -157
- package/dist/{index.esm.js → index.js} +500 -435
- package/dist/index.js.map +7 -0
- package/package.json +12 -13
- package/src/helpers/use-request-events/use-request-events.hooks.ts +73 -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 +79 -98
- package/src/helpers/use-tracked-state/use-tracked-state.types.ts +44 -25
- package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +79 -34
- 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 -82
- 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 -1514
- 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,12 +118,13 @@ 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;
|
|
126
|
+
disabled?: boolean;
|
|
127
|
+
revalidate?: boolean;
|
|
133
128
|
};
|
|
134
129
|
type UseTrackedStateReturn<T extends RequestInstance> = [
|
|
135
130
|
UseTrackedStateType<T>,
|
|
@@ -157,11 +152,11 @@ type UseTrackedStateType<T extends RequestInstance = RequestInstance> = {
|
|
|
157
152
|
/**
|
|
158
153
|
* Request status
|
|
159
154
|
*/
|
|
160
|
-
status: ExtractAdapterStatusType<ExtractAdapterType<T
|
|
155
|
+
status: null | ExtractAdapterStatusType<ExtractAdapterType<T>> | null;
|
|
161
156
|
/**
|
|
162
157
|
* Request additional response data
|
|
163
158
|
*/
|
|
164
|
-
extra: ExtractAdapterExtraType<ExtractAdapterType<T>>;
|
|
159
|
+
extra: null | ExtractAdapterExtraType<ExtractAdapterType<T>>;
|
|
165
160
|
/**
|
|
166
161
|
* Information whether request succeeded
|
|
167
162
|
*/
|
|
@@ -173,41 +168,58 @@ type UseTrackedStateType<T extends RequestInstance = RequestInstance> = {
|
|
|
173
168
|
/**
|
|
174
169
|
* Request response timestamp
|
|
175
170
|
*/
|
|
176
|
-
|
|
171
|
+
responseTimestamp: null | Date;
|
|
172
|
+
/**
|
|
173
|
+
* Request response timestamp
|
|
174
|
+
*/
|
|
175
|
+
requestTimestamp: null | Date;
|
|
177
176
|
};
|
|
178
177
|
type UseTrackedStateActions<T extends RequestInstance> = {
|
|
179
178
|
/**
|
|
180
|
-
* 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.
|
|
181
|
+
*/
|
|
182
|
+
setData: (data: CacheSetState<ExtractResponseType<T> | null>) => void;
|
|
183
|
+
/**
|
|
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.
|
|
181
186
|
*/
|
|
182
|
-
|
|
187
|
+
setError: (error: CacheSetState<ExtractErrorType<T> | null>) => void;
|
|
183
188
|
/**
|
|
184
|
-
* Action to set custom
|
|
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.
|
|
185
191
|
*/
|
|
186
|
-
|
|
192
|
+
setLoading: (loading: CacheSetState<boolean>) => void;
|
|
187
193
|
/**
|
|
188
|
-
* Action to set custom
|
|
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.
|
|
189
196
|
*/
|
|
190
|
-
|
|
197
|
+
setStatus: (status: CacheSetState<ExtractAdapterStatusType<ExtractAdapterType<T>>>) => void;
|
|
191
198
|
/**
|
|
192
|
-
* Action to set custom
|
|
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.
|
|
193
201
|
*/
|
|
194
|
-
|
|
202
|
+
setSuccess: (success: CacheSetState<boolean>) => void;
|
|
195
203
|
/**
|
|
196
|
-
* Action to set custom
|
|
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.
|
|
197
206
|
*/
|
|
198
|
-
|
|
207
|
+
setExtra: (extra: CacheSetState<ExtractAdapterExtraType<ExtractAdapterType<T>> | null>) => void;
|
|
199
208
|
/**
|
|
200
|
-
* Action to set custom
|
|
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.
|
|
201
211
|
*/
|
|
202
|
-
|
|
212
|
+
setRetries: (retries: CacheSetState<number>) => void;
|
|
203
213
|
/**
|
|
204
|
-
* Action to set custom
|
|
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.
|
|
205
216
|
*/
|
|
206
|
-
|
|
217
|
+
setResponseTimestamp: (timestamp: CacheSetState<Date>) => void;
|
|
207
218
|
/**
|
|
208
|
-
* Action to set custom timestamp. We can do it locally(inside hook state)
|
|
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.
|
|
209
221
|
*/
|
|
210
|
-
|
|
222
|
+
setRequestTimestamp: (timestamp: CacheSetState<Date>) => void;
|
|
211
223
|
};
|
|
212
224
|
|
|
213
225
|
declare const initialState: UseTrackedStateType;
|
|
@@ -215,37 +227,56 @@ declare const initialState: UseTrackedStateType;
|
|
|
215
227
|
/**
|
|
216
228
|
*
|
|
217
229
|
* @param request
|
|
218
|
-
* @param
|
|
230
|
+
* @param initialResponse
|
|
219
231
|
* @param dispatcher
|
|
220
232
|
* @param dependencies
|
|
221
233
|
* @internal
|
|
222
234
|
*/
|
|
223
|
-
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>;
|
|
224
236
|
|
|
225
237
|
declare const getDetailsState: (state?: UseTrackedStateType<RequestInstance>, details?: Partial<ResponseDetailsType>) => ResponseDetailsType;
|
|
226
|
-
declare const isStaleCacheData: (
|
|
227
|
-
declare const getValidCacheData: <T extends RequestInstance>(request: T,
|
|
228
|
-
declare const getTimestamp: (timestamp?: NullableType<number | Date>) => Date;
|
|
229
|
-
declare const
|
|
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, }: {
|
|
242
|
+
queryKey: string;
|
|
243
|
+
dispatcher: Dispatcher<ExtractAdapterType<T>>;
|
|
244
|
+
hasState: boolean;
|
|
245
|
+
revalidate?: boolean;
|
|
246
|
+
disabled?: boolean;
|
|
247
|
+
}) => boolean;
|
|
248
|
+
declare const getInitialState: <T extends RequestInstance>({ initialResponse, dispatcher, request, disabled, revalidate, }: {
|
|
249
|
+
initialResponse: NullableType<Partial<ExtractAdapterResolvedType<T>>>;
|
|
250
|
+
dispatcher: Dispatcher<ExtractAdapterType<T>>;
|
|
251
|
+
request: T;
|
|
252
|
+
disabled?: boolean;
|
|
253
|
+
revalidate?: boolean;
|
|
254
|
+
}) => UseTrackedStateType<T>;
|
|
230
255
|
|
|
231
|
-
declare const useSocketState: <DataType>(socket:
|
|
232
|
-
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;
|
|
233
259
|
setConnected: (connected: boolean) => void;
|
|
234
260
|
setConnecting: (connecting: boolean) => void;
|
|
235
261
|
setTimestamp: (timestamp: number | null) => void;
|
|
236
262
|
}, {
|
|
237
|
-
|
|
238
|
-
|
|
263
|
+
onConnected: (callback: VoidFunction) => void;
|
|
264
|
+
onDisconnected: (callback: VoidFunction) => void;
|
|
239
265
|
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
240
266
|
onConnecting: (callback: VoidFunction) => void;
|
|
241
|
-
onReconnecting: (callback: (
|
|
242
|
-
|
|
267
|
+
onReconnecting: (callback: (data: {
|
|
268
|
+
attempts: number;
|
|
269
|
+
}) => void) => void;
|
|
270
|
+
onReconnectingFailed: (callback: (data: {
|
|
271
|
+
attempts: number;
|
|
272
|
+
}) => void) => void;
|
|
243
273
|
}, {
|
|
244
|
-
readonly setRenderKey: (renderKey: keyof UseSocketStateType<DataType>) => void;
|
|
274
|
+
readonly setRenderKey: (renderKey: keyof UseSocketStateType<Socket, DataType>) => void;
|
|
245
275
|
}];
|
|
246
276
|
|
|
247
|
-
type UseSocketStateType<DataType = any> = {
|
|
277
|
+
type UseSocketStateType<Socket extends SocketInstance, DataType = any> = {
|
|
248
278
|
data: DataType | null;
|
|
279
|
+
extra: ExtractSocketExtraType<Socket> | null;
|
|
249
280
|
connected: boolean;
|
|
250
281
|
connecting: boolean;
|
|
251
282
|
timestamp: number | null;
|
|
@@ -254,11 +285,14 @@ type UseSocketStateProps = {
|
|
|
254
285
|
dependencyTracking?: boolean;
|
|
255
286
|
};
|
|
256
287
|
|
|
257
|
-
declare const initialSocketState: UseSocketStateType
|
|
288
|
+
declare const initialSocketState: UseSocketStateType<SocketInstance>;
|
|
258
289
|
|
|
259
|
-
type
|
|
260
|
-
|
|
261
|
-
|
|
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> = {
|
|
262
296
|
/**
|
|
263
297
|
* Refetch dependencies
|
|
264
298
|
*/
|
|
@@ -278,7 +312,7 @@ type UseFetchOptionsType<T extends RequestInstance> = {
|
|
|
278
312
|
/**
|
|
279
313
|
* If cache is empty we can use placeholder data.
|
|
280
314
|
*/
|
|
281
|
-
|
|
315
|
+
initialResponse?: NullableType<Partial<ExtractAdapterResolvedType<UseFetchRequest<R>>>>;
|
|
282
316
|
/**
|
|
283
317
|
* Enable/disable refresh data
|
|
284
318
|
*/
|
|
@@ -320,6 +354,10 @@ type UseFetchOptionsType<T extends RequestInstance> = {
|
|
|
320
354
|
* How long it should bounce requests.
|
|
321
355
|
*/
|
|
322
356
|
bounceTime?: number;
|
|
357
|
+
/**
|
|
358
|
+
* Not applicable for debounce mode
|
|
359
|
+
*/
|
|
360
|
+
bounceTimeout?: void;
|
|
323
361
|
} | {
|
|
324
362
|
/**
|
|
325
363
|
* Possibility to choose between debounce and throttle approaches
|
|
@@ -334,7 +372,7 @@ type UseFetchOptionsType<T extends RequestInstance> = {
|
|
|
334
372
|
*/
|
|
335
373
|
bounceTimeout?: number;
|
|
336
374
|
});
|
|
337
|
-
type UseFetchReturnType<
|
|
375
|
+
type UseFetchReturnType<R extends RequestInstance> = UseTrackedStateType<UseFetchRequest<R>> & UseTrackedStateActions<UseFetchRequest<R>> & UseRequestEventsActionsType<UseFetchRequest<R>> & {
|
|
338
376
|
/**
|
|
339
377
|
* Data related to current state of the bounce usage
|
|
340
378
|
*/
|
|
@@ -349,15 +387,15 @@ type UseFetchReturnType<T extends RequestInstance> = UseTrackedStateType<T> & Us
|
|
|
349
387
|
reset: () => void;
|
|
350
388
|
};
|
|
351
389
|
/**
|
|
352
|
-
* Refetch current request
|
|
390
|
+
* Refetch current request
|
|
353
391
|
*/
|
|
354
|
-
refetch: (
|
|
392
|
+
refetch: () => void;
|
|
355
393
|
};
|
|
356
394
|
|
|
357
395
|
declare const getRefreshTime: (refreshTime: number, dataTimestamp?: Date) => number;
|
|
358
396
|
|
|
359
|
-
type DefaultOptionsType$1 = RequiredKeys<Omit<UseFetchOptionsType<RequestInstance>, "
|
|
360
|
-
|
|
397
|
+
type DefaultOptionsType$1 = RequiredKeys<Omit<UseFetchOptionsType<RequestInstance>, "initialResponse">> & {
|
|
398
|
+
initialResponse: null;
|
|
361
399
|
};
|
|
362
400
|
declare const useFetchDefaultOptions: DefaultOptionsType$1;
|
|
363
401
|
|
|
@@ -377,7 +415,7 @@ type UseSubmitOptionsType<T extends RequestInstance> = {
|
|
|
377
415
|
/**
|
|
378
416
|
* If cache is empty we can use placeholder data.
|
|
379
417
|
*/
|
|
380
|
-
|
|
418
|
+
initialResponse?: NullableType<Partial<ExtractAdapterResolvedType<T>>>;
|
|
381
419
|
/**
|
|
382
420
|
* Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.
|
|
383
421
|
*/
|
|
@@ -415,7 +453,7 @@ type UseSubmitOptionsType<T extends RequestInstance> = {
|
|
|
415
453
|
});
|
|
416
454
|
type UseSubmitReturnType<RequestType extends RequestInstance> = Omit<UseTrackedStateType<RequestType>, "loading"> & UseTrackedStateActions<RequestType> & {
|
|
417
455
|
/**
|
|
418
|
-
* Callback which allows to cancel ongoing requests from given
|
|
456
|
+
* Callback which allows to cancel ongoing requests from given queryKey.
|
|
419
457
|
*/
|
|
420
458
|
abort: () => void;
|
|
421
459
|
/**
|
|
@@ -476,13 +514,13 @@ type UseSubmitReturnType<RequestType extends RequestInstance> = Omit<UseTrackedS
|
|
|
476
514
|
reset: () => void;
|
|
477
515
|
};
|
|
478
516
|
/**
|
|
479
|
-
* Refetch current request
|
|
517
|
+
* Refetch current request
|
|
480
518
|
*/
|
|
481
|
-
refetch: (
|
|
519
|
+
refetch: () => void;
|
|
482
520
|
};
|
|
483
521
|
|
|
484
|
-
type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<RequestInstance>, "
|
|
485
|
-
|
|
522
|
+
type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<RequestInstance>, "initialResponse">> & {
|
|
523
|
+
initialResponse: null;
|
|
486
524
|
};
|
|
487
525
|
declare const useSubmitDefaultOptions: DefaultOptionsType;
|
|
488
526
|
|
|
@@ -492,20 +530,25 @@ declare const useSubmitDefaultOptions: DefaultOptionsType;
|
|
|
492
530
|
* @param options
|
|
493
531
|
* @returns
|
|
494
532
|
*/
|
|
495
|
-
declare const useQueue: <
|
|
533
|
+
declare const useQueue: <Request extends RequestInstance>(request: Request, options?: UseQueueOptionsType) => UseQueueReturnType<Request>;
|
|
496
534
|
|
|
497
535
|
type UseQueueOptionsType = {
|
|
498
|
-
|
|
536
|
+
dispatcherType?: "auto" | "fetch" | "submit";
|
|
537
|
+
keepFinishedRequests?: boolean;
|
|
499
538
|
};
|
|
500
|
-
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;
|
|
501
544
|
/**
|
|
502
545
|
* Uploading progress for given request
|
|
503
546
|
*/
|
|
504
|
-
uploading
|
|
547
|
+
uploading: ProgressType;
|
|
505
548
|
/**
|
|
506
549
|
* Downloading progress for given request
|
|
507
550
|
*/
|
|
508
|
-
downloading
|
|
551
|
+
downloading: ProgressType;
|
|
509
552
|
/**
|
|
510
553
|
* Callback which allow to start previously stopped request.
|
|
511
554
|
*/
|
|
@@ -528,6 +571,10 @@ type UseQueueReturnType<T extends RequestInstance> = {
|
|
|
528
571
|
* List of requests for provided request
|
|
529
572
|
*/
|
|
530
573
|
requests: QueueRequest<T>[];
|
|
574
|
+
/**
|
|
575
|
+
* Request dispatcher instance
|
|
576
|
+
*/
|
|
577
|
+
dispatcher: Dispatcher<ExtractAdapterType<T>>;
|
|
531
578
|
/**
|
|
532
579
|
* Callback which allow to stop queue, it will cancel ongoing requests.
|
|
533
580
|
*/
|
|
@@ -548,7 +595,7 @@ declare const useCache: <T extends RequestInstance>(request: T, options?: UseCac
|
|
|
548
595
|
|
|
549
596
|
declare const useCacheDefaultOptions: {
|
|
550
597
|
dependencyTracking: boolean;
|
|
551
|
-
|
|
598
|
+
initialResponse: null;
|
|
552
599
|
deepCompare: boolean;
|
|
553
600
|
};
|
|
554
601
|
|
|
@@ -560,7 +607,7 @@ type UseCacheOptionsType<T extends RequestInstance> = {
|
|
|
560
607
|
/**
|
|
561
608
|
* If cache is empty we can use placeholder data.
|
|
562
609
|
*/
|
|
563
|
-
|
|
610
|
+
initialResponse?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
|
|
564
611
|
/**
|
|
565
612
|
* Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
|
|
566
613
|
*/
|
|
@@ -568,104 +615,71 @@ type UseCacheOptionsType<T extends RequestInstance> = {
|
|
|
568
615
|
};
|
|
569
616
|
type UseCacheReturnType<T extends RequestInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & {
|
|
570
617
|
/**
|
|
571
|
-
*
|
|
572
|
-
*/
|
|
573
|
-
onCacheSuccess: (callback: OnSuccessCallbackType<T>) => void;
|
|
574
|
-
/**
|
|
575
|
-
* Helper hook listener for error response
|
|
576
|
-
*/
|
|
577
|
-
onCacheError: (callback: OnErrorCallbackType<T>) => void;
|
|
578
|
-
/**
|
|
579
|
-
* Helper hook listener for response
|
|
618
|
+
* Invalidate cache for the current request or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
|
|
580
619
|
*/
|
|
581
|
-
|
|
582
|
-
/**
|
|
583
|
-
* Refetch current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
|
|
584
|
-
*/
|
|
585
|
-
refetch: (invalidateKey?: string | RegExp | RequestInstance) => void;
|
|
620
|
+
invalidate: (cacheKeys?: string | RegExp | RequestInstance | Array<string | RegExp | RequestInstance>) => void;
|
|
586
621
|
};
|
|
587
622
|
|
|
588
|
-
declare const useListener: <ListenerType extends ListenerInstance>(listener: ListenerType, options
|
|
623
|
+
declare const useListener: <ListenerType extends ListenerInstance>(listener: ListenerType, options?: UseListenerOptionsType) => {
|
|
589
624
|
listen: () => void;
|
|
590
|
-
onEvent: (callback: (response: {
|
|
625
|
+
onEvent: (callback: NonNullable<((response: {
|
|
591
626
|
data: ExtractListenerResponseType<ListenerType>;
|
|
592
|
-
extra:
|
|
593
|
-
}) => void) => void;
|
|
594
|
-
|
|
595
|
-
|
|
627
|
+
extra: Record<string, any>;
|
|
628
|
+
}) => void) | null>) => void;
|
|
629
|
+
onConnected: (callback: VoidFunction) => void;
|
|
630
|
+
onDisconnected: (callback: VoidFunction) => void;
|
|
596
631
|
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
597
632
|
onConnecting: (callback: VoidFunction) => void;
|
|
598
|
-
onReconnecting: (callback: (
|
|
599
|
-
|
|
633
|
+
onReconnecting: (callback: (data: {
|
|
634
|
+
attempts: number;
|
|
635
|
+
}) => void) => void;
|
|
636
|
+
onReconnectingFailed: (callback: (data: {
|
|
637
|
+
attempts: number;
|
|
638
|
+
}) => void) => void;
|
|
600
639
|
setData: (data: unknown) => void;
|
|
640
|
+
setExtra: (extra: any) => void;
|
|
601
641
|
setConnected: (connected: boolean) => void;
|
|
602
642
|
setConnecting: (connecting: boolean) => void;
|
|
603
|
-
setTimestamp: (timestamp: number) => void;
|
|
643
|
+
setTimestamp: (timestamp: number | null) => void;
|
|
604
644
|
data: unknown;
|
|
645
|
+
extra: any;
|
|
605
646
|
connected: boolean;
|
|
606
647
|
connecting: boolean;
|
|
607
|
-
timestamp: number;
|
|
648
|
+
timestamp: number | null;
|
|
608
649
|
};
|
|
609
650
|
|
|
610
651
|
type UseListenerOptionsType = {
|
|
611
652
|
dependencyTracking?: boolean;
|
|
612
653
|
};
|
|
613
654
|
|
|
614
|
-
declare const useEmitter: <EmitterType extends EmitterInstance>(emitter: EmitterType, options
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
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;
|
|
620
661
|
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
621
662
|
onConnecting: (callback: VoidFunction) => void;
|
|
622
|
-
onReconnecting: (callback: (
|
|
623
|
-
|
|
663
|
+
onReconnecting: (callback: (data: {
|
|
664
|
+
attempts: number;
|
|
665
|
+
}) => void) => void;
|
|
666
|
+
onReconnectingFailed: (callback: (data: {
|
|
667
|
+
attempts: number;
|
|
668
|
+
}) => void) => void;
|
|
624
669
|
setData: (data: unknown) => void;
|
|
670
|
+
setExtra: (extra: any) => void;
|
|
625
671
|
setConnected: (connected: boolean) => void;
|
|
626
672
|
setConnecting: (connecting: boolean) => void;
|
|
627
|
-
setTimestamp: (timestamp: number) => void;
|
|
673
|
+
setTimestamp: (timestamp: number | null) => void;
|
|
628
674
|
connected: boolean;
|
|
629
675
|
connecting: boolean;
|
|
630
|
-
timestamp: number;
|
|
631
676
|
};
|
|
632
677
|
|
|
633
678
|
type UseEmitterOptionsType = {
|
|
634
679
|
dependencyTracking?: boolean;
|
|
635
680
|
};
|
|
636
681
|
|
|
637
|
-
|
|
638
|
-
* Allow to listen to all event messages received with sockets
|
|
639
|
-
* @param socket
|
|
640
|
-
* @param options
|
|
641
|
-
* @returns
|
|
642
|
-
*/
|
|
643
|
-
declare const useEventMessages: <ResponsesType extends {
|
|
644
|
-
endpoint: string;
|
|
645
|
-
}>(socket: SocketInstance, options: UseEventMessagesOptionsType<ResponsesType>) => {
|
|
646
|
-
onEvent: (callback: (data: ResponsesType, event: MessageEvent<ResponsesType>) => void) => void;
|
|
647
|
-
onOpen: (callback: VoidFunction) => void;
|
|
648
|
-
onClose: (callback: VoidFunction) => void;
|
|
649
|
-
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
650
|
-
onConnecting: (callback: VoidFunction) => void;
|
|
651
|
-
onReconnecting: (callback: (attempts: number) => void) => void;
|
|
652
|
-
onReconnectingStop: (callback: (attempts: number) => void) => void;
|
|
653
|
-
setData: (data: unknown) => void;
|
|
654
|
-
setConnected: (connected: boolean) => void;
|
|
655
|
-
setConnecting: (connecting: boolean) => void;
|
|
656
|
-
setTimestamp: (timestamp: number) => void;
|
|
657
|
-
data: unknown;
|
|
658
|
-
connected: boolean;
|
|
659
|
-
connecting: boolean;
|
|
660
|
-
timestamp: number;
|
|
661
|
-
};
|
|
662
|
-
|
|
663
|
-
type UseEventMessagesOptionsType<ResponsesType> = {
|
|
664
|
-
dependencyTracking?: boolean;
|
|
665
|
-
filter?: ((endpoint: string, data: ResponsesType) => boolean) | string[];
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
declare const useAppManager: <B extends ClientInstance>(client: B) => UseAppManagerReturnType;
|
|
682
|
+
declare const useAppManager: <Client extends ClientInstance>(client: Client) => UseAppManagerReturnType;
|
|
669
683
|
|
|
670
684
|
type UseAppManagerReturnType = {
|
|
671
685
|
/**
|
|
@@ -686,31 +700,39 @@ type UseAppManagerReturnType = {
|
|
|
686
700
|
setFocused: (isFocused: boolean) => void;
|
|
687
701
|
};
|
|
688
702
|
|
|
689
|
-
type
|
|
703
|
+
type ProviderOptionsType = {
|
|
690
704
|
useFetchConfig?: Partial<UseFetchOptionsType<RequestInstance>>;
|
|
691
705
|
useSubmitConfig?: Partial<UseSubmitOptionsType<RequestInstance>>;
|
|
692
706
|
useCacheConfig?: Partial<UseCacheOptionsType<RequestInstance>>;
|
|
693
707
|
useQueueConfig?: Partial<UseQueueOptionsType>;
|
|
694
708
|
useListener?: Partial<UseListenerOptionsType>;
|
|
695
709
|
useEmitter?: Partial<UseEmitterOptionsType>;
|
|
696
|
-
useEventMessages?: Partial<UseEventMessagesOptionsType<SocketResponses>>;
|
|
697
710
|
};
|
|
698
|
-
type
|
|
711
|
+
type ProviderProps = {
|
|
712
|
+
/**
|
|
713
|
+
* Children to render
|
|
714
|
+
*/
|
|
699
715
|
children: React.ReactNode;
|
|
700
|
-
|
|
716
|
+
/**
|
|
717
|
+
* Configuration to set for available hooks
|
|
718
|
+
*/
|
|
719
|
+
config?: ProviderOptionsType;
|
|
720
|
+
};
|
|
721
|
+
type ProviderValueType = {
|
|
722
|
+
config: ProviderOptionsType;
|
|
723
|
+
setConfig: (newConfig: ProviderOptionsType) => void;
|
|
701
724
|
};
|
|
702
|
-
type ConfigProviderValueType = [ConfigProviderOptionsType, (newConfig: ConfigProviderOptionsType) => void];
|
|
703
725
|
|
|
704
726
|
/**
|
|
705
727
|
* Context provider with configuration for hooks
|
|
706
728
|
* @param options
|
|
707
729
|
* @returns
|
|
708
730
|
*/
|
|
709
|
-
declare const
|
|
731
|
+
declare const Provider: ({ children, config }: ProviderProps) => react_jsx_runtime.JSX.Element;
|
|
710
732
|
/**
|
|
711
733
|
* Hook to allow reading current context config
|
|
712
734
|
* @returns
|
|
713
735
|
*/
|
|
714
|
-
declare const
|
|
736
|
+
declare const useProvider: () => ProviderValueType;
|
|
715
737
|
|
|
716
|
-
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 };
|