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

sprotty-protocol

Package Overview
Dependencies
Maintainers
4
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sprotty-protocol - npm Package Compare versions

Comparing version 0.11.0-next.ddf634c to 0.11.0-next.e898c14.30

lib/action-handler.d.ts

1

lib/actions.d.ts

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

const KIND = "open";
function create(elementId: string): OpenAction;
}

@@ -287,0 +288,0 @@ /**

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

OpenAction.KIND = 'open';
function create(elementId) {
return {
kind: OpenAction.KIND,
elementId: elementId
};
}
OpenAction.create = create;
})(OpenAction = exports.OpenAction || (exports.OpenAction = {}));

@@ -232,0 +239,0 @@ var LayoutAction;

37

lib/diagram-server.d.ts

@@ -16,7 +16,7 @@ /********************************************************************************

********************************************************************************/
import { ServerActionHandler, ServerActionHandlerRegistry } from './action-handler';
import { Action, ResponseAction, RequestModelAction, ComputedBoundsAction, LayoutAction, RequestAction } from './actions';
import { DiagramServices, DiagramState, IDiagramGenerator, IModelLayoutEngine } from './diagram-services';
import { SModelRoot } from './model';
import { Deferred } from './utils/async';
import { JsonMap } from './utils/json';
import { SModelIndex } from './utils/model-utils';
/**

@@ -27,16 +27,17 @@ * An instance of this class is responsible for handling a single diagram client. It holds the current

export declare class DiagramServer {
protected readonly state: DiagramState & {
readonly state: DiagramState & {
lastSubmittedModelType?: string;
};
readonly dispatch: <A extends Action>(action: A) => Promise<void>;
protected readonly diagramGenerator: IDiagramGenerator;
protected readonly layoutEngine?: IModelLayoutEngine;
protected actionHandlerRegistry?: ServerActionHandlerRegistry;
protected readonly requests: Map<string, Deferred<ResponseAction>>;
protected readonly handlers: Map<string, ServerActionHandler<Action>[]>;
readonly dispatch: <A extends Action>(action: A) => Promise<void>;
readonly services: DiagramServices;
constructor(dispatch: <A extends Action>(action: A) => Promise<void>, services: DiagramServices);
/**
* Add an action handler to be called when an action of the specified kind is received.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
onAction<A extends Action>(kind: string, handler: ServerActionHandler<A>): void;
/**
* Remove an action handler that was previously added with `onAction`.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/

@@ -93,22 +94,2 @@ removeActionHandler<A extends Action>(kind: string, handler: ServerActionHandler<A>): void;

}
export declare type DiagramOptions = JsonMap;
export interface IModelLayoutEngine {
layout(model: SModelRoot, index?: SModelIndex): SModelRoot | Promise<SModelRoot>;
}
export interface IDiagramGenerator {
generate(args: {
options: DiagramOptions;
state: DiagramState;
}): SModelRoot | Promise<SModelRoot>;
}
export interface DiagramServices {
readonly diagramGenerator: IDiagramGenerator;
readonly layoutEngine: IModelLayoutEngine;
}
export interface DiagramState {
options?: DiagramOptions;
currentRoot: SModelRoot;
revision: number;
}
export declare type ServerActionHandler<A extends Action = Action> = (action: A, state: DiagramState, server: DiagramServer) => Promise<void>;
//# sourceMappingURL=diagram-server.d.ts.map

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

Object.defineProperty(exports, "__esModule", { value: true });
var action_handler_1 = require("./action-handler");
var actions_1 = require("./actions");

@@ -72,27 +73,22 @@ var async_1 = require("./utils/async");

this.requests = new Map();
this.handlers = new Map();
this.dispatch = dispatch;
this.services = services;
this.diagramGenerator = services.DiagramGenerator;
this.layoutEngine = services.ModelLayoutEngine;
this.actionHandlerRegistry = services.ServerActionHandlerRegistry;
}
/**
* Add an action handler to be called when an action of the specified kind is received.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
DiagramServer.prototype.onAction = function (kind, handler) {
if (this.handlers.has(kind)) {
this.handlers.get(kind).push(handler);
if (!this.actionHandlerRegistry) {
this.actionHandlerRegistry = new action_handler_1.ServerActionHandlerRegistry();
}
else {
this.handlers.set(kind, [handler]);
}
this.actionHandlerRegistry.onAction(kind, handler);
};
/**
* Remove an action handler that was previously added with `onAction`.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
DiagramServer.prototype.removeActionHandler = function (kind, handler) {
var list = this.handlers.get(kind);
if (list) {
var index = list.indexOf(handler);
if (index >= 0) {
list.splice(index, 1);
}
if (this.actionHandlerRegistry) {
this.actionHandlerRegistry.removeActionHandler(kind, handler);
}

@@ -208,4 +204,5 @@ };

var _this = this;
// Find a matching action handler in the registered map
var handlers = this.handlers.get(action.kind);
var _a;
// Find a matching action handler in the registry
var handlers = (_a = this.actionHandlerRegistry) === null || _a === void 0 ? void 0 : _a.getHandler(action.kind);
if (handlers && handlers.length === 1) {

@@ -241,3 +238,3 @@ return handlers[0](action, this.state, this);

_b.trys.push([1, 4, , 5]);
return [4 /*yield*/, this.services.diagramGenerator.generate({
return [4 /*yield*/, this.diagramGenerator.generate({
options: (_a = this.state.options) !== null && _a !== void 0 ? _a : {},

@@ -312,4 +309,4 @@ state: this.state

}
if (!this.needsServerLayout) return [3 /*break*/, 2];
return [4 /*yield*/, this.services.layoutEngine.layout(newRoot)];
if (!(this.needsServerLayout && this.layoutEngine)) return [3 /*break*/, 2];
return [4 /*yield*/, this.layoutEngine.layout(newRoot)];
case 1:

@@ -352,9 +349,25 @@ newRoot = _a.sent();

DiagramServer.prototype.handleLayout = function (action) {
if (!this.needsServerLayout) {
return Promise.resolve();
}
var newRoot = model_utils_1.cloneModel(this.state.currentRoot);
newRoot.revision = ++this.state.revision;
this.state.currentRoot = newRoot;
return this.doSubmitModel(newRoot, true, action);
return __awaiter(this, void 0, void 0, function () {
var newRoot;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.layoutEngine) {
return [2 /*return*/];
}
if (!!this.needsServerLayout) return [3 /*break*/, 2];
newRoot = model_utils_1.cloneModel(this.state.currentRoot);
return [4 /*yield*/, this.layoutEngine.layout(newRoot)];
case 1:
newRoot = _a.sent();
newRoot.revision = ++this.state.revision;
this.state.currentRoot = newRoot;
_a.label = 2;
case 2: return [4 /*yield*/, this.doSubmitModel(this.state.currentRoot, true, action)];
case 3:
_a.sent();
return [2 /*return*/];
}
});
});
};

@@ -361,0 +374,0 @@ return DiagramServer;

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

export * from './diagram-server';
export * from './diagram-services';
export * from './model';

@@ -20,0 +21,0 @@ export * from './utils/async';

{
"name": "sprotty-protocol",
"version": "0.11.0-next.ddf634c",
"version": "0.11.0-next.e898c14.30+e898c14",
"description": "TypeScript declarations for Sprotty to be used both in browser and Node.js context",

@@ -31,3 +31,2 @@ "license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)",

},
"dependencies": {},
"devDependencies": {

@@ -53,6 +52,3 @@ "@types/mocha": "^7.0.2",

"lint": "eslint -c ../../configs/.eslintrc.js \"src/**/!(*.spec.ts*)\"",
"test": "mocha --config ../../configs/.mocharc.json \"./src/**/*.spec.?(ts|tsx)\"",
"prepublishOnly": "yarn run test",
"publish:next": "yarn publish --new-version \"$(semver $npm_package_version -i minor)-next.$(git rev-parse --short HEAD)\" --tag next",
"publish:latest": "yarn publish --tag latest"
"test": "mocha --config ../../configs/.mocharc.json \"./src/**/*.spec.?(ts|tsx)\""
},

@@ -67,3 +63,4 @@ "files": [

"src/**/*.spec.?(ts|tsx)"
]
],
"gitHead": "e898c14efbb54155049c2aa6c14dd5ead150eaa1"
}

@@ -301,3 +301,3 @@ /********************************************************************************

*/
export interface ElementAndBounds {
export interface ElementAndBounds {
elementId: string

@@ -311,3 +311,3 @@ newPosition?: Point

*/
export interface ElementAndAlignment {
export interface ElementAndAlignment {
elementId: string

@@ -363,3 +363,3 @@ newAlignment: Point

*/
export interface CollapseExpandAction {
export interface CollapseExpandAction {
kind: typeof CollapseExpandAction.KIND

@@ -385,3 +385,3 @@ expandIds: string[]

*/
export interface CollapseExpandAllAction {
export interface CollapseExpandAllAction {
kind: typeof CollapseExpandAllAction.KIND

@@ -407,2 +407,9 @@ expand: boolean

export const KIND = 'open';
export function create(elementId: string): OpenAction {
return {
kind: KIND,
elementId
};
}
}

@@ -409,0 +416,0 @@

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

import { Action, ComputedBoundsAction, RequestBoundsAction, RequestModelAction, SetModelAction } from './actions';
import { DiagramServer, ServerActionHandler } from './diagram-server';
import { DiagramServer } from './diagram-server';
import { BoundsAware, SModelRoot } from './model';
import { ServerActionHandler, ServerActionHandlerRegistry } from './action-handler';

@@ -43,4 +44,9 @@ declare function setImmediate(callback: () => void): void;

describe('DiagramServer', () => {
function createServer(): { server: DiagramServer, dispatched: Action[] } {
function createServer(): {
server: DiagramServer,
actionHandlerRegistry: ServerActionHandlerRegistry,
dispatched: Action[]
} {
const dispatched: Action[] = [];
const actionHandlerRegistry = new ServerActionHandlerRegistry();
const server = new DiagramServer(

@@ -50,3 +56,3 @@ async a => {

}, {
diagramGenerator: {
DiagramGenerator: {
generate: () => {

@@ -59,3 +65,3 @@ return {

},
layoutEngine: {
ModelLayoutEngine: {
layout: model => {

@@ -65,5 +71,6 @@ (model as SModelRoot & BoundsAware).position = { x: 10, y: 10 };

}
}
},
ServerActionHandlerRegistry: actionHandlerRegistry
});
return { server, dispatched };
return { server, actionHandlerRegistry, dispatched };
}

@@ -177,4 +184,4 @@

it('calls a registered action handler', async () => {
const { server, dispatched } = createServer();
server.onAction('foo', (_, state, server) => {
const { server, actionHandlerRegistry, dispatched } = createServer();
actionHandlerRegistry.onAction('foo', (_, state, server) => {
state.revision = -7;

@@ -191,3 +198,3 @@ server.dispatch({ kind: 'bar' });

it('does not call an unregistered action handler', async () => {
const { server, dispatched } = createServer();
const { server, actionHandlerRegistry, dispatched } = createServer();
const handler: ServerActionHandler = (_, state, server) => {

@@ -198,4 +205,4 @@ state.revision = -7;

};
server.onAction('foo', handler);
server.removeActionHandler('foo', handler);
actionHandlerRegistry.onAction('foo', handler);
actionHandlerRegistry.removeActionHandler('foo', handler);
await server.accept({ kind: 'foo' });

@@ -202,0 +209,0 @@ expect((server as any).state.revision).to.equal(0);

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

import { ServerActionHandler, ServerActionHandlerRegistry } from './action-handler';
import {

@@ -22,6 +23,6 @@ Action, isResponseAction, ResponseAction, RequestModelAction, ComputedBoundsAction, LayoutAction, RequestBoundsAction,

} from './actions';
import { DiagramServices, DiagramState, IDiagramGenerator, IModelLayoutEngine } from './diagram-services';
import { SModelRoot } from './model';
import { Deferred } from './utils/async';
import { JsonMap } from './utils/json';
import { applyBounds, cloneModel, SModelIndex } from './utils/model-utils';
import { applyBounds, cloneModel } from './utils/model-utils';

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

protected readonly state: DiagramState & {
readonly state: DiagramState & {
lastSubmittedModelType?: string

@@ -44,34 +45,33 @@ } = {

};
protected readonly requests = new Map<string, Deferred<ResponseAction>>();
protected readonly handlers = new Map<string, ServerActionHandler[]>();
readonly dispatch: <A extends Action>(action: A) => Promise<void>;
readonly services: DiagramServices;
protected readonly diagramGenerator: IDiagramGenerator;
protected readonly layoutEngine?: IModelLayoutEngine;
protected actionHandlerRegistry?: ServerActionHandlerRegistry;
protected readonly requests = new Map<string, Deferred<ResponseAction>>();
constructor(dispatch: <A extends Action>(action: A) => Promise<void>,
services: DiagramServices) {
this.dispatch = dispatch;
this.services = services;
this.diagramGenerator = services.DiagramGenerator;
this.layoutEngine = services.ModelLayoutEngine;
this.actionHandlerRegistry = services.ServerActionHandlerRegistry;
}
/**
* Add an action handler to be called when an action of the specified kind is received.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
onAction<A extends Action>(kind: string, handler: ServerActionHandler<A>) {
if (this.handlers.has(kind)) {
this.handlers.get(kind)!.push(handler);
} else {
this.handlers.set(kind, [handler]);
if (!this.actionHandlerRegistry) {
this.actionHandlerRegistry = new ServerActionHandlerRegistry();
}
this.actionHandlerRegistry.onAction(kind, handler);
}
/**
* Remove an action handler that was previously added with `onAction`.
* @deprecated Use the `ServerActionHandlerRegistry` service instead
*/
removeActionHandler<A extends Action>(kind: string, handler: ServerActionHandler<A>) {
const list = this.handlers.get(kind);
if (list) {
const index = list.indexOf(handler);
if (index >= 0) {
list.splice(index, 1);
}
if (this.actionHandlerRegistry) {
this.actionHandlerRegistry.removeActionHandler(kind, handler);
}

@@ -184,4 +184,4 @@ }

protected handleAction(action: Action): Promise<void> {
// Find a matching action handler in the registered map
const handlers = this.handlers.get(action.kind);
// Find a matching action handler in the registry
const handlers = this.actionHandlerRegistry?.getHandler(action.kind);
if (handlers && handlers.length === 1) {

@@ -209,3 +209,3 @@ return handlers[0](action, this.state, this);

try {
const newRoot = await this.services.diagramGenerator.generate({
const newRoot = await this.diagramGenerator.generate({
options: this.state.options ?? {},

@@ -251,4 +251,4 @@ state: this.state

}
if (this.needsServerLayout) {
newRoot = await this.services.layoutEngine.layout(newRoot);
if (this.needsServerLayout && this.layoutEngine) {
newRoot = await this.layoutEngine.layout(newRoot);
}

@@ -276,35 +276,15 @@ const modelType = newRoot.type;

protected handleLayout(action: LayoutAction): Promise<void> {
protected async handleLayout(action: LayoutAction): Promise<void> {
if (!this.layoutEngine) {
return;
}
if (!this.needsServerLayout) {
return Promise.resolve();
let newRoot = cloneModel(this.state.currentRoot);
newRoot = await this.layoutEngine.layout(newRoot);
newRoot.revision = ++this.state.revision;
this.state.currentRoot = newRoot;
}
const newRoot = cloneModel(this.state.currentRoot);
newRoot.revision = ++this.state.revision;
this.state.currentRoot = newRoot;
return this.doSubmitModel(newRoot, true, action);
await this.doSubmitModel(this.state.currentRoot, true, action);
}
}
export type DiagramOptions = JsonMap;
export interface IModelLayoutEngine {
layout(model: SModelRoot, index?: SModelIndex): SModelRoot | Promise<SModelRoot>;
}
export interface IDiagramGenerator {
generate(args: { options: DiagramOptions, state: DiagramState }): SModelRoot | Promise<SModelRoot>
}
export interface DiagramServices {
readonly diagramGenerator: IDiagramGenerator
readonly layoutEngine: IModelLayoutEngine;
}
export interface DiagramState {
options?: DiagramOptions;
currentRoot: SModelRoot;
revision: number;
}
export type ServerActionHandler<A extends Action = Action> = (action: A, state: DiagramState, server: DiagramServer) => Promise<void>;

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

export * from './diagram-server';
export * from './diagram-services';
export * from './model';

@@ -21,0 +22,0 @@ export * from './utils/async';

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