structured-elements
Version:
A TypeScript package for modelling and validating data
39 lines • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.attemptSalvageItemViaBlanking = void 0;
const array_1 = require("../is/array");
const attemptSalvageItemViaBlanking = ({ api, failures, name, subject, validElements, }) => {
if (failures.length === 0) {
return subject;
}
const unsalvageableFailures = [];
const salvage = failures.reduce((salvageInProgress, failure) => {
if ((0, array_1.isArray)(failure.expectation) &&
failure.expectation.includes(undefined)) {
return salvageInProgress;
}
if ((0, array_1.isArray)(failure.expectation) && failure.expectation.includes(null)) {
return {
...salvageInProgress,
[failure.key]: null,
};
}
unsalvageableFailures.push(failure);
return salvageInProgress;
}, validElements);
if (unsalvageableFailures.length > 0) {
if (api.debugEnabled()) {
console.log(`StructuredElements#attemptItemSalvageViaBlanking could not salvage subject: `, {
salvage,
failures,
name,
subject,
unsalvageableFailures,
});
}
return;
}
return salvage;
};
exports.attemptSalvageItemViaBlanking = attemptSalvageItemViaBlanking;
//# sourceMappingURL=itemViaBlanking.js.map