Class DataPackageManager

Managers data packages metadata and exposes name lookup methods.

Index
  • Export a DataPackage object for local caching purposes.

    Returns DataPackage

    It is recommended to export/import any data packages ahead of time to reduce unnecessary calls to DataPackageManager.fetchPackage and reduce connection startup time and lighten network overhead. See below for an example.

    import fs from "node:fs";
    import { Client } from "archipelago.js";

    // ... misc client code (connecting and fetching data package).

    // Save data package to a local file.
    const data = client.package.exportPackage();
    fs.writeFileSync("path/to/cache/datapackage_cache.json", JSON.stringify(data), "utf8");
  • Fetches and returns the DataPackage from the server, if the games are not locally cached or checksums do not match.

    Parameters

    • games: string[] = []

      A list of game packages to fetch. If omitted, will fetch all available game packages from the current room.

    • update: boolean = true

      If true, after fetching the data package, any changes will automatically be updated without needing to manually call DataPackageManager.importPackage.

    Returns Promise<DataPackage>

    It is recommended to export and locally cache the data package after fetching, then prior to any future connections, importing the locally cached package to reduce unnecessary network bandwidth.

    Any requested games that do not exist in the current room will be ignored.

  • Import a DataPackage object to prepopulate local cache.

    Parameters

    Returns void

    It is recommended to export/import any data packages ahead of time to reduce unnecessary calls to DataPackageManager.fetchPackage and reduce connection startup time and lighten network overhead. See below for an example.

    import fs from "node:fs";
    import { Client } from "archipelago.js";

    const data = fs.readFileSync("path/to/cache/datapackage_cache.json");
    const client = new Client();

    client.package.importPackage(JSON.parse(data));
    await client.login("wss://archipelago.gg:38281", "Phar", "Clique");
    <script src="archipelago.js" type="module">
    import { Client } from "archipelago.js";

    const data = localStorage.getItem("datapackage_cache");
    const client = new Client();

    client.package.importPackage(JSON.parse(data));
    await client.login("wss://archipelago.gg:38281", "Phar", "Clique");
    </script>
  • Lookup an item name by its integer id.

    Parameters

    • game: string

      The name of the game this item is associated with.

    • id: number

      The id of the item to name lookup.

    • Optionalfallback: true

      If true, returns "Unknown Item {id}" instead of undefined, if id does not exist in package. Defaults to true, if omitted.

    Returns string

  • Lookup an item name by its integer id.

    Parameters

    • game: string

      The name of the game this item is associated with.

    • id: number

      The id of the item to name lookup.

    • fallback: false

      If true, returns "Unknown Item {id}" instead of undefined, if id does not exist in package. Defaults to true, if omitted.

    Returns string | undefined

  • Lookup a location name by its integer id.

    Parameters

    • game: string

      The name of the game this location is associated with.

    • id: number

      The id of the location to name lookup.

    • Optionalfallback: true

      If true, returns "Unknown Location {id}" instead of undefined, if id does not exist in package. Defaults to true, if omitted.

    Returns string

  • Lookup a location name by its integer id.

    Parameters

    • game: string

      The name of the game this location is associated with.

    • id: number

      The id of the location to name lookup.

    • fallback: false

      If true, returns "Unknown Location {id}" instead of undefined, if id does not exist in package. Defaults to true, if omitted.

    Returns string | undefined

  • Registers a custom data package cache, or disables caching completely.

    Parameters

    • cache: DataPackageCache | null

      A DataPackageCache implementation, which will be called into when fetching the data package, or null to disable caching completely.

    Returns void

    By default, the library provides a default cache using IndexedDB in browser environments, but providing a custom cache overrides the default implementation. This can you give more control over the cache if you need it, and it's required if you want to have data package caching in a non-browser environment.