astro-ghostcms/.pnpm-store/v3/files/9e/5fdf0c168c4026b01d8baf3d7ba...

307 lines
10 KiB
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
"use strict";
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Message = exports.NotificationType9 = exports.NotificationType8 = exports.NotificationType7 = exports.NotificationType6 = exports.NotificationType5 = exports.NotificationType4 = exports.NotificationType3 = exports.NotificationType2 = exports.NotificationType1 = exports.NotificationType0 = exports.NotificationType = exports.RequestType9 = exports.RequestType8 = exports.RequestType7 = exports.RequestType6 = exports.RequestType5 = exports.RequestType4 = exports.RequestType3 = exports.RequestType2 = exports.RequestType1 = exports.RequestType = exports.RequestType0 = exports.AbstractMessageSignature = exports.ParameterStructures = exports.ResponseError = exports.ErrorCodes = void 0;
const is = require("./is");
/**
* Predefined error codes.
*/
var ErrorCodes;
(function (ErrorCodes) {
// Defined by JSON RPC
ErrorCodes.ParseError = -32700;
ErrorCodes.InvalidRequest = -32600;
ErrorCodes.MethodNotFound = -32601;
ErrorCodes.InvalidParams = -32602;
ErrorCodes.InternalError = -32603;
/**
* This is the start range of JSON RPC reserved error codes.
* It doesn't denote a real error code. No application error codes should
* be defined between the start and end range. For backwards
* compatibility the `ServerNotInitialized` and the `UnknownErrorCode`
* are left in the range.
*
* @since 3.16.0
*/
ErrorCodes.jsonrpcReservedErrorRangeStart = -32099;
/** @deprecated use jsonrpcReservedErrorRangeStart */
ErrorCodes.serverErrorStart = -32099;
/**
* An error occurred when write a message to the transport layer.
*/
ErrorCodes.MessageWriteError = -32099;
/**
* An error occurred when reading a message from the transport layer.
*/
ErrorCodes.MessageReadError = -32098;
/**
* The connection got disposed or lost and all pending responses got
* rejected.
*/
ErrorCodes.PendingResponseRejected = -32097;
/**
* The connection is inactive and a use of it failed.
*/
ErrorCodes.ConnectionInactive = -32096;
/**
* Error code indicating that a server received a notification or
* request before the server has received the `initialize` request.
*/
ErrorCodes.ServerNotInitialized = -32002;
ErrorCodes.UnknownErrorCode = -32001;
/**
* This is the end range of JSON RPC reserved error codes.
* It doesn't denote a real error code.
*
* @since 3.16.0
*/
ErrorCodes.jsonrpcReservedErrorRangeEnd = -32000;
/** @deprecated use jsonrpcReservedErrorRangeEnd */
ErrorCodes.serverErrorEnd = -32000;
})(ErrorCodes || (exports.ErrorCodes = ErrorCodes = {}));
/**
* An error object return in a response in case a request
* has failed.
*/
class ResponseError extends Error {
constructor(code, message, data) {
super(message);
this.code = is.number(code) ? code : ErrorCodes.UnknownErrorCode;
this.data = data;
Object.setPrototypeOf(this, ResponseError.prototype);
}
toJson() {
const result = {
code: this.code,
message: this.message
};
if (this.data !== undefined) {
result.data = this.data;
}
return result;
}
}
exports.ResponseError = ResponseError;
class ParameterStructures {
constructor(kind) {
this.kind = kind;
}
static is(value) {
return value === ParameterStructures.auto || value === ParameterStructures.byName || value === ParameterStructures.byPosition;
}
toString() {
return this.kind;
}
}
exports.ParameterStructures = ParameterStructures;
/**
* The parameter structure is automatically inferred on the number of parameters
* and the parameter type in case of a single param.
*/
ParameterStructures.auto = new ParameterStructures('auto');
/**
* Forces `byPosition` parameter structure. This is useful if you have a single
* parameter which has a literal type.
*/
ParameterStructures.byPosition = new ParameterStructures('byPosition');
/**
* Forces `byName` parameter structure. This is only useful when having a single
* parameter. The library will report errors if used with a different number of
* parameters.
*/
ParameterStructures.byName = new ParameterStructures('byName');
/**
* An abstract implementation of a MessageType.
*/
class AbstractMessageSignature {
constructor(method, numberOfParams) {
this.method = method;
this.numberOfParams = numberOfParams;
}
get parameterStructures() {
return ParameterStructures.auto;
}
}
exports.AbstractMessageSignature = AbstractMessageSignature;
/**
* Classes to type request response pairs
*/
class RequestType0 extends AbstractMessageSignature {
constructor(method) {
super(method, 0);
}
}
exports.RequestType0 = RequestType0;
class RequestType extends AbstractMessageSignature {
constructor(method, _parameterStructures = ParameterStructures.auto) {
super(method, 1);
this._parameterStructures = _parameterStructures;
}
get parameterStructures() {
return this._parameterStructures;
}
}
exports.RequestType = RequestType;
class RequestType1 extends AbstractMessageSignature {
constructor(method, _parameterStructures = ParameterStructures.auto) {
super(method, 1);
this._parameterStructures = _parameterStructures;
}
get parameterStructures() {
return this._parameterStructures;
}
}
exports.RequestType1 = RequestType1;
class RequestType2 extends AbstractMessageSignature {
constructor(method) {
super(method, 2);
}
}
exports.RequestType2 = RequestType2;
class RequestType3 extends AbstractMessageSignature {
constructor(method) {
super(method, 3);
}
}
exports.RequestType3 = RequestType3;
class RequestType4 extends AbstractMessageSignature {
constructor(method) {
super(method, 4);
}
}
exports.RequestType4 = RequestType4;
class RequestType5 extends AbstractMessageSignature {
constructor(method) {
super(method, 5);
}
}
exports.RequestType5 = RequestType5;
class RequestType6 extends AbstractMessageSignature {
constructor(method) {
super(method, 6);
}
}
exports.RequestType6 = RequestType6;
class RequestType7 extends AbstractMessageSignature {
constructor(method) {
super(method, 7);
}
}
exports.RequestType7 = RequestType7;
class RequestType8 extends AbstractMessageSignature {
constructor(method) {
super(method, 8);
}
}
exports.RequestType8 = RequestType8;
class RequestType9 extends AbstractMessageSignature {
constructor(method) {
super(method, 9);
}
}
exports.RequestType9 = RequestType9;
class NotificationType extends AbstractMessageSignature {
constructor(method, _parameterStructures = ParameterStructures.auto) {
super(method, 1);
this._parameterStructures = _parameterStructures;
}
get parameterStructures() {
return this._parameterStructures;
}
}
exports.NotificationType = NotificationType;
class NotificationType0 extends AbstractMessageSignature {
constructor(method) {
super(method, 0);
}
}
exports.NotificationType0 = NotificationType0;
class NotificationType1 extends AbstractMessageSignature {
constructor(method, _parameterStructures = ParameterStructures.auto) {
super(method, 1);
this._parameterStructures = _parameterStructures;
}
get parameterStructures() {
return this._parameterStructures;
}
}
exports.NotificationType1 = NotificationType1;
class NotificationType2 extends AbstractMessageSignature {
constructor(method) {
super(method, 2);
}
}
exports.NotificationType2 = NotificationType2;
class NotificationType3 extends AbstractMessageSignature {
constructor(method) {
super(method, 3);
}
}
exports.NotificationType3 = NotificationType3;
class NotificationType4 extends AbstractMessageSignature {
constructor(method) {
super(method, 4);
}
}
exports.NotificationType4 = NotificationType4;
class NotificationType5 extends AbstractMessageSignature {
constructor(method) {
super(method, 5);
}
}
exports.NotificationType5 = NotificationType5;
class NotificationType6 extends AbstractMessageSignature {
constructor(method) {
super(method, 6);
}
}
exports.NotificationType6 = NotificationType6;
class NotificationType7 extends AbstractMessageSignature {
constructor(method) {
super(method, 7);
}
}
exports.NotificationType7 = NotificationType7;
class NotificationType8 extends AbstractMessageSignature {
constructor(method) {
super(method, 8);
}
}
exports.NotificationType8 = NotificationType8;
class NotificationType9 extends AbstractMessageSignature {
constructor(method) {
super(method, 9);
}
}
exports.NotificationType9 = NotificationType9;
var Message;
(function (Message) {
/**
* Tests if the given message is a request message
*/
function isRequest(message) {
const candidate = message;
return candidate && is.string(candidate.method) && (is.string(candidate.id) || is.number(candidate.id));
}
Message.isRequest = isRequest;
/**
* Tests if the given message is a notification message
*/
function isNotification(message) {
const candidate = message;
return candidate && is.string(candidate.method) && message.id === void 0;
}
Message.isNotification = isNotification;
/**
* Tests if the given message is a response message
*/
function isResponse(message) {
const candidate = message;
return candidate && (candidate.result !== void 0 || !!candidate.error) && (is.string(candidate.id) || is.number(candidate.id) || candidate.id === null);
}
Message.isResponse = isResponse;
})(Message || (exports.Message = Message = {}));