Comparing version 1.0.4 to 1.0.5
@@ -28,2 +28,3 @@ "use strict"; | ||
record(op) { | ||
console.log("RECORD: ", op); | ||
if (!this.send) { | ||
@@ -77,2 +78,3 @@ throw new Error("OT client must have a send function"); | ||
recv(op) { | ||
console.log("RECV: ", op); | ||
try { | ||
@@ -79,0 +81,0 @@ if (this.wait) { |
import { EditOps } from "./textDoc"; | ||
export interface Op { | ||
type: string; | ||
} | ||
export interface FileCreate { | ||
file: string; | ||
} | ||
export interface FileDelete { | ||
file: string; | ||
} | ||
export interface FileTruncate { | ||
file: string; | ||
} | ||
export interface FileCopy { | ||
src: string; | ||
dst: string; | ||
} | ||
export interface FileRename { | ||
src: string; | ||
dst: string; | ||
} | ||
export interface FileEdit { | ||
file: string; | ||
edits: EditOps; | ||
} | ||
export interface GitHead { | ||
commit: string; | ||
} | ||
export declare type Ops = Op[]; | ||
export declare function toNewOps(op: WorkspaceOp): Ops; | ||
export declare function toLegacyOp(ops: Ops): WorkspaceOp; | ||
export interface WorkspaceOp { | ||
@@ -3,0 +33,0 @@ save?: string[]; |
@@ -6,2 +6,109 @@ "use strict"; | ||
const stringify_1 = require("../util/stringify"); | ||
function toNewOps(op) { | ||
let ops = []; | ||
if (op.copy) { | ||
for (let f of Object.keys(op.copy)) { | ||
ops.push({ type: "copy", src: op.copy[f], dst: f }); | ||
} | ||
} | ||
if (op.rename) { | ||
for (let f of Object.keys(op.rename)) { | ||
ops.push({ type: "rename", src: op.rename[f], dst: f }); | ||
} | ||
} | ||
if (op.create) { | ||
for (let f of op.create) { | ||
ops.push({ type: "create", file: f }); | ||
} | ||
} | ||
if (op.delete) { | ||
for (let f of op.delete) { | ||
ops.push({ type: "delete", file: f }); | ||
} | ||
} | ||
if (op.truncate) { | ||
for (let f of op.truncate) { | ||
ops.push({ type: "truncate", file: f }); | ||
} | ||
} | ||
if (op.edit) { | ||
for (let f of Object.keys(op.edit)) { | ||
ops.push({ type: "edit", file: f, edits: op.edit[f] }); | ||
} | ||
} | ||
if (op.head) { | ||
ops.push({ type: "gitHead", commit: op.head }); | ||
} | ||
return ops; | ||
} | ||
exports.toNewOps = toNewOps; | ||
function toLegacyOp(ops) { | ||
let newOp = {}; | ||
for (let iop of ops) { | ||
switch (iop.type) { | ||
case "create": | ||
{ | ||
let op = iop; | ||
if (!newOp.create) { | ||
newOp.create = []; | ||
} | ||
newOp.create.push(op.file); | ||
} | ||
break; | ||
case "delete": | ||
{ | ||
let op = iop; | ||
if (!newOp.delete) { | ||
newOp.delete = []; | ||
} | ||
newOp.delete.push(op.file); | ||
} | ||
break; | ||
case "truncate": | ||
{ | ||
let op = iop; | ||
if (!newOp.truncate) { | ||
newOp.truncate = []; | ||
} | ||
newOp.truncate.push(op.file); | ||
} | ||
break; | ||
case "copy": | ||
{ | ||
let op = iop; | ||
if (!newOp.copy) { | ||
newOp.copy = {}; | ||
} | ||
newOp.copy[op.dst] = op.src; | ||
} | ||
break; | ||
case "rename": | ||
{ | ||
let op = iop; | ||
if (!newOp.rename) { | ||
newOp.rename = {}; | ||
} | ||
newOp.rename[op.src] = op.dst; | ||
} | ||
break; | ||
case "edit": | ||
{ | ||
let op = iop; | ||
if (!newOp.edit) { | ||
newOp.edit = {}; | ||
} | ||
newOp.edit[op.file] = op.edits; | ||
} | ||
break; | ||
case "gitHead": | ||
{ | ||
let op = iop; | ||
newOp.head = op.commit; | ||
} | ||
break; | ||
} | ||
} | ||
return newOp; | ||
} | ||
exports.toLegacyOp = toLegacyOp; | ||
function toString(op, maxLengthPerItem = 50) { | ||
@@ -8,0 +115,0 @@ if (!op) { |
@@ -215,3 +215,3 @@ "use strict"; | ||
repo: "a", ref: "b", | ||
op: { create: ["/f"] }, | ||
ops: [{ type: "create", file: "/f" }], | ||
}; | ||
@@ -233,3 +233,5 @@ yield handler.afterRefUpdate(ref, params); | ||
repo: "a", ref: "b", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { | ||
data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] }, | ||
}, | ||
}; | ||
@@ -246,3 +248,3 @@ yield handler.afterRefUpdate(ref, params); | ||
name: "b", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] } }, | ||
}; | ||
@@ -273,3 +275,3 @@ const params = { | ||
repo: "a", ref: "b", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] } }, | ||
}; | ||
@@ -288,3 +290,3 @@ yield handler.afterRefUpdate(ref, params); | ||
repo: "a", ref: "b2", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] } }, | ||
}; | ||
@@ -291,0 +293,0 @@ yield handler.afterRefUpdate(ref, params); |
@@ -12,2 +12,3 @@ "use strict"; | ||
const vscode_jsonrpc_1 = require("vscode-jsonrpc"); | ||
const workspace_1 = require("../ot/workspace"); | ||
const protocol_1 = require("./protocol"); | ||
@@ -208,3 +209,3 @@ const ref_1 = require("../ref"); | ||
current: protocol_1.refPointerFrom(ref.state), | ||
op, | ||
ops: workspace_1.toNewOps(op), | ||
}); | ||
@@ -244,7 +245,7 @@ } | ||
if (resetToHistory) { | ||
return this.workspace.reset(resetToHistory); | ||
return this.workspace.reset(resetToHistory.map(workspace_1.toLegacyOp)); | ||
} | ||
} | ||
else if (params.op) { | ||
return this.workspace.apply(params.op); | ||
else if (params.ops) { | ||
return this.workspace.apply(workspace_1.toLegacyOp(params.ops)); | ||
} | ||
@@ -251,0 +252,0 @@ else if (params.delete) { |
import { NotificationType, NotificationType0, RequestType, RequestType0 } from "vscode-jsonrpc"; | ||
import { WorkspaceOp } from "../ot/workspace"; | ||
import { Ops } from "../ot/workspace"; | ||
import { BranchName } from "../ref"; | ||
@@ -130,3 +130,3 @@ export declare enum ErrorCode { | ||
export interface RefData extends RefBase { | ||
history: WorkspaceOp[]; | ||
history: Ops[]; | ||
} | ||
@@ -175,3 +175,3 @@ export interface RefInfo extends RefIdentifier, RefState { | ||
state?: RefState; | ||
op?: WorkspaceOp; | ||
ops?: Ops; | ||
ack?: boolean; | ||
@@ -189,3 +189,3 @@ delete?: boolean; | ||
state?: RefState; | ||
op?: WorkspaceOp; | ||
ops?: Ops; | ||
rev?: number; | ||
@@ -192,0 +192,0 @@ delete?: boolean; |
@@ -21,3 +21,3 @@ "use strict"; | ||
ref.upstream.rev = 1; | ||
ref.state = { data: { gitBase: "", gitBranch: "", history: [{ create: ["/f1"] }] } }; | ||
ref.state = { data: { gitBase: "", gitBranch: "", history: [[{ type: "create", file: "/f1" }]] } }; | ||
repo.refdb.write(ref.name, ref); | ||
@@ -27,3 +27,3 @@ refState_1.update(repo, ref, { | ||
repo: "a", ref: "b", | ||
op: { create: ["/f2"] }, | ||
ops: [{ type: "create", file: "/f2" }], | ||
}); | ||
@@ -30,0 +30,0 @@ assert.deepEqual(sent, [{ repo: "oa", ref: "b", op: { create: ["/f2"] }, rev: 1 }]); |
import { RefIdentifier, RefState, RefPointer, RefUpdateUpstreamParams, RefUpdateDownstreamParams } from "./protocol"; | ||
import { WorkspaceOp } from "../ot/workspace"; | ||
import { Ops } from "../ot/workspace"; | ||
import { RefDB, Ref, NewRef } from "../ref"; | ||
@@ -14,3 +14,3 @@ export declare enum Source { | ||
state?: RefState; | ||
op?: WorkspaceOp; | ||
ops?: Ops; | ||
rev?: number; | ||
@@ -17,0 +17,0 @@ ack?: boolean; |
@@ -11,3 +11,3 @@ "use strict"; | ||
function noop(params) { | ||
return !params.state && !params.op && !params.delete; | ||
return !params.state && !params.ops && !params.delete; | ||
} | ||
@@ -22,3 +22,3 @@ function fromUpdateUpstream(o) { | ||
state: o.state, | ||
op: o.op, | ||
ops: o.ops, | ||
rev: o.rev, | ||
@@ -35,3 +35,3 @@ delete: o.delete, | ||
state: o.state, | ||
op: o.op, | ||
ops: o.ops, | ||
ack: o.ack, | ||
@@ -49,3 +49,3 @@ delete: o.delete, | ||
state: o.state, | ||
op: o.op, | ||
ops: o.ops, | ||
rev: o.rev, | ||
@@ -117,3 +117,3 @@ delete: o.delete, | ||
} | ||
else if (params.op) { | ||
else if (params.ops) { | ||
if (!ref.state) { | ||
@@ -142,3 +142,3 @@ throw new Error(`ref update ${ref.name}: ref does not yet exist and update does not create it`); | ||
if (!noop(params)) { | ||
data.history.push(params.op); | ||
data.history.push(params.ops); | ||
} | ||
@@ -145,0 +145,0 @@ } |
@@ -13,3 +13,3 @@ "use strict"; | ||
repo: "a", ref: "b", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] } }, | ||
}); | ||
@@ -16,0 +16,0 @@ assert.deepEqual(state(u), { wait: null, buf: null, rev: 1 }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const workspace_1 = require("../ot/workspace"); | ||
function compose(a, b) { | ||
return a.concat(b); | ||
} | ||
class Upstream { | ||
@@ -14,3 +17,3 @@ constructor(sendToUpstream, remoteRepoPath) { | ||
params = deepCopy(params); | ||
if (params.op) { | ||
if (params.ops) { | ||
params.rev = 0; | ||
@@ -23,6 +26,6 @@ } | ||
else if (this.buf.state) { | ||
this.buf.state.data.history.push(params.op); | ||
this.buf.state.data.history.push(params.ops); | ||
} | ||
else if (this.buf.op) { | ||
this.buf.op = workspace_1.compose(this.buf.op, params.op); | ||
else if (this.buf.ops) { | ||
this.buf.ops = compose(this.buf.ops, params.ops); | ||
} | ||
@@ -38,3 +41,3 @@ else { | ||
this.wait = params; | ||
if (this.wait.op) { | ||
if (this.wait.ops) { | ||
this.wait.rev = this.rev; | ||
@@ -59,17 +62,17 @@ } | ||
} | ||
else if (params.op) { | ||
else if (params.ops) { | ||
if ((this.wait && this.wait.state) || (this.buf && this.buf.state)) { | ||
params.op = undefined; | ||
params.ops = undefined; | ||
return; | ||
} | ||
params.op = deepCopy(params.op); | ||
if (this.wait && this.wait.op) { | ||
const { a1, b1 } = workspace_1.transform(this.wait.op, params.op); | ||
this.wait.op = a1; | ||
params.op = b1; | ||
params.ops = deepCopy(params.ops); | ||
if (this.wait && this.wait.ops) { | ||
const { a1, b1 } = workspace_1.transform(workspace_1.toLegacyOp(this.wait.ops), workspace_1.toLegacyOp(params.ops)); | ||
this.wait.ops = workspace_1.toNewOps(a1); | ||
params.ops = workspace_1.toNewOps(b1); | ||
} | ||
if (this.buf && this.buf.op) { | ||
const { a1, b1 } = workspace_1.transform(this.buf.op, params.op); | ||
this.buf.op = a1; | ||
params.op = b1; | ||
if (this.buf && this.buf.ops) { | ||
const { a1, b1 } = workspace_1.transform(workspace_1.toLegacyOp(this.buf.ops), workspace_1.toLegacyOp(params.ops)); | ||
this.buf.ops = workspace_1.toNewOps(a1); | ||
params.ops = workspace_1.toNewOps(b1); | ||
} | ||
@@ -91,3 +94,3 @@ this.rev++; | ||
} | ||
else if (this.wait.op) { | ||
else if (this.wait.ops) { | ||
this.rev++; | ||
@@ -100,3 +103,3 @@ } | ||
this.wait = this.buf; | ||
if (this.wait.op) { | ||
if (this.wait.ops) { | ||
this.wait.rev = this.rev; | ||
@@ -103,0 +106,0 @@ } |
{ | ||
"name": "libzap", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "JavaScript library for Zap", | ||
@@ -5,0 +5,0 @@ "license": "none", |
@@ -34,2 +34,3 @@ import { WorkspaceOp, compose, noop, transform, toString as opToString } from "./workspace"; | ||
public record(op: WorkspaceOp) { | ||
console.log("RECORD: ", op); | ||
if (!this.send) { | ||
@@ -86,5 +87,6 @@ throw new Error("OT client must have a send function"); | ||
public recv(op: WorkspaceOp): Promise<void> { | ||
console.log("RECV: ", op); | ||
try { | ||
if (this.wait) { | ||
const {a1, b1} = transform(this.wait, op); | ||
const { a1, b1 } = transform(this.wait, op); | ||
this.wait = a1; | ||
@@ -94,3 +96,3 @@ op = b1; | ||
if (this.buf) { | ||
const {a1, b1} = transform(this.buf, op); | ||
const { a1, b1 } = transform(this.buf, op); | ||
this.buf = a1; | ||
@@ -97,0 +99,0 @@ op = b1; |
@@ -6,2 +6,139 @@ import { cloneDeep, includes, invert, invertBy, uniq, values, without } from "lodash"; | ||
export interface Op { | ||
type: string; | ||
} | ||
// TODO(renfred): make these classes to make the instantiation of indivitual ops cleaner/safer. | ||
export interface FileCreate { | ||
file: string; | ||
} | ||
export interface FileDelete { | ||
file: string; | ||
} | ||
export interface FileTruncate { | ||
file: string; | ||
} | ||
export interface FileCopy { | ||
src: string; | ||
dst: string; | ||
} | ||
export interface FileRename { | ||
src: string; | ||
dst: string; | ||
} | ||
export interface FileEdit { | ||
file: string; | ||
edits: EditOps; | ||
} | ||
export interface GitHead { | ||
commit: string; | ||
} | ||
export type Ops = Op[]; | ||
export function toNewOps(op: WorkspaceOp): Ops { | ||
let ops = []; | ||
if (op.copy) { | ||
for (let f of Object.keys(op.copy)) { | ||
ops.push({ type: "copy", src: op.copy[f], dst: f } as Op); | ||
} | ||
} | ||
if (op.rename) { | ||
for (let f of Object.keys(op.rename)) { | ||
ops.push({ type: "rename", src: op.rename[f], dst: f } as Op); | ||
} | ||
} | ||
if (op.create) { | ||
for (let f of op.create) { | ||
ops.push({ type: "create", file: f } as Op); | ||
} | ||
} | ||
if (op.delete) { | ||
for (let f of op.delete) { | ||
ops.push({ type: "delete", file: f } as Op); | ||
} | ||
} | ||
if (op.truncate) { | ||
for (let f of op.truncate) { | ||
ops.push({ type: "truncate", file: f } as Op); | ||
} | ||
} | ||
if (op.edit) { | ||
for (let f of Object.keys(op.edit)) { | ||
ops.push({ type: "edit", file: f, edits: op.edit[f] } as Op); | ||
} | ||
} | ||
if (op.head) { | ||
ops.push({ type: "gitHead", commit: op.head } as Op); | ||
} | ||
return ops; | ||
} | ||
export function toLegacyOp(ops: Ops): WorkspaceOp { | ||
let newOp: WorkspaceOp = {}; | ||
for (let iop of ops) { | ||
switch (iop.type) { | ||
case "create": | ||
{ | ||
let op = iop as any as FileCreate; | ||
if (!newOp.create) { newOp.create = []; } | ||
newOp.create.push(op.file); | ||
} | ||
break; | ||
case "delete": | ||
{ | ||
let op = iop as any as FileTruncate; | ||
if (!newOp.delete) { newOp.delete = []; } | ||
newOp.delete.push(op.file); | ||
} | ||
break; | ||
case "truncate": | ||
{ | ||
let op = iop as any as FileTruncate; | ||
if (!newOp.truncate) { newOp.truncate = []; } | ||
newOp.truncate.push(op.file); | ||
} | ||
break; | ||
case "copy": | ||
{ | ||
let op = iop as any as FileCopy; | ||
if (!newOp.copy) { newOp.copy = {}; } | ||
newOp.copy[op.dst] = op.src; | ||
} | ||
break; | ||
case "rename": | ||
{ | ||
let op = iop as any as FileCopy; | ||
if (!newOp.rename) { newOp.rename = {}; } | ||
newOp.rename[op.src] = op.dst; | ||
} | ||
break; | ||
case "edit": | ||
{ | ||
let op = iop as any as FileEdit; | ||
if (!newOp.edit) { newOp.edit = {}; } | ||
newOp.edit[op.file] = op.edits; | ||
} | ||
break; | ||
case "gitHead": | ||
{ | ||
let op = iop as any as GitHead; | ||
newOp.head = op.commit; | ||
} | ||
break; | ||
} | ||
} | ||
return newOp; | ||
} | ||
/* | ||
* ========= DEPRECATED: ========= | ||
*/ | ||
export interface WorkspaceOp { | ||
@@ -517,3 +654,3 @@ save?: string[]; | ||
if (op.create && includes(op.create, f)) { | ||
const {ret: ret} = countEdits(op.edit[f]); | ||
const { ret: ret } = countEdits(op.edit[f]); | ||
if (ret !== 0) { | ||
@@ -634,3 +771,3 @@ throw new Error(`newly created file has nonzero retain count ${f}`); | ||
} | ||
const {a1: x1, b1: y1} = transformEdits(edit1, edit2); | ||
const { a1: x1, b1: y1 } = transformEdits(edit1, edit2); | ||
if (primary) { | ||
@@ -637,0 +774,0 @@ return x1; |
@@ -8,3 +8,3 @@ import * as assert from "assert"; | ||
import { Ref } from "../ref"; | ||
import { WorkspaceOp } from "../ot/workspace"; | ||
import { WorkspaceOp, Op } from "../ot/workspace"; | ||
import { Workspace } from "../workspace"; | ||
@@ -250,3 +250,3 @@ | ||
repo: "a", ref: "b", | ||
op: { create: ["/f"] }, | ||
ops: [{ type: "create", file: "/f" } as Op], | ||
}; | ||
@@ -271,3 +271,5 @@ await handler.afterRefUpdate(ref, params); | ||
repo: "a", ref: "b", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { | ||
data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] }, | ||
}, | ||
}; | ||
@@ -287,3 +289,3 @@ await handler.afterRefUpdate(ref, params); | ||
name: "b", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] } }, | ||
}; | ||
@@ -317,3 +319,3 @@ const params: RefUpdate = { | ||
repo: "a", ref: "b", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] } }, | ||
}; | ||
@@ -336,3 +338,3 @@ await handler.afterRefUpdate(ref, params); | ||
repo: "a", ref: "b2", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] } }, | ||
}; | ||
@@ -339,0 +341,0 @@ await handler.afterRefUpdate(ref, params); |
import { RequestType, Emitter, Event } from "vscode-jsonrpc"; | ||
import { WorkspaceOp } from "../ot/workspace"; | ||
import { WorkspaceOp, toNewOps, toLegacyOp } from "../ot/workspace"; | ||
import { IConnection } from "./connection"; | ||
@@ -311,3 +311,3 @@ import { RefUpdateUpstreamRequest, RefUpdateUpstreamParams, RefUpdateDownstreamRequest, RefUpdateDownstreamParams, RepoWatchParams, RepoWatchRequest, WorkspaceWillSaveFileParams, WorkspaceWillSaveFileRequest, WorkspaceBranchCreateRequest, WorkspaceStatusRequest, WorkspaceBranchSetResult, WorkspaceBranchCreateParams, WorkspaceBranchSetRequest, WorkspaceBranchSetParams, WorkspaceAddRequest, WorkspaceAddParams, WorkspaceRemoveRequest, WorkspaceRemoveParams, WorkspaceBranchCreateResult, WorkspaceBranchCloseRequest, WorkspaceBranchCloseParams, refPointerFrom } from "./protocol"; | ||
current: refPointerFrom(ref.state), | ||
op, | ||
ops: toNewOps(op), | ||
}); | ||
@@ -363,6 +363,6 @@ } | ||
if (resetToHistory) { | ||
return this.workspace.reset(resetToHistory); | ||
return this.workspace.reset(resetToHistory.map(toLegacyOp)); | ||
} | ||
} else if (params.op) { | ||
return this.workspace.apply(params.op); | ||
} else if (params.ops) { | ||
return this.workspace.apply(toLegacyOp(params.ops)); | ||
} else if (params.delete) { | ||
@@ -369,0 +369,0 @@ if (workRef.name === ref.name) { |
import { NotificationType, NotificationType0, RequestType, RequestType0 } from "vscode-jsonrpc"; | ||
import { WorkspaceOp } from "../ot/workspace"; | ||
import { Ops } from "../ot/workspace"; | ||
import { BranchName } from "../ref"; | ||
@@ -318,3 +318,3 @@ | ||
export interface RefData extends RefBase { | ||
history: WorkspaceOp[]; | ||
history: Ops[]; | ||
} | ||
@@ -373,3 +373,3 @@ | ||
state?: RefState; | ||
op?: WorkspaceOp; | ||
ops?: Ops; | ||
ack?: boolean; | ||
@@ -389,3 +389,3 @@ delete?: boolean; | ||
state?: RefState; | ||
op?: WorkspaceOp; | ||
ops?: Ops; | ||
rev?: number; | ||
@@ -392,0 +392,0 @@ delete?: boolean; |
@@ -7,2 +7,3 @@ import * as assert from "assert"; | ||
import { RefUpdateUpstreamParams } from "./protocol"; | ||
import { Op } from "../ot/workspace"; | ||
import { Ref, RefDB } from "../ref"; | ||
@@ -25,3 +26,3 @@ | ||
ref.upstream.rev = 1; | ||
ref.state = { data: { gitBase: "", gitBranch: "", history: [{ create: ["/f1"] }] } }; | ||
ref.state = { data: { gitBase: "", gitBranch: "", history: [[{ type: "create", file: "/f1" } as Op]] } }; | ||
repo.refdb.write(ref.name, ref as Ref); | ||
@@ -32,3 +33,3 @@ | ||
repo: "a", ref: "b", | ||
op: { create: ["/f2"] }, | ||
ops: [{ type: "create", file: "/f2" } as Op], | ||
}); | ||
@@ -67,2 +68,2 @@ | ||
return ref; | ||
} | ||
} |
import { RefIdentifier, RefState, RefPointer, RefUpdateUpstreamParams, RefUpdateDownstreamParams } from "./protocol"; | ||
import { WorkspaceOp } from "../ot/workspace"; | ||
import { Ops } from "../ot/workspace"; | ||
import { Upstream } from "./upstream"; | ||
@@ -17,3 +17,3 @@ import { RefDB, Ref, NewRef } from "../ref"; | ||
state?: RefState; | ||
op?: WorkspaceOp; | ||
ops?: Ops; | ||
rev?: number; | ||
@@ -25,3 +25,3 @@ ack?: boolean; | ||
function noop(params: RefUpdate): boolean { | ||
return !params.state && !params.op && !params.delete; | ||
return !params.state && !params.ops && !params.delete; | ||
} | ||
@@ -37,3 +37,3 @@ | ||
state: o.state, | ||
op: o.op, | ||
ops: o.ops, | ||
rev: o.rev, | ||
@@ -50,3 +50,3 @@ delete: o.delete, | ||
state: o.state, | ||
op: o.op, | ||
ops: o.ops, | ||
ack: o.ack, | ||
@@ -64,3 +64,3 @@ delete: o.delete, | ||
state: o.state, | ||
op: o.op, | ||
ops: o.ops, | ||
rev: o.rev, | ||
@@ -147,3 +147,3 @@ delete: o.delete, | ||
} | ||
} else if (params.op) { | ||
} else if (params.ops) { | ||
if (!ref.state) { | ||
@@ -175,3 +175,3 @@ throw new Error(`ref update ${ref.name}: ref does not yet exist and update does not create it`); | ||
if (!noop(params)) { | ||
data.history.push(params.op); | ||
data.history.push(params.ops); | ||
} | ||
@@ -191,2 +191,2 @@ } | ||
return JSON.parse(JSON.stringify(o)); | ||
} | ||
} |
@@ -6,2 +6,3 @@ import * as assert from "assert"; | ||
import { RefUpdateUpstreamParams } from "./protocol"; | ||
import { Op } from "../ot/workspace"; | ||
@@ -19,3 +20,3 @@ describe("Upstream", () => { | ||
repo: "a", ref: "b", | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } }, | ||
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] } }, | ||
}); | ||
@@ -33,2 +34,2 @@ | ||
return { wait: u.wait, buf: u.buf, rev: u.rev }; | ||
} | ||
} |
import { RefUpdate } from "./refState"; | ||
import { compose, transform } from "../ot/workspace"; | ||
import { transform, Ops, toLegacyOp, toNewOps } from "../ot/workspace"; | ||
import { RefUpdateUpstreamParams } from "./protocol"; | ||
// TODO(renfred): implement compose | ||
function compose(a: Ops, b: Ops): Ops { | ||
return a.concat(b); | ||
} | ||
export class Upstream { | ||
@@ -25,3 +30,3 @@ /** | ||
params = deepCopy(params); | ||
if (params.op) { | ||
if (params.ops) { | ||
params.rev = 0; | ||
@@ -33,5 +38,5 @@ } | ||
} else if (this.buf.state) { | ||
this.buf.state.data!.history.push(params.op!); | ||
} else if (this.buf.op) { | ||
this.buf.op = compose(this.buf.op, params.op!); | ||
this.buf.state.data!.history.push(params.ops!); | ||
} else if (this.buf.ops) { | ||
this.buf.ops = compose(this.buf.ops, params.ops!); | ||
} else { | ||
@@ -44,3 +49,3 @@ throw new Error(`unable to append/compose op to RefUpdateUpstreamParams with !state and !op`); | ||
this.wait = params; | ||
if (this.wait.op) { | ||
if (this.wait.ops) { | ||
this.wait.rev = this.rev; | ||
@@ -65,18 +70,20 @@ } | ||
} | ||
} else if (params.op) { | ||
} else if (params.ops) { | ||
if ((this.wait && this.wait.state) || (this.buf && this.buf.state)) { | ||
params.op = undefined; | ||
params.ops = undefined; | ||
return; | ||
} | ||
params.op = deepCopy(params.op); | ||
if (this.wait && this.wait.op) { | ||
const { a1, b1 } = transform(this.wait.op, params.op); | ||
this.wait.op = a1; | ||
params.op = b1; | ||
params.ops = deepCopy(params.ops); | ||
if (this.wait && this.wait.ops) { | ||
// TODO(renfred): implement transform | ||
const { a1, b1 } = transform(toLegacyOp(this.wait.ops), toLegacyOp(params.ops)); | ||
this.wait.ops = toNewOps(a1); | ||
params.ops = toNewOps(b1); | ||
} | ||
if (this.buf && this.buf.op) { | ||
const { a1, b1 } = transform(this.buf.op, params.op); | ||
this.buf.op = a1; | ||
params.op = b1; | ||
if (this.buf && this.buf.ops) { | ||
// TODO(renfred): implement transform | ||
const { a1, b1 } = transform(toLegacyOp(this.buf.ops), toLegacyOp(params.ops)); | ||
this.buf.ops = toNewOps(a1); | ||
params.ops = toNewOps(b1); | ||
} | ||
@@ -101,3 +108,3 @@ this.rev++; | ||
} | ||
} else if (this.wait.op) { | ||
} else if (this.wait.ops) { | ||
this.rev++; | ||
@@ -110,3 +117,3 @@ } else { | ||
this.wait = this.buf; | ||
if (this.wait.op) { | ||
if (this.wait.ops) { | ||
this.wait.rev = this.rev; | ||
@@ -124,2 +131,2 @@ } | ||
return JSON.parse(JSON.stringify(o)); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
765708
21605
0