Skip to content

Commit 14967b1

Browse files
Merge branch 'main' into cloud-functions-streaming
2 parents 9245d6d + dc28a77 commit 14967b1

95 files changed

Lines changed: 3154 additions & 1598 deletions

File tree

Some content is hidden

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

eslint.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ export default [
4141
'**/type-test.ts',
4242
'packages/**/modular/dist/**/*',
4343
'packages/ai/__tests__/test-utils',
44+
'packages/**/dist/**/*',
4445
'packages/vertexai/__tests__/test-utils',
45-
'packages/vertexai/dist',
46-
'packages/ai/dist',
4746
],
4847
},
4948
...compat

jest.setup.ts

Lines changed: 335 additions & 7 deletions
Large diffs are not rendered by default.

packages/ai/tsconfig.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
"esModuleInterop": true,
77
"forceConsistentCasingInFileNames": true,
88
"jsx": "react-jsx",
9-
"lib": [
10-
"ESNext"
11-
],
9+
"lib": ["ESNext"],
1210
"module": "ESNext",
1311
"target": "ESNext",
1412
"moduleResolution": "Bundler",
@@ -24,9 +22,20 @@
2422
"strict": true,
2523
"baseUrl": ".",
2624
"paths": {
27-
"@react-native-firebase/app": ["../app/lib"],
25+
"@react-native-firebase/app/lib/common/*": ["../app/dist/typescript/commonjs/lib/common/*"],
26+
"@react-native-firebase/app/lib/common": ["../app/dist/typescript/commonjs/lib/common"],
27+
"@react-native-firebase/app/lib/internal/web/*": [
28+
"../app/dist/typescript/commonjs/lib/internal/web/*"
29+
],
30+
"@react-native-firebase/app/lib/internal/*": [
31+
"../app/dist/typescript/commonjs/lib/internal/*"
32+
],
33+
"@react-native-firebase/app/lib/internal": ["../app/dist/typescript/commonjs/lib/internal"],
34+
"@react-native-firebase/app": ["../app/dist/typescript/commonjs/lib"],
2835
"@react-native-firebase/auth": ["../auth/lib"],
29-
"@react-native-firebase/app-check": ["../app-check/lib"],
36+
"@react-native-firebase/app-check": ["../app-check/lib"]
3037
}
31-
}
38+
},
39+
"include": ["lib/**/*"],
40+
"exclude": ["node_modules", "dist", "__tests__", "**/*.test.ts"]
3241
}
Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,26 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
import { warnIfNotModularCall } from '@react-native-firebase/app/lib/common';
17+
import { warnIfNotModularCall } from './common';
1818
import { getAppModule } from './internal/registry/nativeModule';
19+
import type { ReactNativeFirebase, Utils } from './types/app';
1920

20-
export default class FirebaseApp {
21-
constructor(options, appConfig, fromNative, deleteApp) {
22-
const { name, automaticDataCollectionEnabled } = appConfig;
21+
export default class FirebaseApp implements ReactNativeFirebase.FirebaseAppBase {
22+
private _name: string;
23+
private _deleted: boolean;
24+
private _deleteApp: () => Promise<void>;
25+
private _options: ReactNativeFirebase.FirebaseAppOptions;
26+
private _automaticDataCollectionEnabled: boolean;
27+
_initialized: boolean;
28+
_nativeInitialized: boolean;
29+
30+
constructor(
31+
options: ReactNativeFirebase.FirebaseAppOptions,
32+
appConfig: ReactNativeFirebase.FirebaseAppConfig,
33+
fromNative: boolean,
34+
deleteApp: () => Promise<void>,
35+
) {
36+
const { name = '[DEFAULT]', automaticDataCollectionEnabled } = appConfig;
2337

2438
this._name = name;
2539
this._deleted = false;
@@ -36,44 +50,49 @@ export default class FirebaseApp {
3650
}
3751
}
3852

39-
get name() {
53+
get name(): string {
4054
return this._name;
4155
}
4256

43-
get options() {
57+
get options(): ReactNativeFirebase.FirebaseAppOptions {
4458
return Object.assign({}, this._options);
4559
}
4660

47-
get automaticDataCollectionEnabled() {
61+
get automaticDataCollectionEnabled(): boolean {
4862
return this._automaticDataCollectionEnabled;
4963
}
5064

51-
set automaticDataCollectionEnabled(enabled) {
65+
set automaticDataCollectionEnabled(enabled: boolean) {
5266
this._checkDestroyed();
5367
getAppModule().setAutomaticDataCollectionEnabled(this.name, enabled);
5468
this._automaticDataCollectionEnabled = enabled;
5569
}
5670

57-
_checkDestroyed() {
71+
private _checkDestroyed(): void {
5872
if (this._deleted) {
5973
throw new Error(`Firebase App named '${this._name}' already deleted`);
6074
}
6175
}
6276

63-
extendApp(extendedProps) {
77+
extendApp(extendedProps: Record<string, unknown>): void {
6478
warnIfNotModularCall(arguments);
6579
this._checkDestroyed();
6680
Object.assign(this, extendedProps);
6781
}
6882

69-
delete() {
83+
delete(): Promise<void> {
7084
warnIfNotModularCall(arguments, 'deleteApp()');
7185
this._checkDestroyed();
7286
return this._deleteApp();
7387
}
7488

75-
toString() {
89+
toString(): string {
7690
warnIfNotModularCall(arguments, '.name property');
7791
return this.name;
7892
}
93+
94+
// For backward compatibility - utils method added by registry
95+
utils(): Utils.Module {
96+
throw new Error('utils() should be added by registry');
97+
}
7998
}
Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*
1616
*/
1717

18+
// @ts-expect-error - No type declarations available
1819
import binaryToBase64 from 'react-native/Libraries/Utilities/binaryToBase64';
1920
import { promiseDefer } from './promise';
2021

@@ -23,7 +24,7 @@ const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
2324
/**
2425
* window.btoa
2526
*/
26-
function btoa(input) {
27+
function btoa(input: string): string {
2728
let map;
2829
let i = 0;
2930
let block = 0;
@@ -51,11 +52,11 @@ function btoa(input) {
5152
/**
5253
* window.atob
5354
*/
54-
function atob(input) {
55+
function atob(input: string): string {
5556
let i = 0;
5657
let bc = 0;
5758
let bs = 0;
58-
let buffer;
59+
let buffer: number | string;
5960
let output = '';
6061

6162
const str = input.replace(/[=]+$/, '');
@@ -69,7 +70,7 @@ function atob(input) {
6970
for (
7071
bc = 0, bs = 0, i = 0;
7172
(buffer = str.charAt(i++));
72-
~buffer && ((bs = bc % 4 ? bs * 64 + buffer : buffer), bc++ % 4)
73+
~buffer && ((bs = bc % 4 ? bs * 64 + (buffer as number) : buffer), bc++ % 4)
7374
? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6))))
7475
: 0
7576
) {
@@ -79,23 +80,30 @@ function atob(input) {
7980
return output;
8081
}
8182

83+
export interface Base64Result {
84+
string: string | ArrayBuffer | null;
85+
format: 'data_url' | 'base64';
86+
}
87+
8288
/**
8389
* Converts a Blob, ArrayBuffer or Uint8Array to a base64 string.
8490
*/
85-
function fromData(data) {
91+
function fromData(data: Blob | ArrayBuffer | Uint8Array): Promise<Base64Result> {
8692
if (data instanceof Blob) {
8793
const fileReader = new FileReader();
88-
const { resolve, reject, promise } = promiseDefer();
94+
const { resolve, reject, promise } = promiseDefer<Base64Result>();
8995

9096
fileReader.readAsDataURL(data);
9197

92-
fileReader.onloadend = function onloadend() {
93-
resolve({ string: fileReader.result, format: 'data_url' });
98+
fileReader.onloadend = () => {
99+
if (fileReader?.result) {
100+
resolve?.({ string: fileReader.result, format: 'data_url' });
101+
}
94102
};
95103

96-
fileReader.onerror = function onerror(event) {
97-
fileReader.abort();
98-
reject(event);
104+
fileReader.onerror = event => {
105+
fileReader?.abort();
106+
reject?.(event);
99107
};
100108

101109
return promise;

packages/app/lib/common/MutatableParams.js renamed to packages/app/lib/common/MutatableParams.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
import { deepGet, deepSet } from './deeps';
1919

2020
export default class MutatableParams {
21-
constructor(parentInstance) {
21+
_mutatableParams: Record<string, unknown>;
22+
_parentInstance: MutatableParams;
23+
24+
constructor(parentInstance?: MutatableParams) {
2225
if (parentInstance) {
2326
this._mutatableParams = parentInstance._mutatableParams;
2427
this._parentInstance = parentInstance;
@@ -28,20 +31,20 @@ export default class MutatableParams {
2831
}
2932
}
3033

31-
set(param, value) {
34+
set(param: string, value: unknown): MutatableParams {
3235
deepSet(this._mutatableParams, param, value);
3336
return this._parentInstance;
3437
}
3538

36-
get(param) {
37-
return deepGet(this._mutatableParams, param, '.');
39+
get<T = unknown>(param: string): T | undefined {
40+
return deepGet<T>(this._mutatableParams, param, '.');
3841
}
3942

40-
toJSON() {
43+
toJSON(): Record<string, unknown> {
4144
return Object.assign({}, this._mutatableParams);
4245
}
4346

44-
validate() {
47+
validate(): void {
4548
// do nothing
4649
}
4750
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
*/
1717

1818
export default class ReferenceBase {
19-
constructor(_path) {
19+
path: string;
20+
21+
constructor(_path: string) {
2022
let path = _path;
2123

2224
if (path) {
@@ -37,7 +39,7 @@ export default class ReferenceBase {
3739
* @type {String}
3840
* {@link https://firebase.google.com/docs/reference/js/firebase.database.Reference#key}
3941
*/
40-
get key() {
42+
get key(): string | null {
4143
return this.path === '/' ? null : this.path.substring(this.path.lastIndexOf('/') + 1);
4244
}
4345
}
Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,29 @@ import { isArray, isObject } from './validate';
2525
* @param joiner
2626
* @returns {*}
2727
*/
28-
export function deepGet(object, path, joiner = '/') {
28+
export function deepGet<T = unknown>(
29+
object: Record<string, unknown> | unknown[],
30+
path: string,
31+
joiner: string = '/',
32+
): T | undefined {
2933
if (!isObject(object) && !Array.isArray(object)) {
3034
return undefined;
3135
}
3236
const keys = path.split(joiner);
3337

3438
let i = 0;
35-
let tmp = object;
39+
let tmp: unknown = object;
3640
const len = keys.length;
3741

3842
while (i < len) {
39-
const key = keys[i++];
43+
const key = keys[i++]!;
4044
if (!tmp || !Object.hasOwnProperty.call(tmp, key)) {
4145
return undefined;
4246
}
43-
tmp = tmp[key];
47+
tmp = (tmp as Record<string, unknown>)[key];
4448
}
4549

46-
return tmp;
50+
return tmp as T;
4751
}
4852

4953
/**
@@ -54,26 +58,32 @@ export function deepGet(object, path, joiner = '/') {
5458
* @param initPaths
5559
* @param joiner
5660
*/
57-
export function deepSet(object, path, value, initPaths = true, joiner = '.') {
61+
export function deepSet(
62+
object: Record<string, unknown>,
63+
path: string,
64+
value: unknown,
65+
initPaths: boolean = true,
66+
joiner: string = '.',
67+
): boolean {
5868
if (!isObject(object)) {
5969
return false;
6070
}
6171
const keys = path.split(joiner);
6272

6373
let i = 0;
64-
let _object = object;
74+
let _object: unknown = object;
6575
const len = keys.length - 1;
6676

6777
while (i < len) {
68-
const key = keys[i++];
78+
const key = keys[i++]!;
6979
if (initPaths && !Object.hasOwnProperty.call(object, key)) {
70-
_object[key] = {};
80+
(_object as Record<string, unknown>)[key] = {};
7181
}
72-
_object = _object[key];
82+
_object = (_object as Record<string, unknown>)[key];
7383
}
7484

7585
if (isObject(_object) || (isArray(_object) && !Number.isNaN(keys[i]))) {
76-
_object[keys[i]] = value;
86+
(_object as Record<string, unknown>)[keys[i]!] = value;
7787
} else {
7888
return false;
7989
}

0 commit comments

Comments
 (0)