@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
@@ -0,0 +1,70 @@
1
+ import { useMutation, useQueryClient, type QueryKey } from "@tanstack/react-query";
2
+
3
+ import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
4
+
5
+ export type EntityMutationProps<TVariables, TResult> = {
6
+ /** Sends the write. Receives the variables passed to `mutate`, and only those. */
7
+ mutationFn: (variables: TVariables) => Promise<TResult>;
8
+ /**
9
+ * Invalidated after a success, so the screens reading it refetch. Pass the `queryKey` a fetch
10
+ * hook returned, or a prefix of it (`["datastores"]`) to refresh every list of that entity.
11
+ */
12
+ queryKey?: QueryKey;
13
+ /** Shown as a success alert. */
14
+ successMessage: string;
15
+ /** Shown as an error alert when the failure carries no message of its own. */
16
+ errorMessage: string;
17
+ };
18
+
19
+ /**
20
+ * useEntityMutation
21
+ *
22
+ * The write hook every SDK mutation is built on, and the one to build on for an endpoint the SDK
23
+ * does not cover — the counterpart of `useEntityQuery`. A hook says how to send the write and
24
+ * what to tell the user; this owns the cache invalidation and the alerts.
25
+ *
26
+ * It replaced nine copies of the same `useMutation` call across `useDatastoreMutations`,
27
+ * `useFileMutations` and `usePortfolioMutations`, which had already drifted apart in wording.
28
+ *
29
+ * The invalidation is awaited before the mutation resolves, so code after `mutateAsync` sees the
30
+ * refetched data rather than racing it.
31
+ *
32
+ * @returns {UseMutationResult} The `useMutation` result.
33
+ *
34
+ * Example:
35
+ * ```ts
36
+ * export const useReportMutations = ({ queryKey }: { queryKey?: QueryKey }) => {
37
+ * const { api } = useAxios();
38
+ *
39
+ * const share = useEntityMutation({
40
+ * mutationFn: ({ id, workspace }: ShareReportProps) => shareReport(api, id, workspace),
41
+ * queryKey,
42
+ * successMessage: "Report shared successfully.",
43
+ * errorMessage: "Unable to share the report. Please try again.",
44
+ * });
45
+ *
46
+ * return { share };
47
+ * };
48
+ * ```
49
+ */
50
+ export function useEntityMutation<TVariables, TResult>({
51
+ mutationFn,
52
+ queryKey,
53
+ successMessage,
54
+ errorMessage,
55
+ }: EntityMutationProps<TVariables, TResult>) {
56
+ const { showAlert } = useAppAlert();
57
+ const queryClient = useQueryClient();
58
+
59
+ return useMutation<TResult, Error, TVariables>({
60
+ // TanStack passes a context as a second argument; the request gets the variables alone.
61
+ mutationFn: (variables) => mutationFn(variables),
62
+ onSuccess: async () => {
63
+ if (queryKey?.length) await queryClient.invalidateQueries({ queryKey });
64
+ showAlert({ severity: "success", message: successMessage });
65
+ },
66
+ onError: (error) => {
67
+ showAlert({ severity: "error", message: error.message || errorMessage });
68
+ },
69
+ });
70
+ }
@@ -0,0 +1,117 @@
1
+ import { useEffect } from "react";
2
+ import { useQuery, type QueryKey } from "@tanstack/react-query";
3
+
4
+ import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
5
+ import { failWithConfigError } from "@/hooks/useEntityInfiniteQuery";
6
+ import type { EntityQueryOptions } from "@/types/entityQuery";
7
+
8
+ export type EntityQueryProps<TEntity, TData> = {
9
+ /** Must describe everything that changes the response: the entity's ids and workspace. */
10
+ queryKey: QueryKey;
11
+ /**
12
+ * Requests the entity. `signal` aborts when no screen wants it any more — pass it to the
13
+ * request (`api.get(url, { signal })`) to cancel it in flight.
14
+ */
15
+ fetchEntity: (signal: AbortSignal) => Promise<TEntity>;
16
+ select?: (entity: TEntity) => TData;
17
+ /**
18
+ * Your hook's own precondition for something legitimately not there yet — an id from a
19
+ * selection the user has not made — ANDed with the caller's `queryOptions.enabled`. Unmet,
20
+ * the query stays idle rather than send an empty id, which reaches another endpoint entirely.
21
+ */
22
+ enabled?: boolean;
23
+ /**
24
+ * Why the request cannot be right, when it cannot — `missingWorkspaceError(hookName)` in the
25
+ * SDK's hooks. Set, the query fails at once with it, without a request or a retry, logs it once
26
+ * with `console.error` and shows it as the error alert. See `useEntityInfiniteQuery`.
27
+ * It is reported even while `enabled` is unmet, so an empty id cannot hide a misconfigured
28
+ * workspace; only the caller's `queryOptions.enabled: false` holds it back.
29
+ */
30
+ configError?: string;
31
+ /** Replaces the SDK's defaults for this hook, as the profile does. */
32
+ defaultQueryOptions?: EntityQueryOptions<TEntity, TData>;
33
+ queryOptions?: EntityQueryOptions<TEntity, TData>;
34
+ };
35
+
36
+ /**
37
+ * The entity hooks read data the platform keeps changing, so by default nothing is cached:
38
+ * refetched on every mount, dropped as soon as no screen reads it.
39
+ */
40
+ const sdkDefaultQueryOptions = {
41
+ refetchOnMount: "always",
42
+ staleTime: 0,
43
+ gcTime: 0,
44
+ } as const;
45
+
46
+ /**
47
+ * useEntityQuery
48
+ *
49
+ * The single-entity hook every SDK single-entity hook is built on, and the one to build on for
50
+ * an endpoint the SDK does not cover — the counterpart of `useEntityInfiniteQuery`. A hook says
51
+ * how to request the entity; this owns the defaults, the idle precondition, `select` and the
52
+ * error alert.
53
+ *
54
+ * It replaced eight copies of the same `useQuery` call, which is how one defect had reached all
55
+ * eight: each declared `queryOptions = defaultQueryOptions`, so passing any option replaced the
56
+ * defaults and the query fell back to TanStack's own (a 5-minute cache instead of none). Here
57
+ * the caller's options are merged over the defaults.
58
+ *
59
+ * A failure is shown through `useAppAlert`, as the entity hooks always have.
60
+ *
61
+ * @returns {UseQueryResult} The `useQuery` result; `data` is the entity, or what `select` makes
62
+ * of it. The SDK's hooks spread it and add `queryKey`.
63
+ *
64
+ * Example:
65
+ * ```ts
66
+ * export const useFetchReport = <TData = Report>({ id, workspace, select, queryOptions }: Props<TData>) => {
67
+ * const { api } = useAxios();
68
+ * const queryKey = ["report", id, workspace];
69
+ *
70
+ * const query = useEntityQuery<Report, TData>({
71
+ * queryKey,
72
+ * fetchEntity: (signal) => getReport(api, id, workspace, signal),
73
+ * select,
74
+ * enabled: Boolean(id),
75
+ * configError: workspace ? undefined : missingWorkspaceError("useFetchReport"),
76
+ * queryOptions,
77
+ * });
78
+ *
79
+ * return { ...query, queryKey };
80
+ * };
81
+ * ```
82
+ */
83
+ export function useEntityQuery<TEntity, TData = TEntity>({
84
+ queryKey,
85
+ fetchEntity,
86
+ select,
87
+ enabled = true,
88
+ configError,
89
+ defaultQueryOptions = sdkDefaultQueryOptions,
90
+ queryOptions,
91
+ }: EntityQueryProps<TEntity, TData>) {
92
+ const { showAlert } = useAppAlert();
93
+
94
+ const query = useQuery<TEntity, Error, TData>({
95
+ ...defaultQueryOptions,
96
+ ...queryOptions,
97
+
98
+ queryKey,
99
+ queryFn: async ({ signal }) =>
100
+ configError ? failWithConfigError(configError) : fetchEntity(signal),
101
+ // A retry would rerun the same check and delay an error that cannot resolve itself.
102
+ ...(configError ? { retry: false } : {}),
103
+ select,
104
+ // A config error runs past the hook's own precondition, so that an empty id cannot hide a
105
+ // misconfigured workspace; the caller's `enabled` still wins. Kept as the caller wrote it,
106
+ // so a function still works.
107
+ enabled: configError || enabled ? (queryOptions?.enabled ?? true) : false,
108
+ });
109
+
110
+ useEffect(() => {
111
+ if (!query.error) return;
112
+
113
+ showAlert({ severity: "error", message: query.error.message });
114
+ }, [query.error, showAlert]);
115
+
116
+ return query;
117
+ }
@@ -1,78 +1,49 @@
1
- import { useEffect } from "react";
2
-
3
- import { useQuery } from "@tanstack/react-query";
4
-
5
1
  import { useAxios } from "@/hooks/useAxios";
6
- import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
2
+ import { useEntityQuery } from "@/hooks/useEntityQuery";
3
+ import { missingWorkspaceError } from "@/api/entityQuery";
7
4
  import { getWorkerExecution } from "@/api/workflow";
8
5
  import type { WorkerExecution } from "@/types/workflow";
9
- import type { EntityQueryOptions } from "@/types/entityQuery";
6
+ import type { FetchEntityProps } from "@/types/entityQuery";
10
7
 
11
- export type FetchWorkerExecutionProps<TData = WorkerExecution, TSelected = TData> = {
8
+ export type FetchWorkerExecutionProps<
9
+ TData = WorkerExecution,
10
+ TSelected = TData,
11
+ > = FetchEntityProps<TData, TSelected> & {
12
12
  workflowId: string;
13
13
  workerExecutionId: string;
14
14
  workspace: string;
15
- queryOptions?: EntityQueryOptions<TData, TSelected>;
16
- };
17
-
18
- const defaultQueryOptions: EntityQueryOptions<WorkerExecution> = {
19
- refetchOnMount: "always",
20
- staleTime: 0,
21
- gcTime: 0,
22
15
  };
23
16
 
24
17
  /**
25
18
  * useFetchWorkerExecution
26
19
  *
27
- * Data-fetching hook built on TanStack Query to retrieve a single worker execution.
28
- *
29
- * It also:
30
- * - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
31
- * - triggers an error alert via `useAppAlert` whenever `query.error` is present
32
- *
33
- * @param workflowId - Workflow identifier the worker execution belongs to (required).
34
- * @param workerExecutionId - Worker execution identifier (required).
35
- * @param workspace - Workspace the workflow belongs to (required).
36
- * @param queryOptions - TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
20
+ * Fetches one worker execution; `data` is the execution, or whatever `select` makes of it. Idle
21
+ * while an id is empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error alert.
37
22
  *
38
- * @returns TanStack Query result extended with `queryKey`.
39
- *
40
- * Example:
41
- * ```ts
42
- * const { data, isLoading } = useFetchWorkerExecution({
43
- * workflowId: "wf-123",
44
- * workerExecutionId: "wkex-456",
45
- * workspace: "main",
46
- * });
47
- * // data -> WorkerExecution
48
- * ```
23
+ * @param {FetchWorkerExecutionProps} props - `workflowId`, `workerExecutionId`, `workspace`,
24
+ * `select` and TanStack `queryOptions`.
25
+ * @returns {object} The `useQuery` result, plus `queryKey`.
49
26
  */
50
- export const useFetchWorkerExecution = ({ workflowId, workerExecutionId, workspace, queryOptions = defaultQueryOptions }: FetchWorkerExecutionProps) => {
51
-
27
+ export const useFetchWorkerExecution = <TSelected = WorkerExecution>({
28
+ workflowId,
29
+ workerExecutionId,
30
+ workspace,
31
+ select,
32
+ queryOptions,
33
+ }: FetchWorkerExecutionProps<WorkerExecution, TSelected>) => {
52
34
  const { api } = useAxios();
53
- const { showAlert } = useAppAlert();
54
35
 
55
36
  const queryKey = ["worker_execution", workflowId, workerExecutionId, workspace];
56
37
 
57
- const query = useQuery<WorkerExecution>({
38
+ const query = useEntityQuery<WorkerExecution, TSelected>({
58
39
  queryKey,
59
- queryFn: async () => {
60
- return await getWorkerExecution(api, workflowId, workerExecutionId, workspace);
61
- },
62
- ...queryOptions ?? {}
40
+ fetchEntity: (signal) =>
41
+ getWorkerExecution(api, workflowId, workerExecutionId, workspace, signal),
42
+ select,
43
+ enabled: Boolean(workflowId) && Boolean(workerExecutionId),
44
+ configError: workspace ? undefined : missingWorkspaceError("useFetchWorkerExecution"),
45
+ queryOptions,
63
46
  });
64
47
 
65
- useEffect(() => {
66
- if (!query.error) return;
67
-
68
- showAlert({
69
- severity: "error",
70
- message: query.error.message,
71
- });
72
- }, [query.error, showAlert]);
73
-
74
- return {
75
- ...query,
76
- queryKey,
77
- };
48
+ return { ...query, queryKey };
78
49
  };
@@ -1,98 +1,73 @@
1
- import { useMemo } from "react";
2
- import { useInfiniteQuery, type UseInfiniteQueryOptions, type QueryKey } from "@tanstack/react-query";
3
-
4
1
  import { useAxios } from "@/hooks/useAxios";
2
+ import { useEntityQuery } from "@/hooks/useEntityQuery";
5
3
  import { listWorkerExecutions } from "@/api/workflow";
6
- import type { FetchEntitiesParams } from "@/types/entityQuery";
7
- import { buildQueryKey, buildQueryObject } from "@/api/entityQuery";
8
- import type { WorkerExecution, WorkerExecutionListResponse } from "@/types/workflow";
9
-
10
- type PageToken = string | null;
4
+ import { missingWorkspaceError } from "@/api/entityQuery";
5
+ import type { FetchEntityProps } from "@/types/entityQuery";
6
+ import type { WorkerExecutionGroup } from "@/types/workflow";
11
7
 
12
- type InfiniteOptions<TData> = Omit<UseInfiniteQueryOptions<WorkerExecutionListResponse, Error, TData, QueryKey, PageToken>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
13
-
14
- export type FetchInfiniteWorkerExecutionProps = FetchEntitiesParams<WorkerExecution[], InfiniteOptions<WorkerExecution[]>> & {
8
+ export type FetchWorkerExecutionsProps<
9
+ TData = WorkerExecutionGroup[],
10
+ TSelected = TData,
11
+ > = FetchEntityProps<TData, TSelected> & {
15
12
  workflowId: string;
16
13
  workflowExecutionId: string;
17
- pageSize?: number;
18
- };
19
-
20
- const defaultQueryOptions: InfiniteOptions<WorkerExecution[]> = {
21
- refetchOnMount: "always",
22
- staleTime: 0,
23
- gcTime: 0,
14
+ workspace: string;
15
+ /** Include each run's `result` and `input_params`. The API leaves them out by default. */
16
+ withResult?: boolean;
24
17
  };
25
18
 
26
19
  /**
27
20
  * useFetchWorkerExecutions
28
21
  *
29
- * Data-fetching hook built on TanStack Query's `useInfiniteQuery` to retrieve
30
- * worker executions for a given workflow with cursor-based pagination.
31
- *
32
- * Automatically flattens all pages into a single `WorkerExecution[]` via `select`.
33
- *
34
- * Note: `query.data` returns a flat `WorkerExecution[]` with all fetched items merged across pages.
35
- *
36
- * @param workflowId - Workflow identifier whose worker executions to fetch (required).
37
- * @param workflowExecutionId - Workflow execution identifier to filter worker executions (required).
38
- * @param filters - Filters applied to every page request. Must include a `workspace` filter.
39
- * @param order - Sorting applied to every page request.
40
- * @param projection - Single field to project: `"field"` returns only that field (others come
41
- * back null), `"-field"` returns every field except that one. One field only — lists 500. Omitted when empty.
42
- * @param pageSize - Number of executions to fetch per page. Defaults to `10`.
43
- * @param queryOptions - TanStack Query options passed through to `useInfiniteQuery`.
22
+ * Fetches every worker execution of one workflow execution, grouped by worker; `data` is the
23
+ * groups, or whatever `select` makes of them. Narrow a group on `is_parallel_execution`: a
24
+ * worker that ran in parallel carries every run under `executions`, any other one its run as
25
+ * `execution`. Idle while an id is empty; fails loudly, without a request, while `workspace` is.
26
+ * A failure is shown as an error alert.
44
27
  *
45
- * @returns
46
- * - `query`: the full `useInfiniteQuery` result (data, isLoading, hasNextPage, fetchNextPage, etc.)
47
- * - `queryKey`: the cache key used by React Query
28
+ * A plain query, not an infinite one, and so shaped like the single-entity hooks: the endpoint
29
+ * returns the whole set at once, with no cursor to page by. It used to be paged, over a JSON
30
+ * query the endpoint ignores, and typed as a flat list of worker executions.
48
31
  *
49
- * @example
50
- * ```ts
51
- * const { query } = useFetchWorkerExecutions({
52
- * workflowId: "wf-123",
53
- * workflowExecutionId: "wfex-456",
54
- * filters: [{ field: "workspace", value: "main" }],
55
- * pageSize: 20,
56
- * });
57
- *
58
- * // Flat list of all fetched worker executions
59
- * const workerExecutions = query.data ?? [];
60
- * ```
32
+ * @param {FetchWorkerExecutionsProps} props - Workflow and execution ids, workspace,
33
+ * `withResult`, `select` and TanStack `queryOptions`.
34
+ * @returns {object} The `useQuery` result, plus `queryKey`.
61
35
  */
62
- export function useFetchWorkerExecutions({ workflowId, workflowExecutionId, filters = [], order = [], projection = "", pageSize = 10, queryOptions }: FetchInfiniteWorkerExecutionProps) {
36
+ export const useFetchWorkerExecutions = <TSelected = WorkerExecutionGroup[]>({
37
+ workflowId,
38
+ workflowExecutionId,
39
+ workspace,
40
+ withResult,
41
+ select,
42
+ queryOptions,
43
+ }: FetchWorkerExecutionsProps<WorkerExecutionGroup[], TSelected>) => {
63
44
  const { api } = useAxios();
64
45
 
65
- const queryKey = buildQueryKey(["worker_executions", workflowId, workflowExecutionId], filters);
66
-
67
- const mergedQueryOptions = useMemo<InfiniteOptions<WorkerExecution[]>>(() => ({
68
- ...defaultQueryOptions,
69
- ...(queryOptions ?? {}),
70
- }), [queryOptions]);
46
+ const queryKey = [
47
+ "worker_executions",
48
+ workflowId,
49
+ workflowExecutionId,
50
+ workspace,
51
+ withResult ?? null,
52
+ ];
71
53
 
72
- const query = useInfiniteQuery<WorkerExecutionListResponse, Error, WorkerExecution[], QueryKey, PageToken>({
54
+ const query = useEntityQuery<WorkerExecutionGroup[], TSelected>({
73
55
  queryKey,
74
- initialPageParam: null,
75
- getNextPageParam: (lastPage) => lastPage.next_page_token ?? undefined,
76
-
77
- queryFn: async ({ pageParam }) => {
78
- const queryFilter = buildQueryObject({
79
- filters,
80
- order,
81
- projection,
82
- pageSize,
83
- pageToken: pageParam ?? undefined,
84
- });
85
-
86
- return await listWorkerExecutions(api, workflowId, workflowExecutionId, queryFilter);
87
- },
88
-
89
- select: (data) => data.pages.flatMap((p) => p.worker_executions),
90
-
91
- ...mergedQueryOptions,
56
+ fetchEntity: async (signal) =>
57
+ (
58
+ await listWorkerExecutions(
59
+ api,
60
+ workflowId,
61
+ workflowExecutionId,
62
+ { workspace, withResult },
63
+ signal,
64
+ )
65
+ ).worker_executions,
66
+ select,
67
+ enabled: Boolean(workflowId) && Boolean(workflowExecutionId),
68
+ configError: workspace ? undefined : missingWorkspaceError("useFetchWorkerExecutions"),
69
+ queryOptions,
92
70
  });
93
71
 
94
- return {
95
- query,
96
- queryKey,
97
- };
98
- }
72
+ return { ...query, queryKey };
73
+ };
@@ -1,76 +1,42 @@
1
- import { useEffect } from "react";
2
-
3
- import { useQuery } from "@tanstack/react-query";
4
-
5
1
  import { useAxios } from "@/hooks/useAxios";
6
- import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
2
+ import { useEntityQuery } from "@/hooks/useEntityQuery";
3
+ import { missingWorkspaceError } from "@/api/entityQuery";
7
4
  import { getWorkflow } from "@/api/workflow";
8
5
  import type { Workflow } from "@/types/workflow";
9
- import type { EntityQueryOptions, FetchEntityParams } from "@/types/entityQuery";
10
-
11
- export type FetchWorkflowProps<TData = Workflow, TSelected = TData> = FetchEntityParams<TData, TSelected>;
6
+ import type { FetchEntityByIdProps } from "@/types/entityQuery";
12
7
 
13
- const defaultQueryOptions: EntityQueryOptions<Workflow> = {
14
- refetchOnMount: "always",
15
- staleTime: 0,
16
- gcTime: 0
17
- }
8
+ export type FetchWorkflowProps<TData = Workflow, TSelected = TData> = FetchEntityByIdProps<
9
+ TData,
10
+ TSelected
11
+ >;
18
12
 
19
13
  /**
20
14
  * useFetchWorkflow
21
15
  *
22
- * Data-fetching hook built on TanStack Query to retrieve a single workflow by ID.
23
- *
24
- * It also:
25
- * - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
26
- * - triggers an error alert via `useAppAlert` whenever `query.error` is present
27
- *
28
- * @param id - Workflow identifier (required).
29
- * @param workspace - Workspace the workflow belongs to (required).
30
- * @param queryOptions - TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
31
- *
32
- * @returns TanStack Query result extended with `queryKey`.
16
+ * Fetches one workflow; `data` is the workflow, or whatever `select` makes of it. Idle while
17
+ * `id` is empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error alert.
33
18
  *
34
- * Tip:
35
- * - The returned `queryKey` can be reused by mutation hooks for cache invalidation:
36
- * ```ts
37
- * const fetch = useFetchWorkflow({ id: "wf-123", workspace: "main" });
38
- * useWorkflowMutations({ queryKey: fetch.queryKey });
39
- * ```
40
- *
41
- * Example:
42
- * ```ts
43
- * const { data, isLoading } = useFetchWorkflow({ id: "wf-123", workspace: "main" });
44
- * // data -> Workflow
45
- * ```
19
+ * @param {FetchWorkflowProps} props - `id`, `workspace`, `select` and TanStack `queryOptions`.
20
+ * @returns {object} The `useQuery` result, plus `queryKey`.
46
21
  */
47
- export const useFetchWorkflow = ({ id, workspace, queryOptions = defaultQueryOptions }: FetchWorkflowProps) => {
48
-
22
+ export const useFetchWorkflow = <TSelected = Workflow>({
23
+ id,
24
+ workspace,
25
+ select,
26
+ queryOptions,
27
+ }: FetchWorkflowProps<Workflow, TSelected>) => {
49
28
  const { api } = useAxios();
50
- const { showAlert } = useAppAlert();
51
29
 
52
30
  const queryKey = ["workflow", id, workspace];
53
31
 
54
- const query = useQuery<Workflow>({
32
+ const query = useEntityQuery<Workflow, TSelected>({
55
33
  queryKey,
56
- queryFn: async () => {
57
- const workflow = await getWorkflow(api, id, workspace);
58
- return workflow;
59
- },
60
- ...queryOptions ?? {}
34
+ fetchEntity: (signal) => getWorkflow(api, id, workspace, signal),
35
+ select,
36
+ enabled: Boolean(id),
37
+ configError: workspace ? undefined : missingWorkspaceError("useFetchWorkflow"),
38
+ queryOptions,
61
39
  });
62
40
 
63
- useEffect(() => {
64
- if (!query.error) return;
65
-
66
- showAlert({
67
- severity: "error",
68
- message: query.error.message,
69
- });
70
- }, [query.error, showAlert]);
71
-
72
- return {
73
- ...query,
74
- queryKey,
75
- };
41
+ return { ...query, queryKey };
76
42
  };
@@ -1,79 +1,49 @@
1
- import { useEffect } from "react";
2
-
3
- import { useQuery } from "@tanstack/react-query";
4
-
5
1
  import { useAxios } from "@/hooks/useAxios";
6
- import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
2
+ import { useEntityQuery } from "@/hooks/useEntityQuery";
3
+ import { missingWorkspaceError } from "@/api/entityQuery";
7
4
  import { getWorkflowExecution } from "@/api/workflow";
8
5
  import type { WorkflowExecution } from "@/types/workflow";
9
- import type { EntityQueryOptions } from "@/types/entityQuery";
6
+ import type { FetchEntityProps } from "@/types/entityQuery";
10
7
 
11
- export type FetchWorkflowExecutionProps<TData = WorkflowExecution, TSelected = TData> = {
8
+ export type FetchWorkflowExecutionProps<
9
+ TData = WorkflowExecution,
10
+ TSelected = TData,
11
+ > = FetchEntityProps<TData, TSelected> & {
12
12
  workflowId: string;
13
13
  workflowExecutionId: string;
14
14
  workspace: string;
15
- queryOptions?: EntityQueryOptions<TData, TSelected>;
16
- };
17
-
18
- const defaultQueryOptions: EntityQueryOptions<WorkflowExecution> = {
19
- refetchOnMount: "always",
20
- staleTime: 0,
21
- gcTime: 0,
22
15
  };
23
16
 
24
17
  /**
25
18
  * useFetchWorkflowExecution
26
19
  *
27
- * Data-fetching hook built on TanStack Query to retrieve a single workflow execution.
28
- *
29
- * It also:
30
- * - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
31
- * - triggers an error alert via `useAppAlert` whenever `query.error` is present
32
- *
33
- * @param workflowId - Workflow identifier the execution belongs to (required).
34
- * @param workflowExecutionId - Workflow execution identifier (required).
35
- * @param workspace - Workspace the workflow belongs to (required).
36
- * @param queryOptions - TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
20
+ * Fetches one execution of a workflow; `data` is the execution, or whatever `select` makes of
21
+ * it. Idle while an id is empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error alert.
37
22
  *
38
- * @returns TanStack Query result extended with `queryKey`.
39
- *
40
- * Example:
41
- * ```ts
42
- * const { data, isLoading } = useFetchWorkflowExecution({
43
- * workflowId: "wf-123",
44
- * workflowExecutionId: "exec-456",
45
- * workspace: "main",
46
- * });
47
- * // data -> WorkflowExecution
48
- * ```
23
+ * @param {FetchWorkflowExecutionProps} props - `workflowId`, `workflowExecutionId`, `workspace`,
24
+ * `select` and TanStack `queryOptions`.
25
+ * @returns {object} The `useQuery` result, plus `queryKey`.
49
26
  */
50
- export const useFetchWorkflowExecution = ({ workflowId, workflowExecutionId, workspace, queryOptions = defaultQueryOptions }: FetchWorkflowExecutionProps) => {
51
-
27
+ export const useFetchWorkflowExecution = <TSelected = WorkflowExecution>({
28
+ workflowId,
29
+ workflowExecutionId,
30
+ workspace,
31
+ select,
32
+ queryOptions,
33
+ }: FetchWorkflowExecutionProps<WorkflowExecution, TSelected>) => {
52
34
  const { api } = useAxios();
53
- const { showAlert } = useAppAlert();
54
35
 
55
36
  const queryKey = ["workflow_execution", workflowId, workflowExecutionId, workspace];
56
37
 
57
- const query = useQuery<WorkflowExecution>({
38
+ const query = useEntityQuery<WorkflowExecution, TSelected>({
58
39
  queryKey,
59
- queryFn: async () => {
60
- const execution = await getWorkflowExecution(api, workflowId, workflowExecutionId, workspace);
61
- return execution;
62
- },
63
- ...queryOptions ?? {}
40
+ fetchEntity: (signal) =>
41
+ getWorkflowExecution(api, workflowId, workflowExecutionId, workspace, signal),
42
+ select,
43
+ enabled: Boolean(workflowId) && Boolean(workflowExecutionId),
44
+ configError: workspace ? undefined : missingWorkspaceError("useFetchWorkflowExecution"),
45
+ queryOptions,
64
46
  });
65
47
 
66
- useEffect(() => {
67
- if (!query.error) return;
68
-
69
- showAlert({
70
- severity: "error",
71
- message: query.error.message,
72
- });
73
- }, [query.error, showAlert]);
74
-
75
- return {
76
- ...query,
77
- queryKey,
78
- };
48
+ return { ...query, queryKey };
79
49
  };