A Lix Schema is a formal definition that describes the structure of data for a type of entity. It acts as a contract that ensures data is consistent and understandable throughout the Lix ecosystem.
Lix schemas are based on the widely-used JSON Schema standard, with a few Lix-specific extensions.
Schemas are fundamental to how Lix understands and manages data. They are not just for validation; they are the core of what makes entity-level operations possible.
property
(the path) and a value
.Lix Schemas extend standard JSON Schema with several x-lix-
properties that provide Lix-specific metadata.
Let's start with a simple example, the JSONPropertySchema
from the Lix JSON Plugin:
This schema has two types of fields:
1. Lix-Specific Fields (Basic):
x-lix-key
: A globally unique string that identifies this schema. When a plugin reports a change, it references this key, telling Lix which schema to use for validation and interpretation.x-lix-version
: A version number for the schema itself, allowing schemas to evolve over time.2. Standard JSON Schema Fields:
type
, properties
, required
, etc.: These are standard JSON Schema keywords that define the shape of the data.Lix Schemas offer additional x-lix-
properties to define more complex relationships and constraints, enabling features like primary keys, unique constraints, foreign keys, and auto-generated fields.
Let's look at a more advanced AccountSchema
example:
Here are the additional Lix-specific fields used in this advanced schema:
x-lix-primary-key
: An array of property names that form the primary key for entities conforming to this schema. These properties uniquely identify an entity.x-lix-unique
: An array of arrays, where each inner array specifies a set of properties that must be unique across all entities of this schema.x-lix-foreign-keys
: An array of objects defining foreign key constraints. Each object specifies:
properties
: The local properties that form the foreign key.references
: An object detailing the referenced schema (schemaKey
) and its properties.mode
: (Optional) Validation mode ("immediate"
or "materialized"
).x-lix-generated
: (Used within a property definition) A boolean flag indicating that the property's value is automatically generated by Lix (e.g., for IDs or timestamps).2. Standard JSON Schema Fields:
type
, properties
, required
, etc.: These are standard JSON Schema keywords that define the shape of the data.