Slight restructure, updated auth, implement player and game endpoints

This commit is contained in:
jd
2026-02-18 21:32:28 +00:00
parent 99c7bdc0fd
commit 2996a2eb95
32 changed files with 2093 additions and 266 deletions

20
src/utilities/helpers.ts Normal file
View File

@@ -0,0 +1,20 @@
export function memo<T extends (...args: any[]) => {}, S>(
func: T,
lifespan: number = 5 * 60 * 1000,
keyDelegate?: (...args: any[]) => string,
): T {
const cache: { [key: string]: { value: S; timestamp: number } } = {};
return ((...args: any[]): S => {
const key: string = (keyDelegate ? keyDelegate(...args) : args?.[0]?.toString()) ?? '';
const now = Date.now();
if (!cache[key] || now - cache[key].timestamp > lifespan) {
cache[key] = {
value: func(...args) as S,
timestamp: now,
};
}
return cache[key].value;
}) as unknown as T;
}