1
- import type { PostgrestBuilder } from " @supabase/postgrest-js" ;
1
+ import type { PostgrestBuilder } from ' @supabase/postgrest-js' ;
2
2
3
- import { encodeObject } from " ./lib/encode-object" ;
4
- import { isObject } from " ./lib/is-object" ;
5
- import type { OrderDefinition } from " ./lib/query-types" ;
6
- import { sortSearchParams } from " ./lib/sort-search-param" ;
3
+ import { encodeObject } from ' ./lib/encode-object' ;
4
+ import { isObject } from ' ./lib/is-object' ;
5
+ import type { OrderDefinition } from ' ./lib/query-types' ;
6
+ import { sortSearchParams } from ' ./lib/sort-search-param' ;
7
7
import {
8
8
PostgrestQueryParser ,
9
9
type PostgrestQueryParserOptions ,
10
- } from " ./postgrest-query-parser" ;
11
- import { getTableFromUrl } from " ./lib/get-table-from-url" ;
10
+ } from ' ./postgrest-query-parser' ;
11
+ import { getTableFromUrl } from ' ./lib/get-table-from-url' ;
12
12
13
13
export class PostgrestParser < Result > extends PostgrestQueryParser {
14
14
private readonly _url : URL ;
15
15
private readonly _headers : { [ key : string ] : string } ;
16
16
private readonly _body : object | undefined ;
17
- private readonly _method : " GET" | " HEAD" | " POST" | " PATCH" | " DELETE" ;
17
+ private readonly _method : ' GET' | ' HEAD' | ' POST' | ' PATCH' | ' DELETE' ;
18
18
19
19
public readonly queryKey : string ;
20
20
public readonly bodyKey : string | undefined ;
@@ -31,12 +31,12 @@ export class PostgrestParser<Result> extends PostgrestQueryParser {
31
31
fb : PostgrestBuilder < Result > ,
32
32
public readonly opts ?: PostgrestQueryParserOptions
33
33
) {
34
- super ( new URL ( fb [ " url" ] ) . searchParams . toString ( ) , opts ) ;
34
+ super ( new URL ( fb [ ' url' ] ) . searchParams . toString ( ) , opts ) ;
35
35
36
- this . _url = new URL ( fb [ " url" ] ) ;
37
- this . _headers = { ...fb [ " headers" ] } ;
38
- this . _body = isObject ( fb [ " body" ] ) ? { ...fb [ " body" ] } : undefined ;
39
- this . _method = fb [ " method" ] ;
36
+ this . _url = new URL ( fb [ ' url' ] ) ;
37
+ this . _headers = { ...fb [ ' headers' ] } ;
38
+ this . _body = isObject ( fb [ ' body' ] ) ? { ...fb [ ' body' ] } : undefined ;
39
+ this . _method = fb [ ' method' ] ;
40
40
41
41
this . queryKey = sortSearchParams ( this . _url . searchParams ) . toString ( ) ;
42
42
@@ -48,38 +48,38 @@ export class PostgrestParser<Result> extends PostgrestQueryParser {
48
48
49
49
// 'Prefer': return=minimal|representation,count=exact|planned|estimated
50
50
const preferHeaders : Record < string , string > = (
51
- this . _headers [ " Prefer" ] ?? ""
51
+ this . _headers [ ' Prefer' ] ?? ''
52
52
)
53
- . split ( "," )
53
+ . split ( ',' )
54
54
. reduce < Record < string , string > > ( ( prev , curr ) => {
55
- const s = curr . split ( "=" ) ;
55
+ const s = curr . split ( '=' ) ;
56
56
return {
57
57
...prev ,
58
58
[ s [ 0 ] ] : s [ 1 ] ,
59
59
} ;
60
60
} , { } ) ;
61
- this . count = preferHeaders [ " count" ] ?? null ;
61
+ this . count = preferHeaders [ ' count' ] ?? null ;
62
62
63
- this . schema = fb [ " schema" ] as string ;
63
+ this . schema = fb [ ' schema' ] as string ;
64
64
65
- this . isHead = this . _method === " HEAD" ;
65
+ this . isHead = this . _method === ' HEAD' ;
66
66
67
- const limit = this . _url . searchParams . get ( " limit" ) ;
67
+ const limit = this . _url . searchParams . get ( ' limit' ) ;
68
68
this . limit = limit ? Number ( limit ) : undefined ;
69
- const offset = this . _url . searchParams . get ( " offset" ) ;
69
+ const offset = this . _url . searchParams . get ( ' offset' ) ;
70
70
this . offset = offset ? Number ( offset ) : undefined ;
71
71
72
72
this . _url . searchParams . forEach ( ( value , key ) => {
73
- const split = key . split ( "." ) ;
74
- if ( split [ split . length === 2 ? 1 : 0 ] === " order" ) {
73
+ const split = key . split ( '.' ) ;
74
+ if ( split [ split . length === 2 ? 1 : 0 ] === ' order' ) {
75
75
// separated by ,
76
- const orderByDefs = value . split ( "," ) ;
76
+ const orderByDefs = value . split ( ',' ) ;
77
77
orderByDefs . forEach ( ( def ) => {
78
- const [ column , ascending , nullsFirst ] = def . split ( "." ) ;
78
+ const [ column , ascending , nullsFirst ] = def . split ( '.' ) ;
79
79
this . orderBy . push ( {
80
- ascending : ascending === " asc" ,
80
+ ascending : ascending === ' asc' ,
81
81
column,
82
- nullsFirst : nullsFirst === " nullsfirst" ,
82
+ nullsFirst : nullsFirst === ' nullsfirst' ,
83
83
foreignTable : split . length === 2 ? split [ 0 ] : undefined ,
84
84
} ) ;
85
85
} ) ;
@@ -88,10 +88,10 @@ export class PostgrestParser<Result> extends PostgrestQueryParser {
88
88
this . orderByKey = this . orderBy
89
89
. map (
90
90
( { column, ascending, nullsFirst, foreignTable } ) =>
91
- `${ foreignTable ? `${ foreignTable } .` : "" } ${ column } :${
92
- ascending ? " asc" : " desc"
93
- } .${ nullsFirst ? " nullsFirst" : " nullsLast" } `
91
+ `${ foreignTable ? `${ foreignTable } .` : '' } ${ column } :${
92
+ ascending ? ' asc' : ' desc'
93
+ } .${ nullsFirst ? ' nullsFirst' : ' nullsLast' } `
94
94
)
95
- . join ( "|" ) ;
95
+ . join ( '|' ) ;
96
96
}
97
97
}
0 commit comments