@hyper-fetch/react 3.1.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.
Files changed (61) hide show
  1. package/.eslintrc.json +1 -2
  2. package/README.md +15 -15
  3. package/dist/index.cjs.js +1 -1
  4. package/dist/index.cjs.js.map +3 -3
  5. package/dist/index.d.ts +674 -11
  6. package/dist/index.esm.js +1 -1
  7. package/dist/index.esm.js.map +3 -3
  8. package/package.json +2 -2
  9. package/src/hooks/use-event-messages/use-event-messages.hooks.ts +2 -2
  10. package/src/hooks/use-fetch/use-fetch.hooks.ts +5 -5
  11. package/src/index.ts +1 -0
  12. package/dist/config-provider/config-provider.d.ts +0 -13
  13. package/dist/config-provider/config-provider.types.d.ts +0 -23
  14. package/dist/config-provider/index.d.ts +0 -2
  15. package/dist/helpers/index.d.ts +0 -3
  16. package/dist/helpers/use-request-events/index.d.ts +0 -2
  17. package/dist/helpers/use-request-events/use-request-events.hooks.d.ts +0 -8
  18. package/dist/helpers/use-request-events/use-request-events.types.d.ts +0 -80
  19. package/dist/helpers/use-socket-state/index.d.ts +0 -3
  20. package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts +0 -2
  21. package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts +0 -16
  22. package/dist/helpers/use-socket-state/use-socket-state.types.d.ts +0 -9
  23. package/dist/helpers/use-tracked-state/index.d.ts +0 -4
  24. package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts +0 -2
  25. package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +0 -10
  26. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +0 -72
  27. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +0 -7
  28. package/dist/hooks/use-app-manager/index.d.ts +0 -2
  29. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +0 -2
  30. package/dist/hooks/use-app-manager/use-app-manager.types.d.ts +0 -18
  31. package/dist/hooks/use-cache/index.d.ts +0 -3
  32. package/dist/hooks/use-cache/use-cache.constants.d.ts +0 -5
  33. package/dist/hooks/use-cache/use-cache.hooks.d.ts +0 -2
  34. package/dist/hooks/use-cache/use-cache.types.d.ts +0 -35
  35. package/dist/hooks/use-emitter/index.d.ts +0 -2
  36. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +0 -19
  37. package/dist/hooks/use-emitter/use-emitter.types.d.ts +0 -3
  38. package/dist/hooks/use-event-messages/index.d.ts +0 -2
  39. package/dist/hooks/use-event-messages/use-event-messages.hooks.d.ts +0 -24
  40. package/dist/hooks/use-event-messages/use-event-messages.types.d.ts +0 -4
  41. package/dist/hooks/use-fetch/index.d.ts +0 -4
  42. package/dist/hooks/use-fetch/use-fetch.constants.d.ts +0 -7
  43. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +0 -8
  44. package/dist/hooks/use-fetch/use-fetch.types.d.ts +0 -89
  45. package/dist/hooks/use-fetch/use-fetch.utils.d.ts +0 -1
  46. package/dist/hooks/use-listener/index.d.ts +0 -2
  47. package/dist/hooks/use-listener/use-listener.hooks.d.ts +0 -20
  48. package/dist/hooks/use-listener/use-listener.types.d.ts +0 -3
  49. package/dist/hooks/use-queue/index.d.ts +0 -3
  50. package/dist/hooks/use-queue/use-queue.constants.d.ts +0 -3
  51. package/dist/hooks/use-queue/use-queue.hooks.d.ts +0 -8
  52. package/dist/hooks/use-queue/use-queue.types.d.ts +0 -48
  53. package/dist/hooks/use-submit/index.d.ts +0 -3
  54. package/dist/hooks/use-submit/use-submit.constants.d.ts +0 -7
  55. package/dist/hooks/use-submit/use-submit.hooks.d.ts +0 -8
  56. package/dist/hooks/use-submit/use-submit.types.d.ts +0 -105
  57. package/dist/types/index.d.ts +0 -1
  58. package/dist/types/invalidation.types.d.ts +0 -2
  59. package/dist/utils/bounce.utils.d.ts +0 -7
  60. package/dist/utils/deep-equal.utils.d.ts +0 -13
  61. package/dist/utils/index.d.ts +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyper-fetch/react",
3
- "version": "3.1.0",
3
+ "version": "3.2.1",
4
4
  "private": false,
5
5
  "description": "React hooks and utils for the hyper-fetch",
6
6
  "author": "Maciej Pyrc <m.pyrc@interia.pl>",
@@ -17,7 +17,7 @@
17
17
  "test-pipeline": "jest --watchAll=false --maxWorkers=1 --no-cache",
18
18
  "start": "yarn build && npx run-when-changed --watch 'src/**/*.ts' --exec 'yarn build'",
19
19
  "build": "yarn clean && node ../../scripts/build.js",
20
- "postbuild": "ttsc --project tsconfig.json --outDir dist",
20
+ "postbuild": "rollup -c '../../rollup.config.js'",
21
21
  "lint": "eslint . --ext .js,.jsx,.tsx,.ts --fix",
22
22
  "format": "prettier --write .",
23
23
  "typecheck": "tsc --noEmit --emitDeclarationOnly false",
@@ -12,7 +12,7 @@ import { useConfigProvider } from "config-provider";
12
12
  * @param options
13
13
  * @returns
14
14
  */
15
- export const useEventMessages = <ResponsesType>(
15
+ export const useEventMessages = <ResponsesType extends { name: string }>(
16
16
  socket: SocketInstance,
17
17
  options: UseEventMessagesOptionsType<ResponsesType>,
18
18
  ) => {
@@ -24,7 +24,7 @@ export const useEventMessages = <ResponsesType>(
24
24
 
25
25
  useDidUpdate(
26
26
  () => {
27
- const unmountListener = socket.events.onListenerEvent((data, event) => {
27
+ const unmountListener = socket.events.onListenerEvent<ResponsesType>((data, event) => {
28
28
  const filterFn = typeof filter === "function" ? () => filter(data, event) : () => filter.includes(data.name);
29
29
  const isFiltered = filter ? filterFn() : false;
30
30
  if (!isFiltered) {
@@ -15,10 +15,10 @@ import { InvalidationKeyType } from "types";
15
15
  * @param options Hook options
16
16
  * @returns
17
17
  */
18
- export const useFetch = <T extends RequestInstance>(
19
- request: T,
20
- options: UseFetchOptionsType<T> = useFetchDefaultOptions,
21
- ): UseFetchReturnType<T> => {
18
+ export const useFetch = <RequestType extends RequestInstance>(
19
+ request: RequestType,
20
+ options: UseFetchOptionsType<RequestType> = useFetchDefaultOptions,
21
+ ): UseFetchReturnType<RequestType> => {
22
22
  // Build the configuration options
23
23
  const [globalConfig] = useConfigProvider();
24
24
  const {
@@ -59,7 +59,7 @@ export const useFetch = <T extends RequestInstance>(
59
59
  /**
60
60
  * State handler with optimization for rerendering, that hooks into the cache state and dispatchers queues
61
61
  */
62
- const [state, actions, { setRenderKey, setCacheData, getStaleStatus }] = useTrackedState<T>({
62
+ const [state, actions, { setRenderKey, setCacheData, getStaleStatus }] = useTrackedState<RequestType>({
63
63
  logger,
64
64
  request,
65
65
  dispatcher,
package/src/index.ts CHANGED
@@ -7,5 +7,6 @@ export * from "./hooks/use-emitter";
7
7
  export * from "./hooks/use-event-messages";
8
8
  export * from "./hooks/use-app-manager";
9
9
  export * from "./helpers";
10
+ export * from "./config-provider";
10
11
  export * from "./types";
11
12
  export * from "./utils";
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { ConfigProviderProps, ConfigProviderValueType } from "./config-provider.types";
3
- /**
4
- * Context provider with configuration for hooks
5
- * @param options
6
- * @returns
7
- */
8
- export declare const ConfigProvider: ({ children, config }: ConfigProviderProps) => JSX.Element;
9
- /**
10
- * Hook to allow reading current context config
11
- * @returns
12
- */
13
- export declare const useConfigProvider: () => ConfigProviderValueType;
@@ -1,23 +0,0 @@
1
- import React from "react";
2
- import { RequestInstance } from "@hyper-fetch/core";
3
- import { UseFetchOptionsType } from "hooks/use-fetch";
4
- import { UseSubmitOptionsType } from "hooks/use-submit";
5
- import { UseCacheOptionsType } from "hooks/use-cache";
6
- import { UseQueueOptionsType } from "hooks/use-queue";
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>>;
14
- useQueueConfig?: Partial<UseQueueOptionsType>;
15
- useListener?: Partial<UseListenerOptionsType>;
16
- useEmitter?: Partial<UseEmitterOptionsType>;
17
- useEventMessages?: Partial<UseEventMessagesOptionsType<SocketResponses>>;
18
- };
19
- export type ConfigProviderProps = {
20
- children: React.ReactNode;
21
- config?: ConfigProviderOptionsType;
22
- };
23
- export type ConfigProviderValueType = [ConfigProviderOptionsType, (newConfig: ConfigProviderOptionsType) => void];
@@ -1,2 +0,0 @@
1
- export * from "./config-provider";
2
- export * from "./config-provider.types";
@@ -1,3 +0,0 @@
1
- export * from "./use-request-events";
2
- export * from "./use-tracked-state";
3
- export * from "./use-socket-state";
@@ -1,2 +0,0 @@
1
- export * from "./use-request-events.hooks";
2
- export * from "./use-request-events.types";
@@ -1,8 +0,0 @@
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,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,3 +0,0 @@
1
- export * from "./use-socket-state.hooks";
2
- export * from "./use-socket-state.types";
3
- export * from "./use-socket-state.constants";
@@ -1,2 +0,0 @@
1
- import { UseSocketStateType } from "./use-socket-state.types";
2
- export declare const initialSocketState: UseSocketStateType;
@@ -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,9 +0,0 @@
1
- export type UseSocketStateType<DataType = any> = {
2
- data: DataType | null;
3
- connected: boolean;
4
- connecting: boolean;
5
- timestamp: number | null;
6
- };
7
- export type UseSocketStateProps = {
8
- dependencyTracking?: boolean;
9
- };
@@ -1,4 +0,0 @@
1
- export * from "./use-tracked-state.constants";
2
- export * from "./use-tracked-state.hooks";
3
- export * from "./use-tracked-state.types";
4
- export * from "./use-tracked-state.utils";
@@ -1,2 +0,0 @@
1
- import { UseTrackedStateType } from "./use-tracked-state.types";
2
- export declare const initialState: UseTrackedStateType;
@@ -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,2 +0,0 @@
1
- export * from "./use-app-manager.hooks";
2
- export * from "./use-app-manager.types";
@@ -1,2 +0,0 @@
1
- import { UseAppManagerReturnType } from "hooks/use-app-manager";
2
- export declare const useAppManager: <B extends Client<any, any>>(client: B) => UseAppManagerReturnType;
@@ -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,3 +0,0 @@
1
- export * from "./use-cache.hooks";
2
- export * from "./use-cache.constants";
3
- export * from "./use-cache.types";
@@ -1,5 +0,0 @@
1
- export declare const useCacheDefaultOptions: {
2
- dependencyTracking: boolean;
3
- initialData: any;
4
- deepCompare: boolean;
5
- };
@@ -1,2 +0,0 @@
1
- import { UseCacheOptionsType, UseCacheReturnType } from "hooks/use-cache";
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,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,2 +0,0 @@
1
- export * from "./use-emitter.hooks";
2
- export * from "./use-emitter.types";
@@ -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,3 +0,0 @@
1
- export type UseEmitterOptionsType = {
2
- dependencyTracking?: boolean;
3
- };
@@ -1,2 +0,0 @@
1
- export * from "./use-event-messages.hooks";
2
- export * from "./use-event-messages.types";
@@ -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,4 +0,0 @@
1
- export type UseEventMessagesOptionsType<ResponsesType> = {
2
- dependencyTracking?: boolean;
3
- filter?: ((data: ResponsesType, event: MessageEvent<ResponsesType>) => boolean) | string[];
4
- };
@@ -1,4 +0,0 @@
1
- export * from "./use-fetch.hooks";
2
- export * from "./use-fetch.types";
3
- export * from "./use-fetch.utils";
4
- export * from "./use-fetch.constants";
@@ -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,2 +0,0 @@
1
- export * from "./use-listener.hooks";
2
- export * from "./use-listener.types";
@@ -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
- };