forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatasets.ts
More file actions
173 lines (148 loc) · 5.07 KB
/
datasets.ts
File metadata and controls
173 lines (148 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import axios from "axios";
import {
type components,
type DatasetTextContentDetails,
GalaxyApi,
type GalaxyApiPaths,
type HDADetailed,
type HDASummary,
} from "@/api";
import { withPrefix } from "@/utils/redirect";
import { rethrowSimple } from "@/utils/simple-error";
export interface LoadDatasetsOptions {
limit?: number;
offset?: number;
sortBy?: string;
sortDesc?: boolean;
search?: string;
}
export interface LoadDatasetsResult {
data: HDASummary[];
totalMatches: number;
}
export async function loadDatasets(options: LoadDatasetsOptions): Promise<LoadDatasetsResult> {
const { limit = 24, offset = 0, sortBy = "update_time", sortDesc = true, search = "" } = options;
const {
response,
data: datasets,
error,
} = await GalaxyApi().GET("/api/datasets", {
params: {
query: {
q: search ? ["name-contains"] : undefined,
qv: search ? [search] : undefined,
limit,
offset,
order: `${sortBy}${sortDesc ? "-dsc" : "-asc"}`,
view: "summary",
},
},
});
if (error) {
rethrowSimple(error);
}
const totalMatches = parseInt(response.headers.get("total_matches") ?? "0", 10) || 0;
const data = datasets as unknown as HDASummary[];
return { data, totalMatches };
}
export async function fetchDatasetTextContentDetails(params: { id: string }): Promise<DatasetTextContentDetails> {
const { data, error } = await GalaxyApi().GET("/api/datasets/{dataset_id}/get_content_as_text", {
params: {
path: {
dataset_id: params.id,
},
},
});
if (error) {
rethrowSimple(error);
}
return data;
}
export async function fetchDatasetDetails(params: { id: string }, view: string = "detailed"): Promise<HDADetailed> {
const { data, error } = await GalaxyApi().GET("/api/datasets/{dataset_id}", {
params: {
path: {
dataset_id: params.id,
},
query: { view },
},
});
if (error) {
rethrowSimple(error);
}
return data as HDADetailed;
}
export async function undeleteDataset(datasetId: string) {
const { data, error } = await GalaxyApi().PUT("/api/datasets/{dataset_id}", {
params: {
path: { dataset_id: datasetId },
},
body: {
deleted: false,
},
});
if (error) {
rethrowSimple(error);
}
return data;
}
export async function deleteDataset(datasetId: string, purge: boolean = false) {
const { data, error } = await GalaxyApi().DELETE("/api/datasets/{dataset_id}", {
params: {
path: { dataset_id: datasetId },
query: { purge },
},
});
if (error) {
rethrowSimple(error);
}
return data;
}
export async function purgeDataset(datasetId: string) {
return deleteDataset(datasetId, true);
}
type CopyDatasetParamsType = GalaxyApiPaths["/api/histories/{history_id}/contents/{type}s"]["post"]["parameters"];
type CopyDatasetBodyType = components["schemas"]["CreateHistoryContentPayload"];
export async function copyDataset(
datasetId: CopyDatasetBodyType["content"],
historyId: CopyDatasetParamsType["path"]["history_id"],
type: CopyDatasetParamsType["path"]["type"] = "dataset",
source: CopyDatasetBodyType["source"] = "hda",
) {
const { data, error } = await GalaxyApi().POST("/api/histories/{history_id}/contents/{type}s", {
params: {
path: { history_id: historyId, type },
},
body: {
source,
content: datasetId,
type,
copy_elements: true,
// TODO: Investigate. These should be optional, but the API requires explicit null values?
fields: null,
hide_source_items: null,
instance_type: null,
},
});
if (error) {
rethrowSimple(error);
}
return data;
}
export function getCompositeDatasetLink(historyDatasetId: string, path: string) {
return withPrefix(`/api/datasets/${historyDatasetId}/display?filename=${path}`);
}
export type DatasetExtraFiles = components["schemas"]["DatasetExtraFiles"];
export async function fetchDatasetAttributes(datasetId: string) {
const { data } = await axios.get(withPrefix(`/dataset/get_edit?dataset_id=${datasetId}`));
return data;
}
export type HistoryContentType = components["schemas"]["HistoryContentType"];
export type HistoryContentSource = components["schemas"]["HistoryContentSource"];
/** Dataset state constants */
// Non-terminal dataset states (dataset is still being processed)
export const NON_TERMINAL_DATASET_STATES = ["new", "upload", "queued", "running", "setting_metadata"];
// Error dataset states (dataset failed processing)
export const ERROR_DATASET_STATES = ["error", "failed_metadata"];
// Terminal dataset states (dataset processing is complete)
export const TERMINAL_DATASET_STATES = ["ok", "empty", "deferred", "discarded", "paused"].concat(ERROR_DATASET_STATES);