Class DataPackageManager
Methods
exportPackage
-
Export a DataPackage object for local caching purposes.
Returns DataPackage
Remarks
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.
Example: Node.js
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");
fetchPackage
-
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>
- games: string[] = []
findPackage
-
Returns the package metadata helper object for a specified game. If game package does not exist in cache, returns
nullinstead.Parameters
- game: string
The specific game package to look up.
Returns PackageMetadata | null
- game: string
importPackage
-
Import a DataPackage object to prepopulate local cache.
Parameters
- dataPackage: DataPackage
The package to import.
Returns void
Remarks
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.
Example: Node.js
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");Example: Modern browser (using localStorage and ES-syntax)
<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> - dataPackage: DataPackage
lookupItemName
-
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: trueIf
true, returns"Unknown Item {id}"instead ofundefined, if id does not exist in package. Defaults totrue, if omitted.
Returns string
- game: 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 ofundefined, if id does not exist in package. Defaults totrue, if omitted.
Returns string | undefined
- game: string
lookupLocationName
-
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: trueIf
true, returns"Unknown Location {id}"instead ofundefined, if id does not exist in package. Defaults totrue, if omitted.
Returns string
- game: 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 ofundefined, if id does not exist in package. Defaults totrue, if omitted.
Returns string | undefined
- game: string
setCache
-
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
nullto disable caching completely.
Returns void
Remarks
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.
- cache: DataPackageCache | null
Managers data packages metadata and exposes name lookup methods.