Skip to content

Conversation

colerogers
Copy link
Contributor

@colerogers colerogers commented May 20, 2022

Adds RTDB triggers for v2 functions.

import {
  onRefWritten,
  onRefCreated,
  onRefUpdated,
  onRefDeleted,
} from 'firebase-functions/v2/database';

export const written = onRefWritten("/foo/{bar}", (event) => {
  console.log("hi");
});

export const created = onRefCreated("/foo/{bar}", (event) => {
  console.log("hi");
});

export const updated = onRefUpdated("/foo/{bar}", (event) => {
  console.log("hi");
});

export const deleted = onRefDeleted("/foo/{bar}", (event) => {
  console.log("hi");
});

@colerogers colerogers marked this pull request as ready for review May 26, 2022 19:43
@colerogers colerogers changed the title RTDB triggers for v2 Adds RTDB triggers for v2 functions May 27, 2022
@colerogers colerogers requested review from TheIronDev and inlined May 27, 2022 15:19
@colerogers colerogers requested a review from taeold June 1, 2022 14:07
Copy link
Member

@inlined inlined left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some overall comments:

  1. We're missing src/v2/database.js which is used to quiet the import linter (since the maintainer of the repo says we should pay them if we want a fix.
  2. We've got an outstanding PR to fix some behavior around null handling in the RTDB. Did we incorporate any of that here? Can we incorporate it without doing a major version bump? We should figure out how to not throw away the author's work
  3. In general I think _.isPlainObject is more strongly verifying things than we need. The only thing we need to check is whether something has typeof val === 'object' and that the type is not null.
  4. We can ship the current path pattern work for now if we need to, but I strongly suspect we'll want to create a PathPattern utilty class like we have in One Platform code. Maybe PathPattern.compile(string) which can throw if there's a malformed path. Then something like hasParams() and matchParams(atual: string): Record<string, string>.

Copy link
Contributor

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple nits for you Cole, thanks!

I'll take another look when only living code remains.

@colerogers
Copy link
Contributor Author

@rhodgkins Yep that's the one. This will apply both to v1 & v2 functions.

@colerogers colerogers merged commit e42fe3a into master Jun 9, 2022
TheIronDev added a commit to firebase/firebase-functions-test that referenced this pull request Aug 2, 2022
* Add and handle MockCloudEvents for RTDB-V2

This commit is a follow-up to firebase-function's addition of rtdb-v2, firebase/firebase-functions#1127.

Wrap can now handle:

* `database.onValueCreated`
* `database.onValueDeleted`
* `database.onValueUpdated`
* `database.onValueWritten`
@taeold taeold added this to the v4 milestone Aug 17, 2022
henryrivera0304 added a commit to henryrivera0304/firebase-functions-test that referenced this pull request Jul 2, 2025
* Add and handle MockCloudEvents for RTDB-V2

This commit is a follow-up to firebase-function's addition of rtdb-v2, firebase/firebase-functions#1127.

Wrap can now handle:

* `database.onValueCreated`
* `database.onValueDeleted`
* `database.onValueUpdated`
* `database.onValueWritten`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants