@depup/firebase__storage 0.14.1-depup.0
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 +31 -0
- package/changes.json +10 -0
- package/dist/index.browser.cjs.js +3685 -0
- package/dist/index.browser.cjs.js.map +1 -0
- package/dist/index.cjs.js +3685 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +3656 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.node.cjs.js +3710 -0
- package/dist/index.node.cjs.js.map +1 -0
- package/dist/node-esm/index.node.esm.js +3681 -0
- package/dist/node-esm/index.node.esm.js.map +1 -0
- package/dist/node-esm/package.json +1 -0
- package/dist/node-esm/src/api.browser.d.ts +47 -0
- package/dist/node-esm/src/api.d.ts +200 -0
- package/dist/node-esm/src/api.node.d.ts +47 -0
- package/dist/node-esm/src/constants.d.ts +20 -0
- package/dist/node-esm/src/implementation/async.d.ts +22 -0
- package/dist/node-esm/src/implementation/backoff.d.ts +43 -0
- package/dist/node-esm/src/implementation/blob.d.ts +34 -0
- package/dist/node-esm/src/implementation/connection.d.ts +56 -0
- package/dist/node-esm/src/implementation/constants.d.ts +48 -0
- package/dist/node-esm/src/implementation/error.d.ts +126 -0
- package/dist/node-esm/src/implementation/failrequest.d.ts +29 -0
- package/dist/node-esm/src/implementation/fs.d.ts +17 -0
- package/dist/node-esm/src/implementation/json.d.ts +7 -0
- package/dist/node-esm/src/implementation/list.d.ts +19 -0
- package/dist/node-esm/src/implementation/location.d.ts +32 -0
- package/dist/node-esm/src/implementation/metadata.d.ts +40 -0
- package/dist/node-esm/src/implementation/observer.d.ts +47 -0
- package/dist/node-esm/src/implementation/path.d.ts +31 -0
- package/dist/node-esm/src/implementation/request.d.ts +47 -0
- package/dist/node-esm/src/implementation/requestinfo.d.ts +73 -0
- package/dist/node-esm/src/implementation/requests.d.ts +84 -0
- package/dist/node-esm/src/implementation/string.d.ts +73 -0
- package/dist/node-esm/src/implementation/taskenums.d.ts +77 -0
- package/dist/node-esm/src/implementation/type.d.ts +23 -0
- package/dist/node-esm/src/implementation/url.d.ts +22 -0
- package/dist/node-esm/src/implementation/utils.d.ts +23 -0
- package/dist/node-esm/src/index.d.ts +7 -0
- package/dist/node-esm/src/index.node.d.ts +7 -0
- package/dist/node-esm/src/list.d.ts +41 -0
- package/dist/node-esm/src/metadata.d.ts +27 -0
- package/dist/node-esm/src/platform/base64.d.ts +20 -0
- package/dist/node-esm/src/platform/browser/base64.d.ts +19 -0
- package/dist/node-esm/src/platform/browser/connection.d.ts +55 -0
- package/dist/node-esm/src/platform/connection.d.ts +22 -0
- package/dist/node-esm/src/platform/node/base64.d.ts +19 -0
- package/dist/node-esm/src/platform/node/connection.d.ts +58 -0
- package/dist/node-esm/src/public-types.d.ts +424 -0
- package/dist/node-esm/src/reference.d.ts +208 -0
- package/dist/node-esm/src/service.d.ts +131 -0
- package/dist/node-esm/src/task.d.ts +148 -0
- package/dist/node-esm/test/unit/connection.d.ts +47 -0
- package/dist/node-esm/test/unit/testshared.d.ts +60 -0
- package/dist/src/api.browser.d.ts +47 -0
- package/dist/src/api.d.ts +200 -0
- package/dist/src/api.node.d.ts +47 -0
- package/dist/src/constants.d.ts +20 -0
- package/dist/src/implementation/async.d.ts +22 -0
- package/dist/src/implementation/backoff.d.ts +43 -0
- package/dist/src/implementation/blob.d.ts +34 -0
- package/dist/src/implementation/connection.d.ts +56 -0
- package/dist/src/implementation/constants.d.ts +48 -0
- package/dist/src/implementation/error.d.ts +126 -0
- package/dist/src/implementation/failrequest.d.ts +29 -0
- package/dist/src/implementation/fs.d.ts +17 -0
- package/dist/src/implementation/json.d.ts +7 -0
- package/dist/src/implementation/list.d.ts +19 -0
- package/dist/src/implementation/location.d.ts +32 -0
- package/dist/src/implementation/metadata.d.ts +40 -0
- package/dist/src/implementation/observer.d.ts +47 -0
- package/dist/src/implementation/path.d.ts +31 -0
- package/dist/src/implementation/request.d.ts +47 -0
- package/dist/src/implementation/requestinfo.d.ts +73 -0
- package/dist/src/implementation/requests.d.ts +84 -0
- package/dist/src/implementation/string.d.ts +73 -0
- package/dist/src/implementation/taskenums.d.ts +77 -0
- package/dist/src/implementation/type.d.ts +23 -0
- package/dist/src/implementation/url.d.ts +22 -0
- package/dist/src/implementation/utils.d.ts +23 -0
- package/dist/src/index.d.ts +7 -0
- package/dist/src/index.node.d.ts +7 -0
- package/dist/src/list.d.ts +41 -0
- package/dist/src/metadata.d.ts +27 -0
- package/dist/src/platform/base64.d.ts +20 -0
- package/dist/src/platform/browser/base64.d.ts +19 -0
- package/dist/src/platform/browser/connection.d.ts +55 -0
- package/dist/src/platform/connection.d.ts +22 -0
- package/dist/src/platform/node/base64.d.ts +19 -0
- package/dist/src/platform/node/connection.d.ts +58 -0
- package/dist/src/public-types.d.ts +424 -0
- package/dist/src/reference.d.ts +208 -0
- package/dist/src/service.d.ts +131 -0
- package/dist/src/task.d.ts +148 -0
- package/dist/src/tsdoc-metadata.json +11 -0
- package/dist/storage-public.d.ts +725 -0
- package/dist/storage.d.ts +1391 -0
- package/dist/test/unit/connection.d.ts +47 -0
- package/dist/test/unit/testshared.d.ts +60 -0
- package/package.json +98 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2017 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { FirebaseApp, _FirebaseService } from '@firebase/app';
|
|
18
|
+
import { CompleteFn, NextFn, Subscribe, Unsubscribe } from '@firebase/util';
|
|
19
|
+
import { StorageError } from './implementation/error';
|
|
20
|
+
/**
|
|
21
|
+
* A Firebase Storage instance.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export interface FirebaseStorage extends _FirebaseService {
|
|
25
|
+
/**
|
|
26
|
+
* The {@link @firebase/app#FirebaseApp} associated with this `FirebaseStorage` instance.
|
|
27
|
+
*/
|
|
28
|
+
readonly app: FirebaseApp;
|
|
29
|
+
/**
|
|
30
|
+
* The maximum time to retry uploads in milliseconds.
|
|
31
|
+
*/
|
|
32
|
+
maxUploadRetryTime: number;
|
|
33
|
+
/**
|
|
34
|
+
* The maximum time to retry operations other than uploads or downloads in
|
|
35
|
+
* milliseconds.
|
|
36
|
+
*/
|
|
37
|
+
maxOperationRetryTime: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Represents a reference to a Google Cloud Storage object. Developers can
|
|
41
|
+
* upload, download, and delete objects, as well as get/set object metadata.
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
export interface StorageReference {
|
|
45
|
+
/**
|
|
46
|
+
* Returns a gs:// URL for this object in the form
|
|
47
|
+
* `gs://<bucket>/<path>/<to>/<object>`
|
|
48
|
+
* @returns The gs:// URL.
|
|
49
|
+
*/
|
|
50
|
+
toString(): string;
|
|
51
|
+
/**
|
|
52
|
+
* A reference to the root of this object's bucket.
|
|
53
|
+
*/
|
|
54
|
+
root: StorageReference;
|
|
55
|
+
/**
|
|
56
|
+
* The name of the bucket containing this reference's object.
|
|
57
|
+
*/
|
|
58
|
+
bucket: string;
|
|
59
|
+
/**
|
|
60
|
+
* The full path of this object.
|
|
61
|
+
*/
|
|
62
|
+
fullPath: string;
|
|
63
|
+
/**
|
|
64
|
+
* The short name of this object, which is the last component of the full path.
|
|
65
|
+
* For example, if fullPath is 'full/path/image.png', name is 'image.png'.
|
|
66
|
+
*/
|
|
67
|
+
name: string;
|
|
68
|
+
/**
|
|
69
|
+
* The {@link FirebaseStorage} instance associated with this reference.
|
|
70
|
+
*/
|
|
71
|
+
storage: FirebaseStorage;
|
|
72
|
+
/**
|
|
73
|
+
* A reference pointing to the parent location of this reference, or null if
|
|
74
|
+
* this reference is the root.
|
|
75
|
+
*/
|
|
76
|
+
parent: StorageReference | null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The options `list()` accepts.
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
export interface ListOptions {
|
|
83
|
+
/**
|
|
84
|
+
* If set, limits the total number of `prefixes` and `items` to return.
|
|
85
|
+
* The default and maximum maxResults is 1000.
|
|
86
|
+
*/
|
|
87
|
+
maxResults?: number | null;
|
|
88
|
+
/**
|
|
89
|
+
* The `nextPageToken` from a previous call to `list()`. If provided,
|
|
90
|
+
* listing is resumed from the previous position.
|
|
91
|
+
*/
|
|
92
|
+
pageToken?: string | null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Result returned by list().
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export interface ListResult {
|
|
99
|
+
/**
|
|
100
|
+
* References to prefixes (sub-folders). You can call list() on them to
|
|
101
|
+
* get its contents.
|
|
102
|
+
*
|
|
103
|
+
* Folders are implicit based on '/' in the object paths.
|
|
104
|
+
* For example, if a bucket has two objects '/a/b/1' and '/a/b/2', list('/a')
|
|
105
|
+
* will return '/a/b' as a prefix.
|
|
106
|
+
*/
|
|
107
|
+
prefixes: StorageReference[];
|
|
108
|
+
/**
|
|
109
|
+
* Objects in this directory.
|
|
110
|
+
* You can call getMetadata() and getDownloadUrl() on them.
|
|
111
|
+
*/
|
|
112
|
+
items: StorageReference[];
|
|
113
|
+
/**
|
|
114
|
+
* If set, there might be more results for this list. Use this token to resume the list.
|
|
115
|
+
*/
|
|
116
|
+
nextPageToken?: string;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Object metadata that can be set at any time.
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
export interface SettableMetadata {
|
|
123
|
+
/**
|
|
124
|
+
* Served as the 'Cache-Control' header on object download.
|
|
125
|
+
*/
|
|
126
|
+
cacheControl?: string | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Served as the 'Content-Disposition' header on object download.
|
|
129
|
+
*/
|
|
130
|
+
contentDisposition?: string | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Served as the 'Content-Encoding' header on object download.
|
|
133
|
+
*/
|
|
134
|
+
contentEncoding?: string | undefined;
|
|
135
|
+
/**
|
|
136
|
+
* Served as the 'Content-Language' header on object download.
|
|
137
|
+
*/
|
|
138
|
+
contentLanguage?: string | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* Served as the 'Content-Type' header on object download.
|
|
141
|
+
*/
|
|
142
|
+
contentType?: string | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Additional user-defined custom metadata.
|
|
145
|
+
*/
|
|
146
|
+
customMetadata?: {
|
|
147
|
+
[key: string]: string;
|
|
148
|
+
} | undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Object metadata that can be set at upload.
|
|
152
|
+
* @public
|
|
153
|
+
*/
|
|
154
|
+
export interface UploadMetadata extends SettableMetadata {
|
|
155
|
+
/**
|
|
156
|
+
* A Base64-encoded MD5 hash of the object being uploaded.
|
|
157
|
+
*/
|
|
158
|
+
md5Hash?: string | undefined;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The full set of object metadata, including read-only properties.
|
|
162
|
+
* @public
|
|
163
|
+
*/
|
|
164
|
+
export interface FullMetadata extends UploadMetadata {
|
|
165
|
+
/**
|
|
166
|
+
* The bucket this object is contained in.
|
|
167
|
+
*/
|
|
168
|
+
bucket: string;
|
|
169
|
+
/**
|
|
170
|
+
* The full path of this object.
|
|
171
|
+
*/
|
|
172
|
+
fullPath: string;
|
|
173
|
+
/**
|
|
174
|
+
* The object's generation.
|
|
175
|
+
* {@link https://cloud.google.com/storage/docs/metadata#generation-number}
|
|
176
|
+
*/
|
|
177
|
+
generation: string;
|
|
178
|
+
/**
|
|
179
|
+
* The object's metageneration.
|
|
180
|
+
* {@link https://cloud.google.com/storage/docs/metadata#generation-number}
|
|
181
|
+
*/
|
|
182
|
+
metageneration: string;
|
|
183
|
+
/**
|
|
184
|
+
* The short name of this object, which is the last component of the full path.
|
|
185
|
+
* For example, if fullPath is 'full/path/image.png', name is 'image.png'.
|
|
186
|
+
*/
|
|
187
|
+
name: string;
|
|
188
|
+
/**
|
|
189
|
+
* The size of this object, in bytes.
|
|
190
|
+
*/
|
|
191
|
+
size: number;
|
|
192
|
+
/**
|
|
193
|
+
* A date string representing when this object was created.
|
|
194
|
+
*/
|
|
195
|
+
timeCreated: string;
|
|
196
|
+
/**
|
|
197
|
+
* A date string representing when this object was last updated.
|
|
198
|
+
*/
|
|
199
|
+
updated: string;
|
|
200
|
+
/**
|
|
201
|
+
* Tokens to allow access to the download URL.
|
|
202
|
+
*/
|
|
203
|
+
downloadTokens: string[] | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* `StorageReference` associated with this upload.
|
|
206
|
+
*/
|
|
207
|
+
ref?: StorageReference | undefined;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* An event that is triggered on a task.
|
|
211
|
+
* @public
|
|
212
|
+
*/
|
|
213
|
+
export type TaskEvent = 'state_changed';
|
|
214
|
+
/**
|
|
215
|
+
* Represents the current state of a running upload.
|
|
216
|
+
* @public
|
|
217
|
+
*/
|
|
218
|
+
export type TaskState = 'running' | 'paused' | 'success' | 'canceled' | 'error';
|
|
219
|
+
/**
|
|
220
|
+
* A stream observer for Firebase Storage.
|
|
221
|
+
* @public
|
|
222
|
+
*/
|
|
223
|
+
export interface StorageObserver<T> {
|
|
224
|
+
next?: NextFn<T> | null;
|
|
225
|
+
error?: (error: StorageError) => void | null;
|
|
226
|
+
complete?: CompleteFn | null;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Represents the process of uploading an object. Allows you to monitor and
|
|
230
|
+
* manage the upload.
|
|
231
|
+
* @public
|
|
232
|
+
*/
|
|
233
|
+
export interface UploadTask {
|
|
234
|
+
/**
|
|
235
|
+
* Cancels a running task. Has no effect on a complete or failed task.
|
|
236
|
+
* @returns True if the cancel had an effect.
|
|
237
|
+
*/
|
|
238
|
+
cancel(): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Equivalent to calling `then(null, onRejected)`.
|
|
241
|
+
*/
|
|
242
|
+
catch(onRejected: (error: StorageError) => unknown): Promise<unknown>;
|
|
243
|
+
/**
|
|
244
|
+
* Listens for events on this task.
|
|
245
|
+
*
|
|
246
|
+
* Events have three callback functions (referred to as `next`, `error`, and
|
|
247
|
+
* `complete`).
|
|
248
|
+
*
|
|
249
|
+
* If only the event is passed, a function that can be used to register the
|
|
250
|
+
* callbacks is returned. Otherwise, the callbacks are passed after the event.
|
|
251
|
+
*
|
|
252
|
+
* Callbacks can be passed either as three separate arguments <em>or</em> as the
|
|
253
|
+
* `next`, `error`, and `complete` properties of an object. Any of the three
|
|
254
|
+
* callbacks is optional, as long as at least one is specified. In addition,
|
|
255
|
+
* when you add your callbacks, you get a function back. You can call this
|
|
256
|
+
* function to unregister the associated callbacks.
|
|
257
|
+
*
|
|
258
|
+
* @example **Pass callbacks separately or in an object.**
|
|
259
|
+
* ```javascript
|
|
260
|
+
* var next = function(snapshot) {};
|
|
261
|
+
* var error = function(error) {};
|
|
262
|
+
* var complete = function() {};
|
|
263
|
+
*
|
|
264
|
+
* // The first example.
|
|
265
|
+
* uploadTask.on(
|
|
266
|
+
* firebase.storage.TaskEvent.STATE_CHANGED,
|
|
267
|
+
* next,
|
|
268
|
+
* error,
|
|
269
|
+
* complete);
|
|
270
|
+
*
|
|
271
|
+
* // This is equivalent to the first example.
|
|
272
|
+
* uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
|
|
273
|
+
* 'next': next,
|
|
274
|
+
* 'error': error,
|
|
275
|
+
* 'complete': complete
|
|
276
|
+
* });
|
|
277
|
+
*
|
|
278
|
+
* // This is equivalent to the first example.
|
|
279
|
+
* var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
|
|
280
|
+
* subscribe(next, error, complete);
|
|
281
|
+
*
|
|
282
|
+
* // This is equivalent to the first example.
|
|
283
|
+
* var subscribe = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
|
|
284
|
+
* subscribe({
|
|
285
|
+
* 'next': next,
|
|
286
|
+
* 'error': error,
|
|
287
|
+
* 'complete': complete
|
|
288
|
+
* });
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* @example **Any callback is optional.**
|
|
292
|
+
* ```javascript
|
|
293
|
+
* // Just listening for completion, this is legal.
|
|
294
|
+
* uploadTask.on(
|
|
295
|
+
* firebase.storage.TaskEvent.STATE_CHANGED,
|
|
296
|
+
* null,
|
|
297
|
+
* null,
|
|
298
|
+
* function() {
|
|
299
|
+
* console.log('upload complete!');
|
|
300
|
+
* });
|
|
301
|
+
*
|
|
302
|
+
* // Just listening for progress/state changes, this is legal.
|
|
303
|
+
* uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, function(snapshot) {
|
|
304
|
+
* var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
|
305
|
+
* console.log(percent + "% done");
|
|
306
|
+
* });
|
|
307
|
+
*
|
|
308
|
+
* // This is also legal.
|
|
309
|
+
* uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, {
|
|
310
|
+
* 'complete': function() {
|
|
311
|
+
* console.log('upload complete!');
|
|
312
|
+
* }
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*
|
|
316
|
+
* @example **Use the returned function to remove callbacks.**
|
|
317
|
+
* ```javascript
|
|
318
|
+
* var unsubscribe = uploadTask.on(
|
|
319
|
+
* firebase.storage.TaskEvent.STATE_CHANGED,
|
|
320
|
+
* function(snapshot) {
|
|
321
|
+
* var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
|
322
|
+
* console.log(percent + "% done");
|
|
323
|
+
* // Stop after receiving one update.
|
|
324
|
+
* unsubscribe();
|
|
325
|
+
* });
|
|
326
|
+
*
|
|
327
|
+
* // This code is equivalent to the above.
|
|
328
|
+
* var handle = uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED);
|
|
329
|
+
* unsubscribe = handle(function(snapshot) {
|
|
330
|
+
* var percent = snapshot.bytesTransferred / snapshot.totalBytes * 100;
|
|
331
|
+
* console.log(percent + "% done");
|
|
332
|
+
* // Stop after receiving one update.
|
|
333
|
+
* unsubscribe();
|
|
334
|
+
* });
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
337
|
+
* @param event - The type of event to listen for.
|
|
338
|
+
* @param nextOrObserver -
|
|
339
|
+
* The `next` function, which gets called for each item in
|
|
340
|
+
* the event stream, or an observer object with some or all of these three
|
|
341
|
+
* properties (`next`, `error`, `complete`).
|
|
342
|
+
* @param error - A function that gets called with a `StorageError`
|
|
343
|
+
* if the event stream ends due to an error.
|
|
344
|
+
* @param completed - A function that gets called if the
|
|
345
|
+
* event stream ends normally.
|
|
346
|
+
* @returns
|
|
347
|
+
* If only the event argument is passed, returns a function you can use to
|
|
348
|
+
* add callbacks (see the examples above). If more than just the event
|
|
349
|
+
* argument is passed, returns a function you can call to unregister the
|
|
350
|
+
* callbacks.
|
|
351
|
+
*/
|
|
352
|
+
on(event: TaskEvent, nextOrObserver?: StorageObserver<UploadTaskSnapshot> | null | ((snapshot: UploadTaskSnapshot) => unknown), error?: ((a: StorageError) => unknown) | null, complete?: Unsubscribe | null): Unsubscribe | Subscribe<UploadTaskSnapshot>;
|
|
353
|
+
/**
|
|
354
|
+
* Pauses a currently running task. Has no effect on a paused or failed task.
|
|
355
|
+
* @returns True if the operation took effect, false if ignored.
|
|
356
|
+
*/
|
|
357
|
+
pause(): boolean;
|
|
358
|
+
/**
|
|
359
|
+
* Resumes a paused task. Has no effect on a currently running or failed task.
|
|
360
|
+
* @returns True if the operation took effect, false if ignored.
|
|
361
|
+
*/
|
|
362
|
+
resume(): boolean;
|
|
363
|
+
/**
|
|
364
|
+
* A snapshot of the current task state.
|
|
365
|
+
*/
|
|
366
|
+
snapshot: UploadTaskSnapshot;
|
|
367
|
+
/**
|
|
368
|
+
* This object behaves like a Promise, and resolves with its snapshot data
|
|
369
|
+
* when the upload completes.
|
|
370
|
+
* @param onFulfilled - The fulfillment callback. Promise chaining works as normal.
|
|
371
|
+
* @param onRejected - The rejection callback.
|
|
372
|
+
*/
|
|
373
|
+
then(onFulfilled?: ((snapshot: UploadTaskSnapshot) => unknown) | null, onRejected?: ((error: StorageError) => unknown) | null): Promise<unknown>;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Holds data about the current state of the upload task.
|
|
377
|
+
* @public
|
|
378
|
+
*/
|
|
379
|
+
export interface UploadTaskSnapshot {
|
|
380
|
+
/**
|
|
381
|
+
* The number of bytes that have been successfully uploaded so far.
|
|
382
|
+
*/
|
|
383
|
+
bytesTransferred: number;
|
|
384
|
+
/**
|
|
385
|
+
* Before the upload completes, contains the metadata sent to the server.
|
|
386
|
+
* After the upload completes, contains the metadata sent back from the server.
|
|
387
|
+
*/
|
|
388
|
+
metadata: FullMetadata;
|
|
389
|
+
/**
|
|
390
|
+
* The reference that spawned this snapshot's upload task.
|
|
391
|
+
*/
|
|
392
|
+
ref: StorageReference;
|
|
393
|
+
/**
|
|
394
|
+
* The current state of the task.
|
|
395
|
+
*/
|
|
396
|
+
state: TaskState;
|
|
397
|
+
/**
|
|
398
|
+
* The task of which this is a snapshot.
|
|
399
|
+
*/
|
|
400
|
+
task: UploadTask;
|
|
401
|
+
/**
|
|
402
|
+
* The total number of bytes to be uploaded.
|
|
403
|
+
*/
|
|
404
|
+
totalBytes: number;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Result returned from a non-resumable upload.
|
|
408
|
+
* @public
|
|
409
|
+
*/
|
|
410
|
+
export interface UploadResult {
|
|
411
|
+
/**
|
|
412
|
+
* Contains the metadata sent back from the server.
|
|
413
|
+
*/
|
|
414
|
+
readonly metadata: FullMetadata;
|
|
415
|
+
/**
|
|
416
|
+
* The reference that spawned this upload.
|
|
417
|
+
*/
|
|
418
|
+
readonly ref: StorageReference;
|
|
419
|
+
}
|
|
420
|
+
declare module '@firebase/component' {
|
|
421
|
+
interface NameServiceMapping {
|
|
422
|
+
'storage': FirebaseStorage;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2019 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { Location } from './implementation/location';
|
|
18
|
+
import { ListOptions, UploadResult } from './public-types';
|
|
19
|
+
import { StringFormat } from './implementation/string';
|
|
20
|
+
import { Metadata } from './metadata';
|
|
21
|
+
import { FirebaseStorageImpl } from './service';
|
|
22
|
+
import { ListResult } from './list';
|
|
23
|
+
import { UploadTask } from './task';
|
|
24
|
+
/**
|
|
25
|
+
* Provides methods to interact with a bucket in the Firebase Storage service.
|
|
26
|
+
* @internal
|
|
27
|
+
* @param _location - An fbs.location, or the URL at
|
|
28
|
+
* which to base this object, in one of the following forms:
|
|
29
|
+
* gs://<bucket>/<object-path>
|
|
30
|
+
* http[s]://firebasestorage.googleapis.com/
|
|
31
|
+
* <api-version>/b/<bucket>/o/<object-path>
|
|
32
|
+
* Any query or fragment strings will be ignored in the http[s]
|
|
33
|
+
* format. If no value is passed, the storage object will use a URL based on
|
|
34
|
+
* the project ID of the base firebase.App instance.
|
|
35
|
+
*/
|
|
36
|
+
export declare class Reference {
|
|
37
|
+
private _service;
|
|
38
|
+
_location: Location;
|
|
39
|
+
constructor(_service: FirebaseStorageImpl, location: string | Location);
|
|
40
|
+
/**
|
|
41
|
+
* Returns the URL for the bucket and path this object references,
|
|
42
|
+
* in the form gs://<bucket>/<object-path>
|
|
43
|
+
* @override
|
|
44
|
+
*/
|
|
45
|
+
toString(): string;
|
|
46
|
+
protected _newRef(service: FirebaseStorageImpl, location: Location): Reference;
|
|
47
|
+
/**
|
|
48
|
+
* A reference to the root of this object's bucket.
|
|
49
|
+
*/
|
|
50
|
+
get root(): Reference;
|
|
51
|
+
/**
|
|
52
|
+
* The name of the bucket containing this reference's object.
|
|
53
|
+
*/
|
|
54
|
+
get bucket(): string;
|
|
55
|
+
/**
|
|
56
|
+
* The full path of this object.
|
|
57
|
+
*/
|
|
58
|
+
get fullPath(): string;
|
|
59
|
+
/**
|
|
60
|
+
* The short name of this object, which is the last component of the full path.
|
|
61
|
+
* For example, if fullPath is 'full/path/image.png', name is 'image.png'.
|
|
62
|
+
*/
|
|
63
|
+
get name(): string;
|
|
64
|
+
/**
|
|
65
|
+
* The `StorageService` instance this `StorageReference` is associated with.
|
|
66
|
+
*/
|
|
67
|
+
get storage(): FirebaseStorageImpl;
|
|
68
|
+
/**
|
|
69
|
+
* A `StorageReference` pointing to the parent location of this `StorageReference`, or null if
|
|
70
|
+
* this reference is the root.
|
|
71
|
+
*/
|
|
72
|
+
get parent(): Reference | null;
|
|
73
|
+
/**
|
|
74
|
+
* Utility function to throw an error in methods that do not accept a root reference.
|
|
75
|
+
*/
|
|
76
|
+
_throwIfRoot(name: string): void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Download the bytes at the object's location.
|
|
80
|
+
* @returns A Promise containing the downloaded bytes.
|
|
81
|
+
*/
|
|
82
|
+
export declare function getBytesInternal(ref: Reference, maxDownloadSizeBytes?: number): Promise<ArrayBuffer>;
|
|
83
|
+
/**
|
|
84
|
+
* Download the bytes at the object's location.
|
|
85
|
+
* @returns A Promise containing the downloaded blob.
|
|
86
|
+
*/
|
|
87
|
+
export declare function getBlobInternal(ref: Reference, maxDownloadSizeBytes?: number): Promise<Blob>;
|
|
88
|
+
/** Stream the bytes at the object's location. */
|
|
89
|
+
export declare function getStreamInternal(ref: Reference, maxDownloadSizeBytes?: number): ReadableStream;
|
|
90
|
+
/**
|
|
91
|
+
* Uploads data to this object's location.
|
|
92
|
+
* The upload is not resumable.
|
|
93
|
+
*
|
|
94
|
+
* @param ref - StorageReference where data should be uploaded.
|
|
95
|
+
* @param data - The data to upload.
|
|
96
|
+
* @param metadata - Metadata for the newly uploaded data.
|
|
97
|
+
* @returns A Promise containing an UploadResult
|
|
98
|
+
*/
|
|
99
|
+
export declare function uploadBytes(ref: Reference, data: Blob | Uint8Array | ArrayBuffer, metadata?: Metadata): Promise<UploadResult>;
|
|
100
|
+
/**
|
|
101
|
+
* Uploads data to this object's location.
|
|
102
|
+
* The upload can be paused and resumed, and exposes progress updates.
|
|
103
|
+
* @public
|
|
104
|
+
* @param ref - StorageReference where data should be uploaded.
|
|
105
|
+
* @param data - The data to upload.
|
|
106
|
+
* @param metadata - Metadata for the newly uploaded data.
|
|
107
|
+
* @returns An UploadTask
|
|
108
|
+
*/
|
|
109
|
+
export declare function uploadBytesResumable(ref: Reference, data: Blob | Uint8Array | ArrayBuffer, metadata?: Metadata): UploadTask;
|
|
110
|
+
/**
|
|
111
|
+
* Uploads a string to this object's location.
|
|
112
|
+
* The upload is not resumable.
|
|
113
|
+
* @public
|
|
114
|
+
* @param ref - StorageReference where string should be uploaded.
|
|
115
|
+
* @param value - The string to upload.
|
|
116
|
+
* @param format - The format of the string to upload.
|
|
117
|
+
* @param metadata - Metadata for the newly uploaded string.
|
|
118
|
+
* @returns A Promise containing an UploadResult
|
|
119
|
+
*/
|
|
120
|
+
export declare function uploadString(ref: Reference, value: string, format?: StringFormat, metadata?: Metadata): Promise<UploadResult>;
|
|
121
|
+
/**
|
|
122
|
+
* List all items (files) and prefixes (folders) under this storage reference.
|
|
123
|
+
*
|
|
124
|
+
* This is a helper method for calling list() repeatedly until there are
|
|
125
|
+
* no more results. The default pagination size is 1000.
|
|
126
|
+
*
|
|
127
|
+
* Note: The results may not be consistent if objects are changed while this
|
|
128
|
+
* operation is running.
|
|
129
|
+
*
|
|
130
|
+
* Warning: listAll may potentially consume too many resources if there are
|
|
131
|
+
* too many results.
|
|
132
|
+
* @public
|
|
133
|
+
* @param ref - StorageReference to get list from.
|
|
134
|
+
*
|
|
135
|
+
* @returns A Promise that resolves with all the items and prefixes under
|
|
136
|
+
* the current storage reference. `prefixes` contains references to
|
|
137
|
+
* sub-directories and `items` contains references to objects in this
|
|
138
|
+
* folder. `nextPageToken` is never returned.
|
|
139
|
+
*/
|
|
140
|
+
export declare function listAll(ref: Reference): Promise<ListResult>;
|
|
141
|
+
/**
|
|
142
|
+
* List items (files) and prefixes (folders) under this storage reference.
|
|
143
|
+
*
|
|
144
|
+
* List API is only available for Firebase Rules Version 2.
|
|
145
|
+
*
|
|
146
|
+
* GCS is a key-blob store. Firebase Storage imposes the semantic of '/'
|
|
147
|
+
* delimited folder structure.
|
|
148
|
+
* Refer to GCS's List API if you want to learn more.
|
|
149
|
+
*
|
|
150
|
+
* To adhere to Firebase Rules's Semantics, Firebase Storage does not
|
|
151
|
+
* support objects whose paths end with "/" or contain two consecutive
|
|
152
|
+
* "/"s. Firebase Storage List API will filter these unsupported objects.
|
|
153
|
+
* list() may fail if there are too many unsupported objects in the bucket.
|
|
154
|
+
* @public
|
|
155
|
+
*
|
|
156
|
+
* @param ref - StorageReference to get list from.
|
|
157
|
+
* @param options - See ListOptions for details.
|
|
158
|
+
* @returns A Promise that resolves with the items and prefixes.
|
|
159
|
+
* `prefixes` contains references to sub-folders and `items`
|
|
160
|
+
* contains references to objects in this folder. `nextPageToken`
|
|
161
|
+
* can be used to get the rest of the results.
|
|
162
|
+
*/
|
|
163
|
+
export declare function list(ref: Reference, options?: ListOptions | null): Promise<ListResult>;
|
|
164
|
+
/**
|
|
165
|
+
* A `Promise` that resolves with the metadata for this object. If this
|
|
166
|
+
* object doesn't exist or metadata cannot be retrieved, the promise is
|
|
167
|
+
* rejected.
|
|
168
|
+
* @public
|
|
169
|
+
* @param ref - StorageReference to get metadata from.
|
|
170
|
+
*/
|
|
171
|
+
export declare function getMetadata(ref: Reference): Promise<Metadata>;
|
|
172
|
+
/**
|
|
173
|
+
* Updates the metadata for this object.
|
|
174
|
+
* @public
|
|
175
|
+
* @param ref - StorageReference to update metadata for.
|
|
176
|
+
* @param metadata - The new metadata for the object.
|
|
177
|
+
* Only values that have been explicitly set will be changed. Explicitly
|
|
178
|
+
* setting a value to null will remove the metadata.
|
|
179
|
+
* @returns A `Promise` that resolves
|
|
180
|
+
* with the new metadata for this object.
|
|
181
|
+
* See `firebaseStorage.Reference.prototype.getMetadata`
|
|
182
|
+
*/
|
|
183
|
+
export declare function updateMetadata(ref: Reference, metadata: Partial<Metadata>): Promise<Metadata>;
|
|
184
|
+
/**
|
|
185
|
+
* Returns the download URL for the given Reference.
|
|
186
|
+
* @public
|
|
187
|
+
* @returns A `Promise` that resolves with the download
|
|
188
|
+
* URL for this object.
|
|
189
|
+
*/
|
|
190
|
+
export declare function getDownloadURL(ref: Reference): Promise<string>;
|
|
191
|
+
/**
|
|
192
|
+
* Deletes the object at this location.
|
|
193
|
+
* @public
|
|
194
|
+
* @param ref - StorageReference for object to delete.
|
|
195
|
+
* @returns A `Promise` that resolves if the deletion succeeds.
|
|
196
|
+
*/
|
|
197
|
+
export declare function deleteObject(ref: Reference): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Returns reference for object obtained by appending `childPath` to `ref`.
|
|
200
|
+
*
|
|
201
|
+
* @param ref - StorageReference to get child of.
|
|
202
|
+
* @param childPath - Child path from provided ref.
|
|
203
|
+
* @returns A reference to the object obtained by
|
|
204
|
+
* appending childPath, removing any duplicate, beginning, or trailing
|
|
205
|
+
* slashes.
|
|
206
|
+
*
|
|
207
|
+
*/
|
|
208
|
+
export declare function _getChild(ref: Reference, childPath: string): Reference;
|