feat: implement command functionality with new CommandController, update Query entity, and enhance query execution with headers support
This commit is contained in:
25
src/vm/plugins/query.plugin.ts
Normal file
25
src/vm/plugins/query.plugin.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { QueryExecuterService } from "../../query/executer/query.executer.service";
|
||||
import { Query } from "../../query/entities/query.entity";
|
||||
import { Plugin } from "../plugin.class";
|
||||
|
||||
export class QueryPlugin extends Plugin {
|
||||
constructor(
|
||||
name: string,
|
||||
private query: Query,
|
||||
private QueryExecuterService: QueryExecuterService
|
||||
) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
static async init(query: Query, queryExecuterService: QueryExecuterService) {
|
||||
return new QueryPlugin("query", query, queryExecuterService);
|
||||
}
|
||||
|
||||
async run(data): Promise<any> {
|
||||
return await this.QueryExecuterService.runQuery(this.query.id, data);
|
||||
}
|
||||
|
||||
onFinish() {
|
||||
// No resources to clean up
|
||||
}
|
||||
}
|
||||
@ -47,7 +47,11 @@ export class Vm {
|
||||
this.jail.setSync(name, func);
|
||||
}
|
||||
|
||||
async runScript(script: string, args: Record<string, any>): Promise<any> {
|
||||
async runScript(
|
||||
script: string,
|
||||
args: Record<string, any>,
|
||||
headers: Record<string, any>
|
||||
): Promise<any> {
|
||||
let resolvePromise: (value: any) => void;
|
||||
let rejectPromise: (reason?: any) => void;
|
||||
|
||||
@ -76,7 +80,9 @@ export class Vm {
|
||||
(async () => {
|
||||
${script}
|
||||
try {
|
||||
const result = await main(${JSON.stringify(args)});
|
||||
const result = await main(${JSON.stringify(
|
||||
args
|
||||
)}, ${JSON.stringify(headers)});
|
||||
returnResult(JSON.stringify(result))
|
||||
} catch (e) {
|
||||
error(e)
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
import { QueryExecuterService } from "src/query/executer/query.executer.service";
|
||||
import { DatabasePlugin } from "./plugins/database.plugin";
|
||||
import { Query } from "src/query/entities/query.entity";
|
||||
import { QueryPlugin } from "./plugins/query.plugin";
|
||||
|
||||
export const registeredPlugins = {
|
||||
db: async (service: QueryExecuterService, query: Query) => {
|
||||
const databaseConnection =
|
||||
await service.databaseManagerService.getConnectionOptions(
|
||||
query.project.id
|
||||
query.project.id,
|
||||
query.isCommand == 0
|
||||
);
|
||||
|
||||
if (!databaseConnection) {
|
||||
@ -15,6 +17,12 @@ export const registeredPlugins = {
|
||||
|
||||
return DatabasePlugin.init("db", databaseConnection);
|
||||
},
|
||||
query: async (service: QueryExecuterService, query: Query) => {
|
||||
return QueryPlugin.init(query, service);
|
||||
},
|
||||
command: async (service: QueryExecuterService, query: Query) => {
|
||||
return QueryPlugin.init(query, service);
|
||||
},
|
||||
};
|
||||
|
||||
export const registeredModules = {
|
||||
|
||||
Reference in New Issue
Block a user