New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@eclipse-emfcloud/modelserver-node

Package Overview
Dependencies
Maintainers
8
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eclipse-emfcloud/modelserver-node - npm Package Compare versions

Comparing version 0.2.0-next.16b2e5e.24 to 0.2.0-next.272d84f.34

lib/client/promise-utils.d.ts

7

lib/client/model-server-client.d.ts

@@ -136,2 +136,9 @@ /********************************************************************************

}
/**
* Query whether an `object` is any kind of `ModelServerCommand`.
*
* @param object an object
* @returns whether it is a `ModelServerCommand` of some kind
*/
export declare function isModelServerCommand(object: any): object is ModelServerCommand;
//# sourceMappingURL=model-server-client.d.ts.map

52

lib/client/model-server-client.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.InternalModelServerClient = exports.ExecuteMessageBody = exports.InternalModelServerClientApi = exports.UpstreamConnectionConfig = void 0;
exports.isModelServerCommand = exports.InternalModelServerClient = exports.ExecuteMessageBody = exports.InternalModelServerClientApi = exports.UpstreamConnectionConfig = void 0;
/********************************************************************************

@@ -33,2 +33,3 @@ * Copyright (c) 2022 STMicroelectronics.

const trigger_provider_registry_1 = require("../trigger-provider-registry");
const promise_utils_1 = require("./promise-utils");
const web_socket_utils_1 = require("./web-socket-utils");

@@ -234,2 +235,3 @@ exports.UpstreamConnectionConfig = Symbol('UpstreamConnectionConfig');

this.rollback = this.rollback.bind(this);
this.uuid = promise_utils_1.CompletablePromise.newPromise();
}

@@ -243,3 +245,3 @@ /**

open(closeCallback) {
const result = new Promise((resolve, reject) => {
const result = new Promise((resolveTransaction, reject) => {
this.closeCallback = closeCallback;

@@ -255,3 +257,8 @@ const wsURI = new URL(this.transactionURI);

this.socket = socket;
resolve(this);
web_socket_utils_1.WebSocketMessageAcceptor.promise(this.socket, msg => typeof msg.data === 'string', modelserver_client_1.MessageDataMapper.asString)
.then(uuid_ => {
this.uuid.resolve(uuid_);
resolveTransaction(this);
})
.catch(this.uuid.reject);
};

@@ -269,2 +276,10 @@ socket.onmessage = event => {

}
/**
* Obtain the UUID of this transaction, when it has been received from the upstream server.
*
* @returns the UUID, when it is available
*/
getUUID() {
return this.uuid;
}
// Doc inherited from `Executor` interface

@@ -311,3 +326,3 @@ async applyPatch(patch) {

// It's a substitute command or patch. Just pass it on in the usual way
if (modelserver_client_1.ModelServerCommand.is(provided)) {
if (isModelServerCommand(provided)) {
return this.sendCommand(provided);

@@ -325,13 +340,16 @@ }

}
sendExecuteMessage(body) {
async sendExecuteMessage(body) {
if (!this.socket) {
return Promise.reject('Socket is closed.');
}
// Make sure that we have first processed the transaction opening exchange
await this.getUUID();
const { aggregatedUpdateResult: current } = this.peekNestedContext();
const result = web_socket_utils_1.WebSocketMessageAcceptor.promise(this.socket, message => {
const matched = message.type === 'success' && modelserver_client_1.Operations.isPatch(message.data.patch);
if (matched && current) {
this.mergeModelUpdateResult(current, message.data);
const result = web_socket_utils_1.WebSocketMessageAcceptor.promise(this.socket, message => true, // Need to accept and merge failed updates as well as successful
modelserver_client_1.MessageDataMapper.patchModel).then(modelUpdateResult => {
// If we are currently tracking a merged update result, incorporate this new result
if (current) {
this.mergeModelUpdateResult(current, modelUpdateResult);
}
return matched;
return modelUpdateResult;
});

@@ -385,3 +403,7 @@ this.socket.send(JSON.stringify(this.message('execute', body)));

if ((src === null || src === void 0 ? void 0 : src.patch) && src.patch.length) {
dst.success = dst.success && src.success;
dst.patch = ((_a = dst.patch) !== null && _a !== void 0 ? _a : []).concat(src.patch);
if (dst.success && src.patchModel) {
dst.patchModel = src.patchModel;
}
}

@@ -462,2 +484,12 @@ }

const transactionClosed = { success: false };
/**
* Query whether an `object` is any kind of `ModelServerCommand`.
*
* @param object an object
* @returns whether it is a `ModelServerCommand` of some kind
*/
function isModelServerCommand(object) {
return modelserver_client_1.ModelServerObject.is(object) && object.eClass.startsWith(modelserver_client_1.ModelServerCommandPackage.NS_URI + '#//');
}
exports.isModelServerCommand = isModelServerCommand;
//# sourceMappingURL=model-server-client.js.map

@@ -12,3 +12,3 @@ /// <reference types="node" />

*******************************************************************************/
import { AnyObject, ModelServerMessage, TypeGuard } from '@eclipse-emfcloud/modelserver-client';
import { AnyObject, MessageDataMapper, ModelServerMessage, TypeGuard } from '@eclipse-emfcloud/modelserver-client';
import { Request } from 'express';

@@ -87,3 +87,14 @@ import { Logger } from 'winston';

*/
static promise<U>(socket: WebSocket, predicate: (object: ModelServerMessage<U>) => boolean): Promise<U>;
static promise<D>(socket: WebSocket, predicate: (object: ModelServerMessage<D>) => boolean): Promise<D>;
/**
* Convenience for creating a promise that will be resolved when a message of the expected
* type is received, with transformation of the message by a mapper function.
* If the socket is closed before that, then the promise is rejected.
*
* @param socket the socket on which to wait for incoming messages
* @param predicate a test whether a message payload is of the expected type
* @param mapper a message data mapper to generate the promised result
* @returns a promise of the expected mapped message type
*/
static promise<D = unknown, U = unknown>(socket: WebSocket, predicate: (object: ModelServerMessage<D>) => boolean, mapper: MessageDataMapper<U>): Promise<U>;
}

@@ -90,0 +101,0 @@ /**

24

lib/client/web-socket-utils.js

@@ -106,13 +106,8 @@ "use strict";

}
/**
* Convenience for creating a promise that will be resolved when a message of the expected
* type is received. If the socket is closed before that, then the promise is rejected.
*
* @param socket the socket on which to wait for incoming messages
* @param predicate a test whether a message payload is of the expected type
* @returns a promise of the expected message type
*/
static promise(socket, predicate) {
static promise(socket, predicate, mapper) {
if (!mapper) {
mapper = modelserver_client_1.IdentityMapper;
}
return new Promise((resolve, reject) => {
const parser = message => (predicate(message) ? message.data : undefined);
const parser = message => (predicate(message) ? mapper(message) : undefined);
WebSocketMessageAcceptor.accept(socket, parser, resolve, () => reject('Socket closed'));

@@ -123,7 +118,6 @@ });

exports.WebSocketMessageAcceptor = WebSocketMessageAcceptor;
function toModelServerMessage(o) {
if (modelserver_client_1.ModelServerMessage.is(o)) {
// Convert $type to eClass for now
// TODO: API with correct $type property
return (0, modelserver_client_1.encode)('json')(o);
function toModelServerMessage(message) {
if (modelserver_client_1.ModelServerMessage.is(message)) {
// The received patch message is in format 'json-v2', therefore no additional encoding needed here
return message;
}

@@ -130,0 +124,0 @@ return undefined;

@@ -38,2 +38,6 @@ /********************************************************************************

unregister(commandType: string, ...provider: CommandProvider[]): void;
/**
* Query whether any command providers are registered.
*/
hasProviders(): boolean;
hasProvider(commandType: string): boolean;

@@ -40,0 +44,0 @@ getProviders(commandType: string): CommandProvider[];

@@ -70,2 +70,8 @@ "use strict";

}
/**
* Query whether any command providers are registered.
*/
hasProviders() {
return this.providers.size > 0;
}
hasProvider(commandType) {

@@ -72,0 +78,0 @@ return this.providers.has(commandType);

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

let result;
if (modelserver_client_1.ModelServerCommand.is(providedEdit)) {
if ((0, model_server_client_1.isModelServerCommand)(providedEdit)) {
// Command case

@@ -146,3 +146,3 @@ result = this.modelServerClient.edit(modelURI, providedEdit);

// It's a command or JSON Patch. Just execute/apply it in the usual way
if (modelserver_client_1.ModelServerCommand.is(providedEdit)) {
if ((0, model_server_client_1.isModelServerCommand)(providedEdit)) {
// Command case

@@ -242,3 +242,3 @@ await executor.execute(modelURI, providedEdit);

}
if (!(command instanceof modelserver_client_1.ModelServerCommand) && isModelServerCommand(command)) {
if (!(command instanceof modelserver_client_1.ModelServerCommand) && (0, model_server_client_1.isModelServerCommand)(command)) {
let proto;

@@ -267,5 +267,2 @@ switch (command.eClass) {

}
function isModelServerCommand(object) {
return modelserver_client_1.ModelServerObject.is(object) && object.eClass.startsWith(modelserver_client_1.ModelServerCommandPackage.NS_URI + '#//');
}
function isCustomCommand(command) {

@@ -272,0 +269,0 @@ return !(modelserver_client_1.SetCommand.is(command) || modelserver_client_1.AddCommand.is(command) || modelserver_client_1.RemoveCommand.is(command));

@@ -11,4 +11,6 @@ /********************************************************************************

*******************************************************************************/
import { Diagnostic } from '@eclipse-emfcloud/modelserver-client';
/// <reference types="node" />
import { Diagnostic, ModelServerMessage } from '@eclipse-emfcloud/modelserver-client';
import { Logger } from '@eclipse-emfcloud/modelserver-plugin-ext';
import { EventEmitter } from 'events';
import * as WebSocket from 'ws';

@@ -20,3 +22,3 @@ import { UpstreamConnectionConfig } from '../client/model-server-client';

*/
interface SubscriptionQuery {
export interface SubscriptionQuery {
/** The model URI to subscribe to. */

@@ -34,2 +36,3 @@ modeluri: string;

};
export declare type EventType = 'subscribed' | 'unsubscribed';
export declare class SubscriptionManager {

@@ -40,8 +43,38 @@ protected readonly logger: Logger;

protected readonly subscriptions: Map<Client, JSONSocket>;
addSubscription(client: WebSocket, endpoint: string, params: SubscriptionQuery): void;
protected readonly eventEmitter: EventEmitter;
addSubscription(client: WebSocket, endpoint: string, params: SubscriptionQuery): JSONSocket;
protected fireEvent(eventType: EventType, client: JSONSocket, params: SubscriptionQuery): void;
addSubscribedListener(listener: (client: JSONSocket, params: SubscriptionQuery) => void): this;
removeSubscribedListener(listener: (client: JSONSocket, params: SubscriptionQuery) => void): this;
addUnsubscribedListener(listener: (client: JSONSocket, params: SubscriptionQuery) => void): this;
removeUnsubscribedListener(listener: (client: JSONSocket, params: SubscriptionQuery) => void): this;
/**
* Retrieve subscribers on a model URI. If provided, the `filter` may be either
*
* - a `string` indicating a property of the subscription options that must have a truthy value, or
* - a `function` that tests whether the subscription options match some arbitrary predicate
*
* @param modelURI the model URI for which to get subscribers
* @param filter an optional subscriber filter, by options property or a generic predicate
* @returns the matching subscriber sockets
*/
protected getSubscribers(modelURI: string, filter?: keyof SubscriptionQuery | ((options: SubscriptionQuery) => boolean)): JSONSocket[];
/**
* Query whether any subscribers are registered on a model URI. If provided, the `filter` may be either
*
* - a `string` indicating a property of the subscription options that must have a truthy value, or
* - a `function` that tests whether the subscription options match some arbitrary predicate
*
* @param modelURI the model URI for which to get subscribers
* @param filter an optional subscriber filter, by options property or a generic predicate
* @returns whether any matching subscriptions exist
*/
protected hasSubscribers(modelURI: string, filter?: keyof SubscriptionQuery | ((options: SubscriptionQuery) => boolean)): boolean;
hasValidationSubscribers(modelURI: string): boolean;
protected getValidationSubscribers(modelURI: string): JSONSocket[];
broadcastValidation(modelURI: string, results: Diagnostic): Promise<boolean>;
sendValidation(client: JSONSocket, results: Diagnostic): Promise<boolean>;
protected sendSubscriptionMessage(client: JSONSocket, message: ModelServerMessage<any>): Promise<boolean>;
}
export {};
//# sourceMappingURL=subscription-manager.d.ts.map

@@ -37,2 +37,3 @@ "use strict";

const modelserver_plugin_ext_1 = require("@eclipse-emfcloud/modelserver-plugin-ext");
const events_1 = require("events");
const inversify_1 = require("inversify");

@@ -47,2 +48,3 @@ const qs_1 = require("qs");

this.subscriptions = new Map();
this.eventEmitter = new events_1.EventEmitter();
}

@@ -66,3 +68,6 @@ addSubscription(client, endpoint, params) {

// Clean-up on close
const cleanupHandler = () => this.subscriptions.delete(downstream);
const cleanupHandler = () => {
this.subscriptions.delete(downstream);
this.fireEvent('unsubscribed', downstream, params);
};
downstream.onClose(cleanupHandler);

@@ -79,8 +84,59 @@ upstream.onClose(cleanupHandler);

}
this.fireEvent('subscribed', downstream, params);
return downstream;
}
fireEvent(eventType, client, params) {
this.eventEmitter.emit(eventType, client, params);
}
addSubscribedListener(listener) {
this.eventEmitter.on('subscribed', listener);
return this;
}
removeSubscribedListener(listener) {
this.eventEmitter.off('subscribed', listener);
return this;
}
addUnsubscribedListener(listener) {
this.eventEmitter.on('unsubscribed', listener);
return this;
}
removeUnsubscribedListener(listener) {
this.eventEmitter.off('unsubscribed', listener);
return this;
}
/**
* Retrieve subscribers on a model URI. If provided, the `filter` may be either
*
* - a `string` indicating a property of the subscription options that must have a truthy value, or
* - a `function` that tests whether the subscription options match some arbitrary predicate
*
* @param modelURI the model URI for which to get subscribers
* @param filter an optional subscriber filter, by options property or a generic predicate
* @returns the matching subscriber sockets
*/
getSubscribers(modelURI, filter) {
return Array.from(this.subscriptions.keys())
.filter(client => client.options.modeluri === modelURI)
.filter(subscriberFilter(filter));
}
/**
* Query whether any subscribers are registered on a model URI. If provided, the `filter` may be either
*
* - a `string` indicating a property of the subscription options that must have a truthy value, or
* - a `function` that tests whether the subscription options match some arbitrary predicate
*
* @param modelURI the model URI for which to get subscribers
* @param filter an optional subscriber filter, by options property or a generic predicate
* @returns whether any matching subscriptions exist
*/
hasSubscribers(modelURI, filter) {
return Array.from(this.subscriptions.keys())
.filter(client => client.options.modeluri === modelURI)
.some(subscriberFilter(filter));
}
hasValidationSubscribers(modelURI) {
return Array.from(this.subscriptions.keys()).some(client => { var _a; return ((_a = client.options) === null || _a === void 0 ? void 0 : _a.livevalidation) && client.options.modeluri === modelURI; });
return this.hasSubscribers(modelURI, 'livevalidation');
}
getValidationSubscribers(modelURI) {
return Array.from(this.subscriptions.keys()).filter(client => { var _a; return ((_a = client.options) === null || _a === void 0 ? void 0 : _a.livevalidation) && client.options.modeluri === modelURI; });
return this.getSubscribers(modelURI, 'livevalidation');
}

@@ -92,3 +148,13 @@ async broadcastValidation(modelURI, results) {

};
return Promise.all(this.getValidationSubscribers(modelURI).map(client => new Promise(resolve => {
return Promise.all(this.getValidationSubscribers(modelURI).map(client => this.sendSubscriptionMessage(client, message))).then(sent => sent.every(each => each));
}
async sendValidation(client, results) {
const message = {
type: modelserver_client_1.MessageType.validationResult,
data: results
};
return this.sendSubscriptionMessage(client, message);
}
async sendSubscriptionMessage(client, message) {
return new Promise(resolve => {
client.send(message, (error) => {

@@ -103,3 +169,3 @@ if (error) {

});
}))).then(sent => sent.every(each => each));
});
}

@@ -120,2 +186,7 @@ };

exports.SubscriptionManager = SubscriptionManager;
const subscriberFilter = filter => typeof filter === 'string'
? client => { var _a; return !!((_a = client.options) === null || _a === void 0 ? void 0 : _a[filter]); }
: typeof filter === 'function'
? client => client.options && filter(client.options)
: () => true;
//# sourceMappingURL=subscription-manager.js.map

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

import { InternalModelServerClientApi } from '../client/model-server-client';
import { JSONSocket } from '../client/web-socket-utils';
import { ValidationProviderRegistry } from '../validation-provider-registry';

@@ -27,2 +28,3 @@ import { SubscriptionManager } from './subscription-manager';

protected readonly subscriptionManager: SubscriptionManager;
initialize(): void;
validate(modelURI: string): Promise<Diagnostic>;

@@ -37,3 +39,4 @@ /**

performLiveValidation(modelURI: string): Promise<boolean>;
protected initializeLiveValidation(client: JSONSocket, modelURI: string): Promise<unknown>;
}
//# sourceMappingURL=validation-manager.d.ts.map

@@ -36,2 +36,9 @@ "use strict";

let ValidationManager = ValidationManager_1 = class ValidationManager {
initialize() {
this.subscriptionManager.addSubscribedListener((client, params) => {
if (params.livevalidation) {
this.initializeLiveValidation(client, params.modeluri);
}
});
}
async validate(modelURI) {

@@ -70,2 +77,5 @@ const model = await this.modelServerClient.get(modelURI).then(asModelServerObject);

}
async initializeLiveValidation(client, modelURI) {
return this.validate(modelURI).then(diagnostics => this.subscriptionManager.sendValidation(client, diagnostics));
}
};

@@ -89,2 +99,8 @@ __decorate([

], ValidationManager.prototype, "subscriptionManager", void 0);
__decorate([
(0, inversify_1.postConstruct)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], ValidationManager.prototype, "initialize", null);
ValidationManager = ValidationManager_1 = __decorate([

@@ -91,0 +107,0 @@ (0, inversify_1.injectable)()

{
"name": "@eclipse-emfcloud/modelserver-node",
"version": "0.2.0-next.16b2e5e.24+16b2e5e",
"version": "0.2.0-next.272d84f.34+272d84f",
"description": "Business Logic layer façade for the Model Server.",

@@ -25,6 +25,7 @@ "license": "(EPL-2.0 OR MIT)",

"files": [
"lib"
"lib",
"src"
],
"dependencies": {
"@eclipse-emfcloud/modelserver-plugin-ext": "0.2.0-next.16b2e5e.24+16b2e5e",
"@eclipse-emfcloud/modelserver-plugin-ext": "0.2.0-next.272d84f.34+272d84f",
"axios": "^0.24.0",

@@ -57,8 +58,9 @@ "express": "^4.17.1",

"lint:fix": "eslint --fix --ext .ts,.tsx ./src",
"build": "tsc",
"build": "tsc && yarn lint",
"start": "node lib/app.js --port=8082 --upstream=8081",
"test": "mocha --config ../../configs/.mocharc.json \"./src/**/*.spec.?(ts|tsx)\"",
"test": "mocha --config ../../configs/.mocharc.json",
"test:ci": "mocha --config ../../configs/.mocharc.ci.json",
"watch": "tsc -w"
},
"gitHead": "16b2e5ed6441a4fd5b63e2bc9b6bd13ae1c44405"
"gitHead": "272d84fba75fb1cc11cbd4a5efa340150326c7fb"
}

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