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