svelte-firekit 0.0.25 → 0.1.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/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 +389 -0
- package/dist/services/auth.js +824 -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 +290 -0
- package/dist/services/user.svelte.js +533 -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 +65 -65
- 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
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview FirekitCollection - Optimized collection management for Svelte applications
|
|
3
|
+
* @module FirekitCollection
|
|
4
|
+
* @version 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
import { type Query, type CollectionReference, type DocumentData, type QueryConstraint } from 'firebase/firestore';
|
|
7
|
+
import { type CollectionState, type CollectionOptions, type CollectionEventCallback, type CollectionStats, type QueryBuilder, CollectionError } from '../types/collection.js';
|
|
8
|
+
/**
|
|
9
|
+
* Comprehensive Firestore collection management with real-time updates and advanced features.
|
|
10
|
+
* Uses Svelte 5 runes for optimal reactivity and performance.
|
|
11
|
+
*
|
|
12
|
+
* @class FirekitCollection
|
|
13
|
+
* @template T Document data type
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* interface User {
|
|
18
|
+
* id: string;
|
|
19
|
+
* name: string;
|
|
20
|
+
* email: string;
|
|
21
|
+
* active: boolean;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* // Simple collection subscription
|
|
25
|
+
* const users = firekitCollection<User>('users');
|
|
26
|
+
*
|
|
27
|
+
* // With query constraints
|
|
28
|
+
* const activeUsers = firekitCollection<User>('users',
|
|
29
|
+
* where('active', '==', true),
|
|
30
|
+
* orderBy('name'),
|
|
31
|
+
* limit(10)
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* // With advanced options
|
|
35
|
+
* const paginatedUsers = firekitCollection<User>('users', {
|
|
36
|
+
* pagination: { enabled: true, pageSize: 20 },
|
|
37
|
+
* cache: { enabled: true, ttl: 300000 },
|
|
38
|
+
* transform: (doc) => ({ ...doc, displayName: doc.name.toUpperCase() })
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Access reactive state
|
|
42
|
+
* $: if (users.loading) {
|
|
43
|
+
* console.log('Loading...');
|
|
44
|
+
* } else if (users.error) {
|
|
45
|
+
* console.error('Error:', users.error);
|
|
46
|
+
* } else {
|
|
47
|
+
* console.log('Users:', users.data);
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare class FirekitCollection<T extends DocumentData = DocumentData> {
|
|
52
|
+
private _data;
|
|
53
|
+
private _loading;
|
|
54
|
+
private _initialized;
|
|
55
|
+
private _error;
|
|
56
|
+
private _lastUpdated;
|
|
57
|
+
private collectionRef;
|
|
58
|
+
protected queryRef: Query<T> | null;
|
|
59
|
+
private unsubscribe;
|
|
60
|
+
private eventListeners;
|
|
61
|
+
protected options: CollectionOptions;
|
|
62
|
+
private stats;
|
|
63
|
+
private cache;
|
|
64
|
+
private collectionPath;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a collection subscription
|
|
67
|
+
*
|
|
68
|
+
* @param path Collection path
|
|
69
|
+
* @param constraintsOrOptions Query constraints or collection options
|
|
70
|
+
* @param additionalConstraints Additional constraints if options were provided
|
|
71
|
+
*/
|
|
72
|
+
constructor(path: string, constraintsOrOptions?: QueryConstraint[] | CollectionOptions, ...additionalConstraints: QueryConstraint[]);
|
|
73
|
+
/**
|
|
74
|
+
* Initialize statistics object
|
|
75
|
+
*/
|
|
76
|
+
private initializeStats;
|
|
77
|
+
/**
|
|
78
|
+
* Initialize collection subscription
|
|
79
|
+
*/
|
|
80
|
+
private initializeCollection;
|
|
81
|
+
/**
|
|
82
|
+
* Set up real-time document listener
|
|
83
|
+
*/
|
|
84
|
+
protected setupRealtimeListener(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Fetch collection data once (no real-time updates)
|
|
87
|
+
*/
|
|
88
|
+
protected fetchOnce(): Promise<void>;
|
|
89
|
+
/**
|
|
90
|
+
* Process query snapshot and update state
|
|
91
|
+
*/
|
|
92
|
+
private processSnapshot;
|
|
93
|
+
/**
|
|
94
|
+
* Calculate changes between old and new document arrays
|
|
95
|
+
*/
|
|
96
|
+
private calculateChanges;
|
|
97
|
+
/**
|
|
98
|
+
* Handle and process errors
|
|
99
|
+
*/
|
|
100
|
+
protected handleError(error: any): void;
|
|
101
|
+
/**
|
|
102
|
+
* Map Firestore error codes to CollectionErrorCode
|
|
103
|
+
*/
|
|
104
|
+
private mapFirestoreErrorCode;
|
|
105
|
+
/**
|
|
106
|
+
* Generate cache key for query
|
|
107
|
+
*/
|
|
108
|
+
private getCacheKey;
|
|
109
|
+
/**
|
|
110
|
+
* Check if cache entry is still valid
|
|
111
|
+
*/
|
|
112
|
+
private isCacheValid;
|
|
113
|
+
/**
|
|
114
|
+
* Clean up expired cache entries
|
|
115
|
+
*/
|
|
116
|
+
private cleanupCache;
|
|
117
|
+
/**
|
|
118
|
+
* Calculate memory usage of documents
|
|
119
|
+
*/
|
|
120
|
+
private calculateMemoryUsage;
|
|
121
|
+
/**
|
|
122
|
+
* Emit event to all listeners
|
|
123
|
+
*/
|
|
124
|
+
private emitEvent;
|
|
125
|
+
/**
|
|
126
|
+
* Get current collection data
|
|
127
|
+
*/
|
|
128
|
+
get data(): T[];
|
|
129
|
+
/**
|
|
130
|
+
* Get loading state
|
|
131
|
+
*/
|
|
132
|
+
get loading(): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Get initialization state
|
|
135
|
+
*/
|
|
136
|
+
get initialized(): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Get error state
|
|
139
|
+
*/
|
|
140
|
+
get error(): CollectionError | null;
|
|
141
|
+
/**
|
|
142
|
+
* Check if collection is empty
|
|
143
|
+
*/
|
|
144
|
+
get empty(): boolean;
|
|
145
|
+
/**
|
|
146
|
+
* Get number of documents
|
|
147
|
+
*/
|
|
148
|
+
get size(): number;
|
|
149
|
+
/**
|
|
150
|
+
* Get last update timestamp
|
|
151
|
+
*/
|
|
152
|
+
get lastUpdated(): Date | null;
|
|
153
|
+
/**
|
|
154
|
+
* Get collection reference
|
|
155
|
+
*/
|
|
156
|
+
get ref(): CollectionReference<T>;
|
|
157
|
+
/**
|
|
158
|
+
* Get query reference
|
|
159
|
+
*/
|
|
160
|
+
get queryReference(): Query<T>;
|
|
161
|
+
/**
|
|
162
|
+
* Get collection path
|
|
163
|
+
*/
|
|
164
|
+
get path(): string;
|
|
165
|
+
/**
|
|
166
|
+
* Get collection state summary
|
|
167
|
+
*/
|
|
168
|
+
get state(): CollectionState<T>;
|
|
169
|
+
/**
|
|
170
|
+
* Manually refresh collection data
|
|
171
|
+
*/
|
|
172
|
+
refresh(): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Get fresh data from server (bypassing cache)
|
|
175
|
+
*/
|
|
176
|
+
getFromServer(): Promise<T[]>;
|
|
177
|
+
/**
|
|
178
|
+
* Add query constraints to existing query
|
|
179
|
+
*/
|
|
180
|
+
addConstraints(...constraints: QueryConstraint[]): FirekitCollection<T>;
|
|
181
|
+
/**
|
|
182
|
+
* Create a new query builder for this collection
|
|
183
|
+
*/
|
|
184
|
+
createQuery(): QueryBuilder<T>;
|
|
185
|
+
/**
|
|
186
|
+
* Apply new query constraints
|
|
187
|
+
*/
|
|
188
|
+
withQuery(builder: QueryBuilder<T>): FirekitCollection<T>;
|
|
189
|
+
/**
|
|
190
|
+
* Filter documents by predicate
|
|
191
|
+
*/
|
|
192
|
+
filter(predicate: (doc: T) => boolean): T[];
|
|
193
|
+
/**
|
|
194
|
+
* Find first document matching predicate
|
|
195
|
+
*/
|
|
196
|
+
find(predicate: (doc: T) => boolean): T | undefined;
|
|
197
|
+
/**
|
|
198
|
+
* Find document by ID
|
|
199
|
+
*/
|
|
200
|
+
findById(id: string): T | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* Sort documents by field or custom function
|
|
203
|
+
*/
|
|
204
|
+
sort(compareFn: (a: T, b: T) => number): T[];
|
|
205
|
+
/**
|
|
206
|
+
* Get paginated subset of documents
|
|
207
|
+
*/
|
|
208
|
+
paginate(page: number, pageSize: number): T[];
|
|
209
|
+
/**
|
|
210
|
+
* Group documents by field value
|
|
211
|
+
*/
|
|
212
|
+
groupBy<K extends keyof T>(field: K): Map<T[K], T[]>;
|
|
213
|
+
/**
|
|
214
|
+
* Get unique values for a field
|
|
215
|
+
*/
|
|
216
|
+
unique<K extends keyof T>(field: K): T[K][];
|
|
217
|
+
/**
|
|
218
|
+
* Count documents matching predicate
|
|
219
|
+
*/
|
|
220
|
+
count(predicate?: (doc: T) => boolean): number;
|
|
221
|
+
/**
|
|
222
|
+
* Check if any document matches predicate
|
|
223
|
+
*/
|
|
224
|
+
some(predicate: (doc: T) => boolean): boolean;
|
|
225
|
+
/**
|
|
226
|
+
* Check if all documents match predicate
|
|
227
|
+
*/
|
|
228
|
+
every(predicate: (doc: T) => boolean): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Switch between realtime and one-time fetch modes
|
|
231
|
+
*/
|
|
232
|
+
setRealtimeMode(realtime: boolean): void;
|
|
233
|
+
/**
|
|
234
|
+
* Clear cache for this collection
|
|
235
|
+
*/
|
|
236
|
+
clearCache(): void;
|
|
237
|
+
/**
|
|
238
|
+
* Get collection statistics
|
|
239
|
+
*/
|
|
240
|
+
getStats(): CollectionStats;
|
|
241
|
+
/**
|
|
242
|
+
* Reset statistics
|
|
243
|
+
*/
|
|
244
|
+
resetStats(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Add event listener
|
|
247
|
+
*/
|
|
248
|
+
addEventListener(callback: CollectionEventCallback<T>): () => void;
|
|
249
|
+
/**
|
|
250
|
+
* Remove all event listeners
|
|
251
|
+
*/
|
|
252
|
+
clearEventListeners(): void;
|
|
253
|
+
/**
|
|
254
|
+
* Wait for collection to initialize
|
|
255
|
+
*/
|
|
256
|
+
waitForInitialization(): Promise<T[]>;
|
|
257
|
+
/**
|
|
258
|
+
* Dispose of all resources and cleanup
|
|
259
|
+
*/
|
|
260
|
+
dispose(): void;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Collection Group implementation for querying across multiple collections
|
|
264
|
+
*/
|
|
265
|
+
declare class FirekitCollectionGroup<T extends DocumentData = DocumentData> extends FirekitCollection<T> {
|
|
266
|
+
constructor(collectionId: string, constraintsOrOptions?: QueryConstraint[] | CollectionOptions, ...additionalConstraints: QueryConstraint[]);
|
|
267
|
+
/**
|
|
268
|
+
* Initialize collection group subscription
|
|
269
|
+
*/
|
|
270
|
+
private initializeCollectionGroup;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Creates a reactive collection subscription
|
|
274
|
+
*/
|
|
275
|
+
export declare function firekitCollection<T extends DocumentData = DocumentData>(path: string, constraintsOrOptions?: QueryConstraint[] | CollectionOptions, ...additionalConstraints: QueryConstraint[]): FirekitCollection<T>;
|
|
276
|
+
export declare function firekitCollection<T extends DocumentData = DocumentData>(path: string, options: CollectionOptions, ...constraints: QueryConstraint[]): FirekitCollection<T>;
|
|
277
|
+
/**
|
|
278
|
+
* Creates a one-time collection fetch (no real-time updates)
|
|
279
|
+
*/
|
|
280
|
+
export declare function firekitCollectionOnce<T extends DocumentData = DocumentData>(path: string, ...constraints: QueryConstraint[]): FirekitCollection<T>;
|
|
281
|
+
/**
|
|
282
|
+
* Creates a collection group subscription
|
|
283
|
+
*/
|
|
284
|
+
export declare function firekitCollectionGroup<T extends DocumentData = DocumentData>(collectionId: string, constraintsOrOptions?: QueryConstraint[] | CollectionOptions, ...additionalConstraints: QueryConstraint[]): FirekitCollectionGroup<T>;
|
|
285
|
+
export declare function firekitCollectionGroup<T extends DocumentData = DocumentData>(collectionId: string, options: CollectionOptions, ...constraints: QueryConstraint[]): FirekitCollectionGroup<T>;
|
|
286
|
+
export {};
|