-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support asymmetric objects * Add asymmetric tests * Add generator tests * Update CHANGELOG * Update doc comments * PR feedback * Fix spelling mistake * Add test for use of asymmetric objects in local realms * Add test for use of asymmetric objects with disconnectedSync * Fix bug
- Loading branch information
Showing
24 changed files
with
615 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
generator/test/error_test_data/asymmetric_external_link.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
|
||
@RealmModel(ObjectType.asymmetricObject) | ||
class _Asymmetric { | ||
@PrimaryKey() | ||
@MapTo('_id') | ||
late ObjectId id; | ||
} | ||
|
||
@RealmModel() | ||
class _Bad { | ||
_Asymmetric? asymmetric; | ||
} |
12 changes: 12 additions & 0 deletions
12
generator/test/error_test_data/asymmetric_external_link.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Linking to asymmetric objects is not allowed | ||
|
||
in: asset:pkg/test/error_test_data/asymmetric_external_link.dart:12:16 | ||
╷ | ||
10 │ @RealmModel() | ||
11 │ class _Bad { | ||
│ ━━━━ in realm model for 'Bad' | ||
12 │ _Asymmetric? asymmetric; | ||
│ ^^^^^^^^^^ ! | ||
╵ | ||
Remove the field | ||
|
13 changes: 13 additions & 0 deletions
13
generator/test/error_test_data/asymmetric_link_to_non_embedded.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
|
||
@RealmModel() | ||
class _Symmetric {} | ||
|
||
@RealmModel(ObjectType.asymmetricObject) | ||
class _Asymmetric { | ||
@PrimaryKey() | ||
@MapTo('_id') | ||
late ObjectId id; | ||
|
||
_Symmetric? illegal; | ||
} |
11 changes: 11 additions & 0 deletions
11
generator/test/error_test_data/asymmetric_link_to_non_embedded.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Asymmetric objects cannot link to non-embedded objects | ||
|
||
in: asset:pkg/test/error_test_data/asymmetric_link_to_non_embedded.dart:12:15 | ||
╷ | ||
6 │ @RealmModel(ObjectType.asymmetricObject) | ||
7 │ class _Asymmetric { | ||
│ ━━━━━━━━━━━ in realm model for 'Asymmetric' | ||
... │ | ||
12 │ _Symmetric? illegal; | ||
│ ^^^^^^^ ! | ||
╵ |
13 changes: 13 additions & 0 deletions
13
generator/test/error_test_data/asymmetric_link_to_non_embedded_list.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
|
||
@RealmModel() | ||
class _Symmetric {} | ||
|
||
@RealmModel(ObjectType.asymmetricObject) | ||
class _Asymmetric { | ||
@PrimaryKey() | ||
@MapTo('_id') | ||
late ObjectId id; | ||
|
||
late List<_Symmetric> illegal; | ||
} |
11 changes: 11 additions & 0 deletions
11
generator/test/error_test_data/asymmetric_link_to_non_embedded_list.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Asymmetric objects cannot link to non-embedded objects | ||
|
||
in: asset:pkg/test/error_test_data/asymmetric_link_to_non_embedded_list.dart:12:25 | ||
╷ | ||
6 │ @RealmModel(ObjectType.asymmetricObject) | ||
7 │ class _Asymmetric { | ||
│ ━━━━━━━━━━━ in realm model for 'Asymmetric' | ||
... │ | ||
12 │ late List<_Symmetric> illegal; | ||
│ ^^^^^^^ ! | ||
╵ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
|
||
@RealmModel(ObjectType.asymmetricObject) | ||
class _BadAsymmetric { | ||
// missing @PrimaryKey() | ||
@MapTo('_id') | ||
late ObjectId id; | ||
} |
10 changes: 10 additions & 0 deletions
10
generator/test/error_test_data/asymmetric_missing_pk.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Asymmetric objects must have a primary key named _id | ||
|
||
in: asset:pkg/test/error_test_data/asymmetric_missing_pk.dart:4:7 | ||
╷ | ||
3 │ @RealmModel(ObjectType.asymmetricObject) | ||
4 │ class _BadAsymmetric { | ||
│ ^^^^^^^^^^^^^^ | ||
╵ | ||
Add a primary key named _id | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
|
||
@RealmModel(ObjectType.asymmetricObject) | ||
class _BadAsymmetric { | ||
@PrimaryKey() | ||
late ObjectId wrongName; | ||
} |
13 changes: 13 additions & 0 deletions
13
generator/test/error_test_data/asymmetric_wrong_pk.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Asymmetric objects must have a primary key named _id | ||
|
||
in: asset:pkg/test/error_test_data/asymmetric_wrong_pk.dart:6:17 | ||
╷ | ||
3 │ @RealmModel(ObjectType.asymmetricObject) | ||
4 │ class _BadAsymmetric { | ||
│ ━━━━━━━━━━━━━━ in realm model for 'BadAsymmetric' | ||
5 │ @PrimaryKey() | ||
6 │ late ObjectId wrongName; | ||
│ ^^^^^^^^^ ! | ||
╵ | ||
Add @MapTo("_id") to the @PrimaryKey field | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
|
||
@RealmModel() | ||
class _Asymmetric { | ||
@PrimaryKey() | ||
@MapTo('_id') | ||
late ObjectId id; | ||
|
||
late List<_Embedded> children; | ||
late _Embedded? father; | ||
late _Embedded? mother; | ||
} | ||
|
||
@RealmModel(ObjectType.embeddedObject) | ||
class _Embedded { | ||
late String name; | ||
late int age; | ||
} |
112 changes: 112 additions & 0 deletions
112
generator/test/good_test_data/asymmetric_object.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// ************************************************************************** | ||
// RealmObjectGenerator | ||
// ************************************************************************** | ||
|
||
class Asymmetric extends _Asymmetric | ||
with RealmEntity, RealmObjectBase, RealmObject { | ||
Asymmetric( | ||
ObjectId id, { | ||
Embedded? father, | ||
Embedded? mother, | ||
Iterable<Embedded> children = const [], | ||
}) { | ||
RealmObjectBase.set(this, '_id', id); | ||
RealmObjectBase.set(this, 'father', father); | ||
RealmObjectBase.set(this, 'mother', mother); | ||
RealmObjectBase.set<RealmList<Embedded>>( | ||
this, 'children', RealmList<Embedded>(children)); | ||
} | ||
|
||
Asymmetric._(); | ||
|
||
@override | ||
ObjectId get id => RealmObjectBase.get<ObjectId>(this, '_id') as ObjectId; | ||
@override | ||
set id(ObjectId value) => RealmObjectBase.set(this, '_id', value); | ||
|
||
@override | ||
RealmList<Embedded> get children => | ||
RealmObjectBase.get<Embedded>(this, 'children') as RealmList<Embedded>; | ||
@override | ||
set children(covariant RealmList<Embedded> value) => | ||
throw RealmUnsupportedSetError(); | ||
|
||
@override | ||
Embedded? get father => | ||
RealmObjectBase.get<Embedded>(this, 'father') as Embedded?; | ||
@override | ||
set father(covariant Embedded? value) => | ||
RealmObjectBase.set(this, 'father', value); | ||
|
||
@override | ||
Embedded? get mother => | ||
RealmObjectBase.get<Embedded>(this, 'mother') as Embedded?; | ||
@override | ||
set mother(covariant Embedded? value) => | ||
RealmObjectBase.set(this, 'mother', value); | ||
|
||
@override | ||
Stream<RealmObjectChanges<Asymmetric>> get changes => | ||
RealmObjectBase.getChanges<Asymmetric>(this); | ||
|
||
@override | ||
Asymmetric freeze() => RealmObjectBase.freezeObject<Asymmetric>(this); | ||
|
||
static SchemaObject get schema => _schema ??= _initSchema(); | ||
static SchemaObject? _schema; | ||
static SchemaObject _initSchema() { | ||
RealmObjectBase.registerFactory(Asymmetric._); | ||
return const SchemaObject( | ||
ObjectType.realmObject, Asymmetric, 'Asymmetric', [ | ||
SchemaProperty('id', RealmPropertyType.objectid, | ||
mapTo: '_id', primaryKey: true), | ||
SchemaProperty('children', RealmPropertyType.object, | ||
linkTarget: 'Embedded', collectionType: RealmCollectionType.list), | ||
SchemaProperty('father', RealmPropertyType.object, | ||
optional: true, linkTarget: 'Embedded'), | ||
SchemaProperty('mother', RealmPropertyType.object, | ||
optional: true, linkTarget: 'Embedded'), | ||
]); | ||
} | ||
} | ||
|
||
class Embedded extends _Embedded | ||
with RealmEntity, RealmObjectBase, EmbeddedObject { | ||
Embedded( | ||
String name, | ||
int age, | ||
) { | ||
RealmObjectBase.set(this, 'name', name); | ||
RealmObjectBase.set(this, 'age', age); | ||
} | ||
|
||
Embedded._(); | ||
|
||
@override | ||
String get name => RealmObjectBase.get<String>(this, 'name') as String; | ||
@override | ||
set name(String value) => RealmObjectBase.set(this, 'name', value); | ||
|
||
@override | ||
int get age => RealmObjectBase.get<int>(this, 'age') as int; | ||
@override | ||
set age(int value) => RealmObjectBase.set(this, 'age', value); | ||
|
||
@override | ||
Stream<RealmObjectChanges<Embedded>> get changes => | ||
RealmObjectBase.getChanges<Embedded>(this); | ||
|
||
@override | ||
Embedded freeze() => RealmObjectBase.freezeObject<Embedded>(this); | ||
|
||
static SchemaObject get schema => _schema ??= _initSchema(); | ||
static SchemaObject? _schema; | ||
static SchemaObject _initSchema() { | ||
RealmObjectBase.registerFactory(Embedded._); | ||
return const SchemaObject(ObjectType.embeddedObject, Embedded, 'Embedded', [ | ||
SchemaProperty('name', RealmPropertyType.string), | ||
SchemaProperty('age', RealmPropertyType.int), | ||
]); | ||
} | ||
} | ||
|
Oops, something went wrong.