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,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitDocumentMutations
|
|
3
|
-
*/
|
|
4
|
-
import { type DocumentData, type WithFieldValue, type PartialWithFieldValue } from "firebase/firestore";
|
|
5
|
-
/**
|
|
6
|
-
* Response structure for document mutations
|
|
7
|
-
* @interface MutationResponse
|
|
8
|
-
* @template T Document data type
|
|
9
|
-
*/
|
|
10
|
-
interface MutationResponse<T> {
|
|
11
|
-
/** Operation success status */
|
|
12
|
-
success: boolean;
|
|
13
|
-
/** Document data */
|
|
14
|
-
data?: T;
|
|
15
|
-
/** Document ID */
|
|
16
|
-
id?: string;
|
|
17
|
-
/** Error details if operation failed */
|
|
18
|
-
error?: {
|
|
19
|
-
code: string;
|
|
20
|
-
message: string;
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Options for document mutations
|
|
25
|
-
* @interface MutationOptions
|
|
26
|
-
*/
|
|
27
|
-
interface MutationOptions {
|
|
28
|
-
/** Whether to include timestamp fields */
|
|
29
|
-
timestamps?: boolean;
|
|
30
|
-
/** Whether to merge data in set operations */
|
|
31
|
-
merge?: boolean;
|
|
32
|
-
/** Custom document ID for add operations */
|
|
33
|
-
customId?: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Manages Firestore document mutations with automatic timestamps and error handling
|
|
37
|
-
* @class
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* // Add a new document
|
|
41
|
-
* const result = await firekitDocMutations.add('users', {
|
|
42
|
-
* name: 'John Doe',
|
|
43
|
-
* email: 'john@example.com'
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* // Update a document
|
|
47
|
-
* await firekitDocMutations.update('users/123', {
|
|
48
|
-
* name: 'Jane Doe'
|
|
49
|
-
* });
|
|
50
|
-
*
|
|
51
|
-
* // Delete a document
|
|
52
|
-
* await firekitDocMutations.delete('users/123');
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
declare class FirekitDocumentMutations {
|
|
56
|
-
/**
|
|
57
|
-
* Generates timestamp data for document mutations
|
|
58
|
-
* @private
|
|
59
|
-
* @param {boolean} [isNew=true] Whether this is a new document
|
|
60
|
-
* @returns {Record<string, any>} Timestamp data
|
|
61
|
-
*/
|
|
62
|
-
private getTimestampData;
|
|
63
|
-
/**
|
|
64
|
-
* Handles and formats mutation errors
|
|
65
|
-
* @private
|
|
66
|
-
* @param {any} error Error object
|
|
67
|
-
* @returns {MutationResponse<never>} Formatted error response
|
|
68
|
-
*/
|
|
69
|
-
private handleError;
|
|
70
|
-
/**
|
|
71
|
-
* Adds a new document to a collection
|
|
72
|
-
* @template T Document data type
|
|
73
|
-
* @param {string} collectionPath Collection path
|
|
74
|
-
* @param {WithFieldValue<T>} data Document data
|
|
75
|
-
* @param {MutationOptions} [options] Mutation options
|
|
76
|
-
* @returns {Promise<MutationResponse<T>>} Mutation response
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* const result = await firekitDocMutations.add('users', {
|
|
81
|
-
* name: 'John Doe',
|
|
82
|
-
* email: 'john@example.com'
|
|
83
|
-
* }, { timestamps: true, customId: 'custom-id' });
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
add<T extends DocumentData>(collectionPath: string, data: WithFieldValue<T>, options?: MutationOptions): Promise<MutationResponse<T>>;
|
|
87
|
-
/**
|
|
88
|
-
* Sets document data at specified path
|
|
89
|
-
* @template T Document data type
|
|
90
|
-
* @param {string} path Document path
|
|
91
|
-
* @param {WithFieldValue<T>} data Document data
|
|
92
|
-
* @param {MutationOptions} [options] Mutation options
|
|
93
|
-
* @returns {Promise<MutationResponse<T>>} Mutation response
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```typescript
|
|
97
|
-
* const result = await firekitDocMutations.set('users/123', {
|
|
98
|
-
* name: 'John Doe',
|
|
99
|
-
* email: 'john@example.com'
|
|
100
|
-
* }, { merge: true });
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
set<T extends DocumentData>(path: string, data: WithFieldValue<T>, options?: MutationOptions): Promise<MutationResponse<T>>;
|
|
104
|
-
/**
|
|
105
|
-
* Updates a document at specified path
|
|
106
|
-
* @template T Document data type
|
|
107
|
-
* @param {string} path Document path
|
|
108
|
-
* @param {PartialWithFieldValue<T>} data Update data
|
|
109
|
-
* @param {MutationOptions} [options] Mutation options
|
|
110
|
-
* @returns {Promise<MutationResponse<Partial<T>>>} Mutation response
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* const result = await firekitDocMutations.update('users/123', {
|
|
115
|
-
* name: 'Jane Doe'
|
|
116
|
-
* });
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
update<T extends DocumentData>(path: string, data: PartialWithFieldValue<T>, options?: MutationOptions): Promise<MutationResponse<Partial<T>>>;
|
|
120
|
-
/**
|
|
121
|
-
* Deletes a document at specified path
|
|
122
|
-
* @param {string} path Document path
|
|
123
|
-
* @returns {Promise<MutationResponse<void>>} Mutation response
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const result = await firekitDocMutations.delete('users/123');
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
delete(path: string): Promise<MutationResponse<void>>;
|
|
131
|
-
/**
|
|
132
|
-
* Checks if a document exists at specified path
|
|
133
|
-
* @param {string} path Document path
|
|
134
|
-
* @returns {Promise<boolean>} Whether document exists
|
|
135
|
-
*
|
|
136
|
-
* @example
|
|
137
|
-
* ```typescript
|
|
138
|
-
* const exists = await firekitDocMutations.exists('users/123');
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
exists(path: string): Promise<boolean>;
|
|
142
|
-
/**
|
|
143
|
-
* Gets a document at specified path
|
|
144
|
-
* @template T Document data type
|
|
145
|
-
* @param {string} path Document path
|
|
146
|
-
* @returns {Promise<MutationResponse<T>>} Mutation response with document data
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```typescript
|
|
150
|
-
* const result = await firekitDocMutations.getDoc<UserData>('users/123');
|
|
151
|
-
* if (result.success) {
|
|
152
|
-
* console.log(result.data);
|
|
153
|
-
* }
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
getDoc<T extends DocumentData>(path: string): Promise<MutationResponse<T>>;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Pre-initialized instance of FirekitDocumentMutations
|
|
160
|
-
* @const
|
|
161
|
-
* @type {FirekitDocumentMutations}
|
|
162
|
-
*/
|
|
163
|
-
export declare const firekitDocMutations: FirekitDocumentMutations;
|
|
164
|
-
export {};
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitDocumentMutations
|
|
3
|
-
*/
|
|
4
|
-
import { addDoc, setDoc, updateDoc, deleteDoc, doc, getDoc, collection, serverTimestamp, } from "firebase/firestore";
|
|
5
|
-
import { firebaseService } from "../firebase.js";
|
|
6
|
-
import { firekitUser } from "../auth/user.svelte.js";
|
|
7
|
-
/**
|
|
8
|
-
* Manages Firestore document mutations with automatic timestamps and error handling
|
|
9
|
-
* @class
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* // Add a new document
|
|
13
|
-
* const result = await firekitDocMutations.add('users', {
|
|
14
|
-
* name: 'John Doe',
|
|
15
|
-
* email: 'john@example.com'
|
|
16
|
-
* });
|
|
17
|
-
*
|
|
18
|
-
* // Update a document
|
|
19
|
-
* await firekitDocMutations.update('users/123', {
|
|
20
|
-
* name: 'Jane Doe'
|
|
21
|
-
* });
|
|
22
|
-
*
|
|
23
|
-
* // Delete a document
|
|
24
|
-
* await firekitDocMutations.delete('users/123');
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
class FirekitDocumentMutations {
|
|
28
|
-
/**
|
|
29
|
-
* Generates timestamp data for document mutations
|
|
30
|
-
* @private
|
|
31
|
-
* @param {boolean} [isNew=true] Whether this is a new document
|
|
32
|
-
* @returns {Record<string, any>} Timestamp data
|
|
33
|
-
*/
|
|
34
|
-
getTimestampData(isNew = true) {
|
|
35
|
-
const timestamps = {
|
|
36
|
-
updatedAt: serverTimestamp(),
|
|
37
|
-
updatedBy: firekitUser.uid,
|
|
38
|
-
};
|
|
39
|
-
if (isNew) {
|
|
40
|
-
timestamps.createdAt = serverTimestamp();
|
|
41
|
-
timestamps.createdBy = firekitUser.uid;
|
|
42
|
-
}
|
|
43
|
-
return timestamps;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Handles and formats mutation errors
|
|
47
|
-
* @private
|
|
48
|
-
* @param {any} error Error object
|
|
49
|
-
* @returns {MutationResponse<never>} Formatted error response
|
|
50
|
-
*/
|
|
51
|
-
handleError(error) {
|
|
52
|
-
console.error('Firestore mutation error:', error);
|
|
53
|
-
return {
|
|
54
|
-
success: false,
|
|
55
|
-
error: {
|
|
56
|
-
code: error.code || 'unknown_error',
|
|
57
|
-
message: error.message || 'An unknown error occurred'
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Adds a new document to a collection
|
|
63
|
-
* @template T Document data type
|
|
64
|
-
* @param {string} collectionPath Collection path
|
|
65
|
-
* @param {WithFieldValue<T>} data Document data
|
|
66
|
-
* @param {MutationOptions} [options] Mutation options
|
|
67
|
-
* @returns {Promise<MutationResponse<T>>} Mutation response
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* const result = await firekitDocMutations.add('users', {
|
|
72
|
-
* name: 'John Doe',
|
|
73
|
-
* email: 'john@example.com'
|
|
74
|
-
* }, { timestamps: true, customId: 'custom-id' });
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
async add(collectionPath, data, options = { timestamps: true }) {
|
|
78
|
-
try {
|
|
79
|
-
const firestore = firebaseService.getDbInstance();
|
|
80
|
-
const colRef = collection(firestore, collectionPath);
|
|
81
|
-
let dataToAdd = {
|
|
82
|
-
...data,
|
|
83
|
-
...(options.timestamps && this.getTimestampData()),
|
|
84
|
-
};
|
|
85
|
-
let docRef;
|
|
86
|
-
if (options.customId) {
|
|
87
|
-
docRef = doc(colRef, options.customId);
|
|
88
|
-
dataToAdd = { ...dataToAdd, id: docRef.id };
|
|
89
|
-
await setDoc(docRef, dataToAdd);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
docRef = await addDoc(colRef, dataToAdd);
|
|
93
|
-
dataToAdd = { ...dataToAdd, id: docRef.id };
|
|
94
|
-
await setDoc(docRef, dataToAdd);
|
|
95
|
-
}
|
|
96
|
-
return {
|
|
97
|
-
success: true,
|
|
98
|
-
id: docRef.id,
|
|
99
|
-
data: { ...dataToAdd, id: docRef.id }
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
return this.handleError(error);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Sets document data at specified path
|
|
108
|
-
* @template T Document data type
|
|
109
|
-
* @param {string} path Document path
|
|
110
|
-
* @param {WithFieldValue<T>} data Document data
|
|
111
|
-
* @param {MutationOptions} [options] Mutation options
|
|
112
|
-
* @returns {Promise<MutationResponse<T>>} Mutation response
|
|
113
|
-
*
|
|
114
|
-
* @example
|
|
115
|
-
* ```typescript
|
|
116
|
-
* const result = await firekitDocMutations.set('users/123', {
|
|
117
|
-
* name: 'John Doe',
|
|
118
|
-
* email: 'john@example.com'
|
|
119
|
-
* }, { merge: true });
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
async set(path, data, options = { merge: false, timestamps: true }) {
|
|
123
|
-
try {
|
|
124
|
-
const firestore = firebaseService.getDbInstance();
|
|
125
|
-
let docRef;
|
|
126
|
-
if (path.includes('/')) {
|
|
127
|
-
docRef = doc(firestore, path);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
const [collectionPath, documentId] = path.split('/');
|
|
131
|
-
docRef = doc(collection(firestore, collectionPath), documentId);
|
|
132
|
-
}
|
|
133
|
-
const dataToSet = {
|
|
134
|
-
...data,
|
|
135
|
-
...(options.timestamps && this.getTimestampData()),
|
|
136
|
-
id: docRef.id,
|
|
137
|
-
};
|
|
138
|
-
await setDoc(docRef, dataToSet, { merge: options.merge });
|
|
139
|
-
return {
|
|
140
|
-
success: true,
|
|
141
|
-
id: docRef.id,
|
|
142
|
-
data: dataToSet
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
return this.handleError(error);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Updates a document at specified path
|
|
151
|
-
* @template T Document data type
|
|
152
|
-
* @param {string} path Document path
|
|
153
|
-
* @param {PartialWithFieldValue<T>} data Update data
|
|
154
|
-
* @param {MutationOptions} [options] Mutation options
|
|
155
|
-
* @returns {Promise<MutationResponse<Partial<T>>>} Mutation response
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* ```typescript
|
|
159
|
-
* const result = await firekitDocMutations.update('users/123', {
|
|
160
|
-
* name: 'Jane Doe'
|
|
161
|
-
* });
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
async update(path, data, options = { timestamps: true }) {
|
|
165
|
-
try {
|
|
166
|
-
const firestore = firebaseService.getDbInstance();
|
|
167
|
-
const docRef = doc(firestore, path);
|
|
168
|
-
const dataToUpdate = {
|
|
169
|
-
...data,
|
|
170
|
-
...(options.timestamps && this.getTimestampData(false)),
|
|
171
|
-
};
|
|
172
|
-
await updateDoc(docRef, dataToUpdate);
|
|
173
|
-
return {
|
|
174
|
-
success: true,
|
|
175
|
-
id: docRef.id,
|
|
176
|
-
data: dataToUpdate
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
return this.handleError(error);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Deletes a document at specified path
|
|
185
|
-
* @param {string} path Document path
|
|
186
|
-
* @returns {Promise<MutationResponse<void>>} Mutation response
|
|
187
|
-
*
|
|
188
|
-
* @example
|
|
189
|
-
* ```typescript
|
|
190
|
-
* const result = await firekitDocMutations.delete('users/123');
|
|
191
|
-
* ```
|
|
192
|
-
*/
|
|
193
|
-
async delete(path) {
|
|
194
|
-
try {
|
|
195
|
-
const firestore = firebaseService.getDbInstance();
|
|
196
|
-
const docRef = doc(firestore, path);
|
|
197
|
-
await deleteDoc(docRef);
|
|
198
|
-
return {
|
|
199
|
-
success: true,
|
|
200
|
-
id: docRef.id
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
catch (error) {
|
|
204
|
-
return this.handleError(error);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Checks if a document exists at specified path
|
|
209
|
-
* @param {string} path Document path
|
|
210
|
-
* @returns {Promise<boolean>} Whether document exists
|
|
211
|
-
*
|
|
212
|
-
* @example
|
|
213
|
-
* ```typescript
|
|
214
|
-
* const exists = await firekitDocMutations.exists('users/123');
|
|
215
|
-
* ```
|
|
216
|
-
*/
|
|
217
|
-
async exists(path) {
|
|
218
|
-
try {
|
|
219
|
-
const firestore = firebaseService.getDbInstance();
|
|
220
|
-
const docRef = doc(firestore, path);
|
|
221
|
-
const docSnap = await getDoc(docRef);
|
|
222
|
-
return docSnap.exists();
|
|
223
|
-
}
|
|
224
|
-
catch (error) {
|
|
225
|
-
console.error('Error checking document existence:', error);
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* Gets a document at specified path
|
|
231
|
-
* @template T Document data type
|
|
232
|
-
* @param {string} path Document path
|
|
233
|
-
* @returns {Promise<MutationResponse<T>>} Mutation response with document data
|
|
234
|
-
*
|
|
235
|
-
* @example
|
|
236
|
-
* ```typescript
|
|
237
|
-
* const result = await firekitDocMutations.getDoc<UserData>('users/123');
|
|
238
|
-
* if (result.success) {
|
|
239
|
-
* console.log(result.data);
|
|
240
|
-
* }
|
|
241
|
-
* ```
|
|
242
|
-
*/
|
|
243
|
-
async getDoc(path) {
|
|
244
|
-
try {
|
|
245
|
-
const firestore = firebaseService.getDbInstance();
|
|
246
|
-
const docRef = doc(firestore, path);
|
|
247
|
-
const docSnap = await getDoc(docRef);
|
|
248
|
-
if (!docSnap.exists()) {
|
|
249
|
-
return {
|
|
250
|
-
success: false,
|
|
251
|
-
error: {
|
|
252
|
-
code: 'not_found',
|
|
253
|
-
message: 'Document does not exist'
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
return {
|
|
258
|
-
success: true,
|
|
259
|
-
id: docSnap.id,
|
|
260
|
-
data: { id: docSnap.id, ...docSnap.data() }
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
catch (error) {
|
|
264
|
-
return this.handleError(error);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Pre-initialized instance of FirekitDocumentMutations
|
|
270
|
-
* @const
|
|
271
|
-
* @type {FirekitDocumentMutations}
|
|
272
|
-
*/
|
|
273
|
-
export const firekitDocMutations = new FirekitDocumentMutations();
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitDownloadUrl
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Manages Firebase Storage download URL fetching with reactive state
|
|
6
|
-
* @class
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* // Get download URL for image
|
|
11
|
-
* const imageUrl = firekitDownloadUrl('images/photo.jpg');
|
|
12
|
-
*
|
|
13
|
-
* // Access reactive state
|
|
14
|
-
* if (imageUrl.loading) {
|
|
15
|
-
* console.log('Loading URL...');
|
|
16
|
-
* } else if (imageUrl.url) {
|
|
17
|
-
* console.log('Download URL:', imageUrl.url);
|
|
18
|
-
* }
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
declare class FirekitDownloadUrl {
|
|
22
|
-
/** Current download URL */
|
|
23
|
-
private _url;
|
|
24
|
-
/** Loading state */
|
|
25
|
-
private _loading;
|
|
26
|
-
/** Error state */
|
|
27
|
-
private _error;
|
|
28
|
-
/** Storage reference */
|
|
29
|
-
private storageRef;
|
|
30
|
-
/**
|
|
31
|
-
* Creates a download URL fetcher
|
|
32
|
-
* @param {string} path Storage path to file
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```typescript
|
|
36
|
-
* const url = new FirekitDownloadUrl('documents/file.pdf');
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
constructor(path: string);
|
|
40
|
-
/**
|
|
41
|
-
* Initializes download URL fetching
|
|
42
|
-
* @private
|
|
43
|
-
* @param {string} path Storage path
|
|
44
|
-
*/
|
|
45
|
-
private initializeDownload;
|
|
46
|
-
/** Gets current download URL */
|
|
47
|
-
get url(): string | null;
|
|
48
|
-
/** Gets loading state */
|
|
49
|
-
get loading(): boolean;
|
|
50
|
-
/** Gets error state */
|
|
51
|
-
get error(): Error | null;
|
|
52
|
-
/**
|
|
53
|
-
* Refreshes download URL
|
|
54
|
-
* Useful when file content has changed
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* ```typescript
|
|
58
|
-
* // Refresh URL after file update
|
|
59
|
-
* await uploadNewVersion();
|
|
60
|
-
* imageUrl.refresh();
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
refresh(): void;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Creates a download URL fetcher
|
|
67
|
-
* @param {string} path Storage path to file
|
|
68
|
-
* @returns {FirekitDownloadUrl} Download URL fetcher instance
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const imageUrl = firekitDownloadUrl('images/profile.jpg');
|
|
73
|
-
*
|
|
74
|
-
* // Use in template
|
|
75
|
-
* {#if imageUrl.loading}
|
|
76
|
-
* <p>Loading...</p>
|
|
77
|
-
* {:else if imageUrl.url}
|
|
78
|
-
* <img src={imageUrl.url} alt="Profile" />
|
|
79
|
-
* {/if}
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export declare function firekitDownloadUrl(path: string): FirekitDownloadUrl;
|
|
83
|
-
export {};
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module FirekitDownloadUrl
|
|
3
|
-
*/
|
|
4
|
-
import { ref, getDownloadURL } from "firebase/storage";
|
|
5
|
-
import { browser } from "$app/environment";
|
|
6
|
-
import { firebaseService } from "../firebase.js";
|
|
7
|
-
/**
|
|
8
|
-
* Manages Firebase Storage download URL fetching with reactive state
|
|
9
|
-
* @class
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* // Get download URL for image
|
|
14
|
-
* const imageUrl = firekitDownloadUrl('images/photo.jpg');
|
|
15
|
-
*
|
|
16
|
-
* // Access reactive state
|
|
17
|
-
* if (imageUrl.loading) {
|
|
18
|
-
* console.log('Loading URL...');
|
|
19
|
-
* } else if (imageUrl.url) {
|
|
20
|
-
* console.log('Download URL:', imageUrl.url);
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
class FirekitDownloadUrl {
|
|
25
|
-
/** Current download URL */
|
|
26
|
-
_url = $state(null);
|
|
27
|
-
/** Loading state */
|
|
28
|
-
_loading = $state(true);
|
|
29
|
-
/** Error state */
|
|
30
|
-
_error = $state(null);
|
|
31
|
-
/** Storage reference */
|
|
32
|
-
storageRef = null;
|
|
33
|
-
/**
|
|
34
|
-
* Creates a download URL fetcher
|
|
35
|
-
* @param {string} path Storage path to file
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const url = new FirekitDownloadUrl('documents/file.pdf');
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
constructor(path) {
|
|
43
|
-
if (browser) {
|
|
44
|
-
this.initializeDownload(path);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Initializes download URL fetching
|
|
49
|
-
* @private
|
|
50
|
-
* @param {string} path Storage path
|
|
51
|
-
*/
|
|
52
|
-
async initializeDownload(path) {
|
|
53
|
-
try {
|
|
54
|
-
const storage = firebaseService.getStorageInstance();
|
|
55
|
-
this.storageRef = ref(storage, path);
|
|
56
|
-
this._url = await getDownloadURL(this.storageRef);
|
|
57
|
-
this._loading = false;
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
this._error = error;
|
|
61
|
-
this._loading = false;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/** Gets current download URL */
|
|
65
|
-
get url() {
|
|
66
|
-
return this._url;
|
|
67
|
-
}
|
|
68
|
-
/** Gets loading state */
|
|
69
|
-
get loading() {
|
|
70
|
-
return this._loading;
|
|
71
|
-
}
|
|
72
|
-
/** Gets error state */
|
|
73
|
-
get error() {
|
|
74
|
-
return this._error;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Refreshes download URL
|
|
78
|
-
* Useful when file content has changed
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```typescript
|
|
82
|
-
* // Refresh URL after file update
|
|
83
|
-
* await uploadNewVersion();
|
|
84
|
-
* imageUrl.refresh();
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
refresh() {
|
|
88
|
-
if (this.storageRef) {
|
|
89
|
-
this._loading = true;
|
|
90
|
-
this._error = null;
|
|
91
|
-
this.initializeDownload(this.storageRef.fullPath);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Creates a download URL fetcher
|
|
97
|
-
* @param {string} path Storage path to file
|
|
98
|
-
* @returns {FirekitDownloadUrl} Download URL fetcher instance
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* const imageUrl = firekitDownloadUrl('images/profile.jpg');
|
|
103
|
-
*
|
|
104
|
-
* // Use in template
|
|
105
|
-
* {#if imageUrl.loading}
|
|
106
|
-
* <p>Loading...</p>
|
|
107
|
-
* {:else if imageUrl.url}
|
|
108
|
-
* <img src={imageUrl.url} alt="Profile" />
|
|
109
|
-
* {/if}
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
export function firekitDownloadUrl(path) {
|
|
113
|
-
return new FirekitDownloadUrl(path);
|
|
114
|
-
}
|