@base44-preview/sdk 0.8.22-pr.146.6b18dc5 → 0.8.22-pr.146.a67f1ad

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.
@@ -40,7 +40,7 @@ export interface DeleteManyResult {
40
40
  deleted: number;
41
41
  }
42
42
  /**
43
- * Result returned when updating multiple entities via a query.
43
+ * Result returned when updating multiple entities using a query.
44
44
  */
45
45
  export interface UpdateManyResult {
46
46
  /** Whether the operation was successful. */
@@ -279,6 +279,11 @@ export interface EntityHandler<T = any> {
279
279
  * Updates a record by ID with the provided data. Only the fields
280
280
  * included in the data object will be updated.
281
281
  *
282
+ * To update a single record by ID, use this method. To apply the same
283
+ * update to many records matching a query, use {@linkcode updateMany | updateMany()}.
284
+ * To update multiple specific records with different data each, use
285
+ * {@linkcode bulkUpdate | bulkUpdate()}.
286
+ *
282
287
  * @param id - The unique identifier of the record to update.
283
288
  * @param data - Object containing the fields to update.
284
289
  * @returns Promise resolving to the updated record.
@@ -360,29 +365,39 @@ export interface EntityHandler<T = any> {
360
365
  */
361
366
  bulkCreate(data: Partial<T>[]): Promise<T[]>;
362
367
  /**
363
- * Updates multiple records matching a query using a MongoDB update operator.
368
+ * Applies the same update to all records that match a query.
364
369
  *
365
- * Applies the same update operation to all records matching the query.
366
- * The `data` parameter must contain one or more MongoDB update operators
367
- * (e.g., `$set`, `$inc`, `$push`). Multiple operators can be combined in a
368
- * single call, but each field may only appear in one operator.
370
+ * Use this when you need to make the same change across all records that
371
+ * match specific criteria. For example, you could set every completed order
372
+ * to "archived", or increment a counter on all active users.
369
373
  *
370
- * Results are batched in groups of up to 500 when `has_more` is `true`
374
+ * Results are batched in groups of up to 500. When `has_more` is `true`
371
375
  * in the response, call `updateMany` again with the same query to update
372
- * the next batch.
373
- *
374
- * @param query - Query object to filter which records to update. Records matching all
375
- * specified criteria will be updated.
376
- * @param data - Update operation object containing one or more MongoDB update operators.
376
+ * the next batch. Make sure the query excludes already-updated records
377
+ * so you don't re-process the same entities on each iteration. For
378
+ * example, filter by `status: 'pending'` when setting status to `'processed'`.
379
+ *
380
+ * To update a single record by ID, use {@linkcode update | update()} instead. To update
381
+ * multiple specific records with different data each, use {@linkcode bulkUpdate | bulkUpdate()}.
382
+ *
383
+ * @param query - Query object to filter which records to update. Use field-value
384
+ * pairs for exact matches, or
385
+ * [MongoDB query operators](https://www.mongodb.com/docs/manual/reference/operator/query/)
386
+ * for advanced filtering. Supported query operators include `$eq`, `$ne`, `$gt`,
387
+ * `$gte`, `$lt`, `$lte`, `$in`, `$nin`, `$and`, `$or`, `$not`, `$nor`,
388
+ * `$exists`, `$regex`, `$all`, `$elemMatch`, and `$size`.
389
+ * @param data - Update operation object containing one or more
390
+ * [MongoDB update operators](https://www.mongodb.com/docs/manual/reference/operator/update/).
377
391
  * Each field may only appear in one operator per call.
378
- * Supported operators: `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`,
379
- * `$currentDate`, `$addToSet`, `$push`, `$pull`.
392
+ * Supported update operators include `$set`, `$rename`, `$unset`, `$inc`, `$mul`, `$min`, `$max`,
393
+ * `$currentDate`, `$addToSet`, `$push`, and `$pull`.
380
394
  * @returns Promise resolving to the update result.
381
395
  *
382
396
  * @example
383
397
  * ```typescript
384
- * // Set status to 'archived' for all completed records
385
- * const result = await base44.entities.MyEntity.updateMany(
398
+ * // Basic usage
399
+ * // Archive all completed orders
400
+ * const result = await base44.entities.Order.updateMany(
386
401
  * { status: 'completed' },
387
402
  * { $set: { status: 'archived' } }
388
403
  * );
@@ -391,8 +406,19 @@ export interface EntityHandler<T = any> {
391
406
  *
392
407
  * @example
393
408
  * ```typescript
394
- * // Combine multiple operators in a single call
395
- * const result = await base44.entities.MyEntity.updateMany(
409
+ * // Multiple query operators
410
+ * // Flag urgent items that haven't been handled yet
411
+ * const result = await base44.entities.Task.updateMany(
412
+ * { priority: { $in: ['high', 'critical'] }, status: { $ne: 'done' } },
413
+ * { $set: { flagged: true } }
414
+ * );
415
+ * ```
416
+ *
417
+ * @example
418
+ * ```typescript
419
+ * // Multiple update operators
420
+ * // Close out sales records and bump the view count
421
+ * const result = await base44.entities.Deal.updateMany(
396
422
  * { category: 'sales' },
397
423
  * { $set: { status: 'done' }, $inc: { view_count: 1 } }
398
424
  * );
@@ -400,11 +426,14 @@ export interface EntityHandler<T = any> {
400
426
  *
401
427
  * @example
402
428
  * ```typescript
403
- * // Handle batched updates for large datasets
429
+ * // Batched updates
430
+ * // Process all pending items in batches of 500.
431
+ * // The query filters by 'pending', so updated records (now 'processed')
432
+ * // are automatically excluded from the next batch.
404
433
  * let hasMore = true;
405
434
  * let totalUpdated = 0;
406
435
  * while (hasMore) {
407
- * const result = await base44.entities.MyEntity.updateMany(
436
+ * const result = await base44.entities.Job.updateMany(
408
437
  * { status: 'pending' },
409
438
  * { $set: { status: 'processed' } }
410
439
  * );
@@ -415,27 +444,42 @@ export interface EntityHandler<T = any> {
415
444
  */
416
445
  updateMany(query: Partial<T>, data: Record<string, Record<string, any>>): Promise<UpdateManyResult>;
417
446
  /**
418
- * Updates multiple records in a single request, each with its own update data.
447
+ * Updates the specified records in a single request, each with its own data.
419
448
  *
420
- * Unlike `updateMany` which applies the same update to all matching records,
421
- * `bulkUpdate` allows different updates for each record. Each item in the
422
- * array must include an `id` field identifying which record to update.
449
+ * Use this when you already know which records to update and each one needs
450
+ * different field values. For example, you could update the status and amount
451
+ * on three separate invoices in one call.
423
452
  *
424
- * **Note:** Maximum 500 items per request.
453
+ * You can update up to 500 records per request.
425
454
  *
426
- * @param data - Array of update objects (max 500). Each object must have an `id` field
427
- * and any number of fields to update.
428
- * @returns Promise resolving to an array of updated records.
455
+ * To apply the same update to all records matching a query, use
456
+ * {@linkcode updateMany | updateMany()}. To update a single record by ID, use
457
+ * {@linkcode update | update()}.
458
+ *
459
+ * @param data - Array of objects to update. Each object must contain an `id` field identifying which record to update and any fields to change.
460
+ * @returns Promise resolving to an array of the updated records.
429
461
  *
430
462
  * @example
431
463
  * ```typescript
432
- * // Update multiple records with different data
433
- * const updated = await base44.entities.MyEntity.bulkUpdate([
434
- * { id: 'entity-1', status: 'paid', amount: 999 },
435
- * { id: 'entity-2', status: 'cancelled' },
436
- * { id: 'entity-3', name: 'Renamed Item' }
464
+ * // Basic usage
465
+ * // Update three invoices with different statuses and amounts
466
+ * const updated = await base44.entities.Invoice.bulkUpdate([
467
+ * { id: 'inv-1', status: 'paid', amount: 999 },
468
+ * { id: 'inv-2', status: 'cancelled' },
469
+ * { id: 'inv-3', amount: 450 }
437
470
  * ]);
438
471
  * ```
472
+ *
473
+ * @example
474
+ * ```typescript
475
+ * // More than 500 items
476
+ * // Reassign each task to a different owner in batches
477
+ * const allUpdates = reassignments.map(r => ({ id: r.taskId, owner: r.newOwner }));
478
+ * for (let i = 0; i < allUpdates.length; i += 500) {
479
+ * const batch = allUpdates.slice(i, i + 500);
480
+ * await base44.entities.Task.bulkUpdate(batch);
481
+ * }
482
+ * ```
439
483
  */
440
484
  bulkUpdate(data: (Partial<T> & {
441
485
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@base44-preview/sdk",
3
- "version": "0.8.22-pr.146.6b18dc5",
3
+ "version": "0.8.22-pr.146.a67f1ad",
4
4
  "description": "JavaScript SDK for Base44 API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",