Deprecate FieldMetadataInterface (#13264)
# Introduction
From the moment replaced the FieldMetadataInterface definition to:
```ts
import { FieldMetadataType } from 'twenty-shared/types';
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
export type FieldMetadataInterface<
T extends FieldMetadataType = FieldMetadataType,
> = FieldMetadataEntity<T>;
```
After this PR merge will create a new one removing the type and
replacing it to `FieldMetadataEntity`.
Did not renamed it here to avoid conflicts on naming + type issues fixs
within the same PR
## Field metadata entity RELATION or MORPH
Relations fields cannot be null for those field metadata entity instance
anymore, but are never for the others see
`packages/twenty-server/src/engine/metadata-modules/field-metadata/types/field-metadata-entity-test.type.ts`
( introduced TypeScript tests )
## Concerns
- TS_VECTOR is the most at risk with the `generatedType` and
`asExpression` removal from interface
## What's next
- `FielMetadataInterface` removal and rename ( see introduction )
- Depcrecating `ObjectMetadataInterface`
- Refactor `FieldMetadataEntity` optional fiels to be nullable only
- TO DIG `never` occurences on settings, defaultValue etc
- Some interfaces will be replaced by the `FlatFieldMetadata` when
deprecating the current sync and comparators tools
This commit is contained in:
@ -1,7 +1,11 @@
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
|
||||
import { WorkspaceEntityDuplicateCriteria } from 'src/engine/api/graphql/workspace-query-builder/types/workspace-entity-duplicate-criteria.type';
|
||||
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';
|
||||
|
||||
const workspaceId = '20202020-1c25-4d02-bf25-6aeccf7ea419';
|
||||
|
||||
export const mockPersonObjectMetadataWithFieldMaps = (
|
||||
duplicateCriteria: WorkspaceEntityDuplicateCriteria[],
|
||||
@ -24,7 +28,7 @@ export const mockPersonObjectMetadataWithFieldMaps = (
|
||||
duplicateCriteria: duplicateCriteria,
|
||||
labelIdentifierFieldMetadataId: '',
|
||||
imageIdentifierFieldMetadataId: '',
|
||||
workspaceId: '',
|
||||
workspaceId,
|
||||
indexMetadatas: [],
|
||||
fieldIdByName: {
|
||||
name: 'name-id',
|
||||
@ -34,9 +38,10 @@ export const mockPersonObjectMetadataWithFieldMaps = (
|
||||
},
|
||||
fieldIdByJoinColumnName: {},
|
||||
fieldsById: {
|
||||
'name-id': {
|
||||
id: '',
|
||||
'name-id': getMockFieldMetadataEntity({
|
||||
workspaceId,
|
||||
objectMetadataId: '',
|
||||
id: 'name-id',
|
||||
type: FieldMetadataType.FULL_NAME,
|
||||
name: 'name',
|
||||
label: 'Name',
|
||||
@ -44,18 +49,18 @@ export const mockPersonObjectMetadataWithFieldMaps = (
|
||||
lastName: "''",
|
||||
firstName: "''",
|
||||
},
|
||||
description: 'Contact’s name',
|
||||
description: "Contact's name",
|
||||
isCustom: false,
|
||||
isNullable: true,
|
||||
isUnique: false,
|
||||
workspaceId: '',
|
||||
isLabelSyncedWithName: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
'emails-id': {
|
||||
id: '',
|
||||
}) as FieldMetadataEntity,
|
||||
'emails-id': getMockFieldMetadataEntity({
|
||||
workspaceId,
|
||||
objectMetadataId: '',
|
||||
id: 'emails-id',
|
||||
type: FieldMetadataType.EMAILS,
|
||||
name: 'emails',
|
||||
label: 'Emails',
|
||||
@ -63,49 +68,48 @@ export const mockPersonObjectMetadataWithFieldMaps = (
|
||||
primaryEmail: "''",
|
||||
additionalEmails: null,
|
||||
},
|
||||
description: 'Contact’s Emails',
|
||||
description: "Contact's Emails",
|
||||
isCustom: false,
|
||||
isNullable: true,
|
||||
workspaceId: '',
|
||||
isLabelSyncedWithName: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
'linkedinLink-id': {
|
||||
id: '',
|
||||
}) as FieldMetadataEntity,
|
||||
'linkedinLink-id': getMockFieldMetadataEntity({
|
||||
workspaceId,
|
||||
objectMetadataId: '',
|
||||
id: 'linkedinLink-id',
|
||||
type: FieldMetadataType.LINKS,
|
||||
name: 'linkedinLink',
|
||||
label: 'Linkedin',
|
||||
defaultValue: {
|
||||
primaryLinkUrl: "''",
|
||||
secondaryLinks: "'[]'",
|
||||
secondaryLinks: [],
|
||||
primaryLinkLabel: "''",
|
||||
},
|
||||
description: 'Contact’s Linkedin account',
|
||||
description: "Contact's Linkedin account",
|
||||
isCustom: false,
|
||||
isNullable: true,
|
||||
isUnique: false,
|
||||
workspaceId: '',
|
||||
isLabelSyncedWithName: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
'jobTitle-id': {
|
||||
id: '',
|
||||
}) as FieldMetadataEntity,
|
||||
'jobTitle-id': getMockFieldMetadataEntity({
|
||||
workspaceId,
|
||||
objectMetadataId: '',
|
||||
id: 'jobTitle-id',
|
||||
type: FieldMetadataType.TEXT,
|
||||
name: 'jobTitle',
|
||||
label: 'Job Title',
|
||||
defaultValue: "''",
|
||||
description: 'Contact’s job title',
|
||||
description: "Contact's job title",
|
||||
isCustom: false,
|
||||
isNullable: false,
|
||||
isUnique: false,
|
||||
workspaceId: '20202020-1c25-4d02-bf25-6aeccf7ea419',
|
||||
isLabelSyncedWithName: true,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
}) as FieldMetadataEntity,
|
||||
},
|
||||
});
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
|
||||
import { GraphQLEnumType } from 'graphql';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { WorkspaceBuildSchemaOptions } from 'src/engine/api/graphql/workspace-schema-builder/interfaces/workspace-build-schema-optionts.interface';
|
||||
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface';
|
||||
@ -54,11 +55,13 @@ export class EnumTypeDefinitionFactory {
|
||||
): GraphQLEnumType {
|
||||
// FixMe: It's a hack until Typescript get fixed on union types for reduce function
|
||||
// https://github.com/microsoft/TypeScript/issues/36390
|
||||
const enumOptions = transformEnumValue(fieldMetadata.options) as Array<
|
||||
FieldMetadataDefaultOption | FieldMetadataComplexOption
|
||||
>;
|
||||
const enumOptions = transformEnumValue(
|
||||
fieldMetadata.options ?? undefined,
|
||||
) as
|
||||
| Array<FieldMetadataDefaultOption | FieldMetadataComplexOption>
|
||||
| undefined;
|
||||
|
||||
if (!enumOptions) {
|
||||
if (!isDefined(enumOptions)) {
|
||||
this.logger.error(
|
||||
`Enum options are not defined for ${fieldMetadata.name}`,
|
||||
{
|
||||
|
||||
@ -117,7 +117,7 @@ export class RelationConnectInputTypeDefinitionFactory {
|
||||
} else {
|
||||
const scalarType = this.typeMapperService.mapToScalarType(
|
||||
field.type,
|
||||
field.settings,
|
||||
field.settings ?? undefined,
|
||||
field.name === 'id',
|
||||
);
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ const getTypeFactoryOptions = <T extends FieldMetadataType>(
|
||||
) => {
|
||||
return isInputTypeDefinitionKind(kind)
|
||||
? {
|
||||
nullable: fieldMetadata.isNullable,
|
||||
nullable: fieldMetadata.isNullable ?? undefined,
|
||||
defaultValue: fieldMetadata.defaultValue,
|
||||
isArray:
|
||||
kind !== InputTypeDefinitionKind.Filter &&
|
||||
@ -117,7 +117,7 @@ const getTypeFactoryOptions = <T extends FieldMetadataType>(
|
||||
isIdField: fieldMetadata.name === 'id',
|
||||
}
|
||||
: {
|
||||
nullable: fieldMetadata.isNullable,
|
||||
nullable: fieldMetadata.isNullable ?? undefined,
|
||||
isArray: fieldMetadata.type === FieldMetadataType.MULTI_SELECT,
|
||||
settings: fieldMetadata.settings,
|
||||
// Scalar type is already defined in the entity itself.
|
||||
|
||||
Reference in New Issue
Block a user