@hyper-fetch/react 2.0.0 → 3.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/README.md +16 -15
- package/dist/config-provider/config-provider.types.d.ts +11 -5
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/use-request-events/index.d.ts +2 -0
- package/dist/helpers/use-request-events/use-request-events.hooks.d.ts +8 -0
- package/dist/helpers/{use-command-events/use-command-events.types.d.ts → use-request-events/use-request-events.types.d.ts} +24 -24
- package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +2 -2
- package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +12 -12
- package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +4 -4
- package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +1 -1
- package/dist/hooks/use-cache/use-cache.hooks.d.ts +1 -1
- package/dist/hooks/use-cache/use-cache.types.d.ts +6 -6
- package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +2 -2
- package/dist/hooks/use-event-messages/use-event-messages.hooks.d.ts +1 -1
- package/dist/hooks/use-fetch/use-fetch.constants.d.ts +2 -2
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +2 -2
- package/dist/hooks/use-fetch/use-fetch.types.d.ts +10 -6
- package/dist/hooks/use-listener/use-listener.hooks.d.ts +3 -3
- package/dist/hooks/use-queue/use-queue.hooks.d.ts +2 -2
- package/dist/hooks/use-queue/use-queue.types.d.ts +7 -7
- package/dist/hooks/use-submit/use-submit.constants.d.ts +2 -2
- package/dist/hooks/use-submit/use-submit.hooks.d.ts +2 -2
- package/dist/hooks/use-submit/use-submit.types.d.ts +20 -16
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +4 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +4 -4
- package/dist/types/invalidation.types.d.ts +2 -2
- package/package.json +3 -3
- package/src/config-provider/config-provider.types.ts +11 -5
- package/src/helpers/index.ts +1 -1
- package/src/helpers/use-request-events/index.ts +2 -0
- package/src/helpers/{use-command-events/use-command-events.hooks.ts → use-request-events/use-request-events.hooks.ts} +56 -53
- package/src/helpers/{use-command-events/use-command-events.types.ts → use-request-events/use-request-events.types.ts} +35 -35
- package/src/helpers/use-socket-state/use-socket-state.hooks.ts +1 -1
- package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +16 -16
- package/src/helpers/use-tracked-state/use-tracked-state.types.ts +15 -15
- package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +22 -22
- package/src/hooks/use-app-manager/use-app-manager.hooks.ts +11 -11
- package/src/hooks/use-cache/use-cache.hooks.ts +13 -13
- package/src/hooks/use-cache/use-cache.types.ts +6 -6
- package/src/hooks/use-emitter/use-emitter.hooks.ts +9 -5
- package/src/hooks/use-event-messages/use-event-messages.hooks.ts +6 -2
- package/src/hooks/use-fetch/use-fetch.constants.ts +3 -2
- package/src/hooks/use-fetch/use-fetch.hooks.ts +26 -25
- package/src/hooks/use-fetch/use-fetch.types.ts +11 -7
- package/src/hooks/use-listener/use-listener.hooks.ts +9 -5
- package/src/hooks/use-queue/use-queue.hooks.ts +23 -23
- package/src/hooks/use-queue/use-queue.types.ts +7 -7
- package/src/hooks/use-submit/use-submit.constants.ts +3 -2
- package/src/hooks/use-submit/use-submit.hooks.ts +42 -41
- package/src/hooks/use-submit/use-submit.types.ts +28 -18
- package/src/index.ts +3 -0
- package/src/types/invalidation.types.ts +2 -2
- package/dist/helpers/use-command-events/index.d.ts +0 -2
- package/dist/helpers/use-command-events/use-command-events.hooks.d.ts +0 -8
- package/src/helpers/use-command-events/index.ts +0 -2
package/README.md
CHANGED
|
@@ -39,38 +39,39 @@
|
|
|
39
39
|
`optimized`, `maintainable` and `high quality solutions`. We offer many hooks for your use, thanks to which you can
|
|
40
40
|
fetch or mutate data, observe sent requests and interact with data in the cache.
|
|
41
41
|
|
|
42
|
-
## Features
|
|
42
|
+
## Key Features
|
|
43
43
|
|
|
44
|
-
🔮 **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
|
|
44
|
+
🔮 **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Basic/Setup)
|
|
45
45
|
|
|
46
|
-
🎯 **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Cancellation)
|
|
46
|
+
🎯 **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Cancellation)
|
|
47
47
|
|
|
48
|
-
✨ **Window Focus/Blur Events** -
|
|
48
|
+
✨ **Window Focus/Blur Events** -
|
|
49
|
+
[Read more](https://hyperfetch.bettertyped.com/docs/guides/React/Window%20Focus%20&%20Blur)
|
|
49
50
|
|
|
50
|
-
🚀 **Queueing** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Queueing)
|
|
51
|
+
🚀 **Queueing** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Queueing)
|
|
51
52
|
|
|
52
|
-
💎 **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/Core/Cache)
|
|
53
|
+
💎 **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Cache)
|
|
53
54
|
|
|
54
|
-
🪄 **
|
|
55
|
+
🪄 **Persistence** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Persistence)
|
|
55
56
|
|
|
56
|
-
🎊 **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Environment)
|
|
57
|
+
🎊 **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Environment)
|
|
57
58
|
|
|
58
|
-
🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Offline)
|
|
59
|
+
🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Offline)
|
|
59
60
|
|
|
60
|
-
📡 **Built-in
|
|
61
|
+
📡 **Built-in adapter** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Adapter)
|
|
61
62
|
|
|
62
|
-
🧪 **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Testing)
|
|
63
|
+
🧪 **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Testing)
|
|
63
64
|
|
|
64
|
-
🎟 **Authentication** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Authentication)
|
|
65
|
+
🎟 **Authentication** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Basic/Authentication)
|
|
65
66
|
|
|
66
|
-
💡 **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Prefetching)
|
|
67
|
+
💡 **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Prefetching)
|
|
67
68
|
|
|
68
69
|
## Sources
|
|
69
70
|
|
|
70
|
-
- #### [Installation](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Installation)
|
|
71
|
+
- #### [Installation](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Installation)
|
|
71
72
|
- #### [Docs](https://hyperfetch.bettertyped.com/docs/React/Overview)
|
|
72
73
|
- #### [API](https://hyperfetch.bettertyped.com/api/)
|
|
73
|
-
- #### [NPM](https://www.npmjs.com/package/@hyper-fetch/
|
|
74
|
+
- #### [NPM](https://www.npmjs.com/package/@hyper-fetch/react)
|
|
74
75
|
- #### [Guides](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
|
|
75
76
|
|
|
76
77
|
## Other Packages
|
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { RequestInstance } from "@hyper-fetch/core";
|
|
3
3
|
import { UseFetchOptionsType } from "hooks/use-fetch";
|
|
4
4
|
import { UseSubmitOptionsType } from "hooks/use-submit";
|
|
5
5
|
import { UseCacheOptionsType } from "hooks/use-cache";
|
|
6
6
|
import { UseQueueOptionsType } from "hooks/use-queue";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import { UseListenerOptionsType } from "hooks/use-listener";
|
|
8
|
+
import { UseEmitterOptionsType } from "hooks/use-emitter";
|
|
9
|
+
import { UseEventMessagesOptionsType } from "hooks/use-event-messages";
|
|
10
|
+
export type ConfigProviderOptionsType<SocketResponses = any> = {
|
|
11
|
+
useFetchConfig?: Partial<UseFetchOptionsType<RequestInstance>>;
|
|
12
|
+
useSubmitConfig?: Partial<UseSubmitOptionsType<RequestInstance>>;
|
|
13
|
+
useCacheConfig?: Partial<UseCacheOptionsType<RequestInstance>>;
|
|
11
14
|
useQueueConfig?: Partial<UseQueueOptionsType>;
|
|
15
|
+
useListener?: Partial<UseListenerOptionsType>;
|
|
16
|
+
useEmitter?: Partial<UseEmitterOptionsType>;
|
|
17
|
+
useEventMessages?: Partial<UseEventMessagesOptionsType<SocketResponses>>;
|
|
12
18
|
};
|
|
13
19
|
export type ConfigProviderProps = {
|
|
14
20
|
children: React.ReactNode;
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UseRequestEventsReturnType, UseRequestEventsPropsType } from "helpers";
|
|
2
|
+
/**
|
|
3
|
+
* This is helper hook that handles main Hyper-Fetch event/data flow
|
|
4
|
+
* @internal
|
|
5
|
+
* @param options
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare const useRequestEvents: <T extends Request<any, any, any, any, any, any, any, any, any, any, any>>({ request, dispatcher, logger, actions, setCacheData, }: UseRequestEventsPropsType<T>) => UseRequestEventsReturnType<T>;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { Dispatcher,
|
|
1
|
+
import { Dispatcher, ExtractErrorType, CacheValueType, ExtractResponseType, LoggerType, ProgressType, ExtractAdapterReturnType, RequestEventType, RequestInstance, ResponseDetailsType } from "@hyper-fetch/core";
|
|
2
2
|
import { UseTrackedStateActions } from "helpers";
|
|
3
|
-
export type
|
|
3
|
+
export type UseRequestEventsDataMap = {
|
|
4
4
|
unmount: VoidFunction;
|
|
5
5
|
};
|
|
6
|
-
export type
|
|
6
|
+
export type UseRequestEventsLifecycleMap = Map<string, {
|
|
7
7
|
unmount: VoidFunction;
|
|
8
8
|
}>;
|
|
9
|
-
export type
|
|
10
|
-
|
|
9
|
+
export type UseRequestEventsPropsType<T extends RequestInstance> = {
|
|
10
|
+
request: T;
|
|
11
11
|
dispatcher: Dispatcher;
|
|
12
12
|
logger: LoggerType;
|
|
13
13
|
actions: UseTrackedStateActions<T>;
|
|
14
|
-
setCacheData: (cacheData: CacheValueType<
|
|
14
|
+
setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
|
|
15
15
|
};
|
|
16
|
-
export type
|
|
16
|
+
export type UseRequestEventsActionsType<T extends RequestInstance> = {
|
|
17
17
|
/**
|
|
18
18
|
* Callback that allows canceling ongoing requests from the given queueKey.
|
|
19
19
|
*/
|
|
@@ -31,7 +31,7 @@ export type UseCommandEventsActionsType<T extends CommandInstance> = {
|
|
|
31
31
|
*/
|
|
32
32
|
onAbort: (callback: OnErrorCallbackType<T>) => void;
|
|
33
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
|
|
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
35
|
*/
|
|
36
36
|
onOfflineError: (callback: OnErrorCallbackType<T>) => void;
|
|
37
37
|
/**
|
|
@@ -47,34 +47,34 @@ export type UseCommandEventsActionsType<T extends CommandInstance> = {
|
|
|
47
47
|
*/
|
|
48
48
|
onResponseStart: (callback: OnStartCallbackType<T>) => void;
|
|
49
49
|
/**
|
|
50
|
-
* Helper hook listening on download progress ETA. We can later match given requests by their id's or
|
|
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
51
|
*/
|
|
52
52
|
onDownloadProgress: (callback: OnProgressCallbackType) => void;
|
|
53
53
|
/**
|
|
54
|
-
* Helper hook listening on upload progress ETA. We can later match given requests by their id's or
|
|
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
55
|
*/
|
|
56
56
|
onUploadProgress: (callback: OnProgressCallbackType) => void;
|
|
57
57
|
};
|
|
58
|
-
export type
|
|
59
|
-
|
|
58
|
+
export type UseRequestEventsReturnType<T extends RequestInstance> = [
|
|
59
|
+
UseRequestEventsActionsType<T>,
|
|
60
60
|
{
|
|
61
|
-
addDataListener: (
|
|
61
|
+
addDataListener: (request: RequestInstance) => VoidFunction;
|
|
62
62
|
clearDataListener: VoidFunction;
|
|
63
|
-
addLifecycleListeners: (
|
|
63
|
+
addLifecycleListeners: (request: RequestInstance, requestId?: string) => VoidFunction;
|
|
64
64
|
removeLifecycleListener: (requestId: string) => void;
|
|
65
65
|
clearLifecycleListeners: () => void;
|
|
66
66
|
}
|
|
67
67
|
];
|
|
68
|
-
export type CallbackParameters<
|
|
68
|
+
export type CallbackParameters<Request, ResponseType> = {
|
|
69
69
|
response: ResponseType;
|
|
70
|
-
details:
|
|
71
|
-
|
|
70
|
+
details: ResponseDetailsType;
|
|
71
|
+
request: Request;
|
|
72
72
|
};
|
|
73
|
-
export type OnSuccessCallbackType<
|
|
74
|
-
export type OnErrorCallbackType<
|
|
75
|
-
export type OnFinishedCallbackType<
|
|
76
|
-
export type OnStartCallbackType<
|
|
77
|
-
details:
|
|
78
|
-
|
|
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
79
|
}) => void | Promise<void>;
|
|
80
|
-
export type OnProgressCallbackType = <
|
|
80
|
+
export type OnProgressCallbackType = <Request extends RequestInstance>(progress: ProgressType, details: RequestEventType<Request>) => void | Promise<void>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { UseTrackedStateProps, UseTrackedStateReturn } from "./use-tracked-state.types";
|
|
2
2
|
/**
|
|
3
3
|
*
|
|
4
|
-
* @param
|
|
4
|
+
* @param request
|
|
5
5
|
* @param initialData
|
|
6
6
|
* @param dispatcher
|
|
7
7
|
* @param dependencies
|
|
8
8
|
* @internal
|
|
9
9
|
*/
|
|
10
|
-
export declare const useTrackedState: <T extends
|
|
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,32 +1,32 @@
|
|
|
1
|
-
import { Dispatcher,
|
|
1
|
+
import { Dispatcher, ExtractErrorType, CacheValueType, ExtractResponseType, ResponseType, RequestInstance, LoggerType } from "@hyper-fetch/core";
|
|
2
2
|
import { isEqual } from "utils";
|
|
3
|
-
export type UseTrackedStateProps<T extends
|
|
4
|
-
|
|
3
|
+
export type UseTrackedStateProps<T extends RequestInstance> = {
|
|
4
|
+
request: T;
|
|
5
5
|
logger: LoggerType;
|
|
6
|
-
initialData:
|
|
6
|
+
initialData: ResponseType<ExtractResponseType<T>, ExtractErrorType<T>> | null;
|
|
7
7
|
dispatcher: Dispatcher;
|
|
8
8
|
dependencyTracking: boolean;
|
|
9
9
|
defaultCacheEmitting?: boolean;
|
|
10
10
|
deepCompare: boolean | typeof isEqual;
|
|
11
11
|
};
|
|
12
|
-
export type UseTrackedStateReturn<T extends
|
|
12
|
+
export type UseTrackedStateReturn<T extends RequestInstance> = [
|
|
13
13
|
UseTrackedStateType<T>,
|
|
14
14
|
UseTrackedStateActions<T>,
|
|
15
15
|
{
|
|
16
16
|
setRenderKey: (renderKey: keyof UseTrackedStateType<T>) => void;
|
|
17
|
-
setCacheData: (cacheData: CacheValueType<
|
|
17
|
+
setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
|
|
18
18
|
getStaleStatus: () => boolean;
|
|
19
19
|
}
|
|
20
20
|
];
|
|
21
|
-
export type UseTrackedStateType<T extends
|
|
21
|
+
export type UseTrackedStateType<T extends RequestInstance = RequestInstance> = {
|
|
22
22
|
/**
|
|
23
23
|
* Request response data
|
|
24
24
|
*/
|
|
25
|
-
data: null |
|
|
25
|
+
data: null | ExtractResponseType<T>;
|
|
26
26
|
/**
|
|
27
27
|
* Request response error
|
|
28
28
|
*/
|
|
29
|
-
error: null |
|
|
29
|
+
error: null | ExtractErrorType<T>;
|
|
30
30
|
/**
|
|
31
31
|
* Request loading state
|
|
32
32
|
*/
|
|
@@ -44,15 +44,15 @@ export type UseTrackedStateType<T extends CommandInstance = CommandInstance> = {
|
|
|
44
44
|
*/
|
|
45
45
|
timestamp: null | Date;
|
|
46
46
|
};
|
|
47
|
-
export type UseTrackedStateActions<T extends
|
|
47
|
+
export type UseTrackedStateActions<T extends RequestInstance> = {
|
|
48
48
|
/**
|
|
49
49
|
* Action to set custom data. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option.
|
|
50
50
|
*/
|
|
51
|
-
setData: (data:
|
|
51
|
+
setData: (data: ExtractResponseType<T>, emitToCache?: boolean) => void;
|
|
52
52
|
/**
|
|
53
53
|
* Action to set custom error. We can do it locally(inside hook state) or in all hooks with 'emitToCache' option.
|
|
54
54
|
*/
|
|
55
|
-
setError: (error:
|
|
55
|
+
setError: (error: ExtractErrorType<T>, emitToCache?: boolean) => void;
|
|
56
56
|
/**
|
|
57
57
|
* Action to set custom loading. We can do it locally(inside hook state) or in cache(all related sources) with 'emitToCache' option
|
|
58
58
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CacheValueType, NullableType,
|
|
1
|
+
import { CacheValueType, NullableType, RequestInstance, ResponseType, ExtractResponseType, ExtractErrorType, Dispatcher } from "@hyper-fetch/core";
|
|
2
2
|
import { UseTrackedStateType } from "helpers";
|
|
3
|
-
export declare const getDetailsState: (state?: UseTrackedStateType<
|
|
3
|
+
export declare const getDetailsState: (state?: UseTrackedStateType<RequestInstance>, details?: ResponseDetailsType) => ResponseDetailsType;
|
|
4
4
|
export declare const isStaleCacheData: (cacheTime: number, cacheTimestamp: NullableType<Date | number>) => boolean;
|
|
5
|
-
export declare const getValidCacheData: <T extends
|
|
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
6
|
export declare const getTimestamp: (timestamp?: NullableType<number | Date>) => Date;
|
|
7
|
-
export declare const getInitialState: <T extends
|
|
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,2 +1,2 @@
|
|
|
1
1
|
import { UseAppManagerReturnType } from "hooks/use-app-manager";
|
|
2
|
-
export declare const useAppManager: <B extends
|
|
2
|
+
export declare const useAppManager: <B extends Client<any, any>>(client: B) => UseAppManagerReturnType;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { UseCacheOptionsType, UseCacheReturnType } from "hooks/use-cache";
|
|
2
|
-
export declare const useCache: <T extends
|
|
2
|
+
export declare const useCache: <T extends Request<any, any, any, any, any, any, any, any, any, any, any>>(request: T, options?: UseCacheOptionsType<T>) => UseCacheReturnType<T>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestInstance, ExtractResponseType, ExtractErrorType, CacheValueType } from "@hyper-fetch/core";
|
|
2
2
|
import { isEqual } from "utils";
|
|
3
3
|
import { OnErrorCallbackType, OnFinishedCallbackType, OnSuccessCallbackType, UseTrackedStateActions, UseTrackedStateType } from "helpers";
|
|
4
|
-
export type UseCacheOptionsType<T extends
|
|
4
|
+
export type UseCacheOptionsType<T extends RequestInstance> = {
|
|
5
5
|
/**
|
|
6
6
|
* If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
|
|
7
7
|
*/
|
|
@@ -9,13 +9,13 @@ export type UseCacheOptionsType<T extends CommandInstance> = {
|
|
|
9
9
|
/**
|
|
10
10
|
* If cache is empty we can use placeholder data.
|
|
11
11
|
*/
|
|
12
|
-
initialData?: CacheValueType<
|
|
12
|
+
initialData?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
|
|
13
13
|
/**
|
|
14
14
|
* Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
|
|
15
15
|
*/
|
|
16
16
|
deepCompare?: boolean | typeof isEqual;
|
|
17
17
|
};
|
|
18
|
-
export type UseCacheReturnType<T extends
|
|
18
|
+
export type UseCacheReturnType<T extends RequestInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & {
|
|
19
19
|
/**
|
|
20
20
|
* Helper hook listener for success response
|
|
21
21
|
*/
|
|
@@ -29,7 +29,7 @@ export type UseCacheReturnType<T extends CommandInstance> = UseTrackedStateType<
|
|
|
29
29
|
*/
|
|
30
30
|
onCacheChange: (callback: OnFinishedCallbackType<T>) => void;
|
|
31
31
|
/**
|
|
32
|
-
* Revalidate current
|
|
32
|
+
* Revalidate current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
|
|
33
33
|
*/
|
|
34
|
-
revalidate: (invalidateKey?: string | RegExp |
|
|
34
|
+
revalidate: (invalidateKey?: string | RegExp | RequestInstance) => void;
|
|
35
35
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UseEmitterOptionsType } from "hooks/use-emitter";
|
|
2
|
-
export declare const useEmitter: <EmitterType extends Emitter<any, any, any>>(emitter: EmitterType,
|
|
2
|
+
export declare const useEmitter: <EmitterType extends Emitter<any, any, any>>(emitter: EmitterType, options: UseEmitterOptionsType) => {
|
|
3
3
|
emit: any;
|
|
4
4
|
reconnect: any;
|
|
5
|
-
|
|
5
|
+
onEvent: (callback: (emitter: EmitterType) => void) => void;
|
|
6
6
|
onOpen: (callback: VoidFunction) => void;
|
|
7
7
|
onClose: (callback: VoidFunction) => void;
|
|
8
8
|
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
@@ -5,7 +5,7 @@ import { UseEventMessagesOptionsType } from "hooks/use-event-messages";
|
|
|
5
5
|
* @param options
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
|
-
export declare const useEventMessages: <ResponsesType>(socket: Socket<any>,
|
|
8
|
+
export declare const useEventMessages: <ResponsesType>(socket: Socket<any>, options: UseEventMessagesOptionsType<ResponsesType>) => {
|
|
9
9
|
onEvent: (callback: (data: ResponsesType, event: MessageEvent<ResponsesType>) => void) => void;
|
|
10
10
|
onOpen: (callback: VoidFunction) => void;
|
|
11
11
|
onClose: (callback: VoidFunction) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestInstance, RequiredKeys } from "@hyper-fetch/core";
|
|
2
2
|
import { UseFetchOptionsType } from "hooks/use-fetch";
|
|
3
|
-
type DefaultOptionsType = RequiredKeys<Omit<UseFetchOptionsType<
|
|
3
|
+
type DefaultOptionsType = RequiredKeys<Omit<UseFetchOptionsType<RequestInstance>, "initialData">> & {
|
|
4
4
|
initialData: null;
|
|
5
5
|
};
|
|
6
6
|
export declare const useFetchDefaultOptions: DefaultOptionsType;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UseFetchOptionsType, UseFetchReturnType } from "hooks/use-fetch";
|
|
2
2
|
/**
|
|
3
3
|
* This hooks aims to retrieve data from server.
|
|
4
|
-
* @param
|
|
4
|
+
* @param request Request instance
|
|
5
5
|
* @param options Hook options
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
|
-
export declare const useFetch: <T extends
|
|
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,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { RequestInstance, ExtractResponseType, ExtractErrorType, CacheValueType } from "@hyper-fetch/core";
|
|
2
|
+
import { UseRequestEventsActionsType, UseTrackedStateActions, UseTrackedStateType } from "helpers";
|
|
3
3
|
import { InvalidationKeyType } from "types";
|
|
4
4
|
import { isEqual } from "utils";
|
|
5
|
-
export type UseFetchOptionsType<T extends
|
|
5
|
+
export type UseFetchOptionsType<T extends RequestInstance> = {
|
|
6
6
|
/**
|
|
7
7
|
* Refetch dependencies
|
|
8
8
|
*/
|
|
@@ -22,7 +22,7 @@ export type UseFetchOptionsType<T extends CommandInstance> = {
|
|
|
22
22
|
/**
|
|
23
23
|
* If cache is empty we can use placeholder data.
|
|
24
24
|
*/
|
|
25
|
-
initialData?: CacheValueType<
|
|
25
|
+
initialData?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
|
|
26
26
|
/**
|
|
27
27
|
* Enable/disable refresh data
|
|
28
28
|
*/
|
|
@@ -59,12 +59,16 @@ export type UseFetchOptionsType<T extends CommandInstance> = {
|
|
|
59
59
|
* How long it should bounce requests.
|
|
60
60
|
*/
|
|
61
61
|
bounceTime?: number;
|
|
62
|
+
/**
|
|
63
|
+
* ONLY in throttle mode - options for handling last bounce event
|
|
64
|
+
*/
|
|
65
|
+
bounceTimeout?: number;
|
|
62
66
|
/**
|
|
63
67
|
* Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
|
|
64
68
|
*/
|
|
65
69
|
deepCompare?: boolean | typeof isEqual;
|
|
66
70
|
};
|
|
67
|
-
export type UseFetchReturnType<T extends
|
|
71
|
+
export type UseFetchReturnType<T extends RequestInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & UseRequestEventsActionsType<T> & {
|
|
68
72
|
/**
|
|
69
73
|
* Data related to current state of the bounce usage
|
|
70
74
|
*/
|
|
@@ -79,7 +83,7 @@ export type UseFetchReturnType<T extends CommandInstance> = UseTrackedStateType<
|
|
|
79
83
|
reset: () => void;
|
|
80
84
|
};
|
|
81
85
|
/**
|
|
82
|
-
* Revalidate current
|
|
86
|
+
* Revalidate current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
|
|
83
87
|
*/
|
|
84
88
|
revalidate: (invalidateKey?: InvalidationKeyType | InvalidationKeyType[]) => void;
|
|
85
89
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtractListenerAdapterType } from "@hyper-fetch/sockets";
|
|
2
2
|
import { UseListenerOptionsType } from "hooks/use-listener";
|
|
3
|
-
export declare const useListener: <ListenerType extends Listener<any, any>>(listener: ListenerType,
|
|
3
|
+
export declare const useListener: <ListenerType extends Listener<any, any>>(listener: ListenerType, options: UseListenerOptionsType) => {
|
|
4
4
|
listen: () => void;
|
|
5
|
-
onEvent: (callback: (data:
|
|
5
|
+
onEvent: (callback: (data: ExtractListenerAdapterType<ListenerType>, event: MessageEvent<ExtractListenerAdapterType<ListenerType>>) => void) => void;
|
|
6
6
|
onOpen: (callback: VoidFunction) => void;
|
|
7
7
|
onClose: (callback: VoidFunction) => void;
|
|
8
8
|
onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UseQueueOptionsType, UseQueueReturnType } from "hooks/use-queue";
|
|
2
2
|
/**
|
|
3
3
|
* This hook allows to control dispatchers request queues
|
|
4
|
-
* @param
|
|
4
|
+
* @param request
|
|
5
5
|
* @param options
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
|
-
export declare const useQueue: <
|
|
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,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProgressType, RequestInstance, DispatcherStorageValueType } from "@hyper-fetch/core";
|
|
2
2
|
export type UseQueueOptionsType = {
|
|
3
3
|
queueType?: "auto" | "fetch" | "submit";
|
|
4
4
|
};
|
|
5
|
-
export type QueueRequest<
|
|
5
|
+
export type QueueRequest<Request extends RequestInstance> = DispatcherStorageValueType<Request> & {
|
|
6
6
|
/**
|
|
7
7
|
* Uploading progress for given request
|
|
8
8
|
*/
|
|
9
|
-
uploading?:
|
|
9
|
+
uploading?: ProgressType;
|
|
10
10
|
/**
|
|
11
11
|
* Downloading progress for given request
|
|
12
12
|
*/
|
|
13
|
-
downloading?:
|
|
13
|
+
downloading?: ProgressType;
|
|
14
14
|
/**
|
|
15
15
|
* Callback which allow to start previously stopped request.
|
|
16
16
|
*/
|
|
@@ -24,13 +24,13 @@ export type QueueRequest<Command extends CommandInstance> = DispatcherDumpValueT
|
|
|
24
24
|
*/
|
|
25
25
|
deleteRequest: () => void;
|
|
26
26
|
};
|
|
27
|
-
export type UseQueueReturnType<T extends
|
|
27
|
+
export type UseQueueReturnType<T extends RequestInstance> = {
|
|
28
28
|
/**
|
|
29
|
-
* Queue status for provided
|
|
29
|
+
* Queue status for provided request
|
|
30
30
|
*/
|
|
31
31
|
stopped: boolean;
|
|
32
32
|
/**
|
|
33
|
-
* List of requests for provided
|
|
33
|
+
* List of requests for provided request
|
|
34
34
|
*/
|
|
35
35
|
requests: QueueRequest<T>[];
|
|
36
36
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestInstance, RequiredKeys } from "@hyper-fetch/core";
|
|
2
2
|
import { UseSubmitOptionsType } from "./use-submit.types";
|
|
3
|
-
type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<
|
|
3
|
+
type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<RequestInstance>, "initialData">> & {
|
|
4
4
|
initialData: null;
|
|
5
5
|
};
|
|
6
6
|
export declare const useSubmitDefaultOptions: DefaultOptionsType;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UseSubmitOptionsType, UseSubmitReturnType } from "hooks/use-submit";
|
|
2
2
|
/**
|
|
3
3
|
* This hooks aims to mutate data on the server.
|
|
4
|
-
* @param
|
|
4
|
+
* @param request
|
|
5
5
|
* @param options
|
|
6
6
|
* @returns
|
|
7
7
|
*/
|
|
8
|
-
export declare const useSubmit: <
|
|
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>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { CacheValueType,
|
|
1
|
+
import { CacheValueType, ExtractErrorType, ExtractResponseType, RequestInstance, RequestSendType } from "@hyper-fetch/core";
|
|
2
2
|
import { isEqual } from "utils";
|
|
3
3
|
import { OnErrorCallbackType, OnFinishedCallbackType, OnProgressCallbackType, OnStartCallbackType, OnSuccessCallbackType, UseTrackedStateType, UseTrackedStateActions } from "helpers";
|
|
4
4
|
import { InvalidationKeyType } from "types";
|
|
5
|
-
export type UseSubmitOptionsType<T extends
|
|
5
|
+
export type UseSubmitOptionsType<T extends RequestInstance> = {
|
|
6
6
|
/**
|
|
7
7
|
* Disable fetching
|
|
8
8
|
*/
|
|
@@ -10,7 +10,7 @@ export type UseSubmitOptionsType<T extends CommandInstance> = {
|
|
|
10
10
|
/**
|
|
11
11
|
* If cache is empty we can use placeholder data.
|
|
12
12
|
*/
|
|
13
|
-
initialData?: CacheValueType<
|
|
13
|
+
initialData?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
|
|
14
14
|
/**
|
|
15
15
|
* Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.
|
|
16
16
|
*/
|
|
@@ -23,6 +23,10 @@ export type UseSubmitOptionsType<T extends CommandInstance> = {
|
|
|
23
23
|
* How long it should bounce requests.
|
|
24
24
|
*/
|
|
25
25
|
bounceTime?: number;
|
|
26
|
+
/**
|
|
27
|
+
* ONLY in throttle mode - options for handling last bounce event
|
|
28
|
+
*/
|
|
29
|
+
bounceTimeout?: number;
|
|
26
30
|
/**
|
|
27
31
|
* If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
|
|
28
32
|
*/
|
|
@@ -32,7 +36,7 @@ export type UseSubmitOptionsType<T extends CommandInstance> = {
|
|
|
32
36
|
*/
|
|
33
37
|
deepCompare?: boolean | typeof isEqual;
|
|
34
38
|
};
|
|
35
|
-
export type UseSubmitReturnType<
|
|
39
|
+
export type UseSubmitReturnType<RequestType extends RequestInstance> = Omit<UseTrackedStateType<RequestType>, "loading"> & UseTrackedStateActions<RequestType> & {
|
|
36
40
|
/**
|
|
37
41
|
* Callback which allows to cancel ongoing requests from given queueKey.
|
|
38
42
|
*/
|
|
@@ -40,43 +44,43 @@ export type UseSubmitReturnType<CommandType extends CommandInstance> = Omit<UseT
|
|
|
40
44
|
/**
|
|
41
45
|
* Helper hook listening on success response.
|
|
42
46
|
*/
|
|
43
|
-
onSubmitSuccess: (callback: OnSuccessCallbackType<
|
|
47
|
+
onSubmitSuccess: (callback: OnSuccessCallbackType<RequestType>) => void;
|
|
44
48
|
/**
|
|
45
49
|
* Helper hook listening on error response.
|
|
46
50
|
*/
|
|
47
|
-
onSubmitError: (callback: OnErrorCallbackType<
|
|
51
|
+
onSubmitError: (callback: OnErrorCallbackType<RequestType>) => void;
|
|
48
52
|
/**
|
|
49
53
|
* Helper hook listening on any response.
|
|
50
54
|
*/
|
|
51
|
-
onSubmitFinished: (callback: OnFinishedCallbackType<
|
|
55
|
+
onSubmitFinished: (callback: OnFinishedCallbackType<RequestType>) => void;
|
|
52
56
|
/**
|
|
53
57
|
* Helper hook listening on request start.
|
|
54
58
|
*/
|
|
55
|
-
onSubmitRequestStart: (callback: OnStartCallbackType<
|
|
59
|
+
onSubmitRequestStart: (callback: OnStartCallbackType<RequestType>) => void;
|
|
56
60
|
/**
|
|
57
61
|
* Helper hook listening on response start(before we receive all data from server).
|
|
58
62
|
*/
|
|
59
|
-
onSubmitResponseStart: (callback: OnStartCallbackType<
|
|
63
|
+
onSubmitResponseStart: (callback: OnStartCallbackType<RequestType>) => void;
|
|
60
64
|
/**
|
|
61
|
-
* Helper hook listening on download progress ETA. We can later match given requests by their id's or
|
|
65
|
+
* 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.
|
|
62
66
|
*/
|
|
63
67
|
onSubmitDownloadProgress: (callback: OnProgressCallbackType) => void;
|
|
64
68
|
/**
|
|
65
|
-
* Helper hook listening on upload progress ETA. We can later match given requests by their id's or
|
|
69
|
+
* 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.
|
|
66
70
|
*/
|
|
67
71
|
onSubmitUploadProgress: (callback: OnProgressCallbackType) => void;
|
|
68
72
|
/**
|
|
69
73
|
* Helper hook listening on aborting of requests. Abort events are not triggering onError callbacks.
|
|
70
74
|
*/
|
|
71
|
-
onSubmitAbort: (callback: OnErrorCallbackType<
|
|
75
|
+
onSubmitAbort: (callback: OnErrorCallbackType<RequestType>) => void;
|
|
72
76
|
/**
|
|
73
|
-
* 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
|
|
77
|
+
* 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.
|
|
74
78
|
*/
|
|
75
|
-
onSubmitOfflineError: (callback: OnErrorCallbackType<
|
|
79
|
+
onSubmitOfflineError: (callback: OnErrorCallbackType<RequestType>) => void;
|
|
76
80
|
/**
|
|
77
81
|
* Method responsible for triggering requests. It return Promise which will be resolved with the request.
|
|
78
82
|
*/
|
|
79
|
-
submit:
|
|
83
|
+
submit: RequestSendType<RequestType>;
|
|
80
84
|
/**
|
|
81
85
|
* Request loading state
|
|
82
86
|
*/
|
|
@@ -95,7 +99,7 @@ export type UseSubmitReturnType<CommandType extends CommandInstance> = Omit<UseT
|
|
|
95
99
|
reset: () => void;
|
|
96
100
|
};
|
|
97
101
|
/**
|
|
98
|
-
* Revalidate current
|
|
102
|
+
* Revalidate current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
|
|
99
103
|
*/
|
|
100
104
|
revalidate: (invalidateKey: InvalidationKeyType | InvalidationKeyType[]) => void;
|
|
101
105
|
};
|