Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Basketball ICO
@BasketballICO_twitter
Other question, can I use flutter packages pub ... instead of pub...?
Anatoly Pulyaevskiy
@pulyaevskiy

I'm curious that if I reach that point, is it possible to interface to that JS library from Dart, and if so, how much of a pain is it?

@pauldemarco sorry for late reply. The answer is two fold. Is it possible to interface with a JS library? Definitely YES, this is exactly what this project is doing. How hard or easy is it to interface? It depends. It could definitely be a bit confusing in the beginning, JS interop is not very well documented and there are some nuances specific to Node.js packages. The good news though you guys now have a very good example to base your work on. Both firebase_admin_interop and firebase_functions_interop provide a lot of use cases, so you just need to look inside. Don't forget to look at the node_interop, node_io and node_http for examples on how to use regular Node.js APIs and define bindings.

@serenity-luna could you point at the docs on this feature (collection group queries)? I can take a look into this later
Anatoly Pulyaevskiy
@pulyaevskiy
@BasketballICO_twitter look at the test functions subfolder in this repo: https://github.com/pulyaevskiy/firebase-functions-interop/tree/master/functions It's the bare minimum required. The only structure item I recommend to follow is to put entrypoint dart files inside node/ folder. The rest of the code can (and probably should) live inside lib/ and lib/src/ as in any other Dart project.

Other question, can I use flutter packages pub ... instead of pub...?

No, unfortunately. Flutter's version of Dart does not have web components required by JS interop. I have Dart SDK installed as the default in my shell.

Basketball ICO
@BasketballICO_twitter

@pulyaevskiy thanks, i am trying to use but cant't get it work,
is normal that dart analysis show this errors in packages folder?

https://github.com/pulyaevskiy/firebase-functions-interop/issues/58#issuecomment-527363229

fail.png
Basketball ICO
@BasketballICO_twitter

@pulyaevskiy I fix the analysis by exclude this folder like your project

https://github.com/pulyaevskiy/firebase-functions-interop/blob/master/analysis_options.yaml

This is correct?

But can't deploy with the same error

Could not read source directory. Remove links and shortcuts and try again.

https://github.com/pulyaevskiy/firebase-functions-interop/issues/58#issue-467039814

Thanks

Serena
@serenity-luna

@pulyaevskiy Thank you!

Here is the documentation you asked for:
https://googleapis.dev/nodejs/firestore/latest/Firestore.html#collectionGroup

Collection Group Queries is a new feature in Cloud Firestore:
https://firebase.googleblog.com/2019/06/understanding-collection-group-queries.html

Anatoly Pulyaevskiy
@pulyaevskiy
Thanks @serenity-luna for providing the details. This looks like a small addition, i should be able to push an update tonight, if I have some time.
Serena
@serenity-luna
@pulyaevskiy Thank you. It is a very useful feature.
Anatoly Pulyaevskiy
@pulyaevskiy

I just released firebase_admin_interop 2.0.0 with support for Collection Groups. Please read the CHANGELOG.md since this is a breaking change release and requires upgrading your npm dependencies. There are some breaking changes in the code as well.

I might need to do a follow up release for firebase_functions_interop to match new npm dependencies though. Will take a look tomorrow

Basketball ICO
@BasketballICO_twitter

@pulyaevskiy
hello firebase_admin_interop not support messaging, how can i send push notification?,
can I create a javascript function with this functionality and call in dart code?
What is the best way to do this currently?

Thanks

Thanks

void main() {
  functions['sendNewTripNotification'] = functions.firestore
      .document('/{uid}/shared_trips/')
      .onWrite(sendNewTripNotification);
}

FutureOr<void> sendNewTripNotification(
    Change<DocumentSnapshot> change, EventContext context) async {
  final uid = change.after.data.getString('userId');

  final app = FirebaseAdmin.instance.initializeApp();
  final user = User.fromMap(
      (await app.firestore().document('Users/${uid}/token').get())
          .data
          .toMap());

  // ********** JAVASCRIPT CODE
  sendNotification(user.tokenId, notification: {
    title: 'You have been invited to a trip.',
    body: 'Tap here to check it out!'
  });
  // ********** JAVASCRIPT CODE
}
Anatoly Pulyaevskiy
@pulyaevskiy
@BasketballICO_twitter yeah, I haven't got around to implement messaging portion of Admin SDK, so this still needs to be done. There is no blockers for this work aside from the fact that my free time is pretty limited. If you feeling adventurous you are welcome to submit a pull request to firebase_admin_interop with this change.
I don't see sendNotification method in the docs though. Which one are you referring to exactly? I'm looking at https://firebase.google.com/docs/reference/admin/node/admin.messaging.Messaging.html?hl=en#methods
Basketball ICO
@BasketballICO_twitter
@pulyaevskiy send notification is only a shortcut function for sendToDevice
function sendNotification(tokenId, payload) {
    admin.messaging().sendToDevice(tokenId, payload).then((response) => {
        // Response is a message ID string.
        console.log('Successfully sent message:', response);
    })
        .catch((error) => {
            console.log('Error sending message:', error);
        });
}
I'm going to look at the repository to see if I can do something
Anatoly Pulyaevskiy
@pulyaevskiy
I see. Yeah, take a look, it should be fairly straightforward if you follow examples in other namespaces. In short this would involve:
  1. Adding new bindings (type declarations) in lib/src/bindings.dart. Bare minimum would be Messaging class with sendToDevice method + MessagingPayload, MessagingOptions, MessagingDevicesResponse(which are used in this method arguments) + any other type that these classes depend on.
  2. Adding new lib/src/messaging.dart file. This one would have the same classes as above, but these would actually have all methods implemented to proxy all calls to the bindings. Just look at lib/src/auth.dart follow similar pattern.
  3. Adding new method messaging to the App class in both bindings and lib/src/app.dart, which is again a simple proxy to native JS method.
Basketball ICO
@BasketballICO_twitter
😵 It's late here, I try to follow this steps tomorrow, thanks
Anatoly Pulyaevskiy
@pulyaevskiy
sure, no rush on my end :D
Luke Pighetti
@lukepighetti
Hey @pulyaevskiy thanks for making a Dart option for firebase functions
I tried following your example for setup and build_runner just spits out a index.dart file instead of index.dart.js
if you have any thuoghts on how to proceed i would much appreciate it :)
Anatoly Pulyaevskiy
@pulyaevskiy
Hey Luke, thanks for checking it out. I’ll take a look tonight. I just released an update to build_node_compilers which could be the reason. Do you see any errors or warnings in build runner output?
Feel free to submit a GitHub issue with more details as well
Luke Pighetti
@lukepighetti
I didn't see any errors or warnings tbh
just followed the directions exactly and it produced an index.dart file with the original source not transformed in any way
as a note, due to dart's tree shaking have you seen improved cold starts over JS functions?
Anatoly Pulyaevskiy
@pulyaevskiy
@lukepighetti could you confirm if you see this warning in the build output pulyaevskiy/node-interop#67 ?
sorry for late reply
I looked at it tonight and it seems like the issue is in just released build_node_compilers not happy with node_io.
Dustin Graham
@dustin-graham
Hello! @pulyaevskiy thanks for the library! We're building a new flutter app with firebase on the backend and we're trying to build our our cloud functions with Dart as well. really nice to have shared code and have the same language everywhere.
Dustin Graham
@dustin-graham
We've run into a few challenges and so I'd like to ask a few questions here. First, one of the more difficult parts about our workflow is that our function logs aren't really human readable. The types are all minified and it's difficult to debug issues. Stacktraces are equally unhelpful. Second, we'd really love to find a way to attach a debugger when running tests. We haven't been able to figure out a way to do that. Third, the library is several versions behind the latest firebase JS dependencies. I can see quite a few forks of the library in which the fork maintainers bumped up the dependency versions. Are there any plans to update dependencies and get on with the newer dependencies? It's also behind on some other build_runner related dependencies which causes a bit of clash in our project (we depend on a newer version of analyzer for example). I'm willing to help out and contribute if you'd like.
Basketball ICO
@BasketballICO_twitter
@dustin-graham please write this in github, @pulyaevskiy doesn't come here much xD
Anatoly Pulyaevskiy
@pulyaevskiy
I’ve been pretty quite recently yes, sorry guys.

The types are all minified and it's difficult to debug issues.

You can disable minification when compiling with build runner, don’t remember exact flag name though.

find a way to attach a debugger when running tests.

I was able to use VSCode to debug though it requires a bit of setup. Just run your tests with node and enable node’s debugger, then in vscode use “attach to process” command and specify your debugger port

Anatoly Pulyaevskiy
@pulyaevskiy

Third, the library is several versions behind the latest firebase JS dependencies.

Yes it’s lagging a bit behind. Haven’t had a lot of spare time recently to work on this unfortunately. Feel free to submit your PRs, I’d be happy to review.

Dustin Graham
@dustin-graham
Thank you for the reply. I'll see what I can do. I removed the minification flag on the build.yaml file but it still appears to be minified
is there anyone else here that is running their firebase functions in Dart with this library? We're quite happy with the idea of doing this but we're needing to make sure we can get good logs and debuggability before we can go all in on this method
raywalz
@raywalz
I'm a beginner Flutter developer. I found this and was hoping it would allow me to use Dart exclusively. I'm trying to decide whether I should try using this, or just stick to TypeScript on Firebase until I actually understand what I'm doing/this library is more mature
Alfin Bakhtiar Ilhami
@alf2_gitlab
how to handle custom claim? why it must be Map<String,String>? and when I try get user.customClaims. it returns dynamic that I can not cast into Map.
Alfin Bakhtiar Ilhami
@alfinbi
@dustin-graham you can pass dart2js args --O0 to disable all optimization and get a good log
Alfin Bakhtiar Ilhami
@alfinbi
I found that customClaims is a jsObject. so to get the property one need to call getProperty method from package:js/js_util library. Since it is a jsObject, I think it shouldn't be set as Map<String,String>. For instance, one want to store claim like admin: true, if it is stored as Map<String,String> in firestore rules, one will need to assert request.auth.token.admin=="true" instead of request.auth.token.admin == true.
Alfin Bakhtiar Ilhami
@alfinbi
hi, I have firestore data {favorite: {color: blue, size: large}}, I want to update favorite.color = red. how do I achieve this? should I use UpdateData.fromMap({'favorite': {'color': 'blue'}}) ? or UpdateData.fromMap({'favorite.color': 'blue'}) ?
or maybe UpdateData().setString('favorite.color' : 'blue') ?
@pulyaevskiy
Alfin Bakhtiar Ilhami
@alfinbi
another scenario, my data is {favorite: colors: {blue: {size: large, quantity: 5}, green: {size: small, quantity: 10}}} and I want to update favorite.color.blue.size = small, favorite.color.green.quantity = 2. how do I achieve this?
Nathan
@natebot13
I'd love to help out with getting this package updated with some of the latest firebase versions. I noticed there are a bunch of forks with updated version numbers, and others with some of the missing features like cloud messaging and more. Personally, I'm having issues with realtime database transactions finishing with an error. I wouldn't mind spending an hour or more a day getting this family of packages updated (functions, admin, node if needed)