dyno-table 0.1.7 → 0.1.8
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 +115 -17
- 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.js +392 -0
- package/dist/builders/condition-check-builder.js.map +1 -0
- package/dist/builders/delete-builder.cjs +422 -0
- package/dist/builders/delete-builder.cjs.map +1 -0
- package/dist/builders/delete-builder.js +420 -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.js +197 -0
- package/dist/builders/paginator.js.map +1 -0
- package/dist/builders/put-builder.cjs +468 -0
- package/dist/builders/put-builder.cjs.map +1 -0
- package/dist/builders/put-builder.js +466 -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.js +672 -0
- package/dist/builders/query-builder.js.map +1 -0
- package/dist/builders/transaction-builder.cjs +876 -0
- package/dist/builders/transaction-builder.cjs.map +1 -0
- package/dist/builders/transaction-builder.js +874 -0
- package/dist/builders/transaction-builder.js.map +1 -0
- package/dist/builders/update-builder.cjs +662 -0
- package/dist/builders/update-builder.cjs.map +1 -0
- package/dist/builders/update-builder.js +660 -0
- package/dist/builders/update-builder.js.map +1 -0
- package/dist/conditions.cjs +59 -0
- package/dist/conditions.cjs.map +1 -0
- package/dist/conditions.js +43 -0
- package/dist/conditions.js.map +1 -0
- package/dist/entity.cjs +169 -0
- package/dist/entity.cjs.map +1 -0
- package/dist/entity.js +165 -0
- package/dist/entity.js.map +1 -0
- package/dist/index.cjs +3333 -0
- package/dist/index.d.cts +2971 -0
- package/dist/index.d.ts +386 -338
- package/dist/index.js +247 -232
- package/dist/standard-schema.cjs +4 -0
- package/dist/standard-schema.cjs.map +1 -0
- package/dist/standard-schema.js +3 -0
- package/dist/standard-schema.js.map +1 -0
- package/dist/table.cjs +3265 -0
- package/dist/table.cjs.map +1 -0
- package/dist/table.js +3263 -0
- package/dist/table.js.map +1 -0
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/key-template.cjs +19 -0
- package/dist/utils/key-template.cjs.map +1 -0
- package/dist/utils/key-template.js +17 -0
- package/dist/utils/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.js +17 -0
- package/dist/utils/sort-key-template.js.map +1 -0
- package/package.json +24 -26
package/dist/index.js
CHANGED
|
@@ -365,30 +365,24 @@ var Paginator = class {
|
|
|
365
365
|
}
|
|
366
366
|
};
|
|
367
367
|
|
|
368
|
-
// src/builders/
|
|
369
|
-
var
|
|
370
|
-
keyCondition;
|
|
368
|
+
// src/builders/filter-builder.ts
|
|
369
|
+
var FilterBuilder = class {
|
|
371
370
|
options = {};
|
|
372
371
|
selectedFields = /* @__PURE__ */ new Set();
|
|
373
|
-
executor;
|
|
374
|
-
constructor(executor, keyCondition) {
|
|
375
|
-
this.executor = executor;
|
|
376
|
-
this.keyCondition = keyCondition;
|
|
377
|
-
}
|
|
378
372
|
/**
|
|
379
|
-
* Sets the maximum number of items to return
|
|
373
|
+
* Sets the maximum number of items to return.
|
|
380
374
|
* Use this method when you need to:
|
|
381
|
-
* - Limit the
|
|
382
|
-
* -
|
|
383
|
-
* -
|
|
375
|
+
* - Limit the number of dinosaurs returned
|
|
376
|
+
* - Control the size of habitat reports
|
|
377
|
+
* - Implement manual pagination of security logs
|
|
384
378
|
*
|
|
385
379
|
* Note: This limit applies to the items that match the key condition
|
|
386
380
|
* before any filter expressions are applied.
|
|
387
381
|
*
|
|
388
382
|
* @example
|
|
389
|
-
* ```
|
|
390
|
-
* // Get first 10
|
|
391
|
-
* const result = await
|
|
383
|
+
* ```typescript
|
|
384
|
+
* // Get first 10 dinosaurs
|
|
385
|
+
* const result = await builder
|
|
392
386
|
* .limit(10)
|
|
393
387
|
* .execute();
|
|
394
388
|
* ```
|
|
@@ -401,7 +395,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
401
395
|
return this;
|
|
402
396
|
}
|
|
403
397
|
/**
|
|
404
|
-
* Gets the current limit set on the
|
|
398
|
+
* Gets the current limit set on the operation.
|
|
405
399
|
* This is used internally by the paginator to manage result sets.
|
|
406
400
|
*
|
|
407
401
|
* @returns The current limit or undefined if no limit is set
|
|
@@ -410,41 +404,9 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
410
404
|
return this.options.limit;
|
|
411
405
|
}
|
|
412
406
|
/**
|
|
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.
|
|
407
|
+
* Specifies a Global Secondary Index (GSI) to use for the operation.
|
|
446
408
|
* Use this method when you need to:
|
|
447
|
-
* -
|
|
409
|
+
* - Find dinosaurs by species or status
|
|
448
410
|
* - Search habitats by security level
|
|
449
411
|
* - Find incidents by date
|
|
450
412
|
* - List feeding schedules by time
|
|
@@ -475,7 +437,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
475
437
|
return this;
|
|
476
438
|
}
|
|
477
439
|
/**
|
|
478
|
-
* Sets whether to use strongly consistent reads for the
|
|
440
|
+
* Sets whether to use strongly consistent reads for the operation.
|
|
479
441
|
* Use this method when you need to:
|
|
480
442
|
* - Get real-time dinosaur status updates
|
|
481
443
|
* - Monitor critical security systems
|
|
@@ -488,15 +450,15 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
488
450
|
* - Default is eventually consistent reads
|
|
489
451
|
*
|
|
490
452
|
* @example
|
|
491
|
-
* ```
|
|
453
|
+
* ```typescript
|
|
492
454
|
* // Check immediate dinosaur status
|
|
493
|
-
* const result = await
|
|
455
|
+
* const result = await builder
|
|
494
456
|
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
495
457
|
* .consistentRead()
|
|
496
458
|
* .execute();
|
|
497
459
|
*
|
|
498
460
|
* // Monitor security breaches
|
|
499
|
-
* const result = await
|
|
461
|
+
* const result = await builder
|
|
500
462
|
* .useIndex('primary-index')
|
|
501
463
|
* .consistentRead(isEmergencyMode)
|
|
502
464
|
* .execute();
|
|
@@ -510,35 +472,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
510
472
|
return this;
|
|
511
473
|
}
|
|
512
474
|
/**
|
|
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.
|
|
475
|
+
* Adds a filter expression to refine the operation results.
|
|
542
476
|
* Use this method when you need to:
|
|
543
477
|
* - Filter dinosaurs by behavior patterns
|
|
544
478
|
* - Find habitats with specific conditions
|
|
@@ -594,34 +528,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
594
528
|
return this;
|
|
595
529
|
}
|
|
596
530
|
/**
|
|
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.
|
|
531
|
+
* Specifies which attributes to return in the results.
|
|
625
532
|
* Use this method when you need to:
|
|
626
533
|
* - Get specific dinosaur attributes
|
|
627
534
|
* - Retrieve habitat statistics
|
|
@@ -663,11 +570,86 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
663
570
|
return this;
|
|
664
571
|
}
|
|
665
572
|
/**
|
|
666
|
-
*
|
|
573
|
+
* Creates a paginator that handles DynamoDB pagination automatically.
|
|
574
|
+
* The paginator handles:
|
|
575
|
+
* - Tracking the last evaluated key
|
|
576
|
+
* - Managing page boundaries
|
|
577
|
+
* - Respecting overall query limits
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* ```typescript
|
|
581
|
+
* // Create a paginator for dinosaur records
|
|
582
|
+
* const paginator = builder
|
|
583
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
584
|
+
* .paginate(10);
|
|
585
|
+
*
|
|
586
|
+
* // Process pages of dinosaur results
|
|
587
|
+
* while (paginator.hasNextPage()) {
|
|
588
|
+
* const page = await paginator.getNextPage();
|
|
589
|
+
* console.log(`Processing page ${page.page}, count: ${page.items.length}`);
|
|
590
|
+
* // Process dinosaur data
|
|
591
|
+
* }
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @param pageSize - The number of items to return per page
|
|
595
|
+
* @returns A Paginator instance that manages the pagination state
|
|
596
|
+
* @see Paginator for more pagination control options
|
|
597
|
+
*/
|
|
598
|
+
paginate(pageSize) {
|
|
599
|
+
return new Paginator(this, pageSize);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Sets the starting point using a previous lastEvaluatedKey.
|
|
667
603
|
* Use this method when you need to:
|
|
668
|
-
* -
|
|
669
|
-
* -
|
|
670
|
-
* -
|
|
604
|
+
* - Implement manual dinosaur list pagination
|
|
605
|
+
* - Resume habitat inspection reviews
|
|
606
|
+
* - Continue security incident analysis
|
|
607
|
+
* - Store operation position between sessions
|
|
608
|
+
*
|
|
609
|
+
* Note: This method is typically used for manual pagination.
|
|
610
|
+
* For automatic pagination, use the paginate() method instead.
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```typescript
|
|
614
|
+
* // First batch of dinosaurs
|
|
615
|
+
* const result1 = await builder
|
|
616
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
617
|
+
* .limit(5)
|
|
618
|
+
* .execute();
|
|
619
|
+
*
|
|
620
|
+
* if (result1.lastEvaluatedKey) {
|
|
621
|
+
* // Continue listing dinosaurs
|
|
622
|
+
* const result2 = await builder
|
|
623
|
+
* .filter(op => op.eq('status', 'ACTIVE'))
|
|
624
|
+
* .startFrom(result1.lastEvaluatedKey)
|
|
625
|
+
* .limit(5)
|
|
626
|
+
* .execute();
|
|
627
|
+
*
|
|
628
|
+
* console.log('Additional dinosaurs:', result2.items);
|
|
629
|
+
* }
|
|
630
|
+
* ```
|
|
631
|
+
*
|
|
632
|
+
* @param lastEvaluatedKey - The exclusive start key from a previous result
|
|
633
|
+
* @returns The builder instance for method chaining
|
|
634
|
+
*/
|
|
635
|
+
startFrom(lastEvaluatedKey) {
|
|
636
|
+
this.options.lastEvaluatedKey = lastEvaluatedKey;
|
|
637
|
+
return this;
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
|
|
641
|
+
// src/builders/query-builder.ts
|
|
642
|
+
var QueryBuilder = class _QueryBuilder extends FilterBuilder {
|
|
643
|
+
keyCondition;
|
|
644
|
+
options = {};
|
|
645
|
+
executor;
|
|
646
|
+
constructor(executor, keyCondition) {
|
|
647
|
+
super();
|
|
648
|
+
this.executor = executor;
|
|
649
|
+
this.keyCondition = keyCondition;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Sets the maximum number of items to return from the query.
|
|
671
653
|
*
|
|
672
654
|
* Note: This is the default behavior if no sort order is specified.
|
|
673
655
|
*
|
|
@@ -689,11 +671,6 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
689
671
|
*/
|
|
690
672
|
/**
|
|
691
673
|
* 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
674
|
*
|
|
698
675
|
* @example
|
|
699
676
|
* ```typescript
|
|
@@ -718,11 +695,6 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
718
695
|
}
|
|
719
696
|
/**
|
|
720
697
|
* 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
698
|
*
|
|
727
699
|
* @example
|
|
728
700
|
* ```typescript
|
|
@@ -747,92 +719,8 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
747
719
|
this.options.scanIndexForward = false;
|
|
748
720
|
return this;
|
|
749
721
|
}
|
|
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
722
|
/**
|
|
830
723
|
* 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
724
|
*
|
|
837
725
|
* This is particularly useful when:
|
|
838
726
|
* - Implementing pagination (used internally by paginate())
|
|
@@ -872,11 +760,6 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
872
760
|
}
|
|
873
761
|
/**
|
|
874
762
|
* 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
763
|
*
|
|
881
764
|
* The method returns both the matched items and, if there are more results,
|
|
882
765
|
* a lastEvaluatedKey that can be used with startFrom() to continue the query.
|
|
@@ -967,13 +850,16 @@ function debugCommand(command) {
|
|
|
967
850
|
// src/builders/put-builder.ts
|
|
968
851
|
var PutBuilder = class {
|
|
969
852
|
item;
|
|
970
|
-
options
|
|
853
|
+
options;
|
|
971
854
|
executor;
|
|
972
855
|
tableName;
|
|
973
856
|
constructor(executor, item, tableName) {
|
|
974
857
|
this.executor = executor;
|
|
975
858
|
this.item = item;
|
|
976
859
|
this.tableName = tableName;
|
|
860
|
+
this.options = {
|
|
861
|
+
returnValues: "NONE"
|
|
862
|
+
};
|
|
977
863
|
}
|
|
978
864
|
/**
|
|
979
865
|
* Adds a condition that must be satisfied for the put operation to succeed.
|
|
@@ -1002,10 +888,6 @@ var PutBuilder = class {
|
|
|
1002
888
|
*/
|
|
1003
889
|
/**
|
|
1004
890
|
* 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
891
|
*
|
|
1010
892
|
* @example
|
|
1011
893
|
* ```typescript
|
|
@@ -1062,10 +944,11 @@ var PutBuilder = class {
|
|
|
1062
944
|
}
|
|
1063
945
|
/**
|
|
1064
946
|
* Sets whether to return the item's previous values (if it existed).
|
|
1065
|
-
*
|
|
1066
|
-
*
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
947
|
+
*
|
|
948
|
+
* @options
|
|
949
|
+
* - NONE: No return value
|
|
950
|
+
* - ALL_OLD: Returns the item's previous state if it existed, no read capacity units are consumed
|
|
951
|
+
* - CONSISTENT: (default) Performs a GET operation after the put to retrieve the item's new state
|
|
1069
952
|
*
|
|
1070
953
|
* @example
|
|
1071
954
|
* ```ts
|
|
@@ -1086,7 +969,7 @@ var PutBuilder = class {
|
|
|
1086
969
|
* }
|
|
1087
970
|
* ```
|
|
1088
971
|
*
|
|
1089
|
-
* @param returnValues - Use 'ALL_OLD' to return previous values, or 'NONE' (default)
|
|
972
|
+
* @param returnValues - Use 'ALL_OLD' to return previous values if the item was overwritten, or 'NONE' (default).
|
|
1090
973
|
* @returns The builder instance for method chaining
|
|
1091
974
|
*/
|
|
1092
975
|
returnValues(returnValues) {
|
|
@@ -1174,11 +1057,6 @@ var PutBuilder = class {
|
|
|
1174
1057
|
/**
|
|
1175
1058
|
* Gets a human-readable representation of the put command
|
|
1176
1059
|
* 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
1060
|
*
|
|
1183
1061
|
* @example
|
|
1184
1062
|
* ```ts
|
|
@@ -2848,14 +2726,89 @@ var GetBuilder = class {
|
|
|
2848
2726
|
}
|
|
2849
2727
|
};
|
|
2850
2728
|
|
|
2729
|
+
// src/builders/scan-builder.ts
|
|
2730
|
+
var ScanBuilder = class _ScanBuilder extends FilterBuilder {
|
|
2731
|
+
executor;
|
|
2732
|
+
constructor(executor) {
|
|
2733
|
+
super();
|
|
2734
|
+
this.executor = executor;
|
|
2735
|
+
}
|
|
2736
|
+
/**
|
|
2737
|
+
* Creates a deep clone of this ScanBuilder instance.
|
|
2738
|
+
* Use this method when you need to:
|
|
2739
|
+
* - Create scan templates
|
|
2740
|
+
* - Run multiple variations of a scan
|
|
2741
|
+
* - Implement pagination (used internally by paginate())
|
|
2742
|
+
*
|
|
2743
|
+
* @returns A new ScanBuilder instance with the same configuration
|
|
2744
|
+
*/
|
|
2745
|
+
clone() {
|
|
2746
|
+
const clone = new _ScanBuilder(this.executor);
|
|
2747
|
+
clone.options = { ...this.options };
|
|
2748
|
+
clone.selectedFields = new Set(this.selectedFields);
|
|
2749
|
+
return clone;
|
|
2750
|
+
}
|
|
2751
|
+
/**
|
|
2752
|
+
* Executes the scan against DynamoDB.
|
|
2753
|
+
* Use this method when you need to:
|
|
2754
|
+
* - Search across the entire table
|
|
2755
|
+
* - Find items matching specific criteria
|
|
2756
|
+
* - Perform full table analysis
|
|
2757
|
+
* - Generate reports across all data
|
|
2758
|
+
*
|
|
2759
|
+
* The method returns both the matched items and, if there are more results,
|
|
2760
|
+
* a lastEvaluatedKey that can be used with startFrom() to continue the scan.
|
|
2761
|
+
*
|
|
2762
|
+
* @example
|
|
2763
|
+
* ```typescript
|
|
2764
|
+
* try {
|
|
2765
|
+
* // Find all dinosaurs with high aggression levels
|
|
2766
|
+
* const result = await new ScanBuilder(executor)
|
|
2767
|
+
* .filter(op =>
|
|
2768
|
+
* op.and([
|
|
2769
|
+
* op.eq('status', 'ACTIVE'),
|
|
2770
|
+
* op.gt('aggressionLevel', 7)
|
|
2771
|
+
* ])
|
|
2772
|
+
* )
|
|
2773
|
+
* .limit(20)
|
|
2774
|
+
* .execute();
|
|
2775
|
+
*
|
|
2776
|
+
* console.log(`Found ${result.items.length} potentially dangerous dinosaurs`);
|
|
2777
|
+
*
|
|
2778
|
+
* if (result.lastEvaluatedKey) {
|
|
2779
|
+
* console.log('More results available');
|
|
2780
|
+
* }
|
|
2781
|
+
* } catch (error) {
|
|
2782
|
+
* console.error('Security scan failed:', error);
|
|
2783
|
+
* }
|
|
2784
|
+
* ```
|
|
2785
|
+
*
|
|
2786
|
+
* @returns A promise that resolves to an object containing:
|
|
2787
|
+
* - items: Array of items matching the scan criteria
|
|
2788
|
+
* - lastEvaluatedKey: Token for continuing the scan, if more items exist
|
|
2789
|
+
*/
|
|
2790
|
+
async execute() {
|
|
2791
|
+
return this.executor(this.options);
|
|
2792
|
+
}
|
|
2793
|
+
};
|
|
2794
|
+
|
|
2851
2795
|
// src/table.ts
|
|
2852
2796
|
var DDB_BATCH_WRITE_LIMIT = 25;
|
|
2853
2797
|
var DDB_BATCH_GET_LIMIT = 100;
|
|
2854
2798
|
var Table = class {
|
|
2855
2799
|
dynamoClient;
|
|
2856
2800
|
tableName;
|
|
2801
|
+
/**
|
|
2802
|
+
* The column name of the partitionKey for the Table
|
|
2803
|
+
*/
|
|
2857
2804
|
partitionKey;
|
|
2805
|
+
/**
|
|
2806
|
+
* The column name of the sortKey for the Table
|
|
2807
|
+
*/
|
|
2858
2808
|
sortKey;
|
|
2809
|
+
/**
|
|
2810
|
+
* The Global Secondary Indexes that are configured on this table
|
|
2811
|
+
*/
|
|
2859
2812
|
gsis;
|
|
2860
2813
|
constructor(config) {
|
|
2861
2814
|
this.dynamoClient = config.client;
|
|
@@ -2902,15 +2855,29 @@ var Table = class {
|
|
|
2902
2855
|
put(item) {
|
|
2903
2856
|
const executor = async (params) => {
|
|
2904
2857
|
try {
|
|
2905
|
-
await this.dynamoClient.put({
|
|
2858
|
+
const result = await this.dynamoClient.put({
|
|
2906
2859
|
TableName: params.tableName,
|
|
2907
2860
|
Item: params.item,
|
|
2908
2861
|
ConditionExpression: params.conditionExpression,
|
|
2909
2862
|
ExpressionAttributeNames: params.expressionAttributeNames,
|
|
2910
2863
|
ExpressionAttributeValues: params.expressionAttributeValues,
|
|
2911
|
-
|
|
2864
|
+
// CONSISTENT is not a valid ReturnValue for DDB, so we set NONE as we are not interested in its
|
|
2865
|
+
// response and will be reloading the item from the DB through a get instead
|
|
2866
|
+
ReturnValues: params.returnValues === "CONSISTENT" ? "NONE" : params.returnValues
|
|
2912
2867
|
});
|
|
2913
|
-
|
|
2868
|
+
if (params.returnValues === "CONSISTENT") {
|
|
2869
|
+
const key = {
|
|
2870
|
+
pk: params.item[this.partitionKey],
|
|
2871
|
+
...this.sortKey && { sk: params.item[this.sortKey] }
|
|
2872
|
+
};
|
|
2873
|
+
const getResult = await this.dynamoClient.get({
|
|
2874
|
+
TableName: params.tableName,
|
|
2875
|
+
Key: key,
|
|
2876
|
+
ConsistentRead: true
|
|
2877
|
+
});
|
|
2878
|
+
return getResult.Item;
|
|
2879
|
+
}
|
|
2880
|
+
return result.Attributes;
|
|
2914
2881
|
} catch (error) {
|
|
2915
2882
|
console.error("Error creating item:", error);
|
|
2916
2883
|
throw error;
|
|
@@ -3036,6 +3003,54 @@ var Table = class {
|
|
|
3036
3003
|
};
|
|
3037
3004
|
return new QueryBuilder(executor, keyConditionExpression);
|
|
3038
3005
|
}
|
|
3006
|
+
/**
|
|
3007
|
+
* Creates a scan builder for scanning the entire table
|
|
3008
|
+
* Use this when you need to:
|
|
3009
|
+
* - Process all items in a table
|
|
3010
|
+
* - Apply filters to a large dataset
|
|
3011
|
+
* - Use a GSI for scanning
|
|
3012
|
+
*
|
|
3013
|
+
* @returns A ScanBuilder instance for chaining operations
|
|
3014
|
+
*/
|
|
3015
|
+
scan() {
|
|
3016
|
+
const executor = async (options) => {
|
|
3017
|
+
const expressionParams = {
|
|
3018
|
+
expressionAttributeNames: {},
|
|
3019
|
+
expressionAttributeValues: {},
|
|
3020
|
+
valueCounter: { count: 0 }
|
|
3021
|
+
};
|
|
3022
|
+
let filterExpression;
|
|
3023
|
+
if (options.filter) {
|
|
3024
|
+
filterExpression = buildExpression(options.filter, expressionParams);
|
|
3025
|
+
}
|
|
3026
|
+
const projectionExpression = options.projection?.map((p) => generateAttributeName(expressionParams, p)).join(", ");
|
|
3027
|
+
const { expressionAttributeNames, expressionAttributeValues } = expressionParams;
|
|
3028
|
+
const { indexName, limit, consistentRead, lastEvaluatedKey } = options;
|
|
3029
|
+
const params = {
|
|
3030
|
+
TableName: this.tableName,
|
|
3031
|
+
FilterExpression: filterExpression,
|
|
3032
|
+
ExpressionAttributeNames: Object.keys(expressionAttributeNames).length > 0 ? expressionAttributeNames : void 0,
|
|
3033
|
+
ExpressionAttributeValues: Object.keys(expressionAttributeValues).length > 0 ? expressionAttributeValues : void 0,
|
|
3034
|
+
IndexName: indexName,
|
|
3035
|
+
Limit: limit,
|
|
3036
|
+
ConsistentRead: consistentRead,
|
|
3037
|
+
ProjectionExpression: projectionExpression,
|
|
3038
|
+
ExclusiveStartKey: lastEvaluatedKey
|
|
3039
|
+
};
|
|
3040
|
+
try {
|
|
3041
|
+
const result = await this.dynamoClient.scan(params);
|
|
3042
|
+
return {
|
|
3043
|
+
items: result.Items,
|
|
3044
|
+
lastEvaluatedKey: result.LastEvaluatedKey
|
|
3045
|
+
};
|
|
3046
|
+
} catch (error) {
|
|
3047
|
+
console.log(debugCommand(params));
|
|
3048
|
+
console.error("Error scanning items:", error);
|
|
3049
|
+
throw error;
|
|
3050
|
+
}
|
|
3051
|
+
};
|
|
3052
|
+
return new ScanBuilder(executor);
|
|
3053
|
+
}
|
|
3039
3054
|
delete(keyCondition) {
|
|
3040
3055
|
const executor = async (params) => {
|
|
3041
3056
|
try {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"standard-schema.cjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"standard-schema.js"}
|