@hyper-fetch/react 7.5.3 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/.eslintrc.cjs +12 -0
  2. package/__tests__/features/helpers/use-request-events/use-request-events.base.spec.ts +4 -4
  3. package/__tests__/features/helpers/use-request-events/use-request-events.utils.spec.ts +3 -3
  4. package/__tests__/features/helpers/use-socket-state/use-socket-state.base.spec.ts +44 -6
  5. package/__tests__/features/helpers/use-tracked-state/use-tacked-state.actions.spec.ts +177 -9
  6. package/__tests__/features/helpers/use-tracked-state/use-tracked-state.base.spec.ts +47 -8
  7. package/__tests__/features/helpers/use-tracked-state/use-tracked-state.utils.spec.ts +6 -6
  8. package/__tests__/features/provider/provider.hydration.spec.tsx +7 -3
  9. package/__tests__/features/provider/use-config-provider.base.spec.tsx +2 -1
  10. package/__tests__/features/use-app-manager/use-app-manager.base.spec.ts +1 -1
  11. package/__tests__/features/use-cache/use-cache.base.spec.ts +9 -6
  12. package/__tests__/features/use-cache/use-cache.helpers.ts +1 -1
  13. package/__tests__/features/use-cache/use-cache.typescript.spec.ts +111 -0
  14. package/__tests__/features/use-emitter/use-emitter.base.spec.ts +2 -2
  15. package/__tests__/features/use-fetch/use-fetch.base.spec.ts +103 -15
  16. package/__tests__/features/use-fetch/use-fetch.cancel.spec.ts +2 -2
  17. package/__tests__/features/use-fetch/use-fetch.clear-state.spec.ts +82 -0
  18. package/__tests__/features/use-fetch/use-fetch.concurrency.spec.ts +3 -3
  19. package/__tests__/features/use-fetch/use-fetch.debounce.spec.ts +5 -5
  20. package/__tests__/features/use-fetch/use-fetch.deduplication.spec.ts +1 -1
  21. package/__tests__/features/use-fetch/use-fetch.infinite.ts +1 -1
  22. package/__tests__/features/use-fetch/use-fetch.integration.spec.tsx +3 -3
  23. package/__tests__/features/use-fetch/use-fetch.keep-previous-data.spec.ts +215 -0
  24. package/__tests__/features/use-fetch/use-fetch.methods.spec.ts +34 -34
  25. package/__tests__/features/use-fetch/use-fetch.offline.spec.ts +3 -3
  26. package/__tests__/features/use-fetch/use-fetch.pagination.ts +1 -1
  27. package/__tests__/features/use-fetch/use-fetch.prefetch.spec.tsx +1 -1
  28. package/__tests__/features/use-fetch/use-fetch.refresh.spec.ts +41 -7
  29. package/__tests__/features/use-fetch/use-fetch.rerender.spec.tsx +2 -2
  30. package/__tests__/features/use-fetch/use-fetch.retry.ts +1 -1
  31. package/__tests__/features/use-fetch/use-fetch.revalidate.spec.ts +6 -4
  32. package/__tests__/features/use-fetch/use-fetch.suspense.spec.tsx +505 -0
  33. package/__tests__/features/use-fetch/use-fetch.typescript.spec.ts +179 -56
  34. package/__tests__/features/use-fetch/use-fetch.window.spec.ts +75 -3
  35. package/__tests__/features/use-listener/use-listener.base.spec.ts +3 -3
  36. package/__tests__/features/use-queue/use-queue.actions.spec.ts +1 -1
  37. package/__tests__/features/use-queue/use-queue.base.spec.ts +259 -1
  38. package/__tests__/features/use-queue/use-queue.resolve.spec.ts +173 -0
  39. package/__tests__/features/use-stream/use-stream.base.spec.ts +481 -0
  40. package/__tests__/features/use-submit/use-submit.base.spec.ts +2 -2
  41. package/__tests__/features/use-submit/use-submit.cancel.spec.ts +1 -1
  42. package/__tests__/features/use-submit/use-submit.concurrency.spec.ts +1 -1
  43. package/__tests__/features/use-submit/use-submit.debounce.spec.ts +8 -8
  44. package/__tests__/features/use-submit/use-submit.methods.spec.ts +44 -46
  45. package/__tests__/features/use-submit/use-submit.optimistic.spec.ts +548 -0
  46. package/__tests__/features/use-submit/use-submit.queue.spec.ts +3 -3
  47. package/__tests__/features/use-submit/use-submit.retry.spec.ts +4 -4
  48. package/__tests__/features/use-submit/use-submit.revalidate.spec.ts +5 -5
  49. package/__tests__/features/use-submit/use-submit.submit.spec.ts +4 -3
  50. package/__tests__/features/use-submit/use-submit.typescript.spec.ts +325 -0
  51. package/__tests__/shared/isolation.tests.ts +1 -1
  52. package/__tests__/shared/response.tests.ts +5 -4
  53. package/__tests__/tsconfig.json +21 -2
  54. package/__tests__/utils/cache.utils.ts +6 -4
  55. package/__tests__/utils/emitter.utils.ts +3 -2
  56. package/__tests__/utils/listener.utils.ts +3 -2
  57. package/__tests__/utils/request.utils.ts +6 -6
  58. package/__tests__/utils/state.utils.ts +1 -1
  59. package/__tests__/utils/use-app-manager.utils.ts +1 -1
  60. package/__tests__/utils/use-cache.utils.ts +3 -2
  61. package/__tests__/utils/use-emitter.utils.ts +3 -2
  62. package/__tests__/utils/use-fetch.utils.ts +4 -3
  63. package/__tests__/utils/use-listener.utils.ts +3 -2
  64. package/__tests__/utils/use-queue.utils.ts +4 -2
  65. package/__tests__/utils/use-request-events.utils.ts +3 -2
  66. package/__tests__/utils/use-socket-state.utils.ts +3 -2
  67. package/__tests__/utils/use-submit.utils.ts +3 -2
  68. package/__tests__/utils/use-tracked-state.utils.ts +3 -2
  69. package/__tests__/vitest.setup.ts +8 -0
  70. package/dist/helpers/index.d.ts +4 -0
  71. package/dist/helpers/index.d.ts.map +1 -0
  72. package/dist/helpers/use-request-events/index.d.ts +3 -0
  73. package/dist/helpers/use-request-events/index.d.ts.map +1 -0
  74. package/dist/helpers/use-request-events/use-request-events.hooks.d.ts +10 -0
  75. package/dist/helpers/use-request-events/use-request-events.hooks.d.ts.map +1 -0
  76. package/dist/helpers/use-request-events/use-request-events.types.d.ts +78 -0
  77. package/dist/helpers/use-request-events/use-request-events.types.d.ts.map +1 -0
  78. package/dist/helpers/use-socket-state/index.d.ts +4 -0
  79. package/dist/helpers/use-socket-state/index.d.ts.map +1 -0
  80. package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts +4 -0
  81. package/dist/helpers/use-socket-state/use-socket-state.constants.d.ts.map +1 -0
  82. package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts +24 -0
  83. package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts.map +1 -0
  84. package/dist/helpers/use-socket-state/use-socket-state.types.d.ts +12 -0
  85. package/dist/helpers/use-socket-state/use-socket-state.types.d.ts.map +1 -0
  86. package/dist/helpers/use-tracked-state/index.d.ts +5 -0
  87. package/dist/helpers/use-tracked-state/index.d.ts.map +1 -0
  88. package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts +3 -0
  89. package/dist/helpers/use-tracked-state/use-tracked-state.constants.d.ts.map +1 -0
  90. package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts +12 -0
  91. package/dist/helpers/use-tracked-state/use-tracked-state.hooks.d.ts.map +1 -0
  92. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts +113 -0
  93. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts.map +1 -0
  94. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts +29 -0
  95. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts.map +1 -0
  96. package/dist/hooks/use-app-manager/index.d.ts +3 -0
  97. package/dist/hooks/use-app-manager/index.d.ts.map +1 -0
  98. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +4 -0
  99. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts.map +1 -0
  100. package/dist/hooks/use-app-manager/use-app-manager.types.d.ts +19 -0
  101. package/dist/hooks/use-app-manager/use-app-manager.types.d.ts.map +1 -0
  102. package/dist/hooks/use-cache/index.d.ts +4 -0
  103. package/dist/hooks/use-cache/index.d.ts.map +1 -0
  104. package/dist/hooks/use-cache/use-cache.constants.d.ts +6 -0
  105. package/dist/hooks/use-cache/use-cache.constants.d.ts.map +1 -0
  106. package/dist/hooks/use-cache/use-cache.hooks.d.ts +4 -0
  107. package/dist/hooks/use-cache/use-cache.hooks.d.ts.map +1 -0
  108. package/dist/hooks/use-cache/use-cache.types.d.ts +24 -0
  109. package/dist/hooks/use-cache/use-cache.types.d.ts.map +1 -0
  110. package/dist/hooks/use-emitter/index.d.ts +3 -0
  111. package/dist/hooks/use-emitter/index.d.ts.map +1 -0
  112. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +26 -0
  113. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts.map +1 -0
  114. package/dist/hooks/use-emitter/use-emitter.types.d.ts +4 -0
  115. package/dist/hooks/use-emitter/use-emitter.types.d.ts.map +1 -0
  116. package/dist/hooks/use-fetch/index.d.ts +5 -0
  117. package/dist/hooks/use-fetch/index.d.ts.map +1 -0
  118. package/dist/hooks/use-fetch/use-fetch.constants.d.ts +8 -0
  119. package/dist/hooks/use-fetch/use-fetch.constants.d.ts.map +1 -0
  120. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +10 -0
  121. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts.map +1 -0
  122. package/dist/hooks/use-fetch/use-fetch.types.d.ts +118 -0
  123. package/dist/hooks/use-fetch/use-fetch.types.d.ts.map +1 -0
  124. package/dist/hooks/use-fetch/use-fetch.utils.d.ts +2 -0
  125. package/dist/hooks/use-fetch/use-fetch.utils.d.ts.map +1 -0
  126. package/dist/hooks/use-listener/index.d.ts +3 -0
  127. package/dist/hooks/use-listener/index.d.ts.map +1 -0
  128. package/dist/hooks/use-listener/use-listener.hooks.d.ts +31 -0
  129. package/dist/hooks/use-listener/use-listener.hooks.d.ts.map +1 -0
  130. package/dist/hooks/use-listener/use-listener.types.d.ts +4 -0
  131. package/dist/hooks/use-listener/use-listener.types.d.ts.map +1 -0
  132. package/dist/hooks/use-queue/index.d.ts +4 -0
  133. package/dist/hooks/use-queue/index.d.ts.map +1 -0
  134. package/dist/hooks/use-queue/use-queue.constants.d.ts +4 -0
  135. package/dist/hooks/use-queue/use-queue.constants.d.ts.map +1 -0
  136. package/dist/hooks/use-queue/use-queue.hooks.d.ts +10 -0
  137. package/dist/hooks/use-queue/use-queue.hooks.d.ts.map +1 -0
  138. package/dist/hooks/use-queue/use-queue.types.d.ts +58 -0
  139. package/dist/hooks/use-queue/use-queue.types.d.ts.map +1 -0
  140. package/dist/hooks/use-stream/index.d.ts +3 -0
  141. package/dist/hooks/use-stream/index.d.ts.map +1 -0
  142. package/dist/hooks/use-stream/use-stream.hooks.d.ts +11 -0
  143. package/dist/hooks/use-stream/use-stream.hooks.d.ts.map +1 -0
  144. package/dist/hooks/use-stream/use-stream.types.d.ts +52 -0
  145. package/dist/hooks/use-stream/use-stream.types.d.ts.map +1 -0
  146. package/dist/hooks/use-submit/index.d.ts +4 -0
  147. package/dist/hooks/use-submit/index.d.ts.map +1 -0
  148. package/dist/hooks/use-submit/use-submit.constants.d.ts +8 -0
  149. package/dist/hooks/use-submit/use-submit.constants.d.ts.map +1 -0
  150. package/dist/hooks/use-submit/use-submit.hooks.d.ts +10 -0
  151. package/dist/hooks/use-submit/use-submit.hooks.d.ts.map +1 -0
  152. package/dist/hooks/use-submit/use-submit.types.d.ts +115 -0
  153. package/dist/hooks/use-submit/use-submit.types.d.ts.map +1 -0
  154. package/dist/index.d.ts +12 -733
  155. package/dist/index.d.ts.map +1 -0
  156. package/dist/index.mjs +1935 -0
  157. package/dist/index.mjs.map +1 -0
  158. package/dist/provider/index.d.ts +3 -0
  159. package/dist/provider/index.d.ts.map +1 -0
  160. package/dist/provider/provider.d.ts +13 -0
  161. package/dist/provider/provider.d.ts.map +1 -0
  162. package/dist/provider/provider.types.d.ts +31 -0
  163. package/dist/provider/provider.types.d.ts.map +1 -0
  164. package/dist/utils/bounce.utils.d.ts +8 -0
  165. package/dist/utils/bounce.utils.d.ts.map +1 -0
  166. package/dist/utils/deep-equal.utils.d.ts +14 -0
  167. package/dist/utils/deep-equal.utils.d.ts.map +1 -0
  168. package/dist/utils/index.d.ts +4 -0
  169. package/dist/utils/index.d.ts.map +1 -0
  170. package/dist/utils/tracked-proxy.utils.d.ts +7 -0
  171. package/dist/utils/tracked-proxy.utils.d.ts.map +1 -0
  172. package/package.json +21 -13
  173. package/src/helpers/use-request-events/use-request-events.hooks.ts +60 -14
  174. package/src/helpers/use-request-events/use-request-events.types.ts +19 -12
  175. package/src/helpers/use-socket-state/use-socket-state.constants.ts +2 -2
  176. package/src/helpers/use-socket-state/use-socket-state.hooks.ts +47 -13
  177. package/src/helpers/use-socket-state/use-socket-state.types.ts +1 -1
  178. package/src/helpers/use-tracked-state/use-tracked-state.constants.ts +1 -1
  179. package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +74 -22
  180. package/src/helpers/use-tracked-state/use-tracked-state.types.ts +7 -2
  181. package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +39 -4
  182. package/src/hooks/use-app-manager/use-app-manager.hooks.ts +2 -2
  183. package/src/hooks/use-cache/use-cache.hooks.ts +33 -41
  184. package/src/hooks/use-cache/use-cache.types.ts +3 -3
  185. package/src/hooks/use-emitter/use-emitter.hooks.ts +17 -16
  186. package/src/hooks/use-fetch/use-fetch.constants.ts +5 -2
  187. package/src/hooks/use-fetch/use-fetch.hooks.ts +109 -51
  188. package/src/hooks/use-fetch/use-fetch.types.ts +18 -3
  189. package/src/hooks/use-listener/use-listener.hooks.ts +19 -27
  190. package/src/hooks/use-queue/use-queue.constants.ts +2 -2
  191. package/src/hooks/use-queue/use-queue.hooks.ts +25 -6
  192. package/src/hooks/use-queue/use-queue.types.ts +8 -2
  193. package/src/hooks/use-stream/index.ts +2 -0
  194. package/src/hooks/use-stream/use-stream.hooks.ts +164 -0
  195. package/src/hooks/use-stream/use-stream.types.ts +53 -0
  196. package/src/hooks/use-submit/use-submit.constants.ts +2 -2
  197. package/src/hooks/use-submit/use-submit.hooks.ts +43 -48
  198. package/src/hooks/use-submit/use-submit.types.ts +9 -9
  199. package/src/index.ts +1 -0
  200. package/src/provider/provider.tsx +1 -1
  201. package/src/provider/provider.types.ts +8 -8
  202. package/src/utils/index.ts +1 -0
  203. package/src/utils/tracked-proxy.utils.ts +19 -0
  204. package/tsconfig.json +1 -1
  205. package/vite.config.ts +45 -0
  206. package/.eslintrc.json +0 -11
  207. package/__tests__/features/use-fetch/use-fetch.suspense.ts +0 -37
  208. package/__tests__/global.d.ts +0 -1
  209. package/__tests__/jest.setup.ts +0 -9
  210. package/dist/index.js +0 -1541
  211. package/dist/index.js.map +0 -7
  212. package/jest.config.ts +0 -6
package/dist/index.d.ts CHANGED
@@ -1,733 +1,12 @@
1
- import { RequestInstance, RequestResponseEventType, ResponseSuccessType, ExtractResponseType, ExtractAdapterType, ResponseErrorType, ExtractErrorType, ResponseType, RequestEventType, RequestProgressEventType, Dispatcher, LoggerMethods, CacheValueType, ExtractAdapterStatusType, ExtractAdapterExtraType, CacheSetState, NullableType, ExtractAdapterResolvedType, ResponseDetailsType, RequiredKeys, RequestSendType, QueueItemType, ProgressType, ClientInstance } from '@hyper-fetch/core';
2
- import { SocketInstance, ExtractSocketExtraType, ListenerInstance, ExtractListenerResponseType, EmitterInstance, EmitterCallbackErrorType, EmitType } from '@hyper-fetch/sockets';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
4
- import React from 'react';
5
-
6
- /**
7
- * This hooks aims to retrieve data from server.
8
- * @param request Request instance
9
- * @param options Hook options
10
- * @returns
11
- */
12
- declare const useFetch: <R extends RequestInstance>(request: R, options?: UseFetchOptionsType<R>) => UseFetchReturnType<R>;
13
-
14
- /**
15
- * This is helper hook that handles main Hyper-Fetch event/data flow
16
- * @internal
17
- * @param options
18
- * @returns
19
- */
20
- declare const useRequestEvents: <R extends RequestInstance>({ request, dispatcher, logger, actions, setCacheData, getIsDataProcessing, }: UseRequestEventsPropsType<R>) => UseRequestEventsReturnType<R>;
21
-
22
- type UseRequestEventsDataMap = {
23
- unmount: VoidFunction;
24
- };
25
- type UseRequestEventsLifecycleMap = Map<string, {
26
- unmount: VoidFunction;
27
- }>;
28
- type UseRequestEventsPropsType<T extends RequestInstance> = {
29
- request: T;
30
- dispatcher: Dispatcher<ExtractAdapterType<T>>;
31
- logger: LoggerMethods;
32
- actions: UseTrackedStateActions<T>;
33
- setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
34
- getIsDataProcessing: (cacheKey: string) => boolean;
35
- };
36
- type UseRequestEventsActionsType<T extends RequestInstance> = {
37
- /**
38
- * Callback that allows canceling ongoing requests from the given queryKey.
39
- */
40
- abort: () => void;
41
- /**
42
- * Helper hook listening on success response.
43
- */
44
- onSuccess: (callback: OnSuccessCallbackType<T>) => void;
45
- /**
46
- * Helper hook listening on error response.
47
- */
48
- onError: (callback: OnErrorCallbackType<T>) => void;
49
- /**
50
- * Helper hook listening on aborting of requests. Abort events are not triggering onError callbacks.
51
- */
52
- onAbort: (callback: OnErrorCallbackType<T>) => void;
53
- /**
54
- * 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.
55
- */
56
- onOfflineError: (callback: OnErrorCallbackType<T>) => void;
57
- /**
58
- * Helper hook listening on any response.
59
- */
60
- onFinished: (callback: OnFinishedCallbackType<T>) => void;
61
- /**
62
- * Helper hook listening on request start.
63
- */
64
- onRequestStart: (callback: OnStartCallbackType<T>) => void;
65
- /**
66
- * Helper hook listening on response start(before we receive all data from server).
67
- */
68
- onResponseStart: (callback: OnStartCallbackType<T>) => void;
69
- /**
70
- * 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.
71
- */
72
- onDownloadProgress: (callback: OnProgressCallbackType) => void;
73
- /**
74
- * 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.
75
- */
76
- onUploadProgress: (callback: OnProgressCallbackType) => void;
77
- };
78
- type UseRequestEventsReturnType<T extends RequestInstance> = [
79
- UseRequestEventsActionsType<T>,
80
- {
81
- addCacheDataListener: (request: T) => VoidFunction;
82
- clearCacheDataListener: VoidFunction;
83
- addLifecycleListeners: (request: T, requestId?: string) => VoidFunction;
84
- removeLifecycleListener: (requestId: string) => void;
85
- clearLifecycleListeners: () => void;
86
- }
87
- ];
88
- type CallbackParameters<Request extends RequestInstance, ResponseType> = {
89
- response: ResponseType;
90
- } & Omit<RequestResponseEventType<Request>, "response">;
91
- type OnSuccessCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ResponseSuccessType<ExtractResponseType<Request>, ExtractAdapterType<Request>>>) => void | Promise<void>;
92
- type OnErrorCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ResponseErrorType<ExtractErrorType<Request>, ExtractAdapterType<Request>>>) => void | Promise<void>;
93
- type OnFinishedCallbackType<Request extends RequestInstance> = (params: CallbackParameters<Request, ResponseType<ExtractResponseType<Request>, ExtractErrorType<Request>, ExtractAdapterType<Request>>>) => void | Promise<void>;
94
- type OnStartCallbackType<Request extends RequestInstance> = (data: RequestEventType<Request>) => void | Promise<void>;
95
- type OnProgressCallbackType = <Request extends RequestInstance>(data: RequestProgressEventType<Request>) => void | Promise<void>;
96
-
97
- /**
98
- * Check if value is empty
99
- * @param value any object or primitive
100
- * @returns true when value is empty
101
- */
102
- declare const isEmpty: (value: unknown) => boolean;
103
- /**
104
- * Allow to deep compare any passed values
105
- * @param firstValue unknown
106
- * @param secondValue unknown
107
- * @returns true when elements are equal
108
- */
109
- declare const isEqual: (firstValue: unknown, secondValue: unknown) => boolean;
110
-
111
- declare const getBounceData: (bounceData: {
112
- reset: () => void;
113
- active: boolean;
114
- }) => {
115
- reset: () => void;
116
- active: boolean;
117
- };
118
-
119
- type UseTrackedStateProps<T extends RequestInstance> = {
120
- request: T;
121
- logger: LoggerMethods;
122
- initialResponse: NullableType<Partial<ExtractAdapterResolvedType<T>>>;
123
- dispatcher: Dispatcher<ExtractAdapterType<T>>;
124
- dependencyTracking: boolean;
125
- deepCompare: boolean | typeof isEqual;
126
- disabled?: boolean;
127
- revalidate?: boolean;
128
- };
129
- type UseTrackedStateReturn<T extends RequestInstance> = [
130
- UseTrackedStateType<T>,
131
- UseTrackedStateActions<T>,
132
- {
133
- setRenderKey: (renderKey: keyof UseTrackedStateType<T>) => void;
134
- setCacheData: (cacheData: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>) => void;
135
- getStaleStatus: () => boolean;
136
- getIsDataProcessing: (cacheKey: string) => boolean;
137
- }
138
- ];
139
- type UseTrackedStateType<T extends RequestInstance = RequestInstance> = {
140
- /**
141
- * Request response data
142
- */
143
- data: null | ExtractResponseType<T>;
144
- /**
145
- * Request response error
146
- */
147
- error: null | ExtractErrorType<T>;
148
- /**
149
- * Request loading state
150
- */
151
- loading: boolean;
152
- /**
153
- * Request status
154
- */
155
- status: null | ExtractAdapterStatusType<ExtractAdapterType<T>> | null;
156
- /**
157
- * Request additional response data
158
- */
159
- extra: null | ExtractAdapterExtraType<ExtractAdapterType<T>>;
160
- /**
161
- * Information whether request succeeded
162
- */
163
- success: boolean;
164
- /**
165
- * Request attempts
166
- */
167
- retries: number;
168
- /**
169
- * Request response timestamp
170
- */
171
- responseTimestamp: null | Date;
172
- /**
173
- * Request response timestamp
174
- */
175
- requestTimestamp: null | Date;
176
- };
177
- type UseTrackedStateActions<T extends RequestInstance> = {
178
- /**
179
- * Action to set custom data. We can do it locally(inside hook state).
180
- * If you need to update cache data use client.cache.update(). method.
181
- */
182
- setData: (data: CacheSetState<ExtractResponseType<T> | null>) => void;
183
- /**
184
- * Action to set custom error. We can do it locally(inside hook state).
185
- * If you need to update cache data use client.cache.update() method.
186
- */
187
- setError: (error: CacheSetState<ExtractErrorType<T> | null>) => void;
188
- /**
189
- * Action to set custom loading. We can do it locally(inside hook state).
190
- * If you need to update cache data use client.cache.update() method.
191
- */
192
- setLoading: (loading: CacheSetState<boolean>) => void;
193
- /**
194
- * Action to set custom status. We can do it locally(inside hook state).
195
- * If you need to turn on loading for all listening hooks use client.requestManager.events.emitLoading() method.
196
- */
197
- setStatus: (status: CacheSetState<ExtractAdapterStatusType<ExtractAdapterType<T>>>) => void;
198
- /**
199
- * Action to set custom success. We can do it locally(inside hook state).
200
- * If you need to update cache data use client.cache.update() method.
201
- */
202
- setSuccess: (success: CacheSetState<boolean>) => void;
203
- /**
204
- * Action to set custom additional data. We can do it locally(inside hook state).
205
- * If you need to update cache data use client.cache.update() method.
206
- */
207
- setExtra: (extra: CacheSetState<ExtractAdapterExtraType<ExtractAdapterType<T>> | null>) => void;
208
- /**
209
- * Action to set custom retries count. We can do it locally(inside hook state).
210
- * If you need to update cache data use client.cache.update() method.
211
- */
212
- setRetries: (retries: CacheSetState<number>) => void;
213
- /**
214
- * Action to set custom timestamp. We can do it locally(inside hook state).
215
- * If you need to update cache data use client.cache.update() method.
216
- */
217
- setResponseTimestamp: (timestamp: CacheSetState<Date>) => void;
218
- /**
219
- * Action to set custom timestamp. We can do it locally(inside hook state).
220
- * If you need to update cache data use client.cache.update() method.
221
- */
222
- setRequestTimestamp: (timestamp: CacheSetState<Date>) => void;
223
- };
224
-
225
- declare const initialState: UseTrackedStateType;
226
-
227
- /**
228
- *
229
- * @param request
230
- * @param initialResponse
231
- * @param dispatcher
232
- * @param dependencies
233
- * @internal
234
- */
235
- declare const useTrackedState: <T extends RequestInstance>({ request, dispatcher, initialResponse, deepCompare, dependencyTracking, disabled, revalidate, }: UseTrackedStateProps<T>) => UseTrackedStateReturn<T>;
236
-
237
- declare const getDetailsState: (state?: UseTrackedStateType<RequestInstance>, details?: Partial<ResponseDetailsType>) => ResponseDetailsType;
238
- declare const isStaleCacheData: (staleTime: number, staleTimestamp: NullableType<Date | number>) => boolean;
239
- declare const getValidCacheData: <T extends RequestInstance>(request: T, initialResponse: NullableType<Partial<ExtractAdapterResolvedType<T>>>, cacheData: NullableType<CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>>>) => CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>, ExtractAdapterType<T>> | null;
240
- declare const getTimestamp: (timestamp?: NullableType<number | Date>) => Date | null;
241
- declare const getIsInitiallyLoading: <T extends RequestInstance>({ queryKey, dispatcher, hasState, revalidate, disabled, }: {
242
- queryKey: string;
243
- dispatcher: Dispatcher<ExtractAdapterType<T>>;
244
- hasState: boolean;
245
- revalidate?: boolean;
246
- disabled?: boolean;
247
- }) => boolean;
248
- declare const getInitialState: <T extends RequestInstance>({ initialResponse, dispatcher, request, disabled, revalidate, }: {
249
- initialResponse: NullableType<Partial<ExtractAdapterResolvedType<T>>>;
250
- dispatcher: Dispatcher<ExtractAdapterType<T>>;
251
- request: T;
252
- disabled?: boolean;
253
- revalidate?: boolean;
254
- }) => UseTrackedStateType<T>;
255
-
256
- declare const useSocketState: <DataType, Socket extends SocketInstance>(socket: Socket, { dependencyTracking }: UseSocketStateProps) => readonly [UseSocketStateType<Socket, DataType>, {
257
- setData: (data: DataType | null) => void;
258
- setExtra: (extra: ExtractSocketExtraType<Socket> | null) => void;
259
- setConnected: (connected: boolean) => void;
260
- setConnecting: (connecting: boolean) => void;
261
- setTimestamp: (timestamp: number | null) => void;
262
- }, {
263
- onConnected: (callback: VoidFunction) => void;
264
- onDisconnected: (callback: VoidFunction) => void;
265
- onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
266
- onConnecting: (callback: VoidFunction) => void;
267
- onReconnecting: (callback: (data: {
268
- attempts: number;
269
- }) => void) => void;
270
- onReconnectingFailed: (callback: (data: {
271
- attempts: number;
272
- }) => void) => void;
273
- }, {
274
- readonly setRenderKey: (renderKey: keyof UseSocketStateType<Socket, DataType>) => void;
275
- }];
276
-
277
- type UseSocketStateType<Socket extends SocketInstance, DataType = any> = {
278
- data: DataType | null;
279
- extra: ExtractSocketExtraType<Socket> | null;
280
- connected: boolean;
281
- connecting: boolean;
282
- timestamp: number | null;
283
- };
284
- type UseSocketStateProps = {
285
- dependencyTracking?: boolean;
286
- };
287
-
288
- declare const initialSocketState: UseSocketStateType<SocketInstance>;
289
-
290
- type UseFetchOptionsType<R extends RequestInstance> = {
291
- /**
292
- * Refetch dependencies
293
- */
294
- dependencies?: any[];
295
- /**
296
- * Disable fetching
297
- */
298
- disabled?: boolean;
299
- /**
300
- * If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
301
- */
302
- dependencyTracking?: boolean;
303
- /**
304
- * If `true` it will refetch data in background no matter if we have it from cache.
305
- */
306
- revalidate?: boolean;
307
- /**
308
- * If cache is empty we can use placeholder data.
309
- */
310
- initialResponse?: NullableType<Partial<ExtractAdapterResolvedType<R>>>;
311
- /**
312
- * Enable/disable refresh data
313
- */
314
- refresh?: boolean;
315
- /**
316
- * Refresh data interval time
317
- */
318
- refreshTime?: number;
319
- /**
320
- * Enable/disable data refresh if our tab is not focused(used by user at given time).
321
- */
322
- refetchBlurred?: boolean;
323
- /**
324
- * Enable/disable data refresh if user leaves current tab.
325
- */
326
- refetchOnBlur?: boolean;
327
- /**
328
- * Enable/disable data refresh if user enters current tab.
329
- */
330
- refetchOnFocus?: boolean;
331
- /**
332
- * Enable/disable data refresh if network is restored.
333
- */
334
- refetchOnReconnect?: boolean;
335
- /**
336
- * Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.
337
- */
338
- bounce?: boolean;
339
- /**
340
- * Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
341
- */
342
- deepCompare?: boolean | typeof isEqual;
343
- } & ({
344
- /**
345
- * Possibility to choose between debounce and throttle approaches
346
- */
347
- bounceType?: "debounce";
348
- /**
349
- * How long it should bounce requests.
350
- */
351
- bounceTime?: number;
352
- /**
353
- * Not applicable for debounce mode
354
- */
355
- bounceTimeout?: void;
356
- } | {
357
- /**
358
- * Possibility to choose between debounce and throttle approaches
359
- */
360
- bounceType: "throttle";
361
- /**
362
- * How long it should bounce requests.
363
- */
364
- bounceTime?: number;
365
- /**
366
- * ONLY in throttle mode - options for handling last bounce event
367
- */
368
- bounceTimeout?: number;
369
- });
370
- type UseFetchReturnType<R extends RequestInstance> = UseTrackedStateType<R> & UseTrackedStateActions<R> & UseRequestEventsActionsType<R> & {
371
- /**
372
- * Data related to current state of the bounce usage
373
- */
374
- bounce: {
375
- /**
376
- * Active state of the bounce method
377
- */
378
- active: boolean;
379
- /**
380
- * Method to stop the active bounce method execution
381
- */
382
- reset: () => void;
383
- };
384
- /**
385
- * Refetch current request
386
- */
387
- refetch: () => void;
388
- };
389
-
390
- declare const getRefreshTime: (refreshTime: number, dataTimestamp?: Date) => number;
391
-
392
- type DefaultOptionsType$1 = RequiredKeys<Omit<UseFetchOptionsType<RequestInstance>, "initialResponse">> & {
393
- initialResponse: null;
394
- };
395
- declare const useFetchDefaultOptions: DefaultOptionsType$1;
396
-
397
- /**
398
- * This hooks aims to mutate data on the server.
399
- * @param request
400
- * @param options
401
- * @returns
402
- */
403
- declare const useSubmit: <RequestType extends RequestInstance>(request: RequestType, options?: UseSubmitOptionsType<RequestType>) => UseSubmitReturnType<RequestType>;
404
-
405
- type UseSubmitOptionsType<T extends RequestInstance> = {
406
- /**
407
- * Disable submitting
408
- */
409
- disabled?: boolean;
410
- /**
411
- * If cache is empty we can use placeholder data.
412
- */
413
- initialResponse?: NullableType<Partial<ExtractAdapterResolvedType<T>>>;
414
- /**
415
- * Enable/disable debouncing for often changing keys or refreshing, to limit requests to server.
416
- */
417
- bounce?: boolean;
418
- /**
419
- * If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
420
- */
421
- dependencyTracking?: boolean;
422
- /**
423
- * Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
424
- */
425
- deepCompare?: boolean | typeof isEqual;
426
- } & ({
427
- /**
428
- * Possibility to choose between debounce and throttle approaches
429
- */
430
- bounceType?: "debounce";
431
- /**
432
- * How long it should bounce requests.
433
- */
434
- bounceTime?: number;
435
- } | {
436
- /**
437
- * Possibility to choose between debounce and throttle approaches
438
- */
439
- bounceType: "throttle";
440
- /**
441
- * How long it should interval requests.
442
- */
443
- bounceTime?: number;
444
- /**
445
- * ONLY in throttle mode - options for handling last bounce event
446
- */
447
- bounceTimeout?: number;
448
- });
449
- type UseSubmitReturnType<RequestType extends RequestInstance> = Omit<UseTrackedStateType<RequestType>, "loading"> & UseTrackedStateActions<RequestType> & {
450
- /**
451
- * Callback which allows to cancel ongoing requests from given queryKey.
452
- */
453
- abort: () => void;
454
- /**
455
- * Helper hook listening on success response.
456
- */
457
- onSubmitSuccess: (callback: OnSuccessCallbackType<RequestType>) => void;
458
- /**
459
- * Helper hook listening on error response.
460
- */
461
- onSubmitError: (callback: OnErrorCallbackType<RequestType>) => void;
462
- /**
463
- * Helper hook listening on any response.
464
- */
465
- onSubmitFinished: (callback: OnFinishedCallbackType<RequestType>) => void;
466
- /**
467
- * Helper hook listening on request start.
468
- */
469
- onSubmitRequestStart: (callback: OnStartCallbackType<RequestType>) => void;
470
- /**
471
- * Helper hook listening on response start(before we receive all data from server).
472
- */
473
- onSubmitResponseStart: (callback: OnStartCallbackType<RequestType>) => void;
474
- /**
475
- * 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.
476
- */
477
- onSubmitDownloadProgress: (callback: OnProgressCallbackType) => void;
478
- /**
479
- * 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.
480
- */
481
- onSubmitUploadProgress: (callback: OnProgressCallbackType) => void;
482
- /**
483
- * Helper hook listening on aborting of requests. Abort events are not triggering onError callbacks.
484
- */
485
- onSubmitAbort: (callback: OnErrorCallbackType<RequestType>) => void;
486
- /**
487
- * 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.
488
- */
489
- onSubmitOfflineError: (callback: OnErrorCallbackType<RequestType>) => void;
490
- /**
491
- * Method responsible for triggering requests. It return Promise which will be resolved with the request.
492
- */
493
- submit: RequestSendType<RequestType>;
494
- /**
495
- * Request loading state
496
- */
497
- submitting: boolean;
498
- /**
499
- * Data related to current state of the bounce usage
500
- */
501
- bounce: {
502
- /**
503
- * Active state of the bounce method
504
- */
505
- active: boolean;
506
- /**
507
- * Method to stop the active bounce method execution
508
- */
509
- reset: () => void;
510
- };
511
- /**
512
- * Refetch current request
513
- */
514
- refetch: () => void;
515
- };
516
-
517
- type DefaultOptionsType = RequiredKeys<Omit<UseSubmitOptionsType<RequestInstance>, "initialResponse">> & {
518
- initialResponse: null;
519
- };
520
- declare const useSubmitDefaultOptions: DefaultOptionsType;
521
-
522
- /**
523
- * This hook allows to control dispatchers request queues
524
- * @param request
525
- * @param options
526
- * @returns
527
- */
528
- declare const useQueue: <Request extends RequestInstance>(request: Request, options?: UseQueueOptionsType) => UseQueueReturnType<Request>;
529
-
530
- type UseQueueOptionsType = {
531
- dispatcherType?: "auto" | "fetch" | "submit";
532
- keepFinishedRequests?: boolean;
533
- };
534
- type QueueRequest<Request extends RequestInstance> = QueueItemType<Request> & {
535
- failed?: boolean;
536
- canceled?: boolean;
537
- removed?: boolean;
538
- success?: boolean;
539
- /**
540
- * Uploading progress for given request
541
- */
542
- uploading: ProgressType;
543
- /**
544
- * Downloading progress for given request
545
- */
546
- downloading: ProgressType;
547
- /**
548
- * Callback which allow to start previously stopped request.
549
- */
550
- startRequest: () => void;
551
- /**
552
- * Callback which allow to stop request and cancel it if it's ongoing.
553
- */
554
- stopRequest: () => void;
555
- /**
556
- * Removes request from the queue
557
- */
558
- deleteRequest: () => void;
559
- };
560
- type UseQueueReturnType<T extends RequestInstance> = {
561
- /**
562
- * Queue status for provided request
563
- */
564
- stopped: boolean;
565
- /**
566
- * List of requests for provided request
567
- */
568
- requests: QueueRequest<T>[];
569
- /**
570
- * Request dispatcher instance
571
- */
572
- dispatcher: Dispatcher<ExtractAdapterType<T>>;
573
- /**
574
- * Callback which allow to stop queue, it will cancel ongoing requests.
575
- */
576
- stop: () => void;
577
- /**
578
- * Callback which allow to pause queue. It will allow ongoing requests to be finished, but will stop next from being send.
579
- */
580
- pause: () => void;
581
- /**
582
- * Callback which allow to start queue.
583
- */
584
- start: () => void;
585
- };
586
-
587
- declare const useQueueDefaultOptions: RequiredKeys<UseQueueOptionsType>;
588
-
589
- declare const useCache: <T extends RequestInstance>(request: T, options?: UseCacheOptionsType<T>) => UseCacheReturnType<T>;
590
-
591
- declare const useCacheDefaultOptions: {
592
- dependencyTracking: boolean;
593
- initialResponse: null;
594
- deepCompare: boolean;
595
- };
596
-
597
- type UseCacheOptionsType<T extends RequestInstance> = {
598
- /**
599
- * If `true` it will rerender only when values used by our component gets changed. Otherwise it will rerender on any change.
600
- */
601
- dependencyTracking?: boolean;
602
- /**
603
- * If cache is empty we can use placeholder data.
604
- */
605
- initialResponse?: CacheValueType<ExtractResponseType<T>, ExtractErrorType<T>>["data"] | null;
606
- /**
607
- * Deep comparison function for hook to check for equality in incoming data, to limit rerenders.
608
- */
609
- deepCompare?: boolean | typeof isEqual;
610
- };
611
- type UseCacheReturnType<T extends RequestInstance> = UseTrackedStateType<T> & UseTrackedStateActions<T> & {
612
- /**
613
- * Invalidate cache for the current request or pass custom key to trigger it by invalidationKey(Regex / cacheKey).
614
- */
615
- invalidate: (cacheKeys?: string | RegExp | RequestInstance | Array<string | RegExp | RequestInstance>) => void;
616
- };
617
-
618
- declare const useListener: <ListenerType extends ListenerInstance>(listener: ListenerType, options?: UseListenerOptionsType) => {
619
- listen: () => void;
620
- onEvent: (callback: NonNullable<((response: {
621
- data: ExtractListenerResponseType<ListenerType>;
622
- extra: Record<string, any>;
623
- }) => void) | null>) => void;
624
- onConnected: (callback: VoidFunction) => void;
625
- onDisconnected: (callback: VoidFunction) => void;
626
- onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
627
- onConnecting: (callback: VoidFunction) => void;
628
- onReconnecting: (callback: (data: {
629
- attempts: number;
630
- }) => void) => void;
631
- onReconnectingFailed: (callback: (data: {
632
- attempts: number;
633
- }) => void) => void;
634
- setData: (data: unknown) => void;
635
- setExtra: (extra: any) => void;
636
- setConnected: (connected: boolean) => void;
637
- setConnecting: (connecting: boolean) => void;
638
- setTimestamp: (timestamp: number | null) => void;
639
- data: unknown;
640
- extra: any;
641
- connected: boolean;
642
- connecting: boolean;
643
- timestamp: number | null;
644
- };
645
-
646
- type UseListenerOptionsType = {
647
- dependencyTracking?: boolean;
648
- };
649
-
650
- declare const useEmitter: <EmitterType extends EmitterInstance>(emitter: EmitterType, options?: UseEmitterOptionsType) => {
651
- onEmit: (callback: (emitter: EmitterType) => void) => void;
652
- onEmitError: (callback: EmitterCallbackErrorType) => void;
653
- emit: EmitType<EmitterType>;
654
- onConnected: (callback: VoidFunction) => void;
655
- onDisconnected: (callback: VoidFunction) => void;
656
- onError: <ErrorType = Event>(callback: (event: ErrorType) => void) => void;
657
- onConnecting: (callback: VoidFunction) => void;
658
- onReconnecting: (callback: (data: {
659
- attempts: number;
660
- }) => void) => void;
661
- onReconnectingFailed: (callback: (data: {
662
- attempts: number;
663
- }) => void) => void;
664
- setData: (data: unknown) => void;
665
- setExtra: (extra: any) => void;
666
- setConnected: (connected: boolean) => void;
667
- setConnecting: (connecting: boolean) => void;
668
- setTimestamp: (timestamp: number | null) => void;
669
- connected: boolean;
670
- connecting: boolean;
671
- };
672
-
673
- type UseEmitterOptionsType = {
674
- dependencyTracking?: boolean;
675
- };
676
-
677
- declare const useAppManager: <Client extends ClientInstance>(client: Client) => UseAppManagerReturnType;
678
-
679
- type UseAppManagerReturnType = {
680
- /**
681
- * Is window focused
682
- */
683
- isFocused: boolean;
684
- /**
685
- * Network online status
686
- */
687
- isOnline: boolean;
688
- /**
689
- * Network state setter
690
- */
691
- setOnline: (isOnline: boolean) => void;
692
- /**
693
- * Focus state setter
694
- */
695
- setFocused: (isFocused: boolean) => void;
696
- };
697
-
698
- type ProviderOptionsType = {
699
- useFetchConfig?: Partial<UseFetchOptionsType<RequestInstance>>;
700
- useSubmitConfig?: Partial<UseSubmitOptionsType<RequestInstance>>;
701
- useCacheConfig?: Partial<UseCacheOptionsType<RequestInstance>>;
702
- useQueueConfig?: Partial<UseQueueOptionsType>;
703
- useListener?: Partial<UseListenerOptionsType>;
704
- useEmitter?: Partial<UseEmitterOptionsType>;
705
- };
706
- type ProviderProps = {
707
- /**
708
- * Children to render
709
- */
710
- children: React.ReactNode;
711
- /**
712
- * Configuration to set for available hooks
713
- */
714
- config?: ProviderOptionsType;
715
- };
716
- type ProviderValueType = {
717
- config: ProviderOptionsType;
718
- setConfig: (newConfig: ProviderOptionsType) => void;
719
- };
720
-
721
- /**
722
- * Provider with configuration for hooks
723
- * @param options
724
- * @returns
725
- */
726
- declare const Provider: ({ children, config }: ProviderProps) => react_jsx_runtime.JSX.Element;
727
- /**
728
- * Hook to allow reading current context config
729
- * @returns
730
- */
731
- declare const useProvider: () => ProviderValueType;
732
-
733
- export { type CallbackParameters, type OnErrorCallbackType, type OnFinishedCallbackType, type OnProgressCallbackType, type OnStartCallbackType, type OnSuccessCallbackType, Provider, type ProviderOptionsType, type ProviderProps, type ProviderValueType, type QueueRequest, type UseAppManagerReturnType, type UseCacheOptionsType, type UseCacheReturnType, type UseEmitterOptionsType, type UseFetchOptionsType, type UseFetchReturnType, type UseListenerOptionsType, type UseQueueOptionsType, type UseQueueReturnType, type UseRequestEventsActionsType, type UseRequestEventsDataMap, type UseRequestEventsLifecycleMap, type UseRequestEventsPropsType, type UseRequestEventsReturnType, type UseSocketStateProps, type UseSocketStateType, type UseSubmitOptionsType, type UseSubmitReturnType, type UseTrackedStateActions, type UseTrackedStateProps, type UseTrackedStateReturn, type UseTrackedStateType, getBounceData, getDetailsState, getInitialState, getIsInitiallyLoading, getRefreshTime, getTimestamp, getValidCacheData, initialSocketState, initialState, isEmpty, isEqual, isStaleCacheData, useAppManager, useCache, useCacheDefaultOptions, useEmitter, useFetch, useFetchDefaultOptions, useListener, useProvider, useQueue, useQueueDefaultOptions, useRequestEvents, useSocketState, useSubmit, useSubmitDefaultOptions, useTrackedState };
1
+ export * from './hooks/use-fetch';
2
+ export * from './hooks/use-submit';
3
+ export * from './hooks/use-queue';
4
+ export * from './hooks/use-cache';
5
+ export * from './hooks/use-stream';
6
+ export * from './hooks/use-listener';
7
+ export * from './hooks/use-emitter';
8
+ export * from './hooks/use-app-manager';
9
+ export * from './helpers';
10
+ export * from './provider';
11
+ export * from './utils';
12
+ //# sourceMappingURL=index.d.ts.map