@base44-preview/sdk 0.8.11-pr.58.a137910 → 0.8.11-pr.58.aadf182
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/index.d.ts +1 -1
- package/dist/modules/entities.js +4 -54
- package/dist/modules/entities.types.d.ts +6 -85
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl } from
|
|
|
4
4
|
export { createClient, createClientFromRequest, Base44Error, getAccessToken, saveAccessToken, removeAccessToken, getLoginUrl, };
|
|
5
5
|
export type { Base44Client, CreateClientConfig, CreateClientOptions, Base44ErrorJSON, };
|
|
6
6
|
export * from "./types.js";
|
|
7
|
-
export type { EntitiesModule, EntityHandler, RealtimeEventType, RealtimeEvent, RealtimeCallback,
|
|
7
|
+
export type { EntitiesModule, EntityHandler, RealtimeEventType, RealtimeEvent, RealtimeCallback, Subscription, } from "./modules/entities.types.js";
|
|
8
8
|
export type { AuthModule, LoginResponse, RegisterParams, VerifyOtpParams, ChangePasswordParams, ResetPasswordParams, User, } from "./modules/auth.types.js";
|
|
9
9
|
export type { IntegrationsModule, IntegrationPackage, IntegrationEndpointFunction, CoreIntegrations, InvokeLLMParams, GenerateImageParams, GenerateImageResult, UploadFileParams, UploadFileResult, SendEmailParams, SendEmailResult, ExtractDataFromUploadedFileParams, ExtractDataFromUploadedFileResult, UploadPrivateFileParams, UploadPrivateFileResult, CreateFileSignedUrlParams, CreateFileSignedUrlResult, } from "./modules/integrations.types.js";
|
|
10
10
|
export type { FunctionsModule } from "./modules/functions.types.js";
|
package/dist/modules/entities.js
CHANGED
|
@@ -24,24 +24,6 @@ export function createEntitiesModule(configOrAxios, appIdArg) {
|
|
|
24
24
|
},
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Creates a stable hash from a query object for room naming.
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
function hashQuery(query) {
|
|
32
|
-
const sortedKeys = Object.keys(query).sort();
|
|
33
|
-
const normalized = sortedKeys
|
|
34
|
-
.map((k) => `${k}:${JSON.stringify(query[k])}`)
|
|
35
|
-
.join("|");
|
|
36
|
-
// Simple hash function
|
|
37
|
-
let hash = 0;
|
|
38
|
-
for (let i = 0; i < normalized.length; i++) {
|
|
39
|
-
const char = normalized.charCodeAt(i);
|
|
40
|
-
hash = (hash << 5) - hash + char;
|
|
41
|
-
hash = hash & hash; // Convert to 32bit integer
|
|
42
|
-
}
|
|
43
|
-
return Math.abs(hash).toString(36);
|
|
44
|
-
}
|
|
45
27
|
/**
|
|
46
28
|
* Parses the realtime message data and extracts event information.
|
|
47
29
|
* @internal
|
|
@@ -55,7 +37,6 @@ function parseRealtimeMessage(dataStr) {
|
|
|
55
37
|
data: parsed.data,
|
|
56
38
|
id: parsed.id || ((_a = parsed.data) === null || _a === void 0 ? void 0 : _a.id),
|
|
57
39
|
timestamp: parsed.timestamp || new Date().toISOString(),
|
|
58
|
-
previousData: parsed.previousData,
|
|
59
40
|
};
|
|
60
41
|
}
|
|
61
42
|
catch (_b) {
|
|
@@ -138,51 +119,20 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
|
|
|
138
119
|
});
|
|
139
120
|
},
|
|
140
121
|
// Subscribe to realtime updates
|
|
141
|
-
subscribe(
|
|
142
|
-
|
|
143
|
-
let callback;
|
|
144
|
-
let options;
|
|
145
|
-
// Parse overloaded arguments
|
|
146
|
-
if (typeof callbackOrIdOrQuery === "function") {
|
|
147
|
-
// subscribe(callback, options?)
|
|
148
|
-
room = `entities:${appId}:${entityName}`;
|
|
149
|
-
callback = callbackOrIdOrQuery;
|
|
150
|
-
options = callbackOrOptions;
|
|
151
|
-
}
|
|
152
|
-
else if (typeof callbackOrIdOrQuery === "string") {
|
|
153
|
-
// subscribe(id, callback, options?)
|
|
154
|
-
room = `entities:${appId}:${entityName}:${callbackOrIdOrQuery}`;
|
|
155
|
-
callback = callbackOrOptions;
|
|
156
|
-
options = optionsArg;
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
// subscribe(query, callback, options?)
|
|
160
|
-
const queryHash = hashQuery(callbackOrIdOrQuery);
|
|
161
|
-
room = `entities:${appId}:${entityName}:query:${queryHash}`;
|
|
162
|
-
callback = callbackOrOptions;
|
|
163
|
-
options = optionsArg;
|
|
164
|
-
}
|
|
165
|
-
const eventFilter = options === null || options === void 0 ? void 0 : options.events;
|
|
122
|
+
subscribe(callback) {
|
|
123
|
+
const room = `entities:${appId}:${entityName}`;
|
|
166
124
|
// Get the socket and subscribe to the room
|
|
167
125
|
const socket = getSocket();
|
|
168
126
|
const unsubscribe = socket.subscribeToRoom(room, {
|
|
169
127
|
update_model: (msg) => {
|
|
170
|
-
// Only process messages for our room
|
|
171
|
-
if (msg.room !== room)
|
|
172
|
-
return;
|
|
173
128
|
const event = parseRealtimeMessage(msg.data);
|
|
174
|
-
if (!event)
|
|
175
|
-
return;
|
|
176
|
-
// Apply event type filter if specified
|
|
177
|
-
if (eventFilter && !eventFilter.includes(event.type)) {
|
|
129
|
+
if (!event) {
|
|
178
130
|
return;
|
|
179
131
|
}
|
|
180
132
|
callback(event);
|
|
181
133
|
},
|
|
182
134
|
});
|
|
183
|
-
return
|
|
184
|
-
unsubscribe,
|
|
185
|
-
};
|
|
135
|
+
return unsubscribe;
|
|
186
136
|
},
|
|
187
137
|
};
|
|
188
138
|
}
|
|
@@ -14,27 +14,15 @@ export interface RealtimeEvent<T = Record<string, any>> {
|
|
|
14
14
|
id: string;
|
|
15
15
|
/** ISO 8601 timestamp of when the event occurred */
|
|
16
16
|
timestamp: string;
|
|
17
|
-
/** For update events, contains the previous data before the change */
|
|
18
|
-
previousData?: T;
|
|
19
17
|
}
|
|
20
18
|
/**
|
|
21
19
|
* Callback function invoked when a realtime event occurs.
|
|
22
20
|
*/
|
|
23
21
|
export type RealtimeCallback<T = Record<string, any>> = (event: RealtimeEvent<T>) => void;
|
|
24
22
|
/**
|
|
25
|
-
*
|
|
23
|
+
* Function returned from subscribe, call it to unsubscribe.
|
|
26
24
|
*/
|
|
27
|
-
export
|
|
28
|
-
/** Filter events by type. Defaults to all types. */
|
|
29
|
-
events?: RealtimeEventType[];
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Handle returned from subscribe, used to unsubscribe.
|
|
33
|
-
*/
|
|
34
|
-
export interface Subscription {
|
|
35
|
-
/** Stops listening to updates and cleans up the subscription. */
|
|
36
|
-
unsubscribe: () => void;
|
|
37
|
-
}
|
|
25
|
+
export type Subscription = () => void;
|
|
38
26
|
/**
|
|
39
27
|
* Entity handler providing CRUD operations for a specific entity type.
|
|
40
28
|
*
|
|
@@ -285,87 +273,20 @@ export interface EntityHandler {
|
|
|
285
273
|
* Receives notifications whenever any record is created, updated, or deleted.
|
|
286
274
|
*
|
|
287
275
|
* @param callback - Function called when an entity changes.
|
|
288
|
-
* @
|
|
289
|
-
* @returns Subscription handle with an unsubscribe method.
|
|
276
|
+
* @returns Unsubscribe function to stop listening.
|
|
290
277
|
*
|
|
291
278
|
* @example
|
|
292
279
|
* ```typescript
|
|
293
280
|
* // Subscribe to all Task changes
|
|
294
|
-
* const
|
|
281
|
+
* const unsubscribe = base44.entities.Task.subscribe((event) => {
|
|
295
282
|
* console.log(`Task ${event.id} was ${event.type}d:`, event.data);
|
|
296
283
|
* });
|
|
297
284
|
*
|
|
298
285
|
* // Later, unsubscribe
|
|
299
|
-
*
|
|
300
|
-
* ```
|
|
301
|
-
*
|
|
302
|
-
* @example
|
|
303
|
-
* ```typescript
|
|
304
|
-
* // Subscribe only to create events
|
|
305
|
-
* const subscription = base44.entities.Task.subscribe(
|
|
306
|
-
* (event) => console.log("New task:", event.data),
|
|
307
|
-
* { events: ["create"] }
|
|
308
|
-
* );
|
|
309
|
-
* ```
|
|
310
|
-
*/
|
|
311
|
-
subscribe(callback: RealtimeCallback, options?: SubscribeOptions): Subscription;
|
|
312
|
-
/**
|
|
313
|
-
* Subscribes to realtime updates for a specific entity record.
|
|
314
|
-
*
|
|
315
|
-
* Receives notifications when the specified record is updated or deleted.
|
|
316
|
-
*
|
|
317
|
-
* @param id - The unique identifier of the record to watch.
|
|
318
|
-
* @param callback - Function called when the entity changes.
|
|
319
|
-
* @param options - Optional configuration for filtering events.
|
|
320
|
-
* @returns Subscription handle with an unsubscribe method.
|
|
321
|
-
*
|
|
322
|
-
* @example
|
|
323
|
-
* ```typescript
|
|
324
|
-
* // Subscribe to a specific task
|
|
325
|
-
* const subscription = base44.entities.Task.subscribe("task-123", (event) => {
|
|
326
|
-
* if (event.type === "update") {
|
|
327
|
-
* console.log("Task updated:", event.data);
|
|
328
|
-
* } else if (event.type === "delete") {
|
|
329
|
-
* console.log("Task was deleted");
|
|
330
|
-
* }
|
|
331
|
-
* });
|
|
332
|
-
* ```
|
|
333
|
-
*/
|
|
334
|
-
subscribe(id: string, callback: RealtimeCallback, options?: SubscribeOptions): Subscription;
|
|
335
|
-
/**
|
|
336
|
-
* Subscribes to realtime updates for records matching a query.
|
|
337
|
-
*
|
|
338
|
-
* Receives notifications for records that match the specified criteria.
|
|
339
|
-
* Includes create events when new records match the query, update events
|
|
340
|
-
* when matching records change, and delete events when matching records
|
|
341
|
-
* are removed.
|
|
342
|
-
*
|
|
343
|
-
* @param query - Query object with field-value pairs to filter records.
|
|
344
|
-
* @param callback - Function called when a matching entity changes.
|
|
345
|
-
* @param options - Optional configuration for filtering events.
|
|
346
|
-
* @returns Subscription handle with an unsubscribe method.
|
|
347
|
-
*
|
|
348
|
-
* @example
|
|
349
|
-
* ```typescript
|
|
350
|
-
* // Subscribe to all completed tasks
|
|
351
|
-
* const subscription = base44.entities.Task.subscribe(
|
|
352
|
-
* { isCompleted: true },
|
|
353
|
-
* (event) => {
|
|
354
|
-
* console.log(`Completed task ${event.type}:`, event.data);
|
|
355
|
-
* }
|
|
356
|
-
* );
|
|
357
|
-
* ```
|
|
358
|
-
*
|
|
359
|
-
* @example
|
|
360
|
-
* ```typescript
|
|
361
|
-
* // Subscribe to high-priority active tasks
|
|
362
|
-
* const subscription = base44.entities.Task.subscribe(
|
|
363
|
-
* { priority: "high", status: "active" },
|
|
364
|
-
* (event) => console.log("High priority task changed:", event.data)
|
|
365
|
-
* );
|
|
286
|
+
* unsubscribe();
|
|
366
287
|
* ```
|
|
367
288
|
*/
|
|
368
|
-
subscribe(
|
|
289
|
+
subscribe(callback: RealtimeCallback): Subscription;
|
|
369
290
|
}
|
|
370
291
|
/**
|
|
371
292
|
* Entities module for managing app data.
|