Skip to content

Commit 93f9eab

Browse files
authored
fix: boolean import (#642)
1 parent 6f1fd45 commit 93f9eab

File tree

9 files changed

+52
-3
lines changed

9 files changed

+52
-3
lines changed

.changeset/kind-swans-add.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@supabase-cache-helpers/postgrest-server": patch
3+
---
4+
5+
fix: dont eval 'false' as empty

examples/react-query/types/database.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ export type Database = {
277277
[_ in never]: never;
278278
};
279279
Functions: {
280+
boolean_return: {
281+
Args: Record<PropertyKey, never>;
282+
Returns: boolean;
283+
};
280284
contacts_cursor: {
281285
Args: {
282286
v_username_cursor?: string;

examples/swr/types/database.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ export type Database = {
277277
[_ in never]: never;
278278
};
279279
Functions: {
280+
boolean_return: {
281+
Args: Record<PropertyKey, never>;
282+
Returns: boolean;
283+
};
280284
contacts_cursor: {
281285
Args: {
282286
v_username_cursor?: string;

packages/postgrest-core/tests/database.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ export type Database = {
277277
[_ in never]: never;
278278
};
279279
Functions: {
280+
boolean_return: {
281+
Args: Record<PropertyKey, never>;
282+
Returns: boolean;
283+
};
280284
contacts_cursor: {
281285
Args: {
282286
v_username_cursor?: string;

packages/postgrest-react-query/tests/database.types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,10 @@ export type Database = {
277277
[_ in never]: never;
278278
};
279279
Functions: {
280+
boolean_return: {
281+
Args: Record<PropertyKey, never>;
282+
Returns: boolean;
283+
};
280284
contacts_cursor: {
281285
Args: {
282286
v_username_cursor?: string;

packages/postgrest-server/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function isEmpty<Result>(result: Value<Result>) {
1515
return false;
1616
}
1717

18-
if (!result.data) {
18+
if (result.data === null || typeof result.data === 'undefined') {
1919
return true;
2020
}
2121

packages/postgrest-server/tests/query-cache.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,27 @@ describe('QueryCache', () => {
169169
expect(spy).toHaveBeenCalledTimes(2);
170170
});
171171

172+
it('should store boolean results', async () => {
173+
const map = new Map();
174+
175+
const cache = new QueryCache(ctx, {
176+
stores: [new MemoryStore({ persistentMap: map })],
177+
fresh: 1000,
178+
stale: 2000,
179+
});
180+
181+
const query = client.rpc('boolean_return').maybeSingle();
182+
183+
const spy = vi.spyOn(query, 'then');
184+
185+
const res = await cache.query(query);
186+
const res2 = await cache.query(query);
187+
188+
expect(res.data).toBe(false);
189+
expect(res2.data).toBe(false);
190+
expect(spy).toHaveBeenCalledTimes(1);
191+
});
192+
172193
it('should not store result if store() returns false', async () => {
173194
const map = new Map();
174195

packages/postgrest-swr/tests/database.types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export type Database = {
109109
tags?: string[] | null;
110110
ticket_number?: number | null;
111111
username?: string | null;
112-
has_low_ticket_number?: boolean | null;
113112
};
114113
Update: {
115114
age_range?: unknown | null;
@@ -123,7 +122,6 @@ export type Database = {
123122
tags?: string[] | null;
124123
ticket_number?: number | null;
125124
username?: string | null;
126-
has_low_ticket_number?: boolean | null;
127125
};
128126
Relationships: [
129127
{
@@ -279,6 +277,10 @@ export type Database = {
279277
[_ in never]: never;
280278
};
281279
Functions: {
280+
boolean_return: {
281+
Args: Record<PropertyKey, never>;
282+
Returns: boolean;
283+
};
282284
contacts_cursor: {
283285
Args: {
284286
v_username_cursor?: string;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
create or replace function public.boolean_return() returns boolean
2+
as $$
3+
select false;
4+
$$ language sql stable set search_path = '';
5+

0 commit comments

Comments
 (0)