Skip to content

Fix expectedCount encoding in grpc #7087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/firestore/src/protos/firestore_proto_api.ts
Original file line number Diff line number Diff line change
@@ -399,7 +399,7 @@ export declare namespace firestoreV1ApiClientInterfaces {
readTime?: Timestamp;
targetId?: number;
once?: boolean;
expectedCount?: number;
expectedCount?: number | { value: number };
}
interface TargetChange {
targetChangeType?: TargetChangeTargetChangeType;
32 changes: 32 additions & 0 deletions packages/firestore/src/protos/protos.json
Original file line number Diff line number Diff line change
@@ -928,6 +928,30 @@
}
}
},
"BitSequence": {
"fields": {
"bitmap": {
"type": "bytes",
"id": 1
},
"padding": {
"type": "int32",
"id": 2
}
}
},
"BloomFilter": {
"fields": {
"bits": {
"type": "BitSequence",
"id": 1
},
"hashCount": {
"type": "int32",
"id": 2
}
}
},
"DocumentMask": {
"fields": {
"fieldPaths": {
@@ -2052,6 +2076,10 @@
"once": {
"type": "bool",
"id": 6
},
"expectedCount": {
"type": "google.protobuf.Int32Value",
"id": 12
}
},
"nested": {
@@ -2660,6 +2688,10 @@
"count": {
"type": "int32",
"id": 2
},
"unchangedNames": {
"type": "BloomFilter",
"id": 3
}
}
}
10 changes: 8 additions & 2 deletions packages/firestore/src/remote/serializer.ts
Original file line number Diff line number Diff line change
@@ -1051,7 +1051,10 @@ export function toTarget(

if (targetData.resumeToken.approximateByteSize() > 0) {
result.resumeToken = toBytes(serializer, targetData.resumeToken);
result.expectedCount = targetData.expectedCount ?? undefined;
const expectedCount = toInt32Proto(serializer, targetData.expectedCount);
if (expectedCount !== null) {
result.expectedCount = expectedCount;
}
} else if (targetData.snapshotVersion.compareTo(SnapshotVersion.min()) > 0) {
// TODO(wuandy): Consider removing above check because it is most likely true.
// Right now, many tests depend on this behaviour though (leaving min() out
@@ -1060,7 +1063,10 @@ export function toTarget(
serializer,
targetData.snapshotVersion.toTimestamp()
);
result.expectedCount = targetData.expectedCount ?? undefined;
const expectedCount = toInt32Proto(serializer, targetData.expectedCount);
if (expectedCount !== null) {
result.expectedCount = expectedCount;
}
}

return result;
3 changes: 1 addition & 2 deletions packages/firestore/test/unit/remote/serializer.helper.ts
Original file line number Diff line number Diff line change
@@ -1778,8 +1778,7 @@ export function serializerTest(
}
},
resumeToken: new Uint8Array([1, 2, 3]),
targetId: 1,
expectedCount: undefined
targetId: 1
};
expect(result).to.deep.equal(expected);
});