dyno-table 1.7.0 → 1.8.0-next.1

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 (46) hide show
  1. package/README.md +1 -1
  2. package/dist/{batch-builder-Dz1yPGrJ.d.ts → batch-builder-BOBwOIUE.d.ts} +1 -1
  3. package/dist/{batch-builder-DNsz6zvh.d.cts → batch-builder-CKYnMRyz.d.cts} +1 -1
  4. package/dist/{builder-types-DlaUSc-b.d.cts → builder-types-BTVhQSHI.d.cts} +55 -5
  5. package/dist/{builder-types-B_tCpn9F.d.ts → builder-types-CzuLR4Th.d.ts} +55 -5
  6. package/dist/builders/condition-check-builder.d.cts +1 -1
  7. package/dist/builders/condition-check-builder.d.ts +1 -1
  8. package/dist/builders/delete-builder.d.cts +2 -2
  9. package/dist/builders/delete-builder.d.ts +2 -2
  10. package/dist/builders/paginator.cjs +21 -3
  11. package/dist/builders/paginator.cjs.map +1 -1
  12. package/dist/builders/paginator.d.cts +3 -3
  13. package/dist/builders/paginator.d.ts +3 -3
  14. package/dist/builders/paginator.js +21 -3
  15. package/dist/builders/paginator.js.map +1 -1
  16. package/dist/builders/put-builder.d.cts +2 -2
  17. package/dist/builders/put-builder.d.ts +2 -2
  18. package/dist/builders/query-builder.cjs +115 -22
  19. package/dist/builders/query-builder.cjs.map +1 -1
  20. package/dist/builders/query-builder.d.cts +2 -2
  21. package/dist/builders/query-builder.d.ts +2 -2
  22. package/dist/builders/query-builder.js +115 -22
  23. package/dist/builders/query-builder.js.map +1 -1
  24. package/dist/builders/transaction-builder.d.cts +1 -1
  25. package/dist/builders/transaction-builder.d.ts +1 -1
  26. package/dist/builders/update-builder.d.cts +1 -1
  27. package/dist/builders/update-builder.d.ts +1 -1
  28. package/dist/entity.d.cts +4 -4
  29. package/dist/entity.d.ts +4 -4
  30. package/dist/index.cjs +131 -36
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +4 -4
  33. package/dist/index.d.ts +4 -4
  34. package/dist/index.js +131 -36
  35. package/dist/index.js.map +1 -1
  36. package/dist/{query-builder-C6XjVEFH.d.ts → query-builder-CaHzZmDf.d.ts} +31 -29
  37. package/dist/{query-builder-BDuHHrb-.d.cts → query-builder-DFkxojBM.d.cts} +31 -29
  38. package/dist/{table-DAKlzQsK.d.cts → table-CHitMHXE.d.cts} +18 -20
  39. package/dist/{table-BWa4tx63.d.ts → table-m7DQk5dK.d.ts} +18 -20
  40. package/dist/table.cjs +131 -36
  41. package/dist/table.cjs.map +1 -1
  42. package/dist/table.d.cts +4 -4
  43. package/dist/table.d.ts +4 -4
  44. package/dist/table.js +131 -36
  45. package/dist/table.js.map +1 -1
  46. package/package.json +1 -1
package/dist/index.d.cts CHANGED
@@ -1,16 +1,16 @@
1
- export { T as Table } from './table-DAKlzQsK.cjs';
1
+ export { T as Table } from './table-CHitMHXE.cjs';
2
2
  export { EntityConfig, EntityRepository, IndexDefinition, QueryEntity, QueryRecord, createIndex, createQueries, defineEntity } from './entity.cjs';
3
3
  export { p as ComparisonOperator, C as Condition, q as ConditionOperator, E as ExpressionParams, K as KeyConditionOperator, L as LogicalOperator, P as PrimaryKey, r as PrimaryKeyWithoutExpression, k as and, h as attributeExists, j as attributeNotExists, d as beginsWith, c as between, f as contains, e as eq, g as gt, b as gte, i as inArray, l as lt, a as lte, n as ne, m as not, o as or } from './conditions-3ae5znV_.cjs';
4
- export { Q as QueryBuilder, a as QueryOptions } from './query-builder-BDuHHrb-.cjs';
4
+ export { Q as QueryBuilder, a as QueryOptions } from './query-builder-DFkxojBM.cjs';
5
5
  export { PutBuilder, PutOptions } from './builders/put-builder.cjs';
6
6
  export { UpdateBuilder, UpdateOptions } from './builders/update-builder.cjs';
7
7
  export { DeleteBuilder, DeleteOptions } from './builders/delete-builder.cjs';
8
8
  export { TransactionBuilder, TransactionOptions } from './builders/transaction-builder.cjs';
9
- export { B as BatchBuilder, a as BatchError, b as BatchResult } from './batch-builder-DNsz6zvh.cjs';
9
+ export { B as BatchBuilder, a as BatchError, b as BatchResult } from './batch-builder-CKYnMRyz.cjs';
10
10
  export { partitionKey, sortKey } from './utils.cjs';
11
11
  import './types.cjs';
12
12
  import '@aws-sdk/lib-dynamodb';
13
13
  import './builders/condition-check-builder.cjs';
14
- import './builder-types-DlaUSc-b.cjs';
14
+ import './builder-types-BTVhQSHI.cjs';
15
15
  import './standard-schema.cjs';
16
16
  import './builders/paginator.cjs';
package/dist/index.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- export { T as Table } from './table-BWa4tx63.js';
1
+ export { T as Table } from './table-m7DQk5dK.js';
2
2
  export { EntityConfig, EntityRepository, IndexDefinition, QueryEntity, QueryRecord, createIndex, createQueries, defineEntity } from './entity.js';
3
3
  export { p as ComparisonOperator, C as Condition, q as ConditionOperator, E as ExpressionParams, K as KeyConditionOperator, L as LogicalOperator, P as PrimaryKey, r as PrimaryKeyWithoutExpression, k as and, h as attributeExists, j as attributeNotExists, d as beginsWith, c as between, f as contains, e as eq, g as gt, b as gte, i as inArray, l as lt, a as lte, n as ne, m as not, o as or } from './conditions-BtynAviC.js';
4
- export { Q as QueryBuilder, a as QueryOptions } from './query-builder-C6XjVEFH.js';
4
+ export { Q as QueryBuilder, a as QueryOptions } from './query-builder-CaHzZmDf.js';
5
5
  export { PutBuilder, PutOptions } from './builders/put-builder.js';
6
6
  export { UpdateBuilder, UpdateOptions } from './builders/update-builder.js';
7
7
  export { DeleteBuilder, DeleteOptions } from './builders/delete-builder.js';
8
8
  export { TransactionBuilder, TransactionOptions } from './builders/transaction-builder.js';
9
- export { B as BatchBuilder, a as BatchError, b as BatchResult } from './batch-builder-Dz1yPGrJ.js';
9
+ export { B as BatchBuilder, a as BatchError, b as BatchResult } from './batch-builder-BOBwOIUE.js';
10
10
  export { partitionKey, sortKey } from './utils.js';
11
11
  import './types.js';
12
12
  import '@aws-sdk/lib-dynamodb';
13
13
  import './builders/condition-check-builder.js';
14
- import './builder-types-B_tCpn9F.js';
14
+ import './builder-types-CzuLR4Th.js';
15
15
  import './standard-schema.js';
16
16
  import './builders/paginator.js';
package/dist/index.js CHANGED
@@ -307,13 +307,31 @@ var Paginator = class {
307
307
  page: this.currentPage
308
308
  };
309
309
  }
310
- effectivePageSize = Math.min(effectivePageSize, remainingItems);
310
+ if (effectivePageSize !== void 0) {
311
+ effectivePageSize = Math.min(effectivePageSize, remainingItems);
312
+ } else {
313
+ effectivePageSize = remainingItems;
314
+ }
315
+ }
316
+ const query = this.queryBuilder.clone();
317
+ if (effectivePageSize !== void 0) {
318
+ query.limit(effectivePageSize);
311
319
  }
312
- const query = this.queryBuilder.clone().limit(effectivePageSize);
313
320
  if (this.lastEvaluatedKey) {
314
321
  query.startFrom(this.lastEvaluatedKey);
315
322
  }
316
- const result = await query.execute();
323
+ const generator = await query.execute();
324
+ const items = [];
325
+ let itemCount = 0;
326
+ for await (const item of generator) {
327
+ if (effectivePageSize !== void 0 && itemCount >= effectivePageSize) {
328
+ break;
329
+ }
330
+ items.push(item);
331
+ itemCount++;
332
+ }
333
+ const lastEvaluatedKey = generator.getLastEvaluatedKey();
334
+ const result = { items, lastEvaluatedKey };
317
335
  this.currentPage += 1;
318
336
  this.lastEvaluatedKey = result.lastEvaluatedKey;
319
337
  this.totalItemsRetrieved += result.items.length;
@@ -552,11 +570,16 @@ var FilterBuilder = class {
552
570
  *
553
571
  * @example
554
572
  * ```typescript
555
- * // Create a paginator for dinosaur records
573
+ * // Create a paginator for dinosaur records with specific page size
556
574
  * const paginator = builder
557
575
  * .filter(op => op.eq('status', 'ACTIVE'))
558
576
  * .paginate(10);
559
577
  *
578
+ * // Create a paginator with automatic DynamoDB paging (no page size limit)
579
+ * const autoPaginator = builder
580
+ * .filter(op => op.eq('status', 'ACTIVE'))
581
+ * .paginate();
582
+ *
560
583
  * // Process pages of dinosaur results
561
584
  * while (paginator.hasNextPage()) {
562
585
  * const page = await paginator.getNextPage();
@@ -565,7 +588,7 @@ var FilterBuilder = class {
565
588
  * }
566
589
  * ```
567
590
  *
568
- * @param pageSize - The number of items to return per page
591
+ * @param pageSize - The number of items to return per page. If not provided, DynamoDB will automatically determine page sizes.
569
592
  * @returns A Paginator instance that manages the pagination state
570
593
  * @see Paginator for more pagination control options
571
594
  */
@@ -586,15 +609,17 @@ var FilterBuilder = class {
586
609
  * .limit(5)
587
610
  * .execute();
588
611
  *
589
- * if (result1.lastEvaluatedKey) {
612
+ * const lastKey = result1.getLastEvaluatedKey();
613
+ * if (lastKey) {
590
614
  * // Continue listing dinosaurs
591
615
  * const result2 = await builder
592
616
  * .filter(op => op.eq('status', 'ACTIVE'))
593
- * .startFrom(result1.lastEvaluatedKey)
617
+ * .startFrom(lastKey)
594
618
  * .limit(5)
595
619
  * .execute();
596
620
  *
597
- * console.log('Additional dinosaurs:', result2.items);
621
+ * const items = await result2.toArray();
622
+ * console.log('Additional dinosaurs:', items);
598
623
  * }
599
624
  * ```
600
625
  *
@@ -607,6 +632,72 @@ var FilterBuilder = class {
607
632
  }
608
633
  };
609
634
 
635
+ // src/builders/result-iterator.ts
636
+ var ResultIterator = class {
637
+ constructor(queryBuilder, directExecutor) {
638
+ this.queryBuilder = queryBuilder;
639
+ this.directExecutor = directExecutor;
640
+ this.overallLimit = queryBuilder.getLimit();
641
+ }
642
+ lastEvaluatedKey;
643
+ itemsYielded = 0;
644
+ overallLimit;
645
+ /**
646
+ * Async iterator with automatic pagination
647
+ */
648
+ async *[Symbol.asyncIterator]() {
649
+ let hasMorePages = true;
650
+ while (hasMorePages) {
651
+ const result = await this.directExecutor();
652
+ for (const item of result.items) {
653
+ if (this.overallLimit !== void 0 && this.itemsYielded >= this.overallLimit) {
654
+ return;
655
+ }
656
+ yield item;
657
+ this.itemsYielded++;
658
+ }
659
+ if (result.lastEvaluatedKey !== null && result.lastEvaluatedKey !== void 0) {
660
+ this.lastEvaluatedKey = result.lastEvaluatedKey;
661
+ this.queryBuilder.startFrom(result.lastEvaluatedKey);
662
+ } else if (result.lastEvaluatedKey === null) {
663
+ if (this.lastEvaluatedKey === void 0) {
664
+ this.lastEvaluatedKey = null;
665
+ }
666
+ }
667
+ hasMorePages = !!result.lastEvaluatedKey && (this.overallLimit === void 0 || this.itemsYielded < this.overallLimit);
668
+ }
669
+ }
670
+ /**
671
+ * Convert to array (loads all pages).
672
+ *
673
+ * ```ts
674
+ * const result = await table.query({ pk: "foo" }).execute();
675
+ * const allItemsFromDynamo = await result.toArray();
676
+ * ```
677
+ *
678
+ * Note: This will load all pages into memory. For large datasets, consider using async iteration instead.
679
+ *```ts
680
+ * const result = await table.query({ pk: "foo" }).execute();
681
+ * for await (const item of result) {
682
+ * // Process each item
683
+ * }
684
+ * ```
685
+ */
686
+ async toArray() {
687
+ const items = [];
688
+ for await (const item of this) {
689
+ items.push(item);
690
+ }
691
+ return items;
692
+ }
693
+ /**
694
+ * Get the last evaluated key
695
+ */
696
+ getLastEvaluatedKey() {
697
+ return this.lastEvaluatedKey === null ? void 0 : this.lastEvaluatedKey;
698
+ }
699
+ };
700
+
610
701
  // src/builders/query-builder.ts
611
702
  var QueryBuilder = class _QueryBuilder extends FilterBuilder {
612
703
  keyCondition;
@@ -728,16 +819,16 @@ var QueryBuilder = class _QueryBuilder extends FilterBuilder {
728
819
  return clone;
729
820
  }
730
821
  /**
731
- * Executes the query against DynamoDB.
822
+ * Executes the query against DynamoDB and returns a generator that behaves like an array.
732
823
  *
733
- * The method returns both the matched items and, if there are more results,
734
- * a lastEvaluatedKey that can be used with startFrom() to continue the query.
824
+ * The generator automatically handles pagination and provides array-like methods
825
+ * for processing results efficiently without loading everything into memory at once.
735
826
  *
736
827
  * @example
737
828
  * ```typescript
738
829
  * try {
739
- * // Find active carnivores in specific habitat
740
- * const result = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
830
+ * // Find active carnivores with automatic pagination
831
+ * const results = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
741
832
  * .useIndex('species-status-index')
742
833
  * .filter(op =>
743
834
  * op.and([
@@ -747,25 +838,27 @@ var QueryBuilder = class _QueryBuilder extends FilterBuilder {
747
838
  * ])
748
839
  * )
749
840
  * .sortDescending()
750
- * .limit(5)
751
841
  * .execute();
752
842
  *
753
- * console.log(`Found ${result.items.length} dangerous dinosaurs`);
754
- *
755
- * if (result.lastEvaluatedKey) {
756
- * console.log('Additional threats detected');
843
+ * // Use like an array with automatic pagination
844
+ * for await (const dinosaur of results) {
845
+ * console.log(`Processing ${dinosaur.name}`);
757
846
  * }
847
+ *
848
+ * // Or convert to array and use array methods
849
+ * const allItems = await results.toArray();
850
+ * const dangerousOnes = allItems.filter(dino => dino.aggressionLevel > 9);
851
+ * const totalCount = allItems.length;
758
852
  * } catch (error) {
759
853
  * console.error('Security scan failed:', error);
760
854
  * }
761
855
  * ```
762
856
  *
763
- * @returns A promise that resolves to an object containing:
764
- * - items: Array of items matching the query
765
- * - lastEvaluatedKey: Token for continuing the query, if more items exist
857
+ * @returns A promise that resolves to a ResultGenerator that behaves like an array
766
858
  */
767
859
  async execute() {
768
- return this.executor(this.keyCondition, this.options);
860
+ const directExecutor = () => this.executor(this.keyCondition, this.options);
861
+ return new ResultIterator(this, directExecutor);
769
862
  }
770
863
  };
771
864
 
@@ -3048,41 +3141,43 @@ var ScanBuilder = class _ScanBuilder extends FilterBuilder {
3048
3141
  return clone;
3049
3142
  }
3050
3143
  /**
3051
- * Executes the scan against DynamoDB.
3144
+ * Executes the scan against DynamoDB and returns a generator that behaves like an array.
3052
3145
  *
3053
- * The method returns both the matched items and, if there are more results,
3054
- * a lastEvaluatedKey that can be used with startFrom() to continue the scan.
3146
+ * The generator automatically handles pagination and provides array-like methods
3147
+ * for processing results efficiently without loading everything into memory at once.
3055
3148
  *
3056
3149
  * @example
3057
3150
  * ```typescript
3058
3151
  * try {
3059
- * // Find all dinosaurs with high aggression levels
3060
- * const result = await new ScanBuilder(executor)
3152
+ * // Find all dinosaurs with high aggression levels with automatic pagination
3153
+ * const results = await new ScanBuilder(executor)
3061
3154
  * .filter(op =>
3062
3155
  * op.and([
3063
3156
  * op.eq('status', 'ACTIVE'),
3064
3157
  * op.gt('aggressionLevel', 7)
3065
3158
  * ])
3066
3159
  * )
3067
- * .limit(20)
3068
3160
  * .execute();
3069
3161
  *
3070
- * console.log(`Found ${result.items.length} potentially dangerous dinosaurs`);
3071
- *
3072
- * if (result.lastEvaluatedKey) {
3073
- * console.log('More results available');
3162
+ * // Use like an array with automatic pagination
3163
+ * for await (const dinosaur of results) {
3164
+ * console.log(`Processing dangerous dinosaur: ${dinosaur.name}`);
3074
3165
  * }
3166
+ *
3167
+ * // Or convert to array and use array methods
3168
+ * const allItems = await results.toArray();
3169
+ * const criticalThreats = allItems.filter(dino => dino.aggressionLevel > 9);
3170
+ * const totalCount = allItems.length;
3075
3171
  * } catch (error) {
3076
3172
  * console.error('Security scan failed:', error);
3077
3173
  * }
3078
3174
  * ```
3079
3175
  *
3080
- * @returns A promise that resolves to an object containing:
3081
- * - items: Array of items matching the scan criteria
3082
- * - lastEvaluatedKey: Token for continuing the scan, if more items exist
3176
+ * @returns A promise that resolves to a ResultGenerator that behaves like an array
3083
3177
  */
3084
3178
  async execute() {
3085
- return this.executor(this.options);
3179
+ const directExecutor = () => this.executor(this.options);
3180
+ return new ResultIterator(this, directExecutor);
3086
3181
  }
3087
3182
  };
3088
3183