svelte-firekit 0.0.25 → 0.1.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/README.md +445 -213
- package/dist/components/Collection.svelte +150 -0
- package/dist/components/Collection.svelte.d.ts +27 -0
- package/dist/components/Ddoc.svelte +131 -0
- package/dist/components/Ddoc.svelte.d.ts +28 -0
- package/dist/components/Node.svelte +97 -0
- package/dist/components/Node.svelte.d.ts +23 -0
- package/dist/components/auth-guard.svelte +89 -0
- package/dist/components/auth-guard.svelte.d.ts +26 -0
- package/dist/components/custom-guard.svelte +122 -0
- package/dist/components/custom-guard.svelte.d.ts +31 -0
- package/dist/components/download-url.svelte +92 -0
- package/dist/components/download-url.svelte.d.ts +19 -0
- package/dist/components/firebase-app.svelte +30 -0
- package/dist/components/firebase-app.svelte.d.ts +7 -0
- package/dist/components/node-list.svelte +102 -0
- package/dist/components/node-list.svelte.d.ts +27 -0
- package/dist/components/signed-in.svelte +42 -0
- package/dist/components/signed-in.svelte.d.ts +11 -0
- package/dist/components/signed-out.svelte +42 -0
- package/dist/components/signed-out.svelte.d.ts +11 -0
- package/dist/components/storage-list.svelte +97 -0
- package/dist/components/storage-list.svelte.d.ts +26 -0
- package/dist/components/upload-task.svelte +108 -0
- package/dist/components/upload-task.svelte.d.ts +24 -0
- package/dist/config.js +17 -39
- package/dist/firebase.d.ts +43 -21
- package/dist/firebase.js +121 -35
- package/dist/index.d.ts +21 -13
- package/dist/index.js +27 -15
- package/dist/services/auth.d.ts +397 -0
- package/dist/services/auth.js +882 -0
- package/dist/services/collection.svelte.d.ts +286 -0
- package/dist/services/collection.svelte.js +871 -0
- package/dist/services/document.svelte.d.ts +288 -0
- package/dist/services/document.svelte.js +555 -0
- package/dist/services/mutations.d.ts +336 -0
- package/dist/services/mutations.js +1079 -0
- package/dist/services/presence.svelte.d.ts +141 -0
- package/dist/services/presence.svelte.js +727 -0
- package/dist/{realtime → services}/realtime.svelte.d.ts +3 -1
- package/dist/{realtime → services}/realtime.svelte.js +13 -7
- package/dist/services/storage.svelte.d.ts +257 -0
- package/dist/services/storage.svelte.js +374 -0
- package/dist/services/user.svelte.d.ts +296 -0
- package/dist/services/user.svelte.js +609 -0
- package/dist/types/auth.d.ts +158 -0
- package/dist/types/auth.js +106 -0
- package/dist/types/collection.d.ts +360 -0
- package/dist/types/collection.js +167 -0
- package/dist/types/document.d.ts +342 -0
- package/dist/types/document.js +148 -0
- package/dist/types/firebase.d.ts +44 -0
- package/dist/types/firebase.js +33 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.js +4 -0
- package/dist/types/mutations.d.ts +387 -0
- package/dist/types/mutations.js +205 -0
- package/dist/types/presence.d.ts +282 -0
- package/dist/types/presence.js +80 -0
- package/dist/utils/errors.d.ts +21 -0
- package/dist/utils/errors.js +35 -0
- package/dist/utils/firestore.d.ts +9 -0
- package/dist/utils/firestore.js +33 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/providers.d.ts +16 -0
- package/dist/utils/providers.js +30 -0
- package/dist/utils/user.d.ts +8 -0
- package/dist/utils/user.js +29 -0
- package/package.json +64 -64
- package/dist/auth/auth.d.ts +0 -117
- package/dist/auth/auth.js +0 -194
- package/dist/auth/presence.svelte.d.ts +0 -139
- package/dist/auth/presence.svelte.js +0 -373
- package/dist/auth/user.svelte.d.ts +0 -112
- package/dist/auth/user.svelte.js +0 -155
- package/dist/firestore/awaitable-doc.svelte.d.ts +0 -141
- package/dist/firestore/awaitable-doc.svelte.js +0 -183
- package/dist/firestore/batch-mutations.svelte.d.ts +0 -140
- package/dist/firestore/batch-mutations.svelte.js +0 -218
- package/dist/firestore/collection-group.svelte.d.ts +0 -78
- package/dist/firestore/collection-group.svelte.js +0 -120
- package/dist/firestore/collection.svelte.d.ts +0 -96
- package/dist/firestore/collection.svelte.js +0 -137
- package/dist/firestore/doc.svelte.d.ts +0 -90
- package/dist/firestore/doc.svelte.js +0 -131
- package/dist/firestore/document-mutations.svelte.d.ts +0 -164
- package/dist/firestore/document-mutations.svelte.js +0 -273
- package/dist/storage/download-url.svelte.d.ts +0 -83
- package/dist/storage/download-url.svelte.js +0 -114
- package/dist/storage/storage-list.svelte.d.ts +0 -89
- package/dist/storage/storage-list.svelte.js +0 -123
- package/dist/storage/upload-task.svelte.d.ts +0 -94
- package/dist/storage/upload-task.svelte.js +0 -138
|
@@ -1,78 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,120 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitCollection
|
|
3
|
-
*/
|
|
4
|
-
import { type CollectionReference, type DocumentData, type QueryConstraint } from "firebase/firestore";
|
|
5
|
-
/**
|
|
6
|
-
* Manages real-time Firestore collection subscriptions with reactive state
|
|
7
|
-
* @class
|
|
8
|
-
* @template T Collection document type
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* interface User {
|
|
13
|
-
* id: string;
|
|
14
|
-
* name: string;
|
|
15
|
-
* email: string;
|
|
16
|
-
* }
|
|
17
|
-
*
|
|
18
|
-
* // Create collection subscription
|
|
19
|
-
* const users = firekitCollection<User>('users',
|
|
20
|
-
* where('active', '==', true),
|
|
21
|
-
* orderBy('name')
|
|
22
|
-
* );
|
|
23
|
-
*
|
|
24
|
-
* // Access reactive state
|
|
25
|
-
* console.log(users.data); // Array of documents
|
|
26
|
-
* console.log(users.loading); // Loading state
|
|
27
|
-
* console.log(users.error); // Error state
|
|
28
|
-
* console.log(users.empty); // Whether collection is empty
|
|
29
|
-
* console.log(users.size); // Number of documents
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
declare class FirekitCollection<T> {
|
|
33
|
-
/** Current collection data */
|
|
34
|
-
private _data;
|
|
35
|
-
/** Loading state */
|
|
36
|
-
private _loading;
|
|
37
|
-
/** Error state */
|
|
38
|
-
private _error;
|
|
39
|
-
/** Collection reference */
|
|
40
|
-
private colRef;
|
|
41
|
-
/** Query reference */
|
|
42
|
-
private queryRef;
|
|
43
|
-
/**
|
|
44
|
-
* Creates a collection subscription
|
|
45
|
-
* @param {string} path Collection path
|
|
46
|
-
* @param {...QueryConstraint[]} queryConstraints Query constraints (where, orderBy, limit, etc.)
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* const collection = new FirekitCollection('users',
|
|
51
|
-
* where('age', '>=', 18),
|
|
52
|
-
* orderBy('name', 'asc'),
|
|
53
|
-
* limit(10)
|
|
54
|
-
* );
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
constructor(path: string, ...queryConstraints: QueryConstraint[]);
|
|
58
|
-
/** Gets current collection data */
|
|
59
|
-
get data(): T[];
|
|
60
|
-
/** Gets loading state */
|
|
61
|
-
get loading(): boolean;
|
|
62
|
-
/** Gets error state */
|
|
63
|
-
get error(): Error | null;
|
|
64
|
-
/** Checks if collection is empty */
|
|
65
|
-
get empty(): boolean;
|
|
66
|
-
/** Gets number of documents in collection */
|
|
67
|
-
get size(): number;
|
|
68
|
-
/**
|
|
69
|
-
* Gets collection reference
|
|
70
|
-
* @throws {Error} If collection reference is not available
|
|
71
|
-
*/
|
|
72
|
-
get ref(): CollectionReference<T>;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Creates a collection subscription
|
|
76
|
-
* @template T Collection document type
|
|
77
|
-
* @param {string} path Collection path
|
|
78
|
-
* @param {...QueryConstraint[]} queryConstraints Query constraints
|
|
79
|
-
* @returns {FirekitCollection<T>} Collection subscription instance
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```typescript
|
|
83
|
-
* interface Post {
|
|
84
|
-
* id: string;
|
|
85
|
-
* title: string;
|
|
86
|
-
* authorId: string;
|
|
87
|
-
* }
|
|
88
|
-
*
|
|
89
|
-
* const posts = firekitCollection<Post>('posts',
|
|
90
|
-
* where('authorId', '==', currentUserId),
|
|
91
|
-
* orderBy('createdAt', 'desc')
|
|
92
|
-
* );
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
export declare function firekitCollection<T extends DocumentData>(path: string, ...queryConstraints: QueryConstraint[]): FirekitCollection<T>;
|
|
96
|
-
export {};
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitCollection
|
|
3
|
-
*/
|
|
4
|
-
import { collection, query, onSnapshot } from "firebase/firestore";
|
|
5
|
-
import { firebaseService } from "../firebase.js";
|
|
6
|
-
import { browser } from "$app/environment";
|
|
7
|
-
/**
|
|
8
|
-
* Manages real-time Firestore collection subscriptions with reactive state
|
|
9
|
-
* @class
|
|
10
|
-
* @template T Collection document type
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* interface User {
|
|
15
|
-
* id: string;
|
|
16
|
-
* name: string;
|
|
17
|
-
* email: string;
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* // Create collection subscription
|
|
21
|
-
* const users = firekitCollection<User>('users',
|
|
22
|
-
* where('active', '==', true),
|
|
23
|
-
* orderBy('name')
|
|
24
|
-
* );
|
|
25
|
-
*
|
|
26
|
-
* // Access reactive state
|
|
27
|
-
* console.log(users.data); // Array of documents
|
|
28
|
-
* console.log(users.loading); // Loading state
|
|
29
|
-
* console.log(users.error); // Error state
|
|
30
|
-
* console.log(users.empty); // Whether collection is empty
|
|
31
|
-
* console.log(users.size); // Number of documents
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
class FirekitCollection {
|
|
35
|
-
/** Current collection data */
|
|
36
|
-
_data = $state([]);
|
|
37
|
-
/** Loading state */
|
|
38
|
-
_loading = $state(true);
|
|
39
|
-
/** Error state */
|
|
40
|
-
_error = $state(null);
|
|
41
|
-
/** Collection reference */
|
|
42
|
-
colRef = null;
|
|
43
|
-
/** Query reference */
|
|
44
|
-
queryRef = null;
|
|
45
|
-
/**
|
|
46
|
-
* Creates a collection subscription
|
|
47
|
-
* @param {string} path Collection path
|
|
48
|
-
* @param {...QueryConstraint[]} queryConstraints Query constraints (where, orderBy, limit, etc.)
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* const collection = new FirekitCollection('users',
|
|
53
|
-
* where('age', '>=', 18),
|
|
54
|
-
* orderBy('name', 'asc'),
|
|
55
|
-
* limit(10)
|
|
56
|
-
* );
|
|
57
|
-
* ```
|
|
58
|
-
*/
|
|
59
|
-
constructor(path, ...queryConstraints) {
|
|
60
|
-
if (browser) {
|
|
61
|
-
try {
|
|
62
|
-
const firestore = firebaseService.getDbInstance();
|
|
63
|
-
this.colRef = collection(firestore, path);
|
|
64
|
-
this.queryRef = query(this.colRef, ...queryConstraints);
|
|
65
|
-
onSnapshot(this.queryRef, (snapshot) => {
|
|
66
|
-
this._data = snapshot.docs.map(doc => ({
|
|
67
|
-
id: doc.id,
|
|
68
|
-
...doc.data()
|
|
69
|
-
}));
|
|
70
|
-
this._loading = false;
|
|
71
|
-
this._error = null;
|
|
72
|
-
}, (error) => {
|
|
73
|
-
this._error = error;
|
|
74
|
-
this._loading = false;
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
this._error = error;
|
|
79
|
-
this._loading = false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
/** Gets current collection data */
|
|
84
|
-
get data() {
|
|
85
|
-
return this._data;
|
|
86
|
-
}
|
|
87
|
-
/** Gets loading state */
|
|
88
|
-
get loading() {
|
|
89
|
-
return this._loading;
|
|
90
|
-
}
|
|
91
|
-
/** Gets error state */
|
|
92
|
-
get error() {
|
|
93
|
-
return this._error;
|
|
94
|
-
}
|
|
95
|
-
/** Checks if collection is empty */
|
|
96
|
-
get empty() {
|
|
97
|
-
return this._data.length === 0;
|
|
98
|
-
}
|
|
99
|
-
/** Gets number of documents in collection */
|
|
100
|
-
get size() {
|
|
101
|
-
return this._data.length;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Gets collection reference
|
|
105
|
-
* @throws {Error} If collection reference is not available
|
|
106
|
-
*/
|
|
107
|
-
get ref() {
|
|
108
|
-
if (!this.colRef) {
|
|
109
|
-
throw new Error("Collection reference is not available");
|
|
110
|
-
}
|
|
111
|
-
return this.colRef;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Creates a collection subscription
|
|
116
|
-
* @template T Collection document type
|
|
117
|
-
* @param {string} path Collection path
|
|
118
|
-
* @param {...QueryConstraint[]} queryConstraints Query constraints
|
|
119
|
-
* @returns {FirekitCollection<T>} Collection subscription instance
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* ```typescript
|
|
123
|
-
* interface Post {
|
|
124
|
-
* id: string;
|
|
125
|
-
* title: string;
|
|
126
|
-
* authorId: string;
|
|
127
|
-
* }
|
|
128
|
-
*
|
|
129
|
-
* const posts = firekitCollection<Post>('posts',
|
|
130
|
-
* where('authorId', '==', currentUserId),
|
|
131
|
-
* orderBy('createdAt', 'desc')
|
|
132
|
-
* );
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
export function firekitCollection(path, ...queryConstraints) {
|
|
136
|
-
return new FirekitCollection(path, ...queryConstraints);
|
|
137
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitDoc
|
|
3
|
-
*/
|
|
4
|
-
import { DocumentReference } from "firebase/firestore";
|
|
5
|
-
/**
|
|
6
|
-
* Manages real-time Firestore document subscriptions with reactive state
|
|
7
|
-
* @class
|
|
8
|
-
* @template T Document data type
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* interface User {
|
|
13
|
-
* id: string;
|
|
14
|
-
* name: string;
|
|
15
|
-
* email: string;
|
|
16
|
-
* }
|
|
17
|
-
*
|
|
18
|
-
* // Create document subscription
|
|
19
|
-
* const userDoc = firekitDoc<User>('users/123', {
|
|
20
|
-
* id: '123',
|
|
21
|
-
* name: 'Loading...',
|
|
22
|
-
* email: ''
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
declare class FirekitDoc<T> {
|
|
27
|
-
/** Current document data */
|
|
28
|
-
private _data;
|
|
29
|
-
/** Loading state */
|
|
30
|
-
private _loading;
|
|
31
|
-
/** Error state */
|
|
32
|
-
private _error;
|
|
33
|
-
/** Document reference */
|
|
34
|
-
private docRef;
|
|
35
|
-
/**
|
|
36
|
-
* Creates a document subscription
|
|
37
|
-
* @param {string | DocumentReference<T>} ref Document path or reference
|
|
38
|
-
* @param {T} [startWith] Initial data before fetch completes
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const doc = new FirekitDoc('users/123', defaultUser);
|
|
43
|
-
* // or
|
|
44
|
-
* const doc = new FirekitDoc(docRef, defaultUser);
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
constructor(ref: string | DocumentReference<T>, startWith?: T);
|
|
48
|
-
/** Gets current document data */
|
|
49
|
-
get data(): T | null;
|
|
50
|
-
/** Gets document ID */
|
|
51
|
-
get id(): string;
|
|
52
|
-
/** Gets loading state */
|
|
53
|
-
get loading(): boolean;
|
|
54
|
-
/** Gets error state */
|
|
55
|
-
get error(): Error | null;
|
|
56
|
-
/**
|
|
57
|
-
* Gets document reference
|
|
58
|
-
* @throws {Error} If document reference is not available
|
|
59
|
-
*/
|
|
60
|
-
get ref(): DocumentReference<T>;
|
|
61
|
-
/** Checks if document exists */
|
|
62
|
-
get exists(): boolean;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Creates a document subscription
|
|
66
|
-
* @template T Document data type
|
|
67
|
-
* @param {string | DocumentReference<T>} ref Document path or reference
|
|
68
|
-
* @param {T} [startWith] Initial data before fetch completes
|
|
69
|
-
* @returns {FirekitDoc<T>} Document subscription instance
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const userDoc = firekitDoc<User>('users/123', {
|
|
74
|
-
* id: '123',
|
|
75
|
-
* name: 'Loading...',
|
|
76
|
-
* email: ''
|
|
77
|
-
* });
|
|
78
|
-
*
|
|
79
|
-
* // Access reactive state
|
|
80
|
-
* if (userDoc.loading) {
|
|
81
|
-
* console.log('Loading...');
|
|
82
|
-
* } else if (userDoc.error) {
|
|
83
|
-
* console.error(userDoc.error);
|
|
84
|
-
* } else if (userDoc.exists) {
|
|
85
|
-
* console.log(userDoc.data);
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
export declare function firekitDoc<T>(ref: string | DocumentReference<T>, startWith?: T): FirekitDoc<T>;
|
|
90
|
-
export {};
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitDoc
|
|
3
|
-
*/
|
|
4
|
-
import { doc, DocumentReference, onSnapshot } from "firebase/firestore";
|
|
5
|
-
import { firebaseService } from "../firebase.js";
|
|
6
|
-
import { browser } from "$app/environment";
|
|
7
|
-
/**
|
|
8
|
-
* Manages real-time Firestore document subscriptions with reactive state
|
|
9
|
-
* @class
|
|
10
|
-
* @template T Document data type
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* interface User {
|
|
15
|
-
* id: string;
|
|
16
|
-
* name: string;
|
|
17
|
-
* email: string;
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* // Create document subscription
|
|
21
|
-
* const userDoc = firekitDoc<User>('users/123', {
|
|
22
|
-
* id: '123',
|
|
23
|
-
* name: 'Loading...',
|
|
24
|
-
* email: ''
|
|
25
|
-
* });
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
class FirekitDoc {
|
|
29
|
-
/** Current document data */
|
|
30
|
-
_data = $state(null);
|
|
31
|
-
/** Loading state */
|
|
32
|
-
_loading = $state(true);
|
|
33
|
-
/** Error state */
|
|
34
|
-
_error = $state(null);
|
|
35
|
-
/** Document reference */
|
|
36
|
-
docRef = null;
|
|
37
|
-
/**
|
|
38
|
-
* Creates a document subscription
|
|
39
|
-
* @param {string | DocumentReference<T>} ref Document path or reference
|
|
40
|
-
* @param {T} [startWith] Initial data before fetch completes
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const doc = new FirekitDoc('users/123', defaultUser);
|
|
45
|
-
* // or
|
|
46
|
-
* const doc = new FirekitDoc(docRef, defaultUser);
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
constructor(ref, startWith) {
|
|
50
|
-
this._data = startWith ?? null;
|
|
51
|
-
if (browser) {
|
|
52
|
-
try {
|
|
53
|
-
const firestore = firebaseService.getDbInstance();
|
|
54
|
-
this.docRef = typeof ref === "string"
|
|
55
|
-
? doc(firestore, ref)
|
|
56
|
-
: ref;
|
|
57
|
-
onSnapshot(this.docRef, (snapshot) => {
|
|
58
|
-
const data = snapshot.data();
|
|
59
|
-
this._data = data ? { ...data, id: snapshot.id } : null;
|
|
60
|
-
this._loading = false;
|
|
61
|
-
this._error = null;
|
|
62
|
-
}, (error) => {
|
|
63
|
-
this._error = error;
|
|
64
|
-
this._loading = false;
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
this._error = error;
|
|
69
|
-
this._loading = false;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/** Gets current document data */
|
|
74
|
-
get data() {
|
|
75
|
-
return this._data;
|
|
76
|
-
}
|
|
77
|
-
/** Gets document ID */
|
|
78
|
-
get id() {
|
|
79
|
-
return this.docRef?.id ?? '';
|
|
80
|
-
}
|
|
81
|
-
/** Gets loading state */
|
|
82
|
-
get loading() {
|
|
83
|
-
return this._loading;
|
|
84
|
-
}
|
|
85
|
-
/** Gets error state */
|
|
86
|
-
get error() {
|
|
87
|
-
return this._error;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Gets document reference
|
|
91
|
-
* @throws {Error} If document reference is not available
|
|
92
|
-
*/
|
|
93
|
-
get ref() {
|
|
94
|
-
if (this.docRef === null) {
|
|
95
|
-
throw new Error("Document reference is not available yet.");
|
|
96
|
-
}
|
|
97
|
-
return this.docRef;
|
|
98
|
-
}
|
|
99
|
-
/** Checks if document exists */
|
|
100
|
-
get exists() {
|
|
101
|
-
return this._data !== null;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Creates a document subscription
|
|
106
|
-
* @template T Document data type
|
|
107
|
-
* @param {string | DocumentReference<T>} ref Document path or reference
|
|
108
|
-
* @param {T} [startWith] Initial data before fetch completes
|
|
109
|
-
* @returns {FirekitDoc<T>} Document subscription instance
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```typescript
|
|
113
|
-
* const userDoc = firekitDoc<User>('users/123', {
|
|
114
|
-
* id: '123',
|
|
115
|
-
* name: 'Loading...',
|
|
116
|
-
* email: ''
|
|
117
|
-
* });
|
|
118
|
-
*
|
|
119
|
-
* // Access reactive state
|
|
120
|
-
* if (userDoc.loading) {
|
|
121
|
-
* console.log('Loading...');
|
|
122
|
-
* } else if (userDoc.error) {
|
|
123
|
-
* console.error(userDoc.error);
|
|
124
|
-
* } else if (userDoc.exists) {
|
|
125
|
-
* console.log(userDoc.data);
|
|
126
|
-
* }
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
export function firekitDoc(ref, startWith) {
|
|
130
|
-
return new FirekitDoc(ref, startWith);
|
|
131
|
-
}
|