UNPKG

@hms-networks/kolibri-js-core

Version:

Kolibri Core library containing common kolibri models and utils

45 lines 1.81 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.RpcCompatMapper = void 0; const version_service_1 = require("../util/version_service"); const rpc_v10_mapper_1 = require("./rpc_v10_mapper"); const rpc_v20_mapper_1 = require("./rpc_v20_mapper"); /** * Provide compatibility between different kolibri protocol versions * e.g. convert data that is in format of v2 to data format for v1 */ class RpcCompatMapper { constructor(kolibriVersion) { this.kolibriVersion = kolibriVersion; this.rpcV10Mapper = new rpc_v10_mapper_1.RpcV10Mapper(); this.rpcV20Mapper = new rpc_v20_mapper_1.RpcV20Mapper(); } map(rpc) { if (version_service_1.VersionService.isVersionInRange(this.kolibriVersion, '1.0')) { return this.rpcV10Mapper.map(rpc); } else if (version_service_1.VersionService.isVersionInRange(this.kolibriVersion, '>=2.0')) { return this.rpcV20Mapper.map(rpc); } else { throw new Error('Should never get here. All versions should be covered by the checks above'); } } } exports.RpcCompatMapper = RpcCompatMapper; //# sourceMappingURL=rpc_compat_mapper.js.map