feat: enhance query handling with modules and plugins

- Added ManyToMany relationship for plugins in Query entity.
- Updated QueryExecuterController to accept structured query data.
- Enhanced QueryExecuterService to support plugin initialization and execution.
- Implemented QueryHandlerService methods for creating and updating queries, modules, and plugins.
- Introduced new endpoints for creating and adding modules and plugins to queries.
- Created Plugin base class and DatabasePlugin implementation for database interactions.
- Updated VM class to integrate plugin functionality during script execution.
- Added test cases for project, query, module, and plugin operations.
This commit is contained in:
lborv
2025-09-21 01:07:51 +03:00
parent d90c85d66f
commit 8eba1d1344
26 changed files with 620 additions and 25 deletions

22
tests/base/case1.ts Normal file
View File

@ -0,0 +1,22 @@
import createProject from "../functions/createProject";
import createQuery from "../functions/createQuery";
import runQuery from "../functions/runQuery";
(async () => {
try {
const project = await createProject("Test Project");
const query = await createQuery(
project,
"async function main(input) { return `Hello, ${input.name}!`; }"
);
console.log(query);
const result = await runQuery(query.id, { name: "World" });
console.log("Query Result:", result);
} catch (error) {
console.error("Error during test execution:", error);
}
})();

View File

@ -0,0 +1,17 @@
import axios from "axios";
export default async (query: { id: string }, module: { id: string }) => {
try {
const response = await axios.post(
"http://localhost:3000/query/module/add",
{
queryId: query.id,
moduleId: module.id,
}
);
return response;
} catch (error) {
console.error("Error in adding module to query:", error);
}
};

View File

@ -0,0 +1,17 @@
import axios from "axios";
export default async (query: { id: string }, plugin: { id: string }) => {
try {
const response = await axios.post(
"http://localhost:3000/query/plugin/add",
{
queryId: query.id,
pluginId: plugin.id,
}
);
return response;
} catch (error) {
console.error("Error in adding plugin to query:", error);
}
};

View File

@ -0,0 +1,17 @@
import axios from "axios";
export default async (name: string, sourcePath: string) => {
try {
const response = await axios.post(
"http://localhost:3000/query/module/create",
{
name,
sourcePath,
}
);
return response;
} catch (error) {
console.error("Error in creating project or query:", error);
}
};

View File

@ -0,0 +1,18 @@
import axios from "axios";
export default async (name: string, className: string, config: string) => {
try {
const response = await axios.post(
"http://localhost:3000/query/plugin/create",
{
name,
class: className,
config,
}
);
return response;
} catch (error) {
console.error("Error in creating project or query:", error);
}
};

View File

@ -0,0 +1,16 @@
import axios from "axios";
const createProject = async (name: string) => {
try {
const response = await axios.put("http://localhost:3000/project/create", {
name: name,
});
return response.data;
} catch (error) {
console.error("Error creating project:", error);
throw error;
}
};
export default createProject;

View File

@ -0,0 +1,14 @@
import axios from "axios";
export default async (project: { token: string }, source: string) => {
try {
const response = await axios.post("http://localhost:3000/query/create", {
source,
projectToken: project.token,
});
return response.data;
} catch (error) {
console.error("Error creating query:", error);
throw error;
}
};

View File

@ -0,0 +1,14 @@
import axios from "axios";
export default async (token: string, queryData: Record<string, any>) => {
try {
const response = await axios.post(
`http://localhost:3000/query/run/${token}`,
queryData
);
return response;
} catch (error) {
console.error("Error in running query:", error);
}
};

View File

@ -0,0 +1,14 @@
import axios from "axios";
export default async (query: { id: string; source: string }) => {
try {
const response = await axios.post("http://localhost:3000/query/update", {
queryId: query.id,
source: query.source,
});
return response;
} catch (error) {
console.error("Error in updating query:", error);
}
};