refactor(core): Move final batch of entities to @n8n/db (#15061)

This commit is contained in:
Iván Ovejero
2025-05-02 17:46:05 +02:00
committed by GitHub
parent f3e29d25ed
commit bd258be052
63 changed files with 201 additions and 420 deletions

View File

@@ -1,4 +1,4 @@
import { User } from '@n8n/db';
import { User } from '../user';
describe('User Entity', () => {
describe('JSON.stringify', () => {

View File

@@ -1,9 +1,9 @@
import { WithTimestampsAndStringId } from '@n8n/db';
import { Column, Entity, Index, ManyToMany, OneToMany } from '@n8n/typeorm';
import { IsString, Length } from 'class-validator';
import type { AnnotationTagMapping } from '@/databases/entities/annotation-tag-mapping.ee';
import type { ExecutionAnnotation } from '@/databases/entities/execution-annotation.ee';
import { WithTimestampsAndStringId } from './abstract-entity';
import type { AnnotationTagMapping } from './annotation-tag-mapping.ee';
import type { ExecutionAnnotation } from './execution-annotation.ee';
@Entity()
export class AnnotationTagEntity extends WithTimestampsAndStringId {

View File

@@ -1,8 +1,7 @@
import { DateTimeColumn, AuthProviderType } from '@n8n/db';
import { Column, Entity, PrimaryGeneratedColumn } from '@n8n/typeorm';
export type RunningMode = 'dry' | 'live';
export type SyncStatus = 'success' | 'error';
import { DateTimeColumn } from './abstract-entity';
import { AuthProviderType, RunningMode, SyncStatus } from './types-db';
@Entity()
export class AuthProviderSyncHistory {

View File

@@ -1,6 +1,7 @@
import { User } from '@n8n/db';
import { Column, Entity } from '@n8n/typeorm';
import { User } from './user';
@Entity({ name: 'user' })
export class AuthUser extends User {
@Column({ type: String, nullable: true })

View File

@@ -1,8 +1,9 @@
import { JsonColumn, idStringifier } from '@n8n/db';
import { Column, Entity, ManyToOne, PrimaryColumn } from '@n8n/typeorm';
import { IWorkflowBase } from 'n8n-workflow';
import { JsonColumn } from './abstract-entity';
import { ExecutionEntity } from './execution-entity';
import { idStringifier } from '../utils/transformers';
@Entity()
export class ExecutionData {

View File

@@ -1,4 +1,3 @@
import { DateTimeColumn, datetimeColumnType, idStringifier, WorkflowEntity } from '@n8n/db';
import {
Column,
Entity,
@@ -14,10 +13,12 @@ import {
import type { SimpleColumnType } from '@n8n/typeorm/driver/types/ColumnTypes';
import { ExecutionStatus, WorkflowExecuteMode } from 'n8n-workflow';
import type { ExecutionAnnotation } from '@/databases/entities/execution-annotation.ee';
import { DateTimeColumn, datetimeColumnType } from './abstract-entity';
import type { ExecutionAnnotation } from './execution-annotation.ee';
import type { ExecutionData } from './execution-data';
import type { ExecutionMetadata } from './execution-metadata';
import { WorkflowEntity } from './workflow-entity';
import { idStringifier } from '../utils/transformers';
@Entity()
@Index(['workflowId', 'id'])

View File

@@ -1,7 +1,15 @@
import { AnnotationTagEntity } from './annotation-tag-entity.ee';
import { AnnotationTagMapping } from './annotation-tag-mapping.ee';
import { ApiKey } from './api-key';
import { AuthIdentity } from './auth-identity';
import { AuthProviderSyncHistory } from './auth-provider-sync-history';
import { AuthUser } from './auth-user';
import { CredentialsEntity } from './credentials-entity';
import { EventDestinations } from './event-destinations';
import { ExecutionAnnotation } from './execution-annotation.ee';
import { ExecutionData } from './execution-data';
import { ExecutionEntity } from './execution-entity';
import { ExecutionMetadata } from './execution-metadata';
import { Folder } from './folder';
import { FolderTagMapping } from './folder-tag-mapping';
import { InstalledNodes } from './installed-nodes';
@@ -14,10 +22,15 @@ import { Settings } from './settings';
import { SharedCredentials } from './shared-credentials';
import { SharedWorkflow } from './shared-workflow';
import { TagEntity } from './tag-entity';
import { TestCaseExecution } from './test-case-execution.ee';
import { TestDefinition } from './test-definition.ee';
import { TestMetric } from './test-metric.ee';
import { TestRun } from './test-run.ee';
import { User } from './user';
import { Variables } from './variables';
import { WebhookEntity } from './webhook-entity';
import { WorkflowEntity } from './workflow-entity';
import { WorkflowHistory } from './workflow-history';
import { WorkflowStatistics } from './workflow-statistics';
import { WorkflowTagMapping } from './workflow-tag-mapping';
@@ -44,4 +57,55 @@ export {
WorkflowStatistics,
WorkflowTagMapping,
FolderTagMapping,
AuthProviderSyncHistory,
AuthUser,
WorkflowHistory,
ExecutionData,
ExecutionMetadata,
AnnotationTagEntity,
ExecutionAnnotation,
AnnotationTagMapping,
TestDefinition,
TestMetric,
TestRun,
TestCaseExecution,
ExecutionEntity,
};
export const entities = {
EventDestinations,
InstalledNodes,
InstalledPackages,
InvalidAuthToken,
ProcessedData,
Settings,
Variables,
ApiKey,
WebhookEntity,
AuthIdentity,
CredentialsEntity,
Folder,
Project,
ProjectRelation,
SharedCredentials,
SharedWorkflow,
TagEntity,
User,
WorkflowEntity,
WorkflowStatistics,
WorkflowTagMapping,
FolderTagMapping,
AuthProviderSyncHistory,
AuthUser,
WorkflowHistory,
ExecutionData,
ExecutionMetadata,
AnnotationTagEntity,
ExecutionAnnotation,
AnnotationTagMapping,
TestDefinition,
TestMetric,
TestRun,
TestCaseExecution,
ExecutionEntity,
};

View File

@@ -1,10 +1,10 @@
import { DateTimeColumn, JsonColumn, WithStringId } from '@n8n/db';
import { Column, Entity, ManyToOne, OneToOne } from '@n8n/typeorm';
import type { IDataObject } from 'n8n-workflow';
import type { ExecutionEntity } from '@/databases/entities/execution-entity';
import { TestRun } from '@/databases/entities/test-run.ee';
import type { TestCaseExecutionErrorCode } from '@/evaluation.ee/test-runner/errors.ee';
import { WithStringId, DateTimeColumn, JsonColumn } from './abstract-entity';
import type { ExecutionEntity } from './execution-entity';
import { TestRun } from './test-run.ee';
import type { TestCaseExecutionErrorCode } from './types-db';
export type TestCaseRunMetrics = Record<string, number | boolean>;

View File

@@ -1,15 +1,11 @@
import { JsonColumn, WithTimestampsAndStringId, WorkflowEntity } from '@n8n/db';
import { Column, Entity, Index, ManyToOne, OneToMany, RelationId } from '@n8n/typeorm';
import { Length } from 'class-validator';
import { AnnotationTagEntity } from '@/databases/entities/annotation-tag-entity.ee';
import type { TestMetric } from '@/databases/entities/test-metric.ee';
// Entity representing a node in a workflow under test, for which data should be mocked during test execution
export type MockedNodeItem = {
name?: string;
id: string;
};
import { JsonColumn, WithTimestampsAndStringId } from './abstract-entity';
import { AnnotationTagEntity } from './annotation-tag-entity.ee';
import type { TestMetric } from './test-metric.ee';
import type { MockedNodeItem } from './types-db';
import { WorkflowEntity } from './workflow-entity';
/**
* Entity representing a Test Definition

View File

@@ -1,8 +1,8 @@
import { WithTimestampsAndStringId } from '@n8n/db';
import { Column, Entity, Index, ManyToOne } from '@n8n/typeorm';
import { Length } from 'class-validator';
import { TestDefinition } from '@/databases/entities/test-definition.ee';
import { WithTimestampsAndStringId } from './abstract-entity';
import { TestDefinition } from './test-definition.ee';
/**
* Entity representing a Test Metric

View File

@@ -1,16 +1,14 @@
import { WithTimestampsAndStringId, JsonColumn, DateTimeColumn } from '@n8n/db';
import { Column, Entity, Index, ManyToOne, OneToMany, RelationId } from '@n8n/typeorm';
import type { IDataObject } from 'n8n-workflow';
import type { TestCaseExecution } from '@/databases/entities/test-case-execution.ee';
import { TestDefinition } from '@/databases/entities/test-definition.ee';
import type { TestRunFinalResult } from '@/databases/repositories/test-run.repository.ee';
import type { TestRunErrorCode } from '@/evaluation.ee/test-runner/errors.ee';
import { DateTimeColumn, JsonColumn, WithTimestampsAndStringId } from './abstract-entity';
import type { TestCaseExecution } from './test-case-execution.ee';
import { TestDefinition } from './test-definition.ee';
import { AggregatedTestRunMetrics } from './types-db';
import type { TestRunErrorCode, TestRunFinalResult } from './types-db';
export type TestRunStatus = 'new' | 'running' | 'completed' | 'error' | 'cancelled';
export type AggregatedTestRunMetrics = Record<string, number | boolean>;
/**
* Entity representing a Test Run.
* It stores info about a specific run of a test, combining the test definition with the status and collected metrics

View File

@@ -278,3 +278,33 @@ export type FolderWithWorkflowAndSubFolderCount = Folder & {
workflowCount: boolean;
subFolderCount: number;
};
export type TestRunFinalResult = 'success' | 'error' | 'warning';
export type TestRunErrorCode =
| 'PAST_EXECUTIONS_NOT_FOUND'
| 'EVALUATION_WORKFLOW_NOT_FOUND'
| 'INTERRUPTED'
| 'UNKNOWN_ERROR';
export type TestCaseExecutionErrorCode =
| 'MOCKED_NODE_DOES_NOT_EXIST'
| 'TRIGGER_NO_LONGER_EXISTS'
| 'FAILED_TO_EXECUTE_WORKFLOW'
| 'EVALUATION_WORKFLOW_DOES_NOT_EXIST'
| 'FAILED_TO_EXECUTE_EVALUATION_WORKFLOW'
| 'INVALID_METRICS'
| 'PAYLOAD_LIMIT_EXCEEDED'
| 'UNKNOWN_ERROR';
export type AggregatedTestRunMetrics = Record<string, number | boolean>;
// Entity representing a node in a workflow under test, for which data should be mocked during test execution
export type MockedNodeItem = {
name?: string;
id: string;
};
export type RunningMode = 'dry' | 'live';
export type SyncStatus = 'success' | 'error';

View File

@@ -1,8 +1,10 @@
import { JsonColumn, WithTimestamps, WorkflowEntity } from '@n8n/db';
import { Column, Entity, ManyToOne, PrimaryColumn } from '@n8n/typeorm';
import { IConnections } from 'n8n-workflow';
import type { INode } from 'n8n-workflow';
import { JsonColumn, WithTimestamps } from './abstract-entity';
import { WorkflowEntity } from './workflow-entity';
@Entity()
export class WorkflowHistory extends WithTimestamps {
@PrimaryColumn()

View File

@@ -16,3 +16,5 @@ export { idStringifier, lowerCaser, objectRetriever, sqlite } from './utils/tran
export * from './entities';
export * from './entities/types-db';
export { NoXss } from './utils/validators/no-xss.validator';
export { NoUrl } from './utils/validators/no-url.validator';

View File

@@ -1,4 +1,5 @@
import type { User } from '@n8n/db';
import type { ExecutionEntity } from '@n8n/db';
import { Container } from '@n8n/di';
import { mock } from 'jest-mock-extended';
import { DirectedGraph, WorkflowExecute } from 'n8n-core';
@@ -20,7 +21,6 @@ import PCancelable from 'p-cancelable';
import { ActiveExecutions } from '@/active-executions';
import config from '@/config';
import type { ExecutionEntity } from '@/databases/entities/execution-entity';
import { ExecutionNotFoundError } from '@/errors/execution-not-found-error';
import { CredentialsPermissionChecker } from '@/executions/pre-execution-checks';
import { ManualExecutionService } from '@/manual-execution.service';

View File

@@ -1,9 +1,8 @@
import { NoXss } from '@n8n/db';
import { Expose } from 'class-transformer';
import { IsString, IsArray, IsOptional, IsEmail, IsEnum } from 'class-validator';
import type { IPersonalizationSurveyAnswersV4 } from 'n8n-workflow';
import { NoXss } from '@/validators/no-xss.validator';
export class PersonalizationSurveyAnswersV4 implements IPersonalizationSurveyAnswersV4 {
@NoXss()
@Expose()

View File

@@ -1,4 +1,5 @@
import { GlobalConfig } from '@n8n/config';
import { entities } from '@n8n/db';
import { Container } from '@n8n/di';
import type { DataSourceOptions, LoggerOptions } from '@n8n/typeorm';
import type { MysqlConnectionOptions } from '@n8n/typeorm/driver/mysql/MysqlConnectionOptions';
@@ -10,7 +11,10 @@ import { UserError } from 'n8n-workflow';
import path from 'path';
import type { TlsOptions } from 'tls';
import { entities } from './entities';
import { InsightsByPeriod } from '@/modules/insights/database/entities/insights-by-period';
import { InsightsMetadata } from '@/modules/insights/database/entities/insights-metadata';
import { InsightsRaw } from '@/modules/insights/database/entities/insights-raw';
import { mysqlMigrations } from './migrations/mysqldb';
import { postgresMigrations } from './migrations/postgresdb';
import { sqliteMigrations } from './migrations/sqlite';
@@ -32,7 +36,7 @@ const getCommonOptions = () => {
return {
entityPrefix,
entities: Object.values(entities),
entities: [...Object.values(entities), InsightsRaw, InsightsByPeriod, InsightsMetadata],
subscribers: Object.values(subscribers),
migrationsTableName: `${entityPrefix}migrations`,
migrationsRun: false,

View File

@@ -1,82 +0,0 @@
import {
EventDestinations,
InstalledNodes,
InstalledPackages,
InvalidAuthToken,
ProcessedData,
Settings,
Variables,
WebhookEntity,
AuthIdentity,
User,
WorkflowEntity,
CredentialsEntity,
ApiKey,
Folder,
FolderTagMapping,
Project,
ProjectRelation,
SharedCredentials,
SharedWorkflow,
TagEntity,
WorkflowStatistics,
WorkflowTagMapping,
} from '@n8n/db';
import { AnnotationTagEntity } from './annotation-tag-entity.ee';
import { AnnotationTagMapping } from './annotation-tag-mapping.ee';
import { AuthProviderSyncHistory } from './auth-provider-sync-history';
import { AuthUser } from './auth-user';
import { ExecutionAnnotation } from './execution-annotation.ee';
import { ExecutionData } from './execution-data';
import { ExecutionEntity } from './execution-entity';
import { ExecutionMetadata } from './execution-metadata';
import { TestCaseExecution } from './test-case-execution.ee';
import { TestDefinition } from './test-definition.ee';
import { TestMetric } from './test-metric.ee';
import { TestRun } from './test-run.ee';
import { WorkflowHistory } from './workflow-history';
import { InsightsByPeriod } from '../../modules/insights/database/entities/insights-by-period';
import { InsightsMetadata } from '../../modules/insights/database/entities/insights-metadata';
import { InsightsRaw } from '../../modules/insights/database/entities/insights-raw';
export const entities = {
AnnotationTagEntity,
AnnotationTagMapping,
AuthIdentity,
AuthProviderSyncHistory,
AuthUser,
CredentialsEntity,
EventDestinations,
ExecutionAnnotation,
ExecutionEntity,
InstalledNodes,
InstalledPackages,
InvalidAuthToken,
Settings,
SharedCredentials,
SharedWorkflow,
TagEntity,
User,
Variables,
WebhookEntity,
WorkflowEntity,
WorkflowTagMapping,
WorkflowStatistics,
ExecutionMetadata,
ExecutionData,
WorkflowHistory,
Project,
ProjectRelation,
ApiKey,
ProcessedData,
TestDefinition,
TestMetric,
TestRun,
TestCaseExecution,
Folder,
FolderTagMapping,
InsightsRaw,
InsightsMetadata,
InsightsByPeriod,
};

View File

@@ -1,6 +1,7 @@
import { GlobalConfig } from '@n8n/config';
import type { SqliteConfig } from '@n8n/config/src/configs/database.config';
import type { IExecutionResponse } from '@n8n/db';
import { ExecutionEntity } from '@n8n/db';
import { Container } from '@n8n/di';
import type { SelectQueryBuilder } from '@n8n/typeorm';
import { Not, LessThanOrEqual } from '@n8n/typeorm';
@@ -9,7 +10,6 @@ import { BinaryDataService } from 'n8n-core';
import type { IRunExecutionData, IWorkflowBase } from 'n8n-workflow';
import { nanoid } from 'nanoid';
import { ExecutionEntity } from '@/databases/entities/execution-entity';
import { ExecutionRepository } from '@/databases/repositories/execution.repository';
import { mockInstance, mockEntityManager } from '@test/mocking';

View File

@@ -1,8 +1,7 @@
import { AnnotationTagMapping } from '@n8n/db';
import { Service } from '@n8n/di';
import { DataSource, Repository } from '@n8n/typeorm';
import { AnnotationTagMapping } from '@/databases/entities/annotation-tag-mapping.ee';
@Service()
export class AnnotationTagMappingRepository extends Repository<AnnotationTagMapping> {
constructor(dataSource: DataSource) {

View File

@@ -1,8 +1,7 @@
import { AnnotationTagEntity } from '@n8n/db';
import { Service } from '@n8n/di';
import { DataSource, Repository } from '@n8n/typeorm';
import { AnnotationTagEntity } from '@/databases/entities/annotation-tag-entity.ee';
@Service()
export class AnnotationTagRepository extends Repository<AnnotationTagEntity> {
constructor(dataSource: DataSource) {

View File

@@ -1,8 +1,7 @@
import { AuthProviderSyncHistory } from '@n8n/db';
import { Service } from '@n8n/di';
import { DataSource, Repository } from '@n8n/typeorm';
import { AuthProviderSyncHistory } from '../entities/auth-provider-sync-history';
@Service()
export class AuthProviderSyncHistoryRepository extends Repository<AuthProviderSyncHistory> {
constructor(dataSource: DataSource) {

View File

@@ -1,8 +1,7 @@
import { AuthUser } from '@n8n/db';
import { Service } from '@n8n/di';
import { DataSource, Repository } from '@n8n/typeorm';
import { AuthUser } from '../entities/auth-user';
@Service()
export class AuthUserRepository extends Repository<AuthUser> {
constructor(dataSource: DataSource) {

View File

@@ -1,8 +1,7 @@
import { ExecutionAnnotation } from '@n8n/db';
import { Service } from '@n8n/di';
import { DataSource, Repository } from '@n8n/typeorm';
import { ExecutionAnnotation } from '@/databases/entities/execution-annotation.ee';
@Service()
export class ExecutionAnnotationRepository extends Repository<ExecutionAnnotation> {
constructor(dataSource: DataSource) {

View File

@@ -1,10 +1,9 @@
import { ExecutionData } from '@n8n/db';
import { Service } from '@n8n/di';
import { DataSource, In, Repository } from '@n8n/typeorm';
import type { EntityManager } from '@n8n/typeorm';
import type { QueryDeepPartialEntity } from '@n8n/typeorm/query-builder/QueryPartialEntity';
import { ExecutionData } from '../entities/execution-data';
@Service()
export class ExecutionDataRepository extends Repository<ExecutionData> {
constructor(dataSource: DataSource) {

View File

@@ -1,8 +1,7 @@
import { ExecutionMetadata } from '@n8n/db';
import { Service } from '@n8n/di';
import { DataSource, Repository } from '@n8n/typeorm';
import { ExecutionMetadata } from '../entities/execution-metadata';
@Service()
export class ExecutionMetadataRepository extends Repository<ExecutionMetadata> {
constructor(dataSource: DataSource) {

View File

@@ -6,7 +6,17 @@ import type {
IExecutionResponse,
ExecutionSummaries,
} from '@n8n/db';
import { separate, SharedWorkflow, WorkflowEntity } from '@n8n/db';
import {
separate,
SharedWorkflow,
WorkflowEntity,
AnnotationTagEntity,
AnnotationTagMapping,
ExecutionData,
ExecutionEntity,
ExecutionAnnotation,
ExecutionMetadata,
} from '@n8n/db';
import { Service } from '@n8n/di';
import type {
FindManyOptions,
@@ -39,15 +49,9 @@ import type {
IRunExecutionData,
} from 'n8n-workflow';
import { AnnotationTagEntity } from '@/databases/entities/annotation-tag-entity.ee';
import { AnnotationTagMapping } from '@/databases/entities/annotation-tag-mapping.ee';
import { ExecutionAnnotation } from '@/databases/entities/execution-annotation.ee';
import { PostgresLiveRowsRetrievalError } from '@/errors/postgres-live-rows-retrieval.error';
import { ExecutionDataRepository } from './execution-data.repository';
import { ExecutionData } from '../entities/execution-data';
import { ExecutionEntity } from '../entities/execution-entity';
import { ExecutionMetadata } from '../entities/execution-metadata';
export interface IGetExecutionsQueryFilter {
id?: FindOperator<string> | string;

View File

@@ -1,12 +1,11 @@
import { TestCaseExecution } from '@n8n/db';
import type { TestCaseExecutionErrorCode } from '@n8n/db';
import { Service } from '@n8n/di';
import type { EntityManager } from '@n8n/typeorm';
import { DataSource, In, Not, Repository } from '@n8n/typeorm';
import type { DeepPartial } from '@n8n/typeorm/common/DeepPartial';
import type { IDataObject } from 'n8n-workflow';
import { TestCaseExecution } from '@/databases/entities/test-case-execution.ee';
import type { TestCaseExecutionErrorCode } from '@/evaluation.ee/test-runner/errors.ee';
type StatusUpdateOptions = {
testRunId: string;
pastExecutionId: string;

View File

@@ -1,8 +1,8 @@
import { TestDefinition } from '@n8n/db';
import { Service } from '@n8n/di';
import type { FindManyOptions, FindOptionsWhere } from '@n8n/typeorm';
import { DataSource, In, Repository } from '@n8n/typeorm';
import { TestDefinition } from '@/databases/entities/test-definition.ee';
import { ForbiddenError } from '@/errors/response-errors/forbidden.error';
import type { ListQuery } from '@/requests';

View File

@@ -1,8 +1,7 @@
import { TestMetric } from '@n8n/db';
import { Service } from '@n8n/di';
import { DataSource, Repository } from '@n8n/typeorm';
import { TestMetric } from '@/databases/entities/test-metric.ee';
@Service()
export class TestMetricRepository extends Repository<TestMetric> {
constructor(dataSource: DataSource) {

View File

@@ -1,17 +1,14 @@
import type { AggregatedTestRunMetrics, TestRunErrorCode, TestRunFinalResult } from '@n8n/db';
import { TestRun } from '@n8n/db';
import { Service } from '@n8n/di';
import type { EntityManager, FindManyOptions } from '@n8n/typeorm';
import { DataSource, In, Repository } from '@n8n/typeorm';
import type { IDataObject } from 'n8n-workflow';
import type { AggregatedTestRunMetrics } from '@/databases/entities/test-run.ee';
import { TestRun } from '@/databases/entities/test-run.ee';
import { NotFoundError } from '@/errors/response-errors/not-found.error';
import type { TestRunErrorCode } from '@/evaluation.ee/test-runner/errors.ee';
import { getTestRunFinalResult } from '@/evaluation.ee/test-runner/utils.ee';
import type { ListQuery } from '@/requests';
export type TestRunFinalResult = 'success' | 'error' | 'warning';
export type TestRunSummary = TestRun & {
finalResult: TestRunFinalResult | null;
};

View File

@@ -1,8 +1,7 @@
import { WorkflowHistory } from '@n8n/db';
import { Service } from '@n8n/di';
import { DataSource, LessThan, Repository } from '@n8n/typeorm';
import { WorkflowHistory } from '../entities/workflow-history';
@Service()
export class WorkflowHistoryRepository extends Repository<WorkflowHistory> {
constructor(dataSource: DataSource) {

View File

@@ -1,6 +1,6 @@
import type { MockedNodeItem, TestDefinition } from '@n8n/db';
import { Service } from '@n8n/di';
import type { MockedNodeItem, TestDefinition } from '@/databases/entities/test-definition.ee';
import { AnnotationTagRepository } from '@/databases/repositories/annotation-tag.repository.ee';
import { TestDefinitionRepository } from '@/databases/repositories/test-definition.repository.ee';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';

View File

@@ -1,4 +1,5 @@
import type { MockedNodeItem } from '@/databases/entities/test-definition.ee';
import type { MockedNodeItem } from '@n8n/db';
import type { AuthenticatedRequest, ListQuery } from '@/requests';
// ----------------------------------

View File

@@ -1,6 +1,6 @@
import type { TestCaseExecution } from '@n8n/db';
import { mock } from 'jest-mock-extended';
import type { TestCaseExecution } from '@/databases/entities/test-case-execution.ee';
import { getTestRunFinalResult } from '@/evaluation.ee/test-runner/utils.ee';
function mockTestCaseExecutions(statuses: Array<TestCaseExecution['status']>) {

View File

@@ -1,19 +1,19 @@
import type { User } from '@n8n/db';
import type { ExecutionEntity } from '@n8n/db';
import type { TestDefinition } from '@n8n/db';
import type { TestMetric } from '@n8n/db';
import type { TestRun } from '@n8n/db';
import type { SelectQueryBuilder } from '@n8n/typeorm';
import { stringify } from 'flatted';
import { readFileSync } from 'fs';
import { mock, mockDeep } from 'jest-mock-extended';
import type { ErrorReporter } from 'n8n-core';
import type { ExecutionError, GenericValue, IRun } from 'n8n-workflow';
import type { ITaskData } from 'n8n-workflow';
import type { ExecutionError, GenericValue, IRun } from 'n8n-workflow';
import path from 'path';
import type { ActiveExecutions } from '@/active-executions';
import config from '@/config';
import type { ExecutionEntity } from '@/databases/entities/execution-entity';
import type { TestDefinition } from '@/databases/entities/test-definition.ee';
import type { TestMetric } from '@/databases/entities/test-metric.ee';
import type { TestRun } from '@/databases/entities/test-run.ee';
import type { ExecutionRepository } from '@/databases/repositories/execution.repository';
import type { TestCaseExecutionRepository } from '@/databases/repositories/test-case-execution.repository.ee';
import type { TestMetricRepository } from '@/databases/repositories/test-metric.repository.ee';

View File

@@ -1,15 +1,6 @@
import type { TestCaseExecutionErrorCode, TestRunErrorCode } from '@n8n/db';
import { UnexpectedError } from 'n8n-workflow';
export type TestCaseExecutionErrorCode =
| 'MOCKED_NODE_DOES_NOT_EXIST'
| 'TRIGGER_NO_LONGER_EXISTS'
| 'FAILED_TO_EXECUTE_WORKFLOW'
| 'EVALUATION_WORKFLOW_DOES_NOT_EXIST'
| 'FAILED_TO_EXECUTE_EVALUATION_WORKFLOW'
| 'INVALID_METRICS'
| 'PAYLOAD_LIMIT_EXCEEDED'
| 'UNKNOWN_ERROR';
export class TestCaseExecutionError extends UnexpectedError {
readonly code: TestCaseExecutionErrorCode;
@@ -20,12 +11,6 @@ export class TestCaseExecutionError extends UnexpectedError {
}
}
export type TestRunErrorCode =
| 'PAST_EXECUTIONS_NOT_FOUND'
| 'EVALUATION_WORKFLOW_NOT_FOUND'
| 'INTERRUPTED'
| 'UNKNOWN_ERROR';
export class TestRunError extends UnexpectedError {
readonly code: TestRunErrorCode;

View File

@@ -1,4 +1,4 @@
import type { User } from '@n8n/db';
import type { User, ExecutionEntity, MockedNodeItem, TestDefinition, TestRun } from '@n8n/db';
import { Service } from '@n8n/di';
import { parse } from 'flatted';
import difference from 'lodash/difference';
@@ -17,9 +17,6 @@ import assert from 'node:assert';
import { ActiveExecutions } from '@/active-executions';
import config from '@/config';
import { EVALUATION_METRICS_NODE } from '@/constants';
import type { ExecutionEntity } from '@/databases/entities/execution-entity';
import type { MockedNodeItem, TestDefinition } from '@/databases/entities/test-definition.ee';
import type { TestRun } from '@/databases/entities/test-run.ee';
import { ExecutionRepository } from '@/databases/repositories/execution.repository';
import { TestCaseExecutionRepository } from '@/databases/repositories/test-case-execution.repository.ee';
import { TestMetricRepository } from '@/databases/repositories/test-metric.repository.ee';

View File

@@ -1,3 +1,4 @@
import type { TestCaseExecution, MockedNodeItem, TestRunFinalResult } from '@n8n/db';
import assert from 'assert';
import { mapValues, pick } from 'lodash';
import type {
@@ -9,9 +10,6 @@ import type {
INode,
} from 'n8n-workflow';
import type { TestCaseExecution } from '@/databases/entities/test-case-execution.ee';
import type { MockedNodeItem } from '@/databases/entities/test-definition.ee';
import type { TestRunFinalResult } from '@/databases/repositories/test-run.repository.ee';
import { TestCaseExecutionError } from '@/evaluation.ee/test-runner/errors.ee';
import type { TestCaseRunMetadata } from '@/evaluation.ee/test-runner/test-runner.service.ee';

View File

@@ -1,4 +1,4 @@
import type { ExecutionSummaries } from '@n8n/db';
import type { ExecutionSummaries, ExecutionEntity } from '@n8n/db';
import type {
AnnotationVote,
ExecutionStatus,
@@ -6,7 +6,6 @@ import type {
WorkflowExecuteMode,
} from 'n8n-workflow';
import type { ExecutionEntity } from '@/databases/entities/execution-entity';
import type { AuthenticatedRequest } from '@/requests';
export declare namespace ExecutionRequest {

View File

@@ -1,9 +1,13 @@
import type { CredentialsEntity, User, WorkflowEntity, TagEntity } from '@n8n/db';
import type {
CredentialsEntity,
User,
WorkflowEntity,
TagEntity,
AnnotationTagEntity,
TestDefinition,
} from '@n8n/db';
import { validate } from 'class-validator';
import type { AnnotationTagEntity } from '@/databases/entities/annotation-tag-entity.ee';
import type { TestDefinition } from '@/databases/entities/test-definition.ee';
import type { PersonalizationSurveyAnswersV4 } from './controllers/survey-answers.dto';
import { BadRequestError } from './errors/response-errors/bad-request.error';

View File

@@ -1,4 +1,5 @@
import { AuthIdentity, User } from '@n8n/db';
import type { AuthProviderSyncHistory } from '@n8n/db';
import { Container } from '@n8n/di';
import { validate } from 'jsonschema';
import type { Entry as LdapUser } from 'ldapts';
@@ -6,7 +7,6 @@ import { Filter } from 'ldapts/filters/Filter';
import { randomString } from 'n8n-workflow';
import config from '@/config';
import type { AuthProviderSyncHistory } from '@/databases/entities/auth-provider-sync-history';
import { AuthIdentityRepository } from '@/databases/repositories/auth-identity.repository';
import { AuthProviderSyncHistoryRepository } from '@/databases/repositories/auth-provider-sync-history.repository';
import { UserRepository } from '@/databases/repositories/user.repository';

View File

@@ -1,4 +1,4 @@
import type { User } from '@n8n/db';
import type { User, RunningMode, SyncStatus } from '@n8n/db';
import { Service } from '@n8n/di';
// eslint-disable-next-line n8n-local-rules/misplaced-n8n-typeorm-import
import { QueryFailedError } from '@n8n/typeorm';
@@ -9,7 +9,6 @@ import { jsonParse, UnexpectedError } from 'n8n-workflow';
import type { ConnectionOptions } from 'tls';
import config from '@/config';
import type { RunningMode, SyncStatus } from '@/databases/entities/auth-provider-sync-history';
import { SettingsRepository } from '@/databases/repositories/settings.repository';
import { BadRequestError } from '@/errors/response-errors/bad-request.error';
import { InternalServerError } from '@/errors/response-errors/internal-server.error';

View File

@@ -1,4 +1,5 @@
import type { RunningMode } from '@/databases/entities/auth-provider-sync-history';
import type { RunningMode } from '@n8n/db';
import type { AuthenticatedRequest } from '@/requests';
export type ConnectionSecurity = 'none' | 'tls' | 'startTls';

View File

@@ -1,5 +1,5 @@
import type { ProjectIcon, ProjectRole, ProjectType } from '@n8n/api-types';
import type { Variables, Project, User, ListQueryDb } from '@n8n/db';
import type { Variables, Project, User, ListQueryDb, WorkflowHistory } from '@n8n/db';
import type { AssignableRole, GlobalRole, Scope } from '@n8n/permissions';
import type express from 'express';
import type {
@@ -8,8 +8,6 @@ import type {
IPersonalizationSurveyAnswersV4,
} from 'n8n-workflow';
import type { WorkflowHistory } from '@/databases/entities/workflow-history';
export type APIRequest<
RouteParams = {},
ResponseBody = {},

View File

@@ -1,9 +1,9 @@
import type { AuthUser } from '@n8n/db';
import RudderStack from '@rudderstack/rudder-sdk-node';
import type { Response } from 'express';
import { mock } from 'jest-mock-extended';
import type { AuthService } from '@/auth/auth.service';
import type { AuthUser } from '@/databases/entities/auth-user';
import type { AuthUserRepository } from '@/databases/repositories/auth-user.repository';
import type { CredentialsRepository } from '@/databases/repositories/credentials.repository';
import type { SettingsRepository } from '@/databases/repositories/settings.repository';

View File

@@ -1,6 +1,6 @@
import type { AnnotationTagEntity } from '@n8n/db';
import { Service } from '@n8n/di';
import type { AnnotationTagEntity } from '@/databases/entities/annotation-tag-entity.ee';
import { AnnotationTagRepository } from '@/databases/repositories/annotation-tag.repository.ee';
import { validateEntity } from '@/generic-helpers';

View File

@@ -1,6 +1,6 @@
import type { ExecutionMetadata } from '@n8n/db';
import { Service } from '@n8n/di';
import type { ExecutionMetadata } from '@/databases/entities/execution-metadata';
import { ExecutionMetadataRepository } from '@/databases/repositories/execution-metadata.repository';
@Service()

View File

@@ -1,4 +1,4 @@
import type { Settings, CredentialsEntity, User, WorkflowEntity } from '@n8n/db';
import type { Settings, CredentialsEntity, User, WorkflowEntity, AuthUser } from '@n8n/db';
import { Service } from '@n8n/di';
// eslint-disable-next-line n8n-local-rules/misplaced-n8n-typeorm-import
import type { FindManyOptions, FindOneOptions, FindOptionsWhere } from '@n8n/typeorm';
@@ -7,7 +7,6 @@ import RudderStack, { type constructorOptions } from '@rudderstack/rudder-sdk-no
import type { NextFunction, Response } from 'express';
import { AuthService } from '@/auth/auth.service';
import type { AuthUser } from '@/databases/entities/auth-user';
import { AuthUserRepository } from '@/databases/repositories/auth-user.repository';
import { CredentialsRepository } from '@/databases/repositories/credentials.repository';
import { SettingsRepository } from '@/databases/repositories/settings.repository';

View File

@@ -1,27 +0,0 @@
import { validate } from 'class-validator';
import { NoUrl } from '../no-url.validator';
describe('NoUrl', () => {
class Entity {
@NoUrl()
name = '';
}
const entity = new Entity();
describe('URLs', () => {
const URLS = ['http://google.com', 'www.domain.tld', 'n8n.io'];
for (const str of URLS) {
test(`should block ${str}`, async () => {
entity.name = str;
const errors = await validate(entity);
expect(errors).toHaveLength(1);
const [error] = errors;
expect(error.property).toEqual('name');
expect(error.constraints).toEqual({ NoUrl: 'Potentially malicious string' });
});
}
});
});

View File

@@ -1,118 +0,0 @@
import { validate } from 'class-validator';
import { NoXss } from '../no-xss.validator';
describe('NoXss', () => {
class Entity {
@NoXss()
name = '';
@NoXss()
timestamp = '';
@NoXss()
version = '';
@NoXss({ each: true })
categories: string[] = [];
}
const entity = new Entity();
describe('Scripts', () => {
// eslint-disable-next-line n8n-local-rules/no-unneeded-backticks
const XSS_STRINGS = ['<script src/>', "<script>alert('xss')</script>", `<a href="#">Jack</a>`];
for (const str of XSS_STRINGS) {
test(`should block ${str}`, async () => {
entity.name = str;
const errors = await validate(entity);
expect(errors).toHaveLength(1);
const [error] = errors;
expect(error.property).toEqual('name');
expect(error.constraints).toEqual({ NoXss: 'Potentially malicious string' });
});
}
});
describe('Names', () => {
const VALID_NAMES = [
'Johann Strauß',
'Вагиф Сәмәдоғлу',
'René Magritte',
'সুকুমার রায়',
'མགོན་པོ་རྡོ་རྗེ།',
'عبدالحليم حافظ',
];
for (const name of VALID_NAMES) {
test(`should allow ${name}`, async () => {
entity.name = name;
expect(await validate(entity)).toBeEmptyArray();
});
}
});
describe('ISO-8601 timestamps', () => {
const VALID_TIMESTAMPS = ['2022-01-01T00:00:00.000Z', '2022-01-01T00:00:00.000+02:00'];
for (const timestamp of VALID_TIMESTAMPS) {
test(`should allow ${timestamp}`, async () => {
entity.timestamp = timestamp;
await expect(validate(entity)).resolves.toBeEmptyArray();
});
}
});
describe('Semver versions', () => {
const VALID_VERSIONS = ['1.0.0', '1.0.0-alpha.1'];
for (const version of VALID_VERSIONS) {
test(`should allow ${version}`, async () => {
entity.version = version;
await expect(validate(entity)).resolves.toBeEmptyArray();
});
}
});
describe('Miscellaneous strings', () => {
const VALID_MISCELLANEOUS_STRINGS = ['CI/CD'];
for (const str of VALID_MISCELLANEOUS_STRINGS) {
test(`should allow ${str}`, async () => {
entity.name = str;
await expect(validate(entity)).resolves.toBeEmptyArray();
});
}
});
describe('Array of strings', () => {
const VALID_STRING_ARRAYS = [
['cloud-infrastructure-orchestration', 'ci-cd', 'reporting'],
['automationGoalDevops', 'cloudComputing', 'containerization'],
];
for (const arr of VALID_STRING_ARRAYS) {
test(`should allow array: ${JSON.stringify(arr)}`, async () => {
entity.categories = arr;
await expect(validate(entity)).resolves.toBeEmptyArray();
});
}
const INVALID_STRING_ARRAYS = [
['valid-string', '<script>alert("xss")</script>', 'another-valid-string'],
['<img src="x" onerror="alert(\'XSS\')">', 'valid-string'],
];
for (const arr of INVALID_STRING_ARRAYS) {
test(`should reject array containing invalid string: ${JSON.stringify(arr)}`, async () => {
entity.categories = arr;
const errors = await validate(entity);
expect(errors).toHaveLength(1);
const [error] = errors;
expect(error.property).toEqual('categories');
expect(error.constraints).toEqual({ NoXss: 'Potentially malicious string' });
});
}
});
});

View File

@@ -1,27 +0,0 @@
import type { ValidationOptions, ValidatorConstraintInterface } from 'class-validator';
import { registerDecorator, ValidatorConstraint } from 'class-validator';
const URL_REGEX = /^(https?:\/\/|www\.)|(\.[\p{L}\d-]+)/iu;
@ValidatorConstraint({ name: 'NoUrl', async: false })
class NoUrlConstraint implements ValidatorConstraintInterface {
validate(value: string) {
return !URL_REGEX.test(value);
}
defaultMessage() {
return 'Potentially malicious string';
}
}
export function NoUrl(options?: ValidationOptions) {
return function (object: object, propertyName: string) {
registerDecorator({
name: 'NoUrl',
target: object.constructor,
propertyName,
options,
validator: NoUrlConstraint,
});
};
}

View File

@@ -1,33 +0,0 @@
import type { ValidationOptions, ValidatorConstraintInterface } from 'class-validator';
import { registerDecorator, ValidatorConstraint } from 'class-validator';
import xss from 'xss';
@ValidatorConstraint({ name: 'NoXss', async: false })
class NoXssConstraint implements ValidatorConstraintInterface {
validate(value: unknown) {
if (typeof value !== 'string') return false;
return (
value ===
xss(value, {
whiteList: {}, // no tags are allowed
})
);
}
defaultMessage() {
return 'Potentially malicious string';
}
}
export function NoXss(options?: ValidationOptions) {
return function (object: object, propertyName: string) {
registerDecorator({
name: 'NoXss',
target: object.constructor,
propertyName,
options,
validator: NoXssConstraint,
});
};
}

View File

@@ -1,10 +1,9 @@
import type { User } from '@n8n/db';
import type { User, WorkflowHistory } from '@n8n/db';
import { Service } from '@n8n/di';
import { Logger } from 'n8n-core';
import type { IWorkflowBase } from 'n8n-workflow';
import { ensureError } from 'n8n-workflow';
import type { WorkflowHistory } from '@/databases/entities/workflow-history';
import { WorkflowHistoryRepository } from '@/databases/repositories/workflow-history.repository';
import { SharedWorkflowNotFoundError } from '@/errors/shared-workflow-not-found.error';
import { WorkflowHistoryVersionNotFoundError } from '@/errors/workflow-history-version-not-found.error';

View File

@@ -1,9 +1,9 @@
import type { User } from '@n8n/db';
import type { AnnotationTagEntity } from '@n8n/db';
import { Container } from '@n8n/di';
import { mockInstance } from 'n8n-core/test/utils';
import type { IWorkflowBase } from 'n8n-workflow';
import type { AnnotationTagEntity } from '@/databases/entities/annotation-tag-entity.ee';
import { TestDefinitionRepository } from '@/databases/repositories/test-definition.repository.ee';
import { TestRunnerService } from '@/evaluation.ee/test-runner/test-runner.service.ee';
import { createAnnotationTags } from '@test-integration/db/executions';

View File

@@ -1,9 +1,9 @@
import type { User } from '@n8n/db';
import type { TestDefinition } from '@n8n/db';
import { Container } from '@n8n/di';
import { mockInstance } from 'n8n-core/test/utils';
import type { IWorkflowBase } from 'n8n-workflow';
import type { TestDefinition } from '@/databases/entities/test-definition.ee';
import { ProjectRepository } from '@/databases/repositories/project.repository';
import { TestDefinitionRepository } from '@/databases/repositories/test-definition.repository.ee';
import { TestRunRepository } from '@/databases/repositories/test-run.repository.ee';

View File

@@ -1,10 +1,10 @@
import { ExecutionsConfig } from '@n8n/config';
import type { ExecutionEntity } from '@n8n/db';
import { Container } from '@n8n/di';
import { BinaryDataService, InstanceSettings } from 'n8n-core';
import type { ExecutionStatus, IWorkflowBase } from 'n8n-workflow';
import { Time } from '@/constants';
import type { ExecutionEntity } from '@/databases/entities/execution-entity';
import { ExecutionRepository } from '@/databases/repositories/execution.repository';
import { PruningService } from '@/services/pruning/pruning.service';

View File

@@ -1,7 +1,7 @@
import type { User } from '@n8n/db';
import type { ExecutionEntity } from '@n8n/db';
import type { ActiveWorkflowManager } from '@/active-workflow-manager';
import type { ExecutionEntity } from '@/databases/entities/execution-entity';
import { Telemetry } from '@/telemetry';
import { mockInstance } from '@test/mocking';
import { createTeamProject } from '@test-integration/db/projects';

View File

@@ -1,8 +1,8 @@
import type { ExecutionEntity } from '@n8n/db';
import type { ExecutionData } from '@n8n/db';
import { Container } from '@n8n/di';
import type { AnnotationVote, IWorkflowBase } from 'n8n-workflow';
import type { ExecutionData } from '@/databases/entities/execution-data';
import type { ExecutionEntity } from '@/databases/entities/execution-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';

View File

@@ -1,7 +1,7 @@
import type { WorkflowHistory } from '@n8n/db';
import { Container } from '@n8n/di';
import { v4 as uuid } from 'uuid';
import type { WorkflowHistory } from '@/databases/entities/workflow-history';
import { WorkflowHistoryRepository } from '@/databases/repositories/workflow-history.repository';
export async function createWorkflowHistoryItem(