sveltedfire 0.0.4 → 0.0.5

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 CHANGED
@@ -4,6 +4,8 @@ export { fetchDocs } from './sveltedfire/utilities/fetchDocs.js';
4
4
  export { signInWithGoogle } from './sveltedfire/auth/signInWithGoogle.js';
5
5
  export { signOut } from './sveltedfire/auth/signOut.js';
6
6
  export { listenDoc } from './sveltedfire/utilities/listenDoc.js';
7
+ export { kindlyFetchDoc } from './sveltedfire/utilities/kindlyFetchDoc.js';
8
+ export { kindlyFetchDocs } from './sveltedfire/utilities/kindlyFetchDocs.js';
7
9
  import SignedIn from './sveltedfire/components/SignedIn.svelte';
8
10
  import SignedOut from './sveltedfire/components/SignedOut.svelte';
9
11
  export { SignedIn, SignedOut };
package/dist/index.js CHANGED
@@ -5,6 +5,8 @@ export { fetchDocs } from './sveltedfire/utilities/fetchDocs.js';
5
5
  export { signInWithGoogle } from './sveltedfire/auth/signInWithGoogle.js';
6
6
  export { signOut } from './sveltedfire/auth/signOut.js';
7
7
  export { listenDoc } from './sveltedfire/utilities/listenDoc.js';
8
+ export { kindlyFetchDoc } from './sveltedfire/utilities/kindlyFetchDoc.js';
9
+ export { kindlyFetchDocs } from './sveltedfire/utilities/kindlyFetchDocs.js';
8
10
  import SignedIn from './sveltedfire/components/SignedIn.svelte';
9
11
  import SignedOut from './sveltedfire/components/SignedOut.svelte';
10
12
  export { SignedIn, SignedOut };
@@ -5,7 +5,6 @@
5
5
  const auth = getAuth()
6
6
  let user = $state(null)
7
7
  auth.onAuthStateChanged(u => {
8
- console.log('User is', u)
9
8
  user = u
10
9
  })
11
10
  </script>
@@ -5,7 +5,6 @@
5
5
  const auth = getAuth()
6
6
  let user = $state(null)
7
7
  auth.onAuthStateChanged(u => {
8
- console.log('User is', u)
9
8
  user = u
10
9
  })
11
10
  </script>
@@ -1,7 +1,14 @@
1
1
  import { initializeApp } from "firebase/app";
2
+ import { getAuth } from 'firebase/auth';
3
+ import { setLogLevel } from "firebase/firestore";
2
4
  export const initFirebase = async (firebaseConfig) => {
3
5
  await new Promise((res, rej) => {
4
- initializeApp(firebaseConfig);
5
- res(null);
6
+ // setLogLevel('debug')
7
+ const app = initializeApp(firebaseConfig);
8
+ const auth = getAuth(app);
9
+ const unsubscribe = auth.onAuthStateChanged(_ => {
10
+ unsubscribe();
11
+ res(null);
12
+ });
6
13
  });
7
14
  };
@@ -1,7 +1,6 @@
1
1
  import { getAuth } from "firebase/auth";
2
2
  import { getFirestore, collection, doc, getDoc } from "firebase/firestore";
3
3
  export const fetchDoc = async (...docPath) => {
4
- const auth = getAuth(); // Initialize auth so that requests are authenticated
5
4
  const db = getFirestore();
6
5
  let theRef;
7
6
  if (docPath.length > 2) {
@@ -1,7 +1,5 @@
1
- import { getAuth } from "firebase/auth";
2
1
  import { getFirestore, collection, doc, getDocs, Query, QueryFieldFilterConstraint, where, query, QueryCompositeFilterConstraint } from "firebase/firestore";
3
2
  export const fetchDocs = (...collectionPath) => async (qOrField = null, comparator = null, value = null) => {
4
- const auth = getAuth(); // Initialize auth so that requests are authenticated
5
3
  const db = getFirestore();
6
4
  let theRef;
7
5
  if (collectionPath.length > 1) {
@@ -0,0 +1,4 @@
1
+ export declare const kindlyFetchDoc: (...args: any[]) => Promise<{
2
+ _id: string;
3
+ id: string;
4
+ } | null>;
@@ -0,0 +1,12 @@
1
+ import { FirebaseError } from "firebase/app";
2
+ import { fetchDoc } from "./fetchDoc.js";
3
+ export const kindlyFetchDoc = async (...args) => {
4
+ return await fetchDoc(...args).then(result => {
5
+ return result;
6
+ }).catch(err => {
7
+ if ((err instanceof FirebaseError) && (err.code == 'permission-denied')) {
8
+ return null;
9
+ }
10
+ throw err;
11
+ });
12
+ };
@@ -0,0 +1,10 @@
1
+ export declare const kindlyFetchDocs: (...initialArgs: any[]) => (...args: any[]) => Promise<{
2
+ docs: {
3
+ _id: string;
4
+ id: string;
5
+ }[];
6
+ count: number;
7
+ } | {
8
+ docs: never[];
9
+ count: number;
10
+ }>;
@@ -0,0 +1,12 @@
1
+ import { FirebaseError } from "firebase/app";
2
+ import { fetchDocs } from "./fetchDocs.js";
3
+ export const kindlyFetchDocs = (...initialArgs) => async (...args) => {
4
+ return await fetchDocs(...initialArgs)(...args).then(result => {
5
+ return result;
6
+ }).catch(err => {
7
+ if ((err instanceof FirebaseError) && (err.code == 'permission-denied')) {
8
+ return { docs: [], count: 0 };
9
+ }
10
+ throw err;
11
+ });
12
+ };
@@ -1,8 +1,6 @@
1
- import { getAuth } from "firebase/auth";
2
1
  import { getFirestore, collection, doc, onSnapshot } from "firebase/firestore";
3
2
  import { readable } from 'svelte/store';
4
3
  export const listenDoc = (...docPath) => {
5
- const auth = getAuth(); // Initialize auth so that requests are authenticated
6
4
  const db = getFirestore();
7
5
  let theRef;
8
6
  if (docPath.length > 2) {
@@ -11,7 +9,6 @@ export const listenDoc = (...docPath) => {
11
9
  else {
12
10
  theRef = doc(collection(db, docPath[0]), docPath.slice(-1)[0]);
13
11
  }
14
- console.log(theRef);
15
12
  const theDoc = readable(null, (set) => {
16
13
  const unsubscribe = onSnapshot(theRef, (val) => {
17
14
  if (!val.exists()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveltedfire",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",