This repository has been archived on 2023-08-31. You can view files and clone it, but cannot push or open issues or pull requests.
relay-plugin-registry/src/storage/backends/lmdb.ts

26 lines
854 B
TypeScript

import { SignedRegistryEntry, RegistryStorage } from "../../types.js";
import { open, RootDatabase } from "lmdb";
import { PluginAPI } from "@lumeweb/relay-types";
import path from "node:path";
export default class Lmdb implements RegistryStorage {
private _database: RootDatabase<SignedRegistryEntry>;
constructor(opts: { api: PluginAPI }) {
const config = opts.api.config.str("configdir");
this._database = open<SignedRegistryEntry>({
path: path.join(path.dirname(config), "data", "registry"),
sharedStructuresKey: Symbol.for("structures"),
});
}
async get(key: string): Promise<boolean | SignedRegistryEntry> {
const ret = await this._database.get(key);
return ret ?? false;
}
async set(key: string, value: SignedRegistryEntry): Promise<boolean> {
return await this._database.put(key, value);
}
}