@hyper-fetch/react 3.2.0 → 3.3.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.
Files changed (60) hide show
  1. package/.eslintrc.json +1 -2
  2. package/dist/index.cjs.js +1 -1
  3. package/dist/index.cjs.js.map +3 -3
  4. package/dist/index.d.ts +674 -12
  5. package/package.json +2 -3
  6. package/src/helpers/use-request-events/use-request-events.hooks.ts +0 -1
  7. package/src/hooks/use-event-messages/use-event-messages.hooks.ts +2 -2
  8. package/src/hooks/use-fetch/use-fetch.hooks.ts +6 -7
  9. package/dist/config-provider/config-provider.d.ts +0 -13
  10. package/dist/config-provider/config-provider.types.d.ts +0 -23
  11. package/dist/config-provider/index.d.ts +0 -2
  12. package/dist/helpers/index.d.ts +0 -3
  13. package/dist/helpers/use-request-events/index.d.ts +0 -2
  14. package/dist/helpers/use-request-events/use-request-events.hooks.d.ts +0 -8
  15. package/dist/helpers/use-request-events/use-request-events.types.d.ts +0 -80
  16. package/dist/helpers/use-socket-state/index.d.ts +0 -3
  17. package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts +0 -2
  18. package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts +0 -16
  19. package/dist/helpers/use-socket-state/use-socket-state.types.d.ts +0 -9
  20. package/dist/helpers/use-tracked-state/index.d.ts +0 -4
  21. package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts +0 -2
  22. package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +0 -10
  23. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +0 -72
  24. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +0 -7
  25. package/dist/hooks/use-app-manager/index.d.ts +0 -2
  26. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +0 -2
  27. package/dist/hooks/use-app-manager/use-app-manager.types.d.ts +0 -18
  28. package/dist/hooks/use-cache/index.d.ts +0 -3
  29. package/dist/hooks/use-cache/use-cache.constants.d.ts +0 -5
  30. package/dist/hooks/use-cache/use-cache.hooks.d.ts +0 -2
  31. package/dist/hooks/use-cache/use-cache.types.d.ts +0 -35
  32. package/dist/hooks/use-emitter/index.d.ts +0 -2
  33. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +0 -19
  34. package/dist/hooks/use-emitter/use-emitter.types.d.ts +0 -3
  35. package/dist/hooks/use-event-messages/index.d.ts +0 -2
  36. package/dist/hooks/use-event-messages/use-event-messages.hooks.d.ts +0 -24
  37. package/dist/hooks/use-event-messages/use-event-messages.types.d.ts +0 -4
  38. package/dist/hooks/use-fetch/index.d.ts +0 -4
  39. package/dist/hooks/use-fetch/use-fetch.constants.d.ts +0 -7
  40. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +0 -8
  41. package/dist/hooks/use-fetch/use-fetch.types.d.ts +0 -89
  42. package/dist/hooks/use-fetch/use-fetch.utils.d.ts +0 -1
  43. package/dist/hooks/use-listener/index.d.ts +0 -2
  44. package/dist/hooks/use-listener/use-listener.hooks.d.ts +0 -20
  45. package/dist/hooks/use-listener/use-listener.types.d.ts +0 -3
  46. package/dist/hooks/use-queue/index.d.ts +0 -3
  47. package/dist/hooks/use-queue/use-queue.constants.d.ts +0 -3
  48. package/dist/hooks/use-queue/use-queue.hooks.d.ts +0 -8
  49. package/dist/hooks/use-queue/use-queue.types.d.ts +0 -48
  50. package/dist/hooks/use-submit/index.d.ts +0 -3
  51. package/dist/hooks/use-submit/use-submit.constants.d.ts +0 -7
  52. package/dist/hooks/use-submit/use-submit.hooks.d.ts +0 -8
  53. package/dist/hooks/use-submit/use-submit.types.d.ts +0 -105
  54. package/dist/index.esm.js +0 -2
  55. package/dist/index.esm.js.map +0 -7
  56. package/dist/types/index.d.ts +0 -1
  57. package/dist/types/invalidation.types.d.ts +0 -2
  58. package/dist/utils/bounce.utils.d.ts +0 -7
  59. package/dist/utils/deep-equal.utils.d.ts +0 -13
  60. package/dist/utils/index.d.ts +0 -2
package/dist/index.d.ts CHANGED
@@ -1,12 +1,674 @@
1
- export * from "./hooks/use-fetch";
2
- export * from "./hooks/use-submit";
3
- export * from "./hooks/use-queue";
4
- export * from "./hooks/use-cache";
5
- export * from "./hooks/use-listener";
6
- export * from "./hooks/use-emitter";
7
- export * from "./hooks/use-event-messages";
8
- export * from "./hooks/use-app-manager";
9
- export * from "./helpers";
10
- export * from "./config-provider";
11
- export * from "./types";
12
- export * from "./utils";
1
+ import { RequestInstance, Dispatcher, LoggerType, CacheValueType, ExtractResponseType, ExtractErrorType, ResponseDetailsType, ExtractAdapterReturnType, RequestEventType, ProgressType, ResponseType, NullableType, RequiredKeys, RequestSendType, DispatcherStorageValueType, ClientInstance } from '@hyper-fetch/core';
2
+ import * as _hyper_fetch_sockets from '@hyper-fetch/sockets';
3
+ import { SocketInstance, ListenerInstance, ExtractListenerAdapterType, EmitterInstance } from '@hyper-fetch/sockets';
4
+ import React from 'react';
5
+
6
+ /**
7
+ * This hooks aims to retrieve data from server.
8
+ * @param request Request instance
9
+ * @param options Hook options
10
+ * @returns
11
+ */
12
+ declare const useFetch: <RequestType extends RequestInstance>(request: RequestType, options?: UseFetchOptionsType<RequestType>) => UseFetchReturnType<RequestType>;
13
+
14
+ /**
15
+ * This is helper hook that handles main Hyper-Fetch event/data flow
16
+ * @internal
17
+ * @param options
18
+ * @returns
19
+ */
20
+ declare const useRequestEvents: <T extends RequestInstance>({ request, dispatcher, logger, actions, setCacheData, }: UseRequestEventsPropsType<T>) => UseRequestEventsReturnType<T>;
21
+
22
+ type UseRequestEventsDataMap = {
23
+ unmount: VoidFunction;
24
+ };
25
+ type UseRequestEventsLifecycleMap = Map<string, {
26
+ unmount: VoidFunction;
27
+ }>;
28
+ type UseRequestEventsPropsType<T extends RequestInstance> = {
29
+ request: T;
30
+ dispatcher: Dispatcher;
31
+ logger: LoggerType;
32
+ actions: UseTrackedStateActions<T>;
33
+ setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
34
+ };
35
+ type UseRequestEventsActionsType<T extends RequestInstance> = {
36
+ /**
37
+ * Callback that allows canceling ongoing requests from the given queueKey.
38
+ */
39
+ abort: () => void;
40
+ /**
41
+ * Helper hook listening on success response.
42
+ */
43
+ onSuccess: (callback: OnSuccessCallbackType<T>) => void;
44
+ /**
45
+ * Helper hook listening on error response.
46
+ */
47
+ onError: (callback: OnErrorCallbackType<T>) => void;
48
+ /**
49
+ * Helper hook listening on aborting of requests. Abort events are not triggering onError callbacks.
50
+ */
51
+ onAbort: (callback: OnErrorCallbackType<T>) => void;
52
+ /**
53
+ * Helper hook listening on request going into offline awaiting for network connection to be restored. It will not trigger onError when 'offline' mode is set on request.
54
+ */
55
+ onOfflineError: (callback: OnErrorCallbackType<T>) => void;
56
+ /**
57
+ * Helper hook listening on any response.
58
+ */
59
+ onFinished: (callback: OnFinishedCallbackType<T>) => void;
60
+ /**
61
+ * Helper hook listening on request start.
62
+ */
63
+ onRequestStart: (callback: OnStartCallbackType<T>) => void;
64
+ /**
65
+ * Helper hook listening on response start(before we receive all data from server).
66
+ */
67
+ onResponseStart: (callback: OnStartCallbackType<T>) => void;
68
+ /**
69
+ * Helper hook listening on download progress ETA. We can later match given requests by their id's or request instance which holds all data which is being transferred.
70
+ */
71
+ onDownloadProgress: (callback: OnProgressCallbackType) => void;
72
+ /**
73
+ * Helper hook listening on upload progress ETA. We can later match given requests by their id's or request instance which holds all data which is being transferred.
74
+ */
75
+ onUploadProgress: (callback: OnProgressCallbackType) => void;
76
+ };
77
+ type UseRequestEventsReturnType<T extends RequestInstance> = [
78
+ UseRequestEventsActionsType<T>,
79
+ {
80
+ addDataListener: (request: RequestInstance) => VoidFunction;
81
+ clearDataListener: VoidFunction;
82
+ addLifecycleListeners: (request: RequestInstance, requestId?: string) => VoidFunction;
83
+ removeLifecycleListener: (requestId: string) => void;
84
+ clearLifecycleListeners: () => void;
85
+ }
86
+ ];
87
+ type CallbackParameters<Request, ResponseType> = {
88
+ response: ResponseType;
89
+ details: ResponseDetailsType;
90
+ request: Request;
91
+ };
92
+ type OnSuccessCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ExtractResponseType<Request>>) => void | Promise<void>;
93
+ type OnErrorCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ExtractErrorType<Request>>) => void | Promise<void>;
94
+ type OnFinishedCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ExtractAdapterReturnType<Request>>) => void | Promise<void>;
95
+ type OnStartCallbackType<Request extends RequestInstance> = (params: {
96
+ details: RequestEventType<Request>;
97
+ request: Request;
98
+ }) => void | Promise<void>;
99
+ type OnProgressCallbackType = <Request extends RequestInstance>(progress: ProgressType, details: RequestEventType<Request>) => void | Promise<void>;
100
+
101
+ /**
102
+ * Check if value is empty
103
+ * @param value any object or primitive
104
+ * @returns true when value is empty
105
+ */
106
+ declare const isEmpty: (value: unknown) => boolean;
107
+ /**
108
+ * Allow to deep compare any passed values
109
+ * @param firstValue unknown
110
+ * @param secondValue unknown
111
+ * @returns true when elements are equal
112
+ */
113
+ declare const isEqual: (firstValue: unknown, secondValue: unknown) => boolean;
114
+
115
+ declare const getBounceData: (bounceData: {
116
+ reset: () => void;
117
+ active: boolean;
118
+ }) => {
119
+ reset: () => void;
120
+ active: boolean;
121
+ };
122
+
123
+ type UseTrackedStateProps<T extends RequestInstance> = {
124
+ request: T;
125
+ logger: LoggerType;
126
+ initialData: ResponseType<ExtractResponseType<T>, ExtractErrorType<T>> | null;
127
+ dispatcher: Dispatcher;
128
+ dependencyTracking: boolean;
129
+ defaultCacheEmitting?: boolean;
130
+ deepCompare: boolean | typeof isEqual;
131
+ };
132
+ type UseTrackedStateReturn<T extends RequestInstance> = [
133
+ UseTrackedStateType<T>,
134
+ UseTrackedStateActions<T>,
135
+ {
136
+ setRenderKey: (renderKey: keyof UseTrackedStateType<T>) => void;
137
+ setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
138
+ getStaleStatus: () => boolean;
139
+ }
140
+ ];
141
+ type UseTrackedStateType<T extends RequestInstance = RequestInstance> = {
142
+ /**
143
+ * Request response data
144
+ */
145
+ data: null | ExtractResponseType<T>;
146
+ /**
147
+ * Request response error
148
+ */
149
+ error: null | ExtractErrorType<T>;
150
+ /**
151
+ * Request loading state
152
+ */
153
+ loading: boolean;
154
+ /**
155
+ * Request http status code
156
+ */
157
+ status: null | number;
158
+ /**
159
+ * Request attempts
160
+ */
161
+ retries: number;
162
+ /**
163
+ * Request response timestamp
164
+ */
165
+ timestamp: null | Date;
166
+ };
167
+ type UseTrackedStateActions<T extends RequestInstance> = {
168
+ /**
169
+ * Action to set custom data. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option.
170
+ */
171
+ setData: (data: ExtractResponseType<T>, emitToCache?: boolean) => void;
172
+ /**
173
+ * Action to set custom error. We can do it locally(inside hook state) or in all hooks with 'emitToCache' option.
174
+ */
175
+ setError: (error: ExtractErrorType<T>, emitToCache?: boolean) => void;
176
+ /**
177
+ * Action to set custom loading. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option
178
+ */
179
+ setLoading: (loading: boolean, emitToHooks?: boolean) => void;
180
+ /**
181
+ * Action to set custom status. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option
182
+ */
183
+ setStatus: (status: number | null, emitToCache?: boolean) => void;
184
+ /**
185
+ * Action to set custom retries count. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option
186
+ */
187
+ setRetries: (retries: number, emitToCache?: boolean) => void;
188
+ /**
189
+ * Action to set custom timestamp. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option
190
+ */
191
+ setTimestamp: (timestamp: Date, emitToCache?: boolean) => void;
192
+ };
193
+
194
+ declare const initialState: UseTrackedStateType;
195
+
196
+ /**
197
+ *
198
+ * @param request
199
+ * @param initialData
200
+ * @param dispatcher
201
+ * @param dependencies
202
+ * @internal
203
+ */
204
+ declare const useTrackedState: <T extends RequestInstance>({ request, dispatcher, initialData, deepCompare, dependencyTracking, defaultCacheEmitting, }: UseTrackedStateProps<T>) => UseTrackedStateReturn<T>;
205
+
206
+ declare const getDetailsState: (state?: UseTrackedStateType<RequestInstance>, details?: Partial<CacheValueType<unknown, unknown>["details"]>) => CacheValueType<unknown, unknown>["details"];
207
+ declare const isStaleCacheData: (cacheTime: number, cacheTimestamp: NullableType<Date | number>) => boolean;
208
+ declare const getValidCacheData: <T extends RequestInstance>(request: T, initialData: ExtractAdapterReturnType<T>, cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>;
209
+ declare const getTimestamp: (timestamp?: NullableType<number | Date>) => Date;
210
+ declare const getInitialState: <T extends RequestInstance>(initialData: ResponseType<ExtractResponseType<T>, ExtractErrorType<T>>, dispatcher: Dispatcher, request: T) => UseTrackedStateType<T>;
211
+
212
+ declare const useSocketState: <DataType>(socket: SocketInstance, { dependencyTracking }: UseSocketStateProps) => readonly [UseSocketStateType<DataType>, {
213
+ setData: (data: DataType) => void;
214
+ setConnected: (connected: boolean) => void;
215
+ setConnecting: (connecting: boolean) => void;
216
+ setTimestamp: (timestamp: number | null) => void;
217
+ }, {
218
+ onOpen: (callback: VoidFunction) => void;
219
+ onClose: (callback: VoidFunction) => void;
220
+ onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
221
+ onConnecting: (callback: VoidFunction) => void;
222
+ onReconnecting: (callback: (attempts: number) => void) => void;
223
+ onReconnectingStop: (callback: (attempts: number) => void) => void;
224
+ }, {
225
+ readonly setRenderKey: (renderKey: keyof UseSocketStateType<DataType>) => void;
226
+ }];
227
+
228
+ type UseSocketStateType<DataType = any> = {
229
+ data: DataType | null;
230
+ connected: boolean;
231
+ connecting: boolean;
232
+ timestamp: number | null;
233
+ };
234
+ type UseSocketStateProps = {
235
+ dependencyTracking?: boolean;
236
+ };
237
+
238
+ declare const initialSocketState: UseSocketStateType;
239
+
240
+ type InvalidationKeyType = string | RequestInstance | RegExp;
241
+
242
+ type UseFetchOptionsType<T extends RequestInstance> = {
243
+ /**
244
+ * Refetch dependencies
245
+ */
246
+ dependencies?: any[];
247
+ /**
248
+ * Disable fetching
249
+ */
250
+ disabled?: boolean;
251
+ /**
252
+ * If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
253
+ */
254
+ dependencyTracking?: boolean;
255
+ /**
256
+ * If `true` it will refetch data in background no matter if we have it from cache.
257
+ */
258
+ revalidateOnMount?: boolean;
259
+ /**
260
+ * If cache is empty we can use placeholder data.
261
+ */
262
+ initialData?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
263
+ /**
264
+ * Enable/disable refresh data
265
+ */
266
+ refresh?: boolean;
267
+ /**
268
+ * Refresh data interval time
269
+ */
270
+ refreshTime?: number;
271
+ /**
272
+ * Enable/disable data refresh if our tab is not focused(used by user at given time).
273
+ */
274
+ refreshBlurred?: boolean;
275
+ /**
276
+ * Enable/disable data refresh if user leaves current tab.
277
+ */
278
+ refreshOnBlur?: boolean;
279
+ /**
280
+ * Enable/disable data refresh if user enters current tab.
281
+ */
282
+ refreshOnFocus?: boolean;
283
+ /**
284
+ * Enable/disable data refresh if network is restored.
285
+ */
286
+ refreshOnReconnect?: boolean;
287
+ /**
288
+ * Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.
289
+ */
290
+ bounce?: boolean;
291
+ /**
292
+ * Possibility to choose between debounce and throttle approaches
293
+ */
294
+ bounceType?: "debounce" | "throttle";
295
+ /**
296
+ * How long it should bounce requests.
297
+ */
298
+ bounceTime?: number;
299
+ /**
300
+ * ONLY in throttle mode - options for handling last bounce event
301
+ */
302
+ bounceTimeout?: number;
303
+ /**
304
+ * Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
305
+ */
306
+ deepCompare?: boolean | typeof isEqual;
307
+ };
308
+ type UseFetchReturnType<T extends RequestInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & UseRequestEventsActionsType<T> & {
309
+ /**
310
+ * Data related to current state of the bounce usage
311
+ */
312
+ bounce: {
313
+ /**
314
+ * Active state of the bounce method
315
+ */
316
+ active: boolean;
317
+ /**
318
+ * Method to stop the active bounce method execution
319
+ */
320
+ reset: () => void;
321
+ };
322
+ /**
323
+ * Revalidate current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
324
+ */
325
+ revalidate: (invalidateKey?: InvalidationKeyType | InvalidationKeyType[]) => void;
326
+ };
327
+
328
+ declare const getRefreshTime: (refreshTime: number, dataTimestamp?: Date) => number;
329
+
330
+ type DefaultOptionsType$1 = RequiredKeys<Omit<UseFetchOptionsType<RequestInstance>, "initialData">> & {
331
+ initialData: null;
332
+ };
333
+ declare const useFetchDefaultOptions: DefaultOptionsType$1;
334
+
335
+ /**
336
+ * This hooks aims to mutate data on the server.
337
+ * @param request
338
+ * @param options
339
+ * @returns
340
+ */
341
+ declare const useSubmit: <RequestType extends RequestInstance>(request: RequestType, options?: UseSubmitOptionsType<RequestType>) => UseSubmitReturnType<RequestType>;
342
+
343
+ type UseSubmitOptionsType<T extends RequestInstance> = {
344
+ /**
345
+ * Disable fetching
346
+ */
347
+ disabled?: boolean;
348
+ /**
349
+ * If cache is empty we can use placeholder data.
350
+ */
351
+ initialData?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
352
+ /**
353
+ * Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.
354
+ */
355
+ bounce?: boolean;
356
+ /**
357
+ * Possibility to choose between debounce and throttle approaches
358
+ */
359
+ bounceType?: "debounce" | "throttle";
360
+ /**
361
+ * How long it should bounce requests.
362
+ */
363
+ bounceTime?: number;
364
+ /**
365
+ * ONLY in throttle mode - options for handling last bounce event
366
+ */
367
+ bounceTimeout?: number;
368
+ /**
369
+ * If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
370
+ */
371
+ dependencyTracking?: boolean;
372
+ /**
373
+ * Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
374
+ */
375
+ deepCompare?: boolean | typeof isEqual;
376
+ };
377
+ type UseSubmitReturnType<RequestType extends RequestInstance> = Omit<UseTrackedStateType<RequestType>, "loading"> & UseTrackedStateActions<RequestType> & {
378
+ /**
379
+ * Callback which allows to cancel ongoing requests from given queueKey.
380
+ */
381
+ abort: () => void;
382
+ /**
383
+ * Helper hook listening on success response.
384
+ */
385
+ onSubmitSuccess: (callback: OnSuccessCallbackType<RequestType>) => void;
386
+ /**
387
+ * Helper hook listening on error response.
388
+ */
389
+ onSubmitError: (callback: OnErrorCallbackType<RequestType>) => void;
390
+ /**
391
+ * Helper hook listening on any response.
392
+ */
393
+ onSubmitFinished: (callback: OnFinishedCallbackType<RequestType>) => void;
394
+ /**
395
+ * Helper hook listening on request start.
396
+ */
397
+ onSubmitRequestStart: (callback: OnStartCallbackType<RequestType>) => void;
398
+ /**
399
+ * Helper hook listening on response start(before we receive all data from server).
400
+ */
401
+ onSubmitResponseStart: (callback: OnStartCallbackType<RequestType>) => void;
402
+ /**
403
+ * Helper hook listening on download progress ETA. We can later match given requests by their id's or request instance which holds all data which is being transferred.
404
+ */
405
+ onSubmitDownloadProgress: (callback: OnProgressCallbackType) => void;
406
+ /**
407
+ * Helper hook listening on upload progress ETA. We can later match given requests by their id's or request instance which holds all data which is being transferred.
408
+ */
409
+ onSubmitUploadProgress: (callback: OnProgressCallbackType) => void;
410
+ /**
411
+ * Helper hook listening on aborting of requests. Abort events are not triggering onError callbacks.
412
+ */
413
+ onSubmitAbort: (callback: OnErrorCallbackType<RequestType>) => void;
414
+ /**
415
+ * Helper hook listening on request going into offline awaiting for network connection to be restored. It will not trigger onError when 'offline' mode is set on request.
416
+ */
417
+ onSubmitOfflineError: (callback: OnErrorCallbackType<RequestType>) => void;
418
+ /**
419
+ * Method responsible for triggering requests. It return Promise which will be resolved with the request.
420
+ */
421
+ submit: RequestSendType<RequestType>;
422
+ /**
423
+ * Request loading state
424
+ */
425
+ submitting: boolean;
426
+ /**
427
+ * Data related to current state of the bounce usage
428
+ */
429
+ bounce: {
430
+ /**
431
+ * Active state of the bounce method
432
+ */
433
+ active: boolean;
434
+ /**
435
+ * Method to stop the active bounce method execution
436
+ */
437
+ reset: () => void;
438
+ };
439
+ /**
440
+ * Revalidate current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
441
+ */
442
+ revalidate: (invalidateKey: InvalidationKeyType | InvalidationKeyType[]) => void;
443
+ };
444
+
445
+ type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<RequestInstance>, "initialData">> & {
446
+ initialData: null;
447
+ };
448
+ declare const useSubmitDefaultOptions: DefaultOptionsType;
449
+
450
+ /**
451
+ * This hook allows to control dispatchers request queues
452
+ * @param request
453
+ * @param options
454
+ * @returns
455
+ */
456
+ declare const useQueue: <Request_1 extends RequestInstance>(request: Request_1, options?: UseQueueOptionsType) => UseQueueReturnType<Request_1>;
457
+
458
+ type UseQueueOptionsType = {
459
+ queueType?: "auto" | "fetch" | "submit";
460
+ };
461
+ type QueueRequest<Request extends RequestInstance> = DispatcherStorageValueType<Request> & {
462
+ /**
463
+ * Uploading progress for given request
464
+ */
465
+ uploading?: ProgressType;
466
+ /**
467
+ * Downloading progress for given request
468
+ */
469
+ downloading?: ProgressType;
470
+ /**
471
+ * Callback which allow to start previously stopped request.
472
+ */
473
+ startRequest: () => void;
474
+ /**
475
+ * Callback which allow to stop request and cancel it if it's ongoing.
476
+ */
477
+ stopRequest: () => void;
478
+ /**
479
+ * Removes request from the queue
480
+ */
481
+ deleteRequest: () => void;
482
+ };
483
+ type UseQueueReturnType<T extends RequestInstance> = {
484
+ /**
485
+ * Queue status for provided request
486
+ */
487
+ stopped: boolean;
488
+ /**
489
+ * List of requests for provided request
490
+ */
491
+ requests: QueueRequest<T>[];
492
+ /**
493
+ * Callback which allow to stop queue, it will cancel ongoing requests.
494
+ */
495
+ stop: () => void;
496
+ /**
497
+ * Callback which allow to pause queue. It will allow ongoing requests to be finished, but will stop next from being send.
498
+ */
499
+ pause: () => void;
500
+ /**
501
+ * Callback which allow to start queue.
502
+ */
503
+ start: () => void;
504
+ };
505
+
506
+ declare const useQueueDefaultOptions: RequiredKeys<UseQueueOptionsType>;
507
+
508
+ declare const useCache: <T extends RequestInstance>(request: T, options?: UseCacheOptionsType<T>) => UseCacheReturnType<T>;
509
+
510
+ declare const useCacheDefaultOptions: {
511
+ dependencyTracking: boolean;
512
+ initialData: any;
513
+ deepCompare: boolean;
514
+ };
515
+
516
+ type UseCacheOptionsType<T extends RequestInstance> = {
517
+ /**
518
+ * If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
519
+ */
520
+ dependencyTracking?: boolean;
521
+ /**
522
+ * If cache is empty we can use placeholder data.
523
+ */
524
+ initialData?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
525
+ /**
526
+ * Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
527
+ */
528
+ deepCompare?: boolean | typeof isEqual;
529
+ };
530
+ type UseCacheReturnType<T extends RequestInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & {
531
+ /**
532
+ * Helper hook listener for success response
533
+ */
534
+ onCacheSuccess: (callback: OnSuccessCallbackType<T>) => void;
535
+ /**
536
+ * Helper hook listener for error response
537
+ */
538
+ onCacheError: (callback: OnErrorCallbackType<T>) => void;
539
+ /**
540
+ * Helper hook listener for response
541
+ */
542
+ onCacheChange: (callback: OnFinishedCallbackType<T>) => void;
543
+ /**
544
+ * Revalidate current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
545
+ */
546
+ revalidate: (invalidateKey?: string | RegExp | RequestInstance) => void;
547
+ };
548
+
549
+ declare const useListener: <ListenerType extends ListenerInstance>(listener: ListenerType, options: UseListenerOptionsType) => {
550
+ listen: () => void;
551
+ onEvent: (callback: (data: ExtractListenerAdapterType<ListenerType>, event: MessageEvent<ExtractListenerAdapterType<ListenerType>>) => void) => void;
552
+ onOpen: (callback: VoidFunction) => void;
553
+ onClose: (callback: VoidFunction) => void;
554
+ onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
555
+ onConnecting: (callback: VoidFunction) => void;
556
+ onReconnecting: (callback: (attempts: number) => void) => void;
557
+ onReconnectingStop: (callback: (attempts: number) => void) => void;
558
+ setData: (data: unknown) => void;
559
+ setConnected: (connected: boolean) => void;
560
+ setConnecting: (connecting: boolean) => void;
561
+ setTimestamp: (timestamp: number) => void;
562
+ data: unknown;
563
+ connected: boolean;
564
+ connecting: boolean;
565
+ timestamp: number;
566
+ };
567
+
568
+ type UseListenerOptionsType = {
569
+ dependencyTracking?: boolean;
570
+ };
571
+
572
+ declare const useEmitter: <EmitterType extends EmitterInstance>(emitter: EmitterType, options: UseEmitterOptionsType) => {
573
+ emit: (options?: Partial<_hyper_fetch_sockets.EmitterCloneOptionsType<any, any>>, ack?: (error: Error, response: any) => void) => string;
574
+ reconnect: number;
575
+ onEvent: (callback: (emitter: EmitterType) => void) => void;
576
+ onOpen: (callback: VoidFunction) => void;
577
+ onClose: (callback: VoidFunction) => void;
578
+ onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
579
+ onConnecting: (callback: VoidFunction) => void;
580
+ onReconnecting: (callback: (attempts: number) => void) => void;
581
+ onReconnectingStop: (callback: (attempts: number) => void) => void;
582
+ setData: (data: unknown) => void;
583
+ setConnected: (connected: boolean) => void;
584
+ setConnecting: (connecting: boolean) => void;
585
+ setTimestamp: (timestamp: number) => void;
586
+ connected: boolean;
587
+ connecting: boolean;
588
+ timestamp: number;
589
+ };
590
+
591
+ type UseEmitterOptionsType = {
592
+ dependencyTracking?: boolean;
593
+ };
594
+
595
+ /**
596
+ * Allow to listen to all event messages received with sockets
597
+ * @param socket
598
+ * @param options
599
+ * @returns
600
+ */
601
+ declare const useEventMessages: <ResponsesType extends {
602
+ name: string;
603
+ }>(socket: SocketInstance, options: UseEventMessagesOptionsType<ResponsesType>) => {
604
+ onEvent: (callback: (data: ResponsesType, event: MessageEvent<ResponsesType>) => void) => void;
605
+ onOpen: (callback: VoidFunction) => void;
606
+ onClose: (callback: VoidFunction) => void;
607
+ onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
608
+ onConnecting: (callback: VoidFunction) => void;
609
+ onReconnecting: (callback: (attempts: number) => void) => void;
610
+ onReconnectingStop: (callback: (attempts: number) => void) => void;
611
+ setData: (data: unknown) => void;
612
+ setConnected: (connected: boolean) => void;
613
+ setConnecting: (connecting: boolean) => void;
614
+ setTimestamp: (timestamp: number) => void;
615
+ data: unknown;
616
+ connected: boolean;
617
+ connecting: boolean;
618
+ timestamp: number;
619
+ };
620
+
621
+ type UseEventMessagesOptionsType<ResponsesType> = {
622
+ dependencyTracking?: boolean;
623
+ filter?: ((data: ResponsesType, event: MessageEvent<ResponsesType>) => boolean) | string[];
624
+ };
625
+
626
+ declare const useAppManager: <B extends ClientInstance>(client: B) => UseAppManagerReturnType;
627
+
628
+ type UseAppManagerReturnType = {
629
+ /**
630
+ * Is window focused
631
+ */
632
+ isFocused: boolean;
633
+ /**
634
+ * Network online status
635
+ */
636
+ isOnline: boolean;
637
+ /**
638
+ * Network state setter
639
+ */
640
+ setOnline: (isOnline: boolean) => void;
641
+ /**
642
+ * Focus state setter
643
+ */
644
+ setFocused: (isFocused: boolean) => void;
645
+ };
646
+
647
+ type ConfigProviderOptionsType<SocketResponses = any> = {
648
+ useFetchConfig?: Partial<UseFetchOptionsType<RequestInstance>>;
649
+ useSubmitConfig?: Partial<UseSubmitOptionsType<RequestInstance>>;
650
+ useCacheConfig?: Partial<UseCacheOptionsType<RequestInstance>>;
651
+ useQueueConfig?: Partial<UseQueueOptionsType>;
652
+ useListener?: Partial<UseListenerOptionsType>;
653
+ useEmitter?: Partial<UseEmitterOptionsType>;
654
+ useEventMessages?: Partial<UseEventMessagesOptionsType<SocketResponses>>;
655
+ };
656
+ type ConfigProviderProps = {
657
+ children: React.ReactNode;
658
+ config?: ConfigProviderOptionsType;
659
+ };
660
+ type ConfigProviderValueType = [ConfigProviderOptionsType, (newConfig: ConfigProviderOptionsType) => void];
661
+
662
+ /**
663
+ * Context provider with configuration for hooks
664
+ * @param options
665
+ * @returns
666
+ */
667
+ declare const ConfigProvider: ({ children, config }: ConfigProviderProps) => JSX.Element;
668
+ /**
669
+ * Hook to allow reading current context config
670
+ * @returns
671
+ */
672
+ declare const useConfigProvider: () => ConfigProviderValueType;
673
+
674
+ export { CallbackParameters, ConfigProvider, ConfigProviderOptionsType, ConfigProviderProps, ConfigProviderValueType, InvalidationKeyType, OnErrorCallbackType, OnFinishedCallbackType, OnProgressCallbackType, OnStartCallbackType, OnSuccessCallbackType, QueueRequest, UseAppManagerReturnType, UseCacheOptionsType, UseCacheReturnType, UseEmitterOptionsType, UseEventMessagesOptionsType, UseFetchOptionsType, UseFetchReturnType, UseListenerOptionsType, UseQueueOptionsType, UseQueueReturnType, UseRequestEventsActionsType, UseRequestEventsDataMap, UseRequestEventsLifecycleMap, UseRequestEventsPropsType, UseRequestEventsReturnType, UseSocketStateProps, UseSocketStateType, UseSubmitOptionsType, UseSubmitReturnType, UseTrackedStateActions, UseTrackedStateProps, UseTrackedStateReturn, UseTrackedStateType, getBounceData, getDetailsState, getInitialState, getRefreshTime, getTimestamp, getValidCacheData, initialSocketState, initialState, isEmpty, isEqual, isStaleCacheData, useAppManager, useCache, useCacheDefaultOptions, useConfigProvider, useEmitter, useEventMessages, useFetch, useFetchDefaultOptions, useListener, useQueue, useQueueDefaultOptions, useRequestEvents, useSocketState, useSubmit, useSubmitDefaultOptions, useTrackedState };