JSON0 operational transformation for MoonBit
{"tasks":[{"title":"A"},{"title":"B"}]}[
[{"p":["tasks",0],"lm":1}],
[{"p":["tasks",1,"title",1],"si":"!"}]
]moon run examples/board --target js| 看板案例 | 可以观察到的转换规则 |
|---|---|
| 移动卡片时另一端修改标题 | 编辑路径随原卡片移动 |
| 两端都在列表头部新增卡片 | 同位置插入时左侧在前,右侧下标后移 |
| 两端同时重分配负责人 | 左侧替换获胜,并把右侧负责人记录为被替换值 |
| 删除卡片时另一端调整工分 | 删除载荷保留更新后的工分,撤销删除能恢复修改过的卡片 |
| 删除标题片段时另一端在 emoji 后插入 | text0 按 UTF-16 偏移拆分删除,保留并发插入 |
let board = @opgrain.parse_json("{\"tasks\":[\"Review\"]}")
let op = @opgrain.Operation::parse("[{\"p\":[\"tasks\",1],\"li\":\"Publish\"}]")
let next = @opgrain.apply(board, op)
println(@opgrain.stringify_json(next))moon add sbqrre/opgrain@0.2.0npm --prefix test/oracle ci --ignore-scripts
npm --prefix test/oracle test
npm --prefix test/oracle run fixtures -- --check
npm --prefix test/oracle run live
npm --prefix test/oracle run extended
npm --prefix test/oracle run package-smoke
moon test --frozen --deny-warn --target native
moon test --frozen --deny-warn --target js
moon test --frozen --deny-warn --target wasm
moon test --frozen --deny-warn --target wasm-gcpub(all) suberror HistoryError {
InvalidHistorySnapshot(OpError)
HistoryBusy
RevisionOverflow
HistoryEncodingFailed(Side, Int, OpError)
HistoryTransformFailed(Int, Int, OpError)
HistoryApplyFailed(HistoryPhase, Side, Int, VerificationError)
DivergentHistory(Json?, Json?)
InvalidRevisionRange(Int, Int, Int)
HistoryInvertFailed(Int, OpError)
HistoryUndoFailed(Int, VerificationError)
HistoryUndoMismatch(Json?, Json?)
} derive(Debug)pub(all) suberror OpError {
InvalidJson(String)
InvalidComponent(Int, String)
InvalidPath(Array[PathSegment], String)
UnknownSubtype(String)
SubtypeError(String, String)
TextMismatch(Int)
NonFiniteNumber
MissingRoot
DraftBusy
} derive(Debug)pub(all) suberror TrackingError {
InvalidLocation(Int, Array[PathSegment], OpError)
TrackingSnapshotFailed(OpError)
TrackingApplyFailed(Int, VerificationError)
} derive(Debug)pub(all) suberror UndoError {
ForwardRejected(VerificationError)
InverseRejected(Int, OpError)
UndoRejected(VerificationError)
UndoDidNotRestore(Json?, Json?)
} derive(Debug)pub(all) suberror VerificationError {
InvalidSnapshot(OpError)
ComponentFailed(Int, Array[PathSegment], OpError)
StalePreimage(Int, Array[PathSegment], Json?, Json?)
} derive(Debug)pub struct Component {
// private fields
}pub(all) struct DiffOptions {
text_encoding : TextEncoding
alignment_cells : Int
list_identity_key : String?
prefer_number_add : Bool
}pub struct Draft {
// private fields
}fn Draft::add_number(self : Draft, path : Array[PathSegment], amount : Double) -> Unit raise OpErrorfn Draft::move_item(self : Draft, path : Array[PathSegment], destination : Int) -> Unit raise OpErrorfn Draft::splice_text(self : Draft, path : Array[PathSegment], position : Int, delete_count : Int, inserted : String, encoding? : TextEncoding) -> Unit raise OpErrorpub struct Engine {
// private fields
}fn Engine::apply_tracked(self : Engine, snapshot : Json?, operation : Operation, locations : Array[Location]) -> TrackedApply raise TrackingErrorfn Engine::apply_tracked_batches(self : Engine, snapshot : Json?, operations : Array[Operation], locations : Array[Location]) -> TrackedApply raise TrackingErrorfn Engine::merge_histories(self : Engine, base : Json?, left : Array[Operation], right : Array[Operation], text_encoding? : TextEncoding?) -> HistoryMerge raise HistoryErrorfn Engine::merge_snapshot_histories(self : Engine, base : Snapshot, left : Array[Operation], right : Array[Operation], text_encoding? : TextEncoding?) -> HistoryMerge raise HistoryErrorfn Engine::transform_histories(self : Engine, left : Array[Operation], right : Array[Operation]) -> TransformedHistories raise HistoryErrorpub struct HistoryMerge {
// private fields
}pub struct Journal {
// private fields
}fn Journal::integrate(self : Journal, base : Int, incoming : Array[Operation], text_encoding? : TextEncoding?) -> Int raise HistoryErrorfn Journal::operations(self : Journal, start : Int, end : Int) -> Array[Operation] raise HistoryErrorfn Journal::revert(self : Journal, start : Int, end : Int, text_encoding? : TextEncoding?) -> Int raise HistoryErrorpub(all) enum Location {
Node(Array[PathSegment])
Cursor(Array[PathSegment], TextPosition)
TextRange(Array[PathSegment], TextPosition, TextPosition)
} derive(Eq, Debug)pub struct Operation {
// private fields
}pub struct Snapshot {
// private fields
}pub struct TrackedApply {
// private fields
}pub struct TransformedHistories {
// private fields
}pub struct UndoableEdit {
// private fields
}