UNPKG

serverless-prune-versions

Version:

Serverless plugin to delete old versions of deployed functions from AWS

49 lines 5.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Settings = void 0; const assert_1 = require("assert"); class Settings { constructor(config, rawOptions) { const settings = this.getSettings(config, rawOptions); this.validate(settings); Object.assign(this, settings); } getSettings(config, rawOptions) { const options = this.cleanRawOptions(rawOptions); const defaultConfig = { automatic: false, includeLayers: false, number: 5 }; const settings = options ? Object.assign(Object.assign(Object.assign({}, defaultConfig), config), options) : Object.assign(Object.assign({}, defaultConfig), config); return settings; } cleanRawOptions(rawOptions) { if (rawOptions && Object.keys(rawOptions).length > 0) { const replacementKeys = { n: 'number', d: 'dryRun', i: 'includeLayers' }; const replacedOptions = Object.keys(rawOptions).map(key => { const newKey = replacementKeys[key] || key; const value = rawOptions[key]; const numberValue = parseInt(value); const newValue = isNaN(numberValue) ? value : numberValue; return { [newKey]: newValue }; }); const options = replacedOptions === null || replacedOptions === void 0 ? void 0 : replacedOptions.reduce((option1, option2) => Object.assign({}, option1, option2)); return options; } else { return undefined; } } validate({ automatic, includeLayers, number }) { assert_1.ok(typeof automatic === 'boolean', this.validationMsg('automatic', 'true or false', typeof automatic)); assert_1.ok(typeof includeLayers === 'boolean', this.validationMsg('includeLayers', 'true or false', typeof includeLayers)); assert_1.ok(typeof number === 'number', this.validationMsg('number', 'an integer greater than 1', typeof number)); assert_1.ok(number > 1, this.validationMsg('number', 'an integer greater than 1', number)); } validationMsg(property, expected, actual) { return `The prune config '${property}' property can only be ${expected}, not ${actual}`; } } exports.Settings = Settings; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2V0dGluZ3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2V0dGluZ3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQUEsbUNBQTRCO0FBRTVCLE1BQWEsUUFBUTtJQVduQixZQUFZLE1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