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.9 to 1.0.10

lib/wow.d.ts

2

lib/remote/client_test.js

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

return new client_1.Client("testClient", serverOptions, {})
.start().initialStart.then(() => {
.connection().then(() => {
assert.ok(ok, "server did not receive 'initialize' from client");

@@ -18,0 +18,0 @@ }, (err) => assert.ifError(err));

@@ -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, Event, GenericNotificationHandler, GenericRequestHandler, Logger, MessageReader, 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 {

@@ -14,20 +10,11 @@ reader: MessageReader;

}
export interface Configuration {
}
export interface ClientOptions {
configuration?: Configuration;
initializationOptions?: any | (() => any);
initializationFailedHandler?: InitializationFailedHandler;
errorHandler?: ErrorHandler;
logger?: Logger;
connectionRetryInterval?: number;
}
export declare enum State {
Initial = 0,
Stopped = 1,
Running = 2,
On = 0,
Off = 1,
}
export interface StateChangeEvent {
oldState: State;
newState: State;
}
export interface FeatureHandler {

@@ -43,11 +30,4 @@ register(connection: IConnection): void;

private _state;
private readyPromise;
private readyPromiseCallbacks;
private connectionPromise;
private resolvedConnection;
private capabilities;
private configuration;
private listeners;
private providers;
private telemetryEmitter;
private stateChangeEmitter;

@@ -57,5 +37,3 @@ private logger;

private tracer;
constructor(id: string, serverOptions: ServerOptions, clientOptions: ClientOptions);
private state;
private getPublicState();
constructor(id: string, serverOptions: ServerOptions, clientOptions?: ClientOptions);
sendRequest<R, E, RO>(type: RequestType0<R, E, RO>, token?: CancellationToken): Thenable<R>;

@@ -75,25 +53,15 @@ sendRequest<P, R, E, RO>(type: RequestType<P, R, E, RO>, params: P, token?: CancellationToken): Thenable<R>;

onNotification(method: string, handler: GenericNotificationHandler): void;
readonly onTelemetry: Event<any>;
readonly onDidChangeState: Event<StateChangeEvent>;
private state;
readonly onDidChangeState: Event<State>;
trace: Trace;
needsStart(): boolean;
needsStop(): boolean;
onReady(): Promise<void>;
private isConnectionActive();
start(): {
disposable: Disposable;
initialStart: Thenable<void>;
};
private resolveConnection();
dispose(): void;
connection(): Thenable<IConnection>;
private retryConnect();
connect(): void;
private attachHandlers(connection);
private initialize(connection);
clearStartFailedState(): Thenable<void>;
stop(): Thenable<void>;
private cleanUp();
private createConnection();
private handleConnectionClosed();
private handleConnectionError(error, message, count);
private _registeredHandlers;
private registeredHandlers;
registerHandler(id: string, handler: FeatureHandler): void;
private hookCapabilities(connection);
protected logFailedRequest(type: RPCMessageType, error: any): void;
private logErrorData(message, data);

@@ -103,13 +71,1 @@ private logDebugData(message, data);

export declare function errorDataToString(data: any): string;
export interface ErrorHandler {
error(error: Error, message: Message, count: number): ErrorAction;
closed(): CloseAction;
}
export declare enum ErrorAction {
Continue = 1,
Shutdown = 2,
}
export declare enum CloseAction {
DoNotRestart = 1,
Restart = 2,
}

@@ -8,22 +8,13 @@ "use strict";

const alert = (message) => { console.log("ALERT:", message); };
const confirm = (message) => { console.log("CONFIRM:", message); return false; };
;
var State;
(function (State) {
State[State["Initial"] = 0] = "Initial";
State[State["Stopped"] = 1] = "Stopped";
State[State["Running"] = 2] = "Running";
State[State["On"] = 0] = "On";
State[State["Off"] = 1] = "Off";
})(State = exports.State || (exports.State = {}));
var ClientState;
(function (ClientState) {
ClientState[ClientState["Initial"] = 0] = "Initial";
ClientState[ClientState["Starting"] = 1] = "Starting";
ClientState[ClientState["StartFailed"] = 2] = "StartFailed";
ClientState[ClientState["Running"] = 3] = "Running";
ClientState[ClientState["Stopping"] = 4] = "Stopping";
ClientState[ClientState["Stopped"] = 5] = "Stopped";
})(ClientState || (ClientState = {}));
class Client {
constructor(id, serverOptions, clientOptions) {
this._registeredHandlers = new Map();
this._state = State.Off;
this.stateChangeEmitter = new vscode_jsonrpc_1.Emitter();
this.registeredHandlers = new Map();
this.id = id;

@@ -33,15 +24,3 @@ this.name = id;

this.clientOptions = clientOptions || {};
this.clientOptions.errorHandler = this.clientOptions.errorHandler || new DefaultErrorHandler(this.name);
this.configuration = clientOptions.configuration || {};
this.stateChangeEmitter = new vscode_jsonrpc_1.Emitter();
this.state = ClientState.Initial;
this.connectionPromise = undefined;
this.resolvedConnection = undefined;
this.listeners = undefined;
this.providers = undefined;
this.readyPromise = new Promise((resolve, reject) => {
this.readyPromiseCallbacks = { resolve, reject };
});
this.logger = this.clientOptions.logger || new connection_1.ConsoleLogger();
this.telemetryEmitter = new vscode_jsonrpc_1.Emitter();
this.tracer = {

@@ -53,30 +32,5 @@ log: (message, data) => {

}
get state() {
return this._state;
}
set state(value) {
let oldState = this.getPublicState();
this._state = value;
let newState = this.getPublicState();
if (newState !== oldState) {
this.stateChangeEmitter.fire({ oldState, newState });
}
}
getPublicState() {
if (this.state === ClientState.Initial) {
return State.Initial;
}
else if (this.state === ClientState.Running) {
return State.Running;
}
else {
return State.Stopped;
}
}
sendRequest(type, ...params) {
if (!this.isConnectionActive()) {
throw new Error("Zap client is not ready yet");
}
try {
return this.resolvedConnection.sendRequest(type, ...params);
return this.connection().then(connection => connection.sendRequest(type, ...params));
}

@@ -89,7 +43,4 @@ catch (error) {

onRequest(type, handler) {
if (!this.isConnectionActive()) {
throw new Error("Zap client is not ready yet");
}
try {
this.resolvedConnection.onRequest(type, handler);
this.connection().then(connection => connection.onRequest(type, handler));
}

@@ -102,7 +53,4 @@ catch (error) {

sendNotification(type, params) {
if (!this.isConnectionActive()) {
throw new Error("Zap client is not ready yet");
}
try {
this.resolvedConnection.sendNotification(type, params);
this.connection().then(connection => connection.sendNotification(type, params));
}

@@ -115,7 +63,4 @@ catch (error) {

onNotification(type, handler) {
if (!this.isConnectionActive()) {
throw new Error("Zap client is not ready yet");
}
try {
this.resolvedConnection.onNotification(type, handler);
this.connection().then(connection => connection.onNotification(type, handler));
}

@@ -127,4 +72,5 @@ catch (error) {

}
get onTelemetry() {
return this.telemetryEmitter.event;
set state(state) {
this._state = state;
this.stateChangeEmitter.fire(state);
}

@@ -136,104 +82,84 @@ get onDidChangeState() {

this._trace = value;
this.onReady().then(() => {
this.resolveConnection().then((connection) => {
connection.trace(value, this.tracer);
});
this.connection().then(connection => {
connection.trace(value, this.tracer);
}, () => { });
}
needsStart() {
return this.state === ClientState.Initial || this.state === ClientState.Stopping || this.state === ClientState.Stopped;
dispose() {
if (this.connectionPromise) {
this.connectionPromise.then(connection => {
connection.dispose();
}, () => { });
}
}
needsStop() {
return this.state === ClientState.Starting || this.state === ClientState.Running;
connection() {
if (this.connectionPromise) {
return this.connectionPromise;
}
this.connectionPromise = this.createConnection().then(connection => connection, error => {
this.connectionPromise = undefined;
this.retryConnect();
return Promise.reject(error);
});
return this.connectionPromise;
}
onReady() {
return this.readyPromise;
retryConnect() {
const delay = this.clientOptions.connectionRetryInterval || 500;
setTimeout(() => {
this.connect();
}, delay);
}
isConnectionActive() {
return this.state === ClientState.Running && !!this.resolvedConnection;
connect() {
this.connection().then(() => { }, () => { });
}
start() {
this.listeners = [];
this.providers = [];
if (!this.needsStart()) {
throw new Error("!needsStart()");
}
this.state = ClientState.Starting;
const initialStart = this.resolveConnection().then((connection) => {
connection.onLogMessage((message) => {
switch (message.type) {
case protocol_1.MessageType.Error:
this.logger.error(message.message);
break;
case protocol_1.MessageType.Warning:
this.logger.warn(message.message);
break;
case protocol_1.MessageType.Info:
this.logger.info(message.message);
break;
default:
this.logger.info(message.message);
}
});
connection.onShowMessage((message) => {
switch (message.type) {
case protocol_1.MessageType.Error:
alert(message.message);
break;
case protocol_1.MessageType.Warning:
alert(message.message);
break;
case protocol_1.MessageType.Info:
alert(message.message);
break;
default:
alert(message.message);
}
});
connection.onRequest(protocol_1.ShowMessageRequest.type, (params) => {
const alert2 = (message) => { alert(message); return Promise.resolve(); };
let messageFunc;
switch (params.type) {
case protocol_1.MessageType.Error:
messageFunc = alert2;
break;
case protocol_1.MessageType.Warning:
messageFunc = alert2;
break;
case protocol_1.MessageType.Info:
messageFunc = alert2;
break;
default:
messageFunc = alert2;
}
let actions = params.actions || [];
return messageFunc(`${params.message}: ${JSON.stringify(actions)}`);
});
connection.onTelemetry((data) => {
this.telemetryEmitter.fire(data);
});
connection.listen();
return this.initialize(connection);
}, (error) => {
this.state = ClientState.StartFailed;
this.readyPromiseCallbacks.reject(error);
this.logErrorData("Starting client failed", error);
alert(`Couldn't start ${this.name} client`);
return error;
attachHandlers(connection) {
connection.onLogMessage((message) => {
switch (message.type) {
case protocol_1.MessageType.Error:
this.logger.error(message.message);
break;
case protocol_1.MessageType.Warning:
this.logger.warn(message.message);
break;
case protocol_1.MessageType.Info:
this.logger.info(message.message);
break;
default:
this.logger.info(message.message);
}
});
return {
initialStart: initialStart.then(() => void 0),
disposable: vscode_jsonrpc_1.Disposable.create(() => {
if (this.needsStop()) {
this.stop();
}
}),
};
connection.onShowMessage((message) => {
switch (message.type) {
case protocol_1.MessageType.Error:
alert(message.message);
break;
case protocol_1.MessageType.Warning:
alert(message.message);
break;
case protocol_1.MessageType.Info:
alert(message.message);
break;
default:
alert(message.message);
}
});
connection.onRequest(protocol_1.ShowMessageRequest.type, (params) => {
const alert2 = (message) => { alert(message); return Promise.resolve(); };
let messageFunc;
switch (params.type) {
case protocol_1.MessageType.Error:
messageFunc = alert2;
break;
case protocol_1.MessageType.Warning:
messageFunc = alert2;
break;
case protocol_1.MessageType.Info:
messageFunc = alert2;
break;
default:
messageFunc = alert2;
}
let actions = params.actions || [];
return messageFunc(`${params.message}: ${JSON.stringify(actions)}`);
});
}
resolveConnection() {
if (!this.connectionPromise) {
this.connectionPromise = this.createConnection();
}
return this.connectionPromise;
}
initialize(connection) {

@@ -248,119 +174,36 @@ let initOption = this.clientOptions.initializationOptions;

return connection.initialize(initParams).then((result) => {
this.resolvedConnection = connection;
this.state = ClientState.Running;
this.capabilities = result.capabilities || {};
this.hookCapabilities(connection);
connection.sendNotification(protocol_1.InitializedNotification.type, {});
this.hookCapabilities(connection);
this.readyPromiseCallbacks.resolve();
return result;
}, (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 (confirm("Retry?")) {
this.initialize(connection);
}
else {
this.stop();
this.readyPromiseCallbacks.reject(error);
}
}
else {
if (error && error.message) {
alert(error.message);
}
this.logErrorData("Server initialization failed.", error);
this.stop();
this.readyPromiseCallbacks.reject(error);
}
});
}
clearStartFailedState() {
if (this.state === ClientState.StartFailed) {
this.state = ClientState.Initial;
return this.stop();
}
return Promise.resolve();
}
stop() {
if (!this.connectionPromise) {
this.state = ClientState.Stopped;
return Promise.resolve();
}
this.state = ClientState.Stopping;
this.cleanUp();
return this.resolveConnection().then(connection => {
return connection.shutdown().then(() => {
connection.exit();
connection.dispose();
});
}, () => { }).then(() => {
this.state = ClientState.Stopped;
this.connectionPromise = undefined;
this.resolvedConnection = undefined;
});
}
cleanUp() {
if (this.listeners) {
this.listeners.forEach(listener => listener.dispose());
this.listeners = undefined;
}
if (this.providers) {
this.providers.forEach(provider => provider.dispose());
this.providers = undefined;
}
}
createConnection() {
const errorHandler = (err, message, count) => {
this.handleConnectionError(err, message, count);
this.logger.error(`connection error ${err} message ${message} count ${count}`);
};
const closeHandler = () => this.handleConnectionClosed();
return this.serverOptions.connect()
.then(({ reader, writer }) => connection_1.createConnection(reader, writer, errorHandler, closeHandler));
const closeHandler = () => {
this.logger.log(`connection closed`);
this.connectionPromise = undefined;
this.state = State.Off;
this.retryConnect();
};
return this.serverOptions.connect().then(({ reader, writer }) => {
const connection = connection_1.createConnection(reader, writer, errorHandler, closeHandler);
this.attachHandlers(connection);
connection.listen();
return this.initialize(connection).then(() => {
this.state = State.On;
return connection;
});
}).then(v => v, error => Promise.reject(`Unable to connect to local Zap server: ${error}`));
}
handleConnectionClosed() {
if (this.state === ClientState.Stopping || this.state === ClientState.Stopped) {
return;
}
if (this.resolvedConnection) {
this.resolvedConnection.dispose();
}
this.connectionPromise = undefined;
this.resolvedConnection = undefined;
let action = this.clientOptions.errorHandler.closed();
if (action === CloseAction.DoNotRestart) {
this.logger.error("Connection to server got closed. Server will not be restarted.");
this.state = ClientState.Stopped;
this.cleanUp();
}
else if (action === CloseAction.Restart) {
this.logger.info("Connection to server got closed. Server will restart.");
this.cleanUp();
this.state = ClientState.Initial;
this.start();
}
}
handleConnectionError(error, message, count) {
let action = this.clientOptions.errorHandler.error(error, message, count);
if (action === ErrorAction.Shutdown) {
this.logger.error("Connection to server is erroring. Shutting down server.");
this.stop();
}
}
registerHandler(id, handler) {
if (this._registeredHandlers.has(id)) {
if (this.registeredHandlers.has(id)) {
throw new Error(`handler already registered with id ${id}`);
}
this._registeredHandlers.set(id, handler);
this.registeredHandlers.set(id, handler);
}
hookCapabilities(connection) {
if (this.capabilities.workspaceOperationalTransformation) {
this._registeredHandlers.forEach((handler) => {
this.registeredHandlers.forEach((handler) => {
handler.register(connection);

@@ -373,5 +216,2 @@ });

}
logFailedRequest(type, error) {
this.logErrorData(`Request ${type.method} failed.`, error);
}
logErrorData(message, data) {

@@ -412,41 +252,2 @@ if (data) {

exports.errorDataToString = errorDataToString;
var ErrorAction;
(function (ErrorAction) {
ErrorAction[ErrorAction["Continue"] = 1] = "Continue";
ErrorAction[ErrorAction["Shutdown"] = 2] = "Shutdown";
})(ErrorAction = exports.ErrorAction || (exports.ErrorAction = {}));
var CloseAction;
(function (CloseAction) {
CloseAction[CloseAction["DoNotRestart"] = 1] = "DoNotRestart";
CloseAction[CloseAction["Restart"] = 2] = "Restart";
})(CloseAction = exports.CloseAction || (exports.CloseAction = {}));
class DefaultErrorHandler {
constructor(name) {
this.name = name;
this.restarts = [];
}
error(_error, _message, count) {
if (count && count <= 3) {
return ErrorAction.Continue;
}
return ErrorAction.Shutdown;
}
closed() {
this.restarts.push(Date.now());
if (this.restarts.length < 5) {
return CloseAction.Restart;
}
else {
let diff = this.restarts[this.restarts.length - 1] - this.restarts[0];
if (diff <= 3 * 1000) {
alert(`The ${this.name} server crashed 5 times in the last 3 seconds. The server will not be restarted.`);
return CloseAction.DoNotRestart;
}
else {
this.restarts.shift();
return CloseAction.Restart;
}
}
}
}
//# sourceMappingURL=client.js.map

@@ -31,4 +31,2 @@ import { CancellationToken, GenericNotificationHandler, GenericRequestHandler, Logger, Message, MessageReader, MessageType as RPCMessageType, MessageWriter, NotificationHandler, NotificationHandler0, NotificationType, NotificationType0, RequestHandler, RequestHandler0, RequestType, RequestType0, Trace, Tracer } from "vscode-jsonrpc";

initialize(params: InitializeParams): Thenable<InitializeResult>;
shutdown(): Thenable<void>;
exit(): void;
onLogMessage(handle: NotificationHandler<LogMessageParams>): void;

@@ -35,0 +33,0 @@ onShowMessage(handler: NotificationHandler<ShowMessageParams>): void;

@@ -34,4 +34,2 @@ "use strict";

initialize: (params) => connection.sendRequest(protocol_1.InitializeRequest.type, params),
shutdown: () => connection.sendRequest(protocol_1.ShutdownRequest.type, undefined),
exit: () => connection.sendNotification(protocol_1.ExitNotification.type),
onLogMessage: (handler) => connection.onNotification(protocol_1.LogMessageNotification.type, handler),

@@ -38,0 +36,0 @@ onShowMessage: (handler) => connection.onNotification(protocol_1.ShowMessageNotification.type, handler),

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

const sendToUpstream = [];
const repo = new TestRepoHandler("a", {
const repo = new TestRepoHandler(undefined, "a", {
remotePath: "oa",

@@ -189,2 +189,5 @@ sendToUpstream: (params) => {

class TestWorkspaceHandler extends handler_1.AbstractWorkspaceHandler {
constructor(path, opt, workspace, workRef) {
super(undefined, path, opt, workspace, workRef);
}
afterRefUpdate(ref, params) {

@@ -191,0 +194,0 @@ return super.afterRefUpdate(ref, params, undefined);

@@ -8,3 +8,2 @@ import { RequestType, Emitter, Event } from "vscode-jsonrpc";

export interface IRemoteClient {
onReady(): Promise<void>;
sendRequest<P, R, E, RO>(type: RequestType<P, R, E, RO>, params?: P): Thenable<R>;

@@ -38,8 +37,8 @@ }

export declare class RepoHandler implements IRepoHandler {
protected client: IRemoteClient | undefined;
readonly path: string;
protected client?: IRemoteClient;
readonly remotePath?: string;
readonly sendToUpstream?: (params: RefUpdateUpstreamParams) => void;
readonly refdb: RefDB;
constructor(path: string, opt: RepoCreationOptions);
constructor(client: IRemoteClient | undefined, path: string, opt: RepoCreationOptions);
dispose(): void;

@@ -55,3 +54,3 @@ onRefUpdateFromUpstream(params: RefUpdateDownstreamParams): Thenable<void>;

protected _workRef: string;
constructor(path: string, opt: RepoCreationOptions, workspace: Workspace, _workRef?: string);
constructor(client: IRemoteClient | undefined, path: string, opt: RepoCreationOptions, workspace: Workspace, _workRef?: string);
dispose(): void;

@@ -73,3 +72,3 @@ onDidAddRepo(): Thenable<void>;

protected readonly client: IRemoteClient;
constructor(path: string, opt: RepoCreationOptions, workspace: Workspace);
constructor(client: IRemoteClient | undefined, path: string, opt: RepoCreationOptions, workspace: Workspace);
initializeConnection(client: IRemoteClient): Promise<void>;

@@ -87,3 +86,3 @@ onDidAddRepo(): Thenable<void>;

_workRef: string;
constructor(path: string, opt: RepoCreationOptions, workspace: Workspace, workRef: Ref | NewRef);
constructor(client: IRemoteClient | undefined, path: string, opt: RepoCreationOptions, workspace: Workspace, workRef: Ref | NewRef);
private getCurrentBranch();

@@ -90,0 +89,0 @@ create(ref: string | undefined, overwrite: boolean): Thenable<WorkspaceBranchCreateResult>;

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

if (repo) {
throw new Error(`repo ${repoPath} already exists`);
return Promise.reject(`repo ${repoPath} already exists`);
}

@@ -62,5 +62,3 @@ const opt = {

const stack = new Error().stack;
this.client.onReady().then(() => {
return this.client.sendRequest(protocol_1.RefUpdateUpstreamRequest.type, Object.assign({}, params, { repo: repoPath }));
}).then(() => { }, err => { console.error(`ERROR: sending failed with ${err}: ${JSON.stringify(params)} - at ${stack}`); });
this.client.sendRequest(protocol_1.RefUpdateUpstreamRequest.type, Object.assign({}, params, { repo: repoPath })).then(() => { }, err => { console.error(`ERROR: sending failed with ${err}: ${JSON.stringify(params)} - at ${stack}`); });
} : undefined,

@@ -71,3 +69,3 @@ };

if (workRef) {
repo = new StandaloneWorkspaceHandler(repoPath, opt, workspace, workRef);
repo = new StandaloneWorkspaceHandler(this.client, repoPath, opt, workspace, workRef);
}

@@ -78,3 +76,3 @@ else {

}
repo = new LocalServerWorkspaceHandler(repoPath, opt, workspace);
repo = new LocalServerWorkspaceHandler(this.client, repoPath, opt, workspace);
if (addToLocalServer) {

@@ -86,3 +84,3 @@ p = repo.startSync();

else {
repo = new RepoHandler(repoPath, opt);
repo = new RepoHandler(this.client, repoPath, opt);
}

@@ -95,3 +93,2 @@ this.repodb.set(repo.path, repo);

if (this.client) {
yield this.client.onReady();
yield repo.initializeConnection(this.client);

@@ -104,9 +101,7 @@ }

onDidConnectToRemote() {
return this.client.onReady().then(() => {
const responses = [];
for (const repo of this.repodb.values()) {
responses.push(repo.initializeConnection(this.client));
}
return Promise.all(responses);
}).then(() => void 0);
const responses = [];
for (const repo of this.repodb.values()) {
responses.push(repo.initializeConnection(this.client));
}
return Promise.all(responses);
}

@@ -117,3 +112,4 @@ }

class RepoHandler {
constructor(path, opt) {
constructor(client, path, opt) {
this.client = client;
this.path = path;

@@ -172,4 +168,4 @@ this.refdb = new ref_1.RefDB(this.path);

class AbstractWorkspaceHandler extends RepoHandler {
constructor(path, opt, workspace, _workRef) {
super(path, opt);
constructor(client, path, opt, workspace, _workRef) {
super(client, path, opt);
this.workspace = workspace;

@@ -275,4 +271,4 @@ this._workRef = _workRef;

class LocalServerWorkspaceHandler extends AbstractWorkspaceHandler {
constructor(path, opt, workspace) {
super(path, opt, workspace, undefined);
constructor(client, path, opt, workspace) {
super(client, path, opt, workspace, undefined);
}

@@ -294,5 +290,3 @@ initializeConnection(client) {

onWorkspaceWillSaveFile(params) {
return this.client.onReady().then(() => {
return this.client.sendRequest(protocol_1.WorkspaceWillSaveFileRequest.type, params).then(() => { }, (err) => console.error(`ERROR: workspace/willSaveFile ${JSON.stringify(params)} failed: ${err}`));
});
return this.client.sendRequest(protocol_1.WorkspaceWillSaveFileRequest.type, params).then(() => { }, (err) => console.error(`ERROR: workspace/willSaveFile ${JSON.stringify(params)} failed: ${err}`));
}

@@ -334,4 +328,4 @@ create(ref, overwrite) {

class StandaloneWorkspaceHandler extends AbstractWorkspaceHandler {
constructor(path, opt, workspace, workRef) {
super(path, opt, workspace, workRef.name);
constructor(client, path, opt, workspace, workRef) {
super(client, path, opt, workspace, workRef.name);
if (workRef.state) {

@@ -338,0 +332,0 @@ let ref = this.refdb.lookup(workRef.name);

@@ -1,2 +0,2 @@

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

@@ -56,3 +56,2 @@ import { BranchName } from "../ref";

export interface InitializeError {
retry: boolean;
}

@@ -64,8 +63,2 @@ export interface InitializedParams {

}
export declare namespace ShutdownRequest {
const type: RequestType0<void, void, void>;
}
export declare namespace ExitNotification {
const type: NotificationType0<void>;
}
export declare namespace DidChangeConfigurationNotification {

@@ -152,3 +145,2 @@ const type: NotificationType<DidChangeConfigurationParams, void>;

export interface RepoConfiguration {
workspace?: WorkspaceConfiguration;
remotes?: {

@@ -215,11 +207,2 @@ [remote: string]: RepoRemoteConfiguration;

}
export interface WorkspaceConfiguration {
}
export interface WorkspaceConfigureParams extends WorkspaceIdentifier, WorkspaceConfiguration {
}
export interface WorkspaceConfigureResult {
}
export declare namespace WorkspaceConfigureRequest {
const type: RequestType<WorkspaceConfigureParams, WorkspaceConfigureResult, any, void>;
}
export interface WorkspaceBranchCreateParams extends WorkspaceIdentifier {

@@ -226,0 +209,0 @@ branch?: BranchName;

@@ -43,10 +43,2 @@ "use strict";

})(InitializedNotification = exports.InitializedNotification || (exports.InitializedNotification = {}));
var ShutdownRequest;
(function (ShutdownRequest) {
ShutdownRequest.type = new vscode_jsonrpc_1.RequestType0("shutdown");
})(ShutdownRequest = exports.ShutdownRequest || (exports.ShutdownRequest = {}));
var ExitNotification;
(function (ExitNotification) {
ExitNotification.type = new vscode_jsonrpc_1.NotificationType0("exit");
})(ExitNotification = exports.ExitNotification || (exports.ExitNotification = {}));
var DidChangeConfigurationNotification;

@@ -129,6 +121,2 @@ (function (DidChangeConfigurationNotification) {

})(WorkspaceRemoveRequest = exports.WorkspaceRemoveRequest || (exports.WorkspaceRemoveRequest = {}));
var WorkspaceConfigureRequest;
(function (WorkspaceConfigureRequest) {
WorkspaceConfigureRequest.type = new vscode_jsonrpc_1.RequestType("workspace/configure");
})(WorkspaceConfigureRequest = exports.WorkspaceConfigureRequest || (exports.WorkspaceConfigureRequest = {}));
var WorkspaceBranchCreateRequest;

@@ -135,0 +123,0 @@ (function (WorkspaceBranchCreateRequest) {

{
"name": "libzap",
"version": "1.0.9",
"version": "1.0.10",
"description": "JavaScript library for Zap",

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

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

return new Client("testClient", serverOptions, {})
.start().initialStart.then(() => {
.connection().then(() => {
assert.ok(ok, "server did not receive 'initialize' from client");

@@ -20,0 +20,0 @@ }, (err) => assert.ifError(err));

import * as is from "../util/is";
import { CancellationToken, Disposable, Emitter, Event, GenericNotificationHandler, GenericRequestHandler, Logger, Message, MessageReader, MessageType as RPCMessageType, MessageWriter, NotificationHandler, NotificationHandler0, NotificationType, NotificationType0, RequestHandler, RequestHandler0, RequestType, RequestType0, ResponseError, Trace, Tracer } from "vscode-jsonrpc";
import { CancellationToken, Emitter, Event, GenericNotificationHandler, GenericRequestHandler, Logger, Message, MessageReader, MessageType as RPCMessageType, MessageWriter, NotificationHandler, NotificationHandler0, NotificationType, NotificationType0, RequestHandler, RequestHandler0, RequestType, RequestType0, ResponseError, Trace, Tracer } from "vscode-jsonrpc";
/// import { extractSettingsInformation } from "./config";
import { ConsoleLogger, IConnection, createConnection } from "./connection";
import { InitializeParams, InitializeResult, InitializedNotification, MessageType, ServerCapabilities, ShowMessageRequest } from "./protocol";
import { InitializeParams, InitializedNotification, MessageType, ServerCapabilities, ShowMessageRequest } from "./protocol";
const alert = (message: string): void => { console.log("ALERT:", message); };
const confirm = (message: string): boolean => { console.log("CONFIRM:", message); return false; };

@@ -20,32 +18,19 @@ export interface MessageStream {

export interface Configuration {
}
export interface ClientOptions {
configuration?: Configuration;
initializationOptions?: any | (() => any);
errorHandler?: ErrorHandler;
logger?: Logger;
/**
* The number of milliseconds between reconnection attempts.
* Should be low for native extension and higher for sourcegraph.com.
* Defaults to 500ms
*/
connectionRetryInterval?: number;
}
export enum State {
Initial = 0,
Stopped = 1,
Running = 2,
On = 0,
Off = 1,
}
export interface StateChangeEvent {
oldState: State;
newState: State;
}
enum ClientState {
Initial,
Starting,
StartFailed,
Running,
Stopping,
Stopped,
}
export interface FeatureHandler {

@@ -63,16 +48,8 @@ register(connection: IConnection): void;

private _state: ClientState;
private readyPromise: Promise<void>;
private readyPromiseCallbacks: { resolve: () => void; reject: (error: any) => void; };
private _state = State.Off;
private connectionPromise: Thenable<IConnection> | undefined;
private resolvedConnection: IConnection | undefined;
private capabilities: ServerCapabilities;
private configuration: Configuration;
private listeners: Disposable[] | undefined;
private providers: Disposable[] | undefined;
private stateChangeEmitter = new Emitter<State>();
private telemetryEmitter: Emitter<any>;
private stateChangeEmitter: Emitter<StateChangeEvent>;
private logger: Logger;

@@ -83,3 +60,3 @@

public constructor(id: string, serverOptions: ServerOptions, clientOptions: ClientOptions) {
public constructor(id: string, serverOptions: ServerOptions, clientOptions?: ClientOptions) {
this.id = id;

@@ -89,18 +66,4 @@ this.name = id;

this.clientOptions = clientOptions || {};
this.clientOptions.errorHandler = this.clientOptions.errorHandler || new DefaultErrorHandler(this.name);
this.configuration = clientOptions.configuration || {};
this.stateChangeEmitter = new Emitter<StateChangeEvent>();
this.state = ClientState.Initial;
this.connectionPromise = undefined;
this.resolvedConnection = undefined;
this.listeners = undefined;
this.providers = undefined;
this.readyPromise = new Promise<void>((resolve, reject) => {
this.readyPromiseCallbacks = { resolve, reject };
});
this.logger = this.clientOptions.logger || new ConsoleLogger();
this.telemetryEmitter = new Emitter<any>();
this.tracer = {

@@ -113,25 +76,2 @@ log: (message: string, data?: string) => {

private get state(): ClientState {
return this._state;
}
private set state(value: ClientState) {
let oldState = this.getPublicState();
this._state = value;
let newState = this.getPublicState();
if (newState !== oldState) {
this.stateChangeEmitter.fire({ oldState, newState });
}
}
private getPublicState(): State {
if (this.state === ClientState.Initial) {
return State.Initial;
} else if (this.state === ClientState.Running) {
return State.Running;
} else {
return State.Stopped;
}
}
public sendRequest<R, E, RO>(type: RequestType0<R, E, RO>, token?: CancellationToken): Thenable<R>;

@@ -142,7 +82,4 @@ public sendRequest<P, R, E, RO>(type: RequestType<P, R, E, RO>, params: P, token?: CancellationToken): Thenable<R>;

public sendRequest<R>(type: string | RPCMessageType, ...params: any[]): Thenable<R> {
if (!this.isConnectionActive()) {
throw new Error("Zap client is not ready yet");
}
try {
return this.resolvedConnection!.sendRequest<R>(type, ...params);
return this.connection().then(connection => connection.sendRequest<R>(type, ...params));
} catch (error) {

@@ -158,7 +95,4 @@ this.logErrorData(`Sending request ${is.string(type) ? type : type.method} failed.`, error);

public onRequest<R, E>(type: string | RPCMessageType, handler: GenericRequestHandler<R, E>): void {
if (!this.isConnectionActive()) {
throw new Error("Zap client is not ready yet");
}
try {
this.resolvedConnection!.onRequest(type, handler);
this.connection().then(connection => connection.onRequest(type, handler));
} catch (error) {

@@ -175,7 +109,4 @@ this.logErrorData(`Registering request handler ${is.string(type) ? type : type.method} failed.`, error);

public sendNotification<P>(type: string | RPCMessageType, params?: P): void {
if (!this.isConnectionActive()) {
throw new Error("Zap client is not ready yet");
}
try {
this.resolvedConnection!.sendNotification(type, params);
this.connection().then(connection => connection.sendNotification(type, params));
} catch (error) {

@@ -191,7 +122,4 @@ this.logErrorData(`Sending notification ${is.string(type) ? type : type.method} failed.`, error);

public onNotification(type: string | RPCMessageType, handler: GenericNotificationHandler): void {
if (!this.isConnectionActive()) {
throw new Error("Zap client is not ready yet");
}
try {
this.resolvedConnection!.onNotification(type, handler);
this.connection().then(connection => connection.onNotification(type, handler));
} catch (error) {

@@ -203,7 +131,8 @@ this.logErrorData(`Registering notification handler ${is.string(type) ? type : type.method} failed.`, error);

public get onTelemetry(): Event<any> {
return this.telemetryEmitter.event;
private set state(state: State) {
this._state = state;
this.stateChangeEmitter.fire(state);
}
public get onDidChangeState(): Event<StateChangeEvent> {
public get onDidChangeState(): Event<State> {
return this.stateChangeEmitter.event;

@@ -214,114 +143,117 @@ }

this._trace = value;
this.onReady().then(() => {
this.resolveConnection().then((connection) => {
connection.trace(value, this.tracer);
});
this.connection().then(connection => {
connection.trace(value, this.tracer);
}, () => { /* noop */ });
}
public needsStart(): boolean {
return this.state === ClientState.Initial || this.state === ClientState.Stopping || this.state === ClientState.Stopped;
public dispose(): void {
if (this.connectionPromise) {
this.connectionPromise.then(connection => {
connection.dispose();
}, () => { /* noop */ });
}
}
public needsStop(): boolean {
return this.state === ClientState.Starting || this.state === ClientState.Running;
/**
* Returns a promise for the active connection.
* It will try to establish a new connection if one does not already exist.
* Usually a connection should already exist since the client continuously tries to reconnect.
* There is only one active connection at any given point in time.
*/
public connection(): Thenable<IConnection> {
if (this.connectionPromise) {
// A connection has already been established, or is in progress.
return this.connectionPromise;
}
// A connection has not been established (or we got disconnected).
// Create a new connection and save the promise so future calls to connect
// will get the same connection.
this.connectionPromise = this.createConnection().then(
connection => connection,
error => {
// Unset the connection promise so the next call to connection() creates a new connection.
this.connectionPromise = undefined;
this.retryConnect();
// Bubble the error
return Promise.reject(error);
},
);
return this.connectionPromise;
}
public onReady(): Promise<void> {
return this.readyPromise;
/**
* Attempts to reconnect after a delay.
*/
private retryConnect(): void {
// Try to automatically reconnect.
const delay = this.clientOptions.connectionRetryInterval || 500;
setTimeout(() => {
this.connect();
}, delay);
}
private isConnectionActive(): boolean {
return this.state === ClientState.Running && !!this.resolvedConnection;
/**
* Initiates a connection to the server if one doesn't already exist.
* Errors are silently ignored.
* If you care about errors, call `this.connection` directly.
*/
public connect(): void {
this.connection().then(() => { /* noop */ }, () => { /* noop */ });
}
public start(): { disposable: Disposable, initialStart: Thenable<void> } {
this.listeners = [];
this.providers = [];
if (!this.needsStart()) {
throw new Error("!needsStart()");
}
this.state = ClientState.Starting;
const initialStart = this.resolveConnection().then((connection) => {
connection.onLogMessage((message) => {
switch (message.type) {
case MessageType.Error:
this.logger.error(message.message);
break;
case MessageType.Warning:
this.logger.warn(message.message);
break;
case MessageType.Info:
this.logger.info(message.message);
break;
default:
this.logger.info(message.message);
}
});
connection.onShowMessage((message) => {
switch (message.type) {
case MessageType.Error:
alert(message.message);
break;
case MessageType.Warning:
alert(message.message);
break;
case MessageType.Info:
alert(message.message);
break;
default:
alert(message.message);
}
});
connection.onRequest(ShowMessageRequest.type, (params) => {
const alert2 = (message: string) => { alert(message); return Promise.resolve(); };
let messageFunc: (message: string) => Thenable<void>;
switch (params.type) {
case MessageType.Error:
messageFunc = alert2;
break;
case MessageType.Warning:
messageFunc = alert2;
break;
case MessageType.Info:
messageFunc = alert2;
break;
default:
messageFunc = alert2;
}
let actions = params.actions || [];
return messageFunc(`${params.message}: ${JSON.stringify(actions)}`);
});
connection.onTelemetry((data) => {
this.telemetryEmitter.fire(data);
});
connection.listen();
return this.initialize(connection);
}, (error) => {
this.state = ClientState.StartFailed;
this.readyPromiseCallbacks.reject(error);
this.logErrorData("Starting client failed", error);
alert(`Couldn't start ${this.name} client`);
return error;
private attachHandlers(connection: IConnection) {
connection.onLogMessage((message) => {
switch (message.type) {
case MessageType.Error:
this.logger.error(message.message);
break;
case MessageType.Warning:
this.logger.warn(message.message);
break;
case MessageType.Info:
this.logger.info(message.message);
break;
default:
this.logger.info(message.message);
}
});
return {
initialStart: initialStart.then(() => void 0),
disposable: Disposable.create(() => {
if (this.needsStop()) {
this.stop();
}
}),
};
connection.onShowMessage((message) => {
switch (message.type) {
case MessageType.Error:
alert(message.message);
break;
case MessageType.Warning:
alert(message.message);
break;
case MessageType.Info:
alert(message.message);
break;
default:
alert(message.message);
}
});
connection.onRequest(ShowMessageRequest.type, (params) => {
const alert2 = (message: string) => { alert(message); return Promise.resolve(); };
let messageFunc: (message: string) => Thenable<void>;
switch (params.type) {
case MessageType.Error:
messageFunc = alert2;
break;
case MessageType.Warning:
messageFunc = alert2;
break;
case MessageType.Info:
messageFunc = alert2;
break;
default:
messageFunc = alert2;
}
let actions = params.actions || [];
return messageFunc(`${params.message}: ${JSON.stringify(actions)}`);
});
}
private resolveConnection(): Thenable<IConnection> {
if (!this.connectionPromise) {
this.connectionPromise = this.createConnection();
}
return this.connectionPromise;
}
private initialize(connection: IConnection): Thenable<InitializeResult> {
private initialize(connection: IConnection): Thenable<void> {
let initOption = this.clientOptions.initializationOptions;

@@ -335,128 +267,37 @@ let initParams: InitializeParams = {

return connection.initialize(initParams).then((result) => {
this.resolvedConnection = connection;
this.state = ClientState.Running;
/// this.trace = Trace.Verbose;
this.capabilities = result.capabilities || {};
this.hookCapabilities(connection);
connection.sendNotification(InitializedNotification.type, {});
this.hookCapabilities(connection);
this.readyPromiseCallbacks.resolve();
return result;
}, (error: any) => {
if (error instanceof ResponseError && error.data && error.data.retry) {
if (confirm("Retry?")) {
this.initialize(connection);
} else {
this.stop();
this.readyPromiseCallbacks.reject(error);
}
/// Window.showErrorMessage(error.message, { title: "Retry", id: "retry" }).then(item => {
/// if (item && item.id === "retry") {
/// this.initialize(connection);
/// } else {
/// this.stop();
/// this._onReadyCallbacks.reject(error);
/// }
/// });
} else {
if (error && error.message) {
alert(error.message);
}
this.logErrorData("Server initialization failed.", error);
this.stop();
this.readyPromiseCallbacks.reject(error);
}
});
}
/**
* clearStartFailedState clears the StartFailed state so that
* future calls to start() will initiate a new connection.
*/
public clearStartFailedState(): Thenable<void> {
if (this.state === ClientState.StartFailed) {
this.state = ClientState.Initial;
return this.stop();
}
return Promise.resolve();
}
public stop(): Thenable<void> {
if (!this.connectionPromise) {
this.state = ClientState.Stopped;
return Promise.resolve();
}
this.state = ClientState.Stopping;
this.cleanUp();
return this.resolveConnection().then(connection => {
return connection.shutdown().then(() => {
connection.exit();
connection.dispose();
});
}, () => { /* noop; have already logged/returned error */ }).then(() => {
this.state = ClientState.Stopped;
this.connectionPromise = undefined;
this.resolvedConnection = undefined;
});
}
private cleanUp(): void {
if (this.listeners) {
this.listeners.forEach(listener => listener.dispose());
this.listeners = undefined;
}
if (this.providers) {
this.providers.forEach(provider => provider.dispose());
this.providers = undefined;
}
}
private createConnection(): Thenable<IConnection> {
const errorHandler = (err: Error, message: Message, count: number): void => {
this.handleConnectionError(err, message, count);
this.logger.error(`connection error ${err} message ${message} count ${count}`);
};
const closeHandler = () => this.handleConnectionClosed();
return this.serverOptions.connect()
.then(({ reader, writer }) => createConnection(reader, writer, errorHandler, closeHandler));
const closeHandler = () => {
this.logger.log(`connection closed`);
this.connectionPromise = undefined;
this.state = State.Off;
this.retryConnect();
};
return this.serverOptions.connect().then(({ reader, writer }) => {
const connection = createConnection(reader, writer, errorHandler, closeHandler);
this.attachHandlers(connection);
connection.listen();
return this.initialize(connection).then(() => {
this.state = State.On;
return connection;
});
}).then(v => v, error => Promise.reject(`Unable to connect to local Zap server: ${error}`));
}
private handleConnectionClosed() {
// Check whether this is a normal shutdown in progress or the client stopped normally.
if (this.state === ClientState.Stopping || this.state === ClientState.Stopped) {
return;
}
if (this.resolvedConnection) { this.resolvedConnection.dispose(); }
this.connectionPromise = undefined;
this.resolvedConnection = undefined;
let action = this.clientOptions.errorHandler!.closed();
if (action === CloseAction.DoNotRestart) {
this.logger.error("Connection to server got closed. Server will not be restarted.");
this.state = ClientState.Stopped;
this.cleanUp();
} else if (action === CloseAction.Restart) {
this.logger.info("Connection to server got closed. Server will restart.");
this.cleanUp();
this.state = ClientState.Initial;
this.start();
}
}
private registeredHandlers = new Map<string, FeatureHandler>();
private handleConnectionError(error: Error, message: Message, count: number) {
let action = this.clientOptions.errorHandler!.error(error, message, count);
if (action === ErrorAction.Shutdown) {
this.logger.error("Connection to server is erroring. Shutting down server.");
this.stop();
}
}
private _registeredHandlers: Map<string, FeatureHandler> = new Map();
public registerHandler(id: string, handler: FeatureHandler): void {
if (this._registeredHandlers.has(id)) {
if (this.registeredHandlers.has(id)) {
throw new Error(`handler already registered with id ${id}`);
}
this._registeredHandlers.set(id, handler);
this.registeredHandlers.set(id, handler);
}

@@ -467,4 +308,4 @@

if (this.capabilities.workspaceOperationalTransformation) {
this._registeredHandlers.forEach((handler: FeatureHandler) => {
handler!.register(connection);
this.registeredHandlers.forEach((handler: FeatureHandler) => {
handler.register(connection);
});

@@ -476,6 +317,2 @@ } else {

protected logFailedRequest(type: RPCMessageType, error: any): void {
this.logErrorData(`Request ${type.method} failed.`, error);
}
private logErrorData(message: string, data: any): void {

@@ -514,77 +351,1 @@ if (data) {

}
/**
* A pluggable error handler that is invoked when the connection is either
* producing errors or got closed.
*/
export interface ErrorHandler {
/**
* An error has occurred while writing or reading from the connection.
*
* @param error - the error received
* @param message - the message to be delivered to the server if know.
* @param count - a count indicating how often an error is received. Will
* be reset if a message got successfully send or received.
*/
error(error: Error, message: Message, count: number): ErrorAction;
/**
* The connection to the server got closed.
*/
closed(): CloseAction;
}
export enum ErrorAction {
/**
* Continue running the server.
*/
Continue = 1,
/**
* Shutdown the server.
*/
Shutdown = 2,
}
/**
* An action to be performed when the connection to a server got closed.
*/
export enum CloseAction {
/**
* Don't restart the server. The connection stays closed.
*/
DoNotRestart = 1,
/**
* Restart the server.
*/
Restart = 2,
}
class DefaultErrorHandler implements ErrorHandler {
private restarts: number[];
constructor(private name: string) {
this.restarts = [];
}
public error(_error: Error, _message: Message, count: number): ErrorAction {
if (count && count <= 3) {
return ErrorAction.Continue;
}
return ErrorAction.Shutdown;
}
public closed(): CloseAction {
this.restarts.push(Date.now());
if (this.restarts.length < 5) {
return CloseAction.Restart;
} else {
let diff = this.restarts[this.restarts.length - 1] - this.restarts[0];
if (diff <= 3 * 1000) {
alert(`The ${this.name} server crashed 5 times in the last 3 seconds. The server will not be restarted.`);
return CloseAction.DoNotRestart;
} else {
this.restarts.shift();
return CloseAction.Restart;
}
}
}
}

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

import {
DidChangeConfigurationNotification, DidChangeConfigurationParams, ExitNotification, InitializeParams, InitializeRequest, InitializeResult, LogMessageNotification, LogMessageParams, ShowMessageNotification, ShowMessageParams, ShutdownRequest, TelemetryEventNotification,
DidChangeConfigurationNotification, DidChangeConfigurationParams, InitializeParams, InitializeRequest, InitializeResult, LogMessageNotification, LogMessageParams, ShowMessageNotification, ShowMessageParams, TelemetryEventNotification,
} from "./protocol";

@@ -54,4 +54,2 @@

initialize(params: InitializeParams): Thenable<InitializeResult>;
shutdown(): Thenable<void>;
exit(): void;

@@ -93,4 +91,2 @@ onLogMessage(handle: NotificationHandler<LogMessageParams>): void;

initialize: (params: InitializeParams) => connection.sendRequest(InitializeRequest.type, params),
shutdown: () => connection.sendRequest(ShutdownRequest.type, undefined),
exit: () => connection.sendNotification(ExitNotification.type),

@@ -97,0 +93,0 @@ onLogMessage: (handler: NotificationHandler<LogMessageParams>) => connection.onNotification(LogMessageNotification.type, handler),

import * as assert from "assert";
import { RefDB } from "../ref";
import { AbstractWorkspaceHandler, Handler, RepoHandler, IRepoHandler, IRemoteClient } from "./handler";
import { AbstractWorkspaceHandler, Handler, RepoHandler, IRepoHandler, IRemoteClient, RepoCreationOptions } from "./handler";
import { WorkspaceStatusResult, WorkspaceStatusRequest, WorkspaceBranchSetResult, WorkspaceBranchCreateResult, WorkspaceWillSaveFileParams, RefUpdateDownstreamParams, RefUpdateUpstreamParams } from "./protocol";

@@ -177,3 +177,3 @@ import { Source, RefUpdate } from "./refState";

const sendToUpstream: RefUpdateUpstreamParams[] = [];
const repo = new TestRepoHandler("a", {
const repo = new TestRepoHandler(undefined, "a", {
remotePath: "oa",

@@ -217,2 +217,12 @@ sendToUpstream: (params: RefUpdateUpstreamParams): void => {

class TestWorkspaceHandler extends AbstractWorkspaceHandler {
constructor(
path: string,
opt: RepoCreationOptions,
workspace: Workspace,
workRef?: string, // only known at constructor call time for StandaloneWorkspaceHandler
) {
super(undefined, path, opt, workspace, workRef);
}
public afterRefUpdate(ref: Ref, params: RefUpdate): Thenable<void> {

@@ -219,0 +229,0 @@ return super.afterRefUpdate(ref, params, undefined);

@@ -11,3 +11,2 @@ import { RequestType, Emitter, Event } from "vscode-jsonrpc";

export interface IRemoteClient {
onReady(): Promise<void>;
sendRequest<P, R, E, RO>(type: RequestType<P, R, E, RO>, params?: P): Thenable<R>;

@@ -77,3 +76,3 @@ }

if (repo) {
throw new Error(`repo ${repoPath} already exists`);
return Promise.reject(`repo ${repoPath} already exists`);
}

@@ -91,5 +90,3 @@

// TODO(sqs8) TODO(sqs8!): make this use a queue instead of deferred callbacks (who knows what order they'll run in)
this.client!.onReady().then(() => {
return this.client!.sendRequest(RefUpdateUpstreamRequest.type, { ...params, repo: repoPath /* TODO(sqs8): use remote repo path */ });
}).then(
this.client!.sendRequest(RefUpdateUpstreamRequest.type, { ...params, repo: repoPath /* TODO(sqs8): use remote repo path */ }).then(
() => { /* noop */ },

@@ -103,3 +100,3 @@ err => { console.error(`ERROR: sending failed with ${err}: ${JSON.stringify(params)} - at ${stack}`); },

if (workRef) {
repo = new StandaloneWorkspaceHandler(repoPath, opt, workspace, workRef);
repo = new StandaloneWorkspaceHandler(this.client, repoPath, opt, workspace, workRef);
} else {

@@ -109,9 +106,9 @@ if (!this.client) {

}
repo = new LocalServerWorkspaceHandler(repoPath, opt, workspace);
repo = new LocalServerWorkspaceHandler(this.client, repoPath, opt, workspace);
if (addToLocalServer) {
p = (repo as LocalServerWorkspaceHandler).startSync();
p = (repo as AbstractWorkspaceHandler).startSync();
}
}
} else {
repo = new RepoHandler(repoPath, opt);
repo = new RepoHandler(this.client, repoPath, opt);
}

@@ -124,4 +121,3 @@ this.repodb.set(repo.path, repo);

if (this.client) {
await this.client.onReady();
await repo.initializeConnection(this.client!);
await repo.initializeConnection(this.client);
}

@@ -136,10 +132,8 @@ await repo.onDidAddRepo();

*/
private onDidConnectToRemote(): Thenable<void> {
return this.client!.onReady().then(() => {
const responses: Thenable<void>[] = [];
for (const repo of this.repodb.values()) {
responses.push(repo.initializeConnection(this.client!));
}
return Promise.all(responses);
}).then(() => void 0);
private onDidConnectToRemote(): Thenable<void[]> {
const responses: Thenable<void>[] = [];
for (const repo of this.repodb.values()) {
responses.push(repo.initializeConnection(this.client!));
}
return Promise.all(responses);
}

@@ -182,3 +176,2 @@ }

export class RepoHandler implements IRepoHandler {
protected client?: IRemoteClient;
public readonly remotePath?: string;

@@ -190,2 +183,3 @@ public readonly sendToUpstream?: (params: RefUpdateUpstreamParams) => void;

constructor(
protected client: IRemoteClient | undefined,
public readonly path: string,

@@ -261,2 +255,3 @@ opt: RepoCreationOptions,

constructor(
client: IRemoteClient | undefined,
path: string,

@@ -267,3 +262,3 @@ opt: RepoCreationOptions,

) {
super(path, opt);
super(client, path, opt);
this._workRef = _workRef;

@@ -437,2 +432,3 @@ }

constructor(
client: IRemoteClient | undefined,
path: string,

@@ -442,3 +438,3 @@ opt: RepoCreationOptions,

) {
super(path, opt, workspace, undefined);
super(client, path, opt, workspace, undefined);
}

@@ -465,8 +461,6 @@

private onWorkspaceWillSaveFile(params: WorkspaceWillSaveFileParams): Thenable<void> {
return this.client.onReady().then(() => {
return this.client.sendRequest(WorkspaceWillSaveFileRequest.type, params).then(
() => { /* noop */ },
(err) => console.error(`ERROR: workspace/willSaveFile ${JSON.stringify(params)} failed: ${err}`),
);
});
return this.client.sendRequest(WorkspaceWillSaveFileRequest.type, params).then(
() => { /* noop */ },
(err) => console.error(`ERROR: workspace/willSaveFile ${JSON.stringify(params)} failed: ${err}`),
);
}

@@ -526,2 +520,3 @@

constructor(
client: IRemoteClient | undefined,
path: string,

@@ -532,3 +527,3 @@ opt: RepoCreationOptions,

) {
super(path, opt, workspace, workRef.name);
super(client, path, opt, workspace, workRef.name);

@@ -535,0 +530,0 @@ if (workRef.state) {

@@ -1,2 +0,2 @@

import { NotificationType, NotificationType0, RequestType, RequestType0 } from "vscode-jsonrpc";
import { NotificationType, RequestType } from "vscode-jsonrpc";

@@ -131,20 +131,2 @@ import { WorkspaceOp } from "../ot/workspace";

/**
* A shutdown request is sent from the client to the server.
* It is sent once when the client descides to shutdown the
* server. The only notification that is sent after a shudown request
* is the exit event.
*/
export namespace ShutdownRequest {
export const type = new RequestType0<void, void, void>("shutdown");
}
/**
* The exit event is sent from the client to the server to
* ask the server to exit its process.
*/
export namespace ExitNotification {
export const type = new NotificationType0<void>("exit");
}
/**
* The configuration change notification is sent from the client to the server

@@ -151,0 +133,0 @@ * when the client's configuration has changed. The notification contains

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