feat: enhance API and query handling with Redis caching; add QueryGuard for query validation; refactor services to utilize RedisClient for improved performance

This commit is contained in:
Boris D
2025-10-10 10:51:52 +03:00
parent 45db65cec8
commit ca134414b0
20 changed files with 228 additions and 64 deletions

View File

@ -10,33 +10,33 @@ import * as path from "path";
(async () => {
try {
const node = await createDatabaseNode("localhost", 3306, "root", "root");
// const node = await createDatabaseNode("localhost", 3306, "root", "root");
console.log("Database node created:", node);
// console.log("Database node created:", node);
const project = await createProject("Test Project");
// const project = await createProject("Test Project");
console.log("Project created:", project);
// console.log("Project created:", project);
const db = await createDatabase(project.id, node.id);
// const db = await createDatabase(project.id, node.id);
console.log("Database created:", db);
// console.log("Database created:", db);
const migration = await createMigration(
db.id,
"CREATE TABLE `test` (id INT AUTO_INCREMENT PRIMARY KEY, col1 VARCHAR(255))",
"DROP TABLE `test`"
);
// const migration = await createMigration(
// db.id,
// "CREATE TABLE `test` (id INT AUTO_INCREMENT PRIMARY KEY, col1 VARCHAR(255))",
// "DROP TABLE `test`"
// );
console.log("Migration created:", migration);
// console.log("Migration created:", migration);
const migrationResult = await databaseMigrationUp(db.id);
// const migrationResult = await databaseMigrationUp(db.id);
console.log("Migrations applied:", migrationResult);
// console.log("Migrations applied:", migrationResult);
const payloadPath = path.join(__dirname, "case1-payload.js");
const query = await createQuery(
project,
{ token: "04c38f93-f2fb-4d2c-a8e2-791effa35239" },
fs.readFileSync(payloadPath, { encoding: "utf-8" })
);

View File

@ -3,10 +3,14 @@ import { config } from "../config";
export default async (project: { token: string }, source: string) => {
try {
const response = await axios.post(`${config.url}/query/create`, {
source,
projectToken: project.token,
});
const response = await axios.post(
`${config.url}/query/create`,
{
source,
projectToken: project.token,
},
{ headers: { "x-api-token": "efbeccd6-dde1-47dc-b3aa-4fbd773d5429" } }
);
return response.data;
} catch (error) {
console.error("Error creating query:", error);

View File

@ -5,7 +5,8 @@ export default async (token: string, queryData: Record<string, any>) => {
try {
const response = await axios.post(
`${config.url}/query/run/${token}`,
queryData
queryData,
{ headers: { "x-api-token": "efbeccd6-dde1-47dc-b3aa-4fbd773d5429" } }
);
return response;