Improvements for Supplier replication

This commit is contained in:
Uwe Klinger
2021-05-03 12:52:11 +02:00
parent de806a1e38
commit eb4bc703dd
6 changed files with 106 additions and 5 deletions

38
suppliers/monkey-patch.js Normal file
View File

@@ -0,0 +1,38 @@
const deploy = require("@sap/cds/lib/deploy");
const DEBUG = (...args) => console.log(...args);
deploy.exclude_external_entities_in = function (csn, _bound) {
// NOSONAR
for (let [each, { service = each, model, credentials }] of Object.entries(
cds.requires
)) {
if (!model) continue; //> not for internal services like cds.requires.odata
if (_bound && !credentials) continue;
DEBUG && DEBUG("excluding external entities for", service, "...");
const prefix = service + ".";
for (let each in csn.definitions) {
const def = csn.definitions[each];
if (def["@cds.persistence.table"] === true) continue;
if (each.startsWith(prefix)) {
DEBUG && DEBUG("excluding external entity", each);
_exclude(each);
}
}
}
return csn;
function _exclude(each) {
const def = csn.definitions[each];
if (def.kind !== "entity") return;
def["@cds.persistence.skip"] = true;
// propagate to all views...
for (let other in csn.definitions) {
const d = csn.definitions[other];
// do not exclude replica table
if (d["@cds.persistence.table"] === true) continue;
const p = (d.query && d.query.SELECT) || d.projection;
if (p && p.from.ref && p.from.ref[0] === each) _exclude(other);
}
}
};