Files
AFFiNE-Mirror/blocksuite/docs/api/@blocksuite/store/classes/Schema.md
Mirone 0785438cfe docs(editor): add typedoc for schema module (#12830)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Documentation**
- Added comprehensive documentation for the `Schema` class, detailing
its methods, properties, and usage.
- Improved formatting and linking in the documentation for the `Store`
class, enhancing clarity and navigation.
- Updated the README to include a direct link to the new `Schema` class
documentation.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-06-16 22:24:40 +08:00

5.5 KiB

BlockSuite API Documentation


BlockSuite API Documentation / @blocksuite/store / Schema

Class: Schema

Represents a schema manager for block flavours and their relationships. Provides methods to register, validate, and query block schemas.

Properties

flavourSchemaMap

readonly flavourSchemaMap: 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.

Accessors

versions

Get Signature

get versions(): object

Returns an object mapping each registered flavour to its version number.

Returns

object

Methods

get()

get(flavour): undefined | { 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; }

Retrieves the schema for a given block flavour.

Parameters

flavour

string

The block flavour name.

Returns

undefined | { 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; }

The corresponding BlockSchemaType or undefined if not found.


isValid()

isValid(child, parent): boolean

Checks if the child flavour is valid under the parent flavour.

Parameters

child

string

The child block flavour name.

parent

string

The parent block flavour name.

Returns

boolean

True if the relationship is valid, false otherwise.


register()

register(blockSchema): Schema

Registers an array of block schemas into the schema manager.

Parameters

blockSchema

object[]

An array of block schema definitions to register.

Returns

Schema

The Schema instance (for chaining).


safeValidate()

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).

Parameters

flavour

string

The block flavour to validate.

parentFlavour?

string

The parent block flavour (optional).

childFlavours?

string[]

The child block flavours (optional).

Returns

boolean

True if the schema relationship is valid, false otherwise.


toJSON()

toJSON(): object

Serializes the schema map to a plain object for JSON output.

Returns

object

An object mapping each flavour to its role, parent, and children.


validate()

validate(flavour, parentFlavour?, childFlavours?): void

Validates the schema relationship for a given flavour, parent, and children. Throws SchemaValidateError if invalid.

Parameters

flavour

string

The block flavour to validate.

parentFlavour?

string

The parent block flavour (optional).

childFlavours?

string[]

The child block flavours (optional).

Returns

void

Throws

If the schema relationship is invalid.


validateSchema()

validateSchema(child, parent): void

Validates the relationship between a child and parent schema. Throws if the relationship is invalid.

Parameters

child

The child block schema.

model

{ children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; } = ...

model.children?

string[] = ContentSchema

model.flavour

string = FlavourSchema

model.isFlatData?

boolean = ...

model.parent?

string[] = ParentSchema

model.props?

(...args) => Record<string, any> = ...

model.role

string = RoleSchema

model.toModel?

(...args) => BlockModel<object> = ...

transformer?

(...args) => BaseBlockTransformer<object> = ...

version

number = ...

parent

The parent block schema.

model

{ children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; } = ...

model.children?

string[] = ContentSchema

model.flavour

string = FlavourSchema

model.isFlatData?

boolean = ...

model.parent?

string[] = ParentSchema

model.props?

(...args) => Record<string, any> = ...

model.role

string = RoleSchema

model.toModel?

(...args) => BlockModel<object> = ...

transformer?

(...args) => BaseBlockTransformer<object> = ...

version

number = ...

Returns

void

Throws

If the relationship is invalid.