@@ -156,7 +156,10 @@ export class SlateDBKVStore implements AsyncDisposable {
156156 }
157157 }
158158
159- scanPrefix < T = unknown > ( prefix : SlateDBKey , options ?: { limit ?: number } ) : AsyncIterable < SlateDBEntry < T > > {
159+ scanPrefix < T = unknown > (
160+ prefix : SlateDBKey ,
161+ options ?: { limit ?: number ; startAfter ?: SlateDBKey ; endAt ?: SlateDBKey }
162+ ) : AsyncIterable < SlateDBEntry < T > > {
160163 return scanPrefixFrom < T > ( this . db , prefix , options ) ;
161164 }
162165
@@ -269,7 +272,10 @@ export class SlateDBCheckpointReader {
269272 return getFrom < T > ( this . reader , key ) ;
270273 }
271274
272- scanPrefix < T = unknown > ( prefix : SlateDBKey , options ?: { limit ?: number } ) : AsyncIterable < SlateDBEntry < T > > {
275+ scanPrefix < T = unknown > (
276+ prefix : SlateDBKey ,
277+ options ?: { limit ?: number ; startAfter ?: SlateDBKey ; endAt ?: SlateDBKey }
278+ ) : AsyncIterable < SlateDBEntry < T > > {
273279 return scanPrefixFrom < T > ( this . reader , prefix , options ) ;
274280 }
275281}
@@ -306,9 +312,9 @@ async function getFrom<T>(reader: SlateDBReadable, key: SlateDBKey): Promise<T |
306312async function * scanPrefixFrom < T > (
307313 reader : SlateDBReadable ,
308314 prefix : SlateDBKey ,
309- options : { limit ?: number } = { }
315+ options : { limit ?: number ; startAfter ?: SlateDBKey ; endAt ?: SlateDBKey } = { }
310316) : AsyncIterable < SlateDBEntry < T > > {
311- const iterator = await reader . scan_prefix ( toKeyBytes ( prefix ) , unboundedRange ( ) ) ;
317+ const iterator = await reader . scan_prefix ( toKeyBytes ( prefix ) , scanRange ( options ) ) ;
312318 try {
313319 let count = 0 ;
314320 while ( options . limit == null || count < options . limit ) {
@@ -332,12 +338,12 @@ function toKeyBytes(key: SlateDBKey): Uint8Array {
332338 return typeof key == 'string' ? textEncoder . encode ( key ) : key ;
333339}
334340
335- function unboundedRange ( ) : KeyRange {
341+ function scanRange ( options : { startAfter ?: SlateDBKey ; endAt ?: SlateDBKey } ) : KeyRange {
336342 return {
337- start : undefined ,
343+ start : options . startAfter == null ? undefined : toKeyBytes ( options . startAfter ) ,
338344 start_inclusive : false ,
339- end : undefined ,
340- end_inclusive : false
345+ end : options . endAt == null ? undefined : toKeyBytes ( options . endAt ) ,
346+ end_inclusive : true
341347 } ;
342348}
343349
0 commit comments