reactfire 4.1.1 → 4.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.d.ts CHANGED
@@ -1,55 +1,70 @@
1
- import * as React from 'react';
2
- import type { AppCheck } from 'firebase/app-check';
3
- import type { Auth } from 'firebase/auth';
4
- import type { Analytics } from 'firebase/analytics';
5
- import type { Database } from 'firebase/database';
6
- import type { Firestore } from 'firebase/firestore';
7
- import type { FirebasePerformance } from 'firebase/performance';
8
- import type { FirebaseStorage } from 'firebase/storage';
9
- import type { RemoteConfig } from 'firebase/remote-config';
10
- import { FirebaseApp } from 'firebase/app';
11
- import { ObservableStatus } from './useObservable';
12
- import { ReactFireOptions } from '.';
13
- declare type FirebaseSdks = Analytics | AppCheck | Auth | Database | Firestore | FirebasePerformance | FirebaseStorage | RemoteConfig;
14
- export declare const AppCheckProvider: (props: React.PropsWithChildren<{
15
- sdk: AppCheck;
16
- }>) => JSX.Element;
17
- export declare const AuthProvider: (props: React.PropsWithChildren<{
18
- sdk: Auth;
19
- }>) => JSX.Element;
20
- export declare const AnalyticsProvider: (props: React.PropsWithChildren<{
21
- sdk: Analytics;
22
- }>) => JSX.Element;
23
- export declare const DatabaseProvider: (props: React.PropsWithChildren<{
24
- sdk: Database;
25
- }>) => JSX.Element;
26
- export declare const FirestoreProvider: (props: React.PropsWithChildren<{
27
- sdk: Firestore;
28
- }>) => JSX.Element;
29
- export declare const PerformanceProvider: (props: React.PropsWithChildren<{
30
- sdk: FirebasePerformance;
31
- }>) => JSX.Element;
32
- export declare const StorageProvider: (props: React.PropsWithChildren<{
33
- sdk: FirebaseStorage;
34
- }>) => JSX.Element;
35
- export declare const RemoteConfigProvider: (props: React.PropsWithChildren<{
36
- sdk: RemoteConfig;
37
- }>) => JSX.Element;
38
- export declare const useAppCheck: () => AppCheck;
39
- export declare const useAuth: () => Auth;
40
- export declare const useAnalytics: () => Analytics;
41
- export declare const useDatabase: () => Database;
42
- export declare const useFirestore: () => Firestore;
43
- export declare const usePerformance: () => FirebasePerformance;
44
- export declare const useStorage: () => FirebaseStorage;
45
- export declare const useRemoteConfig: () => RemoteConfig;
46
- declare type InitSdkHook<Sdk extends FirebaseSdks> = (initializer: (firebaseApp: FirebaseApp) => Promise<Sdk>, options?: ReactFireOptions<Sdk>) => ObservableStatus<Sdk>;
47
- export declare const useInitAppCheck: InitSdkHook<AppCheck>;
48
- export declare const useInitAuth: InitSdkHook<Auth>;
49
- export declare const useInitAnalytics: InitSdkHook<Analytics>;
50
- export declare const useInitDatabase: InitSdkHook<Database>;
51
- export declare const useInitFirestore: InitSdkHook<Firestore>;
52
- export declare const useInitPerformance: InitSdkHook<FirebasePerformance>;
53
- export declare const useInitRemoteConfig: InitSdkHook<RemoteConfig>;
54
- export declare const useInitStorage: InitSdkHook<FirebaseStorage>;
55
- export {};
1
+ import * as React from 'react';
2
+ import type { AppCheck } from 'firebase/app-check';
3
+ import type { Auth } from 'firebase/auth';
4
+ import type { Analytics } from 'firebase/analytics';
5
+ import type { Database } from 'firebase/database';
6
+ import type { Firestore } from 'firebase/firestore';
7
+ import type { Functions } from 'firebase/functions';
8
+ import type { FirebasePerformance } from 'firebase/performance';
9
+ import type { FirebaseStorage } from 'firebase/storage';
10
+ import type { RemoteConfig } from 'firebase/remote-config';
11
+ import { FirebaseApp } from 'firebase/app';
12
+ import { ObservableStatus } from './useObservable';
13
+ import { ReactFireOptions } from '.';
14
+ export declare const AppCheckSdkContext: React.Context<AppCheck | undefined>;
15
+ export declare const AuthSdkContext: React.Context<Auth | undefined>;
16
+ export declare const AnalyticsSdkContext: React.Context<Analytics | undefined>;
17
+ export declare const DatabaseSdkContext: React.Context<Database | undefined>;
18
+ export declare const FirestoreSdkContext: React.Context<Firestore | undefined>;
19
+ export declare const FunctionsSdkContext: React.Context<Functions | undefined>;
20
+ export declare const StorageSdkContext: React.Context<FirebaseStorage | undefined>;
21
+ export declare const PerformanceSdkContext: React.Context<FirebasePerformance | undefined>;
22
+ export declare const RemoteConfigSdkContext: React.Context<RemoteConfig | undefined>;
23
+ declare type FirebaseSdks = Analytics | AppCheck | Auth | Database | Firestore | FirebasePerformance | FirebaseStorage | Functions | RemoteConfig;
24
+ export declare const AppCheckProvider: (props: React.PropsWithChildren<{
25
+ sdk: AppCheck;
26
+ }>) => JSX.Element;
27
+ export declare const AuthProvider: (props: React.PropsWithChildren<{
28
+ sdk: Auth;
29
+ }>) => JSX.Element;
30
+ export declare const AnalyticsProvider: (props: React.PropsWithChildren<{
31
+ sdk: Analytics;
32
+ }>) => JSX.Element;
33
+ export declare const DatabaseProvider: (props: React.PropsWithChildren<{
34
+ sdk: Database;
35
+ }>) => JSX.Element;
36
+ export declare const FirestoreProvider: (props: React.PropsWithChildren<{
37
+ sdk: Firestore;
38
+ }>) => JSX.Element;
39
+ export declare const FunctionsProvider: (props: React.PropsWithChildren<{
40
+ sdk: Functions;
41
+ }>) => JSX.Element;
42
+ export declare const PerformanceProvider: (props: React.PropsWithChildren<{
43
+ sdk: FirebasePerformance;
44
+ }>) => JSX.Element;
45
+ export declare const StorageProvider: (props: React.PropsWithChildren<{
46
+ sdk: FirebaseStorage;
47
+ }>) => JSX.Element;
48
+ export declare const RemoteConfigProvider: (props: React.PropsWithChildren<{
49
+ sdk: RemoteConfig;
50
+ }>) => JSX.Element;
51
+ export declare const useAppCheck: () => AppCheck;
52
+ export declare const useAuth: () => Auth;
53
+ export declare const useAnalytics: () => Analytics;
54
+ export declare const useDatabase: () => Database;
55
+ export declare const useFirestore: () => Firestore;
56
+ export declare const useFunctions: () => Functions;
57
+ export declare const usePerformance: () => FirebasePerformance;
58
+ export declare const useStorage: () => FirebaseStorage;
59
+ export declare const useRemoteConfig: () => RemoteConfig;
60
+ declare type InitSdkHook<Sdk extends FirebaseSdks> = (initializer: (firebaseApp: FirebaseApp) => Promise<Sdk>, options?: ReactFireOptions<Sdk>) => ObservableStatus<Sdk>;
61
+ export declare const useInitAppCheck: InitSdkHook<AppCheck>;
62
+ export declare const useInitAuth: InitSdkHook<Auth>;
63
+ export declare const useInitAnalytics: InitSdkHook<Analytics>;
64
+ export declare const useInitDatabase: InitSdkHook<Database>;
65
+ export declare const useInitFirestore: InitSdkHook<Firestore>;
66
+ export declare const useInitFunctions: InitSdkHook<Functions>;
67
+ export declare const useInitPerformance: InitSdkHook<FirebasePerformance>;
68
+ export declare const useInitRemoteConfig: InitSdkHook<RemoteConfig>;
69
+ export declare const useInitStorage: InitSdkHook<FirebaseStorage>;
70
+ export {};
package/dist/storage.d.ts CHANGED
@@ -1,26 +1,26 @@
1
- import * as React from 'react';
2
- import { ReactFireOptions, ObservableStatus } from './';
3
- import type { UploadTask, UploadTaskSnapshot, StorageReference, FirebaseStorage } from 'firebase/storage';
4
- /**
5
- * Subscribe to the progress of a storage task
6
- *
7
- * @param task - the task you want to listen to
8
- * @param ref - reference to the blob the task is acting on
9
- * @param options
10
- */
11
- export declare function useStorageTask<T = unknown>(task: UploadTask, ref: StorageReference, options?: ReactFireOptions<T>): ObservableStatus<UploadTaskSnapshot | T>;
12
- /**
13
- * Subscribe to a storage ref's download URL
14
- *
15
- * @param ref - reference to the blob you want to download
16
- * @param options
17
- */
18
- export declare function useStorageDownloadURL<T = string>(ref: StorageReference, options?: ReactFireOptions<T>): ObservableStatus<string | T>;
19
- declare type StorageImageProps = {
20
- storagePath: string;
21
- storage?: FirebaseStorage;
22
- suspense?: boolean;
23
- placeHolder?: JSX.Element;
24
- };
25
- export declare function StorageImage(props: StorageImageProps & React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>): JSX.Element;
26
- export {};
1
+ import * as React from 'react';
2
+ import { ReactFireOptions, ObservableStatus } from './';
3
+ import type { UploadTask, UploadTaskSnapshot, StorageReference, FirebaseStorage } from 'firebase/storage';
4
+ /**
5
+ * Subscribe to the progress of a storage task
6
+ *
7
+ * @param task - the task you want to listen to
8
+ * @param ref - reference to the blob the task is acting on
9
+ * @param options
10
+ */
11
+ export declare function useStorageTask<T = unknown>(task: UploadTask, ref: StorageReference, options?: ReactFireOptions<T>): ObservableStatus<UploadTaskSnapshot | T>;
12
+ /**
13
+ * Subscribe to a storage ref's download URL
14
+ *
15
+ * @param ref - reference to the blob you want to download
16
+ * @param options
17
+ */
18
+ export declare function useStorageDownloadURL<T = string>(ref: StorageReference, options?: ReactFireOptions<T>): ObservableStatus<string | T>;
19
+ declare type StorageImageProps = {
20
+ storagePath: string;
21
+ storage?: FirebaseStorage;
22
+ suspense?: boolean;
23
+ placeHolder?: JSX.Element;
24
+ };
25
+ export declare function StorageImage(props: StorageImageProps & React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>): JSX.Element;
26
+ export {};
@@ -1,41 +1,41 @@
1
- import { Observable } from 'rxjs';
2
- import { SuspenseSubject } from './SuspenseSubject';
3
- import { ReactFireOptions } from './';
4
- export declare function preloadObservable<T>(source: Observable<T>, id: string): SuspenseSubject<T>;
5
- export interface ObservableStatus<T> {
6
- /**
7
- * The loading status.
8
- *
9
- * - `loading`: Waiting for the first value from an observable
10
- * - `error`: Something went wrong. Check `ObservableStatus.error` for more details
11
- * - `success`: The hook has emitted at least one value
12
- *
13
- * If `initialData` is passed in, this will skip `loading` and go straight to `success`.
14
- */
15
- status: 'loading' | 'error' | 'success';
16
- /**
17
- * Indicates whether the hook has emitted a value at some point
18
- *
19
- * If `initialData` is passed in, this will be `true`.
20
- */
21
- hasEmitted: boolean;
22
- /**
23
- * If this is `true`, the hook will be emitting no further items.
24
- */
25
- isComplete: boolean;
26
- /**
27
- * The most recent value.
28
- *
29
- * If `initialData` is passed in, the first value of `data` will be the valuea provided in `initialData` **UNLESS** the underlying observable is ready, in which case it will skip `initialData`.
30
- */
31
- data: T;
32
- /**
33
- * Any error that may have occurred in the underlying observable
34
- */
35
- error: Error | undefined;
36
- /**
37
- * Promise that resolves after first emit from observable
38
- */
39
- firstValuePromise: Promise<void>;
40
- }
41
- export declare function useObservable<T = unknown>(observableId: string, source: Observable<T>, config?: ReactFireOptions): ObservableStatus<T>;
1
+ import { Observable } from 'rxjs';
2
+ import { SuspenseSubject } from './SuspenseSubject';
3
+ import { ReactFireOptions } from './';
4
+ export declare function preloadObservable<T>(source: Observable<T>, id: string): SuspenseSubject<T>;
5
+ export interface ObservableStatus<T> {
6
+ /**
7
+ * The loading status.
8
+ *
9
+ * - `loading`: Waiting for the first value from an observable
10
+ * - `error`: Something went wrong. Check `ObservableStatus.error` for more details
11
+ * - `success`: The hook has emitted at least one value
12
+ *
13
+ * If `initialData` is passed in, this will skip `loading` and go straight to `success`.
14
+ */
15
+ status: 'loading' | 'error' | 'success';
16
+ /**
17
+ * Indicates whether the hook has emitted a value at some point
18
+ *
19
+ * If `initialData` is passed in, this will be `true`.
20
+ */
21
+ hasEmitted: boolean;
22
+ /**
23
+ * If this is `true`, the hook will be emitting no further items.
24
+ */
25
+ isComplete: boolean;
26
+ /**
27
+ * The most recent value.
28
+ *
29
+ * If `initialData` is passed in, the first value of `data` will be the valuea provided in `initialData` **UNLESS** the underlying observable is ready, in which case it will skip `initialData`.
30
+ */
31
+ data: T;
32
+ /**
33
+ * Any error that may have occurred in the underlying observable
34
+ */
35
+ error: Error | undefined;
36
+ /**
37
+ * Promise that resolves after first emit from observable
38
+ */
39
+ firstValuePromise: Promise<void>;
40
+ }
41
+ export declare function useObservable<T = unknown>(observableId: string, source: Observable<T>, config?: ReactFireOptions): ObservableStatus<T>;
package/package.json CHANGED
@@ -1,26 +1,35 @@
1
1
  {
2
- "version": "4.1.1",
2
+ "version": "4.2.2",
3
3
  "license": "MIT",
4
- "main": "dist/index.js",
4
+ "type": "module",
5
+ "main": "dist/index.umd.cjs",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.umd.cjs"
10
+ }
11
+ },
5
12
  "typings": "dist/index.d.ts",
6
13
  "files": [
7
14
  "dist",
8
15
  "src"
9
16
  ],
10
17
  "engines": {
11
- "node": ">=10"
18
+ "node": ">=14"
12
19
  },
13
20
  "scripts": {
14
- "start": "tsdx watch",
15
- "build": "tsdx build",
16
- "test:tsdx": "tsdx test",
17
- "test": "firebase emulators:exec --only firestore,database,auth,storage --project=rxfire-525a3 \"tsdx test\"",
18
- "test:firestore": "firebase emulators:exec --only firestore --project=rxfire-525a3 \"tsdx test firestore --verbose\"",
19
- "test:database": "firebase emulators:exec --only database --project=rxfire-525a3 \"tsdx test database --verbose\"",
20
- "test:auth": "firebase emulators:exec --only auth --project=rxfire-525a3 \"tsdx test auth --verbose\"",
21
- "test:storage": "firebase emulators:exec --only storage --project=rxfire-525a3 \"tsdx test storage --verbose\"",
22
- "test:useObservable": "tsdx test useObservable --verbose",
23
- "lint": "tsdx lint src test",
21
+ "start": "firebase emulators:exec --project=rxfire-525a3 \"vitest --ui\"",
22
+ "build": "tsc && vite build && npm run docs",
23
+ "test": "firebase emulators:exec --project=rxfire-525a3 \"vitest\"",
24
+ "test:firestore": "firebase emulators:exec --only firestore --ui --project=rxfire-525a3 \"vitest firestore\"",
25
+ "test:database": "firebase emulators:exec --only database --project=rxfire-525a3 \"vitest database\"",
26
+ "test:auth": "firebase emulators:exec --only auth --project=rxfire-525a3 \"vitest auth\"",
27
+ "test:functions": "firebase emulators:exec --only functions --project=rxfire-525a3 \"vitest functions\"",
28
+ "test:storage": "firebase emulators:exec --only storage --project=rxfire-525a3 \"vitest storage\"",
29
+ "test:useObservable": "vitest useObservable",
30
+ "test:firebaseApp": "vitest firebaseApp",
31
+ "format": "prettier src test vite.config.ts -w",
32
+ "lint": "eslint src/* test/* vite.config.ts",
24
33
  "size": "size-limit",
25
34
  "analyze": "size-limit --why",
26
35
  "docs": "typedoc --options typedoc.json && markdown-toc -i docs/use.md",
@@ -32,18 +41,9 @@
32
41
  },
33
42
  "husky": {
34
43
  "hooks": {
35
- "pre-commit": "yarn lint"
44
+ "pre-commit": "npm run lint"
36
45
  }
37
46
  },
38
- "eslint": {
39
- "rules": {
40
- "react-hooks/rules-of-hooks": "error",
41
- "no-only-tests/no-only-tests": "error"
42
- },
43
- "plugins": [
44
- "no-only-tests"
45
- ]
46
- },
47
47
  "prettier": {
48
48
  "singleQuote": true,
49
49
  "printWidth": 160
@@ -59,7 +59,7 @@
59
59
  "url": "https://github.com/Firebase/reactfire/issues"
60
60
  },
61
61
  "homepage": "https://firebaseopensource.com/projects/firebaseextended/reactfire/",
62
- "module": "dist/reactfire.esm.js",
62
+ "module": "./dist/index.js",
63
63
  "size-limit": [
64
64
  {
65
65
  "path": "dist/reactfire.cjs.production.min.js",
@@ -71,42 +71,43 @@
71
71
  }
72
72
  ],
73
73
  "devDependencies": {
74
- "@babel/core": "^7.11.6",
75
- "@size-limit/preset-small-lib": "^4.6.0",
76
- "@testing-library/jest-dom": "^5.11.4",
77
- "@testing-library/react": "^11.2.6",
78
- "@testing-library/react-hooks": "^5.1.1",
79
- "@types/node-fetch": "^2.5.7",
80
- "@types/react": "^17.0.15",
81
- "@types/react-dom": "^17.0.9",
82
- "babel-jest": "^26.6.3",
83
- "babel-plugin-minify-replace": "^0.5.0",
74
+ "@rollup/plugin-typescript": "^8.3.4",
75
+ "@size-limit/preset-small-lib": "^7.0.8",
76
+ "@testing-library/jest-dom": "^5.16.4",
77
+ "@testing-library/react": "^12.1.5",
78
+ "@testing-library/react-hooks": "^8.0.1",
79
+ "@types/react": "^17.0.2",
80
+ "@types/react-dom": "^17.0.2",
81
+ "@typescript-eslint/eslint-plugin": "^5.32.0",
82
+ "@typescript-eslint/parser": "^5.32.0",
83
+ "@vitejs/plugin-react": "^2.0.0",
84
+ "@vitest/ui": "^0.20.3",
85
+ "cross-fetch": "^3.1.5",
86
+ "eslint": "^8.20.0",
84
87
  "eslint-plugin-no-only-tests": "^2.6.0",
85
- "firebase": "^9.0.1",
86
- "firebase-tools": "^9.16.0",
87
- "globalthis": "^1.0.1",
88
- "husky": "^4.3.0",
89
- "jest-environment-jsdom": "^26.6.2",
88
+ "eslint-plugin-react": "^7.30.1",
89
+ "eslint-plugin-react-hooks": "^4.6.0",
90
+ "firebase": "^9.9.0",
91
+ "firebase-tools": "^11.3.0",
92
+ "globalthis": "^1.0.3",
93
+ "husky": "^8.0.1",
94
+ "jest-environment-jsdom": "^28.1.3",
95
+ "jsdom": "^20.0.0",
90
96
  "markdown-toc": "^1.2.0",
91
- "node-fetch": "^2.6.1",
97
+ "prettier": "^2.7.1",
92
98
  "react": "^17.0.2",
93
99
  "react-dom": "^17.0.2",
94
100
  "react-test-renderer": "^17.0.2",
95
- "size-limit": "^4.6.0",
96
- "tsdx": "^0.14.1",
97
- "tslib": "^2.2.0",
98
- "typedoc": "^0.21.2",
99
- "typedoc-plugin-markdown": "^3.6.1",
100
- "typescript": "^4.2.4"
101
+ "rollup-plugin-visualizer": "^5.7.1",
102
+ "size-limit": "^7.0.8",
103
+ "typedoc": "^0.23.8",
104
+ "typedoc-plugin-markdown": "^3.13.3",
105
+ "typescript": "^4.7.4",
106
+ "vite": "^3.0.2",
107
+ "vitest": "^0.18.1"
101
108
  },
102
109
  "dependencies": {
103
- "rxfire": "^6.0.0",
110
+ "rxfire": "^6.0.3",
104
111
  "rxjs": "^6.6.3 || ^7.0.1"
105
- },
106
- "resolutions": {
107
- "tsdx/**/jest": "^26.6.3",
108
- "tsdx/**/ts-jest": "^26.5.5",
109
- "tsdx/**/prettier": "^2.2.1",
110
- "tsdx/**/typescript": "^4.2.4"
111
112
  }
112
113
  }
package/src/auth.tsx CHANGED
@@ -24,15 +24,15 @@ export function useUser<T = unknown>(options?: ReactFireOptions<T>): ObservableS
24
24
 
25
25
  const observableId = `auth:user:${auth.name}`;
26
26
  const observable$ = user(auth);
27
+ const _options: ReactFireOptions<T> = { ...options } ?? {};
27
28
 
28
- let currentUser = auth.currentUser;
29
-
30
- // Only use options.initialData if auth.currentUser is unavailable
31
- if (!currentUser && (options?.initialData ?? options?.startWithValue)) {
32
- currentUser = options.initialData ?? options.startWithValue;
29
+ // only set/override initialData if auth has finished loading
30
+ if (auth.currentUser !== undefined) {
31
+ _options.initialData = auth.currentUser;
32
+ _options.startWithValue = auth.currentUser;
33
33
  }
34
34
 
35
- return useObservable(observableId, observable$, { ...options, initialData: currentUser });
35
+ return useObservable(observableId, observable$, _options);
36
36
  }
37
37
 
38
38
  export function useIdTokenResult(user: User, forceRefresh: boolean = false, options?: ReactFireOptions<IdTokenResult>): ObservableStatus<IdTokenResult> {
@@ -16,8 +16,8 @@ interface FirebaseAppProviderProps {
16
16
  suspense?: boolean;
17
17
  }
18
18
 
19
- // @ts-expect-error: "__REACTFIRE_VERSION__" is replaced with actual ReactFire version (see babel.config.js)
20
- export const version = __REACTFIRE_VERSION__;
19
+ // REACTFIRE_VERSION is automatically pulled in from `package.json` by Vite
20
+ export const version = process.env.REACTFIRE_VERSION as string;
21
21
 
22
22
  const shallowEq = (a: { [key: string]: any }, b: { [key: string]: any }) => a === b || [...Object.keys(a), ...Object.keys(b)].every((key) => a[key] === b[key]);
23
23
 
@@ -0,0 +1,26 @@
1
+ import { httpsCallable as rxHttpsCallable } from 'rxfire/functions';
2
+ import { ReactFireOptions, useObservable, ObservableStatus } from './';
3
+ import { useFunctions } from '.';
4
+
5
+ import type { HttpsCallableOptions } from 'firebase/functions';
6
+
7
+ /**
8
+ * Calls a callable function.
9
+ *
10
+ * @param functionName - The name of the function to call
11
+ * @param options
12
+ */
13
+ export function useCallableFunctionResponse<RequestData, ResponseData>(
14
+ functionName: string,
15
+ options?: ReactFireOptions<ResponseData> & {
16
+ httpsCallableOptions?: HttpsCallableOptions;
17
+ data?: RequestData;
18
+ }
19
+ ): ObservableStatus<ResponseData> {
20
+ const functions = useFunctions();
21
+ const observableId = `functions:callableResponse:${functionName}:${JSON.stringify(options?.data)}:${JSON.stringify(options?.httpsCallableOptions)}`;
22
+ const obsFactory = rxHttpsCallable<RequestData, ResponseData>(functions, functionName, options?.httpsCallableOptions);
23
+ const observable$ = obsFactory(options?.data);
24
+
25
+ return useObservable(observableId, observable$, options);
26
+ }
package/src/index.ts CHANGED
@@ -52,6 +52,7 @@ export * from './auth';
52
52
  export * from './database';
53
53
  export * from './firebaseApp';
54
54
  export * from './firestore';
55
+ export * from './functions';
55
56
  export * from './performance';
56
57
  export * from './remote-config';
57
58
  export * from './storage';
package/src/sdk.tsx CHANGED
@@ -5,6 +5,7 @@ import type { Auth } from 'firebase/auth';
5
5
  import type { Analytics } from 'firebase/analytics';
6
6
  import type { Database } from 'firebase/database';
7
7
  import type { Firestore } from 'firebase/firestore';
8
+ import type { Functions } from 'firebase/functions';
8
9
  import type { FirebasePerformance } from 'firebase/performance';
9
10
  import type { FirebaseStorage } from 'firebase/storage';
10
11
  import type { RemoteConfig } from 'firebase/remote-config';
@@ -14,16 +15,17 @@ import { ObservableStatus, useObservable } from './useObservable';
14
15
  import { from } from 'rxjs';
15
16
  import { ReactFireOptions } from '.';
16
17
 
17
- const AppCheckSdkContext = React.createContext<AppCheck | undefined>(undefined);
18
- const AuthSdkContext = React.createContext<Auth | undefined>(undefined);
19
- const AnalyticsSdkContext = React.createContext<Analytics | undefined>(undefined);
20
- const DatabaseSdkContext = React.createContext<Database | undefined>(undefined);
21
- const FirestoreSdkContext = React.createContext<Firestore | undefined>(undefined);
22
- const StorageSdkContext = React.createContext<FirebaseStorage | undefined>(undefined);
23
- const PerformanceSdkContext = React.createContext<FirebasePerformance | undefined>(undefined);
24
- const RemoteConfigSdkContext = React.createContext<RemoteConfig | undefined>(undefined);
18
+ export const AppCheckSdkContext = React.createContext<AppCheck | undefined>(undefined);
19
+ export const AuthSdkContext = React.createContext<Auth | undefined>(undefined);
20
+ export const AnalyticsSdkContext = React.createContext<Analytics | undefined>(undefined);
21
+ export const DatabaseSdkContext = React.createContext<Database | undefined>(undefined);
22
+ export const FirestoreSdkContext = React.createContext<Firestore | undefined>(undefined);
23
+ export const FunctionsSdkContext = React.createContext<Functions | undefined>(undefined);
24
+ export const StorageSdkContext = React.createContext<FirebaseStorage | undefined>(undefined);
25
+ export const PerformanceSdkContext = React.createContext<FirebasePerformance | undefined>(undefined);
26
+ export const RemoteConfigSdkContext = React.createContext<RemoteConfig | undefined>(undefined);
25
27
 
26
- type FirebaseSdks = Analytics | AppCheck | Auth | Database | Firestore | FirebasePerformance | FirebaseStorage | RemoteConfig;
28
+ type FirebaseSdks = Analytics | AppCheck | Auth | Database | Firestore | FirebasePerformance | FirebaseStorage | Functions | RemoteConfig;
27
29
 
28
30
  function getSdkProvider<Sdk extends FirebaseSdks>(SdkContext: React.Context<Sdk | undefined>) {
29
31
  return function SdkProvider(props: React.PropsWithChildren<{ sdk: Sdk }>) {
@@ -72,6 +74,7 @@ export const AuthProvider = getSdkProvider<Auth>(AuthSdkContext);
72
74
  export const AnalyticsProvider = getSdkProvider<Analytics>(AnalyticsSdkContext);
73
75
  export const DatabaseProvider = getSdkProvider<Database>(DatabaseSdkContext);
74
76
  export const FirestoreProvider = getSdkProvider<Firestore>(FirestoreSdkContext);
77
+ export const FunctionsProvider = getSdkProvider<Functions>(FunctionsSdkContext);
75
78
  export const PerformanceProvider = getSdkProvider<FirebasePerformance>(PerformanceSdkContext);
76
79
  export const StorageProvider = getSdkProvider<FirebaseStorage>(StorageSdkContext);
77
80
  export const RemoteConfigProvider = getSdkProvider<RemoteConfig>(RemoteConfigSdkContext);
@@ -81,6 +84,7 @@ export const useAuth = () => useSdk<Auth>(AuthSdkContext);
81
84
  export const useAnalytics = () => useSdk<Analytics>(AnalyticsSdkContext);
82
85
  export const useDatabase = () => useSdk<Database>(DatabaseSdkContext);
83
86
  export const useFirestore = () => useSdk<Firestore>(FirestoreSdkContext);
87
+ export const useFunctions = () => useSdk<Functions>(FunctionsSdkContext);
84
88
  export const usePerformance = () => useSdk<FirebasePerformance>(PerformanceSdkContext);
85
89
  export const useStorage = () => useSdk<FirebaseStorage>(StorageSdkContext);
86
90
  export const useRemoteConfig = () => useSdk<RemoteConfig>(RemoteConfigSdkContext);
@@ -95,6 +99,7 @@ export const useInitAuth: InitSdkHook<Auth> = (initializer, options) => useInitS
95
99
  export const useInitAnalytics: InitSdkHook<Analytics> = (initializer, options) => useInitSdk<Analytics>('analytics', AnalyticsSdkContext, initializer, options);
96
100
  export const useInitDatabase: InitSdkHook<Database> = (initializer, options) => useInitSdk<Database>('database', DatabaseSdkContext, initializer, options);
97
101
  export const useInitFirestore: InitSdkHook<Firestore> = (initializer, options) => useInitSdk<Firestore>('firestore', FirestoreSdkContext, initializer, options);
102
+ export const useInitFunctions: InitSdkHook<Functions> = (initializer, options) => useInitSdk<Functions>('functions', FunctionsSdkContext, initializer, options);
98
103
  export const useInitPerformance: InitSdkHook<FirebasePerformance> = (initializer, options) =>
99
104
  useInitSdk<FirebasePerformance>('performance', PerformanceSdkContext, initializer, options);
100
105
  export const useInitRemoteConfig: InitSdkHook<RemoteConfig> = (initializer, options) =>
package/src/storage.tsx CHANGED
@@ -1,33 +1,11 @@
1
1
  import * as React from 'react';
2
- import { getDownloadURL } from 'rxfire/storage';
3
- import { Observable } from 'rxjs';
2
+ import { getDownloadURL, fromTask } from 'rxfire/storage';
4
3
  import { ReactFireOptions, useObservable, ObservableStatus, useStorage } from './';
5
4
  import { useSuspenseEnabledFromConfigAndContext } from './firebaseApp';
6
5
  import { ref } from 'firebase/storage';
7
6
 
8
7
  import type { UploadTask, UploadTaskSnapshot, StorageReference, FirebaseStorage } from 'firebase/storage';
9
8
 
10
- /**
11
- * modified version of rxFire's _fromTask
12
- *
13
- * @param task
14
- */
15
- function _fromTask(task: UploadTask) {
16
- return new Observable<UploadTaskSnapshot>((subscriber) => {
17
- const progress = (snap: UploadTaskSnapshot) => {
18
- return subscriber.next(snap);
19
- };
20
- const error = (e: any) => subscriber.error(e);
21
- const complete = () => {
22
- return subscriber.complete();
23
- };
24
- task.on('state_changed', progress, error, complete);
25
-
26
- // I REMOVED THE UNSUBSCRIBE RETURN BECAUSE IT CANCELS THE UPLOAD
27
- // https://github.com/firebase/firebase-js-sdk/issues/1659
28
- });
29
- }
30
-
31
9
  /**
32
10
  * Subscribe to the progress of a storage task
33
11
  *
@@ -37,7 +15,7 @@ function _fromTask(task: UploadTask) {
37
15
  */
38
16
  export function useStorageTask<T = unknown>(task: UploadTask, ref: StorageReference, options?: ReactFireOptions<T>): ObservableStatus<UploadTaskSnapshot | T> {
39
17
  const observableId = `storage:task:${ref.toString()}`;
40
- const observable$ = _fromTask(task);
18
+ const observable$ = fromTask(task);
41
19
 
42
20
  return useObservable(observableId, observable$, options);
43
21
  }