Compile with swc on twenty-server (#4863)

Experiment using swc instead of tsc (as we did the switch on
twenty-front)

It's **much** faster (at least 5x) but has stricter requirements.
I fixed the build but there's still an error while starting the server,
opening this PR for discussion.

Checkout the branch and try `nx build:swc twenty-server`

Read: https://docs.nestjs.com/recipes/swc#common-pitfalls
This commit is contained in:
Félix Malfait
2024-04-14 09:09:51 +02:00
committed by GitHub
parent f82b1ff9ef
commit 9aa24ed803
50 changed files with 600 additions and 152 deletions

View File

@ -25,7 +25,7 @@ export class RelationFieldAliasFactory {
constructor(
@Inject(forwardRef(() => FieldsStringFactory))
private readonly fieldsStringFactory: FieldsStringFactory,
private readonly fieldsStringFactory: CircularDep<FieldsStringFactory>,
private readonly argsStringFactory: ArgsStringFactory,
private readonly objectMetadataService: ObjectMetadataService,
) {}

View File

@ -30,7 +30,7 @@ export interface InputTypeDefinition {
export class InputTypeDefinitionFactory {
constructor(
@Inject(forwardRef(() => InputTypeFactory))
private readonly inputTypeFactory: InputTypeFactory,
private readonly inputTypeFactory: CircularDep<InputTypeFactory>,
private readonly typeMapperService: TypeMapperService,
) {}

View File

@ -8,6 +8,7 @@ import {
JoinColumn,
CreateDateColumn,
UpdateDateColumn,
Relation,
} from 'typeorm';
import { BeforeCreateOne, IDField } from '@ptc-org/nestjs-query-graphql';
@ -33,7 +34,7 @@ export class AppToken {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'userId' })
user: User;
user: Relation<User>;
@Column()
userId: string;
@ -42,7 +43,7 @@ export class AppToken {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'workspaceId' })
workspace: Workspace;
workspace: Relation<Workspace>;
@Column({ nullable: true })
workspaceId: string;

View File

@ -4,6 +4,7 @@ import {
Entity,
ManyToOne,
PrimaryGeneratedColumn,
Relation,
Unique,
UpdateDateColumn,
} from 'typeorm';
@ -42,7 +43,7 @@ export class BillingSubscriptionItem {
onDelete: 'CASCADE',
},
)
billingSubscription: BillingSubscription;
billingSubscription: Relation<BillingSubscription>;
@Column({ nullable: false })
stripeProductId: string;

View File

@ -8,6 +8,7 @@ import {
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
Relation,
UpdateDateColumn,
} from 'typeorm';
import Stripe from 'stripe';
@ -37,7 +38,7 @@ export class BillingSubscription {
onDelete: 'CASCADE',
})
@JoinColumn()
workspace: Workspace;
workspace: Relation<Workspace>;
@Column({ nullable: false, type: 'uuid' })
workspaceId: string;
@ -48,17 +49,17 @@ export class BillingSubscription {
@Column({ unique: true, nullable: false })
stripeSubscriptionId: string;
@Field()
@Column({ nullable: false })
@Field(() => String)
@Column({ type: 'text', nullable: false })
status: Stripe.Subscription.Status;
@Field({ nullable: true })
@Column({ nullable: true })
@Field(() => String, { nullable: true })
@Column({ type: 'text', nullable: true })
interval: Stripe.Price.Recurring.Interval;
@OneToMany(
() => BillingSubscriptionItem,
(billingSubscriptionItem) => billingSubscriptionItem.billingSubscription,
)
billingSubscriptionItems: BillingSubscriptionItem[];
billingSubscriptionItems: Relation<BillingSubscriptionItem[]>;
}

View File

@ -8,6 +8,7 @@ import {
CreateDateColumn,
UpdateDateColumn,
ManyToOne,
Relation,
} from 'typeorm';
import { IDField } from '@ptc-org/nestjs-query-graphql';
@ -43,7 +44,7 @@ export class FeatureFlagEntity {
@ManyToOne(() => Workspace, (workspace) => workspace.featureFlags, {
onDelete: 'CASCADE',
})
workspace: Workspace;
workspace: Relation<Workspace>;
@Field()
@Column({ nullable: false })

View File

@ -8,6 +8,7 @@ import {
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
Relation,
Unique,
UpdateDateColumn,
} from 'typeorm';
@ -29,7 +30,7 @@ export class UserWorkspace {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'userId' })
user: User;
user: Relation<User>;
@Field({ nullable: false })
@Column()
@ -40,7 +41,7 @@ export class UserWorkspace {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'workspaceId' })
workspace: Workspace;
workspace: Relation<Workspace>;
@Field({ nullable: false })
@Column()

View File

@ -8,6 +8,7 @@ import {
UpdateDateColumn,
OneToMany,
ManyToOne,
Relation,
} from 'typeorm';
import { IDField } from '@ptc-org/nestjs-query-graphql';
@ -72,7 +73,7 @@ export class User {
@ManyToOne(() => Workspace, (workspace) => workspace.users, {
onDelete: 'SET NULL',
})
defaultWorkspace: Workspace;
defaultWorkspace: Relation<Workspace>;
@Field()
@Column()
@ -89,12 +90,12 @@ export class User {
@OneToMany(() => AppToken, (appToken) => appToken.user, {
cascade: true,
})
appTokens: AppToken[];
appTokens: Relation<AppToken[]>;
@Field(() => WorkspaceMember, { nullable: true })
workspaceMember: WorkspaceMember;
workspaceMember: Relation<WorkspaceMember>;
@Field(() => [UserWorkspace])
@OneToMany(() => UserWorkspace, (userWorkspace) => userWorkspace.user)
workspaces: UserWorkspace[];
workspaces: Relation<UserWorkspace[]>;
}

View File

@ -7,6 +7,7 @@ import {
Entity,
OneToMany,
PrimaryGeneratedColumn,
Relation,
UpdateDateColumn,
} from 'typeorm';
import Stripe from 'stripe';
@ -60,25 +61,25 @@ export class Workspace {
@OneToMany(() => AppToken, (appToken) => appToken.workspace, {
cascade: true,
})
appTokens: AppToken[];
appTokens: Relation<AppToken[]>;
@OneToMany(() => User, (user) => user.defaultWorkspace)
users: User[];
users: Relation<User[]>;
@OneToMany(() => UserWorkspace, (userWorkspace) => userWorkspace.workspace, {
onDelete: 'CASCADE',
})
workspaceUsers: UserWorkspace[];
workspaceUsers: Relation<UserWorkspace[]>;
@Field()
@Column({ default: true })
allowImpersonation: boolean;
@OneToMany(() => FeatureFlagEntity, (featureFlag) => featureFlag.workspace)
featureFlags: FeatureFlagEntity[];
featureFlags: Relation<FeatureFlagEntity[]>;
@Field()
@Column({ default: 'incomplete' })
@Field(() => String)
@Column({ type: 'text', default: 'incomplete' })
subscriptionStatus: Stripe.Subscription.Status;
@Field({ nullable: true })
@ -91,5 +92,5 @@ export class Workspace {
() => BillingSubscription,
(billingSubscription) => billingSubscription.workspace,
)
billingSubscriptions: BillingSubscription[];
billingSubscriptions: Relation<BillingSubscription[]>;
}

View File

@ -1,6 +1,7 @@
import { Field, ObjectType, registerEnumType } from '@nestjs/graphql';
import { IsEnum, IsNotEmpty } from 'class-validator';
import { Relation } from 'typeorm';
import { FieldMetadataDTO } from 'src/engine/metadata-modules/field-metadata/dtos/field-metadata.dto';
import { ObjectMetadataDTO } from 'src/engine/metadata-modules/object-metadata/dtos/object-metadata.dto';
@ -22,19 +23,19 @@ registerEnumType(RelationDefinitionType, {
export class RelationDefinitionDTO {
@IsNotEmpty()
@Field(() => ObjectMetadataDTO)
sourceObjectMetadata: ObjectMetadataDTO;
sourceObjectMetadata: Relation<ObjectMetadataDTO>;
@IsNotEmpty()
@Field(() => ObjectMetadataDTO)
targetObjectMetadata: ObjectMetadataDTO;
targetObjectMetadata: Relation<ObjectMetadataDTO>;
@IsNotEmpty()
@Field(() => FieldMetadataDTO)
sourceFieldMetadata: FieldMetadataDTO;
sourceFieldMetadata: Relation<FieldMetadataDTO>;
@IsNotEmpty()
@Field(() => FieldMetadataDTO)
targetFieldMetadata: FieldMetadataDTO;
targetFieldMetadata: Relation<FieldMetadataDTO>;
@IsEnum(RelationDefinitionType)
@IsNotEmpty()

View File

@ -8,6 +8,7 @@ import {
OneToOne,
CreateDateColumn,
UpdateDateColumn,
Relation,
} from 'typeorm';
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface';
@ -63,7 +64,7 @@ export class FieldMetadataEntity<
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'objectMetadataId' })
object: ObjectMetadataEntity;
object: Relation<ObjectMetadataEntity>;
@Column({ nullable: false })
type: FieldMetadataType;
@ -105,13 +106,13 @@ export class FieldMetadataEntity<
() => RelationMetadataEntity,
(relation: RelationMetadataEntity) => relation.fromFieldMetadata,
)
fromRelationMetadata: RelationMetadataEntity;
fromRelationMetadata: Relation<RelationMetadataEntity>;
@OneToOne(
() => RelationMetadataEntity,
(relation: RelationMetadataEntity) => relation.toFieldMetadata,
)
toRelationMetadata: RelationMetadataEntity;
toRelationMetadata: Relation<RelationMetadataEntity>;
@CreateDateColumn({ type: 'timestamptz' })
createdAt: Date;

View File

@ -7,6 +7,7 @@ import {
CreateDateColumn,
UpdateDateColumn,
ManyToOne,
Relation,
} from 'typeorm';
import { ObjectMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/object-metadata.interface';
@ -79,7 +80,7 @@ export class ObjectMetadataEntity implements ObjectMetadataInterface {
@OneToMany(() => FieldMetadataEntity, (field) => field.object, {
cascade: true,
})
fields: FieldMetadataEntity[];
fields: Relation<FieldMetadataEntity[]>;
@OneToMany(
() => RelationMetadataEntity,
@ -88,7 +89,7 @@ export class ObjectMetadataEntity implements ObjectMetadataInterface {
cascade: true,
},
)
fromRelations: RelationMetadataEntity[];
fromRelations: Relation<RelationMetadataEntity[]>;
@OneToMany(
() => RelationMetadataEntity,
@ -97,12 +98,12 @@ export class ObjectMetadataEntity implements ObjectMetadataInterface {
cascade: true,
},
)
toRelations: RelationMetadataEntity[];
toRelations: Relation<RelationMetadataEntity[]>;
@ManyToOne(() => DataSourceEntity, (dataSource) => dataSource.objects, {
onDelete: 'CASCADE',
})
dataSource: DataSourceEntity;
dataSource: Relation<DataSourceEntity>;
@CreateDateColumn({ type: 'timestamptz' })
createdAt: Date;

View File

@ -6,6 +6,7 @@ import {
ManyToOne,
OneToOne,
PrimaryGeneratedColumn,
Relation,
UpdateDateColumn,
} from 'typeorm';
@ -65,7 +66,7 @@ export class RelationMetadataEntity implements RelationMetadataInterface {
onDelete: 'CASCADE',
},
)
fromObjectMetadata: ObjectMetadataEntity;
fromObjectMetadata: Relation<ObjectMetadataEntity>;
@ManyToOne(
() => ObjectMetadataEntity,
@ -74,21 +75,21 @@ export class RelationMetadataEntity implements RelationMetadataInterface {
onDelete: 'CASCADE',
},
)
toObjectMetadata: ObjectMetadataEntity;
toObjectMetadata: Relation<ObjectMetadataEntity>;
@OneToOne(
() => FieldMetadataEntity,
(field: FieldMetadataEntity) => field.fromRelationMetadata,
)
@JoinColumn()
fromFieldMetadata: FieldMetadataEntity;
fromFieldMetadata: Relation<FieldMetadataEntity>;
@OneToOne(
() => FieldMetadataEntity,
(field: FieldMetadataEntity) => field.toRelationMetadata,
)
@JoinColumn()
toFieldMetadata: FieldMetadataEntity;
toFieldMetadata: Relation<FieldMetadataEntity>;
@CreateDateColumn({ type: 'timestamptz' })
createdAt: Date;

View File

@ -39,7 +39,7 @@ export class RemoteServerEntity<T extends RemoteServerType> {
@Generated('uuid')
foreignDataWrapperId: string;
@Column({ nullable: true })
@Column({ type: 'text', nullable: true })
foreignDataWrapperType: T;
@Column({ nullable: true, type: 'jsonb' })

View File

@ -1,6 +1,6 @@
import { EntityManager } from 'typeorm';
import companiesDemo from './companies-demo.json';
import { companiesDemo } from 'src/engine/workspace-manager/demo-objects-prefill-data/companies-demo.json';
export const companyPrefillDemoData = async (
entityManager: EntityManager,

View File

@ -1,6 +1,6 @@
import { EntityManager } from 'typeorm';
import peopleDemo from './people-demo.json';
import { peopleDemo } from 'src/engine/workspace-manager/demo-objects-prefill-data/people-demo.json';
export const personPrefillDemoData = async (
entityManager: EntityManager,

View File

@ -0,0 +1,5 @@
/**
* Wrapper type used to circumvent ESM modules circular dependency issue
* caused by reflection metadata saving the type of the property.
*/
export type Relation<T> = T;