From a332fc80ffa76bf60090fc86f5fed38b2b3baf94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Overg=C3=A5rd=20Nielsen?= Date: Thu, 27 Jun 2024 14:09:52 +0200 Subject: [PATCH] Update .expected files --- .../good_test_data/all_named_ctor.expected | 4 +- .../test/good_test_data/all_types.expected | 42 +++++------- .../another_mapto.expected_multi | 16 ++--- .../good_test_data/asymmetric_object.expected | 11 ++-- .../test/good_test_data/binary_type.expected | 4 +- .../good_test_data/const_initializer.expected | 64 ++++++------------- .../embedded_annotations.expected | 20 ++---- .../good_test_data/embedded_objects.expected | 48 +++++--------- .../good_test_data/indexable_types.expected | 25 +++----- .../list_initialization.expected | 40 ++++-------- .../test/good_test_data/map.expected | 44 +++++-------- .../test/good_test_data/mapto.expected | 19 ++---- .../good_test_data/optional_argument.expected | 13 ++-- .../test/good_test_data/pinhole.expected | 13 ++-- .../test/good_test_data/primary_key.expected | 16 +++-- .../good_test_data/private_fields.expected | 4 +- .../test/good_test_data/realm_set.expected | 50 ++++++--------- .../good_test_data/required_argument.expected | 1 + ...uired_argument_with_default_value.expected | 13 ++-- .../user_defined_getter.expected | 1 + 20 files changed, 163 insertions(+), 285 deletions(-) diff --git a/packages/realm_generator/test/good_test_data/all_named_ctor.expected b/packages/realm_generator/test/good_test_data/all_named_ctor.expected index 295a2722f..8585622bb 100644 --- a/packages/realm_generator/test/good_test_data/all_named_ctor.expected +++ b/packages/realm_generator/test/good_test_data/all_named_ctor.expected @@ -55,14 +55,14 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Person value) => value.toEJson(); static Person _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'name': EJsonValue name, - 'age': EJsonValue age, } => Person( name: fromEJson(name), - age: fromEJson(age), + age: fromEJson(ejson['age']), ), _ => raiseInvalidEJson(ejson), }; diff --git a/packages/realm_generator/test/good_test_data/all_types.expected b/packages/realm_generator/test/good_test_data/all_types.expected index c32e4a538..11ebad831 100644 --- a/packages/realm_generator/test/good_test_data/all_types.expected +++ b/packages/realm_generator/test/good_test_data/all_types.expected @@ -55,17 +55,11 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Foo value) => value.toEJson(); static Foo _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'x': EJsonValue x, - 'bar': EJsonValue bar, - } => - Foo( - x: fromEJson(x), - bar: fromEJson(bar), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return Foo( + x: fromEJson(ejson['x']), + bar: fromEJson(ejson['bar']), + ); } static final schema = () { @@ -269,6 +263,7 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Bar value) => value.toEJson(); static Bar _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'name': EJsonValue name, @@ -276,16 +271,8 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { 'another': EJsonValue another, 'data': EJsonValue data, 'tidspunkt': EJsonValue timestamp, - 'aDouble': EJsonValue aDouble, - 'foo': EJsonValue foo, 'objectId': EJsonValue objectId, 'uuid': EJsonValue uuid, - 'list': EJsonValue list, - 'set': EJsonValue set, - 'map': EJsonValue map, - 'anOptionalString': EJsonValue anOptionalString, - 'any': EJsonValue any, - 'manyAny': EJsonValue manyAny, 'decimal': EJsonValue decimal, } => Bar( @@ -297,14 +284,14 @@ class Bar extends _Bar with RealmEntity, RealmObjectBase, RealmObject { fromEJson(objectId), fromEJson(uuid), fromEJson(decimal), - aDouble: fromEJson(aDouble), - foo: fromEJson(foo), - list: fromEJson(list), - set: fromEJson(set), - map: fromEJson(map), - anOptionalString: fromEJson(anOptionalString), - any: fromEJson(any), - manyAny: fromEJson(manyAny), + aDouble: fromEJson(ejson['aDouble']), + foo: fromEJson(ejson['foo']), + list: fromEJson(ejson['list']), + set: fromEJson(ejson['set']), + map: fromEJson(ejson['map']), + anOptionalString: fromEJson(ejson['anOptionalString']), + any: fromEJson(ejson['any']), + manyAny: fromEJson(ejson['manyAny']), ), _ => raiseInvalidEJson(ejson), }; @@ -426,6 +413,7 @@ class PrimitiveTypes extends _PrimitiveTypes static EJsonValue _toEJson(PrimitiveTypes value) => value.toEJson(); static PrimitiveTypes _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'stringProp': EJsonValue stringProp, diff --git a/packages/realm_generator/test/good_test_data/another_mapto.expected_multi b/packages/realm_generator/test/good_test_data/another_mapto.expected_multi index 62b443a45..2081154b1 100644 --- a/packages/realm_generator/test/good_test_data/another_mapto.expected_multi +++ b/packages/realm_generator/test/good_test_data/another_mapto.expected_multi @@ -54,17 +54,11 @@ class MappedToo extends _MappedToo static EJsonValue _toEJson(MappedToo value) => value.toEJson(); static MappedToo _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'singleLink': EJsonValue singleLink, - 'listLink': EJsonValue listLink, - } => - MappedToo( - singleLink: fromEJson(singleLink), - listLink: fromEJson(listLink), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return MappedToo( + singleLink: fromEJson(ejson['singleLink']), + listLink: fromEJson(ejson['listLink']), + ); } static final schema = () { diff --git a/packages/realm_generator/test/good_test_data/asymmetric_object.expected b/packages/realm_generator/test/good_test_data/asymmetric_object.expected index 14f3de6fd..fc07d5787 100644 --- a/packages/realm_generator/test/good_test_data/asymmetric_object.expected +++ b/packages/realm_generator/test/good_test_data/asymmetric_object.expected @@ -72,18 +72,16 @@ class Asymmetric extends _Asymmetric static EJsonValue _toEJson(Asymmetric value) => value.toEJson(); static Asymmetric _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { '_id': EJsonValue id, - 'children': EJsonValue children, - 'father': EJsonValue father, - 'mother': EJsonValue mother, } => Asymmetric( fromEJson(id), - children: fromEJson(children), - father: fromEJson(father), - mother: fromEJson(mother), + children: fromEJson(ejson['children']), + father: fromEJson(ejson['father']), + mother: fromEJson(ejson['mother']), ), _ => raiseInvalidEJson(ejson), }; @@ -150,6 +148,7 @@ class Embedded extends _Embedded static EJsonValue _toEJson(Embedded value) => value.toEJson(); static Embedded _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'name': EJsonValue name, diff --git a/packages/realm_generator/test/good_test_data/binary_type.expected b/packages/realm_generator/test/good_test_data/binary_type.expected index 7fc9f2a0d..d91a4671a 100644 --- a/packages/realm_generator/test/good_test_data/binary_type.expected +++ b/packages/realm_generator/test/good_test_data/binary_type.expected @@ -52,14 +52,14 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Foo value) => value.toEJson(); static Foo _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'requiredBinaryProp': EJsonValue requiredBinaryProp, - 'nullableBinaryProp': EJsonValue nullableBinaryProp, } => Foo( fromEJson(requiredBinaryProp), - nullableBinaryProp: fromEJson(nullableBinaryProp), + nullableBinaryProp: fromEJson(ejson['nullableBinaryProp']), ), _ => raiseInvalidEJson(ejson), }; diff --git a/packages/realm_generator/test/good_test_data/const_initializer.expected b/packages/realm_generator/test/good_test_data/const_initializer.expected index 2f040fea8..e20d1eb49 100644 --- a/packages/realm_generator/test/good_test_data/const_initializer.expected +++ b/packages/realm_generator/test/good_test_data/const_initializer.expected @@ -220,49 +220,27 @@ class ConstInitializer extends _ConstInitializer static EJsonValue _toEJson(ConstInitializer value) => value.toEJson(); static ConstInitializer _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'zero': EJsonValue zero, - 'minusOne': EJsonValue minusOne, - 'fooOrOne': EJsonValue fooOrOne, - 'parenthesis': EJsonValue parenthesis, - 'minusMinusOne': EJsonValue minusMinusOne, - 'add': EJsonValue add, - 'identifier': EJsonValue identifier, - 'infinity': EJsonValue infinity, - 'nan': EJsonValue nan, - 'negativeInfinity': EJsonValue negativeInfinity, - 'fooEnv': EJsonValue fooEnv, - 'fooLit': EJsonValue fooLit, - 'constEmptyList': EJsonValue constEmptyList, - 'constEmptyMap': EJsonValue constEmptyMap, - 'constEmptySet': EJsonValue constEmptySet, - 'emptyList': EJsonValue emptyList, - 'emptyMao': EJsonValue emptyMao, - 'emptySet': EJsonValue emptySet, - } => - ConstInitializer( - zero: fromEJson(zero), - minusOne: fromEJson(minusOne), - fooOrOne: fromEJson(fooOrOne), - parenthesis: fromEJson(parenthesis), - minusMinusOne: fromEJson(minusMinusOne), - add: fromEJson(add), - identifier: fromEJson(identifier), - infinity: fromEJson(infinity), - nan: fromEJson(nan), - negativeInfinity: fromEJson(negativeInfinity), - fooEnv: fromEJson(fooEnv), - fooLit: fromEJson(fooLit), - constEmptyList: fromEJson(constEmptyList), - constEmptyMap: fromEJson(constEmptyMap), - constEmptySet: fromEJson(constEmptySet), - emptyList: fromEJson(emptyList), - emptyMao: fromEJson(emptyMao), - emptySet: fromEJson(emptySet), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return ConstInitializer( + zero: fromEJson(ejson['zero']), + minusOne: fromEJson(ejson['minusOne']), + fooOrOne: fromEJson(ejson['fooOrOne']), + parenthesis: fromEJson(ejson['parenthesis']), + minusMinusOne: fromEJson(ejson['minusMinusOne']), + add: fromEJson(ejson['add']), + identifier: fromEJson(ejson['identifier']), + infinity: fromEJson(ejson['infinity']), + nan: fromEJson(ejson['nan']), + negativeInfinity: fromEJson(ejson['negativeInfinity']), + fooEnv: fromEJson(ejson['fooEnv']), + fooLit: fromEJson(ejson['fooLit']), + constEmptyList: fromEJson(ejson['constEmptyList']), + constEmptyMap: fromEJson(ejson['constEmptyMap']), + constEmptySet: fromEJson(ejson['constEmptySet']), + emptyList: fromEJson(ejson['emptyList']), + emptyMao: fromEJson(ejson['emptyMao']), + emptySet: fromEJson(ejson['emptySet']), + ); } static final schema = () { diff --git a/packages/realm_generator/test/good_test_data/embedded_annotations.expected b/packages/realm_generator/test/good_test_data/embedded_annotations.expected index bf7c4cc85..47ceb7ee7 100644 --- a/packages/realm_generator/test/good_test_data/embedded_annotations.expected +++ b/packages/realm_generator/test/good_test_data/embedded_annotations.expected @@ -53,17 +53,11 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Parent value) => value.toEJson(); static Parent _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'single child': EJsonValue child, - 'CHILDREN': EJsonValue children, - } => - Parent( - child: fromEJson(child), - children: fromEJson(children), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return Parent( + child: fromEJson(ejson['single child']), + children: fromEJson(ejson['CHILDREN']), + ); } static final schema = () { @@ -136,16 +130,16 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { static EJsonValue _toEJson(Child1 value) => value.toEJson(); static Child1 _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { '_value': EJsonValue value, - '_parent': EJsonValue linkToParent, 'indexedString': EJsonValue indexedString, } => Child1( fromEJson(value), fromEJson(indexedString), - linkToParent: fromEJson(linkToParent), + linkToParent: fromEJson(ejson['_parent']), ), _ => raiseInvalidEJson(ejson), }; diff --git a/packages/realm_generator/test/good_test_data/embedded_objects.expected b/packages/realm_generator/test/good_test_data/embedded_objects.expected index 291024fdb..43a829180 100644 --- a/packages/realm_generator/test/good_test_data/embedded_objects.expected +++ b/packages/realm_generator/test/good_test_data/embedded_objects.expected @@ -52,17 +52,11 @@ class Parent extends _Parent with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Parent value) => value.toEJson(); static Parent _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'child': EJsonValue child, - 'children': EJsonValue children, - } => - Parent( - child: fromEJson(child), - children: fromEJson(children), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return Parent( + child: fromEJson(ejson['child']), + children: fromEJson(ejson['children']), + ); } static final schema = () { @@ -143,18 +137,16 @@ class Child1 extends _Child1 with RealmEntity, RealmObjectBase, EmbeddedObject { static EJsonValue _toEJson(Child1 value) => value.toEJson(); static Child1 _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'value': EJsonValue value, - 'child': EJsonValue child, - 'children': EJsonValue children, - 'linkToParent': EJsonValue linkToParent, } => Child1( fromEJson(value), - child: fromEJson(child), - children: fromEJson(children), - linkToParent: fromEJson(linkToParent), + child: fromEJson(ejson['child']), + children: fromEJson(ejson['children']), + linkToParent: fromEJson(ejson['linkToParent']), ), _ => raiseInvalidEJson(ejson), }; @@ -336,6 +328,7 @@ class Child2 extends _Child2 with RealmEntity, RealmObjectBase, EmbeddedObject { static EJsonValue _toEJson(Child2 value) => value.toEJson(); static Child2 _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'boolProp': EJsonValue boolProp, @@ -345,13 +338,6 @@ class Child2 extends _Child2 with RealmEntity, RealmObjectBase, EmbeddedObject { 'dateProp': EJsonValue dateProp, 'objectIdProp': EJsonValue objectIdProp, 'uuidProp': EJsonValue uuidProp, - 'nullableBoolProp': EJsonValue nullableBoolProp, - 'nullableIntProp': EJsonValue nullableIntProp, - 'nullableDoubleProp': EJsonValue nullableDoubleProp, - 'nullableStringProp': EJsonValue nullableStringProp, - 'nullableDateProp': EJsonValue nullableDateProp, - 'nullableObjectIdProp': EJsonValue nullableObjectIdProp, - 'nullableUuidProp': EJsonValue nullableUuidProp, } => Child2( fromEJson(boolProp), @@ -361,13 +347,13 @@ class Child2 extends _Child2 with RealmEntity, RealmObjectBase, EmbeddedObject { fromEJson(dateProp), fromEJson(objectIdProp), fromEJson(uuidProp), - nullableBoolProp: fromEJson(nullableBoolProp), - nullableIntProp: fromEJson(nullableIntProp), - nullableDoubleProp: fromEJson(nullableDoubleProp), - nullableStringProp: fromEJson(nullableStringProp), - nullableDateProp: fromEJson(nullableDateProp), - nullableObjectIdProp: fromEJson(nullableObjectIdProp), - nullableUuidProp: fromEJson(nullableUuidProp), + nullableBoolProp: fromEJson(ejson['nullableBoolProp']), + nullableIntProp: fromEJson(ejson['nullableIntProp']), + nullableDoubleProp: fromEJson(ejson['nullableDoubleProp']), + nullableStringProp: fromEJson(ejson['nullableStringProp']), + nullableDateProp: fromEJson(ejson['nullableDateProp']), + nullableObjectIdProp: fromEJson(ejson['nullableObjectIdProp']), + nullableUuidProp: fromEJson(ejson['nullableUuidProp']), ), _ => raiseInvalidEJson(ejson), }; diff --git a/packages/realm_generator/test/good_test_data/indexable_types.expected b/packages/realm_generator/test/good_test_data/indexable_types.expected index 657a38fbd..41503bcf4 100644 --- a/packages/realm_generator/test/good_test_data/indexable_types.expected +++ b/packages/realm_generator/test/good_test_data/indexable_types.expected @@ -185,24 +185,17 @@ class Indexable extends _Indexable static EJsonValue _toEJson(Indexable value) => value.toEJson(); static Indexable _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'aBool': EJsonValue aBool, - 'aNullableBool': EJsonValue aNullableBool, 'anInt': EJsonValue anInt, - 'aNullableInt': EJsonValue aNullableInt, 'aString': EJsonValue aString, - 'aNullableString': EJsonValue aNullableString, 'anObjectId': EJsonValue anObjectId, - 'aNullableObjectId': EJsonValue aNullableObjectId, 'anUuid': EJsonValue anUuid, - 'aNullableUuid': EJsonValue aNullableUuid, 'aDateTime': EJsonValue aDateTime, - 'aNullableDateTime': EJsonValue aNullableDateTime, - 'aRealmValue': EJsonValue aRealmValue, 'generalStringIndex': EJsonValue generalStringIndex, 'ftsStringValue': EJsonValue ftsStringValue, - 'nullableFtsStringValue': EJsonValue nullableFtsStringValue, } => Indexable( fromEJson(aBool), @@ -213,14 +206,14 @@ class Indexable extends _Indexable fromEJson(aDateTime), fromEJson(generalStringIndex), fromEJson(ftsStringValue), - aNullableBool: fromEJson(aNullableBool), - aNullableInt: fromEJson(aNullableInt), - aNullableString: fromEJson(aNullableString), - aNullableObjectId: fromEJson(aNullableObjectId), - aNullableUuid: fromEJson(aNullableUuid), - aNullableDateTime: fromEJson(aNullableDateTime), - aRealmValue: fromEJson(aRealmValue), - nullableFtsStringValue: fromEJson(nullableFtsStringValue), + aNullableBool: fromEJson(ejson['aNullableBool']), + aNullableInt: fromEJson(ejson['aNullableInt']), + aNullableString: fromEJson(ejson['aNullableString']), + aNullableObjectId: fromEJson(ejson['aNullableObjectId']), + aNullableUuid: fromEJson(ejson['aNullableUuid']), + aNullableDateTime: fromEJson(ejson['aNullableDateTime']), + aRealmValue: fromEJson(ejson['aRealmValue']), + nullableFtsStringValue: fromEJson(ejson['nullableFtsStringValue']), ), _ => raiseInvalidEJson(ejson), }; diff --git a/packages/realm_generator/test/good_test_data/list_initialization.expected b/packages/realm_generator/test/good_test_data/list_initialization.expected index d0463f516..22927a958 100644 --- a/packages/realm_generator/test/good_test_data/list_initialization.expected +++ b/packages/realm_generator/test/good_test_data/list_initialization.expected @@ -140,33 +140,19 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Person value) => value.toEJson(); static Person _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'children': EJsonValue children, - 'initList': EJsonValue initList, - 'initListWithType': EJsonValue initListWithType, - 'initListConst': EJsonValue initListConst, - 'initSet': EJsonValue initSet, - 'initSetWithType': EJsonValue initSetWithType, - 'initSetConst': EJsonValue initSetConst, - 'initMap': EJsonValue initMap, - 'initMapWithType': EJsonValue initMapWithType, - 'initMapConst': EJsonValue initMapConst, - } => - Person( - children: fromEJson(children), - initList: fromEJson(initList), - initListWithType: fromEJson(initListWithType), - initListConst: fromEJson(initListConst), - initSet: fromEJson(initSet), - initSetWithType: fromEJson(initSetWithType), - initSetConst: fromEJson(initSetConst), - initMap: fromEJson(initMap), - initMapWithType: fromEJson(initMapWithType), - initMapConst: fromEJson(initMapConst), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return Person( + children: fromEJson(ejson['children']), + initList: fromEJson(ejson['initList']), + initListWithType: fromEJson(ejson['initListWithType']), + initListConst: fromEJson(ejson['initListConst']), + initSet: fromEJson(ejson['initSet']), + initSetWithType: fromEJson(ejson['initSetWithType']), + initSetConst: fromEJson(ejson['initSetConst']), + initMap: fromEJson(ejson['initMap']), + initMapWithType: fromEJson(ejson['initMapWithType']), + initMapConst: fromEJson(ejson['initMapConst']), + ); } static final schema = () { diff --git a/packages/realm_generator/test/good_test_data/map.expected b/packages/realm_generator/test/good_test_data/map.expected index 62c71fda1..1e9b665ef 100644 --- a/packages/realm_generator/test/good_test_data/map.expected +++ b/packages/realm_generator/test/good_test_data/map.expected @@ -148,35 +148,20 @@ class LotsOfMaps extends _LotsOfMaps static EJsonValue _toEJson(LotsOfMaps value) => value.toEJson(); static LotsOfMaps _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'persons': EJsonValue persons, - 'bools': EJsonValue bools, - 'dateTimes': EJsonValue dateTimes, - 'decimals': EJsonValue decimals, - 'doubles': EJsonValue doubles, - 'ints': EJsonValue ints, - 'objectIds': EJsonValue objectIds, - 'any': EJsonValue any, - 'strings': EJsonValue strings, - 'binary': EJsonValue binary, - 'uuids': EJsonValue uuids, - } => - LotsOfMaps( - persons: fromEJson(persons), - bools: fromEJson(bools), - dateTimes: fromEJson(dateTimes), - decimals: fromEJson(decimals), - doubles: fromEJson(doubles), - ints: fromEJson(ints), - objectIds: fromEJson(objectIds), - any: fromEJson(any), - strings: fromEJson(strings), - binary: fromEJson(binary), - uuids: fromEJson(uuids), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return LotsOfMaps( + persons: fromEJson(ejson['persons']), + bools: fromEJson(ejson['bools']), + dateTimes: fromEJson(ejson['dateTimes']), + decimals: fromEJson(ejson['decimals']), + doubles: fromEJson(ejson['doubles']), + ints: fromEJson(ejson['ints']), + objectIds: fromEJson(ejson['objectIds']), + any: fromEJson(ejson['any']), + strings: fromEJson(ejson['strings']), + binary: fromEJson(ejson['binary']), + uuids: fromEJson(ejson['uuids']), + ); } static final schema = () { @@ -247,6 +232,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Person value) => value.toEJson(); static Person _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'name': EJsonValue name, diff --git a/packages/realm_generator/test/good_test_data/mapto.expected b/packages/realm_generator/test/good_test_data/mapto.expected index 8f6fcac83..228d15e55 100644 --- a/packages/realm_generator/test/good_test_data/mapto.expected +++ b/packages/realm_generator/test/good_test_data/mapto.expected @@ -72,19 +72,12 @@ class Original extends $Original static EJsonValue _toEJson(Original value) => value.toEJson(); static Original _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'remapped primitive': EJsonValue primitiveProperty, - 'remapped object': EJsonValue objectProperty, - 'remapped list': EJsonValue listProperty, - } => - Original( - primitiveProperty: fromEJson(primitiveProperty), - objectProperty: fromEJson(objectProperty), - listProperty: fromEJson(listProperty), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return Original( + primitiveProperty: fromEJson(ejson['remapped primitive']), + objectProperty: fromEJson(ejson['remapped object']), + listProperty: fromEJson(ejson['remapped list']), + ); } static final schema = () { diff --git a/packages/realm_generator/test/good_test_data/optional_argument.expected b/packages/realm_generator/test/good_test_data/optional_argument.expected index 5ca9325c2..b019af9cd 100644 --- a/packages/realm_generator/test/good_test_data/optional_argument.expected +++ b/packages/realm_generator/test/good_test_data/optional_argument.expected @@ -41,15 +41,10 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Person value) => value.toEJson(); static Person _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'spouse': EJsonValue spouse, - } => - Person( - spouse: fromEJson(spouse), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return Person( + spouse: fromEJson(ejson['spouse']), + ); } static final schema = () { diff --git a/packages/realm_generator/test/good_test_data/pinhole.expected b/packages/realm_generator/test/good_test_data/pinhole.expected index 494bbceb5..9f8ef1c4f 100644 --- a/packages/realm_generator/test/good_test_data/pinhole.expected +++ b/packages/realm_generator/test/good_test_data/pinhole.expected @@ -47,15 +47,10 @@ class Foo extends _Foo with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Foo value) => value.toEJson(); static Foo _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'x': EJsonValue x, - } => - Foo( - x: fromEJson(x), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return Foo( + x: fromEJson(ejson['x']), + ); } static final schema = () { diff --git a/packages/realm_generator/test/good_test_data/primary_key.expected b/packages/realm_generator/test/good_test_data/primary_key.expected index d60f5e3a1..0bc04fc68 100644 --- a/packages/realm_generator/test/good_test_data/primary_key.expected +++ b/packages/realm_generator/test/good_test_data/primary_key.expected @@ -40,6 +40,7 @@ class IntPK extends _IntPK with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(IntPK value) => value.toEJson(); static IntPK _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'id': EJsonValue id, @@ -98,12 +99,13 @@ class NullableIntPK extends _NullableIntPK static EJsonValue _toEJson(NullableIntPK value) => value.toEJson(); static NullableIntPK _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'id': EJsonValue id, } => NullableIntPK( - fromEJson(id), + fromEJson(ejson['id']), ), _ => raiseInvalidEJson(ejson), }; @@ -157,6 +159,7 @@ class StringPK extends _StringPK static EJsonValue _toEJson(StringPK value) => value.toEJson(); static StringPK _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'id': EJsonValue id, @@ -216,12 +219,13 @@ class NullableStringPK extends _NullableStringPK static EJsonValue _toEJson(NullableStringPK value) => value.toEJson(); static NullableStringPK _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'id': EJsonValue id, } => NullableStringPK( - fromEJson(id), + fromEJson(ejson['id']), ), _ => raiseInvalidEJson(ejson), }; @@ -275,6 +279,7 @@ class ObjectIdPK extends _ObjectIdPK static EJsonValue _toEJson(ObjectIdPK value) => value.toEJson(); static ObjectIdPK _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'id': EJsonValue id, @@ -334,12 +339,13 @@ class NullableObjectIdPK extends _NullableObjectIdPK static EJsonValue _toEJson(NullableObjectIdPK value) => value.toEJson(); static NullableObjectIdPK _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'id': EJsonValue id, } => NullableObjectIdPK( - fromEJson(id), + fromEJson(ejson['id']), ), _ => raiseInvalidEJson(ejson), }; @@ -392,6 +398,7 @@ class UuidPK extends _UuidPK with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(UuidPK value) => value.toEJson(); static UuidPK _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'id': EJsonValue id, @@ -450,12 +457,13 @@ class NullableUuidPK extends _NullableUuidPK static EJsonValue _toEJson(NullableUuidPK value) => value.toEJson(); static NullableUuidPK _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'id': EJsonValue id, } => NullableUuidPK( - fromEJson(id), + fromEJson(ejson['id']), ), _ => raiseInvalidEJson(ejson), }; diff --git a/packages/realm_generator/test/good_test_data/private_fields.expected b/packages/realm_generator/test/good_test_data/private_fields.expected index 5d727d62d..997044b42 100644 --- a/packages/realm_generator/test/good_test_data/private_fields.expected +++ b/packages/realm_generator/test/good_test_data/private_fields.expected @@ -59,14 +59,14 @@ class WithPrivateFields extends _WithPrivateFields static EJsonValue _toEJson(WithPrivateFields value) => value.toEJson(); static WithPrivateFields _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { '_plain': EJsonValue _plain, - '_withDefault': EJsonValue _withDefault, } => WithPrivateFields( fromEJson(_plain), - withDefault: fromEJson(_withDefault), + withDefault: fromEJson(ejson['_withDefault']), ), _ => raiseInvalidEJson(ejson), }; diff --git a/packages/realm_generator/test/good_test_data/realm_set.expected b/packages/realm_generator/test/good_test_data/realm_set.expected index c5e4afc6f..c6320878a 100644 --- a/packages/realm_generator/test/good_test_data/realm_set.expected +++ b/packages/realm_generator/test/good_test_data/realm_set.expected @@ -40,6 +40,7 @@ class Car extends _Car with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Car value) => value.toEJson(); static Car _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'make': EJsonValue make, @@ -276,44 +277,29 @@ class RealmSets extends _RealmSets static EJsonValue _toEJson(RealmSets value) => value.toEJson(); static RealmSets _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'key': EJsonValue key, - 'boolSet': EJsonValue boolSet, - 'nullableBoolSet': EJsonValue nullableBoolSet, - 'intSet': EJsonValue intSet, - 'nullableintSet': EJsonValue nullableintSet, - 'stringSet': EJsonValue stringSet, - 'nullablestringSet': EJsonValue nullablestringSet, - 'doubleSet': EJsonValue doubleSet, - 'nullabledoubleSet': EJsonValue nullabledoubleSet, - 'dateTimeSet': EJsonValue dateTimeSet, - 'nullabledateTimeSet': EJsonValue nullabledateTimeSet, - 'objectIdSet': EJsonValue objectIdSet, - 'nullableobjectIdSet': EJsonValue nullableobjectIdSet, - 'uuidSet': EJsonValue uuidSet, - 'nullableuuidSet': EJsonValue nullableuuidSet, - 'realmValueSet': EJsonValue realmValueSet, - 'realmObjectsSet': EJsonValue realmObjectsSet, } => RealmSets( fromEJson(key), - boolSet: fromEJson(boolSet), - nullableBoolSet: fromEJson(nullableBoolSet), - intSet: fromEJson(intSet), - nullableintSet: fromEJson(nullableintSet), - stringSet: fromEJson(stringSet), - nullablestringSet: fromEJson(nullablestringSet), - doubleSet: fromEJson(doubleSet), - nullabledoubleSet: fromEJson(nullabledoubleSet), - dateTimeSet: fromEJson(dateTimeSet), - nullabledateTimeSet: fromEJson(nullabledateTimeSet), - objectIdSet: fromEJson(objectIdSet), - nullableobjectIdSet: fromEJson(nullableobjectIdSet), - uuidSet: fromEJson(uuidSet), - nullableuuidSet: fromEJson(nullableuuidSet), - realmValueSet: fromEJson(realmValueSet), - realmObjectsSet: fromEJson(realmObjectsSet), + boolSet: fromEJson(ejson['boolSet']), + nullableBoolSet: fromEJson(ejson['nullableBoolSet']), + intSet: fromEJson(ejson['intSet']), + nullableintSet: fromEJson(ejson['nullableintSet']), + stringSet: fromEJson(ejson['stringSet']), + nullablestringSet: fromEJson(ejson['nullablestringSet']), + doubleSet: fromEJson(ejson['doubleSet']), + nullabledoubleSet: fromEJson(ejson['nullabledoubleSet']), + dateTimeSet: fromEJson(ejson['dateTimeSet']), + nullabledateTimeSet: fromEJson(ejson['nullabledateTimeSet']), + objectIdSet: fromEJson(ejson['objectIdSet']), + nullableobjectIdSet: fromEJson(ejson['nullableobjectIdSet']), + uuidSet: fromEJson(ejson['uuidSet']), + nullableuuidSet: fromEJson(ejson['nullableuuidSet']), + realmValueSet: fromEJson(ejson['realmValueSet']), + realmObjectsSet: fromEJson(ejson['realmObjectsSet']), ), _ => raiseInvalidEJson(ejson), }; diff --git a/packages/realm_generator/test/good_test_data/required_argument.expected b/packages/realm_generator/test/good_test_data/required_argument.expected index fb1478894..377f8e6d6 100644 --- a/packages/realm_generator/test/good_test_data/required_argument.expected +++ b/packages/realm_generator/test/good_test_data/required_argument.expected @@ -40,6 +40,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Person value) => value.toEJson(); static Person _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'name': EJsonValue name, diff --git a/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected b/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected index b0ad1b3a1..52dfca206 100644 --- a/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected +++ b/packages/realm_generator/test/good_test_data/required_argument_with_default_value.expected @@ -47,15 +47,10 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Person value) => value.toEJson(); static Person _fromEJson(EJsonValue ejson) { - return switch (ejson) { - { - 'age': EJsonValue age, - } => - Person( - age: fromEJson(age), - ), - _ => raiseInvalidEJson(ejson), - }; + if (ejson is! Map) return raiseInvalidEJson(ejson); + return Person( + age: fromEJson(ejson['age']), + ); } static final schema = () { diff --git a/packages/realm_generator/test/good_test_data/user_defined_getter.expected b/packages/realm_generator/test/good_test_data/user_defined_getter.expected index 470f09635..c097f90d2 100644 --- a/packages/realm_generator/test/good_test_data/user_defined_getter.expected +++ b/packages/realm_generator/test/good_test_data/user_defined_getter.expected @@ -40,6 +40,7 @@ class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { static EJsonValue _toEJson(Person value) => value.toEJson(); static Person _fromEJson(EJsonValue ejson) { + if (ejson is! Map) return raiseInvalidEJson(ejson); return switch (ejson) { { 'name': EJsonValue name,