Saxonberg Server API
    Preparing search index...

    Type Alias CommandValidator<T>

    CommandValidator: (context: CommandContext, preloaded: T) => string | undefined & {
        preload?: (context: CommandContext) => Promise<T>;
    }

    Verb-level validator function type.

    Verb-level validators fire BEFORE field-level validators with context.commandGiver populated. They guard command-shape preconditions that don't tie to a specific arg — animacy, mobility, vocal capacity. Returns undefined when the precondition holds, or an error message string when it doesn't.

    Sync by design — the validator phase runs inside CommandApi.runValidators (sync). Validators whose sync body needs async work declare a preload hook; the dispatcher walks all validators-for-this-command between MQL resolution and the sync validator phase, awaits each preload, and passes each resolved value back to the validator's sync body as its second argument (preloaded).

    The T type parameter is the preload's return type. For preloads that only warm a singleton cache (the original use-case), use T = void and ignore the extra arg. For preloads whose result is the actual decision (e.g., the access checks — AccessApi.can is async; the sync body needs the boolean), declare T = boolean and read the result from preloaded.

    Type Parameters

    • T = void