From 049dc8f6590979a70e303eb653335402b2c84f07 Mon Sep 17 00:00:00 2001 From: sultson <11300079+sultson@users.noreply.github.com> Date: Sat, 13 Jul 2024 22:43:59 +0200 Subject: [PATCH 1/2] fix: select param parsing when embedding begins with another embedding --- packages/postgrest-core/src/lib/parse-select-param.ts | 7 ++++++- .../postgrest-core/tests/lib/parse-select-param.spec.ts | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/postgrest-core/src/lib/parse-select-param.ts b/packages/postgrest-core/src/lib/parse-select-param.ts index 8556d2f7..12d7760c 100644 --- a/packages/postgrest-core/src/lib/parse-select-param.ts +++ b/packages/postgrest-core/src/lib/parse-select-param.ts @@ -7,13 +7,18 @@ 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([ { From 6eadac55283de3c51976cd1477b15a499df17c42 Mon Sep 17 00:00:00 2001 From: sultson <11300079+sultson@users.noreply.github.com> Date: Sat, 13 Jul 2024 23:41:10 +0200 Subject: [PATCH 2/2] chore: add changeset and format --- .changeset/lazy-bananas-tap.md | 3 +++ packages/postgrest-core/src/lib/parse-select-param.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/lazy-bananas-tap.md 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 12d7760c..ab7bb571 100644 --- a/packages/postgrest-core/src/lib/parse-select-param.ts +++ b/packages/postgrest-core/src/lib/parse-select-param.ts @@ -14,8 +14,12 @@ export const parseSelectParam = (s: string, currentPath?: Path): Path[] => { '2': 'selectedColumns', '3': null, }, - }).map(item => { - if (item.name === 'tableName' && item.value && !item.value.startsWith(',')) { + }).map((item) => { + if ( + item.name === 'tableName' && + item.value && + !item.value.startsWith(',') + ) { item.value = ',' + item.value; } return item;