2017-11-24 20:37:40 +02:00
|
|
|
class SyncTargetRegistry {
|
|
|
|
static classById(syncTargetId) {
|
2017-11-24 20:59:16 +02:00
|
|
|
const info = SyncTargetRegistry.reg_[syncTargetId];
|
|
|
|
if (!info) throw new Error('Invalid id: ' + syncTargetId);
|
|
|
|
return info.classRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
static addClass(SyncTargetClass) {
|
|
|
|
this.reg_[SyncTargetClass.id()] = {
|
|
|
|
id: SyncTargetClass.id(),
|
2017-11-24 21:21:30 +02:00
|
|
|
name: SyncTargetClass.targetName(),
|
2017-11-24 20:59:16 +02:00
|
|
|
label: SyncTargetClass.label(),
|
|
|
|
classRef: SyncTargetClass,
|
2018-02-06 20:59:36 +02:00
|
|
|
supportsConfigCheck: SyncTargetClass.supportsConfigCheck(),
|
2017-11-24 20:59:16 +02:00
|
|
|
};
|
2017-11-24 20:37:40 +02:00
|
|
|
}
|
|
|
|
|
2017-11-24 21:21:30 +02:00
|
|
|
static nameToId(name) {
|
|
|
|
for (let n in this.reg_) {
|
|
|
|
if (!this.reg_.hasOwnProperty(n)) continue;
|
|
|
|
if (this.reg_[n].name === name) return this.reg_[n].id;
|
|
|
|
}
|
|
|
|
throw new Error('Name not found: ' + name);
|
|
|
|
}
|
|
|
|
|
2018-01-25 21:01:14 +02:00
|
|
|
static idToMetadata(id) {
|
|
|
|
for (let n in this.reg_) {
|
|
|
|
if (!this.reg_.hasOwnProperty(n)) continue;
|
|
|
|
if (this.reg_[n].id === id) return this.reg_[n];
|
|
|
|
}
|
|
|
|
throw new Error('ID not found: ' + id);
|
|
|
|
}
|
|
|
|
|
2018-01-25 23:15:58 +02:00
|
|
|
static idToName(id) {
|
|
|
|
return this.idToMetadata(id).name;
|
|
|
|
}
|
|
|
|
|
2017-11-24 21:21:30 +02:00
|
|
|
static idAndLabelPlainObject() {
|
|
|
|
let output = {};
|
|
|
|
for (let n in this.reg_) {
|
|
|
|
if (!this.reg_.hasOwnProperty(n)) continue;
|
|
|
|
output[n] = this.reg_[n].label;
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
2017-11-24 20:37:40 +02:00
|
|
|
}
|
|
|
|
|
2017-11-24 20:59:16 +02:00
|
|
|
SyncTargetRegistry.reg_ = {};
|
|
|
|
|
2019-07-29 15:43:53 +02:00
|
|
|
module.exports = SyncTargetRegistry;
|