@hyper-fetch/react 3.2.0 → 3.2.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 +1 -2
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.d.ts +674 -12
- package/dist/index.esm.js.map +2 -2
- package/package.json +2 -2
- package/src/hooks/use-event-messages/use-event-messages.hooks.ts +2 -2
- package/src/hooks/use-fetch/use-fetch.hooks.ts +5 -5
- package/dist/config-provider/config-provider.d.ts +0 -13
- package/dist/config-provider/config-provider.types.d.ts +0 -23
- package/dist/config-provider/index.d.ts +0 -2
- package/dist/helpers/index.d.ts +0 -3
- package/dist/helpers/use-request-events/index.d.ts +0 -2
- package/dist/helpers/use-request-events/use-request-events.hooks.d.ts +0 -8
- package/dist/helpers/use-request-events/use-request-events.types.d.ts +0 -80
- package/dist/helpers/use-socket-state/index.d.ts +0 -3
- package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts +0 -2
- package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts +0 -16
- package/dist/helpers/use-socket-state/use-socket-state.types.d.ts +0 -9
- package/dist/helpers/use-tracked-state/index.d.ts +0 -4
- package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts +0 -2
- package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +0 -10
- package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +0 -72
- package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +0 -7
- package/dist/hooks/use-app-manager/index.d.ts +0 -2
- package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +0 -2
- package/dist/hooks/use-app-manager/use-app-manager.types.d.ts +0 -18
- package/dist/hooks/use-cache/index.d.ts +0 -3
- package/dist/hooks/use-cache/use-cache.constants.d.ts +0 -5
- package/dist/hooks/use-cache/use-cache.hooks.d.ts +0 -2
- package/dist/hooks/use-cache/use-cache.types.d.ts +0 -35
- package/dist/hooks/use-emitter/index.d.ts +0 -2
- package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +0 -19
- package/dist/hooks/use-emitter/use-emitter.types.d.ts +0 -3
- package/dist/hooks/use-event-messages/index.d.ts +0 -2
- package/dist/hooks/use-event-messages/use-event-messages.hooks.d.ts +0 -24
- package/dist/hooks/use-event-messages/use-event-messages.types.d.ts +0 -4
- package/dist/hooks/use-fetch/index.d.ts +0 -4
- package/dist/hooks/use-fetch/use-fetch.constants.d.ts +0 -7
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +0 -8
- package/dist/hooks/use-fetch/use-fetch.types.d.ts +0 -89
- package/dist/hooks/use-fetch/use-fetch.utils.d.ts +0 -1
- package/dist/hooks/use-listener/index.d.ts +0 -2
- package/dist/hooks/use-listener/use-listener.hooks.d.ts +0 -20
- package/dist/hooks/use-listener/use-listener.types.d.ts +0 -3
- package/dist/hooks/use-queue/index.d.ts +0 -3
- package/dist/hooks/use-queue/use-queue.constants.d.ts +0 -3
- package/dist/hooks/use-queue/use-queue.hooks.d.ts +0 -8
- package/dist/hooks/use-queue/use-queue.types.d.ts +0 -48
- package/dist/hooks/use-submit/index.d.ts +0 -3
- package/dist/hooks/use-submit/use-submit.constants.d.ts +0 -7
- package/dist/hooks/use-submit/use-submit.hooks.d.ts +0 -8
- package/dist/hooks/use-submit/use-submit.types.d.ts +0 -105
- package/dist/types/index.d.ts +0 -1
- package/dist/types/invalidation.types.d.ts +0 -2
- package/dist/utils/bounce.utils.d.ts +0 -7
- package/dist/utils/deep-equal.utils.d.ts +0 -13
- package/dist/utils/index.d.ts +0 -2
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Dispatcher, ExtractErrorType, CacheValueType, ExtractResponseType, LoggerType, ProgressType, ExtractAdapterReturnType, RequestEventType, RequestInstance, ResponseDetailsType } from "@hyper-fetch/core";
|
|
2
|
-
import { UseTrackedStateActions } from "helpers";
|
|
3
|
-
export type UseRequestEventsDataMap = {
|
|
4
|
-
unmount: VoidFunction;
|
|
5
|
-
};
|
|
6
|
-
export type UseRequestEventsLifecycleMap = Map<string, {
|
|
7
|
-
unmount: VoidFunction;
|
|
8
|
-
}>;
|
|
9
|
-
export type UseRequestEventsPropsType<T extends RequestInstance> = {
|
|
10
|
-
request: T;
|
|
11
|
-
dispatcher: Dispatcher;
|
|
12
|
-
logger: LoggerType;
|
|
13
|
-
actions: UseTrackedStateActions<T>;
|
|
14
|
-
setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
|
|
15
|
-
};
|
|
16
|
-
export type UseRequestEventsActionsType<T extends RequestInstance> = {
|
|
17
|
-
/**
|
|
18
|
-
* Callback that allows canceling ongoing requests from the given queueKey.
|
|
19
|
-
*/
|
|
20
|
-
abort: () => void;
|
|
21
|
-
/**
|
|
22
|
-
* Helper hook listening on success response.
|
|
23
|
-
*/
|
|
24
|
-
onSuccess: (callback: OnSuccessCallbackType<T>) => void;
|
|
25
|
-
/**
|
|
26
|
-
* Helper hook listening on error response.
|
|
27
|
-
*/
|
|
28
|
-
onError: (callback: OnErrorCallbackType<T>) => void;
|
|
29
|
-
/**
|
|
30
|
-
* Helper hook listening on aborting of requests. Abort events are not triggering onError callbacks.
|
|
31
|
-
*/
|
|
32
|
-
onAbort: (callback: OnErrorCallbackType<T>) => void;
|
|
33
|
-
/**
|
|
34
|
-
* 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.
|
|
35
|
-
*/
|
|
36
|
-
onOfflineError: (callback: OnErrorCallbackType<T>) => void;
|
|
37
|
-
/**
|
|
38
|
-
* Helper hook listening on any response.
|
|
39
|
-
*/
|
|
40
|
-
onFinished: (callback: OnFinishedCallbackType<T>) => void;
|
|
41
|
-
/**
|
|
42
|
-
* Helper hook listening on request start.
|
|
43
|
-
*/
|
|
44
|
-
onRequestStart: (callback: OnStartCallbackType<T>) => void;
|
|
45
|
-
/**
|
|
46
|
-
* Helper hook listening on response start(before we receive all data from server).
|
|
47
|
-
*/
|
|
48
|
-
onResponseStart: (callback: OnStartCallbackType<T>) => void;
|
|
49
|
-
/**
|
|
50
|
-
* 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.
|
|
51
|
-
*/
|
|
52
|
-
onDownloadProgress: (callback: OnProgressCallbackType) => void;
|
|
53
|
-
/**
|
|
54
|
-
* 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.
|
|
55
|
-
*/
|
|
56
|
-
onUploadProgress: (callback: OnProgressCallbackType) => void;
|
|
57
|
-
};
|
|
58
|
-
export type UseRequestEventsReturnType<T extends RequestInstance> = [
|
|
59
|
-
UseRequestEventsActionsType<T>,
|
|
60
|
-
{
|
|
61
|
-
addDataListener: (request: RequestInstance) => VoidFunction;
|
|
62
|
-
clearDataListener: VoidFunction;
|
|
63
|
-
addLifecycleListeners: (request: RequestInstance, requestId?: string) => VoidFunction;
|
|
64
|
-
removeLifecycleListener: (requestId: string) => void;
|
|
65
|
-
clearLifecycleListeners: () => void;
|
|
66
|
-
}
|
|
67
|
-
];
|
|
68
|
-
export type CallbackParameters<Request, ResponseType> = {
|
|
69
|
-
response: ResponseType;
|
|
70
|
-
details: ResponseDetailsType;
|
|
71
|
-
request: Request;
|
|
72
|
-
};
|
|
73
|
-
export type OnSuccessCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ExtractResponseType<Request>>) => void | Promise<void>;
|
|
74
|
-
export type OnErrorCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ExtractErrorType<Request>>) => void | Promise<void>;
|
|
75
|
-
export type OnFinishedCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ExtractAdapterReturnType<Request>>) => void | Promise<void>;
|
|
76
|
-
export type OnStartCallbackType<Request extends RequestInstance> = (params: {
|
|
77
|
-
details: RequestEventType<Request>;
|
|
78
|
-
request: Request;
|
|
79
|
-
}) => void | Promise<void>;
|
|
80
|
-
export type OnProgressCallbackType = <Request extends RequestInstance>(progress: ProgressType, details: RequestEventType<Request>) => void | Promise<void>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { UseSocketStateType, UseSocketStateProps } from "helpers";
|
|
2
|
-
export declare const useSocketState: <DataType>(socket: Socket<any>, { dependencyTracking }: UseSocketStateProps) => readonly [UseSocketStateType<DataType>, {
|
|
3
|
-
setData: (data: DataType) => void;
|
|
4
|
-
setConnected: (connected: boolean) => void;
|
|
5
|
-
setConnecting: (connecting: boolean) => void;
|
|
6
|
-
setTimestamp: (timestamp: number | null) => void;
|
|
7
|
-
}, {
|
|
8
|
-
onOpen: (callback: VoidFunction) => void;
|
|
9
|
-
onClose: (callback: VoidFunction) => void;
|
|
10
|
-
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
11
|
-
onConnecting: (callback: VoidFunction) => void;
|
|
12
|
-
onReconnecting: (callback: (attempts: number) => void) => void;
|
|
13
|
-
onReconnectingStop: (callback: (attempts: number) => void) => void;
|
|
14
|
-
}, {
|
|
15
|
-
readonly setRenderKey: (renderKey: keyof UseSocketStateType<DataType>) => void;
|
|
16
|
-
}];
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { UseTrackedStateProps, UseTrackedStateReturn } from "./use-tracked-state.types";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param request
|
|
5
|
-
* @param initialData
|
|
6
|
-
* @param dispatcher
|
|
7
|
-
* @param dependencies
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export declare const useTrackedState: <T extends Request<any, any, any, any, any, any, any, any, any, any, any>>({ request, dispatcher, initialData, deepCompare, dependencyTracking, defaultCacheEmitting, }: UseTrackedStateProps<T>) => UseTrackedStateReturn<T>;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Dispatcher, ExtractErrorType, CacheValueType, ExtractResponseType, ResponseType, RequestInstance, LoggerType } from "@hyper-fetch/core";
|
|
2
|
-
import { isEqual } from "utils";
|
|
3
|
-
export type UseTrackedStateProps<T extends RequestInstance> = {
|
|
4
|
-
request: T;
|
|
5
|
-
logger: LoggerType;
|
|
6
|
-
initialData: ResponseType<ExtractResponseType<T>, ExtractErrorType<T>> | null;
|
|
7
|
-
dispatcher: Dispatcher;
|
|
8
|
-
dependencyTracking: boolean;
|
|
9
|
-
defaultCacheEmitting?: boolean;
|
|
10
|
-
deepCompare: boolean | typeof isEqual;
|
|
11
|
-
};
|
|
12
|
-
export type UseTrackedStateReturn<T extends RequestInstance> = [
|
|
13
|
-
UseTrackedStateType<T>,
|
|
14
|
-
UseTrackedStateActions<T>,
|
|
15
|
-
{
|
|
16
|
-
setRenderKey: (renderKey: keyof UseTrackedStateType<T>) => void;
|
|
17
|
-
setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
|
|
18
|
-
getStaleStatus: () => boolean;
|
|
19
|
-
}
|
|
20
|
-
];
|
|
21
|
-
export type UseTrackedStateType<T extends RequestInstance = RequestInstance> = {
|
|
22
|
-
/**
|
|
23
|
-
* Request response data
|
|
24
|
-
*/
|
|
25
|
-
data: null | ExtractResponseType<T>;
|
|
26
|
-
/**
|
|
27
|
-
* Request response error
|
|
28
|
-
*/
|
|
29
|
-
error: null | ExtractErrorType<T>;
|
|
30
|
-
/**
|
|
31
|
-
* Request loading state
|
|
32
|
-
*/
|
|
33
|
-
loading: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Request http status code
|
|
36
|
-
*/
|
|
37
|
-
status: null | number;
|
|
38
|
-
/**
|
|
39
|
-
* Request attempts
|
|
40
|
-
*/
|
|
41
|
-
retries: number;
|
|
42
|
-
/**
|
|
43
|
-
* Request response timestamp
|
|
44
|
-
*/
|
|
45
|
-
timestamp: null | Date;
|
|
46
|
-
};
|
|
47
|
-
export type UseTrackedStateActions<T extends RequestInstance> = {
|
|
48
|
-
/**
|
|
49
|
-
* Action to set custom data. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option.
|
|
50
|
-
*/
|
|
51
|
-
setData: (data: ExtractResponseType<T>, emitToCache?: boolean) => void;
|
|
52
|
-
/**
|
|
53
|
-
* Action to set custom error. We can do it locally(inside hook state) or in all hooks with 'emitToCache' option.
|
|
54
|
-
*/
|
|
55
|
-
setError: (error: ExtractErrorType<T>, emitToCache?: boolean) => void;
|
|
56
|
-
/**
|
|
57
|
-
* Action to set custom loading. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option
|
|
58
|
-
*/
|
|
59
|
-
setLoading: (loading: boolean, emitToHooks?: boolean) => void;
|
|
60
|
-
/**
|
|
61
|
-
* Action to set custom status. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option
|
|
62
|
-
*/
|
|
63
|
-
setStatus: (status: number | null, emitToCache?: boolean) => void;
|
|
64
|
-
/**
|
|
65
|
-
* Action to set custom retries count. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option
|
|
66
|
-
*/
|
|
67
|
-
setRetries: (retries: number, emitToCache?: boolean) => void;
|
|
68
|
-
/**
|
|
69
|
-
* Action to set custom timestamp. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option
|
|
70
|
-
*/
|
|
71
|
-
setTimestamp: (timestamp: Date, emitToCache?: boolean) => void;
|
|
72
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CacheValueType, NullableType, RequestInstance, ResponseType, ExtractResponseType, ExtractErrorType, Dispatcher } from "@hyper-fetch/core";
|
|
2
|
-
import { UseTrackedStateType } from "helpers";
|
|
3
|
-
export declare const getDetailsState: (state?: UseTrackedStateType<RequestInstance>, details?: ResponseDetailsType) => ResponseDetailsType;
|
|
4
|
-
export declare const isStaleCacheData: (cacheTime: number, cacheTimestamp: NullableType<Date | number>) => boolean;
|
|
5
|
-
export declare const getValidCacheData: <T extends Request<any, any, any, any, any, any, any, any, any, any, any>>(request: T, initialData: ResponseType<ExtractResponseType<T_1>, ExtractErrorType<T_1>>, cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>;
|
|
6
|
-
export declare const getTimestamp: (timestamp?: NullableType<number | Date>) => Date;
|
|
7
|
-
export declare const getInitialState: <T extends Request<any, any, any, any, any, any, any, any, any, any, any>>(initialData: ResponseType<ExtractResponseType<T>, ExtractErrorType<T>>, dispatcher: Dispatcher, request: T) => UseTrackedStateType<T>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type UseAppManagerReturnType = {
|
|
2
|
-
/**
|
|
3
|
-
* Is window focused
|
|
4
|
-
*/
|
|
5
|
-
isFocused: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Network online status
|
|
8
|
-
*/
|
|
9
|
-
isOnline: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Network state setter
|
|
12
|
-
*/
|
|
13
|
-
setOnline: (isOnline: boolean) => void;
|
|
14
|
-
/**
|
|
15
|
-
* Focus state setter
|
|
16
|
-
*/
|
|
17
|
-
setFocused: (isFocused: boolean) => void;
|
|
18
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { RequestInstance, ExtractResponseType, ExtractErrorType, CacheValueType } from "@hyper-fetch/core";
|
|
2
|
-
import { isEqual } from "utils";
|
|
3
|
-
import { OnErrorCallbackType, OnFinishedCallbackType, OnSuccessCallbackType, UseTrackedStateActions, UseTrackedStateType } from "helpers";
|
|
4
|
-
export type UseCacheOptionsType<T extends RequestInstance> = {
|
|
5
|
-
/**
|
|
6
|
-
* If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
|
|
7
|
-
*/
|
|
8
|
-
dependencyTracking?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* If cache is empty we can use placeholder data.
|
|
11
|
-
*/
|
|
12
|
-
initialData?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
|
|
13
|
-
/**
|
|
14
|
-
* Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
|
|
15
|
-
*/
|
|
16
|
-
deepCompare?: boolean | typeof isEqual;
|
|
17
|
-
};
|
|
18
|
-
export type UseCacheReturnType<T extends RequestInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & {
|
|
19
|
-
/**
|
|
20
|
-
* Helper hook listener for success response
|
|
21
|
-
*/
|
|
22
|
-
onCacheSuccess: (callback: OnSuccessCallbackType<T>) => void;
|
|
23
|
-
/**
|
|
24
|
-
* Helper hook listener for error response
|
|
25
|
-
*/
|
|
26
|
-
onCacheError: (callback: OnErrorCallbackType<T>) => void;
|
|
27
|
-
/**
|
|
28
|
-
* Helper hook listener for response
|
|
29
|
-
*/
|
|
30
|
-
onCacheChange: (callback: OnFinishedCallbackType<T>) => void;
|
|
31
|
-
/**
|
|
32
|
-
* Revalidate current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
|
|
33
|
-
*/
|
|
34
|
-
revalidate: (invalidateKey?: string | RegExp | RequestInstance) => void;
|
|
35
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { UseEmitterOptionsType } from "hooks/use-emitter";
|
|
2
|
-
export declare const useEmitter: <EmitterType extends Emitter<any, any, any>>(emitter: EmitterType, options: UseEmitterOptionsType) => {
|
|
3
|
-
emit: any;
|
|
4
|
-
reconnect: any;
|
|
5
|
-
onEvent: (callback: (emitter: EmitterType) => void) => void;
|
|
6
|
-
onOpen: (callback: VoidFunction) => void;
|
|
7
|
-
onClose: (callback: VoidFunction) => void;
|
|
8
|
-
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
9
|
-
onConnecting: (callback: VoidFunction) => void;
|
|
10
|
-
onReconnecting: (callback: (attempts: number) => void) => void;
|
|
11
|
-
onReconnectingStop: (callback: (attempts: number) => void) => void;
|
|
12
|
-
setData: (data: unknown) => void;
|
|
13
|
-
setConnected: (connected: boolean) => void;
|
|
14
|
-
setConnecting: (connecting: boolean) => void;
|
|
15
|
-
setTimestamp: (timestamp: number) => void;
|
|
16
|
-
connected: boolean;
|
|
17
|
-
connecting: boolean;
|
|
18
|
-
timestamp: number;
|
|
19
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { UseEventMessagesOptionsType } from "hooks/use-event-messages";
|
|
2
|
-
/**
|
|
3
|
-
* Allow to listen to all event messages received with sockets
|
|
4
|
-
* @param socket
|
|
5
|
-
* @param options
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare const useEventMessages: <ResponsesType>(socket: Socket<any>, options: UseEventMessagesOptionsType<ResponsesType>) => {
|
|
9
|
-
onEvent: (callback: (data: ResponsesType, event: MessageEvent<ResponsesType>) => void) => void;
|
|
10
|
-
onOpen: (callback: VoidFunction) => void;
|
|
11
|
-
onClose: (callback: VoidFunction) => void;
|
|
12
|
-
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
13
|
-
onConnecting: (callback: VoidFunction) => void;
|
|
14
|
-
onReconnecting: (callback: (attempts: number) => void) => void;
|
|
15
|
-
onReconnectingStop: (callback: (attempts: number) => void) => void;
|
|
16
|
-
setData: (data: unknown) => void;
|
|
17
|
-
setConnected: (connected: boolean) => void;
|
|
18
|
-
setConnecting: (connecting: boolean) => void;
|
|
19
|
-
setTimestamp: (timestamp: number) => void;
|
|
20
|
-
data: unknown;
|
|
21
|
-
connected: boolean;
|
|
22
|
-
connecting: boolean;
|
|
23
|
-
timestamp: number;
|
|
24
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { RequestInstance, RequiredKeys } from "@hyper-fetch/core";
|
|
2
|
-
import { UseFetchOptionsType } from "hooks/use-fetch";
|
|
3
|
-
type DefaultOptionsType = RequiredKeys<Omit<UseFetchOptionsType<RequestInstance>, "initialData">> & {
|
|
4
|
-
initialData: null;
|
|
5
|
-
};
|
|
6
|
-
export declare const useFetchDefaultOptions: DefaultOptionsType;
|
|
7
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { UseFetchOptionsType, UseFetchReturnType } from "hooks/use-fetch";
|
|
2
|
-
/**
|
|
3
|
-
* This hooks aims to retrieve data from server.
|
|
4
|
-
* @param request Request instance
|
|
5
|
-
* @param options Hook options
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare const useFetch: <T extends Request<any, any, any, any, any, any, any, any, any, any, any>>(request: T, options?: UseFetchOptionsType<T>) => UseFetchReturnType<T>;
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { RequestInstance, ExtractResponseType, ExtractErrorType, CacheValueType } from "@hyper-fetch/core";
|
|
2
|
-
import { UseRequestEventsActionsType, UseTrackedStateActions, UseTrackedStateType } from "helpers";
|
|
3
|
-
import { InvalidationKeyType } from "types";
|
|
4
|
-
import { isEqual } from "utils";
|
|
5
|
-
export type UseFetchOptionsType<T extends RequestInstance> = {
|
|
6
|
-
/**
|
|
7
|
-
* Refetch dependencies
|
|
8
|
-
*/
|
|
9
|
-
dependencies?: any[];
|
|
10
|
-
/**
|
|
11
|
-
* Disable fetching
|
|
12
|
-
*/
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
|
|
16
|
-
*/
|
|
17
|
-
dependencyTracking?: boolean;
|
|
18
|
-
/**
|
|
19
|
-
* If `true` it will refetch data in background no matter if we have it from cache.
|
|
20
|
-
*/
|
|
21
|
-
revalidateOnMount?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* If cache is empty we can use placeholder data.
|
|
24
|
-
*/
|
|
25
|
-
initialData?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
|
|
26
|
-
/**
|
|
27
|
-
* Enable/disable refresh data
|
|
28
|
-
*/
|
|
29
|
-
refresh?: boolean;
|
|
30
|
-
/**
|
|
31
|
-
* Refresh data interval time
|
|
32
|
-
*/
|
|
33
|
-
refreshTime?: number;
|
|
34
|
-
/**
|
|
35
|
-
* Enable/disable data refresh if our tab is not focused(used by user at given time).
|
|
36
|
-
*/
|
|
37
|
-
refreshBlurred?: boolean;
|
|
38
|
-
/**
|
|
39
|
-
* Enable/disable data refresh if user leaves current tab.
|
|
40
|
-
*/
|
|
41
|
-
refreshOnBlur?: boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Enable/disable data refresh if user enters current tab.
|
|
44
|
-
*/
|
|
45
|
-
refreshOnFocus?: boolean;
|
|
46
|
-
/**
|
|
47
|
-
* Enable/disable data refresh if network is restored.
|
|
48
|
-
*/
|
|
49
|
-
refreshOnReconnect?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.
|
|
52
|
-
*/
|
|
53
|
-
bounce?: boolean;
|
|
54
|
-
/**
|
|
55
|
-
* Possibility to choose between debounce and throttle approaches
|
|
56
|
-
*/
|
|
57
|
-
bounceType?: "debounce" | "throttle";
|
|
58
|
-
/**
|
|
59
|
-
* How long it should bounce requests.
|
|
60
|
-
*/
|
|
61
|
-
bounceTime?: number;
|
|
62
|
-
/**
|
|
63
|
-
* ONLY in throttle mode - options for handling last bounce event
|
|
64
|
-
*/
|
|
65
|
-
bounceTimeout?: number;
|
|
66
|
-
/**
|
|
67
|
-
* Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
|
|
68
|
-
*/
|
|
69
|
-
deepCompare?: boolean | typeof isEqual;
|
|
70
|
-
};
|
|
71
|
-
export type UseFetchReturnType<T extends RequestInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & UseRequestEventsActionsType<T> & {
|
|
72
|
-
/**
|
|
73
|
-
* Data related to current state of the bounce usage
|
|
74
|
-
*/
|
|
75
|
-
bounce: {
|
|
76
|
-
/**
|
|
77
|
-
* Active state of the bounce method
|
|
78
|
-
*/
|
|
79
|
-
active: boolean;
|
|
80
|
-
/**
|
|
81
|
-
* Method to stop the active bounce method execution
|
|
82
|
-
*/
|
|
83
|
-
reset: () => void;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Revalidate current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
|
|
87
|
-
*/
|
|
88
|
-
revalidate: (invalidateKey?: InvalidationKeyType | InvalidationKeyType[]) => void;
|
|
89
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const getRefreshTime: (refreshTime: number, dataTimestamp?: Date) => number;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ExtractListenerAdapterType } from "@hyper-fetch/sockets";
|
|
2
|
-
import { UseListenerOptionsType } from "hooks/use-listener";
|
|
3
|
-
export declare const useListener: <ListenerType extends Listener<any, any>>(listener: ListenerType, options: UseListenerOptionsType) => {
|
|
4
|
-
listen: () => void;
|
|
5
|
-
onEvent: (callback: (data: ExtractListenerAdapterType<ListenerType>, event: MessageEvent<ExtractListenerAdapterType<ListenerType>>) => void) => void;
|
|
6
|
-
onOpen: (callback: VoidFunction) => void;
|
|
7
|
-
onClose: (callback: VoidFunction) => void;
|
|
8
|
-
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
9
|
-
onConnecting: (callback: VoidFunction) => void;
|
|
10
|
-
onReconnecting: (callback: (attempts: number) => void) => void;
|
|
11
|
-
onReconnectingStop: (callback: (attempts: number) => void) => void;
|
|
12
|
-
setData: (data: unknown) => void;
|
|
13
|
-
setConnected: (connected: boolean) => void;
|
|
14
|
-
setConnecting: (connecting: boolean) => void;
|
|
15
|
-
setTimestamp: (timestamp: number) => void;
|
|
16
|
-
data: unknown;
|
|
17
|
-
connected: boolean;
|
|
18
|
-
connecting: boolean;
|
|
19
|
-
timestamp: number;
|
|
20
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { UseQueueOptionsType, UseQueueReturnType } from "hooks/use-queue";
|
|
2
|
-
/**
|
|
3
|
-
* This hook allows to control dispatchers request queues
|
|
4
|
-
* @param request
|
|
5
|
-
* @param options
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare const useQueue: <Request_1 extends Request<any, any, any, any, any, any, any, any, any, any, any>>(request: Request_1, options?: UseQueueOptionsType) => UseQueueReturnType<Request_1>;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ProgressType, RequestInstance, DispatcherStorageValueType } from "@hyper-fetch/core";
|
|
2
|
-
export type UseQueueOptionsType = {
|
|
3
|
-
queueType?: "auto" | "fetch" | "submit";
|
|
4
|
-
};
|
|
5
|
-
export type QueueRequest<Request extends RequestInstance> = DispatcherStorageValueType<Request> & {
|
|
6
|
-
/**
|
|
7
|
-
* Uploading progress for given request
|
|
8
|
-
*/
|
|
9
|
-
uploading?: ProgressType;
|
|
10
|
-
/**
|
|
11
|
-
* Downloading progress for given request
|
|
12
|
-
*/
|
|
13
|
-
downloading?: ProgressType;
|
|
14
|
-
/**
|
|
15
|
-
* Callback which allow to start previously stopped request.
|
|
16
|
-
*/
|
|
17
|
-
startRequest: () => void;
|
|
18
|
-
/**
|
|
19
|
-
* Callback which allow to stop request and cancel it if it's ongoing.
|
|
20
|
-
*/
|
|
21
|
-
stopRequest: () => void;
|
|
22
|
-
/**
|
|
23
|
-
* Removes request from the queue
|
|
24
|
-
*/
|
|
25
|
-
deleteRequest: () => void;
|
|
26
|
-
};
|
|
27
|
-
export type UseQueueReturnType<T extends RequestInstance> = {
|
|
28
|
-
/**
|
|
29
|
-
* Queue status for provided request
|
|
30
|
-
*/
|
|
31
|
-
stopped: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* List of requests for provided request
|
|
34
|
-
*/
|
|
35
|
-
requests: QueueRequest<T>[];
|
|
36
|
-
/**
|
|
37
|
-
* Callback which allow to stop queue, it will cancel ongoing requests.
|
|
38
|
-
*/
|
|
39
|
-
stop: () => void;
|
|
40
|
-
/**
|
|
41
|
-
* Callback which allow to pause queue. It will allow ongoing requests to be finished, but will stop next from being send.
|
|
42
|
-
*/
|
|
43
|
-
pause: () => void;
|
|
44
|
-
/**
|
|
45
|
-
* Callback which allow to start queue.
|
|
46
|
-
*/
|
|
47
|
-
start: () => void;
|
|
48
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { RequestInstance, RequiredKeys } from "@hyper-fetch/core";
|
|
2
|
-
import { UseSubmitOptionsType } from "./use-submit.types";
|
|
3
|
-
type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<RequestInstance>, "initialData">> & {
|
|
4
|
-
initialData: null;
|
|
5
|
-
};
|
|
6
|
-
export declare const useSubmitDefaultOptions: DefaultOptionsType;
|
|
7
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { UseSubmitOptionsType, UseSubmitReturnType } from "hooks/use-submit";
|
|
2
|
-
/**
|
|
3
|
-
* This hooks aims to mutate data on the server.
|
|
4
|
-
* @param request
|
|
5
|
-
* @param options
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare const useSubmit: <RequestType extends Request<any, any, any, any, any, any, any, any, any, any, any>>(request: RequestType, options?: UseSubmitOptionsType<RequestType>) => UseSubmitReturnType<RequestType>;
|