dyno-table 0.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/LICENSE +21 -0
- package/README.md +681 -160
- package/dist/builder-types-C_PDZhnP.d.ts +118 -0
- package/dist/builder-types-DtwbqMeF.d.cts +118 -0
- package/dist/builders/condition-check-builder.cjs +394 -0
- package/dist/builders/condition-check-builder.cjs.map +1 -0
- package/dist/builders/condition-check-builder.d.cts +157 -0
- package/dist/builders/condition-check-builder.d.ts +157 -0
- package/dist/builders/condition-check-builder.js +392 -0
- package/dist/builders/condition-check-builder.js.map +1 -0
- package/dist/builders/delete-builder.cjs +405 -0
- package/dist/builders/delete-builder.cjs.map +1 -0
- package/dist/builders/delete-builder.d.cts +166 -0
- package/dist/builders/delete-builder.d.ts +166 -0
- package/dist/builders/delete-builder.js +403 -0
- package/dist/builders/delete-builder.js.map +1 -0
- package/dist/builders/paginator.cjs +199 -0
- package/dist/builders/paginator.cjs.map +1 -0
- package/dist/builders/paginator.d.cts +179 -0
- package/dist/builders/paginator.d.ts +179 -0
- package/dist/builders/paginator.js +197 -0
- package/dist/builders/paginator.js.map +1 -0
- package/dist/builders/put-builder.cjs +476 -0
- package/dist/builders/put-builder.cjs.map +1 -0
- package/dist/builders/put-builder.d.cts +274 -0
- package/dist/builders/put-builder.d.ts +274 -0
- package/dist/builders/put-builder.js +474 -0
- package/dist/builders/put-builder.js.map +1 -0
- package/dist/builders/query-builder.cjs +674 -0
- package/dist/builders/query-builder.cjs.map +1 -0
- package/dist/builders/query-builder.d.cts +6 -0
- package/dist/builders/query-builder.d.ts +6 -0
- package/dist/builders/query-builder.js +672 -0
- package/dist/builders/query-builder.js.map +1 -0
- package/dist/builders/transaction-builder.cjs +894 -0
- package/dist/builders/transaction-builder.cjs.map +1 -0
- package/dist/builders/transaction-builder.d.cts +511 -0
- package/dist/builders/transaction-builder.d.ts +511 -0
- package/dist/builders/transaction-builder.js +892 -0
- package/dist/builders/transaction-builder.js.map +1 -0
- package/dist/builders/update-builder.cjs +627 -0
- package/dist/builders/update-builder.cjs.map +1 -0
- package/dist/builders/update-builder.d.cts +365 -0
- package/dist/builders/update-builder.d.ts +365 -0
- package/dist/builders/update-builder.js +625 -0
- package/dist/builders/update-builder.js.map +1 -0
- package/dist/conditions--ld9a78i.d.ts +331 -0
- package/dist/conditions-ChhQWd6z.d.cts +331 -0
- package/dist/conditions.cjs +59 -0
- package/dist/conditions.cjs.map +1 -0
- package/dist/conditions.d.cts +3 -0
- package/dist/conditions.d.ts +3 -0
- package/dist/conditions.js +43 -0
- package/dist/conditions.js.map +1 -0
- package/dist/entity.cjs +228 -0
- package/dist/entity.cjs.map +1 -0
- package/dist/entity.d.cts +149 -0
- package/dist/entity.d.ts +149 -0
- package/dist/entity.js +224 -0
- package/dist/entity.js.map +1 -0
- package/dist/query-builder-Csror9Iu.d.ts +507 -0
- package/dist/query-builder-D2FM9rsu.d.cts +507 -0
- package/dist/standard-schema.cjs +4 -0
- package/dist/standard-schema.cjs.map +1 -0
- package/dist/standard-schema.d.cts +57 -0
- package/dist/standard-schema.d.ts +57 -0
- package/dist/standard-schema.js +3 -0
- package/dist/standard-schema.js.map +1 -0
- package/dist/table-BEhBPy2G.d.cts +364 -0
- package/dist/table-BW3cmUqr.d.ts +364 -0
- package/dist/{index.js → table.cjs} +330 -354
- package/dist/table.cjs.map +1 -0
- package/dist/table.d.cts +12 -0
- package/dist/table.d.ts +12 -0
- package/dist/table.js +3243 -0
- package/dist/table.js.map +1 -0
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +22 -0
- package/dist/types.d.ts +22 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/partition-key-template.cjs +19 -0
- package/dist/utils/partition-key-template.cjs.map +1 -0
- package/dist/utils/partition-key-template.d.cts +32 -0
- package/dist/utils/partition-key-template.d.ts +32 -0
- package/dist/utils/partition-key-template.js +17 -0
- package/dist/utils/partition-key-template.js.map +1 -0
- package/dist/utils/sort-key-template.cjs +19 -0
- package/dist/utils/sort-key-template.cjs.map +1 -0
- package/dist/utils/sort-key-template.d.cts +35 -0
- package/dist/utils/sort-key-template.d.ts +35 -0
- package/dist/utils/sort-key-template.js +17 -0
- package/dist/utils/sort-key-template.js.map +1 -0
- package/package.json +97 -22
- package/dist/index.d.ts +0 -2923
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
1
3
|
// src/conditions.ts
|
|
2
4
|
var createComparisonCondition = (type) => (attr, value) => ({
|
|
3
5
|
type,
|
|
@@ -365,30 +367,24 @@ var Paginator = class {
|
|
|
365
367
|
}
|
|
366
368
|
};
|
|
367
369
|
|
|
368
|
-
// src/builders/
|
|
369
|
-
var
|
|
370
|
-
keyCondition;
|
|
370
|
+
// src/builders/filter-builder.ts
|
|
371
|
+
var FilterBuilder = class {
|
|
371
372
|
options = {};
|
|
372
373
|
selectedFields = /* @__PURE__ */ new Set();
|
|
373
|
-
executor;
|
|
374
|
-
constructor(executor, keyCondition) {
|
|
375
|
-
this.executor = executor;
|
|
376
|
-
this.keyCondition = keyCondition;
|
|
377
|
-
}
|
|
378
374
|
/**
|
|
379
|
-
* Sets the maximum number of items to return
|
|
375
|
+
* Sets the maximum number of items to return.
|
|
380
376
|
* Use this method when you need to:
|
|
381
|
-
* - Limit the
|
|
382
|
-
* -
|
|
383
|
-
* -
|
|
377
|
+
* - Limit the number of dinosaurs returned
|
|
378
|
+
* - Control the size of habitat reports
|
|
379
|
+
* - Implement manual pagination of security logs
|
|
384
380
|
*
|
|
385
381
|
* Note: This limit applies to the items that match the key condition
|
|
386
382
|
* before any filter expressions are applied.
|
|
387
383
|
*
|
|
388
384
|
* @example
|
|
389
|
-
* ```
|
|
390
|
-
* // Get first 10
|
|
391
|
-
* const result = await
|
|
385
|
+
* ```typescript
|
|
386
|
+
* // Get first 10 dinosaurs
|
|
387
|
+
* const result = await builder
|
|
392
388
|
* .limit(10)
|
|
393
389
|
* .execute();
|
|
394
390
|
* ```
|
|
@@ -401,7 +397,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
401
397
|
return this;
|
|
402
398
|
}
|
|
403
399
|
/**
|
|
404
|
-
* Gets the current limit set on the
|
|
400
|
+
* Gets the current limit set on the operation.
|
|
405
401
|
* This is used internally by the paginator to manage result sets.
|
|
406
402
|
*
|
|
407
403
|
* @returns The current limit or undefined if no limit is set
|
|
@@ -410,41 +406,9 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
410
406
|
return this.options.limit;
|
|
411
407
|
}
|
|
412
408
|
/**
|
|
413
|
-
* Specifies a Global Secondary Index (GSI) to use for the
|
|
414
|
-
* Use this method when you need to:
|
|
415
|
-
* - Query data using non-primary key attributes
|
|
416
|
-
* - Access data through alternate access patterns
|
|
417
|
-
* - Optimize query performance for specific access patterns
|
|
418
|
-
*
|
|
419
|
-
* This method provides type safety by only allowing valid GSI names
|
|
420
|
-
* defined in your table configuration.
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* ```ts
|
|
424
|
-
* // Query by status using a GSI
|
|
425
|
-
* const result = await new QueryBuilder(executor, eq('status', 'ACTIVE'))
|
|
426
|
-
* .useIndex('status-index')
|
|
427
|
-
* .execute();
|
|
428
|
-
*
|
|
429
|
-
* // Query by category and date range
|
|
430
|
-
* const result = await new QueryBuilder(executor, eq('category', 'books'))
|
|
431
|
-
* .useIndex('category-date-index')
|
|
432
|
-
* .filter(op => op.between('date', startDate, endDate))
|
|
433
|
-
* .execute();
|
|
434
|
-
* ```
|
|
435
|
-
*
|
|
436
|
-
* Note: Be aware that GSIs:
|
|
437
|
-
* - May have different projected attributes
|
|
438
|
-
* - Have eventually consistent reads only
|
|
439
|
-
* - May have different provisioned throughput
|
|
440
|
-
*
|
|
441
|
-
* @param indexName - The name of the GSI to use (type-safe based on table configuration)
|
|
442
|
-
* @returns The builder instance for method chaining
|
|
443
|
-
*/
|
|
444
|
-
/**
|
|
445
|
-
* Specifies a Global Secondary Index (GSI) to use for the query.
|
|
409
|
+
* Specifies a Global Secondary Index (GSI) to use for the operation.
|
|
446
410
|
* Use this method when you need to:
|
|
447
|
-
* -
|
|
411
|
+
* - Find dinosaurs by species or status
|
|
448
412
|
* - Search habitats by security level
|
|
449
413
|
* - Find incidents by date
|
|
450
414
|
* - List feeding schedules by time
|
|
@@ -475,7 +439,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
475
439
|
return this;
|
|
476
440
|
}
|
|
477
441
|
/**
|
|
478
|
-
* Sets whether to use strongly consistent reads for the
|
|
442
|
+
* Sets whether to use strongly consistent reads for the operation.
|
|
479
443
|
* Use this method when you need to:
|
|
480
444
|
* - Get real-time dinosaur status updates
|
|
481
445
|
* - Monitor critical security systems
|
|
@@ -488,15 +452,15 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
488
452
|
* - Default is eventually consistent reads
|
|
489
453
|
*
|
|
490
454
|
* @example
|
|
491
|
-
* ```
|
|
455
|
+
* ```typescript
|
|
492
456
|
* // Check immediate dinosaur status
|
|
493
|
-
* const result = await
|
|
457
|
+
* const result = await builder
|
|
494
458
|
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
495
459
|
* .consistentRead()
|
|
496
460
|
* .execute();
|
|
497
461
|
*
|
|
498
462
|
* // Monitor security breaches
|
|
499
|
-
* const result = await
|
|
463
|
+
* const result = await builder
|
|
500
464
|
* .useIndex('primary-index')
|
|
501
465
|
* .consistentRead(isEmergencyMode)
|
|
502
466
|
* .execute();
|
|
@@ -510,35 +474,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
510
474
|
return this;
|
|
511
475
|
}
|
|
512
476
|
/**
|
|
513
|
-
* Adds a filter expression to the
|
|
514
|
-
* Use this method when you need to:
|
|
515
|
-
* - Filter results based on non-key attributes
|
|
516
|
-
* - Apply complex filtering conditions
|
|
517
|
-
* - Combine multiple filter conditions
|
|
518
|
-
*
|
|
519
|
-
* Note: Filter expressions are applied after the key condition,
|
|
520
|
-
* so they don't reduce the amount of data read from DynamoDB.
|
|
521
|
-
*
|
|
522
|
-
* @example
|
|
523
|
-
* ```ts
|
|
524
|
-
* // Simple filter
|
|
525
|
-
* builder.filter(op => op.eq('status', 'ACTIVE'))
|
|
526
|
-
*
|
|
527
|
-
* // Complex filter with multiple conditions
|
|
528
|
-
* builder.filter(op =>
|
|
529
|
-
* op.and([
|
|
530
|
-
* op.gt('amount', 1000),
|
|
531
|
-
* op.beginsWith('category', 'ELECTRONICS'),
|
|
532
|
-
* op.attributeExists('reviewDate')
|
|
533
|
-
* ])
|
|
534
|
-
* )
|
|
535
|
-
* ```
|
|
536
|
-
*
|
|
537
|
-
* @param condition - Either a Condition object or a callback function that builds the condition
|
|
538
|
-
* @returns The builder instance for method chaining
|
|
539
|
-
*/
|
|
540
|
-
/**
|
|
541
|
-
* Adds a filter expression to refine the query results.
|
|
477
|
+
* Adds a filter expression to refine the operation results.
|
|
542
478
|
* Use this method when you need to:
|
|
543
479
|
* - Filter dinosaurs by behavior patterns
|
|
544
480
|
* - Find habitats with specific conditions
|
|
@@ -594,34 +530,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
594
530
|
return this;
|
|
595
531
|
}
|
|
596
532
|
/**
|
|
597
|
-
* Specifies which attributes to return in the
|
|
598
|
-
* Use this method when you need to:
|
|
599
|
-
* - Reduce data transfer by selecting specific attributes
|
|
600
|
-
* - Optimize response size
|
|
601
|
-
* - Focus on relevant attributes only
|
|
602
|
-
*
|
|
603
|
-
* Note: Using projection can significantly reduce the amount
|
|
604
|
-
* of data returned and lower your costs.
|
|
605
|
-
*
|
|
606
|
-
* @example
|
|
607
|
-
* ```ts
|
|
608
|
-
* // Select single attribute
|
|
609
|
-
* builder.select('email')
|
|
610
|
-
*
|
|
611
|
-
* // Select multiple attributes
|
|
612
|
-
* builder.select(['id', 'name', 'email'])
|
|
613
|
-
*
|
|
614
|
-
* // Chain multiple select calls
|
|
615
|
-
* builder
|
|
616
|
-
* .select('id')
|
|
617
|
-
* .select(['name', 'email'])
|
|
618
|
-
* ```
|
|
619
|
-
*
|
|
620
|
-
* @param fields - A single field name or an array of field names to return
|
|
621
|
-
* @returns The builder instance for method chaining
|
|
622
|
-
*/
|
|
623
|
-
/**
|
|
624
|
-
* Specifies which attributes to return in the query results.
|
|
533
|
+
* Specifies which attributes to return in the results.
|
|
625
534
|
* Use this method when you need to:
|
|
626
535
|
* - Get specific dinosaur attributes
|
|
627
536
|
* - Retrieve habitat statistics
|
|
@@ -663,11 +572,86 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
663
572
|
return this;
|
|
664
573
|
}
|
|
665
574
|
/**
|
|
666
|
-
*
|
|
575
|
+
* Creates a paginator that handles DynamoDB pagination automatically.
|
|
576
|
+
* The paginator handles:
|
|
577
|
+
* - Tracking the last evaluated key
|
|
578
|
+
* - Managing page boundaries
|
|
579
|
+
* - Respecting overall query limits
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* ```typescript
|
|
583
|
+
* // Create a paginator for dinosaur records
|
|
584
|
+
* const paginator = builder
|
|
585
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
586
|
+
* .paginate(10);
|
|
587
|
+
*
|
|
588
|
+
* // Process pages of dinosaur results
|
|
589
|
+
* while (paginator.hasNextPage()) {
|
|
590
|
+
* const page = await paginator.getNextPage();
|
|
591
|
+
* console.log(`Processing page ${page.page}, count: ${page.items.length}`);
|
|
592
|
+
* // Process dinosaur data
|
|
593
|
+
* }
|
|
594
|
+
* ```
|
|
595
|
+
*
|
|
596
|
+
* @param pageSize - The number of items to return per page
|
|
597
|
+
* @returns A Paginator instance that manages the pagination state
|
|
598
|
+
* @see Paginator for more pagination control options
|
|
599
|
+
*/
|
|
600
|
+
paginate(pageSize) {
|
|
601
|
+
return new Paginator(this, pageSize);
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Sets the starting point using a previous lastEvaluatedKey.
|
|
667
605
|
* Use this method when you need to:
|
|
668
|
-
* -
|
|
669
|
-
* -
|
|
670
|
-
* -
|
|
606
|
+
* - Implement manual dinosaur list pagination
|
|
607
|
+
* - Resume habitat inspection reviews
|
|
608
|
+
* - Continue security incident analysis
|
|
609
|
+
* - Store operation position between sessions
|
|
610
|
+
*
|
|
611
|
+
* Note: This method is typically used for manual pagination.
|
|
612
|
+
* For automatic pagination, use the paginate() method instead.
|
|
613
|
+
*
|
|
614
|
+
* @example
|
|
615
|
+
* ```typescript
|
|
616
|
+
* // First batch of dinosaurs
|
|
617
|
+
* const result1 = await builder
|
|
618
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
619
|
+
* .limit(5)
|
|
620
|
+
* .execute();
|
|
621
|
+
*
|
|
622
|
+
* if (result1.lastEvaluatedKey) {
|
|
623
|
+
* // Continue listing dinosaurs
|
|
624
|
+
* const result2 = await builder
|
|
625
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
626
|
+
* .startFrom(result1.lastEvaluatedKey)
|
|
627
|
+
* .limit(5)
|
|
628
|
+
* .execute();
|
|
629
|
+
*
|
|
630
|
+
* console.log('Additional dinosaurs:', result2.items);
|
|
631
|
+
* }
|
|
632
|
+
* ```
|
|
633
|
+
*
|
|
634
|
+
* @param lastEvaluatedKey - The exclusive start key from a previous result
|
|
635
|
+
* @returns The builder instance for method chaining
|
|
636
|
+
*/
|
|
637
|
+
startFrom(lastEvaluatedKey) {
|
|
638
|
+
this.options.lastEvaluatedKey = lastEvaluatedKey;
|
|
639
|
+
return this;
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
// src/builders/query-builder.ts
|
|
644
|
+
var QueryBuilder = class _QueryBuilder extends FilterBuilder {
|
|
645
|
+
keyCondition;
|
|
646
|
+
options = {};
|
|
647
|
+
executor;
|
|
648
|
+
constructor(executor, keyCondition) {
|
|
649
|
+
super();
|
|
650
|
+
this.executor = executor;
|
|
651
|
+
this.keyCondition = keyCondition;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Sets the maximum number of items to return from the query.
|
|
671
655
|
*
|
|
672
656
|
* Note: This is the default behavior if no sort order is specified.
|
|
673
657
|
*
|
|
@@ -689,11 +673,6 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
689
673
|
*/
|
|
690
674
|
/**
|
|
691
675
|
* Sets the query to return items in ascending order by sort key.
|
|
692
|
-
* Use this method when you need to:
|
|
693
|
-
* - List dinosaurs by age (youngest first)
|
|
694
|
-
* - View incidents chronologically
|
|
695
|
-
* - Track feeding schedule progression
|
|
696
|
-
* - Monitor habitat inspections
|
|
697
676
|
*
|
|
698
677
|
* @example
|
|
699
678
|
* ```typescript
|
|
@@ -718,11 +697,6 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
718
697
|
}
|
|
719
698
|
/**
|
|
720
699
|
* Sets the query to return items in descending order by sort key.
|
|
721
|
-
* Use this method when you need to:
|
|
722
|
-
* - Get most recent security breaches
|
|
723
|
-
* - Find oldest dinosaurs first
|
|
724
|
-
* - Check latest habitat modifications
|
|
725
|
-
* - Monitor recent feeding events
|
|
726
700
|
*
|
|
727
701
|
* @example
|
|
728
702
|
* ```typescript
|
|
@@ -747,92 +721,8 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
747
721
|
this.options.scanIndexForward = false;
|
|
748
722
|
return this;
|
|
749
723
|
}
|
|
750
|
-
/**
|
|
751
|
-
* Creates a paginator that handles DynamoDB pagination automatically.
|
|
752
|
-
* Use this method when you need to:
|
|
753
|
-
* - Browse large dinosaur collections
|
|
754
|
-
* - View habitat inspection history
|
|
755
|
-
* - Monitor security incidents
|
|
756
|
-
* - Track feeding patterns
|
|
757
|
-
*
|
|
758
|
-
* The paginator handles:
|
|
759
|
-
* - Tracking the last evaluated key
|
|
760
|
-
* - Managing page boundaries
|
|
761
|
-
* - Respecting overall query limits
|
|
762
|
-
*
|
|
763
|
-
* @example
|
|
764
|
-
* ```typescript
|
|
765
|
-
* // List dinosaurs by species
|
|
766
|
-
* const paginator = new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
767
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
768
|
-
* .useIndex('species-index')
|
|
769
|
-
* .paginate(10);
|
|
770
|
-
*
|
|
771
|
-
* // Process pages of security incidents
|
|
772
|
-
* const paginator = new QueryBuilder(executor, eq('type', 'SECURITY_BREACH'))
|
|
773
|
-
* .filter(op => op.gt('severityLevel', 7))
|
|
774
|
-
* .sortDescending()
|
|
775
|
-
* .paginate(25);
|
|
776
|
-
*
|
|
777
|
-
* while (paginator.hasNextPage()) {
|
|
778
|
-
* const page = await paginator.getNextPage();
|
|
779
|
-
* console.log(`Processing incidents page ${page.page}, count: ${page.items.length}`);
|
|
780
|
-
* // Handle security incidents
|
|
781
|
-
* }
|
|
782
|
-
* ```
|
|
783
|
-
*
|
|
784
|
-
* @param pageSize - The number of items to return per page
|
|
785
|
-
* @returns A Paginator instance that manages the pagination state
|
|
786
|
-
* @see Paginator for more pagination control options
|
|
787
|
-
*/
|
|
788
|
-
paginate(pageSize) {
|
|
789
|
-
return new Paginator(this, pageSize);
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Sets the starting point for the query using a previous lastEvaluatedKey.
|
|
793
|
-
* Use this method when you need to:
|
|
794
|
-
* - Implement manual dinosaur list pagination
|
|
795
|
-
* - Resume habitat inspection reviews
|
|
796
|
-
* - Continue security incident analysis
|
|
797
|
-
* - Store query position between sessions
|
|
798
|
-
*
|
|
799
|
-
* Note: This method is typically used for manual pagination.
|
|
800
|
-
* For automatic pagination, use the paginate() method instead.
|
|
801
|
-
*
|
|
802
|
-
* @example
|
|
803
|
-
* ```typescript
|
|
804
|
-
* // First batch of dinosaurs
|
|
805
|
-
* const result1 = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
806
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
807
|
-
* .limit(5)
|
|
808
|
-
* .execute();
|
|
809
|
-
*
|
|
810
|
-
* if (result1.lastEvaluatedKey) {
|
|
811
|
-
* // Continue listing dinosaurs
|
|
812
|
-
* const result2 = await new QueryBuilder(executor, eq('species', 'Velociraptor'))
|
|
813
|
-
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
814
|
-
* .startFrom(result1.lastEvaluatedKey)
|
|
815
|
-
* .limit(5)
|
|
816
|
-
* .execute();
|
|
817
|
-
*
|
|
818
|
-
* console.log('Additional dinosaurs:', result2.items);
|
|
819
|
-
* }
|
|
820
|
-
* ```
|
|
821
|
-
*
|
|
822
|
-
* @param lastEvaluatedKey - The exclusive start key from a previous query result
|
|
823
|
-
* @returns The builder instance for method chaining
|
|
824
|
-
*/
|
|
825
|
-
startFrom(lastEvaluatedKey) {
|
|
826
|
-
this.options.lastEvaluatedKey = lastEvaluatedKey;
|
|
827
|
-
return this;
|
|
828
|
-
}
|
|
829
724
|
/**
|
|
830
725
|
* Creates a deep clone of this QueryBuilder instance.
|
|
831
|
-
* Use this method when you need to:
|
|
832
|
-
* - Query different dinosaur statuses
|
|
833
|
-
* - Check multiple habitat conditions
|
|
834
|
-
* - Monitor various security levels
|
|
835
|
-
* - Create report templates
|
|
836
726
|
*
|
|
837
727
|
* This is particularly useful when:
|
|
838
728
|
* - Implementing pagination (used internally by paginate())
|
|
@@ -872,11 +762,6 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
872
762
|
}
|
|
873
763
|
/**
|
|
874
764
|
* Executes the query against DynamoDB.
|
|
875
|
-
* Use this method when you need to:
|
|
876
|
-
* - Find specific dinosaur groups
|
|
877
|
-
* - Check habitat conditions
|
|
878
|
-
* - Monitor security incidents
|
|
879
|
-
* - Track feeding patterns
|
|
880
765
|
*
|
|
881
766
|
* The method returns both the matched items and, if there are more results,
|
|
882
767
|
* a lastEvaluatedKey that can be used with startFrom() to continue the query.
|
|
@@ -967,13 +852,24 @@ function debugCommand(command) {
|
|
|
967
852
|
// src/builders/put-builder.ts
|
|
968
853
|
var PutBuilder = class {
|
|
969
854
|
item;
|
|
970
|
-
options
|
|
855
|
+
options;
|
|
971
856
|
executor;
|
|
972
857
|
tableName;
|
|
973
858
|
constructor(executor, item, tableName) {
|
|
974
859
|
this.executor = executor;
|
|
975
860
|
this.item = item;
|
|
976
861
|
this.tableName = tableName;
|
|
862
|
+
this.options = {
|
|
863
|
+
returnValues: "NONE"
|
|
864
|
+
};
|
|
865
|
+
}
|
|
866
|
+
set(valuesOrPath, value) {
|
|
867
|
+
if (typeof valuesOrPath === "object") {
|
|
868
|
+
Object.assign(this.item, valuesOrPath);
|
|
869
|
+
} else {
|
|
870
|
+
this.item[valuesOrPath] = value;
|
|
871
|
+
}
|
|
872
|
+
return this;
|
|
977
873
|
}
|
|
978
874
|
/**
|
|
979
875
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
@@ -1002,10 +898,6 @@ var PutBuilder = class {
|
|
|
1002
898
|
*/
|
|
1003
899
|
/**
|
|
1004
900
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
1005
|
-
* Use this method when you need to:
|
|
1006
|
-
* - Prevent duplicate dinosaur entries
|
|
1007
|
-
* - Ensure habitat requirements
|
|
1008
|
-
* - Validate security protocols
|
|
1009
901
|
*
|
|
1010
902
|
* @example
|
|
1011
903
|
* ```typescript
|
|
@@ -1062,10 +954,11 @@ var PutBuilder = class {
|
|
|
1062
954
|
}
|
|
1063
955
|
/**
|
|
1064
956
|
* Sets whether to return the item's previous values (if it existed).
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
957
|
+
*
|
|
958
|
+
* @options
|
|
959
|
+
* - NONE: No return value
|
|
960
|
+
* - ALL_OLD: Returns the item's previous state if it existed, no read capacity units are consumed
|
|
961
|
+
* - CONSISTENT: (default) Performs a GET operation after the put to retrieve the item's new state
|
|
1069
962
|
*
|
|
1070
963
|
* @example
|
|
1071
964
|
* ```ts
|
|
@@ -1086,7 +979,7 @@ var PutBuilder = class {
|
|
|
1086
979
|
* }
|
|
1087
980
|
* ```
|
|
1088
981
|
*
|
|
1089
|
-
* @param returnValues - Use 'ALL_OLD' to return previous values, or 'NONE' (default)
|
|
982
|
+
* @param returnValues - Use 'ALL_OLD' to return previous values if the item was overwritten, or 'NONE' (default).
|
|
1090
983
|
* @returns The builder instance for method chaining
|
|
1091
984
|
*/
|
|
1092
985
|
returnValues(returnValues) {
|
|
@@ -1174,11 +1067,6 @@ var PutBuilder = class {
|
|
|
1174
1067
|
/**
|
|
1175
1068
|
* Gets a human-readable representation of the put command
|
|
1176
1069
|
* with all expression placeholders replaced by their actual values.
|
|
1177
|
-
* Use this method when you need to:
|
|
1178
|
-
* - Debug complex dinosaur transfers
|
|
1179
|
-
* - Verify habitat assignments
|
|
1180
|
-
* - Log security protocols
|
|
1181
|
-
* - Troubleshoot breeding program conditions
|
|
1182
1070
|
*
|
|
1183
1071
|
* @example
|
|
1184
1072
|
* ```ts
|
|
@@ -1227,10 +1115,6 @@ var DeleteBuilder = class {
|
|
|
1227
1115
|
}
|
|
1228
1116
|
/**
|
|
1229
1117
|
* Adds a condition that must be satisfied for the delete operation to succeed.
|
|
1230
|
-
* Use this method when you need to:
|
|
1231
|
-
* - Ensure safe removal conditions
|
|
1232
|
-
* - Verify habitat status before deletion
|
|
1233
|
-
* - Implement safety protocols
|
|
1234
1118
|
*
|
|
1235
1119
|
* @example
|
|
1236
1120
|
* ```typescript
|
|
@@ -1282,10 +1166,6 @@ var DeleteBuilder = class {
|
|
|
1282
1166
|
}
|
|
1283
1167
|
/**
|
|
1284
1168
|
* Sets whether to return the item's attribute values before deletion.
|
|
1285
|
-
* Use this method when you need to:
|
|
1286
|
-
* - Archive removed dinosaur data
|
|
1287
|
-
* - Track habitat decommissioning history
|
|
1288
|
-
* - Maintain removal audit logs
|
|
1289
1169
|
*
|
|
1290
1170
|
* @example
|
|
1291
1171
|
* ```ts
|
|
@@ -1326,10 +1206,6 @@ var DeleteBuilder = class {
|
|
|
1326
1206
|
}
|
|
1327
1207
|
/**
|
|
1328
1208
|
* Adds this delete operation to a transaction.
|
|
1329
|
-
* Use this method when you need to:
|
|
1330
|
-
* - Coordinate dinosaur transfers
|
|
1331
|
-
* - Manage habitat decommissioning
|
|
1332
|
-
* - Handle species relocations
|
|
1333
1209
|
*
|
|
1334
1210
|
* @example
|
|
1335
1211
|
* ```ts
|
|
@@ -1380,11 +1256,6 @@ var DeleteBuilder = class {
|
|
|
1380
1256
|
/**
|
|
1381
1257
|
* Gets a human-readable representation of the delete command
|
|
1382
1258
|
* with all expression placeholders replaced by their actual values.
|
|
1383
|
-
* Use this method when you need to:
|
|
1384
|
-
* - Debug complex deletion conditions
|
|
1385
|
-
* - Verify safety checks
|
|
1386
|
-
* - Log removal operations
|
|
1387
|
-
* - Troubleshoot failed deletions
|
|
1388
1259
|
*
|
|
1389
1260
|
* @example
|
|
1390
1261
|
* ```ts
|
|
@@ -1443,10 +1314,6 @@ var UpdateBuilder = class {
|
|
|
1443
1314
|
}
|
|
1444
1315
|
/**
|
|
1445
1316
|
* Removes an attribute from the item.
|
|
1446
|
-
* Use this method when you need to:
|
|
1447
|
-
* - Delete attributes completely
|
|
1448
|
-
* - Remove nested attributes
|
|
1449
|
-
* - Clean up deprecated fields
|
|
1450
1317
|
*
|
|
1451
1318
|
* @example
|
|
1452
1319
|
* ```typescript
|
|
@@ -1473,10 +1340,6 @@ var UpdateBuilder = class {
|
|
|
1473
1340
|
}
|
|
1474
1341
|
/**
|
|
1475
1342
|
* Adds a value to a number attribute or adds elements to a set.
|
|
1476
|
-
* Use this method when you need to:
|
|
1477
|
-
* - Increment counters
|
|
1478
|
-
* - Add elements to a set atomically
|
|
1479
|
-
* - Update numerical statistics
|
|
1480
1343
|
*
|
|
1481
1344
|
* @example
|
|
1482
1345
|
* ```typescript
|
|
@@ -1505,10 +1368,6 @@ var UpdateBuilder = class {
|
|
|
1505
1368
|
}
|
|
1506
1369
|
/**
|
|
1507
1370
|
* Removes elements from a set attribute.
|
|
1508
|
-
* Use this method when you need to:
|
|
1509
|
-
* - Remove specific elements from a set
|
|
1510
|
-
* - Update set-based attributes atomically
|
|
1511
|
-
* - Maintain set membership
|
|
1512
1371
|
*
|
|
1513
1372
|
* @example
|
|
1514
1373
|
* ```typescript
|
|
@@ -1518,7 +1377,7 @@ var UpdateBuilder = class {
|
|
|
1518
1377
|
* ['JUNGLE', 'COASTAL']
|
|
1519
1378
|
* );
|
|
1520
1379
|
*
|
|
1521
|
-
* // Remove from sets using Set
|
|
1380
|
+
* // Remove from sets using Set DynamoItems
|
|
1522
1381
|
* builder.deleteElementsFromSet(
|
|
1523
1382
|
* 'knownBehaviors',
|
|
1524
1383
|
* new Set(['NOCTURNAL', 'TERRITORIAL'])
|
|
@@ -1551,11 +1410,6 @@ var UpdateBuilder = class {
|
|
|
1551
1410
|
}
|
|
1552
1411
|
/**
|
|
1553
1412
|
* Adds a condition that must be satisfied for the update to succeed.
|
|
1554
|
-
* Use this method when you need to:
|
|
1555
|
-
* - Implement optimistic locking
|
|
1556
|
-
* - Ensure item state before update
|
|
1557
|
-
* - Validate business rules
|
|
1558
|
-
* - Prevent concurrent modifications
|
|
1559
1413
|
*
|
|
1560
1414
|
* @example
|
|
1561
1415
|
* ```typescript
|
|
@@ -1587,7 +1441,7 @@ var UpdateBuilder = class {
|
|
|
1587
1441
|
* );
|
|
1588
1442
|
* ```
|
|
1589
1443
|
*
|
|
1590
|
-
* @param condition - Either a Condition
|
|
1444
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
1591
1445
|
* @returns The builder instance for method chaining
|
|
1592
1446
|
*/
|
|
1593
1447
|
condition(condition) {
|
|
@@ -1616,11 +1470,6 @@ var UpdateBuilder = class {
|
|
|
1616
1470
|
}
|
|
1617
1471
|
/**
|
|
1618
1472
|
* Sets which item attributes to include in the response.
|
|
1619
|
-
* Use this method when you need to:
|
|
1620
|
-
* - Get the complete updated item
|
|
1621
|
-
* - Track changes to specific attributes
|
|
1622
|
-
* - Compare old and new values
|
|
1623
|
-
* - Monitor attribute modifications
|
|
1624
1473
|
*
|
|
1625
1474
|
* Available options:
|
|
1626
1475
|
* - ALL_NEW: All attributes after the update
|
|
@@ -1748,10 +1597,6 @@ var UpdateBuilder = class {
|
|
|
1748
1597
|
}
|
|
1749
1598
|
/**
|
|
1750
1599
|
* Adds this update operation to a transaction.
|
|
1751
|
-
* Use this method when you need to:
|
|
1752
|
-
* - Update items as part of a larger transaction
|
|
1753
|
-
* - Ensure multiple updates are atomic
|
|
1754
|
-
* - Coordinate updates across multiple items
|
|
1755
1600
|
*
|
|
1756
1601
|
* @example
|
|
1757
1602
|
* ```typescript
|
|
@@ -1781,11 +1626,6 @@ var UpdateBuilder = class {
|
|
|
1781
1626
|
}
|
|
1782
1627
|
/**
|
|
1783
1628
|
* Gets a human-readable representation of the update command.
|
|
1784
|
-
* Use this method when you need to:
|
|
1785
|
-
* - Debug complex update expressions
|
|
1786
|
-
* - Verify attribute names and values
|
|
1787
|
-
* - Log update operations
|
|
1788
|
-
* - Troubleshoot condition expressions
|
|
1789
1629
|
*
|
|
1790
1630
|
* @example
|
|
1791
1631
|
* ```typescript
|
|
@@ -1812,10 +1652,6 @@ var UpdateBuilder = class {
|
|
|
1812
1652
|
}
|
|
1813
1653
|
/**
|
|
1814
1654
|
* Executes the update operation against DynamoDB.
|
|
1815
|
-
* Use this method when you need to:
|
|
1816
|
-
* - Apply updates immediately
|
|
1817
|
-
* - Get the updated item values
|
|
1818
|
-
* - Handle conditional update failures
|
|
1819
1655
|
*
|
|
1820
1656
|
* @example
|
|
1821
1657
|
* ```typescript
|
|
@@ -1850,7 +1686,7 @@ var UpdateBuilder = class {
|
|
|
1850
1686
|
* }
|
|
1851
1687
|
* ```
|
|
1852
1688
|
*
|
|
1853
|
-
* @returns A promise that resolves to an
|
|
1689
|
+
* @returns A promise that resolves to an DynamoItem containing the updated item (if returnValues is set)
|
|
1854
1690
|
* @throws {ConditionalCheckFailedException} If the condition check fails
|
|
1855
1691
|
* @throws {Error} If the update operation fails for other reasons
|
|
1856
1692
|
*/
|
|
@@ -1904,7 +1740,7 @@ var TransactionBuilder = class {
|
|
|
1904
1740
|
*/
|
|
1905
1741
|
checkForDuplicateItem(tableName, newItem) {
|
|
1906
1742
|
const pkName = this.indexConfig.partitionKey;
|
|
1907
|
-
const skName = this.indexConfig.sortKey
|
|
1743
|
+
const skName = this.indexConfig.sortKey ?? "";
|
|
1908
1744
|
const pkValue = newItem[pkName];
|
|
1909
1745
|
const skValue = skName ? newItem[skName] : void 0;
|
|
1910
1746
|
if (!pkValue) {
|
|
@@ -1945,6 +1781,18 @@ var TransactionBuilder = class {
|
|
|
1945
1781
|
);
|
|
1946
1782
|
}
|
|
1947
1783
|
}
|
|
1784
|
+
createKeyForPrimaryIndex(key) {
|
|
1785
|
+
const keyCondition = {
|
|
1786
|
+
[this.indexConfig.partitionKey]: key.pk
|
|
1787
|
+
};
|
|
1788
|
+
if (this.indexConfig.sortKey) {
|
|
1789
|
+
if (key.sk === void 0) {
|
|
1790
|
+
throw new Error("Sort key is required for delete operation");
|
|
1791
|
+
}
|
|
1792
|
+
keyCondition[this.indexConfig.sortKey] = key.sk;
|
|
1793
|
+
}
|
|
1794
|
+
return keyCondition;
|
|
1795
|
+
}
|
|
1948
1796
|
/**
|
|
1949
1797
|
* Adds a put operation to the transaction.
|
|
1950
1798
|
* Use this method when you need to:
|
|
@@ -2084,15 +1932,13 @@ var TransactionBuilder = class {
|
|
|
2084
1932
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2085
1933
|
*/
|
|
2086
1934
|
delete(tableName, key, condition) {
|
|
2087
|
-
this.
|
|
1935
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
1936
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2088
1937
|
const transactionItem = {
|
|
2089
1938
|
type: "Delete",
|
|
2090
1939
|
params: {
|
|
2091
1940
|
tableName,
|
|
2092
|
-
key:
|
|
2093
|
-
pk: key.pk,
|
|
2094
|
-
sk: key.sk
|
|
2095
|
-
}
|
|
1941
|
+
key: keyCondition
|
|
2096
1942
|
}
|
|
2097
1943
|
};
|
|
2098
1944
|
if (condition) {
|
|
@@ -2134,10 +1980,14 @@ var TransactionBuilder = class {
|
|
|
2134
1980
|
* @see DeleteBuilder for creating delete commands
|
|
2135
1981
|
*/
|
|
2136
1982
|
deleteWithCommand(command) {
|
|
2137
|
-
this.
|
|
1983
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
1984
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2138
1985
|
const transactionItem = {
|
|
2139
1986
|
type: "Delete",
|
|
2140
|
-
params:
|
|
1987
|
+
params: {
|
|
1988
|
+
...command,
|
|
1989
|
+
key: keyCondition
|
|
1990
|
+
}
|
|
2141
1991
|
};
|
|
2142
1992
|
this.items.push(transactionItem);
|
|
2143
1993
|
return this;
|
|
@@ -2197,15 +2047,13 @@ var TransactionBuilder = class {
|
|
|
2197
2047
|
* @throws {Error} If a duplicate item is detected in the transaction
|
|
2198
2048
|
*/
|
|
2199
2049
|
update(tableName, key, updateExpression, expressionAttributeNames, expressionAttributeValues, condition) {
|
|
2200
|
-
this.
|
|
2050
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2051
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2201
2052
|
const transactionItem = {
|
|
2202
2053
|
type: "Update",
|
|
2203
2054
|
params: {
|
|
2204
2055
|
tableName,
|
|
2205
|
-
key:
|
|
2206
|
-
pk: key.pk,
|
|
2207
|
-
sk: key.sk
|
|
2208
|
-
},
|
|
2056
|
+
key: keyCondition,
|
|
2209
2057
|
updateExpression,
|
|
2210
2058
|
expressionAttributeNames,
|
|
2211
2059
|
expressionAttributeValues
|
|
@@ -2259,10 +2107,14 @@ var TransactionBuilder = class {
|
|
|
2259
2107
|
* @see UpdateBuilder for creating update commands
|
|
2260
2108
|
*/
|
|
2261
2109
|
updateWithCommand(command) {
|
|
2262
|
-
this.
|
|
2110
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
2111
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2263
2112
|
const transactionItem = {
|
|
2264
2113
|
type: "Update",
|
|
2265
|
-
params:
|
|
2114
|
+
params: {
|
|
2115
|
+
...command,
|
|
2116
|
+
key: keyCondition
|
|
2117
|
+
}
|
|
2266
2118
|
};
|
|
2267
2119
|
this.items.push(transactionItem);
|
|
2268
2120
|
return this;
|
|
@@ -2319,7 +2171,8 @@ var TransactionBuilder = class {
|
|
|
2319
2171
|
* @throws {Error} If condition expression generation fails
|
|
2320
2172
|
*/
|
|
2321
2173
|
conditionCheck(tableName, key, condition) {
|
|
2322
|
-
this.
|
|
2174
|
+
const keyCondition = this.createKeyForPrimaryIndex(key);
|
|
2175
|
+
this.checkForDuplicateItem(tableName, keyCondition);
|
|
2323
2176
|
const { expression, names, values } = prepareExpressionParams(condition);
|
|
2324
2177
|
if (!expression) {
|
|
2325
2178
|
throw new Error("Failed to generate condition expression");
|
|
@@ -2328,10 +2181,7 @@ var TransactionBuilder = class {
|
|
|
2328
2181
|
type: "ConditionCheck",
|
|
2329
2182
|
params: {
|
|
2330
2183
|
tableName,
|
|
2331
|
-
key:
|
|
2332
|
-
pk: key.pk,
|
|
2333
|
-
sk: key.sk
|
|
2334
|
-
},
|
|
2184
|
+
key: keyCondition,
|
|
2335
2185
|
conditionExpression: expression,
|
|
2336
2186
|
expressionAttributeNames: names,
|
|
2337
2187
|
expressionAttributeValues: values
|
|
@@ -2371,10 +2221,14 @@ var TransactionBuilder = class {
|
|
|
2371
2221
|
* @see ConditionCheckBuilder for creating condition check commands
|
|
2372
2222
|
*/
|
|
2373
2223
|
conditionCheckWithCommand(command) {
|
|
2374
|
-
this.
|
|
2224
|
+
const keyCondition = this.createKeyForPrimaryIndex(command.key);
|
|
2225
|
+
this.checkForDuplicateItem(command.tableName, keyCondition);
|
|
2375
2226
|
const transactionItem = {
|
|
2376
2227
|
type: "ConditionCheck",
|
|
2377
|
-
params:
|
|
2228
|
+
params: {
|
|
2229
|
+
...command,
|
|
2230
|
+
key: keyCondition
|
|
2231
|
+
}
|
|
2378
2232
|
};
|
|
2379
2233
|
this.items.push(transactionItem);
|
|
2380
2234
|
return this;
|
|
@@ -2607,7 +2461,7 @@ var ConditionCheckBuilder = class {
|
|
|
2607
2461
|
* );
|
|
2608
2462
|
* ```
|
|
2609
2463
|
*
|
|
2610
|
-
* @param condition - Either a Condition
|
|
2464
|
+
* @param condition - Either a Condition DynamoItem or a callback function that builds the condition
|
|
2611
2465
|
* @returns The builder instance for method chaining
|
|
2612
2466
|
*/
|
|
2613
2467
|
condition(condition) {
|
|
@@ -2833,18 +2687,84 @@ var GetBuilder = class {
|
|
|
2833
2687
|
* - item: The retrieved dinosaur or undefined if not found
|
|
2834
2688
|
*/
|
|
2835
2689
|
async execute() {
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
this.params
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2690
|
+
const expressionParams = {
|
|
2691
|
+
expressionAttributeNames: {},
|
|
2692
|
+
expressionAttributeValues: {},
|
|
2693
|
+
valueCounter: { count: 0 }
|
|
2694
|
+
};
|
|
2695
|
+
const projectionExpression = Array.from(this.selectedFields).map((p) => generateAttributeName(expressionParams, p)).join(", ");
|
|
2696
|
+
const { expressionAttributeNames } = expressionParams;
|
|
2697
|
+
return this.executor({
|
|
2698
|
+
...this.params,
|
|
2699
|
+
projectionExpression: projectionExpression.length > 0 ? projectionExpression : void 0,
|
|
2700
|
+
expressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0
|
|
2701
|
+
});
|
|
2702
|
+
}
|
|
2703
|
+
};
|
|
2704
|
+
|
|
2705
|
+
// src/builders/scan-builder.ts
|
|
2706
|
+
var ScanBuilder = class _ScanBuilder extends FilterBuilder {
|
|
2707
|
+
executor;
|
|
2708
|
+
constructor(executor) {
|
|
2709
|
+
super();
|
|
2710
|
+
this.executor = executor;
|
|
2711
|
+
}
|
|
2712
|
+
/**
|
|
2713
|
+
* Creates a deep clone of this ScanBuilder instance.
|
|
2714
|
+
* Use this method when you need to:
|
|
2715
|
+
* - Create scan templates
|
|
2716
|
+
* - Run multiple variations of a scan
|
|
2717
|
+
* - Implement pagination (used internally by paginate())
|
|
2718
|
+
*
|
|
2719
|
+
* @returns A new ScanBuilder instance with the same configuration
|
|
2720
|
+
*/
|
|
2721
|
+
clone() {
|
|
2722
|
+
const clone = new _ScanBuilder(this.executor);
|
|
2723
|
+
clone.options = { ...this.options };
|
|
2724
|
+
clone.selectedFields = new Set(this.selectedFields);
|
|
2725
|
+
return clone;
|
|
2726
|
+
}
|
|
2727
|
+
/**
|
|
2728
|
+
* Executes the scan against DynamoDB.
|
|
2729
|
+
* Use this method when you need to:
|
|
2730
|
+
* - Search across the entire table
|
|
2731
|
+
* - Find items matching specific criteria
|
|
2732
|
+
* - Perform full table analysis
|
|
2733
|
+
* - Generate reports across all data
|
|
2734
|
+
*
|
|
2735
|
+
* The method returns both the matched items and, if there are more results,
|
|
2736
|
+
* a lastEvaluatedKey that can be used with startFrom() to continue the scan.
|
|
2737
|
+
*
|
|
2738
|
+
* @example
|
|
2739
|
+
* ```typescript
|
|
2740
|
+
* try {
|
|
2741
|
+
* // Find all dinosaurs with high aggression levels
|
|
2742
|
+
* const result = await new ScanBuilder(executor)
|
|
2743
|
+
* .filter(op =>
|
|
2744
|
+
* op.and([
|
|
2745
|
+
* op.eq('status', 'ACTIVE'),
|
|
2746
|
+
* op.gt('aggressionLevel', 7)
|
|
2747
|
+
* ])
|
|
2748
|
+
* )
|
|
2749
|
+
* .limit(20)
|
|
2750
|
+
* .execute();
|
|
2751
|
+
*
|
|
2752
|
+
* console.log(`Found ${result.items.length} potentially dangerous dinosaurs`);
|
|
2753
|
+
*
|
|
2754
|
+
* if (result.lastEvaluatedKey) {
|
|
2755
|
+
* console.log('More results available');
|
|
2756
|
+
* }
|
|
2757
|
+
* } catch (error) {
|
|
2758
|
+
* console.error('Security scan failed:', error);
|
|
2759
|
+
* }
|
|
2760
|
+
* ```
|
|
2761
|
+
*
|
|
2762
|
+
* @returns A promise that resolves to an object containing:
|
|
2763
|
+
* - items: Array of items matching the scan criteria
|
|
2764
|
+
* - lastEvaluatedKey: Token for continuing the scan, if more items exist
|
|
2765
|
+
*/
|
|
2766
|
+
async execute() {
|
|
2767
|
+
return this.executor(this.options);
|
|
2848
2768
|
}
|
|
2849
2769
|
};
|
|
2850
2770
|
|
|
@@ -2854,8 +2774,17 @@ var DDB_BATCH_GET_LIMIT = 100;
|
|
|
2854
2774
|
var Table = class {
|
|
2855
2775
|
dynamoClient;
|
|
2856
2776
|
tableName;
|
|
2777
|
+
/**
|
|
2778
|
+
* The column name of the partitionKey for the Table
|
|
2779
|
+
*/
|
|
2857
2780
|
partitionKey;
|
|
2781
|
+
/**
|
|
2782
|
+
* The column name of the sortKey for the Table
|
|
2783
|
+
*/
|
|
2858
2784
|
sortKey;
|
|
2785
|
+
/**
|
|
2786
|
+
* The Global Secondary Indexes that are configured on this table
|
|
2787
|
+
*/
|
|
2859
2788
|
gsis;
|
|
2860
2789
|
constructor(config) {
|
|
2861
2790
|
this.dynamoClient = config.client;
|
|
@@ -2864,6 +2793,16 @@ var Table = class {
|
|
|
2864
2793
|
this.sortKey = config.indexes.sortKey;
|
|
2865
2794
|
this.gsis = config.indexes.gsis || {};
|
|
2866
2795
|
}
|
|
2796
|
+
createKeyForPrimaryIndex(keyCondition) {
|
|
2797
|
+
const primaryCondition = { [this.partitionKey]: keyCondition.pk };
|
|
2798
|
+
if (this.sortKey) {
|
|
2799
|
+
if (!keyCondition.sk) {
|
|
2800
|
+
throw new Error("Sort key has not been provided but the Table has a sort key");
|
|
2801
|
+
}
|
|
2802
|
+
primaryCondition[this.sortKey] = keyCondition.sk;
|
|
2803
|
+
}
|
|
2804
|
+
return primaryCondition;
|
|
2805
|
+
}
|
|
2867
2806
|
/**
|
|
2868
2807
|
* Creates a new item in the table, it will fail if the item already exists
|
|
2869
2808
|
*
|
|
@@ -2878,7 +2817,7 @@ var Table = class {
|
|
|
2878
2817
|
try {
|
|
2879
2818
|
const result = await this.dynamoClient.get({
|
|
2880
2819
|
TableName: params.tableName,
|
|
2881
|
-
Key:
|
|
2820
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
2882
2821
|
ProjectionExpression: params.projectionExpression,
|
|
2883
2822
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2884
2823
|
ConsistentRead: params.consistentRead
|
|
@@ -2902,15 +2841,28 @@ var Table = class {
|
|
|
2902
2841
|
put(item) {
|
|
2903
2842
|
const executor = async (params) => {
|
|
2904
2843
|
try {
|
|
2905
|
-
await this.dynamoClient.put({
|
|
2844
|
+
const result = await this.dynamoClient.put({
|
|
2906
2845
|
TableName: params.tableName,
|
|
2907
2846
|
Item: params.item,
|
|
2908
2847
|
ConditionExpression: params.conditionExpression,
|
|
2909
2848
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2910
2849
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
2911
|
-
|
|
2850
|
+
// CONSISTENT is not a valid ReturnValue for DDB, so we set NONE as we are not interested in its
|
|
2851
|
+
// response and will be reloading the item from the DB through a get instead
|
|
2852
|
+
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2912
2853
|
});
|
|
2913
|
-
|
|
2854
|
+
if (params.returnValues === "CONSISTENT") {
|
|
2855
|
+
const getResult = await this.dynamoClient.get({
|
|
2856
|
+
TableName: params.tableName,
|
|
2857
|
+
Key: this.createKeyForPrimaryIndex({
|
|
2858
|
+
pk: params.item[this.partitionKey],
|
|
2859
|
+
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2860
|
+
}),
|
|
2861
|
+
ConsistentRead: true
|
|
2862
|
+
});
|
|
2863
|
+
return getResult.Item;
|
|
2864
|
+
}
|
|
2865
|
+
return result.Attributes;
|
|
2914
2866
|
} catch (error) {
|
|
2915
2867
|
console.error("Error creating item:", error);
|
|
2916
2868
|
throw error;
|
|
@@ -3036,12 +2988,60 @@ var Table = class {
|
|
|
3036
2988
|
};
|
|
3037
2989
|
return new QueryBuilder(executor, keyConditionExpression);
|
|
3038
2990
|
}
|
|
2991
|
+
/**
|
|
2992
|
+
* Creates a scan builder for scanning the entire table
|
|
2993
|
+
* Use this when you need to:
|
|
2994
|
+
* - Process all items in a table
|
|
2995
|
+
* - Apply filters to a large dataset
|
|
2996
|
+
* - Use a GSI for scanning
|
|
2997
|
+
*
|
|
2998
|
+
* @returns A ScanBuilder instance for chaining operations
|
|
2999
|
+
*/
|
|
3000
|
+
scan() {
|
|
3001
|
+
const executor = async (options) => {
|
|
3002
|
+
const expressionParams = {
|
|
3003
|
+
expressionAttributeNames: {},
|
|
3004
|
+
expressionAttributeValues: {},
|
|
3005
|
+
valueCounter: { count: 0 }
|
|
3006
|
+
};
|
|
3007
|
+
let filterExpression;
|
|
3008
|
+
if (options.filter) {
|
|
3009
|
+
filterExpression = buildExpression(options.filter, expressionParams);
|
|
3010
|
+
}
|
|
3011
|
+
const projectionExpression = options.projection?.map((p) => generateAttributeName(expressionParams, p)).join(", ");
|
|
3012
|
+
const { expressionAttributeNames, expressionAttributeValues } = expressionParams;
|
|
3013
|
+
const { indexName, limit, consistentRead, lastEvaluatedKey } = options;
|
|
3014
|
+
const params = {
|
|
3015
|
+
TableName: this.tableName,
|
|
3016
|
+
FilterExpression: filterExpression,
|
|
3017
|
+
ExpressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0,
|
|
3018
|
+
ExpressionAttributeValues: Object.keys(expressionAttributeValues).length > 0 ? expressionAttributeValues : void 0,
|
|
3019
|
+
IndexName: indexName,
|
|
3020
|
+
Limit: limit,
|
|
3021
|
+
ConsistentRead: consistentRead,
|
|
3022
|
+
ProjectionExpression: projectionExpression,
|
|
3023
|
+
ExclusiveStartKey: lastEvaluatedKey
|
|
3024
|
+
};
|
|
3025
|
+
try {
|
|
3026
|
+
const result = await this.dynamoClient.scan(params);
|
|
3027
|
+
return {
|
|
3028
|
+
items: result.Items,
|
|
3029
|
+
lastEvaluatedKey: result.LastEvaluatedKey
|
|
3030
|
+
};
|
|
3031
|
+
} catch (error) {
|
|
3032
|
+
console.log(debugCommand(params));
|
|
3033
|
+
console.error("Error scanning items:", error);
|
|
3034
|
+
throw error;
|
|
3035
|
+
}
|
|
3036
|
+
};
|
|
3037
|
+
return new ScanBuilder(executor);
|
|
3038
|
+
}
|
|
3039
3039
|
delete(keyCondition) {
|
|
3040
3040
|
const executor = async (params) => {
|
|
3041
3041
|
try {
|
|
3042
3042
|
const result = await this.dynamoClient.delete({
|
|
3043
3043
|
TableName: params.tableName,
|
|
3044
|
-
Key:
|
|
3044
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3045
3045
|
ConditionExpression: params.conditionExpression,
|
|
3046
3046
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
3047
3047
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
@@ -3068,7 +3068,7 @@ var Table = class {
|
|
|
3068
3068
|
try {
|
|
3069
3069
|
const result = await this.dynamoClient.update({
|
|
3070
3070
|
TableName: params.tableName,
|
|
3071
|
-
Key:
|
|
3071
|
+
Key: this.createKeyForPrimaryIndex(keyCondition),
|
|
3072
3072
|
UpdateExpression: params.updateExpression,
|
|
3073
3073
|
ConditionExpression: params.conditionExpression,
|
|
3074
3074
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
@@ -3196,10 +3196,7 @@ var Table = class {
|
|
|
3196
3196
|
}
|
|
3197
3197
|
return {
|
|
3198
3198
|
DeleteRequest: {
|
|
3199
|
-
Key:
|
|
3200
|
-
[this.partitionKey]: operation.key.pk,
|
|
3201
|
-
...this.sortKey ? { [this.sortKey]: operation.key.sk } : {}
|
|
3202
|
-
}
|
|
3199
|
+
Key: this.createKeyForPrimaryIndex(operation.key)
|
|
3203
3200
|
}
|
|
3204
3201
|
};
|
|
3205
3202
|
});
|
|
@@ -3242,28 +3239,7 @@ var Table = class {
|
|
|
3242
3239
|
};
|
|
3243
3240
|
}
|
|
3244
3241
|
};
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
PutBuilder,
|
|
3250
|
-
QueryBuilder,
|
|
3251
|
-
Table,
|
|
3252
|
-
TransactionBuilder,
|
|
3253
|
-
UpdateBuilder,
|
|
3254
|
-
and,
|
|
3255
|
-
attributeExists,
|
|
3256
|
-
attributeNotExists,
|
|
3257
|
-
beginsWith,
|
|
3258
|
-
between,
|
|
3259
|
-
contains,
|
|
3260
|
-
createComparisonCondition,
|
|
3261
|
-
eq,
|
|
3262
|
-
gt,
|
|
3263
|
-
gte,
|
|
3264
|
-
lt,
|
|
3265
|
-
lte,
|
|
3266
|
-
ne,
|
|
3267
|
-
not,
|
|
3268
|
-
or
|
|
3269
|
-
};
|
|
3242
|
+
|
|
3243
|
+
exports.Table = Table;
|
|
3244
|
+
//# sourceMappingURL=table.cjs.map
|
|
3245
|
+
//# sourceMappingURL=table.cjs.map
|