supabase-cache-helpers
supabase-cache-helpers copied to clipboard
Error when invalidating cache with useUpdateMutation and foreignTables
Describe the bug
Hi again! Just wanted to raise a small issue I ran in to when using the useUpdateMutation
regarding foreignTables during the cache invalidation flow where I ran in to an error when I have a query like this:
supabase
.from("Collection")
.select("id,name,imageEnding,type,CollectionFolder!inner(CollectionFolderTrack!inner(trackId))")
.eq("CollectionFolder.CollectionFolderTrack.trackId", id)
Then when I utilize the useUpdateMutation
i end up with an error that looks like this:
Error: Unbalanced right delimiter found in string at position 85
Which I discovered was from this matchRecursive
in this library.
const foreignTables = XRegExp.matchRecursive(
`,${s}`,
',[^,]*\\(',
'\\)',
'g',
{
valueNames: {
'0': null,
'1': 'tableName',
'2': 'selectedColumns',
'3': null,
},
},
).reduce((prev, curr, idx, matches) => {
if (curr.name === 'selectedColumns') {
const name = matches[idx - 1].value.slice(1, -1);
prev = { ...prev, [name]: curr.value };
}
return prev;
}, {});
I think the regex is having issues when parsing related tables inside parentheses without a scalar property before it because if I go from:
CollectionFolder!inner(CollectionFolderTrack!inner(trackId))
to this one (note the id added in the !inner):
CollectionFolder!inner(id,CollectionFolderTrack!inner(trackId))
Then it works great. I'm not quite sure if it's an expected behavior so I just wanted to raise it up? Regex is my kryptonite so I didn't want to spend time with a change if this was expected. Let me know!