sveltedfire 0.0.5 → 0.0.7

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,7 @@ 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 { listenDocs } from './sveltedfire/utilities/listenDocs.js';
7
8
  export { kindlyFetchDoc } from './sveltedfire/utilities/kindlyFetchDoc.js';
8
9
  export { kindlyFetchDocs } from './sveltedfire/utilities/kindlyFetchDocs.js';
9
10
  import SignedIn from './sveltedfire/components/SignedIn.svelte';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ 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 { listenDocs } from './sveltedfire/utilities/listenDocs.js';
8
9
  export { kindlyFetchDoc } from './sveltedfire/utilities/kindlyFetchDoc.js';
9
10
  export { kindlyFetchDocs } from './sveltedfire/utilities/kindlyFetchDocs.js';
10
11
  import SignedIn from './sveltedfire/components/SignedIn.svelte';
@@ -0,0 +1,3 @@
1
+ import { QueryCompositeFilterConstraint } from "firebase/firestore";
2
+ import { type DocumentData } from "firebase/firestore";
3
+ export declare const listenDocs: (...collectionPath: Array<string>) => (qOrField?: QueryCompositeFilterConstraint | string | null, comparator?: string | null, value?: string | boolean | number | null) => Promise<import("svelte/store").Readable<DocumentData | null>>;
@@ -0,0 +1,40 @@
1
+ import { getFirestore, collection, doc, getDocs, Query, QueryFieldFilterConstraint, where, query, QueryCompositeFilterConstraint } from "firebase/firestore";
2
+ import { onSnapshot } from "firebase/firestore";
3
+ import { readable } from 'svelte/store';
4
+ export const listenDocs = (...collectionPath) => async (qOrField = null, comparator = null, value = null) => {
5
+ const db = getFirestore();
6
+ let theRef;
7
+ if (collectionPath.length > 1) {
8
+ theRef = collection(db, collectionPath[0], ...collectionPath.slice(1));
9
+ }
10
+ else {
11
+ theRef = collection(db, collectionPath[0]);
12
+ }
13
+ let theQuery = query(theRef);
14
+ if (qOrField) {
15
+ if (comparator) {
16
+ theQuery = query(theRef, where(qOrField, comparator, value));
17
+ }
18
+ else {
19
+ if (qOrField instanceof QueryFieldFilterConstraint) {
20
+ theQuery = query(theRef, qOrField);
21
+ }
22
+ else if (qOrField instanceof QueryCompositeFilterConstraint) {
23
+ theQuery = query(theRef, qOrField);
24
+ }
25
+ }
26
+ }
27
+ const theDocs = readable(null, (set) => {
28
+ const unsubscribe = onSnapshot(theQuery, (vals) => {
29
+ let combined = [];
30
+ vals.forEach(val => {
31
+ if (val.exists()) {
32
+ combined.push({ id: val.id, ...val.data(), _id: val.id });
33
+ }
34
+ });
35
+ set(combined);
36
+ });
37
+ return () => unsubscribe();
38
+ });
39
+ return theDocs;
40
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveltedfire",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run prepack",