Skip to content

Commit

Permalink
fix: api/annonars type GeneInfoResult (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Feb 1, 2024
1 parent 7bd9dfd commit 4476c13
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/api/annonars/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 } }))
)
})

Expand Down
3 changes: 2 additions & 1 deletion src/api/annonars/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/api/annonars/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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.
*/
Expand Down

0 comments on commit 4476c13

Please sign in to comment.