feat: twenty orm sync (#5266)

This PR is updating all object metadata entities with the new
decorators, and deleting the old ones.
This way we can use the new TwentyORM with all the standard objects.

---------

Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
Jérémy M
2024-05-15 16:58:47 +02:00
committed by GitHub
parent 6898c1e4d8
commit f0383e3147
81 changed files with 1721 additions and 2060 deletions

View File

@ -4,7 +4,7 @@ import { WorkspaceIsPimaryField } from 'src/engine/twenty-orm/decorators/workspa
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { BASE_OBJECT_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
export abstract class BaseObjectMetadata {
export abstract class BaseWorkspaceEntity {
@WorkspaceField({
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.id,
type: FieldMetadataType.UUID,
@ -25,7 +25,6 @@ export abstract class BaseObjectMetadata {
icon: 'IconCalendar',
defaultValue: 'now',
})
@WorkspaceIsSystem()
createdAt: Date;
@WorkspaceField({

View File

@ -0,0 +1,94 @@
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import {
RelationMetadataType,
RelationOnDeleteAction,
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { ActivityTargetObjectMetadata } from 'src/modules/activity/standard-objects/activity-target.object-metadata';
import { FavoriteObjectMetadata } from 'src/modules/favorite/standard-objects/favorite.object-metadata';
import { AttachmentObjectMetadata } from 'src/modules/attachment/standard-objects/attachment.object-metadata';
import { CUSTOM_OBJECT_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { TimelineActivityObjectMetadata } from 'src/modules/timeline/standard-objects/timeline-activity.object-metadata';
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { WorkspaceCustomObject } from 'src/engine/twenty-orm/decorators/workspace-custom-object.decorator';
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
@WorkspaceCustomObject()
export class CustomWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceField({
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.name,
label: 'Name',
description: 'Name',
type: FieldMetadataType.TEXT,
icon: 'IconAbc',
defaultValue: "'Untitled'",
})
name: string;
@WorkspaceField({
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.position,
label: 'Position',
description: 'Position',
type: FieldMetadataType.POSITION,
icon: 'IconHierarchy2',
})
@WorkspaceIsNullable()
@WorkspaceIsSystem()
position: number;
@WorkspaceRelation({
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.activityTargets,
label: 'Activities',
type: RelationMetadataType.ONE_TO_MANY,
description: (objectMetadata) =>
`Activities tied to the ${objectMetadata.labelSingular}`,
icon: 'IconCheckbox',
inverseSideTarget: () => ActivityTargetObjectMetadata,
onDelete: RelationOnDeleteAction.CASCADE,
})
@WorkspaceIsNullable()
activityTargets: ActivityTargetObjectMetadata[];
@WorkspaceRelation({
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.favorites,
label: 'Favorites',
type: RelationMetadataType.ONE_TO_MANY,
description: (objectMetadata) =>
`Favorites tied to the ${objectMetadata.labelSingular}`,
icon: 'IconHeart',
inverseSideTarget: () => FavoriteObjectMetadata,
onDelete: RelationOnDeleteAction.CASCADE,
})
@WorkspaceIsNullable()
@WorkspaceIsSystem()
favorites: FavoriteObjectMetadata[];
@WorkspaceRelation({
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.attachments,
label: 'Attachments',
type: RelationMetadataType.ONE_TO_MANY,
description: (objectMetadata) =>
`Attachments tied to the ${objectMetadata.labelSingular}`,
icon: 'IconFileImport',
inverseSideTarget: () => AttachmentObjectMetadata,
onDelete: RelationOnDeleteAction.CASCADE,
})
@WorkspaceIsNullable()
attachments: AttachmentObjectMetadata[];
@WorkspaceRelation({
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.timelineActivities,
label: 'Timeline Activities',
type: RelationMetadataType.ONE_TO_MANY,
description: (objectMetadata) =>
`Timeline Activities tied to the ${objectMetadata.labelSingular}`,
icon: 'IconIconTimelineEvent',
inverseSideTarget: () => TimelineActivityObjectMetadata,
onDelete: RelationOnDeleteAction.CASCADE,
})
@WorkspaceIsNullable()
@WorkspaceIsSystem()
timelineActivities: TimelineActivityObjectMetadata[];
}

View File

@ -0,0 +1,16 @@
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
import { TypedReflect } from 'src/utils/typed-reflect';
export function WorkspaceCustomObject(): ClassDecorator {
return (target) => {
const gate = TypedReflect.getMetadata(
'workspace:gate-metadata-args',
target,
);
metadataArgsStorage.addExtendedEntities({
target,
gate,
});
};
}

View File

@ -0,0 +1,49 @@
import { ObjectType } from 'typeorm';
import { WorkspaceDynamicRelationMetadataArgsFactory } from 'src/engine/twenty-orm/interfaces/workspace-dynamic-relation-metadata-args.interface';
import { TypedReflect } from 'src/utils/typed-reflect';
import {
RelationMetadataType,
RelationOnDeleteAction,
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
interface WorkspaceBaseDynamicRelationOptions<TClass> {
type: RelationMetadataType;
argsFactory: WorkspaceDynamicRelationMetadataArgsFactory;
inverseSideTarget: () => ObjectType<TClass>;
inverseSideFieldKey?: keyof TClass;
onDelete?: RelationOnDeleteAction;
}
export function WorkspaceDynamicRelation<TClass extends object>(
args: WorkspaceBaseDynamicRelationOptions<TClass>,
): PropertyDecorator {
return (target, propertyKey) => {
const isSystem =
TypedReflect.getMetadata(
'workspace:is-system-metadata-args',
target,
propertyKey.toString(),
) ?? false;
const gate = TypedReflect.getMetadata(
'workspace:gate-metadata-args',
target,
propertyKey.toString(),
);
metadataArgsStorage.addDynamicRelations({
target: target.constructor,
argsFactory: args.argsFactory,
type: args.type,
inverseSideTarget: args.inverseSideTarget,
inverseSideFieldKey: args.inverseSideFieldKey as string | undefined,
onDelete: args.onDelete,
isSystem,
isNullable: true,
isPrimary: false,
gate,
});
};
}

View File

@ -5,6 +5,7 @@ import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/fi
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
import { TypedReflect } from 'src/utils/typed-reflect';
import { generateDefaultValue } from 'src/engine/metadata-modules/field-metadata/utils/generate-default-value';
export interface WorkspaceFieldOptions<
T extends FieldMetadataType | 'default',
@ -15,7 +16,6 @@ export interface WorkspaceFieldOptions<
description?: string | ((objectMetadata: ObjectMetadataEntity) => string);
icon?: string;
defaultValue?: FieldMetadataDefaultValue<T>;
joinColumn?: string;
options?: FieldMetadataOptions<T>;
}
@ -23,28 +23,35 @@ export function WorkspaceField<T extends FieldMetadataType>(
options: WorkspaceFieldOptions<T>,
): PropertyDecorator {
return (object, propertyKey) => {
const isPrimary = TypedReflect.getMetadata(
'workspace:is-primary-field-metadata-args',
object,
propertyKey.toString(),
);
const isNullable = TypedReflect.getMetadata(
'workspace:is-nullable-metadata-args',
object,
propertyKey.toString(),
);
const isSystem = TypedReflect.getMetadata(
'workspace:is-system-metadata-args',
object,
propertyKey.toString(),
);
const isPrimary =
TypedReflect.getMetadata(
'workspace:is-primary-field-metadata-args',
object,
propertyKey.toString(),
) ?? false;
const isNullable =
TypedReflect.getMetadata(
'workspace:is-nullable-metadata-args',
object,
propertyKey.toString(),
) ?? false;
const isSystem =
TypedReflect.getMetadata(
'workspace:is-system-metadata-args',
object,
propertyKey.toString(),
) ?? false;
const gate = TypedReflect.getMetadata(
'workspace:gate-metadata-args',
object,
propertyKey.toString(),
);
const defaultValue = (options.defaultValue ??
generateDefaultValue(
options.type,
)) as FieldMetadataDefaultValue<'default'> | null;
metadataArgsStorage.fields.push({
metadataArgsStorage.addFields({
target: object.constructor,
standardId: options.standardId,
name: propertyKey.toString(),
@ -52,7 +59,7 @@ export function WorkspaceField<T extends FieldMetadataType>(
type: options.type,
description: options.description,
icon: options.icon,
defaultValue: options.defaultValue,
defaultValue,
options: options.options,
isPrimary,
isNullable,

View File

@ -2,7 +2,7 @@ import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args
import { convertClassNameToObjectMetadataName } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util';
import { TypedReflect } from 'src/utils/typed-reflect';
interface WorkspaceObjectOptions {
interface WorkspaceEntityOptions {
standardId: string;
namePlural: string;
labelSingular: string;
@ -11,8 +11,8 @@ interface WorkspaceObjectOptions {
icon?: string;
}
export function WorkspaceObject(
options: WorkspaceObjectOptions,
export function WorkspaceEntity(
options: WorkspaceEntityOptions,
): ClassDecorator {
return (target) => {
const isAuditLogged =
@ -20,17 +20,16 @@ export function WorkspaceObject(
'workspace:is-audit-logged-metadata-args',
target,
) ?? true;
const isSystem = TypedReflect.getMetadata(
'workspace:is-system-metadata-args',
target,
);
const isSystem =
TypedReflect.getMetadata('workspace:is-system-metadata-args', target) ??
false;
const gate = TypedReflect.getMetadata(
'workspace:gate-metadata-args',
target,
);
const objectName = convertClassNameToObjectMetadataName(target.name);
metadataArgsStorage.objects.push({
metadataArgsStorage.addEntities({
target,
standardId: options.standardId,
nameSingular: objectName,

View File

@ -6,11 +6,12 @@ import {
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
import { TypedReflect } from 'src/utils/typed-reflect';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
interface WorkspaceBaseRelationOptions<TType, TClass> {
standardId: string;
label: string;
description?: string;
label: string | ((objectMetadata: ObjectMetadataEntity) => string);
description?: string | ((objectMetadata: ObjectMetadataEntity) => string);
icon?: string;
type: TType;
inverseSideTarget: () => ObjectType<TClass>;
@ -38,21 +39,24 @@ export function WorkspaceRelation<TClass extends object>(
| WorkspaceOtherRelationOptions<TClass>,
): PropertyDecorator {
return (object, propertyKey) => {
const isPrimary = TypedReflect.getMetadata(
'workspace:is-primary-field-metadata-args',
object,
propertyKey.toString(),
);
const isNullable = TypedReflect.getMetadata(
'workspace:is-nullable-metadata-args',
object,
propertyKey.toString(),
);
const isSystem = TypedReflect.getMetadata(
'workspace:is-system-metadata-args',
object,
propertyKey.toString(),
);
const isPrimary =
TypedReflect.getMetadata(
'workspace:is-primary-field-metadata-args',
object,
propertyKey.toString(),
) ?? false;
const isNullable =
TypedReflect.getMetadata(
'workspace:is-nullable-metadata-args',
object,
propertyKey.toString(),
) ?? false;
const isSystem =
TypedReflect.getMetadata(
'workspace:is-system-metadata-args',
object,
propertyKey.toString(),
) ?? false;
const gate = TypedReflect.getMetadata(
'workspace:gate-metadata-args',
object,
@ -67,7 +71,7 @@ export function WorkspaceRelation<TClass extends object>(
: `${propertyKey.toString()}Id`;
}
metadataArgsStorage.relations.push({
metadataArgsStorage.addRelations({
target: object.constructor,
standardId: options.standardId,
name: propertyKey.toString(),

View File

@ -15,10 +15,10 @@ export class EntitySchemaFactory {
) {}
create<T>(target: Type<T>): EntitySchema {
const objectMetadataArgs = metadataArgsStorage.filterObjects(target);
const entityMetadataArgs = metadataArgsStorage.filterEntities(target);
if (!objectMetadataArgs) {
throw new Error('Object metadata args are missing on this target');
if (!entityMetadataArgs) {
throw new Error('Entity metadata args are missing on this target');
}
const fieldMetadataArgsCollection =
@ -35,8 +35,8 @@ export class EntitySchemaFactory {
);
const entitySchema = new EntitySchema({
name: objectMetadataArgs.nameSingular,
tableName: objectMetadataArgs.nameSingular,
name: entityMetadataArgs.nameSingular,
tableName: entityMetadataArgs.nameSingular,
columns,
relations,
});

View File

@ -1,9 +0,0 @@
import { CompositeMetadataTypes } from 'src/engine/metadata-modules/field-metadata/composite-types';
// TODO: At the time the composite types are generating union of types instead of a single type for their keys
// We need to find a way to fix that
export type FlattenCompositeTypes<T> = {
[P in keyof T as T[P] extends CompositeMetadataTypes
? `${string & P}${Capitalize<string & keyof T[P]>}`
: P]: T[P] extends CompositeMetadataTypes ? T[P][keyof T[P]] : T[P];
};

View File

@ -1,9 +1,9 @@
import { FactoryProvider, ModuleMetadata, Type } from '@nestjs/common';
import { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects/base.object-metadata';
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
export interface TwentyORMOptions {
objects: Type<BaseObjectMetadata>[];
workspaceEntities: Type<BaseWorkspaceEntity>[];
}
export type TwentyORMModuleAsyncOptions = {

View File

@ -0,0 +1,96 @@
import { ObjectType } from 'typeorm';
import { Gate } from 'src/engine/twenty-orm/interfaces/gate.interface';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import {
RelationMetadataType,
RelationOnDeleteAction,
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
export type WorkspaceDynamicRelationMetadataArgsFactory = (
oppositeObjectMetadata: ObjectMetadataEntity,
) => {
/**
* Standard id.
*/
readonly standardId: string;
/**
* Relation name.
*/
readonly name: string;
/**
* Relation label.
*/
readonly label: string;
/**
* Relation description.
*/
readonly description?: string;
/**
* Relation icon.
*/
readonly icon?: string;
/**
* Relation join column.
*/
readonly joinColumn?: string;
};
export interface WorkspaceDynamicRelationMetadataArgs {
/**
* Class to which relation is applied.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
readonly target: Function;
/**
* Factory function
*/
readonly argsFactory: WorkspaceDynamicRelationMetadataArgsFactory;
/**
* Relation type.
*/
readonly type: RelationMetadataType;
/**
* Relation inverse side target.
*/
readonly inverseSideTarget: () => ObjectType<object>;
/**
* Relation inverse side field key.
*/
readonly inverseSideFieldKey?: string;
/**
* Relation on delete action.
*/
readonly onDelete?: RelationOnDeleteAction;
/**
* Is primary field.
*/
readonly isPrimary: boolean;
/**
* Is system field.
*/
readonly isSystem: boolean;
/**
* Is nullable field.
*/
readonly isNullable: boolean;
/**
* Field gate.
*/
readonly gate?: Gate;
}

View File

@ -1,6 +1,6 @@
import { Gate } from 'src/engine/twenty-orm/interfaces/gate.interface';
export interface WorkspaceObjectMetadataArgs {
export interface WorkspaceEntityMetadataArgs {
/**
* Standard id.
*/
@ -12,27 +12,27 @@ export interface WorkspaceObjectMetadataArgs {
* String target is a table defined in a json schema.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
readonly target: Function | string;
readonly target: Function;
/**
* Object name.
* Entity name.
*/
readonly nameSingular: string;
readonly namePlural: string;
/**
* Object label.
* Entity label.
*/
readonly labelSingular: string;
readonly labelPlural: string;
/**
* Object description.
* Entity description.
*/
readonly description?: string;
/**
* Object icon.
* Entity icon.
*/
readonly icon?: string;
@ -44,10 +44,10 @@ export interface WorkspaceObjectMetadataArgs {
/**
* Is system object.
*/
readonly isSystem?: boolean;
readonly isSystem: boolean;
/**
* Object gate.
* Entity gate.
*/
readonly gate?: Gate;
}

View File

@ -0,0 +1,16 @@
import { Gate } from 'src/engine/twenty-orm/interfaces/gate.interface';
export interface WorkspaceExtendedEntityMetadataArgs {
/**
* Class to which table is applied.
* Function target is a table defined in the class.
* String target is a table defined in a json schema.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
readonly target: Function;
/**
* Entity gate.
*/
readonly gate?: Gate;
}

View File

@ -15,7 +15,7 @@ export interface WorkspaceFieldMetadataArgs {
* Class to which field is applied.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
readonly target: Function | string;
readonly target: Function;
/**
* Field name.
@ -57,17 +57,17 @@ export interface WorkspaceFieldMetadataArgs {
/**
* Is primary field.
*/
readonly isPrimary?: boolean;
readonly isPrimary: boolean;
/**
* Is system field.
*/
readonly isSystem?: boolean;
readonly isSystem: boolean;
/**
* Is nullable field.
*/
readonly isNullable?: boolean;
readonly isNullable: boolean;
/**
* Field gate.

View File

@ -18,7 +18,7 @@ export interface WorkspaceRelationMetadataArgs {
* Class to which relation is applied.
*/
// eslint-disable-next-line @typescript-eslint/ban-types
readonly target: Function | string;
readonly target: Function;
/**
* Relation name.
@ -70,17 +70,17 @@ export interface WorkspaceRelationMetadataArgs {
/**
* Is primary field.
*/
readonly isPrimary?: boolean;
readonly isPrimary: boolean;
/**
* Is system field.
*/
readonly isSystem?: boolean;
readonly isSystem: boolean;
/**
* Is nullable field.
*/
readonly isNullable?: boolean;
readonly isNullable: boolean;
/**
* Field gate.

View File

@ -1,24 +1,72 @@
/* eslint-disable @typescript-eslint/ban-types */
import { WorkspaceDynamicRelationMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-dynamic-relation-metadata-args.interface';
import { WorkspaceFieldMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-field-metadata-args.interface';
import { WorkspaceObjectMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-object-metadata-args.interface';
import { WorkspaceEntityMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-entity-metadata-args.interface';
import { WorkspaceRelationMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface';
import { WorkspaceExtendedEntityMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-extended-entity-metadata-args.interface';
export class MetadataArgsStorage {
readonly objects: WorkspaceObjectMetadataArgs[] = [];
readonly fields: WorkspaceFieldMetadataArgs[] = [];
readonly relations: WorkspaceRelationMetadataArgs[] = [];
private readonly entities: WorkspaceEntityMetadataArgs[] = [];
private readonly extendedEntities: WorkspaceExtendedEntityMetadataArgs[] = [];
private readonly fields: WorkspaceFieldMetadataArgs[] = [];
private readonly relations: WorkspaceRelationMetadataArgs[] = [];
private readonly dynamicRelations: WorkspaceDynamicRelationMetadataArgs[] =
[];
filterObjects(
addEntities(...entities: WorkspaceEntityMetadataArgs[]): void {
this.entities.push(...entities);
}
addExtendedEntities(
...extendedEntities: WorkspaceExtendedEntityMetadataArgs[]
): void {
this.extendedEntities.push(...extendedEntities);
}
addFields(...fields: WorkspaceFieldMetadataArgs[]): void {
this.fields.push(...fields);
}
addRelations(...relations: WorkspaceRelationMetadataArgs[]): void {
this.relations.push(...relations);
}
addDynamicRelations(
...dynamicRelations: WorkspaceDynamicRelationMetadataArgs[]
): void {
this.dynamicRelations.push(...dynamicRelations);
}
filterEntities(
target: Function | string,
): WorkspaceObjectMetadataArgs | undefined;
): WorkspaceEntityMetadataArgs | undefined;
filterObjects(target: (Function | string)[]): WorkspaceObjectMetadataArgs[];
filterEntities(target: (Function | string)[]): WorkspaceEntityMetadataArgs[];
filterObjects(
filterEntities(
target: (Function | string) | (Function | string)[],
): WorkspaceObjectMetadataArgs | undefined | WorkspaceObjectMetadataArgs[] {
const objects = this.filterByTarget(this.objects, target);
): WorkspaceEntityMetadataArgs | undefined | WorkspaceEntityMetadataArgs[] {
const objects = this.filterByTarget(this.entities, target);
return Array.isArray(objects) ? objects[0] : objects;
}
filterExtendedEntities(
target: Function | string,
): WorkspaceExtendedEntityMetadataArgs | undefined;
filterExtendedEntities(
target: (Function | string)[],
): WorkspaceExtendedEntityMetadataArgs[];
filterExtendedEntities(
target: (Function | string) | (Function | string)[],
):
| WorkspaceExtendedEntityMetadataArgs
| undefined
| WorkspaceExtendedEntityMetadataArgs[] {
const objects = this.filterByTarget(this.extendedEntities, target);
return Array.isArray(objects) ? objects[0] : objects;
}
@ -45,6 +93,20 @@ export class MetadataArgsStorage {
return this.filterByTarget(this.relations, target);
}
filterDynamicRelations(
target: Function | string,
): WorkspaceDynamicRelationMetadataArgs[];
filterDynamicRelations(
target: (Function | string)[],
): WorkspaceDynamicRelationMetadataArgs[];
filterDynamicRelations(
target: (Function | string) | (Function | string)[],
): WorkspaceDynamicRelationMetadataArgs[] {
return this.filterByTarget(this.dynamicRelations, target);
}
protected filterByTarget<T extends { target: Function | string }>(
array: T[],
target: (Function | string) | (Function | string)[],

View File

@ -45,7 +45,7 @@ export class TwentyORMCoreModule
entitySchemaFactory: EntitySchemaFactory,
scopedWorkspaceDatasourceFactory: ScopedWorkspaceDatasourceFactory,
) => {
const entities = options.objects.map((entityClass) =>
const entities = options.workspaceEntities.map((entityClass) =>
entitySchemaFactory.create(entityClass),
);
@ -80,7 +80,7 @@ export class TwentyORMCoreModule
scopedWorkspaceDatasourceFactory: ScopedWorkspaceDatasourceFactory,
options: TwentyORMOptions,
) => {
const entities = options.objects.map((entityClass) =>
const entities = options.workspaceEntities.map((entityClass) =>
entitySchemaFactory.create(entityClass),
);

View File

@ -1,61 +0,0 @@
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { ATTACHMENT_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { WorkspaceObject } from 'src/engine/twenty-orm/decorators/workspace-object.decorator';
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { BaseObjectMetadata } from 'src/engine/twenty-orm/workspace-object-tests/base.object-metadata';
import { WorkspaceMemberObjectMetadata } from 'src/engine/twenty-orm/workspace-object-tests/workspace-member.object-metadata';
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/workspace-is-not-audit-logged.decorator';
@WorkspaceObject({
standardId: STANDARD_OBJECT_IDS.attachment,
namePlural: 'attachments',
labelSingular: 'Attachment',
labelPlural: 'Attachments',
description: 'An attachment',
icon: 'IconFileImport',
})
@WorkspaceIsSystem()
@WorkspaceIsNotAuditLogged()
export class AttachmentObjectMetadata extends BaseObjectMetadata {
@WorkspaceField({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.name,
type: FieldMetadataType.TEXT,
label: 'Name',
description: 'Attachment name',
icon: 'IconFileUpload',
})
name: string;
@WorkspaceField({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.fullPath,
type: FieldMetadataType.TEXT,
label: 'Full path',
description: 'Attachment full path',
icon: 'IconLink',
})
fullPath: string;
@WorkspaceField({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.type,
type: FieldMetadataType.TEXT,
label: 'Type',
description: 'Attachment type',
icon: 'IconList',
})
type: string;
@WorkspaceRelation({
standardId: ATTACHMENT_STANDARD_FIELD_IDS.author,
label: 'Author',
type: RelationMetadataType.MANY_TO_ONE,
inverseSideTarget: () => WorkspaceMemberObjectMetadata,
inverseSideFieldKey: 'authoredAttachments',
})
author: Relation<WorkspaceMemberObjectMetadata>;
}

View File

@ -1,130 +0,0 @@
import { CurrencyMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/currency.composite-type';
import { LinkMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/link.composite-type';
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import {
RelationMetadataType,
RelationOnDeleteAction,
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { COMPANY_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { WorkspaceObject } from 'src/engine/twenty-orm/decorators/workspace-object.decorator';
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { WorkspaceMemberObjectMetadata } from 'src/engine/twenty-orm/workspace-object-tests/workspace-member.object-metadata';
import { BaseObjectMetadata } from 'src/engine/twenty-orm/workspace-object-tests/base.object-metadata';
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
@WorkspaceObject({
standardId: STANDARD_OBJECT_IDS.company,
namePlural: 'companies',
labelSingular: 'Company',
labelPlural: 'Companies',
description: 'A company',
icon: 'IconBuildingSkyscraper',
})
export class CompanyObjectMetadata extends BaseObjectMetadata {
@WorkspaceField({
standardId: COMPANY_STANDARD_FIELD_IDS.name,
type: FieldMetadataType.TEXT,
label: 'Name',
description: 'The company name',
icon: 'IconBuildingSkyscraper',
})
name: string;
@WorkspaceField({
standardId: COMPANY_STANDARD_FIELD_IDS.domainName,
type: FieldMetadataType.TEXT,
label: 'Domain Name',
description:
'The company website URL. We use this url to fetch the company icon',
icon: 'IconLink',
})
domainName?: string;
@WorkspaceField({
standardId: COMPANY_STANDARD_FIELD_IDS.address,
type: FieldMetadataType.TEXT,
label: 'Address',
description: 'The company address',
icon: 'IconMap',
})
address: string;
@WorkspaceField({
standardId: COMPANY_STANDARD_FIELD_IDS.employees,
type: FieldMetadataType.NUMBER,
label: 'Employees',
description: 'Number of employees in the company',
icon: 'IconUsers',
})
@WorkspaceIsNullable()
employees: number;
@WorkspaceField({
standardId: COMPANY_STANDARD_FIELD_IDS.linkedinLink,
type: FieldMetadataType.LINK,
label: 'Linkedin',
description: 'The company Linkedin account',
icon: 'IconBrandLinkedin',
})
@WorkspaceIsNullable()
linkedinLink: LinkMetadata;
@WorkspaceField({
standardId: COMPANY_STANDARD_FIELD_IDS.xLink,
type: FieldMetadataType.LINK,
label: 'X',
description: 'The company Twitter/X account',
icon: 'IconBrandX',
})
@WorkspaceIsNullable()
xLink: LinkMetadata;
@WorkspaceField({
standardId: COMPANY_STANDARD_FIELD_IDS.annualRecurringRevenue,
type: FieldMetadataType.CURRENCY,
label: 'ARR',
description:
'Annual Recurring Revenue: The actual or estimated annual revenue of the company',
icon: 'IconMoneybag',
})
@WorkspaceIsNullable()
annualRecurringRevenue: CurrencyMetadata;
@WorkspaceField({
standardId: COMPANY_STANDARD_FIELD_IDS.idealCustomerProfile,
type: FieldMetadataType.BOOLEAN,
label: 'ICP',
description:
'Ideal Customer Profile: Indicates whether the company is the most suitable and valuable customer for you',
icon: 'IconTarget',
defaultValue: false,
})
idealCustomerProfile: boolean;
@WorkspaceField({
standardId: COMPANY_STANDARD_FIELD_IDS.position,
type: FieldMetadataType.POSITION,
label: 'Position',
description: 'Company record position',
icon: 'IconHierarchy2',
})
@WorkspaceIsSystem()
@WorkspaceIsNullable()
position: number;
@WorkspaceRelation({
standardId: COMPANY_STANDARD_FIELD_IDS.accountOwner,
label: 'Account Owner',
description:
'Your team member responsible for managing the company account',
type: RelationMetadataType.MANY_TO_ONE,
inverseSideTarget: () => WorkspaceMemberObjectMetadata,
inverseSideFieldKey: 'accountOwnerForCompanies',
onDelete: RelationOnDeleteAction.SET_NULL,
})
@WorkspaceIsNullable()
accountOwner: WorkspaceMemberObjectMetadata;
}

View File

@ -1,110 +0,0 @@
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
import { FullNameMetadata } from 'src/engine/metadata-modules/field-metadata/composite-types/full-name.composite-type';
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import {
RelationMetadataType,
RelationOnDeleteAction,
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
import { WORKSPACE_MEMBER_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { AttachmentObjectMetadata } from 'src/modules/attachment/standard-objects/attachment.object-metadata';
import { WorkspaceObject } from 'src/engine/twenty-orm/decorators/workspace-object.decorator';
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { BaseObjectMetadata } from 'src/engine/twenty-orm/workspace-object-tests/base.object-metadata';
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/workspace-is-not-audit-logged.decorator';
import { CompanyObjectMetadata } from 'src/engine/twenty-orm/workspace-object-tests/company.object-metadata';
@WorkspaceObject({
standardId: STANDARD_OBJECT_IDS.workspaceMember,
namePlural: 'workspaceMembers',
labelSingular: 'Workspace Member',
labelPlural: 'Workspace Members',
description: 'A workspace member',
icon: 'IconUserCircle',
})
@WorkspaceIsSystem()
@WorkspaceIsNotAuditLogged()
export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata {
@WorkspaceField({
standardId: WORKSPACE_MEMBER_STANDARD_FIELD_IDS.name,
type: FieldMetadataType.FULL_NAME,
label: 'Name',
description: 'Workspace member name',
icon: 'IconCircleUser',
})
name: FullNameMetadata;
@WorkspaceField({
standardId: WORKSPACE_MEMBER_STANDARD_FIELD_IDS.colorScheme,
type: FieldMetadataType.TEXT,
label: 'Color Scheme',
description: 'Preferred color scheme',
icon: 'IconColorSwatch',
defaultValue: "'Light'",
})
colorScheme: string;
@WorkspaceField({
standardId: WORKSPACE_MEMBER_STANDARD_FIELD_IDS.locale,
type: FieldMetadataType.TEXT,
label: 'Language',
description: 'Preferred language',
icon: 'IconLanguage',
defaultValue: "'en'",
})
locale: string;
@WorkspaceField({
standardId: WORKSPACE_MEMBER_STANDARD_FIELD_IDS.avatarUrl,
type: FieldMetadataType.TEXT,
label: 'Avatar Url',
description: 'Workspace member avatar',
icon: 'IconFileUpload',
})
avatarUrl: string;
@WorkspaceField({
standardId: WORKSPACE_MEMBER_STANDARD_FIELD_IDS.userEmail,
type: FieldMetadataType.TEXT,
label: 'User Email',
description: 'Related user email address',
icon: 'IconMail',
})
userEmail: string;
@WorkspaceField({
standardId: WORKSPACE_MEMBER_STANDARD_FIELD_IDS.userId,
type: FieldMetadataType.UUID,
label: 'User Id',
description: 'Associated User Id',
icon: 'IconCircleUsers',
})
userId: string;
@WorkspaceRelation({
standardId: WORKSPACE_MEMBER_STANDARD_FIELD_IDS.authoredAttachments,
label: 'Authored attachments',
description: 'Attachments created by the workspace member',
icon: 'IconFileImport',
type: RelationMetadataType.ONE_TO_MANY,
inverseSideTarget: () => AttachmentObjectMetadata,
inverseSideFieldKey: 'author',
onDelete: RelationOnDeleteAction.SET_NULL,
})
authoredAttachments: Relation<AttachmentObjectMetadata[]>;
@WorkspaceRelation({
standardId: WORKSPACE_MEMBER_STANDARD_FIELD_IDS.accountOwnerForCompanies,
label: 'Account Owner For Companies',
description: 'Account owner for companies',
icon: 'IconBriefcase',
type: RelationMetadataType.ONE_TO_MANY,
inverseSideTarget: () => CompanyObjectMetadata,
inverseSideFieldKey: 'accountOwner',
onDelete: RelationOnDeleteAction.SET_NULL,
})
accountOwnerForCompanies: Relation<CompanyObjectMetadata[]>;
}