@@ -22,7 +22,6 @@ import { KEY_INDEX } from '../snap/indexes/KeyIndex';
22
22
import { PathIndex } from '../snap/indexes/PathIndex' ;
23
23
import { PRIORITY_INDEX , PriorityIndex } from '../snap/indexes/PriorityIndex' ;
24
24
import { VALUE_INDEX } from '../snap/indexes/ValueIndex' ;
25
- import { predecessor , successor } from '../util/NextPushId' ;
26
25
import { MAX_NAME , MIN_NAME } from '../util/util' ;
27
26
28
27
import { IndexedFilter } from './filter/IndexedFilter' ;
@@ -36,8 +35,10 @@ import { RangedFilter } from './filter/RangedFilter';
36
35
const enum WIRE_PROTOCOL_CONSTANTS {
37
36
INDEX_START_VALUE = 'sp' ,
38
37
INDEX_START_NAME = 'sn' ,
38
+ INDEX_START_IS_INCLUSIVE = 'sin' ,
39
39
INDEX_END_VALUE = 'ep' ,
40
40
INDEX_END_NAME = 'en' ,
41
+ INDEX_END_IS_INCLUSIVE = 'ein' ,
41
42
LIMIT = 'l' ,
42
43
VIEW_FROM = 'vf' ,
43
44
VIEW_FROM_LEFT = 'l' ,
@@ -53,8 +54,10 @@ const enum REST_QUERY_CONSTANTS {
53
54
PRIORITY_INDEX = '$priority' ,
54
55
VALUE_INDEX = '$value' ,
55
56
KEY_INDEX = '$key' ,
57
+ START_AFTER = 'startAfter' ,
56
58
START_AT = 'startAt' ,
57
59
END_AT = 'endAt' ,
60
+ END_BEFORE = 'endBefore' ,
58
61
LIMIT_TO_FIRST = 'limitToFirst' ,
59
62
LIMIT_TO_LAST = 'limitToLast'
60
63
}
@@ -70,10 +73,10 @@ export class QueryParams {
70
73
limitSet_ = false ;
71
74
startSet_ = false ;
72
75
startNameSet_ = false ;
73
- startAfterSet_ = false ;
76
+ startAfterSet_ = false ; // can only be true if startSet_ is true
74
77
endSet_ = false ;
75
78
endNameSet_ = false ;
76
- endBeforeSet_ = false ;
79
+ endBeforeSet_ = false ; // can only be true if endSet_ is true
77
80
limit_ = 0 ;
78
81
viewFrom_ = '' ;
79
82
indexStartValue_ : unknown | null = null ;
@@ -86,14 +89,6 @@ export class QueryParams {
86
89
return this . startSet_ ;
87
90
}
88
91
89
- hasStartAfter ( ) : boolean {
90
- return this . startAfterSet_ ;
91
- }
92
-
93
- hasEndBefore ( ) : boolean {
94
- return this . endBeforeSet_ ;
95
- }
96
-
97
92
/**
98
93
* @returns True if it would return from left.
99
94
*/
@@ -191,10 +186,12 @@ export class QueryParams {
191
186
copy . limitSet_ = this . limitSet_ ;
192
187
copy . limit_ = this . limit_ ;
193
188
copy . startSet_ = this . startSet_ ;
189
+ copy . startAfterSet_ = this . startAfterSet_ ;
194
190
copy . indexStartValue_ = this . indexStartValue_ ;
195
191
copy . startNameSet_ = this . startNameSet_ ;
196
192
copy . indexStartName_ = this . indexStartName_ ;
197
193
copy . endSet_ = this . endSet_ ;
194
+ copy . endBeforeSet_ = this . endBeforeSet_ ;
198
195
copy . indexEndValue_ = this . indexEndValue_ ;
199
196
copy . endNameSet_ = this . endNameSet_ ;
200
197
copy . indexEndName_ = this . indexEndName_ ;
@@ -274,19 +271,10 @@ export function queryParamsStartAfter(
274
271
key ?: string | null
275
272
) : QueryParams {
276
273
let params : QueryParams ;
277
- if ( queryParams . index_ === KEY_INDEX ) {
278
- if ( typeof indexValue === 'string' ) {
279
- indexValue = successor ( indexValue as string ) ;
280
- }
274
+ if ( queryParams . index_ === KEY_INDEX || ! ! key ) {
281
275
params = queryParamsStartAt ( queryParams , indexValue , key ) ;
282
276
} else {
283
- let childKey : string ;
284
- if ( key == null ) {
285
- childKey = MAX_NAME ;
286
- } else {
287
- childKey = successor ( key ) ;
288
- }
289
- params = queryParamsStartAt ( queryParams , indexValue , childKey ) ;
277
+ params = queryParamsStartAt ( queryParams , indexValue , MAX_NAME ) ;
290
278
}
291
279
params . startAfterSet_ = true ;
292
280
return params ;
@@ -318,20 +306,11 @@ export function queryParamsEndBefore(
318
306
indexValue : unknown ,
319
307
key ?: string | null
320
308
) : QueryParams {
321
- let childKey : string ;
322
309
let params : QueryParams ;
323
- if ( queryParams . index_ === KEY_INDEX ) {
324
- if ( typeof indexValue === 'string' ) {
325
- indexValue = predecessor ( indexValue as string ) ;
326
- }
310
+ if ( queryParams . index_ === KEY_INDEX || ! ! key ) {
327
311
params = queryParamsEndAt ( queryParams , indexValue , key ) ;
328
312
} else {
329
- if ( key == null ) {
330
- childKey = MIN_NAME ;
331
- } else {
332
- childKey = predecessor ( key ) ;
333
- }
334
- params = queryParamsEndAt ( queryParams , indexValue , childKey ) ;
313
+ params = queryParamsEndAt ( queryParams , indexValue , MIN_NAME ) ;
335
314
}
336
315
params . endBeforeSet_ = true ;
337
316
return params ;
@@ -374,18 +353,22 @@ export function queryParamsToRestQueryStringParameters(
374
353
qs [ REST_QUERY_CONSTANTS . ORDER_BY ] = stringify ( orderBy ) ;
375
354
376
355
if ( queryParams . startSet_ ) {
377
- qs [ REST_QUERY_CONSTANTS . START_AT ] = stringify ( queryParams . indexStartValue_ ) ;
356
+ const startParam = queryParams . startAfterSet_
357
+ ? REST_QUERY_CONSTANTS . START_AFTER
358
+ : REST_QUERY_CONSTANTS . START_AT ;
359
+ qs [ startParam ] = stringify ( queryParams . indexStartValue_ ) ;
378
360
if ( queryParams . startNameSet_ ) {
379
- qs [ REST_QUERY_CONSTANTS . START_AT ] +=
380
- ',' + stringify ( queryParams . indexStartName_ ) ;
361
+ qs [ startParam ] += ',' + stringify ( queryParams . indexStartName_ ) ;
381
362
}
382
363
}
383
364
384
365
if ( queryParams . endSet_ ) {
385
- qs [ REST_QUERY_CONSTANTS . END_AT ] = stringify ( queryParams . indexEndValue_ ) ;
366
+ const endParam = queryParams . endBeforeSet_
367
+ ? REST_QUERY_CONSTANTS . END_BEFORE
368
+ : REST_QUERY_CONSTANTS . END_AT ;
369
+ qs [ endParam ] = stringify ( queryParams . indexEndValue_ ) ;
386
370
if ( queryParams . endNameSet_ ) {
387
- qs [ REST_QUERY_CONSTANTS . END_AT ] +=
388
- ',' + stringify ( queryParams . indexEndName_ ) ;
371
+ qs [ endParam ] += ',' + stringify ( queryParams . indexEndName_ ) ;
389
372
}
390
373
}
391
374
@@ -411,12 +394,16 @@ export function queryParamsGetQueryObject(
411
394
obj [ WIRE_PROTOCOL_CONSTANTS . INDEX_START_NAME ] =
412
395
queryParams . indexStartName_ ;
413
396
}
397
+ obj [ WIRE_PROTOCOL_CONSTANTS . INDEX_START_IS_INCLUSIVE ] =
398
+ ! queryParams . startAfterSet_ ;
414
399
}
415
400
if ( queryParams . endSet_ ) {
416
401
obj [ WIRE_PROTOCOL_CONSTANTS . INDEX_END_VALUE ] = queryParams . indexEndValue_ ;
417
402
if ( queryParams . endNameSet_ ) {
418
403
obj [ WIRE_PROTOCOL_CONSTANTS . INDEX_END_NAME ] = queryParams . indexEndName_ ;
419
404
}
405
+ obj [ WIRE_PROTOCOL_CONSTANTS . INDEX_END_IS_INCLUSIVE ] =
406
+ ! queryParams . endBeforeSet_ ;
420
407
}
421
408
if ( queryParams . limitSet_ ) {
422
409
obj [ WIRE_PROTOCOL_CONSTANTS . LIMIT ] = queryParams . limit_ ;
0 commit comments