LegendApp / legend-state

Legend-State is a super fast and powerful state library that enables fine-grained reactivity and easy automatic persistence
https://legendapp.com/open-source/state/
MIT License
3.11k stars 88 forks source link

Supabase plugin type issue #345

Open GeekJC opened 4 months ago

GeekJC commented 4 months ago

I tried to setup the syncedSupabase with the documentation. However, it seems like the collection is not regcoising my database interface and show up and type error. Is it just me or i have done something wrong? I am sure "UserInfo" exist in Database type.

Code:

export const supabase = createClient<Database>(
  process.env.EXPO_PUBLIC_SUPABASE_URL,
  process.env.EXPO_PUBLIC__SUPABASE_API_KEY
);

const messages$ = observable(syncedSupabase({
  supabase,
  collection: 'UserInfo',
  // Filter by the current user
  filter: (select) => select.eq('user_id', 'uid')
}))

Error: Screenshot 2024-08-02 at 06 50 30

jmeistrich commented 3 months ago

Is UserInfo in the public schema? That's the only thing I can think of off the top of my head.

Is it possible you can share your supabase types file (where Database is defined) with me so I can try to reproduce it?

GeekJC commented 3 months ago

The database is in public. I am suspecting thats a issue with supabase cli instead but would be very much appreciated if you have any thoughts on that. Please see below. (Note that I changed the table name to user_info on below)

Environment info

Library Version
@legendapp/state ^3.0.0-alpha.27
@supabase/supabase-js ^2.45.0
supabase 1.187.10
typescript ~5.3.3
export type Json =
  | string
  | number
  | boolean
  | null
  | { [key: string]: Json | undefined }
  | Json[]

export type Database = {
  public: {
    Tables: {
      user_info: {
        Row: {
          background_url: string
          bio: string
          birthday: string
          created_at: string
          deleted: boolean
          education: string
          gender: boolean
          icon_url: string
          id: string
          link: string
          location: string
          occupation: string
          show_age: boolean
          show_birthday: boolean
          show_constellation: boolean
          show_education: boolean
          show_gender: boolean
          show_location: boolean
          show_occupation: boolean
          signature: string
          updated_at: string
          user_id: string
          username: string
        }
        Insert: {
          background_url?: string
          bio?: string
          birthday?: string
          created_at?: string
          deleted?: boolean
          education?: string
          gender?: boolean
          icon_url?: string
          id: string
          link?: string
          location?: string
          occupation?: string
          show_age?: boolean
          show_birthday?: boolean
          show_constellation?: boolean
          show_education?: boolean
          show_gender?: boolean
          show_location?: boolean
          show_occupation?: boolean
          signature?: string
          updated_at?: string
          user_id?: string
          username?: string
        }
        Update: {
          background_url?: string
          bio?: string
          birthday?: string
          created_at?: string
          deleted?: boolean
          education?: string
          gender?: boolean
          icon_url?: string
          id?: string
          link?: string
          location?: string
          occupation?: string
          show_age?: boolean
          show_birthday?: boolean
          show_constellation?: boolean
          show_education?: boolean
          show_gender?: boolean
          show_location?: boolean
          show_occupation?: boolean
          signature?: string
          updated_at?: string
          user_id?: string
          username?: string
        }
        Relationships: []
      }
    }
    Views: {
      [_ in never]: never
    }
    Functions: {
      [_ in never]: never
    }
    Enums: {
      [_ in never]: never
    }
    CompositeTypes: {
      [_ in never]: never
    }
  }
}

type PublicSchema = Database[Extract<keyof Database, "public">]

export type Tables<
  PublicTableNameOrOptions extends
    | keyof (PublicSchema["Tables"] & PublicSchema["Views"])
    | { schema: keyof Database },
  TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
    ? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
        Database[PublicTableNameOrOptions["schema"]]["Views"])
    : never = never,
> = PublicTableNameOrOptions extends { schema: keyof Database }
  ? (Database[PublicTableNameOrOptions["schema"]]["Tables"] &
      Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends {
      Row: infer R
    }
    ? R
    : never
  : PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] &
        PublicSchema["Views"])
    ? (PublicSchema["Tables"] &
        PublicSchema["Views"])[PublicTableNameOrOptions] extends {
        Row: infer R
      }
      ? R
      : never
    : never

export type TablesInsert<
  PublicTableNameOrOptions extends
    | keyof PublicSchema["Tables"]
    | { schema: keyof Database },
  TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
    ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
    : never = never,
> = PublicTableNameOrOptions extends { schema: keyof Database }
  ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
      Insert: infer I
    }
    ? I
    : never
  : PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
    ? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
        Insert: infer I
      }
      ? I
      : never
    : never

export type TablesUpdate<
  PublicTableNameOrOptions extends
    | keyof PublicSchema["Tables"]
    | { schema: keyof Database },
  TableName extends PublicTableNameOrOptions extends { schema: keyof Database }
    ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"]
    : never = never,
> = PublicTableNameOrOptions extends { schema: keyof Database }
  ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends {
      Update: infer U
    }
    ? U
    : never
  : PublicTableNameOrOptions extends keyof PublicSchema["Tables"]
    ? PublicSchema["Tables"][PublicTableNameOrOptions] extends {
        Update: infer U
      }
      ? U
      : never
    : never

export type Enums<
  PublicEnumNameOrOptions extends
    | keyof PublicSchema["Enums"]
    | { schema: keyof Database },
  EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database }
    ? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"]
    : never = never,
> = PublicEnumNameOrOptions extends { schema: keyof Database }
  ? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName]
  : PublicEnumNameOrOptions extends keyof PublicSchema["Enums"]
    ? PublicSchema["Enums"][PublicEnumNameOrOptions]
    : never
jmeistrich commented 2 months ago

I think this should be fixed in the latest alpha version. Can you try updating and see if it works better for you?