UNPKG

3.19 kBTypeScriptView Raw
1import { CloudFunction, EventContext } from "../cloud-functions";
2import { DeploymentOptions, ScheduleRetryConfig } from "../function-configuration";
3/**
4 * Registers a Cloud Function triggered when a Google Cloud Pub/Sub message
5 * is sent to a specified topic.
6 *
7 * @param topic - The Pub/Sub topic to watch for message events.
8 * @returns Pub/Sub topic builder interface.
9 */
10export declare function topic(topic: string): TopicBuilder;
11/**
12 * The Google Cloud Pub/Sub topic builder.
13 *
14 * Access via `functions.pubsub.topic()`.
15 */
16export declare class TopicBuilder {
17 private triggerResource;
18 private options;
19 /** @hidden */
20 constructor(triggerResource: () => string, options: DeploymentOptions);
21 /**
22 * Event handler that fires every time a Cloud Pub/Sub message is
23 * published.
24 *
25 * @param handler - Event handler that runs every time a Cloud Pub/Sub message
26 * is published.
27 * @returns A function that you can export and deploy.
28 */
29 onPublish(handler: (message: Message, context: EventContext) => PromiseLike<any> | any): CloudFunction<Message>;
30}
31/**
32 * Registers a Cloud Function to run at specified times.
33 *
34 * @param schedule - The schedule, in Unix Crontab or AppEngine syntax.
35 * @returns ScheduleBuilder interface.
36 */
37export declare function schedule(schedule: string): ScheduleBuilder;
38/**
39 * The builder for scheduled functions, which are powered by
40 * Google Pub/Sub and Cloud Scheduler. Describes the Cloud Scheduler
41 * job that is deployed to trigger a scheduled function at the provided
42 * frequency. For more information, see
43 * [Schedule functions](/docs/functions/schedule-functions).
44 *
45 * Access via `functions.pubsub.schedule()`.
46 */
47export declare class ScheduleBuilder {
48 private triggerResource;
49 private options;
50 /** @hidden */
51 constructor(triggerResource: () => string, options: DeploymentOptions);
52 retryConfig(config: ScheduleRetryConfig): ScheduleBuilder;
53 timeZone(timeZone: string): ScheduleBuilder;
54 /**
55 * Event handler for scheduled functions. Triggered whenever the associated
56 * scheduler job sends a Pub/Sub message.
57 *
58 * @param handler - Handler that fires whenever the associated
59 * scheduler job sends a Pub/Sub message.
60 * @returns A function that you can export and deploy.
61 */
62 onRun(handler: (context: EventContext) => PromiseLike<any> | any): CloudFunction<unknown>;
63}
64/**
65 * Interface representing a Google Cloud Pub/Sub message.
66 *
67 * @param data - Payload of a Pub/Sub message.
68 */
69export declare class Message {
70 /**
71 * The data payload of this message object as a base64-encoded string.
72 */
73 readonly data: string;
74 /**
75 * User-defined attributes published with the message, if any.
76 */
77 readonly attributes: {
78 [key: string]: string;
79 };
80 /** @hidden */
81 private _json;
82 constructor(data: any);
83 /**
84 * The JSON data payload of this message object, if any.
85 */
86 get json(): any;
87 /**
88 * Returns a JSON-serializable representation of this object.
89 *
90 * @returns A JSON-serializable representation of this object.
91 */
92 toJSON(): any;
93}