Skip to content

Commit 757e62e

Browse files
committed
Merge branch 'master' into varconst/geo-point-to-json
2 parents da4e02d + 4e09c70 commit 757e62e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1664
-166
lines changed

.changeset/cold-bats-hammer.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@firebase/rules-unit-testing': major
3+
---
4+
5+
Release `@firebase/rules-unit-testing` to replace the `@firebase/testing` package. The new
6+
package is API compatible but has the following breaking behavior changes:
7+
8+
* `assertFails()` will now only fail on `PERMISSION DENIED` errors, not any error.
9+
* `initializeAdminApp()` now relies on `firebase-admin` rather than imitating the Admin SDK.

.changeset/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@firebase/app-types-exp",
1818
"@firebase/functions-exp",
1919
"@firebase/functions-types-exp",
20+
"@firebase/testing",
2021
"firebase-exp",
2122
"@firebase/changelog-generator",
2223
"firebase-size-analysis"
@@ -25,4 +26,4 @@
2526
"onlyUpdatePeerDependentsWhenOutOfRange": true,
2627
"useCalculatedVersionForSnapshots": true
2728
}
28-
}
29+
}

.changeset/neat-gorillas-behave.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+
`terminate()` can now be retried if it fails with an IndexedDB exception.

.github/CODEOWNERS

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ packages/auth-types @bojeil-google @avolkovi @samhorlbeck @scottcrossen @fireba
6060

6161
# Testing Code
6262
packages/testing @avolkovi @samhorlbeck @scottcrossen @yuchenshi @firebase/jssdk-global-approvers
63+
packages/rules-unit-testing @avolkovi @samhorlbeck @scottcrossen @yuchenshi @firebase/jssdk-global-approvers
6364

6465
# RxFire Code
6566
packages/rxfire @davideast @jamesdaniels @firebase/jssdk-global-approvers
6667

6768
# Installations
68-
packages/installations @andirayo @firebase/jssdk-global-approvers
69-
packages/installations-types @andirayo @firebase/jssdk-global-approvers
69+
packages/installations @andirayo @ChaoqunCHEN @firebase/jssdk-global-approvers
70+
packages/installations-types @andirayo @ChaoqunCHEN @firebase/jssdk-global-approvers
7071

7172
# Performance Code
7273
packages/performance @alikn @zijianjoy @firebase/jssdk-global-approvers

.github/workflows/check-changeset.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Check Changeset
2+
3+
on: pull_request
4+
5+
jobs:
6+
check_changeset:
7+
name: Check changeset vs changed files
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout Repo
12+
uses: actions/checkout@master
13+
with:
14+
# This makes Actions fetch all Git history so check_changeset script can diff properly.
15+
- name: Set up Node (10)
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: 10.x
19+
- name: Yarn install
20+
run: yarn
21+
- name: Run changeset script
22+
run: yarn ts-node-script scripts/check_changeset.ts
23+
id: check-changeset
24+
- name: Read output
25+
run: echo "${{steps.check-changeset.outputs.MISSING_PACKAGES}}"
26+
- name: Find Comment
27+
uses: peter-evans/find-comment@v1
28+
id: fc
29+
with:
30+
issue-number: ${{github.event.number}}
31+
body-includes: Changeset File Check
32+
- name: Create comment (missing packages)
33+
if: ${{!steps.fc.outputs.comment-id && steps.check-changeset.outputs.MISSING_PACKAGES}}
34+
uses: peter-evans/create-or-update-comment@v1
35+
with:
36+
issue-number: ${{github.event.number}}
37+
body: |
38+
### Changeset File Check :warning:
39+
Warning: This PR modifies files in the following packages but they have not been included in the changeset file:
40+
${{steps.check-changeset.outputs.MISSING_PACKAGES}}
41+
42+
Make sure this was intentional.
43+
- name: Update comment (missing packages)
44+
if: ${{steps.fc.outputs.comment-id}}
45+
uses: peter-evans/create-or-update-comment@v1
46+
with:
47+
comment-id: ${{steps.fc.outputs.comment-id}} && steps.check-changeset.outputs.MISSING_PACKAGES}}
48+
edit-mode: replace
49+
body: |
50+
### Changeset File Check :warning:
51+
Warning: This PR modifies files in the following packages but they have not been included in the changeset file:
52+
${{steps.check-changeset.outputs.MISSING_PACKAGES}}
53+
54+
Make sure this was intentional.
55+
- name: Update comment (no missing packages)
56+
if: ${{steps.fc.outputs.comment-id && !steps.check-changeset.outputs.MISSING_PACKAGES}}
57+
uses: peter-evans/create-or-update-comment@v1
58+
with:
59+
comment-id: ${{steps.fc.outputs.comment-id}}
60+
edit-mode: replace
61+
body: |
62+
### Changeset File Check :white_check_mark:
63+
No modified packages are missing from the changeset file.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,21 @@
6767
"@changesets/cli": "2.9.2",
6868
"@microsoft/api-documenter": "7.8.21",
6969
"@microsoft/api-extractor": "7.9.2",
70+
"@types/mz": "2.7.1",
7071
"@types/chai": "4.2.12",
7172
"@types/chai-as-promised": "7.1.3",
7273
"@types/child-process-promise": "2.2.1",
7374
"@types/clone": "0.1.30",
7475
"@types/inquirer": "7.3.0",
76+
"@types/listr": "0.14.2",
7577
"@types/long": "4.0.1",
7678
"@types/mocha": "7.0.2",
79+
"@types/mz": "2.7.1",
7780
"@types/node": "12.12.53",
7881
"@types/sinon": "9.0.4",
7982
"@types/sinon-chai": "3.2.4",
8083
"@types/tmp": "0.2.0",
8184
"@types/yargs": "15.0.5",
82-
"@types/listr": "0.14.2",
8385
"@typescript-eslint/eslint-plugin": "2.34.0",
8486
"@typescript-eslint/eslint-plugin-tslint": "2.34.0",
8587
"@typescript-eslint/parser": "2.34.0",
@@ -112,11 +114,11 @@
112114
"karma-coverage-istanbul-reporter": "2.1.1",
113115
"karma-firefox-launcher": "1.3.0",
114116
"karma-mocha": "2.0.1",
117+
"karma-mocha-reporter": "2.2.5",
115118
"karma-safari-launcher": "1.0.0",
116119
"karma-sauce-launcher": "1.2.0",
117120
"karma-sourcemap-loader": "0.3.7",
118121
"karma-spec-reporter": "0.0.32",
119-
"karma-mocha-reporter": "2.2.5",
120122
"karma-summary-reporter": "1.8.0",
121123
"karma-webpack": "4.0.2",
122124
"lcov-result-merger": "3.1.0",

packages/component/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
_NOTE: This is specifically tailored for Firebase JS SDK usage, if you are not a
44
member of the Firebase team, please avoid using this package_
55

6-
## Installation
7-
8-
You can install this wrapper by running the following in your project:
9-
10-
```bash
11-
$ npm install @firebase/component
12-
```
13-
146
## Usage
157

168
**ES Modules**

packages/firebase/README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ For more information, visit:
1414
The Firebase Realtime Database lets you store and query user data, and makes
1515
it available between users in realtime.
1616
- [Cloud Firestore](https://firebase.google.com/docs/firestore/quickstart) -
17-
Cloud Firestore is a flexible, scalable database for mobile, web, and server
17+
Cloud Firestore is a flexible, scalable database for mobile, web, and server
1818
development from Firebase and Google Cloud Platform.
1919
- [Firebase Storage](https://firebase.google.com/docs/storage/web/start) -
2020
Firebase Storage lets you upload and store user generated content, such as
@@ -37,6 +37,10 @@ you should use the
3737
## Get the code (browser)
3838

3939
### Script include
40+
>This brings in all Firebase features. See
41+
>["Include only the features you need"](#include-only-the-features-you-need)
42+
>below for
43+
>how to minimize download size by only including the scripts you need.
4044
4145
Include Firebase in your web application via a `<script>` tag:
4246

@@ -56,12 +60,17 @@ Include Firebase in your web application via a `<script>` tag:
5660
</script>
5761
```
5862

59-
*Note: To get a filled in version of the above code snippet, go to the
63+
_Note: To get a filled in version of the above code snippet, go to the
6064
[Firebase console](https://console.firebase.google.com/) for your app and click on "Add
61-
Firebase to your web app".*
65+
Firebase to your web app"._
6266

6367
### npm bundler (Browserify, Webpack, etc.)
6468

69+
>This brings in all Firebase features. See
70+
>["Include only the features you need"](#include-only-the-features-you-need)
71+
>below for
72+
>how to minimize bundle size by only importing the features you need.
73+
6574
The Firebase JavaScript npm package contains code that can be run in the browser
6675
after combining the modules you use with a package bundler (e.g.,
6776
[Browserify](http://browserify.org/), [Webpack](https://webpack.github.io/)).
@@ -173,11 +182,12 @@ var app = firebase.initializeApp({ ... });
173182
// ...
174183
```
175184

176-
If you are using native ES6 module with --experimental-modules flag, you should do:
185+
If you are using native ES6 module with --experimental-modules flag (or Node 12+)
186+
you should do:
177187

178188
```js
179189
// This import loads the firebase namespace.
180-
import firebase from 'firebase/app';
190+
import * as firebase from 'firebase/app';
181191

182192
// These imports load individual services into the firebase namespace.
183193
import 'firebase/auth';
@@ -186,7 +196,6 @@ import 'firebase/database';
186196

187197
_Known issue for typescript users with --experimental-modules: you have to set allowSyntheticDefaultImports to true in tsconfig.json to pass the type check. Use it with caution since it makes the assumption that all modules have a default export, which might not be the case for the other dependencies you have. And Your code will break if you try to import the default export from a module that doesn't have default export._
188198

189-
190199
Firebase Storage is not included in the server side Firebase npm module.
191200
Instead, you can use the
192201
[`google-cloud` Node.js client](https://github.com/GoogleCloudPlatform/google-cloud-node).
@@ -231,4 +240,5 @@ The Firebase changelog can be found at
231240
[firebase.google.com](https://firebase.google.com/support/release-notes/js).
232241

233242
## Browser/environment compatibility
243+
234244
Please see [Environment Support](https://firebase.google.com/support/guides/environments_js-sdk).

packages/firestore/README.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,6 @@ If you are developing a Node.js application that requires administrative access
1010
use the [`@google-cloud/firestore`](https://www.npmjs.com/package/@google-cloud/firestore) Server
1111
SDK with your developer credentials.
1212

13-
## Usage
14-
15-
You can then use the firebase namespace exposed by this package as illustrated
16-
below:
17-
18-
**ES Modules**
19-
20-
```javascript
21-
import firebase from '@firebase/app';
22-
import '@firebase/firestore'
23-
24-
// Do stuff w/ `firebase` and `firebase.firestore`
25-
```
26-
27-
**CommonJS Modules**
28-
29-
```javascript
30-
const firebase = require('@firebase/app').default;
31-
require('@firebase/firestore');
32-
33-
// Do stuff with `firebase` and `firebase.firestore`
34-
```
35-
3613
## Documentation
3714

3815
For comprehensive documentation please see the [Firebase Reference

packages/firestore/exp/src/api/database.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ import {
2727
enqueueWaitForPendingWrites,
2828
MAX_CONCURRENT_LIMBO_RESOLUTIONS
2929
} from '../../../src/core/firestore_client';
30-
import { AsyncQueue } from '../../../src/util/async_queue';
30+
import {
31+
AsyncQueue,
32+
wrapInUserErrorIfRecoverable
33+
} from '../../../src/util/async_queue';
3134
import {
3235
ComponentConfiguration,
3336
IndexedDbOfflineComponentProvider,
@@ -59,7 +62,6 @@ import { AutoId } from '../../../src/util/misc';
5962
import { User } from '../../../src/auth/user';
6063
import { CredentialChangeListener } from '../../../src/api/credentials';
6164
import { logDebug } from '../../../src/util/log';
62-
import { debugAssert } from '../../../src/util/assert';
6365

6466
const LOG_TAG = 'Firestore';
6567

@@ -131,16 +133,28 @@ export class Firestore extends LiteFirestore
131133
}
132134

133135
_terminate(): Promise<void> {
134-
debugAssert(!this._terminated, 'Cannot invoke _terminate() more than once');
135-
return this._queue.enqueueAndInitiateShutdown(async () => {
136-
await super._terminate();
137-
await removeComponents(this);
138-
139-
// `removeChangeListener` must be called after shutting down the
140-
// RemoteStore as it will prevent the RemoteStore from retrieving
141-
// auth tokens.
142-
this._credentials.removeChangeListener();
136+
this._queue.enterRestrictedMode();
137+
const deferred = new Deferred();
138+
this._queue.enqueueAndForgetEvenWhileRestricted(async () => {
139+
try {
140+
await super._terminate();
141+
await removeComponents(this);
142+
143+
// `removeChangeListener` must be called after shutting down the
144+
// RemoteStore as it will prevent the RemoteStore from retrieving
145+
// auth tokens.
146+
this._credentials.removeChangeListener();
147+
148+
deferred.resolve();
149+
} catch (e) {
150+
const firestoreError = wrapInUserErrorIfRecoverable(
151+
e,
152+
`Failed to shutdown persistence`
153+
);
154+
deferred.reject(firestoreError);
155+
}
143156
});
157+
return deferred.promise;
144158
}
145159
}
146160

@@ -242,7 +256,7 @@ export function clearIndexedDbPersistence(
242256
}
243257

244258
const deferred = new Deferred<void>();
245-
firestoreImpl._queue.enqueueAndForgetEvenAfterShutdown(async () => {
259+
firestoreImpl._queue.enqueueAndForgetEvenWhileRestricted(async () => {
246260
try {
247261
await indexedDbClearPersistence(
248262
indexedDbStoragePrefix(

packages/firestore/scripts/run-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
17-
*/exports.__esModule=true;var yargs=require("yargs");var path_1=require("path");var child_process_promise_1=require("child-process-promise");var argv=yargs.options({main:{type:"string",demandOption:true},platform:{type:"string",default:"node"},emulator:{type:"boolean"},persistence:{type:"boolean"}}).argv;var nyc=path_1.resolve(__dirname,"../../../node_modules/.bin/nyc");var mocha=path_1.resolve(__dirname,"../../../node_modules/.bin/mocha");process.env.TS_NODE_CACHE="NO";process.env.TS_NODE_COMPILER_OPTIONS='{"module":"commonjs"}';process.env.TEST_PLATFORM=argv.platform;var args=[mocha,"--require","ts-node/register","--require",argv.main,"--config","../../config/mocharc.node.js"];if(argv.emulator){process.env.FIRESTORE_EMULATOR_PORT="8080";process.env.FIRESTORE_EMULATOR_PROJECT_ID="test-emulator"}if(argv.persistence){process.env.USE_MOCK_PERSISTENCE="YES";args.push("--require","test/util/node_persistence.ts")}args=args.concat(argv._);var childProcess=child_process_promise_1.spawn(nyc,args,{stdio:"inherit",cwd:process.cwd()}).childProcess;process.once("exit",(function(){return childProcess.kill()}));process.once("SIGINT",(function(){return childProcess.kill("SIGINT")}));process.once("SIGTERM",(function(){return childProcess.kill("SIGTERM")}));
17+
*/exports.__esModule=true;var yargs=require("yargs");var path_1=require("path");var child_process_promise_1=require("child-process-promise");var argv=yargs.options({main:{type:"string",demandOption:true},platform:{type:"string",default:"node"},emulator:{type:"boolean"},persistence:{type:"boolean"}}).argv;var nyc=path_1.resolve(__dirname,"../../../node_modules/.bin/nyc");var mocha=path_1.resolve(__dirname,"../../../node_modules/.bin/mocha");process.env.TS_NODE_CACHE="NO";process.env.TS_NODE_COMPILER_OPTIONS='{"module":"commonjs"}';process.env.TEST_PLATFORM=argv.platform;var args=["--reporter","lcovonly",mocha,"--require","ts-node/register","--require",argv.main,"--config","../../config/mocharc.node.js"];if(argv.emulator){process.env.FIRESTORE_EMULATOR_PORT="8080";process.env.FIRESTORE_EMULATOR_PROJECT_ID="test-emulator"}if(argv.persistence){process.env.USE_MOCK_PERSISTENCE="YES";args.push("--require","test/util/node_persistence.ts")}args=args.concat(argv._);var childProcess=child_process_promise_1.spawn(nyc,args,{stdio:"inherit",cwd:process.cwd()}).childProcess;process.once("exit",(function(){return childProcess.kill()}));process.once("SIGINT",(function(){return childProcess.kill("SIGINT")}));process.once("SIGTERM",(function(){return childProcess.kill("SIGTERM")}));

packages/firestore/scripts/run-tests.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ process.env.TS_NODE_COMPILER_OPTIONS = '{"module":"commonjs"}';
4444
process.env.TEST_PLATFORM = argv.platform;
4545

4646
let args = [
47+
'--reporter',
48+
'lcovonly',
4749
mocha,
4850
'--require',
4951
'ts-node/register',

packages/firestore/src/api/credentials.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ export class EmptyCredentialsProvider implements CredentialsProvider {
127127
}
128128

129129
removeChangeListener(): void {
130-
debugAssert(
131-
this.changeListener !== null,
132-
'removeChangeListener() when no listener registered'
133-
);
134130
this.changeListener = null;
135131
}
136132
}
@@ -252,15 +248,6 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
252248
}
253249

254250
removeChangeListener(): void {
255-
debugAssert(
256-
this.tokenListener != null,
257-
'removeChangeListener() called twice'
258-
);
259-
debugAssert(
260-
this.changeListener !== null,
261-
'removeChangeListener() called when no listener registered'
262-
);
263-
264251
if (this.auth) {
265252
this.auth.removeAuthTokenListener(this.tokenListener!);
266253
}

packages/firestore/src/api/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
448448
}
449449

450450
const deferred = new Deferred<void>();
451-
this._queue.enqueueAndForgetEvenAfterShutdown(async () => {
451+
this._queue.enqueueAndForgetEvenWhileRestricted(async () => {
452452
try {
453453
await this._offlineComponentProvider.clearPersistence(
454454
this._databaseId,

0 commit comments

Comments
 (0)