Skip to content

Commit f0f0639

Browse files
committed
Address some PR comments
1 parent 570443d commit f0f0639

20 files changed

+193
-257
lines changed

packages/storage/compat/reference.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
9+
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
1111
* Unless required by applicable law or agreed to in writing, software
1212
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -42,7 +42,7 @@ import { ListOptions } from '../src/list';
4242
import { UploadTaskCompat } from './task';
4343
import { ListResultCompat } from './list';
4444
import { StorageServiceCompat } from './service';
45-
import * as errorsExports from '../src/implementation/error';
45+
import { invalidRootOperation } from '../src/implementation/error';
4646

4747
export class ReferenceCompat implements types.Reference {
4848
constructor(private readonly delegate: Reference) {}
@@ -62,8 +62,8 @@ export class ReferenceCompat implements types.Reference {
6262

6363
/**
6464
* @return A reference to the object obtained by
65-
* appending childPath, removing any duplicate, beginning, or trailing
66-
* slashes.
65+
* appending childPath, removing any duplicate, beginning, or trailing
66+
* slashes.
6767
*/
6868
child(childPath: string): types.Reference {
6969
validate('child', [stringSpec()], arguments);
@@ -77,10 +77,9 @@ export class ReferenceCompat implements types.Reference {
7777

7878
/**
7979
* @return A reference to the parent of the
80-
* current object, or null if the current object is the root.
80+
* current object, or null if the current object is the root.
8181
*/
8282
get parent(): types.Reference | null {
83-
validate('parent', [], arguments);
8483
const reference = getParent(this.delegate);
8584
if (reference == null) {
8685
return null;
@@ -92,25 +91,26 @@ export class ReferenceCompat implements types.Reference {
9291
* Uploads a blob to this object's location.
9392
* @param data The blob to upload.
9493
* @return An UploadTask that lets you control and
95-
* observe the upload.
94+
* observe the upload.
9695
*/
9796
put(
9897
data: Blob | Uint8Array | ArrayBuffer,
9998
metadata?: Metadata
10099
): types.UploadTask {
101100
validate('put', [uploadDataSpec(), metadataSpec(true)], arguments);
102-
this.throwIfRoot_('put');
101+
this._throwIfRoot('put');
103102
return new UploadTaskCompat(
104103
uploadBytes(this.delegate, data, metadata),
105104
this
106105
);
107106
}
107+
108108
/**
109109
* Uploads a string to this object's location.
110110
* @param value The string to upload.
111111
* @param format The format of the string to upload.
112112
* @return An UploadTask that lets you control and
113-
* observe the upload.
113+
* observe the upload.
114114
*/
115115
putString(
116116
value: string,
@@ -122,7 +122,7 @@ export class ReferenceCompat implements types.Reference {
122122
[stringSpec(), stringSpec(formatValidator, true), metadataSpec(true)],
123123
arguments
124124
);
125-
this.throwIfRoot_('putString');
125+
this._throwIfRoot('putString');
126126
return new UploadTaskCompat(
127127
uploadString(this.delegate, value, format, metadata),
128128
this
@@ -142,9 +142,9 @@ export class ReferenceCompat implements types.Reference {
142142
* too many results.
143143
*
144144
* @return A Promise that resolves with all the items and prefixes under
145-
* the current storage reference. `prefixes` contains references to
146-
* sub-directories and `items` contains references to objects in this
147-
* folder. `nextPageToken` is never returned.
145+
* the current storage reference. `prefixes` contains references to
146+
* sub-directories and `items` contains references to objects in this
147+
* folder. `nextPageToken` is never returned.
148148
*/
149149
listAll(): Promise<types.ListResult> {
150150
validate('listAll', [], arguments);
@@ -169,9 +169,9 @@ export class ReferenceCompat implements types.Reference {
169169
*
170170
* @param options See ListOptions for details.
171171
* @return A Promise that resolves with the items and prefixes.
172-
* `prefixes` contains references to sub-folders and `items`
173-
* contains references to objects in this folder. `nextPageToken`
174-
* can be used to get the rest of the results.
172+
* `prefixes` contains references to sub-folders and `items`
173+
* contains references to objects in this folder. `nextPageToken`
174+
* can be used to get the rest of the results.
175175
*/
176176
list(options?: ListOptions | null): Promise<types.ListResult> {
177177
validate('list', [listOptionSpec(true)], arguments);
@@ -181,9 +181,9 @@ export class ReferenceCompat implements types.Reference {
181181
}
182182

183183
/**
184-
* A promise that resolves with the metadata for this object. If this
185-
* object doesn't exist or metadata cannot be retreived, the promise is
186-
* rejected.
184+
* A promise that resolves with the metadata for this object. If this
185+
* object doesn't exist or metadata cannot be retreived, the promise is
186+
* rejected.
187187
*/
188188
getMetadata(): Promise<Metadata> {
189189
validate('getMetadata', [], arguments);
@@ -193,11 +193,11 @@ export class ReferenceCompat implements types.Reference {
193193
/**
194194
* Updates the metadata for this object.
195195
* @param metadata The new metadata for the object.
196-
* Only values that have been explicitly set will be changed. Explicitly
197-
* setting a value to null will remove the metadata.
196+
* Only values that have been explicitly set will be changed. Explicitly
197+
* setting a value to null will remove the metadata.
198198
* @return A promise that resolves
199-
* with the new metadata for this object.
200-
* @see firebaseStorage.Reference.prototype.getMetadata
199+
* with the new metadata for this object.
200+
* @see firebaseStorage.Reference.prototype.getMetadata
201201
*/
202202
updateMetadata(metadata: Metadata): Promise<Metadata> {
203203
validate('updateMetadata', [metadataSpec()], arguments);
@@ -206,7 +206,7 @@ export class ReferenceCompat implements types.Reference {
206206

207207
/**
208208
* @return A promise that resolves with the download
209-
* URL for this object.
209+
* URL for this object.
210210
*/
211211
getDownloadURL(): Promise<string> {
212212
validate('getDownloadURL', [], arguments);
@@ -219,13 +219,13 @@ export class ReferenceCompat implements types.Reference {
219219
*/
220220
delete(): Promise<void> {
221221
validate('delete', [], arguments);
222-
this.throwIfRoot_('delete');
222+
this._throwIfRoot('delete');
223223
return deleteObject(this.delegate);
224224
}
225225

226-
private throwIfRoot_(name: string): void {
226+
private _throwIfRoot(name: string): void {
227227
if (this.delegate.location.path === '') {
228-
throw errorsExports.invalidRootOperation(name);
228+
throw invalidRootOperation(name);
229229
}
230230
}
231231
}

packages/storage/compat/service.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ export function pathValidator(path: unknown): void {
4848
/**
4949
* A service that provides firebaseStorage.Reference instances.
5050
* @param opt_url gs:// url to a custom Storage Bucket
51-
*
52-
* @struct
5351
*/
5452
export class StorageServiceCompat implements types.FirebaseStorage {
5553
constructor(
@@ -104,20 +102,20 @@ export class StorageServiceCompat implements types.FirebaseStorage {
104102
}
105103

106104
/**
107-
* @struct
105+
* @internal
108106
*/
109107
export class ServiceInternals {
110-
service_: StorageServiceCompat;
108+
_service: StorageServiceCompat;
111109

112110
constructor(service: StorageServiceCompat) {
113-
this.service_ = service;
111+
this._service = service;
114112
}
115113

116114
/**
117115
* Called when the associated app is deleted.
118116
*/
119117
delete(): Promise<void> {
120-
this.service_.delegate.deleteApp();
118+
this._service.delegate.deleteApp();
121119
return Promise.resolve();
122120
}
123121
}

packages/storage/rollup.config.exp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import path from 'path';
2424
const deps = Object.keys(
2525
Object.assign({}, pkg.peerDependencies, pkg.dependencies)
2626
).concat('@firebase/app-exp');
27+
2728
/**
2829
* ES5 Builds
2930
*/

packages/storage/src/implementation/args.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
import * as errorsExports from './error';
18-
import * as MetadataUtils from './metadata';
19-
import * as ListOptionsUtils from './list';
20-
import * as type from './type';
17+
import { invalidArgumentCount, invalidArgument } from './error';
18+
import { metadataValidator } from './metadata';
19+
import { listOptionsValidator } from './list';
20+
import {
21+
isJustDef,
22+
isNativeBlobDefined,
23+
isString,
24+
isNumber,
25+
isFunction
26+
} from './type';
2127

2228
/**
2329
* @param name Name of the function.
@@ -40,37 +46,29 @@ export function validate(
4046
}
4147
const validLength = minArgs <= passed.length && passed.length <= maxArgs;
4248
if (!validLength) {
43-
throw errorsExports.invalidArgumentCount(
44-
minArgs,
45-
maxArgs,
46-
name,
47-
passed.length
48-
);
49+
throw invalidArgumentCount(minArgs, maxArgs, name, passed.length);
4950
}
5051
for (let i = 0; i < passed.length; i++) {
5152
try {
5253
specs[i].validator(passed[i]);
5354
} catch (e) {
5455
if (e instanceof Error) {
55-
throw errorsExports.invalidArgument(i, name, e.message);
56+
throw invalidArgument(i, name, e.message);
5657
} else {
57-
throw errorsExports.invalidArgument(i, name, e);
58+
throw invalidArgument(i, name, e);
5859
}
5960
}
6061
}
6162
}
6263

63-
/**
64-
* @struct
65-
*/
6664
export class ArgSpec {
6765
validator: (p1: unknown) => void;
6866
optional: boolean;
6967

7068
constructor(validator: (p1: unknown) => void, optional?: boolean) {
7169
const self = this;
7270
this.validator = function (p: unknown) {
73-
if (self.optional && !type.isJustDef(p)) {
71+
if (self.optional && !isJustDef(p)) {
7472
return;
7573
}
7674
validator(p);
@@ -94,7 +92,7 @@ export function stringSpec(
9492
optional?: boolean
9593
): ArgSpec {
9694
function stringValidator(p: unknown): void {
97-
if (!type.isString(p)) {
95+
if (!isString(p)) {
9896
throw 'Expected string.';
9997
}
10098
}
@@ -112,25 +110,25 @@ export function uploadDataSpec(): ArgSpec {
112110
const valid =
113111
p instanceof Uint8Array ||
114112
p instanceof ArrayBuffer ||
115-
(type.isNativeBlobDefined() && p instanceof Blob);
113+
(isNativeBlobDefined() && p instanceof Blob);
116114
if (!valid) {
117-
throw 'Expected Blob or File.';
115+
throw invalidArgument('Expected Blob or File.');
118116
}
119117
}
120118
return new ArgSpec(validator);
121119
}
122120

123121
export function metadataSpec(optional?: boolean): ArgSpec {
124-
return new ArgSpec(MetadataUtils.metadataValidator, optional);
122+
return new ArgSpec(metadataValidator, optional);
125123
}
126124

127125
export function listOptionSpec(optional?: boolean): ArgSpec {
128-
return new ArgSpec(ListOptionsUtils.listOptionsValidator, optional);
126+
return new ArgSpec(listOptionsValidator, optional);
129127
}
130128

131129
export function nonNegativeNumberSpec(): ArgSpec {
132130
function validator(p: unknown): void {
133-
const valid = type.isNumber(p) && p >= 0;
131+
const valid = isNumber(p) && p >= 0;
134132
if (!valid) {
135133
throw 'Expected a number 0 or greater.';
136134
}
@@ -143,7 +141,7 @@ export function looseObjectSpec(
143141
optional?: boolean
144142
): ArgSpec {
145143
function isLooseObjectValidator(p: unknown): void {
146-
const isLooseObject = p === null || (type.isDef(p) && p instanceof Object);
144+
const isLooseObject = p === null || (p != null && p instanceof Object);
147145
if (!isLooseObject) {
148146
throw 'Expected an Object.';
149147
}
@@ -156,7 +154,7 @@ export function looseObjectSpec(
156154

157155
export function nullFunctionSpec(optional?: boolean): ArgSpec {
158156
function validator(p: unknown): void {
159-
const valid = p === null || type.isFunction(p);
157+
const valid = p === null || isFunction(p);
160158
if (!valid) {
161159
throw 'Expected a Function.';
162160
}

packages/storage/src/implementation/error.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,30 @@ export function noDownloadURL(): FirebaseStorageError {
239239
);
240240
}
241241

242+
export function invalidArgument(message: string): FirebaseStorageError;
242243
export function invalidArgument(
243-
index: number,
244+
index: number | string,
244245
fnName: string,
245246
message: string
247+
): FirebaseStorageError;
248+
export function invalidArgument(
249+
indexOrMessage: number | string,
250+
fnName?: string,
251+
message?: string
246252
): FirebaseStorageError {
247-
return new FirebaseStorageError(
248-
Code.INVALID_ARGUMENT,
249-
'Invalid argument in `' + fnName + '` at index ' + index + ': ' + message
250-
);
253+
if (typeof indexOrMessage === 'string') {
254+
return new FirebaseStorageError(Code.INVALID_ARGUMENT, indexOrMessage);
255+
} else {
256+
return new FirebaseStorageError(
257+
Code.INVALID_ARGUMENT,
258+
'Invalid argument in `' +
259+
fnName +
260+
'` at index ' +
261+
indexOrMessage +
262+
': ' +
263+
message
264+
);
265+
}
251266
}
252267

253268
export function invalidArgumentCount(

packages/storage/src/implementation/failrequest.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import { Request } from './request';
1919

2020
/**
2121
* A request whose promise always fails.
22-
* @struct
23-
* @template T
2422
*/
2523
export class FailRequest<T> implements Request<T> {
2624
promise_: Promise<T>;

0 commit comments

Comments
 (0)