@vueuse/firebase 14.0.0-alpha.0 → 14.0.0-alpha.1

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,104 @@
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
104
+ export { FirebaseDocRef, UseFirebaseAuthOptions, UseFirestoreOptions, UseRTDBOptions, useAuth, useFirestore, useRTDB };
@@ -0,0 +1,117 @@
1
+ (function(exports, vue, __vueuse_shared, firebase_firestore, firebase_database) {
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+
25
+ //#endregion
26
+ vue = __toESM(vue);
27
+ __vueuse_shared = __toESM(__vueuse_shared);
28
+ firebase_firestore = __toESM(firebase_firestore);
29
+ firebase_database = __toESM(firebase_database);
30
+
31
+ //#region useAuth/index.ts
32
+ /**
33
+ * Reactive Firebase Auth binding
34
+ *
35
+ * @see https://vueuse.org/useAuth
36
+ *
37
+ * @__NO_SIDE_EFFECTS__
38
+ */
39
+ function useAuth(auth) {
40
+ const user = (0, vue.ref)(auth.currentUser);
41
+ const isAuthenticated = (0, vue.computed)(() => !!user.value);
42
+ auth.onIdTokenChanged((authUser) => user.value = authUser);
43
+ return {
44
+ isAuthenticated,
45
+ user
46
+ };
47
+ }
48
+
49
+ //#endregion
50
+ //#region useFirestore/index.ts
51
+ function getData(docRef) {
52
+ const data = docRef.data();
53
+ if (data) Object.defineProperty(data, "id", {
54
+ value: docRef.id.toString(),
55
+ writable: false
56
+ });
57
+ return data;
58
+ }
59
+ function isDocumentReference(docRef) {
60
+ var _docRef$path;
61
+ return (((_docRef$path = docRef.path) === null || _docRef$path === void 0 ? void 0 : _docRef$path.match(/\//g)) || []).length % 2 !== 0;
62
+ }
63
+ /**
64
+ * Reactive Firestore binding. Making it straightforward to always keep your
65
+ * local data in sync with remotes databases.
66
+ *
67
+ * @see https://vueuse.org/useFirestore
68
+ */
69
+ function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
70
+ const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
71
+ const refOfDocRef = (0, vue.isRef)(maybeDocRef) ? maybeDocRef : (0, vue.computed)(() => maybeDocRef);
72
+ let close = () => {};
73
+ const data = (0, vue.ref)(initialValue);
74
+ (0, vue.watch)(refOfDocRef, (docRef) => {
75
+ close();
76
+ if (!refOfDocRef.value) data.value = initialValue;
77
+ else if (isDocumentReference(refOfDocRef.value)) close = (0, firebase_firestore.onSnapshot)(docRef, (snapshot) => {
78
+ data.value = getData(snapshot) || null;
79
+ }, errorHandler);
80
+ else close = (0, firebase_firestore.onSnapshot)(docRef, (snapshot) => {
81
+ data.value = snapshot.docs.map(getData).filter(__vueuse_shared.isDef);
82
+ }, errorHandler);
83
+ }, { immediate: true });
84
+ if (autoDispose === true) (0, __vueuse_shared.tryOnScopeDispose)(() => {
85
+ close();
86
+ });
87
+ else if (typeof autoDispose === "number") (0, __vueuse_shared.tryOnScopeDispose)(() => {
88
+ (0, __vueuse_shared.useTimeoutFn)(() => {
89
+ close();
90
+ }, autoDispose);
91
+ });
92
+ return data;
93
+ }
94
+
95
+ //#endregion
96
+ //#region useRTDB/index.ts
97
+ /**
98
+ * Reactive Firebase Realtime Database binding.
99
+ *
100
+ * @see https://vueuse.org/useRTDB
101
+ */
102
+ function useRTDB(docRef, options = {}) {
103
+ const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
104
+ const data = (0, vue.ref)(void 0);
105
+ function update(snapshot) {
106
+ data.value = snapshot.val();
107
+ }
108
+ const off = (0, firebase_database.onValue)(docRef, update, errorHandler);
109
+ if (autoDispose) (0, __vueuse_shared.tryOnScopeDispose)(() => off());
110
+ return data;
111
+ }
112
+
113
+ //#endregion
114
+ exports.useAuth = useAuth;
115
+ exports.useFirestore = useFirestore;
116
+ exports.useRTDB = useRTDB;
117
+ })(this.VueUse = this.VueUse || {}, Vue, VueUse, firebase, firebase);
@@ -0,0 +1 @@
1
+ (function(exports,t,n,r,i){var a=Object.create,o=Object.defineProperty,s=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyNames,l=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty,d=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=c(t),a=0,l=i.length,d;a<l;a++)d=i[a],!u.call(e,d)&&d!==n&&o(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=s(t,d))||r.enumerable});return e},f=(e,t,n)=>(n=e==null?{}:a(l(e)),d(t||!e||!e.__esModule?o(n,`default`,{value:e,enumerable:!0}):n,e));t=f(t),n=f(n),r=f(r),i=f(i);function p(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}}function m(e){let t=e.data();return t&&Object.defineProperty(t,`id`,{value:e.id.toString(),writable:!1}),t}function h(e){var t;return(((t=e.path)==null?void 0:t.match(/\//g))||[]).length%2!=0}function g(e,i=void 0,a={}){let{errorHandler:o=e=>console.error(e),autoDispose:s=!0}=a,c=(0,t.isRef)(e)?e:(0,t.computed)(()=>e),l=()=>{},u=(0,t.ref)(i);return(0,t.watch)(c,e=>{l(),c.value?l=h(c.value)?(0,r.onSnapshot)(e,e=>{u.value=m(e)||null},o):(0,r.onSnapshot)(e,e=>{u.value=e.docs.map(m).filter(n.isDef)},o):u.value=i},{immediate:!0}),s===!0?(0,n.tryOnScopeDispose)(()=>{l()}):typeof s==`number`&&(0,n.tryOnScopeDispose)(()=>{(0,n.useTimeoutFn)(()=>{l()},s)}),u}function _(e,r={}){let{errorHandler:a=e=>console.error(e),autoDispose:o=!0}=r,s=(0,t.ref)(void 0);function c(e){s.value=e.val()}let l=(0,i.onValue)(e,c,a);return o&&(0,n.tryOnScopeDispose)(()=>l()),s}exports.useAuth=p,exports.useFirestore=g,exports.useRTDB=_})(this.VueUse=this.VueUse||{},Vue,VueUse,firebase,firebase);
package/dist/index.js ADDED
@@ -0,0 +1,89 @@
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";
5
+
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
+ export { useAuth, useFirestore, useRTDB };
@@ -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 };
@@ -0,0 +1,48 @@
1
+ (function(exports, vue) {
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+
25
+ //#endregion
26
+ vue = __toESM(vue);
27
+
28
+ //#region useAuth/index.ts
29
+ /**
30
+ * Reactive Firebase Auth binding
31
+ *
32
+ * @see https://vueuse.org/useAuth
33
+ *
34
+ * @__NO_SIDE_EFFECTS__
35
+ */
36
+ function useAuth(auth) {
37
+ const user = (0, vue.ref)(auth.currentUser);
38
+ const isAuthenticated = (0, vue.computed)(() => !!user.value);
39
+ auth.onIdTokenChanged((authUser) => user.value = authUser);
40
+ return {
41
+ isAuthenticated,
42
+ user
43
+ };
44
+ }
45
+
46
+ //#endregion
47
+ exports.useAuth = useAuth;
48
+ })(this.VueUse = this.VueUse || {}, Vue);
@@ -0,0 +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);
@@ -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 };
@@ -1,9 +1,10 @@
1
- import { Query, DocumentReference, DocumentData } from 'firebase/firestore';
2
- import { MaybeRef, Ref } from 'vue';
1
+ import { DocumentData, DocumentReference, Query } from "firebase/firestore";
2
+ import { MaybeRef, Ref } from "vue";
3
3
 
4
+ //#region useFirestore/index.d.ts
4
5
  interface UseFirestoreOptions {
5
- errorHandler?: (err: Error) => void;
6
- autoDispose?: boolean | number;
6
+ errorHandler?: (err: Error) => void;
7
+ autoDispose?: boolean | number;
7
8
  }
8
9
  type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
9
10
  type Falsy = false | 0 | '' | null | undefined;
@@ -11,6 +12,5 @@ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Docu
11
12
  declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
12
13
  declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
13
14
  declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
14
-
15
- export { useFirestore };
16
- export type { FirebaseDocRef, UseFirestoreOptions };
15
+ //#endregion
16
+ export { FirebaseDocRef, UseFirestoreOptions, useFirestore };
@@ -0,0 +1,77 @@
1
+ (function(exports, __vueuse_shared, firebase_firestore, vue) {
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+
25
+ //#endregion
26
+ __vueuse_shared = __toESM(__vueuse_shared);
27
+ firebase_firestore = __toESM(firebase_firestore);
28
+ vue = __toESM(vue);
29
+
30
+ //#region useFirestore/index.ts
31
+ function getData(docRef) {
32
+ const data = docRef.data();
33
+ if (data) Object.defineProperty(data, "id", {
34
+ value: docRef.id.toString(),
35
+ writable: false
36
+ });
37
+ return data;
38
+ }
39
+ function isDocumentReference(docRef) {
40
+ var _docRef$path;
41
+ return (((_docRef$path = docRef.path) === null || _docRef$path === void 0 ? void 0 : _docRef$path.match(/\//g)) || []).length % 2 !== 0;
42
+ }
43
+ /**
44
+ * Reactive Firestore binding. Making it straightforward to always keep your
45
+ * local data in sync with remotes databases.
46
+ *
47
+ * @see https://vueuse.org/useFirestore
48
+ */
49
+ function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
50
+ const { errorHandler = (err) => console.error(err), autoDispose = true } = options;
51
+ const refOfDocRef = (0, vue.isRef)(maybeDocRef) ? maybeDocRef : (0, vue.computed)(() => maybeDocRef);
52
+ let close = () => {};
53
+ const data = (0, vue.ref)(initialValue);
54
+ (0, vue.watch)(refOfDocRef, (docRef) => {
55
+ close();
56
+ if (!refOfDocRef.value) data.value = initialValue;
57
+ else if (isDocumentReference(refOfDocRef.value)) close = (0, firebase_firestore.onSnapshot)(docRef, (snapshot) => {
58
+ data.value = getData(snapshot) || null;
59
+ }, errorHandler);
60
+ else close = (0, firebase_firestore.onSnapshot)(docRef, (snapshot) => {
61
+ data.value = snapshot.docs.map(getData).filter(__vueuse_shared.isDef);
62
+ }, errorHandler);
63
+ }, { immediate: true });
64
+ if (autoDispose === true) (0, __vueuse_shared.tryOnScopeDispose)(() => {
65
+ close();
66
+ });
67
+ else if (typeof autoDispose === "number") (0, __vueuse_shared.tryOnScopeDispose)(() => {
68
+ (0, __vueuse_shared.useTimeoutFn)(() => {
69
+ close();
70
+ }, autoDispose);
71
+ });
72
+ return data;
73
+ }
74
+
75
+ //#endregion
76
+ exports.useFirestore = useFirestore;
77
+ })(this.VueUse = this.VueUse || {}, VueUse, firebase, Vue);
@@ -0,0 +1 @@
1
+ (function(exports,t,n,r){var i=Object.create,a=Object.defineProperty,o=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,c=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty,u=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=s(t),c=0,u=i.length,d;c<u;c++)d=i[c],!l.call(e,d)&&d!==n&&a(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=o(t,d))||r.enumerable});return e},d=(e,t,n)=>(n=e==null?{}:i(c(e)),u(t||!e||!e.__esModule?a(n,`default`,{value:e,enumerable:!0}):n,e));t=d(t),n=d(n),r=d(r);function f(e){let t=e.data();return t&&Object.defineProperty(t,`id`,{value:e.id.toString(),writable:!1}),t}function p(e){var t;return(((t=e.path)==null?void 0:t.match(/\//g))||[]).length%2!=0}function m(e,i=void 0,a={}){let{errorHandler:o=e=>console.error(e),autoDispose:s=!0}=a,c=(0,r.isRef)(e)?e:(0,r.computed)(()=>e),l=()=>{},u=(0,r.ref)(i);return(0,r.watch)(c,e=>{l(),c.value?l=p(c.value)?(0,n.onSnapshot)(e,e=>{u.value=f(e)||null},o):(0,n.onSnapshot)(e,e=>{u.value=e.docs.map(f).filter(t.isDef)},o):u.value=i},{immediate:!0}),s===!0?(0,t.tryOnScopeDispose)(()=>{l()}):typeof s==`number`&&(0,t.tryOnScopeDispose)(()=>{(0,t.useTimeoutFn)(()=>{l()},s)}),u}exports.useFirestore=m})(this.VueUse=this.VueUse||{},VueUse,firebase,Vue);
@@ -0,0 +1,51 @@
1
+ import { isDef, tryOnScopeDispose, useTimeoutFn } from "@vueuse/shared";
2
+ import { onSnapshot } from "firebase/firestore";
3
+ import { computed, isRef, ref, watch } from "vue";
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,9 +1,10 @@
1
- import { DatabaseReference } from 'firebase/database';
2
- import { Ref } from 'vue';
1
+ import { DatabaseReference } from "firebase/database";
2
+ import { Ref } from "vue";
3
3
 
4
+ //#region useRTDB/index.d.ts
4
5
  interface UseRTDBOptions {
5
- errorHandler?: (err: Error) => void;
6
- autoDispose?: boolean;
6
+ errorHandler?: (err: Error) => void;
7
+ autoDispose?: boolean;
7
8
  }
8
9
  /**
9
10
  * Reactive Firebase Realtime Database binding.
@@ -11,6 +12,5 @@ interface UseRTDBOptions {
11
12
  * @see https://vueuse.org/useRTDB
12
13
  */
13
14
  declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined, T | undefined>;
14
-
15
- export { useRTDB };
16
- export type { UseRTDBOptions };
15
+ //#endregion
16
+ export { UseRTDBOptions, useRTDB };