feat: implement function management with FunctionEntity, FunctionService, and FunctionController; enhance QueryExecuterService to utilize functions; refactor CommandController and QueryController to extend BaseQueryController; update Vm class to handle functions; remove obsolete log entities
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Query } from "../entities/query.entity";
|
||||
import { Repository } from "typeorm";
|
||||
@ -13,6 +13,7 @@ import { DatabaseManagerService } from "src/databaseManager/database/database.ma
|
||||
import { InjectQueue } from "@nestjs/bullmq";
|
||||
import { QUEUE_NAMES } from "src/queue/constants";
|
||||
import { Queue, QueueEvents } from "bullmq";
|
||||
import { FunctionService } from "src/project/function/function.service";
|
||||
|
||||
@Injectable()
|
||||
export class QueryExecuterService {
|
||||
@ -21,6 +22,8 @@ export class QueryExecuterService {
|
||||
constructor(
|
||||
@InjectRepository(Query)
|
||||
readonly queryRepository: Repository<Query>,
|
||||
@Inject(FunctionService)
|
||||
private readonly functionService: FunctionService,
|
||||
readonly databaseManagerService: DatabaseManagerService,
|
||||
@InjectQueue(QUEUE_NAMES.QUERY) private queryQueue: Queue
|
||||
) {
|
||||
@ -110,6 +113,16 @@ export class QueryExecuterService {
|
||||
|
||||
const moduleNames = importsParsed.filter((imp) => imp.type === "module");
|
||||
const pluginNames = importsParsed.filter((imp) => imp.type === "plugin");
|
||||
const functionNames = importsParsed.filter(
|
||||
(imp) => imp.type === "function"
|
||||
);
|
||||
|
||||
const functions = (
|
||||
await this.functionService.findByNames(
|
||||
query.project.id,
|
||||
functionNames.map((fn) => fn.name)
|
||||
)
|
||||
).map((fn) => fn.source);
|
||||
|
||||
const modules = moduleNames.map((mod) => {
|
||||
if (registeredModules[mod.name]) {
|
||||
@ -134,24 +147,18 @@ export class QueryExecuterService {
|
||||
cpuTimeLimit: BigInt(5e9),
|
||||
modules: modules,
|
||||
plugins: plugins,
|
||||
functions: functions,
|
||||
});
|
||||
|
||||
return await vm.init();
|
||||
}
|
||||
|
||||
private checkResponse(obj: any): obj is QueryResponse {
|
||||
return (
|
||||
obj !== null &&
|
||||
typeof obj === "object" &&
|
||||
typeof obj.statusCode === "number" &&
|
||||
typeof obj.response === "object" &&
|
||||
obj.response !== null &&
|
||||
typeof obj.headers === "object" &&
|
||||
obj.headers !== null &&
|
||||
Object.keys(obj.headers).every(
|
||||
(key) => typeof obj.headers[key] === "string"
|
||||
)
|
||||
);
|
||||
private checkResponse(obj: any): boolean {
|
||||
if (obj?.statusCode && obj.response && typeof obj.statusCode === "number") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
|
||||
Reference in New Issue
Block a user