dyno-table 0.1.7 → 0.1.8

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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +115 -17
  3. package/dist/builders/condition-check-builder.cjs +394 -0
  4. package/dist/builders/condition-check-builder.cjs.map +1 -0
  5. package/dist/builders/condition-check-builder.js +392 -0
  6. package/dist/builders/condition-check-builder.js.map +1 -0
  7. package/dist/builders/delete-builder.cjs +422 -0
  8. package/dist/builders/delete-builder.cjs.map +1 -0
  9. package/dist/builders/delete-builder.js +420 -0
  10. package/dist/builders/delete-builder.js.map +1 -0
  11. package/dist/builders/paginator.cjs +199 -0
  12. package/dist/builders/paginator.cjs.map +1 -0
  13. package/dist/builders/paginator.js +197 -0
  14. package/dist/builders/paginator.js.map +1 -0
  15. package/dist/builders/put-builder.cjs +468 -0
  16. package/dist/builders/put-builder.cjs.map +1 -0
  17. package/dist/builders/put-builder.js +466 -0
  18. package/dist/builders/put-builder.js.map +1 -0
  19. package/dist/builders/query-builder.cjs +674 -0
  20. package/dist/builders/query-builder.cjs.map +1 -0
  21. package/dist/builders/query-builder.js +672 -0
  22. package/dist/builders/query-builder.js.map +1 -0
  23. package/dist/builders/transaction-builder.cjs +876 -0
  24. package/dist/builders/transaction-builder.cjs.map +1 -0
  25. package/dist/builders/transaction-builder.js +874 -0
  26. package/dist/builders/transaction-builder.js.map +1 -0
  27. package/dist/builders/update-builder.cjs +662 -0
  28. package/dist/builders/update-builder.cjs.map +1 -0
  29. package/dist/builders/update-builder.js +660 -0
  30. package/dist/builders/update-builder.js.map +1 -0
  31. package/dist/conditions.cjs +59 -0
  32. package/dist/conditions.cjs.map +1 -0
  33. package/dist/conditions.js +43 -0
  34. package/dist/conditions.js.map +1 -0
  35. package/dist/entity.cjs +169 -0
  36. package/dist/entity.cjs.map +1 -0
  37. package/dist/entity.js +165 -0
  38. package/dist/entity.js.map +1 -0
  39. package/dist/index.cjs +3333 -0
  40. package/dist/index.d.cts +2971 -0
  41. package/dist/index.d.ts +386 -338
  42. package/dist/index.js +247 -232
  43. package/dist/standard-schema.cjs +4 -0
  44. package/dist/standard-schema.cjs.map +1 -0
  45. package/dist/standard-schema.js +3 -0
  46. package/dist/standard-schema.js.map +1 -0
  47. package/dist/table.cjs +3265 -0
  48. package/dist/table.cjs.map +1 -0
  49. package/dist/table.js +3263 -0
  50. package/dist/table.js.map +1 -0
  51. package/dist/types.cjs +4 -0
  52. package/dist/types.cjs.map +1 -0
  53. package/dist/types.js +3 -0
  54. package/dist/types.js.map +1 -0
  55. package/dist/utils/key-template.cjs +19 -0
  56. package/dist/utils/key-template.cjs.map +1 -0
  57. package/dist/utils/key-template.js +17 -0
  58. package/dist/utils/key-template.js.map +1 -0
  59. package/dist/utils/sort-key-template.cjs +19 -0
  60. package/dist/utils/sort-key-template.cjs.map +1 -0
  61. package/dist/utils/sort-key-template.js +17 -0
  62. package/dist/utils/sort-key-template.js.map +1 -0
  63. package/package.json +24 -26
package/dist/index.d.ts CHANGED
@@ -375,7 +375,13 @@ interface DeleteCommandParams extends DynamoCommandWithExpressions {
375
375
  }
376
376
  /**
377
377
  * Parameters for the DynamoDB put command.
378
+ *
378
379
  * These parameters are used when executing the operation against DynamoDB.
380
+ *
381
+ * The `returnValues` property can be:
382
+ * - `"ALL_OLD"`: Return the attributes of the item as they were before the operation
383
+ * - `"NONE"`: Return nothing
384
+ * - `"CONSISTENT"`: Triggers a GET operation after the put to retrieve the updated item state
379
385
  */
380
386
  interface PutCommandParams extends DynamoCommandWithExpressions {
381
387
  tableName: string;
@@ -383,7 +389,7 @@ interface PutCommandParams extends DynamoCommandWithExpressions {
383
389
  conditionExpression?: string;
384
390
  expressionAttributeNames?: Record<string, string>;
385
391
  expressionAttributeValues?: Record<string, unknown>;
386
- returnValues?: "ALL_OLD" | "NONE";
392
+ returnValues?: "ALL_OLD" | "NONE" | "CONSISTENT";
387
393
  }
388
394
  /**
389
395
  * Parameters for the DynamoDB update command.
@@ -413,19 +419,37 @@ interface ConditionCheckCommandParams extends DynamoCommandWithExpressions {
413
419
  expressionAttributeValues?: Record<string, unknown>;
414
420
  }
415
421
  /**
416
- * Interface for the QueryBuilder class to be used by Paginator
417
- * without creating a circular dependency.
422
+ * Base interface for all builder classes that support pagination
423
+ * to be used by Paginator without creating circular dependencies.
418
424
  */
419
- interface QueryBuilderInterface<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> {
420
- clone(): QueryBuilderInterface<T, TConfig>;
421
- limit(limit: number): QueryBuilderInterface<T, TConfig>;
425
+ interface BaseBuilderInterface<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig, B = unknown> {
426
+ clone(): B;
427
+ limit(limit: number): B;
422
428
  getLimit(): number | undefined;
423
- startFrom(lastEvaluatedKey: Record<string, unknown>): QueryBuilderInterface<T, TConfig>;
429
+ startFrom(lastEvaluatedKey: Record<string, unknown>): B;
424
430
  execute(): Promise<{
425
431
  items: T[];
426
432
  lastEvaluatedKey?: Record<string, unknown>;
427
433
  }>;
428
434
  }
435
+ /**
436
+ * Interface for the QueryBuilder class to be used by Paginator
437
+ * without creating a circular dependency.
438
+ */
439
+ interface QueryBuilderInterface<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends BaseBuilderInterface<T, TConfig, QueryBuilderInterface<T, TConfig>> {
440
+ }
441
+ /**
442
+ * Interface for the ScanBuilder class to be used by Paginator
443
+ * without creating a circular dependency.
444
+ */
445
+ interface ScanBuilderInterface<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends BaseBuilderInterface<T, TConfig, ScanBuilderInterface<T, TConfig>> {
446
+ }
447
+ /**
448
+ * Interface for the FilterBuilder class to be used by Paginator
449
+ * without creating a circular dependency.
450
+ */
451
+ interface FilterBuilderInterface<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends BaseBuilderInterface<T, TConfig, FilterBuilderInterface<T, TConfig>> {
452
+ }
429
453
  /**
430
454
  * Represents the result of a single page query operation.
431
455
  * This interface provides all necessary information about the current page
@@ -617,140 +641,54 @@ declare class Paginator<T extends Record<string, unknown>, TConfig extends Table
617
641
  }
618
642
 
619
643
  /**
620
- * Configuration options for DynamoDB query operations.
644
+ * Configuration options for DynamoDB filter operations.
645
+ * These are common options shared between query and scan operations.
621
646
  */
622
- interface QueryOptions {
623
- /** Condition for the sort key in the table or index */
624
- sortKeyCondition?: Condition;
625
- /** Additional filter conditions applied after the key condition */
647
+ interface FilterOptions {
648
+ /** Filter conditions applied to results */
626
649
  filter?: Condition;
627
650
  /** Maximum number of items to return */
628
651
  limit?: number;
629
- /** Name of the Global Secondary Index to query */
652
+ /** Name of the Global Secondary Index to use */
630
653
  indexName?: string;
631
654
  /** Whether to use strongly consistent reads */
632
655
  consistentRead?: boolean;
633
- /** Direction of sort key traversal (true for ascending, false for descending) */
634
- scanIndexForward?: boolean;
635
656
  /** List of attributes to return in the result */
636
657
  projection?: string[];
637
- /** Number of items to fetch per page when using pagination */
638
- paginationSize?: number;
639
- /** Token for starting the query from a specific point */
658
+ /** Token for starting the operation from a specific point */
640
659
  lastEvaluatedKey?: Record<string, unknown>;
641
660
  }
642
661
  /**
643
- * Function type for executing DynamoDB query operations.
644
- * @typeParam T - The type of items being queried
645
- */
646
- type QueryExecutor<T extends Record<string, unknown>> = (keyCondition: Condition, options: QueryOptions) => Promise<{
647
- items: T[];
648
- lastEvaluatedKey?: Record<string, unknown>;
649
- }>;
650
- /**
651
- * Builder for creating DynamoDB query operations.
652
- * Use this builder when you need to:
653
- * - Query items using partition key (and optionally sort key)
654
- * - Filter results based on non-key attributes
655
- * - Use Global Secondary Indexes (GSIs)
656
- * - Implement pagination
657
- * - Control result ordering
658
- * - Project specific attributes
662
+ * Abstract base builder for creating DynamoDB filter operations.
663
+ * This class provides common functionality for both Query and Scan operations.
659
664
  *
660
665
  * The builder supports:
661
666
  * - Type-safe GSI selection
662
667
  * - Complex filter conditions
663
- * - Automatic pagination handling
668
+ * - Pagination
664
669
  * - Consistent reads
665
- * - Forward and reverse sorting
666
- *
667
- * @example
668
- * ```ts
669
- * // Simple query
670
- * const result = await new QueryBuilder(executor, eq('userId', '123'))
671
- * .execute();
672
- *
673
- * // Complex query with GSI and filtering
674
- * const result = await new QueryBuilder(executor, eq('status', 'ACTIVE'))
675
- * .useIndex('status-index')
676
- * .filter(op => op.beginsWith('name', 'John'))
677
- * .select(['id', 'name', 'email'])
678
- * .sortDescending()
679
- * .limit(10)
680
- * .execute();
681
- *
682
- * // Query with pagination
683
- * const paginator = new QueryBuilder(executor, eq('type', 'order'))
684
- * .paginate(25);
685
- *
686
- * while (paginator.hasNextPage()) {
687
- * const page = await paginator.getNextPage();
688
- * // Process page.items
689
- * }
690
- * ```
691
- *
692
- * @typeParam T - The type of items being queried
693
- * @typeParam TConfig - The table configuration type for type-safe GSI selection
694
- */
695
- /**
696
- * Builder for creating DynamoDB query operations.
697
- * Use this builder when you need to:
698
- * - Find dinosaurs by species or status
699
- * - Search habitats by type or region
700
- * - List incidents by date range
701
- * - Retrieve feeding schedules
702
- *
703
- * The builder supports:
704
- * - Complex filtering conditions
705
- * - Sorting and pagination
706
- * - Global Secondary Indexes
707
670
  * - Attribute projection
708
671
  *
709
- * @example
710
- * ```typescript
711
- * // Find active carnivores
712
- * const result = await new QueryBuilder(executor, eq('species', 'Tyrannosaurus'))
713
- * .filter(op => op.eq('status', 'ACTIVE'))
714
- * .execute();
715
- *
716
- * // Search habitats by security level
717
- * const result = await new QueryBuilder(executor, eq('type', 'CARNIVORE'))
718
- * .useIndex('security-level-index')
719
- * .filter(op => op.gt('securityLevel', 8))
720
- * .select(['id', 'capacity', 'currentOccupants'])
721
- * .sortDescending()
722
- * .execute();
723
- *
724
- * // List recent incidents
725
- * const result = await new QueryBuilder(executor, eq('type', 'INCIDENT'))
726
- * .useIndex('date-index')
727
- * .filter(op => op.gt('severityLevel', 5))
728
- * .paginate(10);
729
- * ```
730
- *
731
- * @typeParam T - The type of items being queried
672
+ * @typeParam T - The type of items being filtered
732
673
  * @typeParam TConfig - The table configuration type for type-safe GSI selection
733
674
  */
734
- declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> implements QueryBuilderInterface<T, TConfig> {
735
- private readonly keyCondition;
736
- private options;
737
- private selectedFields;
738
- private readonly executor;
739
- constructor(executor: QueryExecutor<T>, keyCondition: Condition);
675
+ declare abstract class FilterBuilder<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> implements FilterBuilderInterface<T, TConfig> {
676
+ protected options: FilterOptions;
677
+ protected selectedFields: Set<string>;
740
678
  /**
741
- * Sets the maximum number of items to return from the query.
679
+ * Sets the maximum number of items to return.
742
680
  * Use this method when you need to:
743
- * - Limit the result set size
744
- * - Implement manual pagination
745
- * - Control data transfer size
681
+ * - Limit the number of dinosaurs returned
682
+ * - Control the size of habitat reports
683
+ * - Implement manual pagination of security logs
746
684
  *
747
685
  * Note: This limit applies to the items that match the key condition
748
686
  * before any filter expressions are applied.
749
687
  *
750
688
  * @example
751
- * ```ts
752
- * // Get first 10 orders for a user
753
- * const result = await new QueryBuilder(executor, eq('userId', '123'))
689
+ * ```typescript
690
+ * // Get first 10 dinosaurs
691
+ * const result = await builder
754
692
  * .limit(10)
755
693
  * .execute();
756
694
  * ```
@@ -758,50 +696,18 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
758
696
  * @param limit - Maximum number of items to return
759
697
  * @returns The builder instance for method chaining
760
698
  */
761
- limit(limit: number): QueryBuilder<T>;
699
+ limit(limit: number): this;
762
700
  /**
763
- * Gets the current limit set on the query.
701
+ * Gets the current limit set on the operation.
764
702
  * This is used internally by the paginator to manage result sets.
765
703
  *
766
704
  * @returns The current limit or undefined if no limit is set
767
705
  */
768
706
  getLimit(): number | undefined;
769
707
  /**
770
- * Specifies a Global Secondary Index (GSI) to use for the query.
771
- * Use this method when you need to:
772
- * - Query data using non-primary key attributes
773
- * - Access data through alternate access patterns
774
- * - Optimize query performance for specific access patterns
775
- *
776
- * This method provides type safety by only allowing valid GSI names
777
- * defined in your table configuration.
778
- *
779
- * @example
780
- * ```ts
781
- * // Query by status using a GSI
782
- * const result = await new QueryBuilder(executor, eq('status', 'ACTIVE'))
783
- * .useIndex('status-index')
784
- * .execute();
785
- *
786
- * // Query by category and date range
787
- * const result = await new QueryBuilder(executor, eq('category', 'books'))
788
- * .useIndex('category-date-index')
789
- * .filter(op => op.between('date', startDate, endDate))
790
- * .execute();
791
- * ```
792
- *
793
- * Note: Be aware that GSIs:
794
- * - May have different projected attributes
795
- * - Have eventually consistent reads only
796
- * - May have different provisioned throughput
797
- *
798
- * @param indexName - The name of the GSI to use (type-safe based on table configuration)
799
- * @returns The builder instance for method chaining
800
- */
801
- /**
802
- * Specifies a Global Secondary Index (GSI) to use for the query.
708
+ * Specifies a Global Secondary Index (GSI) to use for the operation.
803
709
  * Use this method when you need to:
804
- * - Query dinosaurs by species or status
710
+ * - Find dinosaurs by species or status
805
711
  * - Search habitats by security level
806
712
  * - Find incidents by date
807
713
  * - List feeding schedules by time
@@ -827,9 +733,9 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
827
733
  * @param indexName - The name of the GSI to use (type-safe based on table configuration)
828
734
  * @returns The builder instance for method chaining
829
735
  */
830
- useIndex<I extends GSINames<TConfig>>(indexName: I): QueryBuilder<T, TConfig>;
736
+ useIndex<I extends GSINames<TConfig>>(indexName: I): this;
831
737
  /**
832
- * Sets whether to use strongly consistent reads for the query.
738
+ * Sets whether to use strongly consistent reads for the operation.
833
739
  * Use this method when you need to:
834
740
  * - Get real-time dinosaur status updates
835
741
  * - Monitor critical security systems
@@ -842,15 +748,15 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
842
748
  * - Default is eventually consistent reads
843
749
  *
844
750
  * @example
845
- * ```ts
751
+ * ```typescript
846
752
  * // Check immediate dinosaur status
847
- * const result = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
753
+ * const result = await builder
848
754
  * .filter(op => op.eq('status', 'ACTIVE'))
849
755
  * .consistentRead()
850
756
  * .execute();
851
757
  *
852
758
  * // Monitor security breaches
853
- * const result = await new QueryBuilder(executor, eq('type', 'SECURITY_ALERT'))
759
+ * const result = await builder
854
760
  * .useIndex('primary-index')
855
761
  * .consistentRead(isEmergencyMode)
856
762
  * .execute();
@@ -859,37 +765,9 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
859
765
  * @param consistentRead - Whether to use consistent reads (defaults to true)
860
766
  * @returns The builder instance for method chaining
861
767
  */
862
- consistentRead(consistentRead?: boolean): QueryBuilder<T>;
863
- /**
864
- * Adds a filter expression to the query.
865
- * Use this method when you need to:
866
- * - Filter results based on non-key attributes
867
- * - Apply complex filtering conditions
868
- * - Combine multiple filter conditions
869
- *
870
- * Note: Filter expressions are applied after the key condition,
871
- * so they don't reduce the amount of data read from DynamoDB.
872
- *
873
- * @example
874
- * ```ts
875
- * // Simple filter
876
- * builder.filter(op => op.eq('status', 'ACTIVE'))
877
- *
878
- * // Complex filter with multiple conditions
879
- * builder.filter(op =>
880
- * op.and([
881
- * op.gt('amount', 1000),
882
- * op.beginsWith('category', 'ELECTRONICS'),
883
- * op.attributeExists('reviewDate')
884
- * ])
885
- * )
886
- * ```
887
- *
888
- * @param condition - Either a Condition object or a callback function that builds the condition
889
- * @returns The builder instance for method chaining
890
- */
768
+ consistentRead(consistentRead?: boolean): this;
891
769
  /**
892
- * Adds a filter expression to refine the query results.
770
+ * Adds a filter expression to refine the operation results.
893
771
  * Use this method when you need to:
894
772
  * - Filter dinosaurs by behavior patterns
895
773
  * - Find habitats with specific conditions
@@ -920,36 +798,9 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
920
798
  * @param condition - Either a Condition object or a callback function that builds the condition
921
799
  * @returns The builder instance for method chaining
922
800
  */
923
- filter(condition: Condition | ((op: ConditionOperator<T>) => Condition)): QueryBuilder<T>;
924
- /**
925
- * Specifies which attributes to return in the query results.
926
- * Use this method when you need to:
927
- * - Reduce data transfer by selecting specific attributes
928
- * - Optimize response size
929
- * - Focus on relevant attributes only
930
- *
931
- * Note: Using projection can significantly reduce the amount
932
- * of data returned and lower your costs.
933
- *
934
- * @example
935
- * ```ts
936
- * // Select single attribute
937
- * builder.select('email')
938
- *
939
- * // Select multiple attributes
940
- * builder.select(['id', 'name', 'email'])
941
- *
942
- * // Chain multiple select calls
943
- * builder
944
- * .select('id')
945
- * .select(['name', 'email'])
946
- * ```
947
- *
948
- * @param fields - A single field name or an array of field names to return
949
- * @returns The builder instance for method chaining
950
- */
801
+ filter(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this;
951
802
  /**
952
- * Specifies which attributes to return in the query results.
803
+ * Specifies which attributes to return in the results.
953
804
  * Use this method when you need to:
954
805
  * - Get specific dinosaur attributes
955
806
  * - Retrieve habitat statistics
@@ -979,13 +830,177 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
979
830
  * @param fields - A single field name or an array of field names to return
980
831
  * @returns The builder instance for method chaining
981
832
  */
982
- select(fields: string | string[]): QueryBuilder<T>;
833
+ select(fields: string | string[]): this;
983
834
  /**
984
- * Sets the query to return items in ascending order by sort key.
835
+ * Creates a paginator that handles DynamoDB pagination automatically.
836
+ * The paginator handles:
837
+ * - Tracking the last evaluated key
838
+ * - Managing page boundaries
839
+ * - Respecting overall query limits
840
+ *
841
+ * @example
842
+ * ```typescript
843
+ * // Create a paginator for dinosaur records
844
+ * const paginator = builder
845
+ * .filter(op => op.eq('status', 'ACTIVE'))
846
+ * .paginate(10);
847
+ *
848
+ * // Process pages of dinosaur results
849
+ * while (paginator.hasNextPage()) {
850
+ * const page = await paginator.getNextPage();
851
+ * console.log(`Processing page ${page.page}, count: ${page.items.length}`);
852
+ * // Process dinosaur data
853
+ * }
854
+ * ```
855
+ *
856
+ * @param pageSize - The number of items to return per page
857
+ * @returns A Paginator instance that manages the pagination state
858
+ * @see Paginator for more pagination control options
859
+ */
860
+ paginate(pageSize: number): Paginator<T, TConfig>;
861
+ /**
862
+ * Sets the starting point using a previous lastEvaluatedKey.
863
+ * Use this method when you need to:
864
+ * - Implement manual dinosaur list pagination
865
+ * - Resume habitat inspection reviews
866
+ * - Continue security incident analysis
867
+ * - Store operation position between sessions
868
+ *
869
+ * Note: This method is typically used for manual pagination.
870
+ * For automatic pagination, use the paginate() method instead.
871
+ *
872
+ * @example
873
+ * ```typescript
874
+ * // First batch of dinosaurs
875
+ * const result1 = await builder
876
+ * .filter(op => op.eq('status', 'ACTIVE'))
877
+ * .limit(5)
878
+ * .execute();
879
+ *
880
+ * if (result1.lastEvaluatedKey) {
881
+ * // Continue listing dinosaurs
882
+ * const result2 = await builder
883
+ * .filter(op => op.eq('status', 'ACTIVE'))
884
+ * .startFrom(result1.lastEvaluatedKey)
885
+ * .limit(5)
886
+ * .execute();
887
+ *
888
+ * console.log('Additional dinosaurs:', result2.items);
889
+ * }
890
+ * ```
891
+ *
892
+ * @param lastEvaluatedKey - The exclusive start key from a previous result
893
+ * @returns The builder instance for method chaining
894
+ */
895
+ startFrom(lastEvaluatedKey: Record<string, unknown>): this;
896
+ /**
897
+ * Creates a deep clone of this builder instance.
985
898
  * Use this method when you need to:
986
- * - Retrieve items in natural order (e.g., timestamps, versions)
987
- * - Implement chronological ordering
988
- * - Get oldest items first
899
+ * - Query different dinosaur statuses
900
+ * - Check multiple habitat conditions
901
+ * - Monitor various security levels
902
+ * - Create report templates
903
+ *
904
+ * This is particularly useful when:
905
+ * - Implementing pagination (used internally by paginate())
906
+ * - Creating operation templates
907
+ * - Running multiple variations of an operation
908
+ *
909
+ * @example
910
+ * ```typescript
911
+ * // Create base dinosaur query
912
+ * const baseBuilder = builder
913
+ * .useIndex('status-index')
914
+ * .select(['id', 'status', 'location']);
915
+ *
916
+ * // Check active dinosaurs
917
+ * const activeRaptors = baseBuilder.clone()
918
+ * .filter(op => op.eq('status', 'HUNTING'))
919
+ * .execute();
920
+ *
921
+ * // Check contained dinosaurs
922
+ * const containedRaptors = baseBuilder.clone()
923
+ * .filter(op => op.eq('status', 'CONTAINED'))
924
+ * .execute();
925
+ * ```
926
+ *
927
+ * @returns A new builder instance with the same configuration
928
+ */
929
+ abstract clone(): FilterBuilderInterface<T, TConfig>;
930
+ /**
931
+ * Executes the operation against DynamoDB.
932
+ * This method must be implemented by subclasses to handle
933
+ * their specific execution logic.
934
+ */
935
+ abstract execute(): Promise<{
936
+ items: T[];
937
+ lastEvaluatedKey?: Record<string, unknown>;
938
+ }>;
939
+ }
940
+
941
+ /**
942
+ * Configuration options for DynamoDB query operations.
943
+ * Extends the base FilterOptions with query-specific options.
944
+ */
945
+ interface QueryOptions extends FilterOptions {
946
+ /** Condition for the sort key in the table or index */
947
+ sortKeyCondition?: Condition;
948
+ /** Direction of sort key traversal (true for ascending, false for descending) */
949
+ scanIndexForward?: boolean;
950
+ }
951
+ /**
952
+ * Function type for executing DynamoDB query operations.
953
+ * @typeParam T - The type of items being queried
954
+ */
955
+ type QueryExecutor<T extends Record<string, unknown>> = (keyCondition: Condition, options: QueryOptions) => Promise<{
956
+ items: T[];
957
+ lastEvaluatedKey?: Record<string, unknown>;
958
+ }>;
959
+ /**
960
+ * Builder for creating DynamoDB query operations.
961
+ *
962
+ * The builder supports:
963
+ * - Type-safe GSI selection
964
+ * - Complex filter conditions
965
+ * - Automatic pagination handling
966
+ * - Consistent reads
967
+ * - Forward and reverse sorting
968
+ *
969
+ * @example
970
+ * ```typescript
971
+ * // Simple query
972
+ * const result = await new QueryBuilder(executor, eq('userId', '123'))
973
+ * .execute();
974
+ *
975
+ * // Complex query with GSI and filtering
976
+ * const result = await new QueryBuilder(executor, eq('status', 'ACTIVE'))
977
+ * .useIndex('status-index')
978
+ * .filter(op => op.beginsWith('name', 'John'))
979
+ * .select(['id', 'name', 'email'])
980
+ * .sortDescending()
981
+ * .limit(10)
982
+ * .execute();
983
+ *
984
+ * // Query with pagination
985
+ * const paginator = new QueryBuilder(executor, eq('type', 'order'))
986
+ * .paginate(25);
987
+ *
988
+ * while (paginator.hasNextPage()) {
989
+ * const page = await paginator.getNextPage();
990
+ * // Process page.items
991
+ * }
992
+ * ```
993
+ *
994
+ * @typeParam T - The type of items being queried
995
+ * @typeParam TConfig - The table configuration type for type-safe GSI selection
996
+ */
997
+ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends FilterBuilder<T, TConfig> implements QueryBuilderInterface<T, TConfig> {
998
+ private readonly keyCondition;
999
+ protected options: QueryOptions;
1000
+ protected readonly executor: QueryExecutor<T>;
1001
+ constructor(executor: QueryExecutor<T>, keyCondition: Condition);
1002
+ /**
1003
+ * Sets the maximum number of items to return from the query.
989
1004
  *
990
1005
  * Note: This is the default behavior if no sort order is specified.
991
1006
  *
@@ -1007,11 +1022,6 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
1007
1022
  */
1008
1023
  /**
1009
1024
  * Sets the query to return items in ascending order by sort key.
1010
- * Use this method when you need to:
1011
- * - List dinosaurs by age (youngest first)
1012
- * - View incidents chronologically
1013
- * - Track feeding schedule progression
1014
- * - Monitor habitat inspections
1015
1025
  *
1016
1026
  * @example
1017
1027
  * ```typescript
@@ -1033,11 +1043,6 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
1033
1043
  sortAscending(): QueryBuilder<T>;
1034
1044
  /**
1035
1045
  * Sets the query to return items in descending order by sort key.
1036
- * Use this method when you need to:
1037
- * - Get most recent security breaches
1038
- * - Find oldest dinosaurs first
1039
- * - Check latest habitat modifications
1040
- * - Monitor recent feeding events
1041
1046
  *
1042
1047
  * @example
1043
1048
  * ```typescript
@@ -1059,87 +1064,8 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
1059
1064
  * @returns The builder instance for method chaining
1060
1065
  */
1061
1066
  sortDescending(): QueryBuilder<T>;
1062
- /**
1063
- * Creates a paginator that handles DynamoDB pagination automatically.
1064
- * Use this method when you need to:
1065
- * - Browse large dinosaur collections
1066
- * - View habitat inspection history
1067
- * - Monitor security incidents
1068
- * - Track feeding patterns
1069
- *
1070
- * The paginator handles:
1071
- * - Tracking the last evaluated key
1072
- * - Managing page boundaries
1073
- * - Respecting overall query limits
1074
- *
1075
- * @example
1076
- * ```typescript
1077
- * // List dinosaurs by species
1078
- * const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
1079
- * .filter(op => op.eq('status', 'ACTIVE'))
1080
- * .useIndex('species-index')
1081
- * .paginate(10);
1082
- *
1083
- * // Process pages of security incidents
1084
- * const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
1085
- * .filter(op => op.gt('severityLevel', 7))
1086
- * .sortDescending()
1087
- * .paginate(25);
1088
- *
1089
- * while (paginator.hasNextPage()) {
1090
- * const page = await paginator.getNextPage();
1091
- * console.log(`Processing incidents page ${page.page}, count: ${page.items.length}`);
1092
- * // Handle security incidents
1093
- * }
1094
- * ```
1095
- *
1096
- * @param pageSize - The number of items to return per page
1097
- * @returns A Paginator instance that manages the pagination state
1098
- * @see Paginator for more pagination control options
1099
- */
1100
- paginate(pageSize: number): Paginator<T, TConfig>;
1101
- /**
1102
- * Sets the starting point for the query using a previous lastEvaluatedKey.
1103
- * Use this method when you need to:
1104
- * - Implement manual dinosaur list pagination
1105
- * - Resume habitat inspection reviews
1106
- * - Continue security incident analysis
1107
- * - Store query position between sessions
1108
- *
1109
- * Note: This method is typically used for manual pagination.
1110
- * For automatic pagination, use the paginate() method instead.
1111
- *
1112
- * @example
1113
- * ```typescript
1114
- * // First batch of dinosaurs
1115
- * const result1 = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
1116
- * .filter(op => op.eq('status', 'ACTIVE'))
1117
- * .limit(5)
1118
- * .execute();
1119
- *
1120
- * if (result1.lastEvaluatedKey) {
1121
- * // Continue listing dinosaurs
1122
- * const result2 = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
1123
- * .filter(op => op.eq('status', 'ACTIVE'))
1124
- * .startFrom(result1.lastEvaluatedKey)
1125
- * .limit(5)
1126
- * .execute();
1127
- *
1128
- * console.log('Additional dinosaurs:', result2.items);
1129
- * }
1130
- * ```
1131
- *
1132
- * @param lastEvaluatedKey - The exclusive start key from a previous query result
1133
- * @returns The builder instance for method chaining
1134
- */
1135
- startFrom(lastEvaluatedKey: Record<string, unknown>): QueryBuilder<T>;
1136
1067
  /**
1137
1068
  * Creates a deep clone of this QueryBuilder instance.
1138
- * Use this method when you need to:
1139
- * - Query different dinosaur statuses
1140
- * - Check multiple habitat conditions
1141
- * - Monitor various security levels
1142
- * - Create report templates
1143
1069
  *
1144
1070
  * This is particularly useful when:
1145
1071
  * - Implementing pagination (used internally by paginate())
@@ -1174,11 +1100,6 @@ declare class QueryBuilder<T extends Record<string, unknown>, TConfig extends Ta
1174
1100
  clone(): QueryBuilder<T, TConfig>;
1175
1101
  /**
1176
1102
  * Executes the query against DynamoDB.
1177
- * Use this method when you need to:
1178
- * - Find specific dinosaur groups
1179
- * - Check habitat conditions
1180
- * - Monitor security incidents
1181
- * - Track feeding patterns
1182
1103
  *
1183
1104
  * The method returns both the matched items and, if there are more results,
1184
1105
  * a lastEvaluatedKey that can be used with startFrom() to continue the query.
@@ -1728,17 +1649,17 @@ declare class TransactionBuilder {
1728
1649
  interface PutOptions {
1729
1650
  /** Optional condition that must be satisfied for the put operation to succeed */
1730
1651
  condition?: Condition;
1731
- /** Determines whether to return the item's previous state (if it existed) */
1732
- returnValues?: "ALL_OLD" | "NONE";
1652
+ /** Determines how to handle the return value of the put operation
1653
+ * @options
1654
+ * - NONE: No return value
1655
+ * - ALL_OLD: Returns the item's previous state if it existed
1656
+ * - CONSISTENT: (default) Performs a GET operation after the put to retrieve the item's new state
1657
+ */
1658
+ returnValues?: "ALL_OLD" | "NONE" | "CONSISTENT";
1733
1659
  }
1734
1660
  type PutExecutor<T extends Record<string, unknown>> = (params: PutCommandParams) => Promise<T>;
1735
1661
  /**
1736
1662
  * Builder for creating DynamoDB put operations.
1737
- * Use this builder when you need to:
1738
- * - Add new dinosaurs to the registry
1739
- * - Create new habitats
1740
- * - Update dinosaur profiles completely
1741
- * - Initialize tracking records
1742
1663
  *
1743
1664
  * @example
1744
1665
  * ```typescript
@@ -1801,10 +1722,6 @@ declare class PutBuilder<T extends Record<string, unknown>> {
1801
1722
  */
1802
1723
  /**
1803
1724
  * Adds a condition that must be satisfied for the put operation to succeed.
1804
- * Use this method when you need to:
1805
- * - Prevent duplicate dinosaur entries
1806
- * - Ensure habitat requirements
1807
- * - Validate security protocols
1808
1725
  *
1809
1726
  * @example
1810
1727
  * ```typescript
@@ -1835,13 +1752,14 @@ declare class PutBuilder<T extends Record<string, unknown>> {
1835
1752
  * @param condition - Either a Condition object or a callback function that builds the condition
1836
1753
  * @returns The builder instance for method chaining
1837
1754
  */
1838
- condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): PutBuilder<T>;
1755
+ condition(condition: Condition | ((op: ConditionOperator<T>) => Condition)): this;
1839
1756
  /**
1840
1757
  * Sets whether to return the item's previous values (if it existed).
1841
- * Use this method when you need to:
1842
- * - Track dinosaur profile updates
1843
- * - Monitor habitat modifications
1844
- * - Maintain change history
1758
+ *
1759
+ * @options
1760
+ * - NONE: No return value
1761
+ * - ALL_OLD: Returns the item's previous state if it existed, no read capacity units are consumed
1762
+ * - CONSISTENT: (default) Performs a GET operation after the put to retrieve the item's new state
1845
1763
  *
1846
1764
  * @example
1847
1765
  * ```ts
@@ -1862,10 +1780,10 @@ declare class PutBuilder<T extends Record<string, unknown>> {
1862
1780
  * }
1863
1781
  * ```
1864
1782
  *
1865
- * @param returnValues - Use 'ALL_OLD' to return previous values, or 'NONE' (default)
1783
+ * @param returnValues - Use 'ALL_OLD' to return previous values if the item was overwritten, or 'NONE' (default).
1866
1784
  * @returns The builder instance for method chaining
1867
1785
  */
1868
- returnValues(returnValues: "ALL_OLD" | "NONE"): PutBuilder<T>;
1786
+ returnValues(returnValues: "ALL_OLD" | "NONE" | "CONSISTENT"): this;
1869
1787
  /**
1870
1788
  * Generate the DynamoDB command parameters
1871
1789
  */
@@ -1903,7 +1821,7 @@ declare class PutBuilder<T extends Record<string, unknown>> {
1903
1821
  * @param transaction - The transaction builder to add this operation to
1904
1822
  * @returns The builder instance for method chaining
1905
1823
  */
1906
- withTransaction(transaction: TransactionBuilder): PutBuilder<T>;
1824
+ withTransaction(transaction: TransactionBuilder): this;
1907
1825
  /**
1908
1826
  * Executes the put operation against DynamoDB.
1909
1827
  *
@@ -1926,15 +1844,10 @@ declare class PutBuilder<T extends Record<string, unknown>> {
1926
1844
  * @returns A promise that resolves to the operation result (type depends on returnValues setting)
1927
1845
  * @throws Will throw an error if the condition check fails or other DynamoDB errors occur
1928
1846
  */
1929
- execute(): Promise<T>;
1847
+ execute(): Promise<T | undefined>;
1930
1848
  /**
1931
1849
  * Gets a human-readable representation of the put command
1932
1850
  * with all expression placeholders replaced by their actual values.
1933
- * Use this method when you need to:
1934
- * - Debug complex dinosaur transfers
1935
- * - Verify habitat assignments
1936
- * - Log security protocols
1937
- * - Troubleshoot breeding program conditions
1938
1851
  *
1939
1852
  * @example
1940
1853
  * ```ts
@@ -2843,11 +2756,136 @@ declare class GetBuilder<T extends Record<string, unknown>> {
2843
2756
  }>;
2844
2757
  }
2845
2758
 
2759
+ /**
2760
+ * Configuration options for DynamoDB scan operations.
2761
+ * Extends the base FilterOptions.
2762
+ */
2763
+ type ScanOptions = FilterOptions;
2764
+ /**
2765
+ * Function type for executing DynamoDB filter operations.
2766
+ * @typeParam T - The type of items being filtered
2767
+ */
2768
+ type ScanExecutor<T extends Record<string, unknown>> = (options: ScanOptions) => Promise<{
2769
+ items: T[];
2770
+ lastEvaluatedKey?: Record<string, unknown>;
2771
+ }>;
2772
+ /**
2773
+ * Builder for creating DynamoDB scan operations.
2774
+ * Use this builder when you need to:
2775
+ * - Scan all items in a table
2776
+ * - Filter results based on non-key attributes
2777
+ * - Scan items on a Secondary Index (GSI)
2778
+ * - Implement pagination
2779
+ * - Project specific attributes
2780
+ *
2781
+ * The builder supports:
2782
+ * - Type-safe GSI selection
2783
+ * - Complex filter conditions
2784
+ * - Automatic pagination handling
2785
+ * - Consistent reads
2786
+ * - Attribute projection
2787
+ *
2788
+ * @example
2789
+ * ```typescript
2790
+ * // Simple scan with filtering
2791
+ * const result = await new ScanBuilder(executor)
2792
+ * .filter(op => op.eq('status', 'ACTIVE'))
2793
+ * .execute();
2794
+ *
2795
+ * // Scan with GSI and filtering
2796
+ * const result = await new ScanBuilder(executor)
2797
+ * .useIndex('status-index')
2798
+ * .filter(op => op.gt('securityLevel', 8))
2799
+ * .select(['id', 'capacity', 'currentOccupants'])
2800
+ * .limit(10)
2801
+ * .execute();
2802
+ *
2803
+ * // Scan with pagination
2804
+ * const paginator = new ScanBuilder(executor)
2805
+ * .filter(op => op.eq('type', 'INCIDENT'))
2806
+ * .paginate(25);
2807
+ *
2808
+ * while (paginator.hasNextPage()) {
2809
+ * const page = await paginator.getNextPage();
2810
+ * // Process page.items
2811
+ * }
2812
+ * ```
2813
+ *
2814
+ * @typeParam T - The type of items being scanned
2815
+ * @typeParam TConfig - The table configuration type for type-safe GSI selection
2816
+ */
2817
+ declare class ScanBuilder<T extends Record<string, unknown>, TConfig extends TableConfig = TableConfig> extends FilterBuilder<T, TConfig> implements ScanBuilderInterface<T, TConfig> {
2818
+ protected readonly executor: ScanExecutor<T>;
2819
+ constructor(executor: ScanExecutor<T>);
2820
+ /**
2821
+ * Creates a deep clone of this ScanBuilder instance.
2822
+ * Use this method when you need to:
2823
+ * - Create scan templates
2824
+ * - Run multiple variations of a scan
2825
+ * - Implement pagination (used internally by paginate())
2826
+ *
2827
+ * @returns A new ScanBuilder instance with the same configuration
2828
+ */
2829
+ clone(): ScanBuilder<T, TConfig>;
2830
+ /**
2831
+ * Executes the scan against DynamoDB.
2832
+ * Use this method when you need to:
2833
+ * - Search across the entire table
2834
+ * - Find items matching specific criteria
2835
+ * - Perform full table analysis
2836
+ * - Generate reports across all data
2837
+ *
2838
+ * The method returns both the matched items and, if there are more results,
2839
+ * a lastEvaluatedKey that can be used with startFrom() to continue the scan.
2840
+ *
2841
+ * @example
2842
+ * ```typescript
2843
+ * try {
2844
+ * // Find all dinosaurs with high aggression levels
2845
+ * const result = await new ScanBuilder(executor)
2846
+ * .filter(op =>
2847
+ * op.and([
2848
+ * op.eq('status', 'ACTIVE'),
2849
+ * op.gt('aggressionLevel', 7)
2850
+ * ])
2851
+ * )
2852
+ * .limit(20)
2853
+ * .execute();
2854
+ *
2855
+ * console.log(`Found ${result.items.length} potentially dangerous dinosaurs`);
2856
+ *
2857
+ * if (result.lastEvaluatedKey) {
2858
+ * console.log('More results available');
2859
+ * }
2860
+ * } catch (error) {
2861
+ * console.error('Security scan failed:', error);
2862
+ * }
2863
+ * ```
2864
+ *
2865
+ * @returns A promise that resolves to an object containing:
2866
+ * - items: Array of items matching the scan criteria
2867
+ * - lastEvaluatedKey: Token for continuing the scan, if more items exist
2868
+ */
2869
+ execute(): Promise<{
2870
+ items: T[];
2871
+ lastEvaluatedKey?: Record<string, unknown>;
2872
+ }>;
2873
+ }
2874
+
2846
2875
  declare class Table<TConfig extends TableConfig = TableConfig> {
2847
- private dynamoClient;
2876
+ private readonly dynamoClient;
2848
2877
  readonly tableName: string;
2878
+ /**
2879
+ * The column name of the partitionKey for the Table
2880
+ */
2849
2881
  readonly partitionKey: string;
2882
+ /**
2883
+ * The column name of the sortKey for the Table
2884
+ */
2850
2885
  readonly sortKey?: string;
2886
+ /**
2887
+ * The Global Secondary Indexes that are configured on this table
2888
+ */
2851
2889
  readonly gsis: Record<string, Index>;
2852
2890
  constructor(config: TConfig);
2853
2891
  /**
@@ -2870,6 +2908,16 @@ declare class Table<TConfig extends TableConfig = TableConfig> {
2870
2908
  * If useIndex is called on the returned QueryBuilder, it will use the GSI configuration
2871
2909
  */
2872
2910
  query<T extends Record<string, unknown>>(keyCondition: PrimaryKey): QueryBuilder<T, TConfig>;
2911
+ /**
2912
+ * Creates a scan builder for scanning the entire table
2913
+ * Use this when you need to:
2914
+ * - Process all items in a table
2915
+ * - Apply filters to a large dataset
2916
+ * - Use a GSI for scanning
2917
+ *
2918
+ * @returns A ScanBuilder instance for chaining operations
2919
+ */
2920
+ scan<T extends Record<string, unknown>>(): ScanBuilder<T, TConfig>;
2873
2921
  delete(keyCondition: PrimaryKeyWithoutExpression): DeleteBuilder;
2874
2922
  /**
2875
2923
  * Updates an item in the table