wxt-dev / wxt-dev/wxt

storage.defineMap

Open
#1,864 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
10.5k
Forks
564
PR merge metrics
No merged PRs in 30d

Description

Feature Request

Add support for storage.defineMap to manage namespaced collections in extension storage.

Currently, storage.defineItem is great for managing a single key/value with fallback and typing. However, many extensions need to manage collections of related entries (like accounts, sessions, cached items, etc.) where each entry should be stored under its own key but share a common namespace.

Proposed API
type AccountDetails = {
  name: string;
  email: string;
};

const accounts = storage.defineMap<string, AccountDetails | null>(
  "local:account",
  {
    fallbackValue: null,
  },
);

// set
await accounts.setValue("account-1", { name: "Alice", email: "a@ex.com" });

// get
const acc = await accounts.getValue("account-1"); // AccountDetails | null

// list
const allAccounts = await accounts.getAll();

// keys
const keys = await accounts.keys();

// delete
await accounts.deleteValue("account-1");

The entries would be stored as multiple keys with the format:

account:account-1
account:account-2
...

This mirrors defineItem’s ergonomics but allows managing collections in a structured way.

Is your feature request related to a bug?

N/A

What are the alternatives?
  • Manually prefix keys with storage.defineItem and manage them individually.
  • Implement custom helper utilities (which leads to duplicated code across projects).
  • Use defineItem with a single object holding all entries, but this means writes overwrite the whole collection, making sync inefficient.
Additional context

defineMap would simplify working with multiple related storage items, improve readability, and reduce boilerplate in extensions that manage sets of accounts, wallets, or similar keyed collections.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing storage.defineItem implementation and its tests, then compare its typing, fallback, and key-handling behavior with the proposed defineMap API. Done means supporting setValue, getValue, getAll, keys, and deleteValue for namespaced entries using the documented key format, with appropriate tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.