dart-lang / labs

This repository is home to Dart 'labs' packages.
BSD 3-Clause "New" or "Revised" License
16 stars 2 forks source link

Support for Cloud Datastore in Dart without relying on `dart:mirrors` #89

Open bwnyasse opened 1 year ago

bwnyasse commented 1 year ago

Description: I'm currently using the gcloud package in my Dart application to work with Cloud Datastore. However, I encountered an issue when trying to use the package with the Cloud Datastore due to the reliance on the dart:mirrors package. The dart compile command fails with the following error:

error: import of dart:mirrors is not supported in the current Dart runtime
Error: AOT compilation failed
Generating AOT snapshot failed!

I believe it would be beneficial to provide an alternative way to define Datastore models without relying on the dart:mirrors package. This would enable the use of Cloud Datastore in Dart applications without encountering the reflection-related limitations imposed by the Dart runtime when calling dart compile command.

In the documentation, the usage of the @db.Kind() and @db.Property() annotations from the gcloud package is demonstrated. However, since Dart's AOT compilation does not support dart:mirrors, it would be helpful to have an alternative approach for defining Datastore models that doesn't rely on reflection.

My use case:

I am trying to use the package to build a faas with functions-framework-dart . When building the tiny docker image, the dart compile command fails if I use Datastore library.

nagakuta commented 1 year ago

I'm one of those who would like to see this issue resolved. I also want to realize FaaS by Dart, but I'm about to give up due to the error of this dart compile :-(

jarrodcolburn commented 11 months ago

This is interesting to see here. If I'm not mistaken, defining these models is similar to the firestore problem that the cloud_firestore_odm package tries to solve for the cloud_firestore package, that takes a different approach. Since dart:mirrors isn't available on mobile, the odm package uses a build runner step.

If there is an irony, it's that cloud_firestore_odm comes with plenty of gotchas of its own, leaving the dev wishing they could use some type of reflection... like server devs.