vscode-jsonrpc
Advanced tools
Comparing version 3.0.4 to 3.1.0-alpha.1
@@ -9,2 +9,3 @@ /// <reference path="thenable.d.ts" /> | ||
export { Message, MessageType, ErrorCodes, ResponseError, RequestMessage, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, MessageReader, DataCallback, StreamMessageReader, IPCMessageReader, MessageWriter, StreamMessageWriter, IPCMessageWriter, CancellationTokenSource, CancellationToken, Disposable, Event, Emitter }; | ||
export * from './pipeSupport'; | ||
export interface GenericRequestHandler<R, E> { | ||
@@ -11,0 +12,0 @@ (...params: any[]): R | ResponseError<E> | Thenable<R> | Thenable<ResponseError<E>>; |
@@ -12,2 +12,5 @@ /* -------------------------------------------------------------------------------------------- | ||
}; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var is = require("./is"); | ||
@@ -52,2 +55,3 @@ var messages_1 = require("./messages"); | ||
exports.CancellationToken = cancellation_1.CancellationToken; | ||
__export(require("./pipeSupport")); | ||
var CancelNotification; | ||
@@ -54,0 +58,0 @@ (function (CancelNotification) { |
/// <reference types="node" /> | ||
import { Socket } from 'net'; | ||
import { ChildProcess } from 'child_process'; | ||
@@ -51,1 +52,4 @@ import { Message } from './messages'; | ||
} | ||
export declare class SocketMessageReader extends StreamMessageReader { | ||
constructor(socket: Socket, encoding?: string); | ||
} |
@@ -28,4 +28,5 @@ /* -------------------------------------------------------------------------------------------- | ||
var str = chunk; | ||
toAppend = new Buffer(str.length); | ||
toAppend.write(str, 0, str.length, this.encoding); | ||
var bufferLen = Buffer.byteLength(str, this.encoding); | ||
toAppend = new Buffer(bufferLen); | ||
toAppend.write(str, 0, bufferLen, this.encoding); | ||
} | ||
@@ -241,1 +242,10 @@ if (this.buffer.length - this.index >= toAppend.length) { | ||
exports.IPCMessageReader = IPCMessageReader; | ||
var SocketMessageReader = (function (_super) { | ||
__extends(SocketMessageReader, _super); | ||
function SocketMessageReader(socket, encoding) { | ||
if (encoding === void 0) { encoding = 'utf-8'; } | ||
return _super.call(this, socket, encoding) || this; | ||
} | ||
return SocketMessageReader; | ||
}(StreamMessageReader)); | ||
exports.SocketMessageReader = SocketMessageReader; |
/// <reference types="node" /> | ||
import { ChildProcess } from 'child_process'; | ||
import { Socket } from 'net'; | ||
import { Message } from './messages'; | ||
@@ -29,5 +30,19 @@ import { Event } from './events'; | ||
private process; | ||
private queue; | ||
private sending; | ||
private errorCount; | ||
constructor(process: NodeJS.Process | ChildProcess); | ||
write(msg: Message): void; | ||
doWriteMessage(msg: Message): void; | ||
} | ||
export declare class SocketMessageWriter extends AbstractMessageWriter implements MessageWriter { | ||
private socket; | ||
private queue; | ||
private sending; | ||
private encoding; | ||
private errorCount; | ||
constructor(socket: Socket, encoding?: string); | ||
write(msg: Message): void; | ||
doWriteMessage(msg: Message): void; | ||
private handleError(error, msg); | ||
} |
@@ -91,2 +91,4 @@ /* -------------------------------------------------------------------------------------------- | ||
_this.errorCount = 0; | ||
_this.queue = []; | ||
_this.sending = false; | ||
var eventEmitter = _this.process; | ||
@@ -98,6 +100,28 @@ eventEmitter.on('error', function (error) { return _this.fireError(error); }); | ||
IPCMessageWriter.prototype.write = function (msg) { | ||
if (!this.sending && this.queue.length === 0) { | ||
// See https://github.com/nodejs/node/issues/7657 | ||
this.doWriteMessage(msg); | ||
} | ||
else { | ||
this.queue.push(msg); | ||
} | ||
}; | ||
IPCMessageWriter.prototype.doWriteMessage = function (msg) { | ||
var _this = this; | ||
try { | ||
if (this.process.send) { | ||
this.process.send(msg); | ||
this.errorCount = 0; | ||
this.sending = true; | ||
this.process.send(msg, undefined, undefined, function (error) { | ||
_this.sending = false; | ||
if (error) { | ||
_this.errorCount++; | ||
_this.fireError(error, msg, _this.errorCount); | ||
} | ||
else { | ||
_this.errorCount = 0; | ||
} | ||
if (_this.queue.length > 0) { | ||
_this.doWriteMessage(_this.queue.shift()); | ||
} | ||
}); | ||
} | ||
@@ -113,1 +137,70 @@ } | ||
exports.IPCMessageWriter = IPCMessageWriter; | ||
var SocketMessageWriter = (function (_super) { | ||
__extends(SocketMessageWriter, _super); | ||
function SocketMessageWriter(socket, encoding) { | ||
if (encoding === void 0) { encoding = 'utf8'; } | ||
var _this = _super.call(this) || this; | ||
_this.socket = socket; | ||
_this.queue = []; | ||
_this.sending = false; | ||
_this.encoding = encoding; | ||
_this.errorCount = 0; | ||
_this.socket.on('error', function (error) { return _this.fireError(error); }); | ||
_this.socket.on('close', function () { return _this.fireClose(); }); | ||
return _this; | ||
} | ||
SocketMessageWriter.prototype.write = function (msg) { | ||
if (!this.sending && this.queue.length === 0) { | ||
// See https://github.com/nodejs/node/issues/7657 | ||
this.doWriteMessage(msg); | ||
} | ||
else { | ||
this.queue.push(msg); | ||
} | ||
}; | ||
SocketMessageWriter.prototype.doWriteMessage = function (msg) { | ||
var _this = this; | ||
var json = JSON.stringify(msg); | ||
var contentLength = Buffer.byteLength(json, this.encoding); | ||
var headers = [ | ||
ContentLength, contentLength.toString(), CRLF, | ||
CRLF | ||
]; | ||
try { | ||
// Header must be written in ASCII encoding | ||
this.sending = true; | ||
this.socket.write(headers.join(''), 'ascii', function (error) { | ||
if (error) { | ||
_this.handleError(error, msg); | ||
} | ||
try { | ||
// Now write the content. This can be written in any encoding | ||
_this.socket.write(json, _this.encoding, function (error) { | ||
_this.sending = false; | ||
if (error) { | ||
_this.handleError(error, msg); | ||
} | ||
else { | ||
_this.errorCount = 0; | ||
} | ||
if (_this.queue.length > 0) { | ||
_this.doWriteMessage(_this.queue.shift()); | ||
} | ||
}); | ||
} | ||
catch (error) { | ||
_this.handleError(error, msg); | ||
} | ||
}); | ||
} | ||
catch (error) { | ||
this.handleError(error, msg); | ||
} | ||
}; | ||
SocketMessageWriter.prototype.handleError = function (error, msg) { | ||
this.errorCount++; | ||
this.fireError(error, msg, this.errorCount); | ||
}; | ||
return SocketMessageWriter; | ||
}(AbstractMessageWriter)); | ||
exports.SocketMessageWriter = SocketMessageWriter; |
{ | ||
"name": "vscode-jsonrpc", | ||
"description": "A json rpc implementation over streams", | ||
"version": "3.0.4", | ||
"version": "3.1.0-alpha.1", | ||
"author": "Microsoft Corporation", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105691
23
2459
2
1