model filling
This commit is contained in:
parent
c27c061c15
commit
6ca82f8c2e
29 changed files with 245 additions and 132 deletions
3
server/.gitignore
vendored
3
server/.gitignore
vendored
|
@ -6,4 +6,5 @@ node_modules/
|
|||
coverage
|
||||
package-lock.json
|
||||
.*.swp
|
||||
build/
|
||||
build/
|
||||
model_create.ts
|
|
@ -40,6 +40,7 @@
|
|||
"first-di": "^1.0.11",
|
||||
"md5": "^2.3.0",
|
||||
"mongoose": "^7.6.2",
|
||||
"mongoose-autopopulate": "^1.1.0",
|
||||
"node-watch": "^0.7.4",
|
||||
"nodemon": "^3.0.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
|
|
|
@ -5,7 +5,7 @@ import locator from "../di/register_di";
|
|||
import { DevEnv, UnitTestEnv } from "../di/env";
|
||||
import mongoose from "mongoose";
|
||||
import http from "http";
|
||||
import { Server } from "socket.io";
|
||||
// import { Server } from "socket.io";
|
||||
|
||||
export class App {
|
||||
public app: express.Application;
|
||||
|
@ -14,13 +14,14 @@ export class App {
|
|||
public computedFolder: string;
|
||||
// public io:
|
||||
constructor(routes: Routes[], computedFolder: string) {
|
||||
this.app = express();
|
||||
this.port = Number(process.env.PORT) || 3000;
|
||||
this.port = 3000;
|
||||
this.env = "dev";
|
||||
this.initializeMiddlewares();
|
||||
this.initializeRoutes(routes);
|
||||
this.loadAppDependencies();
|
||||
this.computedFolder = computedFolder;
|
||||
this.loadAppDependencies().then(() => {
|
||||
this.app = express();
|
||||
this.initializeMiddlewares();
|
||||
this.initializeRoutes(routes);
|
||||
this.computedFolder = computedFolder;
|
||||
});
|
||||
}
|
||||
|
||||
public listen() {
|
||||
|
@ -28,6 +29,7 @@ export class App {
|
|||
// const io = new Server(httpServer);
|
||||
|
||||
httpServer.listen(this.port, () => {
|
||||
console.log(this.port);
|
||||
console.info(`=================================`);
|
||||
console.info(`======= ENV: ${this.env} =======`);
|
||||
console.info(`🚀 HTTP http://localhost:${this.port}`);
|
||||
|
@ -44,7 +46,6 @@ export class App {
|
|||
// io.emit("goodbye");
|
||||
// console.log(200);
|
||||
// }, 1000);
|
||||
|
||||
}
|
||||
|
||||
public getServer() {
|
||||
|
@ -62,8 +63,8 @@ export class App {
|
|||
this.app.use("/", route.router);
|
||||
});
|
||||
}
|
||||
loadAppDependencies() {
|
||||
locator(
|
||||
async loadAppDependencies() {
|
||||
await locator(
|
||||
this.env == "development"
|
||||
? new DevEnv(this.computedFolder)
|
||||
: new UnitTestEnv(this.computedFolder)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
import { Service } from "typedi";
|
||||
|
||||
@Service()
|
||||
export class IEnv{
|
||||
rootFolder!: string;
|
||||
constructor(){
|
||||
|
@ -12,7 +14,8 @@ export class IEnv{
|
|||
}
|
||||
}
|
||||
|
||||
export class DevEnv implements IEnv {
|
||||
@Service()
|
||||
export class DevEnv implements IEnv {
|
||||
rootFolder:string;
|
||||
constructor(rootFolder:string){
|
||||
this.rootFolder = rootFolder
|
||||
|
@ -25,7 +28,7 @@ export class IEnv{
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
@Service()
|
||||
export class UnitTestEnv implements IEnv{
|
||||
rootFolder:string;
|
||||
constructor(rootFolder:string){
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// import { override } from "first-di";
|
||||
import { DevEnv, IEnv, UnitTestEnv } from "./env";
|
||||
import { MetaDataFileManagerModel } from "../model/meta_data_file_manager_model";
|
||||
import { extensions } from "../extensions/extensions";
|
||||
import { Container, Service } from 'typedi';
|
||||
|
||||
export default function locator(env: IEnv) {
|
||||
extensions();
|
||||
|
|
|
@ -2,4 +2,5 @@ import { ArrayEquals } from "./array";
|
|||
|
||||
export const extensions = () =>{
|
||||
ArrayEquals()
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,8 @@ import { Trigger } from "../../features/triggers/trigger_model";
|
|||
import { EXEC_TYPE } from "./exec_error_model";
|
||||
|
||||
|
||||
export interface ProcessMetaData {
|
||||
process: Process;
|
||||
export interface IPipeline {
|
||||
process: IProcess;
|
||||
trigger: Trigger;
|
||||
env: Env | null;
|
||||
stackGenerateType:StackGenerateType;
|
||||
|
@ -20,7 +20,7 @@ export interface Env {
|
|||
isExtends: string;
|
||||
}
|
||||
|
||||
export interface Process {
|
||||
export interface IProcess {
|
||||
type: EXEC_TYPE;
|
||||
command: string;
|
||||
isGenerating: boolean;
|
||||
|
|
|
@ -2,7 +2,7 @@ import {
|
|||
FilesChangeNotifierService,
|
||||
IHashesCache,
|
||||
} from "./files_change_notifier_service";
|
||||
import { ProcessMetaData } from "../model/process_model";
|
||||
import { IPipeline } from "../model/process_model";
|
||||
import { ExecutorProgramService } from "./executor_program_service";
|
||||
import {
|
||||
EXEC_EVENT,
|
||||
|
@ -18,27 +18,27 @@ import { Trigger } from "../../features/triggers/trigger_model";
|
|||
|
||||
export interface Iteration {
|
||||
hashes: IHashesCache | null;
|
||||
process: ProcessMetaData;
|
||||
process: IPipeline;
|
||||
result?: ExecError | SpawnError | ExecutorResult;
|
||||
}
|
||||
|
||||
export abstract class IStackService {
|
||||
abstract callStack: Iteration[];
|
||||
abstract path: string;
|
||||
abstract init(processed: ProcessMetaData[], path: string): void;
|
||||
abstract init(processed: IPipeline[], path: string): void;
|
||||
}
|
||||
|
||||
export class StackService extends TypedEvent<string> implements IStackService {
|
||||
callStack: Iteration[];
|
||||
path: string;
|
||||
constructor(processed: ProcessMetaData[], path: string) {
|
||||
constructor(processed: IPipeline[], path: string) {
|
||||
super();
|
||||
this.path = path;
|
||||
this.callStack = [];
|
||||
this.init(processed);
|
||||
}
|
||||
|
||||
public init(processed: ProcessMetaData[]) {
|
||||
public init(processed: IPipeline[]) {
|
||||
for (let el of processed) {
|
||||
el = this.commandHandler(el);
|
||||
this.callStack.push({
|
||||
|
@ -47,7 +47,7 @@ export class StackService extends TypedEvent<string> implements IStackService {
|
|||
});
|
||||
}
|
||||
}
|
||||
private commandHandler(processMetaData: ProcessMetaData) {
|
||||
private commandHandler(processMetaData: IPipeline) {
|
||||
processMetaData.process.command = processMetaData.process.command.replace(
|
||||
"$PATH",
|
||||
this.path
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
import { IsArray, IsString, IsOptional } from "class-validator";
|
||||
import { Schema, model } from "mongoose";
|
||||
|
||||
export interface ICompositionModel {
|
||||
|
||||
}
|
||||
|
||||
export const CompositionSchema = new Schema({
|
||||
|
||||
});
|
||||
|
||||
const schema = "Composition";
|
||||
|
||||
export const CompositionDBModel = model<ICompositionModel>(schema, CompositionSchema);
|
||||
|
||||
export class CompositionModel implements ICompositionModel {
|
||||
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
import { CrudController } from "../../core/controllers/crud_controller";
|
||||
import { CompositionDBModel, CompositionModel } from "./composition_model";
|
||||
|
||||
export class CompositionPresentation extends CrudController<
|
||||
CompositionModel,
|
||||
typeof CompositionDBModel
|
||||
> {
|
||||
constructor() {
|
||||
super({
|
||||
url: "compositions",
|
||||
validationModel: CompositionModel,
|
||||
databaseModel: CompositionDBModel,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
import { IsArray, IsString, IsOptional } from "class-validator";
|
||||
import { Schema, model } from "mongoose";
|
||||
|
||||
export interface IFunctionsModel {
|
||||
|
||||
}
|
||||
|
||||
export const FunctionsSchema = new Schema({
|
||||
|
||||
});
|
||||
|
||||
const schema = "Functions";
|
||||
|
||||
export const FunctionsDBModel = model<IFunctionsModel>(schema, FunctionsSchema);
|
||||
|
||||
export class FunctionsModel implements IFunctionsModel {
|
||||
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
import { CrudController } from "../../core/controllers/crud_controller";
|
||||
import { FunctionsDBModel, FunctionsModel } from "./functions_model";
|
||||
|
||||
export class FunctionsPresentation extends CrudController<
|
||||
FunctionsModel,
|
||||
typeof FunctionsDBModel
|
||||
> {
|
||||
constructor() {
|
||||
super({
|
||||
url: "functions",
|
||||
validationModel: FunctionsModel,
|
||||
databaseModel: FunctionsDBModel,
|
||||
});
|
||||
}
|
||||
}
|
47
server/src/features/pipelines/pipeline_model.ts
Normal file
47
server/src/features/pipelines/pipeline_model.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { IsMongoId, IsEnum } from "class-validator";
|
||||
import { Schema, model } from "mongoose";
|
||||
import { StackGenerateType } from "../../core/model/process_model";
|
||||
import {
|
||||
TriggerModel,
|
||||
triggerSchema,
|
||||
} from "../triggers/trigger_model";
|
||||
import { schemaProcess } from "../process/process_model";
|
||||
|
||||
export const PipelineSchema = new Schema({
|
||||
process: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: schemaProcess,
|
||||
autopopulate: true,
|
||||
default: null,
|
||||
},
|
||||
trigger: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: triggerSchema,
|
||||
autopopulate: true,
|
||||
default: null,
|
||||
},
|
||||
command: {
|
||||
type: String,
|
||||
},
|
||||
}).plugin(require("mongoose-autopopulate"));
|
||||
|
||||
export const schemaPipeline = "Pipeline";
|
||||
|
||||
export const PipelineDBModel = model<PipelineModel>(
|
||||
schemaPipeline,
|
||||
PipelineSchema
|
||||
);
|
||||
|
||||
export class PipelineModel {
|
||||
@IsMongoId()
|
||||
public process: PipelineModel;
|
||||
|
||||
@IsMongoId()
|
||||
//TODO(IDONTSUDO):NEED OPTION DECORATOR??
|
||||
public trigger: TriggerModel;
|
||||
|
||||
public env = null;
|
||||
|
||||
@IsEnum(StackGenerateType)
|
||||
public stackGenerateType: StackGenerateType;
|
||||
}
|
16
server/src/features/pipelines/pipeline_presentation.ts
Normal file
16
server/src/features/pipelines/pipeline_presentation.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
import { CrudController } from "../../core/controllers/crud_controller";
|
||||
import { PipelineDBModel, PipelineModel } from "./pipeline_model";
|
||||
|
||||
export class PipelinePresentation extends CrudController<
|
||||
PipelineModel,
|
||||
typeof PipelineDBModel
|
||||
> {
|
||||
constructor() {
|
||||
super({
|
||||
url: "pipeline",
|
||||
validationModel: PipelineModel,
|
||||
databaseModel: PipelineDBModel,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
74
server/src/features/process/process_model.ts
Normal file
74
server/src/features/process/process_model.ts
Normal file
|
@ -0,0 +1,74 @@
|
|||
import {
|
||||
IsString,
|
||||
IsOptional,
|
||||
ValidateNested,
|
||||
IsEnum,
|
||||
IsMongoId,
|
||||
IsNumber,
|
||||
IsBoolean,
|
||||
} from "class-validator";
|
||||
import { ObjectId, Schema, model } from "mongoose";
|
||||
import {
|
||||
IProcess,
|
||||
IPipeline,
|
||||
IssueType,
|
||||
StackGenerateType,
|
||||
} from "../../core/model/process_model";
|
||||
import { Type } from "class-transformer";
|
||||
import { EXEC_TYPE } from "../../core/model/exec_error_model";
|
||||
|
||||
export const ProcessSchema = new Schema({
|
||||
type: {
|
||||
type: String,
|
||||
},
|
||||
command: {
|
||||
type: String,
|
||||
},
|
||||
isGenerating: {
|
||||
type: String,
|
||||
},
|
||||
isLocaleCode: {
|
||||
type: String,
|
||||
},
|
||||
issueType: {
|
||||
type: String,
|
||||
},
|
||||
timeout: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
commit: {
|
||||
type: String,
|
||||
default: null,
|
||||
},
|
||||
});
|
||||
|
||||
export const schemaProcess = "Process";
|
||||
|
||||
export const ProcessDBModel = model<IProcess>(schemaProcess, ProcessSchema);
|
||||
|
||||
export class ProcessModel implements IProcess {
|
||||
@IsEnum(EXEC_TYPE)
|
||||
public type: EXEC_TYPE;
|
||||
|
||||
@IsString()
|
||||
public command: string;
|
||||
|
||||
@IsBoolean()
|
||||
public isGenerating: boolean;
|
||||
|
||||
@IsBoolean()
|
||||
public isLocaleCode: boolean;
|
||||
|
||||
@IsEnum(IssueType)
|
||||
public issueType: IssueType;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
public timeout?: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
public commit?: string;
|
||||
}
|
||||
|
15
server/src/features/process/process_presentation.ts
Normal file
15
server/src/features/process/process_presentation.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import { CrudController } from "../../core/controllers/crud_controller";
|
||||
import { ProcessDBModel, ProcessModel } from "./process_model";
|
||||
|
||||
export class ProcessPresentation extends CrudController<
|
||||
ProcessModel,
|
||||
typeof ProcessDBModel
|
||||
> {
|
||||
constructor() {
|
||||
super({
|
||||
url: "process",
|
||||
validationModel: ProcessModel,
|
||||
databaseModel: ProcessDBModel,
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,14 +1,42 @@
|
|||
import { IsArray, IsString, IsOptional } from "class-validator";
|
||||
import { Schema, model } from "mongoose";
|
||||
import mongoose, { Schema, model } from "mongoose";
|
||||
import { PipelineModel, schemaPipeline } from "../pipelines/pipeline_model";
|
||||
|
||||
export interface IProjectModel {
|
||||
pipelines: [PipelineModel];
|
||||
rootDir: string;
|
||||
}
|
||||
|
||||
export interface IProjectModel {}
|
||||
|
||||
export const ProjectSchema = new Schema({
|
||||
|
||||
});
|
||||
pipelines: {
|
||||
type: Array<Schema.Types.ObjectId>,
|
||||
ref: schemaPipeline,
|
||||
autopopulate: true,
|
||||
default: null,
|
||||
},
|
||||
rootDir: {
|
||||
type: String,
|
||||
},
|
||||
}).plugin(require("mongoose-autopopulate"));
|
||||
|
||||
const schema = "Projects";
|
||||
|
||||
export const ProjectDBModel = model<IProjectModel>(schema, ProjectSchema);
|
||||
|
||||
export class ProjectModel implements IProjectModel {}
|
||||
export class ProjectModel implements IProjectModel {
|
||||
pipelines: [PipelineModel];
|
||||
rootDir: string;
|
||||
}
|
||||
|
||||
// export class ProcessModel implements IProcessMetaData {
|
||||
|
||||
// public process: IProcess;
|
||||
|
||||
// public trigger: ObjectId;
|
||||
|
||||
// // TODO(IDONTSUDO): later, when maintaining many environments, you will need to make a table
|
||||
// public env = null;
|
||||
|
||||
// @IsEnum(StackGenerateType)
|
||||
// public stackGenerateType: StackGenerateType;
|
||||
// }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { IsArray, IsString, IsOptional } from "class-validator";
|
||||
import { IsArray, IsOptional, IsEnum} from "class-validator";
|
||||
import { Schema, model } from "mongoose";
|
||||
|
||||
export interface ITriggerModel {
|
||||
|
@ -18,16 +18,20 @@ export const TriggerSchema = new Schema({
|
|||
},
|
||||
});
|
||||
|
||||
const schema = "Trigger";
|
||||
export const triggerSchema = "Trigger";
|
||||
|
||||
export const TriggerDBModel = model<ITriggerModel>(schema, TriggerSchema);
|
||||
export const TriggerDBModel = model<ITriggerModel>(triggerSchema, TriggerSchema);
|
||||
|
||||
export enum TriggerType {
|
||||
PROCESS = "PROCESS",
|
||||
FILE = "FILE",
|
||||
}
|
||||
|
||||
export class TriggerModel implements ITriggerModel {
|
||||
@IsOptional()
|
||||
public _id: string;
|
||||
@IsString()
|
||||
public type: string;
|
||||
|
||||
@IsEnum(TriggerType)
|
||||
public type: TriggerType;
|
||||
@IsArray()
|
||||
public value: string[];
|
||||
}
|
||||
|
@ -36,8 +40,4 @@ export interface Trigger {
|
|||
type: TriggerType;
|
||||
value: string[];
|
||||
}
|
||||
|
||||
export enum TriggerType {
|
||||
PROCESS = "PROCESS",
|
||||
FILE = "FILE",
|
||||
}
|
||||
|
|
@ -1,21 +1,20 @@
|
|||
import "reflect-metadata";
|
||||
import { App } from "./core/controllers/app";
|
||||
import { Routes } from "./core/interfaces/router";
|
||||
import { TriggerPresentation } from "./features/triggers/triggers_presentation";
|
||||
import { ProjectsPresentation } from "./features/projects/projects_presentation";
|
||||
import { FunctionsPresentation } from "./features/functions/functions_presentation";
|
||||
import { CompositionPresentation } from "./features/compositions/compositions_presentation";
|
||||
import { Routes } from "./core/interfaces/router";
|
||||
|
||||
import { Container, Service } from 'typedi';
|
||||
import { PipelinePresentation } from "./features/pipelines/pipeline_presentation";
|
||||
import { ProcessPresentation } from "./features/process/process_presentation";
|
||||
|
||||
|
||||
const httpRoutes: Routes[] = [
|
||||
new TriggerPresentation(),
|
||||
new ProjectsPresentation(),
|
||||
new FunctionsPresentation(),
|
||||
new CompositionPresentation(),
|
||||
new ProcessPresentation(),
|
||||
new PipelinePresentation(),
|
||||
].map((el) => el.call());
|
||||
|
||||
const computedFolder = "";
|
||||
|
||||
new App(httpRoutes, computedFolder).listen();
|
||||
|
|
@ -4,7 +4,6 @@ import * as fs from "fs";
|
|||
import {
|
||||
IssueType,
|
||||
StackGenerateType,
|
||||
|
||||
} from "../../src/core/model/process_model";
|
||||
import { EXEC_TYPE } from "../../src/core/model/exec_error_model";
|
||||
import { StackService } from "../../src/core/services/stack_service";
|
|
@ -1,18 +1,17 @@
|
|||
import { fileURLToPath } from "url";
|
||||
import { TestCore } from "./core/test_core";
|
||||
import { UnitTestEnv } from "../src/core/di/env";
|
||||
import { dirname } from "path";
|
||||
import locator from "../src/core/di/register_di";
|
||||
import { ExecutorProgramServiceTest } from "./features/executor_program_service_test";
|
||||
import { FilesChangerTest } from "./features/files_change_notifier_service_test";
|
||||
import { TriggerServiceTest } from "./features/trigger_service_test";
|
||||
import { StackServiceTest } from "./features/stack_service_test";
|
||||
import { ExecutorProgramServiceTest } from "./services/executor_program_service_test";
|
||||
import { FilesChangerTest } from "./services/files_change_notifier_service_test";
|
||||
import { TriggerServiceTest } from "./services/trigger_service_test";
|
||||
import { StackServiceTest } from "./services/stack_service_test";
|
||||
import mongoose from "mongoose";
|
||||
import { CreateDataBaseModelUseCaseTest } from "./usecase/create_database_model_usecase_test";
|
||||
import { DeleteDataBaseModelUseCaseTest } from "./usecase/delete_database_model_usecase_test";
|
||||
import { ReadDataBaseModelUseCaseTest } from "./usecase/read_database_model_usecase_test";
|
||||
import { UpdateDataBaseModelUseCaseTest } from "./usecase/update_database_model_usecase";
|
||||
import { PaginationDataBaseModelUseCaseTest } from "./usecase/pagination_database_model_usecase_test";
|
||||
import { CreateDataBaseModelUseCaseTest } from "./usecases/create_database_model_usecase_test";
|
||||
import { DeleteDataBaseModelUseCaseTest } from "./usecases/delete_database_model_usecase_test";
|
||||
import { ReadDataBaseModelUseCaseTest } from "./usecases/read_database_model_usecase_test";
|
||||
import { UpdateDataBaseModelUseCaseTest } from "./usecases/update_database_model_usecase";
|
||||
import { PaginationDataBaseModelUseCaseTest } from "./usecases/pagination_database_model_usecase_test";
|
||||
|
||||
|
||||
const testCore = TestCore.instance;
|
||||
|
@ -23,6 +22,7 @@ export const resultTest = testCore.resultTest;
|
|||
const env = new UnitTestEnv(dirname__);
|
||||
|
||||
locator(env);
|
||||
|
||||
const tests = [CreateDataBaseModelUseCaseTest, DeleteDataBaseModelUseCaseTest,ReadDataBaseModelUseCaseTest,UpdateDataBaseModelUseCaseTest, PaginationDataBaseModelUseCaseTest]
|
||||
const init = async () =>{
|
||||
await mongoose.connect('mongodb://127.0.0.1:27017/test')
|
||||
|
@ -46,8 +46,6 @@ const test = async () =>{
|
|||
const main = async () => {
|
||||
await init()
|
||||
await test()
|
||||
|
||||
|
||||
await testCore.testResult();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue