Storage
Older API, still supported and not going away. New decks should use
Storeinstead: it stores each key on its own, so concurrent writes do not overwrite each other, and it holds far more than this does.Storagekeeps 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 atkey, ornullif it is not set.Storage.set(key, value)โ setskey.valuemust be something that converts to JSON. The nextget(key)returns it immediately; the write saves in the background.Storage.remove(key)โ removeskey.
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 });