svelte-firekit 0.0.21 → 0.0.22
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 +218 -55
- package/dist/auth/auth.d.ts +84 -1
- package/dist/auth/auth.js +89 -3
- package/dist/auth/presence.svelte.d.ts +65 -0
- package/dist/auth/presence.svelte.js +42 -0
- package/dist/auth/user.svelte.d.ts +22 -4
- package/dist/auth/user.svelte.js +25 -4
- package/dist/config.d.ts +10 -0
- package/dist/config.js +63 -0
- package/dist/firebase.d.ts +69 -0
- package/dist/firebase.js +71 -3
- package/dist/firestore/awaitable-doc.svelte.d.ts +126 -0
- package/dist/firestore/awaitable-doc.svelte.js +126 -0
- package/dist/firestore/collection.svelte.d.ts +80 -1
- package/dist/firestore/collection.svelte.js +79 -0
- package/dist/firestore/doc.svelte.d.ts +75 -1
- package/dist/firestore/doc.svelte.js +74 -1
- package/dist/firestore/document-mutations.svelte.d.ts +137 -0
- package/dist/firestore/document-mutations.svelte.js +123 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/realtime/realtime.svelte.d.ts +145 -0
- package/dist/realtime/realtime.svelte.js +113 -14
- package/dist/storage/download-url.svelte.d.ts +69 -0
- package/dist/storage/download-url.svelte.js +69 -0
- package/dist/storage/storage-list.svelte.d.ts +72 -0
- package/dist/storage/storage-list.svelte.js +72 -0
- package/dist/storage/upload-task.svelte.d.ts +71 -0
- package/dist/storage/upload-task.svelte.js +71 -0
- package/package.json +1 -1
|
@@ -1,20 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module FirekitUploadTask
|
|
3
|
+
*/
|
|
1
4
|
import { ref, uploadBytesResumable, getDownloadURL } from "firebase/storage";
|
|
2
5
|
import { browser } from "$app/environment";
|
|
3
6
|
import { firebaseService } from "../firebase.js";
|
|
7
|
+
/**
|
|
8
|
+
* Manages Firebase Storage upload operations with reactive state and progress tracking
|
|
9
|
+
* @class
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Create upload task
|
|
14
|
+
* const upload = firekitUploadTask('images/photo.jpg', file);
|
|
15
|
+
*
|
|
16
|
+
* // Monitor progress
|
|
17
|
+
* console.log(`Upload progress: ${upload.progress}%`);
|
|
18
|
+
*
|
|
19
|
+
* // Control upload
|
|
20
|
+
* upload.pause();
|
|
21
|
+
* upload.resume();
|
|
22
|
+
* upload.cancel();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
4
25
|
class FirekitUploadTask {
|
|
26
|
+
/** Upload progress percentage */
|
|
5
27
|
_progress = $state(0);
|
|
28
|
+
/** Error state */
|
|
6
29
|
_error = $state(null);
|
|
30
|
+
/** Current upload snapshot */
|
|
7
31
|
_snapshot = $state(null);
|
|
32
|
+
/** Download URL of uploaded file */
|
|
8
33
|
_downloadURL = $state(null);
|
|
34
|
+
/** Upload completion state */
|
|
9
35
|
_completed = $state(false);
|
|
36
|
+
/** Upload task reference */
|
|
10
37
|
uploadTask = null;
|
|
38
|
+
/** Storage reference */
|
|
11
39
|
storageRef = null;
|
|
40
|
+
/** Derived download URL */
|
|
12
41
|
URLdownload = $derived(this._downloadURL);
|
|
42
|
+
/**
|
|
43
|
+
* Creates an upload task
|
|
44
|
+
* @param {string} path Storage path for upload
|
|
45
|
+
* @param {File} file File to upload
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const task = new FirekitUploadTask('documents/report.pdf', file);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
13
52
|
constructor(path, file) {
|
|
14
53
|
if (browser) {
|
|
15
54
|
this.initializeUpload(path, file);
|
|
16
55
|
}
|
|
17
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Initializes file upload
|
|
59
|
+
* @private
|
|
60
|
+
* @param {string} path Storage path
|
|
61
|
+
* @param {File} file File to upload
|
|
62
|
+
*/
|
|
18
63
|
initializeUpload(path, file) {
|
|
19
64
|
try {
|
|
20
65
|
const storage = firebaseService.getStorageInstance();
|
|
@@ -37,31 +82,57 @@ class FirekitUploadTask {
|
|
|
37
82
|
this._error = error;
|
|
38
83
|
}
|
|
39
84
|
}
|
|
85
|
+
/** Pauses upload */
|
|
40
86
|
pause() {
|
|
41
87
|
this.uploadTask?.pause();
|
|
42
88
|
}
|
|
89
|
+
/** Resumes upload */
|
|
43
90
|
resume() {
|
|
44
91
|
this.uploadTask?.resume();
|
|
45
92
|
}
|
|
93
|
+
/** Cancels upload */
|
|
46
94
|
cancel() {
|
|
47
95
|
this.uploadTask?.cancel();
|
|
48
96
|
}
|
|
97
|
+
/** Gets upload progress percentage */
|
|
49
98
|
get progress() {
|
|
50
99
|
return this._progress;
|
|
51
100
|
}
|
|
101
|
+
/** Gets error state */
|
|
52
102
|
get error() {
|
|
53
103
|
return this._error;
|
|
54
104
|
}
|
|
105
|
+
/** Gets current upload snapshot */
|
|
55
106
|
get snapshot() {
|
|
56
107
|
return this._snapshot;
|
|
57
108
|
}
|
|
109
|
+
/** Gets download URL */
|
|
58
110
|
get downloadURL() {
|
|
59
111
|
return this._downloadURL;
|
|
60
112
|
}
|
|
113
|
+
/** Gets completion state */
|
|
61
114
|
get completed() {
|
|
62
115
|
return this._completed;
|
|
63
116
|
}
|
|
64
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Creates an upload task
|
|
120
|
+
* @param {string} path Storage path for upload
|
|
121
|
+
* @param {File} file File to upload
|
|
122
|
+
* @returns {FirekitUploadTask} Upload task instance
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const uploadTask = firekitUploadTask('images/profile.jpg', imageFile);
|
|
127
|
+
*
|
|
128
|
+
* // Template usage
|
|
129
|
+
* {#if !uploadTask.completed}
|
|
130
|
+
* <progress value={uploadTask.progress} max="100" />
|
|
131
|
+
* {:else}
|
|
132
|
+
* <img src={uploadTask.downloadURL} alt="Uploaded file" />
|
|
133
|
+
* {/if}
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
65
136
|
export function firekitUploadTask(path, file) {
|
|
66
137
|
return new FirekitUploadTask(path, file);
|
|
67
138
|
}
|