From 5e9b57423fe5b8b5ae7c417c5d7098e433abb144 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Wed, 5 Jul 2023 09:07:56 +0200 Subject: [PATCH] fix: relationship types --- .changeset/soft-birds-brush.md | 8 + examples/react-query/types/database.ts | 70 +++- examples/swr/types/database.ts | 70 +++- package.json | 2 +- .../__tests__/database.types.ts | 319 ++++++++++++++++-- packages/postgrest-fetcher/src/delete.ts | 11 +- packages/postgrest-fetcher/src/insert.ts | 13 +- .../src/pagination-fetcher.ts | 5 +- packages/postgrest-fetcher/src/update.ts | 11 +- packages/postgrest-fetcher/src/upsert.ts | 11 +- .../__tests__/database.types.ts | 319 ++++++++++++++++-- .../src/mutate/use-delete-mutation.ts | 24 +- .../src/mutate/use-insert-mutation.ts | 13 +- .../src/mutate/use-update-mutation.ts | 24 +- .../src/mutate/use-upsert-mutation.ts | 13 +- .../postgrest-swr/__tests__/database.types.ts | 319 ++++++++++++++++-- .../src/mutate/use-delete-mutation.ts | 24 +- .../src/mutate/use-insert-mutation.ts | 10 +- .../src/mutate/use-update-mutation.ts | 24 +- .../src/mutate/use-upsert-mutation.ts | 10 +- .../src/query/use-infinite-query.ts | 10 +- .../src/query/use-infinite-scroll-query.ts | 10 +- .../src/subscribe/use-subscription-query.ts | 10 +- 23 files changed, 1106 insertions(+), 224 deletions(-) create mode 100644 .changeset/soft-birds-brush.md diff --git a/.changeset/soft-birds-brush.md b/.changeset/soft-birds-brush.md new file mode 100644 index 000000000..09887329c --- /dev/null +++ b/.changeset/soft-birds-brush.md @@ -0,0 +1,8 @@ +--- +"@supabase-cache-helpers/postgrest-react-query": patch +"@supabase-cache-helpers/postgrest-fetcher": patch +"@supabase-cache-helpers/postgrest-filter": patch +"@supabase-cache-helpers/postgrest-swr": patch +--- + +fix: relationship types diff --git a/examples/react-query/types/database.ts b/examples/react-query/types/database.ts index f8c374716..845e8ed30 100644 --- a/examples/react-query/types/database.ts +++ b/examples/react-query/types/database.ts @@ -47,7 +47,7 @@ export interface Database { tags: string[] | null ticket_number: number | null username: string | null - has_low_ticket_number: boolean | null + has_low_ticket_number: unknown | null } Insert: { age_range?: unknown | null @@ -75,6 +75,20 @@ export interface Database { ticket_number?: number | null username?: string | null } + Relationships: [ + { + foreignKeyName: "contact_continent_fkey" + columns: ["continent"] + referencedRelation: "continent" + referencedColumns: ["code"] + }, + { + foreignKeyName: "contact_country_fkey" + columns: ["country"] + referencedRelation: "country" + referencedColumns: ["code"] + } + ] } contact_note: { Row: { @@ -95,6 +109,14 @@ export interface Database { id?: string text?: string } + Relationships: [ + { + foreignKeyName: "contact_note_contact_id_fkey" + columns: ["contact_id"] + referencedRelation: "contact" + referencedColumns: ["id"] + } + ] } continent: { Row: { @@ -109,6 +131,7 @@ export interface Database { code?: string name?: string | null } + Relationships: [] } country: { Row: { @@ -135,6 +158,14 @@ export interface Database { name?: string number?: string } + Relationships: [ + { + foreignKeyName: "country_continent_code_fkey" + columns: ["continent_code"] + referencedRelation: "continent" + referencedColumns: ["code"] + } + ] } } Views: { @@ -191,6 +222,14 @@ export interface Database { public?: boolean | null updated_at?: string | null } + Relationships: [ + { + foreignKeyName: "buckets_owner_fkey" + columns: ["owner"] + referencedRelation: "users" + referencedColumns: ["id"] + } + ] } migrations: { Row: { @@ -211,6 +250,7 @@ export interface Database { id?: number name?: string } + Relationships: [] } objects: { Row: { @@ -223,6 +263,7 @@ export interface Database { owner: string | null path_tokens: string[] | null updated_at: string | null + version: string | null } Insert: { bucket_id?: string | null @@ -234,6 +275,7 @@ export interface Database { owner?: string | null path_tokens?: string[] | null updated_at?: string | null + version?: string | null } Update: { bucket_id?: string | null @@ -245,13 +287,37 @@ export interface Database { owner?: string | null path_tokens?: string[] | null updated_at?: string | null + version?: string | null } + Relationships: [ + { + foreignKeyName: "objects_bucketId_fkey" + columns: ["bucket_id"] + referencedRelation: "buckets" + referencedColumns: ["id"] + }, + { + foreignKeyName: "objects_owner_fkey" + columns: ["owner"] + referencedRelation: "users" + referencedColumns: ["id"] + } + ] } } Views: { [_ in never]: never } Functions: { + can_insert_object: { + Args: { + bucketid: string + name: string + owner: string + metadata: Json + } + Returns: undefined + } extension: { Args: { name: string @@ -268,7 +334,7 @@ export interface Database { Args: { name: string } - Returns: string[] + Returns: unknown } get_size_by_bucket: { Args: Record diff --git a/examples/swr/types/database.ts b/examples/swr/types/database.ts index f8c374716..845e8ed30 100644 --- a/examples/swr/types/database.ts +++ b/examples/swr/types/database.ts @@ -47,7 +47,7 @@ export interface Database { tags: string[] | null ticket_number: number | null username: string | null - has_low_ticket_number: boolean | null + has_low_ticket_number: unknown | null } Insert: { age_range?: unknown | null @@ -75,6 +75,20 @@ export interface Database { ticket_number?: number | null username?: string | null } + Relationships: [ + { + foreignKeyName: "contact_continent_fkey" + columns: ["continent"] + referencedRelation: "continent" + referencedColumns: ["code"] + }, + { + foreignKeyName: "contact_country_fkey" + columns: ["country"] + referencedRelation: "country" + referencedColumns: ["code"] + } + ] } contact_note: { Row: { @@ -95,6 +109,14 @@ export interface Database { id?: string text?: string } + Relationships: [ + { + foreignKeyName: "contact_note_contact_id_fkey" + columns: ["contact_id"] + referencedRelation: "contact" + referencedColumns: ["id"] + } + ] } continent: { Row: { @@ -109,6 +131,7 @@ export interface Database { code?: string name?: string | null } + Relationships: [] } country: { Row: { @@ -135,6 +158,14 @@ export interface Database { name?: string number?: string } + Relationships: [ + { + foreignKeyName: "country_continent_code_fkey" + columns: ["continent_code"] + referencedRelation: "continent" + referencedColumns: ["code"] + } + ] } } Views: { @@ -191,6 +222,14 @@ export interface Database { public?: boolean | null updated_at?: string | null } + Relationships: [ + { + foreignKeyName: "buckets_owner_fkey" + columns: ["owner"] + referencedRelation: "users" + referencedColumns: ["id"] + } + ] } migrations: { Row: { @@ -211,6 +250,7 @@ export interface Database { id?: number name?: string } + Relationships: [] } objects: { Row: { @@ -223,6 +263,7 @@ export interface Database { owner: string | null path_tokens: string[] | null updated_at: string | null + version: string | null } Insert: { bucket_id?: string | null @@ -234,6 +275,7 @@ export interface Database { owner?: string | null path_tokens?: string[] | null updated_at?: string | null + version?: string | null } Update: { bucket_id?: string | null @@ -245,13 +287,37 @@ export interface Database { owner?: string | null path_tokens?: string[] | null updated_at?: string | null + version?: string | null } + Relationships: [ + { + foreignKeyName: "objects_bucketId_fkey" + columns: ["bucket_id"] + referencedRelation: "buckets" + referencedColumns: ["id"] + }, + { + foreignKeyName: "objects_owner_fkey" + columns: ["owner"] + referencedRelation: "users" + referencedColumns: ["id"] + } + ] } } Views: { [_ in never]: never } Functions: { + can_insert_object: { + Args: { + bucketid: string + name: string + owner: string + metadata: Json + } + Returns: undefined + } extension: { Args: { name: string @@ -268,7 +334,7 @@ export interface Database { Args: { name: string } - Returns: string[] + Returns: unknown } get_size_by_bucket: { Args: Record diff --git a/package.json b/package.json index 709571ba6..fcce8a004 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "test": "turbo run test --concurrency=1", "format:write": "turbo run format:write", "format:check": "turbo run format:check", - "typegen": "supabase gen types typescript --local > packages/postgrest-swr/__tests__/database.types.ts && supabase gen types typescript --local > packages/postgrest-filter/__tests__/database.types.ts && supabase gen types typescript --local > packages/postgrest-fetcher/__tests__/database.types.ts", + "typegen": "supabase gen types typescript --local > packages/postgrest-swr/__tests__/database.types.ts && supabase gen types typescript --local > packages/postgrest-filter/__tests__/database.types.ts && supabase gen types typescript --local > packages/postgrest-fetcher/__tests__/database.types.ts && supabase gen types typescript --local > examples/swr/types/database.ts && supabase gen types typescript --local > examples/react-query/types/database.ts", "clear-branches": "git branch --merged | egrep -v \"(^\\*|main)\" | xargs git branch -d", "merge-main": "git fetch origin main:main && git merge main", "reset-git": "git checkout main && git pull && pnpm run clear-branches", diff --git a/packages/postgrest-fetcher/__tests__/database.types.ts b/packages/postgrest-fetcher/__tests__/database.types.ts index 20890b7ea..f2de0d8a0 100644 --- a/packages/postgrest-fetcher/__tests__/database.types.ts +++ b/packages/postgrest-fetcher/__tests__/database.types.ts @@ -7,66 +7,116 @@ export type Json = | Json[]; export interface Database { + graphql_public: { + Tables: { + [_ in never]: never; + }; + Views: { + [_ in never]: never; + }; + Functions: { + graphql: { + Args: { + operationName?: string; + query?: string; + variables?: Json; + extensions?: Json; + }; + Returns: Json; + }; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; + }; public: { Tables: { contact: { Row: { - country: string | null; - username: string | null; - ticket_number: number | null; - golden_ticket: boolean | null; - tags: string[] | null; age_range: unknown | null; - metadata: Json | null; catchphrase: unknown | null; - id: string; + continent: string | null; + country: string | null; created_at: string; - has_low_ticket_number: boolean; + golden_ticket: boolean | null; + id: string; + metadata: Json | null; + tags: string[] | null; + ticket_number: number | null; + username: string | null; + has_low_ticket_number: unknown | null; }; Insert: { - country?: string | null; - username?: string | null; - ticket_number?: number | null; - golden_ticket?: boolean | null; - tags?: string[] | null; age_range?: unknown | null; - metadata?: Json | null; catchphrase?: unknown | null; - id?: string; - created_at?: string; - }; - Update: { + continent?: string | null; country?: string | null; - username?: string | null; - ticket_number?: number | null; + created_at?: string; golden_ticket?: boolean | null; + id?: string; + metadata?: Json | null; tags?: string[] | null; + ticket_number?: number | null; + username?: string | null; + }; + Update: { age_range?: unknown | null; - metadata?: Json | null; catchphrase?: unknown | null; - id?: string; + continent?: string | null; + country?: string | null; created_at?: string; + golden_ticket?: boolean | null; + id?: string; + metadata?: Json | null; + tags?: string[] | null; + ticket_number?: number | null; + username?: string | null; }; + Relationships: [ + { + foreignKeyName: 'contact_continent_fkey'; + columns: ['continent']; + referencedRelation: 'continent'; + referencedColumns: ['code']; + }, + { + foreignKeyName: 'contact_country_fkey'; + columns: ['country']; + referencedRelation: 'country'; + referencedColumns: ['code']; + } + ]; }; contact_note: { Row: { contact_id: string; - text: string; - id: string; created_at: string; + id: string; + text: string; }; Insert: { contact_id: string; - text: string; - id?: string; created_at?: string; + id?: string; + text: string; }; Update: { contact_id?: string; - text?: string; - id?: string; created_at?: string; + id?: string; + text?: string; }; + Relationships: [ + { + foreignKeyName: 'contact_note_contact_id_fkey'; + columns: ['contact_id']; + referencedRelation: 'contact'; + referencedColumns: ['id']; + } + ]; }; continent: { Row: { @@ -81,32 +131,41 @@ export interface Database { code?: string; name?: string | null; }; + Relationships: []; }; country: { Row: { code: string; - name: string; + continent_code: string; full_name: string; iso3: string; + name: string; number: string; - continent_code: string; }; Insert: { code: string; - name: string; + continent_code: string; full_name: string; iso3: string; + name: string; number: string; - continent_code: string; }; Update: { code?: string; - name?: string; + continent_code?: string; full_name?: string; iso3?: string; + name?: string; number?: string; - continent_code?: string; }; + Relationships: [ + { + foreignKeyName: 'country_continent_code_fkey'; + columns: ['continent_code']; + referencedRelation: 'continent'; + referencedColumns: ['code']; + } + ]; }; }; Views: { @@ -114,12 +173,202 @@ export interface Database { }; Functions: { has_low_ticket_number: { - Args: { '': unknown }; + Args: { + '': unknown; + }; Returns: boolean; }; }; Enums: { [_ in never]: never; }; + CompositeTypes: { + [_ in never]: never; + }; + }; + storage: { + Tables: { + buckets: { + Row: { + allowed_mime_types: string[] | null; + avif_autodetection: boolean | null; + created_at: string | null; + file_size_limit: number | null; + id: string; + name: string; + owner: string | null; + public: boolean | null; + updated_at: string | null; + }; + Insert: { + allowed_mime_types?: string[] | null; + avif_autodetection?: boolean | null; + created_at?: string | null; + file_size_limit?: number | null; + id: string; + name: string; + owner?: string | null; + public?: boolean | null; + updated_at?: string | null; + }; + Update: { + allowed_mime_types?: string[] | null; + avif_autodetection?: boolean | null; + created_at?: string | null; + file_size_limit?: number | null; + id?: string; + name?: string; + owner?: string | null; + public?: boolean | null; + updated_at?: string | null; + }; + Relationships: [ + { + foreignKeyName: 'buckets_owner_fkey'; + columns: ['owner']; + referencedRelation: 'users'; + referencedColumns: ['id']; + } + ]; + }; + migrations: { + Row: { + executed_at: string | null; + hash: string; + id: number; + name: string; + }; + Insert: { + executed_at?: string | null; + hash: string; + id: number; + name: string; + }; + Update: { + executed_at?: string | null; + hash?: string; + id?: number; + name?: string; + }; + Relationships: []; + }; + objects: { + Row: { + bucket_id: string | null; + created_at: string | null; + id: string; + last_accessed_at: string | null; + metadata: Json | null; + name: string | null; + owner: string | null; + path_tokens: string[] | null; + updated_at: string | null; + version: string | null; + }; + Insert: { + bucket_id?: string | null; + created_at?: string | null; + id?: string; + last_accessed_at?: string | null; + metadata?: Json | null; + name?: string | null; + owner?: string | null; + path_tokens?: string[] | null; + updated_at?: string | null; + version?: string | null; + }; + Update: { + bucket_id?: string | null; + created_at?: string | null; + id?: string; + last_accessed_at?: string | null; + metadata?: Json | null; + name?: string | null; + owner?: string | null; + path_tokens?: string[] | null; + updated_at?: string | null; + version?: string | null; + }; + Relationships: [ + { + foreignKeyName: 'objects_bucketId_fkey'; + columns: ['bucket_id']; + referencedRelation: 'buckets'; + referencedColumns: ['id']; + }, + { + foreignKeyName: 'objects_owner_fkey'; + columns: ['owner']; + referencedRelation: 'users'; + referencedColumns: ['id']; + } + ]; + }; + }; + Views: { + [_ in never]: never; + }; + Functions: { + can_insert_object: { + Args: { + bucketid: string; + name: string; + owner: string; + metadata: Json; + }; + Returns: undefined; + }; + extension: { + Args: { + name: string; + }; + Returns: string; + }; + filename: { + Args: { + name: string; + }; + Returns: string; + }; + foldername: { + Args: { + name: string; + }; + Returns: unknown; + }; + get_size_by_bucket: { + Args: Record; + Returns: { + size: number; + bucket_id: string; + }[]; + }; + search: { + Args: { + prefix: string; + bucketname: string; + limits?: number; + levels?: number; + offsets?: number; + search?: string; + sortcolumn?: string; + sortorder?: string; + }; + Returns: { + name: string; + id: string; + updated_at: string; + created_at: string; + last_accessed_at: string; + metadata: Json; + }[]; + }; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; }; } diff --git a/packages/postgrest-fetcher/src/delete.ts b/packages/postgrest-fetcher/src/delete.ts index 00270cead..b31a03750 100644 --- a/packages/postgrest-fetcher/src/delete.ts +++ b/packages/postgrest-fetcher/src/delete.ts @@ -14,18 +14,19 @@ export type DeleteFetcher = ( export type DeleteFetcherOptions< S extends GenericSchema, - T extends GenericTable -> = Parameters['delete']>[0]; + T extends GenericTable, + Re = T extends { Relationships: infer R } ? R : unknown +> = Parameters['delete']>[0]; export const buildDeleteFetcher = < S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], opts: LoadQueryOps & DeleteFetcherOptions ): DeleteFetcher => diff --git a/packages/postgrest-fetcher/src/insert.ts b/packages/postgrest-fetcher/src/insert.ts index 2689d482e..712e66ca1 100644 --- a/packages/postgrest-fetcher/src/insert.ts +++ b/packages/postgrest-fetcher/src/insert.ts @@ -15,18 +15,19 @@ export type InsertFetcher = ( export type InsertFetcherOptions< S extends GenericSchema, - T extends GenericTable -> = Parameters['insert']>[1]; + T extends GenericTable, + Re = T extends { Relationships: infer R } ? R : unknown +> = Parameters['insert']>[1]; function buildInsertFetcher< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, - opts: LoadQueryOps & InsertFetcherOptions + qb: PostgrestQueryBuilder, + opts: LoadQueryOps & InsertFetcherOptions ): InsertFetcher { return async ( input: T['Insert'][] diff --git a/packages/postgrest-fetcher/src/pagination-fetcher.ts b/packages/postgrest-fetcher/src/pagination-fetcher.ts index 94bf9f06f..e6d4e6d41 100644 --- a/packages/postgrest-fetcher/src/pagination-fetcher.ts +++ b/packages/postgrest-fetcher/src/pagination-fetcher.ts @@ -18,9 +18,10 @@ export const createPaginationFetcher = < Schema extends GenericSchema, Row extends Record, Result, - Args + Args, + Relationships = unknown >( - query: PostgrestTransformBuilder | null, + query: PostgrestTransformBuilder | null, decode: PostgrestPaginationKeyDecoder, pageSize: number ): PostgrestPaginationFetcher< diff --git a/packages/postgrest-fetcher/src/update.ts b/packages/postgrest-fetcher/src/update.ts index 55e5a7498..7645d02a2 100644 --- a/packages/postgrest-fetcher/src/update.ts +++ b/packages/postgrest-fetcher/src/update.ts @@ -17,18 +17,19 @@ export type UpdateFetcher = ( export type UpdateFetcherOptions< S extends GenericSchema, - T extends GenericTable -> = Parameters['update']>[1]; + T extends GenericTable, + Re = T extends { Relationships: infer R } ? R : unknown +> = Parameters['update']>[1]; export const buildUpdateFetcher = < S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], opts: LoadQueryOps & UpdateFetcherOptions ): UpdateFetcher => diff --git a/packages/postgrest-fetcher/src/upsert.ts b/packages/postgrest-fetcher/src/upsert.ts index bc2cf8c48..eb41fd3ce 100644 --- a/packages/postgrest-fetcher/src/upsert.ts +++ b/packages/postgrest-fetcher/src/upsert.ts @@ -15,18 +15,19 @@ export type UpsertFetcher = ( export type UpsertFetcherOptions< S extends GenericSchema, - T extends GenericTable -> = Parameters['upsert']>[1]; + T extends GenericTable, + Re = T extends { Relationships: infer R } ? R : unknown +> = Parameters['upsert']>[1]; export const buildUpsertFetcher = < S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, opts: LoadQueryOps & UpsertFetcherOptions ): UpsertFetcher => async ( diff --git a/packages/postgrest-filter/__tests__/database.types.ts b/packages/postgrest-filter/__tests__/database.types.ts index 20890b7ea..f2de0d8a0 100644 --- a/packages/postgrest-filter/__tests__/database.types.ts +++ b/packages/postgrest-filter/__tests__/database.types.ts @@ -7,66 +7,116 @@ export type Json = | Json[]; export interface Database { + graphql_public: { + Tables: { + [_ in never]: never; + }; + Views: { + [_ in never]: never; + }; + Functions: { + graphql: { + Args: { + operationName?: string; + query?: string; + variables?: Json; + extensions?: Json; + }; + Returns: Json; + }; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; + }; public: { Tables: { contact: { Row: { - country: string | null; - username: string | null; - ticket_number: number | null; - golden_ticket: boolean | null; - tags: string[] | null; age_range: unknown | null; - metadata: Json | null; catchphrase: unknown | null; - id: string; + continent: string | null; + country: string | null; created_at: string; - has_low_ticket_number: boolean; + golden_ticket: boolean | null; + id: string; + metadata: Json | null; + tags: string[] | null; + ticket_number: number | null; + username: string | null; + has_low_ticket_number: unknown | null; }; Insert: { - country?: string | null; - username?: string | null; - ticket_number?: number | null; - golden_ticket?: boolean | null; - tags?: string[] | null; age_range?: unknown | null; - metadata?: Json | null; catchphrase?: unknown | null; - id?: string; - created_at?: string; - }; - Update: { + continent?: string | null; country?: string | null; - username?: string | null; - ticket_number?: number | null; + created_at?: string; golden_ticket?: boolean | null; + id?: string; + metadata?: Json | null; tags?: string[] | null; + ticket_number?: number | null; + username?: string | null; + }; + Update: { age_range?: unknown | null; - metadata?: Json | null; catchphrase?: unknown | null; - id?: string; + continent?: string | null; + country?: string | null; created_at?: string; + golden_ticket?: boolean | null; + id?: string; + metadata?: Json | null; + tags?: string[] | null; + ticket_number?: number | null; + username?: string | null; }; + Relationships: [ + { + foreignKeyName: 'contact_continent_fkey'; + columns: ['continent']; + referencedRelation: 'continent'; + referencedColumns: ['code']; + }, + { + foreignKeyName: 'contact_country_fkey'; + columns: ['country']; + referencedRelation: 'country'; + referencedColumns: ['code']; + } + ]; }; contact_note: { Row: { contact_id: string; - text: string; - id: string; created_at: string; + id: string; + text: string; }; Insert: { contact_id: string; - text: string; - id?: string; created_at?: string; + id?: string; + text: string; }; Update: { contact_id?: string; - text?: string; - id?: string; created_at?: string; + id?: string; + text?: string; }; + Relationships: [ + { + foreignKeyName: 'contact_note_contact_id_fkey'; + columns: ['contact_id']; + referencedRelation: 'contact'; + referencedColumns: ['id']; + } + ]; }; continent: { Row: { @@ -81,32 +131,41 @@ export interface Database { code?: string; name?: string | null; }; + Relationships: []; }; country: { Row: { code: string; - name: string; + continent_code: string; full_name: string; iso3: string; + name: string; number: string; - continent_code: string; }; Insert: { code: string; - name: string; + continent_code: string; full_name: string; iso3: string; + name: string; number: string; - continent_code: string; }; Update: { code?: string; - name?: string; + continent_code?: string; full_name?: string; iso3?: string; + name?: string; number?: string; - continent_code?: string; }; + Relationships: [ + { + foreignKeyName: 'country_continent_code_fkey'; + columns: ['continent_code']; + referencedRelation: 'continent'; + referencedColumns: ['code']; + } + ]; }; }; Views: { @@ -114,12 +173,202 @@ export interface Database { }; Functions: { has_low_ticket_number: { - Args: { '': unknown }; + Args: { + '': unknown; + }; Returns: boolean; }; }; Enums: { [_ in never]: never; }; + CompositeTypes: { + [_ in never]: never; + }; + }; + storage: { + Tables: { + buckets: { + Row: { + allowed_mime_types: string[] | null; + avif_autodetection: boolean | null; + created_at: string | null; + file_size_limit: number | null; + id: string; + name: string; + owner: string | null; + public: boolean | null; + updated_at: string | null; + }; + Insert: { + allowed_mime_types?: string[] | null; + avif_autodetection?: boolean | null; + created_at?: string | null; + file_size_limit?: number | null; + id: string; + name: string; + owner?: string | null; + public?: boolean | null; + updated_at?: string | null; + }; + Update: { + allowed_mime_types?: string[] | null; + avif_autodetection?: boolean | null; + created_at?: string | null; + file_size_limit?: number | null; + id?: string; + name?: string; + owner?: string | null; + public?: boolean | null; + updated_at?: string | null; + }; + Relationships: [ + { + foreignKeyName: 'buckets_owner_fkey'; + columns: ['owner']; + referencedRelation: 'users'; + referencedColumns: ['id']; + } + ]; + }; + migrations: { + Row: { + executed_at: string | null; + hash: string; + id: number; + name: string; + }; + Insert: { + executed_at?: string | null; + hash: string; + id: number; + name: string; + }; + Update: { + executed_at?: string | null; + hash?: string; + id?: number; + name?: string; + }; + Relationships: []; + }; + objects: { + Row: { + bucket_id: string | null; + created_at: string | null; + id: string; + last_accessed_at: string | null; + metadata: Json | null; + name: string | null; + owner: string | null; + path_tokens: string[] | null; + updated_at: string | null; + version: string | null; + }; + Insert: { + bucket_id?: string | null; + created_at?: string | null; + id?: string; + last_accessed_at?: string | null; + metadata?: Json | null; + name?: string | null; + owner?: string | null; + path_tokens?: string[] | null; + updated_at?: string | null; + version?: string | null; + }; + Update: { + bucket_id?: string | null; + created_at?: string | null; + id?: string; + last_accessed_at?: string | null; + metadata?: Json | null; + name?: string | null; + owner?: string | null; + path_tokens?: string[] | null; + updated_at?: string | null; + version?: string | null; + }; + Relationships: [ + { + foreignKeyName: 'objects_bucketId_fkey'; + columns: ['bucket_id']; + referencedRelation: 'buckets'; + referencedColumns: ['id']; + }, + { + foreignKeyName: 'objects_owner_fkey'; + columns: ['owner']; + referencedRelation: 'users'; + referencedColumns: ['id']; + } + ]; + }; + }; + Views: { + [_ in never]: never; + }; + Functions: { + can_insert_object: { + Args: { + bucketid: string; + name: string; + owner: string; + metadata: Json; + }; + Returns: undefined; + }; + extension: { + Args: { + name: string; + }; + Returns: string; + }; + filename: { + Args: { + name: string; + }; + Returns: string; + }; + foldername: { + Args: { + name: string; + }; + Returns: unknown; + }; + get_size_by_bucket: { + Args: Record; + Returns: { + size: number; + bucket_id: string; + }[]; + }; + search: { + Args: { + prefix: string; + bucketname: string; + limits?: number; + levels?: number; + offsets?: number; + search?: string; + sortcolumn?: string; + sortorder?: string; + }; + Returns: { + name: string; + id: string; + updated_at: string; + created_at: string; + last_accessed_at: string; + metadata: Json; + }[]; + }; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; }; } diff --git a/packages/postgrest-react-query/src/mutate/use-delete-mutation.ts b/packages/postgrest-react-query/src/mutate/use-delete-mutation.ts index 4ccc4873f..46b254c28 100644 --- a/packages/postgrest-react-query/src/mutate/use-delete-mutation.ts +++ b/packages/postgrest-react-query/src/mutate/use-delete-mutation.ts @@ -26,15 +26,15 @@ import { UsePostgrestMutationOpts } from './types'; function useDeleteMutation< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], query?: QueryWithoutWildcard | null, opts?: Omit< - UsePostgrestMutationOpts, + UsePostgrestMutationOpts, 'mutationFn' > ) { @@ -48,16 +48,12 @@ function useDeleteMutation< return useMutation({ mutationFn: async (input) => { - const result = await buildDeleteFetcher( - qb, - primaryKeys, - { - query: query ?? undefined, - queriesForTable, - disabled: opts?.disableAutoQuery, - ...opts, - } - )(input); + const result = await buildDeleteFetcher(qb, primaryKeys, { + query: query ?? undefined, + queriesForTable, + disabled: opts?.disableAutoQuery, + ...opts, + })(input); if (result) { await deleteItem(result.normalizedData as T['Row']); diff --git a/packages/postgrest-react-query/src/mutate/use-insert-mutation.ts b/packages/postgrest-react-query/src/mutate/use-insert-mutation.ts index 76531c238..54e4b570b 100644 --- a/packages/postgrest-react-query/src/mutate/use-insert-mutation.ts +++ b/packages/postgrest-react-query/src/mutate/use-insert-mutation.ts @@ -27,17 +27,14 @@ import { UsePostgrestMutationOpts } from './types'; function useInsertMutation< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], query?: QueryWithoutWildcard | null, - opts?: Omit< - UsePostgrestMutationOpts, - 'mutationFn' - > + opts?: Omit, 'mutationFn'> ) { const queriesForTable = useQueriesForTableLoader(getTable(qb)); const upsertItem = useUpsertItem({ @@ -49,7 +46,7 @@ function useInsertMutation< return useMutation({ mutationFn: async (input) => { - const result = await buildInsertFetcher(qb, { + const result = await buildInsertFetcher(qb, { query: query ?? undefined, queriesForTable, disabled: opts?.disableAutoQuery, diff --git a/packages/postgrest-react-query/src/mutate/use-update-mutation.ts b/packages/postgrest-react-query/src/mutate/use-update-mutation.ts index 40c8d941b..2bd45d818 100644 --- a/packages/postgrest-react-query/src/mutate/use-update-mutation.ts +++ b/packages/postgrest-react-query/src/mutate/use-update-mutation.ts @@ -26,15 +26,15 @@ import { UsePostgrestMutationOpts } from './types'; function useUpdateMutation< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], query?: QueryWithoutWildcard | null, opts?: Omit< - UsePostgrestMutationOpts, + UsePostgrestMutationOpts, 'mutationFn' > ) { @@ -48,16 +48,12 @@ function useUpdateMutation< return useMutation({ mutationFn: async (input) => { - const result = await buildUpdateFetcher( - qb, - primaryKeys, - { - query: query ?? undefined, - queriesForTable, - disabled: opts?.disableAutoQuery, - ...opts, - } - )(input); + const result = await buildUpdateFetcher(qb, primaryKeys, { + query: query ?? undefined, + queriesForTable, + disabled: opts?.disableAutoQuery, + ...opts, + })(input); if (result) { await upsertItem(result.normalizedData as T['Row']); } diff --git a/packages/postgrest-react-query/src/mutate/use-upsert-mutation.ts b/packages/postgrest-react-query/src/mutate/use-upsert-mutation.ts index 8ed012c32..45182c756 100644 --- a/packages/postgrest-react-query/src/mutate/use-upsert-mutation.ts +++ b/packages/postgrest-react-query/src/mutate/use-upsert-mutation.ts @@ -27,17 +27,14 @@ import { UsePostgrestMutationOpts } from './types'; function useUpsertMutation< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], query?: QueryWithoutWildcard | null, - opts?: Omit< - UsePostgrestMutationOpts, - 'mutationFn' - > + opts?: Omit, 'mutationFn'> ) { const queriesForTable = useQueriesForTableLoader(getTable(qb)); const upsertItem = useUpsertItem({ @@ -49,7 +46,7 @@ function useUpsertMutation< return useMutation({ mutationFn: async (input: T['Insert'][]) => { - const data = await buildUpsertFetcher(qb, { + const data = await buildUpsertFetcher(qb, { query: query ?? undefined, queriesForTable, disabled: opts?.disableAutoQuery, diff --git a/packages/postgrest-swr/__tests__/database.types.ts b/packages/postgrest-swr/__tests__/database.types.ts index 20890b7ea..f2de0d8a0 100644 --- a/packages/postgrest-swr/__tests__/database.types.ts +++ b/packages/postgrest-swr/__tests__/database.types.ts @@ -7,66 +7,116 @@ export type Json = | Json[]; export interface Database { + graphql_public: { + Tables: { + [_ in never]: never; + }; + Views: { + [_ in never]: never; + }; + Functions: { + graphql: { + Args: { + operationName?: string; + query?: string; + variables?: Json; + extensions?: Json; + }; + Returns: Json; + }; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; + }; public: { Tables: { contact: { Row: { - country: string | null; - username: string | null; - ticket_number: number | null; - golden_ticket: boolean | null; - tags: string[] | null; age_range: unknown | null; - metadata: Json | null; catchphrase: unknown | null; - id: string; + continent: string | null; + country: string | null; created_at: string; - has_low_ticket_number: boolean; + golden_ticket: boolean | null; + id: string; + metadata: Json | null; + tags: string[] | null; + ticket_number: number | null; + username: string | null; + has_low_ticket_number: unknown | null; }; Insert: { - country?: string | null; - username?: string | null; - ticket_number?: number | null; - golden_ticket?: boolean | null; - tags?: string[] | null; age_range?: unknown | null; - metadata?: Json | null; catchphrase?: unknown | null; - id?: string; - created_at?: string; - }; - Update: { + continent?: string | null; country?: string | null; - username?: string | null; - ticket_number?: number | null; + created_at?: string; golden_ticket?: boolean | null; + id?: string; + metadata?: Json | null; tags?: string[] | null; + ticket_number?: number | null; + username?: string | null; + }; + Update: { age_range?: unknown | null; - metadata?: Json | null; catchphrase?: unknown | null; - id?: string; + continent?: string | null; + country?: string | null; created_at?: string; + golden_ticket?: boolean | null; + id?: string; + metadata?: Json | null; + tags?: string[] | null; + ticket_number?: number | null; + username?: string | null; }; + Relationships: [ + { + foreignKeyName: 'contact_continent_fkey'; + columns: ['continent']; + referencedRelation: 'continent'; + referencedColumns: ['code']; + }, + { + foreignKeyName: 'contact_country_fkey'; + columns: ['country']; + referencedRelation: 'country'; + referencedColumns: ['code']; + } + ]; }; contact_note: { Row: { contact_id: string; - text: string; - id: string; created_at: string; + id: string; + text: string; }; Insert: { contact_id: string; - text: string; - id?: string; created_at?: string; + id?: string; + text: string; }; Update: { contact_id?: string; - text?: string; - id?: string; created_at?: string; + id?: string; + text?: string; }; + Relationships: [ + { + foreignKeyName: 'contact_note_contact_id_fkey'; + columns: ['contact_id']; + referencedRelation: 'contact'; + referencedColumns: ['id']; + } + ]; }; continent: { Row: { @@ -81,32 +131,41 @@ export interface Database { code?: string; name?: string | null; }; + Relationships: []; }; country: { Row: { code: string; - name: string; + continent_code: string; full_name: string; iso3: string; + name: string; number: string; - continent_code: string; }; Insert: { code: string; - name: string; + continent_code: string; full_name: string; iso3: string; + name: string; number: string; - continent_code: string; }; Update: { code?: string; - name?: string; + continent_code?: string; full_name?: string; iso3?: string; + name?: string; number?: string; - continent_code?: string; }; + Relationships: [ + { + foreignKeyName: 'country_continent_code_fkey'; + columns: ['continent_code']; + referencedRelation: 'continent'; + referencedColumns: ['code']; + } + ]; }; }; Views: { @@ -114,12 +173,202 @@ export interface Database { }; Functions: { has_low_ticket_number: { - Args: { '': unknown }; + Args: { + '': unknown; + }; Returns: boolean; }; }; Enums: { [_ in never]: never; }; + CompositeTypes: { + [_ in never]: never; + }; + }; + storage: { + Tables: { + buckets: { + Row: { + allowed_mime_types: string[] | null; + avif_autodetection: boolean | null; + created_at: string | null; + file_size_limit: number | null; + id: string; + name: string; + owner: string | null; + public: boolean | null; + updated_at: string | null; + }; + Insert: { + allowed_mime_types?: string[] | null; + avif_autodetection?: boolean | null; + created_at?: string | null; + file_size_limit?: number | null; + id: string; + name: string; + owner?: string | null; + public?: boolean | null; + updated_at?: string | null; + }; + Update: { + allowed_mime_types?: string[] | null; + avif_autodetection?: boolean | null; + created_at?: string | null; + file_size_limit?: number | null; + id?: string; + name?: string; + owner?: string | null; + public?: boolean | null; + updated_at?: string | null; + }; + Relationships: [ + { + foreignKeyName: 'buckets_owner_fkey'; + columns: ['owner']; + referencedRelation: 'users'; + referencedColumns: ['id']; + } + ]; + }; + migrations: { + Row: { + executed_at: string | null; + hash: string; + id: number; + name: string; + }; + Insert: { + executed_at?: string | null; + hash: string; + id: number; + name: string; + }; + Update: { + executed_at?: string | null; + hash?: string; + id?: number; + name?: string; + }; + Relationships: []; + }; + objects: { + Row: { + bucket_id: string | null; + created_at: string | null; + id: string; + last_accessed_at: string | null; + metadata: Json | null; + name: string | null; + owner: string | null; + path_tokens: string[] | null; + updated_at: string | null; + version: string | null; + }; + Insert: { + bucket_id?: string | null; + created_at?: string | null; + id?: string; + last_accessed_at?: string | null; + metadata?: Json | null; + name?: string | null; + owner?: string | null; + path_tokens?: string[] | null; + updated_at?: string | null; + version?: string | null; + }; + Update: { + bucket_id?: string | null; + created_at?: string | null; + id?: string; + last_accessed_at?: string | null; + metadata?: Json | null; + name?: string | null; + owner?: string | null; + path_tokens?: string[] | null; + updated_at?: string | null; + version?: string | null; + }; + Relationships: [ + { + foreignKeyName: 'objects_bucketId_fkey'; + columns: ['bucket_id']; + referencedRelation: 'buckets'; + referencedColumns: ['id']; + }, + { + foreignKeyName: 'objects_owner_fkey'; + columns: ['owner']; + referencedRelation: 'users'; + referencedColumns: ['id']; + } + ]; + }; + }; + Views: { + [_ in never]: never; + }; + Functions: { + can_insert_object: { + Args: { + bucketid: string; + name: string; + owner: string; + metadata: Json; + }; + Returns: undefined; + }; + extension: { + Args: { + name: string; + }; + Returns: string; + }; + filename: { + Args: { + name: string; + }; + Returns: string; + }; + foldername: { + Args: { + name: string; + }; + Returns: unknown; + }; + get_size_by_bucket: { + Args: Record; + Returns: { + size: number; + bucket_id: string; + }[]; + }; + search: { + Args: { + prefix: string; + bucketname: string; + limits?: number; + levels?: number; + offsets?: number; + search?: string; + sortcolumn?: string; + sortorder?: string; + }; + Returns: { + name: string; + id: string; + updated_at: string; + created_at: string; + last_accessed_at: string; + metadata: Json; + }[]; + }; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; }; } diff --git a/packages/postgrest-swr/src/mutate/use-delete-mutation.ts b/packages/postgrest-swr/src/mutate/use-delete-mutation.ts index e8635be8a..2c80aa2b6 100644 --- a/packages/postgrest-swr/src/mutate/use-delete-mutation.ts +++ b/packages/postgrest-swr/src/mutate/use-delete-mutation.ts @@ -28,14 +28,14 @@ import { useRandomKey } from './use-random-key'; function useDeleteMutation< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], query?: QueryWithoutWildcard | null, - opts?: UsePostgrestSWRMutationOpts + opts?: UsePostgrestSWRMutationOpts ): SWRMutationResponse> { const key = useRandomKey(); const queriesForTable = useQueriesForTableLoader(getTable(qb)); @@ -49,16 +49,12 @@ function useDeleteMutation< return useMutation>( key, async (_, { arg }) => { - const result = await buildDeleteFetcher( - qb, - primaryKeys, - { - query: query ?? undefined, - queriesForTable, - disabled: opts?.disableAutoQuery, - ...opts, - } - )(arg); + const result = await buildDeleteFetcher(qb, primaryKeys, { + query: query ?? undefined, + queriesForTable, + disabled: opts?.disableAutoQuery, + ...opts, + })(arg); if (result) { deleteItem(result?.normalizedData as T['Row']); diff --git a/packages/postgrest-swr/src/mutate/use-insert-mutation.ts b/packages/postgrest-swr/src/mutate/use-insert-mutation.ts index 42cf23d3a..cf8f6991d 100644 --- a/packages/postgrest-swr/src/mutate/use-insert-mutation.ts +++ b/packages/postgrest-swr/src/mutate/use-insert-mutation.ts @@ -29,14 +29,14 @@ import { useRandomKey } from './use-random-key'; function useInsertMutation< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], query?: QueryWithoutWildcard | null, - opts?: UsePostgrestSWRMutationOpts + opts?: UsePostgrestSWRMutationOpts ): SWRMutationResponse { const key = useRandomKey(); const queriesForTable = useQueriesForTableLoader(getTable(qb)); @@ -50,7 +50,7 @@ function useInsertMutation< return useMutation( key, async (key, { arg }) => { - const result = await buildInsertFetcher(qb, { + const result = await buildInsertFetcher(qb, { query: query ?? undefined, queriesForTable, disabled: opts?.disableAutoQuery, diff --git a/packages/postgrest-swr/src/mutate/use-update-mutation.ts b/packages/postgrest-swr/src/mutate/use-update-mutation.ts index 035f96464..876910fff 100644 --- a/packages/postgrest-swr/src/mutate/use-update-mutation.ts +++ b/packages/postgrest-swr/src/mutate/use-update-mutation.ts @@ -28,14 +28,14 @@ import { useRandomKey } from './use-random-key'; function useUpdateMutation< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], query?: QueryWithoutWildcard | null, - opts?: UsePostgrestSWRMutationOpts + opts?: UsePostgrestSWRMutationOpts ): SWRMutationResponse { const key = useRandomKey(); const queriesForTable = useQueriesForTableLoader(getTable(qb)); @@ -49,16 +49,12 @@ function useUpdateMutation< return useSWRMutation( key, async (_, { arg }) => { - const result = await buildUpdateFetcher( - qb, - primaryKeys, - { - query: query ?? undefined, - queriesForTable, - disabled: opts?.disableAutoQuery, - ...opts, - } - )(arg); + const result = await buildUpdateFetcher(qb, primaryKeys, { + query: query ?? undefined, + queriesForTable, + disabled: opts?.disableAutoQuery, + ...opts, + })(arg); if (result?.normalizedData) { upsertItem(result?.normalizedData as T['Row']); diff --git a/packages/postgrest-swr/src/mutate/use-upsert-mutation.ts b/packages/postgrest-swr/src/mutate/use-upsert-mutation.ts index da1d70418..d2d5b151f 100644 --- a/packages/postgrest-swr/src/mutate/use-upsert-mutation.ts +++ b/packages/postgrest-swr/src/mutate/use-upsert-mutation.ts @@ -29,14 +29,14 @@ import { useRandomKey } from './use-random-key'; function useUpsertMutation< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( - qb: PostgrestQueryBuilder, + qb: PostgrestQueryBuilder, primaryKeys: (keyof T['Row'])[], query?: QueryWithoutWildcard | null, - opts?: UsePostgrestSWRMutationOpts + opts?: UsePostgrestSWRMutationOpts ): SWRMutationResponse { const key = useRandomKey(); const queriesForTable = useQueriesForTableLoader(getTable(qb)); @@ -50,7 +50,7 @@ function useUpsertMutation< return useMutation( key, async (_, { arg }) => { - const result = await buildUpsertFetcher(qb, { + const result = await buildUpsertFetcher(qb, { query: query ?? undefined, queriesForTable, disabled: opts?.disableAutoQuery, diff --git a/packages/postgrest-swr/src/query/use-infinite-query.ts b/packages/postgrest-swr/src/query/use-infinite-query.ts index 7005b4470..915ab9121 100644 --- a/packages/postgrest-swr/src/query/use-infinite-query.ts +++ b/packages/postgrest-swr/src/query/use-infinite-query.ts @@ -31,9 +31,15 @@ export type UseInfiniteQueryReturn> = function useInfiniteQuery< Schema extends GenericSchema, Table extends Record, - Result extends Record + Result extends Record, + Relationships = unknown >( - query: PostgrestTransformBuilder | null, + query: PostgrestTransformBuilder< + Schema, + Table, + Result[], + Relationships + > | null, config?: SWRInfiniteConfiguration & { pageSize?: number } ): UseInfiniteQueryReturn { return useSWRInfinite< diff --git a/packages/postgrest-swr/src/query/use-infinite-scroll-query.ts b/packages/postgrest-swr/src/query/use-infinite-scroll-query.ts index a8f3d20a0..9f3d4611a 100644 --- a/packages/postgrest-swr/src/query/use-infinite-scroll-query.ts +++ b/packages/postgrest-swr/src/query/use-infinite-scroll-query.ts @@ -54,9 +54,15 @@ export type UseInfiniteScrollQueryReturn< function useInfiniteScrollQuery< Schema extends GenericSchema, Table extends Record, - Result extends Record + Result extends Record, + Relationships = unknown >( - query: PostgrestTransformBuilder | null, + query: PostgrestTransformBuilder< + Schema, + Table, + Result[], + Relationships + > | null, config?: SWRInfiniteConfiguration & { pageSize?: number } ): UseInfiniteScrollQueryReturn { const { data, setSize, size, ...rest } = useSWRInfinite< diff --git a/packages/postgrest-swr/src/subscribe/use-subscription-query.ts b/packages/postgrest-swr/src/subscribe/use-subscription-query.ts index 2f562b9cc..6eda10d84 100644 --- a/packages/postgrest-swr/src/subscribe/use-subscription-query.ts +++ b/packages/postgrest-swr/src/subscribe/use-subscription-query.ts @@ -26,9 +26,9 @@ import { useQueriesForTableLoader } from '../lib'; export type UseSubscriptionQueryOpts< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult > = PostgrestMutatorOpts & SWRMutatorOptions & { /** @@ -64,9 +64,9 @@ export type UseSubscriptionQueryOpts< function useSubscriptionQuery< S extends GenericSchema, T extends GenericTable, - Relationships, + Re = T extends { Relationships: infer R } ? R : unknown, Q extends string = '*', - R = GetResult + R = GetResult >( client: SupabaseClient | null, channelName: string, @@ -76,7 +76,7 @@ function useSubscriptionQuery< > & { table: string }, primaryKeys: (keyof T['Row'])[], query?: QueryWithoutWildcard | null, - opts?: UseSubscriptionQueryOpts + opts?: UseSubscriptionQueryOpts ) { const [status, setStatus] = useState(); const [channel, setChannel] = useState();