@vueuse/firebase 14.0.0-alpha.1 → 14.0.0-alpha.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.
@@ -0,0 +1,16 @@
1
+ import { Ref } from "vue";
2
+ import { DatabaseReference } from "firebase/database";
3
+
4
+ //#region useRTDB/index.d.ts
5
+ interface UseRTDBOptions {
6
+ errorHandler?: (err: Error) => void;
7
+ autoDispose?: boolean;
8
+ }
9
+ /**
10
+ * Reactive Firebase Realtime Database binding.
11
+ *
12
+ * @see https://vueuse.org/useRTDB
13
+ */
14
+ declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined, T | undefined>;
15
+ //#endregion
16
+ export { UseRTDBOptions, useRTDB };
@@ -0,0 +1,16 @@
1
+ import { MaybeRef, Ref } from "vue";
2
+ import { DocumentData, DocumentReference, Query } from "firebase/firestore";
3
+
4
+ //#region useFirestore/index.d.ts
5
+ interface UseFirestoreOptions {
6
+ errorHandler?: (err: Error) => void;
7
+ autoDispose?: boolean | number;
8
+ }
9
+ type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
10
+ type Falsy = false | 0 | '' | null | undefined;
11
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
12
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
13
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
14
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
15
+ //#endregion
16
+ export { FirebaseDocRef, UseFirestoreOptions, useFirestore };
@@ -0,0 +1,78 @@
1
+ import { ComputedRef, Ref } from "vue";
2
+ import * as firebase_auth0 from "firebase/auth";
3
+ import { Auth, User } from "firebase/auth";
4
+
5
+ //#region useAuth/index.d.ts
6
+ interface UseFirebaseAuthOptions {
7
+ isAuthenticated: ComputedRef<boolean>;
8
+ user: Ref<User | null>;
9
+ }
10
+ /**
11
+ * Reactive Firebase Auth binding
12
+ *
13
+ * @see https://vueuse.org/useAuth
14
+ *
15
+ * @__NO_SIDE_EFFECTS__
16
+ */
17
+ declare function useAuth(auth: Auth): {
18
+ isAuthenticated: ComputedRef<boolean>;
19
+ user: Ref<{
20
+ readonly emailVerified: boolean;
21
+ readonly isAnonymous: boolean;
22
+ readonly metadata: {
23
+ readonly creationTime?: string | undefined;
24
+ readonly lastSignInTime?: string | undefined;
25
+ };
26
+ readonly providerData: {
27
+ readonly displayName: string | null;
28
+ readonly email: string | null;
29
+ readonly phoneNumber: string | null;
30
+ readonly photoURL: string | null;
31
+ readonly providerId: string;
32
+ readonly uid: string;
33
+ }[];
34
+ readonly refreshToken: string;
35
+ readonly tenantId: string | null;
36
+ delete: () => Promise<void>;
37
+ getIdToken: (forceRefresh?: boolean) => Promise<string>;
38
+ getIdTokenResult: (forceRefresh?: boolean) => Promise<firebase_auth0.IdTokenResult>;
39
+ reload: () => Promise<void>;
40
+ toJSON: () => object;
41
+ readonly displayName: string | null;
42
+ readonly email: string | null;
43
+ readonly phoneNumber: string | null;
44
+ readonly photoURL: string | null;
45
+ readonly providerId: string;
46
+ readonly uid: string;
47
+ } | null, User | {
48
+ readonly emailVerified: boolean;
49
+ readonly isAnonymous: boolean;
50
+ readonly metadata: {
51
+ readonly creationTime?: string | undefined;
52
+ readonly lastSignInTime?: string | undefined;
53
+ };
54
+ readonly providerData: {
55
+ readonly displayName: string | null;
56
+ readonly email: string | null;
57
+ readonly phoneNumber: string | null;
58
+ readonly photoURL: string | null;
59
+ readonly providerId: string;
60
+ readonly uid: string;
61
+ }[];
62
+ readonly refreshToken: string;
63
+ readonly tenantId: string | null;
64
+ delete: () => Promise<void>;
65
+ getIdToken: (forceRefresh?: boolean) => Promise<string>;
66
+ getIdTokenResult: (forceRefresh?: boolean) => Promise<firebase_auth0.IdTokenResult>;
67
+ reload: () => Promise<void>;
68
+ toJSON: () => object;
69
+ readonly displayName: string | null;
70
+ readonly email: string | null;
71
+ readonly phoneNumber: string | null;
72
+ readonly photoURL: string | null;
73
+ readonly providerId: string;
74
+ readonly uid: string;
75
+ } | null>;
76
+ };
77
+ //#endregion
78
+ export { UseFirebaseAuthOptions, useAuth };
package/dist/index.d.ts CHANGED
@@ -1,104 +1,4 @@
1
- import { ComputedRef, MaybeRef, Ref } from "vue";
2
- import { DocumentData, DocumentReference, Query } from "firebase/firestore";
3
- import { DatabaseReference } from "firebase/database";
4
- import * as firebase_auth0 from "firebase/auth";
5
- import { Auth, User } from "firebase/auth";
6
-
7
- //#region useAuth/index.d.ts
8
- interface UseFirebaseAuthOptions {
9
- isAuthenticated: ComputedRef<boolean>;
10
- user: Ref<User | null>;
11
- }
12
- /**
13
- * Reactive Firebase Auth binding
14
- *
15
- * @see https://vueuse.org/useAuth
16
- *
17
- * @__NO_SIDE_EFFECTS__
18
- */
19
- declare function useAuth(auth: Auth): {
20
- isAuthenticated: ComputedRef<boolean>;
21
- user: Ref<{
22
- readonly emailVerified: boolean;
23
- readonly isAnonymous: boolean;
24
- readonly metadata: {
25
- readonly creationTime?: string | undefined;
26
- readonly lastSignInTime?: string | undefined;
27
- };
28
- readonly providerData: {
29
- readonly displayName: string | null;
30
- readonly email: string | null;
31
- readonly phoneNumber: string | null;
32
- readonly photoURL: string | null;
33
- readonly providerId: string;
34
- readonly uid: string;
35
- }[];
36
- readonly refreshToken: string;
37
- readonly tenantId: string | null;
38
- delete: () => Promise<void>;
39
- getIdToken: (forceRefresh?: boolean) => Promise<string>;
40
- getIdTokenResult: (forceRefresh?: boolean) => Promise<firebase_auth0.IdTokenResult>;
41
- reload: () => Promise<void>;
42
- toJSON: () => object;
43
- readonly displayName: string | null;
44
- readonly email: string | null;
45
- readonly phoneNumber: string | null;
46
- readonly photoURL: string | null;
47
- readonly providerId: string;
48
- readonly uid: string;
49
- } | null, User | {
50
- readonly emailVerified: boolean;
51
- readonly isAnonymous: boolean;
52
- readonly metadata: {
53
- readonly creationTime?: string | undefined;
54
- readonly lastSignInTime?: string | undefined;
55
- };
56
- readonly providerData: {
57
- readonly displayName: string | null;
58
- readonly email: string | null;
59
- readonly phoneNumber: string | null;
60
- readonly photoURL: string | null;
61
- readonly providerId: string;
62
- readonly uid: string;
63
- }[];
64
- readonly refreshToken: string;
65
- readonly tenantId: string | null;
66
- delete: () => Promise<void>;
67
- getIdToken: (forceRefresh?: boolean) => Promise<string>;
68
- getIdTokenResult: (forceRefresh?: boolean) => Promise<firebase_auth0.IdTokenResult>;
69
- reload: () => Promise<void>;
70
- toJSON: () => object;
71
- readonly displayName: string | null;
72
- readonly email: string | null;
73
- readonly phoneNumber: string | null;
74
- readonly photoURL: string | null;
75
- readonly providerId: string;
76
- readonly uid: string;
77
- } | null>;
78
- };
79
- //#endregion
80
- //#region useFirestore/index.d.ts
81
- interface UseFirestoreOptions {
82
- errorHandler?: (err: Error) => void;
83
- autoDispose?: boolean | number;
84
- }
85
- type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
86
- type Falsy = false | 0 | '' | null | undefined;
87
- declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
88
- declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
89
- declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
90
- declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
91
- //#endregion
92
- //#region useRTDB/index.d.ts
93
- interface UseRTDBOptions {
94
- errorHandler?: (err: Error) => void;
95
- autoDispose?: boolean;
96
- }
97
- /**
98
- * Reactive Firebase Realtime Database binding.
99
- *
100
- * @see https://vueuse.org/useRTDB
101
- */
102
- declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined, T | undefined>;
103
- //#endregion
1
+ import { UseFirebaseAuthOptions, useAuth } from "./index-b8UVCofo.js";
2
+ import { FirebaseDocRef, UseFirestoreOptions, useFirestore } from "./index-CpsujYtM.js";
3
+ import { UseRTDBOptions, useRTDB } from "./index-CKgxjVly.js";
104
4
  export { FirebaseDocRef, UseFirebaseAuthOptions, UseFirestoreOptions, UseRTDBOptions, useAuth, useFirestore, useRTDB };
package/dist/index.js CHANGED
@@ -1,89 +1,5 @@
1
- import { computed, isRef, ref, watch } from "vue";
2
- import { isDef, tryOnScopeDispose, useTimeoutFn } from "@vueuse/shared";
3
- import { onSnapshot } from "firebase/firestore";
4
- import { onValue } from "firebase/database";
1
+ import { useAuth } from "./useAuth-Drx9pmk6.js";
2
+ import { useFirestore } from "./useFirestore-DlUzLR_t.js";
3
+ import { useRTDB } from "./useRTDB-BGccE9Ip.js";
5
4
 
6
- //#region useAuth/index.ts
7
- /**
8
- * Reactive Firebase Auth binding
9
- *
10
- * @see https://vueuse.org/useAuth
11
- *
12
- * @__NO_SIDE_EFFECTS__
13
- */
14
- function useAuth(auth) {
15
- const user = ref(auth.currentUser);
16
- const isAuthenticated = computed(() => !!user.value);
17
- auth.onIdTokenChanged((authUser) => user.value = authUser);
18
- return {
19
- isAuthenticated,
20
- user
21
- };
22
- }
23
-
24
- //#endregion
25
- //#region useFirestore/index.ts
26
- function getData(docRef) {
27
- const data = docRef.data();
28
- if (data) Object.defineProperty(data, "id", {
29
- value: docRef.id.toString(),
30
- writable: false
31
- });
32
- return data;
33
- }
34
- function isDocumentReference(docRef) {
35
- var _docRef$path;
36
- return (((_docRef$path = docRef.path) === null || _docRef$path === void 0 ? void 0 : _docRef$path.match(/\//g)) || []).length % 2 !== 0;
37
- }
38
- /**
39
- * Reactive Firestore binding. Making it straightforward to always keep your
40
- * local data in sync with remotes databases.
41
- *
42
- * @see https://vueuse.org/useFirestore
43
- */
44
- function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
45
- const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
46
- const refOfDocRef = isRef(maybeDocRef) ? maybeDocRef : computed(() => maybeDocRef);
47
- let close = () => {};
48
- const data = ref(initialValue);
49
- watch(refOfDocRef, (docRef) => {
50
- close();
51
- if (!refOfDocRef.value) data.value = initialValue;
52
- else if (isDocumentReference(refOfDocRef.value)) close = onSnapshot(docRef, (snapshot) => {
53
- data.value = getData(snapshot) || null;
54
- }, errorHandler);
55
- else close = onSnapshot(docRef, (snapshot) => {
56
- data.value = snapshot.docs.map(getData).filter(isDef);
57
- }, errorHandler);
58
- }, { immediate: true });
59
- if (autoDispose === true) tryOnScopeDispose(() => {
60
- close();
61
- });
62
- else if (typeof autoDispose === "number") tryOnScopeDispose(() => {
63
- useTimeoutFn(() => {
64
- close();
65
- }, autoDispose);
66
- });
67
- return data;
68
- }
69
-
70
- //#endregion
71
- //#region useRTDB/index.ts
72
- /**
73
- * Reactive Firebase Realtime Database binding.
74
- *
75
- * @see https://vueuse.org/useRTDB
76
- */
77
- function useRTDB(docRef, options = {}) {
78
- const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
79
- const data = ref(void 0);
80
- function update(snapshot) {
81
- data.value = snapshot.val();
82
- }
83
- const off = onValue(docRef, update, errorHandler);
84
- if (autoDispose) tryOnScopeDispose(() => off());
85
- return data;
86
- }
87
-
88
- //#endregion
89
5
  export { useAuth, useFirestore, useRTDB };
@@ -0,0 +1,22 @@
1
+ import { computed, ref } from "vue";
2
+
3
+ //#region useAuth/index.ts
4
+ /**
5
+ * Reactive Firebase Auth binding
6
+ *
7
+ * @see https://vueuse.org/useAuth
8
+ *
9
+ * @__NO_SIDE_EFFECTS__
10
+ */
11
+ function useAuth(auth) {
12
+ const user = ref(auth.currentUser);
13
+ const isAuthenticated = computed(() => !!user.value);
14
+ auth.onIdTokenChanged((authUser) => user.value = authUser);
15
+ return {
16
+ isAuthenticated,
17
+ user
18
+ };
19
+ }
20
+
21
+ //#endregion
22
+ export { useAuth };
package/dist/useAuth.d.ts CHANGED
@@ -1,78 +1,2 @@
1
- import { ComputedRef, Ref } from "vue";
2
- import * as firebase_auth0 from "firebase/auth";
3
- import { Auth, User } from "firebase/auth";
4
-
5
- //#region useAuth/index.d.ts
6
- interface UseFirebaseAuthOptions {
7
- isAuthenticated: ComputedRef<boolean>;
8
- user: Ref<User | null>;
9
- }
10
- /**
11
- * Reactive Firebase Auth binding
12
- *
13
- * @see https://vueuse.org/useAuth
14
- *
15
- * @__NO_SIDE_EFFECTS__
16
- */
17
- declare function useAuth(auth: Auth): {
18
- isAuthenticated: ComputedRef<boolean>;
19
- user: Ref<{
20
- readonly emailVerified: boolean;
21
- readonly isAnonymous: boolean;
22
- readonly metadata: {
23
- readonly creationTime?: string | undefined;
24
- readonly lastSignInTime?: string | undefined;
25
- };
26
- readonly providerData: {
27
- readonly displayName: string | null;
28
- readonly email: string | null;
29
- readonly phoneNumber: string | null;
30
- readonly photoURL: string | null;
31
- readonly providerId: string;
32
- readonly uid: string;
33
- }[];
34
- readonly refreshToken: string;
35
- readonly tenantId: string | null;
36
- delete: () => Promise<void>;
37
- getIdToken: (forceRefresh?: boolean) => Promise<string>;
38
- getIdTokenResult: (forceRefresh?: boolean) => Promise<firebase_auth0.IdTokenResult>;
39
- reload: () => Promise<void>;
40
- toJSON: () => object;
41
- readonly displayName: string | null;
42
- readonly email: string | null;
43
- readonly phoneNumber: string | null;
44
- readonly photoURL: string | null;
45
- readonly providerId: string;
46
- readonly uid: string;
47
- } | null, User | {
48
- readonly emailVerified: boolean;
49
- readonly isAnonymous: boolean;
50
- readonly metadata: {
51
- readonly creationTime?: string | undefined;
52
- readonly lastSignInTime?: string | undefined;
53
- };
54
- readonly providerData: {
55
- readonly displayName: string | null;
56
- readonly email: string | null;
57
- readonly phoneNumber: string | null;
58
- readonly photoURL: string | null;
59
- readonly providerId: string;
60
- readonly uid: string;
61
- }[];
62
- readonly refreshToken: string;
63
- readonly tenantId: string | null;
64
- delete: () => Promise<void>;
65
- getIdToken: (forceRefresh?: boolean) => Promise<string>;
66
- getIdTokenResult: (forceRefresh?: boolean) => Promise<firebase_auth0.IdTokenResult>;
67
- reload: () => Promise<void>;
68
- toJSON: () => object;
69
- readonly displayName: string | null;
70
- readonly email: string | null;
71
- readonly phoneNumber: string | null;
72
- readonly photoURL: string | null;
73
- readonly providerId: string;
74
- readonly uid: string;
75
- } | null>;
76
- };
77
- //#endregion
1
+ import { UseFirebaseAuthOptions, useAuth } from "./index-b8UVCofo.js";
78
2
  export { UseFirebaseAuthOptions, useAuth };
@@ -1 +1 @@
1
- (function(exports,t){var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e},l=(e,t,i)=>(i=e==null?{}:n(o(e)),c(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e));t=l(t);function u(e){let n=(0,t.ref)(e.currentUser),r=(0,t.computed)(()=>!!n.value);return e.onIdTokenChanged(e=>n.value=e),{isAuthenticated:r,user:n}}exports.useAuth=u})(this.VueUse=this.VueUse||{},Vue);
1
+ (function(exports,t){var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e};t=((e,t,i)=>(i=e==null?{}:n(o(e)),c(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)))(t);function l(e){let n=(0,t.ref)(e.currentUser),r=(0,t.computed)(()=>!!n.value);return e.onIdTokenChanged(e=>n.value=e),{isAuthenticated:r,user:n}}exports.useAuth=l})(this.VueUse=this.VueUse||{},Vue);
package/dist/useAuth.js CHANGED
@@ -1,22 +1,3 @@
1
- import { computed, ref } from "vue";
1
+ import { useAuth } from "./useAuth-Drx9pmk6.js";
2
2
 
3
- //#region useAuth/index.ts
4
- /**
5
- * Reactive Firebase Auth binding
6
- *
7
- * @see https://vueuse.org/useAuth
8
- *
9
- * @__NO_SIDE_EFFECTS__
10
- */
11
- function useAuth(auth) {
12
- const user = ref(auth.currentUser);
13
- const isAuthenticated = computed(() => !!user.value);
14
- auth.onIdTokenChanged((authUser) => user.value = authUser);
15
- return {
16
- isAuthenticated,
17
- user
18
- };
19
- }
20
-
21
- //#endregion
22
3
  export { useAuth };
@@ -0,0 +1,51 @@
1
+ import { computed, isRef, ref, watch } from "vue";
2
+ import { isDef, tryOnScopeDispose, useTimeoutFn } from "@vueuse/shared";
3
+ import { onSnapshot } from "firebase/firestore";
4
+
5
+ //#region useFirestore/index.ts
6
+ function getData(docRef) {
7
+ const data = docRef.data();
8
+ if (data) Object.defineProperty(data, "id", {
9
+ value: docRef.id.toString(),
10
+ writable: false
11
+ });
12
+ return data;
13
+ }
14
+ function isDocumentReference(docRef) {
15
+ var _docRef$path;
16
+ return (((_docRef$path = docRef.path) === null || _docRef$path === void 0 ? void 0 : _docRef$path.match(/\//g)) || []).length % 2 !== 0;
17
+ }
18
+ /**
19
+ * Reactive Firestore binding. Making it straightforward to always keep your
20
+ * local data in sync with remotes databases.
21
+ *
22
+ * @see https://vueuse.org/useFirestore
23
+ */
24
+ function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
25
+ const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
26
+ const refOfDocRef = isRef(maybeDocRef) ? maybeDocRef : computed(() => maybeDocRef);
27
+ let close = () => {};
28
+ const data = ref(initialValue);
29
+ watch(refOfDocRef, (docRef) => {
30
+ close();
31
+ if (!refOfDocRef.value) data.value = initialValue;
32
+ else if (isDocumentReference(refOfDocRef.value)) close = onSnapshot(docRef, (snapshot) => {
33
+ data.value = getData(snapshot) || null;
34
+ }, errorHandler);
35
+ else close = onSnapshot(docRef, (snapshot) => {
36
+ data.value = snapshot.docs.map(getData).filter(isDef);
37
+ }, errorHandler);
38
+ }, { immediate: true });
39
+ if (autoDispose === true) tryOnScopeDispose(() => {
40
+ close();
41
+ });
42
+ else if (typeof autoDispose === "number") tryOnScopeDispose(() => {
43
+ useTimeoutFn(() => {
44
+ close();
45
+ }, autoDispose);
46
+ });
47
+ return data;
48
+ }
49
+
50
+ //#endregion
51
+ export { useFirestore };
@@ -1,16 +1,2 @@
1
- import { DocumentData, DocumentReference, Query } from "firebase/firestore";
2
- import { MaybeRef, Ref } from "vue";
3
-
4
- //#region useFirestore/index.d.ts
5
- interface UseFirestoreOptions {
6
- errorHandler?: (err: Error) => void;
7
- autoDispose?: boolean | number;
8
- }
9
- type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
10
- type Falsy = false | 0 | '' | null | undefined;
11
- declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
12
- declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
13
- declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
14
- declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
15
- //#endregion
1
+ import { FirebaseDocRef, UseFirestoreOptions, useFirestore } from "./index-CpsujYtM.js";
16
2
  export { FirebaseDocRef, UseFirestoreOptions, useFirestore };
@@ -1,51 +1,3 @@
1
- import { isDef, tryOnScopeDispose, useTimeoutFn } from "@vueuse/shared";
2
- import { onSnapshot } from "firebase/firestore";
3
- import { computed, isRef, ref, watch } from "vue";
1
+ import { useFirestore } from "./useFirestore-DlUzLR_t.js";
4
2
 
5
- //#region useFirestore/index.ts
6
- function getData(docRef) {
7
- const data = docRef.data();
8
- if (data) Object.defineProperty(data, "id", {
9
- value: docRef.id.toString(),
10
- writable: false
11
- });
12
- return data;
13
- }
14
- function isDocumentReference(docRef) {
15
- var _docRef$path;
16
- return (((_docRef$path = docRef.path) === null || _docRef$path === void 0 ? void 0 : _docRef$path.match(/\//g)) || []).length % 2 !== 0;
17
- }
18
- /**
19
- * Reactive Firestore binding. Making it straightforward to always keep your
20
- * local data in sync with remotes databases.
21
- *
22
- * @see https://vueuse.org/useFirestore
23
- */
24
- function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
25
- const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
26
- const refOfDocRef = isRef(maybeDocRef) ? maybeDocRef : computed(() => maybeDocRef);
27
- let close = () => {};
28
- const data = ref(initialValue);
29
- watch(refOfDocRef, (docRef) => {
30
- close();
31
- if (!refOfDocRef.value) data.value = initialValue;
32
- else if (isDocumentReference(refOfDocRef.value)) close = onSnapshot(docRef, (snapshot) => {
33
- data.value = getData(snapshot) || null;
34
- }, errorHandler);
35
- else close = onSnapshot(docRef, (snapshot) => {
36
- data.value = snapshot.docs.map(getData).filter(isDef);
37
- }, errorHandler);
38
- }, { immediate: true });
39
- if (autoDispose === true) tryOnScopeDispose(() => {
40
- close();
41
- });
42
- else if (typeof autoDispose === "number") tryOnScopeDispose(() => {
43
- useTimeoutFn(() => {
44
- close();
45
- }, autoDispose);
46
- });
47
- return data;
48
- }
49
-
50
- //#endregion
51
3
  export { useFirestore };
@@ -0,0 +1,23 @@
1
+ import { ref } from "vue";
2
+ import { tryOnScopeDispose } from "@vueuse/shared";
3
+ import { onValue } from "firebase/database";
4
+
5
+ //#region useRTDB/index.ts
6
+ /**
7
+ * Reactive Firebase Realtime Database binding.
8
+ *
9
+ * @see https://vueuse.org/useRTDB
10
+ */
11
+ function useRTDB(docRef, options = {}) {
12
+ const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
13
+ const data = ref(void 0);
14
+ function update(snapshot) {
15
+ data.value = snapshot.val();
16
+ }
17
+ const off = onValue(docRef, update, errorHandler);
18
+ if (autoDispose) tryOnScopeDispose(() => off());
19
+ return data;
20
+ }
21
+
22
+ //#endregion
23
+ export { useRTDB };
package/dist/useRTDB.d.ts CHANGED
@@ -1,16 +1,2 @@
1
- import { DatabaseReference } from "firebase/database";
2
- import { Ref } from "vue";
3
-
4
- //#region useRTDB/index.d.ts
5
- interface UseRTDBOptions {
6
- errorHandler?: (err: Error) => void;
7
- autoDispose?: boolean;
8
- }
9
- /**
10
- * Reactive Firebase Realtime Database binding.
11
- *
12
- * @see https://vueuse.org/useRTDB
13
- */
14
- declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined, T | undefined>;
15
- //#endregion
1
+ import { UseRTDBOptions, useRTDB } from "./index-CKgxjVly.js";
16
2
  export { UseRTDBOptions, useRTDB };
package/dist/useRTDB.js CHANGED
@@ -1,23 +1,3 @@
1
- import { tryOnScopeDispose } from "@vueuse/shared";
2
- import { onValue } from "firebase/database";
3
- import { ref } from "vue";
1
+ import { useRTDB } from "./useRTDB-BGccE9Ip.js";
4
2
 
5
- //#region useRTDB/index.ts
6
- /**
7
- * Reactive Firebase Realtime Database binding.
8
- *
9
- * @see https://vueuse.org/useRTDB
10
- */
11
- function useRTDB(docRef, options = {}) {
12
- const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
13
- const data = ref(void 0);
14
- function update(snapshot) {
15
- data.value = snapshot.val();
16
- }
17
- const off = onValue(docRef, update, errorHandler);
18
- if (autoDispose) tryOnScopeDispose(() => off());
19
- return data;
20
- }
21
-
22
- //#endregion
23
3
  export { useRTDB };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vueuse/firebase",
3
3
  "type": "module",
4
- "version": "14.0.0-alpha.1",
4
+ "version": "14.0.0-alpha.2",
5
5
  "description": "Enables realtime bindings for Firebase",
6
6
  "author": "Anthony Fu <https://github.com/antfu>",
7
7
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "vue": "^3.5.0"
44
44
  },
45
45
  "dependencies": {
46
- "@vueuse/shared": "14.0.0-alpha.1"
46
+ "@vueuse/shared": "14.0.0-alpha.2"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "tsdown",