@esri/solution-common
Version:
Provides general helper functions for @esri/solution.js.
75 lines • 4.04 kB
JavaScript
;
/** @license
* Copyright 2018 Esri
*
* 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.migrateSchema = exports.CURRENT_SCHEMA_VERSION = void 0;
const is_legacy_solution_1 = require("./migrations/is-legacy-solution");
const apply_schema_1 = require("./migrations/apply-schema");
const upgrade_two_dot_zero_1 = require("./migrations/upgrade-two-dot-zero");
const upgrade_two_dot_one_1 = require("./migrations/upgrade-two-dot-one");
const upgrade_two_dot_two_1 = require("./migrations/upgrade-two-dot-two");
const upgrade_two_dot_three_1 = require("./migrations/upgrade-two-dot-three");
const upgrade_two_dot_four_1 = require("./migrations/upgrade-two-dot-four");
const upgrade_two_dot_five_1 = require("./migrations/upgrade-two-dot-five");
const upgrade_two_dot_six_1 = require("./migrations/upgrade-two-dot-six");
const upgrade_two_dot_seven_1 = require("./migrations/upgrade-two-dot-seven");
const upgrade_three_dot_zero_1 = require("./migrations/upgrade-three-dot-zero");
const hub_common_1 = require("@esri/hub-common");
// Starting at 3.0 because Hub has been versioning Solution items up to 2.x
exports.CURRENT_SCHEMA_VERSION = 3.0;
/**
* Apply schema migrations to a Solution item
* This system allows the schema of the Solution item to change over time
* while abstracting those changes into a single set of functional transforms
*
* @param model ISolutionItem
*/
function migrateSchema(model) {
// ensure properties
if (!(0, hub_common_1.getProp)(model, "item.properties")) {
model.item.properties = {};
}
const modelVersion = (0, hub_common_1.getProp)(model, "item.properties.schemaVersion");
// if it's already on the current version, return it
if (modelVersion === exports.CURRENT_SCHEMA_VERSION) {
return Promise.resolve(model);
}
else {
// check if this is a legacy solution created by Hub
const isLegacy = (0, is_legacy_solution_1._isLegacySolution)(model);
const schemaUpgrades = [];
// if this is a Solution.js "native" item, it is already at 3.0
if (!modelVersion && !isLegacy) {
// apply the 3.0+ transforms
// TEMP to allow merge to develop w/o breaking things
schemaUpgrades.push(upgrade_three_dot_zero_1._upgradeThreeDotZero);
// schemaUpgrades.push(_upgradeThreeDotZero, _upgradeThreeDotOne);
}
else {
// Hub created a set of Solution items that are not 100% compatible
// with the Solution.js deployer.
schemaUpgrades.push(apply_schema_1._applySchema, upgrade_two_dot_zero_1._upgradeTwoDotZero, upgrade_two_dot_one_1._upgradeTwoDotOne, upgrade_two_dot_two_1._upgradeTwoDotTwo, upgrade_two_dot_three_1._upgradeTwoDotThree, upgrade_two_dot_four_1._upgradeTwoDotFour, upgrade_two_dot_five_1._upgradeTwoDotFive, upgrade_two_dot_six_1._upgradeTwoDotSix, upgrade_two_dot_seven_1._upgradeTwoDotSeven);
// Apply the 3.x upgrades
schemaUpgrades.push(upgrade_three_dot_zero_1._upgradeThreeDotZero);
}
// Run any migrations serially. Since we start with a promise,
// individual migrations are free to return either ISolutionItem
// or Promise<ISolutionItem>
return schemaUpgrades.reduce((promise, upgradeFn) => promise.then((updatedModel) => upgradeFn(updatedModel)), Promise.resolve(model));
}
}
exports.migrateSchema = migrateSchema;
//# sourceMappingURL=migrator.js.map