API View source
validateEvent()
Validates an event envelope and returns a branded validated value on success.
Signature
function validateEvent<T>(
event: EventEnvelope<T>,
options?: { maxClockDriftMs?: bigint; now?: () => bigint; includeWarnings?: boolean },
): ValidationResult<ValidatedEventEnvelope<T>>function validateEvent(
event: unknown,
options?: { maxClockDriftMs?: bigint; now?: () => bigint; includeWarnings?: boolean },
): ValidationResult<ValidatedEventEnvelope<unknown>>function validateEvent<T>(
event: unknown,
options?: { maxClockDriftMs?: bigint; now?: () => bigint; includeWarnings?: boolean },
): ValidationResult<ValidatedEventEnvelope<T>>Use this when you need to validate event-envelope input directly before ordering or other downstream processing.
Usage
import { validateEvent } from "causal-order"
const validation = validateEvent(event, {
includeWarnings: true,
})
if (!validation.valid) {
console.error(validation.errors)
} else {
console.log(validation.value)
console.log(validation.warnings)
} Details
valid: truereturns a brandedvalueplus any warnings.valid: falsereturns structurederrorsandwarnings.event.idmust be a non-empty string.event.nodeIdmust be a non-empty string.event.clockmust pass HLC validation.event.sequence, when present, must be a non-negativebigint.