vscode-jsonrpc
Advanced tools
Comparing version 5.0.1 to 5.1.0-next.1
@@ -1,2 +0,2 @@ | ||
import { Event } from './events'; | ||
import { Disposable, Event } from './events'; | ||
/** | ||
@@ -22,3 +22,7 @@ * Defines a CancellationToken. This interface is not | ||
} | ||
export declare class CancellationTokenSource { | ||
export interface AbstractCancellationTokenSource extends Disposable { | ||
token: CancellationToken; | ||
cancel(): void; | ||
} | ||
export declare class CancellationTokenSource implements AbstractCancellationTokenSource { | ||
private _token; | ||
@@ -25,0 +29,0 @@ get token(): CancellationToken; |
@@ -100,2 +100,6 @@ /* -------------------------------------------------------------------------------------------- | ||
dispose: () => { | ||
if (!this._callbacks) { | ||
// disposable is disposed after emitter is disposed. | ||
return; | ||
} | ||
this._callbacks.remove(listener, thisArgs); | ||
@@ -102,0 +106,0 @@ result.dispose = Emitter._noop; |
@@ -7,5 +7,5 @@ /// <reference path="../typings/thenable.d.ts" /> | ||
import { Disposable, Event, Emitter } from './events'; | ||
import { CancellationTokenSource, CancellationToken } from './cancellation'; | ||
import { CancellationTokenSource, CancellationToken, AbstractCancellationTokenSource } from './cancellation'; | ||
import { LinkedMap } from './linkedMap'; | ||
export { Message, MessageType, ErrorCodes, ResponseError, RequestMessage, _EM, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, MessageReader, PartialMessageInfo, DataCallback, StreamMessageReader, IPCMessageReader, SocketMessageReader, MessageWriter, StreamMessageWriter, IPCMessageWriter, SocketMessageWriter, CancellationTokenSource, CancellationToken, Disposable, Event, Emitter }; | ||
export { Message, MessageType, ErrorCodes, ResponseError, RequestMessage, _EM, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, MessageReader, PartialMessageInfo, DataCallback, StreamMessageReader, IPCMessageReader, SocketMessageReader, MessageWriter, StreamMessageWriter, IPCMessageWriter, SocketMessageWriter, AbstractCancellationTokenSource, CancellationTokenSource, CancellationToken, Disposable, Event, Emitter }; | ||
export * from './pipeSupport'; | ||
@@ -180,2 +180,35 @@ export * from './socketSupport'; | ||
} | ||
export declare type CancellationId = number | string; | ||
export interface CancellationReceiverStrategy { | ||
createCancellationTokenSource(id: CancellationId): AbstractCancellationTokenSource; | ||
dispose?(): void; | ||
} | ||
export declare namespace CancellationReceiverStrategy { | ||
const Message: CancellationReceiverStrategy; | ||
function is(value: any): value is CancellationReceiverStrategy; | ||
} | ||
export interface CancellationSenderStrategy { | ||
sendCancellation(conn: MessageConnection, id: CancellationId): void; | ||
cleanup(id: CancellationId): void; | ||
dispose?(): void; | ||
} | ||
export declare namespace CancellationSenderStrategy { | ||
const Message: CancellationSenderStrategy; | ||
function is(value: any): value is CancellationSenderStrategy; | ||
} | ||
export interface CancellationStrategy { | ||
receiver: CancellationReceiverStrategy; | ||
sender: CancellationSenderStrategy; | ||
} | ||
export declare namespace CancellationStrategy { | ||
const Message: CancellationStrategy; | ||
function is(value: any): value is CancellationStrategy; | ||
} | ||
export interface ConnectionOptions { | ||
cancellationStrategy?: CancellationStrategy; | ||
connectionStrategy?: ConnectionStrategy; | ||
} | ||
export declare namespace ConnectionOptions { | ||
function is(value: any): value is ConnectionOptions; | ||
} | ||
export interface MessageConnection { | ||
@@ -245,3 +278,3 @@ sendRequest<R, E, RO>(type: RequestType0<R, E, RO>, token?: CancellationToken): Promise<R>; | ||
} | ||
export declare function createMessageConnection(reader: MessageReader, writer: MessageWriter, logger?: Logger, strategy?: ConnectionStrategy): MessageConnection; | ||
export declare function createMessageConnection(inputStream: NodeJS.ReadableStream, outputStream: NodeJS.WritableStream, logger?: Logger, strategy?: ConnectionStrategy): MessageConnection; | ||
export declare function createMessageConnection(reader: MessageReader, writer: MessageWriter, logger?: Logger, options?: ConnectionStrategy | ConnectionOptions): MessageConnection; | ||
export declare function createMessageConnection(inputStream: NodeJS.ReadableStream, outputStream: NodeJS.WritableStream, logger?: Logger, options?: ConnectionStrategy | ConnectionOptions): MessageConnection; |
@@ -170,2 +170,49 @@ /* -------------------------------------------------------------------------------------------- | ||
})(ConnectionStrategy = exports.ConnectionStrategy || (exports.ConnectionStrategy = {})); | ||
var CancellationReceiverStrategy; | ||
(function (CancellationReceiverStrategy) { | ||
CancellationReceiverStrategy.Message = Object.freeze({ | ||
createCancellationTokenSource(_) { | ||
return new cancellation_1.CancellationTokenSource(); | ||
} | ||
}); | ||
function is(value) { | ||
let candidate = value; | ||
return candidate && Is.func(candidate.createCancellationTokenSource); | ||
} | ||
CancellationReceiverStrategy.is = is; | ||
})(CancellationReceiverStrategy = exports.CancellationReceiverStrategy || (exports.CancellationReceiverStrategy = {})); | ||
var CancellationSenderStrategy; | ||
(function (CancellationSenderStrategy) { | ||
CancellationSenderStrategy.Message = Object.freeze({ | ||
sendCancellation(conn, id) { | ||
conn.sendNotification(CancelNotification.type, { id }); | ||
}, | ||
cleanup(_) { } | ||
}); | ||
function is(value) { | ||
let candidate = value; | ||
return candidate && Is.func(candidate.sendCancellation) && Is.func(candidate.cleanup); | ||
} | ||
CancellationSenderStrategy.is = is; | ||
})(CancellationSenderStrategy = exports.CancellationSenderStrategy || (exports.CancellationSenderStrategy = {})); | ||
var CancellationStrategy; | ||
(function (CancellationStrategy) { | ||
CancellationStrategy.Message = Object.freeze({ | ||
receiver: CancellationReceiverStrategy.Message, | ||
sender: CancellationSenderStrategy.Message | ||
}); | ||
function is(value) { | ||
let candidate = value; | ||
return candidate && CancellationReceiverStrategy.is(candidate.receiver) && CancellationSenderStrategy.is(candidate.sender); | ||
} | ||
CancellationStrategy.is = is; | ||
})(CancellationStrategy = exports.CancellationStrategy || (exports.CancellationStrategy = {})); | ||
var ConnectionOptions; | ||
(function (ConnectionOptions) { | ||
function is(value) { | ||
let candidate = value; | ||
return candidate && (CancellationStrategy.is(candidate.cancellationStrategy) || ConnectionStrategy.is(candidate.connectionStrategy)); | ||
} | ||
ConnectionOptions.is = is; | ||
})(ConnectionOptions = exports.ConnectionOptions || (exports.ConnectionOptions = {})); | ||
var ConnectionState; | ||
@@ -178,3 +225,3 @@ (function (ConnectionState) { | ||
})(ConnectionState || (ConnectionState = {})); | ||
function _createMessageConnection(messageReader, messageWriter, logger, strategy) { | ||
function _createMessageConnection(messageReader, messageWriter, logger, options) { | ||
let sequenceNumber = 0; | ||
@@ -202,2 +249,3 @@ let notificationSquenceNumber = 0; | ||
let disposeEmitter = new events_1.Emitter(); | ||
let cancellationStrategy = (options && options.cancellationStrategy) ? options.cancellationStrategy : CancellationStrategy.Message; | ||
function createRequestQueueKey(id) { | ||
@@ -290,2 +338,3 @@ return 'req-' + id.toString(); | ||
let callback = (message) => { | ||
var _a; | ||
try { | ||
@@ -298,3 +347,4 @@ // We have received a cancellation message. Check if the message is still in the queue | ||
if (messages_1.isRequestMessage(toCancel)) { | ||
let response = strategy && strategy.cancelUndispatched ? strategy.cancelUndispatched(toCancel, cancelUndispatched) : cancelUndispatched(toCancel); | ||
const strategy = (_a = options) === null || _a === void 0 ? void 0 : _a.connectionStrategy; | ||
let response = (strategy && strategy.cancelUndispatched) ? strategy.cancelUndispatched(toCancel, cancelUndispatched) : cancelUndispatched(toCancel); | ||
if (response && (response.error !== void 0 || response.result !== void 0)) { | ||
@@ -368,4 +418,4 @@ messageQueue.delete(key); | ||
if (requestHandler || starRequestHandler) { | ||
let cancellationSource = new cancellation_1.CancellationTokenSource(); | ||
let tokenKey = String(requestMessage.id); | ||
let cancellationSource = cancellationStrategy.receiver.createCancellationTokenSource(tokenKey); | ||
requestTokens[tokenKey] = cancellationSource; | ||
@@ -834,2 +884,8 @@ try { | ||
let id = sequenceNumber++; | ||
let disposable; | ||
if (token) { | ||
disposable = token.onCancellationRequested(() => { | ||
cancellationStrategy.sender.sendCancellation(connection, id); | ||
}); | ||
} | ||
let result = new Promise((resolve, reject) => { | ||
@@ -842,3 +898,15 @@ let requestMessage = { | ||
}; | ||
let responsePromise = { method: method, timerStart: Date.now(), resolve, reject }; | ||
const resolveWithCleanup = (r) => { | ||
var _a; | ||
resolve(r); | ||
cancellationStrategy.sender.cleanup(id); | ||
(_a = disposable) === null || _a === void 0 ? void 0 : _a.dispose(); | ||
}; | ||
const rejectWithCleanup = (r) => { | ||
var _a; | ||
reject(r); | ||
cancellationStrategy.sender.cleanup(id); | ||
(_a = disposable) === null || _a === void 0 ? void 0 : _a.dispose(); | ||
}; | ||
let responsePromise = { method: method, timerStart: Date.now(), resolve: resolveWithCleanup, reject: rejectWithCleanup }; | ||
traceSendingRequest(requestMessage); | ||
@@ -857,7 +925,2 @@ try { | ||
}); | ||
if (token) { | ||
token.onCancellationRequested(() => { | ||
connection.sendNotification(CancelNotification.type, { id }); | ||
}); | ||
} | ||
return result; | ||
@@ -962,3 +1025,3 @@ }, | ||
} | ||
function createMessageConnection(input, output, logger, strategy) { | ||
function createMessageConnection(input, output, logger, options) { | ||
if (!logger) { | ||
@@ -969,4 +1032,7 @@ logger = exports.NullLogger; | ||
let writer = isMessageWriter(output) ? output : new messageWriter_1.StreamMessageWriter(output); | ||
return _createMessageConnection(reader, writer, logger, strategy); | ||
if (ConnectionStrategy.is(options)) { | ||
options = { connectionStrategy: options }; | ||
} | ||
return _createMessageConnection(reader, writer, logger, options); | ||
} | ||
exports.createMessageConnection = createMessageConnection; |
{ | ||
"name": "vscode-jsonrpc", | ||
"description": "A json rpc implementation over streams", | ||
"version": "5.0.1", | ||
"version": "5.1.0-next.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
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
129522
3151
2