UNPKG

@hms-networks/kolibri-js-core

Version:

Kolibri Core library containing common kolibri models and utils

85 lines 3.08 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 { constants } from '../common/constant'; import { VersionService } from '../util/version_service'; import { MapperUtils } from './mapper_utils'; export class OpcodeCompatMapper { constructor(kolibriVersion) { this.kolibriVersion = kolibriVersion; } map(kpo, direction) { if (VersionService.isVersionInRange(this.kolibriVersion, '1.0')) { return this.mapKolibriKpo(kpo, direction); } if (VersionService.isVersionInRange(this.kolibriVersion, '>=2.0')) { return this.mapKolibriV20Kpo(kpo, direction); } } mapKolibriKpo(kpo, direction) { if (direction === constants.INCOMING_DIRECTION) { this.mapIncomingKolibriKpo(kpo); } if (direction === constants.OUTGOING_DIRECTION) { this.mapOutgoingKolibriKpo(kpo); } return kpo; } mapKolibriV20Kpo(kpo, direction) { if (direction === 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 = MapperUtils .mapTimestampFromSecToMicro(node.timestamp); } }); } } if (kpo.hasOwnProperty('timestamp')) { kpo.timestamp = 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 = MapperUtils .mapTimestampFromMicroToSec(node.timestamp); } }); } } if (kpo.hasOwnProperty('timestamp')) { kpo.timestamp = MapperUtils.mapTimestampFromMilliToSec(kpo.timestamp); } } mapOutgoingKolibriV20Kpo(kpo) { if (kpo.hasOwnProperty('timestamp')) { kpo.timestamp = MapperUtils.mapTimestampFromMilliToMicro(kpo.timestamp); } } } //# sourceMappingURL=opcode_compat_mapper.js.map