-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsinkWrapper.js
63 lines (53 loc) · 1.34 KB
/
sinkWrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"use strict";
class sinkWrapper {
constructor(sinkConfig, globallyExcludedFields) {
this.sinks = [];
sinkConfig.forEach((sink) => {
if (!sink.enabled) {
return;
}
var type = require(`./data-sink/${sink.type}.js` );
sink.options.excludeFields = this.getFieldsToExclude(globallyExcludedFields, sink.options.excludeFields);
this.sinks.push(new type(sink.options));
});
}
insertClient(clientInfo, batchId) {
this.sinks.forEach((sink) => {
clientInfo = this.exceptFields(clientInfo, sink.excludeFields);
sink.insertClient(clientInfo, batchId);
});
}
insertAccount(accountInfo, batchId) {
this.sinks.forEach((sink) => {
accountInfo = this.exceptFields(accountInfo, sink.excludeFields);
sink.insertAccount(accountInfo, batchId);
});
}
hasSinks() {
return this.sinks.length > 0;
}
/**
* Combines the global exclude list and a sink-specific one
*/
getFieldsToExclude(globalFields, customFields) {
var allFields = (customFields || []).concat(globalFields || []);
if (allFields.length == 0) {
return null;
} else {
return allFields;
}
}
exceptFields(input, exceptFields) {
if (!exceptFields) {
return input;
}
var out = {};
Object.keys(input).forEach((k) => {
if (exceptFields.indexOf(k) === -1) {
out[k] = input[k];
}
})
return out;
}
}
module.exports = sinkWrapper;