unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
49 lines • 1.27 kB
JavaScript
import NotFoundError from '../../lib/error/notfound-error.js';
export default class FakeAddonStore {
constructor() {
this.addons = [];
this.highestId = 0;
}
async delete(key) {
this.addons.splice(this.addons.findIndex((a) => a.id === key), 1);
}
async deleteAll() {
this.addons = [];
}
destroy() { }
async exists(key) {
return this.addons.some((a) => a.id === key);
}
async get(key) {
const addon = this.addons.find((a) => a.id === key);
if (addon) {
return addon;
}
throw new NotFoundError(`Could not find addon with id ${key}`);
}
async getAll() {
return this.addons;
}
async insert(addon) {
const ins = {
id: this.highestId++,
createdAt: new Date(),
description: null,
...addon,
};
this.addons.push(ins);
return ins;
}
async update(id, addon) {
await this.delete(id);
const inserted = {
id,
createdAt: new Date(),
description: null,
...addon,
};
this.addons.push(inserted);
return inserted;
}
}
//# sourceMappingURL=fake-addon-store.js.map