@@ -811,7 +811,40 @@ Please use the format 'prezzy' or '${instance.name}/tables/prezzy'.`);
811
811
} ;
812
812
813
813
if ( lastRowKey ) {
814
- TableUtils . spliceRanges ( ranges , lastRowKey ) ;
814
+ const lessThanOrEqualTo = ( lhs : string , rhs : string ) =>
815
+ ! TableUtils . greaterThan ( lhs , rhs ) ;
816
+
817
+ // Readjust and/or remove ranges based on previous valid row reads.
818
+ // Iterate backward since items may need to be removed.
819
+ for ( let index = ranges . length - 1 ; index >= 0 ; index -- ) {
820
+ const range = ranges [ index ] ;
821
+ const startValue = is . object ( range . start )
822
+ ? ( range . start as BoundData ) . value
823
+ : range . start ;
824
+ const endValue = is . object ( range . end )
825
+ ? ( range . end as BoundData ) . value
826
+ : range . end ;
827
+ const startKeyIsRead =
828
+ ! startValue ||
829
+ lessThanOrEqualTo ( startValue as string , lastRowKey as string ) ;
830
+ const endKeyIsNotRead =
831
+ ! endValue ||
832
+ ( endValue as Buffer ) . length === 0 ||
833
+ TableUtils . lessThan ( lastRowKey as string , endValue as string ) ;
834
+ if ( startKeyIsRead ) {
835
+ if ( endKeyIsNotRead ) {
836
+ // EndKey is not read, reset the range to start from lastRowKey open
837
+ range . start = {
838
+ value : lastRowKey ,
839
+ inclusive : false ,
840
+ } ;
841
+ } else {
842
+ // EndKey is read, remove this range
843
+ ranges . splice ( index , 1 ) ;
844
+ }
845
+ }
846
+ }
847
+
815
848
rowKeys = TableUtils . getRowKeys ( rowKeys , lastRowKey ) ;
816
849
817
850
// If there was a row limit in the original request and
0 commit comments