Skip to content

Commit

Permalink
Merge master into release
Browse files Browse the repository at this point in the history
  • Loading branch information
google-oss-bot authored Mar 12, 2024
2 parents b4d59d6 + ce88e71 commit b498867
Show file tree
Hide file tree
Showing 19 changed files with 2,062 additions and 83 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-avocados-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/auth': patch
---

Do not allow double slash at beginning of authTokenSyncURL. (follow-up fix to https://github.com/firebase/firebase-js-sdk/pull/8056)
5 changes: 5 additions & 0 deletions .changeset/smart-games-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/firestore': minor
'firebase': minor
---
Enable snapshot listener option to retrieve data from local cache only.
4 changes: 4 additions & 0 deletions common/api-review/firestore.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ export function limit(limit: number): QueryLimitConstraint;
// @public
export function limitToLast(limit: number): QueryLimitConstraint;

// @public
export type ListenSource = 'default' | 'cache';

// @public
export function loadBundle(firestore: Firestore, bundleData: ReadableStream<Uint8Array> | ArrayBuffer | string): LoadBundleTask;

Expand Down Expand Up @@ -651,6 +654,7 @@ export function snapshotEqual<AppModelType, DbModelType extends DocumentData>(le
// @public
export interface SnapshotListenOptions {
readonly includeMetadataChanges?: boolean;
readonly source?: ListenSource;
}

// @public
Expand Down
13 changes: 13 additions & 0 deletions docs-devsite/firestore_.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ https://github.com/firebase/firebase-js-sdk
| [DocumentChangeType](./firestore_.md#documentchangetype) | The type of a <code>DocumentChange</code> may be 'added', 'removed', or 'modified'. |
| [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. |
| [FirestoreLocalCache](./firestore_.md#firestorelocalcache) | Union type from all supported SDK cache layer. |
| [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. |
| [MemoryGarbageCollector](./firestore_.md#memorygarbagecollector) | Union type from all support gabage collectors for memory local cache. |
| [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 |
| [OrderByDirection](./firestore_.md#orderbydirection) | The direction of a [orderBy()](./firestore_.md#orderby_006d61f) clause is specified as 'desc' or 'asc' (descending or ascending). |
Expand Down Expand Up @@ -2551,6 +2552,18 @@ Union type from all supported SDK cache layer.
export declare type FirestoreLocalCache = MemoryLocalCache | PersistentLocalCache;
```

## ListenSource

Describe the source a query listens to.

Set to `default` to listen to both cache and server changes. Set to `cache` to listen to changes in cache only.

<b>Signature:</b>

```typescript
export declare type ListenSource = 'default' | 'cache';
```

## MemoryGarbageCollector

Union type from all support gabage collectors for memory local cache.
Expand Down
11 changes: 11 additions & 0 deletions docs-devsite/firestore_.snapshotlistenoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export declare interface SnapshotListenOptions
| Property | Type | Description |
| --- | --- | --- |
| [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. |
| [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. |

## SnapshotListenOptions.includeMetadataChanges

Expand All @@ -33,3 +34,13 @@ Include a change even if only the metadata of the query or of a document changed
```typescript
readonly includeMetadataChanges?: boolean;
```

## SnapshotListenOptions.source

Set the source the query listens to. Default to "default", which listens to both cache and server.

<b>Signature:</b>

```typescript
readonly source?: ListenSource;
```
4 changes: 2 additions & 2 deletions packages/auth/src/platform_browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export function getAuth(app: FirebaseApp = getApp()): Auth {

const authTokenSyncPath = getExperimentalSetting('authTokenSyncURL');
// Don't allow urls (XSS possibility), only paths on the same domain
// (starting with '/')
if (authTokenSyncPath && authTokenSyncPath.startsWith('/')) {
// (starting with a single '/')
if (authTokenSyncPath && authTokenSyncPath.match(/^\/[^\/].*/)) {
const mintCookie = mintCookieFactory(authTokenSyncPath);
beforeAuthStateChanged(auth, mintCookie, () =>
mintCookie(auth.currentUser)
Expand Down
6 changes: 5 additions & 1 deletion packages/firestore/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ export {
WhereFilterOp
} from './api/filter';

export { SnapshotListenOptions, Unsubscribe } from './api/reference_impl';
export {
ListenSource,
SnapshotListenOptions,
Unsubscribe
} from './api/reference_impl';

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

Expand Down
21 changes: 19 additions & 2 deletions packages/firestore/src/api/reference_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
NextFn,
PartialObserver
} from '../api/observer';
import { ListenerDataSource } from '../core/event_manager';
import {
firestoreClientAddSnapshotsInSyncListener,
firestoreClientGetDocumentFromLocalCache,
Expand Down Expand Up @@ -78,8 +79,22 @@ export interface SnapshotListenOptions {
* changed. Default is false.
*/
readonly includeMetadataChanges?: boolean;

/**
* Set the source the query listens to. Default to "default", which
* listens to both cache and server.
*/
readonly source?: ListenSource;
}

/**
* Describe the source a query listens to.
*
* Set to `default` to listen to both cache and server changes. Set to `cache`
* to listen to changes in cache only.
*/
export type ListenSource = 'default' | 'cache';

/**
* Reads the document referred to by this `DocumentReference`.
*
Expand Down Expand Up @@ -668,7 +683,8 @@ export function onSnapshot<AppModelType, DbModelType extends DocumentData>(
reference = getModularInstance(reference);

let options: SnapshotListenOptions = {
includeMetadataChanges: false
includeMetadataChanges: false,
source: 'default'
};
let currArg = 0;
if (typeof args[currArg] === 'object' && !isPartialObserver(args[currArg])) {
Expand All @@ -677,7 +693,8 @@ export function onSnapshot<AppModelType, DbModelType extends DocumentData>(
}

const internalOptions = {
includeMetadataChanges: options.includeMetadataChanges
includeMetadataChanges: options.includeMetadataChanges,
source: options.source as ListenerDataSource
};

if (isPartialObserver(args[currArg])) {
Expand Down
Loading

0 comments on commit b498867

Please sign in to comment.