UNPKG

2.73 kBTypeScriptView Raw
1import * as firestore from "firebase-admin/firestore";
2import { Change } from "../../common/change";
3import { ParamsOf } from "../../common/params";
4import { CloudFunction, Event, EventContext } from "../cloud-functions";
5import { DeploymentOptions } from "../function-configuration";
6export type DocumentSnapshot = firestore.DocumentSnapshot;
7export type QueryDocumentSnapshot = firestore.QueryDocumentSnapshot;
8/**
9 * Select the Firestore document to listen to for events.
10 * @param path Full database path to listen to. This includes the name of
11 * the collection that the document is a part of. For example, if the
12 * collection is named "users" and the document is named "Ada", then the
13 * path is "/users/Ada".
14 */
15export declare function document<Path extends string>(path: Path): DocumentBuilder<Path>;
16export declare function namespace(namespace: string): NamespaceBuilder;
17export declare function database(database: string): DatabaseBuilder;
18export declare class DatabaseBuilder {
19 private database;
20 private options;
21 constructor(database: string, options: DeploymentOptions);
22 namespace(namespace: string): NamespaceBuilder;
23 document<Path extends string>(path: Path): DocumentBuilder<Path>;
24}
25export declare class NamespaceBuilder {
26 private database;
27 private options;
28 private namespace?;
29 constructor(database: string, options: DeploymentOptions, namespace?: string);
30 document<Path extends string>(path: Path): DocumentBuilder<Path>;
31}
32export declare function snapshotConstructor(event: Event): DocumentSnapshot;
33export declare function beforeSnapshotConstructor(event: Event): DocumentSnapshot;
34export declare class DocumentBuilder<Path extends string> {
35 private triggerResource;
36 private options;
37 constructor(triggerResource: () => string, options: DeploymentOptions);
38 /** Respond to all document writes (creates, updates, or deletes). */
39 onWrite(handler: (change: Change<DocumentSnapshot>, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any): CloudFunction<Change<DocumentSnapshot>>;
40 /** Respond only to document updates. */
41 onUpdate(handler: (change: Change<QueryDocumentSnapshot>, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any): CloudFunction<Change<QueryDocumentSnapshot>>;
42 /** Respond only to document creations. */
43 onCreate(handler: (snapshot: QueryDocumentSnapshot, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any): CloudFunction<QueryDocumentSnapshot>;
44 /** Respond only to document deletions. */
45 onDelete(handler: (snapshot: QueryDocumentSnapshot, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any): CloudFunction<QueryDocumentSnapshot>;
46 private onOperation;
47}