nodejs-firestore icon indicating copy to clipboard operation
nodejs-firestore copied to clipboard

Expose the internal snapshot_ method for public use

Open GriffinJohnston opened this issue 1 year ago • 7 comments

What would you like to see in the library?

Currently Firestore document triggers in EventArc are extremely clunky to use. Decoding and then parsing protobuf-encoded payloads provides a poor DX compared to the ease of accessing document data in Firebase Functions. Firebase Functions is able to provide this smooth experience by making use of an internal Firestore method, snapshot_ found here: snapshot_

How it's used in FF: https://github.com/firebase/firebase-functions/blob/master/src/common/providers/firestore.ts

If you expose snapshot_ as a public method, it will make the experience of using EventArc Firestore Document triggers with something like Cloud Run way better. And since the method already exists, I can't imagine this would be such a big lift. Absolutely huge ROI on this effort for your users. Thanks!

Describe alternatives you've considered

Painfully decoding and parsing Protobuf-encoded data

Additional context/notes

I'm posting this here because this is where the internal snapshot_ method lives, but it would make sense to expose this through firebase-admin as well.

GriffinJohnston avatar Nov 15 '24 23:11 GriffinJohnston

(drive-by comment: this appears to be a similar request to https://github.com/googleapis/nodejs-firestore/issues/2057)

dconeybe avatar Nov 16 '24 03:11 dconeybe

(drive-by comment: this appears to be a similar request to https://github.com/googleapis/nodejs-firestore/issues/2057)

Yea, basically the same request. A sane, official way to convert document event protobufs into something useful.

GriffinJohnston avatar Nov 16 '24 04:11 GriffinJohnston

Thanks for the suggestion @GriffinJohnston . I'll bring it up with the team.

ehsannas avatar Nov 19 '24 18:11 ehsannas

Thanks for the suggestion @GriffinJohnston . I'll bring it up with the team.

Thanks! While we're here I should mention that the ideal would be a function that decodes the incoming protobuf and then also parses the resulting data into a DocumentSnapshot or even just a plain JS object. Something like the createSnapshotFromProtobuf function in the referenced Firebase Functions code. I'm happy to handle the protobuf decoding if it means getting this sooner though :)

GriffinJohnston avatar Nov 19 '24 18:11 GriffinJohnston

Hi @GriffinJohnston , could you elaborate on why you could not use the firebase-functions library in your workflow?

ehsannas avatar Nov 26 '24 21:11 ehsannas

@ehsannas I'm handling these events with a containerized application on Cloud Run. Maybe I'm missing something, but I haven't found anything in firebase-functions that would be relevant to my situation.

GriffinJohnston avatar Nov 26 '24 21:11 GriffinJohnston

Hey @ehsannas, we're facing the same issue. Essentially we're trying to react to eventarc events using Cloud Run as as well, so we can have more control on the eventarc delivery. We're using a single Cloud Run service to handle Firestore events from various Firestore collections, even across projects.

We would not want to deploy the exact same Firebase Function a hundred times.

In addition to that, the "manual" workflow using eventarc gives us more control over retry settings and dead-letter queues.

Are there any updates on exposing such a function so we don't need to build such a parser ourselves?

alexregier avatar Jan 30 '25 15:01 alexregier