-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
15 changed files
with
197 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
import createFetchMock from 'vitest-fetch-mock' | ||
|
||
import { DottyClient, type DottyResponse } from '@/api/dotty' | ||
|
||
const fetchMocker = createFetchMock(vi) | ||
|
||
describe.concurrent('DottyClient', () => { | ||
beforeEach(() => { | ||
fetchMocker.enableMocks() | ||
fetchMocker.resetMocks() | ||
}) | ||
|
||
it('should resolve to SPDI successfully', async () => { | ||
const mockData: DottyResponse = { | ||
spdi: { | ||
assembly: 'GRCh38', | ||
contig: '13', | ||
pos: 32319283, | ||
reference_deleted: 'C', | ||
alternate_inserted: 'A' | ||
} | ||
} | ||
fetchMocker.mockResponseOnce(JSON.stringify(mockData), { status: 200 }) | ||
|
||
const client = new DottyClient() | ||
const result = await client.toSpdi('NM_000059.3:c.274G>A') | ||
|
||
expect(result).toEqual(mockData) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,6 @@ | ||
export const API_INTERNAL_BASE_PREFIX = '/internal/' | ||
// import.meta.env.MODE == 'development' ? '//localhost:8080/internal/' : '/internal/' | ||
|
||
export const API_INTERNAL_BASE_PREFIX_ANNONARS = '/internal/proxy/annonars' | ||
// import.meta.env.MODE == 'development' | ||
// ? `//localhost:8080/internal/proxy/annonars` | ||
// : '/internal/proxy/annonars' | ||
|
||
export const API_INTERNAL_BASE_PREFIX_MEHARI = '/internal/proxy/mehari' | ||
// import.meta.env.MODE == 'development' | ||
// ? '//localhost:8080/internal/proxy/mehari' | ||
// : '/internal/proxy/mehari' | ||
|
||
export const API_INTERNAL_BASE_PREFIX_NGINX = '/internal/proxy/nginx' | ||
// import.meta.env.MODE == 'development' | ||
// ? '//localhost:8080/internal/proxy/proxy/nginx' | ||
// : '/internal/proxy/nginx' | ||
|
||
export const API_INTERNAL_BASE_PREFIX_DOTTY = '/internal/proxy/dotty' | ||
export const API_V1_BASE_PREFIX = '/api/v1/' | ||
// import.meta.env.MODE == 'development' ? '//localhost:8080/api/v1/' : '/api/v1/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { API_INTERNAL_BASE_PREFIX_DOTTY } from '@/api/common' | ||
|
||
const API_BASE_URL = `${API_INTERNAL_BASE_PREFIX_DOTTY}/` | ||
|
||
/** SPDI representation as returned by dotty. */ | ||
export interface Spdi { | ||
/** Assembly version. */ | ||
assembly: 'GRCh37' | 'GRCh38' | ||
/** Contig. */ | ||
contig: string | ||
/** Position. */ | ||
pos: number | ||
/** Deleted sequence. */ | ||
reference_deleted: string | ||
/** Inserted sequence. */ | ||
alternate_inserted: string | ||
} | ||
|
||
/** Response of a dotto query */ | ||
export interface DottyResponse { | ||
/** SPDI returned by dotty. */ | ||
spdi: Spdi | ||
} | ||
|
||
export class DottyClient { | ||
private apiBaseUrl: string | ||
private csrfToken: string | null | ||
|
||
constructor(apiBaseUrl?: string, csrfToken?: string) { | ||
this.apiBaseUrl = apiBaseUrl ?? API_BASE_URL | ||
this.csrfToken = csrfToken ?? null | ||
} | ||
|
||
async toSpdi(q: String, assembly: 'GRCh37' | 'GRCh38' = 'GRCh38'): Promise<DottyResponse | null> { | ||
const url = `${API_INTERNAL_BASE_PREFIX_DOTTY}/api/v1/to-spdi?q=${q}&assembly=${assembly}` | ||
const response = await fetch(url, { | ||
method: 'GET' | ||
}) | ||
if (response.status == 200) { | ||
return await response.json() | ||
} else { | ||
return null | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.