Skip to content

Commit

Permalink
make decorator metadata work around swc issues
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed May 26, 2023
1 parent dbaa887 commit 46b5ac9
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 62 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const swcJestOptions = {
transform: {
legacyDecorator: true,
decoratorMetadata: true,
useDefineForClassFields: false,
},
experimental: {
plugins: [['jest_workaround', {}]],
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/databases/entities/AuthIdentity.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Column, Entity, ManyToOne, PrimaryColumn, Unique } from 'typeorm';
import { Column, Entity, ManyToOne, PrimaryColumn, Relation, Unique } from 'typeorm';
import { AbstractEntity } from './AbstractEntity';
import { User } from './User';
import type { User } from './User';

export type AuthProviderType = 'ldap' | 'email' | 'saml'; // | 'google';
export type AuthProviderType = AuthIdentity['providerType'];

@Entity()
@Unique(['providerId', 'providerType'])
export class AuthIdentity extends AbstractEntity {
@Column()
userId: string;

@ManyToOne(() => User, (user) => user.authIdentities)
user: User;
@ManyToOne('User', 'authIdentities')
user: Relation<User>;

@PrimaryColumn()
providerId: string;

@PrimaryColumn()
providerType: AuthProviderType;
providerType: 'ldap' | 'email' | 'saml'; // | 'google';

static create(
user: User,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { datetimeColumnType } from './AbstractEntity';
import { AuthProviderType } from './AuthIdentity';

export type RunningMode = 'dry' | 'live';
export type SyncStatus = 'success' | 'error';
export type RunningMode = AuthProviderSyncHistory['runMode'];
export type SyncStatus = AuthProviderSyncHistory['status'];

@Entity()
export class AuthProviderSyncHistory {
Expand All @@ -14,10 +14,10 @@ export class AuthProviderSyncHistory {
providerType: AuthProviderType;

@Column('text')
runMode: RunningMode;
runMode: 'dry' | 'live';

@Column('text')
status: SyncStatus;
status: 'success' | 'error';

@Column(datetimeColumnType)
startedAt: Date;
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/databases/entities/CredentialsEntity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ICredentialNodeAccess } from 'n8n-workflow';
import { Column, Entity, Generated, Index, OneToMany, PrimaryColumn } from 'typeorm';
import { Column, Entity, Generated, Index, OneToMany, PrimaryColumn, Relation } from 'typeorm';
import { IsArray, IsObject, IsString, Length } from 'class-validator';
import type { SharedCredentials } from './SharedCredentials';
import { AbstractEntity, jsonColumnType } from './AbstractEntity';
Expand Down Expand Up @@ -31,7 +31,7 @@ export class CredentialsEntity extends AbstractEntity implements ICredentialsDb
type: string;

@OneToMany('SharedCredentials', 'credentials')
shared: SharedCredentials[];
shared: Relation<SharedCredentials[]>;

@Column(jsonColumnType)
@IsArray()
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/databases/entities/ExecutionEntity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutionStatus, WorkflowExecuteMode } from 'n8n-workflow';
import { Column, Entity, Generated, Index, OneToMany, PrimaryColumn } from 'typeorm';
import { Column, Entity, Generated, Index, OneToMany, PrimaryColumn, Relation } from 'typeorm';
import { datetimeColumnType, jsonColumnType } from './AbstractEntity';
import { IWorkflowDb } from '@/Interfaces';
import type { IExecutionFlattedDb } from '@/Interfaces';
Expand Down Expand Up @@ -52,5 +52,5 @@ export class ExecutionEntity implements IExecutionFlattedDb {
waitTill: Date | null;

@OneToMany('ExecutionMetadata', 'execution')
metadata: ExecutionMetadata[];
metadata: Relation<ExecutionMetadata[]>;
}
6 changes: 3 additions & 3 deletions packages/cli/src/databases/entities/ExecutionMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, RelationId } from 'typeorm';
import { ExecutionEntity } from './ExecutionEntity';
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn, Relation, RelationId } from 'typeorm';
import type { ExecutionEntity } from './ExecutionEntity';

@Entity()
export class ExecutionMetadata {
Expand All @@ -9,7 +9,7 @@ export class ExecutionMetadata {
@ManyToOne('ExecutionEntity', 'metadata', {
onDelete: 'CASCADE',
})
execution: ExecutionEntity;
execution: Relation<ExecutionEntity>;

@RelationId((executionMetadata: ExecutionMetadata) => executionMetadata.execution)
executionId: number;
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/databases/entities/InstalledNodes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm';
import { InstalledPackages } from './InstalledPackages';
import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, Relation } from 'typeorm';
import type { InstalledPackages } from './InstalledPackages';

@Entity()
export class InstalledNodes {
Expand All @@ -14,5 +14,5 @@ export class InstalledNodes {

@ManyToOne('InstalledPackages', 'installedNodes')
@JoinColumn({ name: 'package', referencedColumnName: 'packageName' })
package: InstalledPackages;
package: Relation<InstalledPackages>;
}
4 changes: 2 additions & 2 deletions packages/cli/src/databases/entities/InstalledPackages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, JoinColumn, OneToMany, PrimaryColumn } from 'typeorm';
import { Column, Entity, JoinColumn, OneToMany, PrimaryColumn, Relation } from 'typeorm';
import type { InstalledNodes } from './InstalledNodes';
import { AbstractEntity } from './AbstractEntity';

Expand All @@ -18,5 +18,5 @@ export class InstalledPackages extends AbstractEntity {

@OneToMany('InstalledNodes', 'package')
@JoinColumn({ referencedColumnName: 'package' })
installedNodes: InstalledNodes[];
installedNodes: Relation<InstalledNodes[]>;
}
16 changes: 8 additions & 8 deletions packages/cli/src/databases/entities/Role.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Column, Entity, OneToMany, PrimaryColumn, Unique } from 'typeorm';
import { Column, Entity, OneToMany, PrimaryColumn, Relation, Unique } from 'typeorm';
import { IsString, Length } from 'class-validator';

import type { User } from './User';
Expand All @@ -7,8 +7,8 @@ import type { SharedCredentials } from './SharedCredentials';
import { AbstractEntity } from './AbstractEntity';
import { idStringifier } from '../utils/transformers';

export type RoleNames = 'owner' | 'member' | 'user' | 'editor';
export type RoleScopes = 'global' | 'workflow' | 'credential';
export type RoleNames = Role['name'];
export type RoleScopes = Role['scope'];

@Entity()
@Unique(['scope', 'name'])
Expand All @@ -19,17 +19,17 @@ export class Role extends AbstractEntity {
@Column({ length: 32 })
@IsString({ message: 'Role name must be of type string.' })
@Length(1, 32, { message: 'Role name must be 1 to 32 characters long.' })
name: RoleNames;
name: 'owner' | 'member' | 'user' | 'editor';

@Column()
scope: RoleScopes;
scope: 'global' | 'workflow' | 'credential';

@OneToMany('User', 'globalRole')
globalForUsers: User[];
globalForUsers: Relation<User[]>;

@OneToMany('SharedWorkflow', 'role')
sharedWorkflows: SharedWorkflow[];
sharedWorkflows: Relation<SharedWorkflow[]>;

@OneToMany('SharedCredentials', 'role')
sharedCredentials: SharedCredentials[];
sharedCredentials: Relation<SharedCredentials[]>;
}
14 changes: 7 additions & 7 deletions packages/cli/src/databases/entities/SharedCredentials.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Column, Entity, ManyToOne, PrimaryColumn } from 'typeorm';
import { CredentialsEntity } from './CredentialsEntity';
import { User } from './User';
import { Role } from './Role';
import { Column, Entity, ManyToOne, PrimaryColumn, Relation } from 'typeorm';
import type { CredentialsEntity } from './CredentialsEntity';
import type { User } from './User';
import type { Role } from './Role';
import { AbstractEntity } from './AbstractEntity';
import { idStringifier } from '../utils/transformers';

@Entity()
export class SharedCredentials extends AbstractEntity {
@ManyToOne('Role', 'sharedCredentials', { nullable: false })
role: Role;
role: Relation<Role>;

@Column()
roleId: string;

@ManyToOne('User', 'sharedCredentials')
user: User;
user: Relation<User>;

@PrimaryColumn()
userId: string;

@ManyToOne('CredentialsEntity', 'shared')
credentials: CredentialsEntity;
credentials: Relation<CredentialsEntity>;

@PrimaryColumn({ transformer: idStringifier })
credentialsId: string;
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/databases/entities/SharedWorkflow.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Column, Entity, ManyToOne, PrimaryColumn } from 'typeorm';
import { WorkflowEntity } from './WorkflowEntity';
import { User } from './User';
import { Role } from './Role';
import { Column, Entity, ManyToOne, PrimaryColumn, Relation } from 'typeorm';
import type { WorkflowEntity } from './WorkflowEntity';
import type { User } from './User';
import type { Role } from './Role';
import { AbstractEntity } from './AbstractEntity';
import { idStringifier } from '../utils/transformers';

@Entity()
export class SharedWorkflow extends AbstractEntity {
@ManyToOne('Role', 'sharedWorkflows', { nullable: false })
role: Role;
role: Relation<Role>;

@Column()
roleId: string;

@ManyToOne('User', 'sharedWorkflows')
user: User;
user: Relation<User>;

@PrimaryColumn()
userId: string;

@ManyToOne('WorkflowEntity', 'shared')
workflow: WorkflowEntity;
workflow: Relation<WorkflowEntity>;

@PrimaryColumn({ transformer: idStringifier })
workflowId: string;
Expand Down
15 changes: 12 additions & 3 deletions packages/cli/src/databases/entities/TagEntity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Column, Entity, Generated, Index, ManyToMany, OneToMany, PrimaryColumn } from 'typeorm';
import {
Column,
Entity,
Generated,
Index,
ManyToMany,
OneToMany,
PrimaryColumn,
Relation,
} from 'typeorm';
import { IsString, Length } from 'class-validator';

import { idStringifier } from '../utils/transformers';
Expand All @@ -19,8 +28,8 @@ export class TagEntity extends AbstractEntity {
name: string;

@ManyToMany('WorkflowEntity', 'tags')
workflows: WorkflowEntity[];
workflows: Relation<WorkflowEntity[]>;

@OneToMany('WorkflowTagMapping', 'tags')
workflowMappings: WorkflowTagMapping[];
workflowMappings: Relation<WorkflowTagMapping[]>;
}
11 changes: 6 additions & 5 deletions packages/cli/src/databases/entities/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {
ManyToOne,
PrimaryGeneratedColumn,
BeforeInsert,
Relation,
} from 'typeorm';
import { IsEmail, IsString, Length } from 'class-validator';
import type { IUser } from 'n8n-workflow';
import { Role } from './Role';
import type { Role } from './Role';
import type { SharedWorkflow } from './SharedWorkflow';
import type { SharedCredentials } from './SharedCredentials';
import { NoXss } from '../utils/customValidators';
Expand Down Expand Up @@ -76,19 +77,19 @@ export class User extends AbstractEntity implements IUser {
settings: IUserSettings | null;

@ManyToOne('Role', 'globalForUsers', { nullable: false })
globalRole: Role;
globalRole: Relation<Role>;

@Column()
globalRoleId: string;

@OneToMany('AuthIdentity', 'user')
authIdentities: AuthIdentity[];
authIdentities: Relation<AuthIdentity[]>;

@OneToMany('SharedWorkflow', 'user')
sharedWorkflows: SharedWorkflow[];
sharedWorkflows: Relation<SharedWorkflow[]>;

@OneToMany('SharedCredentials', 'user')
sharedCredentials: SharedCredentials[];
sharedCredentials: Relation<SharedCredentials[]>;

@Column({ type: Boolean, default: false })
disabled: boolean;
Expand Down
9 changes: 5 additions & 4 deletions packages/cli/src/databases/entities/WorkflowEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ManyToMany,
OneToMany,
PrimaryColumn,
Relation,
} from 'typeorm';

import config from '@/config';
Expand Down Expand Up @@ -72,17 +73,17 @@ export class WorkflowEntity extends AbstractEntity implements IWorkflowDb {
referencedColumnName: 'id',
},
})
tags?: TagEntity[];
tags?: Relation<TagEntity[]>;

@OneToMany('WorkflowTagMapping', 'workflows')
tagMappings: WorkflowTagMapping[];
tagMappings: Relation<WorkflowTagMapping[]>;

@OneToMany('SharedWorkflow', 'workflow')
shared: SharedWorkflow[];
shared: Relation<SharedWorkflow[]>;

@OneToMany('WorkflowStatistics', 'workflow')
@JoinColumn({ referencedColumnName: 'workflow' })
statistics: WorkflowStatistics[];
statistics: Relation<WorkflowStatistics[]>;

@Column({
type: config.getEnv('database.type') === 'sqlite' ? 'text' : 'json',
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/databases/entities/WorkflowStatistics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Column, Entity, ManyToOne, PrimaryColumn } from 'typeorm';
import { Column, Entity, ManyToOne, PrimaryColumn, Relation } from 'typeorm';
import { idStringifier } from '../utils/transformers';
import { datetimeColumnType } from './AbstractEntity';
import { WorkflowEntity } from './WorkflowEntity';
import type { WorkflowEntity } from './WorkflowEntity';

export const enum StatisticsNames {
productionSuccess = 'production_success',
Expand All @@ -23,7 +23,7 @@ export class WorkflowStatistics {
name: StatisticsNames;

@ManyToOne('WorkflowEntity', 'shared')
workflow: WorkflowEntity;
workflow: Relation<WorkflowEntity>;

@PrimaryColumn({ transformer: idStringifier })
workflowId: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/databases/entities/WorkflowTagMapping.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm';
import { Entity, JoinColumn, ManyToOne, PrimaryColumn, Relation } from 'typeorm';
import { idStringifier } from '../utils/transformers';
import type { TagEntity } from './TagEntity';
import type { WorkflowEntity } from './WorkflowEntity';
Expand All @@ -10,12 +10,12 @@ export class WorkflowTagMapping {

@ManyToOne('WorkflowEntity', 'tagMappings')
@JoinColumn({ name: 'workflowId' })
workflows: WorkflowEntity[];
workflows: Relation<WorkflowEntity[]>;

@PrimaryColumn()
tagId: string;

@ManyToOne('TagEntity', 'workflowMappings')
@JoinColumn({ name: 'tagId' })
tags: TagEntity[];
tags: Relation<TagEntity[]>;
}

0 comments on commit 46b5ac9

Please sign in to comment.