Sanity Library Reference Docs
    Preparing search index...

    Interface ValidateDocumentOptionsBeta

    interface ValidateDocumentOptions {
        document: SanityDocument;
        environment?: "studio" | "cli";
        getClient?: (clientOptions: SourceClientOptions) => SanityClient;
        getDocumentExists?: (options: { id: string }) => Promise<boolean>;
        maxCustomValidationConcurrency?: number;
        maxFetchConcurrency?: number;
        workspace: Workspace;
    }
    Index

    Properties

    document: SanityDocument

    The document to be validated

    environment?: "studio" | "cli"

    Specify the environment name. This will be passed down to the ValidationContext and made available to custom validators.

    getClient?: (clientOptions: SourceClientOptions) => SanityClient

    The factory function used to get a sanity client used in custom validators. If not provided, the one from the workspace will be used (preferred).

    For internal use only

    getDocumentExists?: (options: { id: string }) => Promise<boolean>

    Function used to check if referenced documents exists (and is published).

    If you're validating many documents in bulk, you may want to query for all document IDs first and provide your own implementation using those.

    If no function is provided a default one will be provided that will batch call the doc endpoint to check for document existence.

    maxCustomValidationConcurrency?: number

    The maximum amount of custom validation functions to be running concurrently at once. This helps prevent custom validators from overwhelming backend services (e.g. called via fetch) used in async, user-defined validation functions. (i.e. rule.custom(async() => {}))

    Note that lowering this number may also help in cases where a custom validator could potentially exhaust the fetch concurrency. This is 5 by default.

    maxFetchConcurrency?: number

    The amount of allowed inflight fetch requests at once. You may need to up this value if you have complex custom validations that require many client.fetch requests at once. It's possible for custom validator to stall if there are not enough concurrent fetch requests available to fullfil the custom validation. This is 25 by default.

    workspace: Workspace

    The workspace instance (and associated schema) used to validate the given document against.