Skip to content

Commit 7deaaa7

Browse files
russellwheatleymikehardy
authored andcommitted
refactor(installations)!: migrate to TypeScript
BREAKING CHANGE: installations modular types now match firebase-js-sdk Please see https://rnfirebase.io/migrating-to-v25 for help migrating if needed. react-native-firebase has a goal to be a drop-in replacement for firebase-js-sdk, with native extensions and performance. It has always worked that way at the javascript level but the typescript types have been divergent. We are fixing that as we refactor to typescript. Please bear with us as we get closer to our goal of react-native-firebase matching firebase-js-sdk both in functionality where possible, but also in exact typescript typing. Specifics for Installations: changed modular getInstallations() to return the firebase-js-sdk-style Installations type, which only exposes app; TypeScript consumers should use the modular helpers getId(installations), getToken(installations), and deleteInstallations(installations) instead of calling .getId(), .getToken(), or .delete() on the returned instance. changed modular deleteInstallations(installations) so the installations argument is required in the TypeScript surface, matching firebase-js-sdk. Code that previously relied on the old optional typing should pass getInstallations() explicitly. preserved the namespaced API surface: installations(), firebase.installations(), firebase.app().installations(), and FirebaseInstallationsTypes.Module remain available for compatibility, with deprecation annotations added. added explicit modular public types including Installations, IdChangeCallbackFn, and IdChangeUnsubscribeFn.
1 parent 4aedfe8 commit 7deaaa7

18 files changed

Lines changed: 442 additions & 299 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Known differences between the firebase-js-sdk @firebase/installations public
3+
* API and the @react-native-firebase/installations modular API.
4+
*
5+
* Each entry must have a `name` (the export name) and a `reason` explaining
6+
* why the difference exists. Any difference NOT listed here will cause CI to
7+
* fail so that new drift is caught and deliberately acknowledged.
8+
*/
9+
10+
import type { PackageConfig } from '../src/types';
11+
12+
const config: PackageConfig = {
13+
nameMapping: {},
14+
missingInRN: [],
15+
extraInRN: [],
16+
differentShape: [],
17+
};
18+
19+
export default config;

.github/scripts/compare-types/src/registry.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import appCheckConfig from '../configs/app-check';
1818
import firestoreConfig from '../configs/firestore';
1919
import firestorePipelinesConfig from '../configs/firestore-pipelines';
2020
import remoteConfigConfig from '../configs/remote-config';
21+
import installationsConfig from '../configs/installations';
2122
import perfConfig from '../configs/perf-config';
2223

2324
const SCRIPT_DIR = path.resolve(__dirname, '..');
@@ -197,6 +198,18 @@ export const packages: PackageEntry[] = [
197198
],
198199
config: appCheckConfig,
199200
},
201+
{
202+
name: 'installations',
203+
firebaseSdkTypesPaths: [
204+
requiredFirebaseTypes('installations'),
205+
],
206+
rnFirebaseModularFiles: [
207+
path.join(rnDist('installations'), 'types', 'installations.d.ts'),
208+
path.join(rnDist('installations'), 'modular.d.ts'),
209+
],
210+
rnFirebaseSupportFiles: [path.join(rnDist('installations'), 'types', 'internal.d.ts')],
211+
config: installationsConfig,
212+
},
200213
{
201214
name: 'firestore',
202215
firebaseSdkTypesPaths: [requiredFirebaseTypes('firestore')],

packages/installations/__tests__/installations.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ describe('installations()', function () {
109109
const installations = getInstallations();
110110
installationsV9Deprecation(
111111
() => deleteInstallations(installations),
112+
// @ts-expect-error Combines modular and namespace API
112113
() => installations.delete(),
113114
'delete',
114115
);
@@ -118,6 +119,7 @@ describe('installations()', function () {
118119
const installations = getInstallations();
119120
installationsV9Deprecation(
120121
() => getId(installations),
122+
// @ts-expect-error Combines modular and namespace API
121123
() => installations.getId(),
122124
'getId',
123125
);
@@ -127,6 +129,7 @@ describe('installations()', function () {
127129
const installations = getInstallations();
128130
installationsV9Deprecation(
129131
() => getToken(installations),
132+
// @ts-expect-error Combines modular and namespace API
130133
() => installations.getToken(),
131134
'getToken',
132135
);

packages/installations/lib/index.d.ts

Lines changed: 0 additions & 173 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
// Export modular/public types.
19+
export type * from './types/installations';
20+
21+
// Export modular API functions.
22+
export * from './modular';
23+
24+
// Export namespaced API.
25+
export type { FirebaseInstallationsTypes } from './types/namespaced';
26+
export * from './namespaced';
27+
export { default } from './namespaced';
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2016-present Invertase Limited & Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this library except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
import { getApp } from '@react-native-firebase/app';
19+
import type { FirebaseApp } from '@react-native-firebase/app';
20+
import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/dist/module/common';
21+
import type {
22+
IdChangeCallbackFn,
23+
IdChangeUnsubscribeFn,
24+
Installations,
25+
} from './types/installations';
26+
import type { InstallationsInternal } from './types/internal';
27+
28+
function withModularDeprecationArg(installations: Installations): InstallationsInternal {
29+
return installations as InstallationsInternal;
30+
}
31+
32+
/**
33+
* Returns an instance of Installations associated with the given FirebaseApp instance.
34+
*/
35+
export function getInstallations(app?: FirebaseApp): Installations {
36+
if (app) {
37+
return getApp(app.name).installations();
38+
}
39+
return getApp().installations();
40+
}
41+
42+
/**
43+
* Deletes the Firebase Installation and all associated data.
44+
*/
45+
export function deleteInstallations(installations: Installations): Promise<void> {
46+
const internalInstallations = withModularDeprecationArg(installations);
47+
return internalInstallations.delete.call(internalInstallations, MODULAR_DEPRECATION_ARG);
48+
}
49+
50+
/**
51+
* Creates a Firebase Installation if there isn't one for the app and returns the Installation ID.
52+
*/
53+
export function getId(installations: Installations): Promise<string> {
54+
const internalInstallations = withModularDeprecationArg(installations);
55+
return internalInstallations.getId.call(internalInstallations, MODULAR_DEPRECATION_ARG);
56+
}
57+
58+
/**
59+
* Returns a Firebase Installations auth token, identifying the current Firebase Installation.
60+
*/
61+
export function getToken(installations: Installations, forceRefresh?: boolean): Promise<string> {
62+
const internalInstallations = withModularDeprecationArg(installations);
63+
return internalInstallations.getToken.call(
64+
internalInstallations,
65+
forceRefresh,
66+
MODULAR_DEPRECATION_ARG,
67+
);
68+
}
69+
70+
/**
71+
* Throw an error since react-native-firebase does not support this method.
72+
*
73+
* Sets a new callback that will get called when Installation ID changes. Returns an unsubscribe function that will remove the callback when called.
74+
*/
75+
export function onIdChange(
76+
_installations: Installations,
77+
_callback: IdChangeCallbackFn,
78+
): IdChangeUnsubscribeFn {
79+
throw new Error('onIdChange() is unsupported by the React Native Firebase SDK.');
80+
}

packages/installations/lib/modular/index.d.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)