Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eclipse-glsp/protocol

Package Overview
Dependencies
Maintainers
6
Versions
297
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eclipse-glsp/protocol - npm Package Compare versions

Comparing version 1.1.0-next.7ff1b00.184 to 1.1.0-next.80bb01c.251

lib/client-server-protocol/base-glsp-client.d.ts

2

lib/action-protocol/base-protocol.d.ts
/********************************************************************************
* Copyright (c) 2021-2022 STMicroelectronics and others.
* Copyright (c) 2021-2023 STMicroelectronics and others.
*

@@ -4,0 +4,0 @@ * This program and the accompanying materials are made available under the

@@ -27,3 +27,3 @@ "use strict";

const actionGuard = typeguard !== null && typeguard !== void 0 ? typeguard : Action.is;
return type_util_1.AnyObject.is(object) && (0, type_util_1.hasStringProp)(object, 'clientId') && actionGuard(object.action);
return type_util_1.AnyObject.is(object) && (0, type_util_1.hasStringProp)(object, 'clientId') && 'action' in object && actionGuard(object.action);
}

@@ -30,0 +30,0 @@ ActionMessage.is = is;

@@ -34,3 +34,3 @@ import { Action } from './base-protocol';

*/
export declare type ServerSeverity = 'NONE' | 'INFO' | 'WARNING' | 'ERROR' | 'FATAL' | 'OK';
export type ServerSeverity = 'NONE' | 'INFO' | 'WARNING' | 'ERROR' | 'FATAL' | 'OK';
/**

@@ -37,0 +37,0 @@ * Sent by the server to notify the user about something of interest. Typically this message is handled by

@@ -17,2 +17,3 @@ /********************************************************************************

import { Point } from 'sprotty-protocol';
import * as sprotty from 'sprotty-protocol/lib/actions';
import { Operation } from './base-protocol';

@@ -90,3 +91,3 @@ import { Args } from './types';

*/
export interface DeleteElementOperation extends Operation {
export interface DeleteElementOperation extends Operation, Omit<sprotty.DeleteElementAction, 'kind'> {
kind: typeof DeleteElementOperation.KIND;

@@ -93,0 +94,0 @@ /**

@@ -0,1 +1,17 @@

/********************************************************************************
* Copyright (c) 2020-2023 EclipseSource 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
********************************************************************************/
import * as sprotty from 'sprotty-protocol/lib/actions';
import { Operation, RequestAction, ResponseAction } from './base-protocol';

@@ -58,3 +74,3 @@ import { Args } from './types';

*/
export interface ApplyLabelEditOperation extends Operation {
export interface ApplyLabelEditOperation extends Operation, sprotty.ApplyLabelEditAction {
kind: typeof ApplyLabelEditOperation.KIND;

@@ -61,0 +77,0 @@ /**

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidationStatus = exports.ApplyLabelEditOperation = exports.SetEditValidationResultAction = exports.RequestEditValidationAction = void 0;
/********************************************************************************
* Copyright (c) 2020-2022 EclipseSource 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 type_util_1 = require("../utils/type-util");

@@ -65,3 +50,2 @@ const base_protocol_1 = require("./base-protocol");

*/
// eslint-disable-next-line no-shadow
let Severity;

@@ -74,3 +58,2 @@ (function (Severity) {

Severity[Severity["OK"] = 4] = "OK";
// eslint-disable-next-line no-shadow
Severity[Severity["NONE"] = 5] = "NONE";

@@ -77,0 +60,0 @@ })(Severity = ValidationStatus.Severity || (ValidationStatus.Severity = {}));

@@ -32,2 +32,11 @@ import { Action, RequestAction, ResponseAction } from './base-protocol';

/**
* The default reasons for markers.
*/
export declare namespace MarkersReason {
/** Markers resulting from a batch validation */
const BATCH = "batch";
/** Markers resulting from a live validation */
const LIVE = "live";
}
/**
* Action to retrieve markers for the specified model elements. Sent from the client to the server.

@@ -43,2 +52,6 @@ * The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks

elementsIDs: string[];
/**
* The reason for this request, such as `batch` or `live` validation. `batch` by default.
*/
reason?: string;
}

@@ -50,2 +63,3 @@ export declare namespace RequestMarkersAction {

requestId?: string;
reason?: string;
}): RequestMarkersAction;

@@ -66,2 +80,6 @@ }

readonly markers: Marker[];
/**
* The reason for message, such as `batch` or `live` validation.
*/
reason?: string;
}

@@ -73,2 +91,3 @@ export declare namespace SetMarkersAction {

responseId?: string;
reason?: string;
}): SetMarkersAction;

@@ -75,0 +94,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DeleteMarkersAction = exports.SetMarkersAction = exports.RequestMarkersAction = exports.MarkerKind = void 0;
exports.DeleteMarkersAction = exports.SetMarkersAction = exports.RequestMarkersAction = exports.MarkersReason = exports.MarkerKind = void 0;
/********************************************************************************
* Copyright (c) 2021-2022 STMicroelectronics and others.
* Copyright (c) 2021-2023 STMicroelectronics and others.
*

@@ -30,2 +30,12 @@ * This program and the accompanying materials are made available under the

})(MarkerKind = exports.MarkerKind || (exports.MarkerKind = {}));
/**
* The default reasons for markers.
*/
var MarkersReason;
(function (MarkersReason) {
/** Markers resulting from a batch validation */
MarkersReason.BATCH = 'batch';
/** Markers resulting from a live validation */
MarkersReason.LIVE = 'live';
})(MarkersReason = exports.MarkersReason || (exports.MarkersReason = {}));
var RequestMarkersAction;

@@ -39,3 +49,3 @@ (function (RequestMarkersAction) {

function create(elementsIDs, options = {}) {
return Object.assign({ kind: RequestMarkersAction.KIND, requestId: '', elementsIDs }, options);
return Object.assign({ kind: RequestMarkersAction.KIND, requestId: '', elementsIDs, reason: MarkersReason.BATCH }, options);
}

@@ -52,3 +62,3 @@ RequestMarkersAction.create = create;

function create(markers, options = {}) {
return Object.assign({ kind: SetMarkersAction.KIND, responseId: '', markers }, options);
return Object.assign({ kind: SetMarkersAction.KIND, responseId: '', markers, reason: MarkersReason.BATCH }, options);
}

@@ -55,0 +65,0 @@ SetMarkersAction.create = create;

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k;

/********************************************************************************
* Copyright (c) 2021-2022 STMicroelectronics and others.
* Copyright (c) 2021-2023 STMicroelectronics and others.
*

@@ -19,3 +19,3 @@ * This program and the accompanying materials are made available under the

import { SModelRootSchema } from './model-structure';
import { ElementAndAlignment, ElementAndBounds } from './types';
import { ElementAndAlignment, ElementAndBounds, ElementAndRoutingPoints } from './types';
/**

@@ -59,2 +59,6 @@ * Sent from the server to the client to request bounds for the given model. The model is rendered invisibly so the bounds can

alignments?: ElementAndAlignment[];
/**
* The route of the model elements.
*/
routes?: ElementAndRoutingPoints[];
}

@@ -68,2 +72,3 @@ export declare namespace ComputedBoundsAction {

alignments?: ElementAndAlignment[];
routes?: ElementAndRoutingPoints[];
}): ComputedBoundsAction;

@@ -79,5 +84,5 @@ }

/**
* The identifiers of the elements that should be layouted, may be just the root element.
* The identifiers of the elements that should be layouted, will default to the root element if not defined.
*/
elementIds: string[];
elementIds?: string[];
}

@@ -87,4 +92,4 @@ export declare namespace LayoutOperation {

function is(object: any): object is LayoutOperation;
function create(elementIds: string[]): LayoutOperation;
function create(elementIds?: string[]): LayoutOperation;
}
//# sourceMappingURL=model-layout.d.ts.map

@@ -39,3 +39,3 @@ import { Action, RequestAction, ResponseAction } from './base-protocol';

}
export declare type DirtyStateChangeReason = 'operation' | 'undo' | 'redo' | 'save' | 'external';
export type DirtyStateChangeReason = 'operation' | 'undo' | 'redo' | 'save' | 'external';
export declare namespace SetDirtyStateAction {

@@ -42,0 +42,0 @@ const KIND = "setDirtyState";

@@ -16,15 +16,15 @@ /********************************************************************************

********************************************************************************/
import { Operation } from './base-protocol';
import * as sprotty from 'sprotty-protocol/lib/actions';
/**
* Trigger an undo of the latest executed command.
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks
* and creating new `UndoOperations`.
* and creating new `UndoAction`.
*/
export interface UndoOperation extends Operation {
kind: typeof UndoOperation.KIND;
export interface UndoAction extends Omit<sprotty.UndoAction, 'kind'> {
kind: typeof UndoAction.KIND;
}
export declare namespace UndoOperation {
export declare namespace UndoAction {
const KIND = "glspUndo";
function is(object: any): object is UndoOperation;
function create(): UndoOperation;
function is(object: any): object is UndoAction;
function create(): UndoAction;
}

@@ -34,12 +34,12 @@ /**

* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks
* and creating new `RedoOperations`.
* and creating new `RedoAction`.
*/
export interface RedoOperation extends Operation {
kind: typeof RedoOperation.KIND;
export interface RedoAction extends Omit<sprotty.RedoAction, 'kind'> {
kind: typeof RedoAction.KIND;
}
export declare namespace RedoOperation {
export declare namespace RedoAction {
const KIND = "glspRedo";
function is(object: any): object is RedoOperation;
function create(): RedoOperation;
function is(object: any): object is RedoAction;
function create(): RedoAction;
}
//# sourceMappingURL=undo-redo.d.ts.map

@@ -18,34 +18,32 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.RedoOperation = exports.UndoOperation = void 0;
exports.RedoAction = exports.UndoAction = void 0;
const base_protocol_1 = require("./base-protocol");
var UndoOperation;
(function (UndoOperation) {
UndoOperation.KIND = 'glspUndo';
var UndoAction;
(function (UndoAction) {
UndoAction.KIND = 'glspUndo';
function is(object) {
return base_protocol_1.Operation.hasKind(object, UndoOperation.KIND);
return base_protocol_1.Action.hasKind(object, UndoAction.KIND);
}
UndoOperation.is = is;
UndoAction.is = is;
function create() {
return {
kind: UndoOperation.KIND,
isOperation: true
kind: UndoAction.KIND
};
}
UndoOperation.create = create;
})(UndoOperation = exports.UndoOperation || (exports.UndoOperation = {}));
var RedoOperation;
(function (RedoOperation) {
RedoOperation.KIND = 'glspRedo';
UndoAction.create = create;
})(UndoAction = exports.UndoAction || (exports.UndoAction = {}));
var RedoAction;
(function (RedoAction) {
RedoAction.KIND = 'glspRedo';
function is(object) {
return base_protocol_1.Operation.hasKind(object, RedoOperation.KIND);
return base_protocol_1.Action.hasKind(object, RedoAction.KIND);
}
RedoOperation.is = is;
RedoAction.is = is;
function create() {
return {
kind: RedoOperation.KIND,
isOperation: true
kind: RedoAction.KIND
};
}
RedoOperation.create = create;
})(RedoOperation = exports.RedoOperation || (exports.RedoOperation = {}));
RedoAction.create = create;
})(RedoAction = exports.RedoAction || (exports.RedoAction = {}));
//# sourceMappingURL=undo-redo.js.map
/********************************************************************************
* Copyright (c) 2020-2022 EclipseSource and others.
* Copyright (c) 2020-2023 EclipseSource and others.
*

@@ -31,10 +31,17 @@ * This program and the accompanying materials are made available under the

export * from './action-protocol';
export * from './glsp-client';
export * from './jsonrpc/base-jsonrpc-glsp-client';
export * from './jsonrpc/glsp-jsonrpc-client';
export * from './client-server-protocol/base-glsp-client';
export * from './client-server-protocol/glsp-client';
export * from './client-server-protocol/glsp-server';
export * from './client-server-protocol/jsonrpc/base-jsonrpc-glsp-client';
export * from './client-server-protocol/jsonrpc/glsp-jsonrpc-client';
export * from './client-server-protocol/jsonrpc/glsp-jsonrpc-server';
export * from './client-server-protocol/jsonrpc/websocket-connection';
export * from './client-server-protocol/types';
export * from './disposable/disposable';
export * from './model/default-types';
export * from './model/model-schema';
export * from './utils/array-util';
export * from './utils/di-util';
export * from './utils/type-util';
export { SetBoundsAction, SetViewportAction };
//# sourceMappingURL=index.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -15,3 +19,3 @@ if (k2 === undefined) k2 = k;

/********************************************************************************
* Copyright (c) 2020-2022 EclipseSource and others.
* Copyright (c) 2020-2023 EclipseSource and others.
*

@@ -46,9 +50,16 @@ * This program and the accompanying materials are made available under the

__exportStar(require("./action-protocol"), exports);
__exportStar(require("./glsp-client"), exports);
__exportStar(require("./jsonrpc/base-jsonrpc-glsp-client"), exports);
__exportStar(require("./jsonrpc/glsp-jsonrpc-client"), exports);
__exportStar(require("./client-server-protocol/base-glsp-client"), exports);
__exportStar(require("./client-server-protocol/glsp-client"), exports);
__exportStar(require("./client-server-protocol/glsp-server"), exports);
__exportStar(require("./client-server-protocol/jsonrpc/base-jsonrpc-glsp-client"), exports);
__exportStar(require("./client-server-protocol/jsonrpc/glsp-jsonrpc-client"), exports);
__exportStar(require("./client-server-protocol/jsonrpc/glsp-jsonrpc-server"), exports);
__exportStar(require("./client-server-protocol/jsonrpc/websocket-connection"), exports);
__exportStar(require("./client-server-protocol/types"), exports);
__exportStar(require("./disposable/disposable"), exports);
__exportStar(require("./model/default-types"), exports);
__exportStar(require("./model/model-schema"), exports);
__exportStar(require("./utils/array-util"), exports);
__exportStar(require("./utils/di-util"), exports);
__exportStar(require("./utils/type-util"), exports);
//# sourceMappingURL=index.js.map
/********************************************************************************
* Copyright (c) 2019-2022 EclipseSource and others.
* Copyright (c) 2019-2023 EclipseSource and others.
*

@@ -20,3 +20,3 @@ * This program and the accompanying materials are made available under the

*/
export declare type MaybeArray<T> = T | T[];
export type MaybeArray<T> = T | T[];
/**

@@ -70,2 +70,8 @@ * Returns the first element of the given array.

/**
* Helper function to convert a {@link MaybeArray} into an array.
* @param maybe The MaybeArray to convert
* @returns The corresponding array
*/
export declare function asArray<T>(maybe: MaybeArray<T>): T[];
/**
* Adds the given values to the given array. The add operation is executed distinct meaning

@@ -72,0 +78,0 @@ * a value will not be pushed to the array if its already present in the array.

"use strict";
/********************************************************************************
* Copyright (c) 2019-2022 EclipseSource and others.
* Copyright (c) 2019-2023 EclipseSource and others.
*

@@ -18,3 +18,3 @@ * This program and the accompanying materials are made available under the

Object.defineProperty(exports, "__esModule", { value: true });
exports.isArrayMatching = exports.isStringArray = exports.isArrayOfPrimitive = exports.isArrayOfClass = exports.isArrayOfType = exports.distinctAdd = exports.flatPush = exports.remove = exports.pluck = exports.last = exports.first = void 0;
exports.isArrayMatching = exports.isStringArray = exports.isArrayOfPrimitive = exports.isArrayOfClass = exports.isArrayOfType = exports.distinctAdd = exports.asArray = exports.flatPush = exports.remove = exports.pluck = exports.last = exports.first = void 0;
function first(array, n) {

@@ -70,2 +70,14 @@ if (n) {

/**
* Helper function to convert a {@link MaybeArray} into an array.
* @param maybe The MaybeArray to convert
* @returns The corresponding array
*/
function asArray(maybe) {
if (Array.isArray(maybe)) {
return maybe;
}
return [maybe];
}
exports.asArray = asArray;
/**
* Adds the given values to the given array. The add operation is executed distinct meaning

@@ -72,0 +84,0 @@ * a value will not be pushed to the array if its already present in the array.

/********************************************************************************
* Copyright (c) 2021-2022 EclipseSource and others.
* Copyright (c) 2021-2023 EclipseSource and others.
*

@@ -16,8 +16,3 @@ * This program and the accompanying materials are made available under the

********************************************************************************/
/**
* The built-in 'object' & 'Object' types are currently hard to use
* an should be avoided. It's recommended to use Record instead to describe the
* type meaning of "any object";
*/
export declare type AnyObject = Record<PropertyKey, unknown>;
export type AnyObject = object;
export declare namespace AnyObject {

@@ -34,3 +29,3 @@ /**

*/
export declare type Primitive = string | number | boolean | bigint | symbol | undefined | null;
export type Primitive = string | number | boolean | bigint | symbol | undefined | null;
/**

@@ -47,13 +42,17 @@ * Utility type to describe objects that have a constructor function i.e. classes.

*/
export declare type Writable<T> = {
export type Writable<T> = {
-readonly [P in keyof T]: Writable<T[P]>;
};
/**
* Utility type to describe a value as might be provided as a promise.
*/
export type MaybePromise<T> = T | PromiseLike<T>;
/**
* Utility type to describe typeguard functions.
*/
export declare type TypeGuard<T> = (element: any, ...args: any[]) => element is T;
export type TypeGuard<T> = (element: any) => element is T;
/**
* Utility function that create a typeguard function for a given class constructor.
* Essentially this wraps an instance of check as typeguard function.
* @param constructor The constructor fo the class for which the typeguard should be created.
* @param constructor The constructor of the class for which the typeguard should be created.
* @returns The typeguard for this class.

@@ -63,36 +62,49 @@ */

/**
* Validates whether the given object as a property of type `string` with the given key.
* Validates whether the given object has a property of type `string` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `string`.
*/
export declare function hasStringProp(object: AnyObject, propertyKey: string): boolean;
export declare function hasStringProp(object: AnyObject, propertyKey: string, optional?: boolean): boolean;
/**
* Validates whether the given object as a property of type `boolean` with the given key.
* Validates whether the given object has a property of type `boolean` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `boolean`.
*/
export declare function hasBooleanProp(object: AnyObject, propertyKey: string): boolean;
export declare function hasBooleanProp(object: AnyObject, propertyKey: string, optional?: boolean): boolean;
/**
* Validates whether the given object as a property of type `number` with the given key.
* Validates whether the given object has a property of type `number` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `number`.
*/
export declare function hasNumberProp(object: AnyObject, propertyKey: string): boolean;
export declare function hasNumberProp(object: AnyObject, propertyKey: string, optional?: boolean): boolean;
/**
* Validates whether the given object as a property of type `object` with the given key.
* Validates whether the given object has a property of type `object` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `object`.
*/
export declare function hasObjectProp(object: AnyObject, propertyKey: string): boolean;
export declare function hasObjectProp(object: AnyObject, propertyKey: string, optional?: boolean): boolean;
/**
* Validates whether the given object as a property of type `Array` with the given key.
* Validates whether the given object has a property of type `function` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `function`.
*/
export declare function hasFunctionProp(object: AnyObject, propertyKey: string, optional?: boolean): boolean;
/**
* Validates whether the given object has a property of type `Array` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `Array`.
*/
export declare function hasArrayProp(object: AnyObject, propertyKey: string): boolean;
export declare function hasArrayProp(object: AnyObject, propertyKey: string, optional?: boolean): boolean;
//# sourceMappingURL=type-util.d.ts.map
"use strict";
/********************************************************************************
* Copyright (c) 2021-2022 EclipseSource and others.
* Copyright (c) 2021-2023 EclipseSource and others.
*

@@ -18,3 +18,3 @@ * This program and the accompanying materials are made available under the

Object.defineProperty(exports, "__esModule", { value: true });
exports.hasArrayProp = exports.hasObjectProp = exports.hasNumberProp = exports.hasBooleanProp = exports.hasStringProp = exports.toTypeGuard = exports.AnyObject = void 0;
exports.hasArrayProp = exports.hasFunctionProp = exports.hasObjectProp = exports.hasNumberProp = exports.hasBooleanProp = exports.hasStringProp = exports.toTypeGuard = exports.AnyObject = void 0;
var AnyObject;

@@ -36,3 +36,3 @@ (function (AnyObject) {

* Essentially this wraps an instance of check as typeguard function.
* @param constructor The constructor fo the class for which the typeguard should be created.
* @param constructor The constructor of the class for which the typeguard should be created.
* @returns The typeguard for this class.

@@ -45,51 +45,67 @@ */

/**
* Validates whether the given object as a property of type `string` with the given key.
* Validates whether the given object has a property of type `string` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `string`.
*/
function hasStringProp(object, propertyKey) {
return propertyKey in object && typeof object[propertyKey] === 'string';
function hasStringProp(object, propertyKey, optional = false) {
return propertyKey in object ? typeof object[propertyKey] === 'string' : optional;
}
exports.hasStringProp = hasStringProp;
/**
* Validates whether the given object as a property of type `boolean` with the given key.
* Validates whether the given object has a property of type `boolean` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `boolean`.
*/
function hasBooleanProp(object, propertyKey) {
return propertyKey in object && typeof object[propertyKey] === 'boolean';
function hasBooleanProp(object, propertyKey, optional = false) {
return propertyKey in object ? typeof object[propertyKey] === 'boolean' : optional;
}
exports.hasBooleanProp = hasBooleanProp;
/**
* Validates whether the given object as a property of type `number` with the given key.
* Validates whether the given object has a property of type `number` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `number`.
*/
function hasNumberProp(object, propertyKey) {
return propertyKey in object && typeof object[propertyKey] === 'number';
function hasNumberProp(object, propertyKey, optional = false) {
return propertyKey in object ? typeof object[propertyKey] === 'number' : optional;
}
exports.hasNumberProp = hasNumberProp;
/**
* Validates whether the given object as a property of type `object` with the given key.
* Validates whether the given object has a property of type `object` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `object`.
*/
function hasObjectProp(object, propertyKey) {
return propertyKey in object && AnyObject.is(object[propertyKey]);
function hasObjectProp(object, propertyKey, optional = false) {
return propertyKey in object ? AnyObject.is(object[propertyKey]) : optional;
}
exports.hasObjectProp = hasObjectProp;
/**
* Validates whether the given object as a property of type `Array` with the given key.
* Validates whether the given object has a property of type `function` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `function`.
*/
function hasFunctionProp(object, propertyKey, optional = false) {
return propertyKey in object ? typeof object[propertyKey] === 'function' : optional;
}
exports.hasFunctionProp = hasFunctionProp;
/**
* Validates whether the given object has a property of type `Array` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `Array`.
*/
function hasArrayProp(object, propertyKey) {
return propertyKey in object && Array.isArray(object[propertyKey]);
function hasArrayProp(object, propertyKey, optional = false) {
return propertyKey in object ? Array.isArray(object[propertyKey]) : optional;
}
exports.hasArrayProp = hasArrayProp;
//# sourceMappingURL=type-util.js.map
{
"name": "@eclipse-glsp/protocol",
"version": "1.1.0-next.7ff1b00.184+7ff1b00",
"version": "1.1.0-next.80bb01c.251+80bb01c",
"description": "The protocol definition for client-server communication in GLSP",
"license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)",
"keywords": [

@@ -15,6 +14,4 @@ "eclipse",

],
"author": {
"name": "Eclipse GLSP"
},
"homepage": "https://www.eclipse.org/glsp/",
"bugs": "https://github.com/eclipse-glsp/glsp/issues",
"repository": {

@@ -24,3 +21,6 @@ "type": "git",

},
"bugs": "https://github.com/eclipse-glsp/glsp/issues",
"license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)",
"author": {
"name": "Eclipse GLSP"
},
"contributors": [

@@ -33,2 +33,4 @@ {

],
"main": "lib/index",
"types": "lib/index",
"files": [

@@ -38,6 +40,17 @@ "lib",

],
"scripts": {
"build": "tsc -b",
"clean": "rimraf lib tsconfig.tsbuildinfo coverage .nyc_output ",
"lint": "eslint --ext .ts,.tsx ./src",
"lint:ci": "yarn lint -o eslint.xml -f checkstyle",
"prepare": "yarn clean && yarn build",
"test": "mocha --config ../../.mocharc \"./src/**/*.spec.?(ts|tsx)\"",
"test:ci": "export JUNIT_REPORT_PATH=./report.xml && yarn test --reporter mocha-jenkins-reporter",
"test:coverage": "nyc yarn test",
"watch": "tsc -w"
},
"dependencies": {
"sprotty-protocol": "0.12.0",
"sprotty-protocol": "0.14.0-next.02bbac0.26",
"uuid": "7.0.3",
"vscode-ws-jsonrpc": "0.2.0"
"vscode-jsonrpc": "^8.0.2"
},

@@ -47,10 +60,4 @@ "devDependencies": {

},
"scripts": {
"prepare": "yarn clean && yarn build && yarn lint",
"clean": "rimraf lib tsconfig.tsbuildinfo ",
"build": "tsc",
"lint": "eslint -c ./.eslintrc.js --ext .ts ./src",
"test": "mocha --config ../../.mocharc.json \"./src/**/*.spec.?(ts|tsx)\"",
"test:ci": "export JUNIT_REPORT_PATH=./report.xml && yarn test --reporter mocha-jenkins-reporter",
"watch": "tsc -w"
"peerDependencies": {
"inversify": "^5.1.1"
},

@@ -60,5 +67,3 @@ "publishConfig": {

},
"main": "lib/index",
"types": "lib/index",
"gitHead": "7ff1b00a1575eb1979aa69e8e2873807883d9c6a"
"gitHead": "80bb01c5e0129da59b31c75395f9cead632c512b"
}

@@ -1,4 +0,5 @@

# Eclipse GLSP - Client [![build-status](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fci.eclipse.org%2Fglsp%2Fjob%2Feclipse-glsp%2Fjob%2Fglsp-client%2Fjob%2Fmaster%2F)](https://ci.eclipse.org/glsp/job/eclipse-glsp/job/glsp-client/job/master) [![build-status-server](https://img.shields.io/jenkins/build?jobUrl=https://ci.eclipse.org/glsp/job/deploy-npm-glsp-client/&label=publish)](https://ci.eclipse.org/glsp/job/deploy-npm-glsp-client/)
# Eclipse GLSP - Protocol
The generic client-server communication protocol for the [Graphical Language Server Platform (GLSP)](https://github.com/eclipse-glsp/glsp) and a json-rpc based default implementation.
In addition, this package provides shared common code and utility libraries for GLSP components.

@@ -10,4 +11,4 @@ This project is built with `yarn` and is available from npm via [@eclipse-glsp/protocol](https://www.npmjs.com/package/@eclipse-glsp/protocol).

For more information, please visit the [Eclipse GLSP Umbrella repository](https://github.com/eclipse-glsp/glsp) and the [Eclipse GLSP Website](https://www.eclipse.org/glsp/).
If you have questions, contact us on our [spectrum chat](https://spectrum.chat/glsp/) and have a look at our [communication and support options](https://www.eclipse.org/glsp/contact/).
If you have questions, please raise them in the [discussions](https://github.com/eclipse-glsp/glsp/discussions) and have a look at our [communication and support options](https://www.eclipse.org/glsp/contact/).
![alt](https://www.eclipse.org/glsp/images/diagramanimated.gif)
/********************************************************************************
* Copyright (c) 2021-2022 STMicroelectronics and others.
* Copyright (c) 2021-2023 STMicroelectronics and others.
*

@@ -68,3 +68,3 @@ * This program and the accompanying materials are made available under the

const actionGuard = typeguard ?? Action.is;
return AnyObject.is(object) && hasStringProp(object, 'clientId') && actionGuard(object.action);
return AnyObject.is(object) && hasStringProp(object, 'clientId') && 'action' in object && actionGuard(object.action);
}

@@ -71,0 +71,0 @@ }

@@ -18,2 +18,3 @@ /********************************************************************************

import { Point } from 'sprotty-protocol';
import * as sprotty from 'sprotty-protocol/lib/actions';
import { hasArrayProp, hasStringProp } from '../utils/type-util';

@@ -135,3 +136,3 @@ import { Operation } from './base-protocol';

*/
export interface DeleteElementOperation extends Operation {
export interface DeleteElementOperation extends Operation, Omit<sprotty.DeleteElementAction, 'kind'> {
kind: typeof DeleteElementOperation.KIND;

@@ -138,0 +139,0 @@

/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*

@@ -107,3 +107,3 @@ * This program and the accompanying materials are made available under the

kind: 'setEditValidationResult',
responseId: 'myRespsone',
responseId: 'myResponse',
args: { some: 'args' },

@@ -110,0 +110,0 @@ status: { severity: ValidationStatus.Severity.OK }

/********************************************************************************
* Copyright (c) 2020-2022 EclipseSource and others.
* Copyright (c) 2020-2023 EclipseSource and others.
*

@@ -16,2 +16,3 @@ * This program and the accompanying materials are made available under the

********************************************************************************/
import * as sprotty from 'sprotty-protocol/lib/actions';
import { hasObjectProp, hasStringProp } from '../utils/type-util';

@@ -111,3 +112,3 @@ import { Action, Operation, RequestAction, ResponseAction } from './base-protocol';

*/
export interface ApplyLabelEditOperation extends Operation {
export interface ApplyLabelEditOperation extends Operation, sprotty.ApplyLabelEditAction {
kind: typeof ApplyLabelEditOperation.KIND;

@@ -168,3 +169,2 @@

*/
// eslint-disable-next-line no-shadow
export enum Severity {

@@ -176,3 +176,2 @@ FATAL,

OK,
// eslint-disable-next-line no-shadow
NONE

@@ -179,0 +178,0 @@ }

/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*

@@ -48,3 +48,4 @@ * This program and the accompanying materials are made available under the

requestId: '',
elementsIDs: ['myIds']
elementsIDs: ['myIds'],
reason: 'batch'
};

@@ -58,3 +59,4 @@ const { elementsIDs } = expected;

requestId: 'myRequest',
elementsIDs: ['myIds']
elementsIDs: ['myIds'],
reason: 'batch'
};

@@ -90,2 +92,3 @@ const { elementsIDs, requestId } = expected;

responseId: '',
reason: 'batch',
markers: [{ description: 'desc', elementId: 'myId', kind: 'info', label: 'string' }]

@@ -100,2 +103,3 @@ };

responseId: 'myResponse',
reason: 'batch',
markers: [{ description: 'desc', elementId: 'myId', kind: 'info', label: 'string' }]

@@ -102,0 +106,0 @@ };

/********************************************************************************
* Copyright (c) 2021-2022 STMicroelectronics and others.
* Copyright (c) 2021-2023 STMicroelectronics and others.
*

@@ -51,2 +51,12 @@ * This program and the accompanying materials are made available under the

/**
* The default reasons for markers.
*/
export namespace MarkersReason {
/** Markers resulting from a batch validation */
export const BATCH = 'batch';
/** Markers resulting from a live validation */
export const LIVE = 'live';
}
/**
* Action to retrieve markers for the specified model elements. Sent from the client to the server.

@@ -63,2 +73,7 @@ * The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks

elementsIDs: string[];
/**
* The reason for this request, such as `batch` or `live` validation. `batch` by default.
*/
reason?: string;
}

@@ -73,3 +88,3 @@

export function create(elementsIDs: string[], options: { requestId?: string } = {}): RequestMarkersAction {
export function create(elementsIDs: string[], options: { requestId?: string; reason?: string } = {}): RequestMarkersAction {
return {

@@ -79,2 +94,3 @@ kind: KIND,

elementsIDs,
reason: MarkersReason.BATCH,
...options

@@ -99,2 +115,7 @@ };

readonly markers: Marker[];
/**
* The reason for message, such as `batch` or `live` validation.
*/
reason?: string;
}

@@ -109,3 +130,3 @@

export function create(markers: Marker[], options: { responseId?: string } = {}): SetMarkersAction {
export function create(markers: Marker[], options: { responseId?: string; reason?: string } = {}): SetMarkersAction {
return {

@@ -115,2 +136,3 @@ kind: KIND,

markers,
reason: MarkersReason.BATCH,
...options

@@ -117,0 +139,0 @@ };

@@ -100,6 +100,7 @@ /********************************************************************************

revision: 5,
bounds: [{ elementId: '', newSize: Dimension.EMPTY, newPosition: Point.ORIGIN }]
bounds: [{ elementId: '', newSize: Dimension.EMPTY, newPosition: Point.ORIGIN }],
routes: [{ elementId: 'myEdge', newRoutingPoints: [{ x: 42, y: 1337 }] }]
};
const { bounds, responseId, alignments, revision } = expected;
expect(ComputedBoundsAction.create(bounds, { responseId, alignments, revision })).to.deep.equals(expected);
const { bounds, responseId, alignments, revision, routes } = expected;
expect(ComputedBoundsAction.create(bounds, { responseId, alignments, revision, routes })).to.deep.equals(expected);
});

@@ -106,0 +107,0 @@ });

/********************************************************************************
* Copyright (c) 2021-2022 STMicroelectronics and others.
* Copyright (c) 2021-2023 STMicroelectronics and others.
*

@@ -20,3 +20,3 @@ * This program and the accompanying materials are made available under the

import { SModelRootSchema } from './model-structure';
import { ElementAndAlignment, ElementAndBounds } from './types';
import { ElementAndAlignment, ElementAndBounds, ElementAndRoutingPoints } from './types';

@@ -78,2 +78,7 @@ /**

alignments?: ElementAndAlignment[];
/**
* The route of the model elements.
*/
routes?: ElementAndRoutingPoints[];
}

@@ -94,2 +99,3 @@

alignments?: ElementAndAlignment[];
routes?: ElementAndRoutingPoints[];
} = {}

@@ -115,5 +121,5 @@ ): ComputedBoundsAction {

/**
* The identifiers of the elements that should be layouted, may be just the root element.
* The identifiers of the elements that should be layouted, will default to the root element if not defined.
*/
elementIds: string[];
elementIds?: string[];
}

@@ -128,3 +134,3 @@

export function create(elementIds: string[]): LayoutOperation {
export function create(elementIds?: string[]): LayoutOperation {
return {

@@ -131,0 +137,0 @@ kind: KIND,

/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*

@@ -21,3 +21,3 @@ * This program and the accompanying materials are made available under the

describe('Tool palette Actions', () => {
describe('TrigerNodeCreationAction', () => {
describe('TriggerNodeCreationAction', () => {
describe('is', () => {

@@ -24,0 +24,0 @@ it('should return true for an object having the correct type and a value for all required interface properties', () => {

@@ -17,19 +17,18 @@ /********************************************************************************

import { expect } from 'chai';
import { RedoOperation, UndoOperation } from './undo-redo';
import { RedoAction, UndoAction } from './undo-redo';
describe('Undo & Redo Actions', () => {
describe('UndoOperation', () => {
describe('UndoAction', () => {
describe('is', () => {
it('should return true for an object having the correct type and a value for all required interface properties', () => {
const action: UndoOperation = {
kind: 'glspUndo',
isOperation: true
const action: UndoAction = {
kind: 'glspUndo'
};
expect(UndoOperation.is(action)).to.be.true;
expect(UndoAction.is(action)).to.be.true;
});
it('should return false for `undefined`', () => {
expect(UndoOperation.is(undefined)).to.be.false;
expect(UndoAction.is(undefined)).to.be.false;
});
it('should return false for an object that does not have all required interface properties', () => {
expect(UndoOperation.is({ kind: 'notTheRightOne' })).to.be.false;
expect(UndoAction.is({ kind: 'notTheRightOne' })).to.be.false;
});

@@ -40,7 +39,6 @@ });

it('should return an object conforming to the interface with matching properties for the given required arguments', () => {
const expected: UndoOperation = {
kind: 'glspUndo',
isOperation: true
const expected: UndoAction = {
kind: 'glspUndo'
};
expect(UndoOperation.create()).to.deep.equals(expected);
expect(UndoAction.create()).to.deep.equals(expected);
});

@@ -50,16 +48,15 @@ });

describe('RedoOperation', () => {
describe('RedoAction', () => {
describe('is', () => {
it('should return true for an object having the correct type and a value for all required interface properties', () => {
const action: RedoOperation = {
kind: 'glspRedo',
isOperation: true
const action: RedoAction = {
kind: 'glspRedo'
};
expect(RedoOperation.is(action)).to.be.true;
expect(RedoAction.is(action)).to.be.true;
});
it('should return false for `undefined`', () => {
expect(RedoOperation.is(undefined)).to.be.false;
expect(RedoAction.is(undefined)).to.be.false;
});
it('should return false for an object that does not have all required interface properties', () => {
expect(RedoOperation.is({ kind: 'notTheRightOne' })).to.be.false;
expect(RedoAction.is({ kind: 'notTheRightOne' })).to.be.false;
});

@@ -70,7 +67,6 @@ });

it('should return an object conforming to the interface with matching properties for the given required arguments', () => {
const expected: RedoOperation = {
kind: 'glspRedo',
isOperation: true
const expected: RedoAction = {
kind: 'glspRedo'
};
expect(RedoOperation.create()).to.deep.equals(expected);
expect(RedoAction.create()).to.deep.equals(expected);
});

@@ -77,0 +73,0 @@ });

@@ -17,24 +17,23 @@ /********************************************************************************

import { Operation } from './base-protocol';
import * as sprotty from 'sprotty-protocol/lib/actions';
import { Action } from './base-protocol';
/**
* Trigger an undo of the latest executed command.
* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks
* and creating new `UndoOperations`.
* and creating new `UndoAction`.
*/
export interface UndoOperation extends Operation {
kind: typeof UndoOperation.KIND;
export interface UndoAction extends Omit<sprotty.UndoAction, 'kind'> {
kind: typeof UndoAction.KIND;
}
export namespace UndoOperation {
export namespace UndoAction {
export const KIND = 'glspUndo';
export function is(object: any): object is UndoOperation {
return Operation.hasKind(object, KIND);
export function is(object: any): object is UndoAction {
return Action.hasKind(object, KIND);
}
export function create(): UndoOperation {
export function create(): UndoAction {
return {
kind: KIND,
isOperation: true
kind: KIND
};

@@ -47,21 +46,20 @@ }

* The corresponding namespace declares the action kind as constant and offers helper functions for type guard checks
* and creating new `RedoOperations`.
* and creating new `RedoAction`.
*/
export interface RedoOperation extends Operation {
kind: typeof RedoOperation.KIND;
export interface RedoAction extends Omit<sprotty.RedoAction, 'kind'> {
kind: typeof RedoAction.KIND;
}
export namespace RedoOperation {
export namespace RedoAction {
export const KIND = 'glspRedo';
export function is(object: any): object is RedoOperation {
return Operation.hasKind(object, KIND);
export function is(object: any): object is RedoAction {
return Action.hasKind(object, KIND);
}
export function create(): RedoOperation {
export function create(): RedoAction {
return {
kind: KIND,
isOperation: true
kind: KIND
};
}
}
/********************************************************************************
* Copyright (c) 2020-2022 EclipseSource and others.
* Copyright (c) 2020-2023 EclipseSource and others.
*

@@ -22,3 +22,3 @@ * This program and the accompanying materials are made available under the

declare module 'sprotty-protocol/lib/actions' {
// eslint-disable-next-line no-shadow
// eslint-disable-next-line @typescript-eslint/no-shadow
namespace SetViewportAction {

@@ -28,3 +28,3 @@ export function is(object: any): object is SetViewportAction;

// eslint-disable-next-line no-shadow
// eslint-disable-next-line @typescript-eslint/no-shadow
namespace SetBoundsAction {

@@ -52,9 +52,16 @@ export function is(object: any): object is SetBoundsAction;

export * from './action-protocol';
export * from './glsp-client';
export * from './jsonrpc/base-jsonrpc-glsp-client';
export * from './jsonrpc/glsp-jsonrpc-client';
export * from './client-server-protocol/base-glsp-client';
export * from './client-server-protocol/glsp-client';
export * from './client-server-protocol/glsp-server';
export * from './client-server-protocol/jsonrpc/base-jsonrpc-glsp-client';
export * from './client-server-protocol/jsonrpc/glsp-jsonrpc-client';
export * from './client-server-protocol/jsonrpc/glsp-jsonrpc-server';
export * from './client-server-protocol/jsonrpc/websocket-connection';
export * from './client-server-protocol/types';
export * from './disposable/disposable';
export * from './model/default-types';
export * from './model/model-schema';
export * from './utils/array-util';
export * from './utils/di-util';
export * from './utils/type-util';
export { SetBoundsAction, SetViewportAction };
/********************************************************************************
* Copyright (c) 2019-2022 EclipseSource and others.
* Copyright (c) 2019-2023 EclipseSource and others.
*

@@ -102,2 +102,13 @@ * This program and the accompanying materials are made available under the

/**
* Helper function to convert a {@link MaybeArray} into an array.
* @param maybe The MaybeArray to convert
* @returns The corresponding array
*/
export function asArray<T>(maybe: MaybeArray<T>): T[] {
if (Array.isArray(maybe)) {
return maybe;
}
return [maybe];
}
/**
* Adds the given values to the given array. The add operation is executed distinct meaning

@@ -104,0 +115,0 @@ * a value will not be pushed to the array if its already present in the array.

/********************************************************************************
* Copyright (c) 2022 STMicroelectronics and others.
* Copyright (c) 2022-2023 STMicroelectronics and others.
*

@@ -17,3 +17,3 @@ * This program and the accompanying materials are made available under the

import { expect } from 'chai';
import { AnyObject, hasArrayProp, hasBooleanProp, hasNumberProp, hasObjectProp, hasStringProp } from './type-util';
import { AnyObject, hasArrayProp, hasBooleanProp, hasFunctionProp, hasNumberProp, hasObjectProp, hasStringProp } from './type-util';

@@ -58,5 +58,11 @@ describe('TypeUtil', () => {

});
it('should return false for an object that does not have a property that matches the given key.', () => {
it('should return false for an object that does not have a property that matches the given key', () => {
expect(hasStringProp({ anotherProp: 123 }, 'someProp')).to.be.false;
});
it('should return true for an object that does not have a matching key when using the optional flag', () => {
expect(hasStringProp({ anotherProp: 123 }, 'someProp', true)).to.be.true;
});
it('should return false for an object that has a property with matching name but invalid type when using the optional flag', () => {
expect(hasStringProp({ someProp: 123 }, 'someProp', true)).to.be.false;
});
});

@@ -71,5 +77,11 @@

});
it('should return false for an object that does not have a property that matches the given key.', () => {
it('should return false for an object that does not have a property that matches the given key', () => {
expect(hasBooleanProp({ anotherProp: 123 }, 'someProp')).to.be.false;
});
it('should return true for an object that does not have a matching key when using the optional flag', () => {
expect(hasBooleanProp({ anotherProp: 123 }, 'someProp', true)).to.be.true;
});
it('should return false for an object that has a property with matching name but invalid type when using the optional flag', () => {
expect(hasBooleanProp({ someProp: 123 }, 'someProp', true)).to.be.false;
});
});

@@ -84,5 +96,11 @@

});
it('should return false for an object that does not have a property that matches the given key.', () => {
expect(hasBooleanProp({ anotherProp: 123 }, 'someProp')).to.be.false;
it('should return false for an object that does not have a property that matches the given key', () => {
expect(hasNumberProp({ anotherProp: 123 }, 'someProp')).to.be.false;
});
it('should return true for an object that does not have a matching key when using the optional flag', () => {
expect(hasNumberProp({ anotherProp: 123 }, 'someProp', true)).to.be.true;
});
it('should return false for an object that has a property with matching name but invalid type when using the optional flag', () => {
expect(hasNumberProp({ someProp: '123' }, 'someProp', true)).to.be.false;
});
});

@@ -97,7 +115,32 @@

});
it('should return false for an object that does not have a property that matches the given key.', () => {
it('should return false for an object that does not have a property that matches the given key', () => {
expect(hasObjectProp({ anotherProp: 123 }, 'someProp')).to.be.false;
});
it('should return true for an object that does not have a matching key when using the optional flag', () => {
expect(hasObjectProp({ anotherProp: 123 }, 'someProp', true)).to.be.true;
});
it('should return false for an object that has a property with matching name but invalid type when using the optional flag', () => {
expect(hasObjectProp({ someProp: 123 }, 'someProp', true)).to.be.false;
});
});
describe('hasFunctionProp', () => {
it('should return true for an object that has a property that matches the given key and type', () => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect(hasFunctionProp({ someProp: () => {} }, 'someProp')).to.be.true;
});
it('should return false for an object that has a property that matches the given but not the given type', () => {
expect(hasFunctionProp({ someProp: '123' }, 'someProp')).to.be.false;
});
it('should return false for an object that does not have a property that matches the given key', () => {
expect(hasFunctionProp({ anotherProp: 123 }, 'someProp')).to.be.false;
});
it('should return true for an object that does not have a matching key when using the optional flag', () => {
expect(hasFunctionProp({ anotherProp: 123 }, 'someProp', true)).to.be.true;
});
it('should return false for an object that has a property with matching name but invalid type when using the optional flag', () => {
expect(hasFunctionProp({ someProp: 123 }, 'someProp', true)).to.be.false;
});
});
describe('hasArrayProp', () => {

@@ -110,6 +153,12 @@ it('should return true for an object that has a property that matches the given key and type', () => {

});
it('should return false for an object that does not have a property that matches the given key.', () => {
it('should return false for an object that does not have a property that matches the given key', () => {
expect(hasArrayProp({ anotherProp: 123 }, 'someProp')).to.be.false;
});
it('should return true for an object that does not have a matching key when using the optional flag', () => {
expect(hasArrayProp({ anotherProp: 123 }, 'someProp', true)).to.be.true;
});
it('should return false for an object that has a property with matching name but invalid type when using the optional flag', () => {
expect(hasArrayProp({ someProp: 123 }, 'someProp', true)).to.be.false;
});
});
});
/********************************************************************************
* Copyright (c) 2021-2022 EclipseSource and others.
* Copyright (c) 2021-2023 EclipseSource and others.
*

@@ -17,8 +17,3 @@ * This program and the accompanying materials are made available under the

/**
* The built-in 'object' & 'Object' types are currently hard to use
* an should be avoided. It's recommended to use Record instead to describe the
* type meaning of "any object";
*/
export type AnyObject = Record<PropertyKey, unknown>;
export type AnyObject = object;

@@ -58,5 +53,10 @@ export namespace AnyObject {

/**
* Utility type to describe a value as might be provided as a promise.
*/
export type MaybePromise<T> = T | PromiseLike<T>;
/**
* Utility type to describe typeguard functions.
*/
export type TypeGuard<T> = (element: any, ...args: any[]) => element is T;
export type TypeGuard<T> = (element: any) => element is T;

@@ -66,57 +66,73 @@ /**

* Essentially this wraps an instance of check as typeguard function.
* @param constructor The constructor fo the class for which the typeguard should be created.
* @param constructor The constructor of the class for which the typeguard should be created.
* @returns The typeguard for this class.
*/
export function toTypeGuard<G>(constructor: Constructor<G>): TypeGuard<G> {
return (element: any): element is G => element instanceof constructor;
return (element: unknown): element is G => element instanceof constructor;
}
/**
* Validates whether the given object as a property of type `string` with the given key.
* Validates whether the given object has a property of type `string` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `string`.
*/
export function hasStringProp(object: AnyObject, propertyKey: string): boolean {
return propertyKey in object && typeof object[propertyKey] === 'string';
export function hasStringProp(object: AnyObject, propertyKey: string, optional = false): boolean {
return propertyKey in object ? typeof (object as any)[propertyKey] === 'string' : optional;
}
/**
* Validates whether the given object as a property of type `boolean` with the given key.
* Validates whether the given object has a property of type `boolean` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `boolean`.
*/
export function hasBooleanProp(object: AnyObject, propertyKey: string): boolean {
return propertyKey in object && typeof object[propertyKey] === 'boolean';
export function hasBooleanProp(object: AnyObject, propertyKey: string, optional = false): boolean {
return propertyKey in object ? typeof (object as any)[propertyKey] === 'boolean' : optional;
}
/**
* Validates whether the given object as a property of type `number` with the given key.
* Validates whether the given object has a property of type `number` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `number`.
*/
export function hasNumberProp(object: AnyObject, propertyKey: string): boolean {
return propertyKey in object && typeof object[propertyKey] === 'number';
export function hasNumberProp(object: AnyObject, propertyKey: string, optional = false): boolean {
return propertyKey in object ? typeof (object as any)[propertyKey] === 'number' : optional;
}
/**
* Validates whether the given object as a property of type `object` with the given key.
* Validates whether the given object has a property of type `object` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `object`.
*/
export function hasObjectProp(object: AnyObject, propertyKey: string): boolean {
return propertyKey in object && AnyObject.is(object[propertyKey]);
export function hasObjectProp(object: AnyObject, propertyKey: string, optional = false): boolean {
return propertyKey in object ? AnyObject.is((object as any)[propertyKey]) : optional;
}
/**
* Validates whether the given object as a property of type `Array` with the given key.
* Validates whether the given object has a property of type `function` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `function`.
*/
export function hasFunctionProp(object: AnyObject, propertyKey: string, optional = false): boolean {
return propertyKey in object ? typeof (object as any)[propertyKey] === 'function' : optional;
}
/**
* Validates whether the given object has a property of type `Array` with the given key.
* @param object The object that should be validated
* @param propertyKey The key of the property
* @param optional Flag to indicate wether the property can be optional i.e. also return true if the given key is undefined
* @returns `true` if the object has property with matching key of type `Array`.
*/
export function hasArrayProp(object: AnyObject, propertyKey: string): boolean {
return propertyKey in object && Array.isArray(object[propertyKey]);
export function hasArrayProp(object: AnyObject, propertyKey: string, optional = false): boolean {
return propertyKey in object ? Array.isArray((object as any)[propertyKey]) : optional;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc