-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Execution curation (#10342)
Co-authored-by: oleg <me@olegivaniv.com>
- Loading branch information
1 parent
8603946
commit 022ddcb
Showing
75 changed files
with
2,746 additions
and
726 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/cli/src/controllers/annotation-tags.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Delete, Get, Patch, Post, RestController, GlobalScope } from '@/decorators'; | ||
import { AnnotationTagService } from '@/services/annotation-tag.service'; | ||
import { AnnotationTagsRequest } from '@/requests'; | ||
|
||
@RestController('/annotation-tags') | ||
export class AnnotationTagsController { | ||
constructor(private readonly annotationTagService: AnnotationTagService) {} | ||
|
||
@Get('/') | ||
@GlobalScope('annotationTag:list') | ||
async getAll(req: AnnotationTagsRequest.GetAll) { | ||
return await this.annotationTagService.getAll({ | ||
withUsageCount: req.query.withUsageCount === 'true', | ||
}); | ||
} | ||
|
||
@Post('/') | ||
@GlobalScope('annotationTag:create') | ||
async createTag(req: AnnotationTagsRequest.Create) { | ||
const tag = this.annotationTagService.toEntity({ name: req.body.name }); | ||
|
||
return await this.annotationTagService.save(tag); | ||
} | ||
|
||
@Patch('/:id(\\w+)') | ||
@GlobalScope('annotationTag:update') | ||
async updateTag(req: AnnotationTagsRequest.Update) { | ||
const newTag = this.annotationTagService.toEntity({ | ||
id: req.params.id, | ||
name: req.body.name.trim(), | ||
}); | ||
|
||
return await this.annotationTagService.save(newTag); | ||
} | ||
|
||
@Delete('/:id(\\w+)') | ||
@GlobalScope('annotationTag:delete') | ||
async deleteTag(req: AnnotationTagsRequest.Delete) { | ||
const { id } = req.params; | ||
|
||
await this.annotationTagService.delete(id); | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/cli/src/databases/entities/annotation-tag-entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Column, Entity, Index, ManyToMany, OneToMany } from '@n8n/typeorm'; | ||
import { IsString, Length } from 'class-validator'; | ||
import { WithTimestampsAndStringId } from './abstract-entity'; | ||
import type { ExecutionAnnotation } from '@/databases/entities/execution-annotation'; | ||
import type { AnnotationTagMapping } from '@/databases/entities/annotation-tag-mapping'; | ||
|
||
@Entity() | ||
export class AnnotationTagEntity extends WithTimestampsAndStringId { | ||
@Column({ length: 24 }) | ||
@Index({ unique: true }) | ||
@IsString({ message: 'Tag name must be of type string.' }) | ||
@Length(1, 24, { message: 'Tag name must be $constraint1 to $constraint2 characters long.' }) | ||
name: string; | ||
|
||
@ManyToMany('ExecutionAnnotation', 'tags') | ||
annotations: ExecutionAnnotation[]; | ||
|
||
@OneToMany('AnnotationTagMapping', 'tags') | ||
annotationMappings: AnnotationTagMapping[]; | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/cli/src/databases/entities/annotation-tag-mapping.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Entity, JoinColumn, ManyToOne, PrimaryColumn } from '@n8n/typeorm'; | ||
import type { ExecutionAnnotation } from './execution-annotation'; | ||
import type { AnnotationTagEntity } from './annotation-tag-entity'; | ||
|
||
/** | ||
* This entity represents the junction table between the execution annotations and the tags | ||
*/ | ||
@Entity({ name: 'execution_annotation_tags' }) | ||
export class AnnotationTagMapping { | ||
@PrimaryColumn() | ||
annotationId: number; | ||
|
||
@ManyToOne('ExecutionAnnotation', 'tagMappings') | ||
@JoinColumn({ name: 'annotationId' }) | ||
annotations: ExecutionAnnotation[]; | ||
|
||
@PrimaryColumn() | ||
tagId: string; | ||
|
||
@ManyToOne('AnnotationTagEntity', 'annotationMappings') | ||
@JoinColumn({ name: 'tagId' }) | ||
tags: AnnotationTagEntity[]; | ||
} |
61 changes: 61 additions & 0 deletions
61
packages/cli/src/databases/entities/execution-annotation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
Column, | ||
Entity, | ||
Index, | ||
JoinColumn, | ||
JoinTable, | ||
ManyToMany, | ||
OneToMany, | ||
OneToOne, | ||
PrimaryGeneratedColumn, | ||
RelationId, | ||
} from '@n8n/typeorm'; | ||
import { ExecutionEntity } from './execution-entity'; | ||
import type { AnnotationTagEntity } from './annotation-tag-entity'; | ||
import type { AnnotationTagMapping } from './annotation-tag-mapping'; | ||
import type { AnnotationVote } from 'n8n-workflow'; | ||
|
||
@Entity({ name: 'execution_annotations' }) | ||
export class ExecutionAnnotation { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
/** | ||
* This field stores the up- or down-vote of the execution by user. | ||
*/ | ||
@Column({ type: 'varchar', nullable: true }) | ||
vote: AnnotationVote | null; | ||
|
||
/** | ||
* Custom text note added to the execution by user. | ||
*/ | ||
@Column({ type: 'varchar', nullable: true }) | ||
note: string | null; | ||
|
||
@RelationId((annotation: ExecutionAnnotation) => annotation.execution) | ||
executionId: string; | ||
|
||
@Index({ unique: true }) | ||
@OneToOne('ExecutionEntity', 'annotation', { | ||
onDelete: 'CASCADE', | ||
}) | ||
@JoinColumn({ name: 'executionId' }) | ||
execution: ExecutionEntity; | ||
|
||
@ManyToMany('AnnotationTagEntity', 'annotations') | ||
@JoinTable({ | ||
name: 'execution_annotation_tags', // table name for the junction table of this relation | ||
joinColumn: { | ||
name: 'annotationId', | ||
referencedColumnName: 'id', | ||
}, | ||
inverseJoinColumn: { | ||
name: 'tagId', | ||
referencedColumnName: 'id', | ||
}, | ||
}) | ||
tags?: AnnotationTagEntity[]; | ||
|
||
@OneToMany('AnnotationTagMapping', 'annotations') | ||
tagMappings: AnnotationTagMapping[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ages/cli/src/databases/migrations/common/1724753530828-CreateExecutionAnnotationTables.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { MigrationContext, ReversibleMigration } from '@/databases/types'; | ||
|
||
const annotationsTableName = 'execution_annotations'; | ||
const annotationTagsTableName = 'annotation_tag_entity'; | ||
const annotationTagMappingsTableName = 'execution_annotation_tags'; | ||
|
||
export class CreateAnnotationTables1724753530828 implements ReversibleMigration { | ||
async up({ schemaBuilder: { createTable, column } }: MigrationContext) { | ||
await createTable(annotationsTableName) | ||
.withColumns( | ||
column('id').int.notNull.primary.autoGenerate, | ||
column('executionId').int.notNull, | ||
column('vote').varchar(6), | ||
column('note').text, | ||
) | ||
.withIndexOn('executionId', true) | ||
.withForeignKey('executionId', { | ||
tableName: 'execution_entity', | ||
columnName: 'id', | ||
onDelete: 'CASCADE', | ||
}).withTimestamps; | ||
|
||
await createTable(annotationTagsTableName) | ||
.withColumns(column('id').varchar(16).primary.notNull, column('name').varchar(24).notNull) | ||
.withIndexOn('name', true).withTimestamps; | ||
|
||
await createTable(annotationTagMappingsTableName) | ||
.withColumns(column('annotationId').int.notNull, column('tagId').varchar(24).notNull) | ||
.withForeignKey('annotationId', { | ||
tableName: annotationsTableName, | ||
columnName: 'id', | ||
onDelete: 'CASCADE', | ||
}) | ||
.withIndexOn('tagId') | ||
.withIndexOn('annotationId') | ||
.withForeignKey('tagId', { | ||
tableName: annotationTagsTableName, | ||
columnName: 'id', | ||
onDelete: 'CASCADE', | ||
}); | ||
} | ||
|
||
async down({ schemaBuilder: { dropTable } }: MigrationContext) { | ||
await dropTable(annotationTagMappingsTableName); | ||
await dropTable(annotationTagsTableName); | ||
await dropTable(annotationsTableName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/cli/src/databases/repositories/annotation-tag-mapping.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Service } from 'typedi'; | ||
import { DataSource, Repository } from '@n8n/typeorm'; | ||
import { AnnotationTagMapping } from '@/databases/entities/annotation-tag-mapping'; | ||
|
||
@Service() | ||
export class AnnotationTagMappingRepository extends Repository<AnnotationTagMapping> { | ||
constructor(dataSource: DataSource) { | ||
super(AnnotationTagMapping, dataSource.manager); | ||
} | ||
|
||
/** | ||
* Overwrite annotation tags for the given execution. Annotation should already exist. | ||
*/ | ||
async overwriteTags(annotationId: number, tagIds: string[]) { | ||
return await this.manager.transaction(async (tx) => { | ||
await tx.delete(AnnotationTagMapping, { annotationId }); | ||
|
||
const tagMappings = tagIds.map((tagId) => ({ | ||
annotationId, | ||
tagId, | ||
})); | ||
|
||
return await tx.insert(AnnotationTagMapping, tagMappings); | ||
}); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/cli/src/databases/repositories/annotation-tag.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Service } from 'typedi'; | ||
import { DataSource, Repository } from '@n8n/typeorm'; | ||
import { AnnotationTagEntity } from '@/databases/entities/annotation-tag-entity'; | ||
|
||
@Service() | ||
export class AnnotationTagRepository extends Repository<AnnotationTagEntity> { | ||
constructor(dataSource: DataSource) { | ||
super(AnnotationTagEntity, dataSource.manager); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/cli/src/databases/repositories/execution-annotation.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Service } from 'typedi'; | ||
import { DataSource, Repository } from '@n8n/typeorm'; | ||
import { ExecutionAnnotation } from '@/databases/entities/execution-annotation'; | ||
|
||
@Service() | ||
export class ExecutionAnnotationRepository extends Repository<ExecutionAnnotation> { | ||
constructor(dataSource: DataSource) { | ||
super(ExecutionAnnotation, dataSource.manager); | ||
} | ||
} |
Oops, something went wrong.