From dbc692e92a5cd423e953441689b421a31a3ce19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Djk=C3=A1=C5=A5o?= Date: Mon, 9 Oct 2023 17:31:55 +0200 Subject: [PATCH] replace debugs with console.logs, some fixes --- src/APL/redis-apl.ts | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/APL/redis-apl.ts b/src/APL/redis-apl.ts index 0c0eeb1..f17b6b2 100644 --- a/src/APL/redis-apl.ts +++ b/src/APL/redis-apl.ts @@ -3,8 +3,6 @@ import Redis from "ioredis"; import { APL, AplConfiguredResult, AplReadyResult, AuthData } from "./apl"; import { createAPLDebug } from "./apl-debug"; -const debug = createAPLDebug("RedisAPL"); - export type RedisAPLClientArgs = { client: Redis; appApiBaseUrl: string; @@ -25,19 +23,19 @@ export class RedisAPL implements APL { private appApiBaseUrl; constructor(args: RedisAPLClientArgs | RedisAPLUrlArgs) { + console.log(args) if (!args.appApiBaseUrl) throw new Error("The RedisAPL requires to know the app api url beforehand"); this.appApiBaseUrl = args.appApiBaseUrl; if ("client" in args && args.client) { this.client = args.client; - debug("RedisAPL: created redis client"); } else if ("redisUrl" in args && args.redisUrl) { this.client = new Redis(args.redisUrl, { lazyConnect: true }); - debug("RedisAPL: created redis client"); } else { throw new Error("RedisAPL: No redis url or client defined"); } + this.isConfigured().then((v) => console.log("REDIS: CONFIGURED TEST: ", v)) } private prepareKey(saleorApiUrl: string) { @@ -47,28 +45,28 @@ export class RedisAPL implements APL { async get(saleorApiUrl: string): Promise { try { const res = await this.client.get(this.prepareKey(saleorApiUrl)); - debug("RedisAPL: get - received: %j", res); + const exit = this.client.quit(); + console.log("REDIS: GET: ") + console.dir(res, { depth: null }) if (res) { - await this.client.quit(); - return JSON.parse(res) as AuthData; + const data = JSON.parse(res) as AuthData + await exit + return data; } - await this.client.quit(); - return undefined; } catch (e) { - await this.client.quit(); - return undefined; + this.client.quit() } } async set(authData: AuthData): Promise { - await this.client.set(this.prepareKey(authData.saleorApiUrl), JSON.stringify(authData)); - debug("RedisAPL: set - set sucessfully: %j", authData); + const res = await this.client.set(this.prepareKey(authData.saleorApiUrl), JSON.stringify(authData)); + console.log("REDIS: SET: ", res) await this.client.quit(); } async delete(saleorApiUrl: string): Promise { const val = await this.client.getdel(this.prepareKey(saleorApiUrl)); - debug("RedisAPL: del - deleted successfuly: %j", val); + console.log("REDIS: DEL: ", val) await this.client.quit(); } @@ -77,14 +75,18 @@ export class RedisAPL implements APL { } async isReady(): Promise { - const ready = !!(await this.client.info()); + const res = await this.client.info() + const ready = !!(res); + console.log("REDIS: ISREADY: ", res) await this.client.quit(); - return { ready } as AplReadyResult; + return { ready: true } as AplReadyResult; } async isConfigured(): Promise { - const ready = !!(await this.client.info()); + const res = await this.client.info() + const ready = !!(res); + console.log("REDIS: ISCONF: ", res) await this.client.quit(); - return { configured: ready } as AplConfiguredResult; + return { configured: true } as AplConfiguredResult; } }