@vueuse/firebase 9.0.0-beta.1 → 9.0.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.
- package/README.md +3 -1
- package/index.cjs +25 -20
- package/index.d.ts +46 -70
- package/index.iife.js +25 -22
- package/index.iife.min.js +1 -1
- package/index.mjs +26 -21
- package/package.json +3 -3
- package/useAuth.cjs +1 -6
- package/useAuth.d.ts +35 -60
- package/useAuth.iife.js +1 -6
- package/useAuth.iife.min.js +1 -1
- package/useAuth.mjs +1 -6
- package/useFirestore.cjs +20 -8
- package/useFirestore.d.ts +9 -8
- package/useFirestore.iife.js +21 -10
- package/useFirestore.iife.min.js +1 -1
- package/useFirestore.mjs +21 -9
- package/useRTDB.cjs +4 -6
- package/useRTDB.d.ts +3 -4
- package/useRTDB.iife.js +5 -8
- package/useRTDB.iife.min.js +1 -1
- package/useRTDB.mjs +4 -6
package/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@vueuse/firebase)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Add-on of [VueUse](https://github.com/vueuse/vueuse), enables the real-time bindings for Firebase.
|
|
6
|
+
|
|
7
|
+
> ⚠️ This package only work with [Firebase 9 or above with the modular style](https://firebase.google.com/docs/web/modular-upgrade). For legacy versions, use `@vueuse/firebase@8` instead.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
8
10
|
|
package/index.cjs
CHANGED
|
@@ -4,13 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vueDemi = require('vue-demi');
|
|
6
6
|
var shared = require('@vueuse/shared');
|
|
7
|
+
var firestore = require('firebase/firestore');
|
|
8
|
+
var database = require('firebase/database');
|
|
7
9
|
|
|
8
|
-
function useAuth(
|
|
9
|
-
let auth;
|
|
10
|
-
if (authInstance instanceof Function)
|
|
11
|
-
auth = authInstance();
|
|
12
|
-
else
|
|
13
|
-
auth = authInstance;
|
|
10
|
+
function useAuth(auth) {
|
|
14
11
|
const user = vueDemi.ref(auth.currentUser);
|
|
15
12
|
const isAuthenticated = vueDemi.computed(() => !!user.value);
|
|
16
13
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
|
@@ -34,25 +31,36 @@ function isDocumentReference(docRef) {
|
|
|
34
31
|
var _a;
|
|
35
32
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
36
33
|
}
|
|
37
|
-
function useFirestore(
|
|
34
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
38
35
|
const {
|
|
39
36
|
errorHandler = (err) => console.error(err),
|
|
40
37
|
autoDispose = true
|
|
41
38
|
} = options;
|
|
42
|
-
|
|
39
|
+
const refOfDocRef = vueDemi.isRef(maybeDocRef) ? maybeDocRef : vueDemi.computed(() => maybeDocRef);
|
|
40
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
43
41
|
const data = vueDemi.ref(initialValue);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
let close = () => {
|
|
43
|
+
};
|
|
44
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
45
|
+
close();
|
|
46
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
47
|
+
data.value = getData(snapshot) || null;
|
|
48
|
+
}, errorHandler);
|
|
49
|
+
}, { immediate: true });
|
|
47
50
|
shared.tryOnScopeDispose(() => {
|
|
48
51
|
close();
|
|
49
52
|
});
|
|
50
53
|
return data;
|
|
51
54
|
} else {
|
|
52
55
|
const data = vueDemi.ref(initialValue);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
let close = () => {
|
|
57
|
+
};
|
|
58
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
59
|
+
close();
|
|
60
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
61
|
+
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
62
|
+
}, errorHandler);
|
|
63
|
+
}, { immediate: true });
|
|
56
64
|
if (autoDispose) {
|
|
57
65
|
shared.tryOnScopeDispose(() => {
|
|
58
66
|
close();
|
|
@@ -70,12 +78,9 @@ function useRTDB(docRef, options = {}) {
|
|
|
70
78
|
function update(snapshot) {
|
|
71
79
|
data.value = snapshot.val();
|
|
72
80
|
}
|
|
73
|
-
|
|
74
|
-
if (autoDispose)
|
|
75
|
-
shared.tryOnScopeDispose(() =>
|
|
76
|
-
docRef.off("value", update);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
81
|
+
const off = database.onValue(docRef, update);
|
|
82
|
+
if (autoDispose)
|
|
83
|
+
shared.tryOnScopeDispose(() => off());
|
|
79
84
|
return data;
|
|
80
85
|
}
|
|
81
86
|
|
package/index.d.ts
CHANGED
|
@@ -1,84 +1,61 @@
|
|
|
1
|
+
import * as _firebase_auth from '@firebase/auth';
|
|
1
2
|
import { ComputedRef, Ref } from 'vue-demi';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
3
|
+
import { User, Auth } from 'firebase/auth';
|
|
4
|
+
import { Query, DocumentReference, DocumentData } from 'firebase/firestore';
|
|
5
|
+
import { MaybeRef } from '@vueuse/shared';
|
|
6
|
+
import { DatabaseReference } from 'firebase/database';
|
|
4
7
|
|
|
5
|
-
interface
|
|
8
|
+
interface UseFirebaseAuthOptions {
|
|
6
9
|
isAuthenticated: ComputedRef<boolean>;
|
|
7
|
-
user: Ref<
|
|
10
|
+
user: Ref<User | null>;
|
|
8
11
|
}
|
|
9
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Reactive Firebase Auth binding
|
|
14
|
+
*
|
|
15
|
+
* @see https://vueuse.org/useAuth
|
|
16
|
+
*/
|
|
17
|
+
declare function useAuth(auth: Auth): {
|
|
10
18
|
isAuthenticated: ComputedRef<boolean>;
|
|
11
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;
|
|
12
36
|
delete: () => Promise<void>;
|
|
13
|
-
emailVerified: boolean;
|
|
14
|
-
getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<firebase.auth.IdTokenResult>;
|
|
15
37
|
getIdToken: (forceRefresh?: boolean | undefined) => Promise<string>;
|
|
16
|
-
|
|
17
|
-
linkAndRetrieveDataWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
18
|
-
linkWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
19
|
-
linkWithPhoneNumber: (phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier) => Promise<firebase.auth.ConfirmationResult>;
|
|
20
|
-
linkWithPopup: (provider: firebase.auth.AuthProvider) => Promise<firebase.auth.UserCredential>;
|
|
21
|
-
linkWithRedirect: (provider: firebase.auth.AuthProvider) => Promise<void>;
|
|
22
|
-
metadata: {
|
|
23
|
-
creationTime?: string | undefined;
|
|
24
|
-
lastSignInTime?: string | undefined;
|
|
25
|
-
};
|
|
26
|
-
multiFactor: {
|
|
27
|
-
enrolledFactors: {
|
|
28
|
-
uid: string;
|
|
29
|
-
displayName?: string | null | undefined;
|
|
30
|
-
enrollmentTime: string;
|
|
31
|
-
factorId: string;
|
|
32
|
-
}[];
|
|
33
|
-
enroll: (assertion: firebase.auth.MultiFactorAssertion, displayName?: string | null | undefined) => Promise<void>;
|
|
34
|
-
getSession: () => Promise<firebase.auth.MultiFactorSession>;
|
|
35
|
-
unenroll: (option: string | firebase.auth.MultiFactorInfo) => Promise<void>;
|
|
36
|
-
};
|
|
37
|
-
phoneNumber: string | null;
|
|
38
|
-
providerData: ({
|
|
39
|
-
displayName: string | null;
|
|
40
|
-
email: string | null;
|
|
41
|
-
phoneNumber: string | null;
|
|
42
|
-
photoURL: string | null;
|
|
43
|
-
providerId: string;
|
|
44
|
-
uid: string;
|
|
45
|
-
} | null)[];
|
|
46
|
-
reauthenticateAndRetrieveDataWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
47
|
-
reauthenticateWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
48
|
-
reauthenticateWithPhoneNumber: (phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier) => Promise<firebase.auth.ConfirmationResult>;
|
|
49
|
-
reauthenticateWithPopup: (provider: firebase.auth.AuthProvider) => Promise<firebase.auth.UserCredential>;
|
|
50
|
-
reauthenticateWithRedirect: (provider: firebase.auth.AuthProvider) => Promise<void>;
|
|
51
|
-
refreshToken: string;
|
|
38
|
+
getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<_firebase_auth.IdTokenResult>;
|
|
52
39
|
reload: () => Promise<void>;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
updateProfile: (profile: {
|
|
61
|
-
displayName?: string | null | undefined;
|
|
62
|
-
photoURL?: string | null | undefined;
|
|
63
|
-
}) => Promise<void>;
|
|
64
|
-
verifyBeforeUpdateEmail: (newEmail: string, actionCodeSettings?: firebase.auth.ActionCodeSettings | null | undefined) => Promise<void>;
|
|
65
|
-
displayName: string | null;
|
|
66
|
-
email: string | null;
|
|
67
|
-
photoURL: string | null;
|
|
68
|
-
providerId: string;
|
|
69
|
-
uid: string;
|
|
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;
|
|
70
47
|
} | null>;
|
|
71
48
|
};
|
|
72
49
|
|
|
73
|
-
interface
|
|
50
|
+
interface UseFirestoreOptions {
|
|
74
51
|
errorHandler?: (err: Error) => void;
|
|
75
52
|
autoDispose?: boolean;
|
|
76
53
|
}
|
|
77
|
-
declare type FirebaseDocRef<T> =
|
|
78
|
-
declare function useFirestore<T extends
|
|
79
|
-
declare function useFirestore<T extends
|
|
80
|
-
declare function useFirestore<T extends
|
|
81
|
-
declare function useFirestore<T extends
|
|
54
|
+
declare type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
|
|
55
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T>>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
|
|
56
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T>>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
|
|
57
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T>>, initialValue?: T | undefined, options?: UseFirestoreOptions): Ref<T | undefined | null>;
|
|
58
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T>>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
|
|
82
59
|
|
|
83
60
|
interface UseRTDBOptions {
|
|
84
61
|
autoDispose?: boolean;
|
|
@@ -86,9 +63,8 @@ interface UseRTDBOptions {
|
|
|
86
63
|
/**
|
|
87
64
|
* Reactive Firebase Realtime Database binding.
|
|
88
65
|
*
|
|
89
|
-
* @
|
|
90
|
-
* @param options
|
|
66
|
+
* @see https://vueuse.org/useRTDB
|
|
91
67
|
*/
|
|
92
|
-
declare function useRTDB<T = any>(docRef:
|
|
68
|
+
declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
|
|
93
69
|
|
|
94
|
-
export {
|
|
70
|
+
export { FirebaseDocRef, UseFirebaseAuthOptions, UseFirestoreOptions, UseRTDBOptions, useAuth, useFirestore, useRTDB };
|
package/index.iife.js
CHANGED
|
@@ -71,15 +71,10 @@
|
|
|
71
71
|
this.VueCompositionAPI || (typeof VueCompositionAPI !== "undefined" ? VueCompositionAPI : undefined)
|
|
72
72
|
);
|
|
73
73
|
;
|
|
74
|
-
;(function (exports, vueDemi, shared) {
|
|
74
|
+
;(function (exports, vueDemi, shared, firestore, database) {
|
|
75
75
|
'use strict';
|
|
76
76
|
|
|
77
|
-
function useAuth(
|
|
78
|
-
let auth;
|
|
79
|
-
if (authInstance instanceof Function)
|
|
80
|
-
auth = authInstance();
|
|
81
|
-
else
|
|
82
|
-
auth = authInstance;
|
|
77
|
+
function useAuth(auth) {
|
|
83
78
|
const user = vueDemi.ref(auth.currentUser);
|
|
84
79
|
const isAuthenticated = vueDemi.computed(() => !!user.value);
|
|
85
80
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
|
@@ -103,25 +98,36 @@
|
|
|
103
98
|
var _a;
|
|
104
99
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
105
100
|
}
|
|
106
|
-
function useFirestore(
|
|
101
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
107
102
|
const {
|
|
108
103
|
errorHandler = (err) => console.error(err),
|
|
109
104
|
autoDispose = true
|
|
110
105
|
} = options;
|
|
111
|
-
|
|
106
|
+
const refOfDocRef = vueDemi.isRef(maybeDocRef) ? maybeDocRef : vueDemi.computed(() => maybeDocRef);
|
|
107
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
112
108
|
const data = vueDemi.ref(initialValue);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
let close = () => {
|
|
110
|
+
};
|
|
111
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
112
|
+
close();
|
|
113
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
114
|
+
data.value = getData(snapshot) || null;
|
|
115
|
+
}, errorHandler);
|
|
116
|
+
}, { immediate: true });
|
|
116
117
|
shared.tryOnScopeDispose(() => {
|
|
117
118
|
close();
|
|
118
119
|
});
|
|
119
120
|
return data;
|
|
120
121
|
} else {
|
|
121
122
|
const data = vueDemi.ref(initialValue);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
let close = () => {
|
|
124
|
+
};
|
|
125
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
126
|
+
close();
|
|
127
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
128
|
+
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
129
|
+
}, errorHandler);
|
|
130
|
+
}, { immediate: true });
|
|
125
131
|
if (autoDispose) {
|
|
126
132
|
shared.tryOnScopeDispose(() => {
|
|
127
133
|
close();
|
|
@@ -139,12 +145,9 @@
|
|
|
139
145
|
function update(snapshot) {
|
|
140
146
|
data.value = snapshot.val();
|
|
141
147
|
}
|
|
142
|
-
|
|
143
|
-
if (autoDispose)
|
|
144
|
-
shared.tryOnScopeDispose(() =>
|
|
145
|
-
docRef.off("value", update);
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
+
const off = database.onValue(docRef, update);
|
|
149
|
+
if (autoDispose)
|
|
150
|
+
shared.tryOnScopeDispose(() => off());
|
|
148
151
|
return data;
|
|
149
152
|
}
|
|
150
153
|
|
|
@@ -154,4 +157,4 @@
|
|
|
154
157
|
|
|
155
158
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
156
159
|
|
|
157
|
-
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse);
|
|
160
|
+
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse, firestore, database);
|
package/index.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,e,
|
|
1
|
+
var VueDemi=function(n,e,f){if(n.install)return n;if(e)if(e.version.slice(0,4)==="2.7."){for(var t in e)n[t]=e[t];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version}else if(e.version.slice(0,2)==="2.")if(f){for(var t in f)n[t]=f[t];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(e.version.slice(0,2)==="3."){for(var t in e)n[t]=e[t];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=e,n.Vue2=void 0,n.version=e.version,n.set=function(r,u,c){return Array.isArray(r)?(r.length=Math.max(r.length,u),r.splice(u,1,c),c):(r[u]=c,c)},n.del=function(r,u){if(Array.isArray(r)){r.splice(u,1);return}delete r[u]}}else console.error("[vue-demi] Vue version "+e.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(n,e,f,t,r){"use strict";function u(s){const o=e.ref(s.currentUser),d=e.computed(()=>!!o.value);return s.onIdTokenChanged(l=>o.value=l),{isAuthenticated:d,user:o}}function c(s){const o=s.data();return o&&Object.defineProperty(o,"id",{value:s.id.toString(),writable:!1}),o}function y(s){var o;return(((o=s.path)==null?void 0:o.match(/\//g))||[]).length%2!=0}function b(s,o=void 0,d={}){const{errorHandler:l=i=>console.error(i),autoDispose:v=!0}=d,p=e.isRef(s)?s:e.computed(()=>s);if(y(p.value)){const i=e.ref(o);let a=()=>{};return e.watch(p,h=>{a(),a=t.onSnapshot(h,A=>{i.value=c(A)||null},l)},{immediate:!0}),f.tryOnScopeDispose(()=>{a()}),i}else{const i=e.ref(o);let a=()=>{};return e.watch(p,h=>{a(),a=t.onSnapshot(h,A=>{i.value=A.docs.map(c).filter(f.isDef)},l)},{immediate:!0}),v&&f.tryOnScopeDispose(()=>{a()}),i}}function O(s,o={}){const{autoDispose:d=!0}=o,l=e.ref(void 0);function v(i){l.value=i.val()}const p=r.onValue(s,v);return d&&f.tryOnScopeDispose(()=>p()),l}n.useAuth=u,n.useFirestore=b,n.useRTDB=O,Object.defineProperty(n,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firestore,database);
|
package/index.mjs
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import { ref, computed } from 'vue-demi';
|
|
1
|
+
import { ref, computed, isRef, watch } from 'vue-demi';
|
|
2
2
|
import { tryOnScopeDispose, isDef } from '@vueuse/shared';
|
|
3
|
+
import { onSnapshot } from 'firebase/firestore';
|
|
4
|
+
import { onValue } from 'firebase/database';
|
|
3
5
|
|
|
4
|
-
function useAuth(
|
|
5
|
-
let auth;
|
|
6
|
-
if (authInstance instanceof Function)
|
|
7
|
-
auth = authInstance();
|
|
8
|
-
else
|
|
9
|
-
auth = authInstance;
|
|
6
|
+
function useAuth(auth) {
|
|
10
7
|
const user = ref(auth.currentUser);
|
|
11
8
|
const isAuthenticated = computed(() => !!user.value);
|
|
12
9
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
|
@@ -30,25 +27,36 @@ function isDocumentReference(docRef) {
|
|
|
30
27
|
var _a;
|
|
31
28
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
32
29
|
}
|
|
33
|
-
function useFirestore(
|
|
30
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
34
31
|
const {
|
|
35
32
|
errorHandler = (err) => console.error(err),
|
|
36
33
|
autoDispose = true
|
|
37
34
|
} = options;
|
|
38
|
-
|
|
35
|
+
const refOfDocRef = isRef(maybeDocRef) ? maybeDocRef : computed(() => maybeDocRef);
|
|
36
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
39
37
|
const data = ref(initialValue);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
let close = () => {
|
|
39
|
+
};
|
|
40
|
+
watch(refOfDocRef, (docRef) => {
|
|
41
|
+
close();
|
|
42
|
+
close = onSnapshot(docRef, (snapshot) => {
|
|
43
|
+
data.value = getData(snapshot) || null;
|
|
44
|
+
}, errorHandler);
|
|
45
|
+
}, { immediate: true });
|
|
43
46
|
tryOnScopeDispose(() => {
|
|
44
47
|
close();
|
|
45
48
|
});
|
|
46
49
|
return data;
|
|
47
50
|
} else {
|
|
48
51
|
const data = ref(initialValue);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
let close = () => {
|
|
53
|
+
};
|
|
54
|
+
watch(refOfDocRef, (docRef) => {
|
|
55
|
+
close();
|
|
56
|
+
close = onSnapshot(docRef, (snapshot) => {
|
|
57
|
+
data.value = snapshot.docs.map(getData).filter(isDef);
|
|
58
|
+
}, errorHandler);
|
|
59
|
+
}, { immediate: true });
|
|
52
60
|
if (autoDispose) {
|
|
53
61
|
tryOnScopeDispose(() => {
|
|
54
62
|
close();
|
|
@@ -66,12 +74,9 @@ function useRTDB(docRef, options = {}) {
|
|
|
66
74
|
function update(snapshot) {
|
|
67
75
|
data.value = snapshot.val();
|
|
68
76
|
}
|
|
69
|
-
docRef
|
|
70
|
-
if (autoDispose)
|
|
71
|
-
tryOnScopeDispose(() =>
|
|
72
|
-
docRef.off("value", update);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
77
|
+
const off = onValue(docRef, update);
|
|
78
|
+
if (autoDispose)
|
|
79
|
+
tryOnScopeDispose(() => off());
|
|
75
80
|
return data;
|
|
76
81
|
}
|
|
77
82
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vueuse/firebase",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.1",
|
|
4
4
|
"description": "Enables realtime bindings for Firebase",
|
|
5
5
|
"author": "Anthony Fu <https://github.com/antfu>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
"jsdelivr": "./index.iife.min.js",
|
|
52
52
|
"types": "./index.d.ts",
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"firebase": ">=
|
|
54
|
+
"firebase": ">=9.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@vueuse/shared": "9.0.
|
|
57
|
+
"@vueuse/shared": "9.0.1",
|
|
58
58
|
"vue-demi": "*"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/useAuth.cjs
CHANGED
|
@@ -4,12 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vueDemi = require('vue-demi');
|
|
6
6
|
|
|
7
|
-
function useAuth(
|
|
8
|
-
let auth;
|
|
9
|
-
if (authInstance instanceof Function)
|
|
10
|
-
auth = authInstance();
|
|
11
|
-
else
|
|
12
|
-
auth = authInstance;
|
|
7
|
+
function useAuth(auth) {
|
|
13
8
|
const user = vueDemi.ref(auth.currentUser);
|
|
14
9
|
const isAuthenticated = vueDemi.computed(() => !!user.value);
|
|
15
10
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
package/useAuth.d.ts
CHANGED
|
@@ -1,72 +1,47 @@
|
|
|
1
|
+
import * as _firebase_auth from '@firebase/auth';
|
|
1
2
|
import { ComputedRef, Ref } from 'vue-demi';
|
|
2
|
-
import
|
|
3
|
+
import { User, Auth } from 'firebase/auth';
|
|
3
4
|
|
|
4
|
-
interface
|
|
5
|
+
interface UseFirebaseAuthOptions {
|
|
5
6
|
isAuthenticated: ComputedRef<boolean>;
|
|
6
|
-
user: Ref<
|
|
7
|
+
user: Ref<User | null>;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Reactive Firebase Auth binding
|
|
11
|
+
*
|
|
12
|
+
* @see https://vueuse.org/useAuth
|
|
13
|
+
*/
|
|
14
|
+
declare function useAuth(auth: Auth): {
|
|
9
15
|
isAuthenticated: ComputedRef<boolean>;
|
|
10
16
|
user: Ref<{
|
|
17
|
+
readonly emailVerified: boolean;
|
|
18
|
+
readonly isAnonymous: boolean;
|
|
19
|
+
readonly metadata: {
|
|
20
|
+
readonly creationTime?: string | undefined;
|
|
21
|
+
readonly lastSignInTime?: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
readonly providerData: {
|
|
24
|
+
readonly displayName: string | null;
|
|
25
|
+
readonly email: string | null;
|
|
26
|
+
readonly phoneNumber: string | null;
|
|
27
|
+
readonly photoURL: string | null;
|
|
28
|
+
readonly providerId: string;
|
|
29
|
+
readonly uid: string;
|
|
30
|
+
}[];
|
|
31
|
+
readonly refreshToken: string;
|
|
32
|
+
readonly tenantId: string | null;
|
|
11
33
|
delete: () => Promise<void>;
|
|
12
|
-
emailVerified: boolean;
|
|
13
|
-
getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<firebase.auth.IdTokenResult>;
|
|
14
34
|
getIdToken: (forceRefresh?: boolean | undefined) => Promise<string>;
|
|
15
|
-
|
|
16
|
-
linkAndRetrieveDataWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
17
|
-
linkWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
18
|
-
linkWithPhoneNumber: (phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier) => Promise<firebase.auth.ConfirmationResult>;
|
|
19
|
-
linkWithPopup: (provider: firebase.auth.AuthProvider) => Promise<firebase.auth.UserCredential>;
|
|
20
|
-
linkWithRedirect: (provider: firebase.auth.AuthProvider) => Promise<void>;
|
|
21
|
-
metadata: {
|
|
22
|
-
creationTime?: string | undefined;
|
|
23
|
-
lastSignInTime?: string | undefined;
|
|
24
|
-
};
|
|
25
|
-
multiFactor: {
|
|
26
|
-
enrolledFactors: {
|
|
27
|
-
uid: string;
|
|
28
|
-
displayName?: string | null | undefined;
|
|
29
|
-
enrollmentTime: string;
|
|
30
|
-
factorId: string;
|
|
31
|
-
}[];
|
|
32
|
-
enroll: (assertion: firebase.auth.MultiFactorAssertion, displayName?: string | null | undefined) => Promise<void>;
|
|
33
|
-
getSession: () => Promise<firebase.auth.MultiFactorSession>;
|
|
34
|
-
unenroll: (option: string | firebase.auth.MultiFactorInfo) => Promise<void>;
|
|
35
|
-
};
|
|
36
|
-
phoneNumber: string | null;
|
|
37
|
-
providerData: ({
|
|
38
|
-
displayName: string | null;
|
|
39
|
-
email: string | null;
|
|
40
|
-
phoneNumber: string | null;
|
|
41
|
-
photoURL: string | null;
|
|
42
|
-
providerId: string;
|
|
43
|
-
uid: string;
|
|
44
|
-
} | null)[];
|
|
45
|
-
reauthenticateAndRetrieveDataWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
46
|
-
reauthenticateWithCredential: (credential: firebase.auth.AuthCredential) => Promise<firebase.auth.UserCredential>;
|
|
47
|
-
reauthenticateWithPhoneNumber: (phoneNumber: string, applicationVerifier: firebase.auth.ApplicationVerifier) => Promise<firebase.auth.ConfirmationResult>;
|
|
48
|
-
reauthenticateWithPopup: (provider: firebase.auth.AuthProvider) => Promise<firebase.auth.UserCredential>;
|
|
49
|
-
reauthenticateWithRedirect: (provider: firebase.auth.AuthProvider) => Promise<void>;
|
|
50
|
-
refreshToken: string;
|
|
35
|
+
getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<_firebase_auth.IdTokenResult>;
|
|
51
36
|
reload: () => Promise<void>;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
updateProfile: (profile: {
|
|
60
|
-
displayName?: string | null | undefined;
|
|
61
|
-
photoURL?: string | null | undefined;
|
|
62
|
-
}) => Promise<void>;
|
|
63
|
-
verifyBeforeUpdateEmail: (newEmail: string, actionCodeSettings?: firebase.auth.ActionCodeSettings | null | undefined) => Promise<void>;
|
|
64
|
-
displayName: string | null;
|
|
65
|
-
email: string | null;
|
|
66
|
-
photoURL: string | null;
|
|
67
|
-
providerId: string;
|
|
68
|
-
uid: string;
|
|
37
|
+
toJSON: () => object;
|
|
38
|
+
readonly displayName: string | null;
|
|
39
|
+
readonly email: string | null;
|
|
40
|
+
readonly phoneNumber: string | null;
|
|
41
|
+
readonly photoURL: string | null;
|
|
42
|
+
readonly providerId: string;
|
|
43
|
+
readonly uid: string;
|
|
69
44
|
} | null>;
|
|
70
45
|
};
|
|
71
46
|
|
|
72
|
-
export {
|
|
47
|
+
export { UseFirebaseAuthOptions, useAuth };
|
package/useAuth.iife.js
CHANGED
|
@@ -74,12 +74,7 @@
|
|
|
74
74
|
;(function (exports, vueDemi) {
|
|
75
75
|
'use strict';
|
|
76
76
|
|
|
77
|
-
function useAuth(
|
|
78
|
-
let auth;
|
|
79
|
-
if (authInstance instanceof Function)
|
|
80
|
-
auth = authInstance();
|
|
81
|
-
else
|
|
82
|
-
auth = authInstance;
|
|
77
|
+
function useAuth(auth) {
|
|
83
78
|
const user = vueDemi.ref(auth.currentUser);
|
|
84
79
|
const isAuthenticated = vueDemi.computed(() => !!user.value);
|
|
85
80
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
package/useAuth.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,
|
|
1
|
+
var VueDemi=function(n,s,t){if(n.install)return n;if(s)if(s.version.slice(0,4)==="2.7."){for(var o in s)n[o]=s[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else if(s.version.slice(0,2)==="2.")if(t){for(var o in t)n[o]=t[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(s.version.slice(0,2)==="3."){for(var o in s)n[o]=s[o];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=s,n.Vue2=void 0,n.version=s.version,n.set=function(e,r,i){return Array.isArray(e)?(e.length=Math.max(e.length,r),e.splice(r,1,i),i):(e[r]=i,i)},n.del=function(e,r){if(Array.isArray(e)){e.splice(r,1);return}delete e[r]}}else console.error("[vue-demi] Vue version "+s.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(n,s){"use strict";function t(o){const e=s.ref(o.currentUser),r=s.computed(()=>!!e.value);return o.onIdTokenChanged(i=>e.value=i),{isAuthenticated:r,user:e}}n.useAuth=t,Object.defineProperty(n,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},VueDemi);
|
package/useAuth.mjs
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { ref, computed } from 'vue-demi';
|
|
2
2
|
|
|
3
|
-
function useAuth(
|
|
4
|
-
let auth;
|
|
5
|
-
if (authInstance instanceof Function)
|
|
6
|
-
auth = authInstance();
|
|
7
|
-
else
|
|
8
|
-
auth = authInstance;
|
|
3
|
+
function useAuth(auth) {
|
|
9
4
|
const user = ref(auth.currentUser);
|
|
10
5
|
const isAuthenticated = computed(() => !!user.value);
|
|
11
6
|
auth.onIdTokenChanged((authUser) => user.value = authUser);
|
package/useFirestore.cjs
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var vueDemi = require('vue-demi');
|
|
6
6
|
var shared = require('@vueuse/shared');
|
|
7
|
+
var firestore = require('firebase/firestore');
|
|
7
8
|
|
|
8
9
|
function getData(docRef) {
|
|
9
10
|
const data = docRef.data();
|
|
@@ -19,25 +20,36 @@ function isDocumentReference(docRef) {
|
|
|
19
20
|
var _a;
|
|
20
21
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
21
22
|
}
|
|
22
|
-
function useFirestore(
|
|
23
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
23
24
|
const {
|
|
24
25
|
errorHandler = (err) => console.error(err),
|
|
25
26
|
autoDispose = true
|
|
26
27
|
} = options;
|
|
27
|
-
|
|
28
|
+
const refOfDocRef = vueDemi.isRef(maybeDocRef) ? maybeDocRef : vueDemi.computed(() => maybeDocRef);
|
|
29
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
28
30
|
const data = vueDemi.ref(initialValue);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
let close = () => {
|
|
32
|
+
};
|
|
33
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
34
|
+
close();
|
|
35
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
36
|
+
data.value = getData(snapshot) || null;
|
|
37
|
+
}, errorHandler);
|
|
38
|
+
}, { immediate: true });
|
|
32
39
|
shared.tryOnScopeDispose(() => {
|
|
33
40
|
close();
|
|
34
41
|
});
|
|
35
42
|
return data;
|
|
36
43
|
} else {
|
|
37
44
|
const data = vueDemi.ref(initialValue);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
let close = () => {
|
|
46
|
+
};
|
|
47
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
48
|
+
close();
|
|
49
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
50
|
+
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
51
|
+
}, errorHandler);
|
|
52
|
+
}, { immediate: true });
|
|
41
53
|
if (autoDispose) {
|
|
42
54
|
shared.tryOnScopeDispose(() => {
|
|
43
55
|
close();
|
package/useFirestore.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import firebase from 'firebase';
|
|
2
1
|
import { Ref } from 'vue-demi';
|
|
2
|
+
import { Query, DocumentReference, DocumentData } from 'firebase/firestore';
|
|
3
|
+
import { MaybeRef } from '@vueuse/shared';
|
|
3
4
|
|
|
4
|
-
interface
|
|
5
|
+
interface UseFirestoreOptions {
|
|
5
6
|
errorHandler?: (err: Error) => void;
|
|
6
7
|
autoDispose?: boolean;
|
|
7
8
|
}
|
|
8
|
-
declare type FirebaseDocRef<T> =
|
|
9
|
-
declare function useFirestore<T extends
|
|
10
|
-
declare function useFirestore<T extends
|
|
11
|
-
declare function useFirestore<T extends
|
|
12
|
-
declare function useFirestore<T extends
|
|
9
|
+
declare type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
|
|
10
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T>>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
|
|
11
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T>>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
|
|
12
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T>>, initialValue?: T | undefined, options?: UseFirestoreOptions): Ref<T | undefined | null>;
|
|
13
|
+
declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T>>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
|
|
13
14
|
|
|
14
|
-
export { FirebaseDocRef,
|
|
15
|
+
export { FirebaseDocRef, UseFirestoreOptions, useFirestore };
|
package/useFirestore.iife.js
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
this.VueCompositionAPI || (typeof VueCompositionAPI !== "undefined" ? VueCompositionAPI : undefined)
|
|
72
72
|
);
|
|
73
73
|
;
|
|
74
|
-
;(function (exports, vueDemi, shared) {
|
|
74
|
+
;(function (exports, vueDemi, shared, firestore) {
|
|
75
75
|
'use strict';
|
|
76
76
|
|
|
77
77
|
function getData(docRef) {
|
|
@@ -88,25 +88,36 @@
|
|
|
88
88
|
var _a;
|
|
89
89
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
90
90
|
}
|
|
91
|
-
function useFirestore(
|
|
91
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
92
92
|
const {
|
|
93
93
|
errorHandler = (err) => console.error(err),
|
|
94
94
|
autoDispose = true
|
|
95
95
|
} = options;
|
|
96
|
-
|
|
96
|
+
const refOfDocRef = vueDemi.isRef(maybeDocRef) ? maybeDocRef : vueDemi.computed(() => maybeDocRef);
|
|
97
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
97
98
|
const data = vueDemi.ref(initialValue);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
let close = () => {
|
|
100
|
+
};
|
|
101
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
102
|
+
close();
|
|
103
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
104
|
+
data.value = getData(snapshot) || null;
|
|
105
|
+
}, errorHandler);
|
|
106
|
+
}, { immediate: true });
|
|
101
107
|
shared.tryOnScopeDispose(() => {
|
|
102
108
|
close();
|
|
103
109
|
});
|
|
104
110
|
return data;
|
|
105
111
|
} else {
|
|
106
112
|
const data = vueDemi.ref(initialValue);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
113
|
+
let close = () => {
|
|
114
|
+
};
|
|
115
|
+
vueDemi.watch(refOfDocRef, (docRef) => {
|
|
116
|
+
close();
|
|
117
|
+
close = firestore.onSnapshot(docRef, (snapshot) => {
|
|
118
|
+
data.value = snapshot.docs.map(getData).filter(shared.isDef);
|
|
119
|
+
}, errorHandler);
|
|
120
|
+
}, { immediate: true });
|
|
110
121
|
if (autoDispose) {
|
|
111
122
|
shared.tryOnScopeDispose(() => {
|
|
112
123
|
close();
|
|
@@ -120,4 +131,4 @@
|
|
|
120
131
|
|
|
121
132
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
122
133
|
|
|
123
|
-
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse);
|
|
134
|
+
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse, firestore);
|
package/useFirestore.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,
|
|
1
|
+
var VueDemi=function(e,n,f){if(e.install)return e;if(n)if(n.version.slice(0,4)==="2.7."){for(var o in n)e[o]=n[o];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version}else if(n.version.slice(0,2)==="2.")if(f){for(var o in f)e[o]=f[o];e.isVue2=!0,e.isVue3=!1,e.install=function(){},e.Vue=n,e.Vue2=n,e.version=n.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(n.version.slice(0,2)==="3."){for(var o in n)e[o]=n[o];e.isVue2=!1,e.isVue3=!0,e.install=function(){},e.Vue=n,e.Vue2=void 0,e.version=n.version,e.set=function(s,t,a){return Array.isArray(s)?(s.length=Math.max(s.length,t),s.splice(t,1,a),a):(s[t]=a,a)},e.del=function(s,t){if(Array.isArray(s)){s.splice(t,1);return}delete s[t]}}else console.error("[vue-demi] Vue version "+n.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");return e}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(e,n,f,o){"use strict";function s(i){const r=i.data();return r&&Object.defineProperty(r,"id",{value:i.id.toString(),writable:!1}),r}function t(i){var r;return(((r=i.path)==null?void 0:r.match(/\//g))||[]).length%2!=0}function a(i,r=void 0,h={}){const{errorHandler:v=l=>console.error(l),autoDispose:y=!0}=h,u=n.isRef(i)?i:n.computed(()=>i);if(t(u.value)){const l=n.ref(r);let c=()=>{};return n.watch(u,d=>{c(),c=o.onSnapshot(d,p=>{l.value=s(p)||null},v)},{immediate:!0}),f.tryOnScopeDispose(()=>{c()}),l}else{const l=n.ref(r);let c=()=>{};return n.watch(u,d=>{c(),c=o.onSnapshot(d,p=>{l.value=p.docs.map(s).filter(f.isDef)},v)},{immediate:!0}),y&&f.tryOnScopeDispose(()=>{c()}),l}}e.useFirestore=a,Object.defineProperty(e,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firestore);
|
package/useFirestore.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ref } from 'vue-demi';
|
|
1
|
+
import { isRef, computed, ref, watch } from 'vue-demi';
|
|
2
2
|
import { tryOnScopeDispose, isDef } from '@vueuse/shared';
|
|
3
|
+
import { onSnapshot } from 'firebase/firestore';
|
|
3
4
|
|
|
4
5
|
function getData(docRef) {
|
|
5
6
|
const data = docRef.data();
|
|
@@ -15,25 +16,36 @@ function isDocumentReference(docRef) {
|
|
|
15
16
|
var _a;
|
|
16
17
|
return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
|
|
17
18
|
}
|
|
18
|
-
function useFirestore(
|
|
19
|
+
function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
|
|
19
20
|
const {
|
|
20
21
|
errorHandler = (err) => console.error(err),
|
|
21
22
|
autoDispose = true
|
|
22
23
|
} = options;
|
|
23
|
-
|
|
24
|
+
const refOfDocRef = isRef(maybeDocRef) ? maybeDocRef : computed(() => maybeDocRef);
|
|
25
|
+
if (isDocumentReference(refOfDocRef.value)) {
|
|
24
26
|
const data = ref(initialValue);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
let close = () => {
|
|
28
|
+
};
|
|
29
|
+
watch(refOfDocRef, (docRef) => {
|
|
30
|
+
close();
|
|
31
|
+
close = onSnapshot(docRef, (snapshot) => {
|
|
32
|
+
data.value = getData(snapshot) || null;
|
|
33
|
+
}, errorHandler);
|
|
34
|
+
}, { immediate: true });
|
|
28
35
|
tryOnScopeDispose(() => {
|
|
29
36
|
close();
|
|
30
37
|
});
|
|
31
38
|
return data;
|
|
32
39
|
} else {
|
|
33
40
|
const data = ref(initialValue);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
let close = () => {
|
|
42
|
+
};
|
|
43
|
+
watch(refOfDocRef, (docRef) => {
|
|
44
|
+
close();
|
|
45
|
+
close = onSnapshot(docRef, (snapshot) => {
|
|
46
|
+
data.value = snapshot.docs.map(getData).filter(isDef);
|
|
47
|
+
}, errorHandler);
|
|
48
|
+
}, { immediate: true });
|
|
37
49
|
if (autoDispose) {
|
|
38
50
|
tryOnScopeDispose(() => {
|
|
39
51
|
close();
|
package/useRTDB.cjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var database = require('firebase/database');
|
|
5
6
|
var vueDemi = require('vue-demi');
|
|
6
7
|
var shared = require('@vueuse/shared');
|
|
7
8
|
|
|
@@ -13,12 +14,9 @@ function useRTDB(docRef, options = {}) {
|
|
|
13
14
|
function update(snapshot) {
|
|
14
15
|
data.value = snapshot.val();
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
if (autoDispose)
|
|
18
|
-
shared.tryOnScopeDispose(() =>
|
|
19
|
-
docRef.off("value", update);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
17
|
+
const off = database.onValue(docRef, update);
|
|
18
|
+
if (autoDispose)
|
|
19
|
+
shared.tryOnScopeDispose(() => off());
|
|
22
20
|
return data;
|
|
23
21
|
}
|
|
24
22
|
|
package/useRTDB.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DatabaseReference } from 'firebase/database';
|
|
2
2
|
import { Ref } from 'vue-demi';
|
|
3
3
|
|
|
4
4
|
interface UseRTDBOptions {
|
|
@@ -7,9 +7,8 @@ interface UseRTDBOptions {
|
|
|
7
7
|
/**
|
|
8
8
|
* Reactive Firebase Realtime Database binding.
|
|
9
9
|
*
|
|
10
|
-
* @
|
|
11
|
-
* @param options
|
|
10
|
+
* @see https://vueuse.org/useRTDB
|
|
12
11
|
*/
|
|
13
|
-
declare function useRTDB<T = any>(docRef:
|
|
12
|
+
declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
|
|
14
13
|
|
|
15
14
|
export { UseRTDBOptions, useRTDB };
|
package/useRTDB.iife.js
CHANGED
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
this.VueCompositionAPI || (typeof VueCompositionAPI !== "undefined" ? VueCompositionAPI : undefined)
|
|
72
72
|
);
|
|
73
73
|
;
|
|
74
|
-
;(function (exports, vueDemi, shared) {
|
|
74
|
+
;(function (exports, database, vueDemi, shared) {
|
|
75
75
|
'use strict';
|
|
76
76
|
|
|
77
77
|
function useRTDB(docRef, options = {}) {
|
|
@@ -82,12 +82,9 @@
|
|
|
82
82
|
function update(snapshot) {
|
|
83
83
|
data.value = snapshot.val();
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
if (autoDispose)
|
|
87
|
-
shared.tryOnScopeDispose(() =>
|
|
88
|
-
docRef.off("value", update);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
85
|
+
const off = database.onValue(docRef, update);
|
|
86
|
+
if (autoDispose)
|
|
87
|
+
shared.tryOnScopeDispose(() => off());
|
|
91
88
|
return data;
|
|
92
89
|
}
|
|
93
90
|
|
|
@@ -95,4 +92,4 @@
|
|
|
95
92
|
|
|
96
93
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
97
94
|
|
|
98
|
-
})(this.VueUse = this.VueUse || {}, VueDemi, VueUse);
|
|
95
|
+
})(this.VueUse = this.VueUse || {}, database, VueDemi, VueUse);
|
package/useRTDB.iife.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var VueDemi=function(n,s,t){if(n.install)return n;if(s)if(s.version.slice(0,4)==="2.7."){for(var o in s)n[o]=s[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else if(s.version.slice(0,2)==="2.")if(t){for(var o in t)n[o]=t[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(s.version.slice(0,2)==="3."){for(var o in s)n[o]=s[o];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=s,n.Vue2=void 0,n.version=s.version,n.set=function(e,i,r){return Array.isArray(e)?(e.length=Math.max(e.length,i),e.splice(i,1,r),r):(e[i]=r,r)},n.del=function(e,i){if(Array.isArray(e)){e.splice(i,1);return}delete e[i]}}else console.error("[vue-demi] Vue version "+s.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(n,s,t){"use strict";function
|
|
1
|
+
var VueDemi=function(n,s,t){if(n.install)return n;if(s)if(s.version.slice(0,4)==="2.7."){for(var o in s)n[o]=s[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else if(s.version.slice(0,2)==="2.")if(t){for(var o in t)n[o]=t[o];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=s,n.Vue2=s,n.version=s.version}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(s.version.slice(0,2)==="3."){for(var o in s)n[o]=s[o];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=s,n.Vue2=void 0,n.version=s.version,n.set=function(e,i,r){return Array.isArray(e)?(e.length=Math.max(e.length,i),e.splice(i,1,r),r):(e[i]=r,r)},n.del=function(e,i){if(Array.isArray(e)){e.splice(i,1);return}delete e[i]}}else console.error("[vue-demi] Vue version "+s.version+" is unsupported.");else console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi!="undefined"?VueDemi:{}),this.Vue||(typeof Vue!="undefined"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI!="undefined"?VueCompositionAPI:void 0));(function(n,s,t,o){"use strict";function e(i,r={}){const{autoDispose:l=!0}=r,f=t.ref(void 0);function u(c){f.value=c.val()}const d=s.onValue(i,u);return l&&o.tryOnScopeDispose(()=>d()),f}n.useRTDB=e,Object.defineProperty(n,"__esModule",{value:!0})})(this.VueUse=this.VueUse||{},database,VueDemi,VueUse);
|
package/useRTDB.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { onValue } from 'firebase/database';
|
|
1
2
|
import { ref } from 'vue-demi';
|
|
2
3
|
import { tryOnScopeDispose } from '@vueuse/shared';
|
|
3
4
|
|
|
@@ -9,12 +10,9 @@ function useRTDB(docRef, options = {}) {
|
|
|
9
10
|
function update(snapshot) {
|
|
10
11
|
data.value = snapshot.val();
|
|
11
12
|
}
|
|
12
|
-
docRef
|
|
13
|
-
if (autoDispose)
|
|
14
|
-
tryOnScopeDispose(() =>
|
|
15
|
-
docRef.off("value", update);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
13
|
+
const off = onValue(docRef, update);
|
|
14
|
+
if (autoDispose)
|
|
15
|
+
tryOnScopeDispose(() => off());
|
|
18
16
|
return data;
|
|
19
17
|
}
|
|
20
18
|
|