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:
22
tests/base/case1.ts
Normal file
22
tests/base/case1.ts
Normal 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);
|
||||
}
|
||||
})();
|
||||
17
tests/functions/addModule.ts
Normal file
17
tests/functions/addModule.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
17
tests/functions/addPlugin.ts
Normal file
17
tests/functions/addPlugin.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
17
tests/functions/createModule.ts
Normal file
17
tests/functions/createModule.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
18
tests/functions/createPluign.ts
Normal file
18
tests/functions/createPluign.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
16
tests/functions/createProject.ts
Normal file
16
tests/functions/createProject.ts
Normal 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;
|
||||
14
tests/functions/createQuery.ts
Normal file
14
tests/functions/createQuery.ts
Normal 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;
|
||||
}
|
||||
};
|
||||
14
tests/functions/runQuery.ts
Normal file
14
tests/functions/runQuery.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
14
tests/functions/updateQuery.ts
Normal file
14
tests/functions/updateQuery.ts
Normal 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);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user