Skip to content

Commit

Permalink
TypeScript 4.7.4 upgrade for Firestore (#6796)
Browse files Browse the repository at this point in the history
  • Loading branch information
dconeybe committed Nov 21, 2022
1 parent 37dd6f6 commit ab3f16c
Show file tree
Hide file tree
Showing 14 changed files with 79 additions and 29 deletions.
7 changes: 7 additions & 0 deletions .changeset/breezy-wombats-care.md
@@ -0,0 +1,7 @@
---
'@firebase/firestore': minor
'@firebase/firestore-compat': minor
'firebase': minor
---

Upgrade TypeScript to 4.7.4 (was 4.2.2)
2 changes: 1 addition & 1 deletion packages/firestore-compat/package.json
Expand Up @@ -58,7 +58,7 @@
"rollup-plugin-typescript2": "0.31.2",
"@rollup/plugin-node-resolve": "13.3.0",
"ts-node": "10.9.1",
"typescript": "4.2.2"
"typescript": "4.7.4"
},
"license": "Apache-2.0",
"typings": "dist/src/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/firestore-compat/test/array_transforms.test.ts
Expand Up @@ -189,7 +189,8 @@ apiDescribe('Array Transforms:', (persistence: boolean) => {
let errCaught = false;
try {
await docRef.get({ source: 'cache' });
} catch (err) {
} catch (e) {
const err = e as firestore.FirestoreError;
expect(err.code).to.equal('unavailable');
errCaught = true;
}
Expand Down
11 changes: 7 additions & 4 deletions packages/firestore-compat/test/transactions.test.ts
Expand Up @@ -116,7 +116,8 @@ apiDescribe('Database transactions', (persistence: boolean) => {
const snapshot = await this.docRef.get();
expect(snapshot.exists).to.equal(true);
expect(snapshot.data()).to.deep.equal(expected);
} catch (err) {
} catch (e) {
const err = e as firestore.FirestoreError;
expect.fail(
'Expected the sequence (' +
this.listStages(this.stages) +
Expand All @@ -133,7 +134,8 @@ apiDescribe('Database transactions', (persistence: boolean) => {
await this.runTransaction();
const snapshot = await this.docRef.get();
expect(snapshot.exists).to.equal(false);
} catch (err) {
} catch (e) {
const err = e as firestore.FirestoreError;
expect.fail(
'Expected the sequence (' +
this.listStages(this.stages) +
Expand All @@ -150,8 +152,9 @@ apiDescribe('Database transactions', (persistence: boolean) => {
await this.prepareDoc();
await this.runTransaction();
succeeded = true;
} catch (err) {
expect((err as firestore.FirestoreError).code).to.equal(expected);
} catch (e) {
const err = e as firestore.FirestoreError;
expect(err.code).to.equal(expected);
}
if (succeeded) {
expect.fail(
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/package.json
Expand Up @@ -84,7 +84,7 @@
"@firebase/logger": "0.3.4",
"@firebase/util": "1.7.3",
"@firebase/webchannel-wrapper": "0.8.1",
"@grpc/grpc-js": "^1.3.2",
"@grpc/grpc-js": "~1.7.0",
"@grpc/proto-loader": "^0.6.13",
"node-fetch": "2.6.7",
"tslib": "^2.1.0"
Expand All @@ -111,7 +111,7 @@
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-typescript2": "0.31.2",
"ts-node": "10.9.1",
"typescript": "4.2.2"
"typescript": "4.7.4"
},
"repository": {
"directory": "packages/firestore",
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/scripts/remove-asserts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/firestore/scripts/remove-asserts.ts
Expand Up @@ -64,7 +64,7 @@ class RemoveAsserts {
) {
const method = declaration.name!.text;
if (method === 'debugAssert') {
updatedNode = ts.createEmptyStatement();
updatedNode = ts.createOmittedExpression();
} else if (method === 'hardAssert') {
// Remove the log message but keep the assertion
updatedNode = ts.createCall(
Expand Down
Expand Up @@ -61,7 +61,8 @@ export class FetchConnection extends RestConnection {
headers,
body: requestJson
});
} catch (err) {
} catch (e) {
const err = e as { status: number | undefined; statusText: string };
throw new FirestoreError(
mapCodeFromHttpStatus(err.status),
'Request failed with error: ' + err.statusText
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/util/types.ts
Expand Up @@ -61,7 +61,7 @@ export interface WindowLike {

/** The subset of the browser's Document interface used by the SDK. */
export interface DocumentLike {
readonly visibilityState: VisibilityState;
readonly visibilityState: DocumentVisibilityState;
addEventListener(type: string, listener: EventListener): void;
removeEventListener(type: string, listener: EventListener): void;
}
Expand Up @@ -17,6 +17,7 @@

import { expect } from 'chai';

import { FirestoreError } from '../../../src';
import { DEFAULT_TRANSACTION_OPTIONS } from '../../../src/core/transaction_options';
import { TimerId } from '../../../src/util/async_queue';
import { Deferred } from '../../util/promise';
Expand Down Expand Up @@ -155,7 +156,8 @@ apiDescribe(
await transaction.set(docRef, { count: 16 });
});
expect.fail('transaction should fail');
} catch (err) {
} catch (e) {
const err = e as FirestoreError;
expect(err).to.exist;
expect(err.code).to.equal('aborted');
}
Expand Down Expand Up @@ -194,7 +196,8 @@ apiDescribe(
options
);
expect.fail('transaction should fail');
} catch (err) {
} catch (e) {
const err = e as FirestoreError;
expect(err).to.exist;
expect(err.code).to.equal('aborted');
}
Expand Down
Expand Up @@ -1310,18 +1310,18 @@ describe('IndexedDb: canActAsPrimary', () => {

after(() => SimpleDb.delete(INDEXEDDB_TEST_DATABASE_NAME));

const visible: VisibilityState = 'visible';
const hidden: VisibilityState = 'hidden';
const visible: DocumentVisibilityState = 'visible';
const hidden: DocumentVisibilityState = 'hidden';
const networkEnabled = true;
const networkDisabled = false;
const primary = true;
const secondary = false;

type ExpectedPrimaryStateTestCase = [
boolean,
VisibilityState,
DocumentVisibilityState,
boolean,
VisibilityState,
DocumentVisibilityState,
boolean
];

Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/test/unit/specs/spec_test_runner.ts
Expand Up @@ -1571,7 +1571,7 @@ export interface SpecWatchEntity {
// PORTING NOTE: Only used by web multi-tab tests.
export interface SpecClientState {
/** The visibility state of the browser tab running the client. */
visibility?: VisibilityState;
visibility?: DocumentVisibilityState;
/** Whether this tab should try to forcefully become primary. */
primary?: true;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/test/util/test_platform.ts
Expand Up @@ -93,10 +93,10 @@ export function testWindow(
* `Document` fake that implements the `visibilitychange` API used by Firestore.
*/
export class FakeDocument implements DocumentLike {
private _visibilityState: VisibilityState = 'hidden';
private _visibilityState: DocumentVisibilityState = 'hidden';
private visibilityListener: EventListener | null = null;

get visibilityState(): VisibilityState {
get visibilityState(): DocumentVisibilityState {
return this._visibilityState;
}

Expand All @@ -114,7 +114,7 @@ export class FakeDocument implements DocumentLike {
}
}

raiseVisibilityEvent(visibility: VisibilityState): void {
raiseVisibilityEvent(visibility: DocumentVisibilityState): void {
this._visibilityState = visibility;
if (this.visibilityListener) {
this.visibilityListener(new Event('visibilitychange'));
Expand Down
49 changes: 42 additions & 7 deletions yarn.lock
Expand Up @@ -1815,13 +1815,6 @@
lodash.snakecase "^4.1.1"
p-defer "^3.0.0"

"@grpc/grpc-js@^1.3.2":
version "1.3.7"
resolved "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.3.7.tgz#58b687aff93b743aafde237fd2ee9a3259d7f2d8"
integrity sha512-CKQVuwuSPh40tgOkR7c0ZisxYRiN05PcKPW72mQL5y++qd7CwBRoaJZvU5xfXnCJDFBmS3qZGQ71Frx6Ofo2XA==
dependencies:
"@types/node" ">=12.12.47"

"@grpc/grpc-js@~1.6.0":
version "1.6.7"
resolved "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.6.7.tgz#4c4fa998ff719fe859ac19fe977fdef097bb99aa"
Expand All @@ -1830,6 +1823,14 @@
"@grpc/proto-loader" "^0.6.4"
"@types/node" ">=12.12.47"

"@grpc/grpc-js@~1.7.0":
version "1.7.3"
resolved "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.7.3.tgz#f2ea79f65e31622d7f86d4b4c9ae38f13ccab99a"
integrity sha512-H9l79u4kJ2PVSxUNA08HMYAnUBLj9v6KjYQ7SQ71hOZcEXhShE/y5iQCesP8+6/Ik/7i2O0a10bPquIcYfufog==
dependencies:
"@grpc/proto-loader" "^0.7.0"
"@types/node" ">=12.12.47"

"@grpc/proto-loader@^0.6.12", "@grpc/proto-loader@^0.6.13", "@grpc/proto-loader@^0.6.4":
version "0.6.13"
resolved "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.6.13.tgz#008f989b72a40c60c96cd4088522f09b05ac66bc"
Expand All @@ -1841,6 +1842,17 @@
protobufjs "^6.11.3"
yargs "^16.2.0"

"@grpc/proto-loader@^0.7.0":
version "0.7.3"
resolved "https://registry.npmjs.org/@grpc/proto-loader/-/proto-loader-0.7.3.tgz#75a6f95b51b85c5078ac7394da93850c32d36bb8"
integrity sha512-5dAvoZwna2Py3Ef96Ux9jIkp3iZ62TUsV00p3wVBPNX5K178UbNi8Q7gQVqwXT1Yq9RejIGG9G2IPEo93T6RcA==
dependencies:
"@types/long" "^4.0.1"
lodash.camelcase "^4.3.0"
long "^4.0.0"
protobufjs "^7.0.0"
yargs "^16.2.0"

"@gulp-sourcemaps/identity-map@^2.0.1":
version "2.0.1"
resolved "https://registry.npmjs.org/@gulp-sourcemaps/identity-map/-/identity-map-2.0.1.tgz#a6e8b1abec8f790ec6be2b8c500e6e68037c0019"
Expand Down Expand Up @@ -11889,6 +11901,11 @@ long@^4.0.0:
resolved "https://registry.npmjs.org/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==

long@^5.0.0:
version "5.2.1"
resolved "https://registry.npmjs.org/long/-/long-5.2.1.tgz#e27595d0083d103d2fa2c20c7699f8e0c92b897f"
integrity sha512-GKSNGeNAtw8IryjjkhZxuKB3JzlcLTwjtiQCHKvqQet81I93kXslhDQruGI/QsddO83mcDToBVy7GqGS/zYf/A==

loose-envify@^1.0.0:
version "1.4.0"
resolved "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
Expand Down Expand Up @@ -14128,6 +14145,24 @@ protobufjs@6.11.3, protobufjs@^6.11.3:
"@types/node" ">=13.7.0"
long "^4.0.0"

protobufjs@^7.0.0:
version "7.1.2"
resolved "https://registry.npmjs.org/protobufjs/-/protobufjs-7.1.2.tgz#a0cf6aeaf82f5625bffcf5a38b7cd2a7de05890c"
integrity sha512-4ZPTPkXCdel3+L81yw3dG6+Kq3umdWKh7Dc7GW/CpNk4SX3hK58iPCWeCyhVTDrbkNeKrYNZ7EojM5WDaEWTLQ==
dependencies:
"@protobufjs/aspromise" "^1.1.2"
"@protobufjs/base64" "^1.1.2"
"@protobufjs/codegen" "^2.0.4"
"@protobufjs/eventemitter" "^1.1.0"
"@protobufjs/fetch" "^1.1.0"
"@protobufjs/float" "^1.0.2"
"@protobufjs/inquire" "^1.1.0"
"@protobufjs/path" "^1.1.2"
"@protobufjs/pool" "^1.1.0"
"@protobufjs/utf8" "^1.1.0"
"@types/node" ">=13.7.0"
long "^5.0.0"

protocols@^1.1.0, protocols@^1.4.0:
version "1.4.8"
resolved "https://registry.npmjs.org/protocols/-/protocols-1.4.8.tgz#48eea2d8f58d9644a4a32caae5d5db290a075ce8"
Expand Down

0 comments on commit ab3f16c

Please sign in to comment.