Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 14 additions & 21 deletions src/v1/providers/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ import * as logger from "../../logger";
import { CloudFunction, Event, EventContext, makeCloudFunction } from "../cloud-functions";
import { DeploymentOptions } from "../function-configuration";

/** @hidden */
export const provider = "google.firestore";
/** @hidden */
export const service = "firestore.googleapis.com";
/** @hidden */
export const defaultDatabase = "(default)";
/** @internal */
export const PROVIDER = "google.firestore";
/** @internal */
export const SERVICE = "firestore.googleapis.com";
/** @internal */
export const DEFAULT_DATABASE = "(default)";
let firestoreInstance: any;
export type DocumentSnapshot = firestore.DocumentSnapshot;
export type QueryDocumentSnapshot = firestore.QueryDocumentSnapshot;
Expand All @@ -52,38 +52,35 @@ export function document<Path extends string>(path: Path) {
return _documentWithOptions(path, {});
}

/** @hidden */
// Multiple namespaces are not yet supported by Firestore.
export function namespace(namespace: string) {
return _namespaceWithOptions(namespace, {});
}

/** @hidden */
// Multiple databases are not yet supported by Firestore.
export function database(database: string) {
return _databaseWithOptions(database, {});
}

/** @hidden */
/** @internal */
export function _databaseWithOptions(
database: string = defaultDatabase,
database: string = DEFAULT_DATABASE,
options: DeploymentOptions
) {
return new DatabaseBuilder(database, options);
}

/** @hidden */
/** @internal */
export function _namespaceWithOptions(namespace: string, options: DeploymentOptions) {
return _databaseWithOptions(defaultDatabase, options).namespace(namespace);
return _databaseWithOptions(DEFAULT_DATABASE, options).namespace(namespace);
}

/** @hidden */
/** @internal */
export function _documentWithOptions<Path extends string>(path: Path, options: DeploymentOptions) {
return _databaseWithOptions(defaultDatabase, options).document(path);
return _databaseWithOptions(DEFAULT_DATABASE, options).document(path);
}

export class DatabaseBuilder {
/** @hidden */
constructor(private database: string, private options: DeploymentOptions) {}

namespace(namespace: string) {
Expand All @@ -96,7 +93,6 @@ export class DatabaseBuilder {
}

export class NamespaceBuilder {
/** @hidden */
constructor(
private database: string,
private options: DeploymentOptions,
Expand Down Expand Up @@ -142,7 +138,6 @@ function _getValueProto(data: any, resource: string, valueFieldName: string) {
return proto;
}

/** @hidden */
export function snapshotConstructor(event: Event): DocumentSnapshot {
if (!firestoreInstance) {
firestoreInstance = firestore.getFirestore(getApp());
Expand All @@ -159,7 +154,6 @@ export function snapshotConstructor(event: Event): DocumentSnapshot {
return firestoreInstance.snapshot_(valueProto, readTime, "json");
}

/** @hidden */
// TODO remove this function when wire format changes to new format
export function beforeSnapshotConstructor(event: Event): DocumentSnapshot {
if (!firestoreInstance) {
Expand All @@ -175,7 +169,6 @@ function changeConstructor(raw: Event) {
}

export class DocumentBuilder<Path extends string> {
/** @hidden */
constructor(private triggerResource: () => string, private options: DeploymentOptions) {
// TODO what validation do we want to do here?
}
Expand Down Expand Up @@ -227,9 +220,9 @@ export class DocumentBuilder<Path extends string> {
): CloudFunction<T> {
return makeCloudFunction({
handler,
provider,
provider: PROVIDER,
eventType,
service,
service: SERVICE,
triggerResource: this.triggerResource,
legacyEventType: `providers/cloud.firestore/eventTypes/${eventType}`,
dataConstructor,
Expand Down