@everysk/apps-sdk 0.1.0 → 0.3.0-beta-20261016180126

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 (349) hide show
  1. package/README.md +395 -8
  2. package/dist/EveryskApp.d.ts +34 -2
  3. package/dist/EveryskApp.d.ts.map +1 -1
  4. package/dist/EveryskApp.js +35 -2
  5. package/dist/EveryskApp.js.map +1 -1
  6. package/dist/agGrid/handleRowsScrollEnd.d.ts +53 -0
  7. package/dist/agGrid/handleRowsScrollEnd.d.ts.map +1 -0
  8. package/dist/agGrid/handleRowsScrollEnd.js +47 -0
  9. package/dist/agGrid/handleRowsScrollEnd.js.map +1 -0
  10. package/dist/agGrid/index.d.ts +2 -0
  11. package/dist/agGrid/index.d.ts.map +1 -1
  12. package/dist/agGrid/index.js +2 -1
  13. package/dist/api/datastore.d.ts +10 -8
  14. package/dist/api/datastore.d.ts.map +1 -1
  15. package/dist/api/datastore.js +24 -55
  16. package/dist/api/datastore.js.map +1 -1
  17. package/dist/api/entityQuery.d.ts +46 -41
  18. package/dist/api/entityQuery.d.ts.map +1 -1
  19. package/dist/api/entityQuery.js +55 -14
  20. package/dist/api/entityQuery.js.map +1 -1
  21. package/dist/api/file.d.ts +26 -9
  22. package/dist/api/file.d.ts.map +1 -1
  23. package/dist/api/file.js +45 -55
  24. package/dist/api/file.js.map +1 -1
  25. package/dist/api/portfolio.d.ts +11 -8
  26. package/dist/api/portfolio.d.ts.map +1 -1
  27. package/dist/api/portfolio.js +24 -55
  28. package/dist/api/portfolio.js.map +1 -1
  29. package/dist/api/profile.d.ts +3 -2
  30. package/dist/api/profile.d.ts.map +1 -1
  31. package/dist/api/profile.js +4 -9
  32. package/dist/api/profile.js.map +1 -1
  33. package/dist/api/request.d.ts +106 -0
  34. package/dist/api/request.d.ts.map +1 -0
  35. package/dist/api/request.js +132 -0
  36. package/dist/api/request.js.map +1 -0
  37. package/dist/api/websocketsConfig.d.ts +7 -2
  38. package/dist/api/websocketsConfig.d.ts.map +1 -1
  39. package/dist/api/websocketsConfig.js +2 -10
  40. package/dist/api/websocketsConfig.js.map +1 -1
  41. package/dist/api/workflow.d.ts +84 -89
  42. package/dist/api/workflow.d.ts.map +1 -1
  43. package/dist/api/workflow.js +121 -208
  44. package/dist/api/workflow.js.map +1 -1
  45. package/dist/api/workspace.d.ts +18 -8
  46. package/dist/api/workspace.d.ts.map +1 -1
  47. package/dist/api/workspace.js +21 -26
  48. package/dist/api/workspace.js.map +1 -1
  49. package/dist/components/ui/Footer/index.d.ts.map +1 -1
  50. package/dist/components/ui/Footer/index.js.map +1 -1
  51. package/dist/components/ui/GlobalLoading/index.d.ts.map +1 -1
  52. package/dist/components/ui/GlobalLoading/index.js.map +1 -1
  53. package/dist/components/ui/PageContainer/index.d.ts +1 -1
  54. package/dist/components/ui/PageContainer/index.d.ts.map +1 -1
  55. package/dist/components/ui/PageContainer/index.js.map +1 -1
  56. package/dist/components/ui/Toolbar/index.d.ts +40 -3
  57. package/dist/components/ui/Toolbar/index.d.ts.map +1 -1
  58. package/dist/components/ui/Toolbar/index.js +42 -15
  59. package/dist/components/ui/Toolbar/index.js.map +1 -1
  60. package/dist/contexts/appAlertContext/provider.js.map +1 -1
  61. package/dist/contexts/appAlertContext/types.d.ts.map +1 -1
  62. package/dist/contexts/appConfigContext/index.d.ts.map +1 -1
  63. package/dist/contexts/appConfigContext/index.js.map +1 -1
  64. package/dist/contexts/appConfigContext/provider.d.ts.map +1 -1
  65. package/dist/contexts/appConfigContext/provider.js.map +1 -1
  66. package/dist/contexts/webSocketContext/handler.d.ts +3 -2
  67. package/dist/contexts/webSocketContext/handler.d.ts.map +1 -1
  68. package/dist/contexts/webSocketContext/handler.js.map +1 -1
  69. package/dist/contexts/webSocketContext/hooks/useWebSocket/index.d.ts +1 -1
  70. package/dist/contexts/webSocketContext/hooks/useWebSocket/index.js +1 -1
  71. package/dist/contexts/webSocketContext/hooks/useWebSocket/index.js.map +1 -1
  72. package/dist/contexts/webSocketContext/provider.d.ts +6 -3
  73. package/dist/contexts/webSocketContext/provider.d.ts.map +1 -1
  74. package/dist/contexts/webSocketContext/provider.js +42 -7
  75. package/dist/contexts/webSocketContext/provider.js.map +1 -1
  76. package/dist/contexts/webSocketContext/types.d.ts +7 -5
  77. package/dist/contexts/webSocketContext/types.d.ts.map +1 -1
  78. package/dist/file/index.d.ts +2 -0
  79. package/dist/file/index.d.ts.map +1 -1
  80. package/dist/hooks/datastore/useDatastoreMutations.d.ts +4 -4
  81. package/dist/hooks/datastore/useDatastoreMutations.d.ts.map +1 -1
  82. package/dist/hooks/datastore/useDatastoreMutations.js +17 -55
  83. package/dist/hooks/datastore/useDatastoreMutations.js.map +1 -1
  84. package/dist/hooks/datastore/useFetchDatastore.d.ts +30 -41
  85. package/dist/hooks/datastore/useFetchDatastore.d.ts.map +1 -1
  86. package/dist/hooks/datastore/useFetchDatastore.js +25 -59
  87. package/dist/hooks/datastore/useFetchDatastore.js.map +1 -1
  88. package/dist/hooks/datastore/useFetchDatastores.d.ts +47 -52
  89. package/dist/hooks/datastore/useFetchDatastores.d.ts.map +1 -1
  90. package/dist/hooks/datastore/useFetchDatastores.js +55 -70
  91. package/dist/hooks/datastore/useFetchDatastores.js.map +1 -1
  92. package/dist/hooks/file/fileData.d.ts +17 -0
  93. package/dist/hooks/file/fileData.d.ts.map +1 -0
  94. package/dist/hooks/file/fileData.js +10 -0
  95. package/dist/hooks/file/fileData.js.map +1 -0
  96. package/dist/hooks/file/useFetchFile.d.ts +38 -58
  97. package/dist/hooks/file/useFetchFile.d.ts.map +1 -1
  98. package/dist/hooks/file/useFetchFile.js +26 -66
  99. package/dist/hooks/file/useFetchFile.js.map +1 -1
  100. package/dist/hooks/file/useFetchFiles.d.ts +18 -52
  101. package/dist/hooks/file/useFetchFiles.d.ts.map +1 -1
  102. package/dist/hooks/file/useFetchFiles.js +53 -69
  103. package/dist/hooks/file/useFetchFiles.js.map +1 -1
  104. package/dist/hooks/file/useFileMutations.d.ts +9 -8
  105. package/dist/hooks/file/useFileMutations.d.ts.map +1 -1
  106. package/dist/hooks/file/useFileMutations.js +23 -60
  107. package/dist/hooks/file/useFileMutations.js.map +1 -1
  108. package/dist/hooks/portfolio/useFetchPortfolio.d.ts +16 -50
  109. package/dist/hooks/portfolio/useFetchPortfolio.d.ts.map +1 -1
  110. package/dist/hooks/portfolio/useFetchPortfolio.js +15 -63
  111. package/dist/hooks/portfolio/useFetchPortfolio.js.map +1 -1
  112. package/dist/hooks/portfolio/useFetchPortfolios.d.ts +13 -52
  113. package/dist/hooks/portfolio/useFetchPortfolios.d.ts.map +1 -1
  114. package/dist/hooks/portfolio/useFetchPortfolios.js +29 -71
  115. package/dist/hooks/portfolio/useFetchPortfolios.js.map +1 -1
  116. package/dist/hooks/portfolio/usePortfolioMutations.d.ts +8 -8
  117. package/dist/hooks/portfolio/usePortfolioMutations.d.ts.map +1 -1
  118. package/dist/hooks/portfolio/usePortfolioMutations.js +20 -58
  119. package/dist/hooks/portfolio/usePortfolioMutations.js.map +1 -1
  120. package/dist/hooks/profile/useFetchProfile.d.ts +18 -44
  121. package/dist/hooks/profile/useFetchProfile.d.ts.map +1 -1
  122. package/dist/hooks/profile/useFetchProfile.js +16 -48
  123. package/dist/hooks/profile/useFetchProfile.js.map +1 -1
  124. package/dist/hooks/useAxios.js.map +1 -1
  125. package/dist/hooks/useEntityInfiniteQuery.d.ts +88 -0
  126. package/dist/hooks/useEntityInfiniteQuery.d.ts.map +1 -0
  127. package/dist/hooks/useEntityInfiniteQuery.js +111 -0
  128. package/dist/hooks/useEntityInfiniteQuery.js.map +1 -0
  129. package/dist/hooks/useEntityMutation.d.ts +47 -0
  130. package/dist/hooks/useEntityMutation.d.ts.map +1 -0
  131. package/dist/hooks/useEntityMutation.js +58 -0
  132. package/dist/hooks/useEntityMutation.js.map +1 -0
  133. package/dist/hooks/useEntityQuery.d.ts +68 -0
  134. package/dist/hooks/useEntityQuery.d.ts.map +1 -0
  135. package/dist/hooks/useEntityQuery.js +75 -0
  136. package/dist/hooks/useEntityQuery.js.map +1 -0
  137. package/dist/hooks/workflow/useFetchWorkerExecution.d.ts +17 -34
  138. package/dist/hooks/workflow/useFetchWorkerExecution.d.ts.map +1 -1
  139. package/dist/hooks/workflow/useFetchWorkerExecution.js +16 -46
  140. package/dist/hooks/workflow/useFetchWorkerExecution.js.map +1 -1
  141. package/dist/hooks/workflow/useFetchWorkerExecutions.d.ts +179 -41
  142. package/dist/hooks/workflow/useFetchWorkerExecutions.d.ts.map +1 -1
  143. package/dist/hooks/workflow/useFetchWorkerExecutions.js +29 -62
  144. package/dist/hooks/workflow/useFetchWorkerExecutions.js.map +1 -1
  145. package/dist/hooks/workflow/useFetchWorkflow.d.ts +16 -35
  146. package/dist/hooks/workflow/useFetchWorkflow.d.ts.map +1 -1
  147. package/dist/hooks/workflow/useFetchWorkflow.js +15 -48
  148. package/dist/hooks/workflow/useFetchWorkflow.js.map +1 -1
  149. package/dist/hooks/workflow/useFetchWorkflowExecution.d.ts +17 -34
  150. package/dist/hooks/workflow/useFetchWorkflowExecution.d.ts.map +1 -1
  151. package/dist/hooks/workflow/useFetchWorkflowExecution.js +16 -46
  152. package/dist/hooks/workflow/useFetchWorkflowExecution.js.map +1 -1
  153. package/dist/hooks/workflow/useFetchWorkflowExecutions.d.ts +22 -36
  154. package/dist/hooks/workflow/useFetchWorkflowExecutions.d.ts.map +1 -1
  155. package/dist/hooks/workflow/useFetchWorkflowExecutions.js +43 -56
  156. package/dist/hooks/workflow/useFetchWorkflowExecutions.js.map +1 -1
  157. package/dist/hooks/workflow/useFetchWorkflows.d.ts +20 -37
  158. package/dist/hooks/workflow/useFetchWorkflows.d.ts.map +1 -1
  159. package/dist/hooks/workflow/useFetchWorkflows.js +32 -47
  160. package/dist/hooks/workflow/useFetchWorkflows.js.map +1 -1
  161. package/dist/hooks/workflow/useRunWorkflow.d.ts +21 -16
  162. package/dist/hooks/workflow/useRunWorkflow.d.ts.map +1 -1
  163. package/dist/hooks/workflow/useRunWorkflow.js +66 -29
  164. package/dist/hooks/workflow/useRunWorkflow.js.map +1 -1
  165. package/dist/hooks/workflow/useTriggerWorkflow.d.ts +20 -0
  166. package/dist/hooks/workflow/useTriggerWorkflow.d.ts.map +1 -0
  167. package/dist/hooks/workflow/useTriggerWorkflow.js +32 -0
  168. package/dist/hooks/workflow/useTriggerWorkflow.js.map +1 -0
  169. package/dist/hooks/workspace/useFetchWorkspace.d.ts +19 -34
  170. package/dist/hooks/workspace/useFetchWorkspace.d.ts.map +1 -1
  171. package/dist/hooks/workspace/useFetchWorkspace.js +16 -46
  172. package/dist/hooks/workspace/useFetchWorkspace.js.map +1 -1
  173. package/dist/hooks/workspace/useFetchWorkspaces.d.ts +17 -37
  174. package/dist/hooks/workspace/useFetchWorkspaces.d.ts.map +1 -1
  175. package/dist/hooks/workspace/useFetchWorkspaces.js +25 -47
  176. package/dist/hooks/workspace/useFetchWorkspaces.js.map +1 -1
  177. package/dist/index.d.ts +13 -10
  178. package/dist/index.d.ts.map +1 -1
  179. package/dist/index.js +13 -11
  180. package/dist/lib/abort.d.ts +58 -0
  181. package/dist/lib/abort.d.ts.map +1 -0
  182. package/dist/lib/abort.js +112 -0
  183. package/dist/lib/abort.js.map +1 -0
  184. package/dist/lib/datastoreTable.d.ts +59 -54
  185. package/dist/lib/datastoreTable.d.ts.map +1 -1
  186. package/dist/lib/datastoreTable.js +58 -62
  187. package/dist/lib/datastoreTable.js.map +1 -1
  188. package/dist/lib/file.d.ts +34 -0
  189. package/dist/lib/file.d.ts.map +1 -0
  190. package/dist/lib/file.js +63 -0
  191. package/dist/lib/file.js.map +1 -0
  192. package/dist/lib/queryClient.d.ts.map +1 -1
  193. package/dist/lib/queryClient.js.map +1 -1
  194. package/dist/lib/workflowRun.d.ts +91 -0
  195. package/dist/lib/workflowRun.d.ts.map +1 -0
  196. package/dist/lib/workflowRun.js +224 -0
  197. package/dist/lib/workflowRun.js.map +1 -0
  198. package/dist/socket/index.d.ts +1 -3
  199. package/dist/socket/index.d.ts.map +1 -1
  200. package/dist/socket/index.js +3 -5
  201. package/dist/test/mocks/index.d.ts +1 -1
  202. package/dist/test/mocks/index.d.ts.map +1 -1
  203. package/dist/test/renderWithProviders.d.ts +2 -2
  204. package/dist/test/renderWithProviders.d.ts.map +1 -1
  205. package/dist/test/renderWithProviders.js.map +1 -1
  206. package/dist/test/setup.js.map +1 -1
  207. package/dist/theme/index.d.ts +1 -1
  208. package/dist/theme/index.d.ts.map +1 -1
  209. package/dist/theme/overrides/index.d.ts +4 -2
  210. package/dist/theme/overrides/index.d.ts.map +1 -1
  211. package/dist/theme/overrides/index.js +5 -3
  212. package/dist/theme/overrides/index.js.map +1 -1
  213. package/dist/theme/overrides/muiButton.d.ts +2 -2
  214. package/dist/theme/overrides/muiButton.js.map +1 -1
  215. package/dist/theme/overrides/muiCssBaseline.d.ts.map +1 -1
  216. package/dist/theme/overrides/muiCssBaseline.js.map +1 -1
  217. package/dist/theme/overrides/muiDatePicker.js.map +1 -1
  218. package/dist/theme/overrides/muiFormControl.js.map +1 -1
  219. package/dist/theme/overrides/muiIconButton.d.ts +2 -2
  220. package/dist/theme/overrides/muiIconButton.js.map +1 -1
  221. package/dist/theme/overrides/muiSelect.d.ts.map +1 -1
  222. package/dist/theme/overrides/muiSelect.js.map +1 -1
  223. package/dist/theme/overrides/muiSvgIcon.d.ts.map +1 -1
  224. package/dist/theme/overrides/muiSvgIcon.js.map +1 -1
  225. package/dist/theme/overrides/muiTextField.js.map +1 -1
  226. package/dist/theme/overrides/muiToggleButton.d.ts +2 -2
  227. package/dist/theme/overrides/muiToggleButton.js.map +1 -1
  228. package/dist/theme/overrides/muiToggleButtonGroup.d.ts +2 -2
  229. package/dist/theme/overrides/muiToggleButtonGroup.js.map +1 -1
  230. package/dist/theme/themes/DefaultDark.js +2 -2
  231. package/dist/theme/themes/DefaultDark.js.map +1 -1
  232. package/dist/theme/themes/DefaultLight.js +2 -2
  233. package/dist/theme/themes/DefaultLight.js.map +1 -1
  234. package/dist/theme/themes/EveryskDark.js +2 -2
  235. package/dist/theme/themes/EveryskDark.js.map +1 -1
  236. package/dist/theme/themes/EveryskLight.js +2 -2
  237. package/dist/theme/themes/EveryskLight.js.map +1 -1
  238. package/dist/theme/themes/MidnightEmber.js +2 -2
  239. package/dist/theme/themes/MidnightEmber.js.map +1 -1
  240. package/dist/types/anyRecord.d.ts.map +1 -1
  241. package/dist/types/datastore.d.ts +35 -5
  242. package/dist/types/datastore.d.ts.map +1 -1
  243. package/dist/types/datastoreDataFormat.d.ts +13 -0
  244. package/dist/types/datastoreDataFormat.d.ts.map +1 -0
  245. package/dist/types/entityQuery.d.ts +86 -16
  246. package/dist/types/entityQuery.d.ts.map +1 -1
  247. package/dist/types/file.d.ts +7 -3
  248. package/dist/types/file.d.ts.map +1 -1
  249. package/dist/types/portfolio.d.ts +1 -3
  250. package/dist/types/portfolio.d.ts.map +1 -1
  251. package/dist/types/profile.d.ts +0 -10
  252. package/dist/types/profile.d.ts.map +1 -1
  253. package/dist/types/workflow.d.ts +35 -6
  254. package/dist/types/workflow.d.ts.map +1 -1
  255. package/dist/types/workspace.d.ts +1 -2
  256. package/dist/types/workspace.d.ts.map +1 -1
  257. package/dist/ui/index.d.ts +1 -1
  258. package/dist/ui/index.d.ts.map +1 -1
  259. package/dist/workflow/index.d.ts +2 -0
  260. package/dist/workflow/index.d.ts.map +1 -1
  261. package/package.json +6 -6
  262. package/src/EveryskApp.tsx +53 -2
  263. package/src/agGrid/handleRowsScrollEnd.ts +71 -0
  264. package/src/agGrid/index.ts +5 -1
  265. package/src/api/datastore.ts +79 -107
  266. package/src/api/entityQuery.ts +86 -17
  267. package/src/api/file.ts +110 -103
  268. package/src/api/portfolio.ts +82 -125
  269. package/src/api/profile.ts +25 -18
  270. package/src/api/request.ts +168 -0
  271. package/src/api/websocketsConfig.ts +11 -19
  272. package/src/api/workflow.ts +232 -334
  273. package/src/api/workspace.ts +43 -43
  274. package/src/components/ui/Footer/index.tsx +8 -7
  275. package/src/components/ui/GlobalLoading/index.tsx +13 -3
  276. package/src/components/ui/PageContainer/index.tsx +9 -2
  277. package/src/components/ui/Toolbar/index.tsx +105 -30
  278. package/src/contexts/appAlertContext/provider.tsx +1 -1
  279. package/src/contexts/appAlertContext/types.ts +3 -3
  280. package/src/contexts/appConfigContext/index.tsx +1 -1
  281. package/src/contexts/appConfigContext/provider.tsx +1 -5
  282. package/src/contexts/webSocketContext/handler.ts +8 -2
  283. package/src/contexts/webSocketContext/hooks/useWebSocket/index.ts +1 -1
  284. package/src/contexts/webSocketContext/provider.tsx +64 -14
  285. package/src/contexts/webSocketContext/types.ts +7 -6
  286. package/src/file/index.ts +2 -0
  287. package/src/hooks/datastore/useDatastoreMutations.ts +19 -60
  288. package/src/hooks/datastore/useFetchDatastore.ts +45 -73
  289. package/src/hooks/datastore/useFetchDatastores.ts +106 -131
  290. package/src/hooks/file/fileData.ts +19 -0
  291. package/src/hooks/file/useFetchFile.ts +41 -76
  292. package/src/hooks/file/useFetchFiles.ts +92 -87
  293. package/src/hooks/file/useFileMutations.ts +23 -73
  294. package/src/hooks/portfolio/useFetchPortfolio.ts +26 -78
  295. package/src/hooks/portfolio/useFetchPortfolios.ts +50 -93
  296. package/src/hooks/portfolio/usePortfolioMutations.ts +22 -72
  297. package/src/hooks/profile/useFetchProfile.ts +24 -65
  298. package/src/hooks/useAxios.ts +5 -5
  299. package/src/hooks/useEntityInfiniteQuery.ts +193 -0
  300. package/src/hooks/useEntityMutation.ts +70 -0
  301. package/src/hooks/useEntityQuery.ts +117 -0
  302. package/src/hooks/workflow/useFetchWorkerExecution.ts +27 -56
  303. package/src/hooks/workflow/useFetchWorkerExecutions.ts +54 -79
  304. package/src/hooks/workflow/useFetchWorkflow.ts +24 -58
  305. package/src/hooks/workflow/useFetchWorkflowExecution.ts +27 -57
  306. package/src/hooks/workflow/useFetchWorkflowExecutions.ts +64 -73
  307. package/src/hooks/workflow/useFetchWorkflows.ts +48 -64
  308. package/src/hooks/workflow/useRunWorkflow.ts +82 -36
  309. package/src/hooks/workflow/useTriggerWorkflow.ts +36 -0
  310. package/src/hooks/workspace/useFetchWorkspace.ts +25 -58
  311. package/src/hooks/workspace/useFetchWorkspaces.ts +38 -69
  312. package/src/index.ts +34 -19
  313. package/src/lib/abort.ts +131 -0
  314. package/src/lib/datastoreTable.ts +127 -74
  315. package/src/lib/file.ts +67 -0
  316. package/src/lib/queryClient.ts +11 -13
  317. package/src/lib/workflowRun.ts +329 -0
  318. package/src/socket/index.ts +1 -3
  319. package/src/test/mocks/index.ts +1 -5
  320. package/src/test/renderWithProviders.tsx +8 -3
  321. package/src/test/setup.ts +16 -16
  322. package/src/theme/index.ts +1 -1
  323. package/src/theme/overrides/index.ts +5 -3
  324. package/src/theme/overrides/muiButton.ts +3 -3
  325. package/src/theme/overrides/muiCssBaseline.ts +11 -12
  326. package/src/theme/overrides/muiDatePicker.ts +2 -2
  327. package/src/theme/overrides/muiFormControl.ts +2 -2
  328. package/src/theme/overrides/muiIconButton.ts +3 -3
  329. package/src/theme/overrides/muiSelect.ts +2 -2
  330. package/src/theme/overrides/muiSvgIcon.ts +2 -2
  331. package/src/theme/overrides/muiTextField.ts +1 -1
  332. package/src/theme/overrides/muiToggleButton.ts +4 -4
  333. package/src/theme/overrides/muiToggleButtonGroup.ts +4 -4
  334. package/src/theme/themes/DefaultDark.ts +2 -2
  335. package/src/theme/themes/DefaultLight.ts +2 -2
  336. package/src/theme/themes/EveryskDark.ts +2 -2
  337. package/src/theme/themes/EveryskLight.ts +2 -2
  338. package/src/theme/themes/MidnightEmber.ts +15 -15
  339. package/src/types/anyRecord.ts +2 -2
  340. package/src/types/datastore.ts +56 -22
  341. package/src/types/datastoreDataFormat.ts +12 -0
  342. package/src/types/entityQuery.ts +122 -38
  343. package/src/types/file.ts +8 -6
  344. package/src/types/portfolio.ts +70 -74
  345. package/src/types/profile.ts +0 -11
  346. package/src/types/workflow.ts +38 -9
  347. package/src/types/workspace.ts +2 -4
  348. package/src/ui/index.ts +1 -1
  349. package/src/workflow/index.ts +5 -0
@@ -1 +1 @@
1
- {"version":3,"file":"useFileMutations.js","names":[],"sources":["../../../src/hooks/file/useFileMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient } from \"@tanstack/react-query\";\n\nimport { useAxios } from \"@/hooks/useAxios\";\nimport { useAppAlert } from \"@/contexts/appAlertContext/useAppAlert\";\nimport type { EveryskFile } from \"@/types/file\";\nimport { deleteFile, createFile, updateFile } from \"@/api/file\";\n\ntype CreateFileProps = {\n data: Partial<EveryskFile>;\n};\n\ntype UpdateFileProps = {\n id: string;\n data: Partial<EveryskFile>;\n};\n\ntype DeleteFileProps = {\n id: string;\n workspace: string;\n};\n\ntype UseFileMutationsProps = {\n queryKey?: unknown[];\n};\n\nconst getErrorMessage = (err: unknown, fallback: string) =>\n err instanceof Error && err.message ? err.message : fallback;\n\n/**\n * useFileMutations\n *\n * Mutation hook built on TanStack Query to perform EveryskFile write operations:\n * - create a file (POST)\n * - update a file (PUT)\n * - delete a file (DELETE)\n *\n * It also:\n * - optionally invalidates a target query cache key after successful mutations\n * - displays success/error alerts via `useAppAlert`\n *\n * Important notes:\n * - This hook is intended for side-effect operations only. Reading/retrieving data should be done via `useQuery` or `useFetchFile`.\n * - Cache invalidation is controlled by `queryKey`. If `queryKey` is not provided, the hook will still run\n * mutations and show alerts, but it will NOT invalidate any cached queries.\n * - `remove` requires a `workspace` parameter because the underlying API helper `deleteFile(api, id, workspace)`\n * expects it as a query param.\n * \n * - EveryskFile content (`data`):\n * - When creating/updating a file, the file content must be provided in `data` as a Base64-encoded string.\n * - Send only the raw Base64 content (do not include a data URL prefix like `data:<mime>;base64,`)\n * - `content_type` should match the file MIME type (e.g., \"text/csv\", \"application/pdf\").\n *\n * Parameters (UseFileMutationsProps):\n * @param {unknown[]} [queryKey]\n * Query key to invalidate after successful mutations. Use the same `queryKey` you pass to the relevant `useQuery`\n * (e.g., file list/detail) so UI data is refreshed automatically after a write.\n *\n * Tip:\n * - If you're using `useFetchFile`, you can pass its returned `queryKey` directly:\n * `const fetch = useFetchFile(...);`\n * `useFileMutations({ queryKey: fetch.queryKey });`\n *\n * Mutations:\n * - `create`:\n * - mutationFn: `createFile(api, data)`\n * - variables: `{ data: Partial<EveryskFile> }`\n * - success message: \"EveryskFile created successfully.\"\n * - error message: \"Unable to create the file. Please try again.\" (fallback)\n *\n * - `update`:\n * - mutationFn: `updateFile(api, id, data)`\n * - variables: `{ id: string; data: Partial<EveryskFile> }`\n * - success message: \"EveryskFile updated successfully.\"\n * - error message: \"Unable to update the file. Please try again.\" (fallback)\n *\n * - `remove`:\n * - mutationFn: `deleteFile(api, id, workspace)`\n * - variables: `{ id: string; workspace: string }`\n * - success message: \"EveryskFile deleted successfully.\"\n * - error message: \"Unable to delete the file. Please try again.\" (fallback)\n *\n * Return value:\n * @returns {object}\n * Returns an object with the three TanStack Query mutation results:\n * - `create`: UseMutationResult<EveryskFile, Error, CreateFileProps, unknown>\n * - `update`: UseMutationResult<EveryskFile, Error, UpdateFileProps, unknown>\n * - `remove`: UseMutationResult<EveryskFile, Error, DeleteFileProps, unknown>\n *\n * Each mutation includes standard TanStack Query helpers:\n * - `mutate(variables, options?)`\n * - `mutateAsync(variables, options?)`\n * - `isPending`, `isSuccess`, `isError`, `error`, `data`, etc.\n *\n * Examples:\n *\n * 1) Invalidate a file list query after mutations:\n * ```ts\n * const { create, update, remove } = useFileMutations({ queryKey: [\"file\"] });\n *\n * // Create\n * create.mutate({\n * data: {\n * name: \"My file\",\n * workspace: \"ws-1\",\n * content_type: \"text/plain\",\n * version: \"1\",\n * link_uid: null,\n * data: \"SGVsbG8gd29ybGQ=\", // Base64 content\n * }\n * });\n *\n * // Update\n * update.mutate({\n * id: \"file-123\",\n * data: {\n * name: \"Renamed file\",\n * content_type: \"text/plain\",\n * data: \"SGVsbG8gd29ybGQ=\", // Base64 content (optional if only renaming)\n * }\n * });\n *\n * // Delete\n * remove.mutate({ id: \"file-123\", workspace: \"ws-1\" });\n * ```\n *\n * 2) Using async/await with `mutateAsync`:\n * ```ts\n * const { create } = useFileMutations({ queryKey: [\"file\"] });\n *\n * await create.mutateAsync({\n * data: {\n * name: \"My file\",\n * workspace: \"ws-1\",\n * content_type: \"text/plain\",\n * version: \"1\",\n * link_uid: null,\n * data: \"SGVsbG8gd29ybGQ=\",\n * }\n * });\n * ```\n *\n * 3) Without cache invalidation (no queryKey):\n * ```ts\n * const { update } = useFileMutations({});\n *\n * update.mutate({\n * id: \"file-123\",\n * data: {\n * name: \"New name\",\n * content_type: \"text/plain\",\n * }\n * });\n * // Mutation still runs and alerts are shown, but cached queries are not invalidated.\n * ```\n *\n * 4) Using `useFetchFile` queryKey for automatic invalidation:\n * ```ts\n * const fetch = useFetchFile({\n * id: null,\n * filters: [{ field: \"workspace\", value: \"ws-1\" }],\n * });\n *\n * const { remove } = useFileMutations({ queryKey: fetch.queryKey });\n *\n * await remove.mutateAsync({ id: \"file-123\", workspace: \"ws-1\" });\n * ```\n */\n\nexport const useFileMutations = ({ queryKey }: UseFileMutationsProps) => {\n const { api } = useAxios();\n const { showAlert } = useAppAlert();\n const queryClient = useQueryClient();\n\n const invalidate = async () => {\n if (!queryKey?.length) return;\n await queryClient.invalidateQueries({ queryKey });\n };\n\n const create = useMutation({\n mutationFn: async ({ data }: CreateFileProps) => createFile(api, data),\n onSuccess: async () => {\n await invalidate();\n showAlert({\n severity: \"success\",\n message: \"EveryskFile created successfully.\",\n });\n },\n onError: (err: unknown) => {\n showAlert({\n severity: \"error\",\n message: getErrorMessage(\n err,\n \"Unable to create the file. Please try again.\"\n ),\n });\n },\n });\n\n const update = useMutation({\n mutationFn: async ({ id, data }: UpdateFileProps) => updateFile(api, id, data),\n onSuccess: async () => {\n await invalidate();\n showAlert({\n severity: \"success\",\n message: \"EveryskFile updated successfully.\",\n });\n },\n onError: (err: unknown) => {\n showAlert({\n severity: \"error\",\n message: getErrorMessage(\n err,\n \"Unable to update the file. Please try again.\"\n ),\n });\n },\n });\n\n const remove = useMutation({\n mutationFn: async ({ id, workspace }: DeleteFileProps) => deleteFile(api, id, workspace),\n onSuccess: async () => {\n await invalidate();\n showAlert({\n severity: \"success\",\n message: \"EveryskFile deleted successfully.\",\n });\n },\n onError: (err: unknown) => {\n showAlert({\n severity: \"error\",\n message: getErrorMessage(\n err,\n \"Unable to delete the file. Please try again.\"\n ),\n });\n },\n });\n\n return { create, update, remove };\n};\n"],"mappings":";;;;;AAyBA,IAAM,mBAAmB,KAAc,aACnC,eAAe,SAAS,IAAI,UAAU,IAAI,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8IxD,IAAa,oBAAoB,EAAE,eAAsC;CACrE,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,EAAE,cAAc,YAAY;CAClC,MAAM,cAAc,eAAe;CAEnC,MAAM,aAAa,YAAY;EAC3B,IAAI,CAAC,UAAU,QAAQ;EACvB,MAAM,YAAY,kBAAkB,EAAE,SAAS,CAAC;CACpD;CA8DA,OAAO;EAAE,QA5DM,YAAY;GACvB,YAAY,OAAO,EAAE,WAA4B,WAAW,KAAK,IAAI;GACrE,WAAW,YAAY;IACnB,MAAM,WAAW;IACjB,UAAU;KACN,UAAU;KACV,SAAS;IACb,CAAC;GACL;GACA,UAAU,QAAiB;IACvB,UAAU;KACN,UAAU;KACV,SAAS,gBACL,KACA,8CACJ;IACJ,CAAC;GACL;EACJ,CA0CS;EAAQ,QAxCF,YAAY;GACvB,YAAY,OAAO,EAAE,IAAI,WAA4B,WAAW,KAAK,IAAI,IAAI;GAC7E,WAAW,YAAY;IACnB,MAAM,WAAW;IACjB,UAAU;KACN,UAAU;KACV,SAAS;IACb,CAAC;GACL;GACA,UAAU,QAAiB;IACvB,UAAU;KACN,UAAU;KACV,SAAS,gBACL,KACA,8CACJ;IACJ,CAAC;GACL;EACJ,CAsBiB;EAAQ,QApBV,YAAY;GACvB,YAAY,OAAO,EAAE,IAAI,gBAAiC,WAAW,KAAK,IAAI,SAAS;GACvF,WAAW,YAAY;IACnB,MAAM,WAAW;IACjB,UAAU;KACN,UAAU;KACV,SAAS;IACb,CAAC;GACL;GACA,UAAU,QAAiB;IACvB,UAAU;KACN,UAAU;KACV,SAAS,gBACL,KACA,8CACJ;IACJ,CAAC;GACL;EACJ,CAEyB;CAAO;AACpC"}
1
+ {"version":3,"file":"useFileMutations.js","names":[],"sources":["../../../src/hooks/file/useFileMutations.ts"],"sourcesContent":["import { useAxios } from \"@/hooks/useAxios\";\nimport { useEntityMutation } from \"@/hooks/useEntityMutation\";\nimport type { EveryskFile } from \"@/types/file\";\nimport { deleteFile, createFile, updateFile } from \"@/api/file\";\n\ntype CreateFileProps = {\n data: Partial<EveryskFile>;\n};\n\ntype UpdateFileProps = {\n id: string;\n data: Partial<EveryskFile>;\n};\n\ntype DeleteFileProps = {\n id: string;\n workspace: string;\n};\n\ntype UseFileMutationsProps = {\n queryKey?: unknown[];\n};\n\n/**\n * useFileMutations\n *\n * Mutation hook built on TanStack Query to perform EveryskFile write operations:\n * - create a file (POST)\n * - update a file (PUT)\n * - delete a file (DELETE)\n *\n * It also:\n * - optionally invalidates a target query cache key after successful mutations\n * - displays success/error alerts via `useAppAlert`\n *\n * Important notes:\n * - This hook is intended for side-effect operations only. Reading/retrieving data should be done via `useQuery` or `useFetchFile`.\n * - Cache invalidation is controlled by `queryKey`. If `queryKey` is not provided, the hook will still run\n * mutations and show alerts, but it will NOT invalidate any cached queries.\n * - `remove` requires a `workspace` parameter because the underlying API helper `deleteFile(api, id, workspace)`\n * expects it as a query param.\n *\n * - EveryskFile content (`data`):\n * - When creating/updating a file, the file content must be provided in `data` as a Base64-encoded string.\n * - Send only the raw Base64 content (do not include a data URL prefix like `data:<mime>;base64,`):\n * `fileToBase64(file)` gives it from a `File`, and a data URL is refused before the request\n * - `content_type` should match the file MIME type (e.g., \"text/csv\", \"application/pdf\").\n *\n * Parameters (UseFileMutationsProps):\n * @param {unknown[]} [queryKey]\n * Query key to invalidate after successful mutations. Use the same `queryKey` you pass to the relevant `useQuery`\n * (e.g., file list/detail) so UI data is refreshed automatically after a write.\n *\n * Tip:\n * - If you're using `useFetchFile`, you can pass its returned `queryKey` directly:\n * `const fetch = useFetchFile(...);`\n * `useFileMutations({ queryKey: fetch.queryKey });`\n *\n * Mutations:\n * - `create`:\n * - mutationFn: `createFile(api, data)`\n * - variables: `{ data: Partial<EveryskFile> }`\n * - success message: \"File created successfully.\"\n * - error message: \"Unable to create the file. Please try again.\" (fallback)\n *\n * - `update`:\n * - mutationFn: `updateFile(api, id, data)`\n * - variables: `{ id: string; data: Partial<EveryskFile> }`\n * - success message: \"File updated successfully.\"\n * - error message: \"Unable to update the file. Please try again.\" (fallback)\n *\n * - `remove`:\n * - mutationFn: `deleteFile(api, id, workspace)`\n * - variables: `{ id: string; workspace: string }`\n * - success message: \"File deleted successfully.\"\n * - error message: \"Unable to delete the file. Please try again.\" (fallback)\n *\n * Return value:\n * @returns {object}\n * Returns an object with the three TanStack Query mutation results:\n * - `create`: UseMutationResult<EveryskFile, Error, CreateFileProps, unknown>\n * - `update`: UseMutationResult<EveryskFile, Error, UpdateFileProps, unknown>\n * - `remove`: UseMutationResult<DeletedEntity, Error, DeleteFileProps, unknown>\n *\n * Each mutation includes standard TanStack Query helpers:\n * - `mutate(variables, options?)`\n * - `mutateAsync(variables, options?)`\n * - `isPending`, `isSuccess`, `isError`, `error`, `data`, etc.\n *\n * Examples:\n *\n * 1) Invalidate a file list query after mutations:\n * ```ts\n * const { create, update, remove } = useFileMutations({ queryKey: [\"file\"] });\n *\n * // Create\n * create.mutate({\n * data: {\n * name: \"My file\",\n * workspace: \"ws-1\",\n * content_type: \"text/plain\",\n * version: \"1\",\n * link_uid: null,\n * data: \"SGVsbG8gd29ybGQ=\", // Base64 content\n * }\n * });\n *\n * // Update\n * update.mutate({\n * id: \"file-123\",\n * data: {\n * name: \"Renamed file\",\n * content_type: \"text/plain\",\n * data: \"SGVsbG8gd29ybGQ=\", // Base64 content (optional if only renaming)\n * }\n * });\n *\n * // Delete\n * remove.mutate({ id: \"file-123\", workspace: \"ws-1\" });\n * ```\n *\n * 2) Using async/await with `mutateAsync`:\n * ```ts\n * const { create } = useFileMutations({ queryKey: [\"file\"] });\n *\n * await create.mutateAsync({\n * data: {\n * name: \"My file\",\n * workspace: \"ws-1\",\n * content_type: \"text/plain\",\n * version: \"1\",\n * link_uid: null,\n * data: \"SGVsbG8gd29ybGQ=\",\n * }\n * });\n * ```\n *\n * 3) Without cache invalidation (no queryKey):\n * ```ts\n * const { update } = useFileMutations({});\n *\n * update.mutate({\n * id: \"file-123\",\n * data: {\n * name: \"New name\",\n * content_type: \"text/plain\",\n * }\n * });\n * // Mutation still runs and alerts are shown, but cached queries are not invalidated.\n * ```\n *\n * 4) Using `useFetchFile` queryKey for automatic invalidation:\n * ```ts\n * const fetch = useFetchFile({\n * id: null,\n * filters: [{ field: \"workspace\", value: \"ws-1\" }],\n * });\n *\n * const { remove } = useFileMutations({ queryKey: fetch.queryKey });\n *\n * await remove.mutateAsync({ id: \"file-123\", workspace: \"ws-1\" });\n * ```\n */\n\nexport const useFileMutations = ({ queryKey }: UseFileMutationsProps) => {\n const { api } = useAxios();\n\n const create = useEntityMutation({\n mutationFn: ({ data }: CreateFileProps) => createFile(api, data),\n queryKey,\n successMessage: \"File created successfully.\",\n errorMessage: \"Unable to create the file. Please try again.\",\n });\n\n const update = useEntityMutation({\n mutationFn: ({ id, data }: UpdateFileProps) => updateFile(api, id, data),\n queryKey,\n successMessage: \"File updated successfully.\",\n errorMessage: \"Unable to update the file. Please try again.\",\n });\n\n const remove = useEntityMutation({\n mutationFn: ({ id, workspace }: DeleteFileProps) => deleteFile(api, id, workspace),\n queryKey,\n successMessage: \"File deleted successfully.\",\n errorMessage: \"Unable to delete the file. Please try again.\",\n });\n\n return { create, update, remove };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoKA,IAAa,oBAAoB,EAAE,eAAsC;CACrE,MAAM,EAAE,QAAQ,SAAS;CAuBzB,OAAO;EAAE,QArBM,kBAAkB;GAC7B,aAAa,EAAE,WAA4B,WAAW,KAAK,IAAI;GAC/D;GACA,gBAAgB;GAChB,cAAc;EAClB,CAgBS;EAAQ,QAdF,kBAAkB;GAC7B,aAAa,EAAE,IAAI,WAA4B,WAAW,KAAK,IAAI,IAAI;GACvE;GACA,gBAAgB;GAChB,cAAc;EAClB,CASiB;EAAQ,QAPV,kBAAkB;GAC7B,aAAa,EAAE,IAAI,gBAAiC,WAAW,KAAK,IAAI,SAAS;GACjF;GACA,gBAAgB;GAChB,cAAc;EAClB,CAEyB;CAAO;AACpC"}
@@ -1,52 +1,18 @@
1
1
  import type { Portfolio } from "../../types/portfolio.d.ts";
2
- import type { FetchEntityParams } from "../../types/entityQuery.d.ts";
3
- export type FetchPortfolioProps<TData = Portfolio, TSelected = TData> = FetchEntityParams<TData, TSelected>;
2
+ import type { FetchEntityByIdProps } from "../../types/entityQuery.d.ts";
3
+ export type FetchPortfolioProps<TData = Portfolio, TSelected = TData> = FetchEntityByIdProps<TData, TSelected>;
4
4
  /**
5
5
  * useFetchPortfolio
6
6
  *
7
- * Data-fetching hook built on TanStack Query to retrieve a single portfolio by ID.
7
+ * Fetches one portfolio; `data` is the portfolio, or whatever `select` makes of it. Idle while
8
+ * `id` is empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error alert.
8
9
  *
9
- * It also:
10
- * - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
11
- * - triggers an error alert via `useAppAlert` whenever `query.error` is present
12
- *
13
- * Important notes:
14
- * - Always returns a single `Portfolio` object.
15
- *
16
- * Parameters (FetchPortfolioProps):
17
- * @param {string} id
18
- * Portfolio identifier (required).
19
- *
20
- * @param {string} workspace
21
- * Workspace the portfolio belongs to (required by `getPortfolio`).
22
- *
23
- * @param {EntityQueryOptions<Portfolio>} [queryOptions=defaultQueryOptions]
24
- * TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
25
- *
26
- * Returns:
27
- * @returns {object}
28
- * TanStack Query's `query` object extended with:
29
- * - `queryKey`: the cache key used by React Query
30
- *
31
- * Tip:
32
- * - The returned `queryKey` can be reused by mutation hooks for cache invalidation:
33
- * ```ts
34
- * const fetch = useFetchPortfolio({ id: "pf-123", workspace: "ws-1" });
35
- * usePortfolioMutations({ queryKey: fetch.queryKey });
36
- * ```
37
- *
38
- * Example:
39
- * ```ts
40
- * const { data, isLoading } = useFetchPortfolio({
41
- * id: "pf-123",
42
- * workspace: "ws-1",
43
- * });
44
- * // data -> Portfolio
45
- * ```
10
+ * @param {FetchPortfolioProps} props - `id`, `workspace`, `select` and TanStack `queryOptions`.
11
+ * @returns {object} The `useQuery` result, plus `queryKey`.
46
12
  */
47
- export declare const useFetchPortfolio: ({ id, workspace, queryOptions }: FetchPortfolioProps) => {
13
+ export declare const useFetchPortfolio: <TSelected = Portfolio>({ id, workspace, select, queryOptions, }: FetchPortfolioProps<Portfolio, TSelected>) => {
48
14
  queryKey: string[];
49
- data: Portfolio;
15
+ data: TSelected;
50
16
  error: Error;
51
17
  isError: true;
52
18
  isPending: false;
@@ -69,11 +35,11 @@ export declare const useFetchPortfolio: ({ id, workspace, queryOptions }: FetchP
69
35
  isRefetching: boolean;
70
36
  isStale: boolean;
71
37
  isEnabled: boolean;
72
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<Portfolio, Error>>;
38
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
73
39
  fetchStatus: import("@tanstack/query-core").FetchStatus;
74
40
  } | {
75
41
  queryKey: string[];
76
- data: Portfolio;
42
+ data: TSelected;
77
43
  error: null;
78
44
  isError: false;
79
45
  isPending: false;
@@ -96,7 +62,7 @@ export declare const useFetchPortfolio: ({ id, workspace, queryOptions }: FetchP
96
62
  isRefetching: boolean;
97
63
  isStale: boolean;
98
64
  isEnabled: boolean;
99
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<Portfolio, Error>>;
65
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
100
66
  fetchStatus: import("@tanstack/query-core").FetchStatus;
101
67
  } | {
102
68
  queryKey: string[];
@@ -123,7 +89,7 @@ export declare const useFetchPortfolio: ({ id, workspace, queryOptions }: FetchP
123
89
  isRefetching: boolean;
124
90
  isStale: boolean;
125
91
  isEnabled: boolean;
126
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<Portfolio, Error>>;
92
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
127
93
  fetchStatus: import("@tanstack/query-core").FetchStatus;
128
94
  } | {
129
95
  queryKey: string[];
@@ -150,7 +116,7 @@ export declare const useFetchPortfolio: ({ id, workspace, queryOptions }: FetchP
150
116
  isRefetching: boolean;
151
117
  isStale: boolean;
152
118
  isEnabled: boolean;
153
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<Portfolio, Error>>;
119
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
154
120
  fetchStatus: import("@tanstack/query-core").FetchStatus;
155
121
  } | {
156
122
  queryKey: string[];
@@ -177,11 +143,11 @@ export declare const useFetchPortfolio: ({ id, workspace, queryOptions }: FetchP
177
143
  isRefetching: boolean;
178
144
  isStale: boolean;
179
145
  isEnabled: boolean;
180
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<Portfolio, Error>>;
146
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
181
147
  fetchStatus: import("@tanstack/query-core").FetchStatus;
182
148
  } | {
183
149
  queryKey: string[];
184
- data: Portfolio;
150
+ data: TSelected;
185
151
  isError: false;
186
152
  error: null;
187
153
  isPending: false;
@@ -204,7 +170,7 @@ export declare const useFetchPortfolio: ({ id, workspace, queryOptions }: FetchP
204
170
  isRefetching: boolean;
205
171
  isStale: boolean;
206
172
  isEnabled: boolean;
207
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<Portfolio, Error>>;
173
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
208
174
  fetchStatus: import("@tanstack/query-core").FetchStatus;
209
175
  };
210
176
  //# sourceMappingURL=useFetchPortfolio.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFetchPortfolio.d.ts","sourceRoot":"","sources":["../../../src/hooks/portfolio/useFetchPortfolio.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,MAAM,MAAM,mBAAmB,CAAC,KAAK,GAAG,SAAS,EAAE,SAAS,GAAG,KAAK,IAAI,iBAAiB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAQ5G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,iBAAiB,GAAI,iCAAuD,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC3G,CAAC"}
1
+ {"version":3,"file":"useFetchPortfolio.d.ts","sourceRoot":"","sources":["../../../src/hooks/portfolio/useFetchPortfolio.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,MAAM,MAAM,mBAAmB,CAAC,KAAK,GAAG,SAAS,EAAE,SAAS,GAAG,KAAK,IAAI,oBAAoB,CACxF,KAAK,EACL,SAAS,CACZ,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAS,GAAG,SAAS,EAAE,0CAKtD,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAe3C,CAAC"}
@@ -1,81 +1,33 @@
1
- import { useAppAlert } from "../../contexts/appAlertContext/useAppAlert.js";
2
1
  import { useAxios } from "../useAxios.js";
2
+ import { useEntityQuery } from "../useEntityQuery.js";
3
+ import { missingWorkspaceError } from "../../api/entityQuery.js";
3
4
  import { getPortfolio } from "../../api/portfolio.js";
4
- import { useEffect } from "react";
5
- import { useQuery } from "@tanstack/react-query";
6
5
  //#region src/hooks/portfolio/useFetchPortfolio.ts
7
- var defaultQueryOptions = {
8
- refetchOnMount: "always",
9
- staleTime: 0,
10
- gcTime: 0
11
- };
12
6
  /**
13
7
  * useFetchPortfolio
14
8
  *
15
- * Data-fetching hook built on TanStack Query to retrieve a single portfolio by ID.
16
- *
17
- * It also:
18
- * - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
19
- * - triggers an error alert via `useAppAlert` whenever `query.error` is present
20
- *
21
- * Important notes:
22
- * - Always returns a single `Portfolio` object.
23
- *
24
- * Parameters (FetchPortfolioProps):
25
- * @param {string} id
26
- * Portfolio identifier (required).
27
- *
28
- * @param {string} workspace
29
- * Workspace the portfolio belongs to (required by `getPortfolio`).
30
- *
31
- * @param {EntityQueryOptions<Portfolio>} [queryOptions=defaultQueryOptions]
32
- * TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
33
- *
34
- * Returns:
35
- * @returns {object}
36
- * TanStack Query's `query` object extended with:
37
- * - `queryKey`: the cache key used by React Query
38
- *
39
- * Tip:
40
- * - The returned `queryKey` can be reused by mutation hooks for cache invalidation:
41
- * ```ts
42
- * const fetch = useFetchPortfolio({ id: "pf-123", workspace: "ws-1" });
43
- * usePortfolioMutations({ queryKey: fetch.queryKey });
44
- * ```
9
+ * Fetches one portfolio; `data` is the portfolio, or whatever `select` makes of it. Idle while
10
+ * `id` is empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error alert.
45
11
  *
46
- * Example:
47
- * ```ts
48
- * const { data, isLoading } = useFetchPortfolio({
49
- * id: "pf-123",
50
- * workspace: "ws-1",
51
- * });
52
- * // data -> Portfolio
53
- * ```
12
+ * @param {FetchPortfolioProps} props - `id`, `workspace`, `select` and TanStack `queryOptions`.
13
+ * @returns {object} The `useQuery` result, plus `queryKey`.
54
14
  */
55
- var useFetchPortfolio = ({ id, workspace, queryOptions = defaultQueryOptions }) => {
15
+ var useFetchPortfolio = ({ id, workspace, select, queryOptions }) => {
56
16
  const { api } = useAxios();
57
- const { showAlert } = useAppAlert();
58
17
  const queryKey = [
59
18
  "portfolio",
60
19
  id,
61
20
  workspace
62
21
  ];
63
- const query = useQuery({
64
- queryKey,
65
- queryFn: async () => {
66
- return (await getPortfolio(api, id, workspace)).portfolio;
67
- },
68
- ...queryOptions ?? {}
69
- });
70
- useEffect(() => {
71
- if (!query.error) return;
72
- showAlert({
73
- severity: "error",
74
- message: query.error.message
75
- });
76
- }, [query.error, showAlert]);
77
22
  return {
78
- ...query,
23
+ ...useEntityQuery({
24
+ queryKey,
25
+ fetchEntity: (signal) => getPortfolio(api, id, workspace, signal),
26
+ select,
27
+ enabled: Boolean(id),
28
+ configError: workspace ? void 0 : missingWorkspaceError("useFetchPortfolio"),
29
+ queryOptions
30
+ }),
79
31
  queryKey
80
32
  };
81
33
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useFetchPortfolio.js","names":[],"sources":["../../../src/hooks/portfolio/useFetchPortfolio.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useQuery } from \"@tanstack/react-query\";\n\nimport { useAxios } from \"@/hooks/useAxios\";\nimport { useAppAlert } from \"@/contexts/appAlertContext/useAppAlert\";\nimport type { Portfolio } from \"@/types/portfolio\";\nimport { getPortfolio } from \"@/api/portfolio\";\nimport type { EntityQueryOptions, FetchEntityParams } from \"@/types/entityQuery\";\n\nexport type FetchPortfolioProps<TData = Portfolio, TSelected = TData> = FetchEntityParams<TData, TSelected>;\n\nconst defaultQueryOptions: EntityQueryOptions<Portfolio> = {\n refetchOnMount: \"always\",\n staleTime: 0,\n gcTime: 0\n}\n\n/**\n * useFetchPortfolio\n *\n * Data-fetching hook built on TanStack Query to retrieve a single portfolio by ID.\n *\n * It also:\n * - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation\n * - triggers an error alert via `useAppAlert` whenever `query.error` is present\n *\n * Important notes:\n * - Always returns a single `Portfolio` object.\n *\n * Parameters (FetchPortfolioProps):\n * @param {string} id\n * Portfolio identifier (required).\n *\n * @param {string} workspace\n * Workspace the portfolio belongs to (required by `getPortfolio`).\n *\n * @param {EntityQueryOptions<Portfolio>} [queryOptions=defaultQueryOptions]\n * TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).\n *\n * Returns:\n * @returns {object}\n * TanStack Query's `query` object extended with:\n * - `queryKey`: the cache key used by React Query\n *\n * Tip:\n * - The returned `queryKey` can be reused by mutation hooks for cache invalidation:\n * ```ts\n * const fetch = useFetchPortfolio({ id: \"pf-123\", workspace: \"ws-1\" });\n * usePortfolioMutations({ queryKey: fetch.queryKey });\n * ```\n *\n * Example:\n * ```ts\n * const { data, isLoading } = useFetchPortfolio({\n * id: \"pf-123\",\n * workspace: \"ws-1\",\n * });\n * // data -> Portfolio\n * ```\n */\nexport const useFetchPortfolio = ({ id, workspace, queryOptions = defaultQueryOptions }: FetchPortfolioProps) => {\n\n const { api } = useAxios();\n const { showAlert } = useAppAlert();\n\n const queryKey = [\n \"portfolio\",\n id,\n workspace\n ];\n\n const query = useQuery<Portfolio>({\n queryKey,\n queryFn: async () => {\n const response = await getPortfolio(api, id, workspace);\n return response.portfolio;\n },\n ...queryOptions ?? {}\n });\n\n useEffect(() => {\n if (!query.error) return;\n\n showAlert({\n severity: \"error\",\n message: query.error.message,\n });\n }, [query.error, showAlert]);\n\n return {\n ...query,\n queryKey,\n };\n};\n"],"mappings":";;;;;;AAWA,IAAM,sBAAqD;CACvD,gBAAgB;CAChB,WAAW;CACX,QAAQ;AACZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,qBAAqB,EAAE,IAAI,WAAW,eAAe,0BAA+C;CAE7G,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,EAAE,cAAc,YAAY;CAElC,MAAM,WAAW;EACb;EACA;EACA;CACJ;CAEA,MAAM,QAAQ,SAAoB;EAC9B;EACA,SAAS,YAAY;GAEjB,QAAO,MADgB,aAAa,KAAK,IAAI,SAAS,EAAA,CACtC;EACpB;EACA,GAAG,gBAAgB,CAAC;CACxB,CAAC;CAED,gBAAgB;EACZ,IAAI,CAAC,MAAM,OAAO;EAElB,UAAU;GACN,UAAU;GACV,SAAS,MAAM,MAAM;EACzB,CAAC;CACL,GAAG,CAAC,MAAM,OAAO,SAAS,CAAC;CAE3B,OAAO;EACH,GAAG;EACH;CACJ;AACJ"}
1
+ {"version":3,"file":"useFetchPortfolio.js","names":[],"sources":["../../../src/hooks/portfolio/useFetchPortfolio.ts"],"sourcesContent":["import { useAxios } from \"@/hooks/useAxios\";\nimport { useEntityQuery } from \"@/hooks/useEntityQuery\";\nimport { missingWorkspaceError } from \"@/api/entityQuery\";\nimport { getPortfolio } from \"@/api/portfolio\";\nimport type { Portfolio } from \"@/types/portfolio\";\nimport type { FetchEntityByIdProps } from \"@/types/entityQuery\";\n\nexport type FetchPortfolioProps<TData = Portfolio, TSelected = TData> = FetchEntityByIdProps<\n TData,\n TSelected\n>;\n\n/**\n * useFetchPortfolio\n *\n * Fetches one portfolio; `data` is the portfolio, or whatever `select` makes of it. Idle while\n * `id` is empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error alert.\n *\n * @param {FetchPortfolioProps} props - `id`, `workspace`, `select` and TanStack `queryOptions`.\n * @returns {object} The `useQuery` result, plus `queryKey`.\n */\nexport const useFetchPortfolio = <TSelected = Portfolio>({\n id,\n workspace,\n select,\n queryOptions,\n}: FetchPortfolioProps<Portfolio, TSelected>) => {\n const { api } = useAxios();\n\n const queryKey = [\"portfolio\", id, workspace];\n\n const query = useEntityQuery<Portfolio, TSelected>({\n queryKey,\n fetchEntity: (signal) => getPortfolio(api, id, workspace, signal),\n select,\n enabled: Boolean(id),\n configError: workspace ? undefined : missingWorkspaceError(\"useFetchPortfolio\"),\n queryOptions,\n });\n\n return { ...query, queryKey };\n};\n"],"mappings":";;;;;;;;;;;;;;AAqBA,IAAa,qBAA4C,EACrD,IACA,WACA,QACA,mBAC6C;CAC7C,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,WAAW;EAAC;EAAa;EAAI;CAAS;CAW5C,OAAO;EAAE,GATK,eAAqC;GAC/C;GACA,cAAc,WAAW,aAAa,KAAK,IAAI,WAAW,MAAM;GAChE;GACA,SAAS,QAAQ,EAAE;GACnB,aAAa,YAAY,KAAA,IAAY,sBAAsB,mBAAmB;GAC9E;EACJ,CAEY;EAAO;CAAS;AAChC"}
@@ -1,60 +1,21 @@
1
- import { type UseInfiniteQueryOptions, type QueryKey } from "@tanstack/react-query";
2
- import type { FetchEntitiesParams } from "../../types/entityQuery.d.ts";
3
1
  import type { Portfolio, PortfolioListResponse } from "../../types/portfolio.d.ts";
4
- type PageToken = string | null;
5
- type InfiniteOptions<TData> = Omit<UseInfiniteQueryOptions<PortfolioListResponse, Error, TData, QueryKey, PageToken>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
6
- export type FetchInfinitePortfolioProps = FetchEntitiesParams<Portfolio[], InfiniteOptions<Portfolio[]>> & {
7
- pageSize?: number;
8
- };
2
+ import type { FetchEntitiesProps, ListQueryProps, ListCache } from "../../types/entityQuery.d.ts";
3
+ /** The query cache of `useFetchPortfolios`, for typing `setQueryData`. */
4
+ export type PortfoliosCache = ListCache<PortfolioListResponse>;
5
+ export type FetchPortfoliosProps<TData = Portfolio[]> = ListQueryProps & FetchEntitiesProps<Portfolio, TData, PortfolioListResponse>;
9
6
  /**
10
- * useFetchInfinitePortfolios
11
- *
12
- * Data-fetching hook built on TanStack Query's `useInfiniteQuery` to retrieve
13
- * portfolios with cursor-based pagination.
14
- *
15
- * It also:
16
- * - flattens all pages into a single `Portfolio[]` via `select`
17
- *
18
- * Important notes:
19
- * - `query.data` returns a flat `Portfolio[]` (all pages merged).
20
- *
21
- * Parameters (FetchInfinitePortfolioProps):
22
- * @param {FilterClause[]} [filters=[]]
23
- * Filters applied to every page request. Must include a `workspace` filter.
24
- *
25
- * @param {string[]} [order=[]]
26
- * Sorting applied to every page request.
27
- *
28
- * @param {string} [projection=""]
29
- * Single field to project: `"field"` returns only that field (others come back null),
30
- * `"-field"` returns every field except that one. One field only — lists 500. Omitted when empty.
31
- *
32
- * @param {number} [pageSize=10]
33
- * Number of portfolios to fetch per page.
34
- *
35
- * @param {InfiniteOptions<Portfolio[]>} [queryOptions]
36
- * TanStack Query options passed through to `useInfiniteQuery`
37
- * (e.g., enabled, staleTime, gcTime, etc.).
38
- *
39
- * Returns:
40
- * @returns {object}
41
- * - `query`: the full `useInfiniteQuery` result (data, isLoading, hasNextPage, fetchNextPage, etc.)
42
- * - `queryKey`: the cache key used by React Query
7
+ * useFetchPortfolios
43
8
  *
44
- * Example:
45
- * ```ts
46
- * const { query } = useFetchInfinitePortfolios({
47
- * filters: [{ field: "workspace", value: "ws-1" }],
48
- * pageSize: 20,
49
- * });
9
+ * Lists portfolios with cursor pagination; `query.data` is every loaded page merged, or
10
+ * whatever `select` makes of it. Paging, `select`, `fetchAllPages` and the
11
+ * missing-workspace error behave as in `useFetchDatastores`.
50
12
  *
51
- * // Flat list of all fetched portfolios
52
- * const portfolios = query.data ?? [];
53
- * ```
13
+ * @param {FetchPortfoliosProps} props - Filters (one must be `workspace`), order,
14
+ * projection, page size, `select`, `fetchAllPages` and TanStack `queryOptions`.
15
+ * @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.
54
16
  */
55
- export declare function useFetchPortfolios({ filters, order, projection, pageSize, queryOptions }: FetchInfinitePortfolioProps): {
56
- query: import("@tanstack/react-query").UseInfiniteQueryResult<Portfolio[], Error>;
17
+ export declare function useFetchPortfolios<TData = Portfolio[]>({ filters, order, projection, pageSize, select, fetchAllPages, queryOptions, }: FetchPortfoliosProps<TData>): {
18
+ query: import("@tanstack/react-query").UseInfiniteQueryResult<TData, Error>;
57
19
  queryKey: unknown[];
58
20
  };
59
- export {};
60
21
  //# sourceMappingURL=useFetchPortfolios.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFetchPortfolios.d.ts","sourceRoot":"","sources":["../../../src/hooks/portfolio/useFetchPortfolios.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,uBAAuB,EAAE,KAAK,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAItG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG1E,KAAK,SAAS,GAAG,MAAM,GAAG,IAAI,CAAC;AAE/B,KAAK,eAAe,CAAC,KAAK,IAAI,IAAI,CAC9B,uBAAuB,CAAC,qBAAqB,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,EACjF,UAAU,GAAG,SAAS,GAAG,kBAAkB,GAAG,kBAAkB,CACnE,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,mBAAmB,CAAC,SAAS,EAAE,EAAE,eAAe,CAAC,SAAS,EAAE,CAAC,CAAC,GAAG;IACvG,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAQF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,OAAY,EAAE,KAAU,EAAE,UAAe,EAAE,QAAa,EAAE,YAAY,EAAE,EAAE,2BAA2B;;;EAoCzI"}
1
+ {"version":3,"file":"useFetchPortfolios.d.ts","sourceRoot":"","sources":["../../../src/hooks/portfolio/useFetchPortfolios.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAQzF,0EAA0E;AAC1E,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,qBAAqB,CAAC,CAAC;AAE/D,MAAM,MAAM,oBAAoB,CAAC,KAAK,GAAG,SAAS,EAAE,IAAI,cAAc,GAClE,kBAAkB,CAAC,SAAS,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,GAAG,SAAS,EAAE,EAAE,EACpD,OAAY,EACZ,KAAU,EACV,UAAe,EACf,QAAa,EACb,MAAM,EACN,aAAqB,EACrB,YAAY,GACf,EAAE,oBAAoB,CAAC,KAAK,CAAC;;;EA4B7B"}
@@ -1,84 +1,42 @@
1
1
  import { useAxios } from "../useAxios.js";
2
- import { buildQueryKey, buildQueryObject } from "../../api/entityQuery.js";
2
+ import { useEntityInfiniteQuery } from "../useEntityInfiniteQuery.js";
3
+ import { buildQueryKey, buildQueryObject, hasWorkspaceFilter, missingWorkspaceError } from "../../api/entityQuery.js";
3
4
  import { listPortfolios } from "../../api/portfolio.js";
4
- import { useMemo } from "react";
5
- import { useInfiniteQuery } from "@tanstack/react-query";
6
5
  //#region src/hooks/portfolio/useFetchPortfolios.ts
7
- var defaultQueryOptions = {
8
- refetchOnMount: "always",
9
- staleTime: 0,
10
- gcTime: 0
11
- };
12
6
  /**
13
- * useFetchInfinitePortfolios
7
+ * useFetchPortfolios
14
8
  *
15
- * Data-fetching hook built on TanStack Query's `useInfiniteQuery` to retrieve
16
- * portfolios with cursor-based pagination.
9
+ * Lists portfolios with cursor pagination; `query.data` is every loaded page merged, or
10
+ * whatever `select` makes of it. Paging, `select`, `fetchAllPages` and the
11
+ * missing-workspace error behave as in `useFetchDatastores`.
17
12
  *
18
- * It also:
19
- * - flattens all pages into a single `Portfolio[]` via `select`
20
- *
21
- * Important notes:
22
- * - `query.data` returns a flat `Portfolio[]` (all pages merged).
23
- *
24
- * Parameters (FetchInfinitePortfolioProps):
25
- * @param {FilterClause[]} [filters=[]]
26
- * Filters applied to every page request. Must include a `workspace` filter.
27
- *
28
- * @param {string[]} [order=[]]
29
- * Sorting applied to every page request.
30
- *
31
- * @param {string} [projection=""]
32
- * Single field to project: `"field"` returns only that field (others come back null),
33
- * `"-field"` returns every field except that one. One field only — lists 500. Omitted when empty.
34
- *
35
- * @param {number} [pageSize=10]
36
- * Number of portfolios to fetch per page.
37
- *
38
- * @param {InfiniteOptions<Portfolio[]>} [queryOptions]
39
- * TanStack Query options passed through to `useInfiniteQuery`
40
- * (e.g., enabled, staleTime, gcTime, etc.).
41
- *
42
- * Returns:
43
- * @returns {object}
44
- * - `query`: the full `useInfiniteQuery` result (data, isLoading, hasNextPage, fetchNextPage, etc.)
45
- * - `queryKey`: the cache key used by React Query
46
- *
47
- * Example:
48
- * ```ts
49
- * const { query } = useFetchInfinitePortfolios({
50
- * filters: [{ field: "workspace", value: "ws-1" }],
51
- * pageSize: 20,
52
- * });
53
- *
54
- * // Flat list of all fetched portfolios
55
- * const portfolios = query.data ?? [];
56
- * ```
13
+ * @param {FetchPortfoliosProps} props - Filters (one must be `workspace`), order,
14
+ * projection, page size, `select`, `fetchAllPages` and TanStack `queryOptions`.
15
+ * @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.
57
16
  */
58
- function useFetchPortfolios({ filters = [], order = [], projection = "", pageSize = 10, queryOptions }) {
17
+ function useFetchPortfolios({ filters = [], order = [], projection = "", pageSize = 10, select, fetchAllPages = false, queryOptions }) {
59
18
  const { api } = useAxios();
60
- const queryKey = buildQueryKey(["portfolios"], filters);
61
- const mergedQueryOptions = useMemo(() => ({
62
- ...defaultQueryOptions,
63
- ...queryOptions ?? {}
64
- }), [queryOptions]);
19
+ const queryKey = buildQueryKey(["portfolios"], filters, {
20
+ order,
21
+ projection,
22
+ pageSize,
23
+ fetchAllPages
24
+ });
65
25
  return {
66
- query: useInfiniteQuery({
26
+ query: useEntityInfiniteQuery({
67
27
  queryKey,
68
- initialPageParam: null,
69
- getNextPageParam: (lastPage) => lastPage.next_page_token ?? void 0,
70
- queryFn: async ({ pageParam }) => {
71
- const queryFilter = buildQueryObject({
72
- filters,
73
- order,
74
- projection,
75
- pageSize,
76
- pageToken: pageParam ?? void 0
77
- });
78
- return await listPortfolios(api, queryFilter);
79
- },
80
- select: (data) => data.pages.flatMap((p) => p.portfolios),
81
- ...mergedQueryOptions
28
+ itemsKey: "portfolios",
29
+ fetchPage: (pageToken, signal) => listPortfolios(api, buildQueryObject({
30
+ filters,
31
+ order,
32
+ projection,
33
+ pageSize,
34
+ pageToken
35
+ }), signal),
36
+ select,
37
+ fetchAllPages,
38
+ configError: hasWorkspaceFilter(filters) ? void 0 : missingWorkspaceError("useFetchPortfolios"),
39
+ queryOptions
82
40
  }),
83
41
  queryKey
84
42
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useFetchPortfolios.js","names":[],"sources":["../../../src/hooks/portfolio/useFetchPortfolios.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { useInfiniteQuery, type UseInfiniteQueryOptions, type QueryKey } from \"@tanstack/react-query\";\n\nimport { useAxios } from \"@/hooks/useAxios\";\nimport { listPortfolios } from \"@/api/portfolio\";\nimport type { FetchEntitiesParams } from \"@/types/entityQuery\";\nimport type { Portfolio, PortfolioListResponse } from \"@/types/portfolio\";\nimport { buildQueryKey, buildQueryObject } from \"@/api/entityQuery\";\n\ntype PageToken = string | null;\n\ntype InfiniteOptions<TData> = Omit<\n UseInfiniteQueryOptions<PortfolioListResponse, Error, TData, QueryKey, PageToken>,\n \"queryKey\" | \"queryFn\" | \"initialPageParam\" | \"getNextPageParam\"\n>;\n\nexport type FetchInfinitePortfolioProps = FetchEntitiesParams<Portfolio[], InfiniteOptions<Portfolio[]>> & {\n pageSize?: number;\n};\n\nconst defaultQueryOptions: InfiniteOptions<Portfolio[]> = {\n refetchOnMount: \"always\",\n staleTime: 0,\n gcTime: 0,\n};\n\n/**\n * useFetchInfinitePortfolios\n *\n * Data-fetching hook built on TanStack Query's `useInfiniteQuery` to retrieve\n * portfolios with cursor-based pagination.\n *\n * It also:\n * - flattens all pages into a single `Portfolio[]` via `select`\n *\n * Important notes:\n * - `query.data` returns a flat `Portfolio[]` (all pages merged).\n *\n * Parameters (FetchInfinitePortfolioProps):\n * @param {FilterClause[]} [filters=[]]\n * Filters applied to every page request. Must include a `workspace` filter.\n *\n * @param {string[]} [order=[]]\n * Sorting applied to every page request.\n *\n * @param {string} [projection=\"\"]\n * Single field to project: `\"field\"` returns only that field (others come back null),\n * `\"-field\"` returns every field except that one. One field only — lists 500. Omitted when empty.\n *\n * @param {number} [pageSize=10]\n * Number of portfolios to fetch per page.\n *\n * @param {InfiniteOptions<Portfolio[]>} [queryOptions]\n * TanStack Query options passed through to `useInfiniteQuery`\n * (e.g., enabled, staleTime, gcTime, etc.).\n *\n * Returns:\n * @returns {object}\n * - `query`: the full `useInfiniteQuery` result (data, isLoading, hasNextPage, fetchNextPage, etc.)\n * - `queryKey`: the cache key used by React Query\n *\n * Example:\n * ```ts\n * const { query } = useFetchInfinitePortfolios({\n * filters: [{ field: \"workspace\", value: \"ws-1\" }],\n * pageSize: 20,\n * });\n *\n * // Flat list of all fetched portfolios\n * const portfolios = query.data ?? [];\n * ```\n */\nexport function useFetchPortfolios({ filters = [], order = [], projection = \"\", pageSize = 10, queryOptions }: FetchInfinitePortfolioProps) {\n const { api } = useAxios();\n\n const queryKey = buildQueryKey([\"portfolios\"], filters);\n\n const mergedQueryOptions = useMemo<InfiniteOptions<Portfolio[]>>(() => ({\n ...defaultQueryOptions,\n ...(queryOptions ?? {}),\n }), [queryOptions]);\n\n const query = useInfiniteQuery<PortfolioListResponse, Error, Portfolio[], QueryKey, PageToken>({\n queryKey,\n initialPageParam: null,\n getNextPageParam: (lastPage) => lastPage.next_page_token ?? undefined,\n\n queryFn: async ({ pageParam }) => {\n const queryFilter = buildQueryObject({\n filters,\n order,\n projection,\n pageSize,\n pageToken: pageParam ?? undefined,\n });\n\n return await listPortfolios(api, queryFilter);\n },\n\n select: (data) => data.pages.flatMap((p) => p.portfolios),\n\n ...mergedQueryOptions,\n });\n\n return {\n query,\n queryKey,\n };\n}"],"mappings":";;;;;;AAoBA,IAAM,sBAAoD;CACtD,gBAAgB;CAChB,WAAW;CACX,QAAQ;AACZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,SAAgB,mBAAmB,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,GAAG,aAAa,IAAI,WAAW,IAAI,gBAA6C;CACxI,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,WAAW,cAAc,CAAC,YAAY,GAAG,OAAO;CAEtD,MAAM,qBAAqB,eAA6C;EACpE,GAAG;EACH,GAAI,gBAAgB,CAAC;CACzB,IAAI,CAAC,YAAY,CAAC;CAwBlB,OAAO;EACH,OAvBU,iBAAiF;GAC3F;GACA,kBAAkB;GAClB,mBAAmB,aAAa,SAAS,mBAAmB,KAAA;GAE5D,SAAS,OAAO,EAAE,gBAAgB;IAC9B,MAAM,cAAc,iBAAiB;KACjC;KACA;KACA;KACA;KACA,WAAW,aAAa,KAAA;IAC5B,CAAC;IAED,OAAO,MAAM,eAAe,KAAK,WAAW;GAChD;GAEA,SAAS,SAAS,KAAK,MAAM,SAAS,MAAM,EAAE,UAAU;GAExD,GAAG;EACP,CAGI;EACA;CACJ;AACJ"}
1
+ {"version":3,"file":"useFetchPortfolios.js","names":[],"sources":["../../../src/hooks/portfolio/useFetchPortfolios.ts"],"sourcesContent":["import { useAxios } from \"@/hooks/useAxios\";\nimport { useEntityInfiniteQuery } from \"@/hooks/useEntityInfiniteQuery\";\nimport { listPortfolios } from \"@/api/portfolio\";\nimport type { Portfolio, PortfolioListResponse } from \"@/types/portfolio\";\nimport type { FetchEntitiesProps, ListQueryProps, ListCache } from \"@/types/entityQuery\";\nimport {\n buildQueryKey,\n buildQueryObject,\n hasWorkspaceFilter,\n missingWorkspaceError,\n} from \"@/api/entityQuery\";\n\n/** The query cache of `useFetchPortfolios`, for typing `setQueryData`. */\nexport type PortfoliosCache = ListCache<PortfolioListResponse>;\n\nexport type FetchPortfoliosProps<TData = Portfolio[]> = ListQueryProps &\n FetchEntitiesProps<Portfolio, TData, PortfolioListResponse>;\n\n/**\n * useFetchPortfolios\n *\n * Lists portfolios with cursor pagination; `query.data` is every loaded page merged, or\n * whatever `select` makes of it. Paging, `select`, `fetchAllPages` and the\n * missing-workspace error behave as in `useFetchDatastores`.\n *\n * @param {FetchPortfoliosProps} props - Filters (one must be `workspace`), order,\n * projection, page size, `select`, `fetchAllPages` and TanStack `queryOptions`.\n * @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.\n */\nexport function useFetchPortfolios<TData = Portfolio[]>({\n filters = [],\n order = [],\n projection = \"\",\n pageSize = 10,\n select,\n fetchAllPages = false,\n queryOptions,\n}: FetchPortfoliosProps<TData>) {\n const { api } = useAxios();\n\n const queryKey = buildQueryKey([\"portfolios\"], filters, {\n order,\n projection,\n pageSize,\n fetchAllPages,\n });\n\n const query = useEntityInfiniteQuery<PortfolioListResponse, \"portfolios\", TData>({\n queryKey,\n itemsKey: \"portfolios\",\n fetchPage: (pageToken, signal) =>\n listPortfolios(\n api,\n buildQueryObject({ filters, order, projection, pageSize, pageToken }),\n signal,\n ),\n select,\n fetchAllPages,\n configError: hasWorkspaceFilter(filters)\n ? undefined\n : missingWorkspaceError(\"useFetchPortfolios\"),\n queryOptions,\n });\n\n return { query, queryKey };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA6BA,SAAgB,mBAAwC,EACpD,UAAU,CAAC,GACX,QAAQ,CAAC,GACT,aAAa,IACb,WAAW,IACX,QACA,gBAAgB,OAChB,gBAC4B;CAC5B,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,WAAW,cAAc,CAAC,YAAY,GAAG,SAAS;EACpD;EACA;EACA;EACA;CACJ,CAAC;CAmBD,OAAO;EAAE,OAjBK,uBAAmE;GAC7E;GACA,UAAU;GACV,YAAY,WAAW,WACnB,eACI,KACA,iBAAiB;IAAE;IAAS;IAAO;IAAY;IAAU;GAAU,CAAC,GACpE,MACJ;GACJ;GACA;GACA,aAAa,mBAAmB,OAAO,IACjC,KAAA,IACA,sBAAsB,oBAAoB;GAChD;EACJ,CAES;EAAO;CAAS;AAC7B"}
@@ -47,26 +47,26 @@ type UsePortfolioMutationsProps = {
47
47
  * - mutationFn: `createPortfolio(api, data)`
48
48
  * - variables: `{ data: Partial<Portfolio> }`
49
49
  * - success message: "Portfolio created successfully."
50
- * - error message: "We couldn't create the portfolio. Please review your inputs and try again." (fallback)
50
+ * - error message: "Unable to create the portfolio. Please try again." (fallback)
51
51
  *
52
52
  * - `update`:
53
53
  * - mutationFn: `updatePortfolio(api, id, data)`
54
54
  * - variables: `{ id: string; data: Partial<Portfolio> }`
55
55
  * - success message: "Portfolio updated successfully."
56
- * - error message: "We couldn't update the portfolio. Please try again." (fallback)
56
+ * - error message: "Unable to update the portfolio. Please try again." (fallback)
57
57
  *
58
58
  * - `remove`:
59
59
  * - mutationFn: `deletePortfolio(api, id, workspace)`
60
60
  * - variables: `{ id: string; workspace: string }`
61
61
  * - success message: "Portfolio deleted successfully."
62
- * - error message: "We couldn't delete the portfolio. Please try again." (fallback)
62
+ * - error message: "Unable to delete the portfolio. Please try again." (fallback)
63
63
  *
64
64
  * Return value:
65
65
  * @returns {object}
66
66
  * Returns an object with the three TanStack Query mutation results:
67
67
  * - `create`: UseMutationResult<Portfolio, Error, CreatePortfolioProps, unknown>
68
68
  * - `update`: UseMutationResult<Portfolio, Error, UpdatePortfolioProps, unknown>
69
- * - `remove`: UseMutationResult<Portfolio, Error, DeletePortfolioProps, unknown>
69
+ * - `remove`: UseMutationResult<DeletedEntity, Error, DeletePortfolioProps, unknown>
70
70
  *
71
71
  * Each mutation includes standard TanStack Query helpers:
72
72
  * - `mutate(variables, options?)`
@@ -79,7 +79,7 @@ type UsePortfolioMutationsProps = {
79
79
  * ```ts
80
80
  * const { create, update, remove } = usePortfolioMutations({ queryKey: ["portfolio"] });
81
81
  *
82
- * // Create (minimal example - other Security fields omitted for brevity)
82
+ * // Create (minimal example - other Security fields omitted for brevity)
83
83
  * create.mutate({
84
84
  * data: {
85
85
  * name: "My Portfolio",
@@ -163,9 +163,9 @@ type UsePortfolioMutationsProps = {
163
163
  * ```
164
164
  */
165
165
  export declare const usePortfolioMutations: ({ queryKey }: UsePortfolioMutationsProps) => {
166
- create: import("@tanstack/react-query").UseMutationResult<Portfolio, unknown, CreatePortfolioProps, unknown>;
167
- update: import("@tanstack/react-query").UseMutationResult<Portfolio, unknown, UpdatePortfolioProps, unknown>;
168
- remove: import("@tanstack/react-query").UseMutationResult<Portfolio, unknown, DeletePortfolioProps, unknown>;
166
+ create: import("@tanstack/react-query").UseMutationResult<Portfolio, Error, CreatePortfolioProps, unknown>;
167
+ update: import("@tanstack/react-query").UseMutationResult<Portfolio, Error, UpdatePortfolioProps, unknown>;
168
+ remove: import("@tanstack/react-query").UseMutationResult<import("../..").DeletedEntity, Error, DeletePortfolioProps, unknown>;
169
169
  };
170
170
  export {};
171
171
  //# sourceMappingURL=usePortfolioMutations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePortfolioMutations.d.ts","sourceRoot":"","sources":["../../../src/hooks/portfolio/usePortfolioMutations.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD,KAAK,oBAAoB,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;CAC5B,CAAC;AAEF,KAAK,oBAAoB,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;CAC5B,CAAC;AAEF,KAAK,oBAAoB,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAC9B,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACxB,CAAC;AAKF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoJG;AAEH,eAAO,MAAM,qBAAqB,GAAI,cAAc,0BAA0B;;;;CAuE7E,CAAC"}
1
+ {"version":3,"file":"usePortfolioMutations.d.ts","sourceRoot":"","sources":["../../../src/hooks/portfolio/usePortfolioMutations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAGnD,KAAK,oBAAoB,GAAG;IACxB,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;CAC5B,CAAC;AAEF,KAAK,oBAAoB,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;CAC5B,CAAC;AAEF,KAAK,oBAAoB,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,0BAA0B,GAAG;IAC9B,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoJG;AAEH,eAAO,MAAM,qBAAqB,GAAI,cAAc,0BAA0B;;;;CA0B7E,CAAC"}