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
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
|
|
42
|
-
if (
|
|
43
|
-
throw Error(
|
|
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) {
|
package/dist/firebase.d.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { type
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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():
|
|
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():
|
|
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():
|
|
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():
|
|
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():
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
this.
|
|
58
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
84
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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 './
|
|
4
|
-
export { firekitAuth } from './
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export { firekitDocMutations } from './
|
|
8
|
-
export { firekitCollection } from './
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
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 './
|
|
6
|
-
export { firekitAuth } from './
|
|
7
|
-
export {
|
|
8
|
-
//
|
|
9
|
-
export {
|
|
10
|
-
|
|
11
|
-
export {
|
|
12
|
-
|
|
13
|
-
export { firekitCollectionGroup } from './
|
|
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 './
|
|
17
|
-
//
|
|
18
|
-
export { firekitDownloadUrl } from './storage
|
|
19
|
-
|
|
20
|
-
export {
|
|
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';
|