1 import type { DecryptedMessage } from '@proton/docs-shared'
2 import { GetCommitDULimit } from '../Types/SquashingConstants'
3 import { mergeUpdates } from 'yjs'
5 export class DecryptedCommit {
6 public readonly byteSize: number
9 public commitId: string,
10 public updates: DecryptedMessage[],
12 this.byteSize = updates.reduce((acc, update) => acc + update.byteSize(), 0)
17 numberOfUpdates(): number {
18 return this.updates.length
21 needsSquash(): boolean {
22 return this.numberOfUpdates() > GetCommitDULimit()
25 squashedRepresentation(): Uint8Array {
27 const merged = mergeUpdates(this.updates.map((update) => update.content))
30 throw new Error(`Failed to merge updates: ${error}`)