@techfinityedge/koolbase-react-native 4.2.0 → 4.2.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 +11 -12
- package/dist/realtime.js +12 -7
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -297,26 +297,25 @@ await Koolbase.storage.delete('avatars', `user-${userId}.jpg`);
|
|
|
297
297
|
|
|
298
298
|
## Realtime
|
|
299
299
|
|
|
300
|
-
Subscribe to live changes on a collection.
|
|
301
|
-
|
|
300
|
+
Subscribe to live changes on a collection. Uses the signed-in user's session, so
|
|
301
|
+
subscribe after login. Streams `created`, `updated`, and `deleted` events for
|
|
302
302
|
collections whose read rule is `public` or `authenticated`.
|
|
303
303
|
|
|
304
304
|
```ts
|
|
305
|
-
import { Koolbase } from '@techfinityedge/koolbase-react-native';
|
|
306
|
-
|
|
307
305
|
const unsubscribe = Koolbase.realtime.subscribe('messages', (event) => {
|
|
308
|
-
// event.type
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
306
|
+
// event.type -> 'created' | 'updated' | 'deleted'
|
|
307
|
+
if (event.type === 'deleted') {
|
|
308
|
+
console.log('deleted', event.recordId); // recordId on deletes
|
|
309
|
+
} else {
|
|
310
|
+
console.log(event.type, event.record!.data); // record on created/updated
|
|
311
|
+
}
|
|
312
312
|
});
|
|
313
313
|
|
|
314
|
-
unsubscribe();
|
|
314
|
+
unsubscribe();
|
|
315
315
|
```
|
|
316
316
|
|
|
317
|
-
The socket opens lazily
|
|
318
|
-
|
|
319
|
-
don't pass it.
|
|
317
|
+
The socket opens lazily, is shared, and reconnects automatically. The project is
|
|
318
|
+
taken from the user's session..
|
|
320
319
|
|
|
321
320
|
---
|
|
322
321
|
|
package/dist/realtime.js
CHANGED
|
@@ -94,13 +94,18 @@ class KoolbaseRealtime {
|
|
|
94
94
|
if (!mapped)
|
|
95
95
|
return; // ignore subscribed / unsubscribed / error / unknown
|
|
96
96
|
const payload = raw.payload;
|
|
97
|
-
if (!payload || !payload.collection
|
|
98
|
-
return;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
collection: payload.collection,
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
if (!payload || !payload.collection)
|
|
98
|
+
return;
|
|
99
|
+
let msg;
|
|
100
|
+
if (mapped === 'deleted') {
|
|
101
|
+
msg = { type: 'deleted', collection: payload.collection, recordId: payload.record_id };
|
|
102
|
+
}
|
|
103
|
+
else if (payload.record) {
|
|
104
|
+
msg = { type: mapped, collection: payload.collection, record: (0, record_1.recordFromWire)(payload.record) };
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
104
109
|
(this.listeners.get(payload.collection) ?? []).forEach((cb) => cb(msg));
|
|
105
110
|
};
|
|
106
111
|
ws.onclose = () => {
|
package/dist/types.d.ts
CHANGED
|
@@ -160,7 +160,8 @@ export interface UploadOptions {
|
|
|
160
160
|
export interface RealtimeEvent {
|
|
161
161
|
type: 'created' | 'updated' | 'deleted';
|
|
162
162
|
collection: string;
|
|
163
|
-
record
|
|
163
|
+
record?: KoolbaseRecord;
|
|
164
|
+
recordId?: string;
|
|
164
165
|
}
|
|
165
166
|
export type RealtimeCallback = (event: RealtimeEvent) => void;
|
|
166
167
|
export interface BootstrapPayload {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@techfinityedge/koolbase-react-native",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "React Native SDK for Koolbase — auth, database, storage, realtime, feature flags, and functions in one package.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|