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

Port embedded object support to master #975

Merged
merged 14 commits into from
Oct 21, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Added more validations when using `User.apiKeys` to return more meaningful errors when the user cannot perform API key actions - e.g. when the user has been logged in with API key credentials or when the user has been logged out. (Issue [#950](https://github.com/realm/realm-dart/issues/950))
* Fixed `dart run realm_dart generate` and `flutter pub run realm generate` commands to exit with the correct error code on failure.
* Added more descriptive error messages when passing objects managed by another Realm as arguments to `Realm.add/delete/deleteMany`. (PR [#942](https://github.com/realm/realm-dart/pull/942))
* Fixed a bug where `list.remove` would not correctly remove the value if the value is the first element in the list. (PR [#975](https://github.com/realm/realm-dart/pull/975))
nirinchev marked this conversation as resolved.
Show resolved Hide resolved

### Compatibility
* Realm Studio: 12.0.0 or later.
Expand Down
34 changes: 29 additions & 5 deletions common/lib/src/realm_common_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,36 @@
//
// //////////////////////////////////////////////////////////////////////////////

/// An enum controlling the base type for a [RealmModel].
///
/// {@category Annotations}
enum ObjectType {
/// A standalone top-level object that can be persisted in Realm. It can link
/// to other objects or collections of other objects.
topLevel('RealmObject'),
blagoev marked this conversation as resolved.
Show resolved Hide resolved

/// An object that can be embedded in other objects. It is considered owned
/// by its parent and will be deleted if its parent is deleted.
embedded('EmbeddedObject'),

/// A special type of object used to facilitate unidirectional synchronization
/// with Atlas App Services. It is used to push data to Realm without the ability
/// to query or modify it.
_asymmetric('AsymmetricObject');

const ObjectType([this.className = 'Unknown']);

/// The name of the base class exposed by the Realm SDK.
final String className;
nirinchev marked this conversation as resolved.
Show resolved Hide resolved
}

/// Annotation class used to define `Realm` data model classes and their properties
///
/// {@category Annotations}
class RealmModel {
const RealmModel();
final ObjectType type;

const RealmModel([this.type = ObjectType.topLevel]);
nirinchev marked this conversation as resolved.
Show resolved Hide resolved
}

/// MapTo annotation for class member level.
Expand All @@ -36,7 +60,7 @@ class MapTo {
}

/// Indicates a primary key property.
///
///
/// It enables quick lookup of objects and enforces uniqueness of the values stored.
/// It may only be applied to a single property in a [RealmModel] class.
/// Only [String] and [int] can be used as primary keys.
Expand All @@ -47,8 +71,8 @@ class PrimaryKey {
const PrimaryKey();
}

/// Indicates an indexed property.
///
/// Indicates an indexed property.
///
/// Indexed properties slightly slow down insertions but can greatly speed up queries.
///
/// {@category Annotations}
Expand All @@ -57,7 +81,7 @@ class Indexed {
}

/// Indicates an ignored property.
///
///
/// Ignored properties will not be persisted in the `Realm`.
///
/// {@category Annotations}
Expand Down
10 changes: 8 additions & 2 deletions common/lib/src/realm_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ class RealmStateError extends StateError implements RealmError {
class Decimal128 {} // TODO Support decimal128 datatype https://github.com/realm/realm-dart/issues/725

/// @nodoc
class RealmObjectMarker {}
class RealmObjectBaseMarker {}

/// @nodoc
class RealmObjectMarker extends RealmObjectBaseMarker {}

/// @nodoc
class EmbeddedObjectMarker extends RealmObjectBaseMarker {}

// Union type
/// @nodoc
Expand All @@ -107,7 +113,7 @@ class RealmAny {
const RealmAny.double(double d) : this._(d);
const RealmAny.uint8List(Uint8List data) : this._(data);
// TODO: RealmObjectMarker introduced to avoid dependency inversion. It would be better if we could use RealmObject directly. https://github.com/realm/realm-dart/issues/701
const RealmAny.realmObject(RealmObjectMarker o) : this._(o);
const RealmAny.realmObject(RealmObjectBaseMarker o) : this._(o);
const RealmAny.dateTime(DateTime timestamp) : this._(timestamp);
const RealmAny.objectId(ObjectId id) : this._(id);
const RealmAny.decimal128(Decimal128 decimal) : this._(decimal);
Expand Down
61 changes: 31 additions & 30 deletions example/bin/myapp.g.dart

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

61 changes: 31 additions & 30 deletions flutter/realm_flutter/example/lib/main.g.dart

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

2 changes: 2 additions & 0 deletions flutter/realm_flutter/tests/test_driver/realm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '../test/app_test.dart' as app_test;
import '../test/configuration_test.dart' as configuration_test;
import '../test/credentials_test.dart' as credentials_test;
import '../test/dynamic_realm_test.dart' as dynamic_realm_test;
import '../test/embedded_test.dart' as embedded_test;
import '../test/list_test.dart' as list_test;
import '../test/migration_test.dart' as migration_test;
import '../test/realm_object_test.dart' as realm_object_test;
Expand All @@ -29,6 +30,7 @@ Future<String> main(List<String> args) async {
await configuration_test.main(args);
await credentials_test.main(args);
await dynamic_realm_test.main(args);
await embedded_test.main(args);
await list_test.main(args);
await migration_test.main(args);
await realm_object_test.main(args);
Expand Down
Loading