UNPKG

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