feat: add CacheStore for GitHub stats and use names instead of usernames (#405)

* feat: add CacheStore for GitHub stats and use names instead of usernames

* fix: only cache name for successful API queries

* chore: linting

* chore: refactor any with unknown and add jsdocs

* fix: use cached endpoint to avoid rate limiting issues

* fix: code style

* chore: add type assertion

* fix: use correct type

* Revert "fix: use correct type"

This reverts commit 74956c12f3.

* fix: use correct type

* fix: use URL Web API

* fix: add CONTRIBUTORS_API_ROUTE constant

---------

Co-authored-by: Derek Chen <derex1987@gmail.com>
Co-authored-by: doprz <52579214+doprz@users.noreply.github.com>
This commit is contained in:
Kabir Ramzan
2024-11-13 12:01:20 -06:00
committed by GitHub
parent 46c76b1703
commit b732a80eaa
4 changed files with 108 additions and 25 deletions

View File

@@ -0,0 +1,15 @@
import type { CachedData } from '@shared/types/CachedData';
import { createLocalStore, debugStore } from 'chrome-extension-toolkit';
interface ICacheStore {
github: Record<string, CachedData<unknown>>;
}
/**
* A store that is used for storing cached data such as GitHub contributors
*/
export const CacheStore = createLocalStore<ICacheStore>({
github: {},
});
debugStore({ cacheStore: CacheStore });

View File

@@ -0,0 +1,8 @@
/**
* Represents cached data with its fetch timestamp
* @template T The type of the cached data
*/
export type CachedData<T> = {
data: T;
dataFetched: number;
};