@getplate/delta-client v1.1.0
delta-client-schema
This library is part of the Delta Client utility packages. It provides a utility to convert abstract building blocks and their values to usable data structures.
Usage
Defining a schema looks as follows consists of a root object and nested fields. For example for a building block that has a welcome message, the schema would look like this:
import { s } from "@getplate/delta-client/schema";
const heroBuildingBlock = s.object({
title: s.primitive(c('root', 'title')),
description: s.cast(c('root', 'description')),
images: s.array(s.asset())
})
The schema can then be used to convert the abstract building block to a usable data structure:
import { p as parser } from "@getplate/delta-client/schema";
const heroBuildingBlock = parser.parse(schema, buildingBlockFieldFulfillments);
Yields:
const heroBuildingBlock = {
title: "Hero Title",
description: {
type: 'root',
children: [
{
type: 'text',
value: 'Welcome to our website'
}
]
},
images: [
{
fileName: "first image",
url: 'https://example.com/image.jpg',
}
]
}
API
Object
s.object({
// shape of the object
})
Array
Default array with one placeholder
s.array(
s.primitive('value')
)
Array with a limit of the maximum number of items to display
s.array(
s.primitive('value'), 5 // limit to 5 items
)
Array with an array of placeholders, also uses this a minimum number of items to display
s.array(
[
s.primitive('value'),
s.primitive('value'),
// other fields
]
)
Primitive
string
s.primitive('value')
number
s.primitive(23)
Asset
Accepts a partial Asset object as a placeholder
s.asset({
fileName: 'first',
url: 'https://example.com/image.jpg'
})
PathPart
Accepts a partial PathPart object as a placeholder
s.pathPart({
path: '/blogs',
})
GridPlacement
Accepts a partial GridPlacement object as a placeholder
s.gridPlacement({
prn: 'prn:grid:123',
row: 1
})
Cast
Accepts a correct root object to cast the schema to a usable data structure
s.cast({
type: 'root',
children: []
})