Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

941 B
Raw Blame
import { BatchWritingGroupStore } from '~/ingestion/common/groups/batch-writing-group-store'
import { BatchBoundGroupStore, GroupStoreForBatch } from '~/ingestion/common/groups/group-store-for-batch'
import { BeforeBatchStep } from '~/ingestion/framework/batching-pipeline'
import { ok } from '~/ingestion/framework/results'

export interface GroupStoreBatchContext {
    groupStoreForBatch: GroupStoreForBatch
}

export function createGroupStoreBeforeBatchStep<TInput, CInput, CBatch>(
    groupStore: BatchWritingGroupStore
): BeforeBatchStep<TInput, CInput, CBatch, CBatch & GroupStoreBatchContext> {
    return function groupStoreBeforeBatchStep(input) {
        const groupStoreForBatch: GroupStoreForBatch = new BatchBoundGroupStore(groupStore, input.batchContext.batchId)
        const batchContext = { ...input.batchContext, groupStoreForBatch }
        return Promise.resolve(ok({ elements: input.elements, batchContext }))
    }
}