Skip to content

Commit

Permalink
Fully support RTDB functions and use firebase-functions 3.x (#1411)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern committed Jun 22, 2019
1 parent 7a539da commit 2cadffa
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 101 deletions.
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Fixes a bug where the functions emulator did not work with `firebase-functions` versions `3.x.x`.
* Make the Functions emulator automatically point to the RTDB emulator when running.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"eslint-plugin-prettier": "^3.0.0",
"firebase": "^2.4.2",
"firebase-admin": "^8.1.0",
"firebase-functions": "^2.2.1",
"firebase-functions": "^3.0.1",
"mocha": "^5.0.5",
"nock": "^9.3.3",
"nyc": "^14.0.0",
Expand Down
26 changes: 0 additions & 26 deletions src/emulator/events/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,4 @@ export class EventUtils {
static isLegacyEvent(proto: any): proto is LegacyEvent {
return _.has(proto, "data") && _.has(proto, "resource");
}

static convertFromLegacy(event: LegacyEvent, service: string): Event {
// TODO(samstern): Unclear what we should do with "params" and "authMode"
return {
context: {
eventId: event.eventId || "",
timestamp: event.timestamp || "",
eventType: event.eventType || "",
resource: {
name: event.resource || "",
service,
},
},
data: event.data,
};
}

static convertToLegacy(event: Event): LegacyEvent {
return {
eventId: event.context.eventId,
timestamp: event.context.timestamp,
eventType: event.context.eventType,
resource: event.context.resource.name,
data: event.data,
};
}
}
14 changes: 13 additions & 1 deletion src/emulator/functionsEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export class FunctionsEmulator implements EmulatorInstance {
...bundleTemplate,
ports: {
firestore: EmulatorRegistry.getPort(Emulators.FIRESTORE),
database: EmulatorRegistry.getPort(Emulators.DATABASE),
},
proto,
triggerId,
Expand Down Expand Up @@ -613,6 +614,17 @@ You can probably fix this by running "npm install ${
reject();
return;
}

if (res.statusCode === 200) {
EmulatorLogger.logLabeled(
"SUCCESS",
"functions",
`Trigger "${
definition.name
}" has been acknowledged by the Realtime Database emulator.`
);
}

resolve();
}
);
Expand Down Expand Up @@ -652,7 +664,7 @@ You can probably fix this by running "npm install ${
return;
}

if (JSON.stringify(JSON.parse(body)) === "{}") {
if (res.statusCode === 200) {
EmulatorLogger.logLabeled(
"SUCCESS",
"functions",
Expand Down
Loading

0 comments on commit 2cadffa

Please sign in to comment.