Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

libzap

Package Overview
Dependencies
Maintainers
8
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libzap - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

2

lib/ot/client.js

@@ -28,3 +28,2 @@ "use strict";

record(op) {
console.log("RECORD: ", op);
if (!this.send) {

@@ -78,3 +77,2 @@ throw new Error("OT client must have a send function");

recv(op) {
console.log("RECV: ", op);
try {

@@ -81,0 +79,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 {

@@ -33,0 +3,0 @@ save?: string[];

@@ -6,109 +6,2 @@ "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) {

@@ -115,0 +8,0 @@ if (!op) {

@@ -1,7 +0,3 @@

import { CancellationToken, Disposable, Event, GenericNotificationHandler, GenericRequestHandler, Logger, Message, MessageReader, MessageType as RPCMessageType, MessageWriter, NotificationHandler, NotificationHandler0, NotificationType, NotificationType0, RequestHandler, RequestHandler0, RequestType, RequestType0, ResponseError, Trace } from "vscode-jsonrpc";
import { CancellationToken, Disposable, Event, GenericNotificationHandler, GenericRequestHandler, Logger, Message, MessageReader, MessageType as RPCMessageType, MessageWriter, NotificationHandler, NotificationHandler0, NotificationType, NotificationType0, RequestHandler, RequestHandler0, RequestType, RequestType0, Trace } from "vscode-jsonrpc";
import { IConnection } from "./connection";
import { InitializeError } from "./protocol";
export interface InitializationFailedHandler {
(error: ResponseError<InitializeError> | Error | any): boolean;
}
export interface MessageStream {

@@ -19,3 +15,2 @@ reader: MessageReader;

initializationOptions?: any | (() => any);
initializationFailedHandler?: InitializationFailedHandler;
errorHandler?: ErrorHandler;

@@ -22,0 +17,0 @@ logger?: Logger;

@@ -248,12 +248,3 @@ "use strict";

}, (error) => {
if (this.clientOptions.initializationFailedHandler) {
if (this.clientOptions.initializationFailedHandler(error)) {
this.initialize(connection);
}
else {
this.stop();
this.readyPromiseCallbacks.reject(error);
}
}
else if (error instanceof vscode_jsonrpc_1.ResponseError && error.data && error.data.retry) {
if (error instanceof vscode_jsonrpc_1.ResponseError && error.data && error.data.retry) {
if (confirm("Retry?")) {

@@ -260,0 +251,0 @@ this.initialize(connection);

12

lib/remote/handler_test.js

@@ -215,3 +215,3 @@ "use strict";

repo: "a", ref: "b",
ops: [{ type: "create", file: "/f" }],
op: { create: ["/f"] },
};

@@ -233,5 +233,3 @@ yield handler.afterRefUpdate(ref, params);

repo: "a", ref: "b",
state: {
data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] },
},
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } },
};

@@ -248,3 +246,3 @@ yield handler.afterRefUpdate(ref, params);

name: "b",
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] } },
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } },
};

@@ -275,3 +273,3 @@ const params = {

repo: "a", ref: "b",
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] } },
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } },
};

@@ -290,3 +288,3 @@ yield handler.afterRefUpdate(ref, params);

repo: "a", ref: "b2",
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] } },
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } },
};

@@ -293,0 +291,0 @@ yield handler.afterRefUpdate(ref, params);

@@ -12,3 +12,2 @@ "use strict";

const vscode_jsonrpc_1 = require("vscode-jsonrpc");
const workspace_1 = require("../ot/workspace");
const protocol_1 = require("./protocol");

@@ -209,3 +208,3 @@ const ref_1 = require("../ref");

current: protocol_1.refPointerFrom(ref.state),
ops: workspace_1.toNewOps(op),
op,
});

@@ -245,7 +244,7 @@ }

if (resetToHistory) {
return this.workspace.reset(resetToHistory.map(workspace_1.toLegacyOp));
return this.workspace.reset(resetToHistory);
}
}
else if (params.ops) {
return this.workspace.apply(workspace_1.toLegacyOp(params.ops));
else if (params.op) {
return this.workspace.apply(params.op);
}

@@ -252,0 +251,0 @@ else if (params.delete) {

import { NotificationType, NotificationType0, RequestType, RequestType0 } from "vscode-jsonrpc";
import { Ops } from "../ot/workspace";
import { WorkspaceOp } from "../ot/workspace";
import { BranchName } from "../ref";

@@ -56,3 +56,2 @@ export declare enum ErrorCode {

export interface InitializeError {
retry: boolean;
}

@@ -131,3 +130,3 @@ export interface InitializedParams {

export interface RefData extends RefBase {
history: Ops[];
history: WorkspaceOp[];
}

@@ -176,3 +175,3 @@ export interface RefInfo extends RefIdentifier, RefState {

state?: RefState;
ops?: Ops;
op?: WorkspaceOp;
ack?: boolean;

@@ -190,3 +189,3 @@ delete?: boolean;

state?: RefState;
ops?: Ops;
op?: WorkspaceOp;
rev?: number;

@@ -193,0 +192,0 @@ delete?: boolean;

@@ -21,3 +21,3 @@ "use strict";

ref.upstream.rev = 1;
ref.state = { data: { gitBase: "", gitBranch: "", history: [[{ type: "create", file: "/f1" }]] } };
ref.state = { data: { gitBase: "", gitBranch: "", history: [{ create: ["/f1"] }] } };
repo.refdb.write(ref.name, ref);

@@ -27,3 +27,3 @@ refState_1.update(repo, ref, {

repo: "a", ref: "b",
ops: [{ type: "create", file: "/f2" }],
op: { create: ["/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 { Ops } from "../ot/workspace";
import { WorkspaceOp } from "../ot/workspace";
import { RefDB, Ref, NewRef } from "../ref";

@@ -14,3 +14,3 @@ export declare enum Source {

state?: RefState;
ops?: Ops;
op?: WorkspaceOp;
rev?: number;

@@ -17,0 +17,0 @@ ack?: boolean;

@@ -11,3 +11,3 @@ "use strict";

function noop(params) {
return !params.state && !params.ops && !params.delete;
return !params.state && !params.op && !params.delete;
}

@@ -22,3 +22,3 @@ function fromUpdateUpstream(o) {

state: o.state,
ops: o.ops,
op: o.op,
rev: o.rev,

@@ -35,3 +35,3 @@ delete: o.delete,

state: o.state,
ops: o.ops,
op: o.op,
ack: o.ack,

@@ -49,3 +49,3 @@ delete: o.delete,

state: o.state,
ops: o.ops,
op: o.op,
rev: o.rev,

@@ -117,3 +117,3 @@ delete: o.delete,

}
else if (params.ops) {
else if (params.op) {
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.ops);
data.history.push(params.op);
}

@@ -145,0 +145,0 @@ }

@@ -13,3 +13,3 @@ "use strict";

repo: "a", ref: "b",
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" }]] } },
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/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 {

@@ -17,3 +14,3 @@ constructor(sendToUpstream, remoteRepoPath) {

params = deepCopy(params);
if (params.ops) {
if (params.op) {
params.rev = 0;

@@ -26,6 +23,6 @@ }

else if (this.buf.state) {
this.buf.state.data.history.push(params.ops);
this.buf.state.data.history.push(params.op);
}
else if (this.buf.ops) {
this.buf.ops = compose(this.buf.ops, params.ops);
else if (this.buf.op) {
this.buf.op = workspace_1.compose(this.buf.op, params.op);
}

@@ -41,3 +38,3 @@ else {

this.wait = params;
if (this.wait.ops) {
if (this.wait.op) {
this.wait.rev = this.rev;

@@ -62,17 +59,17 @@ }

}
else if (params.ops) {
else if (params.op) {
if ((this.wait && this.wait.state) || (this.buf && this.buf.state)) {
params.ops = undefined;
params.op = undefined;
return;
}
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);
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;
}
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);
if (this.buf && this.buf.op) {
const { a1, b1 } = workspace_1.transform(this.buf.op, params.op);
this.buf.op = a1;
params.op = b1;
}

@@ -94,3 +91,3 @@ this.rev++;

}
else if (this.wait.ops) {
else if (this.wait.op) {
this.rev++;

@@ -103,3 +100,3 @@ }

this.wait = this.buf;
if (this.wait.ops) {
if (this.wait.op) {
this.wait.rev = this.rev;

@@ -106,0 +103,0 @@ }

{
"name": "libzap",
"version": "1.0.5",
"version": "1.0.6",
"description": "JavaScript library for Zap",

@@ -5,0 +5,0 @@ "license": "none",

@@ -34,3 +34,2 @@ import { WorkspaceOp, compose, noop, transform, toString as opToString } from "./workspace";

public record(op: WorkspaceOp) {
console.log("RECORD: ", op);
if (!this.send) {

@@ -87,6 +86,5 @@ 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;

@@ -96,3 +94,3 @@ op = b1;

if (this.buf) {
const { a1, b1 } = transform(this.buf, op);
const {a1, b1} = transform(this.buf, op);
this.buf = a1;

@@ -99,0 +97,0 @@ op = b1;

@@ -6,139 +6,2 @@ 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 {

@@ -654,3 +517,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) {

@@ -771,3 +634,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) {

@@ -774,0 +637,0 @@ return x1;

@@ -6,3 +6,3 @@ import * as is from "../util/is";

import { ConsoleLogger, IConnection, createConnection } from "./connection";
import { InitializeError, InitializeParams, InitializeResult, InitializedNotification, MessageType, ServerCapabilities, ShowMessageRequest } from "./protocol";
import { InitializeParams, InitializeResult, InitializedNotification, MessageType, ServerCapabilities, ShowMessageRequest } from "./protocol";

@@ -12,6 +12,2 @@ const alert = (message: string): void => { console.log("ALERT:", message); };

export interface InitializationFailedHandler {
(error: ResponseError<InitializeError> | Error | any): boolean;
}
export interface MessageStream {

@@ -32,3 +28,2 @@ reader: MessageReader;

initializationOptions?: any | (() => any);
initializationFailedHandler?: InitializationFailedHandler;
errorHandler?: ErrorHandler;

@@ -345,10 +340,3 @@ logger?: Logger;

}, (error: any) => {
if (this.clientOptions.initializationFailedHandler) {
if (this.clientOptions.initializationFailedHandler(error)) {
this.initialize(connection);
} else {
this.stop();
this.readyPromiseCallbacks.reject(error);
}
} else if (error instanceof ResponseError && error.data && error.data.retry) {
if (error instanceof ResponseError && error.data && error.data.retry) {
if (confirm("Retry?")) {

@@ -355,0 +343,0 @@ this.initialize(connection);

@@ -8,3 +8,3 @@ import * as assert from "assert";

import { Ref } from "../ref";
import { WorkspaceOp, Op } from "../ot/workspace";
import { WorkspaceOp } from "../ot/workspace";
import { Workspace } from "../workspace";

@@ -250,3 +250,3 @@

repo: "a", ref: "b",
ops: [{ type: "create", file: "/f" } as Op],
op: { create: ["/f"] },
};

@@ -271,5 +271,3 @@ await handler.afterRefUpdate(ref, params);

repo: "a", ref: "b",
state: {
data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] },
},
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } },
};

@@ -289,3 +287,3 @@ await handler.afterRefUpdate(ref, params);

name: "b",
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] } },
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } },
};

@@ -319,3 +317,3 @@ const params: RefUpdate = {

repo: "a", ref: "b",
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] } },
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } },
};

@@ -338,3 +336,3 @@ await handler.afterRefUpdate(ref, params);

repo: "a", ref: "b2",
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] } },
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } },
};

@@ -341,0 +339,0 @@ await handler.afterRefUpdate(ref, params);

import { RequestType, Emitter, Event } from "vscode-jsonrpc";
import { WorkspaceOp, toNewOps, toLegacyOp } from "../ot/workspace";
import { WorkspaceOp } 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),
ops: toNewOps(op),
op,
});

@@ -363,6 +363,6 @@ }

if (resetToHistory) {
return this.workspace.reset(resetToHistory.map(toLegacyOp));
return this.workspace.reset(resetToHistory);
}
} else if (params.ops) {
return this.workspace.apply(toLegacyOp(params.ops));
} else if (params.op) {
return this.workspace.apply(params.op);
} else if (params.delete) {

@@ -369,0 +369,0 @@ if (workRef.name === ref.name) {

import { NotificationType, NotificationType0, RequestType, RequestType0 } from "vscode-jsonrpc";
import { Ops } from "../ot/workspace";
import { WorkspaceOp } from "../ot/workspace";
import { BranchName } from "../ref";

@@ -116,8 +116,2 @@

export interface InitializeError {
/**
* Indicates whether the client should retry to send the
* initialize request after showing the message provided
* in the {@link ResponseError}
*/
retry: boolean;
}

@@ -319,3 +313,3 @@

export interface RefData extends RefBase {
history: Ops[];
history: WorkspaceOp[];
}

@@ -374,3 +368,3 @@

state?: RefState;
ops?: Ops;
op?: WorkspaceOp;
ack?: boolean;

@@ -390,3 +384,3 @@ delete?: boolean;

state?: RefState;
ops?: Ops;
op?: WorkspaceOp;
rev?: number;

@@ -393,0 +387,0 @@ delete?: boolean;

@@ -7,3 +7,2 @@ import * as assert from "assert";

import { RefUpdateUpstreamParams } from "./protocol";
import { Op } from "../ot/workspace";
import { Ref, RefDB } from "../ref";

@@ -26,3 +25,3 @@

ref.upstream.rev = 1;
ref.state = { data: { gitBase: "", gitBranch: "", history: [[{ type: "create", file: "/f1" } as Op]] } };
ref.state = { data: { gitBase: "", gitBranch: "", history: [{ create: ["/f1"] }] } };
repo.refdb.write(ref.name, ref as Ref);

@@ -33,3 +32,3 @@

repo: "a", ref: "b",
ops: [{ type: "create", file: "/f2" } as Op],
op: { create: ["/f2"] },
});

@@ -68,2 +67,2 @@

return ref;
}
}
import { RefIdentifier, RefState, RefPointer, RefUpdateUpstreamParams, RefUpdateDownstreamParams } from "./protocol";
import { Ops } from "../ot/workspace";
import { WorkspaceOp } from "../ot/workspace";
import { Upstream } from "./upstream";

@@ -17,3 +17,3 @@ import { RefDB, Ref, NewRef } from "../ref";

state?: RefState;
ops?: Ops;
op?: WorkspaceOp;
rev?: number;

@@ -25,3 +25,3 @@ ack?: boolean;

function noop(params: RefUpdate): boolean {
return !params.state && !params.ops && !params.delete;
return !params.state && !params.op && !params.delete;
}

@@ -37,3 +37,3 @@

state: o.state,
ops: o.ops,
op: o.op,
rev: o.rev,

@@ -50,3 +50,3 @@ delete: o.delete,

state: o.state,
ops: o.ops,
op: o.op,
ack: o.ack,

@@ -64,3 +64,3 @@ delete: o.delete,

state: o.state,
ops: o.ops,
op: o.op,
rev: o.rev,

@@ -147,3 +147,3 @@ delete: o.delete,

}
} else if (params.ops) {
} else if (params.op) {
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.ops);
data.history.push(params.op);
}

@@ -191,2 +191,2 @@ }

return JSON.parse(JSON.stringify(o));
}
}

@@ -6,3 +6,2 @@ import * as assert from "assert";

import { RefUpdateUpstreamParams } from "./protocol";
import { Op } from "../ot/workspace";

@@ -20,3 +19,3 @@ describe("Upstream", () => {

repo: "a", ref: "b",
state: { data: { gitBase: "c", gitBranch: "d", history: [[{ type: "create", file: "/f" } as Op]] } },
state: { data: { gitBase: "c", gitBranch: "d", history: [{ create: ["/f"] }] } },
});

@@ -34,2 +33,2 @@

return { wait: u.wait, buf: u.buf, rev: u.rev };
}
}
import { RefUpdate } from "./refState";
import { transform, Ops, toLegacyOp, toNewOps } from "../ot/workspace";
import { compose, transform } 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 {

@@ -30,3 +25,3 @@ /**

params = deepCopy(params);
if (params.ops) {
if (params.op) {
params.rev = 0;

@@ -38,5 +33,5 @@ }

} else if (this.buf.state) {
this.buf.state.data!.history.push(params.ops!);
} else if (this.buf.ops) {
this.buf.ops = compose(this.buf.ops, params.ops!);
this.buf.state.data!.history.push(params.op!);
} else if (this.buf.op) {
this.buf.op = compose(this.buf.op, params.op!);
} else {

@@ -49,3 +44,3 @@ throw new Error(`unable to append/compose op to RefUpdateUpstreamParams with !state and !op`);

this.wait = params;
if (this.wait.ops) {
if (this.wait.op) {
this.wait.rev = this.rev;

@@ -70,20 +65,18 @@ }

}
} else if (params.ops) {
} else if (params.op) {
if ((this.wait && this.wait.state) || (this.buf && this.buf.state)) {
params.ops = undefined;
params.op = undefined;
return;
}
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);
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;
}
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);
if (this.buf && this.buf.op) {
const { a1, b1 } = transform(this.buf.op, params.op);
this.buf.op = a1;
params.op = b1;
}

@@ -108,3 +101,3 @@ this.rev++;

}
} else if (this.wait.ops) {
} else if (this.wait.op) {
this.rev++;

@@ -117,3 +110,3 @@ } else {

this.wait = this.buf;
if (this.wait.ops) {
if (this.wait.op) {
this.wait.rev = this.rev;

@@ -131,2 +124,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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc