ART Framework API Docs
    Preparing search index...

    Class IndexedDBStorageAdapter

    An implementation of the StorageAdapter interface that uses the browser's IndexedDB API for persistent, client-side storage.

    This adapter is suitable for web applications where conversation history, agent state, and observations need to persist across sessions.

    Important: The init() method must be called and awaited before performing any other database operations (get, set, delete, query).

    • StorageAdapter for the interface it implements.
    • IndexedDBConfig for configuration options.

    Implements

    Index

    Constructors

    Methods

    • Removes all data from all object stores managed by this adapter instance within the database. Use with caution as this is destructive.

      Returns Promise<void>

      A promise that resolves when all specified object stores have been cleared.

      If the database is not initialized or a transaction error occurs.

    • Removes all items from a specific object store (collection).

      Parameters

      • collection: string

        The name of the object store to clear.

      Returns Promise<void>

      A promise that resolves when the collection is successfully cleared.

      If the database is not initialized, the store doesn't exist, or a database error occurs.

    • Deletes an item from the specified object store (collection) by its ID.

      Parameters

      • collection: string

        The name of the object store.

      • id: string

        The ID (key) of the item to delete.

      Returns Promise<void>

      A promise that resolves when the deletion is successful.

      If the database is not initialized, the store doesn't exist, or a database error occurs.

    • Retrieves a single item by its ID from the specified object store (collection).

      Type Parameters

      • T

        The expected type of the retrieved item.

      Parameters

      • collection: string

        The name of the object store.

      • id: string

        The ID (key) of the item to retrieve.

      Returns Promise<null | T>

      A promise resolving to a copy of the item if found, or null otherwise.

      If the database is not initialized, the store doesn't exist, or a database error occurs.

    • Opens the IndexedDB database connection and ensures the required object stores are created or updated based on the configured dbVersion. This method MUST be called and awaited successfully before using other adapter methods. It handles the onupgradeneeded event to create stores.

      Returns Promise<void>

      A promise that resolves when the database is successfully opened and ready, or rejects on error.

    • Queries items within a collection based on provided filter options. Note: This implementation uses getAll() and performs filtering, sorting, and limiting client-side. For large datasets, performance may be suboptimal. A more advanced version would leverage IndexedDB indexes and cursors for efficient querying directly within the database. Supports basic exact-match filtering and single-key sorting.

      Type Parameters

      • T

        The expected type of the items in the collection.

      Parameters

      • collection: string

        The name of the object store to query.

      • filterOptions: FilterOptions

        Options for filtering, sorting, skipping, and limiting results.

      Returns Promise<T[]>

      A promise resolving to an array of deep copies of the matching items.

      If the database is not initialized, the store doesn't exist, or a database error occurs.

      TODO: Implement more advanced querying using IndexedDB indexes and cursors. This will improve performance for large datasets.

    • Saves (creates or updates) an item in the specified object store (collection). Assumes the object store uses 'id' as its keyPath. The id parameter provided should match the id property within the data object. Uses structuredClone to store a deep copy.

      Type Parameters

      • T

        The type of the data being saved. Must have an 'id' property.

      Parameters

      • collection: string

        The name of the object store.

      • id: string

        The unique ID of the item (should match data.id).

      • data: T

        The data object to save. Must contain an id property matching the id parameter.

      Returns Promise<void>

      A promise that resolves when the data is successfully saved.

      If the database is not initialized, the store doesn't exist, data is missing the 'id' property, or a database error occurs.