dyno-table 1.6.0 → 1.7.0

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.
Files changed (72) hide show
  1. package/README.md +52 -139
  2. package/dist/batch-builder-DNsz6zvh.d.cts +398 -0
  3. package/dist/batch-builder-Dz1yPGrJ.d.ts +398 -0
  4. package/dist/builders/condition-check-builder.cjs +0 -13
  5. package/dist/builders/condition-check-builder.cjs.map +1 -1
  6. package/dist/builders/condition-check-builder.d.cts +0 -13
  7. package/dist/builders/condition-check-builder.d.ts +0 -13
  8. package/dist/builders/condition-check-builder.js +0 -13
  9. package/dist/builders/condition-check-builder.js.map +1 -1
  10. package/dist/builders/delete-builder.cjs +38 -0
  11. package/dist/builders/delete-builder.cjs.map +1 -1
  12. package/dist/builders/delete-builder.d.cts +36 -0
  13. package/dist/builders/delete-builder.d.ts +36 -0
  14. package/dist/builders/delete-builder.js +38 -0
  15. package/dist/builders/delete-builder.js.map +1 -1
  16. package/dist/builders/paginator.cjs +0 -24
  17. package/dist/builders/paginator.cjs.map +1 -1
  18. package/dist/builders/paginator.d.cts +0 -24
  19. package/dist/builders/paginator.d.ts +0 -24
  20. package/dist/builders/paginator.js +0 -24
  21. package/dist/builders/paginator.js.map +1 -1
  22. package/dist/builders/put-builder.cjs +39 -8
  23. package/dist/builders/put-builder.cjs.map +1 -1
  24. package/dist/builders/put-builder.d.cts +37 -8
  25. package/dist/builders/put-builder.d.ts +37 -8
  26. package/dist/builders/put-builder.js +39 -8
  27. package/dist/builders/put-builder.js.map +1 -1
  28. package/dist/builders/query-builder.cjs +0 -53
  29. package/dist/builders/query-builder.cjs.map +1 -1
  30. package/dist/builders/query-builder.d.cts +1 -1
  31. package/dist/builders/query-builder.d.ts +1 -1
  32. package/dist/builders/query-builder.js +0 -53
  33. package/dist/builders/query-builder.js.map +1 -1
  34. package/dist/builders/transaction-builder.cjs +0 -47
  35. package/dist/builders/transaction-builder.cjs.map +1 -1
  36. package/dist/builders/transaction-builder.d.cts +0 -47
  37. package/dist/builders/transaction-builder.d.ts +0 -47
  38. package/dist/builders/transaction-builder.js +0 -47
  39. package/dist/builders/transaction-builder.js.map +1 -1
  40. package/dist/builders/update-builder.cjs +2 -2
  41. package/dist/builders/update-builder.cjs.map +1 -1
  42. package/dist/builders/update-builder.d.cts +2 -2
  43. package/dist/builders/update-builder.d.ts +2 -2
  44. package/dist/builders/update-builder.js +2 -2
  45. package/dist/builders/update-builder.js.map +1 -1
  46. package/dist/conditions.cjs.map +1 -1
  47. package/dist/conditions.js.map +1 -1
  48. package/dist/entity.cjs +69 -37
  49. package/dist/entity.cjs.map +1 -1
  50. package/dist/entity.d.cts +30 -10
  51. package/dist/entity.d.ts +30 -10
  52. package/dist/entity.js +69 -37
  53. package/dist/entity.js.map +1 -1
  54. package/dist/index.cjs +530 -182
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +3 -2
  57. package/dist/index.d.ts +3 -2
  58. package/dist/index.js +529 -183
  59. package/dist/index.js.map +1 -1
  60. package/dist/{query-builder-CbHvimBk.d.cts → query-builder-BDuHHrb-.d.cts} +0 -34
  61. package/dist/{query-builder-BhrR31oO.d.ts → query-builder-C6XjVEFH.d.ts} +0 -34
  62. package/dist/{table-Des8C2od.d.ts → table-BWa4tx63.d.ts} +39 -151
  63. package/dist/{table-CY9byPEg.d.cts → table-DAKlzQsK.d.cts} +39 -151
  64. package/dist/table.cjs +459 -145
  65. package/dist/table.cjs.map +1 -1
  66. package/dist/table.d.cts +3 -2
  67. package/dist/table.d.ts +3 -2
  68. package/dist/table.js +459 -145
  69. package/dist/table.js.map +1 -1
  70. package/dist/utils.cjs.map +1 -1
  71. package/dist/utils.js.map +1 -1
  72. package/package.json +1 -1
package/dist/table.cjs CHANGED
@@ -210,10 +210,6 @@ var Paginator = class {
210
210
  }
211
211
  /**
212
212
  * Gets the current page number (1-indexed).
213
- * Use this method when you need to:
214
- * - Track progress through dinosaur lists
215
- * - Display habitat inspection status
216
- * - Monitor security sweep progress
217
213
  *
218
214
  * @example
219
215
  * ```ts
@@ -231,11 +227,6 @@ var Paginator = class {
231
227
  }
232
228
  /**
233
229
  * Checks if there are more pages of dinosaurs or habitats to process.
234
- * Use this method when you need to:
235
- * - Check for more dinosaurs to review
236
- * - Continue habitat inspections
237
- * - Process security incidents
238
- * - Complete feeding schedules
239
230
  *
240
231
  * This method takes into account both:
241
232
  * - DynamoDB's lastEvaluatedKey mechanism
@@ -267,11 +258,6 @@ var Paginator = class {
267
258
  }
268
259
  /**
269
260
  * Retrieves the next page of dinosaurs or habitats from DynamoDB.
270
- * Use this method when you need to:
271
- * - Process dinosaur groups systematically
272
- * - Review habitat inspections in batches
273
- * - Monitor security incidents in sequence
274
- * - Schedule feeding rotations
275
261
  *
276
262
  * This method handles:
277
263
  * - Automatic continuation between groups
@@ -343,16 +329,6 @@ var Paginator = class {
343
329
  }
344
330
  /**
345
331
  * Gets all remaining dinosaurs or habitats and combines them into a single array.
346
- * Use this method when you need to:
347
- * - Generate complete park inventory
348
- * - Perform full security audit
349
- * - Create comprehensive feeding schedule
350
- * - Run park-wide health checks
351
- *
352
- * Note: Use with caution! This method:
353
- * - Could overwhelm systems with large dinosaur populations
354
- * - Makes multiple database requests
355
- * - May cause system strain during peak hours
356
332
  *
357
333
  * @example
358
334
  * ```ts
@@ -394,10 +370,6 @@ var FilterBuilder = class {
394
370
  selectedFields = /* @__PURE__ */ new Set();
395
371
  /**
396
372
  * Sets the maximum number of items to return.
397
- * Use this method when you need to:
398
- * - Limit the number of dinosaurs returned
399
- * - Control the size of habitat reports
400
- * - Implement manual pagination of security logs
401
373
  *
402
374
  * Note: This limit applies to the items that match the key condition
403
375
  * before any filter expressions are applied.
@@ -428,11 +400,6 @@ var FilterBuilder = class {
428
400
  }
429
401
  /**
430
402
  * Specifies a Global Secondary Index (GSI) to use for the operation.
431
- * Use this method when you need to:
432
- * - Find dinosaurs by species or status
433
- * - Search habitats by security level
434
- * - Find incidents by date
435
- * - List feeding schedules by time
436
403
  *
437
404
  * @example
438
405
  * ```typescript
@@ -461,11 +428,6 @@ var FilterBuilder = class {
461
428
  }
462
429
  /**
463
430
  * Sets whether to use strongly consistent reads for the operation.
464
- * Use this method when you need to:
465
- * - Get real-time dinosaur status updates
466
- * - Monitor critical security systems
467
- * - Track immediate habitat changes
468
- * - Verify containment protocols
469
431
  *
470
432
  * Note:
471
433
  * - Consistent reads are not available on GSIs
@@ -496,11 +458,6 @@ var FilterBuilder = class {
496
458
  }
497
459
  /**
498
460
  * Adds a filter expression to refine the operation results.
499
- * Use this method when you need to:
500
- * - Filter dinosaurs by behavior patterns
501
- * - Find habitats with specific conditions
502
- * - Search for security incidents
503
- * - Monitor feeding patterns
504
461
  *
505
462
  * @example
506
463
  * ```typescript
@@ -553,11 +510,6 @@ var FilterBuilder = class {
553
510
  }
554
511
  /**
555
512
  * Specifies which attributes to return in the results.
556
- * Use this method when you need to:
557
- * - Get specific dinosaur attributes
558
- * - Retrieve habitat statistics
559
- * - Monitor security metrics
560
- * - Optimize response size
561
513
  *
562
514
  * @example
563
515
  * ```typescript
@@ -624,11 +576,6 @@ var FilterBuilder = class {
624
576
  }
625
577
  /**
626
578
  * Sets the starting point using a previous lastEvaluatedKey.
627
- * Use this method when you need to:
628
- * - Implement manual dinosaur list pagination
629
- * - Resume habitat inspection reviews
630
- * - Continue security incident analysis
631
- * - Store operation position between sessions
632
579
  *
633
580
  * Note: This method is typically used for manual pagination.
634
581
  * For automatic pagination, use the paginate() method instead.
@@ -895,10 +842,6 @@ var PutBuilder = class {
895
842
  }
896
843
  /**
897
844
  * Adds a condition that must be satisfied for the put operation to succeed.
898
- * Use this method when you need to:
899
- * - Prevent overwriting existing items (optimistic locking)
900
- * - Ensure items meet certain criteria before replacement
901
- * - Implement complex business rules for item updates
902
845
  *
903
846
  * @example
904
847
  * ```ts
@@ -1031,10 +974,6 @@ var PutBuilder = class {
1031
974
  }
1032
975
  /**
1033
976
  * Adds this put operation to a transaction.
1034
- * Use this method when you need to:
1035
- * - Transfer dinosaurs between habitats
1036
- * - Initialize new breeding programs
1037
- * - Update multiple facility records
1038
977
  *
1039
978
  * @example
1040
979
  * ```ts
@@ -1067,6 +1006,45 @@ var PutBuilder = class {
1067
1006
  transaction.putWithCommand(command);
1068
1007
  return this;
1069
1008
  }
1009
+ /**
1010
+ * Adds this put operation to a batch with optional entity type information.
1011
+ *
1012
+ * @example Basic Usage
1013
+ * ```ts
1014
+ * const batch = table.batchBuilder();
1015
+ *
1016
+ * // Add multiple dinosaurs to batch
1017
+ * dinosaurRepo.create(newDino1).withBatch(batch);
1018
+ * dinosaurRepo.create(newDino2).withBatch(batch);
1019
+ * dinosaurRepo.create(newDino3).withBatch(batch);
1020
+ *
1021
+ * // Execute all operations efficiently
1022
+ * await batch.execute();
1023
+ * ```
1024
+ *
1025
+ * @example Typed Usage
1026
+ * ```ts
1027
+ * const batch = table.batchBuilder<{
1028
+ * User: UserEntity;
1029
+ * Order: OrderEntity;
1030
+ * }>();
1031
+ *
1032
+ * // Add operations with type information
1033
+ * userRepo.create(newUser).withBatch(batch, 'User');
1034
+ * orderRepo.create(newOrder).withBatch(batch, 'Order');
1035
+ *
1036
+ * // Execute and get typed results
1037
+ * const result = await batch.execute();
1038
+ * const users: UserEntity[] = result.reads.itemsByType.User;
1039
+ * ```
1040
+ *
1041
+ * @param batch - The batch builder to add this operation to
1042
+ * @param entityType - Optional entity type key for type tracking
1043
+ */
1044
+ withBatch(batch, entityType) {
1045
+ const command = this.toDynamoCommand();
1046
+ batch.putWithCommand(command, entityType);
1047
+ }
1070
1048
  /**
1071
1049
  * Executes the put operation against DynamoDB.
1072
1050
  *
@@ -1261,6 +1239,44 @@ var DeleteBuilder = class {
1261
1239
  const command = this.toDynamoCommand();
1262
1240
  transaction.deleteWithCommand(command);
1263
1241
  }
1242
+ /**
1243
+ * Adds this delete operation to a batch with optional entity type information.
1244
+ *
1245
+ * @example Basic Usage
1246
+ * ```ts
1247
+ * const batch = table.batchBuilder();
1248
+ *
1249
+ * // Remove multiple dinosaurs in batch
1250
+ * dinosaurRepo.delete({ id: 'old-dino-1' }).withBatch(batch);
1251
+ * dinosaurRepo.delete({ id: 'old-dino-2' }).withBatch(batch);
1252
+ * dinosaurRepo.delete({ id: 'old-dino-3' }).withBatch(batch);
1253
+ *
1254
+ * // Execute all deletions efficiently
1255
+ * await batch.execute();
1256
+ * ```
1257
+ *
1258
+ * @example Typed Usage
1259
+ * ```ts
1260
+ * const batch = table.batchBuilder<{
1261
+ * User: UserEntity;
1262
+ * Order: OrderEntity;
1263
+ * }>();
1264
+ *
1265
+ * // Add operations with type information
1266
+ * userRepo.delete({ id: 'user-1' }).withBatch(batch, 'User');
1267
+ * orderRepo.delete({ id: 'order-1' }).withBatch(batch, 'Order');
1268
+ *
1269
+ * // Execute batch operations
1270
+ * await batch.execute();
1271
+ * ```
1272
+ *
1273
+ * @param batch - The batch builder to add this operation to
1274
+ * @param entityType - Optional entity type key for type tracking
1275
+ */
1276
+ withBatch(batch, entityType) {
1277
+ const command = this.toDynamoCommand();
1278
+ batch.deleteWithCommand(command, entityType);
1279
+ }
1264
1280
  /**
1265
1281
  * Executes the delete operation against DynamoDB.
1266
1282
  *
@@ -1503,11 +1519,11 @@ var UpdateBuilder = class {
1503
1519
  * Sets which item attributes to include in the response.
1504
1520
  *
1505
1521
  * Available options:
1506
- * - ALL_NEW: All attributes after the update
1522
+ * - ALL_NEW: All attributes after the update (default)
1507
1523
  * - UPDATED_NEW: Only updated attributes, new values
1508
1524
  * - ALL_OLD: All attributes before the update
1509
1525
  * - UPDATED_OLD: Only updated attributes, old values
1510
- * - NONE: No attributes returned (default)
1526
+ * - NONE: No attributes returned
1511
1527
  *
1512
1528
  * @example
1513
1529
  * ```typescript
@@ -1826,10 +1842,6 @@ var TransactionBuilder = class {
1826
1842
  }
1827
1843
  /**
1828
1844
  * Adds a put operation to the transaction.
1829
- * Use this method when you need to:
1830
- * - Insert new items as part of a transaction
1831
- * - Replace existing items atomically
1832
- * - Ensure items meet certain conditions before insertion
1833
1845
  *
1834
1846
  * The method automatically checks for duplicate items within the transaction
1835
1847
  * to prevent multiple operations on the same item.
@@ -1887,10 +1899,6 @@ var TransactionBuilder = class {
1887
1899
  }
1888
1900
  /**
1889
1901
  * Adds a pre-configured put operation to the transaction.
1890
- * Use this method when you need to:
1891
- * - Reuse put commands from PutBuilder
1892
- * - Add complex put operations with pre-configured parameters
1893
- * - Integrate with existing put command configurations
1894
1902
  *
1895
1903
  * This method is particularly useful when working with PutBuilder
1896
1904
  * to maintain consistency in put operations across your application.
@@ -1922,10 +1930,6 @@ var TransactionBuilder = class {
1922
1930
  }
1923
1931
  /**
1924
1932
  * Adds a delete operation to the transaction.
1925
- * Use this method when you need to:
1926
- * - Remove items as part of a transaction
1927
- * - Conditionally delete items
1928
- * - Ensure items exist before deletion
1929
1933
  *
1930
1934
  * The method automatically checks for duplicate items within the transaction
1931
1935
  * to prevent multiple operations on the same item.
@@ -1983,10 +1987,6 @@ var TransactionBuilder = class {
1983
1987
  }
1984
1988
  /**
1985
1989
  * Adds a pre-configured delete operation to the transaction.
1986
- * Use this method when you need to:
1987
- * - Reuse delete commands from DeleteBuilder
1988
- * - Add complex delete operations with pre-configured parameters
1989
- * - Integrate with existing delete command configurations
1990
1990
  *
1991
1991
  * This method is particularly useful when working with DeleteBuilder
1992
1992
  * to maintain consistency in delete operations across your application.
@@ -2033,11 +2033,6 @@ var TransactionBuilder = class {
2033
2033
  }
2034
2034
  /**
2035
2035
  * Adds an update operation to the transaction.
2036
- * Use this method when you need to:
2037
- * - Modify existing items as part of a transaction
2038
- * - Update multiple attributes atomically
2039
- * - Apply conditional updates
2040
- * - Perform complex attribute manipulations
2041
2036
  *
2042
2037
  * The method supports all DynamoDB update expressions:
2043
2038
  * - SET: Modify or add attributes
@@ -2115,10 +2110,6 @@ var TransactionBuilder = class {
2115
2110
  }
2116
2111
  /**
2117
2112
  * Adds a pre-configured update operation to the transaction.
2118
- * Use this method when you need to:
2119
- * - Reuse update commands from UpdateBuilder
2120
- * - Add complex update operations with pre-configured parameters
2121
- * - Integrate with existing update command configurations
2122
2113
  *
2123
2114
  * This method is particularly useful when working with UpdateBuilder
2124
2115
  * to maintain consistency in update operations across your application.
@@ -2168,11 +2159,6 @@ var TransactionBuilder = class {
2168
2159
  }
2169
2160
  /**
2170
2161
  * Adds a condition check operation to the transaction.
2171
- * Use this method when you need to:
2172
- * - Validate item state without modifying it
2173
- * - Ensure data consistency across tables
2174
- * - Implement complex business rules
2175
- * - Verify preconditions for other operations
2176
2162
  *
2177
2163
  * Condition checks are particularly useful for:
2178
2164
  * - Implementing optimistic locking
@@ -2239,10 +2225,6 @@ var TransactionBuilder = class {
2239
2225
  }
2240
2226
  /**
2241
2227
  * Adds a pre-configured condition check operation to the transaction.
2242
- * Use this method when you need to:
2243
- * - Reuse condition checks from ConditionCheckBuilder
2244
- * - Add complex condition checks with pre-configured parameters
2245
- * - Integrate with existing condition check configurations
2246
2228
  *
2247
2229
  * This method is particularly useful when working with ConditionCheckBuilder
2248
2230
  * to maintain consistency in condition checks across your application.
@@ -2290,10 +2272,6 @@ var TransactionBuilder = class {
2290
2272
  }
2291
2273
  /**
2292
2274
  * Sets options for the transaction execution.
2293
- * Use this method when you need to:
2294
- * - Enable idempotent transactions
2295
- * - Track consumed capacity
2296
- * - Monitor item collection metrics
2297
2275
  *
2298
2276
  * @example
2299
2277
  * ```typescript
@@ -2321,11 +2299,6 @@ var TransactionBuilder = class {
2321
2299
  }
2322
2300
  /**
2323
2301
  * Gets a human-readable representation of the transaction items.
2324
- * Use this method when you need to:
2325
- * - Debug complex transactions
2326
- * - Verify operation parameters
2327
- * - Log transaction details
2328
- * - Troubleshoot condition expressions
2329
2302
  *
2330
2303
  * The method resolves all expression placeholders with their actual values,
2331
2304
  * making it easier to understand the transaction's operations.
@@ -2354,10 +2327,6 @@ var TransactionBuilder = class {
2354
2327
  }
2355
2328
  /**
2356
2329
  * Executes all operations in the transaction atomically.
2357
- * Use this method when you need to:
2358
- * - Perform multiple operations atomically
2359
- * - Ensure all-or-nothing execution
2360
- * - Maintain data consistency across operations
2361
2330
  *
2362
2331
  * The transaction will only succeed if all operations succeed.
2363
2332
  * If any operation fails, the entire transaction is rolled back.
@@ -2481,10 +2450,6 @@ var ConditionCheckBuilder = class {
2481
2450
  }
2482
2451
  /**
2483
2452
  * Adds a condition that must be satisfied for the check to succeed.
2484
- * Use this method when you need to:
2485
- * - Validate complex item states
2486
- * - Check multiple attributes together
2487
- * - Ensure safety conditions are met
2488
2453
  *
2489
2454
  * @example
2490
2455
  * ```typescript
@@ -2580,10 +2545,6 @@ var ConditionCheckBuilder = class {
2580
2545
  }
2581
2546
  /**
2582
2547
  * Adds this condition check operation to a transaction.
2583
- * Use this method when you need to:
2584
- * - Verify habitat safety before transfers
2585
- * - Ensure proper feeding conditions
2586
- * - Validate security protocols
2587
2548
  *
2588
2549
  * @example
2589
2550
  * ```ts
@@ -2613,11 +2574,6 @@ var ConditionCheckBuilder = class {
2613
2574
  /**
2614
2575
  * Gets a human-readable representation of the condition check command
2615
2576
  * with all expression placeholders replaced by their actual values.
2616
- * Use this method when you need to:
2617
- * - Debug complex condition expressions
2618
- * - Verify condition parameters
2619
- * - Log safety checks
2620
- * - Troubleshoot condition failures
2621
2577
  *
2622
2578
  * @example
2623
2579
  * ```ts
@@ -2640,6 +2596,283 @@ var ConditionCheckBuilder = class {
2640
2596
  }
2641
2597
  };
2642
2598
 
2599
+ // src/builders/batch-builder.ts
2600
+ var BatchError = class extends Error {
2601
+ operation;
2602
+ cause;
2603
+ constructor(message, operation, cause) {
2604
+ super(message);
2605
+ this.name = "BatchError";
2606
+ this.operation = operation;
2607
+ this.cause = cause;
2608
+ }
2609
+ };
2610
+ var BatchBuilder = class {
2611
+ constructor(batchWriteExecutor, batchGetExecutor, config) {
2612
+ this.batchWriteExecutor = batchWriteExecutor;
2613
+ this.batchGetExecutor = batchGetExecutor;
2614
+ this.config = config;
2615
+ }
2616
+ writeItems = [];
2617
+ getItems = [];
2618
+ /**
2619
+ * Checks if the batch is empty (contains no operations)
2620
+ *
2621
+ * @returns true if the batch contains no operations
2622
+ */
2623
+ isEmpty() {
2624
+ return this.writeItems.length === 0 && this.getItems.length === 0;
2625
+ }
2626
+ /**
2627
+ * Gets the count of operations in the batch
2628
+ *
2629
+ * @returns Object containing the count of write and read operations
2630
+ */
2631
+ getOperationCount() {
2632
+ return {
2633
+ writes: this.writeItems.length,
2634
+ reads: this.getItems.length
2635
+ };
2636
+ }
2637
+ /**
2638
+ * Validates that the batch is not empty before execution
2639
+ *
2640
+ * @throws {BatchError} If the batch is empty
2641
+ */
2642
+ validateNotEmpty() {
2643
+ if (this.isEmpty()) {
2644
+ throw new BatchError(
2645
+ "Cannot execute empty batch. Add operations using entity builders with .withBatch()",
2646
+ "write"
2647
+ );
2648
+ }
2649
+ }
2650
+ /**
2651
+ * Adds a put operation to the batch with entity type information.
2652
+ * This method is used internally by entity builders.
2653
+ *
2654
+ * @param command - The complete put command configuration
2655
+ * @param entityType - The entity type name for type tracking
2656
+ * @returns The batch builder for method chaining
2657
+ * @internal
2658
+ */
2659
+ putWithCommand(command, entityType) {
2660
+ const batchItem = {
2661
+ type: "Put",
2662
+ params: command,
2663
+ entityType
2664
+ };
2665
+ this.writeItems.push(batchItem);
2666
+ return this;
2667
+ }
2668
+ /**
2669
+ * Adds a delete operation to the batch with entity type information.
2670
+ * This method is used internally by entity builders.
2671
+ *
2672
+ * @param command - The complete delete command configuration
2673
+ * @param entityType - The entity type name for type tracking
2674
+ * @returns The batch builder for method chaining
2675
+ * @internal
2676
+ */
2677
+ deleteWithCommand(command, entityType) {
2678
+ const batchItem = {
2679
+ type: "Delete",
2680
+ params: command,
2681
+ entityType
2682
+ };
2683
+ this.writeItems.push(batchItem);
2684
+ return this;
2685
+ }
2686
+ /**
2687
+ * Adds a get operation to the batch with entity type information.
2688
+ * This method is used internally by entity builders.
2689
+ *
2690
+ * @param command - The complete get command configuration
2691
+ * @param entityType - The entity type name for type tracking
2692
+ * @returns The batch builder for method chaining
2693
+ * @internal
2694
+ */
2695
+ getWithCommand(command, entityType) {
2696
+ const batchItem = {
2697
+ type: "Get",
2698
+ params: command,
2699
+ entityType
2700
+ };
2701
+ this.getItems.push(batchItem);
2702
+ return this;
2703
+ }
2704
+ /**
2705
+ * Executes all write operations in the batch.
2706
+ *
2707
+ * @returns A promise that resolves to any unprocessed operations
2708
+ * @private
2709
+ */
2710
+ async executeWrites() {
2711
+ if (this.writeItems.length === 0) {
2712
+ return { unprocessedItems: [] };
2713
+ }
2714
+ try {
2715
+ const operations = this.writeItems.map((item) => {
2716
+ if (item.type === "Put") {
2717
+ return {
2718
+ type: "put",
2719
+ item: item.params.item
2720
+ };
2721
+ }
2722
+ if (item.type === "Delete") {
2723
+ let key;
2724
+ if (typeof item.params.key === "object" && item.params.key !== null && "pk" in item.params.key) {
2725
+ key = item.params.key;
2726
+ } else {
2727
+ const tableKey = item.params.key;
2728
+ key = {
2729
+ pk: tableKey[this.config.partitionKey],
2730
+ sk: this.config.sortKey ? tableKey[this.config.sortKey] : void 0
2731
+ };
2732
+ }
2733
+ return {
2734
+ type: "delete",
2735
+ key
2736
+ };
2737
+ }
2738
+ throw new BatchError(`Unsupported batch item type for write operation: ${item.type}`, "write");
2739
+ });
2740
+ return await this.batchWriteExecutor(operations);
2741
+ } catch (error) {
2742
+ throw new BatchError(
2743
+ `Failed to execute batch write operations: ${error instanceof Error ? error.message : "Unknown error"}`,
2744
+ "write",
2745
+ error instanceof Error ? error : void 0
2746
+ );
2747
+ }
2748
+ }
2749
+ /**
2750
+ * Executes all get operations in the batch.
2751
+ *
2752
+ * @returns A promise that resolves to the retrieved items
2753
+ * @private
2754
+ */
2755
+ async executeGets() {
2756
+ if (this.getItems.length === 0) {
2757
+ return { items: [], unprocessedKeys: [] };
2758
+ }
2759
+ try {
2760
+ const keys = this.getItems.map((item) => {
2761
+ if (item.type === "Get") {
2762
+ if (typeof item.params.key === "object" && item.params.key !== null && "pk" in item.params.key) {
2763
+ return item.params.key;
2764
+ }
2765
+ const tableKey = item.params.key;
2766
+ return {
2767
+ pk: tableKey[this.config.partitionKey],
2768
+ sk: this.config.sortKey ? tableKey[this.config.sortKey] : void 0
2769
+ };
2770
+ }
2771
+ throw new BatchError(`Unsupported batch item type for get operation: ${item.type}`, "read");
2772
+ });
2773
+ return await this.batchGetExecutor(keys);
2774
+ } catch (error) {
2775
+ throw new BatchError(
2776
+ `Failed to execute batch get operations: ${error instanceof Error ? error.message : "Unknown error"}`,
2777
+ "read",
2778
+ error instanceof Error ? error : void 0
2779
+ );
2780
+ }
2781
+ }
2782
+ /**
2783
+ * Groups retrieved items by their entity type.
2784
+ * @private
2785
+ */
2786
+ groupItemsByType(items) {
2787
+ const grouped = {};
2788
+ for (const item of this.getItems) {
2789
+ if (item.entityType) {
2790
+ const entityType = item.entityType;
2791
+ if (!grouped[entityType]) {
2792
+ grouped[entityType] = [];
2793
+ }
2794
+ }
2795
+ }
2796
+ for (const item of items) {
2797
+ const entityType = item.entityType;
2798
+ if (entityType && grouped[entityType]) {
2799
+ grouped[entityType].push(item);
2800
+ }
2801
+ }
2802
+ return grouped;
2803
+ }
2804
+ /**
2805
+ * Executes all operations in the batch with typed results.
2806
+ * Performs write operations first, then get operations.
2807
+ *
2808
+ * @returns A promise that resolves to a TypedBatchResult with entity type information
2809
+ * @throws {BatchError} If the batch is empty or if operations fail
2810
+ */
2811
+ async execute() {
2812
+ this.validateNotEmpty();
2813
+ const errors = [];
2814
+ let writeResults = { unprocessedItems: [] };
2815
+ let getResults = {
2816
+ items: [],
2817
+ unprocessedKeys: []
2818
+ };
2819
+ if (this.writeItems.length > 0) {
2820
+ try {
2821
+ writeResults = await this.executeWrites();
2822
+ } catch (error) {
2823
+ if (error instanceof BatchError) {
2824
+ errors.push(error);
2825
+ } else {
2826
+ errors.push(
2827
+ new BatchError(
2828
+ "Unexpected error during write operations",
2829
+ "write",
2830
+ error instanceof Error ? error : void 0
2831
+ )
2832
+ );
2833
+ }
2834
+ }
2835
+ }
2836
+ if (this.getItems.length > 0) {
2837
+ try {
2838
+ getResults = await this.executeGets();
2839
+ } catch (error) {
2840
+ if (error instanceof BatchError) {
2841
+ errors.push(error);
2842
+ } else {
2843
+ errors.push(
2844
+ new BatchError(
2845
+ "Unexpected error during read operations",
2846
+ "read",
2847
+ error instanceof Error ? error : void 0
2848
+ )
2849
+ );
2850
+ }
2851
+ }
2852
+ }
2853
+ if (errors.length > 0 && (writeResults.unprocessedItems.length === this.writeItems.length || getResults.unprocessedKeys.length === this.getItems.length)) {
2854
+ throw errors[0];
2855
+ }
2856
+ const totalOperations = this.writeItems.length + this.getItems.length;
2857
+ const success = errors.length === 0 && writeResults.unprocessedItems.length === 0 && getResults.unprocessedKeys.length === 0;
2858
+ return {
2859
+ success,
2860
+ writes: {
2861
+ processed: this.writeItems.length - writeResults.unprocessedItems.length,
2862
+ unprocessed: writeResults.unprocessedItems
2863
+ },
2864
+ reads: {
2865
+ itemsByType: this.groupItemsByType(getResults.items),
2866
+ items: getResults.items,
2867
+ found: getResults.items.length,
2868
+ unprocessed: getResults.unprocessedKeys
2869
+ },
2870
+ totalOperations,
2871
+ errors: errors.length > 0 ? errors : void 0
2872
+ };
2873
+ }
2874
+ };
2875
+
2643
2876
  // src/builders/get-builder.ts
2644
2877
  var GetBuilder = class {
2645
2878
  /**
@@ -2661,10 +2894,6 @@ var GetBuilder = class {
2661
2894
  selectedFields = /* @__PURE__ */ new Set();
2662
2895
  /**
2663
2896
  * Specifies which attributes to return in the get results.
2664
- * Use this method when you need to:
2665
- * - Reduce data transfer by selecting specific dinosaur attributes
2666
- * - Optimize response size for dinosaur records
2667
- * - Focus on relevant dinosaur characteristics only
2668
2897
  *
2669
2898
  * @example
2670
2899
  * ```typescript
@@ -2718,6 +2947,60 @@ var GetBuilder = class {
2718
2947
  this.params.consistentRead = consistentRead;
2719
2948
  return this;
2720
2949
  }
2950
+ /**
2951
+ * Adds this get operation to a batch with optional entity type information.
2952
+ *
2953
+ * @example Basic Usage
2954
+ * ```ts
2955
+ * const batch = table.batchBuilder();
2956
+ *
2957
+ * // Add multiple get operations to batch
2958
+ * dinosaurRepo.get({ id: 'dino-1' }).withBatch(batch);
2959
+ * dinosaurRepo.get({ id: 'dino-2' }).withBatch(batch);
2960
+ * dinosaurRepo.get({ id: 'dino-3' }).withBatch(batch);
2961
+ *
2962
+ * // Execute all gets efficiently
2963
+ * const results = await batch.execute();
2964
+ * ```
2965
+ *
2966
+ * @example Typed Usage
2967
+ * ```ts
2968
+ * const batch = table.batchBuilder<{
2969
+ * User: UserEntity;
2970
+ * Order: OrderEntity;
2971
+ * }>();
2972
+ *
2973
+ * // Add operations with type information
2974
+ * userRepo.get({ id: 'user-1' }).withBatch(batch, 'User');
2975
+ * orderRepo.get({ id: 'order-1' }).withBatch(batch, 'Order');
2976
+ *
2977
+ * // Execute and get typed results
2978
+ * const result = await batch.execute();
2979
+ * const users: UserEntity[] = result.reads.itemsByType.User;
2980
+ * const orders: OrderEntity[] = result.reads.itemsByType.Order;
2981
+ * ```
2982
+ *
2983
+ * @param batch - The batch builder to add this operation to
2984
+ * @param entityType - Optional entity type key for type tracking
2985
+ */
2986
+ withBatch(batch, entityType) {
2987
+ const command = this.toDynamoCommand();
2988
+ batch.getWithCommand(command, entityType);
2989
+ }
2990
+ /**
2991
+ * Converts the builder configuration to a DynamoDB command
2992
+ */
2993
+ toDynamoCommand() {
2994
+ const expressionParams = {
2995
+ expressionAttributeNames: {}};
2996
+ const projectionExpression = Array.from(this.selectedFields).map((p) => generateAttributeName(expressionParams, p)).join(", ");
2997
+ const { expressionAttributeNames } = expressionParams;
2998
+ return {
2999
+ ...this.params,
3000
+ projectionExpression: projectionExpression.length > 0 ? projectionExpression : void 0,
3001
+ expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0
3002
+ };
3003
+ }
2721
3004
  /**
2722
3005
  * Executes the get operation against DynamoDB.
2723
3006
  *
@@ -2743,15 +3026,8 @@ var GetBuilder = class {
2743
3026
  * - item: The retrieved dinosaur or undefined if not found
2744
3027
  */
2745
3028
  async execute() {
2746
- const expressionParams = {
2747
- expressionAttributeNames: {}};
2748
- const projectionExpression = Array.from(this.selectedFields).map((p) => generateAttributeName(expressionParams, p)).join(", ");
2749
- const { expressionAttributeNames } = expressionParams;
2750
- return this.executor({
2751
- ...this.params,
2752
- projectionExpression: projectionExpression.length > 0 ? projectionExpression : void 0,
2753
- expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0
2754
- });
3029
+ const command = this.toDynamoCommand();
3030
+ return this.executor(command);
2755
3031
  }
2756
3032
  };
2757
3033
 
@@ -2764,10 +3040,6 @@ var ScanBuilder = class _ScanBuilder extends FilterBuilder {
2764
3040
  }
2765
3041
  /**
2766
3042
  * Creates a deep clone of this ScanBuilder instance.
2767
- * Use this method when you need to:
2768
- * - Create scan templates
2769
- * - Run multiple variations of a scan
2770
- * - Implement pagination (used internally by paginate())
2771
3043
  *
2772
3044
  * @returns A new ScanBuilder instance with the same configuration
2773
3045
  */
@@ -2779,11 +3051,6 @@ var ScanBuilder = class _ScanBuilder extends FilterBuilder {
2779
3051
  }
2780
3052
  /**
2781
3053
  * Executes the scan against DynamoDB.
2782
- * Use this method when you need to:
2783
- * - Search across the entire table
2784
- * - Find items matching specific criteria
2785
- * - Perform full table analysis
2786
- * - Generate reports across all data
2787
3054
  *
2788
3055
  * The method returns both the matched items and, if there are more results,
2789
3056
  * a lastEvaluatedKey that can be used with startFrom() to continue the scan.
@@ -3178,6 +3445,53 @@ var Table = class {
3178
3445
  sortKey: this.sortKey
3179
3446
  });
3180
3447
  }
3448
+ /**
3449
+ * Creates a batch builder for performing multiple operations efficiently with optional type inference
3450
+ *
3451
+ * @example Basic Usage
3452
+ * ```typescript
3453
+ * const batch = table.batchBuilder();
3454
+ *
3455
+ * // Add operations
3456
+ * userRepo.create(newUser).withBatch(batch);
3457
+ * orderRepo.get({ id: 'order-1' }).withBatch(batch);
3458
+ *
3459
+ * // Execute operations
3460
+ * const result = await batch.execute();
3461
+ * ```
3462
+ *
3463
+ * @example Typed Usage
3464
+ * ```typescript
3465
+ * // Define entity types for the batch
3466
+ * const batch = table.batchBuilder<{
3467
+ * User: UserEntity;
3468
+ * Order: OrderEntity;
3469
+ * Product: ProductEntity;
3470
+ * }>();
3471
+ *
3472
+ * // Add operations with type information
3473
+ * userRepo.create(newUser).withBatch(batch, 'User');
3474
+ * orderRepo.get({ id: 'order-1' }).withBatch(batch, 'Order');
3475
+ * productRepo.delete({ id: 'old-product' }).withBatch(batch, 'Product');
3476
+ *
3477
+ * // Execute and get typed results
3478
+ * const result = await batch.execute();
3479
+ * const users: UserEntity[] = result.reads.itemsByType.User;
3480
+ * const orders: OrderEntity[] = result.reads.itemsByType.Order;
3481
+ * ```
3482
+ */
3483
+ batchBuilder() {
3484
+ const batchWriteExecutor = async (operations) => {
3485
+ return this.batchWrite(operations);
3486
+ };
3487
+ const batchGetExecutor = async (keys) => {
3488
+ return this.batchGet(keys);
3489
+ };
3490
+ return new BatchBuilder(batchWriteExecutor, batchGetExecutor, {
3491
+ partitionKey: this.partitionKey,
3492
+ sortKey: this.sortKey
3493
+ });
3494
+ }
3181
3495
  /**
3182
3496
  * Executes a transaction using a callback function
3183
3497
  *