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/SuspenseSubject.d.ts +21 -21
- package/dist/auth.d.ts +104 -104
- package/dist/database.d.ts +23 -23
- package/dist/firebaseApp.d.ts +14 -14
- package/dist/firestore.d.ts +35 -35
- package/dist/functions.d.ts +12 -0
- package/dist/index.d.ts +36 -35
- package/dist/index.js +2337 -5
- package/dist/index.js.map +1 -0
- package/dist/index.umd.cjs +122 -0
- package/dist/index.umd.cjs.map +1 -0
- package/dist/performance.d.ts +7 -7
- package/dist/remote-config.d.ts +30 -30
- package/dist/sdk.d.ts +70 -55
- package/dist/storage.d.ts +26 -26
- package/dist/useObservable.d.ts +41 -41
- package/package.json +54 -53
- package/src/auth.tsx +6 -6
- package/src/firebaseApp.tsx +2 -2
- package/src/functions.tsx +26 -0
- package/src/index.ts +1 -0
- package/src/sdk.tsx +14 -9
- package/src/storage.tsx +2 -24
- package/dist/reactfire.cjs.development.js +0 -2093
- package/dist/reactfire.cjs.development.js.map +0 -1
- package/dist/reactfire.cjs.production.min.js +0 -2
- package/dist/reactfire.cjs.production.min.js.map +0 -1
- package/dist/reactfire.esm.js +0 -2029
- package/dist/reactfire.esm.js.map +0 -1
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 {
|
|
8
|
-
import type {
|
|
9
|
-
import type {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
export declare const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export declare const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export declare const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export declare const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export declare const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export declare const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
export declare const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
export declare const
|
|
52
|
-
export declare const
|
|
53
|
-
export declare const
|
|
54
|
-
export declare const
|
|
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 {};
|
package/dist/useObservable.d.ts
CHANGED
|
@@ -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.
|
|
2
|
+
"version": "4.2.2",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"
|
|
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": ">=
|
|
18
|
+
"node": ">=14"
|
|
12
19
|
},
|
|
13
20
|
"scripts": {
|
|
14
|
-
"start": "
|
|
15
|
-
"build": "
|
|
16
|
-
"test
|
|
17
|
-
"test": "firebase emulators:exec --only firestore
|
|
18
|
-
"test:
|
|
19
|
-
"test:
|
|
20
|
-
"test:
|
|
21
|
-
"test:storage": "firebase emulators:exec --only storage --project=rxfire-525a3 \"
|
|
22
|
-
"test:useObservable": "
|
|
23
|
-
"
|
|
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": "
|
|
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/
|
|
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
|
-
"@
|
|
75
|
-
"@size-limit/preset-small-lib": "^
|
|
76
|
-
"@testing-library/jest-dom": "^5.
|
|
77
|
-
"@testing-library/react": "^
|
|
78
|
-
"@testing-library/react-hooks": "^
|
|
79
|
-
"@types/
|
|
80
|
-
"@types/react": "^17.0.
|
|
81
|
-
"@
|
|
82
|
-
"
|
|
83
|
-
"
|
|
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
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
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
|
-
"
|
|
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
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"typedoc": "^
|
|
99
|
-
"
|
|
100
|
-
"
|
|
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.
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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$,
|
|
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/firebaseApp.tsx
CHANGED
|
@@ -16,8 +16,8 @@ interface FirebaseAppProviderProps {
|
|
|
16
16
|
suspense?: boolean;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
//
|
|
20
|
-
export const 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
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
|
|
23
|
-
const
|
|
24
|
-
const
|
|
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$ =
|
|
18
|
+
const observable$ = fromTask(task);
|
|
41
19
|
|
|
42
20
|
return useObservable(observableId, observable$, options);
|
|
43
21
|
}
|