mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 12:57:29 -08:00
refactor(core): Consolidate executions controllers (no-changelog) (#8349)
This commit is contained in:
parent
b267bf07e3
commit
7bb2d1799e
|
@ -39,7 +39,8 @@ import {
|
|||
TEMPLATES_DIR,
|
||||
} from '@/constants';
|
||||
import { credentialsController } from '@/credentials/credentials.controller';
|
||||
import type { CurlHelper, ExecutionRequest } from '@/requests';
|
||||
import type { CurlHelper } from '@/requests';
|
||||
import type { ExecutionRequest } from '@/executions/execution.request';
|
||||
import { registerController } from '@/decorators';
|
||||
import { AuthController } from '@/controllers/auth.controller';
|
||||
import { BinaryDataController } from '@/controllers/binaryData.controller';
|
||||
|
@ -56,7 +57,7 @@ import { TranslationController } from '@/controllers/translation.controller';
|
|||
import { UsersController } from '@/controllers/users.controller';
|
||||
import { WorkflowStatisticsController } from '@/controllers/workflowStatistics.controller';
|
||||
import { ExternalSecretsController } from '@/ExternalSecrets/ExternalSecrets.controller.ee';
|
||||
import { executionsController } from '@/executions/executions.controller';
|
||||
import { ExecutionsController } from '@/executions/executions.controller';
|
||||
import { isApiEnabled, loadPublicApiVersions } from '@/PublicApi';
|
||||
import type { ICredentialsOverwrite, IDiagnosticInfo, IExecutionsStopData } from '@/Interfaces';
|
||||
import { ActiveExecutions } from '@/ActiveExecutions';
|
||||
|
@ -247,6 +248,7 @@ export class Server extends AbstractServer {
|
|||
RoleController,
|
||||
ActiveWorkflowsController,
|
||||
WorkflowsController,
|
||||
ExecutionsController,
|
||||
];
|
||||
|
||||
if (process.env.NODE_ENV !== 'production' && Container.get(MultiMainSetup).isEnabled) {
|
||||
|
@ -397,12 +399,6 @@ export class Server extends AbstractServer {
|
|||
}),
|
||||
);
|
||||
|
||||
// ----------------------------------------
|
||||
// Executions
|
||||
// ----------------------------------------
|
||||
|
||||
this.app.use(`/${this.restEndpoint}/executions`, executionsController);
|
||||
|
||||
// ----------------------------------------
|
||||
// Executing Workflows
|
||||
// ----------------------------------------
|
||||
|
|
|
@ -4,7 +4,7 @@ import type { WorkflowStatistics } from '@db/entities/WorkflowStatistics';
|
|||
import { StatisticsNames } from '@db/entities/WorkflowStatistics';
|
||||
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
|
||||
import { WorkflowStatisticsRepository } from '@db/repositories/workflowStatistics.repository';
|
||||
import { ExecutionRequest } from '@/requests';
|
||||
import { ExecutionRequest } from '@/executions/execution.request';
|
||||
import type { IWorkflowStatisticsDataLoaded } from '@/Interfaces';
|
||||
import { Logger } from '@/Logger';
|
||||
import { NotFoundError } from '@/errors/response-errors/not-found.error';
|
||||
|
|
29
packages/cli/src/executions/execution.request.ts
Normal file
29
packages/cli/src/executions/execution.request.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import type { IExecutionDeleteFilter } from '@/Interfaces';
|
||||
import type { AuthenticatedRequest } from '@/requests';
|
||||
|
||||
export declare namespace ExecutionRequest {
|
||||
namespace QueryParam {
|
||||
type GetAll = {
|
||||
filter: string; // '{ waitTill: string; finished: boolean, [other: string]: string }'
|
||||
limit: string;
|
||||
lastId: string;
|
||||
firstId: string;
|
||||
};
|
||||
|
||||
type GetAllCurrent = {
|
||||
filter: string; // '{ workflowId: string }'
|
||||
};
|
||||
}
|
||||
|
||||
type GetAll = AuthenticatedRequest<{}, {}, {}, QueryParam.GetAll>;
|
||||
|
||||
type Get = AuthenticatedRequest<{ id: string }, {}, {}, { unflattedResponse: 'true' | 'false' }>;
|
||||
|
||||
type Delete = AuthenticatedRequest<{}, {}, IExecutionDeleteFilter>;
|
||||
|
||||
type Retry = AuthenticatedRequest<{ id: string }, {}, { loadWorkflow: boolean }, {}>;
|
||||
|
||||
type Stop = AuthenticatedRequest<{ id: string }>;
|
||||
|
||||
type GetAllCurrent = AuthenticatedRequest<{}, {}, {}, QueryParam.GetAllCurrent>;
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
import express from 'express';
|
||||
import type {
|
||||
IExecutionFlattedResponse,
|
||||
IExecutionResponse,
|
||||
IExecutionsListResponse,
|
||||
} from '@/Interfaces';
|
||||
import type { ExecutionRequest } from '@/requests';
|
||||
import * as ResponseHelper from '@/ResponseHelper';
|
||||
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
|
||||
import { EEExecutionsService } from './executions.service.ee';
|
||||
|
||||
export const EEExecutionsController = express.Router();
|
||||
|
||||
EEExecutionsController.use((req, res, next) => {
|
||||
if (!isSharingEnabled()) {
|
||||
// skip ee router and use free one
|
||||
next('router');
|
||||
return;
|
||||
}
|
||||
// use ee router
|
||||
next();
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /executions
|
||||
*/
|
||||
EEExecutionsController.get(
|
||||
'/',
|
||||
ResponseHelper.send(async (req: ExecutionRequest.GetAll): Promise<IExecutionsListResponse> => {
|
||||
return EEExecutionsService.getExecutionsList(req);
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* GET /executions/:id
|
||||
*/
|
||||
EEExecutionsController.get(
|
||||
'/:id(\\d+)',
|
||||
ResponseHelper.send(
|
||||
async (
|
||||
req: ExecutionRequest.Get,
|
||||
): Promise<IExecutionResponse | IExecutionFlattedResponse | undefined> => {
|
||||
return EEExecutionsService.getExecution(req);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* POST /executions/:id/retry
|
||||
*/
|
||||
EEExecutionsController.post(
|
||||
'/:id/retry',
|
||||
ResponseHelper.send(async (req: ExecutionRequest.Retry): Promise<boolean> => {
|
||||
return EEExecutionsService.retryExecution(req);
|
||||
}),
|
||||
);
|
||||
|
||||
/**
|
||||
* POST /executions/delete
|
||||
* INFORMATION: We use POST instead of DELETE to not run into any issues with the query data
|
||||
* getting too long
|
||||
*/
|
||||
EEExecutionsController.post(
|
||||
'/delete',
|
||||
ResponseHelper.send(async (req: ExecutionRequest.Delete): Promise<void> => {
|
||||
await EEExecutionsService.deleteExecutions(req);
|
||||
}),
|
||||
);
|
|
@ -1,59 +1,31 @@
|
|||
import express from 'express';
|
||||
import type {
|
||||
IExecutionFlattedResponse,
|
||||
IExecutionResponse,
|
||||
IExecutionsListResponse,
|
||||
} from '@/Interfaces';
|
||||
import * as ResponseHelper from '@/ResponseHelper';
|
||||
import type { ExecutionRequest } from '@/requests';
|
||||
import { EEExecutionsController } from './executions.controller.ee';
|
||||
import { ExecutionRequest } from './execution.request';
|
||||
import { ExecutionsService } from './executions.service';
|
||||
import { Authorized, Get, Post, RestController } from '@/decorators';
|
||||
import { EnterpriseExecutionsService } from './executions.service.ee';
|
||||
import { isSharingEnabled } from '@/UserManagement/UserManagementHelper';
|
||||
|
||||
export const executionsController = express.Router();
|
||||
executionsController.use('/', EEExecutionsController);
|
||||
|
||||
/**
|
||||
* GET /executions
|
||||
*/
|
||||
executionsController.get(
|
||||
'/',
|
||||
ResponseHelper.send(async (req: ExecutionRequest.GetAll): Promise<IExecutionsListResponse> => {
|
||||
@Authorized()
|
||||
@RestController('/executions')
|
||||
export class ExecutionsController {
|
||||
@Get('/')
|
||||
async getExecutionsList(req: ExecutionRequest.GetAll) {
|
||||
return ExecutionsService.getExecutionsList(req);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /executions/:id
|
||||
*/
|
||||
executionsController.get(
|
||||
'/:id(\\d+)',
|
||||
ResponseHelper.send(
|
||||
async (
|
||||
req: ExecutionRequest.Get,
|
||||
): Promise<IExecutionResponse | IExecutionFlattedResponse | undefined> => {
|
||||
return ExecutionsService.getExecution(req);
|
||||
},
|
||||
),
|
||||
);
|
||||
@Get('/:id')
|
||||
async getExecution(req: ExecutionRequest.Get) {
|
||||
return isSharingEnabled()
|
||||
? EnterpriseExecutionsService.getExecution(req)
|
||||
: ExecutionsService.getExecution(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /executions/:id/retry
|
||||
*/
|
||||
executionsController.post(
|
||||
'/:id/retry',
|
||||
ResponseHelper.send(async (req: ExecutionRequest.Retry): Promise<boolean> => {
|
||||
@Post('/:id/retry')
|
||||
async retryExecution(req: ExecutionRequest.Retry) {
|
||||
return ExecutionsService.retryExecution(req);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /executions/delete
|
||||
* INFORMATION: We use POST instead of DELETE to not run into any issues with the query data
|
||||
* getting too long
|
||||
*/
|
||||
executionsController.post(
|
||||
'/delete',
|
||||
ResponseHelper.send(async (req: ExecutionRequest.Delete): Promise<void> => {
|
||||
await ExecutionsService.deleteExecutions(req);
|
||||
}),
|
||||
);
|
||||
@Post('/delete')
|
||||
async deleteExecutions(req: ExecutionRequest.Delete) {
|
||||
return ExecutionsService.deleteExecutions(req);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import type { User } from '@db/entities/User';
|
||||
import { getSharedWorkflowIds } from '@/WorkflowHelpers';
|
||||
import { ExecutionsService } from './executions.service';
|
||||
import type { ExecutionRequest } from '@/requests';
|
||||
import type { ExecutionRequest } from './execution.request';
|
||||
import type { IExecutionResponse, IExecutionFlattedResponse } from '@/Interfaces';
|
||||
import { EnterpriseWorkflowService } from '../workflows/workflow.service.ee';
|
||||
import type { WorkflowWithSharingsAndCredentials } from '@/workflows/workflows.types';
|
||||
import Container from 'typedi';
|
||||
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
|
||||
|
||||
export class EEExecutionsService extends ExecutionsService {
|
||||
export class EnterpriseExecutionsService extends ExecutionsService {
|
||||
/**
|
||||
* Function to get the workflow Ids for a User regardless of role
|
||||
*/
|
||||
|
|
|
@ -21,7 +21,7 @@ import type {
|
|||
} from '@/Interfaces';
|
||||
import { NodeTypes } from '@/NodeTypes';
|
||||
import { Queue } from '@/Queue';
|
||||
import type { ExecutionRequest } from '@/requests';
|
||||
import type { ExecutionRequest } from './execution.request';
|
||||
import { getSharedWorkflowIds } from '@/WorkflowHelpers';
|
||||
import { WorkflowRunner } from '@/WorkflowRunner';
|
||||
import * as GenericHelpers from '@/GenericHelpers';
|
||||
|
|
|
@ -13,12 +13,7 @@ import type {
|
|||
|
||||
import { IsBoolean, IsEmail, IsIn, IsOptional, IsString, Length } from 'class-validator';
|
||||
import { NoXss } from '@db/utils/customValidators';
|
||||
import type {
|
||||
PublicUser,
|
||||
IExecutionDeleteFilter,
|
||||
SecretsProvider,
|
||||
SecretsProviderState,
|
||||
} from '@/Interfaces';
|
||||
import type { PublicUser, SecretsProvider, SecretsProviderState } from '@/Interfaces';
|
||||
import type { Role, RoleNames } from '@db/entities/Role';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { UserManagementMailer } from '@/UserManagement/email';
|
||||
|
@ -171,32 +166,6 @@ export declare namespace CredentialRequest {
|
|||
type Share = AuthenticatedRequest<{ credentialId: string }, {}, { shareWithIds: string[] }>;
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
// /executions
|
||||
// ----------------------------------
|
||||
|
||||
export declare namespace ExecutionRequest {
|
||||
namespace QueryParam {
|
||||
type GetAll = {
|
||||
filter: string; // '{ waitTill: string; finished: boolean, [other: string]: string }'
|
||||
limit: string;
|
||||
lastId: string;
|
||||
firstId: string;
|
||||
};
|
||||
|
||||
type GetAllCurrent = {
|
||||
filter: string; // '{ workflowId: string }'
|
||||
};
|
||||
}
|
||||
|
||||
type GetAll = AuthenticatedRequest<{}, {}, {}, QueryParam.GetAll>;
|
||||
type Get = AuthenticatedRequest<{ id: string }, {}, {}, { unflattedResponse: 'true' | 'false' }>;
|
||||
type Delete = AuthenticatedRequest<{}, {}, IExecutionDeleteFilter>;
|
||||
type Retry = AuthenticatedRequest<{ id: string }, {}, { loadWorkflow: boolean }, {}>;
|
||||
type Stop = AuthenticatedRequest<{ id: string }>;
|
||||
type GetAllCurrent = AuthenticatedRequest<{}, {}, {}, QueryParam.GetAllCurrent>;
|
||||
}
|
||||
|
||||
// ----------------------------------
|
||||
// /me
|
||||
// ----------------------------------
|
||||
|
|
|
@ -131,8 +131,8 @@ export const setupTestServer = ({
|
|||
break;
|
||||
|
||||
case 'executions':
|
||||
const { executionsController } = await import('@/executions/executions.controller');
|
||||
app.use(`/${REST_PATH_SEGMENT}/executions`, executionsController);
|
||||
const { ExecutionsController } = await import('@/executions/executions.controller');
|
||||
registerController(app, ExecutionsController);
|
||||
break;
|
||||
|
||||
case 'variables':
|
||||
|
|
Loading…
Reference in a new issue