UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

55 lines 1.49 kB
import { NotFoundError } from '../../error/index.js'; export default class FakeFeatureLinkStore { constructor() { this.links = []; } async count(query) { if (!query) { return this.links.length; } const filteredLinks = this.links.filter((link) => { return Object.entries(query).every(([key, value]) => { return link[key] === value; }); }); return filteredLinks.length; } async insert(link) { const newLink = { ...link, id: String(Math.random()), }; this.links.push(newLink); return newLink; } async delete(id) { const index = this.links.findIndex((link) => link.id === id); if (index !== -1) { this.links.splice(index, 1); } } async deleteAll() { this.links = []; } destroy() { } async exists(id) { return this.links.some((link) => link.id === id); } async get(id) { const link = this.links.find((link) => link.id === id); if (link) { return link; } throw new NotFoundError('Could not find feature link'); } async getAll() { return this.links; } async update(id, link) { await this.delete(id); const fullLink = { ...link, id }; this.links.push(fullLink); return fullLink; } } //# sourceMappingURL=fake-feature-link-store.js.map