* db entities don't need an ID before they are inserted * don't define constructors on entity classes, use repository.create instead * use mixins to reduce duplicate code in db entity classes
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import type { ICredentialNodeAccess } from 'n8n-workflow';
|
|
import { Column, Entity, Index, OneToMany } from 'typeorm';
|
|
import { IsArray, IsObject, IsString, Length } from 'class-validator';
|
|
import type { SharedCredentials } from './SharedCredentials';
|
|
import { WithTimestampsAndStringId, jsonColumnType } from './AbstractEntity';
|
|
import type { ICredentialsDb } from '@/Interfaces';
|
|
|
|
@Entity()
|
|
export class CredentialsEntity extends WithTimestampsAndStringId implements ICredentialsDb {
|
|
@Column({ length: 128 })
|
|
@IsString({ message: 'Credential `name` must be of type string.' })
|
|
@Length(3, 128, {
|
|
message: 'Credential name must be $constraint1 to $constraint2 characters long.',
|
|
})
|
|
name: string;
|
|
|
|
@Column('text')
|
|
@IsObject()
|
|
data: string;
|
|
|
|
@Index()
|
|
@IsString({ message: 'Credential `type` must be of type string.' })
|
|
@Column({
|
|
length: 128,
|
|
})
|
|
type: string;
|
|
|
|
@OneToMany('SharedCredentials', 'credentials')
|
|
shared: SharedCredentials[];
|
|
|
|
@Column(jsonColumnType)
|
|
@IsArray()
|
|
nodesAccess: ICredentialNodeAccess[];
|
|
}
|