Skip to content

Commit

Permalink
Merge pull request #75 from biothings/move-redisclient
Browse files Browse the repository at this point in the history
Support typescript migration/moving redis client
  • Loading branch information
tokebe committed Apr 1, 2024
2 parents 547094e + 913cfe9 commit 5f74d34
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 59 deletions.
3 changes: 2 additions & 1 deletion __test__/integration/integration.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
1 change: 1 addition & 0 deletions __test__/unittest/query_queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
9 changes: 5 additions & 4 deletions src/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
22 changes: 11 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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<Record[]> {
async _annotate(
records: Record[],
resolveOutputIDs = true,
): Promise<Record[]> {
const groupedCuries = this._groupCuriesBySemanticType(records);
let res: SRIResolverOutput | ResolverOutput;
let attributes: unknown;
Expand Down Expand Up @@ -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];
}
}
});
Expand All @@ -132,7 +131,8 @@ export default class APIQueryDispatcher {
): Promise<Record[]> {
// 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 = [
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/query_queue.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
2 changes: 1 addition & 1 deletion src/rate_limiter.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand Down
41 changes: 0 additions & 41 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>[];
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;
}
Expand Down Expand Up @@ -311,28 +295,3 @@ export interface QueryHandlerOptions {
export interface UnavailableAPITracker {
[server: string]: { skip: boolean; skippedQueries: number };
}

interface RedisClientInterface {
getTimeout: (key: string) => Promise<string>;
setTimeout: (key: string, value: string | number | Buffer) => Promise<"OK">;
hsetTimeout: (
...args: [key: string, ...fieldValues: (string | Buffer | number)[]]
) => Promise<number>;
hgetallTimeout: (key: string) => Promise<unknown>;
expireTimeout: (key: string, seconds: string | number) => Promise<number>;
delTimeout: (...args: string[]) => Promise<number>;
usingLock: (
resources: string[],
duration: number,
routine?: (signal: unknown) => Promise<unknown>,
) => Promise<unknown>;
incrTimeout: (key: string) => Promise<number>;
decrTimeout: (key: string) => Promise<number>;
existsTimeout: (...args: string[]) => Promise<number>;
pingTimeout: () => Promise<"PONG">;
}

export interface RedisClient {
client?: RedisClientInterface;
clientEnabled: boolean;
}

0 comments on commit 5f74d34

Please sign in to comment.