UNPKG

3.83 kBTypeScriptView Raw
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
18import { FirebaseApp } from '@firebase/app-types';
19import { CompleteFn, FirebaseError, NextFn, Unsubscribe } from '@firebase/util';
20
21export interface FullMetadata extends UploadMetadata {
22 bucket: string;
23 fullPath: string;
24 generation: string;
25 metageneration: string;
26 name: string;
27 size: number;
28 timeCreated: string;
29 updated: string;
30}
31
32export interface Reference {
33 bucket: string;
34 child(path: string): Reference;
35 delete(): Promise<void>;
36 fullPath: string;
37 getDownloadURL(): Promise<string>;
38 getMetadata(): Promise<FullMetadata>;
39 name: string;
40 parent: Reference | null;
41 put(
42 data: Blob | Uint8Array | ArrayBuffer,
43 metadata?: UploadMetadata
44 ): UploadTask;
45 putString(
46 data: string,
47 format?: StringFormat,
48 metadata?: UploadMetadata
49 ): UploadTask;
50 root: Reference;
51 storage: FirebaseStorage;
52 toString(): string;
53 updateMetadata(metadata: SettableMetadata): Promise<FullMetadata>;
54 listAll(): Promise<ListResult>;
55 list(options?: ListOptions): Promise<ListResult>;
56}
57
58export interface ListResult {
59 prefixes: Reference[];
60 items: Reference[];
61 nextPageToken: string | null;
62}
63
64export interface ListOptions {
65 maxResults?: number | null;
66 pageToken?: string | null;
67}
68
69export interface SettableMetadata {
70 cacheControl?: string | null;
71 contentDisposition?: string | null;
72 contentEncoding?: string | null;
73 contentLanguage?: string | null;
74 contentType?: string | null;
75 customMetadata?: {
76 [/* warning: coerced from ? */ key: string]: string;
77 } | null;
78}
79
80export type StringFormat = string;
81export type TaskEvent = string;
82export type TaskState = string;
83
84export interface UploadMetadata extends SettableMetadata {
85 md5Hash?: string | null;
86}
87
88interface FirebaseStorageError extends FirebaseError {
89 serverResponse: string | null;
90}
91
92export interface StorageObserver<T> {
93 next?: NextFn<T> | null;
94 error?: (error: FirebaseStorageError) => void | null;
95 complete?: CompleteFn | null;
96}
97
98export interface UploadTask {
99 cancel(): boolean;
100 catch(onRejected: (error: FirebaseStorageError) => any): Promise<any>;
101 on(
102 event: TaskEvent,
103 nextOrObserver?:
104 | StorageObserver<UploadTaskSnapshot>
105 | null
106 | ((snapshot: UploadTaskSnapshot) => any),
107 error?: ((a: FirebaseStorageError) => any) | null,
108 complete?: Unsubscribe | null
109 ): Function;
110 pause(): boolean;
111 resume(): boolean;
112 snapshot: UploadTaskSnapshot;
113 then(
114 onFulfilled?: ((snapshot: UploadTaskSnapshot) => any) | null,
115 onRejected?: ((error: FirebaseStorageError) => any) | null
116 ): Promise<any>;
117}
118
119export interface UploadTaskSnapshot {
120 bytesTransferred: number;
121 metadata: FullMetadata;
122 ref: Reference;
123 state: TaskState;
124 task: UploadTask;
125 totalBytes: number;
126}
127
128export class FirebaseStorage {
129 private constructor();
130
131 app: FirebaseApp;
132 maxOperationRetryTime: number;
133 maxUploadRetryTime: number;
134 ref(path?: string): Reference;
135 refFromURL(url: string): Reference;
136 setMaxOperationRetryTime(time: number): void;
137 setMaxUploadRetryTime(time: number): void;
138 useEmulator(host: string, port: number): void;
139}
140
141declare module '@firebase/component' {
142 interface NameServiceMapping {
143 'storage': FirebaseStorage;
144 }
145}
146
\No newline at end of file