@hiki9/rich-domain
Version:
Rich Domain is a library that provides a set of tools to help you build complex business logic in NodeJS using Domain Driven Design principles.
57 lines • 2.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.lodashCompare = void 0;
const lodash_1 = __importDefault(require("lodash"));
const entity_keys_to_exclude_on_compare_1 = require("../core/domain/entity-keys-to-exclude-on-compare");
function lodashCompare(a, b) {
const result = {
different: [],
missing_from_first: [],
missing_from_second: []
};
lodash_1.default.reduce(a, function (result, value, key) {
if (b?.hasOwnProperty(key)) {
if (lodash_1.default.isEqualWith(value, b[key], entity_keys_to_exclude_on_compare_1.isEqualWithoutCompareSpecifiedKeys)) {
return result;
}
else {
if (typeof (a[key]) != typeof ({}) || typeof (b[key]) != typeof ({})) {
result.different.push(key);
return result;
}
else {
var deeper = lodashCompare(a[key], b[key]);
result.different = result.different.concat(lodash_1.default.map(deeper.different, (sub_path) => {
return key + "." + sub_path;
}));
result.missing_from_second = result.missing_from_second.concat(lodash_1.default.map(deeper.missing_from_second, (sub_path) => {
return key + "." + sub_path;
}));
result.missing_from_first = result.missing_from_first.concat(lodash_1.default.map(deeper.missing_from_first, (sub_path) => {
return key + "." + sub_path;
}));
return result;
}
}
}
else {
result.missing_from_second.push(key);
return result;
}
}, result);
lodash_1.default.reduce(b, function (result, _, key) {
if (a.hasOwnProperty(key)) {
return result;
}
else {
result.missing_from_first.push(key);
return result;
}
}, result);
return result;
}
exports.lodashCompare = lodashCompare;
//# sourceMappingURL=lodash-compare.js.map