reactfire 4.0.0-rc.1 → 4.0.1-exp.f6d2351

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,43 +1,70 @@
1
- import * as React from 'react';
2
- import type { Auth } from 'firebase/auth';
3
- import type { Database } from 'firebase/database';
4
- import type { Firestore } from 'firebase/firestore';
5
- import type { FirebasePerformance } from 'firebase/performance';
6
- import type { FirebaseStorage } from 'firebase/storage';
7
- import type { RemoteConfig } from 'firebase/remote-config';
8
- import { FirebaseApp } from 'firebase/app';
9
- import { ObservableStatus } from './useObservable';
10
- import { ReactFireOptions } from '.';
11
- declare type FirebaseSdks = Auth | Database | Firestore | FirebasePerformance | FirebaseStorage | RemoteConfig;
12
- export declare const AuthProvider: (props: React.PropsWithChildren<{
13
- sdk: Auth;
14
- }>) => JSX.Element;
15
- export declare const DatabaseProvider: (props: React.PropsWithChildren<{
16
- sdk: Database;
17
- }>) => JSX.Element;
18
- export declare const FirestoreProvider: (props: React.PropsWithChildren<{
19
- sdk: Firestore;
20
- }>) => JSX.Element;
21
- export declare const PerformanceProvider: (props: React.PropsWithChildren<{
22
- sdk: FirebasePerformance;
23
- }>) => JSX.Element;
24
- export declare const StorageProvider: (props: React.PropsWithChildren<{
25
- sdk: FirebaseStorage;
26
- }>) => JSX.Element;
27
- export declare const RemoteConfigProvider: (props: React.PropsWithChildren<{
28
- sdk: RemoteConfig;
29
- }>) => JSX.Element;
30
- export declare const useAuth: () => Auth;
31
- export declare const useDatabase: () => Database;
32
- export declare const useFirestore: () => Firestore;
33
- export declare const usePerformance: () => FirebasePerformance;
34
- export declare const useStorage: () => FirebaseStorage;
35
- export declare const useRemoteConfig: () => RemoteConfig;
36
- declare type InitSdkHook<Sdk extends FirebaseSdks> = (initializer: (firebaseApp: FirebaseApp) => Promise<Sdk>, options?: ReactFireOptions<Sdk>) => ObservableStatus<Sdk>;
37
- export declare const useInitAuth: InitSdkHook<Auth>;
38
- export declare const useInitDatabase: InitSdkHook<Database>;
39
- export declare const useInitFirestore: InitSdkHook<Firestore>;
40
- export declare const useInitPerformance: InitSdkHook<FirebasePerformance>;
41
- export declare const useInitRemoteConfig: InitSdkHook<RemoteConfig>;
42
- export declare const useInitStorage: InitSdkHook<FirebaseStorage>;
43
- 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,48 +1,49 @@
1
1
  {
2
- "version": "4.0.0-rc.1",
2
+ "version": "4.0.1-exp.f6d2351",
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
- "docs": "typedoc --options typedoc.json && markdown-toc -i docs/use.md"
35
+ "docs": "typedoc --options typedoc.json && markdown-toc -i docs/use.md",
36
+ "docs:fork": "typedoc --options typedoc.json --gitRemote upstream && markdown-toc -i docs/use.md"
27
37
  },
28
38
  "peerDependencies": {
29
- "firebase": "9.0.0-202171919375",
39
+ "firebase": "^9.0.0",
30
40
  "react": ">=16 || experimental"
31
41
  },
32
42
  "husky": {
33
43
  "hooks": {
34
- "pre-commit": "yarn lint"
44
+ "pre-commit": "npm run lint"
35
45
  }
36
46
  },
37
- "eslint": {
38
- "rules": {
39
- "react-hooks/rules-of-hooks": "error",
40
- "no-only-tests/no-only-tests": "error"
41
- },
42
- "plugins": [
43
- "no-only-tests"
44
- ]
45
- },
46
47
  "prettier": {
47
48
  "singleQuote": true,
48
49
  "printWidth": 160
@@ -58,7 +59,7 @@
58
59
  "url": "https://github.com/Firebase/reactfire/issues"
59
60
  },
60
61
  "homepage": "https://firebaseopensource.com/projects/firebaseextended/reactfire/",
61
- "module": "dist/reactfire.esm.js",
62
+ "module": "./dist/index.js",
62
63
  "size-limit": [
63
64
  {
64
65
  "path": "dist/reactfire.cjs.production.min.js",
@@ -70,42 +71,43 @@
70
71
  }
71
72
  ],
72
73
  "devDependencies": {
73
- "@babel/core": "^7.11.6",
74
- "@size-limit/preset-small-lib": "^4.6.0",
75
- "@testing-library/jest-dom": "^5.11.4",
76
- "@testing-library/react": "^11.2.6",
77
- "@testing-library/react-hooks": "^5.1.1",
78
- "@types/node-fetch": "^2.5.7",
79
- "@types/react": "^17.0.15",
80
- "@types/react-dom": "^17.0.9",
81
- "babel-jest": "^26.6.3",
82
- "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",
83
87
  "eslint-plugin-no-only-tests": "^2.6.0",
84
- "firebase": "9.0.0-202171919375",
85
- "firebase-tools": "^9.16.0",
86
- "globalthis": "^1.0.1",
87
- "husky": "^4.3.0",
88
- "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",
89
96
  "markdown-toc": "^1.2.0",
90
- "node-fetch": "^2.6.1",
97
+ "prettier": "^2.7.1",
91
98
  "react": "^17.0.2",
92
99
  "react-dom": "^17.0.2",
93
100
  "react-test-renderer": "^17.0.2",
94
- "size-limit": "^4.6.0",
95
- "tsdx": "^0.14.1",
96
- "tslib": "^2.2.0",
97
- "typedoc": "^0.21.2",
98
- "typedoc-plugin-markdown": "^3.6.1",
99
- "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"
100
108
  },
101
109
  "dependencies": {
102
- "rxfire": "6.0.0-rc.0",
110
+ "rxfire": "^6.0.3",
103
111
  "rxjs": "^6.6.3 || ^7.0.1"
104
- },
105
- "resolutions": {
106
- "tsdx/**/jest": "^26.6.3",
107
- "tsdx/**/ts-jest": "^26.5.5",
108
- "tsdx/**/prettier": "^2.2.1",
109
- "tsdx/**/typescript": "^4.2.4"
110
112
  }
111
113
  }
@@ -10,9 +10,9 @@ export class SuspenseSubject<T> extends Subject<T> {
10
10
  private _innerObservable: Observable<T>;
11
11
  private _warmupSubscription: Subscription;
12
12
 
13
- // @ts-ignore: TODO: double check to see if this is an RXJS thing or if we should listen to TS
13
+ // @ts-expect-error: TODO: double check to see if this is an RXJS thing or if we should listen to TS
14
14
  private _innerSubscriber: Subscription;
15
- // @ts-ignore: TODO: double check to see if this is an RXJS thing or if we should listen to TS
15
+ // @ts-expect-error: TODO: double check to see if this is an RXJS thing or if we should listen to TS
16
16
  private _resolveFirstEmission: () => void;
17
17
 
18
18
  constructor(innerObservable: Observable<T>, private _timeoutWindow: number) {
@@ -48,14 +48,16 @@ export class SuspenseSubject<T> extends Subject<T> {
48
48
  return this._hasValue || !!this._error;
49
49
  }
50
50
 
51
- get value(): T | undefined {
51
+ get value(): T {
52
52
  // TODO figure out how to reset the cache here, if I _reset() here before throwing
53
53
  // it doesn't seem to work.
54
54
  // As it is now, this will burn the cache entry until the timeout fires.
55
55
  if (this._error) {
56
56
  throw this._error;
57
+ } else if (!this.hasValue) {
58
+ throw Error('Can only get value if SuspenseSubject has a value');
57
59
  }
58
- return this._value;
60
+ return this._value as T;
59
61
  }
60
62
 
61
63
  get firstEmission(): Promise<void> {
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> {
package/src/database.tsx CHANGED
@@ -1,9 +1,6 @@
1
- import { list, object, QueryChange, listVal } from 'rxfire/database';
1
+ import { list, object, QueryChange, listVal, objectVal } from 'rxfire/database';
2
2
  import { ReactFireOptions, useObservable, checkIdField, ObservableStatus, ReactFireGlobals } from './';
3
3
 
4
- import { Observable } from 'rxjs';
5
- import { map } from 'rxjs/operators';
6
-
7
4
  import type { Query as DatabaseQuery, DatabaseReference } from 'firebase/database';
8
5
 
9
6
  // Since we're side-effect free, we need to ensure our observableId cache is global
@@ -34,33 +31,10 @@ export function useDatabaseObject<T = unknown>(ref: DatabaseReference, options?:
34
31
  return useObservable(observableId, observable$, options);
35
32
  }
36
33
 
37
- // ============================================================================
38
- // TODO: switch to rxfire's objectVal once this PR is merged:
39
- // https://github.com/firebase/firebase-js-sdk/pull/2352
40
-
41
- function objectVal<T>(query: DatabaseQuery, keyField?: string): Observable<T> {
42
- return object(query).pipe(map((change) => changeToData(change, keyField) as T));
43
- }
44
-
45
- function changeToData(change: QueryChange, keyField?: string): {} {
46
- const val = change.snapshot.val();
47
-
48
- // don't worry about setting IDs if the value is a primitive type
49
- if (typeof val !== 'object') {
50
- return val;
51
- }
52
-
53
- return {
54
- ...change.snapshot.val(),
55
- ...(keyField ? { [keyField]: change.snapshot.key } : null),
56
- };
57
- }
58
- // ============================================================================
59
-
60
34
  export function useDatabaseObjectData<T>(ref: DatabaseReference, options?: ReactFireOptions<T>): ObservableStatus<T> {
61
35
  const idField = options ? checkIdField(options) : 'NO_ID_FIELD';
62
36
  const observableId = `database:objectVal:${ref.toString()}:idField=${idField}`;
63
- const observable$ = objectVal<T>(ref, idField);
37
+ const observable$ = objectVal<T>(ref, { keyField: idField });
64
38
 
65
39
  return useObservable(observableId, observable$, options);
66
40
  }
@@ -87,6 +61,6 @@ export function useDatabaseListData<T = { [key: string]: unknown }>(
87
61
  ): ObservableStatus<T[] | null> {
88
62
  const idField = options ? checkIdField(options) : 'NO_ID_FIELD';
89
63
  const observableId = `database:listVal:${getUniqueIdForDatabaseQuery(ref)}:idField=${idField}`;
90
- const observable$ = listVal<T>(ref, idField);
64
+ const observable$ = listVal<T>(ref, { keyField: idField });
91
65
  return useObservable(observableId, observable$, options);
92
66
  }
@@ -16,8 +16,8 @@ interface FirebaseAppProviderProps {
16
16
  suspense?: boolean;
17
17
  }
18
18
 
19
- // @ts-ignore: "__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
 
package/src/firestore.tsx CHANGED
@@ -63,7 +63,7 @@ export function useFirestoreDocData<T = unknown>(ref: DocumentReference<T>, opti
63
63
  const idField = options ? checkIdField(options) : 'NO_ID_FIELD';
64
64
 
65
65
  const observableId = `firestore:docData:${ref.firestore.app.name}:${ref.path}:idField=${idField}`;
66
- const observable = docData(ref, idField);
66
+ const observable = docData(ref, { idField });
67
67
 
68
68
  return useObservable(observableId, observable, options);
69
69
  }
@@ -75,7 +75,7 @@ export function useFirestoreDocDataOnce<T = unknown>(ref: DocumentReference<T>,
75
75
  const idField = options ? checkIdField(options) : 'NO_ID_FIELD';
76
76
 
77
77
  const observableId = `firestore:docDataOnce:${ref.firestore.app.name}:${ref.path}:idField=${idField}`;
78
- const observable$ = docData(ref, idField).pipe(first());
78
+ const observable$ = docData(ref, { idField }).pipe(first());
79
79
 
80
80
  return useObservable(observableId, observable$, options);
81
81
  }
@@ -96,7 +96,7 @@ export function useFirestoreCollection<T = DocumentData>(query: FirestoreQuery<T
96
96
  export function useFirestoreCollectionData<T = DocumentData>(query: FirestoreQuery<T>, options?: ReactFireOptions<T[]>): ObservableStatus<T[]> {
97
97
  const idField = options ? checkIdField(options) : 'NO_ID_FIELD';
98
98
  const observableId = `firestore:collectionData:${getUniqueIdForFirestoreQuery(query)}:idField=${idField}`;
99
- const observable$ = collectionData(query, idField);
99
+ const observable$ = collectionData(query, { idField });
100
100
 
101
101
  return useObservable(observableId, observable$, options);
102
102
  }
@@ -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';