-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathfetchSingleDatasetAuspice.ts
64 lines (55 loc) · 1.93 KB
/
fetchSingleDatasetAuspice.ts
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
import { isEmpty } from 'lodash'
import { attrStrMaybe, AuspiceTree, Dataset } from 'src/types'
import { removeTrailingSlash } from 'src/io/url'
import { axiosFetch, axiosFetchOrUndefined } from 'src/io/axiosFetch'
export async function fetchSingleDatasetAuspice(datasetJsonUrl_: string) {
const datasetJsonUrl = removeTrailingSlash(datasetJsonUrl_)
const auspiceJson = await axiosFetch<AuspiceTree>(datasetJsonUrl, {
headers: {
Accept: 'application/vnd.nextstrain.dataset.main+json;q=1, application/json;q=0.9, text/plain;q=0.8, */*;q=0.1',
},
})
if (isEmpty(auspiceJson.root_sequence)) {
const sidecar = await axiosFetchOrUndefined<Record<string, string>>(datasetJsonUrl, {
headers: { Accept: 'application/vnd.nextstrain.dataset.root-sequence+json' },
strictAccept: true,
})
if (!isEmpty(sidecar)) {
auspiceJson.root_sequence = sidecar
}
}
const pathogen = auspiceJson.meta.extensions?.nextclade?.pathogen
const name =
attrStrMaybe(pathogen?.attributes, 'name') ??
auspiceJson.meta.title ??
auspiceJson.meta.description ??
datasetJsonUrl
let version = pathogen?.version
if (!version) {
const updatedAt = pathogen?.version?.updatedAt ?? auspiceJson.meta.updated
version = {
tag: updatedAt ?? '',
updatedAt,
}
}
const currentDataset: Dataset = {
path: datasetJsonUrl,
capabilities: {
primers: false,
qc: [],
},
...pathogen,
attributes: {
name,
...pathogen?.attributes,
},
type: 'auspiceJson',
version,
}
const datasets = [currentDataset]
const defaultDataset = currentDataset
const currentDatasetName = currentDataset.path
const defaultDatasetName = currentDatasetName
const defaultDatasetNameFriendly = attrStrMaybe(currentDataset.attributes, 'name') ?? currentDatasetName
return { datasets, defaultDataset, defaultDatasetName, defaultDatasetNameFriendly, currentDataset, auspiceJson }
}