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:
15
src/shared/storage/CacheStore.ts
Normal file
15
src/shared/storage/CacheStore.ts
Normal 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 });
|
||||
8
src/shared/types/CachedData.ts
Normal file
8
src/shared/types/CachedData.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user