Deprecate ObjectMetadataInterface and improve entity typing (#13310)

# Introduction
Following `FieldMetadataInterface` deprecation in
https://github.com/twentyhq/twenty/pull/13264
As for the previous PR will rename and remove all the file in a
secondary PR to avoid conflicts and over loading this one

## Improvements
Removed optional properties from the `objectMetadataEntity` model and
added utils to retrieve test data

## Notes
By touching to `ObjectMetadataDTO` I would have expected a twenty-front
codegenerated types mutation, but it does not seem to be granular enough
to null/undefined coercion
This commit is contained in:
Paul Rastoin
2025-07-21 17:53:17 +02:00
committed by GitHub
parent 79f3fbb016
commit 1536ed3434
23 changed files with 1031 additions and 909 deletions
@@ -1,206 +1,205 @@
import { FieldMetadataType } from 'twenty-shared/types';
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { ObjectMetadataItemWithFieldMaps } from 'src/engine/metadata-modules/types/object-metadata-item-with-field-maps';
import { getMockFieldMetadataEntity } from 'src/utils/__test__/get-field-metadata-entity.mock';
import { getMockObjectMetadataItemWithFieldsMaps } from 'src/utils/__test__/get-object-metadata-item-with-fields-maps.mock';
const workspaceId = '20202020-0000-0000-0000-000000000000';
export const mockObjectMetadataItemsWithFieldMaps: ObjectMetadataItemWithFieldMaps[] =
[
{
id: '20202020-8dec-43d5-b2ff-6eef05095bec',
standardId: '',
nameSingular: 'person',
namePlural: 'people',
labelSingular: 'Person',
labelPlural: 'People',
description: 'A person',
icon: 'test-person-icon',
targetTableName: 'DEPRECATED',
isCustom: false,
isRemote: false,
isActive: true,
isSystem: false,
isAuditLogged: true,
isSearchable: true,
labelIdentifierFieldMetadataId: 'nameFieldMetadataId',
imageIdentifierFieldMetadataId: '',
workspaceId,
indexMetadatas: [],
fieldsById: {
nameFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-8dec-43d5-b2ff-6eef05095bec',
id: 'nameFieldMetadataId',
type: FieldMetadataType.FULL_NAME,
icon: 'test-field-icon',
name: 'name',
label: 'Name',
defaultValue: {
lastName: "''",
firstName: "''",
},
description: "Contact's name",
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
},
fieldIdByName: {
name: 'nameFieldMetadataId',
},
fieldIdByJoinColumnName: {},
export const mockObjectMetadataItemsWithFieldMaps = [
getMockObjectMetadataItemWithFieldsMaps({
id: '20202020-8dec-43d5-b2ff-6eef05095bec',
standardId: '',
nameSingular: 'person',
namePlural: 'people',
labelSingular: 'Person',
labelPlural: 'People',
description: 'A person',
icon: 'test-person-icon',
targetTableName: 'DEPRECATED',
isCustom: false,
isRemote: false,
isActive: true,
isSystem: false,
isAuditLogged: true,
isSearchable: true,
labelIdentifierFieldMetadataId: 'nameFieldMetadataId',
imageIdentifierFieldMetadataId: '',
workspaceId,
indexMetadatas: [],
fieldsById: {
nameFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-8dec-43d5-b2ff-6eef05095bec',
id: 'nameFieldMetadataId',
type: FieldMetadataType.FULL_NAME,
icon: 'test-field-icon',
name: 'name',
label: 'Name',
defaultValue: {
lastName: "''",
firstName: "''",
},
description: "Contact's name",
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
},
{
id: '20202020-c03c-45d6-a4b0-04afe1357c5c',
standardId: '',
nameSingular: 'company',
namePlural: 'companies',
labelSingular: 'Company',
labelPlural: 'Companies',
description: 'A company',
icon: 'test-company-icon',
targetTableName: 'DEPRECATED',
isCustom: false,
isRemote: false,
isActive: true,
isSystem: false,
isAuditLogged: true,
isSearchable: true,
labelIdentifierFieldMetadataId: 'nameFieldMetadataId',
imageIdentifierFieldMetadataId: '',
workspaceId,
indexMetadatas: [],
fieldsById: {
nameFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-c03c-45d6-a4b0-04afe1357c5c',
id: 'nameFieldMetadataId',
type: FieldMetadataType.TEXT,
icon: 'test-field-icon',
name: 'name',
label: 'Name',
defaultValue: '',
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
domainNameFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-c03c-45d6-a4b0-04afe1357c5c',
id: 'domainNameFieldMetadataId',
type: FieldMetadataType.LINKS,
icon: 'test-field-icon',
name: 'domainName',
label: 'Domain Name',
defaultValue: {
primaryLinkLabel: '',
primaryLinkUrl: '',
secondaryLinks: [],
},
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
},
fieldIdByName: {
name: 'nameFieldMetadataId',
domainName: 'domainNameFieldMetadataId',
},
fieldIdByJoinColumnName: {},
fieldIdByName: {
name: 'nameFieldMetadataId',
},
{
id: '20202020-3d75-4aab-bacd-ee176c5f63ca',
standardId: '',
nameSingular: 'regular-custom-object',
namePlural: 'regular-custom-objects',
labelSingular: 'Regular Custom Object',
labelPlural: 'Regular Custom Objects',
description: 'A regular custom object',
icon: 'test-regular-custom-object-icon',
targetTableName: 'DEPRECATED',
isCustom: true,
isRemote: false,
isActive: true,
isSystem: false,
isAuditLogged: true,
isSearchable: true,
labelIdentifierFieldMetadataId: 'nameFieldMetadataId',
imageIdentifierFieldMetadataId: 'imageIdentifierFieldMetadataId',
workspaceId,
indexMetadatas: [],
fieldsById: {
nameFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-3d75-4aab-bacd-ee176c5f63ca',
id: 'nameFieldMetadataId',
type: FieldMetadataType.TEXT,
icon: 'test-field-icon',
name: 'name',
label: 'Name',
defaultValue: '',
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
imageIdentifierFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-3d75-4aab-bacd-ee176c5f63ca',
id: 'imageIdentifierFieldMetadataId',
type: FieldMetadataType.TEXT,
icon: 'test-field-icon',
name: 'imageIdentifierFieldName',
label: 'Image Identifier Field Name',
defaultValue: '',
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
},
fieldIdByName: {
name: 'nameFieldMetadataId',
imageIdentifierFieldName: 'imageIdentifierFieldMetadataId',
},
fieldIdByJoinColumnName: {},
fieldIdByJoinColumnName: {},
}),
getMockObjectMetadataItemWithFieldsMaps({
id: '20202020-c03c-45d6-a4b0-04afe1357c5c',
standardId: '',
nameSingular: 'company',
namePlural: 'companies',
labelSingular: 'Company',
labelPlural: 'Companies',
description: 'A company',
icon: 'test-company-icon',
targetTableName: 'DEPRECATED',
isCustom: false,
isRemote: false,
isActive: true,
isSystem: false,
isAuditLogged: true,
isSearchable: true,
labelIdentifierFieldMetadataId: 'nameFieldMetadataId',
imageIdentifierFieldMetadataId: '',
workspaceId,
indexMetadatas: [],
fieldsById: {
nameFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-c03c-45d6-a4b0-04afe1357c5c',
id: 'nameFieldMetadataId',
type: FieldMetadataType.TEXT,
icon: 'test-field-icon',
name: 'name',
label: 'Name',
defaultValue: '',
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
domainNameFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-c03c-45d6-a4b0-04afe1357c5c',
id: 'domainNameFieldMetadataId',
type: FieldMetadataType.LINKS,
icon: 'test-field-icon',
name: 'domainName',
label: 'Domain Name',
defaultValue: {
primaryLinkLabel: '',
primaryLinkUrl: '',
secondaryLinks: [],
},
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
},
{
id: '20202020-540c-4397-b872-2a90ea2fb809',
standardId: '',
nameSingular: 'non-searchable-object',
namePlural: 'non-searchable-objects',
labelSingular: '',
labelPlural: '',
description: '',
icon: 'test-non-searchable-object-icon',
targetTableName: 'DEPRECATED',
isCustom: false,
isRemote: false,
isActive: true,
isSystem: true,
isAuditLogged: true,
isSearchable: false,
labelIdentifierFieldMetadataId: '',
imageIdentifierFieldMetadataId: '',
workspaceId,
indexMetadatas: [],
fieldsById: {},
fieldIdByName: {},
fieldIdByJoinColumnName: {},
fieldIdByName: {
name: 'nameFieldMetadataId',
domainName: 'domainNameFieldMetadataId',
},
];
fieldIdByJoinColumnName: {},
}),
getMockObjectMetadataItemWithFieldsMaps({
id: '20202020-3d75-4aab-bacd-ee176c5f63ca',
standardId: '',
nameSingular: 'regular-custom-object',
namePlural: 'regular-custom-objects',
labelSingular: 'Regular Custom Object',
labelPlural: 'Regular Custom Objects',
description: 'A regular custom object',
icon: 'test-regular-custom-object-icon',
targetTableName: 'DEPRECATED',
isCustom: true,
isRemote: false,
isActive: true,
isSystem: false,
isAuditLogged: true,
isSearchable: true,
labelIdentifierFieldMetadataId: 'nameFieldMetadataId',
imageIdentifierFieldMetadataId: 'imageIdentifierFieldMetadataId',
workspaceId,
indexMetadatas: [],
fieldsById: {
nameFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-3d75-4aab-bacd-ee176c5f63ca',
id: 'nameFieldMetadataId',
type: FieldMetadataType.TEXT,
icon: 'test-field-icon',
name: 'name',
label: 'Name',
defaultValue: '',
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
imageIdentifierFieldMetadataId: getMockFieldMetadataEntity({
workspaceId,
objectMetadataId: '20202020-3d75-4aab-bacd-ee176c5f63ca',
id: 'imageIdentifierFieldMetadataId',
type: FieldMetadataType.TEXT,
icon: 'test-field-icon',
name: 'imageIdentifierFieldName',
label: 'Image Identifier Field Name',
defaultValue: '',
isCustom: false,
isNullable: true,
isUnique: false,
isLabelSyncedWithName: true,
createdAt: new Date(),
updatedAt: new Date(),
}) as FieldMetadataEntity,
},
fieldIdByName: {
name: 'nameFieldMetadataId',
imageIdentifierFieldName: 'imageIdentifierFieldMetadataId',
},
fieldIdByJoinColumnName: {},
}),
getMockObjectMetadataItemWithFieldsMaps({
id: '20202020-540c-4397-b872-2a90ea2fb809',
standardId: '',
nameSingular: 'non-searchable-object',
namePlural: 'non-searchable-objects',
labelSingular: '',
labelPlural: '',
description: '',
icon: 'test-non-searchable-object-icon',
targetTableName: 'DEPRECATED',
isCustom: false,
isRemote: false,
isActive: true,
isSystem: true,
isAuditLogged: true,
isSearchable: false,
labelIdentifierFieldMetadataId: '',
imageIdentifierFieldMetadataId: '',
workspaceId,
indexMetadatas: [],
fieldsById: {},
fieldIdByName: {},
fieldIdByJoinColumnName: {},
}),
];
@@ -1,7 +1,7 @@
import { objectRecordChangedValues } from 'src/engine/core-modules/event-emitter/utils/object-record-changed-values';
import { ObjectMetadataItemWithFieldMaps } from 'src/engine/metadata-modules/types/object-metadata-item-with-field-maps';
import { getMockObjectMetadataItemWithFieldsMaps } from 'src/utils/__test__/get-object-metadata-item-with-fields-maps.mock';
const mockObjectMetadata: ObjectMetadataItemWithFieldMaps = {
const mockObjectMetadata = getMockObjectMetadataItemWithFieldsMaps({
id: '1',
icon: 'Icon123',
nameSingular: 'Object',
@@ -21,7 +21,7 @@ const mockObjectMetadata: ObjectMetadataItemWithFieldMaps = {
isSearchable: true,
indexMetadatas: [],
fieldIdByJoinColumnName: {},
};
});
describe('objectRecordChangedValues', () => {
it('detects changes in scalar values correctly', () => {
@@ -142,7 +142,7 @@ const computeSchemaComponent = ({
const result: OpenAPIV3_1.SchemaObject = {
type: 'object',
description: item.description,
description: item.description ?? undefined,
properties: convertObjectMetadataToSchemaProperties({
item,
forResponse,