@base44-preview/sdk 0.8.20-pr.142.985ee7b → 0.8.20-pr.143.d04635a

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 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 { DeleteManyResult, DeleteResult, EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, } from "./modules/entities.types.js";
7
+ export type { DeleteManyResult, DeleteResult, EntitiesModule, EntityHandler, EntityRecord, EntityTypeRegistry, ImportResult, RealtimeEventType, RealtimeEvent, RealtimeCallback, SortField, UpdateManyResult, } 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, 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, FunctionName, FunctionNameRegistry, } from "./modules/functions.types.js";
@@ -106,6 +106,14 @@ function createEntityHandler(axios, appId, entityName, getSocket) {
106
106
  async bulkCreate(data) {
107
107
  return axios.post(`${baseURL}/bulk`, data);
108
108
  },
109
+ // Update multiple entities matching a query using a MongoDB update operator
110
+ async updateMany(query, data) {
111
+ return axios.patch(`${baseURL}/update-many`, { query, data });
112
+ },
113
+ // Update multiple entities by ID, each with its own update data
114
+ async bulkUpdate(data) {
115
+ return axios.put(`${baseURL}/bulk`, data);
116
+ },
109
117
  // Import entities from a file
110
118
  async importEntities(file) {
111
119
  const formData = new FormData();
@@ -39,6 +39,17 @@ export interface DeleteManyResult {
39
39
  /** Number of entities that were deleted. */
40
40
  deleted: number;
41
41
  }
42
+ /**
43
+ * Result returned when updating multiple entities via a query.
44
+ */
45
+ export interface UpdateManyResult {
46
+ /** Whether the operation was successful. */
47
+ success: boolean;
48
+ /** Number of entities that were updated. */
49
+ updated: number;
50
+ /** Whether there are more entities matching the query that were not updated in this batch. When `true`, call `updateMany` again with the same query to update the next batch. */
51
+ has_more: boolean;
52
+ }
42
53
  /**
43
54
  * Result returned when importing entities from a file.
44
55
  *
@@ -348,6 +359,82 @@ export interface EntityHandler<T = any> {
348
359
  * ```
349
360
  */
350
361
  bulkCreate(data: Partial<T>[]): Promise<T[]>;
362
+ /**
363
+ * Updates multiple records matching a query using a MongoDB update operator.
364
+ *
365
+ * Applies the same update operation to all records matching the query.
366
+ * The `data` parameter must contain exactly one MongoDB update operator
367
+ * (e.g., `$set`, `$inc`, `$push`).
368
+ *
369
+ * Results are batched — when `has_more` is `true` in the response, call
370
+ * `updateMany` again with the same query to update the next batch.
371
+ *
372
+ * @param query - Query object to filter which records to update. Records matching all
373
+ * specified criteria will be updated.
374
+ * @param data - Update operation object containing exactly one MongoDB update operator.
375
+ * Supported operators: `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`,
376
+ * `$currentDate`, `$addToSet`, `$push`, `$pull`.
377
+ * @returns Promise resolving to the update result.
378
+ *
379
+ * @example
380
+ * ```typescript
381
+ * // Set status to 'archived' for all completed records
382
+ * const result = await base44.entities.MyEntity.updateMany(
383
+ * { status: 'completed' },
384
+ * { $set: { status: 'archived' } }
385
+ * );
386
+ * console.log(`Updated ${result.updated} records`);
387
+ * ```
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * // Increment a counter on all matching records
392
+ * const result = await base44.entities.MyEntity.updateMany(
393
+ * { category: 'sales' },
394
+ * { $inc: { view_count: 1 } }
395
+ * );
396
+ * ```
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * // Handle batched updates for large datasets
401
+ * let hasMore = true;
402
+ * let totalUpdated = 0;
403
+ * while (hasMore) {
404
+ * const result = await base44.entities.MyEntity.updateMany(
405
+ * { status: 'pending' },
406
+ * { $set: { status: 'processed' } }
407
+ * );
408
+ * totalUpdated += result.updated;
409
+ * hasMore = result.has_more;
410
+ * }
411
+ * ```
412
+ */
413
+ updateMany(query: Partial<T>, data: Record<string, Record<string, any>>): Promise<UpdateManyResult>;
414
+ /**
415
+ * Updates multiple records in a single request, each with its own update data.
416
+ *
417
+ * Unlike `updateMany` which applies the same update to all matching records,
418
+ * `bulkUpdate` allows different updates for each record. Each item in the
419
+ * array must include an `id` field identifying which record to update.
420
+ *
421
+ * @param data - Array of update objects. Each object must have an `id` field
422
+ * and any number of fields to update.
423
+ * @returns Promise resolving to an array of updated records.
424
+ *
425
+ * @example
426
+ * ```typescript
427
+ * // Update multiple records with different data
428
+ * const updated = await base44.entities.MyEntity.bulkUpdate([
429
+ * { id: 'entity-1', status: 'paid', amount: 999 },
430
+ * { id: 'entity-2', status: 'cancelled' },
431
+ * { id: 'entity-3', name: 'Renamed Item' }
432
+ * ]);
433
+ * ```
434
+ */
435
+ bulkUpdate(data: (Partial<T> & {
436
+ id: string;
437
+ })[]): Promise<T[]>;
351
438
  /**
352
439
  * Imports records from a file.
353
440
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.20-pr.142.985ee7b",
3
+ "version": "0.8.20-pr.143.d04635a",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",