Skip to content

Commit 317394d

Browse files
Remove ConnectionPool (#5469)
1 parent f485276 commit 317394d

22 files changed

+161
-210
lines changed

common/api-review/storage.api.md

+4-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>;
@@ -78,23 +78,20 @@ export class _FirebaseStorageImpl implements FirebaseStorage {
7878
get host(): string;
7979
set host(host: string);
8080
// Warning: (ae-forgotten-export) The symbol "RequestInfo" needs to be exported by the entry point index.d.ts
81+
// Warning: (ae-forgotten-export) The symbol "Connection" needs to be exported by the entry point index.d.ts
8182
// Warning: (ae-forgotten-export) The symbol "Request" needs to be exported by the entry point index.d.ts
8283
//
8384
// (undocumented)
84-
_makeRequest<T>(requestInfo: RequestInfo_2<T>, authToken: string | null, appCheckToken: string | null): Request_2<T>;
85+
_makeRequest<T>(requestInfo: RequestInfo_2<T>, requestFactory: () => Connection, authToken: string | null, appCheckToken: string | null): Request_2<T>;
8586
// (undocumented)
86-
makeRequestWithTokens<T>(requestInfo: RequestInfo_2<T>): Promise<Request_2<T>>;
87+
makeRequestWithTokens<T>(requestInfo: RequestInfo_2<T>, requestFactory: () => Connection): Promise<T>;
8788
_makeStorageReference(loc: _Location): _Reference;
8889
get maxOperationRetryTime(): number;
8990
set maxOperationRetryTime(time: number);
9091
get maxUploadRetryTime(): number;
9192
set maxUploadRetryTime(time: number);
9293
// (undocumented)
9394
_overrideAuthToken?: string;
94-
// Warning: (ae-forgotten-export) The symbol "ConnectionPool" needs to be exported by the entry point index.d.ts
95-
//
96-
// (undocumented)
97-
readonly _pool: ConnectionPool;
9895
// (undocumented)
9996
_protocol: string;
10097
// (undocumented)

packages/storage-compat/src/task.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import {
1919
UploadTask,
20-
FirebaseStorageError,
20+
StorageError,
2121
UploadTaskSnapshot,
2222
TaskEvent,
2323
StorageObserver
@@ -48,7 +48,7 @@ export class UploadTaskCompat implements types.UploadTask, Compat<UploadTask> {
4848

4949
then(
5050
onFulfilled?: ((a: UploadTaskSnapshotCompat) => unknown) | null,
51-
onRejected?: ((a: FirebaseStorageError) => unknown) | null
51+
onRejected?: ((a: StorageError) => unknown) | null
5252
): Promise<unknown> {
5353
return this._delegate.then(snapshot => {
5454
if (onFulfilled) {
@@ -65,7 +65,7 @@ export class UploadTaskCompat implements types.UploadTask, Compat<UploadTask> {
6565
| types.StorageObserver<UploadTaskSnapshotCompat>
6666
| null
6767
| ((a: UploadTaskSnapshotCompat) => unknown),
68-
error?: (error: FirebaseStorageError) => void | null,
68+
error?: (error: StorageError) => void | null,
6969
completed?: () => void | null
7070
): Unsubscribe | Subscribe<UploadTaskSnapshotCompat> {
7171
let wrappedNextOrObserver:
@@ -123,7 +123,7 @@ export type NextFn<T> = (value: T) => void;
123123
* A function that is called with a `FirebaseStorageError`
124124
* if the event stream ends due to an error.
125125
*/
126-
export type ErrorFn = (error: FirebaseStorageError) => void;
126+
export type ErrorFn = (error: StorageError) => void;
127127

128128
/**
129129
* A function that is called if the event stream ends normally.

packages/storage-compat/test/unit/reference.test.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,15 @@ describe('Firebase Storage > Reference', () => {
162162

163163
describe('Argument verification', () => {
164164
describe('list', () => {
165-
it('throws on invalid maxResults', async () => {
165+
it('throws on invalid maxResults', () => {
166166
const child = service.refFromURL('gs://test-bucket/hello');
167-
await expect(child.list({ maxResults: 0 })).to.be.rejectedWith(
167+
expect(() => child.list({ maxResults: 0 })).to.throw(
168168
'storage/invalid-argument'
169169
);
170-
await expect(child.list({ maxResults: -4 })).to.be.rejectedWith(
170+
expect(() => child.list({ maxResults: -4 })).to.throw(
171171
'storage/invalid-argument'
172172
);
173-
await expect(child.list({ maxResults: 1001 })).to.be.rejectedWith(
173+
expect(() => child.list({ maxResults: 1001 })).to.throw(
174174
'storage/invalid-argument'
175175
);
176176
});
@@ -195,18 +195,18 @@ describe('Firebase Storage > Reference', () => {
195195
it('delete throws', () => {
196196
expect(() => root.delete()).to.throw('storage/invalid-root-operation');
197197
});
198-
it('getMetadata throws', async () => {
199-
await expect(root.getMetadata()).to.be.rejectedWith(
198+
it('getMetadata throws', () => {
199+
expect(() => root.getMetadata()).to.throw(
200200
'storage/invalid-root-operation'
201201
);
202202
});
203-
it('updateMetadata throws', async () => {
204-
await expect(root.updateMetadata({})).to.be.rejectedWith(
203+
it('updateMetadata throws', () => {
204+
expect(() => root.updateMetadata({})).to.throw(
205205
'storage/invalid-root-operation'
206206
);
207207
});
208208
it('getDownloadURL throws', async () => {
209-
await expect(root.getDownloadURL()).to.be.rejectedWith(
209+
expect(() => root.getDownloadURL()).to.throw(
210210
'storage/invalid-root-operation'
211211
);
212212
});

packages/storage-compat/test/unit/service.test.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ import { expect } from 'chai';
1919
import { stub } from 'sinon';
2020
import * as modularStorage from '@firebase/storage';
2121
import { makeTestCompatStorage, fakeApp, fakeStorage } from '../utils';
22-
import {
23-
FirebaseStorage,
24-
getStorage,
25-
FirebaseStorageError
26-
} from '@firebase/storage';
22+
import { FirebaseStorage, getStorage, StorageError } from '@firebase/storage';
2723
import firebase from '@firebase/app-compat';
2824
import { StorageServiceCompat } from '../../src/service';
2925
import { FirebaseApp } from '@firebase/app-types';
@@ -215,10 +211,8 @@ GOOG4-RSA-SHA256`
215211
ref.put(new Uint8Array([97])).on(
216212
'state_changed',
217213
null,
218-
(err: FirebaseStorageError | Error) => {
219-
expect((err as FirebaseStorageError).code).to.equal(
220-
'storage/app-deleted'
221-
);
214+
(err: StorageError | Error) => {
215+
expect((err as StorageError).code).to.equal('storage/app-deleted');
222216
resolve();
223217
},
224218
() => {

packages/storage/src/implementation/connectionPool.ts

-31
This file was deleted.

packages/storage/src/implementation/request.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { RequestHandler, RequestInfo } from './requestinfo';
3232
import { isJustDef } from './type';
3333
import { makeQueryString } from './url';
3434
import { Headers, Connection, ErrorCode } from './connection';
35-
import { ConnectionPool } from './connectionPool';
3635

3736
export interface Request<T> {
3837
getPromise(): Promise<T>;
@@ -68,7 +67,7 @@ class NetworkRequest<T> implements Request<T> {
6867
private errorCallback_: RequestHandler<StorageError, StorageError> | null,
6968
private timeout_: number,
7069
private progressCallback_: ((p1: number, p2: number) => void) | null,
71-
private pool_: ConnectionPool
70+
private connectionFactory_: () => Connection
7271
) {
7372
this.promise_ = new Promise((resolve, reject) => {
7473
this.resolve_ = resolve as (value?: T | PromiseLike<T>) => void;
@@ -89,7 +88,7 @@ class NetworkRequest<T> implements Request<T> {
8988
backoffCallback(false, new RequestEndStatus(false, null, true));
9089
return;
9190
}
92-
const connection = this.pool_.createConnection();
91+
const connection = this.connectionFactory_();
9392
this.pendingConnection_ = connection;
9493

9594
const progressListener: (progressEvent: ProgressEvent) => void =
@@ -272,7 +271,7 @@ export function makeRequest<T>(
272271
appId: string | null,
273272
authToken: string | null,
274273
appCheckToken: string | null,
275-
pool: ConnectionPool,
274+
requestFactory: () => Connection,
276275
firebaseVersion?: string
277276
): Request<T> {
278277
const queryPart = makeQueryString(requestInfo.urlParams);
@@ -293,6 +292,6 @@ export function makeRequest<T>(
293292
requestInfo.errorHandler,
294293
requestInfo.timeout,
295294
requestInfo.progressCallback,
296-
pool
295+
requestFactory
297296
);
298297
}

packages/storage/src/implementation/requestmaker.ts

-28
This file was deleted.

packages/storage/src/index.node.ts

-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import { name, version } from '../package.json';
4040

4141
import { FirebaseStorage } from './public-types';
4242
import { STORAGE_TYPE } from './constants';
43-
import { ConnectionPool } from './implementation/connectionPool';
4443

4544
export * from './api';
4645
export * from './api.node';
@@ -57,7 +56,6 @@ function factory(
5756
app,
5857
authProvider,
5958
appCheckProvider,
60-
new ConnectionPool(),
6159
url,
6260
SDK_VERSION
6361
);

packages/storage/src/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
SDK_VERSION
2828
} from '@firebase/app';
2929

30-
import { ConnectionPool } from '../src/implementation/connectionPool';
3130
import { FirebaseStorageImpl } from '../src/service';
3231
import {
3332
Component,
@@ -56,7 +55,6 @@ function factory(
5655
app,
5756
authProvider,
5857
appCheckProvider,
59-
new ConnectionPool(),
6058
url,
6159
SDK_VERSION
6260
);

packages/storage/src/platform/browser/connection.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import {
2222
} from '../../implementation/connection';
2323
import { internalError } from '../../implementation/error';
2424

25+
/** An override for the text-based Connection. Used in tests. */
26+
let connectionFactoryOverride: (() => Connection) | null = null;
27+
2528
/**
2629
* Network layer for browsers. We use this instead of goog.net.XhrIo because
2730
* goog.net.XhrIo is hyuuuuge and doesn't work in React Native on Android.
@@ -124,5 +127,11 @@ export class XhrConnection implements Connection {
124127
}
125128

126129
export function newConnection(): Connection {
127-
return new XhrConnection();
130+
return connectionFactoryOverride
131+
? connectionFactoryOverride()
132+
: new XhrConnection();
133+
}
134+
135+
export function injectTestConnection(factory: (() => Connection) | null): void {
136+
connectionFactoryOverride = factory;
128137
}

packages/storage/src/platform/connection.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@
1515
* limitations under the License.
1616
*/
1717
import { Connection } from '../implementation/connection';
18-
import { newConnection as nodeNewConnection } from './node/connection';
18+
import {
19+
newConnection as nodeNewConnection,
20+
injectTestConnection as nodeInjectTestConnection
21+
} from './node/connection';
1922

2023
export function newConnection(): Connection {
2124
// This file is only used under ts-node.
2225
return nodeNewConnection();
2326
}
27+
28+
export function injectTestConnection(factory: (() => Connection) | null): void {
29+
// This file is only used under ts-node.
30+
nodeInjectTestConnection(factory);
31+
}

packages/storage/src/platform/node/connection.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import { ErrorCode, Connection } from '../../implementation/connection';
1919
import { internalError } from '../../implementation/error';
2020
import nodeFetch, { FetchError } from 'node-fetch';
2121

22+
/** An override for the text-based Connection. Used in tests. */
23+
let connectionFactoryOverride: (() => Connection) | null = null;
24+
2225
/**
2326
* Network layer that works in Node.
2427
*
@@ -118,5 +121,11 @@ export class FetchConnection implements Connection {
118121
}
119122

120123
export function newConnection(): Connection {
121-
return new FetchConnection();
124+
return connectionFactoryOverride
125+
? connectionFactoryOverride()
126+
: new FetchConnection();
127+
}
128+
129+
export function injectTestConnection(factory: (() => Connection) | null): void {
130+
connectionFactoryOverride = factory;
122131
}

0 commit comments

Comments
 (0)