firebase-admin-interop icon indicating copy to clipboard operation
firebase-admin-interop copied to clipboard

Align syntax with firebase/firebase-dart where possible (firestore)

Open grundid opened this issue 7 years ago • 5 comments

This is more of a discussion issue ;)

I'm using Dart on the client (AngularDart) and on the backend (cloud functions). Sometimes I want to try a functionality on the client and also on the backend and see what works best. For this I have to rewrite the firestore code since there are some minor differences between your code and the code in the client library.

Here is an example of a query in firebase-dart:

firestore.collection("list").where("field", "==", value).get();

where as in firebase-admin-interop a query looks like this:

firestore.collection("list").where("field", isEqualTo: value).get();

There are many other differences especially with DocumentData where your interop library adds more type safety whereas firebase-dart uses only Maps with dynamic values.

Adding documents in firebase-dart:

firestore.collection("list").add({"name": "test"});

in firebase-admin-interop:

DocumentData data = new DocumentData();
data.setString("name", "test");
firestore.collection("list").add(data);

It would be great if we could have some common API and only swap the implementation when needed. Also great for code reuse. What do you think?

grundid avatar Jun 07 '18 07:06 grundid

Thanks for bringing this up. I agree that it would make more sense if Firestore libraries shared common interface.

Note that there is also cloud_firestore package for Flutter which also uses it's own interfaces.

I used the Flutter package interface as a reference in some cases. For instance the DocumentQuery.where method maps to the one in the Flutter plugin. So in this regard I did try to conform to a certain interface.

Though I must admit I didn't follow through there.

I can imagine we'd need some sort of firestore_core package with interfaces for all Firestore objects (DocumentReference, CollectionReference, Query, etc) and then make all other libraries use those to have platform specific implementations.

This would definitely be nice to have. But we need collaboration with authors of other libraries in order to achieve this.

I'm gonna try and ping @Janamou @kevmoo (Firebase Web) and @kroikie @collinjackson (Flutter) to hopefully get some input on this.

pulyaevskiy avatar Jun 07 '18 17:06 pulyaevskiy

I'd love to align here, too. I pondered for a while creating a "mono repo" for https://github.com/firebase/firebase-dart – to separate out the VM vs browser libraries. That could also let us create a "core" or "interfaces" package we could share.

Sadly, I have very little time to work on such things...

kevmoo avatar Jun 08 '18 15:06 kevmoo

The underlying native APIs (Web, Node, Flutter) are still in flux (There are almost 3 different SDKs for javascript: browser, Node.js, admin sdk) and some features are different (Query.select not supported on Flutter/Browser). The API are quite similar and I think it is getting there so hopefully something might pop up one day!.

I have my opiniated abstraction layer that tries to sanitize the API if you need something right now (Flutter untested and still missing important feature like startAt(snaphot) and FieldValue) for now mainly firestore oriented, undocumented...

alextekartik avatar Jun 09 '18 09:06 alextekartik

@grundid

you might be interested in this thread https://github.com/flutter/flutter/issues/16186 . Also leaving this here as a cross reference.

pulyaevskiy avatar Jul 10 '18 22:07 pulyaevskiy

Here's one more example of a mismatch. Use serverTimestamp differs in different Dart Firestore clients:

In AngularDart: FieldValue.serverTimestamp() In here: Firestore.fieldValues.serverTimestamp()

gazialankus avatar Sep 02 '18 12:09 gazialankus