@svadmin/supabase 0.9.4 → 0.9.5
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/package.json +16 -2
- package/src/data-provider.ts +1 -0
- package/src/live-provider.ts +24 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@svadmin/supabase",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "Supabase adapters — DataProvider, AuthProvider, LiveProvider, AuditHandler",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"peerDependencies": {
|
|
19
|
-
"@svadmin/core": "^0.
|
|
19
|
+
"@svadmin/core": "^0.23.3",
|
|
20
20
|
"@supabase/supabase-js": "^2.0.0",
|
|
21
21
|
"@refinedev/supabase": "^5.0.0",
|
|
22
22
|
"@svadmin/refine-adapter": "^0.9.3"
|
|
@@ -31,5 +31,19 @@
|
|
|
31
31
|
"homepage": "https://github.com/zuohuadong/svadmin#readme",
|
|
32
32
|
"bugs": {
|
|
33
33
|
"url": "https://github.com/zuohuadong/svadmin/issues"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@svadmin/core": {
|
|
37
|
+
"optional": true
|
|
38
|
+
},
|
|
39
|
+
"@supabase/supabase-js": {
|
|
40
|
+
"optional": true
|
|
41
|
+
},
|
|
42
|
+
"@refinedev/supabase": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"@svadmin/refine-adapter": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
34
48
|
}
|
|
35
49
|
}
|
package/src/data-provider.ts
CHANGED
|
@@ -11,6 +11,7 @@ export async function createSupabaseDataProvider(...args: any[]): Promise<DataPr
|
|
|
11
11
|
// @ts-ignore Peer dependency
|
|
12
12
|
const pkg = (await import('@refinedev/supabase')) as any;
|
|
13
13
|
const init: any = pkg.dataProvider || pkg.default || pkg.DataProvider;
|
|
14
|
+
if (typeof init !== 'function') throw new Error('[svadmin] Failed to resolve @refinedev/supabase data provider. Ensure the package is installed correctly.');
|
|
14
15
|
const refineProvider = init(...args);
|
|
15
16
|
return createRefineAdapter(refineProvider);
|
|
16
17
|
}
|
package/src/live-provider.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { LiveProvider, LiveEvent } from '@svadmin/core';
|
|
|
5
5
|
export function createSupabaseLiveProvider(client: SupabaseClient): LiveProvider {
|
|
6
6
|
const subscribers = new Map<string, Set<(event: LiveEvent) => void>>();
|
|
7
7
|
const channels = new Map<string, RealtimeChannel>();
|
|
8
|
+
const broadcastChannels = new Map<string, RealtimeChannel>();
|
|
8
9
|
|
|
9
10
|
function getOrCreateChannel(resource: string): RealtimeChannel {
|
|
10
11
|
let channel = channels.get(resource);
|
|
@@ -33,6 +34,23 @@ export function createSupabaseLiveProvider(client: SupabaseClient): LiveProvider
|
|
|
33
34
|
return channel;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
function getOrCreateBroadcastChannel(resource: string): RealtimeChannel {
|
|
38
|
+
let channel = broadcastChannels.get(resource);
|
|
39
|
+
if (!channel) {
|
|
40
|
+
const existing = channels.get(resource);
|
|
41
|
+
if (existing) return existing;
|
|
42
|
+
channel = client.channel(`live-bc-${resource}`)
|
|
43
|
+
.on('broadcast', { event: 'live-event' }, ({ payload }) => {
|
|
44
|
+
if (payload) {
|
|
45
|
+
subscribers.get(resource)?.forEach(cb => cb(payload as LiveEvent));
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.subscribe();
|
|
49
|
+
broadcastChannels.set(resource, channel);
|
|
50
|
+
}
|
|
51
|
+
return channel;
|
|
52
|
+
}
|
|
53
|
+
|
|
36
54
|
return {
|
|
37
55
|
subscribe({ resource, callback }) {
|
|
38
56
|
if (!subscribers.has(resource)) subscribers.set(resource, new Set());
|
|
@@ -51,13 +69,18 @@ export function createSupabaseLiveProvider(client: SupabaseClient): LiveProvider
|
|
|
51
69
|
channel.unsubscribe();
|
|
52
70
|
channels.delete(resource);
|
|
53
71
|
}
|
|
72
|
+
const bc = broadcastChannels.get(resource);
|
|
73
|
+
if (bc) {
|
|
74
|
+
bc.unsubscribe();
|
|
75
|
+
broadcastChannels.delete(resource);
|
|
76
|
+
}
|
|
54
77
|
}
|
|
55
78
|
}
|
|
56
79
|
};
|
|
57
80
|
},
|
|
58
81
|
|
|
59
82
|
publish(event: LiveEvent) {
|
|
60
|
-
const channel =
|
|
83
|
+
const channel = getOrCreateBroadcastChannel(event.resource);
|
|
61
84
|
channel.send({
|
|
62
85
|
type: 'broadcast',
|
|
63
86
|
event: 'live-event',
|