|
1 | | -const TRANSCRIPT_INDICES = { |
2 | | - GRCh37: 'transcripts_grch37', |
3 | | - GRCh38: 'transcripts_grch38', |
| 1 | +import { ReferenceGenome } from '@gnomad/dataset-metadata/metadata' |
| 2 | +import { GetResponse, LimitedElasticClient } from '../elasticsearch' |
| 3 | +import { getFromMultipleIndices } from './helpers/elasticsearch-helpers' |
| 4 | + |
| 5 | +type TranscriptIndex = |
| 6 | + | 'transcripts_grch37' |
| 7 | + | 'transcripts_grch38' |
| 8 | + | 'transcripts_grch38_patched-2025-10-17--18-18' |
| 9 | + |
| 10 | +const TRANSCRIPT_INDICES: Record<ReferenceGenome, TranscriptIndex[]> = { |
| 11 | + GRCh37: ['transcripts_grch37'], |
| 12 | + GRCh38: ['transcripts_grch38', 'transcripts_grch38_patched-2025-10-17--18-18'], |
4 | 13 | } |
5 | 14 |
|
6 | | -export const fetchTranscriptById = async (es: any, transcriptId: any, referenceGenome: any) => { |
7 | | - try { |
8 | | - const response = await es.get({ |
9 | | - // @ts-expect-error TS(7053) FIXME: Element implicitly has an 'any' type because expre... Remove this comment to see the full error message |
10 | | - index: TRANSCRIPT_INDICES[referenceGenome], |
11 | | - type: '_doc', |
12 | | - id: transcriptId, |
13 | | - }) |
| 15 | +export const fetchTranscriptById = async ( |
| 16 | + esClient: LimitedElasticClient, |
| 17 | + transcriptId: string, |
| 18 | + referenceGenome: ReferenceGenome |
| 19 | +) => { |
| 20 | + const indices = TRANSCRIPT_INDICES[referenceGenome] |
| 21 | + const requests = indices.map( |
| 22 | + (index) => |
| 23 | + esClient |
| 24 | + .get({ |
| 25 | + index, |
| 26 | + type: '_doc', |
| 27 | + id: transcriptId, |
| 28 | + }) |
| 29 | + .catch((err) => { |
| 30 | + // meta will not be present if the request times out in the queue before reaching ES |
| 31 | + if (err.meta && err.meta.body.found === false) { |
| 32 | + return null |
| 33 | + } |
| 34 | + throw err |
| 35 | + }) as Promise<GetResponse | null> |
| 36 | + ) |
14 | 37 |
|
15 | | - return response.body._source.value |
16 | | - } catch (err) { |
17 | | - // meta will not be present if the request times out in the queue before reaching ES |
18 | | - // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'. |
19 | | - if (err.meta && err.meta.body.found === false) { |
20 | | - return null |
21 | | - } |
22 | | - throw err |
23 | | - } |
| 38 | + return getFromMultipleIndices(requests) |
24 | 39 | } |
0 commit comments