@hyper-fetch/react 1.7.1 โ†’ 2.1.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 (56) hide show
  1. package/README.md +18 -16
  2. package/dist/config-provider/config-provider.types.d.ts +7 -7
  3. package/dist/helpers/index.d.ts +1 -0
  4. package/dist/helpers/use-command-events/use-command-events.hooks.d.ts +2 -3
  5. package/dist/helpers/use-command-events/use-command-events.types.d.ts +12 -12
  6. package/dist/helpers/use-socket-state/index.d.ts +3 -0
  7. package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts +2 -0
  8. package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts +16 -0
  9. package/dist/helpers/use-socket-state/use-socket-state.types.d.ts +9 -0
  10. package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +1 -2
  11. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +5 -5
  12. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +5 -5
  13. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +2 -3
  14. package/dist/hooks/use-app-manager/use-app-manager.types.d.ts +1 -1
  15. package/dist/hooks/use-cache/use-cache.hooks.d.ts +2 -3
  16. package/dist/hooks/use-cache/use-cache.types.d.ts +4 -4
  17. package/dist/hooks/use-emitter/index.d.ts +2 -0
  18. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +19 -0
  19. package/dist/hooks/use-emitter/use-emitter.types.d.ts +3 -0
  20. package/dist/hooks/use-event-messages/index.d.ts +2 -0
  21. package/dist/hooks/use-event-messages/use-event-messages.hooks.d.ts +24 -0
  22. package/dist/hooks/use-event-messages/use-event-messages.types.d.ts +4 -0
  23. package/dist/hooks/use-fetch/use-fetch.constants.d.ts +2 -2
  24. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +2 -3
  25. package/dist/hooks/use-fetch/use-fetch.types.d.ts +5 -5
  26. package/dist/hooks/use-listener/index.d.ts +2 -0
  27. package/dist/hooks/use-listener/use-listener.hooks.d.ts +20 -0
  28. package/dist/hooks/use-listener/use-listener.types.d.ts +3 -0
  29. package/dist/hooks/use-queue/use-queue.constants.d.ts +1 -1
  30. package/dist/hooks/use-queue/use-queue.hooks.d.ts +2 -3
  31. package/dist/hooks/use-queue/use-queue.types.d.ts +3 -3
  32. package/dist/hooks/use-submit/use-submit.constants.d.ts +1 -1
  33. package/dist/hooks/use-submit/use-submit.hooks.d.ts +2 -3
  34. package/dist/hooks/use-submit/use-submit.types.d.ts +5 -5
  35. package/dist/index.cjs.js +1 -1
  36. package/dist/index.cjs.js.map +4 -4
  37. package/dist/index.d.ts +3 -0
  38. package/dist/index.esm.js +1 -1
  39. package/dist/index.esm.js.map +4 -4
  40. package/dist/types/invalidation.types.d.ts +1 -1
  41. package/package.json +11 -3
  42. package/src/helpers/index.ts +1 -0
  43. package/src/helpers/use-socket-state/index.ts +3 -0
  44. package/src/helpers/use-socket-state/use-socket-state.constants.ts +8 -0
  45. package/src/helpers/use-socket-state/use-socket-state.hooks.ts +135 -0
  46. package/src/helpers/use-socket-state/use-socket-state.types.ts +10 -0
  47. package/src/hooks/use-emitter/index.ts +2 -0
  48. package/src/hooks/use-emitter/use-emitter.hooks.ts +47 -0
  49. package/src/hooks/use-emitter/use-emitter.types.ts +3 -0
  50. package/src/hooks/use-event-messages/index.ts +2 -0
  51. package/src/hooks/use-event-messages/use-event-messages.hooks.ts +65 -0
  52. package/src/hooks/use-event-messages/use-event-messages.types.ts +4 -0
  53. package/src/hooks/use-listener/index.ts +2 -0
  54. package/src/hooks/use-listener/use-listener.hooks.ts +75 -0
  55. package/src/hooks/use-listener/use-listener.types.ts +3 -0
  56. package/src/index.ts +3 -0
package/README.md CHANGED
@@ -39,40 +39,42 @@
39
39
  `optimized`, `maintainable` and `high quality solutions`. We offer many hooks for your use, thanks to which you can
40
40
  fetch or mutate data, observe sent requests and interact with data in the cache.
41
41
 
42
- ## Features
42
+ ## Key Features
43
43
 
44
- ๐Ÿ”ฎ **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
44
+ ๐Ÿ”ฎ **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Basic/Setup)
45
45
 
46
- ๐ŸŽฏ **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Cancellation)
46
+ ๐ŸŽฏ **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Cancellation)
47
47
 
48
- โœจ **Window Focus/Blur Events** - [Read more](https://hyperfetch.bettertyped.com/guides/React/Window%20Focus%20&%20Blur)
48
+ โœจ **Window Focus/Blur Events** -
49
+ [Read more](https://hyperfetch.bettertyped.com/docs/guides/React/Window%20Focus%20&%20Blur)
49
50
 
50
- ๐Ÿš€ **Queueing** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Queueing)
51
+ ๐Ÿš€ **Queueing** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Queueing)
51
52
 
52
- ๐Ÿ’Ž **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/Architecture/Cache)
53
+ ๐Ÿ’Ž **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Cache)
53
54
 
54
- ๐Ÿช„ **Persistance** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Persistence)
55
+ ๐Ÿช„ **Persistence** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Persistence)
55
56
 
56
- ๐ŸŽŠ **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Environment)
57
+ ๐ŸŽŠ **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Environment)
57
58
 
58
- ๐Ÿ”‹ **Offline First** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Offline)
59
+ ๐Ÿ”‹ **Offline First** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Offline)
59
60
 
60
- ๐Ÿ“ก **Built-in client** - [Read more](https://hyperfetch.bettertyped.com/docs/Architecture/Client)
61
+ ๐Ÿ“ก **Built-in client** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Core/Client)
61
62
 
62
- ๐Ÿงช **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Testing)
63
+ ๐Ÿงช **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Testing)
63
64
 
64
- ๐ŸŽŸ **Authentication** - [Read more](https://hyperfetch.bettertyped.com/guides/Basic/Authentication)
65
+ ๐ŸŽŸ **Authentication** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Basic/Authentication)
65
66
 
66
- ๐Ÿ’ก **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/guides/Advanced/Prefetching)
67
+ ๐Ÿ’ก **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/Advanced/Prefetching)
67
68
 
68
69
  ## Sources
69
70
 
70
- - #### [Installation](https://hyperfetch.bettertyped.com/docs/Getting%20Started/Installation)
71
+ - #### [Installation](https://hyperfetch.bettertyped.com/docs/documentation/Getting%20Started/Installation)
71
72
  - #### [Docs](https://hyperfetch.bettertyped.com/docs/React/Overview)
72
73
  - #### [API](https://hyperfetch.bettertyped.com/api/)
73
- - #### [NPM](https://www.npmjs.com/package/@hyper-fetch/core)
74
+ - #### [NPM](https://www.npmjs.com/package/@hyper-fetch/react)
74
75
  - #### [Guides](https://hyperfetch.bettertyped.com/guides/Basic/Setup)
75
76
 
76
77
  ## Other Packages
77
78
 
78
- - #### [Hyper Fetch](https://github.com/BetterTyped/hyper-fetch/tree/main/packages/core)
79
+ - - #### [Hyper Fetch](https://github.com/BetterTyped/hyper-fetch/tree/main/packages/core)
80
+ - #### [Hyper Fetch Sockets](https://github.com/BetterTyped/hyper-fetch/tree/main/packages/sockets)
@@ -1,17 +1,17 @@
1
1
  import React from "react";
2
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 = {
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 type ConfigProviderOptionsType = {
8
8
  useFetchConfig?: Partial<UseFetchOptionsType<CommandInstance>>;
9
9
  useSubmitConfig?: Partial<UseSubmitOptionsType<CommandInstance>>;
10
10
  useCacheConfig?: Partial<UseCacheOptionsType<CommandInstance>>;
11
11
  useQueueConfig?: Partial<UseQueueOptionsType>;
12
12
  };
13
- export declare type ConfigProviderProps = {
13
+ export type ConfigProviderProps = {
14
14
  children: React.ReactNode;
15
15
  config?: ConfigProviderOptionsType;
16
16
  };
17
- export declare type ConfigProviderValueType = [ConfigProviderOptionsType, (newConfig: ConfigProviderOptionsType) => void];
17
+ export type ConfigProviderValueType = [ConfigProviderOptionsType, (newConfig: ConfigProviderOptionsType) => void];
@@ -1,2 +1,3 @@
1
1
  export * from "./use-command-events";
2
2
  export * from "./use-tracked-state";
3
+ export * from "./use-socket-state";
@@ -1,9 +1,8 @@
1
- import { CommandInstance } from "@hyper-fetch/core";
2
- import { UseCommandEventsReturnType, UseCommandEventsPropsType } from "./..";
1
+ import { UseCommandEventsReturnType, UseCommandEventsPropsType } from "helpers";
3
2
  /**
4
3
  * This is helper hook that handles main Hyper-Fetch event/data flow
5
4
  * @internal
6
5
  * @param options
7
6
  * @returns
8
7
  */
9
- export declare const useCommandEvents: <T extends CommandInstance>({ command, dispatcher, logger, actions, setCacheData, }: UseCommandEventsPropsType<T>) => UseCommandEventsReturnType<T>;
8
+ export declare const useCommandEvents: <T extends Command<any, any, any, any, any, any, any, any, any, any, any>>({ command, dispatcher, logger, actions, setCacheData, }: UseCommandEventsPropsType<T>) => UseCommandEventsReturnType<T>;
@@ -1,19 +1,19 @@
1
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 = {
2
+ import { UseTrackedStateActions } from "helpers";
3
+ export type UseCommandEventsDataMap = {
4
4
  unmount: VoidFunction;
5
5
  };
6
- export declare type UseCommandEventsLifecycleMap = Map<string, {
6
+ export type UseCommandEventsLifecycleMap = Map<string, {
7
7
  unmount: VoidFunction;
8
8
  }>;
9
- export declare type UseCommandEventsPropsType<T extends CommandInstance> = {
9
+ export type UseCommandEventsPropsType<T extends CommandInstance> = {
10
10
  command: T;
11
11
  dispatcher: Dispatcher;
12
12
  logger: LoggerType;
13
13
  actions: UseTrackedStateActions<T>;
14
14
  setCacheData: (cacheData: CacheValueType<ExtractResponse<T>, ExtractError<T>>) => void;
15
15
  };
16
- export declare type UseCommandEventsActionsType<T extends CommandInstance> = {
16
+ export type UseCommandEventsActionsType<T extends CommandInstance> = {
17
17
  /**
18
18
  * Callback that allows canceling ongoing requests from the given queueKey.
19
19
  */
@@ -55,7 +55,7 @@ export declare type UseCommandEventsActionsType<T extends CommandInstance> = {
55
55
  */
56
56
  onUploadProgress: (callback: OnProgressCallbackType) => void;
57
57
  };
58
- export declare type UseCommandEventsReturnType<T extends CommandInstance> = [
58
+ export type UseCommandEventsReturnType<T extends CommandInstance> = [
59
59
  UseCommandEventsActionsType<T>,
60
60
  {
61
61
  addDataListener: (command: CommandInstance) => VoidFunction;
@@ -65,16 +65,16 @@ export declare type UseCommandEventsReturnType<T extends CommandInstance> = [
65
65
  clearLifecycleListeners: () => void;
66
66
  }
67
67
  ];
68
- export declare type CallbackParameters<Command, ResponseType> = {
68
+ export type CallbackParameters<Command, ResponseType> = {
69
69
  response: ResponseType;
70
70
  details: CommandResponseDetails;
71
71
  command: Command;
72
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: {
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
77
  details: CommandEventDetails<Command>;
78
78
  command: Command;
79
79
  }) => void | Promise<void>;
80
- export declare type OnProgressCallbackType = <Command extends CommandInstance>(progress: FetchProgressType, details: CommandEventDetails<Command>) => void | Promise<void>;
80
+ export type OnProgressCallbackType = <Command extends CommandInstance>(progress: FetchProgressType, details: CommandEventDetails<Command>) => void | Promise<void>;
@@ -0,0 +1,3 @@
1
+ export * from "./use-socket-state.hooks";
2
+ export * from "./use-socket-state.types";
3
+ export * from "./use-socket-state.constants";
@@ -0,0 +1,2 @@
1
+ import { UseSocketStateType } from "./use-socket-state.types";
2
+ export declare const initialSocketState: UseSocketStateType;
@@ -0,0 +1,16 @@
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
+ }];
@@ -0,0 +1,9 @@
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 +1,3 @@
1
- import { CommandInstance } from "@hyper-fetch/core";
2
1
  import { UseTrackedStateProps, UseTrackedStateReturn } from "./use-tracked-state.types";
3
2
  /**
4
3
  *
@@ -8,4 +7,4 @@ import { UseTrackedStateProps, UseTrackedStateReturn } from "./use-tracked-state
8
7
  * @param dependencies
9
8
  * @internal
10
9
  */
11
- export declare const useTrackedState: <T extends CommandInstance>({ command, dispatcher, initialData, deepCompare, dependencyTracking, defaultCacheEmitting, }: UseTrackedStateProps<T>) => UseTrackedStateReturn<T>;
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>;
@@ -1,6 +1,6 @@
1
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> = {
2
+ import { isEqual } from "utils";
3
+ export type UseTrackedStateProps<T extends CommandInstance> = {
4
4
  command: T;
5
5
  logger: LoggerType;
6
6
  initialData: ClientResponseType<ExtractResponse<T>, ExtractError<T>> | null;
@@ -9,7 +9,7 @@ export declare type UseTrackedStateProps<T extends CommandInstance> = {
9
9
  defaultCacheEmitting?: boolean;
10
10
  deepCompare: boolean | typeof isEqual;
11
11
  };
12
- export declare type UseTrackedStateReturn<T extends CommandInstance> = [
12
+ export type UseTrackedStateReturn<T extends CommandInstance> = [
13
13
  UseTrackedStateType<T>,
14
14
  UseTrackedStateActions<T>,
15
15
  {
@@ -18,7 +18,7 @@ export declare type UseTrackedStateReturn<T extends CommandInstance> = [
18
18
  getStaleStatus: () => boolean;
19
19
  }
20
20
  ];
21
- export declare type UseTrackedStateType<T extends CommandInstance = CommandInstance> = {
21
+ export type UseTrackedStateType<T extends CommandInstance = CommandInstance> = {
22
22
  /**
23
23
  * Request response data
24
24
  */
@@ -44,7 +44,7 @@ export declare type UseTrackedStateType<T extends CommandInstance = CommandInsta
44
44
  */
45
45
  timestamp: null | Date;
46
46
  };
47
- export declare type UseTrackedStateActions<T extends CommandInstance> = {
47
+ export type UseTrackedStateActions<T extends CommandInstance> = {
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
  */
@@ -1,7 +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"];
1
+ import { CacheValueType, NullableType, CommandInstance, ClientResponseType, ExtractResponse, ExtractError, Dispatcher } from "@hyper-fetch/core";
2
+ import { UseTrackedStateType } from "helpers";
3
+ export declare const getDetailsState: (state?: UseTrackedStateType<CommandInstance>, details?: CommandResponseDetails) => CommandResponseDetails;
4
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>>;
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>>;
6
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>;
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>;
@@ -1,3 +1,2 @@
1
- import { BuilderInstance } from "@hyper-fetch/core";
2
- import { UseAppManagerReturnType } from "./";
3
- export declare const useAppManager: <B extends BuilderInstance>(builder: B) => UseAppManagerReturnType;
1
+ import { UseAppManagerReturnType } from "hooks/use-app-manager";
2
+ export declare const useAppManager: <B extends Builder<any, any>>(builder: B) => UseAppManagerReturnType;
@@ -1,4 +1,4 @@
1
- export declare type UseAppManagerReturnType = {
1
+ export type UseAppManagerReturnType = {
2
2
  /**
3
3
  * Is window focused
4
4
  */
@@ -1,3 +1,2 @@
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>;
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>;
@@ -1,7 +1,7 @@
1
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> = {
2
+ import { isEqual } from "utils";
3
+ import { OnErrorCallbackType, OnFinishedCallbackType, OnSuccessCallbackType, UseTrackedStateActions, UseTrackedStateType } from "helpers";
4
+ export type UseCacheOptionsType<T extends CommandInstance> = {
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
  */
@@ -15,7 +15,7 @@ export declare type UseCacheOptionsType<T extends CommandInstance> = {
15
15
  */
16
16
  deepCompare?: boolean | typeof isEqual;
17
17
  };
18
- export declare type UseCacheReturnType<T extends CommandInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & {
18
+ export type UseCacheReturnType<T extends CommandInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & {
19
19
  /**
20
20
  * Helper hook listener for success response
21
21
  */
@@ -0,0 +1,2 @@
1
+ export * from "./use-emitter.hooks";
2
+ export * from "./use-emitter.types";
@@ -0,0 +1,19 @@
1
+ import { UseEmitterOptionsType } from "hooks/use-emitter";
2
+ export declare const useEmitter: <EmitterType extends Emitter<any, any, any>>(emitter: EmitterType, { dependencyTracking }: 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
+ };
@@ -0,0 +1,3 @@
1
+ export type UseEmitterOptionsType = {
2
+ dependencyTracking?: boolean;
3
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./use-event-messages.hooks";
2
+ export * from "./use-event-messages.types";
@@ -0,0 +1,24 @@
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>, { dependencyTracking, filter }: 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
+ };
@@ -0,0 +1,4 @@
1
+ export type UseEventMessagesOptionsType<ResponsesType> = {
2
+ dependencyTracking?: boolean;
3
+ filter?: ((data: ResponsesType, event: MessageEvent<ResponsesType>) => boolean) | string[];
4
+ };
@@ -1,6 +1,6 @@
1
1
  import { CommandInstance, RequiredKeys } from "@hyper-fetch/core";
2
- import { UseFetchOptionsType } from "./";
3
- declare type DefaultOptionsType = RequiredKeys<Omit<UseFetchOptionsType<CommandInstance>, "initialData">> & {
2
+ import { UseFetchOptionsType } from "hooks/use-fetch";
3
+ type DefaultOptionsType = RequiredKeys<Omit<UseFetchOptionsType<CommandInstance>, "initialData">> & {
4
4
  initialData: null;
5
5
  };
6
6
  export declare const useFetchDefaultOptions: DefaultOptionsType;
@@ -1,9 +1,8 @@
1
- import { CommandInstance } from "@hyper-fetch/core";
2
- import { UseFetchOptionsType, UseFetchReturnType } from "./";
1
+ import { UseFetchOptionsType, UseFetchReturnType } from "hooks/use-fetch";
3
2
  /**
4
3
  * This hooks aims to retrieve data from server.
5
4
  * @param command Command instance
6
5
  * @param options Hook options
7
6
  * @returns
8
7
  */
9
- export declare const useFetch: <T extends CommandInstance>(command: T, options?: UseFetchOptionsType<T>) => UseFetchReturnType<T>;
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>;
@@ -1,8 +1,8 @@
1
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> = {
2
+ import { UseCommandEventsActionsType, UseTrackedStateActions, UseTrackedStateType } from "helpers";
3
+ import { InvalidationKeyType } from "types";
4
+ import { isEqual } from "utils";
5
+ export type UseFetchOptionsType<T extends CommandInstance> = {
6
6
  /**
7
7
  * Refetch dependencies
8
8
  */
@@ -64,7 +64,7 @@ export declare type UseFetchOptionsType<T extends CommandInstance> = {
64
64
  */
65
65
  deepCompare?: boolean | typeof isEqual;
66
66
  };
67
- export declare type UseFetchReturnType<T extends CommandInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & UseCommandEventsActionsType<T> & {
67
+ export type UseFetchReturnType<T extends CommandInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & UseCommandEventsActionsType<T> & {
68
68
  /**
69
69
  * Data related to current state of the bounce usage
70
70
  */
@@ -0,0 +1,2 @@
1
+ export * from "./use-listener.hooks";
2
+ export * from "./use-listener.types";
@@ -0,0 +1,20 @@
1
+ import { ExtractListenerDataType } from "@hyper-fetch/sockets";
2
+ import { UseListenerOptionsType } from "hooks/use-listener";
3
+ export declare const useListener: <ListenerType extends Listener<any, any>>(listener: ListenerType, { dependencyTracking }: UseListenerOptionsType) => {
4
+ listen: () => void;
5
+ onEvent: (callback: (data: ExtractListenerDataType<ListenerType>, event: MessageEvent<ExtractListenerDataType<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
+ };
@@ -0,0 +1,3 @@
1
+ export type UseListenerOptionsType = {
2
+ dependencyTracking?: boolean;
3
+ };
@@ -1,3 +1,3 @@
1
1
  import { RequiredKeys } from "@hyper-fetch/core";
2
- import { UseQueueOptionsType } from "./";
2
+ import { UseQueueOptionsType } from "hooks/use-queue";
3
3
  export declare const useQueueDefaultOptions: RequiredKeys<UseQueueOptionsType>;
@@ -1,9 +1,8 @@
1
- import { CommandInstance } from "@hyper-fetch/core";
2
- import { UseQueueOptionsType, UseQueueReturnType } from "./";
1
+ import { UseQueueOptionsType, UseQueueReturnType } from "hooks/use-queue";
3
2
  /**
4
3
  * This hook allows to control dispatchers request queues
5
4
  * @param command
6
5
  * @param options
7
6
  * @returns
8
7
  */
9
- export declare const useQueue: <Command extends CommandInstance>(command: Command, options?: UseQueueOptionsType) => UseQueueReturnType<Command>;
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>;
@@ -1,8 +1,8 @@
1
1
  import { FetchProgressType, CommandInstance, DispatcherDumpValueType } from "@hyper-fetch/core";
2
- export declare type UseQueueOptionsType = {
2
+ export type UseQueueOptionsType = {
3
3
  queueType?: "auto" | "fetch" | "submit";
4
4
  };
5
- export declare type QueueRequest<Command extends CommandInstance> = DispatcherDumpValueType<Command> & {
5
+ export type QueueRequest<Command extends CommandInstance> = DispatcherDumpValueType<Command> & {
6
6
  /**
7
7
  * Uploading progress for given request
8
8
  */
@@ -24,7 +24,7 @@ export declare type QueueRequest<Command extends CommandInstance> = DispatcherDu
24
24
  */
25
25
  deleteRequest: () => void;
26
26
  };
27
- export declare type UseQueueReturnType<T extends CommandInstance> = {
27
+ export type UseQueueReturnType<T extends CommandInstance> = {
28
28
  /**
29
29
  * Queue status for provided command
30
30
  */
@@ -1,6 +1,6 @@
1
1
  import { CommandInstance, RequiredKeys } from "@hyper-fetch/core";
2
2
  import { UseSubmitOptionsType } from "./use-submit.types";
3
- declare type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<CommandInstance>, "initialData">> & {
3
+ type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<CommandInstance>, "initialData">> & {
4
4
  initialData: null;
5
5
  };
6
6
  export declare const useSubmitDefaultOptions: DefaultOptionsType;
@@ -1,9 +1,8 @@
1
- import { CommandInstance } from "@hyper-fetch/core";
2
- import { UseSubmitOptionsType, UseSubmitReturnType } from "./";
1
+ import { UseSubmitOptionsType, UseSubmitReturnType } from "hooks/use-submit";
3
2
  /**
4
3
  * This hooks aims to mutate data on the server.
5
4
  * @param command
6
5
  * @param options
7
6
  * @returns
8
7
  */
9
- export declare const useSubmit: <CommandType extends CommandInstance>(command: CommandType, options?: UseSubmitOptionsType<CommandType>) => UseSubmitReturnType<CommandType>;
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>;
@@ -1,8 +1,8 @@
1
1
  import { CacheValueType, ExtractError, ExtractResponse, CommandInstance, FetchMethodType } from "@hyper-fetch/core";
2
- import { isEqual } from "../../utils";
3
- import { OnErrorCallbackType, OnFinishedCallbackType, OnProgressCallbackType, OnStartCallbackType, OnSuccessCallbackType, UseTrackedStateType, UseTrackedStateActions } from "../../helpers";
4
- import { InvalidationKeyType } from "../../types";
5
- export declare type UseSubmitOptionsType<T extends CommandInstance> = {
2
+ import { isEqual } from "utils";
3
+ import { OnErrorCallbackType, OnFinishedCallbackType, OnProgressCallbackType, OnStartCallbackType, OnSuccessCallbackType, UseTrackedStateType, UseTrackedStateActions } from "helpers";
4
+ import { InvalidationKeyType } from "types";
5
+ export type UseSubmitOptionsType<T extends CommandInstance> = {
6
6
  /**
7
7
  * Disable fetching
8
8
  */
@@ -32,7 +32,7 @@ export declare type UseSubmitOptionsType<T extends CommandInstance> = {
32
32
  */
33
33
  deepCompare?: boolean | typeof isEqual;
34
34
  };
35
- export declare type UseSubmitReturnType<CommandType extends CommandInstance> = Omit<UseTrackedStateType<CommandType>, "loading"> & UseTrackedStateActions<CommandType> & {
35
+ export type UseSubmitReturnType<CommandType extends CommandInstance> = Omit<UseTrackedStateType<CommandType>, "loading"> & UseTrackedStateActions<CommandType> & {
36
36
  /**
37
37
  * Callback which allows to cancel ongoing requests from given queueKey.
38
38
  */