Skip to content

Commit

Permalink
Merge pull request #50 from molgenis/feat/bam
Browse files Browse the repository at this point in the history
Introduce Metadata.urls
  • Loading branch information
marikaris authored Mar 30, 2021
2 parents fe6327c + 97a865f commit 751464c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@molgenis/vip-report-api",
"version": "0.8.1",
"version": "1.0.0",
"description": "Report API for Variant Call Format (VCF) Report Templates",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ beforeEach(() => {
info: [],
format: [],
},
urls: {},
},
data: {
samples: {
Expand Down Expand Up @@ -166,6 +167,7 @@ test('getMeta', async () => {
info: [],
format: [],
},
urls: {},
});
});

Expand Down
36 changes: 30 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Metadata {
app: AppMetadata;
htsFile: HtsFileMetadata;
records: RecordsMetadata;
urls: UrlsMetadata;
}

export interface Data {
Expand Down Expand Up @@ -84,6 +85,15 @@ export interface RecordsMetadata {
format: FormatMetadata[];
}

export interface UrlsMetadata {
reference?: string;
referenceAccessToken?: string;
alignment?: string;
alignmentAccessToken?: string;
variant?: string;
variantAccessToken?: string;
}

export interface CompoundMetadata {
id: string;
number?: NumberMetadata;
Expand Down Expand Up @@ -183,9 +193,7 @@ export default class Api {
}

getMeta(): Promise<Metadata> {
return new Promise((resolve) => {
resolve(this.reportData.metadata);
});
return Promise.resolve(this.reportData.metadata);
}

get<T extends Resource>(resource: string, params: Params = {}): Promise<PagedItems<T>> {
Expand Down Expand Up @@ -257,17 +265,33 @@ function compareAsc(a: unknown, b: unknown) {
} else if (b === null) {
return -1;
} else if (typeof a === 'number' && typeof b === 'number') {
return a - b;
return compareAscNumber(a, b);
} else if (typeof a === 'string' && typeof b === 'string') {
return a.toUpperCase().localeCompare(b.toUpperCase());
return compareAscString(a, b);
} else if (typeof a === 'boolean' && typeof b === 'boolean') {
return a === b ? 0 : a ? -1 : 1;
return compareAscBoolean(a, b);
} else {
const type = typeof a;
throw new Error(`can't compare values of type '${type}'. consider providing a custom compare function.`);
}
}

function compareAscNumber(a: number, b: number) {
return a - b;
}

function compareAscString(a: string, b: string) {
return a.toUpperCase().localeCompare(b.toUpperCase());
}

function compareAscBoolean(a: boolean, b: boolean) {
if (a === b) {
return 0;
} else {
return a ? -1 : 1;
}
}

function compareDesc(a: unknown, b: unknown) {
return compareAsc(b, a);
}
Expand Down

0 comments on commit 751464c

Please sign in to comment.