Skip to content

Commit 397317b

Browse files
authored
Make COUNT queries available to the Firestore Console (#6643)
1 parent 9799efe commit 397317b

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

.changeset/metal-goats-unite.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@firebase/firestore': minor
3+
'@firebase/firestore-compat': minor
4+
'@firebase/webchannel-wrapper': minor
5+
'firebase': minor
6+
---
7+
8+
Set withCredentials=true when making requests via non-streaming RPCs, like is done for streaming RPCs.

packages/firestore-compat/src/index.console.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ import {
2222
Firestore as FirestoreExp,
2323
FirestoreError,
2424
_EmptyAuthCredentialsProvider,
25-
_EmptyAppCheckTokenProvider
25+
_EmptyAppCheckTokenProvider,
26+
Query as ExpQuery,
27+
getCountFromServer
2628
} from '@firebase/firestore';
29+
import { Compat } from '@firebase/util';
2730

2831
import {
2932
Firestore as FirestoreCompat,
@@ -98,6 +101,15 @@ export class Firestore extends FirestoreCompat {
98101
new MemoryPersistenceProvider()
99102
);
100103
}
104+
105+
INTERNAL = {
106+
delete: () => this.terminate(),
107+
count: (query: Compat<ExpQuery<unknown>>) => {
108+
return getCountFromServer(query._delegate).then(response => {
109+
return response.data().count;
110+
});
111+
}
112+
};
101113
}
102114

103115
function databaseIdFromFirestoreDatabase(

packages/firestore/src/platform/browser/webchannel_connection.ts

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class WebChannelConnection extends RestConnection {
7272
): Promise<Resp> {
7373
return new Promise((resolve: Resolver<Resp>, reject: Rejecter) => {
7474
const xhr = new XhrIo();
75+
xhr.setWithCredentials(true);
7576
xhr.listenOnce(EventType.COMPLETE, () => {
7677
try {
7778
switch (xhr.getLastErrorCode()) {

packages/webchannel-wrapper/src/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export class XhrIo {
7474
getResponseJson(): WebChannelError | object;
7575

7676
listenOnce(type: string, cb: (param: unknown) => void): void;
77+
78+
setWithCredentials(withCredentials: boolean): void;
7779
}
7880

7981
export interface WebChannelOptions {

packages/webchannel-wrapper/src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ goog.net.XhrIo.prototype['getResponseJson'] =
7575
goog.net.XhrIo.prototype['getResponseText'] =
7676
goog.net.XhrIo.prototype.getResponseText;
7777
goog.net.XhrIo.prototype['send'] = goog.net.XhrIo.prototype.send;
78+
goog.net.XhrIo.prototype['setWithCredentials'] =
79+
goog.net.XhrIo.prototype.setWithCredentials;
7880

7981
module['exports']['createWebChannelTransport'] =
8082
goog.net.createWebChannelTransport;

0 commit comments

Comments
 (0)