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