Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
- BREAKING: Unhandled errors in async `onRequest` handlers in the Emulator now return a 500 error immediately. (#1755)
- Add support for ESM (ECMAScript Modules) alongside CommonJS. (#1750)
- Add `onMutationExecuted()` trigger for Firebase Data Connect. (#1727)
- BREAKING: Rename v1 Event to LegacyEvent to avoid api-extractor conflict. (#1767)
10 changes: 5 additions & 5 deletions spec/v1/cloud-functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { expect } from "chai";

import {
onInit,
Event,
LegacyEvent,
EventContext,
makeCloudFunction,
MakeCloudFunctionArgs,
Expand All @@ -43,7 +43,7 @@ describe("makeCloudFunction", () => {
};

it("calls init function", async () => {
const test: Event = {
const test: LegacyEvent = {
context: {
eventId: "00000",
timestamp: "2016-11-04T21:29:03.496Z",
Expand Down Expand Up @@ -253,7 +253,7 @@ describe("makeCloudFunction", () => {
handler: (data: any, context: EventContext) => context,
};
const cf = makeCloudFunction(args);
const test: Event = {
const test: LegacyEvent = {
context: {
eventId: "00000",
timestamp: "2016-11-04T21:29:03.496Z",
Expand Down Expand Up @@ -285,7 +285,7 @@ describe("makeCloudFunction", () => {
triggerResource: () => null,
};
const cf = makeCloudFunction(args);
const test: Event = {
const test: LegacyEvent = {
context: {
eventId: "00000",
timestamp: "2016-11-04T21:29:03.496Z",
Expand Down Expand Up @@ -325,7 +325,7 @@ describe("makeParams", () => {
const cf = makeCloudFunction(args);

it("should construct params from the event resource of events", () => {
const testEvent: Event = {
const testEvent: LegacyEvent = {
context: {
eventId: "111",
timestamp: "2016-11-04T21:29:03.496Z",
Expand Down
12 changes: 6 additions & 6 deletions spec/v1/providers/analytics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { expect } from "chai";

import * as functions from "../../../src/v1";
import { Event } from "../../../src/v1/cloud-functions";
import { LegacyEvent } from "../../../src/v1/cloud-functions";
import * as analytics from "../../../src/v1/providers/analytics";
import * as analyticsSpecInput from "./analytics.spec.input";
import { MINIMAL_V1_ENDPOINT } from "../../fixtures";
Expand Down Expand Up @@ -92,7 +92,7 @@ describe("Analytics Functions", () => {

// The event data delivered over the wire will be the JSON for an AnalyticsEvent:
// https://firebase.google.com/docs/auth/admin/manage-users#retrieve_user_data
const event: Event = {
const event: LegacyEvent = {
data: {
userDim: {
userId: "hi!",
Expand Down Expand Up @@ -126,7 +126,7 @@ describe("Analytics Functions", () => {
// Incoming events will have four kinds of "xValue" fields: "intValue",
// "stringValue", "doubleValue" and "floatValue". We expect those to get
// flattened away, leaving just their values.
const event: Event = {
const event: LegacyEvent = {
data: {
eventDim: [
{
Expand Down Expand Up @@ -193,7 +193,7 @@ describe("Analytics Functions", () => {
.event("first_open")
.onLog((data: analytics.AnalyticsEvent) => data);

const event: Event = {
const event: LegacyEvent = {
data: {
eventDim: [
{
Expand Down Expand Up @@ -264,7 +264,7 @@ describe("Analytics Functions", () => {
//
// Separately, the input has a number of microsecond timestamps that we'd
// like to rename and scale down to milliseconds.
const event: Event = {
const event: LegacyEvent = {
data: {
eventDim: [
{
Expand Down Expand Up @@ -311,7 +311,7 @@ describe("Analytics Functions", () => {
.event("app_remove")
.onLog((data: analytics.AnalyticsEvent) => data);

const event: Event = {
const event: LegacyEvent = {
data: {
eventDim: [
{
Expand Down
4 changes: 2 additions & 2 deletions spec/v1/providers/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import { expect } from "chai";
import { UserRecord } from "../../../src/common/providers/identity";
import * as functions from "../../../src/v1";
import { CloudFunction, Event } from "../../../src/v1/cloud-functions";
import { CloudFunction, LegacyEvent } from "../../../src/v1/cloud-functions";
import * as auth from "../../../src/v1/providers/auth";
import { MINIMAL_V1_ENDPOINT } from "../../fixtures";

describe("Auth Functions", () => {
const event: Event = {
const event: LegacyEvent = {
data: {
metadata: {
creationTime: "2016-12-15T19:37:37.059Z",
Expand Down
4 changes: 2 additions & 2 deletions spec/v1/providers/pubsub.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import { expect } from "chai";

import { Event, RESET_VALUE } from "../../../src/v1";
import { LegacyEvent, RESET_VALUE } from "../../../src/v1";
import { MINIMAL_V1_ENDPOINT } from "../../fixtures";
import { MINIMAL_SCHEDULE_TRIGGER } from "./fixtures";
import * as functions from "../../../src/v1";
Expand Down Expand Up @@ -125,7 +125,7 @@ describe("Pubsub Functions", () => {

it("should properly handle a new-style event", () => {
const raw = new Buffer('{"hello":"world"}', "utf8").toString("base64");
const event: Event = {
const event: LegacyEvent = {
data: {
data: raw,
attributes: {
Expand Down
4 changes: 2 additions & 2 deletions spec/v1/providers/remoteConfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { expect } from "chai";

import * as functions from "../../../src/v1";
import { CloudFunction, Event } from "../../../src/v1/cloud-functions";
import { CloudFunction, LegacyEvent } from "../../../src/v1/cloud-functions";
import * as remoteConfig from "../../../src/v1/providers/remoteConfig";
import { MINIMAL_V1_ENDPOINT } from "../../fixtures";

Expand Down Expand Up @@ -96,7 +96,7 @@ describe("RemoteConfig Functions", () => {

describe("unwraps TemplateVersion", () => {
let cloudFunctionUpdate: CloudFunction<remoteConfig.TemplateVersion>;
let event: Event;
let event: LegacyEvent;

before(() => {
process.env.GCLOUD_PROJECT = "project1";
Expand Down
4 changes: 2 additions & 2 deletions spec/v1/providers/storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// SOFTWARE.

import { expect } from "chai";
import { Event } from "../../../src/v1";
import { LegacyEvent } from "../../../src/v1";
import * as config from "../../../src/common/config";
import * as functions from "../../../src/v1";
import * as storage from "../../../src/v1/providers/storage";
Expand Down Expand Up @@ -136,7 +136,7 @@ describe("Storage Functions", () => {
const cloudFunction = storage.object().onArchive((data) => {
return data.mediaLink;
});
const goodMediaLinkEvent: Event = {
const goodMediaLinkEvent: LegacyEvent = {
data: {
mediaLink:
"https://www.googleapis.com/storage/v1/b/mybucket.appspot.com" +
Expand Down
18 changes: 9 additions & 9 deletions src/v1/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const WILDCARD_REGEX = new RegExp("{[^/{}]*}", "g");
/**
* Wire format for an event.
*/
export interface Event {
export interface LegacyEvent {
/**
* Wire format for an event context.
*/
Expand Down Expand Up @@ -344,7 +344,7 @@ export interface BlockingFunction {
* from your JavaScript file to define a Cloud Function.
*
* This type is a special JavaScript function which takes a templated
* `Event` object as its only argument.
* `LegacyEvent` object as its only argument.
*/
export interface CloudFunction<T> extends Runnable<T> {
(input: any, context?: any): PromiseLike<any> | any;
Expand All @@ -361,10 +361,10 @@ export interface CloudFunction<T> extends Runnable<T> {

/** @internal */
export interface MakeCloudFunctionArgs<EventData> {
after?: (raw: Event) => void;
before?: (raw: Event) => void;
after?: (raw: LegacyEvent) => void;
before?: (raw: LegacyEvent) => void;
contextOnlyHandler?: (context: EventContext) => PromiseLike<any> | any;
dataConstructor?: (raw: Event) => EventData;
dataConstructor?: (raw: LegacyEvent) => EventData;
eventType: string;
handler?: (data: EventData, context: EventContext) => PromiseLike<any> | any;
labels?: Record<string, string>;
Expand All @@ -382,7 +382,7 @@ export interface MakeCloudFunctionArgs<EventData> {
/** @internal */
export function makeCloudFunction<EventData>({
contextOnlyHandler,
dataConstructor = (raw: Event) => raw.data,
dataConstructor = (raw: LegacyEvent) => raw.data,
eventType,
handler,
labels = {},
Expand All @@ -406,7 +406,7 @@ export function makeCloudFunction<EventData>({
};
}

const event: Event = {
const event: LegacyEvent = {
data,
context,
};
Expand Down Expand Up @@ -550,7 +550,7 @@ function _makeParams(
return params;
}

function _makeAuth(event: Event, authType: string) {
function _makeAuth(event: LegacyEvent, authType: string) {
if (authType === "UNAUTHENTICATED") {
return null;
}
Expand All @@ -560,7 +560,7 @@ function _makeAuth(event: Event, authType: string) {
};
}

function _detectAuthType(event: Event) {
function _detectAuthType(event: LegacyEvent) {
if (event.context?.auth?.admin) {
return "ADMIN";
}
Expand Down
4 changes: 2 additions & 2 deletions src/v1/providers/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import { CloudFunction, Event, EventContext, makeCloudFunction } from "../cloud-functions";
import { CloudFunction, LegacyEvent, EventContext, makeCloudFunction } from "../cloud-functions";
import { DeploymentOptions } from "../function-configuration";

/** @internal */
Expand Down Expand Up @@ -70,7 +70,7 @@ export class AnalyticsEventBuilder {
onLog(
handler: (event: AnalyticsEvent, context: EventContext) => PromiseLike<any> | any
): CloudFunction<AnalyticsEvent> {
const dataConstructor = (raw: Event) => {
const dataConstructor = (raw: LegacyEvent) => {
return new AnalyticsEvent(raw.data);
};
return makeCloudFunction({
Expand Down
4 changes: 2 additions & 2 deletions src/v1/providers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import {
BlockingFunction,
CloudFunction,
Event,
LegacyEvent,
EventContext,
makeCloudFunction,
optionsToEndpoint,
Expand Down Expand Up @@ -108,7 +108,7 @@ export function _userWithOptions(options: DeploymentOptions, userOptions: UserOp
* @public
*/
export class UserBuilder {
private static dataConstructor(raw: Event): UserRecord {
private static dataConstructor(raw: LegacyEvent): UserRecord {
return userRecordConstructor(raw.data);
}

Expand Down
10 changes: 5 additions & 5 deletions src/v1/providers/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ParamsOf } from "../../common/params";
import { DataSnapshot } from "../../common/providers/database";
import { normalizePath } from "../../common/utilities/path";
import { applyChange } from "../../common/utilities/utils";
import { CloudFunction, Event, EventContext, makeCloudFunction } from "../cloud-functions";
import { CloudFunction, LegacyEvent, EventContext, makeCloudFunction } from "../cloud-functions";
import { DeploymentOptions } from "../function-configuration";

export { DataSnapshot };
Expand Down Expand Up @@ -217,7 +217,7 @@ export class RefBuilder<Ref extends string> {
context: EventContext<ParamsOf<Ref>>
) => PromiseLike<any> | any
): CloudFunction<DataSnapshot> {
const dataConstructor = (raw: Event) => {
const dataConstructor = (raw: LegacyEvent) => {
const [dbInstance, path] = extractInstanceAndPath(
raw.context.resource.name,
raw.context.domain
Expand All @@ -241,7 +241,7 @@ export class RefBuilder<Ref extends string> {
context: EventContext<ParamsOf<Ref>>
) => PromiseLike<any> | any
): CloudFunction<DataSnapshot> {
const dataConstructor = (raw: Event) => {
const dataConstructor = (raw: LegacyEvent) => {
const [dbInstance, path] = extractInstanceAndPath(
raw.context.resource.name,
raw.context.domain
Expand All @@ -254,7 +254,7 @@ export class RefBuilder<Ref extends string> {
private onOperation<T>(
handler: (data: T, context: EventContext) => PromiseLike<any> | any,
eventType: string,
dataConstructor: (raw: Event | Event) => any
dataConstructor: (raw: LegacyEvent | LegacyEvent) => any
): CloudFunction<T> {
return makeCloudFunction({
handler,
Expand All @@ -268,7 +268,7 @@ export class RefBuilder<Ref extends string> {
});
}

private changeConstructor = (raw: Event): Change<DataSnapshot> => {
private changeConstructor = (raw: LegacyEvent): Change<DataSnapshot> => {
const [dbInstance, path] = extractInstanceAndPath(
raw.context.resource.name,
raw.context.domain
Expand Down
10 changes: 5 additions & 5 deletions src/v1/providers/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
createBeforeSnapshotFromJson,
createSnapshotFromJson,
} from "../../common/providers/firestore";
import { CloudFunction, Event, EventContext, makeCloudFunction } from "../cloud-functions";
import { CloudFunction, LegacyEvent, EventContext, makeCloudFunction } from "../cloud-functions";
import { DeploymentOptions } from "../function-configuration";

/** @internal */
Expand Down Expand Up @@ -120,7 +120,7 @@ export class NamespaceBuilder {
}
}

export function snapshotConstructor(event: Event): DocumentSnapshot {
export function snapshotConstructor(event: LegacyEvent): DocumentSnapshot {
return createSnapshotFromJson(
event.data,
event.context.resource.name,
Expand All @@ -130,7 +130,7 @@ export function snapshotConstructor(event: Event): DocumentSnapshot {
}

// TODO remove this function when wire format changes to new format
export function beforeSnapshotConstructor(event: Event): DocumentSnapshot {
export function beforeSnapshotConstructor(event: LegacyEvent): DocumentSnapshot {
return createBeforeSnapshotFromJson(
event.data,
event.context.resource.name,
Expand All @@ -139,7 +139,7 @@ export function beforeSnapshotConstructor(event: Event): DocumentSnapshot {
);
}

function changeConstructor(raw: Event) {
function changeConstructor(raw: LegacyEvent) {
return Change.fromObjects(beforeSnapshotConstructor(raw), snapshotConstructor(raw));
}

Expand Down Expand Up @@ -191,7 +191,7 @@ export class DocumentBuilder<Path extends string> {
private onOperation<T>(
handler: (data: T, context: EventContext<ParamsOf<Path>>) => PromiseLike<any> | any,
eventType: string,
dataConstructor: (raw: Event) => any
dataConstructor: (raw: LegacyEvent) => any
): CloudFunction<T> {
return makeCloudFunction({
handler,
Expand Down
4 changes: 2 additions & 2 deletions src/v1/providers/testLab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

import { CloudFunction, Event, EventContext, makeCloudFunction } from "../cloud-functions";
import { CloudFunction, LegacyEvent, EventContext, makeCloudFunction } from "../cloud-functions";
import { DeploymentOptions } from "../function-configuration";

/** @internal */
Expand Down Expand Up @@ -54,7 +54,7 @@ export class TestMatrixBuilder {
onComplete(
handler: (testMatrix: TestMatrix, context: EventContext) => PromiseLike<any> | any
): CloudFunction<TestMatrix> {
const dataConstructor = (raw: Event) => {
const dataConstructor = (raw: LegacyEvent) => {
return new TestMatrix(raw.data);
};
return makeCloudFunction({
Expand Down
Loading