unleash-server
Version:
Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.
52 lines • 1.54 kB
JavaScript
import NotFoundError from '../../error/notfound-error.js';
export default class FakePatStore {
constructor() {
this.pats = [];
this.nextId = 1;
}
async create(pat, secret, userId) {
const newPat = {
id: this.nextId++,
description: pat.description,
expiresAt: pat.expiresAt,
userId,
createdAt: new Date().toISOString(),
seenAt: undefined,
};
this.pats.push(newPat);
return newPat;
}
async delete(key) {
this.pats = this.pats.filter((p) => p.id !== key);
}
async deleteForUser(id, userId) {
this.pats = this.pats.filter((p) => !(p.id === id && p.userId === userId));
}
async deleteAll() {
this.pats = [];
}
destroy() { }
async exists(key) {
return this.pats.some((p) => p.id === key);
}
async existsWithDescriptionByUser(description, userId) {
return this.pats.some((pat) => pat.description === description && pat.userId === userId);
}
async countByUser(userId) {
return this.pats.filter((p) => p.userId === userId).length;
}
async get(key) {
const pat = this.pats.find((p) => p.id === key);
if (!pat) {
throw new NotFoundError('No PAT found.');
}
return pat;
}
async getAll() {
return this.pats;
}
async getAllByUser(userId) {
return this.pats.filter((p) => p.userId === userId);
}
}
//# sourceMappingURL=fake-pat-store.js.map