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.
Files changed (95) hide show
  1. package/README.md +445 -213
  2. package/dist/components/Collection.svelte +150 -0
  3. package/dist/components/Collection.svelte.d.ts +27 -0
  4. package/dist/components/Ddoc.svelte +131 -0
  5. package/dist/components/Ddoc.svelte.d.ts +28 -0
  6. package/dist/components/Node.svelte +97 -0
  7. package/dist/components/Node.svelte.d.ts +23 -0
  8. package/dist/components/auth-guard.svelte +89 -0
  9. package/dist/components/auth-guard.svelte.d.ts +26 -0
  10. package/dist/components/custom-guard.svelte +122 -0
  11. package/dist/components/custom-guard.svelte.d.ts +31 -0
  12. package/dist/components/download-url.svelte +92 -0
  13. package/dist/components/download-url.svelte.d.ts +19 -0
  14. package/dist/components/firebase-app.svelte +30 -0
  15. package/dist/components/firebase-app.svelte.d.ts +7 -0
  16. package/dist/components/node-list.svelte +102 -0
  17. package/dist/components/node-list.svelte.d.ts +27 -0
  18. package/dist/components/signed-in.svelte +42 -0
  19. package/dist/components/signed-in.svelte.d.ts +11 -0
  20. package/dist/components/signed-out.svelte +42 -0
  21. package/dist/components/signed-out.svelte.d.ts +11 -0
  22. package/dist/components/storage-list.svelte +97 -0
  23. package/dist/components/storage-list.svelte.d.ts +26 -0
  24. package/dist/components/upload-task.svelte +108 -0
  25. package/dist/components/upload-task.svelte.d.ts +24 -0
  26. package/dist/config.js +17 -39
  27. package/dist/firebase.d.ts +43 -21
  28. package/dist/firebase.js +121 -35
  29. package/dist/index.d.ts +21 -13
  30. package/dist/index.js +27 -15
  31. package/dist/services/auth.d.ts +397 -0
  32. package/dist/services/auth.js +882 -0
  33. package/dist/services/collection.svelte.d.ts +286 -0
  34. package/dist/services/collection.svelte.js +871 -0
  35. package/dist/services/document.svelte.d.ts +288 -0
  36. package/dist/services/document.svelte.js +555 -0
  37. package/dist/services/mutations.d.ts +336 -0
  38. package/dist/services/mutations.js +1079 -0
  39. package/dist/services/presence.svelte.d.ts +141 -0
  40. package/dist/services/presence.svelte.js +727 -0
  41. package/dist/{realtime → services}/realtime.svelte.d.ts +3 -1
  42. package/dist/{realtime → services}/realtime.svelte.js +13 -7
  43. package/dist/services/storage.svelte.d.ts +257 -0
  44. package/dist/services/storage.svelte.js +374 -0
  45. package/dist/services/user.svelte.d.ts +296 -0
  46. package/dist/services/user.svelte.js +609 -0
  47. package/dist/types/auth.d.ts +158 -0
  48. package/dist/types/auth.js +106 -0
  49. package/dist/types/collection.d.ts +360 -0
  50. package/dist/types/collection.js +167 -0
  51. package/dist/types/document.d.ts +342 -0
  52. package/dist/types/document.js +148 -0
  53. package/dist/types/firebase.d.ts +44 -0
  54. package/dist/types/firebase.js +33 -0
  55. package/dist/types/index.d.ts +6 -0
  56. package/dist/types/index.js +4 -0
  57. package/dist/types/mutations.d.ts +387 -0
  58. package/dist/types/mutations.js +205 -0
  59. package/dist/types/presence.d.ts +282 -0
  60. package/dist/types/presence.js +80 -0
  61. package/dist/utils/errors.d.ts +21 -0
  62. package/dist/utils/errors.js +35 -0
  63. package/dist/utils/firestore.d.ts +9 -0
  64. package/dist/utils/firestore.js +33 -0
  65. package/dist/utils/index.d.ts +4 -0
  66. package/dist/utils/index.js +8 -0
  67. package/dist/utils/providers.d.ts +16 -0
  68. package/dist/utils/providers.js +30 -0
  69. package/dist/utils/user.d.ts +8 -0
  70. package/dist/utils/user.js +29 -0
  71. package/package.json +64 -64
  72. package/dist/auth/auth.d.ts +0 -117
  73. package/dist/auth/auth.js +0 -194
  74. package/dist/auth/presence.svelte.d.ts +0 -139
  75. package/dist/auth/presence.svelte.js +0 -373
  76. package/dist/auth/user.svelte.d.ts +0 -112
  77. package/dist/auth/user.svelte.js +0 -155
  78. package/dist/firestore/awaitable-doc.svelte.d.ts +0 -141
  79. package/dist/firestore/awaitable-doc.svelte.js +0 -183
  80. package/dist/firestore/batch-mutations.svelte.d.ts +0 -140
  81. package/dist/firestore/batch-mutations.svelte.js +0 -218
  82. package/dist/firestore/collection-group.svelte.d.ts +0 -78
  83. package/dist/firestore/collection-group.svelte.js +0 -120
  84. package/dist/firestore/collection.svelte.d.ts +0 -96
  85. package/dist/firestore/collection.svelte.js +0 -137
  86. package/dist/firestore/doc.svelte.d.ts +0 -90
  87. package/dist/firestore/doc.svelte.js +0 -131
  88. package/dist/firestore/document-mutations.svelte.d.ts +0 -164
  89. package/dist/firestore/document-mutations.svelte.js +0 -273
  90. package/dist/storage/download-url.svelte.d.ts +0 -83
  91. package/dist/storage/download-url.svelte.js +0 -114
  92. package/dist/storage/storage-list.svelte.d.ts +0 -89
  93. package/dist/storage/storage-list.svelte.js +0 -123
  94. package/dist/storage/upload-task.svelte.d.ts +0 -94
  95. package/dist/storage/upload-task.svelte.js +0 -138
@@ -0,0 +1,336 @@
1
+ /**
2
+ * @fileoverview FirekitDocumentMutations - Optimized document mutation service for Svelte
3
+ * @module FirekitDocumentMutations
4
+ * @version 1.0.0
5
+ */
6
+ import { type DocumentData, type WithFieldValue, type PartialWithFieldValue } from 'firebase/firestore';
7
+ import { type MutationResponse, type MutationOptions, type BatchOperation, type BatchResult, type ExistenceCheckResult, type BulkMutationConfig, type MutationEventCallback, type MutationAnalytics } from '../types/mutations.js';
8
+ /**
9
+ * Comprehensive Firestore document mutation service with advanced features.
10
+ * Handles CRUD operations, batch processing, validation, error handling, and analytics.
11
+ *
12
+ * @class FirekitDocumentMutations
13
+ * @example
14
+ * ```typescript
15
+ * import { firekitDocMutations } from 'svelte-firekit';
16
+ *
17
+ * // Add a new document
18
+ * const result = await firekitDocMutations.add('users', {
19
+ * name: 'John Doe',
20
+ * email: 'john@example.com'
21
+ * }, {
22
+ * timestamps: true,
23
+ * validate: true
24
+ * });
25
+ *
26
+ * // Batch operations
27
+ * const batchResult = await firekitDocMutations.batch([
28
+ * { type: 'create', path: 'users', data: userData },
29
+ * { type: 'update', path: 'profiles/123', data: profileUpdate }
30
+ * ]);
31
+ *
32
+ * // Listen to mutation events
33
+ * const unsubscribe = firekitDocMutations.addEventListener((event) => {
34
+ * console.log('Mutation event:', event.type, event.data);
35
+ * });
36
+ * ```
37
+ */
38
+ declare class FirekitDocumentMutations {
39
+ private eventListeners;
40
+ private analytics;
41
+ private defaultOptions;
42
+ /**
43
+ * Initialize analytics object
44
+ */
45
+ private initializeAnalytics;
46
+ /**
47
+ * Generate timestamp data for document mutations
48
+ */
49
+ private getTimestampData;
50
+ /**
51
+ * Validate data using custom validator or basic validation
52
+ */
53
+ private validateData;
54
+ /**
55
+ * Handle and format mutation errors
56
+ */
57
+ private handleError;
58
+ /**
59
+ * Map Firestore error codes to MutationErrorCode
60
+ */
61
+ private mapFirestoreErrorCode;
62
+ /**
63
+ * Update error analytics
64
+ */
65
+ private updateErrorAnalytics;
66
+ /**
67
+ * Emit event to all listeners
68
+ */
69
+ private emitEvent;
70
+ /**
71
+ * Execute operation with retry logic
72
+ */
73
+ private executeWithRetry;
74
+ /**
75
+ * Add a new document to a collection
76
+ *
77
+ * @template T Document data type
78
+ * @param collectionPath Collection path
79
+ * @param data Document data
80
+ * @param options Mutation options
81
+ * @returns Promise resolving to mutation response
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const result = await firekitDocMutations.add('users', {
86
+ * name: 'John Doe',
87
+ * email: 'john@example.com'
88
+ * }, {
89
+ * timestamps: true,
90
+ * customId: 'custom-user-id',
91
+ * validate: true
92
+ * });
93
+ *
94
+ * if (result.success) {
95
+ * console.log('Created document:', result.id);
96
+ * }
97
+ * ```
98
+ */
99
+ add<T extends DocumentData>(collectionPath: string, data: WithFieldValue<T>, options?: MutationOptions): Promise<MutationResponse<T>>;
100
+ /**
101
+ * Set document data at specified path
102
+ *
103
+ * @template T Document data type
104
+ * @param path Document path
105
+ * @param data Document data
106
+ * @param options Mutation options
107
+ * @returns Promise resolving to mutation response
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * const result = await firekitDocMutations.set('users/123', {
112
+ * name: 'John Doe',
113
+ * email: 'john@example.com'
114
+ * }, {
115
+ * merge: true,
116
+ * timestamps: true
117
+ * });
118
+ * ```
119
+ */
120
+ set<T extends DocumentData>(path: string, data: WithFieldValue<T>, options?: MutationOptions): Promise<MutationResponse<T>>;
121
+ /**
122
+ * Update a document at specified path
123
+ *
124
+ * @template T Document data type
125
+ * @param path Document path
126
+ * @param data Update data
127
+ * @param options Mutation options
128
+ * @returns Promise resolving to mutation response
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const result = await firekitDocMutations.update('users/123', {
133
+ * name: 'Jane Doe',
134
+ * lastLogin: serverTimestamp()
135
+ * });
136
+ * ```
137
+ */
138
+ update<T extends DocumentData>(path: string, data: PartialWithFieldValue<T>, options?: MutationOptions): Promise<MutationResponse<Partial<T>>>;
139
+ /**
140
+ * Delete a document at specified path
141
+ *
142
+ * @param path Document path
143
+ * @param options Mutation options
144
+ * @returns Promise resolving to mutation response
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const result = await firekitDocMutations.delete('users/123');
149
+ * if (result.success) {
150
+ * console.log('Document deleted');
151
+ * }
152
+ * ```
153
+ */
154
+ delete(path: string, options?: MutationOptions): Promise<MutationResponse<void>>;
155
+ /**
156
+ * Increment a numeric field
157
+ *
158
+ * @param path Document path
159
+ * @param field Field name
160
+ * @param value Increment value
161
+ * @param options Mutation options
162
+ * @returns Promise resolving to mutation response
163
+ */
164
+ increment(path: string, field: string, value: number, options?: MutationOptions): Promise<MutationResponse<any>>;
165
+ /**
166
+ * Add elements to an array field
167
+ *
168
+ * @param path Document path
169
+ * @param field Field name
170
+ * @param elements Elements to add
171
+ * @param options Mutation options
172
+ * @returns Promise resolving to mutation response
173
+ */
174
+ arrayUnion(path: string, field: string, elements: any[], options?: MutationOptions): Promise<MutationResponse<any>>;
175
+ /**
176
+ * Remove elements from an array field
177
+ *
178
+ * @param path Document path
179
+ * @param field Field name
180
+ * @param elements Elements to remove
181
+ * @param options Mutation options
182
+ * @returns Promise resolving to mutation response
183
+ */
184
+ arrayRemove(path: string, field: string, elements: any[], options?: MutationOptions): Promise<MutationResponse<any>>;
185
+ /**
186
+ * Delete a field from document
187
+ *
188
+ * @param path Document path
189
+ * @param field Field name
190
+ * @param options Mutation options
191
+ * @returns Promise resolving to mutation response
192
+ */
193
+ deleteField(path: string, field: string, options?: MutationOptions): Promise<MutationResponse<any>>;
194
+ /**
195
+ * Execute multiple operations in a batch
196
+ *
197
+ * @param operations Array of batch operations
198
+ * @param config Bulk mutation configuration
199
+ * @returns Promise resolving to batch result
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const result = await firekitDocMutations.batch([
204
+ * { type: 'create', path: 'users', data: userData },
205
+ * { type: 'update', path: 'profiles/123', data: profileUpdate },
206
+ * { type: 'delete', path: 'temp/456' }
207
+ * ], {
208
+ * batchSize: 500,
209
+ * failFast: false,
210
+ * onProgress: (completed, total) => console.log(`${completed}/${total}`)
211
+ * });
212
+ * ```
213
+ */
214
+ batch(operations: BatchOperation[], config?: BulkMutationConfig): Promise<BatchResult>;
215
+ /**
216
+ * Add operation to batch writer
217
+ */
218
+ private addOperationToBatch;
219
+ /**
220
+ * Chunk array into smaller arrays
221
+ */
222
+ private chunkArray;
223
+ /**
224
+ * Check if a document exists at specified path
225
+ *
226
+ * @param path Document path
227
+ * @returns Promise resolving to existence check result
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const checkResult = await firekitDocMutations.exists('users/123');
232
+ * if (checkResult.exists) {
233
+ * console.log('Document exists');
234
+ * }
235
+ * ```
236
+ */
237
+ exists(path: string): Promise<ExistenceCheckResult>;
238
+ /**
239
+ * Get a document at specified path
240
+ *
241
+ * @template T Document data type
242
+ * @param path Document path
243
+ * @returns Promise resolving to mutation response with document data
244
+ *
245
+ * @example
246
+ * ```typescript
247
+ * const result = await firekitDocMutations.getDoc<UserData>('users/123');
248
+ * if (result.success && result.data) {
249
+ * console.log('User data:', result.data);
250
+ * }
251
+ * ```
252
+ */
253
+ getDoc<T extends DocumentData>(path: string): Promise<MutationResponse<T>>;
254
+ /**
255
+ * Update operation analytics
256
+ */
257
+ private updateOperationAnalytics;
258
+ /**
259
+ * Add event listener for mutation events
260
+ *
261
+ * @param callback Event callback function
262
+ * @returns Cleanup function to remove listener
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * const unsubscribe = firekitDocMutations.addEventListener((event) => {
267
+ * console.log('Mutation event:', event.type, event.data);
268
+ * });
269
+ *
270
+ * // Clean up when done
271
+ * unsubscribe();
272
+ * ```
273
+ */
274
+ addEventListener(callback: MutationEventCallback): () => void;
275
+ /**
276
+ * Remove all event listeners
277
+ */
278
+ clearEventListeners(): void;
279
+ /**
280
+ * Get current mutation analytics
281
+ *
282
+ * @returns Current analytics data
283
+ */
284
+ getAnalytics(): MutationAnalytics;
285
+ /**
286
+ * Reset analytics data
287
+ */
288
+ resetAnalytics(): void;
289
+ /**
290
+ * Create server timestamp field value
291
+ */
292
+ static serverTimestamp(): import("@firebase/firestore").FieldValue;
293
+ /**
294
+ * Create increment field value
295
+ */
296
+ static increment(value: number): import("@firebase/firestore").FieldValue;
297
+ /**
298
+ * Create array union field value
299
+ */
300
+ static arrayUnion(...elements: any[]): import("@firebase/firestore").FieldValue;
301
+ /**
302
+ * Create array remove field value
303
+ */
304
+ static arrayRemove(...elements: any[]): import("@firebase/firestore").FieldValue;
305
+ /**
306
+ * Create delete field value
307
+ */
308
+ static deleteField(): import("@firebase/firestore").FieldValue;
309
+ }
310
+ /**
311
+ * Pre-initialized singleton instance of FirekitDocumentMutations.
312
+ *
313
+ * @example
314
+ * ```typescript
315
+ * import { firekitDocMutations } from 'svelte-firekit';
316
+ *
317
+ * // Add document
318
+ * const result = await firekitDocMutations.add('users', userData);
319
+ *
320
+ * // Update document
321
+ * await firekitDocMutations.update('users/123', { name: 'New Name' });
322
+ *
323
+ * // Batch operations
324
+ * const batchResult = await firekitDocMutations.batch([
325
+ * { type: 'create', path: 'users', data: userData },
326
+ * { type: 'update', path: 'profiles/123', data: updateData }
327
+ * ]);
328
+ *
329
+ * // Listen to events
330
+ * const unsubscribe = firekitDocMutations.addEventListener((event) => {
331
+ * console.log('Mutation:', event.type, event.data);
332
+ * });
333
+ * ```
334
+ */
335
+ export declare const firekitDocMutations: FirekitDocumentMutations;
336
+ export {};