refactor(core): Use IWorkflowBase over WorkflowEntity in most places (#13225)

This commit is contained in:
Tomi Turtiainen
2025-02-13 10:54:11 +02:00
committed by GitHub
parent 11cf1cd23a
commit f001edb2a2
54 changed files with 190 additions and 192 deletions

View File

@@ -1,9 +1,8 @@
import { Container } from '@n8n/di';
import type { AnnotationVote } from 'n8n-workflow';
import type { AnnotationVote, IWorkflowBase } from 'n8n-workflow';
import type { ExecutionData } from '@/databases/entities/execution-data';
import type { ExecutionEntity } from '@/databases/entities/execution-entity';
import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
import { AnnotationTagRepository } from '@/databases/repositories/annotation-tag.repository.ee';
import { ExecutionDataRepository } from '@/databases/repositories/execution-data.repository';
import { ExecutionMetadataRepository } from '@/databases/repositories/execution-metadata.repository';
@@ -16,8 +15,8 @@ mockInstance(Telemetry);
export async function createManyExecutions(
amount: number,
workflow: WorkflowEntity,
callback: (workflow: WorkflowEntity) => Promise<ExecutionEntity>,
workflow: IWorkflowBase,
callback: (workflow: IWorkflowBase) => Promise<ExecutionEntity>,
) {
const executionsRequests = [...Array(amount)].map(async (_) => await callback(workflow));
return await Promise.all(executionsRequests);
@@ -31,7 +30,7 @@ export async function createExecution(
Omit<ExecutionEntity, 'metadata'> &
ExecutionData & { metadata: Array<{ key: string; value: string }> }
>,
workflow: WorkflowEntity,
workflow: IWorkflowBase,
) {
const { data, finished, mode, startedAt, stoppedAt, waitTill, status, deletedAt, metadata } =
attributes;
@@ -70,14 +69,14 @@ export async function createExecution(
/**
* Store a successful execution in the DB and assign it to a workflow.
*/
export async function createSuccessfulExecution(workflow: WorkflowEntity) {
export async function createSuccessfulExecution(workflow: IWorkflowBase) {
return await createExecution({ finished: true, status: 'success' }, workflow);
}
/**
* Store an error execution in the DB and assign it to a workflow.
*/
export async function createErrorExecution(workflow: WorkflowEntity) {
export async function createErrorExecution(workflow: IWorkflowBase) {
return await createExecution(
{ finished: false, stoppedAt: new Date(), status: 'error' },
workflow,
@@ -87,7 +86,7 @@ export async function createErrorExecution(workflow: WorkflowEntity) {
/**
* Store a waiting execution in the DB and assign it to a workflow.
*/
export async function createWaitingExecution(workflow: WorkflowEntity) {
export async function createWaitingExecution(workflow: IWorkflowBase) {
return await createExecution(
{ finished: false, waitTill: new Date(), status: 'waiting' },
workflow,

View File

@@ -1,14 +1,14 @@
import { Container } from '@n8n/di';
import type { IWorkflowBase } from 'n8n-workflow';
import type { TagEntity } from '@/databases/entities/tag-entity';
import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
import { TagRepository } from '@/databases/repositories/tag.repository';
import { WorkflowTagMappingRepository } from '@/databases/repositories/workflow-tag-mapping.repository';
import { generateNanoId } from '@/databases/utils/generators';
import { randomName } from '../random';
export async function createTag(attributes: Partial<TagEntity> = {}, workflow?: WorkflowEntity) {
export async function createTag(attributes: Partial<TagEntity> = {}, workflow?: IWorkflowBase) {
const { name } = attributes;
const tag = await Container.get(TagRepository).save({

View File

@@ -1,19 +1,20 @@
import { Container } from '@n8n/di';
import type { DeepPartial } from '@n8n/typeorm';
import type { IWorkflowBase } from 'n8n-workflow';
import { NodeConnectionType } from 'n8n-workflow';
import { v4 as uuid } from 'uuid';
import { Project } from '@/databases/entities/project';
import type { SharedWorkflow, WorkflowSharingRole } from '@/databases/entities/shared-workflow';
import { User } from '@/databases/entities/user';
import type { WorkflowEntity } from '@/databases/entities/workflow-entity';
import { ProjectRepository } from '@/databases/repositories/project.repository';
import { SharedWorkflowRepository } from '@/databases/repositories/shared-workflow.repository';
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
import type { IWorkflowDb } from '@/interfaces';
export async function createManyWorkflows(
amount: number,
attributes: Partial<WorkflowEntity> = {},
attributes: Partial<IWorkflowDb> = {},
user?: User,
) {
const workflowRequests = [...Array(amount)].map(
@@ -22,7 +23,7 @@ export async function createManyWorkflows(
return await Promise.all(workflowRequests);
}
export function newWorkflow(attributes: Partial<WorkflowEntity> = {}): WorkflowEntity {
export function newWorkflow(attributes: Partial<IWorkflowDb> = {}): IWorkflowDb {
const { active, name, nodes, connections, versionId } = attributes;
const workflowEntity = Container.get(WorkflowRepository).create({
@@ -53,7 +54,7 @@ export function newWorkflow(attributes: Partial<WorkflowEntity> = {}): WorkflowE
* @param user user to assign the workflow to
*/
export async function createWorkflow(
attributes: Partial<WorkflowEntity> = {},
attributes: Partial<IWorkflowDb> = {},
userOrProject?: User | Project,
) {
const workflow = await Container.get(WorkflowRepository).save(newWorkflow(attributes));
@@ -84,7 +85,7 @@ export async function createWorkflow(
return workflow;
}
export async function shareWorkflowWithUsers(workflow: WorkflowEntity, users: User[]) {
export async function shareWorkflowWithUsers(workflow: IWorkflowBase, users: User[]) {
const sharedWorkflows: Array<DeepPartial<SharedWorkflow>> = await Promise.all(
users.map(async (user) => {
const project = await Container.get(ProjectRepository).getPersonalProjectForUserOrFail(
@@ -101,7 +102,7 @@ export async function shareWorkflowWithUsers(workflow: WorkflowEntity, users: Us
}
export async function shareWorkflowWithProjects(
workflow: WorkflowEntity,
workflow: IWorkflowBase,
projectsWithRole: Array<{ project: Project; role?: WorkflowSharingRole }>,
) {
const newSharedWorkflow = await Promise.all(
@@ -117,7 +118,7 @@ export async function shareWorkflowWithProjects(
return await Container.get(SharedWorkflowRepository).save(newSharedWorkflow);
}
export async function getWorkflowSharing(workflow: WorkflowEntity) {
export async function getWorkflowSharing(workflow: IWorkflowBase) {
return await Container.get(SharedWorkflowRepository).findBy({
workflowId: workflow.id,
});
@@ -128,7 +129,7 @@ export async function getWorkflowSharing(workflow: WorkflowEntity) {
* @param user user to assign the workflow to
*/
export async function createWorkflowWithTrigger(
attributes: Partial<WorkflowEntity> = {},
attributes: Partial<IWorkflowDb> = {},
user?: User,
) {
const workflow = await createWorkflow(