@hyper-fetch/react 2.1.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +1 -1
  2. package/dist/config-provider/config-provider.types.d.ts +11 -5
  3. package/dist/helpers/index.d.ts +1 -1
  4. package/dist/helpers/use-request-events/index.d.ts +2 -0
  5. package/dist/helpers/use-request-events/use-request-events.hooks.d.ts +8 -0
  6. package/dist/helpers/{use-command-events/use-command-events.types.d.ts → use-request-events/use-request-events.types.d.ts} +24 -24
  7. package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +2 -2
  8. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +12 -12
  9. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +4 -4
  10. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +1 -1
  11. package/dist/hooks/use-cache/use-cache.hooks.d.ts +1 -1
  12. package/dist/hooks/use-cache/use-cache.types.d.ts +6 -6
  13. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +1 -1
  14. package/dist/hooks/use-event-messages/use-event-messages.hooks.d.ts +1 -1
  15. package/dist/hooks/use-fetch/use-fetch.constants.d.ts +2 -2
  16. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +2 -2
  17. package/dist/hooks/use-fetch/use-fetch.types.d.ts +10 -6
  18. package/dist/hooks/use-listener/use-listener.hooks.d.ts +3 -3
  19. package/dist/hooks/use-queue/use-queue.hooks.d.ts +2 -2
  20. package/dist/hooks/use-queue/use-queue.types.d.ts +7 -7
  21. package/dist/hooks/use-submit/use-submit.constants.d.ts +2 -2
  22. package/dist/hooks/use-submit/use-submit.hooks.d.ts +2 -2
  23. package/dist/hooks/use-submit/use-submit.types.d.ts +20 -16
  24. package/dist/index.cjs.js +1 -1
  25. package/dist/index.cjs.js.map +4 -4
  26. package/dist/index.esm.js +1 -1
  27. package/dist/index.esm.js.map +4 -4
  28. package/dist/types/invalidation.types.d.ts +2 -2
  29. package/package.json +3 -3
  30. package/src/config-provider/config-provider.types.ts +11 -5
  31. package/src/helpers/index.ts +1 -1
  32. package/src/helpers/use-request-events/index.ts +2 -0
  33. package/src/helpers/{use-command-events/use-command-events.hooks.ts → use-request-events/use-request-events.hooks.ts} +56 -53
  34. package/src/helpers/{use-command-events/use-command-events.types.ts → use-request-events/use-request-events.types.ts} +35 -35
  35. package/src/helpers/use-socket-state/use-socket-state.hooks.ts +1 -1
  36. package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +16 -16
  37. package/src/helpers/use-tracked-state/use-tracked-state.types.ts +15 -15
  38. package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +22 -22
  39. package/src/hooks/use-app-manager/use-app-manager.hooks.ts +11 -11
  40. package/src/hooks/use-cache/use-cache.hooks.ts +13 -13
  41. package/src/hooks/use-cache/use-cache.types.ts +6 -6
  42. package/src/hooks/use-emitter/use-emitter.hooks.ts +5 -1
  43. package/src/hooks/use-event-messages/use-event-messages.hooks.ts +6 -2
  44. package/src/hooks/use-fetch/use-fetch.constants.ts +3 -2
  45. package/src/hooks/use-fetch/use-fetch.hooks.ts +26 -25
  46. package/src/hooks/use-fetch/use-fetch.types.ts +11 -7
  47. package/src/hooks/use-listener/use-listener.hooks.ts +9 -5
  48. package/src/hooks/use-queue/use-queue.hooks.ts +23 -23
  49. package/src/hooks/use-queue/use-queue.types.ts +7 -7
  50. package/src/hooks/use-submit/use-submit.constants.ts +3 -2
  51. package/src/hooks/use-submit/use-submit.hooks.ts +42 -41
  52. package/src/hooks/use-submit/use-submit.types.ts +28 -18
  53. package/src/types/invalidation.types.ts +2 -2
  54. package/dist/helpers/use-command-events/index.d.ts +0 -2
  55. package/dist/helpers/use-command-events/use-command-events.hooks.d.ts +0 -8
  56. package/src/helpers/use-command-events/index.ts +0 -2
package/README.md CHANGED
@@ -58,7 +58,7 @@ fetch or mutate data, observe sent requests and interact with data in the cache.
58
58
 
59
59
  🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Offline)
60
60
 
61
- 📡 **Built-in client** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Client)
61
+ 📡 **Built-in adapter** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Adapter)
62
62
 
63
63
  🧪 **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Testing)
64
64
 
@@ -1,14 +1,20 @@
1
1
  import React from "react";
2
- import { CommandInstance } from "@hyper-fetch/core";
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
- export type ConfigProviderOptionsType = {
8
- useFetchConfig?: Partial<UseFetchOptionsType<CommandInstance>>;
9
- useSubmitConfig?: Partial<UseSubmitOptionsType<CommandInstance>>;
10
- useCacheConfig?: Partial<UseCacheOptionsType<CommandInstance>>;
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;
@@ -1,3 +1,3 @@
1
- export * from "./use-command-events";
1
+ export * from "./use-request-events";
2
2
  export * from "./use-tracked-state";
3
3
  export * from "./use-socket-state";
@@ -0,0 +1,2 @@
1
+ export * from "./use-request-events.hooks";
2
+ export * from "./use-request-events.types";
@@ -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, ExtractError, CacheValueType, ExtractResponse, LoggerType, FetchProgressType, ExtractClientReturnType, CommandEventDetails, CommandInstance, CommandResponseDetails } from "@hyper-fetch/core";
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 UseCommandEventsDataMap = {
3
+ export type UseRequestEventsDataMap = {
4
4
  unmount: VoidFunction;
5
5
  };
6
- export type UseCommandEventsLifecycleMap = Map<string, {
6
+ export type UseRequestEventsLifecycleMap = Map<string, {
7
7
  unmount: VoidFunction;
8
8
  }>;
9
- export type UseCommandEventsPropsType<T extends CommandInstance> = {
10
- command: T;
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<ExtractResponse<T>, ExtractError<T>>) => void;
14
+ setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
15
15
  };
16
- export type UseCommandEventsActionsType<T extends CommandInstance> = {
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 command.
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 command instance which holds all data which is being transferred.
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 command instance which holds all data which is being transferred.
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 UseCommandEventsReturnType<T extends CommandInstance> = [
59
- UseCommandEventsActionsType<T>,
58
+ export type UseRequestEventsReturnType<T extends RequestInstance> = [
59
+ UseRequestEventsActionsType<T>,
60
60
  {
61
- addDataListener: (command: CommandInstance) => VoidFunction;
61
+ addDataListener: (request: RequestInstance) => VoidFunction;
62
62
  clearDataListener: VoidFunction;
63
- addLifecycleListeners: (command: CommandInstance, requestId?: string) => VoidFunction;
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<Command, ResponseType> = {
68
+ export type CallbackParameters<Request, ResponseType> = {
69
69
  response: ResponseType;
70
- details: CommandResponseDetails;
71
- command: Command;
70
+ details: ResponseDetailsType;
71
+ request: Request;
72
72
  };
73
- export type OnSuccessCallbackType<Command extends CommandInstance> = (params: CallbackParameters<Command, ExtractResponse<Command>>) => void | Promise<void>;
74
- export type OnErrorCallbackType<Command extends CommandInstance> = (params: CallbackParameters<Command, ExtractError<Command>>) => void | Promise<void>;
75
- export type OnFinishedCallbackType<Command extends CommandInstance> = (params: CallbackParameters<Command, ExtractClientReturnType<Command>>) => void | Promise<void>;
76
- export type OnStartCallbackType<Command extends CommandInstance> = (params: {
77
- details: CommandEventDetails<Command>;
78
- command: Command;
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 = <Command extends CommandInstance>(progress: FetchProgressType, details: CommandEventDetails<Command>) => void | Promise<void>;
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 command
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 Command<any, any, any, any, any, any, any, any, any, any, any>>({ command, dispatcher, initialData, deepCompare, dependencyTracking, defaultCacheEmitting, }: UseTrackedStateProps<T>) => UseTrackedStateReturn<T>;
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, ExtractError, CacheValueType, ExtractResponse, ClientResponseType, CommandInstance, LoggerType } from "@hyper-fetch/core";
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 CommandInstance> = {
4
- command: T;
3
+ export type UseTrackedStateProps<T extends RequestInstance> = {
4
+ request: T;
5
5
  logger: LoggerType;
6
- initialData: ClientResponseType<ExtractResponse<T>, ExtractError<T>> | null;
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 CommandInstance> = [
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<ExtractResponse<T>, ExtractError<T>>) => void;
17
+ setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
18
18
  getStaleStatus: () => boolean;
19
19
  }
20
20
  ];
21
- export type UseTrackedStateType<T extends CommandInstance = CommandInstance> = {
21
+ export type UseTrackedStateType<T extends RequestInstance = RequestInstance> = {
22
22
  /**
23
23
  * Request response data
24
24
  */
25
- data: null | ExtractResponse<T>;
25
+ data: null | ExtractResponseType<T>;
26
26
  /**
27
27
  * Request response error
28
28
  */
29
- error: null | ExtractError<T>;
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 CommandInstance> = {
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: ExtractResponse<T>, emitToCache?: boolean) => void;
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: ExtractError<T>, emitToCache?: boolean) => void;
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, CommandInstance, ClientResponseType, ExtractResponse, ExtractError, Dispatcher } from "@hyper-fetch/core";
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<CommandInstance>, details?: CommandResponseDetails) => CommandResponseDetails;
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 Command<any, any, any, any, any, any, any, any, any, any, any>>(command: T, initialData: ClientResponseType<ExtractResponse<T_1>, ExtractError<T_1>>, cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => CacheValueType<ExtractResponse<T>, ExtractError<T>>;
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 Command<any, any, any, any, any, any, any, any, any, any, any>>(initialData: ClientResponseType<ExtractResponse<T>, ExtractError<T>>, dispatcher: Dispatcher, command: T) => UseTrackedStateType<T>;
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 Builder<any, any>>(builder: B) => UseAppManagerReturnType;
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 Command<any, any, any, any, any, any, any, any, any, any, any>>(command: T, options?: UseCacheOptionsType<T>) => UseCacheReturnType<T>;
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 { CommandInstance, ExtractResponse, ExtractError, CacheValueType } from "@hyper-fetch/core";
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 CommandInstance> = {
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<ExtractResponse<T>, ExtractError<T>>["data"] | null;
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 CommandInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & {
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 command resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
32
+ * Revalidate current request resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
33
33
  */
34
- revalidate: (invalidateKey?: string | RegExp | CommandInstance) => void;
34
+ revalidate: (invalidateKey?: string | RegExp | RequestInstance) => void;
35
35
  };
@@ -1,5 +1,5 @@
1
1
  import { UseEmitterOptionsType } from "hooks/use-emitter";
2
- export declare const useEmitter: <EmitterType extends Emitter<any, any, any>>(emitter: EmitterType, { dependencyTracking }: UseEmitterOptionsType) => {
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;
@@ -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>, { dependencyTracking, filter }: UseEventMessagesOptionsType<ResponsesType>) => {
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 { CommandInstance, RequiredKeys } from "@hyper-fetch/core";
1
+ import { RequestInstance, RequiredKeys } from "@hyper-fetch/core";
2
2
  import { UseFetchOptionsType } from "hooks/use-fetch";
3
- type DefaultOptionsType = RequiredKeys<Omit<UseFetchOptionsType<CommandInstance>, "initialData">> & {
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 command Command instance
4
+ * @param request Request instance
5
5
  * @param options Hook options
6
6
  * @returns
7
7
  */
8
- export declare const useFetch: <T extends Command<any, any, any, any, any, any, any, any, any, any, any>>(command: T, options?: UseFetchOptionsType<T>) => UseFetchReturnType<T>;
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 { CommandInstance, ExtractResponse, ExtractError, CacheValueType } from "@hyper-fetch/core";
2
- import { UseCommandEventsActionsType, UseTrackedStateActions, UseTrackedStateType } from "helpers";
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 CommandInstance> = {
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<ExtractResponse<T>, ExtractError<T>>["data"] | null;
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 CommandInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & UseCommandEventsActionsType<T> & {
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 command resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
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 { ExtractListenerDataType } from "@hyper-fetch/sockets";
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, { dependencyTracking }: UseListenerOptionsType) => {
3
+ export declare const useListener: <ListenerType extends Listener<any, any>>(listener: ListenerType, options: UseListenerOptionsType) => {
4
4
  listen: () => void;
5
- onEvent: (callback: (data: ExtractListenerDataType<ListenerType>, event: MessageEvent<ExtractListenerDataType<ListenerType>>) => void) => void;
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 command
4
+ * @param request
5
5
  * @param options
6
6
  * @returns
7
7
  */
8
- export declare const useQueue: <Command extends Command<any, any, any, any, any, any, any, any, any, any, any>>(command: Command, options?: UseQueueOptionsType) => UseQueueReturnType<Command>;
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 { FetchProgressType, CommandInstance, DispatcherDumpValueType } from "@hyper-fetch/core";
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<Command extends CommandInstance> = DispatcherDumpValueType<Command> & {
5
+ export type QueueRequest<Request extends RequestInstance> = DispatcherStorageValueType<Request> & {
6
6
  /**
7
7
  * Uploading progress for given request
8
8
  */
9
- uploading?: FetchProgressType;
9
+ uploading?: ProgressType;
10
10
  /**
11
11
  * Downloading progress for given request
12
12
  */
13
- downloading?: FetchProgressType;
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 CommandInstance> = {
27
+ export type UseQueueReturnType<T extends RequestInstance> = {
28
28
  /**
29
- * Queue status for provided command
29
+ * Queue status for provided request
30
30
  */
31
31
  stopped: boolean;
32
32
  /**
33
- * List of requests for provided command
33
+ * List of requests for provided request
34
34
  */
35
35
  requests: QueueRequest<T>[];
36
36
  /**
@@ -1,6 +1,6 @@
1
- import { CommandInstance, RequiredKeys } from "@hyper-fetch/core";
1
+ import { RequestInstance, RequiredKeys } from "@hyper-fetch/core";
2
2
  import { UseSubmitOptionsType } from "./use-submit.types";
3
- type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<CommandInstance>, "initialData">> & {
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 command
4
+ * @param request
5
5
  * @param options
6
6
  * @returns
7
7
  */
8
- export declare const useSubmit: <CommandType extends Command<any, any, any, any, any, any, any, any, any, any, any>>(command: CommandType, options?: UseSubmitOptionsType<CommandType>) => UseSubmitReturnType<CommandType>;
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, ExtractError, ExtractResponse, CommandInstance, FetchMethodType } from "@hyper-fetch/core";
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 CommandInstance> = {
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<ExtractResponse<T>, ExtractError<T>>["data"] | null;
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<CommandType extends CommandInstance> = Omit<UseTrackedStateType<CommandType>, "loading"> & UseTrackedStateActions<CommandType> & {
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<CommandType>) => void;
47
+ onSubmitSuccess: (callback: OnSuccessCallbackType<RequestType>) => void;
44
48
  /**
45
49
  * Helper hook listening on error response.
46
50
  */
47
- onSubmitError: (callback: OnErrorCallbackType<CommandType>) => void;
51
+ onSubmitError: (callback: OnErrorCallbackType<RequestType>) => void;
48
52
  /**
49
53
  * Helper hook listening on any response.
50
54
  */
51
- onSubmitFinished: (callback: OnFinishedCallbackType<CommandType>) => void;
55
+ onSubmitFinished: (callback: OnFinishedCallbackType<RequestType>) => void;
52
56
  /**
53
57
  * Helper hook listening on request start.
54
58
  */
55
- onSubmitRequestStart: (callback: OnStartCallbackType<CommandType>) => void;
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<CommandType>) => void;
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 command instance which holds all data which is being transferred.
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 command instance which holds all data which is being transferred.
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<CommandType>) => void;
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 command.
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<CommandType>) => void;
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: FetchMethodType<CommandType>;
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 command resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
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
  };