Object that stores injectables
AnnotatedDatastore for interface definition
import { AnnotatedDatastore, Datastore } from "@fork-git-it/annotatedjs";
@Datastore()
class TestDatastore implements AnnotatedDatastore<string> {
private map = new Map<string, string>();
length: number = 0;
async clear(): Promise<undefined> {
this.map.clear();
this.length = 0;
}
async getItem(keyName: string): Promise<string | null> {
return this.map.get(keyName) || null;
}
async key(index: number): Promise<string | null> {
return [...this.map.keys()].at(index) || null;
}
async removeItem(keyName: string): Promise<undefined> {
const keyExisted = this.map.has(keyName);
this.map.delete(keyName);
if (!keyExisted) {
this.length--;
}
}
async setItem(keyName: string, value: string): Promise<undefined> {
const keyExisted = this.map.has(keyName);
this.map.set(keyName, value);
if (!keyExisted) {
this.length++;
}
}
}
Generated using TypeDoc
A class decorator that defines an injectable datastore