Takingtypeno test imports ittype Taking = { readonly versions: number; readonly blobs: number; readonly bytes: number; readonly id: string | undefined };What one store takes in a merge.
The merge of two stores that both merge. It is a plan before it is anything else, as every transfer of the bridge is: the vectors of the two stores, the delta each takes from the other (the rows it lacks and the blobs they name) and the hash of all of it. Applying it takes the hash the plan had; where the stores have changed since, the plan is stale and nothing is applied. A merge has no conflict, so there is no policy to choose: what the plan says is what each store takes. The rails are a maximum of rows and of bytes, which refuse a plan that is too large to be taken at once.
import { applyMerge, planMerge } from "./mod.ts";
// const prepared = await planMerge(a, b, {}); if (prepared.kind === "ok") await applyMerge(a, b, prepared.value, { approved: prepared.value.plan.hash });Takingtypeno test imports ittype Taking = { readonly versions: number; readonly blobs: number; readonly bytes: number; readonly id: string | undefined };What one store takes in a merge.
MergeRailstypeno test imports ittype MergeRails = { readonly maxVersions?: number; readonly maxBytes?: number };The rails of a merge: the most rows and the most bytes of blobs one store may take at once.
MergePlantypeno test imports ittype MergePlan = { readonly a: VersionVector; readonly b: VersionVector; readonly toA: Taking; readonly toB: Taking; readonly hash: string };A merge as a plan: what each store holds and takes, and the hash of that.
PreparedMergetypeno test imports ittype PreparedMerge = { readonly plan: MergePlan; readonly toA: Delta | undefined; readonly toB: Delta | undefined };A plan with the deltas it was made from.
MergeProblemtypeno test imports ittype MergeProblem =
| { readonly kind: "store"; readonly which: "a" | "b"; readonly problem: Problem }
| { readonly kind: "rails"; readonly which: "a" | "b"; readonly detail: string }
| { readonly kind: "stale"; readonly planned: string; readonly now: string }
| { readonly kind: "unapproved"; readonly hash: string };Why a merge was not planned or applied.
describeMergeProblemfunctionfunction describeMergeProblem(p: MergeProblem): stringOne sentence for a problem.
planMergefunctionfunction planMerge(a: Mergeable, b: Mergeable, rails?: MergeRails): Promise<Result<PreparedMerge, MergeProblem>>The plan of a merge between two stores, and the deltas it is made of; nothing is changed.
MergeReporttypeno test imports ittype MergeReport = { readonly toA: MergeOutcome | undefined; readonly toB: MergeOutcome | undefined; readonly vectorsEqual: boolean };What a merge did: what each store said of the delta it took.
applyMergefunctionfunction applyMerge(a: Mergeable, b: Mergeable, prepared: PreparedMerge, options: { readonly approved: string | undefined; readonly rails?: MergeRails | undefined; readonly signers?: readonly Signer[] | undefined; readonly trust?: { readonly a?: Trust | undefined; readonly b?: Trust | undefined; } | undefined; }): Promise<Result<MergeReport, MergeProblem>>Applies a merge: the plan is made again, and where its hash is not the one approved nothing is applied; otherwise each store takes its delta, whole or not at all, and a second merge of the same stores changes nothing.