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.e746384.40 to 0.2.0-next.e9ebcb4.46

lib/test/test-helpers.d.ts

54

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

@@ -43,3 +43,3 @@ /********************************************************************************

*/
openTransaction(modeluri: string): Promise<TransactionContext>;
openTransaction(modeluri: URI): Promise<TransactionContext>;
}

@@ -96,36 +96,36 @@ /**

initialize(): void | Promise<void>;
openTransaction(modelUri: string): Promise<TransactionContext>;
openTransaction(modelUri: URI): Promise<TransactionContext>;
private closeTransaction;
protected makeURL(path: string, queryParameters?: any): string;
protected makeURL(path: string, modeluri: URI): string;
getAll(): Promise<Model<unknown>[]>;
getAll<M>(typeGuard: TypeGuard<M>): Promise<Model<M>[]>;
getAll(format: Format): Promise<Model<string>[]>;
get(modeluri: string, format?: Format): Promise<AnyObject>;
get<M>(modeluri: string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
getModelUris(): Promise<string[]>;
getElementById(modeluri: string, elementid: string, format?: Format): Promise<AnyObject>;
getElementById<M>(modeluri: string, elementid: string, typeGuard: TypeGuard<M>): Promise<M>;
getElementByName(modeluri: string, elementname: string, format?: Format): Promise<AnyObject>;
getElementByName<M>(modeluri: string, elementname: string, typeGuard: TypeGuard<M>): Promise<M>;
delete(modeluri: string): Promise<boolean>;
close(modeluri: string): Promise<boolean>;
create(modeluri: string, model: string | AnyObject, format?: Format): Promise<AnyObject>;
create<M>(modeluri: string, model: string | AnyObject, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
update(modeluri: string, model: AnyObject | string, format?: Format): Promise<AnyObject>;
update<M>(modeluri: string, model: AnyObject | string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
save(modeluri: string): Promise<boolean>;
get(modeluri: URI, format?: Format): Promise<AnyObject>;
get<M>(modeluri: URI, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
getModelUris(): Promise<URI[]>;
getElementById(modeluri: URI, elementid: string, format?: Format): Promise<AnyObject>;
getElementById<M>(modeluri: URI, elementid: string, typeGuard: TypeGuard<M>): Promise<M>;
getElementByName(modeluri: URI, elementname: string, format?: Format): Promise<AnyObject>;
getElementByName<M>(modeluri: URI, elementname: string, typeGuard: TypeGuard<M>): Promise<M>;
delete(modeluri: URI): Promise<boolean>;
close(modeluri: URI): Promise<boolean>;
create(modeluri: URI, model: string | AnyObject, format?: Format): Promise<AnyObject>;
create<M>(modeluri: URI, model: string | AnyObject, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
update(modeluri: URI, model: AnyObject | string, format?: Format): Promise<AnyObject>;
update<M>(modeluri: URI, model: AnyObject | string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
save(modeluri: URI): Promise<boolean>;
saveAll(): Promise<boolean>;
validate(modeluri: string): Promise<Diagnostic>;
getValidationConstraints(modeluri: string): Promise<string>;
getTypeSchema(modeluri: string): Promise<string>;
validate(modeluri: URI): Promise<Diagnostic>;
getValidationConstraints(modeluri: URI): Promise<string>;
getTypeSchema(modeluri: URI): Promise<string>;
getUiSchema(schemaname: string): Promise<string>;
configureServer(configuration: ServerConfiguration): Promise<boolean>;
ping(): Promise<boolean>;
edit(modeluri: string, patch: Operation | Operation[], format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: string, command: ModelServerCommand, format?: Format): Promise<ModelUpdateResult>;
undo(modeluri: string): Promise<ModelUpdateResult>;
redo(modeluri: string): Promise<ModelUpdateResult>;
subscribe(modeluri: string, listener: SubscriptionListener, options?: SubscriptionOptions): SubscriptionListener;
send(modelUri: string, message: ModelServerMessage<unknown>): void;
unsubscribe(modelUri: string): void;
edit(modeluri: URI, patch: Operation | Operation[], format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: URI, command: ModelServerCommand, format?: Format): Promise<ModelUpdateResult>;
undo(modeluri: URI): Promise<ModelUpdateResult>;
redo(modeluri: URI): Promise<ModelUpdateResult>;
subscribe(modeluri: URI, listener: SubscriptionListener, options?: SubscriptionOptions): SubscriptionListener;
send(modeluri: URI, message: ModelServerMessage<unknown>): void;
unsubscribe(modeluri: URI): void;
}

@@ -132,0 +132,0 @@ /**

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

const promise_utils_1 = require("./promise-utils");
const uri_utils_1 = require("./uri-utils");
const web_socket_utils_1 = require("./web-socket-utils");

@@ -69,23 +68,16 @@ exports.UpstreamConnectionConfig = Symbol('UpstreamConnectionConfig');

});
return this.delegate.initialize(this._baseURL.toString(), DEFAULT_FORMAT);
return this.delegate.initialize(this._baseURL, DEFAULT_FORMAT);
}
async openTransaction(modelUri) {
let uri;
try {
uri = (0, uri_utils_1.validateModelURI)(modelUri);
}
catch (error) {
this.logger.error(error);
return Promise.reject();
}
if (this.transactions.has(uri.toString())) {
const uriKey = modelUri.normalize().toString();
if (this.transactions.has(uriKey)) {
// Open a nested transaction
return this.transactions.get(uri.toString()).openTransaction();
return this.transactions.get(uriKey).openTransaction();
}
const clientID = (0, uuid_1.v4)();
return axios_1.default.post(this.makeURL('transaction', { modeluri: uri.toString() }), { data: clientID }).then(response => {
return axios_1.default.post(this.makeURL('transaction', modelUri), { data: clientID }).then(response => {
const { uri: transactionURI } = response.data.data;
const result = new DefaultTransactionContext(transactionURI, modelUri, this.commandProviderRegistry, this.triggerProviderRegistry, this.logger);
this.transactions.set(uri.toString(), result);
return result.open(tc => this.closeTransaction(uri, tc));
this.transactions.set(uriKey, result);
return result.open(tc => this.closeTransaction(modelUri, tc));
});

@@ -98,6 +90,6 @@ }

}
makeURL(path, queryParameters) {
makeURL(path, modeluri) {
const uri = this._baseURL.clone();
uri.path(URI.joinPaths(uri.path(), path).toString());
uri.addQuery(queryParameters);
path.split('/').forEach(seg => uri.segment(seg));
uri.addQuery('modeluri', modeluri);
return uri.toString();

@@ -207,7 +199,7 @@ }

}
send(modelUri, message) {
return this.delegate.send(modelUri, message);
send(modeluri, message) {
return this.delegate.send(modeluri, message);
}
unsubscribe(modelUri) {
return this.delegate.unsubscribe(modelUri);
unsubscribe(modeluri) {
return this.delegate.unsubscribe(modeluri);
}

@@ -519,3 +511,3 @@ };

type,
modelUri: this.modelURI,
modeluri: this.modelURI,
data

@@ -522,0 +514,0 @@ };

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

import { Operation } from 'fast-json-patch';
import * as URI from 'urijs';
/**

@@ -54,4 +55,4 @@ * A registry of command providers from _Model Server_ plug-ins.

*/
getCommands(modelUri: string, customCommand: ModelServerCommand): Promise<ModelServerCommand | Operation[] | Transaction>;
getCommands(modelUri: URI, customCommand: ModelServerCommand): Promise<ModelServerCommand | Operation[] | Transaction>;
}
//# sourceMappingURL=command-provider-registry.d.ts.map

@@ -67,5 +67,5 @@ /********************************************************************************

*/
protected performModelValidation(modelURI: string): (delegatedResult: AnyObject) => Promise<AnyObject>;
protected performModelValidation(modelURI: URI): (delegatedResult: AnyObject) => Promise<AnyObject>;
}
export {};
//# sourceMappingURL=models.d.ts.map

@@ -70,5 +70,5 @@ "use strict";

const delegated = isCreate //
? this.modelServerClient.create(modeluri.toString(), model, format)
: this.modelServerClient.update(modeluri.toString(), model, format);
delegated.then(this.performModelValidation(modeluri.toString())).then((0, routes_1.relay)(res)).catch((0, routes_1.handleError)(res));
? this.modelServerClient.create(modeluri, model, format)
: this.modelServerClient.update(modeluri, model, format);
delegated.then(this.performModelValidation(modeluri)).then((0, routes_1.relay)(res)).catch((0, routes_1.handleError)(res));
};

@@ -107,3 +107,3 @@ }

forwardEdit(modelURI, patchOrCommand, res) {
this.editService.edit(modelURI.toString(), patchOrCommand).then((0, routes_1.relay)(res)).catch((0, routes_1.handleError)(res));
this.editService.edit(modelURI, patchOrCommand).then((0, routes_1.relay)(res)).catch((0, routes_1.handleError)(res));
}

@@ -110,0 +110,0 @@ /**

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

import { RequestHandler } from 'express';
import * as URI from 'urijs';
import { InternalModelServerClientApi } from '../client/model-server-client';

@@ -41,5 +42,5 @@ import { ValidationManager } from '../services/validation-manager';

protected interceptUndoRedoGet(): RequestHandler<unknown, any, any, UndoRedoGetQuery, Record<string, any>>;
protected performLiveValidation(modelURI: string): (delegatedResult: ModelUpdateResult) => Promise<ModelUpdateResult>;
protected performLiveValidation(modelURI: URI): (delegatedResult: ModelUpdateResult) => Promise<ModelUpdateResult>;
}
export {};
//# sourceMappingURL=undo-redo.d.ts.map

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

const inversify_1 = require("inversify");
const URI = require("urijs");
const model_server_client_1 = require("../client/model-server-client");

@@ -50,3 +51,6 @@ const validation_manager_1 = require("../services/validation-manager");

: this.modelServerClient.redo(modelURI);
delegated.then(this.performLiveValidation(modelURI)).then((0, routes_1.relay)(res)).catch((0, routes_1.handleError)(res));
delegated
.then(this.performLiveValidation(new URI(modelURI)))
.then((0, routes_1.relay)(res))
.catch((0, routes_1.handleError)(res));
};

@@ -53,0 +57,0 @@ }

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

const inversify_1 = require("inversify");
const URI = require("urijs");
const model_server_client_1 = require("../client/model-server-client");

@@ -55,3 +56,3 @@ const validation_manager_1 = require("../services/validation-manager");

}
this.validationManager.validate(modelURI).then((0, routes_1.relay)(res)).catch((0, routes_1.handleError)(res));
this.validationManager.validate(new URI(modelURI)).then((0, routes_1.relay)(res)).catch((0, routes_1.handleError)(res));
};

@@ -58,0 +59,0 @@ }

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

import { AxiosInstance } from 'axios';
import { RequestHandler } from 'express';
import { Request, RequestHandler } from 'express';
import { WebsocketRequestHandler } from 'express-ws';

@@ -30,2 +30,3 @@ import * as http from 'http';

protected initialize(): void;
protected readonly backstopPaths: Set<string>;
protected server: http.Server;

@@ -60,3 +61,5 @@ /**

protected forwardWS(upstreamServer: AxiosInstance): WebsocketRequestHandler;
protected shouldBackstop(req: Request): boolean;
protected isModelServerRoute(route: string): boolean;
}
//# sourceMappingURL=server.d.ts.map

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

const inversify_1 = require("inversify");
const URI = require("urijs");
const WebSocket = require("ws");

@@ -35,2 +36,20 @@ const model_server_client_1 = require("./client/model-server-client");

const plugin_context_1 = require("./plugin-context");
const STANDARD_ROUTES = new Set([
'/models',
'/modelelement',
'/modeluris',
'/server/ping',
'/server/configure',
'/subscribe',
'/close',
'/save',
'/saveall',
'/undo',
'/redo',
'/transaction',
'/validation',
'/validation/constraints',
'/typeschema',
'/uischema'
]);
/**

@@ -43,2 +62,3 @@ * The _Model Server_ core.

this.middlewareProviders = [];
this.backstopPaths = new Set();
}

@@ -59,16 +79,39 @@ initialize() {

app.use(express.json());
// Use provided middlewares that are applicable globally
this.middlewareProviders.flatMap(p => p.getMiddlewares(app)).forEach(mw => app.use(mw));
// Use provided before-middlewares that are applicable globally
this.middlewareProviders.flatMap(p => { var _a, _b; return (_b = (_a = p.getMiddlewares) === null || _a === void 0 ? void 0 : _a.call(p, app)) !== null && _b !== void 0 ? _b : []; }).forEach(mw => app.use(mw));
// Isolate contributed route handlers each in their own router.
const routes = {
routers: [],
factory: (route) => {
factory: (route, options) => {
const newRouter = express.Router();
wsify(newRouter);
// Apply provided route-specific middlewares
this.middlewareProviders.flatMap(p => p.getMiddlewares(newRouter, route)).forEach(mw => newRouter.use(mw));
routes.routers.push({ route, router: newRouter });
// Apply provided route-specific _before_ middlewares
this.middlewareProviders
.flatMap(p => { var _a, _b; return (_b = (_a = p.getMiddlewares) === null || _a === void 0 ? void 0 : _a.call(p, newRouter, route, options === null || options === void 0 ? void 0 : options.routerId)) !== null && _b !== void 0 ? _b : []; })
.forEach(mw => newRouter.use(mw));
routes.routers.push({ route, router: newRouter, options });
return newRouter;
},
install: () => routes.routers.forEach(r => app.use(r.route, r.router))
install: () => routes.routers.forEach(r => {
var _a, _b;
// Install middlewares after the route handlers
this.middlewareProviders
.flatMap(p => { var _a, _b, _c; return (_c = (_a = p.getAfterMiddlewares) === null || _a === void 0 ? void 0 : _a.call(p, r.router, r.route, (_b = r.options) === null || _b === void 0 ? void 0 : _b.routerId)) !== null && _c !== void 0 ? _c : []; })
.forEach(mw => r.router.use(mw));
// Do we need a backstop to prevent `next()` delegation to the upstream server?
if (!((_a = r.options) === null || _a === void 0 ? void 0 : _a.forwardToUpstream)) {
// Record the routes supported by this router as needing to be backstopped.
// By default, do not backstop (i.e., allow to pass through) routes that are
// known to be supported by the upstream server because they are core
// Model Server API, unless the options expressly deny with an actual falsy value
const explicitlyBackstopped = typeof ((_b = r.options) === null || _b === void 0 ? void 0 : _b.forwardToUpstream) !== 'undefined';
r.router.stack
.map(layer => { var _a, _b; return r.route + ((_b = (_a = layer === null || layer === void 0 ? void 0 : layer.route) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : ''); })
.map(handledRoute => handledRoute.replace(/\/+$/, ''))
.filter(handledRoute => explicitlyBackstopped || !this.isModelServerRoute(handledRoute))
.forEach(backstopped => this.backstopPaths.add(backstopped));
}
// And install the router in the app
app.use(r.route, r.router);
})
};

@@ -79,3 +122,6 @@ for (const routing of this.routeProviders) {

routes.install();
const upstream = axios_1.default.create({ baseURL: `http://localhost:${upstreamPort}/` });
// Use provided after-middlewares that are applicable globally
this.middlewareProviders.flatMap(p => { var _a, _b; return (_b = (_a = p.getAfterMiddlewares) === null || _a === void 0 ? void 0 : _a.call(p, app)) !== null && _b !== void 0 ? _b : []; }).forEach(mw => app.use(mw));
const baseURL = new URI({ protocol: 'http', hostname: 'localhost', port: upstreamPort });
const upstream = axios_1.default.create({ baseURL: baseURL.toString() });
app.all('*', this.forward(upstream));

@@ -125,2 +171,6 @@ app.ws('*', this.forwardWS(upstream));

}
if (this.shouldBackstop(req)) {
// Don't forward to upstream
return;
}
const relayReq = {

@@ -131,3 +181,3 @@ url: req.url,

};
this.logger.debug(`Forwarding ${req.method} request to Upstream Model Server.`);
this.logger.debug(`Forwarding ${req.method} request on ${req.url} to Upstream Model Server.`);
upstream

@@ -192,2 +242,9 @@ .request(relayReq)

}
shouldBackstop(req) {
return this.backstopPaths.has(req.path);
}
isModelServerRoute(route) {
const match = route.match(/^\/api\/v[0-9.]+(\/.*)/);
return match && STANDARD_ROUTES.has(match[1]);
}
};

@@ -194,0 +251,0 @@ __decorate([

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

import { Operation } from 'fast-json-patch';
import * as URI from 'urijs';
import { InternalModelServerClientApi } from '../client/model-server-client';

@@ -28,5 +29,5 @@ import { CommandProviderRegistry } from '../command-provider-registry';

protected readonly validationManager: ValidationManager;
edit(modelURI: string, patchOrCommand: Operation | Operation[] | ModelServerCommand): Promise<ModelUpdateResult>;
protected handleCommand(modelURI: string, command: ModelServerCommand): Promise<ModelUpdateResult>;
protected forwardEdit(modelURI: string, providedEdit: ModelServerCommand | Operation | Operation[] | Transaction): Promise<ModelUpdateResult>;
edit(modelURI: URI, patchOrCommand: Operation | Operation[] | ModelServerCommand): Promise<ModelUpdateResult>;
protected handleCommand(modelURI: URI, command: ModelServerCommand): Promise<ModelUpdateResult>;
protected forwardEdit(modelURI: URI, providedEdit: ModelServerCommand | Operation | Operation[] | Transaction): Promise<ModelUpdateResult>;
private forwardEditSimple;

@@ -40,4 +41,4 @@ private forwardEditWithTriggers;

*/
protected performPatchValidation(modelURI: string): (validate: ModelUpdateResult) => Promise<ModelUpdateResult>;
protected performPatchValidation(modelURI: URI): (validate: ModelUpdateResult) => Promise<ModelUpdateResult>;
}
//# sourceMappingURL=edit-service.d.ts.map

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

edit(patchOrCommand) {
return this.editService.edit(this.getModelURI().toString(), patchOrCommand);
return this.editService.edit(this.getModelURI(), patchOrCommand);
}

@@ -60,6 +60,6 @@ undo() {

openTransaction() {
return this.client.openTransaction(this.getModelURI().toString());
return this.client.openTransaction(this.getModelURI());
}
validate() {
return this.validator.validate(this.getModelURI().toString());
return this.validator.validate(this.getModelURI());
}

@@ -66,0 +66,0 @@ async create(content, format) {

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

import { EventEmitter } from 'events';
import * as URI from 'urijs';
import * as WebSocket from 'ws';

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

*/
protected getSubscribers(modelURI: string, filter?: keyof SubscriptionQuery | ((options: SubscriptionQuery) => boolean)): JSONSocket[];
protected getSubscribers(modelURI: URI, filter?: keyof SubscriptionQuery | ((options: SubscriptionQuery) => boolean)): JSONSocket[];
/**

@@ -70,6 +71,6 @@ * Query whether any subscribers are registered on a model URI. If provided, the `filter` may be either

*/
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>;
protected hasSubscribers(modelURI: URI, filter?: keyof SubscriptionQuery | ((options: SubscriptionQuery) => boolean)): boolean;
hasValidationSubscribers(modelURI: URI): boolean;
protected getValidationSubscribers(modelURI: URI): JSONSocket[];
broadcastValidation(modelURI: URI, results: Diagnostic): Promise<boolean>;
sendValidation(client: JSONSocket, results: Diagnostic): Promise<boolean>;

@@ -76,0 +77,0 @@ protected sendSubscriptionMessage(client: JSONSocket, message: ModelServerMessage<any>): Promise<boolean>;

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

return Array.from(this.subscriptions.keys())
.filter(client => client.options.modeluri === modelURI)
.filter(client => modelURI.equals(client.options.modeluri))
.filter(subscriberFilter(filter));

@@ -131,3 +131,3 @@ }

return Array.from(this.subscriptions.keys())
.filter(client => client.options.modeluri === modelURI)
.filter(client => modelURI.equals(client.options.modeluri))
.some(subscriberFilter(filter));

@@ -134,0 +134,0 @@ }

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

import { Logger } from '@eclipse-emfcloud/modelserver-plugin-ext';
import * as URI from 'urijs';
import { InternalModelServerClientApi } from '../client/model-server-client';

@@ -29,3 +30,3 @@ import { JSONSocket } from '../client/web-socket-utils';

initialize(): void;
validate(modelURI: string): Promise<Diagnostic>;
validate(modelURI: URI): Promise<Diagnostic>;
/**

@@ -38,5 +39,5 @@ * Perform live validation of a model. The result is not a validation result but

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

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

const model_server_client_1 = require("../client/model-server-client");
const uri_utils_1 = require("../client/uri-utils");
const validation_provider_registry_1 = require("../validation-provider-registry");

@@ -40,3 +41,3 @@ const subscription_manager_1 = require("./subscription-manager");

if (params.livevalidation) {
this.initializeLiveValidation(client, params.modeluri);
this.initializeLiveValidation(client, (0, uri_utils_1.validateModelURI)(params.modeluri));
}

@@ -43,0 +44,0 @@ });

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

import { Operation } from 'fast-json-patch';
import * as URI from 'urijs';
/**

@@ -39,3 +40,3 @@ * A registry of trigger providers from _Model Server_ plug-ins.

hasProviders(): boolean;
getProviders(modelURI: string, patch: Operation[]): TriggerProvider[];
getProviders(modelURI: URI, patch: Operation[]): TriggerProvider[];
/**

@@ -49,3 +50,3 @@ * Gets a trigger provider that aggregates all triggers provided for the given `patch`.

*/
getProvider(modelURI: string, patch: Operation[]): TriggerProvider | undefined;
getProvider(modelURI: URI, patch: Operation[]): TriggerProvider | undefined;
/**

@@ -58,4 +59,4 @@ * Obtain additional edits to forward to the _Model Server_ that are triggered by the given `patch`.

*/
getTriggers(modelURI: string, patch: Operation[]): Promise<Operation[] | Transaction | undefined>;
getTriggers(modelURI: URI, patch: Operation[]): Promise<Operation[] | Transaction | undefined>;
}
//# sourceMappingURL=trigger-provider-registry.d.ts.map

@@ -13,4 +13,5 @@ /********************************************************************************

import { Logger, ValidationProvider, ValidationProviderRegistrationOptions } from '@eclipse-emfcloud/modelserver-plugin-ext';
declare type ValidationProviderFilter = (model: ModelServerObjectV2, modelURI: string) => boolean;
export declare type Validator = (model: ModelServerObjectV2, modelURI: string) => Promise<Diagnostic>;
import * as URI from 'urijs';
declare type ValidationProviderFilter = (model: ModelServerObjectV2, modelURI: URI) => boolean;
export declare type Validator = (model: ModelServerObjectV2, modelURI: URI) => Promise<Diagnostic>;
/**

@@ -40,5 +41,5 @@ * A registry of validation providers from _Model Server_ plug-ins.

unregister(id: string, provider: ValidationProvider): void;
hasProvider(model: ModelServerObjectV2, modelURI: string): boolean;
getProviders(model: ModelServerObjectV2, modelURI: string): ValidationProvider[];
getValidator(model: ModelServerObjectV2, modelURI: string): Validator | undefined;
hasProvider(model: ModelServerObjectV2, modelURI: URI): boolean;
getProviders(model: ModelServerObjectV2, modelURI: URI): ValidationProvider[];
getValidator(model: ModelServerObjectV2, modelURI: URI): Validator | undefined;
/**

@@ -51,5 +52,5 @@ * Validate a `model`.

*/
validate(model: ModelServerObjectV2, modelURI: string): Promise<Diagnostic>;
validate(model: ModelServerObjectV2, modelURI: URI): Promise<Diagnostic>;
}
export {};
//# sourceMappingURL=validation-provider-registry.d.ts.map

@@ -128,4 +128,4 @@ "use strict";

if (typeof filter === 'string')
return modelURI => modelURI.includes(filter);
return modelURI => filter.test(modelURI);
return modelURI => modelURI.toString().includes(filter);
return modelURI => filter.test(modelURI.toString());
}

@@ -141,3 +141,3 @@ function multiValidator(providers) {

if (result.severity > modelserver_client_1.OK) {
result.message = `Diagnosis of ${modelURI}`;
result.message = `Diagnosis of ${modelURI.toString()}`;
result.id = '/';

@@ -144,0 +144,0 @@ }

{
"name": "@eclipse-emfcloud/modelserver-node",
"version": "0.2.0-next.e746384.40+e746384",
"version": "0.2.0-next.e9ebcb4.46+e9ebcb4",
"description": "Business Logic layer façade for the Model Server.",

@@ -29,3 +29,3 @@ "license": "(EPL-2.0 OR MIT)",

"dependencies": {
"@eclipse-emfcloud/modelserver-plugin-ext": "0.2.0-next.e746384.40+e746384",
"@eclipse-emfcloud/modelserver-plugin-ext": "0.2.0-next.e9ebcb4.46+e9ebcb4",
"axios": "^0.24.0",

@@ -66,3 +66,3 @@ "express": "^4.17.1",

},
"gitHead": "e746384fe2a31ddecd147965cbd5c0427bace8c4"
"gitHead": "e9ebcb42f1ae5d31bd5bcb84a2bb4305c98a86f1"
}

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

import { CompletablePromise } from './promise-utils';
import { validateModelURI } from './uri-utils';
import { WebSocketMessageAcceptor } from './web-socket-utils';

@@ -75,3 +74,3 @@

*/
openTransaction(modeluri: string): Promise<TransactionContext>;
openTransaction(modeluri: URI): Promise<TransactionContext>;
}

@@ -176,16 +175,10 @@

});
return this.delegate.initialize(this._baseURL.toString(), DEFAULT_FORMAT);
return this.delegate.initialize(this._baseURL, DEFAULT_FORMAT);
}
async openTransaction(modelUri: string): Promise<TransactionContext> {
let uri: URI;
try {
uri = validateModelURI(modelUri);
} catch (error) {
this.logger.error(error);
return Promise.reject();
}
if (this.transactions.has(uri.toString())) {
async openTransaction(modelUri: URI): Promise<TransactionContext> {
const uriKey = modelUri.normalize().toString();
if (this.transactions.has(uriKey)) {
// Open a nested transaction
return this.transactions.get(uri.toString()).openTransaction();
return this.transactions.get(uriKey).openTransaction();
}

@@ -195,3 +188,3 @@

return axios.post(this.makeURL('transaction', { modeluri: uri.toString() }), { data: clientID }).then(response => {
return axios.post(this.makeURL('transaction', modelUri), { data: clientID }).then(response => {
const { uri: transactionURI } = (response.data as CreateTransactionResponseBody).data;

@@ -205,4 +198,4 @@ const result = new DefaultTransactionContext(

);
this.transactions.set(uri.toString(), result);
return result.open(tc => this.closeTransaction(uri, tc));
this.transactions.set(uriKey, result);
return result.open(tc => this.closeTransaction(modelUri, tc));
});

@@ -217,6 +210,6 @@ }

protected makeURL(path: string, queryParameters?: any): string {
protected makeURL(path: string, modeluri: URI): string {
const uri = this._baseURL.clone();
uri.path(URI.joinPaths(uri.path(), path).toString());
uri.addQuery(queryParameters);
path.split('/').forEach(seg => uri.segment(seg));
uri.addQuery('modeluri', modeluri);
return uri.toString();

@@ -238,5 +231,5 @@ }

}
get(modeluri: string, format?: Format): Promise<AnyObject>;
get<M>(modeluri: string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
get<M>(modeluri: string, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
get(modeluri: URI, format?: Format): Promise<AnyObject>;
get<M>(modeluri: URI, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
get<M>(modeluri: URI, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
if (!typeGuard) {

@@ -250,8 +243,8 @@ return this.delegate.get(modeluri, format);

}
getModelUris(): Promise<string[]> {
getModelUris(): Promise<URI[]> {
return this.delegate.getModelUris();
}
getElementById(modeluri: string, elementid: string, format?: Format): Promise<AnyObject>;
getElementById<M>(modeluri: string, elementid: string, typeGuard: TypeGuard<M>): Promise<M>;
getElementById<M>(modeluri: string, elementid: string, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
getElementById(modeluri: URI, elementid: string, format?: Format): Promise<AnyObject>;
getElementById<M>(modeluri: URI, elementid: string, typeGuard: TypeGuard<M>): Promise<M>;
getElementById<M>(modeluri: URI, elementid: string, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
if (!typeGuard) {

@@ -265,5 +258,5 @@ return this.delegate.getElementById(modeluri, elementid, format);

}
getElementByName(modeluri: string, elementname: string, format?: Format): Promise<AnyObject>;
getElementByName<M>(modeluri: string, elementname: string, typeGuard: TypeGuard<M>): Promise<M>;
getElementByName<M>(modeluri: string, elementname: string, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
getElementByName(modeluri: URI, elementname: string, format?: Format): Promise<AnyObject>;
getElementByName<M>(modeluri: URI, elementname: string, typeGuard: TypeGuard<M>): Promise<M>;
getElementByName<M>(modeluri: URI, elementname: string, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
if (!typeGuard) {

@@ -277,11 +270,11 @@ return this.delegate.getElementByName(modeluri, elementname, format);

}
delete(modeluri: string): Promise<boolean> {
delete(modeluri: URI): Promise<boolean> {
return this.delegate.delete(modeluri);
}
close(modeluri: string): Promise<boolean> {
close(modeluri: URI): Promise<boolean> {
return this.delegate.close(modeluri);
}
create(modeluri: string, model: string | AnyObject, format?: Format): Promise<AnyObject>;
create<M>(modeluri: string, model: string | AnyObject, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
create<M>(modeluri: string, model: string, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
create(modeluri: URI, model: string | AnyObject, format?: Format): Promise<AnyObject>;
create<M>(modeluri: URI, model: string | AnyObject, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
create<M>(modeluri: URI, model: string, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
if (!typeGuard) {

@@ -295,5 +288,5 @@ return this.delegate.create(modeluri, model, format);

}
update(modeluri: string, model: AnyObject | string, format?: Format): Promise<AnyObject>;
update<M>(modeluri: string, model: AnyObject | string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
update<M>(modeluri: string, model: AnyObject | string, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
update(modeluri: URI, model: AnyObject | string, format?: Format): Promise<AnyObject>;
update<M>(modeluri: URI, model: AnyObject | string, typeGuard: TypeGuard<M>, format?: Format): Promise<M>;
update<M>(modeluri: URI, model: AnyObject | string, typeGuard?: Format | TypeGuard<M>, format?: Format): Promise<AnyObject | M> {
if (!typeGuard) {

@@ -307,3 +300,3 @@ return this.delegate.update(modeluri, model, format);

}
save(modeluri: string): Promise<boolean> {
save(modeluri: URI): Promise<boolean> {
return this.delegate.save(modeluri);

@@ -314,9 +307,9 @@ }

}
validate(modeluri: string): Promise<Diagnostic> {
validate(modeluri: URI): Promise<Diagnostic> {
return this.delegate.validate(modeluri);
}
getValidationConstraints(modeluri: string): Promise<string> {
getValidationConstraints(modeluri: URI): Promise<string> {
return this.delegate.getValidationConstraints(modeluri);
}
getTypeSchema(modeluri: string): Promise<string> {
getTypeSchema(modeluri: URI): Promise<string> {
return this.delegate.getTypeSchema(modeluri);

@@ -333,5 +326,5 @@ }

}
edit(modeluri: string, patch: Operation | Operation[], format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: string, command: ModelServerCommand, format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: string, patchOrCommand: Operation | Operation[] | ModelServerCommand): Promise<ModelUpdateResult> {
edit(modeluri: URI, patch: Operation | Operation[], format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: URI, command: ModelServerCommand, format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: URI, patchOrCommand: Operation | Operation[] | ModelServerCommand): Promise<ModelUpdateResult> {
if (patchOrCommand instanceof ModelServerCommand) {

@@ -345,16 +338,16 @@ return this.delegate.edit(modeluri, patchOrCommand);

}
undo(modeluri: string): Promise<ModelUpdateResult> {
undo(modeluri: URI): Promise<ModelUpdateResult> {
return this.delegate.undo(modeluri);
}
redo(modeluri: string): Promise<ModelUpdateResult> {
redo(modeluri: URI): Promise<ModelUpdateResult> {
return this.delegate.redo(modeluri);
}
subscribe(modeluri: string, listener: SubscriptionListener, options?: SubscriptionOptions): SubscriptionListener {
subscribe(modeluri: URI, listener: SubscriptionListener, options?: SubscriptionOptions): SubscriptionListener {
return this.delegate.subscribe(modeluri, listener, options);
}
send(modelUri: string, message: ModelServerMessage<unknown>): void {
return this.delegate.send(modelUri, message);
send(modeluri: URI, message: ModelServerMessage<unknown>): void {
return this.delegate.send(modeluri, message);
}
unsubscribe(modelUri: string): void {
return this.delegate.unsubscribe(modelUri);
unsubscribe(modeluri: URI): void {
return this.delegate.unsubscribe(modeluri);
}

@@ -388,3 +381,3 @@ }

protected readonly transactionURI: string,
protected readonly modelURI: string,
protected readonly modelURI: URI,
protected readonly commandProviderRegistry: CommandProviderRegistry,

@@ -404,3 +397,3 @@ protected readonly triggerProviderRegistry: TriggerProviderRegistry,

// Doc inherited from `EditTransaction` interface
getModelURI(): string {
getModelURI(): URI {
return this.modelURI;

@@ -510,3 +503,3 @@ }

// Doc inherited from `Executor` interface
async execute(modelUri: string, command: ModelServerCommand): Promise<ModelUpdateResult> {
async execute(modelUri: URI, command: ModelServerCommand): Promise<ModelUpdateResult> {
if (!this.isOpen()) {

@@ -520,3 +513,3 @@ return Promise.reject('Socket is closed.');

/** Internal implementation of the {@link TransactionContext.execute} method. */
async doExecute(modelUri: string, command: ModelServerCommand): Promise<ModelUpdateResult> {
async doExecute(modelUri: URI, command: ModelServerCommand): Promise<ModelUpdateResult> {
// Hook in command-provider plug-ins

@@ -710,3 +703,3 @@ if (!this.commandProviderRegistry.hasProvider(command.type)) {

type,
modelUri: this.modelURI,
modeluri: this.modelURI,
data

@@ -713,0 +706,0 @@ };

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

import { inject, injectable, named } from 'inversify';
import * as URI from 'urijs';

@@ -97,3 +98,3 @@ /**

*/
async getCommands(modelUri: string, customCommand: ModelServerCommand): Promise<ModelServerCommand | Operation[] | Transaction> {
async getCommands(modelUri: URI, customCommand: ModelServerCommand): Promise<ModelServerCommand | Operation[] | Transaction> {
let result: ModelServerCommand | Operation[] | Transaction | undefined;

@@ -100,0 +101,0 @@ const provider = this.getProvider(customCommand);

@@ -105,6 +105,6 @@ /********************************************************************************

const delegated = isCreate //
? this.modelServerClient.create(modeluri.toString(), model, format)
: this.modelServerClient.update(modeluri.toString(), model, format);
? this.modelServerClient.create(modeluri, model, format)
: this.modelServerClient.update(modeluri, model, format);
delegated.then(this.performModelValidation(modeluri.toString())).then(relay(res)).catch(handleError(res));
delegated.then(this.performModelValidation(modeluri)).then(relay(res)).catch(handleError(res));
};

@@ -150,3 +150,3 @@ }

): void {
this.editService.edit(modelURI.toString(), patchOrCommand).then(relay(res)).catch(handleError(res));
this.editService.edit(modelURI, patchOrCommand).then(relay(res)).catch(handleError(res));
}

@@ -160,3 +160,3 @@

*/
protected performModelValidation(modelURI: string): (delegatedResult: AnyObject) => Promise<AnyObject> {
protected performModelValidation(modelURI: URI): (delegatedResult: AnyObject) => Promise<AnyObject> {
const validator = this.validationManager;

@@ -163,0 +163,0 @@

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

import { inject, injectable, named } from 'inversify';
import * as URI from 'urijs';

@@ -73,7 +74,10 @@ import { InternalModelServerClientApi } from '../client/model-server-client';

delegated.then(this.performLiveValidation(modelURI)).then(relay(res)).catch(handleError(res));
delegated
.then(this.performLiveValidation(new URI(modelURI)))
.then(relay(res))
.catch(handleError(res));
};
}
protected performLiveValidation(modelURI: string): (delegatedResult: ModelUpdateResult) => Promise<ModelUpdateResult> {
protected performLiveValidation(modelURI: URI): (delegatedResult: ModelUpdateResult) => Promise<ModelUpdateResult> {
const validator = this.validationManager;

@@ -80,0 +84,0 @@

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

import { inject, injectable, named } from 'inversify';
import * as URI from 'urijs';

@@ -71,5 +72,5 @@ import { InternalModelServerClientApi } from '../client/model-server-client';

this.validationManager.validate(modelURI).then(relay(res)).catch(handleError(res));
this.validationManager.validate(new URI(modelURI)).then(relay(res)).catch(handleError(res));
};
}
}

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

*******************************************************************************/
import { Logger, MiddlewareProvider, RouteProvider } from '@eclipse-emfcloud/modelserver-plugin-ext';
import { Logger, MiddlewareProvider, RouteProvider, RoutingOptions } from '@eclipse-emfcloud/modelserver-plugin-ext';
import axios, { AxiosInstance, AxiosRequestConfig, Method } from 'axios';
import * as express from 'express';
import { RequestHandler } from 'express';
import { Request, RequestHandler } from 'express';
import * as asyncify from 'express-asyncify';

@@ -21,2 +21,3 @@ import * as expressWS from 'express-ws';

import { inject, injectable, multiInject, named, optional, postConstruct } from 'inversify';
import * as URI from 'urijs';
import * as WebSocket from 'ws';

@@ -28,2 +29,21 @@

const STANDARD_ROUTES = new Set([
'/models',
'/modelelement',
'/modeluris',
'/server/ping',
'/server/configure',
'/subscribe',
'/close',
'/save',
'/saveall',
'/undo',
'/redo',
'/transaction',
'/validation',
'/validation/constraints',
'/typeschema',
'/uischema'
]);
/**

@@ -56,2 +76,4 @@ * The _Model Server_ core.

protected readonly backstopPaths = new Set<string>();
protected server: http.Server;

@@ -71,19 +93,45 @@

// Use provided middlewares that are applicable globally
this.middlewareProviders.flatMap(p => p.getMiddlewares(app)).forEach(mw => app.use(mw));
// Use provided before-middlewares that are applicable globally
this.middlewareProviders.flatMap(p => p.getMiddlewares?.(app) ?? []).forEach(mw => app.use(mw));
// Isolate contributed route handlers each in their own router.
const routes = {
routers: [],
factory: (route: string) => {
routers: [] as Array<{ route: string; router: express.Router; options?: RoutingOptions }>,
factory: (route: string, options?: RoutingOptions) => {
const newRouter = express.Router();
wsify(newRouter);
// Apply provided route-specific middlewares
this.middlewareProviders.flatMap(p => p.getMiddlewares(newRouter, route)).forEach(mw => newRouter.use(mw));
// Apply provided route-specific _before_ middlewares
this.middlewareProviders
.flatMap(p => p.getMiddlewares?.(newRouter, route, options?.routerId) ?? [])
.forEach(mw => newRouter.use(mw));
routes.routers.push({ route, router: newRouter });
routes.routers.push({ route, router: newRouter, options });
return newRouter;
},
install: () => routes.routers.forEach(r => app.use(r.route, r.router))
install: () =>
routes.routers.forEach(r => {
// Install middlewares after the route handlers
this.middlewareProviders
.flatMap(p => p.getAfterMiddlewares?.(r.router, r.route, r.options?.routerId) ?? [])
.forEach(mw => r.router.use(mw));
// Do we need a backstop to prevent `next()` delegation to the upstream server?
if (!r.options?.forwardToUpstream) {
// Record the routes supported by this router as needing to be backstopped.
// By default, do not backstop (i.e., allow to pass through) routes that are
// known to be supported by the upstream server because they are core
// Model Server API, unless the options expressly deny with an actual falsy value
const explicitlyBackstopped = typeof r.options?.forwardToUpstream !== 'undefined';
r.router.stack
.map(layer => r.route + (layer?.route?.path ?? ''))
.map(handledRoute => handledRoute.replace(/\/+$/, ''))
.filter(handledRoute => explicitlyBackstopped || !this.isModelServerRoute(handledRoute))
.forEach(backstopped => this.backstopPaths.add(backstopped));
}
// And install the router in the app
app.use(r.route, r.router);
})
};

@@ -96,4 +144,8 @@

const upstream = axios.create({ baseURL: `http://localhost:${upstreamPort}/` });
// Use provided after-middlewares that are applicable globally
this.middlewareProviders.flatMap(p => p.getAfterMiddlewares?.(app) ?? []).forEach(mw => app.use(mw));
const baseURL = new URI({ protocol: 'http', hostname: 'localhost', port: upstreamPort });
const upstream = axios.create({ baseURL: baseURL.toString() });
app.all('*', this.forward(upstream));

@@ -145,2 +197,7 @@ app.ws('*', this.forwardWS(upstream));

if (this.shouldBackstop(req)) {
// Don't forward to upstream
return;
}
const relayReq: AxiosRequestConfig = {

@@ -152,3 +209,3 @@ url: req.url,

this.logger.debug(`Forwarding ${req.method} request to Upstream Model Server.`);
this.logger.debug(`Forwarding ${req.method} request on ${req.url} to Upstream Model Server.`);

@@ -216,2 +273,11 @@ upstream

}
protected shouldBackstop(req: Request): boolean {
return this.backstopPaths.has(req.path);
}
protected isModelServerRoute(route: string): boolean {
const match = route.match(/^\/api\/v[0-9.]+(\/.*)/);
return match && STANDARD_ROUTES.has(match[1]);
}
}

@@ -218,0 +284,0 @@

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

import { inject, injectable, named } from 'inversify';
import * as URI from 'urijs';

@@ -43,3 +44,3 @@ import { InternalModelServerClientApi, isModelServerCommand, TransactionContext } from '../client/model-server-client';

async edit(modelURI: string, patchOrCommand: Operation | Operation[] | ModelServerCommand): Promise<ModelUpdateResult> {
async edit(modelURI: URI, patchOrCommand: Operation | Operation[] | ModelServerCommand): Promise<ModelUpdateResult> {
if (isModelServerCommand(patchOrCommand)) {

@@ -56,3 +57,3 @@ // Case of executing a command

protected async handleCommand(modelURI: string, command: ModelServerCommand): Promise<ModelUpdateResult> {
protected async handleCommand(modelURI: URI, command: ModelServerCommand): Promise<ModelUpdateResult> {
this.logger.debug(`Getting commands provided for ${command.type}`);

@@ -65,3 +66,3 @@

protected forwardEdit(
modelURI: string,
modelURI: URI,
providedEdit: ModelServerCommand | Operation | Operation[] | Transaction

@@ -76,3 +77,3 @@ ): Promise<ModelUpdateResult> {

private async forwardEditSimple(
modelURI: string,
modelURI: URI,
providedEdit: ModelServerCommand | Operation | Operation[] | Transaction

@@ -105,3 +106,3 @@ ): Promise<ModelUpdateResult> {

private async forwardEditWithTriggers(
modelURI: string,
modelURI: URI,
providedEdit: ModelServerCommand | Operation | Operation[] | Transaction

@@ -144,3 +145,3 @@ ): Promise<ModelUpdateResult> {

*/
protected performPatchValidation(modelURI: string): (validate: ModelUpdateResult) => Promise<ModelUpdateResult> {
protected performPatchValidation(modelURI: URI): (validate: ModelUpdateResult) => Promise<ModelUpdateResult> {
const validator = this.validationManager;

@@ -147,0 +148,0 @@

@@ -72,3 +72,3 @@ /********************************************************************************

edit(patchOrCommand: Operation | Operation[] | ModelServerCommand): Promise<ModelUpdateResult> {
return this.editService.edit(this.getModelURI().toString(), patchOrCommand);
return this.editService.edit(this.getModelURI(), patchOrCommand);
}

@@ -85,7 +85,7 @@

openTransaction(): Promise<EditTransaction> {
return this.client.openTransaction(this.getModelURI().toString());
return this.client.openTransaction(this.getModelURI());
}
validate(): Promise<Diagnostic> {
return this.validator.validate(this.getModelURI().toString());
return this.validator.validate(this.getModelURI());
}

@@ -92,0 +92,0 @@

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

import { stringify as unparseQuery } from 'qs';
import * as URI from 'urijs';
import * as WebSocket from 'ws';

@@ -133,5 +134,5 @@

*/
protected getSubscribers(modelURI: string, filter?: keyof SubscriptionQuery | ((options: SubscriptionQuery) => boolean)): JSONSocket[] {
protected getSubscribers(modelURI: URI, filter?: keyof SubscriptionQuery | ((options: SubscriptionQuery) => boolean)): JSONSocket[] {
return Array.from(this.subscriptions.keys())
.filter(client => client.options.modeluri === modelURI)
.filter(client => modelURI.equals(client.options.modeluri))
.filter(subscriberFilter(filter));

@@ -150,17 +151,17 @@ }

*/
protected hasSubscribers(modelURI: string, filter?: keyof SubscriptionQuery | ((options: SubscriptionQuery) => boolean)): boolean {
protected hasSubscribers(modelURI: URI, filter?: keyof SubscriptionQuery | ((options: SubscriptionQuery) => boolean)): boolean {
return Array.from(this.subscriptions.keys())
.filter(client => client.options.modeluri === modelURI)
.filter(client => modelURI.equals(client.options.modeluri))
.some(subscriberFilter(filter));
}
hasValidationSubscribers(modelURI: string): boolean {
hasValidationSubscribers(modelURI: URI): boolean {
return this.hasSubscribers(modelURI, 'livevalidation');
}
protected getValidationSubscribers(modelURI: string): JSONSocket[] {
protected getValidationSubscribers(modelURI: URI): JSONSocket[] {
return this.getSubscribers(modelURI, 'livevalidation');
}
async broadcastValidation(modelURI: string, results: Diagnostic): Promise<boolean> {
async broadcastValidation(modelURI: URI, results: Diagnostic): Promise<boolean> {
const message = {

@@ -167,0 +168,0 @@ type: MessageType.validationResult,

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

import { inject, injectable, named, postConstruct } from 'inversify';
import * as URI from 'urijs';
import { InternalModelServerClientApi } from '../client/model-server-client';
import { validateModelURI } from '../client/uri-utils';
import { JSONSocket } from '../client/web-socket-utils';

@@ -45,3 +47,3 @@ import { ValidationProviderRegistry } from '../validation-provider-registry';

if (params.livevalidation) {
this.initializeLiveValidation(client, params.modeluri);
this.initializeLiveValidation(client, validateModelURI(params.modeluri));
}

@@ -51,3 +53,3 @@ });

async validate(modelURI: string): Promise<Diagnostic> {
async validate(modelURI: URI): Promise<Diagnostic> {
let model: ModelServerObjectV2;

@@ -81,3 +83,3 @@ try {

*/
async performLiveValidation(modelURI: string): Promise<boolean> {
async performLiveValidation(modelURI: URI): Promise<boolean> {
// Short-circuit if there are no live validation subscribers

@@ -98,3 +100,3 @@ if (!this.subscriptionManager.hasValidationSubscribers(modelURI)) {

protected async initializeLiveValidation(client: JSONSocket, modelURI: string): Promise<unknown> {
protected async initializeLiveValidation(client: JSONSocket, modelURI: URI): Promise<unknown> {
return this.validate(modelURI)

@@ -101,0 +103,0 @@ .then(diagnostics => this.subscriptionManager.sendValidation(client, diagnostics))

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

import { inject, injectable, named } from 'inversify';
import * as URI from 'urijs';
import { v4 as uuid } from 'uuid';

@@ -66,3 +67,3 @@

getProviders(modelURI: string, patch: Operation[]): TriggerProvider[] {
getProviders(modelURI: URI, patch: Operation[]): TriggerProvider[] {
this.logger.debug('Looking up trigger providers for JSON Patch');

@@ -86,3 +87,3 @@ const result: TriggerProvider[] = [];

*/
getProvider(modelURI: string, patch: Operation[]): TriggerProvider | undefined {
getProvider(modelURI: URI, patch: Operation[]): TriggerProvider | undefined {
const providers = this.getProviders(modelURI, patch);

@@ -106,3 +107,3 @@ switch (providers.length) {

*/
async getTriggers(modelURI: string, patch: Operation[]): Promise<Operation[] | Transaction | undefined> {
async getTriggers(modelURI: URI, patch: Operation[]): Promise<Operation[] | Transaction | undefined> {
let result: Operation[] | Transaction | undefined;

@@ -131,3 +132,3 @@ const provider = this.getProvider(modelURI, patch);

canTrigger: () => true,
getTriggers: (modelURI: string, modelDelta: Operation[]) => async (executor: Executor) => {
getTriggers: (modelURI: URI, modelDelta: Operation[]) => async (executor: Executor) => {
let result = true;

@@ -134,0 +135,0 @@

@@ -15,7 +15,8 @@ /********************************************************************************

import { inject, injectable, named } from 'inversify';
import * as URI from 'urijs';
import { v4 as uuid } from 'uuid';
type ValidationProviderFilter = (model: ModelServerObjectV2, modelURI: string) => boolean;
type ValidationProviderFilter = (model: ModelServerObjectV2, modelURI: URI) => boolean;
export type Validator = (model: ModelServerObjectV2, modelURI: string) => Promise<Diagnostic>;
export type Validator = (model: ModelServerObjectV2, modelURI: URI) => Promise<Diagnostic>;

@@ -70,3 +71,3 @@ /**

hasProvider(model: ModelServerObjectV2, modelURI: string): boolean {
hasProvider(model: ModelServerObjectV2, modelURI: URI): boolean {
for (const next of this.providers.values()) {

@@ -80,3 +81,3 @@ if (next.filter(model, modelURI)) {

getProviders(model: ModelServerObjectV2, modelURI: string): ValidationProvider[] {
getProviders(model: ModelServerObjectV2, modelURI: URI): ValidationProvider[] {
const result: ValidationProvider[] = [];

@@ -91,3 +92,3 @@ this.providers.forEach(next => {

getValidator(model: ModelServerObjectV2, modelURI: string): Validator | undefined {
getValidator(model: ModelServerObjectV2, modelURI: URI): Validator | undefined {
this.logger.debug(`Looking up provider for validation of ${modelURI}`);

@@ -112,3 +113,3 @@ const providers = this.getProviders(model, modelURI);

*/
async validate(model: ModelServerObjectV2, modelURI: string): Promise<Diagnostic> {
async validate(model: ModelServerObjectV2, modelURI: URI): Promise<Diagnostic> {
const validator = this.getValidator(model, modelURI);

@@ -125,10 +126,10 @@ return validator(model, modelURI);

function createModelURIFilter(filter?: string | RegExp): (modelURI: string) => boolean {
function createModelURIFilter(filter?: string | RegExp): (modelURI: URI) => boolean {
if (!filter) return () => true;
if (typeof filter === 'string') return modelURI => modelURI.includes(filter);
return modelURI => filter.test(modelURI);
if (typeof filter === 'string') return modelURI => modelURI.toString().includes(filter);
return modelURI => filter.test(modelURI.toString());
}
function multiValidator(providers: ValidationProvider[]): Validator {
return async (model: ModelServerObjectV2, modelURI: string) => {
return async (model: ModelServerObjectV2, modelURI: URI) => {
const diagnostics = await Promise.all(providers.map(v => v.validate(model, modelURI)));

@@ -139,6 +140,6 @@ return summarize(model, modelURI, diagnostics);

function summarize(model: ModelServerObjectV2, modelURI: string, diagnostics: Diagnostic[]): Diagnostic {
function summarize(model: ModelServerObjectV2, modelURI: URI, diagnostics: Diagnostic[]): Diagnostic {
const result = Diagnostic.merge(...diagnostics);
if (result.severity > OK) {
result.message = `Diagnosis of ${modelURI}`;
result.message = `Diagnosis of ${modelURI.toString()}`;
result.id = '/';

@@ -145,0 +146,0 @@ }

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

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