Skip to content

Latest commit

Β 

History

History
725 lines (475 loc) Β· 15.2 KB

validation.md

File metadata and controls

725 lines (475 loc) Β· 15.2 KB

Contentful Migration – Validations

Here is a list of supported validations.

INVALID_PROPERTY_NAME

Whenever trying to set a property which doesn't exist, and we couldn't offer any suggestion to use as a replacement.

Example:

field.fdskljhdf('Ctrl + arm')

INVALID_PROPERTY_NAME_WITH_SUGGESTION

Whenever trying to set a property which doesn't exist, and we could offer a suggestion to use as a replacement.

Example:

field.nmae('First name')

INVALID_PROPERTY_TYPE

Whenever setting a value to a property which is not matching the expected type.

Example:

field.name(true)

INVALID_MOVEMENT_TYPE

Whenever trying to move a field with the wrong type for the field id.

Example:

contentType.moveField(3).toTheTop()

INVALID_MOVEMENT_WITH_SELF

Whenever trying to move a field relative to itself.

Example:

contentType.moveField('name').afterField('name')

INVALID_MOVEMENT_NAME

Whenever trying to move a field relative to another with an invalid movement.

Example:

contentType.moveField('name').xyz('surname')

INVALID_MOVEMENT_NAME_WITH_SUGGESTION

Whenever trying to move a field relative to another with an invalid movement but we can provide a suggestion.

Example:

contentType.moveField('name').after('surname')

While evaluating your migration script we validate that the actions you want to perform on content types and fields aren't wrong in any sense. These validations are bound to the entity type and action on which they ocurred. Therefore the error keys are scoped to it and have a layout of {entity}.{action}.{validation name}.

field.create.FIELD_ALREADY_CREATED

Whenever trying to create twice the same field.

Example:

contentType.createField('name').name('First name')

contentType.createField('name').name('Last name')

field.create.CONTENT_TYPE_DOES_NOT_EXIST

Whenever trying to create a field on a non-existing content type.

Example:

// While no `inexistent` content type exists in the target space
migration.editContentType('inexistent').createField('foo')

field.delete.FIELD_ALREADY_DELETED

Whenever trying to delete a field twice.

Example:

contentType.deleteField('name')

contentType.deleteField('name')

field.delete.FIELD_DOES_NOT_EXIST

Whenever trying to delete a field which doesn't exist.

Example:

contentType.createField('name')
// ...
contentType.deleteField('nmae')

field.delete.CONTENT_TYPE_DOES_NOT_EXIST

Whenever trying to delete a field of a content type which doesn't exist.

Example:

// While no `inexistent` content type exists in the target space
migration.editContentType('inexistent').deleteField('foo')

field.update.FIELD_DOES_NOT_EXIST

Whenever trying to edit a field which doesn't exist.

Example:

contentType.createField('name')
// ...
contentType.editField('nmae')

field.update.FIELD_ALREADY_DELETED

Whenever trying to update a field after it has been deleted.

Example:

contentType.deleteField('name')

contentType.editField('name')

field.update.CONTENT_TYPE_DOES_NOT_EXIST

Whenever trying to update a field on a non-existing content type.

Example:

// While no `inexistent` content type exists in the target space
migration.editContentType('inexistent').editField('foo')

contentType.create.CONTENT_TYPE_ALREADY_CREATED

Whenever trying to create a content type twice.

Example:

migration.createContentType('author').name('Author')
// ...
migration.createContentType('author').name('Editor')

field.move.FIELD_DELETED

Whenever trying to move a field which was already deleted.

Example:

contentType.deleteField('name')
// ...
contentType.moveField('name').toTheTop()

field.move.FIELD_DOES_NOT_EXIST

Whenever trying to move a field which doesn't exists.

field.move.FIELD_ALREADY_MOVED

Whenever trying to move a field which was already moved.

Example:

contentType.moveField('name').toTheTop()
contentType.moveField('name').toTheBottom()

field.move.CONTENT_TYPE_DOES_NOT_EXIST

Whenever you try to move a field on a non existing content type.

field.move.PIVOT_FIELD_DOES_NOT_EXIST

Whenever you try to move field relative to another one which doesn't exist.

Example:

contentType.moveField('name').afterField('somefield-that-doesnt-exist')

field.move.PIVOT_FIELD_DELETED

Whenever you try to move a field relative to another one which has been already deleted.

Example:

contentType.deleteField('surname')
contentType.moveField('name').afterField('surname')

contentType.create.CONTENT_TYPE_ALREADY_EXISTS

Whenever trying to create a content type which already exists in the target space.

Example:

// While `author` already exists in the target space
migration.createContentType('author').name('Author')

contentType.update.CONTENT_TYPE_NOT_YET_CREATED

Whenever trying to edit a content type which doesn't exist currently. (i.e. is created later in the migration)

Example:

// While no `inexistent` content type exists in the target space
migration.editContentType('inexistent')
migration.createContentType('inexistent')

contentType.update.CONTENT_TYPE_DOES_NOT_EXIST

Whenever trying to create or edit a field of a content type which hasn't yet been created.

Example:

author.createField('fullName').name('Full name')

const author = migration.createContentType('author').name('Author')

Some other validation errors pop up when checking the payload generated after applying your migration. On this case the validation keys are scoped only by the entity on which the ocurred: {entity}.{validation name}

contentType.REQUIRED_PROPERTY

Whenever a required property is missing in the definition, such as, for example, name for fields of content types.

Example:

const author = migration.createContentType('author')

contentType.TOO_MANY_FIELDS

Whenever hitting the 50 fields limit on a content type, while trying to create a new field.

Example:

const author = migration.createContentType('author').name('Author')

for (let i = 0; i < 60; i++) {
  author
    .createField('dummy-' + i)
    .name('Dummy field ' + i)
    .type('Symbol')
}

contentType.TOO_MANY_RESOURCE_LINK_FIELDS

Whenever hitting the 3 resource link field limit on a content type, while trying to create a new field.

Example:

const author = migration.createContentType('author').name('Author')

for (let i = 0; i < 4; i++) {
  author
    .createField('dummy-' + i)
    .name('Dummy field ' + i)
    .type('ResourceLink')
    .allowedResources(/* ... */)
}

contentType.NON_EXISTENT_DISPLAY_FIELD

Whenever setting the displayField of a content type to an ID of a field which doesn't exist.

Example:

const author = migration.createContentType('author').name('Author').displayField('fullName')

author.createField('firstName').name('First name').type('Symbol')

author.createField('lastName').name('Last name').type('Symbol')

contentType.DELETE_DISPLAY_FIELD

Whenever trying to delete the field used as the displayField of the content type.

Example:

const author = migration.createContentType('author').name('Author').displayField('fullName')

author.createField('fullName').name('Full name').type('Symbol')

author.deleteField('fullName')

contentType.ID_MUST_BE_DIFFERENT

When setting a new field ID to the value it already has.

Example:

author.changeFieldId('fullName', 'fullName')

contentType.ID_MUST_BE_UNIQUE

When giving a field an ID that another field on the same content type already has.

Example:

author.createField('fullName').name('Full name').type('Symbol')

author.changeFieldId('firstName', 'fullName')

contentType.ID_MUST_MATCH_SCHEMA

When setting a new field ID that does not match the requirements.

Example:

author.changeFieldId('fullName', '!%#')

field.REQUIRED_PROPERTY

Whenever a required property is missing in the definition, such as, for example, the type property of a field.

Example:

contentType.createField('author').name('Author')
// .type('Symbol') is missing

## field.REQUIRED_DEPENDENT_PROPERTY
Whenever editing an element, but forgetting to set a required property, such as `items` for fields of type `Array` or `linkType` for fields of type `Link`.

**Example:**
```javascript
const author = migration.createContentType('author')
  .name('Author')

author.createField('articles')
  .name('Written articles')
  .type('Array')

// Missing the `items` property

field.FORBIDDEN_DEPENDENT_PROPERTY

Whenever using a property which is not compatible with the type of the field.

Example:

const author = migration.createContentType('author').name('Author')

author.createField('fullName').name('Full name').type('Symbol').items({ type: 'Asset' })

// `items` is not compatible with field type `Symbol`.

field.PROPERTY_MUST_BE_ONE_OF

Whenever trying to set a field type with a value which is not allowed.

Example:

author.createField('fullName').name('Full name').type('Wrong')

Allowed types are listed in the createField documentation.

field.NO_DELETE_WITHOUT_OMIT

Whenever using deleted(true) on a field which hasn't been omitted first (using omitted(true)).

Example:

const author = migration.editContentType('author')

// Missing the following code:
// author.editField('fullName')
//  .omitted(true)

author.editField('fullName').deleted(true)

Note: you may use the deleteField shorthand method to do both operations at once.

field.NO_TYPE_CHANGE

Whenever trying to edit the type of an existing field.

Example:

author.createField('fullName').name('Full name').type('Symbol')

author.editField('fullName').type('Text')

Field types can't be changed, you must disable and omit the field, and create a new field with the right type and a different ID instead.

field.validations.DUPLICATED_VALIDATION

Whenever trying to add the same validation twice.

Example:

author
  .createField('fullName')
  .name('Full name')
  .type('Symbol')
  .validations([{ unique: true }, { unique: true }])

field.validations.INVALID_VALIDATION_PROPERTY

Whenever trying to set a non existing validation.

Example:

author
  .createField('fullName')
  .name('Full name')
  .type('Symbol')
  .validations([{ customValidation: { crazy: 'stuff' } }])

field.validations.INVALID_VALIDATION_PARAMETER

Whenever trying to set the wrong parameters for a validation.

Example:

author
  .createField('fullName')
  .name('Full name')
  .type('Symbol')
  .validations([
    { unique: 'yes' }, // needs to be Boolean
    { size: 5 } // needs to be object { min, max }
  ])

field.allowedResources.DUPLICATE_SOURCE

When trying to set the same space multiple times in one allowedResources property.

Example:

author
  .createField('works')
  .name('Works')
  .type('ResourceLink')
  .allowedResources([
    {
      source: 'crn:contentful:::content:spaces/books'
      // ...
    },
    {
      source: 'crn:contentful:::content:spaces/books'
      // ...
    }
  ])

field.allowedResources.INVALID_RESOURCE

When trying to set an allowed resource that is not an object.

Example:

author
  .createField('works')
  .name('Works')
  .type('ResourceLink')
  .allowedResources(['crn:contentful:::content:spaces/books'])

field.allowedResources.INVALID_RESOURCE_PROPERTY

When trying to set an allowed resource where a property of an allowed resource is missing, unexpected, or has the wrong format.

Example:

author
  .createField('works')
  .name('Works')
  .type('ResourceLink')
  .allowedResources([
    {
      type: 'InvalidType'
      // ...
    }
  ])

field.allowedResources.TOO_FEW_ITEMS

When trying to set an empty list of allowed resources.

Example:

author.createField('works').name('Works').type('ResourceLink').allowedResources([])

field.allowedResources.TOO_MANY_ITEMS

When trying to set more than 3 allowed resources on a field.

Example:

author.createField('works').name('Works').type('ResourceLink').allowedResources([
  {
    /* ... */
  },
  {
    /* ... */
  },
  {
    /* ... */
  },
  {
    /* ... */
  }
])

DUPLICATE_PROP

When setting the same property on a content type or field multiple times.

Example:

author.createField('fullName').name('Full name').type('Symbol').name('Name')

Note that steps in the migration description are grouped into what will be requests to Contentful's API. If the property changes would not end up in the same request because they are done in a later, separate step, this will not produce an error.

Example:

author.createField('fullName').name('Full name').type('Symbol')

migration.deleteContentType('reader')

author.editField('fullName').name('Name')

editorLayout.TOO_MANY_TABS

When saving an editor layout with more than 5 tabs

Example:

editorLayout.createFieldGroup('content', {
  name: 'Content'
})

editorLayout.createFieldGroup('references', {
  name: 'References'
})

editorLayout.createFieldGroup('settings', {
  name: 'Settings'
})

editorLayout.createFieldGroup('seo', {
  name: 'SEO'
})

editorLayout.createFieldGroup('keywords', {
  name: 'Keywords'
})

editorLayout.createFieldGroup('extras', {
  name: 'Extras'
})

editorLayout.TAB_CONTROL_INVALID

When saving an editor layout with a tab that has fieldset control

Example:

editorLayout.createFieldGroup('settings', {
  name: 'Settings'
})

editorLayout.changeFieldGroupControl('settings', 'builtin', 'fieldset')

editorLayout.FIELDSET_CONTROL_INVALID

When saving an editor layout with a field set that has topLevelTab control

Example:

editorLayout.createFieldGroup('settings', {
  name: 'Settings'
})

editorLayout.editFieldGroup('settings').createFieldGroup('seo').name('SEO')

editorLayout.changeFieldGroupControl('seo', 'builtin', 'topLevelTab')

editorLayout.FIELD_GROUP_LEVEL_TOO_DEEP

When saving an editor layout with more than 2 levels deep

Example:

editorLayout.createFieldGroup('settings', {
  name: 'Settings'
})

editorLayout.editFieldGroup('settings').createFieldGroup('seo').name('SEO')

editorLayout.editFieldGroup('seo').createFieldGroup('keywords').name('Keywords')

editorLayout.TOO_FEW_FIELD_GROUPS

When saving an editor layout with less than 2 field groups.

Example:

editorLayout.createFieldGroup('content', {
  name: 'Content'
})

editorLayout.TOO_MANY_FIELD_SETS

When saving an editor layout with more than 15 field sets.

Example:

editorLayout.createFieldGroup('content', {
  name: 'Content'
})

for (let i = 0; i <= 15; i++) {
  editorLayout
    .editFieldGroup('content')
    .createFieldGroup('dummy-' + i)
    .name('Dummy group ' + i)
}