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