Files
twenty/packages/twenty-server/src/modules/messaging/common/standard-objects/message-channel-message-association.workspace-entity.ts
Paul Rastoin 9ad8287dbc [REFACTOR] twenty-shared multi barrel and CJS/ESM build with preconstruct (#11083)
# 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 !
2025-03-22 19:16:06 +01:00

118 lines
4.8 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 { WorkspaceEntity } from 'src/engine/twenty-orm/decorators/workspace-entity.decorator';
import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field.decorator';
import { WorkspaceIndex } from 'src/engine/twenty-orm/decorators/workspace-index.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 {
MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS,
MESSAGE_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 { MessageDirection } from 'src/modules/messaging/common/enums/message-direction.enum';
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { MessageWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message.workspace-entity';
@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.messageChannelMessageAssociation,
namePlural: 'messageChannelMessageAssociations',
labelSingular: msg`Message Channel Message Association`,
labelPlural: msg`Message Channel Message Associations`,
description: msg`Message Synced with a Message Channel`,
icon: STANDARD_OBJECT_ICONS.messageChannelMessageAssociation,
})
@WorkspaceIsNotAuditLogged()
@WorkspaceIsSystem()
@WorkspaceIndex(['messageChannelId', 'messageId'], {
isUnique: true,
indexWhereClause: '"deletedAt" IS NULL',
})
export class MessageChannelMessageAssociationWorkspaceEntity extends BaseWorkspaceEntity {
@WorkspaceField({
standardId:
MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS.messageExternalId,
type: FieldMetadataType.TEXT,
label: msg`Message External Id`,
description: msg`Message id from the messaging provider`,
icon: 'IconHash',
})
@WorkspaceIsNullable()
messageExternalId: string | null;
@WorkspaceField({
standardId:
MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS.messageThreadExternalId,
type: FieldMetadataType.TEXT,
label: msg`Thread External Id`,
description: msg`Thread id from the messaging provider`,
icon: 'IconHash',
})
@WorkspaceIsNullable()
messageThreadExternalId: string | null;
@WorkspaceField({
standardId: MESSAGE_STANDARD_FIELD_IDS.direction,
type: FieldMetadataType.SELECT,
label: msg`Direction`,
description: msg`Message Direction`,
icon: 'IconDirection',
options: [
{
value: MessageDirection.INCOMING,
label: 'Incoming',
position: 0,
color: 'green',
},
{
value: MessageDirection.OUTGOING,
label: 'Outgoing',
position: 1,
color: 'blue',
},
],
defaultValue: `'${MessageDirection.INCOMING}'`,
})
direction: MessageDirection;
@WorkspaceRelation({
standardId:
MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS.messageChannel,
type: RelationMetadataType.MANY_TO_ONE,
label: msg`Message Channel Id`,
description: msg`Message Channel Id`,
icon: 'IconHash',
inverseSideTarget: () => MessageChannelWorkspaceEntity,
inverseSideFieldKey: 'messageChannelMessageAssociations',
})
@WorkspaceIsNullable()
messageChannel: Relation<MessageChannelWorkspaceEntity> | null;
@WorkspaceJoinColumn('messageChannel')
messageChannelId: string;
@WorkspaceRelation({
standardId: MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS.message,
type: RelationMetadataType.MANY_TO_ONE,
label: msg`Message Id`,
description: msg`Message Id`,
icon: 'IconHash',
inverseSideTarget: () => MessageWorkspaceEntity,
inverseSideFieldKey: 'messageChannelMessageAssociations',
})
@WorkspaceIsNullable()
message: Relation<MessageWorkspaceEntity> | null;
@WorkspaceJoinColumn('message')
messageId: string;
}