@hyper-fetch/react 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/.eslintrc.json +7 -0
  2. package/README.md +82 -0
  3. package/dist/config-provider/config-provider.d.ts +13 -0
  4. package/dist/config-provider/config-provider.types.d.ts +17 -0
  5. package/dist/config-provider/index.d.ts +2 -0
  6. package/dist/helpers/index.d.ts +2 -0
  7. package/dist/helpers/use-command-events/index.d.ts +2 -0
  8. package/dist/helpers/use-command-events/use-command-events.hooks.d.ts +9 -0
  9. package/dist/helpers/use-command-events/use-command-events.types.d.ts +80 -0
  10. package/dist/helpers/use-tracked-state/index.d.ts +4 -0
  11. package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts +2 -0
  12. package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +11 -0
  13. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +72 -0
  14. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +7 -0
  15. package/dist/hooks/use-app-manager/index.d.ts +2 -0
  16. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +3 -0
  17. package/dist/hooks/use-app-manager/use-app-manager.types.d.ts +18 -0
  18. package/dist/hooks/use-cache/index.d.ts +3 -0
  19. package/dist/hooks/use-cache/use-cache.constants.d.ts +5 -0
  20. package/dist/hooks/use-cache/use-cache.hooks.d.ts +3 -0
  21. package/dist/hooks/use-cache/use-cache.types.d.ts +35 -0
  22. package/dist/hooks/use-fetch/index.d.ts +4 -0
  23. package/dist/hooks/use-fetch/use-fetch.constants.d.ts +7 -0
  24. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +9 -0
  25. package/dist/hooks/use-fetch/use-fetch.types.d.ts +85 -0
  26. package/dist/hooks/use-fetch/use-fetch.utils.d.ts +1 -0
  27. package/dist/hooks/use-queue/index.d.ts +3 -0
  28. package/dist/hooks/use-queue/use-queue.constants.d.ts +3 -0
  29. package/dist/hooks/use-queue/use-queue.hooks.d.ts +9 -0
  30. package/dist/hooks/use-queue/use-queue.types.d.ts +48 -0
  31. package/dist/hooks/use-submit/index.d.ts +3 -0
  32. package/dist/hooks/use-submit/use-submit.constants.d.ts +7 -0
  33. package/dist/hooks/use-submit/use-submit.hooks.d.ts +9 -0
  34. package/dist/hooks/use-submit/use-submit.types.d.ts +101 -0
  35. package/dist/index.cjs.js +2 -0
  36. package/dist/index.cjs.js.map +7 -0
  37. package/dist/index.d.ts +8 -0
  38. package/dist/index.esm.js +2 -0
  39. package/dist/index.esm.js.map +7 -0
  40. package/dist/types/index.d.ts +1 -0
  41. package/dist/types/invalidation.types.d.ts +2 -0
  42. package/dist/utils/bounce.utils.d.ts +7 -0
  43. package/dist/utils/deep-equal.utils.d.ts +13 -0
  44. package/dist/utils/index.d.ts +2 -0
  45. package/package.json +74 -0
  46. package/src/config-provider/config-provider.tsx +30 -0
  47. package/src/config-provider/config-provider.types.ts +21 -0
  48. package/src/config-provider/index.ts +2 -0
  49. package/src/helpers/index.ts +2 -0
  50. package/src/helpers/use-command-events/index.ts +2 -0
  51. package/src/helpers/use-command-events/use-command-events.hooks.ts +283 -0
  52. package/src/helpers/use-command-events/use-command-events.types.ts +108 -0
  53. package/src/helpers/use-tracked-state/index.ts +4 -0
  54. package/src/helpers/use-tracked-state/use-tracked-state.constants.ts +10 -0
  55. package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +227 -0
  56. package/src/helpers/use-tracked-state/use-tracked-state.types.ts +85 -0
  57. package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +82 -0
  58. package/src/hooks/use-app-manager/index.ts +2 -0
  59. package/src/hooks/use-app-manager/use-app-manager.hooks.ts +36 -0
  60. package/src/hooks/use-app-manager/use-app-manager.types.ts +18 -0
  61. package/src/hooks/use-cache/index.ts +3 -0
  62. package/src/hooks/use-cache/use-cache.constants.ts +5 -0
  63. package/src/hooks/use-cache/use-cache.hooks.ts +90 -0
  64. package/src/hooks/use-cache/use-cache.types.ts +45 -0
  65. package/src/hooks/use-fetch/index.ts +4 -0
  66. package/src/hooks/use-fetch/use-fetch.constants.ts +25 -0
  67. package/src/hooks/use-fetch/use-fetch.hooks.ts +265 -0
  68. package/src/hooks/use-fetch/use-fetch.types.ts +90 -0
  69. package/src/hooks/use-fetch/use-fetch.utils.ts +7 -0
  70. package/src/hooks/use-queue/index.ts +3 -0
  71. package/src/hooks/use-queue/use-queue.constants.ts +7 -0
  72. package/src/hooks/use-queue/use-queue.hooks.ts +112 -0
  73. package/src/hooks/use-queue/use-queue.types.ts +51 -0
  74. package/src/hooks/use-submit/index.ts +3 -0
  75. package/src/hooks/use-submit/use-submit.constants.ts +17 -0
  76. package/src/hooks/use-submit/use-submit.hooks.ts +219 -0
  77. package/src/hooks/use-submit/use-submit.types.ts +119 -0
  78. package/src/index.ts +8 -0
  79. package/src/types/index.ts +1 -0
  80. package/src/types/invalidation.types.ts +3 -0
  81. package/src/utils/bounce.utils.ts +9 -0
  82. package/src/utils/deep-equal.utils.ts +64 -0
  83. package/src/utils/index.ts +2 -0
  84. package/tsconfig.json +9 -0
package/.eslintrc.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": ["../../.eslintrc.json"],
3
+ "parserOptions": {
4
+ "project": ["./tsconfig.json", "./__tests__/tsconfig.json"]
5
+ },
6
+ "ignorePatterns": ["dist/"]
7
+ }
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ <h1 align="center">
2
+
3
+ ⚛️ <br /> React Hyper Fetch
4
+
5
+ </h1>
6
+
7
+ <p align="center">
8
+ <a href="https://bettertyped.com/">
9
+ <img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
10
+ </a>
11
+ <a href="https://github.com/BetterTyped/hyper-fetch">
12
+ <img src="https://custom-icon-badges.demolab.com/github/stars/BetterTyped/hyper-fetch?logo=star&color=118ab2" />
13
+ </a>
14
+ <a href="https://github.com/BetterTyped/hyper-fetch/blob/main/License.md">
15
+ <img src="https://custom-icon-badges.demolab.com/github/license/BetterTyped/hyper-fetch?logo=law&color=yellow" />
16
+ </a>
17
+ <a href="https://www.npmjs.com/package/@hyper-fetch/react">
18
+ <img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/react.svg?logo=npm&color=e76f51" />
19
+ </a>
20
+ <a href="https://api.codeclimate.com/v1/badges/eade9435e75ecea0c004/test_coverage">
21
+ <img src="https://api.codeclimate.com/v1/badges/eade9435e75ecea0c004/test_coverage" />
22
+ </a>
23
+ <a href="https://github.com/BetterTyped/hyper-fetch">
24
+ <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
25
+ </a>
26
+ <a href="https://github.com/BetterTyped/hyper-fetch">
27
+ <img src="https://custom-icon-badges.demolab.com/badge/-REST-informational?logo=rss&color=11b8cc" />
28
+ </a>
29
+ <a href="https://github.com/BetterTyped/hyper-fetch">
30
+ <img src="https://custom-icon-badges.demolab.com/badge/-GraphQL-E10098?logo=graphql&logoColor=white" />
31
+ </a>
32
+ <a href="https://gitter.im/hyper-fetch/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge">
33
+ <img src="https://custom-icon-badges.demolab.com/badge/chat%20-on%20gitter-brightgreen.svg?logo=gitter&color=blueviolet" />
34
+ </a>
35
+ <a href="https://www.npmjs.com/package/@hyper-fetch/react">
36
+ <img src="https://custom-icon-badges.demolab.com/bundlephobia/min/@hyper-fetch/react?color=64BC4B&logo=package" />
37
+ </a>
38
+ </p>
39
+
40
+ ## About
41
+
42
+ **`React Hyper Fetch`** is a set of hooks for Hyper Fetch. Combined with React's lifecycle it allow to `create modern`,
43
+ `optimized`, `maintainable` and `high quality solutions`. We offer many hooks for your use, thanks to which you can
44
+ fetch or mutate data, observe sent requests and interact with data in the cache.
45
+
46
+ ## Features
47
+
48
+ 🔮 **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
49
+
50
+ 🎯 **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Cancellation)
51
+
52
+ ✨ **Window Focus/Blur Events** - [Read more](https://hyperfetch.bettertyped.com/guides/React/Window%20Focus%20&%20Blur)
53
+
54
+ 🚀 **Queueing** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Queueing)
55
+
56
+ 💎 **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/Architecture/Cache)
57
+
58
+ 🪄 **Persistance** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Persistence)
59
+
60
+ 🎊 **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Environment)
61
+
62
+ 🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Offline)
63
+
64
+ 📡 **Built-in client** - [Read more](https://hyperfetch.bettertyped.com/docs/Architecture/Client)
65
+
66
+ 🧪 **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Testing)
67
+
68
+ 🎟 **Authentication** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Authentication)
69
+
70
+ 💡 **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Prefetching)
71
+
72
+ ## Sources
73
+
74
+ - #### [Installation](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Installation)
75
+ - #### [Docs](https://hyperfetch.bettertyped.com/docs/React/Overview)
76
+ - #### [API](https://hyperfetch.bettertyped.com/api/)
77
+ - #### [NPM](https://www.npmjs.com/package/@hyper-fetch/core)
78
+ - #### [Guides](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
79
+
80
+ ## Other Packages
81
+
82
+ - #### [Hyper Fetch](https://github.com/BetterTyped/hyper-fetch/tree/main/packages/core)
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { CommandInstance } 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
+ export declare type ConfigProviderOptionsType = {
8
+ useFetchConfig?: Partial<UseFetchOptionsType<CommandInstance>>;
9
+ useSubmitConfig?: Partial<UseSubmitOptionsType<CommandInstance>>;
10
+ useCacheConfig?: Partial<UseCacheOptionsType<CommandInstance>>;
11
+ useQueueConfig?: Partial<UseQueueOptionsType>;
12
+ };
13
+ export declare type ConfigProviderProps = {
14
+ children: React.ReactNode;
15
+ config?: ConfigProviderOptionsType;
16
+ };
17
+ export declare type ConfigProviderValueType = [ConfigProviderOptionsType, (newConfig: ConfigProviderOptionsType) => void];
@@ -0,0 +1,2 @@
1
+ export * from "./config-provider";
2
+ export * from "./config-provider.types";
@@ -0,0 +1,2 @@
1
+ export * from "./use-command-events";
2
+ export * from "./use-tracked-state";
@@ -0,0 +1,2 @@
1
+ export * from "./use-command-events.hooks";
2
+ export * from "./use-command-events.types";
@@ -0,0 +1,9 @@
1
+ import { CommandInstance } from "@hyper-fetch/core";
2
+ import { UseCommandEventsReturnType, UseCommandEventsPropsType } from "./..";
3
+ /**
4
+ * This is helper hook that handles main Hyper-Fetch event/data flow
5
+ * @internal
6
+ * @param options
7
+ * @returns
8
+ */
9
+ export declare const useCommandEvents: <T extends CommandInstance>({ command, dispatcher, logger, actions, setCacheData, }: UseCommandEventsPropsType<T>) => UseCommandEventsReturnType<T>;
@@ -0,0 +1,80 @@
1
+ import { Dispatcher, ExtractError, CacheValueType, ExtractResponse, LoggerType, FetchProgressType, ExtractClientReturnType, CommandEventDetails, CommandInstance, CommandResponseDetails } from "@hyper-fetch/core";
2
+ import { UseTrackedStateActions } from "./..";
3
+ export declare type UseCommandEventsDataMap = {
4
+ unmount: VoidFunction;
5
+ };
6
+ export declare type UseCommandEventsLifecycleMap = Map<string, {
7
+ unmount: VoidFunction;
8
+ }>;
9
+ export declare type UseCommandEventsPropsType<T extends CommandInstance> = {
10
+ command: T;
11
+ dispatcher: Dispatcher;
12
+ logger: LoggerType;
13
+ actions: UseTrackedStateActions<T>;
14
+ setCacheData: (cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => void;
15
+ };
16
+ export declare type UseCommandEventsActionsType<T extends CommandInstance> = {
17
+ /**
18
+ * Callback which allows to cancel ongoing requests from 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 command.
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 command 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 command instance which holds all data which is being transferred.
55
+ */
56
+ onUploadProgress: (callback: OnProgressCallbackType) => void;
57
+ };
58
+ export declare type UseCommandEventsReturnType<T extends CommandInstance> = [
59
+ UseCommandEventsActionsType<T>,
60
+ {
61
+ addDataListener: (command: CommandInstance) => VoidFunction;
62
+ clearDataListener: VoidFunction;
63
+ addLifecycleListeners: (command: CommandInstance, requestId?: string) => VoidFunction;
64
+ removeLifecycleListener: (requestId: string) => void;
65
+ clearLifecycleListeners: () => void;
66
+ }
67
+ ];
68
+ export declare type CallbackParameters<Command, ResponseType> = {
69
+ response: ResponseType;
70
+ details: CommandResponseDetails;
71
+ command: Command;
72
+ };
73
+ export declare type OnSuccessCallbackType<Command extends CommandInstance> = (params: CallbackParameters<Command, ExtractResponse<Command>>) => void | Promise<void>;
74
+ export declare type OnErrorCallbackType<Command extends CommandInstance> = (params: CallbackParameters<Command, ExtractError<Command>>) => void | Promise<void>;
75
+ export declare type OnFinishedCallbackType<Command extends CommandInstance> = (params: CallbackParameters<Command, ExtractClientReturnType<Command>>) => void | Promise<void>;
76
+ export declare type OnStartCallbackType<Command extends CommandInstance> = (params: {
77
+ details: CommandEventDetails<Command>;
78
+ command: Command;
79
+ }) => void | Promise<void>;
80
+ export declare type OnProgressCallbackType = <Command extends CommandInstance>(progress: FetchProgressType, details: CommandEventDetails<Command>) => void | Promise<void>;
@@ -0,0 +1,4 @@
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";
@@ -0,0 +1,2 @@
1
+ import { UseTrackedStateType } from "./use-tracked-state.types";
2
+ export declare const initialState: UseTrackedStateType;
@@ -0,0 +1,11 @@
1
+ import { CommandInstance } from "@hyper-fetch/core";
2
+ import { UseTrackedStateProps, UseTrackedStateReturn } from "./use-tracked-state.types";
3
+ /**
4
+ *
5
+ * @param command
6
+ * @param initialData
7
+ * @param dispatcher
8
+ * @param dependencies
9
+ * @internal
10
+ */
11
+ export declare const useTrackedState: <T extends CommandInstance>({ command, dispatcher, initialData, deepCompare, dependencyTracking, defaultCacheEmitting, }: UseTrackedStateProps<T>) => UseTrackedStateReturn<T>;
@@ -0,0 +1,72 @@
1
+ import { Dispatcher, ExtractError, CacheValueType, ExtractResponse, ClientResponseType, CommandInstance, LoggerType } from "@hyper-fetch/core";
2
+ import { isEqual } from "../../utils";
3
+ export declare type UseTrackedStateProps<T extends CommandInstance> = {
4
+ command: T;
5
+ logger: LoggerType;
6
+ initialData: ClientResponseType<ExtractResponse<T>, ExtractError<T>> | null;
7
+ dispatcher: Dispatcher;
8
+ dependencyTracking: boolean;
9
+ defaultCacheEmitting?: boolean;
10
+ deepCompare: boolean | typeof isEqual;
11
+ };
12
+ export declare type UseTrackedStateReturn<T extends CommandInstance> = [
13
+ UseTrackedStateType<T>,
14
+ UseTrackedStateActions<T>,
15
+ {
16
+ setRenderKey: (renderKey: keyof UseTrackedStateType<T>) => void;
17
+ setCacheData: (cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => void;
18
+ getStaleStatus: () => boolean;
19
+ }
20
+ ];
21
+ export declare type UseTrackedStateType<T extends CommandInstance = CommandInstance> = {
22
+ /**
23
+ * Request response data
24
+ */
25
+ data: null | ExtractResponse<T>;
26
+ /**
27
+ * Request response error
28
+ */
29
+ error: null | ExtractError<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 declare type UseTrackedStateActions<T extends CommandInstance> = {
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: ExtractResponse<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: ExtractError<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
+ };
@@ -0,0 +1,7 @@
1
+ import { CacheValueType, NullableType, CommandInstance, ClientResponseType, ExtractResponse, ExtractError, ExtractClientReturnType, Dispatcher } from "@hyper-fetch/core";
2
+ import { UseTrackedStateType } from "./..";
3
+ export declare const getDetailsState: (state?: UseTrackedStateType<CommandInstance>, details?: Partial<CacheValueType<unknown, unknown>["details"]>) => CacheValueType<unknown, unknown>["details"];
4
+ export declare const isStaleCacheData: (cacheTime: number, cacheTimestamp: NullableType<Date | number>) => boolean;
5
+ export declare const getValidCacheData: <T extends CommandInstance>(command: T, initialData: ExtractClientReturnType<T>, cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => CacheValueType<ExtractResponse<T>, ExtractError<T>>;
6
+ export declare const getTimestamp: (timestamp?: NullableType<number | Date>) => Date;
7
+ export declare const getInitialState: <T extends CommandInstance>(initialData: ClientResponseType<ExtractResponse<T>, ExtractError<T>>, dispatcher: Dispatcher, command: T) => UseTrackedStateType<T>;
@@ -0,0 +1,2 @@
1
+ export * from "./use-app-manager.hooks";
2
+ export * from "./use-app-manager.types";
@@ -0,0 +1,3 @@
1
+ import { BuilderInstance } from "@hyper-fetch/core";
2
+ import { UseAppManagerReturnType } from "./";
3
+ export declare const useAppManager: <B extends BuilderInstance>(builder: B) => UseAppManagerReturnType;
@@ -0,0 +1,18 @@
1
+ export declare 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
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./use-cache.hooks";
2
+ export * from "./use-cache.constants";
3
+ export * from "./use-cache.types";
@@ -0,0 +1,5 @@
1
+ export declare const useCacheDefaultOptions: {
2
+ dependencyTracking: boolean;
3
+ initialData: any;
4
+ deepCompare: boolean;
5
+ };
@@ -0,0 +1,3 @@
1
+ import { CommandInstance } from "@hyper-fetch/core";
2
+ import { UseCacheOptionsType, UseCacheReturnType } from "./";
3
+ export declare const useCache: <T extends CommandInstance>(command: T, options?: UseCacheOptionsType<T>) => UseCacheReturnType<T>;
@@ -0,0 +1,35 @@
1
+ import { CommandInstance, ExtractResponse, ExtractError, CacheValueType } from "@hyper-fetch/core";
2
+ import { isEqual } from "../../utils";
3
+ import { OnErrorCallbackType, OnFinishedCallbackType, OnSuccessCallbackType, UseTrackedStateActions, UseTrackedStateType } from "../../helpers";
4
+ export declare type UseCacheOptionsType<T extends CommandInstance> = {
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<ExtractResponse<T>, ExtractError<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 declare type UseCacheReturnType<T extends CommandInstance> = 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 command resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
33
+ */
34
+ revalidate: (invalidateKey?: string | RegExp | CommandInstance) => void;
35
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./use-fetch.hooks";
2
+ export * from "./use-fetch.types";
3
+ export * from "./use-fetch.utils";
4
+ export * from "./use-fetch.constants";
@@ -0,0 +1,7 @@
1
+ import { CommandInstance, RequiredKeys } from "@hyper-fetch/core";
2
+ import { UseFetchOptionsType } from "./";
3
+ declare type DefaultOptionsType = RequiredKeys<Omit<UseFetchOptionsType<CommandInstance>, "initialData">> & {
4
+ initialData: null;
5
+ };
6
+ export declare const useFetchDefaultOptions: DefaultOptionsType;
7
+ export {};
@@ -0,0 +1,9 @@
1
+ import { CommandInstance } from "@hyper-fetch/core";
2
+ import { UseFetchOptionsType, UseFetchReturnType } from "./";
3
+ /**
4
+ * This hooks aims to retrieve data from server.
5
+ * @param command Command instance
6
+ * @param options Hook options
7
+ * @returns
8
+ */
9
+ export declare const useFetch: <T extends CommandInstance>(command: T, options?: UseFetchOptionsType<T>) => UseFetchReturnType<T>;
@@ -0,0 +1,85 @@
1
+ import { CommandInstance, ExtractResponse, ExtractError, CacheValueType } from "@hyper-fetch/core";
2
+ import { UseCommandEventsActionsType, UseTrackedStateActions, UseTrackedStateType } from "../../helpers";
3
+ import { InvalidationKeyType } from "../../types";
4
+ import { isEqual } from "../../utils";
5
+ export declare type UseFetchOptionsType<T extends CommandInstance> = {
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<ExtractResponse<T>, ExtractError<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
+ * Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
64
+ */
65
+ deepCompare?: boolean | typeof isEqual;
66
+ };
67
+ export declare type UseFetchReturnType<T extends CommandInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & UseCommandEventsActionsType<T> & {
68
+ /**
69
+ * Data related to current state of the bounce usage
70
+ */
71
+ bounce: {
72
+ /**
73
+ * Active state of the bounce method
74
+ */
75
+ active: boolean;
76
+ /**
77
+ * Method to stop the active bounce method execution
78
+ */
79
+ reset: () => void;
80
+ };
81
+ /**
82
+ * Revalidate current command resource or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
83
+ */
84
+ revalidate: (invalidateKey?: InvalidationKeyType | InvalidationKeyType[]) => void;
85
+ };
@@ -0,0 +1 @@
1
+ export declare const getRefreshTime: (refreshTime: number, dataTimestamp?: Date) => number;
@@ -0,0 +1,3 @@
1
+ export * from "./use-queue.hooks";
2
+ export * from "./use-queue.types";
3
+ export * from "./use-queue.constants";
@@ -0,0 +1,3 @@
1
+ import { RequiredKeys } from "@hyper-fetch/core";
2
+ import { UseQueueOptionsType } from "./";
3
+ export declare const useQueueDefaultOptions: RequiredKeys<UseQueueOptionsType>;
@@ -0,0 +1,9 @@
1
+ import { CommandInstance } from "@hyper-fetch/core";
2
+ import { UseQueueOptionsType, UseQueueReturnType } from "./";
3
+ /**
4
+ * This hook allows to control dispatchers request queues
5
+ * @param command
6
+ * @param options
7
+ * @returns
8
+ */
9
+ export declare const useQueue: <Command extends CommandInstance>(command: Command, options?: UseQueueOptionsType) => UseQueueReturnType<Command>;
@@ -0,0 +1,48 @@
1
+ import { FetchProgressType, CommandInstance, DispatcherDumpValueType } from "@hyper-fetch/core";
2
+ export declare type UseQueueOptionsType = {
3
+ queueType?: "auto" | "fetch" | "submit";
4
+ };
5
+ export declare type QueueRequest<Command extends CommandInstance> = DispatcherDumpValueType<Command> & {
6
+ /**
7
+ * Uploading progress for given request
8
+ */
9
+ uploading?: FetchProgressType;
10
+ /**
11
+ * Downloading progress for given request
12
+ */
13
+ downloading?: FetchProgressType;
14
+ /**
15
+ * Callback which allow to start previously stopped request.
16
+ */
17
+ startRequest: () => void;
18
+ /**
19
+ * Callback which allow to stop request and cancel it if it's ongoing.
20
+ */
21
+ stopRequest: () => void;
22
+ /**
23
+ * Removes request from the queue
24
+ */
25
+ deleteRequest: () => void;
26
+ };
27
+ export declare type UseQueueReturnType<T extends CommandInstance> = {
28
+ /**
29
+ * Queue status for provided command
30
+ */
31
+ stopped: boolean;
32
+ /**
33
+ * List of requests for provided command
34
+ */
35
+ requests: QueueRequest<T>[];
36
+ /**
37
+ * Callback which allow to stop queue, it will cancel ongoing requests.
38
+ */
39
+ stop: () => void;
40
+ /**
41
+ * Callback which allow to pause queue. It will allow ongoing requests to be finished, but will stop next from being send.
42
+ */
43
+ pause: () => void;
44
+ /**
45
+ * Callback which allow to start queue.
46
+ */
47
+ start: () => void;
48
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./use-submit.hooks";
2
+ export * from "./use-submit.types";
3
+ export * from "./use-submit.constants";
@@ -0,0 +1,7 @@
1
+ import { CommandInstance, RequiredKeys } from "@hyper-fetch/core";
2
+ import { UseSubmitOptionsType } from "./use-submit.types";
3
+ declare type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<CommandInstance>, "initialData">> & {
4
+ initialData: null;
5
+ };
6
+ export declare const useSubmitDefaultOptions: DefaultOptionsType;
7
+ export {};
@@ -0,0 +1,9 @@
1
+ import { CommandInstance } from "@hyper-fetch/core";
2
+ import { UseSubmitOptionsType, UseSubmitReturnType } from "./";
3
+ /**
4
+ * This hooks aims to mutate data on the server.
5
+ * @param command
6
+ * @param options
7
+ * @returns
8
+ */
9
+ export declare const useSubmit: <Command_1 extends CommandInstance>(command: Command_1, options?: UseSubmitOptionsType<Command_1>) => UseSubmitReturnType<Command_1>;