Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/add-vue-que…
Browse files Browse the repository at this point in the history
…ry-package

* upstream/main:
  chore: update versions
  Update tests
  Changeset
  Add tests and fixes for deletes with useSubscriptionQuery
  fix(deps): update dependency eslint-config-universe to v12.1.0
  chore: update versions
  Add changeset
  Adding additional base case and tests
  fix: correctly parse and sort using JSON expressions
  chore(deps): update react monorepo to v18.3.0
  fix(deps): update nextjs monorepo to v14.2.0
  chore(deps): update dependency @testing-library/react to v14.3.0
  • Loading branch information
cpannwitz committed May 25, 2024
2 parents ce5b967 + ef874a9 commit 805d2f9
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 23 deletions.
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"@types/react-dom": "^18.0.7",
"@vercel/analytics": "^1.0.0",
"eslint": "8.54.0",
"eslint-config-next": "14.1.0",
"next": "14.1.0",
"eslint-config-next": "14.2.0",
"next": "14.2.0",
"nextra": "2.13.2",
"nextra-theme-docs": "2.13.2",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependencies": {
"eslint": "8.54.0",
"eslint-config-turbo": "1.10.16",
"eslint-config-universe": "12.0.0"
"eslint-config-universe": "12.1.0"
},
"devDependencies": {
"typescript": "5.4.2"
Expand Down
6 changes: 6 additions & 0 deletions packages/postgrest-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @supabase-cache-helpers/postgrest-core

## 0.5.0

### Minor Changes

- 7a99711: Adds support for parsing JSON arrow expressions in order clauses

## 0.4.7

### Patch Changes
Expand Down
25 changes: 25 additions & 0 deletions packages/postgrest-core/__tests__/lib/get.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { get } from '../../src/lib/get';

describe('get', () => {
it.each([
[{ a: 1 }, 'a', undefined, 1], // simple case
[{ a: 1 }, 'b', 2, 2], // default case
[{ a: 1 }, '', undefined, undefined], // empty case
[{ a: { b: 1 } }, 'a.b', undefined, 1], // dot syntax
[{ a: { b: 1 } }, 'a,b', undefined, 1], // comma syntax
[{ a: { b: 1 } }, 'a[b]', undefined, 1], // bracket syntax
[{ a: { b: { c: { d: 1 } } } }, 'a.b,c.[d]', undefined, 1], // combination syntax
[{ a: { b: 1 } }, 'a->b', undefined, 1], // json value syntax
[{ a: { b: 1 } }, 'a->>b', undefined, '1'], // json string syntax
[{ a: [1, 2] }, 'a->0', undefined, 1], // json array value syntax
[{ a: [1, 2] }, 'a->>0', undefined, '1'], // json array string syntax
[{ a: { b: { c: 1 } } }, 'a->b->c', undefined, 1], // nested json syntax
[{ a: { b: { c: 1 } } }, 'a->b->>c', undefined, '1'],
[{ a: { b: [1, 2] } }, 'a.b->0', undefined, 1],
[{ a: { b: [1, 2] } }, 'a.b->>0', undefined, '1'],
[{ a: { b: 1 } }, 'a->0', undefined, undefined], // not an array
[{ a: [1, 2] }, 'a->2', undefined, undefined], // missing array value
])('get(%j, "%s", %s) should be %s', (obj, path, defaultValue, expected) => {
expect(get(obj, path, defaultValue)).toEqual(expected);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('parseOrderByKey', () => {
c = createClient('https://localhost', '1234');
});

it('should parse forth and bock correctly', () => {
it('should parse forth and back correctly', () => {
const parser = new PostgrestParser(
c
.from('test')
Expand Down
25 changes: 25 additions & 0 deletions packages/postgrest-core/__tests__/lib/sorted-comparator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,29 @@ describe('sortedComparator', () => {
{ value_1: new Date('December 3, 1995 03:24:00'), value_2: 3 },
]);
});

it('json column', () => {
expect(
[
{ json: { value_1: 1 }, value_2: 1 },
{ json: { value_1: 3 }, value_2: 3 },
{ json: { value_1: 2 }, value_2: 2 },
].sort(
buildSortedComparator<{
json: { value_1: number };
value_2: number;
}>([
{
column: 'json->value_1',
ascending: true,
nullsFirst: false,
},
]),
),
).toEqual([
{ json: { value_1: 1 }, value_2: 1 },
{ json: { value_1: 2 }, value_2: 2 },
{ json: { value_1: 3 }, value_2: 3 },
]);
});
});
2 changes: 1 addition & 1 deletion packages/postgrest-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@supabase-cache-helpers/postgrest-core",
"version": "0.4.7",
"version": "0.5.0",
"main": "./dist/index.js",
"source": "./src/index.ts",
"exports": {
Expand Down
28 changes: 19 additions & 9 deletions packages/postgrest-core/src/lib/get.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
export const get = (obj: any, path: string, defaultValue: any = undefined) => {
const travel = (regexp: RegExp) =>
String.prototype.split
.call(path, regexp)
.filter(Boolean)
.reduce(
(res, key) => (res !== null && res !== undefined ? res[key] : res),
obj,
);
const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/);
const split = path.split(/((?:\.|,|\[|\]|->>|->)+)/g);
let result: any = obj;
for (let i = -1; i < split.length; i += 2) {
const separator = split[i];
let key: string | number = split[i + 1];
if (!key) {
continue;
}
if (separator?.endsWith('->') || separator?.endsWith('->>')) {
if (/^\d+$/.test(key)) {
key = parseInt(key, 10);
}
}
if (separator?.endsWith('->>')) {
result = `${result ? result[key] : result}`;
} else {
result = result ? result[key] : result;
}
}
return result === undefined || result === obj ? defaultValue : result;
};
13 changes: 13 additions & 0 deletions packages/postgrest-react-query/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @supabase-cache-helpers/postgrest-react-query

## 1.6.4

### Patch Changes

- 3116e61: fix: correctly handle delete payloads in useSubscriptionQuery

## 1.6.3

### Patch Changes

- Updated dependencies [7a99711]
- @supabase-cache-helpers/postgrest-core@0.5.0

## 1.6.2

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ describe('useSubscriptionQuery', () => {
);
expect(screen.getByTestId('count').textContent).toEqual('count: 1');
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
await act(async () => {
await client
.from('contact')
.delete()
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('count: 0', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 0');
unmount();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ describe('useSubscription', () => {
await screen.findByText('ticket_number: 5', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 1');
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
await act(async () => {
await client
.from('contact')
.delete()
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('count: 0', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 0');
unmount();
});
});
4 changes: 2 additions & 2 deletions packages/postgrest-react-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@supabase-cache-helpers/postgrest-react-query",
"version": "1.6.2",
"version": "1.6.4",
"author": "Philipp Steinrötter <[email protected]>",
"homepage": "https://supabase-cache-helpers.vercel.app",
"bugs": {
Expand Down Expand Up @@ -58,7 +58,7 @@
"devDependencies": {
"@supabase/supabase-js": "2.38.5",
"@supabase/postgrest-js": "1.9.0",
"@testing-library/react": "14.2.0",
"@testing-library/react": "14.3.0",
"@testing-library/jest-dom": "6.4.0",
"jest-environment-jsdom": "29.7.0",
"@types/jest": "29.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function useSubscriptionQuery<
} else if (
payload.eventType === REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE
) {
await deleteItem(data as Record<string, unknown>);
await deleteItem(payload.old);
}
if (opts?.callback) {
opts.callback({
Expand Down
13 changes: 13 additions & 0 deletions packages/postgrest-swr/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @supabase-cache-helpers/postgrest-swr

## 1.7.3

### Patch Changes

- 3116e61: fix: correctly handle delete payloads in useSubscriptionQuery

## 1.7.2

### Patch Changes

- Updated dependencies [7a99711]
- @supabase-cache-helpers/postgrest-core@0.5.0

## 1.7.1

### Patch Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ describe('useSubscriptionQuery', () => {
);
expect(screen.getByTestId('count').textContent).toEqual('count: 1');
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
await act(async () => {
await client
.from('contact')
.delete()
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('count: 0', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 0');
unmount();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,18 @@ describe('useSubscription', () => {
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
await screen.findByText('ticket_number: 5', {}, { timeout: 20000 });
await screen.findByText('cbCalled: true', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 1');
await act(async () => {
await client
.from('contact')
.delete()
.eq('username', USERNAME_1)
.throwOnError();
});
await screen.findByText('count: 0', {}, { timeout: 10000 });
expect(screen.getByTestId('count').textContent).toEqual('count: 0');
unmount();
});
});
4 changes: 2 additions & 2 deletions packages/postgrest-swr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@supabase-cache-helpers/postgrest-swr",
"version": "1.7.1",
"version": "1.7.3",
"author": "Philipp Steinrötter <[email protected]>",
"homepage": "https://supabase-cache-helpers.vercel.app",
"bugs": {
Expand Down Expand Up @@ -67,7 +67,7 @@
"@supabase/postgrest-js": "1.9.0",
"@supabase/supabase-js": "2.38.5",
"@testing-library/jest-dom": "6.4.0",
"@testing-library/react": "14.2.0",
"@testing-library/react": "14.3.0",
"@types/jest": "29.5.0",
"@types/react": "18.2.0",
"dotenv": "16.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function useSubscriptionQuery<
} else if (
payload.eventType === REALTIME_POSTGRES_CHANGES_LISTEN_EVENT.DELETE
) {
await deleteItem(data as Record<string, unknown>);
await deleteItem(payload.old);
}
if (opts?.callback) {
opts.callback({
Expand Down
2 changes: 1 addition & 1 deletion packages/storage-react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"devDependencies": {
"@supabase/supabase-js": "2.38.5",
"@supabase/storage-js": "2.5.5",
"@testing-library/react": "14.2.0",
"@testing-library/react": "14.3.0",
"@testing-library/jest-dom": "6.4.0",
"jest-environment-jsdom": "29.7.0",
"@types/jest": "29.5.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/storage-swr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"devDependencies": {
"@supabase/supabase-js": "2.38.5",
"@supabase/storage-js": "2.5.5",
"@testing-library/react": "14.2.0",
"@testing-library/react": "14.3.0",
"@testing-library/jest-dom": "6.4.0",
"jest-environment-jsdom": "29.7.0",
"@types/jest": "29.5.0",
Expand Down

0 comments on commit 805d2f9

Please sign in to comment.