@svadmin/pocketbase 0.9.3 → 0.9.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@svadmin/pocketbase",
3
- "version": "0.9.3",
3
+ "version": "0.9.4",
4
4
  "description": "PocketBase adapters — DataProvider, AuthProvider, LiveProvider for svadmin",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "peerDependencies": {
19
- "@svadmin/core": "^0.19.4",
19
+ "@svadmin/core": "^0.22.1",
20
20
  "pocketbase": ">=0.21.0"
21
21
  },
22
22
  "keywords": [
@@ -10,7 +10,7 @@ interface PocketBaseLiveOptions {
10
10
  interface PBClientRealtime {
11
11
  collection: (name: string) => {
12
12
  subscribe: (topic: string, callback: (data: PBRealtimeEvent) => void) => Promise<void>;
13
- unsubscribe: (topic?: string) => Promise<void>;
13
+ unsubscribe: (topic?: string, callback?: (data: PBRealtimeEvent) => void) => Promise<void>;
14
14
  };
15
15
  }
16
16
 
@@ -48,17 +48,18 @@ export function createPocketBaseLiveProvider(options: PocketBaseLiveOptions): Li
48
48
 
49
49
  return {
50
50
  subscribe({ resource, callback }) {
51
- // PocketBase subscribe uses '*' for all events on a collection
52
- pb.collection(resource).subscribe('*', (data) => {
51
+ const handler = (data: PBRealtimeEvent) => {
53
52
  callback({
54
53
  type: mapAction(data.action),
55
54
  resource,
56
55
  payload: data.record,
57
56
  });
58
- });
57
+ };
58
+
59
+ pb.collection(resource).subscribe('*', handler).catch(console.error);
59
60
 
60
61
  return () => {
61
- pb.collection(resource).unsubscribe('*');
62
+ pb.collection(resource).unsubscribe('*', handler).catch(console.error);
62
63
  };
63
64
  },
64
65
  };
@@ -207,6 +207,6 @@ describe('PocketBase LiveProvider', () => {
207
207
  const lp = createPocketBaseLiveProvider({ pb });
208
208
  const unsub = lp.subscribe({ resource: 'posts', callback: () => {} });
209
209
  unsub();
210
- expect(mockCollection.unsubscribe).toHaveBeenCalledWith('*');
210
+ expect(mockCollection.unsubscribe).toHaveBeenCalledWith('*', expect.any(Function));
211
211
  });
212
212
  });