key-value-file-system
Version:
Turn any key-value store into a file system for hierarchical object storage
33 lines (32 loc) • 1.3 kB
TypeScript
export interface KeyValueStore {
getAllKeys(): Promise<readonly string[]>;
getItem(key: string): Promise<string | null>;
setItem(key: string, value: string): Promise<void>;
removeItem(key: string): Promise<void>;
multiGet(keys: readonly string[]): Promise<readonly [string, string | null][]>;
multiSet(keyValuePairs: Array<[string, string]>): Promise<void>;
multiRemove(keys: readonly string[]): Promise<void>;
}
export interface PathValue<T> {
path: string;
value: T;
}
export default class KeyValueFileSystem {
store: KeyValueStore;
prefix: string;
constructor(store: KeyValueStore, keyNamespacePrefix?: string);
ls(spec?: string): Promise<readonly string[]>;
read<T>(path: string): Promise<T | null>;
readMulti<T>(spec: string): Promise<readonly PathValue<T | null>[]>;
write<T>(path: string, value: T): Promise<void>;
/**
* @param basePath The base path to prepend to each subPath in values.
* @param values Each subPath and object you want written
*/
writeMulti<T>(basePath: string | undefined, values: PathValue<T>[]): Promise<void>;
rm(spec: string): Promise<void>;
rmMulti(paths: string[]): Promise<void>;
rmAllForce(): Promise<void>;
private validatePath;
private regexFromSpec;
}