dyno-table 1.6.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.
- package/README.md +53 -140
- package/dist/batch-builder-BOBwOIUE.d.ts +398 -0
- package/dist/batch-builder-CKYnMRyz.d.cts +398 -0
- 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.cjs +0 -13
- package/dist/builders/condition-check-builder.cjs.map +1 -1
- package/dist/builders/condition-check-builder.d.cts +1 -14
- package/dist/builders/condition-check-builder.d.ts +1 -14
- package/dist/builders/condition-check-builder.js +0 -13
- package/dist/builders/condition-check-builder.js.map +1 -1
- package/dist/builders/delete-builder.cjs +38 -0
- package/dist/builders/delete-builder.cjs.map +1 -1
- package/dist/builders/delete-builder.d.cts +37 -1
- package/dist/builders/delete-builder.d.ts +37 -1
- package/dist/builders/delete-builder.js +38 -0
- package/dist/builders/delete-builder.js.map +1 -1
- package/dist/builders/paginator.cjs +21 -27
- package/dist/builders/paginator.cjs.map +1 -1
- package/dist/builders/paginator.d.cts +3 -27
- package/dist/builders/paginator.d.ts +3 -27
- package/dist/builders/paginator.js +21 -27
- package/dist/builders/paginator.js.map +1 -1
- package/dist/builders/put-builder.cjs +39 -8
- package/dist/builders/put-builder.cjs.map +1 -1
- package/dist/builders/put-builder.d.cts +38 -9
- package/dist/builders/put-builder.d.ts +38 -9
- package/dist/builders/put-builder.js +39 -8
- package/dist/builders/put-builder.js.map +1 -1
- package/dist/builders/query-builder.cjs +115 -75
- 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 -75
- package/dist/builders/query-builder.js.map +1 -1
- package/dist/builders/transaction-builder.cjs +0 -47
- package/dist/builders/transaction-builder.cjs.map +1 -1
- package/dist/builders/transaction-builder.d.cts +1 -48
- package/dist/builders/transaction-builder.d.ts +1 -48
- package/dist/builders/transaction-builder.js +0 -47
- package/dist/builders/transaction-builder.js.map +1 -1
- package/dist/builders/update-builder.cjs +2 -2
- package/dist/builders/update-builder.cjs.map +1 -1
- package/dist/builders/update-builder.d.cts +3 -3
- package/dist/builders/update-builder.d.ts +3 -3
- package/dist/builders/update-builder.js +2 -2
- package/dist/builders/update-builder.js.map +1 -1
- package/dist/conditions.cjs.map +1 -1
- package/dist/conditions.js.map +1 -1
- package/dist/entity.cjs +69 -37
- package/dist/entity.cjs.map +1 -1
- package/dist/entity.d.cts +30 -10
- package/dist/entity.d.ts +30 -10
- package/dist/entity.js +69 -37
- package/dist/entity.js.map +1 -1
- package/dist/index.cjs +661 -218
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +660 -219
- package/dist/index.js.map +1 -1
- package/dist/{query-builder-BhrR31oO.d.ts → query-builder-CaHzZmDf.d.ts} +31 -63
- package/dist/{query-builder-CbHvimBk.d.cts → query-builder-DFkxojBM.d.cts} +31 -63
- package/dist/{table-CY9byPEg.d.cts → table-CHitMHXE.d.cts} +55 -169
- package/dist/{table-Des8C2od.d.ts → table-m7DQk5dK.d.ts} +55 -169
- package/dist/table.cjs +590 -181
- package/dist/table.cjs.map +1 -1
- package/dist/table.d.cts +4 -3
- package/dist/table.d.ts +4 -3
- package/dist/table.js +590 -181
- package/dist/table.js.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
|
@@ -61,10 +61,6 @@ var Paginator = class {
|
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* Gets the current page number (1-indexed).
|
|
64
|
-
* Use this method when you need to:
|
|
65
|
-
* - Track progress through dinosaur lists
|
|
66
|
-
* - Display habitat inspection status
|
|
67
|
-
* - Monitor security sweep progress
|
|
68
64
|
*
|
|
69
65
|
* @example
|
|
70
66
|
* ```ts
|
|
@@ -82,11 +78,6 @@ var Paginator = class {
|
|
|
82
78
|
}
|
|
83
79
|
/**
|
|
84
80
|
* Checks if there are more pages of dinosaurs or habitats to process.
|
|
85
|
-
* Use this method when you need to:
|
|
86
|
-
* - Check for more dinosaurs to review
|
|
87
|
-
* - Continue habitat inspections
|
|
88
|
-
* - Process security incidents
|
|
89
|
-
* - Complete feeding schedules
|
|
90
81
|
*
|
|
91
82
|
* This method takes into account both:
|
|
92
83
|
* - DynamoDB's lastEvaluatedKey mechanism
|
|
@@ -118,11 +109,6 @@ var Paginator = class {
|
|
|
118
109
|
}
|
|
119
110
|
/**
|
|
120
111
|
* Retrieves the next page of dinosaurs or habitats from DynamoDB.
|
|
121
|
-
* Use this method when you need to:
|
|
122
|
-
* - Process dinosaur groups systematically
|
|
123
|
-
* - Review habitat inspections in batches
|
|
124
|
-
* - Monitor security incidents in sequence
|
|
125
|
-
* - Schedule feeding rotations
|
|
126
112
|
*
|
|
127
113
|
* This method handles:
|
|
128
114
|
* - Automatic continuation between groups
|
|
@@ -174,13 +160,31 @@ var Paginator = class {
|
|
|
174
160
|
page: this.currentPage
|
|
175
161
|
};
|
|
176
162
|
}
|
|
177
|
-
|
|
163
|
+
if (effectivePageSize !== void 0) {
|
|
164
|
+
effectivePageSize = Math.min(effectivePageSize, remainingItems);
|
|
165
|
+
} else {
|
|
166
|
+
effectivePageSize = remainingItems;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const query = this.queryBuilder.clone();
|
|
170
|
+
if (effectivePageSize !== void 0) {
|
|
171
|
+
query.limit(effectivePageSize);
|
|
178
172
|
}
|
|
179
|
-
const query = this.queryBuilder.clone().limit(effectivePageSize);
|
|
180
173
|
if (this.lastEvaluatedKey) {
|
|
181
174
|
query.startFrom(this.lastEvaluatedKey);
|
|
182
175
|
}
|
|
183
|
-
const
|
|
176
|
+
const generator = await query.execute();
|
|
177
|
+
const items = [];
|
|
178
|
+
let itemCount = 0;
|
|
179
|
+
for await (const item of generator) {
|
|
180
|
+
if (effectivePageSize !== void 0 && itemCount >= effectivePageSize) {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
items.push(item);
|
|
184
|
+
itemCount++;
|
|
185
|
+
}
|
|
186
|
+
const lastEvaluatedKey = generator.getLastEvaluatedKey();
|
|
187
|
+
const result = { items, lastEvaluatedKey };
|
|
184
188
|
this.currentPage += 1;
|
|
185
189
|
this.lastEvaluatedKey = result.lastEvaluatedKey;
|
|
186
190
|
this.totalItemsRetrieved += result.items.length;
|
|
@@ -194,16 +198,6 @@ var Paginator = class {
|
|
|
194
198
|
}
|
|
195
199
|
/**
|
|
196
200
|
* Gets all remaining dinosaurs or habitats and combines them into a single array.
|
|
197
|
-
* Use this method when you need to:
|
|
198
|
-
* - Generate complete park inventory
|
|
199
|
-
* - Perform full security audit
|
|
200
|
-
* - Create comprehensive feeding schedule
|
|
201
|
-
* - Run park-wide health checks
|
|
202
|
-
*
|
|
203
|
-
* Note: Use with caution! This method:
|
|
204
|
-
* - Could overwhelm systems with large dinosaur populations
|
|
205
|
-
* - Makes multiple database requests
|
|
206
|
-
* - May cause system strain during peak hours
|
|
207
201
|
*
|
|
208
202
|
* @example
|
|
209
203
|
* ```ts
|
|
@@ -245,10 +239,6 @@ var FilterBuilder = class {
|
|
|
245
239
|
selectedFields = /* @__PURE__ */ new Set();
|
|
246
240
|
/**
|
|
247
241
|
* Sets the maximum number of items to return.
|
|
248
|
-
* Use this method when you need to:
|
|
249
|
-
* - Limit the number of dinosaurs returned
|
|
250
|
-
* - Control the size of habitat reports
|
|
251
|
-
* - Implement manual pagination of security logs
|
|
252
242
|
*
|
|
253
243
|
* Note: This limit applies to the items that match the key condition
|
|
254
244
|
* before any filter expressions are applied.
|
|
@@ -279,11 +269,6 @@ var FilterBuilder = class {
|
|
|
279
269
|
}
|
|
280
270
|
/**
|
|
281
271
|
* Specifies a Global Secondary Index (GSI) to use for the operation.
|
|
282
|
-
* Use this method when you need to:
|
|
283
|
-
* - Find dinosaurs by species or status
|
|
284
|
-
* - Search habitats by security level
|
|
285
|
-
* - Find incidents by date
|
|
286
|
-
* - List feeding schedules by time
|
|
287
272
|
*
|
|
288
273
|
* @example
|
|
289
274
|
* ```typescript
|
|
@@ -312,11 +297,6 @@ var FilterBuilder = class {
|
|
|
312
297
|
}
|
|
313
298
|
/**
|
|
314
299
|
* Sets whether to use strongly consistent reads for the operation.
|
|
315
|
-
* Use this method when you need to:
|
|
316
|
-
* - Get real-time dinosaur status updates
|
|
317
|
-
* - Monitor critical security systems
|
|
318
|
-
* - Track immediate habitat changes
|
|
319
|
-
* - Verify containment protocols
|
|
320
300
|
*
|
|
321
301
|
* Note:
|
|
322
302
|
* - Consistent reads are not available on GSIs
|
|
@@ -347,11 +327,6 @@ var FilterBuilder = class {
|
|
|
347
327
|
}
|
|
348
328
|
/**
|
|
349
329
|
* Adds a filter expression to refine the operation results.
|
|
350
|
-
* Use this method when you need to:
|
|
351
|
-
* - Filter dinosaurs by behavior patterns
|
|
352
|
-
* - Find habitats with specific conditions
|
|
353
|
-
* - Search for security incidents
|
|
354
|
-
* - Monitor feeding patterns
|
|
355
330
|
*
|
|
356
331
|
* @example
|
|
357
332
|
* ```typescript
|
|
@@ -404,11 +379,6 @@ var FilterBuilder = class {
|
|
|
404
379
|
}
|
|
405
380
|
/**
|
|
406
381
|
* Specifies which attributes to return in the results.
|
|
407
|
-
* Use this method when you need to:
|
|
408
|
-
* - Get specific dinosaur attributes
|
|
409
|
-
* - Retrieve habitat statistics
|
|
410
|
-
* - Monitor security metrics
|
|
411
|
-
* - Optimize response size
|
|
412
382
|
*
|
|
413
383
|
* @example
|
|
414
384
|
* ```typescript
|
|
@@ -453,11 +423,16 @@ var FilterBuilder = class {
|
|
|
453
423
|
*
|
|
454
424
|
* @example
|
|
455
425
|
* ```typescript
|
|
456
|
-
* // Create a paginator for dinosaur records
|
|
426
|
+
* // Create a paginator for dinosaur records with specific page size
|
|
457
427
|
* const paginator = builder
|
|
458
428
|
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
459
429
|
* .paginate(10);
|
|
460
430
|
*
|
|
431
|
+
* // Create a paginator with automatic DynamoDB paging (no page size limit)
|
|
432
|
+
* const autoPaginator = builder
|
|
433
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
434
|
+
* .paginate();
|
|
435
|
+
*
|
|
461
436
|
* // Process pages of dinosaur results
|
|
462
437
|
* while (paginator.hasNextPage()) {
|
|
463
438
|
* const page = await paginator.getNextPage();
|
|
@@ -466,7 +441,7 @@ var FilterBuilder = class {
|
|
|
466
441
|
* }
|
|
467
442
|
* ```
|
|
468
443
|
*
|
|
469
|
-
* @param pageSize - The number of items to return per page
|
|
444
|
+
* @param pageSize - The number of items to return per page. If not provided, DynamoDB will automatically determine page sizes.
|
|
470
445
|
* @returns A Paginator instance that manages the pagination state
|
|
471
446
|
* @see Paginator for more pagination control options
|
|
472
447
|
*/
|
|
@@ -475,11 +450,6 @@ var FilterBuilder = class {
|
|
|
475
450
|
}
|
|
476
451
|
/**
|
|
477
452
|
* Sets the starting point using a previous lastEvaluatedKey.
|
|
478
|
-
* Use this method when you need to:
|
|
479
|
-
* - Implement manual dinosaur list pagination
|
|
480
|
-
* - Resume habitat inspection reviews
|
|
481
|
-
* - Continue security incident analysis
|
|
482
|
-
* - Store operation position between sessions
|
|
483
453
|
*
|
|
484
454
|
* Note: This method is typically used for manual pagination.
|
|
485
455
|
* For automatic pagination, use the paginate() method instead.
|
|
@@ -492,15 +462,17 @@ var FilterBuilder = class {
|
|
|
492
462
|
* .limit(5)
|
|
493
463
|
* .execute();
|
|
494
464
|
*
|
|
495
|
-
*
|
|
465
|
+
* const lastKey = result1.getLastEvaluatedKey();
|
|
466
|
+
* if (lastKey) {
|
|
496
467
|
* // Continue listing dinosaurs
|
|
497
468
|
* const result2 = await builder
|
|
498
469
|
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
499
|
-
* .startFrom(
|
|
470
|
+
* .startFrom(lastKey)
|
|
500
471
|
* .limit(5)
|
|
501
472
|
* .execute();
|
|
502
473
|
*
|
|
503
|
-
*
|
|
474
|
+
* const items = await result2.toArray();
|
|
475
|
+
* console.log('Additional dinosaurs:', items);
|
|
504
476
|
* }
|
|
505
477
|
* ```
|
|
506
478
|
*
|
|
@@ -513,6 +485,72 @@ var FilterBuilder = class {
|
|
|
513
485
|
}
|
|
514
486
|
};
|
|
515
487
|
|
|
488
|
+
// src/builders/result-iterator.ts
|
|
489
|
+
var ResultIterator = class {
|
|
490
|
+
constructor(queryBuilder, directExecutor) {
|
|
491
|
+
this.queryBuilder = queryBuilder;
|
|
492
|
+
this.directExecutor = directExecutor;
|
|
493
|
+
this.overallLimit = queryBuilder.getLimit();
|
|
494
|
+
}
|
|
495
|
+
lastEvaluatedKey;
|
|
496
|
+
itemsYielded = 0;
|
|
497
|
+
overallLimit;
|
|
498
|
+
/**
|
|
499
|
+
* Async iterator with automatic pagination
|
|
500
|
+
*/
|
|
501
|
+
async *[Symbol.asyncIterator]() {
|
|
502
|
+
let hasMorePages = true;
|
|
503
|
+
while (hasMorePages) {
|
|
504
|
+
const result = await this.directExecutor();
|
|
505
|
+
for (const item of result.items) {
|
|
506
|
+
if (this.overallLimit !== void 0 && this.itemsYielded >= this.overallLimit) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
yield item;
|
|
510
|
+
this.itemsYielded++;
|
|
511
|
+
}
|
|
512
|
+
if (result.lastEvaluatedKey !== null && result.lastEvaluatedKey !== void 0) {
|
|
513
|
+
this.lastEvaluatedKey = result.lastEvaluatedKey;
|
|
514
|
+
this.queryBuilder.startFrom(result.lastEvaluatedKey);
|
|
515
|
+
} else if (result.lastEvaluatedKey === null) {
|
|
516
|
+
if (this.lastEvaluatedKey === void 0) {
|
|
517
|
+
this.lastEvaluatedKey = null;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
hasMorePages = !!result.lastEvaluatedKey && (this.overallLimit === void 0 || this.itemsYielded < this.overallLimit);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Convert to array (loads all pages).
|
|
525
|
+
*
|
|
526
|
+
* ```ts
|
|
527
|
+
* const result = await table.query({ pk: "foo" }).execute();
|
|
528
|
+
* const allItemsFromDynamo = await result.toArray();
|
|
529
|
+
* ```
|
|
530
|
+
*
|
|
531
|
+
* Note: This will load all pages into memory. For large datasets, consider using async iteration instead.
|
|
532
|
+
*```ts
|
|
533
|
+
* const result = await table.query({ pk: "foo" }).execute();
|
|
534
|
+
* for await (const item of result) {
|
|
535
|
+
* // Process each item
|
|
536
|
+
* }
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
async toArray() {
|
|
540
|
+
const items = [];
|
|
541
|
+
for await (const item of this) {
|
|
542
|
+
items.push(item);
|
|
543
|
+
}
|
|
544
|
+
return items;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Get the last evaluated key
|
|
548
|
+
*/
|
|
549
|
+
getLastEvaluatedKey() {
|
|
550
|
+
return this.lastEvaluatedKey === null ? void 0 : this.lastEvaluatedKey;
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
|
|
516
554
|
// src/builders/query-builder.ts
|
|
517
555
|
var QueryBuilder = class _QueryBuilder extends FilterBuilder {
|
|
518
556
|
keyCondition;
|
|
@@ -634,16 +672,16 @@ var QueryBuilder = class _QueryBuilder extends FilterBuilder {
|
|
|
634
672
|
return clone;
|
|
635
673
|
}
|
|
636
674
|
/**
|
|
637
|
-
* Executes the query against DynamoDB.
|
|
675
|
+
* Executes the query against DynamoDB and returns a generator that behaves like an array.
|
|
638
676
|
*
|
|
639
|
-
* The
|
|
640
|
-
*
|
|
677
|
+
* The generator automatically handles pagination and provides array-like methods
|
|
678
|
+
* for processing results efficiently without loading everything into memory at once.
|
|
641
679
|
*
|
|
642
680
|
* @example
|
|
643
681
|
* ```typescript
|
|
644
682
|
* try {
|
|
645
|
-
* // Find active carnivores
|
|
646
|
-
* const
|
|
683
|
+
* // Find active carnivores with automatic pagination
|
|
684
|
+
* const results = await new QueryBuilder(executor, eq('habitatId', 'PADDOCK-A'))
|
|
647
685
|
* .useIndex('species-status-index')
|
|
648
686
|
* .filter(op =>
|
|
649
687
|
* op.and([
|
|
@@ -653,25 +691,27 @@ var QueryBuilder = class _QueryBuilder extends FilterBuilder {
|
|
|
653
691
|
* ])
|
|
654
692
|
* )
|
|
655
693
|
* .sortDescending()
|
|
656
|
-
* .limit(5)
|
|
657
694
|
* .execute();
|
|
658
695
|
*
|
|
659
|
-
*
|
|
660
|
-
*
|
|
661
|
-
*
|
|
662
|
-
* console.log('Additional threats detected');
|
|
696
|
+
* // Use like an array with automatic pagination
|
|
697
|
+
* for await (const dinosaur of results) {
|
|
698
|
+
* console.log(`Processing ${dinosaur.name}`);
|
|
663
699
|
* }
|
|
700
|
+
*
|
|
701
|
+
* // Or convert to array and use array methods
|
|
702
|
+
* const allItems = await results.toArray();
|
|
703
|
+
* const dangerousOnes = allItems.filter(dino => dino.aggressionLevel > 9);
|
|
704
|
+
* const totalCount = allItems.length;
|
|
664
705
|
* } catch (error) {
|
|
665
706
|
* console.error('Security scan failed:', error);
|
|
666
707
|
* }
|
|
667
708
|
* ```
|
|
668
709
|
*
|
|
669
|
-
* @returns A promise that resolves to an
|
|
670
|
-
* - items: Array of items matching the query
|
|
671
|
-
* - lastEvaluatedKey: Token for continuing the query, if more items exist
|
|
710
|
+
* @returns A promise that resolves to a ResultGenerator that behaves like an array
|
|
672
711
|
*/
|
|
673
712
|
async execute() {
|
|
674
|
-
|
|
713
|
+
const directExecutor = () => this.executor(this.keyCondition, this.options);
|
|
714
|
+
return new ResultIterator(this, directExecutor);
|
|
675
715
|
}
|
|
676
716
|
};
|
|
677
717
|
|