UNPKG

15.5 kBTypeScriptView Raw
1import { ResetValue } from "../../common/options";
2import { CloudEvent, CloudFunction } from "../core";
3import { Expression } from "../../params";
4import * as options from "../options";
5import { SecretParam } from "../../params/types";
6/**
7 * An object within Google Cloud Storage.
8 * Ref: https://github.com/googleapis/google-cloudevents-nodejs/blob/main/cloud/storage/v1/StorageObjectData.ts
9 */
10export interface StorageObjectData {
11 /**
12 * The name of the bucket containing this object.
13 */
14 bucket: string;
15 /**
16 * Cache-Control directive for the object data, matching
17 * [https://tools.ietf.org/html/rfc7234#section-5.2"][RFC 7234 §5.2].
18 */
19 cacheControl?: string;
20 /**
21 * Number of underlying components that make up this object. Components are
22 * accumulated by compose operations.
23 * Attempting to set this field will result in an error.
24 */
25 componentCount?: number;
26 /**
27 * Content-Disposition of the object data, matching
28 * [https://tools.ietf.org/html/rfc6266][RFC 6266].
29 */
30 contentDisposition?: string;
31 /**
32 * Content-Encoding of the object data, matching
33 * [https://tools.ietf.org/html/rfc7231#section-3.1.2.2][RFC 7231 §3.1.2.2]
34 */
35 contentEncoding?: string;
36 /**
37 * Content-Language of the object data, matching
38 * [https://tools.ietf.org/html/rfc7231#section-3.1.3.2][RFC 7231 §3.1.3.2].
39 */
40 contentLanguage?: string;
41 /**
42 * Content-Type of the object data, matching
43 * [https://tools.ietf.org/html/rfc7231#section-3.1.1.5][RFC 7231 §3.1.1.5].
44 * If an object is stored without a Content-Type, it is served as
45 * `application/octet-stream`.
46 */
47 contentType?: string;
48 /**
49 * CRC32c checksum. For more information about using the CRC32c
50 * checksum, see
51 * [https://cloud.google.com/storage/docs/hashes-etags#_JSONAPI][Hashes and
52 * ETags: Best Practices].
53 */
54 crc32c?: string;
55 /**
56 * Metadata of customer-supplied encryption key, if the object is encrypted by
57 * such a key.
58 */
59 customerEncryption?: CustomerEncryption;
60 /**
61 * HTTP 1.1 Entity tag for the object. See
62 * [https://tools.ietf.org/html/rfc7232#section-2.3][RFC 7232 §2.3].
63 */
64 etag?: string;
65 /**
66 * The content generation of this object. Used for object versioning.
67 * Attempting to set this field will result in an error.
68 */
69 generation: number;
70 /**
71 * The ID of the object, including the bucket name, object name, and
72 * generation number.
73 */
74 id: string;
75 /**
76 * The kind of item this is. For objects, this is always "storage#object".
77 */
78 kind?: string;
79 /**
80 * MD5 hash of the data; encoded using base64 as per
81 * [https://tools.ietf.org/html/rfc4648#section-4][RFC 4648 §4]. For more
82 * information about using the MD5 hash, see
83 * [https://cloud.google.com/storage/docs/hashes-etags#_JSONAPI][Hashes and
84 * ETags: Best Practices].
85 */
86 md5Hash?: string;
87 /**
88 * Media download link.
89 */
90 mediaLink?: string;
91 /**
92 * User-provided metadata, in key/value pairs.
93 */
94 metadata?: {
95 [key: string]: string;
96 };
97 /**
98 * The version of the metadata for this object at this generation. Used for
99 * preconditions and for detecting changes in metadata. A metageneration
100 * number is only meaningful in the context of a particular generation of a
101 * particular object.
102 */
103 metageneration: number;
104 /**
105 * The name of the object.
106 */
107 name: string;
108 /**
109 * The link to this object.
110 */
111 selfLink?: string;
112 /**
113 * Content-Length of the object data in bytes, matching
114 * [https://tools.ietf.org/html/rfc7230#section-3.3.2][RFC 7230 §3.3.2].
115 */
116 size: number;
117 /**
118 * Storage class of the object.
119 */
120 storageClass: string;
121 /**
122 * The creation time of the object.
123 * Attempting to set this field will result in an error.
124 */
125 timeCreated?: Date | string;
126 /**
127 * The deletion time of the object. Will be returned if and only if this
128 * version of the object has been deleted.
129 */
130 timeDeleted?: Date | string;
131 /**
132 * The time at which the object's storage class was last changed.
133 */
134 timeStorageClassUpdated?: Date | string;
135 /**
136 * The modification time of the object metadata.
137 */
138 updated?: Date | string;
139}
140/**
141 * Metadata of customer-supplied encryption key, if the object is encrypted by
142 * such a key.
143 */
144export interface CustomerEncryption {
145 /**
146 * The encryption algorithm.
147 */
148 encryptionAlgorithm?: string;
149 /**
150 * SHA256 hash value of the encryption key.
151 */
152 keySha256?: string;
153}
154/** A CloudEvent that contains StorageObjectData */
155export interface StorageEvent extends CloudEvent<StorageObjectData> {
156 /** The name of the bucket containing this object. */
157 bucket: string;
158}
159/** StorageOptions extend EventHandlerOptions with a bucket name */
160export interface StorageOptions extends options.EventHandlerOptions {
161 /** The name of the bucket containing this object. */
162 bucket?: string | Expression<string>;
163 /**
164 * If true, do not deploy or emulate this function.
165 */
166 omit?: boolean | Expression<boolean>;
167 /**
168 * Region where functions should be deployed.
169 */
170 region?: options.SupportedRegion | string | Expression<string> | ResetValue;
171 /**
172 * Amount of memory to allocate to a function.
173 */
174 memory?: options.MemoryOption | Expression<number> | ResetValue;
175 /**
176 * Timeout for the function in seconds, possible values are 0 to 540.
177 * HTTPS functions can specify a higher timeout.
178 *
179 * @remarks
180 * The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
181 * function depends on the type of function: Event handling functions have a
182 * maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
183 * maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
184 * timeout of 1,800s (30 minutes)
185 */
186 timeoutSeconds?: number | Expression<number> | ResetValue;
187 /**
188 * Min number of actual instances to be running at a given time.
189 *
190 * @remarks
191 * Instances will be billed for memory allocation and 10% of CPU allocation
192 * while idle.
193 */
194 minInstances?: number | Expression<number> | ResetValue;
195 /**
196 * Max number of instances to be running in parallel.
197 */
198 maxInstances?: number | Expression<number> | ResetValue;
199 /**
200 * Number of requests a function can serve at once.
201 *
202 * @remarks
203 * Can only be applied to functions running on Cloud Functions v2.
204 * A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
205 * Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
206 * The maximum value for concurrency is 1,000.
207 */
208 concurrency?: number | Expression<number> | ResetValue;
209 /**
210 * Fractional number of CPUs to allocate to a function.
211 *
212 * @remarks
213 * Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
214 * This is different from the defaults when using the gcloud utility and is different from
215 * the fixed amount assigned in Google Cloud Functions generation 1.
216 * To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
217 * to the value "gcf_gen1"
218 */
219 cpu?: number | "gcf_gen1";
220 /**
221 * Connect cloud function to specified VPC connector.
222 */
223 vpcConnector?: string | Expression<string> | ResetValue;
224 /**
225 * Egress settings for VPC connector.
226 */
227 vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
228 /**
229 * Specific service account for the function to run as.
230 */
231 serviceAccount?: string | Expression<string> | ResetValue;
232 /**
233 * Ingress settings which control where this function can be called from.
234 */
235 ingressSettings?: options.IngressSetting | ResetValue;
236 /**
237 * User labels to set on the function.
238 */
239 labels?: Record<string, string>;
240 secrets?: (string | SecretParam)[];
241 /** Whether failed executions should be delivered again. */
242 retry?: boolean | Expression<boolean> | ResetValue;
243}
244/**
245 * Event handler sent only when a bucket has enabled object versioning.
246 * This event indicates that the live version of an object has become an
247 * archived version, either because it was archived or because it was
248 * overwritten by the upload of an object of the same name.
249 *
250 * @param handler - Event handler which is run every time a Google Cloud Storage archival occurs.
251 */
252export declare function onObjectArchived(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
253/**
254 * Event handler sent only when a bucket has enabled object versioning.
255 * This event indicates that the live version of an object has become an
256 * archived version, either because it was archived or because it was
257 * overwritten by the upload of an object of the same name.
258 *
259 * @param bucket - The name of the bucket containing this object.
260 * @param handler - Event handler which is run every time a Google Cloud Storage archival occurs.
261 */
262export declare function onObjectArchived(bucket: string | Expression<string>, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
263/**
264 * Event handler sent only when a bucket has enabled object versioning.
265 * This event indicates that the live version of an object has become an
266 * archived version, either because it was archived or because it was
267 * overwritten by the upload of an object of the same name.
268 *
269 * @param opts - Options that can be set on an individual event-handling function.
270 * @param handler - Event handler which is run every time a Google Cloud Storage archival occurs.
271 */
272export declare function onObjectArchived(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
273/**
274 * Event handler which fires every time a Google Cloud Storage object
275 * creation occurs.
276 *
277 * Sent when a new object (or a new generation of an existing object)
278 * is successfully created in the bucket. This includes copying or rewriting
279 * an existing object. A failed upload does not trigger this event.
280 *
281 * @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs.
282 */
283export declare function onObjectFinalized(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
284/**
285 * Event handler which fires every time a Google Cloud Storage object
286 * creation occurs.
287 *
288 * Sent when a new object (or a new generation of an existing object)
289 * is successfully created in the bucket. This includes copying or rewriting
290 * an existing object. A failed upload does not trigger this event.
291 *
292 * @param bucket - The name of the bucket containing this object.
293 * @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs.
294 */
295export declare function onObjectFinalized(bucket: string | Expression<string>, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
296/**
297 * Event handler which fires every time a Google Cloud Storage object
298 * creation occurs.
299 *
300 * Sent when a new object (or a new generation of an existing object)
301 * is successfully created in the bucket. This includes copying or rewriting
302 * an existing object. A failed upload does not trigger this event.
303 *
304 * @param opts - Options that can be set on an individual event-handling function.
305 * @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs.
306 */
307export declare function onObjectFinalized(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
308/**
309 * Event handler which fires every time a Google Cloud Storage deletion occurs.
310 *
311 * Sent when an object has been permanently deleted. This includes objects
312 * that are overwritten or are deleted as part of the bucket's lifecycle
313 * configuration. For buckets with object versioning enabled, this is not
314 * sent when an object is archived, even if archival occurs
315 * via the `storage.objects.delete` method.
316 *
317 * @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs.
318 */
319export declare function onObjectDeleted(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
320/**
321 * Event handler which fires every time a Google Cloud Storage deletion occurs.
322 *
323 * Sent when an object has been permanently deleted. This includes objects
324 * that are overwritten or are deleted as part of the bucket's lifecycle
325 * configuration. For buckets with object versioning enabled, this is not
326 * sent when an object is archived, even if archival occurs
327 * via the `storage.objects.delete` method.
328 *
329 * @param bucket - The name of the bucket containing this object.
330 * @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs.
331 */
332export declare function onObjectDeleted(bucket: string | Expression<string>, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
333/**
334 * Event handler which fires every time a Google Cloud Storage deletion occurs.
335 *
336 * Sent when an object has been permanently deleted. This includes objects
337 * that are overwritten or are deleted as part of the bucket's lifecycle
338 * configuration. For buckets with object versioning enabled, this is not
339 * sent when an object is archived, even if archival occurs
340 * via the `storage.objects.delete` method.
341 *
342 * @param opts - Options that can be set on an individual event-handling function.
343 * @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs.
344 */
345export declare function onObjectDeleted(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
346/**
347 * Event handler which fires every time the metadata of an existing object
348 * changes.
349 *
350 * @param bucketOrOptsOrHandler - Options or string that may (or may not) define the bucket to be used.
351 * @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs.
352 */
353export declare function onObjectMetadataUpdated(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
354/**
355 * Event handler which fires every time the metadata of an existing object
356 * changes.
357 *
358 * @param bucket - The name of the bucket containing this object.
359 * @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs.
360 */
361export declare function onObjectMetadataUpdated(bucket: string | Expression<string>, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
362/**
363 * Event handler which fires every time the metadata of an existing object
364 * changes.
365 *
366 * @param opts - Options that can be set on an individual event-handling function.
367 * @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs.
368 */
369export declare function onObjectMetadataUpdated(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;