@@ -733,6 +733,9 @@ class Entity {
733
733
let count = 0 ;
734
734
let hydratedUnprocessed = [ ] ;
735
735
const shouldHydrate = config . hydrate && method === MethodTypes . query ;
736
+ let allRawItems = [ ] ;
737
+ let indexHasHiddenComposites = ( this . model . lookup . indexHasHiddenComposites [ indexName ] || this . model . lookup . indexHasHiddenComposites [ TableIndex ] ) ;
738
+ let hasCountOption = typeof config . count === "number" ;
736
739
do {
737
740
let limit = max === undefined ? parameters . Limit : max - count ;
738
741
let response = await this . _exec (
@@ -747,6 +750,7 @@ class Entity {
747
750
...config ,
748
751
includeKeys : shouldHydrate || config . includeKeys ,
749
752
ignoreOwnership : shouldHydrate || config . ignoreOwnership ,
753
+ includeRaw : hasCountOption && indexHasHiddenComposites ,
750
754
} ) ;
751
755
752
756
if ( config . raw ) {
@@ -774,13 +778,16 @@ class Entity {
774
778
}
775
779
} else if ( Array . isArray ( response . data ) ) {
776
780
let prevCount = count
777
- if ( ! ! max || ! ! config . count ) {
781
+ if ( ! ! max || hasCountOption ) {
778
782
count += response . data . length ;
779
783
}
780
784
let items = response . data ;
781
- const moreItemsThanRequired = ! ! config . count && count > config . count ;
785
+ const moreItemsThanRequired = hasCountOption && count > config . count ;
786
+ let rawItems = response . raw || [ ] ;
782
787
if ( moreItemsThanRequired ) {
783
- items = items . slice ( 0 , config . count - prevCount ) ;
788
+ const endIndex = config . count - prevCount ;
789
+ items = items . slice ( 0 , endIndex ) ;
790
+ rawItems = rawItems . slice ( 0 , endIndex ) ;
784
791
}
785
792
if ( shouldHydrate ) {
786
793
const hydrated = await this . hydrate (
@@ -794,9 +801,10 @@ class Entity {
794
801
) ;
795
802
}
796
803
results = [ ...results , ...items ] ;
804
+ allRawItems = [ ...allRawItems , ...rawItems ] ;
797
805
if ( moreItemsThanRequired || count === config . count ) {
798
- const lastItem = results [ results . length - 1 ] ;
799
- ExclusiveStartKey = this . _fromCompositeToKeysByIndex ( { indexName, provided : lastItem } ) ;
806
+ const lastRawItem = rawItems [ rawItems . length - 1 ] ;
807
+ ExclusiveStartKey = this . _trimKeysToIndex ( { indexName, provided : lastRawItem } ) ;
800
808
break ;
801
809
}
802
810
} else {
@@ -955,6 +963,7 @@ class Entity {
955
963
stackTrace = new e . ElectroError ( e . ErrorCodes . AWSError ) ;
956
964
}
957
965
try {
966
+ let raw = { } ;
958
967
let results = { } ;
959
968
if ( validations . isFunction ( config . parse ) ) {
960
969
results = config . parse ( config , response ) ;
@@ -980,18 +989,24 @@ class Entity {
980
989
this . ownsKeys ( response . Item ) ) ||
981
990
this . ownsItem ( response . Item )
982
991
) {
992
+ if ( config . includeRaw ) {
993
+ raw = results . Item ;
994
+ }
983
995
results = this . model . schema . formatItemForRetrieval (
984
996
response . Item ,
985
997
config ,
986
998
) ;
987
999
if ( Object . keys ( results ) . length === 0 ) {
1000
+ raw = null ;
988
1001
results = null ;
989
1002
}
990
1003
} else if ( ! config . _objectOnEmpty ) {
1004
+ raw = null ;
991
1005
results = null ;
992
1006
}
993
1007
} else if ( response . Items ) {
994
1008
results = [ ] ;
1009
+ raw = [ ] ;
995
1010
for ( let item of response . Items ) {
996
1011
if (
997
1012
( config . ignoreOwnership &&
@@ -1008,6 +1023,9 @@ class Entity {
1008
1023
) ;
1009
1024
if ( Object . keys ( record ) . length > 0 ) {
1010
1025
results . push ( record ) ;
1026
+ if ( config . includeRaw ) {
1027
+ raw . push ( item ) ;
1028
+ }
1011
1029
}
1012
1030
}
1013
1031
}
@@ -1017,6 +1035,7 @@ class Entity {
1017
1035
config ,
1018
1036
) ;
1019
1037
if ( Object . keys ( results ) . length === 0 ) {
1038
+ raw = null ;
1020
1039
results = null ;
1021
1040
}
1022
1041
} else if ( config . _objectOnEmpty ) {
@@ -1027,18 +1046,28 @@ class Entity {
1027
1046
} ;
1028
1047
} else {
1029
1048
results = null ;
1049
+ raw = null ;
1030
1050
}
1031
1051
}
1032
1052
1053
+ let formatted = {
1054
+ data : results ,
1055
+ }
1056
+
1057
+ if ( config . includeRaw ) {
1058
+ formatted . raw = raw ;
1059
+ }
1060
+
1033
1061
if ( config . _isPagination || response . LastEvaluatedKey ) {
1034
1062
const nextPage = this . _formatReturnPager (
1035
1063
config ,
1036
1064
response . LastEvaluatedKey ,
1037
1065
) ;
1038
- return { cursor : nextPage || null , data : results } ;
1066
+
1067
+ formatted . cursor = nextPage || null ;
1039
1068
}
1040
1069
1041
- return { data : results } ;
1070
+ return formatted ;
1042
1071
} catch ( err ) {
1043
1072
if (
1044
1073
config . originalErr ||
@@ -4044,7 +4073,7 @@ class Entity {
4044
4073
}
4045
4074
}
4046
4075
4047
- let definition = {
4076
+ let definition = {
4048
4077
pk,
4049
4078
sk,
4050
4079
hasSk,
@@ -4498,7 +4527,14 @@ class Entity {
4498
4527
getClient : ( ) => this . client ,
4499
4528
isRoot : true ,
4500
4529
} ) ;
4501
-
4530
+ const indexHasHiddenComposites = { } ;
4531
+ for ( let hiddenAttr of schema . hiddenAttributes . values ( ) ) {
4532
+ if ( facets . byAttr [ hiddenAttr ] ) {
4533
+ for ( const facet of facets . byAttr [ hiddenAttr ] ) {
4534
+ indexHasHiddenComposites [ facet . index ] = true ;
4535
+ }
4536
+ }
4537
+ }
4502
4538
let filters = this . _normalizeFilters ( model . filters ) ;
4503
4539
// todo: consider a rename
4504
4540
let prefixes = this . _normalizeKeyFixings ( {
@@ -4562,6 +4598,7 @@ class Entity {
4562
4598
clusteredIndexes,
4563
4599
indexHasSortKeys,
4564
4600
indexHasSubCollections,
4601
+ indexHasHiddenComposites,
4565
4602
} ,
4566
4603
translations : {
4567
4604
keys : indexField ,
0 commit comments