@supabase/postgrest-js 3.0.0-next.2 → 3.0.0-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +14 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +346 -28
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +346 -28
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +14 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/PostgrestBuilder.ts +10 -6
- package/src/PostgrestClient.ts +3 -3
- package/src/PostgrestError.ts +6 -0
- package/src/PostgrestFilterBuilder.ts +37 -2
- package/src/PostgrestQueryBuilder.ts +7 -83
- package/src/version.ts +1 -1
package/package.json
CHANGED
package/src/PostgrestBuilder.ts
CHANGED
|
@@ -96,7 +96,7 @@ export default abstract class PostgrestBuilder<
|
|
|
96
96
|
* ```ts
|
|
97
97
|
* import { createClient } from '@supabase/supabase-js'
|
|
98
98
|
*
|
|
99
|
-
* const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-
|
|
99
|
+
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
|
100
100
|
* const { data, error } = await supabase.from('users').select('*')
|
|
101
101
|
* ```
|
|
102
102
|
*
|
|
@@ -108,7 +108,7 @@ export default abstract class PostgrestBuilder<
|
|
|
108
108
|
*
|
|
109
109
|
* const builder = new PostgrestQueryBuilder(
|
|
110
110
|
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
111
|
-
* { headers: new Headers({ apikey: 'publishable-
|
|
111
|
+
* { headers: new Headers({ apikey: 'your-publishable-key' }) }
|
|
112
112
|
* )
|
|
113
113
|
* ```
|
|
114
114
|
*/
|
|
@@ -321,9 +321,13 @@ export default abstract class PostgrestBuilder<
|
|
|
321
321
|
),
|
|
322
322
|
signal: this.signal,
|
|
323
323
|
})
|
|
324
|
-
} catch (fetchError
|
|
324
|
+
} catch (fetchError) {
|
|
325
325
|
// Never retry aborted requests
|
|
326
|
-
if (
|
|
326
|
+
if (
|
|
327
|
+
fetchError instanceof Error &&
|
|
328
|
+
(fetchError.name === 'AbortError' ||
|
|
329
|
+
('code' in fetchError && (fetchError as { code?: string }).code === 'ABORT_ERR'))
|
|
330
|
+
) {
|
|
327
331
|
throw fetchError
|
|
328
332
|
}
|
|
329
333
|
|
|
@@ -446,7 +450,7 @@ export default abstract class PostgrestBuilder<
|
|
|
446
450
|
*/
|
|
447
451
|
private async processResponse(res: Response): Promise<{
|
|
448
452
|
success: boolean
|
|
449
|
-
error:
|
|
453
|
+
error: PostgrestError | null
|
|
450
454
|
data: any
|
|
451
455
|
count: number | null
|
|
452
456
|
status: number
|
|
@@ -533,7 +537,7 @@ export default abstract class PostgrestBuilder<
|
|
|
533
537
|
|
|
534
538
|
return {
|
|
535
539
|
success: error === null,
|
|
536
|
-
error,
|
|
540
|
+
error: error ? new PostgrestError(error) : null,
|
|
537
541
|
data,
|
|
538
542
|
count,
|
|
539
543
|
status,
|
package/src/PostgrestClient.ts
CHANGED
|
@@ -62,7 +62,7 @@ export default class PostgrestClient<
|
|
|
62
62
|
* ```ts
|
|
63
63
|
* import { createClient } from '@supabase/supabase-js'
|
|
64
64
|
*
|
|
65
|
-
* const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-
|
|
65
|
+
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
|
66
66
|
* const { data, error } = await supabase.from('profiles').select('*')
|
|
67
67
|
* ```
|
|
68
68
|
*
|
|
@@ -77,7 +77,7 @@ export default class PostgrestClient<
|
|
|
77
77
|
* import { PostgrestClient } from '@supabase/postgrest-js'
|
|
78
78
|
*
|
|
79
79
|
* const postgrest = new PostgrestClient('https://xyzcompany.supabase.co/rest/v1', {
|
|
80
|
-
* headers: { apikey: 'publishable-
|
|
80
|
+
* headers: { apikey: 'your-publishable-key' },
|
|
81
81
|
* schema: 'public',
|
|
82
82
|
* timeout: 30000, // 30 second timeout
|
|
83
83
|
* })
|
|
@@ -389,7 +389,7 @@ export default class PostgrestClient<
|
|
|
389
389
|
}: {
|
|
390
390
|
head?: boolean
|
|
391
391
|
get?: boolean
|
|
392
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
392
|
+
count?: 'exact' | 'planned' | 'estimated' | (string & {})
|
|
393
393
|
} = {}
|
|
394
394
|
): PostgrestFilterBuilder<
|
|
395
395
|
ClientOptions,
|
package/src/PostgrestError.ts
CHANGED
|
@@ -23,6 +23,12 @@ export default class PostgrestError extends Error {
|
|
|
23
23
|
*/
|
|
24
24
|
constructor(context: { message: string; details: string; hint: string; code: string }) {
|
|
25
25
|
super(context.message)
|
|
26
|
+
Object.defineProperty(this, 'message', {
|
|
27
|
+
value: context.message,
|
|
28
|
+
enumerable: true,
|
|
29
|
+
writable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
})
|
|
26
32
|
this.name = 'PostgrestError'
|
|
27
33
|
this.details = context.details
|
|
28
34
|
this.hint = context.hint
|
|
@@ -76,6 +76,22 @@ type ResolveFilterRelationshipValue<
|
|
|
76
76
|
|
|
77
77
|
export type InvalidMethodError<S extends string> = { Error: S }
|
|
78
78
|
|
|
79
|
+
type NonNullableColumn<T extends Record<string, unknown>, Col extends string> = Col extends keyof T
|
|
80
|
+
? { [K in keyof T]: K extends Col ? NonNullable<T[K]> : T[K] }
|
|
81
|
+
: T
|
|
82
|
+
|
|
83
|
+
type NarrowResultColumn<T, Col extends string> = T extends (infer Item)[]
|
|
84
|
+
? Item extends Record<string, unknown>
|
|
85
|
+
? Col extends keyof Item
|
|
86
|
+
? { [K in keyof Item]: K extends Col ? NonNullable<Item[K]> : Item[K] }[]
|
|
87
|
+
: T
|
|
88
|
+
: T
|
|
89
|
+
: T extends Record<string, unknown>
|
|
90
|
+
? Col extends keyof T
|
|
91
|
+
? { [K in keyof T]: K extends Col ? NonNullable<T[K]> : T[K] }
|
|
92
|
+
: T
|
|
93
|
+
: T
|
|
94
|
+
|
|
79
95
|
export default class PostgrestFilterBuilder<
|
|
80
96
|
ClientOptions extends ClientServerOptions,
|
|
81
97
|
Schema extends GenericSchema,
|
|
@@ -1719,6 +1735,20 @@ export default class PostgrestFilterBuilder<
|
|
|
1719
1735
|
return this
|
|
1720
1736
|
}
|
|
1721
1737
|
|
|
1738
|
+
not<ColumnName extends string & keyof Row>(
|
|
1739
|
+
column: ColumnName,
|
|
1740
|
+
operator: 'is',
|
|
1741
|
+
value: null
|
|
1742
|
+
): PostgrestFilterBuilder<
|
|
1743
|
+
ClientOptions,
|
|
1744
|
+
Schema,
|
|
1745
|
+
NonNullableColumn<Row, ColumnName>,
|
|
1746
|
+
NarrowResultColumn<Result, ColumnName>,
|
|
1747
|
+
RelationName,
|
|
1748
|
+
Relationships,
|
|
1749
|
+
Method
|
|
1750
|
+
> &
|
|
1751
|
+
this
|
|
1722
1752
|
not<ColumnName extends string & keyof Row>(
|
|
1723
1753
|
column: ColumnName,
|
|
1724
1754
|
operator: FilterOperator,
|
|
@@ -1783,9 +1813,14 @@ export default class PostgrestFilterBuilder<
|
|
|
1783
1813
|
*
|
|
1784
1814
|
* ```
|
|
1785
1815
|
*/
|
|
1786
|
-
not(
|
|
1816
|
+
not(
|
|
1817
|
+
column: string,
|
|
1818
|
+
operator: string,
|
|
1819
|
+
value: unknown
|
|
1820
|
+
): PostgrestFilterBuilder<ClientOptions, Schema, any, any, RelationName, Relationships, Method> &
|
|
1821
|
+
this {
|
|
1787
1822
|
this.url.searchParams.append(column, `not.${operator}.${value}`)
|
|
1788
|
-
return this
|
|
1823
|
+
return this as any
|
|
1789
1824
|
}
|
|
1790
1825
|
|
|
1791
1826
|
/**
|
|
@@ -48,7 +48,7 @@ export default class PostgrestQueryBuilder<
|
|
|
48
48
|
* ```ts
|
|
49
49
|
* import { createClient } from '@supabase/supabase-js'
|
|
50
50
|
*
|
|
51
|
-
* const supabase = createClient('https://xyzcompany.supabase.co', 'publishable-
|
|
51
|
+
* const supabase = createClient('https://xyzcompany.supabase.co', 'your-publishable-key')
|
|
52
52
|
* const { data, error } = await supabase.from('users').select('*')
|
|
53
53
|
* ```
|
|
54
54
|
*
|
|
@@ -58,7 +58,7 @@ export default class PostgrestQueryBuilder<
|
|
|
58
58
|
*
|
|
59
59
|
* const query = new PostgrestQueryBuilder(
|
|
60
60
|
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
|
|
61
|
-
* { headers: { apikey: 'publishable-
|
|
61
|
+
* { headers: { apikey: 'your-publishable-key' }, retry: true }
|
|
62
62
|
* )
|
|
63
63
|
* ```
|
|
64
64
|
*/
|
|
@@ -889,7 +889,7 @@ export default class PostgrestQueryBuilder<
|
|
|
889
889
|
columns?: Query,
|
|
890
890
|
options?: {
|
|
891
891
|
head?: boolean
|
|
892
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
892
|
+
count?: 'exact' | 'planned' | 'estimated' | (string & {})
|
|
893
893
|
}
|
|
894
894
|
): PostgrestFilterBuilder<
|
|
895
895
|
ClientOptions,
|
|
@@ -936,42 +936,6 @@ export default class PostgrestQueryBuilder<
|
|
|
936
936
|
})
|
|
937
937
|
}
|
|
938
938
|
|
|
939
|
-
// TODO(v3): Make `defaultToNull` consistent for both single & bulk inserts.
|
|
940
|
-
insert<Row extends Relation extends { Insert: unknown } ? Relation['Insert'] : never>(
|
|
941
|
-
values: RejectExcessProperties<
|
|
942
|
-
Relation extends { Insert: unknown } ? Relation['Insert'] : never,
|
|
943
|
-
Row
|
|
944
|
-
>,
|
|
945
|
-
options?: {
|
|
946
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
947
|
-
}
|
|
948
|
-
): PostgrestFilterBuilder<
|
|
949
|
-
ClientOptions,
|
|
950
|
-
Schema,
|
|
951
|
-
Relation['Row'],
|
|
952
|
-
null,
|
|
953
|
-
RelationName,
|
|
954
|
-
Relationships,
|
|
955
|
-
'POST'
|
|
956
|
-
>
|
|
957
|
-
insert<Row extends Relation extends { Insert: unknown } ? Relation['Insert'] : never>(
|
|
958
|
-
values: RejectExcessProperties<
|
|
959
|
-
Relation extends { Insert: unknown } ? Relation['Insert'] : never,
|
|
960
|
-
Row
|
|
961
|
-
>[],
|
|
962
|
-
options?: {
|
|
963
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
964
|
-
defaultToNull?: boolean
|
|
965
|
-
}
|
|
966
|
-
): PostgrestFilterBuilder<
|
|
967
|
-
ClientOptions,
|
|
968
|
-
Schema,
|
|
969
|
-
Relation['Row'],
|
|
970
|
-
null,
|
|
971
|
-
RelationName,
|
|
972
|
-
Relationships,
|
|
973
|
-
'POST'
|
|
974
|
-
>
|
|
975
939
|
/**
|
|
976
940
|
* Perform an INSERT into the table or view.
|
|
977
941
|
*
|
|
@@ -1097,7 +1061,7 @@ export default class PostgrestQueryBuilder<
|
|
|
1097
1061
|
count,
|
|
1098
1062
|
defaultToNull = true,
|
|
1099
1063
|
}: {
|
|
1100
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
1064
|
+
count?: 'exact' | 'planned' | 'estimated' | (string & {})
|
|
1101
1065
|
defaultToNull?: boolean
|
|
1102
1066
|
} = {}
|
|
1103
1067
|
): PostgrestFilterBuilder<
|
|
@@ -1139,46 +1103,6 @@ export default class PostgrestQueryBuilder<
|
|
|
1139
1103
|
})
|
|
1140
1104
|
}
|
|
1141
1105
|
|
|
1142
|
-
// TODO(v3): Make `defaultToNull` consistent for both single & bulk upserts.
|
|
1143
|
-
upsert<Row extends Relation extends { Insert: unknown } ? Relation['Insert'] : never>(
|
|
1144
|
-
values: RejectExcessProperties<
|
|
1145
|
-
Relation extends { Insert: unknown } ? Relation['Insert'] : never,
|
|
1146
|
-
Row
|
|
1147
|
-
>,
|
|
1148
|
-
options?: {
|
|
1149
|
-
onConflict?: string
|
|
1150
|
-
ignoreDuplicates?: boolean
|
|
1151
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
1152
|
-
}
|
|
1153
|
-
): PostgrestFilterBuilder<
|
|
1154
|
-
ClientOptions,
|
|
1155
|
-
Schema,
|
|
1156
|
-
Relation['Row'],
|
|
1157
|
-
null,
|
|
1158
|
-
RelationName,
|
|
1159
|
-
Relationships,
|
|
1160
|
-
'POST'
|
|
1161
|
-
>
|
|
1162
|
-
upsert<Row extends Relation extends { Insert: unknown } ? Relation['Insert'] : never>(
|
|
1163
|
-
values: RejectExcessProperties<
|
|
1164
|
-
Relation extends { Insert: unknown } ? Relation['Insert'] : never,
|
|
1165
|
-
Row
|
|
1166
|
-
>[],
|
|
1167
|
-
options?: {
|
|
1168
|
-
onConflict?: string
|
|
1169
|
-
ignoreDuplicates?: boolean
|
|
1170
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
1171
|
-
defaultToNull?: boolean
|
|
1172
|
-
}
|
|
1173
|
-
): PostgrestFilterBuilder<
|
|
1174
|
-
ClientOptions,
|
|
1175
|
-
Schema,
|
|
1176
|
-
Relation['Row'],
|
|
1177
|
-
null,
|
|
1178
|
-
RelationName,
|
|
1179
|
-
Relationships,
|
|
1180
|
-
'POST'
|
|
1181
|
-
>
|
|
1182
1106
|
/**
|
|
1183
1107
|
* Perform an UPSERT on the table or view. Depending on the column(s) passed
|
|
1184
1108
|
* to `onConflict`, `.upsert()` allows you to perform the equivalent of
|
|
@@ -1406,7 +1330,7 @@ export default class PostgrestQueryBuilder<
|
|
|
1406
1330
|
}: {
|
|
1407
1331
|
onConflict?: string
|
|
1408
1332
|
ignoreDuplicates?: boolean
|
|
1409
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
1333
|
+
count?: 'exact' | 'planned' | 'estimated' | (string & {})
|
|
1410
1334
|
defaultToNull?: boolean
|
|
1411
1335
|
} = {}
|
|
1412
1336
|
): PostgrestFilterBuilder<
|
|
@@ -1598,7 +1522,7 @@ export default class PostgrestQueryBuilder<
|
|
|
1598
1522
|
{
|
|
1599
1523
|
count,
|
|
1600
1524
|
}: {
|
|
1601
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
1525
|
+
count?: 'exact' | 'planned' | 'estimated' | (string & {})
|
|
1602
1526
|
} = {}
|
|
1603
1527
|
): PostgrestFilterBuilder<
|
|
1604
1528
|
ClientOptions,
|
|
@@ -1749,7 +1673,7 @@ export default class PostgrestQueryBuilder<
|
|
|
1749
1673
|
delete({
|
|
1750
1674
|
count,
|
|
1751
1675
|
}: {
|
|
1752
|
-
count?: 'exact' | 'planned' | 'estimated'
|
|
1676
|
+
count?: 'exact' | 'planned' | 'estimated' | (string & {})
|
|
1753
1677
|
} = {}): PostgrestFilterBuilder<
|
|
1754
1678
|
ClientOptions,
|
|
1755
1679
|
Schema,
|
package/src/version.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// - Debugging and support (identifying which version is running)
|
|
5
5
|
// - Telemetry and logging (version reporting in errors/analytics)
|
|
6
6
|
// - Ensuring build artifacts match the published package version
|
|
7
|
-
export const version = '3.0.0-next.
|
|
7
|
+
export const version = '3.0.0-next.21'
|