vscode-jsonrpc
Advanced tools
Comparing version 8.1.0-next.1 to 8.1.0-next.2
@@ -11,4 +11,4 @@ /// <reference path="../../typings/thenable.d.ts" /> | ||
import { ContentTypeEncoderOptions, ContentTypeDecoderOptions } from './encoding'; | ||
import { Logger, ConnectionStrategy, ConnectionOptions, MessageConnection, NullLogger, createMessageConnection, ProgressToken, ProgressType, HandlerResult, StarRequestHandler, GenericRequestHandler, RequestHandler0, RequestHandler, RequestHandler1, RequestHandler2, RequestHandler3, RequestHandler4, RequestHandler5, RequestHandler6, RequestHandler7, RequestHandler8, RequestHandler9, StarNotificationHandler, GenericNotificationHandler, NotificationHandler0, NotificationHandler, NotificationHandler1, NotificationHandler2, NotificationHandler3, NotificationHandler4, NotificationHandler5, NotificationHandler6, NotificationHandler7, NotificationHandler8, NotificationHandler9, Trace, TraceValues, TraceFormat, TraceOptions, SetTraceParams, SetTraceNotification, LogTraceParams, LogTraceNotification, Tracer, ConnectionErrors, ConnectionError, CancellationId, CancellationReceiverStrategy, CancellationSenderStrategy, CancellationStrategy } from './connection'; | ||
import { Logger, ConnectionStrategy, ConnectionOptions, MessageConnection, NullLogger, createMessageConnection, ProgressToken, ProgressType, HandlerResult, StarRequestHandler, GenericRequestHandler, RequestHandler0, RequestHandler, RequestHandler1, RequestHandler2, RequestHandler3, RequestHandler4, RequestHandler5, RequestHandler6, RequestHandler7, RequestHandler8, RequestHandler9, StarNotificationHandler, GenericNotificationHandler, NotificationHandler0, NotificationHandler, NotificationHandler1, NotificationHandler2, NotificationHandler3, NotificationHandler4, NotificationHandler5, NotificationHandler6, NotificationHandler7, NotificationHandler8, NotificationHandler9, Trace, TraceValues, TraceFormat, TraceOptions, SetTraceParams, SetTraceNotification, LogTraceParams, LogTraceNotification, Tracer, ConnectionErrors, ConnectionError, CancellationId, CancellationReceiverStrategy, CancellationSenderStrategy, CancellationStrategy, MessageStrategy } from './connection'; | ||
import RAL from './ral'; | ||
export { RAL, Message, MessageSignature, RequestMessage, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, ResponseError, ErrorCodes, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, ResponseMessage, ParameterStructures, _EM, LinkedMap, Touch, LRUCache, Disposable, Event, Emitter, AbstractCancellationTokenSource, CancellationTokenSource, CancellationToken, MessageReader, AbstractMessageReader, ReadableStreamMessageReader, DataCallback, MessageReaderOptions, PartialMessageInfo, MessageWriter, AbstractMessageWriter, WriteableStreamMessageWriter, MessageWriterOptions, AbstractMessageBuffer, ContentTypeEncoderOptions, ContentTypeDecoderOptions, Logger, ConnectionStrategy, ConnectionOptions, MessageConnection, NullLogger, createMessageConnection, ProgressToken, ProgressType, HandlerResult, StarRequestHandler, GenericRequestHandler, RequestHandler0, RequestHandler, RequestHandler1, RequestHandler2, RequestHandler3, RequestHandler4, RequestHandler5, RequestHandler6, RequestHandler7, RequestHandler8, RequestHandler9, StarNotificationHandler, GenericNotificationHandler, NotificationHandler0, NotificationHandler, NotificationHandler1, NotificationHandler2, NotificationHandler3, NotificationHandler4, NotificationHandler5, NotificationHandler6, NotificationHandler7, NotificationHandler8, NotificationHandler9, Trace, TraceValues, TraceFormat, TraceOptions, SetTraceParams, SetTraceNotification, LogTraceParams, LogTraceNotification, Tracer, ConnectionErrors, ConnectionError, CancellationId, CancellationReceiverStrategy, CancellationSenderStrategy, CancellationStrategy, }; | ||
export { RAL, Message, MessageSignature, RequestMessage, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, ResponseError, ErrorCodes, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, ResponseMessage, ParameterStructures, _EM, LinkedMap, Touch, LRUCache, Disposable, Event, Emitter, AbstractCancellationTokenSource, CancellationTokenSource, CancellationToken, MessageReader, AbstractMessageReader, ReadableStreamMessageReader, DataCallback, MessageReaderOptions, PartialMessageInfo, MessageWriter, AbstractMessageWriter, WriteableStreamMessageWriter, MessageWriterOptions, AbstractMessageBuffer, ContentTypeEncoderOptions, ContentTypeDecoderOptions, Logger, ConnectionStrategy, ConnectionOptions, MessageConnection, NullLogger, createMessageConnection, ProgressToken, ProgressType, HandlerResult, StarRequestHandler, GenericRequestHandler, RequestHandler0, RequestHandler, RequestHandler1, RequestHandler2, RequestHandler3, RequestHandler4, RequestHandler5, RequestHandler6, RequestHandler7, RequestHandler8, RequestHandler9, StarNotificationHandler, GenericNotificationHandler, NotificationHandler0, NotificationHandler, NotificationHandler1, NotificationHandler2, NotificationHandler3, NotificationHandler4, NotificationHandler5, NotificationHandler6, NotificationHandler7, NotificationHandler8, NotificationHandler9, Trace, TraceValues, TraceFormat, TraceOptions, SetTraceParams, SetTraceNotification, LogTraceParams, LogTraceNotification, Tracer, ConnectionErrors, ConnectionError, CancellationId, CancellationReceiverStrategy, CancellationSenderStrategy, CancellationStrategy, MessageStrategy }; |
@@ -9,3 +9,3 @@ "use strict"; | ||
exports.TraceValues = exports.Trace = exports.ProgressType = exports.ProgressToken = exports.createMessageConnection = exports.NullLogger = exports.ConnectionOptions = exports.ConnectionStrategy = exports.AbstractMessageBuffer = exports.WriteableStreamMessageWriter = exports.AbstractMessageWriter = exports.MessageWriter = exports.ReadableStreamMessageReader = exports.AbstractMessageReader = exports.MessageReader = exports.CancellationToken = exports.CancellationTokenSource = exports.Emitter = exports.Event = exports.Disposable = exports.LRUCache = exports.Touch = exports.LinkedMap = exports.ParameterStructures = exports.NotificationType9 = exports.NotificationType8 = exports.NotificationType7 = exports.NotificationType6 = exports.NotificationType5 = exports.NotificationType4 = exports.NotificationType3 = exports.NotificationType2 = exports.NotificationType1 = exports.NotificationType0 = exports.NotificationType = exports.ErrorCodes = exports.ResponseError = exports.RequestType9 = exports.RequestType8 = exports.RequestType7 = exports.RequestType6 = exports.RequestType5 = exports.RequestType4 = exports.RequestType3 = exports.RequestType2 = exports.RequestType1 = exports.RequestType0 = exports.RequestType = exports.Message = exports.RAL = void 0; | ||
exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.CancellationReceiverStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = void 0; | ||
exports.MessageStrategy = exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.CancellationReceiverStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = void 0; | ||
const messages_1 = require("./messages"); | ||
@@ -77,4 +77,5 @@ Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return messages_1.Message; } }); | ||
Object.defineProperty(exports, "CancellationStrategy", { enumerable: true, get: function () { return connection_1.CancellationStrategy; } }); | ||
Object.defineProperty(exports, "MessageStrategy", { enumerable: true, get: function () { return connection_1.MessageStrategy; } }); | ||
const ral_1 = require("./ral"); | ||
exports.RAL = ral_1.default; | ||
//# sourceMappingURL=api.js.map |
@@ -1,2 +0,2 @@ | ||
import { Message, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, ResponseMessage, ResponseError, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, _EM, ParameterStructures } from './messages'; | ||
import { Message, RequestMessage, RequestType, RequestType0, RequestType1, RequestType2, RequestType3, RequestType4, RequestType5, RequestType6, RequestType7, RequestType8, RequestType9, ResponseMessage, ResponseError, NotificationMessage, NotificationType, NotificationType0, NotificationType1, NotificationType2, NotificationType3, NotificationType4, NotificationType5, NotificationType6, NotificationType7, NotificationType8, NotificationType9, _EM, ParameterStructures } from './messages'; | ||
import type { Disposable } from './disposable'; | ||
@@ -198,6 +198,39 @@ import { Event } from './events'; | ||
export declare type CancellationId = number | string; | ||
export interface CancellationReceiverStrategy { | ||
export interface IdCancellationReceiverStrategy { | ||
kind?: 'id'; | ||
/** | ||
* Creates a CancellationTokenSource from a cancellation id. | ||
* | ||
* @param id The cancellation id. | ||
*/ | ||
createCancellationTokenSource(id: CancellationId): AbstractCancellationTokenSource; | ||
/** | ||
* An optional method to dispose the strategy. | ||
*/ | ||
dispose?(): void; | ||
} | ||
export declare namespace IdCancellationReceiverStrategy { | ||
function is(value: any): value is IdCancellationReceiverStrategy; | ||
} | ||
export interface RequestCancellationReceiverStrategy { | ||
kind: 'request'; | ||
/** | ||
* Create a cancellation token source from a given request message. | ||
* | ||
* @param requestMessage The request message. | ||
*/ | ||
createCancellationTokenSource(requestMessage: RequestMessage): AbstractCancellationTokenSource; | ||
/** | ||
* An optional method to dispose the strategy. | ||
*/ | ||
dispose?(): void; | ||
} | ||
export declare namespace RequestCancellationReceiverStrategy { | ||
function is(value: any): value is RequestCancellationReceiverStrategy; | ||
} | ||
/** | ||
* This will break with the next major version and will become | ||
* export type CancellationReceiverStrategy = IdCancellationReceiverStrategy | RequestCancellationReceiverStrategy; | ||
*/ | ||
export declare type CancellationReceiverStrategy = IdCancellationReceiverStrategy; | ||
export declare namespace CancellationReceiverStrategy { | ||
@@ -208,4 +241,25 @@ const Message: CancellationReceiverStrategy; | ||
export interface CancellationSenderStrategy { | ||
/** | ||
* Hook to enable cancellation for the given request. | ||
* | ||
* @param request The request to enable cancellation for. | ||
*/ | ||
enableCancellation?(request: RequestMessage): void; | ||
/** | ||
* Send cancellation for the given cancellation id | ||
* | ||
* @param conn The connection used. | ||
* @param id The cancellation id. | ||
*/ | ||
sendCancellation(conn: MessageConnection, id: CancellationId): Promise<void>; | ||
/** | ||
* Cleanup any cancellation state for the given cancellation id. After this | ||
* method has been call no cancellation will be sent anymore for the given id. | ||
* | ||
* @param id The cancellation id. | ||
*/ | ||
cleanup(id: CancellationId): void; | ||
/** | ||
* An optional method to dispose the strategy. | ||
*/ | ||
dispose?(): void; | ||
@@ -218,3 +272,3 @@ } | ||
export interface CancellationStrategy { | ||
receiver: CancellationReceiverStrategy; | ||
receiver: CancellationReceiverStrategy | RequestCancellationReceiverStrategy; | ||
sender: CancellationSenderStrategy; | ||
@@ -226,5 +280,12 @@ } | ||
} | ||
export interface MessageStrategy { | ||
handleMessage(message: Message, next: (message: Message) => void): void; | ||
} | ||
export declare namespace MessageStrategy { | ||
function is(value: any): value is MessageStrategy; | ||
} | ||
export interface ConnectionOptions { | ||
cancellationStrategy?: CancellationStrategy; | ||
connectionStrategy?: ConnectionStrategy; | ||
messageStrategy?: MessageStrategy; | ||
} | ||
@@ -231,0 +292,0 @@ export declare namespace ConnectionOptions { |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createMessageConnection = exports.ConnectionOptions = exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.CancellationReceiverStrategy = exports.ConnectionStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = exports.TraceValues = exports.Trace = exports.NullLogger = exports.ProgressType = exports.ProgressToken = void 0; | ||
exports.createMessageConnection = exports.ConnectionOptions = exports.MessageStrategy = exports.CancellationStrategy = exports.CancellationSenderStrategy = exports.CancellationReceiverStrategy = exports.RequestCancellationReceiverStrategy = exports.IdCancellationReceiverStrategy = exports.ConnectionStrategy = exports.ConnectionError = exports.ConnectionErrors = exports.LogTraceNotification = exports.SetTraceNotification = exports.TraceFormat = exports.TraceValues = exports.Trace = exports.NullLogger = exports.ProgressType = exports.ProgressToken = void 0; | ||
const ral_1 = require("./ral"); | ||
@@ -169,2 +169,18 @@ const Is = require("./is"); | ||
})(ConnectionStrategy = exports.ConnectionStrategy || (exports.ConnectionStrategy = {})); | ||
var IdCancellationReceiverStrategy; | ||
(function (IdCancellationReceiverStrategy) { | ||
function is(value) { | ||
const candidate = value; | ||
return candidate && (candidate.kind === undefined || candidate.kind === 'id') && Is.func(candidate.createCancellationTokenSource) && (candidate.dispose === undefined || Is.func(candidate.dispose)); | ||
} | ||
IdCancellationReceiverStrategy.is = is; | ||
})(IdCancellationReceiverStrategy = exports.IdCancellationReceiverStrategy || (exports.IdCancellationReceiverStrategy = {})); | ||
var RequestCancellationReceiverStrategy; | ||
(function (RequestCancellationReceiverStrategy) { | ||
function is(value) { | ||
const candidate = value; | ||
return candidate && candidate.kind === 'request' && Is.func(candidate.createCancellationTokenSource) && (candidate.dispose === undefined || Is.func(candidate.dispose)); | ||
} | ||
RequestCancellationReceiverStrategy.is = is; | ||
})(RequestCancellationReceiverStrategy = exports.RequestCancellationReceiverStrategy || (exports.RequestCancellationReceiverStrategy = {})); | ||
var CancellationReceiverStrategy; | ||
@@ -178,4 +194,3 @@ (function (CancellationReceiverStrategy) { | ||
function is(value) { | ||
const candidate = value; | ||
return candidate && Is.func(candidate.createCancellationTokenSource); | ||
return IdCancellationReceiverStrategy.is(value) || RequestCancellationReceiverStrategy.is(value); | ||
} | ||
@@ -210,2 +225,10 @@ CancellationReceiverStrategy.is = is; | ||
})(CancellationStrategy = exports.CancellationStrategy || (exports.CancellationStrategy = {})); | ||
var MessageStrategy; | ||
(function (MessageStrategy) { | ||
function is(value) { | ||
const candidate = value; | ||
return candidate && Is.func(candidate.handleMessage); | ||
} | ||
MessageStrategy.is = is; | ||
})(MessageStrategy = exports.MessageStrategy || (exports.MessageStrategy = {})); | ||
var ConnectionOptions; | ||
@@ -215,3 +238,3 @@ (function (ConnectionOptions) { | ||
const candidate = value; | ||
return candidate && (CancellationStrategy.is(candidate.cancellationStrategy) || ConnectionStrategy.is(candidate.connectionStrategy)); | ||
return candidate && (CancellationStrategy.is(candidate.cancellationStrategy) || ConnectionStrategy.is(candidate.connectionStrategy) || MessageStrategy.is(candidate.messageStrategy)); | ||
} | ||
@@ -319,2 +342,16 @@ ConnectionOptions.is = is; | ||
} | ||
function handleMessage(message) { | ||
if (messages_1.Message.isRequest(message)) { | ||
handleRequest(message); | ||
} | ||
else if (messages_1.Message.isNotification(message)) { | ||
handleNotification(message); | ||
} | ||
else if (messages_1.Message.isResponse(message)) { | ||
handleResponse(message); | ||
} | ||
else { | ||
handleInvalidMessage(message); | ||
} | ||
} | ||
function processMessageQueue() { | ||
@@ -326,13 +363,8 @@ if (messageQueue.size === 0) { | ||
try { | ||
if (messages_1.Message.isRequest(message)) { | ||
handleRequest(message); | ||
const messageStrategy = options?.messageStrategy; | ||
if (MessageStrategy.is(messageStrategy)) { | ||
messageStrategy.handleMessage(message, handleMessage); | ||
} | ||
else if (messages_1.Message.isNotification(message)) { | ||
handleNotification(message); | ||
} | ||
else if (messages_1.Message.isResponse(message)) { | ||
handleResponse(message); | ||
} | ||
else { | ||
handleInvalidMessage(message); | ||
handleMessage(message); | ||
} | ||
@@ -437,3 +469,5 @@ } | ||
const tokenKey = requestMessage.id ?? String(Date.now()); // | ||
const cancellationSource = cancellationStrategy.receiver.createCancellationTokenSource(tokenKey); | ||
const cancellationSource = IdCancellationReceiverStrategy.is(cancellationStrategy.receiver) | ||
? cancellationStrategy.receiver.createCancellationTokenSource(tokenKey) | ||
: cancellationStrategy.receiver.createCancellationTokenSource(requestMessage); | ||
if (requestMessage.id !== null && knownCanceledRequests.has(requestMessage.id)) { | ||
@@ -1048,2 +1082,5 @@ cancellationSource.cancel(); | ||
try { | ||
if (typeof cancellationStrategy.sender.enableCancellation === 'function') { | ||
cancellationStrategy.sender.enableCancellation(requestMessage); | ||
} | ||
messageWriter.write(requestMessage).catch(() => logger.error(`Sending request failed.`)); | ||
@@ -1050,0 +1087,0 @@ } |
{ | ||
"name": "vscode-jsonrpc", | ||
"description": "A json rpc implementation over streams", | ||
"version": "8.1.0-next.1", | ||
"version": "8.1.0-next.2", | ||
"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
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
207216
48
4942