@firebase/storage 0.8.7 → 0.9.0-canary.cb7299cbf

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/index.browser.cjs.js +198 -25
  3. package/dist/index.browser.cjs.js.map +1 -1
  4. package/dist/index.esm2017.js +177 -26
  5. package/dist/index.esm2017.js.map +1 -1
  6. package/dist/index.esm5.js +196 -26
  7. package/dist/index.esm5.js.map +1 -1
  8. package/dist/index.node.cjs.js +245 -45
  9. package/dist/index.node.cjs.js.map +1 -1
  10. package/dist/node-esm/index.node.esm.js +189 -46
  11. package/dist/node-esm/index.node.esm.js.map +1 -1
  12. package/dist/node-esm/src/api.browser.d.ts +32 -1
  13. package/dist/node-esm/src/api.d.ts +15 -0
  14. package/dist/node-esm/src/api.node.d.ts +32 -1
  15. package/dist/node-esm/src/implementation/connection.d.ts +14 -4
  16. package/dist/node-esm/src/implementation/request.d.ts +5 -5
  17. package/dist/node-esm/src/implementation/requestinfo.d.ts +14 -6
  18. package/dist/node-esm/src/implementation/requests.d.ts +17 -16
  19. package/dist/node-esm/src/platform/browser/connection.d.ts +24 -7
  20. package/dist/node-esm/src/platform/connection.d.ts +6 -2
  21. package/dist/node-esm/src/platform/node/connection.d.ts +30 -14
  22. package/dist/node-esm/src/reference.d.ts +13 -0
  23. package/dist/node-esm/src/service.d.ts +3 -3
  24. package/dist/node-esm/test/integration/integration.test.d.ts +4 -0
  25. package/dist/node-esm/test/{unit → node}/connection.test.d.ts +0 -0
  26. package/dist/{test/unit/connection.test.d.ts → node-esm/test/node/stream.test.d.ts} +0 -0
  27. package/dist/node-esm/test/unit/connection.d.ts +4 -3
  28. package/dist/node-esm/test/unit/testshared.d.ts +2 -2
  29. package/dist/src/api.browser.d.ts +32 -1
  30. package/dist/src/api.d.ts +15 -0
  31. package/dist/src/api.node.d.ts +32 -1
  32. package/dist/src/implementation/connection.d.ts +14 -4
  33. package/dist/src/implementation/request.d.ts +5 -5
  34. package/dist/src/implementation/requestinfo.d.ts +14 -6
  35. package/dist/src/implementation/requests.d.ts +17 -16
  36. package/dist/src/platform/browser/connection.d.ts +24 -7
  37. package/dist/src/platform/connection.d.ts +6 -2
  38. package/dist/src/platform/node/connection.d.ts +30 -14
  39. package/dist/src/reference.d.ts +13 -0
  40. package/dist/src/service.d.ts +3 -3
  41. package/dist/storage-public.d.ts +46 -0
  42. package/dist/storage.d.ts +80 -11
  43. package/dist/test/integration/integration.test.d.ts +4 -0
  44. package/dist/test/node/connection.test.d.ts +17 -0
  45. package/dist/test/node/stream.test.d.ts +17 -0
  46. package/dist/test/unit/connection.d.ts +4 -3
  47. package/dist/test/unit/testshared.d.ts +2 -2
  48. package/package.json +6 -6
@@ -14,4 +14,35 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export {};
17
+ /// <reference types="node" />
18
+ import { StorageReference } from './public-types';
19
+ /**
20
+ * Downloads the data at the object's location. Returns an error if the object
21
+ * is not found.
22
+ *
23
+ * To use this functionality, you have to whitelist your app's origin in your
24
+ * Cloud Storage bucket. See also
25
+ * https://cloud.google.com/storage/docs/configuring-cors
26
+ *
27
+ * This API is not available in Node.
28
+ *
29
+ * @public
30
+ * @param ref - StorageReference where data should be downloaded.
31
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
32
+ * retrieve.
33
+ * @returns A Promise that resolves with a Blob containing the object's bytes
34
+ */
35
+ export declare function getBlob(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<Blob>;
36
+ /**
37
+ * Downloads the data at the object's location. Raises an error event if the
38
+ * object is not found.
39
+ *
40
+ * This API is only available in Node.
41
+ *
42
+ * @public
43
+ * @param ref - StorageReference where data should be downloaded.
44
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
45
+ * retrieve.
46
+ * @returns A stream with the object's data as bytes
47
+ */
48
+ export declare function getStream(ref: StorageReference, maxDownloadSizeBytes?: number): NodeJS.ReadableStream;
@@ -33,6 +33,21 @@ export { dataFromString as _dataFromString } from './implementation/string';
33
33
  export { invalidRootOperation as _invalidRootOperation, invalidArgument as _invalidArgument } from './implementation/error';
34
34
  export { TaskEvent as _TaskEvent, TaskState as _TaskState } from './implementation/taskenums';
35
35
  export { StringFormat };
36
+ /**
37
+ * Downloads the data at the object's location. Returns an error if the object
38
+ * is not found.
39
+ *
40
+ * To use this functionality, you have to whitelist your app's origin in your
41
+ * Cloud Storage bucket. See also
42
+ * https://cloud.google.com/storage/docs/configuring-cors
43
+ *
44
+ * @public
45
+ * @param ref - StorageReference where data should be downloaded.
46
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
47
+ * retrieve.
48
+ * @returns A Promise containing the object's bytes
49
+ */
50
+ export declare function getBytes(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<ArrayBuffer>;
36
51
  /**
37
52
  * Uploads data to this object's location.
38
53
  * The upload is not resumable.
@@ -14,4 +14,35 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export {};
17
+ /// <reference types="node" />
18
+ import { StorageReference } from './public-types';
19
+ /**
20
+ * Downloads the data at the object's location. Returns an error if the object
21
+ * is not found.
22
+ *
23
+ * To use this functionality, you have to whitelist your app's origin in your
24
+ * Cloud Storage bucket. See also
25
+ * https://cloud.google.com/storage/docs/configuring-cors
26
+ *
27
+ * This API is not available in Node.
28
+ *
29
+ * @public
30
+ * @param ref - StorageReference where data should be downloaded.
31
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
32
+ * retrieve.
33
+ * @returns A Promise that resolves with a Blob containing the object's bytes
34
+ */
35
+ export declare function getBlob(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<Blob>;
36
+ /**
37
+ * Downloads the data at the object's location. Raises an error event if the
38
+ * object is not found.
39
+ *
40
+ * This API is only available in Node.
41
+ *
42
+ * @public
43
+ * @param ref - StorageReference where data should be downloaded.
44
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
45
+ * retrieve.
46
+ * @returns A stream with the object's data as bytes
47
+ */
48
+ export declare function getStream(ref: StorageReference, maxDownloadSizeBytes?: number): NodeJS.ReadableStream;
@@ -14,21 +14,31 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ /// <reference types="node" />
17
18
  /** Network headers */
18
19
  export declare type Headers = Record<string, string>;
20
+ /** Response type exposed by the networking APIs. */
21
+ export declare type ConnectionType = string | ArrayBuffer | Blob | NodeJS.ReadableStream;
19
22
  /**
20
23
  * A lightweight wrapper around XMLHttpRequest with a
21
24
  * goog.net.XhrIo-like interface.
25
+ *
26
+ * You can create a new connection by invoking `newTextConnection()`,
27
+ * `newBytesConnection()` or `newStreamConnection()`.
22
28
  */
23
- export interface Connection {
29
+ export interface Connection<T extends ConnectionType> {
24
30
  /**
25
- * This method should never reject. In case of encountering an error, set an error code internally which can be accessed
26
- * by calling getErrorCode() by callers.
31
+ * Sends a request to the provided URL.
32
+ *
33
+ * This method never rejects its promise. In case of encountering an error,
34
+ * it sets an error code internally which can be accessed by calling
35
+ * getErrorCode() by callers.
27
36
  */
28
37
  send(url: string, method: string, body?: ArrayBufferView | Blob | string | null, headers?: Headers): Promise<void>;
29
38
  getErrorCode(): ErrorCode;
30
39
  getStatus(): number;
31
- getResponseText(): string;
40
+ getResponse(): T;
41
+ getErrorText(): string;
32
42
  /**
33
43
  * Abort the request.
34
44
  */
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { RequestInfo } from './requestinfo';
18
- import { Headers, Connection } from './connection';
18
+ import { Connection, Headers, ConnectionType } from './connection';
19
19
  export interface Request<T> {
20
20
  getPromise(): Promise<T>;
21
21
  /**
@@ -31,17 +31,17 @@ export interface Request<T> {
31
31
  * A collection of information about the result of a network request.
32
32
  * @param opt_canceled - Defaults to false.
33
33
  */
34
- export declare class RequestEndStatus {
34
+ export declare class RequestEndStatus<I extends ConnectionType> {
35
35
  wasSuccessCode: boolean;
36
- connection: Connection | null;
36
+ connection: Connection<I> | null;
37
37
  /**
38
38
  * True if the request was canceled.
39
39
  */
40
40
  canceled: boolean;
41
- constructor(wasSuccessCode: boolean, connection: Connection | null, canceled?: boolean);
41
+ constructor(wasSuccessCode: boolean, connection: Connection<I> | null, canceled?: boolean);
42
42
  }
43
43
  export declare function addAuthHeader_(headers: Headers, authToken: string | null): void;
44
44
  export declare function addVersionHeader_(headers: Headers, firebaseVersion?: string): void;
45
45
  export declare function addGmpidHeader_(headers: Headers, appId: string | null): void;
46
46
  export declare function addAppCheckHeader_(headers: Headers, appCheckToken: string | null): void;
47
- export declare function makeRequest<T>(requestInfo: RequestInfo<T>, appId: string | null, authToken: string | null, appCheckToken: string | null, requestFactory: () => Connection, firebaseVersion?: string): Request<T>;
47
+ export declare function makeRequest<I extends ConnectionType, O>(requestInfo: RequestInfo<I, O>, appId: string | null, authToken: string | null, appCheckToken: string | null, requestFactory: () => Connection<I>, firebaseVersion?: string): Request<O>;
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  import { StorageError } from './error';
18
- import { Headers, Connection } from './connection';
18
+ import { Headers, Connection, ConnectionType } from './connection';
19
19
  /**
20
20
  * Type for url params stored in RequestInfo.
21
21
  */
@@ -29,8 +29,16 @@ export interface UrlParams {
29
29
  * @param I - the type of the backend's network response
30
30
  * @param O - the output response type used by the rest of the SDK.
31
31
  */
32
- export declare type RequestHandler<I, O> = (connection: Connection, response: I) => O;
33
- export declare class RequestInfo<T> {
32
+ export declare type RequestHandler<I extends ConnectionType, O> = (connection: Connection<I>, response: I) => O;
33
+ /** A function to handle an error. */
34
+ export declare type ErrorHandler = (connection: Connection<ConnectionType>, response: StorageError) => StorageError;
35
+ /**
36
+ * Contains a fully specified request.
37
+ *
38
+ * @param I - the type of the backend's network response.
39
+ * @param O - the output response type used by the rest of the SDK.
40
+ */
41
+ export declare class RequestInfo<I extends ConnectionType, O> {
34
42
  url: string;
35
43
  method: string;
36
44
  /**
@@ -40,12 +48,12 @@ export declare class RequestInfo<T> {
40
48
  * Note: The XhrIo passed to this function may be reused after this callback
41
49
  * returns. Do not keep a reference to it in any way.
42
50
  */
43
- handler: RequestHandler<string, T>;
51
+ handler: RequestHandler<I, O>;
44
52
  timeout: number;
45
53
  urlParams: UrlParams;
46
54
  headers: Headers;
47
55
  body: Blob | string | Uint8Array | null;
48
- errorHandler: RequestHandler<StorageError, StorageError> | null;
56
+ errorHandler: ErrorHandler | null;
49
57
  /**
50
58
  * Called with the current number of bytes uploaded and total size (-1 if not
51
59
  * computable) of the request body (i.e. used to report upload progress).
@@ -61,5 +69,5 @@ export declare class RequestInfo<T> {
61
69
  * Note: The XhrIo passed to this function may be reused after this callback
62
70
  * returns. Do not keep a reference to it in any way.
63
71
  */
64
- handler: RequestHandler<string, T>, timeout: number);
72
+ handler: RequestHandler<I, O>, timeout: number);
65
73
  }
@@ -24,28 +24,29 @@ import { StorageError } from './error';
24
24
  import { Location } from './location';
25
25
  import { Mappings } from './metadata';
26
26
  import { RequestInfo } from './requestinfo';
27
- import { Connection } from './connection';
27
+ import { Connection, ConnectionType } from './connection';
28
28
  import { FirebaseStorageImpl } from '../service';
29
29
  /**
30
30
  * Throws the UNKNOWN StorageError if cndn is false.
31
31
  */
32
32
  export declare function handlerCheck(cndn: boolean): void;
33
- export declare function metadataHandler(service: FirebaseStorageImpl, mappings: Mappings): (p1: Connection, p2: string) => Metadata;
34
- export declare function listHandler(service: FirebaseStorageImpl, bucket: string): (p1: Connection, p2: string) => ListResult;
35
- export declare function downloadUrlHandler(service: FirebaseStorageImpl, mappings: Mappings): (p1: Connection, p2: string) => string | null;
36
- export declare function sharedErrorHandler(location: Location): (p1: Connection, p2: StorageError) => StorageError;
37
- export declare function objectErrorHandler(location: Location): (p1: Connection, p2: StorageError) => StorageError;
38
- export declare function getMetadata(service: FirebaseStorageImpl, location: Location, mappings: Mappings): RequestInfo<Metadata>;
39
- export declare function list(service: FirebaseStorageImpl, location: Location, delimiter?: string, pageToken?: string | null, maxResults?: number | null): RequestInfo<ListResult>;
40
- export declare function getDownloadUrl(service: FirebaseStorageImpl, location: Location, mappings: Mappings): RequestInfo<string | null>;
41
- export declare function updateMetadata(service: FirebaseStorageImpl, location: Location, metadata: Partial<Metadata>, mappings: Mappings): RequestInfo<Metadata>;
42
- export declare function deleteObject(service: FirebaseStorageImpl, location: Location): RequestInfo<void>;
33
+ export declare function metadataHandler(service: FirebaseStorageImpl, mappings: Mappings): (p1: Connection<string>, p2: string) => Metadata;
34
+ export declare function listHandler(service: FirebaseStorageImpl, bucket: string): (p1: Connection<string>, p2: string) => ListResult;
35
+ export declare function downloadUrlHandler(service: FirebaseStorageImpl, mappings: Mappings): (p1: Connection<string>, p2: string) => string | null;
36
+ export declare function sharedErrorHandler(location: Location): (p1: Connection<ConnectionType>, p2: StorageError) => StorageError;
37
+ export declare function objectErrorHandler(location: Location): (p1: Connection<ConnectionType>, p2: StorageError) => StorageError;
38
+ export declare function getMetadata(service: FirebaseStorageImpl, location: Location, mappings: Mappings): RequestInfo<string, Metadata>;
39
+ export declare function list(service: FirebaseStorageImpl, location: Location, delimiter?: string, pageToken?: string | null, maxResults?: number | null): RequestInfo<string, ListResult>;
40
+ export declare function getBytes<I extends ConnectionType>(service: FirebaseStorageImpl, location: Location, maxDownloadSizeBytes?: number): RequestInfo<I, I>;
41
+ export declare function getDownloadUrl(service: FirebaseStorageImpl, location: Location, mappings: Mappings): RequestInfo<string, string | null>;
42
+ export declare function updateMetadata(service: FirebaseStorageImpl, location: Location, metadata: Partial<Metadata>, mappings: Mappings): RequestInfo<string, Metadata>;
43
+ export declare function deleteObject(service: FirebaseStorageImpl, location: Location): RequestInfo<string, void>;
43
44
  export declare function determineContentType_(metadata: Metadata | null, blob: FbsBlob | null): string;
44
45
  export declare function metadataForUpload_(location: Location, blob: FbsBlob, metadata?: Metadata | null): Metadata;
45
46
  /**
46
47
  * Prepare RequestInfo for uploads as Content-Type: multipart.
47
48
  */
48
- export declare function multipartUpload(service: FirebaseStorageImpl, location: Location, mappings: Mappings, blob: FbsBlob, metadata?: Metadata | null): RequestInfo<Metadata>;
49
+ export declare function multipartUpload(service: FirebaseStorageImpl, location: Location, mappings: Mappings, blob: FbsBlob, metadata?: Metadata | null): RequestInfo<string, Metadata>;
49
50
  /**
50
51
  * @param current The number of bytes that have been uploaded so far.
51
52
  * @param total The total number of bytes in the upload.
@@ -60,12 +61,12 @@ export declare class ResumableUploadStatus {
60
61
  metadata: Metadata | null;
61
62
  constructor(current: number, total: number, finalized?: boolean, metadata?: Metadata | null);
62
63
  }
63
- export declare function checkResumeHeader_(xhr: Connection, allowed?: string[]): string;
64
- export declare function createResumableUpload(service: FirebaseStorageImpl, location: Location, mappings: Mappings, blob: FbsBlob, metadata?: Metadata | null): RequestInfo<string>;
64
+ export declare function checkResumeHeader_(xhr: Connection<string>, allowed?: string[]): string;
65
+ export declare function createResumableUpload(service: FirebaseStorageImpl, location: Location, mappings: Mappings, blob: FbsBlob, metadata?: Metadata | null): RequestInfo<string, string>;
65
66
  /**
66
67
  * @param url From a call to fbs.requests.createResumableUpload.
67
68
  */
68
- export declare function getResumableUploadStatus(service: FirebaseStorageImpl, location: Location, url: string, blob: FbsBlob): RequestInfo<ResumableUploadStatus>;
69
+ export declare function getResumableUploadStatus(service: FirebaseStorageImpl, location: Location, url: string, blob: FbsBlob): RequestInfo<string, ResumableUploadStatus>;
69
70
  /**
70
71
  * Any uploads via the resumable upload API must transfer a number of bytes
71
72
  * that is a multiple of this number.
@@ -80,4 +81,4 @@ export declare const RESUMABLE_UPLOAD_CHUNK_SIZE: number;
80
81
  * has a final size inconsistent with the blob, or the blob cannot be sliced
81
82
  * for upload.
82
83
  */
83
- export declare function continueResumableUpload(location: Location, service: FirebaseStorageImpl, url: string, blob: FbsBlob, chunkSize: number, mappings: Mappings, status?: ResumableUploadStatus | null, progressCallback?: ((p1: number, p2: number) => void) | null): RequestInfo<ResumableUploadStatus>;
84
+ export declare function continueResumableUpload(location: Location, service: FirebaseStorageImpl, url: string, blob: FbsBlob, chunkSize: number, mappings: Mappings, status?: ResumableUploadStatus | null, progressCallback?: ((p1: number, p2: number) => void) | null): RequestInfo<string, ResumableUploadStatus>;
@@ -14,26 +14,43 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { Headers, Connection, ErrorCode } from '../../implementation/connection';
17
+ /// <reference types="node" />
18
+ import { Connection, ConnectionType, ErrorCode, Headers } from '../../implementation/connection';
18
19
  /**
19
20
  * Network layer for browsers. We use this instead of goog.net.XhrIo because
20
21
  * goog.net.XhrIo is hyuuuuge and doesn't work in React Native on Android.
21
22
  */
22
- export declare class XhrConnection implements Connection {
23
- private xhr_;
23
+ declare abstract class XhrConnection<T extends ConnectionType> implements Connection<T> {
24
+ protected xhr_: XMLHttpRequest;
24
25
  private errorCode_;
25
26
  private sendPromise_;
26
- private sent_;
27
+ protected sent_: boolean;
27
28
  constructor();
29
+ abstract initXhr(): void;
28
30
  send(url: string, method: string, body?: ArrayBufferView | Blob | string, headers?: Headers): Promise<void>;
29
31
  getErrorCode(): ErrorCode;
30
32
  getStatus(): number;
31
- getResponseText(): string;
33
+ getResponse(): T;
34
+ getErrorText(): string;
32
35
  /** Aborts the request. */
33
36
  abort(): void;
34
37
  getResponseHeader(header: string): string | null;
35
38
  addUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
36
39
  removeUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
37
40
  }
38
- export declare function newConnection(): Connection;
39
- export declare function injectTestConnection(factory: (() => Connection) | null): void;
41
+ export declare class XhrTextConnection extends XhrConnection<string> {
42
+ initXhr(): void;
43
+ }
44
+ export declare function newTextConnection(): Connection<string>;
45
+ export declare class XhrBytesConnection extends XhrConnection<ArrayBuffer> {
46
+ private data_?;
47
+ initXhr(): void;
48
+ }
49
+ export declare function newBytesConnection(): Connection<ArrayBuffer>;
50
+ export declare class XhrBlobConnection extends XhrConnection<Blob> {
51
+ initXhr(): void;
52
+ }
53
+ export declare function newBlobConnection(): Connection<Blob>;
54
+ export declare function newStreamConnection(): Connection<NodeJS.ReadableStream>;
55
+ export declare function injectTestConnection(factory: (() => Connection<string>) | null): void;
56
+ export {};
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  /**
2
3
  * @license
3
4
  * Copyright 2020 Google LLC
@@ -15,5 +16,8 @@
15
16
  * limitations under the License.
16
17
  */
17
18
  import { Connection } from '../implementation/connection';
18
- export declare function newConnection(): Connection;
19
- export declare function injectTestConnection(factory: (() => Connection) | null): void;
19
+ export declare function injectTestConnection(factory: (() => Connection<string>) | null): void;
20
+ export declare function newTextConnection(): Connection<string>;
21
+ export declare function newBytesConnection(): Connection<ArrayBuffer>;
22
+ export declare function newBlobConnection(): Connection<Blob>;
23
+ export declare function newStreamConnection(): Connection<NodeJS.ReadableStream>;
@@ -14,32 +14,48 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { ErrorCode, Connection } from '../../implementation/connection';
17
+ /// <reference types="node" />
18
+ import { Connection, ConnectionType, ErrorCode } from '../../implementation/connection';
19
+ import nodeFetch, { Headers } from 'node-fetch';
18
20
  /**
19
21
  * Network layer that works in Node.
20
22
  *
21
23
  * This network implementation should not be used in browsers as it does not
22
24
  * support progress updates.
23
25
  */
24
- export declare class FetchConnection implements Connection {
25
- private errorCode_;
26
- private statusCode_;
27
- private body_;
28
- private headers_;
29
- private sent_;
30
- private fetch_;
26
+ declare abstract class FetchConnection<T extends ConnectionType> implements Connection<T> {
27
+ protected errorCode_: ErrorCode;
28
+ protected statusCode_: number | undefined;
29
+ protected body_: ArrayBuffer | undefined;
30
+ protected errorText_: string;
31
+ protected headers_: Headers | undefined;
32
+ protected sent_: boolean;
33
+ protected fetch_: typeof nodeFetch;
31
34
  constructor();
32
35
  send(url: string, method: string, body?: ArrayBufferView | Blob | string, headers?: Record<string, string>): Promise<void>;
33
36
  getErrorCode(): ErrorCode;
34
37
  getStatus(): number;
35
- getResponseText(): string;
38
+ abstract getResponse(): T;
39
+ getErrorText(): string;
36
40
  abort(): void;
37
41
  getResponseHeader(header: string): string | null;
38
42
  addUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
39
- /**
40
- * @override
41
- */
42
43
  removeUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
43
44
  }
44
- export declare function newConnection(): Connection;
45
- export declare function injectTestConnection(factory: (() => Connection) | null): void;
45
+ export declare class FetchTextConnection extends FetchConnection<string> {
46
+ getResponse(): string;
47
+ }
48
+ export declare function newTextConnection(): Connection<string>;
49
+ export declare class FetchBytesConnection extends FetchConnection<ArrayBuffer> {
50
+ getResponse(): ArrayBuffer;
51
+ }
52
+ export declare function newBytesConnection(): Connection<ArrayBuffer>;
53
+ export declare class FetchStreamConnection extends FetchConnection<NodeJS.ReadableStream> {
54
+ private stream_;
55
+ send(url: string, method: string, body?: ArrayBufferView | Blob | string, headers?: Record<string, string>): Promise<void>;
56
+ getResponse(): NodeJS.ReadableStream;
57
+ }
58
+ export declare function newStreamConnection(): Connection<NodeJS.ReadableStream>;
59
+ export declare function newBlobConnection(): Connection<Blob>;
60
+ export declare function injectTestConnection(factory: (() => Connection<string>) | null): void;
61
+ export {};
@@ -14,6 +14,7 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ /// <reference types="node" />
17
18
  import { Location } from './implementation/location';
18
19
  import { ListOptions, UploadResult } from './public-types';
19
20
  import { StringFormat } from './implementation/string';
@@ -75,6 +76,18 @@ export declare class Reference {
75
76
  */
76
77
  _throwIfRoot(name: string): void;
77
78
  }
79
+ /**
80
+ * Download the bytes at the object's location.
81
+ * @returns A Promise containing the downloaded bytes.
82
+ */
83
+ export declare function getBytesInternal(ref: Reference, maxDownloadSizeBytes?: number): Promise<ArrayBuffer>;
84
+ /**
85
+ * Download the bytes at the object's location.
86
+ * @returns A Promise containing the downloaded blob.
87
+ */
88
+ export declare function getBlobInternal(ref: Reference, maxDownloadSizeBytes?: number): Promise<Blob>;
89
+ /** Stream the bytes at the object's location. */
90
+ export declare function getStreamInternal(ref: Reference, maxDownloadSizeBytes?: number): NodeJS.ReadableStream;
78
91
  /**
79
92
  * Uploads data to this object's location.
80
93
  * The upload is not resumable.
@@ -24,7 +24,7 @@ import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types
24
24
  import { FirebaseApp } from '@firebase/app';
25
25
  import { FirebaseStorage } from './public-types';
26
26
  import { EmulatorMockTokenOptions } from '@firebase/util';
27
- import { Connection } from './implementation/connection';
27
+ import { Connection, ConnectionType } from './implementation/connection';
28
28
  export declare function isUrl(path?: string): boolean;
29
29
  /**
30
30
  * Returns a storage Reference for the given url.
@@ -125,6 +125,6 @@ export declare class FirebaseStorageImpl implements FirebaseStorage {
125
125
  * @param requestInfo - HTTP RequestInfo object
126
126
  * @param authToken - Firebase auth token
127
127
  */
128
- _makeRequest<T>(requestInfo: RequestInfo<T>, requestFactory: () => Connection, authToken: string | null, appCheckToken: string | null): Request<T>;
129
- makeRequestWithTokens<T>(requestInfo: RequestInfo<T>, requestFactory: () => Connection): Promise<T>;
128
+ _makeRequest<I extends ConnectionType, O>(requestInfo: RequestInfo<I, O>, requestFactory: () => Connection<I>, authToken: string | null, appCheckToken: string | null): Request<O>;
129
+ makeRequestWithTokens<I extends ConnectionType, O>(requestInfo: RequestInfo<I, O>, requestFactory: () => Connection<I>): Promise<O>;
130
130
  }
@@ -14,7 +14,11 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ import * as types from '../../src/public-types';
17
19
  export declare const PROJECT_ID: any;
18
20
  export declare const STORAGE_BUCKET: any;
19
21
  export declare const API_KEY: any;
20
22
  export declare const AUTH_DOMAIN: any;
23
+ export declare function createApp(): Promise<FirebaseApp>;
24
+ export declare function createStorage(app: FirebaseApp): types.FirebaseStorage;
@@ -21,7 +21,7 @@ export declare enum State {
21
21
  SENT = 1,
22
22
  DONE = 2
23
23
  }
24
- export declare class TestingConnection implements Connection {
24
+ export declare class TestingConnection implements Connection<string> {
25
25
  private state;
26
26
  private sendPromise;
27
27
  private resolve;
@@ -37,10 +37,11 @@ export declare class TestingConnection implements Connection {
37
37
  }): void;
38
38
  getErrorCode(): ErrorCode;
39
39
  getStatus(): number;
40
- getResponseText(): string;
40
+ getResponse(): string;
41
+ getErrorText(): string;
41
42
  abort(): void;
42
43
  getResponseHeader(header: string): string | null;
43
44
  addUploadProgressListener(): void;
44
45
  removeUploadProgressListener(): void;
45
46
  }
46
- export declare function newTestConnection(sendHook?: SendHook | null): Connection;
47
+ export declare function newTestConnection(sendHook?: SendHook | null): Connection<string>;
@@ -1,6 +1,6 @@
1
1
  import { FirebaseApp } from '@firebase/app-types';
2
2
  import { StorageError } from '../../src/implementation/error';
3
- import { Headers, Connection } from '../../src/implementation/connection';
3
+ import { Headers, Connection, ConnectionType } from '../../src/implementation/connection';
4
4
  import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
5
5
  import { Provider } from '@firebase/component';
6
6
  import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
@@ -24,7 +24,7 @@ export declare function makeFakeAppCheckProvider(tokenResult: {
24
24
  * Returns something that looks like an fbs.XhrIo with the given headers
25
25
  * and status.
26
26
  */
27
- export declare function fakeXhrIo(headers: Headers, status?: number): Connection;
27
+ export declare function fakeXhrIo<I extends ConnectionType = string>(headers: Headers, status?: number): Connection<I>;
28
28
  /**
29
29
  * Binds ignoring types. Used to test calls involving improper arguments.
30
30
  */
@@ -14,4 +14,35 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export {};
17
+ /// <reference types="node" />
18
+ import { StorageReference } from './public-types';
19
+ /**
20
+ * Downloads the data at the object's location. Returns an error if the object
21
+ * is not found.
22
+ *
23
+ * To use this functionality, you have to whitelist your app's origin in your
24
+ * Cloud Storage bucket. See also
25
+ * https://cloud.google.com/storage/docs/configuring-cors
26
+ *
27
+ * This API is not available in Node.
28
+ *
29
+ * @public
30
+ * @param ref - StorageReference where data should be downloaded.
31
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
32
+ * retrieve.
33
+ * @returns A Promise that resolves with a Blob containing the object's bytes
34
+ */
35
+ export declare function getBlob(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<Blob>;
36
+ /**
37
+ * Downloads the data at the object's location. Raises an error event if the
38
+ * object is not found.
39
+ *
40
+ * This API is only available in Node.
41
+ *
42
+ * @public
43
+ * @param ref - StorageReference where data should be downloaded.
44
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
45
+ * retrieve.
46
+ * @returns A stream with the object's data as bytes
47
+ */
48
+ export declare function getStream(ref: StorageReference, maxDownloadSizeBytes?: number): NodeJS.ReadableStream;
package/dist/src/api.d.ts CHANGED
@@ -33,6 +33,21 @@ export { dataFromString as _dataFromString } from './implementation/string';
33
33
  export { invalidRootOperation as _invalidRootOperation, invalidArgument as _invalidArgument } from './implementation/error';
34
34
  export { TaskEvent as _TaskEvent, TaskState as _TaskState } from './implementation/taskenums';
35
35
  export { StringFormat };
36
+ /**
37
+ * Downloads the data at the object's location. Returns an error if the object
38
+ * is not found.
39
+ *
40
+ * To use this functionality, you have to whitelist your app's origin in your
41
+ * Cloud Storage bucket. See also
42
+ * https://cloud.google.com/storage/docs/configuring-cors
43
+ *
44
+ * @public
45
+ * @param ref - StorageReference where data should be downloaded.
46
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
47
+ * retrieve.
48
+ * @returns A Promise containing the object's bytes
49
+ */
50
+ export declare function getBytes(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<ArrayBuffer>;
36
51
  /**
37
52
  * Uploads data to this object's location.
38
53
  * The upload is not resumable.
@@ -14,4 +14,35 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- export {};
17
+ /// <reference types="node" />
18
+ import { StorageReference } from './public-types';
19
+ /**
20
+ * Downloads the data at the object's location. Returns an error if the object
21
+ * is not found.
22
+ *
23
+ * To use this functionality, you have to whitelist your app's origin in your
24
+ * Cloud Storage bucket. See also
25
+ * https://cloud.google.com/storage/docs/configuring-cors
26
+ *
27
+ * This API is not available in Node.
28
+ *
29
+ * @public
30
+ * @param ref - StorageReference where data should be downloaded.
31
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
32
+ * retrieve.
33
+ * @returns A Promise that resolves with a Blob containing the object's bytes
34
+ */
35
+ export declare function getBlob(ref: StorageReference, maxDownloadSizeBytes?: number): Promise<Blob>;
36
+ /**
37
+ * Downloads the data at the object's location. Raises an error event if the
38
+ * object is not found.
39
+ *
40
+ * This API is only available in Node.
41
+ *
42
+ * @public
43
+ * @param ref - StorageReference where data should be downloaded.
44
+ * @param maxDownloadSizeBytes - If set, the maximum allowed size in bytes to
45
+ * retrieve.
46
+ * @returns A stream with the object's data as bytes
47
+ */
48
+ export declare function getStream(ref: StorageReference, maxDownloadSizeBytes?: number): NodeJS.ReadableStream;