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

Const schema refactoring #903

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6cdc36e
Implement list of nullables with minimal refactoring
nielsenko Sep 21, 2022
7e6b76a
Update json_serializable and json_annotation constraint
nielsenko Jul 4, 2022
46f7922
Const construct schema compile time
nielsenko Aug 26, 2022
7059737
Add GoldenFileMatcher
nielsenko Jul 4, 2022
839906b
Use GoldenFileMatcher
nielsenko Jul 4, 2022
1e4445a
Update good test .expected
nielsenko Jul 4, 2022
206b072
Fix generator tests
nielsenko Aug 18, 2022
2b46291
Update flutter example
nielsenko Jul 4, 2022
6aa8ccf
Fix minor linter violations
nielsenko Jul 5, 2022
5c1e29e
Fix concurrency issue
nielsenko Jul 5, 2022
4ca6dcc
Use Myers diff to color code generator output mismatch
nielsenko Jul 5, 2022
49fddf9
Normalize with DartFormatter
nielsenko Jul 5, 2022
d343b82
Add simple test
nielsenko Aug 15, 2022
9929a0a
Update expected
nielsenko Aug 25, 2022
65e2399
Split RealmObject in a pure interface and a mixin
nielsenko Aug 25, 2022
2aaab5d
Update .expected to match changes to generator
nielsenko Aug 25, 2022
70535f5
Clean dead-code, update a generated file that was missing
nielsenko Aug 25, 2022
7eaab2e
"Fix" failing tests
nielsenko Aug 25, 2022
9b52515
Get rid off DynamiRealmObject.getList<T>('x'). You can use get<List<T…
nielsenko Aug 25, 2022
0aefb15
Decorate internal (but public) classes/enums with /// @nodoc
nielsenko Sep 12, 2022
7ae42f4
Handle default values correctly against core
nielsenko Sep 14, 2022
9238c80
Add test case for default values (local realm only)
nielsenko Sep 22, 2022
c20df78
Fix generator tests
nielsenko Sep 14, 2022
ddcf598
Make migration tests compile again
nielsenko Sep 22, 2022
eb7a07b
Make RealmObject interface generic on type
nielsenko Sep 22, 2022
b80d580
Update generator to use generic RealmObjectMixin and RealmObject
nielsenko Sep 22, 2022
f4ea3a0
Run generator to update realm objects
nielsenko Sep 22, 2022
625102a
Fix bug in create
nielsenko Sep 22, 2022
cba8206
Update .expected to match changes to generator
nielsenko Sep 22, 2022
6e436f9
Fix isInMigration bug
nielsenko Sep 22, 2022
ad31e7d
Tweak generator output a bit
nielsenko Sep 23, 2022
165df3f
Remove bad comment from list.dart and cleanup a bit
nielsenko Sep 23, 2022
e000282
Avoid setting classInfo.primary_key twice
nielsenko Sep 23, 2022
fd4a878
Strengthen assert to isNullable <=> schemaProperty.optional
nielsenko Sep 23, 2022
4bef442
Make objectFactory private on SchemaObject and allow to pass null in …
nielsenko Sep 23, 2022
0895676
Tweak default value test and add extra comment
nielsenko Sep 23, 2022
d74b40b
Rebase changes
nielsenko Oct 10, 2022
d5f965d
Split RealmObject<T> into RealmObject and TypedRealmObject<T>. Still …
nielsenko Oct 10, 2022
70769e6
Fix all but 3 analyzer warnings
nielsenko Oct 10, 2022
d39de76
Update CHANGELOG
nielsenko Oct 11, 2022
2bf0a3b
Address PR feedback about comments and lazy construction of string ba…
nielsenko Oct 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"dart.lineLength": 160,
"cSpell.words": [
"apikey",
"apikeys",
"bson",
"deallocated",
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

**This project is in the Beta stage. The API should be quite stable, but occasional breaking changes may be made.**

### Breaking Changes
* Use const constructed schema objects. ([#903](https://github.com/realm/realm-dart/pull/903))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change? I guess people just need to re-run the generator?


### Enhancements
* None

Expand Down
79 changes: 54 additions & 25 deletions common/lib/src/realm_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,65 @@ import 'dart:typed_data';
import 'package:objectid/objectid.dart';
import 'package:sane_uuid/uuid.dart';

/// All supported `Realm` property types.
/// {@category Configuration}
/// @nodoc
abstract class RealmAccessorMarker {
T getValue<T>(RealmObjectMarker object, String propertyName);
T? getObject<T>(RealmObjectMarker object, String propertyName);
List<T> getList<T>(RealmObjectMarker object, String propertyName);
void set<T>(RealmObjectMarker object, String propertyName, T value, {bool isDefault = false, bool update = false});
}

Type _typeOf<T>() => T; // TODO(kasper): Replace with public version once realm_common contains all

/// @nodoc
class Mapping<T> {
const Mapping();

// Types
Type get type => T;
Type get nullableType => _typeOf<T?>();
Type get listType => List<T>;
Type get listOfNullablesType => List<T?>;

// Factories
T? getObject(RealmAccessorMarker accessor, RealmObjectMarker object, String propertyName) => accessor.getObject<T>(object, propertyName);
T getValue(RealmAccessorMarker accessor, RealmObjectMarker object, String propertyName) => accessor.getValue<T>(object, propertyName);
T? getNullableValue(RealmAccessorMarker accessor, RealmObjectMarker object, String propertyName) => accessor.getValue<T?>(object, propertyName);
List<T> getList(RealmAccessorMarker accessor, RealmObjectMarker object, String propertyName) => accessor.getList<T>(object, propertyName);
List<T?> getListOfNullables(RealmAccessorMarker accessor, RealmObjectMarker object, String propertyName) => accessor.getList<T?>(object, propertyName);
}

const _intMapping = Mapping<int>();
const _boolMapping = Mapping<bool>();
const _doubleMapping = Mapping<double>();
Comment on lines +52 to +54
Copy link
Contributor

@desistefanova desistefanova Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this types are special and we have constants only for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because int, bool, and double are both members of the enum and primitive types in dart.. Hence this little trick


/// @nodoc
enum RealmPropertyType {
int,
bool,
string,
// ignore: unused_field, constant_identifier_names
_3,
binary,
// ignore: unused_field, constant_identifier_names
_5,
mixed,
// ignore: unused_field, constant_identifier_names
_7,
timestamp,
float,
double,
int(_intMapping),
bool(_boolMapping),
string(Mapping<String>()),
_3, // ignore: unused_field, constant_identifier_names
binary(Mapping<Uint8List>()),
_5, // ignore: unused_field, constant_identifier_names
mixed(Mapping<RealmAny>()),
_7, // ignore: unused_field, constant_identifier_names
timestamp(Mapping<DateTime>()),
float(Mapping<Float>()),
double(_doubleMapping),
decimal128,
object,
// ignore: unused_field, constant_identifier_names
_13,
object(Mapping<RealmObjectMarker>()),
_13, // ignore: unused_field, constant_identifier_names
linkingObjects,
objectid,
// ignore: unused_field, constant_identifier_names
_16,
uuid,
objectid(Mapping<ObjectId>()),
_16, // ignore: unused_field, constant_identifier_names
uuid(Mapping<Uuid>());

const RealmPropertyType([this.mapping = const Mapping<Never>()]);

final Mapping<dynamic> mapping;
}

/// All supported `Realm` collection types.
/// {@category Configuration}
/// @nodoc
enum RealmCollectionType {
none,
list,
Expand Down
130 changes: 63 additions & 67 deletions example/bin/myapp.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading