diff --git a/.changeset/lazy-bananas-tap.md b/.changeset/lazy-bananas-tap.md new file mode 100644 index 00000000..862bf797 --- /dev/null +++ b/.changeset/lazy-bananas-tap.md @@ -0,0 +1,3 @@ +--- +"@supabase-cache-helpers/postgrest-core": patch +--- diff --git a/packages/postgrest-core/src/lib/parse-select-param.ts b/packages/postgrest-core/src/lib/parse-select-param.ts index 8556d2f7..ab7bb571 100644 --- a/packages/postgrest-core/src/lib/parse-select-param.ts +++ b/packages/postgrest-core/src/lib/parse-select-param.ts @@ -7,13 +7,22 @@ export const parseSelectParam = (s: string, currentPath?: Path): Path[] => { let result; try { - result = XRegExp.matchRecursive(`,${s}`, ',[^,]*\\(', '\\)', 'g', { + result = XRegExp.matchRecursive(`,${s}`, '([^,\\(]+)\\(', '\\)', 'g', { valueNames: { '0': null, '1': 'tableName', '2': 'selectedColumns', '3': null, }, + }).map((item) => { + if ( + item.name === 'tableName' && + item.value && + !item.value.startsWith(',') + ) { + item.value = ',' + item.value; + } + return item; }); } catch (e) { const path = currentPath?.path diff --git a/packages/postgrest-core/tests/lib/parse-select-param.spec.ts b/packages/postgrest-core/tests/lib/parse-select-param.spec.ts index 789de7b4..49b11126 100644 --- a/packages/postgrest-core/tests/lib/parse-select-param.spec.ts +++ b/packages/postgrest-core/tests/lib/parse-select-param.spec.ts @@ -39,7 +39,7 @@ describe('parseSelectParam', () => { it('should work for special case', () => { expect( parseSelectParam( - 'id,team_members:team_member_team_id_fkey(team_id,employee!team_member_employee_id_fkey(id,display_name,user_id))', + 'id,team_members:team_member_team_id_fkey(employee!team_member_employee_id_fkey(id,display_name,user_id),team_id)', ), ).toEqual([ {