@@ -29,102 +29,86 @@ import {
29
29
deleteObject
30
30
} from '../src/reference' ;
31
31
import * as types from '@firebase/storage-types' ;
32
- import {
33
- validate ,
34
- stringSpec ,
35
- listOptionSpec ,
36
- metadataSpec ,
37
- uploadDataSpec
38
- } from '../src/implementation/args' ;
39
32
import { Metadata } from '../src/metadata' ;
40
- import { StringFormat , formatValidator } from '../src/implementation/string' ;
33
+ import { StringFormat } from '../src/implementation/string' ;
41
34
import { ListOptions } from '../src/list' ;
42
35
import { UploadTaskCompat } from './task' ;
43
36
import { ListResultCompat } from './list' ;
44
37
import { StorageServiceCompat } from './service' ;
45
38
import { invalidRootOperation } from '../src/implementation/error' ;
46
39
47
40
export class ReferenceCompat implements types . Reference {
48
- constructor ( private readonly delegate : Reference ) { }
41
+ constructor (
42
+ private readonly _delegate : Reference ,
43
+ public storage : StorageServiceCompat
44
+ ) { }
49
45
50
- storage = new StorageServiceCompat (
51
- this . delegate . storage ,
52
- ref => new ReferenceCompat ( ref )
53
- ) as types . FirebaseStorage ;
54
- name = this . delegate . name ;
55
- bucket = this . delegate . bucket ;
56
- fullPath = this . delegate . fullPath ;
46
+ name = this . _delegate . name ;
47
+ bucket = this . _delegate . bucket ;
48
+ fullPath = this . _delegate . fullPath ;
57
49
58
50
toString ( ) : string {
59
- validate ( 'toString' , [ ] , arguments ) ;
60
- return this . delegate . toString ( ) ;
51
+ return this . _delegate . toString ( ) ;
61
52
}
62
53
63
54
/**
64
- * @return A reference to the object obtained by
55
+ * @returns A reference to the object obtained by
65
56
* appending childPath, removing any duplicate, beginning, or trailing
66
57
* slashes.
67
58
*/
68
59
child ( childPath : string ) : types . Reference {
69
- validate ( 'child' , [ stringSpec ( ) ] , arguments ) ;
70
- const reference = getChild ( this . delegate , childPath ) ;
71
- return new ReferenceCompat ( reference ) ;
60
+ const reference = getChild ( this . _delegate , childPath ) ;
61
+ return new ReferenceCompat ( reference , this . storage ) ;
72
62
}
73
63
74
64
get root ( ) : types . Reference {
75
- return new ReferenceCompat ( this . delegate . root ) as types . Reference ;
65
+ return new ReferenceCompat ( this . _delegate . root , this . storage ) ;
76
66
}
77
67
78
68
/**
79
- * @return A reference to the parent of the
69
+ * @returns A reference to the parent of the
80
70
* current object, or null if the current object is the root.
81
71
*/
82
72
get parent ( ) : types . Reference | null {
83
- const reference = getParent ( this . delegate ) ;
73
+ const reference = getParent ( this . _delegate ) ;
84
74
if ( reference == null ) {
85
75
return null ;
86
76
}
87
- return new ReferenceCompat ( reference ) ;
77
+ return new ReferenceCompat ( reference , this . storage ) ;
88
78
}
89
79
90
80
/**
91
81
* Uploads a blob to this object's location.
92
- * @param data The blob to upload.
93
- * @return An UploadTask that lets you control and
82
+ * @param data - The blob to upload.
83
+ * @returns An UploadTask that lets you control and
94
84
* observe the upload.
95
85
*/
96
86
put (
97
87
data : Blob | Uint8Array | ArrayBuffer ,
98
88
metadata ?: Metadata
99
89
) : types . UploadTask {
100
- validate ( 'put' , [ uploadDataSpec ( ) , metadataSpec ( true ) ] , arguments ) ;
101
90
this . _throwIfRoot ( 'put' ) ;
102
91
return new UploadTaskCompat (
103
- uploadBytes ( this . delegate , data , metadata ) ,
92
+ uploadBytes ( this . _delegate , data , metadata ) ,
104
93
this
105
94
) ;
106
95
}
107
96
108
97
/**
109
98
* Uploads a string to this object's location.
110
- * @param value The string to upload.
111
- * @param format The format of the string to upload.
112
- * @return An UploadTask that lets you control and
99
+ * @param value - The string to upload.
100
+ * @param format - The format of the string to upload.
101
+ * @returns An UploadTask that lets you control and
113
102
* observe the upload.
114
103
*/
115
104
putString (
116
105
value : string ,
117
106
format : StringFormat = StringFormat . RAW ,
118
107
metadata ?: Metadata
119
108
) : types . UploadTask {
120
- validate (
121
- 'putString' ,
122
- [ stringSpec ( ) , stringSpec ( formatValidator , true ) , metadataSpec ( true ) ] ,
123
- arguments
124
- ) ;
125
109
this . _throwIfRoot ( 'putString' ) ;
126
110
return new UploadTaskCompat (
127
- uploadString ( this . delegate , value , format , metadata ) ,
111
+ uploadString ( this . _delegate , value , format , metadata ) ,
128
112
this
129
113
) ;
130
114
}
@@ -141,15 +125,15 @@ export class ReferenceCompat implements types.Reference {
141
125
* Warning: listAll may potentially consume too many resources if there are
142
126
* too many results.
143
127
*
144
- * @return A Promise that resolves with all the items and prefixes under
128
+ * @returns A Promise that resolves with all the items and prefixes under
145
129
* the current storage reference. `prefixes` contains references to
146
130
* sub-directories and `items` contains references to objects in this
147
131
* folder. `nextPageToken` is never returned.
148
132
*/
149
133
listAll ( ) : Promise < types . ListResult > {
150
- validate ( 'listAll' , [ ] , arguments ) ;
151
- return listAll ( this . delegate ) . then (
152
- r => new ListResultCompat ( r , ref => new ReferenceCompat ( ref ) )
134
+ return listAll ( this . _delegate ) . then (
135
+ r =>
136
+ new ListResultCompat ( r , ref => new ReferenceCompat ( ref , this . storage ) )
153
137
) ;
154
138
}
155
139
@@ -159,24 +143,23 @@ export class ReferenceCompat implements types.Reference {
159
143
* List API is only available for Firebase Rules Version 2.
160
144
*
161
145
* GCS is a key-blob store. Firebase Storage imposes the semantic of '/'
162
- * delimited folder structure.
163
- * Refer to GCS's List API if you want to learn more.
146
+ * delimited folder structure. Refer to GCS's List API if you want to learn more.
164
147
*
165
148
* To adhere to Firebase Rules's Semantics, Firebase Storage does not
166
149
* support objects whose paths end with "/" or contain two consecutive
167
150
* "/"s. Firebase Storage List API will filter these unsupported objects.
168
151
* list() may fail if there are too many unsupported objects in the bucket.
169
152
*
170
- * @param options See ListOptions for details.
171
- * @return A Promise that resolves with the items and prefixes.
153
+ * @param options - See ListOptions for details.
154
+ * @returns A Promise that resolves with the items and prefixes.
172
155
* `prefixes` contains references to sub-folders and `items`
173
156
* contains references to objects in this folder. `nextPageToken`
174
157
* can be used to get the rest of the results.
175
158
*/
176
159
list ( options ?: ListOptions | null ) : Promise < types . ListResult > {
177
- validate ( 'list' , [ listOptionSpec ( true ) ] , arguments ) ;
178
- return list ( this . delegate , options ) . then (
179
- r => new ListResultCompat ( r , ref => new ReferenceCompat ( ref ) )
160
+ return list ( this . _delegate , options ) . then (
161
+ r =>
162
+ new ListResultCompat ( r , ref => new ReferenceCompat ( ref , this . storage ) )
180
163
) ;
181
164
}
182
165
@@ -186,45 +169,41 @@ export class ReferenceCompat implements types.Reference {
186
169
* rejected.
187
170
*/
188
171
getMetadata ( ) : Promise < Metadata > {
189
- validate ( 'getMetadata' , [ ] , arguments ) ;
190
- return getMetadata ( this . delegate ) ;
172
+ return getMetadata ( this . _delegate ) ;
191
173
}
192
174
193
175
/**
194
176
* Updates the metadata for this object.
195
- * @param metadata The new metadata for the object.
177
+ * @param metadata - The new metadata for the object.
196
178
* Only values that have been explicitly set will be changed. Explicitly
197
179
* setting a value to null will remove the metadata.
198
- * @return A promise that resolves
180
+ * @returns A promise that resolves
199
181
* with the new metadata for this object.
200
182
* @see firebaseStorage.Reference.prototype.getMetadata
201
183
*/
202
184
updateMetadata ( metadata : Metadata ) : Promise < Metadata > {
203
- validate ( 'updateMetadata' , [ metadataSpec ( ) ] , arguments ) ;
204
- return updateMetadata ( this . delegate , metadata ) ;
185
+ return updateMetadata ( this . _delegate , metadata ) ;
205
186
}
206
187
207
188
/**
208
- * @return A promise that resolves with the download
189
+ * @returns A promise that resolves with the download
209
190
* URL for this object.
210
191
*/
211
192
getDownloadURL ( ) : Promise < string > {
212
- validate ( 'getDownloadURL' , [ ] , arguments ) ;
213
- return getDownloadURL ( this . delegate ) ;
193
+ return getDownloadURL ( this . _delegate ) ;
214
194
}
215
195
216
196
/**
217
197
* Deletes the object at this location.
218
- * @return A promise that resolves if the deletion succeeds.
198
+ * @returns A promise that resolves if the deletion succeeds.
219
199
*/
220
200
delete ( ) : Promise < void > {
221
- validate ( 'delete' , [ ] , arguments ) ;
222
201
this . _throwIfRoot ( 'delete' ) ;
223
- return deleteObject ( this . delegate ) ;
202
+ return deleteObject ( this . _delegate ) ;
224
203
}
225
204
226
205
private _throwIfRoot ( name : string ) : void {
227
- if ( this . delegate . location . path === '' ) {
206
+ if ( this . _delegate . location . path === '' ) {
228
207
throw invalidRootOperation ( name ) ;
229
208
}
230
209
}
0 commit comments