diff --git a/src/api/annonars/client.spec.ts b/src/api/annonars/client.spec.ts index 6638203..1c99e50 100644 --- a/src/api/annonars/client.spec.ts +++ b/src/api/annonars/client.spec.ts @@ -6,7 +6,12 @@ import createFetchMock from 'vitest-fetch-mock' import { LinearStrucvarImpl, SeqvarImpl } from '../../lib/genomicVars' import { Record as GeneInfoRecord } from '../../pbs/annonars/genes/base' import { AnnonarsClient } from './client' -import { ClinvarSvQueryResponse, GeneSearchResponse, SeqvarInfoResponse } from './types' +import { + ClinvarSvQueryResponse, + GeneInfoResult, + GeneSearchResponse, + SeqvarInfoResponse +} from './types' const geneInfoBrca1Json = JSON.parse( fs.readFileSync( @@ -45,7 +50,7 @@ describe.concurrent('AnnonarsClient.fetchGeneInfo()', () => { // assert: expect(JSON.stringify(result)).toEqual( - JSON.stringify({ genes: { 'HGNC:1100': geneInfoBrca1Json } }) + JSON.stringify(GeneInfoResult.fromJson({ genes: { 'HGNC:1100': geneInfoBrca1Json } })) ) }) diff --git a/src/api/annonars/client.ts b/src/api/annonars/client.ts index dec163f..7ed639d 100644 --- a/src/api/annonars/client.ts +++ b/src/api/annonars/client.ts @@ -41,7 +41,8 @@ export class AnnonarsClient { const response = await fetch(`${this.apiBaseUrl}/genes/info?hgnc_id=${hgncId}`, { method: 'GET' }) - return await response.json() + const responseJson = await response.json() + return GeneInfoResult.fromJson(responseJson) } /** diff --git a/src/api/annonars/types.ts b/src/api/annonars/types.ts index 78e075e..5cb7192 100644 --- a/src/api/annonars/types.ts +++ b/src/api/annonars/types.ts @@ -152,6 +152,13 @@ class GeneSearchResponse$Type { */ export const GeneSearchResponse = new GeneSearchResponse$Type() +/** + * Interface for gene info result as returned by API. + */ +export interface GeneInfoResult$Api { + genes: { [key: string]: GeneInfoRecord } +} + /** * Interface for gene info result. */ @@ -160,6 +167,22 @@ export interface GeneInfoResult { genes: GeneInfoRecord[] } +/** + * Helper class to convert `GeneInfoResult$Api` to `GeneInfoResult`. + */ +class GeneInfoResult$Type { + fromJson(apiResult: GeneInfoResult$Api): GeneInfoResult { + return { + genes: Object.values(apiResult.genes) + } + } +} + +/** + * Helper instance to convert `GeneInfoResult$Api` to `GeneInfoResult`. + */ +export const GeneInfoResult = new GeneInfoResult$Type() + /** * Interface for seqvar info query as returned by API. */