Skip to content

Commit eeb4bb1

Browse files
committed
change StorageService to FirebaseStorage
1 parent ebecbd0 commit eeb4bb1

18 files changed

+142
-140
lines changed

common/api-review/storage.api.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Subscribe } from '@firebase/util';
1616
import { Unsubscribe } from '@firebase/util';
1717

1818
// @public
19-
export function connectStorageEmulator(storage: StorageService, host: string, port: number): void;
19+
export function connectStorageEmulator(storage: FirebaseStorage, host: string, port: number): void;
2020

2121
// @public
2222
export function deleteObject(ref: StorageReference): Promise<void>;
@@ -36,6 +36,13 @@ export class _FbsBlob {
3636
uploadData(): Blob | Uint8Array;
3737
}
3838

39+
// @public
40+
export interface FirebaseStorage extends _FirebaseService {
41+
readonly app: FirebaseApp;
42+
maxOperationRetryTime: number;
43+
maxUploadRetryTime: number;
44+
}
45+
3946
// @public
4047
export interface FirebaseStorageError extends FirebaseError {
4148
serverResponse: string | null;
@@ -65,7 +72,7 @@ export function getDownloadURL(ref: StorageReference): Promise<string>;
6572
export function getMetadata(ref: StorageReference): Promise<FullMetadata>;
6673

6774
// @public
68-
export function getStorage(app?: FirebaseApp, bucketUrl?: string): StorageService;
75+
export function getStorage(app?: FirebaseApp, bucketUrl?: string): FirebaseStorage;
6976

7077
// @public
7178
export function list(ref: StorageReference, options?: ListOptions): Promise<ListResult>;
@@ -106,25 +113,25 @@ export class _Location {
106113
}
107114

108115
// @public
109-
export function ref(storage: StorageService, url?: string): StorageReference;
116+
export function ref(storage: FirebaseStorage, url?: string): StorageReference;
110117

111118
// @public
112-
export function ref(storageOrRef: StorageService | StorageReference, path?: string): StorageReference;
119+
export function ref(storageOrRef: FirebaseStorage | StorageReference, path?: string): StorageReference;
113120

114121
// @internal
115122
export class _Reference {
116-
// Warning: (ae-forgotten-export) The symbol "StorageService" needs to be exported by the entry point index.d.ts
117-
constructor(_service: StorageService_2, location: string | _Location);
123+
// Warning: (ae-forgotten-export) The symbol "FirebaseStorageImpl" needs to be exported by the entry point index.d.ts
124+
constructor(_service: FirebaseStorageImpl, location: string | _Location);
118125
get bucket(): string;
119126
get fullPath(): string;
120127
// (undocumented)
121128
_location: _Location;
122129
get name(): string;
123130
// (undocumented)
124-
protected _newRef(service: StorageService_2, location: _Location): _Reference;
131+
protected _newRef(service: FirebaseStorageImpl, location: _Location): _Reference;
125132
get parent(): _Reference | null;
126133
get root(): _Reference;
127-
get storage(): StorageService_2;
134+
get storage(): FirebaseStorageImpl;
128135
_throwIfRoot(name: string): void;
129136
// @override
130137
toString(): string;
@@ -159,17 +166,10 @@ export interface StorageReference {
159166
name: string;
160167
parent: StorageReference | null;
161168
root: StorageReference;
162-
storage: StorageService;
169+
storage: FirebaseStorage;
163170
toString(): string;
164171
}
165172

166-
// @public
167-
export interface StorageService extends _FirebaseService {
168-
readonly app: FirebaseApp;
169-
maxOperationRetryTime: number;
170-
maxUploadRetryTime: number;
171-
}
172-
173173
// @public
174174
export type StringFormat = string;
175175

packages/storage/compat/service.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
import * as types from '@firebase/storage-types';
1919
import { FirebaseApp } from '@firebase/app-types';
2020

21-
import { ref, _Location } from '../exp/api'; // import from the exp public API
22-
import { ReferenceCompat } from './reference';
2321
import {
24-
isUrl,
25-
StorageService,
26-
connectStorageEmulator as internalUseEmulator
27-
} from '../src/service';
22+
ref,
23+
_Location,
24+
connectStorageEmulator,
25+
FirebaseStorage
26+
} from '../exp/api'; // import from the exp public API
27+
import { ReferenceCompat } from './reference';
28+
import { isUrl, FirebaseStorageImpl } from '../src/service';
2829
import { invalidArgument } from '../src/implementation/error';
2930
import { Compat } from '@firebase/util';
3031

@@ -33,9 +34,9 @@ import { Compat } from '@firebase/util';
3334
* @param opt_url gs:// url to a custom Storage Bucket
3435
*/
3536
export class StorageServiceCompat
36-
implements types.FirebaseStorage, Compat<StorageService>
37+
implements types.FirebaseStorage, Compat<FirebaseStorage>
3738
{
38-
constructor(public app: FirebaseApp, readonly _delegate: StorageService) {}
39+
constructor(public app: FirebaseApp, readonly _delegate: FirebaseStorage) {}
3940

4041
INTERNAL = {
4142
/**
@@ -78,7 +79,7 @@ export class StorageServiceCompat
7879
);
7980
}
8081
try {
81-
_Location.makeFromUrl(url, this._delegate.host);
82+
_Location.makeFromUrl(url, (this._delegate as FirebaseStorageImpl).host);
8283
} catch (e) {
8384
throw invalidArgument(
8485
'refFromUrl() expected a valid full URL but got an invalid one.'
@@ -96,6 +97,6 @@ export class StorageServiceCompat
9697
}
9798

9899
useEmulator(host: string, port: number): void {
99-
internalUseEmulator(this._delegate, host, port);
100+
connectStorageEmulator(this._delegate, host, port);
100101
}
101102
}

packages/storage/exp/api.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
18-
import {
19-
_getProvider,
20-
FirebaseApp,
21-
getApp
22-
// eslint-disable-next-line import/no-extraneous-dependencies
23-
} from '@firebase/app-exp';
17+
// eslint-disable-next-line import/no-extraneous-dependencies
18+
import { _getProvider, FirebaseApp, getApp } from '@firebase/app-exp';
2419

2520
import {
2621
ref as refInternal,
27-
StorageService as StorageServiceInternal
22+
FirebaseStorageImpl,
23+
connectStorageEmulator as connectEmulatorInternal
2824
} from '../src/service';
2925
import { Provider } from '@firebase/component';
3026

@@ -268,7 +264,7 @@ export function ref(
268264
): StorageReference | null {
269265
serviceOrRef = getModularInstance(serviceOrRef);
270266
return refInternal(
271-
serviceOrRef as StorageServiceInternal | Reference,
267+
serviceOrRef as FirebaseStorageImpl | Reference,
272268
pathOrUrl
273269
);
274270
}
@@ -304,3 +300,19 @@ export function getStorage(
304300
});
305301
return storageInstance;
306302
}
303+
304+
/**
305+
* Modify this `StorageService` instance to communicate with the Cloud Storage emulator.
306+
*
307+
* @param storage - The `StorageService` instance
308+
* @param host - The emulator host (ex: localhost)
309+
* @param port - The emulator port (ex: 5001)
310+
* @public
311+
*/
312+
export function connectStorageEmulator(
313+
storage: FirebaseStorage,
314+
host: string,
315+
port: number
316+
): void {
317+
connectEmulatorInternal(storage as FirebaseStorageImpl, host, port);
318+
}

packages/storage/exp/index.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@
2020
* See the License for the specific language governing permissions and
2121
* limitations under the License.
2222
*/
23-
23+
// eslint-disable-next-line import/no-extraneous-dependencies
2424
import {
2525
_registerComponent,
2626
registerVersion,
2727
SDK_VERSION
28-
// eslint-disable-next-line import/no-extraneous-dependencies
2928
} from '@firebase/app-exp';
3029

3130
import { ConnectionPool } from '../src/implementation/connectionPool';
32-
import {
33-
StorageService as StorageServiceInternal,
34-
connectStorageEmulator as useEmulatorInternal
35-
} from '../src/service';
31+
import { FirebaseStorageImpl } from '../src/service';
3632
import {
3733
Component,
3834
ComponentType,
@@ -45,22 +41,6 @@ import { name, version } from '../package.json';
4541
import { FirebaseStorage } from './public-types';
4642
import { STORAGE_TYPE } from './constants';
4743

48-
/**
49-
* Modify this `StorageService` instance to communicate with the Cloud Storage emulator.
50-
*
51-
* @param storage - The `StorageService` instance
52-
* @param host - The emulator host (ex: localhost)
53-
* @param port - The emulator port (ex: 5001)
54-
* @public
55-
*/
56-
export function connectStorageEmulator(
57-
storage: FirebaseStorage,
58-
host: string,
59-
port: number
60-
): void {
61-
useEmulatorInternal(storage as StorageServiceInternal, host, port);
62-
}
63-
6444
export { StringFormat } from '../src/implementation/string';
6545
export * from './api';
6646

@@ -72,7 +52,7 @@ function factory(
7252
const authProvider = container.getProvider('auth-internal');
7353
const appCheckProvider = container.getProvider('app-check-internal');
7454

75-
return new StorageServiceInternal(
55+
return new FirebaseStorageImpl(
7656
app,
7757
authProvider,
7858
appCheckProvider,

packages/storage/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { TaskEvent, TaskState } from './src/implementation/taskenums';
2323
import { ConnectionPool } from './src/implementation/connectionPool';
2424
import { ReferenceCompat } from './compat/reference';
2525
import { StorageServiceCompat } from './compat/service';
26-
import { StorageService } from './src/service';
26+
import { FirebaseStorageImpl } from './src/service';
2727
import * as types from '@firebase/storage-types';
2828
import {
2929
Component,
@@ -55,7 +55,7 @@ function factory(
5555
// of creating a new one.
5656
const storageServiceCompat: StorageServiceCompat = new StorageServiceCompat(
5757
app,
58-
new StorageService(
58+
new FirebaseStorageImpl(
5959
app,
6060
authProvider,
6161
appCheckProvider,
@@ -73,7 +73,7 @@ export function registerStorage(instance: _FirebaseNamespace): void {
7373
TaskState,
7474
TaskEvent,
7575
StringFormat,
76-
Storage: StorageService,
76+
Storage: FirebaseStorageImpl,
7777
Reference: ReferenceCompat
7878
};
7979
instance.INTERNAL.registerComponent(

packages/storage/src/implementation/list.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import { Location } from './location';
2222
import { jsonObjectOrNull } from './json';
2323
import { ListResult } from '../list';
24-
import { StorageService } from '../service';
24+
import { FirebaseStorageImpl } from '../service';
2525

2626
/**
2727
* Represents the simplified object metadata returned by List API.
@@ -46,7 +46,7 @@ const PREFIXES_KEY = 'prefixes';
4646
const ITEMS_KEY = 'items';
4747

4848
function fromBackendResponse(
49-
service: StorageService,
49+
service: FirebaseStorageImpl,
5050
bucket: string,
5151
resource: ListResultResponse
5252
): ListResult {
@@ -77,14 +77,14 @@ function fromBackendResponse(
7777
}
7878

7979
export function fromResponseString(
80-
service: StorageService,
80+
service: FirebaseStorageImpl,
8181
bucket: string,
8282
resourceString: string
8383
): ListResult | null {
8484
const obj = jsonObjectOrNull(resourceString);
8585
if (obj === null) {
8686
return null;
8787
}
88-
const resource = (obj as unknown) as ListResultResponse;
88+
const resource = obj as unknown as ListResultResponse;
8989
return fromBackendResponse(service, bucket, resource);
9090
}

packages/storage/src/implementation/metadata.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { lastComponent } from './path';
2626
import { isString } from './type';
2727
import { makeUrl, makeQueryString } from './url';
2828
import { Reference } from '../reference';
29-
import { StorageService } from '../service';
29+
import { FirebaseStorageImpl } from '../service';
3030

3131
export function noXform_<T>(metadata: Metadata, value: T): T {
3232
return value;
@@ -111,7 +111,7 @@ export function getMappings(): Mappings {
111111
return mappings_;
112112
}
113113

114-
export function addRef(metadata: Metadata, service: StorageService): void {
114+
export function addRef(metadata: Metadata, service: FirebaseStorageImpl): void {
115115
function generateRef(): Reference {
116116
const bucket: string = metadata['bucket'] as string;
117117
const path: string = metadata['fullPath'] as string;
@@ -122,7 +122,7 @@ export function addRef(metadata: Metadata, service: StorageService): void {
122122
}
123123

124124
export function fromResource(
125-
service: StorageService,
125+
service: FirebaseStorageImpl,
126126
resource: { [name: string]: unknown },
127127
mappings: Mappings
128128
): Metadata {
@@ -141,7 +141,7 @@ export function fromResource(
141141
}
142142

143143
export function fromResourceString(
144-
service: StorageService,
144+
service: FirebaseStorageImpl,
145145
resourceString: string,
146146
mappings: Mappings
147147
): Metadata | null {

0 commit comments

Comments
 (0)