blocksuite/docs/api/@blocksuite/store/classes/Schema.md
BlockSuite API Documentation / @blocksuite/store / Schema
Represents a schema manager for block flavours and their relationships. Provides methods to register, validate, and query block schemas.
readonlyflavourSchemaMap:Map<string, {model: {children?:string[];flavour:string;isFlatData?:boolean;parent?:string[];props?: (...args) =>Record<string,any>;role:string;toModel?: (...args) =>BlockModel<object>; };transformer?: (...args) =>BaseBlockTransformer<object>;version:number; }>
A map storing block flavour names to their corresponding schema definitions.
get versions():
object
Returns an object mapping each registered flavour to its version number.
object
get(
flavour): {model: {children?:string[];flavour:string;isFlatData?:boolean;parent?:string[];props?: (...args) =>Record<string,any>;role:string;toModel?: (...args) =>BlockModel<object>; };transformer?: (...args) =>BaseBlockTransformer<object>;version:number; } |undefined
Retrieves the schema for a given block flavour.
string
The block flavour name.
{ model: { children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; }; transformer?: (...args) => BaseBlockTransformer<object>; version: number; } | undefined
The corresponding BlockSchemaType or undefined if not found.
isValid(
child,parent):boolean
Checks if the child flavour is valid under the parent flavour.
string
The child block flavour name.
string
The parent block flavour name.
boolean
True if the relationship is valid, false otherwise.
register(
blockSchema):Schema
Registers an array of block schemas into the schema manager.
object[]
An array of block schema definitions to register.
Schema
The Schema instance (for chaining).
safeValidate(
flavour,parentFlavour?,childFlavours?):boolean
Safely validates the schema relationship for a given flavour, parent, and children. Returns true if valid, false otherwise (does not throw).
string
The block flavour to validate.
string
The parent block flavour (optional).
string[]
The child block flavours (optional).
boolean
True if the schema relationship is valid, false otherwise.
toJSON():
object
Serializes the schema map to a plain object for JSON output.
object
An object mapping each flavour to its role, parent, and children.
validate(
flavour,parentFlavour?,childFlavours?):void
Validates the schema relationship for a given flavour, parent, and children. Throws SchemaValidateError if invalid.
string
The block flavour to validate.
string
The parent block flavour (optional).
string[]
The child block flavours (optional).
void
If the schema relationship is invalid.
validateSchema(
child,parent):void
Validates the relationship between a child and parent schema. Throws if the relationship is invalid.
The child block schema.
{ children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; } = ...
string[] = ContentSchema
string = FlavourSchema
boolean = ...
string[] = ParentSchema
(...args) => Record<string, any> = ...
string = RoleSchema
(...args) => BlockModel<object> = ...
(...args) => BaseBlockTransformer<object> = ...
number = ...
The parent block schema.
{ children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; } = ...
string[] = ContentSchema
string = FlavourSchema
boolean = ...
string[] = ParentSchema
(...args) => Record<string, any> = ...
string = RoleSchema
(...args) => BlockModel<object> = ...
(...args) => BaseBlockTransformer<object> = ...
number = ...
void
If the relationship is invalid.