UNPKG

@hms-networks/kolibri-js-core

Version:

Kolibri Core library containing common kolibri models and utils

89 lines 3.39 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.OpcodeCompatMapper = void 0; const constant_1 = require("../common/constant"); const version_service_1 = require("../util/version_service"); const mapper_utils_1 = require("./mapper_utils"); class OpcodeCompatMapper { constructor(kolibriVersion) { this.kolibriVersion = kolibriVersion; } map(kpo, direction) { if (version_service_1.VersionService.isVersionInRange(this.kolibriVersion, '1.0')) { return this.mapKolibriKpo(kpo, direction); } if (version_service_1.VersionService.isVersionInRange(this.kolibriVersion, '>=2.0')) { return this.mapKolibriV20Kpo(kpo, direction); } } mapKolibriKpo(kpo, direction) { if (direction === constant_1.constants.INCOMING_DIRECTION) { this.mapIncomingKolibriKpo(kpo); } if (direction === constant_1.constants.OUTGOING_DIRECTION) { this.mapOutgoingKolibriKpo(kpo); } return kpo; } mapKolibriV20Kpo(kpo, direction) { if (direction === constant_1.constants.OUTGOING_DIRECTION) { this.mapOutgoingKolibriV20Kpo(kpo); } return kpo; } mapIncomingKolibriKpo(kpo) { if (kpo.hasOwnProperty('nodes')) { if (Array.isArray(kpo.nodes)) { kpo.nodes .forEach((node) => { if (node.hasOwnProperty('timestamp')) { node.timestamp = mapper_utils_1.MapperUtils .mapTimestampFromSecToMicro(node.timestamp); } }); } } if (kpo.hasOwnProperty('timestamp')) { kpo.timestamp = mapper_utils_1.MapperUtils .mapTimestampFromSecToMicro(kpo.timestamp); } } mapOutgoingKolibriKpo(kpo) { if (kpo.hasOwnProperty('nodes')) { if (Array.isArray(kpo.nodes)) { kpo.nodes .forEach((node) => { if (node.hasOwnProperty('timestamp')) { node.timestamp = mapper_utils_1.MapperUtils .mapTimestampFromMicroToSec(node.timestamp); } }); } } if (kpo.hasOwnProperty('timestamp')) { kpo.timestamp = mapper_utils_1.MapperUtils.mapTimestampFromMilliToSec(kpo.timestamp); } } mapOutgoingKolibriV20Kpo(kpo) { if (kpo.hasOwnProperty('timestamp')) { kpo.timestamp = mapper_utils_1.MapperUtils.mapTimestampFromMilliToMicro(kpo.timestamp); } } } exports.OpcodeCompatMapper = OpcodeCompatMapper; //# sourceMappingURL=opcode_compat_mapper.js.map