Refactor VM and Plugin Management
- Removed the `plugins.constants.ts` file as it was no longer needed. - Updated the `vm.class.ts` to improve result handling and logging. - Introduced `vm.constants.ts` to manage registered plugins and modules. - Simplified the test payload in `case1-payload.js` by removing unnecessary insert logic. - Enhanced `case1.ts` to include database and migration setup, improving test clarity. - Deleted unused functions for adding modules and plugins, streamlining the codebase.
This commit is contained in:
@ -1,28 +1,17 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||
/* eslint-disable no-undef */
|
||||
|
||||
async function insert() {
|
||||
const res = await asyncCall(
|
||||
db,
|
||||
squel.insert().into("testTable").set("col", "test me now").toString()
|
||||
);
|
||||
|
||||
return res;
|
||||
}
|
||||
import "module/squel";
|
||||
import "module/asyncCall";
|
||||
import "plugin/db";
|
||||
|
||||
function createSQL(id) {
|
||||
return squel.select().from("testTable").where("id = ?", id).toString();
|
||||
return squel.select().from("test").where("id = ?", id).toString();
|
||||
}
|
||||
|
||||
async function main(input) {
|
||||
const inserted = await insert();
|
||||
|
||||
log(inserted);
|
||||
|
||||
const sql = createSQL(inserted.rows.insertId);
|
||||
const sql = createSQL(input.id);
|
||||
const res = await asyncCall(db, sql);
|
||||
|
||||
log(res.rows);
|
||||
|
||||
return res;
|
||||
return { test: 1, array: [1, 2, [{ id: 1, name: "Test" }]] };
|
||||
}
|
||||
|
||||
@ -1,13 +1,39 @@
|
||||
import createMigration from "../functions/createMigration";
|
||||
import createDatabase from "../functions/createDatabase";
|
||||
import createDatabaseNode from "../functions/createDatabaseNode";
|
||||
import createProject from "../functions/createProject";
|
||||
import createQuery from "../functions/createQuery";
|
||||
import databaseMigrationUp from "../functions/databaseMigrationUp";
|
||||
import runQuery from "../functions/runQuery";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const node = await createDatabaseNode("localhost", 3306, "root", "root");
|
||||
|
||||
console.log("Database node created:", node);
|
||||
|
||||
const project = await createProject("Test Project");
|
||||
|
||||
console.log("Project created:", project);
|
||||
|
||||
const db = await createDatabase(project.id, node.id);
|
||||
|
||||
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`"
|
||||
);
|
||||
|
||||
console.log("Migration created:", migration);
|
||||
|
||||
const migrationResult = await databaseMigrationUp(db.id);
|
||||
|
||||
console.log("Migrations applied:", migrationResult);
|
||||
|
||||
const payloadPath = path.join(__dirname, "case1-payload.js");
|
||||
const query = await createQuery(
|
||||
project,
|
||||
@ -16,10 +42,10 @@ import * as path from "path";
|
||||
|
||||
console.log(query);
|
||||
|
||||
const result = await runQuery(query.id, { name: "World" });
|
||||
const result = await runQuery(query.id, { id: 1 });
|
||||
|
||||
console.log("Query Result:", result);
|
||||
console.log("Query Result:", result.data);
|
||||
} catch (error) {
|
||||
console.error("Error during test execution:", error);
|
||||
console.error("Error during test execution");
|
||||
}
|
||||
})();
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
import axios from "axios";
|
||||
import { config } from "tests/config";
|
||||
|
||||
export default async (query: { id: string }, module: { id: string }) => {
|
||||
try {
|
||||
const response = await axios.post(`${config.url}/query/module/add`, {
|
||||
queryId: query.id,
|
||||
moduleId: module.id,
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error in adding module to query:", error);
|
||||
}
|
||||
};
|
||||
@ -1,15 +0,0 @@
|
||||
import axios from "axios";
|
||||
import { config } from "tests/config";
|
||||
|
||||
export default async (query: { id: string }, plugin: { id: string }) => {
|
||||
try {
|
||||
const response = await axios.post(`${config.url}/query/plugin/add`, {
|
||||
queryId: query.id,
|
||||
pluginId: plugin.id,
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error in adding plugin to query:", error);
|
||||
}
|
||||
};
|
||||
@ -1,15 +0,0 @@
|
||||
import axios from "axios";
|
||||
import { config } from "tests/config";
|
||||
|
||||
export default async (name: string, sourcePath: string) => {
|
||||
try {
|
||||
const response = await axios.post(`${config.url}/query/module/create`, {
|
||||
name,
|
||||
sourcePath,
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error in creating project or query:", error);
|
||||
}
|
||||
};
|
||||
@ -1,16 +0,0 @@
|
||||
import axios from "axios";
|
||||
import { config as appConfig } from "../config";
|
||||
|
||||
export default async (name: string, className: string, config: string) => {
|
||||
try {
|
||||
const response = await axios.post(`${appConfig.url}/query/plugin/create`, {
|
||||
name,
|
||||
class: className,
|
||||
config,
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Error in creating project or query:", error);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user