Socket
Socket
Sign inDemoInstall

@eclipse-emfcloud/modelserver-client

Package Overview
Dependencies
Maintainers
8
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 0.8.0-next.fd477972 to 0.8.0-theia-cr01

8

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

@@ -10,3 +14,3 @@ if (k2 === undefined) k2 = k;

var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};

@@ -13,0 +17,0 @@ Object.defineProperty(exports, "__esModule", { value: true });

@@ -49,2 +49,11 @@ /********************************************************************************

/**
* A union type that represents all Patches or Commands supported by the model server:
* - Operation
* - Operation[] (Json Patch)
* - ModelPatch
* - ModelPatch[]
* - ModelServerCommand
*/
export declare type PatchOrCommand = Operation | Operation[] | ModelPatch | ModelPatch[] | ModelServerCommand;
/**
* Basic client API to interact with a model server that conforms to the Modelserver API Version 2.

@@ -91,4 +100,3 @@ */

ping(): Promise<boolean>;
edit(modeluri: string, patch: Operation | Operation[], format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: string, command: ModelServerCommand, format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: string, patchOrCommand: PatchOrCommand, format?: Format): Promise<ModelUpdateResult>;
undo(modeluri: string): Promise<ModelUpdateResult>;

@@ -104,2 +112,15 @@ redo(modeluri: string): Promise<ModelUpdateResult>;

/**
* A patch affecting a specific model.
*/
export interface ModelPatch {
/**
* The uri of the patched model.
*/
modelUri: string;
/**
* The patch describing the changes applied to the model.
*/
patch: Operation[];
}
/**
* Result sent to client after requesting a model update.

@@ -121,5 +142,8 @@ */

* the original model unchanged.
* @param modelUri the uri of the model to patch. This can be used when the model is split in multiple
* resources, to identify the patch to apply. The modelUri should correspond to the oldModel object.
* It can be omitted when patching the main model (or in single-model cases).
* @return the patched model.
*/
patchModel?(oldModel: ModelServerElement, copy?: boolean): ModelServerElement;
patchModel?(oldModel: ModelServerElement, copy?: boolean, modelUri?: string): ModelServerElement;
/**

@@ -130,3 +154,10 @@ * The Json Patch describing the changes that were applied to the model. Only present if

patch?: Operation[];
/**
* The list of Json Patches describing the changes that were applied to the models. Only present if
* the edit request was successful.
*
* The list contains one entry per modified model. Unmodified models will not contain any entry.
*/
allPatches?: ModelPatch[];
}
//# sourceMappingURL=model-server-client-api-v2.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -45,10 +49,10 @@ return result;

const undoModel = await client.get(modeluri, _1.ModelServerObjectV2.is);
chai_1.expect(undoModel).to.deep.equal(originalModel);
(0, chai_1.expect)(undoModel).to.deep.equal(originalModel);
const patchedUndoModel = undoPatch.patchModel(patchedModel, true);
chai_1.expect(patchedUndoModel).to.deep.equal(originalModel);
(0, chai_1.expect)(patchedUndoModel).to.deep.equal(originalModel);
const redoPatch = await client.redo(modeluri);
const redoModel = await client.get(modeluri, _1.ModelServerObjectV2.is);
chai_1.expect(redoModel).to.deep.equal(patchedModel);
(0, chai_1.expect)(redoModel).to.deep.equal(patchedModel);
const patchedRedoModel = redoPatch.patchModel(patchedUndoModel, true);
chai_1.expect(patchedRedoModel).to.deep.equal(patchedModel);
(0, chai_1.expect)(patchedRedoModel).to.deep.equal(patchedModel);
// Restore initial state

@@ -66,6 +70,6 @@ await client.undo(modeluri);

const machine = await client.get(modeluri, _1.ModelServerObjectV2.is);
const patch = _1.replace(modeluri, machine, 'name', newName);
const patch = (0, _1.replace)(modeluri, machine, 'name', newName);
await client.edit(modeluri, patch);
const model = await client.get(modeluri);
chai_1.expect(model.name).to.be.equal(newName);
(0, chai_1.expect)(model.name).to.be.equal(newName);
await testUndoRedo(modeluri, machine, model);

@@ -78,11 +82,11 @@ });

const initialWorkflowsCount = originalModel.workflows.length;
const patch = _1.create(modeluri, originalModel, 'workflows', 'http://www.eclipsesource.com/modelserver/example/coffeemodel#//Workflow', { name: newWorkflowName });
const patch = (0, _1.create)(modeluri, originalModel, 'workflows', 'http://www.eclipsesource.com/modelserver/example/coffeemodel#//Workflow', { name: newWorkflowName });
await client.edit(modeluri, patch);
const patchedModel = await client.get(modeluri);
const workflows = patchedModel.workflows;
chai_1.expect(workflows.length).to.be.equal(initialWorkflowsCount + 1);
(0, chai_1.expect)(workflows.length).to.be.equal(initialWorkflowsCount + 1);
const newWorkflow = patchedModel.workflows[initialWorkflowsCount];
chai_1.expect(newWorkflow.name).to.be.equal(newWorkflowName);
chai_1.expect(newWorkflow).to.have.property('$id');
chai_1.expect(newWorkflow.$id).to.be.a('string');
(0, chai_1.expect)(newWorkflow.name).to.be.equal(newWorkflowName);
(0, chai_1.expect)(newWorkflow).to.have.property('$id');
(0, chai_1.expect)(newWorkflow.$id).to.be.a('string');
await testUndoRedo(modeluri, originalModel, patchedModel);

@@ -94,3 +98,3 @@ });

// Add a second workflow to the model; we'll use it to move a Task from a workflow to the other
const createWorkflow = _1.create(modeluri, initialModel, 'workflows', 'http://www.eclipsesource.com/modelserver/example/coffeemodel#//Workflow', { name: 'New Workflow' });
const createWorkflow = (0, _1.create)(modeluri, initialModel, 'workflows', 'http://www.eclipsesource.com/modelserver/example/coffeemodel#//Workflow', { name: 'New Workflow' });
await client.edit(modeluri, createWorkflow);

@@ -100,3 +104,3 @@ const originalModel = await client.get(modeluri, _1.ModelServerObjectV2.is);

const targetWF = originalModel.workflows[1];
const patch = _1.add(modeluri, targetWF, 'nodes', sourceWF.nodes[0]);
const patch = (0, _1.add)(modeluri, targetWF, 'nodes', sourceWF.nodes[0]);
await client.edit(modeluri, patch);

@@ -106,5 +110,5 @@ const patchedModel = await client.get(modeluri);

const patchedTargetWF = patchedModel.workflows[1];
chai_1.expect(patchedSourceWF.nodes).to.be.undefined;
chai_1.expect(patchedTargetWF.nodes).to.be.an('array').of.length(1);
chai_1.expect(patchedTargetWF.nodes[0].name).to.be.equal(sourceWF.nodes[0].name); // Node was moved
(0, chai_1.expect)(patchedSourceWF.nodes).to.be.undefined;
(0, chai_1.expect)(patchedTargetWF.nodes).to.be.an('array').of.length(1);
(0, chai_1.expect)(patchedTargetWF.nodes[0].name).to.be.equal(sourceWF.nodes[0].name); // Node was moved
await testUndoRedo(modeluri, originalModel, patchedModel);

@@ -116,8 +120,8 @@ });

const parentWorkflow = originalModel.workflows[0];
chai_1.expect(parentWorkflow.nodes).to.be.an('array').that.is.not.empty;
const patch = _1.removeValueAt(modeluri, parentWorkflow, 'nodes', 0);
(0, chai_1.expect)(parentWorkflow.nodes).to.be.an('array').that.is.not.empty;
const patch = (0, _1.removeValueAt)(modeluri, parentWorkflow, 'nodes', 0);
await client.edit(modeluri, patch);
const patchedModel = await client.get(modeluri);
const patchedParentWorkflow = patchedModel.workflows[0];
chai_1.expect(patchedParentWorkflow.nodes).to.be.undefined;
(0, chai_1.expect)(patchedParentWorkflow.nodes).to.be.undefined;
await testUndoRedo(modeluri, originalModel, patchedModel);

@@ -129,9 +133,9 @@ });

const parentWorkflow = originalModel.workflows[0];
chai_1.expect(parentWorkflow.nodes).to.be.an('array').that.is.not.empty;
(0, chai_1.expect)(parentWorkflow.nodes).to.be.an('array').that.is.not.empty;
const valueToRemove = parentWorkflow.nodes[0];
const patch = _1.removeObject(modeluri, valueToRemove);
const patch = (0, _1.removeObject)(modeluri, valueToRemove);
await client.edit(modeluri, patch);
const patchedModel = await client.get(modeluri);
const patchedParentWorkflow = patchedModel.workflows[0];
chai_1.expect(patchedParentWorkflow.nodes).to.be.undefined;
(0, chai_1.expect)(patchedParentWorkflow.nodes).to.be.undefined;
await testUndoRedo(modeluri, originalModel, patchedModel);

@@ -150,3 +154,3 @@ });

const model = await client.get(modeluri);
chai_1.expect(model.name).to.be.equal(newName);
(0, chai_1.expect)(model.name).to.be.equal(newName);
await testUndoRedo(modeluri, originalModel, model);

@@ -158,14 +162,14 @@ });

const machine = await client.get(modeluri, _1.ModelServerObjectV2.is);
const patch = _1.replace(modeluri, machine, 'name', newName);
const patch = (0, _1.replace)(modeluri, machine, 'name', newName);
const updateResult = await client.edit(modeluri, patch);
chai_1.expect(updateResult.success).to.be.true;
chai_1.expect(updateResult.patchModel).to.not.be.undefined;
chai_1.expect(updateResult.patch).to.not.be.undefined;
(0, chai_1.expect)(updateResult.success).to.be.true;
(0, chai_1.expect)(updateResult.patchModel).to.not.be.undefined;
(0, chai_1.expect)(updateResult.patch).to.not.be.undefined;
// Patch a copy of the model (machine), to make sure the original model is
// unchanged. We'll need it later to check undo/redo behavior.
const patchedMachine = updateResult.patchModel(machine, true);
chai_1.expect(patchedMachine.name).to.be.equal(newName);
(0, chai_1.expect)(patchedMachine.name).to.be.equal(newName);
// Check that the incremental update is consistent with the server version of the model
const newMachine = await client.get(modeluri, _1.ModelServerObjectV2.is);
chai_1.expect(newMachine).to.deep.equal(patchedMachine);
(0, chai_1.expect)(newMachine).to.deep.equal(patchedMachine);
await testUndoRedo(modeluri, machine, patchedMachine);

@@ -196,9 +200,9 @@ });

const patch = notification.patch;
chai_1.expect(notification.modelUri).to.be.equal(modeluri);
chai_1.expect(patch.length).to.be.equal(1);
(0, chai_1.expect)(notification.modelUri).to.be.equal(modeluri);
(0, chai_1.expect)(patch.length).to.be.equal(1);
const operation = patch[0];
chai_1.expect(_1.Operations.isReplace(operation, 'string')).to.be.equal(true);
chai_1.expect(operation.path).to.be.equal('/name');
(0, chai_1.expect)(_1.Operations.isReplace(operation, 'string')).to.be.equal(true);
(0, chai_1.expect)(operation.path).to.be.equal('/name');
if (_1.Operations.isReplace(operation, 'string')) {
chai_1.expect(operation.value).to.be.equal(newName);
(0, chai_1.expect)(operation.value).to.be.equal(newName);
}

@@ -236,3 +240,3 @@ await client.undo(modeluri);

// from the model server.
chai_1.expect(incrementalPatchedModel).to.deep.equal(patchedModel);
(0, chai_1.expect)(incrementalPatchedModel).to.deep.equal(patchedModel);
await client.undo(modeluri);

@@ -245,3 +249,3 @@ client.unsubscribe(modeluri);

const machine = await client.get(modeluri, _1.ModelServerObjectV2.is);
const patchedMachine = fast_json_patch_1.deepClone(machine);
const patchedMachine = (0, fast_json_patch_1.deepClone)(machine);
// Directly change the model

@@ -254,4 +258,4 @@ patchedMachine.name = newName;

const model = await client.get(modeluri);
chai_1.expect(model.name).to.be.equal(newName);
chai_1.expect(model.children[1].processor.clockSpeed).to.be.equal(6);
(0, chai_1.expect)(model.name).to.be.equal(newName);
(0, chai_1.expect)(model.children[1].processor.clockSpeed).to.be.equal(6);
await testUndoRedo(modeluri, machine, model);

@@ -263,3 +267,3 @@ });

const initialWorkflowsSize = machine.workflows.length;
chai_1.expect(initialWorkflowsSize).to.not.be.equal(0);
(0, chai_1.expect)(initialWorkflowsSize).to.not.be.equal(0);
const patch = [

@@ -274,3 +278,3 @@ {

const newWorkflows = model.workflows;
chai_1.expect(newWorkflows).to.be.undefined;
(0, chai_1.expect)(newWorkflows).to.be.undefined;
await testUndoRedo(modeluri, machine, model);

@@ -282,3 +286,3 @@ });

const initialValue = machine.children[1].processor.thermalDesignPower;
chai_1.expect(initialValue).to.not.be.oneOf([undefined, 0]);
(0, chai_1.expect)(initialValue).to.not.be.oneOf([undefined, 0]);
const patch = [

@@ -293,7 +297,57 @@ {

const newValue = model.children[1].processor.thermalDesignPower;
chai_1.expect(newValue).to.be.oneOf([undefined, 0]); // Should be === 0, but default values are not converted to Json at the moment; so we also expect 'undefined'
(0, chai_1.expect)(newValue).to.be.oneOf([undefined, 0]); // Should be === 0, but default values are not converted to Json at the moment; so we also expect 'undefined'
await testUndoRedo(modeluri, machine, model);
});
it('check all patch replies', async () => {
const modeluri = 'SuperBrewer3000.coffee';
const newName = 'Super Brewer 6000';
const machine = await client.get(modeluri, _1.ModelServerObjectV2.is);
const patchedMachine = (0, fast_json_patch_1.deepClone)(machine);
// Directly change the model
patchedMachine.name = newName;
patchedMachine.children[1].processor.clockSpeed = 6;
// Generate patch by diffing the original model and the patched one
const patch = fast_json_patch_1.default.compare(machine, patchedMachine);
const result = await client.edit(modeluri, patch);
(0, chai_1.expect)(result.success).to.be.true;
(0, chai_1.expect)(result.patch).to.not.be.undefined;
(0, chai_1.expect)(result.allPatches).to.not.be.undefined;
(0, chai_1.expect)(result.allPatches).to.be.an('array').of.length(1);
// Patch the main resource
const updatedMachineMainPatch = result.patchModel(machine, true);
(0, chai_1.expect)(patchedMachine).to.deep.equal(updatedMachineMainPatch);
// Patch the first resource
const updatedMachineFirstPatch = result.patchModel(machine, true, result.allPatches[0].modelUri);
(0, chai_1.expect)(patchedMachine).to.deep.equal(updatedMachineFirstPatch);
await testUndoRedo(modeluri, machine, updatedMachineFirstPatch);
});
it('test model patches', async () => {
const modeluri = 'SuperBrewer3000.coffee';
const newName = 'Super Brewer 6000';
const machine = await client.get(modeluri, _1.ModelServerObjectV2.is);
const patchedMachine = (0, fast_json_patch_1.deepClone)(machine);
// Directly change the model
patchedMachine.name = newName;
patchedMachine.children[1].processor.clockSpeed = 6;
// Generate patch by diffing the original model and the patched one
const patch = fast_json_patch_1.default.compare(machine, patchedMachine);
const modelPatch = {
modelUri: modeluri,
patch
};
const result = await client.edit(modeluri, modelPatch);
(0, chai_1.expect)(result.success).to.be.true;
(0, chai_1.expect)(result.patch).to.not.be.undefined;
(0, chai_1.expect)(result.allPatches).to.not.be.undefined;
(0, chai_1.expect)(result.allPatches).to.be.an('array').of.length(1);
// Patch the main resource
const updatedMachineMainPatch = result.patchModel(machine, true);
(0, chai_1.expect)(patchedMachine).to.deep.equal(updatedMachineMainPatch);
// Patch the first resource
const updatedMachineFirstPatch = result.patchModel(machine, true, result.allPatches[0].modelUri);
(0, chai_1.expect)(patchedMachine).to.deep.equal(updatedMachineFirstPatch);
await testUndoRedo(modeluri, machine, updatedMachineFirstPatch);
});
});
});
//# sourceMappingURL=model-server-client-v2-integration.spec.js.map

@@ -12,8 +12,6 @@ /********************************************************************************

import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { Operation } from 'fast-json-patch';
import WebSocket from 'isomorphic-ws';
import { ModelServerCommand } from './model/command-model';
import { Diagnostic } from './model/diagnostic';
import { ServerConfiguration, SubscriptionOptions } from './model-server-client-api-v1';
import { Format, ModelServerClientApiV2, ModelUpdateResult } from './model-server-client-api-v2';
import { Format, ModelServerClientApiV2, ModelUpdateResult, PatchOrCommand } from './model-server-client-api-v2';
import { MessageDataMapper, Model, ModelServerMessage } from './model-server-message';

@@ -56,5 +54,3 @@ import { SubscriptionListener } from './subscription-listener';

ping(): Promise<boolean>;
edit(modeluri: string, patch: Operation): Promise<ModelUpdateResult>;
edit(modeluri: string, patch: Operation[]): Promise<ModelUpdateResult>;
edit(modeluri: string, command: ModelServerCommand): Promise<ModelUpdateResult>;
edit(modeluri: string, patchOrCommand: PatchOrCommand, format?: string): Promise<ModelUpdateResult>;
undo(modeluri: string): Promise<ModelUpdateResult>;

@@ -61,0 +57,0 @@ redo(modeluri: string): Promise<ModelUpdateResult>;

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

const axios_1 = __importDefault(require("axios"));
const fast_json_patch_1 = require("fast-json-patch");
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));

@@ -36,3 +37,3 @@ const command_model_1 = require("./model/command-model");

initialize(baseUrl, defaultFormat = model_server_client_api_v2_1.FORMAT_JSON_V2) {
this._baseUrl = baseUrl;
this._baseUrl = baseUrl.endsWith('/') ? baseUrl.substring(0, baseUrl.length - 1) : baseUrl;
this.defaultFormat = defaultFormat;

@@ -98,7 +99,7 @@ this.restClient = axios_1.default.create(this.getAxiosConfig(baseUrl));

const typeGuard = formatOrGuard;
return this.process(this.restClient.post(model_server_paths_1.ModelServerPaths.MODEL_CRUD, type_util_1.encodeRequestBody(format)(model), { params: { modeluri, format } }), msg => model_server_message_1.MessageDataMapper.as(msg, typeGuard));
return this.process(this.restClient.post(model_server_paths_1.ModelServerPaths.MODEL_CRUD, (0, type_util_1.encodeRequestBody)(format)(model), { params: { modeluri, format } }), msg => model_server_message_1.MessageDataMapper.as(msg, typeGuard));
}
format = formatOrGuard;
}
return this.process(this.restClient.post(model_server_paths_1.ModelServerPaths.MODEL_CRUD, type_util_1.encodeRequestBody(format)(model), { params: { modeluri, format } }), model_server_message_1.MessageDataMapper.asObject);
return this.process(this.restClient.post(model_server_paths_1.ModelServerPaths.MODEL_CRUD, (0, type_util_1.encodeRequestBody)(format)(model), { params: { modeluri, format } }), model_server_message_1.MessageDataMapper.asObject);
}

@@ -110,7 +111,7 @@ update(modeluri, model, formatOrGuard, format) {

const typeGuard = formatOrGuard;
return this.process(this.restClient.put(model_server_paths_1.ModelServerPaths.MODEL_CRUD, type_util_1.encodeRequestBody(format)(model), { params: { modeluri, format } }), msg => model_server_message_1.MessageDataMapper.as(msg, typeGuard));
return this.process(this.restClient.put(model_server_paths_1.ModelServerPaths.MODEL_CRUD, (0, type_util_1.encodeRequestBody)(format)(model), { params: { modeluri, format } }), msg => model_server_message_1.MessageDataMapper.as(msg, typeGuard));
}
format = formatOrGuard;
}
return this.process(this.restClient.put(model_server_paths_1.ModelServerPaths.MODEL_CRUD, type_util_1.encodeRequestBody(format)(model), { params: { modeluri, format } }), model_server_message_1.MessageDataMapper.asObject);
return this.process(this.restClient.put(model_server_paths_1.ModelServerPaths.MODEL_CRUD, (0, type_util_1.encodeRequestBody)(format)(model), { params: { modeluri, format } }), model_server_message_1.MessageDataMapper.asObject);
}

@@ -150,3 +151,3 @@ delete(modeluri) {

}
edit(modeluri, patchOrCommand) {
edit(modeluri, patchOrCommand, format = this.defaultFormat) {
let patchMessage;

@@ -160,2 +161,3 @@ if (patchOrCommand instanceof command_model_1.ModelServerCommand) {

else {
// Operation[] and ModelPatch[] are treated in the same way; we don't need to distinguish both cases
const fullPatch = Array.isArray(patchOrCommand) ? patchOrCommand : [patchOrCommand];

@@ -166,5 +168,13 @@ patchMessage = {

};
if (fullPatch.length === 0) {
// No-op
return Promise.resolve({
success: true,
patchModel: (oldModel, copy, _modelUri) => (copy ? (0, fast_json_patch_1.deepClone)(oldModel) : oldModel),
patch: []
});
}
}
return this.process(this.restClient.patch(model_server_paths_1.ModelServerPaths.MODEL_CRUD, type_util_1.encodeRequestBody(this.defaultFormat)(patchMessage), {
params: { modeluri, format: this.defaultFormat }
return this.process(this.restClient.patch(model_server_paths_1.ModelServerPaths.MODEL_CRUD, (0, type_util_1.encodeRequestBody)(format)(patchMessage), {
params: { modeluri, format: format }
}), model_server_message_1.MessageDataMapper.patchModel);

@@ -189,3 +199,3 @@ }

if (options.errorWhenUnsuccessful) {
throw new Error('errorMsg');
throw new Error(errorMsg);
}

@@ -252,9 +262,9 @@ }

if (guard) {
return { modelUri, content: type_util_1.asType(content, guard) };
return { modelUri, content: (0, type_util_1.asType)(content, guard) };
}
else if (toString) {
return { modelUri, content: type_util_1.asString(content) };
return { modelUri, content: (0, type_util_1.asString)(content) };
}
return { modelUri, content: type_util_1.asObject(content) };
return { modelUri, content: (0, type_util_1.asObject)(content) };
}
//# sourceMappingURL=model-server-client-v2.js.map

@@ -36,4 +36,16 @@ "use strict";

const axios = client['restClient'];
chai_1.expect(axios.defaults.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(axios.defaults.baseURL).to.be.equal(baseUrl);
});
it('test createSubscriptionPath without trailing slash', () => {
client = new model_server_client_v2_1.ModelServerClientV2();
client.initialize(baseUrl);
const subscriptionPath = client['createSubscriptionPath']('foo', {});
(0, chai_1.expect)(subscriptionPath).to.be.equal('ws://localhost:8081/api/v2/subscribe?modeluri=foo&format=json-v2');
});
it('test createSubscriptionPath with trailing slash', () => {
client = new model_server_client_v2_1.ModelServerClientV2();
client.initialize(`${baseUrl}/`);
const subscriptionPath = client['createSubscriptionPath']('foo', {});
(0, chai_1.expect)(subscriptionPath).to.be.equal('ws://localhost:8081/api/v2/subscribe?modeluri=foo&format=json-v2');
});
describe('test requests', () => {

@@ -46,8 +58,8 @@ it('getAll', done => {

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2 });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2 });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI });
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI });
done();

@@ -60,6 +72,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.undefined;
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_URIS);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.undefined;
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_URIS);
done();

@@ -75,8 +87,8 @@ });

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, elementid, modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_ELEMENT);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, elementid, modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_ELEMENT);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI, elementid, modeluri });
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI, elementid, modeluri });
done();

@@ -92,8 +104,8 @@ });

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, elementname, modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_ELEMENT);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, elementname, modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_ELEMENT);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI, elementname, modeluri });
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI, elementname, modeluri });
done();

@@ -107,6 +119,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('delete');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
(0, chai_1.expect)(request.config.method).to.be.equal('delete');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
done();

@@ -120,6 +132,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('post');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.CLOSE);
(0, chai_1.expect)(request.config.method).to.be.equal('post');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.CLOSE);
done();

@@ -136,9 +148,9 @@ });

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('post');
chai_1.expect(request.config.data).to.be.equal(JSON.stringify({ data }));
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
(0, chai_1.expect)(request.config.method).to.be.equal('post');
(0, chai_1.expect)(request.config.data).to.be.equal(JSON.stringify({ data }));
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI, modeluri });
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI, modeluri });
done();

@@ -155,9 +167,9 @@ });

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('put');
chai_1.expect(request.config.data).to.be.equal(JSON.stringify({ data }));
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
(0, chai_1.expect)(request.config.method).to.be.equal('put');
(0, chai_1.expect)(request.config.data).to.be.equal(JSON.stringify({ data }));
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI, modeluri });
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_XMI, modeluri });
done();

@@ -171,6 +183,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SAVE);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SAVE);
done();

@@ -183,6 +195,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.undefined;
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SAVE_ALL);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.undefined;
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SAVE_ALL);
done();

@@ -196,6 +208,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.VALIDATION);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.VALIDATION);
done();

@@ -209,6 +221,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.VALIDATION_CONSTRAINTS);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.VALIDATION_CONSTRAINTS);
done();

@@ -222,6 +234,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.TYPE_SCHEMA);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.TYPE_SCHEMA);
done();

@@ -235,6 +247,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ schemaname });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.UI_SCHEMA);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ schemaname });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.UI_SCHEMA);
done();

@@ -251,7 +263,7 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('put');
chai_1.expect(request.config.data).to.equal(JSON.stringify(configuration));
chai_1.expect(request.config.params).to.be.undefined;
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SERVER_CONFIGURE);
(0, chai_1.expect)(request.config.method).to.be.equal('put');
(0, chai_1.expect)(request.config.data).to.equal(JSON.stringify(configuration));
(0, chai_1.expect)(request.config.params).to.be.undefined;
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SERVER_CONFIGURE);
done();

@@ -264,6 +276,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.undefined;
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SERVER_PING);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.undefined;
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SERVER_PING);
done();

@@ -288,7 +300,7 @@ });

const request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('patch');
chai_1.expect(request.config.data).to.be.equal(JSON.stringify({ data: expected }));
chai_1.expect(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
(0, chai_1.expect)(request.config.method).to.be.equal('patch');
(0, chai_1.expect)(request.config.data).to.be.equal(JSON.stringify({ data: expected }));
(0, chai_1.expect)(request.config.params).to.include({ format: model_server_client_api_v2_1.FORMAT_JSON_V2, modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
done();

@@ -302,6 +314,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.UNDO);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.UNDO);
done();

@@ -315,6 +327,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.REDO);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.REDO);
done();

@@ -330,3 +342,3 @@ });

};
const onFulfilled = sinon_1.spy();
const onFulfilled = (0, sinon_1.spy)();
client.ping().then(onFulfilled);

@@ -339,3 +351,3 @@ moxios_1.default.wait(async () => {

});
assert_1.strictEqual(onFulfilled.getCall(0).args[0], true);
(0, assert_1.strictEqual)(onFulfilled.getCall(0).args[0], true);
done();

@@ -364,3 +376,3 @@ });

};
const onFulfilled = sinon_1.spy();
const onFulfilled = (0, sinon_1.spy)();
client.getAll().then(onFulfilled);

@@ -374,3 +386,3 @@ moxios_1.default.wait(async () => {

const result = onFulfilled.getCall(0).args[0];
chai_1.expect(result).to.deep.include.members([model2, model1]);
(0, chai_1.expect)(result).to.deep.include.members([model2, model1]);
done();

@@ -377,0 +389,0 @@ });

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

initialize(baseUrl) {
this._baseUrl = baseUrl;
this._baseUrl = baseUrl.endsWith('/') ? baseUrl.substring(0, baseUrl.length - 1) : baseUrl;
this.restClient = axios_1.default.create(this.getAxisConfig(baseUrl));

@@ -177,5 +177,5 @@ }

}
Object.entries(paramOptions).forEach(entry => queryParams.append(entry[0], entry[1]));
Object.entries(paramOptions).forEach(entry => queryParams.append(entry[0], entry[1].toString()));
queryParams.delete('errorWhenUnsuccessful');
return `${this._baseUrl}${model_server_paths_1.ModelServerPaths.SUBSCRIPTION}?${queryParams.toString()}`.replace(/^(http|https):\/\//i, 'ws://');
return `${this._baseUrl}/${model_server_paths_1.ModelServerPaths.SUBSCRIPTION}?${queryParams.toString()}`.replace(/^(http|https):\/\//i, 'ws://');
}

@@ -252,9 +252,9 @@ doSubscribe(listener, modelUri, path) {

if (guard) {
return { modelUri, content: type_util_1.asType(content, guard) };
return { modelUri, content: (0, type_util_1.asType)(content, guard) };
}
else if (toString) {
return { modelUri, content: type_util_1.asString(content) };
return { modelUri, content: (0, type_util_1.asString)(content) };
}
return { modelUri, content: type_util_1.asObject(content) };
return { modelUri, content: (0, type_util_1.asObject)(content) };
}
//# sourceMappingURL=model-server-client.js.map

@@ -37,4 +37,16 @@ "use strict";

const axios = client['restClient'];
chai_1.expect(axios.defaults.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(axios.defaults.baseURL).to.be.equal(baseUrl);
});
it('test createSubscriptionPath without trailing slash', () => {
client = new model_server_client_1.ModelServerClient();
client.initialize(baseUrl);
const subscriptionPath = client['createSubscriptionPath']('foo', {});
(0, chai_1.expect)(subscriptionPath).to.be.equal('ws://localhost:8081/api/v1/subscribe?modeluri=foo');
});
it('test createSubscriptionPath with trailing slash', () => {
client = new model_server_client_1.ModelServerClient();
client.initialize(`${baseUrl}/`);
const subscriptionPath = client['createSubscriptionPath']('foo', {});
(0, chai_1.expect)(subscriptionPath).to.be.equal('ws://localhost:8081/api/v1/subscribe?modeluri=foo');
});
describe('test requests', () => {

@@ -47,8 +59,8 @@ it('getAll', done => {

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ format: 'json' });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ format: 'json' });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: 'xml' });
(0, chai_1.expect)(request.config.params).to.include({ format: 'xml' });
done();

@@ -61,6 +73,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.undefined;
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_URIS);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.undefined;
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_URIS);
done();

@@ -76,8 +88,8 @@ });

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ format: 'json', elementid, modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_ELEMENT);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ format: 'json', elementid, modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_ELEMENT);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: 'xml', elementid, modeluri });
(0, chai_1.expect)(request.config.params).to.include({ format: 'xml', elementid, modeluri });
done();

@@ -93,8 +105,8 @@ });

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ format: 'json', elementname, modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_ELEMENT);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ format: 'json', elementname, modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_ELEMENT);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: 'xml', elementname, modeluri });
(0, chai_1.expect)(request.config.params).to.include({ format: 'xml', elementname, modeluri });
done();

@@ -108,6 +120,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('delete');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
(0, chai_1.expect)(request.config.method).to.be.equal('delete');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
done();

@@ -121,6 +133,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('post');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.CLOSE);
(0, chai_1.expect)(request.config.method).to.be.equal('post');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.CLOSE);
done();

@@ -137,9 +149,9 @@ });

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('post');
chai_1.expect(request.config.data).to.be.equal(JSON.stringify({ data }));
chai_1.expect(request.config.params).to.include({ format: 'json', modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
(0, chai_1.expect)(request.config.method).to.be.equal('post');
(0, chai_1.expect)(request.config.data).to.be.equal(JSON.stringify({ data }));
(0, chai_1.expect)(request.config.params).to.include({ format: 'json', modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: 'xml', modeluri });
(0, chai_1.expect)(request.config.params).to.include({ format: 'xml', modeluri });
done();

@@ -156,9 +168,9 @@ });

let request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('patch');
chai_1.expect(request.config.data).to.be.equal(JSON.stringify({ data }));
chai_1.expect(request.config.params).to.include({ format: 'json', modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
(0, chai_1.expect)(request.config.method).to.be.equal('patch');
(0, chai_1.expect)(request.config.data).to.be.equal(JSON.stringify({ data }));
(0, chai_1.expect)(request.config.params).to.include({ format: 'json', modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.MODEL_CRUD);
request = moxios_1.default.requests.at(1);
chai_1.expect(request.config.params).to.include({ format: 'xml', modeluri });
(0, chai_1.expect)(request.config.params).to.include({ format: 'xml', modeluri });
done();

@@ -172,6 +184,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SAVE);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SAVE);
done();

@@ -184,6 +196,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.undefined;
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SAVE_ALL);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.undefined;
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SAVE_ALL);
done();

@@ -197,6 +209,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.VALIDATION);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.VALIDATION);
done();

@@ -210,6 +222,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.VALIDATION_CONSTRAINTS);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.VALIDATION_CONSTRAINTS);
done();

@@ -223,6 +235,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.TYPE_SCHEMA);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.TYPE_SCHEMA);
done();

@@ -236,6 +248,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.include({ schemaname });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.UI_SCHEMA);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.include({ schemaname });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.UI_SCHEMA);
done();

@@ -252,7 +264,7 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('put');
chai_1.expect(request.config.data).to.equal(JSON.stringify(configuration));
chai_1.expect(request.config.params).to.be.undefined;
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SERVER_CONFIGURE);
(0, chai_1.expect)(request.config.method).to.be.equal('put');
(0, chai_1.expect)(request.config.data).to.equal(JSON.stringify(configuration));
(0, chai_1.expect)(request.config.params).to.be.undefined;
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SERVER_CONFIGURE);
done();

@@ -265,6 +277,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.undefined;
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SERVER_PING);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.undefined;
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.SERVER_PING);
done();

@@ -282,7 +294,7 @@ });

const request = moxios_1.default.requests.at(0);
chai_1.expect(request.config.method).to.be.equal('patch');
chai_1.expect(request.config.data).to.be.equal(JSON.stringify({ data: command }));
chai_1.expect(request.config.params).to.include({ format: 'json', modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.EDIT);
(0, chai_1.expect)(request.config.method).to.be.equal('patch');
(0, chai_1.expect)(request.config.data).to.be.equal(JSON.stringify({ data: command }));
(0, chai_1.expect)(request.config.params).to.include({ format: 'json', modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.EDIT);
done();

@@ -296,6 +308,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.UNDO);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.UNDO);
done();

@@ -309,6 +321,6 @@ });

const request = moxios_1.default.requests.mostRecent();
chai_1.expect(request.config.method).to.be.equal('get');
chai_1.expect(request.config.params).to.be.include({ modeluri });
chai_1.expect(request.config.baseURL).to.be.equal(baseUrl);
chai_1.expect(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.REDO);
(0, chai_1.expect)(request.config.method).to.be.equal('get');
(0, chai_1.expect)(request.config.params).to.be.include({ modeluri });
(0, chai_1.expect)(request.config.baseURL).to.be.equal(baseUrl);
(0, chai_1.expect)(request.config.url).to.be.equal(model_server_paths_1.ModelServerPaths.REDO);
done();

@@ -324,3 +336,3 @@ });

};
const onFulfilled = sinon_1.spy();
const onFulfilled = (0, sinon_1.spy)();
client.ping().then(onFulfilled);

@@ -333,3 +345,3 @@ moxios_1.default.wait(async () => {

});
assert_1.strictEqual(onFulfilled.getCall(0).args[0], true);
(0, assert_1.strictEqual)(onFulfilled.getCall(0).args[0], true);
done();

@@ -358,3 +370,3 @@ });

};
const onFulfilled = sinon_1.spy();
const onFulfilled = (0, sinon_1.spy)();
client.getAll().then(onFulfilled);

@@ -368,3 +380,3 @@ moxios_1.default.wait(async () => {

const result = onFulfilled.getCall(0).args[0];
chai_1.expect(result).to.deep.include.members([model2, model1]);
(0, chai_1.expect)(result).to.deep.include.members([model2, model1]);
done();

@@ -371,0 +383,0 @@ });

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

@@ -17,3 +21,3 @@ if (k2 === undefined) k2 = k;

var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);

@@ -98,3 +102,4 @@ return result;

*/
exports.IdentityMapper = m => m;
const IdentityMapper = m => m;
exports.IdentityMapper = IdentityMapper;
/**

@@ -190,10 +195,15 @@ * A collection of utility functions to map the `data` property of a {@link ModelServerMessage} to a specific type.

const patch = data ? data.patch : undefined;
if (patch && patch_utils_1.Operations.isPatch(patch)) {
const allPatches = data ? data.allPatches : undefined;
if (patch || allPatches) {
return {
success: isSuccess(message),
patch,
patchModel: (oldModel, copy) => {
const modelToPatch = copy ? fast_json_patch_1.deepClone(oldModel) : oldModel;
return jsonpatch.applyPatch(modelToPatch, patch).newDocument;
}
patchModel: (oldModel, copy, modelUri) => {
const modelToPatch = copy ? (0, fast_json_patch_1.deepClone)(oldModel) : oldModel;
const patchToApply = modelUri ? getPatch(allPatches, modelUri) : patch_utils_1.Operations.isPatch(patch) ? patch : undefined;
return patchToApply
? jsonpatch.applyPatch(modelToPatch, patchToApply).newDocument
: modelToPatch;
},
allPatches
};

@@ -210,3 +220,7 @@ }

MessageDataMapper.patchModel = patchModel;
function getPatch(patches, modelUri) {
var _a;
return (_a = patches.find(mp => mp.modelUri === modelUri)) === null || _a === void 0 ? void 0 : _a.patch;
}
})(MessageDataMapper = exports.MessageDataMapper || (exports.MessageDataMapper = {}));
//# sourceMappingURL=model-server-message.js.map

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

function is(object) {
return type_util_1.AnyObject.is(object) && type_util_1.isString(object, 'modelUri') && type_util_1.isString(object, 'type');
return type_util_1.AnyObject.is(object) && (0, type_util_1.isString)(object, 'modelUri') && (0, type_util_1.isString)(object, 'type');
}

@@ -12,0 +12,0 @@ ModelServerNotification.is = is;

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

static is(object) {
return type_util_1.AnyObject.is(object) && type_util_1.isString(object, 'eClass');
return type_util_1.AnyObject.is(object) && (0, type_util_1.isString)(object, 'eClass');
}

@@ -37,3 +37,3 @@ }

static is(object) {
return type_util_1.AnyObject.is(object) && type_util_1.isString(object, '$type');
return type_util_1.AnyObject.is(object) && (0, type_util_1.isString)(object, '$type');
}

@@ -47,3 +47,3 @@ }

static is(object) {
return type_util_1.AnyObject.is(object) && type_util_1.isString(object, '$type') && type_util_1.isString(object, '$id');
return type_util_1.AnyObject.is(object) && (0, type_util_1.isString)(object, '$type') && (0, type_util_1.isString)(object, '$id');
}

@@ -63,3 +63,3 @@ }

static is(object) {
return type_util_1.AnyObject.is(object) && type_util_1.isString(object, '$type') && type_util_1.isString(object, '$ref');
return type_util_1.AnyObject.is(object) && (0, type_util_1.isString)(object, '$type') && (0, type_util_1.isString)(object, '$ref');
}

@@ -66,0 +66,0 @@ }

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

this.feature = feature;
if (model_server_utils_1.isNumberArray(toDelete)) {
if ((0, model_server_utils_1.isNumberArray)(toDelete)) {
this.indices = toDelete;

@@ -91,3 +91,3 @@ }

}
if (model_server_utils_1.isModelServerObjectArray(toAdd)) {
if ((0, model_server_utils_1.isModelServerObjectArray)(toAdd)) {
const objectValues = toAdd.map((o, i) => new base_model_1.ModelServerReferenceDescription(o.eClass, `//@objectsToAdd.${i}`));

@@ -112,3 +112,3 @@ this.objectsToAdd = toAdd;

this.feature = feature;
if (model_server_utils_1.isModelServerReferenceDescriptionArray(changedValues)) {
if ((0, model_server_utils_1.isModelServerReferenceDescriptionArray)(changedValues)) {
this.objectValues = changedValues;

@@ -115,0 +115,0 @@ }

@@ -34,9 +34,9 @@ "use strict";

return (type_util_1.AnyObject.is(object) &&
type_util_1.isNumber(object, 'severity') &&
type_util_1.isString(object, 'message') &&
type_util_1.isString(object, 'source') &&
type_util_1.isNumber(object, 'code') &&
type_util_1.isArray(object, 'data') &&
type_util_1.isArray(object, 'children') &&
type_util_1.isString(object, 'id'));
(0, type_util_1.isNumber)(object, 'severity') &&
(0, type_util_1.isString)(object, 'message') &&
(0, type_util_1.isString)(object, 'source') &&
(0, type_util_1.isNumber)(object, 'code') &&
(0, type_util_1.isArray)(object, 'data') &&
(0, type_util_1.isArray)(object, 'children') &&
(0, type_util_1.isString)(object, 'id'));
}

@@ -43,0 +43,0 @@ Diagnostic.is = is;

@@ -18,9 +18,9 @@ "use strict";

const ok = diagnostic_1.Diagnostic.ok();
chai_1.expect(ok.severity).to.be.equal(diagnostic_1.OK);
chai_1.expect(ok.source).to.be.empty;
chai_1.expect(ok.code).to.be.equal(0);
chai_1.expect(ok.children).to.be.empty;
chai_1.expect(ok.data).to.be.empty;
chai_1.expect(ok.exception).to.be.undefined;
chai_1.expect(ok.message).to.be.equal('OK');
(0, chai_1.expect)(ok.severity).to.be.equal(diagnostic_1.OK);
(0, chai_1.expect)(ok.source).to.be.empty;
(0, chai_1.expect)(ok.code).to.be.equal(0);
(0, chai_1.expect)(ok.children).to.be.empty;
(0, chai_1.expect)(ok.data).to.be.empty;
(0, chai_1.expect)(ok.exception).to.be.undefined;
(0, chai_1.expect)(ok.message).to.be.equal('OK');
});

@@ -30,3 +30,3 @@ describe('merge', () => {

const merged = diagnostic_1.Diagnostic.merge();
chai_1.expect(merged).to.be.eql(diagnostic_1.Diagnostic.ok());
(0, chai_1.expect)(merged).to.be.eql(diagnostic_1.Diagnostic.ok());
});

@@ -36,3 +36,3 @@ it('one arg', () => {

const merged = diagnostic_1.Diagnostic.merge(only);
chai_1.expect(merged).to.be.eql(only);
(0, chai_1.expect)(merged).to.be.eql(only);
});

@@ -44,5 +44,5 @@ it('several args', () => {

const merged = diagnostic_1.Diagnostic.merge(warning, ok, error);
chai_1.expect(merged.severity).to.be.equal(diagnostic_1.ERROR);
chai_1.expect(merged.source).to.be.equal('c');
chai_1.expect(merged.children).to.be.eql([warning, error]);
(0, chai_1.expect)(merged.severity).to.be.equal(diagnostic_1.ERROR);
(0, chai_1.expect)(merged.source).to.be.equal('c');
(0, chai_1.expect)(merged.children).to.be.eql([warning, error]);
});

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

const worst = diagnostic_1.Diagnostic.worstOf([]);
chai_1.expect(worst).to.be.eql(diagnostic_1.Diagnostic.ok());
(0, chai_1.expect)(worst).to.be.eql(diagnostic_1.Diagnostic.ok());
});

@@ -59,3 +59,3 @@ it('one arg', () => {

const worst = diagnostic_1.Diagnostic.worstOf([only]);
chai_1.expect(worst).to.be.equal(only);
(0, chai_1.expect)(worst).to.be.equal(only);
});

@@ -67,3 +67,3 @@ it('several args', () => {

const worst = diagnostic_1.Diagnostic.worstOf([warning, ok, error]);
chai_1.expect(worst).to.be.equal(error);
(0, chai_1.expect)(worst).to.be.equal(error);
});

@@ -70,0 +70,0 @@ });

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

patchModel: (model, copy) => {
const modelToPatch = copy ? fast_json_patch_1.deepClone(model) : model;
return fast_json_patch_1.applyPatch(modelToPatch, patch).newDocument;
const modelToPatch = copy ? (0, fast_json_patch_1.deepClone)(model) : model;
return (0, fast_json_patch_1.applyPatch)(modelToPatch, patch).newDocument;
}

@@ -112,0 +112,0 @@ });

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

const object = { eClass: 'Foo', name: 'test', nested: [{ eClass: 'Nested', name: 'inner', tags, emptyArray, nada, emptyObj }] };
const encoded = type_util_1.encode('json')(object);
chai_1.expect(encoded).to.be.equal(encoded);
const encoded = (0, type_util_1.encode)('json')(object);
(0, chai_1.expect)(encoded).to.be.equal(encoded);
});

@@ -31,4 +31,4 @@ it('JSON v1 as JSON v2', () => {

const expected = { $type: 'Foo', name: 'test', nested: [{ $type: 'Nested', name: 'inner', tags, emptyArray, nada, emptyObj }] };
const encoded = type_util_1.encode('json-v2')(object);
chai_1.expect(encoded).to.be.eql(expected);
const encoded = (0, type_util_1.encode)('json-v2')(object);
(0, chai_1.expect)(encoded).to.be.eql(expected);
});

@@ -42,9 +42,9 @@ it('JSON v2 as JSON v1', () => {

};
const encoded = type_util_1.encode('json')(object);
chai_1.expect(encoded).to.be.eql(expected);
const encoded = (0, type_util_1.encode)('json')(object);
(0, chai_1.expect)(encoded).to.be.eql(expected);
});
it('JSON v2 as JSON v2', () => {
const object = { $type: 'Foo', name: 'test', nested: [{ $type: 'Nested', name: 'inner', tags, emptyArray, nada, emptyObj }] };
const encoded = type_util_1.encode('json-v2')(object);
chai_1.expect(encoded).to.be.equal(encoded);
const encoded = (0, type_util_1.encode)('json-v2')(object);
(0, chai_1.expect)(encoded).to.be.equal(encoded);
});

@@ -64,4 +64,4 @@ });

});
const encoded = type_util_1.encode('json')(object);
chai_1.expect(encoded).to.be.equal(encoded);
const encoded = (0, type_util_1.encode)('json')(object);
(0, chai_1.expect)(encoded).to.be.equal(encoded);
});

@@ -75,5 +75,5 @@ it('JSON v1 as JSON v2', () => {

const expected = { $type: 'Foo', name: 'test', nested: { $type: 'Nested', name: 'inner', tags, emptyArray, nada, emptyObj } };
const encoded = type_util_1.encode('json-v2')(object);
chai_1.expect(encoded).to.be.a('string');
chai_1.expect(JSON.parse(encoded)).to.be.eql(expected);
const encoded = (0, type_util_1.encode)('json-v2')(object);
(0, chai_1.expect)(encoded).to.be.a('string');
(0, chai_1.expect)(JSON.parse(encoded)).to.be.eql(expected);
});

@@ -87,5 +87,5 @@ it('JSON v2 as JSON v1', () => {

const expected = { eClass: 'Foo', name: 'test', nested: { eClass: 'Nested', name: 'inner', tags, emptyArray, nada, emptyObj } };
const encoded = type_util_1.encode('json')(object);
chai_1.expect(encoded).to.be.a('string');
chai_1.expect(JSON.parse(encoded)).to.be.eql(expected);
const encoded = (0, type_util_1.encode)('json')(object);
(0, chai_1.expect)(encoded).to.be.a('string');
(0, chai_1.expect)(JSON.parse(encoded)).to.be.eql(expected);
});

@@ -98,4 +98,4 @@ it('JSON v2 as JSON v2', () => {

});
const encoded = type_util_1.encode('json-v2')(object);
chai_1.expect(encoded).to.be.equal(encoded);
const encoded = (0, type_util_1.encode)('json-v2')(object);
(0, chai_1.expect)(encoded).to.be.equal(encoded);
});

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

@@ -17,3 +17,3 @@ {

"bugs": "https://github.com/eclipse-emfcloud/emfcloud-modelserver-theia/issues",
"version": "0.8.0-next.fd477972",
"version": "0.8.0-theia-cr01",
"files": [

@@ -51,7 +51,8 @@ "lib",

"devDependencies": {
"@types/moxios": "^0.4.14",
"@types/moxios": "0.4.14",
"@types/ws": "8.2.2",
"ignore-styles": "^5.0.1",
"moxios": "^0.4.0",
"typescript": "^3.9.2"
"rimraf": "^3.0.2",
"typescript": "^4.6.3"
},

@@ -63,7 +64,7 @@ "scripts": {

"lint": "eslint --ext .ts,.tsx ./src",
"lint:fix": "eslint --fix --ext .ts,.tsx ./src",
"watch": "tsc -w",
"test": "mocha --config ../../configs/.mocharc.json",
"test:ci": "mocha --config ../../configs/.mocharc.ci.json"
}
},
"gitHead": "c64d6b75e0cf501c0032e2ca714b56418743bf17"
}

@@ -57,2 +57,12 @@ /********************************************************************************

/**
* A union type that represents all Patches or Commands supported by the model server:
* - Operation
* - Operation[] (Json Patch)
* - ModelPatch
* - ModelPatch[]
* - ModelServerCommand
*/
export type PatchOrCommand = Operation | Operation[] | ModelPatch | ModelPatch[] | ModelServerCommand;
/**
* Basic client API to interact with a model server that conforms to the Modelserver API Version 2.

@@ -117,4 +127,3 @@ */

edit(modeluri: string, patch: Operation | Operation[], format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: string, command: ModelServerCommand, format?: Format): Promise<ModelUpdateResult>;
edit(modeluri: string, patchOrCommand: PatchOrCommand, format?: Format): Promise<ModelUpdateResult>;

@@ -137,2 +146,17 @@ undo(modeluri: string): Promise<ModelUpdateResult>;

/**
* A patch affecting a specific model.
*/
export interface ModelPatch {
/**
* The uri of the patched model.
*/
modelUri: string;
/**
* The patch describing the changes applied to the model.
*/
patch: Operation[];
}
/**
* Result sent to client after requesting a model update.

@@ -155,5 +179,8 @@ */

* the original model unchanged.
* @param modelUri the uri of the model to patch. This can be used when the model is split in multiple
* resources, to identify the patch to apply. The modelUri should correspond to the oldModel object.
* It can be omitted when patching the main model (or in single-model cases).
* @return the patched model.
*/
patchModel?(oldModel: ModelServerElement, copy?: boolean): ModelServerElement;
patchModel?(oldModel: ModelServerElement, copy?: boolean, modelUri?: string): ModelServerElement;

@@ -165,2 +192,10 @@ /**

patch?: Operation[];
/**
* The list of Json Patches describing the changes that were applied to the models. Only present if
* the edit request was successful.
*
* The list contains one entry per modified model. Unmodified models will not contain any entry.
*/
allPatches?: ModelPatch[];
}

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

const testUndoRedo: (modeluri: string, originalModel: any, patchedModel: any) => void = async (
const testUndoRedo: (modeluri: string, originalModel: any, patchedModel: any) => Promise<void> = async (
modeluri,

@@ -359,3 +359,71 @@ originalModel,

});
it('check all patch replies', async () => {
const modeluri = 'SuperBrewer3000.coffee';
const newName = 'Super Brewer 6000';
const machine = await client.get(modeluri, ModelServerObjectV2.is);
const patchedMachine = deepClone(machine);
// Directly change the model
patchedMachine.name = newName;
patchedMachine.children[1].processor.clockSpeed = 6;
// Generate patch by diffing the original model and the patched one
const patch = jsonpatch.compare(machine, patchedMachine);
const result = await client.edit(modeluri, patch);
expect(result.success).to.be.true;
expect(result.patch).to.not.be.undefined;
expect(result.allPatches).to.not.be.undefined;
expect(result.allPatches).to.be.an('array').of.length(1);
// Patch the main resource
const updatedMachineMainPatch = result.patchModel!(machine, true);
expect(patchedMachine).to.deep.equal(updatedMachineMainPatch);
// Patch the first resource
const updatedMachineFirstPatch = result.patchModel!(machine, true, result.allPatches![0].modelUri);
expect(patchedMachine).to.deep.equal(updatedMachineFirstPatch);
await testUndoRedo(modeluri, machine, updatedMachineFirstPatch);
});
it('test model patches', async () => {
const modeluri = 'SuperBrewer3000.coffee';
const newName = 'Super Brewer 6000';
const machine = await client.get(modeluri, ModelServerObjectV2.is);
const patchedMachine = deepClone(machine);
// Directly change the model
patchedMachine.name = newName;
patchedMachine.children[1].processor.clockSpeed = 6;
// Generate patch by diffing the original model and the patched one
const patch = jsonpatch.compare(machine, patchedMachine);
const modelPatch = {
modelUri: modeluri,
patch
};
const result = await client.edit(modeluri, modelPatch);
expect(result.success).to.be.true;
expect(result.patch).to.not.be.undefined;
expect(result.allPatches).to.not.be.undefined;
expect(result.allPatches).to.be.an('array').of.length(1);
// Patch the main resource
const updatedMachineMainPatch = result.patchModel!(machine, true);
expect(patchedMachine).to.deep.equal(updatedMachineMainPatch);
// Patch the first resource
const updatedMachineFirstPatch = result.patchModel!(machine, true, result.allPatches![0].modelUri);
expect(patchedMachine).to.deep.equal(updatedMachineFirstPatch);
await testUndoRedo(modeluri, machine, updatedMachineFirstPatch);
});
});
});

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

});
it('test createSubscriptionPath without trailing slash', () => {
client = new ModelServerClientV2();
client.initialize(baseUrl);
const subscriptionPath = client['createSubscriptionPath']('foo', {});
expect(subscriptionPath).to.be.equal('ws://localhost:8081/api/v2/subscribe?modeluri=foo&format=json-v2');
});
it('test createSubscriptionPath with trailing slash', () => {
client = new ModelServerClientV2();
client.initialize(`${baseUrl}/`);
const subscriptionPath = client['createSubscriptionPath']('foo', {});
expect(subscriptionPath).to.be.equal('ws://localhost:8081/api/v2/subscribe?modeluri=foo&format=json-v2');
});

@@ -43,0 +55,0 @@ describe('test requests', () => {

@@ -12,3 +12,3 @@ /********************************************************************************

import axios, { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { Operation } from 'fast-json-patch';
import { deepClone } from 'fast-json-patch';
import WebSocket from 'isomorphic-ws';

@@ -19,3 +19,3 @@

import { ModelServerError, ServerConfiguration, SubscriptionOptions } from './model-server-client-api-v1';
import { Format, FORMAT_JSON_V2, ModelServerClientApiV2, ModelUpdateResult } from './model-server-client-api-v2';
import { Format, FORMAT_JSON_V2, ModelServerClientApiV2, ModelUpdateResult, PatchOrCommand } from './model-server-client-api-v2';
import { MessageDataMapper, Model, ModelServerMessage } from './model-server-message';

@@ -36,3 +36,3 @@ import { ModelServerPaths } from './model-server-paths';

initialize(baseUrl: string, defaultFormat: Format = FORMAT_JSON_V2): void | Promise<void> {
this._baseUrl = baseUrl;
this._baseUrl = baseUrl.endsWith('/') ? baseUrl.substring(0, baseUrl.length - 1) : baseUrl;
this.defaultFormat = defaultFormat;

@@ -218,6 +218,3 @@ this.restClient = axios.create(this.getAxiosConfig(baseUrl));

edit(modeluri: string, patch: Operation): Promise<ModelUpdateResult>;
edit(modeluri: string, patch: Operation[]): Promise<ModelUpdateResult>;
edit(modeluri: string, command: ModelServerCommand): Promise<ModelUpdateResult>;
edit(modeluri: string, patchOrCommand: Operation | Operation[] | ModelServerCommand): Promise<ModelUpdateResult> {
edit(modeluri: string, patchOrCommand: PatchOrCommand, format = this.defaultFormat): Promise<ModelUpdateResult> {
let patchMessage: any;

@@ -230,2 +227,3 @@ if (patchOrCommand instanceof ModelServerCommand) {

} else {
// Operation[] and ModelPatch[] are treated in the same way; we don't need to distinguish both cases
const fullPatch = Array.isArray(patchOrCommand) ? patchOrCommand : [patchOrCommand];

@@ -236,6 +234,14 @@ patchMessage = {

};
if (fullPatch.length === 0) {
// No-op
return Promise.resolve({
success: true,
patchModel: (oldModel, copy, _modelUri) => (copy ? deepClone(oldModel) : oldModel),
patch: []
});
}
}
return this.process(
this.restClient.patch(ModelServerPaths.MODEL_CRUD, encodeRequestBody(this.defaultFormat)(patchMessage), {
params: { modeluri, format: this.defaultFormat }
this.restClient.patch(ModelServerPaths.MODEL_CRUD, encodeRequestBody(format)(patchMessage), {
params: { modeluri, format: format }
}),

@@ -266,3 +272,3 @@ MessageDataMapper.patchModel

if (options.errorWhenUnsuccessful) {
throw new Error('errorMsg');
throw new Error(errorMsg);
}

@@ -269,0 +275,0 @@ }

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

it('test createSubscriptionPath without trailing slash', () => {
client = new ModelServerClient();
client.initialize(baseUrl);
const subscriptionPath = client['createSubscriptionPath']('foo', {});
expect(subscriptionPath).to.be.equal('ws://localhost:8081/api/v1/subscribe?modeluri=foo');
});
it('test createSubscriptionPath with trailing slash', () => {
client = new ModelServerClient();
client.initialize(`${baseUrl}/`);
const subscriptionPath = client['createSubscriptionPath']('foo', {});
expect(subscriptionPath).to.be.equal('ws://localhost:8081/api/v1/subscribe?modeluri=foo');
});
describe('test requests', () => {

@@ -43,0 +56,0 @@ it('getAll', done => {

@@ -32,3 +32,3 @@ /********************************************************************************

initialize(baseUrl: string): void | Promise<void> {
this._baseUrl = baseUrl;
this._baseUrl = baseUrl.endsWith('/') ? baseUrl.substring(0, baseUrl.length - 1) : baseUrl;
this.restClient = axios.create(this.getAxisConfig(baseUrl));

@@ -220,5 +220,5 @@ }

}
Object.entries(paramOptions).forEach(entry => queryParams.append(entry[0], entry[1]));
Object.entries(paramOptions).forEach(entry => queryParams.append(entry[0], entry[1].toString()));
queryParams.delete('errorWhenUnsuccessful');
return `${this._baseUrl}${ModelServerPaths.SUBSCRIPTION}?${queryParams.toString()}`.replace(/^(http|https):\/\//i, 'ws://');
return `${this._baseUrl}/${ModelServerPaths.SUBSCRIPTION}?${queryParams.toString()}`.replace(/^(http|https):\/\//i, 'ws://');
}

@@ -225,0 +225,0 @@

@@ -12,6 +12,6 @@ /********************************************************************************

import * as jsonpatch from 'fast-json-patch';
import { deepClone } from 'fast-json-patch';
import { deepClone, Operation } from 'fast-json-patch';
import { ModelServerElement } from './model/base-model';
import { ModelUpdateResult } from './model-server-client-api-v2';
import { ModelPatch, ModelUpdateResult } from './model-server-client-api-v2';
import { Operations } from './utils/patch-utils';

@@ -203,10 +203,15 @@ import * as Type from './utils/type-util';

const patch = data ? data.patch : undefined;
if (patch && Operations.isPatch(patch)) {
const allPatches = data ? data.allPatches : undefined;
if (patch || allPatches) {
return {
success: isSuccess(message),
patch,
patchModel: (oldModel, copy) => {
patchModel: (oldModel, copy, modelUri) => {
const modelToPatch = copy ? deepClone(oldModel) : oldModel;
return jsonpatch.applyPatch(modelToPatch, patch).newDocument as ModelServerElement;
}
const patchToApply = modelUri ? getPatch(allPatches, modelUri) : Operations.isPatch(patch) ? patch : undefined;
return patchToApply
? (jsonpatch.applyPatch(modelToPatch, patchToApply).newDocument as ModelServerElement)
: modelToPatch;
},
allPatches
};

@@ -220,2 +225,6 @@ } else {

}
function getPatch(patches: ModelPatch[], modelUri: string): Operation[] | undefined {
return patches.find(mp => mp.modelUri === modelUri)?.patch;
}
}

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