{
  "version": 3,
  "sources": ["../../src/getStoreDirectory.ts", "../../src/localPersistentMap.ts", "../../src/SynchronousLmdbMap.ts"],
  "sourcesContent": ["import Path from 'node:path'\n\nimport type { StoreKind } from './StoreKind.ts'\n\n/**\n * Creates a convention-based directory path for an archivist store\n * @param name The name of the archivist\n * @param storageRoot The root directory for storage\n * @param kind The kind of the archivist (optional)\n * @returns The directory path for the archivist store\n */\nexport const getStoreDirectory = (name: string, storageRoot: string, kind?: StoreKind): string => {\n  return (kind === undefined) ? Path.join(storageRoot, name) : Path.join(storageRoot, kind, name)\n}\n", "import { rm } from 'node:fs/promises'\nimport Path from 'node:path'\n\nimport type { MapType } from '@xyo-network/xl1-protocol/protocol-lib'\n\nimport { getStoreDirectory } from './getStoreDirectory.ts'\nimport type { StoreKind } from './StoreKind.ts'\nimport { SynchronousLmdbMap } from './SynchronousLmdbMap.ts'\n\nconst DEFAULT_STORAGE_ROOT = Path.join(process.cwd(), '.store')\n\n/**\n * Returns a local persistent map\n * @param dbName The name of the database\n * @param storeName The name of the store\n * @param storageRoot The root directory for storage (default is '.store' in the current working directory)\n * @param kind The kind of the map\n * @returns a map\n */\nexport const getLocalPersistentMap = async <TId, TData>(\n  dbName: string,\n  storeName: string,\n  storageRoot?: string,\n  kind: StoreKind = 'lmdb'): Promise<MapType<TId, TData>> => {\n  switch (kind) {\n    case 'lmdb': {\n      const root = storageRoot ?? DEFAULT_STORAGE_ROOT\n      const location = getStoreDirectory(dbName, root, 'lmdb')\n      const store = await SynchronousLmdbMap.create({\n        location, dbName, storeName,\n      })\n      await store.start()\n      return store as unknown as MapType<TId, TData>\n    }\n  }\n}\n\n/** Recursively deletes the on-disk storage directory for a local persistent map. */\nexport const deleteLocalPersistentMap = async (\n  dbName: string,\n  storageRoot?: string,\n  kind: StoreKind = 'lmdb',\n): Promise<void> => {\n  await Promise.resolve()\n  let location = ''\n  switch (kind) {\n    case 'lmdb': {\n      const root = storageRoot ?? DEFAULT_STORAGE_ROOT\n      location = getStoreDirectory(dbName, root, 'lmdb')\n      break\n    }\n  }\n  await rm(location, { recursive: true, force: true })\n}\n", "import { AbstractCreatable, creatable } from '@ariestools/sdk'\nimport type { SyncMap } from '@xyo-network/xl1-protocol/protocol-lib'\nimport type {\n  Database, Key, RootDatabase,\n} from 'lmdb'\nimport { open } from 'lmdb'\n\nimport type { LmdbMapParams } from './Params.ts'\n\n// TODO: Abstract creatable instead of service?\n/**\n * A synchronous LMDB-backed Map implementation.\n * This class provides a synchronous interface to an LMDB database, allowing for key-value storage.\n * It allows for multi-tenancy within a single LMDB environment by using a root database (located\n * at this.folderPath) and a specific DB within the environment (specified by this.params.storeName).\n * @template K - The type of keys in the map.\n * @template V - The type of values in the map.\n */\n@creatable()\nexport class SynchronousLmdbMap<K extends Key, V> extends AbstractCreatable<LmdbMapParams> implements SyncMap<K, V> {\n  protected db!: Database<V, K>\n  protected rootDatabase!: RootDatabase\n\n  /**\n   * The path to the LMDB folder where the database is stored.\n   * This is constructed from the location and dbName parameters\n   * allowing for multiple DBs within the root (by specifying a\n   * different storeName).\n   * @returns The folder path for the LMDB database.\n   */\n  get folderPath() {\n    return `${this.params.location}/${this.params.storeName}`\n  }\n\n  /** Returns all values currently stored in the named LMDB database. */\n  all(): V[] {\n    return [...this.db.getRange({})].map(entry => entry.value)\n  }\n\n  /** Removes every key/value entry from the named database synchronously. */\n  clear(): void {\n    this.db.clearSync()\n  }\n\n  /** Removes a key synchronously and reports whether it existed. */\n  delete(id: K): boolean {\n    return this.db.removeSync(id)\n  }\n\n  /** Returns the value stored for a key, or `undefined` when absent. */\n  get(id: K): V | undefined {\n    return this.db.get(id)\n  }\n\n  /** Returns the values found for the supplied keys, omitting absent entries. */\n  getMany(ids: K[]): V[] {\n    const results: V[] = []\n    for (const id of ids) {\n      const value = this.db.get(id)\n      if (value !== undefined) {\n        results.push(value)\n      }\n    }\n    return results\n  }\n\n  /** Returns whether the named database contains the key. */\n  has(id: K): boolean {\n    return this.db.doesExist(id)\n  }\n\n  /** Stores a key/value pair synchronously. */\n  set(id: K, data: V): void {\n    this.db.putSync(id, data)\n  }\n\n  /** Stores each supplied key/value pair synchronously. */\n  setMany(entries: [K, V][]): void {\n    for (const [key, value] of entries) {\n      this.set(key, value)\n    }\n  }\n\n  /** Opens the LMDB environment and named database before map operations begin. */\n  override async startHandler(): Promise<void> {\n    await super.startHandler()\n    // Initialize the DB Environment (opens the default LMDB database)\n    this.rootDatabase = open({ path: this.folderPath, name: this.params.dbName })\n    // Open the desired DB (using the store name)\n    this.db = this.rootDatabase.openDB<V, K>({ name: this.params.storeName, cache: true })\n  }\n}\n"],
  "mappings": ";;;;;;;;;;;;AAAA,OAAO,UAAU;AAWV,IAAM,oBAAoB,CAAC,MAAc,aAAqB,SAA6B;AAChG,SAAQ,SAAS,SAAa,KAAK,KAAK,aAAa,IAAI,IAAI,KAAK,KAAK,aAAa,MAAM,IAAI;AAChG;;;ACbA,SAAS,UAAU;AACnB,OAAOA,WAAU;;;ACDjB,SAAS,mBAAmB,iBAAiB;AAK7C,SAAS,YAAY;AAcd,IAAM,qBAAN,cAAmD,kBAA0D;AAAA,EACxG;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASV,IAAI,aAAa;AACf,WAAO,GAAG,KAAK,OAAO,QAAQ,IAAI,KAAK,OAAO,SAAS;AAAA,EACzD;AAAA;AAAA,EAGA,MAAW;AACT,WAAO,CAAC,GAAG,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,WAAS,MAAM,KAAK;AAAA,EAC3D;AAAA;AAAA,EAGA,QAAc;AACZ,SAAK,GAAG,UAAU;AAAA,EACpB;AAAA;AAAA,EAGA,OAAO,IAAgB;AACrB,WAAO,KAAK,GAAG,WAAW,EAAE;AAAA,EAC9B;AAAA;AAAA,EAGA,IAAI,IAAsB;AACxB,WAAO,KAAK,GAAG,IAAI,EAAE;AAAA,EACvB;AAAA;AAAA,EAGA,QAAQ,KAAe;AACrB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