This document describes the language rules for writing your own Liveblocks schemas. It is an exhaustive account of all features that are implemented and supported as part of the the public beta and is open source.
We support: scalars, arrays, objects, optionals, LiveObject
, LiveList
,
LiveMap
, and most unions. We’re sharing our plans for other syntaxes so you
can give us early feedback
here.
Each schema must include the Storage
type, a special type of “root” object.
Familiar scalar types are globally available when you create a schema:
string
number
boolean
null
A sample schema using only scalar types could look like this:
And here are some updates that would be accepted and rejected by the schema:
You can also use literal types to restrict values even further:
Each field inside an object type can be marked optional using the ?
operator.
An optional field means that it can be deleted.
For example, to make the age
field optional:
Accepted and rejected updates:
Our language supports two different ways to declare object types:
These definitions are equivalent. Accepted and rejected updates:
To use an object type definition as a “live” object, wrap it in the built-in
LiveObject
construct, like
so:
Accepted and rejected updates:
Arrays can be defined like this:
Accepted and rejected updates:
To use a “live” array instead of a normal array, wrap your item type in a
LiveList
when you reference
it.
For example:
Accepted and rejected updates:
It’s also possible to define a
LiveMap
in your schema.
For example:
The first argument to a LiveMap
construct must always be string
.
Accepted and rejected updates:
You can model a choice between two types using a union, which will be familiar from TypeScript. Here are some examples:
We’re also planning to support more language features. Discriminated unions, regex, ranges, etc...
If you’re interested in a specific feature, please send your feedback on this GitHub discussion so we can prioritize it appropriately!