@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.
- package/README.md +298 -12
- package/dist/EveryskApp.d.ts +34 -2
- package/dist/EveryskApp.d.ts.map +1 -1
- package/dist/EveryskApp.js +35 -2
- package/dist/EveryskApp.js.map +1 -1
- package/dist/agGrid/handleRowsScrollEnd.d.ts +53 -0
- package/dist/agGrid/handleRowsScrollEnd.d.ts.map +1 -0
- package/dist/agGrid/handleRowsScrollEnd.js +47 -0
- package/dist/agGrid/handleRowsScrollEnd.js.map +1 -0
- package/dist/agGrid/index.d.ts +2 -0
- package/dist/agGrid/index.d.ts.map +1 -1
- package/dist/agGrid/index.js +2 -1
- package/dist/api/datastore.d.ts +10 -8
- package/dist/api/datastore.d.ts.map +1 -1
- package/dist/api/datastore.js +24 -55
- package/dist/api/datastore.js.map +1 -1
- package/dist/api/entityQuery.d.ts +46 -41
- package/dist/api/entityQuery.d.ts.map +1 -1
- package/dist/api/entityQuery.js +55 -14
- package/dist/api/entityQuery.js.map +1 -1
- package/dist/api/file.d.ts +26 -9
- package/dist/api/file.d.ts.map +1 -1
- package/dist/api/file.js +45 -55
- package/dist/api/file.js.map +1 -1
- package/dist/api/portfolio.d.ts +11 -8
- package/dist/api/portfolio.d.ts.map +1 -1
- package/dist/api/portfolio.js +24 -55
- package/dist/api/portfolio.js.map +1 -1
- package/dist/api/profile.d.ts +3 -2
- package/dist/api/profile.d.ts.map +1 -1
- package/dist/api/profile.js +4 -9
- package/dist/api/profile.js.map +1 -1
- package/dist/api/request.d.ts +106 -0
- package/dist/api/request.d.ts.map +1 -0
- package/dist/api/request.js +132 -0
- package/dist/api/request.js.map +1 -0
- package/dist/api/websocketsConfig.d.ts +7 -2
- package/dist/api/websocketsConfig.d.ts.map +1 -1
- package/dist/api/websocketsConfig.js +2 -10
- package/dist/api/websocketsConfig.js.map +1 -1
- package/dist/api/workflow.d.ts +84 -89
- package/dist/api/workflow.d.ts.map +1 -1
- package/dist/api/workflow.js +121 -208
- package/dist/api/workflow.js.map +1 -1
- package/dist/api/workspace.d.ts +18 -8
- package/dist/api/workspace.d.ts.map +1 -1
- package/dist/api/workspace.js +21 -26
- package/dist/api/workspace.js.map +1 -1
- package/dist/components/ui/Footer/index.d.ts.map +1 -1
- package/dist/components/ui/Footer/index.js.map +1 -1
- package/dist/components/ui/GlobalLoading/index.d.ts.map +1 -1
- package/dist/components/ui/GlobalLoading/index.js.map +1 -1
- package/dist/components/ui/PageContainer/index.d.ts +1 -1
- package/dist/components/ui/PageContainer/index.d.ts.map +1 -1
- package/dist/components/ui/PageContainer/index.js.map +1 -1
- package/dist/components/ui/Toolbar/index.d.ts +40 -3
- package/dist/components/ui/Toolbar/index.d.ts.map +1 -1
- package/dist/components/ui/Toolbar/index.js +42 -15
- package/dist/components/ui/Toolbar/index.js.map +1 -1
- package/dist/contexts/appAlertContext/provider.js.map +1 -1
- package/dist/contexts/appAlertContext/types.d.ts.map +1 -1
- package/dist/contexts/appConfigContext/index.d.ts.map +1 -1
- package/dist/contexts/appConfigContext/index.js.map +1 -1
- package/dist/contexts/appConfigContext/provider.d.ts.map +1 -1
- package/dist/contexts/appConfigContext/provider.js.map +1 -1
- package/dist/contexts/webSocketContext/handler.d.ts +3 -2
- package/dist/contexts/webSocketContext/handler.d.ts.map +1 -1
- package/dist/contexts/webSocketContext/handler.js.map +1 -1
- package/dist/contexts/webSocketContext/hooks/useWebSocket/index.d.ts +1 -1
- package/dist/contexts/webSocketContext/hooks/useWebSocket/index.js +1 -1
- package/dist/contexts/webSocketContext/hooks/useWebSocket/index.js.map +1 -1
- package/dist/contexts/webSocketContext/provider.d.ts +6 -3
- package/dist/contexts/webSocketContext/provider.d.ts.map +1 -1
- package/dist/contexts/webSocketContext/provider.js +42 -7
- package/dist/contexts/webSocketContext/provider.js.map +1 -1
- package/dist/contexts/webSocketContext/types.d.ts +7 -5
- package/dist/contexts/webSocketContext/types.d.ts.map +1 -1
- package/dist/file/index.d.ts +2 -0
- package/dist/file/index.d.ts.map +1 -1
- package/dist/hooks/datastore/useDatastoreMutations.d.ts +4 -4
- package/dist/hooks/datastore/useDatastoreMutations.d.ts.map +1 -1
- package/dist/hooks/datastore/useDatastoreMutations.js +17 -55
- package/dist/hooks/datastore/useDatastoreMutations.js.map +1 -1
- package/dist/hooks/datastore/useFetchDatastore.d.ts +30 -41
- package/dist/hooks/datastore/useFetchDatastore.d.ts.map +1 -1
- package/dist/hooks/datastore/useFetchDatastore.js +25 -59
- package/dist/hooks/datastore/useFetchDatastore.js.map +1 -1
- package/dist/hooks/datastore/useFetchDatastores.d.ts +47 -52
- package/dist/hooks/datastore/useFetchDatastores.d.ts.map +1 -1
- package/dist/hooks/datastore/useFetchDatastores.js +55 -70
- package/dist/hooks/datastore/useFetchDatastores.js.map +1 -1
- package/dist/hooks/file/fileData.d.ts +17 -0
- package/dist/hooks/file/fileData.d.ts.map +1 -0
- package/dist/hooks/file/fileData.js +10 -0
- package/dist/hooks/file/fileData.js.map +1 -0
- package/dist/hooks/file/useFetchFile.d.ts +38 -58
- package/dist/hooks/file/useFetchFile.d.ts.map +1 -1
- package/dist/hooks/file/useFetchFile.js +26 -66
- package/dist/hooks/file/useFetchFile.js.map +1 -1
- package/dist/hooks/file/useFetchFiles.d.ts +18 -52
- package/dist/hooks/file/useFetchFiles.d.ts.map +1 -1
- package/dist/hooks/file/useFetchFiles.js +53 -69
- package/dist/hooks/file/useFetchFiles.js.map +1 -1
- package/dist/hooks/file/useFileMutations.d.ts +9 -8
- package/dist/hooks/file/useFileMutations.d.ts.map +1 -1
- package/dist/hooks/file/useFileMutations.js +23 -60
- package/dist/hooks/file/useFileMutations.js.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolio.d.ts +16 -50
- package/dist/hooks/portfolio/useFetchPortfolio.d.ts.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolio.js +15 -63
- package/dist/hooks/portfolio/useFetchPortfolio.js.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolios.d.ts +13 -52
- package/dist/hooks/portfolio/useFetchPortfolios.d.ts.map +1 -1
- package/dist/hooks/portfolio/useFetchPortfolios.js +29 -71
- package/dist/hooks/portfolio/useFetchPortfolios.js.map +1 -1
- package/dist/hooks/portfolio/usePortfolioMutations.d.ts +8 -8
- package/dist/hooks/portfolio/usePortfolioMutations.d.ts.map +1 -1
- package/dist/hooks/portfolio/usePortfolioMutations.js +20 -58
- package/dist/hooks/portfolio/usePortfolioMutations.js.map +1 -1
- package/dist/hooks/profile/useFetchProfile.d.ts +18 -44
- package/dist/hooks/profile/useFetchProfile.d.ts.map +1 -1
- package/dist/hooks/profile/useFetchProfile.js +16 -48
- package/dist/hooks/profile/useFetchProfile.js.map +1 -1
- package/dist/hooks/useAxios.js.map +1 -1
- package/dist/hooks/useEntityInfiniteQuery.d.ts +88 -0
- package/dist/hooks/useEntityInfiniteQuery.d.ts.map +1 -0
- package/dist/hooks/useEntityInfiniteQuery.js +111 -0
- package/dist/hooks/useEntityInfiniteQuery.js.map +1 -0
- package/dist/hooks/useEntityMutation.d.ts +47 -0
- package/dist/hooks/useEntityMutation.d.ts.map +1 -0
- package/dist/hooks/useEntityMutation.js +58 -0
- package/dist/hooks/useEntityMutation.js.map +1 -0
- package/dist/hooks/useEntityQuery.d.ts +68 -0
- package/dist/hooks/useEntityQuery.d.ts.map +1 -0
- package/dist/hooks/useEntityQuery.js +75 -0
- package/dist/hooks/useEntityQuery.js.map +1 -0
- package/dist/hooks/workflow/useFetchWorkerExecution.d.ts +17 -34
- package/dist/hooks/workflow/useFetchWorkerExecution.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkerExecution.js +16 -46
- package/dist/hooks/workflow/useFetchWorkerExecution.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkerExecutions.d.ts +179 -41
- package/dist/hooks/workflow/useFetchWorkerExecutions.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkerExecutions.js +29 -62
- package/dist/hooks/workflow/useFetchWorkerExecutions.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflow.d.ts +16 -35
- package/dist/hooks/workflow/useFetchWorkflow.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflow.js +15 -48
- package/dist/hooks/workflow/useFetchWorkflow.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecution.d.ts +17 -34
- package/dist/hooks/workflow/useFetchWorkflowExecution.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecution.js +16 -46
- package/dist/hooks/workflow/useFetchWorkflowExecution.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecutions.d.ts +22 -36
- package/dist/hooks/workflow/useFetchWorkflowExecutions.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflowExecutions.js +43 -56
- package/dist/hooks/workflow/useFetchWorkflowExecutions.js.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflows.d.ts +20 -37
- package/dist/hooks/workflow/useFetchWorkflows.d.ts.map +1 -1
- package/dist/hooks/workflow/useFetchWorkflows.js +32 -47
- package/dist/hooks/workflow/useFetchWorkflows.js.map +1 -1
- package/dist/hooks/workflow/useRunWorkflow.d.ts +21 -16
- package/dist/hooks/workflow/useRunWorkflow.d.ts.map +1 -1
- package/dist/hooks/workflow/useRunWorkflow.js +66 -29
- package/dist/hooks/workflow/useRunWorkflow.js.map +1 -1
- package/dist/hooks/workflow/useTriggerWorkflow.d.ts +20 -0
- package/dist/hooks/workflow/useTriggerWorkflow.d.ts.map +1 -0
- package/dist/hooks/workflow/useTriggerWorkflow.js +32 -0
- package/dist/hooks/workflow/useTriggerWorkflow.js.map +1 -0
- package/dist/hooks/workspace/useFetchWorkspace.d.ts +19 -34
- package/dist/hooks/workspace/useFetchWorkspace.d.ts.map +1 -1
- package/dist/hooks/workspace/useFetchWorkspace.js +16 -46
- package/dist/hooks/workspace/useFetchWorkspace.js.map +1 -1
- package/dist/hooks/workspace/useFetchWorkspaces.d.ts +17 -37
- package/dist/hooks/workspace/useFetchWorkspaces.d.ts.map +1 -1
- package/dist/hooks/workspace/useFetchWorkspaces.js +25 -47
- package/dist/hooks/workspace/useFetchWorkspaces.js.map +1 -1
- package/dist/index.d.ts +13 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -11
- package/dist/lib/abort.d.ts +58 -0
- package/dist/lib/abort.d.ts.map +1 -0
- package/dist/lib/abort.js +112 -0
- package/dist/lib/abort.js.map +1 -0
- package/dist/lib/datastoreTable.d.ts +59 -54
- package/dist/lib/datastoreTable.d.ts.map +1 -1
- package/dist/lib/datastoreTable.js +58 -62
- package/dist/lib/datastoreTable.js.map +1 -1
- package/dist/lib/file.d.ts +34 -0
- package/dist/lib/file.d.ts.map +1 -0
- package/dist/lib/file.js +63 -0
- package/dist/lib/file.js.map +1 -0
- package/dist/lib/queryClient.d.ts.map +1 -1
- package/dist/lib/queryClient.js.map +1 -1
- package/dist/lib/workflowRun.d.ts +91 -0
- package/dist/lib/workflowRun.d.ts.map +1 -0
- package/dist/lib/workflowRun.js +224 -0
- package/dist/lib/workflowRun.js.map +1 -0
- package/dist/socket/index.d.ts +1 -3
- package/dist/socket/index.d.ts.map +1 -1
- package/dist/socket/index.js +3 -5
- package/dist/test/mocks/index.d.ts +1 -1
- package/dist/test/mocks/index.d.ts.map +1 -1
- package/dist/test/renderWithProviders.d.ts +2 -2
- package/dist/test/renderWithProviders.d.ts.map +1 -1
- package/dist/test/renderWithProviders.js.map +1 -1
- package/dist/test/setup.js.map +1 -1
- package/dist/theme/index.d.ts +1 -1
- package/dist/theme/index.d.ts.map +1 -1
- package/dist/theme/overrides/index.d.ts +4 -2
- package/dist/theme/overrides/index.d.ts.map +1 -1
- package/dist/theme/overrides/index.js +5 -3
- package/dist/theme/overrides/index.js.map +1 -1
- package/dist/theme/overrides/muiButton.d.ts +2 -2
- package/dist/theme/overrides/muiButton.js.map +1 -1
- package/dist/theme/overrides/muiCssBaseline.d.ts.map +1 -1
- package/dist/theme/overrides/muiCssBaseline.js.map +1 -1
- package/dist/theme/overrides/muiDatePicker.js.map +1 -1
- package/dist/theme/overrides/muiFormControl.js.map +1 -1
- package/dist/theme/overrides/muiIconButton.d.ts +2 -2
- package/dist/theme/overrides/muiIconButton.js.map +1 -1
- package/dist/theme/overrides/muiSelect.d.ts.map +1 -1
- package/dist/theme/overrides/muiSelect.js.map +1 -1
- package/dist/theme/overrides/muiSvgIcon.d.ts.map +1 -1
- package/dist/theme/overrides/muiSvgIcon.js.map +1 -1
- package/dist/theme/overrides/muiTextField.js.map +1 -1
- package/dist/theme/overrides/muiToggleButton.d.ts +2 -2
- package/dist/theme/overrides/muiToggleButton.js.map +1 -1
- package/dist/theme/overrides/muiToggleButtonGroup.d.ts +2 -2
- package/dist/theme/overrides/muiToggleButtonGroup.js.map +1 -1
- package/dist/theme/themes/DefaultDark.js +2 -2
- package/dist/theme/themes/DefaultDark.js.map +1 -1
- package/dist/theme/themes/DefaultLight.js +2 -2
- package/dist/theme/themes/DefaultLight.js.map +1 -1
- package/dist/theme/themes/EveryskDark.js +2 -2
- package/dist/theme/themes/EveryskDark.js.map +1 -1
- package/dist/theme/themes/EveryskLight.js +2 -2
- package/dist/theme/themes/EveryskLight.js.map +1 -1
- package/dist/theme/themes/MidnightEmber.js +2 -2
- package/dist/theme/themes/MidnightEmber.js.map +1 -1
- package/dist/types/anyRecord.d.ts.map +1 -1
- package/dist/types/datastore.d.ts +35 -5
- package/dist/types/datastore.d.ts.map +1 -1
- package/dist/types/datastoreDataFormat.d.ts +13 -0
- package/dist/types/datastoreDataFormat.d.ts.map +1 -0
- package/dist/types/entityQuery.d.ts +86 -16
- package/dist/types/entityQuery.d.ts.map +1 -1
- package/dist/types/file.d.ts +7 -3
- package/dist/types/file.d.ts.map +1 -1
- package/dist/types/portfolio.d.ts +1 -3
- package/dist/types/portfolio.d.ts.map +1 -1
- package/dist/types/profile.d.ts +0 -10
- package/dist/types/profile.d.ts.map +1 -1
- package/dist/types/workflow.d.ts +35 -6
- package/dist/types/workflow.d.ts.map +1 -1
- package/dist/types/workspace.d.ts +1 -2
- package/dist/types/workspace.d.ts.map +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/workflow/index.d.ts +2 -0
- package/dist/workflow/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/EveryskApp.tsx +53 -2
- package/src/agGrid/handleRowsScrollEnd.ts +71 -0
- package/src/agGrid/index.ts +5 -1
- package/src/api/datastore.ts +79 -107
- package/src/api/entityQuery.ts +86 -17
- package/src/api/file.ts +110 -103
- package/src/api/portfolio.ts +82 -125
- package/src/api/profile.ts +25 -18
- package/src/api/request.ts +168 -0
- package/src/api/websocketsConfig.ts +11 -19
- package/src/api/workflow.ts +232 -334
- package/src/api/workspace.ts +43 -43
- package/src/components/ui/Footer/index.tsx +8 -7
- package/src/components/ui/GlobalLoading/index.tsx +13 -3
- package/src/components/ui/PageContainer/index.tsx +9 -2
- package/src/components/ui/Toolbar/index.tsx +105 -30
- package/src/contexts/appAlertContext/provider.tsx +1 -1
- package/src/contexts/appAlertContext/types.ts +3 -3
- package/src/contexts/appConfigContext/index.tsx +1 -1
- package/src/contexts/appConfigContext/provider.tsx +1 -5
- package/src/contexts/webSocketContext/handler.ts +8 -2
- package/src/contexts/webSocketContext/hooks/useWebSocket/index.ts +1 -1
- package/src/contexts/webSocketContext/provider.tsx +64 -14
- package/src/contexts/webSocketContext/types.ts +7 -6
- package/src/file/index.ts +2 -0
- package/src/hooks/datastore/useDatastoreMutations.ts +19 -60
- package/src/hooks/datastore/useFetchDatastore.ts +45 -73
- package/src/hooks/datastore/useFetchDatastores.ts +106 -131
- package/src/hooks/file/fileData.ts +19 -0
- package/src/hooks/file/useFetchFile.ts +41 -76
- package/src/hooks/file/useFetchFiles.ts +92 -87
- package/src/hooks/file/useFileMutations.ts +23 -73
- package/src/hooks/portfolio/useFetchPortfolio.ts +26 -78
- package/src/hooks/portfolio/useFetchPortfolios.ts +50 -93
- package/src/hooks/portfolio/usePortfolioMutations.ts +22 -72
- package/src/hooks/profile/useFetchProfile.ts +24 -65
- package/src/hooks/useAxios.ts +5 -5
- package/src/hooks/useEntityInfiniteQuery.ts +193 -0
- package/src/hooks/useEntityMutation.ts +70 -0
- package/src/hooks/useEntityQuery.ts +117 -0
- package/src/hooks/workflow/useFetchWorkerExecution.ts +27 -56
- package/src/hooks/workflow/useFetchWorkerExecutions.ts +54 -79
- package/src/hooks/workflow/useFetchWorkflow.ts +24 -58
- package/src/hooks/workflow/useFetchWorkflowExecution.ts +27 -57
- package/src/hooks/workflow/useFetchWorkflowExecutions.ts +64 -73
- package/src/hooks/workflow/useFetchWorkflows.ts +48 -64
- package/src/hooks/workflow/useRunWorkflow.ts +82 -36
- package/src/hooks/workflow/useTriggerWorkflow.ts +36 -0
- package/src/hooks/workspace/useFetchWorkspace.ts +25 -58
- package/src/hooks/workspace/useFetchWorkspaces.ts +38 -69
- package/src/index.ts +34 -19
- package/src/lib/abort.ts +131 -0
- package/src/lib/datastoreTable.ts +127 -74
- package/src/lib/file.ts +67 -0
- package/src/lib/queryClient.ts +11 -13
- package/src/lib/workflowRun.ts +329 -0
- package/src/socket/index.ts +1 -3
- package/src/test/mocks/index.ts +1 -5
- package/src/test/renderWithProviders.tsx +8 -3
- package/src/test/setup.ts +16 -16
- package/src/theme/index.ts +1 -1
- package/src/theme/overrides/index.ts +5 -3
- package/src/theme/overrides/muiButton.ts +3 -3
- package/src/theme/overrides/muiCssBaseline.ts +11 -12
- package/src/theme/overrides/muiDatePicker.ts +2 -2
- package/src/theme/overrides/muiFormControl.ts +2 -2
- package/src/theme/overrides/muiIconButton.ts +3 -3
- package/src/theme/overrides/muiSelect.ts +2 -2
- package/src/theme/overrides/muiSvgIcon.ts +2 -2
- package/src/theme/overrides/muiTextField.ts +1 -1
- package/src/theme/overrides/muiToggleButton.ts +4 -4
- package/src/theme/overrides/muiToggleButtonGroup.ts +4 -4
- package/src/theme/themes/DefaultDark.ts +2 -2
- package/src/theme/themes/DefaultLight.ts +2 -2
- package/src/theme/themes/EveryskDark.ts +2 -2
- package/src/theme/themes/EveryskLight.ts +2 -2
- package/src/theme/themes/MidnightEmber.ts +15 -15
- package/src/types/anyRecord.ts +2 -2
- package/src/types/datastore.ts +56 -22
- package/src/types/datastoreDataFormat.ts +12 -0
- package/src/types/entityQuery.ts +122 -38
- package/src/types/file.ts +8 -6
- package/src/types/portfolio.ts +70 -74
- package/src/types/profile.ts +0 -11
- package/src/types/workflow.ts +38 -9
- package/src/types/workspace.ts +2 -4
- package/src/ui/index.ts +1 -1
- package/src/workflow/index.ts +5 -0
|
@@ -1,83 +1,43 @@
|
|
|
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 { getFile } from "../../api/file.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { withoutData } from "./fileData.js";
|
|
6
|
+
import { useCallback } from "react";
|
|
6
7
|
//#region src/hooks/file/useFetchFile.ts
|
|
7
|
-
var defaultQueryOptions = {
|
|
8
|
-
refetchOnMount: "always",
|
|
9
|
-
staleTime: 0,
|
|
10
|
-
gcTime: 0
|
|
11
|
-
};
|
|
12
8
|
/**
|
|
13
9
|
* useFetchFile
|
|
14
10
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* - triggers an error alert via `useAppAlert` whenever `query.error` is present
|
|
20
|
-
*
|
|
21
|
-
* Important notes:
|
|
22
|
-
* - Always returns a single `EveryskFile` object.
|
|
23
|
-
* - `EveryskFile.data` represents the file content and is expected to be a Base64-encoded string
|
|
24
|
-
* when provided by the API (or when sending content through mutations).
|
|
25
|
-
*
|
|
26
|
-
* Parameters (FetchFileProps):
|
|
27
|
-
* @param {string} id
|
|
28
|
-
* EveryskFile identifier (required).
|
|
29
|
-
*
|
|
30
|
-
* @param {string} workspace
|
|
31
|
-
* Workspace the file belongs to (required by `getFile`).
|
|
32
|
-
*
|
|
33
|
-
* @param {EntityQueryOptions<any>} [queryOptions=defaultQueryOptions]
|
|
34
|
-
* TanStack Query options passed through to `useQuery` (e.g., enabled, staleTime, gcTime, etc.).
|
|
35
|
-
*
|
|
36
|
-
* Returns:
|
|
37
|
-
* @returns {object}
|
|
38
|
-
* TanStack Query's `query` object extended with:
|
|
39
|
-
* - `queryKey`: the cache key used by React Query
|
|
40
|
-
*
|
|
41
|
-
* Tip:
|
|
42
|
-
* - The returned `queryKey` can be reused by mutation hooks for cache invalidation:
|
|
43
|
-
* ```ts
|
|
44
|
-
* const fetch = useFetchFile({ id: "file-123", workspace: "ws-1" });
|
|
45
|
-
* useFileMutations({ queryKey: fetch.queryKey });
|
|
46
|
-
* ```
|
|
11
|
+
* Fetches one file; `data` is the file, or whatever `select` makes of it. Idle while `id` is
|
|
12
|
+
* empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error
|
|
13
|
+
* alert. The file comes without its content unless `withData` asks for it: show or download it
|
|
14
|
+
* through its `url`.
|
|
47
15
|
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* id: "file-123",
|
|
52
|
-
* workspace: "ws-1",
|
|
53
|
-
* });
|
|
54
|
-
* // data -> EveryskFile
|
|
55
|
-
* ```
|
|
16
|
+
* @param {FetchFileProps} props - `id`, `workspace`, `withData`, `select` and TanStack
|
|
17
|
+
* `queryOptions`.
|
|
18
|
+
* @returns {object} The `useQuery` result, plus `queryKey`.
|
|
56
19
|
*/
|
|
57
|
-
var useFetchFile = ({ id, workspace, queryOptions =
|
|
20
|
+
var useFetchFile = ({ id, workspace, select, queryOptions, withData = false }) => {
|
|
58
21
|
const { api } = useAxios();
|
|
59
|
-
const { showAlert } = useAppAlert();
|
|
60
22
|
const queryKey = [
|
|
61
23
|
"file",
|
|
62
24
|
id,
|
|
63
|
-
workspace
|
|
25
|
+
workspace,
|
|
26
|
+
{ withData }
|
|
64
27
|
];
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
},
|
|
70
|
-
...queryOptions ?? {}
|
|
71
|
-
});
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (!query.error) return;
|
|
74
|
-
showAlert({
|
|
75
|
-
severity: "error",
|
|
76
|
-
message: query.error.message
|
|
77
|
-
});
|
|
78
|
-
}, [query.error, showAlert]);
|
|
28
|
+
const selectFile = useCallback((file) => {
|
|
29
|
+
const visible = withData ? file : withoutData(file);
|
|
30
|
+
return select ? select(visible) : visible;
|
|
31
|
+
}, [withData, select]);
|
|
79
32
|
return {
|
|
80
|
-
...
|
|
33
|
+
...useEntityQuery({
|
|
34
|
+
queryKey,
|
|
35
|
+
fetchEntity: (signal) => getFile(api, id, workspace, { withData }, signal),
|
|
36
|
+
select: selectFile,
|
|
37
|
+
enabled: Boolean(id),
|
|
38
|
+
configError: workspace ? void 0 : missingWorkspaceError("useFetchFile"),
|
|
39
|
+
queryOptions
|
|
40
|
+
}),
|
|
81
41
|
queryKey
|
|
82
42
|
};
|
|
83
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchFile.js","names":[],"sources":["../../../src/hooks/file/useFetchFile.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useFetchFile.js","names":[],"sources":["../../../src/hooks/file/useFetchFile.ts"],"sourcesContent":["import { useCallback } from \"react\";\n\nimport { useAxios } from \"@/hooks/useAxios\";\nimport { useEntityQuery } from \"@/hooks/useEntityQuery\";\nimport { missingWorkspaceError } from \"@/api/entityQuery\";\nimport { getFile } from \"@/api/file\";\nimport type { EveryskFile } from \"@/types/file\";\nimport type { FetchEntityByIdProps } from \"@/types/entityQuery\";\nimport { withoutData, type FileDataProps } from \"./fileData\";\n\nexport type FetchFileProps<TData = EveryskFile, TSelected = TData> = FetchEntityByIdProps<\n TData,\n TSelected\n> &\n FileDataProps;\n\n/**\n * useFetchFile\n *\n * Fetches one file; `data` is the file, or whatever `select` makes of it. Idle while `id` is\n * empty; fails loudly, without a request, while `workspace` is. A failure is shown as an error\n * alert. The file comes without its content unless `withData` asks for it: show or download it\n * through its `url`.\n *\n * @param {FetchFileProps} props - `id`, `workspace`, `withData`, `select` and TanStack\n * `queryOptions`.\n * @returns {object} The `useQuery` result, plus `queryKey`.\n */\nexport const useFetchFile = <TSelected = EveryskFile>({\n id,\n workspace,\n select,\n queryOptions,\n withData = false,\n}: FetchFileProps<EveryskFile, TSelected>) => {\n const { api } = useAxios();\n\n const queryKey = [\"file\", id, workspace, { withData }];\n\n const selectFile = useCallback(\n (file: EveryskFile): TSelected => {\n const visible = withData ? file : withoutData(file);\n return select ? select(visible) : (visible as TSelected);\n },\n [withData, select],\n );\n\n const query = useEntityQuery<EveryskFile, TSelected>({\n queryKey,\n fetchEntity: (signal) => getFile(api, id, workspace, { withData }, signal),\n select: selectFile,\n enabled: Boolean(id),\n configError: workspace ? undefined : missingWorkspaceError(\"useFetchFile\"),\n queryOptions,\n });\n\n return { ...query, queryKey };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA4BA,IAAa,gBAAyC,EAClD,IACA,WACA,QACA,cACA,WAAW,YAC+B;CAC1C,MAAM,EAAE,QAAQ,SAAS;CAEzB,MAAM,WAAW;EAAC;EAAQ;EAAI;EAAW,EAAE,SAAS;CAAC;CAErD,MAAM,aAAa,aACd,SAAiC;EAC9B,MAAM,UAAU,WAAW,OAAO,YAAY,IAAI;EAClD,OAAO,SAAS,OAAO,OAAO,IAAK;CACvC,GACA,CAAC,UAAU,MAAM,CACrB;CAWA,OAAO;EAAE,GATK,eAAuC;GACjD;GACA,cAAc,WAAW,QAAQ,KAAK,IAAI,WAAW,EAAE,SAAS,GAAG,MAAM;GACzE,QAAQ;GACR,SAAS,QAAQ,EAAE;GACnB,aAAa,YAAY,KAAA,IAAY,sBAAsB,cAAc;GACzE;EACJ,CAEY;EAAO;CAAS;AAChC"}
|
|
@@ -1,60 +1,26 @@
|
|
|
1
|
-
import { type UseInfiniteQueryOptions, type QueryKey } from "@tanstack/react-query";
|
|
2
1
|
import type { EveryskFile, FileListResponse } from "../../types/file.d.ts";
|
|
3
|
-
import type {
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
};
|
|
2
|
+
import type { FetchEntitiesProps, ListQueryProps, ListCache } from "../../types/entityQuery.d.ts";
|
|
3
|
+
import { type FileDataProps } from "./fileData";
|
|
4
|
+
/** The query cache of `useFetchFiles`, for typing `setQueryData`. */
|
|
5
|
+
export type FilesCache = ListCache<FileListResponse>;
|
|
6
|
+
export type FetchFilesProps<TData = EveryskFile[]> = ListQueryProps & FetchEntitiesProps<EveryskFile, TData, FileListResponse> & FileDataProps;
|
|
9
7
|
/**
|
|
10
8
|
* useFetchFiles
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
23
|
-
* Filters applied to every page request. Must include a `workspace` filter.
|
|
24
|
-
*
|
|
25
|
-
* @param {string[]} [order=[]]
|
|
26
|
-
* Sorting applied to every page request.
|
|
27
|
-
*
|
|
28
|
-
* @param {string} [projection=""]
|
|
29
|
-
* Single field to project: `"field"` returns only that field (others come back null),
|
|
30
|
-
* `"-field"` returns every field except that one. One field only — lists 500. Omitted when empty.
|
|
31
|
-
*
|
|
32
|
-
* @param {number} [pageSize=10]
|
|
33
|
-
* Number of files to fetch per page.
|
|
34
|
-
*
|
|
35
|
-
* @param {InfiniteOptions<EveryskFile[]>} [queryOptions]
|
|
36
|
-
* TanStack Query options passed through to `useInfiniteQuery`
|
|
37
|
-
* (e.g., enabled, staleTime, gcTime, etc.).
|
|
38
|
-
*
|
|
39
|
-
* Returns:
|
|
40
|
-
* @returns {object}
|
|
41
|
-
* - `query`: the full `useInfiniteQuery` result (data, isLoading, hasNextPage, fetchNextPage, etc.)
|
|
42
|
-
* - `queryKey`: the cache key used by React Query
|
|
43
|
-
*
|
|
44
|
-
* Example:
|
|
45
|
-
* ```ts
|
|
46
|
-
* const { query } = useFetchFiles({
|
|
47
|
-
* filters: [{ field: "workspace", value: "ws-1" }],
|
|
48
|
-
* pageSize: 20,
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* // Flat list of all fetched files
|
|
52
|
-
* const files = query.data ?? [];
|
|
53
|
-
* ```
|
|
10
|
+
* Lists files with cursor pagination; `query.data` is every loaded page merged, or whatever
|
|
11
|
+
* `select` makes of it. Paging, `select`, `fetchAllPages` and the missing-workspace error
|
|
12
|
+
* behave as in `useFetchDatastores`. The files come without their content unless `withData`
|
|
13
|
+
* asks for it: show or download each through its `url`. The exclusion of `data` is added to a
|
|
14
|
+
* `projection` of the app's own that only excludes fields; one that includes fields is sent as
|
|
15
|
+
* given (see `projectionToSend`). Either way the content is left out of what the hook returns
|
|
16
|
+
* unless `withData` asks for it.
|
|
17
|
+
*
|
|
18
|
+
* @param {FetchFilesProps} props - Filters (one must be `workspace`), order, projection,
|
|
19
|
+
* page size, `withData`, `select`, `fetchAllPages` and TanStack `queryOptions`.
|
|
20
|
+
* @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.
|
|
54
21
|
*/
|
|
55
|
-
export declare function useFetchFiles({ filters, order, projection, pageSize, queryOptions }:
|
|
56
|
-
query: import("@tanstack/react-query").UseInfiniteQueryResult<
|
|
22
|
+
export declare function useFetchFiles<TData = EveryskFile[]>({ filters, order, projection, pageSize, select, fetchAllPages, queryOptions, withData, }: FetchFilesProps<TData>): {
|
|
23
|
+
query: import("@tanstack/react-query").UseInfiniteQueryResult<TData, Error>;
|
|
57
24
|
queryKey: unknown[];
|
|
58
25
|
};
|
|
59
|
-
export {};
|
|
60
26
|
//# sourceMappingURL=useFetchFiles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchFiles.d.ts","sourceRoot":"","sources":["../../../src/hooks/file/useFetchFiles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFetchFiles.d.ts","sourceRoot":"","sources":["../../../src/hooks/file/useFetchFiles.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,KAAK,EACR,kBAAkB,EAClB,cAAc,EACd,SAAS,EAEZ,MAAM,qBAAqB,CAAC;AAO7B,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AAE7D,qEAAqE;AACrE,MAAM,MAAM,UAAU,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAErD,MAAM,MAAM,eAAe,CAAC,KAAK,GAAG,WAAW,EAAE,IAAI,cAAc,GAC/D,kBAAkB,CAAC,WAAW,EAAE,KAAK,EAAE,gBAAgB,CAAC,GACxD,aAAa,CAAC;AAqBlB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,GAAG,WAAW,EAAE,EAAE,EACjD,OAAY,EACZ,KAAU,EACV,UAAe,EACf,QAAa,EACb,MAAM,EACN,aAAqB,EACrB,YAAY,EACZ,QAAgB,GACnB,EAAE,eAAe,CAAC,KAAK,CAAC;;;EA2CxB"}
|
|
@@ -1,84 +1,68 @@
|
|
|
1
1
|
import { useAxios } from "../useAxios.js";
|
|
2
|
-
import {
|
|
2
|
+
import { useEntityInfiniteQuery } from "../useEntityInfiniteQuery.js";
|
|
3
|
+
import { buildQueryKey, buildQueryObject, hasWorkspaceFilter, missingWorkspaceError } from "../../api/entityQuery.js";
|
|
3
4
|
import { listFiles } from "../../api/file.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { withoutData } from "./fileData.js";
|
|
6
|
+
import { useCallback } from "react";
|
|
6
7
|
//#region src/hooks/file/useFetchFiles.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/** What leaves the content out of a list: the JSON query returns `data` in full otherwise. */
|
|
9
|
+
var WITHOUT_DATA_PROJECTION = "-data";
|
|
10
|
+
/**
|
|
11
|
+
* The projection a list read sends. The content is left out unless asked for: alone when the app
|
|
12
|
+
* gave no projection, and added to one that only excludes fields. A projection that includes
|
|
13
|
+
* fields is sent as given, since mixing an inclusion with an exclusion is a 500; it then decides
|
|
14
|
+
* itself whether `data` is read.
|
|
15
|
+
*/
|
|
16
|
+
var projectionToSend = (projection, withData) => {
|
|
17
|
+
if (withData) return projection;
|
|
18
|
+
const fields = typeof projection === "string" ? [projection].filter(Boolean) : projection;
|
|
19
|
+
if (fields.length === 0) return WITHOUT_DATA_PROJECTION;
|
|
20
|
+
if (!fields.every((field) => field.startsWith("-")) || fields.includes(WITHOUT_DATA_PROJECTION)) return projection;
|
|
21
|
+
return [...fields, WITHOUT_DATA_PROJECTION];
|
|
11
22
|
};
|
|
12
23
|
/**
|
|
13
24
|
* useFetchFiles
|
|
14
25
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* - `query.data` returns a flat `EveryskFile[]` (all pages merged).
|
|
23
|
-
*
|
|
24
|
-
* Parameters (FetchInfiniteFileProps):
|
|
25
|
-
* @param {FilterClause[]} [filters=[]]
|
|
26
|
-
* Filters applied to every page request. Must include a `workspace` filter.
|
|
27
|
-
*
|
|
28
|
-
* @param {string[]} [order=[]]
|
|
29
|
-
* Sorting applied to every page request.
|
|
30
|
-
*
|
|
31
|
-
* @param {string} [projection=""]
|
|
32
|
-
* Single field to project: `"field"` returns only that field (others come back null),
|
|
33
|
-
* `"-field"` returns every field except that one. One field only — lists 500. Omitted when empty.
|
|
34
|
-
*
|
|
35
|
-
* @param {number} [pageSize=10]
|
|
36
|
-
* Number of files to fetch per page.
|
|
37
|
-
*
|
|
38
|
-
* @param {InfiniteOptions<EveryskFile[]>} [queryOptions]
|
|
39
|
-
* TanStack Query options passed through to `useInfiniteQuery`
|
|
40
|
-
* (e.g., enabled, staleTime, gcTime, etc.).
|
|
41
|
-
*
|
|
42
|
-
* Returns:
|
|
43
|
-
* @returns {object}
|
|
44
|
-
* - `query`: the full `useInfiniteQuery` result (data, isLoading, hasNextPage, fetchNextPage, etc.)
|
|
45
|
-
* - `queryKey`: the cache key used by React Query
|
|
46
|
-
*
|
|
47
|
-
* Example:
|
|
48
|
-
* ```ts
|
|
49
|
-
* const { query } = useFetchFiles({
|
|
50
|
-
* filters: [{ field: "workspace", value: "ws-1" }],
|
|
51
|
-
* pageSize: 20,
|
|
52
|
-
* });
|
|
26
|
+
* Lists files with cursor pagination; `query.data` is every loaded page merged, or whatever
|
|
27
|
+
* `select` makes of it. Paging, `select`, `fetchAllPages` and the missing-workspace error
|
|
28
|
+
* behave as in `useFetchDatastores`. The files come without their content unless `withData`
|
|
29
|
+
* asks for it: show or download each through its `url`. The exclusion of `data` is added to a
|
|
30
|
+
* `projection` of the app's own that only excludes fields; one that includes fields is sent as
|
|
31
|
+
* given (see `projectionToSend`). Either way the content is left out of what the hook returns
|
|
32
|
+
* unless `withData` asks for it.
|
|
53
33
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
34
|
+
* @param {FetchFilesProps} props - Filters (one must be `workspace`), order, projection,
|
|
35
|
+
* page size, `withData`, `select`, `fetchAllPages` and TanStack `queryOptions`.
|
|
36
|
+
* @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.
|
|
57
37
|
*/
|
|
58
|
-
function useFetchFiles({ filters = [], order = [], projection = "", pageSize = 10, queryOptions }) {
|
|
38
|
+
function useFetchFiles({ filters = [], order = [], projection = "", pageSize = 10, select, fetchAllPages = false, queryOptions, withData = false }) {
|
|
59
39
|
const { api } = useAxios();
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
40
|
+
const sentProjection = projectionToSend(projection, withData);
|
|
41
|
+
const queryKey = buildQueryKey(["files"], filters, {
|
|
42
|
+
order,
|
|
43
|
+
projection: sentProjection,
|
|
44
|
+
pageSize,
|
|
45
|
+
fetchAllPages
|
|
46
|
+
});
|
|
47
|
+
const selectFiles = useCallback((files) => {
|
|
48
|
+
const visible = withData ? files : files.map(withoutData);
|
|
49
|
+
return select ? select(visible) : visible;
|
|
50
|
+
}, [withData, select]);
|
|
65
51
|
return {
|
|
66
|
-
query:
|
|
52
|
+
query: useEntityInfiniteQuery({
|
|
67
53
|
queryKey,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
select: (data) => data.pages.flatMap((p) => p.files),
|
|
81
|
-
...mergedQueryOptions
|
|
54
|
+
itemsKey: "files",
|
|
55
|
+
fetchPage: (pageToken, signal) => listFiles(api, buildQueryObject({
|
|
56
|
+
filters,
|
|
57
|
+
order,
|
|
58
|
+
projection: sentProjection,
|
|
59
|
+
pageSize,
|
|
60
|
+
pageToken
|
|
61
|
+
}), signal),
|
|
62
|
+
select: selectFiles,
|
|
63
|
+
fetchAllPages,
|
|
64
|
+
configError: hasWorkspaceFilter(filters) ? void 0 : missingWorkspaceError("useFetchFiles"),
|
|
65
|
+
queryOptions
|
|
82
66
|
}),
|
|
83
67
|
queryKey
|
|
84
68
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchFiles.js","names":[],"sources":["../../../src/hooks/file/useFetchFiles.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useFetchFiles.js","names":[],"sources":["../../../src/hooks/file/useFetchFiles.ts"],"sourcesContent":["import { useCallback } from \"react\";\n\nimport { useAxios } from \"@/hooks/useAxios\";\nimport { useEntityInfiniteQuery } from \"@/hooks/useEntityInfiniteQuery\";\nimport { listFiles } from \"@/api/file\";\nimport type { EveryskFile, FileListResponse } from \"@/types/file\";\nimport type {\n FetchEntitiesProps,\n ListQueryProps,\n ListCache,\n Projection,\n} from \"@/types/entityQuery\";\nimport {\n buildQueryKey,\n buildQueryObject,\n hasWorkspaceFilter,\n missingWorkspaceError,\n} from \"@/api/entityQuery\";\nimport { withoutData, type FileDataProps } from \"./fileData\";\n\n/** The query cache of `useFetchFiles`, for typing `setQueryData`. */\nexport type FilesCache = ListCache<FileListResponse>;\n\nexport type FetchFilesProps<TData = EveryskFile[]> = ListQueryProps &\n FetchEntitiesProps<EveryskFile, TData, FileListResponse> &\n FileDataProps;\n\n/** What leaves the content out of a list: the JSON query returns `data` in full otherwise. */\nconst WITHOUT_DATA_PROJECTION = \"-data\";\n\n/**\n * The projection a list read sends. The content is left out unless asked for: alone when the app\n * gave no projection, and added to one that only excludes fields. A projection that includes\n * fields is sent as given, since mixing an inclusion with an exclusion is a 500; it then decides\n * itself whether `data` is read.\n */\nconst projectionToSend = (projection: Projection, withData: boolean): Projection => {\n if (withData) return projection;\n\n const fields = typeof projection === \"string\" ? [projection].filter(Boolean) : projection;\n if (fields.length === 0) return WITHOUT_DATA_PROJECTION;\n if (!fields.every((field) => field.startsWith(\"-\")) || fields.includes(WITHOUT_DATA_PROJECTION))\n return projection;\n return [...fields, WITHOUT_DATA_PROJECTION];\n};\n\n/**\n * useFetchFiles\n *\n * Lists files with cursor pagination; `query.data` is every loaded page merged, or whatever\n * `select` makes of it. Paging, `select`, `fetchAllPages` and the missing-workspace error\n * behave as in `useFetchDatastores`. The files come without their content unless `withData`\n * asks for it: show or download each through its `url`. The exclusion of `data` is added to a\n * `projection` of the app's own that only excludes fields; one that includes fields is sent as\n * given (see `projectionToSend`). Either way the content is left out of what the hook returns\n * unless `withData` asks for it.\n *\n * @param {FetchFilesProps} props - Filters (one must be `workspace`), order, projection,\n * page size, `withData`, `select`, `fetchAllPages` and TanStack `queryOptions`.\n * @returns {object} `query` (the `useInfiniteQuery` result) and `queryKey`.\n */\nexport function useFetchFiles<TData = EveryskFile[]>({\n filters = [],\n order = [],\n projection = \"\",\n pageSize = 10,\n select,\n fetchAllPages = false,\n queryOptions,\n withData = false,\n}: FetchFilesProps<TData>) {\n const { api } = useAxios();\n const sentProjection = projectionToSend(projection, withData);\n\n const queryKey = buildQueryKey([\"files\"], filters, {\n order,\n projection: sentProjection,\n pageSize,\n fetchAllPages,\n });\n\n const selectFiles = useCallback(\n (files: EveryskFile[]): TData => {\n const visible = withData ? files : files.map(withoutData);\n return select ? select(visible) : (visible as TData);\n },\n [withData, select],\n );\n\n const query = useEntityInfiniteQuery<FileListResponse, \"files\", TData>({\n queryKey,\n itemsKey: \"files\",\n fetchPage: (pageToken, signal) =>\n listFiles(\n api,\n buildQueryObject({\n filters,\n order,\n projection: sentProjection,\n pageSize,\n pageToken,\n }),\n signal,\n ),\n select: selectFiles,\n fetchAllPages,\n configError: hasWorkspaceFilter(filters)\n ? undefined\n : missingWorkspaceError(\"useFetchFiles\"),\n queryOptions,\n });\n\n return { query, queryKey };\n}\n"],"mappings":";;;;;;;;AA4BA,IAAM,0BAA0B;;;;;;;AAQhC,IAAM,oBAAoB,YAAwB,aAAkC;CAChF,IAAI,UAAU,OAAO;CAErB,MAAM,SAAS,OAAO,eAAe,WAAW,CAAC,UAAU,CAAC,CAAC,OAAO,OAAO,IAAI;CAC/E,IAAI,OAAO,WAAW,GAAG,OAAO;CAChC,IAAI,CAAC,OAAO,OAAO,UAAU,MAAM,WAAW,GAAG,CAAC,KAAK,OAAO,SAAS,uBAAuB,GAC1F,OAAO;CACX,OAAO,CAAC,GAAG,QAAQ,uBAAuB;AAC9C;;;;;;;;;;;;;;;;AAiBA,SAAgB,cAAqC,EACjD,UAAU,CAAC,GACX,QAAQ,CAAC,GACT,aAAa,IACb,WAAW,IACX,QACA,gBAAgB,OAChB,cACA,WAAW,SACY;CACvB,MAAM,EAAE,QAAQ,SAAS;CACzB,MAAM,iBAAiB,iBAAiB,YAAY,QAAQ;CAE5D,MAAM,WAAW,cAAc,CAAC,OAAO,GAAG,SAAS;EAC/C;EACA,YAAY;EACZ;EACA;CACJ,CAAC;CAED,MAAM,cAAc,aACf,UAAgC;EAC7B,MAAM,UAAU,WAAW,QAAQ,MAAM,IAAI,WAAW;EACxD,OAAO,SAAS,OAAO,OAAO,IAAK;CACvC,GACA,CAAC,UAAU,MAAM,CACrB;CAyBA,OAAO;EAAE,OAvBK,uBAAyD;GACnE;GACA,UAAU;GACV,YAAY,WAAW,WACnB,UACI,KACA,iBAAiB;IACb;IACA;IACA,YAAY;IACZ;IACA;GACJ,CAAC,GACD,MACJ;GACJ,QAAQ;GACR;GACA,aAAa,mBAAmB,OAAO,IACjC,KAAA,IACA,sBAAsB,eAAe;GAC3C;EACJ,CAES;EAAO;CAAS;AAC7B"}
|
|
@@ -34,7 +34,8 @@ type UseFileMutationsProps = {
|
|
|
34
34
|
*
|
|
35
35
|
* - EveryskFile content (`data`):
|
|
36
36
|
* - When creating/updating a file, the file content must be provided in `data` as a Base64-encoded string.
|
|
37
|
-
* - Send only the raw Base64 content (do not include a data URL prefix like `data:<mime>;base64,`)
|
|
37
|
+
* - Send only the raw Base64 content (do not include a data URL prefix like `data:<mime>;base64,`):
|
|
38
|
+
* `fileToBase64(file)` gives it from a `File`, and a data URL is refused before the request
|
|
38
39
|
* - `content_type` should match the file MIME type (e.g., "text/csv", "application/pdf").
|
|
39
40
|
*
|
|
40
41
|
* Parameters (UseFileMutationsProps):
|
|
@@ -51,19 +52,19 @@ type UseFileMutationsProps = {
|
|
|
51
52
|
* - `create`:
|
|
52
53
|
* - mutationFn: `createFile(api, data)`
|
|
53
54
|
* - variables: `{ data: Partial<EveryskFile> }`
|
|
54
|
-
* - success message: "
|
|
55
|
+
* - success message: "File created successfully."
|
|
55
56
|
* - error message: "Unable to create the file. Please try again." (fallback)
|
|
56
57
|
*
|
|
57
58
|
* - `update`:
|
|
58
59
|
* - mutationFn: `updateFile(api, id, data)`
|
|
59
60
|
* - variables: `{ id: string; data: Partial<EveryskFile> }`
|
|
60
|
-
* - success message: "
|
|
61
|
+
* - success message: "File updated successfully."
|
|
61
62
|
* - error message: "Unable to update the file. Please try again." (fallback)
|
|
62
63
|
*
|
|
63
64
|
* - `remove`:
|
|
64
65
|
* - mutationFn: `deleteFile(api, id, workspace)`
|
|
65
66
|
* - variables: `{ id: string; workspace: string }`
|
|
66
|
-
* - success message: "
|
|
67
|
+
* - success message: "File deleted successfully."
|
|
67
68
|
* - error message: "Unable to delete the file. Please try again." (fallback)
|
|
68
69
|
*
|
|
69
70
|
* Return value:
|
|
@@ -71,7 +72,7 @@ type UseFileMutationsProps = {
|
|
|
71
72
|
* Returns an object with the three TanStack Query mutation results:
|
|
72
73
|
* - `create`: UseMutationResult<EveryskFile, Error, CreateFileProps, unknown>
|
|
73
74
|
* - `update`: UseMutationResult<EveryskFile, Error, UpdateFileProps, unknown>
|
|
74
|
-
* - `remove`: UseMutationResult<
|
|
75
|
+
* - `remove`: UseMutationResult<DeletedEntity, Error, DeleteFileProps, unknown>
|
|
75
76
|
*
|
|
76
77
|
* Each mutation includes standard TanStack Query helpers:
|
|
77
78
|
* - `mutate(variables, options?)`
|
|
@@ -153,9 +154,9 @@ type UseFileMutationsProps = {
|
|
|
153
154
|
* ```
|
|
154
155
|
*/
|
|
155
156
|
export declare const useFileMutations: ({ queryKey }: UseFileMutationsProps) => {
|
|
156
|
-
create: import("@tanstack/react-query").UseMutationResult<EveryskFile,
|
|
157
|
-
update: import("@tanstack/react-query").UseMutationResult<EveryskFile,
|
|
158
|
-
remove: import("@tanstack/react-query").UseMutationResult<import("../..").
|
|
157
|
+
create: import("@tanstack/react-query").UseMutationResult<EveryskFile, Error, CreateFileProps, unknown>;
|
|
158
|
+
update: import("@tanstack/react-query").UseMutationResult<EveryskFile, Error, UpdateFileProps, unknown>;
|
|
159
|
+
remove: import("@tanstack/react-query").UseMutationResult<import("../..").DeletedEntity, Error, DeleteFileProps, unknown>;
|
|
159
160
|
};
|
|
160
161
|
export {};
|
|
161
162
|
//# sourceMappingURL=useFileMutations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFileMutations.d.ts","sourceRoot":"","sources":["../../../src/hooks/file/useFileMutations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFileMutations.d.ts","sourceRoot":"","sources":["../../../src/hooks/file/useFileMutations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,KAAK,eAAe,GAAG;IACnB,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CAC9B,CAAC;AAEF,KAAK,eAAe,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CAC9B,CAAC;AAEF,KAAK,eAAe,GAAG;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IACzB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;CACxB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2IG;AAEH,eAAO,MAAM,gBAAgB,GAAI,cAAc,qBAAqB;;;;CAyBnE,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 { createFile, deleteFile, updateFile } from "../../api/file.js";
|
|
4
|
-
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
5
4
|
//#region src/hooks/file/useFileMutations.ts
|
|
6
|
-
var getErrorMessage = (err, fallback) => err instanceof Error && err.message ? err.message : fallback;
|
|
7
5
|
/**
|
|
8
6
|
* useFileMutations
|
|
9
7
|
*
|
|
@@ -22,10 +20,11 @@ var getErrorMessage = (err, fallback) => err instanceof Error && err.message ? e
|
|
|
22
20
|
* mutations and show alerts, but it will NOT invalidate any cached queries.
|
|
23
21
|
* - `remove` requires a `workspace` parameter because the underlying API helper `deleteFile(api, id, workspace)`
|
|
24
22
|
* expects it as a query param.
|
|
25
|
-
*
|
|
23
|
+
*
|
|
26
24
|
* - EveryskFile content (`data`):
|
|
27
25
|
* - When creating/updating a file, the file content must be provided in `data` as a Base64-encoded string.
|
|
28
|
-
* - Send only the raw Base64 content (do not include a data URL prefix like `data:<mime>;base64,`)
|
|
26
|
+
* - Send only the raw Base64 content (do not include a data URL prefix like `data:<mime>;base64,`):
|
|
27
|
+
* `fileToBase64(file)` gives it from a `File`, and a data URL is refused before the request
|
|
29
28
|
* - `content_type` should match the file MIME type (e.g., "text/csv", "application/pdf").
|
|
30
29
|
*
|
|
31
30
|
* Parameters (UseFileMutationsProps):
|
|
@@ -42,19 +41,19 @@ var getErrorMessage = (err, fallback) => err instanceof Error && err.message ? e
|
|
|
42
41
|
* - `create`:
|
|
43
42
|
* - mutationFn: `createFile(api, data)`
|
|
44
43
|
* - variables: `{ data: Partial<EveryskFile> }`
|
|
45
|
-
* - success message: "
|
|
44
|
+
* - success message: "File created successfully."
|
|
46
45
|
* - error message: "Unable to create the file. Please try again." (fallback)
|
|
47
46
|
*
|
|
48
47
|
* - `update`:
|
|
49
48
|
* - mutationFn: `updateFile(api, id, data)`
|
|
50
49
|
* - variables: `{ id: string; data: Partial<EveryskFile> }`
|
|
51
|
-
* - success message: "
|
|
50
|
+
* - success message: "File updated successfully."
|
|
52
51
|
* - error message: "Unable to update the file. Please try again." (fallback)
|
|
53
52
|
*
|
|
54
53
|
* - `remove`:
|
|
55
54
|
* - mutationFn: `deleteFile(api, id, workspace)`
|
|
56
55
|
* - variables: `{ id: string; workspace: string }`
|
|
57
|
-
* - success message: "
|
|
56
|
+
* - success message: "File deleted successfully."
|
|
58
57
|
* - error message: "Unable to delete the file. Please try again." (fallback)
|
|
59
58
|
*
|
|
60
59
|
* Return value:
|
|
@@ -62,7 +61,7 @@ var getErrorMessage = (err, fallback) => err instanceof Error && err.message ? e
|
|
|
62
61
|
* Returns an object with the three TanStack Query mutation results:
|
|
63
62
|
* - `create`: UseMutationResult<EveryskFile, Error, CreateFileProps, unknown>
|
|
64
63
|
* - `update`: UseMutationResult<EveryskFile, Error, UpdateFileProps, unknown>
|
|
65
|
-
* - `remove`: UseMutationResult<
|
|
64
|
+
* - `remove`: UseMutationResult<DeletedEntity, Error, DeleteFileProps, unknown>
|
|
66
65
|
*
|
|
67
66
|
* Each mutation includes standard TanStack Query helpers:
|
|
68
67
|
* - `mutate(variables, options?)`
|
|
@@ -145,60 +144,24 @@ var getErrorMessage = (err, fallback) => err instanceof Error && err.message ? e
|
|
|
145
144
|
*/
|
|
146
145
|
var useFileMutations = ({ queryKey }) => {
|
|
147
146
|
const { api } = useAxios();
|
|
148
|
-
const { showAlert } = useAppAlert();
|
|
149
|
-
const queryClient = useQueryClient();
|
|
150
|
-
const invalidate = async () => {
|
|
151
|
-
if (!queryKey?.length) return;
|
|
152
|
-
await queryClient.invalidateQueries({ queryKey });
|
|
153
|
-
};
|
|
154
147
|
return {
|
|
155
|
-
create:
|
|
156
|
-
mutationFn:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
severity: "success",
|
|
161
|
-
message: "EveryskFile created successfully."
|
|
162
|
-
});
|
|
163
|
-
},
|
|
164
|
-
onError: (err) => {
|
|
165
|
-
showAlert({
|
|
166
|
-
severity: "error",
|
|
167
|
-
message: getErrorMessage(err, "Unable to create the file. Please try again.")
|
|
168
|
-
});
|
|
169
|
-
}
|
|
148
|
+
create: useEntityMutation({
|
|
149
|
+
mutationFn: ({ data }) => createFile(api, data),
|
|
150
|
+
queryKey,
|
|
151
|
+
successMessage: "File created successfully.",
|
|
152
|
+
errorMessage: "Unable to create the file. Please try again."
|
|
170
153
|
}),
|
|
171
|
-
update:
|
|
172
|
-
mutationFn:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
severity: "success",
|
|
177
|
-
message: "EveryskFile updated successfully."
|
|
178
|
-
});
|
|
179
|
-
},
|
|
180
|
-
onError: (err) => {
|
|
181
|
-
showAlert({
|
|
182
|
-
severity: "error",
|
|
183
|
-
message: getErrorMessage(err, "Unable to update the file. Please try again.")
|
|
184
|
-
});
|
|
185
|
-
}
|
|
154
|
+
update: useEntityMutation({
|
|
155
|
+
mutationFn: ({ id, data }) => updateFile(api, id, data),
|
|
156
|
+
queryKey,
|
|
157
|
+
successMessage: "File updated successfully.",
|
|
158
|
+
errorMessage: "Unable to update the file. Please try again."
|
|
186
159
|
}),
|
|
187
|
-
remove:
|
|
188
|
-
mutationFn:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
severity: "success",
|
|
193
|
-
message: "EveryskFile deleted successfully."
|
|
194
|
-
});
|
|
195
|
-
},
|
|
196
|
-
onError: (err) => {
|
|
197
|
-
showAlert({
|
|
198
|
-
severity: "error",
|
|
199
|
-
message: getErrorMessage(err, "Unable to delete the file. Please try again.")
|
|
200
|
-
});
|
|
201
|
-
}
|
|
160
|
+
remove: useEntityMutation({
|
|
161
|
+
mutationFn: ({ id, workspace }) => deleteFile(api, id, workspace),
|
|
162
|
+
queryKey,
|
|
163
|
+
successMessage: "File deleted successfully.",
|
|
164
|
+
errorMessage: "Unable to delete the file. Please try again."
|
|
202
165
|
})
|
|
203
166
|
};
|
|
204
167
|
};
|