@d2api/manifest-node v2.0.9
@d2api/manifest-node
a simple singleton with functions to download, ✨CACHE✨, and access the d2 manifest, with proper component types
this package downloads the manifest and provides functions to retrieve its data. it caches the fetched tables on disk, for faster loads later.
these functions will return accurately typed entries from bungie-api-ts.
so your tsc
or IDE of choice should know that a DestinyInventoryItem
has an itemCategoryHashes
property, and it's an array of numbers.
// [...] setup here
const myItem = getInventoryItem(460688465);
myItem.icon;
// TypeScript error: Property 'icon' does not exist on type 'DestinyInventoryItemDefinition'.ts(2339)
functions/exports
setup
setApiKey('apikey')
you should add an api key or defs download will probably only work intermittently.
setLanguage('en')
sets the language of the manifest to download. doing this alone doesn't trigger a fresh download, you need to load()
afterward.
verbose()
run this if you love console logs.
includeTables(['InventoryItem', 'Activity'])
specify which definitions tables should be downloaded and available. you can leave this empty to fetch everything, but do you really need several MB worth of UnlockValue
s?
see load
below for an extra note.
excludeTables(['UnlockValues', 'InventoryItemLite'])
if you realllly want everything, you can specify which definitions tables should be excluded, and download everything else.
prefer using includeTables
, but if you're downloading everything, this is a good place to put InventoryItemLite
since you'll already have InventoryItem
load()
loads the newest manifest according to what version the API advertises. attempts to use the cached copy if it's up to date. returns a promise that resolves once loading is complete.
THIS CAN BE RE-RUN
- to download additional data after adding more components with
includeTables
- to check for manifest version updates
- to switch to a new language
loadLocal()
SYNCHRONOUSLY loads the most recent available LOCAL copy of the requested tables
this uses NO INTERNET: it won't check available version, update data,
or download tables if they're missing, so...
use sparingly and under specific circumstances, like when you KNOW you've already pre-loaded the manifest
returns true if it managed to load all the requested tables
lookups
getActivity('2656947700')
performs a lookup of a known activity hash. this example returns the type DestinyActivityDefinition | undefined
, because the hash might not be valid.
optional chaining will serve you well here, or you can live dangerously with a non-null assertion!
get('Activity', 2656947700)
a more generic def getter, which accepts table names as string literals. this returns the same data as the above example.
getInventoryItem(2575506895)
/ getDamageType(3373582085)
same as getActivity, but for other tables/data types. there's 50+ of these functions, i am not going to list them all here, that's what intellisense is for.
getAll('Activity')
returns an array of all the values in a manifest component, such as DestinyActivityDefinition
getComponent('InventoryItem')
like getAll
but returns the whole object, keyed by hashes
allManifest
an object containing all manifest components which have been fetched
loadedVersion
the manifest version currently loaded in memory. the version that you'll get information from if you get()
an entry
examples
basic usage
import { verbose, setApiKey, load, getInventoryItem, getAll, includeTables } from '@d2api/manifest-node';
verbose(); // make the client chatty. if you want.
setApiKey('hahahoho');
includeTables(['InventoryItem', 'DamageType']);
async () => {
// checks the API for the current version.
// loads our cached copy if it's up to date, or downloads a new one from bungie
await load();
// if you made it to this comment, the manifest is ready for use!
const kindledOrchid = getInventoryItem(2575506895);
console.log(kindledOrchid?.displayProperties.description);
// -> "Find the beauty in the flame."
console.log(getAll('DamageType').length);
// -> 6
}