src/crdt-compaction-types.tsTypeScript
@@ -0,0 +1,65 @@
1+
export type VersionVector = Readonly<Record<string, number>>;2+
3+
export interface CrdtOperation {4+
actorId: string;5+
sequence: number;6+
kind: "insert" | "delete";7+
targetId: string;8+
value?: string;9+
}10+
11+
export interface CrdtSnapshot {12+
documentId: string;13+
frontier: VersionVector;14+
content: string;15+
tombstones: readonly string[];16+
}17+
18+
export interface ReplicaAcknowledgement {19+
replicaId: string;20+
frontier: VersionVector;21+
}22+
23+
export interface CompactionView {24+
head: VersionVector;25+
activeReplicaAcknowledgements: readonly ReplicaAcknowledgement[];26+
}27+
28+
export interface CompactionLease {29+
release(): Promise<void>;30+
}31+
32+
export interface CrdtCompactionStore {33+
acquireCompactionLease(documentId: string): Promise<CompactionLease>;34+
readCompactionView(35+
documentId: string,36+
lease: CompactionLease,37+
): Promise<CompactionView>;38+
currentHead(documentId: string): Promise<VersionVector>;39+
activeReplicaAcknowledgements(40+
documentId: string,41+
): Promise<readonly ReplicaAcknowledgement[]>;42+
loadSnapshot(documentId: string): Promise<CrdtSnapshot | null>;43+
listOperationsThrough(44+
documentId: string,45+
frontier: VersionVector,46+
): Promise<readonly CrdtOperation[]>;47+
saveSnapshot(snapshot: CrdtSnapshot): Promise<void>;48+
deleteOperationsThrough(49+
documentId: string,50+
frontier: VersionVector,51+
): Promise<void>;52+
commitCompaction(53+
snapshot: CrdtSnapshot,54+
frontier: VersionVector,55+
): Promise<void>;56+
resetActorSequences(documentId: string): Promise<void>;57+
}58+
59+
export interface CrdtMaterializer {60+
materialize(61+
base: CrdtSnapshot | null,62+
operations: readonly CrdtOperation[],63+
frontier: VersionVector,64+
): CrdtSnapshot;65+
}