@supabase/supabase-js 1.29.3 → 1.30.2
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 +14 -0
- package/dist/main/SupabaseClient.d.ts +11 -17
- package/dist/main/SupabaseClient.d.ts.map +1 -1
- package/dist/main/SupabaseClient.js +41 -52
- package/dist/main/SupabaseClient.js.map +1 -1
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js.map +1 -1
- package/dist/main/lib/SupabaseQueryBuilder.d.ts +2 -4
- package/dist/main/lib/SupabaseQueryBuilder.d.ts.map +1 -1
- package/dist/main/lib/SupabaseRealtimeClient.d.ts +2 -4
- package/dist/main/lib/SupabaseRealtimeClient.d.ts.map +1 -1
- package/dist/main/lib/SupabaseRealtimeClient.js.map +1 -1
- package/dist/main/lib/helpers.d.ts.map +1 -1
- package/dist/main/lib/helpers.js +1 -2
- package/dist/main/lib/helpers.js.map +1 -1
- package/dist/main/lib/types.d.ts +5 -4
- package/dist/main/lib/types.d.ts.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 +11 -17
- package/dist/module/SupabaseClient.d.ts.map +1 -1
- package/dist/module/SupabaseClient.js +40 -51
- package/dist/module/SupabaseClient.js.map +1 -1
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js.map +1 -1
- package/dist/module/lib/SupabaseQueryBuilder.d.ts +2 -4
- package/dist/module/lib/SupabaseQueryBuilder.d.ts.map +1 -1
- package/dist/module/lib/SupabaseRealtimeClient.d.ts +2 -4
- package/dist/module/lib/SupabaseRealtimeClient.d.ts.map +1 -1
- package/dist/module/lib/SupabaseRealtimeClient.js.map +1 -1
- package/dist/module/lib/helpers.d.ts.map +1 -1
- package/dist/module/lib/types.d.ts +5 -4
- package/dist/module/lib/types.d.ts.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 +4 -4
- package/src/SupabaseClient.ts +51 -77
- package/src/index.ts +1 -1
- package/src/lib/SupabaseQueryBuilder.ts +3 -3
- package/src/lib/SupabaseRealtimeClient.ts +3 -8
- package/src/lib/helpers.ts +1 -1
- package/src/lib/types.ts +5 -3
- package/src/lib/version.ts +1 -1
package/src/SupabaseClient.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_HEADERS, STORAGE_KEY } from './lib/constants'
|
|
2
2
|
import { stripTrailingSlash, isBrowser } from './lib/helpers'
|
|
3
|
-
import { Fetch, SupabaseClientOptions } from './lib/types'
|
|
3
|
+
import { Fetch, GenericObject, SupabaseClientOptions } from './lib/types'
|
|
4
4
|
import { SupabaseAuthClient } from './lib/SupabaseAuthClient'
|
|
5
5
|
import { SupabaseQueryBuilder } from './lib/SupabaseQueryBuilder'
|
|
6
6
|
import { SupabaseStorageClient } from '@supabase/storage-js'
|
|
@@ -62,13 +62,13 @@ export default class SupabaseClient {
|
|
|
62
62
|
if (!supabaseUrl) throw new Error('supabaseUrl is required.')
|
|
63
63
|
if (!supabaseKey) throw new Error('supabaseKey is required.')
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
const _supabaseUrl = stripTrailingSlash(supabaseUrl)
|
|
67
66
|
const settings = { ...DEFAULT_OPTIONS, ...options }
|
|
68
|
-
|
|
69
|
-
this.
|
|
70
|
-
this.
|
|
71
|
-
this.
|
|
67
|
+
|
|
68
|
+
this.restUrl = `${_supabaseUrl}/rest/v1`
|
|
69
|
+
this.realtimeUrl = `${_supabaseUrl}/realtime/v1`.replace('http', 'ws')
|
|
70
|
+
this.authUrl = `${_supabaseUrl}/auth/v1`
|
|
71
|
+
this.storageUrl = `${_supabaseUrl}/storage/v1`
|
|
72
72
|
this.schema = settings.schema
|
|
73
73
|
this.multiTab = settings.multiTab
|
|
74
74
|
this.fetch = settings.fetch
|
|
@@ -131,81 +131,65 @@ export default class SupabaseClient {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
|
-
*
|
|
134
|
+
* Closes and removes all subscriptions and returns a list of removed
|
|
135
|
+
* subscriptions and their errors.
|
|
135
136
|
*/
|
|
136
137
|
async removeAllSubscriptions(): Promise<
|
|
137
|
-
|
|
138
|
-
| {
|
|
139
|
-
status: 'fulfilled'
|
|
140
|
-
value: {
|
|
141
|
-
error: null
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
| { status: 'rejected'; reason: { error: Error } }
|
|
145
|
-
)[]
|
|
138
|
+
{ data: { subscription: RealtimeSubscription }; error: Error | null }[]
|
|
146
139
|
> {
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}))
|
|
158
|
-
)
|
|
159
|
-
return Promise.all(removeSubPromises)
|
|
140
|
+
const allSubs: RealtimeSubscription[] = this.getSubscriptions().slice()
|
|
141
|
+
const allSubPromises = allSubs.map((sub) => this.removeSubscription(sub))
|
|
142
|
+
const allRemovedSubs = await Promise.all(allSubPromises)
|
|
143
|
+
|
|
144
|
+
return allRemovedSubs.map(({ error }, i) => {
|
|
145
|
+
return {
|
|
146
|
+
data: { subscription: allSubs[i] },
|
|
147
|
+
error,
|
|
148
|
+
}
|
|
149
|
+
})
|
|
160
150
|
}
|
|
161
151
|
|
|
162
152
|
/**
|
|
163
|
-
*
|
|
153
|
+
* Closes and removes a subscription and returns the number of open subscriptions.
|
|
164
154
|
*
|
|
165
|
-
* @param subscription The subscription you want to remove.
|
|
155
|
+
* @param subscription The subscription you want to close and remove.
|
|
166
156
|
*/
|
|
167
|
-
removeSubscription(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
> {
|
|
174
|
-
return new Promise(async (resolve, reject) => {
|
|
175
|
-
const { error } = await this._closeSubscription(subscription)
|
|
176
|
-
|
|
177
|
-
if (error) {
|
|
178
|
-
return reject({ error })
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const allSubscriptions = this.getSubscriptions()
|
|
182
|
-
const openSubscriptionsCount = allSubscriptions.filter((chan) => chan.isJoined()).length
|
|
183
|
-
|
|
184
|
-
if (allSubscriptions.length === 0) {
|
|
185
|
-
const { error } = await this.realtime.disconnect()
|
|
157
|
+
async removeSubscription(
|
|
158
|
+
subscription: RealtimeSubscription
|
|
159
|
+
): Promise<{ data: { openSubscriptions: number }; error: Error | null }> {
|
|
160
|
+
const { error } = await this._closeSubscription(subscription)
|
|
161
|
+
const allSubs: RealtimeSubscription[] = this.getSubscriptions()
|
|
162
|
+
const openSubCount = allSubs.filter((chan) => chan.isJoined()).length
|
|
186
163
|
|
|
187
|
-
|
|
188
|
-
return reject({ error })
|
|
189
|
-
}
|
|
190
|
-
}
|
|
164
|
+
if (allSubs.length === 0) await this.realtime.disconnect()
|
|
191
165
|
|
|
192
|
-
|
|
193
|
-
data: { openSubscriptions: openSubscriptionsCount },
|
|
194
|
-
error: null,
|
|
195
|
-
})
|
|
196
|
-
})
|
|
166
|
+
return { data: { openSubscriptions: openSubCount }, error }
|
|
197
167
|
}
|
|
198
168
|
|
|
199
169
|
private async _closeSubscription(
|
|
200
170
|
subscription: RealtimeSubscription
|
|
201
|
-
): Promise<{ error:
|
|
171
|
+
): Promise<{ error: Error | null }> {
|
|
172
|
+
let error = null
|
|
173
|
+
|
|
202
174
|
if (!subscription.isClosed()) {
|
|
203
|
-
|
|
175
|
+
const { error: unsubError } = await this._unsubscribeSubscription(subscription)
|
|
176
|
+
error = unsubError
|
|
204
177
|
}
|
|
205
178
|
|
|
179
|
+
this.realtime.remove(subscription)
|
|
180
|
+
|
|
181
|
+
return { error }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
private _unsubscribeSubscription(
|
|
185
|
+
subscription: RealtimeSubscription
|
|
186
|
+
): Promise<{ error: Error | null }> {
|
|
206
187
|
return new Promise((resolve) => {
|
|
207
|
-
|
|
208
|
-
|
|
188
|
+
subscription
|
|
189
|
+
.unsubscribe()
|
|
190
|
+
.receive('ok', () => resolve({ error: null }))
|
|
191
|
+
.receive('error', (error: Error) => resolve({ error }))
|
|
192
|
+
.receive('timeout', () => resolve({ error: new Error('timed out') }))
|
|
209
193
|
})
|
|
210
194
|
}
|
|
211
195
|
|
|
@@ -254,24 +238,14 @@ export default class SupabaseClient {
|
|
|
254
238
|
})
|
|
255
239
|
}
|
|
256
240
|
|
|
257
|
-
private _getAuthHeaders():
|
|
258
|
-
const headers:
|
|
241
|
+
private _getAuthHeaders(): GenericObject {
|
|
242
|
+
const headers: GenericObject = this.headers
|
|
259
243
|
const authBearer = this.auth.session()?.access_token ?? this.supabaseKey
|
|
260
244
|
headers['apikey'] = this.supabaseKey
|
|
261
245
|
headers['Authorization'] = `Bearer ${authBearer}`
|
|
262
246
|
return headers
|
|
263
247
|
}
|
|
264
248
|
|
|
265
|
-
private _closeChannel(subscription: RealtimeSubscription): Promise<{ error: null | Error }> {
|
|
266
|
-
return new Promise((resolve, reject) => {
|
|
267
|
-
subscription
|
|
268
|
-
.unsubscribe()
|
|
269
|
-
.receive('ok', () => resolve({ error: null }))
|
|
270
|
-
.receive('error', (error: Error) => reject({ error }))
|
|
271
|
-
.receive('timeout', () => reject({ error: 'timed out' }))
|
|
272
|
-
})
|
|
273
|
-
}
|
|
274
|
-
|
|
275
249
|
private _listenForMultiTabEvents() {
|
|
276
250
|
if (!this.multiTab || !isBrowser() || !window?.addEventListener) {
|
|
277
251
|
return null
|
|
@@ -324,7 +298,7 @@ export default class SupabaseClient {
|
|
|
324
298
|
this.changedAccessToken = token
|
|
325
299
|
} else if (event === 'SIGNED_OUT' || event === 'USER_DELETED') {
|
|
326
300
|
// Token is removed
|
|
327
|
-
this.
|
|
301
|
+
this.realtime.setAuth(this.supabaseKey)
|
|
328
302
|
if (source == 'STORAGE') this.auth.signOut()
|
|
329
303
|
}
|
|
330
304
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
|
|
2
2
|
import { SupabaseRealtimeClient } from './SupabaseRealtimeClient'
|
|
3
3
|
import { RealtimeClient } from '@supabase/realtime-js'
|
|
4
|
-
import { Fetch, SupabaseEventTypes, SupabaseRealtimePayload } from './types'
|
|
4
|
+
import { Fetch, GenericObject, SupabaseEventTypes, SupabaseRealtimePayload } from './types'
|
|
5
5
|
|
|
6
6
|
export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
|
|
7
7
|
private _subscription: SupabaseRealtimeClient | null = null
|
|
8
8
|
private _realtime: RealtimeClient
|
|
9
|
-
private _headers:
|
|
9
|
+
private _headers: GenericObject
|
|
10
10
|
private _schema: string
|
|
11
11
|
private _table: string
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@ export class SupabaseQueryBuilder<T> extends PostgrestQueryBuilder<T> {
|
|
|
19
19
|
table,
|
|
20
20
|
fetch,
|
|
21
21
|
}: {
|
|
22
|
-
headers?:
|
|
22
|
+
headers?: GenericObject
|
|
23
23
|
schema: string
|
|
24
24
|
realtime: RealtimeClient
|
|
25
25
|
table: string
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { RealtimeSubscription, RealtimeClient, Transformers } from '@supabase/realtime-js'
|
|
2
|
-
import { SupabaseEventTypes, SupabaseRealtimePayload } from './types'
|
|
2
|
+
import { GenericObject, SupabaseEventTypes, SupabaseRealtimePayload } from './types'
|
|
3
3
|
|
|
4
4
|
export class SupabaseRealtimeClient {
|
|
5
5
|
subscription: RealtimeSubscription
|
|
6
6
|
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
9
|
-
headers: { [key: string]: string },
|
|
10
|
-
schema: string,
|
|
11
|
-
tableName: string
|
|
12
|
-
) {
|
|
13
|
-
const chanParams: { [key: string]: string } = {}
|
|
7
|
+
constructor(socket: RealtimeClient, headers: GenericObject, schema: string, tableName: string) {
|
|
8
|
+
const chanParams: GenericObject = {}
|
|
14
9
|
const topic = tableName === '*' ? `realtime:${schema}` : `realtime:${schema}:${tableName}`
|
|
15
10
|
const userToken = headers['Authorization'].split(' ')[1]
|
|
16
11
|
|
package/src/lib/helpers.ts
CHANGED
package/src/lib/types.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { GoTrueClient } from '@supabase/gotrue-js'
|
|
2
2
|
import { RealtimeClientOptions } from '@supabase/realtime-js'
|
|
3
3
|
|
|
4
|
-
export type Fetch = typeof fetch
|
|
5
|
-
|
|
6
4
|
type GoTrueClientOptions = ConstructorParameters<typeof GoTrueClient>[0]
|
|
7
5
|
|
|
8
6
|
export interface SupabaseAuthClientOptions extends GoTrueClientOptions {}
|
|
9
7
|
|
|
8
|
+
export type GenericObject = { [key: string]: string }
|
|
9
|
+
|
|
10
|
+
export type Fetch = typeof fetch
|
|
11
|
+
|
|
10
12
|
export type SupabaseClientOptions = {
|
|
11
13
|
/**
|
|
12
14
|
* The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to 'public'.
|
|
@@ -15,7 +17,7 @@ export type SupabaseClientOptions = {
|
|
|
15
17
|
/**
|
|
16
18
|
* Optional headers for initializing the client.
|
|
17
19
|
*/
|
|
18
|
-
headers?:
|
|
20
|
+
headers?: GenericObject
|
|
19
21
|
/**
|
|
20
22
|
* Automatically refreshes the token for logged in users.
|
|
21
23
|
*/
|
package/src/lib/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.30.2'
|