diff --git a/packages/access-client/src/drivers/memory.js b/packages/access-client/src/drivers/memory.js index c01e90f9e..a9390cb58 100644 --- a/packages/access-client/src/drivers/memory.js +++ b/packages/access-client/src/drivers/memory.js @@ -1,23 +1,36 @@ /** + * @template T + * @typedef {import('./types').Driver} Driver + */ + +/** + * Driver implementation that stores data in memory." + * + * Usage: + * + * ```js + * import { MemoryDriver } from '@web3-storage/access/drivers/memory' + * ``` + * * @template {Record} T * @implements {Driver} */ export class MemoryDriver { /** - * @type {T} + * @type {T|undefined} */ #data; - + constructor() { - this.#data = {}; + this.#data = undefined; } async open() {} async close() {} - + async reset() { - this.#data = {}; + this.#data = undefined; } /** @param {T} data */ @@ -27,6 +40,7 @@ export class MemoryDriver { /** @returns {Promise} */ async load() { + if (this.#data === undefined) return; if (Object.keys(this.#data).length === 0) return; return this.#data; } diff --git a/packages/access-client/src/stores/store-memory.js b/packages/access-client/src/stores/store-memory.js index dd7448f6c..ba596a5f9 100644 --- a/packages/access-client/src/stores/store-memory.js +++ b/packages/access-client/src/stores/store-memory.js @@ -9,6 +9,6 @@ import { MemoryDriver } from "../drivers/memory.js"; * import { StoreMemory } from '@web3-storage/access/stores/store-memory' * ``` * - * @extends {MemoryDriver} + * @extends {MemoryDriver} */ export class StoreMemory extends MemoryDriver {}