ObjectMetadataServiceV2.createOne (#13849)
# Introduction Introducing v2 object metadata service create one handler v2, not overkilling the flatObjectMetadata validation for the moment that will require sequential validation for the import in order to handle relations and morph relations
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
import { t } from '@lingui/core/macro';
|
||||
import camelCase from 'lodash.camelcase';
|
||||
|
||||
import { type FlatMetadataValidator } from 'src/engine/metadata-modules/types/flat-metadata-validator.type';
|
||||
import {
|
||||
beneathDatabaseIdentifierMinimumLength,
|
||||
exceedsDatabaseIdentifierMaximumLength,
|
||||
} from 'src/engine/metadata-modules/utils/validate-database-identifier-length.utils';
|
||||
import { RESERVED_METADATA_NAME_KEYWORDS } from 'src/engine/metadata-modules/utils/validate-metadata-name-is-not-reserved-keyword';
|
||||
import { STARTS_WITH_LOWER_CASE_AND_CONTAINS_ONLY_CAPS_AND_LOWER_LETTERS_AND_NUMBER_STRING_REGEX } from 'src/engine/metadata-modules/utils/validate-metadata-name-start-with-lowercase-letter-and-contain-digits-nor-letters.utils';
|
||||
|
||||
export const METADATA_NAME_VALIDATORS: FlatMetadataValidator<string>[] = [
|
||||
{
|
||||
message: t`Name is too long`,
|
||||
validator: (name) => exceedsDatabaseIdentifierMaximumLength(name),
|
||||
},
|
||||
{
|
||||
message: t`Name is too short`,
|
||||
validator: (name) => beneathDatabaseIdentifierMinimumLength(name),
|
||||
},
|
||||
{
|
||||
message: t`Name should be in camelCase`,
|
||||
validator: (name) => name !== camelCase(name),
|
||||
},
|
||||
{
|
||||
message: t`Name is not valid: it must start with lowercase letter and contain only alphanumeric letters`,
|
||||
validator: (name) =>
|
||||
!name.match(
|
||||
STARTS_WITH_LOWER_CASE_AND_CONTAINS_ONLY_CAPS_AND_LOWER_LETTERS_AND_NUMBER_STRING_REGEX,
|
||||
),
|
||||
},
|
||||
{
|
||||
message: t`The name is not available`,
|
||||
validator: (name) => RESERVED_METADATA_NAME_KEYWORDS.includes(name),
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user