@eclipse-glsp/protocol
Version:
The protocol definition for client-server communication in GLSP
134 lines • 5.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CompoundOperation = exports.Operation = exports.RejectAction = exports.ResponseAction = exports.RequestAction = exports.ActionMessage = exports.Action = void 0;
/********************************************************************************
* Copyright (c) 2021-2023 STMicroelectronics and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
const sprotty = require("sprotty-protocol/lib/actions");
const type_util_1 = require("../utils/type-util");
var Action;
(function (Action) {
function is(object) {
return type_util_1.AnyObject.is(object) && (0, type_util_1.hasStringProp)(object, 'kind');
}
Action.is = is;
/**
* Typeguard function to check wether the given object is an {@link Action} with the given `kind`.
* @param object The object to check.
* @param kind The expected action kind.
* @returns A type literal indicating wether the given object is an action with the given kind.
*/
function hasKind(object, kind) {
return Action.is(object) && object.kind === kind;
}
Action.hasKind = hasKind;
})(Action || (exports.Action = Action = {}));
var ActionMessage;
(function (ActionMessage) {
function is(object, typeguard) {
const actionGuard = typeguard !== null && typeguard !== void 0 ? typeguard : Action.is;
return type_util_1.AnyObject.is(object) && (0, type_util_1.hasStringProp)(object, 'clientId') && 'action' in object && actionGuard(object.action);
}
ActionMessage.is = is;
})(ActionMessage || (exports.ActionMessage = ActionMessage = {}));
var RequestAction;
(function (RequestAction) {
function is(object) {
return Action.is(object) && (0, type_util_1.hasStringProp)(object, 'requestId');
}
RequestAction.is = is;
/**
* Typeguard function to check wether the given object is an {@link RequestAction} with the given `kind`.
* @param object The object to check.
* @param kind The expected action kind.
* @returns A type literal indicating wether the given object is a request action with the given kind.
*/
function hasKind(object, kind) {
return RequestAction.is(object) && object.kind === kind;
}
RequestAction.hasKind = hasKind;
function generateRequestId() {
return sprotty.generateRequestId();
}
RequestAction.generateRequestId = generateRequestId;
})(RequestAction || (exports.RequestAction = RequestAction = {}));
var ResponseAction;
(function (ResponseAction) {
function is(object) {
return Action.is(object) && (0, type_util_1.hasStringProp)(object, 'responseId');
}
ResponseAction.is = is;
/**
* Typeguard function to check wether the given object is an {@link ResponseAction} with a non-empty response id.
* @param object The object to check.
* @returns A type literal indicating wether the given object is a response action with a non-empty response id.
*/
function hasValidResponseId(object) {
return ResponseAction.is(object) && object.responseId !== '';
}
ResponseAction.hasValidResponseId = hasValidResponseId;
})(ResponseAction || (exports.ResponseAction = ResponseAction = {}));
var RejectAction;
(function (RejectAction) {
RejectAction.KIND = 'rejectRequest';
function is(object) {
return Action.hasKind(object, RejectAction.KIND) && (0, type_util_1.hasStringProp)(object, 'message');
}
RejectAction.is = is;
function create(message, options = {}) {
return {
kind: RejectAction.KIND,
responseId: '',
message,
...options
};
}
RejectAction.create = create;
})(RejectAction || (exports.RejectAction = RejectAction = {}));
var Operation;
(function (Operation) {
function is(object) {
return Action.is(object) && 'isOperation' in object && object.isOperation === true;
}
Operation.is = is;
/**
* Typeguard function to check wether the given object is an {@link Operation} with the given `kind`.
* @param object The object to check.
* @param kind The expected operation kind.
* @returns A type literal indicating wether the given object is an operation with the given kind.
*/
function hasKind(object, kind) {
return Operation.is(object) && object.kind === kind;
}
Operation.hasKind = hasKind;
})(Operation || (exports.Operation = Operation = {}));
var CompoundOperation;
(function (CompoundOperation) {
CompoundOperation.KIND = 'compound';
function is(object) {
return Operation.hasKind(object, CompoundOperation.KIND) && (0, type_util_1.hasArrayProp)(object, 'operationList');
}
CompoundOperation.is = is;
function create(operationList, options = {}) {
return {
kind: CompoundOperation.KIND,
isOperation: true,
operationList,
...options
};
}
CompoundOperation.create = create;
})(CompoundOperation || (exports.CompoundOperation = CompoundOperation = {}));
//# sourceMappingURL=base-protocol.js.map