Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds RTDB triggers for v2 functions #1127

Merged
merged 17 commits into from Jun 9, 2022
Merged

Adds RTDB triggers for v2 functions #1127

merged 17 commits into from Jun 9, 2022

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 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>.

spec/v2/providers/database.spec.ts Outdated Show resolved Hide resolved
src/common/providers/database.ts Outdated Show resolved Hide resolved
src/common/providers/database.ts Show resolved Hide resolved
src/common/providers/database.ts Outdated Show resolved Hide resolved
src/common/providers/database.ts Outdated Show resolved Hide resolved
src/v2/providers/database.ts Outdated Show resolved Hide resolved
src/v2/providers/database.ts Outdated Show resolved Hide resolved
src/v2/providers/database.ts Outdated Show resolved Hide resolved
src/v2/providers/database.ts Outdated Show resolved Hide resolved
src/v2/providers/database.ts Outdated Show resolved Hide resolved
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.

src/common/providers/database.ts Outdated Show resolved Hide resolved
src/common/providers/database.ts Outdated Show resolved Hide resolved
src/common/providers/database.ts Outdated Show resolved Hide resolved
src/utilities/path-pattern.ts Outdated Show resolved Hide resolved
@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
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.

None yet

6 participants