Skip to content

Required validation does not work for map fields of the initial state #47

@Host32

Description

@Host32

Hi Guys, I have the following schema:

export const TAG_SCHEMA = schema({
    data: schema.LoroMap({
        name: schema.String({required: true}),
        description: schema.String(),
    }),
});

If I do:

const doc = new LoroDoc()
doc.getMap('data').set('name', null)

const tag = new Mirror({
    doc,
    schema: TAG_SCHEMA,
    checkStateConsistency: true
})
tag.checkStateConsistency() // no error is thrown here

The same for:

const doc = new LoroDoc()

const tag = new Mirror({
    doc,
    schema: TAG_SCHEMA,
    checkStateConsistency: true,
    initialState: {data: {name: null, description: null}}
})
tag.checkStateConsistency() // no error is thrown here

It seems that validation only happens in the setState() method, am I doing something wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions