@supabase/supabase-js 2.50.5-next.3 → 2.51.0
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/main/SupabaseClient.d.ts +14 -22
- package/dist/main/SupabaseClient.d.ts.map +1 -1
- package/dist/main/SupabaseClient.js +19 -25
- package/dist/main/SupabaseClient.js.map +1 -1
- package/dist/main/index.d.ts +1 -14
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/module/SupabaseClient.d.ts +14 -22
- package/dist/module/SupabaseClient.d.ts.map +1 -1
- package/dist/module/SupabaseClient.js +19 -25
- package/dist/module/SupabaseClient.js.map +1 -1
- package/dist/module/index.d.ts +1 -14
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/dist/umd/supabase.js +1 -1
- package/package.json +6 -6
- package/src/SupabaseClient.ts +24 -42
- package/src/index.ts +6 -20
- package/src/lib/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/supabase-js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.51.0",
|
|
4
4
|
"description": "Isomorphic Javascript client for Supabase",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"scripts": {
|
|
24
24
|
"clean": "rimraf dist docs/v2",
|
|
25
25
|
"format": "prettier --write \"{src,test}/**/*.ts\"",
|
|
26
|
-
"check:jsr": "jsr publish --dry-run",
|
|
27
26
|
"build": "run-s clean format build:*",
|
|
28
27
|
"build:main": "tsc -p tsconfig.json",
|
|
29
28
|
"build:module": "tsc -p tsconfig.module.json",
|
|
@@ -39,7 +38,7 @@
|
|
|
39
38
|
"test:watch": "jest --watch --verbose false --silent false",
|
|
40
39
|
"test:node:playwright": "cd test/integration/node-browser && npm install && cp ../../../dist/umd/supabase.js . && npm run test",
|
|
41
40
|
"test:bun": "cd test/integration/bun && bun install && bun test",
|
|
42
|
-
"test:types": "run-s build:module && tsd --files test/types/*.test-d.ts",
|
|
41
|
+
"test:types": "run-s build:module && tsd --files test/types/*.test-d.ts && jsr publish --dry-run",
|
|
43
42
|
"docs": "typedoc --entryPoints src/index.ts --out docs/v2 --includes src/**/*.ts",
|
|
44
43
|
"docs:json": "typedoc --entryPoints src/index.ts --includes src/**/*.ts --json docs/v2/spec.json --excludeExternals",
|
|
45
44
|
"serve:coverage": "npm run test:coverage && serve test/coverage",
|
|
@@ -50,11 +49,11 @@
|
|
|
50
49
|
"update:test-deps:bun": "npm run build && npm pack && cp supabase-supabase-js-*.tgz test/integration/bun/supabase-supabase-js-0.0.0-automated.tgz && cd test/integration/bun && bun install"
|
|
51
50
|
},
|
|
52
51
|
"dependencies": {
|
|
53
|
-
"@supabase/auth-js": "2.
|
|
52
|
+
"@supabase/auth-js": "2.71.0",
|
|
54
53
|
"@supabase/functions-js": "2.4.5",
|
|
55
54
|
"@supabase/node-fetch": "2.6.15",
|
|
56
|
-
"@supabase/postgrest-js": "1.
|
|
57
|
-
"@supabase/realtime-js": "2.
|
|
55
|
+
"@supabase/postgrest-js": "1.19.4",
|
|
56
|
+
"@supabase/realtime-js": "2.11.15",
|
|
58
57
|
"@supabase/storage-js": "2.7.1"
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|
|
@@ -63,6 +62,7 @@
|
|
|
63
62
|
"@types/jest": "^29.2.5",
|
|
64
63
|
"husky": "^4.3.8",
|
|
65
64
|
"jest": "^29.3.1",
|
|
65
|
+
"jsr": "^0.13.5",
|
|
66
66
|
"npm-run-all": "^4.1.5",
|
|
67
67
|
"prettier": "^2.5.1",
|
|
68
68
|
"pretty-quick": "^3.1.3",
|
package/src/SupabaseClient.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { FunctionsClient } from '@supabase/functions-js'
|
|
2
|
-
import { AuthChangeEvent
|
|
2
|
+
import { AuthChangeEvent } from '@supabase/auth-js'
|
|
3
3
|
import {
|
|
4
4
|
PostgrestClient,
|
|
5
5
|
PostgrestFilterBuilder,
|
|
6
6
|
PostgrestQueryBuilder,
|
|
7
|
-
ClientServerOptions as PostgrestClientServerOption,
|
|
8
|
-
GetGenericDatabaseWithOptions,
|
|
9
7
|
} from '@supabase/postgrest-js'
|
|
10
8
|
import {
|
|
11
9
|
RealtimeChannel,
|
|
@@ -30,18 +28,13 @@ import { Fetch, GenericSchema, SupabaseClientOptions, SupabaseAuthClientOptions
|
|
|
30
28
|
*
|
|
31
29
|
* An isomorphic Javascript client for interacting with Postgres.
|
|
32
30
|
*/
|
|
33
|
-
|
|
34
|
-
export type ServicesOptions = PostgrestClientServerOption & {}
|
|
35
|
-
|
|
36
31
|
export default class SupabaseClient<
|
|
37
32
|
Database = any,
|
|
38
|
-
|
|
39
|
-
SchemaName extends string &
|
|
40
|
-
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
|
|
33
|
+
SchemaName extends string & keyof Database = 'public' extends keyof Database
|
|
41
34
|
? 'public'
|
|
42
|
-
: string & keyof
|
|
43
|
-
Schema extends GenericSchema =
|
|
44
|
-
?
|
|
35
|
+
: string & keyof Database,
|
|
36
|
+
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
|
|
37
|
+
? Database[SchemaName]
|
|
45
38
|
: any
|
|
46
39
|
> {
|
|
47
40
|
/**
|
|
@@ -54,7 +47,7 @@ export default class SupabaseClient<
|
|
|
54
47
|
protected authUrl: URL
|
|
55
48
|
protected storageUrl: URL
|
|
56
49
|
protected functionsUrl: URL
|
|
57
|
-
protected rest: PostgrestClient<Database,
|
|
50
|
+
protected rest: PostgrestClient<Database, SchemaName, Schema>
|
|
58
51
|
protected storageKey: string
|
|
59
52
|
protected fetch?: Fetch
|
|
60
53
|
protected changedAccessToken?: string
|
|
@@ -138,7 +131,7 @@ export default class SupabaseClient<
|
|
|
138
131
|
})
|
|
139
132
|
|
|
140
133
|
if (!settings.accessToken) {
|
|
141
|
-
|
|
134
|
+
this._listenForAuthEvents()
|
|
142
135
|
}
|
|
143
136
|
}
|
|
144
137
|
|
|
@@ -163,16 +156,16 @@ export default class SupabaseClient<
|
|
|
163
156
|
from<
|
|
164
157
|
TableName extends string & keyof Schema['Tables'],
|
|
165
158
|
Table extends Schema['Tables'][TableName]
|
|
166
|
-
>(relation: TableName): PostgrestQueryBuilder<
|
|
159
|
+
>(relation: TableName): PostgrestQueryBuilder<Schema, Table, TableName>
|
|
167
160
|
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
|
|
168
161
|
relation: ViewName
|
|
169
|
-
): PostgrestQueryBuilder<
|
|
162
|
+
): PostgrestQueryBuilder<Schema, View, ViewName>
|
|
170
163
|
/**
|
|
171
164
|
* Perform a query on a table or a view.
|
|
172
165
|
*
|
|
173
166
|
* @param relation - The table or view name to query
|
|
174
167
|
*/
|
|
175
|
-
from(relation: string): PostgrestQueryBuilder<
|
|
168
|
+
from(relation: string): PostgrestQueryBuilder<Schema, any, any> {
|
|
176
169
|
return this.rest.from(relation)
|
|
177
170
|
}
|
|
178
171
|
|
|
@@ -184,11 +177,10 @@ export default class SupabaseClient<
|
|
|
184
177
|
*
|
|
185
178
|
* @param schema - The schema to query
|
|
186
179
|
*/
|
|
187
|
-
schema<DynamicSchema extends string & keyof
|
|
180
|
+
schema<DynamicSchema extends string & keyof Database>(
|
|
188
181
|
schema: DynamicSchema
|
|
189
182
|
): PostgrestClient<
|
|
190
183
|
Database,
|
|
191
|
-
ClientOptions,
|
|
192
184
|
DynamicSchema,
|
|
193
185
|
Database[DynamicSchema] extends GenericSchema ? Database[DynamicSchema] : any
|
|
194
186
|
> {
|
|
@@ -228,7 +220,6 @@ export default class SupabaseClient<
|
|
|
228
220
|
count?: 'exact' | 'planned' | 'estimated'
|
|
229
221
|
} = {}
|
|
230
222
|
): PostgrestFilterBuilder<
|
|
231
|
-
ClientOptions,
|
|
232
223
|
Schema,
|
|
233
224
|
Fn['Returns'] extends any[]
|
|
234
225
|
? Fn['Returns'][number] extends Record<string, unknown>
|
|
@@ -237,8 +228,7 @@ export default class SupabaseClient<
|
|
|
237
228
|
: never,
|
|
238
229
|
Fn['Returns'],
|
|
239
230
|
FnName,
|
|
240
|
-
null
|
|
241
|
-
'RPC'
|
|
231
|
+
null
|
|
242
232
|
> {
|
|
243
233
|
return this.rest.rpc(fn, args, options)
|
|
244
234
|
}
|
|
@@ -278,7 +268,7 @@ export default class SupabaseClient<
|
|
|
278
268
|
return this.realtime.removeAllChannels()
|
|
279
269
|
}
|
|
280
270
|
|
|
281
|
-
|
|
271
|
+
private async _getAccessToken() {
|
|
282
272
|
if (this.accessToken) {
|
|
283
273
|
return await this.accessToken()
|
|
284
274
|
}
|
|
@@ -288,7 +278,7 @@ export default class SupabaseClient<
|
|
|
288
278
|
return data.session?.access_token ?? null
|
|
289
279
|
}
|
|
290
280
|
|
|
291
|
-
|
|
281
|
+
private _initSupabaseAuthClient(
|
|
292
282
|
{
|
|
293
283
|
autoRefreshToken,
|
|
294
284
|
persistSession,
|
|
@@ -301,7 +291,7 @@ export default class SupabaseClient<
|
|
|
301
291
|
}: SupabaseAuthClientOptions,
|
|
302
292
|
headers?: Record<string, string>,
|
|
303
293
|
fetch?: Fetch
|
|
304
|
-
)
|
|
294
|
+
) {
|
|
305
295
|
const authHeaders = {
|
|
306
296
|
Authorization: `Bearer ${this.supabaseKey}`,
|
|
307
297
|
apikey: `${this.supabaseKey}`,
|
|
@@ -324,23 +314,21 @@ export default class SupabaseClient<
|
|
|
324
314
|
})
|
|
325
315
|
}
|
|
326
316
|
|
|
327
|
-
|
|
317
|
+
private _initRealtimeClient(options: RealtimeClientOptions) {
|
|
328
318
|
return new RealtimeClient(this.realtimeUrl.href, {
|
|
329
319
|
...options,
|
|
330
320
|
params: { ...{ apikey: this.supabaseKey }, ...options?.params },
|
|
331
321
|
})
|
|
332
322
|
}
|
|
333
323
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
async () => await this._handleTokenChanged(event, 'CLIENT', session?.access_token),
|
|
338
|
-
0
|
|
339
|
-
)
|
|
324
|
+
private _listenForAuthEvents() {
|
|
325
|
+
let data = this.auth.onAuthStateChange((event, session) => {
|
|
326
|
+
this._handleTokenChanged(event, 'CLIENT', session?.access_token)
|
|
340
327
|
})
|
|
328
|
+
return data
|
|
341
329
|
}
|
|
342
330
|
|
|
343
|
-
|
|
331
|
+
private _handleTokenChanged(
|
|
344
332
|
event: AuthChangeEvent,
|
|
345
333
|
source: 'CLIENT' | 'STORAGE',
|
|
346
334
|
token?: string
|
|
@@ -350,16 +338,10 @@ export default class SupabaseClient<
|
|
|
350
338
|
this.changedAccessToken !== token
|
|
351
339
|
) {
|
|
352
340
|
this.changedAccessToken = token
|
|
353
|
-
this.realtime.setAuth(token)
|
|
354
341
|
} else if (event === 'SIGNED_OUT') {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
} catch (error) {
|
|
359
|
-
console.log('Failed to set auth for realtime client:', error)
|
|
360
|
-
} finally {
|
|
361
|
-
this.changedAccessToken = undefined
|
|
362
|
-
}
|
|
342
|
+
this.realtime.setAuth()
|
|
343
|
+
if (source == 'STORAGE') this.auth.signOut()
|
|
344
|
+
this.changedAccessToken = undefined
|
|
363
345
|
}
|
|
364
346
|
}
|
|
365
347
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import SupabaseClient from './SupabaseClient'
|
|
2
2
|
import type { GenericSchema, SupabaseClientOptions } from './lib/types'
|
|
3
|
-
import type { ServicesOptions } from './SupabaseClient'
|
|
4
|
-
import type { GetGenericDatabaseWithOptions } from '@supabase/postgrest-js'
|
|
5
3
|
|
|
6
4
|
export * from '@supabase/auth-js'
|
|
7
5
|
export type { User as AuthUser, Session as AuthSession } from '@supabase/auth-js'
|
|
@@ -28,28 +26,16 @@ export type { SupabaseClientOptions, QueryResult, QueryData, QueryError } from '
|
|
|
28
26
|
*/
|
|
29
27
|
export const createClient = <
|
|
30
28
|
Database = any,
|
|
31
|
-
|
|
32
|
-
SchemaName extends string &
|
|
33
|
-
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
|
|
29
|
+
SchemaName extends string & keyof Database = 'public' extends keyof Database
|
|
34
30
|
? 'public'
|
|
35
|
-
: string & keyof
|
|
36
|
-
Schema =
|
|
37
|
-
?
|
|
31
|
+
: string & keyof Database,
|
|
32
|
+
Schema extends GenericSchema = Database[SchemaName] extends GenericSchema
|
|
33
|
+
? Database[SchemaName]
|
|
38
34
|
: any
|
|
39
35
|
>(
|
|
40
36
|
supabaseUrl: string,
|
|
41
37
|
supabaseKey: string,
|
|
42
38
|
options?: SupabaseClientOptions<SchemaName>
|
|
43
|
-
): SupabaseClient<
|
|
44
|
-
Database,
|
|
45
|
-
ClientOptions,
|
|
46
|
-
SchemaName,
|
|
47
|
-
Schema extends GenericSchema ? Schema : any
|
|
48
|
-
> => {
|
|
49
|
-
return new SupabaseClient<
|
|
50
|
-
Database,
|
|
51
|
-
ClientOptions,
|
|
52
|
-
SchemaName,
|
|
53
|
-
Schema extends GenericSchema ? Schema : any
|
|
54
|
-
>(supabaseUrl, supabaseKey, options)
|
|
39
|
+
): SupabaseClient<Database, SchemaName, Schema> => {
|
|
40
|
+
return new SupabaseClient<Database, SchemaName, Schema>(supabaseUrl, supabaseKey, options)
|
|
55
41
|
}
|
package/src/lib/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '2.
|
|
1
|
+
export const version = '2.51.0'
|