Skip to content

Commit b498867

Browse files
Merge master into release
2 parents b4d59d6 + ce88e71 commit b498867

19 files changed

+2062
-83
lines changed

.changeset/bright-avocados-attack.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/auth': patch
3+
---
4+
5+
Do not allow double slash at beginning of authTokenSyncURL. (follow-up fix to https://github.com/firebase/firebase-js-sdk/pull/8056)

.changeset/smart-games-cheer.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/firestore': minor
3+
'firebase': minor
4+
---
5+
Enable snapshot listener option to retrieve data from local cache only.

common/api-review/firestore.api.md

+4
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ export function limit(limit: number): QueryLimitConstraint;
350350
// @public
351351
export function limitToLast(limit: number): QueryLimitConstraint;
352352

353+
// @public
354+
export type ListenSource = 'default' | 'cache';
355+
353356
// @public
354357
export function loadBundle(firestore: Firestore, bundleData: ReadableStream<Uint8Array> | ArrayBuffer | string): LoadBundleTask;
355358

@@ -651,6 +654,7 @@ export function snapshotEqual<AppModelType, DbModelType extends DocumentData>(le
651654
// @public
652655
export interface SnapshotListenOptions {
653656
readonly includeMetadataChanges?: boolean;
657+
readonly source?: ListenSource;
654658
}
655659

656660
// @public

docs-devsite/firestore_.md

+13
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ https://github.com/firebase/firebase-js-sdk
204204
| [DocumentChangeType](./firestore_.md#documentchangetype) | The type of a <code>DocumentChange</code> may be 'added', 'removed', or 'modified'. |
205205
| [FirestoreErrorCode](./firestore_.md#firestoreerrorcode) | The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: https://github.com/grpc/grpc/blob/master/doc/statuscodes.md<!-- -->Possible values: - 'cancelled': The operation was cancelled (typically by the caller). - 'unknown': Unknown error or an error from a different error domain. - 'invalid-argument': Client specified an invalid argument. Note that this differs from 'failed-precondition'. 'invalid-argument' indicates arguments that are problematic regardless of the state of the system (e.g. an invalid field name). - 'deadline-exceeded': Deadline expired before operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. - 'not-found': Some requested document was not found. - 'already-exists': Some document that we attempted to create already exists. - 'permission-denied': The caller does not have permission to execute the specified operation. - 'resource-exhausted': Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. - 'failed-precondition': Operation was rejected because the system is not in a state required for the operation's execution. - 'aborted': The operation was aborted, typically due to a concurrency issue like transaction aborts, etc. - 'out-of-range': Operation was attempted past the valid range. - 'unimplemented': Operation is not implemented or not supported/enabled. - 'internal': Internal errors. Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken. - 'unavailable': The service is currently unavailable. This is most likely a transient condition and may be corrected by retrying with a backoff. - 'data-loss': Unrecoverable data loss or corruption. - 'unauthenticated': The request does not have valid authentication credentials for the operation. |
206206
| [FirestoreLocalCache](./firestore_.md#firestorelocalcache) | Union type from all supported SDK cache layer. |
207+
| [ListenSource](./firestore_.md#listensource) | Describe the source a query listens to.<!-- -->Set to <code>default</code> to listen to both cache and server changes. Set to <code>cache</code> to listen to changes in cache only. |
207208
| [MemoryGarbageCollector](./firestore_.md#memorygarbagecollector) | Union type from all support gabage collectors for memory local cache. |
208209
| [NestedUpdateFields](./firestore_.md#nestedupdatefields) | For each field (e.g. 'bar'), find all nested keys (e.g. {<!-- -->'bar.baz': T1, 'bar.qux': T2<!-- -->}<!-- -->). Intersect them together to make a single map containing all possible keys that are all marked as optional |
209210
| [OrderByDirection](./firestore_.md#orderbydirection) | The direction of a [orderBy()](./firestore_.md#orderby_006d61f) clause is specified as 'desc' or 'asc' (descending or ascending). |
@@ -2551,6 +2552,18 @@ Union type from all supported SDK cache layer.
25512552
export declare type FirestoreLocalCache = MemoryLocalCache | PersistentLocalCache;
25522553
```
25532554

2555+
## ListenSource
2556+
2557+
Describe the source a query listens to.
2558+
2559+
Set to `default` to listen to both cache and server changes. Set to `cache` to listen to changes in cache only.
2560+
2561+
<b>Signature:</b>
2562+
2563+
```typescript
2564+
export declare type ListenSource = 'default' | 'cache';
2565+
```
2566+
25542567
## MemoryGarbageCollector
25552568

25562569
Union type from all support gabage collectors for memory local cache.

docs-devsite/firestore_.snapshotlistenoptions.md

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export declare interface SnapshotListenOptions
2323
| Property | Type | Description |
2424
| --- | --- | --- |
2525
| [includeMetadataChanges](./firestore_.snapshotlistenoptions.md#snapshotlistenoptionsincludemetadatachanges) | boolean | Include a change even if only the metadata of the query or of a document changed. Default is false. |
26+
| [source](./firestore_.snapshotlistenoptions.md#snapshotlistenoptionssource) | [ListenSource](./firestore_.md#listensource) | Set the source the query listens to. Default to "default", which listens to both cache and server. |
2627

2728
## SnapshotListenOptions.includeMetadataChanges
2829

@@ -33,3 +34,13 @@ Include a change even if only the metadata of the query or of a document changed
3334
```typescript
3435
readonly includeMetadataChanges?: boolean;
3536
```
37+
38+
## SnapshotListenOptions.source
39+
40+
Set the source the query listens to. Default to "default", which listens to both cache and server.
41+
42+
<b>Signature:</b>
43+
44+
```typescript
45+
readonly source?: ListenSource;
46+
```

packages/auth/src/platform_browser/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ export function getAuth(app: FirebaseApp = getApp()): Auth {
9191

9292
const authTokenSyncPath = getExperimentalSetting('authTokenSyncURL');
9393
// Don't allow urls (XSS possibility), only paths on the same domain
94-
// (starting with '/')
95-
if (authTokenSyncPath && authTokenSyncPath.startsWith('/')) {
94+
// (starting with a single '/')
95+
if (authTokenSyncPath && authTokenSyncPath.match(/^\/[^\/].*/)) {
9696
const mintCookie = mintCookieFactory(authTokenSyncPath);
9797
beforeAuthStateChanged(auth, mintCookie, () =>
9898
mintCookie(auth.currentUser)

packages/firestore/src/api.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ export {
139139
WhereFilterOp
140140
} from './api/filter';
141141

142-
export { SnapshotListenOptions, Unsubscribe } from './api/reference_impl';
142+
export {
143+
ListenSource,
144+
SnapshotListenOptions,
145+
Unsubscribe
146+
} from './api/reference_impl';
143147

144148
export { TransactionOptions } from './api/transaction_options';
145149

packages/firestore/src/api/reference_impl.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
NextFn,
2525
PartialObserver
2626
} from '../api/observer';
27+
import { ListenerDataSource } from '../core/event_manager';
2728
import {
2829
firestoreClientAddSnapshotsInSyncListener,
2930
firestoreClientGetDocumentFromLocalCache,
@@ -78,8 +79,22 @@ export interface SnapshotListenOptions {
7879
* changed. Default is false.
7980
*/
8081
readonly includeMetadataChanges?: boolean;
82+
83+
/**
84+
* Set the source the query listens to. Default to "default", which
85+
* listens to both cache and server.
86+
*/
87+
readonly source?: ListenSource;
8188
}
8289

90+
/**
91+
* Describe the source a query listens to.
92+
*
93+
* Set to `default` to listen to both cache and server changes. Set to `cache`
94+
* to listen to changes in cache only.
95+
*/
96+
export type ListenSource = 'default' | 'cache';
97+
8398
/**
8499
* Reads the document referred to by this `DocumentReference`.
85100
*
@@ -668,7 +683,8 @@ export function onSnapshot<AppModelType, DbModelType extends DocumentData>(
668683
reference = getModularInstance(reference);
669684

670685
let options: SnapshotListenOptions = {
671-
includeMetadataChanges: false
686+
includeMetadataChanges: false,
687+
source: 'default'
672688
};
673689
let currArg = 0;
674690
if (typeof args[currArg] === 'object' && !isPartialObserver(args[currArg])) {
@@ -677,7 +693,8 @@ export function onSnapshot<AppModelType, DbModelType extends DocumentData>(
677693
}
678694

679695
const internalOptions = {
680-
includeMetadataChanges: options.includeMetadataChanges
696+
includeMetadataChanges: options.includeMetadataChanges,
697+
source: options.source as ListenerDataSource
681698
};
682699

683700
if (isPartialObserver(args[currArg])) {

0 commit comments

Comments
 (0)