Skip to content

Commit de204ad

Browse files
Merge master into release
2 parents 47895fe + ca1b0c8 commit de204ad

35 files changed

+1017
-163
lines changed

.changeset/good-bears-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/database": patch
3+
---
4+
5+
Included experimental support for Deno

.changeset/happy-eels-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/auth": patch
3+
---
4+
5+
Fix proactive refresh logic in Auth when RTDB/Firestore/Storage are in use

.changeset/smart-plants-sparkle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/firestore': patch
3+
---
4+
5+
Fix FAILED_PRECONDITION when writing to a deleted document in a transaction (#5871)

.github/workflows/deploy-config.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Deploy Project Config
2+
3+
on: pull_request
4+
5+
# Detects if any project config files (rules or functions) have changed,
6+
# and deploys them to the test project used for CI if so.
7+
# Run this in its own workflow instead of as a step before each test
8+
# workflow to avoid too many deploys, possibly causing race conditions.
9+
# Since the build step of each test workflow takes a long time, this
10+
# this should finish before the tests begin running.
11+
12+
jobs:
13+
test:
14+
name: Deploy Firebase Project Rules and Functions
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout Repo
19+
uses: actions/checkout@master
20+
with:
21+
# This makes Actions fetch all Git history so run-changed script can diff properly.
22+
fetch-depth: 0
23+
- name: Set up Node (14)
24+
uses: actions/setup-node@v2
25+
with:
26+
node-version: 14.x
27+
- name: Yarn install
28+
run: yarn
29+
- name: Deploy project config if needed
30+
run: yarn ts-node scripts/ci-test/deploy-if-needed.ts
31+
env:
32+
FIREBASE_CLI_TOKEN: ${{secrets.FIREBASE_CLI_TOKEN}}

.github/workflows/test-changed-auth.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ jobs:
6363
- name: build
6464
run: yarn build:changed auth
6565
- name: Run tests on auth changed packages
66-
run: xvfb-run yarn --cwd packages/auth test:browser:unit
67-
env:
68-
BROWSERS: 'Firefox'
69-
- name: Run tests on auth-compat changed packages
70-
run: xvfb-run yarn --cwd packages/auth-compat test:browser:unit
66+
run: xvfb-run yarn test:changed auth
7167
env:
7268
BROWSERS: 'Firefox'

.github/workflows/test-changed-firestore.yml

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,62 @@ name: Test Firestore
33
on: pull_request
44

55
jobs:
6-
test:
7-
name: Test Firestore If Changed
6+
test-chrome:
7+
name: Test Firestore on Chrome and Node If Changed
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- name: Checkout Repo
12-
uses: actions/checkout@master
13-
with:
14-
# This makes Actions fetch all Git history so run-changed script can diff properly.
15-
fetch-depth: 0
16-
- name: Set up Node (14)
17-
uses: actions/setup-node@v2
18-
with:
19-
node-version: 14.x
20-
- name: install Chrome stable
21-
run: |
22-
sudo apt-get update
23-
sudo apt-get install google-chrome-stable
24-
- name: Bump Node memory limit
25-
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
26-
- name: Test setup and yarn install
27-
run: |
28-
cp config/ci.config.json config/project.json
29-
yarn
30-
- name: build
31-
run: yarn build:changed firestore
32-
- name: Run tests if firestore or its dependencies has changed
33-
run: yarn test:changed firestore
11+
- name: Checkout Repo
12+
uses: actions/checkout@master
13+
with:
14+
# This makes Actions fetch all Git history so run-changed script can diff properly.
15+
fetch-depth: 0
16+
- name: Set up Node (14)
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: 14.x
20+
- name: install Chrome stable
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install google-chrome-stable
24+
- name: Bump Node memory limit
25+
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
26+
- name: Test setup and yarn install
27+
run: |
28+
cp config/ci.config.json config/project.json
29+
yarn
30+
- name: build
31+
run: yarn build:changed firestore
32+
- name: Run tests if firestore or its dependencies has changed
33+
run: yarn test:changed firestore
34+
35+
test-firefox:
36+
name: Test Firestore on Firefox If Changed
37+
runs-on: ubuntu-latest
38+
39+
steps:
40+
- name: install Firefox stable
41+
run: |
42+
sudo apt-get update
43+
sudo apt-get install firefox
44+
- name: Checkout Repo
45+
uses: actions/checkout@master
46+
with:
47+
# This makes Actions fetch all Git history so run-changed script can diff properly.
48+
fetch-depth: 0
49+
- name: Set up Node (14)
50+
uses: actions/setup-node@v2
51+
with:
52+
node-version: 14.x
53+
- name: Bump Node memory limit
54+
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
55+
- name: Test setup and yarn install
56+
run: |
57+
cp config/ci.config.json config/project.json
58+
yarn
59+
- name: build
60+
run: yarn build:changed firestore
61+
- name: Run tests if firestore or its dependencies has changed
62+
run: xvfb-run yarn test:changed firestore
63+
env:
64+
BROWSERS: 'Firefox'

common/api-review/firestore-lite.api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ export function getDoc<T>(reference: DocumentReference<T>): Promise<DocumentSnap
176176
export function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
177177

178178
// @public
179-
export function getFirestore(app?: FirebaseApp): Firestore;
179+
export function getFirestore(): Firestore;
180+
181+
// @public
182+
export function getFirestore(app: FirebaseApp): Firestore;
180183

181184
// @public
182185
export function increment(n: number): FieldValue;

common/api-review/firestore.api.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,16 @@ export function getDocsFromCache<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
228228
export function getDocsFromServer<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
229229

230230
// @public
231-
export function getFirestore(app?: FirebaseApp): Firestore;
231+
export function getFirestore(): Firestore;
232+
233+
// @public
234+
export function getFirestore(app: FirebaseApp): Firestore;
232235

233236
// @public
234237
export function increment(n: number): FieldValue;
235238

236239
// @public
237-
export function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings): Firestore;
240+
export function initializeFirestore(app: FirebaseApp, settings: FirestoreSettings, databaseId?: string): Firestore;
238241

239242
// @public
240243
export function limit(limit: number): QueryConstraint;

integration/firestore/firebase_export.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,25 @@ import {
2727

2828
let appCount = 0;
2929

30+
export function newTestApp(projectId: string, appName?: string): FirebaseApp {
31+
if (appName === undefined) {
32+
appName = 'test-app-' + appCount++;
33+
}
34+
return initializeApp(
35+
{
36+
apiKey: 'fake-api-key',
37+
projectId
38+
},
39+
appName
40+
);
41+
}
42+
3043
export function newTestFirestore(
31-
projectId: string,
32-
nameOrApp?: string | FirebaseApp,
33-
settings?: FirestoreSettings
44+
app: FirebaseApp,
45+
settings?: FirestoreSettings,
46+
dbName?: string
3447
): Firestore {
35-
if (nameOrApp === undefined) {
36-
nameOrApp = 'test-app-' + appCount++;
37-
}
38-
const app =
39-
typeof nameOrApp === 'string'
40-
? initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
41-
: nameOrApp;
42-
return initializeFirestore(app, settings || {});
48+
return initializeFirestore(app, settings || {}, dbName);
4349
}
4450

4551
export * from '@firebase/firestore';

packages/auth/src/core/auth/auth_impl.test.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,65 @@ describe('core/auth/auth_impl', () => {
306306
});
307307
});
308308

309+
context('with Proactive Refresh', () => {
310+
let oldUser: UserInternal;
311+
312+
beforeEach(() => {
313+
oldUser = testUser(auth, 'old-user-uid');
314+
315+
for (const u of [user, oldUser]) {
316+
sinon.spy(u, '_startProactiveRefresh');
317+
sinon.spy(u, '_stopProactiveRefresh');
318+
}
319+
});
320+
321+
it('null -> user: does not turn on if not enabled', async () => {
322+
await auth._updateCurrentUser(null);
323+
await auth._updateCurrentUser(user);
324+
325+
expect(user._startProactiveRefresh).not.to.have.been.called;
326+
});
327+
328+
it('null -> user: turns on if enabled', async () => {
329+
await auth._updateCurrentUser(null);
330+
auth._startProactiveRefresh();
331+
await auth._updateCurrentUser(user);
332+
333+
expect(user._startProactiveRefresh).to.have.been.called;
334+
});
335+
336+
it('user -> user: does not turn on if not enabled', async () => {
337+
await auth._updateCurrentUser(oldUser);
338+
await auth._updateCurrentUser(user);
339+
340+
expect(user._startProactiveRefresh).not.to.have.been.called;
341+
});
342+
343+
it('user -> user: turns on if enabled', async () => {
344+
auth._startProactiveRefresh();
345+
await auth._updateCurrentUser(oldUser);
346+
await auth._updateCurrentUser(user);
347+
348+
expect(oldUser._stopProactiveRefresh).to.have.been.called;
349+
expect(user._startProactiveRefresh).to.have.been.called;
350+
});
351+
352+
it('calling start on auth triggers user to start', async () => {
353+
await auth._updateCurrentUser(user);
354+
auth._startProactiveRefresh();
355+
356+
expect(user._startProactiveRefresh).to.have.been.calledOnce;
357+
});
358+
359+
it('calling stop stops the refresh on the current user', async () => {
360+
auth._startProactiveRefresh();
361+
await auth._updateCurrentUser(user);
362+
auth._stopProactiveRefresh();
363+
364+
expect(user._stopProactiveRefresh).to.have.been.called;
365+
});
366+
});
367+
309368
it('onAuthStateChange works for multiple listeners', async () => {
310369
const cb1 = sinon.spy();
311370
const cb2 = sinon.spy();

packages/auth/src/core/auth/auth_impl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,9 @@ export class AuthImpl implements AuthInternal, _FirebaseService {
581581
): Promise<void> {
582582
if (this.currentUser && this.currentUser !== user) {
583583
this._currentUser._stopProactiveRefresh();
584-
if (user && this.isProactiveRefreshEnabled) {
585-
user._startProactiveRefresh();
586-
}
584+
}
585+
if (user && this.isProactiveRefreshEnabled) {
586+
user._startProactiveRefresh();
587587
}
588588

589589
this.currentUser = user;

packages/database/src/core/util/util.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,21 @@ export const setTimeoutNonBlocking = function (
618618
time: number
619619
): number | object {
620620
const timeout: number | object = setTimeout(fn, time);
621-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
622-
if (typeof timeout === 'object' && (timeout as any)['unref']) {
621+
// Note: at the time of this comment, unrefTimer is under the unstable set of APIs. Run with --unstable to enable the API.
622+
if (
623+
typeof timeout === 'number' &&
624+
// @ts-ignore Is only defined in Deno environments.
625+
typeof Deno !== 'undefined' &&
626+
// @ts-ignore Deno and unrefTimer are only defined in Deno environments.
627+
Deno['unrefTimer']
628+
) {
629+
// @ts-ignore Deno and unrefTimer are only defined in Deno environments.
630+
Deno.unrefTimer(timeout);
631+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
632+
} else if (typeof timeout === 'object' && (timeout as any)['unref']) {
623633
// eslint-disable-next-line @typescript-eslint/no-explicit-any
624634
(timeout as any)['unref']();
625635
}
636+
626637
return timeout;
627638
};

packages/database/test/deno.test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { expect, use } from 'chai';
19+
import * as sinon from 'sinon';
20+
import sinonChai from 'sinon-chai';
21+
22+
import { setTimeoutNonBlocking } from '../src/core/util/util';
23+
use(sinonChai);
24+
describe('Deno tests', () => {
25+
let oldSetTimeout;
26+
beforeEach(() => {
27+
oldSetTimeout = globalThis.setTimeout;
28+
});
29+
afterEach(() => {
30+
globalThis.setTimeout = oldSetTimeout;
31+
});
32+
it('should call the deno unrefTimer() if in Deno', () => {
33+
// @ts-ignore override nodejs behavior
34+
global.Deno = {
35+
unrefTimer: sinon.spy()
36+
};
37+
// @ts-ignore override nodejs behavior
38+
global.setTimeout = () => 1;
39+
setTimeoutNonBlocking(() => {}, 0);
40+
expect(globalThis.Deno.unrefTimer).to.have.been.called;
41+
});
42+
it('should not call the deno unrefTimer() if not in Deno', () => {
43+
// @ts-ignore override nodejs behavior
44+
global.Deno2 = {
45+
unrefTimer: sinon.spy()
46+
};
47+
// @ts-ignore override node.js behavior
48+
global.setTimeout = () => 1;
49+
setTimeoutNonBlocking(() => {}, 0);
50+
expect(globalThis.Deno2.unrefTimer).to.not.have.been.called;
51+
});
52+
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ export class Firestore extends FirestoreCompat {
9191
super(
9292
databaseIdFromFirestoreDatabase(firestoreDatabase),
9393
new FirestoreExp(
94-
databaseIdFromFirestoreDatabase(firestoreDatabase),
9594
new _EmptyAuthCredentialsProvider(),
96-
new _EmptyAppCheckTokenProvider()
95+
new _EmptyAppCheckTokenProvider(),
96+
databaseIdFromFirestoreDatabase(firestoreDatabase)
9797
),
9898
new MemoryPersistenceProvider()
9999
);

0 commit comments

Comments
 (0)