svelte-firekit 0.0.22 → 0.0.23

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 CHANGED
@@ -1,11 +1,3 @@
1
- ---
2
- slug: docs
3
- title: Welcome to Svelte Firekit
4
- description: a comprehensive library integrating SvelteKit and Firebase for building robust micro SaaS applications.
5
- ---
6
-
7
- ## Introduction to Svelte Firekit
8
-
9
1
  Svelte Firekit is a powerful Firebase toolkit for SvelteKit applications, providing a comprehensive set of utilities, stores, and components for seamless Firebase integration. Whether you're building a micro SaaS, web application, or any Firebase-powered project, Svelte Firekit streamlines your development process.
10
2
 
11
3
  ## Installation
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @module FirekitCollectionGroup
3
+ */
4
+ import { type Query, type DocumentData, type QueryConstraint } from "firebase/firestore";
5
+ /**
6
+ * Manages real-time Firestore collection group subscriptions with reactive state
7
+ * @class
8
+ * @template T Collection document type
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * interface Task {
13
+ * id: string;
14
+ * title: string;
15
+ * status: string;
16
+ * }
17
+ *
18
+ * // Create collection group subscription
19
+ * const allTasks = firekitCollectionGroup<Task>('tasks',
20
+ * where('status', '==', 'active'),
21
+ * orderBy('title')
22
+ * );
23
+ * ```
24
+ */
25
+ declare class FirekitCollectionGroup<T> {
26
+ /** Current collection group data */
27
+ private _data;
28
+ /** Loading state */
29
+ private _loading;
30
+ /** Error state */
31
+ private _error;
32
+ /** Query reference */
33
+ private queryRef;
34
+ /**
35
+ * Creates a collection group subscription
36
+ * @param {string} collectionId Collection ID to query across all documents
37
+ * @param {...QueryConstraint[]} queryConstraints Query constraints (where, orderBy, limit, etc.)
38
+ */
39
+ constructor(collectionId: string, ...queryConstraints: QueryConstraint[]);
40
+ /** Gets current collection group data */
41
+ get data(): T[];
42
+ /** Gets loading state */
43
+ get loading(): boolean;
44
+ /** Gets error state */
45
+ get error(): Error | null;
46
+ /** Checks if collection group is empty */
47
+ get empty(): boolean;
48
+ /** Gets number of documents in collection group */
49
+ get size(): number;
50
+ /**
51
+ * Gets query reference
52
+ * @throws {Error} If query reference is not available
53
+ */
54
+ get ref(): Query<T>;
55
+ }
56
+ /**
57
+ * Creates a collection group subscription
58
+ * @template T Collection document type
59
+ * @param {string} collectionId Collection ID to query across all documents
60
+ * @param {...QueryConstraint[]} queryConstraints Query constraints
61
+ * @returns {FirekitCollectionGroup<T>} Collection group subscription instance
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * interface Comment {
66
+ * id: string;
67
+ * text: string;
68
+ * userId: string;
69
+ * }
70
+ *
71
+ * const allComments = firekitCollectionGroup<Comment>('comments',
72
+ * where('userId', '==', currentUserId),
73
+ * orderBy('createdAt', 'desc')
74
+ * );
75
+ * ```
76
+ */
77
+ export declare function firekitCollectionGroup<T extends DocumentData>(collectionId: string, ...queryConstraints: QueryConstraint[]): FirekitCollectionGroup<T>;
78
+ export {};
@@ -0,0 +1,120 @@
1
+ /**
2
+ * @module FirekitCollectionGroup
3
+ */
4
+ import { collectionGroup, query, onSnapshot } from "firebase/firestore";
5
+ import { firebaseService } from "../firebase.js";
6
+ import { browser } from "$app/environment";
7
+ /**
8
+ * Manages real-time Firestore collection group subscriptions with reactive state
9
+ * @class
10
+ * @template T Collection document type
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * interface Task {
15
+ * id: string;
16
+ * title: string;
17
+ * status: string;
18
+ * }
19
+ *
20
+ * // Create collection group subscription
21
+ * const allTasks = firekitCollectionGroup<Task>('tasks',
22
+ * where('status', '==', 'active'),
23
+ * orderBy('title')
24
+ * );
25
+ * ```
26
+ */
27
+ class FirekitCollectionGroup {
28
+ /** Current collection group data */
29
+ _data = $state([]);
30
+ /** Loading state */
31
+ _loading = $state(true);
32
+ /** Error state */
33
+ _error = $state(null);
34
+ /** Query reference */
35
+ queryRef = null;
36
+ /**
37
+ * Creates a collection group subscription
38
+ * @param {string} collectionId Collection ID to query across all documents
39
+ * @param {...QueryConstraint[]} queryConstraints Query constraints (where, orderBy, limit, etc.)
40
+ */
41
+ constructor(collectionId, ...queryConstraints) {
42
+ if (browser) {
43
+ try {
44
+ const firestore = firebaseService.getDbInstance();
45
+ const groupRef = collectionGroup(firestore, collectionId);
46
+ this.queryRef = query(groupRef, ...queryConstraints);
47
+ onSnapshot(this.queryRef, (snapshot) => {
48
+ this._data = snapshot.docs.map(doc => ({
49
+ id: doc.id,
50
+ path: doc.ref.path,
51
+ ...doc.data()
52
+ }));
53
+ this._loading = false;
54
+ this._error = null;
55
+ }, (error) => {
56
+ this._error = error;
57
+ this._loading = false;
58
+ });
59
+ }
60
+ catch (error) {
61
+ this._error = error;
62
+ this._loading = false;
63
+ }
64
+ }
65
+ }
66
+ /** Gets current collection group data */
67
+ get data() {
68
+ return this._data;
69
+ }
70
+ /** Gets loading state */
71
+ get loading() {
72
+ return this._loading;
73
+ }
74
+ /** Gets error state */
75
+ get error() {
76
+ return this._error;
77
+ }
78
+ /** Checks if collection group is empty */
79
+ get empty() {
80
+ return this._data.length === 0;
81
+ }
82
+ /** Gets number of documents in collection group */
83
+ get size() {
84
+ return this._data.length;
85
+ }
86
+ /**
87
+ * Gets query reference
88
+ * @throws {Error} If query reference is not available
89
+ */
90
+ get ref() {
91
+ if (!this.queryRef) {
92
+ throw new Error("Query reference is not available");
93
+ }
94
+ return this.queryRef;
95
+ }
96
+ }
97
+ /**
98
+ * Creates a collection group subscription
99
+ * @template T Collection document type
100
+ * @param {string} collectionId Collection ID to query across all documents
101
+ * @param {...QueryConstraint[]} queryConstraints Query constraints
102
+ * @returns {FirekitCollectionGroup<T>} Collection group subscription instance
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * interface Comment {
107
+ * id: string;
108
+ * text: string;
109
+ * userId: string;
110
+ * }
111
+ *
112
+ * const allComments = firekitCollectionGroup<Comment>('comments',
113
+ * where('userId', '==', currentUserId),
114
+ * orderBy('createdAt', 'desc')
115
+ * );
116
+ * ```
117
+ */
118
+ export function firekitCollectionGroup(collectionId, ...queryConstraints) {
119
+ return new FirekitCollectionGroup(collectionId, ...queryConstraints);
120
+ }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { firekitAwaitableDoc } from './firestore/awaitable-doc.svelte.js';
7
7
  export { firekitDocMutations } from './firestore/document-mutations.svelte.js';
8
8
  export { firekitCollection } from './firestore/collection.svelte.js';
9
9
  export { firekitDoc } from './firestore/doc.svelte.js';
10
+ export { firekitCollectionGroup } from './firestore/collection-group.svelte.js';
10
11
  export { firekitRealtimeDB } from './realtime/realtime.svelte.js';
11
12
  export { firekitDownloadUrl } from './storage/download-url.svelte.js';
12
13
  export { firekitStorageList } from './storage/storage-list.svelte.js';
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ export { firekitAwaitableDoc } from './firestore/awaitable-doc.svelte.js';
10
10
  export { firekitDocMutations } from './firestore/document-mutations.svelte.js';
11
11
  export { firekitCollection } from './firestore/collection.svelte.js';
12
12
  export { firekitDoc } from './firestore/doc.svelte.js';
13
+ export { firekitCollectionGroup } from './firestore/collection-group.svelte.js';
13
14
  // realtime services
14
15
  export { firekitRealtimeDB } from './realtime/realtime.svelte.js';
15
16
  // Storage services
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-firekit",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev",