From 9a0a393949571944991317db578daac693366207 Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Wed, 11 Dec 2024 22:38:59 +0530 Subject: [PATCH 01/10] fix: handle multiple filters in Supabase liveProvider with warnings and configurable meta.realtimeFilter --- packages/supabase/src/liveProvider/index.ts | 27 ++++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/supabase/src/liveProvider/index.ts b/packages/supabase/src/liveProvider/index.ts index 19200da1de4c..c670e131486c 100644 --- a/packages/supabase/src/liveProvider/index.ts +++ b/packages/supabase/src/liveProvider/index.ts @@ -7,6 +7,8 @@ import type { import { liveTypes, supabaseTypes } from "../types"; import { mapOperator } from "../utils"; +const supportedOperators = ["eq", "neq", "gt", "lt", "gte", "lte"]; + export const liveProvider = ( supabaseClient: SupabaseClient, ): LiveProvider => { @@ -49,14 +51,31 @@ export const liveProvider = ( } }; - const mapFilter = (filters?: CrudFilters): string | undefined => { + const mapFilter = ( + filters?: CrudFilters, + meta?: any, + ): string | undefined => { if (!filters || filters?.length === 0) { return; } - return filters + if (filters.length > 1) { + console.warn( + "Multiple filters detected. Supabase Realtime currently supports only one filter. " + + "Using the first filter. You can override this behavior by using 'meta.realtimeFilter'.", + ); + } + + const effectiveFilter = meta?.realtimeFilter + ? [meta.realtimeFilter] + : [filters[0]]; + + return effectiveFilter .map((filter: CrudFilter): string | undefined => { - if ("field" in filter) { + if ( + "field" in filter && + supportedOperators.includes(filter.operator) + ) { return `${filter.field}=${mapOperator(filter.operator)}.${ filter.value }`; @@ -70,7 +89,7 @@ export const liveProvider = ( const events = types .map((x) => supabaseTypes[x]) .sort((a, b) => a.localeCompare(b)); - const filter = mapFilter(params?.filters); + const filter = mapFilter(params?.filters, meta); const ch = `${channel}:${events.join("|")}${filter ? `:${filter}` : ""}`; let client = supabaseClient.channel(ch); From d9d7eddfba530d32b618a48bc5c55b81268ec8d6 Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Wed, 11 Dec 2024 23:09:47 +0530 Subject: [PATCH 02/10] chore: add changeset for recent changes --- .changeset/shiny-panthers-nail.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/shiny-panthers-nail.md diff --git a/.changeset/shiny-panthers-nail.md b/.changeset/shiny-panthers-nail.md new file mode 100644 index 000000000000..65c2d4139858 --- /dev/null +++ b/.changeset/shiny-panthers-nail.md @@ -0,0 +1,7 @@ +--- +"@refinedev/supabase": patch +--- + +This PR addresses the issue with multiple filters in Supabase liveProvider. It ensures that only the first filter is applied and adds support for the configurable 'meta.realtimeFilter' to handle custom filter behavior. + +Resolves #6360 (https://github.com/refinedev/refine/issues/6360) From 6600f6b946dd9e9d70ab4562558c931fb41959e7 Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Fri, 13 Dec 2024 20:08:46 +0530 Subject: [PATCH 03/10] chore: update changeset --- .changeset/shiny-panthers-nail.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.changeset/shiny-panthers-nail.md b/.changeset/shiny-panthers-nail.md index 65c2d4139858..4d0a713371c0 100644 --- a/.changeset/shiny-panthers-nail.md +++ b/.changeset/shiny-panthers-nail.md @@ -2,6 +2,7 @@ "@refinedev/supabase": patch --- -This PR addresses the issue with multiple filters in Supabase liveProvider. It ensures that only the first filter is applied and adds support for the configurable 'meta.realtimeFilter' to handle custom filter behavior. +fix: handle multiple filters in Supabase liveProvider. +This update addresses the handling of multiple filters in the Supabase liveProvider. It ensures only the first filter is applied and introduces a configurable `meta.realtimeFilter` option for custom filter behavior. A warning is logged when multiple filters are detected. -Resolves #6360 (https://github.com/refinedev/refine/issues/6360) +Resolves [#6360](https://github.com/refinedev/refine/issues/6360) From 89e14aa206aef88f2b5699bd759848f0fa03aabd Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Mon, 23 Dec 2024 01:02:54 +0530 Subject: [PATCH 04/10] chore: update warning message --- packages/supabase/src/liveProvider/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/supabase/src/liveProvider/index.ts b/packages/supabase/src/liveProvider/index.ts index c670e131486c..50e6c9722bd3 100644 --- a/packages/supabase/src/liveProvider/index.ts +++ b/packages/supabase/src/liveProvider/index.ts @@ -61,8 +61,7 @@ export const liveProvider = ( if (filters.length > 1) { console.warn( - "Multiple filters detected. Supabase Realtime currently supports only one filter. " + - "Using the first filter. You can override this behavior by using 'meta.realtimeFilter'.", + "Warning: Multiple filters detected. Supabase Realtime currently supports only a single filter. The first filter will be applied. To customize this behavior, use the 'meta.realtimeFilter' property.", ); } From 2dd33b1116c7ab52cab1bb151f4bdc3245b66828 Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Mon, 30 Dec 2024 17:31:38 +0530 Subject: [PATCH 05/10] chore: update changeset --- .changeset/shiny-panthers-nail.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/shiny-panthers-nail.md b/.changeset/shiny-panthers-nail.md index 4d0a713371c0..2d0783854f28 100644 --- a/.changeset/shiny-panthers-nail.md +++ b/.changeset/shiny-panthers-nail.md @@ -5,4 +5,4 @@ fix: handle multiple filters in Supabase liveProvider. This update addresses the handling of multiple filters in the Supabase liveProvider. It ensures only the first filter is applied and introduces a configurable `meta.realtimeFilter` option for custom filter behavior. A warning is logged when multiple filters are detected. -Resolves [#6360](https://github.com/refinedev/refine/issues/6360) +[Resolves #6360](https://github.com/refinedev/refine/issues/6360) From 2cf3427fd5a8c2296eb6afb85bcbdc0a88d41f1c Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Wed, 1 Jan 2025 23:18:10 +0530 Subject: [PATCH 06/10] fix(supabase): implement warn-once to reduce duplicate warnings for multiple filters --- packages/supabase/src/liveProvider/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/supabase/src/liveProvider/index.ts b/packages/supabase/src/liveProvider/index.ts index 50e6c9722bd3..6434d997bf89 100644 --- a/packages/supabase/src/liveProvider/index.ts +++ b/packages/supabase/src/liveProvider/index.ts @@ -6,6 +6,7 @@ import type { } from "@supabase/supabase-js"; import { liveTypes, supabaseTypes } from "../types"; import { mapOperator } from "../utils"; +import warnOnce from "warn-once"; const supportedOperators = ["eq", "neq", "gt", "lt", "gte", "lte"]; @@ -60,8 +61,9 @@ export const liveProvider = ( } if (filters.length > 1) { - console.warn( - "Warning: Multiple filters detected. Supabase Realtime currently supports only a single filter. The first filter will be applied. To customize this behavior, use the 'meta.realtimeFilter' property.", + warnOnce( + true, + `Warning: Multiple filters detected for resource "${resource}". Supabase Realtime currently supports only a single filter. The first filter will be applied. To customize this behavior, use the 'meta.realtimeFilter' property.`, ); } From 4d3291a3fe20215a0ce4b064aa0ad4b3822edee1 Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Wed, 1 Jan 2025 23:31:42 +0530 Subject: [PATCH 07/10] fix(supabase): update supported operators to use ne instead of neq --- packages/supabase/src/liveProvider/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/supabase/src/liveProvider/index.ts b/packages/supabase/src/liveProvider/index.ts index 6434d997bf89..d38c3abcfade 100644 --- a/packages/supabase/src/liveProvider/index.ts +++ b/packages/supabase/src/liveProvider/index.ts @@ -8,7 +8,7 @@ import { liveTypes, supabaseTypes } from "../types"; import { mapOperator } from "../utils"; import warnOnce from "warn-once"; -const supportedOperators = ["eq", "neq", "gt", "lt", "gte", "lte"]; +const supportedOperators = ["eq", "ne", "gt", "lt", "gte", "lte"]; export const liveProvider = ( supabaseClient: SupabaseClient, From f9e968e1f9a0f3ca3e9628b806f011b78a7d569b Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Wed, 1 Jan 2025 23:52:59 +0530 Subject: [PATCH 08/10] fix(supabase): prevent unnecessary warnings for multiple filters when meta.realtimeFilter is set --- packages/supabase/src/liveProvider/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/supabase/src/liveProvider/index.ts b/packages/supabase/src/liveProvider/index.ts index d38c3abcfade..5684196d218d 100644 --- a/packages/supabase/src/liveProvider/index.ts +++ b/packages/supabase/src/liveProvider/index.ts @@ -60,7 +60,7 @@ export const liveProvider = ( return; } - if (filters.length > 1) { + if (filters.length > 1 && !meta?.realtimeFilter) { warnOnce( true, `Warning: Multiple filters detected for resource "${resource}". Supabase Realtime currently supports only a single filter. The first filter will be applied. To customize this behavior, use the 'meta.realtimeFilter' property.`, From fd447ca9a671d8f3df71286d25d34e40223d5480 Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Thu, 2 Jan 2025 14:03:09 +0530 Subject: [PATCH 09/10] fix(supabase): add warning for unsupported filters --- packages/supabase/src/liveProvider/index.ts | 35 ++++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/supabase/src/liveProvider/index.ts b/packages/supabase/src/liveProvider/index.ts index 5684196d218d..60b7d693f7fc 100644 --- a/packages/supabase/src/liveProvider/index.ts +++ b/packages/supabase/src/liveProvider/index.ts @@ -8,7 +8,21 @@ import { liveTypes, supabaseTypes } from "../types"; import { mapOperator } from "../utils"; import warnOnce from "warn-once"; -const supportedOperators = ["eq", "ne", "gt", "lt", "gte", "lte"]; +const supportedOperators = [ + "eq", + "ne", + "nin", + "ina", + "nina", + "contains", + "ncontains", + "containss", + "ncontainss", + "between", + "nbetween", + "null", + "nnull", +]; export const liveProvider = ( supabaseClient: SupabaseClient, @@ -73,13 +87,18 @@ export const liveProvider = ( return effectiveFilter .map((filter: CrudFilter): string | undefined => { - if ( - "field" in filter && - supportedOperators.includes(filter.operator) - ) { - return `${filter.field}=${mapOperator(filter.operator)}.${ - filter.value - }`; + if ("field" in filter) { + if (supportedOperators.includes(filter.operator)) { + return `${filter.field}=${mapOperator(filter.operator)}.${ + filter.value + }`; + } else { + warnOnce( + true, + `Unsupported filter operator: ${filter.operator}`, + ); + return undefined; + } } return; }) From 19d371fbc482380df8143707c71174fa75fdc08e Mon Sep 17 00:00:00 2001 From: Omkar Bansod Date: Thu, 2 Jan 2025 14:19:27 +0530 Subject: [PATCH 10/10] fix(supabase): remove unnecessary else clause and handle unsupported filter operators cleanly --- packages/supabase/src/liveProvider/index.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/supabase/src/liveProvider/index.ts b/packages/supabase/src/liveProvider/index.ts index 60b7d693f7fc..a8a91906a284 100644 --- a/packages/supabase/src/liveProvider/index.ts +++ b/packages/supabase/src/liveProvider/index.ts @@ -92,15 +92,11 @@ export const liveProvider = ( return `${filter.field}=${mapOperator(filter.operator)}.${ filter.value }`; - } else { - warnOnce( - true, - `Unsupported filter operator: ${filter.operator}`, - ); - return undefined; } + warnOnce(true, `Unsupported filter operator: ${filter.operator}`); + return undefined; } - return; + return undefined; }) .filter(Boolean) .join(",");