UNPKG

@atomist/sdm

Version:

Atomist Software Delivery Machine SDK

59 lines 2.45 kB
"use strict"; /* * Copyright © 2020 Atomist, Inc. * * 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.DefaultPredicateMappingCostAnalyzer = void 0; const logger_1 = require("@atomist/automation-client/lib/util/logger"); const PredicateMappingCostAnalyzer_1 = require("./PredicateMappingCostAnalyzer"); /** * Indications that evaluating this test may be expensive */ const ExpensiveSigns = [ pm => mappingCodeIncludes(pm, "await "), pm => mappingCodeIncludes(pm, ".project"), pm => mappingCodeIncludes(pm, ".graphClient"), pm => mappingCodeIncludes(pm, ".totalFileCount"), pm => mappingCodeIncludes(pm, ".doWithFiles"), pm => mappingCodeIncludes(pm, ".getFile", ".findFile"), pm => mappingCodeIncludes(pm, ".stream"), pm => mappingCodeIncludes(pm, "findMatches", "findFileMatches", "doWithMatches", "doWithFileMatches"), ]; /** * Estimate cost by looking at code to see if it goes through a project * @param {PredicateMapping<any>} pm * @return {any} * @constructor */ const DefaultPredicateMappingCostAnalyzer = pm => { if (ExpensiveSigns.some(sign => sign(pm))) { logger_1.logger.debug(`Expected cost of ${pm.name} is expensive`); return PredicateMappingCostAnalyzer_1.ExpectedPredicateMappingCost.expensive; } logger_1.logger.debug(`Expected cost of ${pm.name} is unknown`); return PredicateMappingCostAnalyzer_1.ExpectedPredicateMappingCost.unknown; }; exports.DefaultPredicateMappingCostAnalyzer = DefaultPredicateMappingCostAnalyzer; /** * Does the mapping include any of these patterns * @param {PredicateMapping<any>} pm * @param {string} patterns * @return {boolean} */ function mappingCodeIncludes(pm, ...patterns) { const code = pm.mapping.toString(); return patterns.some(pattern => code.includes(pattern)); } //# sourceMappingURL=defaultPredicateMappingCostAnalyzer.js.map