Triviaverse / src /lib /supabase /client.ts
Simeon Garratt
feat: remove Supabase, bundle questions locally, use JSON DB + API
ad111f4
Raw
History Blame Contribute Delete
2.42 kB
/**
* Supabase compatibility layer — all queries now use the local API.
*
* The `isSupabaseConfigured` constant is kept for backward compatibility
* and is always true since there is no external dependency anymore.
*/
export const isSupabaseConfigured = true;
/**
* @deprecated All database operations now go through /api/db or /api/questions.
* This export exists only to prevent import errors during migration.
*/
export const supabase = null as unknown as ReturnType<typeof createFakeSupabase>;
type FakeSupabase = {
channel: (name: string) => {
on: () => any;
subscribe: () => any;
track: () => Promise<void>;
untrack: () => Promise<void>;
presenceState: () => Record<string, any>;
send: () => void;
};
removeChannel: (c: any) => Promise<void>;
from: (table: string) => {
select: (...args: any[]) => any;
insert: (...args: any[]) => any;
update: (...args: any[]) => any;
delete: () => any;
eq: (...args: any[]) => any;
is: (...args: any[]) => any;
order: (...args: any[]) => any;
limit: (n: number) => any;
single: () => any;
in: (...args: any[]) => any;
not: (...args: any[]) => any;
gt: (...args: any[]) => any;
or: (...args: any[]) => any;
};
rpc: (...args: any[]) => Promise<{ data: any; error: any }>;
};
function createFakeSupabase(): FakeSupabase {
const chainable = (result: any = null) => ({
select: () => chainable(result),
insert: () => chainable(result),
update: () => chainable(result),
delete: () => chainable({ data: null, error: null }),
eq: () => chainable(result),
is: () => chainable(result),
order: () => chainable(result),
limit: () => chainable(result),
single: () => chainable(result),
in: () => chainable(result),
not: () => chainable(result),
gt: () => chainable(result),
or: () => chainable(result),
then: (resolve: any) => resolve({ data: [], error: null, count: 0 }),
catch: () => {},
});
const channel = (name: string) => ({
on: () => channel(name),
subscribe: () => {},
track: () => Promise.resolve(),
untrack: () => Promise.resolve(),
presenceState: () => ({}),
send: () => {},
});
return {
channel,
removeChannel: () => Promise.resolve(),
from: () => chainable(),
rpc: () => Promise.resolve({ data: null, error: new Error("Supabase removed") }),
};
}