From 6de9ea0bc6c9bdcfe4f6ad306385d020e842e320 Mon Sep 17 00:00:00 2001 From: Brandon Ly Date: Mon, 30 Dec 2024 21:27:14 -0500 Subject: [PATCH 1/3] fix: use fieldId for updateFn & deleteFn has fallback to 'id' if not set --- src/sync-plugins/supabase.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/sync-plugins/supabase.ts b/src/sync-plugins/supabase.ts index 67ccbc97..67b39363 100644 --- a/src/sync-plugins/supabase.ts +++ b/src/sync-plugins/supabase.ts @@ -215,6 +215,7 @@ export function syncedSupabase< fieldUpdatedAt, fieldDeleted, realtime, + fieldId, changesSince, transform: transformParam, stringifyDates, @@ -309,7 +310,11 @@ export function syncedSupabase< ? wrapSupabaseFn(updateParam, 'update') : async (input: SupabaseRowOf, params: SyncedSetParams) => { const { onError } = params; - const res = await client.from(collection).update(input).eq('id', input.id).select(); + const res = await client + .from(collection) + .update(input) + .eq(props.fieldId || 'id', input.id) + .select(); const { data, error } = res; if (data) { const created = data[0]; @@ -337,7 +342,11 @@ export function syncedSupabase< ) => { const { onError } = params; const id = input.id; - const res = await client.from(collection).delete().eq('id', id).select(); + const res = await client + .from(collection) + .delete() + .eq(props.fieldId || 'id', id) + .select(); const { data, error } = res; if (data) { const created = data[0]; @@ -432,6 +441,7 @@ export function syncedSupabase< fieldUpdatedAt, fieldDeleted, updatePartial: false, + fieldId, transform, generateId, waitFor: () => isEnabled$.get() && (waitFor ? computeSelector(waitFor) : true), From e91d8d486ce557c6ebcde68df037a4fa5809ce9d Mon Sep 17 00:00:00 2001 From: Brandon Ly Date: Mon, 30 Dec 2024 21:34:50 -0500 Subject: [PATCH 2/3] fix: list function type assertion for syncedCrud --- src/sync-plugins/supabase.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/sync-plugins/supabase.ts b/src/sync-plugins/supabase.ts index 67b39363..763ac2ff 100644 --- a/src/sync-plugins/supabase.ts +++ b/src/sync-plugins/supabase.ts @@ -432,7 +432,9 @@ export function syncedSupabase< >({ ...rest, mode: mode || 'merge', - list, + list: list as ( + params: SyncedGetParams>, + ) => Promise[] | null>, create, update, delete: deleteFn, From 5e88446d5113f4893a5a13a5f025f73dc2947e9e Mon Sep 17 00:00:00 2001 From: Brandon Ly Date: Mon, 30 Dec 2024 22:01:03 -0500 Subject: [PATCH 3/3] fix: properly access field ID prop --- src/sync-plugins/supabase.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/sync-plugins/supabase.ts b/src/sync-plugins/supabase.ts index 763ac2ff..85f3881a 100644 --- a/src/sync-plugins/supabase.ts +++ b/src/sync-plugins/supabase.ts @@ -310,11 +310,8 @@ export function syncedSupabase< ? wrapSupabaseFn(updateParam, 'update') : async (input: SupabaseRowOf, params: SyncedSetParams) => { const { onError } = params; - const res = await client - .from(collection) - .update(input) - .eq(props.fieldId || 'id', input.id) - .select(); + const idField = props.fieldId || 'id'; + const res = await client.from(collection).update(input).eq(idField, input[idField]).select(); const { data, error } = res; if (data) { const created = data[0]; @@ -337,16 +334,12 @@ export function syncedSupabase< ? deleteParam ? wrapSupabaseFn(deleteParam, 'delete') : async ( - input: { id: SupabaseRowOf['id'] }, + input: { [key: string]: SupabaseRowOf['id'] }, params: SyncedSetParams, ) => { const { onError } = params; - const id = input.id; - const res = await client - .from(collection) - .delete() - .eq(props.fieldId || 'id', id) - .select(); + const idField = props.fieldId || 'id'; + const res = await client.from(collection).delete().eq(idField, input[idField]).select(); const { data, error } = res; if (data) { const created = data[0];