Skip to content

Commit 273c5ff

Browse files
esmacikthechenky
authored andcommitted
Add code comments for storage events (#517)
* Add code comments for storage events * Fix some comment formatting issues
1 parent 0315544 commit 273c5ff

File tree

1 file changed

+169
-10
lines changed

1 file changed

+169
-10
lines changed

src/providers/storage.ts

Lines changed: 169 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,22 @@ export const provider = 'google.storage';
3434
export const service = 'storage.googleapis.com';
3535

3636
/**
37-
* The optional bucket function allows you to choose which buckets' events to handle.
38-
* This step can be bypassed by calling object() directly, which will use the default
39-
* Cloud Storage for Firebase bucket.
40-
* @param bucket Name of the Google Cloud Storage bucket to listen to.
37+
* Registers a Cloud Function scoped to a specific storage bucket.
38+
*
39+
* @param bucket Name of the bucket to which this Cloud Function is
40+
* scoped.
41+
*
42+
* @return Storage bucket builder interface.
4143
*/
4244
export function bucket(bucket?: string) {
4345
return _bucketWithOptions({}, bucket);
4446
}
4547

4648
/**
47-
* Handle events related to Cloud Storage objects.
49+
* Registers a Cloud Function scoped to the default storage bucket for the
50+
* project.
51+
*
52+
* @return Storage object builder interface.
4853
*/
4954
export function object() {
5055
return _objectWithOptions({});
@@ -76,19 +81,34 @@ export function _objectWithOptions(options: DeploymentOptions): ObjectBuilder {
7681
return _bucketWithOptions(options).object();
7782
}
7883

84+
/**
85+
* The Google Cloud Storage bucket builder interface.
86+
*
87+
* Access via [`functions.storage.bucket()`](functions.storage#.bucket).
88+
*/
7989
export class BucketBuilder {
8090
/** @hidden */
8191
constructor(
8292
private triggerResource: () => string,
8393
private options: DeploymentOptions
8494
) {}
8595

86-
/** Handle events for objects in this bucket. */
96+
/**
97+
* Event handler which fires every time a Google Cloud Storage change occurs.
98+
*
99+
* @return Storage object builder interface scoped to the specified storage
100+
* bucket.
101+
*/
87102
object() {
88103
return new ObjectBuilder(this.triggerResource, this.options);
89104
}
90105
}
91106

107+
/**
108+
* The Google Cloud Storage object builder interface.
109+
*
110+
* Access via [`functions.storage.object()`](functions.storage#.object).
111+
*/
92112
export class ObjectBuilder {
93113
/** @hidden */
94114
constructor(
@@ -104,7 +124,17 @@ export class ObjectBuilder {
104124
);
105125
}
106126

107-
/** Respond to archiving of an object, this is only for buckets that enabled object versioning. */
127+
/**
128+
* Event handler sent only when a bucket has enabled object versioning.
129+
* This event indicates that the live version of an object has become an
130+
* archived version, either because it was archived or because it was
131+
* overwritten by the upload of an object of the same name.
132+
*
133+
* @param handler Event handler which is run every time a Google Cloud Storage
134+
* archival occurs.
135+
*
136+
* @return A Cloud Function which you can export and deploy.
137+
*/
108138
onArchive(
109139
handler: (
110140
object: ObjectMetadata,
@@ -114,7 +144,20 @@ export class ObjectBuilder {
114144
return this.onOperation(handler, 'object.archive');
115145
}
116146

117-
/** Respond to the deletion of an object (not to archiving, if object versioning is enabled). */
147+
/**
148+
* Event handler which fires every time a Google Cloud Storage deletion occurs.
149+
*
150+
* Sent when an object has been permanently deleted. This includes objects
151+
* that are overwritten or are deleted as part of the bucket's lifecycle
152+
* configuration. For buckets with object versioning enabled, this is not
153+
* sent when an object is archived, even if archival occurs
154+
* via the `storage.objects.delete` method.
155+
*
156+
* @param handler Event handler which is run every time a Google Cloud Storage
157+
* deletion occurs.
158+
*
159+
* @return A Cloud Function which you can export and deploy.
160+
*/
118161
onDelete(
119162
handler: (
120163
object: ObjectMetadata,
@@ -124,7 +167,19 @@ export class ObjectBuilder {
124167
return this.onOperation(handler, 'object.delete');
125168
}
126169

127-
/** Respond to the successful creation of an object. */
170+
/**
171+
* Event handler which fires every time a Google Cloud Storage object
172+
* creation occurs.
173+
*
174+
* Sent when a new object (or a new generation of an existing object)
175+
* is successfully created in the bucket. This includes copying or rewriting
176+
* an existing object. A failed upload does not trigger this event.
177+
*
178+
* @param handler Event handler which is run every time a Google Cloud Storage
179+
* object creation occurs.
180+
*
181+
* @return A Cloud Function which you can export and deploy.
182+
*/
128183
onFinalize(
129184
handler: (
130185
object: ObjectMetadata,
@@ -134,7 +189,15 @@ export class ObjectBuilder {
134189
return this.onOperation(handler, 'object.finalize');
135190
}
136191

137-
/** Respond to metadata updates of existing objects. */
192+
/**
193+
* Event handler which fires every time the metadata of an existing object
194+
* changes.
195+
*
196+
* @param handler Event handler which is run every time a Google Cloud Storage
197+
* metadata update occurs.
198+
*
199+
* @return A Cloud Function which you can export and deploy.
200+
*/
138201
onMetadataUpdate(
139202
handler: (
140203
object: ObjectMetadata,
@@ -144,6 +207,7 @@ export class ObjectBuilder {
144207
return this.onOperation(handler, 'object.metadataUpdate');
145208
}
146209

210+
/** @hidden */
147211
private onOperation(
148212
handler: (
149213
object: ObjectMetadata,
@@ -162,30 +226,101 @@ export class ObjectBuilder {
162226
}
163227
}
164228

229+
/** Interface representing a Google Google Cloud Storage object metadata object. */
165230
export interface ObjectMetadata {
231+
/** The kind of the object, which is always `storage#object`. */
166232
kind: string;
233+
234+
/**
235+
* The ID of the object, including the bucket name, object name, and
236+
* generation number.
237+
*/
167238
id: string;
239+
240+
/** Storage bucket that contains the object. */
168241
bucket: string;
242+
243+
/** Storage class of the object. */
169244
storageClass: string;
245+
246+
/**
247+
* The value of the `Content-Length` header, used to determine the length of
248+
* the object data in bytes.
249+
*/
170250
size: string;
251+
252+
/** The creation time of the object in RFC 3339 format. */
171253
timeCreated: string;
254+
255+
/**
256+
* The modification time of the object metadata in RFC 3339 format.
257+
*/
172258
updated: string;
259+
260+
/** Link to access the object, assuming you have sufficient permissions. */
173261
selfLink?: string;
262+
263+
/**The object's name. */
174264
name?: string;
265+
266+
/**
267+
* Generation version number that changes each time the object is
268+
* overwritten.
269+
*/
175270
generation?: string;
271+
272+
/** The object's content type, also known as the MIME type. */
176273
contentType?: string;
274+
275+
/**
276+
* Meta-generation version number that changes each time the object's metadata
277+
* is updated.
278+
*/
177279
metageneration?: string;
280+
281+
/**
282+
* The deletion time of the object in RFC 3339 format. Returned
283+
* only if this version of the object has been deleted.
284+
*/
178285
timeDeleted?: string;
286+
179287
timeStorageClassUpdated?: string;
288+
289+
/**
290+
* MD5 hash for the object. All Google Cloud Storage objects
291+
* have a CRC32C hash or MD5 hash.
292+
*/
180293
md5Hash?: string;
294+
295+
/** Media download link. */
181296
mediaLink?: string;
297+
298+
/**
299+
* Content-Encoding to indicate that an object is compressed
300+
* (for example, with gzip compression) while maintaining its Content-Type.
301+
*/
182302
contentEncoding?: string;
303+
304+
/**
305+
* The value of the `Content-Disposition` header, used to specify presentation
306+
* information about the data being transmitted.
307+
*/
183308
contentDisposition?: string;
309+
310+
/** ISO 639-1 language code of the content. */
184311
contentLanguage?: string;
312+
313+
/**
314+
* The value of the `Cache-Control` header, used to determine whether Internet
315+
* caches are allowed to cache public data for an object.
316+
*/
185317
cacheControl?: string;
318+
319+
/** User-provided metadata. */
186320
metadata?: {
187321
[key: string]: string;
188322
};
323+
189324
acl?: [
190325
{
191326
kind?: string;
@@ -206,13 +341,37 @@ export interface ObjectMetadata {
206341
etag?: string;
207342
}
208343
];
344+
209345
owner?: {
210346
entity?: string;
211347
entityId?: string;
212348
};
349+
350+
/**
351+
* The object's CRC32C hash. All Google Cloud Storage objects
352+
* have a CRC32C hash or MD5 hash.
353+
*/
213354
crc32c?: string;
355+
356+
/**
357+
* Specifies the number of originally uploaded objects from which
358+
* a composite object was created.
359+
*/
214360
componentCount?: string;
361+
215362
etag?: string;
363+
364+
/**
365+
* Customer-supplied encryption key.
366+
*
367+
* This object contains the following properties:
368+
* * `encryptionAlgorithm` (`string|undefined`): The encryption algorithm that
369+
* was used. Always contains the value `AES256`.
370+
* * `keySha256` (`string|undefined`): An RFC 4648 base64-encoded string of the
371+
* SHA256 hash of your encryption key. You can use this SHA256 hash to
372+
* uniquely identify the AES-256 encryption key required to decrypt the
373+
* object, which you must store securely.
374+
*/
216375
customerEncryption?: {
217376
encryptionAlgorithm?: string;
218377
keySha256?: string;

0 commit comments

Comments
 (0)