Skip to content

Commit ad2374e

Browse files
Merge master
1 parent fe531e9 commit ad2374e

29 files changed

+774
-481
lines changed

common/api-review/storage.api.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class _FirebaseStorageImpl implements FirebaseStorage {
5858
constructor(
5959
app: FirebaseApp, _authProvider: Provider<FirebaseAuthInternalName>,
6060
_appCheckProvider: Provider<AppCheckInternalComponentName>,
61-
_pool: ConnectionPool, _url?: string | undefined, _firebaseVersion?: string | undefined);
61+
_url?: string | undefined, _firebaseVersion?: string | undefined);
6262
readonly app: FirebaseApp;
6363
// (undocumented)
6464
readonly _appCheckProvider: Provider<AppCheckInternalComponentName>;
@@ -79,23 +79,20 @@ export class _FirebaseStorageImpl implements FirebaseStorage {
7979
get host(): string;
8080
set host(host: string);
8181
// Warning: (ae-forgotten-export) The symbol "RequestInfo" needs to be exported by the entry point index.d.ts
82+
// Warning: (ae-forgotten-export) The symbol "Connection" needs to be exported by the entry point index.d.ts
8283
// Warning: (ae-forgotten-export) The symbol "Request" needs to be exported by the entry point index.d.ts
8384
//
8485
// (undocumented)
85-
_makeRequest<T>(requestInfo: RequestInfo_2<T>, authToken: string | null, appCheckToken: string | null): Request_2<T>;
86+
_makeRequest<I, O>(requestInfo: RequestInfo_2<I, O>, requestFactory: () => Connection<I>, authToken: string | null, appCheckToken: string | null): Request_2<O>;
8687
// (undocumented)
87-
makeRequestWithTokens<T>(requestInfo: RequestInfo_2<T>): Promise<Request_2<T>>;
88+
makeRequestWithTokens<I, O>(requestInfo: RequestInfo_2<I, O>, requestFactory: () => Connection<I>): Promise<Request_2<O>>;
8889
_makeStorageReference(loc: _Location): _Reference;
8990
get maxOperationRetryTime(): number;
9091
set maxOperationRetryTime(time: number);
9192
get maxUploadRetryTime(): number;
9293
set maxUploadRetryTime(time: number);
9394
// (undocumented)
9495
_overrideAuthToken?: string;
95-
// Warning: (ae-forgotten-export) The symbol "ConnectionPool" needs to be exported by the entry point index.d.ts
96-
//
97-
// (undocumented)
98-
readonly _pool: ConnectionPool;
9996
// (undocumented)
10097
readonly _url?: string | undefined;
10198
}
@@ -114,6 +111,12 @@ export interface FullMetadata extends UploadMetadata {
114111
updated: string;
115112
}
116113

114+
// @public
115+
export function getBlob(ref: StorageReference): Promise<Blob>;
116+
117+
// @public
118+
export function getBytes(ref: StorageReference): Promise<ArrayBuffer>;
119+
117120
// @internal (undocumented)
118121
export function _getChild(ref: StorageReference, childPath: string): _Reference;
119122

packages/storage/karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = function (config) {
3232

3333
function getTestFiles(argv) {
3434
let unitTestFiles = ['test/unit/*'];
35-
let integrationTestFiles = ['test/integration/*'];
35+
let integrationTestFiles = ['test/integration/*', 'test/browser/*'];
3636

3737
if (argv.unit) {
3838
return unitTestFiles;

packages/storage/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const es2017Plugins = [
7878
const es2017Builds = [
7979
// Node
8080
{
81-
input: './src/index.ts',
81+
input: './src/index.node.ts',
8282
output: {
8383
file: pkg.main,
8484
format: 'cjs',

packages/storage/src/api.browser.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* @license
3+
* Copyright 2020 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+
18+
import { StorageReference } from './public-types';
19+
import { Reference, getBlobInternal } from '../src/reference';
20+
import { getModularInstance } from '@firebase/util';
21+
22+
/**
23+
* Downloads the data at the object's location. Returns an error if the object
24+
* is not found.
25+
*
26+
* To use this functionality, you have to whitelist your app's origin in your
27+
* Cloud Storage bucket. See also
28+
* https://cloud.google.com/storage/docs/configuring-cors
29+
*
30+
* This API is not available in Node.
31+
*
32+
* @public
33+
* @param ref - StorageReference where data should be download.
34+
* @returns A Promise that resolves with a Blob containing the object's bytes
35+
*/
36+
export function getBlob(ref: StorageReference): Promise<Blob> {
37+
ref = getModularInstance(ref);
38+
return getBlobInternal(ref as Reference);
39+
}

packages/storage/src/api.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ import {
4747
getDownloadURL as getDownloadURLInternal,
4848
deleteObject as deleteObjectInternal,
4949
Reference,
50-
_getChild as _getChildInternal
50+
_getChild as _getChildInternal,
51+
getBytesInternal
5152
} from './reference';
5253
import { STORAGE_TYPE } from './constants';
5354
import { EmulatorMockTokenOptions, getModularInstance } from '@firebase/util';
@@ -74,6 +75,23 @@ export {
7475
TaskState as _TaskState
7576
} from './implementation/taskenums';
7677

78+
/**
79+
* Downloads the data at the object's location. Returns an error if the object
80+
* is not found.
81+
*
82+
* To use this functionality, you have to whitelist your app's origin in your
83+
* Cloud Storage bucket. See also
84+
* https://cloud.google.com/storage/docs/configuring-cors
85+
*
86+
* @public
87+
* @param ref - StorageReference where data should be download.
88+
* @returns A Promise containing the object's bytes
89+
*/
90+
export function getBytes(ref: StorageReference): Promise<ArrayBuffer> {
91+
ref = getModularInstance(ref);
92+
return getBytesInternal(ref as Reference);
93+
}
94+
7795
/**
7896
* Uploads data to this object's location.
7997
* The upload is not resumable.

packages/storage/src/implementation/connection.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
* limitations under the License.
1616
*/
1717

18-
/**
19-
* Network headers
20-
*/
21-
export interface Headers {
22-
[name: string]: string;
23-
}
18+
/** Network headers */
19+
export type Headers = Record<string, string>;
2420

2521
/**
2622
* A lightweight wrapper around XMLHttpRequest with a
2723
* goog.net.XhrIo-like interface.
24+
*
25+
* ResponseType is generally either `string` or `ArrayBuffer`. You can create
26+
* a new connection by invoking `newTextConnection()` or
27+
* `newBytesConnection()`.
2828
*/
29-
export interface Connection {
29+
export interface Connection<ResponseType> {
3030
send(
3131
url: string,
3232
method: string,
@@ -38,6 +38,8 @@ export interface Connection {
3838

3939
getStatus(): number;
4040

41+
getResponse(): ResponseType;
42+
4143
getResponseText(): string;
4244

4345
/**

packages/storage/src/implementation/connectionPool.ts

-31
This file was deleted.

0 commit comments

Comments
 (0)