Skip to content

Commit 3f5bde1

Browse files
committed
Update SDKs to use the new type system (#2358)
* update database types * update Firestore types * update installations type * update messaging types * update functions types * update performance types * update remoteconfig types * update storage types * fix analytics issue * [AUTOMATED]: Prettier Code Styling
1 parent 959ddcf commit 3f5bde1

File tree

33 files changed

+149
-88
lines changed

33 files changed

+149
-88
lines changed

packages/analytics-interop-types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export interface AnalyticsCallOptions {
3939
global: boolean;
4040
}
4141

42+
export type FirebaseAnalyticsInternalName = 'analytics-internal';
43+
4244
declare module '@firebase/component' {
4345
interface NameServiceMapping {
4446
'analytics-internal': FirebaseAnalyticsInternal;

packages/analytics/index.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import { FirebaseAnalyticsInternal } from '@firebase/analytics-interop-types';
2020
import { _FirebaseNamespace } from '@firebase/app-types/private';
2121
import { factory, settings, resetGlobalVars } from './src/factory';
2222
import { EventName } from './src/constants';
23-
import { Component, ComponentType } from '@firebase/component';
23+
import {
24+
Component,
25+
ComponentType,
26+
ComponentContainer
27+
} from '@firebase/component';
2428
import { ERROR_FACTORY, AnalyticsError } from './src/errors';
2529

2630
declare global {
@@ -50,26 +54,23 @@ export function registerAnalytics(instance: _FirebaseNamespace): void {
5054
);
5155

5256
instance.INTERNAL.registerComponent(
53-
new Component(
54-
'analytics-internal',
55-
container => {
56-
try {
57-
const analytics = container
58-
.getProvider(ANALYTICS_TYPE)
59-
.getImmediate();
60-
return {
61-
logEvent: analytics.logEvent
62-
};
63-
} catch (e) {
64-
throw ERROR_FACTORY.create(
65-
AnalyticsError.INTEROP_COMPONENT_REG_FAILED,
66-
{ reason: e }
67-
);
68-
}
69-
},
70-
ComponentType.PRIVATE
71-
)
57+
new Component('analytics-internal', internalFactory, ComponentType.PRIVATE)
7258
);
59+
60+
function internalFactory(
61+
container: ComponentContainer
62+
): FirebaseAnalyticsInternal {
63+
try {
64+
const analytics = container.getProvider(ANALYTICS_TYPE).getImmediate();
65+
return {
66+
logEvent: analytics.logEvent
67+
};
68+
} catch (e) {
69+
throw ERROR_FACTORY.create(AnalyticsError.INTEROP_COMPONENT_REG_FAILED, {
70+
reason: e
71+
});
72+
}
73+
}
7374
}
7475

7576
export { factory, settings, resetGlobalVars };

packages/database-types/index.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export interface Reference extends Query {
9999
key: string | null;
100100
onDisconnect(): OnDisconnect;
101101
parent: Reference | null;
102-
push(value?: any, onComplete?: (a: Error | null) => any): ThenableReference;
102+
push(value?: any, onComplete?: (a: Error | null) => any): Reference;
103103
remove(onComplete?: (a: Error | null) => any): Promise<any>;
104104
root: Reference;
105105
set(value: any, onComplete?: (a: Error | null) => any): Promise<any>;
@@ -132,3 +132,9 @@ export function enableLogging(
132132
logger?: boolean | ((a: string) => any),
133133
persistent?: boolean
134134
): any;
135+
136+
declare module '@firebase/component' {
137+
interface NameServiceMapping {
138+
'database': FirebaseDatabase;
139+
}
140+
}

packages/database/index.node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
Provider,
3737
ComponentContainer
3838
} from '@firebase/component';
39-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
39+
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
4040

4141
setWebSocketImpl(Client);
4242

@@ -64,7 +64,7 @@ export function initStandalone(app: FirebaseApp, url: string, version: string) {
6464
* ComponentContainer('database-admin') is just a placeholder that doesn't perform
6565
* any actual function.
6666
*/
67-
const authProvider = new Provider<FirebaseAuthInternal>(
67+
const authProvider = new Provider<FirebaseAuthInternalName>(
6868
'auth-internal',
6969
new ComponentContainer('database-admin')
7070
);

packages/database/src/api/Database.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ import { validateUrl } from '../core/util/validation';
2626
import { FirebaseApp } from '@firebase/app-types';
2727
import { FirebaseService } from '@firebase/app-types/private';
2828
import { RepoInfo } from '../core/RepoInfo';
29+
import { FirebaseDatabase } from '@firebase/database-types';
2930

3031
/**
3132
* Class representing a firebase database.
3233
* @implements {FirebaseService}
3334
*/
34-
export class Database implements FirebaseService {
35+
export class Database implements FirebaseService, FirebaseDatabase {
3536
INTERNAL: DatabaseInternals;
3637
private root_: Reference;
3738

packages/database/src/api/Reference.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ import { Deferred } from '@firebase/util';
3737
import { SyncPoint } from '../core/SyncPoint';
3838
import { Database } from './Database';
3939
import { DataSnapshot } from './DataSnapshot';
40+
import * as types from '@firebase/database-types';
4041

4142
export interface ReferenceConstructor {
4243
new (repo: Repo, path: Path): Reference;
4344
}
4445

45-
export class Reference extends Query {
46+
export class Reference extends Query implements types.Reference {
4647
public then: (a?: any) => Promise<any>;
4748
public catch: (a?: Error) => Promise<any>;
4849

packages/database/src/core/AuthTokenProvider.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
*/
1717

1818
import { FirebaseAuthTokenData } from '@firebase/app-types/private';
19-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
19+
import {
20+
FirebaseAuthInternal,
21+
FirebaseAuthInternalName
22+
} from '@firebase/auth-interop-types';
2023
import { Provider } from '@firebase/component';
2124
import { log, warn } from './util/util';
2225
import { FirebaseApp } from '@firebase/app-types';
@@ -28,7 +31,7 @@ export class AuthTokenProvider {
2831
private auth_: FirebaseAuthInternal | null = null;
2932
constructor(
3033
private app_: FirebaseApp,
31-
private authProvider_: Provider<FirebaseAuthInternal>
34+
private authProvider_: Provider<FirebaseAuthInternalName>
3235
) {
3336
this.auth_ = authProvider_.getImmediate({ optional: true });
3437
if (!this.auth_) {

packages/database/src/core/Repo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import { EventRegistration } from './view/EventRegistration';
4444
import { StatsCollection } from './stats/StatsCollection';
4545
import { Event } from './view/Event';
4646
import { Node } from './snap/Node';
47-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
47+
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
4848
import { Provider } from '@firebase/component';
4949

5050
const INTERRUPT_REASON = 'repo_interrupt';
@@ -82,7 +82,7 @@ export class Repo {
8282
public repoInfo_: RepoInfo,
8383
forceRestClient: boolean,
8484
public app: FirebaseApp,
85-
authProvider: Provider<FirebaseAuthInternal>
85+
authProvider: Provider<FirebaseAuthInternalName>
8686
) {
8787
const authTokenProvider = new AuthTokenProvider(app, authProvider);
8888

packages/database/src/core/RepoManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { validateUrl } from './util/validation';
2424
import './Repo_transaction';
2525
import { Database } from '../api/Database';
2626
import { RepoInfo } from './RepoInfo';
27-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
27+
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
2828
import { Provider } from '@firebase/component';
2929

3030
/** @const {string} */
@@ -93,7 +93,7 @@ export class RepoManager {
9393
*/
9494
databaseFromApp(
9595
app: FirebaseApp,
96-
authProvider: Provider<FirebaseAuthInternal>,
96+
authProvider: Provider<FirebaseAuthInternalName>,
9797
url?: string
9898
): Database {
9999
let dbUrl: string | undefined = url || app.options[DATABASE_URL_OPTION];
@@ -159,7 +159,7 @@ export class RepoManager {
159159
createRepo(
160160
repoInfo: RepoInfo,
161161
app: FirebaseApp,
162-
authProvider: Provider<FirebaseAuthInternal>
162+
authProvider: Provider<FirebaseAuthInternalName>
163163
): Repo {
164164
let appRepos = safeGet(this.repos_, app.name);
165165

packages/database/test/helpers/util.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ let numDatabases = 0;
5959
() => ({
6060
getToken: () => Promise.resolve(null),
6161
addAuthTokenListener: () => {},
62-
removeAuthTokenListener: () => {}
62+
removeAuthTokenListener: () => {},
63+
getUid: () => null
6364
}),
6465
ComponentType.PRIVATE
6566
)

packages/firestore-types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,9 @@ export interface FirestoreError {
425425
name: string;
426426
stack?: string;
427427
}
428+
429+
declare module '@firebase/component' {
430+
interface NameServiceMapping {
431+
'firestore': FirebaseFirestore;
432+
}
433+
}

packages/firestore/src/api/credentials.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { _FirebaseApp } from '@firebase/app-types/private';
1919
import { User } from '../auth/user';
2020
import { assert } from '../util/assert';
2121
import { Code, FirestoreError } from '../util/error';
22-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
22+
import {
23+
FirebaseAuthInternal,
24+
FirebaseAuthInternalName
25+
} from '@firebase/auth-interop-types';
2326
import { Provider } from '@firebase/component';
2427

2528
// TODO(mikelehen): This should be split into multiple files and probably
@@ -151,7 +154,7 @@ export class FirebaseCredentialsProvider implements CredentialsProvider {
151154

152155
private auth: FirebaseAuthInternal | null;
153156

154-
constructor(authProvider: Provider<FirebaseAuthInternal>) {
157+
constructor(authProvider: Provider<FirebaseAuthInternalName>) {
155158
this.tokenListener = () => {
156159
this.tokenCounter++;
157160
this.currentUser = this.getUser();

packages/firestore/src/api/database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ import {
105105
fieldPathFromArgument,
106106
UserDataConverter
107107
} from './user_data_converter';
108-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
108+
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
109109
import { Provider } from '@firebase/component';
110110

111111
// settings() defaults:
@@ -312,7 +312,7 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
312312

313313
constructor(
314314
databaseIdOrApp: FirestoreDatabase | FirebaseApp,
315-
authProvider: Provider<FirebaseAuthInternal>
315+
authProvider: Provider<FirebaseAuthInternalName>
316316
) {
317317
if (typeof (databaseIdOrApp as FirebaseApp).options === 'object') {
318318
// This is very likely a Firebase app object

packages/firestore/test/util/api_helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const FIRESTORE = new Firestore(
4747
projectId: 'projectid',
4848
database: 'database'
4949
},
50-
new Provider('auth-interop', new ComponentContainer('default'))
50+
new Provider('auth-internal', new ComponentContainer('default'))
5151
);
5252

5353
export function firestore(): Firestore {

packages/functions-types/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,9 @@ export interface HttpsError extends Error {
133133
*/
134134
readonly details?: any;
135135
}
136+
137+
declare module '@firebase/component' {
138+
interface NameServiceMapping {
139+
'functions': FirebaseFunctions;
140+
}
141+
}

packages/functions/src/api/service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import { _errorForResponse, HttpsErrorImpl } from './error';
2727
import { ContextProvider } from '../context';
2828
import { Serializer } from '../serializer';
2929
import { Provider } from '@firebase/component';
30-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
31-
import { FirebaseMessaging } from '@firebase/messaging-types';
30+
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
31+
import { FirebaseMessagingName } from '@firebase/messaging-types';
3232

3333
/**
3434
* The response to an http request.
@@ -83,8 +83,8 @@ export class Service implements FirebaseFunctions, FirebaseService {
8383
*/
8484
constructor(
8585
private app_: FirebaseApp,
86-
authProvider: Provider<FirebaseAuthInternal>,
87-
messagingProvider: Provider<FirebaseMessaging>,
86+
authProvider: Provider<FirebaseAuthInternalName>,
87+
messagingProvider: Provider<FirebaseMessagingName>,
8888
private region_: string = 'us-central1'
8989
) {
9090
this.contextProvider = new ContextProvider(authProvider, messagingProvider);

packages/functions/src/context.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@
1515
* limitations under the License.
1616
*/
1717
import { _FirebaseApp } from '@firebase/app-types/private';
18-
import { FirebaseMessaging } from '@firebase/messaging-types';
19-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
18+
import {
19+
FirebaseMessaging,
20+
FirebaseMessagingName
21+
} from '@firebase/messaging-types';
22+
import {
23+
FirebaseAuthInternal,
24+
FirebaseAuthInternalName
25+
} from '@firebase/auth-interop-types';
2026
import { Provider } from '@firebase/component';
2127

2228
/**
@@ -34,8 +40,8 @@ export class ContextProvider {
3440
private auth: FirebaseAuthInternal | null = null;
3541
private messaging: FirebaseMessaging | null = null;
3642
constructor(
37-
authProvider: Provider<FirebaseAuthInternal>,
38-
messagingProvider: Provider<FirebaseMessaging>
43+
authProvider: Provider<FirebaseAuthInternalName>,
44+
messagingProvider: Provider<FirebaseMessagingName>
3945
) {
4046
this.auth = authProvider.getImmediate({ optional: true });
4147
this.messaging = messagingProvider.getImmediate({

packages/functions/test/browser/callable.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import * as sinon from 'sinon';
1919
import { FirebaseApp } from '@firebase/app-types';
2020
import { _FirebaseApp } from '@firebase/app-types/private';
2121
import { makeFakeApp, createTestService } from '../utils';
22-
import { FirebaseMessaging } from '@firebase/messaging-types';
22+
import {
23+
FirebaseMessaging,
24+
FirebaseMessagingName
25+
} from '@firebase/messaging-types';
2326
import {
2427
Provider,
2528
ComponentContainer,
@@ -44,7 +47,7 @@ describe('Firebase Functions > Call', () => {
4447
const messagingMock: FirebaseMessaging = ({
4548
getToken: () => Promise.resolve('iid')
4649
} as unknown) as FirebaseMessaging;
47-
const messagingProvider = new Provider<FirebaseMessaging>(
50+
const messagingProvider = new Provider<FirebaseMessagingName>(
4851
'messaging',
4952
new ComponentContainer('test')
5053
);

packages/functions/test/callable.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import {
2525
Component,
2626
ComponentType
2727
} from '@firebase/component';
28-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
28+
import {
29+
FirebaseAuthInternal,
30+
FirebaseAuthInternalName
31+
} from '@firebase/auth-interop-types';
2932
import { makeFakeApp, createTestService } from './utils';
3033

3134
// eslint-disable-next-line @typescript-eslint/no-require-imports
@@ -100,7 +103,7 @@ describe('Firebase Functions > Call', () => {
100103
const authMock: FirebaseAuthInternal = ({
101104
getToken: () => Promise.resolve({ accessToken: 'token' })
102105
} as unknown) as FirebaseAuthInternal;
103-
const authProvider = new Provider<FirebaseAuthInternal>(
106+
const authProvider = new Provider<FirebaseAuthInternalName>(
104107
'auth-internal',
105108
new ComponentContainer('test')
106109
);

packages/functions/test/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import { FirebaseOptions, FirebaseApp } from '@firebase/app-types';
1919
import { Provider, ComponentContainer } from '@firebase/component';
20-
import { FirebaseAuthInternal } from '@firebase/auth-interop-types';
21-
import { FirebaseMessaging } from '@firebase/messaging-types';
20+
import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
21+
import { FirebaseMessagingName } from '@firebase/messaging-types';
2222
import { Service } from '../src/api/service';
2323

2424
export function makeFakeApp(options: FirebaseOptions = {}): FirebaseApp {
@@ -43,11 +43,11 @@ export function makeFakeApp(options: FirebaseOptions = {}): FirebaseApp {
4343
export function createTestService(
4444
app: FirebaseApp,
4545
region?: string,
46-
authProvider = new Provider<FirebaseAuthInternal>(
46+
authProvider = new Provider<FirebaseAuthInternalName>(
4747
'auth-internal',
4848
new ComponentContainer('test')
4949
),
50-
messagingProvider = new Provider<FirebaseMessaging>(
50+
messagingProvider = new Provider<FirebaseMessagingName>(
5151
'messaging',
5252
new ComponentContainer('test')
5353
)

0 commit comments

Comments
 (0)