CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-store

tessl install tessl/npm-store@2.0.0

A localStorage wrapper for all browsers without using cookies or flash, providing persistent client-side storage with automatic fallback and plugin architecture

Agent Success

Agent success rate when using this tile

75%

Improvement

Agent success rate improvement when using this tile compared to baseline

0.96x

Baseline

Agent success rate without this tile

78%

task.mdevals/scenario-6/

Storage Manager with Automatic Fallback

Build a storage manager that implements automatic testing and fallback between multiple storage mechanisms to ensure storage always works, even in restrictive browser environments.

Requirements

Your storage manager should:

  1. Support multiple storage backends that can be tested in priority order
  2. Automatically test each storage mechanism by performing write/read/remove operations
  3. Select and use the first working storage mechanism from the list
  4. Provide a flag indicating whether a working storage mechanism was found
  5. Gracefully handle storage failures and exceptions during testing
  6. Ensure the storage manager always has a usable storage mechanism (even if it's in-memory)

Storage Backend Interface

Each storage backend should support the following operations:

  • Writing a key-value pair
  • Reading a value by key
  • Removing a key

Test Cases

  • Given a list of storage backends where the first one works, the manager selects and uses the first backend. @test
  • Given a list of storage backends where the first one fails but the second works, the manager automatically falls back to the second backend. @test
  • When testing a storage backend that throws an exception during write operations, the manager catches the exception and tries the next backend. @test
  • When all storage backends fail, the manager uses an in-memory fallback that doesn't persist data but allows operations to succeed. @test
  • The manager provides an enabled flag that is true when a persistent storage mechanism is available, and false when using in-memory fallback only. @test

Implementation

@generates

API

/**
 * Creates a storage manager that automatically tests and selects a working storage backend.
 *
 * @param {Array} storageBackends - Array of storage backend objects to test in order.
 *                                  Each backend should have read, write, and remove methods.
 * @returns {Object} A storage manager with read, write, remove methods and an enabled flag.
 */
function createStorageManager(storageBackends) {
  // IMPLEMENTATION HERE
}

module.exports = { createStorageManager };

Dependencies { .dependencies }

store { .dependency }

Provides cross-browser storage functionality with automatic fallback mechanisms.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/store@2.0.x
tile.json