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:
@ -11,9 +11,9 @@ import { TimelineCalendarEventModule } from 'src/engine/core-modules/calendar/ti
|
||||
import { BillingModule } from 'src/engine/core-modules/billing/billing.module';
|
||||
import { HealthModule } from 'src/engine/core-modules/health/health.module';
|
||||
|
||||
import { ClientConfigModule } from './client-config/client-config.module';
|
||||
import { FileModule } from './file/file.module';
|
||||
import { AnalyticsModule } from './analytics/analytics.module';
|
||||
import { FileModule } from './file/file.module';
|
||||
import { ClientConfigModule } from './client-config/client-config.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
||||
@ -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({
|
||||
@ -1,23 +1,23 @@
|
||||
import { BaseCustomObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/base-custom-object-metadata.decorator';
|
||||
import { FieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/field-metadata.decorator';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { IsNullable } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-nullable.decorator';
|
||||
import { IsSystem } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-system.decorator';
|
||||
import { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects/base.object-metadata';
|
||||
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 { RelationMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/relation-metadata.decorator';
|
||||
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';
|
||||
|
||||
@BaseCustomObjectMetadata()
|
||||
export class CustomObjectMetadata extends BaseObjectMetadata {
|
||||
@FieldMetadata({
|
||||
@WorkspaceCustomObject()
|
||||
export class CustomWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
@WorkspaceField({
|
||||
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.name,
|
||||
label: 'Name',
|
||||
description: 'Name',
|
||||
@ -27,81 +27,68 @@ export class CustomObjectMetadata extends BaseObjectMetadata {
|
||||
})
|
||||
name: string;
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceField({
|
||||
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.position,
|
||||
label: 'Position',
|
||||
description: 'Position',
|
||||
type: FieldMetadataType.POSITION,
|
||||
icon: 'IconHierarchy2',
|
||||
})
|
||||
@IsNullable()
|
||||
@IsSystem()
|
||||
@WorkspaceIsNullable()
|
||||
@WorkspaceIsSystem()
|
||||
position: number;
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceRelation({
|
||||
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.activityTargets,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Activities',
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
description: (objectMetadata) =>
|
||||
`Activities tied to the ${objectMetadata.labelSingular}`,
|
||||
icon: 'IconCheckbox',
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => ActivityTargetObjectMetadata,
|
||||
onDelete: RelationOnDeleteAction.CASCADE,
|
||||
})
|
||||
@IsNullable()
|
||||
@WorkspaceIsNullable()
|
||||
activityTargets: ActivityTargetObjectMetadata[];
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceRelation({
|
||||
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.favorites,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Favorites',
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
description: (objectMetadata) =>
|
||||
`Favorites tied to the ${objectMetadata.labelSingular}`,
|
||||
icon: 'IconHeart',
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => FavoriteObjectMetadata,
|
||||
onDelete: RelationOnDeleteAction.CASCADE,
|
||||
})
|
||||
@IsNullable()
|
||||
@IsSystem()
|
||||
@WorkspaceIsNullable()
|
||||
@WorkspaceIsSystem()
|
||||
favorites: FavoriteObjectMetadata[];
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceRelation({
|
||||
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.attachments,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Attachments',
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
description: (objectMetadata) =>
|
||||
`Attachments tied to the ${objectMetadata.labelSingular}`,
|
||||
icon: 'IconFileImport',
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => AttachmentObjectMetadata,
|
||||
onDelete: RelationOnDeleteAction.CASCADE,
|
||||
})
|
||||
@IsNullable()
|
||||
@WorkspaceIsNullable()
|
||||
attachments: AttachmentObjectMetadata[];
|
||||
|
||||
@FieldMetadata({
|
||||
@WorkspaceRelation({
|
||||
standardId: CUSTOM_OBJECT_STANDARD_FIELD_IDS.timelineActivities,
|
||||
type: FieldMetadataType.RELATION,
|
||||
label: 'Timeline Activities',
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
description: (objectMetadata) =>
|
||||
`Timeline Activities tied to the ${objectMetadata.labelSingular}`,
|
||||
|
||||
icon: 'IconIconTimelineEvent',
|
||||
})
|
||||
@RelationMetadata({
|
||||
type: RelationMetadataType.ONE_TO_MANY,
|
||||
inverseSideTarget: () => TimelineActivityObjectMetadata,
|
||||
onDelete: RelationOnDeleteAction.CASCADE,
|
||||
})
|
||||
@IsNullable()
|
||||
@IsSystem()
|
||||
@WorkspaceIsNullable()
|
||||
@WorkspaceIsSystem()
|
||||
timelineActivities: TimelineActivityObjectMetadata[];
|
||||
}
|
||||
@ -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,
|
||||
});
|
||||
};
|
||||
}
|
||||
@ -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,
|
||||
});
|
||||
};
|
||||
}
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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,
|
||||
});
|
||||
|
||||
@ -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];
|
||||
};
|
||||
@ -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 = {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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)[],
|
||||
|
||||
@ -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),
|
||||
);
|
||||
|
||||
|
||||
@ -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>;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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[]>;
|
||||
}
|
||||
@ -10,7 +10,7 @@ import { standardObjectMetadataDefinitions } from 'src/engine/workspace-manager/
|
||||
import { StandardObjectFactory } from 'src/engine/workspace-manager/workspace-sync-metadata/factories/standard-object.factory';
|
||||
import { computeStandardObject } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/compute-standard-object.util';
|
||||
import { StandardFieldFactory } from 'src/engine/workspace-manager/workspace-sync-metadata/factories/standard-field.factory';
|
||||
import { CustomObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/custom-objects/custom.object-metadata';
|
||||
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
|
||||
|
||||
interface RunCommandOptions {
|
||||
workspaceId?: string;
|
||||
@ -61,7 +61,7 @@ export class AddStandardIdCommand extends CommandRunner {
|
||||
},
|
||||
);
|
||||
const standardFieldMetadataCollection = this.standardFieldFactory.create(
|
||||
CustomObjectMetadata,
|
||||
CustomWorkspaceEntity,
|
||||
{
|
||||
workspaceId: '',
|
||||
dataSourceId: '',
|
||||
|
||||
@ -1,20 +0,0 @@
|
||||
import { BaseCustomObjectMetadataDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-custom-object-metadata.interface';
|
||||
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
|
||||
export function BaseCustomObjectMetadata(
|
||||
params?: BaseCustomObjectMetadataDecoratorParams,
|
||||
): ClassDecorator {
|
||||
return (target) => {
|
||||
const gate = TypedReflect.getMetadata('gate', target);
|
||||
|
||||
TypedReflect.defineMetadata(
|
||||
'extendObjectMetadata',
|
||||
{
|
||||
...params,
|
||||
gate,
|
||||
},
|
||||
target,
|
||||
);
|
||||
};
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
import { DynamicRelationFieldMetadataDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-computed-relation-field-metadata.interface';
|
||||
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
|
||||
export function DynamicRelationFieldMetadata(
|
||||
params: DynamicRelationFieldMetadataDecoratorParams,
|
||||
): PropertyDecorator {
|
||||
return (target: object, fieldKey: string) => {
|
||||
const isSystem =
|
||||
TypedReflect.getMetadata('isSystem', target, fieldKey) ?? false;
|
||||
const gate = TypedReflect.getMetadata('gate', target, fieldKey);
|
||||
|
||||
TypedReflect.defineMetadata(
|
||||
'dynamicRelationFieldMetadataMap',
|
||||
{
|
||||
type: FieldMetadataType.RELATION,
|
||||
paramsFactory: params,
|
||||
isCustom: false,
|
||||
isNullable: true,
|
||||
isSystem,
|
||||
gate,
|
||||
},
|
||||
target.constructor,
|
||||
);
|
||||
};
|
||||
}
|
||||
@ -1,92 +0,0 @@
|
||||
import {
|
||||
FieldMetadataDecoratorParams,
|
||||
ReflectFieldMetadata,
|
||||
} from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-field-metadata.interface';
|
||||
import { GateDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/gate-decorator.interface';
|
||||
import { FieldMetadataDefaultValue } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-default-value.interface';
|
||||
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { generateDefaultValue } from 'src/engine/metadata-modules/field-metadata/utils/generate-default-value';
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
import { createDeterministicUuid } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/create-deterministic-uuid.util';
|
||||
|
||||
export function FieldMetadata<T extends FieldMetadataType>(
|
||||
params: FieldMetadataDecoratorParams<T>,
|
||||
): PropertyDecorator {
|
||||
return (target: object, fieldKey: string) => {
|
||||
const existingFieldMetadata =
|
||||
TypedReflect.getMetadata('fieldMetadataMap', target.constructor) ?? {};
|
||||
const isNullable =
|
||||
TypedReflect.getMetadata('isNullable', target, fieldKey) ?? false;
|
||||
const isSystem =
|
||||
TypedReflect.getMetadata('isSystem', target, fieldKey) ?? false;
|
||||
const gate = TypedReflect.getMetadata('gate', target, fieldKey);
|
||||
const { joinColumn, standardId, ...restParams } = params;
|
||||
|
||||
TypedReflect.defineMetadata(
|
||||
'fieldMetadataMap',
|
||||
{
|
||||
...existingFieldMetadata,
|
||||
[fieldKey]: generateFieldMetadata<T>(
|
||||
{
|
||||
...restParams,
|
||||
standardId,
|
||||
joinColumn,
|
||||
},
|
||||
fieldKey,
|
||||
isNullable,
|
||||
isSystem,
|
||||
gate,
|
||||
),
|
||||
...(joinColumn && restParams.type === FieldMetadataType.RELATION
|
||||
? {
|
||||
[joinColumn]: generateFieldMetadata<FieldMetadataType.UUID>(
|
||||
{
|
||||
...restParams,
|
||||
standardId: createDeterministicUuid(standardId),
|
||||
type: FieldMetadataType.UUID,
|
||||
label: `${restParams.label} id (foreign key)`,
|
||||
description: `${restParams.description} id foreign key`,
|
||||
defaultValue: null,
|
||||
options: undefined,
|
||||
settings: undefined,
|
||||
joinColumn,
|
||||
},
|
||||
joinColumn,
|
||||
isNullable,
|
||||
true,
|
||||
gate,
|
||||
),
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
target.constructor,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
function generateFieldMetadata<T extends FieldMetadataType>(
|
||||
params: FieldMetadataDecoratorParams<T>,
|
||||
fieldKey: string,
|
||||
isNullable: boolean,
|
||||
isSystem: boolean,
|
||||
gate: GateDecoratorParams | undefined = undefined,
|
||||
): ReflectFieldMetadata[string] {
|
||||
const defaultValue = (params.defaultValue ??
|
||||
generateDefaultValue(
|
||||
params.type,
|
||||
)) as FieldMetadataDefaultValue<'default'> | null;
|
||||
|
||||
return {
|
||||
name: fieldKey,
|
||||
...params,
|
||||
isNullable: params.type === FieldMetadataType.RELATION ? true : isNullable,
|
||||
isSystem,
|
||||
isCustom: false,
|
||||
options: params.options,
|
||||
description: params.description,
|
||||
icon: params.icon,
|
||||
defaultValue,
|
||||
gate,
|
||||
};
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
import { GateDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/gate-decorator.interface';
|
||||
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
|
||||
export function Gate(metadata: GateDecoratorParams) {
|
||||
return function (target: object, fieldKey?: string) {
|
||||
if (fieldKey) {
|
||||
TypedReflect.defineMetadata('gate', metadata, target, fieldKey);
|
||||
} else {
|
||||
TypedReflect.defineMetadata('gate', metadata, target);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
|
||||
export function IsNotAuditLogged() {
|
||||
return function (target: object) {
|
||||
TypedReflect.defineMetadata('isAuditLogged', false, target);
|
||||
};
|
||||
}
|
||||
@ -1,7 +0,0 @@
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
|
||||
export function IsNullable() {
|
||||
return function (target: object, fieldKey: string) {
|
||||
TypedReflect.defineMetadata('isNullable', true, target, fieldKey);
|
||||
};
|
||||
}
|
||||
@ -1,11 +0,0 @@
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
|
||||
export function IsSystem() {
|
||||
return function (target: object, fieldKey?: string) {
|
||||
if (fieldKey) {
|
||||
TypedReflect.defineMetadata('isSystem', true, target, fieldKey);
|
||||
} else {
|
||||
TypedReflect.defineMetadata('isSystem', true, target);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
import { ObjectMetadataDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-object-metadata.interface';
|
||||
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
import { convertClassNameToObjectMetadataName } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util';
|
||||
|
||||
export function ObjectMetadata(
|
||||
params: ObjectMetadataDecoratorParams,
|
||||
): ClassDecorator {
|
||||
return (target) => {
|
||||
const isSystem = TypedReflect.getMetadata('isSystem', target) ?? false;
|
||||
const isAuditLogged =
|
||||
TypedReflect.getMetadata('isAuditLogged', target) ?? true;
|
||||
const gate = TypedReflect.getMetadata('gate', target);
|
||||
const objectName = convertClassNameToObjectMetadataName(target.name);
|
||||
|
||||
TypedReflect.defineMetadata(
|
||||
'objectMetadata',
|
||||
{
|
||||
nameSingular: objectName,
|
||||
...params,
|
||||
targetTableName: 'DEPRECATED',
|
||||
isSystem,
|
||||
isCustom: false,
|
||||
isRemote: false,
|
||||
isAuditLogged,
|
||||
description: params.description,
|
||||
icon: params.icon,
|
||||
gate,
|
||||
},
|
||||
target,
|
||||
);
|
||||
};
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
import 'reflect-metadata';
|
||||
|
||||
import {
|
||||
ReflectRelationMetadata,
|
||||
RelationMetadataDecoratorParams,
|
||||
} from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-relation-metadata.interface';
|
||||
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
|
||||
export function RelationMetadata<TClass extends object>(
|
||||
params: RelationMetadataDecoratorParams<TClass>,
|
||||
): PropertyDecorator {
|
||||
return (target: object, fieldKey: string) => {
|
||||
const relationMetadataCollection =
|
||||
TypedReflect.getMetadata(
|
||||
'reflectRelationMetadataCollection',
|
||||
target.constructor,
|
||||
) ?? [];
|
||||
const gate = TypedReflect.getMetadata('gate', target, fieldKey);
|
||||
|
||||
TypedReflect.defineMetadata(
|
||||
'reflectRelationMetadataCollection',
|
||||
[
|
||||
...relationMetadataCollection,
|
||||
{
|
||||
target,
|
||||
fieldKey,
|
||||
...params,
|
||||
gate,
|
||||
} satisfies ReflectRelationMetadata,
|
||||
],
|
||||
target.constructor,
|
||||
);
|
||||
};
|
||||
}
|
||||
@ -6,97 +6,219 @@ import {
|
||||
PartialComputedFieldMetadata,
|
||||
PartialFieldMetadata,
|
||||
} from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface';
|
||||
import { ReflectFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-field-metadata.interface';
|
||||
import { ReflectObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-object-metadata.interface';
|
||||
import { ReflectDynamicRelationFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-computed-relation-field-metadata.interface';
|
||||
import { WorkspaceEntityMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-entity-metadata-args.interface';
|
||||
import { WorkspaceFieldMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-field-metadata-args.interface';
|
||||
import { WorkspaceDynamicRelationMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-dynamic-relation-metadata-args.interface';
|
||||
import { WorkspaceRelationMetadataArgs } from 'src/engine/twenty-orm/interfaces/workspace-relation-metadata-args.interface';
|
||||
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
import { isGatedAndNotEnabled } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/is-gate-and-not-enabled.util';
|
||||
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { createDeterministicUuid } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/create-deterministic-uuid.util';
|
||||
|
||||
@Injectable()
|
||||
export class StandardFieldFactory {
|
||||
create(
|
||||
target: object,
|
||||
target: typeof BaseWorkspaceEntity,
|
||||
context: WorkspaceSyncContext,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): (PartialFieldMetadata | PartialComputedFieldMetadata)[] {
|
||||
const reflectObjectMetadata = TypedReflect.getMetadata(
|
||||
'objectMetadata',
|
||||
target,
|
||||
);
|
||||
const reflectFieldMetadataMap =
|
||||
TypedReflect.getMetadata('fieldMetadataMap', target) ?? [];
|
||||
const reflectDynamicRelationFieldMetadataMap = TypedReflect.getMetadata(
|
||||
'dynamicRelationFieldMetadataMap',
|
||||
target,
|
||||
);
|
||||
const partialFieldMetadataCollection: (
|
||||
| PartialFieldMetadata
|
||||
| PartialComputedFieldMetadata
|
||||
)[] = Object.values(reflectFieldMetadataMap)
|
||||
.map((reflectFieldMetadata) =>
|
||||
this.createFieldMetadata(
|
||||
reflectObjectMetadata,
|
||||
reflectFieldMetadata,
|
||||
context,
|
||||
workspaceFeatureFlagsMap,
|
||||
),
|
||||
)
|
||||
.filter((metadata): metadata is PartialFieldMetadata => !!metadata);
|
||||
const partialComputedFieldMetadata = this.createComputedFieldMetadata(
|
||||
reflectDynamicRelationFieldMetadataMap,
|
||||
context,
|
||||
workspaceFeatureFlagsMap,
|
||||
);
|
||||
): Array<PartialFieldMetadata | PartialComputedFieldMetadata> {
|
||||
const workspaceEntityMetadataArgs =
|
||||
metadataArgsStorage.filterEntities(target);
|
||||
const metadataCollections = this.collectMetadata(target);
|
||||
|
||||
if (partialComputedFieldMetadata) {
|
||||
partialFieldMetadataCollection.push(partialComputedFieldMetadata);
|
||||
}
|
||||
|
||||
return partialFieldMetadataCollection;
|
||||
return [
|
||||
...this.processMetadata(
|
||||
workspaceEntityMetadataArgs,
|
||||
metadataCollections.fields,
|
||||
context,
|
||||
workspaceFeatureFlagsMap,
|
||||
this.createFieldMetadata,
|
||||
),
|
||||
...this.processMetadata(
|
||||
workspaceEntityMetadataArgs,
|
||||
metadataCollections.relations,
|
||||
context,
|
||||
workspaceFeatureFlagsMap,
|
||||
this.createFieldRelationMetadata,
|
||||
),
|
||||
...this.processMetadata(
|
||||
workspaceEntityMetadataArgs,
|
||||
metadataCollections.dynamicRelations,
|
||||
context,
|
||||
workspaceFeatureFlagsMap,
|
||||
this.createComputedFieldRelationMetadata,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
private createFieldMetadata(
|
||||
reflectObjectMetadata: ReflectObjectMetadata | undefined,
|
||||
reflectFieldMetadata: ReflectFieldMetadata[string],
|
||||
context: WorkspaceSyncContext,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): PartialFieldMetadata | undefined {
|
||||
if (
|
||||
isGatedAndNotEnabled(reflectFieldMetadata.gate, workspaceFeatureFlagsMap)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private collectMetadata(target: typeof BaseWorkspaceEntity) {
|
||||
return {
|
||||
...reflectFieldMetadata,
|
||||
workspaceId: context.workspaceId,
|
||||
isSystem:
|
||||
reflectObjectMetadata?.isSystem || reflectFieldMetadata.isSystem,
|
||||
fields: metadataArgsStorage.filterFields(target),
|
||||
relations: metadataArgsStorage.filterRelations(target),
|
||||
dynamicRelations: metadataArgsStorage.filterDynamicRelations(target),
|
||||
};
|
||||
}
|
||||
|
||||
private createComputedFieldMetadata(
|
||||
reflectDynamicRelationFieldMetadata:
|
||||
| ReflectDynamicRelationFieldMetadata
|
||||
| undefined,
|
||||
private processMetadata<
|
||||
T,
|
||||
U extends PartialFieldMetadata | PartialComputedFieldMetadata,
|
||||
>(
|
||||
workspaceEntityMetadataArgs: WorkspaceEntityMetadataArgs | undefined,
|
||||
metadataArgs: T[],
|
||||
context: WorkspaceSyncContext,
|
||||
featureFlagsMap: FeatureFlagMap,
|
||||
createMetadata: (
|
||||
workspaceEntityMetadataArgs: WorkspaceEntityMetadataArgs | undefined,
|
||||
args: T,
|
||||
context: WorkspaceSyncContext,
|
||||
featureFlagsMap: FeatureFlagMap,
|
||||
) => U[],
|
||||
): U[] {
|
||||
return metadataArgs
|
||||
.flatMap((args) =>
|
||||
createMetadata(
|
||||
workspaceEntityMetadataArgs,
|
||||
args,
|
||||
context,
|
||||
featureFlagsMap,
|
||||
),
|
||||
)
|
||||
.filter(Boolean) as U[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create field metadata
|
||||
*/
|
||||
private createFieldMetadata(
|
||||
workspaceEntityMetadataArgs: WorkspaceEntityMetadataArgs | undefined,
|
||||
workspaceFieldMetadataArgs: WorkspaceFieldMetadataArgs,
|
||||
context: WorkspaceSyncContext,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): PartialComputedFieldMetadata | undefined {
|
||||
): PartialFieldMetadata[] {
|
||||
if (
|
||||
!reflectDynamicRelationFieldMetadata ||
|
||||
isGatedAndNotEnabled(
|
||||
reflectDynamicRelationFieldMetadata.gate,
|
||||
workspaceFieldMetadataArgs.gate,
|
||||
workspaceFeatureFlagsMap,
|
||||
)
|
||||
) {
|
||||
return undefined;
|
||||
return [];
|
||||
}
|
||||
|
||||
return {
|
||||
...reflectDynamicRelationFieldMetadata,
|
||||
return [
|
||||
{
|
||||
type: workspaceFieldMetadataArgs.type,
|
||||
standardId: workspaceFieldMetadataArgs.standardId,
|
||||
name: workspaceFieldMetadataArgs.name,
|
||||
icon: workspaceFieldMetadataArgs.icon,
|
||||
label: workspaceFieldMetadataArgs.label,
|
||||
description: workspaceFieldMetadataArgs.description,
|
||||
defaultValue: workspaceFieldMetadataArgs.defaultValue,
|
||||
options: workspaceFieldMetadataArgs.options,
|
||||
workspaceId: context.workspaceId,
|
||||
isNullable: workspaceFieldMetadataArgs.isNullable,
|
||||
isCustom: false,
|
||||
isSystem:
|
||||
workspaceEntityMetadataArgs?.isSystem ||
|
||||
workspaceFieldMetadataArgs.isSystem,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create relation field metadata
|
||||
*/
|
||||
private createFieldRelationMetadata(
|
||||
workspaceEntityMetadataArgs: WorkspaceEntityMetadataArgs | undefined,
|
||||
workspaceRelationMetadataArgs: WorkspaceRelationMetadataArgs,
|
||||
context: WorkspaceSyncContext,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): PartialFieldMetadata[] {
|
||||
const fieldMetadataCollection: PartialFieldMetadata[] = [];
|
||||
const foreignKeyStandardId = createDeterministicUuid(
|
||||
workspaceRelationMetadataArgs.standardId,
|
||||
);
|
||||
|
||||
if (
|
||||
isGatedAndNotEnabled(
|
||||
workspaceRelationMetadataArgs.gate,
|
||||
workspaceFeatureFlagsMap,
|
||||
)
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (workspaceRelationMetadataArgs.joinColumn) {
|
||||
fieldMetadataCollection.push({
|
||||
type: FieldMetadataType.UUID,
|
||||
standardId: foreignKeyStandardId,
|
||||
name: workspaceRelationMetadataArgs.joinColumn,
|
||||
label: `${workspaceRelationMetadataArgs.label} id (foreign key)`,
|
||||
description: `${workspaceRelationMetadataArgs.description} id foreign key`,
|
||||
icon: workspaceRelationMetadataArgs.icon,
|
||||
defaultValue: null,
|
||||
options: undefined,
|
||||
settings: undefined,
|
||||
workspaceId: context.workspaceId,
|
||||
isCustom: false,
|
||||
isSystem: true,
|
||||
isNullable: workspaceRelationMetadataArgs.isNullable,
|
||||
});
|
||||
}
|
||||
|
||||
fieldMetadataCollection.push({
|
||||
type: FieldMetadataType.RELATION,
|
||||
standardId: workspaceRelationMetadataArgs.standardId,
|
||||
name: workspaceRelationMetadataArgs.name,
|
||||
label: workspaceRelationMetadataArgs.label,
|
||||
description: workspaceRelationMetadataArgs.description,
|
||||
icon: workspaceRelationMetadataArgs.icon,
|
||||
defaultValue: null,
|
||||
workspaceId: context.workspaceId,
|
||||
isSystem: reflectDynamicRelationFieldMetadata.isSystem,
|
||||
};
|
||||
isCustom: false,
|
||||
isSystem:
|
||||
workspaceEntityMetadataArgs?.isSystem ||
|
||||
workspaceRelationMetadataArgs.isSystem,
|
||||
isNullable: true,
|
||||
});
|
||||
|
||||
return fieldMetadataCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create computed field relation metadata
|
||||
*/
|
||||
private createComputedFieldRelationMetadata(
|
||||
workspaceEntityMetadataArgs: WorkspaceEntityMetadataArgs | undefined,
|
||||
workspaceDynamicRelationMetadataArgs:
|
||||
| WorkspaceDynamicRelationMetadataArgs
|
||||
| undefined,
|
||||
context: WorkspaceSyncContext,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): PartialComputedFieldMetadata[] {
|
||||
if (
|
||||
!workspaceDynamicRelationMetadataArgs ||
|
||||
isGatedAndNotEnabled(
|
||||
workspaceDynamicRelationMetadataArgs.gate,
|
||||
workspaceFeatureFlagsMap,
|
||||
)
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
// Foreign key will be computed in compute-standard-object.util.ts, because we need to know the custom object
|
||||
{
|
||||
type: FieldMetadataType.RELATION,
|
||||
argsFactory: workspaceDynamicRelationMetadataArgs.argsFactory,
|
||||
workspaceId: context.workspaceId,
|
||||
isCustom: false,
|
||||
isSystem:
|
||||
workspaceEntityMetadataArgs?.isSystem ||
|
||||
workspaceDynamicRelationMetadataArgs.isSystem,
|
||||
isNullable: workspaceDynamicRelationMetadataArgs.isNullable,
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,9 +4,9 @@ import { WorkspaceSyncContext } from 'src/engine/workspace-manager/workspace-syn
|
||||
import { PartialObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-object-metadata.interface';
|
||||
import { FeatureFlagMap } from 'src/engine/core-modules/feature-flag/interfaces/feature-flag-map.interface';
|
||||
|
||||
import { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects/base.object-metadata';
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
import { isGatedAndNotEnabled } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/is-gate-and-not-enabled.util';
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
|
||||
|
||||
import { StandardFieldFactory } from './standard-field.factory';
|
||||
|
||||
@ -15,7 +15,7 @@ export class StandardObjectFactory {
|
||||
constructor(private readonly standardFieldFactory: StandardFieldFactory) {}
|
||||
|
||||
create(
|
||||
standardObjectMetadataDefinitions: (typeof BaseObjectMetadata)[],
|
||||
standardObjectMetadataDefinitions: (typeof BaseWorkspaceEntity)[],
|
||||
context: WorkspaceSyncContext,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): PartialObjectMetadata[] {
|
||||
@ -27,32 +27,43 @@ export class StandardObjectFactory {
|
||||
}
|
||||
|
||||
private createObjectMetadata(
|
||||
metadata: typeof BaseObjectMetadata,
|
||||
target: typeof BaseWorkspaceEntity,
|
||||
context: WorkspaceSyncContext,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): PartialObjectMetadata | undefined {
|
||||
const objectMetadata = TypedReflect.getMetadata('objectMetadata', metadata);
|
||||
const workspaceEntityMetadataArgs =
|
||||
metadataArgsStorage.filterEntities(target);
|
||||
|
||||
if (!objectMetadata) {
|
||||
if (!workspaceEntityMetadataArgs) {
|
||||
throw new Error(
|
||||
`Object metadata decorator not found, can't parse ${metadata.name}`,
|
||||
`Object metadata decorator not found, can't parse ${target.name}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (isGatedAndNotEnabled(objectMetadata.gate, workspaceFeatureFlagsMap)) {
|
||||
if (
|
||||
isGatedAndNotEnabled(
|
||||
workspaceEntityMetadataArgs.gate,
|
||||
workspaceFeatureFlagsMap,
|
||||
)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const fields = this.standardFieldFactory.create(
|
||||
metadata,
|
||||
target,
|
||||
context,
|
||||
workspaceFeatureFlagsMap,
|
||||
);
|
||||
|
||||
return {
|
||||
...objectMetadata,
|
||||
...workspaceEntityMetadataArgs,
|
||||
// TODO: Remove targetTableName when we remove the old metadata
|
||||
targetTableName: 'DEPRECATED',
|
||||
workspaceId: context.workspaceId,
|
||||
dataSourceId: context.dataSourceId,
|
||||
isCustom: false,
|
||||
isRemote: false,
|
||||
isSystem: workspaceEntityMetadataArgs.isSystem ?? false,
|
||||
fields,
|
||||
};
|
||||
}
|
||||
|
||||
@ -3,17 +3,20 @@ import { Injectable } from '@nestjs/common';
|
||||
import { WorkspaceSyncContext } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/workspace-sync-context.interface';
|
||||
import { FeatureFlagMap } from 'src/engine/core-modules/feature-flag/interfaces/feature-flag-map.interface';
|
||||
|
||||
import { BaseObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects/base.object-metadata';
|
||||
import { TypedReflect } from 'src/utils/typed-reflect';
|
||||
import { isGatedAndNotEnabled } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/is-gate-and-not-enabled.util';
|
||||
import { assert } from 'src/utils/assert';
|
||||
import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import {
|
||||
RelationMetadataEntity,
|
||||
RelationMetadataType,
|
||||
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { convertClassNameToObjectMetadataName } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/convert-class-to-object-metadata-name.util';
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
import { metadataArgsStorage } from 'src/engine/twenty-orm/storage/metadata-args.storage';
|
||||
|
||||
interface CustomRelationFactory {
|
||||
object: ObjectMetadataEntity;
|
||||
metadata: typeof BaseObjectMetadata;
|
||||
metadata: typeof BaseWorkspaceEntity;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@ -26,7 +29,7 @@ export class StandardRelationFactory {
|
||||
): Partial<RelationMetadataEntity>[];
|
||||
|
||||
create(
|
||||
standardObjectMetadataDefinitions: (typeof BaseObjectMetadata)[],
|
||||
standardObjectMetadataDefinitions: (typeof BaseWorkspaceEntity)[],
|
||||
context: WorkspaceSyncContext,
|
||||
originalObjectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
@ -34,10 +37,10 @@ export class StandardRelationFactory {
|
||||
|
||||
create(
|
||||
standardObjectMetadataDefinitionsOrCustomObjectFactories:
|
||||
| (typeof BaseObjectMetadata)[]
|
||||
| (typeof BaseWorkspaceEntity)[]
|
||||
| {
|
||||
object: ObjectMetadataEntity;
|
||||
metadata: typeof BaseObjectMetadata;
|
||||
metadata: typeof BaseWorkspaceEntity;
|
||||
}[],
|
||||
context: WorkspaceSyncContext,
|
||||
originalObjectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
@ -46,7 +49,7 @@ export class StandardRelationFactory {
|
||||
return standardObjectMetadataDefinitionsOrCustomObjectFactories.flatMap(
|
||||
(
|
||||
standardObjectMetadata:
|
||||
| typeof BaseObjectMetadata
|
||||
| typeof BaseWorkspaceEntity
|
||||
| CustomRelationFactory,
|
||||
) =>
|
||||
this.createRelationMetadata(
|
||||
@ -59,64 +62,68 @@ export class StandardRelationFactory {
|
||||
}
|
||||
|
||||
private createRelationMetadata(
|
||||
standardObjectMetadataOrCustomRelationFactory:
|
||||
| typeof BaseObjectMetadata
|
||||
workspaceEntityOrCustomRelationFactory:
|
||||
| typeof BaseWorkspaceEntity
|
||||
| CustomRelationFactory,
|
||||
context: WorkspaceSyncContext,
|
||||
originalObjectMetadataMap: Record<string, ObjectMetadataEntity>,
|
||||
workspaceFeatureFlagsMap: FeatureFlagMap,
|
||||
): Partial<RelationMetadataEntity>[] {
|
||||
const standardObjectMetadata =
|
||||
'metadata' in standardObjectMetadataOrCustomRelationFactory
|
||||
? standardObjectMetadataOrCustomRelationFactory.metadata
|
||||
: standardObjectMetadataOrCustomRelationFactory;
|
||||
const objectMetadata = TypedReflect.getMetadata(
|
||||
'metadata' in standardObjectMetadataOrCustomRelationFactory
|
||||
? 'extendObjectMetadata'
|
||||
: 'objectMetadata',
|
||||
standardObjectMetadata,
|
||||
);
|
||||
const reflectRelationMetadataCollection = TypedReflect.getMetadata(
|
||||
'reflectRelationMetadataCollection',
|
||||
standardObjectMetadata,
|
||||
);
|
||||
const target =
|
||||
'metadata' in workspaceEntityOrCustomRelationFactory
|
||||
? workspaceEntityOrCustomRelationFactory.metadata
|
||||
: workspaceEntityOrCustomRelationFactory;
|
||||
const workspaceEntity =
|
||||
'metadata' in workspaceEntityOrCustomRelationFactory
|
||||
? metadataArgsStorage.filterExtendedEntities(target)
|
||||
: metadataArgsStorage.filterEntities(target);
|
||||
const workspaceRelationMetadataArgsCollection =
|
||||
metadataArgsStorage.filterRelations(target);
|
||||
|
||||
if (!objectMetadata) {
|
||||
if (!workspaceEntity) {
|
||||
throw new Error(
|
||||
`Object metadata decorator not found, can't parse ${standardObjectMetadata.name}`,
|
||||
`Object metadata decorator not found, can't parse ${target.name}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
!reflectRelationMetadataCollection ||
|
||||
isGatedAndNotEnabled(objectMetadata?.gate, workspaceFeatureFlagsMap)
|
||||
!workspaceRelationMetadataArgsCollection ||
|
||||
isGatedAndNotEnabled(workspaceEntity?.gate, workspaceFeatureFlagsMap)
|
||||
) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return reflectRelationMetadataCollection
|
||||
.filter(
|
||||
(reflectRelationMetadata) =>
|
||||
!isGatedAndNotEnabled(
|
||||
reflectRelationMetadata.gate,
|
||||
workspaceFeatureFlagsMap,
|
||||
),
|
||||
)
|
||||
.map((reflectRelationMetadata) => {
|
||||
return workspaceRelationMetadataArgsCollection
|
||||
.filter((workspaceRelationMetadataArgs) => {
|
||||
// We're not storing many-to-one relations in the DB for the moment
|
||||
if (
|
||||
workspaceRelationMetadataArgs.type ===
|
||||
RelationMetadataType.MANY_TO_ONE
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !isGatedAndNotEnabled(
|
||||
workspaceRelationMetadataArgs.gate,
|
||||
workspaceFeatureFlagsMap,
|
||||
);
|
||||
})
|
||||
.map((workspaceRelationMetadataArgs) => {
|
||||
// Compute reflect relation metadata
|
||||
const fromObjectNameSingular =
|
||||
'object' in standardObjectMetadataOrCustomRelationFactory
|
||||
? standardObjectMetadataOrCustomRelationFactory.object.nameSingular
|
||||
'object' in workspaceEntityOrCustomRelationFactory
|
||||
? workspaceEntityOrCustomRelationFactory.object.nameSingular
|
||||
: convertClassNameToObjectMetadataName(
|
||||
reflectRelationMetadata.target.constructor.name,
|
||||
workspaceRelationMetadataArgs.target.name,
|
||||
);
|
||||
const toObjectNameSingular = convertClassNameToObjectMetadataName(
|
||||
reflectRelationMetadata.inverseSideTarget().name,
|
||||
workspaceRelationMetadataArgs.inverseSideTarget().name,
|
||||
);
|
||||
const fromFieldMetadataName = reflectRelationMetadata.fieldKey;
|
||||
const fromFieldMetadataName = workspaceRelationMetadataArgs.name;
|
||||
const toFieldMetadataName =
|
||||
(reflectRelationMetadata.inverseSideFieldKey as string | undefined) ??
|
||||
fromObjectNameSingular;
|
||||
(workspaceRelationMetadataArgs.inverseSideFieldKey as
|
||||
| string
|
||||
| undefined) ?? fromObjectNameSingular;
|
||||
const fromObjectMetadata =
|
||||
originalObjectMetadataMap[fromObjectNameSingular];
|
||||
|
||||
@ -156,13 +163,13 @@ export class StandardRelationFactory {
|
||||
);
|
||||
|
||||
return {
|
||||
relationType: reflectRelationMetadata.type,
|
||||
relationType: workspaceRelationMetadataArgs.type,
|
||||
fromObjectMetadataId: fromObjectMetadata?.id,
|
||||
toObjectMetadataId: toObjectMetadata?.id,
|
||||
fromFieldMetadataId: fromFieldMetadata?.id,
|
||||
toFieldMetadataId: toFieldMetadata?.id,
|
||||
workspaceId: context.workspaceId,
|
||||
onDeleteAction: reflectRelationMetadata.onDelete,
|
||||
onDeleteAction: workspaceRelationMetadataArgs.onDelete,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
export interface GateDecoratorParams {
|
||||
featureFlag: string;
|
||||
}
|
||||
@ -1,19 +1,31 @@
|
||||
import { ReflectDynamicRelationFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-computed-relation-field-metadata.interface';
|
||||
import { ReflectFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-field-metadata.interface';
|
||||
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface';
|
||||
import { WorkspaceDynamicRelationMetadataArgsFactory } from 'src/engine/twenty-orm/interfaces/workspace-dynamic-relation-metadata-args.interface';
|
||||
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
|
||||
export type PartialFieldMetadata = Omit<
|
||||
ReflectFieldMetadata[string],
|
||||
'joinColumn'
|
||||
FieldMetadataInterface,
|
||||
'id' | 'label' | 'description' | 'objectMetadataId'
|
||||
> & {
|
||||
standardId: string;
|
||||
label: string | ((objectMetadata: ObjectMetadataEntity) => string);
|
||||
description?: string | ((objectMetadata: ObjectMetadataEntity) => string);
|
||||
icon?: string;
|
||||
isSystem?: boolean;
|
||||
workspaceId: string;
|
||||
objectMetadataId?: string;
|
||||
};
|
||||
|
||||
export type PartialComputedFieldMetadata =
|
||||
ReflectDynamicRelationFieldMetadata & {
|
||||
workspaceId: string;
|
||||
objectMetadataId?: string;
|
||||
};
|
||||
export type PartialComputedFieldMetadata = {
|
||||
type: FieldMetadataType.RELATION;
|
||||
argsFactory: WorkspaceDynamicRelationMetadataArgsFactory;
|
||||
isNullable?: boolean;
|
||||
isSystem?: boolean;
|
||||
isCustom: boolean;
|
||||
workspaceId: string;
|
||||
objectMetadataId?: string;
|
||||
};
|
||||
|
||||
export type ComputedPartialFieldMetadata = {
|
||||
[K in keyof PartialFieldMetadata]: ExcludeFunctions<PartialFieldMetadata[K]>;
|
||||
|
||||
@ -3,10 +3,14 @@ import {
|
||||
PartialComputedFieldMetadata,
|
||||
PartialFieldMetadata,
|
||||
} from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface';
|
||||
import { ReflectObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-object-metadata.interface';
|
||||
import { ObjectMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/object-metadata.interface';
|
||||
|
||||
export type PartialObjectMetadata = ReflectObjectMetadata & {
|
||||
id?: string;
|
||||
export type PartialObjectMetadata = Omit<
|
||||
ObjectMetadataInterface,
|
||||
'id' | 'standardId' | 'fromRelations' | 'toRelations' | 'fields' | 'isActive'
|
||||
> & {
|
||||
standardId: string;
|
||||
icon?: string;
|
||||
workspaceId: string;
|
||||
dataSourceId: string;
|
||||
fields: (PartialFieldMetadata | PartialComputedFieldMetadata)[];
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
import { ReflectRelationMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/reflect-relation-metadata.interface';
|
||||
|
||||
export type PartialRelationMetadata = ReflectRelationMetadata & {
|
||||
id: string;
|
||||
workspaceId: string;
|
||||
fromObjectMetadataId: string;
|
||||
toObjectMetadataId: string;
|
||||
fromFieldMetadataId: string;
|
||||
toFieldMetadataId: string;
|
||||
};
|
||||
@ -1,24 +0,0 @@
|
||||
import { GateDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/gate-decorator.interface';
|
||||
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
|
||||
export type DynamicRelationFieldMetadataDecoratorParams = (
|
||||
oppositeObjectMetadata: ObjectMetadataEntity,
|
||||
) => {
|
||||
standardId: string;
|
||||
name: string;
|
||||
label: string;
|
||||
joinColumn: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
};
|
||||
|
||||
export interface ReflectDynamicRelationFieldMetadata {
|
||||
type: FieldMetadataType.RELATION;
|
||||
paramsFactory: DynamicRelationFieldMetadataDecoratorParams;
|
||||
isNullable: boolean;
|
||||
isSystem: boolean;
|
||||
isCustom: boolean;
|
||||
gate?: GateDecoratorParams;
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
import { GateDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/gate-decorator.interface';
|
||||
|
||||
export type BaseCustomObjectMetadataDecoratorParams =
|
||||
| { allowObjectNameList?: string[] }
|
||||
| { denyObjectNameList?: string[] };
|
||||
|
||||
export type ReflectBaseCustomObjectMetadata =
|
||||
BaseCustomObjectMetadataDecoratorParams & {
|
||||
gate?: GateDecoratorParams;
|
||||
};
|
||||
@ -1,38 +0,0 @@
|
||||
import { FieldMetadataDefaultValue } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-default-value.interface';
|
||||
import { GateDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/gate-decorator.interface';
|
||||
import { FieldMetadataOptions } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-options.interface';
|
||||
import { FieldMetadataSettings } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-settings.interface';
|
||||
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
|
||||
export interface FieldMetadataDecoratorParams<
|
||||
T extends FieldMetadataType | 'default',
|
||||
> {
|
||||
standardId: string;
|
||||
type: T;
|
||||
label: string | ((objectMetadata: ObjectMetadataEntity) => string);
|
||||
description?: string | ((objectMetadata: ObjectMetadataEntity) => string);
|
||||
icon?: string;
|
||||
defaultValue?: FieldMetadataDefaultValue<T>;
|
||||
joinColumn?: string;
|
||||
options?: FieldMetadataOptions<T>;
|
||||
settings?: FieldMetadataSettings<T>;
|
||||
}
|
||||
|
||||
export interface ReflectFieldMetadata {
|
||||
[key: string]: Omit<
|
||||
FieldMetadataDecoratorParams<'default'>,
|
||||
'defaultValue' | 'type' | 'options' | 'settings'
|
||||
> & {
|
||||
name: string;
|
||||
type: FieldMetadataType;
|
||||
isNullable: boolean;
|
||||
isSystem: boolean;
|
||||
isCustom: boolean;
|
||||
defaultValue: FieldMetadataDefaultValue<'default'> | null;
|
||||
gate?: GateDecoratorParams;
|
||||
options?: FieldMetadataOptions<'default'> | null;
|
||||
settings?: FieldMetadataSettings<'default'> | null;
|
||||
};
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
import { GateDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/gate-decorator.interface';
|
||||
|
||||
export interface ObjectMetadataDecoratorParams {
|
||||
standardId: string;
|
||||
namePlural: string;
|
||||
labelSingular: string;
|
||||
labelPlural: string;
|
||||
description?: string;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
export interface ReflectObjectMetadata extends ObjectMetadataDecoratorParams {
|
||||
nameSingular: string;
|
||||
targetTableName: string;
|
||||
isSystem: boolean;
|
||||
isCustom: boolean;
|
||||
isRemote: boolean;
|
||||
isAuditLogged: boolean;
|
||||
gate?: GateDecoratorParams;
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
import { ObjectType } from 'typeorm';
|
||||
|
||||
import { GateDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/gate-decorator.interface';
|
||||
|
||||
import {
|
||||
RelationOnDeleteAction,
|
||||
RelationMetadataType,
|
||||
} from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
|
||||
export interface RelationMetadataDecoratorParams<T> {
|
||||
type: RelationMetadataType;
|
||||
inverseSideTarget: () => ObjectType<T>;
|
||||
inverseSideFieldKey?: keyof T;
|
||||
onDelete: RelationOnDeleteAction;
|
||||
}
|
||||
|
||||
export interface ReflectRelationMetadata
|
||||
extends RelationMetadataDecoratorParams<any> {
|
||||
target: object;
|
||||
fieldKey: string;
|
||||
gate?: GateDecoratorParams;
|
||||
onDelete: RelationOnDeleteAction;
|
||||
}
|
||||
@ -14,7 +14,7 @@ import { WorkspaceMetadataUpdaterService } from 'src/engine/workspace-manager/wo
|
||||
import { WorkspaceSyncStorage } from 'src/engine/workspace-manager/workspace-sync-metadata/storage/workspace-sync.storage';
|
||||
import { WorkspaceMigrationFieldFactory } from 'src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-field.factory';
|
||||
import { StandardFieldFactory } from 'src/engine/workspace-manager/workspace-sync-metadata/factories/standard-field.factory';
|
||||
import { CustomObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/custom-objects/custom.object-metadata';
|
||||
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
|
||||
import { computeStandardObject } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/compute-standard-object.util';
|
||||
|
||||
@Injectable()
|
||||
@ -56,7 +56,7 @@ export class WorkspaceSyncFieldMetadataService {
|
||||
|
||||
// Create standard field metadata collection
|
||||
const standardFieldMetadataCollection = this.standardFieldFactory.create(
|
||||
CustomObjectMetadata,
|
||||
CustomWorkspaceEntity,
|
||||
context,
|
||||
workspaceFeatureFlagsMap,
|
||||
);
|
||||
|
||||
@ -17,7 +17,7 @@ import { WorkspaceMigrationEntity } from 'src/engine/metadata-modules/workspace-
|
||||
import { WorkspaceSyncStorage } from 'src/engine/workspace-manager/workspace-sync-metadata/storage/workspace-sync.storage';
|
||||
import { WorkspaceMigrationRelationFactory } from 'src/engine/workspace-manager/workspace-migration-builder/factories/workspace-migration-relation.factory';
|
||||
import { standardObjectMetadataDefinitions } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects';
|
||||
import { CustomObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/custom-objects/custom.object-metadata';
|
||||
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
|
||||
|
||||
@Injectable()
|
||||
export class WorkspaceSyncRelationMetadataService {
|
||||
@ -88,7 +88,7 @@ export class WorkspaceSyncRelationMetadataService {
|
||||
this.standardRelationFactory.create(
|
||||
customObjectMetadataCollection.map((objectMetadata) => ({
|
||||
object: objectMetadata,
|
||||
metadata: CustomObjectMetadata,
|
||||
metadata: CustomWorkspaceEntity,
|
||||
})),
|
||||
context,
|
||||
originalObjectMetadataMap,
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { BASE_OBJECT_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
||||
import { FieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/field-metadata.decorator';
|
||||
import { IsSystem } from 'src/engine/workspace-manager/workspace-sync-metadata/decorators/is-system.decorator';
|
||||
|
||||
export abstract class BaseObjectMetadata {
|
||||
@FieldMetadata({
|
||||
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.id,
|
||||
type: FieldMetadataType.UUID,
|
||||
label: 'Id',
|
||||
description: 'Id',
|
||||
defaultValue: 'uuid',
|
||||
icon: 'Icon123',
|
||||
})
|
||||
@IsSystem()
|
||||
id: string;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.createdAt,
|
||||
type: FieldMetadataType.DATE_TIME,
|
||||
label: 'Creation date',
|
||||
description: 'Creation date',
|
||||
icon: 'IconCalendar',
|
||||
defaultValue: 'now',
|
||||
})
|
||||
createdAt: Date;
|
||||
|
||||
@FieldMetadata({
|
||||
standardId: BASE_OBJECT_STANDARD_FIELD_IDS.updatedAt,
|
||||
type: FieldMetadataType.DATE_TIME,
|
||||
label: 'Update date',
|
||||
description: 'Update date',
|
||||
icon: 'IconCalendar',
|
||||
defaultValue: 'now',
|
||||
})
|
||||
@IsSystem()
|
||||
updatedAt: Date;
|
||||
}
|
||||
@ -1,6 +1,5 @@
|
||||
import { ComputedPartialObjectMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-object-metadata.interface';
|
||||
import { ComputedPartialFieldMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-field-metadata.interface';
|
||||
import { PartialRelationMetadata } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/partial-relation-metadata.interface';
|
||||
|
||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
@ -28,7 +27,7 @@ export class WorkspaceSyncStorage {
|
||||
[];
|
||||
private readonly _relationMetadataDeleteCollection: RelationMetadataEntity[] =
|
||||
[];
|
||||
private readonly _relationMetadataUpdateCollection: Partial<PartialRelationMetadata>[] =
|
||||
private readonly _relationMetadataUpdateCollection: Partial<RelationMetadataEntity>[] =
|
||||
[];
|
||||
|
||||
constructor() {}
|
||||
@ -101,7 +100,7 @@ export class WorkspaceSyncStorage {
|
||||
this._relationMetadataCreateCollection.push(relation);
|
||||
}
|
||||
|
||||
addUpdateRelationMetadata(relation: Partial<PartialRelationMetadata>) {
|
||||
addUpdateRelationMetadata(relation: Partial<RelationMetadataEntity>) {
|
||||
this._relationMetadataUpdateCollection.push(relation);
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
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 type ObjectRecord<T extends BaseObjectMetadata> = {
|
||||
[K in keyof T as T[K] extends BaseObjectMetadata
|
||||
export type ObjectRecord<T extends BaseWorkspaceEntity> = {
|
||||
[K in keyof T as T[K] extends BaseWorkspaceEntity
|
||||
? `${Extract<K, string>}Id`
|
||||
: K]: T[K] extends BaseObjectMetadata ? string : T[K];
|
||||
: K]: T[K] extends BaseWorkspaceEntity ? string : T[K];
|
||||
} & {
|
||||
[K in keyof T]: T[K] extends BaseObjectMetadata ? ObjectRecord<T[K]> : T[K];
|
||||
[K in keyof T]: T[K] extends BaseWorkspaceEntity ? ObjectRecord<T[K]> : T[K];
|
||||
};
|
||||
|
||||
@ -21,11 +21,11 @@ export const computeStandardObject = (
|
||||
const fields: ComputedPartialFieldMetadata[] = [];
|
||||
|
||||
for (const partialFieldMetadata of standardObjectMetadata.fields) {
|
||||
if ('paramsFactory' in partialFieldMetadata) {
|
||||
if ('argsFactory' in partialFieldMetadata) {
|
||||
// Compute standard fields of custom object
|
||||
for (const customObjectMetadata of customObjectMetadataCollection) {
|
||||
const { paramsFactory, ...rest } = partialFieldMetadata;
|
||||
const { joinColumn, ...data } = paramsFactory(customObjectMetadata);
|
||||
const { argsFactory, ...rest } = partialFieldMetadata;
|
||||
const { joinColumn, ...data } = argsFactory(customObjectMetadata);
|
||||
const relationStandardId = createRelationDeterministicUuid({
|
||||
objectId: customObjectMetadata.id,
|
||||
standardId: data.standardId,
|
||||
@ -35,6 +35,12 @@ export const computeStandardObject = (
|
||||
standardId: data.standardId,
|
||||
});
|
||||
|
||||
if (!joinColumn) {
|
||||
throw new Error(
|
||||
`Missing joinColumn for field ${data.name} in object ${customObjectMetadata.nameSingular}`,
|
||||
);
|
||||
}
|
||||
|
||||
// Relation
|
||||
fields.push({
|
||||
...data,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { GateDecoratorParams } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/gate-decorator.interface';
|
||||
import { Gate } from 'src/engine/twenty-orm/interfaces/gate.interface';
|
||||
|
||||
export const isGatedAndNotEnabled = (
|
||||
gate: GateDecoratorParams | undefined,
|
||||
gate: Gate | undefined,
|
||||
workspaceFeatureFlagsMap: Record<string, boolean>,
|
||||
): boolean => {
|
||||
const featureFlagValue =
|
||||
|
||||
Reference in New Issue
Block a user