UNPKG

@hms-networks/kolibri-js-core

Version:

Kolibri Core library containing common kolibri models and utils

100 lines 4.32 kB
"use strict"; /* * 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. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.RpcV20Mapper = void 0; const mapper_utils_1 = require("./mapper_utils"); class RpcV20Mapper { map(rpc) { if (rpc.hasOwnProperty('method')) { return this.mapRequest(rpc); } if (rpc.hasOwnProperty('result')) { return this.mapResult(rpc); } return rpc; } mapRequest(rpc) { if (rpc.method === 'kolibri.write') { return this.mapKolibriWrite(rpc); } if (rpc.method === 'kolibri.user.notify') { return this.mapKolibriUserNotify(rpc); } return rpc; } mapKolibriWrite(rpc) { const nodes = rpc.params.nodes; nodes.forEach((node) => { node.timestampBroker = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(node.timestampBroker); }); return rpc; } mapKolibriUserNotify(rpc) { const params = rpc.params; params.forEach((param) => { param.timestamp = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(param.timestamp); }); return rpc; } mapResult(rpc) { if (rpc.result.hasOwnProperty('updateUrl')) { delete rpc.result.updateUrl; } if (rpc.result.hasOwnProperty('timestampBroker')) { rpc.result.timestampBroker = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(rpc.result.timestampBroker); } if (rpc.result.hasOwnProperty('timestampLogin')) { rpc.result.timestampLogin = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(rpc.result.timestampLogin); } if (rpc.result.hasOwnProperty('timestampLogout')) { rpc.result.timestampLogout = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(rpc.result.timestampLogout); } if (rpc.result.hasOwnProperty('lastLogin')) { rpc.result.lastLogin = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(rpc.result.lastLogin); } if (rpc.result.hasOwnProperty('lastCommunication')) { rpc.result.lastCommunication = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(rpc.result.lastCommunication); } if (rpc.result.hasOwnProperty('expiration')) { if (rpc.result.expiration > 0) { rpc.result.expiration = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(rpc.result.expiration); } } if (Array.isArray(rpc.result)) { rpc.result.forEach((r) => { if (r.hasOwnProperty('timestampBroker')) { r.timestampBroker = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(r.timestampBroker); } if (r.hasOwnProperty('timestampLogin')) { r.timestampLogin = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(r.timestampLogin); } if (r.hasOwnProperty('timestampLogout')) { r.timestampLogout = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(r.timestampLogout); } if (r.hasOwnProperty('lastCommunication')) { r.lastCommunication = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(r.lastCommunication); } if (r.hasOwnProperty('expiration')) { if (r.expiration > 0) { r.expiration = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(r.expiration); } } }); } return rpc; } } exports.RpcV20Mapper = RpcV20Mapper; //# sourceMappingURL=rpc_v20_mapper.js.map