@hms-networks/kolibri-js-core
Version:
Kolibri Core library containing common kolibri models and utils
100 lines • 4.29 kB
JavaScript
/*
* Copyright 2021 HMS Industrial Networks AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http: //www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { MapperUtils } from './mapper_utils';
var RpcV20Mapper = /** @class */ (function () {
function RpcV20Mapper() {
}
RpcV20Mapper.prototype.map = function (rpc) {
if (rpc.hasOwnProperty('method')) {
return this.mapRequest(rpc);
}
if (rpc.hasOwnProperty('result')) {
return this.mapResult(rpc);
}
return rpc;
};
RpcV20Mapper.prototype.mapRequest = function (rpc) {
if (rpc.method === 'kolibri.write') {
return this.mapKolibriWrite(rpc);
}
if (rpc.method === 'kolibri.user.notify') {
return this.mapKolibriUserNotify(rpc);
}
return rpc;
};
RpcV20Mapper.prototype.mapKolibriWrite = function (rpc) {
var nodes = rpc.params.nodes;
nodes.forEach(function (node) {
node.timestampBroker = MapperUtils.mapTimestampFromMilliToMicro(node.timestampBroker);
});
return rpc;
};
RpcV20Mapper.prototype.mapKolibriUserNotify = function (rpc) {
var params = rpc.params;
params.forEach(function (param) { param.timestamp = MapperUtils.mapTimestampFromMilliToMicro(param.timestamp); });
return rpc;
};
RpcV20Mapper.prototype.mapResult = function (rpc) {
if (rpc.result.hasOwnProperty('updateUrl')) {
delete rpc.result.updateUrl;
}
if (rpc.result.hasOwnProperty('timestampBroker')) {
rpc.result.timestampBroker = MapperUtils.mapTimestampFromMilliToMicro(rpc.result.timestampBroker);
}
if (rpc.result.hasOwnProperty('timestampLogin')) {
rpc.result.timestampLogin = MapperUtils.mapTimestampFromMilliToMicro(rpc.result.timestampLogin);
}
if (rpc.result.hasOwnProperty('timestampLogout')) {
rpc.result.timestampLogout = MapperUtils.mapTimestampFromMilliToMicro(rpc.result.timestampLogout);
}
if (rpc.result.hasOwnProperty('lastLogin')) {
rpc.result.lastLogin = MapperUtils.mapTimestampFromMilliToMicro(rpc.result.lastLogin);
}
if (rpc.result.hasOwnProperty('lastCommunication')) {
rpc.result.lastCommunication = MapperUtils.mapTimestampFromMilliToMicro(rpc.result.lastCommunication);
}
if (rpc.result.hasOwnProperty('expiration')) {
if (rpc.result.expiration > 0) {
rpc.result.expiration = MapperUtils.mapTimestampFromMilliToMicro(rpc.result.expiration);
}
}
if (Array.isArray(rpc.result)) {
rpc.result.forEach(function (r) {
if (r.hasOwnProperty('timestampBroker')) {
r.timestampBroker = MapperUtils.mapTimestampFromMilliToMicro(r.timestampBroker);
}
if (r.hasOwnProperty('timestampLogin')) {
r.timestampLogin = MapperUtils.mapTimestampFromMilliToMicro(r.timestampLogin);
}
if (r.hasOwnProperty('timestampLogout')) {
r.timestampLogout = MapperUtils.mapTimestampFromMilliToMicro(r.timestampLogout);
}
if (r.hasOwnProperty('lastCommunication')) {
r.lastCommunication = MapperUtils.mapTimestampFromMilliToMicro(r.lastCommunication);
}
if (r.hasOwnProperty('expiration')) {
if (r.expiration > 0) {
r.expiration = MapperUtils.mapTimestampFromMilliToMicro(r.expiration);
}
}
});
}
return rpc;
};
return RpcV20Mapper;
}());
export { RpcV20Mapper };
//# sourceMappingURL=rpc_v20_mapper.js.map