Skip to content

Commit 8396405

Browse files
authored
Remove Storage AuthWrapper layer (#3399)
1 parent 7d5678b commit 8396405

File tree

15 files changed

+291
-477
lines changed

15 files changed

+291
-477
lines changed

packages/storage/.eslintrc.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
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+
const path = require('path');
19+
120
module.exports = {
221
extends: '../../config/.eslintrc.js',
322
parserOptions: {
@@ -14,6 +33,12 @@ module.exports = {
1433
varsIgnorePattern: '^_',
1534
args: 'none'
1635
}
36+
],
37+
'import/no-extraneous-dependencies': [
38+
'error',
39+
{
40+
'packageDir': [path.resolve(__dirname, '../../'), __dirname]
41+
}
1742
]
1843
}
1944
};

packages/storage/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { TaskEvent, TaskState } from './src/implementation/taskenums';
2222

2323
import { XhrIoPool } from './src/implementation/xhriopool';
2424
import { Reference } from './src/reference';
25-
import { Service } from './src/service';
25+
import { StorageService } from './src/service';
2626
import * as types from '@firebase/storage-types';
2727
import {
2828
Component,
@@ -45,7 +45,7 @@ function factory(
4545
const app = container.getProvider('app').getImmediate();
4646
const authProvider = container.getProvider('auth-internal');
4747

48-
return (new Service(
48+
return (new StorageService(
4949
app,
5050
authProvider,
5151
new XhrIoPool(),
@@ -59,7 +59,7 @@ export function registerStorage(instance: _FirebaseNamespace): void {
5959
TaskState,
6060
TaskEvent,
6161
StringFormat,
62-
Storage: Service,
62+
Storage: StorageService,
6363
Reference
6464
};
6565
instance.INTERNAL.registerComponent(

packages/storage/src/implementation/authwrapper.ts

Lines changed: 0 additions & 180 deletions
This file was deleted.

packages/storage/src/implementation/list.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
/**
1919
* @fileoverview Documentation for the listOptions and listResult format
2020
*/
21-
import { AuthWrapper } from './authwrapper';
2221
import { Location } from './location';
2322
import * as json from './json';
2423
import * as type from './type';
2524
import { ListResult } from '../list';
25+
import { StorageService } from '../service';
2626

2727
/**
2828
* Represents the simplified object metadata returned by List API.
@@ -50,7 +50,7 @@ const PREFIXES_KEY = 'prefixes';
5050
const ITEMS_KEY = 'items';
5151

5252
function fromBackendResponse(
53-
authWrapper: AuthWrapper,
53+
service: StorageService,
5454
bucket: string,
5555
resource: ListResultResponse
5656
): ListResult {
@@ -62,7 +62,7 @@ function fromBackendResponse(
6262
if (resource[PREFIXES_KEY]) {
6363
for (const path of resource[PREFIXES_KEY]) {
6464
const pathWithoutTrailingSlash = path.replace(/\/$/, '');
65-
const reference = authWrapper.makeStorageReference(
65+
const reference = service.makeStorageReference(
6666
new Location(bucket, pathWithoutTrailingSlash)
6767
);
6868
listResult.prefixes.push(reference);
@@ -71,7 +71,7 @@ function fromBackendResponse(
7171

7272
if (resource[ITEMS_KEY]) {
7373
for (const item of resource[ITEMS_KEY]) {
74-
const reference = authWrapper.makeStorageReference(
74+
const reference = service.makeStorageReference(
7575
new Location(bucket, item['name'])
7676
);
7777
listResult.items.push(reference);
@@ -81,7 +81,7 @@ function fromBackendResponse(
8181
}
8282

8383
export function fromResponseString(
84-
authWrapper: AuthWrapper,
84+
service: StorageService,
8585
bucket: string,
8686
resourceString: string
8787
): ListResult | null {
@@ -90,7 +90,7 @@ export function fromResponseString(
9090
return null;
9191
}
9292
const resource = (obj as unknown) as ListResultResponse;
93-
return fromBackendResponse(authWrapper, bucket, resource);
93+
return fromBackendResponse(service, bucket, resource);
9494
}
9595

9696
export function listOptionsValidator(p: unknown): void {

packages/storage/src/implementation/metadata.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
*/
2121
import { Metadata } from '../metadata';
2222

23-
import { AuthWrapper } from './authwrapper';
2423
import * as json from './json';
2524
import { Location } from './location';
2625
import * as path from './path';
2726
import * as type from './type';
2827
import * as UrlUtils from './url';
2928
import { Reference } from '../reference';
29+
import { StorageService } from '../service';
3030

3131
export function noXform_<T>(metadata: Metadata, value: T): T {
3232
return value;
@@ -114,18 +114,18 @@ export function getMappings(): Mappings {
114114
return mappings_;
115115
}
116116

117-
export function addRef(metadata: Metadata, authWrapper: AuthWrapper): void {
117+
export function addRef(metadata: Metadata, service: StorageService): void {
118118
function generateRef(): Reference {
119119
const bucket: string = metadata['bucket'] as string;
120120
const path: string = metadata['fullPath'] as string;
121121
const loc = new Location(bucket, path);
122-
return authWrapper.makeStorageReference(loc);
122+
return service.makeStorageReference(loc);
123123
}
124124
Object.defineProperty(metadata, 'ref', { get: generateRef });
125125
}
126126

127127
export function fromResource(
128-
authWrapper: AuthWrapper,
128+
service: StorageService,
129129
resource: { [name: string]: unknown },
130130
mappings: Mappings
131131
): Metadata {
@@ -139,12 +139,12 @@ export function fromResource(
139139
resource[mapping.server]
140140
);
141141
}
142-
addRef(metadata, authWrapper);
142+
addRef(metadata, service);
143143
return metadata;
144144
}
145145

146146
export function fromResourceString(
147-
authWrapper: AuthWrapper,
147+
service: StorageService,
148148
resourceString: string,
149149
mappings: Mappings
150150
): Metadata | null {
@@ -153,7 +153,7 @@ export function fromResourceString(
153153
return null;
154154
}
155155
const resource = obj as Metadata;
156-
return fromResource(authWrapper, resource, mappings);
156+
return fromResource(service, resource, mappings);
157157
}
158158

159159
export function downloadUrlFromResourceString(

0 commit comments

Comments
 (0)