import { Injectable, Logger, OnModuleInit } from '@nestjs/common'; import { createClient, SupabaseClient } from '@supabase/supabase-js'; @Injectable() export class SupabaseService implements OnModuleInit { private readonly logger = new Logger(SupabaseService.name); private client: SupabaseClient; constructor() { this.initClient(); } onModuleInit() { this.initClient(); } private initClient(): SupabaseClient { if (this.client) return this.client; const supabaseUrl = process.env.SUPABASE_URL || ''; const serviceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY || ''; this.client = createClient(supabaseUrl, serviceRoleKey, { auth: { autoRefreshToken: false, persistSession: false, }, }); this.logger.log( `SupabaseService initialized for project at ${supabaseUrl}`, ); return this.client; } getClient(): SupabaseClient { return this.initClient(); } // Master tracks table (126k+ catalog) get masterTracks() { return this.initClient().from('master_tracks'); } // Application tables get profiles() { return this.client.from('profiles'); } get artists() { return this.client.from('artists'); } get albums() { return this.client.from('albums'); } get tracks() { return this.client.from('tracks'); } get playlists() { return this.client.from('playlists'); } get playlistTracks() { return this.client.from('playlist_tracks'); } get libraryTracks() { return this.client.from('library_tracks'); } get libraryAlbums() { return this.client.from('library_albums'); } get libraryPlaylists() { return this.client.from('library_playlists'); } get follows() { return this.client.from('follows'); } get playHistory() { return this.client.from('play_history'); } get playbackState() { return this.client.from('playback_state'); } get devices() { return this.client.from('devices'); } get lyrics() { return this.client.from('lyrics'); } get notifications() { return this.client.from('notifications'); } }