@gravity-ui/data-source 0.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 (255) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +82 -0
  3. package/build/cjs/core/constants.d.ts +1 -0
  4. package/build/cjs/core/constants.js +8 -0
  5. package/build/cjs/core/constants.js.map +1 -0
  6. package/build/cjs/core/index.d.ts +13 -0
  7. package/build/cjs/core/index.js +81 -0
  8. package/build/cjs/core/index.js.map +1 -0
  9. package/build/cjs/core/types/DataLoaderStatus.d.ts +1 -0
  10. package/build/cjs/core/types/DataLoaderStatus.js +6 -0
  11. package/build/cjs/core/types/DataLoaderStatus.js.map +1 -0
  12. package/build/cjs/core/types/DataManger.d.ts +10 -0
  13. package/build/cjs/core/types/DataManger.js +6 -0
  14. package/build/cjs/core/types/DataManger.js.map +1 -0
  15. package/build/cjs/core/types/DataSource.d.ts +28 -0
  16. package/build/cjs/core/types/DataSource.js +6 -0
  17. package/build/cjs/core/types/DataSource.js.map +1 -0
  18. package/build/cjs/core/types/utils.d.ts +1 -0
  19. package/build/cjs/core/types/utils.js +6 -0
  20. package/build/cjs/core/types/utils.js.map +1 -0
  21. package/build/cjs/core/utils/composeFullKey.d.ts +2 -0
  22. package/build/cjs/core/utils/composeFullKey.js +15 -0
  23. package/build/cjs/core/utils/composeFullKey.js.map +1 -0
  24. package/build/cjs/core/utils/composeKey.d.ts +2 -0
  25. package/build/cjs/core/utils/composeKey.js +14 -0
  26. package/build/cjs/core/utils/composeKey.js.map +1 -0
  27. package/build/cjs/core/utils/getError.d.ts +3 -0
  28. package/build/cjs/core/utils/getError.js +14 -0
  29. package/build/cjs/core/utils/getError.js.map +1 -0
  30. package/build/cjs/core/utils/getStatus.d.ts +4 -0
  31. package/build/cjs/core/utils/getStatus.js +14 -0
  32. package/build/cjs/core/utils/getStatus.js.map +1 -0
  33. package/build/cjs/core/utils/hasTag.d.ts +2 -0
  34. package/build/cjs/core/utils/hasTag.js +18 -0
  35. package/build/cjs/core/utils/hasTag.js.map +1 -0
  36. package/build/cjs/core/utils/mergeStatuses.d.ts +2 -0
  37. package/build/cjs/core/utils/mergeStatuses.js +20 -0
  38. package/build/cjs/core/utils/mergeStatuses.js.map +1 -0
  39. package/build/cjs/core/utils/skipContext.d.ts +2 -0
  40. package/build/cjs/core/utils/skipContext.js +15 -0
  41. package/build/cjs/core/utils/skipContext.js.map +1 -0
  42. package/build/cjs/core/utils/withCancellation.d.ts +9 -0
  43. package/build/cjs/core/utils/withCancellation.js +26 -0
  44. package/build/cjs/core/utils/withCancellation.js.map +1 -0
  45. package/build/cjs/index.d.ts +3 -0
  46. package/build/cjs/index.js +39 -0
  47. package/build/cjs/index.js.map +1 -0
  48. package/build/cjs/react/DataManagerContext.d.ts +3 -0
  49. package/build/cjs/react/DataManagerContext.js +16 -0
  50. package/build/cjs/react/DataManagerContext.js.map +1 -0
  51. package/build/cjs/react/components/DataInfiniteLoader/DataInfiniteLoader.d.ts +3 -0
  52. package/build/cjs/react/components/DataInfiniteLoader/DataInfiniteLoader.js +48 -0
  53. package/build/cjs/react/components/DataInfiniteLoader/DataInfiniteLoader.js.map +1 -0
  54. package/build/cjs/react/components/DataInfiniteLoader/index.d.ts +2 -0
  55. package/build/cjs/react/components/DataInfiniteLoader/index.js +13 -0
  56. package/build/cjs/react/components/DataInfiniteLoader/index.js.map +1 -0
  57. package/build/cjs/react/components/DataInfiniteLoader/types.d.ts +19 -0
  58. package/build/cjs/react/components/DataInfiniteLoader/types.js +6 -0
  59. package/build/cjs/react/components/DataInfiniteLoader/types.js.map +1 -0
  60. package/build/cjs/react/components/DataLoader/DataLoader.d.ts +3 -0
  61. package/build/cjs/react/components/DataLoader/DataLoader.js +35 -0
  62. package/build/cjs/react/components/DataLoader/DataLoader.js.map +1 -0
  63. package/build/cjs/react/components/DataLoader/index.d.ts +2 -0
  64. package/build/cjs/react/components/DataLoader/index.js +13 -0
  65. package/build/cjs/react/components/DataLoader/index.js.map +1 -0
  66. package/build/cjs/react/components/DataLoader/types.d.ts +11 -0
  67. package/build/cjs/react/components/DataLoader/types.js +6 -0
  68. package/build/cjs/react/components/DataLoader/types.js.map +1 -0
  69. package/build/cjs/react/components/types.d.ts +9 -0
  70. package/build/cjs/react/components/types.js +6 -0
  71. package/build/cjs/react/components/types.js.map +1 -0
  72. package/build/cjs/react/index.d.ts +5 -0
  73. package/build/cjs/react/index.js +55 -0
  74. package/build/cjs/react/index.js.map +1 -0
  75. package/build/cjs/react/withDataManager.d.ts +6 -0
  76. package/build/cjs/react/withDataManager.js +22 -0
  77. package/build/cjs/react/withDataManager.js.map +1 -0
  78. package/build/cjs/react-query/ClientDataManager.d.ts +15 -0
  79. package/build/cjs/react-query/ClientDataManager.js +94 -0
  80. package/build/cjs/react-query/ClientDataManager.js.map +1 -0
  81. package/build/cjs/react-query/hooks/useQueryContext.d.ts +2 -0
  82. package/build/cjs/react-query/hooks/useQueryContext.js +18 -0
  83. package/build/cjs/react-query/hooks/useQueryContext.js.map +1 -0
  84. package/build/cjs/react-query/hooks/useQueryData.d.ts +3 -0
  85. package/build/cjs/react-query/hooks/useQueryData.js +26 -0
  86. package/build/cjs/react-query/hooks/useQueryData.js.map +1 -0
  87. package/build/cjs/react-query/hooks/useQueryResponses.d.ts +11 -0
  88. package/build/cjs/react-query/hooks/useQueryResponses.js +18 -0
  89. package/build/cjs/react-query/hooks/useQueryResponses.js.map +1 -0
  90. package/build/cjs/react-query/hooks/useRefetchAll.d.ts +3 -0
  91. package/build/cjs/react-query/hooks/useRefetchAll.js +21 -0
  92. package/build/cjs/react-query/hooks/useRefetchAll.js.map +1 -0
  93. package/build/cjs/react-query/hooks/useRefetchErrored.d.ts +4 -0
  94. package/build/cjs/react-query/hooks/useRefetchErrored.js +25 -0
  95. package/build/cjs/react-query/hooks/useRefetchErrored.js.map +1 -0
  96. package/build/cjs/react-query/impl/infinite/factory.d.ts +2 -0
  97. package/build/cjs/react-query/impl/infinite/factory.js +14 -0
  98. package/build/cjs/react-query/impl/infinite/factory.js.map +1 -0
  99. package/build/cjs/react-query/impl/infinite/hooks.d.ts +3 -0
  100. package/build/cjs/react-query/impl/infinite/hooks.js +17 -0
  101. package/build/cjs/react-query/impl/infinite/hooks.js.map +1 -0
  102. package/build/cjs/react-query/impl/infinite/types.d.ts +18 -0
  103. package/build/cjs/react-query/impl/infinite/types.js +6 -0
  104. package/build/cjs/react-query/impl/infinite/types.js.map +1 -0
  105. package/build/cjs/react-query/impl/infinite/utils.d.ts +5 -0
  106. package/build/cjs/react-query/impl/infinite/utils.js +49 -0
  107. package/build/cjs/react-query/impl/infinite/utils.js.map +1 -0
  108. package/build/cjs/react-query/impl/plain/factory.d.ts +2 -0
  109. package/build/cjs/react-query/impl/plain/factory.js +14 -0
  110. package/build/cjs/react-query/impl/plain/factory.js.map +1 -0
  111. package/build/cjs/react-query/impl/plain/hooks.d.ts +3 -0
  112. package/build/cjs/react-query/impl/plain/hooks.js +17 -0
  113. package/build/cjs/react-query/impl/plain/hooks.js.map +1 -0
  114. package/build/cjs/react-query/impl/plain/types.d.ts +14 -0
  115. package/build/cjs/react-query/impl/plain/types.js +6 -0
  116. package/build/cjs/react-query/impl/plain/types.js.map +1 -0
  117. package/build/cjs/react-query/impl/plain/utils.d.ts +5 -0
  118. package/build/cjs/react-query/impl/plain/utils.js +28 -0
  119. package/build/cjs/react-query/impl/plain/utils.js.map +1 -0
  120. package/build/cjs/react-query/index.d.ts +15 -0
  121. package/build/cjs/react-query/index.js +83 -0
  122. package/build/cjs/react-query/index.js.map +1 -0
  123. package/build/cjs/react-query/types.d.ts +7 -0
  124. package/build/cjs/react-query/types.js +6 -0
  125. package/build/cjs/react-query/types.js.map +1 -0
  126. package/build/cjs/react-query/utils/normalizeStatus.d.ts +3 -0
  127. package/build/cjs/react-query/utils/normalizeStatus.js +13 -0
  128. package/build/cjs/react-query/utils/normalizeStatus.js.map +1 -0
  129. package/build/esm/core/constants.d.ts +1 -0
  130. package/build/esm/core/constants.js +2 -0
  131. package/build/esm/core/constants.js.map +1 -0
  132. package/build/esm/core/index.d.ts +13 -0
  133. package/build/esm/core/index.js +10 -0
  134. package/build/esm/core/index.js.map +1 -0
  135. package/build/esm/core/types/DataLoaderStatus.d.ts +1 -0
  136. package/build/esm/core/types/DataLoaderStatus.js +2 -0
  137. package/build/esm/core/types/DataLoaderStatus.js.map +1 -0
  138. package/build/esm/core/types/DataManger.d.ts +10 -0
  139. package/build/esm/core/types/DataManger.js +2 -0
  140. package/build/esm/core/types/DataManger.js.map +1 -0
  141. package/build/esm/core/types/DataSource.d.ts +28 -0
  142. package/build/esm/core/types/DataSource.js +2 -0
  143. package/build/esm/core/types/DataSource.js.map +1 -0
  144. package/build/esm/core/types/utils.d.ts +1 -0
  145. package/build/esm/core/types/utils.js +2 -0
  146. package/build/esm/core/types/utils.js.map +1 -0
  147. package/build/esm/core/utils/composeFullKey.d.ts +2 -0
  148. package/build/esm/core/utils/composeFullKey.js +8 -0
  149. package/build/esm/core/utils/composeFullKey.js.map +1 -0
  150. package/build/esm/core/utils/composeKey.d.ts +2 -0
  151. package/build/esm/core/utils/composeKey.js +7 -0
  152. package/build/esm/core/utils/composeKey.js.map +1 -0
  153. package/build/esm/core/utils/getError.d.ts +3 -0
  154. package/build/esm/core/utils/getError.js +8 -0
  155. package/build/esm/core/utils/getError.js.map +1 -0
  156. package/build/esm/core/utils/getStatus.d.ts +4 -0
  157. package/build/esm/core/utils/getStatus.js +8 -0
  158. package/build/esm/core/utils/getStatus.js.map +1 -0
  159. package/build/esm/core/utils/hasTag.d.ts +2 -0
  160. package/build/esm/core/utils/hasTag.js +12 -0
  161. package/build/esm/core/utils/hasTag.js.map +1 -0
  162. package/build/esm/core/utils/mergeStatuses.d.ts +2 -0
  163. package/build/esm/core/utils/mergeStatuses.js +14 -0
  164. package/build/esm/core/utils/mergeStatuses.js.map +1 -0
  165. package/build/esm/core/utils/skipContext.d.ts +2 -0
  166. package/build/esm/core/utils/skipContext.js +9 -0
  167. package/build/esm/core/utils/skipContext.js.map +1 -0
  168. package/build/esm/core/utils/withCancellation.d.ts +9 -0
  169. package/build/esm/core/utils/withCancellation.js +19 -0
  170. package/build/esm/core/utils/withCancellation.js.map +1 -0
  171. package/build/esm/index.d.ts +3 -0
  172. package/build/esm/index.js +4 -0
  173. package/build/esm/index.js.map +1 -0
  174. package/build/esm/react/DataManagerContext.d.ts +3 -0
  175. package/build/esm/react/DataManagerContext.js +10 -0
  176. package/build/esm/react/DataManagerContext.js.map +1 -0
  177. package/build/esm/react/components/DataInfiniteLoader/DataInfiniteLoader.d.ts +3 -0
  178. package/build/esm/react/components/DataInfiniteLoader/DataInfiniteLoader.js +41 -0
  179. package/build/esm/react/components/DataInfiniteLoader/DataInfiniteLoader.js.map +1 -0
  180. package/build/esm/react/components/DataInfiniteLoader/index.d.ts +2 -0
  181. package/build/esm/react/components/DataInfiniteLoader/index.js +2 -0
  182. package/build/esm/react/components/DataInfiniteLoader/index.js.map +1 -0
  183. package/build/esm/react/components/DataInfiniteLoader/types.d.ts +19 -0
  184. package/build/esm/react/components/DataInfiniteLoader/types.js +2 -0
  185. package/build/esm/react/components/DataInfiniteLoader/types.js.map +1 -0
  186. package/build/esm/react/components/DataLoader/DataLoader.d.ts +3 -0
  187. package/build/esm/react/components/DataLoader/DataLoader.js +28 -0
  188. package/build/esm/react/components/DataLoader/DataLoader.js.map +1 -0
  189. package/build/esm/react/components/DataLoader/index.d.ts +2 -0
  190. package/build/esm/react/components/DataLoader/index.js +2 -0
  191. package/build/esm/react/components/DataLoader/index.js.map +1 -0
  192. package/build/esm/react/components/DataLoader/types.d.ts +11 -0
  193. package/build/esm/react/components/DataLoader/types.js +2 -0
  194. package/build/esm/react/components/DataLoader/types.js.map +1 -0
  195. package/build/esm/react/components/types.d.ts +9 -0
  196. package/build/esm/react/components/types.js +2 -0
  197. package/build/esm/react/components/types.js.map +1 -0
  198. package/build/esm/react/index.d.ts +5 -0
  199. package/build/esm/react/index.js +5 -0
  200. package/build/esm/react/index.js.map +1 -0
  201. package/build/esm/react/withDataManager.d.ts +6 -0
  202. package/build/esm/react/withDataManager.js +15 -0
  203. package/build/esm/react/withDataManager.js.map +1 -0
  204. package/build/esm/react-query/ClientDataManager.d.ts +15 -0
  205. package/build/esm/react-query/ClientDataManager.js +87 -0
  206. package/build/esm/react-query/ClientDataManager.js.map +1 -0
  207. package/build/esm/react-query/hooks/useQueryContext.d.ts +2 -0
  208. package/build/esm/react-query/hooks/useQueryContext.js +12 -0
  209. package/build/esm/react-query/hooks/useQueryContext.js.map +1 -0
  210. package/build/esm/react-query/hooks/useQueryData.d.ts +3 -0
  211. package/build/esm/react-query/hooks/useQueryData.js +20 -0
  212. package/build/esm/react-query/hooks/useQueryData.js.map +1 -0
  213. package/build/esm/react-query/hooks/useQueryResponses.d.ts +11 -0
  214. package/build/esm/react-query/hooks/useQueryResponses.js +12 -0
  215. package/build/esm/react-query/hooks/useQueryResponses.js.map +1 -0
  216. package/build/esm/react-query/hooks/useRefetchAll.d.ts +3 -0
  217. package/build/esm/react-query/hooks/useRefetchAll.js +15 -0
  218. package/build/esm/react-query/hooks/useRefetchAll.js.map +1 -0
  219. package/build/esm/react-query/hooks/useRefetchErrored.d.ts +4 -0
  220. package/build/esm/react-query/hooks/useRefetchErrored.js +18 -0
  221. package/build/esm/react-query/hooks/useRefetchErrored.js.map +1 -0
  222. package/build/esm/react-query/impl/infinite/factory.d.ts +2 -0
  223. package/build/esm/react-query/impl/infinite/factory.js +7 -0
  224. package/build/esm/react-query/impl/infinite/factory.js.map +1 -0
  225. package/build/esm/react-query/impl/infinite/hooks.d.ts +3 -0
  226. package/build/esm/react-query/impl/infinite/hooks.js +11 -0
  227. package/build/esm/react-query/impl/infinite/hooks.js.map +1 -0
  228. package/build/esm/react-query/impl/infinite/types.d.ts +18 -0
  229. package/build/esm/react-query/impl/infinite/types.js +2 -0
  230. package/build/esm/react-query/impl/infinite/types.js.map +1 -0
  231. package/build/esm/react-query/impl/infinite/utils.d.ts +5 -0
  232. package/build/esm/react-query/impl/infinite/utils.js +42 -0
  233. package/build/esm/react-query/impl/infinite/utils.js.map +1 -0
  234. package/build/esm/react-query/impl/plain/factory.d.ts +2 -0
  235. package/build/esm/react-query/impl/plain/factory.js +7 -0
  236. package/build/esm/react-query/impl/plain/factory.js.map +1 -0
  237. package/build/esm/react-query/impl/plain/hooks.d.ts +3 -0
  238. package/build/esm/react-query/impl/plain/hooks.js +11 -0
  239. package/build/esm/react-query/impl/plain/hooks.js.map +1 -0
  240. package/build/esm/react-query/impl/plain/types.d.ts +14 -0
  241. package/build/esm/react-query/impl/plain/types.js +2 -0
  242. package/build/esm/react-query/impl/plain/types.js.map +1 -0
  243. package/build/esm/react-query/impl/plain/utils.d.ts +5 -0
  244. package/build/esm/react-query/impl/plain/utils.js +21 -0
  245. package/build/esm/react-query/impl/plain/utils.js.map +1 -0
  246. package/build/esm/react-query/index.d.ts +15 -0
  247. package/build/esm/react-query/index.js +12 -0
  248. package/build/esm/react-query/index.js.map +1 -0
  249. package/build/esm/react-query/types.d.ts +7 -0
  250. package/build/esm/react-query/types.js +2 -0
  251. package/build/esm/react-query/types.js.map +1 -0
  252. package/build/esm/react-query/utils/normalizeStatus.d.ts +3 -0
  253. package/build/esm/react-query/utils/normalizeStatus.js +7 -0
  254. package/build/esm/react-query/utils/normalizeStatus.js.map +1 -0
  255. package/package.json +67 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["DataSource.ts"],"sourcesContent":["import type {idle} from '../constants';\n\nexport type DataSourceKey = readonly unknown[];\nexport type DataSourceTag = string;\n\ndeclare const errorHintSymbol: unique symbol;\ndeclare const stateHintSymbol: unique symbol;\n\nexport interface DataSource<\n TContext,\n TParams,\n TRequest,\n TResponse,\n TData,\n TError,\n TOptions,\n TState,\n TFetchContext,\n> {\n readonly name: string;\n\n fetch: (\n context: TContext,\n fetchContext: TFetchContext,\n request: TRequest,\n ) => Promise<TResponse> | TResponse;\n tags?: (params: ActualParams<this, TParams, TRequest>) => DataSourceTag[];\n\n transformParams?: (params: TParams) => TRequest;\n transformResponse?: (response: TResponse) => TData;\n\n [errorHintSymbol]?: TError;\n\n options?: TOptions;\n [stateHintSymbol]?: TState;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyDataSource = DataSource<any, any, any, any, any, any, any, any, any>;\n\nexport type DataSourceContext<TDataSource> =\n TDataSource extends DataSource<\n infer TContext,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TContext\n : never;\n\nexport type DataSourceParams<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer TParams,\n infer TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualParams<TDataSource, TParams, TRequest>\n : never;\n\nexport type DataSourceRequest<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TRequest\n : never;\n\nexport type DataSourceResponse<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer TResponse,\n infer _TData,\n infer _TError,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TResponse\n : never;\n\nexport type DataSourceData<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer TResponse,\n infer TData,\n infer _TError,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? ActualData<TData, TResponse>\n : never;\n\nexport type DataSourceError<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer TError,\n infer _TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TError\n : never;\n\nexport type DataSourceOptions<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer TOptions,\n infer _TState,\n infer _TFetchContext\n >\n ? TOptions\n : never;\n\nexport type DataSourceState<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TOptions,\n infer TState,\n infer _TFetchContext\n >\n ? TState\n : never;\n\nexport type DataSourceFetchContext<TDataSource> =\n TDataSource extends DataSource<\n infer _TContenxt,\n infer _TParams,\n infer _TRequest,\n infer _TResponse,\n infer _TData,\n infer _TError,\n infer _TOptions,\n infer _TState,\n infer TFetchContext\n >\n ? TFetchContext\n : never;\n\nexport type ActualParams<TDataSource extends AnyDataSource, TParams, TRequest> =\n | (unknown extends TParams\n ? TRequest\n : undefined extends TDataSource['transformParams']\n ? TRequest\n : TParams)\n | typeof idle;\n\nexport type ActualData<TData, TResponse> = unknown extends TData ? TResponse : TData;\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1 @@
1
+ export type AnyFunction = (...args: any[]) => any;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ // #sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["utils.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyFunction = (...args: any[]) => any;\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { AnyDataSource, DataSourceParams } from '../types/DataSource';
2
+ export declare const composeFullKey: <TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>) => readonly string[];
@@ -0,0 +1,8 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { composeKey } from './composeKey';
3
+ export var composeFullKey = function composeFullKey(dataSource, params) {
4
+ var _dataSource$tags, _dataSource$tags2;
5
+ var tags = (_dataSource$tags = (_dataSource$tags2 = dataSource.tags) === null || _dataSource$tags2 === void 0 ? void 0 : _dataSource$tags2.call(dataSource, params)) !== null && _dataSource$tags !== void 0 ? _dataSource$tags : [];
6
+ return [dataSource.name].concat(_toConsumableArray(tags), [composeKey(dataSource, params)]);
7
+ };
8
+ // #sourceMappingURL=composeFullKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["composeKey","composeFullKey","dataSource","params","_dataSource$tags","_dataSource$tags2","tags","call","name","concat","_toConsumableArray"],"sources":["composeFullKey.ts"],"sourcesContent":["import type {AnyDataSource, DataSourceParams} from '../types/DataSource';\n\nimport {composeKey} from './composeKey';\n\nexport const composeFullKey = <TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n): readonly string[] => {\n const tags = dataSource.tags?.(params) ?? [];\n\n return [dataSource.name, ...tags, composeKey(dataSource, params)];\n};\n"],"mappings":";AAEA,SAAQA,UAAU,QAAO,cAAc;AAEvC,OAAO,IAAMC,cAAc,GAAG,SAAjBA,cAAcA,CACvBC,UAAuB,EACvBC,MAAqC,EACjB;EAAA,IAAAC,gBAAA,EAAAC,iBAAA;EACpB,IAAMC,IAAI,IAAAF,gBAAA,IAAAC,iBAAA,GAAGH,UAAU,CAACI,IAAI,cAAAD,iBAAA,uBAAfA,iBAAA,CAAAE,IAAA,CAAAL,UAAU,EAAQC,MAAM,CAAC,cAAAC,gBAAA,cAAAA,gBAAA,GAAI,EAAE;EAE5C,QAAQF,UAAU,CAACM,IAAI,EAAAC,MAAA,CAAAC,kBAAA,CAAKJ,IAAI,IAAEN,UAAU,CAACE,UAAU,EAAEC,MAAM,CAAC;AACpE,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { AnyDataSource, DataSourceParams } from '../types/DataSource';
2
+ export declare const composeKey: <TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>) => string;
@@ -0,0 +1,7 @@
1
+ // TODO(DakEnviy): Do not use react-query in core
2
+ import { hashQueryKey } from '@tanstack/react-query';
3
+ import { idle } from '../constants';
4
+ export var composeKey = function composeKey(dataSource, params) {
5
+ return params === idle ? "".concat(dataSource.name, ":idle") : "".concat(dataSource.name, "(").concat(hashQueryKey(params), ")");
6
+ };
7
+ // #sourceMappingURL=composeKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["hashQueryKey","idle","composeKey","dataSource","params","concat","name"],"sources":["composeKey.ts"],"sourcesContent":["// TODO(DakEnviy): Do not use react-query in core\nimport {hashQueryKey} from '@tanstack/react-query';\n\nimport {idle} from '../constants';\nimport type {AnyDataSource, DataSourceParams} from '../types/DataSource';\n\nexport const composeKey = <TDataSource extends AnyDataSource>(\n dataSource: TDataSource,\n params: DataSourceParams<TDataSource>,\n): string =>\n params === idle ? `${dataSource.name}:idle` : `${dataSource.name}(${hashQueryKey(params)})`;\n"],"mappings":"AAAA;AACA,SAAQA,YAAY,QAAO,uBAAuB;AAElD,SAAQC,IAAI,QAAO,cAAc;AAGjC,OAAO,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CACnBC,UAAuB,EACvBC,MAAqC;EAAA,OAErCA,MAAM,KAAKH,IAAI,MAAAI,MAAA,CAAMF,UAAU,CAACG,IAAI,gBAAAD,MAAA,CAAaF,UAAU,CAACG,IAAI,OAAAD,MAAA,CAAIL,YAAY,CAACI,MAAM,CAAC,MAAG;AAAA","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export declare const getError: <T>(states: {
2
+ error: T | null;
3
+ }[]) => NonNullable<T> | null;
@@ -0,0 +1,8 @@
1
+ export var getError = function getError(states) {
2
+ var _states$find$error, _states$find;
3
+ return (_states$find$error = (_states$find = states.find(function (_ref) {
4
+ var error = _ref.error;
5
+ return Boolean(error);
6
+ })) === null || _states$find === void 0 ? void 0 : _states$find.error) !== null && _states$find$error !== void 0 ? _states$find$error : null;
7
+ };
8
+ // #sourceMappingURL=getError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["getError","states","_states$find$error","_states$find","find","_ref","error","Boolean"],"sources":["getError.ts"],"sourcesContent":["export const getError = <T>(states: {error: T | null}[]) => {\n return states.find(({error}) => Boolean(error))?.error ?? null;\n};\n"],"mappings":"AAAA,OAAO,IAAMA,QAAQ,GAAG,SAAXA,QAAQA,CAAOC,MAA2B,EAAK;EAAA,IAAAC,kBAAA,EAAAC,YAAA;EACxD,QAAAD,kBAAA,IAAAC,YAAA,GAAOF,MAAM,CAACG,IAAI,CAAC,UAAAC,IAAA;IAAA,IAAEC,KAAK,GAAAD,IAAA,CAALC,KAAK;IAAA,OAAMC,OAAO,CAACD,KAAK,CAAC;EAAA,EAAC,cAAAH,YAAA,uBAAxCA,YAAA,CAA0CG,KAAK,cAAAJ,kBAAA,cAAAA,kBAAA,GAAI,IAAI;AAClE,CAAC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ import type { DataLoaderStatus } from '../types/DataLoaderStatus';
2
+ export declare const getStatus: (states: {
3
+ status: DataLoaderStatus;
4
+ }[]) => DataLoaderStatus;
@@ -0,0 +1,8 @@
1
+ import { mergeStatuses } from './mergeStatuses';
2
+ export var getStatus = function getStatus(states) {
3
+ return mergeStatuses(states.map(function (_ref) {
4
+ var status = _ref.status;
5
+ return status;
6
+ }));
7
+ };
8
+ // #sourceMappingURL=getStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["mergeStatuses","getStatus","states","map","_ref","status"],"sources":["getStatus.ts"],"sourcesContent":["import type {DataLoaderStatus} from '../types/DataLoaderStatus';\n\nimport {mergeStatuses} from './mergeStatuses';\n\nexport const getStatus = (states: {status: DataLoaderStatus}[]) => {\n return mergeStatuses(states.map(({status}) => status));\n};\n"],"mappings":"AAEA,SAAQA,aAAa,QAAO,iBAAiB;AAE7C,OAAO,IAAMC,SAAS,GAAG,SAAZA,SAASA,CAAIC,MAAoC,EAAK;EAC/D,OAAOF,aAAa,CAACE,MAAM,CAACC,GAAG,CAAC,UAAAC,IAAA;IAAA,IAAEC,MAAM,GAAAD,IAAA,CAANC,MAAM;IAAA,OAAMA,MAAM;EAAA,EAAC,CAAC;AAC1D,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { DataSourceKey, DataSourceTag } from '../types/DataSource';
2
+ export declare const hasTag: (key: DataSourceKey, tag: DataSourceTag) => boolean;
@@ -0,0 +1,12 @@
1
+ export var hasTag = function hasTag(key, tag) {
2
+ if (!Array.isArray(key)) {
3
+ return false;
4
+ }
5
+ var index = key.indexOf(tag);
6
+
7
+ // First element — data source name
8
+ // Last element — full key
9
+ // Skip them for consistency
10
+ return index > 0 && index < key.length - 2;
11
+ };
12
+ // #sourceMappingURL=hasTag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["hasTag","key","tag","Array","isArray","index","indexOf","length"],"sources":["hasTag.ts"],"sourcesContent":["import type {DataSourceKey, DataSourceTag} from '../types/DataSource';\n\nexport const hasTag = (key: DataSourceKey, tag: DataSourceTag) => {\n if (!Array.isArray(key)) {\n return false;\n }\n\n const index = key.indexOf(tag);\n\n // First element — data source name\n // Last element — full key\n // Skip them for consistency\n return index > 0 && index < key.length - 2;\n};\n"],"mappings":"AAEA,OAAO,IAAMA,MAAM,GAAG,SAATA,MAAMA,CAAIC,GAAkB,EAAEC,GAAkB,EAAK;EAC9D,IAAI,CAACC,KAAK,CAACC,OAAO,CAACH,GAAG,CAAC,EAAE;IACrB,OAAO,KAAK;EAChB;EAEA,IAAMI,KAAK,GAAGJ,GAAG,CAACK,OAAO,CAACJ,GAAG,CAAC;;EAE9B;EACA;EACA;EACA,OAAOG,KAAK,GAAG,CAAC,IAAIA,KAAK,GAAGJ,GAAG,CAACM,MAAM,GAAG,CAAC;AAC9C,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { DataLoaderStatus } from '../types/DataLoaderStatus';
2
+ export declare const mergeStatuses: (statuses: DataLoaderStatus[]) => DataLoaderStatus;
@@ -0,0 +1,14 @@
1
+ export var mergeStatuses = function mergeStatuses(statuses) {
2
+ if (statuses.some(function (status) {
3
+ return status === 'error';
4
+ })) {
5
+ return 'error';
6
+ }
7
+ if (statuses.some(function (status) {
8
+ return status === 'loading';
9
+ })) {
10
+ return 'loading';
11
+ }
12
+ return 'success';
13
+ };
14
+ // #sourceMappingURL=mergeStatuses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["mergeStatuses","statuses","some","status"],"sources":["mergeStatuses.ts"],"sourcesContent":["import type {DataLoaderStatus} from '../types/DataLoaderStatus';\n\nexport const mergeStatuses = (statuses: DataLoaderStatus[]): DataLoaderStatus => {\n if (statuses.some((status) => status === 'error')) {\n return 'error';\n }\n\n if (statuses.some((status) => status === 'loading')) {\n return 'loading';\n }\n\n return 'success';\n};\n"],"mappings":"AAEA,OAAO,IAAMA,aAAa,GAAG,SAAhBA,aAAaA,CAAIC,QAA4B,EAAuB;EAC7E,IAAIA,QAAQ,CAACC,IAAI,CAAC,UAACC,MAAM;IAAA,OAAKA,MAAM,KAAK,OAAO;EAAA,EAAC,EAAE;IAC/C,OAAO,OAAO;EAClB;EAEA,IAAIF,QAAQ,CAACC,IAAI,CAAC,UAACC,MAAM;IAAA,OAAKA,MAAM,KAAK,SAAS;EAAA,EAAC,EAAE;IACjD,OAAO,SAAS;EACpB;EAEA,OAAO,SAAS;AACpB,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ import type { AnyFunction } from '../types/utils';
2
+ export declare const skipContext: <TFunc extends AnyFunction>(fetch: TFunc) => (_0: unknown, _1: unknown, ...args: Parameters<TFunc>) => ReturnType<TFunc>;
@@ -0,0 +1,9 @@
1
+ export var skipContext = function skipContext(fetch) {
2
+ return function (_0, _1) {
3
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
4
+ args[_key - 2] = arguments[_key];
5
+ }
6
+ return fetch.apply(void 0, args);
7
+ };
8
+ };
9
+ // #sourceMappingURL=skipContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["skipContext","fetch","_0","_1","_len","arguments","length","args","Array","_key","apply"],"sources":["skipContext.ts"],"sourcesContent":["import type {AnyFunction} from '../types/utils';\n\nexport const skipContext = <TFunc extends AnyFunction>(fetch: TFunc) => {\n return (_0: unknown, _1: unknown, ...args: Parameters<TFunc>): ReturnType<TFunc> => {\n return fetch(...args);\n };\n};\n"],"mappings":"AAEA,OAAO,IAAMA,WAAW,GAAG,SAAdA,WAAWA,CAA+BC,KAAY,EAAK;EACpE,OAAO,UAACC,EAAW,EAAEC,EAAW,EAAoD;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAA/CC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;IAAA;IACrC,OAAOR,KAAK,CAAAS,KAAA,SAAIH,IAAI,CAAC;EACzB,CAAC;AACL,CAAC","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import type { AnyDataSource } from '../types/DataSource';
2
+ export interface Cancellable {
3
+ cancel: () => void;
4
+ }
5
+ export declare const isCancellable: (value: unknown) => value is Cancellable;
6
+ export declare const isAbortable: (value: unknown) => value is {
7
+ signal: AbortSignal;
8
+ };
9
+ export declare const withCancellation: <TDataSource extends AnyDataSource>(fetch: TDataSource["fetch"]) => TDataSource["fetch"];
@@ -0,0 +1,19 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ export var isCancellable = function isCancellable(value) {
3
+ return _typeof(value) === 'object' && value !== null && 'cancel' in value && typeof value.cancel === 'function';
4
+ };
5
+ export var isAbortable = function isAbortable(value) {
6
+ return _typeof(value) === 'object' && value !== null && 'signal' in value && _typeof(value.signal) === 'object' && value.signal !== null && 'addEventListener' in value.signal && typeof value.signal.addEventListener === 'function';
7
+ };
8
+ export var withCancellation = function withCancellation(fetch) {
9
+ return function (context, fetchContext, request) {
10
+ var value = fetch(context, fetchContext, request);
11
+ if (isAbortable(fetchContext) && isCancellable(value)) {
12
+ fetchContext.signal.addEventListener('abort', function () {
13
+ value.cancel();
14
+ });
15
+ }
16
+ return value;
17
+ };
18
+ };
19
+ // #sourceMappingURL=withCancellation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isCancellable","value","_typeof","cancel","isAbortable","signal","addEventListener","withCancellation","fetch","context","fetchContext","request"],"sources":["withCancellation.ts"],"sourcesContent":["import type {AnyDataSource} from '../types/DataSource';\n\nexport interface Cancellable {\n cancel: () => void;\n}\n\nexport const isCancellable = (value: unknown): value is Cancellable => {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'cancel' in value &&\n typeof value.cancel === 'function'\n );\n};\n\nexport const isAbortable = (value: unknown): value is {signal: AbortSignal} => {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'signal' in value &&\n typeof value.signal === 'object' &&\n value.signal !== null &&\n 'addEventListener' in value.signal &&\n typeof value.signal.addEventListener === 'function'\n );\n};\n\nexport const withCancellation = <TDataSource extends AnyDataSource>(\n fetch: TDataSource['fetch'],\n): TDataSource['fetch'] => {\n return (context, fetchContext, request) => {\n const value = fetch(context, fetchContext, request);\n\n if (isAbortable(fetchContext) && isCancellable(value)) {\n fetchContext.signal.addEventListener('abort', () => {\n value.cancel();\n });\n }\n\n return value;\n };\n};\n"],"mappings":";AAMA,OAAO,IAAMA,aAAa,GAAG,SAAhBA,aAAaA,CAAIC,KAAc,EAA2B;EACnE,OACIC,OAAA,CAAOD,KAAK,MAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,QAAQ,IAAIA,KAAK,IACjB,OAAOA,KAAK,CAACE,MAAM,KAAK,UAAU;AAE1C,CAAC;AAED,OAAO,IAAMC,WAAW,GAAG,SAAdA,WAAWA,CAAIH,KAAc,EAAqC;EAC3E,OACIC,OAAA,CAAOD,KAAK,MAAK,QAAQ,IACzBA,KAAK,KAAK,IAAI,IACd,QAAQ,IAAIA,KAAK,IACjBC,OAAA,CAAOD,KAAK,CAACI,MAAM,MAAK,QAAQ,IAChCJ,KAAK,CAACI,MAAM,KAAK,IAAI,IACrB,kBAAkB,IAAIJ,KAAK,CAACI,MAAM,IAClC,OAAOJ,KAAK,CAACI,MAAM,CAACC,gBAAgB,KAAK,UAAU;AAE3D,CAAC;AAED,OAAO,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAgBA,CACzBC,KAA2B,EACJ;EACvB,OAAO,UAACC,OAAO,EAAEC,YAAY,EAAEC,OAAO,EAAK;IACvC,IAAMV,KAAK,GAAGO,KAAK,CAACC,OAAO,EAAEC,YAAY,EAAEC,OAAO,CAAC;IAEnD,IAAIP,WAAW,CAACM,YAAY,CAAC,IAAIV,aAAa,CAACC,KAAK,CAAC,EAAE;MACnDS,YAAY,CAACL,MAAM,CAACC,gBAAgB,CAAC,OAAO,EAAE,YAAM;QAChDL,KAAK,CAACE,MAAM,CAAC,CAAC;MAClB,CAAC,CAAC;IACN;IAEA,OAAOF,KAAK;EAChB,CAAC;AACL,CAAC","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ export * from './core';
2
+ export * from './react';
3
+ export * from './react-query';
@@ -0,0 +1,4 @@
1
+ export * from './core';
2
+ export * from './react';
3
+ export * from './react-query';
4
+ // #sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from './core';\nexport * from './react';\nexport * from './react-query';\n"],"mappings":"AAAA,cAAc,QAAQ;AACtB,cAAc,SAAS;AACvB,cAAc,eAAe","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ import type { DataManager } from '../core';
2
+ export declare const DataManagerContext: import("react").Context<DataManager | null>;
3
+ export declare const useDataManager: () => DataManager;
@@ -0,0 +1,10 @@
1
+ import { createContext, useContext } from 'react';
2
+ export var DataManagerContext = /*#__PURE__*/createContext(null);
3
+ export var useDataManager = function useDataManager() {
4
+ var dataManager = useContext(DataManagerContext);
5
+ if (!dataManager) {
6
+ throw new Error('DataManager is not provied by context. Use DataManagerContext.Provider to do it');
7
+ }
8
+ return dataManager;
9
+ };
10
+ // #sourceMappingURL=DataManagerContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createContext","useContext","DataManagerContext","useDataManager","dataManager","Error"],"sources":["DataManagerContext.ts"],"sourcesContent":["import {createContext, useContext} from 'react';\n\nimport type {DataManager} from '../core';\n\nexport const DataManagerContext = createContext<DataManager | null>(null);\n\nexport const useDataManager = () => {\n const dataManager = useContext(DataManagerContext);\n\n if (!dataManager) {\n throw new Error(\n 'DataManager is not provied by context. Use DataManagerContext.Provider to do it',\n );\n }\n\n return dataManager;\n};\n"],"mappings":"AAAA,SAAQA,aAAa,EAAEC,UAAU,QAAO,OAAO;AAI/C,OAAO,IAAMC,kBAAkB,gBAAGF,aAAa,CAAqB,IAAI,CAAC;AAEzE,OAAO,IAAMG,cAAc,GAAG,SAAjBA,cAAcA,CAAA,EAAS;EAChC,IAAMC,WAAW,GAAGH,UAAU,CAACC,kBAAkB,CAAC;EAElD,IAAI,CAACE,WAAW,EAAE;IACd,MAAM,IAAIC,KAAK,CACX,iFACJ,CAAC;EACL;EAEA,OAAOD,WAAW;AACtB,CAAC","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { DataInfiniteLoaderProps } from './types';
3
+ export declare const DataInfiniteLoader: <TError>({ status, error, errorAction: errorActionProp, hasNextPage, fetchNextPage, isFetchingNextPage, LoadingView, ErrorView, MoreView, children, }: DataInfiniteLoaderProps<TError>) => React.ReactNode;
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ export var DataInfiniteLoader = function DataInfiniteLoader(_ref) {
4
+ var status = _ref.status,
5
+ error = _ref.error,
6
+ errorActionProp = _ref.errorAction,
7
+ hasNextPage = _ref.hasNextPage,
8
+ fetchNextPage = _ref.fetchNextPage,
9
+ isFetchingNextPage = _ref.isFetchingNextPage,
10
+ LoadingView = _ref.LoadingView,
11
+ ErrorView = _ref.ErrorView,
12
+ MoreView = _ref.MoreView,
13
+ children = _ref.children;
14
+ var errorAction = React.useMemo(function () {
15
+ return typeof errorActionProp === 'function' ? {
16
+ handler: errorActionProp
17
+ } : errorActionProp;
18
+ }, [errorActionProp]);
19
+ var content = React.useMemo(function () {
20
+ if (status === 'loading') {
21
+ return /*#__PURE__*/_jsx(LoadingView, {});
22
+ }
23
+ if (status === 'error') {
24
+ return /*#__PURE__*/_jsx(ErrorView, {
25
+ error: error,
26
+ action: errorAction
27
+ });
28
+ }
29
+ if (status === 'success' && hasNextPage) {
30
+ return /*#__PURE__*/_jsx(MoreView, {
31
+ isLoading: isFetchingNextPage,
32
+ onClick: fetchNextPage
33
+ });
34
+ }
35
+ return null;
36
+ }, [status, hasNextPage, LoadingView, ErrorView, error, errorAction, MoreView, isFetchingNextPage, fetchNextPage]);
37
+ return /*#__PURE__*/_jsxs(_Fragment, {
38
+ children: [status === 'success' ? children : null, content]
39
+ });
40
+ };
41
+ // #sourceMappingURL=DataInfiniteLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","DataInfiniteLoader","_ref","status","error","errorActionProp","errorAction","hasNextPage","fetchNextPage","isFetchingNextPage","LoadingView","ErrorView","MoreView","children","useMemo","handler","content","action","isLoading","onClick"],"sources":["DataInfiniteLoader.tsx"],"sourcesContent":["import React from 'react';\n\nimport type {ErrorViewProps} from '../types';\n\nimport type {DataInfiniteLoaderProps} from './types';\n\nexport const DataInfiniteLoader = <TError,>({\n status,\n error,\n errorAction: errorActionProp,\n hasNextPage,\n fetchNextPage,\n isFetchingNextPage,\n LoadingView,\n ErrorView,\n MoreView,\n children,\n}: DataInfiniteLoaderProps<TError>): React.ReactNode => {\n const errorAction = React.useMemo<ErrorViewProps<TError>['action']>(\n () =>\n typeof errorActionProp === 'function' ? {handler: errorActionProp} : errorActionProp,\n [errorActionProp],\n );\n\n const content = React.useMemo(() => {\n if (status === 'loading') {\n return <LoadingView />;\n }\n\n if (status === 'error') {\n return <ErrorView error={error} action={errorAction} />;\n }\n\n if (status === 'success' && hasNextPage) {\n return <MoreView isLoading={isFetchingNextPage} onClick={fetchNextPage} />;\n }\n\n return null;\n }, [\n status,\n hasNextPage,\n LoadingView,\n ErrorView,\n error,\n errorAction,\n MoreView,\n isFetchingNextPage,\n fetchNextPage,\n ]);\n\n return (\n <>\n {status === 'success' ? children : null}\n {content}\n </>\n );\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAM1B,OAAO,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkBA,CAAAC,IAAA,EAWyB;EAAA,IAVpDC,MAAM,GAAAD,IAAA,CAANC,MAAM;IACNC,KAAK,GAAAF,IAAA,CAALE,KAAK;IACQC,eAAe,GAAAH,IAAA,CAA5BI,WAAW;IACXC,WAAW,GAAAL,IAAA,CAAXK,WAAW;IACXC,aAAa,GAAAN,IAAA,CAAbM,aAAa;IACbC,kBAAkB,GAAAP,IAAA,CAAlBO,kBAAkB;IAClBC,WAAW,GAAAR,IAAA,CAAXQ,WAAW;IACXC,SAAS,GAAAT,IAAA,CAATS,SAAS;IACTC,QAAQ,GAAAV,IAAA,CAARU,QAAQ;IACRC,QAAQ,GAAAX,IAAA,CAARW,QAAQ;EAER,IAAMP,WAAW,GAAGZ,KAAK,CAACoB,OAAO,CAC7B;IAAA,OACI,OAAOT,eAAe,KAAK,UAAU,GAAG;MAACU,OAAO,EAAEV;IAAe,CAAC,GAAGA,eAAe;EAAA,GACxF,CAACA,eAAe,CACpB,CAAC;EAED,IAAMW,OAAO,GAAGtB,KAAK,CAACoB,OAAO,CAAC,YAAM;IAChC,IAAIX,MAAM,KAAK,SAAS,EAAE;MACtB,oBAAOP,IAAA,CAACc,WAAW,IAAE,CAAC;IAC1B;IAEA,IAAIP,MAAM,KAAK,OAAO,EAAE;MACpB,oBAAOP,IAAA,CAACe,SAAS;QAACP,KAAK,EAAEA,KAAM;QAACa,MAAM,EAAEX;MAAY,CAAE,CAAC;IAC3D;IAEA,IAAIH,MAAM,KAAK,SAAS,IAAII,WAAW,EAAE;MACrC,oBAAOX,IAAA,CAACgB,QAAQ;QAACM,SAAS,EAAET,kBAAmB;QAACU,OAAO,EAAEX;MAAc,CAAE,CAAC;IAC9E;IAEA,OAAO,IAAI;EACf,CAAC,EAAE,CACCL,MAAM,EACNI,WAAW,EACXG,WAAW,EACXC,SAAS,EACTP,KAAK,EACLE,WAAW,EACXM,QAAQ,EACRH,kBAAkB,EAClBD,aAAa,CAChB,CAAC;EAEF,oBACIR,KAAA,CAAAF,SAAA;IAAAe,QAAA,GACKV,MAAM,KAAK,SAAS,GAAGU,QAAQ,GAAG,IAAI,EACtCG,OAAO;EAAA,CACV,CAAC;AAEX,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export type { DataInfiniteLoaderProps } from './types';
2
+ export { DataInfiniteLoader } from './DataInfiniteLoader';
@@ -0,0 +1,2 @@
1
+ export { DataInfiniteLoader } from './DataInfiniteLoader';
2
+ // #sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DataInfiniteLoader"],"sources":["index.ts"],"sourcesContent":["export type {DataInfiniteLoaderProps} from './types';\nexport {DataInfiniteLoader} from './DataInfiniteLoader';\n"],"mappings":"AACA,SAAQA,kBAAkB,QAAO,sBAAsB","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ import type { ComponentType, ReactNode } from 'react';
2
+ import type { DataLoaderStatus } from '../../../core';
3
+ import type { ErrorAction, ErrorViewProps } from '../types';
4
+ export interface MoreViewProps {
5
+ isLoading: boolean;
6
+ onClick: () => void;
7
+ }
8
+ export interface DataInfiniteLoaderProps<TError> {
9
+ status: DataLoaderStatus;
10
+ error: TError | null;
11
+ errorAction?: ErrorAction | ErrorAction['handler'];
12
+ hasNextPage: boolean;
13
+ fetchNextPage: () => unknown;
14
+ isFetchingNextPage: boolean;
15
+ LoadingView: ComponentType;
16
+ ErrorView: ComponentType<ErrorViewProps<TError>>;
17
+ MoreView: ComponentType<MoreViewProps>;
18
+ children: ReactNode;
19
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ // #sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {ComponentType, ReactNode} from 'react';\n\nimport type {DataLoaderStatus} from '../../../core';\nimport type {ErrorAction, ErrorViewProps} from '../types';\n\nexport interface MoreViewProps {\n isLoading: boolean;\n onClick: () => void;\n}\n\nexport interface DataInfiniteLoaderProps<TError> {\n status: DataLoaderStatus;\n error: TError | null;\n errorAction?: ErrorAction | ErrorAction['handler'];\n hasNextPage: boolean;\n fetchNextPage: () => unknown;\n isFetchingNextPage: boolean;\n LoadingView: ComponentType;\n ErrorView: ComponentType<ErrorViewProps<TError>>;\n MoreView: ComponentType<MoreViewProps>;\n children: ReactNode;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { DataLoaderProps } from './types';
3
+ export declare const DataLoader: <TError>({ status, error, errorAction: errorActionProp, LoadingView, ErrorView, children, }: DataLoaderProps<TError>) => React.ReactNode;
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
+ export var DataLoader = function DataLoader(_ref) {
4
+ var status = _ref.status,
5
+ error = _ref.error,
6
+ errorActionProp = _ref.errorAction,
7
+ LoadingView = _ref.LoadingView,
8
+ ErrorView = _ref.ErrorView,
9
+ children = _ref.children;
10
+ var errorAction = React.useMemo(function () {
11
+ return typeof errorActionProp === 'function' ? {
12
+ handler: errorActionProp
13
+ } : errorActionProp;
14
+ }, [errorActionProp]);
15
+ if (status === 'loading') {
16
+ return /*#__PURE__*/_jsx(LoadingView, {});
17
+ }
18
+ if (status === 'error') {
19
+ return /*#__PURE__*/_jsx(ErrorView, {
20
+ error: error,
21
+ action: errorAction
22
+ });
23
+ }
24
+ return /*#__PURE__*/_jsx(_Fragment, {
25
+ children: children
26
+ });
27
+ };
28
+ // #sourceMappingURL=DataLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","jsx","_jsx","Fragment","_Fragment","DataLoader","_ref","status","error","errorActionProp","errorAction","LoadingView","ErrorView","children","useMemo","handler","action"],"sources":["DataLoader.tsx"],"sourcesContent":["import React from 'react';\n\nimport type {ErrorViewProps} from '../types';\n\nimport type {DataLoaderProps} from './types';\n\nexport const DataLoader = <TError,>({\n status,\n error,\n errorAction: errorActionProp,\n LoadingView,\n ErrorView,\n children,\n}: DataLoaderProps<TError>): React.ReactNode => {\n const errorAction = React.useMemo<ErrorViewProps<TError>['action']>(\n () =>\n typeof errorActionProp === 'function' ? {handler: errorActionProp} : errorActionProp,\n [errorActionProp],\n );\n\n if (status === 'loading') {\n return <LoadingView />;\n }\n\n if (status === 'error') {\n return <ErrorView error={error} action={errorAction} />;\n }\n\n return <>{children}</>;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA;AAM1B,OAAO,IAAMC,UAAU,GAAG,SAAbA,UAAUA,CAAAC,IAAA,EAOyB;EAAA,IAN5CC,MAAM,GAAAD,IAAA,CAANC,MAAM;IACNC,KAAK,GAAAF,IAAA,CAALE,KAAK;IACQC,eAAe,GAAAH,IAAA,CAA5BI,WAAW;IACXC,WAAW,GAAAL,IAAA,CAAXK,WAAW;IACXC,SAAS,GAAAN,IAAA,CAATM,SAAS;IACTC,QAAQ,GAAAP,IAAA,CAARO,QAAQ;EAER,IAAMH,WAAW,GAAGV,KAAK,CAACc,OAAO,CAC7B;IAAA,OACI,OAAOL,eAAe,KAAK,UAAU,GAAG;MAACM,OAAO,EAAEN;IAAe,CAAC,GAAGA,eAAe;EAAA,GACxF,CAACA,eAAe,CACpB,CAAC;EAED,IAAIF,MAAM,KAAK,SAAS,EAAE;IACtB,oBAAOL,IAAA,CAACS,WAAW,IAAE,CAAC;EAC1B;EAEA,IAAIJ,MAAM,KAAK,OAAO,EAAE;IACpB,oBAAOL,IAAA,CAACU,SAAS;MAACJ,KAAK,EAAEA,KAAM;MAACQ,MAAM,EAAEN;IAAY,CAAE,CAAC;EAC3D;EAEA,oBAAOR,IAAA,CAAAE,SAAA;IAAAS,QAAA,EAAGA;EAAQ,CAAG,CAAC;AAC1B,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export type { DataLoaderProps } from './types';
2
+ export { DataLoader } from './DataLoader';
@@ -0,0 +1,2 @@
1
+ export { DataLoader } from './DataLoader';
2
+ // #sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DataLoader"],"sources":["index.ts"],"sourcesContent":["export type {DataLoaderProps} from './types';\nexport {DataLoader} from './DataLoader';\n"],"mappings":"AACA,SAAQA,UAAU,QAAO,cAAc","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import type { ComponentType, ReactNode } from 'react';
2
+ import type { DataLoaderStatus } from '../../../core';
3
+ import type { ErrorAction, ErrorViewProps } from '../types';
4
+ export interface DataLoaderProps<TError> {
5
+ status: DataLoaderStatus;
6
+ error: TError | null;
7
+ errorAction?: ErrorAction | ErrorAction['handler'];
8
+ LoadingView: ComponentType;
9
+ ErrorView: ComponentType<ErrorViewProps<TError>>;
10
+ children: ReactNode;
11
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ // #sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {ComponentType, ReactNode} from 'react';\n\nimport type {DataLoaderStatus} from '../../../core';\nimport type {ErrorAction, ErrorViewProps} from '../types';\n\nexport interface DataLoaderProps<TError> {\n status: DataLoaderStatus;\n error: TError | null;\n errorAction?: ErrorAction | ErrorAction['handler'];\n LoadingView: ComponentType;\n ErrorView: ComponentType<ErrorViewProps<TError>>;\n children: ReactNode;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from 'react';
2
+ export interface ErrorAction {
3
+ handler: () => unknown;
4
+ children?: ReactNode;
5
+ }
6
+ export interface ErrorViewProps<TError> {
7
+ error: TError | null;
8
+ action?: ErrorAction;
9
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ // #sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {ReactNode} from 'react';\n\nexport interface ErrorAction {\n handler: () => unknown;\n children?: ReactNode;\n}\n\nexport interface ErrorViewProps<TError> {\n error: TError | null;\n action?: ErrorAction;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ export { DataManagerContext, useDataManager } from './DataManagerContext';
2
+ export type { WithDataManagerProps } from './withDataManager';
3
+ export { withDataManager } from './withDataManager';
4
+ export * from './components/DataLoader';
5
+ export * from './components/DataInfiniteLoader';
@@ -0,0 +1,5 @@
1
+ export { DataManagerContext, useDataManager } from './DataManagerContext';
2
+ export { withDataManager } from './withDataManager';
3
+ export * from './components/DataLoader';
4
+ export * from './components/DataInfiniteLoader';
5
+ // #sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DataManagerContext","useDataManager","withDataManager"],"sources":["index.ts"],"sourcesContent":["export {DataManagerContext, useDataManager} from './DataManagerContext';\n\nexport type {WithDataManagerProps} from './withDataManager';\nexport {withDataManager} from './withDataManager';\n\nexport * from './components/DataLoader';\nexport * from './components/DataInfiniteLoader';\n"],"mappings":"AAAA,SAAQA,kBAAkB,EAAEC,cAAc,QAAO,sBAAsB;AAGvE,SAAQC,eAAe,QAAO,mBAAmB;AAEjD,cAAc,yBAAyB;AACvC,cAAc,iCAAiC","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { DataManager } from '../core';
3
+ export interface WithDataManagerProps {
4
+ dataManager: DataManager;
5
+ }
6
+ export declare const withDataManager: <T extends WithDataManagerProps>(WrappedComponent: React.ComponentType<WithDataManagerProps>) => React.FC<T>;
@@ -0,0 +1,15 @@
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
+ import React from 'react';
3
+ import { useDataManager } from './DataManagerContext';
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ export var withDataManager = function withDataManager(WrappedComponent) {
6
+ var ComponentWithDataManager = function ComponentWithDataManager(props) {
7
+ var dataManager = useDataManager();
8
+ return /*#__PURE__*/_jsx(WrappedComponent, _objectSpread(_objectSpread({}, props), {}, {
9
+ dataManager: dataManager
10
+ }));
11
+ };
12
+ ComponentWithDataManager.displayName = "WithDataManager".concat(WrappedComponent.displayName || WrappedComponent.name || 'Component');
13
+ return ComponentWithDataManager;
14
+ };
15
+ // #sourceMappingURL=withDataManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","useDataManager","jsx","_jsx","withDataManager","WrappedComponent","ComponentWithDataManager","props","dataManager","_objectSpread","displayName","concat","name"],"sources":["withDataManager.tsx"],"sourcesContent":["import React from 'react';\n\nimport type {DataManager} from '../core';\n\nimport {useDataManager} from './DataManagerContext';\n\nexport interface WithDataManagerProps {\n dataManager: DataManager;\n}\n\nexport const withDataManager = <T extends WithDataManagerProps>(\n WrappedComponent: React.ComponentType<WithDataManagerProps>,\n) => {\n const ComponentWithDataManager: React.FC<T> = (props) => {\n const dataManager = useDataManager();\n\n return <WrappedComponent {...props} dataManager={dataManager} />;\n };\n\n ComponentWithDataManager.displayName = `WithDataManager${\n WrappedComponent.displayName || WrappedComponent.name || 'Component'\n }`;\n\n return ComponentWithDataManager;\n};\n"],"mappings":";AAAA,OAAOA,KAAK,MAAM,OAAO;AAIzB,SAAQC,cAAc,QAAO,sBAAsB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAMpD,OAAO,IAAMC,eAAe,GAAG,SAAlBA,eAAeA,CACxBC,gBAA2D,EAC1D;EACD,IAAMC,wBAAqC,GAAG,SAAxCA,wBAAqCA,CAAIC,KAAK,EAAK;IACrD,IAAMC,WAAW,GAAGP,cAAc,CAAC,CAAC;IAEpC,oBAAOE,IAAA,CAACE,gBAAgB,EAAAI,aAAA,CAAAA,aAAA,KAAKF,KAAK;MAAEC,WAAW,EAAEA;IAAY,EAAE,CAAC;EACpE,CAAC;EAEDF,wBAAwB,CAACI,WAAW,qBAAAC,MAAA,CAChCN,gBAAgB,CAACK,WAAW,IAAIL,gBAAgB,CAACO,IAAI,IAAI,WAAW,CACtE;EAEF,OAAON,wBAAwB;AACnC,CAAC","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ import type { QueryClientConfig } from '@tanstack/react-query';
2
+ import { QueryClient } from '@tanstack/react-query';
3
+ import { type AnyDataSource, type DataManager, type DataSourceParams, type DataSourceTag } from '../core';
4
+ export type ClientDataManagerConfig = QueryClientConfig;
5
+ export declare class ClientDataManager implements DataManager {
6
+ readonly queryClient: QueryClient;
7
+ constructor(conifg?: ClientDataManagerConfig);
8
+ invalidateTag(tag: DataSourceTag): Promise<void>;
9
+ invalidateTags(tags: DataSourceTag[]): Promise<void>;
10
+ invalidateSource<TDataSource extends AnyDataSource>(dataSource: TDataSource): Promise<void>;
11
+ resetSource<TDataSource extends AnyDataSource>(dataSource: TDataSource): Promise<void>;
12
+ invalidateParams<TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>): Promise<void>;
13
+ resetParams<TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>): Promise<void>;
14
+ invalidateSourceTags<TDataSource extends AnyDataSource>(dataSource: TDataSource, params: DataSourceParams<TDataSource>): Promise<void>;
15
+ }
@@ -0,0 +1,87 @@
1
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/createClass";
4
+ import { QueryClient } from '@tanstack/react-query';
5
+ import { composeFullKey, hasTag } from '../core';
6
+ export var ClientDataManager = /*#__PURE__*/function () {
7
+ function ClientDataManager() {
8
+ var _conifg$defaultOption, _conifg$defaultOption2;
9
+ var conifg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
10
+ _classCallCheck(this, ClientDataManager);
11
+ this.queryClient = void 0;
12
+ this.queryClient = new QueryClient(_objectSpread(_objectSpread({}, conifg), {}, {
13
+ defaultOptions: _objectSpread(_objectSpread({}, conifg.defaultOptions), {}, {
14
+ queries: _objectSpread({
15
+ networkMode: 'always'
16
+ }, (_conifg$defaultOption = conifg.defaultOptions) === null || _conifg$defaultOption === void 0 ? void 0 : _conifg$defaultOption.queries),
17
+ mutations: _objectSpread({
18
+ networkMode: 'always'
19
+ }, (_conifg$defaultOption2 = conifg.defaultOptions) === null || _conifg$defaultOption2 === void 0 ? void 0 : _conifg$defaultOption2.mutations)
20
+ })
21
+ }));
22
+ }
23
+ return _createClass(ClientDataManager, [{
24
+ key: "invalidateTag",
25
+ value: function invalidateTag(tag) {
26
+ return this.queryClient.invalidateQueries({
27
+ predicate: function predicate(_ref) {
28
+ var queryKey = _ref.queryKey;
29
+ return hasTag(queryKey, tag);
30
+ }
31
+ });
32
+ }
33
+ }, {
34
+ key: "invalidateTags",
35
+ value: function invalidateTags(tags) {
36
+ return this.queryClient.invalidateQueries({
37
+ predicate: function predicate(_ref2) {
38
+ var queryKey = _ref2.queryKey;
39
+ return tags.every(function (tag) {
40
+ return hasTag(queryKey, tag);
41
+ });
42
+ }
43
+ });
44
+ }
45
+ }, {
46
+ key: "invalidateSource",
47
+ value: function invalidateSource(dataSource) {
48
+ return this.queryClient.invalidateQueries({
49
+ // First element is a data source name
50
+ queryKey: [dataSource.name]
51
+ });
52
+ }
53
+ }, {
54
+ key: "resetSource",
55
+ value: function resetSource(dataSource) {
56
+ return this.queryClient.resetQueries({
57
+ // First element is a data source name
58
+ queryKey: [dataSource.name]
59
+ });
60
+ }
61
+ }, {
62
+ key: "invalidateParams",
63
+ value: function invalidateParams(dataSource, params) {
64
+ return this.queryClient.invalidateQueries({
65
+ queryKey: composeFullKey(dataSource, params),
66
+ exact: true
67
+ });
68
+ }
69
+ }, {
70
+ key: "resetParams",
71
+ value: function resetParams(dataSource, params) {
72
+ return this.queryClient.resetQueries({
73
+ queryKey: composeFullKey(dataSource, params),
74
+ exact: true
75
+ });
76
+ }
77
+ }, {
78
+ key: "invalidateSourceTags",
79
+ value: function invalidateSourceTags(dataSource, params) {
80
+ return this.queryClient.invalidateQueries({
81
+ // Last element is a full key
82
+ queryKey: composeFullKey(dataSource, params).slice(0, -1)
83
+ });
84
+ }
85
+ }]);
86
+ }();
87
+ // #sourceMappingURL=ClientDataManager.js.map