TheDrone7 / shieldbow

An all-purpose league of legends API Client.
https://shieldbow.thedrone7.dev/
GNU General Public License v3.0
35 stars 6 forks source link

Standardize cache key types #27

Closed MrBartusek closed 2 years ago

MrBartusek commented 2 years ago

Currently diffrent menagers have diffrent keys for thier caches.

const client = new Client(process.env.riot_api_key);
client
  .initialize({
    region: 'eune'
  })
  .then(async () => {
    // Account - ID
    await client.accounts.fetchByNameAndTag('MrBartusek', '2115');
    console.log(client.accounts.cache.firstKey()); //x7CIb26dLfGwIHI3_G2H2FgfwGqbgxBe03WdI2c_rV59l_O29ohqTdh13_f55U7Cik0_HdwoPpzcFg

    // Items - ID
    await client.items.findByName('Boots');
    console.log(client.items.cache.firstKey()); //1001

    // Runes - Name
    await client.runes.fetch('Domination');
    console.log(client.runes.cache.firstKey()); // Domination

    // Spells - Name
    await client.summonerSpells.findByName('SummonerFlash');
    console.log(client.summonerSpells.cache.firstKey()); //SummonerBarrier

    // Summoners - ID
    await client.summoners.fetchBySummonerName('MrBartusek');
    console.log(client.summoners.cache.firstKey()); // XvE1rKiAdjvMZvNBML5b9C4narjF5kZmlQtG1oTcUgkWPrk

    // Leagues - ID
    await client.leagues.fetchByQueueAndTier('RANKED_SOLO_5x5', 'SILVER', 'I');
    console.log(client.leagues.cache.firstKey()); // LLjKgoZ5gjaNqgiIX10NAWo6qlhPowupjQbrTm2-EajW

    // Matches - ID
    await client.matches.fetch('EUN1_3192532599');
    console.log(client.matches.cache.firstKey()); // EUN1_3192532599

    // Clash - ID
    await client.clash.fetchAll();
    console.log(client.clash.cache.firstKey()); // 3125
  });
TheDrone7 commented 2 years ago

The "cache" keys right now are set to whatever would be best to use for internal use. Ideally, we don't want users accessing the cache in the first place and use the fetch methods instead.

MrBartusek commented 2 years ago

I guess, but if it is exposed to the user it can just be standardized. Probably using ids? I guess keys should be ids rather than names

TheDrone7 commented 2 years ago

It's only exposed to the user as a fallback, should definitely update the docs to indicate this as I'm working towards standardization of the fetch methods in the various managers.