@vueuse/firebase 10.2.1 → 10.4.0

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/index.cjs CHANGED
@@ -26,8 +26,7 @@ function getData(docRef) {
26
26
  return data;
27
27
  }
28
28
  function isDocumentReference(docRef) {
29
- var _a;
30
- return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
29
+ return (docRef.path?.match(/\//g) || []).length % 2 !== 0;
31
30
  }
32
31
  function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
33
32
  const {
@@ -68,13 +67,14 @@ function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
68
67
 
69
68
  function useRTDB(docRef, options = {}) {
70
69
  const {
70
+ errorHandler = (err) => console.error(err),
71
71
  autoDispose = true
72
72
  } = options;
73
73
  const data = vueDemi.ref(void 0);
74
74
  function update(snapshot) {
75
75
  data.value = snapshot.val();
76
76
  }
77
- const off = database.onValue(docRef, update);
77
+ const off = database.onValue(docRef, update, errorHandler);
78
78
  if (autoDispose)
79
79
  shared.tryOnScopeDispose(() => off());
80
80
  return data;
package/index.d.cts ADDED
@@ -0,0 +1,72 @@
1
+ import * as _firebase_auth from '@firebase/auth';
2
+ import { ComputedRef, Ref } from 'vue-demi';
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';
7
+
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
+ 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 | undefined) => Promise<string>;
38
+ getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<_firebase_auth.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>;
48
+ };
49
+
50
+ interface UseFirestoreOptions {
51
+ errorHandler?: (err: Error) => void;
52
+ autoDispose?: boolean | number;
53
+ }
54
+ type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
55
+ type Falsy = false | 0 | '' | null | undefined;
56
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
57
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
58
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
59
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
60
+
61
+ interface UseRTDBOptions {
62
+ errorHandler?: (err: Error) => void;
63
+ autoDispose?: boolean;
64
+ }
65
+ /**
66
+ * Reactive Firebase Realtime Database binding.
67
+ *
68
+ * @see https://vueuse.org/useRTDB
69
+ */
70
+ declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
71
+
72
+ export { type FirebaseDocRef, type UseFirebaseAuthOptions, type UseFirestoreOptions, type UseRTDBOptions, useAuth, useFirestore, useRTDB };
package/index.d.mts ADDED
@@ -0,0 +1,72 @@
1
+ import * as _firebase_auth from '@firebase/auth';
2
+ import { ComputedRef, Ref } from 'vue-demi';
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';
7
+
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
+ 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 | undefined) => Promise<string>;
38
+ getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<_firebase_auth.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>;
48
+ };
49
+
50
+ interface UseFirestoreOptions {
51
+ errorHandler?: (err: Error) => void;
52
+ autoDispose?: boolean | number;
53
+ }
54
+ type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
55
+ type Falsy = false | 0 | '' | null | undefined;
56
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
57
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
58
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
59
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
60
+
61
+ interface UseRTDBOptions {
62
+ errorHandler?: (err: Error) => void;
63
+ autoDispose?: boolean;
64
+ }
65
+ /**
66
+ * Reactive Firebase Realtime Database binding.
67
+ *
68
+ * @see https://vueuse.org/useRTDB
69
+ */
70
+ declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
71
+
72
+ export { type FirebaseDocRef, type UseFirebaseAuthOptions, type UseFirestoreOptions, type UseRTDBOptions, useAuth, useFirestore, useRTDB };
package/index.d.ts CHANGED
@@ -59,6 +59,7 @@ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Docu
59
59
  declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
60
60
 
61
61
  interface UseRTDBOptions {
62
+ errorHandler?: (err: Error) => void;
62
63
  autoDispose?: boolean;
63
64
  }
64
65
  /**
@@ -68,4 +69,4 @@ interface UseRTDBOptions {
68
69
  */
69
70
  declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
70
71
 
71
- export { FirebaseDocRef, UseFirebaseAuthOptions, UseFirestoreOptions, UseRTDBOptions, useAuth, useFirestore, useRTDB };
72
+ export { type FirebaseDocRef, type UseFirebaseAuthOptions, type UseFirestoreOptions, type UseRTDBOptions, useAuth, useFirestore, useRTDB };
package/index.iife.js CHANGED
@@ -138,8 +138,7 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
138
138
  return data;
139
139
  }
140
140
  function isDocumentReference(docRef) {
141
- var _a;
142
- return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
141
+ return (docRef.path?.match(/\//g) || []).length % 2 !== 0;
143
142
  }
144
143
  function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
145
144
  const {
@@ -180,13 +179,14 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
180
179
 
181
180
  function useRTDB(docRef, options = {}) {
182
181
  const {
182
+ errorHandler = (err) => console.error(err),
183
183
  autoDispose = true
184
184
  } = options;
185
185
  const data = vueDemi.ref(void 0);
186
186
  function update(snapshot) {
187
187
  data.value = snapshot.val();
188
188
  }
189
- const off = database.onValue(docRef, update);
189
+ const off = database.onValue(docRef, update, errorHandler);
190
190
  if (autoDispose)
191
191
  shared.tryOnScopeDispose(() => off());
192
192
  return data;
package/index.iife.min.js CHANGED
@@ -1 +1 @@
1
- var VueDemi=function(n,t,u){if(n.install)return n;if(!t)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),n;if(t.version.slice(0,4)==="2.7."){let o=function(s,a){var c,h={},r={config:t.config,use:t.use.bind(t),mixin:t.mixin.bind(t),component:t.component.bind(t),provide:function(e,i){return h[e]=i,this},directive:function(e,i){return i?(t.directive(e,i),r):t.directive(e)},mount:function(e,i){return c||(c=new t(Object.assign({propsData:a},s,{provide:Object.assign(h,s.provide)})),c.$mount(e,i),c)},unmount:function(){c&&(c.$destroy(),c=void 0)}};return r};var g=o;for(var f in t)n[f]=t[f];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=t,n.Vue2=t,n.version=t.version,n.warn=t.util.warn,n.hasInjectionContext=()=>!!n.getCurrentInstance(),n.createApp=o}else if(t.version.slice(0,2)==="2.")if(u){for(var f in u)n[f]=u[f];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=t,n.Vue2=t,n.version=t.version,n.hasInjectionContext=()=>!!n.getCurrentInstance()}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(t.version.slice(0,2)==="3."){for(var f in t)n[f]=t[f];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=t,n.Vue2=void 0,n.version=t.version,n.set=function(o,s,a){return Array.isArray(o)?(o.length=Math.max(o.length,s),o.splice(s,1,a),a):(o[s]=a,a)},n.del=function(o,s){if(Array.isArray(o)){o.splice(s,1);return}delete o[s]}}else console.error("[vue-demi] Vue version "+t.version+" is unsupported.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi<"u"?VueDemi:{}),this.Vue||(typeof Vue<"u"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI<"u"?VueCompositionAPI:void 0));(function(n,t,u,f,g){"use strict";function o(r){const e=t.ref(r.currentUser),i=t.computed(()=>!!e.value);return r.onIdTokenChanged(l=>e.value=l),{isAuthenticated:i,user:e}}function s(r){const e=r.data();return e&&Object.defineProperty(e,"id",{value:r.id.toString(),writable:!1}),e}function a(r){var e;return(((e=r.path)==null?void 0:e.match(/\//g))||[]).length%2!==0}function c(r,e=void 0,i={}){const{errorHandler:l=A=>console.error(A),autoDispose:p=!0}=i,v=t.isRef(r)?r:t.computed(()=>r);let d=()=>{};const b=t.ref(e);return t.watch(v,A=>{d(),v.value?a(v.value)?d=f.onSnapshot(A,y=>{b.value=s(y)||null},l):d=f.onSnapshot(A,y=>{b.value=y.docs.map(s).filter(u.isDef)},l):b.value=e},{immediate:!0}),p===!0?u.tryOnScopeDispose(()=>{d()}):typeof p=="number"&&u.tryOnScopeDispose(()=>{u.useTimeoutFn(()=>{d()},p)}),b}function h(r,e={}){const{autoDispose:i=!0}=e,l=t.ref(void 0);function p(d){l.value=d.val()}const v=g.onValue(r,p);return i&&u.tryOnScopeDispose(()=>v()),l}n.useAuth=o,n.useFirestore=c,n.useRTDB=h})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firebase,firebase);
1
+ var VueDemi=function(n,e,u){if(n.install)return n;if(!e)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),n;if(e.version.slice(0,4)==="2.7."){let o=function(s,a){var c,b={},r={config:e.config,use:e.use.bind(e),mixin:e.mixin.bind(e),component:e.component.bind(e),provide:function(t,i){return b[t]=i,this},directive:function(t,i){return i?(e.directive(t,i),r):e.directive(t)},mount:function(t,i){return c||(c=new e(Object.assign({propsData:a},s,{provide:Object.assign(b,s.provide)})),c.$mount(t,i),c)},unmount:function(){c&&(c.$destroy(),c=void 0)}};return r};var g=o;for(var f in e)n[f]=e[f];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version,n.warn=e.util.warn,n.hasInjectionContext=()=>!!n.getCurrentInstance(),n.createApp=o}else if(e.version.slice(0,2)==="2.")if(u){for(var f in u)n[f]=u[f];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version,n.hasInjectionContext=()=>!!n.getCurrentInstance()}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 f in e)n[f]=e[f];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=e,n.Vue2=void 0,n.version=e.version,n.set=function(o,s,a){return Array.isArray(o)?(o.length=Math.max(o.length,s),o.splice(s,1,a),a):(o[s]=a,a)},n.del=function(o,s){if(Array.isArray(o)){o.splice(s,1);return}delete o[s]}}else console.error("[vue-demi] Vue version "+e.version+" is unsupported.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi<"u"?VueDemi:{}),this.Vue||(typeof Vue<"u"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI<"u"?VueCompositionAPI:void 0));(function(n,e,u,f,g){"use strict";function o(r){const t=e.ref(r.currentUser),i=e.computed(()=>!!t.value);return r.onIdTokenChanged(p=>t.value=p),{isAuthenticated:i,user:t}}function s(r){const t=r.data();return t&&Object.defineProperty(t,"id",{value:r.id.toString(),writable:!1}),t}function a(r){return(r.path?.match(/\//g)||[]).length%2!==0}function c(r,t=void 0,i={}){const{errorHandler:p=A=>console.error(A),autoDispose:v=!0}=i,h=e.isRef(r)?r:e.computed(()=>r);let d=()=>{};const l=e.ref(t);return e.watch(h,A=>{d(),h.value?a(h.value)?d=f.onSnapshot(A,y=>{l.value=s(y)||null},p):d=f.onSnapshot(A,y=>{l.value=y.docs.map(s).filter(u.isDef)},p):l.value=t},{immediate:!0}),v===!0?u.tryOnScopeDispose(()=>{d()}):typeof v=="number"&&u.tryOnScopeDispose(()=>{u.useTimeoutFn(()=>{d()},v)}),l}function b(r,t={}){const{errorHandler:i=l=>console.error(l),autoDispose:p=!0}=t,v=e.ref(void 0);function h(l){v.value=l.val()}const d=g.onValue(r,h,i);return p&&u.tryOnScopeDispose(()=>d()),v}n.useAuth=o,n.useFirestore=c,n.useRTDB=b})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firebase,firebase);
package/index.mjs CHANGED
@@ -24,8 +24,7 @@ function getData(docRef) {
24
24
  return data;
25
25
  }
26
26
  function isDocumentReference(docRef) {
27
- var _a;
28
- return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
27
+ return (docRef.path?.match(/\//g) || []).length % 2 !== 0;
29
28
  }
30
29
  function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
31
30
  const {
@@ -66,13 +65,14 @@ function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
66
65
 
67
66
  function useRTDB(docRef, options = {}) {
68
67
  const {
68
+ errorHandler = (err) => console.error(err),
69
69
  autoDispose = true
70
70
  } = options;
71
71
  const data = ref(void 0);
72
72
  function update(snapshot) {
73
73
  data.value = snapshot.val();
74
74
  }
75
- const off = onValue(docRef, update);
75
+ const off = onValue(docRef, update, errorHandler);
76
76
  if (autoDispose)
77
77
  tryOnScopeDispose(() => off());
78
78
  return data;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vueuse/firebase",
3
- "version": "10.2.1",
3
+ "version": "10.4.0",
4
4
  "description": "Enables realtime bindings for Firebase",
5
5
  "author": "Anthony Fu <https://github.com/antfu>",
6
6
  "license": "MIT",
@@ -24,23 +24,19 @@
24
24
  "sideEffects": false,
25
25
  "exports": {
26
26
  ".": {
27
- "types": "./index.d.ts",
28
- "require": "./index.cjs",
29
- "import": "./index.mjs"
27
+ "import": "./index.mjs",
28
+ "require": "./index.cjs"
30
29
  },
31
30
  "./*": "./*",
32
31
  "./useAuth": {
33
- "types": "./useAuth.d.ts",
34
32
  "require": "./useAuth.cjs",
35
33
  "import": "./useAuth.mjs"
36
34
  },
37
35
  "./useFirestore": {
38
- "types": "./useFirestore.d.ts",
39
36
  "require": "./useFirestore.cjs",
40
37
  "import": "./useFirestore.mjs"
41
38
  },
42
39
  "./useRTDB": {
43
- "types": "./useRTDB.d.ts",
44
40
  "require": "./useRTDB.cjs",
45
41
  "import": "./useRTDB.mjs"
46
42
  }
@@ -49,12 +45,12 @@
49
45
  "module": "./index.mjs",
50
46
  "unpkg": "./index.iife.min.js",
51
47
  "jsdelivr": "./index.iife.min.js",
52
- "types": "./index.d.ts",
48
+ "types": "./index.d.cts",
53
49
  "peerDependencies": {
54
50
  "firebase": ">=9.0.0"
55
51
  },
56
52
  "dependencies": {
57
- "@vueuse/shared": "10.2.1",
53
+ "@vueuse/shared": "10.4.0",
58
54
  "vue-demi": ">=0.14.5"
59
55
  }
60
56
  }
package/useAuth.d.cts ADDED
@@ -0,0 +1,47 @@
1
+ import * as _firebase_auth from '@firebase/auth';
2
+ import { ComputedRef, Ref } from 'vue-demi';
3
+ import { User, Auth } from 'firebase/auth';
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
+ declare function useAuth(auth: Auth): {
15
+ isAuthenticated: ComputedRef<boolean>;
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;
33
+ delete: () => Promise<void>;
34
+ getIdToken: (forceRefresh?: boolean | undefined) => Promise<string>;
35
+ getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<_firebase_auth.IdTokenResult>;
36
+ reload: () => Promise<void>;
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;
44
+ } | null>;
45
+ };
46
+
47
+ export { type UseFirebaseAuthOptions, useAuth };
package/useAuth.d.mts ADDED
@@ -0,0 +1,47 @@
1
+ import * as _firebase_auth from '@firebase/auth';
2
+ import { ComputedRef, Ref } from 'vue-demi';
3
+ import { User, Auth } from 'firebase/auth';
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
+ declare function useAuth(auth: Auth): {
15
+ isAuthenticated: ComputedRef<boolean>;
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;
33
+ delete: () => Promise<void>;
34
+ getIdToken: (forceRefresh?: boolean | undefined) => Promise<string>;
35
+ getIdTokenResult: (forceRefresh?: boolean | undefined) => Promise<_firebase_auth.IdTokenResult>;
36
+ reload: () => Promise<void>;
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;
44
+ } | null>;
45
+ };
46
+
47
+ export { type UseFirebaseAuthOptions, useAuth };
package/useAuth.d.ts CHANGED
@@ -44,4 +44,4 @@ declare function useAuth(auth: Auth): {
44
44
  } | null>;
45
45
  };
46
46
 
47
- export { UseFirebaseAuthOptions, useAuth };
47
+ export { type UseFirebaseAuthOptions, useAuth };
package/useFirestore.cjs CHANGED
@@ -15,8 +15,7 @@ function getData(docRef) {
15
15
  return data;
16
16
  }
17
17
  function isDocumentReference(docRef) {
18
- var _a;
19
- return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
18
+ return (docRef.path?.match(/\//g) || []).length % 2 !== 0;
20
19
  }
21
20
  function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
22
21
  const {
@@ -0,0 +1,16 @@
1
+ import { Ref } from 'vue-demi';
2
+ import { Query, DocumentReference, DocumentData } from 'firebase/firestore';
3
+ import { MaybeRef } from '@vueuse/shared';
4
+
5
+ interface UseFirestoreOptions {
6
+ errorHandler?: (err: Error) => void;
7
+ autoDispose?: boolean | number;
8
+ }
9
+ type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
10
+ type Falsy = false | 0 | '' | null | undefined;
11
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
12
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
13
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
14
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
15
+
16
+ export { type FirebaseDocRef, type UseFirestoreOptions, useFirestore };
@@ -0,0 +1,16 @@
1
+ import { Ref } from 'vue-demi';
2
+ import { Query, DocumentReference, DocumentData } from 'firebase/firestore';
3
+ import { MaybeRef } from '@vueuse/shared';
4
+
5
+ interface UseFirestoreOptions {
6
+ errorHandler?: (err: Error) => void;
7
+ autoDispose?: boolean | number;
8
+ }
9
+ type FirebaseDocRef<T> = Query<T> | DocumentReference<T>;
10
+ type Falsy = false | 0 | '' | null | undefined;
11
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue: T, options?: UseFirestoreOptions): Ref<T | null>;
12
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue: T[], options?: UseFirestoreOptions): Ref<T[]>;
13
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
14
+ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
15
+
16
+ export { type FirebaseDocRef, type UseFirestoreOptions, useFirestore };
package/useFirestore.d.ts CHANGED
@@ -13,4 +13,4 @@ declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Quer
13
13
  declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<DocumentReference<T> | Falsy>, initialValue?: T | undefined | null, options?: UseFirestoreOptions): Ref<T | undefined | null>;
14
14
  declare function useFirestore<T extends DocumentData>(maybeDocRef: MaybeRef<Query<T> | Falsy>, initialValue?: T[], options?: UseFirestoreOptions): Ref<T[] | undefined>;
15
15
 
16
- export { FirebaseDocRef, UseFirestoreOptions, useFirestore };
16
+ export { type FirebaseDocRef, type UseFirestoreOptions, useFirestore };
@@ -128,8 +128,7 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
128
128
  return data;
129
129
  }
130
130
  function isDocumentReference(docRef) {
131
- var _a;
132
- return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
131
+ return (docRef.path?.match(/\//g) || []).length % 2 !== 0;
133
132
  }
134
133
  function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
135
134
  const {
@@ -1 +1 @@
1
- var VueDemi=function(n,e,a){if(n.install)return n;if(!e)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),n;if(e.version.slice(0,4)==="2.7."){let o=function(s,t){var r,d={},l={config:e.config,use:e.use.bind(e),mixin:e.mixin.bind(e),component:e.component.bind(e),provide:function(f,c){return d[f]=c,this},directive:function(f,c){return c?(e.directive(f,c),l):e.directive(f)},mount:function(f,c){return r||(r=new e(Object.assign({propsData:t},s,{provide:Object.assign(d,s.provide)})),r.$mount(f,c),r)},unmount:function(){r&&(r.$destroy(),r=void 0)}};return l};var h=o;for(var i in e)n[i]=e[i];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version,n.warn=e.util.warn,n.hasInjectionContext=()=>!!n.getCurrentInstance(),n.createApp=o}else if(e.version.slice(0,2)==="2.")if(a){for(var i in a)n[i]=a[i];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version,n.hasInjectionContext=()=>!!n.getCurrentInstance()}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 i in e)n[i]=e[i];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=e,n.Vue2=void 0,n.version=e.version,n.set=function(o,s,t){return Array.isArray(o)?(o.length=Math.max(o.length,s),o.splice(s,1,t),t):(o[s]=t,t)},n.del=function(o,s){if(Array.isArray(o)){o.splice(s,1);return}delete o[s]}}else console.error("[vue-demi] Vue version "+e.version+" is unsupported.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi<"u"?VueDemi:{}),this.Vue||(typeof Vue<"u"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI<"u"?VueCompositionAPI:void 0));(function(n,e,a,i){"use strict";function h(t){const r=t.data();return r&&Object.defineProperty(r,"id",{value:t.id.toString(),writable:!1}),r}function o(t){var r;return(((r=t.path)==null?void 0:r.match(/\//g))||[]).length%2!==0}function s(t,r=void 0,d={}){const{errorHandler:l=v=>console.error(v),autoDispose:f=!0}=d,c=e.isRef(t)?t:e.computed(()=>t);let u=()=>{};const p=e.ref(r);return e.watch(c,v=>{u(),c.value?o(c.value)?u=i.onSnapshot(v,b=>{p.value=h(b)||null},l):u=i.onSnapshot(v,b=>{p.value=b.docs.map(h).filter(a.isDef)},l):p.value=r},{immediate:!0}),f===!0?a.tryOnScopeDispose(()=>{u()}):typeof f=="number"&&a.tryOnScopeDispose(()=>{a.useTimeoutFn(()=>{u()},f)}),p}n.useFirestore=s})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firebase);
1
+ var VueDemi=function(n,e,a){if(n.install)return n;if(!e)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),n;if(e.version.slice(0,4)==="2.7."){let o=function(s,t){var r,d={},l={config:e.config,use:e.use.bind(e),mixin:e.mixin.bind(e),component:e.component.bind(e),provide:function(f,c){return d[f]=c,this},directive:function(f,c){return c?(e.directive(f,c),l):e.directive(f)},mount:function(f,c){return r||(r=new e(Object.assign({propsData:t},s,{provide:Object.assign(d,s.provide)})),r.$mount(f,c),r)},unmount:function(){r&&(r.$destroy(),r=void 0)}};return l};var h=o;for(var i in e)n[i]=e[i];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version,n.warn=e.util.warn,n.hasInjectionContext=()=>!!n.getCurrentInstance(),n.createApp=o}else if(e.version.slice(0,2)==="2.")if(a){for(var i in a)n[i]=a[i];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=e,n.Vue2=e,n.version=e.version,n.hasInjectionContext=()=>!!n.getCurrentInstance()}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 i in e)n[i]=e[i];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=e,n.Vue2=void 0,n.version=e.version,n.set=function(o,s,t){return Array.isArray(o)?(o.length=Math.max(o.length,s),o.splice(s,1,t),t):(o[s]=t,t)},n.del=function(o,s){if(Array.isArray(o)){o.splice(s,1);return}delete o[s]}}else console.error("[vue-demi] Vue version "+e.version+" is unsupported.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi<"u"?VueDemi:{}),this.Vue||(typeof Vue<"u"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI<"u"?VueCompositionAPI:void 0));(function(n,e,a,i){"use strict";function h(t){const r=t.data();return r&&Object.defineProperty(r,"id",{value:t.id.toString(),writable:!1}),r}function o(t){return(t.path?.match(/\//g)||[]).length%2!==0}function s(t,r=void 0,d={}){const{errorHandler:l=v=>console.error(v),autoDispose:f=!0}=d,c=e.isRef(t)?t:e.computed(()=>t);let u=()=>{};const p=e.ref(r);return e.watch(c,v=>{u(),c.value?o(c.value)?u=i.onSnapshot(v,b=>{p.value=h(b)||null},l):u=i.onSnapshot(v,b=>{p.value=b.docs.map(h).filter(a.isDef)},l):p.value=r},{immediate:!0}),f===!0?a.tryOnScopeDispose(()=>{u()}):typeof f=="number"&&a.tryOnScopeDispose(()=>{a.useTimeoutFn(()=>{u()},f)}),p}n.useFirestore=s})(this.VueUse=this.VueUse||{},VueDemi,VueUse,firebase);
package/useFirestore.mjs CHANGED
@@ -13,8 +13,7 @@ function getData(docRef) {
13
13
  return data;
14
14
  }
15
15
  function isDocumentReference(docRef) {
16
- var _a;
17
- return (((_a = docRef.path) == null ? void 0 : _a.match(/\//g)) || []).length % 2 !== 0;
16
+ return (docRef.path?.match(/\//g) || []).length % 2 !== 0;
18
17
  }
19
18
  function useFirestore(maybeDocRef, initialValue = void 0, options = {}) {
20
19
  const {
package/useRTDB.cjs CHANGED
@@ -6,13 +6,14 @@ var shared = require('@vueuse/shared');
6
6
 
7
7
  function useRTDB(docRef, options = {}) {
8
8
  const {
9
+ errorHandler = (err) => console.error(err),
9
10
  autoDispose = true
10
11
  } = options;
11
12
  const data = vueDemi.ref(void 0);
12
13
  function update(snapshot) {
13
14
  data.value = snapshot.val();
14
15
  }
15
- const off = database.onValue(docRef, update);
16
+ const off = database.onValue(docRef, update, errorHandler);
16
17
  if (autoDispose)
17
18
  shared.tryOnScopeDispose(() => off());
18
19
  return data;
package/useRTDB.d.cts ADDED
@@ -0,0 +1,15 @@
1
+ import { DatabaseReference } from 'firebase/database';
2
+ import { Ref } from 'vue-demi';
3
+
4
+ interface UseRTDBOptions {
5
+ errorHandler?: (err: Error) => void;
6
+ autoDispose?: boolean;
7
+ }
8
+ /**
9
+ * Reactive Firebase Realtime Database binding.
10
+ *
11
+ * @see https://vueuse.org/useRTDB
12
+ */
13
+ declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
14
+
15
+ export { type UseRTDBOptions, useRTDB };
package/useRTDB.d.mts ADDED
@@ -0,0 +1,15 @@
1
+ import { DatabaseReference } from 'firebase/database';
2
+ import { Ref } from 'vue-demi';
3
+
4
+ interface UseRTDBOptions {
5
+ errorHandler?: (err: Error) => void;
6
+ autoDispose?: boolean;
7
+ }
8
+ /**
9
+ * Reactive Firebase Realtime Database binding.
10
+ *
11
+ * @see https://vueuse.org/useRTDB
12
+ */
13
+ declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
14
+
15
+ export { type UseRTDBOptions, useRTDB };
package/useRTDB.d.ts CHANGED
@@ -2,6 +2,7 @@ import { DatabaseReference } from 'firebase/database';
2
2
  import { Ref } from 'vue-demi';
3
3
 
4
4
  interface UseRTDBOptions {
5
+ errorHandler?: (err: Error) => void;
5
6
  autoDispose?: boolean;
6
7
  }
7
8
  /**
@@ -11,4 +12,4 @@ interface UseRTDBOptions {
11
12
  */
12
13
  declare function useRTDB<T = any>(docRef: DatabaseReference, options?: UseRTDBOptions): Ref<T | undefined>;
13
14
 
14
- export { UseRTDBOptions, useRTDB };
15
+ export { type UseRTDBOptions, useRTDB };
package/useRTDB.iife.js CHANGED
@@ -119,13 +119,14 @@ var VueDemi = (function (VueDemi, Vue, VueCompositionAPI) {
119
119
 
120
120
  function useRTDB(docRef, options = {}) {
121
121
  const {
122
+ errorHandler = (err) => console.error(err),
122
123
  autoDispose = true
123
124
  } = options;
124
125
  const data = vueDemi.ref(void 0);
125
126
  function update(snapshot) {
126
127
  data.value = snapshot.val();
127
128
  }
128
- const off = database.onValue(docRef, update);
129
+ const off = database.onValue(docRef, update, errorHandler);
129
130
  if (autoDispose)
130
131
  shared.tryOnScopeDispose(() => off());
131
132
  return data;
@@ -1 +1 @@
1
- var VueDemi=function(n,i,d){if(n.install)return n;if(!i)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),n;if(i.version.slice(0,4)==="2.7."){let r=function(s,e){var o,a={},u={config:i.config,use:i.use.bind(i),mixin:i.mixin.bind(i),component:i.component.bind(i),provide:function(f,c){return a[f]=c,this},directive:function(f,c){return c?(i.directive(f,c),u):i.directive(f)},mount:function(f,c){return o||(o=new i(Object.assign({propsData:e},s,{provide:Object.assign(a,s.provide)})),o.$mount(f,c),o)},unmount:function(){o&&(o.$destroy(),o=void 0)}};return u};var v=r;for(var t in i)n[t]=i[t];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=i,n.Vue2=i,n.version=i.version,n.warn=i.util.warn,n.hasInjectionContext=()=>!!n.getCurrentInstance(),n.createApp=r}else if(i.version.slice(0,2)==="2.")if(d){for(var t in d)n[t]=d[t];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=i,n.Vue2=i,n.version=i.version,n.hasInjectionContext=()=>!!n.getCurrentInstance()}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(i.version.slice(0,2)==="3."){for(var t in i)n[t]=i[t];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=i,n.Vue2=void 0,n.version=i.version,n.set=function(r,s,e){return Array.isArray(r)?(r.length=Math.max(r.length,s),r.splice(s,1,e),e):(r[s]=e,e)},n.del=function(r,s){if(Array.isArray(r)){r.splice(s,1);return}delete r[s]}}else console.error("[vue-demi] Vue version "+i.version+" is unsupported.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi<"u"?VueDemi:{}),this.Vue||(typeof Vue<"u"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI<"u"?VueCompositionAPI:void 0));(function(n,i,d,t){"use strict";function v(r,s={}){const{autoDispose:e=!0}=s,o=d.ref(void 0);function a(f){o.value=f.val()}const u=i.onValue(r,a);return e&&t.tryOnScopeDispose(()=>u()),o}n.useRTDB=v})(this.VueUse=this.VueUse||{},firebase,VueDemi,VueUse);
1
+ var VueDemi=function(n,r,d){if(n.install)return n;if(!r)return console.error("[vue-demi] no Vue instance found, please be sure to import `vue` before `vue-demi`."),n;if(r.version.slice(0,4)==="2.7."){let o=function(i,f){var e,a={},l={config:r.config,use:r.use.bind(r),mixin:r.mixin.bind(r),component:r.component.bind(r),provide:function(c,t){return a[c]=t,this},directive:function(c,t){return t?(r.directive(c,t),l):r.directive(c)},mount:function(c,t){return e||(e=new r(Object.assign({propsData:f},i,{provide:Object.assign(a,i.provide)})),e.$mount(c,t),e)},unmount:function(){e&&(e.$destroy(),e=void 0)}};return l};var u=o;for(var s in r)n[s]=r[s];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=r,n.Vue2=r,n.version=r.version,n.warn=r.util.warn,n.hasInjectionContext=()=>!!n.getCurrentInstance(),n.createApp=o}else if(r.version.slice(0,2)==="2.")if(d){for(var s in d)n[s]=d[s];n.isVue2=!0,n.isVue3=!1,n.install=function(){},n.Vue=r,n.Vue2=r,n.version=r.version,n.hasInjectionContext=()=>!!n.getCurrentInstance()}else console.error("[vue-demi] no VueCompositionAPI instance found, please be sure to import `@vue/composition-api` before `vue-demi`.");else if(r.version.slice(0,2)==="3."){for(var s in r)n[s]=r[s];n.isVue2=!1,n.isVue3=!0,n.install=function(){},n.Vue=r,n.Vue2=void 0,n.version=r.version,n.set=function(o,i,f){return Array.isArray(o)?(o.length=Math.max(o.length,i),o.splice(i,1,f),f):(o[i]=f,f)},n.del=function(o,i){if(Array.isArray(o)){o.splice(i,1);return}delete o[i]}}else console.error("[vue-demi] Vue version "+r.version+" is unsupported.");return n}(this.VueDemi=this.VueDemi||(typeof VueDemi<"u"?VueDemi:{}),this.Vue||(typeof Vue<"u"?Vue:void 0),this.VueCompositionAPI||(typeof VueCompositionAPI<"u"?VueCompositionAPI:void 0));(function(n,r,d,s){"use strict";function u(o,i={}){const{errorHandler:f=t=>console.error(t),autoDispose:e=!0}=i,a=d.ref(void 0);function l(t){a.value=t.val()}const c=r.onValue(o,l,f);return e&&s.tryOnScopeDispose(()=>c()),a}n.useRTDB=u})(this.VueUse=this.VueUse||{},firebase,VueDemi,VueUse);
package/useRTDB.mjs CHANGED
@@ -4,13 +4,14 @@ import { tryOnScopeDispose } from '@vueuse/shared';
4
4
 
5
5
  function useRTDB(docRef, options = {}) {
6
6
  const {
7
+ errorHandler = (err) => console.error(err),
7
8
  autoDispose = true
8
9
  } = options;
9
10
  const data = ref(void 0);
10
11
  function update(snapshot) {
11
12
  data.value = snapshot.val();
12
13
  }
13
- const off = onValue(docRef, update);
14
+ const off = onValue(docRef, update, errorHandler);
14
15
  if (autoDispose)
15
16
  tryOnScopeDispose(() => off());
16
17
  return data;