@firebase/storage 0.8.3 → 0.8.4-2021927221742

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2017 Google LLC
3
+ * Copyright 2021 Google LLC
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -14,13 +14,4 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- /**
18
- * @fileoverview Replacement for goog.net.XhrIoPool that works with fbs.XhrIo.
19
- */
20
- import { Connection } from './connection';
21
- /**
22
- * Factory-like class for creating XhrIo instances.
23
- */
24
- export declare class ConnectionPool {
25
- createConnection(): Connection;
26
- }
17
+ export {};
package/dist/src/api.d.ts CHANGED
@@ -32,6 +32,7 @@ export { FbsBlob as _FbsBlob } from './implementation/blob';
32
32
  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
+ export { StringFormat };
35
36
  /**
36
37
  * Uploads data to this object's location.
37
38
  * The upload is not resumable.
@@ -159,7 +160,6 @@ export declare function ref(storageOrRef: FirebaseStorage | StorageReference, pa
159
160
  * @internal
160
161
  */
161
162
  export declare function _getChild(ref: StorageReference, childPath: string): Reference;
162
- export { StringFormat } from './implementation/string';
163
163
  /**
164
164
  * Gets a {@link FirebaseStorage} instance for the given Firebase app.
165
165
  * @public
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright 2017 Google LLC
3
+ * Copyright 2021 Google LLC
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -14,8 +14,4 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import { Request } from './request';
18
- import { RequestInfo } from './requestinfo';
19
- import { ConnectionPool } from './connectionPool';
20
- declare type requestMaker = <T>(requestInfo: RequestInfo<T>, appId: string | null, authToken: string | null, pool: ConnectionPool) => Request<T>;
21
- export { requestMaker };
17
+ export {};
@@ -14,17 +14,17 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- /**
18
- * Network headers
19
- */
20
- export interface Headers {
21
- [name: string]: string;
22
- }
17
+ /** Network headers */
18
+ export declare type Headers = Record<string, string>;
23
19
  /**
24
20
  * A lightweight wrapper around XMLHttpRequest with a
25
21
  * goog.net.XhrIo-like interface.
26
22
  */
27
23
  export interface Connection {
24
+ /**
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.
27
+ */
28
28
  send(url: string, method: string, body?: ArrayBufferView | Blob | string | null, headers?: Headers): Promise<void>;
29
29
  getErrorCode(): ErrorCode;
30
30
  getStatus(): number;
@@ -16,7 +16,6 @@
16
16
  */
17
17
  import { RequestInfo } from './requestinfo';
18
18
  import { Headers, Connection } from './connection';
19
- import { ConnectionPool } from './connectionPool';
20
19
  export interface Request<T> {
21
20
  getPromise(): Promise<T>;
22
21
  /**
@@ -45,4 +44,4 @@ export declare function addAuthHeader_(headers: Headers, authToken: string | nul
45
44
  export declare function addVersionHeader_(headers: Headers, firebaseVersion?: string): void;
46
45
  export declare function addGmpidHeader_(headers: Headers, appId: string | null): void;
47
46
  export declare function addAppCheckHeader_(headers: Headers, appCheckToken: string | null): void;
48
- export declare function makeRequest<T>(requestInfo: RequestInfo<T>, appId: string | null, authToken: string | null, appCheckToken: string | null, pool: ConnectionPool, firebaseVersion?: string): Request<T>;
47
+ export declare function makeRequest<T>(requestInfo: RequestInfo<T>, appId: string | null, authToken: string | null, appCheckToken: string | null, requestFactory: () => Connection, firebaseVersion?: string): Request<T>;
@@ -22,6 +22,14 @@ import { Headers, Connection } from './connection';
22
22
  export interface UrlParams {
23
23
  [name: string]: string | number;
24
24
  }
25
+ /**
26
+ * A function that converts a server response to the API type expected by the
27
+ * SDK.
28
+ *
29
+ * @param I - the type of the backend's network response
30
+ * @param O - the output response type used by the rest of the SDK.
31
+ */
32
+ export declare type RequestHandler<I, O> = (connection: Connection, response: I) => O;
25
33
  export declare class RequestInfo<T> {
26
34
  url: string;
27
35
  method: string;
@@ -32,12 +40,12 @@ export declare class RequestInfo<T> {
32
40
  * Note: The XhrIo passed to this function may be reused after this callback
33
41
  * returns. Do not keep a reference to it in any way.
34
42
  */
35
- handler: (p1: Connection, p2: string) => T;
43
+ handler: RequestHandler<string, T>;
36
44
  timeout: number;
37
45
  urlParams: UrlParams;
38
46
  headers: Headers;
39
47
  body: Blob | string | Uint8Array | null;
40
- errorHandler: ((p1: Connection, p2: StorageError) => StorageError) | null;
48
+ errorHandler: RequestHandler<StorageError, StorageError> | null;
41
49
  /**
42
50
  * Called with the current number of bytes uploaded and total size (-1 if not
43
51
  * computable) of the request body (i.e. used to report upload progress).
@@ -53,5 +61,5 @@ export declare class RequestInfo<T> {
53
61
  * Note: The XhrIo passed to this function may be reused after this callback
54
62
  * returns. Do not keep a reference to it in any way.
55
63
  */
56
- handler: (p1: Connection, p2: string) => T, timeout: number);
64
+ handler: RequestHandler<string, T>, timeout: number);
57
65
  }
@@ -3,5 +3,5 @@
3
3
  *
4
4
  * @packageDocumentation
5
5
  */
6
- export { StringFormat } from '../src/implementation/string';
7
6
  export * from './api';
7
+ export * from './api.browser';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Cloud Storage for Firebase
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export * from './api';
7
+ export * from './api.node';
@@ -25,38 +25,15 @@ export declare class XhrConnection implements Connection {
25
25
  private sendPromise_;
26
26
  private sent_;
27
27
  constructor();
28
- /**
29
- * @override
30
- */
31
28
  send(url: string, method: string, body?: ArrayBufferView | Blob | string, headers?: Headers): Promise<void>;
32
- /**
33
- * @override
34
- */
35
29
  getErrorCode(): ErrorCode;
36
- /**
37
- * @override
38
- */
39
30
  getStatus(): number;
40
- /**
41
- * @override
42
- */
43
31
  getResponseText(): string;
44
- /**
45
- * Aborts the request.
46
- * @override
47
- */
32
+ /** Aborts the request. */
48
33
  abort(): void;
49
- /**
50
- * @override
51
- */
52
34
  getResponseHeader(header: string): string | null;
53
- /**
54
- * @override
55
- */
56
35
  addUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
57
- /**
58
- * @override
59
- */
60
36
  removeUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
61
37
  }
62
38
  export declare function newConnection(): Connection;
39
+ export declare function injectTestConnection(factory: (() => Connection) | null): void;
@@ -16,3 +16,4 @@
16
16
  */
17
17
  import { Connection } from '../implementation/connection';
18
18
  export declare function newConnection(): Connection;
19
+ export declare function injectTestConnection(factory: (() => Connection) | null): void;
@@ -27,6 +27,7 @@ export declare class FetchConnection implements Connection {
27
27
  private body_;
28
28
  private headers_;
29
29
  private sent_;
30
+ private fetch_;
30
31
  constructor();
31
32
  send(url: string, method: string, body?: ArrayBufferView | Blob | string, headers?: Record<string, string>): Promise<void>;
32
33
  getErrorCode(): ErrorCode;
@@ -41,3 +42,4 @@ export declare class FetchConnection implements Connection {
41
42
  removeUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
42
43
  }
43
44
  export declare function newConnection(): Connection;
45
+ export declare function injectTestConnection(factory: (() => Connection) | null): void;
@@ -17,7 +17,6 @@
17
17
  import { Location } from './implementation/location';
18
18
  import { Request } from './implementation/request';
19
19
  import { RequestInfo } from './implementation/requestinfo';
20
- import { ConnectionPool } from './implementation/connectionPool';
21
20
  import { Reference } from './reference';
22
21
  import { Provider } from '@firebase/component';
23
22
  import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
@@ -25,6 +24,7 @@ import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types
25
24
  import { FirebaseApp } from '@firebase/app';
26
25
  import { FirebaseStorage } from './public-types';
27
26
  import { EmulatorMockTokenOptions } from '@firebase/util';
27
+ import { Connection } from './implementation/connection';
28
28
  export declare function isUrl(path?: string): boolean;
29
29
  /**
30
30
  * Returns a storage Reference for the given url.
@@ -64,7 +64,6 @@ export declare class FirebaseStorageImpl implements FirebaseStorage {
64
64
  /**
65
65
  * @internal
66
66
  */
67
- readonly _pool: ConnectionPool;
68
67
  readonly _url?: string | undefined;
69
68
  readonly _firebaseVersion?: string | undefined;
70
69
  _bucket: Location | null;
@@ -93,7 +92,7 @@ export declare class FirebaseStorageImpl implements FirebaseStorage {
93
92
  /**
94
93
  * @internal
95
94
  */
96
- _pool: ConnectionPool, _url?: string | undefined, _firebaseVersion?: string | undefined);
95
+ _url?: string | undefined, _firebaseVersion?: string | undefined);
97
96
  /**
98
97
  * The host string for this service, in the form of `host` or
99
98
  * `host:port`.
@@ -126,6 +125,6 @@ export declare class FirebaseStorageImpl implements FirebaseStorage {
126
125
  * @param requestInfo - HTTP RequestInfo object
127
126
  * @param authToken - Firebase auth token
128
127
  */
129
- _makeRequest<T>(requestInfo: RequestInfo<T>, authToken: string | null, appCheckToken: string | null): Request<T>;
130
- makeRequestWithTokens<T>(requestInfo: RequestInfo<T>): Promise<Request<T>>;
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>;
131
130
  }
package/dist/storage.d.ts CHANGED
@@ -26,6 +26,10 @@ declare type CompleteFn_2 = () => void;
26
26
  * goog.net.XhrIo-like interface.
27
27
  */
28
28
  declare interface Connection {
29
+ /**
30
+ * This method should never reject. In case of encountering an error, set an error code internally which can be accessed
31
+ * by calling getErrorCode() by callers.
32
+ */
29
33
  send(url: string, method: string, body?: ArrayBufferView | Blob | string | null, headers?: Headers_2): Promise<void>;
30
34
  getErrorCode(): ErrorCode;
31
35
  getStatus(): number;
@@ -39,13 +43,6 @@ declare interface Connection {
39
43
  removeUploadProgressListener(listener: (p1: ProgressEvent) => void): void;
40
44
  }
41
45
 
42
- /**
43
- * Factory-like class for creating XhrIo instances.
44
- */
45
- declare class ConnectionPool {
46
- createConnection(): Connection;
47
- }
48
-
49
46
  /**
50
47
  * Modify this {@link FirebaseStorage} instance to communicate with the Cloud Storage emulator.
51
48
  *
@@ -163,7 +160,6 @@ export declare class _FirebaseStorageImpl implements FirebaseStorage {
163
160
  /**
164
161
  * @internal
165
162
  */
166
- readonly _pool: ConnectionPool;
167
163
  readonly _url?: string | undefined;
168
164
  readonly _firebaseVersion?: string | undefined;
169
165
  _bucket: _Location | null;
@@ -192,7 +188,7 @@ export declare class _FirebaseStorageImpl implements FirebaseStorage {
192
188
  /**
193
189
  * @internal
194
190
  */
195
- _pool: ConnectionPool, _url?: string | undefined, _firebaseVersion?: string | undefined);
191
+ _url?: string | undefined, _firebaseVersion?: string | undefined);
196
192
  /**
197
193
  * The host string for this service, in the form of `host` or
198
194
  * `host:port`.
@@ -225,8 +221,8 @@ export declare class _FirebaseStorageImpl implements FirebaseStorage {
225
221
  * @param requestInfo - HTTP RequestInfo object
226
222
  * @param authToken - Firebase auth token
227
223
  */
228
- _makeRequest<T>(requestInfo: RequestInfo_2<T>, authToken: string | null, appCheckToken: string | null): Request_2<T>;
229
- makeRequestWithTokens<T>(requestInfo: RequestInfo_2<T>): Promise<Request_2<T>>;
224
+ _makeRequest<T>(requestInfo: RequestInfo_2<T>, requestFactory: () => Connection, authToken: string | null, appCheckToken: string | null): Request_2<T>;
225
+ makeRequestWithTokens<T>(requestInfo: RequestInfo_2<T>, requestFactory: () => Connection): Promise<T>;
230
226
  }
231
227
 
232
228
  /**
@@ -328,12 +324,8 @@ export declare function getStorage(app?: FirebaseApp, bucketUrl?: string): Fireb
328
324
  * See the License for the specific language governing permissions and
329
325
  * limitations under the License.
330
326
  */
331
- /**
332
- * Network headers
333
- */
334
- declare interface Headers_2 {
335
- [name: string]: string;
336
- }
327
+ /** Network headers */
328
+ declare type Headers_2 = Record<string, string>;
337
329
 
338
330
  /**
339
331
  * Internal enum for task state.
@@ -580,6 +572,15 @@ declare interface Request_2<T> {
580
572
  cancel(appDelete?: boolean): void;
581
573
  }
582
574
 
575
+ /**
576
+ * A function that converts a server response to the API type expected by the
577
+ * SDK.
578
+ *
579
+ * @param I - the type of the backend's network response
580
+ * @param O - the output response type used by the rest of the SDK.
581
+ */
582
+ declare type RequestHandler<I, O> = (connection: Connection, response: I) => O;
583
+
583
584
  declare class RequestInfo_2<T> {
584
585
  url: string;
585
586
  method: string;
@@ -590,12 +591,12 @@ declare class RequestInfo_2<T> {
590
591
  * Note: The XhrIo passed to this function may be reused after this callback
591
592
  * returns. Do not keep a reference to it in any way.
592
593
  */
593
- handler: (p1: Connection, p2: string) => T;
594
+ handler: RequestHandler<string, T>;
594
595
  timeout: number;
595
596
  urlParams: UrlParams;
596
597
  headers: Headers_2;
597
598
  body: Blob | string | Uint8Array | null;
598
- errorHandler: ((p1: Connection, p2: StorageError_2) => StorageError_2) | null;
599
+ errorHandler: RequestHandler<StorageError_2, StorageError_2> | null;
599
600
  /**
600
601
  * Called with the current number of bytes uploaded and total size (-1 if not
601
602
  * computable) of the request body (i.e. used to report upload progress).
@@ -611,7 +612,7 @@ declare class RequestInfo_2<T> {
611
612
  * Note: The XhrIo passed to this function may be reused after this callback
612
613
  * returns. Do not keep a reference to it in any way.
613
614
  */
614
- handler: (p1: Connection, p2: string) => T, timeout: number);
615
+ handler: RequestHandler<string, T>, timeout: number);
615
616
  }
616
617
 
617
618
  /**
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 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
+ export {};
@@ -43,3 +43,4 @@ export declare class TestingConnection implements Connection {
43
43
  addUploadProgressListener(): void;
44
44
  removeUploadProgressListener(): void;
45
45
  }
46
+ export declare function newTestConnection(sendHook?: SendHook | null): Connection;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2021 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
+ export {};
@@ -1,8 +1,6 @@
1
1
  import { FirebaseApp } from '@firebase/app-types';
2
2
  import { StorageError } from '../../src/implementation/error';
3
3
  import { Headers, Connection } from '../../src/implementation/connection';
4
- import { ConnectionPool } from '../../src/implementation/connectionPool';
5
- import { SendHook } from './connection';
6
4
  import { FirebaseAuthInternalName } from '@firebase/auth-interop-types';
7
5
  import { Provider } from '@firebase/component';
8
6
  import { AppCheckInternalComponentName } from '@firebase/app-check-interop-types';
@@ -22,7 +20,6 @@ export declare function makeFakeAuthProvider(token: {
22
20
  export declare function makeFakeAppCheckProvider(tokenResult: {
23
21
  token: string;
24
22
  }): Provider<AppCheckInternalComponentName>;
25
- export declare function makePool(sendHook: SendHook | null): ConnectionPool;
26
23
  /**
27
24
  * Returns something that looks like an fbs.XhrIo with the given headers
28
25
  * and status.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@firebase/storage",
3
- "version": "0.8.3",
3
+ "version": "0.8.4-2021927221742",
4
4
  "description": "",
5
5
  "author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
6
6
  "main": "dist/index.cjs.js",
@@ -22,7 +22,7 @@
22
22
  "test:browser:unit": "karma start --single-run --unit",
23
23
  "test:browser:integration": "karma start --single-run --integration",
24
24
  "test:browser": "karma start --single-run",
25
- "test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.ts --config ../../config/mocharc.node.js",
25
+ "test:node": "TS_NODE_FILES=true TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file src/index.node.ts --config ../../config/mocharc.node.js",
26
26
  "test:debug": "karma start --browser=Chrome",
27
27
  "prettier": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
28
28
  "api-report": "api-extractor run --local --verbose && ts-node-script ../../repo-scripts/prune-dts/prune-dts.ts --input dist/storage-public.d.ts --output dist/storage-public.d.ts",
@@ -32,16 +32,16 @@
32
32
  "dependencies": {
33
33
  "@firebase/util": "1.4.0",
34
34
  "@firebase/component": "0.5.7",
35
- "node-fetch": "2.6.2",
35
+ "node-fetch": "2.6.5",
36
36
  "tslib": "^2.1.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@firebase/app": "0.x"
40
40
  },
41
41
  "devDependencies": {
42
- "@firebase/app": "0.7.1",
43
- "@firebase/auth": "0.18.0",
44
- "rollup": "2.56.3",
42
+ "@firebase/app": "0.7.4",
43
+ "@firebase/auth": "0.19.0-2021927221742",
44
+ "rollup": "2.57.0",
45
45
  "@rollup/plugin-alias": "3.1.5",
46
46
  "@rollup/plugin-json": "4.1.0",
47
47
  "rollup-plugin-typescript2": "0.30.0",