Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async create(value: PreEntity): Promise {
if (value.id != null) {
if (this.pool[value.id] != null) {
throw new Error(
`The given id "${value.id}" already exists in memory pool.`
);
}
// @ts-ignore value.id exists
return this.set(value);
}
const newValue = updateAndRestore(value, { id: randomString() });
// @ts-ignore value.id exists
return this.set(newValue);
}
async set(value: T): Promise {
this.pool = updateAndRestore(this.pool, { $set: { [value.id]: value } });
return value;
}
async delete(id?: string | null): Promise {
if (id == null || this.pool[id] == null) {
return false;
}
this.pool = updateAndRestore(this.pool, { $unset: { [id]: "" } });
return true;
}
}