CreateFieldInput transpilation to FlatFieldMetadata, FlatFieldMetadata validation (#13493)
# Introduction Following https://github.com/twentyhq/twenty/pull/13420 What has been done: - `CreateFieldInput` transpilation to `FlatFieldMetadata` - `FlatFieldMetadata` validator service - A lof of transpilation utils from `input` to `flatObject` or `flatField` - Created dedicated v2 api metadata services - Introducing `inferDeletionFromMissingObjectFieldIndex` in the builder, to avoid diffing every object and field of the current workspace we allow only generating create/update migration operations, usefull when passing by the api metadata ## We still need to in another PR: - Implement a strong unit test coverage and critical functions and services - Finalize flat field metadata validation exception for `options` `defaultValue` `settings` and `relations` - Finalize `flatObjectMetadata` validation and v2 service refactor - Plug the new service when feature flag is enabled
This commit is contained in:
+8
-8
@@ -62,17 +62,17 @@ describe('validateFieldNameAvailabilityOrThrow', () => {
|
||||
({ context: { input, shouldNotThrow } }) => {
|
||||
if (shouldNotThrow) {
|
||||
expect(() =>
|
||||
validateFieldNameAvailabilityOrThrow(
|
||||
input,
|
||||
objectMetadataMapItemMock,
|
||||
),
|
||||
validateFieldNameAvailabilityOrThrow({
|
||||
name: input,
|
||||
objectMetadata: objectMetadataMapItemMock,
|
||||
}),
|
||||
).not.toThrow();
|
||||
} else {
|
||||
expect(() =>
|
||||
validateFieldNameAvailabilityOrThrow(
|
||||
input,
|
||||
objectMetadataMapItemMock,
|
||||
),
|
||||
validateFieldNameAvailabilityOrThrow({
|
||||
name: input,
|
||||
objectMetadata: objectMetadataMapItemMock,
|
||||
}),
|
||||
).toThrowErrorMatchingSnapshot();
|
||||
}
|
||||
},
|
||||
|
||||
+8
-4
@@ -31,10 +31,14 @@ const getReservedCompositeFieldNames = (
|
||||
return reservedCompositeFieldsNames;
|
||||
};
|
||||
|
||||
export const validateFieldNameAvailabilityOrThrow = (
|
||||
name: string,
|
||||
objectMetadata: ObjectMetadataItemWithFieldMaps,
|
||||
) => {
|
||||
type ValidateFieldNameAvailabilityOrThrowArgs = {
|
||||
name: string;
|
||||
objectMetadata: ObjectMetadataItemWithFieldMaps;
|
||||
};
|
||||
export const validateFieldNameAvailabilityOrThrow = ({
|
||||
name,
|
||||
objectMetadata,
|
||||
}: ValidateFieldNameAvailabilityOrThrowArgs) => {
|
||||
const reservedCompositeFieldsNames =
|
||||
getReservedCompositeFieldNames(objectMetadata);
|
||||
|
||||
|
||||
+7
-4
@@ -7,10 +7,13 @@ import {
|
||||
InvalidMetadataExceptionCode,
|
||||
} from 'src/engine/metadata-modules/utils/exceptions/invalid-metadata.exception';
|
||||
|
||||
export const validateNameAndLabelAreSyncOrThrow = (
|
||||
label: string,
|
||||
name: string,
|
||||
) => {
|
||||
export const validateNameAndLabelAreSyncOrThrow = ({
|
||||
label,
|
||||
name,
|
||||
}: {
|
||||
label: string;
|
||||
name: string;
|
||||
}) => {
|
||||
const computedName = computeMetadataNameFromLabel(label);
|
||||
|
||||
if (name !== computedName) {
|
||||
|
||||
Reference in New Issue
Block a user