Class DataStorageManager

    Manages communication between the data storage API and notifies subscribers of changes to storage updates.

    Accessors

    Methods

    • Fetches a list of key-value pairs from data storage.

      Type Parameters

      • T extends JSONRecord

        The expected key-value types to be returned.

      Parameters

      • keys: (keyof T)[]

        A list of keys to fetch values for.

      • Optionalmonitor: boolean

        Adds keys to local cache and request the server to update client when changes are made to speed up subsequent lookups.

      Returns Promise<T>

      An object containing all current values for each key requested.

      Any keys not currently cached and monitored will be requested over the network instead of from memory.

    • Fetches a single key-value pair from data storage.

      Type Parameters

      Parameters

      • key: string

        The key to fetch a value for.

      • Optionalmonitor: boolean

        Adds key to local cache and request the server to update client when changes are made to speed up subsequent lookups.

      Returns Promise<T>

      The current value for this key.

      Any keys not currently cached and monitored will be requested over the network instead of from memory.

    • Returns item name groups for this package from data storage API.

      Parameters

      • game: string

        The game name to look up item name groups for.

      Returns Promise<Record<string, string[]>>

    • Returns location name groups for this package from the data storage API.

      Parameters

      • game: string

        The game name to look up location name groups for.

      Returns Promise<Record<string, string[]>>

    • Add a list of keys to be monitored for changes and fire a callback when changes are detected.

      Type Parameters

      Parameters

      • keys: (keyof T)[]

        A list of keys to fetch and watch for changes.

      • callback: DataChangeCallback

        A callback to fire whenever one of these keys change.

      Returns Promise<T>

      An object containing all current values for each key requested.

      If connection to the Archipelago server is lost, keys will no longer be tracked for changes and need to be monitored again.

      const keys = ["key1", "key2"];
      const data = await client.storage.notify(keys, (key, value, oldValue) => {
      console.log(`Key '${key}' has been updated from ${oldValue} to ${value}!`);
      });

      client.storage
      .prepare("key2", 0)
      .add(5)
      .commit();
      // Key 'key2' has been updated from 0 to 5!
    • Create a new transaction for setting a data storage key by returning an IntermediateDataOperation. To perform certain operations, just chain additional methods until finished, then call prepare().

      Type Parameters

      Parameters

      • key: string

        The key to manipulate.

      • _default: T

        The default value to be used if key does not exist.

      Returns IntermediateDataOperation<T>

      TypeError if attempting to modify a read only key.

      // Prepare key "my-key" and set initial value to 100, if key doesn't exist.
      client.storage
      .prepare("my-key", 100)
      .multiply(0.25) // Multiply value by 0.25.
      .floor() // Round down to nearest integer.
      .max(0) // Clamp value above 0.
      .commit(); // Commit operations to data storage.