diff --git a/__test__/integration/integration.test.ts b/__test__/integration/integration.test.ts index be67f91..61e4461 100644 --- a/__test__/integration/integration.test.ts +++ b/__test__/integration/integration.test.ts @@ -1,4 +1,5 @@ -import APIQueryDispatcher, { RedisClient } from "../../src/index"; +import APIQueryDispatcher from "../../src/index"; +import { RedisClient } from "@biothings-explorer/utils"; import fs from "fs"; import path from "path"; import axios from "axios"; diff --git a/__test__/unittest/query_queue.test.ts b/__test__/unittest/query_queue.test.ts index 24d3a5e..ee44f70 100644 --- a/__test__/unittest/query_queue.test.ts +++ b/__test__/unittest/query_queue.test.ts @@ -8,6 +8,7 @@ import APIQueryQueue from "../../src/query_queue"; describe("Test Query Queue module", () => { describe("Test getNext function", () => { test("Test getNext function", async () => { + // @ts-expect-error don't need full redisClient, just that it's disabled const queue = new APIQueryQueue([], { clientEnabled: false }); queue.queue = [ { diff --git a/src/dispatcher.ts b/src/dispatcher.ts index 1e11cc5..1978268 100644 --- a/src/dispatcher.ts +++ b/src/dispatcher.ts @@ -2,12 +2,13 @@ import { Record } from "@biothings-explorer/api-response-transform"; import BaseQueryBuilder from "./builder/base_query_builder"; import APIQueryPool from "./query_pool"; import APIQueryQueue from "./query_queue"; +import { QueryHandlerOptions, UnavailableAPITracker } from "./types"; import { - QueryHandlerOptions, + LogEntry, + StampedLog, + Telemetry, RedisClient, - UnavailableAPITracker, -} from "./types"; -import { LogEntry, StampedLog, Telemetry } from "@biothings-explorer/utils"; +} from "@biothings-explorer/utils"; import Debug from "debug"; const debug = Debug("bte:call-apis:query"); diff --git a/src/index.ts b/src/index.ts index 6f59bac..18c9ce1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,5 @@ -import { LogEntry, StampedLog } from "@biothings-explorer/utils"; -import { - APIEdge, - QueryHandlerOptions, - RedisClient, - UnavailableAPITracker, -} from "./types"; +import { LogEntry, StampedLog, RedisClient } from "@biothings-explorer/utils"; +import { APIEdge, QueryHandlerOptions, UnavailableAPITracker } from "./types"; import Debug from "debug"; const debug = Debug("bte:call-apis:query"); import queryBuilder from "./builder/builder_factory"; @@ -83,7 +78,10 @@ export default class APIQueryDispatcher { /** * Add equivalent ids to all entities using biomedical-id-resolver service */ - async _annotate(records: Record[], resolveOutputIDs = true): Promise { + async _annotate( + records: Record[], + resolveOutputIDs = true, + ): Promise { const groupedCuries = this._groupCuriesBySemanticType(records); let res: SRIResolverOutput | ResolverOutput; let attributes: unknown; @@ -119,7 +117,8 @@ export default class APIQueryDispatcher { Object.hasOwnProperty.call(attributes, record.object.original) ) { if (record instanceof ResolvableBioEntity) { - record.object.normalizedInfo.attributes = attributes[record.object.original]; + record.object.normalizedInfo.attributes = + attributes[record.object.original]; } } }); @@ -132,7 +131,8 @@ export default class APIQueryDispatcher { ): Promise { // Used for temporarily storing a message to log via both debug and TRAPI logs let message: string; - message = `Resolving ID feature is turned ${resolveOutputIDs ? "on" : "off"}`; + message = `Resolving ID feature is turned ${resolveOutputIDs ? "on" : "off" + }`; debug(message); this.logs.push(new LogEntry("DEBUG", null, message).getLog()); message = [ @@ -151,7 +151,7 @@ export default class APIQueryDispatcher { this.options, ); const { records, logs } = await subQueryDispatcher.execute(); - this.logs.push(...logs) + this.logs.push(...logs); // Occurs when globalMaxRecords hit, requiring query termination if (!records) return undefined; diff --git a/src/query_queue.ts b/src/query_queue.ts index 45ed072..62df649 100644 --- a/src/query_queue.ts +++ b/src/query_queue.ts @@ -1,6 +1,6 @@ import BaseQueryBuilder from "./builder/base_query_builder"; import RateCounter from "./rate_limiter"; -import { RedisClient } from "./types"; +import { RedisClient } from "@biothings-explorer/utils"; import Debug from "debug"; const debug = Debug("bte:call-apis:query"); diff --git a/src/rate_limiter.ts b/src/rate_limiter.ts index ddecec1..fea2fd0 100644 --- a/src/rate_limiter.ts +++ b/src/rate_limiter.ts @@ -1,5 +1,5 @@ import BaseQueryBuilder from "./builder/base_query_builder"; -import { RedisClient } from "./types"; +import { RedisClient } from "@biothings-explorer/utils"; import Debug from "debug"; const debug = Debug("bte:call-apis:query"); diff --git a/src/types.ts b/src/types.ts index 722b18c..1452bba 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,22 +9,6 @@ import { SRIBioEntity } from "biomedical_id_resolver"; * This would allow for greater flexibility in package structure/type importing */ -declare global { - var missingAPIs: SmartAPISpec[]; - var BIOLINK_VERSION: string; - var SCHEMA_VERSION: string; - var parentPort: MessagePort; - var cachingTasks: Promise[]; - var queryInformation: { - queryGraph: TrapiQueryGraph; - isCreativeMode: boolean; - creativeTemplate?: string; - totalRecords: number; - jobID?: string; - callback_url?: string; - }; - var job: { log: (logString: string) => void }; // TODO type as Piscina job -} export interface QueryParams { [paramName: string]: unknown; } @@ -311,28 +295,3 @@ export interface QueryHandlerOptions { export interface UnavailableAPITracker { [server: string]: { skip: boolean; skippedQueries: number }; } - -interface RedisClientInterface { - getTimeout: (key: string) => Promise; - setTimeout: (key: string, value: string | number | Buffer) => Promise<"OK">; - hsetTimeout: ( - ...args: [key: string, ...fieldValues: (string | Buffer | number)[]] - ) => Promise; - hgetallTimeout: (key: string) => Promise; - expireTimeout: (key: string, seconds: string | number) => Promise; - delTimeout: (...args: string[]) => Promise; - usingLock: ( - resources: string[], - duration: number, - routine?: (signal: unknown) => Promise, - ) => Promise; - incrTimeout: (key: string) => Promise; - decrTimeout: (key: string) => Promise; - existsTimeout: (...args: string[]) => Promise; - pingTimeout: () => Promise<"PONG">; -} - -export interface RedisClient { - client?: RedisClientInterface; - clientEnabled: boolean; -}