diff --git a/src/v1/cloud-functions.ts b/src/v1/cloud-functions.ts index 596b10027..53c01e7ce 100644 --- a/src/v1/cloud-functions.ts +++ b/src/v1/cloud-functions.ts @@ -21,7 +21,6 @@ // SOFTWARE. import { Request, Response } from 'express'; -import * as _ from 'lodash'; import { warn } from '../logger'; import { DEFAULT_FAILURE_POLICY, @@ -202,95 +201,6 @@ export interface EventContext> { timestamp: string; } -/** - * The Functions interface for events that change state, such as - * Realtime Database or Cloud Firestore `onWrite` and `onUpdate`. - * - * For more information about the format used to construct `Change` objects, see - * [`cloud-functions.ChangeJson`](/docs/reference/functions/cloud_functions_.changejson). - * - */ -export class Change { - constructor(public before: T, public after: T) {} -} - -/** - * `ChangeJson` is the JSON format used to construct a Change object. - */ -export interface ChangeJson { - /** - * Key-value pairs representing state of data after the change. - */ - after?: any; - /** - * Key-value pairs representing state of data before the change. If - * `fieldMask` is set, then only fields that changed are present in `before`. - */ - before?: any; - /** - * @hidden - * Comma-separated string that represents names of fields that changed. - */ - fieldMask?: string; -} - -export namespace Change { - /** @hidden */ - function reinterpretCast(x: any) { - return x as T; - } - - /** - * @hidden - * Factory method for creating a Change from a `before` object and an `after` - * object. - */ - export function fromObjects(before: T, after: T) { - return new Change(before, after); - } - - /** - * @hidden - * Factory method for creating a Change from a JSON and an optional customizer - * function to be applied to both the `before` and the `after` fields. - */ - export function fromJSON( - json: ChangeJson, - customizer: (x: any) => T = reinterpretCast - ): Change { - let before = { ...json.before }; - if (json.fieldMask) { - before = applyFieldMask(before, json.after, json.fieldMask); - } - - return Change.fromObjects( - customizer(before || {}), - customizer(json.after || {}) - ); - } - - /** @hidden */ - export function applyFieldMask( - sparseBefore: any, - after: any, - fieldMask: string - ) { - const before = { ...after }; - const masks = fieldMask.split(','); - - masks.forEach((mask) => { - const val = _.get(sparseBefore, mask); - if (typeof val === 'undefined') { - _.unset(before, mask); - } else { - _.set(before, mask, val); - } - }); - - return before; - } -} - /** * Resource is a standard format for defining a resource * (google.rpc.context.AttributeContext.Resource). In Cloud Functions, it is the