@everysk/apps-sdk 0.2.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 +298 -12
  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 +1 -1
  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":"provider.js","names":[],"sources":["../../../src/contexts/webSocketContext/provider.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport { getWebsocketsConfig } from \"@/api/websocketsConfig\";\nimport { useAxios } from \"@/hooks/useAxios\";\nimport { useAppAlert } from \"@/contexts/appAlertContext/useAppAlert\";\nimport { WebSocketContext } from \".\";\nimport { WebSocketHandler } from \"./handler\";\nimport type { WebSocketContextType, WebSocketNotification, WebSocketProviderProps, WebSocketStatus } from \"./types\";\n\n/**\n * WebSocketProvider\n *\n * React context provider that exposes a receive-only pub/sub API backed by Socket.IO.\n *\n * What this provider does:\n * - Fetches `/api/websockets_config` once on mount to get the connection URL, channel id,\n * and session uid. Socket.IO handles reconnection internally — the config is not re-fetched.\n * - Opens a `WebSocketHandler` instance that connects and joins the per-user channel.\n * - Exposes `subscribe`, `lastMessage`, and `status` via `WebSocketContext`.\n *\n * Why the pending buffer exists (`pendingRef`):\n * - The handler is created asynchronously (after the config fetch resolves).\n * - Consumers that call `subscribe` before the handler is ready have their callbacks buffered\n * and registered once the handler initializes, ensuring no early subscriptions are lost.\n *\n * Subscribe buffering behavior:\n * - If `subscribe(fn)` is called before the handler exists, `fn` is stored with a `null` placeholder.\n * - Once the handler is ready, all pending callbacks are registered and their unsubscribe functions\n * stored back into the map.\n * - The returned cleanup always works: it calls the real unsubscribe if available, or removes\n * the entry from the pending map.\n *\n * Usage:\n * ```tsx\n * <WebSocketProvider>\n * <YourPage />\n * </WebSocketProvider>\n * ```\n *\n * Context value (WebSocketContextType):\n * @returns {object}\n * - `subscribe(fn)`: register a listener; returns an unsubscribe function.\n * - `lastMessage`: the most recently received notification (or null).\n * - `status`: current connection status (\"connecting\" | \"connected\" | \"error\").\n */\nexport const WebSocketProvider = ({ children }: WebSocketProviderProps) => {\n const { api } = useAxios();\n const { showAlert } = useAppAlert();\n\n // Refs keep the latest values accessible inside the mount-only effect without\n // making it re-run when api or showAlert change.\n const apiRef = useRef(api);\n const showAlertRef = useRef(showAlert);\n useEffect(() => { apiRef.current = api; });\n useEffect(() => { showAlertRef.current = showAlert; });\n\n const handlerRef = useRef<WebSocketHandler | null>(null);\n const unsubscribeProviderRef = useRef<(() => void) | null>(null);\n const [lastMessage, setLastMessage] = useState<WebSocketNotification | null>(null);\n const [status, setStatus] = useState<WebSocketStatus>(\"idle\");\n\n const pendingRef = useRef(new Map<(m: WebSocketNotification) => void, (() => void) | null>());\n\n useEffect(() => {\n let cancelled = false;\n const pending = pendingRef.current;\n\n getWebsocketsConfig(apiRef.current)\n .then((config) => {\n if (cancelled) return;\n\n setStatus(\"connecting\");\n const handler = new WebSocketHandler({\n ...config,\n onStatusChange: (s) => setStatus(s),\n });\n handlerRef.current = handler;\n\n unsubscribeProviderRef.current = handler.listen((message) => setLastMessage(message));\n\n for (const [fn, unsub] of pending.entries()) {\n if (!unsub) {\n const realUnsub = handler.listen(fn);\n pending.set(fn, realUnsub);\n }\n }\n })\n .catch((error) => {\n if (cancelled) return;\n console.error(\"Failed to initialize WebSocket connection:\", error);\n setStatus(\"error\");\n showAlertRef.current({ message: \"Real-time notifications are unavailable. Please refresh the page.\", severity: \"error\" });\n });\n\n return () => {\n cancelled = true;\n unsubscribeProviderRef.current?.();\n unsubscribeProviderRef.current = null;\n handlerRef.current?.close();\n handlerRef.current = null;\n pending.clear();\n };\n }, []); // mount-only — Socket.IO handles reconnection; no re-init needed when api changes\n\n const subscribe = useCallback((fn: (m: WebSocketNotification) => void) => {\n if (handlerRef.current) {\n return handlerRef.current.listen(fn);\n }\n\n pendingRef.current.set(fn, null);\n\n return () => {\n const maybeUnsub = pendingRef.current.get(fn);\n if (maybeUnsub) maybeUnsub();\n pendingRef.current.delete(fn);\n };\n }, []);\n\n const value: WebSocketContextType = useMemo(\n () => ({ subscribe, lastMessage, status }),\n [subscribe, lastMessage, status]\n );\n\n return <WebSocketContext.Provider value={value}>{children}</WebSocketContext.Provider>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,qBAAqB,EAAE,eAAuC;CACvE,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,EAAE,cAAc,YAAY;CAIlC,MAAM,SAAS,OAAO,GAAG;CACzB,MAAM,eAAe,OAAO,SAAS;CACrC,gBAAgB;EAAE,OAAO,UAAU;CAAK,CAAC;CACzC,gBAAgB;EAAE,aAAa,UAAU;CAAW,CAAC;CAErD,MAAM,aAAa,OAAgC,IAAI;CACvD,MAAM,yBAAyB,OAA4B,IAAI;CAC/D,MAAM,CAAC,aAAa,kBAAkB,SAAuC,IAAI;CACjF,MAAM,CAAC,QAAQ,aAAa,SAA0B,MAAM;CAE5D,MAAM,aAAa,uBAAO,IAAI,IAA6D,CAAC;CAE5F,gBAAgB;EACZ,IAAI,YAAY;EAChB,MAAM,UAAU,WAAW;EAE3B,oBAAoB,OAAO,OAAO,CAAC,CAC9B,MAAM,WAAW;GACd,IAAI,WAAW;GAEf,UAAU,YAAY;GACtB,MAAM,UAAU,IAAI,iBAAiB;IACjC,GAAG;IACH,iBAAiB,MAAM,UAAU,CAAC;GACtC,CAAC;GACD,WAAW,UAAU;GAErB,uBAAuB,UAAU,QAAQ,QAAQ,YAAY,eAAe,OAAO,CAAC;GAEpF,KAAK,MAAM,CAAC,IAAI,UAAU,QAAQ,QAAQ,GACtC,IAAI,CAAC,OAAO;IACR,MAAM,YAAY,QAAQ,OAAO,EAAE;IACnC,QAAQ,IAAI,IAAI,SAAS;GAC7B;EAER,CAAC,CAAC,CACD,OAAO,UAAU;GACd,IAAI,WAAW;GACf,QAAQ,MAAM,8CAA8C,KAAK;GACjE,UAAU,OAAO;GACjB,aAAa,QAAQ;IAAE,SAAS;IAAqE,UAAU;GAAQ,CAAC;EAC5H,CAAC;EAEL,aAAa;GACT,YAAY;GACZ,uBAAuB,UAAU;GACjC,uBAAuB,UAAU;GACjC,WAAW,SAAS,MAAM;GAC1B,WAAW,UAAU;GACrB,QAAQ,MAAM;EAClB;CACJ,GAAG,CAAC,CAAC;CAEL,MAAM,YAAY,aAAa,OAA2C;EACtE,IAAI,WAAW,SACX,OAAO,WAAW,QAAQ,OAAO,EAAE;EAGvC,WAAW,QAAQ,IAAI,IAAI,IAAI;EAE/B,aAAa;GACT,MAAM,aAAa,WAAW,QAAQ,IAAI,EAAE;GAC5C,IAAI,YAAY,WAAW;GAC3B,WAAW,QAAQ,OAAO,EAAE;EAChC;CACJ,GAAG,CAAC,CAAC;CAEL,MAAM,QAA8B,eACzB;EAAE;EAAW;EAAa;CAAO,IACxC;EAAC;EAAW;EAAa;CAAM,CACnC;CAEA,OAAO,oBAAC,iBAAiB,UAAlB;EAAkC;EAAQ;CAAoC,CAAA;AACzF"}
1
+ {"version":3,"file":"provider.js","names":[],"sources":["../../../src/contexts/webSocketContext/provider.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport { getWebsocketsConfig } from \"@/api/websocketsConfig\";\nimport { useAxios } from \"@/hooks/useAxios\";\nimport { useAppAlert } from \"@/contexts/appAlertContext/useAppAlert\";\nimport { WebSocketContext } from \".\";\nimport { WebSocketHandler } from \"./handler\";\nimport type {\n WebSocketContextType,\n WebSocketNotification,\n WebSocketProviderProps,\n WebSocketStatus,\n} from \"./types\";\n\n/**\n * Calls a status listener, logging and skipping one that throws, as notification listeners are,\n * so it cannot keep the others from hearing the change.\n */\nconst tellStatus = (listener: (status: WebSocketStatus) => void, status: WebSocketStatus) => {\n try {\n listener(status);\n } catch (error) {\n console.error(\"WebSocket status listener threw:\", error);\n }\n};\n\n/**\n * WebSocketProvider\n *\n * React context provider that exposes a receive-only pub/sub API backed by Socket.IO.\n *\n * What this provider does:\n * - Fetches `/api/websockets_config` once on mount to get the connection URL, channel id,\n * and session uid. Socket.IO handles reconnection internally — the config is not re-fetched,\n * and the effect that does it runs once (`changeStatus`, its only dependency, is stable).\n * - Opens a `WebSocketHandler` instance that connects and joins the per-user channel.\n * - Exposes `subscribe`, `subscribeStatus`, `lastMessage`, and `status` via `WebSocketContext`.\n *\n * Why the pending buffer exists (`pendingRef`):\n * - The handler is created asynchronously (after the config fetch resolves).\n * - Consumers that call `subscribe` before the handler is ready have their callbacks buffered\n * and registered once the handler initializes, ensuring no early subscriptions are lost.\n *\n * Subscribe buffering behavior:\n * - If `subscribe(fn)` is called before the handler exists, `fn` is stored with a `null` placeholder.\n * - Once the handler is ready, all pending callbacks are registered and their unsubscribe functions\n * stored back into the map.\n * - The returned cleanup always works: it calls the real unsubscribe if available, or removes\n * the entry from the pending map.\n *\n * Usage:\n * ```tsx\n * <WebSocketProvider>\n * <YourPage />\n * </WebSocketProvider>\n * ```\n *\n * Context value (WebSocketContextType):\n * @returns {object}\n * - `subscribe(fn)`: register a listener; returns an unsubscribe function.\n * - `subscribeStatus(fn)`: hear the current status at once, then every status the socket\n * reports, repeats included; returns an unsubscribe function.\n * - `lastMessage`: the most recently received notification (or null).\n * - `status`: current connection status (\"idle\" | \"connecting\" | \"connected\" | \"error\").\n */\nexport const WebSocketProvider = ({ children }: WebSocketProviderProps) => {\n const { api } = useAxios();\n const { showAlert } = useAppAlert();\n\n // Refs keep the latest values accessible inside the mount-only effect without\n // making it re-run when api or showAlert change.\n const apiRef = useRef(api);\n const showAlertRef = useRef(showAlert);\n useEffect(() => {\n apiRef.current = api;\n });\n useEffect(() => {\n showAlertRef.current = showAlert;\n });\n\n const handlerRef = useRef<WebSocketHandler | null>(null);\n const unsubscribeProviderRef = useRef<(() => void) | null>(null);\n const [lastMessage, setLastMessage] = useState<WebSocketNotification | null>(null);\n const [status, setStatus] = useState<WebSocketStatus>(\"idle\");\n const statusListenersRef = useRef(new Set<(status: WebSocketStatus) => void>());\n const currentStatusRef = useRef<WebSocketStatus>(\"idle\");\n\n /**\n * Sets `status` and tells the status listeners, so both see the same sequence. The current\n * status is also kept in a ref, so a new listener is told it at once rather than from React\n * state, which lags a change until the next render.\n */\n const changeStatus = useCallback((next: WebSocketStatus) => {\n currentStatusRef.current = next;\n setStatus(next);\n statusListenersRef.current.forEach((listener) => tellStatus(listener, next));\n }, []);\n\n const pendingRef = useRef(new Map<(m: WebSocketNotification) => void, (() => void) | null>());\n\n useEffect(() => {\n let cancelled = false;\n const pending = pendingRef.current;\n\n getWebsocketsConfig(apiRef.current)\n .then((config) => {\n if (cancelled) return;\n\n changeStatus(\"connecting\");\n const handler = new WebSocketHandler({\n ...config,\n onStatusChange: changeStatus,\n });\n handlerRef.current = handler;\n\n unsubscribeProviderRef.current = handler.listen((message) =>\n setLastMessage(message),\n );\n\n for (const [fn, unsub] of pending.entries()) {\n if (!unsub) {\n const realUnsub = handler.listen(fn);\n pending.set(fn, realUnsub);\n }\n }\n })\n .catch((error) => {\n if (cancelled) return;\n console.error(\"Failed to initialize WebSocket connection:\", error);\n changeStatus(\"error\");\n showAlertRef.current({\n message: \"Real-time notifications are unavailable. Please refresh the page.\",\n severity: \"error\",\n });\n });\n\n return () => {\n cancelled = true;\n unsubscribeProviderRef.current?.();\n unsubscribeProviderRef.current = null;\n handlerRef.current?.close();\n handlerRef.current = null;\n pending.clear();\n };\n }, [changeStatus]);\n\n const subscribe = useCallback((fn: (m: WebSocketNotification) => void) => {\n if (handlerRef.current) {\n return handlerRef.current.listen(fn);\n }\n\n pendingRef.current.set(fn, null);\n\n return () => {\n const maybeUnsub = pendingRef.current.get(fn);\n if (maybeUnsub) maybeUnsub();\n pendingRef.current.delete(fn);\n };\n }, []);\n\n const subscribeStatus = useCallback((listener: (status: WebSocketStatus) => void) => {\n statusListenersRef.current.add(listener);\n tellStatus(listener, currentStatusRef.current);\n return () => {\n statusListenersRef.current.delete(listener);\n };\n }, []);\n\n const value: WebSocketContextType = useMemo(\n () => ({ subscribe, subscribeStatus, lastMessage, status }),\n [subscribe, subscribeStatus, lastMessage, status],\n );\n\n return <WebSocketContext.Provider value={value}>{children}</WebSocketContext.Provider>;\n};\n"],"mappings":";;;;;;;;;;;;AAkBA,IAAM,cAAc,UAA6C,WAA4B;CACzF,IAAI;EACA,SAAS,MAAM;CACnB,SAAS,OAAO;EACZ,QAAQ,MAAM,oCAAoC,KAAK;CAC3D;AACJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,qBAAqB,EAAE,eAAuC;CACvE,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,EAAE,cAAc,YAAY;CAIlC,MAAM,SAAS,OAAO,GAAG;CACzB,MAAM,eAAe,OAAO,SAAS;CACrC,gBAAgB;EACZ,OAAO,UAAU;CACrB,CAAC;CACD,gBAAgB;EACZ,aAAa,UAAU;CAC3B,CAAC;CAED,MAAM,aAAa,OAAgC,IAAI;CACvD,MAAM,yBAAyB,OAA4B,IAAI;CAC/D,MAAM,CAAC,aAAa,kBAAkB,SAAuC,IAAI;CACjF,MAAM,CAAC,QAAQ,aAAa,SAA0B,MAAM;CAC5D,MAAM,qBAAqB,uBAAO,IAAI,IAAuC,CAAC;CAC9E,MAAM,mBAAmB,OAAwB,MAAM;;;;;;CAOvD,MAAM,eAAe,aAAa,SAA0B;EACxD,iBAAiB,UAAU;EAC3B,UAAU,IAAI;EACd,mBAAmB,QAAQ,SAAS,aAAa,WAAW,UAAU,IAAI,CAAC;CAC/E,GAAG,CAAC,CAAC;CAEL,MAAM,aAAa,uBAAO,IAAI,IAA6D,CAAC;CAE5F,gBAAgB;EACZ,IAAI,YAAY;EAChB,MAAM,UAAU,WAAW;EAE3B,oBAAoB,OAAO,OAAO,CAAC,CAC9B,MAAM,WAAW;GACd,IAAI,WAAW;GAEf,aAAa,YAAY;GACzB,MAAM,UAAU,IAAI,iBAAiB;IACjC,GAAG;IACH,gBAAgB;GACpB,CAAC;GACD,WAAW,UAAU;GAErB,uBAAuB,UAAU,QAAQ,QAAQ,YAC7C,eAAe,OAAO,CAC1B;GAEA,KAAK,MAAM,CAAC,IAAI,UAAU,QAAQ,QAAQ,GACtC,IAAI,CAAC,OAAO;IACR,MAAM,YAAY,QAAQ,OAAO,EAAE;IACnC,QAAQ,IAAI,IAAI,SAAS;GAC7B;EAER,CAAC,CAAC,CACD,OAAO,UAAU;GACd,IAAI,WAAW;GACf,QAAQ,MAAM,8CAA8C,KAAK;GACjE,aAAa,OAAO;GACpB,aAAa,QAAQ;IACjB,SAAS;IACT,UAAU;GACd,CAAC;EACL,CAAC;EAEL,aAAa;GACT,YAAY;GACZ,uBAAuB,UAAU;GACjC,uBAAuB,UAAU;GACjC,WAAW,SAAS,MAAM;GAC1B,WAAW,UAAU;GACrB,QAAQ,MAAM;EAClB;CACJ,GAAG,CAAC,YAAY,CAAC;CAEjB,MAAM,YAAY,aAAa,OAA2C;EACtE,IAAI,WAAW,SACX,OAAO,WAAW,QAAQ,OAAO,EAAE;EAGvC,WAAW,QAAQ,IAAI,IAAI,IAAI;EAE/B,aAAa;GACT,MAAM,aAAa,WAAW,QAAQ,IAAI,EAAE;GAC5C,IAAI,YAAY,WAAW;GAC3B,WAAW,QAAQ,OAAO,EAAE;EAChC;CACJ,GAAG,CAAC,CAAC;CAEL,MAAM,kBAAkB,aAAa,aAAgD;EACjF,mBAAmB,QAAQ,IAAI,QAAQ;EACvC,WAAW,UAAU,iBAAiB,OAAO;EAC7C,aAAa;GACT,mBAAmB,QAAQ,OAAO,QAAQ;EAC9C;CACJ,GAAG,CAAC,CAAC;CAEL,MAAM,QAA8B,eACzB;EAAE;EAAW;EAAiB;EAAa;CAAO,IACzD;EAAC;EAAW;EAAiB;EAAa;CAAM,CACpD;CAEA,OAAO,oBAAC,iBAAiB,UAAlB;EAAkC;EAAQ;CAAoC,CAAA;AACzF"}
@@ -1,9 +1,4 @@
1
1
  import type { ReactNode } from "react";
2
- export type WebsocketsConfig = {
3
- appConnectionURL: string;
4
- appChannelID: string;
5
- everyskUID: string;
6
- };
7
2
  export type WebSocketStatus = "idle" | "connecting" | "connected" | "error";
8
3
  export type AppNotificationPayload = {
9
4
  [key: string]: unknown;
@@ -32,6 +27,13 @@ export type AppNotification = WebSocketNotification & {
32
27
  };
33
28
  export type WebSocketContextType = {
34
29
  subscribe: (listener: (msg: WebSocketNotification) => void) => () => void;
30
+ /**
31
+ * Calls `listener` with the current status at once, then on every status the socket reports,
32
+ * repeats included; returns the unsubscribe. For code that waits on the socket outside React,
33
+ * where `status` cannot be watched: a reconnect is when it must catch up on what was
34
+ * published in between, which the server does not replay.
35
+ */
36
+ subscribeStatus: (listener: (status: WebSocketStatus) => void) => () => void;
35
37
  lastMessage: WebSocketNotification | null;
36
38
  status: WebSocketStatus;
37
39
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/contexts/webSocketContext/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,gBAAgB,GAAG;IAC3B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,OAAO,CAAC;AAE5E,MAAM,MAAM,sBAAsB,GAAG;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,qBAAqB,GAAG;IAClD,UAAU,EAAE,uBAAuB,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,sBAAsB,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IAC/B,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,qBAAqB,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IAC1E,WAAW,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAC1C,MAAM,EAAE,eAAe,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IAIjC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/contexts/webSocketContext/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,OAAO,CAAC;AAE5E,MAAM,MAAM,sBAAsB,GAAG;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,qBAAqB,GAAG;IAClD,UAAU,EAAE,uBAAuB,CAAC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,sBAAsB,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IAC/B,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,qBAAqB,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IAC1E;;;;;OAKG;IACH,eAAe,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IAC7E,WAAW,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAC1C,MAAM,EAAE,eAAe,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IAIjC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACxB,CAAC"}
@@ -3,4 +3,6 @@ export * from "../types/file.d.ts";
3
3
  export * from "../hooks/file/useFetchFile.js";
4
4
  export * from "../hooks/file/useFetchFiles.js";
5
5
  export * from "../hooks/file/useFileMutations.js";
6
+ export * from "../lib/file.js";
7
+ export type { FileDataProps } from "../hooks/file/fileData.js";
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAQA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/file/index.ts"],"names":[],"mappings":"AAQA,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC;AAC3B,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
@@ -66,7 +66,7 @@ type UseDatastoreMutationsProps = {
66
66
  * Returns an object with the three TanStack Query mutation results:
67
67
  * - `create`: UseMutationResult<Datastore, Error, CreateDatastoreProps, unknown>
68
68
  * - `update`: UseMutationResult<Datastore, Error, UpdateDatastoreProps, unknown>
69
- * - `remove`: UseMutationResult<Datastore, Error, DeleteDatastoreProps, unknown>
69
+ * - `remove`: UseMutationResult<DeletedEntity, Error, DeleteDatastoreProps, unknown>
70
70
  *
71
71
  * Each mutation includes standard TanStack Query helpers:
72
72
  * - `mutate(variables, options?)`
@@ -143,9 +143,9 @@ type UseDatastoreMutationsProps = {
143
143
  * ```
144
144
  */
145
145
  export declare const useDatastoreMutations: ({ queryKey }: UseDatastoreMutationsProps) => {
146
- create: import("@tanstack/react-query").UseMutationResult<Datastore, unknown, CreateDatastoreProps, unknown>;
147
- update: import("@tanstack/react-query").UseMutationResult<Datastore, unknown, UpdateDatastoreProps, unknown>;
148
- remove: import("@tanstack/react-query").UseMutationResult<import("../..").DeleteEntityDefaultResponse[], unknown, DeleteDatastoreProps, unknown>;
146
+ create: import("@tanstack/react-query").UseMutationResult<Datastore, Error, CreateDatastoreProps, unknown>;
147
+ update: import("@tanstack/react-query").UseMutationResult<Datastore, Error, UpdateDatastoreProps, unknown>;
148
+ remove: import("@tanstack/react-query").UseMutationResult<import("../..").DeletedEntity, Error, DeleteDatastoreProps, unknown>;
149
149
  };
150
150
  export {};
151
151
  //# sourceMappingURL=useDatastoreMutations.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDatastoreMutations.d.ts","sourceRoot":"","sources":["../../../src/hooks/datastore/useDatastoreMutations.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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgIG;AAEH,eAAO,MAAM,qBAAqB,GAAI,cAAc,0BAA0B;;;;CA8D7E,CAAC"}
1
+ {"version":3,"file":"useDatastoreMutations.d.ts","sourceRoot":"","sources":["../../../src/hooks/datastore/useDatastoreMutations.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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgIG;AAEH,eAAO,MAAM,qBAAqB,GAAI,cAAc,0BAA0B;;;;CA0B7E,CAAC"}
@@ -1,9 +1,7 @@
1
- import { useAppAlert } from "../../contexts/appAlertContext/useAppAlert.js";
2
1
  import { useAxios } from "../useAxios.js";
2
+ import { useEntityMutation } from "../useEntityMutation.js";
3
3
  import { createDatastore, deleteDatastore, updateDatastore } from "../../api/datastore.js";
4
- import { useMutation, useQueryClient } from "@tanstack/react-query";
5
4
  //#region src/hooks/datastore/useDatastoreMutations.ts
6
- var getErrorMessage = (err, fallback) => err instanceof Error && err.message ? err.message : fallback;
7
5
  /**
8
6
  * useDatastoreMutations
9
7
  *
@@ -57,7 +55,7 @@ var getErrorMessage = (err, fallback) => err instanceof Error && err.message ? e
57
55
  * Returns an object with the three TanStack Query mutation results:
58
56
  * - `create`: UseMutationResult<Datastore, Error, CreateDatastoreProps, unknown>
59
57
  * - `update`: UseMutationResult<Datastore, Error, UpdateDatastoreProps, unknown>
60
- * - `remove`: UseMutationResult<Datastore, Error, DeleteDatastoreProps, unknown>
58
+ * - `remove`: UseMutationResult<DeletedEntity, Error, DeleteDatastoreProps, unknown>
61
59
  *
62
60
  * Each mutation includes standard TanStack Query helpers:
63
61
  * - `mutate(variables, options?)`
@@ -135,60 +133,24 @@ var getErrorMessage = (err, fallback) => err instanceof Error && err.message ? e
135
133
  */
136
134
  var useDatastoreMutations = ({ queryKey }) => {
137
135
  const { api } = useAxios();
138
- const { showAlert } = useAppAlert();
139
- const queryClient = useQueryClient();
140
- const invalidate = async () => {
141
- if (!queryKey?.length) return;
142
- await queryClient.invalidateQueries({ queryKey });
143
- };
144
136
  return {
145
- create: useMutation({
146
- mutationFn: async ({ data }) => createDatastore(api, data),
147
- onSuccess: async () => {
148
- await invalidate();
149
- showAlert({
150
- severity: "success",
151
- message: "Datastore created successfully."
152
- });
153
- },
154
- onError: (err) => {
155
- showAlert({
156
- severity: "error",
157
- message: getErrorMessage(err, "Unable to create the datastore. Please try again.")
158
- });
159
- }
137
+ create: useEntityMutation({
138
+ mutationFn: ({ data }) => createDatastore(api, data),
139
+ queryKey,
140
+ successMessage: "Datastore created successfully.",
141
+ errorMessage: "Unable to create the datastore. Please try again."
160
142
  }),
161
- update: useMutation({
162
- mutationFn: async ({ id, data }) => updateDatastore(api, id, data),
163
- onSuccess: async () => {
164
- await invalidate();
165
- showAlert({
166
- severity: "success",
167
- message: "Datastore updated successfully."
168
- });
169
- },
170
- onError: (err) => {
171
- showAlert({
172
- severity: "error",
173
- message: getErrorMessage(err, "Unable to update the datastore. Please try again.")
174
- });
175
- }
143
+ update: useEntityMutation({
144
+ mutationFn: ({ id, data }) => updateDatastore(api, id, data),
145
+ queryKey,
146
+ successMessage: "Datastore updated successfully.",
147
+ errorMessage: "Unable to update the datastore. Please try again."
176
148
  }),
177
- remove: useMutation({
178
- mutationFn: async ({ id, workspace }) => deleteDatastore(api, id, workspace),
179
- onSuccess: async () => {
180
- await invalidate();
181
- showAlert({
182
- severity: "success",
183
- message: "Datastore deleted successfully."
184
- });
185
- },
186
- onError: (err) => {
187
- showAlert({
188
- severity: "error",
189
- message: getErrorMessage(err, "Unable to delete the datastore. Please try again.")
190
- });
191
- }
149
+ remove: useEntityMutation({
150
+ mutationFn: ({ id, workspace }) => deleteDatastore(api, id, workspace),
151
+ queryKey,
152
+ successMessage: "Datastore deleted successfully.",
153
+ errorMessage: "Unable to delete the datastore. Please try again."
192
154
  })
193
155
  };
194
156
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useDatastoreMutations.js","names":[],"sources":["../../../src/hooks/datastore/useDatastoreMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient } from \"@tanstack/react-query\";\n\nimport { useAxios } from \"./../useAxios\";\nimport { useAppAlert } from \"@/contexts/appAlertContext/useAppAlert\";\nimport type { Datastore } from \"@/types/datastore\";\nimport { deleteDatastore, createDatastore, updateDatastore } from \"@/api/datastore\";\n\ntype CreateDatastoreProps = {\n data: Partial<Datastore>;\n};\n\ntype UpdateDatastoreProps = {\n id: string;\n data: Partial<Datastore>;\n};\n\ntype DeleteDatastoreProps = {\n id: string;\n workspace: string;\n};\n\ntype UseDatastoreMutationsProps = {\n queryKey?: unknown[];\n};\n\nconst getErrorMessage = (err: unknown, fallback: string) =>\n err instanceof Error && err.message ? err.message : fallback;\n\n/**\n * useDatastoreMutations\n *\n * Mutation hook built on TanStack Query to perform Datastore write operations:\n * - create a datastore (POST)\n * - update a datastore (PUT)\n * - delete a datastore (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 `useFetchDatastore`.\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 `deleteDatastore(api, id, workspace)`\n * expects it as a query param.\n *\n * Parameters (UseDatastoreMutationsProps):\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., datastore list/detail) so UI data is refreshed automatically after a write.\n *\n * Tip:\n * - If you're using `useFetchDatastore`, you can pass its returned `queryKey` directly:\n * `const fetch = useFetchDatastore(...);`\n * `useDatastoreMutations({ queryKey: fetch.queryKey });`\n *\n * Mutations:\n * - `create`:\n * - mutationFn: `createDatastore(api, data)`\n * - variables: `{ data: Partial<Datastore> }`\n * - success message: \"Datastore created successfully.\"\n * - error message: \"Unable to create the datastore. Please try again.\" (fallback)\n *\n * - `update`:\n * - mutationFn: `updateDatastore(api, id, data)`\n * - variables: `{ id: string; data: Partial<Datastore> }`\n * - success message: \"Datastore updated successfully.\"\n * - error message: \"Unable to update the datastore. Please try again.\" (fallback)\n *\n * - `remove`:\n * - mutationFn: `deleteDatastore(api, id, workspace)`\n * - variables: `{ id: string; workspace: string }`\n * - success message: \"Datastore deleted successfully.\"\n * - error message: \"Unable to delete the datastore. 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<Datastore, Error, CreateDatastoreProps, unknown>\n * - `update`: UseMutationResult<Datastore, Error, UpdateDatastoreProps, unknown>\n * - `remove`: UseMutationResult<Datastore, Error, DeleteDatastoreProps, 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 datastore list query after mutations:\n * ```ts\n * const { create, update, remove } = useDatastoreMutations({ queryKey: [\"datastore\"] });\n *\n * // Create\n * create.mutate({\n * data: {\n * name: \"My datastore\",\n * workspace: \"ws-1\",\n * data: [[\"id\", \"name\"], [\"ABEOX135\", \"Jorge\"]],\n * }\n * });\n *\n * // Update\n * update.mutate({\n * id: \"ds-123\",\n * data: {\n * name: \"Renamed datastore\",\n * data: [[\"id\", \"name\"], [\"ABEOX135\", \"Jorge\"]],\n * }\n * });\n *\n * // Delete\n * remove.mutate({\n * id: \"ds-123\",\n * workspace: \"ws-1\"\n * });\n * ```\n *\n * 2) Using async/await with `mutateAsync`:\n * ```ts\n * const { create } = useDatastoreMutations({ queryKey: [\"datastore\"] });\n *\n * await create.mutateAsync({\n * data: {\n * name: \"My datastore\",\n * workspace: \"ws-1\",\n * data: [[\"id\", \"name\"], [\"ABEOX135\", \"Jorge\"]],\n * }\n * });\n * ```\n *\n * 3) Without cache invalidation (no queryKey):\n * ```ts\n * const { update } = useDatastoreMutations({});\n *\n * update.mutate({\n * id: \"ds-123\",\n * data: { name: \"Renamed datastore\" }\n * });\n * // Mutation still runs and alerts are shown, but cached queries are not invalidated.\n * ```\n *\n * 4) Using `useFetchDatastore` queryKey for automatic invalidation:\n * ```ts\n * const fetch = useFetchDatastore({\n * id: null,\n * filters: [{ field: \"workspace\", value: \"ws-1\" }],\n * });\n *\n * const { create } = useDatastoreMutations({ queryKey: fetch.queryKey });\n *\n * await create.mutateAsync({\n * data: { name: \"My datastore\", workspace: \"ws-1\" }\n * });\n * ```\n */\n\nexport const useDatastoreMutations = ({ queryKey }: UseDatastoreMutationsProps) => {\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 }: CreateDatastoreProps) => createDatastore(api, data),\n onSuccess: async () => {\n await invalidate();\n showAlert({\n severity: \"success\",\n message: \"Datastore created successfully.\",\n });\n },\n onError: (err: unknown) => {\n showAlert({\n severity: \"error\",\n message: getErrorMessage(err, \"Unable to create the datastore. Please try again.\"),\n });\n },\n });\n\n const update = useMutation({\n mutationFn: async ({ id, data }: UpdateDatastoreProps) => updateDatastore(api, id, data),\n onSuccess: async () => {\n await invalidate();\n showAlert({\n severity: \"success\",\n message: \"Datastore updated successfully.\",\n });\n },\n onError: (err: unknown) => {\n showAlert({\n severity: \"error\",\n message: getErrorMessage(err, \"Unable to update the datastore. Please try again.\"),\n });\n },\n });\n\n const remove = useMutation({\n mutationFn: async ({ id, workspace }: DeleteDatastoreProps) => deleteDatastore(api, id, workspace),\n onSuccess: async () => {\n await invalidate();\n showAlert({\n severity: \"success\",\n message: \"Datastore deleted successfully.\",\n });\n },\n onError: (err: unknown) => {\n showAlert({\n severity: \"error\",\n message: getErrorMessage(err, \"Unable to delete the datastore. Please try again.\"),\n });\n },\n });\n\n return { create, update, remove };\n};\n"],"mappings":";;;;;AAyBA,IAAM,mBAAmB,KAAc,aACnC,eAAe,SAAS,IAAI,UAAU,IAAI,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoIxD,IAAa,yBAAyB,EAAE,eAA2C;CAC/E,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;CAqDA,OAAO;EAAE,QAnDM,YAAY;GACvB,YAAY,OAAO,EAAE,WAAiC,gBAAgB,KAAK,IAAI;GAC/E,WAAW,YAAY;IACnB,MAAM,WAAW;IACjB,UAAU;KACN,UAAU;KACV,SAAS;IACb,CAAC;GACL;GACA,UAAU,QAAiB;IACvB,UAAU;KACN,UAAU;KACV,SAAS,gBAAgB,KAAK,mDAAmD;IACrF,CAAC;GACL;EACJ,CAoCS;EAAQ,QAlCF,YAAY;GACvB,YAAY,OAAO,EAAE,IAAI,WAAiC,gBAAgB,KAAK,IAAI,IAAI;GACvF,WAAW,YAAY;IACnB,MAAM,WAAW;IACjB,UAAU;KACN,UAAU;KACV,SAAS;IACb,CAAC;GACL;GACA,UAAU,QAAiB;IACvB,UAAU;KACN,UAAU;KACV,SAAS,gBAAgB,KAAK,mDAAmD;IACrF,CAAC;GACL;EACJ,CAmBiB;EAAQ,QAjBV,YAAY;GACvB,YAAY,OAAO,EAAE,IAAI,gBAAsC,gBAAgB,KAAK,IAAI,SAAS;GACjG,WAAW,YAAY;IACnB,MAAM,WAAW;IACjB,UAAU;KACN,UAAU;KACV,SAAS;IACb,CAAC;GACL;GACA,UAAU,QAAiB;IACvB,UAAU;KACN,UAAU;KACV,SAAS,gBAAgB,KAAK,mDAAmD;IACrF,CAAC;GACL;EACJ,CAEyB;CAAO;AACpC"}
1
+ {"version":3,"file":"useDatastoreMutations.js","names":[],"sources":["../../../src/hooks/datastore/useDatastoreMutations.ts"],"sourcesContent":["import { useAxios } from \"@/hooks/useAxios\";\nimport { useEntityMutation } from \"@/hooks/useEntityMutation\";\nimport type { Datastore } from \"@/types/datastore\";\nimport { deleteDatastore, createDatastore, updateDatastore } from \"@/api/datastore\";\n\ntype CreateDatastoreProps = {\n data: Partial<Datastore>;\n};\n\ntype UpdateDatastoreProps = {\n id: string;\n data: Partial<Datastore>;\n};\n\ntype DeleteDatastoreProps = {\n id: string;\n workspace: string;\n};\n\ntype UseDatastoreMutationsProps = {\n queryKey?: unknown[];\n};\n\n/**\n * useDatastoreMutations\n *\n * Mutation hook built on TanStack Query to perform Datastore write operations:\n * - create a datastore (POST)\n * - update a datastore (PUT)\n * - delete a datastore (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 `useFetchDatastore`.\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 `deleteDatastore(api, id, workspace)`\n * expects it as a query param.\n *\n * Parameters (UseDatastoreMutationsProps):\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., datastore list/detail) so UI data is refreshed automatically after a write.\n *\n * Tip:\n * - If you're using `useFetchDatastore`, you can pass its returned `queryKey` directly:\n * `const fetch = useFetchDatastore(...);`\n * `useDatastoreMutations({ queryKey: fetch.queryKey });`\n *\n * Mutations:\n * - `create`:\n * - mutationFn: `createDatastore(api, data)`\n * - variables: `{ data: Partial<Datastore> }`\n * - success message: \"Datastore created successfully.\"\n * - error message: \"Unable to create the datastore. Please try again.\" (fallback)\n *\n * - `update`:\n * - mutationFn: `updateDatastore(api, id, data)`\n * - variables: `{ id: string; data: Partial<Datastore> }`\n * - success message: \"Datastore updated successfully.\"\n * - error message: \"Unable to update the datastore. Please try again.\" (fallback)\n *\n * - `remove`:\n * - mutationFn: `deleteDatastore(api, id, workspace)`\n * - variables: `{ id: string; workspace: string }`\n * - success message: \"Datastore deleted successfully.\"\n * - error message: \"Unable to delete the datastore. 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<Datastore, Error, CreateDatastoreProps, unknown>\n * - `update`: UseMutationResult<Datastore, Error, UpdateDatastoreProps, unknown>\n * - `remove`: UseMutationResult<DeletedEntity, Error, DeleteDatastoreProps, 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 datastore list query after mutations:\n * ```ts\n * const { create, update, remove } = useDatastoreMutations({ queryKey: [\"datastore\"] });\n *\n * // Create\n * create.mutate({\n * data: {\n * name: \"My datastore\",\n * workspace: \"ws-1\",\n * data: [[\"id\", \"name\"], [\"ABEOX135\", \"Jorge\"]],\n * }\n * });\n *\n * // Update\n * update.mutate({\n * id: \"ds-123\",\n * data: {\n * name: \"Renamed datastore\",\n * data: [[\"id\", \"name\"], [\"ABEOX135\", \"Jorge\"]],\n * }\n * });\n *\n * // Delete\n * remove.mutate({\n * id: \"ds-123\",\n * workspace: \"ws-1\"\n * });\n * ```\n *\n * 2) Using async/await with `mutateAsync`:\n * ```ts\n * const { create } = useDatastoreMutations({ queryKey: [\"datastore\"] });\n *\n * await create.mutateAsync({\n * data: {\n * name: \"My datastore\",\n * workspace: \"ws-1\",\n * data: [[\"id\", \"name\"], [\"ABEOX135\", \"Jorge\"]],\n * }\n * });\n * ```\n *\n * 3) Without cache invalidation (no queryKey):\n * ```ts\n * const { update } = useDatastoreMutations({});\n *\n * update.mutate({\n * id: \"ds-123\",\n * data: { name: \"Renamed datastore\" }\n * });\n * // Mutation still runs and alerts are shown, but cached queries are not invalidated.\n * ```\n *\n * 4) Using `useFetchDatastore` queryKey for automatic invalidation:\n * ```ts\n * const fetch = useFetchDatastore({\n * id: null,\n * filters: [{ field: \"workspace\", value: \"ws-1\" }],\n * });\n *\n * const { create } = useDatastoreMutations({ queryKey: fetch.queryKey });\n *\n * await create.mutateAsync({\n * data: { name: \"My datastore\", workspace: \"ws-1\" }\n * });\n * ```\n */\n\nexport const useDatastoreMutations = ({ queryKey }: UseDatastoreMutationsProps) => {\n const { api } = useAxios();\n\n const create = useEntityMutation({\n mutationFn: ({ data }: CreateDatastoreProps) => createDatastore(api, data),\n queryKey,\n successMessage: \"Datastore created successfully.\",\n errorMessage: \"Unable to create the datastore. Please try again.\",\n });\n\n const update = useEntityMutation({\n mutationFn: ({ id, data }: UpdateDatastoreProps) => updateDatastore(api, id, data),\n queryKey,\n successMessage: \"Datastore updated successfully.\",\n errorMessage: \"Unable to update the datastore. Please try again.\",\n });\n\n const remove = useEntityMutation({\n mutationFn: ({ id, workspace }: DeleteDatastoreProps) =>\n deleteDatastore(api, id, workspace),\n queryKey,\n successMessage: \"Datastore deleted successfully.\",\n errorMessage: \"Unable to delete the datastore. Please try again.\",\n });\n\n return { create, update, remove };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyJA,IAAa,yBAAyB,EAAE,eAA2C;CAC/E,MAAM,EAAE,QAAQ,SAAS;CAwBzB,OAAO;EAAE,QAtBM,kBAAkB;GAC7B,aAAa,EAAE,WAAiC,gBAAgB,KAAK,IAAI;GACzE;GACA,gBAAgB;GAChB,cAAc;EAClB,CAiBS;EAAQ,QAfF,kBAAkB;GAC7B,aAAa,EAAE,IAAI,WAAiC,gBAAgB,KAAK,IAAI,IAAI;GACjF;GACA,gBAAgB;GAChB,cAAc;EAClB,CAUiB;EAAQ,QARV,kBAAkB;GAC7B,aAAa,EAAE,IAAI,gBACf,gBAAgB,KAAK,IAAI,SAAS;GACtC;GACA,gBAAgB;GAChB,cAAc;EAClB,CAEyB;CAAO;AACpC"}
@@ -1,47 +1,36 @@
1
- import type { DatastoreWithRows } from "../../types/datastore.d.ts";
2
- import type { FetchEntityParams } from "../../types/entityQuery.d.ts";
3
- export type FetchDatastoreProps = FetchEntityParams<DatastoreWithRows>;
1
+ import type { ParsedDatastore } from "../../types/datastore.d.ts";
2
+ import type { DatastoreDataFormat } from "../../types/datastoreDataFormat.d.ts";
3
+ import type { FetchEntityByIdProps } from "../../types/entityQuery.d.ts";
4
+ export type FetchDatastoreProps<F extends DatastoreDataFormat = "object", TSelected = ParsedDatastore<F>> = FetchEntityByIdProps<ParsedDatastore<F>, TSelected> & {
5
+ /**
6
+ * Tabular datastores only: `"object"` (default) turns the matrix into one object per row;
7
+ * `"matrix"` leaves the matrix, header row included. A JSON datastore's `data` is unchanged either way.
8
+ */
9
+ dataFormat?: F;
10
+ };
4
11
  /**
5
12
  * useFetchDatastore
6
13
  *
7
- * Data-fetching hook built on TanStack Query to retrieve a single datastore by ID.
8
- *
9
- * It also:
10
- * - triggers an error alert via `useAppAlert` whenever `query.error` is present
11
- *
12
- * Important notes:
13
- * - Returns a `DatastoreWithRows` object: the full `Datastore` shape with `data`
14
- * replaced by `AnyRecord[]` (rows transformed via `tableToObjects`).
15
- *
16
- * Parameters (FetchDatastoreProps):
17
- * @param {string} id
18
- * Datastore identifier (required).
19
- *
20
- * @param {string} workspace
21
- * Workspace the datastore belongs to (required by `getDatastore`).
14
+ * Fetches one datastore. `data` is a `ParsedDatastore` — a table's matrix converted to row
15
+ * objects with `fields`, or a JSON datastore's content untouched, told apart by `format`, the
16
+ * same shape `useFetchDatastores` returns — or whatever `select` makes of it. With
17
+ * `dataFormat: "matrix"` a tabular datastore keeps its matrix unconverted, as in `useFetchDatastores`.
22
18
  *
23
- * @param {EntityQueryOptions<DatastoreWithRows>} [queryOptions=defaultQueryOptions]
24
- * TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
19
+ * Idle while `id` is empty; fails loudly, without a request, while `workspace` is. A failure is
20
+ * shown as an error alert.
25
21
  *
26
- * Returns:
27
- * @returns {object}
28
- * TanStack Query's `query` object extended with:
29
- * - `queryKey`: the cache key used by React Query
22
+ * @param {FetchDatastoreProps} props - `id`, `workspace`, `dataFormat`, `select` and TanStack
23
+ * `queryOptions`.
24
+ * @returns {object} The `useQuery` result, plus `queryKey`.
30
25
  *
31
26
  * Example:
32
27
  * ```ts
33
- * const { data, isLoading } = useFetchDatastore({
34
- * id: "abc123",
35
- * workspace: "my-workspace",
36
- * });
37
- * // data -> DatastoreWithRows (datastore metadata + rows as AnyRecord[])
38
- * // data.name -> "my-datastore"
39
- * // data.data -> [{ datastoreId: "abc123", col1: "value", ... }]
28
+ * const { data, isLoading, queryKey } = useFetchDatastore({ id: "abc123", workspace: "ws-1" });
40
29
  * ```
41
30
  */
42
- export declare const useFetchDatastore: ({ id, workspace, queryOptions }: FetchDatastoreProps) => {
31
+ export declare const useFetchDatastore: <F extends DatastoreDataFormat = "object", TSelected = ParsedDatastore<F>>({ id, workspace, dataFormat, select, queryOptions, }: FetchDatastoreProps<F, TSelected>) => {
43
32
  queryKey: string[];
44
- data: DatastoreWithRows;
33
+ data: TSelected;
45
34
  error: Error;
46
35
  isError: true;
47
36
  isPending: false;
@@ -64,11 +53,11 @@ export declare const useFetchDatastore: ({ id, workspace, queryOptions }: FetchD
64
53
  isRefetching: boolean;
65
54
  isStale: boolean;
66
55
  isEnabled: boolean;
67
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<DatastoreWithRows, Error>>;
56
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
68
57
  fetchStatus: import("@tanstack/query-core").FetchStatus;
69
58
  } | {
70
59
  queryKey: string[];
71
- data: DatastoreWithRows;
60
+ data: TSelected;
72
61
  error: null;
73
62
  isError: false;
74
63
  isPending: false;
@@ -91,7 +80,7 @@ export declare const useFetchDatastore: ({ id, workspace, queryOptions }: FetchD
91
80
  isRefetching: boolean;
92
81
  isStale: boolean;
93
82
  isEnabled: boolean;
94
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<DatastoreWithRows, Error>>;
83
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
95
84
  fetchStatus: import("@tanstack/query-core").FetchStatus;
96
85
  } | {
97
86
  queryKey: string[];
@@ -118,7 +107,7 @@ export declare const useFetchDatastore: ({ id, workspace, queryOptions }: FetchD
118
107
  isRefetching: boolean;
119
108
  isStale: boolean;
120
109
  isEnabled: boolean;
121
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<DatastoreWithRows, Error>>;
110
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
122
111
  fetchStatus: import("@tanstack/query-core").FetchStatus;
123
112
  } | {
124
113
  queryKey: string[];
@@ -145,7 +134,7 @@ export declare const useFetchDatastore: ({ id, workspace, queryOptions }: FetchD
145
134
  isRefetching: boolean;
146
135
  isStale: boolean;
147
136
  isEnabled: boolean;
148
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<DatastoreWithRows, Error>>;
137
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
149
138
  fetchStatus: import("@tanstack/query-core").FetchStatus;
150
139
  } | {
151
140
  queryKey: string[];
@@ -172,11 +161,11 @@ export declare const useFetchDatastore: ({ id, workspace, queryOptions }: FetchD
172
161
  isRefetching: boolean;
173
162
  isStale: boolean;
174
163
  isEnabled: boolean;
175
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<DatastoreWithRows, Error>>;
164
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
176
165
  fetchStatus: import("@tanstack/query-core").FetchStatus;
177
166
  } | {
178
167
  queryKey: string[];
179
- data: DatastoreWithRows;
168
+ data: TSelected;
180
169
  isError: false;
181
170
  error: null;
182
171
  isPending: false;
@@ -199,7 +188,7 @@ export declare const useFetchDatastore: ({ id, workspace, queryOptions }: FetchD
199
188
  isRefetching: boolean;
200
189
  isStale: boolean;
201
190
  isEnabled: boolean;
202
- refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<DatastoreWithRows, Error>>;
191
+ refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<TSelected, Error>>;
203
192
  fetchStatus: import("@tanstack/query-core").FetchStatus;
204
193
  };
205
194
  //# sourceMappingURL=useFetchDatastore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useFetchDatastore.d.ts","sourceRoot":"","sources":["../../../src/hooks/datastore/useFetchDatastore.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAsB,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,MAAM,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;AAQvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,iBAAiB,GAAI,iCAAuD,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqC3G,CAAC"}
1
+ {"version":3,"file":"useFetchDatastore.d.ts","sourceRoot":"","sources":["../../../src/hooks/datastore/useFetchDatastore.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,MAAM,MAAM,mBAAmB,CAC3B,CAAC,SAAS,mBAAmB,GAAG,QAAQ,EACxC,SAAS,GAAG,eAAe,CAAC,CAAC,CAAC,IAC9B,oBAAoB,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG;IACtD;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,iBAAiB,GAC1B,CAAC,SAAS,mBAAmB,GAAG,QAAQ,EACxC,SAAS,GAAG,eAAe,CAAC,CAAC,CAAC,EAChC,sDAMC,mBAAmB,CAAC,CAAC,EAAE,SAAS,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiBnC,CAAC"}
@@ -1,81 +1,47 @@
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 { getDatastore } from "../../api/datastore.js";
4
- import { tableToObjects } from "../../lib/datastoreTable.js";
5
- import { useEffect } from "react";
6
- import { useQuery } from "@tanstack/react-query";
5
+ import { parseDatastore } from "../../lib/datastoreTable.js";
7
6
  //#region src/hooks/datastore/useFetchDatastore.ts
8
- var defaultQueryOptions = {
9
- refetchOnMount: "always",
10
- staleTime: 0,
11
- gcTime: 0
12
- };
13
7
  /**
14
8
  * useFetchDatastore
15
9
  *
16
- * Data-fetching hook built on TanStack Query to retrieve a single datastore by ID.
17
- *
18
- * It also:
19
- * - triggers an error alert via `useAppAlert` whenever `query.error` is present
20
- *
21
- * Important notes:
22
- * - Returns a `DatastoreWithRows` object: the full `Datastore` shape with `data`
23
- * replaced by `AnyRecord[]` (rows transformed via `tableToObjects`).
24
- *
25
- * Parameters (FetchDatastoreProps):
26
- * @param {string} id
27
- * Datastore identifier (required).
28
- *
29
- * @param {string} workspace
30
- * Workspace the datastore belongs to (required by `getDatastore`).
10
+ * Fetches one datastore. `data` is a `ParsedDatastore` — a table's matrix converted to row
11
+ * objects with `fields`, or a JSON datastore's content untouched, told apart by `format`, the
12
+ * same shape `useFetchDatastores` returns — or whatever `select` makes of it. With
13
+ * `dataFormat: "matrix"` a tabular datastore keeps its matrix unconverted, as in `useFetchDatastores`.
31
14
  *
32
- * @param {EntityQueryOptions<DatastoreWithRows>} [queryOptions=defaultQueryOptions]
33
- * TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
15
+ * Idle while `id` is empty; fails loudly, without a request, while `workspace` is. A failure is
16
+ * shown as an error alert.
34
17
  *
35
- * Returns:
36
- * @returns {object}
37
- * TanStack Query's `query` object extended with:
38
- * - `queryKey`: the cache key used by React Query
18
+ * @param {FetchDatastoreProps} props - `id`, `workspace`, `dataFormat`, `select` and TanStack
19
+ * `queryOptions`.
20
+ * @returns {object} The `useQuery` result, plus `queryKey`.
39
21
  *
40
22
  * Example:
41
23
  * ```ts
42
- * const { data, isLoading } = useFetchDatastore({
43
- * id: "abc123",
44
- * workspace: "my-workspace",
45
- * });
46
- * // data -> DatastoreWithRows (datastore metadata + rows as AnyRecord[])
47
- * // data.name -> "my-datastore"
48
- * // data.data -> [{ datastoreId: "abc123", col1: "value", ... }]
24
+ * const { data, isLoading, queryKey } = useFetchDatastore({ id: "abc123", workspace: "ws-1" });
49
25
  * ```
50
26
  */
51
- var useFetchDatastore = ({ id, workspace, queryOptions = defaultQueryOptions }) => {
27
+ var useFetchDatastore = ({ id, workspace, dataFormat, select, queryOptions }) => {
52
28
  const { api } = useAxios();
53
- const { showAlert } = useAppAlert();
29
+ const format = dataFormat ?? "object";
54
30
  const queryKey = [
55
31
  "datastore",
56
32
  id,
57
- workspace
33
+ workspace,
34
+ format
58
35
  ];
59
- const query = useQuery({
60
- queryKey,
61
- queryFn: async () => {
62
- const datastore = await getDatastore(api, id, workspace);
63
- return {
64
- ...datastore,
65
- data: tableToObjects(datastore.id, datastore.data?.[0], datastore.data)
66
- };
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
36
  return {
78
- ...query,
37
+ ...useEntityQuery({
38
+ queryKey,
39
+ fetchEntity: async (signal) => parseDatastore(await getDatastore(api, id, workspace, signal), format),
40
+ select,
41
+ enabled: Boolean(id),
42
+ configError: workspace ? void 0 : missingWorkspaceError("useFetchDatastore"),
43
+ queryOptions
44
+ }),
79
45
  queryKey
80
46
  };
81
47
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useFetchDatastore.js","names":[],"sources":["../../../src/hooks/datastore/useFetchDatastore.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { useQuery } from \"@tanstack/react-query\";\n\nimport { useAxios } from \"@/hooks/useAxios\";\nimport { useAppAlert } from \"@/contexts/appAlertContext/useAppAlert\";\nimport { getDatastore } from \"@/api/datastore\";\nimport { tableToObjects } from \"@/lib/datastoreTable\";\nimport type { DatastoreWithRows } from \"@/types/datastore\";\nimport type { EntityQueryOptions, FetchEntityParams } from \"@/types/entityQuery\";\n\nexport type FetchDatastoreProps = FetchEntityParams<DatastoreWithRows>;\n\nconst defaultQueryOptions: EntityQueryOptions<DatastoreWithRows> = {\n refetchOnMount: \"always\",\n staleTime: 0,\n gcTime: 0,\n};\n\n/**\n * useFetchDatastore\n *\n * Data-fetching hook built on TanStack Query to retrieve a single datastore by ID.\n *\n * It also:\n * - triggers an error alert via `useAppAlert` whenever `query.error` is present\n *\n * Important notes:\n * - Returns a `DatastoreWithRows` object: the full `Datastore` shape with `data`\n * replaced by `AnyRecord[]` (rows transformed via `tableToObjects`).\n *\n * Parameters (FetchDatastoreProps):\n * @param {string} id\n * Datastore identifier (required).\n *\n * @param {string} workspace\n * Workspace the datastore belongs to (required by `getDatastore`).\n *\n * @param {EntityQueryOptions<DatastoreWithRows>} [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 * Example:\n * ```ts\n * const { data, isLoading } = useFetchDatastore({\n * id: \"abc123\",\n * workspace: \"my-workspace\",\n * });\n * // data -> DatastoreWithRows (datastore metadata + rows as AnyRecord[])\n * // data.name -> \"my-datastore\"\n * // data.data -> [{ datastoreId: \"abc123\", col1: \"value\", ... }]\n * ```\n */\nexport const useFetchDatastore = ({ id, workspace, queryOptions = defaultQueryOptions }: FetchDatastoreProps) => {\n\n const { api } = useAxios();\n const { showAlert } = useAppAlert();\n\n const queryKey = [\"datastore\", id, workspace];\n\n const query = useQuery<DatastoreWithRows>({\n queryKey,\n queryFn: async () => {\n const datastore = await getDatastore(api, id, workspace);\n\n return {\n ...datastore,\n data: tableToObjects(\n datastore.id,\n datastore.data?.[0] as string[],\n datastore.data\n ),\n };\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":";;;;;;;AAaA,IAAM,sBAA6D;CAC/D,gBAAgB;CAChB,WAAW;CACX,QAAQ;AACZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,IAAa,qBAAqB,EAAE,IAAI,WAAW,eAAe,0BAA+C;CAE7G,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,EAAE,cAAc,YAAY;CAElC,MAAM,WAAW;EAAC;EAAa;EAAI;CAAS;CAE5C,MAAM,QAAQ,SAA4B;EACtC;EACA,SAAS,YAAY;GACjB,MAAM,YAAY,MAAM,aAAa,KAAK,IAAI,SAAS;GAEvD,OAAO;IACH,GAAG;IACH,MAAM,eACF,UAAU,IACV,UAAU,OAAO,IACjB,UAAU,IACd;GACJ;EACJ;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":"useFetchDatastore.js","names":[],"sources":["../../../src/hooks/datastore/useFetchDatastore.ts"],"sourcesContent":["import { useAxios } from \"@/hooks/useAxios\";\nimport { useEntityQuery } from \"@/hooks/useEntityQuery\";\nimport { missingWorkspaceError } from \"@/api/entityQuery\";\nimport { getDatastore } from \"@/api/datastore\";\nimport { parseDatastore } from \"@/lib/datastoreTable\";\nimport type { ParsedDatastore } from \"@/types/datastore\";\nimport type { DatastoreDataFormat } from \"@/types/datastoreDataFormat\";\nimport type { FetchEntityByIdProps } from \"@/types/entityQuery\";\n\nexport type FetchDatastoreProps<\n F extends DatastoreDataFormat = \"object\",\n TSelected = ParsedDatastore<F>,\n> = FetchEntityByIdProps<ParsedDatastore<F>, TSelected> & {\n /**\n * Tabular datastores only: `\"object\"` (default) turns the matrix into one object per row;\n * `\"matrix\"` leaves the matrix, header row included. A JSON datastore's `data` is unchanged either way.\n */\n dataFormat?: F;\n};\n\n/**\n * useFetchDatastore\n *\n * Fetches one datastore. `data` is a `ParsedDatastore` — a table's matrix converted to row\n * objects with `fields`, or a JSON datastore's content untouched, told apart by `format`, the\n * same shape `useFetchDatastores` returns — or whatever `select` makes of it. With\n * `dataFormat: \"matrix\"` a tabular datastore keeps its matrix unconverted, as in `useFetchDatastores`.\n *\n * Idle while `id` is empty; fails loudly, without a request, while `workspace` is. A failure is\n * shown as an error alert.\n *\n * @param {FetchDatastoreProps} props - `id`, `workspace`, `dataFormat`, `select` and TanStack\n * `queryOptions`.\n * @returns {object} The `useQuery` result, plus `queryKey`.\n *\n * Example:\n * ```ts\n * const { data, isLoading, queryKey } = useFetchDatastore({ id: \"abc123\", workspace: \"ws-1\" });\n * ```\n */\nexport const useFetchDatastore = <\n F extends DatastoreDataFormat = \"object\",\n TSelected = ParsedDatastore<F>,\n>({\n id,\n workspace,\n dataFormat,\n select,\n queryOptions,\n}: FetchDatastoreProps<F, TSelected>) => {\n const { api } = useAxios();\n\n const format = (dataFormat ?? \"object\") as F;\n const queryKey = [\"datastore\", id, workspace, format];\n\n const query = useEntityQuery<ParsedDatastore<F>, TSelected>({\n queryKey,\n fetchEntity: async (signal) =>\n parseDatastore(await getDatastore(api, id, workspace, signal), format),\n select,\n enabled: Boolean(id),\n configError: workspace ? undefined : missingWorkspaceError(\"useFetchDatastore\"),\n queryOptions,\n });\n\n return { ...query, queryKey };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,IAAa,qBAGX,EACE,IACA,WACA,YACA,QACA,mBACqC;CACrC,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,SAAU,cAAc;CAC9B,MAAM,WAAW;EAAC;EAAa;EAAI;EAAW;CAAM;CAYpD,OAAO;EAAE,GAVK,eAA8C;GACxD;GACA,aAAa,OAAO,WAChB,eAAe,MAAM,aAAa,KAAK,IAAI,WAAW,MAAM,GAAG,MAAM;GACzE;GACA,SAAS,QAAQ,EAAE;GACnB,aAAa,YAAY,KAAA,IAAY,sBAAsB,mBAAmB;GAC9E;EACJ,CAEY;EAAO;CAAS;AAChC"}