code:
const cachableUserSource = <T>(table: string, key: string) => ({
cache: flru<T>(100),
getUser: async function (query: string) {
const user = this.cache.get(query);
if (user) return user;
const { data, error } = await supabase.from(table).select("*").eq(key, query).single();
if (error) throw error;
this.cache.set(query, data);
return data;
},
addUser: async function (user: T, insert: boolean) {
const { data, error } = insert
? await supabase.from(table).insert(user).select().single()
: await supabase.from(table).upsert(user).select().single();
if (error) throw error;
this.cache.set(user[key], data);
return data;
},
});
the line this.cache.set(user[key], data); is erroring because ts doesn't know that user[key] will be a string