Skip to content

Commit 44df2b1

Browse files
committed
Extend syncpoint spec protocol
1 parent 4e3106c commit 44df2b1

File tree

4 files changed

+117
-14
lines changed

4 files changed

+117
-14
lines changed

packages/database/src/core/view/QueryParams.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ export class QueryParams {
7373
limitSet_=false;
7474
startSet_=false;
7575
startNameSet_=false;
76-
startAfterSet_=false;
76+
startAfterSet_=false;// can only be true if startSet_ is true
7777
endSet_=false;
7878
endNameSet_=false;
79-
endBeforeSet_=false;
79+
endBeforeSet_=false;// can only be true if endSet_ is true
8080
limit_=0;
8181
viewFrom_='';
8282
indexStartValue_: unknown|null=null;
@@ -89,14 +89,6 @@ export class QueryParams {
8989
returnthis.startSet_;
9090
}
9191

92-
hasStartAfter(): boolean{
93-
returnthis.startAfterSet_;
94-
}
95-
96-
hasEndBefore(): boolean{
97-
returnthis.endBeforeSet_;
98-
}
99-
10092
/**
10193
* @returns True if it would return from left.
10294
*/
@@ -128,6 +120,8 @@ export class QueryParams {
128120
assert(this.startSet_,'Only valid if start has been set');
129121
if(this.startNameSet_){
130122
returnthis.indexStartName_;
123+
}elseif(this.startAfterSet_){
124+
returnMAX_NAME;
131125
}else{
132126
returnMIN_NAME;
133127
}
@@ -153,6 +147,8 @@ export class QueryParams {
153147
assert(this.endSet_,'Only valid if end has been set');
154148
if(this.endNameSet_){
155149
returnthis.indexEndName_;
150+
}elseif(this.endBeforeSet_){
151+
returnMIN_NAME;
156152
}else{
157153
returnMAX_NAME;
158154
}

packages/database/src/core/view/filter/RangedFilter.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ export class RangedFilter implements NodeFilter {
3939

4040
privateendPost_: NamedNode;
4141

42+
privatestartIsInclusive_: boolean;
43+
44+
privateendIsInclusive_: boolean;
45+
4246
constructor(params: QueryParams){
4347
this.indexedFilter_=newIndexedFilter(params.getIndex());
4448
this.index_=params.getIndex();
4549
this.startPost_=RangedFilter.getStartPost_(params);
4650
this.endPost_=RangedFilter.getEndPost_(params);
51+
this.startIsInclusive_=!params.startAfterSet_;
52+
this.endIsInclusive_=!params.endBeforeSet_;
4753
}
4854

4955
getStartPost(): NamedNode{
@@ -55,10 +61,13 @@ export class RangedFilter implements NodeFilter {
5561
}
5662

5763
matches(node: NamedNode): boolean{
58-
return(
59-
this.index_.compare(this.getStartPost(),node)<=0&&
60-
this.index_.compare(node,this.getEndPost())<=0
61-
);
64+
constisWithinStart=this.startIsInclusive_
65+
? this.index_.compare(this.getStartPost(),node)<=0
66+
: this.index_.compare(this.getStartPost(),node)<0;
67+
constisWithinEnd=this.endIsInclusive_
68+
? this.index_.compare(node,this.getEndPost())<=0
69+
: this.index_.compare(node,this.getEndPost())<0;
70+
returnisWithinStart&&isWithinEnd;
6271
}
6372
updateChild(
6473
snap: Node,

packages/database/test/helpers/syncPointSpec.json

+92
Original file line numberDiff line numberDiff line change
@@ -4179,6 +4179,98 @@
41794179
}
41804180
]
41814181
},
4182+
{
4183+
"name": "Queries with startAfter and endBefore work",
4184+
"steps":
4185+
[
4186+
{
4187+
"type": "listen",
4188+
"path": "",
4189+
"params": {
4190+
"tag": 1,
4191+
"orderBy": "index",
4192+
"startAfter": { "index": 1 },
4193+
"endBefore": { "index": 10 }
4194+
},
4195+
"events": []
4196+
},
4197+
{
4198+
".comment": "update from server sends all data",
4199+
"type": "serverUpdate",
4200+
"path": "",
4201+
"data": {
4202+
"a": { "index": 0, "value": "a" },
4203+
"b": { "index": 2, "value": "b" },
4204+
"c": { "index": 9, "value": "c" },
4205+
"d": { "index": 11, "value": "d" }
4206+
},
4207+
"events": [
4208+
{
4209+
"path": "",
4210+
"type": "child_added",
4211+
"name": "b",
4212+
"prevName": null,
4213+
"data": { "index": 2, "value": "b" }
4214+
},
4215+
{
4216+
"path": "",
4217+
"type": "child_added",
4218+
"name": "c",
4219+
"prevName": null,
4220+
"data": { "index": 9, "value": "c" }
4221+
},
4222+
{
4223+
"path": "",
4224+
"type": "value",
4225+
"data": {
4226+
"b": { "index": 2, "value": "b" },
4227+
"c": { "index": 9, "value": "c" }
4228+
}
4229+
}
4230+
]
4231+
},
4232+
{
4233+
".comment": "update from server to move child c out of query",
4234+
"type": "serverUpdate",
4235+
"path": "c/index",
4236+
"data": 10,
4237+
"events": [
4238+
{
4239+
"path": "",
4240+
"type": "child_removed",
4241+
"name": "c",
4242+
"data": { "index": 9, "value": "c" }
4243+
},
4244+
{
4245+
"path": "",
4246+
"type": "value",
4247+
"data": {
4248+
"b": { "index": 2, "value": "b" }
4249+
}
4250+
}
4251+
]
4252+
},
4253+
{
4254+
".comment": "update from server to move child b out of window",
4255+
"type": "serverUpdate",
4256+
"path": "b/index",
4257+
"data": 1,
4258+
"events": [
4259+
{
4260+
"path": "",
4261+
"type": "child_removed",
4262+
"name": "b",
4263+
"data": { "index": 2, "value": "b" }
4264+
},
4265+
{
4266+
"path": "",
4267+
"type": "value",
4268+
"data": {}
4269+
}
4270+
]
4271+
}
4272+
]
4273+
},
41824274
{
41834275
"name": "Update to single child that moves out of window",
41844276
"steps":

packages/database/test/helpers/syncpoint-util.ts

+6
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ import {
3131
ref,
3232
limitToFirst,
3333
limitToLast,
34+
startAfter,
3435
startAt,
3536
equalTo,
3637
endAt,
38+
endBefore,
3739
orderByChild,
3840
orderByKey,
3941
orderByPriority
@@ -366,10 +368,14 @@ export class SyncPointTestParser {
366368
q=query(q,limitToFirst(paramValue));
367369
}elseif(paramName==='limitToLast'){
368370
q=query(q,limitToLast(paramValue));
371+
}elseif(paramName==='startAfter'){
372+
q=query(q,startAfter(paramValue.index,paramValue.name));
369373
}elseif(paramName==='startAt'){
370374
q=query(q,startAt(paramValue.index,paramValue.name));
371375
}elseif(paramName==='endAt'){
372376
q=query(q,endAt(paramValue.index,paramValue.name));
377+
}elseif(paramName==='endBefore'){
378+
q=query(q,endBefore(paramValue.index,paramValue.name));
373379
}elseif(paramName==='equalTo'){
374380
q=query(q,equalTo(paramValue.index,paramValue.name));
375381
}elseif(paramName==='orderBy'){

0 commit comments

Comments
 (0)
close