UNPKG

@hms-networks/kolibri-js-core

Version:

Kolibri Core library containing common kolibri models and utils

88 lines 3.68 kB
/* * 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 RpcV10Mapper = /** @class */ (function () { function RpcV10Mapper() { } RpcV10Mapper.prototype.map = function (rpc) { if (rpc.hasOwnProperty('method')) { return this.mapRequest(rpc); } if (rpc.hasOwnProperty('result')) { return this.mapResult(rpc); } return rpc; }; RpcV10Mapper.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; }; RpcV10Mapper.prototype.mapKolibriWrite = function (rpc) { var nodes = rpc.params.nodes; nodes.forEach(function (node) { node.timestamp = MapperUtils.mapTimestampFromMicroToSec(node.timestamp); node.timestampBroker = MapperUtils.mapTimestampFromMilliToSec(node.timestampBroker); }); return rpc; }; RpcV10Mapper.prototype.mapKolibriUserNotify = function (rpc) { var params = rpc.params; params.forEach(function (param) { param.timestamp = MapperUtils.mapTimestampFromMilliToSec(param.timestamp); }); return rpc; }; RpcV10Mapper.prototype.mapResult = function (rpc) { if (rpc.result.hasOwnProperty('timestamp')) { rpc.result.timestamp = MapperUtils.mapTimestampFromMicroToSec(rpc.result.timestamp); } if (rpc.result.hasOwnProperty('timestampBroker')) { rpc.result.timestampBroker = MapperUtils.mapTimestampFromMilliToSec(rpc.result.timestampBroker); } if (rpc.result.hasOwnProperty('lastLogin')) { rpc.result.lastLogin = MapperUtils.mapTimestampFromMilliToSec(rpc.result.lastLogin); } if (rpc.result.hasOwnProperty('lastCommunication')) { rpc.result.lastCommunication = MapperUtils.mapTimestampFromMilliToSec(rpc.result.lastCommunication); } if (Array.isArray(rpc.result)) { this.mapResults(rpc.result); } return rpc; }; RpcV10Mapper.prototype.mapResults = function (results) { results.forEach(function (result) { if (result.hasOwnProperty('timestamp')) { result.timestamp = MapperUtils.mapTimestampFromMicroToSec(result.timestamp); } if (result.hasOwnProperty('timestampBroker')) { result.timestampBroker = MapperUtils.mapTimestampFromMilliToSec(result.timestampBroker); } if (result.hasOwnProperty('timestampLogin')) { result.timestampLogin = MapperUtils.mapTimestampFromMilliToSec(result.timestampLogin); } if (result.hasOwnProperty('timestampLogout')) { result.timestampLogout = MapperUtils.mapTimestampFromMilliToSec(result.timestampLogout); } }); }; return RpcV10Mapper; }()); export { RpcV10Mapper }; //# sourceMappingURL=rpc_v10_mapper.js.map