Skip to content

Commit 9ef7ee0

Browse files
committed
chore: use string based version
1 parent c5f81be commit 9ef7ee0

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/PostgrestTransformBuilder.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import PostgrestBuilder from './PostgrestBuilder'
22
import { InvalidMethodError } from './PostgrestFilterBuilder'
33
import { GetResult } from './select-query-parser/result'
4-
import { GenericSchema, CheckMatchingArrayTypes, ClientServerOptions } from './types'
4+
import {
5+
GenericSchema,
6+
CheckMatchingArrayTypes,
7+
ClientServerOptions,
8+
MaxAffectedEnabled,
9+
} from './types'
510

611
export default class PostgrestTransformBuilder<
712
ClientOptions extends ClientServerOptions,
@@ -346,15 +351,15 @@ export default class PostgrestTransformBuilder<
346351
*
347352
* @param value - The maximum number of rows that can be affected
348353
*/
349-
maxAffected(value: number): ClientOptions['postgrestVersion'] extends 13
354+
maxAffected(value: number): MaxAffectedEnabled<ClientOptions['postgrestVersion']> extends true
350355
? // TODO: update the RPC case to only work on RPC that returns SETOF rows
351356
Method extends 'PATCH' | 'DELETE' | 'RPC'
352357
? this
353358
: InvalidMethodError<'maxAffected method only available on update or delete'>
354359
: InvalidMethodError<'maxAffected method only available on postgrest 13+'> {
355360
this.headers.append('Prefer', 'handling=strict')
356361
this.headers.append('Prefer', `max-affected=${value}`)
357-
return this as unknown as ClientOptions['postgrestVersion'] extends 13
362+
return this as unknown as MaxAffectedEnabled<ClientOptions['postgrestVersion']> extends true
358363
? Method extends 'PATCH' | 'DELETE' | 'RPC'
359364
? this
360365
: InvalidMethodError<'maxAffected method only available on update or delete'>

src/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ export type GetGenericDatabaseWithOptions<
9696
: DatabaseWithOptions<Omit<Database, typeof INTERNAL_SUPABASE_OPTIONS>, Opts>
9797
: DatabaseWithOptions<Database, Opts>
9898

99+
export type MaxAffectedEnabled<postgrestVersion extends string | undefined> =
100+
postgrestVersion extends `13${string}` ? true : false
101+
99102
// https://twitter.com/mattpocockuk/status/1622730173446557697
100103
export type Prettify<T> = { [K in keyof T]: T[K] } & {}
101104

0 commit comments

Comments
 (0)