svelte-firekit 0.0.21 → 0.0.23
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 +210 -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-group.svelte.d.ts +78 -0
- package/dist/firestore/collection-group.svelte.js +120 -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 +3 -2
- package/dist/index.js +3 -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,17 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module FirekitStorageList
|
|
3
|
+
*/
|
|
1
4
|
import { ref, listAll } from "firebase/storage";
|
|
2
5
|
import { browser } from "$app/environment";
|
|
3
6
|
import { firebaseService } from "../firebase.js";
|
|
7
|
+
/**
|
|
8
|
+
* Manages Firebase Storage directory listing with reactive state
|
|
9
|
+
* @class
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // List contents of images directory
|
|
14
|
+
* const imagesList = firekitStorageList('images');
|
|
15
|
+
*
|
|
16
|
+
* // Access items and folders
|
|
17
|
+
* console.log('Files:', imagesList.items);
|
|
18
|
+
* console.log('Folders:', imagesList.prefixes);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
4
21
|
class FirekitStorageList {
|
|
22
|
+
/** List of files in directory */
|
|
5
23
|
_items = $state([]);
|
|
24
|
+
/** List of subdirectories */
|
|
6
25
|
_prefixes = $state([]);
|
|
26
|
+
/** Loading state */
|
|
7
27
|
_loading = $state(true);
|
|
28
|
+
/** Error state */
|
|
8
29
|
_error = $state(null);
|
|
30
|
+
/** Storage reference */
|
|
9
31
|
storageRef = null;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a storage directory lister
|
|
34
|
+
* @param {string} path Storage directory path
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const list = new FirekitStorageList('uploads/2024');
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
10
41
|
constructor(path) {
|
|
11
42
|
if (browser) {
|
|
12
43
|
this.initializeList(path);
|
|
13
44
|
}
|
|
14
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Initializes directory listing
|
|
48
|
+
* @private
|
|
49
|
+
* @param {string} path Storage directory path
|
|
50
|
+
*/
|
|
15
51
|
async initializeList(path) {
|
|
16
52
|
try {
|
|
17
53
|
const storage = firebaseService.getStorageInstance();
|
|
@@ -26,18 +62,33 @@ class FirekitStorageList {
|
|
|
26
62
|
this._loading = false;
|
|
27
63
|
}
|
|
28
64
|
}
|
|
65
|
+
/** Gets list of files */
|
|
29
66
|
get items() {
|
|
30
67
|
return this._items;
|
|
31
68
|
}
|
|
69
|
+
/** Gets list of subdirectories */
|
|
32
70
|
get prefixes() {
|
|
33
71
|
return this._prefixes;
|
|
34
72
|
}
|
|
73
|
+
/** Gets loading state */
|
|
35
74
|
get loading() {
|
|
36
75
|
return this._loading;
|
|
37
76
|
}
|
|
77
|
+
/** Gets error state */
|
|
38
78
|
get error() {
|
|
39
79
|
return this._error;
|
|
40
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Refreshes directory listing
|
|
83
|
+
* Useful when directory contents have changed
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // Refresh after upload
|
|
88
|
+
* await uploadFile('images/new.jpg');
|
|
89
|
+
* imagesList.refresh();
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
41
92
|
refresh() {
|
|
42
93
|
if (this.storageRef) {
|
|
43
94
|
this._loading = true;
|
|
@@ -46,6 +97,27 @@ class FirekitStorageList {
|
|
|
46
97
|
}
|
|
47
98
|
}
|
|
48
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* Creates a storage directory lister
|
|
102
|
+
* @param {string} path Storage directory path
|
|
103
|
+
* @returns {FirekitStorageList} Storage list instance
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const documents = firekitStorageList('documents');
|
|
108
|
+
*
|
|
109
|
+
* // Use in template
|
|
110
|
+
* {#if documents.loading}
|
|
111
|
+
* <p>Loading...</p>
|
|
112
|
+
* {:else}
|
|
113
|
+
* <ul>
|
|
114
|
+
* {#each documents.items as item}
|
|
115
|
+
* <li>{item.name}</li>
|
|
116
|
+
* {/each}
|
|
117
|
+
* </ul>
|
|
118
|
+
* {/if}
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
49
121
|
export function firekitStorageList(path) {
|
|
50
122
|
return new FirekitStorageList(path);
|
|
51
123
|
}
|
|
@@ -1,23 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module FirekitUploadTask
|
|
3
|
+
*/
|
|
1
4
|
import { type UploadTaskSnapshot } from "firebase/storage";
|
|
5
|
+
/**
|
|
6
|
+
* Manages Firebase Storage upload operations with reactive state and progress tracking
|
|
7
|
+
* @class
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // Create upload task
|
|
12
|
+
* const upload = firekitUploadTask('images/photo.jpg', file);
|
|
13
|
+
*
|
|
14
|
+
* // Monitor progress
|
|
15
|
+
* console.log(`Upload progress: ${upload.progress}%`);
|
|
16
|
+
*
|
|
17
|
+
* // Control upload
|
|
18
|
+
* upload.pause();
|
|
19
|
+
* upload.resume();
|
|
20
|
+
* upload.cancel();
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
2
23
|
declare class FirekitUploadTask {
|
|
24
|
+
/** Upload progress percentage */
|
|
3
25
|
private _progress;
|
|
26
|
+
/** Error state */
|
|
4
27
|
private _error;
|
|
28
|
+
/** Current upload snapshot */
|
|
5
29
|
private _snapshot;
|
|
30
|
+
/** Download URL of uploaded file */
|
|
6
31
|
private _downloadURL;
|
|
32
|
+
/** Upload completion state */
|
|
7
33
|
private _completed;
|
|
34
|
+
/** Upload task reference */
|
|
8
35
|
private uploadTask;
|
|
36
|
+
/** Storage reference */
|
|
9
37
|
private storageRef;
|
|
38
|
+
/** Derived download URL */
|
|
10
39
|
readonly URLdownload: string | null;
|
|
40
|
+
/**
|
|
41
|
+
* Creates an upload task
|
|
42
|
+
* @param {string} path Storage path for upload
|
|
43
|
+
* @param {File} file File to upload
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const task = new FirekitUploadTask('documents/report.pdf', file);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
11
50
|
constructor(path: string, file: File);
|
|
51
|
+
/**
|
|
52
|
+
* Initializes file upload
|
|
53
|
+
* @private
|
|
54
|
+
* @param {string} path Storage path
|
|
55
|
+
* @param {File} file File to upload
|
|
56
|
+
*/
|
|
12
57
|
private initializeUpload;
|
|
58
|
+
/** Pauses upload */
|
|
13
59
|
pause(): void;
|
|
60
|
+
/** Resumes upload */
|
|
14
61
|
resume(): void;
|
|
62
|
+
/** Cancels upload */
|
|
15
63
|
cancel(): void;
|
|
64
|
+
/** Gets upload progress percentage */
|
|
16
65
|
get progress(): number;
|
|
66
|
+
/** Gets error state */
|
|
17
67
|
get error(): Error | null;
|
|
68
|
+
/** Gets current upload snapshot */
|
|
18
69
|
get snapshot(): UploadTaskSnapshot | null;
|
|
70
|
+
/** Gets download URL */
|
|
19
71
|
get downloadURL(): string | null;
|
|
72
|
+
/** Gets completion state */
|
|
20
73
|
get completed(): boolean;
|
|
21
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates an upload task
|
|
77
|
+
* @param {string} path Storage path for upload
|
|
78
|
+
* @param {File} file File to upload
|
|
79
|
+
* @returns {FirekitUploadTask} Upload task instance
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const uploadTask = firekitUploadTask('images/profile.jpg', imageFile);
|
|
84
|
+
*
|
|
85
|
+
* // Template usage
|
|
86
|
+
* {#if !uploadTask.completed}
|
|
87
|
+
* <progress value={uploadTask.progress} max="100" />
|
|
88
|
+
* {:else}
|
|
89
|
+
* <img src={uploadTask.downloadURL} alt="Uploaded file" />
|
|
90
|
+
* {/if}
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
22
93
|
export declare function firekitUploadTask(path: string, file: File): FirekitUploadTask;
|
|
23
94
|
export {};
|
|
@@ -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
|
}
|