feat: update ApiTokenGuard to always allow access, add updateDatabase method to ProjectService, enhance QueryExecuterService with job options, integrate QueueModule in QueryModule, apply ApiTokenGuard to RedisManagerController, refactor Plugin class to include methods, implement new methods in RedisPlugin, and remove unused async.js module

This commit is contained in:
Boris D
2025-10-09 11:56:53 +03:00
parent 6c95e9d5e0
commit dac008366a
15 changed files with 169 additions and 59 deletions

View File

@ -9,7 +9,7 @@ export class DatabasePlugin extends Plugin {
);
}
super(name);
super(name, ["execute"]);
}
static async init(
@ -34,17 +34,13 @@ export class DatabasePlugin extends Plugin {
return new DatabasePlugin(name, dbConnection);
}
async run(query): Promise<any> {
try {
const [rows, fields] = await this.dbConnection.execute(query);
async execute(query): Promise<any> {
const [rows, fields] = await this.dbConnection.query(query);
return JSON.stringify({
rows: rows,
fields: fields ?? [],
});
} catch (error) {
console.log("error", error);
}
return {
rows: rows,
fields: fields ?? [],
};
}
onFinish() {

View File

@ -8,7 +8,7 @@ export class QueryPlugin extends Plugin {
private query: Query,
private QueryExecuterService: QueryExecuterService
) {
super(name);
super(name, ["run"]);
}
static async init(query: Query, queryExecuterService: QueryExecuterService) {

View File

@ -2,24 +2,93 @@ import Redis from "ioredis";
import { Plugin } from "../plugin.class";
export class RedisPlugin extends Plugin {
constructor(name: string, private redisClient: Redis) {
super(name);
constructor(
name: string,
private redisClient: Redis,
private prefix: string
) {
super(name, [
"get",
"set",
"del",
"exists",
"lpop",
"rpush",
"llen",
"lrange",
"ltrim",
"lpush",
"rpop",
]);
}
static init(
name: string,
config: { host: string; port: number }
config: { host: string; port: number },
prefix: string
): RedisPlugin {
const redisClient = new Redis({
host: config.host,
port: config.port,
});
return new RedisPlugin(name, redisClient);
return new RedisPlugin(name, redisClient, prefix);
}
async run(): Promise<Redis> {
return this.redisClient;
async get(key: string): Promise<string | null> {
return JSON.parse(await this.redisClient.get(`${this.prefix}:${key}`));
}
async set(key: string, value: any): Promise<void> {
await this.redisClient.set(`${this.prefix}:${key}`, JSON.stringify(value));
}
async del(key: string): Promise<void> {
await this.redisClient.del(`${this.prefix}:${key}`);
}
async exists(key: string): Promise<boolean> {
const result = await this.redisClient.exists(`${this.prefix}:${key}`);
return result === 1;
}
async lpop(key: string): Promise<string | null> {
return this.redisClient.lpop(`${this.prefix}:${key}`);
}
async rpush(key: string, value: any): Promise<number> {
return this.redisClient.rpush(
`${this.prefix}:${key}`,
JSON.stringify(value)
);
}
async llen(key: string): Promise<number> {
return this.redisClient.llen(`${this.prefix}:${key}`);
}
async lrange(key: string, start: number, stop: number): Promise<string[]> {
const results = await this.redisClient.lrange(
`${this.prefix}:${key}`,
start,
stop
);
return results.map((item) => JSON.parse(item));
}
async ltrim(key: string, start: number, stop: number): Promise<void> {
await this.redisClient.ltrim(`${this.prefix}:${key}`, start, stop);
}
async lpush(key: string, value: any): Promise<number> {
return this.redisClient.lpush(
`${this.prefix}:${key}`,
JSON.stringify(value)
);
}
async rpop(key: string): Promise<string | null> {
return this.redisClient.rpop(`${this.prefix}:${key}`);
}
onFinish(): void {