export function createCheckpointProvenance(checkpoint) {
    return {
        sessionId: checkpoint.sessionId,
        checkpoint: checkpoint.type,
        timestamp: checkpoint.timestamp,
        traceRefs: [...checkpoint.traceRefs]
    };
}
function provenanceKey(provenance) {
    return [
        provenance.sessionId,
        provenance.checkpoint,
        provenance.timestamp,
        provenance.traceRefs.join(',')
    ].join('|');
}
export function mergeProvenance(existing, next) {
    const merged = new Map();
    for (const item of [...existing, ...next]) {
        merged.set(provenanceKey(item), item);
    }
    return [...merged.values()];
}
export function attachCheckpointProvenance(topic, checkpoint) {
    const checkpointProvenance = createCheckpointProvenance(checkpoint);
    return {
        ...topic,
        entries: topic.entries.map((entry) => ({
            ...entry,
            provenance: entry.provenance.length === 0
                ? [checkpointProvenance]
                : mergeProvenance(entry.provenance, [])
        }))
    };
}
//# sourceMappingURL=provenance.js.map