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,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(