@base44-preview/sdk 0.8.13-pr.58.bc6cdc5 → 0.8.13-pr.58.f5a13ad
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/dist/modules/entities.js
CHANGED
|
@@ -39,7 +39,8 @@ function parseRealtimeMessage(dataStr) {
|
|
|
39
39
|
timestamp: parsed.timestamp || new Date().toISOString(),
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
catch (
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.warn("[Base44 SDK] Failed to parse realtime message:", error);
|
|
43
44
|
return null;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -119,7 +120,7 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
|
119
120
|
});
|
|
120
121
|
},
|
|
121
122
|
// Subscribe to realtime updates
|
|
122
|
-
subscribe(callback) {
|
|
123
|
+
async subscribe(callback) {
|
|
123
124
|
const room = `entities:${appId}:${entityName}`;
|
|
124
125
|
// Get the socket and subscribe to the room
|
|
125
126
|
const socket = getSocket();
|
|
@@ -129,7 +130,12 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
|
129
130
|
if (!event) {
|
|
130
131
|
return;
|
|
131
132
|
}
|
|
132
|
-
|
|
133
|
+
try {
|
|
134
|
+
callback(event);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error("[Base44 SDK] Subscription callback error:", error);
|
|
138
|
+
}
|
|
133
139
|
},
|
|
134
140
|
});
|
|
135
141
|
return unsubscribe;
|
|
@@ -5,11 +5,11 @@ export type RealtimeEventType = "create" | "update" | "delete";
|
|
|
5
5
|
/**
|
|
6
6
|
* Payload received when a realtime event occurs.
|
|
7
7
|
*/
|
|
8
|
-
export interface RealtimeEvent
|
|
8
|
+
export interface RealtimeEvent {
|
|
9
9
|
/** The type of change that occurred */
|
|
10
10
|
type: RealtimeEventType;
|
|
11
|
-
/** The entity data
|
|
12
|
-
data:
|
|
11
|
+
/** The entity data */
|
|
12
|
+
data: any;
|
|
13
13
|
/** The unique identifier of the affected entity */
|
|
14
14
|
id: string;
|
|
15
15
|
/** ISO 8601 timestamp of when the event occurred */
|
|
@@ -18,7 +18,7 @@ export interface RealtimeEvent<T = Record<string, any>> {
|
|
|
18
18
|
/**
|
|
19
19
|
* Callback function invoked when a realtime event occurs.
|
|
20
20
|
*/
|
|
21
|
-
export type RealtimeCallback
|
|
21
|
+
export type RealtimeCallback = (event: RealtimeEvent) => void;
|
|
22
22
|
/**
|
|
23
23
|
* Function returned from subscribe, call it to unsubscribe.
|
|
24
24
|
*/
|
|
@@ -273,12 +273,12 @@ export interface EntityHandler {
|
|
|
273
273
|
* Receives notifications whenever any record is created, updated, or deleted.
|
|
274
274
|
*
|
|
275
275
|
* @param callback - Function called when an entity changes.
|
|
276
|
-
* @returns
|
|
276
|
+
* @returns Promise resolving to an unsubscribe function to stop listening.
|
|
277
277
|
*
|
|
278
278
|
* @example
|
|
279
279
|
* ```typescript
|
|
280
280
|
* // Subscribe to all Task changes
|
|
281
|
-
* const unsubscribe = base44.entities.Task.subscribe((event) => {
|
|
281
|
+
* const unsubscribe = await base44.entities.Task.subscribe((event) => {
|
|
282
282
|
* console.log(`Task ${event.id} was ${event.type}d:`, event.data);
|
|
283
283
|
* });
|
|
284
284
|
*
|
|
@@ -286,7 +286,7 @@ export interface EntityHandler {
|
|
|
286
286
|
* unsubscribe();
|
|
287
287
|
* ```
|
|
288
288
|
*/
|
|
289
|
-
subscribe(callback: RealtimeCallback): Subscription
|
|
289
|
+
subscribe(callback: RealtimeCallback): Promise<Subscription>;
|
|
290
290
|
}
|
|
291
291
|
/**
|
|
292
292
|
* Entities module for managing app data.
|