API View source
translateBatch()
Translates raw user-space records into event envelopes and structured translation anomalies.
Signature
function translateBatch<TInput, TPayload = TInput>(
records: readonly TInput[],
config: TranslateBatchConfig<TInput, TPayload>,
): TranslateBatchResult<TPayload, TInput>This is the raw-record ingress entry point. It maps arbitrary user-space records into the event envelope, applies the published timestamp coercion rules, and separates accepted envelopes from structured translation anomalies.
Usage
import { orderEvents, translateBatch } from "causal-order"
const translated = translateBatch(records, {
getEventId: (record) => record.eventId,
getNodeId: (record) => record.source,
getPhysicalTime: (record) => record.occurredAt,
getSequence: (record) => record.sequence,
getParentEventId: (record) => record.parent,
getPayload: (record) => record.body,
})
const ordered = orderEvents(translated.translated, {
strict: false,
detectAnomalies: true,
})
console.log(translated.anomalies)
console.log(ordered.ordered) Details
translated: readonly translated event envelopes ready for ordering.anomalies: structured translation failures with field, mapper, stage, and actual-value metadata.getEventId,getNodeId, andgetPhysicalTimeare required mappers.- Timestamps accept
bigint, safe integernumber, and canonical integerstring. Date, ISO timestamp strings, decimals, exponent notation, and unsafe integers are rejected deterministically.- The returned envelope shell is shallowly frozen, while
payloadremains by reference.