declapract
Version:
A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.
27 lines • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDesiredPractices = void 0;
const error_fns_1 = require("@ehmpathy/error-fns");
const getDesiredPractices = ({ config, filter, }) => {
var _a, _b, _c;
// grab the selected use case's practices
const usecase = (_a = config.declared.useCases.find((thisUseCase) => thisUseCase.name === config.scope.usecase)) !== null && _a !== void 0 ? _a : null;
if (!usecase && config.scope.usecase)
throw new error_fns_1.UnexpectedCodePathError('requested usecase was not declared on config', { usecase: config.scope.usecase });
// declare the practices
const practicesChosen = [
...((_b = usecase === null || usecase === void 0 ? void 0 : usecase.practices) !== null && _b !== void 0 ? _b : []),
...((_c = config.scope.practices) !== null && _c !== void 0 ? _c : []).map((practiceName) => {
var _a;
return (_a = config.declared.practices.find((practice) => practice.name === practiceName)) !== null && _a !== void 0 ? _a : error_fns_1.UnexpectedCodePathError.throw('requested practice was not declared on config', { practiceName });
}),
];
// filter the practices
const practicesFiltered = practicesChosen.filter((practice) => (filter === null || filter === void 0 ? void 0 : filter.practiceNames)
? filter === null || filter === void 0 ? void 0 : filter.practiceNames.includes(practice.name) // if practice.name filter was defined, ensure practice.name is included
: true);
// return those
return practicesFiltered;
};
exports.getDesiredPractices = getDesiredPractices;
//# sourceMappingURL=getScopedPractices.js.map