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
package/dist/config.js CHANGED
@@ -1,19 +1,8 @@
1
1
  import { PUBLIC_FIREBASE_API_KEY, PUBLIC_FIREBASE_AUTH_DOMAIN, PUBLIC_FIREBASE_PROJECT_ID, PUBLIC_FIREBASE_STORAGE_BUCKET, PUBLIC_FIREBASE_MESSAGING_SENDER_ID, PUBLIC_FIREBASE_APP_ID, PUBLIC_FIREBASE_MEASUREMENT_ID } from '$env/static/public';
2
+ import { isValidFirebaseConfig } from './types/firebase.js';
2
3
  /**
3
4
  * @module FirebaseConfig
4
5
  */
5
- /**
6
- * Required environment variables for Firebase configuration.
7
- * These must be defined in your .env file or environment.
8
- * @typedef {Object} FirebaseEnvVars
9
- * @property {string} PUBLIC_FIREBASE_API_KEY - Firebase API key
10
- * @property {string} PUBLIC_FIREBASE_AUTH_DOMAIN - Firebase auth domain
11
- * @property {string} PUBLIC_FIREBASE_PROJECT_ID - Firebase project ID
12
- * @property {string} PUBLIC_FIREBASE_STORAGE_BUCKET - Firebase storage bucket
13
- * @property {string} PUBLIC_FIREBASE_MESSAGING_SENDER_ID - Firebase messaging sender ID
14
- * @property {string} PUBLIC_FIREBASE_APP_ID - Firebase app ID
15
- * @property {string} PUBLIC_FIREBASE_MEASUREMENT_ID - Firebase measurement ID
16
- */
17
6
  /**
18
7
  * Singleton class that manages Firebase configuration.
19
8
  * Implements the Singleton pattern to ensure only one Firebase config instance exists.
@@ -25,7 +14,7 @@ import { PUBLIC_FIREBASE_API_KEY, PUBLIC_FIREBASE_AUTH_DOMAIN, PUBLIC_FIREBASE_P
25
14
  * // Initialize Firebase app
26
15
  * const app = initializeApp(config);
27
16
  *
28
- * @throws {Error} If any required Firebase configuration variables are missing
17
+ * @throws {Error} If any required Firebase configuration variables are missing or invalid
29
18
  */
30
19
  class FirebaseConfig {
31
20
  static instance;
@@ -35,14 +24,23 @@ class FirebaseConfig {
35
24
  * Validates all required environment variables are present and creates config.
36
25
  *
37
26
  * @private
38
- * @throws {Error} If any required Firebase configuration variables are missing
27
+ * @throws {Error} If any required Firebase configuration variables are missing or invalid
39
28
  */
40
29
  constructor() {
41
- const missingVars = this.getMissingFirebaseConfigVars();
42
- if (missingVars.length > 0) {
43
- throw Error(`The following Firebase configuration variables are missing: ${missingVars.join(', ')}`);
30
+ const config = this.getFirebaseConfig();
31
+ if (!isValidFirebaseConfig(config)) {
32
+ throw new Error('Invalid Firebase configuration. Please check your environment variables.');
44
33
  }
45
- this.config = {
34
+ this.config = config;
35
+ }
36
+ /**
37
+ * Gets the Firebase configuration from environment variables.
38
+ *
39
+ * @private
40
+ * @returns {Partial<FirebaseEnvVars>} The Firebase configuration
41
+ */
42
+ getFirebaseConfig() {
43
+ return {
46
44
  apiKey: PUBLIC_FIREBASE_API_KEY,
47
45
  authDomain: PUBLIC_FIREBASE_AUTH_DOMAIN,
48
46
  projectId: PUBLIC_FIREBASE_PROJECT_ID,
@@ -52,32 +50,12 @@ class FirebaseConfig {
52
50
  measurementId: PUBLIC_FIREBASE_MEASUREMENT_ID
53
51
  };
54
52
  }
55
- /**
56
- * Checks for missing required Firebase configuration variables.
57
- *
58
- * @private
59
- * @returns {string[]} Array of missing environment variable names
60
- */
61
- getMissingFirebaseConfigVars() {
62
- const requiredVars = {
63
- 'PUBLIC_FIREBASE_API_KEY': PUBLIC_FIREBASE_API_KEY,
64
- 'PUBLIC_FIREBASE_AUTH_DOMAIN': PUBLIC_FIREBASE_AUTH_DOMAIN,
65
- 'PUBLIC_FIREBASE_PROJECT_ID': PUBLIC_FIREBASE_PROJECT_ID,
66
- 'PUBLIC_FIREBASE_STORAGE_BUCKET': PUBLIC_FIREBASE_STORAGE_BUCKET,
67
- 'PUBLIC_FIREBASE_MESSAGING_SENDER_ID': PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
68
- 'PUBLIC_FIREBASE_APP_ID': PUBLIC_FIREBASE_APP_ID,
69
- 'PUBLIC_FIREBASE_MEASUREMENT_ID': PUBLIC_FIREBASE_MEASUREMENT_ID
70
- };
71
- return Object.entries(requiredVars)
72
- .filter(([_, value]) => !value)
73
- .map(([key]) => key);
74
- }
75
53
  /**
76
54
  * Gets the singleton instance of FirebaseConfig.
77
55
  * Creates a new instance if one doesn't exist.
78
56
  *
79
57
  * @returns {FirebaseConfig} The singleton FirebaseConfig instance
80
- * @throws {Error} If any required Firebase configuration variables are missing
58
+ * @throws {Error} If any required Firebase configuration variables are missing or invalid
81
59
  */
82
60
  static getInstance() {
83
61
  if (!FirebaseConfig.instance) {
@@ -1,9 +1,4 @@
1
- import { type FirebaseApp } from 'firebase/app';
2
- import { type Firestore } from 'firebase/firestore';
3
- import { type Auth } from 'firebase/auth';
4
- import { type Functions } from 'firebase/functions';
5
- import { type Database } from 'firebase/database';
6
- import { type FirebaseStorage } from 'firebase/storage';
1
+ import { FirebaseServiceStatus, type FirebaseServiceInstance } from './types/firebase.js';
7
2
  /**
8
3
  * Singleton service class that manages Firebase service instances.
9
4
  * Handles initialization and access to Firebase app and its various services.
@@ -15,16 +10,17 @@ import { type FirebaseStorage } from 'firebase/storage';
15
10
  * // Get Auth instance
16
11
  * const auth = firebaseService.getAuthInstance();
17
12
  */
18
- declare class FirebaseService {
13
+ declare class FirebaseService implements FirebaseServiceInstance {
19
14
  private static instance;
20
- private firebaseApp;
21
- private db;
22
- private auth;
23
- private functions;
24
- private database;
25
- private storage;
26
- /** Flag to determine if code is running in browser environment */
27
- private readonly isBrowser;
15
+ firebaseApp: FirebaseServiceInstance['firebaseApp'];
16
+ db: FirebaseServiceInstance['db'];
17
+ auth: FirebaseServiceInstance['auth'];
18
+ functions: FirebaseServiceInstance['functions'];
19
+ database: FirebaseServiceInstance['database'];
20
+ storage: FirebaseServiceInstance['storage'];
21
+ status: FirebaseServiceStatus;
22
+ initializationError: Error | null;
23
+ readonly isBrowser: boolean;
28
24
  /** @private */
29
25
  private constructor();
30
26
  /**
@@ -34,50 +30,76 @@ declare class FirebaseService {
34
30
  * @returns {FirebaseService} The singleton FirebaseService instance
35
31
  */
36
32
  static getInstance(): FirebaseService;
33
+ /**
34
+ * Gets the current status of the Firebase service
35
+ *
36
+ * @returns {FirebaseServiceStatus} The current service status
37
+ */
38
+ getStatus(): FirebaseServiceStatus;
39
+ /**
40
+ * Gets the initialization error if any occurred
41
+ *
42
+ * @returns {Error | null} The initialization error or null if none occurred
43
+ */
44
+ getInitializationError(): Error | null;
37
45
  /**
38
46
  * Initializes or retrieves the Firebase app instance.
39
47
  * Also initializes Firestore if running in browser environment.
40
48
  *
41
49
  * @returns {FirebaseApp} The Firebase app instance
50
+ * @throws {FirebaseServiceError} If initialization fails
42
51
  */
43
- getFirebaseApp(): FirebaseApp;
52
+ getFirebaseApp(): FirebaseServiceInstance['firebaseApp'];
44
53
  /**
45
54
  * Initializes Firestore with persistent cache and multi-tab support.
46
55
  * Only runs in browser environment.
47
56
  *
48
57
  * @private
58
+ * @throws {FirebaseServiceError} If Firestore initialization fails
49
59
  */
50
60
  private initializeFirestoreInstance;
51
61
  /**
52
62
  * Gets the Firestore instance, initializing it if necessary.
53
63
  *
54
64
  * @returns {Firestore} The Firestore instance
65
+ * @throws {FirebaseServiceError} If Firestore is not available
55
66
  */
56
- getDbInstance(): Firestore;
67
+ getDbInstance(): FirebaseServiceInstance['db'];
57
68
  /**
58
69
  * Gets the Authentication instance, initializing it if necessary.
59
70
  *
60
71
  * @returns {Auth} The Authentication instance
72
+ * @throws {FirebaseServiceError} If Auth initialization fails
61
73
  */
62
- getAuthInstance(): Auth;
74
+ getAuthInstance(): FirebaseServiceInstance['auth'];
63
75
  /**
64
76
  * Gets the Cloud Functions instance, initializing it if necessary.
65
77
  *
66
78
  * @returns {Functions} The Cloud Functions instance
79
+ * @throws {FirebaseServiceError} If Functions initialization fails
67
80
  */
68
- getFunctionsInstance(): Functions;
81
+ getFunctionsInstance(): FirebaseServiceInstance['functions'];
69
82
  /**
70
83
  * Gets the Realtime Database instance, initializing it if necessary.
71
84
  *
72
85
  * @returns {Database} The Realtime Database instance
86
+ * @throws {FirebaseServiceError} If Database initialization fails
73
87
  */
74
- getDatabaseInstance(): Database;
88
+ getDatabaseInstance(): FirebaseServiceInstance['database'];
75
89
  /**
76
90
  * Gets the Storage instance, initializing it if necessary.
77
91
  *
78
92
  * @returns {FirebaseStorage} The Storage instance
93
+ * @throws {FirebaseServiceError} If Storage initialization fails
94
+ */
95
+ getStorageInstance(): FirebaseServiceInstance['storage'];
96
+ /**
97
+ * Resets the Firebase service to its initial state.
98
+ * Useful for testing or when you need to reinitialize the services.
99
+ *
100
+ * @returns {Promise<void>}
79
101
  */
80
- getStorageInstance(): FirebaseStorage;
102
+ reset(): Promise<void>;
81
103
  }
82
104
  /**
83
105
  * Pre-initialized Firebase service instance.
package/dist/firebase.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { initializeApp, getApps } from 'firebase/app';
2
- import { initializeFirestore, CACHE_SIZE_UNLIMITED, persistentLocalCache, persistentMultipleTabManager, enablePersistentCacheIndexAutoCreation, getPersistentCacheIndexManager, } from 'firebase/firestore';
2
+ import { initializeFirestore, CACHE_SIZE_UNLIMITED, persistentLocalCache, persistentMultipleTabManager, enablePersistentCacheIndexAutoCreation, getPersistentCacheIndexManager } from 'firebase/firestore';
3
3
  import { getAuth } from 'firebase/auth';
4
4
  import { getFunctions } from 'firebase/functions';
5
5
  import { getDatabase } from 'firebase/database';
6
6
  import { getStorage } from 'firebase/storage';
7
7
  import { firebaseConfig } from './config.js';
8
+ import { FirebaseServiceStatus, FirebaseServiceError } from './types/firebase.js';
8
9
  /**
9
10
  * Singleton service class that manages Firebase service instances.
10
11
  * Handles initialization and access to Firebase app and its various services.
@@ -24,7 +25,8 @@ class FirebaseService {
24
25
  functions = null;
25
26
  database = null;
26
27
  storage = null;
27
- /** Flag to determine if code is running in browser environment */
28
+ status = FirebaseServiceStatus.UNINITIALIZED;
29
+ initializationError = null;
28
30
  isBrowser = typeof window !== 'undefined';
29
31
  /** @private */
30
32
  constructor() { }
@@ -40,99 +42,183 @@ class FirebaseService {
40
42
  }
41
43
  return FirebaseService.instance;
42
44
  }
45
+ /**
46
+ * Gets the current status of the Firebase service
47
+ *
48
+ * @returns {FirebaseServiceStatus} The current service status
49
+ */
50
+ getStatus() {
51
+ return this.status;
52
+ }
53
+ /**
54
+ * Gets the initialization error if any occurred
55
+ *
56
+ * @returns {Error | null} The initialization error or null if none occurred
57
+ */
58
+ getInitializationError() {
59
+ return this.initializationError;
60
+ }
43
61
  /**
44
62
  * Initializes or retrieves the Firebase app instance.
45
63
  * Also initializes Firestore if running in browser environment.
46
64
  *
47
65
  * @returns {FirebaseApp} The Firebase app instance
66
+ * @throws {FirebaseServiceError} If initialization fails
48
67
  */
49
68
  getFirebaseApp() {
69
+ if (this.status === FirebaseServiceStatus.ERROR) {
70
+ throw new FirebaseServiceError('Firebase service is in error state', 'app');
71
+ }
50
72
  if (this.firebaseApp)
51
73
  return this.firebaseApp;
52
- const existingApps = getApps();
53
- if (existingApps.length) {
54
- this.firebaseApp = existingApps[0];
74
+ try {
75
+ this.status = FirebaseServiceStatus.INITIALIZING;
76
+ const existingApps = getApps();
77
+ if (existingApps.length) {
78
+ this.firebaseApp = existingApps[0];
79
+ }
80
+ else {
81
+ this.firebaseApp = initializeApp(firebaseConfig);
82
+ console.log(`${firebaseConfig.projectId} initialized on ${this.isBrowser ? 'client' : 'server'}`);
83
+ }
84
+ this.initializeFirestoreInstance();
85
+ this.status = FirebaseServiceStatus.INITIALIZED;
86
+ return this.firebaseApp;
55
87
  }
56
- else {
57
- this.firebaseApp = initializeApp(firebaseConfig);
58
- console.log(`${firebaseConfig.projectId} initialized on ${this.isBrowser ? 'client' : 'server'}`);
88
+ catch (error) {
89
+ this.status = FirebaseServiceStatus.ERROR;
90
+ this.initializationError = error instanceof Error ? error : new Error(String(error));
91
+ throw new FirebaseServiceError('Failed to initialize Firebase app', 'app');
59
92
  }
60
- this.initializeFirestoreInstance();
61
- return this.firebaseApp;
62
93
  }
63
94
  /**
64
95
  * Initializes Firestore with persistent cache and multi-tab support.
65
96
  * Only runs in browser environment.
66
97
  *
67
98
  * @private
99
+ * @throws {FirebaseServiceError} If Firestore initialization fails
68
100
  */
69
101
  initializeFirestoreInstance() {
70
102
  if (this.db || !this.isBrowser)
71
103
  return;
72
- this.db = initializeFirestore(this.firebaseApp, {
73
- localCache: persistentLocalCache({
74
- cacheSizeBytes: CACHE_SIZE_UNLIMITED,
75
- tabManager: persistentMultipleTabManager()
76
- }),
77
- });
78
- const indexManager = getPersistentCacheIndexManager(this.db);
79
- if (indexManager) {
80
- enablePersistentCacheIndexAutoCreation(indexManager);
81
- console.log('Firestore persistent cache indexing is enabled');
104
+ try {
105
+ this.db = initializeFirestore(this.firebaseApp, {
106
+ localCache: persistentLocalCache({
107
+ cacheSizeBytes: CACHE_SIZE_UNLIMITED,
108
+ tabManager: persistentMultipleTabManager()
109
+ })
110
+ });
111
+ const indexManager = getPersistentCacheIndexManager(this.db);
112
+ if (indexManager) {
113
+ enablePersistentCacheIndexAutoCreation(indexManager);
114
+ console.log('Firestore persistent cache indexing is enabled');
115
+ }
116
+ else {
117
+ console.warn('Failed to initialize the Firestore cache index manager');
118
+ }
82
119
  }
83
- else {
84
- console.warn('Failed to initialize the Firestore cache index manager');
120
+ catch (error) {
121
+ throw new FirebaseServiceError('Failed to initialize Firestore', 'firestore');
85
122
  }
86
123
  }
87
124
  /**
88
125
  * Gets the Firestore instance, initializing it if necessary.
89
126
  *
90
127
  * @returns {Firestore} The Firestore instance
128
+ * @throws {FirebaseServiceError} If Firestore is not available
91
129
  */
92
130
  getDbInstance() {
93
- if (!this.db)
131
+ if (!this.db) {
94
132
  this.getFirebaseApp();
133
+ if (!this.db) {
134
+ throw new FirebaseServiceError('Firestore instance not available', 'firestore');
135
+ }
136
+ }
95
137
  return this.db;
96
138
  }
97
139
  /**
98
140
  * Gets the Authentication instance, initializing it if necessary.
99
141
  *
100
142
  * @returns {Auth} The Authentication instance
143
+ * @throws {FirebaseServiceError} If Auth initialization fails
101
144
  */
102
145
  getAuthInstance() {
103
- if (!this.auth)
104
- this.auth = getAuth(this.getFirebaseApp());
105
- return this.auth;
146
+ try {
147
+ if (!this.auth) {
148
+ this.auth = getAuth(this.getFirebaseApp());
149
+ }
150
+ return this.auth;
151
+ }
152
+ catch (error) {
153
+ throw new FirebaseServiceError('Failed to initialize Auth', 'auth');
154
+ }
106
155
  }
107
156
  /**
108
157
  * Gets the Cloud Functions instance, initializing it if necessary.
109
158
  *
110
159
  * @returns {Functions} The Cloud Functions instance
160
+ * @throws {FirebaseServiceError} If Functions initialization fails
111
161
  */
112
162
  getFunctionsInstance() {
113
- if (!this.functions)
114
- this.functions = getFunctions(this.getFirebaseApp());
115
- return this.functions;
163
+ try {
164
+ if (!this.functions) {
165
+ this.functions = getFunctions(this.getFirebaseApp());
166
+ }
167
+ return this.functions;
168
+ }
169
+ catch (error) {
170
+ throw new FirebaseServiceError('Failed to initialize Functions', 'functions');
171
+ }
116
172
  }
117
173
  /**
118
174
  * Gets the Realtime Database instance, initializing it if necessary.
119
175
  *
120
176
  * @returns {Database} The Realtime Database instance
177
+ * @throws {FirebaseServiceError} If Database initialization fails
121
178
  */
122
179
  getDatabaseInstance() {
123
- if (!this.database)
124
- this.database = getDatabase(this.getFirebaseApp());
125
- return this.database;
180
+ try {
181
+ if (!this.database) {
182
+ this.database = getDatabase(this.getFirebaseApp());
183
+ }
184
+ return this.database;
185
+ }
186
+ catch (error) {
187
+ throw new FirebaseServiceError('Failed to initialize Database', 'database');
188
+ }
126
189
  }
127
190
  /**
128
191
  * Gets the Storage instance, initializing it if necessary.
129
192
  *
130
193
  * @returns {FirebaseStorage} The Storage instance
194
+ * @throws {FirebaseServiceError} If Storage initialization fails
131
195
  */
132
196
  getStorageInstance() {
133
- if (!this.storage)
134
- this.storage = getStorage(this.getFirebaseApp());
135
- return this.storage;
197
+ try {
198
+ if (!this.storage) {
199
+ this.storage = getStorage(this.getFirebaseApp());
200
+ }
201
+ return this.storage;
202
+ }
203
+ catch (error) {
204
+ throw new FirebaseServiceError('Failed to initialize Storage', 'storage');
205
+ }
206
+ }
207
+ /**
208
+ * Resets the Firebase service to its initial state.
209
+ * Useful for testing or when you need to reinitialize the services.
210
+ *
211
+ * @returns {Promise<void>}
212
+ */
213
+ async reset() {
214
+ this.firebaseApp = null;
215
+ this.db = null;
216
+ this.auth = null;
217
+ this.functions = null;
218
+ this.database = null;
219
+ this.storage = null;
220
+ this.status = FirebaseServiceStatus.UNINITIALIZED;
221
+ this.initializationError = null;
136
222
  }
137
223
  }
138
224
  /**
package/dist/index.d.ts CHANGED
@@ -1,15 +1,23 @@
1
+ export * from './types/index.js';
1
2
  export { firebaseConfig } from './config.js';
2
3
  export { firebaseService } from './firebase.js';
3
- export { firekitUser } from './auth/user.svelte.js';
4
- export { firekitAuth } from './auth/auth.js';
5
- export { presenceService } from './auth/presence.svelte.js';
6
- export { firekitAwaitableDoc } from './firestore/awaitable-doc.svelte.js';
7
- export { firekitDocMutations } from './firestore/document-mutations.svelte.js';
8
- export { firekitCollection } from './firestore/collection.svelte.js';
9
- export { firekitDoc } from './firestore/doc.svelte.js';
10
- export { firekitCollectionGroup } from './firestore/collection-group.svelte.js';
11
- export { firekitBatchMutations } from './firestore/batch-mutations.svelte.js';
12
- export { firekitRealtimeDB } from './realtime/realtime.svelte.js';
13
- export { firekitDownloadUrl } from './storage/download-url.svelte.js';
14
- export { firekitStorageList } from './storage/storage-list.svelte.js';
15
- export { firekitUploadTask } from './storage/upload-task.svelte.js';
4
+ export { firekitUser } from './services/user.svelte.js';
5
+ export { firekitAuth } from './services/auth.js';
6
+ export { firekitPresence } from './services/presence.svelte.js';
7
+ export { firekitDoc, firekitDocOnce, firekitDocWithMetadata } from './services/document.svelte.js';
8
+ export { firekitDocMutations } from './services/mutations.js';
9
+ export { firekitCollection, firekitCollectionGroup, firekitCollectionOnce } from './services/collection.svelte.js';
10
+ export { firekitRealtimeDB, firekitRealtimeList } from './services/realtime.svelte.js';
11
+ export { firekitStorageList, firekitUploadTask, firekitDownloadUrl } from './services/storage.svelte.js';
12
+ export { default as FirebaseApp } from './components/firebase-app.svelte';
13
+ export { default as AuthGuard } from './components/auth-guard.svelte';
14
+ export { default as CustomGuard } from './components/custom-guard.svelte';
15
+ export { default as SignedIn } from './components/signed-in.svelte';
16
+ export { default as SignedOut } from './components/signed-out.svelte';
17
+ export { default as Doc } from './components/Ddoc.svelte';
18
+ export { default as Collection } from './components/Collection.svelte';
19
+ export { default as Node } from './components/Node.svelte';
20
+ export { default as NodeList } from './components/node-list.svelte';
21
+ export { default as StorageList } from './components/storage-list.svelte';
22
+ export { default as DownloadURL } from './components/download-url.svelte';
23
+ export { default as UploadTask } from './components/upload-task.svelte';
package/dist/index.js CHANGED
@@ -1,20 +1,32 @@
1
+ // types
2
+ export * from './types/index.js';
1
3
  // Firebase config
2
4
  export { firebaseConfig } from './config.js';
3
5
  export { firebaseService } from './firebase.js';
4
6
  // auth services
5
- export { firekitUser } from './auth/user.svelte.js';
6
- export { firekitAuth } from './auth/auth.js';
7
- export { presenceService } from './auth/presence.svelte.js';
8
- // firestore services
9
- export { firekitAwaitableDoc } from './firestore/awaitable-doc.svelte.js';
10
- export { firekitDocMutations } from './firestore/document-mutations.svelte.js';
11
- export { firekitCollection } from './firestore/collection.svelte.js';
12
- export { firekitDoc } from './firestore/doc.svelte.js';
13
- export { firekitCollectionGroup } from './firestore/collection-group.svelte.js';
14
- export { firekitBatchMutations } from './firestore/batch-mutations.svelte.js';
7
+ export { firekitUser } from './services/user.svelte.js';
8
+ export { firekitAuth } from './services/auth.js';
9
+ export { firekitPresence } from './services/presence.svelte.js';
10
+ // document services
11
+ export { firekitDoc, firekitDocOnce, firekitDocWithMetadata } from './services/document.svelte.js';
12
+ // mutations services
13
+ export { firekitDocMutations } from './services/mutations.js';
14
+ // collection services
15
+ export { firekitCollection, firekitCollectionGroup, firekitCollectionOnce } from './services/collection.svelte.js';
15
16
  // realtime services
16
- export { firekitRealtimeDB } from './realtime/realtime.svelte.js';
17
- // Storage services
18
- export { firekitDownloadUrl } from './storage/download-url.svelte.js';
19
- export { firekitStorageList } from './storage/storage-list.svelte.js';
20
- export { firekitUploadTask } from './storage/upload-task.svelte.js';
17
+ export { firekitRealtimeDB, firekitRealtimeList } from './services/realtime.svelte.js';
18
+ // storage services
19
+ export { firekitStorageList, firekitUploadTask, firekitDownloadUrl } from './services/storage.svelte.js';
20
+ // Components
21
+ export { default as FirebaseApp } from './components/firebase-app.svelte';
22
+ export { default as AuthGuard } from './components/auth-guard.svelte';
23
+ export { default as CustomGuard } from './components/custom-guard.svelte';
24
+ export { default as SignedIn } from './components/signed-in.svelte';
25
+ export { default as SignedOut } from './components/signed-out.svelte';
26
+ export { default as Doc } from './components/Ddoc.svelte';
27
+ export { default as Collection } from './components/Collection.svelte';
28
+ export { default as Node } from './components/Node.svelte';
29
+ export { default as NodeList } from './components/node-list.svelte';
30
+ export { default as StorageList } from './components/storage-list.svelte';
31
+ export { default as DownloadURL } from './components/download-url.svelte';
32
+ export { default as UploadTask } from './components/upload-task.svelte';