Skip to content

Make validator serialization a first-class feature #112

@jdesrosiers

Description

@jdesrosiers

#111 adds serialize/deserialize functions for compiled schemas. This issue would make it easy to serialize and restore a validator without having to use the low-level experimental API. This is what I'm thinking,

const validator = await validate("https://example.com/main");
const result1 = validator(42, "BASIC");

const json = validator.serialize();

const restoredValidator = restoreValidator(json);
const result2 = restoredValidator(42, "BASIC");

Is it too weird to have a function with properties? This is an interesting option because it allows for the possibility of validating both at runtime and when restored later without having to compile twice.

The alternative is to just have a dedicated function that serializes directly without building a validator function.

const json = await serializedValidator("https://example.com/main");
const restoredValidator = restoreValidator(json);
const result = restoredValidator(42, "BASIC");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions