# Introduction In this PR we've migrated `twenty-shared` from a `vite` app [libary-mode](https://vite.dev/guide/build#library-mode) to a [preconstruct](https://preconstruct.tools/) "atomic" application ( in the future would like to introduce preconstruct to handle of all our atomic dependencies such as `twenty-emails` `twenty-ui` etc it will be integrated at the monorepo's root directly, would be to invasive in the first, starting incremental via `twenty-shared`) For more information regarding the motivations please refer to nor: - https://github.com/twentyhq/core-team-issues/issues/587 - https://github.com/twentyhq/core-team-issues/issues/281#issuecomment-2630949682 close https://github.com/twentyhq/core-team-issues/issues/589 close https://github.com/twentyhq/core-team-issues/issues/590 ## How to test In order to ease the review this PR will ship all the codegen at the very end, the actual meaning full diff is `+2,411 −114` In order to migrate existing dependent packages to `twenty-shared` multi barrel new arch you need to run in local: ```sh yarn tsx packages/twenty-shared/scripts/migrateFromSingleToMultiBarrelImport.ts && \ npx nx run-many -t lint --fix -p twenty-front twenty-ui twenty-server twenty-emails twenty-shared twenty-zapier ``` Note that `migrateFromSingleToMultiBarrelImport` is idempotent, it's atm included in the PR but should not be merged. ( such as codegen will be added before merging this script will be removed ) ## Misc - related opened issue preconstruct https://github.com/preconstruct/preconstruct/issues/617 ## Closed related PR - https://github.com/twentyhq/twenty/pull/11028 - https://github.com/twentyhq/twenty/pull/10993 - https://github.com/twentyhq/twenty/pull/10960 ## Upcoming enhancement: ( in others dedicated PRs ) - 1/ refactor generate barrel to export atomic module instead of `*` - 2/ generate barrel own package with several files and tests - 3/ Migration twenty-ui the same way - 4/ Use `preconstruct` at monorepo global level ## Conclusion As always any suggestions are welcomed !
251 lines
9.6 KiB
TypeScript
251 lines
9.6 KiB
TypeScript
import { msg } from '@lingui/core/macro';
|
|
import { FieldMetadataType } from 'twenty-shared/types';
|
|
|
|
import { Relation } from 'src/engine/workspace-manager/workspace-sync-metadata/interfaces/relation.interface';
|
|
|
|
import { RelationMetadataType } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
|
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
|
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
|
|
import { WorkspaceDynamicRelation } from 'src/engine/twenty-orm/decorators/workspace-dynamic-relation.decorator';
|
|
import { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
|
|
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
|
|
import { WorkspaceIsNotAuditLogged } from 'src/engine/twenty-orm/decorators/workspace-is-not-audit-logged.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 { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
|
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
|
import { TIMELINE_ACTIVITY_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
|
import { STANDARD_OBJECT_ICONS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-icons';
|
|
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
|
import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity';
|
|
import { NoteWorkspaceEntity } from 'src/modules/note/standard-objects/note.workspace-entity';
|
|
import { OpportunityWorkspaceEntity } from 'src/modules/opportunity/standard-objects/opportunity.workspace-entity';
|
|
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
|
import { TaskWorkspaceEntity } from 'src/modules/task/standard-objects/task.workspace-entity';
|
|
import { WorkflowRunWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-run.workspace-entity';
|
|
import { WorkflowVersionWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow-version.workspace-entity';
|
|
import { WorkflowWorkspaceEntity } from 'src/modules/workflow/common/standard-objects/workflow.workspace-entity';
|
|
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
|
|
|
|
@WorkspaceEntity({
|
|
standardId: STANDARD_OBJECT_IDS.timelineActivity,
|
|
namePlural: 'timelineActivities',
|
|
labelSingular: msg`Timeline Activity`,
|
|
labelPlural: msg`Timeline Activities`,
|
|
description: msg`Aggregated / filtered event to be displayed on the timeline`,
|
|
icon: STANDARD_OBJECT_ICONS.timelineActivity,
|
|
})
|
|
@WorkspaceIsSystem()
|
|
@WorkspaceIsNotAuditLogged()
|
|
export class TimelineActivityWorkspaceEntity extends BaseWorkspaceEntity {
|
|
@WorkspaceField({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.happensAt,
|
|
type: FieldMetadataType.DATE_TIME,
|
|
label: msg`Creation date`,
|
|
description: msg`Creation date`,
|
|
icon: 'IconCalendar',
|
|
defaultValue: 'now',
|
|
})
|
|
happensAt: Date;
|
|
|
|
@WorkspaceField({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.name,
|
|
type: FieldMetadataType.TEXT,
|
|
label: msg`Event name`,
|
|
description: msg`Event name`,
|
|
icon: 'IconAbc',
|
|
})
|
|
name: string;
|
|
|
|
@WorkspaceField({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.properties,
|
|
type: FieldMetadataType.RAW_JSON,
|
|
label: msg`Event details`,
|
|
description: msg`Json value for event details`,
|
|
icon: 'IconListDetails',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
properties: JSON | null;
|
|
|
|
// Special objects that don't have their own timeline and are 'link' to the main object
|
|
@WorkspaceField({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.linkedRecordCachedName,
|
|
type: FieldMetadataType.TEXT,
|
|
label: msg`Linked Record cached name`,
|
|
description: msg`Cached record name`,
|
|
icon: 'IconAbc',
|
|
})
|
|
linkedRecordCachedName: string;
|
|
|
|
@WorkspaceField({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.linkedRecordId,
|
|
type: FieldMetadataType.UUID,
|
|
label: msg`Linked Record id`,
|
|
description: msg`Linked Record id`,
|
|
icon: 'IconAbc',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
linkedRecordId: string | null;
|
|
|
|
@WorkspaceField({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.linkedObjectMetadataId,
|
|
type: FieldMetadataType.UUID,
|
|
label: msg`Linked Object Metadata Id`,
|
|
description: msg`Linked Object Metadata Id`,
|
|
icon: 'IconAbc',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
linkedObjectMetadataId: string | null;
|
|
|
|
// Who made the action
|
|
@WorkspaceRelation({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.workspaceMember,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: msg`Workspace Member`,
|
|
description: msg`Event workspace member`,
|
|
icon: 'IconCircleUser',
|
|
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
workspaceMember: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('workspaceMember')
|
|
workspaceMemberId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.person,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: msg`Person`,
|
|
description: msg`Event person`,
|
|
icon: 'IconUser',
|
|
inverseSideTarget: () => PersonWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
person: Relation<PersonWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('person')
|
|
personId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.company,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: msg`Company`,
|
|
description: msg`Event company`,
|
|
icon: 'IconBuildingSkyscraper',
|
|
inverseSideTarget: () => CompanyWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
company: Relation<CompanyWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('company')
|
|
companyId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.opportunity,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: msg`Opportunity`,
|
|
description: msg`Event opportunity`,
|
|
icon: 'IconTargetArrow',
|
|
inverseSideTarget: () => OpportunityWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
opportunity: Relation<OpportunityWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('opportunity')
|
|
opportunityId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.note,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: msg`Note`,
|
|
description: msg`Event note`,
|
|
icon: 'IconTargetArrow',
|
|
inverseSideTarget: () => NoteWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
note: Relation<NoteWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('note')
|
|
noteId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.task,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: msg`Task`,
|
|
description: msg`Event task`,
|
|
icon: 'IconTargetArrow',
|
|
inverseSideTarget: () => TaskWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
task: Relation<TaskWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('task')
|
|
taskId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.workflow,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: msg`Workflow`,
|
|
description: msg`Event workflow`,
|
|
icon: 'IconTargetArrow',
|
|
inverseSideTarget: () => WorkflowWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
workflow: Relation<WorkflowWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('workflow')
|
|
workflowId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.workflowVersion,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: msg`WorkflowVersion`,
|
|
description: msg`Event workflow version`,
|
|
icon: 'IconTargetArrow',
|
|
inverseSideTarget: () => WorkflowVersionWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
workflowVersion: Relation<WorkflowVersionWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('workflowVersion')
|
|
workflowVersionId: string | null;
|
|
|
|
@WorkspaceRelation({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.workflowRun,
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
label: msg`Workflow Run`,
|
|
description: msg`Event workflow run`,
|
|
icon: 'IconTargetArrow',
|
|
inverseSideTarget: () => WorkflowRunWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
@WorkspaceIsNullable()
|
|
workflowRun: Relation<WorkflowRunWorkspaceEntity> | null;
|
|
|
|
@WorkspaceJoinColumn('workflowRun')
|
|
workflowRunId: string | null;
|
|
|
|
@WorkspaceDynamicRelation({
|
|
type: RelationMetadataType.MANY_TO_ONE,
|
|
argsFactory: (oppositeObjectMetadata) => ({
|
|
standardId: TIMELINE_ACTIVITY_STANDARD_FIELD_IDS.custom,
|
|
name: oppositeObjectMetadata.nameSingular,
|
|
label: oppositeObjectMetadata.labelSingular,
|
|
description: `Timeline Activity ${oppositeObjectMetadata.labelSingular}`,
|
|
joinColumn: `${oppositeObjectMetadata.nameSingular}Id`,
|
|
icon: 'IconTimeline',
|
|
}),
|
|
inverseSideTarget: () => CustomWorkspaceEntity,
|
|
inverseSideFieldKey: 'timelineActivities',
|
|
})
|
|
custom: Relation<CustomWorkspaceEntity>;
|
|
}
|