Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 24db26e

Browse files
committed
feat: use undefined as bottom value instead of null
BREAKING CHANGE: use undefined as bottom value instead of null
1 parent 586e6cd commit 24db26e

File tree

9 files changed

+188
-193
lines changed

9 files changed

+188
-193
lines changed

src/PostgrestBuilder.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ export default abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
4141
* @deprecated Use `throwOnError` in the `PostgrestClient` constructor instead.
4242
*/
4343
throwOnError(throwOnError?: boolean): this {
44-
if (throwOnError === null || throwOnError === undefined) {
45-
throwOnError = true
46-
}
47-
this.shouldThrowOnError = throwOnError
44+
this.shouldThrowOnError = throwOnError ?? true
4845
return this
4946
}
5047

@@ -76,9 +73,9 @@ export default abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
7673
body: JSON.stringify(this.body),
7774
signal: this.signal,
7875
}).then(async (res) => {
79-
let error = null
80-
let data = null
81-
let count = null
76+
let error = undefined
77+
let data = undefined
78+
let count = undefined
8279
let status = res.status
8380
let statusText = res.statusText
8481

@@ -112,7 +109,7 @@ export default abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
112109
}
113110

114111
if (error && this.allowEmpty && error?.details?.includes('Results contain 0 rows')) {
115-
error = null
112+
error = undefined
116113
status = 200
117114
statusText = 'OK'
118115
}
@@ -140,8 +137,8 @@ export default abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
140137
hint: '',
141138
code: fetchError.code || '',
142139
},
143-
data: null,
144-
count: null,
140+
data: undefined,
141+
count: undefined,
145142
status: 400,
146143
statusText: 'Bad Request',
147144
}))

src/PostgrestClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ export default class PostgrestClient {
8080
params: Record<string, unknown> = {},
8181
{
8282
head = false,
83-
count = null,
83+
count,
8484
}: {
8585
head?: boolean
86-
count?: null | 'exact' | 'planned' | 'estimated'
86+
count?: 'exact' | 'planned' | 'estimated'
8787
} = {}
8888
): PostgrestFilterBuilder<T> {
8989
let method: 'HEAD' | 'POST'

src/PostgrestFilterBuilder.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,7 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
314314
textSearch(
315315
column: keyof T,
316316
query: string,
317-
{
318-
config,
319-
type = null,
320-
}: { config?: string; type?: 'plain' | 'phrase' | 'websearch' | null } = {}
317+
{ config, type }: { config?: string; type?: 'plain' | 'phrase' | 'websearch' } = {}
321318
): this {
322319
let typePart = ''
323320
if (type === 'plain') {

src/PostgrestQueryBuilder.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
3939
columns = '*',
4040
{
4141
head = false,
42-
count = null,
42+
count,
4343
}: {
4444
head?: boolean
45-
count?: null | 'exact' | 'planned' | 'estimated'
45+
count?: 'exact' | 'planned' | 'estimated'
4646
} = {}
4747
): PostgrestFilterBuilder<T> {
4848
this.method = 'GET'
@@ -79,9 +79,9 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
7979
insert(
8080
values: Partial<T> | Partial<T>[],
8181
{
82-
count = null,
82+
count,
8383
}: {
84-
count?: null | 'exact' | 'planned' | 'estimated'
84+
count?: 'exact' | 'planned' | 'estimated'
8585
} = {}
8686
): PostgrestFilterBuilder<T> {
8787
this.method = 'POST'
@@ -120,11 +120,11 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
120120
values: Partial<T> | Partial<T>[],
121121
{
122122
onConflict,
123-
count = null,
123+
count,
124124
ignoreDuplicates = false,
125125
}: {
126126
onConflict?: string
127-
count?: null | 'exact' | 'planned' | 'estimated'
127+
count?: 'exact' | 'planned' | 'estimated'
128128
ignoreDuplicates?: boolean
129129
} = {}
130130
): PostgrestFilterBuilder<T> {
@@ -154,9 +154,9 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
154154
update(
155155
values: Partial<T>,
156156
{
157-
count = null,
157+
count,
158158
}: {
159-
count?: null | 'exact' | 'planned' | 'estimated'
159+
count?: 'exact' | 'planned' | 'estimated'
160160
} = {}
161161
): PostgrestFilterBuilder<T> {
162162
this.method = 'PATCH'
@@ -178,9 +178,9 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
178178
* @param count Count algorithm to use to count rows in a table.
179179
*/
180180
delete({
181-
count = null,
181+
count,
182182
}: {
183-
count?: null | 'exact' | 'planned' | 'estimated'
183+
count?: 'exact' | 'planned' | 'estimated'
184184
} = {}): PostgrestFilterBuilder<T> {
185185
this.method = 'DELETE'
186186
const prefersHeaders = []

src/types.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ interface PostgrestResponseBase {
2323
}
2424

2525
interface PostgrestResponseSuccess<T> extends PostgrestResponseBase {
26-
error: null
26+
error: undefined
2727
data: T[]
28-
count: number | null
28+
count: number | undefined
2929
}
3030
interface PostgrestResponseFailure extends PostgrestResponseBase {
3131
error: PostgrestError
32-
data: null
33-
count: null
32+
data: undefined
33+
count: undefined
3434
}
3535
export type PostgrestResponse<T> = PostgrestResponseSuccess<T> | PostgrestResponseFailure
3636

3737
interface PostgrestSingleResponseSuccess<T> extends PostgrestResponseBase {
38-
error: null
38+
error: undefined
3939
data: T
40+
count: number | undefined
4041
}
4142
export type PostgrestSingleResponse<T> =
4243
| PostgrestSingleResponseSuccess<T>
4344
| PostgrestResponseFailure
44-
export type PostgrestMaybeSingleResponse<T> = PostgrestSingleResponse<T | null>
45+
export type PostgrestMaybeSingleResponse<T> = PostgrestSingleResponse<T | undefined>

0 commit comments

Comments
 (0)