@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,95 +1,86 @@
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 { useEntityInfiniteQuery } from "@/hooks/useEntityInfiniteQuery";
5
3
  import { listWorkflowExecutions } from "@/api/workflow";
6
- import type { FetchEntitiesParams } from "@/types/entityQuery";
7
- import { buildQueryKey, buildQueryObject } from "@/api/entityQuery";
4
+ import type { FetchEntitiesProps, ListCache } from "@/types/entityQuery";
5
+ import { buildQueryKey, missingWorkspaceError } from "@/api/entityQuery";
8
6
  import type { WorkflowExecution, WorkflowExecutionListResponse } from "@/types/workflow";
9
7
 
10
- type PageToken = string | null;
11
-
12
- type InfiniteOptions<TData> = Omit<UseInfiniteQueryOptions<WorkflowExecutionListResponse, Error, TData, QueryKey, PageToken>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
8
+ /** The query cache of `useFetchWorkflowExecutions`, for typing `setQueryData`. */
9
+ export type WorkflowExecutionsCache = ListCache<WorkflowExecutionListResponse>;
13
10
 
14
- export type FetchInfiniteWorkflowExecutionProps = FetchEntitiesParams<WorkflowExecution[], InfiniteOptions<WorkflowExecution[]>> & {
11
+ export type FetchWorkflowExecutionsProps<TData = WorkflowExecution[]> = FetchEntitiesProps<
12
+ WorkflowExecution,
13
+ TData,
14
+ WorkflowExecutionListResponse
15
+ > & {
15
16
  workflowId: string;
16
- pageSize?: number;
17
- };
18
-
19
- const defaultQueryOptions: InfiniteOptions<WorkflowExecution[]> = {
20
- refetchOnMount: "always",
21
- staleTime: 0,
22
- gcTime: 0,
17
+ workspace: string;
18
+ /** Only the executions this worker took part in. */
19
+ workerId?: string;
20
+ /** Include each execution's `resume`, the per-worker summary. */
21
+ withResume?: boolean;
23
22
  };
24
23
 
25
24
  /**
26
25
  * useFetchWorkflowExecutions
27
26
  *
28
- * Data-fetching hook built on TanStack Query's `useInfiniteQuery` to retrieve
29
- * workflow executions for a given workflow with cursor-based pagination.
30
- *
31
- * Automatically flattens all pages into a single `WorkflowExecution[]` via `select`.
32
- *
33
- * Note: `query.data` returns a flat `WorkflowExecution[]` with all fetched items merged across pages.
34
- *
35
- * @param workflowId - Workflow identifier whose executions to fetch (required).
36
- * @param filters - Filters applied to every page request. Must include a `workspace` filter.
37
- * @param order - Sorting applied to every page request.
38
- * @param projection - Single field to project: `"field"` returns only that field (others come
39
- * back null), `"-field"` returns every field except that one. One field only — lists 500. Omitted when empty.
40
- * @param pageSize - Number of executions to fetch per page. Defaults to `10`.
41
- * @param queryOptions - TanStack Query options passed through to `useInfiniteQuery`.
27
+ * Lists the executions of one workflow, newest first, with cursor pagination; `query.data` is
28
+ * every loaded page merged, or whatever `select` makes of it. `select`, `fetchAllPages` and the
29
+ * missing-workspace error behave as in `useFetchDatastores`. Idle while `workflowId` is empty.
42
30
  *
43
- * @returns
44
- * - `query`: the full `useInfiniteQuery` result (data, isLoading, hasNextPage, fetchNextPage, etc.)
45
- * - `queryKey`: the cache key used by React Query
31
+ * The endpoint takes no filters, order or projection: only a worker id and `withResume`. It used
32
+ * to accept them as props and send them in a JSON query the endpoint ignores, along with the
33
+ * cursor, so every "next page" was the first one.
46
34
  *
47
- * @example
48
- * ```ts
49
- * const { query } = useFetchWorkflowExecutions({
50
- * workflowId: "wf-123",
51
- * filters: [{ field: "workspace", value: "main" }],
52
- * pageSize: 20,
53
- * });
35
+ * The key starts with `["workflow_executions", workflowId]`, which is what apps invalidate to
36
+ * refresh the list after running a workflow.
54
37
  *
55
- * // Flat list of all fetched executions
56
- * const executions = query.data ?? [];
57
- * ```
38
+ * @param {FetchWorkflowExecutionsProps} props - Workflow id, workspace, worker id,
39
+ * `withResume`, page size, `select`, `fetchAllPages`, `queryOptions`.
40
+ * @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.
58
41
  */
59
- export function useFetchWorkflowExecutions({ workflowId, filters = [], order = [], projection = "", pageSize = 10, queryOptions }: FetchInfiniteWorkflowExecutionProps) {
42
+ export function useFetchWorkflowExecutions<TData = WorkflowExecution[]>({
43
+ workflowId,
44
+ workspace,
45
+ workerId,
46
+ withResume,
47
+ pageSize = 10,
48
+ select,
49
+ fetchAllPages = false,
50
+ queryOptions,
51
+ }: FetchWorkflowExecutionsProps<TData>) {
60
52
  const { api } = useAxios();
61
53
 
62
- const queryKey = buildQueryKey(["workflow_executions", workflowId], filters);
63
-
64
- const mergedQueryOptions = useMemo<InfiniteOptions<WorkflowExecution[]>>(() => ({
65
- ...defaultQueryOptions,
66
- ...(queryOptions ?? {}),
67
- }), [queryOptions]);
54
+ // The endpoint's two filters go in the key as filters, so a list per worker gets its own entry.
55
+ const filters = [
56
+ ...(workerId ? [{ field: "worker_id", value: workerId }] : []),
57
+ ...(withResume !== undefined ? [{ field: "with_resume", value: withResume }] : []),
58
+ ];
59
+ const queryKey = buildQueryKey(["workflow_executions", workflowId, workspace], filters, {
60
+ pageSize,
61
+ fetchAllPages,
62
+ });
68
63
 
69
- const query = useInfiniteQuery<WorkflowExecutionListResponse, Error, WorkflowExecution[], QueryKey, PageToken>({
64
+ const query = useEntityInfiniteQuery<
65
+ WorkflowExecutionListResponse,
66
+ "workflow_executions",
67
+ TData
68
+ >({
70
69
  queryKey,
71
- initialPageParam: null,
72
- getNextPageParam: (lastPage) => lastPage.next_page_token ?? undefined,
73
-
74
- queryFn: async ({ pageParam }) => {
75
- const queryFilter = buildQueryObject({
76
- filters,
77
- order,
78
- projection,
79
- pageSize,
80
- pageToken: pageParam ?? undefined,
81
- });
82
-
83
- return await listWorkflowExecutions(api, workflowId, queryFilter);
84
- },
85
-
86
- select: (data) => data.pages.flatMap((p) => p.workflow_executions),
87
-
88
- ...mergedQueryOptions,
70
+ itemsKey: "workflow_executions",
71
+ fetchPage: (pageToken, signal) =>
72
+ listWorkflowExecutions(
73
+ api,
74
+ workflowId,
75
+ { workspace, pageSize, pageToken: pageToken ?? undefined, workerId, withResume },
76
+ signal,
77
+ ),
78
+ select,
79
+ fetchAllPages,
80
+ enabled: Boolean(workflowId),
81
+ configError: workspace ? undefined : missingWorkspaceError("useFetchWorkflowExecutions"),
82
+ queryOptions,
89
83
  });
90
84
 
91
- return {
92
- query,
93
- queryKey,
94
- };
85
+ return { query, queryKey };
95
86
  }
@@ -1,84 +1,68 @@
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 { useEntityInfiniteQuery } from "@/hooks/useEntityInfiniteQuery";
5
3
  import { listWorkflows } from "@/api/workflow";
4
+ import { buildQueryKey, missingWorkspaceError } from "@/api/entityQuery";
6
5
  import type { Workflow, WorkflowListResponse } from "@/types/workflow";
6
+ import type { FetchEntitiesProps, ListCache } from "@/types/entityQuery";
7
7
 
8
- type PageToken = string | null;
9
-
10
- type InfiniteOptions<TData> = Omit<UseInfiniteQueryOptions<WorkflowListResponse, Error, TData, QueryKey, PageToken>,"queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
11
-
12
- export type FetchInfiniteWorkflowProps = {
13
- workspace?: string;
14
- pageSize?: number;
15
- queryOptions?: InfiniteOptions<Workflow[]>;
16
- };
8
+ /** The query cache of `useFetchWorkflows`, for typing `setQueryData`. */
9
+ export type WorkflowsCache = ListCache<WorkflowListResponse>;
17
10
 
18
- const defaultQueryOptions: InfiniteOptions<Workflow[]> = {
19
- refetchOnMount: "always",
20
- staleTime: 0,
21
- gcTime: 0,
11
+ export type FetchWorkflowsProps<TData = Workflow[]> = FetchEntitiesProps<
12
+ Workflow,
13
+ TData,
14
+ WorkflowListResponse
15
+ > & {
16
+ /** Workspace to list. Required: without one the API reads `main`, not the account. */
17
+ workspace: string;
18
+ /** A name prefix, an id, `#tag #tag` (every tag), or `&link_uid`. */
19
+ search?: string;
22
20
  };
23
21
 
24
22
  /**
25
23
  * useFetchWorkflows
26
24
  *
27
- * Data-fetching hook built on TanStack Query's `useInfiniteQuery` to retrieve
28
- * workflows with cursor-based pagination using the legacy method (workspace as query param).
29
- *
30
- * Automatically flattens all pages into a single `Workflow[]` via `select`.
31
- *
32
- * Note: `query.data` returns a flat `Workflow[]` with all fetched items merged across pages.
33
- *
34
- * @param {string} [workspace]
35
- * Current workspace name. Sent as a query param via the legacy method, required by some API configurations.
36
- *
37
- * @param {number} [pageSize=10]
38
- * Number of workflows to fetch per page.
25
+ * Lists workflows with cursor pagination; `query.data` is every loaded page merged, or
26
+ * whatever `select` makes of it. `select` and `fetchAllPages` behave as in
27
+ * `useFetchDatastores`. This endpoint takes a workspace and a text `search` rather than
28
+ * filters.
39
29
  *
40
- * @param {InfiniteOptions<Workflow[]>} [queryOptions]
41
- * TanStack Query options passed through to `useInfiniteQuery`
42
- * (e.g., enabled, staleTime, gcTime, etc.).
30
+ * A missing workspace fails loudly, without a request, as in every other hook. This hook used to
31
+ * allow one, documented as listing the account's workflows; the API reads `main` instead.
43
32
  *
44
- * @returns {{ query, queryKey }}
45
- * - `query`: the full `useInfiniteQuery` result (data, isLoading, hasNextPage, fetchNextPage, etc.)
46
- * - `queryKey`: the cache key used by React Query
47
- *
48
- * @example
49
- * ```ts
50
- * const { query } = useFetchWorkflows({ workspace: "ws-1", pageSize: 20 });
51
- *
52
- * // Flat list of all fetched workflows
53
- * const workflows = query.data ?? [];
54
- * ```
33
+ * @param {FetchWorkflowsProps} props - Workspace, search, page size, `select`,
34
+ * `fetchAllPages` and TanStack `queryOptions`.
35
+ * @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.
55
36
  */
56
- export function useFetchWorkflows({ workspace, pageSize = 10, queryOptions }: FetchInfiniteWorkflowProps) {
37
+ export function useFetchWorkflows<TData = Workflow[]>({
38
+ workspace,
39
+ search,
40
+ pageSize = 10,
41
+ select,
42
+ fetchAllPages = false,
43
+ queryOptions,
44
+ }: FetchWorkflowsProps<TData>) {
57
45
  const { api } = useAxios();
58
46
 
59
- const queryKey: QueryKey = ["workflows", workspace ?? null];
60
-
61
- const mergedQueryOptions = useMemo<InfiniteOptions<Workflow[]>>(() => ({
62
- ...defaultQueryOptions,
63
- ...(queryOptions ?? {}),
64
- }), [queryOptions]);
47
+ const queryKey = buildQueryKey(["workflows", workspace, search ?? null], [], {
48
+ pageSize,
49
+ fetchAllPages,
50
+ });
65
51
 
66
- const query = useInfiniteQuery<WorkflowListResponse, Error, Workflow[], QueryKey, PageToken>({
52
+ const query = useEntityInfiniteQuery<WorkflowListResponse, "workflows", TData>({
67
53
  queryKey,
68
- initialPageParam: null,
69
- getNextPageParam: (lastPage) => lastPage.next_page_token ?? undefined,
70
-
71
- queryFn: async ({ pageParam }) => {
72
- return await listWorkflows(api, workspace, pageSize, pageParam ?? undefined);
73
- },
74
-
75
- select: (data) => data.pages.flatMap((p) => p.workflows),
76
-
77
- ...mergedQueryOptions,
54
+ itemsKey: "workflows",
55
+ fetchPage: (pageToken, signal) =>
56
+ listWorkflows(
57
+ api,
58
+ { workspace, search, pageSize, pageToken: pageToken ?? undefined },
59
+ signal,
60
+ ),
61
+ select,
62
+ fetchAllPages,
63
+ configError: workspace ? undefined : missingWorkspaceError("useFetchWorkflows"),
64
+ queryOptions,
78
65
  });
79
66
 
80
- return {
81
- query,
82
- queryKey,
83
- };
67
+ return { query, queryKey };
84
68
  }
@@ -1,62 +1,108 @@
1
+ import { useEffect, useRef } from "react";
1
2
  import { useMutation } from "@tanstack/react-query";
2
3
 
3
4
  import { useAxios } from "@/hooks/useAxios";
4
5
  import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
6
+ import { useWebSocket } from "@/contexts/webSocketContext/hooks/useWebSocket";
7
+ import {
8
+ getWorkerExecution,
9
+ getWorkflowExecution,
10
+ runWorkflow,
11
+ terminalRunStatusOf,
12
+ } from "@/api/workflow";
13
+ import { anySignal, unlessAborted } from "@/lib/abort";
14
+ import {
15
+ RUN_FAILED_MESSAGE,
16
+ WorkflowRunAbortedError,
17
+ runWorkflowToEnd,
18
+ type WorkflowWaitOptions,
19
+ } from "@/lib/workflowRun";
5
20
  import type { AnyRecord } from "@/types/anyRecord";
6
- import type { PollWorkflowExecutionOptions } from "@/api/workflow";
7
- import { runWorkflow, runWorkflowAndGetResult } from "@/api/workflow";
21
+ import type { WorkflowResult } from "@/types/workflow";
8
22
 
9
23
  type RunWorkflowProps = {
10
24
  id: string;
11
25
  workspace: string;
12
26
  parameters: AnyRecord;
13
- pollOptions?: PollWorkflowExecutionOptions;
27
+ /** How the run is waited for; see `WorkflowWaitOptions`. */
28
+ waitOptions?: WorkflowWaitOptions;
14
29
  };
15
30
 
16
- const getErrorMessage = (err: unknown, fallback: string) =>
17
- err instanceof Error && err.message ? err.message : fallback;
18
-
19
31
  /**
20
32
  * useRunWorkflow
21
33
  *
22
- * TanStack Query mutations to run a workflow. Synchronous execution (`synchronous: true`) is
23
- * intentionally not used; instead the workflow is started asynchronously and, when the result
24
- * is needed, its execution is polled until it reaches a terminal state.
34
+ * A TanStack Query mutation that starts a workflow run, waits for it to end, then reads the
35
+ * Ender's worker execution. Resolves with `{ execution, workerExecution, result }` (`result` is
36
+ * `null` when the run has no output), and fails unless the run ended `SUCCEEDED`.
37
+ *
38
+ * It waits over the websocket (see `runWorkflowToEnd`), not by polling: the backend announces
39
+ * each worker and the run's end on the app's channel, and the end itself is then read from the
40
+ * API. So it requires `WebSocketProvider`, and throws on render without it. To start a run
41
+ * without waiting, and without a websocket, use `useTriggerWorkflow`.
25
42
  *
26
- * - `runAsync`: starts the workflow and returns immediately (fire-and-forget). Use when you do
27
- * not need to wait for completion or consume the output.
28
- * - `runAndGetResult`: starts the workflow, polls until it finishes, then fetches the output of
29
- * the ender worker. Resolves with `{ execution, workerExecution, result }`; `result` is `null`
30
- * when the workflow produces no output. This is the replacement for the old synchronous flow.
43
+ * Leaving the screen stops it — listening, reads in flight and the result read — and so does
44
+ * `waitOptions.signal`. Neither is alerted: there is no screen left, or the app asked for it. Both
45
+ * fail the mutation with a `WorkflowRunAbortedError`, the signal's reason as the cause. The run itself goes
46
+ * on on the server. `waitOptions.timeoutMs` bounds only the wait for the end; the result read
47
+ * after it is a single request that the timeout does not cover. Any other failure is shown as an
48
+ * error alert through `useAppAlert`, and logged with its cause, which says why a wait timed out.
31
49
  *
32
- * Both surface the standard mutation helpers (`mutate`, `mutateAsync`, `isPending`, `data`, ...)
33
- * and report failures through `useAppAlert`.
50
+ * @returns {UseMutationResult} The mutation; `mutate({ id, workspace, parameters, waitOptions })`
51
+ * starts a run and waits for it.
34
52
  */
35
53
  export const useRunWorkflow = () => {
36
54
  const { api } = useAxios();
37
55
  const { showAlert } = useAppAlert();
56
+ const socket = useWebSocket();
57
+ const unmounted = useRef<AbortSignal | undefined>(undefined);
38
58
 
39
- const runAsync = useMutation({
40
- mutationFn: ({ id, workspace, parameters }: RunWorkflowProps) =>
41
- runWorkflow(api, id, workspace, parameters),
42
- onError: (err) => {
43
- showAlert({
44
- severity: "error",
45
- message: getErrorMessage(err, "Unable to run the workflow. Please try again."),
46
- });
47
- },
48
- });
59
+ useEffect(() => {
60
+ const controller = new AbortController();
61
+ unmounted.current = controller.signal;
62
+ return () => controller.abort();
63
+ }, []);
64
+
65
+ return useMutation({
66
+ mutationFn: async ({
67
+ id,
68
+ workspace,
69
+ parameters,
70
+ waitOptions,
71
+ }: RunWorkflowProps): Promise<WorkflowResult> => {
72
+ const { signal, dispose } = anySignal([waitOptions?.signal, unmounted.current]);
73
+ try {
74
+ const execution = await runWorkflowToEnd({
75
+ startRun: () => runWorkflow(api, id, workspace, parameters),
76
+ getExecution: (workflowExecutionId, readSignal) =>
77
+ getWorkflowExecution(api, id, workflowExecutionId, workspace, readSignal),
78
+ subscribeToEvents: socket.subscribe,
79
+ subscribeToStatus: socket.subscribeStatus,
80
+ ...waitOptions,
81
+ signal,
82
+ });
49
83
 
50
- const runAndGetResult = useMutation({
51
- mutationFn: ({ id, workspace, parameters, pollOptions }: RunWorkflowProps) =>
52
- runWorkflowAndGetResult(api, id, workspace, parameters, pollOptions),
53
- onError: (err) => {
54
- showAlert({
55
- severity: "error",
56
- message: getErrorMessage(err, "Unable to run the workflow. Please try again."),
57
- });
84
+ const runStatus = terminalRunStatusOf(execution.run_status);
85
+ if (runStatus !== "SUCCEEDED")
86
+ throw new Error(`Workflow execution ${runStatus?.toLowerCase()}`);
87
+
88
+ const enderId = execution.ender_worker_execution_id;
89
+ if (!enderId) return { execution, workerExecution: null, result: null };
90
+
91
+ const workerExecution = await unlessAborted(
92
+ getWorkerExecution(api, id, enderId, workspace, signal),
93
+ signal,
94
+ ).catch((error: unknown) => {
95
+ throw signal.aborted ? new WorkflowRunAbortedError(signal.reason) : error;
96
+ });
97
+ return { execution, workerExecution, result: workerExecution.result ?? null };
98
+ } finally {
99
+ dispose();
100
+ }
101
+ },
102
+ onError: (error) => {
103
+ if (error instanceof WorkflowRunAbortedError || unmounted.current?.aborted) return;
104
+ console.error("Workflow run failed:", error);
105
+ showAlert({ severity: "error", message: error.message || RUN_FAILED_MESSAGE });
58
106
  },
59
107
  });
60
-
61
- return { runAsync, runAndGetResult };
62
108
  };
@@ -0,0 +1,36 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+
3
+ import { useAxios } from "@/hooks/useAxios";
4
+ import { useAppAlert } from "@/contexts/appAlertContext/useAppAlert";
5
+ import { runWorkflow } from "@/api/workflow";
6
+ import { RUN_FAILED_MESSAGE } from "@/lib/workflowRun";
7
+ import type { AnyRecord } from "@/types/anyRecord";
8
+
9
+ type TriggerWorkflowProps = {
10
+ id: string;
11
+ workspace: string;
12
+ parameters: AnyRecord;
13
+ };
14
+
15
+ /**
16
+ * useTriggerWorkflow
17
+ *
18
+ * A TanStack Query mutation that starts a workflow run and resolves with the execution it started,
19
+ * still `RUNNING`. Fire-and-forget, for when nothing waits for the output; it needs no websocket.
20
+ * To wait for the run and read its result, use `useRunWorkflow`.
21
+ *
22
+ * A failure is shown as an error alert through `useAppAlert`.
23
+ *
24
+ * @returns {UseMutationResult} The mutation; `mutate({ id, workspace, parameters })` starts a run.
25
+ */
26
+ export const useTriggerWorkflow = () => {
27
+ const { api } = useAxios();
28
+ const { showAlert } = useAppAlert();
29
+
30
+ return useMutation({
31
+ mutationFn: ({ id, workspace, parameters }: TriggerWorkflowProps) =>
32
+ runWorkflow(api, id, workspace, parameters),
33
+ onError: (error) =>
34
+ showAlert({ severity: "error", message: error.message || RUN_FAILED_MESSAGE }),
35
+ });
36
+ };
@@ -1,78 +1,45 @@
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";
7
- import type { Workspace } from "@/types/workspace";
2
+ import { useEntityQuery } from "@/hooks/useEntityQuery";
8
3
  import { getWorkspace } from "@/api/workspace";
9
- import type { EntityQueryOptions } from "@/types/entityQuery";
4
+ import type { Workspace } from "@/types/workspace";
5
+ import type { FetchEntityProps } from "@/types/entityQuery";
10
6
 
11
- export type FetchWorkspaceProps<TData = Workspace, TSelected = TData> = {
7
+ export type FetchWorkspaceProps<TData = Workspace, TSelected = TData> = FetchEntityProps<
8
+ TData,
9
+ TSelected
10
+ > & {
12
11
  name: string;
13
- queryOptions?: EntityQueryOptions<TData, TSelected>;
14
- };
15
-
16
- const defaultQueryOptions: EntityQueryOptions<Workspace> = {
17
- refetchOnMount: "always",
18
- staleTime: 0,
19
- gcTime: 0,
20
12
  };
21
13
 
22
14
  /**
23
15
  * useFetchWorkspace
24
16
  *
25
- * Data-fetching hook built on TanStack Query to retrieve a single workspace by name.
26
- *
27
- * It also:
28
- * - builds a stable React Query `queryKey` that can be reused by mutation hooks for cache invalidation
29
- * - triggers an error alert via `useAppAlert` whenever `query.error` is present
17
+ * Fetches one workspace by name; `data` is the workspace, or whatever `select` makes of it.
30
18
  *
31
- * Parameters (FetchWorkspaceProps):
32
- * @param {string} name
33
- * Workspace name (required).
19
+ * A workspace is identified by its name — the API's `GET /workspaces/:id` takes the name, its
20
+ * UID — so `name` is this hook's id, and like the other hooks' id it usually comes from a
21
+ * selection the user has not made yet: while it is empty the hook stays idle, rather than fail
22
+ * as a misconfigured app. A failure is shown as an error alert.
34
23
  *
35
- * @param queryOptions
36
- * TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
37
- *
38
- * Returns:
39
- * @returns {object}
40
- * TanStack Query's `query` object extended with:
41
- * - `queryKey`: the cache key used by React Query
42
- *
43
- * Example:
44
- * ```ts
45
- * const { data, isLoading } = useFetchWorkspace({ name: "main" });
46
- * // data -> Workspace
47
- * ```
24
+ * @param {FetchWorkspaceProps} props - `name`, `select` and TanStack `queryOptions`.
25
+ * @returns {object} The `useQuery` result, plus `queryKey`.
48
26
  */
49
- export const useFetchWorkspace = ({ name, queryOptions = defaultQueryOptions }: FetchWorkspaceProps) => {
50
-
27
+ export const useFetchWorkspace = <TSelected = Workspace>({
28
+ name,
29
+ select,
30
+ queryOptions,
31
+ }: FetchWorkspaceProps<Workspace, TSelected>) => {
51
32
  const { api } = useAxios();
52
- const { showAlert } = useAppAlert();
53
33
 
54
34
  const queryKey = ["workspace", name];
55
35
 
56
- const query = useQuery<Workspace>({
36
+ const query = useEntityQuery<Workspace, TSelected>({
57
37
  queryKey,
58
- queryFn: async () => {
59
- const workspace = await getWorkspace(api, name);
60
- return workspace;
61
- },
62
- ...queryOptions ?? {}
38
+ fetchEntity: (signal) => getWorkspace(api, name, signal),
39
+ select,
40
+ enabled: Boolean(name),
41
+ queryOptions,
63
42
  });
64
43
 
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
- };
44
+ return { ...query, queryKey };
78
45
  };