Skip to content

Commit f7ae525

Browse files
committed
fix: typings, imports
1 parent c7cc098 commit f7ae525

File tree

12 files changed

+61
-46
lines changed

12 files changed

+61
-46
lines changed

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
transform: { "\\.ts$": ['ts-jest'] },
3-
setupFilesAfterEnv: ['./jest.setup.js', './jest.setup.redis-mock.js']
4-
};
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"coveralls": "^3.1.0",
3939
"ioredis-mock": "^8.2.2",
4040
"jest": "^26.6.3",
41+
"jest-util": "^26.6.2",
4142
"prettier": "^2.2.1",
4243
"standard-version": "^9.1.1",
4344
"ts-jest": "^26.5.4",

src/batch_edge_query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { StampedLog } from './log_entry';
1010
import { QueryHandlerOptions } from '.';
1111
import QEdge from './query_edge';
1212
import { UnavailableAPITracker } from './types';
13-
import { Record } from '../../api-response-transform/built';
13+
import { Record } from '@biothings-explorer/api-response-transform';
1414

1515
export interface BatchEdgeQueryOptions extends QueryHandlerOptions {
1616
recordHashEdgeAttributes: string[];
@@ -24,7 +24,7 @@ export default class BatchEdgeQueryHandler {
2424
options: QueryHandlerOptions;
2525
resolveOutputIDs: boolean;
2626
qEdges: QEdge | QEdge[];
27-
constructor(metaKG: MetaKG, resolveOutputIDs = true, options: BatchEdgeQueryOptions) {
27+
constructor(metaKG: MetaKG, resolveOutputIDs = true, options?: BatchEdgeQueryOptions) {
2828
this.metaKG = metaKG;
2929
this.subscribers = [];
3030
this.logs = [];

src/graph/knowledge_graph.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export default class KnowledgeGraph {
2626
[edgeID: string]: TrapiKGEdge;
2727
};
2828
kg: TrapiKnowledgeGraph;
29-
apiList: APIDefinition[];
30-
constructor(apiList: APIDefinition[]) {
29+
apiList?: APIDefinition[];
30+
constructor(apiList?: APIDefinition[]) {
3131
this.nodes = {};
3232
this.edges = {};
3333
this.kg = {
@@ -84,7 +84,7 @@ export default class KnowledgeGraph {
8484
for (const key in kgNode.nodeAttributes) {
8585
node.attributes.push({
8686
attribute_type_id: key,
87-
value: kgNode.nodeAttributes[key],
87+
value: kgNode.nodeAttributes[key] as string[],
8888
//value_type_id: 'bts:' + key,
8989
});
9090
}

src/index.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import EdgeManager from './edge_manager';
1111
import _ from 'lodash';
1212
import QEdge2APIEdgeHandler from './qedge2apiedge';
1313
import LogEntry, { StampedLog } from './log_entry';
14-
import { redisClient, getNewRedisClient } from './redis-client';
1514
import { promises as fs } from 'fs';
1615
import { getDescendants } from '@biothings-explorer/node-expansion';
17-
import { getTemplates, supportedLookups } from './inferred_mode/template_lookup';
1816
import { resolveSRI, SRIResolverFailiure } from 'biomedical_id_resolver';
1917
import InferredQueryHandler from './inferred_mode/inferred_mode';
2018
import KGNode from './graph/kg_node';
@@ -32,7 +30,15 @@ import {
3230
import BTEGraph from './graph/graph';
3331
import QEdge from './query_edge';
3432

35-
export { InvalidQueryGraphError, redisClient, getNewRedisClient, LogEntry, getTemplates, supportedLookups };
33+
// Exports for external availability
34+
export * from './types';
35+
export { redisClient, getNewRedisClient } from './redis-client';
36+
export { getTemplates, supportedLookups } from './inferred_mode/template_lookup';
37+
export { default as QEdge } from './query_edge';
38+
export { default as QNode } from './query_node';
39+
export { default as InvalidQueryGraphError } from './exceptions/invalid_query_graph_error';
40+
export { default as LogEntry } from './log_entry';
41+
export * from './qedge2apiedge';
3642

3743
export interface QueryHandlerOptions {
3844
provenanceUsesServiceProvider?: boolean;
@@ -48,7 +54,7 @@ export interface QueryHandlerOptions {
4854
caching?: boolean; // from request url query values
4955
EDGE_ATTRIBUTES_USED_IN_RECORD_HASH?: string[];
5056
}
51-
export class TRAPIQueryHandler {
57+
export default class TRAPIQueryHandler {
5258
logs: StampedLog[];
5359
options: QueryHandlerOptions;
5460
includeReasoner: boolean;
@@ -62,7 +68,12 @@ export class TRAPIQueryHandler {
6268
auxGraphs: TrapiAuxGraphCollection;
6369
finalizedResults: TrapiResult[];
6470
queryGraph: TrapiQueryGraph;
65-
constructor(options = {}, smartAPIPath = undefined, predicatesPath = undefined, includeReasoner = true) {
71+
constructor(
72+
options: QueryHandlerOptions = {},
73+
smartAPIPath: string = undefined,
74+
predicatesPath: string = undefined,
75+
includeReasoner = true,
76+
) {
6677
this.logs = [];
6778
this.options = options;
6879
this.options.provenanceUsesServiceProvider = this.options.smartAPIID || this.options.teamName ? true : false;
@@ -173,8 +184,8 @@ export class TRAPIQueryHandler {
173184
subject,
174185
object,
175186
});
176-
const source = Object.keys(ontologyKnowledgeSourceMapping).find(([prefix]) => {
177-
if (expanded.includes(prefix)) return true;
187+
const source = Object.entries(ontologyKnowledgeSourceMapping).find(([prefix]) => {
188+
return expanded.includes(prefix);
178189
})[1];
179190
subclassEdge.addSource([
180191
{ resource_id: source, resource_role: 'primary_knowledge_source' },
@@ -599,9 +610,9 @@ export class TRAPIQueryHandler {
599610
new LogEntry(
600611
'INFO',
601612
null,
602-
`execution Summary: (${KGNodes}) nodes / (${kgEdges}) edges / (${results}) results; (${resultQueries}/${queries}) queries${
613+
`Execution Summary: (${KGNodes}) nodes / (${kgEdges}) edges / (${results}) results; (${resultQueries}/${queries}) queries${
603614
cached ? ` (${cached} cached qEdges)` : ''
604-
} returned results from(${sources.length}) unique APIs ${sources.length === 1 ? 's' : ''} `,
615+
} returned results from(${sources.length}) unique API${sources.length === 1 ? 's' : ''}`,
605616
).getLog(),
606617
new LogEntry('INFO', null, `APIs: ${sources.join(', ')} `).getLog(),
607618
];
@@ -640,7 +651,7 @@ export class TRAPIQueryHandler {
640651
null,
641652
`The following APIs were unavailable at the time of execution: ${global.missingAPIs
642653
.map((spec) => spec.info.title)
643-
.join(', ')} `,
654+
.join(', ')}`,
644655
).getLog(),
645656
);
646657
}

src/inferred_mode/inferred_mode.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import async from 'async';
55
import biolink from '../biolink';
66
import { getTemplates, MatchedTemplate, TemplateLookup } from './template_lookup';
77
import { scaled_sigmoid, inverse_scaled_sigmoid } from '../results_assembly/score';
8-
import { QueryHandlerOptions, TRAPIQueryHandler } from '..';
8+
import TRAPIQueryHandler, { QueryHandlerOptions } from '../index';
99
import {
1010
CompactQualifiers,
1111
TrapiAuxGraphCollection,
@@ -20,11 +20,12 @@ import {
2020
const debug = Debug('bte:biothings-explorer-trapi:inferred-mode');
2121

2222
export interface CombinedResponse {
23-
workflow: { id: string }[];
23+
description?: string;
24+
workflow?: { id: string }[];
2425
message: {
2526
query_graph: TrapiQueryGraph;
2627
knowledge_graph: TrapiKnowledgeGraph;
27-
auxiliary_graphs: TrapiAuxGraphCollection;
28+
auxiliary_graphs?: TrapiAuxGraphCollection;
2829
results: {
2930
[resultID: string]: TrapiResult;
3031
};
@@ -488,6 +489,8 @@ export default class InferredQueryHandler {
488489
const { qEdgeID, qEdge, qSubject, qObject } = this.getQueryParts();
489490
const subQueries = await this.createQueries(qEdge, qSubject, qObject);
490491
const combinedResponse = {
492+
status: 'Success',
493+
description: '',
491494
schema_version: global.SCHEMA_VERSION,
492495
biolink_version: global.BIOLINK_VERSION,
493496
workflow: [{ id: 'lookup' }],

src/qedge2apiedge.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const CURIE_WITH_PREFIXES = ['MONDO', 'DOID', 'UBERON', 'EFO', 'HP', 'CHEBI', 'C
55
import Debug from 'debug';
66
import QEdge from './query_edge';
77
import MetaKG from '@biothings-explorer/smartapi-kg';
8-
import { SmartAPIKGOperationObject } from '../../smartapi-kg/built/parser/types';
9-
import { SRIBioEntity } from '../../../biomedical_id_resolver/built/common/types';
8+
import { SmartAPIKGOperationObject } from '@biothings-explorer/smartapi-kg';
9+
import { SRIBioEntity } from 'biomedical_id_resolver';
1010
const debug = Debug('bte:biothings-explorer-trapi:qedge2btedge');
1111

1212
export interface MetaXEdge extends SmartAPIKGOperationObject {

src/query_edge.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import QNode from './query_node';
77
import { QNodeInfo } from './query_node';
88
import { StampedLog } from './log_entry';
99
import { TrapiAttributeConstraint, TrapiQualifierConstraint } from './types';
10-
// import { FrozenRecord } from '../../api-response-transform/built/record';
1110

1211
const debug = Debug('bte:biothings-explorer-trapi:QEdge');
1312

src/query_node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const debug = Debug('bte:biothings-explorer-trapi:QNode');
1010
export interface QNodeInfo {
1111
id: string;
1212
categories?: string[];
13-
ids: string[];
13+
ids?: string[];
1414
is_set?: boolean;
1515
expanded_curie?: ExpandedCuries;
1616
held_curie?: string[];

src/redis-client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ interface RedisClientInterface {
7070
usingLock: (
7171
resources: string[],
7272
duration: number,
73-
settings: unknown,
7473
routine?: (signal: RedlockAbortSignal) => Promise<unknown>,
7574
) => Promise<unknown>;
7675
incrTimeout: (key: string, callback: Callback<number>) => Promise<number>;
@@ -106,8 +105,8 @@ function addClientFuncs(client: Redis | Cluster, redlock: Redlock): RedisClientI
106105
? addPrefixToAll(timeoutFunc((...args: RedisKey[]) => client.del(...args)))
107106
: timeoutFunc((...args: RedisKey[]) => client.del(...args)),
108107
usingLock: lockPrefix(
109-
(resources: string[], duration: number, settings, routine?: (signal: RedlockAbortSignal) => Promise<unknown>) =>
110-
redlock.using(resources, duration, settings, routine),
108+
(resources: string[], duration: number, routine?: (signal: RedlockAbortSignal) => Promise<unknown>) =>
109+
redlock.using(resources, duration, routine),
111110
),
112111
incrTimeout: decorate((key: string) => client.incr(key)),
113112
decrTimeout: decorate((key: string) => client.decr(key)),

0 commit comments

Comments
 (0)