2016-11-05 17:02:46 +01:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-28 10:20:22 +02:00
|
|
|
module.exports = () => {
|
2016-11-13 15:41:35 +01:00
|
|
|
const _features = [];
|
2017-12-18 14:31:59 +01:00
|
|
|
const _archive = [];
|
2016-11-13 15:41:35 +01:00
|
|
|
return {
|
2017-06-28 10:20:22 +02:00
|
|
|
getFeature: name => {
|
2016-11-15 21:27:03 +01:00
|
|
|
const toggle = _features.find(f => f.name === name);
|
|
|
|
if (toggle) {
|
|
|
|
return Promise.resolve(toggle);
|
|
|
|
}
|
2020-08-06 11:18:52 +02:00
|
|
|
return Promise.reject(new Error('could not find toggle'));
|
2016-11-15 21:27:03 +01:00
|
|
|
},
|
2018-01-20 13:28:04 +01:00
|
|
|
hasFeature: name => {
|
|
|
|
const toggle = _features.find(f => f.name === name);
|
|
|
|
const archived = _archive.find(f => f.name === name);
|
|
|
|
if (toggle) {
|
|
|
|
return Promise.resolve({ name, archived: false });
|
2020-04-14 22:29:11 +02:00
|
|
|
}
|
|
|
|
if (archived) {
|
2018-01-20 13:28:04 +01:00
|
|
|
return Promise.resolve({ name, archived: true });
|
|
|
|
}
|
2020-04-14 22:29:11 +02:00
|
|
|
return Promise.reject();
|
2018-01-20 13:28:04 +01:00
|
|
|
},
|
2021-01-18 12:32:19 +01:00
|
|
|
updateFeature: updatedFeature => {
|
|
|
|
_features.splice(
|
|
|
|
_features.indexOf(f => f.name === updatedFeature.name),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
_features.push(updatedFeature);
|
|
|
|
},
|
2016-11-13 15:41:35 +01:00
|
|
|
getFeatures: () => Promise.resolve(_features),
|
2021-01-22 13:09:26 +01:00
|
|
|
getFeaturesClient: () => Promise.resolve(_features),
|
2021-01-18 12:32:19 +01:00
|
|
|
createFeature: feature => _features.push(feature),
|
2017-12-18 14:31:59 +01:00
|
|
|
getArchivedFeatures: () => Promise.resolve(_archive),
|
|
|
|
addArchivedFeature: feature => _archive.push(feature),
|
2021-01-18 12:32:19 +01:00
|
|
|
reviveFeature: feature => {
|
|
|
|
const revived = _archive.find(f => f.name === feature.name);
|
|
|
|
_archive.splice(
|
|
|
|
_archive.indexOf(f => f.name === feature.name),
|
|
|
|
1,
|
|
|
|
);
|
|
|
|
_features.push(revived);
|
|
|
|
},
|
2020-12-22 10:49:17 +01:00
|
|
|
lastSeenToggles: (names = []) => {
|
|
|
|
names.forEach(name => {
|
|
|
|
const toggle = _features.find(f => f.name === name);
|
|
|
|
if (toggle) {
|
|
|
|
toggle.lastSeenAt = new Date();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2021-01-18 12:32:19 +01:00
|
|
|
dropFeatures: () => {
|
|
|
|
_features.splice(0, _features.length);
|
|
|
|
_archive.splice(0, _archive.length);
|
|
|
|
},
|
|
|
|
importFeature: feat => Promise.resolve(_features.push(feat)),
|
2016-11-13 15:41:35 +01:00
|
|
|
};
|
2016-11-05 17:02:46 +01:00
|
|
|
};
|