2 - Transforming data
All data transformation in Enterspeed is done from a set of schema definitions. Schemas are the glue that ties your existing data to your new layout.
So when designing your schema, you get to choose which of your existing data you wish to use in your new layout- and how it should be structured.
How does it work?
You start by choosing which data sources you want to use (triggers
).
Afterward, you begin designing your schema by mapping which data from your data sources you want to use, e.g., a title. The actual schema design is done in the properties
object.
If you want to make your schema routable you define a route
. By defining a route
, you can fetch it via the Delivery API.
When you finish designing your schema, it's time to deploy it. Deploying the schema will automatically generate a View for each Source Entity Type.
A View is the actual data that has been transformed. If you have 10 Source Entity Types linked to your schema, this will generate 10 Views.
Views will be generated if you:
- Deploy the schema again (this will regenerate all Views).
- A new Source Entity with the same type is available (this will only generate Views for the new Source Entities).
- A Source Entity gets Created, Updated, or Deleted via the Ingest API (This will affect the Views for the specific Source Entity).
Example
Below is a simple example showing how a schema can look for transforming source entities with the type of frontPage
.
- Source entity
- Schema design
- Output data
Given the frontPage
source entity have the following content.
{
"id": "1044-en-us",
"type": "frontPage",
"url": "/frontPage",
"properties": {
"title": "Welcome"
}
}
When designing our we access the title property from the sourceEntity
.
We make the schema routable by using routes
and using the url
from the source entity.
/** @type {Enterspeed.FullSchema} */
export default {
triggers: function(context) {
context.triggers('cms', ['frontpage'])
},
routes: function(sourceEntity, context) {
context.url(sourceEntity.url)
},
properties: function (sourceEntity, context) {
return {
headline: sourceEntity.properties.title
}
}
}
When querying the Delivery API with url=/frontPage
the output will be:
{
"title": "Welcome"
}
Next, let's start learning how to design a schema. Go to designing a schema