dyno-table 1.7.0 → 2.0.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.
- package/dist/{batch-builder-Dz1yPGrJ.d.ts → batch-builder-BOBwOIUE.d.ts} +1 -1
- package/dist/{batch-builder-DNsz6zvh.d.cts → batch-builder-CKYnMRyz.d.cts} +1 -1
- package/dist/{builder-types-DlaUSc-b.d.cts → builder-types-BTVhQSHI.d.cts} +55 -5
- package/dist/{builder-types-B_tCpn9F.d.ts → builder-types-CzuLR4Th.d.ts} +55 -5
- package/dist/builders/condition-check-builder.d.cts +1 -1
- package/dist/builders/condition-check-builder.d.ts +1 -1
- package/dist/builders/delete-builder.d.cts +2 -2
- package/dist/builders/delete-builder.d.ts +2 -2
- package/dist/builders/paginator.cjs +21 -3
- package/dist/builders/paginator.cjs.map +1 -1
- package/dist/builders/paginator.d.cts +3 -3
- package/dist/builders/paginator.d.ts +3 -3
- package/dist/builders/paginator.js +21 -3
- package/dist/builders/paginator.js.map +1 -1
- package/dist/builders/put-builder.d.cts +2 -2
- package/dist/builders/put-builder.d.ts +2 -2
- package/dist/builders/query-builder.cjs +115 -22
- package/dist/builders/query-builder.cjs.map +1 -1
- package/dist/builders/query-builder.d.cts +2 -2
- package/dist/builders/query-builder.d.ts +2 -2
- package/dist/builders/query-builder.js +115 -22
- package/dist/builders/query-builder.js.map +1 -1
- package/dist/builders/transaction-builder.d.cts +1 -1
- package/dist/builders/transaction-builder.d.ts +1 -1
- package/dist/builders/update-builder.d.cts +1 -1
- package/dist/builders/update-builder.d.ts +1 -1
- package/dist/entity.d.cts +4 -4
- package/dist/entity.d.ts +4 -4
- package/dist/index.cjs +131 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +131 -36
- package/dist/index.js.map +1 -1
- package/dist/{query-builder-C6XjVEFH.d.ts → query-builder-CaHzZmDf.d.ts} +31 -29
- package/dist/{query-builder-BDuHHrb-.d.cts → query-builder-DFkxojBM.d.cts} +31 -29
- package/dist/{table-DAKlzQsK.d.cts → table-CHitMHXE.d.cts} +18 -20
- package/dist/{table-BWa4tx63.d.ts → table-m7DQk5dK.d.ts} +18 -20
- package/dist/table.cjs +131 -36
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +4 -4
- package/dist/table.d.ts +4 -4
- package/dist/table.js +131 -36
- package/dist/table.js.map +1 -1
- package/package.json +1 -1
package/dist/table.d.cts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import './types.cjs';
|
|
2
2
|
import './conditions-3ae5znV_.cjs';
|
|
3
|
-
import './query-builder-
|
|
3
|
+
import './query-builder-DFkxojBM.cjs';
|
|
4
4
|
import './builders/put-builder.cjs';
|
|
5
5
|
import './builders/delete-builder.cjs';
|
|
6
6
|
import './builders/update-builder.cjs';
|
|
7
7
|
import './builders/transaction-builder.cjs';
|
|
8
|
-
import './batch-builder-
|
|
8
|
+
import './batch-builder-CKYnMRyz.cjs';
|
|
9
9
|
import './builders/condition-check-builder.cjs';
|
|
10
|
-
export { T as Table } from './table-
|
|
10
|
+
export { T as Table } from './table-CHitMHXE.cjs';
|
|
11
11
|
import '@aws-sdk/lib-dynamodb';
|
|
12
12
|
import './builders/paginator.cjs';
|
|
13
|
-
import './builder-types-
|
|
13
|
+
import './builder-types-BTVhQSHI.cjs';
|
package/dist/table.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import './types.js';
|
|
2
2
|
import './conditions-BtynAviC.js';
|
|
3
|
-
import './query-builder-
|
|
3
|
+
import './query-builder-CaHzZmDf.js';
|
|
4
4
|
import './builders/put-builder.js';
|
|
5
5
|
import './builders/delete-builder.js';
|
|
6
6
|
import './builders/update-builder.js';
|
|
7
7
|
import './builders/transaction-builder.js';
|
|
8
|
-
import './batch-builder-
|
|
8
|
+
import './batch-builder-BOBwOIUE.js';
|
|
9
9
|
import './builders/condition-check-builder.js';
|
|
10
|
-
export { T as Table } from './table-
|
|
10
|
+
export { T as Table } from './table-m7DQk5dK.js';
|
|
11
11
|
import '@aws-sdk/lib-dynamodb';
|
|
12
12
|
import './builders/paginator.js';
|
|
13
|
-
import './builder-types-
|
|
13
|
+
import './builder-types-CzuLR4Th.js';
|
package/dist/table.js
CHANGED
|
@@ -307,13 +307,31 @@ var Paginator = class {
|
|
|
307
307
|
page: this.currentPage
|
|
308
308
|
};
|
|
309
309
|
}
|
|
310
|
-
|
|
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
|
|
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
|
-
*
|
|
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(
|
|
617
|
+
* .startFrom(lastKey)
|
|
594
618
|
* .limit(5)
|
|
595
619
|
* .execute();
|
|
596
620
|
*
|
|
597
|
-
*
|
|
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
|
|
734
|
-
*
|
|
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
|
|
740
|
-
* const
|
|
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
|
-
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
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
|
|
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
|
-
|
|
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
|
|
3054
|
-
*
|
|
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
|
|
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
|
-
*
|
|
3071
|
-
*
|
|
3072
|
-
*
|
|
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
|
|
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
|
-
|
|
3179
|
+
const directExecutor = () => this.executor(this.options);
|
|
3180
|
+
return new ResultIterator(this, directExecutor);
|
|
3086
3181
|
}
|
|
3087
3182
|
};
|
|
3088
3183
|
|