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

libzap

Package Overview
Dependencies
Maintainers
1
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 0.0.36 to 0.0.37

2

lib/ot/client_test.js

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

function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
step((generator = generator.apply(thisArg, _arguments)).next());
});

@@ -10,0 +10,0 @@ };

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

function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
step((generator = generator.apply(thisArg, _arguments)).next());
});

@@ -10,0 +10,0 @@ };

@@ -5,3 +5,7 @@ import { Event } from "vscode-jsonrpc";

import { IConnection } from "./connection";
import { RefIdentifier, RepoWatchParams, WorkspaceWillSaveFileParams } from "./protocol";
import { RefIdentifier, RefInfoResult, WorkspaceWillSaveFileParams } from "./protocol";
export declare enum MergeStrategy {
LocalClobbersRemote = 1,
RemoteClobbersLocal = 2,
}
export interface Workspace {

@@ -13,4 +17,5 @@ apply(op: WorkspaceOp): Promise<void>;

onWillSaveFile(listener?: (params: WorkspaceWillSaveFileParams) => Thenable<void>): void;
localOverwritesRemote(): boolean;
diffBufferFilesAgainst(history: WorkspaceOp[]): WorkspaceOp;
allBufferFiles(): {
[fileName: string]: string;
};
dispose(): void;

@@ -29,4 +34,5 @@ }

register(connection: IConnection): void;
attachWorkspace(refID: RefIdentifier, workspace: Workspace): Promise<void>;
repoWatch(params: RepoWatchParams): Thenable<void>;
attachWorkspace(refID: RefIdentifier, workspace: Workspace, mergeStrategy: MergeStrategy): Promise<void>;
private repoWatch(params);
queryRefInfo(refID: RefIdentifier): Thenable<RefInfoResult>;
private symbolicRefUpdateEmitter;

@@ -33,0 +39,0 @@ readonly onDidUpdateSymbolicRef: Event<SymbolicRefUpdateEvent>;

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

function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
step((generator = generator.apply(thisArg, _arguments)).next());
});

@@ -13,4 +13,8 @@ };

const client_1 = require("../ot/client");
const workspace_1 = require("../ot/workspace");
const protocol_1 = require("./protocol");
var MergeStrategy;
(function (MergeStrategy) {
MergeStrategy[MergeStrategy["LocalClobbersRemote"] = 1] = "LocalClobbersRemote";
MergeStrategy[MergeStrategy["RemoteClobbersLocal"] = 2] = "RemoteClobbersLocal";
})(MergeStrategy = exports.MergeStrategy || (exports.MergeStrategy = {}));
class Handler {

@@ -29,5 +33,15 @@ constructor(remoteClient) {

}
attachWorkspace(refID, workspace) {
attachWorkspace(refID, workspace, mergeStrategy) {
return __awaiter(this, void 0, void 0, function* () {
yield this.getRepo(refID.repo).getRef(refID.ref).attachWorkspace(workspace);
const refspecs = [refID.ref];
if (refID.ref === "HEAD") {
const info = yield this.queryRefInfo(refID);
if (!info.target) {
return Promise.reject(new Error(`ref ${JSON.stringify(refID)} has no target`));
}
refspecs.push(info.target);
}
yield this.repoWatch({ repo: refID.repo, refspecs });
yield this.getRepo(refID.repo).getRef(refID.ref).attachWorkspace(workspace, mergeStrategy);
return Promise.resolve(void 0);
});

@@ -42,2 +56,5 @@ }

}
queryRefInfo(refID) {
return this.remoteClient.sendRequest(protocol_1.RefInfoRequest.type, refID);
}
get onDidUpdateSymbolicRef() {

@@ -138,8 +155,9 @@ return this.symbolicRefUpdateEmitter.event;

oldTargetHandler.detachWorkspace();
return this.targetHandler.attachWorkspace(this.workspace);
return this.targetHandler.attachWorkspace(this.workspace, this.mergeStrategy);
}
return Promise.resolve(void 0);
}
attachWorkspace(newWorkspace) {
attachWorkspace(newWorkspace, mergeStrategy) {
return __awaiter(this, void 0, void 0, function* () {
this.mergeStrategy = mergeStrategy;
if (this.workspace === newWorkspace) {

@@ -154,3 +172,3 @@ console.log(`WARNING: SymbolicRefHandler(${JSON.stringify(this.refID)}): attachWorkspace called unnecessarily with this.workspace === newWorkspace`);

this.workspace = newWorkspace;
return this.targetHandler.attachWorkspace(newWorkspace);
return this.targetHandler.attachWorkspace(newWorkspace, mergeStrategy);
});

@@ -195,6 +213,7 @@ }

}
attachWorkspace(newWorkspace) {
attachWorkspace(newWorkspace, mergeStrategy) {
return __awaiter(this, void 0, void 0, function* () {
if (this.workspace === newWorkspace) {
console.log(`WARNING: NonSymbolicRefHandler(${JSON.stringify(this.refID)}): attachWorkspace called unnecessarily with this.workspace === newWorkspace`);
return Promise.resolve(void 0);
}

@@ -209,15 +228,19 @@ if (this.workspace) {

this.workspace.onWillSaveFile(params => this.onWorkspaceWillSaveFile(params));
const localOverwritesRemote = this.workspace.localOverwritesRemote();
if (localOverwritesRemote) {
const toRecord = this.workspace.diffBufferFilesAgainst(this.state.history ? this.state.history : []);
if (!workspace_1.noop(toRecord)) {
this.ot.record(toRecord);
}
}
else {
if (typeof self !== "undefined" && self.importScripts) {
switch (mergeStrategy) {
case MergeStrategy.LocalClobbersRemote:
this.state = yield this.remoteClient.sendRequest(protocol_1.WorkspaceResetRequest.type, {
dir: this.refID.repo,
ref: this.refID.ref,
bufferFiles: this.workspace.allBufferFiles(),
});
yield this.ot.reset(this.state.history);
break;
case MergeStrategy.RemoteClobbersLocal:
yield this.ot.reset(this.state && this.state.history ? this.state.history : []);
yield this.workspace.reset(this.state && this.state.history ? this.state.history : []);
}
break;
default:
return Promise.reject(new Error(`unknown merge strategy: ${mergeStrategy}`));
}
return Promise.resolve(void 0);
});

@@ -224,0 +247,0 @@ }

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

function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
step((generator = generator.apply(thisArg, _arguments)).next());
});

@@ -24,4 +24,3 @@ };

onWillSaveFile(_listener) { },
localOverwritesRemote() { return true; },
diffBufferFilesAgainst(_history) { return {}; },
allBufferFiles() { return {}; },
dispose() { },

@@ -68,5 +67,4 @@ mockRecordOp(op) { onOpListener(op); },

const workspace = createMockWorkspace();
yield handler.attachWorkspace({ repo: "repo", ref: "ref" }, workspace);
return client.start().initialStart.then(() => {
return handler.repoWatch({ repo: "repo", refspecs: ["*"] }).then(() => {
return handler.attachWorkspace({ repo: "repo", ref: "ref" }, workspace, handler_1.MergeStrategy.RemoteClobbersLocal).then(() => {
workspace.mockRecordOp({ head: "a" });

@@ -79,2 +77,9 @@ return util_1.assertResolved(ok, "server did not receive 'ref/update' from client");

const { server, serverOptions } = util_1.createTestServer();
server.onRequest("repo/watch", () => {
return server.sendRequest("ref/update", {
repo: "repo",
ref: "ref",
state: { gitBase: "c", gitBranch: "d" },
});
});
const client = new client_1.Client(serverOptions, {});

@@ -89,7 +94,7 @@ const handler = new handler_1.Handler(client);

const workspace = createMockWorkspace();
yield handler.attachWorkspace({ repo: "repo", ref: "ref" }, workspace);
let ok = false;
handler.getRepo("repo").getRef("ref").ot.ack = () => { ok = true; };
return client.start().initialStart.then(() => {
return server.sendRequest(protocol_1.RefUpdateDownstreamRequest.type, {
return client.start().initialStart.then(() => __awaiter(this, void 0, void 0, function* () {
yield handler.attachWorkspace({ repo: "repo", ref: "ref" }, workspace, handler_1.MergeStrategy.RemoteClobbersLocal);
yield server.sendRequest(protocol_1.RefUpdateDownstreamRequest.type, {
repo: "repo",

@@ -100,8 +105,7 @@ ref: "ref",

op: {},
}).then(() => {
assert.ok(ok, "client did not receive 'ack' from server");
});
}, (err) => assert.ifError(err));
assert.ok(ok, "client did not receive 'ack' from server");
}), (err) => assert.ifError(err));
}));
});
//# sourceMappingURL=ot_test.js.map

@@ -233,2 +233,11 @@ import { NotificationType, NotificationType0, RequestType, RequestType0 } from "vscode-jsonrpc";

}
export interface WorkspaceResetParams extends WorkspaceIdentifier {
bufferFiles: {
[fileName: string]: string;
};
ref: string;
}
export declare namespace WorkspaceResetRequest {
const type: RequestType<WorkspaceResetParams, RefState, any, void>;
}
export interface WorkspaceWillSaveFileParams {

@@ -235,0 +244,0 @@ uri: string;

@@ -119,2 +119,6 @@ "use strict";

})(WorkspaceStatusRequest = exports.WorkspaceStatusRequest || (exports.WorkspaceStatusRequest = {}));
var WorkspaceResetRequest;
(function (WorkspaceResetRequest) {
WorkspaceResetRequest.type = new vscode_jsonrpc_1.RequestType("workspace/reset");
})(WorkspaceResetRequest = exports.WorkspaceResetRequest || (exports.WorkspaceResetRequest = {}));
var WorkspaceWillSaveFileRequest;

@@ -121,0 +125,0 @@ (function (WorkspaceWillSaveFileRequest) {

{
"name": "libzap",
"version": "0.0.36",
"version": "0.0.37",
"description": "JavaScript library for Zap",

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

import { Emitter, Event } from "vscode-jsonrpc";
import { Client as OTClient } from "../ot/client";
import { noop, WorkspaceOp } from "../ot/workspace";
import { WorkspaceOp } from "../ot/workspace";
import { Client } from "./client";
import { IConnection } from "./connection";
import { RefIdentifier, RefState, RefUpdateUpstreamRequest, RefUpdateSymbolicParams, RefUpdateSymbolicRequest, RefUpdateDownstreamRequest, RefUpdateDownstreamParams, RepoWatchParams, RepoWatchRequest, WorkspaceWillSaveFileParams, WorkspaceWillSaveFileRequest } from "./protocol";
import { RefIdentifier, RefInfoRequest, RefInfoResult, RefState, RefUpdateUpstreamRequest, RefUpdateSymbolicParams, RefUpdateSymbolicRequest, RefUpdateDownstreamRequest, RefUpdateDownstreamParams, RepoWatchParams, RepoWatchRequest, WorkspaceResetRequest, WorkspaceResetParams, WorkspaceWillSaveFileParams, WorkspaceWillSaveFileRequest } from "./protocol";
declare var self: any; // HACK(sqs)
export enum MergeStrategy {
LocalClobbersRemote = 1,
RemoteClobbersLocal = 2,
}

@@ -27,4 +30,3 @@ export interface Workspace {

localOverwritesRemote(): boolean; // HACK(sqs)
diffBufferFilesAgainst(history: WorkspaceOp[]): WorkspaceOp;
allBufferFiles(): { [fileName: string]: string };

@@ -67,9 +69,26 @@ dispose(): void;

public async attachWorkspace(refID: RefIdentifier, workspace: Workspace): Promise<void> {
await this.getRepo(refID.repo).getRef(refID.ref).attachWorkspace(workspace);
public async attachWorkspace(refID: RefIdentifier, workspace: Workspace, mergeStrategy: MergeStrategy): Promise<void> {
// Ensure we're watching refID (and, if it's a symbolic ref,
// its target), so that we know the state of the ref.
const refspecs = [refID.ref];
// TODO(sqs): support symbolic refs other than "HEAD"
if (refID.ref === "HEAD") {
const info = await this.queryRefInfo(refID);
if (!info.target) { return Promise.reject(new Error(`ref ${JSON.stringify(refID)} has no target`)); }
refspecs.push(info.target);
}
// The latest watch refspec overwrites all previous watch
// refspecs, so this unwatches past watches (which is desirable).
await this.repoWatch({ repo: refID.repo, refspecs });
await this.getRepo(refID.repo).getRef(refID.ref).attachWorkspace(workspace, mergeStrategy);
return Promise.resolve(void 0);
}
// repoWatch starts watching a repo. It removes any previous watch
// (and the previous watch's refspec) of the same repo.
public repoWatch(params: RepoWatchParams): Thenable<void> {
/**
* repoWatch starts watching a repo. It removes any previous watch
* (and the previous watch's refspec) of the same repo.
*/
private repoWatch(params: RepoWatchParams): Thenable<void> {
return this.remoteClient.onReady().then(() => {

@@ -82,2 +101,6 @@ this.isDuringWatchCall = true;

public queryRefInfo(refID: RefIdentifier): Thenable<RefInfoResult> {
return this.remoteClient.sendRequest(RefInfoRequest.type, refID);
}
private symbolicRefUpdateEmitter: Emitter<SymbolicRefUpdateEvent> = new Emitter<SymbolicRefUpdateEvent>();

@@ -160,3 +183,3 @@ public get onDidUpdateSymbolicRef(): Event<SymbolicRefUpdateEvent> {

interface RefHandler {
attachWorkspace(workspace: Workspace): Promise<void>;
attachWorkspace(workspace: Workspace, mergeStrategy: MergeStrategy): Promise<void>;
detachWorkspace(): void;

@@ -169,2 +192,3 @@ }

private workspace?: Workspace;
private mergeStrategy: MergeStrategy;

@@ -200,3 +224,3 @@ constructor(

oldTargetHandler.detachWorkspace();
return this.targetHandler.attachWorkspace(this.workspace);
return this.targetHandler.attachWorkspace(this.workspace, this.mergeStrategy);
}

@@ -206,3 +230,4 @@ return Promise.resolve(void 0);

public async attachWorkspace(newWorkspace: Workspace): Promise<void> {
public async attachWorkspace(newWorkspace: Workspace, mergeStrategy: MergeStrategy): Promise<void> {
this.mergeStrategy = mergeStrategy;
if (this.workspace === newWorkspace) {

@@ -217,3 +242,3 @@ console.log(`WARNING: SymbolicRefHandler(${JSON.stringify(this.refID)}): attachWorkspace called unnecessarily with this.workspace === newWorkspace`);

this.workspace = newWorkspace;
return this.targetHandler.attachWorkspace(newWorkspace);
return this.targetHandler.attachWorkspace(newWorkspace, mergeStrategy);
}

@@ -262,5 +287,7 @@

public async attachWorkspace(newWorkspace: Workspace): Promise<void> {
public async attachWorkspace(newWorkspace: Workspace, mergeStrategy: MergeStrategy): Promise<void> {
if (this.workspace === newWorkspace) {
console.log(`WARNING: NonSymbolicRefHandler(${JSON.stringify(this.refID)}): attachWorkspace called unnecessarily with this.workspace === newWorkspace`);
// When running on the web it doesn't look like we are really attaching to the workspace which is causing problems updating and refreshing.
return Promise.resolve(void 0);
}

@@ -278,23 +305,22 @@

// What we do here depends on the resolution strategy.
//
// If it's local-overwrites-remote, then we serialize the
// workspace's unsaved changes and add them to the history
// such that this.workspace.reset() on the history would be a
// noop.
//
// If it's remote-overwrites-local, then we reset the
// workspace to the ops provided.
const localOverwritesRemote = this.workspace.localOverwritesRemote();
if (localOverwritesRemote) {
const toRecord = this.workspace.diffBufferFilesAgainst(this.state!.history ? this.state!.history! : []);
if (!noop(toRecord)) { this.ot.record(toRecord); }
} else {
// TODO(sqs): these get called after ref/update resets below on vscode but not on the browser. HACK(sqs)
// for now, check if we're running in the browser.
if (typeof self !== "undefined" && (self as any).importScripts) {
switch (mergeStrategy) {
case MergeStrategy.LocalClobbersRemote:
// TODO(sqs): because this uses workspace/reset, it only works for vscode (not web), but that is OK because we only want this merge strategy's behavior on vscode.
this.state = await this.remoteClient.sendRequest(WorkspaceResetRequest.type, {
dir: this.refID.repo,
ref: this.refID.ref,
bufferFiles: this.workspace.allBufferFiles(),
} as WorkspaceResetParams);
await this.ot.reset(this.state!.history);
break;
case MergeStrategy.RemoteClobbersLocal:
await this.ot.reset(this.state && this.state.history ? this.state.history : []);
await this.workspace.reset(this.state && this.state.history ? this.state.history : []);
}
break;
default:
return Promise.reject(new Error(`unknown merge strategy: ${mergeStrategy}`));
}
return Promise.resolve(void 0);
}

@@ -301,0 +327,0 @@

import * as assert from "assert";
import { Client } from "./client";
import { Handler, Workspace } from "./handler";
import { Handler, MergeStrategy, Workspace } from "./handler";
import { RefUpdateDownstreamRequest, RefUpdateDownstreamParams, WorkspaceWillSaveFileParams } from "./protocol";

@@ -22,5 +22,3 @@ import { assertResolved, createTestServer } from "./util";

// HACK:
localOverwritesRemote(): boolean { return true; },
diffBufferFilesAgainst(_history: WorkspaceOp[]): WorkspaceOp { return {}; },
allBufferFiles(): { [fileName: string]: string } { return {}; },

@@ -73,6 +71,4 @@ dispose(): void { /* noop */ },

const workspace = createMockWorkspace();
await handler.attachWorkspace({ repo: "repo", ref: "ref" }, workspace);
return client.start().initialStart.then(() => {
return handler.repoWatch({ repo: "repo", refspecs: ["*"] }).then(() => {
return handler.attachWorkspace({ repo: "repo", ref: "ref" }, workspace, MergeStrategy.RemoteClobbersLocal).then(() => {
workspace.mockRecordOp({ head: "a" });

@@ -87,2 +83,10 @@ return assertResolved(ok, "server did not receive 'ref/update' from client");

server.onRequest("repo/watch", () => {
return server.sendRequest("ref/update", {
repo: "repo",
ref: "ref",
state: { gitBase: "c", gitBranch: "d" },
} as RefUpdateDownstreamParams);
});
const client = new Client(serverOptions, {});

@@ -100,3 +104,2 @@ const handler = new Handler(client);

const workspace = createMockWorkspace();
await handler.attachWorkspace({ repo: "repo", ref: "ref" }, workspace);

@@ -106,4 +109,5 @@ let ok = false;

return client.start().initialStart.then(() => {
return server.sendRequest(RefUpdateDownstreamRequest.type, {
return client.start().initialStart.then(async () => {
await handler.attachWorkspace({ repo: "repo", ref: "ref" }, workspace, MergeStrategy.RemoteClobbersLocal);
await server.sendRequest(RefUpdateDownstreamRequest.type, {
repo: "repo",

@@ -114,7 +118,6 @@ ref: "ref",

op: {},
} as RefUpdateDownstreamParams).then(() => {
assert.ok(ok, "client did not receive 'ack' from server");
});
} as RefUpdateDownstreamParams);
assert.ok(ok, "client did not receive 'ack' from server");
}, (err) => assert.ifError(err));
});
});

@@ -430,2 +430,11 @@ import { NotificationType, NotificationType0, RequestType, RequestType0 } from "vscode-jsonrpc";

export interface WorkspaceResetParams extends WorkspaceIdentifier {
bufferFiles: { [fileName: string]: string }; // "#mydir/myfile.txt" -> unsaved file contents
ref: string;
}
export namespace WorkspaceResetRequest {
export const type = new RequestType<WorkspaceResetParams, RefState, any, void>("workspace/reset");
}
export interface WorkspaceWillSaveFileParams {

@@ -432,0 +441,0 @@ uri: string;

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