From a03c426eae1ccb16eccb211fc053066147cea224 Mon Sep 17 00:00:00 2001 From: Tim Shedor Date: Thu, 2 Jan 2025 10:40:35 -0800 Subject: [PATCH 1/2] fix: test fixes for offline builders after nullable deprecation --- packages/brick_json_generators/CHANGELOG.md | 2 +- .../lib/json_deserialize.dart | 2 +- packages/brick_json_generators/pubspec.yaml | 2 +- .../brick_offline_first_build/pubspec.yaml | 6 +- .../test_custom_offline_first_serdes.dart | 13 +- .../test_default_value.dart | 5 +- .../offline_first_generator/test_futures.dart | 16 ++- .../test_nullable_field.dart | 26 ++-- ...first_apply_to_remote_deserialization.dart | 10 +- .../test_offline_first_where.dart | 41 ++++--- .../test_one_to_many_association.dart | 14 ++- .../test_primitive_fields.dart | 51 +++++--- .../test_unique_offline_first_serdes.dart | 4 +- .../test_custom_serdes.dart | 4 +- .../test_specify_field_name.dart | 5 +- .../test_custom_serdes.dart | 4 +- .../test_rest_config_field_rename.dart | 114 +++--------------- .../test_field_name.dart | 5 +- .../test_offline_first_where.dart | 12 +- 19 files changed, 157 insertions(+), 179 deletions(-) diff --git a/packages/brick_json_generators/CHANGELOG.md b/packages/brick_json_generators/CHANGELOG.md index 245d11cc..6202b329 100644 --- a/packages/brick_json_generators/CHANGELOG.md +++ b/packages/brick_json_generators/CHANGELOG.md @@ -6,7 +6,7 @@ - Revert `.getDisplayString()` change due to Flutter 3.22 being restricted to analyzer <6.4.1. `meta` is pinned to `1.12` in this version of Flutter, and `analyzer >=6.5.0`, where the change was made, requires `meta >= 1.15`. This change will eventually be re-reverted. - Upgrade `brick_core` to `1.4.0` - Update analysis to modern lints -- Remove redundant nullability checks for siblings and iterable siblings +- Remove redundant nullability checks for enums, siblings and iterable siblings ## 3.1.1 diff --git a/packages/brick_json_generators/lib/json_deserialize.dart b/packages/brick_json_generators/lib/json_deserialize.dart index 67c5a768..89d75c1d 100644 --- a/packages/brick_json_generators/lib/json_deserialize.dart +++ b/packages/brick_json_generators/lib/json_deserialize.dart @@ -123,7 +123,7 @@ mixin JsonDeserialize=2.18.0 <4.0.0" diff --git a/packages/brick_offline_first_build/pubspec.yaml b/packages/brick_offline_first_build/pubspec.yaml index 6ceb84df..17b6d272 100644 --- a/packages/brick_offline_first_build/pubspec.yaml +++ b/packages/brick_offline_first_build/pubspec.yaml @@ -11,9 +11,9 @@ environment: dependencies: analyzer: ">=6.0.0 <7.0.0" - brick_build: ">=3.0.0 <4.0.0" - brick_core: ^1.3.0 - brick_json_generators: ">=3.0.0 <4.0.0" + brick_build: ">=3.3.1 <4.0.0" + brick_core: ">=1.4.0 <4.0.0" + brick_json_generators: ">=3.2.0 <4.0.0" brick_offline_first: ">=3.0.0 <4.0.0" brick_sqlite: ">=3.0.0 <4.0.0" brick_sqlite_generators: ">=3.1.0 <4.0.0" diff --git a/packages/brick_offline_first_build/test/offline_first_generator/test_custom_offline_first_serdes.dart b/packages/brick_offline_first_build/test/offline_first_generator/test_custom_offline_first_serdes.dart index 337435a4..cfb48564 100644 --- a/packages/brick_offline_first_build/test/offline_first_generator/test_custom_offline_first_serdes.dart +++ b/packages/brick_offline_first_build/test/offline_first_generator/test_custom_offline_first_serdes.dart @@ -7,13 +7,16 @@ Future _$CustomOfflineFirstSerdesFromTest( {required TestProvider provider, OfflineFirstRepository? repository}) async { return CustomOfflineFirstSerdes( - string: Serializable.fromTest(data['string']), + string: + data['string'] == null ? null : Serializable.fromTest(data['string']), constructorFieldNullabilityMismatch: data['constructor_field_nullability_mismatch'] as bool?, - strings: data['strings'] - ?.map((c) => Serializable.fromTest(c as Map)) - .toList() - .cast()); + strings: data['strings'] == null + ? null + : data['strings'] + ?.map((c) => Serializable.fromTest(c as Map)) + .toList() + .cast()); } Future> _$CustomOfflineFirstSerdesToTest( diff --git a/packages/brick_offline_first_build/test/offline_first_generator/test_default_value.dart b/packages/brick_offline_first_build/test/offline_first_generator/test_default_value.dart index 21f6674b..7cb16a33 100644 --- a/packages/brick_offline_first_build/test/offline_first_generator/test_default_value.dart +++ b/packages/brick_offline_first_build/test/offline_first_generator/test_default_value.dart @@ -6,7 +6,10 @@ const output = r''' Future _$DefaultValueFromTest(Map data, {required TestProvider provider, OfflineFirstRepository? repository}) async { - return DefaultValue(string: data['string'] as String? ?? "Thomas"); + return DefaultValue( + string: data['string'] == null + ? null + : data['string'] as String? ?? "Thomas"); } Future> _$DefaultValueToTest(DefaultValue instance, diff --git a/packages/brick_offline_first_build/test/offline_first_generator/test_futures.dart b/packages/brick_offline_first_build/test/offline_first_generator/test_futures.dart index 2d6a41cb..00a86885 100644 --- a/packages/brick_offline_first_build/test/offline_first_generator/test_futures.dart +++ b/packages/brick_offline_first_build/test/offline_first_generator/test_futures.dart @@ -11,7 +11,9 @@ Future _$FuturesFromTest(Map data, return Futures( string: data['string'] as Future, strings: data['strings'].toList().cast>(), - futureStrings: data['future_strings']?.toList().cast(), + futureStrings: data['future_strings'] == null + ? null + : data['future_strings']?.toList().cast(), assoc: AssocAdapter() .fromTest(data['assoc'], provider: provider, repository: repository), assocs: Future.wait(data['assocs'] @@ -20,11 +22,13 @@ Future _$FuturesFromTest(Map data, .toList() .cast>() ?? []), - futureAssocs: data['future_assocs'] - ?.map((d) => AssocAdapter() - .fromTest(d, provider: provider, repository: repository)) - .toList() - .cast>()); + futureAssocs: data['future_assocs'] == null + ? null + : data['future_assocs'] + ?.map((d) => AssocAdapter() + .fromTest(d, provider: provider, repository: repository)) + .toList() + .cast>()); } Future> _$FuturesToTest(Futures instance, diff --git a/packages/brick_offline_first_build/test/offline_first_generator/test_nullable_field.dart b/packages/brick_offline_first_build/test/offline_first_generator/test_nullable_field.dart index 4dac8108..177ad2a0 100644 --- a/packages/brick_offline_first_build/test/offline_first_generator/test_nullable_field.dart +++ b/packages/brick_offline_first_build/test/offline_first_generator/test_nullable_field.dart @@ -7,11 +7,16 @@ Future _$NullableFieldFromTest(Map data, {required TestProvider provider, OfflineFirstRepository? repository}) async { return NullableField( - restFalse: data['rest_false'] as String?, - nullableRestTrue: data['nullable_rest_true'] as String?, + restFalse: + data['rest_false'] == null ? null : data['rest_false'] as String?, + nullableRestTrue: data['nullable_rest_true'] == null + ? null + : data['nullable_rest_true'] as String?, restTrue: data['rest_true'] as String, - sqliteFalse: data['sqlite_false'] as String?, - sqliteTrue: data['sqlite_true'] as String?, + sqliteFalse: + data['sqlite_false'] == null ? null : data['sqlite_false'] as String?, + sqliteTrue: + data['sqlite_true'] == null ? null : data['sqlite_true'] as String?, constructorFieldNullabilityMismatch: data['constructor_field_nullability_mismatch'] as String?, constructorFieldTypeMismatch: @@ -37,11 +42,16 @@ Future _$NullableFieldFromSqlite(Map data, {required SqliteProvider provider, OfflineFirstRepository? repository}) async { return NullableField( - restFalse: data['rest_false'] as String?, - nullableRestTrue: data['nullable_rest_true'] as String?, + restFalse: + data['rest_false'] == null ? null : data['rest_false'] as String?, + nullableRestTrue: data['nullable_rest_true'] == null + ? null + : data['nullable_rest_true'] as String?, restTrue: data['rest_true'] as String, - sqliteFalse: data['sqlite_false'] as String?, - sqliteTrue: data['sqlite_true'] as String?, + sqliteFalse: + data['sqlite_false'] == null ? null : data['sqlite_false'] as String?, + sqliteTrue: + data['sqlite_true'] == null ? null : data['sqlite_true'] as String?, constructorFieldNullabilityMismatch: data['constructor_field_nullability_mismatch'] as String, constructorFieldTypeMismatch: diff --git a/packages/brick_offline_first_build/test/offline_first_generator/test_offline_first_apply_to_remote_deserialization.dart b/packages/brick_offline_first_build/test/offline_first_generator/test_offline_first_apply_to_remote_deserialization.dart index 02749d52..067fc89a 100644 --- a/packages/brick_offline_first_build/test/offline_first_generator/test_offline_first_apply_to_remote_deserialization.dart +++ b/packages/brick_offline_first_build/test/offline_first_generator/test_offline_first_apply_to_remote_deserialization.dart @@ -10,10 +10,12 @@ Future _$OfflineFirstWhereFromTest(Map data, {required TestProvider provider, OfflineFirstRepository? repository}) async { return OfflineFirstWhere( - applied: await repository - ?.getAssociation( - Query(where: [Where.exact('id', data['id'])], limit: 1)) - .then((r) => r?.isNotEmpty ?? false ? r!.first : null), + applied: data['applied'] == null + ? null + : await repository + ?.getAssociation( + Query(where: [Where.exact('id', data['id'])], limit: 1)) + .then((r) => r?.isNotEmpty ?? false ? r!.first : null), notApplied: data['not_applied'] == null ? null : await OtherAssocAdapter().fromTest(data['not_applied'], diff --git a/packages/brick_offline_first_build/test/offline_first_generator/test_offline_first_where.dart b/packages/brick_offline_first_build/test/offline_first_generator/test_offline_first_where.dart index e9d5b72d..49d085b0 100644 --- a/packages/brick_offline_first_build/test/offline_first_generator/test_offline_first_where.dart +++ b/packages/brick_offline_first_build/test/offline_first_generator/test_offline_first_where.dart @@ -10,25 +10,30 @@ Future _$OfflineFirstWhereFromTest(Map data, {required TestProvider provider, OfflineFirstRepository? repository}) async { return OfflineFirstWhere( - assoc: repository! - .getAssociation( - Query(where: [Where.exact('id', data['id'])], limit: 1)) - .then((r) => r!.first), - assocs: (data['assocs'] ?? []) - .map>((s) => - repository.getAssociation(Query(where: [Where.exact('id', s), Where.exact('otherVar', s)])).then( + assoc: data['assoc'] == null + ? null + : repository! + .getAssociation( + Query(where: [Where.exact('id', data['id'])], limit: 1)) + .then((r) => r!.first), + assocs: data['assocs'] == null + ? null + : (data['assocs'] ?? []) + .map>((s) => repository.getAssociation(Query(where: [Where.exact('id', s), Where.exact('otherVar', s)])).then( (r) => r!.first)) - .toList(), - loadedAssoc: await repository - .getAssociation( - Query(where: [Where.exact('id', data['id'])], limit: 1)) - .then((r) => r?.isNotEmpty ?? false ? r!.first : null), - loadedAssocs: (await Future.wait((data['loaded_assocs'] ?? []).map>((s) => repository.getAssociation(Query(where: [Where.exact('id', s)])).then((r) => r?.isNotEmpty ?? false ? r!.first : null)))) - .whereType() - .toList(), - multiLookupCustomGenerator: (data['multi_lookup_custom_generator'] ?? []) - .map>((s) => repository.getAssociation(Query(where: [Where.exact('id', s), Where.exact('otherVar', s)])).then((r) => r!.first)) - .toList()); + .toList(), + loadedAssoc: data['loaded_assoc'] == null + ? null + : await repository + .getAssociation( + Query(where: [Where.exact('id', data['id'])], limit: 1)) + .then((r) => r?.isNotEmpty ?? false ? r!.first : null), + loadedAssocs: data['loaded_assocs'] == null + ? null + : (await Future.wait((data['loaded_assocs'] ?? []).map>((s) => repository.getAssociation(Query(where: [Where.exact('id', s)])).then((r) => r?.isNotEmpty ?? false ? r!.first : null)))) + .whereType() + .toList(), + multiLookupCustomGenerator: data['multi_lookup_custom_generator'] == null ? null : (data['multi_lookup_custom_generator'] ?? []).map>((s) => repository.getAssociation(Query(where: [Where.exact('id', s), Where.exact('otherVar', s)])).then((r) => r!.first)).toList()); } Future> _$OfflineFirstWhereToTest( diff --git a/packages/brick_offline_first_build/test/offline_first_generator/test_one_to_many_association.dart b/packages/brick_offline_first_build/test/offline_first_generator/test_one_to_many_association.dart index f7edbf99..aba709be 100644 --- a/packages/brick_offline_first_build/test/offline_first_generator/test_one_to_many_association.dart +++ b/packages/brick_offline_first_build/test/offline_first_generator/test_one_to_many_association.dart @@ -37,12 +37,14 @@ Future _$OneToManyAssociationFromTest( .toList() .cast>() ?? []), - nullableAssoc: await Future.wait(data['nullable_assoc'] - ?.map((d) => SqliteAssocAdapter() - .fromTest(d, provider: provider, repository: repository)) - .toList() - .cast>() ?? - [])); + nullableAssoc: data['nullable_assoc'] == null + ? null + : await Future.wait(data['nullable_assoc'] + ?.map((d) => SqliteAssocAdapter() + .fromTest(d, provider: provider, repository: repository)) + .toList() + .cast>() ?? + [])); } Future> _$OneToManyAssociationToTest( diff --git a/packages/brick_offline_first_build/test/offline_first_generator/test_primitive_fields.dart b/packages/brick_offline_first_build/test/offline_first_generator/test_primitive_fields.dart index 402fe712..f56339fa 100644 --- a/packages/brick_offline_first_build/test/offline_first_generator/test_primitive_fields.dart +++ b/packages/brick_offline_first_build/test/offline_first_generator/test_primitive_fields.dart @@ -7,25 +7,44 @@ Future _$PrimitiveFieldsFromTest(Map data, {required TestProvider provider, OfflineFirstRepository? repository}) async { return PrimitiveFields( - nullableInteger: data['nullable_integer'] as int?, - nullableBoolean: data['nullable_boolean'] as bool?, - nullableDub: data['nullable_dub'] as double?, - nullableString: data['nullable_string'] as String?, - nullableList: data['nullable_list']?.toList().cast(), - nullableSet: data['nullable_set']?.toSet().cast(), - nullableMap: data['nullable_map'], + nullableInteger: data['nullable_integer'] == null + ? null + : data['nullable_integer'] as int?, + nullableBoolean: data['nullable_boolean'] == null + ? null + : data['nullable_boolean'] as bool?, + nullableDub: + data['nullable_dub'] == null ? null : data['nullable_dub'] as double?, + nullableString: data['nullable_string'] == null + ? null + : data['nullable_string'] as String?, + nullableList: data['nullable_list'] == null + ? null + : data['nullable_list']?.toList().cast(), + nullableSet: data['nullable_set'] == null + ? null + : data['nullable_set']?.toSet().cast(), + nullableMap: data['nullable_map'] == null ? null : data['nullable_map'], nullableLongerCamelizedVariable: - data['nullable_longer_camelized_variable'] as String?, - nullableCasing: data['nullable_casing'] is int - ? Casing.values[data['nullable_casing'] as int] - : null, - nullableListCasing: data['nullable_list_casing'] - .map((e) => Casing.values[e]) - .toList() - .cast(), + data['nullable_longer_camelized_variable'] == null + ? null + : data['nullable_longer_camelized_variable'] as String?, + nullableCasing: data['nullable_casing'] == null + ? null + : data['nullable_casing'] is int + ? Casing.values[data['nullable_casing'] as int] + : null, + nullableListCasing: data['nullable_list_casing'] == null + ? null + : data['nullable_list_casing'] + .map((e) => Casing.values[e]) + .toList() + .cast(), nullableDateTime: data['nullable_date_time'] == null ? null - : DateTime.tryParse(data['nullable_date_time'] as String), + : data['nullable_date_time'] == null + ? null + : DateTime.tryParse(data['nullable_date_time'] as String), integer: data['integer'] as int, boolean: data['boolean'] as bool, dub: data['dub'] as double, diff --git a/packages/brick_offline_first_build/test/offline_first_generator/test_unique_offline_first_serdes.dart b/packages/brick_offline_first_build/test/offline_first_generator/test_unique_offline_first_serdes.dart index 8ce7def5..5404d1d9 100644 --- a/packages/brick_offline_first_build/test/offline_first_generator/test_unique_offline_first_serdes.dart +++ b/packages/brick_offline_first_build/test/offline_first_generator/test_unique_offline_first_serdes.dart @@ -11,7 +11,9 @@ Future _$CustomOfflineFirstSerdesFromTest( {required TestProvider provider, OfflineFirstRepository? repository}) async { return CustomOfflineFirstSerdes( - string: Serializable.fromTest(data['string'])); + string: data['string'] == null + ? null + : Serializable.fromTest(data['string'])); } Future> _$CustomOfflineFirstSerdesToTest( diff --git a/packages/brick_offline_first_with_graphql_build/test/offline_first_generator/test_custom_serdes.dart b/packages/brick_offline_first_with_graphql_build/test/offline_first_generator/test_custom_serdes.dart index 1f409586..86066bc5 100644 --- a/packages/brick_offline_first_with_graphql_build/test/offline_first_generator/test_custom_serdes.dart +++ b/packages/brick_offline_first_with_graphql_build/test/offline_first_generator/test_custom_serdes.dart @@ -7,7 +7,9 @@ Future _$CustomSerdesFromGraphql(Map data, {required GraphqlProvider provider, OfflineFirstRepository? repository}) async { return CustomSerdes( - string: data['string'].split('').map((s) => '$s.1').join('')); + string: data['string'] == null + ? null + : data['string'].split('').map((s) => '$s.1').join('')); } Future> _$CustomSerdesToGraphql(CustomSerdes instance, diff --git a/packages/brick_offline_first_with_graphql_build/test/offline_first_generator/test_specify_field_name.dart b/packages/brick_offline_first_with_graphql_build/test/offline_first_generator/test_specify_field_name.dart index 449114b1..6cad79da 100644 --- a/packages/brick_offline_first_with_graphql_build/test/offline_first_generator/test_specify_field_name.dart +++ b/packages/brick_offline_first_with_graphql_build/test/offline_first_generator/test_specify_field_name.dart @@ -7,7 +7,10 @@ Future _$SpecifyFieldNameFromGraphql( Map data, {required GraphqlProvider provider, OfflineFirstRepository? repository}) async { - return SpecifyFieldName(email: data['email_address'] as String?); + return SpecifyFieldName( + email: data['email_address'] == null + ? null + : data['email_address'] as String?); } Future> _$SpecifyFieldNameToGraphql( diff --git a/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_custom_serdes.dart b/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_custom_serdes.dart index cce47b4f..e1fdf659 100644 --- a/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_custom_serdes.dart +++ b/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_custom_serdes.dart @@ -7,7 +7,9 @@ Future _$CustomSerdesFromRest(Map data, {required RestProvider provider, OfflineFirstRepository? repository}) async { return CustomSerdes( - string: data['string'].split('').map((s) => '$s.1').join('')); + string: data['string'] == null + ? null + : data['string'].split('').map((s) => '$s.1').join('')); } Future> _$CustomSerdesToRest(CustomSerdes instance, diff --git a/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_rest_config_field_rename.dart b/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_rest_config_field_rename.dart index 2e0a0379..15ec5118 100644 --- a/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_rest_config_field_rename.dart +++ b/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_rest_config_field_rename.dart @@ -4,120 +4,36 @@ import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart import 'package:brick_rest/brick_rest.dart' show RestSerializable; const output = r''' -Future _$RestConfigNoRenameFromRest( - Map data, +Future _$SpecifyFieldNameFromRest(Map data, {required RestProvider provider, OfflineFirstRepository? repository}) async { - return RestConfigNoRename(someLongField: data['someLongField'] as int); + return SpecifyFieldName( + email: data['email_address'] == null + ? null + : data['email_address'] as String?); } -Future> _$RestConfigNoRenameToRest( - RestConfigNoRename instance, +Future> _$SpecifyFieldNameToRest(SpecifyFieldName instance, {required RestProvider provider, OfflineFirstRepository? repository}) async { - return {'someLongField': instance.someLongField}; + return {'email_address': instance.email}; } -Future _$RestConfigNoRenameFromSqlite( - Map data, +Future _$SpecifyFieldNameFromSqlite(Map data, {required SqliteProvider provider, OfflineFirstRepository? repository}) async { - return RestConfigNoRename(someLongField: data['some_long_field'] as int) + return SpecifyFieldName( + email: data['email_address'] == null + ? null + : data['email_address'] as String?) ..primaryKey = data['_brick_id'] as int; } -Future> _$RestConfigNoRenameToSqlite( - RestConfigNoRename instance, +Future> _$SpecifyFieldNameToSqlite( + SpecifyFieldName instance, {required SqliteProvider provider, OfflineFirstRepository? repository}) async { - return {'some_long_field': instance.someLongField}; -} - -Future _$RestConfigSnakeRenameFromRest( - Map data, - {required RestProvider provider, - OfflineFirstRepository? repository}) async { - return RestConfigSnakeRename(someLongField: data['some_long_field'] as int); -} - -Future> _$RestConfigSnakeRenameToRest( - RestConfigSnakeRename instance, - {required RestProvider provider, - OfflineFirstRepository? repository}) async { - return {'some_long_field': instance.someLongField}; -} - -Future _$RestConfigSnakeRenameFromSqlite( - Map data, - {required SqliteProvider provider, - OfflineFirstRepository? repository}) async { - return RestConfigSnakeRename(someLongField: data['some_long_field'] as int) - ..primaryKey = data['_brick_id'] as int; -} - -Future> _$RestConfigSnakeRenameToSqlite( - RestConfigSnakeRename instance, - {required SqliteProvider provider, - OfflineFirstRepository? repository}) async { - return {'some_long_field': instance.someLongField}; -} - -Future _$RestConfigKebabRenameFromRest( - Map data, - {required RestProvider provider, - OfflineFirstRepository? repository}) async { - return RestConfigKebabRename(someLongField: data['some-long-field'] as int); -} - -Future> _$RestConfigKebabRenameToRest( - RestConfigKebabRename instance, - {required RestProvider provider, - OfflineFirstRepository? repository}) async { - return {'some-long-field': instance.someLongField}; -} - -Future _$RestConfigKebabRenameFromSqlite( - Map data, - {required SqliteProvider provider, - OfflineFirstRepository? repository}) async { - return RestConfigKebabRename(someLongField: data['some_long_field'] as int) - ..primaryKey = data['_brick_id'] as int; -} - -Future> _$RestConfigKebabRenameToSqlite( - RestConfigKebabRename instance, - {required SqliteProvider provider, - OfflineFirstRepository? repository}) async { - return {'some_long_field': instance.someLongField}; -} - -Future _$RestConfigPascalRenameFromRest( - Map data, - {required RestProvider provider, - OfflineFirstRepository? repository}) async { - return RestConfigPascalRename(someLongField: data['SomeLongField'] as int); -} - -Future> _$RestConfigPascalRenameToRest( - RestConfigPascalRename instance, - {required RestProvider provider, - OfflineFirstRepository? repository}) async { - return {'SomeLongField': instance.someLongField}; -} - -Future _$RestConfigPascalRenameFromSqlite( - Map data, - {required SqliteProvider provider, - OfflineFirstRepository? repository}) async { - return RestConfigPascalRename(someLongField: data['some_long_field'] as int) - ..primaryKey = data['_brick_id'] as int; -} - -Future> _$RestConfigPascalRenameToSqlite( - RestConfigPascalRename instance, - {required SqliteProvider provider, - OfflineFirstRepository? repository}) async { - return {'some_long_field': instance.someLongField}; + return {'email_address': instance.email}; } '''; diff --git a/packages/brick_offline_first_with_supabase_build/test/offline_first_generator/test_field_name.dart b/packages/brick_offline_first_with_supabase_build/test/offline_first_generator/test_field_name.dart index 329a3d0a..eaf8dc35 100644 --- a/packages/brick_offline_first_with_supabase_build/test/offline_first_generator/test_field_name.dart +++ b/packages/brick_offline_first_with_supabase_build/test/offline_first_generator/test_field_name.dart @@ -7,7 +7,10 @@ Future _$SpecifyFieldNameFromSupabase( Map data, {required SupabaseProvider provider, OfflineFirstRepository? repository}) async { - return SpecifyFieldName(email: data['supa_email_address'] as String?); + return SpecifyFieldName( + email: data['supa_email_address'] == null + ? null + : data['supa_email_address'] as String?); } Future> _$SpecifyFieldNameToSupabase( diff --git a/packages/brick_offline_first_with_supabase_build/test/offline_first_generator/test_offline_first_where.dart b/packages/brick_offline_first_with_supabase_build/test/offline_first_generator/test_offline_first_where.dart index 958e8f23..1a51bf69 100644 --- a/packages/brick_offline_first_with_supabase_build/test/offline_first_generator/test_offline_first_where.dart +++ b/packages/brick_offline_first_with_supabase_build/test/offline_first_generator/test_offline_first_where.dart @@ -20,11 +20,13 @@ Future _$SupabaseOfflineFirstWhereFromSupabase( .toList() .cast>() ?? []), - nullableAssociations: await Future.wait(data['nullable_associations'] - ?.map((d) => AssocAdapter().fromSupabase(d, provider: provider, repository: repository)) - .toList() - .cast>() ?? - [])); + nullableAssociations: data['nullable_associations'] == null + ? null + : await Future.wait(data['nullable_associations'] + ?.map((d) => AssocAdapter().fromSupabase(d, provider: provider, repository: repository)) + .toList() + .cast>() ?? + [])); } Future> _$SupabaseOfflineFirstWhereToSupabase( From 28d1197181a880f8f936ebbfa9257b8904f4cb23 Mon Sep 17 00:00:00 2001 From: Tim Shedor Date: Thu, 2 Jan 2025 10:45:37 -0800 Subject: [PATCH 2/2] more fixes --- .../test_rest_config_field_rename.dart | 114 +++++++++++++++--- .../test_specify_field_name.dart | 5 +- .../test/offline_first_generator_test.dart | 2 - 3 files changed, 103 insertions(+), 18 deletions(-) diff --git a/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_rest_config_field_rename.dart b/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_rest_config_field_rename.dart index 15ec5118..2e0a0379 100644 --- a/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_rest_config_field_rename.dart +++ b/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_rest_config_field_rename.dart @@ -4,36 +4,120 @@ import 'package:brick_offline_first_with_rest/brick_offline_first_with_rest.dart import 'package:brick_rest/brick_rest.dart' show RestSerializable; const output = r''' -Future _$SpecifyFieldNameFromRest(Map data, +Future _$RestConfigNoRenameFromRest( + Map data, {required RestProvider provider, OfflineFirstRepository? repository}) async { - return SpecifyFieldName( - email: data['email_address'] == null - ? null - : data['email_address'] as String?); + return RestConfigNoRename(someLongField: data['someLongField'] as int); } -Future> _$SpecifyFieldNameToRest(SpecifyFieldName instance, +Future> _$RestConfigNoRenameToRest( + RestConfigNoRename instance, {required RestProvider provider, OfflineFirstRepository? repository}) async { - return {'email_address': instance.email}; + return {'someLongField': instance.someLongField}; } -Future _$SpecifyFieldNameFromSqlite(Map data, +Future _$RestConfigNoRenameFromSqlite( + Map data, {required SqliteProvider provider, OfflineFirstRepository? repository}) async { - return SpecifyFieldName( - email: data['email_address'] == null - ? null - : data['email_address'] as String?) + return RestConfigNoRename(someLongField: data['some_long_field'] as int) ..primaryKey = data['_brick_id'] as int; } -Future> _$SpecifyFieldNameToSqlite( - SpecifyFieldName instance, +Future> _$RestConfigNoRenameToSqlite( + RestConfigNoRename instance, {required SqliteProvider provider, OfflineFirstRepository? repository}) async { - return {'email_address': instance.email}; + return {'some_long_field': instance.someLongField}; +} + +Future _$RestConfigSnakeRenameFromRest( + Map data, + {required RestProvider provider, + OfflineFirstRepository? repository}) async { + return RestConfigSnakeRename(someLongField: data['some_long_field'] as int); +} + +Future> _$RestConfigSnakeRenameToRest( + RestConfigSnakeRename instance, + {required RestProvider provider, + OfflineFirstRepository? repository}) async { + return {'some_long_field': instance.someLongField}; +} + +Future _$RestConfigSnakeRenameFromSqlite( + Map data, + {required SqliteProvider provider, + OfflineFirstRepository? repository}) async { + return RestConfigSnakeRename(someLongField: data['some_long_field'] as int) + ..primaryKey = data['_brick_id'] as int; +} + +Future> _$RestConfigSnakeRenameToSqlite( + RestConfigSnakeRename instance, + {required SqliteProvider provider, + OfflineFirstRepository? repository}) async { + return {'some_long_field': instance.someLongField}; +} + +Future _$RestConfigKebabRenameFromRest( + Map data, + {required RestProvider provider, + OfflineFirstRepository? repository}) async { + return RestConfigKebabRename(someLongField: data['some-long-field'] as int); +} + +Future> _$RestConfigKebabRenameToRest( + RestConfigKebabRename instance, + {required RestProvider provider, + OfflineFirstRepository? repository}) async { + return {'some-long-field': instance.someLongField}; +} + +Future _$RestConfigKebabRenameFromSqlite( + Map data, + {required SqliteProvider provider, + OfflineFirstRepository? repository}) async { + return RestConfigKebabRename(someLongField: data['some_long_field'] as int) + ..primaryKey = data['_brick_id'] as int; +} + +Future> _$RestConfigKebabRenameToSqlite( + RestConfigKebabRename instance, + {required SqliteProvider provider, + OfflineFirstRepository? repository}) async { + return {'some_long_field': instance.someLongField}; +} + +Future _$RestConfigPascalRenameFromRest( + Map data, + {required RestProvider provider, + OfflineFirstRepository? repository}) async { + return RestConfigPascalRename(someLongField: data['SomeLongField'] as int); +} + +Future> _$RestConfigPascalRenameToRest( + RestConfigPascalRename instance, + {required RestProvider provider, + OfflineFirstRepository? repository}) async { + return {'SomeLongField': instance.someLongField}; +} + +Future _$RestConfigPascalRenameFromSqlite( + Map data, + {required SqliteProvider provider, + OfflineFirstRepository? repository}) async { + return RestConfigPascalRename(someLongField: data['some_long_field'] as int) + ..primaryKey = data['_brick_id'] as int; +} + +Future> _$RestConfigPascalRenameToSqlite( + RestConfigPascalRename instance, + {required SqliteProvider provider, + OfflineFirstRepository? repository}) async { + return {'some_long_field': instance.someLongField}; } '''; diff --git a/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_specify_field_name.dart b/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_specify_field_name.dart index d7ec7c57..04fef3c8 100644 --- a/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_specify_field_name.dart +++ b/packages/brick_offline_first_with_rest_build/test/offline_first_generator/test_specify_field_name.dart @@ -6,7 +6,10 @@ const output = r''' Future _$SpecifyFieldNameFromRest(Map data, {required RestProvider provider, OfflineFirstRepository? repository}) async { - return SpecifyFieldName(email: data['email_address'] as String?); + return SpecifyFieldName( + email: data['email_address'] == null + ? null + : data['email_address'] as String?); } Future> _$SpecifyFieldNameToRest(SpecifyFieldName instance, diff --git a/packages/brick_offline_first_with_rest_build/test/offline_first_generator_test.dart b/packages/brick_offline_first_with_rest_build/test/offline_first_generator_test.dart index 9f70fbaf..07bd0813 100644 --- a/packages/brick_offline_first_with_rest_build/test/offline_first_generator_test.dart +++ b/packages/brick_offline_first_with_rest_build/test/offline_first_generator_test.dart @@ -25,8 +25,6 @@ void main() { await generateAdapterExpectation('rest_config_endpoint', rest_config_endpoint.output); }); - test('restSerializable#nullable', () {}, skip: 'Write implementation and then write test'); - test('restSerializable#fieldRename', () async { await generateExpectation('rest_config_field_rename', rest_config_field_rename.output); });