Skip to content

Commit

Permalink
Refactor to fix TSC errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jshcrowthe committed Oct 3, 2017
1 parent bc038c1 commit 63de02d
Show file tree
Hide file tree
Showing 11 changed files with 2,222 additions and 467 deletions.
1,689 changes: 1,241 additions & 448 deletions packages/firebase/index.d.ts

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/firestore/package.json
Expand Up @@ -11,6 +11,9 @@
},
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@firebase/webchannel-wrapper": "^0.2.1"
},
"peerDependencies": {
"@firebase/app": "^0.1.0"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/firestore/src/api/credentials.ts
Expand Up @@ -18,6 +18,7 @@ import { User } from '../auth/user';
import { assert, fail } from '../util/assert';
import { Code, FirestoreError } from '../util/error';
import { AnyJs } from '../util/misc';
import { FirebaseApp } from "@firebase/app";

// TODO(mikelehen): This should be split into multiple files and probably
// moved to an auth/ folder to match other platforms.
Expand Down Expand Up @@ -143,7 +144,7 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
/** The User listener registered with setUserChangeListener(). */
private userListener: UserListener | null = null;

constructor(private readonly app: firebase.app.App) {
constructor(private readonly app: FirebaseApp) {
// We listen for token changes but all we really care about is knowing when
// the uid may have changed.
this.tokenListener = () => {
Expand Down
17 changes: 9 additions & 8 deletions packages/firestore/src/api/database.ts
Expand Up @@ -16,6 +16,7 @@

import * as firestore from 'firestore';

import { FirebaseApp, FirebaseService } from "@firebase/app";
import { FieldPath as ExternalFieldPath } from './field_path';
import { DatabaseId, DatabaseInfo } from '../core/database_info';
import { ListenOptions } from '../core/event_manager';
Expand Down Expand Up @@ -168,7 +169,7 @@ class FirestoreConfig {
databaseId: DatabaseId;
persistenceKey: string;
credentials: CredentialsProvider;
firebaseApp: firebase.app.App;
firebaseApp: FirebaseApp;
settings: FirestoreSettings;
persistence: boolean;
}
Expand All @@ -192,12 +193,12 @@ export class Firestore implements firestore.Firestore, FirebaseService {
return this._config.databaseId;
}

constructor(databaseIdOrApp: FirestoreDatabase | firebase.app.App) {
constructor(databaseIdOrApp: FirestoreDatabase | FirebaseApp) {
const config = new FirestoreConfig();
if (typeof (databaseIdOrApp as firebase.app.App).options === 'object') {
if (typeof (databaseIdOrApp as FirebaseApp).options === 'object') {
// This is very likely a Firebase app object
// TODO(b/34177605): Can we somehow use instanceof?
const app = databaseIdOrApp as firebase.app.App;
const app = databaseIdOrApp as FirebaseApp;
config.firebaseApp = app;
config.databaseId = Firestore.databaseIdFromApp(app);
config.persistenceKey = config.firebaseApp.name;
Expand All @@ -212,7 +213,7 @@ export class Firestore implements firestore.Firestore, FirebaseService {
}

config.databaseId = new DatabaseId(external.projectId, external.database);
// Use a default persistenceKey that lines up with firebase.app.App.
// Use a default persistenceKey that lines up with FirebaseApp.
config.persistenceKey = '[DEFAULT]';
config.credentials = new EmptyCredentialsProvider();
}
Expand Down Expand Up @@ -316,7 +317,7 @@ export class Firestore implements firestore.Firestore, FirebaseService {
return this._firestoreClient.start(persistence);
}

private static databaseIdFromApp(app: firebase.app.App): DatabaseId {
private static databaseIdFromApp(app: FirebaseApp): DatabaseId {
const options = app.options as objUtils.Dict<{}>;
if (!objUtils.contains(options, 'projectId')) {
// TODO(b/62673263): We can safely remove the special handling of
Expand Down Expand Up @@ -348,13 +349,13 @@ export class Firestore implements firestore.Firestore, FirebaseService {
if (!projectId || typeof projectId !== 'string') {
throw new FirestoreError(
Code.INVALID_ARGUMENT,
'projectId must be a string in firebase.app.App.options'
'projectId must be a string in FirebaseApp.options'
);
}
return new DatabaseId(projectId);
}

get app(): firebase.app.App {
get app(): FirebaseApp {
if (!this._config.firebaseApp) {
throw new FirestoreError(
Code.FAILED_PRECONDITION,
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/core/version.ts
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import firebase from '../../app';
import firebase from '@firebase/app';

/** The semver (www.semver.org) version of the SDK. */
export const SDK_VERSION = firebase.SDK_VERSION;
4 changes: 2 additions & 2 deletions packages/firestore/src/platform/config.ts
Expand Up @@ -15,7 +15,7 @@
*/

import * as firestore from 'firestore';

import { FirebaseApp, FirebaseNamespace } from "@firebase/app";
import { PublicBlob } from '../api/blob';
import {
Firestore,
Expand Down Expand Up @@ -55,7 +55,7 @@ const firestoreNamespace = {
export function configureForFirebase(firebase: FirebaseNamespace): void {
firebase.INTERNAL.registerService(
'firestore',
(app: firebase.app.App) => new Firestore(app),
(app: FirebaseApp) => new Firestore(app),
shallowCopy(firestoreNamespace)
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/platform_node/grpc_connection.ts
Expand Up @@ -21,7 +21,7 @@
// import * as protobufjs from 'protobufjs';
// import * as util from 'util';

import firebase from '../../app';
import firebase from '@firebase/app';
const SDK_VERSION = firebase.SDK_VERSION;
// Temporary type definition until types work again (see above)
export type GrpcMetadataCallback = any;
Expand Down

0 comments on commit 63de02d

Please sign in to comment.