import type { Database, Tables } from './database.types'; import type { PostgrestError } from '@supabase/postgrest-js'; export type SdkError = { message: string; code?: string; } | PostgrestError; export type SdkResult = { data: T; error: null; } | { data: null; error: SdkError; }; export type { Database }; /** * We have types generated from our database schema (npm run pull-db-types), * however they are not always accurate, so we overwrite them as needed here. */ /** * Base/row types without joins or computed fields */ export type ChannelRow = Omit, 'coordinates'>; export type TrackRow = Tables<'tracks'>; /** * Channel with computed fields */ export type Channel = Omit, 'id' | 'name' | 'slug' | 'created_at' | 'updated_at' | 'coordinates' | 'fts' | 'track_count' | 'latest_track_at'> & { id: string; name: string; slug: string; created_at: string; updated_at: string; fts?: string | null; track_count?: number | null; latest_track_at?: string | null; source?: 'v1' | 'v2'; }; /** * Track from the channel_tracks view (includes channel slug) * Note: id/title/url/created_at are overridden as non-null because the tracks * table has NOT NULL constraints, but Postgres views lose that type information. */ export type Track = Omit, 'id' | 'title' | 'url' | 'created_at' | 'updated_at' | 'media_id' | 'provider'> & { id: string; title: string; url: string; created_at: string; updated_at: string; media_id?: string | null; provider?: string | null; channel_id?: string; source?: 'v1' | 'v2'; }; /** * Broadcast (live radio state) */ export type BroadcastRow = Tables<'broadcast'>; export interface BroadcastDeckState { index: number; track_id: string | null; track_played_at: string | null; is_playing: boolean; seeked_at: string | null; seek_position: number | null; volume: number; muted: boolean; speed: number; } /** Broadcast with typed decks jsonb */ export type Broadcast = Omit & { decks?: BroadcastDeckState[] | null; }; export interface UpdateBroadcastParams { track_id?: string | null; track_played_at?: string; decks?: BroadcastDeckState[]; } export type ChannelBackup = { version: 2; created_at: string; channel: Channel; tracks: Track[]; }; export interface CreateChannelParams { /** Optional client-side UUID. If omitted, Postgres generates one. */ id?: string; name: string; slug: string; /** Owner user ID. If omitted, uses current session user. */ userId?: string; description?: string; url?: string; latitude?: number; longitude?: number; } export interface UpdateChannelParams { name?: string; slug?: string; description?: string; url?: string; /** Cloudinary image URL. Set to null to remove. */ image?: string | null; latitude?: number; longitude?: number; } export interface CreateTrackParams { /** Optional client-side UUID. If omitted, Postgres generates one. */ id?: string; title: string; url: string; description?: string; discogs_url?: string; } export interface UpdateTrackParams { title?: string; url?: string; description?: string; discogs_url?: string; /** Error message if playback failed */ playback_error?: string; /** Duration in seconds */ duration?: number; }