From d94302ab1aca0cc6bcdeae906e28a56b126a7668 Mon Sep 17 00:00:00 2001 From: Pontus Abrahamsson Date: Fri, 29 Dec 2023 10:47:08 +0100 Subject: [PATCH] Fix query --- .../actions/connect-bank-account-action.ts | 21 +- packages/gocardless/src/index.ts | 1 - .../supabase/src/queries/cached-queries.ts | 2 +- packages/supabase/src/queries/index.ts | 43 +- packages/supabase/src/types/db.ts | 816 ++++++++++-------- 5 files changed, 481 insertions(+), 402 deletions(-) diff --git a/apps/dashboard/src/actions/connect-bank-account-action.ts b/apps/dashboard/src/actions/connect-bank-account-action.ts index 5d6e4d4063..ea598f9bd2 100644 --- a/apps/dashboard/src/actions/connect-bank-account-action.ts +++ b/apps/dashboard/src/actions/connect-bank-account-action.ts @@ -1,7 +1,7 @@ "use server"; import { getTransactions, transformTransactions } from "@midday/gocardless"; -import { Events, scheduler } from "@midday/jobs"; +import { scheduler } from "@midday/jobs"; import { getUser } from "@midday/supabase/cached-queries"; import { createBankAccounts } from "@midday/supabase/mutations"; import { createClient } from "@midday/supabase/server"; @@ -18,7 +18,7 @@ export const connectBankAccountAction = action( const { data } = await createBankAccounts(supabase, accounts); - const promisses = data?.map(async (account) => { + const promises = data?.map(async (account) => { // Fetch transactions for each account const { transactions } = await getTransactions(account.account_id); @@ -31,15 +31,12 @@ export const connectBankAccountAction = action( .eq("id", account.id); // Create transactions - await supabase - .from("transactions") - .insert( - transformTransactions(transactions?.booked, { - accountId: account.id, // Bank account row id - teamId, - }) - ) - .select(); + await supabase.from("transactions").insert( + transformTransactions(transactions?.booked, { + accountId: account.id, // Bank account row id + teamId, + }) + ); // Schedule sync for each account await scheduler.register(account.id, { @@ -52,7 +49,7 @@ export const connectBankAccountAction = action( return; }); - await Promise.all(promisses); + await Promise.all(promises); revalidateTag(`bank_connections_${teamId}`); revalidateTag(`transactions_${teamId}`); diff --git a/packages/gocardless/src/index.ts b/packages/gocardless/src/index.ts index 700bcfe1c6..4f91290020 100644 --- a/packages/gocardless/src/index.ts +++ b/packages/gocardless/src/index.ts @@ -320,7 +320,6 @@ export const transformTransactions = (transactions, { teamId, accountId }) => { return { transaction_id: data.transactionId, reference: data.entryReference, - booking_date: data.bookingDate, date: data.valueDate, name: capitalCase(data.additionalInformation), original: data.additionalInformation, diff --git a/packages/supabase/src/queries/cached-queries.ts b/packages/supabase/src/queries/cached-queries.ts index 6951954f40..45d144f4a9 100644 --- a/packages/supabase/src/queries/cached-queries.ts +++ b/packages/supabase/src/queries/cached-queries.ts @@ -201,7 +201,7 @@ export const getTeams = async () => { ["teams", userId], { tags: [`teams_${userId}`], - revalidate: 10, + revalidate: 180, } )(); }; diff --git a/packages/supabase/src/queries/index.ts b/packages/supabase/src/queries/index.ts index 2202887018..5592ff67c7 100644 --- a/packages/supabase/src/queries/index.ts +++ b/packages/supabase/src/queries/index.ts @@ -135,8 +135,7 @@ export async function getSpendingQuery( ` currency, category, - amount, - enrichment:enrichment_id(category) + amount ` ) .order("order", { ascending: false }) @@ -157,9 +156,9 @@ export async function getSpendingQuery( const combinedValues = {}; for (const item of data) { - const { category, amount, currency, enrichment } = item; + const { category, amount, currency } = item; - const key = category || enrichment?.category || "uncategorized"; + const key = category || "uncategorized"; if (combinedValues[key]) { combinedValues[key].amount += amount; @@ -175,11 +174,9 @@ export async function getSpendingQuery( currency: data?.at(0)?.currency, }, data: Object.entries(combinedValues) - .map(([category, { amount, currency, enrichment }]) => { + .map(([category, { amount, currency }]) => { return { - category: !category - ? "uncategorized" - : category || enrichment?.category, + category: category || "uncategorized", currency, amount: +Math.abs(amount).toFixed(2), }; @@ -229,7 +226,6 @@ export async function getTransactionsQuery( ` *, assigned:assigned_id(*), - enrichment:transaction_enrichments(category), attachments(*) `, { count: "exact" } @@ -272,22 +268,20 @@ export async function getTransactionsQuery( ` *, assigned:assigned_id(*), - enrichment:transaction_enrichments!inner(category), attachments(*) ` ); const matchCategory = categories - .map((category) => `category.eq.${category}`) + .map((category) => { + if (category === "uncategorized") { + return "category.is.null"; + } + return `category.eq.${category}`; + }) .join(","); - query - // .or(matchCategory) - .or(matchCategory, { referencedTable: "enrichment" }); - } - - if (categories?.includes("uncategorized")) { - query.not("category", "is", null); + query.or(matchCategory); } if (type === "expense") { @@ -296,8 +290,7 @@ export async function getTransactionsQuery( } if (type === "income") { - query.gt("amount", 0); - query.neq("category", "transfer"); + query.eq("category", "income"); } const { data, count } = await query.range(from, to).throwOnError(); @@ -327,10 +320,7 @@ export async function getTransactionsQuery( }, data: data?.map((transaction) => ({ ...transaction, - category: - transaction?.category || - transaction?.enrichment?.category || - "uncategorized", + category: transaction?.category || "uncategorized", })), }; } @@ -342,7 +332,6 @@ export async function getTransactionQuery(supabase: Client, id: string) { ` *, assigned:assigned_id(*), - enrichment:enrichment_id(category), attachments(*) ` ) @@ -352,7 +341,7 @@ export async function getTransactionQuery(supabase: Client, id: string) { return { ...data, - category: data?.category || data?.enrichment?.category || "uncategorized", + category: data?.category || "uncategorized", }; } @@ -409,7 +398,7 @@ export async function getMetricsQuery( .neq("category", "transfer"); if (type === "income") { - query.gt("amount", 0); + query.eq("category", "income"); } const { data } = await query.throwOnError(); diff --git a/packages/supabase/src/types/db.ts b/packages/supabase/src/types/db.ts index d679f5dedd..83caa1b9ee 100644 --- a/packages/supabase/src/types/db.ts +++ b/packages/supabase/src/types/db.ts @@ -4,448 +4,460 @@ export type Json = | boolean | null | { [key: string]: Json | undefined } - | Json[]; + | Json[] export interface Database { public: { Tables: { attachments: { Row: { - created_at: string; - id: string; - name: string | null; - path: string | null; - size: number | null; - team_id: string | null; - transaction_id: string | null; - type: string | null; - }; + created_at: string + id: string + name: string | null + path: string | null + size: number | null + team_id: string | null + transaction_id: string | null + type: string | null + } Insert: { - created_at?: string; - id?: string; - name?: string | null; - path?: string | null; - size?: number | null; - team_id?: string | null; - transaction_id?: string | null; - type?: string | null; - }; + created_at?: string + id?: string + name?: string | null + path?: string | null + size?: number | null + team_id?: string | null + transaction_id?: string | null + type?: string | null + } Update: { - created_at?: string; - id?: string; - name?: string | null; - path?: string | null; - size?: number | null; - team_id?: string | null; - transaction_id?: string | null; - type?: string | null; - }; + created_at?: string + id?: string + name?: string | null + path?: string | null + size?: number | null + team_id?: string | null + transaction_id?: string | null + type?: string | null + } Relationships: [ { - foreignKeyName: "attachments_team_id_fkey"; - columns: ["team_id"]; - isOneToOne: false; - referencedRelation: "teams"; - referencedColumns: ["id"]; + foreignKeyName: "attachments_team_id_fkey" + columns: ["team_id"] + isOneToOne: false + referencedRelation: "teams" + referencedColumns: ["id"] }, { - foreignKeyName: "attachments_transaction_id_fkey"; - columns: ["transaction_id"]; - isOneToOne: false; - referencedRelation: "transactions"; - referencedColumns: ["id"]; + foreignKeyName: "attachments_transaction_id_fkey" + columns: ["transaction_id"] + isOneToOne: false + referencedRelation: "transactions" + referencedColumns: ["id"] } - ]; - }; + ] + } bank_accounts: { Row: { - account_id: string; - bank_connection_id: string | null; - bban: string | null; - bic: string | null; - created_at: string; - created_by: string; - currency: string | null; - iban: string | null; - id: string; - last_accessed: string | null; - name: string | null; - owner_name: string | null; - team_id: string | null; - }; + account_id: string + bank_connection_id: string | null + bban: string | null + bic: string | null + created_at: string + created_by: string + currency: string | null + iban: string | null + id: string + last_accessed: string | null + name: string | null + owner_name: string | null + team_id: string | null + } Insert: { - account_id: string; - bank_connection_id?: string | null; - bban?: string | null; - bic?: string | null; - created_at?: string; - created_by: string; - currency?: string | null; - iban?: string | null; - id?: string; - last_accessed?: string | null; - name?: string | null; - owner_name?: string | null; - team_id?: string | null; - }; + account_id: string + bank_connection_id?: string | null + bban?: string | null + bic?: string | null + created_at?: string + created_by: string + currency?: string | null + iban?: string | null + id?: string + last_accessed?: string | null + name?: string | null + owner_name?: string | null + team_id?: string | null + } Update: { - account_id?: string; - bank_connection_id?: string | null; - bban?: string | null; - bic?: string | null; - created_at?: string; - created_by?: string; - currency?: string | null; - iban?: string | null; - id?: string; - last_accessed?: string | null; - name?: string | null; - owner_name?: string | null; - team_id?: string | null; - }; + account_id?: string + bank_connection_id?: string | null + bban?: string | null + bic?: string | null + created_at?: string + created_by?: string + currency?: string | null + iban?: string | null + id?: string + last_accessed?: string | null + name?: string | null + owner_name?: string | null + team_id?: string | null + } Relationships: [ { - foreignKeyName: "bank_accounts_bank_connection_id_fkey"; - columns: ["bank_connection_id"]; - isOneToOne: false; - referencedRelation: "bank_connections"; - referencedColumns: ["id"]; + foreignKeyName: "bank_accounts_bank_connection_id_fkey" + columns: ["bank_connection_id"] + isOneToOne: false + referencedRelation: "bank_connections" + referencedColumns: ["id"] }, { - foreignKeyName: "bank_accounts_created_by_fkey"; - columns: ["created_by"]; - isOneToOne: false; - referencedRelation: "users"; - referencedColumns: ["id"]; + foreignKeyName: "bank_accounts_created_by_fkey" + columns: ["created_by"] + isOneToOne: false + referencedRelation: "users" + referencedColumns: ["id"] }, { - foreignKeyName: "bank_accounts_team_id_fkey"; - columns: ["team_id"]; - isOneToOne: false; - referencedRelation: "teams"; - referencedColumns: ["id"]; + foreignKeyName: "bank_accounts_team_id_fkey" + columns: ["team_id"] + isOneToOne: false + referencedRelation: "teams" + referencedColumns: ["id"] } - ]; - }; + ] + } bank_connections: { Row: { - created_at: string; - expires_at: string | null; - id: string; - institution_id: string | null; - logo_url: string | null; - name: string | null; - provider: Database["public"]["Enums"]["bankProviders"] | null; - team_id: string | null; - }; + created_at: string + expires_at: string | null + id: string + institution_id: string | null + logo_url: string | null + name: string | null + provider: Database["public"]["Enums"]["bankProviders"] | null + team_id: string | null + } Insert: { - created_at?: string; - expires_at?: string | null; - id?: string; - institution_id?: string | null; - logo_url?: string | null; - name?: string | null; - provider?: Database["public"]["Enums"]["bankProviders"] | null; - team_id?: string | null; - }; + created_at?: string + expires_at?: string | null + id?: string + institution_id?: string | null + logo_url?: string | null + name?: string | null + provider?: Database["public"]["Enums"]["bankProviders"] | null + team_id?: string | null + } Update: { - created_at?: string; - expires_at?: string | null; - id?: string; - institution_id?: string | null; - logo_url?: string | null; - name?: string | null; - provider?: Database["public"]["Enums"]["bankProviders"] | null; - team_id?: string | null; - }; + created_at?: string + expires_at?: string | null + id?: string + institution_id?: string | null + logo_url?: string | null + name?: string | null + provider?: Database["public"]["Enums"]["bankProviders"] | null + team_id?: string | null + } Relationships: [ { - foreignKeyName: "bank_connections_team_id_fkey"; - columns: ["team_id"]; - isOneToOne: false; - referencedRelation: "teams"; - referencedColumns: ["id"]; + foreignKeyName: "bank_connections_team_id_fkey" + columns: ["team_id"] + isOneToOne: false + referencedRelation: "teams" + referencedColumns: ["id"] } - ]; - }; + ] + } teams: { Row: { - created_at: string; - id: string; - logo_url: string | null; - name: string | null; - }; + created_at: string + id: string + logo_url: string | null + name: string | null + } Insert: { - created_at?: string; - id?: string; - logo_url?: string | null; - name?: string | null; - }; + created_at?: string + id?: string + logo_url?: string | null + name?: string | null + } Update: { - created_at?: string; - id?: string; - logo_url?: string | null; - name?: string | null; - }; - Relationships: []; - }; + created_at?: string + id?: string + logo_url?: string | null + name?: string | null + } + Relationships: [] + } transaction_enrichments: { Row: { - category: Database["public"]["Enums"]["transactionCategories"]; - created_at: string; - id: string; - name: string | null; - }; + category: Database["public"]["Enums"]["transactionCategories"] + created_at: string + created_by: string | null + id: string + name: string | null + } Insert: { - category: Database["public"]["Enums"]["transactionCategories"]; - created_at?: string; - id?: string; - name?: string | null; - }; + category: Database["public"]["Enums"]["transactionCategories"] + created_at?: string + created_by?: string | null + id?: string + name?: string | null + } Update: { - category?: Database["public"]["Enums"]["transactionCategories"]; - created_at?: string; - id?: string; - name?: string | null; - }; - Relationships: []; - }; + category?: Database["public"]["Enums"]["transactionCategories"] + created_at?: string + created_by?: string | null + id?: string + name?: string | null + } + Relationships: [ + { + foreignKeyName: "transaction_enrichments_created_by_fkey" + columns: ["created_by"] + isOneToOne: false + referencedRelation: "users" + referencedColumns: ["id"] + } + ] + } transactions: { Row: { - amount: number | null; - assigned_id: string | null; - bank_account_id: string | null; - booking_date: string | null; - category: Database["public"]["Enums"]["transactionCategories"] | null; - created_at: string; - currency: string | null; - date: string | null; - id: string; - internal_id: string | null; - method: Database["public"]["Enums"]["transactionMethods"] | null; - name: string | null; - note: string | null; - order: number; - original: string | null; - reference: string; - team_id: string | null; - transaction_id: string; - }; + amount: number + assigned_id: string | null + bank_account_id: string | null + category: Database["public"]["Enums"]["transactionCategories"] | null + created_at: string + currency: string + date: string + id: string + internal_id: string + method: Database["public"]["Enums"]["transactionMethods"] + name: string + note: string | null + order: number + original: string + reference: string + team_id: string + transaction_id: string + } Insert: { - amount?: number | null; - assigned_id?: string | null; - bank_account_id?: string | null; - booking_date?: string | null; - category?: - | Database["public"]["Enums"]["transactionCategories"] - | null; - created_at?: string; - currency?: string | null; - date?: string | null; - id?: string; - internal_id?: string | null; - method?: Database["public"]["Enums"]["transactionMethods"] | null; - name?: string | null; - note?: string | null; - order?: number; - original?: string | null; - reference: string; - team_id?: string | null; - transaction_id: string; - }; + amount: number + assigned_id?: string | null + bank_account_id?: string | null + category?: Database["public"]["Enums"]["transactionCategories"] | null + created_at?: string + currency: string + date: string + id?: string + internal_id: string + method: Database["public"]["Enums"]["transactionMethods"] + name: string + note?: string | null + order?: number + original: string + reference: string + team_id: string + transaction_id: string + } Update: { - amount?: number | null; - assigned_id?: string | null; - bank_account_id?: string | null; - booking_date?: string | null; - category?: - | Database["public"]["Enums"]["transactionCategories"] - | null; - created_at?: string; - currency?: string | null; - date?: string | null; - id?: string; - internal_id?: string | null; - method?: Database["public"]["Enums"]["transactionMethods"] | null; - name?: string | null; - note?: string | null; - order?: number; - original?: string | null; - reference?: string; - team_id?: string | null; - transaction_id?: string; - }; + amount?: number + assigned_id?: string | null + bank_account_id?: string | null + category?: Database["public"]["Enums"]["transactionCategories"] | null + created_at?: string + currency?: string + date?: string + id?: string + internal_id?: string + method?: Database["public"]["Enums"]["transactionMethods"] + name?: string + note?: string | null + order?: number + original?: string + reference?: string + team_id?: string + transaction_id?: string + } Relationships: [ { - foreignKeyName: "transactions_assigned_id_fkey"; - columns: ["assigned_id"]; - isOneToOne: false; - referencedRelation: "users"; - referencedColumns: ["id"]; + foreignKeyName: "transactions_assigned_id_fkey" + columns: ["assigned_id"] + isOneToOne: false + referencedRelation: "users" + referencedColumns: ["id"] }, { - foreignKeyName: "transactions_bank_account_id_fkey"; - columns: ["bank_account_id"]; - isOneToOne: false; - referencedRelation: "bank_accounts"; - referencedColumns: ["id"]; + foreignKeyName: "transactions_bank_account_id_fkey" + columns: ["bank_account_id"] + isOneToOne: false + referencedRelation: "bank_accounts" + referencedColumns: ["id"] }, { - foreignKeyName: "transactions_team_id_fkey"; - columns: ["team_id"]; - isOneToOne: false; - referencedRelation: "teams"; - referencedColumns: ["id"]; + foreignKeyName: "transactions_team_id_fkey" + columns: ["team_id"] + isOneToOne: false + referencedRelation: "teams" + referencedColumns: ["id"] } - ]; - }; + ] + } users: { Row: { - avatar_url: string | null; - created_at: string | null; - email: string | null; - full_name: string | null; - id: string; - locale: string | null; - team_id: string | null; - }; + avatar_url: string | null + created_at: string | null + email: string | null + full_name: string | null + id: string + locale: string | null + team_id: string | null + } Insert: { - avatar_url?: string | null; - created_at?: string | null; - email?: string | null; - full_name?: string | null; - id: string; - locale?: string | null; - team_id?: string | null; - }; + avatar_url?: string | null + created_at?: string | null + email?: string | null + full_name?: string | null + id: string + locale?: string | null + team_id?: string | null + } Update: { - avatar_url?: string | null; - created_at?: string | null; - email?: string | null; - full_name?: string | null; - id?: string; - locale?: string | null; - team_id?: string | null; - }; + avatar_url?: string | null + created_at?: string | null + email?: string | null + full_name?: string | null + id?: string + locale?: string | null + team_id?: string | null + } Relationships: [ { - foreignKeyName: "users_id_fkey"; - columns: ["id"]; - isOneToOne: true; - referencedRelation: "users"; - referencedColumns: ["id"]; + foreignKeyName: "users_id_fkey" + columns: ["id"] + isOneToOne: true + referencedRelation: "users" + referencedColumns: ["id"] }, { - foreignKeyName: "users_team_id_fkey"; - columns: ["team_id"]; - isOneToOne: false; - referencedRelation: "teams"; - referencedColumns: ["id"]; + foreignKeyName: "users_team_id_fkey" + columns: ["team_id"] + isOneToOne: false + referencedRelation: "teams" + referencedColumns: ["id"] } - ]; - }; + ] + } users_on_team: { Row: { - id: string; - role: Database["public"]["Enums"]["teamRoles"] | null; - team_id: string; - user_id: string; - }; + id: string + role: Database["public"]["Enums"]["teamRoles"] | null + team_id: string + user_id: string + } Insert: { - id?: string; - role?: Database["public"]["Enums"]["teamRoles"] | null; - team_id: string; - user_id: string; - }; + id?: string + role?: Database["public"]["Enums"]["teamRoles"] | null + team_id: string + user_id: string + } Update: { - id?: string; - role?: Database["public"]["Enums"]["teamRoles"] | null; - team_id?: string; - user_id?: string; - }; + id?: string + role?: Database["public"]["Enums"]["teamRoles"] | null + team_id?: string + user_id?: string + } Relationships: [ { - foreignKeyName: "users_on_team_team_id_fkey"; - columns: ["team_id"]; - isOneToOne: false; - referencedRelation: "teams"; - referencedColumns: ["id"]; + foreignKeyName: "users_on_team_team_id_fkey" + columns: ["team_id"] + isOneToOne: false + referencedRelation: "teams" + referencedColumns: ["id"] }, { - foreignKeyName: "users_on_team_user_id_fkey"; - columns: ["user_id"]; - isOneToOne: false; - referencedRelation: "users"; - referencedColumns: ["id"]; + foreignKeyName: "users_on_team_user_id_fkey" + columns: ["user_id"] + isOneToOne: false + referencedRelation: "users" + referencedColumns: ["id"] } - ]; - }; - }; + ] + } + } Views: { - [_ in never]: never; - }; + [_ in never]: never + } Functions: { gtrgm_compress: { Args: { - "": unknown; - }; - Returns: unknown; - }; + "": unknown + } + Returns: unknown + } gtrgm_decompress: { Args: { - "": unknown; - }; - Returns: unknown; - }; + "": unknown + } + Returns: unknown + } gtrgm_in: { Args: { - "": unknown; - }; - Returns: unknown; - }; + "": unknown + } + Returns: unknown + } gtrgm_options: { Args: { - "": unknown; - }; - Returns: undefined; - }; + "": unknown + } + Returns: undefined + } gtrgm_out: { Args: { - "": unknown; - }; - Returns: unknown; - }; + "": unknown + } + Returns: unknown + } + nanoid: { + Args: { + size?: number + alphabet?: string + } + Returns: string + } search_enriched_transactions: { Args: { - term: string; - }; + term: string + } Returns: { - category: Database["public"]["Enums"]["transactionCategories"]; - created_at: string; - id: string; - name: string | null; - }[]; - }; + category: Database["public"]["Enums"]["transactionCategories"] + created_at: string + created_by: string | null + id: string + name: string | null + }[] + } set_limit: { Args: { - "": number; - }; - Returns: number; - }; + "": number + } + Returns: number + } show_limit: { - Args: Record; - Returns: number; - }; + Args: Record + Returns: number + } show_trgm: { Args: { - "": string; - }; - Returns: unknown; - }; - }; + "": string + } + Returns: unknown + } + } Enums: { - bankProviders: "gocardless" | "plaid"; - teamRoles: "admin" | "member"; + bankProviders: "gocardless" | "plaid" + teamRoles: "admin" | "member" transactionCategories: | "office_supplies" | "travel" @@ -458,18 +470,100 @@ export interface Database { | "activity" | "uncategorized" | "taxes" - | "other"; + | "other" + | "internet_and_telephone" + | "facilities_expenses" transactionMethods: | "payment" | "card_purchase" | "card_atm" | "transfer" - | "other"; - transactionStatus: "booked" | "pending"; - vatRates: "25" | "12" | "6" | "0"; - }; + | "other" + transactionStatus: "booked" | "pending" + vatRates: "25" | "12" | "6" | "0" + } CompositeTypes: { - [_ in never]: never; - }; - }; + [_ in never]: never + } + } } + +export type Tables< + PublicTableNameOrOptions extends + | keyof (Database["public"]["Tables"] & Database["public"]["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 (Database["public"]["Tables"] & + Database["public"]["Views"]) + ? (Database["public"]["Tables"] & + Database["public"]["Views"])[PublicTableNameOrOptions] extends { + Row: infer R + } + ? R + : never + : never + +export type TablesInsert< + PublicTableNameOrOptions extends + | keyof Database["public"]["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 Database["public"]["Tables"] + ? Database["public"]["Tables"][PublicTableNameOrOptions] extends { + Insert: infer I + } + ? I + : never + : never + +export type TablesUpdate< + PublicTableNameOrOptions extends + | keyof Database["public"]["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 Database["public"]["Tables"] + ? Database["public"]["Tables"][PublicTableNameOrOptions] extends { + Update: infer U + } + ? U + : never + : never + +export type Enums< + PublicEnumNameOrOptions extends + | keyof Database["public"]["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 Database["public"]["Enums"] + ? Database["public"]["Enums"][PublicEnumNameOrOptions] + : never