Skip to main content

Storage

Older API, still supported and not going away. New decks should use Store instead: it stores each key on its own, so concurrent writes do not overwrite each other, and it holds far more than this does. Storage keeps one document per player and rewrites all of it on every change.

Storage saves data for the current player. Nobody else can read it.

A player's whole Storage document is at most 2 MB. A write that takes it past that never saves, and nothing tells the deck: set has already returned.

  • Storage.get<T>(key): Promise<T | null> โ€” the value at key, or null if it is not set.
  • Storage.set(key, value) โ€” sets key. value must be something that converts to JSON. The next get(key) returns it immediately; the write saves in the background.
  • Storage.remove(key) โ€” removes key.
const level = (await Storage.get("level")) ?? 1;
Storage.set("level", 7);

The same thing with Store, which is what a new deck should write:

const { level = 1 } = await Store.private.get(["level"]);
await Store.private.set({ level: 7 });