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

Dart 3 (Macros & Native Assets) Migration #107

Open
19 tasks
GregoryConrad opened this issue Jan 8, 2023 · 1 comment
Open
19 tasks

Dart 3 (Macros & Native Assets) Migration #107

GregoryConrad opened this issue Jan 8, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@GregoryConrad
Copy link
Owner

GregoryConrad commented Jan 8, 2023

Planned Dart 3 (Macros) Migration

  • Update & add docs
  • Update & add to README
  • Update & add tests
  • Add new examples with macros

mimir

  • Rename MimirIndex to RawMimirIndex? Maybe we could add a type alias and deprecate one?
  • TypedMimirIndex (created in macros): class TypedMimirIndex<T> {…}
    • An adapter around RawMimirIndex that handles JSON conversions
  • Macro that defines extension on MimirInstance that has a TypedMimirIndex<ClassName> get classNameIndex for a certain user-defined ClassName
    • Instead of depending on a JSON package, ideally we can just check for the existence of toMap/toJson and fromMap/fromJson in macros placed on ClassName
  • Macro that adds static where method(s) on each user-defined class for easier & type-safe queries (supporting String, number, and boolean).
    • E.g., for @mimir class Movie {...}, we could have something like Mimir.and([Movie.whereTitleIsEqualTo('Forrest Gump'), Movie.whereYearIsBetween(2000, 2010)]) or Mimir.and([Mimir.where(titleIsEqualTo: 'Forrest Gump'), Mimir.where(yearIsBetween: (2000, 2010))])
    • Instead of just one where method, which would be nice/concise, I think it would be better to add several functions for each field. Reason being: isBetween requires an and parameter, which cannot be type-safe. Also, multiple methods for each field forces the method use to be checked at compile time instead of runtime (say, if a user specifies both isEqualTo and isGreaterThan inside the same .where())
    • Actually, revisiting this, perhaps we can make the isBetween field a tuple when records/patterns are supported in Dart 3. Although we will still have the issue where you can have multiple things defined in the same where call, perhaps we can add a few where variants: whereOr & whereAnd, which break down their members into Mimir.or and Mimir.and for convenience.
  • Macro that adds SortBy generators for each field
    • Proposed API: Movie.sortByAsc.title and Movie.sortByDesc.year, for example, would simply return SortBy.asc('title') and SortBy.desc('year')
  • Native Assets instead of custom packaging system in flutter_mimir

Note: there will be no extension methods placed on user-defined classes (i.e. create(), updateWith(), delete()) in plain mimir because there is no way to know the associated instance.
While we could add our own _mimirInstance field to user-defined classes, this approach has numerous issues.

flutter_mimir

  • Remove re-export of mimir, and update README with so
    • Not great to re-export right now anyways, but mimir API bindings rely on a particular binary, so flutter_mimir has to enforce this by including a bundled version.
  • defaultMimirInstance macro that adds methods to user-defined classes
    • I am inclined to do this as it is super convenient; however, I feel like it might open people up to some anti-patterns (using static members instead of DI)
      • Think we can come to good compromise by stating dangers in documentation
    • Possible because we can use the defaultInstance directly via Mimir.defaultInstance
    • create(), updateWith(…), delete() methods planned
      • create() can probably just call updateWith(...) for its implementation
    • static search(), searchStream(), documents, ... to each class as static as well
@GregoryConrad GregoryConrad added the enhancement New feature or request label Jan 8, 2023
@GregoryConrad GregoryConrad self-assigned this Jan 8, 2023
@GregoryConrad
Copy link
Owner Author

If anyone sees this issue, please feel free to chime in on the proposed changes for Dart 3 above! Would be nice to have some feedback from people using the library.

@GregoryConrad GregoryConrad changed the title Dart 3 Migration Dart 3 (Macros) Migration Mar 13, 2023
@GregoryConrad GregoryConrad changed the title Dart 3 (Macros) Migration Dart 3 (Macros & Native Assets) Migration May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant