1 | /**
|
2 | * Core functionality of the Cloud Functions for Firebase 2nd gen SDK.
|
3 | * @packageDocumentation
|
4 | */
|
5 | import { Change } from "../common/change";
|
6 | import { ManifestEndpoint } from "../runtime/manifest";
|
7 | export { Change };
|
8 | export { ParamsOf } from "../common/params";
|
9 | export { onInit } from "../common/onInit";
|
10 | /**
|
11 | * A `CloudEventBase` is the base of a cross-platform format for encoding a serverless event.
|
12 | * For more information, see https://github.com/cloudevents/spec.
|
13 | * @typeParam T - The type of the event data.
|
14 | * @beta
|
15 | */
|
16 | export interface CloudEvent<T> {
|
17 | /** Version of the CloudEvents spec for this event. */
|
18 | readonly specversion: "1.0";
|
19 | /** A globally unique ID for this event. */
|
20 | id: string;
|
21 | /** The resource that published this event. */
|
22 | source: string;
|
23 | /** The resource, provided by source, that this event relates to. */
|
24 | subject?: string;
|
25 | /** The type of event that this represents. */
|
26 | type: string;
|
27 | /** When this event occurred. */
|
28 | time: string;
|
29 | /** Information about this specific event. */
|
30 | data: T;
|
31 | }
|
32 | /**
|
33 | * A handler for CloudEvents.
|
34 | * @typeParam EventType - The kind of event this function handles.
|
35 | * Always a subclass of CloudEvent<>
|
36 | * @beta
|
37 | */
|
38 | export interface CloudFunction<EventType extends CloudEvent<unknown>> {
|
39 | (raw: CloudEvent<unknown>): any | Promise<any>;
|
40 | /** @alpha */
|
41 | __trigger?: unknown;
|
42 | /** @alpha */
|
43 | __endpoint: ManifestEndpoint;
|
44 | /**
|
45 | * The callback passed to the `CloudFunction` constructor.
|
46 | * Use `run` to test a function.
|
47 | * @param event - The parsed event to handle.
|
48 | * @returns Any return value. Cloud Functions awaits any promise
|
49 | * before shutting down your function. Resolved return values
|
50 | * are only used for unit testing purposes.
|
51 | * @beta
|
52 | */
|
53 | run(event: EventType): any | Promise<any>;
|
54 | }
|