Skip to content

Commit

Permalink
fix: typings, imports
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Oct 6, 2023
1 parent c7cc098 commit f7ae525
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 46 deletions.
6 changes: 3 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
transform: { "\\.ts$": ['ts-jest'] },
setupFilesAfterEnv: ['./jest.setup.js', './jest.setup.redis-mock.js']
};
preset: 'ts-jest',
testEnvironment: 'node',
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"coveralls": "^3.1.0",
"ioredis-mock": "^8.2.2",
"jest": "^26.6.3",
"jest-util": "^26.6.2",
"prettier": "^2.2.1",
"standard-version": "^9.1.1",
"ts-jest": "^26.5.4",
Expand Down
4 changes: 2 additions & 2 deletions src/batch_edge_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { StampedLog } from './log_entry';
import { QueryHandlerOptions } from '.';
import QEdge from './query_edge';
import { UnavailableAPITracker } from './types';
import { Record } from '../../api-response-transform/built';
import { Record } from '@biothings-explorer/api-response-transform';

export interface BatchEdgeQueryOptions extends QueryHandlerOptions {
recordHashEdgeAttributes: string[];
Expand All @@ -24,7 +24,7 @@ export default class BatchEdgeQueryHandler {
options: QueryHandlerOptions;
resolveOutputIDs: boolean;
qEdges: QEdge | QEdge[];
constructor(metaKG: MetaKG, resolveOutputIDs = true, options: BatchEdgeQueryOptions) {
constructor(metaKG: MetaKG, resolveOutputIDs = true, options?: BatchEdgeQueryOptions) {
this.metaKG = metaKG;
this.subscribers = [];
this.logs = [];
Expand Down
6 changes: 3 additions & 3 deletions src/graph/knowledge_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default class KnowledgeGraph {
[edgeID: string]: TrapiKGEdge;
};
kg: TrapiKnowledgeGraph;
apiList: APIDefinition[];
constructor(apiList: APIDefinition[]) {
apiList?: APIDefinition[];
constructor(apiList?: APIDefinition[]) {
this.nodes = {};
this.edges = {};
this.kg = {
Expand Down Expand Up @@ -84,7 +84,7 @@ export default class KnowledgeGraph {
for (const key in kgNode.nodeAttributes) {
node.attributes.push({
attribute_type_id: key,
value: kgNode.nodeAttributes[key],
value: kgNode.nodeAttributes[key] as string[],
//value_type_id: 'bts:' + key,
});
}
Expand Down
31 changes: 21 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import EdgeManager from './edge_manager';
import _ from 'lodash';
import QEdge2APIEdgeHandler from './qedge2apiedge';
import LogEntry, { StampedLog } from './log_entry';
import { redisClient, getNewRedisClient } from './redis-client';
import { promises as fs } from 'fs';
import { getDescendants } from '@biothings-explorer/node-expansion';
import { getTemplates, supportedLookups } from './inferred_mode/template_lookup';
import { resolveSRI, SRIResolverFailiure } from 'biomedical_id_resolver';
import InferredQueryHandler from './inferred_mode/inferred_mode';
import KGNode from './graph/kg_node';
Expand All @@ -32,7 +30,15 @@ import {
import BTEGraph from './graph/graph';
import QEdge from './query_edge';

export { InvalidQueryGraphError, redisClient, getNewRedisClient, LogEntry, getTemplates, supportedLookups };
// Exports for external availability
export * from './types';
export { redisClient, getNewRedisClient } from './redis-client';
export { getTemplates, supportedLookups } from './inferred_mode/template_lookup';
export { default as QEdge } from './query_edge';
export { default as QNode } from './query_node';
export { default as InvalidQueryGraphError } from './exceptions/invalid_query_graph_error';
export { default as LogEntry } from './log_entry';
export * from './qedge2apiedge';

export interface QueryHandlerOptions {
provenanceUsesServiceProvider?: boolean;
Expand All @@ -48,7 +54,7 @@ export interface QueryHandlerOptions {
caching?: boolean; // from request url query values
EDGE_ATTRIBUTES_USED_IN_RECORD_HASH?: string[];
}
export class TRAPIQueryHandler {
export default class TRAPIQueryHandler {
logs: StampedLog[];
options: QueryHandlerOptions;
includeReasoner: boolean;
Expand All @@ -62,7 +68,12 @@ export class TRAPIQueryHandler {
auxGraphs: TrapiAuxGraphCollection;
finalizedResults: TrapiResult[];
queryGraph: TrapiQueryGraph;
constructor(options = {}, smartAPIPath = undefined, predicatesPath = undefined, includeReasoner = true) {
constructor(
options: QueryHandlerOptions = {},
smartAPIPath: string = undefined,
predicatesPath: string = undefined,
includeReasoner = true,
) {
this.logs = [];
this.options = options;
this.options.provenanceUsesServiceProvider = this.options.smartAPIID || this.options.teamName ? true : false;
Expand Down Expand Up @@ -173,8 +184,8 @@ export class TRAPIQueryHandler {
subject,
object,
});
const source = Object.keys(ontologyKnowledgeSourceMapping).find(([prefix]) => {
if (expanded.includes(prefix)) return true;
const source = Object.entries(ontologyKnowledgeSourceMapping).find(([prefix]) => {
return expanded.includes(prefix);
})[1];
subclassEdge.addSource([
{ resource_id: source, resource_role: 'primary_knowledge_source' },
Expand Down Expand Up @@ -599,9 +610,9 @@ export class TRAPIQueryHandler {
new LogEntry(
'INFO',
null,
`execution Summary: (${KGNodes}) nodes / (${kgEdges}) edges / (${results}) results; (${resultQueries}/${queries}) queries${
`Execution Summary: (${KGNodes}) nodes / (${kgEdges}) edges / (${results}) results; (${resultQueries}/${queries}) queries${
cached ? ` (${cached} cached qEdges)` : ''
} returned results from(${sources.length}) unique APIs ${sources.length === 1 ? 's' : ''} `,
} returned results from(${sources.length}) unique API${sources.length === 1 ? 's' : ''}`,
).getLog(),
new LogEntry('INFO', null, `APIs: ${sources.join(', ')} `).getLog(),
];
Expand Down Expand Up @@ -640,7 +651,7 @@ export class TRAPIQueryHandler {
null,
`The following APIs were unavailable at the time of execution: ${global.missingAPIs
.map((spec) => spec.info.title)
.join(', ')} `,
.join(', ')}`,
).getLog(),
);
}
Expand Down
9 changes: 6 additions & 3 deletions src/inferred_mode/inferred_mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import async from 'async';
import biolink from '../biolink';
import { getTemplates, MatchedTemplate, TemplateLookup } from './template_lookup';
import { scaled_sigmoid, inverse_scaled_sigmoid } from '../results_assembly/score';
import { QueryHandlerOptions, TRAPIQueryHandler } from '..';
import TRAPIQueryHandler, { QueryHandlerOptions } from '../index';
import {
CompactQualifiers,
TrapiAuxGraphCollection,
Expand All @@ -20,11 +20,12 @@ import {
const debug = Debug('bte:biothings-explorer-trapi:inferred-mode');

export interface CombinedResponse {
workflow: { id: string }[];
description?: string;
workflow?: { id: string }[];
message: {
query_graph: TrapiQueryGraph;
knowledge_graph: TrapiKnowledgeGraph;
auxiliary_graphs: TrapiAuxGraphCollection;
auxiliary_graphs?: TrapiAuxGraphCollection;
results: {
[resultID: string]: TrapiResult;
};
Expand Down Expand Up @@ -488,6 +489,8 @@ export default class InferredQueryHandler {
const { qEdgeID, qEdge, qSubject, qObject } = this.getQueryParts();
const subQueries = await this.createQueries(qEdge, qSubject, qObject);
const combinedResponse = {
status: 'Success',
description: '',
schema_version: global.SCHEMA_VERSION,
biolink_version: global.BIOLINK_VERSION,
workflow: [{ id: 'lookup' }],
Expand Down
4 changes: 2 additions & 2 deletions src/qedge2apiedge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const CURIE_WITH_PREFIXES = ['MONDO', 'DOID', 'UBERON', 'EFO', 'HP', 'CHEBI', 'C
import Debug from 'debug';
import QEdge from './query_edge';
import MetaKG from '@biothings-explorer/smartapi-kg';
import { SmartAPIKGOperationObject } from '../../smartapi-kg/built/parser/types';
import { SRIBioEntity } from '../../../biomedical_id_resolver/built/common/types';
import { SmartAPIKGOperationObject } from '@biothings-explorer/smartapi-kg';
import { SRIBioEntity } from 'biomedical_id_resolver';
const debug = Debug('bte:biothings-explorer-trapi:qedge2btedge');

export interface MetaXEdge extends SmartAPIKGOperationObject {
Expand Down
1 change: 0 additions & 1 deletion src/query_edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import QNode from './query_node';
import { QNodeInfo } from './query_node';
import { StampedLog } from './log_entry';
import { TrapiAttributeConstraint, TrapiQualifierConstraint } from './types';
// import { FrozenRecord } from '../../api-response-transform/built/record';

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

Expand Down
2 changes: 1 addition & 1 deletion src/query_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const debug = Debug('bte:biothings-explorer-trapi:QNode');
export interface QNodeInfo {
id: string;
categories?: string[];
ids: string[];
ids?: string[];
is_set?: boolean;
expanded_curie?: ExpandedCuries;
held_curie?: string[];
Expand Down
5 changes: 2 additions & 3 deletions src/redis-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ interface RedisClientInterface {
usingLock: (
resources: string[],
duration: number,
settings: unknown,
routine?: (signal: RedlockAbortSignal) => Promise<unknown>,
) => Promise<unknown>;
incrTimeout: (key: string, callback: Callback<number>) => Promise<number>;
Expand Down Expand Up @@ -106,8 +105,8 @@ function addClientFuncs(client: Redis | Cluster, redlock: Redlock): RedisClientI
? addPrefixToAll(timeoutFunc((...args: RedisKey[]) => client.del(...args)))
: timeoutFunc((...args: RedisKey[]) => client.del(...args)),
usingLock: lockPrefix(
(resources: string[], duration: number, settings, routine?: (signal: RedlockAbortSignal) => Promise<unknown>) =>
redlock.using(resources, duration, settings, routine),
(resources: string[], duration: number, routine?: (signal: RedlockAbortSignal) => Promise<unknown>) =>
redlock.using(resources, duration, routine),
),
incrTimeout: decorate((key: string) => client.incr(key)),
decrTimeout: decorate((key: string) => client.decr(key)),
Expand Down
35 changes: 18 additions & 17 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ declare global {
}

export interface TrapiQNode {
ids: string[];
categories: string[];
is_set: boolean;
constraints: TrapiAttributeConstraint[];
ids?: string[];
categories?: string[];
is_set?: boolean;
constraints?: TrapiAttributeConstraint[];
}

export interface TrapiQEdge {
knowledge_type: string;
predicates: string[];
knowledge_type?: string;
predicates?: string[];
subject: string;
object: string;
attribute_constraints: TrapiAttributeConstraint[];
qualifier_constraints: TrapiQualifierConstraint[];
attribute_constraints?: TrapiAttributeConstraint[];
qualifier_constraints?: TrapiQualifierConstraint[];
}

export interface TrapiQueryGraph {
Expand Down Expand Up @@ -83,9 +83,10 @@ export interface TrapiAttribute {
original_attribute_name?: string;
value: string | string[] | number | number[];
value_type_id?: string;
attribute_source?: string;
value_url?: string;
attribute_source?: string | null;
value_url?: string | null;
attributes?: TrapiAttribute;
[additionalProperties: string]: string | string[] | null | TrapiAttribute | number | number[];
}

export interface TrapiQualifier {
Expand Down Expand Up @@ -117,8 +118,8 @@ export interface TrapiEdgeBinding {
}

export interface TrapiAnalysis {
resource_id: string;
score: number;
resource_id?: string;
score?: number;
edge_bindings: {
[qEdgeID: string]: TrapiEdgeBinding[];
};
Expand Down Expand Up @@ -152,14 +153,14 @@ export interface TrapiAuxGraphCollection {
}

export interface TrapiResponse {
description: string;
schema_version: string;
biolink_version: string;
workflow: { id: string }[];
description?: string;
schema_version?: string;
biolink_version?: string;
workflow?: { id: string }[];
message: {
query_graph: TrapiQueryGraph;
knowledge_graph: TrapiKnowledgeGraph;
auxiliary_graphs: TrapiAuxGraphCollection;
auxiliary_graphs?: TrapiAuxGraphCollection;
results: TrapiResult[];
};
logs: TrapiLog[];
Expand Down
3 changes: 2 additions & 1 deletion src/update_nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Debug from 'debug';
import { ResolverInput, SRIResolverOutput } from '../../../biomedical_id_resolver/built/common/types';
import { Record } from '@biothings-explorer/api-response-transform';
import QEdge from './query_edge';
import { NodeNormalizerResultObj } from '../../api-response-transform/built';
const debug = Debug('bte:biothings-explorer-trapi:nodeUpdateHandler');

export interface CuriesByCategory {
Expand Down Expand Up @@ -63,7 +64,7 @@ export default class NodesUpdateHandler {
return;
}

_createEquivalentIDsObject(record: Record) {
_createEquivalentIDsObject(record: Record): { [curie: string]: NodeNormalizerResultObj } {
if (record.object.normalizedInfo !== undefined) {
return {
[record.object.curie]: record.object.normalizedInfo,
Expand Down

0 comments on commit f7ae525

Please sign in to comment.