Skip to content

Commit

Permalink
Merge pull request #278 from supabase/BREAK/null-to-undefined
Browse files Browse the repository at this point in the history
feat: use undefined as bottom value instead of null
  • Loading branch information
soedirgo authored Jun 8, 2022
2 parents a7ea5a6 + 628be73 commit 3ac4acb
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 193 deletions.
17 changes: 7 additions & 10 deletions src/PostgrestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ export default abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
* @deprecated Use `throwOnError` in the `PostgrestClient` constructor instead.
*/
throwOnError(throwOnError?: boolean): this {
if (throwOnError === null || throwOnError === undefined) {
throwOnError = true
}
this.shouldThrowOnError = throwOnError
this.shouldThrowOnError = throwOnError ?? true
return this
}

Expand Down Expand Up @@ -76,9 +73,9 @@ export default abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
body: JSON.stringify(this.body),
signal: this.signal,
}).then(async (res) => {
let error = null
let data = null
let count = null
let error = undefined
let data = undefined
let count = undefined
let status = res.status
let statusText = res.statusText

Expand Down Expand Up @@ -112,7 +109,7 @@ export default abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
}

if (error && this.allowEmpty && error?.details?.includes('Results contain 0 rows')) {
error = null
error = undefined
status = 200
statusText = 'OK'
}
Expand Down Expand Up @@ -140,8 +137,8 @@ export default abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
hint: '',
code: fetchError.code || '',
},
data: null,
count: null,
data: undefined,
count: undefined,
status: 400,
statusText: 'Bad Request',
}))
Expand Down
4 changes: 2 additions & 2 deletions src/PostgrestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ export default class PostgrestClient {
params: Record<string, unknown> = {},
{
head = false,
count = null,
count,
}: {
head?: boolean
count?: null | 'exact' | 'planned' | 'estimated'
count?: 'exact' | 'planned' | 'estimated'
} = {}
): PostgrestFilterBuilder<T> {
let method: 'HEAD' | 'POST'
Expand Down
5 changes: 1 addition & 4 deletions src/PostgrestFilterBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,7 @@ export default class PostgrestFilterBuilder<T> extends PostgrestTransformBuilder
textSearch(
column: keyof T,
query: string,
{
config,
type = null,
}: { config?: string; type?: 'plain' | 'phrase' | 'websearch' | null } = {}
{ config, type }: { config?: string; type?: 'plain' | 'phrase' | 'websearch' } = {}
): this {
let typePart = ''
if (type === 'plain') {
Expand Down
20 changes: 10 additions & 10 deletions src/PostgrestQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
columns = '*',
{
head = false,
count = null,
count,
}: {
head?: boolean
count?: null | 'exact' | 'planned' | 'estimated'
count?: 'exact' | 'planned' | 'estimated'
} = {}
): PostgrestFilterBuilder<T> {
this.method = 'GET'
Expand Down Expand Up @@ -79,9 +79,9 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
insert(
values: Partial<T> | Partial<T>[],
{
count = null,
count,
}: {
count?: null | 'exact' | 'planned' | 'estimated'
count?: 'exact' | 'planned' | 'estimated'
} = {}
): PostgrestFilterBuilder<T> {
this.method = 'POST'
Expand Down Expand Up @@ -120,11 +120,11 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
values: Partial<T> | Partial<T>[],
{
onConflict,
count = null,
count,
ignoreDuplicates = false,
}: {
onConflict?: string
count?: null | 'exact' | 'planned' | 'estimated'
count?: 'exact' | 'planned' | 'estimated'
ignoreDuplicates?: boolean
} = {}
): PostgrestFilterBuilder<T> {
Expand Down Expand Up @@ -154,9 +154,9 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
update(
values: Partial<T>,
{
count = null,
count,
}: {
count?: null | 'exact' | 'planned' | 'estimated'
count?: 'exact' | 'planned' | 'estimated'
} = {}
): PostgrestFilterBuilder<T> {
this.method = 'PATCH'
Expand All @@ -178,9 +178,9 @@ export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> {
* @param count Count algorithm to use to count rows in a table.
*/
delete({
count = null,
count,
}: {
count?: null | 'exact' | 'planned' | 'estimated'
count?: 'exact' | 'planned' | 'estimated'
} = {}): PostgrestFilterBuilder<T> {
this.method = 'DELETE'
const prefersHeaders = []
Expand Down
13 changes: 7 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ interface PostgrestResponseBase {
}

interface PostgrestResponseSuccess<T> extends PostgrestResponseBase {
error: null
error: undefined
data: T[]
count: number | null
count: number | undefined
}
interface PostgrestResponseFailure extends PostgrestResponseBase {
error: PostgrestError
data: null
count: null
data: undefined
count: undefined
}
export type PostgrestResponse<T> = PostgrestResponseSuccess<T> | PostgrestResponseFailure

interface PostgrestSingleResponseSuccess<T> extends PostgrestResponseBase {
error: null
error: undefined
data: T
count: number | undefined
}
export type PostgrestSingleResponse<T> =
| PostgrestSingleResponseSuccess<T>
| PostgrestResponseFailure
export type PostgrestMaybeSingleResponse<T> = PostgrestSingleResponse<T | null>
export type PostgrestMaybeSingleResponse<T> = PostgrestSingleResponse<T | undefined>
Loading

0 comments on commit 3ac4acb

Please sign in to comment.