This commit is contained in:
IDONTSUDO 2023-11-16 00:40:35 +03:00
parent 8ecb036b1d
commit d70253d6a6
33 changed files with 201 additions and 81 deletions

View file

@ -84,7 +84,6 @@ export class App {
}
async appStartController() {
console.log(App.staticFilesStoreDir());
if (await dirIsExists(App.staticFilesStoreDir())) {
return;
}

View file

@ -12,7 +12,7 @@ export class CrudController<V, D> extends CoreHttpController<V> {
constructor(routerModel: IRouteModel) {
super(routerModel);
this.url = "/" + routerModel.url;
this.mainURL = "/" + routerModel.url;
this.validationModel = routerModel.validationModel;
this.dataBaseModel = routerModel.databaseModel;
this.init();

View file

@ -3,16 +3,33 @@ import { Result } from "../helper/result";
import { Router, Request, Response } from "express";
import { IRouteModel, Routes } from "../interfaces/router";
export type CallBackFunction<T> = (a: T) => Promise<Result<any, any>>;
type Method =
| "all"
| "get"
| "post"
| "put"
| "delete"
| "patch"
| "options"
| "head";
export type CallbackStrategyWithValidationModel<T> = (
a: T
) => Promise<Result<any, any>>;
// TODO(IDOTSUDO):NEED IMPLEMENTS
// interface ISubSetFeatureRouter<T>{
// method:Method,
// fn:CallbackStrategyWithValidationModel<T>
// }
abstract class ICoreHttpController {
abstract url: string;
abstract mainURL: string;
public router = Router();
abstract call(): Routes;
}
export class CoreHttpController<V> implements ICoreHttpController {
url: string;
mainURL: string;
validationModel: any;
routes = {
@ -25,35 +42,34 @@ export class CoreHttpController<V> implements ICoreHttpController {
public router = Router();
constructor(routerModel: IRouteModel) {
this.url = "/" + routerModel.url;
this.mainURL = "/" + routerModel.url;
this.validationModel = routerModel.validationModel;
}
call(): Routes {
if (this.routes["POST"] != null) {
this.router.post(
this.url,
this.mainURL,
validationModelMiddleware(this.validationModel),
(req, res) =>
this.requestResponseController<V>(req, res, this.routes["POST"])
);
}
if (this.routes["DELETE"] != null) {
this.router.delete(this.url, (req, res) =>
this.router.delete(this.mainURL, (req, res) =>
this.requestResponseController<V>(req, res, this.routes["DELETE"])
);
}
if (this.routes["PUT"] != null) {
this.router.put(
this.url,
this.mainURL,
validationModelMiddleware(this.validationModel),
(req, res) =>
this.requestResponseController<V>(req, res, this.routes["PUT"])
);
}
if (this.routes["GET"] != null) {
this.router.get(this.url, (req, res) =>
this.router.get(this.mainURL, (req, res) =>
this.requestResponseController<V>(req, res, this.routes["GET"])
);
}
@ -62,18 +78,17 @@ export class CoreHttpController<V> implements ICoreHttpController {
router: this.router,
};
}
public put(usecase: CallBackFunction<V>) {
public put(usecase: CallbackStrategyWithValidationModel<V>) {
this.routes["PUT"] = usecase;
}
public delete(usecase: CallBackFunction<V>) {
public delete(usecase: CallbackStrategyWithValidationModel<V>) {
this.routes["DELETE"] = usecase;
}
public async requestResponseController<T>(
req: Request,
res: Response,
usecase: CallBackFunction<T>
usecase: CallbackStrategyWithValidationModel<T>
) {
let payload = null;
if (req["model"] != undefined) {
@ -98,11 +113,11 @@ export class CoreHttpController<V> implements ICoreHttpController {
}
);
}
public post(usecase: CallBackFunction<V>) {
public post(usecase: CallbackStrategyWithValidationModel<V>) {
this.routes["POST"] = usecase;
}
public get(usecase: CallBackFunction<V>) {
public get(usecase: CallbackStrategyWithValidationModel<V>) {
this.routes["GET"] = usecase;
}
}

View file

@ -1,12 +1,15 @@
// import { RequestHandler } from "express";
import { RequestHandler } from "express";
// export const validationMiddleware = (
// type: any,
// value = 'body',
// skipMissingProperties = false,
// whitelist = true,
// forbidNonWhitelisted = true,
// ): RequestHandler => {
// }
export const validationMiddleware = (
type: any,
value = "body",
skipMissingProperties = false,
whitelist = true,
forbidNonWhitelisted = true
): RequestHandler => {
// TODO:(IDONTSUDO) need TOKEN
// return nextTick
return (req, res, next) => {
}
};

View file

@ -1,5 +1,4 @@
export enum EventsFileChanger {
remove = "remove",
update = "update",
delete = "delete",
create = "create",
@ -18,6 +17,7 @@ export class MetaDataFileManagerModel {
this.event = event;
this.unixTime = Date.now();
}
public get timeString(): string {
const date = new Date(this.unixTime * 1000);
const hours = date.getHours();

View file

@ -1,7 +1,6 @@
export interface IPipelineMeta {
pipelineIsRunning: boolean;
projectUUID?: string | null;
lastProcessCompleteCount: number | null;
error: any;
}
pipelineIsRunning: boolean;
projectUUID?: string | null;
lastProcessCompleteCount: number | null;
error: any;
}

View file

@ -9,9 +9,7 @@ import { EXEC_TYPE, ExecError, SpawnError } from "../model/exec_error_model";
abstract class IExecutorProgramService {
abstract execPath: string;
}
class P{
}
export class ExecutorProgramService
extends TypedEvent<Result<ExecError | SpawnError, ExecutorResult>>
implements IExecutorProgramService

View file

@ -34,11 +34,12 @@ export class PipelineRealTimeService extends TypedEvent<IPipelineMeta> {
this.iterationErrorObserver(iteration);
// TODO(IDONTSUDO): implements
// this.iterationLogSaver()
this.iterationLogSaver(iteration);
}
iterationLogSaver() {
throw new Error("Method not implemented.");
iterationLogSaver(iteration: Iteration): void {
// throw new Error("Method not implemented.");
// citeration.result.data
}
iterationErrorObserver(iteration: Iteration): void {
@ -70,8 +71,7 @@ export class PipelineRealTimeService extends TypedEvent<IPipelineMeta> {
path: string,
projectUUID: string
): void {
const testPath = path + "/context";
const stack = new StackService(pipelineModels, testPath);
const stack = new StackService(pipelineModels, path);
this.status["projectUUID"] = projectUUID;
this.status["pipelineIsRunning"] = true;
stack.on(this.pipelineSubscriber);

View file

@ -51,6 +51,7 @@ export class StackService
"$PATH",
this.path
);
console.log(processMetaData.process.command)
return processMetaData;
}
public async call() {

View file

@ -1,4 +1,4 @@
import { IsMongoId, IsEnum, IsOptional } from "class-validator";
import { IsMongoId, IsOptional } from "class-validator";
import { Schema, model } from "mongoose";
import { IProcess, StackGenerateType } from "../../core/model/process_model";
import { TriggerModel, triggerSchema } from "../triggers/trigger_model";

View file

@ -12,5 +12,4 @@ export class PipelinePresentation extends CrudController<
databaseModel: PipelineDBModel,
});
}
}

View file

@ -3,7 +3,7 @@ import { PipelineModel, schemaPipeline } from "../pipelines/pipeline_model";
import { IsArray, IsOptional, IsString } from "class-validator";
export interface IProjectModel {
_id: string;
_id?:string;
pipelines: [PipelineModel];
rootDir: string;
description: string;

View file

@ -11,6 +11,7 @@ export class RealTimeValidationModel {
public id: string;
}
export class RealTimePresentation extends CoreHttpController<RealTimeValidationModel> {
constructor() {
super({
@ -20,5 +21,6 @@ export class RealTimePresentation extends CoreHttpController<RealTimeValidationM
});
super.post(new RunInstancePipelineUseCase().call);
super.get(new PipelineStatusUseCase().call);
}
}

View file

@ -1,4 +1,6 @@
import { App } from "../../../core/controllers/app";
import { Result } from "../../../core/helper/result";
import { EXEC_TYPE } from "../../../core/model/exec_error_model";
import { ReadByIdDataBaseModelUseCase } from "../../../core/usecases/read_by_id_database_model_usecase";
import { IProjectModel, ProjectDBModel } from "../../projects/projects_model";
import {
@ -18,13 +20,19 @@ export class RunInstancePipelineUseCase {
}
const projectModel = readByIdDataBaseModelUseCase.value;
projectModel.pipelines.map((el) => {
el.process.type = EXEC_TYPE.EXEC;
});
pipelineRealTimeService.runPipeline(
projectModel.pipelines,
projectModel.rootDir,
App.staticFilesStoreDir() + projectModel.rootDir + "/",
projectModel._id
);
return Result.ok({ status: "ok" });
}
}
// /Users/idontsudo/Desktop/testdeck-mocha-seed/server/build/public/ce4e7710-73dc-47fc-87ee-d448ea2412ce
// new ObjectId("6554c22d2ef337587505a494")

View file

@ -1,11 +1,12 @@
import { EXEC_TYPE } from "../../src/core/model/exec_error_model";
import {
IPipeline,
IssueType,
StackGenerateType,
} from "../../src/core/model/process_model";
import { TriggerType } from "../../src/features/triggers/trigger_model";
export const mockSimplePipeline = [
export const mockSimplePipeline:IPipeline[] = [
{
process: {
type: EXEC_TYPE.EXEC,