Skip to content

Data normalization

Eduardo Bouças edited this page Mar 16, 2020 · 5 revisions

Source plugins are expected to add data to two specific data buckets.

models

Products like content management systems typically have the concept of models or content types. Source plugins are expected to add information about these models to the models data bucket, as objects with the following properties:

PropertyTypeDescriptionExample
fieldNamesArray An array containing the names of the model fields['title', 'subtitle', 'author']
sourceStringThe name of the source plugin as used in its package.jsonsourcebit-source-contentful
modelNameStringThe ID or machine-friendly name of the modelblog
modelLabelStringThe human-friendly name of the modelBlog Posts
projectIdStringThe ID of the project within the source platformContentful space ID
projectEnvironmentStringThe environment within the source platformContentful space environment

💡 For data sources that don't have the concept of a project ID or environment, these values can be set to an empty string.

objects

The objects data bucket contains all entries coming from the various data sources. Source plugins must normalize all entries before adding them to the data bucket. This normalization consists of adding a property called __metadata, containing an object with the following properties:

PropertyTypeDescriptionExample
idStringA unique identifier for the object123456789
sourceStringThe name of the source plugin as used in its package.jsonsourcebit-source-contentful
modelNameStringThe ID or machine-friendly name of the modelblog
modelLabelStringThe human-friendly name of the modelBlog Posts
projectIdStringThe ID of the project within the source platformContentful space ID
projectEnvironmentStringThe environment within the source platformContentful space environment
createdAtStringThe ISO 8601 representation of the entry's creation date2011-10-05T14:48:00.000Z
updatedAtStringThe ISO 8601 representation of the entry's last update date2011-10-05T15:30:00.000Z

All content fields should be placed at the root level of the entry object.

  • 🚫

    {
    "type": "blog",
    "meta": {
    "_id": "123456789",
    "created_at": "2011-10-05T14:48:00.000Z",
    "updated_at": "2011-10-05T15:30:00.000Z"
    },
    "fields": {
    "title": "Normalizing entries",
    "subtitle": "Because normal is good"
    }
    }
  • {
    "title": "Normalizing entries",
    "subtitle": "Because normal is good",
    "__metadata": {
    "id": "123456789",
    "source": "source-source-contentful",
    "modelName": "blog",
    "modelLabel": "Blog posts",
    "projectId": "1q2w3e4r",
    "projectEnvironment": "master",
    "createdAt": "2011-10-05T14:48:00.000Z",
    "updatedAt": "2011-10-05T15:30:00.000Z"
    }
    }

💡 For data sources that don't have the concept of a unique ID for each entry, you're advised to auto-generate one using a package like https://www.npmjs.com/package/uuid.

Assets

Asset objects are subject to an additional normalization routine. The structure of the objects will be changed so that they always contain the following properties, in addition to any user-defined properties if the source supports it:

  • contentType (String): The MIME type describing the asset type
  • fileName (String): The name of the original file
  • url (String): The full asset URL

A __metadata block will still be added, but the value of the modelName property will be set to __asset.

Clone this wiki locally